@aegis-framework/pandora 0.4.1 → 0.4.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/dist/pandora.browser.js +2 -2
- package/dist/pandora.browser.js.map +3 -3
- package/dist/pandora.js +2 -2
- package/dist/pandora.js.map +3 -3
- package/package.json +1 -1
package/dist/pandora.js
CHANGED
|
@@ -19,11 +19,11 @@ Please use the static 'html' tag function. See https://lit.dev/docs/templates/ex
|
|
|
19
19
|
`;let G=Object.keys(W);for(let Q of G){$+="\t".repeat(Y);let F=W[Q];if(typeof F==="object"&&F!==null){let B={};B[Q]=F,$+=T(B,X,Y+1)}else $+=` ${Q}: ${F};
|
|
20
20
|
`}$+=`}
|
|
21
21
|
`}else $+="\t".repeat(Y),$+=` ${q}: ${W};
|
|
22
|
-
`}return $}class U extends HTMLElement{_children;_state;_props;_ready;_connected;_isReady;_style;static _tag;static _template;static _observedAttributes=[];static _onMount;static _onUnmount;static _onError;static _applyMiddleware;static _hasMiddleware;static get observedAttributes(){return this._observedAttributes}static set observedAttributes(J){this._observedAttributes=J}static get tag(){if(typeof this._tag>"u"){let J=this.name,X=J.match(/([A-Z])/g);if(X!==null)for(let Y of X)J=J.replace(Y,`-${Y}`.toLowerCase());this._tag=J.slice(1)}return this._tag}static set tag(J){this._tag=J}static template(J=null,X=null){if(J!==null)this._template=J,document.querySelectorAll(this.tag).forEach((Y)=>{if(Y instanceof U&&Y._isReady)Y.forceRender()});else{if(typeof this._template==="function")return this._template.call(X,X);return this._template}}constructor(){super();this._children=this.innerHTML.trim(),this._state={},this._props={},this._ready=[],this._connected=!1,this._isReady=!1,this._style={}}get width(){return parseInt(getComputedStyle(this).width.replace("px",""))}set width(J){this.style.width=typeof J==="number"?`${J}px`:J}get height(){return parseInt(getComputedStyle(this).height.replace("px",""))}set height(J){this.style.height=typeof J==="number"?`${J}px`:J}get static(){return this.constructor}set static(J){throw Error("Component static properties cannot be reassigned.")}get props(){return new Proxy(this._props,{get:(J,X)=>{if(X in J)return J[X];if(this.hasAttribute(X)){let Y=this.getAttribute(X);if(typeof Y==="string"){if(Y==="false")Y=!1;else if(Y==="true"||Y==="")Y=!0;else if(!isNaN(Number(Y)))Y=Y.includes(".")?parseFloat(Y):parseInt(Y)}return Y}return},set:()=>{throw Error("Component props should be set using the `setProps` function.")}})}set props(J){if(!this._connected)this._props={...this._props,...J};else throw Error("Component props cannot be directly assigned. Use the `setProps` function instead.")}get state(){return new Proxy(this._state,{get:(J,X)=>J[X],set:(J,X,Y)=>{if(!this._connected)return J[X]=Y,!0;else throw Error("Component state should be set using the `setState` function instead.")}})}set state(J){if(!this._connected)this._state={...this._state,...J};else throw Error("Component state should be set using the `setState` function instead.")}get dom(){return this}set dom(J){throw Error("Component DOM can not be overwritten.")}get slotContent(){return this._children}get isConnected(){return this._connected}get isReady(){return this._isReady}static register(){window.customElements.define(this.tag,this)}template(J=null){return this.constructor.template(J,this)}static _styleSheet=null;setStyle(J,X=!1){let Y=this.constructor;if(!Y._styleSheet)Y._styleSheet=new CSSStyleSheet;let Z="";if(typeof J==="object"){if(!X)this._style={...this._style,...J};else this._style={...J};Z=T(this._style,Y.tag)}else if(typeof J==="string")if(!X)Z=Array.from(Y._styleSheet.cssRules||[]).map((q)=>q.cssText).join(`
|
|
22
|
+
`}return $}class U extends HTMLElement{_children;_state;_props;_ready;_connected;_isReady;_style;static _tag;static _template;static _observedAttributes=[];static _onMount;static _onUnmount;static _onError;static _applyMiddleware;static _hasMiddleware;static get observedAttributes(){return this._observedAttributes}static set observedAttributes(J){this._observedAttributes=J}static get tag(){if(typeof this._tag>"u"){let J=this.name,X=J.match(/([A-Z])/g);if(X!==null)for(let Y of X)J=J.replace(Y,`-${Y}`.toLowerCase());this._tag=J.slice(1)}return this._tag}static set tag(J){this._tag=J}static template(J=null,X=null){if(J!==null)this._template=J,document.querySelectorAll(this.tag).forEach((Y)=>{if(Y instanceof U&&Y._isReady)Y.forceRender()});else{if(typeof this._template==="function")return this._template.call(X,X);return this._template}}constructor(){super();this._children=this.innerHTML.trim(),this._state={},this._props={},this._ready=[],this._connected=!1,this._isReady=!1,this._style={}}get width(){return parseInt(getComputedStyle(this).width.replace("px",""))}set width(J){this.style.width=typeof J==="number"?`${J}px`:J}get height(){return parseInt(getComputedStyle(this).height.replace("px",""))}set height(J){this.style.height=typeof J==="number"?`${J}px`:J}get static(){return this.constructor}set static(J){throw Error("Component static properties cannot be reassigned.")}get props(){return new Proxy(this._props,{get:(J,X)=>{if(X in J&&typeof J[X]<"u")return J[X];if(this.hasAttribute(X)){let Y=this.getAttribute(X);if(typeof Y==="string"){if(Y==="false")Y=!1;else if(Y==="true"||Y==="")Y=!0;else if(!isNaN(Number(Y)))Y=Y.includes(".")?parseFloat(Y):parseInt(Y)}return Y}return},set:()=>{throw Error("Component props should be set using the `setProps` function.")}})}set props(J){if(!this._connected)this._props={...this._props,...J};else throw Error("Component props cannot be directly assigned. Use the `setProps` function instead.")}get state(){return new Proxy(this._state,{get:(J,X)=>J[X],set:(J,X,Y)=>{if(!this._connected)return J[X]=Y,!0;else throw Error("Component state should be set using the `setState` function instead.")}})}set state(J){if(!this._connected)this._state={...this._state,...J};else throw Error("Component state should be set using the `setState` function instead.")}get dom(){return this}set dom(J){throw Error("Component DOM can not be overwritten.")}get slotContent(){return this._children}get isConnected(){return this._connected}get isReady(){return this._isReady}static register(){window.customElements.define(this.tag,this)}template(J=null){return this.constructor.template(J,this)}static _styleSheet=null;setStyle(J,X=!1){let Y=this.constructor;if(!Y._styleSheet)Y._styleSheet=new CSSStyleSheet;let Z="";if(typeof J==="object"){if(!X)this._style={...this._style,...J};else this._style={...J};Z=T(this._style,Y.tag)}else if(typeof J==="string")if(!X)Z=Array.from(Y._styleSheet.cssRules||[]).map((q)=>q.cssText).join(`
|
|
23
23
|
`)+`
|
|
24
24
|
`+J;else Z=J;if(Y._styleSheet.replaceSync(Z),!document.adoptedStyleSheets.includes(Y._styleSheet))document.adoptedStyleSheets=[...document.adoptedStyleSheets,Y._styleSheet];return this._style}setState(J){let X=J;if(U._hasMiddleware?.("state")&&U._applyMiddleware)X=U._applyMiddleware("state",this,J);let Y={...this._state};this._state={...this._state,...X};for(let Z of Object.keys(X))this.updateCallback(Z,Y[Z],this._state[Z],"state",Y,this._state)}setProps(J){let X=J;if(U._hasMiddleware?.("props")&&U._applyMiddleware)X=U._applyMiddleware("props",this,J);let Y={...this._props};this._props={...this._props,...X};for(let Z of Object.keys(X))this.updateCallback(Z,Y[Z],this._props[Z],"props",Y,this._props);this._setPropAttributes(!0)}_setPropAttributes(J=!1){for(let[X,Y]of Object.entries(this._props)){let Z=typeof Y;if(Z==="string"||Z==="number"||Z==="boolean")if(J)this.setAttribute(X,String(Y));else this._props[X]=this.props[X],this.setAttribute(X,String(this.props[X]))}}on(J,X,Y){return this.addEventListener(J,X,Y),this}off(J,X,Y){return this.removeEventListener(J,X,Y),this}once(J,X,Y){let Z=typeof Y==="boolean"?{capture:Y,once:!0}:{...Y,once:!0};return this.addEventListener(J,X,Z),this}emit(J,X,Y){let Z=new CustomEvent(J,{detail:X,bubbles:!0,cancelable:!0,composed:!0,...Y});return this.dispatchEvent(Z)}query(J){return this.dom.querySelector(J)}queryAll(J){return this.dom.querySelectorAll(J)}async willUpdate(J,X,Y,Z,$,q){}async update(J,X,Y,Z,$,q){}async didUpdate(J,X,Y,Z,$,q){}async onStateUpdate(J,X,Y,Z,$){}async onPropsUpdate(J,X,Y,Z,$){}async willMount(){}async didMount(){}async willUnmount(){}async unmount(){}async didUnmount(){}forceRender(){return this._render()}render(){return""}async _render(){let J=this.render;if(this.constructor._template!==void 0)J=()=>this.template();let X=await m(J,this),Y=V(X)||X===M?"lit":"string";if(U._hasMiddleware?.("render")&&U._applyMiddleware)X=U._applyMiddleware("render",this,X,Y);if(V(X)||X===M){if(!this.hasAttribute("data-lit-rendered"))this.innerHTML="",this.setAttribute("data-lit-rendered","");R(X,this,{host:this});return}let Z=X.trim();if(Z==="")return;let $=this.dom.querySelector("slot");if($!==null)$.replaceWith(Z);else if(this.innerHTML=Z,this._children!==""&&Z.indexOf(this._children)===-1)this.innerHTML+=this._children}async connectedCallback(){let J=this.static.tag;try{if(this._connected=!0,this.dataset.component=J,typeof this.static._template>"u"){let Y=document.querySelector(`template#${J}`);if(Y!==null)this.template(Y.innerHTML);else this.static._template=void 0}this._setPropAttributes(!1),await this.willMount(),await this._render(),await this.didMount(),this._isReady=!0;let X=[...this._ready];this._ready=[];for(let Y of X)Y.call(this);if(U._onMount)U._onMount(this,J)}catch(X){if(U._onError)U._onError(X,this,J,"connectedCallback");else throw X}}ready(J){if(this._ready.push(J),this._isReady)J.call(this)}async disconnectedCallback(){let J=this.static.tag;try{if(await this.willUnmount(),await this.unmount(),await this.didUnmount(),this._connected=!1,U._onUnmount)U._onUnmount(this,J)}catch(X){if(U._onError)U._onError(X,this,J,"disconnectedCallback");else throw X}}async updateCallback(J,X,Y,Z="props",$={},q={}){if(await this.willUpdate(Z,J,X,Y,$,q),await this.update(Z,J,X,Y,$,q),Z==="state")await this.onStateUpdate(J,X,Y,$,q);else if(Z==="props"||Z==="attribute")await this.onPropsUpdate(J,X,Y,$,q);await this.didUpdate(Z,J,X,Y,$,q)}attributeChangedCallback(J,X,Y){if(X!==Y)this.updateCallback(J,X,Y,"attribute")}}var j=U;class OJ extends j{_shadowDOM;static _styleSheet=null;constructor(){super();this._shadowDOM=this.attachShadow({mode:"open"})}setStyle(J,X=!1){let Y=this.constructor;if(!Y._styleSheet)Y._styleSheet=new CSSStyleSheet;let Z="";if(typeof J==="object"){if(!X)this._style={...this._style,...J};else this._style={...J};Z=T(this._style)}else if(typeof J==="string")if(!X)Z=Array.from(Y._styleSheet.cssRules||[]).map((q)=>q.cssText).join(`
|
|
25
25
|
`)+`
|
|
26
26
|
`+J;else Z=J;return Y._styleSheet.replaceSync(Z),this._shadowDOM.adoptedStyleSheets=[Y._styleSheet],this._style}async _render(){let J=this.render;if(this.constructor._template!==void 0)J=()=>this.template();let X=await m(J,this),Y=V(X)||X===M?"lit":"string";if(j._hasMiddleware?.("render")&&j._applyMiddleware)X=j._applyMiddleware("render",this,X,Y);if(V(X)||X===M){R(X,this._shadowDOM,{host:this});return}let Z=X.trim(),$=Array.from(this._shadowDOM.childNodes);for(let W of $)W.remove();if(Z==="")return;let q=document.createElement("template");q.innerHTML=Z,this._shadowDOM.appendChild(q.content)}get dom(){throw Error("ShadowComponent DOM can not be accessed. Use the `shadowRoot` property instead.")}set dom(J){throw Error("ShadowComponent DOM can not be overwritten.")}get shadowRoot(){return this._shadowDOM}set shadowRoot(J){throw Error("ShadowComponent shadowRoot can not be overwritten.")}query(J){return this._shadowDOM.querySelector(J)}queryAll(J){return this._shadowDOM.querySelectorAll(J)}}var cJ=OJ;class JJ{static _debug=!1;static components={};static implementations={};static state={};static subscribers={};static mountCallbacks=new Set;static unmountCallbacks=new Set;static errorCallbacks=new Set;static aliases={};static lazyLoaders={};static middleware={props:new Set,state:new Set,render:new Set};static _initialized=!1;static _init(){if(this._initialized)return;this._initialized=!0,j._onMount=(J,X)=>this._notifyMount(J,X),j._onUnmount=(J,X)=>this._notifyUnmount(J,X),j._onError=(J,X,Y,Z)=>this._notifyError(J,X,Y,Z),j._applyMiddleware=(J,X,Y,Z)=>this._applyMiddleware(J,X,Y,Z),j._hasMiddleware=(J)=>this._hasMiddleware(J)}static register(J,X){if(this._init(),typeof this.components[J]>"u")this.components[J]=X,this.implementations[J]=X,X._tag=J,window.customElements.define(J,X),this.components[J]._registered=!0,this.log(`Registered: <${J}>`);else throw Error("A component with this tag has already been registered. Use the evolve() function to modify the component.")}static getImplementation(J){return this.implementations[J]||this.components[J]}static evolve(J,X,Y=!1){if(typeof this.components[J]>"u")throw Error("No component with this tag has been registered. Cannot Evolve.");if(this.implementations[J]=X,X._registered=!0,this.log(`Evolved: <${J}>`),Y){let Z=X.prototype,$=Object.getOwnPropertyNames(Z),q=Object.create(Z);try{X.call(q)}catch{}document.querySelectorAll(J).forEach((W)=>{if(W instanceof j&&W.isReady){let G=W;for(let Q of $)if(Q!=="constructor"&&typeof Z[Q]==="function"){let F=Z[Q];G[Q]=F.bind(W)}if(q._state){let Q=G._state||{},F=q._state;for(let B of Object.keys(F))if(!(B in Q))Q[B]=F[B];G._state=Q}if(q._props){let Q=G._props||{},F=q._props;for(let B of Object.keys(F))if(!(B in Q))Q[B]=F[B];G._props=Q}W.forceRender()}})}}static instances(J,X){if(typeof this.components[J]<"u")if(typeof X==="function")document.querySelectorAll(J).forEach(X);else return document.querySelectorAll(J);else throw Error("No component with the provided tag has been registered.")}static instantiate(J,X){if(!this.has(J))throw Error(`No component with tag "${J}" has been registered.`);if(!this.components[J]._registered)this.register(J,this.components[J]);let Y=document.createElement(this.components[J].tag);return Y.setProps(X),Y}static has(J){return typeof this.components[J]<"u"}static get(J){return this.components[J]}static setState(J,X){let Y=this.state[J];if(this.state[J]=X,this.subscribers[J])this.subscribers[J].forEach((Z)=>{Z(X,Y)})}static getState(J){return this.state[J]}static hasState(J){return J in this.state}static deleteState(J){if(J in this.state){let X=this.state[J];if(delete this.state[J],this.subscribers[J])this.subscribers[J].forEach((Y)=>{Y(void 0,X)});return!0}return!1}static subscribe(J,X){if(!this.subscribers[J])this.subscribers[J]=new Set;return this.subscribers[J].add(X),()=>{this.unsubscribe(J,X)}}static unsubscribe(J,X){if(this.subscribers[J])this.subscribers[J].delete(X)}static getAllState(){return{...this.state}}static clearState(){let J=Object.keys(this.state);for(let X of J)this.deleteState(X)}static get debug(){return this._debug}static set debug(J){this._debug=J}static log(J,X){if(this._debug)if(X!==void 0)console.log(`[Pandora] ${J}`,X);else console.log(`[Pandora] ${J}`)}static list(){return Object.keys(this.components)}static stats(J){if(J){if(!this.has(J))throw Error(`No component with tag "${J}" has been registered.`);return{tag:J,instanceCount:document.querySelectorAll(J).length,isRegistered:this.components[J]?._registered??!1,isLazy:J in this.lazyLoaders}}return this.list().map((X)=>({tag:X,instanceCount:document.querySelectorAll(X).length,isRegistered:this.components[X]?._registered??!1,isLazy:X in this.lazyLoaders}))}static onMount(J){return this._init(),this.mountCallbacks.add(J),()=>this.mountCallbacks.delete(J)}static onUnmount(J){return this._init(),this.unmountCallbacks.add(J),()=>this.unmountCallbacks.delete(J)}static _notifyMount(J,X){this.log(`Mounted: <${X}>`),this.mountCallbacks.forEach((Y)=>{try{Y(J,X)}catch(Z){console.error("[Pandora] Error in onMount callback:",Z)}})}static _notifyUnmount(J,X){this.log(`Unmounted: <${X}>`),this.unmountCallbacks.forEach((Y)=>{try{Y(J,X)}catch(Z){console.error("[Pandora] Error in onUnmount callback:",Z)}})}static onError(J){return this._init(),this.errorCallbacks.add(J),()=>this.errorCallbacks.delete(J)}static _notifyError(J,X,Y,Z){if(this.log(`Error in <${Y}> during ${Z}:`,J),this.errorCallbacks.size===0)throw J;this.errorCallbacks.forEach(($)=>{try{$(J,X,Y,Z)}catch(q){console.error("[Pandora] Error in onError callback:",q)}})}static alias(J,X){if(!this.has(X))throw Error(`Cannot create alias: no component with tag "${X}" has been registered.`);if(this.has(J))throw Error(`Cannot create alias: a component with tag "${J}" already exists.`);this.aliases[J]=X;let Y=this.components[X],Z=class extends Y{static _tag=J};this.components[J]=Z,window.customElements.define(J,Z),this.log(`Created alias: <${J}> -> <${X}>`)}static getOriginalTag(J){return this.aliases[J]}static isAlias(J){return J in this.aliases}static lazy(J,X){if(this._init(),this.has(J))throw Error(`Cannot register lazy component: a component with tag "${J}" already exists.`);this.lazyLoaders[J]=X;let Y=JJ;class Z extends j{static _tag=J;_lazyLoaded=!1;async connectedCallback(){await Y._loadLazyComponent(J);let $=Y.getImplementation(J);if($&&$!==Z){let q=$.prototype,W=Object.getOwnPropertyNames(q),G=this;for(let F of W)if(F!=="constructor"&&typeof q[F]==="function"){let B=q[F];G[F]=B.bind(this)}let Q=Object.create(q);try{$.call(Q)}catch{}if(Q._state)G._state={...Q._state};if(Q._props)G._props={...Q._props};this._lazyLoaded=!0}await super.connectedCallback()}}this.components[J]=Z,window.customElements.define(J,Z),this.log(`Registered lazy component: <${J}>`)}static async _loadLazyComponent(J){if(!(J in this.lazyLoaders))return;let X=this.lazyLoaders[J];this.log(`Loading lazy component: <${J}>`);try{let Y=await X(),Z="default"in Y?Y.default:Y;delete this.lazyLoaders[J],this.implementations[J]=Z,Z._registered=!0,this.log(`Loaded lazy component: <${J}>`)}catch(Y){throw console.error(`[Pandora] Failed to load lazy component <${J}>:`,Y),Y}}static isLazy(J){return J in this.lazyLoaders}static async preload(J){if(this.isLazy(J))await this._loadLazyComponent(J)}static use(J,X){return this._init(),this.middleware[J].add(X),()=>this.middleware[J].delete(X)}static _applyMiddleware(J,X,Y,Z){let $=Y;return this.middleware[J].forEach((q)=>{try{$=q(X,$,Z)}catch(W){console.error(`[Pandora] Error in ${J} middleware:`,W)}}),$}static _hasMiddleware(J){return this.middleware[J].size>0}}var C=JJ;function gJ(J){return function(X){return C.register(J,X),X}}function pJ(J){return function(X,Y){let{connectedCallback:Z,disconnectedCallback:$}=X,q=Symbol(`__pandora_unsub_${Y}`),W=Symbol(`__pandora_value_${Y}`);X.connectedCallback=async function(){this[q]=C.subscribe(J,(Q)=>{if(this[W]=Q,this._isReady)this.forceRender()});let G=C.getState(J);if(G!==void 0)this[W]=G;if(Z)await Z.call(this)},X.disconnectedCallback=async function(){if(this[q])this[q](),this[q]=void 0;if($)await $.call(this)},Object.defineProperty(X,Y,{get:function(){return this[W]},set:function(G){if(this[W]===G)return;if(this[W]=G,C.setState(J,G),this._isReady)this.forceRender()},enumerable:!0,configurable:!0})}}function uJ(J){return function(X,Y){let Z=J||Y,$=Symbol(`__pandora_prop_${Y}`);if(!X.constructor._observedAttributes)X.constructor._observedAttributes=[];if(!X.constructor._observedAttributes.includes(Z))X.constructor._observedAttributes.push(Z);Object.defineProperty(X,Y,{get:function(){if(this[$]!==void 0)return this[$];if(this.hasAttribute(Z)){let q=this.getAttribute(Z);return iJ(q)}return},set:function(q){if(this[$]=q,typeof q==="string"||typeof q==="number"||typeof q==="boolean")if(typeof q==="boolean")if(q)this.setAttribute(Z,"");else this.removeAttribute(Z);else this.setAttribute(Z,String(q))},enumerable:!0,configurable:!0})}}function iJ(J){if(J===null)return;if(J===""||J==="true")return!0;if(J==="false")return!1;if(!isNaN(Number(J)))return J.includes(".")?parseFloat(J):parseInt(J,10);return J}var sJ={};export{dJ as svg,R as render,M as nothing,I as noChange,yJ as html,fJ as Util,sJ as Types,cJ as ShadowComponent,C as Registry,gJ as Register,uJ as Prop,pJ as Consumer,j as Component};
|
|
27
27
|
|
|
28
|
-
//# debugId=
|
|
28
|
+
//# debugId=2D9BC630E201320B64756E2164756E21
|
|
29
29
|
//# sourceMappingURL=pandora.js.map
|