@estjs/template 0.0.11 → 0.0.12
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/template.cjs.js +18 -17
- package/dist/template.cjs.js.map +1 -1
- package/dist/template.d.cts +62 -32
- package/dist/template.d.ts +62 -32
- package/dist/template.dev.cjs.js +190 -110
- package/dist/template.dev.esm.js +190 -111
- package/dist/template.esm.js +6 -6
- package/dist/template.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/template.dev.esm.js
CHANGED
|
@@ -1,34 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isSignal, useSignal, useEffect,
|
|
1
|
+
import { startsWith, isFunction, isString, isArray, isNil, capitalizeFirstLetter, coerceArray, isSymbol, isFalsy, kebabCase, isObject, escape } from '@estjs/shared';
|
|
2
|
+
import { signalObject, useReactive, isSignal, useSignal, useEffect, shallowSignal } from '@estjs/signal';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @estjs/template v0.0.
|
|
5
|
+
* @estjs/template v0.0.12
|
|
6
6
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
7
7
|
* @license MIT
|
|
8
8
|
**/
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var _Hooks = class _Hooks {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.hooks = {
|
|
28
|
+
mounted: /* @__PURE__ */ new Set(),
|
|
29
|
+
destroy: /* @__PURE__ */ new Set()
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
addEventListener() {
|
|
33
|
+
}
|
|
34
|
+
removeEventListener() {
|
|
35
|
+
}
|
|
36
|
+
addHook(hook, cb) {
|
|
37
|
+
var _a;
|
|
38
|
+
(_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
|
|
39
|
+
}
|
|
40
|
+
getContext(context) {
|
|
41
|
+
return _Hooks.context[context];
|
|
42
|
+
}
|
|
43
|
+
setContext(context, value) {
|
|
44
|
+
_Hooks.context[context] = value;
|
|
45
|
+
}
|
|
46
|
+
initRef() {
|
|
47
|
+
_Hooks.ref = this;
|
|
48
|
+
}
|
|
49
|
+
removeRef() {
|
|
50
|
+
_Hooks.ref = null;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
_Hooks.ref = null;
|
|
54
|
+
_Hooks.context = {};
|
|
55
|
+
var Hooks = _Hooks;
|
|
56
|
+
var ComponentNode = class extends Hooks {
|
|
57
|
+
constructor(template2, props, key) {
|
|
58
|
+
super();
|
|
12
59
|
this.template = template2;
|
|
13
60
|
this.props = props;
|
|
61
|
+
this.key = key;
|
|
14
62
|
this.proxyProps = {};
|
|
15
|
-
this.context = {};
|
|
16
63
|
this.emitter = /* @__PURE__ */ new Set();
|
|
17
64
|
this.mounted = false;
|
|
18
65
|
this.rootNode = null;
|
|
19
|
-
this.
|
|
20
|
-
mounted: /* @__PURE__ */ new Set(),
|
|
21
|
-
destroy: /* @__PURE__ */ new Set()
|
|
22
|
-
};
|
|
66
|
+
this.context = {};
|
|
23
67
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
24
68
|
this.proxyProps = signalObject(
|
|
25
69
|
props,
|
|
26
|
-
(
|
|
70
|
+
(key2) => startsWith(key2, "on") || startsWith(key2, "update")
|
|
27
71
|
);
|
|
28
|
-
|
|
29
|
-
addEventListener() {
|
|
30
|
-
}
|
|
31
|
-
removeEventListener() {
|
|
72
|
+
this.key = this.key || props.key;
|
|
32
73
|
}
|
|
33
74
|
get firstChild() {
|
|
34
75
|
var _a, _b;
|
|
@@ -38,16 +79,6 @@ var _ComponentNode = class _ComponentNode {
|
|
|
38
79
|
var _a, _b;
|
|
39
80
|
return (_b = (_a = this.rootNode) == null ? void 0 : _a.isConnected) != null ? _b : false;
|
|
40
81
|
}
|
|
41
|
-
addHook(hook, cb) {
|
|
42
|
-
var _a;
|
|
43
|
-
(_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
|
|
44
|
-
}
|
|
45
|
-
getContext(context) {
|
|
46
|
-
return _ComponentNode.context[context];
|
|
47
|
-
}
|
|
48
|
-
setContext(context, value) {
|
|
49
|
-
_ComponentNode.context[context] = value;
|
|
50
|
-
}
|
|
51
82
|
inheritNode(node) {
|
|
52
83
|
this.context = node.context;
|
|
53
84
|
this.hooks = node.hooks;
|
|
@@ -66,9 +97,9 @@ var _ComponentNode = class _ComponentNode {
|
|
|
66
97
|
if (this.isConnected) {
|
|
67
98
|
return (_b = (_a = this.rootNode) == null ? void 0 : _a.mount(parent, before)) != null ? _b : [];
|
|
68
99
|
}
|
|
69
|
-
|
|
100
|
+
this.initRef();
|
|
70
101
|
this.rootNode = this.template(useReactive(this.proxyProps, ["children"]));
|
|
71
|
-
|
|
102
|
+
this.removeRef();
|
|
72
103
|
this.mounted = true;
|
|
73
104
|
const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
|
|
74
105
|
this.hooks.mounted.forEach((handler) => handler());
|
|
@@ -98,7 +129,7 @@ var _ComponentNode = class _ComponentNode {
|
|
|
98
129
|
return track;
|
|
99
130
|
}
|
|
100
131
|
patchProps(props) {
|
|
101
|
-
var _a, _b, _c, _d
|
|
132
|
+
var _a, _b, _c, _d;
|
|
102
133
|
for (const [key, prop] of Object.entries(props)) {
|
|
103
134
|
if (startsWith(key, "on") && ((_a = this.rootNode) == null ? void 0 : _a.nodes)) {
|
|
104
135
|
const event = key.slice(2).toLowerCase();
|
|
@@ -106,15 +137,11 @@ var _ComponentNode = class _ComponentNode {
|
|
|
106
137
|
const cleanup = addEventListener(this.rootNode.nodes[0], event, listener);
|
|
107
138
|
this.emitter.add(cleanup);
|
|
108
139
|
} else if (key === "ref") {
|
|
109
|
-
|
|
110
|
-
props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
|
|
111
|
-
} else if (isFunction(prop)) {
|
|
112
|
-
props[key]((_c = this.rootNode) == null ? void 0 : _c.nodes[0]);
|
|
113
|
-
}
|
|
140
|
+
props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
|
|
114
141
|
} else if (startsWith(key, "update")) {
|
|
115
142
|
props[key] = isSignal(prop) ? prop.value : prop;
|
|
116
143
|
} else if (key !== "children") {
|
|
117
|
-
const newValue = (
|
|
144
|
+
const newValue = (_d = (_c = this.proxyProps)[key]) != null ? _d : _c[key] = useSignal(prop);
|
|
118
145
|
const track = this.getNodeTrack(key);
|
|
119
146
|
track.cleanup = useEffect(() => {
|
|
120
147
|
newValue.value = isFunction(prop) ? prop() : prop;
|
|
@@ -124,12 +151,9 @@ var _ComponentNode = class _ComponentNode {
|
|
|
124
151
|
this.props = props;
|
|
125
152
|
}
|
|
126
153
|
};
|
|
127
|
-
_ComponentNode.ref = null;
|
|
128
|
-
_ComponentNode.context = {};
|
|
129
|
-
var ComponentNode = _ComponentNode;
|
|
130
154
|
|
|
131
155
|
// src/template.ts
|
|
132
|
-
function h(_template, props) {
|
|
156
|
+
function h(_template, props, key) {
|
|
133
157
|
if (isString(_template)) {
|
|
134
158
|
if (isHtmlTagName(_template)) {
|
|
135
159
|
_template = convertToHtmlTag(_template);
|
|
@@ -144,15 +168,17 @@ function h(_template, props) {
|
|
|
144
168
|
}
|
|
145
169
|
_template = template(_template);
|
|
146
170
|
}
|
|
147
|
-
return isFunction(_template) ? new ComponentNode(_template, props) : new TemplateNode(_template, props);
|
|
171
|
+
return isFunction(_template) ? new ComponentNode(_template, props, key) : new TemplateNode(_template, props, key);
|
|
172
|
+
}
|
|
173
|
+
function isComponent(node) {
|
|
174
|
+
return node instanceof ComponentNode;
|
|
148
175
|
}
|
|
149
176
|
function isJsxElement(node) {
|
|
150
177
|
return node instanceof ComponentNode || node instanceof TemplateNode;
|
|
151
178
|
}
|
|
152
179
|
function template(html) {
|
|
153
|
-
html = closeHtmlTags(html);
|
|
154
180
|
const template2 = document.createElement("template");
|
|
155
|
-
template2.innerHTML = html;
|
|
181
|
+
template2.innerHTML = closeHtmlTags(html);
|
|
156
182
|
return template2;
|
|
157
183
|
}
|
|
158
184
|
function Fragment(props) {
|
|
@@ -327,15 +353,6 @@ function convertToHtmlTag(tagName) {
|
|
|
327
353
|
return `<${tagName}></${tagName}>`;
|
|
328
354
|
}
|
|
329
355
|
}
|
|
330
|
-
function generateShortId() {
|
|
331
|
-
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
332
|
-
let result = "";
|
|
333
|
-
const charactersLength = characters.length;
|
|
334
|
-
for (let i = 0; i < 8; i++) {
|
|
335
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
336
|
-
}
|
|
337
|
-
return result;
|
|
338
|
-
}
|
|
339
356
|
|
|
340
357
|
// src/patch.ts
|
|
341
358
|
function patchChildren(parent, childrenMap, nextChildren, before) {
|
|
@@ -452,6 +469,7 @@ var TemplateNode = class _TemplateNode {
|
|
|
452
469
|
this.provides = {};
|
|
453
470
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
454
471
|
this.parent = null;
|
|
472
|
+
this.key = this.key || props.key;
|
|
455
473
|
}
|
|
456
474
|
get firstChild() {
|
|
457
475
|
var _a;
|
|
@@ -471,7 +489,6 @@ var TemplateNode = class _TemplateNode {
|
|
|
471
489
|
this.nodes.forEach((node) => insertChild(parent, node, before));
|
|
472
490
|
return this.nodes;
|
|
473
491
|
}
|
|
474
|
-
this.key = this.key || generateShortId();
|
|
475
492
|
const cloneNode = this.template.content.cloneNode(true);
|
|
476
493
|
const firstChild = cloneNode.firstChild;
|
|
477
494
|
if ((_a = firstChild == null ? void 0 : firstChild.hasAttribute) == null ? void 0 : _a.call(firstChild, "_svg_")) {
|
|
@@ -575,11 +592,7 @@ var TemplateNode = class _TemplateNode {
|
|
|
575
592
|
});
|
|
576
593
|
}
|
|
577
594
|
} else if (attr === "ref") {
|
|
578
|
-
|
|
579
|
-
props[attr].value = node;
|
|
580
|
-
} else if (isFunction(props[attr])) {
|
|
581
|
-
props[attr](node);
|
|
582
|
-
}
|
|
595
|
+
props[attr].value = node;
|
|
583
596
|
} else if (startsWith(attr, "on")) {
|
|
584
597
|
const eventName = attr.slice(2).toLocaleLowerCase();
|
|
585
598
|
const track = this.getNodeTrack(`${key}:${attr}`);
|
|
@@ -636,85 +649,151 @@ function patchChild(track, parent, child, before) {
|
|
|
636
649
|
});
|
|
637
650
|
}
|
|
638
651
|
}
|
|
639
|
-
|
|
640
|
-
// src/hooks.ts
|
|
641
652
|
function onMount(cb) {
|
|
642
653
|
var _a;
|
|
643
654
|
throwIfOutsideComponent("onMounted");
|
|
644
|
-
(_a =
|
|
655
|
+
(_a = Hooks.ref) == null ? void 0 : _a.addHook("mounted", cb);
|
|
645
656
|
}
|
|
646
657
|
function onDestroy(cb) {
|
|
647
658
|
var _a;
|
|
648
659
|
throwIfOutsideComponent("onDestroy");
|
|
649
|
-
(_a =
|
|
660
|
+
(_a = Hooks.ref) == null ? void 0 : _a.addHook("destroy", cb);
|
|
650
661
|
}
|
|
651
|
-
function throwIfOutsideComponent(hook) {
|
|
652
|
-
if (!
|
|
662
|
+
function throwIfOutsideComponent(hook, key) {
|
|
663
|
+
if (!Hooks.ref) {
|
|
653
664
|
console.error(
|
|
654
|
-
`"${hook}" can only be called within the component function body
|
|
665
|
+
`"${hook}"(key: ${isSymbol(key) ? key.toString() : key}) can only be called within the component function body
|
|
655
666
|
and cannot be used in asynchronous or deferred calls.`
|
|
656
667
|
);
|
|
657
668
|
}
|
|
658
669
|
}
|
|
659
670
|
function useProvide(key, value) {
|
|
660
671
|
var _a;
|
|
661
|
-
throwIfOutsideComponent("useProvide");
|
|
662
|
-
(_a =
|
|
672
|
+
throwIfOutsideComponent("useProvide", key);
|
|
673
|
+
(_a = Hooks.ref) == null ? void 0 : _a.setContext(key, value);
|
|
663
674
|
}
|
|
664
675
|
function useInject(key, defaultValue) {
|
|
665
676
|
var _a;
|
|
666
|
-
throwIfOutsideComponent("useInject");
|
|
667
|
-
return ((_a =
|
|
668
|
-
}
|
|
669
|
-
function
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
677
|
+
throwIfOutsideComponent("useInject", key);
|
|
678
|
+
return ((_a = Hooks.ref) == null ? void 0 : _a.getContext(key)) || defaultValue;
|
|
679
|
+
}
|
|
680
|
+
function useRef() {
|
|
681
|
+
const ref = shallowSignal(null);
|
|
682
|
+
return ref;
|
|
683
|
+
}
|
|
684
|
+
function generateAttributes(props) {
|
|
685
|
+
return Object.entries(props).map(([key, value]) => {
|
|
686
|
+
if (key === "children" || isFunction(value)) return "";
|
|
687
|
+
return `${key}="${escape(String(value))}"`;
|
|
688
|
+
}).filter(Boolean).join(" ");
|
|
689
|
+
}
|
|
690
|
+
function normalizeProps(props) {
|
|
691
|
+
Object.keys(props).forEach((propKey) => {
|
|
692
|
+
if (isFunction(props[propKey])) {
|
|
693
|
+
delete props[propKey];
|
|
694
|
+
}
|
|
695
|
+
if (isSignal(props[propKey])) {
|
|
696
|
+
props[propKey] = props[propKey].value;
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
function handleChildResult(result, prop, key, tmpl, childNodesMap, path) {
|
|
701
|
+
if (isSignal(result)) {
|
|
702
|
+
tmpl.template += result.value;
|
|
703
|
+
} else if (result instanceof ServerNode) {
|
|
704
|
+
const mapKey = path ? String(path) : `${key}`;
|
|
705
|
+
if (!childNodesMap[mapKey]) childNodesMap[mapKey] = [];
|
|
706
|
+
const childResult = result.mount();
|
|
707
|
+
childNodesMap[mapKey].push(
|
|
708
|
+
isFunction(childResult) ? childResult(prop) : isSignal(childResult) ? childResult.value : childResult
|
|
709
|
+
);
|
|
710
|
+
} else {
|
|
711
|
+
tmpl.template += isFunction(result) ? result(prop) : String(result);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
var ServerNode = class _ServerNode extends Hooks {
|
|
715
|
+
constructor(template2, props = {}, key) {
|
|
716
|
+
super();
|
|
717
|
+
this.template = template2;
|
|
718
|
+
this.props = props;
|
|
719
|
+
this.key = key;
|
|
720
|
+
this.childNodesMap = {};
|
|
721
|
+
this.processedTemplates = {};
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Mount and render the component
|
|
725
|
+
*/
|
|
726
|
+
mount() {
|
|
727
|
+
this.initRef();
|
|
728
|
+
const output = this.render();
|
|
729
|
+
this.removeRef();
|
|
730
|
+
return output;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Initialize template entries and props
|
|
734
|
+
*/
|
|
735
|
+
initTemplates() {
|
|
736
|
+
const templateCollection = Array.isArray(this.template) ? this.template.reduce((acc, tmpl, index) => {
|
|
737
|
+
acc[index + 1] = { template: tmpl };
|
|
738
|
+
return acc;
|
|
739
|
+
}, {}) : this.template;
|
|
740
|
+
if (isObject(templateCollection)) {
|
|
741
|
+
Object.entries(templateCollection).forEach(([key, tmpl]) => {
|
|
742
|
+
const prop = __spreadValues({}, this.props[key]);
|
|
743
|
+
normalizeProps(prop);
|
|
691
744
|
if (prop.children) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
745
|
+
prop.children.forEach((item) => {
|
|
746
|
+
const [child, path] = isArray(item) ? item : [item, null];
|
|
747
|
+
if (isFunction(child)) {
|
|
748
|
+
const result = child(prop);
|
|
749
|
+
handleChildResult(result, prop, key, tmpl, this.childNodesMap, path);
|
|
750
|
+
} else {
|
|
751
|
+
tmpl.template += isSignal(child) ? child.value : String(child);
|
|
752
|
+
}
|
|
753
|
+
});
|
|
697
754
|
}
|
|
698
|
-
|
|
699
|
-
|
|
755
|
+
this.processedTemplates[key] = {
|
|
756
|
+
template: tmpl.template,
|
|
757
|
+
props: prop
|
|
758
|
+
};
|
|
759
|
+
});
|
|
700
760
|
}
|
|
701
761
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
762
|
+
/**
|
|
763
|
+
* Render component and its children into a string
|
|
764
|
+
*/
|
|
765
|
+
render() {
|
|
766
|
+
if (isFunction(this.template)) {
|
|
767
|
+
const root = this.template(this.props);
|
|
768
|
+
return root instanceof _ServerNode ? root.mount() : String(root);
|
|
706
769
|
}
|
|
707
|
-
if (
|
|
708
|
-
|
|
770
|
+
if (this.template instanceof _ServerNode) {
|
|
771
|
+
return this.template.mount();
|
|
709
772
|
}
|
|
710
|
-
|
|
711
|
-
|
|
773
|
+
this.initTemplates();
|
|
774
|
+
return Object.entries(this.processedTemplates).map(([key, { template: template2, props }]) => {
|
|
775
|
+
let content = template2;
|
|
776
|
+
if (props && Object.keys(props).length > 0) {
|
|
777
|
+
content += ` ${generateAttributes(props)}`;
|
|
778
|
+
}
|
|
779
|
+
if (this.childNodesMap[key]) {
|
|
780
|
+
content = content.replace("<!>", this.renderChildren(this.childNodesMap[key]));
|
|
781
|
+
}
|
|
782
|
+
return content;
|
|
783
|
+
}).join("");
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Render child nodes into a string
|
|
787
|
+
*/
|
|
788
|
+
renderChildren(children) {
|
|
789
|
+
return coerceArray(children).map(String).join("");
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
function ssg(component, props) {
|
|
793
|
+
return new ServerNode(component, props);
|
|
712
794
|
}
|
|
713
795
|
function renderToString(component, props) {
|
|
714
|
-
return
|
|
715
|
-
}
|
|
716
|
-
function renderSSG(component, root, props = {}) {
|
|
717
|
-
root.innerHTML = renderTemplate(component, props);
|
|
796
|
+
return ssg(component, props).mount();
|
|
718
797
|
}
|
|
719
798
|
|
|
720
|
-
export { ComponentNode, Fragment, TemplateNode, h, isJsxElement, nextTick, onDestroy, onMount,
|
|
799
|
+
export { ComponentNode, Fragment, TemplateNode, h, isComponent, isJsxElement, nextTick, onDestroy, onMount, renderToString, ssg, template, useInject, useProvide, useRef };
|
package/dist/template.esm.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isSignal, useSignal, useEffect,
|
|
1
|
+
import { startsWith, isFunction, isString, isArray, isNil, capitalizeFirstLetter, coerceArray, isSymbol, isFalsy, kebabCase, isObject, escape } from '@estjs/shared';
|
|
2
|
+
import { signalObject, useReactive, isSignal, useSignal, useEffect, shallowSignal } from '@estjs/signal';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @estjs/template v0.0.
|
|
5
|
+
* @estjs/template v0.0.12
|
|
6
6
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
7
7
|
* @license MIT
|
|
8
8
|
**/
|
|
9
|
-
var N=class N{constructor(e,n){this.template=e;this.props=n;this.proxyProps={};this.context={};this.emitter=new Set;this.mounted=!1;this.rootNode=null;this.hooks={mounted:new Set,destroy:new Set};this.trackMap=new Map;this.proxyProps=signalObject(n,o=>startsWith(o,"on")||startsWith(o,"update"));}addEventListener(){}removeEventListener(){}get firstChild(){var e,n;return (n=(e=this.rootNode)==null?void 0:e.firstChild)!=null?n:null}get isConnected(){var e,n;return (n=(e=this.rootNode)==null?void 0:e.isConnected)!=null?n:!1}addHook(e,n){var o;(o=this.hooks[e])==null||o.add(n);}getContext(e){return N.context[e]}setContext(e,n){N.context[e]=n;}inheritNode(e){this.context=e.context,this.hooks=e.hooks,Object.assign(this.proxyProps,e.proxyProps),this.rootNode=e.rootNode,this.trackMap=e.trackMap;let n=this.props;this.props=e.props,this.patchProps(n);}mount(e,n){var r,s,c,i;if(!isFunction(this.template))throw new Error("Template must be a function");if(this.isConnected)return (s=(r=this.rootNode)==null?void 0:r.mount(e,n))!=null?s:[];N.ref=this,this.rootNode=this.template(useReactive(this.proxyProps,["children"])),N.ref=null,this.mounted=!0;let o=(i=(c=this.rootNode)==null?void 0:c.mount(e,n))!=null?i:[];return this.hooks.mounted.forEach(a=>a()),this.patchProps(this.props),o}unmount(){var e;this.hooks.destroy.forEach(n=>n()),Object.values(this.hooks).forEach(n=>n.clear()),(e=this.rootNode)==null||e.unmount(),this.rootNode=null,this.proxyProps={},this.mounted=!1,this.emitter.forEach(n=>n());}getNodeTrack(e,n){let o=this.trackMap.get(e);return o||(o={cleanup:()=>{}},this.trackMap.set(e,o)),n||o.cleanup(),o}patchProps(e){var n,o,r,s,c;for(let[i,a]of Object.entries(e))if(startsWith(i,"on")&&((n=this.rootNode)!=null&&n.nodes)){let u=i.slice(2).toLowerCase(),l=a,d=m(this.rootNode.nodes[0],u,l);this.emitter.add(d);}else if(i==="ref")isSignal(a)?e[i].value=(o=this.rootNode)==null?void 0:o.nodes[0]:isFunction(a)&&e[i]((r=this.rootNode)==null?void 0:r.nodes[0]);else if(startsWith(i,"update"))e[i]=isSignal(a)?a.value:a;else if(i!=="children"){let u=(c=(s=this.proxyProps)[i])!=null?c:s[i]=useSignal(a),l=this.getNodeTrack(i);l.cleanup=useEffect(()=>{u.value=isFunction(a)?a():a;});}this.props=e;}};N.ref=null,N.context={};var f=N;function ie(t,e){return isString(t)&&(O(t)&&(t=X(t),e={1:e}),t===""&&(e={0:e}),t=J(t)),isFunction(t)?new f(t,e):new E(t,e)}function h(t){return t instanceof f||t instanceof E}function J(t){t=F(t);let e=document.createElement("template");return e.innerHTML=t,e}function ce(t){return t.children}var D="area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr",le="a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,command,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,menu,menuitem,meta,meter,nav,nobr,noframes,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,section,select,shadow,small,source,spacer,span,strike,strong,style,sub,summary,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,xmp";function w(t){if(h(t)||t instanceof Node)return t;let e=isFalsy(t)?"":String(t);return document.createTextNode(e)}function g(t,e,n=null){let o=h(n)?n.firstChild:n;h(e)?e.mount(t,o):o?o.before(e):t.append(e);}function x(t){h(t)?t.unmount():t.parentNode&&t.remove();}function A(t,e,n){g(t,e,n),x(n);}function H(t,e,n){if(e==="class"){typeof n=="string"?t.className=n:Array.isArray(n)?t.className=n.join(" "):n&&typeof n=="object"&&(t.className=Object.entries(n).reduce((o,[r,s])=>o+(s?` ${r}`:""),"").trim());return}if(e==="style"){if(typeof n=="string")t.style.cssText=n;else if(n&&typeof n=="object"){let o=n;Object.keys(o).forEach(r=>{t.style.setProperty(kebabCase(r),String(o[r]));});}return}isFalsy(n)?t.removeAttribute(e):n===!0?t.setAttribute(e,""):t instanceof HTMLInputElement?t.value=String(n):t.setAttribute(e,String(n));}function q(t,e){if(t instanceof HTMLInputElement)switch(t.type){case"checkbox":return m(t,"change",()=>{e(!!t.checked);});case"date":return m(t,"change",()=>{e(t.value?t.value:"");});case"file":return m(t,"change",()=>{t.files&&e(t.files);});case"number":return m(t,"input",()=>{let n=Number.parseFloat(t.value);e(Number.isNaN(n)?"":String(n));});case"radio":return m(t,"change",()=>{e(t.checked?t.value:"");});case"text":return m(t,"input",()=>{e(t.value);})}if(t instanceof HTMLSelectElement)return m(t,"change",()=>{e(t.value);});if(t instanceof HTMLTextAreaElement)return m(t,"input",()=>{e(t.value);})}var V=Promise.resolve();function ue(t){return t?V.then(t):V}function m(t,e,n){return t.addEventListener(e,n),()=>t.removeEventListener(e,n)}function F(t){let e=D.split(","),n=[],o=[],r=/<\/?([\da-z-]+)([^>]*)>/gi,s=0;for(;;){let c=r.exec(t);if(!c)break;let[i,a]=c,u=i[1]==="/";if(o.push(t.slice(s,c.index)),s=c.index+i.length,u){for(;n.length>0&&n[n.length-1]!==a;){let l=n.pop();l&&o.push(`</${l}>`);}n.length>0&&n.pop();}else e.includes(a)||n.push(a);o.push(i);}for(o.push(t.slice(s));n.length>0;){let c=n.pop();c&&o.push(`</${c}>`);}return o.join("")}function O(t){return le.split(",").includes(t)}function X(t){return D.split(",").includes(t)?`<${t}/>`:`<${t}></${t}>`}function z(){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e="",n=t.length;for(let o=0;o<8;o++)e+=t.charAt(Math.floor(Math.random()*n));return e}function G(t,e,n,o){let r=new Map,s=Array.from(e.values()),c=s.length;if(e.size>0&&n.length===0){if(t.childNodes.length===c+(o?1:0))t.innerHTML="",o&&g(t,o);else {let l=document.createRange(),d=s[0],p=h(d)?d.firstChild:d;l.setStartBefore(p),o?l.setEndBefore(o):l.setEndAfter(t),l.deleteContents();}return s.forEach(l=>{h(l)&&l.unmount();}),r}let i=[],a=pe(n),u=0;for(let[l,d]of n.entries()){let p=s[u],b=k(p,l);for(;p&&!a.has(b);)x(p),e.delete(b),p=s[++u],b=k(p,l);let P=k(d,l),L=e.get(P);if(L&&(d=de(t,L,d)),p)if(p===L)u++;else {let R=document.createComment("");g(t,R,p),i.push([R,d]);}else g(t,d,o);r.set(P,d);}return i.forEach(([l,d])=>A(t,d,l)),e.forEach((l,d)=>{l.isConnected&&!r.has(d)&&x(l);}),r}function de(t,e,n){return e===n?e:h(e)&&h(n)&&e.template===n.template?(n.inheritNode(e),n):e instanceof Text&&n instanceof Text?(e.textContent!==n.textContent&&(e.textContent=n.textContent),e):(A(t,n,e),n)}function pe(t){let e=new Map;for(let[n,o]of t.entries()){let r=k(o,n);e.set(r,o);}return e}function k(t,e){if(h(t)){let n=t.key;if(n!=null)return String(n)}return `_$${e}$`}var E=class t{constructor(e,n,o){this.template=e;this.props=n;this.key=o;this.treeMap=new Map;this.mounted=!1;this.nodes=[];this.provides={};this.trackMap=new Map;this.parent=null;}get firstChild(){var e;return (e=this.nodes[0])!=null?e:null}get isConnected(){return this.mounted}addEventListener(){}removeEventListener(){}mount(e,n){var s;if(this.parent=e,this.isConnected)return this.nodes.forEach(c=>g(e,c,n)),this.nodes;this.key=this.key||z();let o=this.template.content.cloneNode(!0),r=o.firstChild;return (s=r==null?void 0:r.hasAttribute)!=null&&s.call(r,"_svg_")&&(r.remove(),r==null||r.childNodes.forEach(c=>{o.append(c);})),this.nodes=Array.from(o.childNodes),this.mapNodeTree(e,o),g(e,o,n),this.patchNodes(this.props),this.mounted=!0,this.nodes}unmount(){this.trackMap.forEach(e=>{var n,o;(n=e.cleanup)==null||n.call(e),(o=e.lastNodes)==null||o.forEach(r=>{e.isRoot?x(r):r instanceof t&&r.unmount();});}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(e=>x(e)),this.nodes=[],this.mounted=!1;}mapNodeTree(e,n){let o=1;this.treeMap.set(0,e);let r=s=>{s.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&this.treeMap.set(o++,s);let c=s.firstChild;for(;c;)r(c),c=c.nextSibling;};r(n);}patchNodes(e){for(let n in e){let o=Number(n),r=this.treeMap.get(o);if(r){let s=this.props[n];this.patchNode(n,r,s,o===0);}}this.props=e;}getNodeTrack(e,n,o){var s;let r=this.trackMap.get(e);return r||(r={cleanup:()=>{}},n&&(r.lastNodes=new Map),o&&(r.isRoot=!0),this.trackMap.set(e,r)),(s=r.cleanup)==null||s.call(r),r}inheritNode(e){this.mounted=e.mounted,this.nodes=e.nodes,this.trackMap=e.trackMap,this.treeMap=e.treeMap;let n=this.props;this.props=e.props,this.patchNodes(n);}patchNode(e,n,o,r){for(let s in o)if(s==="children"&&o.children)if(isArray(o.children))o.children.filter(Boolean).forEach((c,i)=>{var b;let[a,u]=isArray(c)?c:[c,null],l=isNil(u)?null:(b=this.treeMap.get(u))!=null?b:null,d=`${e}:${s}:${i}`,p=this.getNodeTrack(d,!0,r);Z(p,n,a,l);});else {let c=`${e}:${s}:0`,i=this.getNodeTrack(c,!0,r);Z(i,n,o.children,null);}else if(s==="ref")isSignal(o[s])?o[s].value=n:isFunction(o[s])&&o[s](n);else if(startsWith(s,"on")){let c=s.slice(2).toLocaleLowerCase(),i=this.getNodeTrack(`${e}:${s}`),a=o[s];i.cleanup=m(n,c,a);}else if(!startsWith(s,"update")){let c=this.getNodeTrack(`${e}:${s}`),i=o[s],a=isSignal(i)?i:useSignal(i);Y(c,n,s,a.value);let u=useEffect(()=>{a.value=isSignal(i)?i.value:i,Y(c,n,s,a.value);}),l,d=`update${capitalizeFirstLetter(s)}`;o[d]&&(l=q(n,p=>{o[d](p);})),c.cleanup=()=>{u&&u(),l&&l();};}}};function Y(t,e,n,o){let r=e;r.setAttribute&&(isFunction(o)?t.cleanup=useEffect(()=>{H(r,n,o());}):H(r,n,o));}function Z(t,e,n,o){isFunction(n)?t.cleanup=useEffect(()=>{let r=coerceArray(n()).map(w);t.lastNodes=G(e,t.lastNodes,r,o);}):coerceArray(n).forEach((r,s)=>{let c=w(r);t.lastNodes.set(String(s),c),g(e,c,o);});}function ge(t){var e;C("onMounted"),(e=f.ref)==null||e.addHook("mounted",t);}function Ne(t){var e;C("onDestroy"),(e=f.ref)==null||e.addHook("destroy",t);}function C(t){f.ref||console.error(`"${t}" can only be called within the component function body
|
|
10
|
-
and cannot be used in asynchronous or deferred calls.`);}function
|
|
9
|
+
var re=Object.defineProperty;var I=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable;var O=(t,n,e)=>n in t?re(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,J=(t,n)=>{for(var e in n||(n={}))ie.call(n,e)&&O(t,e,n[e]);if(I)for(var e of I(n))se.call(n,e)&&O(t,e,n[e]);return t};var N=class N{constructor(){this.hooks={mounted:new Set,destroy:new Set};}addEventListener(){}removeEventListener(){}addHook(n,e){var o;(o=this.hooks[n])==null||o.add(e);}getContext(n){return N.context[n]}setContext(n,e){N.context[n]=e;}initRef(){N.ref=this;}removeRef(){N.ref=null;}};N.ref=null,N.context={};var h=N,y=class extends h{constructor(e,o,r){super();this.template=e;this.props=o;this.key=r;this.proxyProps={};this.emitter=new Set;this.mounted=!1;this.rootNode=null;this.context={};this.trackMap=new Map;this.proxyProps=signalObject(o,i=>startsWith(i,"on")||startsWith(i,"update")),this.key=this.key||o.key;}get firstChild(){var e,o;return (o=(e=this.rootNode)==null?void 0:e.firstChild)!=null?o:null}get isConnected(){var e,o;return (o=(e=this.rootNode)==null?void 0:e.isConnected)!=null?o:!1}inheritNode(e){this.context=e.context,this.hooks=e.hooks,Object.assign(this.proxyProps,e.proxyProps),this.rootNode=e.rootNode,this.trackMap=e.trackMap;let o=this.props;this.props=e.props,this.patchProps(o);}mount(e,o){var i,s,a,l;if(!isFunction(this.template))throw new Error("Template must be a function");if(this.isConnected)return (s=(i=this.rootNode)==null?void 0:i.mount(e,o))!=null?s:[];this.initRef(),this.rootNode=this.template(useReactive(this.proxyProps,["children"])),this.removeRef(),this.mounted=!0;let r=(l=(a=this.rootNode)==null?void 0:a.mount(e,o))!=null?l:[];return this.hooks.mounted.forEach(d=>d()),this.patchProps(this.props),r}unmount(){var e;this.hooks.destroy.forEach(o=>o()),Object.values(this.hooks).forEach(o=>o.clear()),(e=this.rootNode)==null||e.unmount(),this.rootNode=null,this.proxyProps={},this.mounted=!1,this.emitter.forEach(o=>o());}getNodeTrack(e,o){let r=this.trackMap.get(e);return r||(r={cleanup:()=>{}},this.trackMap.set(e,r)),o||r.cleanup(),r}patchProps(e){var o,r,i,s;for(let[a,l]of Object.entries(e))if(startsWith(a,"on")&&((o=this.rootNode)!=null&&o.nodes)){let d=a.slice(2).toLowerCase(),c=l,u=m(this.rootNode.nodes[0],d,c);this.emitter.add(u);}else if(a==="ref")e[a].value=(r=this.rootNode)==null?void 0:r.nodes[0];else if(startsWith(a,"update"))e[a]=isSignal(l)?l.value:l;else if(a!=="children"){let d=(s=(i=this.proxyProps)[a])!=null?s:i[a]=useSignal(l),c=this.getNodeTrack(a);c.cleanup=useEffect(()=>{d.value=isFunction(l)?l():l;});}this.props=e;}};function fe(t,n,e){return isString(t)&&(B(t)&&(t=D(t),n={1:n}),t===""&&(n={0:n}),t=X(t)),isFunction(t)?new y(t,n,e):new E(t,n,e)}function he(t){return t instanceof y}function f(t){return t instanceof y||t instanceof E}function X(t){let n=document.createElement("template");return n.innerHTML=V(t),n}function ge(t){return t.children}var W="area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr",ye="a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,command,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,menu,menuitem,meta,meter,nav,nobr,noframes,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,section,select,shadow,small,source,spacer,span,strike,strong,style,sub,summary,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,xmp";function j(t){if(f(t)||t instanceof Node)return t;let n=isFalsy(t)?"":String(t);return document.createTextNode(n)}function g(t,n,e=null){let o=f(e)?e.firstChild:e;f(n)?n.mount(t,o):o?o.before(n):t.append(n);}function b(t){f(t)?t.unmount():t.parentNode&&t.remove();}function H(t,n,e){g(t,n,e),b(e);}function R(t,n,e){if(n==="class"){typeof e=="string"?t.className=e:Array.isArray(e)?t.className=e.join(" "):e&&typeof e=="object"&&(t.className=Object.entries(e).reduce((o,[r,i])=>o+(i?` ${r}`:""),"").trim());return}if(n==="style"){if(typeof e=="string")t.style.cssText=e;else if(e&&typeof e=="object"){let o=e;Object.keys(o).forEach(r=>{t.style.setProperty(kebabCase(r),String(o[r]));});}return}isFalsy(e)?t.removeAttribute(n):e===!0?t.setAttribute(n,""):t instanceof HTMLInputElement?t.value=String(e):t.setAttribute(n,String(e));}function G(t,n){if(t instanceof HTMLInputElement)switch(t.type){case"checkbox":return m(t,"change",()=>{n(!!t.checked);});case"date":return m(t,"change",()=>{n(t.value?t.value:"");});case"file":return m(t,"change",()=>{t.files&&n(t.files);});case"number":return m(t,"input",()=>{let e=Number.parseFloat(t.value);n(Number.isNaN(e)?"":String(e));});case"radio":return m(t,"change",()=>{n(t.checked?t.value:"");});case"text":return m(t,"input",()=>{n(t.value);})}if(t instanceof HTMLSelectElement)return m(t,"change",()=>{n(t.value);});if(t instanceof HTMLTextAreaElement)return m(t,"input",()=>{n(t.value);})}var z=Promise.resolve();function Te(t){return t?z.then(t):z}function m(t,n,e){return t.addEventListener(n,e),()=>t.removeEventListener(n,e)}function V(t){let n=W.split(","),e=[],o=[],r=/<\/?([\da-z-]+)([^>]*)>/gi,i=0;for(;;){let s=r.exec(t);if(!s)break;let[a,l]=s,d=a[1]==="/";if(o.push(t.slice(i,s.index)),i=s.index+a.length,d){for(;e.length>0&&e[e.length-1]!==l;){let c=e.pop();c&&o.push(`</${c}>`);}e.length>0&&e.pop();}else n.includes(l)||e.push(l);o.push(a);}for(o.push(t.slice(i));e.length>0;){let s=e.pop();s&&o.push(`</${s}>`);}return o.join("")}function B(t){return ye.split(",").includes(t)}function D(t){return W.split(",").includes(t)?`<${t}/>`:`<${t}></${t}>`}function U(t,n,e,o){let r=new Map,i=Array.from(n.values()),s=i.length;if(n.size>0&&e.length===0){if(t.childNodes.length===s+(o?1:0))t.innerHTML="",o&&g(t,o);else {let c=document.createRange(),u=i[0],p=f(u)?u.firstChild:u;c.setStartBefore(p),o?c.setEndBefore(o):c.setEndAfter(t),c.deleteContents();}return i.forEach(c=>{f(c)&&c.unmount();}),r}let a=[],l=be(e),d=0;for(let[c,u]of e.entries()){let p=i[d],x=M(p,c);for(;p&&!l.has(x);)b(p),n.delete(x),p=i[++d],x=M(p,c);let $=M(u,c),A=n.get($);if(A&&(u=ve(t,A,u)),p)if(p===A)d++;else {let K=document.createComment("");g(t,K,p),a.push([K,u]);}else g(t,u,o);r.set($,u);}return a.forEach(([c,u])=>H(t,u,c)),n.forEach((c,u)=>{c.isConnected&&!r.has(u)&&b(c);}),r}function ve(t,n,e){return n===e?n:f(n)&&f(e)&&n.template===e.template?(e.inheritNode(n),e):n instanceof Text&&e instanceof Text?(n.textContent!==e.textContent&&(n.textContent=e.textContent),n):(H(t,e,n),e)}function be(t){let n=new Map;for(let[e,o]of t.entries()){let r=M(o,e);n.set(r,o);}return n}function M(t,n){if(f(t)){let e=t.key;if(e!=null)return String(e)}return `_$${n}$`}var E=class t{constructor(n,e,o){this.template=n;this.props=e;this.key=o;this.treeMap=new Map;this.mounted=!1;this.nodes=[];this.provides={};this.trackMap=new Map;this.parent=null;this.key=this.key||e.key;}get firstChild(){var n;return (n=this.nodes[0])!=null?n:null}get isConnected(){return this.mounted}addEventListener(){}removeEventListener(){}mount(n,e){var i;if(this.parent=n,this.isConnected)return this.nodes.forEach(s=>g(n,s,e)),this.nodes;let o=this.template.content.cloneNode(!0),r=o.firstChild;return (i=r==null?void 0:r.hasAttribute)!=null&&i.call(r,"_svg_")&&(r.remove(),r==null||r.childNodes.forEach(s=>{o.append(s);})),this.nodes=Array.from(o.childNodes),this.mapNodeTree(n,o),g(n,o,e),this.patchNodes(this.props),this.mounted=!0,this.nodes}unmount(){this.trackMap.forEach(n=>{var e,o;(e=n.cleanup)==null||e.call(n),(o=n.lastNodes)==null||o.forEach(r=>{n.isRoot?b(r):r instanceof t&&r.unmount();});}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(n=>b(n)),this.nodes=[],this.mounted=!1;}mapNodeTree(n,e){let o=1;this.treeMap.set(0,n);let r=i=>{i.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&this.treeMap.set(o++,i);let s=i.firstChild;for(;s;)r(s),s=s.nextSibling;};r(e);}patchNodes(n){for(let e in n){let o=Number(e),r=this.treeMap.get(o);if(r){let i=this.props[e];this.patchNode(e,r,i,o===0);}}this.props=n;}getNodeTrack(n,e,o){var i;let r=this.trackMap.get(n);return r||(r={cleanup:()=>{}},e&&(r.lastNodes=new Map),o&&(r.isRoot=!0),this.trackMap.set(n,r)),(i=r.cleanup)==null||i.call(r),r}inheritNode(n){this.mounted=n.mounted,this.nodes=n.nodes,this.trackMap=n.trackMap,this.treeMap=n.treeMap;let e=this.props;this.props=n.props,this.patchNodes(e);}patchNode(n,e,o,r){for(let i in o)if(i==="children"&&o.children)if(isArray(o.children))o.children.filter(Boolean).forEach((s,a)=>{var x;let[l,d]=isArray(s)?s:[s,null],c=isNil(d)?null:(x=this.treeMap.get(d))!=null?x:null,u=`${n}:${i}:${a}`,p=this.getNodeTrack(u,!0,r);te(p,e,l,c);});else {let s=`${n}:${i}:0`,a=this.getNodeTrack(s,!0,r);te(a,e,o.children,null);}else if(i==="ref")o[i].value=e;else if(startsWith(i,"on")){let s=i.slice(2).toLocaleLowerCase(),a=this.getNodeTrack(`${n}:${i}`),l=o[i];a.cleanup=m(e,s,l);}else if(!startsWith(i,"update")){let s=this.getNodeTrack(`${n}:${i}`),a=o[i],l=isSignal(a)?a:useSignal(a);ee(s,e,i,l.value);let d=useEffect(()=>{l.value=isSignal(a)?a.value:a,ee(s,e,i,l.value);}),c,u=`update${capitalizeFirstLetter(i)}`;o[u]&&(c=G(e,p=>{o[u](p);})),s.cleanup=()=>{d&&d(),c&&c();};}}};function ee(t,n,e,o){let r=n;r.setAttribute&&(isFunction(o)?t.cleanup=useEffect(()=>{R(r,e,o());}):R(r,e,o));}function te(t,n,e,o){isFunction(e)?t.cleanup=useEffect(()=>{let r=coerceArray(e()).map(j);t.lastNodes=U(n,t.lastNodes,r,o);}):coerceArray(e).forEach((r,i)=>{let s=j(r);t.lastNodes.set(String(i),s),g(n,s,o);});}function Se(t){var n;S("onMounted"),(n=h.ref)==null||n.addHook("mounted",t);}function we(t){var n;S("onDestroy"),(n=h.ref)==null||n.addHook("destroy",t);}function S(t,n){h.ref||console.error(`"${t}"(key: ${isSymbol(n)?n.toString():n}) can only be called within the component function body
|
|
10
|
+
and cannot be used in asynchronous or deferred calls.`);}function Le(t,n){var e;S("useProvide",t),(e=h.ref)==null||e.setContext(t,n);}function Ae(t,n){var e;return S("useInject",t),((e=h.ref)==null?void 0:e.getContext(t))||n}function je(){return shallowSignal(null)}function Ke(t){return Object.entries(t).map(([n,e])=>n==="children"||isFunction(e)?"":`${n}="${escape(String(e))}"`).filter(Boolean).join(" ")}function Ie(t){Object.keys(t).forEach(n=>{isFunction(t[n])&&delete t[n],isSignal(t[n])&&(t[n]=t[n].value);});}function Oe(t,n,e,o,r,i){if(isSignal(t))o.template+=t.value;else if(t instanceof L){let s=i?String(i):`${e}`;r[s]||(r[s]=[]);let a=t.mount();r[s].push(isFunction(a)?a(n):isSignal(a)?a.value:a);}else o.template+=isFunction(t)?t(n):String(t);}var L=class t extends h{constructor(e,o={},r){super();this.template=e;this.props=o;this.key=r;this.childNodesMap={};this.processedTemplates={};}mount(){this.initRef();let e=this.render();return this.removeRef(),e}initTemplates(){let e=Array.isArray(this.template)?this.template.reduce((o,r,i)=>(o[i+1]={template:r},o),{}):this.template;isObject(e)&&Object.entries(e).forEach(([o,r])=>{let i=J({},this.props[o]);Ie(i),i.children&&i.children.forEach(s=>{let[a,l]=isArray(s)?s:[s,null];if(isFunction(a)){let d=a(i);Oe(d,i,o,r,this.childNodesMap,l);}else r.template+=isSignal(a)?a.value:String(a);}),this.processedTemplates[o]={template:r.template,props:i};});}render(){if(isFunction(this.template)){let e=this.template(this.props);return e instanceof t?e.mount():String(e)}return this.template instanceof t?this.template.mount():(this.initTemplates(),Object.entries(this.processedTemplates).map(([e,{template:o,props:r}])=>{let i=o;return r&&Object.keys(r).length>0&&(i+=` ${Ke(r)}`),this.childNodesMap[e]&&(i=i.replace("<!>",this.renderChildren(this.childNodesMap[e]))),i}).join(""))}renderChildren(e){return coerceArray(e).map(String).join("")}};function oe(t,n){return new L(t,n)}function Je(t,n){return oe(t,n).mount()}
|
|
11
11
|
|
|
12
|
-
export {
|
|
12
|
+
export { y as ComponentNode, ge as Fragment, E as TemplateNode, fe as h, he as isComponent, f as isJsxElement, Te as nextTick, we as onDestroy, Se as onMount, Je as renderToString, oe as ssg, X as template, Ae as useInject, Le as useProvide, je as useRef };
|
|
13
13
|
//# sourceMappingURL=template.esm.js.map
|
|
14
14
|
//# sourceMappingURL=template.esm.js.map
|