solarite 0.4.0 → 0.5.0
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/Solarite-debug.js +1655 -1762
- package/dist/Solarite.js +1679 -1814
- package/dist/Solarite.min.js +2 -11
- package/package.json +11 -1
- package/src/Globals.js +14 -24
- package/src/HtmlParser.js +1 -1
- package/src/MultiValueMap.js +3 -3
- package/src/NodeGroup.js +248 -330
- package/src/Path.js +212 -0
- package/src/PathToAttribValue.js +259 -0
- package/src/PathToAttribs.js +77 -0
- package/src/PathToComment.js +8 -0
- package/src/PathToComponent.js +169 -0
- package/src/PathToEvent.js +57 -0
- package/src/PathToNodes.js +566 -0
- package/src/RootNodeGroup.js +2 -147
- package/src/Shell.js +83 -77
- package/src/Solarite.d.ts +71 -31
- package/src/Solarite.js +124 -14
- package/src/Template.js +39 -40
- package/src/Util.js +22 -38
- package/src/assert.js +5 -5
- package/src/getArg.js +26 -24
- package/src/h.js +23 -20
- package/src/hash.js +11 -9
- package/src/toEl.js +7 -8
- package/src/udomdiff.js +0 -2
- package/src/watch.js +76 -79
- package/src/ExprPath.js +0 -1117
- package/src/createSolarite.js +0 -154
package/dist/Solarite.min.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
// Version
|
|
1
|
+
// Version 0.5.0
|
|
2
2
|
// License: MIT
|
|
3
3
|
// http://vorticode.github.io/solarite
|
|
4
|
-
let lastObjectId=1,objectIds=new WeakMap;function getObjectId(t){let e=objectIds.get(t);return e||(e="~\f"+lastObjectId++,objectIds.set(t,e)),e}let isHashing=!0;function toJSON(){return isHashing?getObjectId(this):this}function getObjectHash(t){let e;Node.prototype.toJSON!==toJSON&&(Node.prototype.toJSON=toJSON,(()=>{}).toJSON!==toJSON&&(Function.prototype.toJSON=toJSON)),isHashing=!0;try{e=JSON.stringify(t)}catch(l){e=getObjectHashCircular(t)}return isHashing=!1,e}function getObjectHashCircular(t){const e=new Set;return JSON.stringify(t,((t,l)=>{if("object"==typeof l&&null!==l){if(e.has(l))return getObjectId(l);e.add(l)}return l}))}var Globals;function reset(){Globals={t:new Map,connected:new WeakSet,l:null,div:document.createElement("div"),i:document,o:{},h:{},u:new WeakMap,p:new WeakMap,m:new WeakMap,$:new WeakSet,v:new WeakSet,P:new WeakMap,reset,count:0}}reset();var Globals$1=Globals;function delve(t,e,l=d){let s=l!==d,i=e.length;if(!t&&!s&&i)return;let r=0;for(let o of e){if(void 0===t[o]){if(!s)return;i-1>r&&(t[o]=(e[r+1]+"").match(/^\d+$/)?[]:{})}s&&r===i-1&&(t[o]=l),t=t[o],r++}return t}let d={},Util={T(t,e){let l=t.length;if(l!==e.length)return!1;for(let s=0;l>s;s++)if(t[s]!==e[s])return!1;return!0},N(t,e=null){let l={};for(let s of t.attributes)s.name!==e&&(l[Util.G(s.name)]=s.value);return l},A(t,e){let l=e.getAttribute("data-id")||e.getAttribute("id");if(l){if(t[l]&&!t[l]?.nodeType)throw Error(`${t.constructor.name}.${l} already has a value. Can't set it as a reference to <${e.tagName.toLowerCase()} id="${l}">`);delve(t,l.split(/\./g),e)}},S(t,e){let l,s,i=e.tagName.toLowerCase();if(t.hasAttribute("global")||t.hasAttribute("data-global")){l=i,s="";let r=Globals$1.i||e.ownerDocument||document;r.head.querySelector(`style[data-style="${l}"]`)?t.remove():(r.head.append(t),t.setAttribute("data-style",l))}else{let t=e.getAttribute("data-style");t||(e.constructor.C||(e.constructor.C=1),t=e.constructor.C++,e.setAttribute("data-style",t)),s=`[data-style="${t}"]`}for(let e of t.childNodes)if(3===e.nodeType){let t=e.textContent,l=t.replace(/:host(?=[^a-z0-9_])/gi,`${i}${s}`);t!==l&&(e.textContent=l)}},H:t=>(t=(t=(t=t.replace(/([a-z0-9])([A-Z])/g,"$1-$2")).replace(/([A-Z])([A-Z][a-z])/g,"$1-$2")).replace(/([a-zA-Z])([0-9])/g,"$1-$2")).toLowerCase(),G:t=>t.replace(/-([a-z])/g,(t=>t[1].toUpperCase())),O:t=>"checkbox"===t.type||"radio"===t.type?t.checked:"file"===t.type?[...t.files]:"number"===t.type||"range"===t.type?t.valueAsNumber:"date"===t.type||"time"===t.type||"datetime-local"===t.type?t.valueAsDate:"select-multiple"===t.type?[...t.selectedOptions].map((t=>t.value)):t.hasAttribute("contenteditable")?t.innerHTML:t.value,k:t=>t.startsWith("on")&&t in Globals$1.div,M(t,e){let l=t.tagName+"."+e,s=Globals$1.h[l];if(void 0===s){let i=Object.getPrototypeOf(t);for(;i;){const t=i.constructor.name;if(t.startsWith("HTML")&&t.endsWith("Element"))break;i=Object.getPrototypeOf(i)}Globals$1.h[l]=s=!!i&&!!Object.getOwnPropertyDescriptor(i,e)?.set}return s},j:t=>Array.isArray(t)&&t.length>=2&&("object"==typeof t[0]||void 0===t[0])&&!t.slice(1).find((t=>"string"!=typeof t&&"number"!=typeof t)),U:t=>void 0===t||!1===t||null===t,I:t=>"function"==typeof t?Util.I(t()):t instanceof Date?t.toISOString().replace(/T/," "):Array.isArray(t)||"object"==typeof t?"":t,F(t,e,l){let s=t.get(e);s?s.push(l):(s=[l],t.set(e,s))},J(t){const e=t=>t.nodeType!==Node.ELEMENT_NODE&&(t.nodeType!==Node.TEXT_NODE||""===t.textContent.trim()),l=[...t];for(;l.length>0&&e(l[0]);)l.shift();for(;l.length>0&&e(l[l.length-1]);)l.pop();return l}};class MultiValueMap{data={};add(t,e){let l=this.data,s=l[t];s||(s=new Set,l[t]=s),s.add(e)}R(){for(let t in this.data)return!0;return!1}getAll(t){return this.data[t]||[]}delete(t,e=void 0){let l,s=this.data,i=s[t];if(i)return void 0===e?([l]=i,i.delete(l)):(i.delete(e),l=e),0===i.size&&delete s[t],l}V(t){let e,l=this.data,s=l[t];if(s)return[e]=s,s.delete(e),0===s.size&&delete l[t],e}L(t,e){let l,s=this.data,i=s[t];if(i)return i.delete(e),l=e,0===i.size&&delete s[t],l}W(t){let e=this.data,l=[];for(let s in e)e[s].has(t)&&l.push(s);return l}}const udomdiff=(t,e,l,s)=>{const i=l.length;let r=e.length,o=i,a=0,n=0,h=null;for(;r>a||o>n;)if(r===a){const e=i>o?n?l[n-1].nextSibling:l[o-n]:s;for(;o>n;){let s=l[n++];t.insertBefore(s,e)}}else if(o===n)for(;r>a;){let l=e[a];h&&h.has(l)||t.removeChild(l),a++}else if(e[a]===l[n])a++,n++;else if(e[r-1]===l[o-1])r--,o--;else if(e[a]===l[o-1]&&l[n]===e[r-1]){const s=e[--r].nextSibling;let i=l[n++],h=e[a++];t.insertBefore(i,h.nextSibling);let f=l[--o];t.insertBefore(f,s),e[r]=l[o]}else{if(!h){h=new Map;let t=n;for(;o>t;)h.set(l[t],t++)}if(h.has(e[a])){const s=h.get(e[a]);if(s>n&&o>s){let i=a,f=1;for(;++i<r&&o>i&&h.get(e[i])===s+f;)f++;if(f>s-n){const i=e[a];for(;s>n;){let e=l[n++];t.insertBefore(e,i)}}else{let s=e[a++],i=l[n++];t.replaceChild(i,s)}}else a++}else{let l=e[a++];t.removeChild(l)}}return l};class ExprPath{type;attrName;D;_;Z;B;K;p=[];q;X;Y;tt;et;lt=void 0;constructor(t,e,l=ExprPathType.st,s=null,i=null){this.Z=t,this.B=e,this.type=l,this.attrName=s,this.D=i,l===ExprPathType.it&&(this._=new Set)}apply(t,e=!0){switch(this.type){case 1:this.rt(t[0],e);break;case 2:this.ot(this.B,t[0]);break;case 4:break;case 5:this.nt(this.B,t[0],this.K.ht.root);break;default:this.ft(this.B,t)}}rt(t,e=!0){let l=this;e&&l.ut();let s=[],i=l.p,r=[];l.p=[],l.dt(t,s,r);let o=!1;if(r.length){for(let[t,e]of r){let i=l.ct(s[t],!1),r=i.bt();1===r.length?s[t]=r[0]:(s[t]=r,o=!0),l.p[e]=i}o&&(s=s.flat())}let a=l.bt();if(!Util.T(a,s)){l.q=s,this.K.yt&&this.K.yt.gt(),a.length&&!s.length&&l.$t()||udomdiff(l.B.parentNode,a,s,l.B);for(let t of i)t.Et.parentNode||t.vt();for(let t of s)if(1===t?.nodeType){t.hasAttribute("solarite-placeholder")&&this.K.Pt(t,null,!0);for(let e of t.querySelectorAll("[solarite-placeholder]"))this.K.Pt(e,null,!0)}}}Tt(t){let e=Math.min(t.Nt,t.items.length),l=t.Nt-e;for(let l=0;e>l;l++){let e=this.p[t.index+l],s=(this.et||this.tt)(t.items[l]);this.Gt(s,(s=>{let i=this.ct(s,!0);if(i&&i===e);else{i||(i=this.ct(s,!1)),this.p[t.index+l]=i;let r=e.Et;for(let t of i.bt())r.parentNode.insertBefore(t,r);i!==e&&e.vt()}}))}if(l>0){for(let s=0;l>s;s++)this.p[t.index+e+s].vt();this.p.splice(t.index+e,l)}else{let l=t.items.slice(e),s=this.p[t.index+e]?.Et||this.B;for(let t=0;l.length>t;t++){let e=this.et(l[t]),i=this.ct(e,!0);i||(i=this.ct(e,!1)),this.p.push(i);for(let t of i.bt())s.parentNode.insertBefore(t,s)}}this.q=null}Gt(t,e){if(Array.isArray(t))for(let l of t)this.Gt(l,e);else if("function"==typeof t)Globals$1.l=this,this.tt=t,t=t(),Globals$1.l=null,this.Gt(t,e);else if(t instanceof Template||t?.nodeType)e(t);else{void 0===t||!1===t||null===t?t="":"string"!=typeof t&&(t+="");let l=new Template([t],[]);l.wt=!0,this.Gt(l,e)}}dt(t,e,l){if(t instanceof Template){let s=this.ct(t,!0);if(s){let l=s.bt();e.push(...l);let i=!1;for(let e of l)if(1===e?.nodeType){e.tagName.includes("-")&&(t.xt.find((t=>t?.B===e))?i=!0:this.K.Pt(e,null,!0));for(let l of e.querySelectorAll("*"))l.tagName.includes("-")&&(t.xt.find((t=>t?.B===l))?i=!0:this.K.Pt(l,null,!0))}return i&&s.At(t.xt),this.p.push(s),s}l.push([e.length,this.p.length]),e.push(t),this.p.push(null)}else t?.nodeType?11===t?.nodeType?e.push(...t.childNodes):e.push(t):this.Gt(t,(t=>{this.dt(t,e,l)}))}ot(t,e){Array.isArray(e)&&(e=e.flat().join(" "));let l=this._;if(this._=new Set,e)if("function"==typeof e&&(Globals$1.l=this,this.tt=e,e=e(),Globals$1.l=null),"object"==typeof e)for(let l in e){let s=e[l];void 0!==s&&!1!==s&&null!==s&&(t.setAttribute(l,s),this._.add(l))}else{let l=(e+"").split(/([\w-]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s]+))/g).map((t=>t.trim())).filter((t=>t.length));for(let e of l){let[l,s]=e.split(/\s*=\s*/);s=(s||"").replace(/^(['"])(.*)\1$/,"$2"),t.setAttribute(l,s),this._.add(l)}}for(let e of l)this._.has(e)||t.removeAttribute(e)}nt(t,e,l){let s,i=this.attrName.slice(2),r=[];if(Array.isArray(e)&&"function"==typeof e[0])s=e[0],r=e.slice(1);else{if("function"!=typeof e)throw Error(`Invalid event binding: <${t.tagName.toLowerCase()} ${this.attrName}=\${${JSON.stringify(e)}}>`);s=e}this.St(t,l,i,i,s,r)}St(t,e,l,s,i,r,o=!1){let a=Globals$1.u.get(t);a||(a={[l]:[,,,]},Globals$1.u.set(t,a));let n=a[l];if(n||(a[l]=n=[,,,]),"function"!=typeof i)throw Error(`Solarite cannot bind to <${t.tagName.toLowerCase()} ${this.attrName}=\${${i}}> because it's not a function.`);if(n[0]!==i){let[l,r,a]=n;l&&t.removeEventListener(s,r,o);let h=i,f=l=>h.call(e,...n[2],l,t);n[0]=h,n[1]=f,t.addEventListener(s,f,o)}a[l][2]=r}ft(t,e){let l=e[0];if(Util.j(l)){let[e,s]=[l[0],l.slice(1)];if(!e)throw Error(`Solarite cannot bind to <${t.tagName.toLowerCase()} ${this.attrName}=\${[${l.map((t=>t?`'${t}'`:t+"")).join(", ")}]}>.`);let i=delve(e,s);if("value"===this.attrName&&"select-multiple"===t.type&&Array.isArray(i)){let e=i.map((t=>t+""));for(let l of t.options)l.selected=e.includes(l.value)}else{const e=Util.U(i)?"":i;"value"===this.attrName&&t.hasAttribute("contenteditable")?e!==t.innerHTML&&(t.innerHTML=e):e!==t[this.attrName]&&(t[this.attrName]=e)}let r=()=>{let l="value"===this.attrName?Util.O(t):t[this.attrName];delve(e,s,l)};this.St(t,s[0],this.attrName,"input",r,[],!0)}else{let s=this.lt;void 0===s&&(s=this.lt=Util.M(t,this.attrName));let i=this.D;if(!i){if(Globals$1.l=this,"function"==typeof l){if(this.Ct)return;this.tt=l,l=l()}else l=Util.I(l);Globals$1.l=null}if(i||void 0!==l&&!1!==l&&null!==l)if(i||!0!==l){let r;if(i){let t=[];for(let l=0;this.D.length>l;l++)if(t.push(this.D[l]),this.D.length-1>l){Globals$1.l=this;let s=Util.I(e[l]);Globals$1.l=null,Util.U(s)||t.push(s)}r=t.join("")}else r=l;(s?t[this.attrName]:t.getAttribute(this.attrName))!==r&&(s?t[this.attrName]=r:t.hasAttribute("contenteditable")&&(t.innerHTML=r),t.setAttribute(this.attrName,r))}else s&&(t[this.attrName]=!0),t.setAttribute(this.attrName,"");else s&&(t[this.attrName]=!1),t.removeAttribute(this.attrName)}}clone(t,e=0){let l,s,i=t,r=e?this.Y.slice(0,-e):this.Y;for(let t=r.length-1;t>0;t--)i=i.childNodes[r[t]];let o=i.childNodes;l=r.length?o[r[0]]:t,this.Z&&(s=o[this.X]);let a=new ExprPath(s,l,this.type,this.attrName,this.D);return a.Ct=this.Ct,a}gt(){let t=this,e=this.B.parentNode;for(;t&&t.B.parentNode===e;)t.q=null,t=t.K?.yt}$t(){let t=this.Z.parentNode;return this.Z===t.firstChild&&this.B===t.lastChild&&(t.innerHTML="",t.append(this.Z,this.B),!0)}bt(){if(this.type===ExprPathType.Ht||this.type===ExprPathType.it)return[this.B];let t;if(t=this.q,t)return t;t=[];let e=this.Z.nextSibling,l=this.B;for(;e&&e!==l;)t.push(e),e=e.nextSibling;return this.q=t,t}Ot(){return this.B.parentNode}ct(t,e=!0){let l,s=this.kt;if(e){if(l=s.V(t.Mt()),l||(s=this.jt,l=s.V(t.Mt())),!l)return null;s.L(t.Ut(),l)}else t.xt.length&&(l=s.V(t.Ut()),l||(s=this.jt,l=s.V(t.Ut())),l&&(s.L(l.It,l),l.At(t.xt),l.It=t.Mt()));return l||(l=new NodeGroup(t,this)),this.Ft.push(l),l}Ft=[];kt=new MultiValueMap;jt=new MultiValueMap;ut(){let t=this.kt.data,e=this.jt.data;for(let l in t){let s=e[l];if(s)for(let e of t[l])s.add(e);else e[l]=t[l]}this.kt=new MultiValueMap;let l=this.kt;for(let t of this.Ft)l.add(t.It,t),l.add(t.Jt,t);this.Ft=[]}}const ExprPathType={st:1,it:2,Ht:3,Comment:4,Event:5};function getNodePath(t){let e=[];for(;;){let l=t.parentNode;if(!l)break;e.push([].indexOf.call(t.parentNode.childNodes,t)),t=l}return e}function resolveNodePath(t,e){for(let l=e.length-1;l>=0;l--)t=t.childNodes[e[l]];return t}class HtmlParser{constructor(){this.Rt={context:HtmlParser.Text,quote:null,buffer:"",Vt:null},this.state={...this.Rt}}reset(){return this.state={...this.Rt},this.state.context}parse(t,e=null){if(null===t)return this.reset();for(let l=0;t.length>l;l++){const s=t[l];switch(this.state.context){case HtmlParser.Text:"<"===s&&t[l+1].match(/[/a-z!]/i)&&(e?.(t,l,this.state.context,HtmlParser.Lt),this.state.context=HtmlParser.Lt,this.state.buffer="");break;case HtmlParser.Lt:if(">"===s)e?.(t,l+1,this.state.context,HtmlParser.Text),this.state.context=HtmlParser.Text,this.state.quote=null,this.state.buffer="";else{if(" "===s&&!this.state.buffer)continue;" "===s||"/"===s||"?"===s?this.state.buffer="":'"'===s||"'"===s||"="===s?(e?.(t,l,this.state.context,HtmlParser.zt),this.state.context=HtmlParser.zt,this.state.quote="="===s?null:s,this.state.buffer=""):this.state.buffer+=s}break;case HtmlParser.zt:this.state.quote||this.state.buffer.length||'"'!==s&&"'"!==s?s===this.state.quote||!this.state.quote&&this.state.buffer.length?(e?.(t,l,this.state.context,HtmlParser.Lt),this.state.context=HtmlParser.Lt,this.state.quote=null,this.state.buffer=""):this.state.quote||">"!==s?" "!==s&&(this.state.buffer+=s):(e?.(t,l+1,this.state.context,HtmlParser.Text),this.state.context=HtmlParser.Text,this.state.quote=null,this.state.buffer=""):this.state.quote=s}}return e?.(t,t.length,this.state.context,null),this.state.context}}HtmlParser.zt="Attribute",HtmlParser.Text="Text",HtmlParser.Lt="Tag";class Shell{fragment;Wt=[];Dt=[];scripts=[];_t=[];Zt=[];constructor(t=null){if(!t)return;if(1===t.length&&!t[0].match(/[<&]/))return void(this.fragment=Globals$1.i.createTextNode(t[0]));let e,l=Shell.Bt(t),s=Globals$1.i.createElement("template");l?s.innerHTML=l:s.content.append(Globals$1.i.createTextNode("")),this.fragment=s.content;let i=[],r=0;const o=Globals$1.i.createTreeWalker(this.fragment,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_TEXT);for(;e=o.nextNode();)if(i.map((t=>t.remove())),i=[],1===e.nodeType)for(let t of[...e.attributes]){let l=t.name.match(/^[\ue000-\uf8ff]$/);if(l)this.Wt.push(new ExprPath(null,e,ExprPathType.it)),r++,e.removeAttribute(l[0]);else{let l=t.value.split(/[\ue000-\uf8ff]/g);if(l.length>1){let s=2!==l.length||l[0].length||l[1].length?l:null,i=Util.k(t.name)?ExprPathType.Event:ExprPathType.Ht;this.Wt.push(new ExprPath(null,e,i,t.name,s)),r+=l.length-1,e.setAttribute(t.name,l.join(""))}}}else if(8===e.nodeType&&"!✨!"===e.nodeValue){if(e?.parentNode?.closest&&e?.parentNode?.closest("[contenteditable]"))throw Error('Contenteditable can\'t have expressions inside them. Use <div contenteditable value="${...}"> instead.');let t,l=e.previousSibling;l||(l=Globals$1.i.createComment("ExprPath:"+this.Wt.length),e.parentNode.insertBefore(l,e)),!e.nextSibling||8===e.nextSibling.nodeType&&"!✨!"===e.nextSibling.textContent?(t=e,t.textContent="ExprPathEnd:"+this.Wt.length):(t=e.nextSibling,i.push(e));let s=new ExprPath(l,t,ExprPathType.st);this.Wt.push(s),r++}else{if(3===e.nodeType&&"TEXTAREA"===e.parentNode?.tagName&&e.textContent.includes("\x3c!--!✨!--\x3e"))throw Error('Textarea can\'t have expressions inside them. Use <textarea value="${...}"> instead.');if(e.nodeType===Node.COMMENT_NODE){let t=e.textContent.split(/[\ue000-\uf8ff]/g);for(let l=0;t.length-1>l;l++){let t=new ExprPath(e.previousSibling,e);t.type=ExprPathType.Comment,this.Wt.push(t),r++}}else if(e.nodeType===Node.TEXT_NODE&&["SCRIPT","STYLE"].includes(e.parentNode?.nodeName)){let t=e.textContent.split(commentPlaceholder);if(t.length>1){let l=[];for(let s=0;t.length>s;s++){let i=Globals$1.i.createTextNode(t[s]);e.parentNode.insertBefore(i,e),s>0&&l.push(i)}for(let t,e=0;t=l[e];e++){let e=new ExprPath(t.previousSibling,t,ExprPathType.st);this.Wt.push(e),r++}i.push(e)}}}if(i.map((t=>t.remove())),r!==t.length-1)throw Error("Could not parse expressions in template. Check for duplicate attributes or malformed html: "+t.join("${...}"));for(let t of this.fragment.querySelectorAll("[is]"))t.setAttribute("_is",t.getAttribute("is"));for(let t of this.Wt)t.Z&&(t.X=[].indexOf.call(t.Z.parentNode.childNodes,t.Z)),t.Y=getNodePath(t.B),t.type!==ExprPathType.Ht&&t.type!==ExprPathType.Event||1!==t.B.nodeType||!t.B.tagName.includes("-")&&!t.B.hasAttribute("is")||(t.Ct=!0);this.Kt()}static Bt(t){let e=[];function l(t,l){l===HtmlParser.Lt&&(t=t.replace(/^<\/?[a-z][a-z0-9]*-[a-z0-9-]+/i,(t=>t+"-solarite-placeholder solarite-placeholder"))),e.push(t)}let s=new HtmlParser;for(let i=0;t.length>i;i++){let r=0,o=s.parse(t[i],((t,e,s,i)=>{r!==e&&l(t.slice(r,e),s),r=e}));t.length-1>i&&e.push(o===HtmlParser.Text?commentPlaceholder:String.fromCharCode(attribPlaceholder+i))}return e.join("")}Kt(){this.scripts=[].map.call(this.fragment.querySelectorAll("scripts"),(t=>getNodePath(t))),this._t=[].map.call(this.fragment.querySelectorAll("style"),(t=>getNodePath(t)));let t=this.fragment.querySelectorAll("[id],[data-id]");for(let e of t){let t=e.getAttribute("data-id")||e.getAttribute("id");if(Globals$1.div.hasOwnProperty(t))throw Error(`<${e.tagName.toLowerCase()} id="${t}"> can't override existing HTMLElement id property.`)}this.Dt=[].map.call(t,(t=>getNodePath(t)));for(let t of this.fragment.querySelectorAll("*"))(t.tagName.includes("-")||t.hasAttribute("_is"))&&(this.Wt.find((e=>e.B===t))||this.Zt.push(getNodePath(t)))}static get(t){let e=Globals$1.P.get(t);return e||(e=new Shell(t),Globals$1.P.set(t,e)),e}}const commentPlaceholder="\x3c!--!✨!--\x3e",attribPlaceholder=57344;class NodeGroup{ht;yt;Et;qt;Wt=[];It;Jt;q;_t;Xt=new Set;Zt=[];Yt;constructor(t,e=null){if(this.ht=e?.K?.ht||this,this.yt=e,!(this instanceof RootNodeGroup)){let[e,l]=this.Qt(t);e&&t.xt.length?(this.te(e,l.Wt),this.Zt=this.ee(e,l),this.le(e,l),this.At(t.xt),this.se(this.Zt)):l&&this.le(e,l)}}Qt(t){if(this.Yt=t,this.It=t.Mt(),this.Jt=t.Ut(),t.wt){let e=Globals$1.i.createTextNode(t.ie[0]);return this.Et=this.qt=e,[]}{let e=Shell.get(t.ie),l=e.fragment.cloneNode(!0);if(11===l?.nodeType){let t=l.childNodes;this.Et=t[0],this.qt=t[t.length-1]}else this.Et=this.qt=l;return[l,e]}}At(t,e=null){let l,s=t.length-1,i=Array((e=e||this.Wt).length);for(let r,o=e.length-1;r=e[o];o--){let a=e[o-1],n=e[o+1];if(r.D?.length>2?(i[o]=t.slice(s-(r.D.length-1)+1,s+1),s-=i[o].length):(i[o]=[t[s]],s--),r.B!==this.ht.root&&r.Ct){if(n&&n.Ct&&n.B===r.B||(l=o),!a||!a.Ct||a.B!==r.B){let t={};for(let s=o;l>=s;s++)t[e[s].attrName]=i[s].length>1?i[s].join(""):i[s][0];this.Pt(r.B,t,!0);for(let t=o;l>=t;t++)e[t].apply(i[t])}}else r.apply(i[o])}this.re();for(let t of this.Zt)t.oe&&t.oe(Util.N(t));this.q=null}Pt(t,e=null,l=!0){let s,i,r=t.hasAttribute("solarite-placeholder"),o=t.hasAttribute("_is");if((r||o)&&([t,s,i]=this.ae(t,r,e)),l&&t.oe){if(!s){s=Util.N(t);for(let t in e||{})s[Util.G(t)]=e[t];i=t.childNodes}t.oe(s,i)}return t}ae(t,e=void 0,l=void 0){void 0===e&&(e=!t.hasAttribute("_is"));let s=(e?t.tagName.slice(0,-21):t.getAttribute("is")).toLowerCase(),i=customElements.get(s);if(!i)throw Error(`The custom tag name ${s} is not registered.`);let r=Util.N(t,"solarite-placeholder");for(let t in l||{})r[Util.G(t)]=l[t];let o=[...t.childNodes].filter((t=>t.nodeType!==Node.COMMENT_NODE||!t.nodeValue.startsWith("ExprPath"))),a=new i(r,o);e||a.setAttribute("is",t.getAttribute("is").toLowerCase()),t.replaceWith(a);let n=t.getAttribute("data-id")||t.getAttribute("id");n&&delve(this.getRootNode(),n.split(/\./g),a);for(let e of this.Wt)e.B===t&&(e.B=a),e.Z===t&&(e.Z=a);this.Et===t&&(this.Et=a),this.qt===t&&(this.qt=a),a.ne&&a.ne();for(let e of t.attributes)"_is"!==e.name&&"solarite-placeholder"!==e.name&&a.setAttribute(e.name,e.value);for(let t in l){let e=l[t];"boolean"==typeof e?!1!==e&&null!=e&&a.setAttribute(t,""):["number","bigint","string"].includes(typeof e)&&a.setAttribute(t,e)}return[a,r,o]}bt(){let t=this.q;if(t)return t;t=[];let e=this.Et,l=this.qt?.nextSibling;for(;e&&e!==l;)t.push(e),e=e.nextSibling;return this.q=t,t}Ot(){return this.Et?.parentNode}getRootNode(){return this.ht.root}he(){return this.ht}vt(){let t=Globals$1.i.createDocumentFragment();for(let e of this.bt())t.append(e)}te(t,e,l){let s=e.length;this.Wt.length=s;for(let i=0;s>i;i++){let s=e[i].clone(t,l);s.K=this,this.Wt[i]=s}}re(){if(this._t)for(let[t,e]of this._t)e!==t.textContent&&Util.S(t,this.he().root)}ee(t,e,l=0){let s=[];for(let i of e.Zt){l&&(i=i.slice(0,-l));let e=resolveNodePath(t,i);t!==e&&s.push(e)}return s}se(t){for(let e in t)t[e]=this.Pt(t[e],null,!1)}le(root,shell,pathOffset=0){let rootEl=this.ht.root;if(rootEl){let options=this.ht.options;if(!1!==options?.Dt)for(let t of shell.Dt){pathOffset&&(t=t.slice(0,-pathOffset));let e=resolveNodePath(root,t);Util.A(rootEl,e)}if(!1!==options?._t){shell._t.length&&(this._t=new Map);for(let t of shell._t){pathOffset&&(t=t.slice(0,-pathOffset));let e=resolveNodePath(root,t);1===rootEl.nodeType&&(Util.S(e,rootEl),this._t.set(e,e.textContent))}}if(!1!==options?.scripts)for(let path of shell.scripts){pathOffset&&(path=path.slice(0,-pathOffset));let script=resolveNodePath(root,path);eval(script.textContent)}}}}class RootNodeGroup extends NodeGroup{root;fe=new Map;constructor(t,e,l){super(t),this.options=l;let[s,i]=this.Qt(t),r=0;if(s instanceof Text){if(!e)throw Error("Cannot create a standalone text node");this.Et=e,this.qt=e,s.nodeValue.length&&e.append(s),this.root=e,Globals$1.p.set(this.root,this)}else{if(e){let t;if(this.root=e,e.childNodes.length&&(t=Globals$1.i.createDocumentFragment(),t.append(...e.childNodes)),isReplaceEl(s,e)){e.append(...s.children[0].childNodes);for(let t of s.children[0].attributes)e.hasAttribute(t.name)||"solarite-placeholder"===t.name||e.setAttribute(t.name,t.value);r=1}else 1===s.childNodes.length&&3===s.childNodes[0].nodeType&&""===s.childNodes[0].textContent||e.append(...s.childNodes);if(t){for(let l of e.querySelectorAll("slot[name]")){let e=l.getAttribute("name");if(e){let s=t.querySelectorAll(`[slot='${e}']`);l.append(...s)}}let l=e.querySelector("slot:not([name])");l?l.append(t):e.append(t)}this.Et=e,this.qt=e}else{let t=getSingleEl(s);this.root=t||s,t&&(r=1)}Globals$1.p.set(this.root,this),this.te(this.root,i.Wt,r),this.Zt=this.ee(this.root,i,r),this.le(this.root,i,r),this.At(t.xt),this.se(this.Zt)}}}function getSingleEl(t){let e=[];for(let l of t.childNodes)if(1===l.nodeType||3===l.nodeType&&l.textContent.trim().length){if(e.length)return null;e.push(l)}return e[0]}function isReplaceEl(t,e){return 1===t.children.length&&e.tagName.includes("-")&&t.children[0].tagName.replace("-SOLARITE-PLACEHOLDER","")===e.tagName}class Template{xt=[];ie=[];ue;wt;constructor(t,e){this.ie=t,this.xt=e}toJSON(){return this.ue||(this.ue=[getObjectId(this.ie),this.xt]),this.ue}oe(t=null,e={}){let l,s=!1;if(t){if(l=Globals$1.p.get(t),l||(l=new RootNodeGroup(this,t,e),Globals$1.p.set(t,l),s=!0),0===l.Wt.length&&this.xt.length||l.Wt.length>this.xt.length)throw Error(`Solarite Error: Parent HTMLElement ${l.Yt.ie.join("${...}")} and ${l.Wt.length} \${value} placeholders can't accomodate a Template with ${this.xt.length} values.`)}else l=new RootNodeGroup(this,null,e),t=l.getRootNode(),Globals$1.p.set(t,l),s=!0;return s||(1!==this.ie?.length||this.ie[0]?l.At(this.xt):t.innerHTML=""),l.fe=new Map,t}Mt(){return this.It||(this.It=this.xt.length?getObjectHash(this):this.ie[0]),this.It}Ut(){return this.Jt||(this.Jt=this.xt.length?this.toJSON()[0]:this.ie[0]),this.Jt}static de(t,e,l){const s=selfClosingTags.has(t.toLowerCase());let i=[],r=[],o="<"+t;if(e&&"object"==typeof e)for(let t in e){let l=e[t];"id"!==t&&"data-id"!==t?(o+=` ${t}=`,i.push(o),r.push(l),o=""):o+=` ${t}="${l}"`}if(!s){i.push(i.length>0?'"'===o?'">':">":o+">");for(let t of l)addChild(t,i,r)}return s?i.push(i.length>0?">":o+">"):i[i.length-1]+=`</${t}>`,new Template(i,r)}}const selfClosingTags=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),addChild=(t,e,l)=>{if(Array.isArray(t))for(let s of t)addChild(s,e,l);else{let s=!1;if(t instanceof Template)if(t.xt.length>0)s=!0;else{const e=(t.ie[0]||"").match(/^<([a-zA-Z][\w:-]*)/),l=e?e[1].toLowerCase():"";s=selfClosingTags.has(l)}if(s){e[e.length-1]+=t.ie[0];for(let s=0;t.xt.length>s;s++)l.push(t.xt[s]),e.push(t.ie[s+1]??"")}else l.push(t),e.push("")}};function toEl(t){if("string"==typeof t){let e=t;(e.match(/^\s^</)||e.match(/>\s+$/))&&(e=e.trim());let l=Globals$1.i.createElement("template");l.innerHTML=e;let s=Util.J(l.content.childNodes);return 1===s.length?s[0]:l.content}if(t instanceof Template)return t.oe();if(t&&"object"==typeof t){let e=t;if("Object"!==e.constructor.name)throw Error(`Solarate Web Component class ${e.constructor?.name} must extend HTMLElement.`);if(!Globals$1.m.has(e)){Globals$1.m.set(e,null),e[renderF]();let t=Globals$1.m.get(e);Globals$1.m.delete(e);for(let l in e)t[l]="function"==typeof e[l]?e[l].bind(t):e[l];return t}}throw Error("toEl() does not support argument of type: "+(t?typeof t:t))}let renderF="render";function h(t=void 0,...e){if(Array.isArray(arguments[0]))return new Template(arguments[0],e);if("string"==typeof arguments[0]||arguments[0]instanceof String){let t=arguments[0];if(!e.length||"object"!=typeof e[0]&&null!==e[0]){let e=t;return e.match(/^\s^</)&&(e=e.trim()),new Template([e],[])}{let l=t+"",s=e[0]||{},i=e.slice(1);return Template.de(l,s,i)}}if(arguments[0]instanceof HTMLElement||arguments[0]instanceof DocumentFragment){if(!(arguments[1]instanceof Template)){let t=arguments[0],e=arguments[1];t.shadowRoot&&(t.innerHTML="");let l=(l,...s)=>(Globals$1.$.add(t),new Template(l,s).oe(t,e));return l}arguments[1].oe(arguments[0],arguments[2])}else{if(!arguments.length)return(t,...e)=>toEl(h(t,...e));if("object"!=typeof arguments[0]||!Globals$1.m.has(arguments[0]))throw Error("h() does not support argument of type: "+(arguments[0]?typeof arguments[0]:arguments[0]));{let t=arguments[0];if("Object"!==t.constructor.name)throw Error(`Solarate Web Component class ${t.constructor?.name} must extend HTMLElement.`);if(!(arguments[1]instanceof Template))return((...e)=>{let l=h(...e).oe();Globals$1.m.set(t,l)}).bind(t);{let e=arguments[1].oe();Globals$1.m.set(t,e)}}}}function getArg(el,attributeName,defaultValue=void 0,type=ArgType.String,fallback=void 0){let val=defaultValue,attrVal=el.getAttribute(attributeName)||el.getAttribute(Util.H(attributeName)),result;if(null!==attrVal&&(val=attrVal),Array.isArray(type))return type.includes(val)?val:fallback;if("function"==typeof type)return type.constructor?new type(val):type(val);if(type===ArgType.ce){let t="string"==typeof val?val.toLowerCase():val;return!["false","0",!1,0,null,void 0,NaN].includes(t)&&(!(!["true",!0].includes(t)&&0===parseFloat(t))||fallback)}switch(type){case ArgType.pe:return result=parseInt(val),isNaN(result)?fallback:result;case ArgType.be:return result=parseFloat(val),isNaN(result)?fallback:result;case ArgType.String:return[void 0,null,!1].includes(val)?"":val+"";case ArgType.me:case ArgType.ye:if("string"!=typeof val||!val.length)return val;try{return type===ArgType.me?JSON.parse(val):eval(`(${val})`)}catch(t){return val}default:return val}}function setArgs(t,e,l){for(let s in e)this[s]=getArg(t,s,e[s],l[s]||ArgType.String)}var ArgType={ce:"Bool",pe:"Int",be:"Float",String:"String",JSON:"Json",me:"Json",ye:"Eval"};function defineClass(t,e,l){if(!customElements[getName](t)){(e=e||Util.H(t.name)).includes("-")||(e+="-element");let s=null;l&&(s={ge:l}),customElements[define](e,t,s)}}function createSolarite(t=null){let e=HTMLElement;t&&!t.includes("-")&&(t=t.toLowerCase(),e=Globals$1.o[t],e||(e=Globals$1.i.createElement(t).constructor,Globals$1.o[t]=e));let l=new Proxy(e,{construct:(e,l,s)=>(defineClass(s,null,t),Reflect.construct(e,l,s))});return class extends l{$e;Ee;ve;constructor(t={}){super(),!0===t.oe?this.oe():!1===t.oe&&Globals$1.$.add(this)}ne(){!Globals$1.$.has(this)&&this.oe&&this.oe()}Pe(){this.ne(),Globals$1.connected.has(this)||(Globals$1.connected.add(this),this.Ee&&this.Ee()),this.$e&&this.$e()}Te(){this.ve&&this.ve()}static define(e=null){defineClass(this,e,t)}}}let define="define",getName="getName";
|
|
5
|
-
/*
|
|
6
|
-
┏┓ ┓ •
|
|
7
|
-
┗┓┏┓┃┏┓┏┓┓╋▗▖
|
|
8
|
-
┗┛┗┛┗┗┻╹ ╹╹┗
|
|
9
|
-
JavasCript UI library
|
|
10
|
-
@license MIT
|
|
11
|
-
@copyright Vorticode LLC
|
|
12
|
-
https://vorticode.github.io/solarite/ */
|
|
13
|
-
const Solarite=new Proxy(createSolarite(),{apply:(t,e,l)=>createSolarite(...l)});export default h;export{ArgType,Globals$1 as Globals,Solarite,Util as SolariteUtil,Template,getArg,h,h as r,setArgs,toEl};
|
|
4
|
+
function assert(t){}let lastObjectId=1,objectIds=new WeakMap;function getObjectId(t){let e=objectIds.get(t);return void 0===e&&(e="~@"+lastObjectId++,objectIds.set(t,e)),e}let isHashing=!0;function toJSON(){return isHashing?getObjectId(this):this}function getObjectHash(t){Node.prototype.toJSON!==toJSON&&(Node.prototype.toJSON=toJSON,(()=>{}).toJSON!==toJSON&&(Function.prototype.toJSON=toJSON)),isHashing=!0;try{return JSON.stringify(t)}catch(e){return getObjectHashCircular(t)}finally{isHashing=!1}}function getObjectHashCircular(t){const e=new Set;return JSON.stringify(t,((t,l)=>{if("object"==typeof l&&null!==l){if(e.has(l))return getObjectId(l);e.add(l)}return l}))}var Globals;function reset(){Globals={connected:new WeakSet,t:null,l:null,div:document.createElement("div"),i:document,o:{},h:{},u:new WeakMap,p:new WeakMap,m:new WeakMap,$:new WeakSet,v:new WeakMap,reset}}reset();var Globals$1=Globals;function delve(t,e,l=d){let s=l!==d,i=e.length;if(!t&&!s&&i)return;let r=0;for(let o of e){if(void 0===t[o]){if(!s)return;i-1>r&&(t[o]=(e[r+1]+"").match(/^\d+$/)?[]:{})}s&&r===i-1&&(t[o]=l),t=t[o],r++}return t}let d={},Util={T(t,e){let l=t.length;if(l!==e.length)return!1;for(let s=0;l>s;s++)if(t[s]!==e[s])return!1;return!0},P(t,e=null){let l={};for(let s of t.attributes)s.name!==e&&(l[Util.G(s.name)]=s.value);return l},A(t,e){let l=e.getAttribute("data-id")||e.getAttribute("id");if(l){if(t[l]&&!t[l]?.nodeType)throw Error(`${t.constructor.name}.${l} already has a value. Can't set it as a reference to <${e.tagName.toLowerCase()} id="${l}">`);delve(t,l.split(/\./g),e)}},N(t,e){let l,s,i=e.tagName.toLowerCase();if(t.hasAttribute("global")||t.hasAttribute("data-global")){l=i,s="";let r=Globals$1.i||e.ownerDocument||document;r.head.querySelector(`style[data-style="${l}"]`)?t.remove():(r.head.append(t),t.setAttribute("data-style",l))}else{let t=e.getAttribute("data-style");t||(e.constructor.S||(e.constructor.S=1),t=e.constructor.S++,e.setAttribute("data-style",t)),s=`[data-style="${t}"]`}for(let e of t.childNodes)if(3===e.nodeType){let t=e.textContent,l=t.replace(/:host(?=[^a-z0-9_])/gi,`${i}${s}`);t!==l&&(e.textContent=l)}},O:t=>(t=(t=(t=t.replace(/([a-z0-9])([A-Z])/g,"$1-$2")).replace(/([A-Z])([A-Z][a-z])/g,"$1-$2")).replace(/([a-zA-Z])([0-9])/g,"$1-$2")).toLowerCase(),G:t=>t.replace(/-([a-z])/g,(t=>t[1].toUpperCase())),H(t,e){customElements[getName](t)||((e=e||Util.O(t.name)).includes("-")||(e+="-element"),customElements[define](e,t))},C:t=>"checkbox"===t.type||"radio"===t.type?t.checked:"file"===t.type?[...t.files]:"number"===t.type||"range"===t.type?t.valueAsNumber:"date"===t.type||"time"===t.type||"datetime-local"===t.type?t.valueAsDate:"select-multiple"===t.type?[...t.selectedOptions].map((t=>t.value)):t.hasAttribute("contenteditable")?t.innerHTML:t.value,j:t=>t.startsWith("on")&&t in Globals$1.div,U(t,e){let l=t.tagName+"."+e,s=Globals$1.h[l];if(void 0===s){let i=Object.getPrototypeOf(t);for(;i;){const t=i.constructor.name;if(t.startsWith("HTML")&&t.endsWith("Element"))break;i=Object.getPrototypeOf(i)}Globals$1.h[l]=s=!!i&&!!Object.getOwnPropertyDescriptor(i,e)?.set}return s},M:t=>Array.isArray(t)&&t.length>=2&&("object"==typeof t[0]||void 0===t[0])&&!t.slice(1).find((t=>"string"!=typeof t&&"number"!=typeof t)),L:t=>void 0===t||!1===t||null===t,I:t=>"function"==typeof t?Util.I(t()):t instanceof Date?t.toISOString().replace(/T/," "):Array.isArray(t)||"object"==typeof t?"":t,R(t,e,l){let s=t.get(e);s?s.push(l):(s=[l],t.set(e,s))},k(t){Globals$1.i.createDocumentFragment().append(...t)},F(t){const e=t=>t.nodeType!==Node.ELEMENT_NODE&&(t.nodeType!==Node.TEXT_NODE||""===t.textContent.trim()),l=[...t];for(;l.length>0&&e(l[0]);)l.shift();for(;l.length>0&&e(l[l.length-1]);)l.pop();return l}},define="define",getName="getName";class Path{J;V;D;W=[];Z;_;B;K;constructor(t,e){this.J=t,this.V=e}apply(t,e=!0){}q(){return 1}X(t,e){let l=t,s=this.B,i=s.length-e;for(let t=i-1;t>0;t--)l=l.childNodes[s[t]];return i?l.childNodes[s[0]]:t}clone(t,e=0){let l,s,i=t,r=this.B,o=r.length-e;for(let t=o-1;t>0;t--)i=i.childNodes[r[t]];let n=i.childNodes;l=o?n[r[0]]:t,this.J&&(s=n[this._]);let a=new this.constructor(s,l,this.attrName,this.Y);return a.tt=this.tt,a.et=this.et,a}lt(){return[this.V]}static get(t){let e=[];for(;;){let l=t.parentNode;if(!l)break;e.push([].indexOf.call(t.parentNode.childNodes,t)),t=l}return e}static resolve(t,e){for(let l=e.length-1;l>=0;l--)t=t.childNodes[e[l]];return t}}class HtmlParser{constructor(){this.st={context:HtmlParser.Text,quote:null,buffer:"",it:null},this.state={...this.st}}reset(){return this.state={...this.st},this.state.context}parse(t,e=null){if(null===t)return this.reset();for(let l=0;t.length>l;l++){const s=t[l];switch(this.state.context){case HtmlParser.Text:"<"===s&&t[l+1].match(/[/a-z!]/i)&&(e?.(t,l,this.state.context,HtmlParser.rt),this.state.context=HtmlParser.rt,this.state.buffer="");break;case HtmlParser.rt:if(">"===s)e?.(t,l+1,this.state.context,HtmlParser.Text),this.state.context=HtmlParser.Text,this.state.quote=null,this.state.buffer="";else{if(" "===s&&!this.state.buffer)continue;" "===s||"/"===s||"?"===s?this.state.buffer="":'"'===s||"'"===s||"="===s?(e?.(t,l,this.state.context,HtmlParser.ot),this.state.context=HtmlParser.ot,this.state.quote="="===s?null:s,this.state.buffer=""):this.state.buffer+=s}break;case HtmlParser.ot:this.state.quote||this.state.buffer.length||'"'!==s&&"'"!==s?s===this.state.quote||!this.state.quote&&this.state.buffer.length?(e?.(t,l,this.state.context,HtmlParser.rt),this.state.context=HtmlParser.rt,this.state.quote=null,this.state.buffer=""):this.state.quote||">"!==s?" "!==s&&(this.state.buffer+=s):(e?.(t,l+1,this.state.context,HtmlParser.Text),this.state.context=HtmlParser.Text,this.state.quote=null,this.state.buffer=""):this.state.quote=s}}return e?.(t,t.length,this.state.context,null),this.state.context}}HtmlParser.ot="Attribute",HtmlParser.Text="Text",HtmlParser.rt="Tag";class PathToAttribValue extends Path{attrName;Y;et;constructor(t,e,l=null,s=null){super(null,e),this.attrName=l,this.Y=s}apply(t){let e=this.V,l=t[0],s=this.Y;if(!s&&Util.M(l)){if(this.tt&&e.tagName.endsWith("-SOLARITE-PLACEHOLDER"))return;let[t,s]=[l[0],l.slice(1)];if(!t)throw Error(`Solarite cannot bind to <${e.tagName.toLowerCase()} ${this.attrName}=\${[${l.map((t=>t?`'${t}'`:t+"")).join(", ")}]}>.`);let i=delve(t,s);if("value"===this.attrName&&"select-multiple"===e.type&&Array.isArray(i)){let t=i.map((t=>t+""));for(let l of e.options)l.selected=t.includes(l.value)}else{const t=Util.L(i)?"":i;"value"===this.attrName&&e.hasAttribute("contenteditable")?t!==e.innerHTML&&(e.innerHTML=t):t!==e[this.attrName]&&(e[this.attrName]=t)}let r=()=>{let l="value"===this.attrName?Util.C(e):e[this.attrName];delve(t,s,l)};this.nt(e,this.D.getRootNode(),this.attrName,"input",r,[],!0)}else{let i=this.et;if(!s){if(Globals$1.t=this,"function"==typeof l){if(this.tt)return;this.K=l,l=l()}else l=Util.I(l);Globals$1.t=null}if(s||void 0!==l&&!1!==l&&null!==l)if(s||!0!==l){let r=s?this.ht(t):l;(i?e[this.attrName]:e.getAttribute(this.attrName))!==r&&(i?e[this.attrName]=r:"value"===this.attrName&&e.hasAttribute("contenteditable")&&(e.innerHTML=r),e.setAttribute(this.attrName,r))}else i&&(e[this.attrName]=!0),e.setAttribute(this.attrName,"");else i&&(e[this.attrName]=!1),e.removeAttribute(this.attrName)}}q(){return this.Y?this.Y.length-1:1}ht(t){if(!this.Y)return t[0];let e=[],l=this.Y;for(let s=0;l.length>s;s++)if(e.push(l[s]),l.length-1>s){Globals$1.t=this;let l=Util.I(t[s]);Globals$1.t=null,Util.L(l)||e.push(l)}return e.join("")}nt(t,e,l,s,i,r,o=!1){let n=Globals$1.u.get(t);n||(n={[l]:[,,,]},Globals$1.u.set(t,n));let a=n[l];if(a||(n[l]=a=[,,,]),"function"!=typeof i)throw Error(`Solarite cannot bind to <${t.tagName.toLowerCase()} ${this.attrName}=\${${i}}> because it's not a function.`);if(a[0]!==i){let[l,r,n]=a;l&&t.removeEventListener(s,r,o);let h=i,f=l=>h.call(e,...a[2],l,t);a[0]=h,a[1]=f,t.addEventListener(s,f,o)}n[l][2]=r}}class PathToEvent extends PathToAttribValue{constructor(t,e,l=null,s=null){super(null,e,l,s)}apply(t){if(this.tt&&this.V.tagName.endsWith("-SOLARITE-PLACEHOLDER"))return;let e,l=t[0],s=this.D.ft.root,i=this.V,r=this.attrName.slice(2),o=[];if(Array.isArray(l)&&"function"==typeof l[0])e=l[0],o=l.slice(1);else{if("function"!=typeof l)throw Error(`Invalid event binding: <${i.tagName.toLowerCase()} ${this.attrName}=\${${JSON.stringify(l)}}>`);e=l}this.nt(i,s,r,r,e,o)}}class PathToAttribs extends Path{ut;constructor(t,e){super(null,null),this.V=e,this.ut=new Set}apply(t,e){let l=t[0],s=this.V;Array.isArray(l)&&(l=l.flat().join(" "));let i=this.ut;if(this.ut=new Set,l)if("function"==typeof l&&(Globals$1.t=this,this.K=l,l=l(),Globals$1.t=null),"object"==typeof l)for(let t in l){let e=l[t];void 0!==e&&!1!==e&&null!==e&&(s.setAttribute(t,e),this.ut.add(t))}else{let t=(l+"").split(/([\w-]+\s*=\s*(?:"[^"]*"|'[^']*'|\S+))/g).map((t=>t.trim())).filter((t=>t.length));for(let e of t){let[t,l]=e.split(/\s*=\s*/);l=(l||"").replace(/^(['"])(.*)\1$/,"$2"),s.setAttribute(t,l),this.ut.add(t)}}for(let t of i)this.ut.has(t)||s.removeAttribute(t)}q(){return 1}}const udomdiff=(t,e,l,s)=>{const i=l.length;let r=e.length,o=i,n=0,a=0,h=null;for(;r>n||o>a;)if(r===n){const e=i>o?a?l[a-1].nextSibling:l[o-a]:s;for(;o>a;){let s=l[a++];t.insertBefore(s,e)}}else if(o===a)for(;r>n;){let l=e[n];h&&h.has(l)||t.removeChild(l),n++}else if(e[n]===l[a])n++,a++;else if(e[r-1]===l[o-1])r--,o--;else if(e[n]===l[o-1]&&l[a]===e[r-1]){const s=e[--r].nextSibling;let i=l[a++],h=e[n++];t.insertBefore(i,h.nextSibling);let f=l[--o];t.insertBefore(f,s),e[r]=l[o]}else{if(!h){h=new Map;let t=a;for(;o>t;)h.set(l[t],t++)}if(h.has(e[n])){const s=h.get(e[n]);if(s>a&&o>s){let i=n,f=1;for(;++i<r&&o>i&&h.get(e[i])===s+f;)f++;if(f>s-a){const i=e[n];for(;s>a;){let e=l[a++];t.insertBefore(e,i)}}else{let s=e[n++],i=l[a++];t.replaceChild(i,s)}}else n++}else{let l=e[n++];t.removeChild(l)}}return l};class MultiValueMap{data={};add(t,e){let l=this.data,s=l[t];s||(s=new Set,l[t]=s),s.add(e)}ct(){for(let t in this.data)return!0;return!1}getAll(t){return this.data[t]||[]}delete(t,e=void 0){let l,s=this.data,i=s[t];if(i)return void 0===e?([l]=i,i.delete(l)):(i.delete(e),l=e),0===i.size&&delete s[t],l}dt(t){let e,l=this.data,s=l[t];if(s)return[e]=s,s.delete(e),0===s.size&&delete l[t],e}bt(t,e){let l,s=this.data,i=s[t];if(i)return i.delete(e),l=e,0===i.size&&delete s[t],l}yt(t){let e=this.data,l=[];for(let s in e)e[s].has(t)&&l.push(s);return l}}class PathToNodes extends Path{gt;$t=[];Et=new MultiValueMap;vt=new MultiValueMap;constructor(t,e){super(t,e)}apply(t,e=!0){let l=this,s=t[0];e&&l.Tt();let i=[],r=l.W,o=[];l.W=[],l.Pt(s,i,o);let n=!1;if(o.length){for(let[t,e]of o){let s=l.Gt(i[t],!1),r=s.lt();1===r.length?i[t]=r[0]:(i[t]=r,n=!0),l.W[e]=s}n&&(i=i.flat())}let a=l.lt();if(!Util.T(a,i)){l.Z=i,this.D.wt&&this.D.wt.At(),a.length&&!i.length&&l.Nt()||udomdiff(l.V.parentNode,a,i,l.V);for(let t of r)t.St.parentNode||Util.k(t.lt())}}Pt(t,e,l){if(t instanceof Template){let s=this.Gt(t,!0);if(s){let l=s.lt();return e.push(...l),s.Ot(t.exprs,!1,!1),this.W.push(s),s}l.push([e.length,this.W.length]),e.push(t),this.W.push(null)}else t instanceof NodeList?e.push(...t):t?.nodeType?11===t?.nodeType?e.push(...t.childNodes):e.push(t):this.Ht(t,(t=>{this.Pt(t,e,l)}))}Ct(t){let e=Math.min(t.xt,t.items.length),l=t.xt-e;for(let l=0;e>l;l++){let e=this.W[t.index+l],s=(this.gt||this.K)(t.items[l]);this.Ht(s,(s=>{let i=this.Gt(s,!0);if(i&&i===e);else{i||(i=this.Gt(s,!1)),this.W[t.index+l]=i;let r=e.St;for(let t of i.lt())r.parentNode.insertBefore(t,r);i!==e&&Util.k(e.lt())}}))}if(l>0){for(let s=0;l>s;s++)Util.k(this.W[t.index+e+s].lt());this.W.splice(t.index+e,l)}else{let l=t.items.slice(e),s=this.W[t.index+e]?.St||this.V;for(let t=0;l.length>t;t++){let e=this.gt(l[t]),i=this.Gt(e,!0);i||(i=this.Gt(e,!1)),this.W.push(i);for(let t of i.lt())s.parentNode.insertBefore(t,s)}}this.Z=null}At(){let t=this,e=this.V.parentNode;for(;t&&t.V.parentNode===e;)t.Z=null,t=t.D?.wt}Nt(){let t=this.J.parentNode;return this.J===t.firstChild&&this.V===t.lastChild&&(t.innerHTML="",t.append(this.J,this.V),!0)}Ht(t,e){if(Array.isArray(t))for(let l of t)this.Ht(l,e);else if("function"==typeof t)Globals$1.t=this,this.K=t,t=t(),Globals$1.t=null,this.Ht(t,e);else if(t instanceof Template||t?.nodeType)e(t);else{void 0===t||!1===t||null===t?t="":"string"!=typeof t&&(t+="");let l=new Template([t],[]);l.jt=!0,this.Ht(l,e)}}Gt(t,e=!0){let l,s=this.Et;if(e){if(l=s.dt(t.Ut()),l||(s=this.vt,l=s.dt(t.Ut())),!l)return null;s.bt(t.Mt(),l)}else t.exprs.length&&(l=s.dt(t.Mt()),l||(s=this.vt,l=s.dt(t.Mt())),l&&(s.bt(l.Lt,l),l.Ot(t.exprs),l.Lt=t.Ut()));return l||(l=new NodeGroup(t,this),l.Ot(t.exprs),l.Lt=t.Ut()),this.$t.push(l),l}Tt(){let t=this.Et.data,e=this.vt.data;for(let l in t){let s=e[l];if(s)for(let e of t[l])s.add(e);else e[l]=t[l]}this.Et=new MultiValueMap;let l=this.Et;for(let t of this.$t)l.add(t.Lt,t),l.add(t.It,t);this.$t=[]}lt(){let t;if(t=this.Z,t)return t;t=[];let e=this.J.nextSibling,l=this.V;for(;e&&e!==l;)t.push(e),e=e.nextSibling;return this.Z=t,t}}class PathToComponent extends Path{Rt;constructor(t,e){super(null,e)}apply(t,e=!0,l=!0){let s=this.V,i=Util.P(s,"_is");for(let e,l=0;e=this.Rt[l];l++)i[Util.G(e.attrName)]=e.ht(t[l]);let r=s.getAttribute("_is");if(s.tagName.endsWith("-SOLARITE-PLACEHOLDER")||r){let e=(r||s.tagName.slice(0,-21)).toLowerCase(),o=customElements.get(e);if(!o)throw Error(`Must call customElements.define('${e}', Class) before using it.`);Globals$1.l=[...s.childNodes];let n=new o(i);r&&n.setAttribute("is",r);for(let t of s.attributes)"_is"!==t.name&&n.setAttribute(t.name,t.value);for(let t in i){let e=i[t],l=typeof e;"boolean"===l?!1!==e&&null!=e&&n.setAttribute(t,""):"string"!==l&&"number"!==l&&"bigint"!==l||n.setAttribute(t,e)}let a=n.getAttribute("data-id")||n.getAttribute("id");a&&delve(this.D.getRootNode(),a.split(/\./g),n);let h=this.D;this.V=n;for(let t of h.kt)t.V===s&&(t.V=n),t.J===s&&(t.J=n);h.St===s&&(h.St=n),h.Ft===s&&(h.Ft=n),"function"!=typeof n.render||Globals$1.$.has(n)||n.render(i,l);for(let e,l=0;e=this.Rt[l];l++)e.D=this.D,e.V=n,e.apply(t[l]);s.replaceWith(n)}else"function"==typeof s.render&&s.render(i,l);Globals$1.l=null}clone(t,e=0){let l=this.X(t,e),s=new PathToComponent(null,l);return s.Rt=this.Rt.map((l=>l.clone(t,e))),s}q(){return 0}}class Shell{fragment;kt=[];Jt=[];scripts=[];Vt=[];constructor(t=null){if(!t)return;if(1===t.length&&!t[0].match(/[<&]/))return void(this.fragment=Globals$1.i.createTextNode(t[0]));let e,l=Shell.Dt(t),s=Globals$1.i.createElement("template");l?s.innerHTML=l:s.content.append(Globals$1.i.createTextNode("")),this.fragment=s.content;let i=[],r=0;const o=Globals$1.i.createTreeWalker(this.fragment,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_TEXT);for(;e=o.nextNode();)if(i.map((t=>t.remove())),i=[],1===e.nodeType){const t=e.hasAttribute("is"),l=t||e.tagName.includes("-"),s=[];for(let t of[...e.attributes]){let i=t.name.match(/^[\ue000-\uf8ff]$/);if(i){let t=new PathToAttribs(null,e);this.kt.push(t),l&&s.push(t),r++,e.removeAttribute(i[0])}else{let i=t.value.split(/[\ue000-\uf8ff]/g);if(i.length>1){let o=2!==i.length||i[0].length||i[1].length?i:null,n=Util.j(t.name)?new PathToEvent(null,e,t.name,o):new PathToAttribValue(null,e,t.name,o);n.et=Util.U(e,t.name),this.kt.push(n),l&&(n.tt=!0,s.push(n)),r+=i.length-1,e.setAttribute(t.name,i.join(""))}}}if(l){let l=new PathToComponent(null,e);l.Rt=s,this.kt.splice(this.kt.length-s.length,0,l),t&&(e.setAttribute("_is",e.getAttribute("is")),e.removeAttribute("is"))}}else if(8===e.nodeType&&"!✨!"===e.nodeValue){if(e?.parentNode?.closest&&e?.parentNode?.closest("[contenteditable]"))throw Error('Contenteditable can\'t have expressions inside them. Use <div contenteditable value="${...}"> instead.');let t,l=e.previousSibling;l||(l=Globals$1.i.createComment("Path:"+this.kt.length),e.parentNode.insertBefore(l,e)),!e.nextSibling||8===e.nextSibling.nodeType&&"!✨!"===e.nextSibling.textContent?(t=e,t.textContent="PathEnd:"+this.kt.length):(t=e.nextSibling,i.push(e));let s=new PathToNodes(l,t);this.kt.push(s),r++}else{if(3===e.nodeType&&"TEXTAREA"===e.parentNode?.tagName&&e.textContent.includes("\x3c!--!✨!--\x3e"))throw Error('Textarea can\'t have expressions inside them. Use <textarea value="${...}"> instead.');if(8===e.nodeType){let t=e.textContent.split(/[\ue000-\uf8ff]/g);for(let l=0;t.length-1>l;l++){let t=new Path(e.previousSibling,e);this.kt.push(t),r++}}else if(3===e.nodeType&&["SCRIPT","STYLE"].includes(e.parentNode?.nodeName)){let t=e.textContent.split(commentPlaceholder);if(t.length>1){let l=[];for(let s=0;t.length>s;s++){let i=Globals$1.i.createTextNode(t[s]);e.parentNode.insertBefore(i,e),s>0&&l.push(i)}for(let t,e=0;t=l[e];e++){let e=new PathToNodes(t.previousSibling,t);this.kt.push(e),r++}i.push(e)}}}if(i.map((t=>t.remove())),r!==t.length-1)throw Error("Could not parse expressions in template. Check for duplicate attributes or malformed html: "+t.join("${...}"));for(let t of this.kt)t.J&&(t._=[].indexOf.call(t.J.parentNode.childNodes,t.J)),t.B=Path.get(t.V);this.zt()}static Dt(t){let e=[],l=new HtmlParser;for(let s=0;t.length>s;s++){let i=0,r=l.parse(t[s],((t,l,s)=>{if(i!==l){let r=t.slice(i,l);s===HtmlParser.rt&&(r=r.replace(/^<\/?[a-z][a-z0-9]*-[a-z0-9-]+/i,(t=>t+"-SOLARITE-PLACEHOLDER"))),e.push(r)}i=l}));t.length-1>s&&e.push(r===HtmlParser.Text?commentPlaceholder:String.fromCharCode(attribPlaceholder+s))}return e.join("")}zt(){this.scripts=[].map.call(this.fragment.querySelectorAll("scripts"),(t=>Path.get(t))),this.Vt=[].map.call(this.fragment.querySelectorAll("style"),(t=>Path.get(t)));let t=this.fragment.querySelectorAll("[id],[data-id]");for(let e of t){let t=e.getAttribute("data-id")||e.getAttribute("id");if(Globals$1.div.hasOwnProperty(t))throw Error(`<${e.tagName.toLowerCase()} id="${t}"> can't override existing HTMLElement id property.`)}this.Jt=[].map.call(t,(t=>Path.get(t)))}static get(t){let e=Globals$1.v.get(t);return e||(e=new Shell(t),Globals$1.v.set(t,e)),e}}const commentPlaceholder="\x3c!--!✨!--\x3e",attribPlaceholder=57344;class NodeGroup{ft;wt;St;Ft;kt=[];Lt;It;Z;Vt;Wt;root;constructor(t,e=null,l=null,s=null){if(this.ft=e?.D?.ft||this,this.wt=e,this.Wt=t,this.It=t.Mt(),t.jt)this.St=this.Ft=Globals$1.i.createTextNode(t.html[0]);else{const e=Shell.get(t.html),i=e.fragment.cloneNode(!0);if(11===i.nodeType?(this.St=i.firstChild,this.Ft=i.lastChild):this.St=this.Ft=i,this instanceof RootNodeGroup){let t=0;if(this.options=s,i instanceof Text){if(!l)throw Error("Cannot create a standalone text node");this.root=l,i.nodeValue.length&&this.root.append(i)}else{if(l){let e;if(this.root=l,(Globals$1.l||l.childNodes.length)&&(e=Globals$1.i.createDocumentFragment(),e.append(...Globals$1.l||l.childNodes)),isReplaceEl(i,this.root.tagName)){this.root.append(...i.children[0].childNodes);for(let t of i.children[0].attributes)this.root.hasAttribute(t.name)||this.root.setAttribute(t.name,t.value);t=1}else 1===i.childNodes.length&&3===i.childNodes[0].nodeType&&""===i.childNodes[0].textContent||this.root.append(...i.childNodes);if(e){for(let t of l.querySelectorAll("slot[name]")){let l=t.getAttribute("name");if(l){let s=e.querySelectorAll(`[slot='${l}']`);t.append(...s)}}let t=l.querySelector("slot:not([name])");t?t.append(e):l.append(e)}}else{let e=getSingleEl(i);this.root=e||i,e&&(t=1)}this.Zt(this.root,e.kt,t),this._t(this.root,e,t)}this.St=this.Ft=this.root,Globals$1.p.set(this.root,this)}else e&&(e.kt.length&&this.Zt(i,e.kt),this._t(i,e))}}Ot(t,e=!0,l=!0){let s=this.kt,i=t.length,r=Array(s.length);for(let o,n=s.length-1;o=s[n];n--){if(0===n&&o instanceof PathToComponent&&o.V===this.getRootNode())continue;let s=o.q();if(r[n]=t.slice(i-s,i),i-=s,o instanceof PathToComponent){let t=r.slice(n+1,n+1+o.Rt.length);o.apply(t,!0,e)}else l&&o.apply(r[n])}l&&(this.Bt(),this.Z=null)}Kt(t){}lt(){let t=this.Z;if(t)return t;t=[];let e=this.St,l=this.Ft?.nextSibling;for(;e&&e!==l;)t.push(e),e=e.nextSibling;return this.Z=t,t}getRootNode(){return this.ft.root}qt(){return this.ft}Zt(t,e,l=0){let s=e.length;this.kt.length=s;for(let i=0;s>i;i++){let s=e[i].clone(t,l);s.D=this,this.kt[i]=s}}Bt(){if(this.Vt)for(let[t,e]of this.Vt)e!==t.textContent&&Util.N(t,this.qt().root)}_t(root,shell,pathOffset=0){let rootEl=this.ft.root;if(rootEl){let options=this.ft.options;if(!1!==options?.Jt)for(let t of shell.Jt){pathOffset&&(t=t.slice(0,-pathOffset));let e=Path.resolve(root,t);Util.A(rootEl,e)}if(!1!==options?.Vt){shell.Vt.length&&(this.Vt=new Map);for(let t of shell.Vt){pathOffset&&(t=t.slice(0,-pathOffset));let e=Path.resolve(root,t);1===rootEl.nodeType&&(Util.N(e,rootEl),this.Vt.set(e,e.textContent))}}if(!1!==options?.scripts)for(let path of shell.scripts){pathOffset&&(path=path.slice(0,-pathOffset));let script=Path.resolve(root,path);eval(script.textContent)}}}}function getSingleEl(t){let e=[];for(let l of t.childNodes)if(1===l.nodeType||3===l.nodeType&&l.textContent.trim().length){if(e.length)return null;e.push(l)}return e[0]}function isReplaceEl(t,e){return 1===t.children.length&&e.includes("-")&&t.children[0].tagName.replace("-SOLARITE-PLACEHOLDER","")===e}class RootNodeGroup extends NodeGroup{Xt}class Template{exprs=[];html=[];Yt;jt;constructor(t=[""],e=[]){this.html=t,this.exprs=e}toJSON(){return void 0===this.Yt&&(this.Yt=[getObjectId(this.html),this.exprs]),this.Yt}render(t=null,e={}){let l=t&&Globals$1.p.get(t);if(l||(l=new RootNodeGroup(this,null,t,e),t||(t=l.getRootNode()),Globals$1.p.set(t,l)),1!==this.html?.length||this.html[0]){let t=l.Lt,e=this.Ut();l.Ot(this.exprs,t!==e),l.Lt=e}else t.innerHTML="";return l.Xt=new Map,t}Ut(){return void 0===this.Lt&&(this.Lt=this.exprs.length?getObjectHash(this):this.html[0]),this.Lt}Mt(){return void 0===this.It&&(this.It=this.exprs.length?this.toJSON()[0]:this.html[0]),this.It}static Qt(t,e,l){const s=selfClosingTags.has(t.toLowerCase());let i=[],r=[],o="<"+t;if(e&&"object"==typeof e)for(let t in e){let l=e[t];"id"!==t&&"data-id"!==t?(o+=` ${t}=`,i.push(o),r.push(l),o=""):o+=` ${t}="${l}"`}if(!s){i.push(i.length>0?'"'===o?'">':">":o+">");for(let t of l)addChild(t,i,r)}return s?i.push(i.length>0?">":o+">"):i[i.length-1]+=`</${t}>`,new Template(i,r)}}const selfClosingTags=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),addChild=(t,e,l)=>{if(Array.isArray(t))for(let s of t)addChild(s,e,l);else{let s=!1;if(t instanceof Template)if(t.exprs.length>0)s=!0;else{const e=(t.html[0]||"").match(/^<([a-zA-Z][\w:-]*)/),l=e?e[1].toLowerCase():"";s=selfClosingTags.has(l)}if(s){e[e.length-1]+=t.html[0];for(let s=0;t.exprs.length>s;s++)l.push(t.exprs[s]),e.push(t.html[s+1]??"")}else l.push(t),e.push("")}};function toEl(t){if("string"==typeof t){let e=t;(e.match(/^\s^<\S+/)||e.match(/\S+>\s+$/))&&(e=e.trim());let l=Globals$1.i.createElement("template");l.innerHTML=e;let s=Util.F(l.content.childNodes);return 1===s.length?s[0]:l.content}if(t instanceof Template)return t.render();if(t&&"object"==typeof t){let e=t;if("Object"!==e.constructor.name)throw Error(`Solarate Web Component class ${e.constructor?.name} must extend HTMLElement.`);if(!Globals$1.m.has(e)){Globals$1.m.set(e,null),e[renderF]();let t=Globals$1.m.get(e);Globals$1.m.delete(e);for(let l in e)t[l]="function"==typeof e[l]?e[l].bind(t):e[l];return t}}throw Error("toEl() does not support argument of type: "+(t?typeof t:t))}let renderF="render";function h(t=void 0,...e){if(Array.isArray(arguments[0]))return new Template(arguments[0],e);if("string"==typeof arguments[0]||arguments[0]instanceof String){let t=arguments[0];if(!e.length||"object"!=typeof e[0]&&null!==e[0]){let e=t;return e.match(/^\s^</)&&(e=e.trim()),new Template([e],[])}{let l=t+"",s=e[0]||{},i=e.slice(1);return Template.Qt(l,s,i)}}if(arguments[0]instanceof HTMLElement||arguments[0]instanceof DocumentFragment){if(!(arguments[1]instanceof Template)){let t=arguments[0],e=arguments[1];t.shadowRoot&&(t.innerHTML="");let l=(l,...s)=>(Globals$1.$.add(t),new Template(l,s).render(t,e));return l}arguments[1].render(arguments[0],arguments[2])}else{if(!arguments.length)return(t,...e)=>toEl(h(t,...e));if("object"!=typeof arguments[0]||!Globals$1.m.has(arguments[0])){if(Util.L(arguments[0]))return new Template;throw Error("h() does not support argument of type: "+(arguments[0]?typeof arguments[0]:arguments[0]))}{let t=arguments[0];if("Object"!==t.constructor.name)throw Error(`Solarate Web Component class ${t.constructor?.name} must extend HTMLElement.`);if(!(arguments[1]instanceof Template))return((...e)=>{let l=h(...e).render();Globals$1.m.set(t,l)}).bind(t);{let e=arguments[1].render();Globals$1.m.set(t,e)}}}}function getArg(el,attributeName,defaultValue=void 0,type=ArgType.String){let val=defaultValue,attrVal=el.getAttribute(attributeName)||el.getAttribute(Util.O(attributeName));if(null!==attrVal&&(val=attrVal),Array.isArray(type))return type.includes(val)?val:void 0;if("function"==typeof type)return type.constructor?new type(val):type(val);if(type===ArgType.te){let t="string"==typeof val?val.toLowerCase():val;return!["false","0",!1,0,null,void 0,NaN].includes(t)&&(!(!["true",!0].includes(t)&&0===parseFloat(t))||void 0)}switch(type){case ArgType.ee:return parseInt(val);case ArgType.le:return parseFloat(val);case ArgType.String:return[void 0,null,!1].includes(val)?"":val+"";case ArgType.se:case ArgType.ie:if("string"!=typeof val||!val.length)return val;try{return type===ArgType.se?JSON.parse(val):eval(`(${val})`)}catch(t){return val}default:return val}}function setArgs(t,e,l){for(let s in e)this[s]=getArg(t,s,e[s],l[s]||ArgType.String)}var ArgType={te:"Bool",ee:"Int",le:"Float",String:"String",JSON:"Json",se:"Json",ie:"Eval"};function t(t){return new Template([t],[])}let HTMLElementAutoDefine=new Proxy(HTMLElement,{construct:(t,e,l)=>(Util.H(l),Reflect.construct(t,e,l))});class Solarite extends HTMLElementAutoDefine{constructor(t=null){if(super(),t){if("object"!=typeof t)throw Error("First argument to custom element constructor must be an object.");if(t&&!Object.keys(t).length){let e=Solarite.getAttribs(this);for(let l in e)t[l]=e[l]}}}render(){throw Error("render() is not defined for "+this.constructor.name)}renderFirstTime(){if(!Globals$1.$.has(this)){let t=Solarite.getAttribs(this);this.render(t)}}connectedCallback(){this.renderFirstTime()}static define(t=null){Util.H(this,t)}static getAttribs(t){let e=Util.P(t);for(let t in e){let l=e[t];l.startsWith("${")&&l.endsWith("}")&&(e[t]=JSON.parse(l.slice(2,-1)))}return e}}export default h;export{ArgType,Globals$1 as Globals,HtmlParser,NodeGroup,Shell,Solarite,Util as SolariteUtil,Template,delve,getArg,h,h as r,setArgs,t,toEl};
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solarite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Solarite is a small (9KB min+gzip), fast, compilation-free JavaScript library for adding reactivity to native web components, so that updates require minimal re-rendering.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/Solarite.js",
|
|
7
|
+
"module": "dist/Solarite.js",
|
|
8
|
+
"types": "src/Solarite.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/Solarite.d.ts",
|
|
12
|
+
"import": "./dist/Solarite.js",
|
|
13
|
+
"default": "./dist/Solarite.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
6
16
|
"files": [
|
|
7
17
|
"readme.md",
|
|
8
18
|
"dist",
|
package/src/Globals.js
CHANGED
|
@@ -5,25 +5,25 @@ var Globals;
|
|
|
5
5
|
function reset() {
|
|
6
6
|
Globals = {
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Dynamic values that should be passed to a Component's constructor and render() function.
|
|
10
|
-
* @type {Map<HTMLElement, any[]>} */
|
|
11
|
-
componentArgs: new Map(),
|
|
12
|
-
|
|
13
8
|
/**
|
|
14
9
|
* Store which instances of Solarite have already been added to the DOM.
|
|
15
10
|
* @type {WeakSet<HTMLElement>} */
|
|
16
11
|
connected: new WeakSet(),
|
|
17
12
|
|
|
18
13
|
/**
|
|
19
|
-
*
|
|
20
|
-
* watch() then adds the
|
|
21
|
-
* @type {
|
|
22
|
-
|
|
14
|
+
* Path.applyExactNodes() sets this property when an expression is being accessed.
|
|
15
|
+
* watch() then adds the Path to the list of Paths that should be re-rendered when the value changes.
|
|
16
|
+
* @type {Path}*/
|
|
17
|
+
currentPath: null,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Set by NodeGroup.instantiateComponent()
|
|
21
|
+
* Used by RootNodeGroup.getSlotChildren(). */
|
|
22
|
+
currentSlotChildren: null,
|
|
23
23
|
|
|
24
24
|
div: document.createElement("div"),
|
|
25
25
|
|
|
26
|
-
/** @type {HTMLDocument} */
|
|
26
|
+
/** @type {HTMLDocument} The global document. */
|
|
27
27
|
doc: document,
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -34,33 +34,25 @@ function reset() {
|
|
|
34
34
|
htmlProps: {},
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* Used by
|
|
37
|
+
* Used by Path.applyEventAttrib()
|
|
38
38
|
* @type {WeakMap<Node, Record<eventName:string, [original:function, bound:function, args:*[]]>>} */
|
|
39
39
|
nodeEvents: new WeakMap(),
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Get the RootNodeGroup for an element.
|
|
43
43
|
* @type {WeakMap<HTMLElement, RootNodeGroup>} */
|
|
44
|
-
|
|
44
|
+
rootNodeGroups: new WeakMap(),
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Used by h() path 9. */
|
|
48
48
|
objToEl: new WeakMap(),
|
|
49
49
|
|
|
50
|
-
//pendingChildren: [],
|
|
51
|
-
|
|
52
|
-
|
|
53
50
|
/**
|
|
54
51
|
* Elements that have been rendered to by h() at least once.
|
|
55
52
|
* This is used by the Solarite class to know when to call onFirstConnect()
|
|
56
53
|
* @type {WeakSet<HTMLElement>} */
|
|
57
54
|
rendered: new WeakSet(),
|
|
58
55
|
|
|
59
|
-
/**
|
|
60
|
-
* Elements that are currently rendering via the h() function.
|
|
61
|
-
* @type {WeakSet<HTMLElement>} */
|
|
62
|
-
rendering: new WeakSet(),
|
|
63
|
-
|
|
64
56
|
/**
|
|
65
57
|
* Map from array of Html strings to a Shell created from them.
|
|
66
58
|
* @type {WeakMap<string[], Shell>} */
|
|
@@ -69,13 +61,11 @@ function reset() {
|
|
|
69
61
|
/**
|
|
70
62
|
* A map of individual untagged strings to their Templates.
|
|
71
63
|
* This way we don't keep creating new Templates for the same string when re-rendering.
|
|
72
|
-
* This is used by
|
|
64
|
+
* This is used by Path.applyExactNodes()
|
|
73
65
|
* @type {Record<string, Template>} */
|
|
74
66
|
//stringTemplates: {},
|
|
75
67
|
|
|
76
|
-
reset
|
|
77
|
-
|
|
78
|
-
count: 0
|
|
68
|
+
reset
|
|
79
69
|
};
|
|
80
70
|
}
|
|
81
71
|
reset();
|
package/src/HtmlParser.js
CHANGED
|
@@ -18,7 +18,7 @@ export default class HtmlParser {
|
|
|
18
18
|
/**
|
|
19
19
|
* Parse the next chunk of html, starting with the same context we left off with from the previous chunk.
|
|
20
20
|
* @param html {string}
|
|
21
|
-
* @param onContextChange {?function(html:string, index:int,
|
|
21
|
+
* @param onContextChange {?function(html:string, index:int, prevContext:string, nextContext:string)}
|
|
22
22
|
* Called every time the context changes, and again at the last context.
|
|
23
23
|
* @return {('Attribute','Text','Tag')} The context at the end of html. */
|
|
24
24
|
parse(html, onContextChange=null) {
|
package/src/MultiValueMap.js
CHANGED
|
@@ -42,7 +42,7 @@ export default class MultiValueMap {
|
|
|
42
42
|
|
|
43
43
|
// Delete any value.
|
|
44
44
|
if (val === undefined) {
|
|
45
|
-
[result] = set; //
|
|
45
|
+
[result] = set; // Get the first value from the set.
|
|
46
46
|
set.delete(result);
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -59,7 +59,7 @@ export default class MultiValueMap {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Remove one value from a key, and return it.
|
|
62
|
+
* Remove any one value from a key, and return it.
|
|
63
63
|
* @param key {string}
|
|
64
64
|
* @returns {*|undefined} The deleted item. */
|
|
65
65
|
deleteAny(key) {
|
|
@@ -69,7 +69,7 @@ export default class MultiValueMap {
|
|
|
69
69
|
if (!set) // slower than pre-check.
|
|
70
70
|
return undefined;
|
|
71
71
|
|
|
72
|
-
[result] = set; //
|
|
72
|
+
[result] = set; // Get the first value from the set.
|
|
73
73
|
set.delete(result);
|
|
74
74
|
|
|
75
75
|
if (set.size === 0)
|