bobe-dom 0.0.67 → 0.0.69
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 +281 -0
- package/dist/bobe-dom.cjs.map +1 -0
- package/dist/bobe-dom.esm.js +28 -319
- package/dist/bobe-dom.esm.js.map +1 -1
- package/dist/{code.cjs.js → code.cjs} +3 -3
- package/dist/code.cjs.map +1 -0
- package/dist/code.esm.js +2 -2
- package/dist/code.esm.js.map +1 -1
- package/dist/iconify.cjs +442 -0
- package/dist/iconify.cjs.map +1 -0
- package/dist/iconify.d.ts +42 -0
- package/dist/iconify.esm.js +432 -0
- package/dist/iconify.esm.js.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -18
- package/dist/index.umd.js +40 -332
- package/dist/index.umd.js.map +1 -1
- package/dist/{markdown.cjs.js → markdown.cjs} +81 -15
- package/dist/markdown.cjs.map +1 -0
- package/dist/markdown.esm.js +80 -14
- package/dist/markdown.esm.js.map +1 -1
- package/dist/ssr-index.cjs +298 -0
- package/dist/ssr-index.cjs.map +1 -0
- package/dist/ssr-index.esm.js +295 -0
- package/dist/ssr-index.esm.js.map +1 -0
- package/package.json +19 -7
- package/dist/bobe-dom.cjs.js +0 -574
- package/dist/bobe-dom.cjs.js.map +0 -1
- package/dist/code.cjs.js.map +0 -1
- package/dist/markdown.cjs.js.map +0 -1
package/dist/bobe-dom.cjs.js
DELETED
|
@@ -1,574 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var bobe = require('bobe');
|
|
4
|
-
var htmlparser2 = require('htmlparser2');
|
|
5
|
-
|
|
6
|
-
const BOOLEAN_ATTRS$1 = 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']);
|
|
7
|
-
const VALUE_PROP_TAGS = new Set(['INPUT', 'TEXTAREA', 'SELECT']);
|
|
8
|
-
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
9
|
-
const MATH_NS = 'http://www.w3.org/1998/Math/MathML';
|
|
10
|
-
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']);
|
|
11
|
-
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']);
|
|
12
|
-
const isNS = el => el.namespaceURI === SVG_NS || el.namespaceURI === MATH_NS;
|
|
13
|
-
const createNode$1 = name => {
|
|
14
|
-
if (name === 'text') return document.createTextNode('');
|
|
15
|
-
if (MATH_TAGS.has(name)) return document.createElementNS(MATH_NS, name);
|
|
16
|
-
if (SVG_TAGS.has(name)) return document.createElementNS(SVG_NS, name);
|
|
17
|
-
return document.createElement(name);
|
|
18
|
-
};
|
|
19
|
-
const CONTENT_FLAG = Symbol('hasContent');
|
|
20
|
-
const setProp$1 = (node, key, value) => {
|
|
21
|
-
const el = node;
|
|
22
|
-
if (key === 'text') {
|
|
23
|
-
node[CONTENT_FLAG] = value != null;
|
|
24
|
-
if (value == null) return;
|
|
25
|
-
node.textContent = value;
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (key.startsWith('on')) {
|
|
29
|
-
const evtName = key.slice(2);
|
|
30
|
-
node.addEventListener(evtName, value);
|
|
31
|
-
return () => node.removeEventListener(evtName, value);
|
|
32
|
-
}
|
|
33
|
-
if (key.startsWith('.')) {
|
|
34
|
-
el.classList.toggle(key.slice(1), !!value);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (key.startsWith('#')) {
|
|
38
|
-
if (value) el.id = key.slice(1);else el.removeAttribute('id');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (key === 'class') {
|
|
42
|
-
if (value == null) {
|
|
43
|
-
el.className = '';
|
|
44
|
-
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
45
|
-
if (isNS(el)) {
|
|
46
|
-
const names = Object.entries(value).filter(([, v]) => !!v).map(([k]) => k).join(' ');
|
|
47
|
-
el.setAttribute('class', names);
|
|
48
|
-
} else {
|
|
49
|
-
for (const k in value) {
|
|
50
|
-
el.classList.toggle(k, !!value[k]);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
const str = typeof value === 'boolean' ? value ? 'true' : '' : String(value);
|
|
55
|
-
if (isNS(el)) {
|
|
56
|
-
el.setAttribute('class', str);
|
|
57
|
-
} else {
|
|
58
|
-
el.className = str;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (key === 'style') {
|
|
64
|
-
if (value == null) {
|
|
65
|
-
el.style.cssText = '';
|
|
66
|
-
} else {
|
|
67
|
-
el.style.cssText = String(value);
|
|
68
|
-
}
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (key === 'html') {
|
|
72
|
-
node[CONTENT_FLAG] = value != null;
|
|
73
|
-
if (value == null) return;
|
|
74
|
-
node.innerHTML = String(value);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (BOOLEAN_ATTRS$1.has(key)) {
|
|
78
|
-
if (value === false || value === null || value === undefined) {
|
|
79
|
-
el.removeAttribute(key);
|
|
80
|
-
} else {
|
|
81
|
-
el.setAttribute(key, '');
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if ((key === 'value' || key === 'checked') && VALUE_PROP_TAGS.has(el.tagName)) {
|
|
86
|
-
el[key] = value;
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (isNS(el)) {
|
|
90
|
-
if (value == null) {
|
|
91
|
-
el.removeAttribute(key);
|
|
92
|
-
} else {
|
|
93
|
-
el.setAttribute(key, String(value));
|
|
94
|
-
}
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (key.startsWith('data-') || key.startsWith('aria-')) {
|
|
98
|
-
if (value == null) {
|
|
99
|
-
el.removeAttribute(key);
|
|
100
|
-
} else {
|
|
101
|
-
el.setAttribute(key, String(value));
|
|
102
|
-
}
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (value == null) {
|
|
106
|
-
el.removeAttribute(key);
|
|
107
|
-
} else if (key in el) {
|
|
108
|
-
el[key] = value;
|
|
109
|
-
} else {
|
|
110
|
-
el.setAttribute(key, String(value));
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const insertAfter$1 = (parent, node, prev) => {
|
|
114
|
-
if (!prev) parent.insertBefore(node, parent.firstChild);else parent.insertBefore(node, prev.nextSibling);
|
|
115
|
-
};
|
|
116
|
-
const createAnchor$1 = name => document.createComment(name);
|
|
117
|
-
const remove$1 = node => {
|
|
118
|
-
node.remove();
|
|
119
|
-
};
|
|
120
|
-
const firstChild$1 = node => node.firstChild;
|
|
121
|
-
const nextSib$1 = node => node.nextSibling;
|
|
122
|
-
const beforeIndent$1 = node => {
|
|
123
|
-
if (node[CONTENT_FLAG]) {
|
|
124
|
-
const tag = node.tagName?.toLowerCase();
|
|
125
|
-
const hasText = node.textContent != null;
|
|
126
|
-
console.warn(`<${tag}> has ${hasText ? 'text' : 'html'} content and child elements — children ignored`);
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
const leaveNode = () => {};
|
|
131
|
-
const leaveLogicNode = () => {};
|
|
132
|
-
const render = bobe.customRender({
|
|
133
|
-
createNode: createNode$1,
|
|
134
|
-
setProp: setProp$1,
|
|
135
|
-
insertAfter: insertAfter$1,
|
|
136
|
-
createAnchor: createAnchor$1,
|
|
137
|
-
remove: remove$1,
|
|
138
|
-
firstChild: firstChild$1,
|
|
139
|
-
nextSib: nextSib$1,
|
|
140
|
-
beforeIndent: beforeIndent$1,
|
|
141
|
-
leaveNode,
|
|
142
|
-
leaveLogicNode
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
(function (SSRNodeType) {
|
|
146
|
-
SSRNodeType[SSRNodeType["Element"] = 0] = "Element";
|
|
147
|
-
SSRNodeType[SSRNodeType["Text"] = 1] = "Text";
|
|
148
|
-
SSRNodeType[SSRNodeType["Anchor"] = 2] = "Anchor";
|
|
149
|
-
SSRNodeType[SSRNodeType["Root"] = 3] = "Root";
|
|
150
|
-
return SSRNodeType;
|
|
151
|
-
})({});
|
|
152
|
-
class SSRFiber {
|
|
153
|
-
parent = undefined;
|
|
154
|
-
next = undefined;
|
|
155
|
-
child = undefined;
|
|
156
|
-
html = undefined;
|
|
157
|
-
openTagEnd = undefined;
|
|
158
|
-
constructor(type, props = {}) {
|
|
159
|
-
this.type = type;
|
|
160
|
-
this.props = props;
|
|
161
|
-
}
|
|
162
|
-
querySelector(selector) {
|
|
163
|
-
const idMatch = selector.match(/#([\w-]+)/);
|
|
164
|
-
const id = idMatch ? idMatch[1] : null;
|
|
165
|
-
const classMatches = selector.match(/\.[\w-]+/g);
|
|
166
|
-
const classes = classMatches ? classMatches.map(c => c.slice(1)) : [];
|
|
167
|
-
const tag = selector.replace(/#[\w-]+/g, '').replace(/\.[\w-]+/g, '').trim() || null;
|
|
168
|
-
const walk = node => {
|
|
169
|
-
if (!node) return null;
|
|
170
|
-
if (node.type !== 'root' && node.type !== 'anchor' && node.type !== 'text') {
|
|
171
|
-
if (!tag || node.type === tag) {
|
|
172
|
-
if (!id || node.props['id'] === id) {
|
|
173
|
-
if (classes.length === 0 || classes.every(c => (node.props['class'] || '').split(/\s+/).includes(c))) {
|
|
174
|
-
return node;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return walk(node.child) || walk(node.next);
|
|
180
|
-
};
|
|
181
|
-
return walk(this.child);
|
|
182
|
-
}
|
|
183
|
-
getElementById(id) {
|
|
184
|
-
return this.querySelector(`#${id}`);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function parseHtmlToFibers(html, root) {
|
|
189
|
-
const stack = [{
|
|
190
|
-
parent: root,
|
|
191
|
-
lastChild: null
|
|
192
|
-
}];
|
|
193
|
-
const append = node => {
|
|
194
|
-
const frame = stack[stack.length - 1];
|
|
195
|
-
if (!frame.parent.child) {
|
|
196
|
-
frame.parent.child = node;
|
|
197
|
-
} else if (frame.lastChild) {
|
|
198
|
-
frame.lastChild.next = node;
|
|
199
|
-
}
|
|
200
|
-
frame.lastChild = node;
|
|
201
|
-
node.parent = frame.parent;
|
|
202
|
-
};
|
|
203
|
-
let parserRef;
|
|
204
|
-
const parser = new htmlparser2.Parser({
|
|
205
|
-
onparserinit(p) {
|
|
206
|
-
parserRef = p;
|
|
207
|
-
},
|
|
208
|
-
onopentag(name, attribs) {
|
|
209
|
-
const fiber = new SSRFiber(name, {
|
|
210
|
-
...attribs
|
|
211
|
-
});
|
|
212
|
-
fiber.openTagEnd = parserRef.endIndex;
|
|
213
|
-
append(fiber);
|
|
214
|
-
stack.push({
|
|
215
|
-
parent: fiber,
|
|
216
|
-
lastChild: null
|
|
217
|
-
});
|
|
218
|
-
},
|
|
219
|
-
ontext(text) {
|
|
220
|
-
const fiber = new SSRFiber('text', {
|
|
221
|
-
text
|
|
222
|
-
});
|
|
223
|
-
append(fiber);
|
|
224
|
-
},
|
|
225
|
-
onclosetag() {
|
|
226
|
-
stack.pop();
|
|
227
|
-
const top = stack[stack.length - 1];
|
|
228
|
-
top.lastChild ?? null;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
parser.write(html);
|
|
232
|
-
parser.end();
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const VOID_TAGS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
236
|
-
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']);
|
|
237
|
-
const ATTR_RE = /[&"<>]/g;
|
|
238
|
-
const TEXT_RE = /[&<>]/g;
|
|
239
|
-
const ATTR_MAP = {
|
|
240
|
-
'&': '&',
|
|
241
|
-
'"': '"',
|
|
242
|
-
'<': '<',
|
|
243
|
-
'>': '>'
|
|
244
|
-
};
|
|
245
|
-
const TEXT_MAP = {
|
|
246
|
-
'&': '&',
|
|
247
|
-
'<': '<',
|
|
248
|
-
'>': '>'
|
|
249
|
-
};
|
|
250
|
-
const escapeAttr = str => {
|
|
251
|
-
const s = String(str);
|
|
252
|
-
return ATTR_RE.test(s) ? s.replace(ATTR_RE, m => ATTR_MAP[m]) : s;
|
|
253
|
-
};
|
|
254
|
-
const escapeText = str => {
|
|
255
|
-
const s = String(str);
|
|
256
|
-
return TEXT_RE.test(s) ? s.replace(TEXT_RE, m => TEXT_MAP[m]) : s;
|
|
257
|
-
};
|
|
258
|
-
const createNode = name => {
|
|
259
|
-
return new SSRFiber(name);
|
|
260
|
-
};
|
|
261
|
-
const setProp = (node, key, value) => {
|
|
262
|
-
node.props[key] = value;
|
|
263
|
-
if (key === 'html') {
|
|
264
|
-
parseHtmlToFibers(value, node);
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
const beforeIndent = node => {
|
|
268
|
-
if (node.props.html != null) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
const insertAfter = (parent, node, prev) => {
|
|
273
|
-
let next;
|
|
274
|
-
if (prev) {
|
|
275
|
-
next = prev.next;
|
|
276
|
-
prev.next = node;
|
|
277
|
-
} else {
|
|
278
|
-
next = parent.child;
|
|
279
|
-
parent.child = node;
|
|
280
|
-
}
|
|
281
|
-
node.next = next;
|
|
282
|
-
node.parent = parent;
|
|
283
|
-
};
|
|
284
|
-
const createAnchor = (name, isBefore) => {
|
|
285
|
-
return new SSRFiber('anchor', {
|
|
286
|
-
name,
|
|
287
|
-
isBefore
|
|
288
|
-
});
|
|
289
|
-
};
|
|
290
|
-
const remove = (node, prev) => {
|
|
291
|
-
const parent = node.parent,
|
|
292
|
-
next = node.next;
|
|
293
|
-
node.next = null;
|
|
294
|
-
if (prev) {
|
|
295
|
-
prev.next = next;
|
|
296
|
-
} else {
|
|
297
|
-
parent.child = next;
|
|
298
|
-
}
|
|
299
|
-
node.parent = null;
|
|
300
|
-
};
|
|
301
|
-
const firstChild = node => node.child;
|
|
302
|
-
const nextSib = node => node.next;
|
|
303
|
-
function walkFiber(root) {
|
|
304
|
-
let point = root;
|
|
305
|
-
let shouldSink = true;
|
|
306
|
-
sink: do {
|
|
307
|
-
if (point.type === 'root') {
|
|
308
|
-
point.html = '';
|
|
309
|
-
} else if (point.type === 'anchor') {
|
|
310
|
-
point.html = `<!--${point.props.name}-->`;
|
|
311
|
-
} else if (point.type === 'text') {
|
|
312
|
-
const text = point.props.text;
|
|
313
|
-
if (text != null) {
|
|
314
|
-
point.html = escapeText(point.props.text);
|
|
315
|
-
}
|
|
316
|
-
} else {
|
|
317
|
-
point.html = `<${point.type}`;
|
|
318
|
-
const props = point.props;
|
|
319
|
-
let text;
|
|
320
|
-
let classStr = '';
|
|
321
|
-
const dotClasses = [];
|
|
322
|
-
let idValue = null;
|
|
323
|
-
for (const key in props) {
|
|
324
|
-
const value = props[key];
|
|
325
|
-
if (key.startsWith('on') || key === 'ref') continue;
|
|
326
|
-
if (key === 'html') {
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
if (key === 'text') {
|
|
330
|
-
text = value;
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
if (key.startsWith('.')) {
|
|
334
|
-
if (value) dotClasses.push(key.slice(1));
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
if (key.startsWith('#')) {
|
|
338
|
-
if (value) idValue = key.slice(1);
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
if (key === 'class') {
|
|
342
|
-
if (value == null) continue;
|
|
343
|
-
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
344
|
-
classStr = Object.entries(value).filter(([, v]) => !!v).map(([k]) => k).join(' ');
|
|
345
|
-
} else {
|
|
346
|
-
classStr = typeof value === 'boolean' ? value ? 'true' : '' : String(value);
|
|
347
|
-
}
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
|
-
if (key === 'style') {
|
|
351
|
-
if (value == null) continue;
|
|
352
|
-
point.html += ` style="${escapeAttr(String(value))}"`;
|
|
353
|
-
continue;
|
|
354
|
-
}
|
|
355
|
-
if (BOOLEAN_ATTRS.has(key)) {
|
|
356
|
-
if (value !== false && value !== null && value !== undefined) {
|
|
357
|
-
point.html += ` ${key}`;
|
|
358
|
-
}
|
|
359
|
-
continue;
|
|
360
|
-
}
|
|
361
|
-
if (key.startsWith('data-') || key.startsWith('aria-')) {
|
|
362
|
-
if (value == null) continue;
|
|
363
|
-
point.html += ` ${key}="${escapeAttr(value)}"`;
|
|
364
|
-
continue;
|
|
365
|
-
}
|
|
366
|
-
if (value == null) continue;
|
|
367
|
-
point.html += ` ${key}="${escapeAttr(value)}"`;
|
|
368
|
-
}
|
|
369
|
-
if (dotClasses.length) {
|
|
370
|
-
classStr = (classStr ? classStr + ' ' : '') + dotClasses.join(' ');
|
|
371
|
-
}
|
|
372
|
-
if (classStr) {
|
|
373
|
-
point.html += ` class="${escapeAttr(classStr)}"`;
|
|
374
|
-
}
|
|
375
|
-
if (idValue) {
|
|
376
|
-
point.html += ` id="${escapeAttr(idValue)}"`;
|
|
377
|
-
}
|
|
378
|
-
if (text != null && props.html == null) {
|
|
379
|
-
const content = escapeText(text);
|
|
380
|
-
point.html += `>${content}</${point.type}>`;
|
|
381
|
-
if (point.child) console.warn(`<${point.type}> has text content and child elements — children ignored`);
|
|
382
|
-
shouldSink = false;
|
|
383
|
-
} else {
|
|
384
|
-
if (VOID_TAGS.has(point.type)) {
|
|
385
|
-
point.html += `/>`;
|
|
386
|
-
if (point.child) console.warn(`<${point.type}> can't have children`);
|
|
387
|
-
shouldSink = false;
|
|
388
|
-
} else {
|
|
389
|
-
point.html += `>`;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
if (point.child && shouldSink) {
|
|
394
|
-
point = point.child;
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
do {
|
|
398
|
-
const notRoot = point !== root;
|
|
399
|
-
const notAnchor = point.type !== 'anchor';
|
|
400
|
-
const notText = point.type !== 'text';
|
|
401
|
-
if (shouldSink && notRoot && notAnchor && notText) {
|
|
402
|
-
point.html += `</${point.type}>`;
|
|
403
|
-
}
|
|
404
|
-
if (notRoot) {
|
|
405
|
-
point.parent.html += point.html;
|
|
406
|
-
}
|
|
407
|
-
shouldSink = true;
|
|
408
|
-
if (!notRoot) break sink;
|
|
409
|
-
if (point.next) {
|
|
410
|
-
point = point.next;
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
point = point.parent;
|
|
414
|
-
} while (true);
|
|
415
|
-
} while (true);
|
|
416
|
-
}
|
|
417
|
-
const renderHtmlStr = ComponentClass => {
|
|
418
|
-
const root = new SSRFiber('root');
|
|
419
|
-
const render = bobe.customRender({
|
|
420
|
-
createNode,
|
|
421
|
-
setProp,
|
|
422
|
-
insertAfter,
|
|
423
|
-
createAnchor,
|
|
424
|
-
remove,
|
|
425
|
-
firstChild,
|
|
426
|
-
nextSib,
|
|
427
|
-
beforeIndent,
|
|
428
|
-
noopEffect: true
|
|
429
|
-
});
|
|
430
|
-
render(ComponentClass, root);
|
|
431
|
-
walkFiber(root);
|
|
432
|
-
return root.html;
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
class TreeCursor {
|
|
436
|
-
claimed = new WeakSet();
|
|
437
|
-
current = null;
|
|
438
|
-
constructor(container) {
|
|
439
|
-
this.parent = container;
|
|
440
|
-
}
|
|
441
|
-
enterChildren(node) {
|
|
442
|
-
this.parent = node;
|
|
443
|
-
this.current = null;
|
|
444
|
-
}
|
|
445
|
-
setParent(node) {
|
|
446
|
-
this.parent = node;
|
|
447
|
-
this.current = null;
|
|
448
|
-
}
|
|
449
|
-
setCurrent(node) {
|
|
450
|
-
this.current = node;
|
|
451
|
-
}
|
|
452
|
-
leaveToParent(node) {
|
|
453
|
-
if (node === this.parent && this.parent.parentNode) {
|
|
454
|
-
this.parent = this.parent.parentNode;
|
|
455
|
-
this.current = node;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
findUnclaimed(predicate) {
|
|
459
|
-
let node = this.current?.nextSibling || this.parent.firstChild;
|
|
460
|
-
while (node) {
|
|
461
|
-
if (!this.claimed.has(node) && predicate(node)) {
|
|
462
|
-
this.claimed.add(node);
|
|
463
|
-
this.current = node;
|
|
464
|
-
return node;
|
|
465
|
-
}
|
|
466
|
-
node = node.nextSibling;
|
|
467
|
-
}
|
|
468
|
-
return null;
|
|
469
|
-
}
|
|
470
|
-
tryClaimElement(tagName) {
|
|
471
|
-
return this.findUnclaimed(node => node.nodeType === 1 && node.tagName.toLowerCase() === tagName);
|
|
472
|
-
}
|
|
473
|
-
tryClaimComment(name) {
|
|
474
|
-
return this.findUnclaimed(node => node.nodeType === 8 && node.data === name);
|
|
475
|
-
}
|
|
476
|
-
tryClaimText() {
|
|
477
|
-
return this.findUnclaimed(node => node.nodeType === 3 && !!node.textContent?.trim());
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
const hydrate = (ComponentClass, rootEl) => {
|
|
481
|
-
const cursor = new TreeCursor(rootEl);
|
|
482
|
-
let isFirstRender = true;
|
|
483
|
-
const hydrateSetProp = (node, key, value) => {
|
|
484
|
-
if (isFirstRender && (key === 'text' || key === 'html')) {
|
|
485
|
-
node[CONTENT_FLAG] = value != null;
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
return setProp$1(node, key, value);
|
|
489
|
-
};
|
|
490
|
-
const createNode = name => {
|
|
491
|
-
if (isFirstRender) {
|
|
492
|
-
const claimed = name === 'text' ? cursor.tryClaimText() : cursor.tryClaimElement(name);
|
|
493
|
-
if (claimed) return claimed;
|
|
494
|
-
}
|
|
495
|
-
return name === 'text' ? document.createTextNode('') : createNode$1(name);
|
|
496
|
-
};
|
|
497
|
-
const createAnchor = name => {
|
|
498
|
-
if (isFirstRender) {
|
|
499
|
-
const claimed = cursor.tryClaimComment(name);
|
|
500
|
-
if (claimed) return claimed;
|
|
501
|
-
}
|
|
502
|
-
return document.createComment(name);
|
|
503
|
-
};
|
|
504
|
-
const insertAfter = (parent, node, prev) => {
|
|
505
|
-
if (node === parent) return;
|
|
506
|
-
const expectedNext = prev ? prev.nextSibling : parent.firstChild;
|
|
507
|
-
if (node === expectedNext) return;
|
|
508
|
-
parent.insertBefore(node, expectedNext);
|
|
509
|
-
};
|
|
510
|
-
const beforeIndent = node => {
|
|
511
|
-
if (node[CONTENT_FLAG]) {
|
|
512
|
-
const tag = node.tagName?.toLowerCase();
|
|
513
|
-
const hasText = node.textContent != null;
|
|
514
|
-
console.warn(`<${tag}> has ${hasText ? 'text' : 'html'} content and child elements — children ignored`);
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
if (isFirstRender) cursor.enterChildren(node);
|
|
518
|
-
};
|
|
519
|
-
const leaveNode = node => {
|
|
520
|
-
if (isFirstRender) cursor.leaveToParent(node);
|
|
521
|
-
};
|
|
522
|
-
const beforeLogicIndent = node => {
|
|
523
|
-
if (isFirstRender && node.tpData) {
|
|
524
|
-
const targetDom = node.tpData.node;
|
|
525
|
-
if (targetDom) cursor.enterChildren(targetDom);
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
const leaveLogicNode = (node, _isDedent) => {
|
|
529
|
-
if (isFirstRender && node.tpData) {
|
|
530
|
-
const parentDom = node.realAfter?.parentNode;
|
|
531
|
-
if (parentDom) {
|
|
532
|
-
cursor.setParent(parentDom);
|
|
533
|
-
if (node.realAfter) cursor.setCurrent(node.realAfter);
|
|
534
|
-
}
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
if (isFirstRender) cursor.leaveToParent(node);
|
|
538
|
-
};
|
|
539
|
-
const render = bobe.customRender({
|
|
540
|
-
createNode,
|
|
541
|
-
setProp: hydrateSetProp,
|
|
542
|
-
insertAfter,
|
|
543
|
-
createAnchor,
|
|
544
|
-
remove: remove$1,
|
|
545
|
-
firstChild: firstChild$1,
|
|
546
|
-
nextSib: nextSib$1,
|
|
547
|
-
beforeIndent,
|
|
548
|
-
beforeLogicIndent,
|
|
549
|
-
leaveNode,
|
|
550
|
-
leaveLogicNode,
|
|
551
|
-
onBeforeFlush: () => {
|
|
552
|
-
isFirstRender = false;
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
return render(ComponentClass, rootEl);
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
exports.BOOLEAN_ATTRS = BOOLEAN_ATTRS$1;
|
|
559
|
-
exports.CONTENT_FLAG = CONTENT_FLAG;
|
|
560
|
-
exports.beforeIndent = beforeIndent$1;
|
|
561
|
-
exports.createAnchor = createAnchor$1;
|
|
562
|
-
exports.createNode = createNode$1;
|
|
563
|
-
exports.firstChild = firstChild$1;
|
|
564
|
-
exports.hydrate = hydrate;
|
|
565
|
-
exports.insertAfter = insertAfter$1;
|
|
566
|
-
exports.leaveLogicNode = leaveLogicNode;
|
|
567
|
-
exports.leaveNode = leaveNode;
|
|
568
|
-
exports.nextSib = nextSib$1;
|
|
569
|
-
exports.remove = remove$1;
|
|
570
|
-
exports.render = render;
|
|
571
|
-
exports.renderHtmlStr = renderHtmlStr;
|
|
572
|
-
exports.setProp = setProp$1;
|
|
573
|
-
exports.walkFiber = walkFiber;
|
|
574
|
-
//# sourceMappingURL=bobe-dom.cjs.js.map
|