@symbiotejs/symbiote 1.8.3 → 1.8.6

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.
@@ -1 +1 @@
1
- var O=Object.defineProperty;var N=(a,t,e)=>t in a?O(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var E=(a,t,e)=>(N(a,typeof t!="symbol"?t+"":t,e),e);function $(a){let t=e=>{var s;for(let i in e)((s=e[i])==null?void 0:s.constructor)===Object&&(e[i]=t(e[i]));return{...e}};return t(a)}var n=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=$(t.schema):(this._storeIsProxy=!0,this.store=t.schema),this.callbackMap=Object.create(null)}static warn(t,e){console.warn(`Symbiote Data: cannot ${t}. Prop name: `+e)}read(t){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(n.warn("read",t),null):this.store[t]}has(t){return this._storeIsProxy?this.store[t]!==void 0:this.store.hasOwnProperty(t)}add(t,e,s=!1){!s&&Object.keys(this.store).includes(t)||(this.store[t]=e,this.notify(t))}pub(t,e){if(!this._storeIsProxy&&!this.store.hasOwnProperty(t)){n.warn("publish",t);return}this.add(t,e)}multiPub(t){for(let e in t)this.pub(e,t[e])}notify(t){this.callbackMap[t]&&this.callbackMap[t].forEach(e=>{e(this.store[t])})}sub(t,e,s=!0){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(n.warn("subscribe",t),null):(this.callbackMap[t]||(this.callbackMap[t]=new Set),this.callbackMap[t].add(e),s&&e(this.store[t]),{remove:()=>{this.callbackMap[t].delete(e),this.callbackMap[t].size||delete this.callbackMap[t]},callback:e})}remove(){delete n.globalStore[this.uid]}static registerLocalCtx(t){let e=new n({schema:t});return n.globalStore[e.uid]=e,e}static registerNamedCtx(t,e){let s=n.globalStore[t];return s?console.warn('State: context name "'+t+'" already in use'):(s=new n({name:t,schema:e}),n.globalStore[t]=s),s}static clearNamedCtx(t){delete n.globalStore[t]}static getNamedCtx(t,e=!0){return n.globalStore[t]||(e&&console.warn('State: wrong context name - "'+t+'"'),null)}};n.globalStore=Object.create(null);var o=Object.freeze({BIND_ATTR:"set",ATTR_BIND_PRFX:"@",EXT_DATA_CTX_PRFX:"*",NAMED_DATA_CTX_SPLTR:"/",CTX_NAME_ATTR:"ctx-name",CSS_CTX_PROP:"--ctx-name",EL_REF_ATTR:"ref",AUTO_TAG_PRFX:"sym",REPEAT_ATTR:"repeat",REPEAT_ITEM_TAG_ATTR:"repeat-item-tag"});var x="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",I=x.length-1,S=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:x.charAt(Math.random()*I);return e}};function R(a,t){[...a.querySelectorAll(`[${o.REPEAT_ATTR}]`)].forEach(e=>{let s=e.getAttribute(o.REPEAT_ITEM_TAG_ATTR),i;if(s&&(i=window.customElements.get(s)),!i){i=class extends t.BaseComponent{constructor(){super();s||(this.style.display="contents")}};let l=e.innerHTML;i.template=l,i.reg(s)}for(;e.firstChild;)e.firstChild.remove();let r=e.getAttribute(o.REPEAT_ATTR);t.sub(r,l=>{if(!l){for(;e.firstChild;)e.firstChild.remove();return}let h=[...e.children],T,g=C=>{C.forEach((_,p)=>{if(h[p])if(h[p].set$)h[p].set$(_);else for(let c in _)h[p][c]=_[c];else{T||(T=new DocumentFragment);let c=new i;Object.assign(c.init$,_),T.appendChild(c)}}),T&&e.appendChild(T);let d=h.slice(C.length,h.length);for(let _ of d)_.remove()};if(l.constructor===Array)g(l);else if(l.constructor===Object){let C=[];for(let d in l){let _=l[d];Object.defineProperty(_,"_KEY_",{value:d,enumerable:!0}),C.push(_)}g(C)}else console.warn("Symbiote repeat data type error:"),console.log(l)}),e.removeAttribute(o.REPEAT_ATTR),e.removeAttribute(o.REPEAT_ITEM_TAG_ATTR)})}function k(a,t){if(t.shadowRoot)return;let e=[...a.querySelectorAll("slot")];if(t.initChildren.length&&e.length){let s={};e.forEach(i=>{let r=i.getAttribute("name");r?s[r]={slot:i,fr:document.createDocumentFragment()}:s.__default__={slot:i,fr:document.createDocumentFragment()}}),t.initChildren.forEach(i=>{var l;let r=(l=i.getAttribute)==null?void 0:l.call(i,"slot");r?(i.removeAttribute("slot"),s[r].fr.appendChild(i)):s.__default__&&s.__default__.fr.appendChild(i)}),Object.values(s).forEach(i=>{i.slot.parentNode.insertBefore(i.fr,i.slot),i.slot.remove()})}}function M(a,t){[...a.querySelectorAll(`[${o.EL_REF_ATTR}]`)].forEach(e=>{let s=e.getAttribute(o.EL_REF_ATTR);t.ref[s]=e,e.removeAttribute(o.EL_REF_ATTR)})}function F(a,t){[...a.querySelectorAll(`[${o.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(o.BIND_ATTR).split(";").forEach(r=>{if(!r)return;let l=r.split(":").map(c=>c.trim()),h=l[0],T;h.indexOf(o.ATTR_BIND_PRFX)===0&&(T=!0,h=h.replace(o.ATTR_BIND_PRFX,""));let g=l[1].split(",").map(c=>c.trim()),C,d,_,p;if(h.includes(".")){C=!0;let c=h.split(".");p=()=>{d=e,c.forEach((A,u)=>{u<c.length-1?d=d[A]:_=A})},p()}for(let c of g){let A;c.startsWith("!!")?(A="double",c=c.replace("!!","")):c.startsWith("!")&&(A="single",c=c.replace("!","")),t.sub(c,u=>{A==="double"?u=!!u:A==="single"&&(u=!u),T?(u==null?void 0:u.constructor)===Boolean?u?e.setAttribute(h,""):e.removeAttribute(h):e.setAttribute(h,u):C?d?d[_]=u:window.setTimeout(()=>{p(),d[_]=u}):e[h]=u})}}),e.removeAttribute(o.BIND_ATTR)})}var y="{{",P="}}",j="skip-text";function L(a){let t,e=[],s=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,{acceptNode:i=>{var r;return!((r=i.parentElement)==null?void 0:r.hasAttribute(j))&&i.textContent.includes(y)&&i.textContent.includes(P)&&1}});for(;t=s.nextNode();)e.push(t);return e}var B=function(a,t){L(a).forEach(s=>{let i=[],r;for(;s.textContent.includes(P);)s.textContent.startsWith(y)?(r=s.textContent.indexOf(P)+P.length,s.splitText(r),i.push(s)):(r=s.textContent.indexOf(y),s.splitText(r)),s=s.nextSibling;i.forEach(l=>{let h=l.textContent.replace(y,"").replace(P,"");t.sub(h,T=>{l.textContent=T})})})},w=[R,k,M,F,B];var D=0,b=null,f=null,m=class extends HTMLElement{constructor(){super();E(this,"updateCssData",()=>{var t;this.dropCssDataCache(),(t=this.__boundCssProps)==null||t.forEach(e=>{let s=this.getCssData(this.__extractCssName(e),!0);this.$[e]!==s&&(this.$[e]=s)})});this.init$=Object.create(null),this.cssInit$=Object.create(null),this.tplProcessors=new Set,this.ref=Object.create(null),this.allSubs=new Set,this.pauseRender=!1,this.renderShadow=!1,this.readyToDestroy=!0,this.processInnerHtml=!1}get BaseComponent(){return m}initCallback(){}__initCallback(){var t;this.__initialized||(this.__initialized=!0,(t=this.initCallback)==null||t.call(this))}render(t,e=this.renderShadow){let s;if((e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"}),this.processInnerHtml)for(let r of this.tplProcessors)r(this,this);if(t||this.constructor.template){if(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template),(t==null?void 0:t.constructor)===DocumentFragment)s=t;else if((t==null?void 0:t.constructor)===String){let r=document.createElement("template");r.innerHTML=t,s=r.content.cloneNode(!0)}else this.constructor.__tpl&&(s=this.constructor.__tpl.content.cloneNode(!0));for(let r of this.tplProcessors)r(s,this)}let i=()=>{s&&(e&&this.shadowRoot.appendChild(s)||this.appendChild(s)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){e=!0;let r=document.createElement("link");r.rel="stylesheet",r.href=this.constructor.__shadowStylesUrl,r.onload=i,this.shadowRoot.prepend(r)}else i()}addTemplateProcessor(t){this.tplProcessors.add(t)}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=S.generate(),this.style.setProperty(o.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(o.CSS_CTX_PROP,!0)}get ctxName(){var t;return((t=this.getAttribute(o.CTX_NAME_ATTR))==null?void 0:t.trim())||this.cssCtxName||this.autoCtxName}get localCtx(){return this.__localCtx||(this.__localCtx=n.registerLocalCtx({})),this.__localCtx}get nodeCtx(){return n.getNamedCtx(this.ctxName,!1)||n.registerNamedCtx(this.ctxName,{})}static __parseProp(t,e){let s,i;if(t.startsWith(o.EXT_DATA_CTX_PRFX))s=e.nodeCtx,i=t.replace(o.EXT_DATA_CTX_PRFX,"");else if(t.includes(o.NAMED_DATA_CTX_SPLTR)){let r=t.split(o.NAMED_DATA_CTX_SPLTR);s=n.getNamedCtx(r[0]),i=r[1]}else s=e.localCtx,i=t;return{ctx:s,name:i}}sub(t,e){let s=m.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=m.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=m.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=m.__parseProp(t,this);s.ctx.add(s.name,e,!1)}add$(t){for(let e in t)this.add(e,t[e])}get $(){if(!this.__stateProxy){let t=Object.create(null);this.__stateProxy=new Proxy(t,{set:(e,s,i)=>{let r=m.__parseProp(s,this);return r.ctx.pub(r.name,i),!0},get:(e,s)=>{let i=m.__parseProp(s,this);return i.ctx.read(i.name)}})}return this.__stateProxy}set$(t,e=!1){for(let s in t){let i=t[s];e||![String,Number,Boolean].includes(i==null?void 0:i.constructor)?this.$[s]=i:this.$[s]!==i&&(this.$[s]=i)}}__initDataCtx(){let t=this.constructor.__attrDesc;if(t)for(let e of Object.values(t))Object.keys(this.init$).includes(e)||(this.init$[e]="");for(let e in this.init$)if(e.startsWith(o.EXT_DATA_CTX_PRFX))this.nodeCtx.add(e.replace(o.EXT_DATA_CTX_PRFX,""),this.init$[e]);else if(e.includes(o.NAMED_DATA_CTX_SPLTR)){let s=e.split(o.NAMED_DATA_CTX_SPLTR),i=s[0].trim(),r=s[1].trim();if(i&&r){let l=n.getNamedCtx(i,!1);l||(l=n.registerNamedCtx(i,{})),l.add(r,this.init$[e])}}else this.localCtx.add(e,this.init$[e]);for(let e in this.cssInit$)this.bindCssData(e,this.cssInit$[e]);this.__dataCtxInitialized=!0}connectedCallback(){var t;if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let e=(t=this.getAttribute(o.CTX_NAME_ATTR))==null?void 0:t.trim();e&&this.style.setProperty(o.CSS_CTX_PROP,`'${e}'`),this.__initDataCtx(),this.initChildren=[...this.childNodes];for(let s of w)this.addTemplateProcessor(s);this.pauseRender?this.__initCallback():this.render()}this.connectedOnce=!0}destroyCallback(){}disconnectedCallback(){this.dropCssDataCache(),!!this.readyToDestroy&&(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),this.__disconnectTimeout=window.setTimeout(()=>{this.destroyCallback();for(let t of this.allSubs)t.remove(),this.allSubs.delete(t);for(let t of this.tplProcessors)this.tplProcessors.delete(t);f==null||f.delete(this.updateCssData),(f==null?void 0:f.size)||(b==null||b.disconnect(),b=null,f=null)},100))}static reg(t,e=!1){if(t||(D++,t=`${o.AUTO_TAG_PRFX}-${D}`),this.__tag=t,window.customElements.get(t)){console.warn(`${t} - is already in "customElements" registry`);return}window.customElements.define(t,e?class extends this{}:this)}static get is(){return this.__tag||this.reg(),this.__tag}static bindAttributes(t){this.observedAttributes=Object.keys(t),this.__attrDesc=t}attributeChangedCallback(t,e,s){if(e===s)return;let i=this.constructor.__attrDesc[t];i?this.__dataCtxInitialized?this.$[i]=s:this.init$[i]=s:this[t]=s}getCssData(t,e=!1){if(this.__cssDataCache||(this.__cssDataCache=Object.create(null)),!Object.keys(this.__cssDataCache).includes(t)){this.__computedStyle||(this.__computedStyle=window.getComputedStyle(this));let s=this.__computedStyle.getPropertyValue(t).trim();s.startsWith("'")&&s.endsWith("'")&&(s=s.replace(/\'/g,'"'));try{this.__cssDataCache[t]=JSON.parse(s)}catch{!e&&console.warn(`CSS Data error: ${t}`),this.__cssDataCache[t]=null}}return this.__cssDataCache[t]}__extractCssName(t){return t.split("--").map((e,s)=>s===0?"":e).join("--")}__initStyleAttrObserver(){f||(f=new Set),f.add(this.updateCssData),b||(b=new MutationObserver(t=>{t[0].type==="attributes"&&f.forEach(e=>{e()})}),b.observe(document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style"]}))}bindCssData(t,e=""){this.__boundCssProps||(this.__boundCssProps=new Set),this.__boundCssProps.add(t);let s=this.getCssData(this.__extractCssName(t),!0);s===null&&(s=e),this.add(t,s),this.__initStyleAttrObserver()}dropCssDataCache(){this.__cssDataCache=null,this.__computedStyle=null}defineAccessor(t,e,s){let i="__"+t;this[i]=this[t],Object.defineProperty(this,t,{set:r=>{this[i]=r,s?window.setTimeout(()=>{e==null||e(r)}):e==null||e(r)},get:()=>this[i]}),this[t]=this[i]}static set shadowStyles(t){let e=new Blob([t],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(e)}},X=m;E(X,"template");export{X as BaseComponent};
1
+ var X=Object.defineProperty;var O=(l,t,e)=>t in l?X(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e;var S=(l,t,e)=>(O(l,typeof t!="symbol"?t+"":t,e),e);function N(l){let t=e=>{var s;for(let i in e)((s=e[i])==null?void 0:s.constructor)===Object&&(e[i]=t(e[i]));return{...e}};return t(l)}var c=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=N(t.schema):(this._storeIsProxy=!0,this.store=t.schema),this.callbackMap=Object.create(null)}static warn(t,e){console.warn(`Symbiote Data: cannot ${t}. Prop name: `+e)}read(t){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(c.warn("read",t),null):this.store[t]}has(t){return this._storeIsProxy?this.store[t]!==void 0:this.store.hasOwnProperty(t)}add(t,e,s=!1){if(!s&&Object.keys(this.store).includes(t)){e!==this.store[t]&&this.notify(t);return}this.store[t]=e,this.notify(t)}pub(t,e){if(!this._storeIsProxy&&!this.store.hasOwnProperty(t)){c.warn("publish",t);return}this.store[t]=e,this.notify(t)}multiPub(t){for(let e in t)this.pub(e,t[e])}notify(t){this.callbackMap[t]&&this.callbackMap[t].forEach(e=>{e(this.store[t])})}sub(t,e,s=!0){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(c.warn("subscribe",t),null):(this.callbackMap[t]||(this.callbackMap[t]=new Set),this.callbackMap[t].add(e),s&&e(this.store[t]),{remove:()=>{this.callbackMap[t].delete(e),this.callbackMap[t].size||delete this.callbackMap[t]},callback:e})}remove(){delete c.globalStore[this.uid]}static registerLocalCtx(t){let e=new c({schema:t});return c.globalStore[e.uid]=e,e}static registerNamedCtx(t,e){let s=c.globalStore[t];return s?console.warn('State: context name "'+t+'" already in use'):(s=new c({name:t,schema:e}),c.globalStore[t]=s),s}static clearNamedCtx(t){delete c.globalStore[t]}static getNamedCtx(t,e=!0){return c.globalStore[t]||(e&&console.warn('State: wrong context name - "'+t+'"'),null)}};c.globalStore=Object.create(null);var o=Object.freeze({BIND_ATTR:"set",ATTR_BIND_PRFX:"@",EXT_DATA_CTX_PRFX:"*",NAMED_DATA_CTX_SPLTR:"/",CTX_NAME_ATTR:"ctx-name",CSS_CTX_PROP:"--ctx-name",EL_REF_ATTR:"ref",AUTO_TAG_PRFX:"sym",REPEAT_ATTR:"repeat",REPEAT_ITEM_TAG_ATTR:"repeat-item-tag",SET_LATER_KEY:"__toSetLater__"});var y="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",$=y.length-1,g=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:y.charAt(Math.random()*$);return e}};function E(l,t,e){let s=!0,i,r=t.split(".");return r.forEach((n,h)=>{h<r.length-1?l=l[n]:i=n}),l?l[i]=e:s=!1,s}function R(l,t){[...l.querySelectorAll(`[${o.REPEAT_ATTR}]`)].forEach(e=>{let s=e.getAttribute(o.REPEAT_ITEM_TAG_ATTR),i;if(s&&(i=window.customElements.get(s)),!i){i=class extends t.BaseComponent{constructor(){super();s||(this.style.display="contents")}};let n=e.innerHTML;i.template=n,i.reg(s)}for(;e.firstChild;)e.firstChild.remove();let r=e.getAttribute(o.REPEAT_ATTR);t.sub(r,n=>{if(!n){for(;e.firstChild;)e.firstChild.remove();return}let h=[...e.children],f,p=u=>{u.forEach((a,b)=>{if(h[b])if(h[b].set$)h[b].set$(a);else for(let C in a)h[b][C]=a[C];else{f||(f=new DocumentFragment);let C=new i;Object.assign(C.init$,a),f.appendChild(C)}}),f&&e.appendChild(f);let d=h.slice(u.length,h.length);for(let a of d)a.remove()};if(n.constructor===Array)p(n);else if(n.constructor===Object){let u=[];for(let d in n){let a=n[d];Object.defineProperty(a,"_KEY_",{value:d,enumerable:!0}),u.push(a)}p(u)}else console.warn("Symbiote repeat data type error:"),console.log(n)}),e.removeAttribute(o.REPEAT_ATTR),e.removeAttribute(o.REPEAT_ITEM_TAG_ATTR)})}function I(l,t){if(t.shadowRoot)return;let e=[...l.querySelectorAll("slot")];if(t.initChildren.length&&e.length){let s={};e.forEach(i=>{let r=i.getAttribute("name");r?s[r]={slot:i,fr:document.createDocumentFragment()}:s.__default__={slot:i,fr:document.createDocumentFragment()}}),t.initChildren.forEach(i=>{var n;let r=(n=i.getAttribute)==null?void 0:n.call(i,"slot");r?(i.removeAttribute("slot"),s[r].fr.appendChild(i)):s.__default__&&s.__default__.fr.appendChild(i)}),Object.values(s).forEach(i=>{i.slot.parentNode.insertBefore(i.fr,i.slot),i.slot.remove()})}}function k(l,t){[...l.querySelectorAll(`[${o.EL_REF_ATTR}]`)].forEach(e=>{let s=e.getAttribute(o.EL_REF_ATTR);t.ref[s]=e,e.removeAttribute(o.EL_REF_ATTR)})}function L(l,t){[...l.querySelectorAll(`[${o.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(o.BIND_ATTR).split(";").forEach(r=>{if(!r)return;let n=r.split(":").map(u=>u.trim()),h=n[0],f;h.indexOf(o.ATTR_BIND_PRFX)===0&&(f=!0,h=h.replace(o.ATTR_BIND_PRFX,""));let p=n[1].split(",").map(u=>u.trim());for(let u of p){let d;u.startsWith("!!")?(d="double",u=u.replace("!!","")):u.startsWith("!")&&(d="single",u=u.replace("!","")),t.sub(u,a=>{d==="double"?a=!!a:d==="single"&&(a=!a),f?(a==null?void 0:a.constructor)===Boolean?a?e.setAttribute(h,""):e.removeAttribute(h):e.setAttribute(h,a):E(e,h,a)||(e[o.SET_LATER_KEY]||(e[o.SET_LATER_KEY]=Object.create(null)),e[o.SET_LATER_KEY][h]=a)})}}),e.removeAttribute(o.BIND_ATTR)})}var P="{{",A="}}",M="skip-text";function F(l){let t,e=[],s=document.createTreeWalker(l,NodeFilter.SHOW_TEXT,{acceptNode:i=>{var r;return!((r=i.parentElement)==null?void 0:r.hasAttribute(M))&&i.textContent.includes(P)&&i.textContent.includes(A)&&1}});for(;t=s.nextNode();)e.push(t);return e}var j=function(l,t){F(l).forEach(s=>{let i=[],r;for(;s.textContent.includes(A);)s.textContent.startsWith(P)?(r=s.textContent.indexOf(A)+A.length,s.splitText(r),i.push(s)):(r=s.textContent.indexOf(P),s.splitText(r)),s=s.nextSibling;i.forEach(n=>{let h=n.textContent.replace(P,"").replace(A,"");t.sub(h,f=>{n.textContent=f})})})},x=[R,I,k,L,j];var w=0,m=null,_=null,T=class extends HTMLElement{constructor(){super();S(this,"updateCssData",()=>{var t;this.dropCssDataCache(),(t=this.__boundCssProps)==null||t.forEach(e=>{let s=this.getCssData(this.__extractCssName(e),!0);this.$[e]!==s&&(this.$[e]=s)})});this.init$=Object.create(null),this.cssInit$=Object.create(null),this.tplProcessors=new Set,this.ref=Object.create(null),this.allSubs=new Set,this.pauseRender=!1,this.renderShadow=!1,this.readyToDestroy=!0,this.processInnerHtml=!1}get BaseComponent(){return T}initCallback(){}__initCallback(){var t;this.__initialized||(this.__initialized=!0,(t=this.initCallback)==null||t.call(this))}render(t,e=this.renderShadow){let s;if((e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"}),this.processInnerHtml)for(let r of this.tplProcessors)r(this,this);if(t||this.constructor.template){if(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template),(t==null?void 0:t.constructor)===DocumentFragment)s=t;else if((t==null?void 0:t.constructor)===String){let r=document.createElement("template");r.innerHTML=t,s=r.content.cloneNode(!0)}else this.constructor.__tpl&&(s=this.constructor.__tpl.content.cloneNode(!0));for(let r of this.tplProcessors)r(s,this)}let i=()=>{s&&(e&&this.shadowRoot.appendChild(s)||this.appendChild(s)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){e=!0;let r=document.createElement("link");r.rel="stylesheet",r.href=this.constructor.__shadowStylesUrl,r.onload=i,this.shadowRoot.prepend(r)}else i()}addTemplateProcessor(t){this.tplProcessors.add(t)}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=g.generate(),this.style.setProperty(o.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(o.CSS_CTX_PROP,!0)}get ctxName(){var t;return((t=this.getAttribute(o.CTX_NAME_ATTR))==null?void 0:t.trim())||this.cssCtxName||this.autoCtxName}get localCtx(){return this.__localCtx||(this.__localCtx=c.registerLocalCtx({})),this.__localCtx}get nodeCtx(){return c.getNamedCtx(this.ctxName,!1)||c.registerNamedCtx(this.ctxName,{})}static __parseProp(t,e){let s,i;if(t.startsWith(o.EXT_DATA_CTX_PRFX))s=e.nodeCtx,i=t.replace(o.EXT_DATA_CTX_PRFX,"");else if(t.includes(o.NAMED_DATA_CTX_SPLTR)){let r=t.split(o.NAMED_DATA_CTX_SPLTR);s=c.getNamedCtx(r[0]),i=r[1]}else s=e.localCtx,i=t;return{ctx:s,name:i}}sub(t,e){let s=T.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=T.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=T.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=T.__parseProp(t,this);s.ctx.add(s.name,e,!1)}add$(t){for(let e in t)this.add(e,t[e])}get $(){if(!this.__stateProxy){let t=Object.create(null);this.__stateProxy=new Proxy(t,{set:(e,s,i)=>{let r=T.__parseProp(s,this);return r.ctx.pub(r.name,i),!0},get:(e,s)=>{let i=T.__parseProp(s,this);return i.ctx.read(i.name)}})}return this.__stateProxy}set$(t,e=!1){for(let s in t){let i=t[s];e||![String,Number,Boolean].includes(i==null?void 0:i.constructor)?this.$[s]=i:this.$[s]!==i&&(this.$[s]=i)}}__initDataCtx(){let t=this.constructor.__attrDesc;if(t)for(let e of Object.values(t))Object.keys(this.init$).includes(e)||(this.init$[e]="");for(let e in this.init$)if(e.startsWith(o.EXT_DATA_CTX_PRFX))this.nodeCtx.add(e.replace(o.EXT_DATA_CTX_PRFX,""),this.init$[e]);else if(e.includes(o.NAMED_DATA_CTX_SPLTR)){let s=e.split(o.NAMED_DATA_CTX_SPLTR),i=s[0].trim(),r=s[1].trim();if(i&&r){let n=c.getNamedCtx(i,!1);n||(n=c.registerNamedCtx(i,{})),n.add(r,this.init$[e])}}else this.localCtx.add(e,this.init$[e]);for(let e in this.cssInit$)this.bindCssData(e,this.cssInit$[e]);this.__dataCtxInitialized=!0}connectedCallback(){var t;if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let e=(t=this.getAttribute(o.CTX_NAME_ATTR))==null?void 0:t.trim();if(e&&this.style.setProperty(o.CSS_CTX_PROP,`'${e}'`),this.__initDataCtx(),this[o.SET_LATER_KEY]){for(let s in this[o.SET_LATER_KEY])E(this,s,this[o.SET_LATER_KEY][s]);delete this[o.SET_LATER_KEY]}this.initChildren=[...this.childNodes];for(let s of x)this.addTemplateProcessor(s);this.pauseRender?this.__initCallback():this.render()}this.connectedOnce=!0}destroyCallback(){}disconnectedCallback(){this.dropCssDataCache(),!!this.readyToDestroy&&(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),this.__disconnectTimeout=window.setTimeout(()=>{this.destroyCallback();for(let t of this.allSubs)t.remove(),this.allSubs.delete(t);for(let t of this.tplProcessors)this.tplProcessors.delete(t);_==null||_.delete(this.updateCssData),(_==null?void 0:_.size)||(m==null||m.disconnect(),m=null,_=null)},100))}static reg(t,e=!1){if(t||(w++,t=`${o.AUTO_TAG_PRFX}-${w}`),this.__tag=t,window.customElements.get(t)){console.warn(`${t} - is already in "customElements" registry`);return}window.customElements.define(t,e?class extends this{}:this)}static get is(){return this.__tag||this.reg(),this.__tag}static bindAttributes(t){this.observedAttributes=Object.keys(t),this.__attrDesc=t}attributeChangedCallback(t,e,s){if(e===s)return;let i=this.constructor.__attrDesc[t];i?this.__dataCtxInitialized?this.$[i]=s:this.init$[i]=s:this[t]=s}getCssData(t,e=!1){if(this.__cssDataCache||(this.__cssDataCache=Object.create(null)),!Object.keys(this.__cssDataCache).includes(t)){this.__computedStyle||(this.__computedStyle=window.getComputedStyle(this));let s=this.__computedStyle.getPropertyValue(t).trim();s.startsWith("'")&&s.endsWith("'")&&(s=s.replace(/\'/g,'"'));try{this.__cssDataCache[t]=JSON.parse(s)}catch{!e&&console.warn(`CSS Data error: ${t}`),this.__cssDataCache[t]=null}}return this.__cssDataCache[t]}__extractCssName(t){return t.split("--").map((e,s)=>s===0?"":e).join("--")}__initStyleAttrObserver(){_||(_=new Set),_.add(this.updateCssData),m||(m=new MutationObserver(t=>{t[0].type==="attributes"&&_.forEach(e=>{e()})}),m.observe(document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style"]}))}bindCssData(t,e=""){this.__boundCssProps||(this.__boundCssProps=new Set),this.__boundCssProps.add(t);let s=this.getCssData(this.__extractCssName(t),!0);s===null&&(s=e),this.add(t,s),this.__initStyleAttrObserver()}dropCssDataCache(){this.__cssDataCache=null,this.__computedStyle=null}defineAccessor(t,e,s){let i="__"+t;this[i]=this[t],Object.defineProperty(this,t,{set:r=>{this[i]=r,s?window.setTimeout(()=>{e==null||e(r)}):e==null||e(r)},get:()=>this[i]}),this[t]=this[i]}static set shadowStyles(t){let e=new Blob([t],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(e)}},D=T;S(D,"template");export{D as BaseComponent};
@@ -201,6 +201,7 @@ export namespace AppRouter {
201
201
  export class UID {
202
202
  static generate(pattern?: string): string;
203
203
  }
204
+ export function setNestedProp(parent: any, path: string, value: any): boolean;
204
205
  export class IDB {
205
206
  static get readyEventName(): string;
206
207
  static open(dbName?: string, storeName?: string): DbInstance;
package/build/symbiote.js CHANGED
@@ -45,6 +45,9 @@ var Data = class {
45
45
  }
46
46
  add(prop, val, rewrite = false) {
47
47
  if (!rewrite && Object.keys(this.store).includes(prop)) {
48
+ if (val !== this.store[prop]) {
49
+ this.notify(prop);
50
+ }
48
51
  return;
49
52
  }
50
53
  this.store[prop] = val;
@@ -55,7 +58,8 @@ var Data = class {
55
58
  Data.warn("publish", prop);
56
59
  return;
57
60
  }
58
- this.add(prop, val);
61
+ this.store[prop] = val;
62
+ this.notify(prop);
59
63
  }
60
64
  multiPub(updObj) {
61
65
  for (let prop in updObj) {
@@ -134,7 +138,8 @@ var DICT = Object.freeze({
134
138
  EL_REF_ATTR: "ref",
135
139
  AUTO_TAG_PRFX: "sym",
136
140
  REPEAT_ATTR: "repeat",
137
- REPEAT_ITEM_TAG_ATTR: "repeat-item-tag"
141
+ REPEAT_ITEM_TAG_ATTR: "repeat-item-tag",
142
+ SET_LATER_KEY: "__toSetLater__"
138
143
  });
139
144
 
140
145
  // utils/UID.js
@@ -150,6 +155,26 @@ var UID = class {
150
155
  }
151
156
  };
152
157
 
158
+ // utils/setNestedProp.js
159
+ function setNestedProp(parent, path, value) {
160
+ let success = true;
161
+ let lastStep;
162
+ let propPath = path.split(".");
163
+ propPath.forEach((step, idx) => {
164
+ if (idx < propPath.length - 1) {
165
+ parent = parent[step];
166
+ } else {
167
+ lastStep = step;
168
+ }
169
+ });
170
+ if (parent) {
171
+ parent[lastStep] = value;
172
+ } else {
173
+ success = false;
174
+ }
175
+ return success;
176
+ }
177
+
153
178
  // core/repeatProcessor.js
154
179
  function repeatProcessor(fr, fnCtx) {
155
180
  [...fr.querySelectorAll(`[${DICT.REPEAT_ATTR}]`)].forEach((el) => {
@@ -295,22 +320,6 @@ function domSetProcessor(fr, fnCtx) {
295
320
  let valKeysArr = kv[1].split(",").map((valKey) => {
296
321
  return valKey.trim();
297
322
  });
298
- let isDeep, parent, lastStep, dive;
299
- if (prop.includes(".")) {
300
- isDeep = true;
301
- let propPath = prop.split(".");
302
- dive = () => {
303
- parent = el;
304
- propPath.forEach((step, idx) => {
305
- if (idx < propPath.length - 1) {
306
- parent = parent[step];
307
- } else {
308
- lastStep = step;
309
- }
310
- });
311
- };
312
- dive();
313
- }
314
323
  for (let valKey of valKeysArr) {
315
324
  let castType;
316
325
  if (valKey.startsWith("!!")) {
@@ -332,17 +341,13 @@ function domSetProcessor(fr, fnCtx) {
332
341
  } else {
333
342
  el.setAttribute(prop, val);
334
343
  }
335
- } else if (isDeep) {
336
- if (parent) {
337
- parent[lastStep] = val;
338
- } else {
339
- window.setTimeout(() => {
340
- dive();
341
- parent[lastStep] = val;
342
- });
343
- }
344
344
  } else {
345
- el[prop] = val;
345
+ if (!setNestedProp(el, prop, val)) {
346
+ if (!el[DICT.SET_LATER_KEY]) {
347
+ el[DICT.SET_LATER_KEY] = Object.create(null);
348
+ }
349
+ el[DICT.SET_LATER_KEY][prop] = val;
350
+ }
346
351
  }
347
352
  });
348
353
  }
@@ -613,6 +618,12 @@ var _BaseComponent = class extends HTMLElement {
613
618
  this.style.setProperty(DICT.CSS_CTX_PROP, `'${ctxNameAttrVal}'`);
614
619
  }
615
620
  this.__initDataCtx();
621
+ if (this[DICT.SET_LATER_KEY]) {
622
+ for (let prop in this[DICT.SET_LATER_KEY]) {
623
+ setNestedProp(this, prop, this[DICT.SET_LATER_KEY][prop]);
624
+ }
625
+ delete this[DICT.SET_LATER_KEY];
626
+ }
616
627
  this.initChildren = [...this.childNodes];
617
628
  for (let proc of tpl_processors_default) {
618
629
  this.addTemplateProcessor(proc);
@@ -1294,5 +1305,6 @@ export {
1294
1305
  UID,
1295
1306
  applyAttributes,
1296
1307
  applyStyles,
1297
- create
1308
+ create,
1309
+ setNestedProp
1298
1310
  };
@@ -1 +1 @@
1
- var B=Object.defineProperty;var U=(o,t,e)=>t in o?B(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var E=(o,t,e)=>(U(o,typeof t!="symbol"?t+"":t,e),e);function H(o){let t=e=>{var s;for(let i in e)((s=e[i])==null?void 0:s.constructor)===Object&&(e[i]=t(e[i]));return{...e}};return t(o)}var h=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=H(t.schema):(this._storeIsProxy=!0,this.store=t.schema),this.callbackMap=Object.create(null)}static warn(t,e){console.warn(`Symbiote Data: cannot ${t}. Prop name: `+e)}read(t){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(h.warn("read",t),null):this.store[t]}has(t){return this._storeIsProxy?this.store[t]!==void 0:this.store.hasOwnProperty(t)}add(t,e,s=!1){!s&&Object.keys(this.store).includes(t)||(this.store[t]=e,this.notify(t))}pub(t,e){if(!this._storeIsProxy&&!this.store.hasOwnProperty(t)){h.warn("publish",t);return}this.add(t,e)}multiPub(t){for(let e in t)this.pub(e,t[e])}notify(t){this.callbackMap[t]&&this.callbackMap[t].forEach(e=>{e(this.store[t])})}sub(t,e,s=!0){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(h.warn("subscribe",t),null):(this.callbackMap[t]||(this.callbackMap[t]=new Set),this.callbackMap[t].add(e),s&&e(this.store[t]),{remove:()=>{this.callbackMap[t].delete(e),this.callbackMap[t].size||delete this.callbackMap[t]},callback:e})}remove(){delete h.globalStore[this.uid]}static registerLocalCtx(t){let e=new h({schema:t});return h.globalStore[e.uid]=e,e}static registerNamedCtx(t,e){let s=h.globalStore[t];return s?console.warn('State: context name "'+t+'" already in use'):(s=new h({name:t,schema:e}),h.globalStore[t]=s),s}static clearNamedCtx(t){delete h.globalStore[t]}static getNamedCtx(t,e=!0){return h.globalStore[t]||(e&&console.warn('State: wrong context name - "'+t+'"'),null)}};h.globalStore=Object.create(null);var n=Object.freeze({BIND_ATTR:"set",ATTR_BIND_PRFX:"@",EXT_DATA_CTX_PRFX:"*",NAMED_DATA_CTX_SPLTR:"/",CTX_NAME_ATTR:"ctx-name",CSS_CTX_PROP:"--ctx-name",EL_REF_ATTR:"ref",AUTO_TAG_PRFX:"sym",REPEAT_ATTR:"repeat",REPEAT_ITEM_TAG_ATTR:"repeat-item-tag"});var N="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",W=N.length-1,C=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:N.charAt(Math.random()*W);return e}};function v(o,t){[...o.querySelectorAll(`[${n.REPEAT_ATTR}]`)].forEach(e=>{let s=e.getAttribute(n.REPEAT_ITEM_TAG_ATTR),i;if(s&&(i=window.customElements.get(s)),!i){i=class extends t.BaseComponent{constructor(){super();s||(this.style.display="contents")}};let a=e.innerHTML;i.template=a,i.reg(s)}for(;e.firstChild;)e.firstChild.remove();let r=e.getAttribute(n.REPEAT_ATTR);t.sub(r,a=>{if(!a){for(;e.firstChild;)e.firstChild.remove();return}let l=[...e.children],d,b=T=>{T.forEach((_,y)=>{if(l[y])if(l[y].set$)l[y].set$(_);else for(let u in _)l[y][u]=_[u];else{d||(d=new DocumentFragment);let u=new i;Object.assign(u.init$,_),d.appendChild(u)}}),d&&e.appendChild(d);let f=l.slice(T.length,l.length);for(let _ of f)_.remove()};if(a.constructor===Array)b(a);else if(a.constructor===Object){let T=[];for(let f in a){let _=a[f];Object.defineProperty(_,"_KEY_",{value:f,enumerable:!0}),T.push(_)}b(T)}else console.warn("Symbiote repeat data type error:"),console.log(a)}),e.removeAttribute(n.REPEAT_ATTR),e.removeAttribute(n.REPEAT_ITEM_TAG_ATTR)})}function V(o,t){if(t.shadowRoot)return;let e=[...o.querySelectorAll("slot")];if(t.initChildren.length&&e.length){let s={};e.forEach(i=>{let r=i.getAttribute("name");r?s[r]={slot:i,fr:document.createDocumentFragment()}:s.__default__={slot:i,fr:document.createDocumentFragment()}}),t.initChildren.forEach(i=>{var a;let r=(a=i.getAttribute)==null?void 0:a.call(i,"slot");r?(i.removeAttribute("slot"),s[r].fr.appendChild(i)):s.__default__&&s.__default__.fr.appendChild(i)}),Object.values(s).forEach(i=>{i.slot.parentNode.insertBefore(i.fr,i.slot),i.slot.remove()})}}function q(o,t){[...o.querySelectorAll(`[${n.EL_REF_ATTR}]`)].forEach(e=>{let s=e.getAttribute(n.EL_REF_ATTR);t.ref[s]=e,e.removeAttribute(n.EL_REF_ATTR)})}function z(o,t){[...o.querySelectorAll(`[${n.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(n.BIND_ATTR).split(";").forEach(r=>{if(!r)return;let a=r.split(":").map(u=>u.trim()),l=a[0],d;l.indexOf(n.ATTR_BIND_PRFX)===0&&(d=!0,l=l.replace(n.ATTR_BIND_PRFX,""));let b=a[1].split(",").map(u=>u.trim()),T,f,_,y;if(l.includes(".")){T=!0;let u=l.split(".");y=()=>{f=e,u.forEach((w,c)=>{c<u.length-1?f=f[w]:_=w})},y()}for(let u of b){let w;u.startsWith("!!")?(w="double",u=u.replace("!!","")):u.startsWith("!")&&(w="single",u=u.replace("!","")),t.sub(u,c=>{w==="double"?c=!!c:w==="single"&&(c=!c),d?(c==null?void 0:c.constructor)===Boolean?c?e.setAttribute(l,""):e.removeAttribute(l):e.setAttribute(l,c):T?f?f[_]=c:window.setTimeout(()=>{y(),f[_]=c}):e[l]=c})}}),e.removeAttribute(n.BIND_ATTR)})}var S="{{",x="}}",G="skip-text";function K(o){let t,e=[],s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,{acceptNode:i=>{var r;return!((r=i.parentElement)==null?void 0:r.hasAttribute(G))&&i.textContent.includes(S)&&i.textContent.includes(x)&&1}});for(;t=s.nextNode();)e.push(t);return e}var Y=function(o,t){K(o).forEach(s=>{let i=[],r;for(;s.textContent.includes(x);)s.textContent.startsWith(S)?(r=s.textContent.indexOf(x)+x.length,s.splitText(r),i.push(s)):(r=s.textContent.indexOf(S),s.splitText(r)),s=s.nextSibling;i.forEach(a=>{let l=a.textContent.replace(S,"").replace(x,"");t.sub(l,d=>{a.textContent=d})})})},O=[v,V,q,z,Y];var M=0,g=null,p=null,m=class extends HTMLElement{constructor(){super();E(this,"updateCssData",()=>{var t;this.dropCssDataCache(),(t=this.__boundCssProps)==null||t.forEach(e=>{let s=this.getCssData(this.__extractCssName(e),!0);this.$[e]!==s&&(this.$[e]=s)})});this.init$=Object.create(null),this.cssInit$=Object.create(null),this.tplProcessors=new Set,this.ref=Object.create(null),this.allSubs=new Set,this.pauseRender=!1,this.renderShadow=!1,this.readyToDestroy=!0,this.processInnerHtml=!1}get BaseComponent(){return m}initCallback(){}__initCallback(){var t;this.__initialized||(this.__initialized=!0,(t=this.initCallback)==null||t.call(this))}render(t,e=this.renderShadow){let s;if((e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"}),this.processInnerHtml)for(let r of this.tplProcessors)r(this,this);if(t||this.constructor.template){if(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template),(t==null?void 0:t.constructor)===DocumentFragment)s=t;else if((t==null?void 0:t.constructor)===String){let r=document.createElement("template");r.innerHTML=t,s=r.content.cloneNode(!0)}else this.constructor.__tpl&&(s=this.constructor.__tpl.content.cloneNode(!0));for(let r of this.tplProcessors)r(s,this)}let i=()=>{s&&(e&&this.shadowRoot.appendChild(s)||this.appendChild(s)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){e=!0;let r=document.createElement("link");r.rel="stylesheet",r.href=this.constructor.__shadowStylesUrl,r.onload=i,this.shadowRoot.prepend(r)}else i()}addTemplateProcessor(t){this.tplProcessors.add(t)}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=C.generate(),this.style.setProperty(n.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(n.CSS_CTX_PROP,!0)}get ctxName(){var t;return((t=this.getAttribute(n.CTX_NAME_ATTR))==null?void 0:t.trim())||this.cssCtxName||this.autoCtxName}get localCtx(){return this.__localCtx||(this.__localCtx=h.registerLocalCtx({})),this.__localCtx}get nodeCtx(){return h.getNamedCtx(this.ctxName,!1)||h.registerNamedCtx(this.ctxName,{})}static __parseProp(t,e){let s,i;if(t.startsWith(n.EXT_DATA_CTX_PRFX))s=e.nodeCtx,i=t.replace(n.EXT_DATA_CTX_PRFX,"");else if(t.includes(n.NAMED_DATA_CTX_SPLTR)){let r=t.split(n.NAMED_DATA_CTX_SPLTR);s=h.getNamedCtx(r[0]),i=r[1]}else s=e.localCtx,i=t;return{ctx:s,name:i}}sub(t,e){let s=m.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=m.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=m.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=m.__parseProp(t,this);s.ctx.add(s.name,e,!1)}add$(t){for(let e in t)this.add(e,t[e])}get $(){if(!this.__stateProxy){let t=Object.create(null);this.__stateProxy=new Proxy(t,{set:(e,s,i)=>{let r=m.__parseProp(s,this);return r.ctx.pub(r.name,i),!0},get:(e,s)=>{let i=m.__parseProp(s,this);return i.ctx.read(i.name)}})}return this.__stateProxy}set$(t,e=!1){for(let s in t){let i=t[s];e||![String,Number,Boolean].includes(i==null?void 0:i.constructor)?this.$[s]=i:this.$[s]!==i&&(this.$[s]=i)}}__initDataCtx(){let t=this.constructor.__attrDesc;if(t)for(let e of Object.values(t))Object.keys(this.init$).includes(e)||(this.init$[e]="");for(let e in this.init$)if(e.startsWith(n.EXT_DATA_CTX_PRFX))this.nodeCtx.add(e.replace(n.EXT_DATA_CTX_PRFX,""),this.init$[e]);else if(e.includes(n.NAMED_DATA_CTX_SPLTR)){let s=e.split(n.NAMED_DATA_CTX_SPLTR),i=s[0].trim(),r=s[1].trim();if(i&&r){let a=h.getNamedCtx(i,!1);a||(a=h.registerNamedCtx(i,{})),a.add(r,this.init$[e])}}else this.localCtx.add(e,this.init$[e]);for(let e in this.cssInit$)this.bindCssData(e,this.cssInit$[e]);this.__dataCtxInitialized=!0}connectedCallback(){var t;if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let e=(t=this.getAttribute(n.CTX_NAME_ATTR))==null?void 0:t.trim();e&&this.style.setProperty(n.CSS_CTX_PROP,`'${e}'`),this.__initDataCtx(),this.initChildren=[...this.childNodes];for(let s of O)this.addTemplateProcessor(s);this.pauseRender?this.__initCallback():this.render()}this.connectedOnce=!0}destroyCallback(){}disconnectedCallback(){this.dropCssDataCache(),!!this.readyToDestroy&&(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),this.__disconnectTimeout=window.setTimeout(()=>{this.destroyCallback();for(let t of this.allSubs)t.remove(),this.allSubs.delete(t);for(let t of this.tplProcessors)this.tplProcessors.delete(t);p==null||p.delete(this.updateCssData),(p==null?void 0:p.size)||(g==null||g.disconnect(),g=null,p=null)},100))}static reg(t,e=!1){if(t||(M++,t=`${n.AUTO_TAG_PRFX}-${M}`),this.__tag=t,window.customElements.get(t)){console.warn(`${t} - is already in "customElements" registry`);return}window.customElements.define(t,e?class extends this{}:this)}static get is(){return this.__tag||this.reg(),this.__tag}static bindAttributes(t){this.observedAttributes=Object.keys(t),this.__attrDesc=t}attributeChangedCallback(t,e,s){if(e===s)return;let i=this.constructor.__attrDesc[t];i?this.__dataCtxInitialized?this.$[i]=s:this.init$[i]=s:this[t]=s}getCssData(t,e=!1){if(this.__cssDataCache||(this.__cssDataCache=Object.create(null)),!Object.keys(this.__cssDataCache).includes(t)){this.__computedStyle||(this.__computedStyle=window.getComputedStyle(this));let s=this.__computedStyle.getPropertyValue(t).trim();s.startsWith("'")&&s.endsWith("'")&&(s=s.replace(/\'/g,'"'));try{this.__cssDataCache[t]=JSON.parse(s)}catch{!e&&console.warn(`CSS Data error: ${t}`),this.__cssDataCache[t]=null}}return this.__cssDataCache[t]}__extractCssName(t){return t.split("--").map((e,s)=>s===0?"":e).join("--")}__initStyleAttrObserver(){p||(p=new Set),p.add(this.updateCssData),g||(g=new MutationObserver(t=>{t[0].type==="attributes"&&p.forEach(e=>{e()})}),g.observe(document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style"]}))}bindCssData(t,e=""){this.__boundCssProps||(this.__boundCssProps=new Set),this.__boundCssProps.add(t);let s=this.getCssData(this.__extractCssName(t),!0);s===null&&(s=e),this.add(t,s),this.__initStyleAttrObserver()}dropCssDataCache(){this.__cssDataCache=null,this.__computedStyle=null}defineAccessor(t,e,s){let i="__"+t;this[i]=this[t],Object.defineProperty(this,t,{set:r=>{this[i]=r,s?window.setTimeout(()=>{e==null||e(r)}):e==null||e(r)},get:()=>this[i]}),this[t]=this[i]}static set shadowStyles(t){let e=new Blob([t],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(e)}},D=m;E(D,"template");var X="[Typed State] Wrong property name: ",J="[Typed State] Wrong property type: ",P=class{constructor(t,e){this.__typedSchema=t,this.__ctxId=e||C.generate(),this.__schema=Object.keys(t).reduce((s,i)=>(s[i]=t[i].value,s),{}),this.__data=h.registerNamedCtx(this.__ctxId,this.__schema)}get uid(){return this.__ctxId}setValue(t,e){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(X+t);return}let s=this.__typedSchema[t];if((e==null?void 0:e.constructor)===s.type||s.nullable&&e===null){this.__data.pub(t,e);return}console.warn(J+t)}setMultipleValues(t){for(let e in t)this.setValue(e,t[e])}getValue(t){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(X+t);return}return this.__data.read(t)}subscribe(t,e){return this.__data.sub(t,e)}remove(){this.__data.remove()}};var I=class{constructor(t){this.__typedSchema=t.typedSchema,this.__ctxId=t.ctxName||C.generate(),this.__data=h.registerNamedCtx(this.__ctxId,{}),this.__watchList=t.watchList||[],this.__handler=t.handler||null,this.__subsMap=Object.create(null),this.__observers=new Set,this.__items=new Set;let e=Object.create(null);this.__notifyObservers=(s,i)=>{this.__observeTimeout&&window.clearTimeout(this.__observeTimeout),e[s]||(e[s]=new Set),e[s].add(i),this.__observeTimeout=window.setTimeout(()=>{this.__observers.forEach(r=>{r({...e})}),e=Object.create(null)})}}notify(){this.__notifyTimeout&&window.clearTimeout(this.__notifyTimeout),this.__notifyTimeout=window.setTimeout(()=>{var t;(t=this.__handler)==null||t.call(this,[...this.__items])})}add(t){let e=new P(this.__typedSchema);for(let s in t)e.setValue(s,t[s]);return this.__data.add(e.uid,e),this.__watchList.forEach(s=>{this.__subsMap[e.uid]||(this.__subsMap[e.uid]=[]),this.__subsMap[e.uid].push(e.subscribe(s,()=>{this.__notifyObservers(s,e.uid)}))}),this.__items.add(e.uid),this.notify(),e}read(t){return this.__data.read(t)}readProp(t,e){return this.read(t).getValue(e)}publishProp(t,e,s){this.read(t).setValue(e,s)}remove(t){this.__items.delete(t),this.notify(),this.__data.pub(t,null),delete this.__subsMap[t]}clearAll(){this.__items.forEach(t=>{this.remove(t)})}observe(t){this.__observers.add(t)}unobserve(t){this.__observers.delete(t)}findItems(t){let e=[];return this.__items.forEach(s=>{let i=this.read(s);t(i)&&e.push(s)}),e}items(){return[...this.__items]}get size(){return this.__items.size}destroy(){this.__data.remove(),this.__observers=null;for(let t in this.__subsMap)this.__subsMap[t].forEach(e=>{e.remove()}),delete this.__subsMap[t]}};var A=class{static _print(t){console.warn(t)}static setDefaultTitle(t){this.defaultTitle=t}static setRoutingMap(t){Object.assign(this.appMap,t);for(let e in this.appMap)!this.defaultRoute&&this.appMap[e].default===!0?this.defaultRoute=e:!this.errorRoute&&this.appMap[e].error===!0&&(this.errorRoute=e)}static set routingEventName(t){this.__routingEventName=t}static get routingEventName(){return this.__routingEventName||"sym-on-route"}static readAddressBar(){let t={route:null,options:{}};return window.location.search.split(this.separator).forEach(s=>{if(s.includes("?"))t.route=s.replace("?","");else if(s.includes("=")){let i=s.split("=");t.options[i[0]]=decodeURI(i[1])}else t.options[s]=!0}),t}static notify(){let t=this.readAddressBar(),e=this.appMap[t.route];if(e&&e.title&&(document.title=e.title),t.route===null&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!e&&this.errorRoute){this.applyRoute(this.errorRoute);return}else if(!e&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!e){this._print(`Route "${t.route}" not found...`);return}let s=new CustomEvent(A.routingEventName,{detail:{route:t.route,options:Object.assign(e||{},t.options)}});window.dispatchEvent(s)}static reflect(t,e={}){let s=this.appMap[t];if(!s){this._print("Wrong route: "+t);return}let i="?"+t;for(let a in e)e[a]===!0?i+=this.separator+a:i+=this.separator+a+`=${e[a]}`;let r=s.title||this.defaultTitle||"";window.history.pushState(null,r,i),document.title=r}static applyRoute(t,e={}){this.reflect(t,e),this.notify()}static setSeparator(t){this._separator=t}static get separator(){return this._separator||"&"}static createRouterData(t,e){this.setRoutingMap(e);let s=h.registerNamedCtx(t,{route:null,options:null,title:null});return window.addEventListener(this.routingEventName,i=>{var r;s.multiPub({route:i.detail.route,options:i.detail.options,title:((r=i.detail.options)==null?void 0:r.title)||this.defaultTitle||""})}),A.notify(),s}};A.appMap=Object.create(null);window.onpopstate=()=>{A.notify()};function $(o,t){for(let e in t)e.includes("-")?o.style.setProperty(e,t[e]):o.style[e]=t[e]}function j(o,t){for(let e in t)t[e].constructor===Boolean?t[e]?o.setAttribute(e,""):o.removeAttribute(e):o.setAttribute(e,t[e])}function k(o={tag:"div"}){let t=document.createElement(o.tag);if(o.attributes&&j(t,o.attributes),o.styles&&$(t,o.styles),o.properties)for(let e in o.properties)t[e]=o.properties[e];return o.processors&&o.processors.forEach(e=>{e(t)}),o.children&&o.children.forEach(e=>{let s=k(e);t.appendChild(s)}),t}var L="idb-store-ready",Q="symbiote-db",Z="symbiote-idb-update_",F=class{_notifyWhenReady(t=null){window.dispatchEvent(new CustomEvent(L,{detail:{dbName:this.name,storeName:this.storeName,event:t}}))}get _updEventName(){return Z+this.name}_getUpdateEvent(t){return new CustomEvent(this._updEventName,{detail:{key:this.name,newValue:t}})}_notifySubscribers(t){window.localStorage.removeItem(this.name),window.localStorage.setItem(this.name,t),window.dispatchEvent(this._getUpdateEvent(t))}constructor(t,e){this.name=t,this.storeName=e,this.version=1,this.request=window.indexedDB.open(this.name,this.version),this.request.onupgradeneeded=s=>{this.db=s.target.result,this.objStore=this.db.createObjectStore(e,{keyPath:"_key"}),this.objStore.transaction.oncomplete=i=>{this._notifyWhenReady(i)}},this.request.onsuccess=s=>{this.db=s.target.result,this._notifyWhenReady(s)},this.request.onerror=s=>{console.error(s)},this._subscriptionsMap={},this._updateHandler=s=>{s.key===this.name&&this._subscriptionsMap[s.newValue]&&this._subscriptionsMap[s.newValue].forEach(async r=>{r(await this.read(s.newValue))})},this._localUpdateHandler=s=>{this._updateHandler(s.detail)},window.addEventListener("storage",this._updateHandler),window.addEventListener(this._updEventName,this._localUpdateHandler)}read(t){let s=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).get(t);return new Promise((i,r)=>{s.onsuccess=a=>{var l;((l=a.target.result)==null?void 0:l._value)?i(a.target.result._value):(i(null),console.warn(`IDB: cannot read "${t}"`))},s.onerror=a=>{r(a)}})}write(t,e,s=!1){let i={_key:t,_value:e},a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).put(i);return new Promise((l,d)=>{a.onsuccess=b=>{s||this._notifySubscribers(t),l(b.target.result)},a.onerror=b=>{d(b)}})}delete(t,e=!1){let i=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).delete(t);return new Promise((r,a)=>{i.onsuccess=l=>{e||this._notifySubscribers(t),r(l)},i.onerror=l=>{a(l)}})}getAll(){let e=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).getAll();return new Promise((s,i)=>{e.onsuccess=r=>{let a=r.target.result;s(a.map(l=>l._value))},e.onerror=r=>{i(r)}})}subscribe(t,e){this._subscriptionsMap[t]||(this._subscriptionsMap[t]=new Set);let s=this._subscriptionsMap[t];return s.add(e),{remove:()=>{s.delete(e),s.size||delete this._subscriptionsMap[t]}}}stop(){window.removeEventListener("storage",this._updateHandler),this._subscriptionsMap=null,R.clear(this.name)}},R=class{static get readyEventName(){return L}static open(t=Q,e="store"){let s=t+"/"+e;return this._reg[s]||(this._reg[s]=new F(t,e)),this._reg[s]}static clear(t){window.indexedDB.deleteDatabase(t);for(let e in this._reg)e.split("/")[0]===t&&delete this._reg[e]}};E(R,"_reg",Object.create(null));export{A as AppRouter,D as BaseComponent,h as Data,R as IDB,I as TypedCollection,P as TypedData,C as UID,j as applyAttributes,$ as applyStyles,k as create};
1
+ var F=Object.defineProperty;var B=(o,t,e)=>t in o?F(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var C=(o,t,e)=>(B(o,typeof t!="symbol"?t+"":t,e),e);function U(o){let t=e=>{var s;for(let r in e)((s=e[r])==null?void 0:s.constructor)===Object&&(e[r]=t(e[r]));return{...e}};return t(o)}var h=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=U(t.schema):(this._storeIsProxy=!0,this.store=t.schema),this.callbackMap=Object.create(null)}static warn(t,e){console.warn(`Symbiote Data: cannot ${t}. Prop name: `+e)}read(t){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(h.warn("read",t),null):this.store[t]}has(t){return this._storeIsProxy?this.store[t]!==void 0:this.store.hasOwnProperty(t)}add(t,e,s=!1){if(!s&&Object.keys(this.store).includes(t)){e!==this.store[t]&&this.notify(t);return}this.store[t]=e,this.notify(t)}pub(t,e){if(!this._storeIsProxy&&!this.store.hasOwnProperty(t)){h.warn("publish",t);return}this.store[t]=e,this.notify(t)}multiPub(t){for(let e in t)this.pub(e,t[e])}notify(t){this.callbackMap[t]&&this.callbackMap[t].forEach(e=>{e(this.store[t])})}sub(t,e,s=!0){return!this._storeIsProxy&&!this.store.hasOwnProperty(t)?(h.warn("subscribe",t),null):(this.callbackMap[t]||(this.callbackMap[t]=new Set),this.callbackMap[t].add(e),s&&e(this.store[t]),{remove:()=>{this.callbackMap[t].delete(e),this.callbackMap[t].size||delete this.callbackMap[t]},callback:e})}remove(){delete h.globalStore[this.uid]}static registerLocalCtx(t){let e=new h({schema:t});return h.globalStore[e.uid]=e,e}static registerNamedCtx(t,e){let s=h.globalStore[t];return s?console.warn('State: context name "'+t+'" already in use'):(s=new h({name:t,schema:e}),h.globalStore[t]=s),s}static clearNamedCtx(t){delete h.globalStore[t]}static getNamedCtx(t,e=!0){return h.globalStore[t]||(e&&console.warn('State: wrong context name - "'+t+'"'),null)}};h.globalStore=Object.create(null);var a=Object.freeze({BIND_ATTR:"set",ATTR_BIND_PRFX:"@",EXT_DATA_CTX_PRFX:"*",NAMED_DATA_CTX_SPLTR:"/",CTX_NAME_ATTR:"ctx-name",CSS_CTX_PROP:"--ctx-name",EL_REF_ATTR:"ref",AUTO_TAG_PRFX:"sym",REPEAT_ATTR:"repeat",REPEAT_ITEM_TAG_ATTR:"repeat-item-tag",SET_LATER_KEY:"__toSetLater__"});var D="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",H=D.length-1,b=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:D.charAt(Math.random()*H);return e}};function A(o,t,e){let s=!0,r,i=t.split(".");return i.forEach((n,l)=>{l<i.length-1?o=o[n]:r=n}),o?o[r]=e:s=!1,s}function N(o,t){[...o.querySelectorAll(`[${a.REPEAT_ATTR}]`)].forEach(e=>{let s=e.getAttribute(a.REPEAT_ITEM_TAG_ATTR),r;if(s&&(r=window.customElements.get(s)),!r){r=class extends t.BaseComponent{constructor(){super();s||(this.style.display="contents")}};let n=e.innerHTML;r.template=n,r.reg(s)}for(;e.firstChild;)e.firstChild.remove();let i=e.getAttribute(a.REPEAT_ATTR);t.sub(i,n=>{if(!n){for(;e.firstChild;)e.firstChild.remove();return}let l=[...e.children],_,m=c=>{c.forEach((u,w)=>{if(l[w])if(l[w].set$)l[w].set$(u);else for(let y in u)l[w][y]=u[y];else{_||(_=new DocumentFragment);let y=new r;Object.assign(y.init$,u),_.appendChild(y)}}),_&&e.appendChild(_);let f=l.slice(c.length,l.length);for(let u of f)u.remove()};if(n.constructor===Array)m(n);else if(n.constructor===Object){let c=[];for(let f in n){let u=n[f];Object.defineProperty(u,"_KEY_",{value:f,enumerable:!0}),c.push(u)}m(c)}else console.warn("Symbiote repeat data type error:"),console.log(n)}),e.removeAttribute(a.REPEAT_ATTR),e.removeAttribute(a.REPEAT_ITEM_TAG_ATTR)})}function K(o,t){if(t.shadowRoot)return;let e=[...o.querySelectorAll("slot")];if(t.initChildren.length&&e.length){let s={};e.forEach(r=>{let i=r.getAttribute("name");i?s[i]={slot:r,fr:document.createDocumentFragment()}:s.__default__={slot:r,fr:document.createDocumentFragment()}}),t.initChildren.forEach(r=>{var n;let i=(n=r.getAttribute)==null?void 0:n.call(r,"slot");i?(r.removeAttribute("slot"),s[i].fr.appendChild(r)):s.__default__&&s.__default__.fr.appendChild(r)}),Object.values(s).forEach(r=>{r.slot.parentNode.insertBefore(r.fr,r.slot),r.slot.remove()})}}function W(o,t){[...o.querySelectorAll(`[${a.EL_REF_ATTR}]`)].forEach(e=>{let s=e.getAttribute(a.EL_REF_ATTR);t.ref[s]=e,e.removeAttribute(a.EL_REF_ATTR)})}function V(o,t){[...o.querySelectorAll(`[${a.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(a.BIND_ATTR).split(";").forEach(i=>{if(!i)return;let n=i.split(":").map(c=>c.trim()),l=n[0],_;l.indexOf(a.ATTR_BIND_PRFX)===0&&(_=!0,l=l.replace(a.ATTR_BIND_PRFX,""));let m=n[1].split(",").map(c=>c.trim());for(let c of m){let f;c.startsWith("!!")?(f="double",c=c.replace("!!","")):c.startsWith("!")&&(f="single",c=c.replace("!","")),t.sub(c,u=>{f==="double"?u=!!u:f==="single"&&(u=!u),_?(u==null?void 0:u.constructor)===Boolean?u?e.setAttribute(l,""):e.removeAttribute(l):e.setAttribute(l,u):A(e,l,u)||(e[a.SET_LATER_KEY]||(e[a.SET_LATER_KEY]=Object.create(null)),e[a.SET_LATER_KEY][l]=u)})}}),e.removeAttribute(a.BIND_ATTR)})}var S="{{",g="}}",q="skip-text";function z(o){let t,e=[],s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,{acceptNode:r=>{var i;return!((i=r.parentElement)==null?void 0:i.hasAttribute(q))&&r.textContent.includes(S)&&r.textContent.includes(g)&&1}});for(;t=s.nextNode();)e.push(t);return e}var Y=function(o,t){z(o).forEach(s=>{let r=[],i;for(;s.textContent.includes(g);)s.textContent.startsWith(S)?(i=s.textContent.indexOf(g)+g.length,s.splitText(i),r.push(s)):(i=s.textContent.indexOf(S),s.splitText(i)),s=s.nextSibling;r.forEach(n=>{let l=n.textContent.replace(S,"").replace(g,"");t.sub(l,_=>{n.textContent=_})})})},v=[N,K,W,V,Y];var O=0,T=null,d=null,p=class extends HTMLElement{constructor(){super();C(this,"updateCssData",()=>{var t;this.dropCssDataCache(),(t=this.__boundCssProps)==null||t.forEach(e=>{let s=this.getCssData(this.__extractCssName(e),!0);this.$[e]!==s&&(this.$[e]=s)})});this.init$=Object.create(null),this.cssInit$=Object.create(null),this.tplProcessors=new Set,this.ref=Object.create(null),this.allSubs=new Set,this.pauseRender=!1,this.renderShadow=!1,this.readyToDestroy=!0,this.processInnerHtml=!1}get BaseComponent(){return p}initCallback(){}__initCallback(){var t;this.__initialized||(this.__initialized=!0,(t=this.initCallback)==null||t.call(this))}render(t,e=this.renderShadow){let s;if((e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"}),this.processInnerHtml)for(let i of this.tplProcessors)i(this,this);if(t||this.constructor.template){if(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template),(t==null?void 0:t.constructor)===DocumentFragment)s=t;else if((t==null?void 0:t.constructor)===String){let i=document.createElement("template");i.innerHTML=t,s=i.content.cloneNode(!0)}else this.constructor.__tpl&&(s=this.constructor.__tpl.content.cloneNode(!0));for(let i of this.tplProcessors)i(s,this)}let r=()=>{s&&(e&&this.shadowRoot.appendChild(s)||this.appendChild(s)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){e=!0;let i=document.createElement("link");i.rel="stylesheet",i.href=this.constructor.__shadowStylesUrl,i.onload=r,this.shadowRoot.prepend(i)}else r()}addTemplateProcessor(t){this.tplProcessors.add(t)}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=b.generate(),this.style.setProperty(a.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(a.CSS_CTX_PROP,!0)}get ctxName(){var t;return((t=this.getAttribute(a.CTX_NAME_ATTR))==null?void 0:t.trim())||this.cssCtxName||this.autoCtxName}get localCtx(){return this.__localCtx||(this.__localCtx=h.registerLocalCtx({})),this.__localCtx}get nodeCtx(){return h.getNamedCtx(this.ctxName,!1)||h.registerNamedCtx(this.ctxName,{})}static __parseProp(t,e){let s,r;if(t.startsWith(a.EXT_DATA_CTX_PRFX))s=e.nodeCtx,r=t.replace(a.EXT_DATA_CTX_PRFX,"");else if(t.includes(a.NAMED_DATA_CTX_SPLTR)){let i=t.split(a.NAMED_DATA_CTX_SPLTR);s=h.getNamedCtx(i[0]),r=i[1]}else s=e.localCtx,r=t;return{ctx:s,name:r}}sub(t,e){let s=p.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=p.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=p.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=p.__parseProp(t,this);s.ctx.add(s.name,e,!1)}add$(t){for(let e in t)this.add(e,t[e])}get $(){if(!this.__stateProxy){let t=Object.create(null);this.__stateProxy=new Proxy(t,{set:(e,s,r)=>{let i=p.__parseProp(s,this);return i.ctx.pub(i.name,r),!0},get:(e,s)=>{let r=p.__parseProp(s,this);return r.ctx.read(r.name)}})}return this.__stateProxy}set$(t,e=!1){for(let s in t){let r=t[s];e||![String,Number,Boolean].includes(r==null?void 0:r.constructor)?this.$[s]=r:this.$[s]!==r&&(this.$[s]=r)}}__initDataCtx(){let t=this.constructor.__attrDesc;if(t)for(let e of Object.values(t))Object.keys(this.init$).includes(e)||(this.init$[e]="");for(let e in this.init$)if(e.startsWith(a.EXT_DATA_CTX_PRFX))this.nodeCtx.add(e.replace(a.EXT_DATA_CTX_PRFX,""),this.init$[e]);else if(e.includes(a.NAMED_DATA_CTX_SPLTR)){let s=e.split(a.NAMED_DATA_CTX_SPLTR),r=s[0].trim(),i=s[1].trim();if(r&&i){let n=h.getNamedCtx(r,!1);n||(n=h.registerNamedCtx(r,{})),n.add(i,this.init$[e])}}else this.localCtx.add(e,this.init$[e]);for(let e in this.cssInit$)this.bindCssData(e,this.cssInit$[e]);this.__dataCtxInitialized=!0}connectedCallback(){var t;if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let e=(t=this.getAttribute(a.CTX_NAME_ATTR))==null?void 0:t.trim();if(e&&this.style.setProperty(a.CSS_CTX_PROP,`'${e}'`),this.__initDataCtx(),this[a.SET_LATER_KEY]){for(let s in this[a.SET_LATER_KEY])A(this,s,this[a.SET_LATER_KEY][s]);delete this[a.SET_LATER_KEY]}this.initChildren=[...this.childNodes];for(let s of v)this.addTemplateProcessor(s);this.pauseRender?this.__initCallback():this.render()}this.connectedOnce=!0}destroyCallback(){}disconnectedCallback(){this.dropCssDataCache(),!!this.readyToDestroy&&(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),this.__disconnectTimeout=window.setTimeout(()=>{this.destroyCallback();for(let t of this.allSubs)t.remove(),this.allSubs.delete(t);for(let t of this.tplProcessors)this.tplProcessors.delete(t);d==null||d.delete(this.updateCssData),(d==null?void 0:d.size)||(T==null||T.disconnect(),T=null,d=null)},100))}static reg(t,e=!1){if(t||(O++,t=`${a.AUTO_TAG_PRFX}-${O}`),this.__tag=t,window.customElements.get(t)){console.warn(`${t} - is already in "customElements" registry`);return}window.customElements.define(t,e?class extends this{}:this)}static get is(){return this.__tag||this.reg(),this.__tag}static bindAttributes(t){this.observedAttributes=Object.keys(t),this.__attrDesc=t}attributeChangedCallback(t,e,s){if(e===s)return;let r=this.constructor.__attrDesc[t];r?this.__dataCtxInitialized?this.$[r]=s:this.init$[r]=s:this[t]=s}getCssData(t,e=!1){if(this.__cssDataCache||(this.__cssDataCache=Object.create(null)),!Object.keys(this.__cssDataCache).includes(t)){this.__computedStyle||(this.__computedStyle=window.getComputedStyle(this));let s=this.__computedStyle.getPropertyValue(t).trim();s.startsWith("'")&&s.endsWith("'")&&(s=s.replace(/\'/g,'"'));try{this.__cssDataCache[t]=JSON.parse(s)}catch{!e&&console.warn(`CSS Data error: ${t}`),this.__cssDataCache[t]=null}}return this.__cssDataCache[t]}__extractCssName(t){return t.split("--").map((e,s)=>s===0?"":e).join("--")}__initStyleAttrObserver(){d||(d=new Set),d.add(this.updateCssData),T||(T=new MutationObserver(t=>{t[0].type==="attributes"&&d.forEach(e=>{e()})}),T.observe(document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style"]}))}bindCssData(t,e=""){this.__boundCssProps||(this.__boundCssProps=new Set),this.__boundCssProps.add(t);let s=this.getCssData(this.__extractCssName(t),!0);s===null&&(s=e),this.add(t,s),this.__initStyleAttrObserver()}dropCssDataCache(){this.__cssDataCache=null,this.__computedStyle=null}defineAccessor(t,e,s){let r="__"+t;this[r]=this[t],Object.defineProperty(this,t,{set:i=>{this[r]=i,s?window.setTimeout(()=>{e==null||e(i)}):e==null||e(i)},get:()=>this[r]}),this[t]=this[r]}static set shadowStyles(t){let e=new Blob([t],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(e)}},R=p;C(R,"template");var M="[Typed State] Wrong property name: ",G="[Typed State] Wrong property type: ",x=class{constructor(t,e){this.__typedSchema=t,this.__ctxId=e||b.generate(),this.__schema=Object.keys(t).reduce((s,r)=>(s[r]=t[r].value,s),{}),this.__data=h.registerNamedCtx(this.__ctxId,this.__schema)}get uid(){return this.__ctxId}setValue(t,e){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(M+t);return}let s=this.__typedSchema[t];if((e==null?void 0:e.constructor)===s.type||s.nullable&&e===null){this.__data.pub(t,e);return}console.warn(G+t)}setMultipleValues(t){for(let e in t)this.setValue(e,t[e])}getValue(t){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(M+t);return}return this.__data.read(t)}subscribe(t,e){return this.__data.sub(t,e)}remove(){this.__data.remove()}};var X=class{constructor(t){this.__typedSchema=t.typedSchema,this.__ctxId=t.ctxName||b.generate(),this.__data=h.registerNamedCtx(this.__ctxId,{}),this.__watchList=t.watchList||[],this.__handler=t.handler||null,this.__subsMap=Object.create(null),this.__observers=new Set,this.__items=new Set;let e=Object.create(null);this.__notifyObservers=(s,r)=>{this.__observeTimeout&&window.clearTimeout(this.__observeTimeout),e[s]||(e[s]=new Set),e[s].add(r),this.__observeTimeout=window.setTimeout(()=>{this.__observers.forEach(i=>{i({...e})}),e=Object.create(null)})}}notify(){this.__notifyTimeout&&window.clearTimeout(this.__notifyTimeout),this.__notifyTimeout=window.setTimeout(()=>{var t;(t=this.__handler)==null||t.call(this,[...this.__items])})}add(t){let e=new x(this.__typedSchema);for(let s in t)e.setValue(s,t[s]);return this.__data.add(e.uid,e),this.__watchList.forEach(s=>{this.__subsMap[e.uid]||(this.__subsMap[e.uid]=[]),this.__subsMap[e.uid].push(e.subscribe(s,()=>{this.__notifyObservers(s,e.uid)}))}),this.__items.add(e.uid),this.notify(),e}read(t){return this.__data.read(t)}readProp(t,e){return this.read(t).getValue(e)}publishProp(t,e,s){this.read(t).setValue(e,s)}remove(t){this.__items.delete(t),this.notify(),this.__data.pub(t,null),delete this.__subsMap[t]}clearAll(){this.__items.forEach(t=>{this.remove(t)})}observe(t){this.__observers.add(t)}unobserve(t){this.__observers.delete(t)}findItems(t){let e=[];return this.__items.forEach(s=>{let r=this.read(s);t(r)&&e.push(s)}),e}items(){return[...this.__items]}get size(){return this.__items.size}destroy(){this.__data.remove(),this.__observers=null;for(let t in this.__subsMap)this.__subsMap[t].forEach(e=>{e.remove()}),delete this.__subsMap[t]}};var E=class{static _print(t){console.warn(t)}static setDefaultTitle(t){this.defaultTitle=t}static setRoutingMap(t){Object.assign(this.appMap,t);for(let e in this.appMap)!this.defaultRoute&&this.appMap[e].default===!0?this.defaultRoute=e:!this.errorRoute&&this.appMap[e].error===!0&&(this.errorRoute=e)}static set routingEventName(t){this.__routingEventName=t}static get routingEventName(){return this.__routingEventName||"sym-on-route"}static readAddressBar(){let t={route:null,options:{}};return window.location.search.split(this.separator).forEach(s=>{if(s.includes("?"))t.route=s.replace("?","");else if(s.includes("=")){let r=s.split("=");t.options[r[0]]=decodeURI(r[1])}else t.options[s]=!0}),t}static notify(){let t=this.readAddressBar(),e=this.appMap[t.route];if(e&&e.title&&(document.title=e.title),t.route===null&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!e&&this.errorRoute){this.applyRoute(this.errorRoute);return}else if(!e&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!e){this._print(`Route "${t.route}" not found...`);return}let s=new CustomEvent(E.routingEventName,{detail:{route:t.route,options:Object.assign(e||{},t.options)}});window.dispatchEvent(s)}static reflect(t,e={}){let s=this.appMap[t];if(!s){this._print("Wrong route: "+t);return}let r="?"+t;for(let n in e)e[n]===!0?r+=this.separator+n:r+=this.separator+n+`=${e[n]}`;let i=s.title||this.defaultTitle||"";window.history.pushState(null,i,r),document.title=i}static applyRoute(t,e={}){this.reflect(t,e),this.notify()}static setSeparator(t){this._separator=t}static get separator(){return this._separator||"&"}static createRouterData(t,e){this.setRoutingMap(e);let s=h.registerNamedCtx(t,{route:null,options:null,title:null});return window.addEventListener(this.routingEventName,r=>{var i;s.multiPub({route:r.detail.route,options:r.detail.options,title:((i=r.detail.options)==null?void 0:i.title)||this.defaultTitle||""})}),E.notify(),s}};E.appMap=Object.create(null);window.onpopstate=()=>{E.notify()};function I(o,t){for(let e in t)e.includes("-")?o.style.setProperty(e,t[e]):o.style[e]=t[e]}function L(o,t){for(let e in t)t[e].constructor===Boolean?t[e]?o.setAttribute(e,""):o.removeAttribute(e):o.setAttribute(e,t[e])}function $(o={tag:"div"}){let t=document.createElement(o.tag);if(o.attributes&&L(t,o.attributes),o.styles&&I(t,o.styles),o.properties)for(let e in o.properties)t[e]=o.properties[e];return o.processors&&o.processors.forEach(e=>{e(t)}),o.children&&o.children.forEach(e=>{let s=$(e);t.appendChild(s)}),t}var j="idb-store-ready",J="symbiote-db",Q="symbiote-idb-update_",k=class{_notifyWhenReady(t=null){window.dispatchEvent(new CustomEvent(j,{detail:{dbName:this.name,storeName:this.storeName,event:t}}))}get _updEventName(){return Q+this.name}_getUpdateEvent(t){return new CustomEvent(this._updEventName,{detail:{key:this.name,newValue:t}})}_notifySubscribers(t){window.localStorage.removeItem(this.name),window.localStorage.setItem(this.name,t),window.dispatchEvent(this._getUpdateEvent(t))}constructor(t,e){this.name=t,this.storeName=e,this.version=1,this.request=window.indexedDB.open(this.name,this.version),this.request.onupgradeneeded=s=>{this.db=s.target.result,this.objStore=this.db.createObjectStore(e,{keyPath:"_key"}),this.objStore.transaction.oncomplete=r=>{this._notifyWhenReady(r)}},this.request.onsuccess=s=>{this.db=s.target.result,this._notifyWhenReady(s)},this.request.onerror=s=>{console.error(s)},this._subscriptionsMap={},this._updateHandler=s=>{s.key===this.name&&this._subscriptionsMap[s.newValue]&&this._subscriptionsMap[s.newValue].forEach(async i=>{i(await this.read(s.newValue))})},this._localUpdateHandler=s=>{this._updateHandler(s.detail)},window.addEventListener("storage",this._updateHandler),window.addEventListener(this._updEventName,this._localUpdateHandler)}read(t){let s=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).get(t);return new Promise((r,i)=>{s.onsuccess=n=>{var l;((l=n.target.result)==null?void 0:l._value)?r(n.target.result._value):(r(null),console.warn(`IDB: cannot read "${t}"`))},s.onerror=n=>{i(n)}})}write(t,e,s=!1){let r={_key:t,_value:e},n=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).put(r);return new Promise((l,_)=>{n.onsuccess=m=>{s||this._notifySubscribers(t),l(m.target.result)},n.onerror=m=>{_(m)}})}delete(t,e=!1){let r=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).delete(t);return new Promise((i,n)=>{r.onsuccess=l=>{e||this._notifySubscribers(t),i(l)},r.onerror=l=>{n(l)}})}getAll(){let e=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).getAll();return new Promise((s,r)=>{e.onsuccess=i=>{let n=i.target.result;s(n.map(l=>l._value))},e.onerror=i=>{r(i)}})}subscribe(t,e){this._subscriptionsMap[t]||(this._subscriptionsMap[t]=new Set);let s=this._subscriptionsMap[t];return s.add(e),{remove:()=>{s.delete(e),s.size||delete this._subscriptionsMap[t]}}}stop(){window.removeEventListener("storage",this._updateHandler),this._subscriptionsMap=null,P.clear(this.name)}},P=class{static get readyEventName(){return j}static open(t=J,e="store"){let s=t+"/"+e;return this._reg[s]||(this._reg[s]=new k(t,e)),this._reg[s]}static clear(t){window.indexedDB.deleteDatabase(t);for(let e in this._reg)e.split("/")[0]===t&&delete this._reg[e]}};C(P,"_reg",Object.create(null));export{E as AppRouter,R as BaseComponent,h as Data,P as IDB,X as TypedCollection,x as TypedData,b as UID,L as applyAttributes,I as applyStyles,$ as create,A as setNestedProp};
@@ -1,6 +1,7 @@
1
1
  import { Data } from './Data.js';
2
2
  import { DICT } from './dictionary.js';
3
3
  import { UID } from '../utils/UID.js';
4
+ import { setNestedProp } from '../utils/setNestedProp.js';
4
5
 
5
6
  import PROCESSORS from './tpl-processors.js';
6
7
 
@@ -301,6 +302,12 @@ export class BaseComponent extends HTMLElement {
301
302
  this.style.setProperty(DICT.CSS_CTX_PROP, `'${ctxNameAttrVal}'`);
302
303
  }
303
304
  this.__initDataCtx();
305
+ if (this[DICT.SET_LATER_KEY]) {
306
+ for (let prop in this[DICT.SET_LATER_KEY]) {
307
+ setNestedProp(this, prop, this[DICT.SET_LATER_KEY][prop]);
308
+ }
309
+ delete this[DICT.SET_LATER_KEY];
310
+ }
304
311
  this.initChildren = [...this.childNodes];
305
312
  for (let proc of PROCESSORS) {
306
313
  this.addTemplateProcessor(proc);
package/core/Data.js CHANGED
@@ -61,6 +61,9 @@ export class Data {
61
61
  */
62
62
  add(prop, val, rewrite = false) {
63
63
  if (!rewrite && Object.keys(this.store).includes(prop)) {
64
+ if (val !== this.store[prop]) {
65
+ this.notify(prop);
66
+ }
64
67
  return;
65
68
  }
66
69
  this.store[prop] = val;
@@ -77,7 +80,8 @@ export class Data {
77
80
  Data.warn('publish', prop);
78
81
  return;
79
82
  }
80
- this.add(prop, val);
83
+ this.store[prop] = val;
84
+ this.notify(prop);
81
85
  }
82
86
 
83
87
  /** @param {Object<string, any>} updObj */
@@ -20,4 +20,6 @@ export const DICT = Object.freeze({
20
20
  REPEAT_ATTR: 'repeat',
21
21
  // List item tag name:
22
22
  REPEAT_ITEM_TAG_ATTR: 'repeat-item-tag',
23
+ // Key to restore nested properties was set before component construction
24
+ SET_LATER_KEY: '__toSetLater__',
23
25
  });
package/core/symbiote.js CHANGED
@@ -7,6 +7,7 @@ export { AppRouter } from './AppRouter.js';
7
7
 
8
8
  // Utils:
9
9
  export { UID } from '../utils/UID.js';
10
+ export { setNestedProp } from '../utils/setNestedProp.js';
10
11
  export { applyStyles } from '../utils/dom-helpers.js';
11
12
  export { applyAttributes } from '../utils/dom-helpers.js';
12
13
  export { create } from '../utils/dom-helpers.js';
@@ -1,4 +1,5 @@
1
1
  import { DICT } from './dictionary.js';
2
+ import { setNestedProp } from '../utils/setNestedProp.js';
2
3
  // Should go first among other processors:
3
4
  import { repeatProcessor } from './repeatProcessor.js';
4
5
 
@@ -82,23 +83,6 @@ function domSetProcessor(fr, fnCtx) {
82
83
  let valKeysArr = kv[1].split(',').map((valKey) => {
83
84
  return valKey.trim();
84
85
  });
85
- // Deep property:
86
- let isDeep, parent, lastStep, dive;
87
- if (prop.includes('.')) {
88
- isDeep = true;
89
- let propPath = prop.split('.');
90
- dive = () => {
91
- parent = el;
92
- propPath.forEach((step, idx) => {
93
- if (idx < propPath.length - 1) {
94
- parent = parent[step];
95
- } else {
96
- lastStep = step;
97
- }
98
- });
99
- };
100
- dive();
101
- }
102
86
  for (let valKey of valKeysArr) {
103
87
  /** @type {'single' | 'double'} */
104
88
  let castType;
@@ -121,19 +105,14 @@ function domSetProcessor(fr, fnCtx) {
121
105
  } else {
122
106
  el.setAttribute(prop, val);
123
107
  }
124
- } else if (isDeep) {
125
- if (parent) {
126
- parent[lastStep] = val;
127
- } else {
108
+ } else {
109
+ if (!setNestedProp(el, prop, val)) {
128
110
  // Custom element instances are not constructed properly at this time, so:
129
- window.setTimeout(() => {
130
- dive();
131
- parent[lastStep] = val;
132
- });
133
- // TODO: investigate how to do it better ^^^
111
+ if (!el[DICT.SET_LATER_KEY]) {
112
+ el[DICT.SET_LATER_KEY] = Object.create(null);
113
+ }
114
+ el[DICT.SET_LATER_KEY][prop] = val;
134
115
  }
135
- } else {
136
- el[prop] = val;
137
116
  }
138
117
  });
139
118
  }
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "version": "1.8.3",
28
+ "version": "1.8.6",
29
29
  "description": "Symbiote.js",
30
30
  "author": "hello@symbiotejs.org",
31
31
  "license": "MIT",
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @param {any} parent
3
+ * @param {String} path
4
+ * @param {any} value
5
+ */
6
+ export function setNestedProp(parent, path, value) {
7
+ let success = true;
8
+ /** @type {String} */
9
+ let lastStep;
10
+ let propPath = path.split('.');
11
+ propPath.forEach((step, idx) => {
12
+ if (idx < propPath.length - 1) {
13
+ parent = parent[step];
14
+ } else {
15
+ lastStep = step;
16
+ }
17
+ });
18
+ if (parent) {
19
+ parent[lastStep] = value;
20
+ } else {
21
+ success = false;
22
+ }
23
+ return success;
24
+ }