@symbiotejs/symbiote 1.4.6 → 1.4.7

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.
@@ -74,8 +74,8 @@ export class BaseComponent extends HTMLElement {
74
74
  notify(prop: string): void;
75
75
  has(prop: string): boolean;
76
76
  add<T_2>(prop: string, val: T_2): void;
77
- add$<T_3>(obj: {
78
- [x: string]: T_4;
77
+ add$(obj: {
78
+ [x: string]: any;
79
79
  }): void;
80
80
  get $(): {
81
81
  [x: string]: any;
@@ -107,15 +107,11 @@ export class TypedData {
107
107
  value: any;
108
108
  };
109
109
  }, ctxName?: string);
110
- __typedSchema: {
111
- [x: string]: {
112
- type: any;
113
- value: any;
114
- };
115
- };
116
- __ctxId: string;
117
- __schema: {};
118
- __state: Data;
110
+ private __typedSchema;
111
+ private __ctxId;
112
+ private __schema;
113
+ private __data;
114
+ get uid(): string;
119
115
  setValue(prop: string, value: any): void;
120
116
  setMultipleValues(updObj: {
121
117
  [x: string]: any;
@@ -141,7 +137,7 @@ export class TypedCollection {
141
137
  });
142
138
  private __typedSchema;
143
139
  private __ctxId;
144
- private __state;
140
+ private __data;
145
141
  private __watchList;
146
142
  private __handler;
147
143
  private __subsMap;
@@ -204,11 +200,9 @@ export class UID {
204
200
  export class IDB {
205
201
  static get readyEventName(): string;
206
202
  static open(dbName?: string, storeName?: string): DbInstance;
203
+ private static _reg;
207
204
  static clear(dbName: string): void;
208
205
  }
209
- export namespace IDB {
210
- const _reg: any;
211
- }
212
206
  declare class DbInstance {
213
207
  constructor(dbName: string, storeName: string);
214
208
  private _notifyWhenReady;
@@ -232,13 +226,26 @@ declare class DbInstance {
232
226
  remove: () => void;
233
227
  };
234
228
  stop(): void;
235
- __subscribtionsMap: any;
236
229
  }
237
230
  export function applyStyles<T extends HTMLElement>(el: T, styleMap: StyleMap): void;
238
231
  export function applyAttributes<T extends HTMLElement>(el: T, attrMap: AttrMap): void;
239
232
  export function create(desc?: ElementDescriptor): any;
240
- export type StyleMap = any;
241
- export type AttrMap = any;
242
- export type ElementDescriptor = any;
233
+ export type StyleMap = {
234
+ [x: string]: string | number | boolean;
235
+ };
236
+ export type AttrMap = {
237
+ [x: string]: string | number | boolean;
238
+ };
239
+ export type PropMap = {
240
+ [x: string]: any;
241
+ };
242
+ export type ElementDescriptor = {
243
+ tag?: string;
244
+ attributes?: AttrMap;
245
+ styles?: StyleMap;
246
+ properties?: PropMap;
247
+ processors?: Function[];
248
+ children?: ElementDescriptor[];
249
+ };
243
250
 
244
251
  export {};
package/build/symbiote.js CHANGED
@@ -636,7 +636,10 @@ var TypedData = class {
636
636
  acc[key] = typedSchema[key].value;
637
637
  return acc;
638
638
  }, {});
639
- this.__state = Data.registerNamedCtx(this.__ctxId, this.__schema);
639
+ this.__data = Data.registerNamedCtx(this.__ctxId, this.__schema);
640
+ }
641
+ get uid() {
642
+ return this.__ctxId;
640
643
  }
641
644
  setValue(prop, value) {
642
645
  if (!this.__typedSchema.hasOwnProperty(prop)) {
@@ -647,7 +650,7 @@ var TypedData = class {
647
650
  console.warn(MSG_TYPE + prop);
648
651
  return;
649
652
  }
650
- this.__state.pub(prop, value);
653
+ this.__data.pub(prop, value);
651
654
  }
652
655
  setMultipleValues(updObj) {
653
656
  for (let prop in updObj) {
@@ -659,13 +662,13 @@ var TypedData = class {
659
662
  console.warn(MSG_NAME + prop);
660
663
  return void 0;
661
664
  }
662
- return this.__state.read(prop);
665
+ return this.__data.read(prop);
663
666
  }
664
667
  subscribe(prop, handler) {
665
- return this.__state.sub(prop, handler);
668
+ return this.__data.sub(prop, handler);
666
669
  }
667
670
  remove() {
668
- this.__state.remove();
671
+ this.__data.remove();
669
672
  }
670
673
  };
671
674
 
@@ -674,7 +677,7 @@ var TypedCollection = class {
674
677
  constructor(options) {
675
678
  this.__typedSchema = options.typedSchema;
676
679
  this.__ctxId = options.ctxName || UID.generate();
677
- this.__state = Data.registerNamedCtx(this.__ctxId, {});
680
+ this.__data = Data.registerNamedCtx(this.__ctxId, {});
678
681
  this.__watchList = options.watchList || [];
679
682
  this.__handler = options.handler || null;
680
683
  this.__subsMap = Object.create(null);
@@ -711,21 +714,21 @@ var TypedCollection = class {
711
714
  for (let prop in init) {
712
715
  item.setValue(prop, init[prop]);
713
716
  }
714
- this.__state.add(item.__ctxId, item);
717
+ this.__data.add(item.uid, item);
715
718
  this.__watchList.forEach((propName) => {
716
- if (!this.__subsMap[item.__ctxId]) {
717
- this.__subsMap[item.__ctxId] = [];
719
+ if (!this.__subsMap[item.uid]) {
720
+ this.__subsMap[item.uid] = [];
718
721
  }
719
- this.__subsMap[item.__ctxId].push(item.subscribe(propName, () => {
720
- this.__notifyObservers(propName, item.__ctxId);
722
+ this.__subsMap[item.uid].push(item.subscribe(propName, () => {
723
+ this.__notifyObservers(propName, item.uid);
721
724
  }));
722
725
  });
723
- this.__items.add(item.__ctxId);
726
+ this.__items.add(item.uid);
724
727
  this.notify();
725
728
  return item;
726
729
  }
727
730
  read(id) {
728
- return this.__state.read(id);
731
+ return this.__data.read(id);
729
732
  }
730
733
  readProp(id, propName) {
731
734
  let item = this.read(id);
@@ -738,7 +741,7 @@ var TypedCollection = class {
738
741
  remove(id) {
739
742
  this.__items.delete(id);
740
743
  this.notify();
741
- this.__state.pub(id, null);
744
+ this.__data.pub(id, null);
742
745
  delete this.__subsMap[id];
743
746
  }
744
747
  clearAll() {
@@ -766,7 +769,7 @@ var TypedCollection = class {
766
769
  return [...this.__items];
767
770
  }
768
771
  destroy() {
769
- this.__state.remove();
772
+ this.__data.remove();
770
773
  this.__observers = null;
771
774
  for (let id in this.__subsMap) {
772
775
  this.__subsMap[id].forEach((sub) => {
@@ -1098,7 +1101,7 @@ var DbInstance = class {
1098
1101
  }
1099
1102
  stop() {
1100
1103
  window.removeEventListener("storage", this._updateHandler);
1101
- this.__subscribtionsMap = null;
1104
+ this._subscribtionsMap = null;
1102
1105
  IDB.clear(this.name);
1103
1106
  }
1104
1107
  };
@@ -1122,7 +1125,7 @@ var IDB = class {
1122
1125
  }
1123
1126
  }
1124
1127
  };
1125
- IDB._reg = Object.create(null);
1128
+ __publicField(IDB, "_reg", Object.create(null));
1126
1129
  export {
1127
1130
  AppRouter,
1128
1131
  BaseComponent,
@@ -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 E=(o,t,e)=>($(o,typeof t!="symbol"?t+"":t,e),e);function F(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 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(r=>{r(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(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 a;let i=(a=r.getAttribute)==null?void 0:a.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()})}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(i=>{if(!i)return;let a=i.split(":").map(u=>u.trim()),h=a[0],m;h.indexOf(l.ATTR_BIND_PRFX)===0&&(m=!0,h=h.replace(l.ATTR_BIND_PRFX,""));let b=a[1].split(",").map(u=>u.trim()),A,p,x,g;if(h.includes(".")){A=!0;let u=h.split(".");g=()=>{p=e,u.forEach((c,j)=>{j<u.length-1?p=p[c]:x=c})},g()}for(let u of b)t.sub(u,c=>{m?(c==null?void 0:c.constructor)===Boolean?c?e.setAttribute(h,""):e.removeAttribute(h):e.setAttribute(h,c):A?p?p[x]=c:window.setTimeout(()=>{g(),p[x]=c}):e[h]=c})}),e.removeAttribute(l.BIND_ATTR)})}var T="{{",y="}}",V="skip-text";function q(o){let t,e=[],s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,{acceptNode:r=>{var i;return!((i=r.parentElement)==null?void 0:i.hasAttribute(V))&&r.textContent.includes(T)&&r.textContent.includes(y)&&1}});for(;t=s.nextNode();)e.push(t);return e}var z=function(o,t){q(o).forEach(s=>{let r=[],i;for(;s.textContent.includes(y);)s.textContent.startsWith(T)?(i=s.textContent.indexOf(y)+2,s.splitText(i),r.push(s)):(i=s.textContent.indexOf(T),s.splitText(i)),s=s.nextSibling;r.forEach(a=>{let h=a.textContent.replace(T,"").replace(y,"");t.sub(h,m=>{a.textContent=m})})})},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 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)}(e||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"});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)}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,r;if(t.startsWith(l.EXT_DATA_CTX_PRFX))s=e.nodeCtx,r=t.replace(l.EXT_DATA_CTX_PRFX,"");else if(t.includes(l.NAMED_DATA_CTX_SPLTR)){let i=t.split(l.NAMED_DATA_CTX_SPLTR);s=n.getNamedCtx(i[0]),r=i[1]}else s=e.localCtx,r=t;return{ctx:s,name:r}}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,r)=>{let i=d.__parseProp(s,this);return i.ctx.pub(i.name,r),!0},get:(e,s)=>{let r=d.__parseProp(s,this);return r.ctx.read(r.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),r=s[0].trim(),i=s[1].trim();if(r&&i){let a=n.getNamedCtx(r,!1);a||(a=n.registerNamedCtx(r,{})),a.add(i,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 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]}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 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)}},S=d;E(S,"template");var N="[Typed State] Wrong property name: ",G="[Typed State] Wrong property type: ",w=class{constructor(t,e){this.__typedSchema=t,this.__ctxId=e||_.generate(),this.__schema=Object.keys(t).reduce((s,r)=>(s[r]=t[r].value,s),{}),this.__state=n.registerNamedCtx(this.__ctxId,this.__schema)}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.__state.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.__state.read(t)}subscribe(t,e){return this.__state.sub(t,e)}remove(){this.__state.remove()}};var v=class{constructor(t){this.__typedSchema=t.typedSchema,this.__ctxId=t.ctxName||_.generate(),this.__state=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,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 w(this.__typedSchema);for(let s in t)e.setValue(s,t[s]);return this.__state.add(e.__ctxId,e),this.__watchList.forEach(s=>{this.__subsMap[e.__ctxId]||(this.__subsMap[e.__ctxId]=[]),this.__subsMap[e.__ctxId].push(e.subscribe(s,()=>{this.__notifyObservers(s,e.__ctxId)}))}),this.__items.add(e.__ctxId),this.notify(),e}read(t){return this.__state.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.__state.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]}destroy(){this.__state.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 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(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 r="?"+t;for(let a in e)e[a]===!0?r+=this.separator+a:r+=this.separator+a+`=${e[a]}`;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=n.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||""})}),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=r=>{this._notifyWhenReady(r)}},this.request.onsuccess=s=>{this.db=s.target.result,this._notifyWhenReady(s)},this.request.onerror=s=>{console.error(s)},this._subscribtionsMap={},this._updateHandler=s=>{s.key===this.name&&this._subscribtionsMap[s.newValue]&&this._subscribtionsMap[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=a=>{var h;((h=a.target.result)==null?void 0:h._value)?r(a.target.result._value):(r(null),console.warn(`IDB: cannot read "${t}"`))},s.onerror=a=>{i(a)}})}write(t,e,s=!1){let r={_key:t,_value:e},a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).put(r);return new Promise((h,m)=>{a.onsuccess=b=>{s||this._notifySubscribers(t),h(b.target.result)},a.onerror=b=>{m(b)}})}delete(t,e=!1){let r=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).delete(t);return new Promise((i,a)=>{r.onsuccess=h=>{e||this._notifySubscribers(t),i(h)},r.onerror=h=>{a(h)}})}getAll(){let e=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).getAll();return new Promise((s,r)=>{e.onsuccess=i=>{let a=i.target.result;s(a.map(h=>h._value))},e.onerror=i=>{r(i)}})}subscribe(t,e){this._subscribtionsMap[t]||(this._subscribtionsMap[t]=new Set);let s=this._subscribtionsMap[t];return s.add(e),{remove:()=>{s.delete(e),s.size||delete this._subscribtionsMap[t]}}}stop(){window.removeEventListener("storage",this._updateHandler),this.__subscribtionsMap=null,C.clear(this.name)}},C=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]}};C._reg=Object.create(null);export{f as AppRouter,S as BaseComponent,n as Data,C as IDB,v as TypedCollection,w 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 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],m;h.indexOf(l.ATTR_BIND_PRFX)===0&&(m=!0,h=h.replace(l.ATTR_BIND_PRFX,""));let b=a[1].split(",").map(c=>c.trim()),E,p,x,S;if(h.includes(".")){E=!0;let c=h.split(".");S=()=>{p=e,c.forEach((u,j)=>{j<c.length-1?p=p[u]:x=u})},S()}for(let c of b)t.sub(c,u=>{m?(u==null?void 0:u.constructor)===Boolean?u?e.setAttribute(h,""):e.removeAttribute(h):e.setAttribute(h,u):E?p?p[x]=u:window.setTimeout(()=>{S(),p[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,m=>{a.textContent=m})})})},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._subscribtionsMap={},this._updateHandler=s=>{s.key===this.name&&this._subscribtionsMap[s.newValue]&&this._subscribtionsMap[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,m)=>{a.onsuccess=b=>{s||this._notifySubscribers(t),h(b.target.result)},a.onerror=b=>{m(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._subscribtionsMap[t]||(this._subscribtionsMap[t]=new Set);let s=this._subscribtionsMap[t];return s.add(e),{remove:()=>{s.delete(e),s.size||delete this._subscribtionsMap[t]}}}stop(){window.removeEventListener("storage",this._updateHandler),this._subscribtionsMap=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};
@@ -194,10 +194,7 @@ export class BaseComponent extends HTMLElement {
194
194
  parsed.ctx.add(parsed.name, val, false);
195
195
  }
196
196
 
197
- /**
198
- * @template T
199
- * @param {Object<string, T>} obj
200
- */
197
+ /** @param {Object<string, any>} obj */
201
198
  add$(obj) {
202
199
  for (let prop in obj) {
203
200
  this.add(prop, obj[prop]);
@@ -5,7 +5,7 @@ import { TypedData } from './TypedData.js';
5
5
  export class TypedCollection {
6
6
  /**
7
7
  * @param {Object} options
8
- * @param {Object<string, { type: any; value: * }>} options.typedSchema
8
+ * @param {Object<string, { type: any; value: any }>} options.typedSchema
9
9
  * @param {String[]} [options.watchList]
10
10
  * @param {(list: string[]) => void} [options.handler]
11
11
  * @param {String} [options.ctxName]
@@ -13,7 +13,7 @@ export class TypedCollection {
13
13
  constructor(options) {
14
14
  /**
15
15
  * @private
16
- * @type {Object<string, { type: any; value: * }>}
16
+ * @type {Object<string, { type: any; value: any }>}
17
17
  */
18
18
  this.__typedSchema = options.typedSchema;
19
19
  /**
@@ -25,7 +25,7 @@ export class TypedCollection {
25
25
  * @private
26
26
  * @type {Data}
27
27
  */
28
- this.__state = Data.registerNamedCtx(this.__ctxId, {});
28
+ this.__data = Data.registerNamedCtx(this.__ctxId, {});
29
29
  /**
30
30
  * @private
31
31
  * @type {string[]}
@@ -96,18 +96,18 @@ export class TypedCollection {
96
96
  for (let prop in init) {
97
97
  item.setValue(prop, init[prop]);
98
98
  }
99
- this.__state.add(item.__ctxId, item);
99
+ this.__data.add(item.uid, item);
100
100
  this.__watchList.forEach((propName) => {
101
- if (!this.__subsMap[item.__ctxId]) {
102
- this.__subsMap[item.__ctxId] = [];
101
+ if (!this.__subsMap[item.uid]) {
102
+ this.__subsMap[item.uid] = [];
103
103
  }
104
- this.__subsMap[item.__ctxId].push(
104
+ this.__subsMap[item.uid].push(
105
105
  item.subscribe(propName, () => {
106
- this.__notifyObservers(propName, item.__ctxId);
106
+ this.__notifyObservers(propName, item.uid);
107
107
  })
108
108
  );
109
109
  });
110
- this.__items.add(item.__ctxId);
110
+ this.__items.add(item.uid);
111
111
  this.notify();
112
112
  return item;
113
113
  }
@@ -117,7 +117,7 @@ export class TypedCollection {
117
117
  * @returns {TypedData}
118
118
  */
119
119
  read(id) {
120
- return this.__state.read(id);
120
+ return this.__data.read(id);
121
121
  }
122
122
 
123
123
  /**
@@ -145,7 +145,7 @@ export class TypedCollection {
145
145
  remove(id) {
146
146
  this.__items.delete(id);
147
147
  this.notify();
148
- this.__state.pub(id, null);
148
+ this.__data.pub(id, null);
149
149
  delete this.__subsMap[id];
150
150
  }
151
151
 
@@ -185,7 +185,7 @@ export class TypedCollection {
185
185
  }
186
186
 
187
187
  destroy() {
188
- this.__state.remove();
188
+ this.__data.remove();
189
189
  this.__observers = null;
190
190
  for (let id in this.__subsMap) {
191
191
  this.__subsMap[id].forEach((sub) => {
package/core/TypedData.js CHANGED
@@ -6,17 +6,29 @@ const MSG_TYPE = '[Typed State] Wrong property type: ';
6
6
 
7
7
  export class TypedData {
8
8
  /**
9
- * @param {Object<string, { type: any; value: * }>} typedSchema
9
+ * @param {Object<string, { type: any; value: any }>} typedSchema
10
10
  * @param {String} [ctxName]
11
11
  */
12
12
  constructor(typedSchema, ctxName) {
13
+ /** @private */
13
14
  this.__typedSchema = typedSchema;
15
+ /** @private */
14
16
  this.__ctxId = ctxName || UID.generate();
17
+ /** @private */
15
18
  this.__schema = Object.keys(typedSchema).reduce((acc, key) => {
16
19
  acc[key] = typedSchema[key].value;
17
20
  return acc;
18
21
  }, {});
19
- this.__state = Data.registerNamedCtx(this.__ctxId, this.__schema);
22
+ /**
23
+ * @private
24
+ * @type {Data}
25
+ */
26
+ this.__data = Data.registerNamedCtx(this.__ctxId, this.__schema);
27
+ }
28
+
29
+ /** @returns {String} */
30
+ get uid() {
31
+ return this.__ctxId;
20
32
  }
21
33
 
22
34
  /**
@@ -32,7 +44,7 @@ export class TypedData {
32
44
  console.warn(MSG_TYPE + prop);
33
45
  return;
34
46
  }
35
- this.__state.pub(prop, value);
47
+ this.__data.pub(prop, value);
36
48
  }
37
49
 
38
50
  /** @param {Object<string, any>} updObj */
@@ -48,7 +60,7 @@ export class TypedData {
48
60
  console.warn(MSG_NAME + prop);
49
61
  return undefined;
50
62
  }
51
- return this.__state.read(prop);
63
+ return this.__data.read(prop);
52
64
  }
53
65
 
54
66
  /**
@@ -56,10 +68,10 @@ export class TypedData {
56
68
  * @param {(newVal: any) => void} handler
57
69
  */
58
70
  subscribe(prop, handler) {
59
- return this.__state.sub(prop, handler);
71
+ return this.__data.sub(prop, handler);
60
72
  }
61
73
 
62
74
  remove() {
63
- this.__state.remove();
75
+ this.__data.remove();
64
76
  }
65
77
  }
package/package.json CHANGED
@@ -10,6 +10,7 @@
10
10
  "lint": "npm run lint:types && npm run lint:eslint && npm run lint:prettier",
11
11
  "format": "npm run format:eslint && npm run format:prettier",
12
12
  "types": "dts-bundle-generator --config ./dts.config.json",
13
+ "dts_native": "tsc -p dts-native.cfg.json",
13
14
  "build": "node esbuild.js && npm run types"
14
15
  },
15
16
  "files": [
@@ -24,7 +25,7 @@
24
25
  "publishConfig": {
25
26
  "access": "public"
26
27
  },
27
- "version": "1.4.6",
28
+ "version": "1.4.7",
28
29
  "description": "Symbiote.js",
29
30
  "author": "hello@symbiotejs.org",
30
31
  "license": "MIT",
package/utils/IDB.js CHANGED
@@ -190,6 +190,7 @@ class DbInstance {
190
190
  */
191
191
  subscribe(key, callback) {
192
192
  if (!this._subscribtionsMap[key]) {
193
+ /** @private */
193
194
  this._subscribtionsMap[key] = new Set();
194
195
  }
195
196
  /** @type {Set} */
@@ -207,7 +208,7 @@ class DbInstance {
207
208
 
208
209
  stop() {
209
210
  window.removeEventListener('storage', this._updateHandler);
210
- this.__subscribtionsMap = null;
211
+ this._subscribtionsMap = null;
211
212
  IDB.clear(this.name);
212
213
  }
213
214
  }
@@ -231,6 +232,9 @@ export class IDB {
231
232
  return this._reg[key];
232
233
  }
233
234
 
235
+ /** @private */
236
+ static _reg = Object.create(null);
237
+
234
238
  /** @param {String} dbName */
235
239
  static clear(dbName) {
236
240
  window.indexedDB.deleteDatabase(dbName);
@@ -241,5 +245,3 @@ export class IDB {
241
245
  }
242
246
  }
243
247
  }
244
-
245
- IDB._reg = Object.create(null);
@@ -1,17 +1,8 @@
1
- /**
2
- * @typedef {any} StyleMap
3
- * @type {Object<string, string | number | boolean>}
4
- */
1
+ /** @typedef {Object<string, string | number | boolean>} StyleMap */
5
2
 
6
- /**
7
- * @typedef {any} AttrMap
8
- * @type {Object<string, string | number | boolean>}
9
- */
3
+ /** @typedef {Object<string, string | number | boolean>} AttrMap */
10
4
 
11
- /**
12
- * @typedef {any} PropMap
13
- * @type {Object<string, any>}
14
- */
5
+ /** @typedef {Object<string, any>} PropMap */
15
6
 
16
7
  /**
17
8
  * @template {HTMLElement} T
@@ -50,15 +41,14 @@ export function applyAttributes(el, attrMap) {
50
41
  }
51
42
 
52
43
  /**
53
- * @typedef {any} ElementDescriptor
54
- * @type {{
44
+ * @typedef {{
55
45
  * tag?: String;
56
46
  * attributes?: AttrMap;
57
47
  * styles?: StyleMap;
58
48
  * properties?: PropMap;
59
49
  * processors?: Function[];
60
50
  * children?: ElementDescriptor[];
61
- * }}
51
+ * }} ElementDescriptor
62
52
  */
63
53
 
64
54
  /**