lume-js 2.2.0 → 2.3.0

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.
Files changed (43) hide show
  1. package/README.md +90 -19
  2. package/dist/addons.min.mjs +1 -1
  3. package/dist/addons.mjs +160 -6
  4. package/dist/addons.mjs.map +1 -1
  5. package/dist/handlers.min.mjs +1 -1
  6. package/dist/handlers.mjs +38 -2
  7. package/dist/handlers.mjs.map +1 -1
  8. package/dist/index.min.mjs +1 -1
  9. package/dist/index.mjs +4 -141
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/lume.global.js +1 -1
  12. package/dist/lume.global.js.map +1 -1
  13. package/dist/shared-Bk_gndPJ.mjs +232 -0
  14. package/dist/shared-Bk_gndPJ.mjs.map +1 -0
  15. package/dist/shared-DNe4ez8V.mjs +249 -0
  16. package/dist/shared-DNe4ez8V.mjs.map +1 -0
  17. package/dist/shared-DmpHYKx7.mjs +15 -0
  18. package/dist/shared-DmpHYKx7.mjs.map +1 -0
  19. package/dist/state.min.mjs +1 -0
  20. package/dist/state.mjs +7 -0
  21. package/dist/state.mjs.map +1 -0
  22. package/package.json +5 -1
  23. package/src/addons/computed.js +5 -0
  24. package/src/addons/hydrateState.js +32 -4
  25. package/src/addons/index.d.ts +70 -2
  26. package/src/addons/index.js +13 -2
  27. package/src/addons/persist.js +152 -0
  28. package/src/addons/repeat.js +120 -5
  29. package/src/addons/withPlugins.js +7 -1
  30. package/src/core/batch.js +139 -0
  31. package/src/core/bindDom.js +12 -3
  32. package/src/core/effect.js +34 -5
  33. package/src/core/state.js +124 -68
  34. package/src/handlers/index.d.ts +24 -0
  35. package/src/handlers/index.js +1 -0
  36. package/src/handlers/on.js +60 -0
  37. package/src/handlers/stringAttr.js +14 -2
  38. package/src/index.d.ts +40 -0
  39. package/src/index.js +3 -1
  40. package/src/state.d.ts +17 -0
  41. package/src/state.js +25 -0
  42. package/dist/shared-Dcokqj5a.mjs +0 -249
  43. package/dist/shared-Dcokqj5a.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,145 +1,8 @@
