bobe-dom 0.0.54 → 0.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bobe-dom.cjs.js +123 -2
- package/dist/bobe-dom.cjs.js.map +1 -1
- package/dist/bobe-dom.esm.js +115 -2
- package/dist/bobe-dom.esm.js.map +1 -1
- package/dist/index.d.ts +22 -2
- package/dist/index.umd.js +125 -6
- package/dist/index.umd.js.map +1 -1
- package/package.json +13 -8
package/dist/bobe-dom.cjs.js
CHANGED
|
@@ -1,6 +1,127 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var bobe = require('bobe');
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const BOOLEAN_ATTRS = new Set(['disabled', 'readonly', 'checked', 'selected', 'hidden', 'multiple', 'required', 'autofocus', 'autoplay', 'controls', 'loop', 'muted', 'defer', 'async', 'reversed', 'open', 'itemscope', 'ismap', 'nohref', 'noshade', 'nowrap', 'compact', 'default']);
|
|
6
|
+
const VALUE_PROP_TAGS = new Set(['INPUT', 'TEXTAREA', 'SELECT']);
|
|
7
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
8
|
+
const MATH_NS = 'http://www.w3.org/1998/Math/MathML';
|
|
9
|
+
const SVG_TAGS = new Set(['svg', 'animate', 'animateMotion', 'animateTransform', 'circle', 'clipPath', 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence', 'filter', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'set', 'stop', 'switch', 'symbol', 'textPath', 'tspan', 'use', 'view']);
|
|
10
|
+
const MATH_TAGS = new Set(['math', 'maction', 'maligngroup', 'malignmark', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mlongdiv', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'mspace', 'msqrt', 'msrow', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'semantics', 'annotation', 'annotation-xml']);
|
|
11
|
+
const isNS = el => el.namespaceURI === SVG_NS || el.namespaceURI === MATH_NS;
|
|
12
|
+
const createNode = name => {
|
|
13
|
+
if (name === 'text') return document.createTextNode('');
|
|
14
|
+
if (MATH_TAGS.has(name)) return document.createElementNS(MATH_NS, name);
|
|
15
|
+
if (SVG_TAGS.has(name)) return document.createElementNS(SVG_NS, name);
|
|
16
|
+
return document.createElement(name);
|
|
17
|
+
};
|
|
18
|
+
const setProp = (node, key, value) => {
|
|
19
|
+
const el = node;
|
|
20
|
+
if (key === 'text') {
|
|
21
|
+
node.textContent = value;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (key.startsWith('on')) {
|
|
25
|
+
const evtName = key.slice(2);
|
|
26
|
+
node.addEventListener(evtName, value);
|
|
27
|
+
return () => node.removeEventListener(evtName, value);
|
|
28
|
+
}
|
|
29
|
+
if (key === 'class') {
|
|
30
|
+
if (value == null) {
|
|
31
|
+
el.className = '';
|
|
32
|
+
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
33
|
+
if (isNS(el)) {
|
|
34
|
+
const names = Object.entries(value).filter(([, v]) => !!v).map(([k]) => k).join(' ');
|
|
35
|
+
el.setAttribute('class', names);
|
|
36
|
+
} else {
|
|
37
|
+
for (const k in value) {
|
|
38
|
+
el.classList.toggle(k, !!value[k]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
const str = typeof value === 'boolean' ? value ? 'true' : '' : String(value);
|
|
43
|
+
if (isNS(el)) {
|
|
44
|
+
el.setAttribute('class', str);
|
|
45
|
+
} else {
|
|
46
|
+
el.className = str;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (key === 'style') {
|
|
52
|
+
if (value == null) {
|
|
53
|
+
el.style.cssText = '';
|
|
54
|
+
} else {
|
|
55
|
+
el.style.cssText = String(value);
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (key === 'html') {
|
|
60
|
+
node.innerHTML = value == null ? '' : String(value);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (BOOLEAN_ATTRS.has(key)) {
|
|
64
|
+
if (value === false || value === null || value === undefined) {
|
|
65
|
+
el.removeAttribute(key);
|
|
66
|
+
} else {
|
|
67
|
+
el.setAttribute(key, '');
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if ((key === 'value' || key === 'checked') && VALUE_PROP_TAGS.has(el.tagName)) {
|
|
72
|
+
el[key] = value;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (isNS(el)) {
|
|
76
|
+
if (value == null) {
|
|
77
|
+
el.removeAttribute(key);
|
|
78
|
+
} else {
|
|
79
|
+
el.setAttribute(key, String(value));
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (key.startsWith('data-') || key.startsWith('aria-')) {
|
|
84
|
+
if (value == null) {
|
|
85
|
+
el.removeAttribute(key);
|
|
86
|
+
} else {
|
|
87
|
+
el.setAttribute(key, String(value));
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (value == null) {
|
|
92
|
+
el.removeAttribute(key);
|
|
93
|
+
} else if (key in el) {
|
|
94
|
+
el[key] = value;
|
|
95
|
+
} else {
|
|
96
|
+
el.setAttribute(key, String(value));
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const insertAfter = (parent, node, prev) => {
|
|
100
|
+
if (!prev) parent.insertBefore(node, parent.firstChild);else parent.insertBefore(node, prev.nextSibling);
|
|
101
|
+
};
|
|
102
|
+
const createAnchor = name => document.createComment(name);
|
|
103
|
+
const remove = node => {
|
|
104
|
+
node.remove();
|
|
105
|
+
};
|
|
106
|
+
const firstChild = node => node.firstChild;
|
|
107
|
+
const nextSib = node => node.nextSibling;
|
|
108
|
+
const render = bobe.customRender({
|
|
109
|
+
createNode,
|
|
110
|
+
setProp,
|
|
111
|
+
insertAfter,
|
|
112
|
+
createAnchor,
|
|
113
|
+
remove,
|
|
114
|
+
firstChild,
|
|
115
|
+
nextSib
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
exports.BOOLEAN_ATTRS = BOOLEAN_ATTRS;
|
|
119
|
+
exports.createAnchor = createAnchor;
|
|
120
|
+
exports.createNode = createNode;
|
|
121
|
+
exports.firstChild = firstChild;
|
|
122
|
+
exports.insertAfter = insertAfter;
|
|
123
|
+
exports.nextSib = nextSib;
|
|
124
|
+
exports.remove = remove;
|
|
125
|
+
exports.render = render;
|
|
126
|
+
exports.setProp = setProp;
|
|
6
127
|
//# sourceMappingURL=bobe-dom.cjs.js.map
|
package/dist/bobe-dom.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bobe-dom.cjs.js","sources":["../src/index.ts"],"sourcesContent":["export const temp = 'temp'"],"names":["temp"],"mappings":";;AAAO,MAAOA,IAAI,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"bobe-dom.cjs.js","sources":["../src/render.ts"],"sourcesContent":["import { customRender } from 'bobe';\n\nexport const BOOLEAN_ATTRS = new Set([\n 'disabled', 'readonly', 'checked', 'selected', 'hidden',\n 'multiple', 'required', 'autofocus', 'autoplay', 'controls',\n 'loop', 'muted', 'defer', 'async', 'reversed', 'open',\n 'itemscope', 'ismap', 'nohref', 'noshade', 'nowrap', 'compact', 'default'\n]);\n\nconst VALUE_PROP_TAGS = new Set(['INPUT', 'TEXTAREA', 'SELECT']);\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML';\n\nconst SVG_TAGS = new Set([\n 'svg', 'animate', 'animateMotion', 'animateTransform', 'circle', 'clipPath',\n 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer',\n 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap',\n 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG',\n 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology',\n 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile',\n 'feTurbulence', 'filter', 'foreignObject', 'g', 'image', 'line', 'linearGradient',\n 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline',\n 'radialGradient', 'rect', 'set', 'stop', 'switch', 'symbol', 'textPath',\n 'tspan', 'use', 'view'\n]);\n\nconst MATH_TAGS = new Set([\n 'math', 'maction', 'maligngroup', 'malignmark', 'menclose', 'merror',\n 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mlongdiv', 'mmultiscripts',\n 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mscarries',\n 'mscarry', 'msgroup', 'mstack', 'mspace', 'msqrt', 'msrow', 'mstyle', 'msub',\n 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover',\n 'semantics', 'annotation', 'annotation-xml'\n]);\n\nconst isNS = (el: Element) => el.namespaceURI === SVG_NS || el.namespaceURI === MATH_NS;\n\n// ---- exported for unit testing ----\n\nexport const createNode = (name: string): Node => {\n if (name === 'text') return document.createTextNode('');\n if (MATH_TAGS.has(name)) return document.createElementNS(MATH_NS, name);\n if (SVG_TAGS.has(name)) return document.createElementNS(SVG_NS, name);\n return document.createElement(name);\n};\n\nexport const setProp = (node: Node, key: string, value: any): (() => void) | undefined => {\n const el = node as HTMLElement;\n\n // 0. text\n if (key === 'text') {\n node.textContent = value;\n return;\n }\n\n // 1. 事件\n if (key.startsWith('on')) {\n const evtName = key.slice(2);\n node.addEventListener(evtName, value);\n return () => node.removeEventListener(evtName, value);\n }\n\n // 2. class\n if (key === 'class') {\n if (value == null) {\n el.className = '';\n } else if (typeof value === 'object' && !Array.isArray(value)) {\n if (isNS(el)) {\n const names = Object.entries(value as Record<string, any>)\n .filter(([, v]) => !!v)\n .map(([k]) => k)\n .join(' ');\n el.setAttribute('class', names);\n } else {\n for (const k in value) {\n el.classList.toggle(k, !!(value as Record<string, any>)[k]);\n }\n }\n } else {\n const str = typeof value === 'boolean' ? (value ? 'true' : '') : String(value);\n if (isNS(el)) {\n el.setAttribute('class', str);\n } else {\n el.className = str;\n }\n }\n return;\n }\n\n // 3. style\n if (key === 'style') {\n if (value == null) {\n el.style.cssText = '';\n } else {\n el.style.cssText = String(value);\n }\n return;\n }\n\n // 4. html\n if (key === 'html') {\n (node as Element).innerHTML = value == null ? '' : String(value);\n return;\n }\n\n // 5. 布尔属性\n if (BOOLEAN_ATTRS.has(key)) {\n if (value === false || value === null || value === undefined) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, '');\n }\n return;\n }\n\n // 6. input/textarea/select value & checked\n if ((key === 'value' || key === 'checked') && VALUE_PROP_TAGS.has(el.tagName)) {\n (el as any)[key] = value;\n return;\n }\n\n // 7. SVG/MathML 元素\n if (isNS(el)) {\n if (value == null) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, String(value));\n }\n return;\n }\n\n // 8. data-* / aria-*\n if (key.startsWith('data-') || key.startsWith('aria-')) {\n if (value == null) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, String(value));\n }\n return;\n }\n\n // 9. 其余属性\n if (value == null) {\n el.removeAttribute(key);\n } else if (key in el) {\n (el as any)[key] = value;\n } else {\n el.setAttribute(key, String(value));\n }\n};\n\nexport const insertAfter = (parent: Node, node: Node, prev: Node | null) => {\n if (!prev) parent.insertBefore(node, parent.firstChild);\n else parent.insertBefore(node, prev.nextSibling);\n};\n\nexport const createAnchor = (name: string) => document.createComment(name);\n\nexport const remove = (node: Node) => { (node as Element).remove(); };\n\nexport const firstChild = (node: Node) => node.firstChild;\n\nexport const nextSib = (node: Node) => node.nextSibling;\n\nexport const render = customRender({\n createNode,\n setProp,\n insertAfter,\n createAnchor,\n remove,\n firstChild,\n nextSib\n});\n"],"names":["BOOLEAN_ATTRS","Set","VALUE_PROP_TAGS","SVG_NS","MATH_NS","SVG_TAGS","MATH_TAGS","isNS","el","namespaceURI","createNode","name","document","createTextNode","has","createElementNS","createElement","setProp","node","key","value","textContent","startsWith","evtName","slice","addEventListener","removeEventListener","className","Array","isArray","names","Object","entries","filter","v","map","k","join","setAttribute","classList","toggle","str","String","style","cssText","innerHTML","undefined","removeAttribute","tagName","insertAfter","parent","prev","insertBefore","firstChild","nextSibling","createAnchor","createComment","remove","nextSib","render","customRender"],"mappings":";;;;AAEO,MAAMA,aAAa,GAAG,IAAIC,GAAG,CAAC,CACnC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EACvD,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAC3D,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EACrD,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAC1E;AAED,MAAMC,eAAe,GAAG,IAAID,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAEhE,MAAME,MAAM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C;;;;;;;;;;;;"}
|
package/dist/bobe-dom.esm.js
CHANGED
|
@@ -1,4 +1,117 @@
|
|
|
1
|
-
|
|
1
|
+
import { customRender } from 'bobe';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const BOOLEAN_ATTRS = new Set(['disabled', 'readonly', 'checked', 'selected', 'hidden', 'multiple', 'required', 'autofocus', 'autoplay', 'controls', 'loop', 'muted', 'defer', 'async', 'reversed', 'open', 'itemscope', 'ismap', 'nohref', 'noshade', 'nowrap', 'compact', 'default']);
|
|
4
|
+
const VALUE_PROP_TAGS = new Set(['INPUT', 'TEXTAREA', 'SELECT']);
|
|
5
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
6
|
+
const MATH_NS = 'http://www.w3.org/1998/Math/MathML';
|
|
7
|
+
const SVG_TAGS = new Set(['svg', 'animate', 'animateMotion', 'animateTransform', 'circle', 'clipPath', 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence', 'filter', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'set', 'stop', 'switch', 'symbol', 'textPath', 'tspan', 'use', 'view']);
|
|
8
|
+
const MATH_TAGS = new Set(['math', 'maction', 'maligngroup', 'malignmark', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mlongdiv', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'mspace', 'msqrt', 'msrow', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'semantics', 'annotation', 'annotation-xml']);
|
|
9
|
+
const isNS = el => el.namespaceURI === SVG_NS || el.namespaceURI === MATH_NS;
|
|
10
|
+
const createNode = name => {
|
|
11
|
+
if (name === 'text') return document.createTextNode('');
|
|
12
|
+
if (MATH_TAGS.has(name)) return document.createElementNS(MATH_NS, name);
|
|
13
|
+
if (SVG_TAGS.has(name)) return document.createElementNS(SVG_NS, name);
|
|
14
|
+
return document.createElement(name);
|
|
15
|
+
};
|
|
16
|
+
const setProp = (node, key, value) => {
|
|
17
|
+
const el = node;
|
|
18
|
+
if (key === 'text') {
|
|
19
|
+
node.textContent = value;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (key.startsWith('on')) {
|
|
23
|
+
const evtName = key.slice(2);
|
|
24
|
+
node.addEventListener(evtName, value);
|
|
25
|
+
return () => node.removeEventListener(evtName, value);
|
|
26
|
+
}
|
|
27
|
+
if (key === 'class') {
|
|
28
|
+
if (value == null) {
|
|
29
|
+
el.className = '';
|
|
30
|
+
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
31
|
+
if (isNS(el)) {
|
|
32
|
+
const names = Object.entries(value).filter(([, v]) => !!v).map(([k]) => k).join(' ');
|
|
33
|
+
el.setAttribute('class', names);
|
|
34
|
+
} else {
|
|
35
|
+
for (const k in value) {
|
|
36
|
+
el.classList.toggle(k, !!value[k]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
const str = typeof value === 'boolean' ? value ? 'true' : '' : String(value);
|
|
41
|
+
if (isNS(el)) {
|
|
42
|
+
el.setAttribute('class', str);
|
|
43
|
+
} else {
|
|
44
|
+
el.className = str;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (key === 'style') {
|
|
50
|
+
if (value == null) {
|
|
51
|
+
el.style.cssText = '';
|
|
52
|
+
} else {
|
|
53
|
+
el.style.cssText = String(value);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (key === 'html') {
|
|
58
|
+
node.innerHTML = value == null ? '' : String(value);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (BOOLEAN_ATTRS.has(key)) {
|
|
62
|
+
if (value === false || value === null || value === undefined) {
|
|
63
|
+
el.removeAttribute(key);
|
|
64
|
+
} else {
|
|
65
|
+
el.setAttribute(key, '');
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if ((key === 'value' || key === 'checked') && VALUE_PROP_TAGS.has(el.tagName)) {
|
|
70
|
+
el[key] = value;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (isNS(el)) {
|
|
74
|
+
if (value == null) {
|
|
75
|
+
el.removeAttribute(key);
|
|
76
|
+
} else {
|
|
77
|
+
el.setAttribute(key, String(value));
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (key.startsWith('data-') || key.startsWith('aria-')) {
|
|
82
|
+
if (value == null) {
|
|
83
|
+
el.removeAttribute(key);
|
|
84
|
+
} else {
|
|
85
|
+
el.setAttribute(key, String(value));
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (value == null) {
|
|
90
|
+
el.removeAttribute(key);
|
|
91
|
+
} else if (key in el) {
|
|
92
|
+
el[key] = value;
|
|
93
|
+
} else {
|
|
94
|
+
el.setAttribute(key, String(value));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const insertAfter = (parent, node, prev) => {
|
|
98
|
+
if (!prev) parent.insertBefore(node, parent.firstChild);else parent.insertBefore(node, prev.nextSibling);
|
|
99
|
+
};
|
|
100
|
+
const createAnchor = name => document.createComment(name);
|
|
101
|
+
const remove = node => {
|
|
102
|
+
node.remove();
|
|
103
|
+
};
|
|
104
|
+
const firstChild = node => node.firstChild;
|
|
105
|
+
const nextSib = node => node.nextSibling;
|
|
106
|
+
const render = customRender({
|
|
107
|
+
createNode,
|
|
108
|
+
setProp,
|
|
109
|
+
insertAfter,
|
|
110
|
+
createAnchor,
|
|
111
|
+
remove,
|
|
112
|
+
firstChild,
|
|
113
|
+
nextSib
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export { BOOLEAN_ATTRS, createAnchor, createNode, firstChild, insertAfter, nextSib, remove, render, setProp };
|
|
4
117
|
//# sourceMappingURL=bobe-dom.esm.js.map
|
package/dist/bobe-dom.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bobe-dom.esm.js","sources":["../src/index.ts"],"sourcesContent":["export const temp = 'temp'"],"names":["temp"],"mappings":"AAAO,MAAOA,IAAI,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"bobe-dom.esm.js","sources":["../src/render.ts"],"sourcesContent":["import { customRender } from 'bobe';\n\nexport const BOOLEAN_ATTRS = new Set([\n 'disabled', 'readonly', 'checked', 'selected', 'hidden',\n 'multiple', 'required', 'autofocus', 'autoplay', 'controls',\n 'loop', 'muted', 'defer', 'async', 'reversed', 'open',\n 'itemscope', 'ismap', 'nohref', 'noshade', 'nowrap', 'compact', 'default'\n]);\n\nconst VALUE_PROP_TAGS = new Set(['INPUT', 'TEXTAREA', 'SELECT']);\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML';\n\nconst SVG_TAGS = new Set([\n 'svg', 'animate', 'animateMotion', 'animateTransform', 'circle', 'clipPath',\n 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer',\n 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap',\n 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG',\n 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology',\n 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile',\n 'feTurbulence', 'filter', 'foreignObject', 'g', 'image', 'line', 'linearGradient',\n 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline',\n 'radialGradient', 'rect', 'set', 'stop', 'switch', 'symbol', 'textPath',\n 'tspan', 'use', 'view'\n]);\n\nconst MATH_TAGS = new Set([\n 'math', 'maction', 'maligngroup', 'malignmark', 'menclose', 'merror',\n 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mlongdiv', 'mmultiscripts',\n 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mscarries',\n 'mscarry', 'msgroup', 'mstack', 'mspace', 'msqrt', 'msrow', 'mstyle', 'msub',\n 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover',\n 'semantics', 'annotation', 'annotation-xml'\n]);\n\nconst isNS = (el: Element) => el.namespaceURI === SVG_NS || el.namespaceURI === MATH_NS;\n\n// ---- exported for unit testing ----\n\nexport const createNode = (name: string): Node => {\n if (name === 'text') return document.createTextNode('');\n if (MATH_TAGS.has(name)) return document.createElementNS(MATH_NS, name);\n if (SVG_TAGS.has(name)) return document.createElementNS(SVG_NS, name);\n return document.createElement(name);\n};\n\nexport const setProp = (node: Node, key: string, value: any): (() => void) | undefined => {\n const el = node as HTMLElement;\n\n // 0. text\n if (key === 'text') {\n node.textContent = value;\n return;\n }\n\n // 1. 事件\n if (key.startsWith('on')) {\n const evtName = key.slice(2);\n node.addEventListener(evtName, value);\n return () => node.removeEventListener(evtName, value);\n }\n\n // 2. class\n if (key === 'class') {\n if (value == null) {\n el.className = '';\n } else if (typeof value === 'object' && !Array.isArray(value)) {\n if (isNS(el)) {\n const names = Object.entries(value as Record<string, any>)\n .filter(([, v]) => !!v)\n .map(([k]) => k)\n .join(' ');\n el.setAttribute('class', names);\n } else {\n for (const k in value) {\n el.classList.toggle(k, !!(value as Record<string, any>)[k]);\n }\n }\n } else {\n const str = typeof value === 'boolean' ? (value ? 'true' : '') : String(value);\n if (isNS(el)) {\n el.setAttribute('class', str);\n } else {\n el.className = str;\n }\n }\n return;\n }\n\n // 3. style\n if (key === 'style') {\n if (value == null) {\n el.style.cssText = '';\n } else {\n el.style.cssText = String(value);\n }\n return;\n }\n\n // 4. html\n if (key === 'html') {\n (node as Element).innerHTML = value == null ? '' : String(value);\n return;\n }\n\n // 5. 布尔属性\n if (BOOLEAN_ATTRS.has(key)) {\n if (value === false || value === null || value === undefined) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, '');\n }\n return;\n }\n\n // 6. input/textarea/select value & checked\n if ((key === 'value' || key === 'checked') && VALUE_PROP_TAGS.has(el.tagName)) {\n (el as any)[key] = value;\n return;\n }\n\n // 7. SVG/MathML 元素\n if (isNS(el)) {\n if (value == null) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, String(value));\n }\n return;\n }\n\n // 8. data-* / aria-*\n if (key.startsWith('data-') || key.startsWith('aria-')) {\n if (value == null) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, String(value));\n }\n return;\n }\n\n // 9. 其余属性\n if (value == null) {\n el.removeAttribute(key);\n } else if (key in el) {\n (el as any)[key] = value;\n } else {\n el.setAttribute(key, String(value));\n }\n};\n\nexport const insertAfter = (parent: Node, node: Node, prev: Node | null) => {\n if (!prev) parent.insertBefore(node, parent.firstChild);\n else parent.insertBefore(node, prev.nextSibling);\n};\n\nexport const createAnchor = (name: string) => document.createComment(name);\n\nexport const remove = (node: Node) => { (node as Element).remove(); };\n\nexport const firstChild = (node: Node) => node.firstChild;\n\nexport const nextSib = (node: Node) => node.nextSibling;\n\nexport const render = customRender({\n createNode,\n setProp,\n insertAfter,\n createAnchor,\n remove,\n firstChild,\n nextSib\n});\n"],"names":["BOOLEAN_ATTRS","Set","VALUE_PROP_TAGS","SVG_NS","MATH_NS","SVG_TAGS","MATH_TAGS","isNS","el","namespaceURI","createNode","name","document","createTextNode","has","createElementNS","createElement","setProp","node","key","value","textContent","startsWith","evtName","slice","addEventListener","removeEventListener","className","Array","isArray","names","Object","entries","filter","v","map","k","join","setAttribute","classList","toggle","str","String","style","cssText","innerHTML","undefined","removeAttribute","tagName","insertAfter","parent","prev","insertBefore","firstChild","nextSibling","createAnchor","createComment","remove","nextSib","render","customRender"],"mappings":";;AAEO,MAAMA,aAAa,GAAG,IAAIC,GAAG,CAAC,CACnC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EACvD,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAC3D,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EACrD,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAC1E;AAED,MAAMC,eAAe,GAAG,IAAID,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAEhE,MAAME,MAAM,GAAG,4BAA4B;AAC3C,MAAMC,OAAO,GAAG,oCAAoC;AAEpD,MAAMC,QAAQ,GAAG,IAAIJ,GAAG,CAAC,CACvB,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,EAC3E,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,qBAAqB,EAC5E,aAAa,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,EAC3E,gBAAgB,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAC5E,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAChF,UAAU,EAAE,cAAc,EAAE,oBAAoB,EAAE,aAAa,EAAE,QAAQ,EAC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GAAG,EAAEuB,MAAM,CAACtB,KAAK,CAAC,CAAC;AACrC,EAAA;AACF;AAEO,MAAM6B,WAAW,GAAGA,CAACC,MAAY,EAAEhC,IAAU,EAAEiC,IAAiB,KAAK;EAC1E,IAAI,CAACA,IAAI,EAAED,MAAM,CAACE,YAAY,CAAClC,IAAI,EAAEgC,MAAM,CAACG,UAAU,CAAC,CAAC,KACnDH,MAAM,CAACE,YAAY,CAAClC,IAAI,EAAEiC,IAAI,CAACG,WAAW,CAAC;AAClD;AAEO,MAAMC,YAAY,GAAI5C,IAAY,IAAKC,QAAQ,CAAC4C,aAAa,CAAC7C,IAAI;AAElE,MAAM8C,MAAM,GAAIvC,IAAU,IAAK;EAAGA,IAAI,CAAauC,MAAM,EAAE;AAAE;MAEvDJ,UAAU,GAAInC,IAAU,IAAKA,IAAI,CAACmC;MAElCK,OAAO,GAAIxC,IAAU,IAAKA,IAAI,CAACoC;AAErC,MAAMK,MAAM,GAAGC,YAAY,CAAC;EACjClD,UAAU;EACVO,OAAO;EACPgC,WAAW;EACXM,YAAY;EACZE,MAAM;EACNJ,UAAU;AACVK,EAAAA;AACF,CAAC;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
import * as bobe from 'bobe';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
declare const BOOLEAN_ATTRS: Set<string>;
|
|
4
|
+
declare const createNode: (name: string) => Node;
|
|
5
|
+
declare const setProp: (node: Node, key: string, value: any) => (() => void) | undefined;
|
|
6
|
+
declare const insertAfter: (parent: Node, node: Node, prev: Node | null) => void;
|
|
7
|
+
declare const createAnchor: (name: string) => Comment;
|
|
8
|
+
declare const remove: (node: Node) => void;
|
|
9
|
+
declare const firstChild: (node: Node) => ChildNode;
|
|
10
|
+
declare const nextSib: (node: Node) => ChildNode;
|
|
11
|
+
declare const render: <T>(Ctor: typeof bobe.Store, root: any) => (({
|
|
12
|
+
data: any;
|
|
13
|
+
__logicType: bobe.FakeType;
|
|
14
|
+
realParent: any;
|
|
15
|
+
realBefore?: any;
|
|
16
|
+
realAfter?: any;
|
|
17
|
+
} & {
|
|
18
|
+
tokenizer: bobe.Tokenizer;
|
|
19
|
+
fragmentSnapshot?: ReturnType<bobe.Tokenizer["snapshot"]>;
|
|
20
|
+
resumeSnapshot?: ReturnType<bobe.Tokenizer["snapshot"]>;
|
|
21
|
+
}) | bobe.Store)[];
|
|
22
|
+
|
|
23
|
+
export { BOOLEAN_ATTRS, createAnchor, createNode, firstChild, insertAfter, nextSib, remove, render, setProp };
|
package/dist/index.umd.js
CHANGED
|
@@ -1,12 +1,131 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('bobe')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'bobe'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BobeDom = {}, global.Bobe));
|
|
5
|
+
})(this, (function (exports, bobe) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const BOOLEAN_ATTRS = new Set(['disabled', 'readonly', 'checked', 'selected', 'hidden', 'multiple', 'required', 'autofocus', 'autoplay', 'controls', 'loop', 'muted', 'defer', 'async', 'reversed', 'open', 'itemscope', 'ismap', 'nohref', 'noshade', 'nowrap', 'compact', 'default']);
|
|
8
|
+
const VALUE_PROP_TAGS = new Set(['INPUT', 'TEXTAREA', 'SELECT']);
|
|
9
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
10
|
+
const MATH_NS = 'http://www.w3.org/1998/Math/MathML';
|
|
11
|
+
const SVG_TAGS = new Set(['svg', 'animate', 'animateMotion', 'animateTransform', 'circle', 'clipPath', 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence', 'filter', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'set', 'stop', 'switch', 'symbol', 'textPath', 'tspan', 'use', 'view']);
|
|
12
|
+
const MATH_TAGS = new Set(['math', 'maction', 'maligngroup', 'malignmark', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mlongdiv', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'mspace', 'msqrt', 'msrow', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'semantics', 'annotation', 'annotation-xml']);
|
|
13
|
+
const isNS = el => el.namespaceURI === SVG_NS || el.namespaceURI === MATH_NS;
|
|
14
|
+
const createNode = name => {
|
|
15
|
+
if (name === 'text') return document.createTextNode('');
|
|
16
|
+
if (MATH_TAGS.has(name)) return document.createElementNS(MATH_NS, name);
|
|
17
|
+
if (SVG_TAGS.has(name)) return document.createElementNS(SVG_NS, name);
|
|
18
|
+
return document.createElement(name);
|
|
19
|
+
};
|
|
20
|
+
const setProp = (node, key, value) => {
|
|
21
|
+
const el = node;
|
|
22
|
+
if (key === 'text') {
|
|
23
|
+
node.textContent = value;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (key.startsWith('on')) {
|
|
27
|
+
const evtName = key.slice(2);
|
|
28
|
+
node.addEventListener(evtName, value);
|
|
29
|
+
return () => node.removeEventListener(evtName, value);
|
|
30
|
+
}
|
|
31
|
+
if (key === 'class') {
|
|
32
|
+
if (value == null) {
|
|
33
|
+
el.className = '';
|
|
34
|
+
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
35
|
+
if (isNS(el)) {
|
|
36
|
+
const names = Object.entries(value).filter(([, v]) => !!v).map(([k]) => k).join(' ');
|
|
37
|
+
el.setAttribute('class', names);
|
|
38
|
+
} else {
|
|
39
|
+
for (const k in value) {
|
|
40
|
+
el.classList.toggle(k, !!value[k]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
const str = typeof value === 'boolean' ? value ? 'true' : '' : String(value);
|
|
45
|
+
if (isNS(el)) {
|
|
46
|
+
el.setAttribute('class', str);
|
|
47
|
+
} else {
|
|
48
|
+
el.className = str;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (key === 'style') {
|
|
54
|
+
if (value == null) {
|
|
55
|
+
el.style.cssText = '';
|
|
56
|
+
} else {
|
|
57
|
+
el.style.cssText = String(value);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (key === 'html') {
|
|
62
|
+
node.innerHTML = value == null ? '' : String(value);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (BOOLEAN_ATTRS.has(key)) {
|
|
66
|
+
if (value === false || value === null || value === undefined) {
|
|
67
|
+
el.removeAttribute(key);
|
|
68
|
+
} else {
|
|
69
|
+
el.setAttribute(key, '');
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if ((key === 'value' || key === 'checked') && VALUE_PROP_TAGS.has(el.tagName)) {
|
|
74
|
+
el[key] = value;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (isNS(el)) {
|
|
78
|
+
if (value == null) {
|
|
79
|
+
el.removeAttribute(key);
|
|
80
|
+
} else {
|
|
81
|
+
el.setAttribute(key, String(value));
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (key.startsWith('data-') || key.startsWith('aria-')) {
|
|
86
|
+
if (value == null) {
|
|
87
|
+
el.removeAttribute(key);
|
|
88
|
+
} else {
|
|
89
|
+
el.setAttribute(key, String(value));
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (value == null) {
|
|
94
|
+
el.removeAttribute(key);
|
|
95
|
+
} else if (key in el) {
|
|
96
|
+
el[key] = value;
|
|
97
|
+
} else {
|
|
98
|
+
el.setAttribute(key, String(value));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const insertAfter = (parent, node, prev) => {
|
|
102
|
+
if (!prev) parent.insertBefore(node, parent.firstChild);else parent.insertBefore(node, prev.nextSibling);
|
|
103
|
+
};
|
|
104
|
+
const createAnchor = name => document.createComment(name);
|
|
105
|
+
const remove = node => {
|
|
106
|
+
node.remove();
|
|
107
|
+
};
|
|
108
|
+
const firstChild = node => node.firstChild;
|
|
109
|
+
const nextSib = node => node.nextSibling;
|
|
110
|
+
const render = bobe.customRender({
|
|
111
|
+
createNode,
|
|
112
|
+
setProp,
|
|
113
|
+
insertAfter,
|
|
114
|
+
createAnchor,
|
|
115
|
+
remove,
|
|
116
|
+
firstChild,
|
|
117
|
+
nextSib
|
|
118
|
+
});
|
|
8
119
|
|
|
9
|
-
|
|
120
|
+
exports.BOOLEAN_ATTRS = BOOLEAN_ATTRS;
|
|
121
|
+
exports.createAnchor = createAnchor;
|
|
122
|
+
exports.createNode = createNode;
|
|
123
|
+
exports.firstChild = firstChild;
|
|
124
|
+
exports.insertAfter = insertAfter;
|
|
125
|
+
exports.nextSib = nextSib;
|
|
126
|
+
exports.remove = remove;
|
|
127
|
+
exports.render = render;
|
|
128
|
+
exports.setProp = setProp;
|
|
10
129
|
|
|
11
130
|
}));
|
|
12
131
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["export const temp = 'temp'"],"names":["temp"],"mappings":";;;;;;AAAO,OAAOA,IAAI,GAAG;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/render.ts"],"sourcesContent":["import { customRender } from 'bobe';\n\nexport const BOOLEAN_ATTRS = new Set([\n 'disabled', 'readonly', 'checked', 'selected', 'hidden',\n 'multiple', 'required', 'autofocus', 'autoplay', 'controls',\n 'loop', 'muted', 'defer', 'async', 'reversed', 'open',\n 'itemscope', 'ismap', 'nohref', 'noshade', 'nowrap', 'compact', 'default'\n]);\n\nconst VALUE_PROP_TAGS = new Set(['INPUT', 'TEXTAREA', 'SELECT']);\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML';\n\nconst SVG_TAGS = new Set([\n 'svg', 'animate', 'animateMotion', 'animateTransform', 'circle', 'clipPath',\n 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer',\n 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap',\n 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG',\n 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology',\n 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile',\n 'feTurbulence', 'filter', 'foreignObject', 'g', 'image', 'line', 'linearGradient',\n 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline',\n 'radialGradient', 'rect', 'set', 'stop', 'switch', 'symbol', 'textPath',\n 'tspan', 'use', 'view'\n]);\n\nconst MATH_TAGS = new Set([\n 'math', 'maction', 'maligngroup', 'malignmark', 'menclose', 'merror',\n 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mlongdiv', 'mmultiscripts',\n 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mscarries',\n 'mscarry', 'msgroup', 'mstack', 'mspace', 'msqrt', 'msrow', 'mstyle', 'msub',\n 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover',\n 'semantics', 'annotation', 'annotation-xml'\n]);\n\nconst isNS = (el: Element) => el.namespaceURI === SVG_NS || el.namespaceURI === MATH_NS;\n\n// ---- exported for unit testing ----\n\nexport const createNode = (name: string): Node => {\n if (name === 'text') return document.createTextNode('');\n if (MATH_TAGS.has(name)) return document.createElementNS(MATH_NS, name);\n if (SVG_TAGS.has(name)) return document.createElementNS(SVG_NS, name);\n return document.createElement(name);\n};\n\nexport const setProp = (node: Node, key: string, value: any): (() => void) | undefined => {\n const el = node as HTMLElement;\n\n // 0. text\n if (key === 'text') {\n node.textContent = value;\n return;\n }\n\n // 1. 事件\n if (key.startsWith('on')) {\n const evtName = key.slice(2);\n node.addEventListener(evtName, value);\n return () => node.removeEventListener(evtName, value);\n }\n\n // 2. class\n if (key === 'class') {\n if (value == null) {\n el.className = '';\n } else if (typeof value === 'object' && !Array.isArray(value)) {\n if (isNS(el)) {\n const names = Object.entries(value as Record<string, any>)\n .filter(([, v]) => !!v)\n .map(([k]) => k)\n .join(' ');\n el.setAttribute('class', names);\n } else {\n for (const k in value) {\n el.classList.toggle(k, !!(value as Record<string, any>)[k]);\n }\n }\n } else {\n const str = typeof value === 'boolean' ? (value ? 'true' : '') : String(value);\n if (isNS(el)) {\n el.setAttribute('class', str);\n } else {\n el.className = str;\n }\n }\n return;\n }\n\n // 3. style\n if (key === 'style') {\n if (value == null) {\n el.style.cssText = '';\n } else {\n el.style.cssText = String(value);\n }\n return;\n }\n\n // 4. html\n if (key === 'html') {\n (node as Element).innerHTML = value == null ? '' : String(value);\n return;\n }\n\n // 5. 布尔属性\n if (BOOLEAN_ATTRS.has(key)) {\n if (value === false || value === null || value === undefined) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, '');\n }\n return;\n }\n\n // 6. input/textarea/select value & checked\n if ((key === 'value' || key === 'checked') && VALUE_PROP_TAGS.has(el.tagName)) {\n (el as any)[key] = value;\n return;\n }\n\n // 7. SVG/MathML 元素\n if (isNS(el)) {\n if (value == null) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, String(value));\n }\n return;\n }\n\n // 8. data-* / aria-*\n if (key.startsWith('data-') || key.startsWith('aria-')) {\n if (value == null) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, String(value));\n }\n return;\n }\n\n // 9. 其余属性\n if (value == null) {\n el.removeAttribute(key);\n } else if (key in el) {\n (el as any)[key] = value;\n } else {\n el.setAttribute(key, String(value));\n }\n};\n\nexport const insertAfter = (parent: Node, node: Node, prev: Node | null) => {\n if (!prev) parent.insertBefore(node, parent.firstChild);\n else parent.insertBefore(node, prev.nextSibling);\n};\n\nexport const createAnchor = (name: string) => document.createComment(name);\n\nexport const remove = (node: Node) => { (node as Element).remove(); };\n\nexport const firstChild = (node: Node) => node.firstChild;\n\nexport const nextSib = (node: Node) => node.nextSibling;\n\nexport const render = customRender({\n createNode,\n setProp,\n insertAfter,\n createAnchor,\n remove,\n firstChild,\n nextSib\n});\n"],"names":["BOOLEAN_ATTRS","Set","VALUE_PROP_TAGS","SVG_NS","MATH_NS","SVG_TAGS","MATH_TAGS","isNS","el","namespaceURI","createNode","name","document","createTextNode","has","createElementNS","createElement","setProp","node","key","value","textContent","startsWith","evtName","slice","addEventListener","removeEventListener","className","Array","isArray","names","Object","entries","filter","v","map","k","join","setAttribute","classList","toggle","str","String","style","cssText","innerHTML","undefined","removeAttribute","tagName","insertAfter","parent","prev","insertBefore","firstChild","nextSibling","createAnchor","createComment","remove","nextSib","render","customRender"],"mappings":";;;;;;AAEO,QAAMA,aAAa,GAAG,IAAIC,GAAG,CAAC,CACnC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EACvD,UAAU,EAAE,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AAI;AAElE,QAAM8C,MAAM,GAAIvC,IAAU,IAAK;IAAGA,IAAI,CAAauC,MAAM,EAAE;EAAE;QAEvDJ,UAAU,GAAInC,IAAU,IAAKA,IAAI,CAACmC;QAElCK,OAAO,GAAIxC,IAAU,IAAKA,IAAI,CAACoC;AAErC,QAAMK,MAAM,GAAGC,iBAAY,CAAC;IACjClD,UAAU;IACVO,OAAO;IACPgC,WAAW;IACXM,YAAY;IACZE,MAAM;IACNJ,UAAU;EACVK,EAAAA;EACF,CAAC;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bobe-dom",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.56",
|
|
4
4
|
"main": "dist/bobe-dom.cjs.js",
|
|
5
5
|
"module": "dist/bobe-dom.esm.js",
|
|
6
6
|
"browser": "dist/bobe-dom.umd.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"private": false,
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"bobe": "0.0.56"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"vitest": "^4.1.7"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
@@ -30,5 +30,10 @@
|
|
|
30
30
|
"url": "https://github.com/bobe-js/bobe/issues"
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/bobe-js/bobe#readme",
|
|
33
|
-
"description": "Bobe customize render for DOM"
|
|
34
|
-
|
|
33
|
+
"description": "Bobe customize render for DOM",
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "rm -rf ./dist && rollup -c",
|
|
36
|
+
"dev": "rollup -c -w",
|
|
37
|
+
"tw": "vitest"
|
|
38
|
+
}
|
|
39
|
+
}
|