solarite 0.5.2 → 0.7.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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Solarite-debug.js +2823 -1856
  3. package/dist/Solarite.js +2779 -1824
  4. package/dist/Solarite.min.js +2 -4
  5. package/package.json +16 -3
  6. package/readme.md +58 -11
  7. package/src/Globals.js +54 -72
  8. package/src/HtmlParser.js +90 -90
  9. package/src/MultiValueMap.js +57 -105
  10. package/src/NodeGroup.js +624 -470
  11. package/src/Path.js +224 -211
  12. package/src/PathToAttribValue.js +401 -261
  13. package/src/PathToAttribs.js +113 -80
  14. package/src/PathToComment.js +7 -7
  15. package/src/PathToComponent.js +183 -188
  16. package/src/PathToEvent.js +76 -64
  17. package/src/PathToKey.js +19 -0
  18. package/src/PathToNodes.js +1053 -566
  19. package/src/RootNodeGroup.js +120 -8
  20. package/src/Shell.js +570 -348
  21. package/src/Solarite.d.ts +134 -113
  22. package/src/Solarite.js +243 -286
  23. package/src/Template.js +195 -274
  24. package/src/Util.js +353 -351
  25. package/src/assert.js +10 -10
  26. package/src/assignAttributes.js +63 -0
  27. package/src/delve.js +55 -43
  28. package/src/h.js +220 -138
  29. package/src/jsx-dev-runtime.d.ts +1 -0
  30. package/src/jsx-dev-runtime.js +5 -0
  31. package/src/jsx-runtime.d.ts +21 -0
  32. package/src/jsx-runtime.js +84 -0
  33. package/src/jsx.js +194 -0
  34. package/src/toEl.js +77 -82
  35. package/dist/udomdiff-license.txt +0 -18
  36. package/src/getArg.js +0 -137
  37. package/src/hash.js +0 -89
  38. package/src/udomdiff.js +0 -176
  39. package/src/unused/FastLookupArray.js +0 -54
  40. package/src/unused/Hashes.js +0 -339
  41. package/src/unused/InUse.test.js +0 -92
  42. package/src/unused/InUseMap.js +0 -98
  43. package/src/unused/LinkedList.js +0 -117
  44. package/src/unused/LinkedList.test.js +0 -115
  45. package/src/unused/Misc.js +0 -13
  46. package/src/unused/Perf.js +0 -47
  47. package/src/unused/TrackedArray.js +0 -54
  48. package/src/unused/WeakArray.js +0 -33
  49. package/src/watch.js +0 -543