1
- import { l as logWarn } from "./shared-Dcokqj5a.mjs";
2
- import { e, s, w } from "./shared-Dcokqj5a.mjs";
3
- const boolHandler = (name) => ({
4
- attr: `data-${name}`,
5
- apply(el, val) {
6
- el[name] = Boolean(val);
7
- }
8
- });
9
- const ariaHandler = (name) => ({
10
- attr: `data-${name}`,
11
- apply(el, val) {
12
- el.setAttribute(name, val ? "true" : "false");
13
- }
14
- });
15
- const DEFAULT_HANDLERS = [
16
- boolHandler("hidden"),
17
- boolHandler("disabled"),
18
- boolHandler("checked"),
19
- boolHandler("required"),
20
- ariaHandler("aria-expanded"),
21
- ariaHandler("aria-hidden")
22
- ];
23
- function mergeHandlers(defaults, userHandlers) {
24
- if (!userHandlers.length) return defaults;
25
- const merged = /* @__PURE__ */ new Map();
26
- for (const h of defaults) merged.set(h.attr, h);
27
- for (const h of userHandlers.flat()) merged.set(h.attr, h);
28
- return [...merged.values()];
29
- }
30
- function bindDom(root, store, options = {}) {
31
- if (!(root instanceof HTMLElement)) {
32
- throw new Error("bindDom() requires a valid HTMLElement as root");
33
- }
34
- if (!store || typeof store !== "object") {
35
- throw new Error("bindDom() requires a reactive state object");
36
- }
37
- const { immediate = false, handlers: userHandlers = [] } = options;
38
- const handlers = mergeHandlers(DEFAULT_HANDLERS, userHandlers);
39
- const performBinding = () => {
40
- const cleanups = [];
41
- const bindingMap = /* @__PURE__ */ new WeakMap();
42
- const selector = ["[data-bind]", ...handlers.map((h) => `[${h.attr}]`)].join(",");
43
- const elements = root.querySelectorAll(selector);
44
- for (const el of elements) {
45
- if (el.hasAttribute("data-bind")) {
46
- const c = handleDataBind(el, store, el.getAttribute("data-bind"), bindingMap);
47
- if (c) cleanups.push(c);
48
- }
49
- for (const handler of handlers) {
50
- if (el.hasAttribute(handler.attr)) {
51
- const c = applyHandler(el, store, el.getAttribute(handler.attr), handler);
52
- if (c) cleanups.push(c);
53
- }
54
- }
55
- }
56
- const inputHandler = (e2) => {
57
- const binding = bindingMap.get(e2.target);
58
- if (binding) binding.target[binding.key] = getInputValue(e2.target);
59
- };
60
- root.addEventListener("input", inputHandler);
61
- cleanups.push(() => root.removeEventListener("input", inputHandler));
62
- return () => cleanups.forEach((c) => c());
63
- };
64
- if (!immediate && document.readyState === "loading") {
65
- let cleanup = null;
66
- const onReady = () => {
67
- cleanup = performBinding();
68
- };
69
- document.addEventListener("DOMContentLoaded", onReady, { once: true });
70
- return () => cleanup ? cleanup() : document.removeEventListener("DOMContentLoaded", onReady);
71
- }
72
- return performBinding();
73
- }
74
- function applyHandler(el, store, path, handler) {
75
- const result = resolveProp(store, path);
76
- if (!result) return null;
77
- const { target, key } = result;
78
- return target.$subscribe(key, (val) => handler.apply(el, val));
79
- }
80
- function handleDataBind(el, store, path, bindingMap) {
81
- const result = resolveProp(store, path);
82
- if (!result) return null;
83
- const { target, key } = result;
84
- const unsub = target.$subscribe(key, (val) => updateElement(el, val));
85
- if (isFormInput(el)) {
86
- bindingMap.set(el, { target, key });
87
- }
88
- return unsub;
89
- }
90
- function resolvePath(obj, pathArr) {
91
- if (!pathArr || pathArr.length === 0) {
92
- return obj;
93
- }
94
- let current = obj;
95
- for (let i = 0; i < pathArr.length; i++) {
96
- const key = pathArr[i];
97
- if (current === null || current === void 0) {
98
- return null;
99
- }
100
- if (!(key in current)) {
101
- return null;
102
- }
103
- current = current[key];
104
- }
105
- return current;
106
- }
107
- function resolveProp(store, path) {
108
- if (!path) return null;
109
- const pathArr = path.split(".");
110
- const key = pathArr.pop();
111
- const target = resolvePath(store, pathArr);
112
- if (target === null || target === void 0) {
113
- logWarn(`[Lume.js] Invalid path "${path}"`);
114
- return null;
115
- }
116
- if (!target?.$subscribe) {
117
- logWarn(`[Lume.js] Target for "${path}" is not reactive`);
118
- return null;
119
- }
120
- return { target, key };
121
- }
122
- function updateElement(el, val) {
123
- if (el.tagName === "INPUT") {
124
- if (el.type === "checkbox") el.checked = Boolean(val);
125
- else if (el.type === "radio") el.checked = el.value === String(val);
126
- else el.value = val ?? "";
127
- } else if (el.tagName === "TEXTAREA" || el.tagName === "SELECT") {
128
- el.value = val ?? "";
129
- } else {
130
- el.textContent = val ?? "";
131
- }
132
- }
133
- function getInputValue(el) {
134
- if (el.type === "checkbox") return el.checked;
135
- if (el.type === "number" || el.type === "range") return el.valueAsNumber;
136
- return el.value;
137
- }
138
- function isFormInput(el) {
139
- return el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.tagName === "SELECT";
140
- }
1
+ import { b, s, w } from "./shared-Bk_gndPJ.mjs";
2
+ import { b as b2, e } from "./shared-DNe4ez8V.mjs";
141
3
  export {
142
- bindDom,
4
+ b as batch,
5
+ b2 as bindDom,
143
6
  e as effect,
144
7
  s as state,
145
8
  w as withReadObserver
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/core/bindDom.js"],"sourcesContent":["// src/core/bindDom.js\n/**\n * Lume-JS DOM Binding\n *\n * Binds reactive state to DOM elements using data-* attributes.\n *\n * Built-in attributes (always available):\n * data-bind=\"key\" → Two-way binding for inputs, textContent for others\n * data-hidden=\"key\" → Toggles hidden (truthy = hidden)\n * data-disabled=\"key\" → Toggles disabled (truthy = disabled)\n * data-checked=\"key\" → Toggles checked (for checkboxes/radios)\n * data-required=\"key\" → Toggles required (truthy = required)\n * data-aria-expanded=\"key\" → Sets aria-expanded to \"true\"/\"false\"\n * data-aria-hidden=\"key\" → Sets aria-hidden to \"true\"/\"false\"\n *\n * Extensible via handlers option:\n * import { show, classToggle } from 'lume-js/handlers';\n * bindDom(root, store, { handlers: [show, classToggle('active')] });\n *\n * Custom handlers:\n * const tooltip = { attr: 'data-tooltip', apply(el, val) { el.title = val ?? ''; } };\n * bindDom(root, store, { handlers: [tooltip] });\n *\n * Usage:\n * import { bindDom } from \"lume-js\";\n * const cleanup = bindDom(document.body, store);\n */\n\nimport { logWarn } from '../utils/log.js';\n\n// --- Default Handlers (always active, backwards compatible) ---\n\nconst boolHandler = (name) => ({\n attr: `data-${name}`,\n apply(el, val) { el[name] = Boolean(val); }\n});\n\nconst ariaHandler = (name) => ({\n attr: `data-${name}`,\n apply(el, val) { el.setAttribute(name, val ? 'true' : 'false'); }\n});\n\nconst DEFAULT_HANDLERS = [\n boolHandler('hidden'),\n boolHandler('disabled'),\n boolHandler('checked'),\n boolHandler('required'),\n ariaHandler('aria-expanded'),\n ariaHandler('aria-hidden'),\n];\n\n/**\n * Merge default and user handlers.\n * User handlers override defaults with same attr (Map deduplicates).\n * User handler arrays are flattened one level (supports classToggle()).\n */\nfunction mergeHandlers(defaults, userHandlers) {\n if (!userHandlers.length) return defaults;\n const merged = new Map();\n for (const h of defaults) merged.set(h.attr, h);\n for (const h of userHandlers.flat()) merged.set(h.attr, h);\n return [...merged.values()];\n}\n\n/**\n * DOM binding for reactive state\n */\nexport function bindDom(root, store, options = {}) {\n if (!(root instanceof HTMLElement)) {\n throw new Error('bindDom() requires a valid HTMLElement as root');\n }\n if (!store || typeof store !== 'object') {\n throw new Error('bindDom() requires a reactive state object');\n }\n\n const { immediate = false, handlers: userHandlers = [] } = options;\n const handlers = mergeHandlers(DEFAULT_HANDLERS, userHandlers);\n\n const performBinding = () => {\n const cleanups = [];\n const bindingMap = new WeakMap();\n\n // Build compiled selector: data-bind (always) + all handler attrs\n const selector = ['[data-bind]', ...handlers.map(h => `[${h.attr}]`)].join(',');\n const elements = root.querySelectorAll(selector);\n\n for (const el of elements) {\n // data-bind (two-way) — always in core, special handling\n if (el.hasAttribute('data-bind')) {\n const c = handleDataBind(el, store, el.getAttribute('data-bind'), bindingMap);\n if (c) cleanups.push(c);\n }\n\n // All registered handlers (default + user)\n for (const handler of handlers) {\n if (el.hasAttribute(handler.attr)) {\n const c = applyHandler(el, store, el.getAttribute(handler.attr), handler);\n if (c) cleanups.push(c);\n }\n }\n }\n\n // Event delegation for two-way bindings\n const inputHandler = e => {\n const binding = bindingMap.get(e.target);\n if (binding) binding.target[binding.key] = getInputValue(e.target);\n };\n root.addEventListener(\"input\", inputHandler);\n cleanups.push(() => root.removeEventListener(\"input\", inputHandler));\n\n return () => cleanups.forEach(c => c());\n };\n\n // Auto-wait for DOM if needed\n if (!immediate && document.readyState === 'loading') {\n let cleanup = null;\n const onReady = () => { cleanup = performBinding(); };\n document.addEventListener('DOMContentLoaded', onReady, { once: true });\n return () => cleanup ? cleanup() : document.removeEventListener('DOMContentLoaded', onReady);\n }\n\n return performBinding();\n}\n\n/**\n * Apply a handler to an element via subscription.\n * Resolves the state path and subscribes to changes.\n */\nfunction applyHandler(el, store, path, handler) {\n const result = resolveProp(store, path);\n if (!result) return null;\n const { target, key } = result;\n return target.$subscribe(key, val => handler.apply(el, val));\n}\n\n/**\n * Handle data-bind (two-way for inputs, textContent for others)\n */\nfunction handleDataBind(el, store, path, bindingMap) {\n const result = resolveProp(store, path);\n if (!result) return null;\n\n const { target, key } = result;\n const unsub = target.$subscribe(key, val => updateElement(el, val));\n\n if (isFormInput(el)) {\n bindingMap.set(el, { target, key });\n }\n\n return unsub;\n}\n\n/**\n * Resolve a nested path in an object.\n * Example: resolvePath(obj, ['user', 'address']) returns obj.user.address\n */\nfunction resolvePath(obj, pathArr) {\n if (!pathArr || pathArr.length === 0) {\n return obj;\n }\n let current = obj;\n for (let i = 0; i < pathArr.length; i++) {\n const key = pathArr[i];\n if (current === null || current === undefined) {\n return null;\n }\n if (!(key in current)) {\n return null;\n }\n current = current[key];\n }\n return current;\n}\n\n/**\n * Resolve path to target and key.\n *\n * ⚠️ Path bindings are resolved once at bind time. If an intermediate\n * object in the path is null/undefined at bindDom call time, the binding\n * is permanently dead and will not self-heal when the path later becomes valid.\n */\nfunction resolveProp(store, path) {\n if (!path) return null;\n\n const pathArr = path.split(\".\");\n const key = pathArr.pop();\n const target = resolvePath(store, pathArr);\n\n if (target === null || target === undefined) {\n logWarn(`[Lume.js] Invalid path \"${path}\"`);\n return null;\n }\n\n if (!target?.$subscribe) {\n logWarn(`[Lume.js] Target for \"${path}\" is not reactive`);\n return null;\n }\n\n return { target, key };\n}\n\n/**\n * Update element with value (for data-bind)\n */\nfunction updateElement(el, val) {\n if (el.tagName === \"INPUT\") {\n if (el.type === \"checkbox\") el.checked = Boolean(val);\n else if (el.type === \"radio\") el.checked = el.value === String(val);\n else el.value = val ?? '';\n } else if (el.tagName === \"TEXTAREA\" || el.tagName === \"SELECT\") {\n el.value = val ?? '';\n } else {\n el.textContent = val ?? '';\n }\n}\n\n/**\n * Get value from input\n */\nfunction getInputValue(el) {\n if (el.type === \"checkbox\") return el.checked;\n if (el.type === \"number\" || el.type === \"range\") return el.valueAsNumber;\n return el.value;\n}\n\n/**\n * Check if element is form input\n */\nfunction isFormInput(el) {\n return el.tagName === \"INPUT\" || el.tagName === \"TEXTAREA\" || el.tagName === \"SELECT\";\n}"],"names":["e"],"mappings":"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"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -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=new Set;function r(e,t){n.add(e);try{return t()}finally{n.delete(e)}}const c=e=>({attr:"data-"+e,apply(t,o){t[e]=!!o}}),s=e=>({attr:"data-"+e,apply(t,o){t.setAttribute(e,o?"true":"false")}}),i=[c("hidden"),c("disabled"),c("checked"),c("required"),s("aria-expanded"),s("aria-hidden")];function l(e,t,o,n){const r=u(t,o);if(!r)return null;const{target:c,key:s}=r;return c.$subscribe(s,t=>n.apply(e,t))}function a(e,t,o,n){const r=u(t,o);if(!r)return null;const{target:c,key:s}=r,i=c.$subscribe(s,t=>function(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??""}(e,t));return function(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName||"SELECT"===e.tagName}(e)&&n.set(e,{target:c,key:s}),i}function u(e,o){if(!o)return null;const n=o.split("."),r=n.pop(),c=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==c?(t(`[Lume.js] Invalid path "${o}"`),null):c?.$subscribe?{target:c,key:r}:(t(`[Lume.js] Target for "${o}" is not reactive`),null)}let f=null;function d(e,t){if("function"!=typeof e)throw Error("effect() requires a function");const n=[];let c=!1;const s=()=>{if(!c){c=!0;try{e()}catch(t){throw o("[Lume.js effect] Error in effect:",t),t}finally{c=!1}}};if(Array.isArray(t)){for(const e of t)if(Array.isArray(e)&&e.length>=2){const[t,...o]=e;if(t&&"function"==typeof t.$subscribe)for(const e of o){let o=!0;const r=t.$subscribe(e,()=>{o?o=!1:s()});n.push(r)}}s()}else{const t=()=>{if(c)return;const s=n.splice(0),i={fn:e,cleanups:n,execute:t,tracking:{}},l=f;f=i,c=!0;try{r((e,t,o)=>{f===i&&(i.tracking[t]||(i.tracking[t]=!0,i.cleanups.push(o(t,i.execute))))},e)}catch(a){throw n.length=0,n.push(...s),o("[Lume.js effect] Error in effect:",a),a}finally{f=l,c=!1}if(n.length>0)for(const e of s)e();else n.push(...s)};t()}return()=>{for(;n.length;)n.pop()()}}function p(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 g(e,t={}){const{isReorder:o=!1}=t,n=e.scrollTop;if(0===n)return()=>{e.scrollTop=0};let r=null,c=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,c=e.top-t.top;break}}}return()=>{if(r&&document.body.contains(r)){const t=r.getBoundingClientRect(),o=e.getBoundingClientRect(),n=t.top-o.top-c;e.scrollTop=e.scrollTop+n}else e.scrollTop=n}}let b=!0,h=null;const y=new Map;function m(e){return null===h||("string"==typeof h?e.includes(h):!(h instanceof RegExp)||h.test(e))}function w(e,t,o){const n=function(e){return y.has(e)||y.set(e,{gets:new Map,sets:new Map,notifies:new Map}),y.get(e)}(e),r=n[t];r.set(o,(r.get(o)||0)+1)}function E(e){try{const t=JSON.stringify(e);return t.length>100?t.slice(0,97)+"...":t}catch{return e+""}}const $={enable(){b=!0,console.log("%c[lume-debug]%c Logging enabled","color: #888; font-weight: bold","color: #4CAF50")},disable(){b=!1,console.log("%c[lume-debug]%c Logging disabled","color: #888; font-weight: bold","color: #F44336")},isEnabled:()=>b,filter(e){h=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:()=>h,stats(){const e={};for(const[t,o]of y)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(){y.clear(),console.log("%c[lume-debug]%c Stats reset","color: #888; font-weight: bold","color: inherit")}},v={attr:"data-show",apply(e,t){e.hidden=!t}},j={attr:"data-classname",apply(e,t){e.className=t||""}};function S(e){return{attr:"data-"+e,apply(t,o){t.toggleAttribute(e,!!o)}}}function k(e){const t=e.startsWith("aria-")?e:"aria-"+e;return{attr:"data-"+t,apply(e,o){e.setAttribute(t,o?"true":"false")}}}function L(e){return{attr:"data-"+e,apply(t,o){null==o?t.removeAttribute(e):t.setAttribute(e,o+"")}}}const A=["readonly","open","novalidate","formnovalidate","multiple","autofocus","autoplay","controls","loop","muted","defer","async","reversed","selected","inert","allowfullscreen"],x=["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"],O=["pressed","selected","disabled","checked","invalid","required","busy","modal","multiselectable","multiline","readonly","atomic"],T=["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"],F=[S("readonly")],N=[k("pressed"),k("selected"),k("disabled")];return e.a11yHandlers=N,e.ariaAttr=k,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,c=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()]}(i,r),s=()=>{const o=[],n=new WeakMap,r=["[data-bind]",...c.map(e=>`[${e.attr}]`)].join(","),s=e.querySelectorAll(r);for(const e of s){if(e.hasAttribute("data-bind")){const r=a(e,t,e.getAttribute("data-bind"),n);r&&o.push(r)}for(const n of c)if(e.hasAttribute(n.attr)){const r=l(e,t,e.getAttribute(n.attr),n);r&&o.push(r)}}const i=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",i),o.push(()=>e.removeEventListener("input",i)),()=>o.forEach(e=>e())};if(!n&&"loading"===document.readyState){let e=null;const t=()=>{e=s()};return document.addEventListener("DOMContentLoaded",t,{once:!0}),()=>e?e():document.removeEventListener("DOMContentLoaded",t)}return s()},e.boolAttr=S,e.className=j,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,c=!1;const s=[],i=d(()=>{if(!r&&!c){r=!0;try{const o=e();n&&Object.is(o,t)||(t=o,n=!0,s.forEach(e=>e(t)))}catch(i){o("[Lume.js computed] Error in computation:",i),n&&void 0===t||(t=void 0,n=!0,s.forEach(e=>e(t)))}finally{queueMicrotask(()=>{c||(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 s.push(e),n&&e(t),()=>{const t=s.indexOf(e);t>-1&&s.splice(t,1)}},dispose(){c=!0,i(),s.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:()=>{b&&console.log(`%c[${t}]%c initialized`,"color: #888; font-weight: bold","color: inherit")},onGet:(e,n)=>("string"==typeof e&&e.startsWith("$")||(w(t,"gets",e),b&&o("logGet",!1)&&m(e)&&console.log(`%c[${t}]%c GET %c${e}%c = ${E(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("$")||(w(t,"sets",e),b&&o("logSet",!0)&&m(e)&&(console.log(`%c[${t}]%c SET %c${e}%c: ${E(r)} → ${E(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=>{b&&m(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("$")||(w(t,"notifies",e),b&&o("logNotify",!0)&&m(e)&&console.log(`%c[${t}]%c NOTIFY %c${e}%c = ${E(n)}`,"color: #888; font-weight: bold","color: #E91E63","color: #2196F3; font-weight: bold","color: inherit"))}}},e.debug=$,e.defaultFocusPreservation=p,e.defaultScrollPreservation=g,e.effect=d,e.formHandlers=F,e.htmlAttrs=function(){return[v,...A.map(e=>S(e)),...x.map(e=>L(e)),...O.map(e=>k(e)),...T.map(e=>L("aria-"+e))]},e.hydrateState=function(e="#__LUME_DATA__"){const t="undefined"!=typeof document?document.querySelector(e):null;if(!t)return{};try{return JSON.parse(t.textContent)}catch{return{}}},e.isReactive=function(e){return!(!e||"object"!=typeof e||"function"!=typeof e.$subscribe)},e.repeat=function(e,n,r,c){const{key:s,render:i,create:l,update:a,remove:u,element:f="div",preserveFocus:d=p,preserveScroll:b=g}=c,h="string"==typeof e?document.querySelector(e):e;if(!h)return t(`[Lume.js] repeat(): container "${e}" not found`),()=>{};if("function"!=typeof s)throw Error("[Lume.js] repeat(): options.key must be a function");if("function"!=typeof i&&"function"!=typeof l)throw Error("[Lume.js] repeat(): options.render or options.create must be a function");const y=new Map,m=new Map,w=new Map,E=new Map,$=new Set;function v(){return"function"==typeof f?f():document.createElement(f)}function j(){const e=n[r];if(!Array.isArray(e))return void t(`[Lume.js] repeat(): store.${r} is not an array`);let c=!1;if(b&&y.size===e.length){c=!0;for(let t=0;t<e.length;t++)if(!y.has(s(e[t]))){c=!1;break}}$.clear();const f=[];for(let n=0;n<e.length;n++){const r=e[n],c=s(r);if($.has(c)){t(`[Lume.js] repeat(): duplicate key "${c}"`);continue}$.add(c);let u=y.get(c);const d=!u;d&&(u=v(),y.set(c,u));try{if(d&&l){const e=l(r,u,n);"function"==typeof e&&E.set(c,e)}const e=m.get(c),t=w.get(c);a?e===r&&t===n||a(r,u,n,{isFirstRender:d}):i&&i(r,u,n),m.set(c,r),w.set(c,n)}catch(p){o(`[Lume.js] repeat(): error rendering key "${c}":`,p)}f.push(u)}!function(e,t,n){const r=document.body.contains(e),c=r&&d?d(e):null,s=r&&b?b(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}}(h,f),y.size!==$.size)for(const e of y.keys())if(!$.has(e)){const t=y.get(e),n=m.get(e),r=E.get(e);if("function"==typeof r)try{r()}catch(p){o(`[Lume.js] repeat(): cleanup error for key "${e}":`,p)}"function"==typeof u&&t&&u(n,t),y.delete(e),m.delete(e),w.delete(e),E.delete(e)}})(),c&&c(),s&&s()}(h,0,c)}let S;if("function"==typeof n.$subscribe)S=n.$subscribe(r,j);else{if("function"!=typeof n.subscribe)return j(),t("[Lume.js] repeat(): store is not reactive (no $subscribe or subscribe method)"),()=>{for(const[t,n]of y){const r=m.get(t),c=E.get(t);if("function"==typeof c)try{c()}catch(e){o(`[Lume.js] repeat(): cleanup error for key "${t}":`,e)}"function"==typeof u&&u(r,n)}h.replaceChildren(),y.clear(),m.clear(),w.clear(),E.clear(),$.clear()};{const e=n.subscribe(()=>j());j(),S="function"==typeof e?e:()=>{e?.unsubscribe?.()}}}return()=>{"function"==typeof S&&S();for(const[t,n]of y){const r=m.get(t),c=E.get(t);if("function"==typeof c)try{c()}catch(e){o(`[Lume.js] repeat(): cleanup error for key "${t}":`,e)}"function"==typeof u&&u(r,n)}h.replaceChildren(),y.clear(),m.clear(),w.clear(),E.clear(),$.clear()}},e.show=v,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 t=Object.create(null),r=new Map,c=new Set,s=[];let i=!1;e[Symbol("lume.reactive")]=!0;const l=(e,o)=>{t[e]||(t[e]=[]);const n=()=>{c.add(o)};return t[e].push(n),()=>{if(t[e]){const o=t[e].indexOf(n);-1!==o&&(t[e].splice(o,1),0===t[e].length&&delete t[e])}}},a=new Proxy(e,{get(e,t){if("string"==typeof t&&t.startsWith("$"))return e[t];const o=e[t];if(n.size>0)for(const r of n)r(a,t,l);return o},set(e,n,l){const a=e[n];return Object.is(a,l)||(e[n]=l,r.set(n,l),i||(i=!0,queueMicrotask(()=>{let e=0;try{for(;(r.size>0||c.size>0)&&100>e;){e++;for(let e=0;e<s.length;e++)try{s[e]()}catch(n){o("[Lume.js state] Error in beforeFlush hook:",n)}for(const[e,c]of r)if(t[e]){const r=t[e];let s=0;for(;s<r.length;){const t=r[s];try{t(c)}catch(n){o(`[Lume.js state] Error notifying subscriber for key "${e+""}":`,n)}r[s]===t&&s++}}r.clear();const i=Array(c.size);let l=0;for(const e of c)i[l++]=e;c.clear();for(let e=0;e<i.length;e++)try{i[e]()}catch(n){o("[Lume.js state] Error in effect:",n)}}}finally{i=!1}100>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}});return e.$beforeFlush=e=>{if("function"!=typeof e)throw Error("$beforeFlush requires a function");return-1===s.indexOf(e)&&s.push(e),()=>{const t=s.indexOf(e);-1!==t&&s.splice(t,1)}},e.$subscribe=(e,o)=>{if("function"!=typeof o)throw Error("Subscriber must be a function");return t[e]||(t[e]=[]),t[e].push(o),o(a[e]),()=>{if(t[e]){const n=t[e].indexOf(o);-1!==n&&(t[e].splice(n,1),0===t[e].length&&delete t[e])}}},a},e.stringAttr=L,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 s of t)try{s.onInit?.()}catch(c){o(`[Lume.js] Plugin "${s.name}" error in onInit:`,c)}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(c){o(`[Lume.js] Plugin "${n.name}" error in onNotify:`,c)}n.clear()})),new Proxy(e,{get(e,s){if("$dispose"===s)return()=>{r&&r(),n.clear()};if("string"==typeof s&&s.startsWith("$")){const n=e[s];return"$subscribe"===s&&"function"==typeof n?(e,r)=>{for(const n of t)try{n.onSubscribe?.(e)}catch(c){o(`[Lume.js] Plugin "${n.name}" error in onSubscribe:`,c)}return n(e,r)}:n}let i=e[s];for(const n of t)try{const e=n.onGet?.(s,i);void 0!==e&&(i=e)}catch(c){o(`[Lume.js] Plugin "${n.name}" error in onGet:`,c)}return i},set(e,r,s){const i=e[r];let l=s;for(const n of t)try{const e=n.onSet?.(r,l,i);void 0!==e&&(l=e)}catch(c){o(`[Lume.js] Plugin "${n.name}" error in onSet:`,c)}return Object.is(l,i)||n.set(r,l),e[r]=l,!0}})},e.withReadObserver=r,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 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}({});
2
2
  //# sourceMappingURL=lume.global.js.map