lume-js 2.3.0 → 2.3.1

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.
@@ -1,2 +1,2 @@
1
- var Lume=function(e){"use strict";function t(e,...t){void 0!==console&&"function"==typeof console.warn&&console.warn(e,...t)}function o(e,...t){void 0!==console&&"function"==typeof console.error&&console.error(e,...t)}const n=100;let r=0;const s=new Set,i=new Set,c=Symbol.for("lume.reactive");function a(e,t){i.add(e);try{return t()}finally{i.delete(e)}}const l=e=>({attr:"data-"+e,apply(t,o){t[e]=!!o}}),u=e=>({attr:"data-"+e,apply(t,o){t.setAttribute(e,o?"true":"false")}}),f=[l("hidden"),l("disabled"),l("checked"),l("required"),u("aria-expanded"),u("aria-hidden")];function d(e,t,o,n){const r=h(t,o);if(!r)return null;const{target:s,key:i}=r;return s.$subscribe(i,t=>n.apply(e,t))}function p(e,t,o,n){const r=h(t,o);if(!r)return null;const{target:s,key:i}=r,c=s.$subscribe(i,t=>b(e,t));return function(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName||"SELECT"===e.tagName}(e)&&n.set(e,{target:s,key:i}),c}function h(e,o){if(!o)return null;const n=o.split("."),r=n.pop(),s=function(e,t){if(!t||0===t.length)return e;let o=e;for(let n=0;n<t.length;n++){const e=t[n];if(null==o)return null;if(!(e in o))return null;o=o[e]}return o}(e,n);return null==s?(t(`[Lume.js] Invalid path "${o}"`),null):s?.$subscribe?{target:s,key:r}:(t(`[Lume.js] Target for "${o}" is not reactive`),null)}function b(e,t){"INPUT"===e.tagName?"checkbox"===e.type?e.checked=!!t:"radio"===e.type?e.checked=e.value===t+"":e.value=t??"":"TEXTAREA"===e.tagName||"SELECT"===e.tagName?e.value=t??"":e.textContent=t??""}let g=null;function y(e,t){if("function"!=typeof e)throw Error("effect() requires a function");const n=[];let r=!1;const s=()=>{if(!r){r=!0;try{e()}catch(t){throw o("[Lume.js effect] Error in effect:",t),t}finally{r=!1}}};if(Array.isArray(t)){let e=!1,o=!1;n.push(()=>{o=!0});const r=()=>{e||(e=!0,queueMicrotask(()=>{if(e=!1,!o)try{s()}catch{}}))};for(const s of t)if(Array.isArray(s)&&s.length>=2){const[e,...t]=s;if(e&&"function"==typeof e.$subscribe)for(const o of t){let t=!0;const s=e.$subscribe(o,()=>{t?t=!1:r()});n.push(s)}}s()}else{const t=()=>{if(r)return;const s=n.splice(0),i={fn:e,cleanups:n,execute:t,tracking:new WeakMap},c=g;g=i,r=!0;try{a((e,t,o)=>{if(g!==i)return;let n=i.tracking.get(e);n||(n=new Set,i.tracking.set(e,n)),n.has(t)||(n.add(t),i.cleanups.push(o(t,i.execute)))},e)}catch(l){throw n.length=0,n.push(...s),o("[Lume.js effect] Error in effect:",l),l}finally{g=c,r=!1}if(n.length>0)for(const e of s)e();else n.push(...s)};t()}return()=>{for(;n.length;)n.pop()()}}function m(e){const t=[],o=e=>{const o=e.getAttribute("data-bind");t.push({node:e,path:o,keys:"$item"===o||"$index"===o?null:o.split(".")})};e.hasAttribute("data-bind")&&o(e);for(const n of e.querySelectorAll("[data-bind]"))o(n);return t}function w(e,t,o){for(const n of e){let e;if("$index"===n.path)e=o;else if("$item"===n.path)e=t;else{e=t;for(let t=0;t<n.keys.length&&null!=e;t++)e=e[n.keys[t]]}b(n.node,e)}}function v(e){const t=document.activeElement;if(!e.contains(t))return null;let o=null,n=null;return"INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName||(o=t.selectionStart,n=t.selectionEnd),()=>{document.body.contains(t)&&(t.focus(),null!==o&&null!==n&&t.setSelectionRange(o,n))}}function E(e,t={}){const{isReorder:o=!1}=t,n=e.scrollTop;if(0===n)return()=>{e.scrollTop=0};let r=null,s=0;if(!o){const t=e.getBoundingClientRect();for(let o=e.firstElementChild;o;o=o.nextElementSibling){const e=o.getBoundingClientRect();if(e.bottom>t.top){r=o,s=e.top-t.top;break}}}return()=>{if(r&&document.body.contains(r)){const t=r.getBoundingClientRect(),o=e.getBoundingClientRect(),n=t.top-o.top-s;e.scrollTop=e.scrollTop+n}else e.scrollTop=n}}let j=!0,$=null;const k=new Map;function L(e){return null===$||("string"==typeof $?e.includes($):!($ instanceof RegExp)||$.test(e))}function S(e,t,o){const n=function(e){return k.has(e)||k.set(e,{gets:new Map,sets:new Map,notifies:new Map}),k.get(e)}(e),r=n[t];r.set(o,(r.get(o)||0)+1)}function A(e){try{const t=JSON.stringify(e);return t.length>100?t.slice(0,97)+"...":t}catch{return e+""}}const O={enable(){j=!0,console.log("%c[lume-debug]%c Logging enabled","color: #888; font-weight: bold","color: #4CAF50")},disable(){j=!1,console.log("%c[lume-debug]%c Logging disabled","color: #888; font-weight: bold","color: #F44336")},isEnabled:()=>j,filter(e){$=e,console.log(null===e?"%c[lume-debug]%c Filter cleared":"%c[lume-debug]%c Filter set: "+e,"color: #888; font-weight: bold","color: inherit")},getFilter:()=>$,stats(){const e={};for(const[t,o]of k)e[t]={gets:Object.fromEntries(o.gets),sets:Object.fromEntries(o.sets),notifies:Object.fromEntries(o.notifies)};return e},logStats(){const e=this.stats();if(0===Object.keys(e).length)return console.log("%c[lume-debug]%c No stats collected yet","color: #888; font-weight: bold","color: inherit"),e;console.group("%c[lume-debug] Statistics","color: #888; font-weight: bold");for(const[t,o]of Object.entries(e)){console.group("%c"+t,"color: #2196F3; font-weight: bold");const e=[],n=new Set([...Object.keys(o.gets),...Object.keys(o.sets),...Object.keys(o.notifies)]);for(const t of n)e.push({key:t,gets:o.gets[t]||0,sets:o.sets[t]||0,notifies:o.notifies[t]||0});e.length>0&&console.table(e),console.groupEnd()}return console.groupEnd(),e},resetStats(){k.clear(),console.log("%c[lume-debug]%c Stats reset","color: #888; font-weight: bold","color: inherit")}};function T(e,t){const o={};for(const n of t)o[n]=e[n];return JSON.stringify(o)}const x={attr:"data-show",apply(e,t){e.hidden=!t}},M={attr:"data-classname",apply(e,t){e.className=t||""}};function N(e){return{attr:"data-"+e,apply(t,o){t.toggleAttribute(e,!!o)}}}function F(e){const t=e.startsWith("aria-")?e:"aria-"+e;return{attr:"data-"+t,apply(e,o){e.setAttribute(t,o?"true":"false")}}}const q=/^(javascript|vbscript|data\s*:\s*text\/html)/i,C=new Set(["href","src","action","srcset","poster","formaction"]);function P(e){return{attr:"data-"+e,apply(t,o){if(null==o)return void t.removeAttribute(e);const n=o+"";C.has(e)&&q.test(n)?t.removeAttribute(e):t.setAttribute(e,n)}}}const R=new WeakMap,z=["readonly","open","novalidate","formnovalidate","multiple","autofocus","autoplay","controls","loop","muted","defer","async","reversed","selected","inert","allowfullscreen"],I=["href","src","alt","title","placeholder","action","method","target","rel","type","name","role","lang","tabindex","pattern","min","max","step","minlength","maxlength","width","height","for","form","accept","autocomplete","loading","decoding","inputmode","enterkeyhint","draggable","contenteditable","spellcheck","translate","dir","id","poster","preload","download","media","sizes","srcset","colspan","rowspan","scope","headers","wrap","sandbox"],B=["pressed","selected","disabled","checked","invalid","required","busy","modal","multiselectable","multiline","readonly","atomic"],W=["current","live","relevant","haspopup","sort","autocomplete","orientation","label","describedby","labelledby","controls","owns","activedescendant","errormessage","details","flowto","valuenow","valuemin","valuemax","valuetext","colcount","colindex","colspan","rowcount","rowindex","rowspan","level","setsize","posinset","placeholder","roledescription","keyshortcuts","braillelabel","brailleroledescription"],_=[N("readonly")],D=[F("pressed"),F("selected"),F("disabled")];return e.a11yHandlers=D,e.ariaAttr=F,e.batch=function(e){if("function"!=typeof e)throw Error("batch() requires a function");if(r>0)return e();let i;r++;try{return i=e(),i&&"function"==typeof i.then&&t("[Lume.js batch] batch() received an async function. Only writes before the first await are batched; later writes flush via normal microtasks."),i}finally{try{!function(){let e=0;for(;s.size>0&&n>e;){e++;const n=Array.from(s);s.clear();const r=new Set;for(const e of n){e.runBeforeFlushHooks(),e.notifySubscribers();for(const t of e.takeEffects())r.add(t)}for(const e of r)try{e()}catch(t){o("[Lume.js state] Error in effect:",t)}}n>e||(s.clear(),o("[Lume.js state] Maximum batch flush iterations reached (100). This usually indicates an infinite loop caused by an effect or computed mutating state it depends on."))}()}finally{r--}}},e.bindDom=function(e,t,o={}){if(!(e instanceof HTMLElement))throw Error("bindDom() requires a valid HTMLElement as root");if(!t||"object"!=typeof t)throw Error("bindDom() requires a reactive state object");const{immediate:n=!1,handlers:r=[]}=o,s=function(e,t){if(!t.length)return e;const o=new Map;for(const n of e)o.set(n.attr,n);for(const n of t.flat())o.set(n.attr,n);return[...o.values()]}(f,r),i=()=>{const o=[],n=new WeakMap,r=["[data-bind]",...s.map(e=>`[${e.attr}]`)].join(","),i=e.querySelectorAll(r);for(const e of i){if(e.hasAttribute("data-bind")){const r=p(e,t,e.getAttribute("data-bind"),n);r&&o.push(r)}for(const n of s)if(e.hasAttribute(n.attr)){const r=d(e,t,e.getAttribute(n.attr),n);r&&o.push(r)}}const c=e=>{const t=n.get(e.target);var o;t&&(t.target[t.key]="checkbox"===(o=e.target).type?o.checked:"number"===o.type||"range"===o.type?o.valueAsNumber:o.value)};return e.addEventListener("input",c),o.push(()=>e.removeEventListener("input",c)),()=>o.forEach(e=>e())};if(!n&&"loading"===document.readyState){let e=null;const t=()=>{e=i()};return document.addEventListener("DOMContentLoaded",t,{once:!0}),()=>e?e():document.removeEventListener("DOMContentLoaded",t)}return i()},e.boolAttr=N,e.className=M,e.classToggle=function(...e){return e.map(e=>({attr:"data-class-"+e,apply(t,o){t.classList.toggle(e,!!o)}}))},e.computed=function(e){if("function"!=typeof e)throw Error("computed() requires a function");let t,n=!1,r=!1,s=!1;const i=[],c=y(()=>{if(!r&&!s){r=!0;try{const o=e();n&&Object.is(o,t)||(t=o,n=!0,i.forEach(e=>e(t)))}catch(c){o("[Lume.js computed] Error in computation:",c),n&&void 0===t||(t=void 0,n=!0,i.forEach(e=>e(t)))}finally{queueMicrotask(()=>{s||(r=!1)})}}});return{get value(){if(!n)throw Error("Computed value accessed before initialization");return t},subscribe(e){if("function"!=typeof e)throw Error("subscribe() requires a function");return i.push(e),n&&e(t),()=>{const t=i.indexOf(e);t>-1&&i.splice(t,1)}},dispose(){s=!0,c(),i.length=0,n=!1,r=!1}}},e.createCleanupGroup=function(){const e=[];return{add(t){"function"==typeof t&&e.push(t)},dispose(){for(;e.length;){const o=e.pop();try{o()}catch(t){}}}}},e.createDebugPlugin=function(e={}){const t=e.label??"store",o=(t,o)=>{const n=e[t];return void 0!==n?n:o};return{name:"debug:"+t,onInit:()=>{j&&console.log(`%c[${t}]%c initialized`,"color: #888; font-weight: bold","color: inherit")},onGet:(e,n)=>("string"==typeof e&&e.startsWith("$")||(S(t,"gets",e),j&&o("logGet",!1)&&L(e)&&console.log(`%c[${t}]%c GET %c${e}%c = ${A(n)}`,"color: #888; font-weight: bold","color: #4CAF50","color: #2196F3; font-weight: bold","color: inherit")),n),onSet:(e,n,r)=>("string"==typeof e&&e.startsWith("$")||(S(t,"sets",e),j&&o("logSet",!0)&&L(e)&&(console.log(`%c[${t}]%c SET %c${e}%c: ${A(r)} → ${A(n)}`,"color: #888; font-weight: bold","color: #FF9800","color: #2196F3; font-weight: bold","color: inherit"),o("trace",!1)&&console.trace(`%c[${t}] Stack trace for ${e}`,"color: #888"))),n),onSubscribe:e=>{j&&L(e)&&console.log(`%c[${t}]%c SUBSCRIBE %c${e}`,"color: #888; font-weight: bold","color: #9C27B0","color: #2196F3; font-weight: bold")},onNotify:(e,n)=>{"string"==typeof e&&e.startsWith("$")||(S(t,"notifies",e),j&&o("logNotify",!0)&&L(e)&&console.log(`%c[${t}]%c NOTIFY %c${e}%c = ${A(n)}`,"color: #888; font-weight: bold","color: #E91E63","color: #2196F3; font-weight: bold","color: inherit"))}}},e.debug=O,e.defaultFocusPreservation=v,e.defaultScrollPreservation=E,e.effect=y,e.formHandlers=_,e.htmlAttrs=function(){return[x,...z.map(e=>N(e)),...I.map(e=>P(e)),...B.map(e=>F(e)),...W.map(e=>P("aria-"+e))]},e.hydrateState=function(e="#__LUME_DATA__",t){const o="undefined"!=typeof document?document.querySelector(e):null;if(!o)return{};if("SCRIPT"!==o.tagName||"application/json"!==o.type)return{};let n;try{n=JSON.parse(o.textContent)}catch{return{}}return"function"!=typeof t||t(n)?n:{}},e.isReactive=function(e){return!(!e||"object"!=typeof e||!(c in e)&&"function"!=typeof e.$subscribe)},e.on=function(...e){return e.map(e=>({attr:"data-on"+e,apply(o,n){let r=R.get(o);const s=r?r.get(e):void 0;s&&(o.removeEventListener(e,s),r.delete(e)),"function"==typeof n?(o.addEventListener(e,n),r||(r=new Map,R.set(o,r)),r.set(e,n)):null!=n&&t(`[Lume.js] on('${e}'): bound value is not a function — listener detached`)}}))},e.persist=function(e,o,n={}){if(!e||"function"!=typeof e.$subscribe)throw Error("[Lume.js] persist() requires a reactive store from state()");if("string"!=typeof o||0===o.length)throw Error("[Lume.js] persist() requires a non-empty storage key");const r=void 0!==n.storage?n.storage:globalThis.localStorage;if(!r||"function"!=typeof r.getItem)return t("[Lume.js] persist(): no storage available — persistence disabled"),()=>{};const s=Array.isArray(n.keys)&&n.keys.length>0?n.keys.slice():Object.keys(e).filter(e=>!e.startsWith("$")),i=function(e,o){try{const t=e.getItem(o);if(!t)return null;const n=JSON.parse(t);return n&&"object"==typeof n&&!Array.isArray(n)?n:null}catch{return t(`[Lume.js] persist(): could not read "${o}" — starting fresh`),null}}(r,o);if(i)for(const t of s)Object.prototype.hasOwnProperty.call(i,t)&&(e[t]=i[t]);let c=null;try{c=T(e,s)}catch{}let a=!1,l=!1;const u=()=>{if(a=!1,l)return;let n;try{n=T(e,s)}catch(i){return void t("[Lume.js] persist(): state not serializable — skipping save",i)}if(n!==c)try{r.setItem(o,n),c=n}catch(i){t("[Lume.js] persist(): could not write — storage full or unavailable?",i)}},f=s.map(t=>{let o=!0;return e.$subscribe(t,()=>{o?o=!1:a||(a=!0,queueMicrotask(u))})});return()=>{for(l=!0;f.length;)f.pop()()}},e.repeat=function(e,n,r,s){const{key:i,render:c,create:a,update:l,remove:u,template:f=null,element:d="div",preserveFocus:p=v,preserveScroll:h=E}=s,b="string"==typeof e?document.querySelector(e):e;if(!b)return t(`[Lume.js] repeat(): container "${e}" not found`),()=>{};if("function"!=typeof i)throw Error("[Lume.js] repeat(): options.key must be a function");const g=f?function(e,t){let o=e;if(!0===e?o=t.querySelector("template"):"string"==typeof e&&(o=document.querySelector(e)),!o||"TEMPLATE"!==o.tagName)throw Error("[Lume.js] repeat(): template not found or not a <template> element");if(1!==o.content.children.length)throw Error("[Lume.js] repeat(): template must contain exactly one root element");return o.content.firstElementChild}(f,b):null;if(g&&"function"==typeof c&&t("[Lume.js] repeat(): options.render is ignored when options.template is set — use create/update instead"),!g&&"function"!=typeof c&&"function"!=typeof a)throw Error("[Lume.js] repeat(): options.render or options.create must be a function");const y=new Map,j=new Map,$=new Map,k=new Map,L=new Map,S=new Set;function A(){return g?g.cloneNode(!0):"function"==typeof d?d():document.createElement(d)}function O(){const e=n[r];if(!Array.isArray(e))return void t(`[Lume.js] repeat(): store.${r} is not an array`);let s=!1;if(h&&y.size===e.length){s=!0;for(let t=0;t<e.length;t++)if(!y.has(i(e[t]))){s=!1;break}}S.clear();const f=[];for(let n=0;n<e.length;n++){const r=e[n],s=i(r);if(S.has(s)){t(`[Lume.js] repeat(): duplicate key "${s}"`);continue}S.add(s);let u=y.get(s);const p=!u;p&&(u=A(),y.set(s,u),g&&L.set(s,m(u)));try{if(p&&a){const e=a(r,u,n);"function"==typeof e&&k.set(s,e)}const e=j.get(s),t=$.get(s);g?e===r&&t===n||(w(L.get(s),r,n),l&&l(r,u,n,{isFirstRender:p})):l?e===r&&t===n||l(r,u,n,{isFirstRender:p}):c&&c(r,u,n),j.set(s,r),$.set(s,n)}catch(d){o(`[Lume.js] repeat(): error rendering key "${s}":`,d)}f.push(u)}!function(e,t,n){const r=document.body.contains(e),s=r&&p?p(e):null,i=r&&h?h(e,{isReorder:n}):null;(()=>{if(function(e,t){let o=e.firstChild;for(let n=0;n<t.length;n++){const r=t[n];o!==r?e.insertBefore(r,o):o=o.nextSibling}for(;o;){const t=o.nextSibling;e.removeChild(o),o=t}}(b,f),y.size!==S.size)for(const e of y.keys())if(!S.has(e)){const t=y.get(e),n=j.get(e),r=k.get(e);if("function"==typeof r)try{r()}catch(d){o(`[Lume.js] repeat(): cleanup error for key "${e}":`,d)}"function"==typeof u&&t&&u(n,t),y.delete(e),j.delete(e),$.delete(e),k.delete(e),L.delete(e)}})(),s&&s(),i&&i()}(b,0,s)}let T;if("function"==typeof n.$subscribe)T=n.$subscribe(r,O);else{if("function"!=typeof n.subscribe)return O(),t("[Lume.js] repeat(): store is not reactive (no $subscribe or subscribe method)"),()=>{for(const[t,n]of y){const r=j.get(t),s=k.get(t);if("function"==typeof s)try{s()}catch(e){o(`[Lume.js] repeat(): cleanup error for key "${t}":`,e)}"function"==typeof u&&u(r,n)}b.replaceChildren(),y.clear(),j.clear(),$.clear(),k.clear(),L.clear(),S.clear()};{const e=n.subscribe(()=>O());O(),T="function"==typeof e?e:()=>{e?.unsubscribe?.()}}}return()=>{"function"==typeof T&&T();for(const[t,n]of y){const r=j.get(t),s=k.get(t);if("function"==typeof s)try{s()}catch(e){o(`[Lume.js] repeat(): cleanup error for key "${t}":`,e)}"function"==typeof u&&u(r,n)}b.replaceChildren(),y.clear(),j.clear(),$.clear(),k.clear(),L.clear(),S.clear()}},e.show=x,e.state=function(e){if(!e||"object"!=typeof e||Array.isArray(e))throw Error("state() requires a plain object");if(Object.isFrozen(e)||Object.isSealed(e))throw Error("state() requires a mutable plain object");const a=Object.create(null),l=new Map,u=new Set,f=[];let d=!1;function p(){for(let t=0;t<f.length;t++)try{f[t]()}catch(e){o("[Lume.js state] Error in beforeFlush hook:",e)}}function h(){for(const[t,n]of l)if(a[t]){const r=a[t];let s=0;for(;s<r.length;){const i=r[s];try{i(n)}catch(e){o(`[Lume.js state] Error notifying subscriber for key "${t+""}":`,e)}r[s]===i&&s++}}l.clear()}function b(){const e=Array.from(u);return u.clear(),e}const g={runBeforeFlushHooks:p,notifySubscribers:h,takeEffects:b};Object.defineProperty(e,c,{value:!0});const y=()=>{};function m(e,t,n){return a[e]||(a[e]=[]),1e3>a[e].length?(a[e].push(t),()=>{if(a[e]){const o=a[e].indexOf(t);-1!==o&&(a[e].splice(o,1),0===a[e].length&&delete a[e])}}):(o(`[Lume.js state] Subscriber limit (1000) reached for key "${e+""}". ${n} ignored — it will NOT receive updates. This usually means subscriptions are created in a loop without cleanup.`),y)}const w=(e,t)=>m(e,()=>{u.add(t)},"Effect subscription"),v=new Set(["__proto__","constructor","prototype"]),E=new Proxy(e,{get(e,t){if("string"==typeof t&&t.startsWith("$"))return e[t];const o=e[t];if(i.size>0)for(const n of i)n(E,t,w);return o},set(e,i,c){if("string"==typeof i&&v.has(i))return t(`[Lume.js state] Blocked write to reserved key "${i}"`),!0;const a=e[i];return Object.is(a,c)||(e[i]=c,l.set(i,c),f=g,(0===r||(s.add(f),0))&&(d||(d=!0,queueMicrotask(()=>{let e=0;try{for(;(l.size>0||u.size>0)&&n>e;){e++,p(),h();const n=b();for(let e=0;e<n.length;e++)try{n[e]()}catch(t){o("[Lume.js state] Error in effect:",t)}}}finally{d=!1}n>e||o("[Lume.js state] Maximum flush iterations reached (100). This usually indicates an infinite loop caused by an effect or computed mutating state it depends on.")})))),!0;var f}});return e.$beforeFlush=e=>{if("function"!=typeof e)throw Error("$beforeFlush requires a function");return-1===f.indexOf(e)&&f.push(e),()=>{const t=f.indexOf(e);-1!==t&&f.splice(t,1)}},e.$subscribe=(e,t)=>{if("function"!=typeof t)throw Error("Subscriber must be a function");const o=m(e,t,"New subscriber");return o===y||t(E[e]),o},E},e.stringAttr=P,e.watch=function(e,t,o,{immediate:n=!0}={}){if(!e.$subscribe)throw Error("store must be created with state()");if(!n){let n=!1;return e.$subscribe(t,e=>{n?o(e):n=!0})}return e.$subscribe(t,o)},e.withPlugins=function(e,t=[]){if(!t.length)return e;for(const i of t){try{i.onInit?.()}catch(s){o(`[Lume.js] Plugin "${i.name}" error in onInit:`,s)}Object.freeze(i)}const n=new Map;let r;return"function"==typeof e.$beforeFlush&&(r=e.$beforeFlush(function(){for(const[e,r]of n)for(const n of t)try{n.onNotify?.(e,r)}catch(s){o(`[Lume.js] Plugin "${n.name}" error in onNotify:`,s)}n.clear()})),new Proxy(e,{get(e,i){if("$dispose"===i)return()=>{r&&r(),n.clear()};if("string"==typeof i&&i.startsWith("$")){const n=e[i];return"$subscribe"===i&&"function"==typeof n?(e,r)=>{for(const n of t)try{n.onSubscribe?.(e)}catch(s){o(`[Lume.js] Plugin "${n.name}" error in onSubscribe:`,s)}return n(e,r)}:n}let c=e[i];for(const n of t)try{const e=n.onGet?.(i,c);void 0!==e&&(c=e)}catch(s){o(`[Lume.js] Plugin "${n.name}" error in onGet:`,s)}return c},set(e,r,i){const c=e[r];let a=i;for(const n of t)try{const e=n.onSet?.(r,a,c);void 0!==e&&(a=e)}catch(s){o(`[Lume.js] Plugin "${n.name}" error in onSet:`,s)}return Object.is(a,c)||n.set(r,a),e[r]=a,!0}})},e.withReadObserver=a,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
1
+ var Lume=function(e){"use strict";function t(e,...t){void 0!==console&&"function"==typeof console.warn&&console.warn(e,...t)}function o(e,...t){void 0!==console&&"function"==typeof console.error&&console.error(e,...t)}const n=100;let r=0;const s=new Set,i=new Set,c=Symbol.for("lume.reactive");function a(e,t){i.add(e);try{return t()}finally{i.delete(e)}}const l=e=>({attr:"data-"+e,apply(t,o){t[e]=!!o}}),u=e=>({attr:"data-"+e,apply(t,o){t.setAttribute(e,o?"true":"false")}}),f=[l("hidden"),l("disabled"),l("checked"),l("required"),u("aria-expanded"),u("aria-hidden")];function d(e,t,o,n){const r=h(t,o);if(!r)return null;const{target:s,key:i}=r;return s.$subscribe(i,t=>n.apply(e,t))}function p(e,t,o,n){const r=h(t,o);if(!r)return null;const{target:s,key:i}=r,c=s.$subscribe(i,t=>b(e,t));return function(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName||"SELECT"===e.tagName}(e)&&n.set(e,{target:s,key:i}),c}function h(e,o){if(!o)return null;const n=o.split("."),r=n.pop(),s=function(e,t){if(!t||0===t.length)return e;let o=e;for(let n=0;n<t.length;n++){const e=t[n];if(null==o)return null;if(!(e in o))return null;o=o[e]}return o}(e,n);return null==s?(t(`[Lume.js] Invalid path "${o}"`),null):s?.$subscribe?{target:s,key:r}:(t(`[Lume.js] Target for "${o}" is not reactive`),null)}function b(e,t){"INPUT"===e.tagName?"checkbox"===e.type?e.checked=!!t:"radio"===e.type?e.checked=e.value===t+"":e.value=t??"":"TEXTAREA"===e.tagName||"SELECT"===e.tagName?e.value=t??"":e.textContent=t??""}let g=null;function y(e,t){if("function"!=typeof e)throw Error("effect() requires a function");const n=[];let r=!1;const s=()=>{if(!r){r=!0;try{e()}catch(t){throw o("[Lume.js effect] Error in effect:",t),t}finally{r=!1}}};if(Array.isArray(t)){let e=!1,o=!1;n.push(()=>{o=!0});const r=()=>{e||(e=!0,queueMicrotask(()=>{if(e=!1,!o)try{s()}catch{}}))};for(const s of t)if(Array.isArray(s)&&s.length>=2){const[e,...t]=s;if(e&&"function"==typeof e.$subscribe)for(const o of t){let t=!0;const s=e.$subscribe(o,()=>{t?t=!1:r()});n.push(s)}}s()}else{const t=()=>{if(r)return;const s=n.splice(0),i={fn:e,cleanups:n,execute:t,tracking:new WeakMap},c=g;g=i,r=!0;try{a((e,t,o)=>{if(g!==i)return;let n=i.tracking.get(e);n||(n=new Set,i.tracking.set(e,n)),n.has(t)||(n.add(t),i.cleanups.push(o(t,i.execute)))},e)}catch(l){throw n.length=0,n.push(...s),o("[Lume.js effect] Error in effect:",l),l}finally{g=c,r=!1}if(n.length>0)for(const e of s)e();else n.push(...s)};t()}return()=>{for(;n.length;)n.pop()()}}function m(e){const t=[],o=e=>{const o=e.getAttribute("data-bind");t.push({node:e,path:o,keys:"$item"===o||"$index"===o?null:o.split(".")})};e.hasAttribute("data-bind")&&o(e);for(const n of e.querySelectorAll("[data-bind]"))o(n);return t}function w(e,t,o){for(const n of e){let e;if("$index"===n.path)e=o;else if("$item"===n.path)e=t;else{e=t;for(let t=0;t<n.keys.length&&null!=e;t++)e=e[n.keys[t]]}b(n.node,e)}}function v(e){const t=document.activeElement;if(!e.contains(t))return null;let o=null,n=null;return"INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName||(o=t.selectionStart,n=t.selectionEnd),()=>{document.body.contains(t)&&(t.focus(),null!==o&&null!==n&&t.setSelectionRange(o,n))}}function E(e,t={}){const{isReorder:o=!1}=t,n=e.scrollTop;if(0===n)return()=>{e.scrollTop=0};let r=null,s=0;if(!o){const t=e.getBoundingClientRect();for(let o=e.firstElementChild;o;o=o.nextElementSibling){const e=o.getBoundingClientRect();if(e.bottom>t.top){r=o,s=e.top-t.top;break}}}return()=>{if(r&&document.body.contains(r)){const t=r.getBoundingClientRect(),o=e.getBoundingClientRect(),n=t.top-o.top-s;e.scrollTop=e.scrollTop+n}else e.scrollTop=n}}let j=!0,$=null;const k=new Map;function L(e){return null===$||("string"==typeof $?e.includes($):!($ instanceof RegExp)||$.test(e))}function S(e,t,o){const n=function(e){return k.has(e)||k.set(e,{gets:new Map,sets:new Map,notifies:new Map}),k.get(e)}(e),r=n[t];r.set(o,(r.get(o)||0)+1)}function A(e){try{const t=JSON.stringify(e);return t.length>100?t.slice(0,97)+"...":t}catch{return e+""}}const O={enable(){j=!0,console.log("%c[lume-debug]%c Logging enabled","color: #888; font-weight: bold","color: #4CAF50")},disable(){j=!1,console.log("%c[lume-debug]%c Logging disabled","color: #888; font-weight: bold","color: #F44336")},isEnabled:()=>j,filter(e){$=e,console.log(null===e?"%c[lume-debug]%c Filter cleared":"%c[lume-debug]%c Filter set: "+e,"color: #888; font-weight: bold","color: inherit")},getFilter:()=>$,stats(){const e={};for(const[t,o]of k)e[t]={gets:Object.fromEntries(o.gets),sets:Object.fromEntries(o.sets),notifies:Object.fromEntries(o.notifies)};return e},logStats(){const e=this.stats();if(0===Object.keys(e).length)return console.log("%c[lume-debug]%c No stats collected yet","color: #888; font-weight: bold","color: inherit"),e;console.group("%c[lume-debug] Statistics","color: #888; font-weight: bold");for(const[t,o]of Object.entries(e)){console.group("%c"+t,"color: #2196F3; font-weight: bold");const e=[],n=new Set([...Object.keys(o.gets),...Object.keys(o.sets),...Object.keys(o.notifies)]);for(const t of n)e.push({key:t,gets:o.gets[t]||0,sets:o.sets[t]||0,notifies:o.notifies[t]||0});e.length>0&&console.table(e),console.groupEnd()}return console.groupEnd(),e},resetStats(){k.clear(),console.log("%c[lume-debug]%c Stats reset","color: #888; font-weight: bold","color: inherit")}};function x(e,t){const o={};for(const n of t)o[n]=e[n];return JSON.stringify(o)}const T=new WeakMap,N={attr:"data-show",apply(e,t){e.hidden=!t}},M={attr:"data-classname",apply(e,t){e.className=t||""}};function F(e){return{attr:"data-"+e,apply(t,o){t.toggleAttribute(e,!!o)}}}function C(e){const t=e.startsWith("aria-")?e:"aria-"+e;return{attr:"data-"+t,apply(e,o){e.setAttribute(t,o?"true":"false")}}}const q=/^(?:javascript:|vbscript:|data:text\/html)/,R=/[\u0000-\u0020\u007F]/g,P=new Set(["href","src","action","srcset","poster","formaction"]);function z(e){return{attr:"data-"+e,apply(t,o){if(null==o)return void t.removeAttribute(e);const n=o+"";P.has(e)&&q.test(n.replace(R,"").toLowerCase())?t.removeAttribute(e):t.setAttribute(e,n)}}}const I=new WeakMap,B=["readonly","open","novalidate","formnovalidate","multiple","autofocus","autoplay","controls","loop","muted","defer","async","reversed","selected","inert","allowfullscreen"],W=["href","src","alt","title","placeholder","action","method","target","rel","type","name","role","lang","tabindex","pattern","min","max","step","minlength","maxlength","width","height","for","form","accept","autocomplete","loading","decoding","inputmode","enterkeyhint","draggable","contenteditable","spellcheck","translate","dir","id","poster","preload","download","media","sizes","srcset","colspan","rowspan","scope","headers","wrap","sandbox"],_=["pressed","selected","disabled","checked","invalid","required","busy","modal","multiselectable","multiline","readonly","atomic"],D=["current","live","relevant","haspopup","sort","autocomplete","orientation","label","describedby","labelledby","controls","owns","activedescendant","errormessage","details","flowto","valuenow","valuemin","valuemax","valuetext","colcount","colindex","colspan","rowcount","rowindex","rowspan","level","setsize","posinset","placeholder","roledescription","keyshortcuts","braillelabel","brailleroledescription"],G=[F("readonly")],H=[C("pressed"),C("selected"),C("disabled")];return e.a11yHandlers=H,e.ariaAttr=C,e.batch=function(e){if("function"!=typeof e)throw Error("batch() requires a function");if(r>0)return e();let i;r++;try{return i=e(),i&&"function"==typeof i.then&&t("[Lume.js batch] batch() received an async function. Only writes before the first await are batched; later writes flush via normal microtasks."),i}finally{try{!function(){let e=0;for(;s.size>0&&n>e;){e++;const n=Array.from(s);s.clear();const r=new Set;for(const e of n){e.runBeforeFlushHooks(),e.notifySubscribers();for(const t of e.takeEffects())r.add(t)}for(const e of r)try{e()}catch(t){o("[Lume.js state] Error in effect:",t)}}n>e||(s.clear(),o("[Lume.js state] Maximum batch flush iterations reached (100). This usually indicates an infinite loop caused by an effect or computed mutating state it depends on."))}()}finally{r--}}},e.bindDom=function(e,t,o={}){if(!(e instanceof HTMLElement))throw Error("bindDom() requires a valid HTMLElement as root");if(!t||"object"!=typeof t)throw Error("bindDom() requires a reactive state object");const{immediate:n=!1,handlers:r=[]}=o,s=function(e,t){if(!t.length)return e;const o=new Map;for(const n of e)o.set(n.attr,n);for(const n of t.flat())o.set(n.attr,n);return[...o.values()]}(f,r),i=()=>{const o=[],n=new WeakMap,r=["[data-bind]",...s.map(e=>`[${e.attr}]`)].join(","),i=e.querySelectorAll(r);for(const e of i){if(e.hasAttribute("data-bind")){const r=p(e,t,e.getAttribute("data-bind"),n);r&&o.push(r)}for(const n of s)if(e.hasAttribute(n.attr)){const r=d(e,t,e.getAttribute(n.attr),n);r&&o.push(r)}}const c=e=>{const t=n.get(e.target);var o;t&&(t.target[t.key]="checkbox"===(o=e.target).type?o.checked:"number"===o.type||"range"===o.type?o.valueAsNumber:o.value)};return e.addEventListener("input",c),o.push(()=>e.removeEventListener("input",c)),()=>o.forEach(e=>e())};if(!n&&"loading"===document.readyState){let e=null;const t=()=>{e=i()};return document.addEventListener("DOMContentLoaded",t,{once:!0}),()=>e?e():document.removeEventListener("DOMContentLoaded",t)}return i()},e.boolAttr=F,e.className=M,e.classToggle=function(...e){return e.map(e=>({attr:"data-class-"+e,apply(t,o){t.classList.toggle(e,!!o)}}))},e.computed=function(e){if("function"!=typeof e)throw Error("computed() requires a function");let t,n=!1,r=!1,s=!1;const i=[],c=y(()=>{if(!r&&!s){r=!0;try{const o=e();n&&Object.is(o,t)||(t=o,n=!0,i.forEach(e=>e(t)))}catch(c){o("[Lume.js computed] Error in computation:",c),n&&void 0===t||(t=void 0,n=!0,i.forEach(e=>e(t)))}finally{queueMicrotask(()=>{s||(r=!1)})}}});return{get value(){if(!n)throw Error("Computed value accessed before initialization");return t},subscribe(e){if("function"!=typeof e)throw Error("subscribe() requires a function");return i.push(e),n&&e(t),()=>{const t=i.indexOf(e);t>-1&&i.splice(t,1)}},dispose(){s=!0,c(),i.length=0,n=!1,r=!1}}},e.createCleanupGroup=function(){const e=[];return{add(t){"function"==typeof t&&e.push(t)},dispose(){for(;e.length;){const o=e.pop();try{o()}catch(t){}}}}},e.createDebugPlugin=function(e={}){const t=e.label??"store",o=(t,o)=>{const n=e[t];return void 0!==n?n:o};return{name:"debug:"+t,onInit:()=>{j&&console.log(`%c[${t}]%c initialized`,"color: #888; font-weight: bold","color: inherit")},onGet:(e,n)=>("string"==typeof e&&e.startsWith("$")||(S(t,"gets",e),j&&o("logGet",!1)&&L(e)&&console.log(`%c[${t}]%c GET %c${e}%c = ${A(n)}`,"color: #888; font-weight: bold","color: #4CAF50","color: #2196F3; font-weight: bold","color: inherit")),n),onSet:(e,n,r)=>("string"==typeof e&&e.startsWith("$")||(S(t,"sets",e),j&&o("logSet",!0)&&L(e)&&(console.log(`%c[${t}]%c SET %c${e}%c: ${A(r)} → ${A(n)}`,"color: #888; font-weight: bold","color: #FF9800","color: #2196F3; font-weight: bold","color: inherit"),o("trace",!1)&&console.trace(`%c[${t}] Stack trace for ${e}`,"color: #888"))),n),onSubscribe:e=>{j&&L(e)&&console.log(`%c[${t}]%c SUBSCRIBE %c${e}`,"color: #888; font-weight: bold","color: #9C27B0","color: #2196F3; font-weight: bold")},onNotify:(e,n)=>{"string"==typeof e&&e.startsWith("$")||(S(t,"notifies",e),j&&o("logNotify",!0)&&L(e)&&console.log(`%c[${t}]%c NOTIFY %c${e}%c = ${A(n)}`,"color: #888; font-weight: bold","color: #E91E63","color: #2196F3; font-weight: bold","color: inherit"))}}},e.debug=O,e.defaultFocusPreservation=v,e.defaultScrollPreservation=E,e.effect=y,e.formHandlers=G,e.htmlAttrs=function(){return[N,...B.map(e=>F(e)),...W.map(e=>z(e)),..._.map(e=>C(e)),...D.map(e=>z("aria-"+e))]},e.hydrateState=function(e="#__LUME_DATA__",t){const o="undefined"!=typeof document?document.querySelector(e):null;if(!o)return{};if("SCRIPT"!==o.tagName||"application/json"!==o.type)return{};let n;try{n=JSON.parse(o.textContent)}catch{return{}}return"function"!=typeof t||t(n)?n:{}},e.isReactive=function(e){return!(!e||"object"!=typeof e||!(c in e)&&"function"!=typeof e.$subscribe)},e.on=function(...e){return e.map(e=>({attr:"data-on"+e,apply(o,n){let r=I.get(o);const s=r?r.get(e):void 0;s&&(o.removeEventListener(e,s),r.delete(e)),"function"==typeof n?(o.addEventListener(e,n),r||(r=new Map,I.set(o,r)),r.set(e,n)):null!=n&&t(`[Lume.js] on('${e}'): bound value is not a function — listener detached`)}}))},e.persist=function(e,o,n={}){if(!e||"function"!=typeof e.$subscribe)throw Error("[Lume.js] persist() requires a reactive store from state()");if("string"!=typeof o||0===o.length)throw Error("[Lume.js] persist() requires a non-empty storage key");const r=void 0!==n.storage?n.storage:function(){try{return"undefined"!=typeof localStorage?localStorage:void 0}catch{return}}();if(!r||"function"!=typeof r.getItem)return t("[Lume.js] persist(): no storage available — persistence disabled"),()=>{};const s=Array.isArray(n.keys)?n.keys.slice():Object.keys(e).filter(e=>!e.startsWith("$"));let i=T.get(r);i||(i=new Set,T.set(r,i));const c=!i.has(o);c?i.add(o):t(`[Lume.js] persist(): "${o}" is already managed by another persist() on this storage — instances will overwrite each other's data. Use a distinct key per store.`);const a=function(e,o){try{const t=e.getItem(o);if(!t)return null;const n=JSON.parse(t);return n&&"object"==typeof n&&!Array.isArray(n)?n:null}catch{return t(`[Lume.js] persist(): could not read "${o}" — starting fresh`),null}}(r,o);if(a)for(const t of s)Object.prototype.hasOwnProperty.call(a,t)&&(e[t]=a[t]);let l=null;try{l=x(e,s)}catch{}let u=!1,f=!1;const d=()=>{if(u=!1,f)return;let n;try{n=x(e,s)}catch(i){return void t("[Lume.js] persist(): state not serializable — skipping save",i)}if(n!==l)try{r.setItem(o,n),l=n}catch(i){t("[Lume.js] persist(): could not write — storage full or unavailable?",i)}},p=s.map(t=>{let o=!0;return e.$subscribe(t,()=>{o?o=!1:u||(u=!0,queueMicrotask(d))})});return()=>{for(f=!0,c&&i.delete(o);p.length;)p.pop()()}},e.repeat=function(e,n,r,s){const{key:i,render:c,create:a,update:l,remove:u,template:f=null,element:d="div",preserveFocus:p=v,preserveScroll:h=E}=s,b="string"==typeof e?document.querySelector(e):e;if(!b)return t(`[Lume.js] repeat(): container "${e}" not found`),()=>{};if("function"!=typeof i)throw Error("[Lume.js] repeat(): options.key must be a function");const{templateRoot:g,keepEl:y}=function(e,t){if(!e)return{templateRoot:null,keepEl:null};const o=function(e,t){let o=e;if(!0===e?o=t.querySelector("template"):"string"==typeof e&&(o=document.querySelector(e)),!o||"TEMPLATE"!==o.tagName)throw Error("[Lume.js] repeat(): template not found or not a <template> element");if(1!==o.content.children.length)throw Error("[Lume.js] repeat(): template must contain exactly one root element");return o}(e,t);let n=o;for(;n&&n.parentNode!==t;)n=n.parentNode;return{templateRoot:o.content.firstElementChild,keepEl:n}}(f,b);if(g&&"function"==typeof c&&t("[Lume.js] repeat(): options.render is ignored when options.template is set — use create/update instead"),!g&&"function"!=typeof c&&"function"!=typeof a)throw Error("[Lume.js] repeat(): options.render or options.create must be a function");const j=new Map,$=new Map,k=new Map,L=new Map,S=new Map,A=new Set;function O(){return g?g.cloneNode(!0):"function"==typeof d?d():document.createElement(d)}function x(){let e=b.firstChild;for(;e;){const t=e.nextSibling;e!==y&&b.removeChild(e),e=t}}function T(){const e=n[r];if(!Array.isArray(e))return void t(`[Lume.js] repeat(): store.${r} is not an array`);let s=!1;if(h&&j.size===e.length){s=!0;for(let t=0;t<e.length;t++)if(!j.has(i(e[t]))){s=!1;break}}A.clear();const f=[];for(let n=0;n<e.length;n++){const r=e[n],s=i(r);if(A.has(s)){t(`[Lume.js] repeat(): duplicate key "${s}"`);continue}A.add(s);let u=j.get(s);const p=!u;p&&(u=O(),j.set(s,u),g&&S.set(s,m(u)));try{if(p&&a){const e=a(r,u,n);"function"==typeof e&&L.set(s,e)}const e=$.get(s),t=k.get(s);g?e===r&&t===n||(w(S.get(s),r,n),l&&l(r,u,n,{isFirstRender:p})):l?e===r&&t===n||l(r,u,n,{isFirstRender:p}):c&&c(r,u,n),$.set(s,r),k.set(s,n)}catch(d){o(`[Lume.js] repeat(): error rendering key "${s}":`,d)}f.push(u)}!function(e,t,n){const r=document.body.contains(e),s=r&&p?p(e):null,i=r&&h?h(e,{isReorder:n}):null;(()=>{if(function(e,t){let o=e.firstChild;for(let n=0;n<t.length;n++){y&&o===y&&(o=o.nextSibling);const r=t[n];o!==r?e.insertBefore(r,o):o=o.nextSibling}for(;o;){const t=o.nextSibling;o!==y&&e.removeChild(o),o=t}}(b,f),j.size!==A.size)for(const e of j.keys())if(!A.has(e)){const t=j.get(e),n=$.get(e),r=L.get(e);if("function"==typeof r)try{r()}catch(d){o(`[Lume.js] repeat(): cleanup error for key "${e}":`,d)}"function"==typeof u&&t&&u(n,t),j.delete(e),$.delete(e),k.delete(e),L.delete(e),S.delete(e)}})(),s&&s(),i&&i()}(b,0,s)}let N;if("function"==typeof n.$subscribe)N=n.$subscribe(r,T);else{if("function"!=typeof n.subscribe)return T(),t("[Lume.js] repeat(): store is not reactive (no $subscribe or subscribe method)"),()=>{for(const[t,n]of j){const r=$.get(t),s=L.get(t);if("function"==typeof s)try{s()}catch(e){o(`[Lume.js] repeat(): cleanup error for key "${t}":`,e)}"function"==typeof u&&u(r,n)}x(),j.clear(),$.clear(),k.clear(),L.clear(),S.clear(),A.clear()};{const e=n.subscribe(()=>T());T(),N="function"==typeof e?e:()=>{e?.unsubscribe?.()}}}return()=>{"function"==typeof N&&N();for(const[t,n]of j){const r=$.get(t),s=L.get(t);if("function"==typeof s)try{s()}catch(e){o(`[Lume.js] repeat(): cleanup error for key "${t}":`,e)}"function"==typeof u&&u(r,n)}x(),j.clear(),$.clear(),k.clear(),L.clear(),S.clear(),A.clear()}},e.show=N,e.state=function(e){if(!e||"object"!=typeof e||Array.isArray(e))throw Error("state() requires a plain object");if(Object.isFrozen(e)||Object.isSealed(e))throw Error("state() requires a mutable plain object");const a=Object.create(null),l=new Map,u=new Set,f=[];let d=!1;function p(){for(let t=0;t<f.length;t++)try{f[t]()}catch(e){o("[Lume.js state] Error in beforeFlush hook:",e)}}function h(){const e=Array.from(l);l.clear();for(const[n,r]of e)if(a[n]){const e=a[n];let s=0;for(;s<e.length;){const i=e[s];try{i(r)}catch(t){o(`[Lume.js state] Error notifying subscriber for key "${n+""}":`,t)}e[s]===i&&s++}}}function b(){const e=Array.from(u);return u.clear(),e}const g={runBeforeFlushHooks:p,notifySubscribers:h,takeEffects:b};Object.defineProperty(e,c,{value:!0});const y=()=>{};function m(e,t,n){return a[e]||(a[e]=[]),1e3>a[e].length?(a[e].push(t),()=>{if(a[e]){const o=a[e].indexOf(t);-1!==o&&(a[e].splice(o,1),0===a[e].length&&delete a[e])}}):(o(`[Lume.js state] Subscriber limit (1000) reached for key "${e+""}". ${n} ignored — it will NOT receive updates. This usually means subscriptions are created in a loop without cleanup.`),y)}const w=(e,t)=>m(e,()=>{u.add(t)},"Effect subscription"),v=new Set(["__proto__","constructor","prototype"]),E=new Proxy(e,{get(e,t){if("string"==typeof t&&t.startsWith("$"))return e[t];const o=e[t];if(i.size>0)for(const n of i)n(E,t,w);return o},set(e,i,c){if("string"==typeof i&&v.has(i))return t(`[Lume.js state] Blocked write to reserved key "${i}"`),!0;const a=e[i];return Object.is(a,c)||(e[i]=c,l.set(i,c),f=g,(0===r||(s.add(f),0))&&(d||(d=!0,queueMicrotask(()=>{let e=0;try{for(;(l.size>0||u.size>0)&&n>e;){e++,p(),h();const n=b();for(let e=0;e<n.length;e++)try{n[e]()}catch(t){o("[Lume.js state] Error in effect:",t)}}}finally{d=!1}n>e||o("[Lume.js state] Maximum flush iterations reached (100). This usually indicates an infinite loop caused by an effect or computed mutating state it depends on.")})))),!0;var f}});return e.$beforeFlush=e=>{if("function"!=typeof e)throw Error("$beforeFlush requires a function");return-1===f.indexOf(e)&&f.push(e),()=>{const t=f.indexOf(e);-1!==t&&f.splice(t,1)}},e.$subscribe=(e,t)=>{if("function"!=typeof t)throw Error("Subscriber must be a function");const o=m(e,t,"New subscriber");return o===y||t(E[e]),o},E},e.stringAttr=z,e.watch=function(e,t,o,{immediate:n=!0}={}){if(!e.$subscribe)throw Error("store must be created with state()");if(!n){let n=!1;return e.$subscribe(t,e=>{n?o(e):n=!0})}return e.$subscribe(t,o)},e.withPlugins=function(e,t=[]){if(!t.length)return e;for(const i of t){try{i.onInit?.()}catch(s){o(`[Lume.js] Plugin "${i.name}" error in onInit:`,s)}Object.freeze(i)}const n=new Map;let r;return"function"==typeof e.$beforeFlush&&(r=e.$beforeFlush(function(){for(const[e,r]of n)for(const n of t)try{n.onNotify?.(e,r)}catch(s){o(`[Lume.js] Plugin "${n.name}" error in onNotify:`,s)}n.clear()})),new Proxy(e,{get(e,i){if("$dispose"===i)return()=>{r&&r(),n.clear()};if("string"==typeof i&&i.startsWith("$")){const n=e[i];return"$subscribe"===i&&"function"==typeof n?(e,r)=>{for(const n of t)try{n.onSubscribe?.(e)}catch(s){o(`[Lume.js] Plugin "${n.name}" error in onSubscribe:`,s)}return n(e,r)}:n}let c=e[i];for(const n of t)try{const e=n.onGet?.(i,c);void 0!==e&&(c=e)}catch(s){o(`[Lume.js] Plugin "${n.name}" error in onGet:`,s)}return c},set(e,r,i){const c=e[r];let a=i;for(const n of t)try{const e=n.onSet?.(r,a,c);void 0!==e&&(a=e)}catch(s){o(`[Lume.js] Plugin "${n.name}" error in onSet:`,s)}return Object.is(a,c)||n.set(r,a),e[r]=a,!0}})},e.withReadObserver=a,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
2
2
  //# sourceMappingURL=lume.global.js.map