-
Notifications
You must be signed in to change notification settings - Fork 0
/
hyperscript.js
120 lines (94 loc) · 4.1 KB
/
hyperscript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.h = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
(function (global){
'use strict';
var React = (typeof window !== "undefined" ? window['React'] : typeof global !== "undefined" ? global['React'] : null);
var parseTag = require('./parse-tag');
module.exports = h;
function h(componentOrTag, properties, children) {
// if only one argument which is an array, wrap items with React.Fragment
if (arguments.length === 1 && Array.isArray(componentOrTag)) {
return h(React.Fragment, null, componentOrTag);
} else if (!children && isChildren(properties)) {
// If a child array or text node are passed as the second argument, shift them
children = properties;
properties = {};
} else if (arguments.length === 2) {
// If no children were passed, we don't want to pass "undefined"
// and potentially overwrite the `children` prop
children = [];
}
properties = properties ? Object.assign({}, properties) : {};
// Supported nested dataset attributes
if (properties.dataset) {
Object.keys(properties.dataset).forEach(function unnest(attrName) {
var dashedAttr = attrName.replace(/([a-z])([A-Z])/, function dash(match) {
return match[0] + '-' + match[1].toLowerCase();
});
properties['data-' + dashedAttr] = properties.dataset[attrName];
});
properties.dataset = undefined;
}
// Support nested attributes
if (properties.attributes) {
Object.keys(properties.attributes).forEach(function unnest(attrName) {
properties[attrName] = properties.attributes[attrName];
});
properties.attributes = undefined;
}
// When a selector, parse the tag name and fill out the properties object
if (typeof componentOrTag === 'string') {
componentOrTag = parseTag(componentOrTag, properties);
}
// Create the element
var args = [componentOrTag, properties].concat(children);
return React.createElement.apply(React, args);
}
function isChildren(x) {
return typeof x === 'string' || typeof x === 'number' || Array.isArray(x);
}
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./parse-tag":2}],2:[function(require,module,exports){
/* eslint-disable complexity, max-statements */
'use strict';
var classIdSplit = /([\.#]?[a-zA-Z0-9_:-]+)/;
var notClassId = /^\.|#/;
module.exports = parseTag;
function parseTag(tag, props) {
if (!tag) {
return 'div';
}
var noId = !('id' in props);
var tagParts = tag.split(classIdSplit);
var tagName = null;
if (notClassId.test(tagParts[1])) {
tagName = 'div';
}
var classes;
var part;
var type;
var i;
for (i = 0; i < tagParts.length; i++) {
part = tagParts[i];
if (!part) {
continue;
}
type = part.charAt(0);
if (!tagName) {
tagName = part;
} else if (type === '.') {
classes = classes || [];
classes.push(part.substring(1, part.length));
} else if (type === '#' && noId) {
props.id = part.substring(1, part.length);
}
}
if (classes) {
if (props.className) {
classes.push(props.className);
}
props.className = classes.join(' ');
}
return tagName ? tagName.toLowerCase() : 'div';
}
},{}]},{},[1])(1)
});