@bquery/bquery 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +527 -501
  2. package/dist/{batch-4LAvfLE7.js → batch-x7b2eZST.js} +2 -2
  3. package/dist/{batch-4LAvfLE7.js.map → batch-x7b2eZST.js.map} +1 -1
  4. package/dist/component.es.mjs +1 -1
  5. package/dist/core/collection.d.ts +19 -3
  6. package/dist/core/collection.d.ts.map +1 -1
  7. package/dist/core/element.d.ts +23 -4
  8. package/dist/core/element.d.ts.map +1 -1
  9. package/dist/core/index.d.ts +1 -0
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/utils/function.d.ts +21 -4
  12. package/dist/core/utils/function.d.ts.map +1 -1
  13. package/dist/{core-COenAZjD.js → core-BhpuvPhy.js} +62 -37
  14. package/dist/core-BhpuvPhy.js.map +1 -0
  15. package/dist/core.es.mjs +174 -131
  16. package/dist/core.es.mjs.map +1 -1
  17. package/dist/full.es.mjs +7 -7
  18. package/dist/full.iife.js +2 -2
  19. package/dist/full.iife.js.map +1 -1
  20. package/dist/full.umd.js +2 -2
  21. package/dist/full.umd.js.map +1 -1
  22. package/dist/index.es.mjs +7 -7
  23. package/dist/motion.es.mjs.map +1 -1
  24. package/dist/{persisted-Dz_ryNuC.js → persisted-DHoi3uEs.js} +4 -4
  25. package/dist/{persisted-Dz_ryNuC.js.map → persisted-DHoi3uEs.js.map} +1 -1
  26. package/dist/platform/storage.d.ts.map +1 -1
  27. package/dist/platform.es.mjs +12 -7
  28. package/dist/platform.es.mjs.map +1 -1
  29. package/dist/reactive/core.d.ts +12 -0
  30. package/dist/reactive/core.d.ts.map +1 -1
  31. package/dist/reactive/effect.d.ts.map +1 -1
  32. package/dist/reactive/internals.d.ts +6 -0
  33. package/dist/reactive/internals.d.ts.map +1 -1
  34. package/dist/reactive.es.mjs +6 -6
  35. package/dist/router.es.mjs +1 -1
  36. package/dist/{sanitize-1FBEPAFH.js → sanitize-Cxvxa-DX.js} +50 -39
  37. package/dist/sanitize-Cxvxa-DX.js.map +1 -0
  38. package/dist/security/sanitize-core.d.ts.map +1 -1
  39. package/dist/security.es.mjs +2 -2
  40. package/dist/store.es.mjs +2 -2
  41. package/dist/type-guards-BdKlYYlS.js +32 -0
  42. package/dist/type-guards-BdKlYYlS.js.map +1 -0
  43. package/dist/untrack-DNnnqdlR.js +6 -0
  44. package/dist/{untrack-BuEQKH7_.js.map → untrack-DNnnqdlR.js.map} +1 -1
  45. package/dist/view/evaluate.d.ts.map +1 -1
  46. package/dist/view.es.mjs +157 -151
  47. package/dist/view.es.mjs.map +1 -1
  48. package/dist/{watch-CXyaBC_9.js → watch-DXXv3iAI.js} +3 -3
  49. package/dist/{watch-CXyaBC_9.js.map → watch-DXXv3iAI.js.map} +1 -1
  50. package/package.json +132 -132
  51. package/src/core/collection.ts +628 -588
  52. package/src/core/element.ts +774 -746
  53. package/src/core/index.ts +48 -47
  54. package/src/core/utils/function.ts +151 -110
  55. package/src/motion/animate.ts +113 -113
  56. package/src/motion/flip.ts +176 -176
  57. package/src/motion/scroll.ts +57 -57
  58. package/src/motion/spring.ts +150 -150
  59. package/src/motion/timeline.ts +246 -246
  60. package/src/motion/transition.ts +51 -51
  61. package/src/platform/storage.ts +215 -208
  62. package/src/reactive/core.ts +114 -93
  63. package/src/reactive/effect.ts +54 -43
  64. package/src/reactive/internals.ts +122 -105
  65. package/src/security/sanitize-core.ts +364 -343
  66. package/src/view/evaluate.ts +290 -274
  67. package/dist/core-COenAZjD.js.map +0 -1
  68. package/dist/sanitize-1FBEPAFH.js.map +0 -1
  69. package/dist/type-guards-DRma3-Kc.js +0 -16
  70. package/dist/type-guards-DRma3-Kc.js.map +0 -1
  71. package/dist/untrack-BuEQKH7_.js +0 -6
