essor 0.0.11 → 0.0.12-beta.1
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/essor.cjs.js +1401 -35
- package/dist/essor.cjs.js.map +1 -1
- package/dist/essor.d.cts +1 -1
- package/dist/essor.d.ts +1 -1
- package/dist/essor.dev.cjs.js +291 -116
- package/dist/essor.dev.esm.js +288 -114
- package/dist/essor.esm.js +1372 -7
- package/dist/essor.esm.js.map +1 -1
- package/package.json +4 -4
package/dist/essor.cjs.js
CHANGED
|
@@ -1,55 +1,1421 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* essor v0.0.
|
|
4
|
+
* essor v0.0.12-beta.1
|
|
5
5
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
6
6
|
* @license MIT
|
|
7
7
|
**/
|
|
8
|
-
var nt="0.0.11";var rt=t=>t!==null&&typeof t=="object";var D=Array.isArray;function K(t){return typeof t=="string"}function st(t){return t==null}var d=t=>typeof t=="function";function B(t){return t===!1||t===null||t===void 0}function q(t){return Array.isArray(t)?t.flat():[t]}function g(t,e){return K(t)?t.indexOf(e)===0:!1}var ot=t=>t.replaceAll(/[A-Z]+/g,(e,n)=>`${n>0?"-":""}${e.toLocaleLowerCase()}`);var it=t=>t.charAt(0).toUpperCase()+t.slice(1);var Tt=Object.defineProperty,ct=Object.getOwnPropertySymbols,Ot=Object.prototype.hasOwnProperty,At=Object.prototype.propertyIsEnumerable,at=(t,e,n)=>e in t?Tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,A=(t,e)=>{for(var n in e||(e={}))Ot.call(e,n)&&at(t,n,e[n]);if(ct)for(var n of ct(e))At.call(e,n)&&at(t,n,e[n]);return t},j=t=>t!==null&&typeof t=="object",pt=Array.isArray;function jt(t){return typeof t=="string"}function xt(t){return t===null}function Pt(t){return $.call(t)==="[object Set]"}function $t(t){return $.call(t)==="[object WeakMap]"}function Lt(t){return $.call(t)==="[object WeakSet]"}function Rt(t){return $.call(t)==="[object Map]"}var J=t=>typeof t=="function",ut=t=>["string","number","boolean","symbol","undefined"].includes(typeof t)||xt(t);function lt(t){return t?t&&typeof t=="object"&&t.nodeType===1&&typeof t.nodeName=="string":!1}var $=Object.prototype.toString,Wt=Object.prototype.hasOwnProperty,Ht=(t,e)=>Wt.call(t,e),L=(t,e)=>t!==e&&(t===t||e===e),Ft=Function.prototype;function It(t,e){return jt(t)?t.indexOf(e)===0:!1}function x(t,e){return Array.isArray(e)?e.includes(t):J(e)?e(t):!1}function ft(t,...e){console.warn.apply(console,[`[Essor warn]: ${t}`].concat(e));}var b=null,_=null,U=new WeakMap,G=new WeakMap,Z=new Set,z=new WeakMap,Dt=["push","pop","shift","unshift","splice","sort","reverse"];function R(t,e){if(!b&&!_)return;let n=G.get(t);n||(n=new Map,G.set(t,n));let r=n.get(e);r||(r=new Set,n.set(e,r)),b&&r.add(b);let o=U.get(t);o||(o=new Map,U.set(t,o));let s=o.get(e);s||(s=new Set,o.set(e,s)),_&&s.add(_);}function E(t,e){let n=G.get(t);if(!n)return;let r=n.get(e);r&&r.forEach(s=>Z.has(s)&&s());let o=U.get(t);if(o){let s=o.get(e);s&&s.forEach(c=>c.run());}}var X=class{constructor(t,e=!1){this._value=t,this._shallow=e;}get value(){return R(this,"_sv"),this.__triggerObject(),this._value}__triggerObject(){!ut(this._value)&&!lt(this._value)&&!this._shallow&&k(this._value);}set value(t){h(t)&&(console.warn("Signal cannot be set to another signal, use .peek() instead"),t=t.peek()),L(t,this._value)&&(this._value=t,!ut(this._value)&&!lt(this._value)&&this.__triggerObject(),E(this,"_sv"));}peek(){return this._value}};function W(t){return h(t)?t:new X(t)}function le(t){return new X(t,!0)}function h(t){return t instanceof X}var dt=class{constructor(t){this.fn=t;let e=_;_=this,this._value=this.fn(),_=e;}peek(){return this._value}run(){let t=this.fn();L(t,this._value)&&(this._value=t,E(this,"_cv"));}get value(){return R(this,"_cv"),this._value}};function Kt(t){return new dt(t)}function ht(t){return t instanceof dt}function M(t){function e(){let n=b;b=e,t(),b=n;}return Z.add(e),e(),()=>{Z.delete(e),b=null;}}function mt(t,e){return Object.entries(t).reduce((r,[o,s])=>(r[o]=x(o,e)||h(s)?s:W(s),r),{})}function Bt(t,e){return t?h(t)?t.peek():pt(t)?t.map(n=>Bt(n,e)):j(t)?Object.entries(t).reduce((n,[r,o])=>(x(r,e)?n[r]=o:n[r]=h(o)?o.peek():w(o)?gt(o):o,n),{}):t:{}}var vt=Symbol("useReactive");function w(t){return t&&t[vt]===!0}function qt(t){Dt.forEach(e=>{let n=Array.prototype[e];R(t,"length"),Object.defineProperty(t,e,{value(...r){let o=n.apply(this,r);return ["push","pop","shift","unshift","splice","sort","reverse"].includes(e)&&E(t,"length"),o},enumerable:!1,writable:!0,configurable:!0});});}function k(t,e){return bt(t,e,!1)}function fe(t,e){return bt(t,e,!0)}function gt(t){if(!j(t)||!w(t))return t;let e=Array.isArray(t)?[]:{};for(let n in t)if(Ht(t,n)){let r=t[n];w(r)?e[n]=gt(r):h(r)?e[n]=r.peek():e[n]=r;}return e}function bt(t,e,n=!1){if(!j(t)||w(t))return t;if(z.has(t))return z.get(t);if(Array.isArray(t)&&qt(t),Pt(t)||Rt(t)||Lt(t)||$t(t))return t;let r={get(s,c,i){if(c===vt||It(c,"_"))return !0;let a=Reflect.get(s,c,i),l=h(a)?a.value:a;return x(c,e)?l:(R(s,c),j(l)&&!n?k(l):l)},set(s,c,i,a){if(x(c,e))return Reflect.set(s,c,i,a),!0;let l=Reflect.get(s,c,a);h(l)&&(l=l.value),h(i)&&(i=i.value);let u=Reflect.set(s,c,i,a);return L(i,l)&&E(s,c),u},deleteProperty(s,c){let i=Reflect.get(s,c),a=Reflect.deleteProperty(s,c);return i!==void 0&&E(s,c),a}},o=new Proxy(t,r);return z.set(t,o),o}function zt(t,e,n){return Jt(t,e,n)}function Jt(t,e,n){let r;h(t)||ht(t)?r=()=>t.value:w(t)?r=()=>A({},t):pt(t)?r=()=>t.map(i=>h(i)||ht(i)?i.value:w(i)?A({},i):J(i)?i():ft("Invalid source",i)):J(t)?r=t:(ft("Invalid source type",t),r=Ft);let o,s=()=>{let i=r();(n!=null&&n.deep||L(i,o))&&(e&&e(i,o),o=i);},c=M(s);return n!=null&&n.immediate&&s(),c}var P=0,Q=new Map;function Ut(t){let{state:e,getters:n,actions:r}=t,o=A({},e!=null?e:{}),s=k(e!=null?e:{}),c=[],i=[],l=A({state:s},{patch$(u){Object.assign(s,u),c.forEach(f=>f(s)),i.forEach(f=>f(s));},subscribe$(u){c.push(u);},unsubscribe$(u){let f=c.indexOf(u);f!==-1&&c.splice(f,1);},onAction$(u){i.push(u);},reset$(){Object.assign(s,o);}});for(let u in n){let f=n[u];f&&zt(Kt(f.bind(s,s)),p=>{l[u]=p;});}for(let u in r){let f=r[u];f&&(l[u]=f.bind(s));}return Q.set(P,l),++P,l}function he(t){return function(){return Q.has(P)?Q.get(P):Ut(t)}}var Y=class S{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=mt(n,r=>g(r,"on")||g(r,"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 r;(r=this.hooks[e])==null||r.add(n);}getContext(e){return S.context[e]}setContext(e,n){S.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,o,s,c;if(!d(this.template))throw new Error("Template must be a function");if(this.isConnected)return (o=(r=this.rootNode)==null?void 0:r.mount(e,n))!=null?o:[];S.ref=this,this.rootNode=this.template(k(this.proxyProps,["children"])),S.ref=null,this.mounted=!0;let i=(c=(s=this.rootNode)==null?void 0:s.mount(e,n))!=null?c:[];return this.hooks.mounted.forEach(a=>a()),this.patchProps(this.props),i}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 r=this.trackMap.get(e);return r||(r={cleanup:()=>{}},this.trackMap.set(e,r)),n||r.cleanup(),r}patchProps(e){var n,r,o,s,c;for(let[i,a]of Object.entries(e))if(g(i,"on")&&((n=this.rootNode)!=null&&n.nodes)){let l=i.slice(2).toLowerCase(),u=a,f=m(this.rootNode.nodes[0],l,u);this.emitter.add(f);}else if(i==="ref")h(a)?e[i].value=(r=this.rootNode)==null?void 0:r.nodes[0]:d(a)&&e[i]((o=this.rootNode)==null?void 0:o.nodes[0]);else if(g(i,"update"))e[i]=h(a)?a.value:a;else if(i!=="children"){let l=(c=(s=this.proxyProps)[i])!=null?c:s[i]=W(a),u=this.getNodeTrack(i);u.cleanup=M(()=>{l.value=d(a)?a():a;});}this.props=e;}};Y.ref=null;Y.context={};var N=Y;function ye(t,e){return K(t)&&(Yt(t)&&(t=Vt(t),e={1:e}),t===""&&(e={0:e}),t=Gt(t)),d(t)?new N(t,e):new kt(t,e)}function v(t){return t instanceof N||t instanceof kt}function Gt(t){t=Xt(t);let e=document.createElement("template");return e.innerHTML=t,e}function Ne(t){return t.children}var Ct="area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr",Zt="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 yt(t){if(v(t)||t instanceof Node)return t;let e=B(t)?"":String(t);return document.createTextNode(e)}function y(t,e,n=null){let r=v(n)?n.firstChild:n;v(e)?e.mount(t,r):r?r.before(e):t.append(e);}function T(t){v(t)?t.unmount():t.parentNode&&t.remove();}function Et(t,e,n){y(t,e,n),T(n);}function Nt(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((r,[o,s])=>r+(s?` ${o}`:""),"").trim());return}if(e==="style"){if(typeof n=="string")t.style.cssText=n;else if(n&&typeof n=="object"){let r=n;Object.keys(r).forEach(o=>{t.style.setProperty(ot(o),String(r[o]));});}return}B(n)?t.removeAttribute(e):n===!0?t.setAttribute(e,""):t instanceof HTMLInputElement?t.value=String(n):t.setAttribute(e,String(n));}function Qt(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 _t=Promise.resolve();function _e(t){return t?_t.then(t):_t}function m(t,e,n){return t.addEventListener(e,n),()=>t.removeEventListener(e,n)}function Xt(t){let e=Ct.split(","),n=[],r=[],o=/<\/?([\da-z-]+)([^>]*)>/gi,s=0;for(;;){let c=o.exec(t);if(!c)break;let[i,a]=c,l=i[1]==="/";if(r.push(t.slice(s,c.index)),s=c.index+i.length,l){for(;n.length>0&&n[n.length-1]!==a;){let u=n.pop();u&&r.push(`</${u}>`);}n.length>0&&n.pop();}else e.includes(a)||n.push(a);r.push(i);}for(r.push(t.slice(s));n.length>0;){let c=n.pop();c&&r.push(`</${c}>`);}return r.join("")}function Yt(t){return Zt.split(",").includes(t)}function Vt(t){return Ct.split(",").includes(t)?`<${t}/>`:`<${t}></${t}>`}function te(){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e="",n=t.length;for(let r=0;r<8;r++)e+=t.charAt(Math.floor(Math.random()*n));return e}function ee(t,e,n,r){let o=new Map,s=Array.from(e.values()),c=s.length;if(e.size>0&&n.length===0){if(t.childNodes.length===c+(r?1:0))t.innerHTML="",r&&y(t,r);else {let u=document.createRange(),f=s[0],p=v(f)?f.firstChild:f;u.setStartBefore(p),r?u.setEndBefore(r):u.setEndAfter(t),u.deleteContents();}return s.forEach(u=>{v(u)&&u.unmount();}),o}let i=[],a=re(n),l=0;for(let[u,f]of n.entries()){let p=s[l],C=H(p,u);for(;p&&!a.has(C);)T(p),e.delete(C),p=s[++l],C=H(p,u);let tt=H(f,u),I=e.get(tt);if(I&&(f=ne(t,I,f)),p)if(p===I)l++;else {let et=document.createComment("");y(t,et,p),i.push([et,f]);}else y(t,f,r);o.set(tt,f);}return i.forEach(([u,f])=>Et(t,f,u)),e.forEach((u,f)=>{u.isConnected&&!o.has(f)&&T(u);}),o}function ne(t,e,n){return e===n?e:v(e)&&v(n)&&e.template===n.template?(n.inheritNode(e),n):e instanceof Text&&n instanceof Text?(e.textContent!==n.textContent&&(e.textContent=n.textContent),e):(Et(t,n,e),n)}function re(t){let e=new Map;for(let[n,r]of t.entries()){let o=H(r,n);e.set(o,r);}return e}function H(t,e){if(v(t)){let n=t.key;if(n!=null)return String(n)}return `_$${e}$`}var kt=class St{constructor(e,n,r){this.template=e,this.props=n,this.key=r,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 r;if(this.parent=e,this.isConnected)return this.nodes.forEach(c=>y(e,c,n)),this.nodes;this.key=this.key||te();let o=this.template.content.cloneNode(!0),s=o.firstChild;return (r=s==null?void 0:s.hasAttribute)!=null&&r.call(s,"_svg_")&&(s.remove(),s==null||s.childNodes.forEach(c=>{o.append(c);})),this.nodes=Array.from(o.childNodes),this.mapNodeTree(e,o),y(e,o,n),this.patchNodes(this.props),this.mounted=!0,this.nodes}unmount(){this.trackMap.forEach(e=>{var n,r;(n=e.cleanup)==null||n.call(e),(r=e.lastNodes)==null||r.forEach(o=>{e.isRoot?T(o):o instanceof St&&o.unmount();});}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(e=>T(e)),this.nodes=[],this.mounted=!1;}mapNodeTree(e,n){let r=1;this.treeMap.set(0,e);let o=s=>{s.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&this.treeMap.set(r++,s);let c=s.firstChild;for(;c;)o(c),c=c.nextSibling;};o(n);}patchNodes(e){for(let n in e){let r=Number(n),o=this.treeMap.get(r);if(o){let s=this.props[n];this.patchNode(n,o,s,r===0);}}this.props=e;}getNodeTrack(e,n,r){var o;let s=this.trackMap.get(e);return s||(s={cleanup:()=>{}},n&&(s.lastNodes=new Map),r&&(s.isRoot=!0),this.trackMap.set(e,s)),(o=s.cleanup)==null||o.call(s),s}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,r,o){for(let s in r)if(s==="children"&&r.children)if(D(r.children))r.children.filter(Boolean).forEach((c,i)=>{var a;let[l,u]=D(c)?c:[c,null],f=st(u)?null:(a=this.treeMap.get(u))!=null?a:null,p=`${e}:${s}:${i}`,C=this.getNodeTrack(p,!0,o);Mt(C,n,l,f);});else {let c=`${e}:${s}:0`,i=this.getNodeTrack(c,!0,o);Mt(i,n,r.children,null);}else if(s==="ref")h(r[s])?r[s].value=n:d(r[s])&&r[s](n);else if(g(s,"on")){let c=s.slice(2).toLocaleLowerCase(),i=this.getNodeTrack(`${e}:${s}`),a=r[s];i.cleanup=m(n,c,a);}else if(!g(s,"update")){let c=this.getNodeTrack(`${e}:${s}`),i=r[s],a=h(i)?i:W(i);wt(c,n,s,a.value);let l=M(()=>{a.value=h(i)?i.value:i,wt(c,n,s,a.value);}),u,f=`update${it(s)}`;r[f]&&(u=Qt(n,p=>{r[f](p);})),c.cleanup=()=>{l&&l(),u&&u();};}}};function wt(t,e,n,r){let o=e;o.setAttribute&&(d(r)?t.cleanup=M(()=>{Nt(o,n,r());}):Nt(o,n,r));}function Mt(t,e,n,r){d(n)?t.cleanup=M(()=>{let o=q(n()).map(yt);t.lastNodes=ee(e,t.lastNodes,o,r);}):q(n).forEach((o,s)=>{let c=yt(o);t.lastNodes.set(String(s),c),y(e,c,r);});}function we(t){var e;F("onMounted"),(e=N.ref)==null||e.addHook("mounted",t);}function Me(t){var e;F("onDestroy"),(e=N.ref)==null||e.addHook("destroy",t);}function F(t){N.ref||console.error(`"${t}" can only be called within the component function body
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
|
|
9
|
+
// src/version.ts
|
|
10
|
+
var essor_version = "0.0.12-beta.1";
|
|
11
|
+
|
|
12
|
+
// ../shared/dist/shared.js
|
|
13
|
+
var isObject = (val) => val !== null && typeof val === "object";
|
|
14
|
+
var isArray = Array.isArray;
|
|
15
|
+
function isString(val) {
|
|
16
|
+
return typeof val === "string";
|
|
17
|
+
}
|
|
18
|
+
function isSymbol(val) {
|
|
19
|
+
return typeof val === "symbol";
|
|
20
|
+
}
|
|
21
|
+
function isNil(x) {
|
|
22
|
+
return x === null || x === void 0;
|
|
23
|
+
}
|
|
24
|
+
var isFunction = (val) => typeof val === "function";
|
|
25
|
+
function isFalsy(x) {
|
|
26
|
+
return x === false || x === null || x === void 0;
|
|
27
|
+
}
|
|
28
|
+
function coerceArray(data) {
|
|
29
|
+
return Array.isArray(data) ? data.flat() : [data];
|
|
30
|
+
}
|
|
31
|
+
function startsWith(str, searchString) {
|
|
32
|
+
if (!isString(str)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return str.indexOf(searchString) === 0;
|
|
36
|
+
}
|
|
37
|
+
function escape(str) {
|
|
38
|
+
return str.replaceAll(/["&'<>]/g, (char) => {
|
|
39
|
+
switch (char) {
|
|
40
|
+
case "&":
|
|
41
|
+
return "&";
|
|
42
|
+
case "<":
|
|
43
|
+
return "<";
|
|
44
|
+
case ">":
|
|
45
|
+
return ">";
|
|
46
|
+
case '"':
|
|
47
|
+
return """;
|
|
48
|
+
case "'":
|
|
49
|
+
return "'";
|
|
50
|
+
default:
|
|
51
|
+
return char;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
var kebabCase = (string) => {
|
|
56
|
+
return string.replaceAll(/[A-Z]+/g, (match, offset) => {
|
|
57
|
+
return `${offset > 0 ? "-" : ""}${match.toLocaleLowerCase()}`;
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
var capitalizeFirstLetter = (inputString) => {
|
|
61
|
+
return inputString.charAt(0).toUpperCase() + inputString.slice(1);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// ../signal/dist/signal.dev.esm.js
|
|
65
|
+
var __defProp = Object.defineProperty;
|
|
66
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
67
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
68
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
69
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
70
|
+
var __spreadValues = (a, b) => {
|
|
71
|
+
for (var prop in b || (b = {}))
|
|
72
|
+
if (__hasOwnProp.call(b, prop))
|
|
73
|
+
__defNormalProp(a, prop, b[prop]);
|
|
74
|
+
if (__getOwnPropSymbols)
|
|
75
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
76
|
+
if (__propIsEnum.call(b, prop))
|
|
77
|
+
__defNormalProp(a, prop, b[prop]);
|
|
78
|
+
}
|
|
79
|
+
return a;
|
|
80
|
+
};
|
|
81
|
+
var isObject2 = (val) => val !== null && typeof val === "object";
|
|
82
|
+
var isArray2 = Array.isArray;
|
|
83
|
+
function isString2(val) {
|
|
84
|
+
return typeof val === "string";
|
|
85
|
+
}
|
|
86
|
+
function isNull(val) {
|
|
87
|
+
return val === null;
|
|
88
|
+
}
|
|
89
|
+
function isSet(val) {
|
|
90
|
+
return _toString.call(val) === "[object Set]";
|
|
91
|
+
}
|
|
92
|
+
function isWeakMap(val) {
|
|
93
|
+
return _toString.call(val) === "[object WeakMap]";
|
|
94
|
+
}
|
|
95
|
+
function isWeakSet(val) {
|
|
96
|
+
return _toString.call(val) === "[object WeakSet]";
|
|
97
|
+
}
|
|
98
|
+
function isMap(val) {
|
|
99
|
+
return _toString.call(val) === "[object Map]";
|
|
100
|
+
}
|
|
101
|
+
var isFunction2 = (val) => typeof val === "function";
|
|
102
|
+
var isPrimitive = (val) => ["string", "number", "boolean", "symbol", "undefined"].includes(typeof val) || isNull(val);
|
|
103
|
+
function isHTMLElement(obj) {
|
|
104
|
+
if (!obj) return false;
|
|
105
|
+
return obj && typeof obj === "object" && obj.nodeType === 1 && typeof obj.nodeName === "string";
|
|
106
|
+
}
|
|
107
|
+
var _toString = Object.prototype.toString;
|
|
108
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
109
|
+
var hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
110
|
+
var hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
|
|
111
|
+
var noop2 = Function.prototype;
|
|
112
|
+
function startsWith2(str, searchString) {
|
|
113
|
+
if (!isString2(str)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return str.indexOf(searchString) === 0;
|
|
117
|
+
}
|
|
118
|
+
function isExclude(key, exclude) {
|
|
119
|
+
return Array.isArray(exclude) ? exclude.includes(key) : isFunction2(exclude) ? exclude(key) : false;
|
|
120
|
+
}
|
|
121
|
+
function warn(msg, ...args) {
|
|
122
|
+
console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
|
|
123
|
+
}
|
|
124
|
+
var queue = [];
|
|
125
|
+
var activePreFlushCbs = [];
|
|
126
|
+
var p = Promise.resolve();
|
|
127
|
+
var isFlushPending = false;
|
|
128
|
+
function nextTick(fn) {
|
|
129
|
+
return fn ? p.then(fn) : p;
|
|
130
|
+
}
|
|
131
|
+
function queueJob(job) {
|
|
132
|
+
if (!queue.includes(job)) {
|
|
133
|
+
queue.push(job);
|
|
134
|
+
queueFlush();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function queueFlush() {
|
|
138
|
+
if (isFlushPending) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
isFlushPending = true;
|
|
142
|
+
nextTick(flushJobs);
|
|
143
|
+
}
|
|
144
|
+
function queuePreFlushCb(cb) {
|
|
145
|
+
queueCb(cb, activePreFlushCbs);
|
|
146
|
+
}
|
|
147
|
+
function queueCb(cb, activeQueue) {
|
|
148
|
+
if (!activeQueue.includes(cb)) {
|
|
149
|
+
activeQueue.push(cb);
|
|
150
|
+
queueFlush();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function flushJobs() {
|
|
154
|
+
isFlushPending = false;
|
|
155
|
+
flushPreFlushCbs();
|
|
156
|
+
let job;
|
|
157
|
+
while (job = queue.shift()) {
|
|
158
|
+
if (job) {
|
|
159
|
+
job();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function flushPreFlushCbs() {
|
|
164
|
+
while (activePreFlushCbs.length > 0) {
|
|
165
|
+
const cb = activePreFlushCbs.shift();
|
|
166
|
+
if (cb) {
|
|
167
|
+
cb();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
var activeEffect = null;
|
|
172
|
+
var activeComputed = null;
|
|
173
|
+
var computedMap = /* @__PURE__ */ new WeakMap();
|
|
174
|
+
var signalMap = /* @__PURE__ */ new WeakMap();
|
|
175
|
+
var effectDeps = /* @__PURE__ */ new Set();
|
|
176
|
+
var reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
177
|
+
var arrayMethods = ["push", "pop", "shift", "unshift", "splice", "sort", "reverse"];
|
|
178
|
+
function track(target, key) {
|
|
179
|
+
if (!activeEffect && !activeComputed) return;
|
|
180
|
+
let depsMap = signalMap.get(target);
|
|
181
|
+
if (!depsMap) {
|
|
182
|
+
depsMap = /* @__PURE__ */ new Map();
|
|
183
|
+
signalMap.set(target, depsMap);
|
|
184
|
+
}
|
|
185
|
+
let dep = depsMap.get(key);
|
|
186
|
+
if (!dep) {
|
|
187
|
+
dep = /* @__PURE__ */ new Set();
|
|
188
|
+
depsMap.set(key, dep);
|
|
189
|
+
}
|
|
190
|
+
if (activeEffect) dep.add(activeEffect);
|
|
191
|
+
let computedDepsMap = computedMap.get(target);
|
|
192
|
+
if (!computedDepsMap) {
|
|
193
|
+
computedDepsMap = /* @__PURE__ */ new Map();
|
|
194
|
+
computedMap.set(target, computedDepsMap);
|
|
195
|
+
}
|
|
196
|
+
let computedDeps = computedDepsMap.get(key);
|
|
197
|
+
if (!computedDeps) {
|
|
198
|
+
computedDeps = /* @__PURE__ */ new Set();
|
|
199
|
+
computedDepsMap.set(key, computedDeps);
|
|
200
|
+
}
|
|
201
|
+
if (activeComputed) {
|
|
202
|
+
computedDeps.add(activeComputed);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function trigger(target, key) {
|
|
206
|
+
const depsMap = signalMap.get(target);
|
|
207
|
+
if (!depsMap) return;
|
|
208
|
+
const dep = depsMap.get(key);
|
|
209
|
+
if (dep) {
|
|
210
|
+
dep.forEach((effect) => effectDeps.has(effect) && effect());
|
|
211
|
+
}
|
|
212
|
+
const computedDepsMap = computedMap.get(target);
|
|
213
|
+
if (computedDepsMap) {
|
|
214
|
+
const computeds = computedDepsMap.get(key);
|
|
215
|
+
if (computeds) {
|
|
216
|
+
computeds.forEach((computed) => computed.run());
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
var Signal = class {
|
|
221
|
+
constructor(value, shallow = false) {
|
|
222
|
+
this._value = value;
|
|
223
|
+
this._shallow = shallow;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get the current value of the Signal and track its usage.
|
|
227
|
+
*/
|
|
228
|
+
get value() {
|
|
229
|
+
track(this, "_sv");
|
|
230
|
+
this.__triggerObject();
|
|
231
|
+
return this._value;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Trigger reactivity for non-primitive and non-HTMLElement values.
|
|
235
|
+
* Recursively applies reactivity to nested objects.
|
|
236
|
+
*/
|
|
237
|
+
__triggerObject() {
|
|
238
|
+
if (!isPrimitive(this._value) && !isHTMLElement(this._value) && !this._shallow) {
|
|
239
|
+
useReactive(this._value);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Set a new value to the Signal and trigger updates if the value has changed.
|
|
244
|
+
*/
|
|
245
|
+
set value(newValue) {
|
|
246
|
+
if (isSignal(newValue)) {
|
|
247
|
+
{
|
|
248
|
+
console.warn(
|
|
249
|
+
"Do not set the signal as a signal, the original value of the signal will be used!"
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
newValue = newValue.peek();
|
|
253
|
+
}
|
|
254
|
+
if (hasChanged(newValue, this._value)) {
|
|
255
|
+
this._value = newValue;
|
|
256
|
+
if (!isPrimitive(this._value) && !isHTMLElement(this._value)) {
|
|
257
|
+
this.__triggerObject();
|
|
258
|
+
}
|
|
259
|
+
trigger(this, "_sv");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Peek at the current value of the Signal without tracking it.
|
|
264
|
+
*/
|
|
265
|
+
peek() {
|
|
266
|
+
return this._value;
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
function useSignal(value) {
|
|
270
|
+
if (isSignal(value)) {
|
|
271
|
+
return value;
|
|
272
|
+
}
|
|
273
|
+
return new Signal(value);
|
|
274
|
+
}
|
|
275
|
+
function shallowSignal(value) {
|
|
276
|
+
return new Signal(value, true);
|
|
277
|
+
}
|
|
278
|
+
function isSignal(value) {
|
|
279
|
+
return value instanceof Signal;
|
|
280
|
+
}
|
|
281
|
+
var Computed = class {
|
|
282
|
+
constructor(fn) {
|
|
283
|
+
this.fn = fn;
|
|
284
|
+
const prev = activeComputed;
|
|
285
|
+
activeComputed = this;
|
|
286
|
+
this._value = this.fn();
|
|
287
|
+
activeComputed = prev;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get the current computed value without tracking it.
|
|
291
|
+
*/
|
|
292
|
+
peek() {
|
|
293
|
+
return this._value;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Run the computed function and update the value if it has changed.
|
|
297
|
+
*/
|
|
298
|
+
run() {
|
|
299
|
+
const newValue = this.fn();
|
|
300
|
+
if (hasChanged(newValue, this._value)) {
|
|
301
|
+
this._value = newValue;
|
|
302
|
+
trigger(this, "_cv");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Get the current computed value and track its usage.
|
|
307
|
+
*/
|
|
308
|
+
get value() {
|
|
309
|
+
track(this, "_cv");
|
|
310
|
+
return this._value;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
function useComputed(fn) {
|
|
314
|
+
return new Computed(fn);
|
|
315
|
+
}
|
|
316
|
+
function isComputed(value) {
|
|
317
|
+
return value instanceof Computed;
|
|
318
|
+
}
|
|
319
|
+
function useEffect(fn, options = {}) {
|
|
320
|
+
const { flush = "pre", onTrack, onTrigger } = options;
|
|
321
|
+
function effectFn() {
|
|
322
|
+
const prev = activeEffect;
|
|
323
|
+
activeEffect = effectFn.init ? effectFn : effectFn.effect;
|
|
324
|
+
fn();
|
|
325
|
+
onTrigger && onTrigger();
|
|
326
|
+
activeEffect = prev;
|
|
327
|
+
}
|
|
328
|
+
const scheduler = flush === "sync" ? () => {
|
|
329
|
+
queueJob(effectFn);
|
|
330
|
+
} : flush === "pre" ? () => {
|
|
331
|
+
queuePreFlushCb(effectFn);
|
|
332
|
+
} : () => {
|
|
333
|
+
nextTick(() => {
|
|
334
|
+
queueJob(effectFn);
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
effectFn.effect = scheduler;
|
|
338
|
+
effectFn.init = true;
|
|
339
|
+
onTrack && onTrack();
|
|
340
|
+
effectFn();
|
|
341
|
+
effectDeps.add(effectFn);
|
|
342
|
+
return () => {
|
|
343
|
+
effectDeps.delete(effectFn);
|
|
344
|
+
activeEffect = null;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function signalObject(initialValues, exclude) {
|
|
348
|
+
if (!initialValues || !isObject2(initialValues)) {
|
|
349
|
+
{
|
|
350
|
+
warn("initialValues must be an object,will return initial value!", initialValues);
|
|
351
|
+
}
|
|
352
|
+
return initialValues;
|
|
353
|
+
}
|
|
354
|
+
const signals = Object.entries(initialValues).reduce((acc, [key, value]) => {
|
|
355
|
+
acc[key] = isExclude(key, exclude) || isSignal(value) ? value : useSignal(value);
|
|
356
|
+
return acc;
|
|
357
|
+
}, {});
|
|
358
|
+
return signals;
|
|
359
|
+
}
|
|
360
|
+
function unSignal(signal, exclude) {
|
|
361
|
+
if (!signal) return {};
|
|
362
|
+
if (isSignal(signal)) {
|
|
363
|
+
return signal.peek();
|
|
364
|
+
}
|
|
365
|
+
if (isArray2(signal)) {
|
|
366
|
+
return signal.map((value) => unSignal(value, exclude));
|
|
367
|
+
}
|
|
368
|
+
if (isObject2(signal)) {
|
|
369
|
+
return Object.entries(signal).reduce((acc, [key, value]) => {
|
|
370
|
+
if (isExclude(key, exclude)) {
|
|
371
|
+
acc[key] = value;
|
|
372
|
+
} else {
|
|
373
|
+
acc[key] = isSignal(value) ? value.peek() : isReactive(value) ? unReactive(value) : value;
|
|
374
|
+
}
|
|
375
|
+
return acc;
|
|
376
|
+
}, {});
|
|
377
|
+
}
|
|
378
|
+
return signal;
|
|
379
|
+
}
|
|
380
|
+
var REACTIVE_MARKER = Symbol("useReactive");
|
|
381
|
+
function isReactive(obj) {
|
|
382
|
+
return obj && obj[REACTIVE_MARKER] === true;
|
|
383
|
+
}
|
|
384
|
+
function createArrayProxy(initialValue) {
|
|
385
|
+
arrayMethods.forEach((method) => {
|
|
386
|
+
const originalMethod = Array.prototype[method];
|
|
387
|
+
track(initialValue, "length");
|
|
388
|
+
Object.defineProperty(initialValue, method, {
|
|
389
|
+
value(...args) {
|
|
390
|
+
const result = originalMethod.apply(this, args);
|
|
391
|
+
if (["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].includes(method)) {
|
|
392
|
+
trigger(initialValue, "length");
|
|
393
|
+
}
|
|
394
|
+
return result;
|
|
395
|
+
},
|
|
396
|
+
enumerable: false,
|
|
397
|
+
writable: true,
|
|
398
|
+
configurable: true
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
function useReactive(initialValue, exclude) {
|
|
403
|
+
return reactive(initialValue, exclude, false);
|
|
404
|
+
}
|
|
405
|
+
function shallowReactive(initialValue, exclude) {
|
|
406
|
+
return reactive(initialValue, exclude, true);
|
|
407
|
+
}
|
|
408
|
+
function unReactive(target) {
|
|
409
|
+
if (!isObject2(target)) {
|
|
410
|
+
return target;
|
|
411
|
+
}
|
|
412
|
+
if (!isReactive(target)) {
|
|
413
|
+
return target;
|
|
414
|
+
}
|
|
415
|
+
const unReactiveObj = Array.isArray(target) ? [] : {};
|
|
416
|
+
for (const key in target) {
|
|
417
|
+
if (hasOwn(target, key)) {
|
|
418
|
+
const value = target[key];
|
|
419
|
+
if (isReactive(value)) {
|
|
420
|
+
unReactiveObj[key] = unReactive(value);
|
|
421
|
+
} else if (isSignal(value)) {
|
|
422
|
+
unReactiveObj[key] = value.peek();
|
|
423
|
+
} else {
|
|
424
|
+
unReactiveObj[key] = value;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return unReactiveObj;
|
|
429
|
+
}
|
|
430
|
+
function reactive(initialValue, exclude, shallow = false) {
|
|
431
|
+
if (!isObject2(initialValue)) {
|
|
432
|
+
return initialValue;
|
|
433
|
+
}
|
|
434
|
+
if (isReactive(initialValue)) {
|
|
435
|
+
return initialValue;
|
|
436
|
+
}
|
|
437
|
+
if (reactiveMap.has(initialValue)) {
|
|
438
|
+
return reactiveMap.get(initialValue);
|
|
439
|
+
}
|
|
440
|
+
if (Array.isArray(initialValue)) {
|
|
441
|
+
createArrayProxy(initialValue);
|
|
442
|
+
}
|
|
443
|
+
if (isSet(initialValue) || isMap(initialValue) || isWeakSet(initialValue) || isWeakMap(initialValue)) {
|
|
444
|
+
return initialValue;
|
|
445
|
+
}
|
|
446
|
+
const handler = {
|
|
447
|
+
get(target, key, receiver) {
|
|
448
|
+
if (key === REACTIVE_MARKER || startsWith2(key, "_")) return true;
|
|
449
|
+
const getValue = Reflect.get(target, key, receiver);
|
|
450
|
+
const value = isSignal(getValue) ? getValue.value : getValue;
|
|
451
|
+
if (isExclude(key, exclude)) {
|
|
452
|
+
return value;
|
|
453
|
+
}
|
|
454
|
+
track(target, key);
|
|
455
|
+
if (isObject2(value) && !shallow) {
|
|
456
|
+
return useReactive(value);
|
|
457
|
+
}
|
|
458
|
+
return value;
|
|
459
|
+
},
|
|
460
|
+
set(target, key, value, receiver) {
|
|
461
|
+
if (isExclude(key, exclude)) {
|
|
462
|
+
Reflect.set(target, key, value, receiver);
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
let oldValue = Reflect.get(target, key, receiver);
|
|
466
|
+
if (isSignal(oldValue)) {
|
|
467
|
+
oldValue = oldValue.value;
|
|
468
|
+
}
|
|
469
|
+
if (isSignal(value)) {
|
|
470
|
+
value = value.value;
|
|
471
|
+
}
|
|
472
|
+
const obj = Reflect.set(target, key, value, receiver);
|
|
473
|
+
if (hasChanged(value, oldValue)) {
|
|
474
|
+
trigger(target, key);
|
|
475
|
+
}
|
|
476
|
+
return obj;
|
|
477
|
+
},
|
|
478
|
+
deleteProperty(target, key) {
|
|
479
|
+
const oldValue = Reflect.get(target, key);
|
|
480
|
+
const result = Reflect.deleteProperty(target, key);
|
|
481
|
+
if (oldValue !== void 0) {
|
|
482
|
+
trigger(target, key);
|
|
483
|
+
}
|
|
484
|
+
return result;
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
const proxy = new Proxy(initialValue, handler);
|
|
488
|
+
reactiveMap.set(initialValue, proxy);
|
|
489
|
+
return proxy;
|
|
490
|
+
}
|
|
491
|
+
function useWatch(source, cb, options) {
|
|
492
|
+
return doWatch(source, cb, options);
|
|
493
|
+
}
|
|
494
|
+
function doWatch(source, cb, options) {
|
|
495
|
+
let getter;
|
|
496
|
+
if (isSignal(source) || isComputed(source)) {
|
|
497
|
+
getter = () => source.value;
|
|
498
|
+
} else if (isReactive(source)) {
|
|
499
|
+
getter = () => __spreadValues({}, source);
|
|
500
|
+
} else if (isArray2(source)) {
|
|
501
|
+
getter = () => source.map((s) => {
|
|
502
|
+
if (isSignal(s) || isComputed(s)) return s.value;
|
|
503
|
+
if (isReactive(s)) return __spreadValues({}, s);
|
|
504
|
+
if (isFunction2(s)) return s();
|
|
505
|
+
return warn("Invalid source", s);
|
|
506
|
+
});
|
|
507
|
+
} else if (isFunction2(source)) {
|
|
508
|
+
getter = source;
|
|
509
|
+
} else {
|
|
510
|
+
warn("Invalid source type", source);
|
|
511
|
+
getter = noop2;
|
|
512
|
+
}
|
|
513
|
+
let oldValue;
|
|
514
|
+
const effectFn = () => {
|
|
515
|
+
const newValue = getter();
|
|
516
|
+
if ((options == null ? void 0 : options.deep) || hasChanged(newValue, oldValue)) {
|
|
517
|
+
cb && cb(newValue, oldValue);
|
|
518
|
+
oldValue = newValue;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
const stop = useEffect(effectFn);
|
|
522
|
+
if (options == null ? void 0 : options.immediate) {
|
|
523
|
+
effectFn();
|
|
524
|
+
}
|
|
525
|
+
return stop;
|
|
526
|
+
}
|
|
527
|
+
var _id = 0;
|
|
528
|
+
var StoreMap = /* @__PURE__ */ new Map();
|
|
529
|
+
function createOptionsStore(options) {
|
|
530
|
+
const { state, getters, actions } = options;
|
|
531
|
+
const initState = __spreadValues({}, state != null ? state : {});
|
|
532
|
+
const reactiveState = useReactive(state != null ? state : {});
|
|
533
|
+
const subscriptions = [];
|
|
534
|
+
const actionCallbacks = [];
|
|
535
|
+
const default_actions = {
|
|
536
|
+
patch$(payload) {
|
|
537
|
+
Object.assign(reactiveState, payload);
|
|
538
|
+
subscriptions.forEach((callback) => callback(reactiveState));
|
|
539
|
+
actionCallbacks.forEach((callback) => callback(reactiveState));
|
|
540
|
+
},
|
|
541
|
+
subscribe$(callback) {
|
|
542
|
+
subscriptions.push(callback);
|
|
543
|
+
},
|
|
544
|
+
unsubscribe$(callback) {
|
|
545
|
+
const index = subscriptions.indexOf(callback);
|
|
546
|
+
if (index !== -1) {
|
|
547
|
+
subscriptions.splice(index, 1);
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
onAction$(callback) {
|
|
551
|
+
actionCallbacks.push(callback);
|
|
552
|
+
},
|
|
553
|
+
reset$() {
|
|
554
|
+
Object.assign(reactiveState, initState);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
const store = __spreadValues({
|
|
558
|
+
state: reactiveState
|
|
559
|
+
}, default_actions);
|
|
560
|
+
for (const key in getters) {
|
|
561
|
+
const getter = getters[key];
|
|
562
|
+
if (getter) {
|
|
563
|
+
useWatch(useComputed(getter.bind(reactiveState, reactiveState)), (value) => {
|
|
564
|
+
store[key] = value;
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
for (const key in actions) {
|
|
569
|
+
const action = actions[key];
|
|
570
|
+
if (action) {
|
|
571
|
+
store[key] = action.bind(reactiveState);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
StoreMap.set(_id, store);
|
|
575
|
+
++_id;
|
|
576
|
+
return store;
|
|
577
|
+
}
|
|
578
|
+
function createStore(options) {
|
|
579
|
+
return function() {
|
|
580
|
+
if (StoreMap.has(_id)) {
|
|
581
|
+
return StoreMap.get(_id);
|
|
582
|
+
}
|
|
583
|
+
return createOptionsStore(options);
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// ../template/dist/template.dev.esm.js
|
|
588
|
+
var __defProp2 = Object.defineProperty;
|
|
589
|
+
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
590
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
591
|
+
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
592
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
593
|
+
var __spreadValues2 = (a, b) => {
|
|
594
|
+
for (var prop in b || (b = {}))
|
|
595
|
+
if (__hasOwnProp2.call(b, prop))
|
|
596
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
597
|
+
if (__getOwnPropSymbols2)
|
|
598
|
+
for (var prop of __getOwnPropSymbols2(b)) {
|
|
599
|
+
if (__propIsEnum2.call(b, prop))
|
|
600
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
601
|
+
}
|
|
602
|
+
return a;
|
|
603
|
+
};
|
|
604
|
+
var _Hooks = class _Hooks2 {
|
|
605
|
+
constructor() {
|
|
606
|
+
this.hooks = {
|
|
607
|
+
mounted: /* @__PURE__ */ new Set(),
|
|
608
|
+
destroy: /* @__PURE__ */ new Set()
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
addEventListener() {
|
|
612
|
+
}
|
|
613
|
+
removeEventListener() {
|
|
614
|
+
}
|
|
615
|
+
addHook(hook, cb) {
|
|
616
|
+
var _a;
|
|
617
|
+
(_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
|
|
618
|
+
}
|
|
619
|
+
getContext(context) {
|
|
620
|
+
return _Hooks2.context[context];
|
|
621
|
+
}
|
|
622
|
+
setContext(context, value) {
|
|
623
|
+
_Hooks2.context[context] = value;
|
|
624
|
+
}
|
|
625
|
+
initRef() {
|
|
626
|
+
_Hooks2.ref = this;
|
|
627
|
+
}
|
|
628
|
+
removeRef() {
|
|
629
|
+
_Hooks2.ref = null;
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
_Hooks.ref = null;
|
|
633
|
+
_Hooks.context = {};
|
|
634
|
+
var Hooks = _Hooks;
|
|
635
|
+
var ComponentNode = class extends Hooks {
|
|
636
|
+
constructor(template2, props, key) {
|
|
637
|
+
super();
|
|
638
|
+
this.template = template2;
|
|
639
|
+
this.props = props;
|
|
640
|
+
this.key = key;
|
|
641
|
+
this.proxyProps = {};
|
|
642
|
+
this.emitter = /* @__PURE__ */ new Set();
|
|
643
|
+
this.mounted = false;
|
|
644
|
+
this.rootNode = null;
|
|
645
|
+
this.context = {};
|
|
646
|
+
this.trackMap = /* @__PURE__ */ new Map();
|
|
647
|
+
this.proxyProps = signalObject(
|
|
648
|
+
props,
|
|
649
|
+
(key2) => startsWith(key2, "on") || startsWith(key2, "update")
|
|
650
|
+
);
|
|
651
|
+
this.key = this.key || props.key;
|
|
652
|
+
}
|
|
653
|
+
get firstChild() {
|
|
654
|
+
var _a, _b;
|
|
655
|
+
return (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
|
|
656
|
+
}
|
|
657
|
+
get isConnected() {
|
|
658
|
+
var _a, _b;
|
|
659
|
+
return (_b = (_a = this.rootNode) == null ? void 0 : _a.isConnected) != null ? _b : false;
|
|
660
|
+
}
|
|
661
|
+
inheritNode(node) {
|
|
662
|
+
this.context = node.context;
|
|
663
|
+
this.hooks = node.hooks;
|
|
664
|
+
Object.assign(this.proxyProps, node.proxyProps);
|
|
665
|
+
this.rootNode = node.rootNode;
|
|
666
|
+
this.trackMap = node.trackMap;
|
|
667
|
+
const props = this.props;
|
|
668
|
+
this.props = node.props;
|
|
669
|
+
this.patchProps(props);
|
|
670
|
+
}
|
|
671
|
+
mount(parent, before) {
|
|
672
|
+
var _a, _b, _c, _d;
|
|
673
|
+
if (!isFunction(this.template)) {
|
|
674
|
+
throw new Error("Template must be a function");
|
|
675
|
+
}
|
|
676
|
+
if (this.isConnected) {
|
|
677
|
+
return (_b = (_a = this.rootNode) == null ? void 0 : _a.mount(parent, before)) != null ? _b : [];
|
|
678
|
+
}
|
|
679
|
+
this.initRef();
|
|
680
|
+
this.rootNode = this.template(useReactive(this.proxyProps, ["children"]));
|
|
681
|
+
this.removeRef();
|
|
682
|
+
this.mounted = true;
|
|
683
|
+
const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
|
|
684
|
+
this.hooks.mounted.forEach((handler) => handler());
|
|
685
|
+
this.patchProps(this.props);
|
|
686
|
+
return mountedNode;
|
|
687
|
+
}
|
|
688
|
+
unmount() {
|
|
689
|
+
var _a;
|
|
690
|
+
this.hooks.destroy.forEach((handler) => handler());
|
|
691
|
+
Object.values(this.hooks).forEach((set) => set.clear());
|
|
692
|
+
(_a = this.rootNode) == null ? void 0 : _a.unmount();
|
|
693
|
+
this.rootNode = null;
|
|
694
|
+
this.proxyProps = {};
|
|
695
|
+
this.mounted = false;
|
|
696
|
+
this.emitter.forEach((emitter) => emitter());
|
|
697
|
+
}
|
|
698
|
+
getNodeTrack(trackKey, suppressCleanupCall) {
|
|
699
|
+
let track2 = this.trackMap.get(trackKey);
|
|
700
|
+
if (!track2) {
|
|
701
|
+
track2 = { cleanup: () => {
|
|
702
|
+
} };
|
|
703
|
+
this.trackMap.set(trackKey, track2);
|
|
704
|
+
}
|
|
705
|
+
if (!suppressCleanupCall) {
|
|
706
|
+
track2.cleanup();
|
|
707
|
+
}
|
|
708
|
+
return track2;
|
|
709
|
+
}
|
|
710
|
+
patchProps(props) {
|
|
711
|
+
var _a, _b, _c, _d;
|
|
712
|
+
for (const [key, prop] of Object.entries(props)) {
|
|
713
|
+
if (startsWith(key, "on") && ((_a = this.rootNode) == null ? void 0 : _a.nodes)) {
|
|
714
|
+
const event = key.slice(2).toLowerCase();
|
|
715
|
+
const listener = prop;
|
|
716
|
+
const cleanup = addEventListener(this.rootNode.nodes[0], event, listener);
|
|
717
|
+
this.emitter.add(cleanup);
|
|
718
|
+
} else if (key === "ref") {
|
|
719
|
+
props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
|
|
720
|
+
} else if (startsWith(key, "update")) {
|
|
721
|
+
props[key] = isSignal(prop) ? prop.value : prop;
|
|
722
|
+
} else if (key !== "children") {
|
|
723
|
+
const newValue = (_d = (_c = this.proxyProps)[key]) != null ? _d : _c[key] = useSignal(prop);
|
|
724
|
+
const track2 = this.getNodeTrack(key);
|
|
725
|
+
track2.cleanup = useEffect(() => {
|
|
726
|
+
newValue.value = isFunction(prop) ? prop() : prop;
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
this.props = props;
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
function h(_template, props, key) {
|
|
734
|
+
if (isString(_template)) {
|
|
735
|
+
if (isHtmlTagName(_template)) {
|
|
736
|
+
_template = convertToHtmlTag(_template);
|
|
737
|
+
props = {
|
|
738
|
+
1: props
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
if (_template === "") {
|
|
742
|
+
props = {
|
|
743
|
+
0: props
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
_template = template(_template);
|
|
747
|
+
}
|
|
748
|
+
return isFunction(_template) ? new ComponentNode(_template, props, key) : new TemplateNode(_template, props, key);
|
|
749
|
+
}
|
|
750
|
+
function isComponent(node) {
|
|
751
|
+
return node instanceof ComponentNode;
|
|
752
|
+
}
|
|
753
|
+
function isJsxElement(node) {
|
|
754
|
+
return node instanceof ComponentNode || node instanceof TemplateNode;
|
|
755
|
+
}
|
|
756
|
+
function template(html) {
|
|
757
|
+
const template2 = document.createElement("template");
|
|
758
|
+
template2.innerHTML = closeHtmlTags(html);
|
|
759
|
+
return template2;
|
|
760
|
+
}
|
|
761
|
+
function Fragment(props) {
|
|
762
|
+
return props.children;
|
|
763
|
+
}
|
|
764
|
+
var selfClosingTags = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
|
|
765
|
+
var htmlTags = "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";
|
|
766
|
+
function coerceNode(data) {
|
|
767
|
+
if (isJsxElement(data) || data instanceof Node) {
|
|
768
|
+
return data;
|
|
769
|
+
}
|
|
770
|
+
const text = isFalsy(data) ? "" : String(data);
|
|
771
|
+
return document.createTextNode(text);
|
|
772
|
+
}
|
|
773
|
+
function insertChild(parent, child, before = null) {
|
|
774
|
+
const beforeNode = isJsxElement(before) ? before.firstChild : before;
|
|
775
|
+
if (isJsxElement(child)) {
|
|
776
|
+
child.mount(parent, beforeNode);
|
|
777
|
+
} else if (beforeNode) {
|
|
778
|
+
beforeNode.before(child);
|
|
779
|
+
} else {
|
|
780
|
+
parent.append(child);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function removeChild(child) {
|
|
784
|
+
if (isJsxElement(child)) {
|
|
785
|
+
child.unmount();
|
|
786
|
+
} else {
|
|
787
|
+
const parent = child.parentNode;
|
|
788
|
+
if (parent) {
|
|
789
|
+
child.remove();
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
function replaceChild(parent, node, child) {
|
|
794
|
+
insertChild(parent, node, child);
|
|
795
|
+
removeChild(child);
|
|
796
|
+
}
|
|
797
|
+
function setAttribute(element, attr, value) {
|
|
798
|
+
if (attr === "class") {
|
|
799
|
+
if (typeof value === "string") {
|
|
800
|
+
element.className = value;
|
|
801
|
+
} else if (Array.isArray(value)) {
|
|
802
|
+
element.className = value.join(" ");
|
|
803
|
+
} else if (value && typeof value === "object") {
|
|
804
|
+
element.className = Object.entries(value).reduce((acc, [key, value2]) => acc + (value2 ? ` ${key}` : ""), "").trim();
|
|
805
|
+
}
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (attr === "style") {
|
|
809
|
+
if (typeof value === "string") {
|
|
810
|
+
element.style.cssText = value;
|
|
811
|
+
} else if (value && typeof value === "object") {
|
|
812
|
+
const obj = value;
|
|
813
|
+
Object.keys(obj).forEach((key) => {
|
|
814
|
+
element.style.setProperty(kebabCase(key), String(obj[key]));
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
if (isFalsy(value)) {
|
|
820
|
+
element.removeAttribute(attr);
|
|
821
|
+
} else if (value === true) {
|
|
822
|
+
element.setAttribute(attr, "");
|
|
823
|
+
} else {
|
|
824
|
+
if (element instanceof HTMLInputElement) {
|
|
825
|
+
element.value = String(value);
|
|
826
|
+
} else {
|
|
827
|
+
element.setAttribute(attr, String(value));
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function binNode(node, setter) {
|
|
832
|
+
if (node instanceof HTMLInputElement) {
|
|
833
|
+
switch (node.type) {
|
|
834
|
+
case "checkbox":
|
|
835
|
+
return addEventListener(node, "change", () => {
|
|
836
|
+
setter(Boolean(node.checked));
|
|
837
|
+
});
|
|
838
|
+
case "date":
|
|
839
|
+
return addEventListener(node, "change", () => {
|
|
840
|
+
setter(node.value ? node.value : "");
|
|
841
|
+
});
|
|
842
|
+
case "file":
|
|
843
|
+
return addEventListener(node, "change", () => {
|
|
844
|
+
if (node.files) {
|
|
845
|
+
setter(node.files);
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
case "number":
|
|
849
|
+
return addEventListener(node, "input", () => {
|
|
850
|
+
const value = Number.parseFloat(node.value);
|
|
851
|
+
setter(Number.isNaN(value) ? "" : String(value));
|
|
852
|
+
});
|
|
853
|
+
case "radio":
|
|
854
|
+
return addEventListener(node, "change", () => {
|
|
855
|
+
setter(node.checked ? node.value : "");
|
|
856
|
+
});
|
|
857
|
+
case "text":
|
|
858
|
+
return addEventListener(node, "input", () => {
|
|
859
|
+
setter(node.value);
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
if (node instanceof HTMLSelectElement) {
|
|
864
|
+
return addEventListener(node, "change", () => {
|
|
865
|
+
setter(node.value);
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
if (node instanceof HTMLTextAreaElement) {
|
|
869
|
+
return addEventListener(node, "input", () => {
|
|
870
|
+
setter(node.value);
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
var p2 = Promise.resolve();
|
|
875
|
+
function nextTick2(fn) {
|
|
876
|
+
return fn ? p2.then(fn) : p2;
|
|
877
|
+
}
|
|
878
|
+
function addEventListener(node, eventName, handler) {
|
|
879
|
+
node.addEventListener(eventName, handler);
|
|
880
|
+
return () => node.removeEventListener(eventName, handler);
|
|
881
|
+
}
|
|
882
|
+
function closeHtmlTags(input) {
|
|
883
|
+
const selfClosingTagList = selfClosingTags.split(",");
|
|
884
|
+
const tagStack = [];
|
|
885
|
+
const output = [];
|
|
886
|
+
const tagPattern = /<\/?([\da-z-]+)([^>]*)>/gi;
|
|
887
|
+
let lastIndex = 0;
|
|
888
|
+
while (true) {
|
|
889
|
+
const match = tagPattern.exec(input);
|
|
890
|
+
if (!match) break;
|
|
891
|
+
const [fullMatch, tagName] = match;
|
|
892
|
+
const isEndTag = fullMatch[1] === "/";
|
|
893
|
+
output.push(input.slice(lastIndex, match.index));
|
|
894
|
+
lastIndex = match.index + fullMatch.length;
|
|
895
|
+
if (isEndTag) {
|
|
896
|
+
while (tagStack.length > 0 && tagStack[tagStack.length - 1] !== tagName) {
|
|
897
|
+
const unclosedTag = tagStack.pop();
|
|
898
|
+
if (unclosedTag) {
|
|
899
|
+
output.push(`</${unclosedTag}>`);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
if (tagStack.length > 0) {
|
|
903
|
+
tagStack.pop();
|
|
904
|
+
}
|
|
905
|
+
} else if (!selfClosingTagList.includes(tagName)) {
|
|
906
|
+
tagStack.push(tagName);
|
|
907
|
+
}
|
|
908
|
+
output.push(fullMatch);
|
|
909
|
+
}
|
|
910
|
+
output.push(input.slice(lastIndex));
|
|
911
|
+
while (tagStack.length > 0) {
|
|
912
|
+
const unclosedTag = tagStack.pop();
|
|
913
|
+
if (unclosedTag) {
|
|
914
|
+
output.push(`</${unclosedTag}>`);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
return output.join("");
|
|
918
|
+
}
|
|
919
|
+
function isHtmlTagName(tagName) {
|
|
920
|
+
const htmlTagsList = htmlTags.split(",");
|
|
921
|
+
return htmlTagsList.includes(tagName);
|
|
922
|
+
}
|
|
923
|
+
function convertToHtmlTag(tagName) {
|
|
924
|
+
const selfClosingTagList = selfClosingTags.split(",");
|
|
925
|
+
if (selfClosingTagList.includes(tagName)) {
|
|
926
|
+
return `<${tagName}/>`;
|
|
927
|
+
} else {
|
|
928
|
+
return `<${tagName}></${tagName}>`;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
function patchChildren(parent, childrenMap, nextChildren, before) {
|
|
932
|
+
const result = /* @__PURE__ */ new Map();
|
|
933
|
+
const children = Array.from(childrenMap.values());
|
|
934
|
+
const childrenLength = children.length;
|
|
935
|
+
if (childrenMap.size > 0 && nextChildren.length === 0) {
|
|
936
|
+
if (parent.childNodes.length === childrenLength + (before ? 1 : 0)) {
|
|
937
|
+
parent.innerHTML = "";
|
|
938
|
+
if (before) {
|
|
939
|
+
insertChild(parent, before);
|
|
940
|
+
}
|
|
941
|
+
} else {
|
|
942
|
+
const range = document.createRange();
|
|
943
|
+
const child = children[0];
|
|
944
|
+
const start = isJsxElement(child) ? child.firstChild : child;
|
|
945
|
+
range.setStartBefore(start);
|
|
946
|
+
if (before) {
|
|
947
|
+
range.setEndBefore(before);
|
|
948
|
+
} else {
|
|
949
|
+
range.setEndAfter(parent);
|
|
950
|
+
}
|
|
951
|
+
range.deleteContents();
|
|
952
|
+
}
|
|
953
|
+
children.forEach((node) => {
|
|
954
|
+
if (isJsxElement(node)) {
|
|
955
|
+
node.unmount();
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
return result;
|
|
959
|
+
}
|
|
960
|
+
const replaces = [];
|
|
961
|
+
const nextChildrenMap = mapKeys(nextChildren);
|
|
962
|
+
let childIndex = 0;
|
|
963
|
+
for (let [i, child] of nextChildren.entries()) {
|
|
964
|
+
let currChild = children[childIndex];
|
|
965
|
+
let currKey = getKey(currChild, i);
|
|
966
|
+
while (currChild && !nextChildrenMap.has(currKey)) {
|
|
967
|
+
removeChild(currChild);
|
|
968
|
+
childrenMap.delete(currKey);
|
|
969
|
+
currChild = children[++childIndex];
|
|
970
|
+
currKey = getKey(currChild, i);
|
|
971
|
+
}
|
|
972
|
+
const key = getKey(child, i);
|
|
973
|
+
const origChild = childrenMap.get(key);
|
|
974
|
+
if (origChild) {
|
|
975
|
+
child = patch(parent, origChild, child);
|
|
976
|
+
}
|
|
977
|
+
if (currChild) {
|
|
978
|
+
if (currChild === origChild) {
|
|
979
|
+
childIndex++;
|
|
980
|
+
} else {
|
|
981
|
+
const placeholder = document.createComment("");
|
|
982
|
+
insertChild(parent, placeholder, currChild);
|
|
983
|
+
replaces.push([placeholder, child]);
|
|
984
|
+
}
|
|
985
|
+
} else {
|
|
986
|
+
insertChild(parent, child, before);
|
|
987
|
+
}
|
|
988
|
+
result.set(key, child);
|
|
989
|
+
}
|
|
990
|
+
replaces.forEach(([placeholder, child]) => replaceChild(parent, child, placeholder));
|
|
991
|
+
childrenMap.forEach((child, key) => {
|
|
992
|
+
if (child.isConnected && !result.has(key)) {
|
|
993
|
+
removeChild(child);
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
return result;
|
|
997
|
+
}
|
|
998
|
+
function patch(parent, node, next) {
|
|
999
|
+
if (node === next) {
|
|
1000
|
+
return node;
|
|
1001
|
+
}
|
|
1002
|
+
if (isJsxElement(node) && isJsxElement(next) && node.template === next.template) {
|
|
1003
|
+
next.inheritNode(node);
|
|
1004
|
+
return next;
|
|
1005
|
+
}
|
|
1006
|
+
if (node instanceof Text && next instanceof Text) {
|
|
1007
|
+
if (node.textContent !== next.textContent) {
|
|
1008
|
+
node.textContent = next.textContent;
|
|
1009
|
+
}
|
|
1010
|
+
return node;
|
|
1011
|
+
}
|
|
1012
|
+
replaceChild(parent, next, node);
|
|
1013
|
+
return next;
|
|
1014
|
+
}
|
|
1015
|
+
function mapKeys(children) {
|
|
1016
|
+
const result = /* @__PURE__ */ new Map();
|
|
1017
|
+
for (const [i, child] of children.entries()) {
|
|
1018
|
+
const key = getKey(child, i);
|
|
1019
|
+
result.set(key, child);
|
|
1020
|
+
}
|
|
1021
|
+
return result;
|
|
1022
|
+
}
|
|
1023
|
+
function getKey(node, index) {
|
|
1024
|
+
if (isJsxElement(node)) {
|
|
1025
|
+
const jsxKey = node.key;
|
|
1026
|
+
if (jsxKey !== void 0 && jsxKey !== null) {
|
|
1027
|
+
return String(jsxKey);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
return `_$${index}$`;
|
|
1031
|
+
}
|
|
1032
|
+
var TemplateNode = class _TemplateNode {
|
|
1033
|
+
constructor(template2, props, key) {
|
|
1034
|
+
this.template = template2;
|
|
1035
|
+
this.props = props;
|
|
1036
|
+
this.key = key;
|
|
1037
|
+
this.treeMap = /* @__PURE__ */ new Map();
|
|
1038
|
+
this.mounted = false;
|
|
1039
|
+
this.nodes = [];
|
|
1040
|
+
this.provides = {};
|
|
1041
|
+
this.trackMap = /* @__PURE__ */ new Map();
|
|
1042
|
+
this.parent = null;
|
|
1043
|
+
this.key = this.key || props.key;
|
|
1044
|
+
}
|
|
1045
|
+
get firstChild() {
|
|
1046
|
+
var _a;
|
|
1047
|
+
return (_a = this.nodes[0]) != null ? _a : null;
|
|
1048
|
+
}
|
|
1049
|
+
get isConnected() {
|
|
1050
|
+
return this.mounted;
|
|
1051
|
+
}
|
|
1052
|
+
addEventListener() {
|
|
1053
|
+
}
|
|
1054
|
+
removeEventListener() {
|
|
1055
|
+
}
|
|
1056
|
+
mount(parent, before) {
|
|
1057
|
+
var _a;
|
|
1058
|
+
this.parent = parent;
|
|
1059
|
+
if (this.isConnected) {
|
|
1060
|
+
this.nodes.forEach((node) => insertChild(parent, node, before));
|
|
1061
|
+
return this.nodes;
|
|
1062
|
+
}
|
|
1063
|
+
const cloneNode = this.template.content.cloneNode(true);
|
|
1064
|
+
const firstChild = cloneNode.firstChild;
|
|
1065
|
+
if ((_a = firstChild == null ? void 0 : firstChild.hasAttribute) == null ? void 0 : _a.call(firstChild, "_svg_")) {
|
|
1066
|
+
firstChild.remove();
|
|
1067
|
+
firstChild == null ? void 0 : firstChild.childNodes.forEach((node) => {
|
|
1068
|
+
cloneNode.append(node);
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
this.nodes = Array.from(cloneNode.childNodes);
|
|
1072
|
+
this.mapNodeTree(parent, cloneNode);
|
|
1073
|
+
insertChild(parent, cloneNode, before);
|
|
1074
|
+
this.patchNodes(this.props);
|
|
1075
|
+
this.mounted = true;
|
|
1076
|
+
return this.nodes;
|
|
1077
|
+
}
|
|
1078
|
+
unmount() {
|
|
1079
|
+
this.trackMap.forEach((track2) => {
|
|
1080
|
+
var _a, _b;
|
|
1081
|
+
(_a = track2.cleanup) == null ? void 0 : _a.call(track2);
|
|
1082
|
+
(_b = track2.lastNodes) == null ? void 0 : _b.forEach((node) => {
|
|
1083
|
+
if (track2.isRoot) {
|
|
1084
|
+
removeChild(node);
|
|
1085
|
+
} else if (node instanceof _TemplateNode) {
|
|
1086
|
+
node.unmount();
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
});
|
|
1090
|
+
this.trackMap.clear();
|
|
1091
|
+
this.treeMap.clear();
|
|
1092
|
+
this.nodes.forEach((node) => removeChild(node));
|
|
1093
|
+
this.nodes = [];
|
|
1094
|
+
this.mounted = false;
|
|
1095
|
+
}
|
|
1096
|
+
mapNodeTree(parent, tree) {
|
|
1097
|
+
let index = 1;
|
|
1098
|
+
this.treeMap.set(0, parent);
|
|
1099
|
+
const walk = (node) => {
|
|
1100
|
+
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
|
1101
|
+
this.treeMap.set(index++, node);
|
|
1102
|
+
}
|
|
1103
|
+
let child = node.firstChild;
|
|
1104
|
+
while (child) {
|
|
1105
|
+
walk(child);
|
|
1106
|
+
child = child.nextSibling;
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
walk(tree);
|
|
1110
|
+
}
|
|
1111
|
+
patchNodes(props) {
|
|
1112
|
+
for (const key in props) {
|
|
1113
|
+
const index = Number(key);
|
|
1114
|
+
const node = this.treeMap.get(index);
|
|
1115
|
+
if (node) {
|
|
1116
|
+
const value = this.props[key];
|
|
1117
|
+
this.patchNode(key, node, value, index === 0);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
this.props = props;
|
|
1121
|
+
}
|
|
1122
|
+
getNodeTrack(trackKey, trackLastNodes, isRoot) {
|
|
1123
|
+
var _a;
|
|
1124
|
+
let track2 = this.trackMap.get(trackKey);
|
|
1125
|
+
if (!track2) {
|
|
1126
|
+
track2 = { cleanup: () => {
|
|
1127
|
+
} };
|
|
1128
|
+
if (trackLastNodes) {
|
|
1129
|
+
track2.lastNodes = /* @__PURE__ */ new Map();
|
|
1130
|
+
}
|
|
1131
|
+
if (isRoot) {
|
|
1132
|
+
track2.isRoot = true;
|
|
1133
|
+
}
|
|
1134
|
+
this.trackMap.set(trackKey, track2);
|
|
1135
|
+
}
|
|
1136
|
+
(_a = track2.cleanup) == null ? void 0 : _a.call(track2);
|
|
1137
|
+
return track2;
|
|
1138
|
+
}
|
|
1139
|
+
inheritNode(node) {
|
|
1140
|
+
this.mounted = node.mounted;
|
|
1141
|
+
this.nodes = node.nodes;
|
|
1142
|
+
this.trackMap = node.trackMap;
|
|
1143
|
+
this.treeMap = node.treeMap;
|
|
1144
|
+
const props = this.props;
|
|
1145
|
+
this.props = node.props;
|
|
1146
|
+
this.patchNodes(props);
|
|
1147
|
+
}
|
|
1148
|
+
patchNode(key, node, props, isRoot) {
|
|
1149
|
+
for (const attr in props) {
|
|
1150
|
+
if (attr === "children" && props.children) {
|
|
1151
|
+
if (!isArray(props.children)) {
|
|
1152
|
+
const trackKey = `${key}:${attr}:${0}`;
|
|
1153
|
+
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
1154
|
+
patchChild(track2, node, props.children, null);
|
|
1155
|
+
} else {
|
|
1156
|
+
props.children.filter(Boolean).forEach((item, index) => {
|
|
1157
|
+
var _a;
|
|
1158
|
+
const [child, path] = isArray(item) ? item : [item, null];
|
|
1159
|
+
const before = isNil(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
|
|
1160
|
+
const trackKey = `${key}:${attr}:${index}`;
|
|
1161
|
+
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
1162
|
+
patchChild(track2, node, child, before);
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
} else if (attr === "ref") {
|
|
1166
|
+
props[attr].value = node;
|
|
1167
|
+
} else if (startsWith(attr, "on")) {
|
|
1168
|
+
const eventName = attr.slice(2).toLocaleLowerCase();
|
|
1169
|
+
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
1170
|
+
const listener = props[attr];
|
|
1171
|
+
track2.cleanup = addEventListener(node, eventName, listener);
|
|
1172
|
+
} else if (!startsWith(attr, "update")) {
|
|
1173
|
+
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
1174
|
+
const val = props[attr];
|
|
1175
|
+
const triggerValue = isSignal(val) ? val : useSignal(val);
|
|
1176
|
+
patchAttribute(track2, node, attr, triggerValue.value);
|
|
1177
|
+
const cleanup = useEffect(() => {
|
|
1178
|
+
triggerValue.value = isSignal(val) ? val.value : val;
|
|
1179
|
+
patchAttribute(track2, node, attr, triggerValue.value);
|
|
1180
|
+
});
|
|
1181
|
+
let cleanupBind;
|
|
1182
|
+
const updateKey = `update${capitalizeFirstLetter(attr)}`;
|
|
1183
|
+
if (props[updateKey]) {
|
|
1184
|
+
cleanupBind = binNode(node, (value) => {
|
|
1185
|
+
props[updateKey](value);
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
track2.cleanup = () => {
|
|
1189
|
+
cleanup && cleanup();
|
|
1190
|
+
cleanupBind && cleanupBind();
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
function patchAttribute(track2, node, attr, data) {
|
|
1197
|
+
const element = node;
|
|
1198
|
+
if (!element.setAttribute) {
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
if (isFunction(data)) {
|
|
1202
|
+
track2.cleanup = useEffect(() => {
|
|
1203
|
+
setAttribute(element, attr, data());
|
|
1204
|
+
});
|
|
1205
|
+
} else {
|
|
1206
|
+
setAttribute(element, attr, data);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
function patchChild(track2, parent, child, before) {
|
|
1210
|
+
if (isFunction(child)) {
|
|
1211
|
+
track2.cleanup = useEffect(() => {
|
|
1212
|
+
const nextNodes = coerceArray(child()).map(coerceNode);
|
|
1213
|
+
track2.lastNodes = patchChildren(parent, track2.lastNodes, nextNodes, before);
|
|
1214
|
+
});
|
|
1215
|
+
} else {
|
|
1216
|
+
coerceArray(child).forEach((node, i) => {
|
|
1217
|
+
const newNode = coerceNode(node);
|
|
1218
|
+
track2.lastNodes.set(String(i), newNode);
|
|
1219
|
+
insertChild(parent, newNode, before);
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
function onMount(cb) {
|
|
1224
|
+
var _a;
|
|
1225
|
+
throwIfOutsideComponent("onMounted");
|
|
1226
|
+
(_a = Hooks.ref) == null ? void 0 : _a.addHook("mounted", cb);
|
|
1227
|
+
}
|
|
1228
|
+
function onDestroy(cb) {
|
|
1229
|
+
var _a;
|
|
1230
|
+
throwIfOutsideComponent("onDestroy");
|
|
1231
|
+
(_a = Hooks.ref) == null ? void 0 : _a.addHook("destroy", cb);
|
|
1232
|
+
}
|
|
1233
|
+
function throwIfOutsideComponent(hook, key) {
|
|
1234
|
+
if (!Hooks.ref) {
|
|
1235
|
+
console.error(
|
|
1236
|
+
`"${hook}"(key: ${isSymbol(key) ? key.toString() : key}) can only be called within the component function body
|
|
1237
|
+
and cannot be used in asynchronous or deferred calls.`
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
function useProvide(key, value) {
|
|
1242
|
+
var _a;
|
|
1243
|
+
throwIfOutsideComponent("useProvide", key);
|
|
1244
|
+
(_a = Hooks.ref) == null ? void 0 : _a.setContext(key, value);
|
|
1245
|
+
}
|
|
1246
|
+
function useInject(key, defaultValue) {
|
|
1247
|
+
var _a;
|
|
1248
|
+
throwIfOutsideComponent("useInject", key);
|
|
1249
|
+
return ((_a = Hooks.ref) == null ? void 0 : _a.getContext(key)) || defaultValue;
|
|
1250
|
+
}
|
|
1251
|
+
function useRef() {
|
|
1252
|
+
const ref = shallowSignal(null);
|
|
1253
|
+
return ref;
|
|
1254
|
+
}
|
|
1255
|
+
function generateAttributes(props) {
|
|
1256
|
+
return Object.entries(props).map(([key, value]) => {
|
|
1257
|
+
if (key === "children" || isFunction(value)) return "";
|
|
1258
|
+
return `${key}="${escape(String(value))}"`;
|
|
1259
|
+
}).filter(Boolean).join(" ");
|
|
1260
|
+
}
|
|
1261
|
+
function normalizeProps(props) {
|
|
1262
|
+
Object.keys(props).forEach((propKey) => {
|
|
1263
|
+
if (isFunction(props[propKey])) {
|
|
1264
|
+
delete props[propKey];
|
|
1265
|
+
}
|
|
1266
|
+
if (isSignal(props[propKey])) {
|
|
1267
|
+
props[propKey] = props[propKey].value;
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
function handleChildResult(result, prop, key, tmpl, childNodesMap, path) {
|
|
1272
|
+
if (isSignal(result)) {
|
|
1273
|
+
tmpl.template += result.value;
|
|
1274
|
+
} else if (result instanceof ServerNode) {
|
|
1275
|
+
const mapKey = path ? String(path) : `${key}`;
|
|
1276
|
+
if (!childNodesMap[mapKey]) childNodesMap[mapKey] = [];
|
|
1277
|
+
const childResult = result.mount();
|
|
1278
|
+
childNodesMap[mapKey].push(
|
|
1279
|
+
isFunction(childResult) ? childResult(prop) : isSignal(childResult) ? childResult.value : childResult
|
|
1280
|
+
);
|
|
1281
|
+
} else {
|
|
1282
|
+
tmpl.template += isFunction(result) ? result(prop) : String(result);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
var ServerNode = class _ServerNode extends Hooks {
|
|
1286
|
+
constructor(template2, props = {}, key) {
|
|
1287
|
+
super();
|
|
1288
|
+
this.template = template2;
|
|
1289
|
+
this.props = props;
|
|
1290
|
+
this.key = key;
|
|
1291
|
+
this.childNodesMap = {};
|
|
1292
|
+
this.processedTemplates = {};
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Mount and render the component
|
|
1296
|
+
*/
|
|
1297
|
+
mount() {
|
|
1298
|
+
this.initRef();
|
|
1299
|
+
const output = this.render();
|
|
1300
|
+
this.removeRef();
|
|
1301
|
+
return output;
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Initialize template entries and props
|
|
1305
|
+
*/
|
|
1306
|
+
initTemplates() {
|
|
1307
|
+
const templateCollection = Array.isArray(this.template) ? this.template.reduce((acc, tmpl, index) => {
|
|
1308
|
+
acc[index + 1] = { template: tmpl };
|
|
1309
|
+
return acc;
|
|
1310
|
+
}, {}) : this.template;
|
|
1311
|
+
if (isObject(templateCollection)) {
|
|
1312
|
+
Object.entries(templateCollection).forEach(([key, tmpl]) => {
|
|
1313
|
+
const prop = __spreadValues2({}, this.props[key]);
|
|
1314
|
+
normalizeProps(prop);
|
|
1315
|
+
if (prop.children) {
|
|
1316
|
+
prop.children.forEach((item) => {
|
|
1317
|
+
const [child, path] = isArray(item) ? item : [item, null];
|
|
1318
|
+
if (isFunction(child)) {
|
|
1319
|
+
const result = child(prop);
|
|
1320
|
+
handleChildResult(result, prop, key, tmpl, this.childNodesMap, path);
|
|
1321
|
+
} else {
|
|
1322
|
+
tmpl.template += isSignal(child) ? child.value : String(child);
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
this.processedTemplates[key] = {
|
|
1327
|
+
template: tmpl.template,
|
|
1328
|
+
props: prop
|
|
1329
|
+
};
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Render component and its children into a string
|
|
1335
|
+
*/
|
|
1336
|
+
render() {
|
|
1337
|
+
if (isFunction(this.template)) {
|
|
1338
|
+
const root = this.template(this.props);
|
|
1339
|
+
return root instanceof _ServerNode ? root.mount() : String(root);
|
|
1340
|
+
}
|
|
1341
|
+
if (this.template instanceof _ServerNode) {
|
|
1342
|
+
return this.template.mount();
|
|
1343
|
+
}
|
|
1344
|
+
this.initTemplates();
|
|
1345
|
+
return Object.entries(this.processedTemplates).map(([key, { template: template2, props }]) => {
|
|
1346
|
+
let content = template2;
|
|
1347
|
+
if (props && Object.keys(props).length > 0) {
|
|
1348
|
+
content += ` ${generateAttributes(props)}`;
|
|
1349
|
+
}
|
|
1350
|
+
if (this.childNodesMap[key]) {
|
|
1351
|
+
content = content.replace("<!>", this.renderChildren(this.childNodesMap[key]));
|
|
1352
|
+
}
|
|
1353
|
+
return content;
|
|
1354
|
+
}).join("");
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Render child nodes into a string
|
|
1358
|
+
*/
|
|
1359
|
+
renderChildren(children) {
|
|
1360
|
+
return coerceArray(children).map(String).join("");
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
function ssg(component, props) {
|
|
1364
|
+
return new ServerNode(component, props);
|
|
1365
|
+
}
|
|
1366
|
+
function renderToString(component, props) {
|
|
1367
|
+
return ssg(component, props).mount();
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// src/index.ts
|
|
1371
|
+
if (globalThis) {
|
|
1372
|
+
globalThis.__essor_version__ = essor_version;
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* @estjs/shared v0.0.12-beta.1
|
|
11
1376
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
12
1377
|
* @license MIT
|
|
13
1378
|
**/
|
|
14
1379
|
/**
|
|
15
|
-
* @estjs/signal v0.0.
|
|
1380
|
+
* @estjs/signal v0.0.12-beta.1
|
|
16
1381
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
17
1382
|
* @license MIT
|
|
18
1383
|
**/
|
|
19
1384
|
/**
|
|
20
|
-
* @estjs/template v0.0.
|
|
1385
|
+
* @estjs/template v0.0.12-beta.1
|
|
21
1386
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
22
1387
|
* @license MIT
|
|
23
1388
|
**/
|
|
24
1389
|
|
|
25
|
-
exports.ComponentNode =
|
|
26
|
-
exports.Fragment =
|
|
27
|
-
exports.TemplateNode =
|
|
28
|
-
exports.createStore =
|
|
29
|
-
exports.essor_version =
|
|
30
|
-
exports.h =
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
33
|
-
exports.
|
|
34
|
-
exports.
|
|
35
|
-
exports.
|
|
36
|
-
exports.
|
|
37
|
-
exports.
|
|
38
|
-
exports.
|
|
39
|
-
exports.
|
|
40
|
-
exports.
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
43
|
-
exports.
|
|
44
|
-
exports.template =
|
|
45
|
-
exports.unReactive =
|
|
46
|
-
exports.unSignal =
|
|
47
|
-
exports.useComputed =
|
|
48
|
-
exports.useEffect =
|
|
49
|
-
exports.useInject =
|
|
50
|
-
exports.useProvide =
|
|
51
|
-
exports.useReactive =
|
|
52
|
-
exports.
|
|
53
|
-
exports.
|
|
1390
|
+
exports.ComponentNode = ComponentNode;
|
|
1391
|
+
exports.Fragment = Fragment;
|
|
1392
|
+
exports.TemplateNode = TemplateNode;
|
|
1393
|
+
exports.createStore = createStore;
|
|
1394
|
+
exports.essor_version = essor_version;
|
|
1395
|
+
exports.h = h;
|
|
1396
|
+
exports.isComponent = isComponent;
|
|
1397
|
+
exports.isComputed = isComputed;
|
|
1398
|
+
exports.isJsxElement = isJsxElement;
|
|
1399
|
+
exports.isReactive = isReactive;
|
|
1400
|
+
exports.isSignal = isSignal;
|
|
1401
|
+
exports.nextTick = nextTick2;
|
|
1402
|
+
exports.onDestroy = onDestroy;
|
|
1403
|
+
exports.onMount = onMount;
|
|
1404
|
+
exports.renderToString = renderToString;
|
|
1405
|
+
exports.shallowReactive = shallowReactive;
|
|
1406
|
+
exports.shallowSignal = shallowSignal;
|
|
1407
|
+
exports.signalObject = signalObject;
|
|
1408
|
+
exports.ssg = ssg;
|
|
1409
|
+
exports.template = template;
|
|
1410
|
+
exports.unReactive = unReactive;
|
|
1411
|
+
exports.unSignal = unSignal;
|
|
1412
|
+
exports.useComputed = useComputed;
|
|
1413
|
+
exports.useEffect = useEffect;
|
|
1414
|
+
exports.useInject = useInject;
|
|
1415
|
+
exports.useProvide = useProvide;
|
|
1416
|
+
exports.useReactive = useReactive;
|
|
1417
|
+
exports.useRef = useRef;
|
|
1418
|
+
exports.useSignal = useSignal;
|
|
1419
|
+
exports.useWatch = useWatch;
|
|
54
1420
|
//# sourceMappingURL=essor.cjs.js.map
|
|
55
1421
|
//# sourceMappingURL=essor.cjs.js.map
|