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.
- package/README.md +90 -19
- package/dist/addons.min.mjs +1 -1
- package/dist/addons.mjs +160 -6
- package/dist/addons.mjs.map +1 -1
- package/dist/handlers.min.mjs +1 -1
- package/dist/handlers.mjs +38 -2
- package/dist/handlers.mjs.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.mjs +4 -141
- package/dist/index.mjs.map +1 -1
- package/dist/lume.global.js +1 -1
- package/dist/lume.global.js.map +1 -1
- package/dist/shared-Bk_gndPJ.mjs +232 -0
- package/dist/shared-Bk_gndPJ.mjs.map +1 -0
- package/dist/shared-DNe4ez8V.mjs +249 -0
- package/dist/shared-DNe4ez8V.mjs.map +1 -0
- package/dist/shared-DmpHYKx7.mjs +15 -0
- package/dist/shared-DmpHYKx7.mjs.map +1 -0
- package/dist/state.min.mjs +1 -0
- package/dist/state.mjs +7 -0
- package/dist/state.mjs.map +1 -0
- package/package.json +5 -1
- package/src/addons/computed.js +5 -0
- package/src/addons/hydrateState.js +32 -4
- package/src/addons/index.d.ts +70 -2
- package/src/addons/index.js +13 -2
- package/src/addons/persist.js +152 -0
- package/src/addons/repeat.js +120 -5
- package/src/addons/withPlugins.js +7 -1
- package/src/core/batch.js +139 -0
- package/src/core/bindDom.js +12 -3
- package/src/core/effect.js +34 -5
- package/src/core/state.js +124 -68
- package/src/handlers/index.d.ts +24 -0
- package/src/handlers/index.js +1 -0
- package/src/handlers/on.js +60 -0
- package/src/handlers/stringAttr.js +14 -2
- package/src/index.d.ts +40 -0
- package/src/index.js +3 -1
- package/src/state.d.ts +17 -0
- package/src/state.js +25 -0
- package/dist/shared-Dcokqj5a.mjs +0 -249
- package/dist/shared-Dcokqj5a.mjs.map +0 -1
package/dist/addons.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addons.mjs","sources":["../src/addons/computed.js","../src/addons/watch.js","../src/addons/repeat.js","../src/addons/debug.js","../src/addons/withPlugins.js","../src/addons/cleanupGroup.js","../src/addons/hydrateState.js","../src/addons/index.js"],"sourcesContent":["/**\n * Lume-JS Computed Addon\n * \n * Creates computed values that automatically update when dependencies change.\n * Uses core effect() for automatic dependency tracking.\n * \n * Usage:\n * import { computed } from \"lume-js/addons/computed\";\n * \n * const doubled = computed(() => store.count * 2);\n * console.log(doubled.value); // Auto-updates when store.count changes\n * \n * Features:\n * - Automatic dependency tracking (no manual recompute)\n * - Cached values (only recomputes when dependencies change)\n * - Subscribe to changes\n * - Cleanup with dispose()\n * \n * @module addons/computed\n */\n\nimport { effect } from '../core/effect.js';\nimport { logError } from '../utils/log.js';\n\n/**\n * Creates a computed value with automatic dependency tracking\n * \n * The computation function runs immediately and tracks which state\n * properties are accessed. When any dependency changes, the value\n * is automatically recomputed.\n *\n * ⚠️ Circular self-mutations are automatically suppressed. If a computed\n * mutates a state property it depends on, the flush triggered by that\n * mutation is skipped to prevent an infinite microtask loop.\n *\n * @param {function} fn - Function that computes the value\n * @returns {object} Object with .value property and methods\n * \n * @example\n * const store = state({ count: 5 });\n * \n * const doubled = computed(() => store.count * 2);\n * console.log(doubled.value); // 10\n * \n * store.count = 10;\n * // After microtask:\n * console.log(doubled.value); // 20 (auto-updated)\n * \n * @example\n * // Subscribe to changes\n * const unsub = doubled.subscribe(value => {\n * console.log('Doubled changed to:', value);\n * });\n * \n * @example\n * // Cleanup\n * doubled.dispose();\n */\nexport function computed(fn) {\n if (typeof fn !== 'function') {\n throw new Error('computed() requires a function');\n }\n\n let cachedValue;\n let isInitialized = false;\n let isInComputation = false;\n let disposed = false;\n const subscribers = [];\n\n // Use effect to automatically track dependencies\n const cleanupEffect = effect(() => {\n // Skip re-entry from a flush triggered by our own synchronous mutation.\n // The mutation inside fn() queues a microtask flush; we stay flagged\n // until a subsequent microtask clears it, so that flush is dropped.\n if (isInComputation || disposed) return;\n\n isInComputation = true;\n\n try {\n const newValue = fn();\n\n // Check if value actually changed - Object.is() handles NaN and -0\n if (!isInitialized || !Object.is(newValue, cachedValue)) {\n cachedValue = newValue;\n isInitialized = true;\n\n // Notify all subscribers\n subscribers.forEach(callback => callback(cachedValue));\n }\n } catch (error) {\n logError('[Lume.js computed] Error in computation:', error);\n // Set to undefined on error, mark as initialized\n if (!isInitialized || cachedValue !== undefined) {\n cachedValue = undefined;\n isInitialized = true;\n\n // Notify subscribers of error state\n subscribers.forEach(callback => callback(cachedValue));\n }\n } finally {\n // Defer clearing the flag so any flush microtask queued by fn()\n // sees it still set and skips re-entry.\n queueMicrotask(() => {\n if (!disposed) {\n isInComputation = false;\n }\n });\n }\n });\n\n return {\n /**\n * Get the current computed value\n */\n get value() {\n if (!isInitialized) {\n throw new Error('Computed value accessed before initialization');\n }\n return cachedValue;\n },\n\n /**\n * Subscribe to changes in computed value\n * \n * @param {function} callback - Called when value changes\n * @returns {function} Unsubscribe function\n */\n subscribe(callback) {\n if (typeof callback !== 'function') {\n throw new Error('subscribe() requires a function');\n }\n\n subscribers.push(callback);\n\n // Call immediately with current value\n if (isInitialized) {\n callback(cachedValue);\n }\n\n // Return unsubscribe function\n return () => {\n const index = subscribers.indexOf(callback);\n if (index > -1) {\n subscribers.splice(index, 1);\n }\n };\n },\n\n /**\n * Clean up computed value and stop tracking\n */\n dispose() {\n disposed = true;\n cleanupEffect();\n subscribers.length = 0;\n isInitialized = false;\n isInComputation = false;\n }\n };\n}","/**\n * watch - observes changes to a state key and triggers callback\n * @param {Object} store - reactive store created with state()\n * @param {string} key - key in store to watch\n * @param {Function} callback - called with new value\n * @param {Object} [options]\n * @param {boolean} [options.immediate=true] - call callback immediately with current value\n * @returns {Function} unsubscribe function\n */\nexport function watch(store, key, callback, { immediate = true } = {}) {\n if (!store.$subscribe) {\n throw new Error(\"store must be created with state()\");\n }\n if (!immediate) {\n let skipped = false;\n return store.$subscribe(key, (val) => {\n if (!skipped) { skipped = true; return; }\n callback(val);\n });\n }\n return store.$subscribe(key, callback);\n}","/**\n * Lume-JS List Rendering (Addon)\n *\n * Renders lists with automatic subscription and element reuse by key.\n * \n * Core guarantees:\n * Element reuse by key (same DOM nodes, not recreated)\n * Minimal DOM operations (only updates what changed)\n * Memory efficiency (cleanup on remove)\n * \n * Default behavior (can be disabled/customized):\n * ✅ Focus preservation (maintains activeElement and selection)\n * ✅ Scroll preservation (intelligent positioning for add/remove/reorder)\n * \n * Philosophy: No artificial limitations\n * - All preservation logic is overridable via options\n * - Set to null/false to disable, or provide custom functions\n * - Export utilities so you can wrap/extend them\n *\n * ⚠️ IMPORTANT: Arrays must be updated immutably!\n * store.items.push(x) // ❌ Won't trigger update\n * store.items = [...items] // ✅ Triggers update\n * \n * ═══════════════════════════════════════════════════════════════════════\n * PATTERN 1: Simple (render only) - for simple cases or backward compat\n * ═══════════════════════════════════════════════════════════════════════\n * \n * repeat('#list', store, 'todos', {\n * key: todo => todo.id,\n * render: (todo, el) => {\n * el.textContent = todo.name; // Called on every update\n * }\n * });\n *\n * ═══════════════════════════════════════════════════════════════════════\n * PATTERN 2: Clean separation (create + update) - recommended\n * ═══════════════════════════════════════════════════════════════════════\n *\n * repeat('#list', store, 'todos', {\n * key: todo => todo.id,\n * create: (todo, el) => {\n * // Called ONCE when element is created - build DOM structure\n * const nameSpan = document.createElement('span');\n * nameSpan.className = 'name';\n * el.appendChild(nameSpan);\n * const btn = document.createElement('button');\n * btn.textContent = 'Delete';\n * btn.onclick = () => deleteTodo(todo.id);\n * el.appendChild(btn);\n *\n * // Return a cleanup function — called automatically when element is removed\n * return () => {\n * // Unsubscribe from external listeners, remove timers, etc.\n * };\n * },\n * update: (todo, el, index, { isFirstRender }) => {\n * // Called on every update - bind data\n * // isFirstRender = true on initial render, false on subsequent\n * // Skipped if same object reference (optimization)\n * el.querySelector('.name').textContent = todo.name;\n * }\n * });\n *\n * ═══════════════════════════════════════════════════════════════════════\n * ADVANCED: Custom preservation strategies\n * ═══════════════════════════════════════════════════════════════════════\n * \n * import { defaultFocusPreservation, defaultScrollPreservation } from \"lume-js/addons\";\n * \n * repeat('#list', store, 'items', {\n * key: item => item.id,\n * create: (item, el) => { ... },\n * update: (item, el) => { ... },\n * preserveFocus: null, // disable focus preservation\n * preserveScroll: (container, context) => {\n * const restore = defaultScrollPreservation(container, context);\n * return () => { restore(); console.log('Scroll restored!'); };\n * }\n * });\n */\nimport { logWarn, logError } from '../utils/log.js';\n\n/**\n * Default focus preservation strategy\n * Saves activeElement and selection state before DOM updates\n * \n * @param {HTMLElement} container - The list container\n * @returns {Function|null} Restore function, or null if nothing to restore\n */\nexport function defaultFocusPreservation(container) {\n const activeEl = document.activeElement;\n const shouldRestore = container.contains(activeEl);\n\n if (!shouldRestore) return null;\n\n let selectionStart = null;\n let selectionEnd = null;\n\n if (activeEl.tagName === 'INPUT' || activeEl.tagName === 'TEXTAREA') {\n selectionStart = activeEl.selectionStart;\n selectionEnd = activeEl.selectionEnd;\n }\n\n return () => {\n if (document.body.contains(activeEl)) {\n activeEl.focus();\n if (selectionStart !== null && selectionEnd !== null) {\n activeEl.setSelectionRange(selectionStart, selectionEnd);\n }\n }\n };\n}\n\n/**\n * Default scroll preservation strategy\n * Uses anchor-based preservation for add/remove, pixel position for reorder\n * \n * @param {HTMLElement} container - The list container\n * @param {Object} context - Additional context\n * @param {boolean} context.isReorder - Whether this is a reorder operation\n * @returns {Function} Restore function\n */\nexport function defaultScrollPreservation(container, context = {}) {\n const { isReorder = false } = context;\n const scrollTop = container.scrollTop;\n\n // Early return if no scroll\n if (scrollTop === 0) {\n return () => { container.scrollTop = 0; };\n }\n\n let anchorElement = null;\n let anchorOffset = 0;\n\n // Only use anchor-based preservation for add/remove, not reorder\n if (!isReorder) {\n const containerRect = container.getBoundingClientRect();\n // Avoid Array.from - iterate children directly\n for (let child = container.firstElementChild; child; child = child.nextElementSibling) {\n const rect = child.getBoundingClientRect();\n\n if (rect.bottom > containerRect.top) {\n anchorElement = child;\n anchorOffset = rect.top - containerRect.top;\n break;\n }\n }\n }\n\n return () => {\n if (anchorElement && document.body.contains(anchorElement)) {\n const newRect = anchorElement.getBoundingClientRect();\n const containerRect = container.getBoundingClientRect();\n const currentOffset = newRect.top - containerRect.top;\n const scrollAdjustment = currentOffset - anchorOffset;\n\n container.scrollTop = container.scrollTop + scrollAdjustment;\n } else {\n container.scrollTop = scrollTop;\n }\n };\n}\n\n/**\n * Efficiently render a list with element reuse\n * \n * @param {string|HTMLElement} container - Container element or selector\n * @param {Object} store - Reactive state object\n * @param {string} arrayKey - Key in store containing the array\n * @param {Object} options - Configuration\n * @param {Function} options.key - Function to extract unique key: (item) => key\n * @param {Function} [options.render] - Function to render item (called for all items): (item, element, index) => void\n * @param {Function} [options.create] - Function for new elements only: (item, element, index) => void | Function. If a function is returned, it is registered as the element's cleanup and called automatically when the element is removed (by list update or full cleanup).\n * @param {Function} [options.update] - Function for data binding: (item, element, index, { isFirstRender }) => void. Skipped if same item reference AND same index.\n * @param {Function} [options.remove] - Additional cleanup when element is removed: (item, element) => void. Called after any cleanup function returned by create(). Optional — prefer returning a cleanup from create() for automatic lifecycle management.\n * @param {string|Function} [options.element='div'] - Element tag name or factory function\n * @param {Function|null} [options.preserveFocus=defaultFocusPreservation] - Focus preservation strategy (null to disable)\n * @param {Function|null} [options.preserveScroll=defaultScrollPreservation] - Scroll preservation strategy (null to disable)\n * @returns {Function} Cleanup function\n */\n\nexport function repeat(container, store, arrayKey, options) {\n const {\n key,\n render,\n create,\n update,\n remove,\n element = 'div',\n preserveFocus = defaultFocusPreservation,\n preserveScroll = defaultScrollPreservation\n } = options;\n\n // Resolve container\n const containerEl =\n typeof container === 'string'\n ? document.querySelector(container)\n : container;\n\n if (!containerEl) {\n logWarn(`[Lume.js] repeat(): container \"${container}\" not found`);\n return () => { };\n }\n\n if (typeof key !== 'function') {\n throw new Error('[Lume.js] repeat(): options.key must be a function');\n }\n\n if (typeof render !== 'function' && typeof create !== 'function') {\n throw new Error('[Lume.js] repeat(): options.render or options.create must be a function');\n }\n\n // key -> HTMLElement\n const elementsByKey = new Map();\n // key -> previous item (for reference comparison)\n const prevItemsByKey = new Map();\n // key -> previous index (for reorder detection)\n const prevIndexByKey = new Map();\n // key -> cleanup function returned by create()\n const cleanupByKey = new Map();\n const seenKeys = new Set();\n\n function createElement() {\n return typeof element === 'function'\n ? element()\n : document.createElement(element);\n }\n\n function reconcileDOM(container, nextEls) {\n let ptr = container.firstChild;\n\n for (let i = 0; i < nextEls.length; i++) {\n const desired = nextEls[i];\n\n if (ptr === desired) {\n ptr = ptr.nextSibling;\n continue;\n }\n\n container.insertBefore(desired, ptr);\n }\n\n // Remove leftover children not in nextEls\n while (ptr) {\n const next = ptr.nextSibling;\n container.removeChild(ptr);\n ptr = next;\n }\n }\n\n function applyPreservation(container, fn, isReorder) {\n const shouldPreserve = document.body.contains(container);\n const restoreFocus = shouldPreserve && preserveFocus ? preserveFocus(container) : null;\n const restoreScroll = shouldPreserve && preserveScroll ? preserveScroll(container, { isReorder }) : null;\n\n fn();\n\n if (restoreFocus) restoreFocus();\n if (restoreScroll) restoreScroll();\n }\n\n // eslint-disable-next-line sonarjs/cognitive-complexity -- keyed DOM reconciliation: create/reuse/remove nodes, key dedup, scroll/focus preservation\n function updateList() {\n const items = store[arrayKey];\n\n if (!Array.isArray(items)) {\n logWarn(`[Lume.js] repeat(): store.${arrayKey} is not an array`);\n return;\n }\n\n // Only compute isReorder if scroll preservation needs it.\n // Uses elementsByKey (previous state) and items directly — no Set allocations.\n let isReorder = false;\n if (preserveScroll && elementsByKey.size === items.length) {\n isReorder = true;\n for (let i = 0; i < items.length; i++) {\n if (!elementsByKey.has(key(items[i]))) { isReorder = false; break; }\n }\n }\n\n seenKeys.clear();\n const nextEls = [];\n\n // Build ordered list of DOM nodes (created or reused)\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const k = key(item);\n\n if (seenKeys.has(k)) {\n logWarn(`[Lume.js] repeat(): duplicate key \"${k}\"`);\n continue;\n }\n seenKeys.add(k);\n\n let el = elementsByKey.get(k);\n const isFirstRender = !el;\n\n if (isFirstRender) {\n el = createElement();\n elementsByKey.set(k, el);\n }\n\n try {\n // Call create for new elements (DOM structure)\n if (isFirstRender && create) {\n const cleanup = create(item, el, i);\n if (typeof cleanup === 'function') {\n cleanupByKey.set(k, cleanup);\n }\n }\n\n // Call update for data binding (new and existing elements)\n // Skip if same item reference AND same index (optimization)\n const prevItem = prevItemsByKey.get(k);\n const prevIndex = prevIndexByKey.get(k);\n if (update) {\n if (prevItem !== item || prevIndex !== i) {\n update(item, el, i, { isFirstRender });\n }\n } else if (render) {\n // Backward compatibility: render handles both create and update\n render(item, el, i);\n }\n\n // Store reference and index for next comparison\n prevItemsByKey.set(k, item);\n prevIndexByKey.set(k, i);\n\n } catch (err) {\n logError(`[Lume.js] repeat(): error rendering key \"${k}\":`, err);\n }\n\n nextEls.push(el);\n }\n\n // eslint-disable-next-line sonarjs/cognitive-complexity -- DOM cleanup pass: remove stale nodes, call per-item cleanup callbacks, update maps\n applyPreservation(containerEl, () => {\n reconcileDOM(containerEl, nextEls);\n\n // Clean maps: remove keys not in seenKeys (new state)\n if (elementsByKey.size !== seenKeys.size) {\n for (const k of elementsByKey.keys()) {\n if (!seenKeys.has(k)) {\n const el = elementsByKey.get(k);\n const prevItem = prevItemsByKey.get(k);\n // Call create-returned cleanup first, then remove callback\n const cleanup = cleanupByKey.get(k);\n if (typeof cleanup === 'function') {\n try {\n cleanup();\n } catch (err) {\n logError(`[Lume.js] repeat(): cleanup error for key \"${k}\":`, err);\n }\n }\n if (typeof remove === 'function' && el) {\n remove(prevItem, el);\n }\n elementsByKey.delete(k);\n prevItemsByKey.delete(k);\n prevIndexByKey.delete(k);\n cleanupByKey.delete(k);\n }\n }\n }\n }, isReorder);\n }\n\n // Subscription — $subscribe calls updateList immediately (initial render),\n // so no separate updateList() call is needed for reactive stores.\n let unsubscribe;\n if (typeof store.$subscribe === 'function') {\n unsubscribe = store.$subscribe(arrayKey, updateList);\n } else if (typeof store.subscribe === 'function') {\n // Generic subscribe (e.g. computed) — subscribe first, then initial render\n const subResult = store.subscribe(() => updateList());\n updateList();\n // Normalize both function-style and object-style (RxJS Subscription) returns\n unsubscribe = typeof subResult === 'function'\n ? subResult\n : () => { subResult?.unsubscribe?.(); };\n } else {\n // Non-reactive store — render once and return cleanup\n updateList();\n logWarn('[Lume.js] repeat(): store is not reactive (no $subscribe or subscribe method)');\n return () => {\n for (const [k, el] of elementsByKey) {\n const prevItem = prevItemsByKey.get(k);\n const cleanup = cleanupByKey.get(k);\n if (typeof cleanup === 'function') {\n try {\n cleanup();\n } catch (err) {\n logError(`[Lume.js] repeat(): cleanup error for key \"${k}\":`, err);\n }\n }\n if (typeof remove === 'function') {\n remove(prevItem, el);\n }\n }\n containerEl.replaceChildren();\n elementsByKey.clear();\n prevItemsByKey.clear();\n prevIndexByKey.clear();\n cleanupByKey.clear();\n seenKeys.clear();\n };\n }\n\n return () => {\n if (typeof unsubscribe === 'function') {\n unsubscribe();\n }\n // Invoke cleanup and remove callback for all remaining elements before clearing\n for (const [k, el] of elementsByKey) {\n const prevItem = prevItemsByKey.get(k);\n const cleanup = cleanupByKey.get(k);\n if (typeof cleanup === 'function') {\n try {\n cleanup();\n } catch (err) {\n logError(`[Lume.js] repeat(): cleanup error for key \"${k}\":`, err);\n }\n }\n if (typeof remove === 'function') {\n remove(prevItem, el);\n }\n }\n // Clear DOM elements (replaceChildren is faster than loop)\n containerEl.replaceChildren();\n elementsByKey.clear();\n prevItemsByKey.clear();\n prevIndexByKey.clear();\n cleanupByKey.clear();\n seenKeys.clear();\n };\n}\n","/**\n * Lume-JS Debug Addon\n * \n * Developer-friendly logging and inspection of reactive state operations.\n * Critical for adoption - hard to debug = hard to adopt.\n * \n * Usage:\n * import { state } from \"lume-js\";\n * import { withPlugins, createDebugPlugin, debug } from \"lume-js/addons\";\n * \n * const store = withPlugins(state({ count: 0 }), [createDebugPlugin({ label: 'myStore' })]);\n * \n * debug.enable(); // Enable logging\n * debug.filter('count'); // Only log 'count' key\n * debug.stats(); // Show statistics\n * \n * @module addons/debug\n */\n\n// Global debug state\nlet globalEnabled = true;\nlet globalFilter = null; // string, RegExp, or null\nconst stats = new Map(); // label -> { gets: Map, sets: Map, notifies: Map }\n\n/**\n * Check if a key matches the current filter\n * @param {string} key\n * @returns {boolean}\n */\nfunction matchesFilter(key) {\n if (globalFilter === null) return true;\n if (typeof globalFilter === 'string') {\n return key.includes(globalFilter);\n }\n if (globalFilter instanceof RegExp) {\n return globalFilter.test(key);\n }\n return true;\n}\n\n/**\n * Get or create stats entry for a label\n * @param {string} label\n * @returns {object}\n */\nfunction getStats(label) {\n if (!stats.has(label)) {\n stats.set(label, {\n gets: new Map(),\n sets: new Map(),\n notifies: new Map()\n });\n }\n return stats.get(label);\n}\n\n/**\n * Increment a stat counter\n * @param {string} label\n * @param {'gets'|'sets'|'notifies'} type\n * @param {string} key\n */\nfunction incrementStat(label, type, key) {\n const s = getStats(label);\n const map = s[type];\n map.set(key, (map.get(key) || 0) + 1);\n}\n\nconst MAX_LOG_LEN = 100;\nconst TRUNCATED_LEN = MAX_LOG_LEN - 3;\n\n/**\n * Format value for logging (truncate long values)\n * @param {any} value\n * @returns {string}\n */\nfunction formatValue(value) {\n try {\n const json = JSON.stringify(value);\n if (json.length > MAX_LOG_LEN) {\n return json.slice(0, TRUNCATED_LEN) + '...';\n }\n return json;\n } catch {\n return String(value);\n }\n}\n\n/**\n * Create a debug plugin instance for a reactive state store.\n * \n * @param {object} [options] - Configuration options\n * @param {string} [options.label='store'] - Label for log messages\n * @param {boolean} [options.logGet=false] - Log property reads (can be noisy)\n * @param {boolean} [options.logSet=true] - Log property writes\n * @param {boolean} [options.logNotify=true] - Log subscriber notifications\n * @param {boolean} [options.trace=false] - Show stack trace for SET operations\n * @returns {object} Plugin object for state()\n * \n * @example\n * const store = withPlugins(state({ count: 0 }), [createDebugPlugin({ label: 'counter' })]);\n * \n * @example\n * // With stack traces for debugging where state changes originate\n * const store = withPlugins(state({ count: 0 }), [createDebugPlugin({ label: 'counter', trace: true })]);\n */\nexport function createDebugPlugin(options = {}) {\n const label = options.label ?? 'store';\n\n // IMPORTANT: Do NOT destructure options here!\n // Options may contain getters for dynamic runtime toggling (e.g., from UI).\n // Destructuring would copy values once at creation time, breaking reactivity.\n // Use getOpt() helper to read options dynamically in each hook.\n const getOpt = (name, defaultVal) => {\n const val = options[name];\n return val !== undefined ? val : defaultVal;\n };\n\n return {\n name: `debug:${label}`,\n\n onInit: () => {\n if (globalEnabled) {\n console.log(`%c[${label}]%c initialized`, 'color: #888; font-weight: bold', 'color: inherit');\n }\n },\n\n onGet: (key, value) => {\n // Skip internal properties\n if (typeof key === 'string' && key.startsWith('$')) {\n return value;\n }\n\n incrementStat(label, 'gets', key);\n\n if (globalEnabled && getOpt('logGet', false) && matchesFilter(key)) {\n console.log(\n `%c[${label}]%c GET %c${key}%c = ${formatValue(value)}`,\n 'color: #888; font-weight: bold',\n 'color: #4CAF50',\n 'color: #2196F3; font-weight: bold',\n 'color: inherit'\n );\n }\n\n return value;\n },\n\n onSet: (key, newValue, oldValue) => {\n // Skip internal properties\n if (typeof key === 'string' && key.startsWith('$')) {\n return newValue;\n }\n\n incrementStat(label, 'sets', key);\n\n if (globalEnabled && getOpt('logSet', true) && matchesFilter(key)) {\n console.log(\n `%c[${label}]%c SET %c${key}%c: ${formatValue(oldValue)} → ${formatValue(newValue)}`,\n 'color: #888; font-weight: bold',\n 'color: #FF9800',\n 'color: #2196F3; font-weight: bold',\n 'color: inherit'\n );\n\n // Show stack trace if enabled (helps find where state changes originate)\n if (getOpt('trace', false)) {\n console.trace(`%c[${label}] Stack trace for ${key}`, 'color: #888');\n }\n }\n\n return newValue;\n },\n\n onSubscribe: (key) => {\n if (globalEnabled && matchesFilter(key)) {\n console.log(\n `%c[${label}]%c SUBSCRIBE %c${key}`,\n 'color: #888; font-weight: bold',\n 'color: #9C27B0',\n 'color: #2196F3; font-weight: bold'\n );\n }\n },\n\n onNotify: (key, value) => {\n // Skip internal properties\n if (typeof key === 'string' && key.startsWith('$')) {\n return;\n }\n\n incrementStat(label, 'notifies', key);\n\n if (globalEnabled && getOpt('logNotify', true) && matchesFilter(key)) {\n console.log(\n `%c[${label}]%c NOTIFY %c${key}%c = ${formatValue(value)}`,\n 'color: #888; font-weight: bold',\n 'color: #E91E63',\n 'color: #2196F3; font-weight: bold',\n 'color: inherit'\n );\n }\n }\n };\n}\n\n/**\n * Global debug controls\n */\nexport const debug = {\n /**\n * Enable debug logging globally\n */\n enable() {\n globalEnabled = true;\n console.log('%c[lume-debug]%c Logging enabled', 'color: #888; font-weight: bold', 'color: #4CAF50');\n },\n\n /**\n * Disable debug logging globally\n */\n disable() {\n globalEnabled = false;\n console.log('%c[lume-debug]%c Logging disabled', 'color: #888; font-weight: bold', 'color: #F44336');\n },\n\n /**\n * Check if debug logging is currently enabled\n * @returns {boolean}\n */\n isEnabled() {\n return globalEnabled;\n },\n\n /**\n * Filter logs by key pattern\n * @param {string|RegExp|null} pattern - Pattern to match, or null to clear filter\n */\n filter(pattern) {\n globalFilter = pattern;\n if (pattern === null) {\n console.log('%c[lume-debug]%c Filter cleared', 'color: #888; font-weight: bold', 'color: inherit');\n } else {\n console.log(`%c[lume-debug]%c Filter set: ${pattern}`, 'color: #888; font-weight: bold', 'color: inherit');\n }\n },\n\n /**\n * Get current filter pattern\n * @returns {string|RegExp|null}\n */\n getFilter() {\n return globalFilter;\n },\n\n /**\n * Get statistics data (silent - no console output)\n * Use logStats() if you want to see stats in console.\n * @returns {object} Stats object for programmatic access\n */\n stats() {\n const result = {};\n\n for (const [label, data] of stats) {\n result[label] = {\n gets: Object.fromEntries(data.gets),\n sets: Object.fromEntries(data.sets),\n notifies: Object.fromEntries(data.notifies)\n };\n }\n\n return result;\n },\n\n /**\n * Log statistics summary to console (with formatting)\n * @returns {object} Stats object for programmatic access\n */\n logStats() {\n const result = this.stats();\n\n if (Object.keys(result).length === 0) {\n console.log('%c[lume-debug]%c No stats collected yet', 'color: #888; font-weight: bold', 'color: inherit');\n return result;\n }\n\n console.group('%c[lume-debug] Statistics', 'color: #888; font-weight: bold');\n\n for (const [label, data] of Object.entries(result)) {\n console.group(`%c${label}`, 'color: #2196F3; font-weight: bold');\n\n // Use console.table for better formatted output\n const tableData = [];\n const allKeys = new Set([\n ...Object.keys(data.gets),\n ...Object.keys(data.sets),\n ...Object.keys(data.notifies)\n ]);\n\n for (const key of allKeys) {\n tableData.push({\n key,\n gets: data.gets[key] || 0,\n sets: data.sets[key] || 0,\n notifies: data.notifies[key] || 0\n });\n }\n\n if (tableData.length > 0) {\n console.table(tableData);\n }\n\n console.groupEnd();\n }\n\n console.groupEnd();\n\n return result;\n },\n\n /**\n * Reset all collected statistics\n */\n resetStats() {\n stats.clear();\n console.log('%c[lume-debug]%c Stats reset', 'color: #888; font-weight: bold', 'color: inherit');\n }\n};\n","/**\n * Lume-JS withPlugins Addon\n *\n * Wraps a reactive state proxy with a plugin layer that intercepts\n * get/set/notify/subscribe operations via plugin hooks.\n *\n * Only stores that opt into debugging or custom behaviors need this.\n * Core state() is not aware of plugins.\n *\n * Usage:\n * import { state } from \"lume-js\";\n * import { withPlugins, createDebugPlugin } from \"lume-js/addons\";\n *\n * const store = withPlugins(state({ count: 0 }), [createDebugPlugin({ label: 'counter' })]);\n */\n\n/**\n * Wrap a reactive state proxy with plugin hooks.\n *\n * Plugin hooks (all optional):\n * onInit() — called once at wrap time\n * onGet(key, value) → value|void — intercept/transform reads\n * onSet(key, newVal, oldVal) → val|void — intercept/transform writes\n * onNotify(key, value) — called before subscribers are notified\n * onSubscribe(key) — called when $subscribe is invoked\n *\n * @param {object} store - A reactive proxy from state()\n * @param {Array<object>} plugins - Array of plugin objects\n * @returns {Proxy} A new proxy wrapping the store with plugin behavior\n */\nimport { logError } from '../utils/log.js';\n\nexport function withPlugins(store, plugins = []) {\n if (!plugins.length) return store;\n\n // Call onInit hooks once at wrap time\n for (const p of plugins) {\n try {\n p.onInit?.();\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onInit:`, e);\n }\n }\n\n // Track pending notifications for onNotify hooks.\n // Instead of a separate microtask, we hook into the underlying state's\n // flush via $beforeFlush so onNotify and subscribers share one microtask.\n const pendingNotifications = new Map();\n\n function runNotifyHooks() {\n for (const [key, value] of pendingNotifications) {\n for (const p of plugins) {\n try {\n p.onNotify?.(key, value);\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onNotify:`, e);\n }\n }\n }\n pendingNotifications.clear();\n }\n\n // Register once on the underlying state; capture unsubscribe for cleanup.\n let flushUnsub;\n if (typeof store.$beforeFlush === 'function') {\n flushUnsub = store.$beforeFlush(runNotifyHooks);\n }\n\n return new Proxy(store, {\n get(target, key) {\n // $dispose — remove the beforeFlush hook and clear pending state\n if (key === '$dispose') {\n return () => {\n if (flushUnsub) flushUnsub();\n pendingNotifications.clear();\n };\n }\n\n // Pass $-prefixed meta methods through without interception\n if (typeof key === 'string' && key.startsWith('$')) {\n const method = target[key];\n if (key === '$subscribe' && typeof method === 'function') {\n // Wrap $subscribe to call onSubscribe hooks\n return (subKey, fn) => {\n for (const p of plugins) {\n try {\n p.onSubscribe?.(subKey);\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onSubscribe:`, e);\n }\n }\n return method(subKey, fn);\n };\n }\n return method;\n }\n\n let value = target[key];\n\n // onGet chain\n for (const p of plugins) {\n try {\n const r = p.onGet?.(key, value);\n if (r !== undefined) value = r;\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onGet:`, e);\n }\n }\n\n return value;\n },\n\n set(target, key, value) {\n const oldValue = target[key];\n let newValue = value;\n\n // onSet chain\n for (const p of plugins) {\n try {\n const r = p.onSet?.(key, newValue, oldValue);\n if (r !== undefined) newValue = r;\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onSet:`, e);\n }\n }\n\n // Only queue onNotify if the value actually changed after plugin chain\n if (!Object.is(newValue, oldValue)) {\n pendingNotifications.set(key, newValue);\n }\n\n target[key] = newValue;\n return true;\n }\n });\n}\n","/**\n * Creates a cleanup group that can collect and dispose multiple\n * cleanup/unsubscribe functions at once.\n *\n * @returns {CleanupGroup}\n *\n * @example\n * ```js\n * import { createCleanupGroup } from 'lume-js/addons';\n *\n * const group = createCleanupGroup();\n * group.add(bindDom(root, store));\n * group.add(effect(() => { ... }));\n * group.add(store.$subscribe('key', fn));\n *\n * // Dispose everything at once\n * group.dispose();\n * ```\n */\nexport function createCleanupGroup() {\n const cleanups = [];\n\n return {\n /**\n * Add a cleanup function to the group.\n * @param {Function} fn - Cleanup/unsubscribe function\n */\n add(fn) {\n if (typeof fn === 'function') {\n cleanups.push(fn);\n }\n },\n\n /**\n * Run all collected cleanup functions and clear the group.\n */\n dispose() {\n while (cleanups.length) {\n const fn = cleanups.pop();\n try { fn(); } catch (e) { /* ignore cleanup errors */ }\n }\n },\n };\n}\n","/**\n * Reads initial state from a `<script type=\"application/json\">` element\n * embedded in the server-rendered HTML. Useful for SSR / hydration patterns.\n *\n * @param {string} [selector='#__LUME_DATA__'] - CSS selector for the script element\n * @returns {object} Parsed JSON object, or empty object if not found / invalid\n *\n * @example\n * ```html\n * <script id=\"__LUME_DATA__\" type=\"application/json\">\n * {\"title\": \"Welcome\", \"count\": 42}\n * </script>\n * ```\n *\n * ```js\n * import { state } from 'lume-js';\n * import { hydrateState } from 'lume-js/addons';\n *\n * const store = state(hydrateState());\n * ```\n */\nexport function hydrateState(selector = '#__LUME_DATA__') {\n const el = typeof document !== 'undefined' ? document.querySelector(selector) : null;\n if (!el) return {};\n try {\n return JSON.parse(el.textContent);\n } catch {\n return {};\n }\n}\n","export { computed } from \"./computed.js\";\nexport { watch } from \"./watch.js\";\nexport { repeat, defaultFocusPreservation, defaultScrollPreservation } from \"./repeat.js\";\nexport { createDebugPlugin, debug } from \"./debug.js\";\nexport { withPlugins } from \"./withPlugins.js\";\nexport { createCleanupGroup } from \"./cleanupGroup.js\";\nexport { hydrateState } from \"./hydrateState.js\";\n\n/**\n * Returns true if the value is a Lume reactive proxy created by state().\n * Uses duck-typing: checks for the presence of $subscribe.\n * @param {any} obj\n * @returns {boolean}\n */\nexport function isReactive(obj) {\n return !!(obj && typeof obj === 'object' && typeof obj.$subscribe === 'function');\n}\n"],"names":["container"],"mappings":";AA0DO,SAAS,SAAS,IAAI;AAC3B,MAAI,OAAO,OAAO,YAAY;AAC5B,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAEA,MAAI;AACJ,MAAI,gBAAgB;AACpB,MAAI,kBAAkB;AACtB,MAAI,WAAW;AACf,QAAM,cAAc,CAAA;AAGpB,QAAM,gBAAgB,OAAO,MAAM;AAIjC,QAAI,mBAAmB,SAAU;AAEjC,sBAAkB;AAElB,QAAI;AACF,YAAM,WAAW,GAAE;AAGnB,UAAI,CAAC,iBAAiB,CAAC,OAAO,GAAG,UAAU,WAAW,GAAG;AACvD,sBAAc;AACd,wBAAgB;AAGhB,oBAAY,QAAQ,cAAY,SAAS,WAAW,CAAC;AAAA,MACvD;AAAA,IACF,SAAS,OAAO;AACd,eAAS,4CAA4C,KAAK;AAE1D,UAAI,CAAC,iBAAiB,gBAAgB,QAAW;AAC/C,sBAAc;AACd,wBAAgB;AAGhB,oBAAY,QAAQ,cAAY,SAAS,WAAW,CAAC;AAAA,MACvD;AAAA,IACF,UAAC;AAGC,qBAAe,MAAM;AACnB,YAAI,CAAC,UAAU;AACb,4BAAkB;AAAA,QACpB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL,IAAI,QAAQ;AACV,UAAI,CAAC,eAAe;AAClB,cAAM,IAAI,MAAM,+CAA+C;AAAA,MACjE;AACA,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQA,UAAU,UAAU;AAClB,UAAI,OAAO,aAAa,YAAY;AAClC,cAAM,IAAI,MAAM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O,YAAY;AAC5B,iBAAS,KAAK,EAAE;AAAA,MAClB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,UAAU;AACR,aAAO,SAAS,QAAQ;AACtB,cAAM,KAAK,SAAS,IAAG;AACvB,YAAI;AAAE,aAAE;AAAA,QAAI,SAAS,GAAG;AAAA,QAA8B;AAAA,MACxD;AAAA,IACF;AAAA,EACJ;AACA;ACtBO,SAAS,aAAa,WAAW,kBAAkB;AACxD,QAAM,KAAK,OAAO,aAAa,cAAc,SAAS,cAAc,QAAQ,IAAI;AAChF,MAAI,CAAC,GAAI,QAAO,CAAA;AAChB,MAAI;AACF,WAAO,KAAK,MAAM,GAAG,WAAW;AAAA,EAClC,QAAQ;AACN,WAAO,CAAA;AAAA,EACT;AACF;ACfO,SAAS,WAAW,KAAK;AAC9B,SAAO,CAAC,EAAE,OAAO,OAAO,QAAQ,YAAY,OAAO,IAAI,eAAe;AACxE;"}
|
|
1
|
+
{"version":3,"file":"addons.mjs","sources":["../src/addons/computed.js","../src/addons/watch.js","../src/addons/repeat.js","../src/addons/debug.js","../src/addons/withPlugins.js","../src/addons/cleanupGroup.js","../src/addons/hydrateState.js","../src/addons/persist.js","../src/addons/index.js"],"sourcesContent":["/**\n * Lume-JS Computed Addon\n * \n * Creates computed values that automatically update when dependencies change.\n * Uses core effect() for automatic dependency tracking.\n * \n * Usage:\n * import { computed } from \"lume-js/addons/computed\";\n * \n * const doubled = computed(() => store.count * 2);\n * console.log(doubled.value); // Auto-updates when store.count changes\n * \n * Features:\n * - Automatic dependency tracking (no manual recompute)\n * - Cached values (only recomputes when dependencies change)\n * - Subscribe to changes\n * - Cleanup with dispose()\n * \n * @module addons/computed\n */\n\nimport { effect } from '../core/effect.js';\nimport { logError } from '../utils/log.js';\n\n/**\n * Creates a computed value with automatic dependency tracking\n * \n * The computation function runs immediately and tracks which state\n * properties are accessed. When any dependency changes, the value\n * is automatically recomputed.\n *\n * ⚠️ Circular self-mutations are automatically suppressed. If a computed\n * mutates a state property it depends on, the flush triggered by that\n * mutation is skipped to prevent an infinite microtask loop.\n *\n * @security After each computation, a re-entry guard stays active until the\n * next microtask. If a dependency changes synchronously during this window,\n * the computed will not recompute until a subsequent microtask. This is\n * intentional — it prevents infinite loops from self-mutating computeds.\n *\n * @param {function} fn - Function that computes the value\n * @returns {object} Object with .value property and methods\n * \n * @example\n * const store = state({ count: 5 });\n * \n * const doubled = computed(() => store.count * 2);\n * console.log(doubled.value); // 10\n * \n * store.count = 10;\n * // After microtask:\n * console.log(doubled.value); // 20 (auto-updated)\n * \n * @example\n * // Subscribe to changes\n * const unsub = doubled.subscribe(value => {\n * console.log('Doubled changed to:', value);\n * });\n * \n * @example\n * // Cleanup\n * doubled.dispose();\n */\nexport function computed(fn) {\n if (typeof fn !== 'function') {\n throw new Error('computed() requires a function');\n }\n\n let cachedValue;\n let isInitialized = false;\n let isInComputation = false;\n let disposed = false;\n const subscribers = [];\n\n // Use effect to automatically track dependencies\n const cleanupEffect = effect(() => {\n // Skip re-entry from a flush triggered by our own synchronous mutation.\n // The mutation inside fn() queues a microtask flush; we stay flagged\n // until a subsequent microtask clears it, so that flush is dropped.\n if (isInComputation || disposed) return;\n\n isInComputation = true;\n\n try {\n const newValue = fn();\n\n // Check if value actually changed - Object.is() handles NaN and -0\n if (!isInitialized || !Object.is(newValue, cachedValue)) {\n cachedValue = newValue;\n isInitialized = true;\n\n // Notify all subscribers\n subscribers.forEach(callback => callback(cachedValue));\n }\n } catch (error) {\n logError('[Lume.js computed] Error in computation:', error);\n // Set to undefined on error, mark as initialized\n if (!isInitialized || cachedValue !== undefined) {\n cachedValue = undefined;\n isInitialized = true;\n\n // Notify subscribers of error state\n subscribers.forEach(callback => callback(cachedValue));\n }\n } finally {\n // Defer clearing the flag so any flush microtask queued by fn()\n // sees it still set and skips re-entry.\n queueMicrotask(() => {\n if (!disposed) {\n isInComputation = false;\n }\n });\n }\n });\n\n return {\n /**\n * Get the current computed value\n */\n get value() {\n if (!isInitialized) {\n throw new Error('Computed value accessed before initialization');\n }\n return cachedValue;\n },\n\n /**\n * Subscribe to changes in computed value\n * \n * @param {function} callback - Called when value changes\n * @returns {function} Unsubscribe function\n */\n subscribe(callback) {\n if (typeof callback !== 'function') {\n throw new Error('subscribe() requires a function');\n }\n\n subscribers.push(callback);\n\n // Call immediately with current value\n if (isInitialized) {\n callback(cachedValue);\n }\n\n // Return unsubscribe function\n return () => {\n const index = subscribers.indexOf(callback);\n if (index > -1) {\n subscribers.splice(index, 1);\n }\n };\n },\n\n /**\n * Clean up computed value and stop tracking\n */\n dispose() {\n disposed = true;\n cleanupEffect();\n subscribers.length = 0;\n isInitialized = false;\n isInComputation = false;\n }\n };\n}","/**\n * watch - observes changes to a state key and triggers callback\n * @param {Object} store - reactive store created with state()\n * @param {string} key - key in store to watch\n * @param {Function} callback - called with new value\n * @param {Object} [options]\n * @param {boolean} [options.immediate=true] - call callback immediately with current value\n * @returns {Function} unsubscribe function\n */\nexport function watch(store, key, callback, { immediate = true } = {}) {\n if (!store.$subscribe) {\n throw new Error(\"store must be created with state()\");\n }\n if (!immediate) {\n let skipped = false;\n return store.$subscribe(key, (val) => {\n if (!skipped) { skipped = true; return; }\n callback(val);\n });\n }\n return store.$subscribe(key, callback);\n}","/**\n * Lume-JS List Rendering (Addon)\n *\n * Renders lists with automatic subscription and element reuse by key.\n * \n * Core guarantees:\n * Element reuse by key (same DOM nodes, not recreated)\n * Minimal DOM operations (only updates what changed)\n * Memory efficiency (cleanup on remove)\n * \n * Default behavior (can be disabled/customized):\n * ✅ Focus preservation (maintains activeElement and selection)\n * ✅ Scroll preservation (intelligent positioning for add/remove/reorder)\n * \n * Philosophy: No artificial limitations\n * - All preservation logic is overridable via options\n * - Set to null/false to disable, or provide custom functions\n * - Export utilities so you can wrap/extend them\n *\n * ⚠️ IMPORTANT: Arrays must be updated immutably!\n * store.items.push(x) // ❌ Won't trigger update\n * store.items = [...items] // ✅ Triggers update\n * \n * ═══════════════════════════════════════════════════════════════════════\n * PATTERN 0: Template-based (recommended) — declarative, zero DOM code\n * ═══════════════════════════════════════════════════════════════════════\n *\n * HTML — a standard <template> element, valid HTML, no custom syntax:\n *\n * <ul id=\"list\">\n * <template>\n * <li>\n * <strong data-bind=\"name\"></strong>\n * <span data-bind=\"role\"></span>\n * <em data-bind=\"$index\"></em>\n * </li>\n * </template>\n * </ul>\n *\n * JS:\n *\n * repeat('#list', store, 'people', {\n * key: p => p.id,\n * template: true // use the <template> inside the container\n * });\n *\n * data-bind paths resolve against EACH ITEM: \"name\" → item.name,\n * \"user.city\" → item.user.city, \"$item\" → the item itself (primitive\n * arrays), \"$index\" → current index. Inputs get .value/.checked, other\n * elements get textContent — identical semantics to bindDom's data-bind.\n * These are one-way snapshot bindings re-applied per list update (items\n * are plain objects, not stores). Combine with create/update for event\n * listeners or extra binding. template also accepts a CSS selector or an\n * HTMLTemplateElement.\n *\n * ═══════════════════════════════════════════════════════════════════════\n * PATTERN 1: Simple (render only) - for simple cases or backward compat\n * ═══════════════════════════════════════════════════════════════════════\n * \n * repeat('#list', store, 'todos', {\n * key: todo => todo.id,\n * render: (todo, el) => {\n * el.textContent = todo.name; // Called on every update\n * }\n * });\n *\n * ═══════════════════════════════════════════════════════════════════════\n * PATTERN 2: Clean separation (create + update) - recommended\n * ═══════════════════════════════════════════════════════════════════════\n *\n * repeat('#list', store, 'todos', {\n * key: todo => todo.id,\n * create: (todo, el) => {\n * // Called ONCE when element is created - build DOM structure\n * const nameSpan = document.createElement('span');\n * nameSpan.className = 'name';\n * el.appendChild(nameSpan);\n * const btn = document.createElement('button');\n * btn.textContent = 'Delete';\n * btn.onclick = () => deleteTodo(todo.id);\n * el.appendChild(btn);\n *\n * // Return a cleanup function — called automatically when element is removed\n * return () => {\n * // Unsubscribe from external listeners, remove timers, etc.\n * };\n * },\n * update: (todo, el, index, { isFirstRender }) => {\n * // Called on every update - bind data\n * // isFirstRender = true on initial render, false on subsequent\n * // Skipped if same object reference (optimization)\n * el.querySelector('.name').textContent = todo.name;\n * }\n * });\n *\n * ═══════════════════════════════════════════════════════════════════════\n * ADVANCED: Custom preservation strategies\n * ═══════════════════════════════════════════════════════════════════════\n * \n * import { defaultFocusPreservation, defaultScrollPreservation } from \"lume-js/addons\";\n * \n * repeat('#list', store, 'items', {\n * key: item => item.id,\n * create: (item, el) => { ... },\n * update: (item, el) => { ... },\n * preserveFocus: null, // disable focus preservation\n * preserveScroll: (container, context) => {\n * const restore = defaultScrollPreservation(container, context);\n * return () => { restore(); console.log('Scroll restored!'); };\n * }\n * });\n */\nimport { logWarn, logError } from '../utils/log.js';\nimport { applyBindValue } from '../core/bindDom.js';\n\n/**\n * Resolve the template option to its single root element.\n * Accepts true (first <template> inside the container), a CSS selector,\n * or an HTMLTemplateElement directly.\n */\nfunction resolveTemplateRoot(template, containerEl) {\n let templateEl = template;\n if (template === true) {\n templateEl = containerEl.querySelector('template');\n } else if (typeof template === 'string') {\n templateEl = document.querySelector(template);\n }\n if (!templateEl || templateEl.tagName !== 'TEMPLATE') {\n throw new Error('[Lume.js] repeat(): template not found or not a <template> element');\n }\n if (templateEl.content.children.length !== 1) {\n throw new Error('[Lume.js] repeat(): template must contain exactly one root element');\n }\n return templateEl.content.firstElementChild;\n}\n\n/**\n * Collect [data-bind] nodes of a cloned item element into a compiled\n * binding list. Paths are resolved against the ITEM (not the store):\n * data-bind=\"name\" → item.name\n * data-bind=\"user.city\" → item.user.city\n * data-bind=\"$item\" → the item itself (for primitive arrays)\n * data-bind=\"$index\" → the item's current index\n */\nfunction collectItemBindings(el) {\n const bindings = [];\n const add = (node) => {\n const path = node.getAttribute('data-bind');\n bindings.push({ node, path, keys: path === '$item' || path === '$index' ? null : path.split('.') });\n };\n if (el.hasAttribute('data-bind')) add(el);\n for (const node of el.querySelectorAll('[data-bind]')) add(node);\n return bindings;\n}\n\nfunction applyItemBindings(bindings, item, index) {\n for (const b of bindings) {\n let val;\n if (b.path === '$index') {\n val = index;\n } else if (b.path === '$item') {\n val = item;\n } else {\n val = item;\n for (let i = 0; i < b.keys.length && val != null; i++) {\n val = val[b.keys[i]];\n }\n }\n applyBindValue(b.node, val);\n }\n}\n\n/**\n * Default focus preservation strategy\n * Saves activeElement and selection state before DOM updates\n * \n * @param {HTMLElement} container - The list container\n * @returns {Function|null} Restore function, or null if nothing to restore\n */\nexport function defaultFocusPreservation(container) {\n const activeEl = document.activeElement;\n const shouldRestore = container.contains(activeEl);\n\n if (!shouldRestore) return null;\n\n let selectionStart = null;\n let selectionEnd = null;\n\n if (activeEl.tagName === 'INPUT' || activeEl.tagName === 'TEXTAREA') {\n selectionStart = activeEl.selectionStart;\n selectionEnd = activeEl.selectionEnd;\n }\n\n return () => {\n if (document.body.contains(activeEl)) {\n activeEl.focus();\n if (selectionStart !== null && selectionEnd !== null) {\n activeEl.setSelectionRange(selectionStart, selectionEnd);\n }\n }\n };\n}\n\n/**\n * Default scroll preservation strategy\n * Uses anchor-based preservation for add/remove, pixel position for reorder\n * \n * @param {HTMLElement} container - The list container\n * @param {Object} context - Additional context\n * @param {boolean} context.isReorder - Whether this is a reorder operation\n * @returns {Function} Restore function\n */\nexport function defaultScrollPreservation(container, context = {}) {\n const { isReorder = false } = context;\n const scrollTop = container.scrollTop;\n\n // Early return if no scroll\n if (scrollTop === 0) {\n return () => { container.scrollTop = 0; };\n }\n\n let anchorElement = null;\n let anchorOffset = 0;\n\n // Only use anchor-based preservation for add/remove, not reorder\n if (!isReorder) {\n const containerRect = container.getBoundingClientRect();\n // Avoid Array.from - iterate children directly\n for (let child = container.firstElementChild; child; child = child.nextElementSibling) {\n const rect = child.getBoundingClientRect();\n\n if (rect.bottom > containerRect.top) {\n anchorElement = child;\n anchorOffset = rect.top - containerRect.top;\n break;\n }\n }\n }\n\n return () => {\n if (anchorElement && document.body.contains(anchorElement)) {\n const newRect = anchorElement.getBoundingClientRect();\n const containerRect = container.getBoundingClientRect();\n const currentOffset = newRect.top - containerRect.top;\n const scrollAdjustment = currentOffset - anchorOffset;\n\n container.scrollTop = container.scrollTop + scrollAdjustment;\n } else {\n container.scrollTop = scrollTop;\n }\n };\n}\n\n/**\n * Efficiently render a list with element reuse\n * \n * @param {string|HTMLElement} container - Container element or selector\n * @param {Object} store - Reactive state object\n * @param {string} arrayKey - Key in store containing the array\n * @param {Object} options - Configuration\n * @param {Function} options.key - Function to extract unique key: (item) => key\n * @param {Function} [options.render] - Function to render item (called for all items): (item, element, index) => void\n * @param {Function} [options.create] - Function for new elements only: (item, element, index) => void | Function. If a function is returned, it is registered as the element's cleanup and called automatically when the element is removed (by list update or full cleanup).\n * @param {Function} [options.update] - Function for data binding: (item, element, index, { isFirstRender }) => void. Skipped if same item reference AND same index.\n * @param {Function} [options.remove] - Additional cleanup when element is removed: (item, element) => void. Called after any cleanup function returned by create(). Optional — prefer returning a cleanup from create() for automatic lifecycle management.\n * @param {true|string|HTMLTemplateElement} [options.template] - Declarative item structure from a <template> element: true = first <template> inside the container, string = CSS selector, or the element itself. The template must have exactly one root element; it is cloned per item and its [data-bind] paths are bound to the item on every update (\"name\", \"user.city\", \"$item\", \"$index\"). When set, options.element is ignored and options.render is ignored (with a warning); create/update remain available on top.\n * @param {string|Function} [options.element='div'] - Element tag name or factory function (ignored when options.template is set)\n * @param {Function|null} [options.preserveFocus=defaultFocusPreservation] - Focus preservation strategy (null to disable)\n * @param {Function|null} [options.preserveScroll=defaultScrollPreservation] - Scroll preservation strategy (null to disable)\n * @returns {Function} Cleanup function\n */\n\nexport function repeat(container, store, arrayKey, options) {\n const {\n key,\n render,\n create,\n update,\n remove,\n template = null,\n element = 'div',\n preserveFocus = defaultFocusPreservation,\n preserveScroll = defaultScrollPreservation\n } = options;\n\n // Resolve container\n const containerEl =\n typeof container === 'string'\n ? document.querySelector(container)\n : container;\n\n if (!containerEl) {\n logWarn(`[Lume.js] repeat(): container \"${container}\" not found`);\n return () => { };\n }\n\n if (typeof key !== 'function') {\n throw new Error('[Lume.js] repeat(): options.key must be a function');\n }\n\n // Template mode: structure and data binding come from the <template>;\n // render/create/update are all optional on top of it.\n const templateRoot = template ? resolveTemplateRoot(template, containerEl) : null;\n\n if (templateRoot && typeof render === 'function') {\n logWarn('[Lume.js] repeat(): options.render is ignored when options.template is set — use create/update instead');\n }\n\n if (!templateRoot && typeof render !== 'function' && typeof create !== 'function') {\n throw new Error('[Lume.js] repeat(): options.render or options.create must be a function');\n }\n\n // key -> HTMLElement\n const elementsByKey = new Map();\n // key -> previous item (for reference comparison)\n const prevItemsByKey = new Map();\n // key -> previous index (for reorder detection)\n const prevIndexByKey = new Map();\n // key -> cleanup function returned by create()\n const cleanupByKey = new Map();\n // key -> compiled [data-bind] nodes of the clone (template mode only)\n const bindingsByKey = new Map();\n const seenKeys = new Set();\n\n function createElement() {\n if (templateRoot) return templateRoot.cloneNode(true);\n return typeof element === 'function'\n ? element()\n : document.createElement(element);\n }\n\n function reconcileDOM(container, nextEls) {\n let ptr = container.firstChild;\n\n for (let i = 0; i < nextEls.length; i++) {\n const desired = nextEls[i];\n\n if (ptr === desired) {\n ptr = ptr.nextSibling;\n continue;\n }\n\n container.insertBefore(desired, ptr);\n }\n\n // Remove leftover children not in nextEls\n while (ptr) {\n const next = ptr.nextSibling;\n container.removeChild(ptr);\n ptr = next;\n }\n }\n\n function applyPreservation(container, fn, isReorder) {\n const shouldPreserve = document.body.contains(container);\n const restoreFocus = shouldPreserve && preserveFocus ? preserveFocus(container) : null;\n const restoreScroll = shouldPreserve && preserveScroll ? preserveScroll(container, { isReorder }) : null;\n\n fn();\n\n if (restoreFocus) restoreFocus();\n if (restoreScroll) restoreScroll();\n }\n\n // eslint-disable-next-line sonarjs/cognitive-complexity -- keyed DOM reconciliation: create/reuse/remove nodes, key dedup, scroll/focus preservation\n function updateList() {\n const items = store[arrayKey];\n\n if (!Array.isArray(items)) {\n logWarn(`[Lume.js] repeat(): store.${arrayKey} is not an array`);\n return;\n }\n\n // Only compute isReorder if scroll preservation needs it.\n // Uses elementsByKey (previous state) and items directly — no Set allocations.\n let isReorder = false;\n if (preserveScroll && elementsByKey.size === items.length) {\n isReorder = true;\n for (let i = 0; i < items.length; i++) {\n if (!elementsByKey.has(key(items[i]))) { isReorder = false; break; }\n }\n }\n\n seenKeys.clear();\n const nextEls = [];\n\n // Build ordered list of DOM nodes (created or reused)\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const k = key(item);\n\n if (seenKeys.has(k)) {\n logWarn(`[Lume.js] repeat(): duplicate key \"${k}\"`);\n continue;\n }\n seenKeys.add(k);\n\n let el = elementsByKey.get(k);\n const isFirstRender = !el;\n\n if (isFirstRender) {\n el = createElement();\n elementsByKey.set(k, el);\n if (templateRoot) {\n bindingsByKey.set(k, collectItemBindings(el));\n }\n }\n\n try {\n // Call create for new elements (DOM structure / event listeners)\n if (isFirstRender && create) {\n const cleanup = create(item, el, i);\n if (typeof cleanup === 'function') {\n cleanupByKey.set(k, cleanup);\n }\n }\n\n // Data binding (new and existing elements)\n // Skip if same item reference AND same index (optimization)\n const prevItem = prevItemsByKey.get(k);\n const prevIndex = prevIndexByKey.get(k);\n if (templateRoot) {\n if (prevItem !== item || prevIndex !== i) {\n applyItemBindings(bindingsByKey.get(k), item, i);\n // update is optional extra binding on top of the template\n if (update) update(item, el, i, { isFirstRender });\n }\n } else if (update) {\n if (prevItem !== item || prevIndex !== i) {\n update(item, el, i, { isFirstRender });\n }\n } else if (render) {\n // Backward compatibility: render handles both create and update\n render(item, el, i);\n }\n\n // Store reference and index for next comparison\n prevItemsByKey.set(k, item);\n prevIndexByKey.set(k, i);\n\n } catch (err) {\n logError(`[Lume.js] repeat(): error rendering key \"${k}\":`, err);\n }\n\n nextEls.push(el);\n }\n\n // eslint-disable-next-line sonarjs/cognitive-complexity -- DOM cleanup pass: remove stale nodes, call per-item cleanup callbacks, update maps\n applyPreservation(containerEl, () => {\n reconcileDOM(containerEl, nextEls);\n\n // Clean maps: remove keys not in seenKeys (new state)\n if (elementsByKey.size !== seenKeys.size) {\n for (const k of elementsByKey.keys()) {\n if (!seenKeys.has(k)) {\n const el = elementsByKey.get(k);\n const prevItem = prevItemsByKey.get(k);\n // Call create-returned cleanup first, then remove callback\n const cleanup = cleanupByKey.get(k);\n if (typeof cleanup === 'function') {\n try {\n cleanup();\n } catch (err) {\n logError(`[Lume.js] repeat(): cleanup error for key \"${k}\":`, err);\n }\n }\n if (typeof remove === 'function' && el) {\n remove(prevItem, el);\n }\n elementsByKey.delete(k);\n prevItemsByKey.delete(k);\n prevIndexByKey.delete(k);\n cleanupByKey.delete(k);\n bindingsByKey.delete(k);\n }\n }\n }\n }, isReorder);\n }\n\n // Subscription — $subscribe calls updateList immediately (initial render),\n // so no separate updateList() call is needed for reactive stores.\n let unsubscribe;\n if (typeof store.$subscribe === 'function') {\n unsubscribe = store.$subscribe(arrayKey, updateList);\n } else if (typeof store.subscribe === 'function') {\n // Generic subscribe (e.g. computed) — subscribe first, then initial render\n const subResult = store.subscribe(() => updateList());\n updateList();\n // Normalize both function-style and object-style (RxJS Subscription) returns\n unsubscribe = typeof subResult === 'function'\n ? subResult\n : () => { subResult?.unsubscribe?.(); };\n } else {\n // Non-reactive store — render once and return cleanup\n updateList();\n logWarn('[Lume.js] repeat(): store is not reactive (no $subscribe or subscribe method)');\n return () => {\n for (const [k, el] of elementsByKey) {\n const prevItem = prevItemsByKey.get(k);\n const cleanup = cleanupByKey.get(k);\n if (typeof cleanup === 'function') {\n try {\n cleanup();\n } catch (err) {\n logError(`[Lume.js] repeat(): cleanup error for key \"${k}\":`, err);\n }\n }\n if (typeof remove === 'function') {\n remove(prevItem, el);\n }\n }\n containerEl.replaceChildren();\n elementsByKey.clear();\n prevItemsByKey.clear();\n prevIndexByKey.clear();\n cleanupByKey.clear();\n bindingsByKey.clear();\n seenKeys.clear();\n };\n }\n\n return () => {\n if (typeof unsubscribe === 'function') {\n unsubscribe();\n }\n // Invoke cleanup and remove callback for all remaining elements before clearing\n for (const [k, el] of elementsByKey) {\n const prevItem = prevItemsByKey.get(k);\n const cleanup = cleanupByKey.get(k);\n if (typeof cleanup === 'function') {\n try {\n cleanup();\n } catch (err) {\n logError(`[Lume.js] repeat(): cleanup error for key \"${k}\":`, err);\n }\n }\n if (typeof remove === 'function') {\n remove(prevItem, el);\n }\n }\n // Clear DOM elements (replaceChildren is faster than loop)\n containerEl.replaceChildren();\n elementsByKey.clear();\n prevItemsByKey.clear();\n prevIndexByKey.clear();\n cleanupByKey.clear();\n bindingsByKey.clear();\n seenKeys.clear();\n };\n}\n","/**\n * Lume-JS Debug Addon\n * \n * Developer-friendly logging and inspection of reactive state operations.\n * Critical for adoption - hard to debug = hard to adopt.\n * \n * Usage:\n * import { state } from \"lume-js\";\n * import { withPlugins, createDebugPlugin, debug } from \"lume-js/addons\";\n * \n * const store = withPlugins(state({ count: 0 }), [createDebugPlugin({ label: 'myStore' })]);\n * \n * debug.enable(); // Enable logging\n * debug.filter('count'); // Only log 'count' key\n * debug.stats(); // Show statistics\n * \n * @module addons/debug\n */\n\n// Global debug state\nlet globalEnabled = true;\nlet globalFilter = null; // string, RegExp, or null\nconst stats = new Map(); // label -> { gets: Map, sets: Map, notifies: Map }\n\n/**\n * Check if a key matches the current filter\n * @param {string} key\n * @returns {boolean}\n */\nfunction matchesFilter(key) {\n if (globalFilter === null) return true;\n if (typeof globalFilter === 'string') {\n return key.includes(globalFilter);\n }\n if (globalFilter instanceof RegExp) {\n return globalFilter.test(key);\n }\n return true;\n}\n\n/**\n * Get or create stats entry for a label\n * @param {string} label\n * @returns {object}\n */\nfunction getStats(label) {\n if (!stats.has(label)) {\n stats.set(label, {\n gets: new Map(),\n sets: new Map(),\n notifies: new Map()\n });\n }\n return stats.get(label);\n}\n\n/**\n * Increment a stat counter\n * @param {string} label\n * @param {'gets'|'sets'|'notifies'} type\n * @param {string} key\n */\nfunction incrementStat(label, type, key) {\n const s = getStats(label);\n const map = s[type];\n map.set(key, (map.get(key) || 0) + 1);\n}\n\nconst MAX_LOG_LEN = 100;\nconst TRUNCATED_LEN = MAX_LOG_LEN - 3;\n\n/**\n * Format value for logging (truncate long values)\n * @param {any} value\n * @returns {string}\n */\nfunction formatValue(value) {\n try {\n const json = JSON.stringify(value);\n if (json.length > MAX_LOG_LEN) {\n return json.slice(0, TRUNCATED_LEN) + '...';\n }\n return json;\n } catch {\n return String(value);\n }\n}\n\n/**\n * Create a debug plugin instance for a reactive state store.\n * \n * @param {object} [options] - Configuration options\n * @param {string} [options.label='store'] - Label for log messages\n * @param {boolean} [options.logGet=false] - Log property reads (can be noisy)\n * @param {boolean} [options.logSet=true] - Log property writes\n * @param {boolean} [options.logNotify=true] - Log subscriber notifications\n * @param {boolean} [options.trace=false] - Show stack trace for SET operations\n * @returns {object} Plugin object for state()\n * \n * @example\n * const store = withPlugins(state({ count: 0 }), [createDebugPlugin({ label: 'counter' })]);\n * \n * @example\n * // With stack traces for debugging where state changes originate\n * const store = withPlugins(state({ count: 0 }), [createDebugPlugin({ label: 'counter', trace: true })]);\n */\nexport function createDebugPlugin(options = {}) {\n const label = options.label ?? 'store';\n\n // IMPORTANT: Do NOT destructure options here!\n // Options may contain getters for dynamic runtime toggling (e.g., from UI).\n // Destructuring would copy values once at creation time, breaking reactivity.\n // Use getOpt() helper to read options dynamically in each hook.\n const getOpt = (name, defaultVal) => {\n const val = options[name];\n return val !== undefined ? val : defaultVal;\n };\n\n return {\n name: `debug:${label}`,\n\n onInit: () => {\n if (globalEnabled) {\n console.log(`%c[${label}]%c initialized`, 'color: #888; font-weight: bold', 'color: inherit');\n }\n },\n\n onGet: (key, value) => {\n // Skip internal properties\n if (typeof key === 'string' && key.startsWith('$')) {\n return value;\n }\n\n incrementStat(label, 'gets', key);\n\n if (globalEnabled && getOpt('logGet', false) && matchesFilter(key)) {\n console.log(\n `%c[${label}]%c GET %c${key}%c = ${formatValue(value)}`,\n 'color: #888; font-weight: bold',\n 'color: #4CAF50',\n 'color: #2196F3; font-weight: bold',\n 'color: inherit'\n );\n }\n\n return value;\n },\n\n onSet: (key, newValue, oldValue) => {\n // Skip internal properties\n if (typeof key === 'string' && key.startsWith('$')) {\n return newValue;\n }\n\n incrementStat(label, 'sets', key);\n\n if (globalEnabled && getOpt('logSet', true) && matchesFilter(key)) {\n console.log(\n `%c[${label}]%c SET %c${key}%c: ${formatValue(oldValue)} → ${formatValue(newValue)}`,\n 'color: #888; font-weight: bold',\n 'color: #FF9800',\n 'color: #2196F3; font-weight: bold',\n 'color: inherit'\n );\n\n // Show stack trace if enabled (helps find where state changes originate)\n if (getOpt('trace', false)) {\n console.trace(`%c[${label}] Stack trace for ${key}`, 'color: #888');\n }\n }\n\n return newValue;\n },\n\n onSubscribe: (key) => {\n if (globalEnabled && matchesFilter(key)) {\n console.log(\n `%c[${label}]%c SUBSCRIBE %c${key}`,\n 'color: #888; font-weight: bold',\n 'color: #9C27B0',\n 'color: #2196F3; font-weight: bold'\n );\n }\n },\n\n onNotify: (key, value) => {\n // Skip internal properties\n if (typeof key === 'string' && key.startsWith('$')) {\n return;\n }\n\n incrementStat(label, 'notifies', key);\n\n if (globalEnabled && getOpt('logNotify', true) && matchesFilter(key)) {\n console.log(\n `%c[${label}]%c NOTIFY %c${key}%c = ${formatValue(value)}`,\n 'color: #888; font-weight: bold',\n 'color: #E91E63',\n 'color: #2196F3; font-weight: bold',\n 'color: inherit'\n );\n }\n }\n };\n}\n\n/**\n * Global debug controls\n */\nexport const debug = {\n /**\n * Enable debug logging globally\n */\n enable() {\n globalEnabled = true;\n console.log('%c[lume-debug]%c Logging enabled', 'color: #888; font-weight: bold', 'color: #4CAF50');\n },\n\n /**\n * Disable debug logging globally\n */\n disable() {\n globalEnabled = false;\n console.log('%c[lume-debug]%c Logging disabled', 'color: #888; font-weight: bold', 'color: #F44336');\n },\n\n /**\n * Check if debug logging is currently enabled\n * @returns {boolean}\n */\n isEnabled() {\n return globalEnabled;\n },\n\n /**\n * Filter logs by key pattern\n * @param {string|RegExp|null} pattern - Pattern to match, or null to clear filter\n */\n filter(pattern) {\n globalFilter = pattern;\n if (pattern === null) {\n console.log('%c[lume-debug]%c Filter cleared', 'color: #888; font-weight: bold', 'color: inherit');\n } else {\n console.log(`%c[lume-debug]%c Filter set: ${pattern}`, 'color: #888; font-weight: bold', 'color: inherit');\n }\n },\n\n /**\n * Get current filter pattern\n * @returns {string|RegExp|null}\n */\n getFilter() {\n return globalFilter;\n },\n\n /**\n * Get statistics data (silent - no console output)\n * Use logStats() if you want to see stats in console.\n * @returns {object} Stats object for programmatic access\n */\n stats() {\n const result = {};\n\n for (const [label, data] of stats) {\n result[label] = {\n gets: Object.fromEntries(data.gets),\n sets: Object.fromEntries(data.sets),\n notifies: Object.fromEntries(data.notifies)\n };\n }\n\n return result;\n },\n\n /**\n * Log statistics summary to console (with formatting)\n * @returns {object} Stats object for programmatic access\n */\n logStats() {\n const result = this.stats();\n\n if (Object.keys(result).length === 0) {\n console.log('%c[lume-debug]%c No stats collected yet', 'color: #888; font-weight: bold', 'color: inherit');\n return result;\n }\n\n console.group('%c[lume-debug] Statistics', 'color: #888; font-weight: bold');\n\n for (const [label, data] of Object.entries(result)) {\n console.group(`%c${label}`, 'color: #2196F3; font-weight: bold');\n\n // Use console.table for better formatted output\n const tableData = [];\n const allKeys = new Set([\n ...Object.keys(data.gets),\n ...Object.keys(data.sets),\n ...Object.keys(data.notifies)\n ]);\n\n for (const key of allKeys) {\n tableData.push({\n key,\n gets: data.gets[key] || 0,\n sets: data.sets[key] || 0,\n notifies: data.notifies[key] || 0\n });\n }\n\n if (tableData.length > 0) {\n console.table(tableData);\n }\n\n console.groupEnd();\n }\n\n console.groupEnd();\n\n return result;\n },\n\n /**\n * Reset all collected statistics\n */\n resetStats() {\n stats.clear();\n console.log('%c[lume-debug]%c Stats reset', 'color: #888; font-weight: bold', 'color: inherit');\n }\n};\n","/**\n * Lume-JS withPlugins Addon\n *\n * Wraps a reactive state proxy with a plugin layer that intercepts\n * get/set/notify/subscribe operations via plugin hooks.\n *\n * Only stores that opt into debugging or custom behaviors need this.\n * Core state() is not aware of plugins.\n *\n * Usage:\n * import { state } from \"lume-js\";\n * import { withPlugins, createDebugPlugin } from \"lume-js/addons\";\n *\n * const store = withPlugins(state({ count: 0 }), [createDebugPlugin({ label: 'counter' })]);\n */\n\n/**\n * Wrap a reactive state proxy with plugin hooks.\n *\n * Plugin hooks (all optional):\n * onInit() — called once at wrap time\n * onGet(key, value) → value|void — intercept/transform reads\n * onSet(key, newVal, oldVal) → val|void — intercept/transform writes\n * onNotify(key, value) — called before subscribers are notified\n * onSubscribe(key) — called when $subscribe is invoked\n *\n * @security Plugins run with full application privilege. A plugin can read\n * all state, alter any write, or suppress mutations. Only pass trusted objects.\n * Plugin objects are frozen after registration to prevent post-init mutation.\n *\n * @param {object} store - A reactive proxy from state()\n * @param {Array<object>} plugins - Array of plugin objects\n * @returns {Proxy} A new proxy wrapping the store with plugin behavior\n */\nimport { logError } from '../utils/log.js';\n\nexport function withPlugins(store, plugins = []) {\n if (!plugins.length) return store;\n\n // Call onInit hooks once at wrap time, then freeze each plugin to prevent\n // post-registration mutation of its hooks (defense-in-depth).\n for (const p of plugins) {\n try {\n p.onInit?.();\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onInit:`, e);\n }\n Object.freeze(p);\n }\n\n // Track pending notifications for onNotify hooks.\n // Instead of a separate microtask, we hook into the underlying state's\n // flush via $beforeFlush so onNotify and subscribers share one microtask.\n const pendingNotifications = new Map();\n\n function runNotifyHooks() {\n for (const [key, value] of pendingNotifications) {\n for (const p of plugins) {\n try {\n p.onNotify?.(key, value);\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onNotify:`, e);\n }\n }\n }\n pendingNotifications.clear();\n }\n\n // Register once on the underlying state; capture unsubscribe for cleanup.\n let flushUnsub;\n if (typeof store.$beforeFlush === 'function') {\n flushUnsub = store.$beforeFlush(runNotifyHooks);\n }\n\n return new Proxy(store, {\n get(target, key) {\n // $dispose — remove the beforeFlush hook and clear pending state\n if (key === '$dispose') {\n return () => {\n if (flushUnsub) flushUnsub();\n pendingNotifications.clear();\n };\n }\n\n // Pass $-prefixed meta methods through without interception\n if (typeof key === 'string' && key.startsWith('$')) {\n const method = target[key];\n if (key === '$subscribe' && typeof method === 'function') {\n // Wrap $subscribe to call onSubscribe hooks\n return (subKey, fn) => {\n for (const p of plugins) {\n try {\n p.onSubscribe?.(subKey);\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onSubscribe:`, e);\n }\n }\n return method(subKey, fn);\n };\n }\n return method;\n }\n\n let value = target[key];\n\n // onGet chain\n for (const p of plugins) {\n try {\n const r = p.onGet?.(key, value);\n if (r !== undefined) value = r;\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onGet:`, e);\n }\n }\n\n return value;\n },\n\n set(target, key, value) {\n const oldValue = target[key];\n let newValue = value;\n\n // onSet chain\n for (const p of plugins) {\n try {\n const r = p.onSet?.(key, newValue, oldValue);\n if (r !== undefined) newValue = r;\n } catch (e) {\n logError(`[Lume.js] Plugin \"${p.name}\" error in onSet:`, e);\n }\n }\n\n // Only queue onNotify if the value actually changed after plugin chain\n if (!Object.is(newValue, oldValue)) {\n pendingNotifications.set(key, newValue);\n }\n\n target[key] = newValue;\n return true;\n }\n });\n}\n","/**\n * Creates a cleanup group that can collect and dispose multiple\n * cleanup/unsubscribe functions at once.\n *\n * @returns {CleanupGroup}\n *\n * @example\n * ```js\n * import { createCleanupGroup } from 'lume-js/addons';\n *\n * const group = createCleanupGroup();\n * group.add(bindDom(root, store));\n * group.add(effect(() => { ... }));\n * group.add(store.$subscribe('key', fn));\n *\n * // Dispose everything at once\n * group.dispose();\n * ```\n */\nexport function createCleanupGroup() {\n const cleanups = [];\n\n return {\n /**\n * Add a cleanup function to the group.\n * @param {Function} fn - Cleanup/unsubscribe function\n */\n add(fn) {\n if (typeof fn === 'function') {\n cleanups.push(fn);\n }\n },\n\n /**\n * Run all collected cleanup functions and clear the group.\n */\n dispose() {\n while (cleanups.length) {\n const fn = cleanups.pop();\n try { fn(); } catch (e) { /* ignore cleanup errors */ }\n }\n },\n };\n}\n","/**\n * Reads initial state from a `<script type=\"application/json\">` element\n * embedded in the server-rendered HTML. Useful for SSR / hydration patterns.\n *\n * @security Hydration trusts the DOM. An attacker who can inject HTML before\n * the legitimate script (DOM clobbering) can control the parsed data. The\n * element must be a real `<script type=\"application/json\">` tag; non-script\n * elements are rejected. Use the optional `validate` parameter to enforce a\n * schema (e.g., whitelist allowed keys) before passing to `state()`.\n *\n * @param {string} [selector='#__LUME_DATA__'] - CSS selector for the script element\n * @param {function} [validate] - Optional validator: (data) => boolean. If it\n * returns false, hydrateState returns {} instead of the parsed data.\n * @returns {object} Parsed JSON object, or empty object if not found / invalid / rejected\n *\n * @example\n * ```html\n * <script id=\"__LUME_DATA__\" type=\"application/json\">\n * {\"title\": \"Welcome\", \"count\": 42}\n * </script>\n * ```\n *\n * ```js\n * import { state } from 'lume-js';\n * import { hydrateState } from 'lume-js/addons';\n *\n * // With optional schema validation\n * const data = hydrateState('#__LUME_DATA__', d =>\n * typeof d.title === 'string' && typeof d.count === 'number'\n * );\n * const store = state(data);\n * ```\n */\nexport function hydrateState(selector = '#__LUME_DATA__', validate) {\n const el = typeof document !== 'undefined' ? document.querySelector(selector) : null;\n if (!el) return {};\n\n // Reject non-script elements or scripts without the correct type.\n // This mitigates DOM clobbering where an attacker injects a matching\n // element with a different tag name (e.g., a div or a script with\n // a different type that would still match querySelector by id).\n if (el.tagName !== 'SCRIPT' || el.type !== 'application/json') {\n return {};\n }\n\n let data;\n try {\n data = JSON.parse(el.textContent);\n } catch {\n return {};\n }\n\n if (typeof validate === 'function' && !validate(data)) {\n return {};\n }\n\n return data;\n}\n","/**\n * Lume-JS Persist Addon\n *\n * Keeps selected store keys in sync with localStorage/sessionStorage (or\n * any Storage-like object): hydrates them on call, then saves on change.\n *\n * Usage:\n * import { state } from \"lume-js\";\n * import { persist } from \"lume-js/addons\";\n *\n * const store = state({ todos: [], filter: 'all', draft: '' });\n *\n * // Hydrate + auto-save todos/filter; draft stays in-memory only\n * const stop = persist(store, 'my-app', { keys: ['todos', 'filter'] });\n *\n * Behavior:\n * - Hydration assigns stored values through the proxy, so subscribers and\n * bindings see them like any other write.\n * - Saves are coalesced to one storage write per microtask, and skipped\n * entirely when the serialized snapshot is unchanged.\n * - Storage failures (quota, unavailable, corrupted JSON, unserializable\n * values) are contained: a console warning, never a throw.\n *\n * @security Storage is same-origin but survives schema changes — hydration\n * only assigns keys you watch (never unknown keys from storage), and the\n * core set trap independently blocks prototype-polluting keys.\n *\n * @module addons/persist\n */\n\nimport { logWarn } from '../utils/log.js';\n\n/**\n * Read and parse the stored JSON blob. Returns a plain object, or null\n * when missing, corrupted, or not an object (warns on read errors).\n */\nfunction readStored(storage, storageKey) {\n try {\n const raw = storage.getItem(storageKey);\n if (!raw) return null;\n const data = JSON.parse(raw);\n return data && typeof data === 'object' && !Array.isArray(data) ? data : null;\n } catch {\n logWarn(`[Lume.js] persist(): could not read \"${storageKey}\" — starting fresh`);\n return null;\n }\n}\n\n/** Serialize the watched subset of the store. May throw (circular refs). */\nfunction serializeKeys(store, watched) {\n const out = {};\n for (const k of watched) out[k] = store[k];\n return JSON.stringify(out);\n}\n\n/**\n * Sync store keys with a Storage object.\n *\n * @param {object} store - Reactive store created with state()\n * @param {string} storageKey - The storage entry name to read/write\n * @param {object} [options]\n * @param {string[]} [options.keys] - Keys to persist. Default: all own\n * non-$ keys of the store at call time.\n * @param {Storage} [options.storage] - Storage object. Default: localStorage.\n * Pass sessionStorage for per-tab persistence.\n * @returns {function} Dispose function — stops watching and saving.\n */\nexport function persist(store, storageKey, options = {}) {\n if (!store || typeof store.$subscribe !== 'function') {\n throw new Error('[Lume.js] persist() requires a reactive store from state()');\n }\n if (typeof storageKey !== 'string' || storageKey.length === 0) {\n throw new Error('[Lume.js] persist() requires a non-empty storage key');\n }\n\n const storage = options.storage !== undefined\n ? options.storage\n : globalThis.localStorage;\n\n if (!storage || typeof storage.getItem !== 'function') {\n logWarn('[Lume.js] persist(): no storage available — persistence disabled');\n return () => {};\n }\n\n const watched = Array.isArray(options.keys) && options.keys.length > 0\n ? options.keys.slice()\n : Object.keys(store).filter(k => !k.startsWith('$'));\n\n // ── Hydrate ────────────────────────────────────────────────────────────\n // Only watched keys are assigned — stale storage can't inject others.\n const stored = readStored(storage, storageKey);\n if (stored) {\n for (const k of watched) {\n if (Object.prototype.hasOwnProperty.call(stored, k)) {\n store[k] = stored[k];\n }\n }\n }\n\n // ── Save on change ─────────────────────────────────────────────────────\n // Remember what storage holds (post-hydration) so unchanged flushes —\n // including the hydration echo itself — skip the write.\n let lastWritten = null;\n try {\n lastWritten = serializeKeys(store, watched);\n } catch {\n // Unserializable initial state: first save attempt will warn.\n }\n\n let scheduled = false;\n let disposed = false;\n\n const flushSave = () => {\n scheduled = false;\n if (disposed) return;\n\n let json;\n try {\n json = serializeKeys(store, watched);\n } catch (err) {\n logWarn('[Lume.js] persist(): state not serializable — skipping save', err);\n return;\n }\n if (json === lastWritten) return;\n\n try {\n storage.setItem(storageKey, json);\n lastWritten = json;\n } catch (err) {\n logWarn('[Lume.js] persist(): could not write — storage full or unavailable?', err);\n }\n };\n\n const save = () => {\n if (scheduled) return;\n scheduled = true;\n queueMicrotask(flushSave);\n };\n\n const unsubs = watched.map(k => {\n let first = true;\n return store.$subscribe(k, () => {\n if (first) { first = false; return; } // skip $subscribe's immediate call\n save();\n });\n });\n\n return () => {\n disposed = true;\n while (unsubs.length) unsubs.pop()();\n };\n}\n","import { REACTIVE_BRAND } from \"../core/state.js\";\n\nexport { computed } from \"./computed.js\";\nexport { watch } from \"./watch.js\";\nexport { repeat, defaultFocusPreservation, defaultScrollPreservation } from \"./repeat.js\";\nexport { createDebugPlugin, debug } from \"./debug.js\";\nexport { withPlugins } from \"./withPlugins.js\";\nexport { createCleanupGroup } from \"./cleanupGroup.js\";\nexport { hydrateState } from \"./hydrateState.js\";\nexport { persist } from \"./persist.js\";\n\n/**\n * Returns true if the value is a Lume reactive proxy created by state().\n *\n * Checks the shared reactive brand first (a registry symbol stamped by\n * state(), reliable across module copies), then falls back to duck-typing\n * ($subscribe) for proxies from older lume-js versions whose brand was not\n * shared. The brand check uses the `in` operator, which does not pass\n * through the proxy `get` trap — calling isReactive inside an effect does\n * not create a spurious dependency.\n *\n * @param {any} obj\n * @returns {boolean}\n */\nexport function isReactive(obj) {\n return !!(obj && typeof obj === 'object' &&\n (REACTIVE_BRAND in obj || typeof obj.$subscribe === 'function'));\n}\n"],"names":["container"],"mappings":";;;AA+DO,SAAS,SAAS,IAAI;AAC3B,MAAI,OAAO,OAAO,YAAY;AAC5B,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAEA,MAAI;AACJ,MAAI,gBAAgB;AACpB,MAAI,kBAAkB;AACtB,MAAI,WAAW;AACf,QAAM,cAAc,CAAA;AAGpB,QAAM,gBAAgB,OAAO,MAAM;AAIjC,QAAI,mBAAmB,SAAU;AAEjC,sBAAkB;AAElB,QAAI;AACF,YAAM,WAAW,GAAE;AAGnB,UAAI,CAAC,iBAAiB,CAAC,OAAO,GAAG,UAAU,WAAW,GAAG;AACvD,sBAAc;AACd,wBAAgB;AAGhB,oBAAY,QAAQ,cAAY,SAAS,WAAW,CAAC;AAAA,MACvD;AAAA,IACF,SAAS,OAAO;AACd,eAAS,4CAA4C,KAAK;AAE1D,UAAI,CAAC,iBAAiB,gBAAgB,QAAW;AAC/C,sBAAc;AACd,wBAAgB;AAGhB,oBAAY,QAAQ,cAAY,SAAS,WAAW,CAAC;AAAA,MACvD;AAAA,IACF,UAAC;AAGC,qBAAe,MAAM;AACnB,YAAI,CAAC,UAAU;AACb,4BAAkB;AAAA,QACpB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL,IAAI,QAAQ;AACV,UAAI,CAAC,eAAe;AAClB,cAAM,IAAI,MAAM,+CAA+C;AAAA,MACjE;AACA,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;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A,MAAI,cAAc;AAClB,MAAI;AACF,kBAAc,cAAc,OAAO,OAAO;AAAA,EAC5C,QAAQ;AAAA,EAER;AAEA,MAAI,YAAY;AAChB,MAAI,WAAW;AAEf,QAAM,YAAY,MAAM;AACtB,gBAAY;AACZ,QAAI,SAAU;AAEd,QAAI;AACJ,QAAI;AACF,aAAO,cAAc,OAAO,OAAO;AAAA,IACrC,SAAS,KAAK;AACZ,cAAQ,+DAA+D,GAAG;AAC1E;AAAA,IACF;AACA,QAAI,SAAS,YAAa;AAE1B,QAAI;AACF,cAAQ,QAAQ,YAAY,IAAI;AAChC,oBAAc;AAAA,IAChB,SAAS,KAAK;AACZ,cAAQ,uEAAuE,GAAG;AAAA,IACpF;AAAA,EACF;AAEA,QAAM,OAAO,MAAM;AACjB,QAAI,UAAW;AACf,gBAAY;AACZ,mBAAe,SAAS;AAAA,EAC1B;AAEA,QAAM,SAAS,QAAQ,IAAI,OAAK;AAC9B,QAAI,QAAQ;AACZ,WAAO,MAAM,WAAW,GAAG,MAAM;AAC/B,UAAI,OAAO;AAAE,gBAAQ;AAAO;AAAA,MAAQ;AACpC,WAAI;AAAA,IACN,CAAC;AAAA,EACH,CAAC;AAED,SAAO,MAAM;AACX,eAAW;AACX,WAAO,OAAO,OAAQ,QAAO,IAAG,EAAE;AAAA,EACpC;AACF;AC/HO,SAAS,WAAW,KAAK;AAC9B,SAAO,CAAC,EAAE,OAAO,OAAO,QAAQ,aAC7B,kBAAkB,OAAO,OAAO,IAAI,eAAe;AACxD;"}
|
package/dist/handlers.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e={attr:"data-show",apply(e,t){e.hidden=!t}},t={attr:"data-classname",apply(e,t){e.className=t||""}};function a(e){return{attr:"data-"+e,apply(t,a){t.toggleAttribute(e,!!a)}}}function
|
|
1
|
+
const e={attr:"data-show",apply(e,t){e.hidden=!t}},t={attr:"data-classname",apply(e,t){e.className=t||""}};function a(e){return{attr:"data-"+e,apply(t,a){t.toggleAttribute(e,!!a)}}}function n(e){const t=e.startsWith("aria-")?e:"aria-"+e;return{attr:"data-"+t,apply(e,a){e.setAttribute(t,a?"true":"false")}}}function o(...e){return e.map(e=>({attr:"data-class-"+e,apply(t,a){t.classList.toggle(e,!!a)}}))}const l=/^(javascript|vbscript|data\s*:\s*text\/html)/i,r=new Set(["href","src","action","srcset","poster","formaction"]);function s(e){return{attr:"data-"+e,apply(t,a){if(null==a)return void t.removeAttribute(e);const n=a+"";r.has(e)&&l.test(n)?t.removeAttribute(e):t.setAttribute(e,n)}}}function i(e,...t){void 0!==console&&"function"==typeof console.warn&&console.warn(e,...t)}const c=new WeakMap;function d(...e){return e.map(e=>({attr:"data-on"+e,apply(t,a){let n=c.get(t);const o=n?n.get(e):void 0;o&&(t.removeEventListener(e,o),n.delete(e)),"function"==typeof a?(t.addEventListener(e,a),n||(n=new Map,c.set(t,n)),n.set(e,a)):null!=a&&i(`[Lume.js] on('${e}'): bound value is not a function — listener detached`)}}))}const p=["readonly","open","novalidate","formnovalidate","multiple","autofocus","autoplay","controls","loop","muted","defer","async","reversed","selected","inert","allowfullscreen"],u=["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"],m=["pressed","selected","disabled","checked","invalid","required","busy","modal","multiselectable","multiline","readonly","atomic"],f=["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"];function b(){return[e,...p.map(e=>a(e)),...u.map(e=>s(e)),...m.map(e=>n(e)),...f.map(e=>s("aria-"+e))]}const v=[a("readonly")],h=[n("pressed"),n("selected"),n("disabled")];export{h as a11yHandlers,n as ariaAttr,a as boolAttr,t as className,o as classToggle,v as formHandlers,b as htmlAttrs,d as on,e as show,s as stringAttr};
|
package/dist/handlers.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { a as logWarn } from "./shared-DmpHYKx7.mjs";
|
|
1
2
|
const show = {
|
|
2
3
|
attr: "data-show",
|
|
3
4
|
apply(el, val) {
|
|
@@ -35,15 +36,49 @@ function classToggle(...names) {
|
|
|
35
36
|
}
|
|
36
37
|
}));
|
|
37
38
|
}
|
|
39
|
+
const DANGEROUS_SCHEME = /^(javascript|vbscript|data\s*:\s*text\/html)/i;
|
|
40
|
+
const URI_ATTRS = /* @__PURE__ */ new Set(["href", "src", "action", "srcset", "poster", "formaction"]);
|
|
38
41
|
function stringAttr(name) {
|
|
39
42
|
return {
|
|
40
43
|
attr: `data-${name}`,
|
|
41
44
|
apply(el, val) {
|
|
42
|
-
if (val == null)
|
|
43
|
-
|
|
45
|
+
if (val == null) {
|
|
46
|
+
el.removeAttribute(name);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const strVal = String(val);
|
|
50
|
+
if (URI_ATTRS.has(name) && DANGEROUS_SCHEME.test(strVal)) {
|
|
51
|
+
el.removeAttribute(name);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
el.setAttribute(name, strVal);
|
|
44
55
|
}
|
|
45
56
|
};
|
|
46
57
|
}
|
|
58
|
+
const attached = /* @__PURE__ */ new WeakMap();
|
|
59
|
+
function on(...types) {
|
|
60
|
+
return types.map((type) => ({
|
|
61
|
+
attr: `data-on${type}`,
|
|
62
|
+
apply(el, val) {
|
|
63
|
+
let byType = attached.get(el);
|
|
64
|
+
const prev = byType ? byType.get(type) : void 0;
|
|
65
|
+
if (prev) {
|
|
66
|
+
el.removeEventListener(type, prev);
|
|
67
|
+
byType.delete(type);
|
|
68
|
+
}
|
|
69
|
+
if (typeof val === "function") {
|
|
70
|
+
el.addEventListener(type, val);
|
|
71
|
+
if (!byType) {
|
|
72
|
+
byType = /* @__PURE__ */ new Map();
|
|
73
|
+
attached.set(el, byType);
|
|
74
|
+
}
|
|
75
|
+
byType.set(type, val);
|
|
76
|
+
} else if (val != null) {
|
|
77
|
+
logWarn(`[Lume.js] on('${type}'): bound value is not a function — listener detached`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
47
82
|
const BOOL_ATTRS = [
|
|
48
83
|
"readonly",
|
|
49
84
|
"open",
|
|
@@ -187,6 +222,7 @@ export {
|
|
|
187
222
|
classToggle,
|
|
188
223
|
formHandlers,
|
|
189
224
|
htmlAttrs,
|
|
225
|
+
on,
|
|
190
226
|
show,
|
|
191
227
|
stringAttr
|
|
192
228
|
};
|
package/dist/handlers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.mjs","sources":["../src/handlers/show.js","../src/handlers/className.js","../src/handlers/boolAttr.js","../src/handlers/ariaAttr.js","../src/handlers/classToggle.js","../src/handlers/stringAttr.js","../src/handlers/htmlAttrs.js","../src/handlers/presets.js"],"sourcesContent":["/** data-show=\"key\" → el.hidden = !Boolean(val) */\nexport const show = {\n attr: 'data-show',\n apply(el, val) { el.hidden = !Boolean(val); }\n};\n","/** data-classname=\"key\" → el.className = val || '' */\nexport const className = {\n attr: 'data-classname',\n apply(el, val) { el.className = val || ''; }\n};\n","/**\n * Create a handler for any HTML boolean attribute.\n * Uses toggleAttribute() — works correctly with any attribute name\n * (readonly, contenteditable, etc.) without worrying about camelCase property names.\n *\n * @param {string} name - Attribute name (e.g., 'readonly', 'open', 'contenteditable')\n * @returns {{ attr: string, apply: function }}\n */\nexport function boolAttr(name) {\n return {\n attr: `data-${name}`,\n apply(el, val) { el.toggleAttribute(name, Boolean(val)); }\n };\n}\n","/**\n * Create a handler for an ARIA attribute.\n * Coerces value to \"true\"/\"false\" string — use stringAttr(\"aria-X\") for token/string ARIA attrs.\n *\n * @param {string} name - ARIA name, with or without \"aria-\" prefix\n * @returns {{ attr: string, apply: function }}\n */\nexport function ariaAttr(name) {\n const fullName = name.startsWith('aria-') ? name : `aria-${name}`;\n return {\n attr: `data-${fullName}`,\n apply(el, val) { el.setAttribute(fullName, val ? 'true' : 'false'); }\n };\n}\n","/**\n * Create handlers for CSS class toggling.\n * Each name creates a handler: data-class-{name}=\"key\" → el.classList.toggle(name, Boolean(val))\n * Returns an array — pass directly to handlers (auto-flattened by bindDom).\n *\n * @param {...string} names - CSS class names to create handlers for\n * @returns {Array<{ attr: string, apply: function }>}\n */\nexport function classToggle(...names) {\n return names.map(name => ({\n attr: `data-class-${name}`,\n apply(el, val) { el.classList.toggle(name, Boolean(val)); }\n }));\n}\n","/**\n * Create a handler for any string attribute (href, src, title, alt, action, etc.)\n * Sets the attribute value as a string. Removes the attribute when value is null/undefined.\n *\n * @param {string} name - HTML attribute name (e.g., 'href', 'src', 'title')\n * @returns {{ attr: string, apply: function }}\n */\nexport function stringAttr(name) {\n return {\n attr: `data-${name}`,\n apply(el, val) {\n if (val == null) el.removeAttribute(name);\n else el.setAttribute(name, String(val));\n }\n };\n}\n","import { show } from './show.js';\nimport { boolAttr } from './boolAttr.js';\nimport { ariaAttr } from './ariaAttr.js';\nimport { stringAttr } from './stringAttr.js';\n\n/** @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes#boolean_attributes */\nconst BOOL_ATTRS = [\n 'readonly', 'open', 'novalidate', 'formnovalidate', 'multiple',\n 'autofocus', 'autoplay', 'controls', 'loop', 'muted', 'defer',\n 'async', 'reversed', 'selected', 'inert', 'allowfullscreen',\n];\n\n/** @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes */\nconst STRING_ATTRS = [\n 'href', 'src', 'alt', 'title', 'placeholder', 'action', 'method',\n 'target', 'rel', 'type', 'name', 'role', 'lang', 'tabindex',\n 'pattern', 'min', 'max', 'step', 'minlength', 'maxlength',\n 'width', 'height', 'for', 'form', 'accept', 'autocomplete',\n 'loading', 'decoding', 'inputmode', 'enterkeyhint', 'draggable',\n 'contenteditable', 'spellcheck', 'translate', 'dir', 'id',\n 'poster', 'preload', 'download', 'media', 'sizes', 'srcset',\n 'colspan', 'rowspan', 'scope', 'headers', 'wrap', 'sandbox',\n];\n\n/** ARIA boolean state attributes — coerced to \"true\"/\"false\" string. */\nconst ARIA_BOOL_ATTRS = [\n 'pressed', 'selected', 'disabled', 'checked', 'invalid', 'required',\n 'busy', 'modal', 'multiselectable', 'multiline', 'readonly', 'atomic',\n];\n\n/** ARIA string/token/numeric attributes — value passed through as-is. */\nconst ARIA_STRING_ATTRS = [\n 'current', 'live', 'relevant', 'haspopup',\n 'sort', 'autocomplete', 'orientation',\n 'label', 'describedby', 'labelledby', 'controls', 'owns',\n 'activedescendant', 'errormessage', 'details', 'flowto',\n 'valuenow', 'valuemin', 'valuemax', 'valuetext',\n 'colcount', 'colindex', 'colspan', 'rowcount', 'rowindex', 'rowspan',\n 'level', 'setsize', 'posinset', 'placeholder', 'roledescription',\n 'keyshortcuts', 'braillelabel', 'brailleroledescription',\n];\n\n/**\n * One-import preset that enables all standard HTML attributes as reactive handlers.\n * Returns a flat array — pass directly to handlers option.\n *\n * @returns {Array<{ attr: string, apply: function }>}\n */\nexport function htmlAttrs() {\n return [\n show,\n ...BOOL_ATTRS.map(name => boolAttr(name)),\n ...STRING_ATTRS.map(name => stringAttr(name)),\n ...ARIA_BOOL_ATTRS.map(name => ariaAttr(name)),\n ...ARIA_STRING_ATTRS.map(name => stringAttr(`aria-${name}`)),\n ];\n}\n","import { boolAttr } from './boolAttr.js';\nimport { ariaAttr } from './ariaAttr.js';\n\n/** Form-related handlers (beyond built-in disabled/checked/required) */\nexport const formHandlers = [\n boolAttr('readonly'),\n];\n\n/** Additional ARIA handlers (beyond built-in aria-expanded/aria-hidden) */\nexport const a11yHandlers = [\n ariaAttr('pressed'),\n ariaAttr('selected'),\n ariaAttr('disabled'),\n];\n"],"names":[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AAAA,EAAe;AAAA,EAC/C;AAAA,EAAgB;AAAA,EAAgB;AAClC;AAQO,SAAS,YAAY;AAC1B,SAAO;AAAA,IACL;AAAA,IACA,GAAG,WAAW,IAAI,UAAQ,SAAS,IAAI,CAAC;AAAA,IACxC,GAAG,aAAa,IAAI,UAAQ,WAAW,IAAI,CAAC;AAAA,IAC5C,GAAG,gBAAgB,IAAI,UAAQ,SAAS,IAAI,CAAC;AAAA,IAC7C,GAAG,kBAAkB,IAAI,UAAQ,WAAW,QAAQ,IAAI,EAAE,CAAC;AAAA,EAC/D;AACA;ACpDY,MAAC,eAAe;AAAA,EAC1B,SAAS,UAAU;AACrB;AAGY,MAAC,eAAe;AAAA,EAC1B,SAAS,SAAS;AAAA,EAClB,SAAS,UAAU;AAAA,EACnB,SAAS,UAAU;AACrB;"}
|
|
1
|
+
{"version":3,"file":"handlers.mjs","sources":["../src/handlers/show.js","../src/handlers/className.js","../src/handlers/boolAttr.js","../src/handlers/ariaAttr.js","../src/handlers/classToggle.js","../src/handlers/stringAttr.js","../src/handlers/on.js","../src/handlers/htmlAttrs.js","../src/handlers/presets.js"],"sourcesContent":["/** data-show=\"key\" → el.hidden = !Boolean(val) */\nexport const show = {\n attr: 'data-show',\n apply(el, val) { el.hidden = !Boolean(val); }\n};\n","/** data-classname=\"key\" → el.className = val || '' */\nexport const className = {\n attr: 'data-classname',\n apply(el, val) { el.className = val || ''; }\n};\n","/**\n * Create a handler for any HTML boolean attribute.\n * Uses toggleAttribute() — works correctly with any attribute name\n * (readonly, contenteditable, etc.) without worrying about camelCase property names.\n *\n * @param {string} name - Attribute name (e.g., 'readonly', 'open', 'contenteditable')\n * @returns {{ attr: string, apply: function }}\n */\nexport function boolAttr(name) {\n return {\n attr: `data-${name}`,\n apply(el, val) { el.toggleAttribute(name, Boolean(val)); }\n };\n}\n","/**\n * Create a handler for an ARIA attribute.\n * Coerces value to \"true\"/\"false\" string — use stringAttr(\"aria-X\") for token/string ARIA attrs.\n *\n * @param {string} name - ARIA name, with or without \"aria-\" prefix\n * @returns {{ attr: string, apply: function }}\n */\nexport function ariaAttr(name) {\n const fullName = name.startsWith('aria-') ? name : `aria-${name}`;\n return {\n attr: `data-${fullName}`,\n apply(el, val) { el.setAttribute(fullName, val ? 'true' : 'false'); }\n };\n}\n","/**\n * Create handlers for CSS class toggling.\n * Each name creates a handler: data-class-{name}=\"key\" → el.classList.toggle(name, Boolean(val))\n * Returns an array — pass directly to handlers (auto-flattened by bindDom).\n *\n * @param {...string} names - CSS class names to create handlers for\n * @returns {Array<{ attr: string, apply: function }>}\n */\nexport function classToggle(...names) {\n return names.map(name => ({\n attr: `data-class-${name}`,\n apply(el, val) { el.classList.toggle(name, Boolean(val)); }\n }));\n}\n","/**\n * Create a handler for any string attribute (href, src, title, alt, action, etc.)\n * Sets the attribute value as a string. Removes the attribute when value is null/undefined.\n *\n * @param {string} name - HTML attribute name (e.g., 'href', 'src', 'title')\n * @returns {{ attr: string, apply: function }}\n */\n\nconst DANGEROUS_SCHEME = /^(javascript|vbscript|data\\s*:\\s*text\\/html)/i;\nconst URI_ATTRS = new Set(['href', 'src', 'action', 'srcset', 'poster', 'formaction']);\n\nexport function stringAttr(name) {\n return {\n attr: `data-${name}`,\n apply(el, val) {\n if (val == null) {\n el.removeAttribute(name);\n return;\n }\n const strVal = String(val);\n if (URI_ATTRS.has(name) && DANGEROUS_SCHEME.test(strVal)) {\n el.removeAttribute(name);\n return;\n }\n el.setAttribute(name, strVal);\n }\n };\n}\n","/**\n * Create handlers for declarative event wiring.\n * Each type creates a handler: data-on{type}=\"key\" wires the function held\n * at that store key as a DOM event listener.\n *\n * <button data-onclick=\"addTodo\">Add</button>\n *\n * const store = state({\n * addTodo: (event) => { ... } // a plain function in state\n * });\n * bindDom(root, store, { handlers: [on('click')] });\n *\n * Reactive like any binding: assigning a new function to the key re-wires\n * the listener; assigning null/undefined detaches it.\n *\n * Returns an array — pass directly to handlers (auto-flattened by bindDom).\n *\n * @security Same trust model as data-bind: an injected data-on* attribute\n * can only reference functions that already exist in reachable state — no\n * expressions, no eval. Ensure your HTML is trusted or sanitized.\n *\n * Note: bindDom's cleanup stops future re-wiring but does not detach\n * listeners already attached to elements that remain in the DOM. Discard\n * the bound subtree (the normal SPA teardown) to drop them.\n *\n * @param {...string} types - DOM event types ('click', 'input', 'submit', ...)\n * @returns {Array<{ attr: string, apply: function }>}\n */\n\nimport { logWarn } from '../utils/log.js';\n\n// element → Map<eventType, listener> — tracks what we attached so a\n// re-assigned store key swaps the listener instead of stacking a second one.\nconst attached = new WeakMap();\n\nexport function on(...types) {\n return types.map(type => ({\n attr: `data-on${type}`,\n apply(el, val) {\n let byType = attached.get(el);\n const prev = byType ? byType.get(type) : undefined;\n\n if (prev) {\n el.removeEventListener(type, prev);\n byType.delete(type);\n }\n\n if (typeof val === 'function') {\n el.addEventListener(type, val);\n if (!byType) {\n byType = new Map();\n attached.set(el, byType);\n }\n byType.set(type, val);\n } else if (val != null) {\n logWarn(`[Lume.js] on('${type}'): bound value is not a function — listener detached`);\n }\n }\n }));\n}\n","import { show } from './show.js';\nimport { boolAttr } from './boolAttr.js';\nimport { ariaAttr } from './ariaAttr.js';\nimport { stringAttr } from './stringAttr.js';\n\n/** @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes#boolean_attributes */\nconst BOOL_ATTRS = [\n 'readonly', 'open', 'novalidate', 'formnovalidate', 'multiple',\n 'autofocus', 'autoplay', 'controls', 'loop', 'muted', 'defer',\n 'async', 'reversed', 'selected', 'inert', 'allowfullscreen',\n];\n\n/** @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes */\nconst STRING_ATTRS = [\n 'href', 'src', 'alt', 'title', 'placeholder', 'action', 'method',\n 'target', 'rel', 'type', 'name', 'role', 'lang', 'tabindex',\n 'pattern', 'min', 'max', 'step', 'minlength', 'maxlength',\n 'width', 'height', 'for', 'form', 'accept', 'autocomplete',\n 'loading', 'decoding', 'inputmode', 'enterkeyhint', 'draggable',\n 'contenteditable', 'spellcheck', 'translate', 'dir', 'id',\n 'poster', 'preload', 'download', 'media', 'sizes', 'srcset',\n 'colspan', 'rowspan', 'scope', 'headers', 'wrap', 'sandbox',\n];\n\n/** ARIA boolean state attributes — coerced to \"true\"/\"false\" string. */\nconst ARIA_BOOL_ATTRS = [\n 'pressed', 'selected', 'disabled', 'checked', 'invalid', 'required',\n 'busy', 'modal', 'multiselectable', 'multiline', 'readonly', 'atomic',\n];\n\n/** ARIA string/token/numeric attributes — value passed through as-is. */\nconst ARIA_STRING_ATTRS = [\n 'current', 'live', 'relevant', 'haspopup',\n 'sort', 'autocomplete', 'orientation',\n 'label', 'describedby', 'labelledby', 'controls', 'owns',\n 'activedescendant', 'errormessage', 'details', 'flowto',\n 'valuenow', 'valuemin', 'valuemax', 'valuetext',\n 'colcount', 'colindex', 'colspan', 'rowcount', 'rowindex', 'rowspan',\n 'level', 'setsize', 'posinset', 'placeholder', 'roledescription',\n 'keyshortcuts', 'braillelabel', 'brailleroledescription',\n];\n\n/**\n * One-import preset that enables all standard HTML attributes as reactive handlers.\n * Returns a flat array — pass directly to handlers option.\n *\n * @returns {Array<{ attr: string, apply: function }>}\n */\nexport function htmlAttrs() {\n return [\n show,\n ...BOOL_ATTRS.map(name => boolAttr(name)),\n ...STRING_ATTRS.map(name => stringAttr(name)),\n ...ARIA_BOOL_ATTRS.map(name => ariaAttr(name)),\n ...ARIA_STRING_ATTRS.map(name => stringAttr(`aria-${name}`)),\n ];\n}\n","import { boolAttr } from './boolAttr.js';\nimport { ariaAttr } from './ariaAttr.js';\n\n/** Form-related handlers (beyond built-in disabled/checked/required) */\nexport const formHandlers = [\n boolAttr('readonly'),\n];\n\n/** Additional ARIA handlers (beyond built-in aria-expanded/aria-hidden) */\nexport const a11yHandlers = [\n ariaAttr('pressed'),\n ariaAttr('selected'),\n ariaAttr('disabled'),\n];\n"],"names":[],"mappings":";AACY,MAAC,OAAO;AAAA,EAClB,MAAM;AAAA,EACN,MAAM,IAAI,KAAK;AA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S,SAAS;AAAA,EAClB,SAAS,UAAU;AAAA,EACnB,SAAS,UAAU;AACrB;"}
|
package/dist/index.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,...e){void 0!==console&&"function"==typeof console.warn&&console.warn(t,...e)}function e(t,...e){void 0!==console&&"function"==typeof console.error&&console.error(t,...e)}const r=new Set;function n(t,e){r.add(t);try{return e()}finally{
|
|
1
|
+
function t(t,...e){void 0!==console&&"function"==typeof console.warn&&console.warn(t,...e)}function e(t,...e){void 0!==console&&"function"==typeof console.error&&console.error(t,...e)}const r=100;let n=0;const o=new Set;function s(t){return 0!==n&&(o.add(t),!0)}function i(){let t=0;for(;o.size>0&&r>t;){t++;const r=Array.from(o);o.clear();const n=new Set;for(const t of r){t.runBeforeFlushHooks(),t.notifySubscribers();for(const e of t.takeEffects())n.add(e)}for(const t of n)try{t()}catch(t){e("[Lume.js state] Error in effect:",t)}}r>t||(o.clear(),e("[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."))}function c(e){if("function"!=typeof e)throw Error("batch() requires a function");if(n>0)return e();let r;n++;try{return r=e(),r&&"function"==typeof r.then&&t("[Lume.js batch] batch() received an async function. Only writes before the first await are batched; later writes flush via normal microtasks."),r}finally{try{i()}finally{n--}}}const a=new Set,u=Symbol.for("lume.reactive");function f(t,e){a.add(t);try{return e()}finally{a.delete(t)}}function l(n){if(!n||"object"!=typeof n||Array.isArray(n))throw Error("state() requires a plain object");if(Object.isFrozen(n)||Object.isSealed(n))throw Error("state() requires a mutable plain object");const o=Object.create(null),i=new Map,c=new Set,f=[];let l=!1;function d(){for(let t=0;t<f.length;t++)try{f[t]()}catch(t){e("[Lume.js state] Error in beforeFlush hook:",t)}}function h(){for(const[t,r]of i)if(o[t]){const n=o[t];let s=0;for(;s<n.length;){const o=n[s];try{o(r)}catch(r){e(`[Lume.js state] Error notifying subscriber for key "${t+""}":`,r)}n[s]===o&&s++}}i.clear()}function p(){const t=Array.from(c);return c.clear(),t}const y={runBeforeFlushHooks:d,notifySubscribers:h,takeEffects:p};Object.defineProperty(n,u,{value:!0});const b=()=>{};function m(t,r,n){return o[t]||(o[t]=[]),1e3>o[t].length?(o[t].push(r),()=>{if(o[t]){const e=o[t].indexOf(r);-1!==e&&(o[t].splice(e,1),0===o[t].length&&delete o[t])}}):(e(`[Lume.js state] Subscriber limit (1000) reached for key "${t+""}". ${n} ignored — it will NOT receive updates. This usually means subscriptions are created in a loop without cleanup.`),b)}const g=(t,e)=>m(t,()=>{c.add(e)},"Effect subscription"),E=new Set(["__proto__","constructor","prototype"]),w=new Proxy(n,{get(t,e){if("string"==typeof e&&e.startsWith("$"))return t[e];const r=t[e];if(a.size>0)for(const t of a)t(w,e,g);return r},set(n,o,a){if("string"==typeof o&&E.has(o))return t(`[Lume.js state] Blocked write to reserved key "${o}"`),!0;const u=n[o];return Object.is(u,a)||(n[o]=a,i.set(o,a),s(y)||l||(l=!0,queueMicrotask(()=>{let t=0;try{for(;(i.size>0||c.size>0)&&r>t;){t++,d(),h();const r=p();for(let t=0;t<r.length;t++)try{r[t]()}catch(t){e("[Lume.js state] Error in effect:",t)}}}finally{l=!1}r>t||e("[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 n.$beforeFlush=t=>{if("function"!=typeof t)throw Error("$beforeFlush requires a function");return-1===f.indexOf(t)&&f.push(t),()=>{const e=f.indexOf(t);-1!==e&&f.splice(e,1)}},n.$subscribe=(t,e)=>{if("function"!=typeof e)throw Error("Subscriber must be a function");const r=m(t,e,"New subscriber");return r===b||e(w[t]),r},w}const d=t=>({attr:"data-"+t,apply(e,r){e[t]=!!r}}),h=t=>({attr:"data-"+t,apply(e,r){e.setAttribute(t,r?"true":"false")}}),p=[d("hidden"),d("disabled"),d("checked"),d("required"),h("aria-expanded"),h("aria-hidden")];function y(t,e){if(!e.length)return t;const r=new Map;for(const e of t)r.set(e.attr,e);for(const t of e.flat())r.set(t.attr,t);return[...r.values()]}function b(t,e,r={}){if(!(t instanceof HTMLElement))throw Error("bindDom() requires a valid HTMLElement as root");if(!e||"object"!=typeof e)throw Error("bindDom() requires a reactive state object");const{immediate:n=!1,handlers:o=[]}=r,s=y(p,o),i=()=>{const r=[],n=new WeakMap,o=["[data-bind]",...s.map(t=>`[${t.attr}]`)].join(","),i=t.querySelectorAll(o);for(const t of i){if(t.hasAttribute("data-bind")){const o=g(t,e,t.getAttribute("data-bind"),n);o&&r.push(o)}for(const n of s)if(t.hasAttribute(n.attr)){const o=m(t,e,t.getAttribute(n.attr),n);o&&r.push(o)}}const c=t=>{const e=n.get(t.target);e&&(e.target[e.key]=j(t.target))};return t.addEventListener("input",c),r.push(()=>t.removeEventListener("input",c)),()=>r.forEach(t=>t())};if(!n&&"loading"===document.readyState){let t=null;const e=()=>{t=i()};return document.addEventListener("DOMContentLoaded",e,{once:!0}),()=>t?t():document.removeEventListener("DOMContentLoaded",e)}return i()}function m(t,e,r,n){const o=w(e,r);if(!o)return null;const{target:s,key:i}=o;return s.$subscribe(i,e=>n.apply(t,e))}function g(t,e,r,n){const o=w(e,r);if(!o)return null;const{target:s,key:i}=o,c=s.$subscribe(i,e=>k(t,e));return v(t)&&n.set(t,{target:s,key:i}),c}function E(t,e){if(!e||0===e.length)return t;let r=t;for(let t=0;t<e.length;t++){const n=e[t];if(null==r)return null;if(!(n in r))return null;r=r[n]}return r}function w(e,r){if(!r)return null;const n=r.split("."),o=n.pop(),s=E(e,n);return null==s?(t(`[Lume.js] Invalid path "${r}"`),null):s?.$subscribe?{target:s,key:o}:(t(`[Lume.js] Target for "${r}" is not reactive`),null)}function k(t,e){"INPUT"===t.tagName?"checkbox"===t.type?t.checked=!!e:"radio"===t.type?t.checked=t.value===e+"":t.value=e??"":"TEXTAREA"===t.tagName||"SELECT"===t.tagName?t.value=e??"":t.textContent=e??""}function j(t){return"checkbox"===t.type?t.checked:"number"===t.type||"range"===t.type?t.valueAsNumber:t.value}function v(t){return"INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName}let L=null;function A(t,r){if("function"!=typeof t)throw Error("effect() requires a function");const n=[];let o=!1;const s=()=>{if(!o){o=!0;try{t()}catch(t){throw e("[Lume.js effect] Error in effect:",t),t}finally{o=!1}}};if(Array.isArray(r)){let t=!1,e=!1;n.push(()=>{e=!0});const o=()=>{t||(t=!0,queueMicrotask(()=>{if(t=!1,!e)try{s()}catch{}}))};for(const t of r)if(Array.isArray(t)&&t.length>=2){const[e,...r]=t;if(e&&"function"==typeof e.$subscribe)for(const t of r){let r=!0;const s=e.$subscribe(t,()=>{r?r=!1:o()});n.push(s)}}s()}else{const r=()=>{if(o)return;const s=n.splice(0),i={fn:t,cleanups:n,execute:r,tracking:new WeakMap},c=L;L=i,o=!0;try{f((t,e,r)=>{if(L!==i)return;let n=i.tracking.get(t);n||(n=new Set,i.tracking.set(t,n)),n.has(e)||(n.add(e),i.cleanups.push(r(e,i.execute)))},t)}catch(t){throw n.length=0,n.push(...s),e("[Lume.js effect] Error in effect:",t),t}finally{L=c,o=!1}if(n.length>0)for(const t of s)t();else n.push(...s)};r()}return()=>{for(;n.length;)n.pop()()}}export{c as batch,b as bindDom,A as effect,l as state,f as withReadObserver};
|