@@ -1 +1 @@
1
- {"version":3,"file":"view.es.mjs","sources":["../src/view/evaluate.ts","../src/view/directives/bind.ts","../src/view/directives/class.ts","../src/view/directives/for.ts","../src/view/directives/html.ts","../src/view/directives/if.ts","../src/view/directives/model.ts","../src/view/directives/on.ts","../src/view/directives/ref.ts","../src/view/directives/show.ts","../src/view/directives/style.ts","../src/view/directives/text.ts","../src/view/process.ts","../src/view/mount.ts"],"sourcesContent":["import { isComputed, isSignal, type Signal } from '../reactive/index';\nimport type { BindingContext } from './types';\n\n/** Maximum number of cached expression functions before LRU eviction */\nconst MAX_CACHE_SIZE = 500;\n\n/** Compiled function type for expression evaluation */\ntype CompiledFn = (ctx: BindingContext) => unknown;\n\n/**\n * Simple LRU cache for compiled expression functions.\n * Uses Map's insertion order to track recency - accessed items are re-inserted.\n * @internal\n */\nclass LRUCache {\n private cache = new Map<string, CompiledFn>();\n private maxSize: number;\n\n constructor(maxSize: number) {\n this.maxSize = maxSize;\n }\n\n get(key: string): CompiledFn | undefined {\n const value = this.cache.get(key);\n if (value !== undefined) {\n // Move to end (most recently used) by re-inserting\n this.cache.delete(key);\n this.cache.set(key, value);\n }\n return value;\n }\n\n set(key: string, value: CompiledFn): void {\n // Delete first if exists to update insertion order\n if (this.cache.has(key)) {\n this.cache.delete(key);\n } else if (this.cache.size >= this.maxSize) {\n // Evict oldest (first) entry\n const oldest = this.cache.keys().next().value;\n if (oldest !== undefined) {\n this.cache.delete(oldest);\n }\n }\n this.cache.set(key, value);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n get size(): number {\n return this.cache.size;\n }\n}\n\n/** LRU cache for compiled evaluate functions, keyed by expression string */\nconst evaluateCache = new LRUCache(MAX_CACHE_SIZE);\n\n/** LRU cache for compiled evaluateRaw functions, keyed by expression string */\nconst evaluateRawCache = new LRUCache(MAX_CACHE_SIZE);\n\n/**\n * Clears all cached compiled expression functions.\n * Call this when unmounting views or to free memory after heavy template usage.\n *\n * @example\n * ```ts\n * import { clearExpressionCache } from 'bquery/view';\n *\n * // After destroying a view or when cleaning up\n * clearExpressionCache();\n * ```\n */\nexport const clearExpressionCache = (): void => {\n evaluateCache.clear();\n evaluateRawCache.clear();\n};\n\n/**\n * Creates a proxy that lazily unwraps signals/computed only when accessed.\n * This avoids subscribing to signals that aren't referenced in the expression.\n * @internal\n */\nconst createLazyContext = (context: BindingContext): BindingContext =>\n new Proxy(context, {\n get(target, prop: string | symbol) {\n // Only handle string keys for BindingContext indexing\n if (typeof prop !== 'string') {\n return Reflect.get(target, prop);\n }\n const value = target[prop];\n // Auto-unwrap signals/computed only when actually accessed\n if (isSignal(value) || isComputed(value)) {\n return (value as Signal<unknown>).value;\n }\n return value;\n },\n has(target, prop: string | symbol) {\n // Required for `with` statement to resolve identifiers correctly\n if (typeof prop !== 'string') {\n return Reflect.has(target, prop);\n }\n return prop in target;\n },\n });\n\n/**\n * Evaluates an expression in the given context using `new Function()`.\n *\n * Signals and computed values in the context are lazily unwrapped only when\n * accessed by the expression, avoiding unnecessary subscriptions to unused values.\n *\n * @security **WARNING:** This function uses dynamic code execution via `new Function()`.\n * - NEVER pass expressions derived from user input or untrusted sources\n * - Expressions should only come from developer-controlled templates\n * - Malicious expressions can access and exfiltrate context data\n * - Consider this equivalent to `eval()` in terms of security implications\n *\n * @internal\n */\nexport const evaluate = <T = unknown>(expression: string, context: BindingContext): T => {\n try {\n // Create a proxy that lazily unwraps signals/computed on access\n const lazyContext = createLazyContext(context);\n\n // Use cached function or compile and cache a new one\n let fn = evaluateCache.get(expression);\n if (!fn) {\n // Use `with` to enable direct property access from proxy scope.\n // Note: `new Function()` runs in non-strict mode, so `with` is allowed.\n fn = new Function('$ctx', `with($ctx) { return (${expression}); }`) as (\n ctx: BindingContext\n ) => unknown;\n evaluateCache.set(expression, fn);\n }\n return fn(lazyContext) as T;\n } catch (error) {\n console.error(`bQuery view: Error evaluating \"${expression}\"`, error);\n return undefined as T;\n }\n};\n\n/**\n * Evaluates an expression and returns the raw value (for signal access).\n *\n * @security **WARNING:** Uses dynamic code execution. See {@link evaluate} for security notes.\n * @internal\n */\nexport const evaluateRaw = <T = unknown>(expression: string, context: BindingContext): T => {\n try {\n // Use cached function or compile and cache a new one\n let fn = evaluateRawCache.get(expression);\n if (!fn) {\n // Use `with` to enable direct property access from context scope.\n // Unlike `evaluate`, we don't use a lazy proxy - values are accessed directly.\n fn = new Function('$ctx', `with($ctx) { return (${expression}); }`) as (\n ctx: BindingContext\n ) => unknown;\n evaluateRawCache.set(expression, fn);\n }\n return fn(context) as T;\n } catch (error) {\n console.error(`bQuery view: Error evaluating \"${expression}\"`, error);\n return undefined as T;\n }\n};\n\n/**\n * Parses object expression like \"{ active: isActive, disabled: !enabled }\".\n * Handles nested structures like function calls, arrays, and template literals.\n * @internal\n */\nexport const parseObjectExpression = (expression: string): Record<string, string> => {\n const result: Record<string, string> = {};\n\n // Remove outer braces and trim\n const inner = expression\n .trim()\n .replace(/^\\{|\\}$/g, '')\n .trim();\n if (!inner) return result;\n\n // Split by comma at depth 0, respecting strings and nesting\n const parts: string[] = [];\n let current = '';\n let depth = 0;\n let inString: string | null = null;\n\n for (let i = 0; i < inner.length; i++) {\n const char = inner[i];\n const prevChar = i > 0 ? inner[i - 1] : '';\n\n // Handle string literals (including escape sequences)\n if ((char === '\"' || char === \"'\" || char === '`') && prevChar !== '\\\\') {\n if (inString === null) {\n inString = char;\n } else if (inString === char) {\n inString = null;\n }\n current += char;\n continue;\n }\n\n // Skip if inside string\n if (inString !== null) {\n current += char;\n continue;\n }\n\n // Track nesting depth for parentheses, brackets, and braces\n if (char === '(' || char === '[' || char === '{') {\n depth++;\n current += char;\n } else if (char === ')' || char === ']' || char === '}') {\n depth--;\n current += char;\n } else if (char === ',' && depth === 0) {\n // Top-level comma - split point\n parts.push(current.trim());\n current = '';\n } else {\n current += char;\n }\n }\n\n // Add the last part\n if (current.trim()) {\n parts.push(current.trim());\n }\n\n // Parse each part to extract key and value\n for (const part of parts) {\n // Find the first colon at depth 0 (to handle ternary operators in values)\n let colonIndex = -1;\n let partDepth = 0;\n let partInString: string | null = null;\n\n for (let i = 0; i < part.length; i++) {\n const char = part[i];\n const prevChar = i > 0 ? part[i - 1] : '';\n\n if ((char === '\"' || char === \"'\" || char === '`') && prevChar !== '\\\\') {\n if (partInString === null) {\n partInString = char;\n } else if (partInString === char) {\n partInString = null;\n }\n continue;\n }\n\n if (partInString !== null) continue;\n\n if (char === '(' || char === '[' || char === '{') {\n partDepth++;\n } else if (char === ')' || char === ']' || char === '}') {\n partDepth--;\n } else if (char === ':' && partDepth === 0) {\n colonIndex = i;\n break;\n }\n }\n\n if (colonIndex > -1) {\n const key = part\n .slice(0, colonIndex)\n .trim()\n .replace(/^['\"]|['\"]$/g, '');\n const value = part.slice(colonIndex + 1).trim();\n result[key] = value;\n }\n }\n\n return result;\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-bind:attr directive - attribute binding.\n * @internal\n */\nexport const handleBind = (attrName: string): DirectiveHandler => {\n return (el, expression, context, cleanups) => {\n const cleanup = effect(() => {\n const value = evaluate(expression, context);\n if (value == null || value === false) {\n el.removeAttribute(attrName);\n } else if (value === true) {\n el.setAttribute(attrName, '');\n } else {\n el.setAttribute(attrName, String(value));\n }\n });\n cleanups.push(cleanup);\n };\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate, parseObjectExpression } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-class directive - dynamic class binding.\n * Tracks previously added classes to ensure proper cleanup when expressions change.\n * @internal\n */\nexport const handleClass: DirectiveHandler = (el, expression, context, cleanups) => {\n // Track classes added by this directive to clean them up on re-evaluation\n let previousClasses: Set<string> = new Set();\n\n const cleanup = effect(() => {\n const newClasses: Set<string> = new Set();\n\n if (expression.trimStart().startsWith('{')) {\n // Object syntax: { active: isActive, disabled: !enabled }\n const classMap = parseObjectExpression(expression);\n for (const [className, conditionExpr] of Object.entries(classMap)) {\n const condition = evaluate<boolean>(conditionExpr, context);\n el.classList.toggle(className, Boolean(condition));\n // Track class regardless of condition - toggle handles add/remove\n newClasses.add(className);\n }\n } else if (/^\\s*\\[/.test(expression)) {\n // Array literal syntax: [class1, class2]\n const classes = evaluate<string[]>(expression, context);\n if (Array.isArray(classes)) {\n for (const cls of classes) {\n if (cls) {\n el.classList.add(cls);\n newClasses.add(cls);\n }\n }\n }\n } else {\n // Single expression returning string or array\n const result = evaluate<string | string[]>(expression, context);\n if (typeof result === 'string') {\n result.split(/\\s+/).forEach((cls) => {\n if (cls) {\n el.classList.add(cls);\n newClasses.add(cls);\n }\n });\n } else if (Array.isArray(result)) {\n result.forEach((cls) => {\n if (cls) {\n el.classList.add(cls);\n newClasses.add(cls);\n }\n });\n }\n }\n\n // Remove classes that were previously added but are no longer in the new set\n // This keeps directive-managed classes in sync across all syntax forms and provides\n // defensive cleanup behavior for edge cases (e.g. external classList changes)\n for (const cls of previousClasses) {\n if (!newClasses.has(cls)) {\n el.classList.remove(cls);\n }\n }\n\n previousClasses = newClasses;\n });\n\n cleanups.push(cleanup);\n};\n","import { effect, signal, type CleanupFn, type Signal } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { BindingContext, DirectiveHandler } from '../types';\n\ntype ProcessElementFn = (\n el: Element,\n context: BindingContext,\n prefix: string,\n cleanups: CleanupFn[]\n) => void;\n\ntype ProcessChildrenFn = (\n el: Element,\n context: BindingContext,\n prefix: string,\n cleanups: CleanupFn[]\n) => void;\n\n/**\n * Represents a rendered item in bq-for with its DOM element and associated cleanup functions.\n * @internal\n */\ntype RenderedItem = {\n key: unknown;\n element: Element;\n cleanups: CleanupFn[];\n item: unknown;\n index: number;\n itemSignal: Signal<unknown>; // Reactive item value for item-dependent bindings\n indexSignal: Signal<number> | null; // Reactive index for index-dependent bindings\n};\n\n/**\n * Extracts a key from an item using the key expression or falls back to index.\n * @internal\n */\nconst getItemKey = (\n item: unknown,\n index: number,\n keyExpression: string | null,\n itemName: string,\n indexName: string | undefined,\n context: BindingContext\n): unknown => {\n if (!keyExpression) {\n return index; // Fallback to index-based keying\n }\n\n const keyContext: BindingContext = {\n ...context,\n [itemName]: item,\n };\n if (indexName) {\n keyContext[indexName] = index;\n }\n\n return evaluate(keyExpression, keyContext);\n};\n\n/**\n * Handles bq-for directive - list rendering with keyed reconciliation.\n *\n * Supports optional `:key` attribute for efficient DOM reuse:\n * ```html\n * <li bq-for=\"item in items\" :key=\"item.id\">...</li>\n * ```\n *\n * Without a key, falls back to index-based tracking (less efficient for reordering).\n *\n * @internal\n */\nexport const createForHandler = (options: {\n prefix: string;\n processElement: ProcessElementFn;\n processChildren: ProcessChildrenFn;\n}): DirectiveHandler => {\n const { prefix, processElement, processChildren } = options;\n\n return (el, expression, context, cleanups) => {\n const parent = el.parentNode;\n if (!parent) return;\n\n // Parse expression: \"item in items\" or \"(item, index) in items\"\n // Use \\S.* instead of .+ to prevent ReDoS by requiring non-whitespace start\n const match = expression.match(/^\\(?(\\w+)(?:\\s*,\\s*(\\w+))?\\)?\\s+in\\s+(\\S.*)$/);\n if (!match) {\n console.error(`bQuery view: Invalid bq-for expression \"${expression}\"`);\n return;\n }\n\n const [, itemName, indexName, listExpression] = match;\n\n // Extract :key attribute if present\n const keyExpression = el.getAttribute(':key') || el.getAttribute(`${prefix}-key`);\n\n const template = el.cloneNode(true) as Element;\n template.removeAttribute(`${prefix}-for`);\n template.removeAttribute(':key');\n template.removeAttribute(`${prefix}-key`);\n\n // Create placeholder comment\n const placeholder = document.createComment(`bq-for: ${expression}`);\n parent.replaceChild(placeholder, el);\n\n // Track rendered items by key for reconciliation\n let renderedItemsMap = new Map<unknown, RenderedItem>();\n let renderedOrder: unknown[] = [];\n\n /**\n * Creates a new DOM element for an item.\n */\n const createItemElement = (item: unknown, index: number, key: unknown): RenderedItem => {\n const clone = template.cloneNode(true) as Element;\n const itemCleanups: CleanupFn[] = [];\n\n // Create reactive signals for item and index\n const itemSig = signal(item);\n const indexSig = indexName ? signal(index) : null;\n\n const childContext: BindingContext = {\n ...context,\n [itemName]: itemSig,\n };\n if (indexName && indexSig) {\n childContext[indexName] = indexSig;\n }\n\n // Process bindings on the clone\n processElement(clone, childContext, prefix, itemCleanups);\n processChildren(clone, childContext, prefix, itemCleanups);\n\n return {\n key,\n element: clone,\n cleanups: itemCleanups,\n item,\n index,\n itemSignal: itemSig,\n indexSignal: indexSig,\n };\n };\n\n /**\n * Removes a rendered item and cleans up its effects.\n */\n const removeItem = (rendered: RenderedItem): void => {\n for (const cleanup of rendered.cleanups) {\n cleanup();\n }\n rendered.element.remove();\n };\n\n /**\n * Updates an existing item's data and index when reused.\n * Updates the reactive signals so bindings re-render.\n */\n const updateItem = (rendered: RenderedItem, newItem: unknown, newIndex: number): void => {\n // Update item if it changed\n if (!Object.is(rendered.item, newItem)) {\n rendered.item = newItem;\n rendered.itemSignal.value = newItem;\n }\n\n // Update index if it changed\n if (rendered.index !== newIndex) {\n rendered.index = newIndex;\n if (rendered.indexSignal) {\n rendered.indexSignal.value = newIndex;\n }\n }\n };\n\n const cleanup = effect(() => {\n const list = evaluate<unknown[]>(listExpression, context);\n\n if (!Array.isArray(list)) {\n // Clear all if list is invalid\n for (const rendered of renderedItemsMap.values()) {\n removeItem(rendered);\n }\n renderedItemsMap.clear();\n renderedOrder = [];\n return;\n }\n\n // Build new key order and detect changes\n const newKeys: unknown[] = [];\n const newItemsByKey = new Map<unknown, { item: unknown; index: number }>();\n const seenKeys = new Set<unknown>();\n\n list.forEach((item, index) => {\n let key = getItemKey(item, index, keyExpression, itemName, indexName, context);\n\n // Detect duplicate keys - warn developer and fall back to unique composite key\n if (seenKeys.has(key)) {\n console.warn(\n `bq-for: Duplicate key \"${String(key)}\" detected at index ${index}. ` +\n `Falling back to index-based key for this item. ` +\n `Ensure :key expressions produce unique values for each item.`\n );\n // Create a unique composite key to avoid corrupting rendered output\n key = { __bqDuplicateKey: key, __bqIndex: index };\n }\n seenKeys.add(key);\n\n newKeys.push(key);\n newItemsByKey.set(key, { item, index });\n });\n\n // Identify items to remove (in old but not in new)\n const keysToRemove: unknown[] = [];\n for (const key of renderedOrder) {\n if (!newItemsByKey.has(key)) {\n keysToRemove.push(key);\n }\n }\n\n // Remove deleted items\n for (const key of keysToRemove) {\n const rendered = renderedItemsMap.get(key);\n if (rendered) {\n removeItem(rendered);\n renderedItemsMap.delete(key);\n }\n }\n\n // Process new list: create new items, update indices, reorder\n const newRenderedMap = new Map<unknown, RenderedItem>();\n let lastInsertedElement: Element | Comment = placeholder;\n\n for (let i = 0; i < newKeys.length; i++) {\n const key = newKeys[i];\n const { item, index } = newItemsByKey.get(key)!;\n let rendered = renderedItemsMap.get(key);\n\n if (rendered) {\n // Reuse existing element\n updateItem(rendered, item, index);\n newRenderedMap.set(key, rendered);\n\n // Check if element needs to be moved\n const currentNext: ChildNode | null = lastInsertedElement.nextSibling;\n if (currentNext !== rendered.element) {\n // Move element to correct position\n lastInsertedElement.after(rendered.element);\n }\n lastInsertedElement = rendered.element;\n } else {\n // Create new element\n rendered = createItemElement(item, index, key);\n newRenderedMap.set(key, rendered);\n\n // Insert at correct position\n lastInsertedElement.after(rendered.element);\n lastInsertedElement = rendered.element;\n }\n }\n\n // Update tracking state\n renderedItemsMap = newRenderedMap;\n renderedOrder = newKeys;\n });\n\n // When the bq-for itself is cleaned up, also cleanup all rendered items\n cleanups.push(() => {\n cleanup();\n for (const rendered of renderedItemsMap.values()) {\n for (const itemCleanup of rendered.cleanups) {\n itemCleanup();\n }\n }\n renderedItemsMap.clear();\n });\n };\n};\n","import { effect } from '../../reactive/index';\nimport { sanitizeHtml } from '../../security/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-html directive - sets innerHTML (sanitized by default).\n * @internal\n */\nexport const handleHtml = (sanitize: boolean): DirectiveHandler => {\n return (el, expression, context, cleanups) => {\n const cleanup = effect(() => {\n const value = evaluate<string>(expression, context);\n const html = String(value ?? '');\n el.innerHTML = sanitize ? sanitizeHtml(html) : html;\n });\n cleanups.push(cleanup);\n };\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-if directive - conditional rendering.\n * @internal\n */\nexport const handleIf: DirectiveHandler = (el, expression, context, cleanups) => {\n const placeholder = document.createComment(`bq-if: ${expression}`);\n\n // Store original element state\n let isInserted = true;\n\n const cleanup = effect(() => {\n const condition = evaluate<boolean>(expression, context);\n\n if (condition && !isInserted) {\n // Insert element using replaceWith to handle moved elements\n placeholder.replaceWith(el);\n isInserted = true;\n } else if (!condition && isInserted) {\n // Remove element using replaceWith to handle moved elements\n el.replaceWith(placeholder);\n isInserted = false;\n }\n });\n\n cleanups.push(cleanup);\n};\n","import { effect, isSignal, type Signal } from '../../reactive/index';\nimport { evaluateRaw } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-model directive - two-way binding.\n * @internal\n */\nexport const handleModel: DirectiveHandler = (el, expression, context, cleanups) => {\n const input = el as HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;\n const rawValue = evaluateRaw<Signal<unknown>>(expression, context);\n\n if (!isSignal(rawValue)) {\n console.warn(`bQuery view: bq-model requires a signal, got \"${expression}\"`);\n return;\n }\n\n const sig = rawValue as Signal<unknown>;\n\n // Initial value sync\n const isCheckbox = input.type === 'checkbox';\n const isRadio = input.type === 'radio';\n\n const updateInput = () => {\n if (isCheckbox) {\n (input as HTMLInputElement).checked = Boolean(sig.value);\n } else if (isRadio) {\n (input as HTMLInputElement).checked = sig.value === input.value;\n } else {\n input.value = String(sig.value ?? '');\n }\n };\n\n // Effect to sync signal -> input\n const cleanup = effect(() => {\n updateInput();\n });\n cleanups.push(cleanup);\n\n // Event listener to sync input -> signal\n const eventType = input.tagName === 'SELECT' ? 'change' : 'input';\n const handler = () => {\n if (isCheckbox) {\n sig.value = (input as HTMLInputElement).checked;\n } else if (isRadio) {\n if ((input as HTMLInputElement).checked) {\n sig.value = input.value;\n }\n } else {\n sig.value = input.value;\n }\n };\n\n input.addEventListener(eventType, handler);\n cleanups.push(() => input.removeEventListener(eventType, handler));\n};\n","import { evaluateRaw } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-on:event directive - event binding.\n * @internal\n */\nexport const handleOn = (eventName: string): DirectiveHandler => {\n return (el, expression, context, cleanups) => {\n const handler = (event: Event) => {\n // Add $event to context for expression evaluation\n const eventContext = { ...context, $event: event, $el: el };\n\n // Check if expression contains a function call (has parentheses)\n // If not, it might be a plain function reference like \"handleClick\"\n // Note: Method references like \"handlers.onClick\" will lose their receiver\n // when auto-invoked. For methods, use explicit calls: \"handlers.onClick($event)\"\n const containsCall = expression.includes('(');\n\n if (!containsCall) {\n // Evaluate the expression - if it returns a function, invoke it with $event\n const result = evaluateRaw<unknown>(expression, eventContext);\n if (typeof result === 'function') {\n // Auto-invoke with event. Note: `this` will be undefined for method references.\n // For proper method binding, use explicit syntax: \"obj.method($event)\"\n result(event);\n return;\n }\n // If not a function, the expression was already evaluated (e.g., \"count.value++\")\n return;\n }\n\n // Otherwise evaluate as expression using evaluateRaw to allow signal mutations\n // (e.g., \"count.value++\" or \"handleClick($event)\")\n evaluateRaw(expression, eventContext);\n };\n\n el.addEventListener(eventName, handler);\n cleanups.push(() => el.removeEventListener(eventName, handler));\n };\n};\n","import { isSignal, type Signal } from '../../reactive/index';\nimport { evaluateRaw } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Checks if an object has a writable `value` property.\n * Returns true if `value` is an own data property or an accessor with a setter.\n * @internal\n */\nfunction hasWritableValue(obj: object): obj is { value: Element | null } {\n const descriptor = Object.getOwnPropertyDescriptor(obj, 'value');\n if (!descriptor) return false;\n // Data property: check writable flag\n if ('value' in descriptor) return descriptor.writable === true;\n // Accessor property: check for setter\n return typeof descriptor.set === 'function';\n}\n\n/**\n * Handles bq-ref directive - element reference.\n * @internal\n */\nexport const handleRef: DirectiveHandler = (el, expression, context, cleanups) => {\n const rawValue = evaluateRaw<Signal<Element | null> | { value: Element | null }>(\n expression,\n context\n );\n\n if (isSignal(rawValue)) {\n rawValue.value = el;\n cleanups.push(() => {\n rawValue.value = null;\n });\n } else if (typeof rawValue === 'object' && rawValue !== null && hasWritableValue(rawValue)) {\n // Object with writable .value property (e.g., { value: null })\n rawValue.value = el;\n cleanups.push(() => {\n rawValue.value = null;\n });\n }\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-show directive - toggle visibility.\n * @internal\n */\nexport const handleShow: DirectiveHandler = (el, expression, context, cleanups) => {\n const htmlEl = el as HTMLElement;\n // Capture the computed display value to properly restore visibility.\n // If inline display is 'none' or empty, we need to use the computed value.\n // Use ownerDocument.defaultView for cross-document/iframe compatibility.\n let originalDisplay = htmlEl.style.display;\n if (!originalDisplay || originalDisplay === 'none') {\n const computed = htmlEl.ownerDocument.defaultView?.getComputedStyle(htmlEl).display ?? '';\n originalDisplay = computed !== 'none' ? computed : '';\n }\n\n const cleanup = effect(() => {\n const condition = evaluate<boolean>(expression, context);\n htmlEl.style.display = condition ? originalDisplay : 'none';\n });\n\n cleanups.push(cleanup);\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate, parseObjectExpression } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-style directive - dynamic style binding.\n * @internal\n */\nexport const handleStyle: DirectiveHandler = (el, expression, context, cleanups) => {\n const htmlEl = el as HTMLElement;\n let appliedStyles: Set<string> = new Set();\n\n const cleanup = effect(() => {\n const newStyles = new Set<string>();\n\n if (expression.trimStart().startsWith('{')) {\n const styleMap = parseObjectExpression(expression);\n for (const [prop, valueExpr] of Object.entries(styleMap)) {\n const value = evaluate<string>(valueExpr, context);\n const cssProp = prop.replace(/([A-Z])/g, '-$1').toLowerCase();\n htmlEl.style.setProperty(cssProp, String(value ?? ''));\n newStyles.add(cssProp);\n }\n } else {\n const result = evaluate<Record<string, string>>(expression, context);\n if (result && typeof result === 'object') {\n for (const [prop, value] of Object.entries(result)) {\n const cssProp = prop.replace(/([A-Z])/g, '-$1').toLowerCase();\n htmlEl.style.setProperty(cssProp, String(value ?? ''));\n newStyles.add(cssProp);\n }\n }\n }\n\n // Remove styles that were previously applied but are no longer present\n for (const cssProp of appliedStyles) {\n if (!newStyles.has(cssProp)) {\n htmlEl.style.removeProperty(cssProp);\n }\n }\n\n // Update the set of applied styles\n appliedStyles = newStyles;\n });\n\n cleanups.push(cleanup);\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-text directive - sets text content.\n * @internal\n */\nexport const handleText: DirectiveHandler = (el, expression, context, cleanups) => {\n const cleanup = effect(() => {\n const value = evaluate(expression, context);\n el.textContent = String(value ?? '');\n });\n cleanups.push(cleanup);\n};\n","import type { CleanupFn } from '../reactive/index';\nimport type { BindingContext, DirectiveHandler } from './types';\n\nexport type DirectiveHandlers = {\n text: DirectiveHandler;\n html: DirectiveHandler;\n if: DirectiveHandler;\n show: DirectiveHandler;\n class: DirectiveHandler;\n style: DirectiveHandler;\n model: DirectiveHandler;\n ref: DirectiveHandler;\n for: DirectiveHandler;\n bind: (attrName: string) => DirectiveHandler;\n on: (eventName: string) => DirectiveHandler;\n};\n\n/**\n * Processes a single element for directives.\n * @internal\n */\nexport const processElement = (\n el: Element,\n context: BindingContext,\n prefix: string,\n cleanups: CleanupFn[],\n handlers: DirectiveHandlers\n): void => {\n const attributes = Array.from(el.attributes);\n\n for (const attr of attributes) {\n const { name, value } = attr;\n\n if (!name.startsWith(`${prefix}-`)) continue;\n\n const directive = name.slice(prefix.length + 1); // Remove prefix and dash\n\n // Handle bq-for specially (creates new scope)\n if (directive === 'for') {\n handlers.for(el, value, context, cleanups);\n return; // Don't process children, bq-for handles it\n }\n\n // Handle other directives\n if (directive === 'text') {\n handlers.text(el, value, context, cleanups);\n } else if (directive === 'html') {\n handlers.html(el, value, context, cleanups);\n } else if (directive === 'if') {\n handlers.if(el, value, context, cleanups);\n } else if (directive === 'show') {\n handlers.show(el, value, context, cleanups);\n } else if (directive === 'class') {\n handlers.class(el, value, context, cleanups);\n } else if (directive === 'style') {\n handlers.style(el, value, context, cleanups);\n } else if (directive === 'model') {\n handlers.model(el, value, context, cleanups);\n } else if (directive === 'ref') {\n handlers.ref(el, value, context, cleanups);\n } else if (directive.startsWith('bind:')) {\n const attrName = directive.slice(5);\n handlers.bind(attrName)(el, value, context, cleanups);\n } else if (directive.startsWith('on:')) {\n const eventName = directive.slice(3);\n handlers.on(eventName)(el, value, context, cleanups);\n }\n }\n};\n\n/**\n * Recursively processes children of an element.\n * @internal\n */\nexport const processChildren = (\n el: Element,\n context: BindingContext,\n prefix: string,\n cleanups: CleanupFn[],\n handlers: DirectiveHandlers\n): void => {\n const children = Array.from(el.children);\n for (const child of children) {\n // Skip if element has bq-for (handled separately)\n if (!child.hasAttribute(`${prefix}-for`)) {\n processElement(child, context, prefix, cleanups, handlers);\n processChildren(child, context, prefix, cleanups, handlers);\n } else {\n processElement(child, context, prefix, cleanups, handlers);\n }\n }\n};\n","import type { CleanupFn } from '../reactive/index';\nimport {\n createForHandler,\n handleBind,\n handleClass,\n handleHtml,\n handleIf,\n handleModel,\n handleOn,\n handleRef,\n handleShow,\n handleStyle,\n handleText,\n} from './directives/index';\nimport { processChildren, processElement, type DirectiveHandlers } from './process';\nimport type { BindingContext, MountOptions, View } from './types';\n\n/**\n * Mounts a reactive view to an element.\n *\n * @param selector - CSS selector or Element\n * @param context - Binding context with signals, computed, and functions\n * @param options - Mount options\n * @returns The mounted View instance\n *\n * @security **WARNING:** Directive expressions (bq-text, bq-if, bq-on, etc.) are evaluated\n * using `new Function()` at runtime. This means:\n * - Template attributes must come from trusted sources only\n * - NEVER load templates containing bq-* attributes from user input or untrusted APIs\n * - If you must use external templates, validate/sanitize attribute values first\n *\n * @example\n * ```ts\n * import { mount } from 'bquery/view';\n * import { signal, computed } from 'bquery/reactive';\n *\n * const name = signal('World');\n * const greeting = computed(() => `Hello, ${name.value}!`);\n * const items = signal([\n * { id: 1, text: 'Item 1' },\n * { id: 2, text: 'Item 2' },\n * ]);\n *\n * const view = mount('#app', {\n * name,\n * greeting,\n * items,\n * addItem: () => {\n * items.value = [...items.value, { id: Date.now(), text: 'New Item' }];\n * },\n * });\n *\n * // Later, cleanup\n * view.destroy();\n * ```\n */\nexport const mount = (\n selector: string | Element,\n context: BindingContext,\n options: MountOptions = {}\n): View => {\n const { prefix = 'bq', sanitize = true } = options;\n\n const el = typeof selector === 'string' ? document.querySelector(selector) : selector;\n\n if (!el) {\n throw new Error(`bQuery view: Element \"${selector}\" not found.`);\n }\n\n // Reject if root element has bq-for directive\n // bq-for replaces the element with a placeholder comment, which would leave View.el detached\n if (el.hasAttribute(`${prefix}-for`)) {\n throw new Error(\n `bQuery view: Cannot mount on element with ${prefix}-for directive. ` +\n `Wrap the ${prefix}-for element in a container instead.`\n );\n }\n\n const cleanups: CleanupFn[] = [];\n\n const handlers: DirectiveHandlers = {\n text: handleText,\n html: handleHtml(sanitize),\n if: handleIf,\n show: handleShow,\n class: handleClass,\n style: handleStyle,\n model: handleModel,\n ref: handleRef,\n for: createForHandler({\n prefix,\n processElement: (node, nodeContext, nodePrefix, nodeCleanups) =>\n processElement(node, nodeContext, nodePrefix, nodeCleanups, handlers),\n processChildren: (node, nodeContext, nodePrefix, nodeCleanups) =>\n processChildren(node, nodeContext, nodePrefix, nodeCleanups, handlers),\n }),\n bind: handleBind,\n on: handleOn,\n };\n\n const processWithHandlers = (\n node: Element,\n nodeContext: BindingContext,\n nodeCleanups: CleanupFn[]\n ) => {\n // Check if element has bq-for before processing\n // bq-for replaces the element and handles its children internally\n const hasFor = node.hasAttribute(`${prefix}-for`);\n\n processElement(node, nodeContext, prefix, nodeCleanups, handlers);\n\n // Skip processChildren if bq-for was on this element - it handles children itself\n if (!hasFor) {\n processChildren(node, nodeContext, prefix, nodeCleanups, handlers);\n }\n };\n\n // Process the root element and its children\n processWithHandlers(el, context, cleanups);\n\n return {\n el,\n context,\n\n update: (newContext: Partial<BindingContext>) => {\n Object.assign(context, newContext);\n },\n\n destroy: () => {\n for (const cleanup of cleanups) {\n cleanup();\n }\n cleanups.length = 0;\n },\n };\n};\n\n/**\n * Creates a reactive template function.\n *\n * @param template - HTML template string\n * @returns A function that creates a mounted element with the given context\n *\n * @example\n * ```ts\n * import { createTemplate } from 'bquery/view';\n * import { signal } from 'bquery/reactive';\n *\n * const TodoItem = createTemplate(`\n * <li bq-class=\"{ completed: done }\">\n * <input type=\"checkbox\" bq-model=\"done\" />\n * <span bq-text=\"text\"></span>\n * </li>\n * `);\n *\n * const item = TodoItem({\n * done: signal(false),\n * text: 'Buy groceries',\n * });\n *\n * document.querySelector('#list').append(item.el);\n * ```\n */\nexport const createTemplate = (\n template: string,\n options: MountOptions = {}\n): ((context: BindingContext) => View) => {\n return (context: BindingContext) => {\n const container = document.createElement('div');\n container.innerHTML = template.trim();\n\n const el = container.firstElementChild;\n if (!el) {\n throw new Error('bQuery view: Template must contain a single root element.');\n }\n\n // We know at least one element exists (firstElementChild is not null above)\n // Reject if there are multiple root elements\n if (container.childElementCount > 1) {\n throw new Error(\n `bQuery view: Template must contain exactly one root element, found ${container.childElementCount}.`\n );\n }\n\n const { prefix = 'bq' } = options;\n // Reject templates with bq-for or bq-if on the root element\n // These directives replace the element with a placeholder comment, which would leave View.el detached\n // Since processing happens while el is still in the temporary container, the placeholder\n // would remain there while view.el is inserted elsewhere, causing desync on future toggles\n if (el.hasAttribute(`${prefix}-for`) || el.hasAttribute(`${prefix}-if`)) {\n const directive = el.hasAttribute(`${prefix}-for`) ? 'for' : 'if';\n throw new Error(\n `bQuery view: Template root element cannot have ${prefix}-${directive} directive. ` +\n `Wrap the ${prefix}-${directive} element in a container instead.`\n );\n }\n\n return mount(el, context, options);\n };\n};\n"],"names":["MAX_CACHE_SIZE","LRUCache","maxSize","key","value","oldest","evaluateCache","evaluateRawCache","clearExpressionCache","createLazyContext","context","target","prop","isSignal","isComputed","evaluate","expression","lazyContext","fn","error","evaluateRaw","parseObjectExpression","result","inner","parts","current","depth","inString","i","char","prevChar","part","colonIndex","partDepth","partInString","handleBind","attrName","el","cleanups","cleanup","effect","handleClass","previousClasses","newClasses","classMap","className","conditionExpr","condition","classes","cls","getItemKey","item","index","keyExpression","itemName","indexName","keyContext","createForHandler","options","prefix","processElement","processChildren","parent","match","listExpression","template","placeholder","renderedItemsMap","renderedOrder","createItemElement","clone","itemCleanups","itemSig","signal","indexSig","childContext","removeItem","rendered","updateItem","newItem","newIndex","list","newKeys","newItemsByKey","seenKeys","keysToRemove","newRenderedMap","lastInsertedElement","itemCleanup","handleHtml","sanitize","html","sanitizeHtml","handleIf","isInserted","handleModel","input","rawValue","sig","isCheckbox","isRadio","updateInput","eventType","handler","handleOn","eventName","event","eventContext","hasWritableValue","obj","descriptor","handleRef","handleShow","htmlEl","originalDisplay","computed","handleStyle","appliedStyles","newStyles","styleMap","valueExpr","cssProp","handleText","handlers","attributes","attr","name","directive","children","child","mount","selector","node","nodeContext","nodePrefix","nodeCleanups","hasFor","newContext","createTemplate","container"],"mappings":";;;;;AAIA,MAAMA,IAAiB;AAUvB,MAAMC,EAAS;AAAA,EAIb,YAAYC,GAAiB;AAH7B,SAAQ,4BAAY,IAAA,GAIlB,KAAK,UAAUA;AAAA,EACjB;AAAA,EAEA,IAAIC,GAAqC;AACvC,UAAMC,IAAQ,KAAK,MAAM,IAAID,CAAG;AAChC,WAAIC,MAAU,WAEZ,KAAK,MAAM,OAAOD,CAAG,GACrB,KAAK,MAAM,IAAIA,GAAKC,CAAK,IAEpBA;AAAA,EACT;AAAA,EAEA,IAAID,GAAaC,GAAyB;AAExC,QAAI,KAAK,MAAM,IAAID,CAAG;AACpB,WAAK,MAAM,OAAOA,CAAG;AAAA,aACZ,KAAK,MAAM,QAAQ,KAAK,SAAS;AAE1C,YAAME,IAAS,KAAK,MAAM,KAAA,EAAO,OAAO;AACxC,MAAIA,MAAW,UACb,KAAK,MAAM,OA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;AAClC,QAAMiI,IAAY,SAAS,cAAc,KAAK;AAC9C,EAAAA,EAAU,YAAY1E,EAAS,KAAA;AAE/B,QAAM5B,IAAKsG,EAAU;AACrB,MAAI,CAACtG;AACH,UAAM,IAAI,MAAM,2DAA2D;AAK7E,MAAIsG,EAAU,oBAAoB;AAChC,UAAM,IAAI;AAAA,MACR,sEAAsEA,EAAU,iBAAiB;AAAA,IAAA;AAIrG,QAAM,EAAE,QAAAhF,IAAS,KAAA,IAASD;AAK1B,MAAIrB,EAAG,aAAa,GAAGsB,CAAM,MAAM,KAAKtB,EAAG,aAAa,GAAGsB,CAAM,KAAK,GAAG;AACvE,UAAMoE,IAAY1F,EAAG,aAAa,GAAGsB,CAAM,MAAM,IAAI,QAAQ;AAC7D,UAAM,IAAI;AAAA,MACR,kDAAkDA,CAAM,IAAIoE,CAAS,wBACvDpE,CAAM,IAAIoE,CAAS;AAAA,IAAA;AAAA,EAErC;AAEA,SAAOG,GAAM7F,GAAI3B,GAASgD,CAAO;AACnC;"}
1
+ {"version":3,"file":"view.es.mjs","sources":["../src/view/evaluate.ts","../src/view/directives/bind.ts","../src/view/directives/class.ts","../src/view/directives/for.ts","../src/view/directives/html.ts","../src/view/directives/if.ts","../src/view/directives/model.ts","../src/view/directives/on.ts","../src/view/directives/ref.ts","../src/view/directives/show.ts","../src/view/directives/style.ts","../src/view/directives/text.ts","../src/view/process.ts","../src/view/mount.ts"],"sourcesContent":["import { isComputed, isSignal, type Signal } from '../reactive/index';\r\nimport type { BindingContext } from './types';\r\n\r\n/** Maximum number of cached expression functions before LRU eviction */\r\nconst MAX_CACHE_SIZE = 500;\r\n\r\n/** Compiled function type for expression evaluation */\r\ntype CompiledFn = (ctx: BindingContext) => unknown;\r\n\r\n/**\r\n * Simple LRU cache for compiled expression functions.\r\n * Uses Map's insertion order to track recency - accessed items are re-inserted.\r\n * @internal\r\n */\r\nclass LRUCache {\r\n private cache = new Map<string, CompiledFn>();\r\n private maxSize: number;\r\n\r\n constructor(maxSize: number) {\r\n this.maxSize = maxSize;\r\n }\r\n\r\n get(key: string): CompiledFn | undefined {\r\n const value = this.cache.get(key);\r\n if (value !== undefined) {\r\n // Move to end (most recently used) by re-inserting\r\n this.cache.delete(key);\r\n this.cache.set(key, value);\r\n }\r\n return value;\r\n }\r\n\r\n set(key: string, value: CompiledFn): void {\r\n // Delete first if exists to update insertion order\r\n if (this.cache.has(key)) {\r\n this.cache.delete(key);\r\n } else if (this.cache.size >= this.maxSize) {\r\n // Evict oldest (first) entry\r\n const oldest = this.cache.keys().next().value;\r\n if (oldest !== undefined) {\r\n this.cache.delete(oldest);\r\n }\r\n }\r\n this.cache.set(key, value);\r\n }\r\n\r\n clear(): void {\r\n this.cache.clear();\r\n }\r\n\r\n get size(): number {\r\n return this.cache.size;\r\n }\r\n}\r\n\r\n/** LRU cache for compiled evaluate functions, keyed by expression string */\r\nconst evaluateCache = new LRUCache(MAX_CACHE_SIZE);\r\n\r\n/** LRU cache for compiled evaluateRaw functions, keyed by expression string */\r\nconst evaluateRawCache = new LRUCache(MAX_CACHE_SIZE);\r\n\r\n/**\r\n * Clears all cached compiled expression functions.\r\n * Call this when unmounting views or to free memory after heavy template usage.\r\n *\r\n * @example\r\n * ```ts\r\n * import { clearExpressionCache } from 'bquery/view';\r\n *\r\n * // After destroying a view or when cleaning up\r\n * clearExpressionCache();\r\n * ```\r\n */\r\nexport const clearExpressionCache = (): void => {\r\n evaluateCache.clear();\r\n evaluateRawCache.clear();\r\n};\r\n\r\n/**\r\n * Creates a proxy that lazily unwraps signals/computed only when accessed.\r\n * This avoids subscribing to signals that aren't referenced in the expression.\r\n * @internal\r\n */\r\nconst createLazyContext = (context: BindingContext): BindingContext =>\r\n new Proxy(context, {\r\n get(target, prop: string | symbol) {\r\n // Only handle string keys for BindingContext indexing\r\n if (typeof prop !== 'string') {\r\n return Reflect.get(target, prop);\r\n }\r\n const value = target[prop];\r\n // Auto-unwrap signals/computed only when actually accessed\r\n if (isSignal(value) || isComputed(value)) {\r\n return (value as Signal<unknown>).value;\r\n }\r\n return value;\r\n },\r\n has(target, prop: string | symbol) {\r\n // Required for `with` statement to resolve identifiers correctly\r\n if (typeof prop !== 'string') {\r\n return Reflect.has(target, prop);\r\n }\r\n return prop in target;\r\n },\r\n });\r\n\r\n/**\r\n * Evaluates an expression in the given context using `new Function()`.\r\n *\r\n * Signals and computed values in the context are lazily unwrapped only when\r\n * accessed by the expression, avoiding unnecessary subscriptions to unused values.\r\n *\r\n * @security **WARNING:** This function uses dynamic code execution via `new Function()`.\r\n * - NEVER pass expressions derived from user input or untrusted sources\r\n * - Expressions should only come from developer-controlled templates\r\n * - Malicious expressions can access and exfiltrate context data\r\n * - Consider this equivalent to `eval()` in terms of security implications\r\n *\r\n * @internal\r\n */\r\nexport const evaluate = <T = unknown>(expression: string, context: BindingContext): T => {\r\n try {\r\n // Create a proxy that lazily unwraps signals/computed on access\r\n const lazyContext = createLazyContext(context);\r\n\r\n // Use cached function or compile and cache a new one\r\n let fn = evaluateCache.get(expression);\r\n if (!fn) {\r\n // Use `with` to enable direct property access from proxy scope.\r\n // Note: `new Function()` runs in non-strict mode, so `with` is allowed.\r\n fn = new Function('$ctx', `with($ctx) { return (${expression}); }`) as (\r\n ctx: BindingContext\r\n ) => unknown;\r\n evaluateCache.set(expression, fn);\r\n }\r\n return fn(lazyContext) as T;\r\n } catch (error) {\r\n console.error(`bQuery view: Error evaluating \"${expression}\"`, error);\r\n return undefined as T;\r\n }\r\n};\r\n\r\n/**\r\n * Evaluates an expression and returns the raw value (for signal access).\r\n *\r\n * @security **WARNING:** Uses dynamic code execution. See {@link evaluate} for security notes.\r\n * @internal\r\n */\r\nexport const evaluateRaw = <T = unknown>(expression: string, context: BindingContext): T => {\r\n try {\r\n // Use cached function or compile and cache a new one\r\n let fn = evaluateRawCache.get(expression);\r\n if (!fn) {\r\n // Use `with` to enable direct property access from context scope.\r\n // Unlike `evaluate`, we don't use a lazy proxy - values are accessed directly.\r\n fn = new Function('$ctx', `with($ctx) { return (${expression}); }`) as (\r\n ctx: BindingContext\r\n ) => unknown;\r\n evaluateRawCache.set(expression, fn);\r\n }\r\n return fn(context) as T;\r\n } catch (error) {\r\n console.error(`bQuery view: Error evaluating \"${expression}\"`, error);\r\n return undefined as T;\r\n }\r\n};\r\n\r\n/**\r\n * Parses object expression like \"{ active: isActive, disabled: !enabled }\".\r\n * Handles nested structures like function calls, arrays, and template literals.\r\n * @internal\r\n */\r\nexport const parseObjectExpression = (expression: string): Record<string, string> => {\r\n const result: Record<string, string> = {};\r\n\r\n // Remove outer braces and trim\r\n const inner = expression\r\n .trim()\r\n .replace(/^\\{|\\}$/g, '')\r\n .trim();\r\n if (!inner) return result;\r\n\r\n // Split by comma at depth 0, respecting strings and nesting\r\n const parts: string[] = [];\r\n let current = '';\r\n let depth = 0;\r\n let inString: string | null = null;\r\n\r\n for (let i = 0; i < inner.length; i++) {\r\n const char = inner[i];\r\n\r\n // Handle string literals: count consecutive backslashes before a quote\r\n // to correctly distinguish escaped quotes from end-of-string\r\n if (char === '\"' || char === \"'\" || char === '`') {\r\n let backslashCount = 0;\r\n let j = i - 1;\r\n while (j >= 0 && inner[j] === '\\\\') {\r\n backslashCount++;\r\n j--;\r\n }\r\n // Quote is escaped only if preceded by an odd number of backslashes\r\n if (backslashCount % 2 === 0) {\r\n if (inString === null) {\r\n inString = char;\r\n } else if (inString === char) {\r\n inString = null;\r\n }\r\n }\r\n current += char;\r\n continue;\r\n }\r\n\r\n // Skip if inside string\r\n if (inString !== null) {\r\n current += char;\r\n continue;\r\n }\r\n\r\n // Track nesting depth for parentheses, brackets, and braces\r\n if (char === '(' || char === '[' || char === '{') {\r\n depth++;\r\n current += char;\r\n } else if (char === ')' || char === ']' || char === '}') {\r\n depth--;\r\n current += char;\r\n } else if (char === ',' && depth === 0) {\r\n // Top-level comma - split point\r\n parts.push(current.trim());\r\n current = '';\r\n } else {\r\n current += char;\r\n }\r\n }\r\n\r\n // Add the last part\r\n if (current.trim()) {\r\n parts.push(current.trim());\r\n }\r\n\r\n // Parse each part to extract key and value\r\n for (const part of parts) {\r\n // Find the first colon at depth 0 (to handle ternary operators in values)\r\n let colonIndex = -1;\r\n let partDepth = 0;\r\n let partInString: string | null = null;\r\n\r\n for (let i = 0; i < part.length; i++) {\r\n const char = part[i];\r\n\r\n if (char === '\"' || char === \"'\" || char === '`') {\r\n let backslashCount = 0;\r\n let j = i - 1;\r\n while (j >= 0 && part[j] === '\\\\') {\r\n backslashCount++;\r\n j--;\r\n }\r\n if (backslashCount % 2 === 0) {\r\n if (partInString === null) {\r\n partInString = char;\r\n } else if (partInString === char) {\r\n partInString = null;\r\n }\r\n }\r\n continue;\r\n }\r\n\r\n if (partInString !== null) continue;\r\n\r\n if (char === '(' || char === '[' || char === '{') {\r\n partDepth++;\r\n } else if (char === ')' || char === ']' || char === '}') {\r\n partDepth--;\r\n } else if (char === ':' && partDepth === 0) {\r\n colonIndex = i;\r\n break;\r\n }\r\n }\r\n\r\n if (colonIndex > -1) {\r\n const key = part\r\n .slice(0, colonIndex)\r\n .trim()\r\n .replace(/^['\"]|['\"]$/g, '');\r\n const value = part.slice(colonIndex + 1).trim();\r\n result[key] = value;\r\n }\r\n }\r\n\r\n return result;\r\n};\r\n","import { effect } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-bind:attr directive - attribute binding.\n * @internal\n */\nexport const handleBind = (attrName: string): DirectiveHandler => {\n return (el, expression, context, cleanups) => {\n const cleanup = effect(() => {\n const value = evaluate(expression, context);\n if (value == null || value === false) {\n el.removeAttribute(attrName);\n } else if (value === true) {\n el.setAttribute(attrName, '');\n } else {\n el.setAttribute(attrName, String(value));\n }\n });\n cleanups.push(cleanup);\n };\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate, parseObjectExpression } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-class directive - dynamic class binding.\n * Tracks previously added classes to ensure proper cleanup when expressions change.\n * @internal\n */\nexport const handleClass: DirectiveHandler = (el, expression, context, cleanups) => {\n // Track classes added by this directive to clean them up on re-evaluation\n let previousClasses: Set<string> = new Set();\n\n const cleanup = effect(() => {\n const newClasses: Set<string> = new Set();\n\n if (expression.trimStart().startsWith('{')) {\n // Object syntax: { active: isActive, disabled: !enabled }\n const classMap = parseObjectExpression(expression);\n for (const [className, conditionExpr] of Object.entries(classMap)) {\n const condition = evaluate<boolean>(conditionExpr, context);\n el.classList.toggle(className, Boolean(condition));\n // Track class regardless of condition - toggle handles add/remove\n newClasses.add(className);\n }\n } else if (/^\\s*\\[/.test(expression)) {\n // Array literal syntax: [class1, class2]\n const classes = evaluate<string[]>(expression, context);\n if (Array.isArray(classes)) {\n for (const cls of classes) {\n if (cls) {\n el.classList.add(cls);\n newClasses.add(cls);\n }\n }\n }\n } else {\n // Single expression returning string or array\n const result = evaluate<string | string[]>(expression, context);\n if (typeof result === 'string') {\n result.split(/\\s+/).forEach((cls) => {\n if (cls) {\n el.classList.add(cls);\n newClasses.add(cls);\n }\n });\n } else if (Array.isArray(result)) {\n result.forEach((cls) => {\n if (cls) {\n el.classList.add(cls);\n newClasses.add(cls);\n }\n });\n }\n }\n\n // Remove classes that were previously added but are no longer in the new set\n // This keeps directive-managed classes in sync across all syntax forms and provides\n // defensive cleanup behavior for edge cases (e.g. external classList changes)\n for (const cls of previousClasses) {\n if (!newClasses.has(cls)) {\n el.classList.remove(cls);\n }\n }\n\n previousClasses = newClasses;\n });\n\n cleanups.push(cleanup);\n};\n","import { effect, signal, type CleanupFn, type Signal } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { BindingContext, DirectiveHandler } from '../types';\n\ntype ProcessElementFn = (\n el: Element,\n context: BindingContext,\n prefix: string,\n cleanups: CleanupFn[]\n) => void;\n\ntype ProcessChildrenFn = (\n el: Element,\n context: BindingContext,\n prefix: string,\n cleanups: CleanupFn[]\n) => void;\n\n/**\n * Represents a rendered item in bq-for with its DOM element and associated cleanup functions.\n * @internal\n */\ntype RenderedItem = {\n key: unknown;\n element: Element;\n cleanups: CleanupFn[];\n item: unknown;\n index: number;\n itemSignal: Signal<unknown>; // Reactive item value for item-dependent bindings\n indexSignal: Signal<number> | null; // Reactive index for index-dependent bindings\n};\n\n/**\n * Extracts a key from an item using the key expression or falls back to index.\n * @internal\n */\nconst getItemKey = (\n item: unknown,\n index: number,\n keyExpression: string | null,\n itemName: string,\n indexName: string | undefined,\n context: BindingContext\n): unknown => {\n if (!keyExpression) {\n return index; // Fallback to index-based keying\n }\n\n const keyContext: BindingContext = {\n ...context,\n [itemName]: item,\n };\n if (indexName) {\n keyContext[indexName] = index;\n }\n\n return evaluate(keyExpression, keyContext);\n};\n\n/**\n * Handles bq-for directive - list rendering with keyed reconciliation.\n *\n * Supports optional `:key` attribute for efficient DOM reuse:\n * ```html\n * <li bq-for=\"item in items\" :key=\"item.id\">...</li>\n * ```\n *\n * Without a key, falls back to index-based tracking (less efficient for reordering).\n *\n * @internal\n */\nexport const createForHandler = (options: {\n prefix: string;\n processElement: ProcessElementFn;\n processChildren: ProcessChildrenFn;\n}): DirectiveHandler => {\n const { prefix, processElement, processChildren } = options;\n\n return (el, expression, context, cleanups) => {\n const parent = el.parentNode;\n if (!parent) return;\n\n // Parse expression: \"item in items\" or \"(item, index) in items\"\n // Use \\S.* instead of .+ to prevent ReDoS by requiring non-whitespace start\n const match = expression.match(/^\\(?(\\w+)(?:\\s*,\\s*(\\w+))?\\)?\\s+in\\s+(\\S.*)$/);\n if (!match) {\n console.error(`bQuery view: Invalid bq-for expression \"${expression}\"`);\n return;\n }\n\n const [, itemName, indexName, listExpression] = match;\n\n // Extract :key attribute if present\n const keyExpression = el.getAttribute(':key') || el.getAttribute(`${prefix}-key`);\n\n const template = el.cloneNode(true) as Element;\n template.removeAttribute(`${prefix}-for`);\n template.removeAttribute(':key');\n template.removeAttribute(`${prefix}-key`);\n\n // Create placeholder comment\n const placeholder = document.createComment(`bq-for: ${expression}`);\n parent.replaceChild(placeholder, el);\n\n // Track rendered items by key for reconciliation\n let renderedItemsMap = new Map<unknown, RenderedItem>();\n let renderedOrder: unknown[] = [];\n\n /**\n * Creates a new DOM element for an item.\n */\n const createItemElement = (item: unknown, index: number, key: unknown): RenderedItem => {\n const clone = template.cloneNode(true) as Element;\n const itemCleanups: CleanupFn[] = [];\n\n // Create reactive signals for item and index\n const itemSig = signal(item);\n const indexSig = indexName ? signal(index) : null;\n\n const childContext: BindingContext = {\n ...context,\n [itemName]: itemSig,\n };\n if (indexName && indexSig) {\n childContext[indexName] = indexSig;\n }\n\n // Process bindings on the clone\n processElement(clone, childContext, prefix, itemCleanups);\n processChildren(clone, childContext, prefix, itemCleanups);\n\n return {\n key,\n element: clone,\n cleanups: itemCleanups,\n item,\n index,\n itemSignal: itemSig,\n indexSignal: indexSig,\n };\n };\n\n /**\n * Removes a rendered item and cleans up its effects.\n */\n const removeItem = (rendered: RenderedItem): void => {\n for (const cleanup of rendered.cleanups) {\n cleanup();\n }\n rendered.element.remove();\n };\n\n /**\n * Updates an existing item's data and index when reused.\n * Updates the reactive signals so bindings re-render.\n */\n const updateItem = (rendered: RenderedItem, newItem: unknown, newIndex: number): void => {\n // Update item if it changed\n if (!Object.is(rendered.item, newItem)) {\n rendered.item = newItem;\n rendered.itemSignal.value = newItem;\n }\n\n // Update index if it changed\n if (rendered.index !== newIndex) {\n rendered.index = newIndex;\n if (rendered.indexSignal) {\n rendered.indexSignal.value = newIndex;\n }\n }\n };\n\n const cleanup = effect(() => {\n const list = evaluate<unknown[]>(listExpression, context);\n\n if (!Array.isArray(list)) {\n // Clear all if list is invalid\n for (const rendered of renderedItemsMap.values()) {\n removeItem(rendered);\n }\n renderedItemsMap.clear();\n renderedOrder = [];\n return;\n }\n\n // Build new key order and detect changes\n const newKeys: unknown[] = [];\n const newItemsByKey = new Map<unknown, { item: unknown; index: number }>();\n const seenKeys = new Set<unknown>();\n\n list.forEach((item, index) => {\n let key = getItemKey(item, index, keyExpression, itemName, indexName, context);\n\n // Detect duplicate keys - warn developer and fall back to unique composite key\n if (seenKeys.has(key)) {\n console.warn(\n `bq-for: Duplicate key \"${String(key)}\" detected at index ${index}. ` +\n `Falling back to index-based key for this item. ` +\n `Ensure :key expressions produce unique values for each item.`\n );\n // Create a unique composite key to avoid corrupting rendered output\n key = { __bqDuplicateKey: key, __bqIndex: index };\n }\n seenKeys.add(key);\n\n newKeys.push(key);\n newItemsByKey.set(key, { item, index });\n });\n\n // Identify items to remove (in old but not in new)\n const keysToRemove: unknown[] = [];\n for (const key of renderedOrder) {\n if (!newItemsByKey.has(key)) {\n keysToRemove.push(key);\n }\n }\n\n // Remove deleted items\n for (const key of keysToRemove) {\n const rendered = renderedItemsMap.get(key);\n if (rendered) {\n removeItem(rendered);\n renderedItemsMap.delete(key);\n }\n }\n\n // Process new list: create new items, update indices, reorder\n const newRenderedMap = new Map<unknown, RenderedItem>();\n let lastInsertedElement: Element | Comment = placeholder;\n\n for (let i = 0; i < newKeys.length; i++) {\n const key = newKeys[i];\n const { item, index } = newItemsByKey.get(key)!;\n let rendered = renderedItemsMap.get(key);\n\n if (rendered) {\n // Reuse existing element\n updateItem(rendered, item, index);\n newRenderedMap.set(key, rendered);\n\n // Check if element needs to be moved\n const currentNext: ChildNode | null = lastInsertedElement.nextSibling;\n if (currentNext !== rendered.element) {\n // Move element to correct position\n lastInsertedElement.after(rendered.element);\n }\n lastInsertedElement = rendered.element;\n } else {\n // Create new element\n rendered = createItemElement(item, index, key);\n newRenderedMap.set(key, rendered);\n\n // Insert at correct position\n lastInsertedElement.after(rendered.element);\n lastInsertedElement = rendered.element;\n }\n }\n\n // Update tracking state\n renderedItemsMap = newRenderedMap;\n renderedOrder = newKeys;\n });\n\n // When the bq-for itself is cleaned up, also cleanup all rendered items\n cleanups.push(() => {\n cleanup();\n for (const rendered of renderedItemsMap.values()) {\n for (const itemCleanup of rendered.cleanups) {\n itemCleanup();\n }\n }\n renderedItemsMap.clear();\n });\n };\n};\n","import { effect } from '../../reactive/index';\nimport { sanitizeHtml } from '../../security/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-html directive - sets innerHTML (sanitized by default).\n * @internal\n */\nexport const handleHtml = (sanitize: boolean): DirectiveHandler => {\n return (el, expression, context, cleanups) => {\n const cleanup = effect(() => {\n const value = evaluate<string>(expression, context);\n const html = String(value ?? '');\n el.innerHTML = sanitize ? sanitizeHtml(html) : html;\n });\n cleanups.push(cleanup);\n };\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-if directive - conditional rendering.\n * @internal\n */\nexport const handleIf: DirectiveHandler = (el, expression, context, cleanups) => {\n const placeholder = document.createComment(`bq-if: ${expression}`);\n\n // Store original element state\n let isInserted = true;\n\n const cleanup = effect(() => {\n const condition = evaluate<boolean>(expression, context);\n\n if (condition && !isInserted) {\n // Insert element using replaceWith to handle moved elements\n placeholder.replaceWith(el);\n isInserted = true;\n } else if (!condition && isInserted) {\n // Remove element using replaceWith to handle moved elements\n el.replaceWith(placeholder);\n isInserted = false;\n }\n });\n\n cleanups.push(cleanup);\n};\n","import { effect, isSignal, type Signal } from '../../reactive/index';\nimport { evaluateRaw } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-model directive - two-way binding.\n * @internal\n */\nexport const handleModel: DirectiveHandler = (el, expression, context, cleanups) => {\n const input = el as HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;\n const rawValue = evaluateRaw<Signal<unknown>>(expression, context);\n\n if (!isSignal(rawValue)) {\n console.warn(`bQuery view: bq-model requires a signal, got \"${expression}\"`);\n return;\n }\n\n const sig = rawValue as Signal<unknown>;\n\n // Initial value sync\n const isCheckbox = input.type === 'checkbox';\n const isRadio = input.type === 'radio';\n\n const updateInput = () => {\n if (isCheckbox) {\n (input as HTMLInputElement).checked = Boolean(sig.value);\n } else if (isRadio) {\n (input as HTMLInputElement).checked = sig.value === input.value;\n } else {\n input.value = String(sig.value ?? '');\n }\n };\n\n // Effect to sync signal -> input\n const cleanup = effect(() => {\n updateInput();\n });\n cleanups.push(cleanup);\n\n // Event listener to sync input -> signal\n const eventType = input.tagName === 'SELECT' ? 'change' : 'input';\n const handler = () => {\n if (isCheckbox) {\n sig.value = (input as HTMLInputElement).checked;\n } else if (isRadio) {\n if ((input as HTMLInputElement).checked) {\n sig.value = input.value;\n }\n } else {\n sig.value = input.value;\n }\n };\n\n input.addEventListener(eventType, handler);\n cleanups.push(() => input.removeEventListener(eventType, handler));\n};\n","import { evaluateRaw } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-on:event directive - event binding.\n * @internal\n */\nexport const handleOn = (eventName: string): DirectiveHandler => {\n return (el, expression, context, cleanups) => {\n const handler = (event: Event) => {\n // Add $event to context for expression evaluation\n const eventContext = { ...context, $event: event, $el: el };\n\n // Check if expression contains a function call (has parentheses)\n // If not, it might be a plain function reference like \"handleClick\"\n // Note: Method references like \"handlers.onClick\" will lose their receiver\n // when auto-invoked. For methods, use explicit calls: \"handlers.onClick($event)\"\n const containsCall = expression.includes('(');\n\n if (!containsCall) {\n // Evaluate the expression - if it returns a function, invoke it with $event\n const result = evaluateRaw<unknown>(expression, eventContext);\n if (typeof result === 'function') {\n // Auto-invoke with event. Note: `this` will be undefined for method references.\n // For proper method binding, use explicit syntax: \"obj.method($event)\"\n result(event);\n return;\n }\n // If not a function, the expression was already evaluated (e.g., \"count.value++\")\n return;\n }\n\n // Otherwise evaluate as expression using evaluateRaw to allow signal mutations\n // (e.g., \"count.value++\" or \"handleClick($event)\")\n evaluateRaw(expression, eventContext);\n };\n\n el.addEventListener(eventName, handler);\n cleanups.push(() => el.removeEventListener(eventName, handler));\n };\n};\n","import { isSignal, type Signal } from '../../reactive/index';\nimport { evaluateRaw } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Checks if an object has a writable `value` property.\n * Returns true if `value` is an own data property or an accessor with a setter.\n * @internal\n */\nfunction hasWritableValue(obj: object): obj is { value: Element | null } {\n const descriptor = Object.getOwnPropertyDescriptor(obj, 'value');\n if (!descriptor) return false;\n // Data property: check writable flag\n if ('value' in descriptor) return descriptor.writable === true;\n // Accessor property: check for setter\n return typeof descriptor.set === 'function';\n}\n\n/**\n * Handles bq-ref directive - element reference.\n * @internal\n */\nexport const handleRef: DirectiveHandler = (el, expression, context, cleanups) => {\n const rawValue = evaluateRaw<Signal<Element | null> | { value: Element | null }>(\n expression,\n context\n );\n\n if (isSignal(rawValue)) {\n rawValue.value = el;\n cleanups.push(() => {\n rawValue.value = null;\n });\n } else if (typeof rawValue === 'object' && rawValue !== null && hasWritableValue(rawValue)) {\n // Object with writable .value property (e.g., { value: null })\n rawValue.value = el;\n cleanups.push(() => {\n rawValue.value = null;\n });\n }\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-show directive - toggle visibility.\n * @internal\n */\nexport const handleShow: DirectiveHandler = (el, expression, context, cleanups) => {\n const htmlEl = el as HTMLElement;\n // Capture the computed display value to properly restore visibility.\n // If inline display is 'none' or empty, we need to use the computed value.\n // Use ownerDocument.defaultView for cross-document/iframe compatibility.\n let originalDisplay = htmlEl.style.display;\n if (!originalDisplay || originalDisplay === 'none') {\n const computed = htmlEl.ownerDocument.defaultView?.getComputedStyle(htmlEl).display ?? '';\n originalDisplay = computed !== 'none' ? computed : '';\n }\n\n const cleanup = effect(() => {\n const condition = evaluate<boolean>(expression, context);\n htmlEl.style.display = condition ? originalDisplay : 'none';\n });\n\n cleanups.push(cleanup);\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate, parseObjectExpression } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-style directive - dynamic style binding.\n * @internal\n */\nexport const handleStyle: DirectiveHandler = (el, expression, context, cleanups) => {\n const htmlEl = el as HTMLElement;\n let appliedStyles: Set<string> = new Set();\n\n const cleanup = effect(() => {\n const newStyles = new Set<string>();\n\n if (expression.trimStart().startsWith('{')) {\n const styleMap = parseObjectExpression(expression);\n for (const [prop, valueExpr] of Object.entries(styleMap)) {\n const value = evaluate<string>(valueExpr, context);\n const cssProp = prop.replace(/([A-Z])/g, '-$1').toLowerCase();\n htmlEl.style.setProperty(cssProp, String(value ?? ''));\n newStyles.add(cssProp);\n }\n } else {\n const result = evaluate<Record<string, string>>(expression, context);\n if (result && typeof result === 'object') {\n for (const [prop, value] of Object.entries(result)) {\n const cssProp = prop.replace(/([A-Z])/g, '-$1').toLowerCase();\n htmlEl.style.setProperty(cssProp, String(value ?? ''));\n newStyles.add(cssProp);\n }\n }\n }\n\n // Remove styles that were previously applied but are no longer present\n for (const cssProp of appliedStyles) {\n if (!newStyles.has(cssProp)) {\n htmlEl.style.removeProperty(cssProp);\n }\n }\n\n // Update the set of applied styles\n appliedStyles = newStyles;\n });\n\n cleanups.push(cleanup);\n};\n","import { effect } from '../../reactive/index';\nimport { evaluate } from '../evaluate';\nimport type { DirectiveHandler } from '../types';\n\n/**\n * Handles bq-text directive - sets text content.\n * @internal\n */\nexport const handleText: DirectiveHandler = (el, expression, context, cleanups) => {\n const cleanup = effect(() => {\n const value = evaluate(expression, context);\n el.textContent = String(value ?? '');\n });\n cleanups.push(cleanup);\n};\n","import type { CleanupFn } from '../reactive/index';\nimport type { BindingContext, DirectiveHandler } from './types';\n\nexport type DirectiveHandlers = {\n text: DirectiveHandler;\n html: DirectiveHandler;\n if: DirectiveHandler;\n show: DirectiveHandler;\n class: DirectiveHandler;\n style: DirectiveHandler;\n model: DirectiveHandler;\n ref: DirectiveHandler;\n for: DirectiveHandler;\n bind: (attrName: string) => DirectiveHandler;\n on: (eventName: string) => DirectiveHandler;\n};\n\n/**\n * Processes a single element for directives.\n * @internal\n */\nexport const processElement = (\n el: Element,\n context: BindingContext,\n prefix: string,\n cleanups: CleanupFn[],\n handlers: DirectiveHandlers\n): void => {\n const attributes = Array.from(el.attributes);\n\n for (const attr of attributes) {\n const { name, value } = attr;\n\n if (!name.startsWith(`${prefix}-`)) continue;\n\n const directive = name.slice(prefix.length + 1); // Remove prefix and dash\n\n // Handle bq-for specially (creates new scope)\n if (directive === 'for') {\n handlers.for(el, value, context, cleanups);\n return; // Don't process children, bq-for handles it\n }\n\n // Handle other directives\n if (directive === 'text') {\n handlers.text(el, value, context, cleanups);\n } else if (directive === 'html') {\n handlers.html(el, value, context, cleanups);\n } else if (directive === 'if') {\n handlers.if(el, value, context, cleanups);\n } else if (directive === 'show') {\n handlers.show(el, value, context, cleanups);\n } else if (directive === 'class') {\n handlers.class(el, value, context, cleanups);\n } else if (directive === 'style') {\n handlers.style(el, value, context, cleanups);\n } else if (directive === 'model') {\n handlers.model(el, value, context, cleanups);\n } else if (directive === 'ref') {\n handlers.ref(el, value, context, cleanups);\n } else if (directive.startsWith('bind:')) {\n const attrName = directive.slice(5);\n handlers.bind(attrName)(el, value, context, cleanups);\n } else if (directive.startsWith('on:')) {\n const eventName = directive.slice(3);\n handlers.on(eventName)(el, value, context, cleanups);\n }\n }\n};\n\n/**\n * Recursively processes children of an element.\n * @internal\n */\nexport const processChildren = (\n el: Element,\n context: BindingContext,\n prefix: string,\n cleanups: CleanupFn[],\n handlers: DirectiveHandlers\n): void => {\n const children = Array.from(el.children);\n for (const child of children) {\n // Skip if element has bq-for (handled separately)\n if (!child.hasAttribute(`${prefix}-for`)) {\n processElement(child, context, prefix, cleanups, handlers);\n processChildren(child, context, prefix, cleanups, handlers);\n } else {\n processElement(child, context, prefix, cleanups, handlers);\n }\n }\n};\n","import type { CleanupFn } from '../reactive/index';\nimport {\n createForHandler,\n handleBind,\n handleClass,\n handleHtml,\n handleIf,\n handleModel,\n handleOn,\n handleRef,\n handleShow,\n handleStyle,\n handleText,\n} from './directives/index';\nimport { processChildren, processElement, type DirectiveHandlers } from './process';\nimport type { BindingContext, MountOptions, View } from './types';\n\n/**\n * Mounts a reactive view to an element.\n *\n * @param selector - CSS selector or Element\n * @param context - Binding context with signals, computed, and functions\n * @param options - Mount options\n * @returns The mounted View instance\n *\n * @security **WARNING:** Directive expressions (bq-text, bq-if, bq-on, etc.) are evaluated\n * using `new Function()` at runtime. This means:\n * - Template attributes must come from trusted sources only\n * - NEVER load templates containing bq-* attributes from user input or untrusted APIs\n * - If you must use external templates, validate/sanitize attribute values first\n *\n * @example\n * ```ts\n * import { mount } from 'bquery/view';\n * import { signal, computed } from 'bquery/reactive';\n *\n * const name = signal('World');\n * const greeting = computed(() => `Hello, ${name.value}!`);\n * const items = signal([\n * { id: 1, text: 'Item 1' },\n * { id: 2, text: 'Item 2' },\n * ]);\n *\n * const view = mount('#app', {\n * name,\n * greeting,\n * items,\n * addItem: () => {\n * items.value = [...items.value, { id: Date.now(), text: 'New Item' }];\n * },\n * });\n *\n * // Later, cleanup\n * view.destroy();\n * ```\n */\nexport const mount = (\n selector: string | Element,\n context: BindingContext,\n options: MountOptions = {}\n): View => {\n const { prefix = 'bq', sanitize = true } = options;\n\n const el = typeof selector === 'string' ? document.querySelector(selector) : selector;\n\n if (!el) {\n throw new Error(`bQuery view: Element \"${selector}\" not found.`);\n }\n\n // Reject if root element has bq-for directive\n // bq-for replaces the element with a placeholder comment, which would leave View.el detached\n if (el.hasAttribute(`${prefix}-for`)) {\n throw new Error(\n `bQuery view: Cannot mount on element with ${prefix}-for directive. ` +\n `Wrap the ${prefix}-for element in a container instead.`\n );\n }\n\n const cleanups: CleanupFn[] = [];\n\n const handlers: DirectiveHandlers = {\n text: handleText,\n html: handleHtml(sanitize),\n if: handleIf,\n show: handleShow,\n class: handleClass,\n style: handleStyle,\n model: handleModel,\n ref: handleRef,\n for: createForHandler({\n prefix,\n processElement: (node, nodeContext, nodePrefix, nodeCleanups) =>\n processElement(node, nodeContext, nodePrefix, nodeCleanups, handlers),\n processChildren: (node, nodeContext, nodePrefix, nodeCleanups) =>\n processChildren(node, nodeContext, nodePrefix, nodeCleanups, handlers),\n }),\n bind: handleBind,\n on: handleOn,\n };\n\n const processWithHandlers = (\n node: Element,\n nodeContext: BindingContext,\n nodeCleanups: CleanupFn[]\n ) => {\n // Check if element has bq-for before processing\n // bq-for replaces the element and handles its children internally\n const hasFor = node.hasAttribute(`${prefix}-for`);\n\n processElement(node, nodeContext, prefix, nodeCleanups, handlers);\n\n // Skip processChildren if bq-for was on this element - it handles children itself\n if (!hasFor) {\n processChildren(node, nodeContext, prefix, nodeCleanups, handlers);\n }\n };\n\n // Process the root element and its children\n processWithHandlers(el, context, cleanups);\n\n return {\n el,\n context,\n\n update: (newContext: Partial<BindingContext>) => {\n Object.assign(context, newContext);\n },\n\n destroy: () => {\n for (const cleanup of cleanups) {\n cleanup();\n }\n cleanups.length = 0;\n },\n };\n};\n\n/**\n * Creates a reactive template function.\n *\n * @param template - HTML template string\n * @returns A function that creates a mounted element with the given context\n *\n * @example\n * ```ts\n * import { createTemplate } from 'bquery/view';\n * import { signal } from 'bquery/reactive';\n *\n * const TodoItem = createTemplate(`\n * <li bq-class=\"{ completed: done }\">\n * <input type=\"checkbox\" bq-model=\"done\" />\n * <span bq-text=\"text\"></span>\n * </li>\n * `);\n *\n * const item = TodoItem({\n * done: signal(false),\n * text: 'Buy groceries',\n * });\n *\n * document.querySelector('#list').append(item.el);\n * ```\n */\nexport const createTemplate = (\n template: string,\n options: MountOptions = {}\n): ((context: BindingContext) => View) => {\n return (context: BindingContext) => {\n const container = document.createElement('div');\n container.innerHTML = template.trim();\n\n const el = container.firstElementChild;\n if (!el) {\n throw new Error('bQuery view: Template must contain a single root element.');\n }\n\n // We know at least one element exists (firstElementChild is not null above)\n // Reject if there are multiple root elements\n if (container.childElementCount > 1) {\n throw new Error(\n `bQuery view: Template must contain exactly one root element, found ${container.childElementCount}.`\n );\n }\n\n const { prefix = 'bq' } = options;\n // Reject templates with bq-for or bq-if on the root element\n // These directives replace the element with a placeholder comment, which would leave View.el detached\n // Since processing happens while el is still in the temporary container, the placeholder\n // would remain there while view.el is inserted elsewhere, causing desync on future toggles\n if (el.hasAttribute(`${prefix}-for`) || el.hasAttribute(`${prefix}-if`)) {\n const directive = el.hasAttribute(`${prefix}-for`) ? 'for' : 'if';\n throw new Error(\n `bQuery view: Template root element cannot have ${prefix}-${directive} directive. ` +\n `Wrap the ${prefix}-${directive} element in a container instead.`\n );\n }\n\n return mount(el, context, options);\n };\n};\n"],"names":["MAX_CACHE_SIZE","LRUCache","maxSize","key","value","oldest","evaluateCache","evaluateRawCache","clearExpressionCache","createLazyContext","context","target","prop","isSignal","isComputed","evaluate","expression","lazyContext","fn","error","evaluateRaw","parseObjectExpression","result","inner","parts","current","depth","inString","i","char","backslashCount","j","part","colonIndex","partDepth","partInString","handleBind","attrName","el","cleanups","cleanup","effect","handleClass","previousClasses","newClasses","classMap","className","conditionExpr","condition","classes","cls","getItemKey","item","index","keyExpression","itemName","indexName","keyContext","createForHandler","options","prefix","processElement","processChildren","parent","match","listExpression","template","placeholder","renderedItemsMap","renderedOrder","createItemElement","clone","itemCleanups","itemSig","signal","indexSig","childContext","removeItem","rendered","updateItem","newItem","newIndex","list","newKeys","newItemsByKey","seenKeys","keysToRemove","newRenderedMap","lastInsertedElement","itemCleanup","handleHtml","sanitize","html","sanitizeHtml","handleIf","isInserted","handleModel","input","rawValue","sig","isCheckbox","isRadio","updateInput","eventType","handler","handleOn","eventName","event","eventContext","hasWritableValue","obj","descriptor","handleRef","handleShow","htmlEl","originalDisplay","computed","handleStyle","appliedStyles","newStyles","styleMap","valueExpr","cssProp","handleText","handlers","attributes","attr","name","directive","children","child","mount","selector","node","nodeContext","nodePrefix","nodeCleanups","hasFor","newContext","createTemplate","container"],"mappings":";;;;;AAIA,MAAMA,IAAiB;AAUvB,MAAMC,EAAS;AAAA,EAIb,YAAYC,GAAiB;AAH7B,SAAQ,4BAAY,IAAA,GAIlB,KAAK,UAAUA;AAAA,EACjB;AAAA,EAEA,IAAIC,GAAqC;AACvC,UAAMC,IAAQ,KAAK,MA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AewE,GAAMC,GAAa1E,GAAQ4E,GAAcZ,CAAQ,GAG3Da,KACH3E,EAAgBuE,GAAMC,GAAa1E,GAAQ4E,GAAcZ,CAAQ;AAAA,EAErE,GAGoBtF,GAAI5B,GAAS6B,CAAQ,GAElC;AAAA,IACL,IAAAD;AAAA,IACA,SAAA5B;AAAA,IAEA,QAAQ,CAACgI,MAAwC;AAC/C,aAAO,OAAOhI,GAASgI,CAAU;AAAA,IACnC;AAAA,IAEA,SAAS,MAAM;AACb,iBAAWlG,KAAWD;AACpB,QAAAC,EAAA;AAEF,MAAAD,EAAS,SAAS;AAAA,IACpB;AAAA,EAAA;AAEJ,GA4BaoG,KAAiB,CAC5BzE,GACAP,IAAwB,OAEjB,CAACjD,MAA4B;AAClC,QAAMkI,IAAY,SAAS,cAAc,KAAK;AAC9C,EAAAA,EAAU,YAAY1E,EAAS,KAAA;AAE/B,QAAM5B,IAAKsG,EAAU;AACrB,MAAI,CAACtG;AACH,UAAM,IAAI,MAAM,2DAA2D;AAK7E,MAAIsG,EAAU,oBAAoB;AAChC,UAAM,IAAI;AAAA,MACR,sEAAsEA,EAAU,iBAAiB;AAAA,IAAA;AAIrG,QAAM,EAAE,QAAAhF,IAAS,KAAA,IAASD;AAK1B,MAAIrB,EAAG,aAAa,GAAGsB,CAAM,MAAM,KAAKtB,EAAG,aAAa,GAAGsB,CAAM,KAAK,GAAG;AACvE,UAAMoE,IAAY1F,EAAG,aAAa,GAAGsB,CAAM,MAAM,IAAI,QAAQ;AAC7D,UAAM,IAAI;AAAA,MACR,kDAAkDA,CAAM,IAAIoE,CAAS,wBACvDpE,CAAM,IAAIoE,CAAS;AAAA,IAAA;AAAA,EAErC;AAEA,SAAOG,GAAM7F,GAAI5B,GAASiD,CAAO;AACnC;"}
@@ -1,5 +1,5 @@
1
- import { s as c } from "./core-COenAZjD.js";
2
- import { e as n } from "./type-guards-DRma3-Kc.js";
1
+ import { s as c } from "./core-BhpuvPhy.js";
2
+ import { e as n } from "./type-guards-BdKlYYlS.js";
3
3
  const m = (s, o) => {
4
4
  let l = !1, t = null;
5
5
  try {
@@ -55,4 +55,4 @@ export {
55
55
  g as r,
56
56
  _ as w
57
57
  };
58
- //# sourceMappingURL=watch-CXyaBC_9.js.map
58
+ //# sourceMappingURL=watch-DXXv3iAI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"watch-CXyaBC_9.js","sources":["../src/reactive/persisted.ts","../src/reactive/readonly.ts","../src/reactive/watch.ts"],"sourcesContent":["/**\n * LocalStorage-backed signals.\n */\n\nimport { signal, Signal } from './core';\nimport { effect } from './effect';\n\n/**\n * Creates a signal that persists to localStorage.\n *\n * @template T - The type of the signal value\n * @param key - The localStorage key\n * @param initialValue - The initial value if not found in storage\n * @returns A Signal that syncs with localStorage (falls back to in-memory if unavailable)\n */\nexport const persistedSignal = <T>(key: string, initialValue: T): Signal<T> => {\n // Check if localStorage is available and accessible\n let hasLocalStorage = false;\n let storage: Storage | null = null;\n\n try {\n // In Safari private mode, accessing localStorage can throw SecurityError\n storage = globalThis.localStorage;\n if (storage) {\n // Test actual access to ensure it's not just present but usable\n // Use a randomized test key to avoid overwriting real user data\n const testKey = `__bquery_test_${Math.random().toString(36).slice(2, 9)}__`;\n const testValue = '__test__';\n try {\n storage.setItem(testKey, testValue);\n storage.getItem(testKey);\n hasLocalStorage = true;\n } finally {\n // Ensure we don't leave any test data behind\n try {\n storage.removeItem(testKey);\n } catch {\n // Ignore cleanup errors (e.g., storage becoming unavailable)\n }\n }\n }\n } catch {\n // localStorage unavailable or access denied (Safari private mode, sandboxed iframes, etc.)\n hasLocalStorage = false;\n }\n\n let stored: T = initialValue;\n\n if (hasLocalStorage && storage) {\n try {\n const raw = storage.getItem(key);\n if (raw !== null) {\n stored = JSON.parse(raw) as T;\n }\n } catch {\n // Use initial value on parse error or access denial\n }\n }\n\n const sig = signal(stored);\n\n // Only set up persistence effect if localStorage is available\n if (hasLocalStorage && storage) {\n effect(() => {\n try {\n storage!.setItem(key, JSON.stringify(sig.value));\n } catch {\n // Ignore storage errors (quota exceeded, sandboxed iframes, etc.)\n }\n });\n }\n\n return sig;\n};\n","/**\n * Read-only signal wrappers.\n */\n\nimport type { Signal } from './core';\n\n/**\n * A readonly wrapper around a signal that prevents writes.\n * Provides read-only access to a signal's value while maintaining reactivity.\n *\n * @template T - The type of the wrapped value\n */\nexport interface ReadonlySignal<T> {\n /** Gets the current value with dependency tracking. */\n readonly value: T;\n /** Gets the current value without dependency tracking. */\n peek(): T;\n}\n\n/**\n * Creates a read-only view of a signal.\n * Useful for exposing reactive state without allowing modifications.\n *\n * @template T - The type of the signal value\n * @param sig - The signal to wrap\n * @returns A readonly signal wrapper\n */\nexport const readonly = <T>(sig: Signal<T>): ReadonlySignal<T> => ({\n get value(): T {\n return sig.value;\n },\n peek(): T {\n return sig.peek();\n },\n});\n","/**\n * Value watching helpers.\n */\n\nimport type { Computed } from './computed';\nimport type { Signal } from './core';\nimport type { CleanupFn } from './internals';\n\nimport { effect } from './effect';\n\n/**\n * Options for the watch function.\n */\nexport interface WatchOptions<T> {\n /** If true, the callback is invoked immediately with the current value. */\n immediate?: boolean;\n /** Custom equality function. Defaults to Object.is. */\n equals?: (a: T, b: T | undefined) => boolean;\n}\n\n/**\n * Watches a signal or computed value and calls a callback with old and new values.\n * Unlike effect, watch provides access to the previous value.\n * The callback is only invoked when the value actually changes (compared via Object.is or custom equals).\n *\n * @template T - The type of the watched value\n * @param source - The signal or computed to watch\n * @param callback - Function called with (newValue, oldValue) on changes\n * @param options - Watch options\n * @returns A cleanup function to stop watching\n *\n * @example\n * ```ts\n * const count = signal(0);\n * watch(count, (newVal, oldVal) => {\n * console.log(`Changed from ${oldVal} to ${newVal}`);\n * });\n *\n * // With custom equality for objects\n * const user = signal({ id: 1, name: 'Alice' });\n * watch(user, (newVal, oldVal) => { ... }, {\n * equals: (a, b) => a?.id === b?.id\n * });\n * ```\n */\nexport const watch = <T>(\n source: Signal<T> | Computed<T>,\n callback: (newValue: T, oldValue: T | undefined) => void,\n options: WatchOptions<T> = {}\n): CleanupFn => {\n const { immediate = false, equals = Object.is } = options;\n let oldValue: T | undefined;\n let isFirst = true;\n\n return effect(() => {\n const newValue = source.value;\n\n if (isFirst) {\n isFirst = false;\n oldValue = newValue;\n if (immediate) {\n callback(newValue, undefined);\n }\n return;\n }\n\n // Only call callback if value actually changed\n if (!equals(newValue, oldValue)) {\n callback(newValue, oldValue);\n oldValue = newValue;\n }\n });\n};\n"],"names":["persistedSignal","key","initialValue","hasLocalStorage","storage","testKey","testValue","stored","raw","sig","signal","effect","readonly","watch","source","callback","options","immediate","equals","oldValue","isFirst","newValue"],"mappings":";;AAeO,MAAMA,IAAkB,CAAIC,GAAaC,MAA+B;AAE7E,MAAIC,IAAkB,IAClBC,IAA0B;AAE9B,MAAI;AAGF,QADAA,IAAU,WAAW,cACjBA,GAAS;AAGX,YAAMC,IAAU,iBAAiB,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,MACjEC,IAAY;AAClB,UAAI;AACF,QAAAF,EAAQ,QAAQC,GAASC,CAAS,GAClCF,EAAQ,QAAQC,CAAO,GACvBF,IAAkB;AAAA,MACpB,UAAA;AAEE,YAAI;AACF,UAAAC,EAAQ,WAAWC,CAAO;AAAA,QAC5B,QAAQ;AAAA,QAER;AAAA,MACF;AAAA,IACF;AAAA,EACF,QAAQ;AAEN,IAAAF,IAAkB;AAAA,EACpB;AAEA,MAAII,IAAYL;AAEhB,MAAIC,KAAmBC;AACrB,QAAI;AACF,YAAMI,IAAMJ,EAAQ,QAAQH,CAAG;AAC/B,MAAIO,MAAQ,SACVD,IAAS,KAAK,MAAMC,CAAG;AAAA,IAE3B,QAAQ;AAAA,IAER;AAGF,QAAMC,IAAMC,EAAOH,CAAM;AAGzB,SAAIJ,KAAmBC,KACrBO,EAAO,MAAM;AACX,QAAI;AACF,MAAAP,EAAS,QAAQH,GAAK,KAAK,UAAUQ,EAAI,KAAK,CAAC;AAAA,IACjD,QAAQ;AAAA,IAER;AAAA,EACF,CAAC,GAGIA;AACT,GC9CaG,IAAW,CAAIH,OAAuC;AAAA,EACjE,IAAI,QAAW;AACb,WAAOA,EAAI;AAAA,EACb;AAAA,EACA,OAAU;AACR,WAAOA,EAAI,KAAA;AAAA,EACb;AACF,ICWaI,IAAQ,CACnBC,GACAC,GACAC,IAA2B,CAAA,MACb;AACd,QAAM,EAAE,WAAAC,IAAY,IAAO,QAAAC,IAAS,OAAO,OAAOF;AAClD,MAAIG,GACAC,IAAU;AAEd,SAAOT,EAAO,MAAM;AAClB,UAAMU,IAAWP,EAAO;AAExB,QAAIM,GAAS;AACX,MAAAA,IAAU,IACVD,IAAWE,GACPJ,KACFF,EAASM,GAAU,MAAS;AAE9B;AAAA,IACF;AAGA,IAAKH,EAAOG,GAAUF,CAAQ,MAC5BJ,EAASM,GAAUF,CAAQ,GAC3BA,IAAWE;AAAA,EAEf,CAAC;AACH;"}
1
+ {"version":3,"file":"watch-DXXv3iAI.js","sources":["../src/reactive/persisted.ts","../src/reactive/readonly.ts","../src/reactive/watch.ts"],"sourcesContent":["/**\n * LocalStorage-backed signals.\n */\n\nimport { signal, Signal } from './core';\nimport { effect } from './effect';\n\n/**\n * Creates a signal that persists to localStorage.\n *\n * @template T - The type of the signal value\n * @param key - The localStorage key\n * @param initialValue - The initial value if not found in storage\n * @returns A Signal that syncs with localStorage (falls back to in-memory if unavailable)\n */\nexport const persistedSignal = <T>(key: string, initialValue: T): Signal<T> => {\n // Check if localStorage is available and accessible\n let hasLocalStorage = false;\n let storage: Storage | null = null;\n\n try {\n // In Safari private mode, accessing localStorage can throw SecurityError\n storage = globalThis.localStorage;\n if (storage) {\n // Test actual access to ensure it's not just present but usable\n // Use a randomized test key to avoid overwriting real user data\n const testKey = `__bquery_test_${Math.random().toString(36).slice(2, 9)}__`;\n const testValue = '__test__';\n try {\n storage.setItem(testKey, testValue);\n storage.getItem(testKey);\n hasLocalStorage = true;\n } finally {\n // Ensure we don't leave any test data behind\n try {\n storage.removeItem(testKey);\n } catch {\n // Ignore cleanup errors (e.g., storage becoming unavailable)\n }\n }\n }\n } catch {\n // localStorage unavailable or access denied (Safari private mode, sandboxed iframes, etc.)\n hasLocalStorage = false;\n }\n\n let stored: T = initialValue;\n\n if (hasLocalStorage && storage) {\n try {\n const raw = storage.getItem(key);\n if (raw !== null) {\n stored = JSON.parse(raw) as T;\n }\n } catch {\n // Use initial value on parse error or access denial\n }\n }\n\n const sig = signal(stored);\n\n // Only set up persistence effect if localStorage is available\n if (hasLocalStorage && storage) {\n effect(() => {\n try {\n storage!.setItem(key, JSON.stringify(sig.value));\n } catch {\n // Ignore storage errors (quota exceeded, sandboxed iframes, etc.)\n }\n });\n }\n\n return sig;\n};\n","/**\n * Read-only signal wrappers.\n */\n\nimport type { Signal } from './core';\n\n/**\n * A readonly wrapper around a signal that prevents writes.\n * Provides read-only access to a signal's value while maintaining reactivity.\n *\n * @template T - The type of the wrapped value\n */\nexport interface ReadonlySignal<T> {\n /** Gets the current value with dependency tracking. */\n readonly value: T;\n /** Gets the current value without dependency tracking. */\n peek(): T;\n}\n\n/**\n * Creates a read-only view of a signal.\n * Useful for exposing reactive state without allowing modifications.\n *\n * @template T - The type of the signal value\n * @param sig - The signal to wrap\n * @returns A readonly signal wrapper\n */\nexport const readonly = <T>(sig: Signal<T>): ReadonlySignal<T> => ({\n get value(): T {\n return sig.value;\n },\n peek(): T {\n return sig.peek();\n },\n});\n","/**\n * Value watching helpers.\n */\n\nimport type { Computed } from './computed';\nimport type { Signal } from './core';\nimport type { CleanupFn } from './internals';\n\nimport { effect } from './effect';\n\n/**\n * Options for the watch function.\n */\nexport interface WatchOptions<T> {\n /** If true, the callback is invoked immediately with the current value. */\n immediate?: boolean;\n /** Custom equality function. Defaults to Object.is. */\n equals?: (a: T, b: T | undefined) => boolean;\n}\n\n/**\n * Watches a signal or computed value and calls a callback with old and new values.\n * Unlike effect, watch provides access to the previous value.\n * The callback is only invoked when the value actually changes (compared via Object.is or custom equals).\n *\n * @template T - The type of the watched value\n * @param source - The signal or computed to watch\n * @param callback - Function called with (newValue, oldValue) on changes\n * @param options - Watch options\n * @returns A cleanup function to stop watching\n *\n * @example\n * ```ts\n * const count = signal(0);\n * watch(count, (newVal, oldVal) => {\n * console.log(`Changed from ${oldVal} to ${newVal}`);\n * });\n *\n * // With custom equality for objects\n * const user = signal({ id: 1, name: 'Alice' });\n * watch(user, (newVal, oldVal) => { ... }, {\n * equals: (a, b) => a?.id === b?.id\n * });\n * ```\n */\nexport const watch = <T>(\n source: Signal<T> | Computed<T>,\n callback: (newValue: T, oldValue: T | undefined) => void,\n options: WatchOptions<T> = {}\n): CleanupFn => {\n const { immediate = false, equals = Object.is } = options;\n let oldValue: T | undefined;\n let isFirst = true;\n\n return effect(() => {\n const newValue = source.value;\n\n if (isFirst) {\n isFirst = false;\n oldValue = newValue;\n if (immediate) {\n callback(newValue, undefined);\n }\n return;\n }\n\n // Only call callback if value actually changed\n if (!equals(newValue, oldValue)) {\n callback(newValue, oldValue);\n oldValue = newValue;\n }\n });\n};\n"],"names":["persistedSignal","key","initialValue","hasLocalStorage","storage","testKey","testValue","stored","raw","sig","signal","effect","readonly","watch","source","callback","options","immediate","equals","oldValue","isFirst","newValue"],"mappings":";;AAeO,MAAMA,IAAkB,CAAIC,GAAaC,MAA+B;AAE7E,MAAIC,IAAkB,IAClBC,IAA0B;AAE9B,MAAI;AAGF,QADAA,IAAU,WAAW,cACjBA,GAAS;AAGX,YAAMC,IAAU,iBAAiB,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,MACjEC,IAAY;AAClB,UAAI;AACF,QAAAF,EAAQ,QAAQC,GAASC,CAAS,GAClCF,EAAQ,QAAQC,CAAO,GACvBF,IAAkB;AAAA,MACpB,UAAA;AAEE,YAAI;AACF,UAAAC,EAAQ,WAAWC,CAAO;AAAA,QAC5B,QAAQ;AAAA,QAER;AAAA,MACF;AAAA,IACF;AAAA,EACF,QAAQ;AAEN,IAAAF,IAAkB;AAAA,EACpB;AAEA,MAAII,IAAYL;AAEhB,MAAIC,KAAmBC;AACrB,QAAI;AACF,YAAMI,IAAMJ,EAAQ,QAAQH,CAAG;AAC/B,MAAIO,MAAQ,SACVD,IAAS,KAAK,MAAMC,CAAG;AAAA,IAE3B,QAAQ;AAAA,IAER;AAGF,QAAMC,IAAMC,EAAOH,CAAM;AAGzB,SAAIJ,KAAmBC,KACrBO,EAAO,MAAM;AACX,QAAI;AACF,MAAAP,EAAS,QAAQH,GAAK,KAAK,UAAUQ,EAAI,KAAK,CAAC;AAAA,IACjD,QAAQ;AAAA,IAER;AAAA,EACF,CAAC,GAGIA;AACT,GC9CaG,IAAW,CAAIH,OAAuC;AAAA,EACjE,IAAI,QAAW;AACb,WAAOA,EAAI;AAAA,EACb;AAAA,EACA,OAAU;AACR,WAAOA,EAAI,KAAA;AAAA,EACb;AACF,ICWaI,IAAQ,CACnBC,GACAC,GACAC,IAA2B,CAAA,MACb;AACd,QAAM,EAAE,WAAAC,IAAY,IAAO,QAAAC,IAAS,OAAO,OAAOF;AAClD,MAAIG,GACAC,IAAU;AAEd,SAAOT,EAAO,MAAM;AAClB,UAAMU,IAAWP,EAAO;AAExB,QAAIM,GAAS;AACX,MAAAA,IAAU,IACVD,IAAWE,GACPJ,KACFF,EAASM,GAAU,MAAS;AAE9B;AAAA,IACF;AAGA,IAAKH,EAAOG,GAAUF,CAAQ,MAC5BJ,EAASM,GAAUF,CAAQ,GAC3BA,IAAWE;AAAA,EAEf,CAAC;AACH;"}
package/package.json CHANGED
@@ -1,132 +1,132 @@
1
- {
2
- "name": "@bquery/bquery",
3
- "version": "1.3.0",
4
- "description": "The jQuery for the Modern Web Platform - Zero build, TypeScript-first library with reactivity, components, and motion",
5
- "type": "module",
6
- "main": "./dist/full.umd.js",
7
- "module": "./dist/index.es.mjs",
8
- "types": "./dist/index.d.ts",
9
- "unpkg": "./dist/full.umd.js",
10
- "jsdelivr": "./dist/full.umd.js",
11
- "exports": {
12
- ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.es.mjs",
15
- "require": "./dist/full.umd.js"
16
- },
17
- "./full": {
18
- "types": "./dist/full.d.ts",
19
- "import": "./dist/full.es.mjs",
20
- "require": "./dist/full.umd.js"
21
- },
22
- "./core": {
23
- "import": "./dist/core.es.mjs",
24
- "types": "./dist/core/index.d.ts"
25
- },
26
- "./reactive": {
27
- "import": "./dist/reactive.es.mjs",
28
- "types": "./dist/reactive/index.d.ts"
29
- },
30
- "./component": {
31
- "import": "./dist/component.es.mjs",
32
- "types": "./dist/component/index.d.ts"
33
- },
34
- "./motion": {
35
- "import": "./dist/motion.es.mjs",
36
- "types": "./dist/motion/index.d.ts"
37
- },
38
- "./security": {
39
- "import": "./dist/security.es.mjs",
40
- "types": "./dist/security/index.d.ts"
41
- },
42
- "./platform": {
43
- "import": "./dist/platform.es.mjs",
44
- "types": "./dist/platform/index.d.ts"
45
- },
46
- "./router": {
47
- "import": "./dist/router.es.mjs",
48
- "types": "./dist/router/index.d.ts"
49
- },
50
- "./store": {
51
- "import": "./dist/store.es.mjs",
52
- "types": "./dist/store/index.d.ts"
53
- },
54
- "./view": {
55
- "import": "./dist/view.es.mjs",
56
- "types": "./dist/view/index.d.ts"
57
- }
58
- },
59
- "files": [
60
- "dist",
61
- "src",
62
- "README.md",
63
- "LICENSE.md"
64
- ],
65
- "sideEffects": false,
66
- "scripts": {
67
- "dev": "vitepress dev docs",
68
- "build:docs": "vitepress build docs",
69
- "preview": "vitepress preview docs",
70
- "playground": "vite dev playground",
71
- "build": "bun run build:lib && bun run build:umd && bun run build:types",
72
- "build:lib": "vite build",
73
- "build:umd": "vite build --config vite.umd.config.ts",
74
- "build:types": "tsc --emitDeclarationOnly --outDir dist",
75
- "test": "bun test",
76
- "test:watch": "bun test --watch",
77
- "lint": "eslint . --fix",
78
- "lint:types": "tsc --noEmit",
79
- "format": "prettier --write .",
80
- "format:check": "prettier --check .",
81
- "docs:api": "typedoc",
82
- "clean": "rimraf dist",
83
- "prepublishOnly": "bun run clean && bun run build && bun test"
84
- },
85
- "keywords": [
86
- "dom",
87
- "manipulation",
88
- "jquery",
89
- "modern",
90
- "typescript",
91
- "signals",
92
- "reactive",
93
- "components",
94
- "web-components",
95
- "animation",
96
- "motion",
97
- "zero-build",
98
- "cdn"
99
- ],
100
- "author": "Jonas Pfalzgraf <support@josunlp.de>",
101
- "license": "MIT",
102
- "repository": {
103
- "type": "git",
104
- "url": "https://github.com/bQuery/bQuery.git"
105
- },
106
- "homepage": "https://bQuery.flausch-code.de",
107
- "bugs": {
108
- "url": "https://github.com/bQuery/bQuery/issues"
109
- },
110
- "publishConfig": {
111
- "access": "public",
112
- "registry": "https://registry.npmjs.org/"
113
- },
114
- "engines": {
115
- "node": ">=18.0.0"
116
- },
117
- "devDependencies": {
118
- "@typescript-eslint/eslint-plugin": "^8.54.0",
119
- "@typescript-eslint/parser": "^8.54.0",
120
- "bun-types": "^1.3.8",
121
- "eslint": "^9.39.2",
122
- "eslint-config-prettier": "^10.1.8",
123
- "globals": "^17.2.0",
124
- "happy-dom": "^20.4.0",
125
- "prettier": "^3.8.1",
126
- "rimraf": "^6.1.2",
127
- "typedoc": "^0.28.16",
128
- "typescript": "^5.9.3",
129
- "vite": "^7.3.1",
130
- "vitepress": "^1.6.4"
131
- }
132
- }
1
+ {
2
+ "name": "@bquery/bquery",
3
+ "version": "1.4.0",
4
+ "description": "The jQuery for the Modern Web Platform - Zero build, TypeScript-first library with reactivity, components, and motion",
5
+ "type": "module",
6
+ "main": "./dist/full.umd.js",
7
+ "module": "./dist/index.es.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "unpkg": "./dist/full.umd.js",
10
+ "jsdelivr": "./dist/full.umd.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.es.mjs",
15
+ "require": "./dist/full.umd.js"
16
+ },
17
+ "./full": {
18
+ "types": "./dist/full.d.ts",
19
+ "import": "./dist/full.es.mjs",
20
+ "require": "./dist/full.umd.js"
21
+ },
22
+ "./core": {
23
+ "import": "./dist/core.es.mjs",
24
+ "types": "./dist/core/index.d.ts"
25
+ },
26
+ "./reactive": {
27
+ "import": "./dist/reactive.es.mjs",
28
+ "types": "./dist/reactive/index.d.ts"
29
+ },
30
+ "./component": {
31
+ "import": "./dist/component.es.mjs",
32
+ "types": "./dist/component/index.d.ts"
33
+ },
34
+ "./motion": {
35
+ "import": "./dist/motion.es.mjs",
36
+ "types": "./dist/motion/index.d.ts"
37
+ },
38
+ "./security": {
39
+ "import": "./dist/security.es.mjs",
40
+ "types": "./dist/security/index.d.ts"
41
+ },
42
+ "./platform": {
43
+ "import": "./dist/platform.es.mjs",
44
+ "types": "./dist/platform/index.d.ts"
45
+ },
46
+ "./router": {
47
+ "import": "./dist/router.es.mjs",
48
+ "types": "./dist/router/index.d.ts"
49
+ },
50
+ "./store": {
51
+ "import": "./dist/store.es.mjs",
52
+ "types": "./dist/store/index.d.ts"
53
+ },
54
+ "./view": {
55
+ "import": "./dist/view.es.mjs",
56
+ "types": "./dist/view/index.d.ts"
57
+ }
58
+ },
59
+ "files": [
60
+ "dist",
61
+ "src",
62
+ "README.md",
63
+ "LICENSE.md"
64
+ ],
65
+ "sideEffects": false,
66
+ "scripts": {
67
+ "dev": "vitepress dev docs",
68
+ "build:docs": "vitepress build docs",
69
+ "preview": "vitepress preview docs",
70
+ "playground": "vite dev playground",
71
+ "build": "bun run build:lib && bun run build:umd && bun run build:types",
72
+ "build:lib": "vite build",
73
+ "build:umd": "vite build --config vite.umd.config.ts",
74
+ "build:types": "tsc --emitDeclarationOnly --outDir dist",
75
+ "test": "bun test",
76
+ "test:watch": "bun test --watch",
77
+ "lint": "eslint . --fix",
78
+ "lint:types": "tsc --noEmit",
79
+ "format": "prettier --write .",
80
+ "format:check": "prettier --check .",
81
+ "docs:api": "typedoc",
82
+ "clean": "rimraf dist",
83
+ "prepublishOnly": "bun run clean && bun run build && bun test"
84
+ },
85
+ "keywords": [
86
+ "dom",
87
+ "manipulation",
88
+ "jquery",
89
+ "modern",
90
+ "typescript",
91
+ "signals",
92
+ "reactive",
93
+ "components",
94
+ "web-components",
95
+ "animation",
96
+ "motion",
97
+ "zero-build",
98
+ "cdn"
99
+ ],
100
+ "author": "Jonas Pfalzgraf <support@josunlp.de>",
101
+ "license": "MIT",
102
+ "repository": {
103
+ "type": "git",
104
+ "url": "https://github.com/bQuery/bQuery.git"
105
+ },
106
+ "homepage": "https://bQuery.flausch-code.de",
107
+ "bugs": {
108
+ "url": "https://github.com/bQuery/bQuery/issues"
109
+ },
110
+ "publishConfig": {
111
+ "access": "public",
112
+ "registry": "https://registry.npmjs.org/"
113
+ },
114
+ "engines": {
115
+ "node": ">=18.0.0"
116
+ },
117
+ "devDependencies": {
118
+ "@typescript-eslint/eslint-plugin": "^8.55.0",
119
+ "@typescript-eslint/parser": "^8.55.0",
120
+ "bun-types": "^1.3.9",
121
+ "eslint": "^9.39.2",
122
+ "eslint-config-prettier": "^10.1.8",
123
+ "globals": "^17.3.0",
124
+ "happy-dom": "^20.6.0",
125
+ "prettier": "^3.8.1",
126
+ "rimraf": "^6.1.2",
127
+ "typedoc": "^0.28.16",
128
+ "typescript": "^5.9.3",
129
+ "vite": "^7.3.1",
130
+ "vitepress": "^1.6.4"
131
+ }
132
+ }