flexium 0.16.13 → 0.16.14

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 (61) hide show
  1. package/dist/chunk-33M3W7D4.mjs +2 -0
  2. package/dist/{chunk-G6CRD7I5.mjs.map → chunk-33M3W7D4.mjs.map} +1 -1
  3. package/dist/{chunk-N5E4LKDY.js → chunk-47EPSC5Q.js} +2 -2
  4. package/dist/{chunk-N5E4LKDY.js.map → chunk-47EPSC5Q.js.map} +1 -1
  5. package/dist/{chunk-B645IQS6.js → chunk-4E3YIGJX.js} +2 -2
  6. package/dist/{chunk-B645IQS6.js.map → chunk-4E3YIGJX.js.map} +1 -1
  7. package/dist/{chunk-HUE2TOCR.js → chunk-A4VGFEMF.js} +2 -2
  8. package/dist/{chunk-HUE2TOCR.js.map → chunk-A4VGFEMF.js.map} +1 -1
  9. package/dist/chunk-AD2E2FQE.js +2 -0
  10. package/dist/{chunk-EROGYZGA.js.map → chunk-AD2E2FQE.js.map} +1 -1
  11. package/dist/{chunk-LOKMOGSA.js → chunk-BP5PDE6F.js} +2 -2
  12. package/dist/{chunk-LOKMOGSA.js.map → chunk-BP5PDE6F.js.map} +1 -1
  13. package/dist/{chunk-CB6CIG76.mjs → chunk-FJNIW7B2.mjs} +2 -2
  14. package/dist/{chunk-CB6CIG76.mjs.map → chunk-FJNIW7B2.mjs.map} +1 -1
  15. package/dist/{chunk-SB3OY2QH.mjs → chunk-OAATT6JA.mjs} +2 -2
  16. package/dist/{chunk-SB3OY2QH.mjs.map → chunk-OAATT6JA.mjs.map} +1 -1
  17. package/dist/chunk-OU6XJZ76.js +2 -0
  18. package/dist/chunk-OU6XJZ76.js.map +1 -0
  19. package/dist/chunk-P6NMD5QH.mjs +2 -0
  20. package/dist/{chunk-KDFYLOV7.mjs.map → chunk-P6NMD5QH.mjs.map} +1 -1
  21. package/dist/chunk-TIUNOZRI.mjs +2 -0
  22. package/dist/chunk-TIUNOZRI.mjs.map +1 -0
  23. package/dist/{chunk-S5DHAAMO.mjs → chunk-UQNPGF7C.mjs} +2 -2
  24. package/dist/{chunk-S5DHAAMO.mjs.map → chunk-UQNPGF7C.mjs.map} +1 -1
  25. package/dist/chunk-VB564E5E.mjs +2 -0
  26. package/dist/{chunk-PPPU2XSA.mjs.map → chunk-VB564E5E.mjs.map} +1 -1
  27. package/dist/{chunk-7LE75TKD.js → chunk-VZVYYGEF.js} +2 -2
  28. package/dist/{chunk-7LE75TKD.js.map → chunk-VZVYYGEF.js.map} +1 -1
  29. package/dist/core.d.cts +2 -1
  30. package/dist/core.d.ts +2 -1
  31. package/dist/core.js +1 -1
  32. package/dist/core.mjs +1 -1
  33. package/dist/dom.js +1 -1
  34. package/dist/dom.mjs +1 -1
  35. package/dist/index.d.cts +2 -2
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +1 -1
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/metafile-cjs.json +1 -1
  42. package/dist/metafile-esm.json +1 -1
  43. package/dist/render-FMQNBA7X.js +2 -0
  44. package/dist/{render-MOUO34XW.js.map → render-FMQNBA7X.js.map} +1 -1
  45. package/dist/render-HZQ6HEMS.mjs +2 -0
  46. package/dist/{render-SMFHDQGA.mjs.map → render-HZQ6HEMS.mjs.map} +1 -1
  47. package/dist/router.js +1 -1
  48. package/dist/router.mjs +1 -1
  49. package/dist/server.js +1 -1
  50. package/dist/server.mjs +1 -1
  51. package/package.json +2 -2
  52. package/dist/chunk-EROGYZGA.js +0 -2
  53. package/dist/chunk-G6CRD7I5.mjs +0 -2
  54. package/dist/chunk-KDFYLOV7.mjs +0 -2
  55. package/dist/chunk-PPPU2XSA.mjs +0 -2
  56. package/dist/chunk-VNYPOCV7.js +0 -2
  57. package/dist/chunk-VNYPOCV7.js.map +0 -1
  58. package/dist/chunk-WHRUAZR4.mjs +0 -2
  59. package/dist/chunk-WHRUAZR4.mjs.map +0 -1
  60. package/dist/render-MOUO34XW.js +0 -2
  61. package/dist/render-SMFHDQGA.mjs +0 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server/escape.ts","../src/server/serverState.ts","../src/server/renderToString.ts"],"names":["ESCAPE_MAP","ESCAPE_REGEX","escapeHtml","str","char","escapeAttribute","isServerRendering","serverStateCollector","hydrationIdCounter","getIsServer","enterServerRender","exitServerRender","states","generateHydrationId","VOID_ELEMENTS","BOOLEAN_ATTRS","ATTR_ALIASES","renderToString","app","options","hydrate","fnode","isFNode","html","renderNodeToString","state","error","renderToStaticMarkup","value","includeHydrationMarkers","child","renderComponentToString","renderElementToString","tag","attrs","renderAttributes","innerHTML","childrenHtml","props","parts","fid","key","attrName","styleStr","v","k","kebabCase","Component","contextId","isProvider","prevContextValue","pushContext","instance","result","runWithComponent","popContext"],"mappings":"iEAAA,IAAMA,EAAqC,CACzC,GAAA,CAAK,OAAA,CACL,GAAA,CAAK,OACL,GAAA,CAAK,MAAA,CACL,GAAA,CAAK,QAAA,CACL,IAAK,QACP,CAAA,CAEMC,CAAAA,CAAe,UAAA,CAEd,SAASC,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,OAAO,OAAOA,CAAG,CAAA,CAAE,OAAA,CAAQF,CAAAA,CAAcG,GAAQJ,CAAAA,CAAWI,CAAI,CAAC,CACnE,CAEO,SAASC,CAAAA,CAAgBF,EAAqB,CACnD,OAAOD,EAAWC,CAAG,CACvB,CCdA,IAAIG,EAAoB,KAAA,CACpBC,CAAAA,CAAoD,IAAA,CACpDC,CAAAA,CAAqB,EAElB,SAASC,CAAAA,EAAuB,CACrC,OAAOH,CACT,CAEO,SAASI,CAAAA,EAA0B,CACxCJ,EAAoB,IAAA,CACpBC,CAAAA,CAAuB,IAAI,GAAA,CAC3BC,EAAqB,EACvB,CAEO,SAASG,CAAAA,EAAoC,CAClDL,CAAAA,CAAoB,KAAA,CACpB,IAAMM,CAAAA,CAAS,OAAO,WAAA,CAAYL,CAAAA,EAA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AA,CAAS,OAAS,CAAA,GAC5CiB,CAAAA,CAAM,QAAA,CAAWjB,CAAAA,CAAM,SAAS,MAAA,GAAW,CAAA,CACvCA,CAAAA,CAAM,QAAA,CAAS,CAAC,CAAA,CAChBA,CAAAA,CAAM,QAAA,CAAA,CAIZ,IAAM2B,EAAaD,CAAAA,CAAkB,UAAA,CAC/BE,CAAAA,CAAaD,CAAAA,GAAc,OAC7BE,CAAAA,CAEAD,CAAAA,GACFC,CAAAA,CAAmBC,kBAAAA,CAAYH,EAAWV,CAAAA,CAAM,KAAK,GAIvD,IAAMc,CAAAA,CAA8B,CAClC,KAAA,CAAO,EAAC,CACR,SAAA,CAAW,CACb,CAAA,CAEA,GAAI,CAEF,IAAMC,EAASC,kBAAAA,CAAiBF,CAAAA,CAAU,IAAML,CAAAA,CAAUT,CAAK,CAAC,CAAA,CAGhE,OAAOd,CAAAA,CAAmB6B,CAAAA,CAAQxB,CAAuB,CAC3D,CAAA,OAAE,CAEIoB,CAAAA,EACFM,mBAAWP,CAAAA,CAAWE,CAAgB,EAE1C,CACF,CAEA,SAASJ,CAAAA,CAAU3C,CAAAA,CAAqB,CACtC,OAAOA,CAAAA,CAAI,OAAA,CAAQ,WAAY,KAAK,CAAA,CAAE,aACxC","file":"chunk-HUE2TOCR.js","sourcesContent":["const ESCAPE_MAP: Record<string, string> = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n \"'\": '&#x27;'\n}\n\nconst ESCAPE_REGEX = /[&<>\"']/g\n\nexport function escapeHtml(str: string): string {\n return String(str).replace(ESCAPE_REGEX, char => ESCAPE_MAP[char])\n}\n\nexport function escapeAttribute(str: string): string {\n return escapeHtml(str)\n}\n","import type { SerializedState } from './types'\n\nlet isServerRendering = false\nlet serverStateCollector: Map<string, unknown> | null = null\nlet hydrationIdCounter = 0\n\nexport function getIsServer(): boolean {\n return isServerRendering\n}\n\nexport function enterServerRender(): void {\n isServerRendering = true\n serverStateCollector = new Map()\n hydrationIdCounter = 0\n}\n\nexport function exitServerRender(): SerializedState {\n isServerRendering = false\n const states = Object.fromEntries(serverStateCollector || new Map())\n serverStateCollector = null\n\n return { states }\n}\n\nexport function collectServerState(key: string, value: unknown): void {\n if (serverStateCollector) {\n serverStateCollector.set(key, value)\n }\n}\n\nexport function generateHydrationId(): string {\n return `fid-${hydrationIdCounter++}`\n}\n\nexport function resetHydrationIdCounter(): void {\n hydrationIdCounter = 0\n}\n","import type { FNode, FNodeChild } from '../dom/types'\nimport type { SSROptions, SSRResult } from './types'\nimport { escapeHtml, escapeAttribute } from './escape'\nimport {\n enterServerRender,\n exitServerRender,\n generateHydrationId\n} from './serverState'\nimport { runWithComponent, ComponentInstance } from '../core/hook'\nimport { pushContext, popContext } from '../core/context'\n\n// Self-closing HTML tags\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\n])\n\n// Attributes that should be rendered as boolean\nconst BOOLEAN_ATTRS = new Set([\n 'disabled', 'checked', 'readonly', 'required', 'hidden',\n 'selected', 'autofocus', 'autoplay', 'controls', 'loop', 'muted',\n 'multiple', 'open', 'defer', 'async', 'novalidate'\n])\n\n// Attributes that need special handling\nconst ATTR_ALIASES: Record<string, string> = {\n className: 'class',\n htmlFor: 'for'\n}\n\n/**\n * Render component tree to HTML string with hydration markers\n */\nexport function renderToString(\n app: FNodeChild | (() => FNodeChild),\n options: SSROptions = {}\n): SSRResult {\n const { hydrate = true } = options\n\n enterServerRender()\n\n try {\n // Normalize input - wrap function in FNode if needed\n let fnode: FNodeChild\n if (typeof app === 'function' && !isFNode(app)) {\n fnode = { type: app, props: {}, children: [], key: undefined }\n } else {\n fnode = app\n }\n\n const html = renderNodeToString(fnode, hydrate)\n const state = exitServerRender()\n\n return { html, state }\n } catch (error) {\n exitServerRender()\n throw error\n }\n}\n\n/**\n * Render component tree to static HTML (no hydration markers)\n * Use for email templates, static pages, etc.\n */\nexport function renderToStaticMarkup(app: FNodeChild | (() => FNodeChild)): string {\n const { html } = renderToString(app, { hydrate: false })\n return html\n}\n\nfunction isFNode(value: any): value is FNode {\n return value && typeof value === 'object' && 'type' in value && 'props' in value\n}\n\nfunction renderNodeToString(fnode: FNodeChild, includeHydrationMarkers: boolean): string {\n // Null/undefined/boolean -> empty string\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n return ''\n }\n\n // String/number -> escaped text\n if (typeof fnode === 'string' || typeof fnode === 'number') {\n return escapeHtml(String(fnode))\n }\n\n // Array -> concatenate children\n if (Array.isArray(fnode)) {\n return fnode.map(child => renderNodeToString(child, includeHydrationMarkers)).join('')\n }\n\n // Function (standalone) -> wrap in FNode and render\n if (typeof fnode === 'function') {\n const wrappedFnode: FNode = { type: fnode, props: {}, children: [], key: undefined }\n return renderComponentToString(wrappedFnode, includeHydrationMarkers)\n }\n\n // Object (FNode)\n if (typeof fnode === 'object' && isFNode(fnode)) {\n // HTML element\n if (typeof fnode.type === 'string') {\n return renderElementToString(fnode, includeHydrationMarkers)\n }\n\n // Function component\n if (typeof fnode.type === 'function') {\n return renderComponentToString(fnode, includeHydrationMarkers)\n }\n }\n\n return ''\n}\n\nfunction renderElementToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const tag = fnode.type as string\n const attrs = renderAttributes(fnode.props, includeHydrationMarkers)\n\n // Handle dangerouslySetInnerHTML\n if (fnode.props?.dangerouslySetInnerHTML) {\n const innerHTML = fnode.props.dangerouslySetInnerHTML.__html || ''\n return `<${tag}${attrs}>${innerHTML}</${tag}>`\n }\n\n // Void elements (self-closing)\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`\n }\n\n // Render children\n const childrenHtml = (fnode.children || [])\n .map(child => renderNodeToString(child, includeHydrationMarkers))\n .join('')\n\n return `<${tag}${attrs}>${childrenHtml}</${tag}>`\n}\n\nfunction renderAttributes(props: Record<string, any>, includeHydrationMarkers: boolean): string {\n if (!props) return ''\n\n const parts: string[] = []\n\n // Add hydration ID if needed\n if (includeHydrationMarkers) {\n const fid = generateHydrationId()\n parts.push(`data-fid=\"${fid}\"`)\n }\n\n for (const [key, value] of Object.entries(props)) {\n // Skip event handlers, refs, and internal props\n if (key.startsWith('on') || key === 'ref' || key === 'key' || key === 'children') continue\n if (key === 'dangerouslySetInnerHTML') continue\n\n // Skip undefined/null values\n if (value === undefined || value === null) continue\n\n // Handle aliased attributes\n const attrName = ATTR_ALIASES[key] || key\n\n // Handle style object\n if (key === 'style' && typeof value === 'object') {\n const styleStr = Object.entries(value)\n .filter(([, v]) => v !== null && v !== undefined)\n .map(([k, v]) => `${kebabCase(k)}:${v}`)\n .join(';')\n if (styleStr) {\n parts.push(`style=\"${escapeAttribute(styleStr)}\"`)\n }\n continue\n }\n\n // Handle boolean attributes\n if (BOOLEAN_ATTRS.has(attrName)) {\n if (value) parts.push(attrName)\n continue\n }\n\n // Handle false boolean values - skip entirely\n if (value === false) continue\n\n // Regular attribute\n parts.push(`${attrName}=\"${escapeAttribute(String(value))}\"`)\n }\n\n return parts.length ? ' ' + parts.join(' ') : ''\n}\n\nfunction renderComponentToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const Component = fnode.type as Function\n\n // Merge props with children\n const props = { ...fnode.props }\n if (fnode.children && fnode.children.length > 0) {\n props.children = fnode.children.length === 1\n ? fnode.children[0]\n : fnode.children\n }\n\n // Check if this is a Context Provider\n const contextId = (Component as any)._contextId\n const isProvider = contextId !== undefined\n let prevContextValue: any\n\n if (isProvider) {\n prevContextValue = pushContext(contextId, props.value)\n }\n\n // Create minimal component instance for server (hooks support)\n const instance: ComponentInstance = {\n hooks: [],\n hookIndex: 0\n }\n\n try {\n // Run component with hook context\n const result = runWithComponent(instance, () => Component(props))\n\n // Render result\n return renderNodeToString(result, includeHydrationMarkers)\n } finally {\n // Restore context if it was a provider\n if (isProvider) {\n popContext(contextId, prevContextValue)\n }\n }\n}\n\nfunction kebabCase(str: string): string {\n return str.replace(/([A-Z])/g, '-$1').toLowerCase()\n}\n"]}
