solarite 0.8.0 → 0.9.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 +340 -166
- package/dist/Solarite.js +339 -165
- package/dist/Solarite.min.js +2 -2
- package/dist/jsx-dev-runtime.min.js +3 -0
- package/dist/jsx-runtime.min.js +2 -0
- package/package.json +2 -2
- package/readme.md +6 -6
- package/src/Globals.js +22 -2
- package/src/NodeGroup.js +5 -5
- package/src/PathToAttribValue.js +122 -56
- package/src/PathToComponent.js +104 -90
- package/src/PathToEvent.js +16 -2
- package/src/RootNodeGroup.js +22 -5
- package/src/Shell.js +37 -6
- package/src/Solarite.d.ts +14 -12
- package/src/Util.js +13 -0
package/dist/Solarite.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Solarite v0.
|
|
2
|
-
function t(t,e,i=O){let l=i!==O,s=e.length;if(!t&&!l&&s)return;let n=0;for(let r of e){if(void 0===t[r]){if(!l)return;s-1>n&&(t[r]=(e[n+1]+"").match(/^\d+$/)?[]:{})}l&&n===s-1&&(t[r]=i);t=t[r];n++}return t}function e(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)}function i(t,e){let i=t[I];if(void 0!==i)return i instanceof V?i.key===e?i:void 0:i[e]}function l(t,e,i=!1){let l=t[z];void 0===l&&(l=t[z]=new Set);if(!l.has(e)){l.add(e);t.addEventListener(e,s)}if(i){let i=t.ownerDocument??document,l=i[z];void 0===l&&(l=i[z]=new Set);if(!l.has(e)){l.add(e);i.addEventListener(e,s)}}}function s(t){if(t[G])return;t[G]=!0;let e=H[t.type],i=t.target;Object.defineProperty(t,"currentTarget",{configurable:!0,get:()=>i});for(;i;){let l=i[e];if(void 0!==l){let e=i[F];if("function"==typeof l)l.call(e,t,i);else switch(l.length){case 1:l[0].call(e,t,i);break;case 2:l[0].call(e,l[1],t,i);break;case 3:l[0].call(e,l[1],l[2],t,i);break;default:l[0].call(e,...l.slice(1),t,i)}if(t.cancelBubble)break}i=i.parentNode}delete t.currentTarget}function n(t){if(null===t||"object"!=typeof t)return t;let e="";for(let i in t){let l=t[i];null!=l&&!1!==l&&(e+=(e?";":"")+$.t(i)+":"+l)}return e}function r(t){return(""+t).replace(/&/g,"&").replace(/"/g,""")}function o(t,e,i=[],l){e=e||{};if(t===J){let t=[""];for(let e=0;i.length>e;e++)t.push("");return new Et(t,i)}if("function"==typeof t){if(t.prototype instanceof HTMLElement)return f($.i(t),e,i,l);let s={};for(let t in e)"key"!==t&&(s[t]="style"===t?n(e[t]):e[t]);!("children"in s)&&i.length&&(s.children=1===i.length?i[0]:i);let r=t(s);void 0===l&&(l=e.key);void 0!==l&&r instanceof Et&&(r.key=l);return r}return f(t,e,i,l)}function f(t,e,i,l){let s=_.has(t.toLowerCase()),o=[],f=[],h="";for(let t in e){if("children"===t)continue;if("key"===t){void 0===l&&(l=e[t]);continue}let i=e[t];if("id"!==t&&"data-id"!==t||"string"!=typeof i){"style"===t&&(i=n(i));o.push(t);f.push(i)}else h+=` ${t}="${r(i)}"`}let u=s?0:i.length,a=t+h+"\0"+o.join("\0")+"\0#"+u,c=B.get(a);if(!c){c=((t,e,i,l,s)=>{let n=[],r="<"+t+e;for(let t of i){n.push(r+" "+t+"=");r=""}r+=">";if(s){n.push(r);return n}if(0===l)n.push(r+"</"+t+">");else{n.push(r);for(let t=1;l>t;t++)n.push("");n.push("</"+t+">")}return n})(t,h,o,u,s);B.set(a,c)}let p=s?f:f.concat(i),d=new Et(c,p);void 0!==l&&(d.key=l);return d}function h(t){if("string"!=typeof t){if(void 0!==t.key)return t.key;if(t.html!==st){st=t.html;nt=ft.get(t.html,t.o).l}return 0>nt?void 0:t.exprs[nt]}}function u(t){let e=new Et([t],[]);e.h=!0;return e}function a(t,e){let i=t.u;return i===e||("string"==typeof e?!0===i.h&&i.html[0]===e:g(i,e))}function c(t,e){let i=t.u;return"string"==typeof e?!0===i.h:i.html===e.html&&i.o===e.o}function p(t,e,i){for(let l=0;e>l;l++)if(t[l]===i)return!0;return!1}function d(t,e,i){let l=e.p,s=e.m;if(l===s)t.insertBefore(l,i);else for(;;){let e=l.nextSibling;t.insertBefore(l,i);if(l===s)break;l=e}}function y(t,e,i,l){if(e.length){let l=new Set(i);for(let i of e)l.has(i)||i.parentNode!==t||t.removeChild(i)}let s=l;for(let e=i.length;e--;){let l=i[e];l.nextSibling===s&&l.parentNode===t||t.insertBefore(l,s);s=l}}function m(t){let e=1===t.nodeType&&at.includes(t.tagName),i=t.firstChild;for(;i;){let t=i.nextSibling;1===i.nodeType?m(i):e&&3===i.nodeType&&!i.nodeValue.trim()&&i.remove();i=t}}function b(t,e,i,l){for(;e.length>i;i+=2,l++){let s,n=e[i+1];if(0>n){s=t[e[i]];do{s=s.nextSibling}while(0>++n)}else{s=t[e[i]].firstChild;for(;n>0;n--)s=s.nextSibling}t[l]=s}return t}function w(t){let e=St.get(t);if(void 0===e){e="~@"+vt++;St.set(t,e)}return e}function g(t,e){if(t.html===e.html&&t.o===e.o){let i=t.exprs,l=e.exprs;for(let t=0;i.length>t;t++){let e=i[t],s=l[t];if(e!==s&&!v(e,s))return!1}return!0}return t.h===e.h&&!t.exprs.length&&!e.exprs.length&&1===t.html.length&&1===e.html.length&&t.o===e.o&&t.html[0]===e.html[0]}function v(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(!v(t[i],e[i]))return!1;return!0}return t instanceof Et&&e instanceof Et&&g(t,e)}function S(t){if("string"==typeof t){let e=N.v.createElement("template");e.innerHTML=t;let i=$.S(e.content.childNodes);return 1===i.length?i[0]:e.content}if(t instanceof Et)return t.render();if(t&&"object"==typeof t){let e=t;if("Object"!==e.constructor.name)throw Error(`Solarite web component class ${e.constructor?.name} must extend HTMLElement.`);if(!N.A.has(e)){N.A.set(e,null);e[At]();let t=N.A.get(e);N.A.delete(e);for(let i in e)t[i]="function"==typeof e[i]?e[i].bind(t):e[i];return t}}throw Error("toEl() does not support argument of type: "+(t?typeof t:t))}function E(t,...e){let i=new Et(t,e);i.o=!0;return i}function A(t=xt,...e){if(Array.isArray(t))return new Et(t,e);if("string"==typeof t||t instanceof String){let i=t;if(!e.length||"object"!=typeof e[0]&&null!==e[0]){let t=i;/^\s+</.test(t)&&(t=t.trim());return new Et([t],[])}return o(i+"",e[0]||{},e.slice(1))}if("function"==typeof t||t===J)return o(t,e[0]||{},e.slice(1));if(t instanceof HTMLElement||t instanceof DocumentFragment){if(!(e[0]instanceof Et)){let i=t,l=e[0],s=i[kt];if(s)return s;let n=(t,...e)=>{i.shadowRoot&&(i.innerHTML="");N.k.add(i);return new Et(t,e).render(i,l)};i[kt]=n;return n}e[0].render(t,e[1])}else{if(t===xt)return(t,...e)=>S(A(t,...e));if("object"!=typeof t||!N.A.has(t)){if($.T(t))return new Et;throw Error("h() does not support argument of type: "+(t?typeof t:t))}{let i=t;if(!(e[0]instanceof Et))return((...t)=>{let e=A(...t).render();N.A.set(i,e)}).bind(i);{let t=e[0].render();N.A.set(i,t)}}}}function k(t,e){return e===Date?new Date(t):e===Boolean?!["false","0"].includes(t):e?e(t):t}function x(t,e={},i=[]){for(let l of t.attributes){let s=$.N(l.name);if(!(s in t)||i.includes(s))continue;let n=l.value,r=e[s];n.startsWith("${")&&n.endsWith("}")?t[s]=JSON.parse(n.slice(2,-1)):r?t[s]=k(n,r):""===n&&("function"==typeof t[s]||"object"==typeof t[s]&&null!==t[s])||(t[s]=n)}}var T;!function t(){T={connected:new WeakSet,O:null,div:document.createElement("div"),v:document,$:{},L:{},P:new WeakMap,A:new WeakMap,k:new WeakSet,j:new WeakMap,reset:t}}();var N=T;let O={},$={C(t,e){let i=t.length;if(i!==e.length)return!1;for(let l=0;i>l;l++)if(t[l]!==e[l])return!1;return!0},R(t,e=null){let i={};for(let l of t.attributes)l.name!==e&&(i[$.N(l.name)]=l.value);return i},M(e,i){let l=i.getAttribute("data-id")||i.getAttribute("id");if(l){if(!l.includes(".")){let t=e[l],i=l in e&&!Object.hasOwn(e,l);if(!t?.nodeType&&(null!=t||i))throw Error(`Solarite: id="${l}" would overwrite an existing ${e.constructor.name} property.`)}t(e,l.split(/\./g),i)}},I(t,e){let i=e.tagName.toLowerCase(),l="";if(t.hasAttribute("global")||t.hasAttribute("data-global")){let e=N.v.head;if(e.querySelector(`style[data-style="${i}"]`))t.remove();else{e.append(t);t.setAttribute("data-style",i)}}else{let t=e.getAttribute("data-style");if(!t){let i=e.constructor;e.setAttribute("data-style",t=i.D=(i.D||0)+1)}l=`[data-style="${t}"]`}for(let e of t.childNodes)if(3===e.nodeType){let t=e.textContent,s=t.replace(/:host(?:\(((?:[^()]|\([^()]*\))*)\)|(?![-a-z0-9_(]))/gi,`${i}${l}$1`);t!==s&&(e.textContent=s)}},t:t=>t.replace(/[a-z0-9](?=[A-Z])|[A-Z](?=[A-Z][a-z])|[a-zA-Z](?=\d)/g,"$&-").toLowerCase(),N:t=>t.replace(/-([a-z])/g,t=>t[1].toUpperCase()),i(t,e){let i=customElements[P](t);if(i)return i;(e=e||$.t(t.name)).includes("-")||(e+="-element");customElements[L](e,t);return e},H: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,F:t=>t.startsWith("on")&&t in N.div,G(t,e){let i=t.tagName+"."+e,l=N.L[i];if(void 0===l){let s=Object.getPrototypeOf(t);for(;s;){const t=s.constructor.name;if(t.startsWith("HTML")&&t.endsWith("Element"))break;s=Object.getPrototypeOf(s)}N.L[i]=l=!!s&&!!Object.getOwnPropertyDescriptor(s,e)?.set}return l},T:t=>void 0===t||!1===t||null===t,V(){return{}},W:t=>"function"==typeof t?$.W(t()):t instanceof Date?t.toISOString().replace(/T/," "):Array.isArray(t)||"object"==typeof t?"":t,J(t){N.v.createDocumentFragment().append(...t)},S(t){let e=t=>1!==t.nodeType&&(3!==t.nodeType||!t.textContent.trim()),i=[...t];for(;i.length&&e(i[0]);)i.shift();for(;i.length&&e(i[i.length-1]);)i.pop();return i}},L="define",P="getName";class j{K;_;B=!1;U;Z;Y;q=!1;X;constructor(t,e){this.K=t;this._=e}tt(t){this.et(t[0])}et(t){}it(){return 1}lt(t){return t[0]}st(t,e){let i=new this.constructor(t,e,this.nt,this.rt);i.Y=this.Y;i.B=this.B;i.X=this.X;return i}clone(t,e=0){let i,l=j.resolve(t,this.ot,e);this.K&&(i=(l===t?t:l.parentNode).childNodes[this.ft]);return this.st(i,l)}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,i=0){for(let l=e.length-1-i;l>=0;l--)t=t.childNodes[e[l]];return t}}class C{selector;selected;constructor(t,e){this.selector=t;this.selected=e}value(){let t=this.selector;return this.selected?t.ht:t.ut}bind(t,e,i){if(i.p!==t)throw Error("Solarite: a selector must be on the row's root element.");let l=this.selector;l.nt=e;l.path=i.ct;let s=this.selected?l.ht:l.ut;""===s||!1===s||null==s?!0!==i.dt&&t.removeAttribute(e):t.setAttribute(e,s)}}class R{#t=null;#e=new C(this,!0);#i=new C(this,!1);ht;ut="";nt=null;path=null;constructor(t=null){this.#t=t}get key(){return this.#t}when(t,e,i=""){this.ht=e;this.ut=i;return t===this.#t?this.#e:this.#i}set(t){let e=this.#t;if(e!==t){this.#t=t;if(null!==this.path){this.#l(e,this.ut);this.#l(t,this.ht)}}}#l(t,e){if(null==t)return;let i=this.path.yt;if(null===i||0===i.length)return;if(void 0===i[0].key)throw Error("Solarite: a selector must be on a keyed list, as key=${...}.");let l=null;for(let e=0;i.length>e;e++)if(i[e].key===t){l=i[e];break}if(null===l)return;let s=l.p;null!==s&&1===s.nodeType&&(""===e||!1===e||null==e?s.removeAttribute(this.nt):s.setAttribute(this.nt,e))}}class M extends j{nt;rt;constructor(t,e,i=null,l=null){super(null,e);this.nt=i;this.rt=l}tt(t){if(this.rt){let e=this._,i=this.lt(t),l=this.X;if((l?e[this.nt]:e.getAttribute(this.nt))!==i){l?e[this.nt]=i:"value"===this.nt&&e.hasAttribute("contenteditable")&&(e.innerHTML=i);e.setAttribute(this.nt,i)}}else this.et(t[0])}et(i){if(this.rt)return this.tt([i]);let l=this._;if(e(i)){if(this.Y&&l.tagName.endsWith("-SOLARITE-PLACEHOLDER"))return;let[e,s]=[i[0],i.slice(1)];if(!e)throw Error(`Solarite cannot bind ${this.nt} to ${e}.`);let n=t(e,s);if("value"===this.nt&&"select-multiple"===l.type&&Array.isArray(n)){let t=n.map(t=>t+"");for(let e of l.options)e.selected=t.includes(e.value)}else if("radio"===l.type)l.checked=l.value===n+"";else{const t=$.T(n)?"":n;"value"===this.nt&&l.hasAttribute("contenteditable")?t!==l.innerHTML&&(l.innerHTML=t):t!==l[this.nt]&&(l[this.nt]=t)}let r=()=>{let i="value"===this.nt||"radio"===l.type?$.H(l):l[this.nt];t(e,s,i)};this.bt(l,this.U.wt(),this.nt,"input",r,null,!0)}else{if("object"==typeof i&&i instanceof C){this.Y||i.bind(l,this.nt,this.U);return}let t=this.X;if("function"==typeof i){if(this.Y)return;i=i()}else i=$.W(i);if(void 0===i||!1===i||null===i||""===i&&!t){t&&(l[this.nt]="boolean"!=typeof l[this.nt]&&"");l.removeAttribute(this.nt)}else if(!0===i){t&&(l[this.nt]=!0);l.setAttribute(this.nt,"")}else if((t?l[this.nt]:l.getAttribute(this.nt)??"")!==i){t?l[this.nt]=i:"value"===this.nt&&l.hasAttribute("contenteditable")&&(l.innerHTML=i);l.setAttribute(this.nt,i)}}}it(){return this.rt?this.rt.length-1:1}lt(t){if(!this.rt)return t[0];let e=[],i=this.rt;for(let l=0;i.length>l;l++){e.push(i[l]);if(i.length-1>l){if("object"==typeof t[l]&&t[l]instanceof C)throw Error(`Solarite: a selector must own the whole ${this.nt} attribute.`);let i=$.W(t[l]);$.T(i)||e.push(i)}}return e.join("")}bt(t,e,i,s,n,r,o=!1){if(!1===o&&void 0!==this.gt){let i=this.U.St.vt?.eventDelegation??!0,o="document"===i;if(!1!==i&&(!0===i||o||i.includes(s))){let i=this.gt;void 0===t[i]&&l(e,s,o);t[i]=r||n;t[F]=e;return}}let f,h=r||[n],u=t[I];if(void 0!==u){if(u instanceof V){if(u.key!==i){let l=t[I]={};l[u.key]=u;f=l[i]=new V(e,t,i,h);t.addEventListener(s,f,o);return}f=u}else{f=u[i];if(!f){f=u[i]=new V(e,t,i,h);t.addEventListener(s,f,o);return}}f.Et=e;f.At=h}else{let l=t[I]=new V(e,t,i,h);t.addEventListener(s,l,o)}}}const I=Symbol(),D=new Set(["beforeinput","click","contextmenu","dblclick","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),H={},F=Symbol(),z=Symbol(),G=Symbol();class V{constructor(t,e,i,l){this.Et=t;this.node=e;this.key=i;this.At=l}handleEvent(t){let e=this.At;switch(e.length){case 1:return e[0].call(this.Et,t,this.node);case 2:return e[0].call(this.Et,e[1],t,this.node);case 3:return e[0].call(this.Et,e[1],e[2],t,this.node)}return e[0].call(this.Et,...e.slice(1),t,this.node)}}class W extends M{kt;gt;constructor(t,e,i=null,l=null){super(null,e,i,l);this.q=!0;this.kt=i?i.slice(2):null;this.gt=null!==this.kt?(t=>{if(D.has(t))return H[t]??=Symbol("sol$"+t)})(this.kt):void 0}tt(t){this.rt?.length>1?super.tt(t):this.et(t[0])}et(t){if(this.rt?.length>1)return super.tt([t]);if(this.Y&&this._.tagName.endsWith("-SOLARITE-PLACEHOLDER"))return;let e,i=this.U.St.Et,l=this._,s=this.kt;if(Array.isArray(t)&&"function"==typeof t[0])e=t[0];else{if("function"!=typeof t)throw Error(`Solarite: ${this.nt}=\${...} is not a function.`);e=t;t=null}this.bt(l,i,s,s,e,t)}}const J=Symbol();class K{constructor(t,e){this.name=t;this.value=e}}const _=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),B=new Map;class U extends j{xt;Tt;Nt;constructor(t,e){super(null,e);this.xt=new Set}et(t){let e=this._;if(t instanceof K)return this.Ot(t);Array.isArray(t)&&(t=t.flat().join(" "));let i=this.xt;this.xt=new Set;if(t){"function"==typeof t&&(t=t());if("object"==typeof t)for(let i in t){let l=t[i];if(void 0!==l&&!1!==l&&null!==l){e.setAttribute(i,l);this.xt.add(i)}}else{let i=$.V(t);for(let t in i){e.setAttribute(t,i[t]);this.xt.add(t)}}}for(let t of i)this.xt.has(t)||e.removeAttribute(t)}Ot(t){let e=t.name;if("key"===e)return;let i=t.value,l=this.Tt;if(void 0===l||this.Nt!==e){let t=this._;if($.F(e))l=new W(null,t,e,null);else{l=new M(null,t,e,null);l.X=$.G(t,e)}l.Y=this.Y;this.Tt=l;this.Nt=e}l._=this._;l.U=this.U;"style"===e&&(i=n(i));l.et(i)}}class Z{data={};add(t,e){let i=this.data,l=i[t];l?l.push(e):i[t]=[e]}$t(t,e,i){let l=this.data,s=l[t];s?i>s.length-(s.Lt||0)&&s.push(e):l[t]=[e]}Pt(t){let e=this.data,i=e[t];if(!i)return;let l=i.Lt||0,s=i[l];l++;i.length>l?i.Lt=l:delete e[t];return s}}class Y{items;jt;constructor(t,e){this.items=t;this.jt=e}*[Symbol.iterator](){let t=this.items,e=this.jt;for(let i=0;t.length>i;i++)yield e(t[i])}}class q extends j{Rt=!1;Mt=null;It=!1;yt=null;Dt=null;Ht=null;Ft=null;zt=null;constructor(t,e){super(t,e)}et(t){let e=typeof t;if(("string"===e||"number"===e)&&!this.It){"string"!==e&&(t+="");let i=this.Dt;if(null!==i){if(this.Ht!==t){i.nodeValue=t;this.Ht=t}return}let l=this.yt;if(null===l||0===l.length){let e;if(this.B){let i=this._.firstChild;if(null!==i&&3===i.nodeType&&i===this._.lastChild){i.nodeValue!==t&&(i.nodeValue=t);this.Dt=i;this.Ht=t;return}this._.textContent=t;e=this._.firstChild}else{e=N.v.createTextNode(t);this._.parentNode.insertBefore(e,this._)}this.Dt=e;this.Ht=t;if(!this.U.dt){this.Z=null;this.U.ct&&this.U.ct.Gt()}return}if(1===l.length){let e=l[0],i=e.u;if(!0===i.h){if(i.html[0]!==t){e.p.nodeValue=t;i.html[0]=t;e.Vt=t}return}}}if(null!==this.Dt){let t=new wt(u(this.Ht),this,this.Dt);(this.yt??=[]).push(t);this.Dt=null}if(t instanceof C)throw Error("Solarite: a selector must own the whole attribute.");if(t instanceof Y){this.Wt(t);return}this.Mt=null;let i=null,l=!1;if(Array.isArray(t)){let e=t.length,l=0;for(;e>l&&t[l]instanceof Et;)l++;l===e&&(i=t)}if(null===i){i=[];l=this.Jt(t,i,!1)}if(l||this.It){this.It=l;this.Kt(i)}else this._t(i)}_t(t){let e=0!==t.length?t[0]:null;(null!==e?"string"==typeof e||void 0===e.key&&0>ft.get(e.html,e.o).l:null===this.yt||0===this.yt.length||void 0===this.yt[0].key)?this.Bt(t):this.Ut(t)}Wt(t){let e=t.items,i=t.jt,l=e.length,s=this.yt,n=this.Mt,r=null===s||null===n||n.length!==s.length?0:s.length,o=null,f=null,h=0;if(r===l&&0!==l&&!this.Rt&&!this.It){let t=!1,u=Q;for(let i=0;l>i;i++)if(n[i]!==e[i]){if(h===u){if(p(n,r,e[i])){t=!0;h=0;break}u=l}(o??=[])[h++]=i}if(!t&&0!==h){f=Array(h);for(let l=0;h>l;l++){let s=i(e[o[l]]);if(!(s instanceof Et)&&"string"!=typeof s){t=!0;h=l;break}f[l]=s}}if(!t&&(0===h||this.Zt(s,o,f,h,l))){for(let t=0;h>t;t++){let i=o[t];n[i]=e[i]}return}}let u=Array(l),a=0!==h?o:null,c=0,d=null,y=!1;const m=t=>{if(y)return-1;if(null===d){if(!p(n,r,t)){y=!0;return-1}d=new Map;for(let t=0;r>t;t++)d.set(n[t],t)}let e=d.get(t);return void 0===e?-1:e};if(0!==r){let t=0,o=!0;for(let p=0;l>p;p++){let d=e[p],y=p+t,b=y>=0&&r>y;if(b&&n[y]===d){u[p]=s[y].u;o=!0}else if(null!==a&&h>c&&a[c]===p)u[p]=f[c++];else{if(o){let f=-1;for(let t=1;et>=t;t++){let e=y+t,i=y-t;if(r>e&&n[e]===d){f=e;break}if(i>=0&&n[i]===d){f=i;break}}if(f>=0){t=f-p;u[p]=s[f].u;continue}if(b&&l>r)for(let s=1;it>=s&&l>p+s;s++)if(e[p+s]===n[y]){u[p]=i(d);t--;f=-2;break}if(-2===f)continue;o=!1}if(r>y){let e=m(d);if(e>=0){u[p]=s[e].u;t=e-p;o=!0;continue}}u[p]=i(d)}}}else for(let t=0;l>t;t++)u[t]=i(e[t]);let b=0!==l?u[0]:null;if(null!==b&&!(b instanceof Et)&&"string"!=typeof b){let t=[],e=this.Jt(u,t,!1);if(e||this.It){this.It=e;this.Kt(t)}else this._t(t);return}if(this.It){this.It=!1;this.Kt(u);return}this._t(u);let w=this.Mt;null!==w&&w.length===l||(w=this.Mt=Array(l));for(let t=0;l>t;t++)w[t]=e[t]}Zt(t,e,i,l,s){let n=void 0!==t[0].key,r=null,o=0;for(let s=0;l>s;s++){let l=t[e[s]],f=i[s];if("string"==typeof f||!c(l,f)||n&&l.key!==h(f)){if(!n||o===tt)return!1;(r??=[])[o++]=s}}for(let s=0,n=0;l>s;s++){if(o>n&&r[n]===s){n++;continue}let l=t[e[s]],f=i[s];a(l,f)?this.Yt(l,f):this.qt(l,f)}if(0===o)return!0;let f=this.B;this.Xt(r,e,t,i,t,s,f?null:this._,f?this._:this._.parentNode);if(!this.U.dt){this.Z=null;this.U.ct&&this.U.ct.Gt()}this.Ft&&(this.Ft=null);return!0}Xt(t,e,i,l,s,n,r,o){let f=t.length,u=Array(f);for(let l=0;f>l;l++){let s=t[l];u[l]=i[null===e?s:e[s]]}let p=Array(f);for(let e=0;f>e;e++){let i=l[t[e]],s=h(i);if(void 0!==s)for(let t=0;f>t;t++){let l=u[t];if(null!==l&&l.key===s&&c(l,i)){u[t]=null;a(l,i)?this.Yt(l,i):this.qt(l,i);p[e]=l;break}}}for(let t=0;f>t;t++){let e=u[t];null!==e&&(e.p!==e.m?$.J(e.Qt()):e.p.remove())}for(let i=f-1;i>=0;i--){let f=t[i],h=null===e?f:e[f],u=p[i];void 0===u&&(u=this.te(l[f]));s[h]=u;let a=n>h+1?s[h+1].p:r;u.m.nextSibling===a&&u.p.parentNode===o||d(o,u,a)}}Bt(t){let e=this.yt||X,i=e.length,l=t.length,s=Array(l),n=0,r=i,o=l;for(;r>n&&o>n;){let i=e[n],l=t[n];if(!a(i,l))break;i.ie.ee&&this.Yt(i,l);s[n]=i;n++}for(;r>n&&o>n;){let i=e[r-1],l=t[o-1];if(!a(i,l))break;i.ie.ee&&this.Yt(i,l);s[--o]=i;r--}for(;r>n&&o>n;){let i=e[n],l=t[n];if(a(i,l))i.ie.ee&&this.Yt(i,l);else{if(!c(i,l))break;this.qt(i,l)}s[n]=i;n++}let f=r-n,h=o-n;if(f||h){if(f){for(let t=n;r>t;t++){let i=e[t];i.p!==i.m&&i.Qt()}let t=0===l&&0===n&&this.le(),i=this.zt??=new Z;for(let l=n;r>l;l++){let s=e[l];s.p!==s.m?$.J(s.Qt()):t||s.p.remove();s.u.h||i.$t(s.Vt,s,lt)}}if(h){let e=this.B,i=l>o?s[o].p:e?null:this._,r=e?this._:this._.parentNode;for(let e=n;o>e;e++){let l=this.se(t[e]);s[e]=l;d(r,l,i)}}if(!this.U.dt){this.Z=null;this.U.ct&&this.U.ct.Gt()}}this.yt=s;this.Ft&&(this.Ft=null)}Ut(t){let e=this.yt||X,i=e.length,l=t.length,s=Array(l),n=0,r=i,o=l;for(;r>n&&o>n;){let i=e[n],l=t[n];if(i.u===l)i.ie.ee&&this.Yt(i,l);else{if("string"==typeof l||i.key!==h(l)||!c(i,l))break;a(i,l)?this.Yt(i,l):this.qt(i,l)}s[n]=i;n++}for(;r>n&&o>n;){let i=e[r-1],l=t[o-1];if(i.u===l)i.ie.ee&&this.Yt(i,l);else{if("string"==typeof l||i.key!==h(l)||!c(i,l))break;a(i,l)?this.Yt(i,l):this.qt(i,l)}s[--o]=i;r--}let f=r-n,u=o-n;if(f||u){let i=this.B,p=i?this._:this._.parentNode,y=!1;if(f===u){let r=null,f=!0;for(let i=n;o>i;i++){let l=e[i],n=t[i];if(l.u===n)l.ie.ee&&this.Yt(l,n);else{let t=h(n);if(void 0===t||l.key!==t||!c(l,n)){(r??=[]).push(i);if(r.length>8){f=!1;break}continue}a(l,n)?this.Yt(l,n):this.qt(l,n)}s[i]=l}if(f){null!==r&&this.Xt(r,null,e,t,s,o,l>o?s[o].p:i?null:this._,p);y=!0}}if(!y){let y=0,m=!1,b=null,w=null;if(f&&u){let i=new Map;for(let e=n;o>e;e++){let l=t[e];"string"!=typeof l&&i.set(h(l),e)}b=Array(u).fill(-1);let l=-1;for(let o=n;r>o;o++){let r,f=e[o],h=void 0===f.key?void 0:i.get(f.key);if(void 0!==h&&-1===b[h-n]&&c(f,r=t[h])){b[h-n]=o;y++;l>h?m=!0:l=h;a(f,r)?this.Yt(f,r):this.qt(f,r);s[h]=f}else(w??=[]).push(f)}}let g=null,v=null;if(i&&0===n&&o===l&&0===y&&u>500&&p.isConnected&&null!==p.parentNode&&-1===p.localName.indexOf("-")&&!p.hasAttribute("is")){g=p.parentNode;v=p.nextSibling;p.remove()}let S=0!==f&&0===u;if((null!==w||S)&&(0!==n||o!==l||0!==y||!this.le())){S&&(w=e.slice(n,r));for(let t of w)t.p!==t.m&&t.Qt();for(let t of w)t.p!==t.m?$.J(t.Qt()):t.p.remove()}if(u){let e=l>o?s[o].p:i?null:this._;if(0===y)for(let i=n;o>i;i++){let l=this.te(t[i]);s[i]=l;d(p,l,e)}else{let i=m?(t=>{let e=[],i=Array(t.length);for(let l=0;t.length>l;l++){let s=t[l];if(-1===s)continue;let n=0,r=e.length;for(;r>n;){let i=n+r>>1;s>t[e[i]]?n=i+1:r=i}n>0&&(i[l]=e[n-1]);n===e.length?e.push(l):e[n]=l}let l=e.length;if(l){let t=e[l-1];for(;l-- >0;){e[l]=t;t=i[t]}}return e})(b):null,l=null!==i?i.length-1:-1;for(let r=o-1;r>=n;r--){let o=s[r];if(void 0===o){o=this.te(t[r]);s[r]=o;d(p,o,e)}else null!==i&&(0>l||i[l]!==r-n?d(p,o,e):l--);e=o.p}}}null!==g&&g.insertBefore(p,v)}if(!this.U.dt){this.Z=null;this.U.ct&&this.U.ct.Gt()}}this.yt=s;this.Ft&&(this.Ft=null)}te(t){if("string"==typeof t)return new wt(u(t),this);let e=new wt(t,this);e.ie.ee&&(this.Rt=!0);(t.exprs.length||e.ne&&e.ne.length)&&e.re(t.exprs);return e}Yt(t,e){let i=t.ie;i.oe?t.re(e.exprs,!1):i.fe&&i.he&&"string"!=typeof e&&this.qt(t,e)}qt(t,e){if("string"==typeof e){t.p.nodeValue=e;t.u.html[0]=e;t.Vt=e}else{if(t.ie.he){if(null!==t.ne||!t.ue(e)){let i=t.u.exprs,l=e.exprs,s=t.ne??t.ae();for(let t=s.length-1;t>=0;t--){let e=i[t],n=l[t];(e!==n&&!v(e,n)||s[t].X&&"boolean"==typeof n)&&s[t].et(n)}}t.styles&&t.ce();t.Z=null;t.dt=!1}else t.re(e.exprs);t.u=e;void 0!==e.key&&(t.key=e.key)}}se(t){let e;if("string"==typeof t){t=u(t);return new wt(t,this)}let i=this.zt;if(i){e=i.Pt(t.pe());if(e){this.qt(e,t);return e}}e=new wt(t,this);e.ie.ee&&(this.Rt=!0);(t.exprs.length||e.ne&&e.ne.length)&&e.re(t.exprs);return e}Jt(t,e,i){if(t instanceof Et)e.push(t);else if(Array.isArray(t))for(let l of t)l instanceof Et?e.push(l):i=this.Jt(l,e,i);else if("function"==typeof t)i=this.Jt(t(),e,i);else if(t instanceof Y){let i=t.items,l=t.jt;for(let t=0;i.length>t;t++)e.push(l(i[t]))}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}Kt(t){let e=this;e.de();let i=[],l=e.yt||X;e.yt=[];for(let l of t){"string"==typeof l&&(l=u(l));if(l instanceof Et){let t=e.ye(l);i.push(...t.Qt());e.yt.push(t)}else i.push(l)}let s=e.Qt();if(!$.C(s,i)){e.Z=i;this.U.ct&&this.U.ct.Gt();s.length&&!i.length&&e.le()||(e.B?y(e._,s,i,null):y(e._.parentNode,s,i,e._));for(let t of l)t.p.parentNode||$.J(t.Qt())}}Gt(){let t=this,e=this.B?this._:this._.parentNode;for(;t&&(t.B?t._:t._.parentNode)===e;){t.Z=null;t=t.U?.ct}}le(){if(this.B){this._.textContent="";return!0}let t=this.K.parentNode;if(this.K===t.firstChild&&this._===t.lastChild){t.innerHTML="";t.append(this.K,this._);return!0}return!1}ye(t){let e=t.pe(),i=this.Ft?.Pt(e)||this.zt?.Pt(e);if(i){g(i.u,t)?this.Yt(i,t):i.re(t.exprs);i.u=t}else{i=new wt(t,this);i.ie.ee&&(this.Rt=!0);i.re(t.exprs)}return i}de(){let t=this.Ft?.data;if(t){let e=(this.zt??=new Z).data;for(let i in t){let l=t[i],s=l.Lt||0,n=e[i];if(n)for(let t=s,e=lt+(n.Lt||0);l.length>t&&e>n.length;t++)n.push(l[t]);else{n=e[i]=s?l.slice(s):l;n.length>lt&&(n.length=lt)}}}let e=this.Ft=new Z;if(this.yt)for(let t of this.yt)e.add(t.Vt,t)}Qt(){let t;t=this.Z;if(t)return t;t=[];let e,i=null;if(this.B)e=this._.firstChild;else{e=this.K.nextSibling;i=this._}for(;e&&e!==i;){t.push(e);e=e.nextSibling}this.Z=t;return t}}const X=[],Q=256,tt=16,et=4,it=64,lt=1e4;let st=null,nt=-1;class rt extends j{et(t){this.U.key=t}}class ot extends j{me;be;constructor(t,e){super(null,e)}tt(i){let l=(t=>{const e=new Set;return JSON.stringify(t,(t,i)=>{if("function"==typeof i)return w(i);if("object"==typeof i&&null!==i){if(i instanceof Node)return w(i);if(e.has(i))return w(i);e.add(i);if(i instanceof Et)return{html:w(i.html),exprs:i.exprs}}return i})})(i),s=l!==this.be;this.be=l;let n=this._,r=$.R(n,"_is");for(let l,s=0;l=this.me[s];s++)if(!(l instanceof rt||l instanceof W))if(l instanceof M){let n=$.N(l.nt),o=l.lt(i[s]);!l.rt&&e(o)&&(o=t(o[0],o.slice(1)));r[n]=o}else{let t=l.lt(i[s]);if("object"==typeof t)for(let e in t)r[$.N(e)]=t[e];else if("string"==typeof t){let e=$.V(t);for(let t in e)r[$.N(t)]=e[t]}}let o=n.getAttribute("_is");if(n.tagName.endsWith("-SOLARITE-PLACEHOLDER")||o){let e=(o||n.tagName.slice(0,-21)).toLowerCase(),l=customElements.get(e);if(!l){this.we=i;if(!this.ge){this.ge=!0;console.warn(`Solarite: <${e}> is not defined yet; waiting for customElements.define().`);customElements.whenDefined(e).then(()=>{this.ge=!1;let t=this.we;this.we=null;t&&this._===n&&n.tagName.endsWith("-SOLARITE-PLACEHOLDER")&&this.tt(t)})}N.O=null;return}N.O=[...n.childNodes];let s=new l(r);o&&s.setAttribute("is",o);for(let t of n.attributes)"_is"!==t.name&&s.setAttribute(t.name,t.value);for(let t in r){let e=r[t],i=typeof e;"boolean"===i?e&&s.setAttribute(t,""):"string"!==i&&"number"!==i&&"bigint"!==i||s.setAttribute(t,e)}let f=s.getAttribute("data-id")||s.getAttribute("id");f&&t(this.U.wt(),f.split(/\./g),s);let h=this.U;this._=s;for(let t of h.ne){t._===n&&(t._=s);t.K===n&&(t.K=s)}h.p===n&&(h.p=s);h.m===n&&(h.m=s);"function"!=typeof s.render||N.k.has(s)||s.render(r,!0);for(let t,e=0;t=this.me[e];e++){t.U=this.U;t._=s;t.tt(i[e])}n.replaceWith(s)}else"function"==typeof n.render&&n.render(r,s);N.O=null}clone(t,e=0){let i=super.clone(t,e);i.me=this.me.map(i=>i.clone(t,e));return i}it(){return 0}}class ft{ve;ne=[];ids=[];styles=[];scripts=[];oe=!1;fe=!1;he=!1;ee=!1;Se=!1;l=-1;Ee=!1;Ae=!1;Vt;ke;xe;Te;Ne;Oe;$e;Le;Pe;je;constructor(t=null,e=!1){if(!t)return;if(1===t.length&&!t[0].match(/[<&]/)){this.ve=N.v.createTextNode(t[0]);return}let i,l=ft.Ce(t),s=N.v.createElement("template");if(l)if(e){s.innerHTML="<svg>"+l+"</svg>";let t=s.content.firstChild,e=N.v.createDocumentFragment();for(;t.firstChild;)e.append(t.firstChild);this.ve=e}else{s.innerHTML=l;this.ve=s.content}else{s.content.append(N.v.createTextNode(""));this.ve=s.content}m(this.ve);let n=[],r=0;const o=N.v.createTreeWalker(this.ve,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_TEXT);for(;i=o.nextNode();){n.map(t=>t.remove());n=[];if(1===i.nodeType){const t=i.hasAttribute("is"),l=t||i.tagName.includes("-"),s=[];for(let t of[...i.attributes]){if("key"===t.name){let e=t.value.split(/[\ue000-\uf8ff]/g);if(2!==e.length||""!==e[0]||""!==e[1])throw Error("Solarite: key must be one whole expression.");if(i.parentNode!==this.ve)throw Error("Solarite: key must be on a top-level element.");if(this.l>=0)throw Error("Solarite: duplicate key attribute.");this.l=t.value.charCodeAt(0)-yt;let n=new rt(null,i);this.ne.push(n);l&&s.push(n);r++;i.removeAttribute("key");continue}let n=t.name.match(/^[\ue000-\uf8ff]$/);if(n){let t=new U(null,i);this.ne.push(t);if(l){t.Y=!0;s.push(t)}r++;i.removeAttribute(n[0])}else{let n=t.value.split(/[\ue000-\uf8ff]/g);if(n.length>1){let o=2!==n.length||n[0].length||n[1].length?n:null,f=$.F(t.name)?new W(null,i,t.name,o):new M(null,i,t.name,o);f.X=$.G(i,t.name);this.ne.push(f);if(l){f.Y=!0;s.push(f)}r+=n.length-1;e||!o?i.removeAttribute(t.name):i.setAttribute(t.name,n.join(""))}}}if(l){let e=new ot(null,i);e.me=s;this.ne.splice(this.ne.length-s.length,0,e);if(t){i.setAttribute("_is",i.getAttribute("is"));i.removeAttribute("is")}}}else if(8===i.nodeType&&"!\u2728!"===i.nodeValue){if(i?.parentNode?.closest&&i?.parentNode?.closest("[contenteditable]"))throw Error('Solarite: no ${...} inside contenteditable; use value="${...}".');let t=i.parentNode;if(1!==t.nodeType||i.previousSibling||i.nextSibling||t.tagName.includes("-")||"SLOT"===t.tagName||t.hasAttribute("is")){let t,e=i.previousSibling;if(!e){e=N.v.createComment("Path:"+this.ne.length);i.parentNode.insertBefore(e,i)}if(!i.nextSibling||8===i.nextSibling.nodeType&&"!\u2728!"===i.nextSibling.textContent){t=i;t.textContent="PathEnd:"+this.ne.length}else{t=i.nextSibling;n.push(i)}let l=new q(e,t);this.ne.push(l);r++}else{let e=new q(null,t);e.B=!0;this.ne.push(e);r++;n.push(i)}}else if(8===i.nodeType){let t=i.textContent.split(/[\ue000-\uf8ff]/g);for(let e=0;t.length-1>e;e++){let t=new j(i.previousSibling,i);this.ne.push(t);r++}}else if(3===i.nodeType){let t=i.parentNode?.nodeName;if("TEXTAREA"===t&&i.textContent.includes(ht))throw Error('Solarite: no ${...} inside textarea; use value="${...}".');if("SCRIPT"===t||"STYLE"===t){let t=i.textContent.split(ht);if(t.length>1){for(let e=0;t.length>e;e++){let l=N.v.createTextNode(t[e]);i.parentNode.insertBefore(l,i);if(e>0){let t=new q(l.previousSibling,l);this.ne.push(t);r++}}n.push(i)}}}}n.map(t=>t.remove());if(r!==t.length-1)throw Error("Solarite: bad html or duplicate attribute: "+t.join("${...}"));for(let t of this.ne){t.ft=t.K?[].indexOf.call(t.K.parentNode.childNodes,t.K):-1;t.ot=j.get(t._)}this.Re();this.he=!0;for(let t of this.ne){if(t instanceof ot){this.oe=!0;this.he=!1}else 1!==t.it()&&(this.he=!1);t.X&&(this.fe=!0)}this.ee=this.oe||this.fe&&this.he;this.Me();if(this.Ee&&this.he){let t=[],e=!0;for(let i=0;this.ne.length>i;i++){let l=this.ne[i];if(l instanceof q){if(!l.B){e=!1;break}t.push(i)}else if(!(l instanceof M||l instanceof rt)){e=!1;break}}if(e){this.Ae=!0;this.Te=t;this.Ne=this.ne.map(t=>t.st(null,t._));let e=this.ne.length;this.Oe=new Uint8Array(e);this.$e=new Uint16Array(e);this.Le=Array(e).fill(null);this.je=new Uint8Array(e);let i=null;for(let t=0;e>t;t++){let e=this.ne[t],l=this.Ne[t];this.$e[t]=e.Ie;this.je[t]=(l.X?1:0)|(l.B?2:0);if(e instanceof rt)this.Oe[t]=1;else if(l.B)this.Oe[t]=2;else if(l instanceof W&&void 0!==l.gt&&!l.rt){this.Oe[t]=3;this.Le[t]=l;(i??=[]).push(l.kt)}else if(l instanceof M&&!l.rt&&!l.X&&!l.Y){this.Oe[t]=4;this.Le[t]=l.nt}}this.Pe=i}}}static Ce(t){let e="",i=!1,l=null;for(let s=0;t.length>s;s++){let n=t[s],r=0;for(let t=0;n.length>t;t++){const s=n[t];if(i)l?s===l&&(l=null):'"'===s||"'"===s?l=s:">"===s&&(i=!1);else if("<"===s&&n[t+1].match(/[/a-z!]/i)){i=!0;ut.lastIndex=t;let l=ut.exec(n);if(l){let i=t+l[0].length;e+=n.slice(r,i)+"-SOLARITE-PLACEHOLDER";r=i}}}e+=n.slice(r);t.length-1>s&&(e+=i?String.fromCharCode(yt+s):ht)}return e}Re(){this.scripts=[].map.call(this.ve.querySelectorAll("script"),t=>j.get(t));this.styles=[].map.call(this.ve.querySelectorAll("style"),t=>j.get(t));this.ids=[].map.call(this.ve.querySelectorAll("[id],[data-id]"),t=>j.get(t));this.Se=this.ids.length>0||this.styles.length>0||this.scripts.length>0}Me(){if(this.oe||!this.ne.length)return;let t=[],e=new Map,i=this.ve,l=1,s=n=>{if(n===i)return 0;let r=e.get(n);if(void 0===r){let i=0,o=-1;for(let t=n.previousSibling;t;t=t.previousSibling){i++;let l=e.get(t);if(void 0!==l){o=l;break}}let f=[].indexOf.call(n.parentNode.childNodes,n);0>o||i>f+1?t.push(s(n.parentNode),f):t.push(o,-i);r=l++;e.set(n,r)}return r};for(let t of this.ne){t.Ie=t._===i?0:s(t._);t.De=t.K?s(t.K):-1}this.ke=t;this.xe=Array(l);this.Se||1!==i.childNodes.length||1!==i.firstChild.nodeType||2>t.length||0!==t[0]||0!==t[1]||(this.Ee=!0)}static get(t,e=!1){if(t===ct&&e===pt)return dt;let i=N.j.get(t);if(!i){i={};N.j.set(t,i)}let l=e?"svg":"html",s=i[l];s||(s=i[l]=new ft(t,e));ct=t;pt=e;dt=s;return s}}const ht="\x3c!--!\u2728!--\x3e",ut=/<\/?[a-z][a-z0-9]*-[a-z0-9-]+/iy,at=["TABLE","THEAD","TBODY","TFOOT","TR"];let ct=null,pt=!1,dt=null;const yt=57344,mt=new ft,bt=Symbol();class wt{St;ct;p;m;ne=null;Vt;key;ie;dt=!0;Z;He=null;styles;u;constructor(t,e=null,i=null,l=null){this.St=e?.U?.St||this;this.ct=e;this.u=t;void 0!==t.key&&(this.key=t.key);if(t.h){this.ie=mt;this.Vt=t.pe();this.p=this.m=i||N.v.createTextNode(t.html[0])}else{const s=this.ie=ft.get(t.html,t.o);this.Vt=s.Vt??=t.pe();if(s.Ee&&null!==e){const t=s.ve.firstChild.cloneNode(!0);this.p=this.m=t;!0!==s.Ae&&this.Fe(t,s,0,!0)}else{const t=s.ve.cloneNode(!0);if(11===t.nodeType){this.p=t.firstChild;this.m=t.lastChild}else this.p=this.m=t;this.instantiate(s,t,i,l)}}}instantiate(t,e,i,l){t.ne.length?this.Fe(e,t):this.ne=[];t.Se&&this.ze(e,t)}re(t,e=!0,i=null){let l=this.ne;if(this.ie.he){if(e){if(null===l){this.Ge(t);return}for(let e=l.length-1;e>=0;e--){let s=l[e];null!==i&&s.q&&i[e]===t[e]||s.et(t[e])}this.styles&&this.ce();this.Z=null}this.dt=!1;return}if(!l){this.dt=!1;return}let s=t.length,n=Array(l.length);for(let i,r=l.length-1;i=l[r];r--){if(0===r&&i instanceof ot&&i._===this.wt())continue;let l=i.it();n[r]=t.slice(s-l,s);s-=l;if(i instanceof ot){let t=n.slice(r+1,r+1+i.me.length);i.tt(t)}else e&&i.tt(n[r])}if(e){this.ce();this.Z=null}this.dt=!1}Ge(t){let e=this.ie,i=e.Te;for(let l=0;i.length>l;l++){let s=typeof t[i[l]];if("string"!==s&&"number"!==s){let i=this.ae(e);for(let e=i.length-1;e>=0;e--)i[e].et(t[e]);this.Z=null;this.dt=!1;return}}let s=this.Ve(e),n=e.Oe,r=e.$e,o=e.Le,f=e.Ne,h=this.St,u=h.Et,a=h.vt?.eventDelegation,c="document"===a,p=void 0===a||!0===a||c,d=e.Pe;if(null!==d&&p&&h[bt]!==e){for(let t=0;d.length>t;t++)l(u,d[t],c);h[bt]=e}let y=this.dt;for(let e=n.length-1;e>=0;e--){let i=t[e],l=n[e];if(2===l){"number"==typeof i&&(i+="");s[r[e]].textContent=i}else if(3===l&&p&&("function"==typeof i||Array.isArray(i)&&"function"==typeof i[0])){let t=s[r[e]];t[o[e].gt]=i;t[F]=u}else if(4===l&&y&&"string"==typeof i)""!==i&&s[r[e]].setAttribute(o[e],i);else if(1===l)this.key=i;else{let t=f[e];t._=s[r[e]];t.U=this;t.et(i)}}this.Z=null;this.dt=!1}ue(t){let e=this.ie,i=t.exprs,l=e.Te;for(let t=0;l.length>t;t++){let e=typeof i[l[t]];if("string"!==e&&"number"!==e)return!1}let s=this.u.exprs,n=e.Ne,r=e.$e,o=e.je,f=this.He;for(let t=n.length-1;t>=0;t--){let l=s[t],h=i[t],u=o[t];if(l!==h&&!v(l,h)||1&u&&"boolean"==typeof h){null===f&&(f=this.He=this.Ve(e).slice());let l=n[t],s=f[r[t]];if(2&u){let e=i[t],n=s.firstChild;"number"==typeof e&&(e+="");if(null!==n&&3===n.nodeType&&n===s.lastChild)n.nodeValue=e;else{l._=s;l.U=this;l.et(i[t]);l.Dt=null;l.Ht=null;l.Z=null}continue}l._=s;l.U=this;l.et(i[t])}}return!0}Ve(t){let e=t.xe;e[1]=this.p;return b(e,t.ke,2,2)}ae(t=null){t??=this.ie;let e=this.We(t,this.Ve(t));for(let i of t.Te){let t=e[i],l=t._.firstChild;if(null!==l&&3===l.nodeType&&l===t._.lastChild){t.Dt=l;t.Ht=l.nodeValue}}return e}Qt(){let t=this.Z;if(t)return t;t=[];let e=this.p,i=this.m?.nextSibling;for(;e&&e!==i;){t.push(e);e=e.nextSibling}this.Z=t;return t}wt(){return this.St.Et}Fe(t,e,i=0,l=!1){let s=e.ke;if(s&&0===i){let i;if(l)i=this.Ve(e);else{i=e.xe;i[0]=t;b(i,s,0,1)}this.We(e,i)}else{let l=e.ne,s=l.length,n=this.ne=Array(s);for(let e=0;s>e;e++){let s=l[e].clone(t,i);s.U=this;n[e]=s}}}We(t,e){let i=t.ne,l=i.length,s=this.ne=Array(l);for(let t=0;l>t;t++){let l=i[t],n=l.st(0>l.De?null:e[l.De],e[l.Ie]);n.U=this;s[t]=n}return s}ce(){if(this.styles)for(let[t,e]of this.styles)e!==t.textContent&&$.I(t,this.St.Et)}ze(t,e,i=0){let l=this.St.Et;if(l){let s=this.St.vt;if(!1!==s?.ids)for(let s of e.ids){let e=j.resolve(t,s,i);$.M(l,e)}if(!1!==s?.styles){e.styles.length&&(this.styles=new Map);for(let s of e.styles){let e=j.resolve(t,s,i);if(1===l.nodeType){$.I(e,l);this.styles.set(e,e.textContent)}}}if(!1!==s?.scripts)for(let l of e.scripts){let e=j.resolve(t,l,i);(0,eval)(e.textContent)}}}}class gt extends wt{instantiate(t,e,i,l){let s=0;this.vt=l;if(e instanceof Text){if(!i)throw Error("Text node needs an element.");this.Et=i;e.nodeValue.length&&this.Et.append(e)}else{if(i){this.Et=i;let t;if(N.O||i.childNodes.length){t=N.v.createDocumentFragment();t.append(...N.O||i.childNodes)}if(r=this.Et.tagName,1===(n=e).children.length&&r.includes("-")&&n.children[0].tagName.replace("-SOLARITE-PLACEHOLDER","")===r){this.Et.append(...e.children[0].childNodes);for(let t of e.children[0].attributes)this.Et.hasAttribute(t.name)||this.Et.setAttribute(t.name,t.value);s=1}else 1===e.childNodes.length&&3===e.childNodes[0].nodeType&&""===e.childNodes[0].textContent||this.Et.append(...e.childNodes);if(t){for(let e of i.querySelectorAll("slot[name]")){let i=e.getAttribute("name");if(i){let l=t.querySelectorAll(`[slot='${i}']`);e.append(...l)}}let e=i.querySelector("slot:not([name])");e?e.append(t):i.append(t)}}else{let t=$.S(e.childNodes),i=1===t.length?t[0]:null;this.Et=i||e;i&&(s=1)}this.Fe(this.Et,t,s);this.ze(this.Et,t,s)}var n,r;this.p=this.m=this.Et;N.P.set(this.Et,this)}}let vt=1,St=new WeakMap;class Et{exprs=void 0;html=void 0;Vt;h;key;o=!1;constructor(t=[""],e=[]){this.html=t;this.exprs=e}render(t=null,e={}){let i=t&&N.P.get(t);if(!i){i=new gt(this,null,t,e);t||(t=i.wt())}if(1!==this.html?.length||this.html[0]){let t=i.u;i.re(this.exprs,!0,t!==this&&t.html===this.html?t.exprs:null);i.u=this}else t.innerHTML="";return t}pe(){void 0===this.Vt&&(this.Vt=this.exprs.length?w(this.html):this.html[0]);return this.Vt}}let At="render";const kt=Symbol(),xt=Symbol();A.immutableMap=A.map=(t,e)=>new Y(t,e);A.selector=(t=null)=>new R(t);let Tt=new Proxy(HTMLElement,{construct(t,e,i){$.i(i);return Reflect.construct(t,e,i)}});class Nt extends Tt{constructor(t=null,e=null){super();if(t){if("object"!=typeof t)throw Error("First argument must be an object.");if(!Object.keys(t).length){let e=Nt.getAttribs(this);for(let i in e)t[i]=e[i]}for(let i in e||{})"string"==typeof t[i]&&(t[i]=k(t[i],e[i]))}}render(){throw Error("render() is not defined for "+this.constructor.name)}renderFirstTime(){if(!N.k.has(this)){let t=Nt.getAttribs(this);this.render(t)}}connectedCallback(){this.renderFirstTime()}static define(t=null){$.i(this,t)}static getAttribs(t){let e=$.R(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 A;export{J as Fragment,N as Globals,K as InternalJsxAttr,Y as MappedList,R as Selector,C as SelectorRef,Nt as Solarite,$ as SolariteUtil,Et as Template,x as assignAttributes,k as convertType,t as delve,i as getEventBinding,A as h,o as internalJsxToTemplate,E as svg,S as toEl};
|
|
1
|
+
// Solarite v0.9.0 | MIT | eric-frost.github.io/solarite
|
|
2
|
+
function t(t,e,i=L){let l=i!==L,s=e.length;if(!t&&!l&&s)return;let n=0;for(let r of e){if(void 0===t[r]){if(!l)return;s-1>n&&(t[r]=(e[n+1]+"").match(/^\d+$/)?[]:{})}l&&n===s-1&&(t[r]=i);t=t[r];n++}return t}function e(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)}function i(t,e){let i=t[F];if(void 0!==i)return i instanceof U?i.key===e?i:void 0:i[e]}function l(t,e){let i=t[W];void 0===i&&(i=t[W]=new Set);if(!i.has(e)){i.add(e);t.addEventListener(e,n,!0);let l=t.ownerDocument,s=l[W];void 0===s&&(s=l[W]=new Set);if(!s.has(e)){s.add(e);l.addEventListener(e,n,!0)}}}function s(){B=0;for(let t in K){let e=K[t];if(0!==e.length){K[t]=[];let i=J[t];for(let l=0;e.length>l;l++)e[l].removeEventListener(t,i)}}}function n(t){let e=t.composedPath();if(t[_]===e.length)return;t[_]=e.length;let i=t.type,l=G[i],n=(t=>{let e=J[t];if(void 0===e){let i=G[t];e=J[t]={handleEvent(t){let e=t.currentTarget,l=e[i];if(void 0===l)return;let s=e[V];if("function"==typeof l)l.call(s,t,e);else switch(l.length){case 1:l[0].call(s,t,e);break;case 2:l[0].call(s,l[1],t,e);break;case 3:l[0].call(s,l[1],l[2],t,e);break;default:l[0].call(s,...l.slice(1),t,e)}}}}return e})(i),r=K[i];void 0===r&&(r=K[i]=[]);for(let t=0;e.length>t;t++){let s=e[t];if(void 0!==s[l]){s.removeEventListener(i,n);s.addEventListener(i,n);r.push(s)}}0!==r.length&&0===B&&(B=setTimeout(s))}function r(t){if(null===t||"object"!=typeof t)return t;let e="";for(let i in t){let l=t[i];null!=l&&!1!==l&&(e+=(e?";":"")+C.t(i)+":"+l)}return e}function o(t){return(""+t).replace(/&/g,"&").replace(/"/g,""")}function f(t,e,i=[],l){e=e||{};if(t===Y){let t=[""];for(let e=0;i.length>e;e++)t.push("");return new $t(t,i)}if("function"==typeof t){if(t.prototype instanceof HTMLElement)return h(C.i(t),e,i,l);let s={};for(let t in e)"key"!==t&&(s[t]="style"===t?r(e[t]):e[t]);!("children"in s)&&i.length&&(s.children=1===i.length?i[0]:i);let n=t(s);void 0===l&&(l=e.key);void 0!==l&&n instanceof $t&&(n.key=l);return n}return h(t,e,i,l)}function h(t,e,i,l){let s=X.has(t.toLowerCase()),n=[],f=[],h="";for(let t in e){if("children"===t)continue;if("key"===t){void 0===l&&(l=e[t]);continue}let i=e[t];if("id"!==t&&"data-id"!==t||"string"!=typeof i){"style"===t&&(i=r(i));n.push(t);f.push(i)}else h+=` ${t}="${o(i)}"`}let u=s?0:i.length,a=t+h+"\0"+n.join("\0")+"\0#"+u,c=Q.get(a);if(!c){c=((t,e,i,l,s)=>{let n=[],r="<"+t+e;for(let t of i){n.push(r+" "+t+"=");r=""}r+=">";if(s){n.push(r);return n}if(0===l)n.push(r+"</"+t+">");else{n.push(r);for(let t=1;l>t;t++)n.push("");n.push("</"+t+">")}return n})(t,h,n,u,s);Q.set(a,c)}let p=s?f:f.concat(i),d=new $t(c,p);void 0!==l&&(d.key=l);return d}function u(t){if("string"!=typeof t){if(void 0!==t.key)return t.key;if(t.html!==ut){ut=t.html;at=dt.get(t.html,t.o).l}return 0>at?void 0:t.exprs[at]}}function a(t){let e=new $t([t],[]);e.h=!0;return e}function c(t,e){let i=t.u;return i===e||("string"==typeof e?!0===i.h&&i.html[0]===e:g(i,e))}function p(t,e){let i=t.u;return"string"==typeof e?!0===i.h:i.html===e.html&&i.o===e.o}function d(t,e,i){for(let l=0;e>l;l++)if(t[l]===i)return!0;return!1}function y(t,e,i){let l=e.p,s=e.m;if(l===s)t.insertBefore(l,i);else for(;;){let e=l.nextSibling;t.insertBefore(l,i);if(l===s)break;l=e}}function m(t,e,i,l){if(e.length){let l=new Set(i);for(let i of e)l.has(i)||i.parentNode!==t||t.removeChild(i)}let s=l;for(let e=i.length;e--;){let l=i[e];l.nextSibling===s&&l.parentNode===t||t.insertBefore(l,s);s=l}}function b(t){let e=1===t.nodeType&&bt.includes(t.tagName),i=t.firstChild;for(;i;){let t=i.nextSibling;1===i.nodeType?b(i):e&&3===i.nodeType&&!i.nodeValue.trim()&&i.remove();i=t}}function w(t,e,i,l){for(;e.length>i;i+=2,l++){let s,n=e[i+1];if(0>n){s=t[e[i]];do{s=s.nextSibling}while(0>++n)}else{s=t[e[i]].firstChild;for(;n>0;n--)s=s.nextSibling}t[l]=s}return t}function v(t){let e=Nt.get(t);if(void 0===e){e="~@"+Tt++;Nt.set(t,e)}return e}function g(t,e){if(t.html===e.html&&t.o===e.o){let i=t.exprs,l=e.exprs;for(let t=0;i.length>t;t++){let e=i[t],s=l[t];if(e!==s&&!S(e,s))return!1}return!0}return t.h===e.h&&!t.exprs.length&&!e.exprs.length&&1===t.html.length&&1===e.html.length&&t.o===e.o&&t.html[0]===e.html[0]}function S(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(!S(t[i],e[i]))return!1;return!0}return t instanceof $t&&e instanceof $t&&g(t,e)}function E(t){if("string"==typeof t){let e=O.v.createElement("template");e.innerHTML=t;let i=C.S(e.content.childNodes);return 1===i.length?i[0]:e.content}if(t instanceof $t)return t.render();if(t&&"object"==typeof t){let e=t;if("Object"!==e.constructor.name)throw Error(`Solarite web component class ${e.constructor?.name} must extend HTMLElement.`);if(!O.A.has(e)){O.A.set(e,null);e[Ot]();let t=O.A.get(e);O.A.delete(e);for(let i in e)t[i]="function"==typeof e[i]?e[i].bind(t):e[i];return t}}throw Error("toEl() does not support argument of type: "+(t?typeof t:t))}function A(t,...e){let i=new $t(t,e);i.o=!0;return i}function k(t=Pt,...e){if(Array.isArray(t))return new $t(t,e);if("string"==typeof t||t instanceof String){let i=t;if(!e.length||"object"!=typeof e[0]&&null!==e[0]){let t=i;/^\s+</.test(t)&&(t=t.trim());return new $t([t],[])}return f(i+"",e[0]||{},e.slice(1))}if("function"==typeof t||t===Y)return f(t,e[0]||{},e.slice(1));if(t instanceof HTMLElement||t instanceof DocumentFragment){if(!(e[0]instanceof $t)){let i=t,l=e[0],s=i[Lt];if(s)return s;let n=(t,...e)=>{i.shadowRoot&&(i.innerHTML="");O.k.add(i);return new $t(t,e).render(i,l)};i[Lt]=n;return n}e[0].render(t,e[1])}else{if(t===Pt)return(t,...e)=>E(k(t,...e));if("object"!=typeof t||!O.A.has(t)){if(C.T(t))return new $t;throw Error("h() does not support argument of type: "+(t?typeof t:t))}{let i=t;if(!(e[0]instanceof $t))return((...t)=>{let e=k(...t).render();O.A.set(i,e)}).bind(i);{let t=e[0].render();O.A.set(i,t)}}}}function x(t,e){return e===Date?new Date(t):e===Boolean?!["false","0"].includes(t):e?e(t):t}function T(t,e={},i=[]){for(let l of t.attributes){let s=C.N(l.name);if(!(s in t)||i.includes(s))continue;let n=l.value,r=e[s];n.startsWith("${")&&n.endsWith("}")?t[s]=JSON.parse(n.slice(2,-1)):r?t[s]=x(n,r):""===n&&("function"==typeof t[s]||"object"==typeof t[s]&&null!==t[s])||(t[s]=n)}}var N;!function t(){N={connected:new WeakSet,$:null,div:document.createElement("div"),v:document,O:{},L:{},P:new WeakMap,A:new WeakMap,k:new WeakSet,C:new WeakMap,reset:t}}();let $=Symbol.for("solarite");globalThis[$]?console.warn(`Solarite loaded twice: ${globalThis[$]} and ${import.meta.url}. Templates and components from one won't work in the other.`):globalThis[$]=import.meta.url;var O=N;let L={};const P="native:";let C={j(t,e){let i=t.length;if(i!==e.length)return!1;for(let l=0;i>l;l++)if(t[l]!==e[l])return!1;return!0},R(t,e=null){let i={};for(let l of t.attributes)l.name!==e&&(i[C.N(l.name)]=l.value);return i},M(e,i){let l=i.getAttribute("data-id")||i.getAttribute("id");if(l){if(!l.includes(".")){let t=e[l],i=l in e&&!Object.hasOwn(e,l);if(!t?.nodeType&&(null!=t||i))throw Error(`Solarite: id="${l}" would overwrite an existing ${e.constructor.name} property.`)}t(e,l.split(/\./g),i)}},I(t,e){let i=e.tagName.toLowerCase(),l="";if(t.hasAttribute("global")||t.hasAttribute("data-global")){let e=O.v.head;if(e.querySelector(`style[data-style="${i}"]`))t.remove();else{e.append(t);t.setAttribute("data-style",i)}}else{let t=e.getAttribute("data-style");if(!t){let i=e.constructor;e.setAttribute("data-style",t=i.D=(i.D||0)+1)}l=`[data-style="${t}"]`}for(let e of t.childNodes)if(3===e.nodeType){let t=e.textContent,s=t.replace(/:host(?:\(((?:[^()]|\([^()]*\))*)\)|(?![-a-z0-9_(]))/gi,`${i}${l}$1`);t!==s&&(e.textContent=s)}},t:t=>t.replace(/[a-z0-9](?=[A-Z])|[A-Z](?=[A-Z][a-z])|[a-zA-Z](?=\d)/g,"$&-").toLowerCase(),N:t=>t.replace(/-([a-z])/g,t=>t[1].toUpperCase()),i(t,e){let i=customElements[R](t);if(i)return i;(e=e||C.t(t.name)).includes("-")||(e+="-element");customElements[j](e,t);return e},H: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,F(t){t.startsWith(P)&&(t=t.slice(7));return t.startsWith("on")&&t in O.div},G(t,e){let i=t.tagName+"."+e,l=O.L[i];if(void 0===l){let s=Object.getPrototypeOf(t);for(;s;){const t=s.constructor.name;if(t.startsWith("HTML")&&t.endsWith("Element"))break;s=Object.getPrototypeOf(s)}O.L[i]=l=!!s&&!!Object.getOwnPropertyDescriptor(s,e)?.set}return l},T:t=>void 0===t||!1===t||null===t,V(){return{}},W:t=>"function"==typeof t?C.W(t()):t instanceof Date?t.toISOString().replace(/T/," "):Array.isArray(t)||"object"==typeof t?"":t,_(t){O.v.createDocumentFragment().append(...t)},S(t){let e=t=>1!==t.nodeType&&(3!==t.nodeType||!t.textContent.trim()),i=[...t];for(;i.length&&e(i[0]);)i.shift();for(;i.length&&e(i[i.length-1]);)i.pop();return i}},j="define",R="getName";class M{J;K;B=!1;U;Z;Y;q=!1;X;constructor(t,e){this.J=t;this.K=e}tt(t){this.et(t[0])}et(t){}it(){return 1}lt(t){return t[0]}st(t,e){let i=new this.constructor(t,e,this.nt,this.rt);i.Y=this.Y;i.B=this.B;i.X=this.X;return i}clone(t,e=0){let i,l=M.resolve(t,this.ot,e);this.J&&(i=(l===t?t:l.parentNode).childNodes[this.ft]);return this.st(i,l)}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,i=0){for(let l=e.length-1-i;l>=0;l--)t=t.childNodes[e[l]];return t}}class I{selector;selected;constructor(t,e){this.selector=t;this.selected=e}value(){let t=this.selector;return this.selected?t.ht:t.ut}bind(t,e,i){if(i.p!==t)throw Error("Solarite: a selector must be on the row's root element.");let l=this.selector;l.nt=e;l.path=i.ct;let s=this.selected?l.ht:l.ut;""===s||!1===s||null==s?!0!==i.dt&&t.removeAttribute(e):t.setAttribute(e,s)}}class D{#t=null;#e=new I(this,!0);#i=new I(this,!1);ht;ut="";nt=null;path=null;constructor(t=null){this.#t=t}get key(){return this.#t}when(t,e,i=""){this.ht=e;this.ut=i;return t===this.#t?this.#e:this.#i}set(t){let e=this.#t;if(e!==t){this.#t=t;if(null!==this.path){this.#l(e,this.ut);this.#l(t,this.ht)}}}#l(t,e){if(null==t)return;let i=this.path.yt;if(null===i||0===i.length)return;if(void 0===i[0].key)throw Error("Solarite: a selector must be on a keyed list, as key=${...}.");let l=null;for(let e=0;i.length>e;e++)if(i[e].key===t){l=i[e];break}if(null===l)return;let s=l.p;null!==s&&1===s.nodeType&&(""===e||!1===e||null==e?s.removeAttribute(this.nt):s.setAttribute(this.nt,e))}}class H extends M{nt;rt;constructor(t,e,i=null,l=null){super(null,e);this.nt=i;this.rt=l}tt(t){if(this.rt){let e=this.K,i=this.lt(t),l=this.X;if((l?e[this.nt]:e.getAttribute(this.nt))!==i){l?e[this.nt]=i:"value"===this.nt&&e.hasAttribute("contenteditable")&&(e.innerHTML=i);e.setAttribute(this.nt,i)}}else this.et(t[0])}et(i){if(this.rt)return this.tt([i]);let l=this.K;if(e(i)){if(this.Y&&l.tagName.endsWith("-SOLARITE-PLACEHOLDER"))return;let[e,s]=[i[0],i.slice(1)];if(!e)throw Error(`Solarite cannot bind ${this.nt} to ${e}.`);let n=t(e,s);if("value"===this.nt&&"select-multiple"===l.type&&Array.isArray(n)){let t=n.map(t=>t+"");for(let e of l.options)e.selected=t.includes(e.value)}else if("radio"===l.type)l.checked=l.value===n+"";else{const t=C.T(n)?"":n;"value"===this.nt&&l.hasAttribute("contenteditable")?t!==l.innerHTML&&(l.innerHTML=t):t!==l[this.nt]&&(l[this.nt]=t)}let r=()=>{let i="value"===this.nt||"radio"===l.type?C.H(l):l[this.nt];t(e,s,i)};this.bt(l,this.U.wt(),this.nt,"input",r,null,!0)}else{if("object"==typeof i&&i instanceof I){this.Y||i.bind(l,this.nt,this.U);return}let t=this.X;if("function"==typeof i){if(this.Y)return;i=i()}else i=C.W(i);if(void 0===i||!1===i||null===i||""===i&&!t){t&&(l[this.nt]="boolean"!=typeof l[this.nt]&&"");l.removeAttribute(this.nt)}else if(!0===i){t&&(l[this.nt]=!0);l.setAttribute(this.nt,"")}else if((t?l[this.nt]:l.getAttribute(this.nt)??"")!==i){t?l[this.nt]=i:"value"===this.nt&&l.hasAttribute("contenteditable")&&(l.innerHTML=i);l.setAttribute(this.nt,i)}}}it(){return this.rt?this.rt.length-1:1}lt(t){if(!this.rt)return t[0];let e=[],i=this.rt;for(let l=0;i.length>l;l++){e.push(i[l]);if(i.length-1>l){if("object"==typeof t[l]&&t[l]instanceof I)throw Error(`Solarite: a selector must own the whole ${this.nt} attribute.`);let i=C.W(t[l]);C.T(i)||e.push(i)}}return e.join("")}bt(t,e,i,s,n,r,o=!1){if(!1===o&&void 0!==this.vt){let i=this.U.St.gt?.eventDelegation??!0;if(!1!==i&&(!Array.isArray(i)||i.includes(s))){let i=this.vt;void 0===t[i]&&l(e,s);t[i]=r||n;t[V]=e;return}}let f,h=r||[n],u=t[F];if(void 0!==u){if(u instanceof U){if(u.key!==i){let l=t[F]={};l[u.key]=u;f=l[i]=new U(e,t,i,h);t.addEventListener(s,f,o);return}f=u}else{f=u[i];if(!f){f=u[i]=new U(e,t,i,h);t.addEventListener(s,f,o);return}}f.Et=e;f.At=h}else{let l=t[F]=new U(e,t,i,h);t.addEventListener(s,l,o)}}}const F=Symbol(),z=new Set(["beforeinput","click","contextmenu","dblclick","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),G={},V=Symbol(),W=Symbol(),_=Symbol(),J={},K={};let B=0;class U{constructor(t,e,i,l){this.Et=t;this.node=e;this.key=i;this.At=l}handleEvent(t){let e=this.At;switch(e.length){case 1:return e[0].call(this.Et,t,this.node);case 2:return e[0].call(this.Et,e[1],t,this.node);case 3:return e[0].call(this.Et,e[1],e[2],t,this.node)}return e[0].call(this.Et,...e.slice(1),t,this.node)}}class Z extends H{kt;vt;xt;constructor(t,e,i=null,l=null){super(null,e,i,l);this.q=!0;let s=i;this.xt=null!==s&&s.startsWith(P);this.xt&&(s=s.slice(7));this.kt=s?s.slice(2):null;this.vt=null===this.kt||this.xt?void 0:(t=>{if(z.has(t))return G[t]??=Symbol("sol$"+t)})(this.kt)}tt(t){this.rt?.length>1?super.tt(t):this.et(t[0])}et(t){if(this.rt?.length>1)return super.tt([t]);if(this.Y&&this.K.tagName.endsWith("-SOLARITE-PLACEHOLDER"))return;let e,i=this.U.St.Et,l=this.K,s=this.kt;if(Array.isArray(t)&&"function"==typeof t[0])e=t[0];else{if("function"!=typeof t)throw Error(`Solarite: ${this.nt}=\${...} is not a function.`);e=t;t=null}this.bt(l,i,s,s,e,t)}}const Y=Symbol();class q{constructor(t,e){this.name=t;this.value=e}}const X=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Q=new Map;class tt extends M{Tt;Nt;$t;constructor(t,e){super(null,e);this.Tt=new Set}et(t){let e=this.K;if(t instanceof q)return this.Ot(t);Array.isArray(t)&&(t=t.flat().join(" "));let i=this.Tt;this.Tt=new Set;if(t){"function"==typeof t&&(t=t());if("object"==typeof t)for(let i in t){let l=t[i];if(void 0!==l&&!1!==l&&null!==l){e.setAttribute(i,l);this.Tt.add(i)}}else{let i=C.V(t);for(let t in i){e.setAttribute(t,i[t]);this.Tt.add(t)}}}for(let t of i)this.Tt.has(t)||e.removeAttribute(t)}Ot(t){let e=t.name;if("key"===e)return;let i=t.value,l=this.Nt;if(void 0===l||this.$t!==e){let t=this.K;if(C.F(e))l=new Z(null,t,e,null);else{l=new H(null,t,e,null);l.X=C.G(t,e)}l.Y=this.Y;this.Nt=l;this.$t=e}l.K=this.K;l.U=this.U;"style"===e&&(i=r(i));l.et(i)}}class et{data={};add(t,e){let i=this.data,l=i[t];l?l.push(e):i[t]=[e]}Lt(t,e,i){let l=this.data,s=l[t];s?i>s.length-(s.Pt||0)&&s.push(e):l[t]=[e]}Ct(t){let e=this.data,i=e[t];if(!i)return;let l=i.Pt||0,s=i[l];l++;i.length>l?i.Pt=l:delete e[t];return s}}class it{items;jt;constructor(t,e){this.items=t;this.jt=e}*[Symbol.iterator](){let t=this.items,e=this.jt;for(let i=0;t.length>i;i++)yield e(t[i])}}class lt extends M{Mt=!1;It=null;Dt=!1;yt=null;Ht=null;Ft=null;zt=null;Gt=null;constructor(t,e){super(t,e)}et(t){let e=typeof t;if(("string"===e||"number"===e)&&!this.Dt){"string"!==e&&(t+="");let i=this.Ht;if(null!==i){if(this.Ft!==t){i.nodeValue=t;this.Ft=t}return}let l=this.yt;if(null===l||0===l.length){let e;if(this.B){let i=this.K.firstChild;if(null!==i&&3===i.nodeType&&i===this.K.lastChild){i.nodeValue!==t&&(i.nodeValue=t);this.Ht=i;this.Ft=t;return}this.K.textContent=t;e=this.K.firstChild}else{e=O.v.createTextNode(t);this.K.parentNode.insertBefore(e,this.K)}this.Ht=e;this.Ft=t;if(!this.U.dt){this.Z=null;this.U.ct&&this.U.ct.Vt()}return}if(1===l.length){let e=l[0],i=e.u;if(!0===i.h){if(i.html[0]!==t){e.p.nodeValue=t;i.html[0]=t;e.Wt=t}return}}}if(null!==this.Ht){let t=new kt(a(this.Ft),this,this.Ht);(this.yt??=[]).push(t);this.Ht=null}if(t instanceof I)throw Error("Solarite: a selector must own the whole attribute.");if(t instanceof it){this._t(t);return}this.It=null;let i=null,l=!1;if(Array.isArray(t)){let e=t.length,l=0;for(;e>l&&t[l]instanceof $t;)l++;l===e&&(i=t)}if(null===i){i=[];l=this.Jt(t,i,!1)}if(l||this.Dt){this.Dt=l;this.Kt(i)}else this.Bt(i)}Bt(t){let e=0!==t.length?t[0]:null;(null!==e?"string"==typeof e||void 0===e.key&&0>dt.get(e.html,e.o).l:null===this.yt||0===this.yt.length||void 0===this.yt[0].key)?this.Ut(t):this.Zt(t)}_t(t){let e=t.items,i=t.jt,l=e.length,s=this.yt,n=this.It,r=null===s||null===n||n.length!==s.length?0:s.length,o=null,f=null,h=0;if(r===l&&0!==l&&!this.Mt&&!this.Dt){let t=!1,u=nt;for(let i=0;l>i;i++)if(n[i]!==e[i]){if(h===u){if(d(n,r,e[i])){t=!0;h=0;break}u=l}(o??=[])[h++]=i}if(!t&&0!==h){f=Array(h);for(let l=0;h>l;l++){let s=i(e[o[l]]);if(!(s instanceof $t)&&"string"!=typeof s){t=!0;h=l;break}f[l]=s}}if(!t&&(0===h||this.Yt(s,o,f,h,l))){for(let t=0;h>t;t++){let i=o[t];n[i]=e[i]}return}}let u=Array(l),a=0!==h?o:null,c=0,p=null,y=!1;const m=t=>{if(y)return-1;if(null===p){if(!d(n,r,t)){y=!0;return-1}p=new Map;for(let t=0;r>t;t++)p.set(n[t],t)}let e=p.get(t);return void 0===e?-1:e};if(0!==r){let t=0,o=!0;for(let p=0;l>p;p++){let d=e[p],y=p+t,b=y>=0&&r>y;if(b&&n[y]===d){u[p]=s[y].u;o=!0}else if(null!==a&&h>c&&a[c]===p)u[p]=f[c++];else{if(o){let f=-1;for(let t=1;ot>=t;t++){let e=y+t,i=y-t;if(r>e&&n[e]===d){f=e;break}if(i>=0&&n[i]===d){f=i;break}}if(f>=0){t=f-p;u[p]=s[f].u;continue}if(b&&l>r)for(let s=1;ft>=s&&l>p+s;s++)if(e[p+s]===n[y]){u[p]=i(d);t--;f=-2;break}if(-2===f)continue;o=!1}if(r>y){let e=m(d);if(e>=0){u[p]=s[e].u;t=e-p;o=!0;continue}}u[p]=i(d)}}}else for(let t=0;l>t;t++)u[t]=i(e[t]);let b=0!==l?u[0]:null;if(null!==b&&!(b instanceof $t)&&"string"!=typeof b){let t=[],e=this.Jt(u,t,!1);if(e||this.Dt){this.Dt=e;this.Kt(t)}else this.Bt(t);return}if(this.Dt){this.Dt=!1;this.Kt(u);return}this.Bt(u);let w=this.It;null!==w&&w.length===l||(w=this.It=Array(l));for(let t=0;l>t;t++)w[t]=e[t]}Yt(t,e,i,l,s){let n=void 0!==t[0].key,r=null,o=0;for(let s=0;l>s;s++){let l=t[e[s]],f=i[s];if("string"==typeof f||!p(l,f)||n&&l.key!==u(f)){if(!n||o===rt)return!1;(r??=[])[o++]=s}}for(let s=0,n=0;l>s;s++){if(o>n&&r[n]===s){n++;continue}let l=t[e[s]],f=i[s];c(l,f)?this.qt(l,f):this.Xt(l,f)}if(0===o)return!0;let f=this.B;this.Qt(r,e,t,i,t,s,f?null:this.K,f?this.K:this.K.parentNode);if(!this.U.dt){this.Z=null;this.U.ct&&this.U.ct.Vt()}this.zt&&(this.zt=null);return!0}Qt(t,e,i,l,s,n,r,o){let f=t.length,h=Array(f);for(let l=0;f>l;l++){let s=t[l];h[l]=i[null===e?s:e[s]]}let a=Array(f);for(let e=0;f>e;e++){let i=l[t[e]],s=u(i);if(void 0!==s)for(let t=0;f>t;t++){let l=h[t];if(null!==l&&l.key===s&&p(l,i)){h[t]=null;c(l,i)?this.qt(l,i):this.Xt(l,i);a[e]=l;break}}}for(let t=0;f>t;t++){let e=h[t];null!==e&&(e.p!==e.m?C._(e.te()):e.p.remove())}for(let i=f-1;i>=0;i--){let f=t[i],h=null===e?f:e[f],u=a[i];void 0===u&&(u=this.ee(l[f]));s[h]=u;let c=n>h+1?s[h+1].p:r;u.m.nextSibling===c&&u.p.parentNode===o||y(o,u,c)}}Ut(t){let e=this.yt||st,i=e.length,l=t.length,s=Array(l),n=0,r=i,o=l;for(;r>n&&o>n;){let i=e[n],l=t[n];if(!c(i,l))break;i.le.ie&&this.qt(i,l);s[n]=i;n++}for(;r>n&&o>n;){let i=e[r-1],l=t[o-1];if(!c(i,l))break;i.le.ie&&this.qt(i,l);s[--o]=i;r--}for(;r>n&&o>n;){let i=e[n],l=t[n];if(c(i,l))i.le.ie&&this.qt(i,l);else{if(!p(i,l))break;this.Xt(i,l)}s[n]=i;n++}let f=r-n,h=o-n;if(f||h){if(f){for(let t=n;r>t;t++){let i=e[t];i.p!==i.m&&i.te()}let t=0===l&&0===n&&this.se(),i=this.Gt??=new et;for(let l=n;r>l;l++){let s=e[l];s.p!==s.m?C._(s.te()):t||s.p.remove();s.u.h||i.Lt(s.Wt,s,ht)}}if(h){let e=this.B,i=l>o?s[o].p:e?null:this.K,r=e?this.K:this.K.parentNode;for(let e=n;o>e;e++){let l=this.ne(t[e]);s[e]=l;y(r,l,i)}}if(!this.U.dt){this.Z=null;this.U.ct&&this.U.ct.Vt()}}this.yt=s;this.zt&&(this.zt=null)}Zt(t){let e=this.yt||st,i=e.length,l=t.length,s=Array(l),n=0,r=i,o=l;for(;r>n&&o>n;){let i=e[n],l=t[n];if(i.u===l)i.le.ie&&this.qt(i,l);else{if("string"==typeof l||i.key!==u(l)||!p(i,l))break;c(i,l)?this.qt(i,l):this.Xt(i,l)}s[n]=i;n++}for(;r>n&&o>n;){let i=e[r-1],l=t[o-1];if(i.u===l)i.le.ie&&this.qt(i,l);else{if("string"==typeof l||i.key!==u(l)||!p(i,l))break;c(i,l)?this.qt(i,l):this.Xt(i,l)}s[--o]=i;r--}let f=r-n,h=o-n;if(f||h){let i=this.B,a=i?this.K:this.K.parentNode,d=!1;if(f===h){let r=null,f=!0;for(let i=n;o>i;i++){let l=e[i],n=t[i];if(l.u===n)l.le.ie&&this.qt(l,n);else{let t=u(n);if(void 0===t||l.key!==t||!p(l,n)){(r??=[]).push(i);if(r.length>8){f=!1;break}continue}c(l,n)?this.qt(l,n):this.Xt(l,n)}s[i]=l}if(f){null!==r&&this.Qt(r,null,e,t,s,o,l>o?s[o].p:i?null:this.K,a);d=!0}}if(!d){let d=0,m=!1,b=null,w=null;if(f&&h){let i=new Map;for(let e=n;o>e;e++){let l=t[e];"string"!=typeof l&&i.set(u(l),e)}b=Array(h).fill(-1);let l=-1;for(let o=n;r>o;o++){let r,f=e[o],h=void 0===f.key?void 0:i.get(f.key);if(void 0!==h&&-1===b[h-n]&&p(f,r=t[h])){b[h-n]=o;d++;l>h?m=!0:l=h;c(f,r)?this.qt(f,r):this.Xt(f,r);s[h]=f}else(w??=[]).push(f)}}let v=null,g=null;if(i&&0===n&&o===l&&0===d&&h>500&&a.isConnected&&null!==a.parentNode&&-1===a.localName.indexOf("-")&&!a.hasAttribute("is")){v=a.parentNode;g=a.nextSibling;a.remove()}let S=0!==f&&0===h;if((null!==w||S)&&(0!==n||o!==l||0!==d||!this.se())){S&&(w=e.slice(n,r));for(let t of w)t.p!==t.m&&t.te();for(let t of w)t.p!==t.m?C._(t.te()):t.p.remove()}if(h){let e=l>o?s[o].p:i?null:this.K;if(0===d)for(let i=n;o>i;i++){let l=this.ee(t[i]);s[i]=l;y(a,l,e)}else{let i=m?(t=>{let e=[],i=Array(t.length);for(let l=0;t.length>l;l++){let s=t[l];if(-1===s)continue;let n=0,r=e.length;for(;r>n;){let i=n+r>>1;s>t[e[i]]?n=i+1:r=i}n>0&&(i[l]=e[n-1]);n===e.length?e.push(l):e[n]=l}let l=e.length;if(l){let t=e[l-1];for(;l-- >0;){e[l]=t;t=i[t]}}return e})(b):null,l=null!==i?i.length-1:-1;for(let r=o-1;r>=n;r--){let o=s[r];if(void 0===o){o=this.ee(t[r]);s[r]=o;y(a,o,e)}else null!==i&&(0>l||i[l]!==r-n?y(a,o,e):l--);e=o.p}}}null!==v&&v.insertBefore(a,g)}if(!this.U.dt){this.Z=null;this.U.ct&&this.U.ct.Vt()}}this.yt=s;this.zt&&(this.zt=null)}ee(t){if("string"==typeof t)return new kt(a(t),this);let e=new kt(t,this);e.le.ie&&(this.Mt=!0);(t.exprs.length||e.re&&e.re.length)&&e.oe(t.exprs);return e}qt(t,e){let i=t.le;i.fe?t.oe(e.exprs,!1):i.he&&i.ue&&"string"!=typeof e&&this.Xt(t,e)}Xt(t,e){if("string"==typeof e){t.p.nodeValue=e;t.u.html[0]=e;t.Wt=e}else{if(t.le.ue){if(null!==t.re||!t.ae(e)){let i=t.u.exprs,l=e.exprs,s=t.re??t.ce();for(let t=s.length-1;t>=0;t--){let e=i[t],n=l[t];(e!==n&&!S(e,n)||s[t].X&&"boolean"==typeof n)&&s[t].et(n)}}t.styles&&t.pe();t.Z=null;t.dt=!1}else t.oe(e.exprs);t.u=e;void 0!==e.key&&(t.key=e.key)}}ne(t){let e;if("string"==typeof t){t=a(t);return new kt(t,this)}let i=this.Gt;if(i){e=i.Ct(t.de());if(e){this.Xt(e,t);return e}}e=new kt(t,this);e.le.ie&&(this.Mt=!0);(t.exprs.length||e.re&&e.re.length)&&e.oe(t.exprs);return e}Jt(t,e,i){if(t instanceof $t)e.push(t);else if(Array.isArray(t))for(let l of t)l instanceof $t?e.push(l):i=this.Jt(l,e,i);else if("function"==typeof t)i=this.Jt(t(),e,i);else if(t instanceof it){let i=t.items,l=t.jt;for(let t=0;i.length>t;t++)e.push(l(i[t]))}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}Kt(t){let e=this;e.ye();let i=[],l=e.yt||st;e.yt=[];for(let l of t){"string"==typeof l&&(l=a(l));if(l instanceof $t){let t=e.me(l);i.push(...t.te());e.yt.push(t)}else i.push(l)}let s=e.te();if(!C.j(s,i)){e.Z=i;this.U.ct&&this.U.ct.Vt();s.length&&!i.length&&e.se()||(e.B?m(e.K,s,i,null):m(e.K.parentNode,s,i,e.K));for(let t of l)t.p.parentNode||C._(t.te())}}Vt(){let t=this,e=this.B?this.K:this.K.parentNode;for(;t&&(t.B?t.K:t.K.parentNode)===e;){t.Z=null;t=t.U?.ct}}se(){if(this.B){this.K.textContent="";return!0}let t=this.J.parentNode;if(this.J===t.firstChild&&this.K===t.lastChild){t.innerHTML="";t.append(this.J,this.K);return!0}return!1}me(t){let e=t.de(),i=this.zt?.Ct(e)||this.Gt?.Ct(e);if(i){g(i.u,t)?this.qt(i,t):i.oe(t.exprs);i.u=t}else{i=new kt(t,this);i.le.ie&&(this.Mt=!0);i.oe(t.exprs)}return i}ye(){let t=this.zt?.data;if(t){let e=(this.Gt??=new et).data;for(let i in t){let l=t[i],s=l.Pt||0,n=e[i];if(n)for(let t=s,e=ht+(n.Pt||0);l.length>t&&e>n.length;t++)n.push(l[t]);else{n=e[i]=s?l.slice(s):l;n.length>ht&&(n.length=ht)}}}let e=this.zt=new et;if(this.yt)for(let t of this.yt)e.add(t.Wt,t)}te(){let t;t=this.Z;if(t)return t;t=[];let e,i=null;if(this.B)e=this.K.firstChild;else{e=this.J.nextSibling;i=this.K}for(;e&&e!==i;){t.push(e);e=e.nextSibling}this.Z=t;return t}}const st=[],nt=256,rt=16,ot=4,ft=64,ht=1e4;let ut=null,at=-1;class ct extends M{et(t){this.U.key=t}}class pt extends M{be;we;constructor(t,e){super(null,e)}tt(i){let l=(t=>{const e=new Set;return JSON.stringify(t,(t,i)=>{if("function"==typeof i)return v(i);if("object"==typeof i&&null!==i){if(i instanceof Node)return v(i);if(e.has(i))return v(i);e.add(i);if(i instanceof $t)return{html:v(i.html),exprs:i.exprs}}return i})})(i),s=l!==this.we;this.we=l;let n=this.K,r=C.R(n,"_is");for(let l,s=0;l=this.be[s];s++)if(!(l instanceof ct||l instanceof Z))if(l instanceof H){let n=C.N(l.nt),o=l.lt(i[s]);!l.rt&&e(o)&&(o=t(o[0],o.slice(1)));r[n]=o}else{let t=l.lt(i[s]);if("object"==typeof t)for(let e in t)r[C.N(e)]=t[e];else if("string"==typeof t){let e=C.V(t);for(let t in e)r[C.N(t)]=e[t]}}let o=O.$;try{let e=n.getAttribute("_is");if(n.tagName.endsWith("-SOLARITE-PLACEHOLDER")||e){let l=(e||n.tagName.slice(0,-21)).toLowerCase(),s=customElements.get(l);if(!s){this.ve=i;if(!this.ge){this.ge=!0;console.warn(`Solarite: <${l}> is not defined yet; waiting for customElements.define().`);customElements.whenDefined(l).then(()=>{this.ge=!1;let t=this.ve;this.ve=null;t&&this.K===n&&n.tagName.endsWith("-SOLARITE-PLACEHOLDER")&&this.tt(t)})}return}O.$={Se:s,Ee:[...n.childNodes]};let o=new s(r);e&&o.setAttribute("is",e);for(let t of n.attributes)"_is"!==t.name&&o.setAttribute(t.name,t.value);for(let t in r){let e=r[t],i=typeof e;"boolean"===i?e&&o.setAttribute(t,""):"string"!==i&&"number"!==i&&"bigint"!==i||o.setAttribute(t,e)}let f=o.getAttribute("data-id")||o.getAttribute("id");f&&t(this.U.wt(),f.split(/\./g),o);let h=this.U;this.K=o;for(let t of h.re){t.K===n&&(t.K=o);t.J===n&&(t.J=o)}h.p===n&&(h.p=o);h.m===n&&(h.m=o);"function"!=typeof o.render||O.k.has(o)||o.render(r,!0);for(let t,e=0;t=this.be[e];e++){t.U=this.U;t.K=o;t.tt(i[e])}n.replaceWith(o)}else"function"==typeof n.render&&n.render(r,s)}finally{O.$=o}}clone(t,e=0){let i=super.clone(t,e);i.be=this.be.map(i=>i.clone(t,e));return i}it(){return 0}}class dt{Ae;re=[];ids=[];styles=[];scripts=[];fe=!1;he=!1;ue=!1;ie=!1;ke=!1;l=-1;xe=!1;Te=!1;Wt;Ne;$e;Oe;Le;Pe;Ce;je;Re;Me;constructor(t=null,e=!1){if(!t)return;if(1===t.length&&!t[0].match(/[<&]/)){this.Ae=O.v.createTextNode(t[0]);return}let i,l=dt.Ie(t),s=O.v.createElement("template");if(l)if(e){s.innerHTML="<svg>"+l+"</svg>";let t=s.content.firstChild,e=O.v.createDocumentFragment();for(;t.firstChild;)e.append(t.firstChild);this.Ae=e}else{s.innerHTML=l;this.Ae=s.content}else{s.content.append(O.v.createTextNode(""));this.Ae=s.content}b(this.Ae);(t=>{for(let e of t.querySelectorAll("[is]")){let t=e.ownerDocument.createElement(e.tagName);for(let i of e.attributes)t.setAttribute("is"===i.name?"_is":i.name,i.value);t.append(...e.childNodes);e.replaceWith(t)}})(this.Ae);let n=[],r=0;const o=O.v.createTreeWalker(this.Ae,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_TEXT);for(;i=o.nextNode();){n.map(t=>t.remove());n=[];if(1===i.nodeType){const t=i.hasAttribute("_is")||i.tagName.includes("-"),l=[];for(let s of[...i.attributes]){if("key"===s.name){let e=s.value.split(/[\ue000-\uf8ff]/g);if(2!==e.length||""!==e[0]||""!==e[1])throw Error("Solarite: key must be one whole expression.");if(i.parentNode!==this.Ae)throw Error("Solarite: key must be on a top-level element.");if(this.l>=0)throw Error("Solarite: duplicate key attribute.");this.l=s.value.charCodeAt(0)-St;let n=new ct(null,i);this.re.push(n);t&&l.push(n);r++;i.removeAttribute("key");continue}let n=s.name.match(/^[\ue000-\uf8ff]$/);if(n){let e=new tt(null,i);this.re.push(e);if(t){e.Y=!0;l.push(e)}r++;i.removeAttribute(n[0])}else{let n=s.value.split(/[\ue000-\uf8ff]/g);if(n.length>1){let o=2!==n.length||n[0].length||n[1].length?n:null,f=C.F(s.name)?new Z(null,i,s.name,o):new H(null,i,s.name,o);f.X=C.G(i,s.name);this.re.push(f);if(t){f.Y=!0;l.push(f)}r+=n.length-1;e||!o?i.removeAttribute(s.name):i.setAttribute(s.name,n.join(""))}}}if(t){let t=new pt(null,i);t.be=l;this.re.splice(this.re.length-l.length,0,t)}}else if(8===i.nodeType&&"!\u2728!"===i.nodeValue){if(i?.parentNode?.closest&&i?.parentNode?.closest("[contenteditable]"))throw Error('Solarite: no ${...} inside contenteditable; use value="${...}".');let t=i.parentNode;if(1!==t.nodeType||i.previousSibling||i.nextSibling||t.tagName.includes("-")||"SLOT"===t.tagName||t.hasAttribute("_is")){let t,e=i.previousSibling;if(!e){e=O.v.createComment("Path:"+this.re.length);i.parentNode.insertBefore(e,i)}if(!i.nextSibling||8===i.nextSibling.nodeType&&"!\u2728!"===i.nextSibling.textContent){t=i;t.textContent="PathEnd:"+this.re.length}else{t=i.nextSibling;n.push(i)}let l=new lt(e,t);this.re.push(l);r++}else{let e=new lt(null,t);e.B=!0;this.re.push(e);r++;n.push(i)}}else if(8===i.nodeType){let t=i.textContent.split(/[\ue000-\uf8ff]/g);for(let e=0;t.length-1>e;e++){let t=new M(i.previousSibling,i);this.re.push(t);r++}}else if(3===i.nodeType){let t=i.parentNode?.nodeName;if("TEXTAREA"===t&&i.textContent.includes(yt))throw Error('Solarite: no ${...} inside textarea; use value="${...}".');if("SCRIPT"===t||"STYLE"===t){let t=i.textContent.split(yt);if(t.length>1){for(let e=0;t.length>e;e++){let l=O.v.createTextNode(t[e]);i.parentNode.insertBefore(l,i);if(e>0){let t=new lt(l.previousSibling,l);this.re.push(t);r++}}n.push(i)}}}}n.map(t=>t.remove());if(r!==t.length-1)throw Error("Solarite: bad html or duplicate attribute: "+t.join("${...}"));for(let t of this.re){t.ft=t.J?[].indexOf.call(t.J.parentNode.childNodes,t.J):-1;t.ot=M.get(t.K)}this.De();this.ue=!0;for(let t of this.re){if(t instanceof pt){this.fe=!0;this.ue=!1}else 1!==t.it()&&(this.ue=!1);t.X&&(this.he=!0)}this.ie=this.fe||this.he&&this.ue;this.He();if(this.xe&&this.ue){let t=[],e=!0;for(let i=0;this.re.length>i;i++){let l=this.re[i];if(l instanceof lt){if(!l.B){e=!1;break}t.push(i)}else if(!(l instanceof H||l instanceof ct)){e=!1;break}}if(e){this.Te=!0;this.Oe=t;this.Le=this.re.map(t=>t.st(null,t.K));let e=this.re.length;this.Pe=new Uint8Array(e);this.Ce=new Uint16Array(e);this.je=Array(e).fill(null);this.Me=new Uint8Array(e);let i=null;for(let t=0;e>t;t++){let e=this.re[t],l=this.Le[t];this.Ce[t]=e.Fe;this.Me[t]=(l.X?1:0)|(l.B?2:0);if(e instanceof ct)this.Pe[t]=1;else if(l.B)this.Pe[t]=2;else if(l instanceof Z&&void 0!==l.vt&&!l.rt){this.Pe[t]=3;this.je[t]=l;(i??=[]).push(l.kt)}else if(l instanceof H&&!l.rt&&!l.X&&!l.Y){this.Pe[t]=4;this.je[t]=l.nt}}this.Re=i}}}static Ie(t){let e="",i=!1,l=null;for(let s=0;t.length>s;s++){let n=t[s],r=0;for(let t=0;n.length>t;t++){const s=n[t];if(i)l?s===l&&(l=null):'"'===s||"'"===s?l=s:">"===s&&(i=!1);else if("<"===s&&n[t+1].match(/[/a-z!]/i)){i=!0;mt.lastIndex=t;let l=mt.exec(n);if(l){let i=t+l[0].length;e+=n.slice(r,i)+"-SOLARITE-PLACEHOLDER";r=i}}}e+=n.slice(r);t.length-1>s&&(e+=i?String.fromCharCode(St+s):yt)}return e}De(){this.scripts=[].map.call(this.Ae.querySelectorAll("script"),t=>M.get(t));this.styles=[].map.call(this.Ae.querySelectorAll("style"),t=>M.get(t));this.ids=[].map.call(this.Ae.querySelectorAll("[id],[data-id]"),t=>M.get(t));this.ke=this.ids.length>0||this.styles.length>0||this.scripts.length>0}He(){if(this.fe||!this.re.length)return;let t=[],e=new Map,i=this.Ae,l=1,s=n=>{if(n===i)return 0;let r=e.get(n);if(void 0===r){let i=0,o=-1;for(let t=n.previousSibling;t;t=t.previousSibling){i++;let l=e.get(t);if(void 0!==l){o=l;break}}let f=[].indexOf.call(n.parentNode.childNodes,n);0>o||i>f+1?t.push(s(n.parentNode),f):t.push(o,-i);r=l++;e.set(n,r)}return r};for(let t of this.re){t.Fe=t.K===i?0:s(t.K);t.ze=t.J?s(t.J):-1}this.Ne=t;this.$e=Array(l);this.ke||1!==i.childNodes.length||1!==i.firstChild.nodeType||2>t.length||0!==t[0]||0!==t[1]||(this.xe=!0)}static get(t,e=!1){if(t===wt&&e===vt)return gt;let i=O.C.get(t);if(!i){i={};O.C.set(t,i)}let l=e?"svg":"html",s=i[l];s||(s=i[l]=new dt(t,e));wt=t;vt=e;gt=s;return s}}const yt="\x3c!--!\u2728!--\x3e",mt=/<\/?[a-z][a-z0-9]*-[a-z0-9-]+/iy,bt=["TABLE","THEAD","TBODY","TFOOT","TR"];let wt=null,vt=!1,gt=null;const St=57344,Et=new dt,At=Symbol();class kt{St;ct;p;m;re=null;Wt;key;le;dt=!0;Z;Ge=null;styles;u;constructor(t,e=null,i=null,l=null){this.St=e?.U?.St||this;this.ct=e;this.u=t;void 0!==t.key&&(this.key=t.key);if(t.h){this.le=Et;this.Wt=t.de();this.p=this.m=i||O.v.createTextNode(t.html[0])}else{const s=this.le=dt.get(t.html,t.o);this.Wt=s.Wt??=t.de();if(s.xe&&null!==e){const t=s.Ae.firstChild.cloneNode(!0);this.p=this.m=t;!0!==s.Te&&this.Ve(t,s,0,!0)}else{const t=s.Ae.cloneNode(!0);if(11===t.nodeType){this.p=t.firstChild;this.m=t.lastChild}else this.p=this.m=t;this.instantiate(s,t,i,l)}}}instantiate(t,e,i,l){t.re.length?this.Ve(e,t):this.re=[];t.ke&&this.We(e,t)}oe(t,e=!0,i=null){let l=this.re;if(this.le.ue){if(e){if(null===l){this._e(t);return}for(let e=l.length-1;e>=0;e--){let s=l[e];null!==i&&s.q&&i[e]===t[e]||s.et(t[e])}this.styles&&this.pe();this.Z=null}this.dt=!1;return}if(!l){this.dt=!1;return}let s=t.length,n=Array(l.length);for(let i,r=l.length-1;i=l[r];r--){if(0===r&&i instanceof pt&&i.K===this.wt())continue;let l=i.it();n[r]=t.slice(s-l,s);s-=l;if(i instanceof pt){let t=n.slice(r+1,r+1+i.be.length);i.tt(t)}else e&&i.tt(n[r])}if(e){this.pe();this.Z=null}this.dt=!1}_e(t){let e=this.le,i=e.Oe;for(let l=0;i.length>l;l++){let s=typeof t[i[l]];if("string"!==s&&"number"!==s){let i=this.ce(e);for(let e=i.length-1;e>=0;e--)i[e].et(t[e]);this.Z=null;this.dt=!1;return}}let s=this.Je(e),n=e.Pe,r=e.Ce,o=e.je,f=e.Le,h=this.St,u=h.Et,a=h.gt?.eventDelegation,c=!1!==a&&!Array.isArray(a),p=e.Re;if(null!==p&&c&&h[At]!==e){for(let t=0;p.length>t;t++)l(u,p[t]);h[At]=e}let d=this.dt;for(let e=n.length-1;e>=0;e--){let i=t[e],l=n[e];if(2===l){"number"==typeof i&&(i+="");s[r[e]].textContent=i}else if(3===l&&c&&("function"==typeof i||Array.isArray(i)&&"function"==typeof i[0])){let t=s[r[e]];t[o[e].vt]=i;t[V]=u}else if(4===l&&d&&"string"==typeof i)""!==i&&s[r[e]].setAttribute(o[e],i);else if(1===l)this.key=i;else{let t=f[e];t.K=s[r[e]];t.U=this;t.et(i)}}this.Z=null;this.dt=!1}ae(t){let e=this.le,i=t.exprs,l=e.Oe;for(let t=0;l.length>t;t++){let e=typeof i[l[t]];if("string"!==e&&"number"!==e)return!1}let s=this.u.exprs,n=e.Le,r=e.Ce,o=e.Me,f=this.Ge;for(let t=n.length-1;t>=0;t--){let l=s[t],h=i[t],u=o[t];if(l!==h&&!S(l,h)||1&u&&"boolean"==typeof h){null===f&&(f=this.Ge=this.Je(e).slice());let l=n[t],s=f[r[t]];if(2&u){let e=i[t],n=s.firstChild;"number"==typeof e&&(e+="");if(null!==n&&3===n.nodeType&&n===s.lastChild)n.nodeValue=e;else{l.K=s;l.U=this;l.et(i[t]);l.Ht=null;l.Ft=null;l.Z=null}continue}l.K=s;l.U=this;l.et(i[t])}}return!0}Je(t){let e=t.$e;e[1]=this.p;return w(e,t.Ne,2,2)}ce(t=null){t??=this.le;let e=this.Ke(t,this.Je(t));for(let i of t.Oe){let t=e[i],l=t.K.firstChild;if(null!==l&&3===l.nodeType&&l===t.K.lastChild){t.Ht=l;t.Ft=l.nodeValue}}return e}te(){let t=this.Z;if(t)return t;t=[];let e=this.p,i=this.m?.nextSibling;for(;e&&e!==i;){t.push(e);e=e.nextSibling}this.Z=t;return t}wt(){return this.St.Et}Ve(t,e,i=0,l=!1){let s=e.Ne;if(s&&0===i){let i;if(l)i=this.Je(e);else{i=e.$e;i[0]=t;w(i,s,0,1)}this.Ke(e,i)}else{let l=e.re,s=l.length,n=this.re=Array(s);for(let e=0;s>e;e++){let s=l[e].clone(t,i);s.U=this;n[e]=s}}}Ke(t,e){let i=t.re,l=i.length,s=this.re=Array(l);for(let t=0;l>t;t++){let l=i[t],n=l.st(0>l.ze?null:e[l.ze],e[l.Fe]);n.U=this;s[t]=n}return s}pe(){if(this.styles)for(let[t,e]of this.styles)e!==t.textContent&&C.I(t,this.St.Et)}We(t,e,i=0){let l=this.St.Et;if(l){let s=this.St.gt;if(!1!==s?.ids)for(let s of e.ids){let e=M.resolve(t,s,i);C.M(l,e)}if(!1!==s?.styles){e.styles.length&&(this.styles=new Map);for(let s of e.styles){let e=M.resolve(t,s,i);if(1===l.nodeType){C.I(e,l);this.styles.set(e,e.textContent)}}}if(!1!==s?.scripts)for(let l of e.scripts){let e=M.resolve(t,l,i);(0,eval)(e.textContent)}}}}class xt extends kt{instantiate(t,e,i,l){let s=0;this.gt=l;if(e instanceof Text){if(!i)throw Error("Text node needs an element.");this.Et=i;e.nodeValue.length&&this.Et.append(e)}else{if(i){this.Et=i;let t,l=O.$,o=l?.Se===i.constructor?l.Ee:i.childNodes.length?[...i.childNodes]:null;if(o){t=O.v.createDocumentFragment();t.append(...o)}if(r=this.Et.tagName,1===(n=e).children.length&&r.includes("-")&&n.children[0].tagName.replace("-SOLARITE-PLACEHOLDER","")===r){this.Et.append(...e.children[0].childNodes);for(let t of e.children[0].attributes)this.Et.hasAttribute(t.name)||this.Et.setAttribute(t.name,t.value);s=1}else 1===e.childNodes.length&&3===e.childNodes[0].nodeType&&""===e.childNodes[0].textContent||this.Et.append(...e.childNodes);if(t){for(let e of i.querySelectorAll("slot[name]")){let i=e.getAttribute("name");if(i){let l=t.querySelectorAll(`[slot='${i}']`);e.append(...l)}}let e=i.querySelector("slot:not([name])");e?e.append(t):i.append(t)}}else{let t=C.S(e.childNodes),i=1===t.length?t[0]:null;this.Et=i||e;i&&(s=1)}this.Ve(this.Et,t,s);this.We(this.Et,t,s)}var n,r;this.p=this.m=this.Et;O.P.set(this.Et,this)}}let Tt=1,Nt=new WeakMap;class $t{exprs=void 0;html=void 0;Wt;h;key;o=!1;constructor(t=[""],e=[]){this.html=t;this.exprs=e}render(t=null,e={}){let i=t&&O.P.get(t);if(!i){i=new xt(this,null,t,e);t||(t=i.wt())}if(1!==this.html?.length||this.html[0]){let t=i.u;i.oe(this.exprs,!0,t!==this&&t.html===this.html?t.exprs:null);i.u=this}else t.innerHTML="";return t}de(){void 0===this.Wt&&(this.Wt=this.exprs.length?v(this.html):this.html[0]);return this.Wt}}let Ot="render";const Lt=Symbol(),Pt=Symbol();k.immutableMap=k.map=(t,e)=>new it(t,e);k.selector=(t=null)=>new D(t);let Ct=new Proxy(HTMLElement,{construct(t,e,i){C.i(i);return Reflect.construct(t,e,i)}});class jt extends Ct{constructor(t=null,e=null){super();if(t){if("object"!=typeof t)throw Error("First argument must be an object.");if(!Object.keys(t).length){let e=jt.getAttribs(this);for(let i in e)t[i]=e[i]}for(let i in e||{})"string"==typeof t[i]&&(t[i]=x(t[i],e[i]))}}render(){throw Error("render() is not defined for "+this.constructor.name)}renderFirstTime(){if(!O.k.has(this)){let t=jt.getAttribs(this);this.render(t)}}connectedCallback(){this.renderFirstTime()}static define(t=null){C.i(this,t)}static getAttribs(t){let e=C.R(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 k;export{Y as Fragment,O as Globals,q as InternalJsxAttr,it as MappedList,D as Selector,I as SelectorRef,jt as Solarite,C as SolariteUtil,$t as Template,T as assignAttributes,x as convertType,t as delve,i as getEventBinding,k as h,f as internalJsxToTemplate,A as svg,E as toEl};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// Generated by build/build.js from src/jsx-runtime.js — do not edit.
|
|
2
|
+
import{Template as e}from"./Solarite.min.js";import{InternalJsxAttr as t,internalJsxToTemplate as r,Fragment as n}from"./Solarite.min.js";export{n as Fragment};export function jsxTemplate(r,...n){let o;for(let e=0;e<n.length;e++){let r=n[e];r instanceof t&&"key"===r.name&&(o=r.value,n[e]="")}let i=new e(r,n);return void 0!==o&&(i.key=o),i}export function jsxAttr(e,r){return new t(e,r)}export function jsxEscape(e){return e}export function jsx(e,t,n){let o="children"in(t=t||{})?[t.children]:[];return r(e,t,o,n)}export function jsxs(e,t,n){let o=(t=t||{}).children;return o=Array.isArray(o)?o:void 0===o?[]:[o],r(e,t,o,n)}export function jsxDEV(e,t,r){return jsx(e,t,r)}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solarite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Solarite is a small (12.
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Solarite is a small (12.7KB with Brotli), 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",
|
package/readme.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Solarite
|
|
2
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
|
|
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 changed. It's small (12.7KB with Brotli) and runs straight in the browser as a standard ES module.
|
|
4
4
|
|
|
5
|
-
**[Documentation & live examples →](https://eric-frost.github.io/solarite/)**
|
|
5
|
+
**[Documentation & live examples →](https://eric-frost.github.io/solarite/docs/)**
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -40,7 +40,7 @@ document.body.append(new Counter());
|
|
|
40
40
|
|
|
41
41
|
## Why Solarite?
|
|
42
42
|
|
|
43
|
-
It's one of the fastest UI libraries measured
|
|
43
|
+
It's one of the fastest UI libraries measured. It scores **1.07** on the [js-framework-benchmark](https://krausest.github.io/js-framework-benchmark/current.html), where hand-written vanilla JavaScript scores 1.01 and lower is better.
|
|
44
44
|
|
|
45
45
|
### Compared to Lit
|
|
46
46
|
|
|
@@ -48,11 +48,11 @@ It's one of the fastest UI libraries measured: a score of **1.10** on the [js-fr
|
|
|
48
48
|
|
|
49
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
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
|
-
- **
|
|
51
|
+
- **No build step.** Solarite works in vanilla JS with a single import statement. JSX plugins for Babel, esbuild, and Vite are there if you want them.
|
|
52
52
|
- **Closer to vanilla speed.** Solarite sits near the top of the [js-framework-benchmark](https://krausest.github.io/js-framework-benchmark/current.html), ahead of most signal-based and virtual-DOM libraries.
|
|
53
53
|
|
|
54
|
-
The trade-off is
|
|
54
|
+
The trade-off is that Solarite doesn't track dependencies for you. It re-renders when you call `render()`.
|
|
55
55
|
|
|
56
56
|
## License
|
|
57
57
|
|
|
58
|
-
[MIT](LICENSE)
|
|
58
|
+
[MIT](LICENSE). Free for commercial use, no attribution required.
|
package/src/Globals.js
CHANGED
|
@@ -11,8 +11,17 @@ function reset() {
|
|
|
11
11
|
connected: new WeakSet(),
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* A hand-off in flight from PathToComponent.applyAll(), which parks the child nodes
|
|
15
|
+
* declared inside a component's tag here just before constructing it, to that
|
|
16
|
+
* component's RootNodeGroup.instantiate(), which puts them in its <slot>. Null when
|
|
17
|
+
* no hand-off is pending.
|
|
18
|
+
*
|
|
19
|
+
* It is addressed by Constructor rather than by tag name because a customized
|
|
20
|
+
* built-in has no usable tag at the moment it is consumed: a <tr is="my-row">
|
|
21
|
+
* reports a tagName of TR, and its 'is' attribute is not written until after the
|
|
22
|
+
* constructor -- which may already have rendered -- has returned.
|
|
23
|
+
*
|
|
24
|
+
* @type {?{Constructor:Function, nodes:Node[]}} */
|
|
16
25
|
currentSlotChildren: null,
|
|
17
26
|
|
|
18
27
|
div: document.createElement("div"),
|
|
@@ -52,4 +61,15 @@ function reset() {
|
|
|
52
61
|
}
|
|
53
62
|
reset();
|
|
54
63
|
|
|
64
|
+
// Warn when a second copy of Solarite loads into the same page. Each copy has its own classes and its own Globals,
|
|
65
|
+
// so a template or component made by one is not recognised by the other, and the failure that follows (a template
|
|
66
|
+
// rendered as "[object Object]", a slot that stays empty) gives no hint of the cause. The usual ways to get two are
|
|
67
|
+
// importing both Solarite.js and Solarite.min.js, or a JSX runtime file that doesn't match the build being imported.
|
|
68
|
+
// The marker is the same for every build, so the source, debug, and minified builds all detect one another.
|
|
69
|
+
let copy = Symbol.for('solarite');
|
|
70
|
+
if (globalThis[copy])
|
|
71
|
+
console.warn(`Solarite loaded twice: ${globalThis[copy]} and ${import.meta.url}. Templates and components from one won't work in the other.`);
|
|
72
|
+
else
|
|
73
|
+
globalThis[copy] = import.meta.url;
|
|
74
|
+
|
|
55
75
|
export default Globals;
|
package/src/NodeGroup.js
CHANGED
|
@@ -330,17 +330,17 @@ export default class NodeGroup {
|
|
|
330
330
|
let stampers = shell.stampPaths;
|
|
331
331
|
let rootNg = this.rootNg;
|
|
332
332
|
let root = rootNg.rootEl;
|
|
333
|
+
// Any value other than false or an array of event names means delegate everything.
|
|
333
334
|
let opt = rootNg.renderOptions?.eventDelegation;
|
|
334
|
-
let
|
|
335
|
-
let delegateAll = opt === undefined || opt === true || delegateDoc;
|
|
335
|
+
let delegateAll = opt !== false && !Array.isArray(opt);
|
|
336
336
|
|
|
337
337
|
// Register this shell's delegated dispatchers once for a whole run of rows. They live on
|
|
338
|
-
// the root, not on the bound nodes, so asking per node — as the general
|
|
339
|
-
// to — would be a call and a set lookup for every handler in the list.
|
|
338
|
+
// the root and the document, not on the bound nodes, so asking per node — as the general
|
|
339
|
+
// binding path has to — would be a call and a set lookup for every handler in the list.
|
|
340
340
|
let names = shell.stampEventNames;
|
|
341
341
|
if (names !== null && delegateAll && rootNg[lastStampedShellKey] !== shell) {
|
|
342
342
|
for (let k=0; k<names.length; k++)
|
|
343
|
-
ensureDelegatedDispatcher(root, names[k]
|
|
343
|
+
ensureDelegatedDispatcher(root, names[k]);
|
|
344
344
|
rootNg[lastStampedShellKey] = shell;
|
|
345
345
|
}
|
|
346
346
|
|
package/src/PathToAttribValue.js
CHANGED
|
@@ -277,17 +277,20 @@ export default class PathToAttribValue extends Path {
|
|
|
277
277
|
|
|
278
278
|
// Delegated path: a bubbling event (when the root's options allow it, the default)
|
|
279
279
|
// stores its handler directly on the node as a per-event-type Symbol expando, with no
|
|
280
|
-
// EventBinding object and no addEventListener call.
|
|
281
|
-
//
|
|
282
|
-
// the
|
|
283
|
-
//
|
|
280
|
+
// EventBinding object and no addEventListener call. When an event of that type
|
|
281
|
+
// starts, jitDispatcher() attaches a real listener to each node on its path that
|
|
282
|
+
// carries the expando, so the browser runs the handler at the node's own turn.
|
|
283
|
+
// Re-renders just overwrite the property. this.delegatedKey is set by the PathToEvent
|
|
284
|
+
// constructor only for delegatable event names, so this test also excludes
|
|
285
|
+
// non-bubbling events and native:on* bindings.
|
|
284
286
|
if (capture === false && this.delegatedKey !== undefined) {
|
|
285
287
|
let opt = this.parentNg.rootNg.renderOptions?.eventDelegation ?? true;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
// true delegates everything, an array only the events it names, and any other
|
|
289
|
+
// value (such as the retired 'document' string) counts as true.
|
|
290
|
+
if (opt !== false && (!Array.isArray(opt) || opt.includes(eventName))) {
|
|
288
291
|
let dk = this.delegatedKey;
|
|
289
292
|
if (node[dk] === undefined) // First binding of this type on this node.
|
|
290
|
-
ensureDelegatedDispatcher(root, eventName
|
|
293
|
+
ensureDelegatedDispatcher(root, eventName);
|
|
291
294
|
// Array-form bindings (onclick=${[fn, arg]}, the hot per-row case) store the
|
|
292
295
|
// template's own [func, ...args] array; a plain function is stored bare.
|
|
293
296
|
// Either way, nothing is allocated.
|
|
@@ -359,7 +362,7 @@ export function getEventBinding(node, key) {
|
|
|
359
362
|
return b instanceof EventBinding ? (b.key === key ? b : undefined) : b[key];
|
|
360
363
|
}
|
|
361
364
|
|
|
362
|
-
// Bubbling events
|
|
365
|
+
// Bubbling events the just-in-time dispatcher handles. Same set Solid.js delegates.
|
|
363
366
|
const delegatableEvents = new Set(['beforeinput', 'click', 'contextmenu', 'dblclick', 'focusin', 'focusout',
|
|
364
367
|
'input', 'keydown', 'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
|
|
365
368
|
'pointerdown', 'pointermove', 'pointerout', 'pointerover', 'pointerup', 'touchend', 'touchmove', 'touchstart']);
|
|
@@ -383,79 +386,142 @@ export function delegatedKeyFor(eventName) {
|
|
|
383
386
|
// Exported so NodeGroup.applyStamp()'s compiled stamp program can write it directly.
|
|
384
387
|
export const delegatedRootKey = Symbol('solariteDelegatedRoot');
|
|
385
388
|
|
|
386
|
-
//
|
|
389
|
+
// Set of event types that already have the dispatcher registered, kept on each root element
|
|
390
|
+
// and on each document.
|
|
387
391
|
const delegatedTypesKey = Symbol('solariteDelegatedTypes');
|
|
388
392
|
|
|
389
393
|
/**
|
|
390
|
-
* Register the
|
|
391
|
-
* Shared by bindEvent()'s delegated branch and NodeGroup.applyStamp()'s stamp program.
|
|
394
|
+
* Register the just-in-time dispatcher for eventName on root and on root's document, once
|
|
395
|
+
* each. Shared by bindEvent()'s delegated branch and NodeGroup.applyStamp()'s stamp program.
|
|
392
396
|
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
397
|
+
* Both registrations are needed. The document's listener is what still reaches a bound node
|
|
398
|
+
* after another component re-parents it outside its root (a toolbar a dock parks in its own
|
|
399
|
+
* chrome). The root's listener is what reaches what the document cannot see: a component
|
|
400
|
+
* that isn't in the document at all, nodes inside a closed shadow root, and a synthetic
|
|
401
|
+
* event dispatched inside any shadow root without composed:true, which never leaves it.
|
|
398
402
|
* @param root {HTMLElement}
|
|
399
|
-
* @param eventName {string}
|
|
400
|
-
|
|
401
|
-
export function ensureDelegatedDispatcher(root, eventName, andDocument=false) {
|
|
403
|
+
* @param eventName {string} */
|
|
404
|
+
export function ensureDelegatedDispatcher(root, eventName) {
|
|
402
405
|
let types = root[delegatedTypesKey];
|
|
403
406
|
if (types === undefined)
|
|
404
407
|
types = root[delegatedTypesKey] = new Set();
|
|
405
408
|
if (!types.has(eventName)) {
|
|
406
409
|
types.add(eventName);
|
|
407
|
-
root.addEventListener(eventName,
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
let doc = root.ownerDocument ?? document;
|
|
410
|
+
root.addEventListener(eventName, jitDispatcher, true);
|
|
411
|
+
|
|
412
|
+
let doc = root.ownerDocument;
|
|
411
413
|
let docTypes = doc[delegatedTypesKey];
|
|
412
414
|
if (docTypes === undefined)
|
|
413
415
|
docTypes = doc[delegatedTypesKey] = new Set();
|
|
414
416
|
if (!docTypes.has(eventName)) {
|
|
415
417
|
docTypes.add(eventName);
|
|
416
|
-
doc.addEventListener(eventName,
|
|
418
|
+
doc.addEventListener(eventName, jitDispatcher, true);
|
|
417
419
|
}
|
|
418
420
|
}
|
|
419
421
|
}
|
|
420
422
|
|
|
421
|
-
//
|
|
422
|
-
//
|
|
423
|
+
// Set on an event by the first dispatcher to walk it, holding the length of the path it saw,
|
|
424
|
+
// so the dispatchers on nested roots further down don't repeat the walk. A root inside a
|
|
425
|
+
// closed shadow root sees a longer path than the document did, because composedPath() hides
|
|
426
|
+
// a closed tree from listeners outside it, and that mismatch is what makes it walk again.
|
|
423
427
|
const delegatedDoneKey = Symbol('solariteDelegated');
|
|
424
428
|
|
|
425
429
|
/**
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
430
|
+
* One shared bubble-phase listener per event type, attached to a node only for the duration
|
|
431
|
+
* of one event. The browser invokes it at the node's own turn in propagation, and it reads
|
|
432
|
+
* the node's handler THEN rather than when it was attached, so a handler that an earlier
|
|
433
|
+
* listener in the same dispatch replaced or removed is honored.
|
|
434
|
+
* @type {Object<string, {handleEvent: function(Event)}>} */
|
|
435
|
+
const trampolines = {};
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @param type {string}
|
|
439
|
+
* @return {{handleEvent: function(Event)}} */
|
|
440
|
+
function trampolineFor(type) {
|
|
441
|
+
let tramp = trampolines[type];
|
|
442
|
+
if (tramp === undefined) {
|
|
443
|
+
let dk = delegatedKeys[type];
|
|
444
|
+
tramp = trampolines[type] = {
|
|
445
|
+
// Quoted so the minifier's property mangling doesn't rename it, since the browser looks it up by name.
|
|
446
|
+
'handleEvent'(ev) {
|
|
447
|
+
let node = ev.currentTarget;
|
|
448
|
+
let a = node[dk];
|
|
449
|
+
if (a === undefined) // Unbound by an earlier handler in this same dispatch.
|
|
450
|
+
return;
|
|
451
|
+
let root = node[delegatedRootKey];
|
|
452
|
+
if (typeof a === 'function')
|
|
453
|
+
a.call(root, ev, node);
|
|
454
|
+
else
|
|
455
|
+
switch (a.length) {
|
|
456
|
+
case 1: a[0].call(root, ev, node); break;
|
|
457
|
+
case 2: a[0].call(root, a[1], ev, node); break;
|
|
458
|
+
case 3: a[0].call(root, a[1], a[2], ev, node); break;
|
|
459
|
+
default: a[0].call(root, ...a.slice(1), ev, node);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
return tramp;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// Nodes still carrying a trampoline, per event type, and the one timer that clears them.
|
|
468
|
+
const pending = {};
|
|
469
|
+
let sweepTimer = 0;
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Remove every trampoline attached since the last sweep. Runs as a task, which is always
|
|
473
|
+
* after every dispatch in progress has finished. A microtask would not be: for a real click
|
|
474
|
+
* the browser runs a microtask checkpoint between listeners, so a microtask sweep would strip
|
|
475
|
+
* the trampolines before the event reached the first of them. The sweep is housekeeping
|
|
476
|
+
* only; a trampoline left in place is harmless, because jitDispatcher() re-attaches it and
|
|
477
|
+
* the trampoline reads its handler fresh. */
|
|
478
|
+
function sweep() {
|
|
479
|
+
sweepTimer = 0;
|
|
480
|
+
for (let type in pending) {
|
|
481
|
+
let nodes = pending[type];
|
|
482
|
+
if (nodes.length !== 0) {
|
|
483
|
+
pending[type] = [];
|
|
484
|
+
let tramp = trampolines[type];
|
|
485
|
+
for (let i=0; i<nodes.length; i++)
|
|
486
|
+
nodes[i].removeEventListener(type, tramp);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* The capture-phase listener registered per delegated event type on every root and on the
|
|
493
|
+
* document. It runs before the event reaches anything, walks the event's path, and attaches
|
|
494
|
+
* the type's trampoline to each node holding a delegated handler. The browser then finishes
|
|
495
|
+
* the dispatch natively, so those handlers interleave correctly with listeners anyone else
|
|
496
|
+
* registered, stopPropagation() works in both directions, currentTarget is right, and the
|
|
497
|
+
* event needn't bubble.
|
|
498
|
+
*
|
|
499
|
+
* Each attach removes the trampoline first. One left from an earlier event in this same task
|
|
500
|
+
* would otherwise keep its old place in the node's listener list, ahead of listeners added
|
|
501
|
+
* since; removing and re-adding puts it last, so the rule holds without exception: a
|
|
502
|
+
* delegated handler runs after every listener its element had when the event started. */
|
|
503
|
+
function jitDispatcher(ev) {
|
|
504
|
+
let path = ev.composedPath();
|
|
505
|
+
if (ev[delegatedDoneKey] === path.length)
|
|
435
506
|
return;
|
|
436
|
-
ev[delegatedDoneKey] =
|
|
437
|
-
|
|
438
|
-
let
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
case 3: a[0].call(root, a[1], a[2], ev, current); break;
|
|
451
|
-
default: a[0].call(root, ...a.slice(1), ev, current);
|
|
452
|
-
}
|
|
453
|
-
if (ev.cancelBubble)
|
|
454
|
-
break;
|
|
507
|
+
ev[delegatedDoneKey] = path.length;
|
|
508
|
+
|
|
509
|
+
let type = ev.type;
|
|
510
|
+
let dk = delegatedKeys[type];
|
|
511
|
+
let tramp = trampolineFor(type);
|
|
512
|
+
let list = pending[type];
|
|
513
|
+
if (list === undefined)
|
|
514
|
+
list = pending[type] = [];
|
|
515
|
+
for (let i=0; i<path.length; i++) {
|
|
516
|
+
let node = path[i];
|
|
517
|
+
if (node[dk] !== undefined) {
|
|
518
|
+
node.removeEventListener(type, tramp);
|
|
519
|
+
node.addEventListener(type, tramp);
|
|
520
|
+
list.push(node);
|
|
455
521
|
}
|
|
456
|
-
current = current.parentNode;
|
|
457
522
|
}
|
|
458
|
-
|
|
523
|
+
if (list.length !== 0 && sweepTimer === 0)
|
|
524
|
+
sweepTimer = setTimeout(sweep);
|
|
459
525
|
}
|
|
460
526
|
|
|
461
527
|
class EventBinding {
|