@@ -1,4 +1,2 @@
1
- // Version 0.5.2
2
- // License: MIT
3
- // http://vorticode.github.io/solarite
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())),C(t,e){customElements[getName](t)||((e=e||Util.O(t.name)).includes("-")||(e+="-element"),customElements[define](e,t))},H: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{V;J;D;W=[];K;Z;_;B;constructor(t,e){this.V=t,this.J=e}apply(t,e=!0){}q(){return 1}X(t,e){let l=t,s=this._,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._,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.V&&(s=n[this.Z]);let a=new this.constructor(s,l,this.attrName,this.Y);return a.tt=this.tt,a.et=this.et,a}lt(){return[this.J]}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;nt;et;constructor(t,e,l=null,s=null){super(null,e),this.attrName=l,this.Y=s}apply(t){let e=this.J,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.H(e):e[this.attrName];delve(t,s,l)};this.ht(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.B=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.ft(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}ft(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("")}ht(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.Y?.length>1)return void super.apply(t);if(this.tt&&this.J.tagName.endsWith("-SOLARITE-PLACEHOLDER"))return;let e,l=t[0],s=this.D.ut.root,i=this.J,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.ht(i,s,r,r,e,o)}}class PathToAttribs extends Path{ct;nt;constructor(t,e){super(null,null),this.J=e,this.ct=new Set}apply(t,e){let l=t[0],s=this.J;Array.isArray(l)&&(l=l.flat().join(" "));let i=this.ct;if(this.ct=new Set,l)if("function"==typeof l&&(Globals$1.t=this,this.B=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.ct.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.ct.add(t)}}for(let t of i)this.ct.has(t)||s.removeAttribute(t)}q(){return 1}ft(t){return t[0]}}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)}dt(){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}bt(t){let e,l=this.data,s=l[t];if(s)return[e]=s,s.delete(e),0===s.size&&delete l[t],e}yt(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}gt(t){let e=this.data,l=[];for(let s in e)e[s].has(t)&&l.push(s);return l}}class PathToNodes extends Path{$t;Et=[];vt=new MultiValueMap;Tt=new MultiValueMap;constructor(t,e){super(t,e)}apply(t,e=!0){let l=this,s=t[0];e&&l.Pt();let i=[],r=l.W,o=[];l.W=[],l.wt(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.K=i,this.D.At&&this.D.At.Nt(),a.length&&!i.length&&l.St()||udomdiff(l.J.parentNode,a,i,l.J);for(let t of r)t.Ot.parentNode||Util.k(t.lt())}}wt(t,e,l){if(t instanceof Template){let s=this.Gt(t,!0);if(s){let l=s.lt();return e.push(...l),s.Ct(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.wt(t,e,l)}))}xt(t){let e=Math.min(t.jt,t.items.length),l=t.jt-e;for(let l=0;e>l;l++){let e=this.W[t.index+l],s=(this.$t||this.B)(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.Ot;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]?.Ot||this.J;for(let t=0;l.length>t;t++){let e=this.$t(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.K=null}Nt(){let t=this,e=this.J.parentNode;for(;t&&t.J.parentNode===e;)t.K=null,t=t.D?.At}St(){let t=this.V.parentNode;return this.V===t.firstChild&&this.J===t.lastChild&&(t.innerHTML="",t.append(this.V,this.J),!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.B=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.Ut=!0,this.Ht(l,e)}}Gt(t,e=!0){let l,s=this.vt;if(e){if(l=s.bt(t.Mt()),l||(s=this.Tt,l=s.bt(t.Mt())),!l)return null;s.yt(t.Lt(),l)}else t.exprs.length&&(l=s.bt(t.Lt()),l||(s=this.Tt,l=s.bt(t.Lt())),l&&(s.yt(l.It,l),l.Ct(t.exprs),l.It=t.Mt()));return l||(l=new NodeGroup(t,this),l.Ct(t.exprs),l.It=t.Mt()),this.Et.push(l),l}Pt(){let t=this.vt.data,e=this.Tt.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.vt=new MultiValueMap;let l=this.vt;for(let t of this.Et)l.add(t.It,t),l.add(t.Rt,t);this.Et=[]}lt(){let t;if(t=this.K,t)return t;t=[];let e=this.V.nextSibling,l=this.J;for(;e&&e!==l;)t.push(e),e=e.nextSibling;return this.K=t,t}}class PathToComponent extends Path{kt;constructor(t,e){super(null,e)}apply(t,e=!0,l=!0){let s=this.J,i=Util.P(s,"_is");for(let e,l=0;e=this.kt[l];l++)if(e instanceof PathToAttribValue)i[Util.G(e.attrName)]=e.ft(t[l]);else{let s=e.ft(t[l]);if("object"==typeof s)for(let t in s)i[Util.G(t)]=s[t];else if("string"==typeof s){let t=s.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"),i[Util.G(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.J=n;for(let t of h.Ft)t.J===s&&(t.J=n),t.V===s&&(t.V=n);h.Ot===s&&(h.Ot=n),h.Vt===s&&(h.Vt=n),"function"!=typeof n.render||Globals$1.$.has(n)||n.render(i,l);for(let e,l=0;e=this.kt[l];l++)e.D=this.D,e.J=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.kt=this.kt.map((l=>l.clone(t,e))),s}q(){return 0}}class Shell{fragment;Ft=[];Jt=[];scripts=[];Dt=[];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.zt(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.Ft.push(t),l&&(t.tt=!0,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.Ft.push(n),l&&(n.tt=!0,s.push(n)),r+=i.length-1;try{e.setAttribute(t.name,i.join(""))}catch(l){throw Error(`Error setting attribute "${t.name}" on node <${e.tagName}>: ${l.message}`)}}}}if(l){let l=new PathToComponent(null,e);l.kt=s,this.Ft.splice(this.Ft.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.Ft.length),e.parentNode.insertBefore(l,e)),!e.nextSibling||8===e.nextSibling.nodeType&&"!✨!"===e.nextSibling.textContent?(t=e,t.textContent="PathEnd:"+this.Ft.length):(t=e.nextSibling,i.push(e));let s=new PathToNodes(l,t);this.Ft.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.Ft.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.Ft.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.Ft)t.V&&(t.Z=[].indexOf.call(t.V.parentNode.childNodes,t.V)),t._=Path.get(t.J);this.Wt()}static zt(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("")}Wt(){this.scripts=[].map.call(this.fragment.querySelectorAll("scripts"),(t=>Path.get(t))),this.Dt=[].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{ut;At;Ot;Vt;Ft=[];It;Rt;K;Dt;Kt;root;constructor(t,e=null,l=null,s=null){if(this.ut=e?.D?.ut||this,this.At=e,this.Kt=t,this.Rt=t.Lt(),t.Ut)this.Ot=this.Vt=Globals$1.i.createTextNode(t.html[0]);else{const e=Shell.get(t.html),i=e.fragment.cloneNode(!0);if(11===i.nodeType?(this.Ot=i.firstChild,this.Vt=i.lastChild):this.Ot=this.Vt=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.Ft,t),this._t(this.root,e,t)}this.Ot=this.Vt=this.root,Globals$1.p.set(this.root,this)}else e&&(e.Ft.length&&this.Zt(i,e.Ft),this._t(i,e))}}Ct(t,e=!0,l=!0){let s=this.Ft,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.J===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.kt.length);o.apply(t,!0,e)}else l&&o.apply(r[n])}l&&(this.Bt(),this.K=null)}qt(t){}lt(){let t=this.K;if(t)return t;t=[];let e=this.Ot,l=this.Vt?.nextSibling;for(;e&&e!==l;)t.push(e),e=e.nextSibling;return this.K=t,t}getRootNode(){return this.ut.root}Xt(){return this.ut}Zt(t,e,l=0){let s=e.length;this.Ft.length=s;for(let i=0;s>i;i++){let s=e[i].clone(t,l);s.D=this,this.Ft[i]=s}}Bt(){if(this.Dt)for(let[t,e]of this.Dt)e!==t.textContent&&Util.N(t,this.Xt().root)}_t(root,shell,pathOffset=0){let rootEl=this.ut.root;if(rootEl){let options=this.ut.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?.Dt){shell.Dt.length&&(this.Dt=new Map);for(let t of shell.Dt){pathOffset&&(t=t.slice(0,-pathOffset));let e=Path.resolve(root,t);1===rootEl.nodeType&&(Util.N(e,rootEl),this.Dt.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{Yt}class Template{exprs=[];html=[];Qt;Rt;It;Ut;constructor(t=[""],e=[]){this.html=t,this.exprs=e}toJSON(){return void 0===this.Qt&&(this.Qt=[getObjectId(this.html),this.exprs]),this.Qt}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.It,e=this.Mt();l.Ct(this.exprs,t!==e),l.It=e}else t.innerHTML="";return l.Yt=new Map,t}Mt(){return void 0===this.It&&(this.It=this.exprs.length?getObjectHash(this):this.html[0]),this.It}Lt(){return void 0===this.Rt&&(this.Rt=this.exprs.length?this.toJSON()[0]:this.html[0]),this.Rt}static te(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.te(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.ee){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.le:return parseInt(val);case ArgType.se:return parseFloat(val);case ArgType.String:return[void 0,null,!1].includes(val)?"":val+"";case ArgType.ie:case ArgType.re:if("string"!=typeof val||!val.length)return val;try{return type===ArgType.ie?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={ee:"Bool",le:"Int",se:"Float",String:"String",JSON:"Json",ie:"Json",re:"Eval"};function t(t){return new Template([t],[])}let HTMLElementAutoDefine=new Proxy(HTMLElement,{construct:(t,e,l)=>(Util.C(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.C(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}}function assignFields(t,e,l=[]){for(let s in e||{})if(s in t&&!l.includes(s)){const l=Object.getOwnPropertyDescriptor(t,s)||Object.getOwnPropertyDescriptor(Object.getPrototypeOf(t),s);if(!l||l.writable||l.set){let l=e[s],i=t[s];t[s]="string"==typeof e[s]?"boolean"==typeof i?![!1,"false",0,"0"].includes(l):"number"==typeof i?+l:i instanceof Date?new Date(l):l:l}}}export default h;export{ArgType,Globals$1 as Globals,HtmlParser,NodeGroup,Shell,Solarite,Util as SolariteUtil,Template,assignFields,delve,getArg,h,h as r,setArgs,t,toEl};
1
+ // Solarite v0.7.0 | MIT | vorticode.github.io/solarite
2
+ var t;!function e(){t={connected:new WeakSet,t:null,div:document.createElement("div"),i:document,l:{},o:{},h:new WeakMap,u:new WeakMap,p:new WeakSet,m:new WeakMap,reset:e}}();var e=t;function i(t,e,i=l){let s=i!==l,n=e.length;if(!t&&!s&&n)return;let r=0;for(let l of e){if(void 0===t[l]){if(!s)return;n-1>r&&(t[l]=(e[r+1]+"").match(/^\d+$/)?[]:{})}s&&r===n-1&&(t[l]=i),t=t[l],r++}return t}function s(t){return 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))}let l={},n={v(t,e){let i=t.length;if(i!==e.length)return!1;for(let s=0;i>s;s++)if(t[s]!==e[s])return!1;return!0},S(t,e=null){let i={};for(let s of t.attributes)s.name!==e&&(i[n.k(s.name)]=s.value);return i},$(t,e){let s=e.getAttribute("data-id")||e.getAttribute("id");if(s){if(!s.includes(".")){let i=t[s],l=s in t&&!Object.hasOwn(t,s);if(!i?.nodeType&&(null!=i||l))throw Error(`${t.constructor.name}.${s} can't be a reference to <${e.tagName.toLowerCase()} id="${s}"> because it would clobber an existing `+(l?"built-in ":"")+"property. Rename the id or the property.")}i(t,s.split(/\./g),e)}},A(t,i){let s,l,n=i.tagName.toLowerCase();if(t.hasAttribute("global")||t.hasAttribute("data-global")){s=n,l="";let r=e.i||i.ownerDocument||document;r.head.querySelector(`style[data-style="${s}"]`)?t.remove():(r.head.append(t),t.setAttribute("data-style",s))}else{let t=i.getAttribute("data-style");t||(i.constructor.T||(i.constructor.T=1),t=i.constructor.T++,i.setAttribute("data-style",t)),l=`[data-style="${t}"]`}for(let e of t.childNodes)if(3===e.nodeType){let t=e.textContent,i=t.replace(/:host(?=[^a-z0-9_])/gi,`${n}${l}`);t!==i&&(e.textContent=i)}},N: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(),k:t=>t.replace(/-([a-z])/g,(t=>t[1].toUpperCase())),C(t,e){customElements[o](t)||((e=e||n.N(t.name)).includes("-")||(e+="-element"),customElements[r](e,t))},O:t=>"checkbox"===t.type?t.checked:"radio"===t.type?t.value:"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,L:t=>t.startsWith("on")&&t in e.div,j(t,i){let s=t.tagName+"."+i,l=e.o[s];if(void 0===l){let n=Object.getPrototypeOf(t);for(;n;){const t=n.constructor.name;if(t.startsWith("HTML")&&t.endsWith("Element"))break;n=Object.getPrototypeOf(n)}e.o[s]=l=!!n&&!!Object.getOwnPropertyDescriptor(n,i)?.set}return l},P:t=>void 0===t||!1===t||null===t,R(t){let e={},i=(t+"").split(/([\w-]+\s*=\s*(?:"[^"]*"|'[^']*'|\S+))/g).map((t=>t.trim())).filter((t=>t.length));for(let t of i){let[i,s]=t.split(/\s*=\s*/);s=(s||"").replace(/^(['"])(.*)\1$/,"$2"),e[i]=s}return e},M:t=>"function"==typeof t?n.M(t()):t instanceof Date?t.toISOString().replace(/T/," "):Array.isArray(t)||"object"==typeof t?"":t,D(t){e.i.createDocumentFragment().append(...t)},H(t){const e=t=>t.nodeType!==Node.ELEMENT_NODE&&(t.nodeType!==Node.TEXT_NODE||""===t.textContent.trim()),i=[...t];for(;i.length>0&&e(i[0]);)i.shift();for(;i.length>0&&e(i[i.length-1]);)i.pop();return i}},r="define",o="getName";class f{F;G;I=!1;W;J;constructor(t,e){this.F=t,this.G=e}apply(t){}V(t){}_(){return 1}B(t,e){let i=t,s=this.K,l=s.length-e;for(let t=l-1;t>0;t--)i=i.childNodes[s[t]];return l?i.childNodes[s[0]]:t}Z(t,e){let i=new this.constructor(t,e,this.attrName,this.U);return i.q=this.q,i.I=this.I,i.Y=this.Y,i}clone(t,e=0){let i,s,l=t,n=this.K,r=n.length-e;for(let t=r-1;t>0;t--)l=l.childNodes[n[t]];let o=l.childNodes;i=r?o[n[0]]:t,this.F&&(s=o[this.X]);let f=new this.constructor(s,i,this.attrName,this.U);return f.q=this.q,f.I=this.I,f.Y=this.Y,f}static get(t){let e=[];for(;;){let i=t.parentNode;if(!i)break;e.push([].indexOf.call(t.parentNode.childNodes,t)),t=i}return e}static resolve(t,e){for(let i=e.length-1;i>=0;i--)t=t.childNodes[e[i]];return t}}class h{constructor(){this.tt={context:h.Text,quote:null,buffer:"",et:null},this.state={...this.tt}}reset(){return this.state={...this.tt},this.state.context}parse(t,e=null){if(null===t)return this.reset();for(let i=0;t.length>i;i++){const s=t[i];switch(this.state.context){case h.Text:"<"===s&&t[i+1].match(/[/a-z!]/i)&&(e?.(t,i,this.state.context,h.it),this.state.context=h.it,this.state.buffer="");break;case h.it:if(">"===s)e?.(t,i+1,this.state.context,h.Text),this.state.context=h.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,i,this.state.context,h.st),this.state.context=h.st,this.state.quote="="===s?null:s,this.state.buffer=""):this.state.buffer+=s}break;case h.st:this.state.quote||this.state.buffer.length||'"'!==s&&"'"!==s?s===this.state.quote||!this.state.quote&&this.state.buffer.length?(e?.(t,i,this.state.context,h.it),this.state.context=h.it,this.state.quote=null,this.state.buffer=""):this.state.quote||">"!==s?" "!==s&&(this.state.buffer+=s):(e?.(t,i+1,this.state.context,h.Text),this.state.context=h.Text,this.state.quote=null,this.state.buffer=""):this.state.quote=s}}return e?.(t,t.length,this.state.context,null),this.state.context}}h.st="Attribute",h.Text="Text",h.it="Tag";class u extends f{attrName;U;lt;Y;constructor(t,e,i=null,s=null){super(null,e),this.attrName=i,this.U=s}apply(t){if(this.U){let e=this.G,i=this.nt(t),s=this.Y;(s?e[this.attrName]:e.getAttribute(this.attrName))!==i&&(s?e[this.attrName]=i:"value"===this.attrName&&e.hasAttribute("contenteditable")&&(e.innerHTML=i),e.setAttribute(this.attrName,i))}else this.V(t[0])}V(t){if(this.U)return this.apply([t]);let e=this.G;if(s(t)){if(this.q&&e.tagName.endsWith("-SOLARITE-PLACEHOLDER"))return;let[s,l]=[t[0],t.slice(1)];if(!s)throw Error(`Solarite cannot bind to <${e.tagName.toLowerCase()} ${this.attrName}=\${[${t.map((t=>t?`'${t}'`:t+"")).join(", ")}]}>.`);let r=i(s,l);if("value"===this.attrName&&"select-multiple"===e.type&&Array.isArray(r)){let t=r.map((t=>t+""));for(let i of e.options)i.selected=t.includes(i.value)}else if("radio"===e.type)e.checked=e.value===r+"";else{const t=n.P(r)?"":r;"value"===this.attrName&&e.hasAttribute("contenteditable")?t!==e.innerHTML&&(e.innerHTML=t):t!==e[this.attrName]&&(e[this.attrName]=t)}let o=()=>{let t="value"===this.attrName||"radio"===e.type?n.O(e):e[this.attrName];i(s,l,t)};this.rt(e,this.W.getRootNode(),this.attrName,"input",o,null,!0)}else{let i=this.Y;if("function"==typeof t){if(this.q)return;t=t()}else t=n.M(t);void 0===t||!1===t||null===t?(i&&(e[this.attrName]=!1),e.removeAttribute(this.attrName)):!0===t?(i&&(e[this.attrName]=!0),e.setAttribute(this.attrName,"")):(i?e[this.attrName]:e.getAttribute(this.attrName)??"")!==t&&(i?e[this.attrName]=t:"value"===this.attrName&&e.hasAttribute("contenteditable")&&(e.innerHTML=t),e.setAttribute(this.attrName,t))}}_(){return this.U?this.U.length-1:1}nt(t){if(!this.U)return t[0];let e=[],i=this.U;for(let s=0;i.length>s;s++)if(e.push(i[s]),i.length-1>s){let i=n.M(t[s]);n.P(i)||e.push(i)}return e.join("")}rt(t,e,i,s,l,n,r=!1){if("function"!=typeof l)throw Error(`Solarite cannot bind to <${t.tagName.toLowerCase()} ${this.attrName}=\${${l}}> because it's not a function.`);let o,f=this.W.ot.options,h=n||[l],u=t[a];if(void 0!==u){if(u instanceof g){if(u.key!==i){let l=t[a]={};return l[u.key]=u,o=l[i]=new g(e,t,i,h),void d(o,t,s,r,f,e)}o=u}else if(o=u[i],!o)return o=u[i]=new g(e,t,i,h),void d(o,t,s,r,f,e);o.root=e,o.ft=h}else d(t[a]=new g(e,t,i,h),t,s,r,f,e)}}const a=Symbol("solariteEvents");function c(t,e){let i=t[a];if(void 0!==i)return i instanceof g?i.key===e?i:void 0:i[e]}function d(t,e,i,s,l,n){let r=!1;if(!1===s){let t=l?.eventDelegation??!0;!1!==t&&p.has(i)&&(r=!0===t||t.includes(i))}if(r){t.ht=!0;let e=n[y];void 0===e&&(e=n[y]=new Set),e.has(i)||(e.add(i),n.addEventListener(i,b))}else e.addEventListener(i,t,s)}const p=new Set(["beforeinput","click","contextmenu","dblclick","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),y=Symbol("solariteDelegatedTypes"),m=Symbol("solariteDelegated");function b(t){if(t[m])return;t[m]=!0;let e=t.type,i=t.target;for(Object.defineProperty(t,"currentTarget",{configurable:!0,get:()=>i});i;){let s=i[a];if(void 0!==s){let i=s instanceof g?s:s[e];if(void 0!==i&&!0===i.ht&&i.key===e&&(i.handleEvent(t),t.cancelBubble))break}i=i.parentNode}delete t.currentTarget}class g{constructor(t,e,i,s){this.root=t,this.node=e,this.key=i,this.ft=s}handleEvent(t){let e=this.ft;switch(e.length){case 1:return e[0].call(this.root,t,this.node);case 2:return e[0].call(this.root,e[1],t,this.node);case 3:return e[0].call(this.root,e[1],e[2],t,this.node)}return e[0].call(this.root,...e.slice(1),t,this.node)}}class v extends u{ut;constructor(t,e,i=null,s=null){super(null,e,i,s),this.ut=i?i.slice(2):null}apply(t){this.U?.length>1?super.apply(t):this.V(t[0])}V(t){if(this.U?.length>1)return super.apply([t]);if(this.q&&this.G.tagName.endsWith("-SOLARITE-PLACEHOLDER"))return;let e,i=this.W.ot.root,s=this.G,l=this.ut;if(Array.isArray(t)&&"function"==typeof t[0])e=t[0];else{if("function"!=typeof t)throw Error(`Invalid event binding: <${s.tagName.toLowerCase()} ${this.attrName}=\${${JSON.stringify(t)}}>`);e=t,t=null}this.rt(s,i,l,l,e,t)}}const w=Symbol("Fragment");class E{constructor(t,e){this.name=t,this.value=e}}const S=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),k=new Map;function $(t){if(null===t||"object"!=typeof t)return t;let e="";for(let i in t){let s=t[i];null!=s&&!1!==s&&(e+=(e?";":"")+n.N(i)+":"+s)}return e}function x(t){return(""+t).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function A(t,e,i=[],s){if(e=e||{},t===w){let t=[""];for(let e=0;i.length>e;e++)t.push("");return new Q(t,i)}if("function"==typeof t){if(t.prototype instanceof HTMLElement){n.C(t);let l=customElements.ct?customElements.ct(t):n.N(t.name);return l&&!l.includes("-")&&(l+="-element"),T(l,e,i,s)}let l={};for(let t in e)"key"!==t&&(l[t]="style"===t?$(e[t]):e[t]);!("children"in l)&&i.length&&(l.children=1===i.length?i[0]:i);let r=t(l);return void 0===s&&(s=e.key),void 0!==s&&r instanceof Q&&(r.key=s),r}return T(t,e,i,s)}function T(t,e,i,s){let l=S.has(t.toLowerCase()),n=[],r=[],o="";for(let t in e){if("children"===t)continue;if("key"===t){void 0===s&&(s=e[t]);continue}let i=e[t];"id"!==t&&"data-id"!==t||"string"!=typeof i?("style"===t&&(i=$(i)),n.push(t),r.push(i)):o+=` ${t}="${x(i)}"`}let f=l?0:i.length,h=t+o+"\0"+n.join("\0")+"\0#"+f,u=k.get(h);u||(u=((t,e,i,s,l)=>{let n=[],r="<"+t+e;for(let t of i)n.push(r+" "+t+"="),r="";if(r+=">",l)return n.push(r),n;if(0===s)n.push(r+"</"+t+">");else{n.push(r);for(let t=1;s>t;t++)n.push("");n.push("</"+t+">")}return n})(t,o,n,f,l),k.set(h,u));let a=l?r:r.concat(i),c=new Q(u,a);return void 0!==s&&(c.key=s),c}class N extends f{dt;lt;constructor(t,e){super(null,null),this.G=e,this.dt=new Set}apply(t){this.V(t[0])}V(t){let e=this.G;if(t instanceof E)return this.yt(t);Array.isArray(t)&&(t=t.flat().join(" "));let i=this.dt;if(this.dt=new Set,t)if("function"==typeof t&&(t=t()),"object"==typeof t)for(let i in t){let s=t[i];void 0!==s&&!1!==s&&null!==s&&(e.setAttribute(i,s),this.dt.add(i))}else{let i=n.R(t);for(let t in i)e.setAttribute(t,i[t]),this.dt.add(t)}for(let t of i)this.dt.has(t)||e.removeAttribute(t)}yt(t){let e=t.name;if("key"===e)return;let i=t.value,s=this.bt;if(void 0===s||this.gt!==e){let t=this.G;n.L(e)?s=new v(null,t,e,null):(s=new u(null,t,e,null),s.Y=n.j(t,e)),s.q=this.q,this.bt=s,this.gt=e}s.G=this.G,s.W=this.W,"style"===e&&(i=$(i)),s.V(i)}_(){return 1}nt(t){return t[0]}}class C{data={};add(t,e){let i=this.data,s=i[t];s?s.push(e):i[t]=[e]}vt(t,e,i){let s=this.data,l=s[t];l?i>l.length-(l.head||0)&&l.push(e):s[t]=[e]}wt(t){let e=this.data,i=e[t];if(!i)return;let s=i.head||0,l=i[s];return s++,i.length>s?i.head=s:delete e[t],l}}class O extends f{Et=null;St=null;kt=null;$t=null;xt=null;At=null;constructor(t,e){super(t,e)}apply(t){this.V(t[0])}V(t){let i=typeof t;if(("string"===i||"number"===i)&&!this.Tt){"string"!==i&&(t+="");let s=this.St;if(null!==s)return void(this.kt!==t&&(s.nodeValue=t,this.kt=t));let l=this.Et;if(null===l||0===l.length){let i;if(this.I){let e=this.G.firstChild;if(null!==e&&3===e.nodeType&&e===this.G.lastChild)return e.nodeValue!==t&&(e.nodeValue=t),this.St=e,void(this.kt=t);this.G.textContent=t,i=this.G.firstChild}else i=e.i.createTextNode(t),this.G.parentNode.insertBefore(i,this.G);return this.St=i,this.kt=t,void(this.W.Nt||(this.J=null,this.W.Ct&&this.W.Ct.Ot()))}if(1===l.length){let e=l[0],i=e.Lt;if(!0===i.jt)return void(i.html[0]!==t&&(e.Pt.nodeValue=t,i.html[0]=t,e.Rt=t))}}if(null!==this.St){let t=new Z(P(this.kt),this,this.St);(this.Et??=[]).push(t),this.St=null}let s=[],l=this.Mt(t,s,!1);if(l||this.Tt)this.Tt=l,this.Dt(s);else{let t=0!==s.length?s[0]:null;(null!==t?"string"==typeof t||void 0===t.key&&0>I.get(t.html,t.Ft).Ht:null===this.Et||0===this.Et.length||void 0===this.Et[0].key)?this.Gt(s):this.It(s)}}Gt(t){let i=this.Et||L,s=i.length,l=t.length,r=Array(l),o=0,f=s,h=l;for(;f>o&&h>o;){let e=i[o],s=t[o];if(!R(e,s))break;e.zt&&e.Wt(s.exprs,!1),r[o]=e,o++}for(;f>o&&h>o;){let e=i[f-1],s=t[h-1];if(!R(e,s))break;e.zt&&e.Wt(s.exprs,!1),r[--h]=e,f--}for(;f>o&&h>o;){let e=i[o],s=t[o];if(R(e,s))e.zt&&e.Wt(s.exprs,!1);else{if(!M(e,s))break;this.Jt(e,s)}r[o]=e,o++}let u=f-o,a=h-o;if(u||a){if(u){for(let t=o;f>t;t++){let e=i[t];e.Pt!==e.Vt&&e._t()}let t=0===l&&0===o&&this.Bt(),e=this.At??=new C;for(let s=o;f>s;s++){let l=i[s];l.Pt!==l.Vt?n.D(l._t()):t||l.Pt.remove(),l.Lt.jt||e.vt(l.Rt,l,j)}}if(a){let i=this.I,s=l>h?r[h].Pt:i?null:this.G,n=i?this.G:this.G.parentNode,f=n,u=s,c=null;a>1&&(c=e.i.createDocumentFragment(),f=c,u=null);for(let e=o;h>e;e++){let i=this.Kt(t[e]);r[e]=i;let s=i.Pt,l=i.Vt;if(s===l)f.insertBefore(s,u);else for(;;){let t=s.nextSibling;if(f.insertBefore(s,u),s===l)break;s=t}}c&&n.insertBefore(c,s)}this.W.Nt||(this.J=null,this.W.Ct&&this.W.Ct.Ot())}this.Et=r,this.$t&&(this.$t=null),this.xt&&(this.xt=null)}It(t){let i=this.Et||L,s=i.length,l=t.length,r=Array(l),o=null,f=-1;const h=t=>void 0!==t.key?t.key:(t.html!==o&&(o=t.html,f=I.get(t.html,t.Ft).Ht),0>f?void 0:t.exprs[f]);let u=0,a=s,c=l;for(;a>u&&c>u;){let e=i[u],s=t[u];if(e.Lt===s)e.zt&&e.Wt(s.exprs,!1);else{if("string"==typeof s||e.key!==h(s)||!M(e,s))break;R(e,s)?e.zt&&e.Wt(s.exprs,!1):this.Jt(e,s)}r[u]=e,u++}for(;a>u&&c>u;){let e=i[a-1],s=t[c-1];if(e.Lt===s)e.zt&&e.Wt(s.exprs,!1);else{if("string"==typeof s||e.key!==h(s)||!M(e,s))break;R(e,s)?e.zt&&e.Wt(s.exprs,!1):this.Jt(e,s)}r[--c]=e,a--}let d=a-u,p=c-u;if(d||p){let s=this.I,o=s?this.G:this.G.parentNode,f=0,y=!1,m=null,b=null;if(d)if(p){let e=new Map;for(let i=u;c>i;i++){let s=t[i];"string"!=typeof s&&e.set(h(s),i)}m=Array(p).fill(-1);let s=-1;for(let l=u;a>l;l++){let n,o=i[l],h=void 0===o.key?void 0:e.get(o.key);void 0!==h&&-1===m[h-u]&&M(o,n=t[h])?(m[h-u]=l,f++,s>h?y=!0:s=h,R(o,n)?o.zt&&o.Wt(n.exprs,!1):this.Jt(o,n),r[h]=o):(b??=[]).push(o)}}else b=i.slice(u,a);if(b){for(let t of b)t.Pt!==t.Vt&&t._t();if(0!==u||c!==l||0!==f||!this.Bt())for(let t of b)t.Pt!==t.Vt?n.D(t._t()):t.Pt.remove()}if(p){let i=l>c?r[c].Pt:s?null:this.G;if(0===f){let s=o,l=i,n=null;p>1&&(n=e.i.createDocumentFragment(),s=n,l=null);for(let e=u;c>e;e++){let i=this.Zt(t[e]);r[e]=i;let n=i.Pt,o=i.Vt;if(n===o)s.insertBefore(n,l);else for(;;){let t=n.nextSibling;if(s.insertBefore(n,l),n===o)break;n=t}}n&&o.insertBefore(n,i)}else{let e=y?(t=>{let e=[],i=Array(t.length);for(let s=0;t.length>s;s++){let l=t[s];if(-1===l)continue;let n=0,r=e.length;for(;r>n;){let i=n+r>>1;l>t[e[i]]?n=i+1:r=i}n>0&&(i[s]=e[n-1]),n===e.length?e.push(s):e[n]=s}let s=e.length;if(s){let t=e[s-1];for(;s-- >0;)e[s]=t,t=i[t]}return e})(m):null,s=null!==e?e.length-1:-1;for(let l=c-1;l>=u;l--){let n=r[l];void 0===n?(n=this.Zt(t[l]),r[l]=n,D(o,n,i)):null!==e&&(0>s||e[s]!==l-u?D(o,n,i):s--),i=n.Pt}}}this.W.Nt||(this.J=null,this.W.Ct&&this.W.Ct.Ot())}this.Et=r,this.$t&&(this.$t=null),this.xt&&(this.xt=null)}Zt(t){if("string"==typeof t)return new Z(P(t),this);let e=new Z(t,this);return(t.exprs.length||e.Ut&&e.Ut.length)&&e.Wt(t.exprs),e}Jt(t,e){if("string"==typeof e)t.Pt.nodeValue=e,t.Lt.html[0]=e,t.Rt=e;else{if(t.qt){if(null!==t.Ut||!t.Yt(e)){let i=t.Lt.exprs,s=e.exprs,l=t.Ut??t.Xt();for(let t=l.length-1;t>=0;t--)et(i[t],s[t])||l[t].V(s[t])}t.styles&&t.Qt(),t.J=null,t.Nt=!1}else t.Wt(e.exprs);t.Lt=e,void 0!==e.key&&(t.key=e.key)}}Kt(t){let e;if("string"==typeof t)return t=P(t),new Z(t,this);let i=this.At;return i&&(e=i.wt(t.te()),e)?(this.Jt(e,t),e):(e=new Z(t,this),(t.exprs.length||e.Ut&&e.Ut.length)&&e.Wt(t.exprs),e)}Mt(t,e,i){if(t instanceof Q)e.push(t);else if(Array.isArray(t))for(let s of t)s instanceof Q?e.push(s):i=this.Mt(s,e,i);else if("function"==typeof t)i=this.Mt(t(),e,i);else if(t instanceof NodeList){for(let i of t)e.push(i);i=i||t.length>0}else if(t?.nodeType){if(11===t.nodeType)for(let i of[...t.childNodes])e.push(i);else e.push(t);i=!0}else void 0===t||!1===t||null===t?t="":"string"!=typeof t&&(t+=""),e.push(t);return i}Dt(t){let e=this;e.ee();let i=[],s=e.Et||L;e.Et=[];for(let s of t)if("string"==typeof s&&(s=P(s)),s instanceof Q){let t=e.ie(s);i.push(...t._t()),e.Et.push(t)}else i.push(s);let l=e._t();if(!n.v(l,i)){e.J=i,this.W.Ct&&this.W.Ct.Ot(),l.length&&!i.length&&e.Bt()||(e.I?H(e.G,l,i,null):H(e.G.parentNode,l,i,e.G));for(let t of s)t.Pt.parentNode||n.D(t._t())}}Ot(){let t=this,e=this.I?this.G:this.G.parentNode;for(;t&&(t.I?t.G:t.G.parentNode)===e;)t.J=null,t=t.W?.Ct}Bt(){if(this.I)return this.G.textContent="",!0;let t=this.F.parentNode;return this.F===t.firstChild&&this.G===t.lastChild&&(t.innerHTML="",t.append(this.F,this.G),!0)}ie(t){let e=t.te(),i=this.xt?.wt(e)||this.At?.wt(e);return i?(tt(i.Lt,t)?i.zt&&i.Wt(t.exprs,!1):i.Wt(t.exprs),i.Lt=t):(i=new Z(t,this),i.Wt(t.exprs)),(this.$t??=[]).push(i),i}ee(){let t=this.xt?.data;if(t){let e=(this.At??=new C).data;for(let i in t){let s=t[i],l=s.head||0,n=e[i];if(n)for(let t=l,e=j+(n.head||0);s.length>t&&e>n.length;t++)n.push(s[t]);else n=e[i]=l?s.slice(l):s,n.length>j&&(n.length=j)}}this.xt=new C;let e=this.xt,i=this.$t?.length?this.$t:this.Et;if(i)for(let t of i)e.add(t.Rt,t);this.$t=null}_t(){let t;if(t=this.J,t)return t;t=[];let e,i=null;for(this.I?e=this.G.firstChild:(e=this.F.nextSibling,i=this.G);e&&e!==i;)t.push(e),e=e.nextSibling;return this.J=t,t}}const L=[],j=1e4;function P(t){let e=new Q([t],[]);return e.jt=!0,e}function R(t,e){let i=t.Lt;return i===e||("string"==typeof e?!0===i.jt&&i.html[0]===e:tt(i,e))}function M(t,e){let i=t.Lt;return"string"==typeof e?!0===i.jt:i.html===e.html&&i.Ft===e.Ft}function D(t,e,i){let s=e.Pt,l=e.Vt;if(s===l)t.insertBefore(s,i);else for(;;){let e=s.nextSibling;if(t.insertBefore(s,i),s===l)break;s=e}}function H(t,e,i,s){if(e.length){let s=new Set(i);for(let i of e)s.has(i)||i.parentNode!==t||t.removeChild(i)}let l=s;for(let e=i.length;e--;){let s=i[e];s.nextSibling===l&&s.parentNode===t||t.insertBefore(s,l),l=s}}class F extends f{apply(t){this.W.key=t[0]}V(t){this.W.key=t}}class G extends f{se;le;constructor(t,e){super(null,e)}apply(t){let l=(t=>{const e=new Set;return JSON.stringify(t,((t,i)=>{if("function"==typeof i)return X(i);if("object"==typeof i&&null!==i){if(i instanceof Node)return X(i);if(e.has(i))return X(i);if(e.add(i),i instanceof Q)return{html:X(i.html),exprs:i.exprs}}return i}))})(t),r=l!==this.le;this.le=l;let o=this.G,f=n.S(o,"_is");for(let e,l=0;e=this.se[l];l++)if(!(e instanceof F))if(e instanceof u){let r=n.k(e.attrName),o=e.nt(t[l]);!e.U&&s(o)&&(o=i(o[0],o.slice(1))),f[r]=o}else{let i=e.nt(t[l]);if("object"==typeof i)for(let t in i)f[n.k(t)]=i[t];else if("string"==typeof i){let t=n.R(i);for(let e in t)f[n.k(e)]=t[e]}}let h=o.getAttribute("_is");if(o.tagName.endsWith("-SOLARITE-PLACEHOLDER")||h){let s=(h||o.tagName.slice(0,-21)).toLowerCase(),l=customElements.get(s);if(!l)throw Error(`Must call customElements.define('${s}', Class) before using it.`);e.t=[...o.childNodes];let n=new l(f);h&&n.setAttribute("is",h);for(let t of o.attributes)"_is"!==t.name&&n.setAttribute(t.name,t.value);for(let t in f){let e=f[t],i=typeof e;"boolean"===i?!1!==e&&null!=e&&n.setAttribute(t,""):"string"!==i&&"number"!==i&&"bigint"!==i||n.setAttribute(t,e)}let r=n.getAttribute("data-id")||n.getAttribute("id");r&&i(this.W.getRootNode(),r.split(/\./g),n);let u=this.W;this.G=n;for(let t of u.Ut)t.G===o&&(t.G=n),t.F===o&&(t.F=n);u.Pt===o&&(u.Pt=n),u.Vt===o&&(u.Vt=n),"function"!=typeof n.render||e.p.has(n)||n.render(f,!0);for(let e,i=0;e=this.se[i];i++)e.W=this.W,e.G=n,e.apply(t[i]);o.replaceWith(n)}else"function"==typeof o.render&&o.render(f,r);e.t=null}clone(t,e=0){let i=this.B(t,e),s=new G(null,i);return s.se=this.se.map((i=>i.clone(t,e))),s}_(){return 0}}class I{fragment;Ut=[];ids=[];styles=[];scripts=[];zt=!1;qt=!1;ne=!1;Ht=-1;re=!1;oe=!1;constructor(t=null,i=!1){if(!t)return;if(1===t.length&&!t[0].match(/[<&]/))return void(this.fragment=e.i.createTextNode(t[0]));let s,l=I.fe(t),r=e.i.createElement("template");if(l)if(i){r.innerHTML="<svg>"+l+"</svg>";let t=r.content.firstChild,i=e.i.createDocumentFragment();for(;t.firstChild;)i.append(t.firstChild);this.fragment=i}else r.innerHTML=l,this.fragment=r.content;else r.content.append(e.i.createTextNode("")),this.fragment=r.content;J(this.fragment);let o=[],h=0;const a=e.i.createTreeWalker(this.fragment,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_TEXT);for(;s=a.nextNode();)if(o.map((t=>t.remove())),o=[],1===s.nodeType){const t=s.hasAttribute("is"),e=t||s.tagName.includes("-"),l=[];for(let t of[...s.attributes]){if("key"===t.name){let i=t.value.split(/[\ue000-\uf8ff]/g);if(2!==i.length||""!==i[0]||""!==i[1])throw Error("The key attribute is reserved and must be a single expression: key=${...}");if(s.parentNode!==this.fragment)throw Error("The key attribute must be on a top-level element of its template.");if(this.Ht>=0)throw Error("A template can have only one key attribute.");this.Ht=t.value.charCodeAt(0)-K;let n=new F(null,s);this.Ut.push(n),e&&l.push(n),h++,s.removeAttribute("key");continue}let r=t.name.match(/^[\ue000-\uf8ff]$/);if(r){let t=new N(null,s);this.Ut.push(t),e&&(t.q=!0,l.push(t)),h++,s.removeAttribute(r[0])}else{let r=t.value.split(/[\ue000-\uf8ff]/g);if(r.length>1){let o=2!==r.length||r[0].length||r[1].length?r:null,f=n.L(t.name),a=f?new v(null,s,t.name,o):new u(null,s,t.name,o);if(a.Y=n.j(s,t.name),this.Ut.push(a),e&&(a.q=!0,l.push(a)),h+=r.length-1,i||f&&!o)s.removeAttribute(t.name);else try{s.setAttribute(t.name,r.join(""))}catch(e){throw Error(`Error setting attribute "${t.name}" on node <${s.tagName}>: ${e.message}`)}}}}if(e){let e=new G(null,s);e.se=l,this.Ut.splice(this.Ut.length-l.length,0,e),t&&(s.setAttribute("_is",s.getAttribute("is")),s.removeAttribute("is"))}}else if(8===s.nodeType&&"!✨!"===s.nodeValue){if(s?.parentNode?.closest&&s?.parentNode?.closest("[contenteditable]"))throw Error('Contenteditable can\'t have expressions inside them. Use <div contenteditable value="${...}"> instead.');let t=s.parentNode;if(1!==t.nodeType||s.previousSibling||s.nextSibling||t.tagName.includes("-")||"SLOT"===t.tagName||t.hasAttribute("is")){let t,i=s.previousSibling;i||(i=e.i.createComment("Path:"+this.Ut.length),s.parentNode.insertBefore(i,s)),!s.nextSibling||8===s.nextSibling.nodeType&&"!✨!"===s.nextSibling.textContent?(t=s,t.textContent="PathEnd:"+this.Ut.length):(t=s.nextSibling,o.push(s));let l=new O(i,t);this.Ut.push(l),h++}else{let e=new O(null,t);e.I=!0,this.Ut.push(e),h++,o.push(s)}}else{if(3===s.nodeType&&"TEXTAREA"===s.parentNode?.tagName&&s.textContent.includes("\x3c!--!✨!--\x3e"))throw Error('Textarea can\'t have expressions inside them. Use <textarea value="${...}"> instead.');if(8===s.nodeType){let t=s.textContent.split(/[\ue000-\uf8ff]/g);for(let e=0;t.length-1>e;e++){let t=new f(s.previousSibling,s);this.Ut.push(t),h++}}else if(3===s.nodeType&&["SCRIPT","STYLE"].includes(s.parentNode?.nodeName)){let t=s.textContent.split(z);if(t.length>1){let i=[];for(let l=0;t.length>l;l++){let n=e.i.createTextNode(t[l]);s.parentNode.insertBefore(n,s),l>0&&i.push(n)}for(let t,e=0;t=i[e];e++){let e=new O(t.previousSibling,t);this.Ut.push(e),h++}o.push(s)}}}if(o.map((t=>t.remove())),h!==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.Ut)t.F&&(t.X=[].indexOf.call(t.F.parentNode.childNodes,t.F)),t.K=f.get(t.G);this.he(),this.ue(),this.qt=!0;for(let t of this.Ut){if(t instanceof G){this.zt=!0,this.qt=!1;break}1!==t._()&&(this.qt=!1)}if(this.re&&this.qt){let t=[],e=!0;for(let i=0;this.Ut.length>i;i++){let s=this.Ut[i];if(s instanceof O){if(!s.I){e=!1;break}t.push(i)}else if(!(s instanceof u||s instanceof F)){e=!1;break}}e&&(this.oe=!0,this.ae=t,this.ce=this.Ut.map((t=>t.Z(null,t.G))))}}static fe(t){let e=[],i=new h;for(let s=0;t.length>s;s++){let l=0,n=i.parse(t[s],((t,i,s)=>{if(l!==i){let n=t.slice(l,i);s===h.it&&(n=n.replace(/^<\/?[a-z][a-z0-9]*-[a-z0-9-]+/i,(t=>t+"-SOLARITE-PLACEHOLDER"))),e.push(n)}l=i}));t.length-1>s&&e.push(n===h.Text?z:String.fromCharCode(K+s))}return e.join("")}he(){this.scripts=[].map.call(this.fragment.querySelectorAll("script"),(t=>f.get(t))),this.styles=[].map.call(this.fragment.querySelectorAll("style"),(t=>f.get(t)));let t=this.fragment.querySelectorAll("[id],[data-id]");for(let i of t){let t=i.getAttribute("data-id")||i.getAttribute("id");if(e.div.hasOwnProperty(t))throw Error(`<${i.tagName.toLowerCase()} id="${t}"> can't override existing HTMLElement id property.`)}this.ids=[].map.call(t,(t=>f.get(t))),this.ne=this.ids.length>0||this.styles.length>0||this.scripts.length>0}ue(){let t=!1;for(let e of this.Ut)if(e instanceof G){t=!0;break}if(t||!this.Ut.length)return;let e=[],i=new Map,s=this.fragment,l=1,n=t=>{if(t===s)return 0;let r=i.get(t);return void 0===r&&(e.push(n(t.parentNode),[].indexOf.call(t.parentNode.childNodes,t)),r=l++,i.set(t,r)),r};for(let t of this.Ut)t.de=t.G===s?0:n(t.G),t.pe=t.F?n(t.F):-1;this.ye=e,this.me=Array(l),this.ne||1!==s.childNodes.length||1!==s.firstChild.nodeType||2>e.length||0!==e[0]||0!==e[1]||(this.re=!0)}static get(t,i=!1){if(t===V&&i===_)return B;let s=e.m.get(t);s||(s={},e.m.set(t,s));let l=i?"svg":"html",n=s[l];return n||(n=s[l]=new I(t,i)),V=t,_=i,B=n,n}}const z="\x3c!--!✨!--\x3e",W=["TABLE","THEAD","TBODY","TFOOT","TR"];function J(t){let e=1===t.nodeType&&W.includes(t.tagName),i=t.firstChild;for(;i;){let t=i.nextSibling;1===i.nodeType?J(i):e&&3===i.nodeType&&!i.nodeValue.trim()&&i.remove(),i=t}}let V=null,_=!1,B=null;const K=57344;class Z{ot;Ct;Pt;Vt;Ut=null;Rt;key;zt=!1;qt=!1;Nt=!0;J;styles;Lt;constructor(t,i=null,s=null,l=null){if(this.ot=i?.W?.ot||this,this.Ct=i,this.Lt=t,void 0!==t.key&&(this.key=t.key),t.jt)this.Rt=t.te(),this.Pt=this.Vt=s||e.i.createTextNode(t.html[0]);else{const e=I.get(t.html,t.Ft);if(this.Rt=e.Rt??=t.te(),this.zt=e.zt,this.qt=e.qt,e.re&&null!==i){const t=e.fragment.firstChild.cloneNode(!0);this.Pt=this.Vt=t,!0!==e.oe&&this.be(t,e,0,!0)}else{const t=e.fragment.cloneNode(!0);11===t.nodeType?(this.Pt=t.firstChild,this.Vt=t.lastChild):this.Pt=this.Vt=t,this.instantiate(e,t,s,l)}}}instantiate(t,e,i,s){t.Ut.length?this.be(e,t):this.Ut=[],t.ne&&this.ge(e,t)}Wt(t,e=!0){let i=this.Ut;if(this.qt){if(e){if(null===i)return void this.ve(t);for(let e=i.length-1;e>=0;e--)i[e].V(t[e]);this.styles&&this.Qt(),this.J=null}return void(this.Nt=!1)}if(!i)return void(this.Nt=!1);let s=t.length,l=Array(i.length);for(let n,r=i.length-1;n=i[r];r--){if(0===r&&n instanceof G&&n.G===this.getRootNode())continue;let i=n._();if(l[r]=t.slice(s-i,s),s-=i,n instanceof G){let t=l.slice(r+1,r+1+n.se.length);n.apply(t)}else e&&n.apply(l[r])}e&&(this.Qt(),this.J=null),this.Nt=!1}ve(t){let e=this.Lt,i=I.get(e.html,e.Ft),s=i.ae;for(let e=0;s.length>e;e++){let l=typeof t[s[e]];if("string"!==l&&"number"!==l){let e=this.Xt(i);for(let i=e.length-1;i>=0;i--)e[i].V(t[i]);return this.J=null,void(this.Nt=!1)}}let l=this.we(i),n=i.Ut,r=i.ce;for(let e=n.length-1;e>=0;e--){let i=r[e],s=l[n[e].de];if(i.I){let i=t[e];"number"==typeof i&&(i+=""),s.textContent=i}else i.G=s,i.W=this,i.V(t[e])}this.J=null,this.Nt=!1}Yt(t){let e=I.get(t.html,t.Ft),i=t.exprs,s=e.ae;for(let t=0;s.length>t;t++){let e=typeof i[s[t]];if("string"!==e&&"number"!==e)return!1}let l=this.Lt.exprs,n=e.Ut,r=e.ce,o=null;for(let t=n.length-1;t>=0;t--)if(!et(l[t],i[t])){null===o&&(o=this.we(e));let s=r[t],l=o[n[t].de];if(s.I){let e=i[t],n=l.firstChild;"number"==typeof e&&(e+=""),null!==n&&3===n.nodeType&&n===l.lastChild?n.nodeValue=e:(s.G=l,s.W=this,s.V(i[t]),s.St=null,s.kt=null,s.J=null);continue}s.G=l,s.W=this,s.V(i[t])}return!0}we(t){let e=t.me;e[1]=this.Pt;let i=t.ye;for(let t=2,s=2;i.length>t;t+=2,s++){let l=e[i[t]].firstChild;for(let e=i[t+1];e>0;e--)l=l.nextSibling;e[s]=l}return e}Xt(t=null){t??=I.get(this.Lt.html,this.Lt.Ft);let e=this.we(t),i=t.Ut,s=i.length,l=this.Ut=Array(s);for(let t=0;s>t;t++){let s=i[t],n=s.Z(0>s.pe?null:e[s.pe],e[s.de]);n.W=this,l[t]=n}for(let e of t.ae){let t=l[e],i=t.G.firstChild;null!==i&&3===i.nodeType&&i===t.G.lastChild&&(t.St=i,t.kt=i.nodeValue)}return l}_t(){let t=this.J;if(t)return t;t=[];let e=this.Pt,i=this.Vt?.nextSibling;for(;e&&e!==i;)t.push(e),e=e.nextSibling;return this.J=t,t}getRootNode(){return this.ot.root}Ee(){return this.ot}be(t,e,i=0,s=!1){let l=e.Ut,n=l.length,r=this.Ut=Array(n),o=e.ye;if(o&&0===i){let i=e.me,f=0,h=1;for(s?(i[1]=t,f=2,h=2):i[0]=t;o.length>f;f+=2,h++){let t=i[o[f]].firstChild;for(let e=o[f+1];e>0;e--)t=t.nextSibling;i[h]=t}for(let t=0;n>t;t++){let e=l[t],s=e.Z(0>e.pe?null:i[e.pe],i[e.de]);s.W=this,r[t]=s}}else for(let e=0;n>e;e++){let s=l[e].clone(t,i);s.W=this,r[e]=s}}Qt(){if(this.styles)for(let[t,e]of this.styles)e!==t.textContent&&n.A(t,this.Ee().root)}ge(t,e,i=0){let s=this.ot.root;if(s){let l=this.ot.options;if(!1!==l?.ids)for(let l of e.ids){i&&(l=l.slice(0,-i));let e=f.resolve(t,l);n.$(s,e)}if(!1!==l?.styles){e.styles.length&&(this.styles=new Map);for(let l of e.styles){i&&(l=l.slice(0,-i));let e=f.resolve(t,l);1===s.nodeType&&(n.A(e,s),this.styles.set(e,e.textContent))}}if(!1!==l?.scripts)for(let s of e.scripts){i&&(s=s.slice(0,-i));let e=f.resolve(t,s);(0,eval)(e.textContent)}}}}class U extends Z{instantiate(t,i,s,l){let n=0;if(this.options=l,i instanceof Text){if(!s)throw Error("Cannot create a standalone text node");this.root=s,i.nodeValue.length&&this.root.append(i)}else{if(s){let t;if(this.root=s,(e.t||s.childNodes.length)&&(t=e.i.createDocumentFragment(),t.append(...e.t||s.childNodes)),o=this.root.tagName,1===(r=i).children.length&&o.includes("-")&&r.children[0].tagName.replace("-SOLARITE-PLACEHOLDER","")===o){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);n=1}else 1===i.childNodes.length&&3===i.childNodes[0].nodeType&&""===i.childNodes[0].textContent||this.root.append(...i.childNodes);if(t){for(let e of s.querySelectorAll("slot[name]")){let i=e.getAttribute("name");if(i){let s=t.querySelectorAll(`[slot='${i}']`);e.append(...s)}}let e=s.querySelector("slot:not([name])");e?e.append(t):s.append(t)}}else{let t=(t=>{let e=[];for(let i of t.childNodes)if(1===i.nodeType||3===i.nodeType&&i.textContent.trim().length){if(e.length)return null;e.push(i)}return e[0]})(i);this.root=t||i,t&&(n=1)}this.be(this.root,t,n),this.ge(this.root,t,n)}var r,o;this.Pt=this.Vt=this.root,e.h.set(this.root,this)}}let q=1,Y=new WeakMap;function X(t){let e=Y.get(t);return void 0===e&&(e="~@"+q++,Y.set(t,e)),e}class Q{exprs=void 0;html=void 0;Rt;jt;key;Ft=!1;constructor(t=[""],e=[]){this.html=t,this.exprs=e}render(t=null,i={}){let s=t&&e.h.get(t);return s||(s=new U(this,null,t,i),t||(t=s.getRootNode()),e.h.set(t,s)),1!==this.html?.length||this.html[0]?s.Wt(this.exprs):t.innerHTML="",t}te(){return void 0===this.Rt&&(this.Rt=this.exprs.length?X(this.html):this.html[0]),this.Rt}}function tt(t,e){if(t.html===e.html&&t.Ft===e.Ft){let i=t.exprs,s=e.exprs;for(let t=0;i.length>t;t++)if(!et(i[t],s[t]))return!1;return!0}return t.jt===e.jt&&!t.exprs.length&&!e.exprs.length&&1===t.html.length&&1===e.html.length&&t.Ft===e.Ft&&t.html[0]===e.html[0]}function et(t,e){if(t===e)return!0;if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;t.length>i;i++)if(!et(t[i],e[i]))return!1;return!0}return t instanceof Q&&e instanceof Q&&tt(t,e)}function it(t){if("string"==typeof t){let i=e.i.createElement("template");i.innerHTML=t;let s=n.H(i.content.childNodes);return 1===s.length?s[0]:i.content}if(t instanceof Q)return t.render();if(t&&"object"==typeof t){let i=t;if("Object"!==i.constructor.name)throw Error(`Solarate Web Component class ${i.constructor?.name} must extend HTMLElement.`);if(!e.u.has(i)){e.u.set(i,null),i[st]();let t=e.u.get(i);e.u.delete(i);for(let e in i)t[e]="function"==typeof i[e]?i[e].bind(t):i[e];return t}}throw Error("toEl() does not support argument of type: "+(t?typeof t:t))}let st="render";function lt(t,...e){let i=new Q(t,e);return i.Ft=!0,i}const nt=Symbol("solariteRender"),rt=Symbol();function ot(t=rt,...i){if(Array.isArray(t))return new Q(t,i);if("string"==typeof t||t instanceof String){let e=t;if(!i.length||"object"!=typeof i[0]&&null!==i[0]){let t=e;return/^\s+</.test(t)&&(t=t.trim()),new Q([t],[])}return A(e+"",i[0]||{},i.slice(1))}if("function"==typeof t||t===w)return A(t,i[0]||{},i.slice(1));if(t instanceof HTMLElement||t instanceof DocumentFragment){if(!(i[0]instanceof Q)){let s=t,l=i[0];if(void 0===l){let t=s[nt];if(t)return t}let n=(t,...i)=>(s.shadowRoot&&(s.innerHTML=""),e.p.add(s),new Q(t,i).render(s,l));return void 0===l&&(s[nt]=n),n}i[0].render(t,i[1])}else{if(t===rt)return(t,...e)=>it(ot(t,...e));if("object"!=typeof t||!e.u.has(t)){if(n.P(t))return new Q;throw Error("h() does not support argument of type: "+(t?typeof t:t))}{let s=t;if("Object"!==s.constructor.name)throw Error(`Solarate Web Component class ${s.constructor?.name} must extend HTMLElement.`);if(!(i[0]instanceof Q))return((...t)=>{let i=ot(...t).render();e.u.set(s,i)}).bind(s);{let t=i[0].render();e.u.set(s,t)}}}}const ft=new WeakMap;function ht(t,e={},i=[]){for(let s of t.attributes){let l=n.k(s.name);if(!(l in t)||i.includes(l))continue;let r=s.value,o=e[l];t[l]=r.startsWith("${")&&r.endsWith("}")?JSON.parse(r.slice(2,-1)):o===Date?new Date(r):o===Boolean?!["false","0"].includes(r):o===Number?+r:o===String?r+"":o?o(r):r}}ot.immutableMap=ot.map=(t,e)=>{let i=Array(t.length);for(let s=0;t.length>s;s++){let l=t[s];if(null!==l&&"object"==typeof l){let t=ft.get(l);void 0===t&&(t=e(l),ft.set(l,t)),i[s]=t}else i[s]=e(l)}return i};let ut=new Proxy(HTMLElement,{construct:(t,e,i)=>(n.C(i),Reflect.construct(t,e,i))});class at extends ut{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=at.getAttribs(this);for(let i in e)t[i]=e[i]}}}render(){throw Error("render() is not defined for "+this.constructor.name)}renderFirstTime(){if(!e.p.has(this)){let t=at.getAttribs(this);this.render(t)}}connectedCallback(){this.renderFirstTime()}static define(t=null){n.C(this,t)}static getAttribs(t){let e=n.S(t);for(let t in e){let i=e[t];i.startsWith("${")&&i.endsWith("}")&&(e[t]=JSON.parse(i.slice(2,-1)))}return e}}export default ot;export{w as Fragment,e as Globals,at as Solarite,n as SolariteUtil,Q as Template,ht as assignAttributes,i as delve,c as getEventBinding,ot as h,lt as svg,it as toEl};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solarite",
3
- "version": "0.5.2",
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.",
3
+ "version": "0.7.0",
4
+ "description": "Solarite is a small (12KB min+gzip), fast, compilation-free JavaScript library that makes native web components fast to update, patching only the DOM that actually changed when you call render().",
5
5
  "type": "module",
