@estjs/template 0.0.14-beta.19 → 0.0.14-beta.21

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.
@@ -4,7 +4,7 @@ var shared = require('@estjs/shared');
4
4
  var signal = require('@estjs/signal');
5
5
 
6
6
  /**
7
- * @estjs/template v0.0.14-beta.19
7
+ * @estjs/template v0.0.14-beta.21
8
8
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
9
9
  * @license MIT
10
10
  **/
@@ -322,11 +322,11 @@ function addEventListener(node, eventName, handler) {
322
322
  function convertToHtmlTag(tagName) {
323
323
  return SELF_CLOSING_TAGS.includes(tagName) ? `<${tagName}/>` : `<${tagName}></${tagName}>`;
324
324
  }
325
- function extractSignal(signal2) {
326
- if (signal.isSignal(signal2)) {
327
- return signal2.value;
325
+ function extractSignal(signal$1) {
326
+ if (signal.isSignal(signal$1)) {
327
+ return signal$1.value;
328
328
  } else {
329
- return signal2;
329
+ return signal$1;
330
330
  }
331
331
  }
332
332
  var ComponentNode = class extends LifecycleContext {
@@ -338,12 +338,15 @@ var ComponentNode = class extends LifecycleContext {
338
338
  this.emitter = /* @__PURE__ */ new Set();
339
339
  this.rootNode = null;
340
340
  this.trackMap = /* @__PURE__ */ new Map();
341
+ this.nodes = [];
342
+ this.parent = null;
343
+ this.before = null;
341
344
  this.key || (this.key = props && props.key);
342
- this.proxyProps = this.createProxyProps(props);
345
+ this.proxyProps || (this.proxyProps = this.createProxyProps(props));
343
346
  }
344
347
  createProxyProps(props) {
345
348
  if (!props) return {};
346
- return signal.signalObject(
349
+ return signal.shallowReactive(
347
350
  props,
348
351
  (key) => shared.startsWith(key, EVENT_PREFIX) || shared.startsWith(key, UPDATE_PREFIX) || key === CHILDREN_PROP
349
352
  );
@@ -358,6 +361,7 @@ var ComponentNode = class extends LifecycleContext {
358
361
  }
359
362
  mount(parent, before) {
360
363
  var _a, _b, _c, _d;
364
+ this.parent = parent;
361
365
  if (!shared.isFunction(this.template)) {
362
366
  throw new Error("Template must be a function");
363
367
  }
@@ -366,20 +370,30 @@ var ComponentNode = class extends LifecycleContext {
366
370
  }
367
371
  this.initRef();
368
372
  this.rootNode = this.template(signal.reactive(this.proxyProps, [CHILDREN_PROP]));
369
- const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
373
+ this.nodes = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
370
374
  this.callMountHooks();
371
375
  this.patchProps(this.props);
372
376
  this.removeRef();
373
- return mountedNode;
377
+ return this.nodes;
374
378
  }
375
379
  unmount() {
376
380
  var _a;
377
- this.callDestroyHooks();
378
- this.clearHooks();
381
+ this.callLifecycleHooks("destroy");
382
+ this.cleanup();
379
383
  (_a = this.rootNode) == null ? void 0 : _a.unmount();
384
+ this.resetState();
385
+ if (this.key) {
386
+ componentCache.delete(this.key);
387
+ }
388
+ }
389
+ resetState() {
380
390
  this.rootNode = null;
381
391
  this.proxyProps = {};
382
- this.clearEmitter();
392
+ this.nodes = [];
393
+ this.parent = null;
394
+ }
395
+ callLifecycleHooks(type) {
396
+ this.hooks[type].forEach((handler) => handler());
383
397
  }
384
398
  callMountHooks() {
385
399
  this.hooks.mounted.forEach((handler) => handler());
@@ -398,9 +412,11 @@ var ComponentNode = class extends LifecycleContext {
398
412
  this.rootNode = node.rootNode;
399
413
  this.trackMap = node.trackMap;
400
414
  this.hooks = node.hooks;
401
- const props = this.props;
402
- this.props = node.props;
403
- this.patchProps(props);
415
+ if (shared.hasChanged(node.props, this.props)) {
416
+ const props = this.props;
417
+ this.props = node.props;
418
+ this.patchProps(props);
419
+ }
404
420
  }
405
421
  getNodeTrack(trackKey) {
406
422
  let track = this.trackMap.get(trackKey);
@@ -440,16 +456,23 @@ var ComponentNode = class extends LifecycleContext {
440
456
  prop.value = (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
441
457
  }
442
458
  patchUpdateHandler(key, prop) {
443
- this.props[key] = extractSignal(prop);
459
+ this.proxyProps[key] = extractSignal(prop);
444
460
  }
445
461
  patchNormalProp(key, prop) {
446
- var _a, _b;
447
- const newValue = (_b = (_a = this.proxyProps)[key]) != null ? _b : _a[key] = signal.signal(prop);
448
462
  const track = this.getNodeTrack(key);
449
463
  track.cleanup = signal.effect(() => {
450
- newValue.value = shared.isFunction(prop) ? prop() : prop;
464
+ this.proxyProps[key] = shared.isFunction(prop) ? prop() : prop;
451
465
  });
452
466
  }
467
+ cleanup() {
468
+ this.trackMap.forEach((track) => {
469
+ var _a;
470
+ return (_a = track.cleanup) == null ? void 0 : _a.call(track);
471
+ });
472
+ this.trackMap.clear();
473
+ this.emitter.forEach((cleanup) => cleanup());
474
+ this.emitter.clear();
475
+ }
453
476
  };
454
477
 
455
478
  // src/patch.ts
@@ -624,6 +647,9 @@ var TemplateNode = class {
624
647
  this.nodes.forEach((node) => removeChild(node));
625
648
  this.nodes = [];
626
649
  this.mounted = false;
650
+ if (this.key) {
651
+ componentCache.delete(this.key);
652
+ }
627
653
  }
628
654
  inheritNode(node) {
629
655
  this.mounted = node.mounted;
@@ -814,41 +840,37 @@ var TemplateNode = class {
814
840
  }
815
841
  };
816
842
 
817
- // src/fragmentNode.ts
818
- var FragmentNode = class extends TemplateNode {
819
- unmount() {
820
- this.trackMap.forEach((track) => {
821
- if (track.lastNodes) {
822
- track.lastNodes.forEach((node) => {
823
- removeChild(node);
824
- });
825
- }
826
- track.cleanup && track.cleanup();
827
- });
828
- this.trackMap.clear();
829
- this.treeMap.clear();
830
- this.nodes.forEach((node) => {
831
- removeChild(node);
832
- });
833
- this.nodes = [];
834
- this.mounted = false;
835
- }
836
- };
837
-
838
843
  // src/jsxRenderer.ts
839
- function h(template, props, key) {
844
+ var componentCache = /* @__PURE__ */ new Map();
845
+ function createNodeCache(NodeConstructor, template, props = {}, key) {
846
+ if (key) {
847
+ const cached = componentCache.get(key);
848
+ if (cached) {
849
+ return cached;
850
+ }
851
+ }
852
+ if (typeof template === "string") {
853
+ template = createTemplate(template);
854
+ }
855
+ const newNode = new NodeConstructor(template, props, key);
856
+ if (key && newNode instanceof ComponentNode) {
857
+ componentCache.set(key, newNode);
858
+ }
859
+ return newNode;
860
+ }
861
+ function h(template, props = {}, key) {
840
862
  if (template === EMPTY_TEMPLATE) {
841
863
  return Fragment(template, props);
842
864
  }
843
865
  if (shared.isString(template)) {
844
866
  const htmlTemplate = convertToHtmlTag(template);
845
- props = { [SINGLE_PROP_KEY]: props };
846
- return new TemplateNode(createTemplate(htmlTemplate), props, key);
867
+ const wrappedProps = { [SINGLE_PROP_KEY]: props };
868
+ return createNodeCache(TemplateNode, htmlTemplate, wrappedProps, key);
847
869
  }
848
870
  if (shared.isFunction(template)) {
849
- return new ComponentNode(template, props, key);
871
+ return createNodeCache(ComponentNode, template, props, key);
850
872
  }
851
- return new TemplateNode(template, props, key);
873
+ return createNodeCache(TemplateNode, template, props, key);
852
874
  }
853
875
  function isComponent(node) {
854
876
  return node instanceof ComponentNode;
@@ -862,17 +884,13 @@ function createTemplate(html) {
862
884
  return template;
863
885
  }
864
886
  function Fragment(template, props) {
865
- if (props.children) {
866
- props = {
867
- [FRAGMENT_PROP_KEY]: {
868
- children: shared.isArray(props.children) ? props.children.filter(Boolean) : [props.children]
869
- }
870
- };
871
- }
872
- if (template === EMPTY_TEMPLATE) {
873
- template = createTemplate(EMPTY_TEMPLATE);
874
- }
875
- return new FragmentNode(template, props);
887
+ const processedProps = props.children ? {
888
+ [FRAGMENT_PROP_KEY]: {
889
+ children: Array.isArray(props.children) ? props.children.filter(Boolean) : [props.children]
890
+ }
891
+ } : props;
892
+ const templateElement = template === EMPTY_TEMPLATE ? createTemplate(EMPTY_TEMPLATE) : template;
893
+ return createNodeCache(TemplateNode, templateElement, processedProps);
876
894
  }
877
895
  function onMount(cb) {
878
896
  assertInsideComponent("onMounted");
@@ -1,8 +1,8 @@
1
- import { isString, isFunction, isArray, isSymbol, escape, startsWith, capitalize, isNil, isPlainObject, isHTMLElement, coerceArray, isFalsy, kebabCase } from '@estjs/shared';
2
- import { isSignal, signalObject, reactive, signal, effect, shallowSignal } from '@estjs/signal';
1
+ import { isString, isFunction, isSymbol, isArray, escape, startsWith, hasChanged, capitalize, isNil, isPlainObject, isHTMLElement, coerceArray, isFalsy, kebabCase } from '@estjs/shared';
2
+ import { isSignal, shallowReactive, reactive, effect, shallowSignal } from '@estjs/signal';
3
3
 
4
4
  /**
5
- * @estjs/template v0.0.14-beta.19
5
+ * @estjs/template v0.0.14-beta.21
6
6
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
7
7
  * @license MIT
8
8
  **/
@@ -320,11 +320,11 @@ function addEventListener(node, eventName, handler) {
320
320
  function convertToHtmlTag(tagName) {
321
321
  return SELF_CLOSING_TAGS.includes(tagName) ? `<${tagName}/>` : `<${tagName}></${tagName}>`;
322
322
  }
323
- function extractSignal(signal2) {
324
- if (isSignal(signal2)) {
325
- return signal2.value;
323
+ function extractSignal(signal) {
324
+ if (isSignal(signal)) {
325
+ return signal.value;
326
326
  } else {
327
- return signal2;
327
+ return signal;
328
328
  }
329
329
  }
330
330
  var ComponentNode = class extends LifecycleContext {
@@ -336,12 +336,15 @@ var ComponentNode = class extends LifecycleContext {
336
336
  this.emitter = /* @__PURE__ */ new Set();
337
337
  this.rootNode = null;
338
338
  this.trackMap = /* @__PURE__ */ new Map();
339
+ this.nodes = [];
340
+ this.parent = null;
341
+ this.before = null;
339
342
  this.key || (this.key = props && props.key);
340
- this.proxyProps = this.createProxyProps(props);
343
+ this.proxyProps || (this.proxyProps = this.createProxyProps(props));
341
344
  }
342
345
  createProxyProps(props) {
343
346
  if (!props) return {};
344
- return signalObject(
347
+ return shallowReactive(
345
348
  props,
346
349
  (key) => startsWith(key, EVENT_PREFIX) || startsWith(key, UPDATE_PREFIX) || key === CHILDREN_PROP
347
350
  );
@@ -356,6 +359,7 @@ var ComponentNode = class extends LifecycleContext {
356
359
  }
357
360
  mount(parent, before) {
358
361
  var _a, _b, _c, _d;
362
+ this.parent = parent;
359
363
  if (!isFunction(this.template)) {
360
364
  throw new Error("Template must be a function");
361
365
  }
@@ -364,20 +368,30 @@ var ComponentNode = class extends LifecycleContext {
364
368
  }
365
369
  this.initRef();
366
370
  this.rootNode = this.template(reactive(this.proxyProps, [CHILDREN_PROP]));
367
- const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
371
+ this.nodes = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
368
372
  this.callMountHooks();
369
373
  this.patchProps(this.props);
370
374
  this.removeRef();
371
- return mountedNode;
375
+ return this.nodes;
372
376
  }
373
377
  unmount() {
374
378
  var _a;
375
- this.callDestroyHooks();
376
- this.clearHooks();
379
+ this.callLifecycleHooks("destroy");
380
+ this.cleanup();
377
381
  (_a = this.rootNode) == null ? void 0 : _a.unmount();
382
+ this.resetState();
383
+ if (this.key) {
384
+ componentCache.delete(this.key);
385
+ }
386
+ }
387
+ resetState() {
378
388
  this.rootNode = null;
379
389
  this.proxyProps = {};
380
- this.clearEmitter();
390
+ this.nodes = [];
391
+ this.parent = null;
392
+ }
393
+ callLifecycleHooks(type) {
394
+ this.hooks[type].forEach((handler) => handler());
381
395
  }
382
396
  callMountHooks() {
383
397
  this.hooks.mounted.forEach((handler) => handler());
@@ -396,9 +410,11 @@ var ComponentNode = class extends LifecycleContext {
396
410
  this.rootNode = node.rootNode;
397
411
  this.trackMap = node.trackMap;
398
412
  this.hooks = node.hooks;
399
- const props = this.props;
400
- this.props = node.props;
401
- this.patchProps(props);
413
+ if (hasChanged(node.props, this.props)) {
414
+ const props = this.props;
415
+ this.props = node.props;
416
+ this.patchProps(props);
417
+ }
402
418
  }
403
419
  getNodeTrack(trackKey) {
404
420
  let track = this.trackMap.get(trackKey);
@@ -438,16 +454,23 @@ var ComponentNode = class extends LifecycleContext {
438
454
  prop.value = (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
439
455
  }
440
456
  patchUpdateHandler(key, prop) {
441
- this.props[key] = extractSignal(prop);
457
+ this.proxyProps[key] = extractSignal(prop);
442
458
  }
443
459
  patchNormalProp(key, prop) {
444
- var _a, _b;
445
- const newValue = (_b = (_a = this.proxyProps)[key]) != null ? _b : _a[key] = signal(prop);
446
460
  const track = this.getNodeTrack(key);
447
461
  track.cleanup = effect(() => {
448
- newValue.value = isFunction(prop) ? prop() : prop;
462
+ this.proxyProps[key] = isFunction(prop) ? prop() : prop;
449
463
  });
450
464
  }
465
+ cleanup() {
466
+ this.trackMap.forEach((track) => {
467
+ var _a;
468
+ return (_a = track.cleanup) == null ? void 0 : _a.call(track);
469
+ });
470
+ this.trackMap.clear();
471
+ this.emitter.forEach((cleanup) => cleanup());
472
+ this.emitter.clear();
473
+ }
451
474
  };
452
475
 
453
476
  // src/patch.ts
@@ -622,6 +645,9 @@ var TemplateNode = class {
622
645
  this.nodes.forEach((node) => removeChild(node));
623
646
  this.nodes = [];
624
647
  this.mounted = false;
648
+ if (this.key) {
649
+ componentCache.delete(this.key);
650
+ }
625
651
  }
626
652
  inheritNode(node) {
627
653
  this.mounted = node.mounted;
@@ -812,41 +838,37 @@ var TemplateNode = class {
812
838
  }
813
839
  };
814
840
 
815
- // src/fragmentNode.ts
816
- var FragmentNode = class extends TemplateNode {
817
- unmount() {
818
- this.trackMap.forEach((track) => {
819
- if (track.lastNodes) {
820
- track.lastNodes.forEach((node) => {
821
- removeChild(node);
822
- });
823
- }
824
- track.cleanup && track.cleanup();
825
- });
826
- this.trackMap.clear();
827
- this.treeMap.clear();
828
- this.nodes.forEach((node) => {
829
- removeChild(node);
830
- });
831
- this.nodes = [];
832
- this.mounted = false;
833
- }
834
- };
835
-
836
841
  // src/jsxRenderer.ts
837
- function h(template, props, key) {
842
+ var componentCache = /* @__PURE__ */ new Map();
843
+ function createNodeCache(NodeConstructor, template, props = {}, key) {
844
+ if (key) {
845
+ const cached = componentCache.get(key);
846
+ if (cached) {
847
+ return cached;
848
+ }
849
+ }
850
+ if (typeof template === "string") {
851
+ template = createTemplate(template);
852
+ }
853
+ const newNode = new NodeConstructor(template, props, key);
854
+ if (key && newNode instanceof ComponentNode) {
855
+ componentCache.set(key, newNode);
856
+ }
857
+ return newNode;
858
+ }
859
+ function h(template, props = {}, key) {
838
860
  if (template === EMPTY_TEMPLATE) {
839
861
  return Fragment(template, props);
840
862
  }
841
863
  if (isString(template)) {
842
864
  const htmlTemplate = convertToHtmlTag(template);
843
- props = { [SINGLE_PROP_KEY]: props };
844
- return new TemplateNode(createTemplate(htmlTemplate), props, key);
865
+ const wrappedProps = { [SINGLE_PROP_KEY]: props };
866
+ return createNodeCache(TemplateNode, htmlTemplate, wrappedProps, key);
845
867
  }
846
868
  if (isFunction(template)) {
847
- return new ComponentNode(template, props, key);
869
+ return createNodeCache(ComponentNode, template, props, key);
848
870
  }
849
- return new TemplateNode(template, props, key);
871
+ return createNodeCache(TemplateNode, template, props, key);
850
872
  }
851
873
  function isComponent(node) {
852
874
  return node instanceof ComponentNode;
@@ -860,17 +882,13 @@ function createTemplate(html) {
860
882
  return template;
861
883
  }
862
884
  function Fragment(template, props) {
863
- if (props.children) {
864
- props = {
865
- [FRAGMENT_PROP_KEY]: {
866
- children: isArray(props.children) ? props.children.filter(Boolean) : [props.children]
867
- }
868
- };
869
- }
870
- if (template === EMPTY_TEMPLATE) {
871
- template = createTemplate(EMPTY_TEMPLATE);
872
- }
873
- return new FragmentNode(template, props);
885
+ const processedProps = props.children ? {
886
+ [FRAGMENT_PROP_KEY]: {
887
+ children: Array.isArray(props.children) ? props.children.filter(Boolean) : [props.children]
888
+ }
889
+ } : props;
890
+ const templateElement = template === EMPTY_TEMPLATE ? createTemplate(EMPTY_TEMPLATE) : template;
891
+ return createNodeCache(TemplateNode, templateElement, processedProps);
874
892
  }
875
893
  function onMount(cb) {
876
894
  assertInsideComponent("onMounted");
@@ -1,7 +1,7 @@
1
- import {isString,isFunction,isArray,escape,startsWith,capitalize,isNil,isPlainObject,isHTMLElement,coerceArray,isFalsy,kebabCase}from'@estjs/shared';import {isSignal,signalObject,reactive,signal,effect,shallowSignal}from'@estjs/signal';/**
2
- * @estjs/template v0.0.14-beta.19
1
+ import {isString,isFunction,isArray,escape,startsWith,hasChanged,capitalize,isNil,isPlainObject,isHTMLElement,coerceArray,isFalsy,kebabCase}from'@estjs/shared';import {isSignal,shallowReactive,reactive,effect,shallowSignal}from'@estjs/signal';/**
2
+ * @estjs/template v0.0.14-beta.21
3
3
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
4
4
  * @license MIT
5
5
  **/
6
- var P="on",L="update",E="children",H="",q="0",z="1";var A="ref",O=" __PLACEHOLDER__ ";var G=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 G,W=new Map;function Q(n,e){W.set(n,{index:e});}function Z(n){var e;return (e=W.get(n))==null?void 0:e.index}var y=class y{constructor(){this.hooks={mounted:new Set,destroy:new Set};}addEventListener(){}removeEventListener(){}addHook(e,t){var o;(o=this.hooks[e])==null||o.add(t);}getContext(e){return y.context[e]}setContext(e,t){y.context[e]=t;}initRef(){y.ref=this;}removeRef(){y.ref=null;}clearHooks(){Object.values(this.hooks).forEach(e=>e.clear());}};y.ref=null,y.context={};var p=y;function _(n){return n instanceof M}var C=1,M=class extends p{constructor(t,o={},r){super();this.template=t;this.props=o;this.key=r;Q(t,C),this.templates=this.processTemplate();}processTemplate(){if(isArray(this.template)){let t=this.template.join(O);return this.processHtmlString(t).split(O)}return []}processHtmlString(t){return t.replaceAll(/(<[^>]+>)|([^<]+)/g,(o,r,i)=>r?r.includes("data-ci")?o:r.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i,(s,a,c)=>`<${a} data-ci="${C}"${c||""}>`):i&&i.replace(O,"").trim()?`<!--0-${C}-->${i}<!$>`:o)}mount(){this.initRef();let t=this.render();return this.removeRef(),t}render(){if(isFunction(this.template)){let t=this.template(this.props);return _(t)?t.mount():String(t)}return this.renderTemplate()}renderTemplate(){return Object.entries(this.props).forEach(([t,o])=>{let r=o.children;this.normalizeProps(o);let i=this.templates.findIndex(s=>s.includes(`data-hk="${t}"`));r&&this.renderChildren(r,i),this.templates[i]=this.templates[i].replace(`data-hk="${t}"`,`data-hk="${t}" ${this.generateAttributes(o)}`);}),this.templates.join("")}normalizeProps(t){Object.entries(t).forEach(([o,r])=>{o===E||isFunction(r)?delete t[o]:isSignal(r)&&(t[o]=r.value);});}generateAttributes(t){return Object.entries(t).filter(([o,r])=>o!==E&&!isFunction(r)).map(([o,r])=>`${o}="${escape(String(r))}"`).join(" ")}renderChildren(t,o){t.forEach(([r])=>{C++;let i=this.renderChild(r);this.templates[o]+=i;});}renderChild(t){if(isSignal(t))return `<!--1-${C}-->${t.value}<!$>`;if(isFunction(t))return this.renderChild(t(this.props));if(_(t)){let o=t.mount();return isFunction(o)?o(this.props):$(o)}else return `<!--1-${C}-->${t}<!$>`}};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 e=isFalsy(n)?"":String(n);return document.createTextNode(e)}function T(n,e,t=null){let o=h(t)?t.firstChild:t,r=u.isSSR;h(e)?e.mount(n,o):o&&!r?o.before(e):r||n.append(e);}function S(n){h(n)?n.unmount():n.parentNode&&n.remove();}function J(n,e,t){T(n,e,t),S(t);}function oe(n,e,t){e==="class"?ge(n,t):e==="style"?Te(n,t):Se(n,e,t);}function ge(n,e){typeof e=="string"?n.className=e:isArray(e)?n.className=e.join(" "):e&&typeof e=="object"&&(n.className=Object.entries(e).reduce((t,[o,r])=>t+(r?` ${o}`:""),"").trim());}function Te(n,e){typeof e=="string"?n.style.cssText=e:e&&typeof e=="object"&&Object.entries(e).forEach(([o,r])=>{n.style.setProperty(kebabCase(o),String(r));});}function Se(n,e,t){isFalsy(t)?n.removeAttribute(e):t===!0?n.setAttribute(e,""):n instanceof HTMLInputElement&&e==="value"?n.value=String(t):n.setAttribute(e,String(t));}function ne(n,e){if(n instanceof HTMLInputElement)switch(n.type){case"checkbox":return m(n,"change",()=>{e(!!n.checked);});case"date":return m(n,"change",()=>{e(n.value?n.value:"");});case"file":return m(n,"change",()=>{n.files&&e(n.files);});case"number":return m(n,"input",()=>{let t=Number.parseFloat(n.value);e(Number.isNaN(t)?"":String(t));});case"radio":return m(n,"change",()=>{e(n.checked?n.value:"");});case"text":return m(n,"input",()=>{e(n.value);})}if(n instanceof HTMLSelectElement)return m(n,"change",()=>{e(n.value);});if(n instanceof HTMLTextAreaElement)return m(n,"input",()=>{e(n.value);})}function m(n,e,t){return n.addEventListener(e,t),()=>n.removeEventListener(e,t)}function re(n){return Ee.includes(n)?`<${n}/>`:`<${n}></${n}>`}function $(n){return isSignal(n)?n.value:n}var k=class extends p{constructor(t,o,r){super();this.template=t;this.props=o;this.key=r;this.emitter=new Set;this.rootNode=null;this.trackMap=new Map;this.key||(this.key=o&&o.key),this.proxyProps=this.createProxyProps(o);}createProxyProps(t){return t?signalObject(t,o=>startsWith(o,P)||startsWith(o,L)||o===E):{}}get firstChild(){var t,o;return (o=(t=this.rootNode)==null?void 0:t.firstChild)!=null?o:null}get isConnected(){var t,o;return (o=(t=this.rootNode)==null?void 0:t.isConnected)!=null?o:!1}mount(t,o){var i,s,a,c;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(t,o))!=null?s:[];this.initRef(),this.rootNode=this.template(reactive(this.proxyProps,[E]));let r=(c=(a=this.rootNode)==null?void 0:a.mount(t,o))!=null?c:[];return this.callMountHooks(),this.patchProps(this.props),this.removeRef(),r}unmount(){var t;this.callDestroyHooks(),this.clearHooks(),(t=this.rootNode)==null||t.unmount(),this.rootNode=null,this.proxyProps={},this.clearEmitter();}callMountHooks(){this.hooks.mounted.forEach(t=>t());}callDestroyHooks(){this.hooks.destroy.forEach(t=>t());}clearEmitter(){for(let t of this.emitter)t();this.emitter.clear();}inheritNode(t){Object.assign(this.proxyProps,t.proxyProps),this.rootNode=t.rootNode,this.trackMap=t.trackMap,this.hooks=t.hooks;let o=this.props;this.props=t.props,this.patchProps(o);}getNodeTrack(t){let o=this.trackMap.get(t);return o||(o={cleanup:()=>{}},this.trackMap.set(t,o)),o.cleanup(),o}patchProps(t){var o;if(t){for(let[r,i]of Object.entries(t))startsWith(r,P)&&((o=this.rootNode)!=null&&o.firstChild)?this.patchEventListener(r,i):r===A?this.patchRef(i):startsWith(r,L)?this.patchUpdateHandler(r,i):r!==E&&this.patchNormalProp(r,i);this.props=t;}}patchEventListener(t,o){let r=t.slice(2).toLowerCase(),i=m(this.rootNode.nodes[0],r,o);this.emitter.add(i);}patchRef(t){var o,r;t.value=(r=(o=this.rootNode)==null?void 0:o.firstChild)!=null?r:null;}patchUpdateHandler(t,o){this.props[t]=$(o);}patchNormalProp(t,o){var s,a;let r=(a=(s=this.proxyProps)[t])!=null?a:s[t]=signal(o),i=this.getNodeTrack(t);i.cleanup=effect(()=>{r.value=isFunction(o)?o():o;});}};function se(n,e,t,o){let r=new Map,i=Array.from(e.values());if(i.length&&t.length===0)return Ce(n,i,o),r;let s=[],a=ke(t),c=0;for(let[d,l]of t.entries()){let g=i[c],b=v(g,d);for(;g&&!a.has(b);)S(g),e.delete(b),g=i[++c],b=v(g,d);let U=v(l,d),D=e.get(U);if(D&&(l=Me(n,D,l)),g)if(g===D)c++;else {let B=document.createComment("");T(n,B,g),s.push([B,l]);}else T(n,l,o);r.set(U,l);}return s.forEach(([d,l])=>{J(n,l,d);}),e.forEach((d,l)=>{d.isConnected&&!r.has(l)&&S(d);}),r}function Ce(n,e,t){if(n.childNodes.length===e.length+(t?1:0))n.innerHTML="",t&&T(n,t);else {let o=document.createRange(),r=e[0],i=h(r)?r.firstChild:r;o.setStartBefore(i),t?o.setEndBefore(t):o.setEndAfter(n),o.deleteContents();}e.forEach(o=>{h(o)&&o.unmount();});}function Me(n,e,t){return e===t?e:h(e)&&h(t)&&e.template===t.template?(t.inheritNode(e),t):e instanceof Text&&t instanceof Text?(e.textContent!==t.textContent&&(e.textContent=t.textContent),e):(J(n,t,e),t)}function ke(n){let e=new Map;for(let[t,o]of n.entries()){let r=v(o,t);e.set(r,o);}return e}function v(n,e){if(h(n)){let t=n.key;if(t!=null)return String(t)}return `_$${e}$`}var x=class{constructor(e,t,o){this.template=e;this.props=t;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=Z(this.template));}get firstChild(){var e;return (e=this.nodes[0])!=null?e:null}get isConnected(){return this.mounted}addEventListener(){}removeEventListener(){}mount(e,t){var i;if(this.parent=e,this.isConnected)return this.nodes.forEach(s=>T(e,s,t)),this.nodes;isArray(this.template)&&(this.template=w(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(e):this.mapNodeTree(e,o),T(e,o,t),this.patchProps(this.props),this.mounted=!0,this.nodes}unmount(){this.trackMap.forEach(e=>{e.cleanup&&e.cleanup();}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(e=>S(e)),this.nodes=[],this.mounted=!1;}inheritNode(e){this.mounted=e.mounted,this.nodes=e.nodes,this.trackMap=e.trackMap,this.treeMap=e.treeMap;let t=this.props;this.props=e.props,this.patchProps(t);}mapSSGNodeTree(e){this.treeMap.set(0,e),this.walkNodeTree(e,this.handleSSGNode.bind(this));}mapNodeTree(e,t){let o=1;this.treeMap.set(0,e);let r=[e],i=s=>{s.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&(this.treeMap.set(o++,s),r.push(s));};this.walkNodeTree(t,i);}walkNodeTree(e,t){e.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&t(e);let o=e.firstChild;for(;o;)this.walkNodeTree(o,t),o=o.nextSibling;}handleSSGNode(e){var t;if(e.nodeType===Node.COMMENT_NODE){let[o,r]=((t=e.textContent)==null?void 0:t.split("-"))||[];if(0===+o&&+r===this.componentIndex){let i=e.nextSibling;this.treeMap.set(+r,i);}}else if(e.nodeType!==Node.TEXT_NODE){let{ci:o="-1",hk:r}=(e==null?void 0:e.dataset)||{};r&&+o===this.componentIndex&&this.treeMap.set(+r,e);}}patchProps(e){e&&(Object.entries(e).forEach(([t,o])=>{let r=Number(t),i=this.treeMap.get(r);i&&this.patchProp(t,i,o,r===0);}),this.props=e);}patchProp(e,t,o,r){o&&Object.entries(o).forEach(([i,s])=>{if(i===E&&s)this.patchChildren(e,t,s,r);else if(i===A)o[i].value=t;else if(startsWith(i,P))this.patchEventListener(e,t,i,s);else {if(this.bindValueKeys.includes(i))return;let a=this.getBindUpdateValue(o,e,i);this.patchAttribute(e,t,i,s,a);}});}getBindUpdateValue(e,t,o){let r=`${L}${capitalize(o)}`;if(r&&e[r]&&isFunction(e[r]))return this.bindValueKeys.push(r),e[r]}patchChildren(e,t,o,r){if(isArray(o))o.filter(Boolean).forEach((i,s)=>{var b;let[a,c]=isArray(i)?i:[i,null],d=isNil(c)?null:(b=this.treeMap.get(c))!=null?b:null,l=`${e}:${E}:${s}`,g=this.getNodeTrack(l,!0,r);this.patchChild(g,t,a,d);});else {let i=`${e}:${E}:0`,s=this.getNodeTrack(i,!0,r);this.patchChild(s,t,o,null);}}patchEventListener(e,t,o,r){let i=o.slice(2).toLowerCase(),s=this.getNodeTrack(`${e}:${o}`);s.cleanup=m(t,i,r);}patchAttribute(e,t,o,r,i){let s=this.getNodeTrack(`${e}:${o}`),a=shallowSignal(),c=effect(()=>{let l=isFunction(r)?r():r;isPlainObject(l)&&isPlainObject(a.peek())&&JSON.stringify(a.value)===JSON.stringify(l)||(a.value=isSignal(l)?l.value:l,oe(t,o,a.value));}),d;i&&isHTMLElement(t)&&(d=ne(t,l=>{i(l);})),s.cleanup=()=>{c&&c(),d&&d();};}getNodeTrack(e,t,o){let r=this.trackMap.get(e);return r||(r={cleanup:()=>{}},t&&(r.lastNodes=new Map),o&&(r.isRoot=!0),this.trackMap.set(e,r)),r.cleanup&&r.cleanup(),r}patchChild(e,t,o,r){isFunction(o)?e.cleanup=effect(()=>{let i=coerceArray(o()).map(F);u.isSSR?e.lastNodes=this.reconcileChildren(t,i,r):e.lastNodes=se(t,e.lastNodes,i,r);}):coerceArray(o).forEach((i,s)=>{let a=F(i),c=v(a,s);u.isSSR?e.lastNodes=this.reconcileChildren(t,[a],r):(e.lastNodes.set(c,a),T(t,a,r));});}reconcileChildren(e,t,o){let r=new Map,i=Array.from(e.childNodes).filter(s=>{var a,c;return s.nodeType===Node.TEXT_NODE&&((a=s.previousSibling)==null?void 0:a.nodeType)===Node.COMMENT_NODE&&((c=s.nextSibling)==null?void 0:c.nodeType)===Node.COMMENT_NODE});return t.forEach((s,a)=>{let c=v(s,a);s.nodeType===Node.TEXT_NODE?i.forEach(d=>{s.textContent===d.textContent&&e.replaceChild(s,d);}):T(e,s,o),r.set(c,s);}),r}};var j=class extends x{unmount(){this.trackMap.forEach(e=>{e.lastNodes&&e.lastNodes.forEach(t=>{S(t);}),e.cleanup&&e.cleanup();}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(e=>{S(e);}),this.nodes=[],this.mounted=!1;}};function K(n,e,t){if(n===H)return de(n,e);if(isString(n)){let o=re(n);return e={[z]:e},new x(w(o),e,t)}return isFunction(n)?new k(n,e,t):new x(n,e,t)}function Ie(n){return n instanceof k}function h(n){return n instanceof k||n instanceof x}function w(n){let e=document.createElement("template");return e.innerHTML=n,e}function de(n,e){return e.children&&(e={[q]:{children:isArray(e.children)?e.children.filter(Boolean):[e.children]}}),n===H&&(n=w(H)),new j(n,e)}function je(n){p.ref&&p.ref.addHook("mounted",n);}function Ke(n){p.ref&&p.ref.addHook("destroy",n);}function Xe(n,e){p.ref&&p.ref.setContext(n,e);}function De(n,e){var t;return (t=p.ref&&p.ref.getContext(n))!=null?t:e}function Ge(n,e){u.setSSG();let o=new M(n,e||{}).mount();return u.setClient(),o}function Fe(n,e){let t=typeof e=="string"?document.querySelector(e):e;if(!t)throw new Error(`Could not find container: ${e}`);u.setSSR(),K(n).mount(t),u.setClient();}function Je(n,e){return u.isSSG?new M(n,e):K(n,e)}export{de as Fragment,K as h,Fe as hydrate,De as inject,Ie as isComponent,h as isJsxElement,Ke as onDestroy,je as onMount,Xe as provide,Ge as renderToString,Je as ssg,w as template};//# sourceMappingURL=template.esm.js.map
6
+ var L="on",R="update",f="children",H="",z="0",W="1";var O="ref",_=" __PLACEHOLDER__ ";var F=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 F,Q=new Map;function Z(n,t){Q.set(n,{index:t});}function ee(n){var t;return (t=Q.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 p=y;function $(n){return n instanceof M}var b=1,M=class extends p{constructor(e,o={},r){super();this.template=e;this.props=o;this.key=r;Z(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,(o,r,i)=>r?r.includes("data-ci")?o:r.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i,(s,c,d)=>`<${c} data-ci="${b}"${d||""}>`):i&&i.replace(_,"").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===f||isFunction(r)?delete e[o]:isSignal(r)&&(e[o]=r.value);});}generateAttributes(e){return Object.entries(e).filter(([o,r])=>o!==f&&!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 ge="area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr".split(",");function J(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 V(n,t,e){T(n,t,e),k(e);}function ne(n,t,e){t==="class"?Te(n,e):t==="style"?ye(n,e):Se(n,t,e);}function Te(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 ye(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 Se(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 re(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 ie(n){return ge.includes(n)?`<${n}/>`:`<${n}></${n}>`}function I(n){return isSignal(n)?n.value:n}var S=class extends p{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=this.createProxyProps(o));}createProxyProps(e){return e?shallowReactive(e,o=>startsWith(o,L)||startsWith(o,R)||o===f):{}}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(reactive(this.proxyProps,[f])),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&&P.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,L)&&((o=this.rootNode)!=null&&o.firstChild)?this.patchEventListener(r,i):r===O?this.patchRef(i):startsWith(r,R)?this.patchUpdateHandler(r,i):r!==f&&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=effect(()=>{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 ce(n,t,e,o){let r=new Map,i=Array.from(t.values());if(i.length&&e.length===0)return Me(n,i,o),r;let s=[],c=Pe(e),d=0;for(let[l,a]of e.entries()){let N=i[d],C=x(N,l);for(;N&&!c.has(C);)k(N),t.delete(C),N=i[++d],C=x(N,l);let B=x(a,l),D=t.get(B);if(D&&(a=ke(n,D,a)),N)if(N===D)d++;else {let q=document.createComment("");T(n,q,N),s.push([q,a]);}else T(n,a,o);r.set(B,a);}return s.forEach(([l,a])=>{V(n,a,l);}),t.forEach((l,a)=>{l.isConnected&&!r.has(a)&&k(l);}),r}function Me(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 ke(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):(V(n,e,t),e)}function Pe(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=ee(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=A(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&&P.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===f&&s)this.patchChildren(t,e,s,r);else if(i===O)o[i].value=e;else if(startsWith(i,L))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=`${R}${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,d]=isArray(i)?i:[i,null],l=isNil(d)?null:(C=this.treeMap.get(d))!=null?C:null,a=`${t}:${f}:${s}`,N=this.getNodeTrack(a,!0,r);this.patchChild(N,e,c,l);});else {let i=`${t}:${f}: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(),d=effect(()=>{let a=isFunction(r)?r():r;isPlainObject(a)&&isPlainObject(c.peek())&&JSON.stringify(c.value)===JSON.stringify(a)||(c.value=isSignal(a)?a.value:a,ne(e,o,c.value));}),l;i&&isHTMLElement(e)&&(l=re(e,a=>{i(a);})),s.cleanup=()=>{d&&d(),l&&l();};}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=effect(()=>{let i=coerceArray(o()).map(J);u.isSSR?t.lastNodes=this.reconcileChildren(e,i,r):t.lastNodes=ce(e,t.lastNodes,i,r);}):coerceArray(o).forEach((i,s)=>{let c=J(i),d=x(c,s);u.isSSR?t.lastNodes=this.reconcileChildren(e,[c],r):(t.lastNodes.set(d,c),T(e,c,r));});}reconcileChildren(t,e,o){let r=new Map,i=Array.from(t.childNodes).filter(s=>{var c,d;return s.nodeType===Node.TEXT_NODE&&((c=s.previousSibling)==null?void 0:c.nodeType)===Node.COMMENT_NODE&&((d=s.nextSibling)==null?void 0:d.nodeType)===Node.COMMENT_NODE});return e.forEach((s,c)=>{let d=x(s,c);s.nodeType===Node.TEXT_NODE?i.forEach(l=>{s.textContent===l.textContent&&t.replaceChild(s,l);}):T(t,s,o),r.set(d,s);}),r}};var P=new Map;function K(n,t,e={},o){if(o){let i=P.get(o);if(i)return i}typeof t=="string"&&(t=A(t));let r=new n(t,e,o);return o&&r instanceof S&&P.set(o,r),r}function X(n,t={},e){if(n===H)return pe(n,t);if(isString(n)){let o=ie(n),r={[W]:t};return K(v,o,r,e)}return isFunction(n)?K(S,n,t,e):K(v,n,t,e)}function Ie(n){return n instanceof S}function h(n){return n instanceof S||n instanceof v}function A(n){let t=document.createElement("template");return t.innerHTML=n,t}function pe(n,t){let e=t.children?{[z]:{children:Array.isArray(t.children)?t.children.filter(Boolean):[t.children]}}:t,o=n===H?A(H):n;return K(v,o,e)}function je(n){p.ref&&p.ref.addHook("mounted",n);}function Ke(n){p.ref&&p.ref.addHook("destroy",n);}function Xe(n,t){p.ref&&p.ref.setContext(n,t);}function Ge(n,t){var e;return (e=p.ref&&p.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(),X(n).mount(e),u.setClient();}function Je(n,t){return u.isSSG?new M(n,t):X(n,t)}export{pe as Fragment,X 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,A as template};//# sourceMappingURL=template.esm.js.map
7
7
  //# sourceMappingURL=template.esm.js.map