UNPKG

stencil-quantum

Version:

Experience the quantum realm of stencil.

1 lines 7.45 kB
import{f as t,g as n}from"./p-e5446afd.js";const i=(...t)=>i.debug&&console.log(...t);i.debug=!1;const e=i,o=()=>{};function s(t,n,i){const s=t[n]||o;return t[n]=async function(...t){e(n,this);const o=await i(this);let l=await s.apply(this,t);return o instanceof Function&&await o(this),l},()=>{t[n]=s}}const l=Symbol.for("stencil-quantum-providers");class c{constructor(n,i,o=!1){this.key=n,this.value=i,this.debug=o,this.listeners=[],this.hooks=new Map,this.mutable=!1,this.paused=!1,this.retrieve=()=>this.value,this.provide=t=>{this.debug&&e(`(${String(this.key)}) `,"PROVIDING",t,"to",this.listeners);let n=this.value;return this.value=t,this.paused||this.listeners.filter((t=>!t.paused)).forEach((i=>i.action(t,n))),this},this.update=t=>this.provide(t(this.retrieve())),this.listen=(t,n=!0)=>{this.debug&&e(`(${String(this.key)}) `,"LISTEN",n,this,t);const i={action:t,unlisten:()=>this.unlisten(t),paused:!1};return this.listeners=[...this.listeners,i],n&&t(this.value),i},this.unlisten=t=>{this.listeners=this.listeners.filter((n=>n.action!==t))},this.attach=(t,n)=>{this.debug&&e(`(${String(this.key)}) `,"Add Provider",t,this);const i=c.getAttached(t);return i.includes(this)||i.push(this),this.debug&&e(`(${String(this.key)}) `,"Total Providers",t,i),n?this:this.hook(t)},this.isHooked=t=>this.hooks.has(t),this.getHook=t=>this.hooks.get(t),this.hook=n=>(this.debug&&e(`(${String(this.key)}) `,"Hook Provider",n,this),this.hooks.set(n,this.listen((()=>t(n)))),this),this.pauseHook=(t,n=!0)=>{this.debug&&e(`(${String(this.key)}) `,"Pausing Hook",n),this.isHooked(t)&&(this.getHook(t).paused=n)},this.unhook=t=>{var n;return this.debug&&e(`(${String(this.key)}) `,"Unhook Provider",t,this),this.isHooked(t)&&(null===(n=this.hooks.get(t))||void 0===n||n.unlisten(),this.hooks.delete(t)),this},this.destroy=()=>{this.listeners=[],this.hooks=new Map}}pause(t=!0){this.paused=t}static makeFilter(t,n){return i=>i.key===t||n&&"string"==typeof t&&i.key===n+"__"+t}static find(t,n,i,o){var s,l,r,a;o&&e(`(${String(n)}) `,"Searching Provider",n,i,t);const h=c.getAttached(t).filter(c.makeFilter(n,i));if(h.length>1)throw new u(`Found multiple "${String(n)}" providers on the same object!`);if(1===h.length)return h[0];let d=null!==(r=null!==(s=t.parentElement)&&void 0!==s?s:null===(l=t.shadowRoot)||void 0===l?void 0:l.host)&&void 0!==r?r:null===(a=t.parentNode)||void 0===a?void 0:a.host;if(!d)throw new u(`No provider in hierarchy found that matches "${String(n)}"!`);return c.find(d,n,i,o).attach(t,!0)}static create(t,n,i,o,s){return"string"==typeof n&&(n=(o?o+"__":"")+n),s&&e(`(${String(n)}) `,"Create Provider",t,n,i),new c(n,i,s).attach(t)}static getAttached(t){return t[l]instanceof Array||(t[l]=[]),t[l]}}const r=Symbol.for("stencil-quantum-error");class u extends Error{constructor(t,n){super(t instanceof Error?t.message:t),this.target=n,t instanceof Error&&Object.assign(this,t)}}function a(t,n){const i=new u(n,t);console.error(i);try{c.find(t,r).provide(i)}catch(t){throw i}}function h(t){return function(i,e){let o;s(i,"componentWillLoad",(i=>{const e=n(i);try{o=c.find(e,r,null==t?void 0:t.namespace),o.attach(e),o.hook(e)}catch(t){a(e,t)}})),delete i[e]&&Object.defineProperty(i,e,{get:()=>null==o?void 0:o.retrieve(),set:t=>null==o?void 0:o.provide(t),enumerable:!0,configurable:!0})}}function d(t){return function(i,e){let o;s(i,"componentWillLoad",(s=>{const l=n(s);o=c.create(l,r,i[e],null==t?void 0:t.namespace);try{o.attach(l),o.hook(l)}catch(t){a(l,t)}})),delete i[e]&&Object.defineProperty(i,e,{get:()=>null==o?void 0:o.retrieve(),set:t=>null==o?void 0:o.provide(t),enumerable:!0,configurable:!0})}}function v(t){return function(i,e,o){return s(i,"componentWillLoad",(i=>{const e=n(i),s=c.create(e,r,void 0,null==t?void 0:t.namespace),l=(null==t?void 0:t.provide)?c.create(e,t.provide,void 0,t.namespace):void 0;try{s.attach(e),null==l||l.attach(e),s.listen((async t=>{var n;try{const e=await(null===(n=o.value)||void 0===n?void 0:n.apply(i,[t]));null==l||l.provide(e)}catch(t){a(e,t)}}))}catch(t){a(e,t)}})),o}}function f(t,i){return function(e,o){const l=null==t?void 0:t.get(i);let r=null==l?void 0:l.default;delete e[o],s(e,"componentWillLoad",(t=>{const u=n(t);let h;try{h=c.find(u,i,null==l?void 0:l.namespace,null==l?void 0:l.debug),h.hook(u)}catch(t){}return s(e,"disconnectedCallback",(i=>{if(i===t){const i=n(t);null==h||h.pauseHook(i,!0)}})),s(e,"connectedCallback",(i=>{if(i===t){const i=n(t);null==h||h.pauseHook(i,!1)}})),Object.defineProperty(t,o,{get:()=>{var t;return null!==(t=null==h?void 0:h.retrieve())&&void 0!==t?t:r},set:t=>{(null==l?void 0:l.mutable)&&(null==h?void 0:h.mutable)?h.provide(t):r=t},enumerable:!0,configurable:!0}),()=>{if(!h)try{h=c.find(u,i,null==l?void 0:l.namespace,null==l?void 0:l.debug),h.hook(u)}catch(t){a(u,t)}}}))}}function b(t,i){return function(e,o,l){const r=null==t?void 0:t.get(i),u=l.value;return s(e,"componentWillLoad",(t=>{let o,l;const h=n(t),d=()=>{o=c.find(h,i,null==r?void 0:r.namespace),l=o.listen((n=>{try{u.apply(t,[n])}catch(t){a(h,t)}}))};s(e,"disconnectedCallback",(n=>{n===t&&l&&(l.paused=!0)})),s(e,"connectedCallback",(n=>{n===t&&l&&(l.paused=!1)}));try{d()}catch(t){}return()=>{if(!o){null==l||l.unlisten();try{d()}catch(t){a(h,t)}}}})),l}}function g(t,i){return function(e,o){const l=null==t?void 0:t.get(i);let r=e[o]||(null==l?void 0:l.default);delete e[o],s(e,"componentWillLoad",(t=>{const u=n(t),h=c.create(u,i,null!=r?r:t[o],null==l?void 0:l.namespace,null==l?void 0:l.debug);h.mutable=!!(null==l?void 0:l.mutable);try{h.attach(u),h.hook(u)}catch(t){a(u,t)}Object.defineProperty(t,o,{get:()=>h.retrieve(),set:t=>h.provide(t),enumerable:!0,configurable:!0}),s(e,"disconnectedCallback",(n=>{n===t&&h.pause()})),s(e,"connectedCallback",(n=>{n===t&&h.pause(!1)}))}))}}function m(t,i,e,l){return function(r,u,h){const d=t.get(i),v=e.get(l),f=h.value;return s(r,"componentWillLoad",(t=>{const i=n(t);let e,l;const u=c.create(i,v.name,void 0,v.namespace);u.mutable=!!v.mutable;const h=()=>{l=c.find(i,d.name,d.namespace),e=l.listen((async n=>{try{const i=await f.apply(t,[n]);u&&u.provide(i)}catch(t){a(i,t)}}))};s(r,"disconnectedCallback",(n=>{n===t&&e&&(e.paused=!0)})),s(r,"connectedCallback",(n=>{n===t&&e&&(e.paused=!1)}));try{return h(),o}catch(t){return()=>{null==e||e.unlisten();try{h()}catch(t){a(i,t)}}}})),h}}function p(t,i){return function(e,o){const l=null==t?void 0:t.get(i);let r=e[o]||(null==l?void 0:l.default);delete e[o],s(e,"componentWillLoad",(t=>{const u=n(t),h=c.create(u,i,null!=r?r:t[o],null==l?void 0:l.namespace,null==l?void 0:l.debug);try{h.attach(u),h.hook(u)}catch(t){a(u,t)}Object.defineProperty(t,o,{get:()=>h.retrieve(),set:n=>h.provide(((...i)=>n.apply(t,i))),enumerable:!0,configurable:!0}),s(e,"disconnectedCallback",(n=>{n===t&&h.pause()})),s(e,"connectedCallback",(n=>{n===t&&h.pause(!1)}))}))}}class y{constructor(t,n){this.keys=Object.entries(t).map((([t,i])=>{var e;return{name:t,namespace:null!==(e=null==n?void 0:n.namespace)&&void 0!==e?e:"$"+y.uid++,default:i.default,mutable:i.mutable,debug:i.debug,config:this}})).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n.name]:n})),{})}get(t){return this.keys[t]}Provide(t){return g(this,t)}Context(t){return f(this,t)}Observe(t){return b(this,t)}React(t,n,i){return m(this,t,n,i)}Implement(t){return p(this,t)}Action(t){return f(this,t)}}y.uid=0;export{d as C,y as E,p as I,b as O,c as P,u as Q,m as R,h as T,v as a,f as b,g as c,s as h,e as l,o as n,a as t}