6
6
  "main": "dist/Solarite.js",
7
7
  "module": "dist/Solarite.js",
@@ -11,6 +11,16 @@
11
11
  "types": "./src/Solarite.d.ts",
12
12
  "import": "./dist/Solarite.js",
13
13
  "default": "./dist/Solarite.js"
14
+ },
15
+ "./jsx-runtime": {
16
+ "types": "./src/jsx-runtime.d.ts",
17
+ "import": "./src/jsx-runtime.js",
18
+ "default": "./src/jsx-runtime.js"
19
+ },
20
+ "./jsx-dev-runtime": {
21
+ "types": "./src/jsx-dev-runtime.d.ts",
22
+ "import": "./src/jsx-dev-runtime.js",
23
+ "default": "./src/jsx-dev-runtime.js"
14
24
  }
15
25
  },
16
26
  "files": [
@@ -18,6 +28,9 @@
18
28
  "dist",
19
29
  "src"
20
30
  ],
31
+ "workspaces": [
32
+ "packages/*"
33
+ ],
21
34
  "scripts": {
22
35
  "test": "echo \"Error: no test specified\" && exit 1"
23
36
  },
@@ -35,7 +48,7 @@
35
48
  "vanilla",
36
49
  "web component"
37
50
  ],
38
- "author": "Eric P",
51
+ "author": "Eric Frost",
39
52
  "license": "MIT",
