@symbiotejs/symbiote 1.4.8 → 1.5.2

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/README.md CHANGED
@@ -67,23 +67,9 @@ The easiest way to try Symbiote.js is to create a simple `html` file in your tex
67
67
  **This code can work directly in any modern browser, so you don't need to install anything to try it!**
68
68
 
69
69
  ## 🧜‍♀️ Dive deeper
70
- * [Installation](https://github.com/symbiotejs/docsite/blob/main/md/Installation.md)
71
- * [Templates](https://github.com/symbiotejs/docsite/blob/main/md/Templates.md)
72
- * [Lifecycle](https://github.com/symbiotejs/docsite/blob/main/md/Lifecycle.md)
73
- * [Component data context](https://github.com/symbiotejs/docsite/blob/main/md/Component_data_context.md)
74
- * [Attribute binding](https://github.com/symbiotejs/docsite/blob/main/md/Attribute_binding.md)
75
- * [Styling](https://github.com/symbiotejs/docsite/blob/main/md/Styling.md)
76
- * [Delayed rendering](https://github.com/symbiotejs/docsite/blob/main/md/Delayed_rendering.md)
77
- * [Extending](https://github.com/symbiotejs/docsite/blob/main/md/Extending.md)
78
- * [Naming collisions](https://github.com/symbiotejs/docsite/blob/main/md/Naming_collisions.md)
79
- * Data (pub/sub)
80
- * Routing
81
- * Domain specific data
82
- * DOM helpers
83
- * Indexed DB
84
- * [TypeScript](https://github.com/symbiotejs/docsite/blob/main/md/TypeScript.md)
85
- * Solution history
86
- * Playground
70
+ Check the project documentation for details:
71
+ * [Docs on GitHub](https://github.com/symbiotejs/docsite/tree/main/md)
72
+ * [symbiotejs.org](https://symbiotejs.org/)
87
73
 
88
74
  ## 🤖 Live examples
89
75
  Browser: https://symbiotejs.github.io/examples/
@@ -1 +1 @@
1
- var E=Object.defineProperty;var X=(n,t,e)=>t in n?E(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var P=(n,t,e)=>(X(n,typeof t!="symbol"?t+"":t,e),e);function D(n){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(n)}var l=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=D(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)?(l.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=!0){!s&&Object.keys(this.store).includes(t)||(this.store[t]=e,this.callbackMap[t]&&this.callbackMap[t].forEach(i=>{i(this.store[t])}))}pub(t,e){if(!this._storeIsProxy&&!this.store.hasOwnProperty(t)){l.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)?(l.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 l.globalStore[this.uid]}static registerLocalCtx(t){let e=new l({schema:t});return l.globalStore[e.uid]=e,e}static registerNamedCtx(t,e){let s=l.globalStore[t];return s?console.warn('State: context name "'+t+'" already in use'):(s=new l({name:t,schema:e}),l.globalStore[t]=s),s}static clearNamedCtx(t){delete l.globalStore[t]}static getNamedCtx(t,e=!0){return l.globalStore[t]||(e&&console.warn('State: wrong context name - "'+t+'"'),null)}};l.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"});var p="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",O=p.length-1,A=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:p.charAt(Math.random()*O);return e}};function N(n,t){if(t.renderShadow)return;let e=[...n.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()})}else t.innerHTML=""}function k(n,t){[...n.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 M(n,t){[...n.querySelectorAll(`[${o.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(o.BIND_ATTR).split(";").forEach(r=>{if(!r)return;let a=r.split(":").map(u=>u.trim()),c=a[0],f;c.indexOf(o.ATTR_BIND_PRFX)===0&&(f=!0,c=c.replace(o.ATTR_BIND_PRFX,""));let R=a[1].split(",").map(u=>u.trim()),x,d,m,b;if(c.includes(".")){x=!0;let u=c.split(".");b=()=>{d=e,u.forEach((h,w)=>{w<u.length-1?d=d[h]:m=h})},b()}for(let u of R)t.sub(u,h=>{f?(h==null?void 0:h.constructor)===Boolean?h?e.setAttribute(c,""):e.removeAttribute(c):e.setAttribute(c,h):x?d?d[m]=h:window.setTimeout(()=>{b(),d[m]=h}):e[c]=h})}),e.removeAttribute(o.BIND_ATTR)})}var T="{{",C="}}",$="skip-text";function F(n){let t,e=[],s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode:i=>{var r;return!((r=i.parentElement)==null?void 0:r.hasAttribute($))&&i.textContent.includes(T)&&i.textContent.includes(C)&&1}});for(;t=s.nextNode();)e.push(t);return e}var L=function(n,t){F(n).forEach(s=>{let i=[],r;for(;s.textContent.includes(C);)s.textContent.startsWith(T)?(r=s.textContent.indexOf(C)+2,s.splitText(r),i.push(s)):(r=s.textContent.indexOf(T),s.splitText(r)),s=s.nextSibling;i.forEach(a=>{let c=a.textContent.replace(T,"").replace(C,"");t.sub(c,f=>{a.textContent=f})})})},S=[N,k,M,L];var y=0,_=class extends HTMLElement{initCallback(){}__initCallback(){var t;this.__initialized||(this.__initialized=!0,(t=this.initCallback)==null||t.call(this))}render(t,e=this.renderShadow){let s;if(t||this.constructor.template){for(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template);this.firstChild;)this.firstChild.remove();if((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)}(e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"});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)}constructor(){super();this.init$=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}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=A.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=l.registerLocalCtx({})),this.__localCtx}get nodeCtx(){return l.getNamedCtx(this.ctxName,!1)||l.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=l.getNamedCtx(r[0]),i=r[1]}else s=e.localCtx,i=t;return{ctx:s,name:i}}sub(t,e){let s=_.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=_.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=_.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=_.__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=_.__parseProp(s,this);return r.ctx.pub(r.name,i),!0},get:(e,s)=>{let i=_.__parseProp(s,this);return i.ctx.read(i.name)}})}return this.__stateProxy}set$(t){for(let e in t)this.$[e]=t[e]}__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 a=l.getNamedCtx(i,!1);a||(a=l.registerNamedCtx(i,{})),a.add(r,this.init$[e])}}else this.localCtx.add(e,this.init$[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 S)this.addTemplateProcessor(s);this.pauseRender||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)},100))}static reg(t,e=!1){if(t||(y++,t=`${o.AUTO_TAG_PRFX}-${y}`),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]}bindCssData(t,e=!0){let s=(e?o.EXT_DATA_CTX_PRFX:"")+t;return this.add(s,this.getCssData(t,!0)),s}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)}},g=_;P(g,"template");export{g as BaseComponent};
1
+ var E=Object.defineProperty;var X=(n,t,e)=>t in n?E(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var P=(n,t,e)=>(X(n,typeof t!="symbol"?t+"":t,e),e);function D(n){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(n)}var l=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=D(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)?(l.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=!0){!s&&Object.keys(this.store).includes(t)||(this.store[t]=e,this.callbackMap[t]&&this.callbackMap[t].forEach(i=>{i(this.store[t])}))}pub(t,e){if(!this._storeIsProxy&&!this.store.hasOwnProperty(t)){l.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)?(l.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 l.globalStore[this.uid]}static registerLocalCtx(t){let e=new l({schema:t});return l.globalStore[e.uid]=e,e}static registerNamedCtx(t,e){let s=l.globalStore[t];return s?console.warn('State: context name "'+t+'" already in use'):(s=new l({name:t,schema:e}),l.globalStore[t]=s),s}static clearNamedCtx(t){delete l.globalStore[t]}static getNamedCtx(t,e=!0){return l.globalStore[t]||(e&&console.warn('State: wrong context name - "'+t+'"'),null)}};l.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"});var x="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",O=x.length-1,A=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()*O);return e}};function N(n,t){if(t.renderShadow)return;let e=[...n.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()})}else!t.processInnerHtml&&(t.innerHTML="")}function k(n,t){[...n.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 M(n,t){[...n.querySelectorAll(`[${o.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(o.BIND_ATTR).split(";").forEach(r=>{if(!r)return;let a=r.split(":").map(u=>u.trim()),c=a[0],T;c.indexOf(o.ATTR_BIND_PRFX)===0&&(T=!0,c=c.replace(o.ATTR_BIND_PRFX,""));let R=a[1].split(",").map(u=>u.trim()),p,d,m,b;if(c.includes(".")){p=!0;let u=c.split(".");b=()=>{d=e,u.forEach((h,w)=>{w<u.length-1?d=d[h]:m=h})},b()}for(let u of R)t.sub(u,h=>{T?(h==null?void 0:h.constructor)===Boolean?h?e.setAttribute(c,""):e.removeAttribute(c):e.setAttribute(c,h):p?d?d[m]=h:window.setTimeout(()=>{b(),d[m]=h}):e[c]=h})}),e.removeAttribute(o.BIND_ATTR)})}var C="{{",f="}}",I="skip-text";function $(n){let t,e=[],s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode:i=>{var r;return!((r=i.parentElement)==null?void 0:r.hasAttribute(I))&&i.textContent.includes(C)&&i.textContent.includes(f)&&1}});for(;t=s.nextNode();)e.push(t);return e}var F=function(n,t){$(n).forEach(s=>{let i=[],r;for(;s.textContent.includes(f);)s.textContent.startsWith(C)?(r=s.textContent.indexOf(f)+f.length,s.splitText(r),i.push(s)):(r=s.textContent.indexOf(C),s.splitText(r)),s=s.nextSibling;i.forEach(a=>{let c=a.textContent.replace(C,"").replace(f,"");t.sub(c,T=>{a.textContent=T})})})},S=[N,k,M,F];var y=0,_=class extends HTMLElement{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){for(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template);!this.processInnerHtml&&this.firstChild;)this.firstChild.remove();if((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)}constructor(){super();this.init$=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 autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=A.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=l.registerLocalCtx({})),this.__localCtx}get nodeCtx(){return l.getNamedCtx(this.ctxName,!1)||l.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=l.getNamedCtx(r[0]),i=r[1]}else s=e.localCtx,i=t;return{ctx:s,name:i}}sub(t,e){let s=_.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=_.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=_.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=_.__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=_.__parseProp(s,this);return r.ctx.pub(r.name,i),!0},get:(e,s)=>{let i=_.__parseProp(s,this);return i.ctx.read(i.name)}})}return this.__stateProxy}set$(t){for(let e in t)this.$[e]=t[e]}__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 a=l.getNamedCtx(i,!1);a||(a=l.registerNamedCtx(i,{})),a.add(r,this.init$[e])}}else this.localCtx.add(e,this.init$[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 S)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)},100))}static reg(t,e=!1){if(t||(y++,t=`${o.AUTO_TAG_PRFX}-${y}`),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]}bindCssData(t,e=!0){let s=(e?o.EXT_DATA_CTX_PRFX:"")+t;return this.add(s,this.getCssData(t,!0)),s}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)}},g=_;P(g,"template");export{g as BaseComponent};
@@ -51,11 +51,11 @@ export class BaseComponent extends HTMLElement {
51
51
  private __initCallback;
52
52
  private __initialized;
53
53
  render(template?: string | DocumentFragment, shadow?: boolean): void;
54
- addTemplateProcessor<T extends BaseComponent>(processorFn: (fr: DocumentFragment, fnCtx: T) => void): void;
54
+ addTemplateProcessor<T extends BaseComponent>(processorFn: (fr: DocumentFragment | T, fnCtx: T) => void): void;
55
55
  init$: {
56
56
  [x: string]: unknown;
57
57
  };
58
- tplProcessors: Set<(fr: DocumentFragment, fnCtx: unknown) => void>;
58
+ tplProcessors: Set<(fr: DocumentFragment | BaseComponent, fnCtx: unknown) => void>;
59
59
  ref: {
60
60
  [x: string]: any;
61
61
  };
@@ -63,6 +63,7 @@ export class BaseComponent extends HTMLElement {
63
63
  pauseRender: boolean;
64
64
  renderShadow: boolean;
65
65
  readyToDestroy: boolean;
66
+ processInnerHtml: boolean;
66
67
  get autoCtxName(): string;
67
68
  private __autoCtxName;
68
69
  get cssCtxName(): string;
@@ -105,6 +106,7 @@ export class TypedData {
105
106
  [x: string]: {
106
107
  type: any;
107
108
  value: any;
109
+ nullable?: boolean;
108
110
  };
109
111
  }, ctxName?: string);
110
112
  private __typedSchema;
package/build/symbiote.js CHANGED
@@ -189,7 +189,7 @@ function slotProcessor(fr, fnCtx) {
189
189
  mapObj.slot.remove();
190
190
  });
191
191
  } else {
192
- fnCtx.innerHTML = "";
192
+ !fnCtx.processInnerHtml && (fnCtx.innerHTML = "");
193
193
  }