1
+ {"version":3,"sources":["../src/server/escape.ts","../src/server/serverState.ts","../src/server/renderToString.ts"],"names":["ESCAPE_MAP","ESCAPE_REGEX","escapeHtml","str","char","escapeAttribute","isServerRendering","serverStateCollector","hydrationIdCounter","getIsServer","enterServerRender","exitServerRender","states","generateHydrationId","VOID_ELEMENTS","BOOLEAN_ATTRS","ATTR_ALIASES","renderToString","app","options","hydrate","fnode","isFNode","html","renderNodeToString","state","error","renderToStaticMarkup","value","includeHydrationMarkers","child","renderComponentToString","renderElementToString","tag","attrs","renderAttributes","innerHTML","childrenHtml","props","parts","fid","key","attrName","styleStr","v","k","kebabCase","Component","contextId","isProvider","prevContextValue","pushContext","instance","result","runWithComponent","popContext"],"mappings":"iEAAA,IAAMA,EAAqC,CACzC,GAAA,CAAK,OAAA,CACL,GAAA,CAAK,OACL,GAAA,CAAK,MAAA,CACL,GAAA,CAAK,QAAA,CACL,IAAK,QACP,CAAA,CAEMC,CAAAA,CAAe,UAAA,CAEd,SAASC,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,OAAO,OAAOA,CAAG,CAAA,CAAE,OAAA,CAAQF,CAAAA,CAAcG,GAAQJ,CAAAA,CAAWI,CAAI,CAAC,CACnE,CAEO,SAASC,CAAAA,CAAgBF,EAAqB,CACnD,OAAOD,EAAWC,CAAG,CACvB,CCdA,IAAIG,EAAoB,KAAA,CACpBC,CAAAA,CAAoD,IAAA,CACpDC,CAAAA,CAAqB,EAElB,SAASC,CAAAA,EAAuB,CACrC,OAAOH,CACT,CAEO,SAASI,CAAAA,EAA0B,CACxCJ,EAAoB,IAAA,CACpBC,CAAAA,CAAuB,IAAI,GAAA,CAC3BC,EAAqB,EACvB,CAEO,SAASG,CAAAA,EAAoC,CAClDL,CAAAA,CAAoB,KAAA,CACpB,IAAMM,CAAAA,CAAS,OAAO,WAAA,CAAYL,CAAAA,EAAwB,IAAI,GAAK,CAAA,CACnE,OAAAA,CAAAA,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M,QAAA,CAAWjB,CAAAA,CAAM,SAAS,MAAA,GAAW,CAAA,CACvCA,CAAAA,CAAM,QAAA,CAAS,CAAC,CAAA,CAChBA,CAAAA,CAAM,QAAA,CAAA,CAIZ,IAAM2B,EAAaD,CAAAA,CAAkB,UAAA,CAC/BE,CAAAA,CAAaD,CAAAA,GAAc,OAC7BE,CAAAA,CAEAD,CAAAA,GACFC,CAAAA,CAAmBC,kBAAAA,CAAYH,EAAWV,CAAAA,CAAM,KAAK,GAIvD,IAAMc,CAAAA,CAA8B,CAClC,KAAA,CAAO,EAAC,CACR,SAAA,CAAW,CACb,CAAA,CAEA,GAAI,CAEF,IAAMC,EAASC,kBAAAA,CAAiBF,CAAAA,CAAU,IAAML,CAAAA,CAAUT,CAAK,CAAC,CAAA,CAGhE,OAAOd,CAAAA,CAAmB6B,CAAAA,CAAQxB,CAAuB,CAC3D,CAAA,OAAE,CAEIoB,CAAAA,EACFM,mBAAWP,CAAAA,CAAWE,CAAgB,EAE1C,CACF,CAEA,SAASJ,CAAAA,CAAU3C,CAAAA,CAAqB,CACtC,OAAOA,CAAAA,CAAI,OAAA,CAAQ,WAAY,KAAK,CAAA,CAAE,aACxC","file":"chunk-A4VGFEMF.js","sourcesContent":["const ESCAPE_MAP: Record<string, string> = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n \"'\": '&#x27;'\n}\n\nconst ESCAPE_REGEX = /[&<>\"']/g\n\nexport function escapeHtml(str: string): string {\n return String(str).replace(ESCAPE_REGEX, char => ESCAPE_MAP[char])\n}\n\nexport function escapeAttribute(str: string): string {\n return escapeHtml(str)\n}\n","import type { SerializedState } from './types'\n\nlet isServerRendering = false\nlet serverStateCollector: Map<string, unknown> | null = null\nlet hydrationIdCounter = 0\n\nexport function getIsServer(): boolean {\n return isServerRendering\n}\n\nexport function enterServerRender(): void {\n isServerRendering = true\n serverStateCollector = new Map()\n hydrationIdCounter = 0\n}\n\nexport function exitServerRender(): SerializedState {\n isServerRendering = false\n const states = Object.fromEntries(serverStateCollector || new Map())\n serverStateCollector = null\n\n return { states }\n}\n\nexport function collectServerState(key: string, value: unknown): void {\n if (serverStateCollector) {\n serverStateCollector.set(key, value)\n }\n}\n\nexport function generateHydrationId(): string {\n return `fid-${hydrationIdCounter++}`\n}\n\nexport function resetHydrationIdCounter(): void {\n hydrationIdCounter = 0\n}\n","import type { FNode, FNodeChild } from '../dom/types'\nimport type { SSROptions, SSRResult } from './types'\nimport { escapeHtml, escapeAttribute } from './escape'\nimport {\n enterServerRender,\n exitServerRender,\n generateHydrationId\n} from './serverState'\nimport { runWithComponent, ComponentInstance } from '../core/hook'\nimport { pushContext, popContext } from '../core/context'\n\n// Self-closing HTML tags\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\n])\n\n// Attributes that should be rendered as boolean\nconst BOOLEAN_ATTRS = new Set([\n 'disabled', 'checked', 'readonly', 'required', 'hidden',\n 'selected', 'autofocus', 'autoplay', 'controls', 'loop', 'muted',\n 'multiple', 'open', 'defer', 'async', 'novalidate'\n])\n\n// Attributes that need special handling\nconst ATTR_ALIASES: Record<string, string> = {\n className: 'class',\n htmlFor: 'for'\n}\n\n/**\n * Render component tree to HTML string with hydration markers\n */\nexport function renderToString(\n app: FNodeChild | (() => FNodeChild),\n options: SSROptions = {}\n): SSRResult {\n const { hydrate = true } = options\n\n enterServerRender()\n\n try {\n // Normalize input - wrap function in FNode if needed\n let fnode: FNodeChild\n if (typeof app === 'function' && !isFNode(app)) {\n fnode = { type: app, props: {}, children: [], key: undefined }\n } else {\n fnode = app\n }\n\n const html = renderNodeToString(fnode, hydrate)\n const state = exitServerRender()\n\n return { html, state }\n } catch (error) {\n exitServerRender()\n throw error\n }\n}\n\n/**\n * Render component tree to static HTML (no hydration markers)\n * Use for email templates, static pages, etc.\n */\nexport function renderToStaticMarkup(app: FNodeChild | (() => FNodeChild)): string {\n const { html } = renderToString(app, { hydrate: false })\n return html\n}\n\nfunction isFNode(value: any): value is FNode {\n return value && typeof value === 'object' && 'type' in value && 'props' in value\n}\n\nfunction renderNodeToString(fnode: FNodeChild, includeHydrationMarkers: boolean): string {\n // Null/undefined/boolean -> empty string\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n return ''\n }\n\n // String/number -> escaped text\n if (typeof fnode === 'string' || typeof fnode === 'number') {\n return escapeHtml(String(fnode))\n }\n\n // Array -> concatenate children\n if (Array.isArray(fnode)) {\n return fnode.map(child => renderNodeToString(child, includeHydrationMarkers)).join('')\n }\n\n // Function (standalone) -> wrap in FNode and render\n if (typeof fnode === 'function') {\n const wrappedFnode: FNode = { type: fnode, props: {}, children: [], key: undefined }\n return renderComponentToString(wrappedFnode, includeHydrationMarkers)\n }\n\n // Object (FNode)\n if (typeof fnode === 'object' && isFNode(fnode)) {\n // HTML element\n if (typeof fnode.type === 'string') {\n return renderElementToString(fnode, includeHydrationMarkers)\n }\n\n // Function component\n if (typeof fnode.type === 'function') {\n return renderComponentToString(fnode, includeHydrationMarkers)\n }\n }\n\n return ''\n}\n\nfunction renderElementToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const tag = fnode.type as string\n const attrs = renderAttributes(fnode.props, includeHydrationMarkers)\n\n // Handle dangerouslySetInnerHTML\n if (fnode.props?.dangerouslySetInnerHTML) {\n const innerHTML = fnode.props.dangerouslySetInnerHTML.__html || ''\n return `<${tag}${attrs}>${innerHTML}</${tag}>`\n }\n\n // Void elements (self-closing)\n if (VOID_ELEMENTS.has(tag)) {\n return `<${tag}${attrs}>`\n }\n\n // Render children\n const childrenHtml = (fnode.children || [])\n .map(child => renderNodeToString(child, includeHydrationMarkers))\n .join('')\n\n return `<${tag}${attrs}>${childrenHtml}</${tag}>`\n}\n\nfunction renderAttributes(props: Record<string, any>, includeHydrationMarkers: boolean): string {\n if (!props) return ''\n\n const parts: string[] = []\n\n // Add hydration ID if needed\n if (includeHydrationMarkers) {\n const fid = generateHydrationId()\n parts.push(`data-fid=\"${fid}\"`)\n }\n\n for (const [key, value] of Object.entries(props)) {\n // Skip event handlers, refs, and internal props\n if (key.startsWith('on') || key === 'ref' || key === 'key' || key === 'children') continue\n if (key === 'dangerouslySetInnerHTML') continue\n\n // Skip undefined/null values\n if (value === undefined || value === null) continue\n\n // Handle aliased attributes\n const attrName = ATTR_ALIASES[key] || key\n\n // Handle style object\n if (key === 'style' && typeof value === 'object') {\n const styleStr = Object.entries(value)\n .filter(([, v]) => v !== null && v !== undefined)\n .map(([k, v]) => `${kebabCase(k)}:${v}`)\n .join(';')\n if (styleStr) {\n parts.push(`style=\"${escapeAttribute(styleStr)}\"`)\n }\n continue\n }\n\n // Handle boolean attributes\n if (BOOLEAN_ATTRS.has(attrName)) {\n if (value) parts.push(attrName)\n continue\n }\n\n // Handle false boolean values - skip entirely\n if (value === false) continue\n\n // Regular attribute\n parts.push(`${attrName}=\"${escapeAttribute(String(value))}\"`)\n }\n\n return parts.length ? ' ' + parts.join(' ') : ''\n}\n\nfunction renderComponentToString(fnode: FNode, includeHydrationMarkers: boolean): string {\n const Component = fnode.type as Function\n\n // Merge props with children\n const props = { ...fnode.props }\n if (fnode.children && fnode.children.length > 0) {\n props.children = fnode.children.length === 1\n ? fnode.children[0]\n : fnode.children\n }\n\n // Check if this is a Context Provider\n const contextId = (Component as any)._contextId\n const isProvider = contextId !== undefined\n let prevContextValue: any\n\n if (isProvider) {\n prevContextValue = pushContext(contextId, props.value)\n }\n\n // Create minimal component instance for server (hooks support)\n const instance: ComponentInstance = {\n hooks: [],\n hookIndex: 0\n }\n\n try {\n // Run component with hook context\n const result = runWithComponent(instance, () => Component(props))\n\n // Render result\n return renderNodeToString(result, includeHydrationMarkers)\n } finally {\n // Restore context if it was a provider\n if (isProvider) {\n popContext(contextId, prevContextValue)\n }\n }\n}\n\nfunction kebabCase(str: string): string {\n return str.replace(/([A-Z])/g, '-$1').toLowerCase()\n}\n"]}
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkOU6XJZ76_js=require('./chunk-OU6XJZ76.js');function o(t){return chunkOU6XJZ76_js.b(()=>({current:t}))}exports.a=o;//# sourceMappingURL=chunk-AD2E2FQE.js.map
2
+ //# sourceMappingURL=chunk-AD2E2FQE.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/ref.ts"],"names":["useRef","initialValue","hook"],"mappings":"iEA2BO,SAASA,CAAAA,CAAUC,CAAAA,CAA4C,CACpE,OAAOC,kBAAAA,CAAK,KAAO,CACjB,OAAA,CAASD,CACX,CAAA,CAAE,CACJ","file":"chunk-EROGYZGA.js","sourcesContent":["import { hook } from './hook'\nimport type { RefObject } from './types'\n\n/**\n * Creates a mutable ref object that persists across renders\n *\n * @example\n * ```tsx\n * function InputWithFocus() {\n * const inputRef = useRef<HTMLInputElement>()\n *\n * const focusInput = () => {\n * inputRef.current?.focus()\n * }\n *\n * return (\n * <div>\n * <input ref={inputRef} type=\"text\" />\n * <button onClick={focusInput}>Focus Input</button>\n * </div>\n * )\n * }\n * ```\n */\nexport function useRef<T>(initialValue: T): RefObject<T>\nexport function useRef<T>(initialValue: T | null): RefObject<T | null>\nexport function useRef<T = undefined>(): RefObject<T | undefined>\nexport function useRef<T>(initialValue?: T): RefObject<T | undefined> {\n return hook(() => ({\n current: initialValue\n }))\n}\n"]}
1
+ {"version":3,"sources":["../src/core/ref.ts"],"names":["useRef","initialValue","hook"],"mappings":"iEA2BO,SAASA,CAAAA,CAAUC,CAAAA,CAA4C,CACpE,OAAOC,kBAAAA,CAAK,KAAO,CACjB,OAAA,CAASD,CACX,CAAA,CAAE,CACJ","file":"chunk-AD2E2FQE.js","sourcesContent":["import { hook } from './hook'\nimport type { RefObject } from './types'\n\n/**\n * Creates a mutable ref object that persists across renders\n *\n * @example\n * ```tsx\n * function InputWithFocus() {\n * const inputRef = useRef<HTMLInputElement>()\n *\n * const focusInput = () => {\n * inputRef.current?.focus()\n * }\n *\n * return (\n * <div>\n * <input ref={inputRef} type=\"text\" />\n * <button onClick={focusInput}>Focus Input</button>\n * </div>\n * )\n * }\n * ```\n */\nexport function useRef<T>(initialValue: T): RefObject<T>\nexport function useRef<T>(initialValue: T | null): RefObject<T | null>\nexport function useRef<T = undefined>(): RefObject<T | undefined>\nexport function useRef<T>(initialValue?: T): RefObject<T | undefined> {\n return hook(() => ({\n current: initialValue\n }))\n}\n"]}
@@ -1,2 +1,2 @@
1
- 'use strict';var chunk3CKIHQIE_js=require('./chunk-3CKIHQIE.js'),chunkVNYPOCV7_js=require('./chunk-VNYPOCV7.js');var b=Symbol("flexium.reactive"),P=new WeakMap,R=new WeakMap;function m(e){if(e&&e[b])return e;let r=R.get(e);if(r)return r;let s=new Proxy(e,{get(t,a,c){if(a===b)return true;let f=Reflect.get(t,a,c);return j(t,a),f!==null&&typeof f=="object"?m(f):f},set(t,a,c,f){let d=t[a],x=Reflect.set(t,a,c,f);return x&&O(c,d)&&I(t,a),x}});return R.set(e,s),s}function j(e,r){if(!chunk3CKIHQIE_js.a)return;let s=P.get(e);s||P.set(e,s=new Map);let t=s.get(r);t||s.set(r,t=new Set),chunk3CKIHQIE_js.c(t);}function I(e,r){let s=P.get(e);if(!s)return;let t=s.get(r);t&&chunk3CKIHQIE_js.d(t);}function O(e,r){return !Object.is(e,r)}function F(e){return !!(e&&e[b])}var K=0,M=new Map;function E(){if(typeof window<"u")return window.__FLEXIUM_DEVTOOLS__}function A(e,r){let s=E();if(!s)return -1;let t=++K;M.set(e,t);let a={id:t,name:r||`signal_${t}`,value:e.value,type:e.type||"signal",subscribers:0,createdAt:Date.now()};return s.onSignalCreate(a),t}function _(e,r){let s=E();if(!s)return;let t=M.get(e);t!==void 0&&s.onSignalUpdate(t,r);}var U=new Map;function V(e){return JSON.stringify(e)}function q(e,r,s){if(chunkVNYPOCV7_js.d(e)){let i=e,o=r,g=chunkVNYPOCV7_js.b(()=>{let u=m({value:i.getInitial(o),cleanup:void 0});return u.cleanup=i.subscribe(o,y=>{u.value=y;}),u}).value,p=i.getActions();return p&&p.length>0?[g,...p]:[g,void 0]}let t,a;if(Array.isArray(r)?(t=r,a=s):r&&typeof r=="object"&&(a=r),a?.key&&!Array.isArray(a.key))throw new Error("State key must be an array");let c=chunkVNYPOCV7_js.b(()=>m({container:void 0,serializedKey:void 0})),f=a?.key,d=f?V(f):void 0,x=d!==c.serializedKey;if(typeof e=="function"&&t!==void 0){let i=e,o=chunkVNYPOCV7_js.b(()=>({value:void 0,prevDeps:void 0,cleanup:void 0,hasRun:false,params:void 0})),n=true;if(o.hasRun&&o.prevDeps&&(n=t.length!==o.prevDeps.length||t.some((p,u)=>p!==o.prevDeps[u])),n){o.cleanup&&(o.cleanup(),o.cleanup=void 0);let p={onCleanup:y=>{o.cleanup=y;},params:o.params},u=i(p);if(u instanceof Promise)throw new Error("deps with async functions is not supported. Use use(asyncFn) without deps for async resources.");o.value=u,o.prevDeps=[...t],o.hasRun=true;}let g={refetch:async()=>{},get loading(){return false},get error(){return null},get status(){return "success"}};return [o.value,g]}if(!c.container||x)if(c.serializedKey=d,d&&U.has(d))c.container=U.get(d);else {let i;if(typeof e=="function"){let o=e,n=m({type:"resource",value:void 0,loading:true,error:null,status:"idle",cleanup:void 0,params:void 0,run:()=>{}}),g=p=>{n.cleanup&&(n.cleanup(),n.cleanup=void 0),n.params=p;try{let u={onCleanup:v=>{n.cleanup=v;},params:n.params},y=o(u);y instanceof Promise?(n.loading=!0,n.status="loading",n.error=null,y.then(v=>{n.value=v,n.status="success",n.loading=!1;}).catch(v=>{n.error=v,n.status="error",n.loading=!1;})):(n.value=y,n.status="success",n.loading=!1,n.error=null);}catch(u){n.error=u,n.status="error",n.loading=false;}};n.run=g,chunk3CKIHQIE_js.b(()=>g()),i=n;}else i=m({type:"signal",value:e}),A(i,a?.name);d&&U.set(d,i),c.container=i;}let l=c.container,w=l.value;return l.type==="signal"?[w,o=>{typeof o=="function"?l.value=o(l.value):l.value=o,_(l,l.value);}]:[w,{refetch:async o=>{l.run(o);},get loading(){return l.loading},get error(){return l.error},get status(){return l.status}}]}exports.a=m;exports.b=F;exports.c=q;//# sourceMappingURL=chunk-LOKMOGSA.js.map
2
- //# sourceMappingURL=chunk-LOKMOGSA.js.map
1
+ 'use strict';var chunk3CKIHQIE_js=require('./chunk-3CKIHQIE.js'),chunkOU6XJZ76_js=require('./chunk-OU6XJZ76.js');var b=Symbol("flexium.reactive"),P=new WeakMap,R=new WeakMap;function m(e){if(e&&e[b])return e;let r=R.get(e);if(r)return r;let s=new Proxy(e,{get(t,a,c){if(a===b)return true;let f=Reflect.get(t,a,c);return j(t,a),f!==null&&typeof f=="object"?m(f):f},set(t,a,c,f){let d=t[a],x=Reflect.set(t,a,c,f);return x&&O(c,d)&&I(t,a),x}});return R.set(e,s),s}function j(e,r){if(!chunk3CKIHQIE_js.a)return;let s=P.get(e);s||P.set(e,s=new Map);let t=s.get(r);t||s.set(r,t=new Set),chunk3CKIHQIE_js.c(t);}function I(e,r){let s=P.get(e);if(!s)return;let t=s.get(r);t&&chunk3CKIHQIE_js.d(t);}function O(e,r){return !Object.is(e,r)}function F(e){return !!(e&&e[b])}var K=0,M=new Map;function E(){if(typeof window<"u")return window.__FLEXIUM_DEVTOOLS__}function A(e,r){let s=E();if(!s)return -1;let t=++K;M.set(e,t);let a={id:t,name:r||`signal_${t}`,value:e.value,type:e.type||"signal",subscribers:0,createdAt:Date.now()};return s.onSignalCreate(a),t}function _(e,r){let s=E();if(!s)return;let t=M.get(e);t!==void 0&&s.onSignalUpdate(t,r);}var U=new Map;function V(e){return JSON.stringify(e)}function q(e,r,s){if(chunkOU6XJZ76_js.d(e)){let i=e,o=r,g=chunkOU6XJZ76_js.b(()=>{let u=m({value:i.getInitial(o),cleanup:void 0});return u.cleanup=i.subscribe(o,y=>{u.value=y;}),u}).value,p=i.getActions();return p&&p.length>0?[g,...p]:[g,void 0]}let t,a;if(Array.isArray(r)?(t=r,a=s):r&&typeof r=="object"&&(a=r),a?.key&&!Array.isArray(a.key))throw new Error("State key must be an array");let c=chunkOU6XJZ76_js.b(()=>m({container:void 0,serializedKey:void 0})),f=a?.key,d=f?V(f):void 0,x=d!==c.serializedKey;if(typeof e=="function"&&t!==void 0){let i=e,o=chunkOU6XJZ76_js.b(()=>({value:void 0,prevDeps:void 0,cleanup:void 0,hasRun:false,params:void 0})),n=true;if(o.hasRun&&o.prevDeps&&(n=t.length!==o.prevDeps.length||t.some((p,u)=>p!==o.prevDeps[u])),n){o.cleanup&&(o.cleanup(),o.cleanup=void 0);let p={onCleanup:y=>{o.cleanup=y;},params:o.params},u=i(p);if(u instanceof Promise)throw new Error("deps with async functions is not supported. Use use(asyncFn) without deps for async resources.");o.value=u,o.prevDeps=[...t],o.hasRun=true;}let g={refetch:async()=>{},get loading(){return false},get error(){return null},get status(){return "success"}};return [o.value,g]}if(!c.container||x)if(c.serializedKey=d,d&&U.has(d))c.container=U.get(d);else {let i;if(typeof e=="function"){let o=e,n=m({type:"resource",value:void 0,loading:true,error:null,status:"idle",cleanup:void 0,params:void 0,run:()=>{}}),g=p=>{n.cleanup&&(n.cleanup(),n.cleanup=void 0),n.params=p;try{let u={onCleanup:v=>{n.cleanup=v;},params:n.params},y=o(u);y instanceof Promise?(n.loading=!0,n.status="loading",n.error=null,y.then(v=>{n.value=v,n.status="success",n.loading=!1;}).catch(v=>{n.error=v,n.status="error",n.loading=!1;})):(n.value=y,n.status="success",n.loading=!1,n.error=null);}catch(u){n.error=u,n.status="error",n.loading=false;}};n.run=g,chunk3CKIHQIE_js.b(()=>g()),i=n;}else i=m({type:"signal",value:e}),A(i,a?.name);d&&U.set(d,i),c.container=i;}let l=c.container,w=l.value;return l.type==="signal"?[w,o=>{typeof o=="function"?l.value=o(l.value):l.value=o,_(l,l.value);}]:[w,{refetch:async o=>{l.run(o);},get loading(){return l.loading},get error(){return l.error},get status(){return l.status}}]}exports.a=m;exports.b=F;exports.c=q;//# sourceMappingURL=chunk-BP5PDE6F.js.map
2
+ //# sourceMappingURL=chunk-BP5PDE6F.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/reactive.ts","../src/core/devtools.ts","../src/core/use.ts"],"names":["REACTIVE_SIGNAL","targetMap","reactiveMap","reactive","target","existingProxy","proxy","key","receiver","res","track","value","oldValue","result","hasChanged","trigger","activeEffect","depsMap","dep","trackEffect","triggerEffects","isReactive","signalIdCounter","signalRegistry","getDevToolsHook","registerSignal","container","name","hook","id","info","updateSignal","globalRegistry","serializeKey","use","input","depsOrOptions","thirdArg","isUseable","source","params","currentValue","s","newValue","actions","deps","options","stateRef","currentKey","serializedKey","keyChanged","fn","memoState","d","i","ctx","control","newContainer","state","run","data","err","unsafeEffect"],"mappings":"iHAEO,IAAMA,CAAAA,CAAkB,OAAO,kBAAkB,CAAA,CAIlDC,EAAY,IAAI,OAAA,CAGhBC,CAAAA,CAAc,IAAI,OAAA,CAEjB,SAASC,EAA2BC,CAAAA,CAAc,CACrD,GAAIA,CAAAA,EAAWA,CAAAA,CAAeJ,CAAe,CAAA,CACzC,OAAOI,CAAAA,CAGX,IAAMC,CAAAA,CAAgBH,CAAAA,CAAY,IAAIE,CAAM,CAAA,CAC5C,GAAIC,CAAAA,CACA,OAAOA,EAGX,IAAMC,CAAAA,CAAQ,IAAI,KAAA,CAAMF,CAAAA,CAAQ,CAC5B,IAAIA,CAAAA,CAAQG,CAAAA,CAAKC,EAAU,CACvB,GAAID,IAAQP,CAAAA,CAAiB,OAAO,KAAA,CAEpC,IAAMS,CAAAA,CAAM,OAAA,CAAQ,IAAIL,CAAAA,CAAQG,CAAAA,CAAKC,CAAQ,CAAA,CAI7C,OAFAE,EAAMN,CAAAA,CAAQG,CAAG,CAAA,CAEbE,CAAAA,GAAQ,IAAA,EAAQ,OAAOA,GAAQ,QAAA,CACxBN,CAAAA,CAASM,CAAG,CAAA,CAGhBA,CACX,EACA,GAAA,CAAIL,CAAAA,CAAQG,CAAAA,CAAKI,CAAAA,CAAOH,CAAAA,CAAU,CAC9B,IAAMI,CA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AE,OAAOd,CAAAA,CAAU,OAAQ,CAAA,CACzC,IAAI,KAAA,EAAQ,CAAE,OAAOA,CAAAA,CAAU,KAAM,CAAA,CACrC,IAAI,MAAA,EAAS,CAAE,OAAOA,CAAAA,CAAU,MAAO,CACzC,CAC6B,CAEjC","file":"chunk-LOKMOGSA.js","sourcesContent":["import { activeEffect, trackEffect, triggerEffects } from './lifecycle'\n\nexport const REACTIVE_SIGNAL = Symbol('flexium.reactive')\n\ntype Dep = Set<any>\ntype KeyToDepMap = Map<any, Dep>\nconst targetMap = new WeakMap<any, KeyToDepMap>()\n\n// WeakMap to store existing proxies to avoid duplicates\nconst reactiveMap = new WeakMap<object, any>()\n\nexport function reactive<T extends object>(target: T): T {\n if (target && (target as any)[REACTIVE_SIGNAL]) {\n return target\n }\n\n const existingProxy = reactiveMap.get(target)\n if (existingProxy) {\n return existingProxy\n }\n\n const proxy = new Proxy(target, {\n get(target, key, receiver) {\n if (key === REACTIVE_SIGNAL) return true\n\n const res = Reflect.get(target, key, receiver)\n\n track(target, key)\n\n if (res !== null && typeof res === 'object') {\n return reactive(res)\n }\n\n return res\n },\n set(target, key, value, receiver) {\n const oldValue = (target as any)[key]\n const result = Reflect.set(target, key, value, receiver)\n\n if (result && hasChanged(value, oldValue)) {\n trigger(target, key)\n }\n\n return result\n }\n })\n\n reactiveMap.set(target, proxy)\n return proxy\n}\n\nexport function track(target: object, key: unknown) {\n if (!activeEffect) return\n\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n targetMap.set(target, (depsMap = new Map()))\n }\n\n let dep = depsMap.get(key)\n if (!dep) {\n depsMap.set(key, (dep = new Set()))\n }\n\n trackEffect(dep)\n}\n\nexport function trigger(target: object, key: unknown) {\n const depsMap = targetMap.get(target)\n if (!depsMap) return\n\n const dep = depsMap.get(key)\n if (dep) {\n triggerEffects(dep)\n }\n}\n\nfunction hasChanged(value: any, oldValue: any): boolean {\n return !Object.is(value, oldValue)\n}\n\nexport function isReactive(value: unknown): boolean {\n return !!(value && (value as any)[REACTIVE_SIGNAL])\n}\n","// DevTools integration for Flexium\n// This module provides hooks for browser DevTools extension\n\ninterface SignalInfo {\n id: number\n name: string\n value: unknown\n type: string\n subscribers: number\n createdAt: number\n}\n\ninterface DevToolsHook {\n signals: Map<number, SignalInfo>\n onSignalCreate: (info: SignalInfo) => void\n onSignalUpdate: (id: number, value: unknown) => void\n onRender: (event: { timestamp: number; componentName: string; trigger: string; duration: number }) => void\n}\n\ndeclare global {\n interface Window {\n __FLEXIUM_DEVTOOLS__?: DevToolsHook\n }\n}\n\nlet signalIdCounter = 0\nconst signalRegistry = new Map<object, number>()\n\nfunction getDevToolsHook(): DevToolsHook | undefined {\n if (typeof window !== 'undefined') {\n return window.__FLEXIUM_DEVTOOLS__\n }\n return undefined\n}\n\nexport function registerSignal(container: object, name?: string): number {\n const hook = getDevToolsHook()\n if (!hook) return -1\n\n const id = ++signalIdCounter\n signalRegistry.set(container, id)\n\n const info: SignalInfo = {\n id,\n name: name || `signal_${id}`,\n value: (container as any).value,\n type: (container as any).type || 'signal',\n subscribers: 0,\n createdAt: Date.now(),\n }\n\n hook.onSignalCreate(info)\n return id\n}\n\nexport function updateSignal(container: object, value: unknown): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n const id = signalRegistry.get(container)\n if (id !== undefined) {\n hook.onSignalUpdate(id, value)\n }\n}\n\nexport function reportRender(componentName: string, trigger: string, duration: number): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n hook.onRender({\n timestamp: Date.now(),\n componentName,\n trigger,\n duration,\n })\n}\n\nexport function isDevToolsEnabled(): boolean {\n return getDevToolsHook() !== undefined\n}\n","import { reactive } from './reactive'\nimport { unsafeEffect } from './lifecycle'\nimport { hook } from './hook'\nimport { registerSignal, updateSignal } from './devtools'\nimport { Context } from './context'\nimport { Useable, isUseable } from './useable'\n\n// Re-export Context and Useable\nexport { Context } from './context'\nexport { Useable, isUseable } from './useable'\n\n// Types\nexport type Setter<T> = (newValue: T | ((prev: T) => T)) => void\n\nexport type ResourceControl<P = void> = {\n refetch: (params?: P) => Promise<void>\n readonly loading: boolean\n readonly error: unknown\n readonly status: 'idle' | 'loading' | 'success' | 'error'\n}\n\nexport interface UseContext<P = void> {\n onCleanup: (fn: () => void) => void\n params?: P\n}\n\nexport interface UseOptions {\n key?: unknown[]\n name?: string\n}\n\n// Global State Registry\nconst globalRegistry = new Map<string, any>()\n\nfunction serializeKey(key: unknown[]): string {\n return JSON.stringify(key)\n}\n\n// Overloads\nexport function use<T>(ctx: Context<T>): [T, undefined]\n\nexport function use<T, P, A extends unknown[]>(source: Useable<T, P, A>, params?: P): [T, ...A]\n\nexport function use<T, P = void>(\n fn: (ctx: UseContext<P>) => Promise<T>,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T | undefined, ResourceControl<P>]\n\nexport function use<T>(\n fn: (ctx: UseContext) => T,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T, ResourceControl]\n\nexport function use<T>(\n initialValue: T extends Function ? never : T,\n options?: UseOptions\n): [T, Setter<T>]\n\nexport function use<T, P = void>(\n input: T | Useable<T, P> | ((ctx: UseContext<P>) => T) | ((ctx: UseContext<P>) => Promise<T>),\n depsOrOptions?: any[] | UseOptions | P,\n thirdArg?: UseOptions\n): any {\n // Useable mode: use(SomeUseable, params?) returns [value, undefined] or [value, send] for sendable\n // This handles Context, Stream, Shared, and any custom Useable\n if (isUseable(input)) {\n const source = input as Useable<T, P>\n const params = depsOrOptions as P | undefined\n\n // Hook to store subscription state\n const state = hook(() => {\n const s = reactive({\n value: source.getInitial(params),\n cleanup: undefined as (() => void) | undefined\n })\n\n // Subscribe to updates\n s.cleanup = source.subscribe(params, (newValue) => {\n s.value = newValue\n })\n\n return s\n })\n\n // Access value to track dependency\n const currentValue = state.value\n\n // Get additional actions from the source (if any)\n const actions = source.getActions()\n if (actions && actions.length > 0) {\n return [currentValue, ...actions]\n }\n\n return [currentValue, undefined]\n }\n\n // Normalize arguments:\n // - use(value, { key }) → options only\n // - use(fn, [deps]) → deps only\n // - use(fn, [deps], { key }) → deps + options\n let deps: any[] | undefined\n let options: UseOptions | undefined\n\n if (Array.isArray(depsOrOptions)) {\n deps = depsOrOptions\n options = thirdArg // third arg is options when second is deps array\n } else if (depsOrOptions && typeof depsOrOptions === 'object') {\n options = depsOrOptions as UseOptions\n }\n\n // Validate key if provided\n if (options?.key && !Array.isArray(options.key)) {\n throw new Error('State key must be an array')\n }\n\n // Hook Wrapper: Store container reference and track key\n const stateRef = hook(() => {\n return reactive({\n container: undefined as any,\n serializedKey: undefined as any\n })\n })\n\n // Compute serialized key\n const currentKey = options?.key\n const serializedKey = currentKey ? serializeKey(currentKey) : undefined\n\n // Check if key has changed\n const keyChanged = serializedKey !== stateRef.serializedKey\n\n // DEPS MODE: Function with explicit deps array\n if (typeof input === 'function' && deps !== undefined) {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n const memoState = hook(() => ({\n value: undefined as T | undefined,\n prevDeps: undefined as any[] | undefined,\n cleanup: undefined as (() => void) | undefined,\n hasRun: false,\n params: undefined as P | undefined\n }))\n\n let hasChanged = true\n if (memoState.hasRun && memoState.prevDeps) {\n hasChanged = deps.length !== memoState.prevDeps.length ||\n deps.some((d, i) => d !== memoState.prevDeps![i])\n }\n\n if (hasChanged) {\n // Run previous cleanup\n if (memoState.cleanup) {\n memoState.cleanup()\n memoState.cleanup = undefined\n }\n\n // Create context with onCleanup\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n memoState.cleanup = fn\n },\n params: memoState.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n throw new Error('deps with async functions is not supported. Use use(asyncFn) without deps for async resources.')\n }\n\n memoState.value = result\n memoState.prevDeps = [...deps]\n memoState.hasRun = true\n }\n\n const control: ResourceControl<P> = {\n refetch: async () => {},\n get loading() { return false },\n get error() { return null },\n get status() { return 'success' as const }\n }\n\n return [memoState.value, control]\n }\n\n // If key changed or first time, get/create container\n if (!stateRef.container || keyChanged) {\n stateRef.serializedKey = serializedKey\n\n // Check Registry FIRST\n if (serializedKey && globalRegistry.has(serializedKey)) {\n stateRef.container = globalRegistry.get(serializedKey)\n } else {\n let newContainer: any\n\n // Function (Computed or Resource)\n if (typeof input === 'function') {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n // State for async/computed\n const state = reactive({\n type: 'resource',\n value: undefined as T | undefined,\n loading: true,\n error: null as any,\n status: 'idle' as 'idle' | 'loading' | 'success' | 'error',\n cleanup: undefined as (() => void) | undefined,\n params: undefined as P | undefined,\n run: () => {}\n })\n\n const run = (params?: P) => {\n // Run previous cleanup\n if (state.cleanup) {\n state.cleanup()\n state.cleanup = undefined\n }\n\n // Store params for context\n state.params = params\n\n try {\n // Create context\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n state.cleanup = fn\n },\n params: state.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n state.loading = true\n state.status = 'loading'\n state.error = null\n\n result\n .then(data => {\n state.value = data\n state.status = 'success'\n state.loading = false\n })\n .catch(err => {\n state.error = err\n state.status = 'error'\n state.loading = false\n })\n } else {\n state.value = result\n state.status = 'success'\n state.loading = false\n state.error = null\n }\n } catch (err) {\n state.error = err\n state.status = 'error'\n state.loading = false\n }\n }\n\n state.run = run\n\n // Make it reactive!\n unsafeEffect(() => run())\n\n newContainer = state\n } else {\n // Value (Signal)\n newContainer = reactive({\n type: 'signal',\n value: input\n })\n\n // Register with DevTools\n registerSignal(newContainer, options?.name)\n }\n\n // Register in global registry if needed\n if (serializedKey) {\n globalRegistry.set(serializedKey, newContainer)\n }\n\n stateRef.container = newContainer\n }\n }\n\n const container = stateRef.container\n\n // Access container.value to track dependency\n const currentValue = container.value\n\n if (container.type === 'signal') {\n const setter: Setter<T> = (newValue) => {\n if (typeof newValue === 'function') {\n container.value = (newValue as Function)(container.value)\n } else {\n container.value = newValue\n }\n updateSignal(container, container.value)\n }\n return [currentValue, setter]\n } else {\n // Resource / Computed\n const control: ResourceControl<P> = {\n refetch: async (params?: P) => { container.run(params) },\n get loading() { return container.loading },\n get error() { return container.error },\n get status() { return container.status }\n }\n return [currentValue, control]\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/core/reactive.ts","../src/core/devtools.ts","../src/core/use.ts"],"names":["REACTIVE_SIGNAL","targetMap","reactiveMap","reactive","target","existingProxy","proxy","key","receiver","res","track","value","oldValue","result","hasChanged","trigger","activeEffect","depsMap","dep","trackEffect","triggerEffects","isReactive","signalIdCounter","signalRegistry","getDevToolsHook","registerSignal","container","name","hook","id","info","updateSignal","globalRegistry","serializeKey","use","input","depsOrOptions","thirdArg","isUseable","source","params","currentValue","s","newValue","actions","deps","options","stateRef","currentKey","serializedKey","keyChanged","fn","memoState","d","i","ctx","control","newContainer","state","run","data","err","unsafeEffect"],"mappings":"iHAEO,IAAMA,CAAAA,CAAkB,OAAO,kBAAkB,CAAA,CAIlDC,EAAY,IAAI,OAAA,CAGhBC,CAAAA,CAAc,IAAI,OAAA,CAEjB,SAASC,EAA2BC,CAAAA,CAAc,CACrD,GAAIA,CAAAA,EAAWA,CAAAA,CAAeJ,CAAe,CAAA,CACzC,OAAOI,CAAAA,CAGX,IAAMC,CAAAA,CAAgBH,CAAAA,CAAY,IAAIE,CAAM,CAAA,CAC5C,GAAIC,CAAAA,CACA,OAAOA,EAGX,IAAMC,CAAAA,CAAQ,IAAI,KAAA,CAAMF,CAAAA,CAAQ,CAC5B,IAAIA,CAAAA,CAAQG,CAAAA,CAAKC,EAAU,CACvB,GAAID,IAAQP,CAAAA,CAAiB,OAAO,KAAA,CAEpC,IAAMS,CAAAA,CAAM,OAAA,CAAQ,IAAIL,CAAAA,CAAQG,CAAAA,CAAKC,CAAQ,CAAA,CAI7C,OAFAE,EAAMN,CAAAA,CAAQG,CAAG,CAAA,CAEbE,CAAAA,GAAQ,IAAA,EAAQ,OAAOA,GAAQ,QAAA,CACxBN,CAAAA,CAASM,CAAG,CAAA,CAGhBA,CACX,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CAAAA,EAAe,CAAEd,CAAAA,CAAU,GAAA,CAAIc,CAAM,EAAE,CAAA,CACvD,IAAI,OAAA,EAAU,CAAE,OAAOd,CAAAA,CAAU,OAAQ,CAAA,CACzC,IAAI,KAAA,EAAQ,CAAE,OAAOA,CAAAA,CAAU,KAAM,CAAA,CACrC,IAAI,MAAA,EAAS,CAAE,OAAOA,CAAAA,CAAU,MAAO,CACzC,CAC6B,CAEjC","file":"chunk-BP5PDE6F.js","sourcesContent":["import { activeEffect, trackEffect, triggerEffects } from './lifecycle'\n\nexport const REACTIVE_SIGNAL = Symbol('flexium.reactive')\n\ntype Dep = Set<any>\ntype KeyToDepMap = Map<any, Dep>\nconst targetMap = new WeakMap<any, KeyToDepMap>()\n\n// WeakMap to store existing proxies to avoid duplicates\nconst reactiveMap = new WeakMap<object, any>()\n\nexport function reactive<T extends object>(target: T): T {\n if (target && (target as any)[REACTIVE_SIGNAL]) {\n return target\n }\n\n const existingProxy = reactiveMap.get(target)\n if (existingProxy) {\n return existingProxy\n }\n\n const proxy = new Proxy(target, {\n get(target, key, receiver) {\n if (key === REACTIVE_SIGNAL) return true\n\n const res = Reflect.get(target, key, receiver)\n\n track(target, key)\n\n if (res !== null && typeof res === 'object') {\n return reactive(res)\n }\n\n return res\n },\n set(target, key, value, receiver) {\n const oldValue = (target as any)[key]\n const result = Reflect.set(target, key, value, receiver)\n\n if (result && hasChanged(value, oldValue)) {\n trigger(target, key)\n }\n\n return result\n }\n })\n\n reactiveMap.set(target, proxy)\n return proxy\n}\n\nexport function track(target: object, key: unknown) {\n if (!activeEffect) return\n\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n targetMap.set(target, (depsMap = new Map()))\n }\n\n let dep = depsMap.get(key)\n if (!dep) {\n depsMap.set(key, (dep = new Set()))\n }\n\n trackEffect(dep)\n}\n\nexport function trigger(target: object, key: unknown) {\n const depsMap = targetMap.get(target)\n if (!depsMap) return\n\n const dep = depsMap.get(key)\n if (dep) {\n triggerEffects(dep)\n }\n}\n\nfunction hasChanged(value: any, oldValue: any): boolean {\n return !Object.is(value, oldValue)\n}\n\nexport function isReactive(value: unknown): boolean {\n return !!(value && (value as any)[REACTIVE_SIGNAL])\n}\n","// DevTools integration for Flexium\n// This module provides hooks for browser DevTools extension\n\ninterface SignalInfo {\n id: number\n name: string\n value: unknown\n type: string\n subscribers: number\n createdAt: number\n}\n\ninterface DevToolsHook {\n signals: Map<number, SignalInfo>\n onSignalCreate: (info: SignalInfo) => void\n onSignalUpdate: (id: number, value: unknown) => void\n onRender: (event: { timestamp: number; componentName: string; trigger: string; duration: number }) => void\n}\n\ndeclare global {\n interface Window {\n __FLEXIUM_DEVTOOLS__?: DevToolsHook\n }\n}\n\nlet signalIdCounter = 0\nconst signalRegistry = new Map<object, number>()\n\nfunction getDevToolsHook(): DevToolsHook | undefined {\n if (typeof window !== 'undefined') {\n return window.__FLEXIUM_DEVTOOLS__\n }\n return undefined\n}\n\nexport function registerSignal(container: object, name?: string): number {\n const hook = getDevToolsHook()\n if (!hook) return -1\n\n const id = ++signalIdCounter\n signalRegistry.set(container, id)\n\n const info: SignalInfo = {\n id,\n name: name || `signal_${id}`,\n value: (container as any).value,\n type: (container as any).type || 'signal',\n subscribers: 0,\n createdAt: Date.now(),\n }\n\n hook.onSignalCreate(info)\n return id\n}\n\nexport function updateSignal(container: object, value: unknown): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n const id = signalRegistry.get(container)\n if (id !== undefined) {\n hook.onSignalUpdate(id, value)\n }\n}\n\nexport function reportRender(componentName: string, trigger: string, duration: number): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n hook.onRender({\n timestamp: Date.now(),\n componentName,\n trigger,\n duration,\n })\n}\n\nexport function isDevToolsEnabled(): boolean {\n return getDevToolsHook() !== undefined\n}\n","import { reactive } from './reactive'\nimport { unsafeEffect } from './lifecycle'\nimport { hook } from './hook'\nimport { registerSignal, updateSignal } from './devtools'\nimport { Context } from './context'\nimport { Useable, isUseable } from './useable'\n\n// Re-export Context and Useable\nexport { Context } from './context'\nexport { Useable, isUseable } from './useable'\n\n// Types\nexport type Setter<T> = (newValue: T | ((prev: T) => T)) => void\n\nexport type ResourceControl<P = void> = {\n refetch: (params?: P) => Promise<void>\n readonly loading: boolean\n readonly error: unknown\n readonly status: 'idle' | 'loading' | 'success' | 'error'\n}\n\nexport interface UseContext<P = void> {\n onCleanup: (fn: () => void) => void\n params?: P\n}\n\nexport interface UseOptions {\n key?: unknown[]\n name?: string\n}\n\n// Global State Registry\nconst globalRegistry = new Map<string, any>()\n\nfunction serializeKey(key: unknown[]): string {\n return JSON.stringify(key)\n}\n\n// Overloads\nexport function use<T>(ctx: Context<T>): [T, undefined]\n\nexport function use<T, P, A extends unknown[]>(source: Useable<T, P, A>, params?: P): [T, ...A]\n\nexport function use<T, P = void>(\n fn: (ctx: UseContext<P>) => Promise<T>,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T | undefined, ResourceControl<P>]\n\nexport function use<T>(\n fn: (ctx: UseContext) => T,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T, ResourceControl]\n\nexport function use<T>(\n initialValue: T extends Function ? never : T,\n options?: UseOptions\n): [T, Setter<T>]\n\nexport function use<T, P = void>(\n input: T | Useable<T, P> | ((ctx: UseContext<P>) => T) | ((ctx: UseContext<P>) => Promise<T>),\n depsOrOptions?: any[] | UseOptions | P,\n thirdArg?: UseOptions\n): any {\n // Useable mode: use(SomeUseable, params?) returns [value, undefined] or [value, send] for sendable\n // This handles Context, Stream, Shared, and any custom Useable\n if (isUseable(input)) {\n const source = input as Useable<T, P>\n const params = depsOrOptions as P | undefined\n\n // Hook to store subscription state\n const state = hook(() => {\n const s = reactive({\n value: source.getInitial(params),\n cleanup: undefined as (() => void) | undefined\n })\n\n // Subscribe to updates\n s.cleanup = source.subscribe(params, (newValue) => {\n s.value = newValue\n })\n\n return s\n })\n\n // Access value to track dependency\n const currentValue = state.value\n\n // Get additional actions from the source (if any)\n const actions = source.getActions()\n if (actions && actions.length > 0) {\n return [currentValue, ...actions]\n }\n\n return [currentValue, undefined]\n }\n\n // Normalize arguments:\n // - use(value, { key }) → options only\n // - use(fn, [deps]) → deps only\n // - use(fn, [deps], { key }) → deps + options\n let deps: any[] | undefined\n let options: UseOptions | undefined\n\n if (Array.isArray(depsOrOptions)) {\n deps = depsOrOptions\n options = thirdArg // third arg is options when second is deps array\n } else if (depsOrOptions && typeof depsOrOptions === 'object') {\n options = depsOrOptions as UseOptions\n }\n\n // Validate key if provided\n if (options?.key && !Array.isArray(options.key)) {\n throw new Error('State key must be an array')\n }\n\n // Hook Wrapper: Store container reference and track key\n const stateRef = hook(() => {\n return reactive({\n container: undefined as any,\n serializedKey: undefined as any\n })\n })\n\n // Compute serialized key\n const currentKey = options?.key\n const serializedKey = currentKey ? serializeKey(currentKey) : undefined\n\n // Check if key has changed\n const keyChanged = serializedKey !== stateRef.serializedKey\n\n // DEPS MODE: Function with explicit deps array\n if (typeof input === 'function' && deps !== undefined) {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n const memoState = hook(() => ({\n value: undefined as T | undefined,\n prevDeps: undefined as any[] | undefined,\n cleanup: undefined as (() => void) | undefined,\n hasRun: false,\n params: undefined as P | undefined\n }))\n\n let hasChanged = true\n if (memoState.hasRun && memoState.prevDeps) {\n hasChanged = deps.length !== memoState.prevDeps.length ||\n deps.some((d, i) => d !== memoState.prevDeps![i])\n }\n\n if (hasChanged) {\n // Run previous cleanup\n if (memoState.cleanup) {\n memoState.cleanup()\n memoState.cleanup = undefined\n }\n\n // Create context with onCleanup\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n memoState.cleanup = fn\n },\n params: memoState.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n throw new Error('deps with async functions is not supported. Use use(asyncFn) without deps for async resources.')\n }\n\n memoState.value = result\n memoState.prevDeps = [...deps]\n memoState.hasRun = true\n }\n\n const control: ResourceControl<P> = {\n refetch: async () => {},\n get loading() { return false },\n get error() { return null },\n get status() { return 'success' as const }\n }\n\n return [memoState.value, control]\n }\n\n // If key changed or first time, get/create container\n if (!stateRef.container || keyChanged) {\n stateRef.serializedKey = serializedKey\n\n // Check Registry FIRST\n if (serializedKey && globalRegistry.has(serializedKey)) {\n stateRef.container = globalRegistry.get(serializedKey)\n } else {\n let newContainer: any\n\n // Function (Computed or Resource)\n if (typeof input === 'function') {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n // State for async/computed\n const state = reactive({\n type: 'resource',\n value: undefined as T | undefined,\n loading: true,\n error: null as any,\n status: 'idle' as 'idle' | 'loading' | 'success' | 'error',\n cleanup: undefined as (() => void) | undefined,\n params: undefined as P | undefined,\n run: () => {}\n })\n\n const run = (params?: P) => {\n // Run previous cleanup\n if (state.cleanup) {\n state.cleanup()\n state.cleanup = undefined\n }\n\n // Store params for context\n state.params = params\n\n try {\n // Create context\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n state.cleanup = fn\n },\n params: state.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n state.loading = true\n state.status = 'loading'\n state.error = null\n\n result\n .then(data => {\n state.value = data\n state.status = 'success'\n state.loading = false\n })\n .catch(err => {\n state.error = err\n state.status = 'error'\n state.loading = false\n })\n } else {\n state.value = result\n state.status = 'success'\n state.loading = false\n state.error = null\n }\n } catch (err) {\n state.error = err\n state.status = 'error'\n state.loading = false\n }\n }\n\n state.run = run\n\n // Make it reactive!\n unsafeEffect(() => run())\n\n newContainer = state\n } else {\n // Value (Signal)\n newContainer = reactive({\n type: 'signal',\n value: input\n })\n\n // Register with DevTools\n registerSignal(newContainer, options?.name)\n }\n\n // Register in global registry if needed\n if (serializedKey) {\n globalRegistry.set(serializedKey, newContainer)\n }\n\n stateRef.container = newContainer\n }\n }\n\n const container = stateRef.container\n\n // Access container.value to track dependency\n const currentValue = container.value\n\n if (container.type === 'signal') {\n const setter: Setter<T> = (newValue) => {\n if (typeof newValue === 'function') {\n container.value = (newValue as Function)(container.value)\n } else {\n container.value = newValue\n }\n updateSignal(container, container.value)\n }\n return [currentValue, setter]\n } else {\n // Resource / Computed\n const control: ResourceControl<P> = {\n refetch: async (params?: P) => { container.run(params) },\n get loading() { return container.loading },\n get error() { return container.error },\n get status() { return container.status }\n }\n return [currentValue, control]\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- import {a,c,d,b as b$2}from'./chunk-NRPWBHKP.mjs';import {d as d$1,b as b$1}from'./chunk-WHRUAZR4.mjs';var b=Symbol("flexium.reactive"),P=new WeakMap,R=new WeakMap;function m(e){if(e&&e[b])return e;let r=R.get(e);if(r)return r;let s=new Proxy(e,{get(t,a,c){if(a===b)return true;let f=Reflect.get(t,a,c);return j(t,a),f!==null&&typeof f=="object"?m(f):f},set(t,a,c,f){let d=t[a],x=Reflect.set(t,a,c,f);return x&&O(c,d)&&I(t,a),x}});return R.set(e,s),s}function j(e,r){if(!a)return;let s=P.get(e);s||P.set(e,s=new Map);let t=s.get(r);t||s.set(r,t=new Set),c(t);}function I(e,r){let s=P.get(e);if(!s)return;let t=s.get(r);t&&d(t);}function O(e,r){return !Object.is(e,r)}function F(e){return !!(e&&e[b])}var K=0,M=new Map;function E(){if(typeof window<"u")return window.__FLEXIUM_DEVTOOLS__}function A(e,r){let s=E();if(!s)return -1;let t=++K;M.set(e,t);let a={id:t,name:r||`signal_${t}`,value:e.value,type:e.type||"signal",subscribers:0,createdAt:Date.now()};return s.onSignalCreate(a),t}function _(e,r){let s=E();if(!s)return;let t=M.get(e);t!==void 0&&s.onSignalUpdate(t,r);}var U=new Map;function V(e){return JSON.stringify(e)}function q(e,r,s){if(d$1(e)){let i=e,o=r,g=b$1(()=>{let u=m({value:i.getInitial(o),cleanup:void 0});return u.cleanup=i.subscribe(o,y=>{u.value=y;}),u}).value,p=i.getActions();return p&&p.length>0?[g,...p]:[g,void 0]}let t,a;if(Array.isArray(r)?(t=r,a=s):r&&typeof r=="object"&&(a=r),a?.key&&!Array.isArray(a.key))throw new Error("State key must be an array");let c=b$1(()=>m({container:void 0,serializedKey:void 0})),f=a?.key,d=f?V(f):void 0,x=d!==c.serializedKey;if(typeof e=="function"&&t!==void 0){let i=e,o=b$1(()=>({value:void 0,prevDeps:void 0,cleanup:void 0,hasRun:false,params:void 0})),n=true;if(o.hasRun&&o.prevDeps&&(n=t.length!==o.prevDeps.length||t.some((p,u)=>p!==o.prevDeps[u])),n){o.cleanup&&(o.cleanup(),o.cleanup=void 0);let p={onCleanup:y=>{o.cleanup=y;},params:o.params},u=i(p);if(u instanceof Promise)throw new Error("deps with async functions is not supported. Use use(asyncFn) without deps for async resources.");o.value=u,o.prevDeps=[...t],o.hasRun=true;}let g={refetch:async()=>{},get loading(){return false},get error(){return null},get status(){return "success"}};return [o.value,g]}if(!c.container||x)if(c.serializedKey=d,d&&U.has(d))c.container=U.get(d);else {let i;if(typeof e=="function"){let o=e,n=m({type:"resource",value:void 0,loading:true,error:null,status:"idle",cleanup:void 0,params:void 0,run:()=>{}}),g=p=>{n.cleanup&&(n.cleanup(),n.cleanup=void 0),n.params=p;try{let u={onCleanup:v=>{n.cleanup=v;},params:n.params},y=o(u);y instanceof Promise?(n.loading=!0,n.status="loading",n.error=null,y.then(v=>{n.value=v,n.status="success",n.loading=!1;}).catch(v=>{n.error=v,n.status="error",n.loading=!1;})):(n.value=y,n.status="success",n.loading=!1,n.error=null);}catch(u){n.error=u,n.status="error",n.loading=false;}};n.run=g,b$2(()=>g()),i=n;}else i=m({type:"signal",value:e}),A(i,a?.name);d&&U.set(d,i),c.container=i;}let l=c.container,w=l.value;return l.type==="signal"?[w,o=>{typeof o=="function"?l.value=o(l.value):l.value=o,_(l,l.value);}]:[w,{refetch:async o=>{l.run(o);},get loading(){return l.loading},get error(){return l.error},get status(){return l.status}}]}export{m as a,F as b,q as c};//# sourceMappingURL=chunk-CB6CIG76.mjs.map
2
- //# sourceMappingURL=chunk-CB6CIG76.mjs.map
1
+ import {a,c,d,b as b$2}from'./chunk-NRPWBHKP.mjs';import {d as d$1,b as b$1}from'./chunk-TIUNOZRI.mjs';var b=Symbol("flexium.reactive"),P=new WeakMap,R=new WeakMap;function m(e){if(e&&e[b])return e;let r=R.get(e);if(r)return r;let s=new Proxy(e,{get(t,a,c){if(a===b)return true;let f=Reflect.get(t,a,c);return j(t,a),f!==null&&typeof f=="object"?m(f):f},set(t,a,c,f){let d=t[a],x=Reflect.set(t,a,c,f);return x&&O(c,d)&&I(t,a),x}});return R.set(e,s),s}function j(e,r){if(!a)return;let s=P.get(e);s||P.set(e,s=new Map);let t=s.get(r);t||s.set(r,t=new Set),c(t);}function I(e,r){let s=P.get(e);if(!s)return;let t=s.get(r);t&&d(t);}function O(e,r){return !Object.is(e,r)}function F(e){return !!(e&&e[b])}var K=0,M=new Map;function E(){if(typeof window<"u")return window.__FLEXIUM_DEVTOOLS__}function A(e,r){let s=E();if(!s)return -1;let t=++K;M.set(e,t);let a={id:t,name:r||`signal_${t}`,value:e.value,type:e.type||"signal",subscribers:0,createdAt:Date.now()};return s.onSignalCreate(a),t}function _(e,r){let s=E();if(!s)return;let t=M.get(e);t!==void 0&&s.onSignalUpdate(t,r);}var U=new Map;function V(e){return JSON.stringify(e)}function q(e,r,s){if(d$1(e)){let i=e,o=r,g=b$1(()=>{let u=m({value:i.getInitial(o),cleanup:void 0});return u.cleanup=i.subscribe(o,y=>{u.value=y;}),u}).value,p=i.getActions();return p&&p.length>0?[g,...p]:[g,void 0]}let t,a;if(Array.isArray(r)?(t=r,a=s):r&&typeof r=="object"&&(a=r),a?.key&&!Array.isArray(a.key))throw new Error("State key must be an array");let c=b$1(()=>m({container:void 0,serializedKey:void 0})),f=a?.key,d=f?V(f):void 0,x=d!==c.serializedKey;if(typeof e=="function"&&t!==void 0){let i=e,o=b$1(()=>({value:void 0,prevDeps:void 0,cleanup:void 0,hasRun:false,params:void 0})),n=true;if(o.hasRun&&o.prevDeps&&(n=t.length!==o.prevDeps.length||t.some((p,u)=>p!==o.prevDeps[u])),n){o.cleanup&&(o.cleanup(),o.cleanup=void 0);let p={onCleanup:y=>{o.cleanup=y;},params:o.params},u=i(p);if(u instanceof Promise)throw new Error("deps with async functions is not supported. Use use(asyncFn) without deps for async resources.");o.value=u,o.prevDeps=[...t],o.hasRun=true;}let g={refetch:async()=>{},get loading(){return false},get error(){return null},get status(){return "success"}};return [o.value,g]}if(!c.container||x)if(c.serializedKey=d,d&&U.has(d))c.container=U.get(d);else {let i;if(typeof e=="function"){let o=e,n=m({type:"resource",value:void 0,loading:true,error:null,status:"idle",cleanup:void 0,params:void 0,run:()=>{}}),g=p=>{n.cleanup&&(n.cleanup(),n.cleanup=void 0),n.params=p;try{let u={onCleanup:v=>{n.cleanup=v;},params:n.params},y=o(u);y instanceof Promise?(n.loading=!0,n.status="loading",n.error=null,y.then(v=>{n.value=v,n.status="success",n.loading=!1;}).catch(v=>{n.error=v,n.status="error",n.loading=!1;})):(n.value=y,n.status="success",n.loading=!1,n.error=null);}catch(u){n.error=u,n.status="error",n.loading=false;}};n.run=g,b$2(()=>g()),i=n;}else i=m({type:"signal",value:e}),A(i,a?.name);d&&U.set(d,i),c.container=i;}let l=c.container,w=l.value;return l.type==="signal"?[w,o=>{typeof o=="function"?l.value=o(l.value):l.value=o,_(l,l.value);}]:[w,{refetch:async o=>{l.run(o);},get loading(){return l.loading},get error(){return l.error},get status(){return l.status}}]}export{m as a,F as b,q as c};//# sourceMappingURL=chunk-FJNIW7B2.mjs.map
2
+ //# sourceMappingURL=chunk-FJNIW7B2.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/reactive.ts","../src/core/devtools.ts","../src/core/use.ts"],"names":["REACTIVE_SIGNAL","targetMap","reactiveMap","reactive","target","existingProxy","proxy","key","receiver","res","track","value","oldValue","result","hasChanged","trigger","activeEffect","depsMap","dep","trackEffect","triggerEffects","isReactive","signalIdCounter","signalRegistry","getDevToolsHook","registerSignal","container","name","hook","id","info","updateSignal","globalRegistry","serializeKey","use","input","depsOrOptions","thirdArg","isUseable","source","params","currentValue","s","newValue","actions","deps","options","stateRef","currentKey","serializedKey","keyChanged","fn","memoState","d","i","ctx","control","newContainer","state","run","data","err","unsafeEffect"],"mappings":"uGAEO,IAAMA,CAAAA,CAAkB,OAAO,kBAAkB,CAAA,CAIlDC,EAAY,IAAI,OAAA,CAGhBC,CAAAA,CAAc,IAAI,OAAA,CAEjB,SAASC,EAA2BC,CAAAA,CAAc,CACrD,GAAIA,CAAAA,EAAWA,CAAAA,CAAeJ,CAAe,CAAA,CACzC,OAAOI,CAAAA,CAGX,IAAMC,CAAAA,CAAgBH,CAAAA,CAAY,IAAIE,CAAM,CAAA,CAC5C,GAAIC,CAAAA,CACA,OAAOA,EAGX,IAAMC,CAAAA,CAAQ,IAAI,KAAA,CAAMF,CAAAA,CAAQ,CAC5B,IAAIA,CAAAA,CAAQG,CAAAA,CAAKC,EAAU,CACvB,GAAID,IAAQP,CAAAA,CAAiB,OAAO,KAAA,CAEpC,IAAMS,CAAAA,CAAM,OAAA,CAAQ,IAAIL,CAAAA,CAAQG,CAAAA,CAAKC,CAAQ,CAAA,CAI7C,OAFAE,EAAMN,CAAAA,CAAQG,CAAG,CAAA,CAEbE,CAAAA,GAAQ,IAAA,EAAQ,OAAOA,GAAQ,QAAA,CACxBN,CAAAA,CAASM,CAAG,CAAA,CAGhBA,CACX,EACA,GAAA,CAAIL,CAAAA,CAAQG,CAAAA,CAAKI,CAAAA,CAAOH,CAAAA,CAAU,CAC9B,IAAMI,CAAAA,CAAYR,CAAAA,CAAeG,CAAG,CAAA,CAC9BM,CAAAA,CAAS,QAAQ,GAAA,CAAIT,CAAAA,CAAQG,CAAAA,CAAKI,CAAAA,CAAOH,CAAQ,CAAA,CAEvD,OAAIK,CAAAA,EAAUC,CAAAA,CAAWH,EAAOC,CAAQ,CAAA,EACpCG,EAAQX,CAAAA,CAAQG,CAAG,CAAA,CAGhBM,CACX,CACJ,CAAC,EAED,OAAAX,CAAAA,CAAY,IAAIE,CAAA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OAAA,CACfA,CAAAA,CAAM,OAAA,CAAU,MAClB,CACF,CAAA,CAEAA,EAAM,GAAA,CAAMC,CAAAA,CAGZG,IAAa,IAAMH,CAAAA,EAAK,CAAA,CAExBF,CAAAA,CAAeC,EACjB,CAAA,KAEED,CAAAA,CAAetD,CAAAA,CAAS,CACtB,IAAA,CAAM,QAAA,CACN,MAAOgC,CACT,CAAC,EAGDV,CAAAA,CAAegC,CAAAA,CAAcX,CAAAA,EAAS,IAAI,CAAA,CAIxCG,CAAAA,EACFjB,EAAe,GAAA,CAAIiB,CAAAA,CAAeQ,CAAY,CAAA,CAGhDV,CAAAA,CAAS,UAAYU,EACvB,CAGF,IAAM/B,CAAAA,CAAYqB,CAAAA,CAAS,SAAA,CAGrBN,EAAef,CAAAA,CAAU,KAAA,CAE/B,OAAIA,CAAAA,CAAU,IAAA,GAAS,SASd,CAACe,CAAAA,CARmBE,CAAAA,EAAa,CAClC,OAAOA,CAAAA,EAAa,WACtBjB,CAAAA,CAAU,KAAA,CAASiB,EAAsBjB,CAAAA,CAAU,KAAK,EAExDA,CAAAA,CAAU,KAAA,CAAQiB,CAAAA,CAEpBZ,CAAAA,CAAaL,CAAAA,CAAWA,CAAAA,CAAU,KAAK,EACzC,CAC4B,EASrB,CAACe,CAAAA,CAN4B,CAClC,OAAA,CAAS,MAAOD,CAAAA,EAAe,CAAEd,CAAAA,CAAU,GAAA,CAAIc,CAAM,EAAE,CAAA,CACvD,IAAI,OAAA,EAAU,CAAE,OAAOd,CAAAA,CAAU,OAAQ,CAAA,CACzC,IAAI,KAAA,EAAQ,CAAE,OAAOA,CAAAA,CAAU,KAAM,CAAA,CACrC,IAAI,MAAA,EAAS,CAAE,OAAOA,CAAAA,CAAU,MAAO,CACzC,CAC6B,CAEjC","file":"chunk-CB6CIG76.mjs","sourcesContent":["import { activeEffect, trackEffect, triggerEffects } from './lifecycle'\n\nexport const REACTIVE_SIGNAL = Symbol('flexium.reactive')\n\ntype Dep = Set<any>\ntype KeyToDepMap = Map<any, Dep>\nconst targetMap = new WeakMap<any, KeyToDepMap>()\n\n// WeakMap to store existing proxies to avoid duplicates\nconst reactiveMap = new WeakMap<object, any>()\n\nexport function reactive<T extends object>(target: T): T {\n if (target && (target as any)[REACTIVE_SIGNAL]) {\n return target\n }\n\n const existingProxy = reactiveMap.get(target)\n if (existingProxy) {\n return existingProxy\n }\n\n const proxy = new Proxy(target, {\n get(target, key, receiver) {\n if (key === REACTIVE_SIGNAL) return true\n\n const res = Reflect.get(target, key, receiver)\n\n track(target, key)\n\n if (res !== null && typeof res === 'object') {\n return reactive(res)\n }\n\n return res\n },\n set(target, key, value, receiver) {\n const oldValue = (target as any)[key]\n const result = Reflect.set(target, key, value, receiver)\n\n if (result && hasChanged(value, oldValue)) {\n trigger(target, key)\n }\n\n return result\n }\n })\n\n reactiveMap.set(target, proxy)\n return proxy\n}\n\nexport function track(target: object, key: unknown) {\n if (!activeEffect) return\n\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n targetMap.set(target, (depsMap = new Map()))\n }\n\n let dep = depsMap.get(key)\n if (!dep) {\n depsMap.set(key, (dep = new Set()))\n }\n\n trackEffect(dep)\n}\n\nexport function trigger(target: object, key: unknown) {\n const depsMap = targetMap.get(target)\n if (!depsMap) return\n\n const dep = depsMap.get(key)\n if (dep) {\n triggerEffects(dep)\n }\n}\n\nfunction hasChanged(value: any, oldValue: any): boolean {\n return !Object.is(value, oldValue)\n}\n\nexport function isReactive(value: unknown): boolean {\n return !!(value && (value as any)[REACTIVE_SIGNAL])\n}\n","// DevTools integration for Flexium\n// This module provides hooks for browser DevTools extension\n\ninterface SignalInfo {\n id: number\n name: string\n value: unknown\n type: string\n subscribers: number\n createdAt: number\n}\n\ninterface DevToolsHook {\n signals: Map<number, SignalInfo>\n onSignalCreate: (info: SignalInfo) => void\n onSignalUpdate: (id: number, value: unknown) => void\n onRender: (event: { timestamp: number; componentName: string; trigger: string; duration: number }) => void\n}\n\ndeclare global {\n interface Window {\n __FLEXIUM_DEVTOOLS__?: DevToolsHook\n }\n}\n\nlet signalIdCounter = 0\nconst signalRegistry = new Map<object, number>()\n\nfunction getDevToolsHook(): DevToolsHook | undefined {\n if (typeof window !== 'undefined') {\n return window.__FLEXIUM_DEVTOOLS__\n }\n return undefined\n}\n\nexport function registerSignal(container: object, name?: string): number {\n const hook = getDevToolsHook()\n if (!hook) return -1\n\n const id = ++signalIdCounter\n signalRegistry.set(container, id)\n\n const info: SignalInfo = {\n id,\n name: name || `signal_${id}`,\n value: (container as any).value,\n type: (container as any).type || 'signal',\n subscribers: 0,\n createdAt: Date.now(),\n }\n\n hook.onSignalCreate(info)\n return id\n}\n\nexport function updateSignal(container: object, value: unknown): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n const id = signalRegistry.get(container)\n if (id !== undefined) {\n hook.onSignalUpdate(id, value)\n }\n}\n\nexport function reportRender(componentName: string, trigger: string, duration: number): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n hook.onRender({\n timestamp: Date.now(),\n componentName,\n trigger,\n duration,\n })\n}\n\nexport function isDevToolsEnabled(): boolean {\n return getDevToolsHook() !== undefined\n}\n","import { reactive } from './reactive'\nimport { unsafeEffect } from './lifecycle'\nimport { hook } from './hook'\nimport { registerSignal, updateSignal } from './devtools'\nimport { Context } from './context'\nimport { Useable, isUseable } from './useable'\n\n// Re-export Context and Useable\nexport { Context } from './context'\nexport { Useable, isUseable } from './useable'\n\n// Types\nexport type Setter<T> = (newValue: T | ((prev: T) => T)) => void\n\nexport type ResourceControl<P = void> = {\n refetch: (params?: P) => Promise<void>\n readonly loading: boolean\n readonly error: unknown\n readonly status: 'idle' | 'loading' | 'success' | 'error'\n}\n\nexport interface UseContext<P = void> {\n onCleanup: (fn: () => void) => void\n params?: P\n}\n\nexport interface UseOptions {\n key?: unknown[]\n name?: string\n}\n\n// Global State Registry\nconst globalRegistry = new Map<string, any>()\n\nfunction serializeKey(key: unknown[]): string {\n return JSON.stringify(key)\n}\n\n// Overloads\nexport function use<T>(ctx: Context<T>): [T, undefined]\n\nexport function use<T, P, A extends unknown[]>(source: Useable<T, P, A>, params?: P): [T, ...A]\n\nexport function use<T, P = void>(\n fn: (ctx: UseContext<P>) => Promise<T>,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T | undefined, ResourceControl<P>]\n\nexport function use<T>(\n fn: (ctx: UseContext) => T,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T, ResourceControl]\n\nexport function use<T>(\n initialValue: T extends Function ? never : T,\n options?: UseOptions\n): [T, Setter<T>]\n\nexport function use<T, P = void>(\n input: T | Useable<T, P> | ((ctx: UseContext<P>) => T) | ((ctx: UseContext<P>) => Promise<T>),\n depsOrOptions?: any[] | UseOptions | P,\n thirdArg?: UseOptions\n): any {\n // Useable mode: use(SomeUseable, params?) returns [value, undefined] or [value, send] for sendable\n // This handles Context, Stream, Shared, and any custom Useable\n if (isUseable(input)) {\n const source = input as Useable<T, P>\n const params = depsOrOptions as P | undefined\n\n // Hook to store subscription state\n const state = hook(() => {\n const s = reactive({\n value: source.getInitial(params),\n cleanup: undefined as (() => void) | undefined\n })\n\n // Subscribe to updates\n s.cleanup = source.subscribe(params, (newValue) => {\n s.value = newValue\n })\n\n return s\n })\n\n // Access value to track dependency\n const currentValue = state.value\n\n // Get additional actions from the source (if any)\n const actions = source.getActions()\n if (actions && actions.length > 0) {\n return [currentValue, ...actions]\n }\n\n return [currentValue, undefined]\n }\n\n // Normalize arguments:\n // - use(value, { key }) → options only\n // - use(fn, [deps]) → deps only\n // - use(fn, [deps], { key }) → deps + options\n let deps: any[] | undefined\n let options: UseOptions | undefined\n\n if (Array.isArray(depsOrOptions)) {\n deps = depsOrOptions\n options = thirdArg // third arg is options when second is deps array\n } else if (depsOrOptions && typeof depsOrOptions === 'object') {\n options = depsOrOptions as UseOptions\n }\n\n // Validate key if provided\n if (options?.key && !Array.isArray(options.key)) {\n throw new Error('State key must be an array')\n }\n\n // Hook Wrapper: Store container reference and track key\n const stateRef = hook(() => {\n return reactive({\n container: undefined as any,\n serializedKey: undefined as any\n })\n })\n\n // Compute serialized key\n const currentKey = options?.key\n const serializedKey = currentKey ? serializeKey(currentKey) : undefined\n\n // Check if key has changed\n const keyChanged = serializedKey !== stateRef.serializedKey\n\n // DEPS MODE: Function with explicit deps array\n if (typeof input === 'function' && deps !== undefined) {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n const memoState = hook(() => ({\n value: undefined as T | undefined,\n prevDeps: undefined as any[] | undefined,\n cleanup: undefined as (() => void) | undefined,\n hasRun: false,\n params: undefined as P | undefined\n }))\n\n let hasChanged = true\n if (memoState.hasRun && memoState.prevDeps) {\n hasChanged = deps.length !== memoState.prevDeps.length ||\n deps.some((d, i) => d !== memoState.prevDeps![i])\n }\n\n if (hasChanged) {\n // Run previous cleanup\n if (memoState.cleanup) {\n memoState.cleanup()\n memoState.cleanup = undefined\n }\n\n // Create context with onCleanup\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n memoState.cleanup = fn\n },\n params: memoState.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n throw new Error('deps with async functions is not supported. Use use(asyncFn) without deps for async resources.')\n }\n\n memoState.value = result\n memoState.prevDeps = [...deps]\n memoState.hasRun = true\n }\n\n const control: ResourceControl<P> = {\n refetch: async () => {},\n get loading() { return false },\n get error() { return null },\n get status() { return 'success' as const }\n }\n\n return [memoState.value, control]\n }\n\n // If key changed or first time, get/create container\n if (!stateRef.container || keyChanged) {\n stateRef.serializedKey = serializedKey\n\n // Check Registry FIRST\n if (serializedKey && globalRegistry.has(serializedKey)) {\n stateRef.container = globalRegistry.get(serializedKey)\n } else {\n let newContainer: any\n\n // Function (Computed or Resource)\n if (typeof input === 'function') {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n // State for async/computed\n const state = reactive({\n type: 'resource',\n value: undefined as T | undefined,\n loading: true,\n error: null as any,\n status: 'idle' as 'idle' | 'loading' | 'success' | 'error',\n cleanup: undefined as (() => void) | undefined,\n params: undefined as P | undefined,\n run: () => {}\n })\n\n const run = (params?: P) => {\n // Run previous cleanup\n if (state.cleanup) {\n state.cleanup()\n state.cleanup = undefined\n }\n\n // Store params for context\n state.params = params\n\n try {\n // Create context\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n state.cleanup = fn\n },\n params: state.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n state.loading = true\n state.status = 'loading'\n state.error = null\n\n result\n .then(data => {\n state.value = data\n state.status = 'success'\n state.loading = false\n })\n .catch(err => {\n state.error = err\n state.status = 'error'\n state.loading = false\n })\n } else {\n state.value = result\n state.status = 'success'\n state.loading = false\n state.error = null\n }\n } catch (err) {\n state.error = err\n state.status = 'error'\n state.loading = false\n }\n }\n\n state.run = run\n\n // Make it reactive!\n unsafeEffect(() => run())\n\n newContainer = state\n } else {\n // Value (Signal)\n newContainer = reactive({\n type: 'signal',\n value: input\n })\n\n // Register with DevTools\n registerSignal(newContainer, options?.name)\n }\n\n // Register in global registry if needed\n if (serializedKey) {\n globalRegistry.set(serializedKey, newContainer)\n }\n\n stateRef.container = newContainer\n }\n }\n\n const container = stateRef.container\n\n // Access container.value to track dependency\n const currentValue = container.value\n\n if (container.type === 'signal') {\n const setter: Setter<T> = (newValue) => {\n if (typeof newValue === 'function') {\n container.value = (newValue as Function)(container.value)\n } else {\n container.value = newValue\n }\n updateSignal(container, container.value)\n }\n return [currentValue, setter]\n } else {\n // Resource / Computed\n const control: ResourceControl<P> = {\n refetch: async (params?: P) => { container.run(params) },\n get loading() { return container.loading },\n get error() { return container.error },\n get status() { return container.status }\n }\n return [currentValue, control]\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/core/reactive.ts","../src/core/devtools.ts","../src/core/use.ts"],"names":["REACTIVE_SIGNAL","targetMap","reactiveMap","reactive","target","existingProxy","proxy","key","receiver","res","track","value","oldValue","result","hasChanged","trigger","activeEffect","depsMap","dep","trackEffect","triggerEffects","isReactive","signalIdCounter","signalRegistry","getDevToolsHook","registerSignal","container","name","hook","id","info","updateSignal","globalRegistry","serializeKey","use","input","depsOrOptions","thirdArg","isUseable","source","params","currentValue","s","newValue","actions","deps","options","stateRef","currentKey","serializedKey","keyChanged","fn","memoState","d","i","ctx","control","newContainer","state","run","data","err","unsafeEffect"],"mappings":"uGAEO,IAAMA,CAAAA,CAAkB,OAAO,kBAAkB,CAAA,CAIlDC,EAAY,IAAI,OAAA,CAGhBC,CAAAA,CAAc,IAAI,OAAA,CAEjB,SAASC,EAA2BC,CAAAA,CAAc,CACrD,GAAIA,CAAAA,EAAWA,CAAAA,CAAeJ,CAAe,CAAA,CACzC,OAAOI,CAAAA,CAGX,IAAMC,CAAAA,CAAgBH,CAAAA,CAAY,IAAIE,CAAM,CAAA,CAC5C,GAAIC,CAAAA,CACA,OAAOA,EAGX,IAAMC,CAAAA,CAAQ,IAAI,KAAA,CAAMF,CAAAA,CAAQ,CAC5B,IAAIA,CAAAA,CAAQG,CAAAA,CAAKC,EAAU,CACvB,GAAID,IAAQP,CAAAA,CAAiB,OAAO,KAAA,CAEpC,IAAMS,CAAAA,CAAM,OAAA,CAAQ,IAAIL,CAAAA,CAAQG,CAAAA,CAAKC,CAAQ,CAAA,CAI7C,OAFAE,EAAMN,CAAAA,CAAQG,CAAG,CAAA,CAEbE,CAAAA,GAAQ,IAAA,EAAQ,OAAOA,GAAQ,QAAA,CACxBN,CAAAA,CAASM,CAAG,CAAA,CAGhBA,CACX,EACA,GAAA,CAAIL,CAAAA,CAAQG,CAAAA,CAAKI,CAAAA,CAAOH,CAAAA,CAAU,CAC9B,IAAMI,CAAAA,CAAYR,CAAAA,CAAeG,CAAG,CAAA,CAC9BM,CAAAA,CAAS,QAAQ,GAAA,CAAIT,CAAAA,CAAQG,CAAAA,CAAKI,CAAAA,CAAOH,CAAQ,CAAA,CAEvD,OAAIK,CAAAA,EAAUC,CAAAA,CAAWH,EAAOC,CAAQ,CAAA,EACpCG,EAAQX,CAAAA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erEffects } from './lifecycle'\n\nexport const REACTIVE_SIGNAL = Symbol('flexium.reactive')\n\ntype Dep = Set<any>\ntype KeyToDepMap = Map<any, Dep>\nconst targetMap = new WeakMap<any, KeyToDepMap>()\n\n// WeakMap to store existing proxies to avoid duplicates\nconst reactiveMap = new WeakMap<object, any>()\n\nexport function reactive<T extends object>(target: T): T {\n if (target && (target as any)[REACTIVE_SIGNAL]) {\n return target\n }\n\n const existingProxy = reactiveMap.get(target)\n if (existingProxy) {\n return existingProxy\n }\n\n const proxy = new Proxy(target, {\n get(target, key, receiver) {\n if (key === REACTIVE_SIGNAL) return true\n\n const res = Reflect.get(target, key, receiver)\n\n track(target, key)\n\n if (res !== null && typeof res === 'object') {\n return reactive(res)\n }\n\n return res\n },\n set(target, key, value, receiver) {\n const oldValue = (target as any)[key]\n const result = Reflect.set(target, key, value, receiver)\n\n if (result && hasChanged(value, oldValue)) {\n trigger(target, key)\n }\n\n return result\n }\n })\n\n reactiveMap.set(target, proxy)\n return proxy\n}\n\nexport function track(target: object, key: unknown) {\n if (!activeEffect) return\n\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n targetMap.set(target, (depsMap = new Map()))\n }\n\n let dep = depsMap.get(key)\n if (!dep) {\n depsMap.set(key, (dep = new Set()))\n }\n\n trackEffect(dep)\n}\n\nexport function trigger(target: object, key: unknown) {\n const depsMap = targetMap.get(target)\n if (!depsMap) return\n\n const dep = depsMap.get(key)\n if (dep) {\n triggerEffects(dep)\n }\n}\n\nfunction hasChanged(value: any, oldValue: any): boolean {\n return !Object.is(value, oldValue)\n}\n\nexport function isReactive(value: unknown): boolean {\n return !!(value && (value as any)[REACTIVE_SIGNAL])\n}\n","// DevTools integration for Flexium\n// This module provides hooks for browser DevTools extension\n\ninterface SignalInfo {\n id: number\n name: string\n value: unknown\n type: string\n subscribers: number\n createdAt: number\n}\n\ninterface DevToolsHook {\n signals: Map<number, SignalInfo>\n onSignalCreate: (info: SignalInfo) => void\n onSignalUpdate: (id: number, value: unknown) => void\n onRender: (event: { timestamp: number; componentName: string; trigger: string; duration: number }) => void\n}\n\ndeclare global {\n interface Window {\n __FLEXIUM_DEVTOOLS__?: DevToolsHook\n }\n}\n\nlet signalIdCounter = 0\nconst signalRegistry = new Map<object, number>()\n\nfunction getDevToolsHook(): DevToolsHook | undefined {\n if (typeof window !== 'undefined') {\n return window.__FLEXIUM_DEVTOOLS__\n }\n return undefined\n}\n\nexport function registerSignal(container: object, name?: string): number {\n const hook = getDevToolsHook()\n if (!hook) return -1\n\n const id = ++signalIdCounter\n signalRegistry.set(container, id)\n\n const info: SignalInfo = {\n id,\n name: name || `signal_${id}`,\n value: (container as any).value,\n type: (container as any).type || 'signal',\n subscribers: 0,\n createdAt: Date.now(),\n }\n\n hook.onSignalCreate(info)\n return id\n}\n\nexport function updateSignal(container: object, value: unknown): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n const id = signalRegistry.get(container)\n if (id !== undefined) {\n hook.onSignalUpdate(id, value)\n }\n}\n\nexport function reportRender(componentName: string, trigger: string, duration: number): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n hook.onRender({\n timestamp: Date.now(),\n componentName,\n trigger,\n duration,\n })\n}\n\nexport function isDevToolsEnabled(): boolean {\n return getDevToolsHook() !== undefined\n}\n","import { reactive } from './reactive'\nimport { unsafeEffect } from './lifecycle'\nimport { hook } from './hook'\nimport { registerSignal, updateSignal } from './devtools'\nimport { Context } from './context'\nimport { Useable, isUseable } from './useable'\n\n// Re-export Context and Useable\nexport { Context } from './context'\nexport { Useable, isUseable } from './useable'\n\n// Types\nexport type Setter<T> = (newValue: T | ((prev: T) => T)) => void\n\nexport type ResourceControl<P = void> = {\n refetch: (params?: P) => Promise<void>\n readonly loading: boolean\n readonly error: unknown\n readonly status: 'idle' | 'loading' | 'success' | 'error'\n}\n\nexport interface UseContext<P = void> {\n onCleanup: (fn: () => void) => void\n params?: P\n}\n\nexport interface UseOptions {\n key?: unknown[]\n name?: string\n}\n\n// Global State Registry\nconst globalRegistry = new Map<string, any>()\n\nfunction serializeKey(key: unknown[]): string {\n return JSON.stringify(key)\n}\n\n// Overloads\nexport function use<T>(ctx: Context<T>): [T, undefined]\n\nexport function use<T, P, A extends unknown[]>(source: Useable<T, P, A>, params?: P): [T, ...A]\n\nexport function use<T, P = void>(\n fn: (ctx: UseContext<P>) => Promise<T>,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T | undefined, ResourceControl<P>]\n\nexport function use<T>(\n fn: (ctx: UseContext) => T,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T, ResourceControl]\n\nexport function use<T>(\n initialValue: T extends Function ? never : T,\n options?: UseOptions\n): [T, Setter<T>]\n\nexport function use<T, P = void>(\n input: T | Useable<T, P> | ((ctx: UseContext<P>) => T) | ((ctx: UseContext<P>) => Promise<T>),\n depsOrOptions?: any[] | UseOptions | P,\n thirdArg?: UseOptions\n): any {\n // Useable mode: use(SomeUseable, params?) returns [value, undefined] or [value, send] for sendable\n // This handles Context, Stream, Shared, and any custom Useable\n if (isUseable(input)) {\n const source = input as Useable<T, P>\n const params = depsOrOptions as P | undefined\n\n // Hook to store subscription state\n const state = hook(() => {\n const s = reactive({\n value: source.getInitial(params),\n cleanup: undefined as (() => void) | undefined\n })\n\n // Subscribe to updates\n s.cleanup = source.subscribe(params, (newValue) => {\n s.value = newValue\n })\n\n return s\n })\n\n // Access value to track dependency\n const currentValue = state.value\n\n // Get additional actions from the source (if any)\n const actions = source.getActions()\n if (actions && actions.length > 0) {\n return [currentValue, ...actions]\n }\n\n return [currentValue, undefined]\n }\n\n // Normalize arguments:\n // - use(value, { key }) → options only\n // - use(fn, [deps]) → deps only\n // - use(fn, [deps], { key }) → deps + options\n let deps: any[] | undefined\n let options: UseOptions | undefined\n\n if (Array.isArray(depsOrOptions)) {\n deps = depsOrOptions\n options = thirdArg // third arg is options when second is deps array\n } else if (depsOrOptions && typeof depsOrOptions === 'object') {\n options = depsOrOptions as UseOptions\n }\n\n // Validate key if provided\n if (options?.key && !Array.isArray(options.key)) {\n throw new Error('State key must be an array')\n }\n\n // Hook Wrapper: Store container reference and track key\n const stateRef = hook(() => {\n return reactive({\n container: undefined as any,\n serializedKey: undefined as any\n })\n })\n\n // Compute serialized key\n const currentKey = options?.key\n const serializedKey = currentKey ? serializeKey(currentKey) : undefined\n\n // Check if key has changed\n const keyChanged = serializedKey !== stateRef.serializedKey\n\n // DEPS MODE: Function with explicit deps array\n if (typeof input === 'function' && deps !== undefined) {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n const memoState = hook(() => ({\n value: undefined as T | undefined,\n prevDeps: undefined as any[] | undefined,\n cleanup: undefined as (() => void) | undefined,\n hasRun: false,\n params: undefined as P | undefined\n }))\n\n let hasChanged = true\n if (memoState.hasRun && memoState.prevDeps) {\n hasChanged = deps.length !== memoState.prevDeps.length ||\n deps.some((d, i) => d !== memoState.prevDeps![i])\n }\n\n if (hasChanged) {\n // Run previous cleanup\n if (memoState.cleanup) {\n memoState.cleanup()\n memoState.cleanup = undefined\n }\n\n // Create context with onCleanup\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n memoState.cleanup = fn\n },\n params: memoState.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n throw new Error('deps with async functions is not supported. Use use(asyncFn) without deps for async resources.')\n }\n\n memoState.value = result\n memoState.prevDeps = [...deps]\n memoState.hasRun = true\n }\n\n const control: ResourceControl<P> = {\n refetch: async () => {},\n get loading() { return false },\n get error() { return null },\n get status() { return 'success' as const }\n }\n\n return [memoState.value, control]\n }\n\n // If key changed or first time, get/create container\n if (!stateRef.container || keyChanged) {\n stateRef.serializedKey = serializedKey\n\n // Check Registry FIRST\n if (serializedKey && globalRegistry.has(serializedKey)) {\n stateRef.container = globalRegistry.get(serializedKey)\n } else {\n let newContainer: any\n\n // Function (Computed or Resource)\n if (typeof input === 'function') {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n // State for async/computed\n const state = reactive({\n type: 'resource',\n value: undefined as T | undefined,\n loading: true,\n error: null as any,\n status: 'idle' as 'idle' | 'loading' | 'success' | 'error',\n cleanup: undefined as (() => void) | undefined,\n params: undefined as P | undefined,\n run: () => {}\n })\n\n const run = (params?: P) => {\n // Run previous cleanup\n if (state.cleanup) {\n state.cleanup()\n state.cleanup = undefined\n }\n\n // Store params for context\n state.params = params\n\n try {\n // Create context\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n state.cleanup = fn\n },\n params: state.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n state.loading = true\n state.status = 'loading'\n state.error = null\n\n result\n .then(data => {\n state.value = data\n state.status = 'success'\n state.loading = false\n })\n .catch(err => {\n state.error = err\n state.status = 'error'\n state.loading = false\n })\n } else {\n state.value = result\n state.status = 'success'\n state.loading = false\n state.error = null\n }\n } catch (err) {\n state.error = err\n state.status = 'error'\n state.loading = false\n }\n }\n\n state.run = run\n\n // Make it reactive!\n unsafeEffect(() => run())\n\n newContainer = state\n } else {\n // Value (Signal)\n newContainer = reactive({\n type: 'signal',\n value: input\n })\n\n // Register with DevTools\n registerSignal(newContainer, options?.name)\n }\n\n // Register in global registry if needed\n if (serializedKey) {\n globalRegistry.set(serializedKey, newContainer)\n }\n\n stateRef.container = newContainer\n }\n }\n\n const container = stateRef.container\n\n // Access container.value to track dependency\n const currentValue = container.value\n\n if (container.type === 'signal') {\n const setter: Setter<T> = (newValue) => {\n if (typeof newValue === 'function') {\n container.value = (newValue as Function)(container.value)\n } else {\n container.value = newValue\n }\n updateSignal(container, container.value)\n }\n return [currentValue, setter]\n } else {\n // Resource / Computed\n const control: ResourceControl<P> = {\n refetch: async (params?: P) => { container.run(params) },\n get loading() { return container.loading },\n get error() { return container.error },\n get status() { return container.status }\n }\n return [currentValue, control]\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- import {a,c}from'./chunk-CB6CIG76.mjs';import {e}from'./chunk-WHRUAZR4.mjs';import {a as a$1}from'./chunk-RUYGSYEV.mjs';function L(t){if(!t)return {};if(typeof URLSearchParams<"u"){let e=new URLSearchParams(t),r={};return e.forEach((n,o)=>r[o]=n),r}return t.substring(1).split("&").reduce((e,r)=>{let[n,o]=r.split("=");return n&&(e[decodeURIComponent(n)]=decodeURIComponent(o||"")),e},{})}function b(t){return !!(!t||typeof t!="string"||t.length>2048||t.includes("__proto__")||t.includes("constructor")||/^\s*javascript:/i.test(t))}function y(t){let e=[];return t.forEach(r=>{if(!r)return;let{path:n,component:o,children:i,beforeEnter:f}=r.props||{},a={path:n||"/",component:o,beforeEnter:f};if(i){let c=Array.isArray(i)?i:[i];a.children=y(c);}!a.children&&r.children&&r.children.length>0&&(a.children=y(r.children)),e.push(a);}),e}function D(t,e){for(let r of t){let n=r.path,o=T(n,e);if(o)return [{route:r,params:o.params,pathname:o.path}]}return null}function T(t,e){let r=t.split("/").filter(Boolean),n=e.split("/").filter(Boolean);if(r.length!==n.length)return null;let o={};for(let i=0;i<r.length;i++){let f=r[i],a=n[i];if(f.startsWith(":")){let c=f.slice(1);o[c]=a;}else if(f!==a)return null}return {params:o,path:e}}var w=new e(null),m=new e(0),U=()=>({pathname:"/",search:"",hash:"",query:{}}),E=()=>{if(typeof window>"u")return U();let t=window.location.pathname;return (!t||t==="srcdoc"||t==="/srcdoc")&&(t="/"),{pathname:t,search:window.location.search,hash:window.location.hash,query:L(window.location.search)}},l=null,p=null,F=false;function j(){l=null,p=null;}function h(){if(l&&p)return [l,p];l=a(E());let t=e=>{l&&(l.pathname=e.pathname,l.search=e.search,l.hash=e.hash,l.query=e.query);};return p=e=>{if(typeof window>"u")return;if(b(e)){console.error("[Flexium Router] Blocked navigation to unsafe path:",e);return}try{window.history.pushState({},"",e);}catch{}let r={pathname:e.split("?")[0].split("#")[0],search:e.includes("?")?"?"+e.split("?")[1].split("#")[0]:"",hash:e.includes("#")?"#"+e.split("#")[1]:"",query:L(e.includes("?")?"?"+e.split("?")[1].split("#")[0]:"")};t(r);},typeof window<"u"&&!F&&(window.addEventListener("popstate",()=>{t(E());}),F=true),[l,p]}function R(){let[t]=c(w);if(!t)throw new Error("useRouter() must be called within a <Routes> component");return t}function _(){let[,t]=h();return t}function P(){return p||h(),p}function Q(){return R().params}function B(){let[t]=h();return t.query}function x(t){return null}function A(t){return t&&typeof t=="object"&&("type"in t||Array.isArray(t))}function M(t){let[e,r]=h(),n=Array.isArray(t.children)?t.children:[t.children],o=n.filter(s=>A(s)&&s.type===x),i=n.filter(s=>!A(s)||s.type!==x),f=y(o),a=e.pathname,c=D(f,a)||[],S=c.length>0?c[c.length-1].params:{},q={location:e,navigate:r,matches:c,params:S},v=null;if(c.length>0){let s=c[0],k=s.route.component,g=a;s.route.beforeEnter?s.route.beforeEnter(s.params)!==false&&(v=a$1(m.Provider,{value:1,key:g,children:a$1(k,{params:s.params,key:g})})):v=a$1(m.Provider,{value:1,key:g,children:a$1(k,{params:s.params,key:g})});}return a$1(w.Provider,{value:q,children:[...i,v]})}function I(){let t=R(),[e]=c(m),r=e??0,[n]=c(()=>t.matches);if(r>=n.length)return null;let o=n[r],i=o.route.component;return o.route.beforeEnter&&o.route.beforeEnter(o.params)===false?null:a$1(m.Provider,{value:r+1,children:a$1(i,{params:o.params})})}function O(t){return a$1("a",{href:t.to,class:t.class||t.className,style:t.style?t.style+"; cursor: pointer;":"cursor: pointer;",onclick:e=>{console.log("Link clicked:",t.to),e.preventDefault(),P()(t.to);},children:t.children})}export{j as a,h as b,R as c,_ as d,P as e,Q as f,B as g,x as h,M as i,I as j,O as k};//# sourceMappingURL=chunk-SB3OY2QH.mjs.map
2
- //# sourceMappingURL=chunk-SB3OY2QH.mjs.map
1
+ import {a,c}from'./chunk-FJNIW7B2.mjs';import {f}from'./chunk-TIUNOZRI.mjs';import {a as a$1}from'./chunk-RUYGSYEV.mjs';function L(t){if(!t)return {};if(typeof URLSearchParams<"u"){let e=new URLSearchParams(t),r={};return e.forEach((n,o)=>r[o]=n),r}return t.substring(1).split("&").reduce((e,r)=>{let[n,o]=r.split("=");return n&&(e[decodeURIComponent(n)]=decodeURIComponent(o||"")),e},{})}function b(t){return !!(!t||typeof t!="string"||t.length>2048||t.includes("__proto__")||t.includes("constructor")||/^\s*javascript:/i.test(t))}function y(t){let e=[];return t.forEach(r=>{if(!r)return;let{path:n,component:o,children:i,beforeEnter:f}=r.props||{},a={path:n||"/",component:o,beforeEnter:f};if(i){let c=Array.isArray(i)?i:[i];a.children=y(c);}!a.children&&r.children&&r.children.length>0&&(a.children=y(r.children)),e.push(a);}),e}function D(t,e){for(let r of t){let n=r.path,o=T(n,e);if(o)return [{route:r,params:o.params,pathname:o.path}]}return null}function T(t,e){let r=t.split("/").filter(Boolean),n=e.split("/").filter(Boolean);if(r.length!==n.length)return null;let o={};for(let i=0;i<r.length;i++){let f=r[i],a=n[i];if(f.startsWith(":")){let c=f.slice(1);o[c]=a;}else if(f!==a)return null}return {params:o,path:e}}var w=new f(null),m=new f(0),U=()=>({pathname:"/",search:"",hash:"",query:{}}),E=()=>{if(typeof window>"u")return U();let t=window.location.pathname;return (!t||t==="srcdoc"||t==="/srcdoc")&&(t="/"),{pathname:t,search:window.location.search,hash:window.location.hash,query:L(window.location.search)}},l=null,p=null,F=false;function j(){l=null,p=null;}function h(){if(l&&p)return [l,p];l=a(E());let t=e=>{l&&(l.pathname=e.pathname,l.search=e.search,l.hash=e.hash,l.query=e.query);};return p=e=>{if(typeof window>"u")return;if(b(e)){console.error("[Flexium Router] Blocked navigation to unsafe path:",e);return}try{window.history.pushState({},"",e);}catch{}let r={pathname:e.split("?")[0].split("#")[0],search:e.includes("?")?"?"+e.split("?")[1].split("#")[0]:"",hash:e.includes("#")?"#"+e.split("#")[1]:"",query:L(e.includes("?")?"?"+e.split("?")[1].split("#")[0]:"")};t(r);},typeof window<"u"&&!F&&(window.addEventListener("popstate",()=>{t(E());}),F=true),[l,p]}function R(){let[t]=c(w);if(!t)throw new Error("useRouter() must be called within a <Routes> component");return t}function _(){let[,t]=h();return t}function P(){return p||h(),p}function Q(){return R().params}function B(){let[t]=h();return t.query}function x(t){return null}function A(t){return t&&typeof t=="object"&&("type"in t||Array.isArray(t))}function M(t){let[e,r]=h(),n=Array.isArray(t.children)?t.children:[t.children],o=n.filter(s=>A(s)&&s.type===x),i=n.filter(s=>!A(s)||s.type!==x),f=y(o),a=e.pathname,c=D(f,a)||[],S=c.length>0?c[c.length-1].params:{},q={location:e,navigate:r,matches:c,params:S},v=null;if(c.length>0){let s=c[0],k=s.route.component,g=a;s.route.beforeEnter?s.route.beforeEnter(s.params)!==false&&(v=a$1(m.Provider,{value:1,key:g,children:a$1(k,{params:s.params,key:g})})):v=a$1(m.Provider,{value:1,key:g,children:a$1(k,{params:s.params,key:g})});}return a$1(w.Provider,{value:q,children:[...i,v]})}function I(){let t=R(),[e]=c(m),r=e??0,[n]=c(()=>t.matches);if(r>=n.length)return null;let o=n[r],i=o.route.component;return o.route.beforeEnter&&o.route.beforeEnter(o.params)===false?null:a$1(m.Provider,{value:r+1,children:a$1(i,{params:o.params})})}function O(t){return a$1("a",{href:t.to,class:t.class||t.className,style:t.style?t.style+"; cursor: pointer;":"cursor: pointer;",onclick:e=>{console.log("Link clicked:",t.to),e.preventDefault(),P()(t.to);},children:t.children})}export{j as a,h as b,R as c,_ as d,P as e,Q as f,B as g,x as h,M as i,I as j,O as k};//# sourceMappingURL=chunk-OAATT6JA.mjs.map
2
+ //# sourceMappingURL=chunk-OAATT6JA.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/router/utils.ts","../src/router/router.ts","../src/router/dom/Route.tsx","../src/router/dom/Routes.tsx","../src/router/dom/Outlet.tsx","../src/router/dom/Link.tsx"],"names":["parseQuery","search","params","result","value","key","accumulator","part","isUnsafePath","path","createRoutesFromChildren","children","routes","child","component","subChildren","beforeEnter","route","nestedChildren","matchRoutes","locationPathname","routePath","matchResult","matchPath","locationPath","routeSegments","locationSegments","routeSegment","locationSegment","RouterCtx","Context","RouteDepthCtx","getDefaultLocation","getCurrentLocation","pathname","globalLocation","globalNavigate","popstateListenerAttached","resetRouter","useLocation","reactive","updateLocation","newLocation","useRouter","routerContext","use","useNavigate","navigate","getNavigate","useParams","useQuery","location","Route","_props","isFNode","node","Routes","props","currentLocation","childrenList","routeNodes","otherChildren","routeDefinitions","currentPath","matches","matchedContent","rootMatch","Component","routeKey","jsx","Outlet","depthValue","depth","match","Link","event"],"mappings":"wHAGA,SAASA,CAAAA,CAAWC,CAAAA,CAAwC,CAC1D,GAAI,CAACA,EAAQ,OAAO,EAAC,CACrB,GAAI,OAAO,eAAA,CAAoB,IAAa,CAC1C,IAAMC,CAAAA,CAAS,IAAI,eAAA,CAAgBD,CAAM,EACnCE,CAAAA,CAAiC,EAAC,CACxC,OAAAD,CAAAA,CAAO,OAAA,CAAQ,CAACE,CAAAA,CAAOC,CAAAA,GAAQF,CAAAA,CAAOE,CAAG,CAAA,CAAID,CAAK,EAC3CD,CACT,CACA,OAAOF,CAAAA,CACJ,SAAA,CAAU,CAAC,EACX,KAAA,CAAM,GAAG,CAAA,CACT,MAAA,CAAO,CAACK,CAAAA,CAAaC,CAAAA,GAAS,CAC7B,GAAM,CAACF,CAAAA,CAAKD,CAAK,CAAA,CAAIG,CAAAA,CAAK,MAAM,GAAG,CAAA,CACnC,OAAIF,CAAAA,GAAKC,CAAAA,CAAY,kBAAA,CAAmBD,CAAG,CAAC,CAAA,CAAI,kBAAA,CAAmBD,CAAAA,EAAS,EAAE,CAAA,CAAA,CACvEE,CACT,CAAA,CAAG,EAA4B,CACnC,CAEA,SAASE,CAAAA,CAAaC,CAAAA,CAAuB,CAO3C,OALI,CAAA,EAAA,CAACA,CAAAA,EAAQ,OAAOA,CAAAA,EAAS,UAEzBA,CAAAA,CAAK,MAAA,CAAS,IAAA,EACdA,CAAAA,CAAK,QAAA,CAAS,WAAW,GAAKA,CAAAA,CAAK,QAAA,CAAS,aAAa,CAAA,EAEzD,kBAAA,CAAmB,IAAA,CAAKA,CAAI,CAAA,CAElC,CAGA,SAASC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AACP,CAAO,CAAA,CAAInB,CAAAA,CAAI,IAAMD,CAAAA,CAAc,OAAO,CAAA,CAEjD,GAAI4B,CAAAA,EAASR,CAAAA,CAAQ,MAAA,CAAQ,OAAO,IAAA,CAEpC,IAAMS,CAAAA,CAAQT,CAAAA,CAAQQ,CAAK,CAAA,CACrBL,CAAAA,CAAYM,CAAAA,CAAM,MAAM,SAAA,CAG9B,OAAIA,CAAAA,CAAM,KAAA,CAAM,WAAA,EACRA,CAAAA,CAAM,MAAM,WAAA,CAAYA,CAAAA,CAAM,MAAM,CAAA,GAAM,KAAA,CAAc,IAAA,CAIzDJ,GAAAA,CAAEtC,CAAAA,CAAc,QAAA,CAAU,CAC7B,KAAA,CAAOyC,CAAAA,CAAQ,CAAA,CACf,QAAA,CAAUH,IAAEF,CAAAA,CAAW,CAAE,MAAA,CAAQM,CAAAA,CAAM,MAAO,CAAC,CACnD,CAAC,CACL,CCnBO,SAASC,CAAAA,CAAKjB,CAAAA,CAAkB,CACnC,OAAOY,GAAAA,CAAE,GAAA,CAAK,CACV,IAAA,CAAMZ,CAAAA,CAAM,EAAA,CACZ,KAAA,CAAOA,CAAAA,CAAM,KAAA,EAASA,CAAAA,CAAM,SAAA,CAC5B,KAAA,CAAOA,CAAAA,CAAM,MAAQA,CAAAA,CAAM,KAAA,CAAQ,oBAAA,CAAuB,kBAAA,CAC1D,OAAA,CAAUkB,CAAAA,EAAiB,CACvB,OAAA,CAAQ,GAAA,CAAI,eAAA,CAAiBlB,CAAAA,CAAM,EAAE,CAAA,CACrCkB,EAAM,cAAA,EAAe,CAErB3B,CAAAA,EAAY,CAAES,CAAAA,CAAM,EAAE,EAC1B,CAAA,CACA,QAAA,CAAUA,CAAAA,CAAM,QACpB,CAAC,CACL","file":"chunk-SB3OY2QH.mjs","sourcesContent":["import { RouteDefinition, RouteMatch } from './types'\n\n// Simple query parser (native URLSearchParams fallback) - internal use only\nfunction parseQuery(search: string): Record<string, string> {\n if (!search) return {}\n if (typeof URLSearchParams !== 'undefined') {\n const params = new URLSearchParams(search)\n const result: Record<string, string> = {}\n params.forEach((value, key) => result[key] = value)\n return result\n }\n return search\n .substring(1)\n .split('&')\n .reduce((accumulator, part) => {\n const [key, value] = part.split('=')\n if (key) accumulator[decodeURIComponent(key)] = decodeURIComponent(value || '')\n return accumulator\n }, {} as Record<string, string>)\n}\n\nfunction isUnsafePath(path: string): boolean {\n // Handle undefined or null path\n if (!path || typeof path !== 'string') return true\n // Prevent prototype pollution or massive strings\n if (path.length > 2048) return true\n if (path.includes('__proto__') || path.includes('constructor')) return true\n // Basic XSS check for javascript: protocol\n if (/^\\s*javascript:/i.test(path)) return true\n return false\n}\n\n// Convert children FNodes to RouteDefinitions - internal use only\nfunction createRoutesFromChildren(children: any[]): RouteDefinition[] {\n const routes: RouteDefinition[] = []\n\n children.forEach(child => {\n if (!child) return\n\n // Assuming child is an FNode-like object (config)\n // In Flexium, Route component returns null, but 'createNode' isn't called here.\n // We are traversing the props passed to Router.\n\n const { path, component, children: subChildren, beforeEnter } = child.props || {}\n\n const route: RouteDefinition = {\n path: path || '/',\n component: component,\n beforeEnter\n }\n\n if (subChildren) {\n // If subChildren is array\n const nestedChildren = Array.isArray(subChildren) ? subChildren : [subChildren]\n // We expect the children of a Route to be other Routes\n // However, the 'children' prop in JSX might be the Route components themselves.\n route.children = createRoutesFromChildren(nestedChildren)\n }\n\n // Also check child.children if props.children is empty (direct FNode structure)\n if (!route.children && child.children && child.children.length > 0) {\n route.children = createRoutesFromChildren(child.children)\n }\n\n routes.push(route)\n })\n return routes\n}\n\n// Simple Matcher - internal use only\nfunction matchRoutes(routes: RouteDefinition[], locationPathname: string): RouteMatch[] | null {\n // We want to find the best matching branch\n\n for (const route of routes) {\n // 1. Match current segment\n // Simple exact match or parameter match logic needed?\n // Let's implement simple param matching: /user/:id\n\n const routePath = route.path\n\n const matchResult = matchPath(routePath, locationPathname)\n if (matchResult) {\n return [{ route, params: matchResult.params, pathname: matchResult.path }]\n }\n }\n return null\n}\n\nfunction matchPath(routePath: string, locationPath: string) {\n // 1. Split into segments\n const routeSegments = routePath.split('/').filter(Boolean)\n const locationSegments = locationPath.split('/').filter(Boolean)\n\n if (routeSegments.length !== locationSegments.length) return null\n\n const params: Record<string, string> = {}\n\n for (let i = 0; i < routeSegments.length; i++) {\n const routeSegment = routeSegments[i]\n const locationSegment = locationSegments[i]\n\n if (routeSegment.startsWith(':')) {\n const key = routeSegment.slice(1)\n params[key] = locationSegment\n } else if (routeSegment !== locationSegment) {\n return null\n }\n }\n\n return { params, path: locationPath }\n}\n\n// Export only what's needed by other router files\nexport { parseQuery, isUnsafePath, createRoutesFromChildren, matchRoutes }\n","import { reactive } from '../core/reactive'\nimport { Context } from '../core/context'\nimport { use } from '../core/use'\nimport type { Location, RouterContext } from './types'\nimport { parseQuery, isUnsafePath } from './utils'\n\n// Contexts\nexport const RouterCtx = new Context<RouterContext>(null as any)\nexport const RouteDepthCtx = new Context<number>(0)\n\n// Helper functions\nconst getDefaultLocation = (): Location => ({\n pathname: '/',\n search: '',\n hash: '',\n query: {},\n})\n\nconst getCurrentLocation = (): Location => {\n if (typeof window === 'undefined') {\n return getDefaultLocation()\n }\n\n // Handle srcdoc iframe - pathname may be empty or 'srcdoc'\n let pathname = window.location.pathname\n if (!pathname || pathname === 'srcdoc' || pathname === '/srcdoc') {\n pathname = '/'\n }\n\n return {\n pathname,\n search: window.location.search,\n hash: window.location.hash,\n query: parseQuery(window.location.search),\n }\n}\n\n// Global singleton location state\nlet globalLocation: Location | null = null\nlet globalNavigate: ((path: string) => void) | null = null\nlet popstateListenerAttached = false\n\n// Reset router state - used when app is re-rendered (e.g., srcdoc iframe update)\nexport function resetRouter(): void {\n globalLocation = null\n globalNavigate = null\n // Note: we don't reset popstateListenerAttached since the listener persists\n}\n\n// Create location state and navigation (singleton pattern)\nexport function useLocation(): [Location, (path: string) => void] {\n // Return existing singleton if already created\n if (globalLocation && globalNavigate) {\n return [globalLocation, globalNavigate]\n }\n\n // Create a reactive location object (only once)\n globalLocation = reactive<Location>(getCurrentLocation())\n\n const updateLocation = (newLocation: Location) => {\n if (!globalLocation) return\n globalLocation.pathname = newLocation.pathname\n globalLocation.search = newLocation.search\n globalLocation.hash = newLocation.hash\n globalLocation.query = newLocation.query\n }\n\n globalNavigate = (path: string) => {\n if (typeof window === 'undefined') return\n if (isUnsafePath(path)) {\n console.error('[Flexium Router] Blocked navigation to unsafe path:', path)\n return\n }\n\n // Try to update browser history, but continue even if it fails (e.g., in srcdoc iframe)\n try {\n window.history.pushState({}, '', path)\n } catch {\n // SecurityError in srcdoc iframe - ignore but continue with internal state update\n }\n\n // Always update internal location state for SPA navigation\n const newLocation = {\n pathname: path.split('?')[0].split('#')[0],\n search: path.includes('?') ? '?' + path.split('?')[1].split('#')[0] : '',\n hash: path.includes('#') ? '#' + path.split('#')[1] : '',\n query: parseQuery(path.includes('?') ? '?' + path.split('?')[1].split('#')[0] : '')\n }\n updateLocation(newLocation)\n }\n\n // Listen to popstate (only once)\n if (typeof window !== 'undefined' && !popstateListenerAttached) {\n window.addEventListener('popstate', () => {\n updateLocation(getCurrentLocation())\n })\n popstateListenerAttached = true\n }\n\n return [globalLocation, globalNavigate]\n}\n\n// Router hook - returns full router context\nexport function useRouter(): RouterContext {\n const [routerContext] = use(RouterCtx)\n if (!routerContext) {\n throw new Error('useRouter() must be called within a <Routes> component')\n }\n return routerContext\n}\n\n// Navigate hook - returns navigate function\nexport function useNavigate(): (path: string) => void {\n const [, navigate] = useLocation()\n return navigate\n}\n\n// Get navigate function directly (for use in event handlers to avoid stale closures)\nexport function getNavigate(): (path: string) => void {\n if (!globalNavigate) {\n useLocation() // Initialize if needed\n }\n return globalNavigate!\n}\n\n// Params hook - returns route params\nexport function useParams<T extends Record<string, string> = Record<string, string>>(): T {\n const router = useRouter()\n return router.params as T\n}\n\n// Query hook - returns query params\nexport function useQuery<T extends Record<string, string> = Record<string, string>>(): T {\n const [location] = useLocation()\n return location.query as T\n}\n","import type { RouteProps } from '../types'\n\nexport function Route(_props: RouteProps) {\n return null\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { FNode, FNodeChild } from '../../dom/types'\nimport { RouterCtx, RouteDepthCtx, useLocation } from '../router'\nimport { createRoutesFromChildren, matchRoutes } from '../utils'\nimport { Route } from './Route'\n\nfunction isFNode(node: any): node is FNode {\n return node && typeof node === 'object' && ('type' in node || Array.isArray(node))\n}\n\nexport function Routes(props: { children: FNodeChild }) {\n const [currentLocation, navigate] = useLocation()\n\n // Parse children to find <Route> definitions and other content\n let childrenList: any[] = Array.isArray(props.children) ? props.children : [props.children]\n\n // Separate routes from other children (like Nav components)\n const routeNodes = childrenList.filter(child => isFNode(child) && child.type === Route)\n const otherChildren = childrenList.filter(child => !isFNode(child) || child.type !== Route)\n\n // Create route definitions\n const routeDefinitions = createRoutesFromChildren(routeNodes)\n\n // DIRECT access to currentLocation.pathname\n // This should trigger reactive tracking in the component's effect context\n const currentPath = currentLocation.pathname\n const matches = matchRoutes(routeDefinitions, currentPath) || []\n const params = matches.length > 0 ? matches[matches.length - 1].params : {}\n\n const routerContext = {\n location: currentLocation,\n navigate,\n matches: matches,\n params: params\n }\n\n // Render matched component\n let matchedContent: FNodeChild = null\n\n if (matches.length > 0) {\n const rootMatch = matches[0]\n const Component = rootMatch.route.component\n\n // Use pathname as key to force re-mount on route change\n const routeKey = currentPath\n\n // Guard Check\n if (rootMatch.route.beforeEnter) {\n const result = rootMatch.route.beforeEnter(rootMatch.params)\n if (result !== false) {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n } else {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n }\n\n return f(RouterCtx.Provider, {\n value: routerContext,\n children: [...otherChildren, matchedContent]\n })\n}\n","import { use } from '../../core/use'\nimport { jsx as f } from '../../jsx-runtime'\nimport { RouteDepthCtx, useRouter } from '../router'\n\nexport function Outlet() {\n const routerContext = useRouter()\n const [depthValue] = use(RouteDepthCtx)\n const depth = depthValue ?? 0\n\n const [matches] = use(() => routerContext.matches)\n\n if (depth >= matches.length) return null\n\n const match = matches[depth]\n const Component = match.route.component\n\n // Guard\n if (match.route.beforeEnter) {\n if (match.route.beforeEnter(match.params) === false) return null\n }\n\n // Render next level\n return f(RouteDepthCtx.Provider, {\n value: depth + 1,\n children: f(Component, { params: match.params })\n })\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { LinkProps } from '../types'\n\n// Import the navigate function getter, not the function itself\n// This ensures we always use the current navigate implementation\nimport { getNavigate } from '../router'\n\nexport function Link(props: LinkProps) {\n return f('a', {\n href: props.to,\n class: props.class || props.className,\n style: props.style ? props.style + '; cursor: pointer;' : 'cursor: pointer;',\n onclick: (event: Event) => {\n console.log('Link clicked:', props.to)\n event.preventDefault()\n // Get current navigate function at click time\n getNavigate()(props.to)\n },\n children: props.children\n })\n}\n"]}
1
+ {"version":3,"sources":["../src/router/utils.ts","../src/router/router.ts","../src/router/dom/Route.tsx","../src/router/dom/Routes.tsx","../src/router/dom/Outlet.tsx","../src/router/dom/Link.tsx"],"names":["parseQuery","search","params","result","value","key","accumulator","part","isUnsafePath","path","createRoutesFromChildren","children","routes","child","component","subChildren","beforeEnter","route","nestedChildren","matchRoutes","locationPathname","routePath","matchResult","matchPath","locationPath","routeSegments","locationSegments","routeSegment","locationSegment","RouterCtx","Context","RouteDepthCtx","getDefaultLocation","getCurrentLocation","pathname","globalLocation","globalNavigate","popstateListenerAttached","resetRouter","useLocation","reactive","updateLocation","newLocation","useRouter","routerContext","use","useNavigate","navigate","getNavigate","useParams","useQuery","location","Route","_props","isFNode","node","Routes","props","currentLocation","childrenList","routeNodes","otherChildren","routeDefinitions","currentPath","matches","matchedContent","rootMatch","Component","routeKey","jsx","Outlet","depthValue","depth","match","Link","event"],"mappings":"wHAGA,SAASA,CAAAA,CAAWC,CAAAA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AAM,WAAA,EACRA,CAAAA,CAAM,MAAM,WAAA,CAAYA,CAAAA,CAAM,MAAM,CAAA,GAAM,KAAA,CAAc,IAAA,CAIzDJ,GAAAA,CAAEtC,CAAAA,CAAc,QAAA,CAAU,CAC7B,KAAA,CAAOyC,CAAAA,CAAQ,CAAA,CACf,QAAA,CAAUH,IAAEF,CAAAA,CAAW,CAAE,MAAA,CAAQM,CAAAA,CAAM,MAAO,CAAC,CACnD,CAAC,CACL,CCnBO,SAASC,CAAAA,CAAKjB,CAAAA,CAAkB,CACnC,OAAOY,GAAAA,CAAE,GAAA,CAAK,CACV,IAAA,CAAMZ,CAAAA,CAAM,EAAA,CACZ,KAAA,CAAOA,CAAAA,CAAM,KAAA,EAASA,CAAAA,CAAM,SAAA,CAC5B,KAAA,CAAOA,CAAAA,CAAM,MAAQA,CAAAA,CAAM,KAAA,CAAQ,oBAAA,CAAuB,kBAAA,CAC1D,OAAA,CAAUkB,CAAAA,EAAiB,CACvB,OAAA,CAAQ,GAAA,CAAI,eAAA,CAAiBlB,CAAAA,CAAM,EAAE,CAAA,CACrCkB,EAAM,cAAA,EAAe,CAErB3B,CAAAA,EAAY,CAAES,CAAAA,CAAM,EAAE,EAC1B,CAAA,CACA,QAAA,CAAUA,CAAAA,CAAM,QACpB,CAAC,CACL","file":"chunk-OAATT6JA.mjs","sourcesContent":["import { RouteDefinition, RouteMatch } from './types'\n\n// Simple query parser (native URLSearchParams fallback) - internal use only\nfunction parseQuery(search: string): Record<string, string> {\n if (!search) return {}\n if (typeof URLSearchParams !== 'undefined') {\n const params = new URLSearchParams(search)\n const result: Record<string, string> = {}\n params.forEach((value, key) => result[key] = value)\n return result\n }\n return search\n .substring(1)\n .split('&')\n .reduce((accumulator, part) => {\n const [key, value] = part.split('=')\n if (key) accumulator[decodeURIComponent(key)] = decodeURIComponent(value || '')\n return accumulator\n }, {} as Record<string, string>)\n}\n\nfunction isUnsafePath(path: string): boolean {\n // Handle undefined or null path\n if (!path || typeof path !== 'string') return true\n // Prevent prototype pollution or massive strings\n if (path.length > 2048) return true\n if (path.includes('__proto__') || path.includes('constructor')) return true\n // Basic XSS check for javascript: protocol\n if (/^\\s*javascript:/i.test(path)) return true\n return false\n}\n\n// Convert children FNodes to RouteDefinitions - internal use only\nfunction createRoutesFromChildren(children: any[]): RouteDefinition[] {\n const routes: RouteDefinition[] = []\n\n children.forEach(child => {\n if (!child) return\n\n // Assuming child is an FNode-like object (config)\n // In Flexium, Route component returns null, but 'createNode' isn't called here.\n // We are traversing the props passed to Router.\n\n const { path, component, children: subChildren, beforeEnter } = child.props || {}\n\n const route: RouteDefinition = {\n path: path || '/',\n component: component,\n beforeEnter\n }\n\n if (subChildren) {\n // If subChildren is array\n const nestedChildren = Array.isArray(subChildren) ? subChildren : [subChildren]\n // We expect the children of a Route to be other Routes\n // However, the 'children' prop in JSX might be the Route components themselves.\n route.children = createRoutesFromChildren(nestedChildren)\n }\n\n // Also check child.children if props.children is empty (direct FNode structure)\n if (!route.children && child.children && child.children.length > 0) {\n route.children = createRoutesFromChildren(child.children)\n }\n\n routes.push(route)\n })\n return routes\n}\n\n// Simple Matcher - internal use only\nfunction matchRoutes(routes: RouteDefinition[], locationPathname: string): RouteMatch[] | null {\n // We want to find the best matching branch\n\n for (const route of routes) {\n // 1. Match current segment\n // Simple exact match or parameter match logic needed?\n // Let's implement simple param matching: /user/:id\n\n const routePath = route.path\n\n const matchResult = matchPath(routePath, locationPathname)\n if (matchResult) {\n return [{ route, params: matchResult.params, pathname: matchResult.path }]\n }\n }\n return null\n}\n\nfunction matchPath(routePath: string, locationPath: string) {\n // 1. Split into segments\n const routeSegments = routePath.split('/').filter(Boolean)\n const locationSegments = locationPath.split('/').filter(Boolean)\n\n if (routeSegments.length !== locationSegments.length) return null\n\n const params: Record<string, string> = {}\n\n for (let i = 0; i < routeSegments.length; i++) {\n const routeSegment = routeSegments[i]\n const locationSegment = locationSegments[i]\n\n if (routeSegment.startsWith(':')) {\n const key = routeSegment.slice(1)\n params[key] = locationSegment\n } else if (routeSegment !== locationSegment) {\n return null\n }\n }\n\n return { params, path: locationPath }\n}\n\n// Export only what's needed by other router files\nexport { parseQuery, isUnsafePath, createRoutesFromChildren, matchRoutes }\n","import { reactive } from '../core/reactive'\nimport { Context } from '../core/context'\nimport { use } from '../core/use'\nimport type { Location, RouterContext } from './types'\nimport { parseQuery, isUnsafePath } from './utils'\n\n// Contexts\nexport const RouterCtx = new Context<RouterContext>(null as any)\nexport const RouteDepthCtx = new Context<number>(0)\n\n// Helper functions\nconst getDefaultLocation = (): Location => ({\n pathname: '/',\n search: '',\n hash: '',\n query: {},\n})\n\nconst getCurrentLocation = (): Location => {\n if (typeof window === 'undefined') {\n return getDefaultLocation()\n }\n\n // Handle srcdoc iframe - pathname may be empty or 'srcdoc'\n let pathname = window.location.pathname\n if (!pathname || pathname === 'srcdoc' || pathname === '/srcdoc') {\n pathname = '/'\n }\n\n return {\n pathname,\n search: window.location.search,\n hash: window.location.hash,\n query: parseQuery(window.location.search),\n }\n}\n\n// Global singleton location state\nlet globalLocation: Location | null = null\nlet globalNavigate: ((path: string) => void) | null = null\nlet popstateListenerAttached = false\n\n// Reset router state - used when app is re-rendered (e.g., srcdoc iframe update)\nexport function resetRouter(): void {\n globalLocation = null\n globalNavigate = null\n // Note: we don't reset popstateListenerAttached since the listener persists\n}\n\n// Create location state and navigation (singleton pattern)\nexport function useLocation(): [Location, (path: string) => void] {\n // Return existing singleton if already created\n if (globalLocation && globalNavigate) {\n return [globalLocation, globalNavigate]\n }\n\n // Create a reactive location object (only once)\n globalLocation = reactive<Location>(getCurrentLocation())\n\n const updateLocation = (newLocation: Location) => {\n if (!globalLocation) return\n globalLocation.pathname = newLocation.pathname\n globalLocation.search = newLocation.search\n globalLocation.hash = newLocation.hash\n globalLocation.query = newLocation.query\n }\n\n globalNavigate = (path: string) => {\n if (typeof window === 'undefined') return\n if (isUnsafePath(path)) {\n console.error('[Flexium Router] Blocked navigation to unsafe path:', path)\n return\n }\n\n // Try to update browser history, but continue even if it fails (e.g., in srcdoc iframe)\n try {\n window.history.pushState({}, '', path)\n } catch {\n // SecurityError in srcdoc iframe - ignore but continue with internal state update\n }\n\n // Always update internal location state for SPA navigation\n const newLocation = {\n pathname: path.split('?')[0].split('#')[0],\n search: path.includes('?') ? '?' + path.split('?')[1].split('#')[0] : '',\n hash: path.includes('#') ? '#' + path.split('#')[1] : '',\n query: parseQuery(path.includes('?') ? '?' + path.split('?')[1].split('#')[0] : '')\n }\n updateLocation(newLocation)\n }\n\n // Listen to popstate (only once)\n if (typeof window !== 'undefined' && !popstateListenerAttached) {\n window.addEventListener('popstate', () => {\n updateLocation(getCurrentLocation())\n })\n popstateListenerAttached = true\n }\n\n return [globalLocation, globalNavigate]\n}\n\n// Router hook - returns full router context\nexport function useRouter(): RouterContext {\n const [routerContext] = use(RouterCtx)\n if (!routerContext) {\n throw new Error('useRouter() must be called within a <Routes> component')\n }\n return routerContext\n}\n\n// Navigate hook - returns navigate function\nexport function useNavigate(): (path: string) => void {\n const [, navigate] = useLocation()\n return navigate\n}\n\n// Get navigate function directly (for use in event handlers to avoid stale closures)\nexport function getNavigate(): (path: string) => void {\n if (!globalNavigate) {\n useLocation() // Initialize if needed\n }\n return globalNavigate!\n}\n\n// Params hook - returns route params\nexport function useParams<T extends Record<string, string> = Record<string, string>>(): T {\n const router = useRouter()\n return router.params as T\n}\n\n// Query hook - returns query params\nexport function useQuery<T extends Record<string, string> = Record<string, string>>(): T {\n const [location] = useLocation()\n return location.query as T\n}\n","import type { RouteProps } from '../types'\n\nexport function Route(_props: RouteProps) {\n return null\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { FNode, FNodeChild } from '../../dom/types'\nimport { RouterCtx, RouteDepthCtx, useLocation } from '../router'\nimport { createRoutesFromChildren, matchRoutes } from '../utils'\nimport { Route } from './Route'\n\nfunction isFNode(node: any): node is FNode {\n return node && typeof node === 'object' && ('type' in node || Array.isArray(node))\n}\n\nexport function Routes(props: { children: FNodeChild }) {\n const [currentLocation, navigate] = useLocation()\n\n // Parse children to find <Route> definitions and other content\n let childrenList: any[] = Array.isArray(props.children) ? props.children : [props.children]\n\n // Separate routes from other children (like Nav components)\n const routeNodes = childrenList.filter(child => isFNode(child) && child.type === Route)\n const otherChildren = childrenList.filter(child => !isFNode(child) || child.type !== Route)\n\n // Create route definitions\n const routeDefinitions = createRoutesFromChildren(routeNodes)\n\n // DIRECT access to currentLocation.pathname\n // This should trigger reactive tracking in the component's effect context\n const currentPath = currentLocation.pathname\n const matches = matchRoutes(routeDefinitions, currentPath) || []\n const params = matches.length > 0 ? matches[matches.length - 1].params : {}\n\n const routerContext = {\n location: currentLocation,\n navigate,\n matches: matches,\n params: params\n }\n\n // Render matched component\n let matchedContent: FNodeChild = null\n\n if (matches.length > 0) {\n const rootMatch = matches[0]\n const Component = rootMatch.route.component\n\n // Use pathname as key to force re-mount on route change\n const routeKey = currentPath\n\n // Guard Check\n if (rootMatch.route.beforeEnter) {\n const result = rootMatch.route.beforeEnter(rootMatch.params)\n if (result !== false) {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n } else {\n matchedContent = f(RouteDepthCtx.Provider, {\n value: 1,\n key: routeKey,\n children: f(Component, { params: rootMatch.params, key: routeKey })\n })\n }\n }\n\n return f(RouterCtx.Provider, {\n value: routerContext,\n children: [...otherChildren, matchedContent]\n })\n}\n","import { use } from '../../core/use'\nimport { jsx as f } from '../../jsx-runtime'\nimport { RouteDepthCtx, useRouter } from '../router'\n\nexport function Outlet() {\n const routerContext = useRouter()\n const [depthValue] = use(RouteDepthCtx)\n const depth = depthValue ?? 0\n\n const [matches] = use(() => routerContext.matches)\n\n if (depth >= matches.length) return null\n\n const match = matches[depth]\n const Component = match.route.component\n\n // Guard\n if (match.route.beforeEnter) {\n if (match.route.beforeEnter(match.params) === false) return null\n }\n\n // Render next level\n return f(RouteDepthCtx.Provider, {\n value: depth + 1,\n children: f(Component, { params: match.params })\n })\n}\n","import { jsx as f } from '../../jsx-runtime'\nimport type { LinkProps } from '../types'\n\n// Import the navigate function getter, not the function itself\n// This ensures we always use the current navigate implementation\nimport { getNavigate } from '../router'\n\nexport function Link(props: LinkProps) {\n return f('a', {\n href: props.to,\n class: props.class || props.className,\n style: props.style ? props.style + '; cursor: pointer;' : 'cursor: pointer;',\n onclick: (event: Event) => {\n console.log('Link clicked:', props.to)\n event.preventDefault()\n // Get current navigate function at click time\n getNavigate()(props.to)\n },\n children: props.children\n })\n}\n"]}
@@ -0,0 +1,2 @@
1
+ 'use strict';var r=null;function l(n,e){let t=r;r=n,n.hookIndex=0;try{return e()}finally{r=t;}}function c(n){if(!r)return n();let e=r,{hooks:t,hookIndex:s}=e;if(s<t.length)return e.hookIndex++,t[s];let i=n();return t.push(i),e.hookIndex++,i}var a=class{constructor(){this._useableTag=true;}getActions(){}};function p(n){return n!==null&&typeof n=="object"&&"_useableTag"in n&&n._useableTag===true}var o=new Map;function y(){o.clear();}var u=class extends a{constructor(e){super(),this.id=Symbol("context"),this.defaultValue=e,this.Provider=t=>t.children,this.Provider._contextId=this.id;}getInitial(){return o.has(this.id)?o.get(this.id):this.defaultValue}subscribe(e,t){return ()=>{}}};function f(n){return n.getInitial()}function T(n,e){let t=o.get(n);return o.set(n,e),t}function b(n,e){e===void 0?o.delete(n):o.set(n,e);}exports.a=l;exports.b=c;exports.c=a;exports.d=p;exports.e=y;exports.f=u;exports.g=f;exports.h=T;exports.i=b;//# sourceMappingURL=chunk-OU6XJZ76.js.map
2
+ //# sourceMappingURL=chunk-OU6XJZ76.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/hook.ts","../src/core/useable.ts","../src/core/context.ts"],"names":["currentComponent","runWithComponent","component","fn","prev","hook","factory","instance","hooks","hookIndex","value","Useable","isUseable","contextMap","resetContext","Context","defaultValue","props","_params","_callback","getContextValue","ctx","pushContext","id","popContext","prevValue"],"mappings":"aAMA,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YC,CAAAA,EAAuCA,EAAM,QAAA,CACzD,IAAA,CAAK,SAAiB,UAAA,CAAa,IAAA,CAAK,GAC/C,CAKA,UAAA,EAAgB,CACd,OAAOJ,CAAAA,CAAW,GAAA,CAAI,KAAK,EAAE,CAAA,CAAIA,EAAW,GAAA,CAAI,IAAA,CAAK,EAAE,CAAA,CAAI,IAAA,CAAK,YAClE,CAMA,SAAA,CAAUK,CAAAA,CAAoBC,EAA2C,CAGvE,OAAO,IAAM,CAAE,CACjB,CACF,EAGO,SAASC,CAAAA,CAAmBC,CAAAA,CAAoB,CACrD,OAAOA,EAAI,UAAA,EACb,CAGO,SAASC,CAAAA,CAAYC,EAAYb,CAAAA,CAAY,CAClD,IAAMN,CAAAA,CAAOS,CAAAA,CAAW,GAAA,CAAIU,CAAE,CAAA,CAC9B,OAAAV,EAAW,GAAA,CAAIU,CAAAA,CAAIb,CAAK,CAAA,CACjBN,CACT,CAGO,SAASoB,CAAAA,CAAWD,CAAAA,CAAYE,EAAgB,CACjDA,CAAAA,GAAc,MAAA,CAChBZ,CAAAA,CAAW,MAAA,CAAOU,CAAE,EAEpBV,CAAAA,CAAW,GAAA,CAAIU,CAAAA,CAAIE,CAAS,EAEhC","file":"chunk-OU6XJZ76.js","sourcesContent":["\nexport interface ComponentInstance {\n hooks: any[]\n hookIndex: number\n}\n\nlet currentComponent: ComponentInstance | null = null\n\nexport function getComponent(): ComponentInstance | null {\n return currentComponent\n}\n\nexport function runWithComponent<T>(component: ComponentInstance, fn: () => T): T {\n const prev = currentComponent\n currentComponent = component\n component.hookIndex = 0\n try {\n return fn()\n } finally {\n currentComponent = prev\n }\n}\n\nexport function hook<T>(factory: () => T): T {\n if (!currentComponent) {\n // Outside component: just run factory\n return factory()\n }\n\n const instance = currentComponent\n const { hooks, hookIndex } = instance\n\n if (hookIndex < hooks.length) {\n // Return existing hook\n instance.hookIndex++\n return hooks[hookIndex] as T\n }\n\n // Create new hook\n const value = factory()\n hooks.push(value)\n instance.hookIndex++\n\n return value\n}\n","/**\n * Useable - Base class for reactive data sources that work with use()\n *\n * Extend this class to create custom data sources (Context, Stream, Shared, etc.)\n *\n * @example\n * ```tsx\n * class MySource<T> extends Useable<T> {\n * getInitial() { return this.initialValue }\n * subscribe(params, callback) {\n * // setup subscription\n * return () => { // cleanup }\n * }\n * }\n *\n * const source = new MySource(...)\n * const [value] = use(source)\n * ```\n *\n * @typeParam T - The value type\n * @typeParam P - The params type for subscribe/send\n * @typeParam Actions - Tuple of additional actions returned by use() after the value\n */\nexport abstract class Useable<T, P = void, Actions extends unknown[] = []> {\n /**\n * Unique identifier for this Useable type\n * Used internally by use() for type checking\n */\n readonly _useableTag = true as const\n\n /**\n * Get the initial/current value synchronously\n * Called when use() first accesses this source\n */\n abstract getInitial(params?: P): T\n\n /**\n * Subscribe to value changes\n * Called by use() to receive updates\n *\n * @param params - Optional parameters for the subscription\n * @param callback - Function called when value changes\n * @returns Cleanup function to unsubscribe\n */\n abstract subscribe(\n params: P | undefined,\n callback: (value: T) => void\n ): () => void\n\n /**\n * Get additional actions to include in the use() tuple\n * Override this to return [action1, action2, ...] that will be appended to [value, ...]\n *\n * @example\n * ```tsx\n * class SendableStream extends Useable<T, P> {\n * getActions() {\n * return [this.send.bind(this)]\n * }\n * }\n *\n * const [value, send] = use(stream)\n * ```\n */\n getActions(): Actions | undefined {\n return undefined\n }\n}\n\n/**\n * Type guard to check if a value is a Useable instance\n */\nexport function isUseable(value: unknown): value is Useable<any, any> {\n return (\n value !== null &&\n typeof value === 'object' &&\n '_useableTag' in value &&\n (value as any)._useableTag === true\n )\n}\n","import { Useable } from './useable'\n\nconst contextMap = new Map<symbol, any>()\n\n// Reset context state - used when app is re-rendered from root\nexport function resetContext(): void {\n contextMap.clear()\n}\n\n/**\n * Context for passing data through the component tree\n *\n * @example\n * ```tsx\n * const ThemeContext = new Context('light')\n *\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <Child />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * function Child() {\n * const [theme] = use(ThemeContext)\n * return <div>{theme}</div>\n * }\n * ```\n */\nexport class Context<T> extends Useable<T> {\n readonly id: symbol\n readonly defaultValue: T\n readonly Provider: (props: { value: T; children: any }) => any\n\n constructor(defaultValue: T) {\n super()\n this.id = Symbol('context')\n this.defaultValue = defaultValue\n this.Provider = (props: { value: T; children: any }) => props.children\n ; (this.Provider as any)._contextId = this.id\n }\n\n /**\n * Get current context value or default\n */\n getInitial(): T {\n return contextMap.has(this.id) ? contextMap.get(this.id) : this.defaultValue\n }\n\n /**\n * Context doesn't have traditional subscriptions\n * Reactivity is handled by component re-rendering\n */\n subscribe(_params: undefined, _callback: (value: T) => void): () => void {\n // Context changes trigger re-render through Provider mechanism\n // No additional subscription needed\n return () => { }\n }\n}\n\n// Internal: get context value (used by use.ts)\nexport function getContextValue<T>(ctx: Context<T>): T {\n return ctx.getInitial()\n}\n\n// Internal helpers for renderer\nexport function pushContext(id: symbol, value: any) {\n const prev = contextMap.get(id)\n contextMap.set(id, value)\n return prev\n}\n\n\nexport function popContext(id: symbol, prevValue: any) {\n if (prevValue === undefined) {\n contextMap.delete(id)\n } else {\n contextMap.set(id, prevValue)\n }\n}\n\nexport function snapshotContext(): Map<symbol, any> {\n return new Map(contextMap)\n}\n\nexport function runWithContext<R>(snapshot: Map<symbol, any>, fn: () => R): R {\n // 1. Save current context\n const prevContext = new Map(contextMap)\n\n // 2. Apply snapshot\n contextMap.clear()\n snapshot.forEach((value, key) => contextMap.set(key, value))\n\n try {\n return fn()\n } finally {\n // 3. Restore previous context\n contextMap.clear()\n prevContext.forEach((value, key) => contextMap.set(key, value))\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import {b}from'./chunk-NRPWBHKP.mjs';import {h,a}from'./chunk-TIUNOZRI.mjs';var d=new WeakMap,l=null;function K(){l=null;}function I(e){e.children.forEach(n=>{I(n);}),e.nodes.forEach(n=>{n.parentNode&&n.parentNode.removeChild(n);}),e.children.clear(),e.parentInstance&&e.parentInstance.children.delete(e);}function S(e,n,a$1){let c=a$1||n,r=f=>{let m={...f.props};return f.children&&f.children.length>0&&(m.children=f.children.length===1?f.children[0]:f.children),m},o=e.key!==void 0;d.has(c)||d.set(c,new Map);let t=d.get(c),i;if(o)i=e.key;else {let f=0,m=e.type.name||"anonymous";t.forEach((b,h)=>{typeof h=="string"&&h.startsWith(`__auto_${m}_`)&&f++;}),i=`__auto_${m}_${f}`;}if(t.has(i)){let f=t.get(i);f.fnode=e;let m=r(e);return f.props=m,f.children.clear(),f.renderFn&&f.renderFn(),f.nodes}let s={hooks:[],hookIndex:0,nodes:[],parent:n,fnode:e,props:r(e),key:i,children:new Set,parentInstance:l||void 0};l&&l.children.add(s),t.set(i,s);let u=true,g=()=>{let f=s.fnode,m=s.props;f.type._contextId!==void 0&&h(f.type._contextId,m.value);let h$1=l;l=s;let C=a(s,()=>f.type(m));if(u){let _=y(C,n);s.nodes=_?Array.isArray(_)?_:[_]:[],s.nodes.forEach(p=>{p.__ownerInstance||(p.__ownerInstance=s);}),u=false;}else {if(s.nodes.length===0){let T=y(C,n);s.nodes=T?Array.isArray(T)?T:[T]:[],l=h$1;return}let p=s.nodes[0].parentNode;if(!p){l=h$1;return}let v=document.createComment("flexium-marker"),L=s.nodes[s.nodes.length-1];L.nextSibling?p.insertBefore(v,L.nextSibling):p.appendChild(v),s.children.clear();let x=document.createElement("div"),M=y(C,x,p),O=M?Array.isArray(M)?M:[M]:[],R=P(s.nodes,O,p,v);p.removeChild(v),s.nodes=R;}l=h$1;};return s.renderFn=g,b(g),s.nodes}function y(e,n,a){let c=a||n;if(e==null||typeof e=="boolean"){let r=document.createTextNode("");return n.appendChild(r),r}if(typeof e=="string"||typeof e=="number"){let r=document.createTextNode(String(e));return n.appendChild(r),r}if(Array.isArray(e)){let r=new Set;d.has(c)&&d.get(c).forEach((s,u)=>r.add(u));let o=[];e.forEach(i=>{let s=y(i,n,a);s&&(Array.isArray(s)?o.push(...s):o.push(s));});let t=new Set;if(d.has(c)&&d.get(c).forEach((s,u)=>t.add(u)),d.has(c)){let i=d.get(c),s=[];r.forEach(u=>{if(!t.has(u)){let g=i.get(u);g&&(I(g),s.push(u));}}),s.forEach(u=>i.delete(u));}return o}if(typeof e=="object"){if(typeof e.type=="string"){let r=document.createElement(e.type);return e.props&&Object.entries(e.props).forEach(([o,t])=>{if(o==="ref")typeof t=="function"?t(r):t&&typeof t=="object"&&"current"in t&&(t.current=r);else if(o.startsWith("on")&&typeof t=="function"){let i=o.slice(2).toLowerCase();r.addEventListener(i,t),r.__eventHandlers||(r.__eventHandlers={}),r.__eventHandlers[i]=t;}else o!=="ref"&&D(r,o,t);}),e.children&&e.children.length>0&&e.children.forEach(o=>{y(o,r);}),n.appendChild(r),r}if(typeof e.type=="function")return S(e,n,a)}return null}function D(e,n,a){a==null?e.removeAttribute(n):n==="style"&&typeof a=="object"?Object.assign(e.style,a):n==="class"?e.className=String(a):n in e&&typeof e[n]!="function"?e[n]=a:e.setAttribute(n,String(a));}function j(e,n){return e.nodeType!==n.nodeType?false:e.nodeType===Node.ELEMENT_NODE&&n.nodeType===Node.ELEMENT_NODE?e.tagName===n.tagName:true}function k(e,n){Array.from(e.attributes).forEach(t=>{n.hasAttribute(t.name)||e.removeAttribute(t.name);}),Array.from(n.attributes).forEach(t=>{e.getAttribute(t.name)!==t.value&&(t.name==="value"&&"value"in e?e.value=t.value:t.name==="checked"&&"checked"in e?e.checked=t.value==="true"||t.value==="":e.setAttribute(t.name,t.value));});let r=e.__eventHandlers||{},o=n.__eventHandlers||{};Object.keys(r).forEach(t=>{o[t]||e.removeEventListener(t,r[t]);}),Object.keys(o).forEach(t=>{r[t]!==o[t]&&(r[t]&&e.removeEventListener(t,r[t]),e.addEventListener(t,o[t]));}),Object.keys(o).length>0?e.__eventHandlers=o:delete e.__eventHandlers,e instanceof HTMLInputElement&&n instanceof HTMLInputElement&&(e.value!==n.value&&(e.value=n.value),e.checked!==n.checked&&(e.checked=n.checked)),e instanceof HTMLTextAreaElement&&n instanceof HTMLTextAreaElement&&e.value!==n.value&&(e.value=n.value),e instanceof HTMLSelectElement&&n instanceof HTMLSelectElement&&e.value!==n.value&&(e.value=n.value);}function F(e,n){let a=Array.from(e.childNodes),c=Array.from(n.childNodes),r=Math.max(a.length,c.length);for(let o=0;o<r;o++){let t=a[o],i=c[o];!t&&i?e.appendChild(i):t&&!i?e.removeChild(t):t&&i&&N(t,i,e);}}function N(e,n,a){if(j(e,n)){let c=n.__ownerInstance;if(c){let r=c.nodes.indexOf(n);r!==-1&&(c.nodes[r]=e),e.__ownerInstance=c,delete n.__ownerInstance;}e.nodeType===Node.TEXT_NODE?e.nodeValue!==n.nodeValue&&(e.nodeValue=n.nodeValue):e.nodeType===Node.ELEMENT_NODE&&(k(e,n),F(e,n));}else e.parentNode===a?a.replaceChild(n,e):(e.parentNode&&e.parentNode.removeChild(e),a.insertBefore(n,null));}function P(e,n,a,c){let r=Math.max(e.length,n.length),o=[];for(let t=0;t<r;t++){let i=e[t],s=n[t];!i&&s?(a.insertBefore(s,c),o.push(s)):i&&!s?i.parentNode&&a.removeChild(i):i&&s&&(N(i,s,a),o.push(i));}return o}function $(e,n){return n.innerHTML="",typeof e=="function"&&(e={type:e,props:{},children:[],key:void 0}),y(e,n),()=>{if(d.has(n)){let a=d.get(n);a.forEach(c=>{I(c);}),a.clear(),d.delete(n);}n.innerHTML="";}}export{K as a,y as b,P as c,$ as d};//# sourceMappingURL=chunk-P6NMD5QH.mjs.map
2
+ //# sourceMappingURL=chunk-P6NMD5QH.mjs.map