40
53
  "bugs": {
41
54
  "url": "https://github.com/Vorticode/solarite/issues"
package/readme.md CHANGED
@@ -1,11 +1,58 @@
1
- # Solarite
2
-
3
- Solarite is a smal, fast, compilation-free JavaScript library for performing minimal DOM updates on web components when your data changes. It follows modern web standards and is easy to use with vanilla JavaScript.
4
-
5
- For documentation and examples, see the **[Official Solarite Page](https://vorticode.github.io/solarite/)**.
6
-
7
- Download [Solarite.js](https://vorticode.github.io/solarite/dist/Solarite.js) (117KB, 9KB min+gzip)
8
-
9
- Or:
10
-
11
- `npm install solarite`
1
+ # Solarite
2
+
3
+ Solarite makes native web components fast to update, with no build step and no signals. You write plain JavaScript and call `render()` when your data changes; Solarite then patches only the DOM that actually changed. It's tiny (12KB min+gzip) and runs straight in the browser as a standard ES module.
4
+
5
+ **[Documentation & live examples ](https://vorticode.github.io/solarite/)**
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install solarite
11
+ ```
12
+
13
+ Or use it with no build step at all, straight from a CDN:
14
+
15
+ ```javascript
16
+ import h, {Solarite} from
17
+ 'https://cdn.jsdelivr.net/npm/solarite@0.7.0/dist/Solarite.min.js';
18
+ ```
19
+
20
+ ## Example
21
+
22
+ ```javascript
23
+ import h, {Solarite} from 'solarite';
24
+
25
+ class Counter extends Solarite {
26
+ count = 0;
27
+
28
+ render() {
29
+ h(this)`
30
+ <my-counter>
31
+ <button onclick=${() => { this.count++; this.render() }}>
32
+ Clicked ${this.count} times
33
+ </button>
34
+ </my-counter>`;
35
+ }
36
+ }
37
+ Counter.define('my-counter');
38
+ document.body.append(new Counter());
39
+ ```
40
+
41
+ ## Why Solarite?
42
+
43
+ It's one of the fastest UI libraries measured: a score of **1.08** on the [js-framework-benchmark](https://krausest.github.io/js-framework-benchmark/current.html) — about 8% slower than hand-written vanilla JavaScript — while staying tiny and build-free.
44
+
45
+ ### Compared to Lit
46
+
47
+ Lit is the best-known way to build web components. Here's where Solarite differs:
48
+
49
+ - **Scoped CSS without Shadow DOM.** Solarite scopes each component's `<style>` in the light DOM, so global stylesheets, form participation, and third-party CSS still reach your elements. There's no Shadow DOM boundary to work around.
50
+ - **No reactivity system to learn.** No signals, no `@property` decorators, no reactive controllers. Mutate plain JavaScript objects and arrays of any depth, then call `render()`. Updates happen exactly when you ask for them.
51
+ - **Truly build-free.** Ship the ES module as-is. Optional JSX plugins exist for Babel, esbuild, and Vite, but nothing requires a compiler.
52
+ - **Closer to vanilla speed.** Solarite sits near the top of the benchmark, ahead of most signal-based and virtual-DOM libraries.
53
+
54
+ The trade-off is deliberate: Solarite re-renders when you call `render()` rather than tracking dependencies automatically. Explicit updates, no hidden reactivity — a design choice, not a missing feature.
55
+
56
+ ## License
57
+
58
+ [MIT](LICENSE) — free for commercial use, no attribution required.
package/src/Globals.js CHANGED
@@ -1,73 +1,55 @@
1
- var Globals;
2
-
3
- /**
4
- * Created with a reset() function because it's useful for testing. */
5
- function reset() {
6
- Globals = {
7
-
8
- /**
9
- * Store which instances of Solarite have already been added to the DOM.
10
- * @type {WeakSet<HTMLElement>} */
11
- connected: new WeakSet(),
12
-
13
- /**
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
-
24
- div: document.createElement("div"),
25
-
26
- /** @type {HTMLDocument} The global document. */
27
- doc: document,
28
-
29
- /**
30
- * @type {Record<string, Class<Node>>} A map from built-in tag names to the constructors that create them. */
31
- elementClasses: {},
32
-
33
- /** @type {Record<string, boolean>} Key is tag-name.propName. Value is whether it's an attribute.*/
34
- htmlProps: {},
35
-
36
- /**
37
- * Used by Path.applyEventAttrib()
38
- * @type {WeakMap<Node, Record<eventName:string, [original:function, bound:function, args:*[]]>>} */
39
- nodeEvents: new WeakMap(),
40
-
41
- /**
42
- * Get the RootNodeGroup for an element.
43
- * @type {WeakMap<HTMLElement, RootNodeGroup>} */
44
- rootNodeGroups: new WeakMap(),
45
-
46
- /**
47
- * Used by h() path 9. */
48
- objToEl: new WeakMap(),
49
-
50
- /**
51
- * Elements that have been rendered to by h() at least once.
52
- * This is used by the Solarite class to know when to call onFirstConnect()
53
- * @type {WeakSet<HTMLElement>} */
54
- rendered: new WeakSet(),
55
-
56
- /**
57
- * Map from array of Html strings to a Shell created from them.
58
- * @type {WeakMap<string[], Shell>} */
59
- shells: new WeakMap(),
60
-
61
- /**
62
- * A map of individual untagged strings to their Templates.
63
- * This way we don't keep creating new Templates for the same string when re-rendering.
64
- * This is used by Path.applyExactNodes()
65
- * @type {Record<string, Template>} */
66
- //stringTemplates: {},
67
-
68
- reset
69
- };
70
- }
71
- reset();
72
-
1
+ var Globals;
2
+
3
+ /**
4
+ * Created with a reset() function because it's useful for testing. */
5
+ function reset() {
6
+ Globals = {
7
+
8
+ /**
9
+ * Store which instances of Solarite have already been added to the DOM.
10
+ * @type {WeakSet<HTMLElement>} */
11
+ connected: new WeakSet(),
12
+
13
+ /**
14
+ * Set by NodeGroup.instantiateComponent()
15
+ * Used by RootNodeGroup.getSlotChildren(). */
16
+ currentSlotChildren: null,
17
+
18
+ div: document.createElement("div"),
19
+
20
+ /** @type {HTMLDocument} The global document. */
21
+ doc: document,
22
+
23
+ /**
24
+ * @type {Record<string, Class<Node>>} A map from built-in tag names to the constructors that create them. */
25
+ elementClasses: {},
26
+
27
+ /** @type {Record<string, boolean>} Key is tag-name.propName. Value is whether it's an attribute.*/
28
+ htmlProps: {},
29
+
30
+ /**
31
+ * Get the RootNodeGroup for an element.
32
+ * @type {WeakMap<HTMLElement, RootNodeGroup>} */
33
+ rootNodeGroups: new WeakMap(),
34
+
35
+ /**
36
+ * Used by h() path 9. */
37
+ objToEl: new WeakMap(),
38
+
39
+ /**
40
+ * Elements that have been rendered to by h() at least once.
41
+ * This is used by the Solarite class to know when to call onFirstConnect()
42
+ * @type {WeakSet<HTMLElement>} */
43
+ rendered: new WeakSet(),
44
+
45
+ /**
46
+ * Map from array of Html strings to the Shells created from them, one per parse mode.
47
+ * @type {WeakMap<string[], {html?:Shell, svg?:Shell}>} */
48
+ shells: new WeakMap(),
49
+
50
+ reset
51
+ };
52
+ }
53
+ reset();
54
+
73
55
  export default Globals;
package/src/HtmlParser.js CHANGED
@@ -1,91 +1,91 @@
1
-
2
- export default class HtmlParser {
3
- constructor() {
4
- this.defaultState = {
5
- context: HtmlParser.Text, // possible values: 'TEXT', 'TAG', 'ATTRIBUTE'
6
- quote: null, // possible values: null, '"', "'"
7
- buffer: '',
8
- lastChar: null
9
- };
10
- this.state = {...this.defaultState};
11
- }
12
-
13
- reset() {
14
- this.state = {...this.defaultState};
15
- return this.state.context;
16
- }
17
-
18
- /**
19
- * Parse the next chunk of html, starting with the same context we left off with from the previous chunk.
20
- * @param html {string}
21
- * @param onContextChange {?function(html:string, index:int, prevContext:string, nextContext:string)}
22
- * Called every time the context changes, and again at the last context.
23
- * @return {('Attribute','Text','Tag')} The context at the end of html. */
24
- parse(html, onContextChange=null) {
25
- if (html === null)
26
- return this.reset();
27
-
28
- for (let i = 0; i < html.length; i++) {
29
- const char = html[i];
30
- switch (this.state.context) {
31
- case HtmlParser.Text:
32
- if (char === '<' && html[i + 1].match(/[/a-z!]/i)) { // Start of a tag or comment.
33
- onContextChange?.(html, i, this.state.context, HtmlParser.Tag);
34
- this.state.context = HtmlParser.Tag;
35
- this.state.buffer = '';
36
- }
37
- break;
38
- case HtmlParser.Tag:
39
- if (char === '>') {
40
- onContextChange?.(html, i+1, this.state.context, HtmlParser.Text);
41
- this.state.context = HtmlParser.Text;
42
- this.state.quote = null;
43
- this.state.buffer = '';
44
- }
45
- else if (char === ' ' && !this.state.buffer) {
46
- // No attribute name is present. Skipping the space.
47
- continue;
48
- }
49
- else if (char === ' ' || char === '/' || char === '?') {
50
- this.state.buffer = ''; // Reset the buffer when a delimiter or potential self-closing sign is found.
51
- }
52
- else if (char === '"' || char === "'" || char === '=') {
53
- onContextChange?.(html, i, this.state.context, HtmlParser.Attribute);
54
- this.state.context = HtmlParser.Attribute;
55
- this.state.quote = char === '=' ? null : char;
56
- this.state.buffer = '';
57
- }
58
- else
59
- this.state.buffer += char;
60
- break;
61
- case HtmlParser.Attribute:
62
- // Start an attribute quote.
63
- if (!this.state.quote && !this.state.buffer.length && (char === '"' || char === "'")) {
64
- this.state.quote = char;
65
- }
66
- else if (char === this.state.quote || (!this.state.quote && this.state.buffer.length)) {
67
- onContextChange?.(html, i, this.state.context, HtmlParser.Tag);
68
- this.state.context = HtmlParser.Tag;
69
- this.state.quote = null;
70
- this.state.buffer = '';
71
- }
72
- else if (!this.state.quote && char === '>') {
73
- onContextChange?.(html, i+1, this.state.context, HtmlParser.Text);
74
- this.state.context = HtmlParser.Text;
75
- this.state.quote = null;
76
- this.state.buffer = '';
77
- }
78
- else if (char !== ' ')
79
- this.state.buffer += char;
80
-
81
- break;
82
- }
83
- }
84
- onContextChange?.(html, html.length, this.state.context, null);
85
- return this.state.context;
86
- }
87
- }
88
-
89
- HtmlParser.Attribute = 'Attribute';
90
- HtmlParser.Text = 'Text';
1
+
2
+ export default class HtmlParser {
3
+ constructor() {
4
+ this.defaultState = {
5
+ context: HtmlParser.Text, // possible values: 'TEXT', 'TAG', 'ATTRIBUTE'
6
+ quote: null, // possible values: null, '"', "'"
7
+ buffer: '',
8
+ lastChar: null
9
+ };
10
+ this.state = {...this.defaultState};
11
+ }
12
+
13
+ reset() {
14
+ this.state = {...this.defaultState};
15
+ return this.state.context;
16
+ }
17
+
18
+ /**
19
+ * Parse the next chunk of html, starting with the same context we left off with from the previous chunk.
20
+ * @param html {string}
21
+ * @param onContextChange {?function(html:string, index:int, prevContext:string, nextContext:string)}
22
+ * Called every time the context changes, and again at the last context.
23
+ * @return {('Attribute','Text','Tag')} The context at the end of html. */
24
+ parse(html, onContextChange=null) {
25
+ if (html === null)
26
+ return this.reset();
27
+
28
+ for (let i = 0; i < html.length; i++) {
29
+ const char = html[i];
30
+ switch (this.state.context) {
31
+ case HtmlParser.Text:
32
+ if (char === '<' && html[i + 1].match(/[/a-z!]/i)) { // Start of a tag or comment.
33
+ onContextChange?.(html, i, this.state.context, HtmlParser.Tag);
34
+ this.state.context = HtmlParser.Tag;
35
+ this.state.buffer = '';
36
+ }
37
+ break;
38
+ case HtmlParser.Tag:
39
+ if (char === '>') {
40
+ onContextChange?.(html, i+1, this.state.context, HtmlParser.Text);
41
+ this.state.context = HtmlParser.Text;
42
+ this.state.quote = null;
43
+ this.state.buffer = '';
44
+ }
45
+ else if (char === ' ' && !this.state.buffer) {
46
+ // No attribute name is present. Skipping the space.
47
+ continue;
48
+ }
49
+ else if (char === ' ' || char === '/' || char === '?') {
50
+ this.state.buffer = ''; // Reset the buffer when a delimiter or potential self-closing sign is found.
51
+ }
52
+ else if (char === '"' || char === "'" || char === '=') {
53
+ onContextChange?.(html, i, this.state.context, HtmlParser.Attribute);
54
+ this.state.context = HtmlParser.Attribute;
55
+ this.state.quote = char === '=' ? null : char;
56
+ this.state.buffer = '';
57
+ }
58
+ else
59
+ this.state.buffer += char;
60
+ break;
61
+ case HtmlParser.Attribute:
62
+ // Start an attribute quote.
63
+ if (!this.state.quote && !this.state.buffer.length && (char === '"' || char === "'")) {
64
+ this.state.quote = char;
65
+ }
66
+ else if (char === this.state.quote || (!this.state.quote && this.state.buffer.length)) {
67
+ onContextChange?.(html, i, this.state.context, HtmlParser.Tag);
68
+ this.state.context = HtmlParser.Tag;
69
+ this.state.quote = null;
70
+ this.state.buffer = '';
71
+ }
72
+ else if (!this.state.quote && char === '>') {
73
+ onContextChange?.(html, i+1, this.state.context, HtmlParser.Text);
74
+ this.state.context = HtmlParser.Text;
75
+ this.state.quote = null;
76
+ this.state.buffer = '';
77
+ }
78
+ else if (char !== ' ')
79
+ this.state.buffer += char;
80
+
81
+ break;
82
+ }
83
+ }
84
+ onContextChange?.(html, html.length, this.state.context, null);
85
+ return this.state.context;
86
+ }
87
+ }
88
+
89
+ HtmlParser.Attribute = 'Attribute';
90
+ HtmlParser.Text = 'Text';
91
91
  HtmlParser.Tag = 'Tag';