194
194
  }
195
195
  function refProcessor(fr, fnCtx) {
@@ -202,8 +202,8 @@ function refProcessor(fr, fnCtx) {
202
202
  function domSetProcessor(fr, fnCtx) {
203
203
  [...fr.querySelectorAll(`[${DICT.BIND_ATTR}]`)].forEach((el) => {
204
204
  let subStr = el.getAttribute(DICT.BIND_ATTR);
205
- let keyValsArr = subStr.split(";");
206
- keyValsArr.forEach((keyValStr) => {
205
+ let keyValArr = subStr.split(";");
206
+ keyValArr.forEach((keyValStr) => {
207
207
  if (!keyValStr) {
208
208
  return;
209
209
  }
@@ -283,7 +283,7 @@ var txtNodesProcessor = function(fr, fnCtx) {
283
283
  let offset;
284
284
  while (txtNode.textContent.includes(CLOSE_TOKEN)) {
285
285
  if (txtNode.textContent.startsWith(OPEN_TOKEN)) {
286
- offset = txtNode.textContent.indexOf(CLOSE_TOKEN) + 2;
286
+ offset = txtNode.textContent.indexOf(CLOSE_TOKEN) + CLOSE_TOKEN.length;
287
287
  txtNode.splitText(offset);
288
288
  tokenNodes.push(txtNode);
289
289
  } else {
@@ -317,12 +317,22 @@ var _BaseComponent = class extends HTMLElement {
317
317
  }
318
318
  render(template, shadow = this.renderShadow) {
319
319
  let fr;
320
+ if ((shadow || this.constructor["__shadowStylesUrl"]) && !this.shadowRoot) {
321
+ this.attachShadow({
322
+ mode: "open"
323
+ });
324
+ }
325
+ if (this.processInnerHtml) {
326
+ for (let fn of this.tplProcessors) {
327
+ fn(this, this);
328
+ }
329
+ }
320
330
  if (template || this.constructor["template"]) {
321
331
  if (this.constructor["template"] && !this.constructor["__tpl"]) {
322
332
  this.constructor["__tpl"] = document.createElement("template");
323
333
  this.constructor["__tpl"].innerHTML = this.constructor["template"];
324
334
  }
325
- while (this.firstChild) {
335
+ while (!this.processInnerHtml && this.firstChild) {
326
336
  this.firstChild.remove();
327
337
  }
328
338
  if ((template == null ? void 0 : template.constructor) === DocumentFragment) {
@@ -338,11 +348,6 @@ var _BaseComponent = class extends HTMLElement {
338
348
  fn(fr, this);
339
349
  }
340
350
  }
341
- if ((shadow || this.constructor["__shadowStylesUrl"]) && !this.shadowRoot) {
342
- this.attachShadow({
343
- mode: "open"
344
- });
345
- }
346
351
  let addFr = () => {
347
352
  fr && (shadow && this.shadowRoot.appendChild(fr) || this.appendChild(fr));
348
353
  this.__initCallback();
@@ -370,6 +375,7 @@ var _BaseComponent = class extends HTMLElement {
370
375
  this.pauseRender = false;
371
376
  this.renderShadow = false;
372
377
  this.readyToDestroy = true;
378
+ this.processInnerHtml = false;
373
379
  }
374
380
  get autoCtxName() {
375
381
  if (!this.__autoCtxName) {
@@ -500,7 +506,9 @@ var _BaseComponent = class extends HTMLElement {
500
506
  for (let proc of tpl_processors_default) {
501
507
  this.addTemplateProcessor(proc);
502
508
  }
503
- if (!this.pauseRender) {
509
+ if (this.pauseRender) {
510
+ this.__initCallback();
511
+ } else {
504
512
  this.render();
505
513
  }
506
514
  }
@@ -646,11 +654,12 @@ var TypedData = class {
646
654
  console.warn(MSG_NAME + prop);
647
655
  return;
648
656
  }
649
- if ((value == null ? void 0 : value.constructor) !== this.__typedSchema[prop].type) {
650
- console.warn(MSG_TYPE + prop);
657
+ let pDesc = this.__typedSchema[prop];
658
+ if ((value == null ? void 0 : value.constructor) === pDesc.type || pDesc.nullable && value === null) {
659
+ this.__data.pub(prop, value);
651
660
  return;
652
661
  }
653
- this.__data.pub(prop, value);
662
+ console.warn(MSG_TYPE + prop);
654
663
  }
655
664
  setMultipleValues(updObj) {
656
665
  for (let prop in updObj) {
@@ -1 +1 @@
1
- var L=Object.defineProperty;var $=(o,t,e)=>t in o?L(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var T=(o,t,e)=>($(o,typeof t!="symbol"?t+"":t,e),e);function F(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 n=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=F(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=!0){!s&&Object.keys(this.store).includes(t)||(this.store[t]=e,this.callbackMap[t]&&this.callbackMap[t].forEach(i=>{i(this.store[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 l=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"});var P="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",B=P.length-1,_=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:P.charAt(Math.random()*B);return e}};function U(o,t){if(t.renderShadow)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()})}else t.innerHTML=""}function H(o,t){[...o.querySelectorAll(`[${l.EL_REF_ATTR}]`)].forEach(e=>{let s=e.getAttribute(l.EL_REF_ATTR);t.ref[s]=e,e.removeAttribute(l.EL_REF_ATTR)})}function W(o,t){[...o.querySelectorAll(`[${l.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(l.BIND_ATTR).split(";").forEach(r=>{if(!r)return;let a=r.split(":").map(c=>c.trim()),h=a[0],p;h.indexOf(l.ATTR_BIND_PRFX)===0&&(p=!0,h=h.replace(l.ATTR_BIND_PRFX,""));let b=a[1].split(",").map(c=>c.trim()),E,m,x,S;if(h.includes(".")){E=!0;let c=h.split(".");S=()=>{m=e,c.forEach((u,j)=>{j<c.length-1?m=m[u]:x=u})},S()}for(let c of b)t.sub(c,u=>{p?(u==null?void 0:u.constructor)===Boolean?u?e.setAttribute(h,""):e.removeAttribute(h):e.setAttribute(h,u):E?m?m[x]=u:window.setTimeout(()=>{S(),m[x]=u}):e[h]=u})}),e.removeAttribute(l.BIND_ATTR)})}var y="{{",w="}}",V="skip-text";function q(o){let t,e=[],s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,{acceptNode:i=>{var r;return!((r=i.parentElement)==null?void 0:r.hasAttribute(V))&&i.textContent.includes(y)&&i.textContent.includes(w)&&1}});for(;t=s.nextNode();)e.push(t);return e}var z=function(o,t){q(o).forEach(s=>{let i=[],r;for(;s.textContent.includes(w);)s.textContent.startsWith(y)?(r=s.textContent.indexOf(w)+2,s.splitText(r),i.push(s)):(r=s.textContent.indexOf(y),s.splitText(r)),s=s.nextSibling;i.forEach(a=>{let h=a.textContent.replace(y,"").replace(w,"");t.sub(h,p=>{a.textContent=p})})})},R=[U,H,W,z];var D=0,d=class extends HTMLElement{initCallback(){}__initCallback(){var t;this.__initialized||(this.__initialized=!0,(t=this.initCallback)==null||t.call(this))}render(t,e=this.renderShadow){let s;if(t||this.constructor.template){for(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template);this.firstChild;)this.firstChild.remove();if((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)}(e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"});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)}constructor(){super();this.init$=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}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=_.generate(),this.style.setProperty(l.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(l.CSS_CTX_PROP,!0)}get ctxName(){var t;return((t=this.getAttribute(l.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(l.EXT_DATA_CTX_PRFX))s=e.nodeCtx,i=t.replace(l.EXT_DATA_CTX_PRFX,"");else if(t.includes(l.NAMED_DATA_CTX_SPLTR)){let r=t.split(l.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=d.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=d.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=d.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=d.__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=d.__parseProp(s,this);return r.ctx.pub(r.name,i),!0},get:(e,s)=>{let i=d.__parseProp(s,this);return i.ctx.read(i.name)}})}return this.__stateProxy}set$(t){for(let e in t)this.$[e]=t[e]}__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(l.EXT_DATA_CTX_PRFX))this.nodeCtx.add(e.replace(l.EXT_DATA_CTX_PRFX,""),this.init$[e]);else if(e.includes(l.NAMED_DATA_CTX_SPLTR)){let s=e.split(l.NAMED_DATA_CTX_SPLTR),i=s[0].trim(),r=s[1].trim();if(i&&r){let a=n.getNamedCtx(i,!1);a||(a=n.registerNamedCtx(i,{})),a.add(r,this.init$[e])}}else this.localCtx.add(e,this.init$[e]);this.__dataCtxInitialized=!0}connectedCallback(){var t;if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let e=(t=this.getAttribute(l.CTX_NAME_ATTR))==null?void 0:t.trim();e&&this.style.setProperty(l.CSS_CTX_PROP,`'${e}'`),this.__initDataCtx(),this.initChildren=[...this.childNodes];for(let s of R)this.addTemplateProcessor(s);this.pauseRender||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)},100))}static reg(t,e=!1){if(t||(D++,t=`${l.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]}bindCssData(t,e=!0){let s=(e?l.EXT_DATA_CTX_PRFX:"")+t;return this.add(s,this.getCssData(t,!0)),s}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)}},A=d;T(A,"template");var N="[Typed State] Wrong property name: ",G="[Typed State] Wrong property type: ",C=class{constructor(t,e){this.__typedSchema=t,this.__ctxId=e||_.generate(),this.__schema=Object.keys(t).reduce((s,i)=>(s[i]=t[i].value,s),{}),this.__data=n.registerNamedCtx(this.__ctxId,this.__schema)}get uid(){return this.__ctxId}setValue(t,e){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(N+t);return}if((e==null?void 0:e.constructor)!==this.__typedSchema[t].type){console.warn(G+t);return}this.__data.pub(t,e)}setMultipleValues(t){for(let e in t)this.setValue(e,t[e])}getValue(t){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(N+t);return}return this.__data.read(t)}subscribe(t,e){return this.__data.sub(t,e)}remove(){this.__data.remove()}};var v=class{constructor(t){this.__typedSchema=t.typedSchema,this.__ctxId=t.ctxName||_.generate(),this.__data=n.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 C(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]}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 f=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(f.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=n.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||""})}),f.notify(),s}};f.appMap=Object.create(null);window.onpopstate=()=>{f.notify()};function M(o,t){for(let e in t)e.includes("-")?o.style.setProperty(e,t[e]):o.style[e]=t[e]}function X(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(o={tag:"div"}){let t=document.createElement(o.tag);if(o.attributes&&X(t,o.attributes),o.styles&&M(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=O(e);t.appendChild(s)}),t}var I="idb-store-ready",K="symbiote-db",Y="symbiote-idb-update_",k=class{_notifyWhenReady(t=null){window.dispatchEvent(new CustomEvent(I,{detail:{dbName:this.name,storeName:this.storeName,event:t}}))}get _updEventName(){return Y+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 h;((h=a.target.result)==null?void 0:h._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((h,p)=>{a.onsuccess=b=>{s||this._notifySubscribers(t),h(b.target.result)},a.onerror=b=>{p(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=h=>{e||this._notifySubscribers(t),r(h)},i.onerror=h=>{a(h)}})}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(h=>h._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,g.clear(this.name)}},g=class{static get readyEventName(){return I}static open(t=K,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]}};T(g,"_reg",Object.create(null));export{f as AppRouter,A as BaseComponent,n as Data,g as IDB,v as TypedCollection,C as TypedData,_ as UID,X as applyAttributes,M as applyStyles,O as create};
1
+ var L=Object.defineProperty;var $=(o,t,e)=>t in o?L(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var y=(o,t,e)=>($(o,typeof t!="symbol"?t+"":t,e),e);function F(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 n=class{constructor(t){this.uid=Symbol(),this.name=t.name||null,t.schema.constructor===Object?this.store=F(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=!0){!s&&Object.keys(this.store).includes(t)||(this.store[t]=e,this.callbackMap[t]&&this.callbackMap[t].forEach(i=>{i(this.store[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 l=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"});var P="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",B=P.length-1,_=class{static generate(t="XXXXXXXXX-XXX"){let e="";for(let s=0;s<t.length;s++)e+=t[s]==="-"?t[s]:P.charAt(Math.random()*B);return e}};function U(o,t){if(t.renderShadow)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()})}else!t.processInnerHtml&&(t.innerHTML="")}function H(o,t){[...o.querySelectorAll(`[${l.EL_REF_ATTR}]`)].forEach(e=>{let s=e.getAttribute(l.EL_REF_ATTR);t.ref[s]=e,e.removeAttribute(l.EL_REF_ATTR)})}function W(o,t){[...o.querySelectorAll(`[${l.BIND_ATTR}]`)].forEach(e=>{e.getAttribute(l.BIND_ATTR).split(";").forEach(r=>{if(!r)return;let a=r.split(":").map(u=>u.trim()),h=a[0],p;h.indexOf(l.ATTR_BIND_PRFX)===0&&(p=!0,h=h.replace(l.ATTR_BIND_PRFX,""));let b=a[1].split(",").map(u=>u.trim()),E,m,x,S;if(h.includes(".")){E=!0;let u=h.split(".");S=()=>{m=e,u.forEach((c,j)=>{j<u.length-1?m=m[c]:x=c})},S()}for(let u of b)t.sub(u,c=>{p?(c==null?void 0:c.constructor)===Boolean?c?e.setAttribute(h,""):e.removeAttribute(h):e.setAttribute(h,c):E?m?m[x]=c:window.setTimeout(()=>{S(),m[x]=c}):e[h]=c})}),e.removeAttribute(l.BIND_ATTR)})}var w="{{",T="}}",V="skip-text";function q(o){let t,e=[],s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,{acceptNode:i=>{var r;return!((r=i.parentElement)==null?void 0:r.hasAttribute(V))&&i.textContent.includes(w)&&i.textContent.includes(T)&&1}});for(;t=s.nextNode();)e.push(t);return e}var z=function(o,t){q(o).forEach(s=>{let i=[],r;for(;s.textContent.includes(T);)s.textContent.startsWith(w)?(r=s.textContent.indexOf(T)+T.length,s.splitText(r),i.push(s)):(r=s.textContent.indexOf(w),s.splitText(r)),s=s.nextSibling;i.forEach(a=>{let h=a.textContent.replace(w,"").replace(T,"");t.sub(h,p=>{a.textContent=p})})})},R=[U,H,W,z];var D=0,d=class extends HTMLElement{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){for(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template);!this.processInnerHtml&&this.firstChild;)this.firstChild.remove();if((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)}constructor(){super();this.init$=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 autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=_.generate(),this.style.setProperty(l.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(l.CSS_CTX_PROP,!0)}get ctxName(){var t;return((t=this.getAttribute(l.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(l.EXT_DATA_CTX_PRFX))s=e.nodeCtx,i=t.replace(l.EXT_DATA_CTX_PRFX,"");else if(t.includes(l.NAMED_DATA_CTX_SPLTR)){let r=t.split(l.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=d.__parseProp(t,this);this.allSubs.add(s.ctx.sub(s.name,e))}notify(t){let e=d.__parseProp(t,this);e.ctx.notify(e.name)}has(t){let e=d.__parseProp(t,this);return e.ctx.has(e.name)}add(t,e){let s=d.__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=d.__parseProp(s,this);return r.ctx.pub(r.name,i),!0},get:(e,s)=>{let i=d.__parseProp(s,this);return i.ctx.read(i.name)}})}return this.__stateProxy}set$(t){for(let e in t)this.$[e]=t[e]}__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(l.EXT_DATA_CTX_PRFX))this.nodeCtx.add(e.replace(l.EXT_DATA_CTX_PRFX,""),this.init$[e]);else if(e.includes(l.NAMED_DATA_CTX_SPLTR)){let s=e.split(l.NAMED_DATA_CTX_SPLTR),i=s[0].trim(),r=s[1].trim();if(i&&r){let a=n.getNamedCtx(i,!1);a||(a=n.registerNamedCtx(i,{})),a.add(r,this.init$[e])}}else this.localCtx.add(e,this.init$[e]);this.__dataCtxInitialized=!0}connectedCallback(){var t;if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let e=(t=this.getAttribute(l.CTX_NAME_ATTR))==null?void 0:t.trim();e&&this.style.setProperty(l.CSS_CTX_PROP,`'${e}'`),this.__initDataCtx(),this.initChildren=[...this.childNodes];for(let s of R)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)},100))}static reg(t,e=!1){if(t||(D++,t=`${l.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]}bindCssData(t,e=!0){let s=(e?l.EXT_DATA_CTX_PRFX:"")+t;return this.add(s,this.getCssData(t,!0)),s}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)}},A=d;y(A,"template");var N="[Typed State] Wrong property name: ",G="[Typed State] Wrong property type: ",C=class{constructor(t,e){this.__typedSchema=t,this.__ctxId=e||_.generate(),this.__schema=Object.keys(t).reduce((s,i)=>(s[i]=t[i].value,s),{}),this.__data=n.registerNamedCtx(this.__ctxId,this.__schema)}get uid(){return this.__ctxId}setValue(t,e){if(!this.__typedSchema.hasOwnProperty(t)){console.warn(N+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(N+t);return}return this.__data.read(t)}subscribe(t,e){return this.__data.sub(t,e)}remove(){this.__data.remove()}};var M=class{constructor(t){this.__typedSchema=t.typedSchema,this.__ctxId=t.ctxName||_.generate(),this.__data=n.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 C(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]}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 f=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(f.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=n.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||""})}),f.notify(),s}};f.appMap=Object.create(null);window.onpopstate=()=>{f.notify()};function v(o,t){for(let e in t)e.includes("-")?o.style.setProperty(e,t[e]):o.style[e]=t[e]}function X(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(o={tag:"div"}){let t=document.createElement(o.tag);if(o.attributes&&X(t,o.attributes),o.styles&&v(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=O(e);t.appendChild(s)}),t}var I="idb-store-ready",K="symbiote-db",Y="symbiote-idb-update_",k=class{_notifyWhenReady(t=null){window.dispatchEvent(new CustomEvent(I,{detail:{dbName:this.name,storeName:this.storeName,event:t}}))}get _updEventName(){return Y+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 h;((h=a.target.result)==null?void 0:h._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((h,p)=>{a.onsuccess=b=>{s||this._notifySubscribers(t),h(b.target.result)},a.onerror=b=>{p(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=h=>{e||this._notifySubscribers(t),r(h)},i.onerror=h=>{a(h)}})}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(h=>h._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,g.clear(this.name)}},g=class{static get readyEventName(){return I}static open(t=K,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]}};y(g,"_reg",Object.create(null));export{f as AppRouter,A as BaseComponent,n as Data,g as IDB,M as TypedCollection,C as TypedData,_ as UID,X as applyAttributes,v as applyStyles,O as create};
@@ -29,12 +29,22 @@ export class BaseComponent extends HTMLElement {
29
29
  render(template, shadow = this.renderShadow) {
30
30
  /** @type {DocumentFragment} */
31
31
  let fr;
32
+ if ((shadow || this.constructor['__shadowStylesUrl']) && !this.shadowRoot) {
33
+ this.attachShadow({
34
+ mode: 'open',
35
+ });
36
+ }
37
+ if (this.processInnerHtml) {
38
+ for (let fn of this.tplProcessors) {
39
+ fn(this, this);
40
+ }
41
+ }
32
42
  if (template || this.constructor['template']) {
33
43
  if (this.constructor['template'] && !this.constructor['__tpl']) {
34
44
  this.constructor['__tpl'] = document.createElement('template');
35
45
  this.constructor['__tpl'].innerHTML = this.constructor['template'];
36
46
  }
37
- while (this.firstChild) {
47
+ while (!this.processInnerHtml && this.firstChild) {
38
48
  this.firstChild.remove();
39
49
  }
40
50
  if (template?.constructor === DocumentFragment) {
@@ -51,11 +61,6 @@ export class BaseComponent extends HTMLElement {
51
61
  fn(fr, this);
52
62
  }
53
63
  }
54
- if ((shadow || this.constructor['__shadowStylesUrl']) && !this.shadowRoot) {
55
- this.attachShadow({
56
- mode: 'open',
57
- });
58
- }
59
64
 
60
65
  // for the possible asynchronous call:
61
66
  let addFr = () => {
@@ -77,7 +82,7 @@ export class BaseComponent extends HTMLElement {
77
82
 
78
83
  /**
79
84
  * @template {BaseComponent} T
80
- * @param {(fr: DocumentFragment, fnCtx: T) => void} processorFn
85
+ * @param {(fr: DocumentFragment | T, fnCtx: T) => void} processorFn
81
86
  */
82
87
  addTemplateProcessor(processorFn) {
83
88
  this.tplProcessors.add(processorFn);
@@ -87,7 +92,7 @@ export class BaseComponent extends HTMLElement {
87
92
  super();
88
93
  /** @type {Object<string, unknown>} */
89
94
  this.init$ = Object.create(null);
90
- /** @type {Set<(fr: DocumentFragment, fnCtx: unknown) => void>} */
95
+ /** @type {Set<(fr: DocumentFragment | BaseComponent, fnCtx: unknown) => void>} */
91
96
  this.tplProcessors = new Set();
92
97
  /** @type {Object<string, any>} */
93
98
  this.ref = Object.create(null);
@@ -98,6 +103,8 @@ export class BaseComponent extends HTMLElement {
98
103
  this.renderShadow = false;
99
104
  /** @type {Boolean} */
100
105
  this.readyToDestroy = true;
106
+ /** @type {Boolean} */
107
+ this.processInnerHtml = false;
101
108
  }
102
109
 
103
110
  /** @returns {String} */
@@ -274,7 +281,9 @@ export class BaseComponent extends HTMLElement {
274
281
  for (let proc of PROCESSORS) {
275
282
  this.addTemplateProcessor(proc);
276
283
  }
277
- if (!this.pauseRender) {
284
+ if (this.pauseRender) {
285
+ this.__initCallback();
286
+ } else {
278
287
  this.render();
279
288
  }
280
289
  }
package/core/TypedData.js CHANGED
@@ -6,7 +6,7 @@ const MSG_TYPE = '[Typed State] Wrong property type: ';
6
6
 
7
7
  export class TypedData {
8
8
  /**
9
- * @param {Object<string, { type: any; value: any }>} typedSchema
9
+ * @param {Object<string, { type: any; value: any; nullable?: Boolean }>} typedSchema
10
10
  * @param {String} [ctxName]
11
11
  */
12
12
  constructor(typedSchema, ctxName) {
@@ -40,11 +40,12 @@ export class TypedData {
40
40
  console.warn(MSG_NAME + prop);
41
41
  return;
42
42
  }
43
- if (value?.constructor !== this.__typedSchema[prop].type) {
44
- console.warn(MSG_TYPE + prop);
43
+ let pDesc = this.__typedSchema[prop];
44
+ if (value?.constructor === pDesc.type || (pDesc.nullable && value === null)) {
45
+ this.__data.pub(prop, value);
45
46
  return;
46
47
  }
47
- this.__data.pub(prop, value);
48
+ console.warn(MSG_TYPE + prop);
48
49
  }
49
50
 
50
51
  /** @param {Object<string, any>} updObj */
@@ -4,7 +4,6 @@ import { DICT } from './dictionary.js';
4
4
  * @template {import('./BaseComponent.js').BaseComponent} T
5
5
  * @param {DocumentFragment} fr
6
6
  * @param {T} fnCtx
7
- * @returns {any}
8
7
  */
9
8
  function slotProcessor(fr, fnCtx) {
10
9
  if (fnCtx.renderShadow) {
@@ -41,7 +40,7 @@ function slotProcessor(fr, fnCtx) {
41
40
  mapObj.slot.remove();
42
41
  });
43
42
  } else {
44
- fnCtx.innerHTML = '';
43
+ !fnCtx.processInnerHtml && (fnCtx.innerHTML = '');
45
44
  }
46
45
  }
47
46
 
@@ -66,8 +65,8 @@ function refProcessor(fr, fnCtx) {
66
65
  function domSetProcessor(fr, fnCtx) {
67
66
  [...fr.querySelectorAll(`[${DICT.BIND_ATTR}]`)].forEach((el) => {
68
67
  let subStr = el.getAttribute(DICT.BIND_ATTR);
69
- let keyValsArr = subStr.split(';');
70
- keyValsArr.forEach((keyValStr) => {
68
+ let keyValArr = subStr.split(';');
69
+ keyValArr.forEach((keyValStr) => {
71
70
  if (!keyValStr) {
72
71
  return;
73
72
  }
@@ -160,7 +159,7 @@ const txtNodesProcessor = function (fr, fnCtx) {
160
159
  // Splitting of the text node:
161
160
  while (txtNode.textContent.includes(CLOSE_TOKEN)) {
162
161
  if (txtNode.textContent.startsWith(OPEN_TOKEN)) {
163
- offset = txtNode.textContent.indexOf(CLOSE_TOKEN) + 2;
162
+ offset = txtNode.textContent.indexOf(CLOSE_TOKEN) + CLOSE_TOKEN.length;
164
163
  txtNode.splitText(offset);
165
164
  tokenNodes.push(txtNode);
166
165
  } else {
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "version": "1.4.8",
28
+ "version": "1.5.2",
29
29
  "description": "Symbiote.js",
30
30
  "author": "hello@symbiotejs.org",
31
31
  "license": "MIT",