mates 0.4.0-beta.2 → 0.4.0-beta.3
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/Template/x-x.d.ts +7 -0
- package/dist/Template/x-x.d.ts.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -71,7 +71,7 @@ class Rt extends X{constructor(t){if(super(t),this.it=E,t.type!==W)throw Error(t
|
|
|
71
71
|
* @license
|
|
72
72
|
* Copyright 2021 Google LLC
|
|
73
73
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
74
|
-
*/const zt=()=>{},Dt={registerComponent:zt,unregisterComponent:zt,notifyRender:zt,getComponentName:()=>"Anonymous",logComponentMount:zt,logComponentRender:zt,logComponentUnmount:zt,logAtomSet:zt,logAtomUpdate:zt,logEventTrigger:zt,logCleanupEventTrigger:zt,logFetchRequest:zt,logFetchResponse:zt,logFetchError:zt,recordRender:zt};function Nt(t,e){Dt.registerComponent(t,e)}function Lt(t){return Dt.getComponentName(t)}function jt(t,e){Dt.logEventTrigger(t,e)}function Ut(t,e,n){Dt.recordRender(t,e,n)}function Ft(){return Dt.registerComponent!==zt}const Vt=Symbol.for("mates.readTracking");globalThis[Vt]||(globalThis[Vt]={enableReadTracking:!1,storesBeingRead:new Set,effectRunning:!1});const Wt=globalThis[Vt];function Bt(){return Wt.enableReadTracking}function Ht(){return Wt.effectRunning}function Yt(t){Wt.storesBeingRead.add(t)}function qt(){Wt.effectRunning=!0}function Xt(){Wt.effectRunning=!1}function Gt(){const t={prevEnabled:Wt.enableReadTracking,prevStores:Wt.storesBeingRead};return Wt.enableReadTracking=!0,Wt.storesBeingRead=new Set,t}function Zt(t){const e=Wt.storesBeingRead;return Wt.enableReadTracking=t.prevEnabled,Wt.storesBeingRead=t.prevStores,e}const Kt=Gt,Qt=Zt,Jt=Symbol.for("mates.componentRunningStatus");globalThis[Jt]||(globalThis[Jt]={setupInProgress:!1,templateInProgress:!1,viewOuterInProgress:!1,isHookRunning:!1});const te=globalThis[Jt];function ee(t){if(!te.isHookRunning){if(te.templateInProgress)throw new Error(`${t} cannot be created during template function execution. Only scopes (useScope) are allowed in templates.`);if(Ht())throw new Error(`${t} cannot be created inside a memo() or effect(). They should only read state, not create new reactive primitives.`)}}function ne(t){if(!te.viewOuterInProgress){if(te.templateInProgress)throw new Error(`${t} cannot be called during template function execution. Move it to the component's outer function.`);if(Ht())throw new Error(`${t} cannot be called inside a memo() or effect(). Move it to the component's outer function.`);throw new Error(`${t} must be called inside a component's outer function. It cannot be used at module level or inside inner functions (e.g. event handlers, timers, or callbacks).`)}}const se=new Set,ie={name:"matesLogEvent",__isEvent___:!0,trigger(t){se.forEach(e=>{try{e(t)}catch(t){}})},__subscribe:t=>(se.add(t),()=>se.delete(t))};function oe(t){try{return structuredClone(t)}catch(e){return t}}function re(){if("undefined"==typeof window)return!0;const t=window.location.hostname;return"localhost"===t||"127.0.0.1"===t||"[::1]"===t||t.startsWith("192.168.")||t.startsWith("10.")||t.endsWith(".local")}function ae(t){try{ie.trigger(t)}catch(t){}}function le(t,e){ae({level:"error",message:t,data:void 0!==e?oe(e):void 0,ts:performance.now()}),re()&&(void 0!==e?console.error(`[${e}]`,t):console.error(t))}function ce(t,e,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(t):s?s.value:e.get(t)}function he(t,e,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(t,n):i?i.value=n:e.set(t,n),n}var ue,de,fe;"function"==typeof SuppressedError&&SuppressedError;class pe{constructor(){ue.set(this,new Set),de.set(this,1)}subscribe(t){return ce(this,ue,"f").add(t),()=>ce(this,ue,"f").delete(t)}notify(){var t;he(this,de,(t=ce(this,de,"f"),++t),"f"),[...ce(this,ue,"f")].forEach(t=>{try{t?.()}catch(t){console.error(t)}})}getVersion(){return ce(this,de,"f")}get subscriberCount(){return ce(this,ue,"f").size}clear(){ce(this,ue,"f").clear()}}ue=new WeakMap,de=new WeakMap;class me{constructor(){fe.set(this,new Set)}subscribe(t){return ee("subscribe"),ce(this,fe,"f").has(t)?()=>{}:(ce(this,fe,"f").add(t),()=>ce(this,fe,"f").delete(t))}trigger(t){ce(this,fe,"f").forEach(e=>{try{e(t)}catch(t){console.error("Error in event handler:",t)}})}get handlerCount(){return ce(this,fe,"f").size}clear(){ce(this,fe,"f").clear()}}fe=new WeakMap;const _e=Symbol.for("mates.hostStack");globalThis[_e]||(globalThis[_e]=[]);const ge=globalThis[_e];function ye(t,e){ge.push(t);let n=null;try{n=e()}finally{ge.pop()}return n}function we(t){const e=ge[ge.length-1];if(!e){if(!1!==t)throw new Error("getCurrentHost(): No active host context");return null}return e}const ve=(t,e)=>{const n=we(!1);n&&n.addToCleanUps(t,e)},be=t=>{ee("event");const e=t||Math.random().toString(36).substring(2,15),n=new me;return{trigger:t=>{jt(e,t),n.trigger(t)},__subscribe:t=>n.subscribe(t),name:e,__isEvent___:!0}},xe=t=>{ee("cleanupEvent");const e=t||Math.random().toString(36).substring(2,15),n=new Map,s=()=>{n.forEach(t=>{if(t)try{t()}catch(t){le(t,"cleanupEvent cleanup")}})},i={trigger:t=>{!function(t,e){Dt.logCleanupEventTrigger(t,e)}(e,t),n.forEach((e,s)=>{if(e)try{e()}catch(t){le(t,"cleanupEvent cleanup")}try{const e=s(t);n.set(s,e)}catch(t){le(t,"cleanupEvent handler"),n.set(s,void 0)}})},__subscribe:t=>(n.set(t,void 0),()=>{const e=n.get(t);if(e)try{e()}catch(t){le(t,"cleanupEvent unsubscribe")}n.delete(t)}),cleanup:s,cleanupAndClearSubs:()=>{s(),n.clear()},get hasSubscribers(){return n.size>0},name:e,__isCleanupEvent___:!0,__isEvent___:!0};return i};let Se=!1;function Ce(){return Se}let Ee=0,Ae=null,ke=null;function Me(){Se&&(Ee++,null!==ke&&(clearTimeout(ke),ke=null))}function $e(){Se&&(Ee=Math.max(0,Ee-1),function(){if(Ee>0)return;if(!Ae)return;if(null!==ke)return;ke=setTimeout(()=>{if(ke=null,0===Ee&&Ae){const t=Ae;Ae=null,t()}},5)}())}function Re(){return"undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("index.js",document.baseURI).href,"undefined"==typeof process||!process.env||"production"!==process.env.NODE_ENV}function Te(t){t.DOMReadyEvent?.cleanupAndClearSubs(),t.PaintEvent?.cleanupAndClearSubs(),t.cleanups.forEach(t=>t.forEach(t=>{try{t()}catch(t){console.error("Error during cleanup:",t)}})),t.cleanups.clear(),t.onEachUpdateCallbacks.clear(),t.scopes=new Map,t._templateFn=null,t._xviewRender=()=>{},t._hasMounted=!1,t._errorState=null,t._errorHandlers=[]}const Oe=new class{constructor(){this.pending=new Set,this.isScheduled=!1}scheduleDisconnect(t){this.pending.add(t),this.isScheduled||(this.isScheduled=!0,queueMicrotask(()=>this.flush()))}cancelDisconnect(t){this.pending.delete(t)}flush(){const t=Array.from(this.pending);this.pending.clear(),this.isScheduled=!1;for(const e of t)e?.isConnected||(Te(e),e._view=null,e._props={},e.oldView=void 0)}reset(){this.pending.clear(),this.isScheduled=!1}},Ie=new class{constructor(){this.pendingEffects=new Set,this.isScheduled=!1,this._isFlushing=!1}get isFlushing(){return this._isFlushing}reset(){this.pendingEffects.clear(),this.isScheduled=!1,this._isFlushing=!1}schedule(t){this.pendingEffects.add(t),this.isScheduled||(this.isScheduled=!0,queueMicrotask(()=>this.flush()))}flush(){this._isFlushing=!0;let t=0;for(;this.pendingEffects.size>0;){if(t++>=500){this.pendingEffects.clear(),console.error("EffectScheduler: Maximum iteration limit (500) reached. This likely means an effect is infinitely updating its own dependency. Remaining effects have been dropped.");break}const e=Array.from(this.pendingEffects);this.pendingEffects.clear();for(const t of e)try{t()}catch(t){le(t,"Effect")}}this._isFlushing=!1,this.isScheduled=!1,Pe.flush()}},Pe=new class{constructor(){this.pendingComponents=new Set,this.nextPendingComponents=new Set,this._currentWave=new Set,this.isScheduled=!1,this._isFlushing=!1,this._flushVersion=0,this._onIdleCallbacks=[]}get flushVersion(){return this._flushVersion}onceIdle(t){this._onIdleCallbacks.push(t),this._isFlushing||this.isScheduled||queueMicrotask(()=>this._drainIdleCallbacks())}_drainIdleCallbacks(){if(this._isFlushing||this.isScheduled)return;if(this.pendingComponents.size>0||this.nextPendingComponents.size>0)return;const t=this._onIdleCallbacks.splice(0);for(const e of t)try{e()}catch(t){console.error(t)}}reset(){this.pendingComponents.clear(),this.nextPendingComponents.clear(),this._currentWave.clear(),this._onIdleCallbacks.length=0,this.isScheduled=!1,this._isFlushing=!1}schedule(t){if(this._isFlushing){if(this._currentWave.has(t)&&t._renderVersion!==this._flushVersion)return;this.nextPendingComponents.add(t)}else this.pendingComponents.add(t);this.isScheduled||(this.isScheduled=!0,queueMicrotask(()=>{Ie.isScheduled||Ie.isFlushing||this.flush()}))}flush(){for(this.nextPendingComponents.size>0&&(this.nextPendingComponents.forEach(t=>this.pendingComponents.add(t)),this.nextPendingComponents.clear()),this._isFlushing=!0,this._flushVersion++;this.pendingComponents.size>0;){const t=Array.from(this.pendingComponents);this.pendingComponents.clear(),t.sort((t,e)=>t._depth-e._depth),this._currentWave=new Set(t);for(const e of t)if(e.isConnected)try{e._render()}catch(t){le(t,"Component render")}this._currentWave.clear()}this._isFlushing=!1,this.isScheduled=!1,this.nextPendingComponents.size>0?(this.isScheduled=!0,queueMicrotask(()=>{Ie.isScheduled||Ie.isFlushing||this.flush()})):this._drainIdleCallbacks()}},ze=()=>{if(te.templateInProgress&&!te.setupInProgress)throw Error("Providers such as atoms, units, bubbles, getters, setters and actions can't be created inside the template function, you can create them in view function. Because template function gets called everytime the view updates.")},De=()=>{},Ne=t=>{ze(),t.__isOnMount__=!0;const e=we();e.addToCleanUps(t,De);if("AsyncFunction"===t.constructor.name&&Ce())return e._asyncMountQueue=e._asyncMountQueue??[],void e._asyncMountQueue.push(t);let n=!1;e.DOMReadyEvent.__subscribe(()=>{if(n)return;n=!0;const s=t();if(s&&"object"==typeof s&&"function"==typeof s.then)return;const i=s;i&&e.addToCleanUps(t,i)})},Le=(t,e=!0)=>{if(e&&ee("Setter"),te.setupInProgress&&e)throw new Error("Setter cannot be created inside setup function. Define setters as class properties before setup runs.");let n=t;const s=we();e&&ze();const i=new Set;try{const t=(...t)=>{const e=n(...t);return[...i].forEach(t=>{try{Ie.schedule(()=>t?.())}catch(t){console.error(t)}}),s?.isConnected&&Pe.schedule(s),e};return t.__subscribe=t=>(ee("subscribe"),i.add(t),()=>i.delete(t)),t.__isSetter___=!0,t.set=t=>{n=t},Object.defineProperty(t,"__version__",{get:()=>0}),t}catch(t){throw new Error("You can only use setter or _ inside a scope or useState or view component's outer function")}},je=Le;function Ue(t,e=!0,n){if(Ht())return;const s=we(e);if(s&&t&&!s.cleanups.has(t)){const e=n||t.__subscribe||t.subscribe,i=e?.(()=>{Pe.schedule(s)});s.addToCleanUps(t,i)}}const Fe=(t,e)=>{t.__isOn__=!0,ee("on");const n=new Set;let s;const i=()=>{if(s){try{s()}catch(t){console.error("Error in on() cleanup:",t)}s=void 0}const e=t();"function"==typeof e&&(s=e)},o=()=>Ie.schedule(i);e.forEach(t=>{n.add(t.__subscribe(o))});const r=()=>{if(n.forEach(t=>t()),s){try{s()}catch(t){console.error("Error in on() cleanup:",t)}s=void 0}};return ve(t,r),r};function Ve(){return Re()&&"undefined"!=typeof window&&!!window.__mates_hmr}function We(t){return!!t&&("AsyncFunction"===t.constructor?.name||t instanceof Promise||"object"==typeof t&&null!==t&&"then"in t||"function"==typeof t.then)}function Be(t){return"function"==typeof t?t():t}function He(t){return t.default||t}class Ye extends HTMLElement{addScope(t,e){this.scopes.set(t,e)}onEachUpdate(t){this.onEachUpdateCallbacks.add(t)}constructor(){super(),this.name="Anonymous",this.scopes=new Map,this._useStates=[],this.lastVersion=-1,this._depth=0,this._parentComponent=null,this._renderVersion=0,this._errorHandlers=[],this._errorState=null,this.onEachUpdateCallbacks=new Set,this.DOMReadyEvent=null,this.PaintEvent=null,this._isViewLoading=!1,this._onRequestParentScope=t=>{const e=t,n=e.detail?.ScopeClass;if(n&&this.scopes.has(n)){const t=this.scopes.get(n);t&&(e.stopPropagation(),e.detail.resolve(t))}},this._props={},this._propsFn=()=>this._props,this._view=null,this._templateFn=null,this._hasMounted=!1,this._renderScheduled=!1,this.componentId=Math.random(),this.cleanups=new Map,this._xviewRender=()=>{};const t=te.templateInProgress;te.templateInProgress=!1,ye(this,()=>{this.DOMReadyEvent=xe("DOMReady"),this.PaintEvent=xe("Paint")}),te.templateInProgress=t}set props(t){this._props=t,Pe.schedule(this)}get props(){return this._props}_applyViewChange(t,e){this.oldView!==t&&(this.oldView=t,e(t),(this._hasMounted||this._errorState)&&Te(this))}set view(t){if(null!==t){if(We(t))return this._isViewLoading=!0,void Be(t).then(t=>{this._isViewLoading=!1,this.view=He(t)},t=>{this._isViewLoading=!1,this._handleRenderError(t)});"function"==typeof t&&(this.name=t.name||"Anonymous"),this._applyViewChange(t,()=>{this._view=t}),Pe.schedule(this)}}get view(){return this._view}callOnEachUpdate(){this.onEachUpdateCallbacks.forEach(t=>t())}connectedCallback(){this.addEventListener("request-parent-scope",this._onRequestParentScope);let t=0,e=null,n=this.parentElement;for(;n;){if(n instanceof Ye){e=n,t=n._depth+1;break}n=n.parentElement}this._depth=t,this._parentComponent=e,Oe.cancelDisconnect(this),this._hasMounted&&(Ft()&&!this._view?.skipDevToolsRender&&Nt(this,this._view),Pe.schedule(this))}disconnectedCallback(){var t,e,n;this.removeEventListener("request-parent-scope",this._onRequestParentScope),Ft()&&(this._view?.__devtools__||this._view?.skipDevToolsRender||(n=Lt(this),Dt.logComponentUnmount(n)),this._view?.skipDevToolsRender||(t=this,e=this._view,Dt.unregisterComponent(t,e))),Oe.scheduleDisconnect(this)}addToCleanUps(t,e){const n=this.cleanups.get(t);n?n.push(e):this.cleanups.set(t,[e])}_render(){var t,e,n;if(!(this._errorState&&!this._view?.__isErrorView__||this._isViewLoading||this._renderScheduled)&&this._view)if(this._renderVersion=Pe.flushVersion,this._hasMounted){if(this._xviewRender){this.callOnEachUpdate();let s=0;if(Ft()){const i=this._view?.__devtools__,o=this._view?.skipDevToolsRender,r=performance.now();this._xviewRender(),s=performance.now()-r,i||o||(Ut(Lt(this),this.componentId,s),e=Lt(this),n=s,Dt.logComponentRender(e,n)),o||(t=this,Dt.notifyRender(t))}else this._xviewRender()}}else this._mountComponent()}_mountComponent(){const t=this._view,e=function(t){if(!Ve())return t;const e=t?.__mates_hmr_id;if(!e)return t;const n=window.__mates_hmr?.components;return n?.[e]??t}(t);F(x``,this),te.viewOuterInProgress=!0;try{this._templateFn=ye(this,()=>e(this._propsFn))}catch(t){return te.viewOuterInProgress=!1,void this._handleRenderError(t)}if(te.viewOuterInProgress=!1,"function"==typeof this._templateFn){if(this._xviewRender=()=>{te.templateInProgress=!0;try{if(!this._templateFn)return;ye(this,()=>{const t=this._templateFn(this._propsFn);F(t,this)}),this.DOMReadyEvent?.trigger(),this.PaintEvent?.hasSubscribers&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.isConnected&&this.PaintEvent?.trigger()})})}catch(t){this._handleRenderError(t)}finally{te.templateInProgress=!1}},this.callOnEachUpdate(),Ft()){const t=e?.__devtools__,n=e?.skipDevToolsRender,s=performance.now();this._xviewRender();const i=performance.now()-s;t||n||Ut(e?.name||"Anonymous",this.componentId,i)}else this._xviewRender();this._view===t&&(this._hasMounted=!0,Ft()&&(e?.skipDevToolsRender||Nt(this,e),e?.__devtools__||e?.skipDevToolsRender||(n=e?.name||"Anonymous",Dt.logComponentMount(n))))}else this._handleRenderError(new Error("inner function must be a template function that returns html result"));var n}_hotRefresh(){Te(this),Pe.schedule(this)}_handleRenderError(t){this._errorState=t;for(const e of this._errorHandlers)try{e(t)}catch(t){}if(le(t,`Component "${this.name}"`),this._view?.__isErrorView__)return;const e=this.name,n=t instanceof Error?t.message:String(t),s=t instanceof Error&&t.stack?t.stack.split("\n").slice(1).map(t=>t.trim()).filter(Boolean).join("\n"):null,i=()=>()=>x`
|
|
74
|
+
*/const zt=()=>{},Dt={registerComponent:zt,unregisterComponent:zt,notifyRender:zt,getComponentName:()=>"Anonymous",logComponentMount:zt,logComponentRender:zt,logComponentUnmount:zt,logAtomSet:zt,logAtomUpdate:zt,logEventTrigger:zt,logCleanupEventTrigger:zt,logFetchRequest:zt,logFetchResponse:zt,logFetchError:zt,recordRender:zt};function Nt(t,e){Dt.registerComponent(t,e)}function Lt(t){return Dt.getComponentName(t)}function jt(t,e){Dt.logEventTrigger(t,e)}function Ut(t,e,n){Dt.recordRender(t,e,n)}function Ft(){return Dt.registerComponent!==zt}const Vt=Symbol.for("mates.readTracking");globalThis[Vt]||(globalThis[Vt]={enableReadTracking:!1,storesBeingRead:new Set,effectRunning:!1});const Wt=globalThis[Vt];function Bt(){return Wt.enableReadTracking}function Ht(){return Wt.effectRunning}function Yt(t){Wt.storesBeingRead.add(t)}function qt(){Wt.effectRunning=!0}function Xt(){Wt.effectRunning=!1}function Gt(){const t={prevEnabled:Wt.enableReadTracking,prevStores:Wt.storesBeingRead};return Wt.enableReadTracking=!0,Wt.storesBeingRead=new Set,t}function Zt(t){const e=Wt.storesBeingRead;return Wt.enableReadTracking=t.prevEnabled,Wt.storesBeingRead=t.prevStores,e}const Kt=Gt,Qt=Zt,Jt=Symbol.for("mates.componentRunningStatus");globalThis[Jt]||(globalThis[Jt]={setupInProgress:!1,templateInProgress:!1,viewOuterInProgress:!1,isHookRunning:!1});const te=globalThis[Jt];function ee(t){if(!te.isHookRunning){if(te.templateInProgress)throw new Error(`${t} cannot be created during template function execution. Only scopes (useScope) are allowed in templates.`);if(Ht())throw new Error(`${t} cannot be created inside a memo() or effect(). They should only read state, not create new reactive primitives.`)}}function ne(t){if(!te.viewOuterInProgress){if(te.templateInProgress)throw new Error(`${t} cannot be called during template function execution. Move it to the component's outer function.`);if(Ht())throw new Error(`${t} cannot be called inside a memo() or effect(). Move it to the component's outer function.`);throw new Error(`${t} must be called inside a component's outer function. It cannot be used at module level or inside inner functions (e.g. event handlers, timers, or callbacks).`)}}const se=new Set,ie={name:"matesLogEvent",__isEvent___:!0,trigger(t){se.forEach(e=>{try{e(t)}catch(t){}})},__subscribe:t=>(se.add(t),()=>se.delete(t))};function oe(t){try{return structuredClone(t)}catch(e){return t}}function re(){if("undefined"==typeof window)return!0;const t=window.location.hostname;return"localhost"===t||"127.0.0.1"===t||"[::1]"===t||t.startsWith("192.168.")||t.startsWith("10.")||t.endsWith(".local")}function ae(t){try{ie.trigger(t)}catch(t){}}function le(t,e){ae({level:"error",message:t,data:void 0!==e?oe(e):void 0,ts:performance.now()}),re()&&(void 0!==e?console.error(`[${e}]`,t):console.error(t))}function ce(t,e,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(t):s?s.value:e.get(t)}function he(t,e,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(t,n):i?i.value=n:e.set(t,n),n}var ue,de,fe;"function"==typeof SuppressedError&&SuppressedError;class pe{constructor(){ue.set(this,new Set),de.set(this,1)}subscribe(t){return ce(this,ue,"f").add(t),()=>ce(this,ue,"f").delete(t)}notify(){var t;he(this,de,(t=ce(this,de,"f"),++t),"f"),[...ce(this,ue,"f")].forEach(t=>{try{t?.()}catch(t){console.error(t)}})}getVersion(){return ce(this,de,"f")}get subscriberCount(){return ce(this,ue,"f").size}clear(){ce(this,ue,"f").clear()}}ue=new WeakMap,de=new WeakMap;class me{constructor(){fe.set(this,new Set)}subscribe(t){return ee("subscribe"),ce(this,fe,"f").has(t)?()=>{}:(ce(this,fe,"f").add(t),()=>ce(this,fe,"f").delete(t))}trigger(t){ce(this,fe,"f").forEach(e=>{try{e(t)}catch(t){console.error("Error in event handler:",t)}})}get handlerCount(){return ce(this,fe,"f").size}clear(){ce(this,fe,"f").clear()}}fe=new WeakMap;const _e=Symbol.for("mates.hostStack");globalThis[_e]||(globalThis[_e]=[]);const ge=globalThis[_e];function ye(t,e){ge.push(t);let n=null;try{n=e()}finally{ge.pop()}return n}function we(t){const e=ge[ge.length-1];if(!e){if(!1!==t)throw new Error("getCurrentHost(): No active host context");return null}return e}const ve=(t,e)=>{const n=we(!1);n&&n.addToCleanUps(t,e)},be=t=>{ee("event");const e=t||Math.random().toString(36).substring(2,15),n=new me;return{trigger:t=>{jt(e,t),n.trigger(t)},__subscribe:t=>n.subscribe(t),name:e,__isEvent___:!0}},xe=t=>{ee("cleanupEvent");const e=t||Math.random().toString(36).substring(2,15),n=new Map,s=()=>{n.forEach(t=>{if(t)try{t()}catch(t){le(t,"cleanupEvent cleanup")}})},i={trigger:t=>{!function(t,e){Dt.logCleanupEventTrigger(t,e)}(e,t),n.forEach((e,s)=>{if(e)try{e()}catch(t){le(t,"cleanupEvent cleanup")}try{const e=s(t);n.set(s,e)}catch(t){le(t,"cleanupEvent handler"),n.set(s,void 0)}})},__subscribe:t=>(n.set(t,void 0),()=>{const e=n.get(t);if(e)try{e()}catch(t){le(t,"cleanupEvent unsubscribe")}n.delete(t)}),cleanup:s,cleanupAndClearSubs:()=>{s(),n.clear()},get hasSubscribers(){return n.size>0},name:e,__isCleanupEvent___:!0,__isEvent___:!0};return i};let Se=!1;function Ce(){return Se}let Ee=0,Ae=null,ke=null;function Me(){Se&&(Ee++,null!==ke&&(clearTimeout(ke),ke=null))}function $e(){Se&&(Ee=Math.max(0,Ee-1),function(){if(Ee>0)return;if(!Ae)return;if(null!==ke)return;ke=setTimeout(()=>{if(ke=null,0===Ee&&Ae){const t=Ae;Ae=null,t()}},5)}())}function Re(){return"undefined"==typeof document?require("url").pathToFileURL(__filename).href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("index.js",document.baseURI).href,"undefined"==typeof process||!process.env||"production"!==process.env.NODE_ENV}function Te(t){t.DOMReadyEvent?.cleanupAndClearSubs(),t.PaintEvent?.cleanupAndClearSubs(),t.cleanups.forEach(t=>t.forEach(t=>{try{t()}catch(t){console.error("Error during cleanup:",t)}})),t.cleanups.clear(),t.onEachUpdateCallbacks.clear(),t.scopes=new Map,t._templateFn=null,t._xviewRender=()=>{},t._hasMounted=!1,t._errorState=null,t._errorHandlers=[]}const Oe=new class{constructor(){this.pending=new Set,this.isScheduled=!1}scheduleDisconnect(t){this.pending.add(t),this.isScheduled||(this.isScheduled=!0,queueMicrotask(()=>this.flush()))}cancelDisconnect(t){this.pending.delete(t)}flush(){const t=Array.from(this.pending);this.pending.clear(),this.isScheduled=!1;for(const e of t)e?.isConnected||(Te(e),e._view=null,e._props={},e.oldView=void 0)}reset(){this.pending.clear(),this.isScheduled=!1}},Ie=new class{constructor(){this.pendingEffects=new Set,this.isScheduled=!1,this._isFlushing=!1}get isFlushing(){return this._isFlushing}reset(){this.pendingEffects.clear(),this.isScheduled=!1,this._isFlushing=!1}schedule(t){this.pendingEffects.add(t),this.isScheduled||(this.isScheduled=!0,queueMicrotask(()=>this.flush()))}flush(){this._isFlushing=!0;let t=0;for(;this.pendingEffects.size>0;){if(t++>=500){this.pendingEffects.clear(),console.error("EffectScheduler: Maximum iteration limit (500) reached. This likely means an effect is infinitely updating its own dependency. Remaining effects have been dropped.");break}const e=Array.from(this.pendingEffects);this.pendingEffects.clear();for(const t of e)try{t()}catch(t){le(t,"Effect")}}this._isFlushing=!1,this.isScheduled=!1,Pe.flush()}},Pe=new class{constructor(){this.pendingComponents=new Set,this.nextPendingComponents=new Set,this._currentWave=new Set,this.isScheduled=!1,this._isFlushing=!1,this._flushVersion=0,this._onIdleCallbacks=[]}get flushVersion(){return this._flushVersion}onceIdle(t){this._onIdleCallbacks.push(t),this._isFlushing||this.isScheduled||queueMicrotask(()=>this._drainIdleCallbacks())}_drainIdleCallbacks(){if(this._isFlushing||this.isScheduled)return;if(this.pendingComponents.size>0||this.nextPendingComponents.size>0)return;const t=this._onIdleCallbacks.splice(0);for(const e of t)try{e()}catch(t){console.error(t)}}reset(){this.pendingComponents.clear(),this.nextPendingComponents.clear(),this._currentWave.clear(),this._onIdleCallbacks.length=0,this.isScheduled=!1,this._isFlushing=!1}schedule(t){if(this._isFlushing){if(this._currentWave.has(t)&&t._renderVersion!==this._flushVersion)return;this.nextPendingComponents.add(t)}else this.pendingComponents.add(t);this.isScheduled||(this.isScheduled=!0,queueMicrotask(()=>{Ie.isScheduled||Ie.isFlushing||this.flush()}))}flush(){for(this.nextPendingComponents.size>0&&(this.nextPendingComponents.forEach(t=>this.pendingComponents.add(t)),this.nextPendingComponents.clear()),this._isFlushing=!0,this._flushVersion++;this.pendingComponents.size>0;){const t=Array.from(this.pendingComponents);this.pendingComponents.clear(),t.sort((t,e)=>t._depth-e._depth),this._currentWave=new Set(t);for(const e of t)if(e.isConnected)try{e._render()}catch(t){le(t,"Component render")}this._currentWave.clear()}this._isFlushing=!1,this.isScheduled=!1,this.nextPendingComponents.size>0?(this.isScheduled=!0,queueMicrotask(()=>{Ie.isScheduled||Ie.isFlushing||this.flush()})):this._drainIdleCallbacks()}},ze=()=>{if(te.templateInProgress&&!te.setupInProgress)throw Error("Providers such as atoms, units, bubbles, getters, setters and actions can't be created inside the template function, you can create them in view function. Because template function gets called everytime the view updates.")},De=()=>{},Ne=t=>{ze(),t.__isOnMount__=!0;const e=we();e.addToCleanUps(t,De);if("AsyncFunction"===t.constructor.name&&Ce())return e._asyncMountQueue=e._asyncMountQueue??[],void e._asyncMountQueue.push(t);let n=!1;e.DOMReadyEvent.__subscribe(()=>{if(n)return;n=!0;const s=t();if(s&&"object"==typeof s&&"function"==typeof s.then)return;const i=s;i&&e.addToCleanUps(t,i)})},Le=(t,e=!0)=>{if(e&&ee("Setter"),te.setupInProgress&&e)throw new Error("Setter cannot be created inside setup function. Define setters as class properties before setup runs.");let n=t;const s=we();e&&ze();const i=new Set;try{const t=(...t)=>{const e=n(...t);return[...i].forEach(t=>{try{Ie.schedule(()=>t?.())}catch(t){console.error(t)}}),s?.isConnected&&Pe.schedule(s),e};return t.__subscribe=t=>(ee("subscribe"),i.add(t),()=>i.delete(t)),t.__isSetter___=!0,t.set=t=>{n=t},Object.defineProperty(t,"__version__",{get:()=>0}),t}catch(t){throw new Error("You can only use setter or _ inside a scope or useState or view component's outer function")}},je=Le;function Ue(t,e=!0,n){if(Ht())return;const s=we(e);if(s&&t&&!s.cleanups.has(t)){const e=n||t.__subscribe||t.subscribe,i=e?.(()=>{Pe.schedule(s)});s.addToCleanUps(t,i)}}const Fe=(t,e)=>{t.__isOn__=!0,ee("on");const n=new Set;let s;const i=()=>{if(s){try{s()}catch(t){console.error("Error in on() cleanup:",t)}s=void 0}const e=t();"function"==typeof e&&(s=e)},o=()=>Ie.schedule(i);e.forEach(t=>{n.add(t.__subscribe(o))});const r=()=>{if(n.forEach(t=>t()),s){try{s()}catch(t){console.error("Error in on() cleanup:",t)}s=void 0}};return ve(t,r),r};function Ve(){return Re()&&"undefined"!=typeof window&&!!window.__mates_hmr}function We(t){return!!t&&("AsyncFunction"===t.constructor?.name||t instanceof Promise||"object"==typeof t&&null!==t&&"then"in t||"function"==typeof t.then)}function Be(t){return"function"==typeof t?t():t}function He(t){return t.default||t}class Ye extends HTMLElement{addScope(t,e){this.scopes.set(t,e)}onEachUpdate(t){this.onEachUpdateCallbacks.add(t)}constructor(){super(),this.name="Anonymous",this.scopes=new Map,this._useStates=[],this.lastVersion=-1,this._depth=0,this._parentComponent=null,this._renderVersion=0,this._errorHandlers=[],this._errorState=null,this.onEachUpdateCallbacks=new Set,this.DOMReadyEvent=null,this.PaintEvent=null,this._isViewLoading=!1,this._onRequestParentScope=t=>{const e=t,n=e.detail?.ScopeClass;if(n&&this.scopes.has(n)){const t=this.scopes.get(n);t&&(e.stopPropagation(),e.detail.resolve(t))}},this._props={},this._propsFn=()=>this._props,this._view=null,this._templateFn=null,this._hasMounted=!1,this._renderScheduled=!1,this.componentId=Math.random(),this.cleanups=new Map,this._xviewRender=()=>{};const t=te.templateInProgress;te.templateInProgress=!1,ye(this,()=>{this.DOMReadyEvent=xe("DOMReady"),this.PaintEvent=xe("Paint")}),te.templateInProgress=t,this._setup()}set props(t){this._props=t,Pe.schedule(this)}get props(){return this._props}_applyViewChange(t,e){this.oldView!==t&&(this.oldView=t,e(t),(this._hasMounted||this._errorState)&&Te(this))}set view(t){if(null!==t){if(We(t))return this._isViewLoading=!0,void Be(t).then(t=>{this._isViewLoading=!1,this.view=He(t)},t=>{this._isViewLoading=!1,this._handleRenderError(t)});"function"==typeof t&&(this.name=t.name||"Anonymous"),this._applyViewChange(t,()=>{this._view=t}),Pe.schedule(this)}}get view(){return this._view}callOnEachUpdate(){this.onEachUpdateCallbacks.forEach(t=>t())}connectedCallback(){this.addEventListener("request-parent-scope",this._onRequestParentScope);let t=0,e=null,n=this.parentElement;for(;n;){if(n instanceof Ye){e=n,t=n._depth+1;break}n=n.parentElement}if(this._depth=t,this._parentComponent=e,Oe.cancelDisconnect(this),this._hasMounted)return Ft()&&!this._view?.skipDevToolsRender&&Nt(this,this._view),void Pe.schedule(this);this._setup()}_setup(){if(this._hasMounted)return;let t=0,e=null,n=this.parentElement;for(;n;){if(n instanceof Ye){e=n,t=n._depth+1;break}n=n.parentElement}this._depth=t,this._parentComponent=e,"function"==typeof this._view&&this._mountComponent()}disconnectedCallback(){var t,e,n;this.removeEventListener("request-parent-scope",this._onRequestParentScope),Ft()&&(this._view?.__devtools__||this._view?.skipDevToolsRender||(n=Lt(this),Dt.logComponentUnmount(n)),this._view?.skipDevToolsRender||(t=this,e=this._view,Dt.unregisterComponent(t,e))),Oe.scheduleDisconnect(this)}addToCleanUps(t,e){const n=this.cleanups.get(t);n?n.push(e):this.cleanups.set(t,[e])}_render(){var t,e,n;if(!(this._errorState&&!this._view?.__isErrorView__||this._isViewLoading||this._renderScheduled)&&this._view)if(this._renderVersion=Pe.flushVersion,this._hasMounted){if(this._xviewRender){this.callOnEachUpdate();let s=0;if(Ft()){const i=this._view?.__devtools__,o=this._view?.skipDevToolsRender,r=performance.now();this._xviewRender(),s=performance.now()-r,i||o||(Ut(Lt(this),this.componentId,s),e=Lt(this),n=s,Dt.logComponentRender(e,n)),o||(t=this,Dt.notifyRender(t))}else this._xviewRender()}}else this._mountComponent()}_mountComponent(){const t=this._view,e=function(t){if(!Ve())return t;const e=t?.__mates_hmr_id;if(!e)return t;const n=window.__mates_hmr?.components;return n?.[e]??t}(t);F(x``,this),te.viewOuterInProgress=!0;try{this._templateFn=ye(this,()=>e(this._propsFn))}catch(t){return te.viewOuterInProgress=!1,void this._handleRenderError(t)}if(te.viewOuterInProgress=!1,"function"==typeof this._templateFn){if(this._xviewRender=()=>{te.templateInProgress=!0;try{if(!this._templateFn)return;ye(this,()=>{const t=this._templateFn(this._propsFn);F(t,this)}),this.DOMReadyEvent?.trigger(),this.PaintEvent?.hasSubscribers&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.isConnected&&this.PaintEvent?.trigger()})})}catch(t){this._handleRenderError(t)}finally{te.templateInProgress=!1}},this.callOnEachUpdate(),Ft()){const t=e?.__devtools__,n=e?.skipDevToolsRender,s=performance.now();this._xviewRender();const i=performance.now()-s;t||n||Ut(e?.name||"Anonymous",this.componentId,i)}else this._xviewRender();this._view===t&&(this._hasMounted=!0,Ft()&&(e?.skipDevToolsRender||Nt(this,e),e?.__devtools__||e?.skipDevToolsRender||(n=e?.name||"Anonymous",Dt.logComponentMount(n))))}else this._handleRenderError(new Error("inner function must be a template function that returns html result"));var n}_hotRefresh(){Te(this),Pe.schedule(this)}_handleRenderError(t){this._errorState=t;for(const e of this._errorHandlers)try{e(t)}catch(t){}if(le(t,`Component "${this.name}"`),this._view?.__isErrorView__)return;const e=this.name,n=t instanceof Error?t.message:String(t),s=t instanceof Error&&t.stack?t.stack.split("\n").slice(1).map(t=>t.trim()).filter(Boolean).join("\n"):null,i=()=>()=>x`
|
|
75
75
|
<div
|
|
76
76
|
style="padding:14px 16px;margin:4px;border:2px solid #e74c3c;border-radius:6px;background:#fdf0ef;color:#c0392b;font-family:monospace;font-size:13px;line-height:1.5"
|
|
77
77
|
>
|