@domql/brender 3.2.7
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/README.md +282 -0
- package/dist/cjs/env.js +57 -0
- package/dist/cjs/hydrate.js +472 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/keys.js +62 -0
- package/dist/cjs/load.js +82 -0
- package/dist/cjs/metadata.js +102 -0
- package/dist/cjs/render.js +341 -0
- package/dist/esm/env.js +38 -0
- package/dist/esm/hydrate.js +453 -0
- package/dist/esm/index.js +39 -0
- package/dist/esm/keys.js +43 -0
- package/dist/esm/load.js +63 -0
- package/dist/esm/metadata.js +83 -0
- package/dist/esm/render.js +311 -0
- package/env.js +43 -0
- package/hydrate.js +388 -0
- package/index.js +40 -0
- package/keys.js +54 -0
- package/load.js +81 -0
- package/metadata.js +117 -0
- package/package.json +48 -0
- package/render.js +386 -0
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var hydrate_exports = {};
|
|
19
|
+
__export(hydrate_exports, {
|
|
20
|
+
collectBrNodes: () => collectBrNodes,
|
|
21
|
+
hydrate: () => hydrate
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(hydrate_exports);
|
|
24
|
+
const collectBrNodes = (root) => {
|
|
25
|
+
const container = root || document;
|
|
26
|
+
const nodes = container.querySelectorAll("[data-br]");
|
|
27
|
+
const map = {};
|
|
28
|
+
nodes.forEach((node) => {
|
|
29
|
+
map[node.getAttribute("data-br")] = node;
|
|
30
|
+
});
|
|
31
|
+
return map;
|
|
32
|
+
};
|
|
33
|
+
const hydrate = (element, options = {}) => {
|
|
34
|
+
const {
|
|
35
|
+
root,
|
|
36
|
+
events: attachEvents = true,
|
|
37
|
+
renderEvents: fireRenderEvents = true,
|
|
38
|
+
emotion,
|
|
39
|
+
designSystem
|
|
40
|
+
} = options;
|
|
41
|
+
const brNodes = collectBrNodes(root);
|
|
42
|
+
const colorMap = designSystem?.color || {};
|
|
43
|
+
const mediaMap = designSystem?.media || {};
|
|
44
|
+
let linked = 0;
|
|
45
|
+
let unlinked = 0;
|
|
46
|
+
const walk = (el) => {
|
|
47
|
+
if (!el || !el.__ref) return;
|
|
48
|
+
const brKey = el.__ref.__brKey;
|
|
49
|
+
if (brKey) {
|
|
50
|
+
const node = brNodes[brKey];
|
|
51
|
+
if (node) {
|
|
52
|
+
el.node = node;
|
|
53
|
+
node.ref = el;
|
|
54
|
+
if (emotion) {
|
|
55
|
+
renderCSS(el, emotion, colorMap, mediaMap);
|
|
56
|
+
}
|
|
57
|
+
if (attachEvents) {
|
|
58
|
+
bindEvents(el);
|
|
59
|
+
}
|
|
60
|
+
linked++;
|
|
61
|
+
} else {
|
|
62
|
+
unlinked++;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (el.__ref.__children) {
|
|
66
|
+
for (const childKey of el.__ref.__children) {
|
|
67
|
+
const child = el[childKey];
|
|
68
|
+
if (child && child.__ref) walk(child);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
walk(element);
|
|
73
|
+
if (fireRenderEvents) {
|
|
74
|
+
fireLifecycle(element);
|
|
75
|
+
}
|
|
76
|
+
return { element, linked, unlinked };
|
|
77
|
+
};
|
|
78
|
+
const renderCSS = (el, emotion, colorMap, mediaMap) => {
|
|
79
|
+
const { node, props } = el;
|
|
80
|
+
if (!node || !props) return;
|
|
81
|
+
const css = {};
|
|
82
|
+
let hasCss = false;
|
|
83
|
+
for (const key in props) {
|
|
84
|
+
const val = props[key];
|
|
85
|
+
if (key.charCodeAt(0) === 64) {
|
|
86
|
+
const breakpoint = mediaMap[key.slice(1)];
|
|
87
|
+
if (breakpoint && typeof val === "object") {
|
|
88
|
+
const mediaCss = resolvePropsToCSS(val, colorMap);
|
|
89
|
+
if (Object.keys(mediaCss).length) {
|
|
90
|
+
css[breakpoint] = mediaCss;
|
|
91
|
+
hasCss = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (key.charCodeAt(0) === 58) {
|
|
97
|
+
if (typeof val === "object") {
|
|
98
|
+
const pseudoCss = resolvePropsToCSS(val, colorMap);
|
|
99
|
+
if (Object.keys(pseudoCss).length) {
|
|
100
|
+
css["&" + key] = pseudoCss;
|
|
101
|
+
hasCss = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const expanded = resolveShorthand(key, val);
|
|
107
|
+
if (expanded) {
|
|
108
|
+
for (const ek in expanded) {
|
|
109
|
+
css[ek] = resolveValue(ek, expanded[ek], colorMap);
|
|
110
|
+
}
|
|
111
|
+
hasCss = true;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!isCSS(key)) continue;
|
|
115
|
+
css[key] = resolveValue(key, val, colorMap);
|
|
116
|
+
hasCss = true;
|
|
117
|
+
}
|
|
118
|
+
if (el.style && typeof el.style === "object") {
|
|
119
|
+
Object.assign(css, el.style);
|
|
120
|
+
hasCss = true;
|
|
121
|
+
}
|
|
122
|
+
if (!hasCss) return;
|
|
123
|
+
const emotionClass = emotion.css(css);
|
|
124
|
+
const classes = [];
|
|
125
|
+
if (emotionClass) classes.push(emotionClass);
|
|
126
|
+
if (typeof el.key === "string" && el.key.charCodeAt(0) === 95 && el.key.charCodeAt(1) !== 95) {
|
|
127
|
+
classes.push(el.key.slice(1));
|
|
128
|
+
}
|
|
129
|
+
if (props.class) classes.push(props.class);
|
|
130
|
+
if (el.attr?.class) classes.push(el.attr.class);
|
|
131
|
+
const classlist = el.classlist;
|
|
132
|
+
if (classlist) {
|
|
133
|
+
if (typeof classlist === "string") classes.push(classlist);
|
|
134
|
+
else if (typeof classlist === "object") {
|
|
135
|
+
for (const k in classlist) {
|
|
136
|
+
const v = classlist[k];
|
|
137
|
+
if (typeof v === "boolean" && v) classes.push(k);
|
|
138
|
+
else if (typeof v === "string") classes.push(v);
|
|
139
|
+
else if (typeof v === "object" && v) classes.push(emotion.css(v));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (classes.length) {
|
|
144
|
+
node.setAttribute("class", classes.join(" "));
|
|
145
|
+
}
|
|
146
|
+
for (const key in props) {
|
|
147
|
+
if (isCSS(key) && node.hasAttribute(key)) {
|
|
148
|
+
node.removeAttribute(key);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const resolvePropsToCSS = (propsObj, colorMap) => {
|
|
153
|
+
const css = {};
|
|
154
|
+
for (const key in propsObj) {
|
|
155
|
+
const expanded = resolveShorthand(key, propsObj[key]);
|
|
156
|
+
if (expanded) {
|
|
157
|
+
for (const ek in expanded) css[ek] = resolveValue(ek, expanded[ek], colorMap);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (!isCSS(key)) continue;
|
|
161
|
+
css[key] = resolveValue(key, propsObj[key], colorMap);
|
|
162
|
+
}
|
|
163
|
+
return css;
|
|
164
|
+
};
|
|
165
|
+
const COLOR_PROPS = /* @__PURE__ */ new Set([
|
|
166
|
+
"color",
|
|
167
|
+
"background",
|
|
168
|
+
"backgroundColor",
|
|
169
|
+
"borderColor",
|
|
170
|
+
"borderTopColor",
|
|
171
|
+
"borderRightColor",
|
|
172
|
+
"borderBottomColor",
|
|
173
|
+
"borderLeftColor",
|
|
174
|
+
"outlineColor",
|
|
175
|
+
"fill",
|
|
176
|
+
"stroke",
|
|
177
|
+
"caretColor",
|
|
178
|
+
"columnRuleColor",
|
|
179
|
+
"textDecorationColor",
|
|
180
|
+
"boxShadow",
|
|
181
|
+
"textShadow"
|
|
182
|
+
]);
|
|
183
|
+
const resolveValue = (key, val, colorMap) => {
|
|
184
|
+
if (typeof val !== "string") return val;
|
|
185
|
+
if (COLOR_PROPS.has(key) && colorMap[val]) return colorMap[val];
|
|
186
|
+
return val;
|
|
187
|
+
};
|
|
188
|
+
const NON_CSS_PROPS = /* @__PURE__ */ new Set([
|
|
189
|
+
"href",
|
|
190
|
+
"src",
|
|
191
|
+
"alt",
|
|
192
|
+
"title",
|
|
193
|
+
"id",
|
|
194
|
+
"name",
|
|
195
|
+
"type",
|
|
196
|
+
"value",
|
|
197
|
+
"placeholder",
|
|
198
|
+
"target",
|
|
199
|
+
"rel",
|
|
200
|
+
"loading",
|
|
201
|
+
"srcset",
|
|
202
|
+
"sizes",
|
|
203
|
+
"media",
|
|
204
|
+
"role",
|
|
205
|
+
"tabindex",
|
|
206
|
+
"for",
|
|
207
|
+
"action",
|
|
208
|
+
"method",
|
|
209
|
+
"enctype",
|
|
210
|
+
"autocomplete",
|
|
211
|
+
"autofocus",
|
|
212
|
+
"theme",
|
|
213
|
+
"__element",
|
|
214
|
+
"update"
|
|
215
|
+
]);
|
|
216
|
+
const resolveShorthand = (key, val) => {
|
|
217
|
+
if (key === "flexAlign" && typeof val === "string") {
|
|
218
|
+
const [alignItems, justifyContent] = val.split(" ");
|
|
219
|
+
return { display: "flex", alignItems, justifyContent };
|
|
220
|
+
}
|
|
221
|
+
if (key === "gridAlign" && typeof val === "string") {
|
|
222
|
+
const [alignItems, justifyContent] = val.split(" ");
|
|
223
|
+
return { display: "grid", alignItems, justifyContent };
|
|
224
|
+
}
|
|
225
|
+
if (key === "round" && val) {
|
|
226
|
+
return { borderRadius: typeof val === "number" ? val + "px" : val };
|
|
227
|
+
}
|
|
228
|
+
if (key === "boxSize" && val) {
|
|
229
|
+
return { width: val, height: val };
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
};
|
|
233
|
+
const isCSS = (key) => {
|
|
234
|
+
const ch = key.charCodeAt(0);
|
|
235
|
+
if (ch === 95 || ch === 64 || ch === 58) return false;
|
|
236
|
+
if (ch >= 65 && ch <= 90) return false;
|
|
237
|
+
if (NON_CSS_PROPS.has(key)) return false;
|
|
238
|
+
return CSS_PROPERTIES.has(key);
|
|
239
|
+
};
|
|
240
|
+
const CSS_PROPERTIES = /* @__PURE__ */ new Set([
|
|
241
|
+
"display",
|
|
242
|
+
"position",
|
|
243
|
+
"top",
|
|
244
|
+
"right",
|
|
245
|
+
"bottom",
|
|
246
|
+
"left",
|
|
247
|
+
"width",
|
|
248
|
+
"height",
|
|
249
|
+
"minWidth",
|
|
250
|
+
"maxWidth",
|
|
251
|
+
"minHeight",
|
|
252
|
+
"maxHeight",
|
|
253
|
+
"margin",
|
|
254
|
+
"marginTop",
|
|
255
|
+
"marginRight",
|
|
256
|
+
"marginBottom",
|
|
257
|
+
"marginLeft",
|
|
258
|
+
"marginBlock",
|
|
259
|
+
"marginInline",
|
|
260
|
+
"padding",
|
|
261
|
+
"paddingTop",
|
|
262
|
+
"paddingRight",
|
|
263
|
+
"paddingBottom",
|
|
264
|
+
"paddingLeft",
|
|
265
|
+
"paddingBlock",
|
|
266
|
+
"paddingInline",
|
|
267
|
+
"border",
|
|
268
|
+
"borderTop",
|
|
269
|
+
"borderRight",
|
|
270
|
+
"borderBottom",
|
|
271
|
+
"borderLeft",
|
|
272
|
+
"borderRadius",
|
|
273
|
+
"borderColor",
|
|
274
|
+
"borderWidth",
|
|
275
|
+
"borderStyle",
|
|
276
|
+
"borderTopWidth",
|
|
277
|
+
"borderRightWidth",
|
|
278
|
+
"borderBottomWidth",
|
|
279
|
+
"borderLeftWidth",
|
|
280
|
+
"borderTopStyle",
|
|
281
|
+
"borderRightStyle",
|
|
282
|
+
"borderBottomStyle",
|
|
283
|
+
"borderLeftStyle",
|
|
284
|
+
"borderTopColor",
|
|
285
|
+
"borderRightColor",
|
|
286
|
+
"borderBottomColor",
|
|
287
|
+
"borderLeftColor",
|
|
288
|
+
"borderTopLeftRadius",
|
|
289
|
+
"borderTopRightRadius",
|
|
290
|
+
"borderBottomLeftRadius",
|
|
291
|
+
"borderBottomRightRadius",
|
|
292
|
+
"background",
|
|
293
|
+
"backgroundColor",
|
|
294
|
+
"backgroundImage",
|
|
295
|
+
"backgroundSize",
|
|
296
|
+
"backgroundPosition",
|
|
297
|
+
"backgroundRepeat",
|
|
298
|
+
"backgroundAttachment",
|
|
299
|
+
"color",
|
|
300
|
+
"fontSize",
|
|
301
|
+
"fontWeight",
|
|
302
|
+
"fontFamily",
|
|
303
|
+
"fontStyle",
|
|
304
|
+
"lineHeight",
|
|
305
|
+
"letterSpacing",
|
|
306
|
+
"textAlign",
|
|
307
|
+
"textDecoration",
|
|
308
|
+
"textTransform",
|
|
309
|
+
"textIndent",
|
|
310
|
+
"textOverflow",
|
|
311
|
+
"textShadow",
|
|
312
|
+
"opacity",
|
|
313
|
+
"overflow",
|
|
314
|
+
"overflowX",
|
|
315
|
+
"overflowY",
|
|
316
|
+
"zIndex",
|
|
317
|
+
"cursor",
|
|
318
|
+
"pointerEvents",
|
|
319
|
+
"userSelect",
|
|
320
|
+
"flex",
|
|
321
|
+
"flexDirection",
|
|
322
|
+
"flexWrap",
|
|
323
|
+
"flexFlow",
|
|
324
|
+
"flexGrow",
|
|
325
|
+
"flexShrink",
|
|
326
|
+
"flexBasis",
|
|
327
|
+
"alignItems",
|
|
328
|
+
"alignContent",
|
|
329
|
+
"alignSelf",
|
|
330
|
+
"justifyContent",
|
|
331
|
+
"justifyItems",
|
|
332
|
+
"justifySelf",
|
|
333
|
+
"gap",
|
|
334
|
+
"rowGap",
|
|
335
|
+
"columnGap",
|
|
336
|
+
"gridTemplateColumns",
|
|
337
|
+
"gridTemplateRows",
|
|
338
|
+
"gridColumn",
|
|
339
|
+
"gridRow",
|
|
340
|
+
"gridArea",
|
|
341
|
+
"gridAutoFlow",
|
|
342
|
+
"gridAutoColumns",
|
|
343
|
+
"gridAutoRows",
|
|
344
|
+
"transform",
|
|
345
|
+
"transformOrigin",
|
|
346
|
+
"transition",
|
|
347
|
+
"animation",
|
|
348
|
+
"animationDelay",
|
|
349
|
+
"boxShadow",
|
|
350
|
+
"outline",
|
|
351
|
+
"outlineColor",
|
|
352
|
+
"outlineWidth",
|
|
353
|
+
"outlineStyle",
|
|
354
|
+
"outlineOffset",
|
|
355
|
+
"whiteSpace",
|
|
356
|
+
"wordBreak",
|
|
357
|
+
"wordWrap",
|
|
358
|
+
"overflowWrap",
|
|
359
|
+
"visibility",
|
|
360
|
+
"boxSizing",
|
|
361
|
+
"objectFit",
|
|
362
|
+
"objectPosition",
|
|
363
|
+
"filter",
|
|
364
|
+
"backdropFilter",
|
|
365
|
+
"mixBlendMode",
|
|
366
|
+
"fill",
|
|
367
|
+
"stroke",
|
|
368
|
+
"strokeWidth",
|
|
369
|
+
"listStyle",
|
|
370
|
+
"listStyleType",
|
|
371
|
+
"listStylePosition",
|
|
372
|
+
"counterReset",
|
|
373
|
+
"counterIncrement",
|
|
374
|
+
"content",
|
|
375
|
+
"aspectRatio",
|
|
376
|
+
"resize",
|
|
377
|
+
"appearance",
|
|
378
|
+
"scrollBehavior",
|
|
379
|
+
"scrollMargin",
|
|
380
|
+
"scrollPadding",
|
|
381
|
+
"willChange",
|
|
382
|
+
"contain",
|
|
383
|
+
"isolation",
|
|
384
|
+
"caretColor",
|
|
385
|
+
"accentColor",
|
|
386
|
+
"columnCount",
|
|
387
|
+
"columnGap",
|
|
388
|
+
"columnRuleColor",
|
|
389
|
+
"columnRuleStyle",
|
|
390
|
+
"columnRuleWidth",
|
|
391
|
+
"textDecorationColor",
|
|
392
|
+
"textDecorationStyle",
|
|
393
|
+
"textDecorationThickness",
|
|
394
|
+
"clipPath",
|
|
395
|
+
"shapeOutside"
|
|
396
|
+
]);
|
|
397
|
+
const DOMQL_LIFECYCLE = /* @__PURE__ */ new Set([
|
|
398
|
+
"render",
|
|
399
|
+
"create",
|
|
400
|
+
"init",
|
|
401
|
+
"start",
|
|
402
|
+
"complete",
|
|
403
|
+
"done",
|
|
404
|
+
"beforeClassAssign",
|
|
405
|
+
"attachNode",
|
|
406
|
+
"stateInit",
|
|
407
|
+
"stateCreated",
|
|
408
|
+
"renderRouter",
|
|
409
|
+
"lazyLoad",
|
|
410
|
+
"error"
|
|
411
|
+
]);
|
|
412
|
+
const bindEvents = (el) => {
|
|
413
|
+
const { node, on, props } = el;
|
|
414
|
+
if (!node) return;
|
|
415
|
+
const handled = /* @__PURE__ */ new Set();
|
|
416
|
+
if (on) {
|
|
417
|
+
for (const param in on) {
|
|
418
|
+
if (DOMQL_LIFECYCLE.has(param)) continue;
|
|
419
|
+
if (typeof on[param] !== "function") continue;
|
|
420
|
+
handled.add(param);
|
|
421
|
+
addListener(node, param, on[param], el);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (props) {
|
|
425
|
+
for (const key in props) {
|
|
426
|
+
if (key.length <= 2 || key[0] !== "o" || key[1] !== "n") continue;
|
|
427
|
+
if (typeof props[key] !== "function") continue;
|
|
428
|
+
const third = key[2];
|
|
429
|
+
if (third !== third.toUpperCase()) continue;
|
|
430
|
+
const eventName = third.toLowerCase() + key.slice(3);
|
|
431
|
+
if (handled.has(eventName) || DOMQL_LIFECYCLE.has(eventName)) continue;
|
|
432
|
+
addListener(node, eventName, props[key], el);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
const addListener = (node, eventName, handler, el) => {
|
|
437
|
+
node.addEventListener(eventName, (event) => {
|
|
438
|
+
const result = handler.call(el, event, el, el.state, el.context);
|
|
439
|
+
if (result && typeof result.then === "function") {
|
|
440
|
+
result.catch(() => {
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
const fireLifecycle = (el) => {
|
|
446
|
+
if (!el || !el.__ref || !el.node) return;
|
|
447
|
+
const on = el.on;
|
|
448
|
+
if (on) {
|
|
449
|
+
fireEvent(on.render, el);
|
|
450
|
+
fireEvent(on.renderRouter, el);
|
|
451
|
+
fireEvent(on.done, el);
|
|
452
|
+
fireEvent(on.create, el);
|
|
453
|
+
}
|
|
454
|
+
if (el.__ref.__children) {
|
|
455
|
+
for (const childKey of el.__ref.__children) {
|
|
456
|
+
const child = el[childKey];
|
|
457
|
+
if (child && child.__ref) fireLifecycle(child);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
const fireEvent = (fn, el) => {
|
|
462
|
+
if (typeof fn !== "function") return;
|
|
463
|
+
try {
|
|
464
|
+
const result = fn.call(el, el, el.state, el.context);
|
|
465
|
+
if (result && typeof result.then === "function") {
|
|
466
|
+
result.catch(() => {
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
} catch (e) {
|
|
470
|
+
console.warn("[brender hydrate]", el.key, e.message);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
__export(index_exports, {
|
|
20
|
+
assignKeys: () => import_keys.assignKeys,
|
|
21
|
+
collectBrNodes: () => import_hydrate.collectBrNodes,
|
|
22
|
+
createEnv: () => import_env.createEnv,
|
|
23
|
+
default: () => index_default,
|
|
24
|
+
extractMetadata: () => import_metadata.extractMetadata,
|
|
25
|
+
generateHeadHtml: () => import_metadata.generateHeadHtml,
|
|
26
|
+
hydrate: () => import_hydrate.hydrate,
|
|
27
|
+
loadAndRenderAll: () => import_load.loadAndRenderAll,
|
|
28
|
+
loadProject: () => import_load.loadProject,
|
|
29
|
+
mapKeysToElements: () => import_keys.mapKeysToElements,
|
|
30
|
+
render: () => import_render.render,
|
|
31
|
+
renderElement: () => import_render.renderElement,
|
|
32
|
+
renderPage: () => import_render.renderPage,
|
|
33
|
+
renderRoute: () => import_render.renderRoute,
|
|
34
|
+
resetKeys: () => import_keys.resetKeys
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_env = require("./env.js");
|
|
38
|
+
var import_keys = require("./keys.js");
|
|
39
|
+
var import_load = require("./load.js");
|
|
40
|
+
var import_render = require("./render.js");
|
|
41
|
+
var import_metadata = require("./metadata.js");
|
|
42
|
+
var import_hydrate = require("./hydrate.js");
|
|
43
|
+
var index_default = {
|
|
44
|
+
createEnv: import_env.createEnv,
|
|
45
|
+
resetKeys: import_keys.resetKeys,
|
|
46
|
+
assignKeys: import_keys.assignKeys,
|
|
47
|
+
mapKeysToElements: import_keys.mapKeysToElements,
|
|
48
|
+
loadProject: import_load.loadProject,
|
|
49
|
+
loadAndRenderAll: import_load.loadAndRenderAll,
|
|
50
|
+
render: import_render.render,
|
|
51
|
+
renderElement: import_render.renderElement,
|
|
52
|
+
renderRoute: import_render.renderRoute,
|
|
53
|
+
renderPage: import_render.renderPage,
|
|
54
|
+
extractMetadata: import_metadata.extractMetadata,
|
|
55
|
+
generateHeadHtml: import_metadata.generateHeadHtml,
|
|
56
|
+
collectBrNodes: import_hydrate.collectBrNodes,
|
|
57
|
+
hydrate: import_hydrate.hydrate
|
|
58
|
+
};
|
package/dist/cjs/keys.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var keys_exports = {};
|
|
19
|
+
__export(keys_exports, {
|
|
20
|
+
assignKeys: () => assignKeys,
|
|
21
|
+
mapKeysToElements: () => mapKeysToElements,
|
|
22
|
+
resetKeys: () => resetKeys
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(keys_exports);
|
|
25
|
+
let _keyCounter = 0;
|
|
26
|
+
const resetKeys = () => {
|
|
27
|
+
_keyCounter = 0;
|
|
28
|
+
};
|
|
29
|
+
const assignKeys = (node) => {
|
|
30
|
+
if (!node) return;
|
|
31
|
+
if (node.nodeType === 1) {
|
|
32
|
+
const key = `br-${_keyCounter++}`;
|
|
33
|
+
node.setAttribute("data-br", key);
|
|
34
|
+
}
|
|
35
|
+
const children = node.childNodes;
|
|
36
|
+
if (children) {
|
|
37
|
+
for (let i = 0; i < children.length; i++) {
|
|
38
|
+
assignKeys(children[i]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const mapKeysToElements = (element, registry = {}) => {
|
|
43
|
+
if (!element) return registry;
|
|
44
|
+
const node = element.node;
|
|
45
|
+
if (node && node.getAttribute) {
|
|
46
|
+
const brKey = node.getAttribute("data-br");
|
|
47
|
+
if (brKey) {
|
|
48
|
+
if (!element.__ref) element.__ref = {};
|
|
49
|
+
element.__ref.__brKey = brKey;
|
|
50
|
+
registry[brKey] = element;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (element.__ref && element.__ref.__children) {
|
|
54
|
+
for (const childKey of element.__ref.__children) {
|
|
55
|
+
const child = element[childKey];
|
|
56
|
+
if (child && child.__ref) {
|
|
57
|
+
mapKeysToElements(child, registry);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return registry;
|
|
62
|
+
};
|
package/dist/cjs/load.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var load_exports = {};
|
|
19
|
+
__export(load_exports, {
|
|
20
|
+
loadAndRenderAll: () => loadAndRenderAll,
|
|
21
|
+
loadProject: () => loadProject
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(load_exports);
|
|
24
|
+
var import_path = require("path");
|
|
25
|
+
const loadProject = async (projectPath) => {
|
|
26
|
+
const symbolsDir = (0, import_path.resolve)(projectPath, "symbols");
|
|
27
|
+
const tryImport = async (modulePath) => {
|
|
28
|
+
try {
|
|
29
|
+
return await import(modulePath);
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const [
|
|
35
|
+
appModule,
|
|
36
|
+
stateModule,
|
|
37
|
+
configModule,
|
|
38
|
+
depsModule,
|
|
39
|
+
componentsModule,
|
|
40
|
+
snippetsModule,
|
|
41
|
+
pagesModule,
|
|
42
|
+
functionsModule,
|
|
43
|
+
methodsModule,
|
|
44
|
+
designSystemModule,
|
|
45
|
+
filesModule
|
|
46
|
+
] = await Promise.all([
|
|
47
|
+
tryImport((0, import_path.join)(symbolsDir, "app.js")),
|
|
48
|
+
tryImport((0, import_path.join)(symbolsDir, "state.js")),
|
|
49
|
+
tryImport((0, import_path.join)(symbolsDir, "config.js")),
|
|
50
|
+
tryImport((0, import_path.join)(symbolsDir, "dependencies.js")),
|
|
51
|
+
tryImport((0, import_path.join)(symbolsDir, "components", "index.js")),
|
|
52
|
+
tryImport((0, import_path.join)(symbolsDir, "snippets", "index.js")),
|
|
53
|
+
tryImport((0, import_path.join)(symbolsDir, "pages", "index.js")),
|
|
54
|
+
tryImport((0, import_path.join)(symbolsDir, "functions", "index.js")),
|
|
55
|
+
tryImport((0, import_path.join)(symbolsDir, "methods", "index.js")),
|
|
56
|
+
tryImport((0, import_path.join)(symbolsDir, "designSystem", "index.js")),
|
|
57
|
+
tryImport((0, import_path.join)(symbolsDir, "files", "index.js"))
|
|
58
|
+
]);
|
|
59
|
+
return {
|
|
60
|
+
app: appModule?.default || {},
|
|
61
|
+
state: stateModule?.default || {},
|
|
62
|
+
dependencies: depsModule?.default || {},
|
|
63
|
+
components: componentsModule || {},
|
|
64
|
+
snippets: snippetsModule || {},
|
|
65
|
+
pages: pagesModule?.default || {},
|
|
66
|
+
functions: functionsModule || {},
|
|
67
|
+
methods: methodsModule || {},
|
|
68
|
+
designSystem: designSystemModule?.default || {},
|
|
69
|
+
files: filesModule?.default || {},
|
|
70
|
+
config: configModule?.default || {}
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
const loadAndRenderAll = async (projectPath, renderFn) => {
|
|
74
|
+
const data = await loadProject(projectPath);
|
|
75
|
+
const pages = data.pages || {};
|
|
76
|
+
const routes = Object.keys(pages);
|
|
77
|
+
const results = {};
|
|
78
|
+
for (const route of routes) {
|
|
79
|
+
results[route] = await renderFn(data, { route });
|
|
80
|
+
}
|
|
81
|
+
return results;
|
|
82
|
+
};
|