@estjs/template 0.0.14-beta.9 → 0.0.14
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 +2 -2
- package/dist/template.cjs.js.map +1 -1
- package/dist/template.d.cts +76 -40
- package/dist/template.d.ts +76 -40
- package/dist/template.dev.cjs.js +84 -117
- package/dist/template.dev.esm.js +85 -117
- package/dist/template.esm.js +3 -3
- package/dist/template.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/template.dev.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isString, isFunction,
|
|
2
|
-
import {
|
|
1
|
+
import { isString, isFunction, isSymbol, isArray, escape, hasChanged, startsWith, capitalize, isNil, isHTMLElement, coerceArray, isFalsy, kebabCase } from '@estjs/shared';
|
|
2
|
+
import { isSignal, shallowReactive, useReactive, useEffect, shallowSignal, isComputed } from '@estjs/signal';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @estjs/template v0.0.14
|
|
5
|
+
* @estjs/template v0.0.14
|
|
6
6
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
7
7
|
* @license MIT
|
|
8
8
|
**/
|
|
@@ -182,10 +182,10 @@ var SSGNode = class extends LifecycleContext {
|
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
renderChild(child) {
|
|
185
|
-
if (
|
|
186
|
-
return this.renderChild(child(this.props));
|
|
187
|
-
} else if (isSignal(child)) {
|
|
185
|
+
if (isSignal(child)) {
|
|
188
186
|
return `<!--${1 /* TEXT_COMPONENT */}-${componentIndex}-->${child.value}<!$>`;
|
|
187
|
+
} else if (isFunction(child)) {
|
|
188
|
+
return this.renderChild(child(this.props));
|
|
189
189
|
} else if (isSSGNode(child)) {
|
|
190
190
|
const childResult = child.mount();
|
|
191
191
|
return isFunction(childResult) ? childResult(this.props) : extractSignal(childResult);
|
|
@@ -317,42 +317,6 @@ function addEventListener(node, eventName, handler) {
|
|
|
317
317
|
node.addEventListener(eventName, handler);
|
|
318
318
|
return () => node.removeEventListener(eventName, handler);
|
|
319
319
|
}
|
|
320
|
-
function closeHtmlTags(input) {
|
|
321
|
-
const tagStack = [];
|
|
322
|
-
const output = [];
|
|
323
|
-
const tagPattern = /<\/?([\da-z-]+)([^>]*)>/gi;
|
|
324
|
-
let lastIndex = 0;
|
|
325
|
-
while (true) {
|
|
326
|
-
const match = tagPattern.exec(input);
|
|
327
|
-
if (!match) break;
|
|
328
|
-
const [fullMatch, tagName] = match;
|
|
329
|
-
const isEndTag = fullMatch[1] === "/";
|
|
330
|
-
output.push(input.slice(lastIndex, match.index));
|
|
331
|
-
lastIndex = match.index + fullMatch.length;
|
|
332
|
-
if (isEndTag) {
|
|
333
|
-
while (tagStack.length > 0 && tagStack[tagStack.length - 1] !== tagName) {
|
|
334
|
-
const unclosedTag = tagStack.pop();
|
|
335
|
-
if (unclosedTag) {
|
|
336
|
-
output.push(`</${unclosedTag}>`);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (tagStack.length > 0) {
|
|
340
|
-
tagStack.pop();
|
|
341
|
-
}
|
|
342
|
-
} else if (!SELF_CLOSING_TAGS.includes(tagName)) {
|
|
343
|
-
tagStack.push(tagName);
|
|
344
|
-
}
|
|
345
|
-
output.push(fullMatch);
|
|
346
|
-
}
|
|
347
|
-
output.push(input.slice(lastIndex));
|
|
348
|
-
while (tagStack.length > 0) {
|
|
349
|
-
const unclosedTag = tagStack.pop();
|
|
350
|
-
if (unclosedTag) {
|
|
351
|
-
output.push(`</${unclosedTag}>`);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return output.join("");
|
|
355
|
-
}
|
|
356
320
|
function convertToHtmlTag(tagName) {
|
|
357
321
|
return SELF_CLOSING_TAGS.includes(tagName) ? `<${tagName}/>` : `<${tagName}></${tagName}>`;
|
|
358
322
|
}
|
|
@@ -372,15 +336,11 @@ var ComponentNode = class extends LifecycleContext {
|
|
|
372
336
|
this.emitter = /* @__PURE__ */ new Set();
|
|
373
337
|
this.rootNode = null;
|
|
374
338
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
339
|
+
this.nodes = [];
|
|
340
|
+
this.parent = null;
|
|
341
|
+
this.before = null;
|
|
375
342
|
this.key || (this.key = props && props.key);
|
|
376
|
-
this.proxyProps
|
|
377
|
-
}
|
|
378
|
-
createProxyProps(props) {
|
|
379
|
-
if (!props) return {};
|
|
380
|
-
return signalObject(
|
|
381
|
-
props,
|
|
382
|
-
(key) => startsWith(key, EVENT_PREFIX) || startsWith(key, UPDATE_PREFIX) || key === CHILDREN_PROP
|
|
383
|
-
);
|
|
343
|
+
this.proxyProps || (this.proxyProps = shallowReactive(props || {}));
|
|
384
344
|
}
|
|
385
345
|
get firstChild() {
|
|
386
346
|
var _a, _b;
|
|
@@ -392,6 +352,7 @@ var ComponentNode = class extends LifecycleContext {
|
|
|
392
352
|
}
|
|
393
353
|
mount(parent, before) {
|
|
394
354
|
var _a, _b, _c, _d;
|
|
355
|
+
this.parent = parent;
|
|
395
356
|
if (!isFunction(this.template)) {
|
|
396
357
|
throw new Error("Template must be a function");
|
|
397
358
|
}
|
|
@@ -400,20 +361,30 @@ var ComponentNode = class extends LifecycleContext {
|
|
|
400
361
|
}
|
|
401
362
|
this.initRef();
|
|
402
363
|
this.rootNode = this.template(useReactive(this.proxyProps, [CHILDREN_PROP]));
|
|
403
|
-
|
|
364
|
+
this.nodes = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
|
|
404
365
|
this.callMountHooks();
|
|
405
366
|
this.patchProps(this.props);
|
|
406
367
|
this.removeRef();
|
|
407
|
-
return
|
|
368
|
+
return this.nodes;
|
|
408
369
|
}
|
|
409
370
|
unmount() {
|
|
410
371
|
var _a;
|
|
411
|
-
this.
|
|
412
|
-
this.
|
|
372
|
+
this.callLifecycleHooks("destroy");
|
|
373
|
+
this.cleanup();
|
|
413
374
|
(_a = this.rootNode) == null ? void 0 : _a.unmount();
|
|
375
|
+
this.resetState();
|
|
376
|
+
if (this.key) {
|
|
377
|
+
componentCache.delete(this.key);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
resetState() {
|
|
414
381
|
this.rootNode = null;
|
|
415
382
|
this.proxyProps = {};
|
|
416
|
-
this.
|
|
383
|
+
this.nodes = [];
|
|
384
|
+
this.parent = null;
|
|
385
|
+
}
|
|
386
|
+
callLifecycleHooks(type) {
|
|
387
|
+
this.hooks[type].forEach((handler) => handler());
|
|
417
388
|
}
|
|
418
389
|
callMountHooks() {
|
|
419
390
|
this.hooks.mounted.forEach((handler) => handler());
|
|
@@ -432,9 +403,11 @@ var ComponentNode = class extends LifecycleContext {
|
|
|
432
403
|
this.rootNode = node.rootNode;
|
|
433
404
|
this.trackMap = node.trackMap;
|
|
434
405
|
this.hooks = node.hooks;
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
406
|
+
if (hasChanged(node.props, this.props)) {
|
|
407
|
+
const props = this.props;
|
|
408
|
+
this.props = node.props;
|
|
409
|
+
this.patchProps(props);
|
|
410
|
+
}
|
|
438
411
|
}
|
|
439
412
|
getNodeTrack(trackKey) {
|
|
440
413
|
let track = this.trackMap.get(trackKey);
|
|
@@ -474,16 +447,23 @@ var ComponentNode = class extends LifecycleContext {
|
|
|
474
447
|
prop.value = (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
|
|
475
448
|
}
|
|
476
449
|
patchUpdateHandler(key, prop) {
|
|
477
|
-
this.
|
|
450
|
+
this.proxyProps[key] = extractSignal(prop);
|
|
478
451
|
}
|
|
479
452
|
patchNormalProp(key, prop) {
|
|
480
|
-
var _a, _b;
|
|
481
|
-
const newValue = (_b = (_a = this.proxyProps)[key]) != null ? _b : _a[key] = useSignal(prop);
|
|
482
453
|
const track = this.getNodeTrack(key);
|
|
483
454
|
track.cleanup = useEffect(() => {
|
|
484
|
-
|
|
455
|
+
this.proxyProps[key] = isFunction(prop) ? prop() : prop;
|
|
485
456
|
});
|
|
486
457
|
}
|
|
458
|
+
cleanup() {
|
|
459
|
+
this.trackMap.forEach((track) => {
|
|
460
|
+
var _a;
|
|
461
|
+
return (_a = track.cleanup) == null ? void 0 : _a.call(track);
|
|
462
|
+
});
|
|
463
|
+
this.trackMap.clear();
|
|
464
|
+
this.emitter.forEach((cleanup) => cleanup());
|
|
465
|
+
this.emitter.clear();
|
|
466
|
+
}
|
|
487
467
|
};
|
|
488
468
|
|
|
489
469
|
// src/patch.ts
|
|
@@ -599,14 +579,12 @@ var TemplateNode = class {
|
|
|
599
579
|
this.template = template;
|
|
600
580
|
this.props = props;
|
|
601
581
|
this.key = key;
|
|
602
|
-
// Private properties for managing the node's state
|
|
603
582
|
this.treeMap = /* @__PURE__ */ new Map();
|
|
604
583
|
this.mounted = false;
|
|
605
584
|
this.nodes = [];
|
|
606
585
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
607
586
|
this.bindValueKeys = [];
|
|
608
587
|
this.parent = null;
|
|
609
|
-
this.key || (this.key = props && props.key);
|
|
610
588
|
if (renderContext.isSSR) {
|
|
611
589
|
this.componentIndex = getComponentIndex(this.template);
|
|
612
590
|
}
|
|
@@ -652,39 +630,16 @@ var TemplateNode = class {
|
|
|
652
630
|
return this.nodes;
|
|
653
631
|
}
|
|
654
632
|
unmount() {
|
|
655
|
-
var _a, _b;
|
|
656
633
|
this.trackMap.forEach((track) => {
|
|
657
634
|
track.cleanup && track.cleanup();
|
|
658
635
|
});
|
|
659
636
|
this.trackMap.clear();
|
|
660
637
|
this.treeMap.clear();
|
|
661
638
|
this.nodes.forEach((node) => removeChild(node));
|
|
662
|
-
if (!this.template.innerHTML && !this.nodes.length) {
|
|
663
|
-
const children = (_b = (_a = this.props) == null ? void 0 : _a[FRAGMENT_PROP_KEY]) == null ? void 0 : _b.children;
|
|
664
|
-
if (children) {
|
|
665
|
-
if (isArray(children)) {
|
|
666
|
-
children.forEach((child) => {
|
|
667
|
-
this.deleteFragmentTextNode(child);
|
|
668
|
-
});
|
|
669
|
-
} else {
|
|
670
|
-
this.deleteFragmentTextNode(children);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
639
|
this.nodes = [];
|
|
675
640
|
this.mounted = false;
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
if (isPrimitive(child)) {
|
|
679
|
-
if (this.parent && this.parent.childNodes.length) {
|
|
680
|
-
this.parent.childNodes.forEach((node) => {
|
|
681
|
-
if (node.nodeType === Node.TEXT_NODE && node.textContent === `${child}`) {
|
|
682
|
-
this.parent.removeChild(node);
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
} else {
|
|
687
|
-
removeChild(child);
|
|
641
|
+
if (this.key) {
|
|
642
|
+
componentCache.delete(this.key);
|
|
688
643
|
}
|
|
689
644
|
}
|
|
690
645
|
inheritNode(node) {
|
|
@@ -700,7 +655,7 @@ var TemplateNode = class {
|
|
|
700
655
|
this.treeMap.set(0, parent);
|
|
701
656
|
this.walkNodeTree(parent, this.handleSSGNode.bind(this));
|
|
702
657
|
}
|
|
703
|
-
//
|
|
658
|
+
// protected method to map node tree
|
|
704
659
|
mapNodeTree(parent, tree) {
|
|
705
660
|
let index = 1;
|
|
706
661
|
this.treeMap.set(0, parent);
|
|
@@ -793,14 +748,9 @@ var TemplateNode = class {
|
|
|
793
748
|
}
|
|
794
749
|
patchAttribute(key, element, attr, value, updateFn) {
|
|
795
750
|
const track = this.getNodeTrack(`${key}:${attr}`);
|
|
796
|
-
const
|
|
797
|
-
const triggerValue = isSignal(val) ? val : shallowSignal(val);
|
|
798
|
-
setAttribute(element, attr, triggerValue.value);
|
|
751
|
+
const triggerValue = shallowSignal();
|
|
799
752
|
const cleanup = useEffect(() => {
|
|
800
|
-
|
|
801
|
-
if (isPlainObject(val2) && isPlainObject(triggerValue.peek()) && JSON.stringify(triggerValue.value) === JSON.stringify(val2))
|
|
802
|
-
return;
|
|
803
|
-
triggerValue.value = isSignal(val2) ? val2.value : val2;
|
|
753
|
+
triggerValue.value = isSignal(value) || isComputed(value) ? value.value : value;
|
|
804
754
|
setAttribute(element, attr, triggerValue.value);
|
|
805
755
|
});
|
|
806
756
|
let cleanupBind;
|
|
@@ -879,17 +829,36 @@ var TemplateNode = class {
|
|
|
879
829
|
};
|
|
880
830
|
|
|
881
831
|
// src/jsxRenderer.ts
|
|
882
|
-
|
|
832
|
+
var componentCache = /* @__PURE__ */ new Map();
|
|
833
|
+
function createNodeCache(NodeConstructor, template, props = {}, key) {
|
|
834
|
+
if (key) {
|
|
835
|
+
const cached = componentCache.get(key);
|
|
836
|
+
if (cached) {
|
|
837
|
+
return cached;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (typeof template === "string") {
|
|
841
|
+
template = createTemplate(template);
|
|
842
|
+
}
|
|
843
|
+
const newNode = new NodeConstructor(template, props, key);
|
|
844
|
+
if (key && newNode instanceof ComponentNode) {
|
|
845
|
+
componentCache.set(key, newNode);
|
|
846
|
+
}
|
|
847
|
+
return newNode;
|
|
848
|
+
}
|
|
849
|
+
function h(template, props = {}, key) {
|
|
850
|
+
if (template === EMPTY_TEMPLATE) {
|
|
851
|
+
return Fragment(template, props);
|
|
852
|
+
}
|
|
883
853
|
if (isString(template)) {
|
|
884
|
-
const
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
return new TemplateNode(createTemplate(htmlTemplate), props, key);
|
|
854
|
+
const htmlTemplate = convertToHtmlTag(template);
|
|
855
|
+
const wrappedProps = { [SINGLE_PROP_KEY]: props };
|
|
856
|
+
return createNodeCache(TemplateNode, htmlTemplate, wrappedProps, key);
|
|
888
857
|
}
|
|
889
858
|
if (isFunction(template)) {
|
|
890
|
-
return
|
|
859
|
+
return createNodeCache(ComponentNode, template, props, key);
|
|
891
860
|
}
|
|
892
|
-
return
|
|
861
|
+
return createNodeCache(TemplateNode, template, props, key);
|
|
893
862
|
}
|
|
894
863
|
function isComponent(node) {
|
|
895
864
|
return node instanceof ComponentNode;
|
|
@@ -899,15 +868,17 @@ function isJsxElement(node) {
|
|
|
899
868
|
}
|
|
900
869
|
function createTemplate(html) {
|
|
901
870
|
const template = document.createElement("template");
|
|
902
|
-
template.innerHTML =
|
|
871
|
+
template.innerHTML = html;
|
|
903
872
|
return template;
|
|
904
873
|
}
|
|
905
|
-
function Fragment(props) {
|
|
906
|
-
|
|
874
|
+
function Fragment(template, props) {
|
|
875
|
+
const processedProps = props.children ? {
|
|
907
876
|
[FRAGMENT_PROP_KEY]: {
|
|
908
|
-
children: isArray(props.children) ? props.children.filter(Boolean) : [props.children]
|
|
877
|
+
children: Array.isArray(props.children) ? props.children.filter(Boolean) : [props.children]
|
|
909
878
|
}
|
|
910
|
-
}
|
|
879
|
+
} : props;
|
|
880
|
+
const templateElement = template === EMPTY_TEMPLATE ? createTemplate(EMPTY_TEMPLATE) : template;
|
|
881
|
+
return createNodeCache(TemplateNode, templateElement, processedProps);
|
|
911
882
|
}
|
|
912
883
|
function onMount(cb) {
|
|
913
884
|
assertInsideComponent("onMounted");
|
|
@@ -925,18 +896,15 @@ function assertInsideComponent(hookName, key) {
|
|
|
925
896
|
);
|
|
926
897
|
}
|
|
927
898
|
}
|
|
928
|
-
function
|
|
929
|
-
assertInsideComponent("
|
|
899
|
+
function provide(key, value) {
|
|
900
|
+
assertInsideComponent("provide", key);
|
|
930
901
|
LifecycleContext.ref && LifecycleContext.ref.setContext(key, value);
|
|
931
902
|
}
|
|
932
|
-
function
|
|
903
|
+
function inject(key, defaultValue) {
|
|
933
904
|
var _a;
|
|
934
|
-
assertInsideComponent("
|
|
905
|
+
assertInsideComponent("inject", key);
|
|
935
906
|
return (_a = LifecycleContext.ref && LifecycleContext.ref.getContext(key)) != null ? _a : defaultValue;
|
|
936
907
|
}
|
|
937
|
-
function useRef() {
|
|
938
|
-
return shallowSignal(null);
|
|
939
|
-
}
|
|
940
908
|
|
|
941
909
|
// src/server.ts
|
|
942
910
|
function renderToString(component, props) {
|
|
@@ -962,4 +930,4 @@ function ssg(component, props) {
|
|
|
962
930
|
return h(component, props);
|
|
963
931
|
}
|
|
964
932
|
|
|
965
|
-
export { Fragment, h, hydrate, isComponent, isJsxElement, onDestroy, onMount, renderToString, ssg, createTemplate as template
|
|
933
|
+
export { Fragment, h, hydrate, inject, isComponent, isJsxElement, onDestroy, onMount, provide, renderToString, ssg, createTemplate as template };
|
package/dist/template.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {isString,isFunction,isArray,escape,startsWith,
|
|
2
|
-
* @estjs/template v0.0.14
|
|
1
|
+
import {isString,isFunction,isArray,escape,hasChanged,startsWith,capitalize,isNil,isHTMLElement,coerceArray,isFalsy,kebabCase}from'@estjs/shared';import {isSignal,shallowReactive,useReactive,useEffect,shallowSignal,isComputed}from'@estjs/signal';/**
|
|
2
|
+
* @estjs/template v0.0.14
|
|
3
3
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
6
|
-
var P="on",L="update",N="children",O="",R="0",q="1";var _="ref",$=" __PLACEHOLDER__ ";var J=class{constructor(){this.renderMode=0;}get isSSG(){return this.renderMode===1}get isSSR(){return this.renderMode===2}get isClient(){return this.renderMode===0}setSSR(){this.renderMode=2;}setSSG(){this.renderMode=1;}setClient(){this.renderMode=0;}},m=new J,W=new Map;function Q(o,t){W.set(o,{index:t});}function Z(o){var t;return (t=W.get(o))==null?void 0:t.index}var v=class v{constructor(){this.hooks={mounted:new Set,destroy:new Set};}addEventListener(){}removeEventListener(){}addHook(t,e){var n;(n=this.hooks[t])==null||n.add(e);}getContext(t){return v.context[t]}setContext(t,e){v.context[t]=e;}initRef(){v.ref=this;}removeRef(){v.ref=null;}clearHooks(){Object.values(this.hooks).forEach(t=>t.clear());}};v.ref=null,v.context={};var u=v;function I(o){return o instanceof C}var b=1,C=class extends u{constructor(e,n={},r){super();this.template=e;this.props=n;this.key=r;Q(e,b),this.templates=this.processTemplate();}processTemplate(){if(isArray(this.template)){let e=this.template.join($);return this.processHtmlString(e).split($)}return []}processHtmlString(e){return e.replaceAll(/(<[^>]+>)|([^<]+)/g,(n,r,i)=>r?r.includes("data-ci")?n:r.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i,(s,a,l)=>`<${a} data-ci="${b}"${l||""}>`):i&&i.replace($,"").trim()?`<!--0-${b}-->${i}<!$>`:n)}mount(){this.initRef();let e=this.render();return this.removeRef(),e}render(){if(isFunction(this.template)){let e=this.template(this.props);return I(e)?e.mount():String(e)}return this.renderTemplate()}renderTemplate(){return Object.entries(this.props).forEach(([e,n])=>{let r=n.children;this.normalizeProps(n);let i=this.templates.findIndex(s=>s.includes(`data-hk="${e}"`));r&&this.renderChildren(r,i),this.templates[i]=this.templates[i].replace(`data-hk="${e}"`,`data-hk="${e}" ${this.generateAttributes(n)}`);}),this.templates.join("")}normalizeProps(e){Object.entries(e).forEach(([n,r])=>{n===N||isFunction(r)?delete e[n]:isSignal(r)&&(e[n]=r.value);});}generateAttributes(e){return Object.entries(e).filter(([n,r])=>n!==N&&!isFunction(r)).map(([n,r])=>`${n}="${escape(String(r))}"`).join(" ")}renderChildren(e,n){e.forEach(([r])=>{b++;let i=this.renderChild(r);this.templates[n]+=i;});}renderChild(e){if(isFunction(e))return this.renderChild(e(this.props));if(isSignal(e))return `<!--1-${b}-->${e.value}<!$>`;if(I(e)){let n=e.mount();return isFunction(n)?n(this.props):j(n)}else return `<!--1-${b}-->${e}<!$>`}};var ne="area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr".split(",");function V(o){if(f(o)||o instanceof Node||I(o))return o;let t=isFalsy(o)?"":String(o);return document.createTextNode(t)}function T(o,t,e=null){let n=f(e)?e.firstChild:e,r=m.isSSR;f(t)?t.mount(o,n):n&&!r?n.before(t):r||o.append(t);}function S(o){f(o)?o.unmount():o.parentNode&&o.remove();}function Y(o,t,e){T(o,t,e),S(e);}function U(o,t,e){t==="class"?Ee(o,e):t==="style"?Te(o,e):ve(o,t,e);}function Ee(o,t){typeof t=="string"?o.className=t:isArray(t)?o.className=t.join(" "):t&&typeof t=="object"&&(o.className=Object.entries(t).reduce((e,[n,r])=>e+(r?` ${n}`:""),"").trim());}function Te(o,t){typeof t=="string"?o.style.cssText=t:t&&typeof t=="object"&&Object.entries(t).forEach(([n,r])=>{o.style.setProperty(kebabCase(n),String(r));});}function ve(o,t,e){isFalsy(e)?o.removeAttribute(t):e===!0?o.setAttribute(t,""):o instanceof HTMLInputElement&&t==="value"?o.value=String(e):o.setAttribute(t,String(e));}function oe(o,t){if(o instanceof HTMLInputElement)switch(o.type){case"checkbox":return h(o,"change",()=>{t(!!o.checked);});case"date":return h(o,"change",()=>{t(o.value?o.value:"");});case"file":return h(o,"change",()=>{o.files&&t(o.files);});case"number":return h(o,"input",()=>{let e=Number.parseFloat(o.value);t(Number.isNaN(e)?"":String(e));});case"radio":return h(o,"change",()=>{t(o.checked?o.value:"");});case"text":return h(o,"input",()=>{t(o.value);})}if(o instanceof HTMLSelectElement)return h(o,"change",()=>{t(o.value);});if(o instanceof HTMLTextAreaElement)return h(o,"input",()=>{t(o.value);})}function h(o,t,e){return o.addEventListener(t,e),()=>o.removeEventListener(t,e)}function re(o){let t=[],e=[],n=/<\/?([\da-z-]+)([^>]*)>/gi,r=0;for(;;){let i=n.exec(o);if(!i)break;let[s,a]=i,l=s[1]==="/";if(e.push(o.slice(r,i.index)),r=i.index+s.length,l){for(;t.length>0&&t[t.length-1]!==a;){let c=t.pop();c&&e.push(`</${c}>`);}t.length>0&&t.pop();}else ne.includes(a)||t.push(a);e.push(s);}for(e.push(o.slice(r));t.length>0;){let i=t.pop();i&&e.push(`</${i}>`);}return e.join("")}function ie(o){return ne.includes(o)?`<${o}/>`:`<${o}></${o}>`}function j(o){return isSignal(o)?o.value:o}var M=class extends u{constructor(e,n,r){super();this.template=e;this.props=n;this.key=r;this.emitter=new Set;this.rootNode=null;this.trackMap=new Map;this.key||(this.key=n&&n.key),this.proxyProps=this.createProxyProps(n);}createProxyProps(e){return e?signalObject(e,n=>startsWith(n,P)||startsWith(n,L)||n===N):{}}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}mount(e,n){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,n))!=null?s:[];this.initRef(),this.rootNode=this.template(useReactive(this.proxyProps,[N]));let r=(l=(a=this.rootNode)==null?void 0:a.mount(e,n))!=null?l:[];return this.callMountHooks(),this.patchProps(this.props),this.removeRef(),r}unmount(){var e;this.callDestroyHooks(),this.clearHooks(),(e=this.rootNode)==null||e.unmount(),this.rootNode=null,this.proxyProps={},this.clearEmitter();}callMountHooks(){this.hooks.mounted.forEach(e=>e());}callDestroyHooks(){this.hooks.destroy.forEach(e=>e());}clearEmitter(){for(let e of this.emitter)e();this.emitter.clear();}inheritNode(e){Object.assign(this.proxyProps,e.proxyProps),this.rootNode=e.rootNode,this.trackMap=e.trackMap,this.hooks=e.hooks;let n=this.props;this.props=e.props,this.patchProps(n);}getNodeTrack(e){let n=this.trackMap.get(e);return n||(n={cleanup:()=>{}},this.trackMap.set(e,n)),n.cleanup(),n}patchProps(e){var n;if(e){for(let[r,i]of Object.entries(e))startsWith(r,P)&&((n=this.rootNode)!=null&&n.firstChild)?this.patchEventListener(r,i):r===_?this.patchRef(i):startsWith(r,L)?this.patchUpdateHandler(r,i):r!==N&&this.patchNormalProp(r,i);this.props=e;}}patchEventListener(e,n){let r=e.slice(2).toLowerCase(),i=h(this.rootNode.nodes[0],r,n);this.emitter.add(i);}patchRef(e){var n,r;e.value=(r=(n=this.rootNode)==null?void 0:n.firstChild)!=null?r:null;}patchUpdateHandler(e,n){this.props[e]=j(n);}patchNormalProp(e,n){var s,a;let r=(a=(s=this.proxyProps)[e])!=null?a:s[e]=useSignal(n),i=this.getNodeTrack(e);i.cleanup=useEffect(()=>{r.value=isFunction(n)?n():n;});}};function ae(o,t,e,n){let r=new Map,i=Array.from(t.values());if(i.length&&e.length===0)return Ce(o,i,n),r;let s=[],a=ke(e),l=0;for(let[c,d]of e.entries()){let p=i[l],x=y(p,c);for(;p&&!a.has(x);)S(p),t.delete(x),p=i[++l],x=y(p,c);let B=y(d,c),G=t.get(B);if(G&&(d=Me(o,G,d)),p)if(p===G)l++;else {let z=document.createComment("");T(o,z,p),s.push([z,d]);}else T(o,d,n);r.set(B,d);}return s.forEach(([c,d])=>{Y(o,d,c);}),t.forEach((c,d)=>{c.isConnected&&!r.has(d)&&S(c);}),r}function Ce(o,t,e){if(o.childNodes.length===t.length+(e?1:0))o.innerHTML="",e&&T(o,e);else {let n=document.createRange(),r=t[0],i=f(r)?r.firstChild:r;n.setStartBefore(i),e?n.setEndBefore(e):n.setEndAfter(o),n.deleteContents();}t.forEach(n=>{f(n)&&n.unmount();});}function Me(o,t,e){return t===e?t:f(t)&&f(e)&&t.template===e.template?(e.inheritNode(t),e):t instanceof Text&&e instanceof Text?(t.textContent!==e.textContent&&(t.textContent=e.textContent),t):(Y(o,e,t),e)}function ke(o){let t=new Map;for(let[e,n]of o.entries()){let r=y(n,e);t.set(r,n);}return t}function y(o,t){if(f(o)){let e=o.key;if(e!=null)return String(e)}return `_$${t}$`}var k=class{constructor(t,e,n){this.template=t;this.props=e;this.key=n;this.treeMap=new Map;this.mounted=!1;this.nodes=[];this.trackMap=new Map;this.bindValueKeys=[];this.parent=null;this.key||(this.key=e&&e.key),m.isSSR&&(this.componentIndex=Z(this.template));}get firstChild(){var t;return (t=this.nodes[0])!=null?t:null}get isConnected(){return this.mounted}addEventListener(){}removeEventListener(){}mount(t,e){var i;if(this.parent=t,this.isConnected)return this.nodes.forEach(s=>T(t,s,e)),this.nodes;isArray(this.template)&&(this.template=H(this.template.join("")));let n=this.template.content.cloneNode(!0),r=n.firstChild;return (i=r==null?void 0:r.hasAttribute)!=null&&i.call(r,"_svg_")&&(r.remove(),r.childNodes.forEach(s=>{n.append(s);})),this.nodes=Array.from(n.childNodes),m.isSSR?this.mapSSGNodeTree(t):this.mapNodeTree(t,n),T(t,n,e),this.patchProps(this.props),this.mounted=!0,this.nodes}unmount(){var t,e;if(this.trackMap.forEach(n=>{n.cleanup&&n.cleanup();}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(n=>S(n)),!this.template.innerHTML&&!this.nodes.length){let n=(e=(t=this.props)==null?void 0:t[R])==null?void 0:e.children;n&&(isArray(n)?n.forEach(r=>{this.deleteFragmentTextNode(r);}):this.deleteFragmentTextNode(n));}this.nodes=[],this.mounted=!1;}deleteFragmentTextNode(t){isPrimitive(t)?this.parent&&this.parent.childNodes.length&&this.parent.childNodes.forEach(e=>{e.nodeType===Node.TEXT_NODE&&e.textContent===`${t}`&&this.parent.removeChild(e);}):S(t);}inheritNode(t){this.mounted=t.mounted,this.nodes=t.nodes,this.trackMap=t.trackMap,this.treeMap=t.treeMap;let e=this.props;this.props=t.props,this.patchProps(e);}mapSSGNodeTree(t){this.treeMap.set(0,t),this.walkNodeTree(t,this.handleSSGNode.bind(this));}mapNodeTree(t,e){let n=1;this.treeMap.set(0,t);let r=[t],i=s=>{s.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&(this.treeMap.set(n++,s),r.push(s));};this.walkNodeTree(e,i);}walkNodeTree(t,e){t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&e(t);let n=t.firstChild;for(;n;)this.walkNodeTree(n,e),n=n.nextSibling;}handleSSGNode(t){var e;if(t.nodeType===Node.COMMENT_NODE){let[n,r]=((e=t.textContent)==null?void 0:e.split("-"))||[];if(0===+n&&+r===this.componentIndex){let i=t.nextSibling;this.treeMap.set(+r,i);}}else if(t.nodeType!==Node.TEXT_NODE){let{ci:n="-1",hk:r}=(t==null?void 0:t.dataset)||{};r&&+n===this.componentIndex&&this.treeMap.set(+r,t);}}patchProps(t){t&&(Object.entries(t).forEach(([e,n])=>{let r=Number(e),i=this.treeMap.get(r);i&&this.patchProp(e,i,n,r===0);}),this.props=t);}patchProp(t,e,n,r){n&&Object.entries(n).forEach(([i,s])=>{if(i===N&&s)this.patchChildren(t,e,s,r);else if(i===_)n[i].value=e;else if(startsWith(i,P))this.patchEventListener(t,e,i,s);else {if(this.bindValueKeys.includes(i))return;let a=this.getBindUpdateValue(n,t,i);this.patchAttribute(t,e,i,s,a);}});}getBindUpdateValue(t,e,n){let r=`${L}${capitalize(n)}`;if(r&&t[r]&&isFunction(t[r]))return this.bindValueKeys.push(r),t[r]}patchChildren(t,e,n,r){if(isArray(n))n.filter(Boolean).forEach((i,s)=>{var x;let[a,l]=isArray(i)?i:[i,null],c=isNil(l)?null:(x=this.treeMap.get(l))!=null?x:null,d=`${t}:${N}:${s}`,p=this.getNodeTrack(d,!0,r);this.patchChild(p,e,a,c);});else {let i=`${t}:${N}:0`,s=this.getNodeTrack(i,!0,r);this.patchChild(s,e,n,null);}}patchEventListener(t,e,n,r){let i=n.slice(2).toLowerCase(),s=this.getNodeTrack(`${t}:${n}`);s.cleanup=h(e,i,r);}patchAttribute(t,e,n,r,i){let s=this.getNodeTrack(`${t}:${n}`),a=isFunction(r)?r():r,l=isSignal(a)?a:shallowSignal(a);U(e,n,l.value);let c=useEffect(()=>{let p=isFunction(r)?r():r;isPlainObject(p)&&isPlainObject(l.peek())&&JSON.stringify(l.value)===JSON.stringify(p)||(l.value=isSignal(p)?p.value:p,U(e,n,l.value));}),d;i&&isHTMLElement(e)&&(d=oe(e,p=>{i(p);})),s.cleanup=()=>{c&&c(),d&&d();};}getNodeTrack(t,e,n){let r=this.trackMap.get(t);return r||(r={cleanup:()=>{}},e&&(r.lastNodes=new Map),n&&(r.isRoot=!0),this.trackMap.set(t,r)),r.cleanup&&r.cleanup(),r}patchChild(t,e,n,r){isFunction(n)?t.cleanup=useEffect(()=>{let i=coerceArray(n()).map(V);m.isSSR?t.lastNodes=this.reconcileChildren(e,i,r):t.lastNodes=ae(e,t.lastNodes,i,r);}):coerceArray(n).forEach((i,s)=>{let a=V(i),l=y(a,s);m.isSSR?t.lastNodes=this.reconcileChildren(e,[a],r):(t.lastNodes.set(l,a),T(e,a,r));});}reconcileChildren(t,e,n){let r=new Map,i=Array.from(t.childNodes).filter(s=>{var a,l;return s.nodeType===Node.TEXT_NODE&&((a=s.previousSibling)==null?void 0:a.nodeType)===Node.COMMENT_NODE&&((l=s.nextSibling)==null?void 0:l.nodeType)===Node.COMMENT_NODE});return e.forEach((s,a)=>{let l=y(s,a);s.nodeType===Node.TEXT_NODE?i.forEach(c=>{s.textContent===c.textContent&&t.replaceChild(s,c);}):T(t,s,n),r.set(l,s);}),r}};function A(o,t,e){if(isString(o)){let n=o===O,r=n?O:ie(o);return t={[n?R:q]:t},new k(H(r),t,e)}return isFunction(o)?new M(o,t,e):new k(o,t,e)}function Ie(o){return o instanceof M}function f(o){return o instanceof M||o instanceof k}function H(o){let t=document.createElement("template");return t.innerHTML=re(o),t}function je(o){return A(H(O),{[R]:{children:isArray(o.children)?o.children.filter(Boolean):[o.children]}})}function Xe(o){u.ref&&u.ref.addHook("mounted",o);}function De(o){u.ref&&u.ref.addHook("destroy",o);}function Fe(o,t){u.ref&&u.ref.setContext(o,t);}function Ge(o,t){var e;return (e=u.ref&&u.ref.getContext(o))!=null?e:t}function Je(){return shallowSignal(null)}function Ve(o,t){m.setSSG();let n=new C(o,t||{}).mount();return m.setClient(),n}function Ye(o,t){let e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`Could not find container: ${t}`);m.setSSR(),A(o).mount(e),m.setClient();}function Ue(o,t){return m.isSSG?new C(o,t):A(o,t)}export{je as Fragment,A as h,Ye as hydrate,Ie as isComponent,f as isJsxElement,De as onDestroy,Xe as onMount,Ve as renderToString,Ue as ssg,H as template,Ge as useInject,Fe as useProvide,Je as useRef};//# sourceMappingURL=template.esm.js.map
|
|
6
|
+
var w="on",A="update",g="children",H="",B="0",q="1";var _="ref",O=" __PLACEHOLDER__ ";var D=class{constructor(){this.renderMode=0;}get isSSG(){return this.renderMode===1}get isSSR(){return this.renderMode===2}get isClient(){return this.renderMode===0}setSSR(){this.renderMode=2;}setSSG(){this.renderMode=1;}setClient(){this.renderMode=0;}},u=new D,z=new Map;function W(n,t){z.set(n,{index:t});}function Q(n){var t;return (t=z.get(n))==null?void 0:t.index}var y=class y{constructor(){this.hooks={mounted:new Set,destroy:new Set};}addEventListener(){}removeEventListener(){}addHook(t,e){var o;(o=this.hooks[t])==null||o.add(e);}getContext(t){return y.context[t]}setContext(t,e){y.context[t]=e;}initRef(){y.ref=this;}removeRef(){y.ref=null;}clearHooks(){Object.values(this.hooks).forEach(t=>t.clear());}};y.ref=null,y.context={};var l=y;function $(n){return n instanceof M}var b=1,M=class extends l{constructor(e,o={},r){super();this.template=e;this.props=o;this.key=r;W(e,b),this.templates=this.processTemplate();}processTemplate(){if(isArray(this.template)){let e=this.template.join(O);return this.processHtmlString(e).split(O)}return []}processHtmlString(e){return e.replaceAll(/(<[^>]+>)|([^<]+)/g,(o,r,i)=>r?r.includes("data-ci")?o:r.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i,(s,c,a)=>`<${c} data-ci="${b}"${a||""}>`):i&&i.replace(O,"").trim()?`<!--0-${b}-->${i}<!$>`:o)}mount(){this.initRef();let e=this.render();return this.removeRef(),e}render(){if(isFunction(this.template)){let e=this.template(this.props);return $(e)?e.mount():String(e)}return this.renderTemplate()}renderTemplate(){return Object.entries(this.props).forEach(([e,o])=>{let r=o.children;this.normalizeProps(o);let i=this.templates.findIndex(s=>s.includes(`data-hk="${e}"`));r&&this.renderChildren(r,i),this.templates[i]=this.templates[i].replace(`data-hk="${e}"`,`data-hk="${e}" ${this.generateAttributes(o)}`);}),this.templates.join("")}normalizeProps(e){Object.entries(e).forEach(([o,r])=>{o===g||isFunction(r)?delete e[o]:isSignal(r)&&(e[o]=r.value);});}generateAttributes(e){return Object.entries(e).filter(([o,r])=>o!==g&&!isFunction(r)).map(([o,r])=>`${o}="${escape(String(r))}"`).join(" ")}renderChildren(e,o){e.forEach(([r])=>{b++;let i=this.renderChild(r);this.templates[o]+=i;});}renderChild(e){if(isSignal(e))return `<!--1-${b}-->${e.value}<!$>`;if(isFunction(e))return this.renderChild(e(this.props));if($(e)){let o=e.mount();return isFunction(o)?o(this.props):I(o)}else return `<!--1-${b}-->${e}<!$>`}};var Ee="area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr".split(",");function F(n){if(h(n)||n instanceof Node||$(n))return n;let t=isFalsy(n)?"":String(n);return document.createTextNode(t)}function T(n,t,e=null){let o=h(e)?e.firstChild:e,r=u.isSSR;h(t)?t.mount(n,o):o&&!r?o.before(t):r||n.append(t);}function k(n){h(n)?n.unmount():n.parentNode&&n.remove();}function J(n,t,e){T(n,t,e),k(e);}function te(n,t,e){t==="class"?ge(n,e):t==="style"?Te(n,e):ye(n,t,e);}function ge(n,t){typeof t=="string"?n.className=t:isArray(t)?n.className=t.join(" "):t&&typeof t=="object"&&(n.className=Object.entries(t).reduce((e,[o,r])=>e+(r?` ${o}`:""),"").trim());}function Te(n,t){typeof t=="string"?n.style.cssText=t:t&&typeof t=="object"&&Object.entries(t).forEach(([o,r])=>{n.style.setProperty(kebabCase(o),String(r));});}function ye(n,t,e){isFalsy(e)?n.removeAttribute(t):e===!0?n.setAttribute(t,""):n instanceof HTMLInputElement&&t==="value"?n.value=String(e):n.setAttribute(t,String(e));}function oe(n,t){if(n instanceof HTMLInputElement)switch(n.type){case"checkbox":return m(n,"change",()=>{t(!!n.checked);});case"date":return m(n,"change",()=>{t(n.value?n.value:"");});case"file":return m(n,"change",()=>{n.files&&t(n.files);});case"number":return m(n,"input",()=>{let e=Number.parseFloat(n.value);t(Number.isNaN(e)?"":String(e));});case"radio":return m(n,"change",()=>{t(n.checked?n.value:"");});case"text":return m(n,"input",()=>{t(n.value);})}if(n instanceof HTMLSelectElement)return m(n,"change",()=>{t(n.value);});if(n instanceof HTMLTextAreaElement)return m(n,"input",()=>{t(n.value);})}function m(n,t,e){return n.addEventListener(t,e),()=>n.removeEventListener(t,e)}function ne(n){return Ee.includes(n)?`<${n}/>`:`<${n}></${n}>`}function I(n){return isSignal(n)?n.value:n}var S=class extends l{constructor(e,o,r){super();this.template=e;this.props=o;this.key=r;this.emitter=new Set;this.rootNode=null;this.trackMap=new Map;this.nodes=[];this.parent=null;this.before=null;this.key||(this.key=o&&o.key),this.proxyProps||(this.proxyProps=shallowReactive(o||{}));}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}mount(e,o){var r,i,s,c;if(this.parent=e,!isFunction(this.template))throw new Error("Template must be a function");return this.isConnected?(i=(r=this.rootNode)==null?void 0:r.mount(e,o))!=null?i:[]:(this.initRef(),this.rootNode=this.template(useReactive(this.proxyProps,[g])),this.nodes=(c=(s=this.rootNode)==null?void 0:s.mount(e,o))!=null?c:[],this.callMountHooks(),this.patchProps(this.props),this.removeRef(),this.nodes)}unmount(){var e;this.callLifecycleHooks("destroy"),this.cleanup(),(e=this.rootNode)==null||e.unmount(),this.resetState(),this.key&&L.delete(this.key);}resetState(){this.rootNode=null,this.proxyProps={},this.nodes=[],this.parent=null;}callLifecycleHooks(e){this.hooks[e].forEach(o=>o());}callMountHooks(){this.hooks.mounted.forEach(e=>e());}callDestroyHooks(){this.hooks.destroy.forEach(e=>e());}clearEmitter(){for(let e of this.emitter)e();this.emitter.clear();}inheritNode(e){if(Object.assign(this.proxyProps,e.proxyProps),this.rootNode=e.rootNode,this.trackMap=e.trackMap,this.hooks=e.hooks,hasChanged(e.props,this.props)){let o=this.props;this.props=e.props,this.patchProps(o);}}getNodeTrack(e){let o=this.trackMap.get(e);return o||(o={cleanup:()=>{}},this.trackMap.set(e,o)),o.cleanup(),o}patchProps(e){var o;if(e){for(let[r,i]of Object.entries(e))startsWith(r,w)&&((o=this.rootNode)!=null&&o.firstChild)?this.patchEventListener(r,i):r===_?this.patchRef(i):startsWith(r,A)?this.patchUpdateHandler(r,i):r!==g&&this.patchNormalProp(r,i);this.props=e;}}patchEventListener(e,o){let r=e.slice(2).toLowerCase(),i=m(this.rootNode.nodes[0],r,o);this.emitter.add(i);}patchRef(e){var o,r;e.value=(r=(o=this.rootNode)==null?void 0:o.firstChild)!=null?r:null;}patchUpdateHandler(e,o){this.proxyProps[e]=I(o);}patchNormalProp(e,o){let r=this.getNodeTrack(e);r.cleanup=useEffect(()=>{this.proxyProps[e]=isFunction(o)?o():o;});}cleanup(){this.trackMap.forEach(e=>{var o;return (o=e.cleanup)==null?void 0:o.call(e)}),this.trackMap.clear(),this.emitter.forEach(e=>e()),this.emitter.clear();}};function se(n,t,e,o){let r=new Map,i=Array.from(t.values());if(i.length&&e.length===0)return be(n,i,o),r;let s=[],c=ke(e),a=0;for(let[d,p]of e.entries()){let f=i[a],C=x(f,d);for(;f&&!c.has(C);)k(f),t.delete(C),f=i[++a],C=x(f,d);let Y=x(p,d),G=t.get(Y);if(G&&(p=Me(n,G,p)),f)if(f===G)a++;else {let U=document.createComment("");T(n,U,f),s.push([U,p]);}else T(n,p,o);r.set(Y,p);}return s.forEach(([d,p])=>{J(n,p,d);}),t.forEach((d,p)=>{d.isConnected&&!r.has(p)&&k(d);}),r}function be(n,t,e){if(n.childNodes.length===t.length+(e?1:0))n.innerHTML="",e&&T(n,e);else {let o=document.createRange(),r=t[0],i=h(r)?r.firstChild:r;o.setStartBefore(i),e?o.setEndBefore(e):o.setEndAfter(n),o.deleteContents();}t.forEach(o=>{h(o)&&o.unmount();});}function Me(n,t,e){return t===e?t:h(t)&&h(e)&&t.template===e.template?(e.inheritNode(t),e):t instanceof Text&&e instanceof Text?(t.textContent!==e.textContent&&(t.textContent=e.textContent),t):(J(n,e,t),e)}function ke(n){let t=new Map;for(let[e,o]of n.entries()){let r=x(o,e);t.set(r,o);}return t}function x(n,t){if(h(n)){let e=n.key;if(e!=null)return String(e)}return `_$${t}$`}var v=class{constructor(t,e,o){this.template=t;this.props=e;this.key=o;this.treeMap=new Map;this.mounted=!1;this.nodes=[];this.trackMap=new Map;this.bindValueKeys=[];this.parent=null;u.isSSR&&(this.componentIndex=Q(this.template));}get firstChild(){var t;return (t=this.nodes[0])!=null?t:null}get isConnected(){return this.mounted}addEventListener(){}removeEventListener(){}mount(t,e){var i;if(this.parent=t,this.isConnected)return this.nodes.forEach(s=>T(t,s,e)),this.nodes;isArray(this.template)&&(this.template=R(this.template.join("")));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.childNodes.forEach(s=>{o.append(s);})),this.nodes=Array.from(o.childNodes),u.isSSR?this.mapSSGNodeTree(t):this.mapNodeTree(t,o),T(t,o,e),this.patchProps(this.props),this.mounted=!0,this.nodes}unmount(){this.trackMap.forEach(t=>{t.cleanup&&t.cleanup();}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(t=>k(t)),this.nodes=[],this.mounted=!1,this.key&&L.delete(this.key);}inheritNode(t){this.mounted=t.mounted,this.nodes=t.nodes,this.trackMap=t.trackMap,this.treeMap=t.treeMap;let e=this.props;this.props=t.props,this.patchProps(e);}mapSSGNodeTree(t){this.treeMap.set(0,t),this.walkNodeTree(t,this.handleSSGNode.bind(this));}mapNodeTree(t,e){let o=1;this.treeMap.set(0,t);let r=[t],i=s=>{s.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&(this.treeMap.set(o++,s),r.push(s));};this.walkNodeTree(e,i);}walkNodeTree(t,e){t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&e(t);let o=t.firstChild;for(;o;)this.walkNodeTree(o,e),o=o.nextSibling;}handleSSGNode(t){var e;if(t.nodeType===Node.COMMENT_NODE){let[o,r]=((e=t.textContent)==null?void 0:e.split("-"))||[];if(0===+o&&+r===this.componentIndex){let i=t.nextSibling;this.treeMap.set(+r,i);}}else if(t.nodeType!==Node.TEXT_NODE){let{ci:o="-1",hk:r}=(t==null?void 0:t.dataset)||{};r&&+o===this.componentIndex&&this.treeMap.set(+r,t);}}patchProps(t){t&&(Object.entries(t).forEach(([e,o])=>{let r=Number(e),i=this.treeMap.get(r);i&&this.patchProp(e,i,o,r===0);}),this.props=t);}patchProp(t,e,o,r){o&&Object.entries(o).forEach(([i,s])=>{if(i===g&&s)this.patchChildren(t,e,s,r);else if(i===_)o[i].value=e;else if(startsWith(i,w))this.patchEventListener(t,e,i,s);else {if(this.bindValueKeys.includes(i))return;let c=this.getBindUpdateValue(o,t,i);this.patchAttribute(t,e,i,s,c);}});}getBindUpdateValue(t,e,o){let r=`${A}${capitalize(o)}`;if(r&&t[r]&&isFunction(t[r]))return this.bindValueKeys.push(r),t[r]}patchChildren(t,e,o,r){if(isArray(o))o.filter(Boolean).forEach((i,s)=>{var C;let[c,a]=isArray(i)?i:[i,null],d=isNil(a)?null:(C=this.treeMap.get(a))!=null?C:null,p=`${t}:${g}:${s}`,f=this.getNodeTrack(p,!0,r);this.patchChild(f,e,c,d);});else {let i=`${t}:${g}:0`,s=this.getNodeTrack(i,!0,r);this.patchChild(s,e,o,null);}}patchEventListener(t,e,o,r){let i=o.slice(2).toLowerCase(),s=this.getNodeTrack(`${t}:${o}`);s.cleanup=m(e,i,r);}patchAttribute(t,e,o,r,i){let s=this.getNodeTrack(`${t}:${o}`),c=shallowSignal(),a=useEffect(()=>{c.value=isSignal(r)||isComputed(r)?r.value:r,te(e,o,c.value);}),d;i&&isHTMLElement(e)&&(d=oe(e,p=>{i(p);})),s.cleanup=()=>{a&&a(),d&&d();};}getNodeTrack(t,e,o){let r=this.trackMap.get(t);return r||(r={cleanup:()=>{}},e&&(r.lastNodes=new Map),o&&(r.isRoot=!0),this.trackMap.set(t,r)),r.cleanup&&r.cleanup(),r}patchChild(t,e,o,r){isFunction(o)?t.cleanup=useEffect(()=>{let i=coerceArray(o()).map(F);u.isSSR?t.lastNodes=this.reconcileChildren(e,i,r):t.lastNodes=se(e,t.lastNodes,i,r);}):coerceArray(o).forEach((i,s)=>{let c=F(i),a=x(c,s);u.isSSR?t.lastNodes=this.reconcileChildren(e,[c],r):(t.lastNodes.set(a,c),T(e,c,r));});}reconcileChildren(t,e,o){let r=new Map,i=Array.from(t.childNodes).filter(s=>{var c,a;return s.nodeType===Node.TEXT_NODE&&((c=s.previousSibling)==null?void 0:c.nodeType)===Node.COMMENT_NODE&&((a=s.nextSibling)==null?void 0:a.nodeType)===Node.COMMENT_NODE});return e.forEach((s,c)=>{let a=x(s,c);s.nodeType===Node.TEXT_NODE?i.forEach(d=>{s.textContent===d.textContent&&t.replaceChild(s,d);}):T(t,s,o),r.set(a,s);}),r}};var L=new Map;function j(n,t,e={},o){if(o){let i=L.get(o);if(i)return i}typeof t=="string"&&(t=R(t));let r=new n(t,e,o);return o&&r instanceof S&&L.set(o,r),r}function K(n,t={},e){if(n===H)return le(n,t);if(isString(n)){let o=ne(n),r={[q]:t};return j(v,o,r,e)}return isFunction(n)?j(S,n,t,e):j(v,n,t,e)}function Ie(n){return n instanceof S}function h(n){return n instanceof S||n instanceof v}function R(n){let t=document.createElement("template");return t.innerHTML=n,t}function le(n,t){let e=t.children?{[B]:{children:Array.isArray(t.children)?t.children.filter(Boolean):[t.children]}}:t,o=n===H?R(H):n;return j(v,o,e)}function je(n){l.ref&&l.ref.addHook("mounted",n);}function Ke(n){l.ref&&l.ref.addHook("destroy",n);}function Xe(n,t){l.ref&&l.ref.setContext(n,t);}function Ge(n,t){var e;return (e=l.ref&&l.ref.getContext(n))!=null?e:t}function De(n,t){u.setSSG();let o=new M(n,t||{}).mount();return u.setClient(),o}function Fe(n,t){let e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`Could not find container: ${t}`);u.setSSR(),K(n).mount(e),u.setClient();}function Je(n,t){return u.isSSG?new M(n,t):K(n,t)}export{le as Fragment,K as h,Fe as hydrate,Ge as inject,Ie as isComponent,h as isJsxElement,Ke as onDestroy,je as onMount,Xe as provide,De as renderToString,Je as ssg,R as template};//# sourceMappingURL=template.esm.js.map
|
|
7
7
|
//# sourceMappingURL=template.esm.js.map
|