@fictjs/runtime 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/advanced.cjs +8 -8
  2. package/dist/advanced.d.cts +3 -3
  3. package/dist/advanced.d.ts +3 -3
  4. package/dist/advanced.js +3 -3
  5. package/dist/{chunk-YQ4IB7NC.cjs → chunk-7EAEROZ5.cjs} +7 -7
  6. package/dist/{chunk-YQ4IB7NC.cjs.map → chunk-7EAEROZ5.cjs.map} +1 -1
  7. package/dist/{chunk-CF3OHML2.js → chunk-7TPCESQS.js} +2 -2
  8. package/dist/{chunk-BWZFJXUI.js → chunk-FOLRR3NZ.js} +84 -10
  9. package/dist/chunk-FOLRR3NZ.js.map +1 -0
  10. package/dist/{chunk-7WAGAQLT.cjs → chunk-MWI3USXB.cjs} +84 -10
  11. package/dist/chunk-MWI3USXB.cjs.map +1 -0
  12. package/dist/{chunk-V62XZLDU.js → chunk-VVNMIER7.js} +2 -2
  13. package/dist/{chunk-V62XZLDU.js.map → chunk-VVNMIER7.js.map} +1 -1
  14. package/dist/{chunk-Q4EN6BXV.cjs → chunk-Z5WRKD7Y.cjs} +16 -16
  15. package/dist/{chunk-Q4EN6BXV.cjs.map → chunk-Z5WRKD7Y.cjs.map} +1 -1
  16. package/dist/{context-B7UYnfzM.d.ts → context-4woHo7-L.d.ts} +1 -1
  17. package/dist/{context-UXySaqI_.d.cts → context-9gFXOdJl.d.cts} +1 -1
  18. package/dist/{effect-Auji1rz9.d.cts → effect-ClARNUCc.d.cts} +23 -2
  19. package/dist/{effect-Auji1rz9.d.ts → effect-ClARNUCc.d.ts} +23 -2
  20. package/dist/index.cjs +51 -58
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +5 -5
  23. package/dist/index.d.ts +5 -5
  24. package/dist/index.dev.js +71 -28
  25. package/dist/index.dev.js.map +1 -1
  26. package/dist/index.js +15 -22
  27. package/dist/index.js.map +1 -1
  28. package/dist/internal.cjs +64 -42
  29. package/dist/internal.cjs.map +1 -1
  30. package/dist/internal.d.cts +4 -4
  31. package/dist/internal.d.ts +4 -4
  32. package/dist/internal.js +32 -10
  33. package/dist/internal.js.map +1 -1
  34. package/dist/{props-BfmSLuyp.d.cts → props-CBwuh35e.d.cts} +4 -4
  35. package/dist/{props-BBi8Tkks.d.ts → props-DAyeRPwH.d.ts} +4 -4
  36. package/dist/{scope-S6eAzBJZ.d.ts → scope-DvgMquEy.d.ts} +1 -1
  37. package/dist/{scope-DKYzWfTn.d.cts → scope-xmdo6lVU.d.cts} +1 -1
  38. package/package.json +1 -1
  39. package/src/binding.ts +58 -5
  40. package/src/context.ts +1 -1
  41. package/src/effect.ts +9 -2
  42. package/src/error-boundary.ts +9 -9
  43. package/src/lifecycle.ts +13 -3
  44. package/src/signal.ts +44 -4
  45. package/src/store.ts +42 -20
  46. package/src/suspense.ts +14 -15
  47. package/dist/chunk-7WAGAQLT.cjs.map +0 -1
  48. package/dist/chunk-BWZFJXUI.js.map +0 -1
  49. /package/dist/{chunk-CF3OHML2.js.map → chunk-7TPCESQS.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/context.ts"],"sourcesContent":["/**\n * @fileoverview Context API for Fict\n *\n * Provides a way to pass data through the component tree without having to pass\n * props down manually at every level. Context is designed for:\n *\n * - SSR isolation (different request = different context values)\n * - Multi-instance support (multiple app roots with different values)\n * - Subtree scoping (override values in specific parts of the tree)\n *\n * ## Design Principles\n *\n * 1. **Reuses existing RootContext hierarchy** - Uses parent chain for value lookup,\n * consistent with handleError/handleSuspend mechanisms.\n *\n * 2. **Zero extra root creation overhead** - Provider doesn't create new root,\n * only mounts value on current root.\n *\n * 3. **Auto-aligned with insert/suspense boundaries** - Because they create child\n * roots that inherit parent, context values propagate correctly.\n *\n * ## Usage\n *\n * ```tsx\n * // Create context with default value\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Provide value to subtree\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <ThemedComponent />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume value\n * function ThemedComponent() {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>...</div>\n * }\n * ```\n *\n * @module\n */\n\nimport { createElement } from './dom'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n popRoot,\n pushRoot,\n type RootContext,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport { createRenderEffect } from './effect'\nimport type { BaseProps, FictNode } from './types'\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Context object created by createContext.\n * Contains the Provider component and serves as a key for context lookup.\n */\nexport interface Context<T> {\n /** Unique identifier for this context */\n readonly id: symbol\n /** Default value when no provider is found */\n readonly defaultValue: T\n /** Provider component for supplying context values */\n Provider: ContextProvider<T>\n /** Display name for debugging */\n displayName?: string\n}\n\n/**\n * Props for the Context Provider component\n */\nexport interface ProviderProps<T> extends BaseProps {\n /** The value to provide to the subtree */\n value: T\n}\n\n/**\n * Provider component type\n */\nexport type ContextProvider<T> = (props: ProviderProps<T>) => FictNode\n\n// ============================================================================\n// Internal Context Storage\n// ============================================================================\n\n/**\n * WeakMap to store context values per RootContext.\n * Using WeakMap ensures proper garbage collection when roots are destroyed.\n */\nconst contextStorage = new WeakMap<RootContext, Map<symbol, unknown>>()\n\n/**\n * Get the context map for a root, creating it if needed\n */\nfunction getContextMap(root: RootContext): Map<symbol, unknown> {\n let map = contextStorage.get(root)\n if (!map) {\n map = new Map()\n contextStorage.set(root, map)\n }\n return map\n}\n\n// ============================================================================\n// Context API\n// ============================================================================\n\n/**\n * Creates a new context with the given default value.\n *\n * Context provides a way to pass values through the component tree without\n * explicit props drilling. It's especially useful for:\n *\n * - Theme data\n * - Locale/i18n settings\n * - Authentication state\n * - Feature flags\n * - Any data that many components at different nesting levels need\n *\n * @param defaultValue - The value to use when no Provider is found above in the tree\n * @returns A context object with a Provider component\n *\n * @example\n * ```tsx\n * // Create a theme context\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Use the provider\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <Content />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume the context\n * function Content() {\n * const theme = useContext(ThemeContext)\n * return <div class={`theme-${theme}`}>Hello</div>\n * }\n * ```\n */\nexport function createContext<T>(defaultValue: T): Context<T> {\n const id = Symbol('fict.context')\n\n const context: Context<T> = {\n id,\n defaultValue,\n Provider: null as unknown as ContextProvider<T>,\n }\n\n // Create the Provider component\n context.Provider = function Provider(props: ProviderProps<T>): FictNode {\n const hostRoot = getCurrentRoot()\n\n // Create a child root for the provider's subtree\n // This establishes the provider boundary - children will look up from here\n const providerRoot = createRootContext(hostRoot)\n\n // Store the context value on this root\n const contextMap = getContextMap(providerRoot)\n contextMap.set(id, props.value)\n\n // Create DOM structure\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:ctx')\n fragment.appendChild(marker)\n\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n\n const renderChildren = (children: FictNode) => {\n // Cleanup previous render\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (children == null || children === false) {\n return\n }\n\n const prev = pushRoot(providerRoot)\n let nodes: Node[] = []\n try {\n const output = createElement(children)\n nodes = toNodeArray(output)\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } finally {\n popRoot(prev)\n flushOnMount(providerRoot)\n }\n\n cleanup = () => {\n destroyRoot(providerRoot)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n // Initial render\n createRenderEffect(() => {\n // Update context value on re-render (if value prop changes reactively)\n contextMap.set(id, props.value)\n renderChildren(props.children)\n })\n\n return fragment\n }\n\n return context\n}\n\n/**\n * Reads the current value of a context.\n *\n * useContext looks up through the RootContext parent chain to find the\n * nearest Provider for this context. If no Provider is found, returns\n * the context's default value.\n *\n * @param context - The context object created by createContext\n * @returns The current context value\n *\n * @example\n * ```tsx\n * const ThemeContext = createContext('light')\n *\n * function ThemedButton() {\n * const theme = useContext(ThemeContext)\n * return <button class={theme === 'dark' ? 'btn-dark' : 'btn-light'}>Click</button>\n * }\n * ```\n */\nexport function useContext<T>(context: Context<T>): T {\n let root = getCurrentRoot()\n\n // Walk up the parent chain looking for the context value\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return contextMap.get(context.id) as T\n }\n root = root.parent\n }\n\n // No provider found, return default value\n return context.defaultValue\n}\n\n/**\n * Checks if a context value is currently provided in the tree.\n *\n * Useful for conditional behavior when a provider may or may not exist.\n *\n * @param context - The context object to check\n * @returns true if a Provider exists above in the tree\n *\n * @example\n * ```tsx\n * function OptionalTheme() {\n * if (hasContext(ThemeContext)) {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>Themed content</div>\n * }\n * return <div>Default content</div>\n * }\n * ```\n */\nexport function hasContext<T>(context: Context<T>): boolean {\n let root = getCurrentRoot()\n\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return true\n }\n root = root.parent\n }\n\n return false\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoGA,IAAM,iBAAiB,oBAAI,QAA2C;AAKtE,SAAS,cAAc,MAAyC;AAC9D,MAAI,MAAM,eAAe,IAAI,IAAI;AACjC,MAAI,CAAC,KAAK;AACR,UAAM,oBAAI,IAAI;AACd,mBAAe,IAAI,MAAM,GAAG;AAAA,EAC9B;AACA,SAAO;AACT;AA0CO,SAAS,cAAiB,cAA6B;AAC5D,QAAM,KAAK,OAAO,cAAc;AAEhC,QAAM,UAAsB;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACZ;AAGA,UAAQ,WAAW,SAAS,SAAS,OAAmC;AACtE,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,SAAO,QAAQ;AACjB;AAqBO,SAAS,WAAc,SAA8B;AAC1D,MAAI,OAAO,eAAe;AAE1B,SAAO,MAAM;AACX,UAAM,aAAa,eAAe,IAAI,IAAI;AAC1C,QAAI,cAAc,WAAW,IAAI,QAAQ,EAAE,GAAG;AAC5C,aAAO;AAAA,IACT;AACA,WAAO,KAAK;AAAA,EACd;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/context.ts"],"sourcesContent":["/**\n * @fileoverview Context API for Fict\n *\n * Provides a way to pass data through the component tree without having to pass\n * props down manually at every level. Context is designed for:\n *\n * - SSR isolation (different request = different context values)\n * - Multi-instance support (multiple app roots with different values)\n * - Subtree scoping (override values in specific parts of the tree)\n *\n * ## Design Principles\n *\n * 1. **Reuses existing RootContext hierarchy** - Uses parent chain for value lookup,\n * consistent with handleError/handleSuspend mechanisms.\n *\n * 2. **Zero extra root creation overhead** - Provider doesn't create new root,\n * only mounts value on current root.\n *\n * 3. **Auto-aligned with insert/suspense boundaries** - Because they create child\n * roots that inherit parent, context values propagate correctly.\n *\n * ## Usage\n *\n * ```tsx\n * // Create context with default value\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Provide value to subtree\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <ThemedComponent />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume value\n * function ThemedComponent() {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>...</div>\n * }\n * ```\n *\n * @module\n */\n\nimport { createElement } from './dom'\nimport { createRenderEffect } from './effect'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n popRoot,\n pushRoot,\n type RootContext,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport type { BaseProps, FictNode } from './types'\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Context object created by createContext.\n * Contains the Provider component and serves as a key for context lookup.\n */\nexport interface Context<T> {\n /** Unique identifier for this context */\n readonly id: symbol\n /** Default value when no provider is found */\n readonly defaultValue: T\n /** Provider component for supplying context values */\n Provider: ContextProvider<T>\n /** Display name for debugging */\n displayName?: string\n}\n\n/**\n * Props for the Context Provider component\n */\nexport interface ProviderProps<T> extends BaseProps {\n /** The value to provide to the subtree */\n value: T\n}\n\n/**\n * Provider component type\n */\nexport type ContextProvider<T> = (props: ProviderProps<T>) => FictNode\n\n// ============================================================================\n// Internal Context Storage\n// ============================================================================\n\n/**\n * WeakMap to store context values per RootContext.\n * Using WeakMap ensures proper garbage collection when roots are destroyed.\n */\nconst contextStorage = new WeakMap<RootContext, Map<symbol, unknown>>()\n\n/**\n * Get the context map for a root, creating it if needed\n */\nfunction getContextMap(root: RootContext): Map<symbol, unknown> {\n let map = contextStorage.get(root)\n if (!map) {\n map = new Map()\n contextStorage.set(root, map)\n }\n return map\n}\n\n// ============================================================================\n// Context API\n// ============================================================================\n\n/**\n * Creates a new context with the given default value.\n *\n * Context provides a way to pass values through the component tree without\n * explicit props drilling. It's especially useful for:\n *\n * - Theme data\n * - Locale/i18n settings\n * - Authentication state\n * - Feature flags\n * - Any data that many components at different nesting levels need\n *\n * @param defaultValue - The value to use when no Provider is found above in the tree\n * @returns A context object with a Provider component\n *\n * @example\n * ```tsx\n * // Create a theme context\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Use the provider\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <Content />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume the context\n * function Content() {\n * const theme = useContext(ThemeContext)\n * return <div class={`theme-${theme}`}>Hello</div>\n * }\n * ```\n */\nexport function createContext<T>(defaultValue: T): Context<T> {\n const id = Symbol('fict.context')\n\n const context: Context<T> = {\n id,\n defaultValue,\n Provider: null as unknown as ContextProvider<T>,\n }\n\n // Create the Provider component\n context.Provider = function Provider(props: ProviderProps<T>): FictNode {\n const hostRoot = getCurrentRoot()\n\n // Create a child root for the provider's subtree\n // This establishes the provider boundary - children will look up from here\n const providerRoot = createRootContext(hostRoot)\n\n // Store the context value on this root\n const contextMap = getContextMap(providerRoot)\n contextMap.set(id, props.value)\n\n // Create DOM structure\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:ctx')\n fragment.appendChild(marker)\n\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n\n const renderChildren = (children: FictNode) => {\n // Cleanup previous render\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (children == null || children === false) {\n return\n }\n\n const prev = pushRoot(providerRoot)\n let nodes: Node[] = []\n try {\n const output = createElement(children)\n nodes = toNodeArray(output)\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } finally {\n popRoot(prev)\n flushOnMount(providerRoot)\n }\n\n cleanup = () => {\n destroyRoot(providerRoot)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n // Initial render\n createRenderEffect(() => {\n // Update context value on re-render (if value prop changes reactively)\n contextMap.set(id, props.value)\n renderChildren(props.children)\n })\n\n return fragment\n }\n\n return context\n}\n\n/**\n * Reads the current value of a context.\n *\n * useContext looks up through the RootContext parent chain to find the\n * nearest Provider for this context. If no Provider is found, returns\n * the context's default value.\n *\n * @param context - The context object created by createContext\n * @returns The current context value\n *\n * @example\n * ```tsx\n * const ThemeContext = createContext('light')\n *\n * function ThemedButton() {\n * const theme = useContext(ThemeContext)\n * return <button class={theme === 'dark' ? 'btn-dark' : 'btn-light'}>Click</button>\n * }\n * ```\n */\nexport function useContext<T>(context: Context<T>): T {\n let root = getCurrentRoot()\n\n // Walk up the parent chain looking for the context value\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return contextMap.get(context.id) as T\n }\n root = root.parent\n }\n\n // No provider found, return default value\n return context.defaultValue\n}\n\n/**\n * Checks if a context value is currently provided in the tree.\n *\n * Useful for conditional behavior when a provider may or may not exist.\n *\n * @param context - The context object to check\n * @returns true if a Provider exists above in the tree\n *\n * @example\n * ```tsx\n * function OptionalTheme() {\n * if (hasContext(ThemeContext)) {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>Themed content</div>\n * }\n * return <div>Default content</div>\n * }\n * ```\n */\nexport function hasContext<T>(context: Context<T>): boolean {\n let root = getCurrentRoot()\n\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return true\n }\n root = root.parent\n }\n\n return false\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoGA,IAAM,iBAAiB,oBAAI,QAA2C;AAKtE,SAAS,cAAc,MAAyC;AAC9D,MAAI,MAAM,eAAe,IAAI,IAAI;AACjC,MAAI,CAAC,KAAK;AACR,UAAM,oBAAI,IAAI;AACd,mBAAe,IAAI,MAAM,GAAG;AAAA,EAC9B;AACA,SAAO;AACT;AA0CO,SAAS,cAAiB,cAA6B;AAC5D,QAAM,KAAK,OAAO,cAAc;AAEhC,QAAM,UAAsB;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACZ;AAGA,UAAQ,WAAW,SAAS,SAAS,OAAmC;AACtE,UAAM,WAAW,eAAe;AAIhC,UAAM,eAAe,kBAAkB,QAAQ;AAG/C,UAAM,aAAa,cAAc,YAAY;AAC7C,eAAW,IAAI,IAAI,MAAM,KAAK;AAG9B,UAAM,WAAW,SAAS,uBAAuB;AACjD,UAAM,SAAS,SAAS,cAAc,UAAU;AAChD,aAAS,YAAY,MAAM;AAE3B,QAAI;AACJ,QAAI,cAAsB,CAAC;AAE3B,UAAM,iBAAiB,CAAC,aAAuB;AAE7C,UAAI,SAAS;AACX,gBAAQ;AACR,kBAAU;AAAA,MACZ;AACA,UAAI,YAAY,QAAQ;AACtB,oBAAY,WAAW;AACvB,sBAAc,CAAC;AAAA,MACjB;AAEA,UAAI,YAAY,QAAQ,aAAa,OAAO;AAC1C;AAAA,MACF;AAEA,YAAM,OAAO,SAAS,YAAY;AAClC,UAAI,QAAgB,CAAC;AACrB,UAAI;AACF,cAAM,SAAS,cAAc,QAAQ;AACrC,gBAAQ,YAAY,MAAM;AAC1B,cAAM,aAAa,OAAO;AAC1B,YAAI,YAAY;AACd,4BAAkB,YAAY,OAAO,MAAM;AAAA,QAC7C;AAAA,MACF,UAAE;AACA,gBAAQ,IAAI;AACZ,qBAAa,YAAY;AAAA,MAC3B;AAEA,gBAAU,MAAM;AACd,oBAAY,YAAY;AACxB,oBAAY,KAAK;AAAA,MACnB;AACA,oBAAc;AAAA,IAChB;AAGA,uBAAmB,MAAM;AAEvB,iBAAW,IAAI,IAAI,MAAM,KAAK;AAC9B,qBAAe,MAAM,QAAQ;AAAA,IAC/B,CAAC;AAED,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAsBO,SAAS,WAAc,SAAwB;AACpD,MAAI,OAAO,eAAe;AAG1B,SAAO,MAAM;AACX,UAAM,aAAa,eAAe,IAAI,IAAI;AAC1C,QAAI,cAAc,WAAW,IAAI,QAAQ,EAAE,GAAG;AAC5C,aAAO,WAAW,IAAI,QAAQ,EAAE;AAAA,IAClC;AACA,WAAO,KAAK;AAAA,EACd;AAGA,SAAO,QAAQ;AACjB;AAqBO,SAAS,WAAc,SAA8B;AAC1D,MAAI,OAAO,eAAe;AAE1B,SAAO,MAAM;AACX,UAAM,aAAa,eAAe,IAAI,IAAI;AAC1C,QAAI,cAAc,WAAW,IAAI,QAAQ,EAAE,GAAG;AAC5C,aAAO;AAAA,IACT;AACA,WAAO,KAAK;AAAA,EACd;AAEA,SAAO;AACT;","names":[]}
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- var _chunk7WAGAQLTcjs = require('./chunk-7WAGAQLT.cjs');
13
+ var _chunkMWI3USXBcjs = require('./chunk-MWI3USXB.cjs');
14
14
 
15
15
  // src/context.ts
16
16
  var contextStorage = /* @__PURE__ */ new WeakMap();
@@ -30,8 +30,8 @@ function createContext(defaultValue) {
30
30
  Provider: null
31
31
  };
32
32
  context.Provider = function Provider(props) {
33
- const hostRoot = _chunk7WAGAQLTcjs.getCurrentRoot.call(void 0, );
34
- const providerRoot = _chunk7WAGAQLTcjs.createRootContext.call(void 0, hostRoot);
33
+ const hostRoot = _chunkMWI3USXBcjs.getCurrentRoot.call(void 0, );
34
+ const providerRoot = _chunkMWI3USXBcjs.createRootContext.call(void 0, hostRoot);
35
35
  const contextMap = getContextMap(providerRoot);
36
36
  contextMap.set(id, props.value);
37
37
  const fragment = document.createDocumentFragment();
@@ -45,32 +45,32 @@ function createContext(defaultValue) {
45
45
  cleanup = void 0;
46
46
  }
47
47
  if (activeNodes.length) {
48
- _chunk7WAGAQLTcjs.removeNodes.call(void 0, activeNodes);
48
+ _chunkMWI3USXBcjs.removeNodes.call(void 0, activeNodes);
49
49
  activeNodes = [];
50
50
  }
51
51
  if (children == null || children === false) {
52
52
  return;
53
53
  }
54
- const prev = _chunk7WAGAQLTcjs.pushRoot.call(void 0, providerRoot);
54
+ const prev = _chunkMWI3USXBcjs.pushRoot.call(void 0, providerRoot);
55
55
  let nodes = [];
56
56
  try {
57
- const output = _chunk7WAGAQLTcjs.createElement.call(void 0, children);
58
- nodes = _chunk7WAGAQLTcjs.toNodeArray.call(void 0, output);
57
+ const output = _chunkMWI3USXBcjs.createElement.call(void 0, children);
58
+ nodes = _chunkMWI3USXBcjs.toNodeArray.call(void 0, output);
59
59
  const parentNode = marker.parentNode;
60
60
  if (parentNode) {
61
- _chunk7WAGAQLTcjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
61
+ _chunkMWI3USXBcjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
62
62
  }
63
63
  } finally {
64
- _chunk7WAGAQLTcjs.popRoot.call(void 0, prev);
65
- _chunk7WAGAQLTcjs.flushOnMount.call(void 0, providerRoot);
64
+ _chunkMWI3USXBcjs.popRoot.call(void 0, prev);
65
+ _chunkMWI3USXBcjs.flushOnMount.call(void 0, providerRoot);
66
66
  }
67
67
  cleanup = () => {
68
- _chunk7WAGAQLTcjs.destroyRoot.call(void 0, providerRoot);
69
- _chunk7WAGAQLTcjs.removeNodes.call(void 0, nodes);
68
+ _chunkMWI3USXBcjs.destroyRoot.call(void 0, providerRoot);
69
+ _chunkMWI3USXBcjs.removeNodes.call(void 0, nodes);
70
70
  };
71
71
  activeNodes = nodes;
72
72
  };
73
- _chunk7WAGAQLTcjs.createRenderEffect.call(void 0, () => {
73
+ _chunkMWI3USXBcjs.createRenderEffect.call(void 0, () => {
74
74
  contextMap.set(id, props.value);
75
75
  renderChildren(props.children);
76
76
  });
@@ -79,7 +79,7 @@ function createContext(defaultValue) {
79
79
  return context;
80
80
  }
81
81
  function useContext(context) {
82
- let root = _chunk7WAGAQLTcjs.getCurrentRoot.call(void 0, );
82
+ let root = _chunkMWI3USXBcjs.getCurrentRoot.call(void 0, );
83
83
  while (root) {
84
84
  const contextMap = contextStorage.get(root);
85
85
  if (contextMap && contextMap.has(context.id)) {
@@ -90,7 +90,7 @@ function useContext(context) {
90
90
  return context.defaultValue;
91
91
  }
92
92
  function hasContext(context) {
93
- let root = _chunk7WAGAQLTcjs.getCurrentRoot.call(void 0, );
93
+ let root = _chunkMWI3USXBcjs.getCurrentRoot.call(void 0, );
94
94
  while (root) {
95
95
  const contextMap = contextStorage.get(root);
96
96
  if (contextMap && contextMap.has(context.id)) {
@@ -106,4 +106,4 @@ function hasContext(context) {
106
106
 
107
107
 
108
108
  exports.createContext = createContext; exports.useContext = useContext; exports.hasContext = hasContext;
109
- //# sourceMappingURL=chunk-Q4EN6BXV.cjs.map
109
+ //# sourceMappingURL=chunk-Z5WRKD7Y.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/fict/fict/packages/runtime/dist/chunk-Q4EN6BXV.cjs","../src/context.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA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Ae;AAG1B,EAAA,MAAA,CAAO,IAAA,EAAM;AACX,IAAA,MAAM,WAAA,EAAa,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AAC1C,IAAA,GAAA,CAAI,WAAA,GAAc,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC5C,MAAA,OAAO,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA;AAAA,IAClC;AACA,IAAA,KAAA,EAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAGA,EAAA,OAAO,OAAA,CAAQ,YAAA;AACjB;AAqBO,SAAS,UAAA,CAAc,OAAA,EAA8B;AAC1D,EAAA,IAAI,KAAA,EAAO,8CAAA,CAAe;AAE1B,EAAA,MAAA,CAAO,IAAA,EAAM;AACX,IAAA,MAAM,WAAA,EAAa,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AAC1C,IAAA,GAAA,CAAI,WAAA,GAAc,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC5C,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,KAAA,EAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAEA,EAAA,OAAO,KAAA;AACT;ADrMA;AACA;AACE;AACA;AACA;AACF,wGAAC","file":"/home/runner/work/fict/fict/packages/runtime/dist/chunk-Q4EN6BXV.cjs","sourcesContent":[null,"/**\n * @fileoverview Context API for Fict\n *\n * Provides a way to pass data through the component tree without having to pass\n * props down manually at every level. Context is designed for:\n *\n * - SSR isolation (different request = different context values)\n * - Multi-instance support (multiple app roots with different values)\n * - Subtree scoping (override values in specific parts of the tree)\n *\n * ## Design Principles\n *\n * 1. **Reuses existing RootContext hierarchy** - Uses parent chain for value lookup,\n * consistent with handleError/handleSuspend mechanisms.\n *\n * 2. **Zero extra root creation overhead** - Provider doesn't create new root,\n * only mounts value on current root.\n *\n * 3. **Auto-aligned with insert/suspense boundaries** - Because they create child\n * roots that inherit parent, context values propagate correctly.\n *\n * ## Usage\n *\n * ```tsx\n * // Create context with default value\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Provide value to subtree\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <ThemedComponent />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume value\n * function ThemedComponent() {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>...</div>\n * }\n * ```\n *\n * @module\n */\n\nimport { createElement } from './dom'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n popRoot,\n pushRoot,\n type RootContext,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport { createRenderEffect } from './effect'\nimport type { BaseProps, FictNode } from './types'\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Context object created by createContext.\n * Contains the Provider component and serves as a key for context lookup.\n */\nexport interface Context<T> {\n /** Unique identifier for this context */\n readonly id: symbol\n /** Default value when no provider is found */\n readonly defaultValue: T\n /** Provider component for supplying context values */\n Provider: ContextProvider<T>\n /** Display name for debugging */\n displayName?: string\n}\n\n/**\n * Props for the Context Provider component\n */\nexport interface ProviderProps<T> extends BaseProps {\n /** The value to provide to the subtree */\n value: T\n}\n\n/**\n * Provider component type\n */\nexport type ContextProvider<T> = (props: ProviderProps<T>) => FictNode\n\n// ============================================================================\n// Internal Context Storage\n// ============================================================================\n\n/**\n * WeakMap to store context values per RootContext.\n * Using WeakMap ensures proper garbage collection when roots are destroyed.\n */\nconst contextStorage = new WeakMap<RootContext, Map<symbol, unknown>>()\n\n/**\n * Get the context map for a root, creating it if needed\n */\nfunction getContextMap(root: RootContext): Map<symbol, unknown> {\n let map = contextStorage.get(root)\n if (!map) {\n map = new Map()\n contextStorage.set(root, map)\n }\n return map\n}\n\n// ============================================================================\n// Context API\n// ============================================================================\n\n/**\n * Creates a new context with the given default value.\n *\n * Context provides a way to pass values through the component tree without\n * explicit props drilling. It's especially useful for:\n *\n * - Theme data\n * - Locale/i18n settings\n * - Authentication state\n * - Feature flags\n * - Any data that many components at different nesting levels need\n *\n * @param defaultValue - The value to use when no Provider is found above in the tree\n * @returns A context object with a Provider component\n *\n * @example\n * ```tsx\n * // Create a theme context\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Use the provider\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <Content />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume the context\n * function Content() {\n * const theme = useContext(ThemeContext)\n * return <div class={`theme-${theme}`}>Hello</div>\n * }\n * ```\n */\nexport function createContext<T>(defaultValue: T): Context<T> {\n const id = Symbol('fict.context')\n\n const context: Context<T> = {\n id,\n defaultValue,\n Provider: null as unknown as ContextProvider<T>,\n }\n\n // Create the Provider component\n context.Provider = function Provider(props: ProviderProps<T>): FictNode {\n const hostRoot = getCurrentRoot()\n\n // Create a child root for the provider's subtree\n // This establishes the provider boundary - children will look up from here\n const providerRoot = createRootContext(hostRoot)\n\n // Store the context value on this root\n const contextMap = getContextMap(providerRoot)\n contextMap.set(id, props.value)\n\n // Create DOM structure\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:ctx')\n fragment.appendChild(marker)\n\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n\n const renderChildren = (children: FictNode) => {\n // Cleanup previous render\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (children == null || children === false) {\n return\n }\n\n const prev = pushRoot(providerRoot)\n let nodes: Node[] = []\n try {\n const output = createElement(children)\n nodes = toNodeArray(output)\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } finally {\n popRoot(prev)\n flushOnMount(providerRoot)\n }\n\n cleanup = () => {\n destroyRoot(providerRoot)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n // Initial render\n createRenderEffect(() => {\n // Update context value on re-render (if value prop changes reactively)\n contextMap.set(id, props.value)\n renderChildren(props.children)\n })\n\n return fragment\n }\n\n return context\n}\n\n/**\n * Reads the current value of a context.\n *\n * useContext looks up through the RootContext parent chain to find the\n * nearest Provider for this context. If no Provider is found, returns\n * the context's default value.\n *\n * @param context - The context object created by createContext\n * @returns The current context value\n *\n * @example\n * ```tsx\n * const ThemeContext = createContext('light')\n *\n * function ThemedButton() {\n * const theme = useContext(ThemeContext)\n * return <button class={theme === 'dark' ? 'btn-dark' : 'btn-light'}>Click</button>\n * }\n * ```\n */\nexport function useContext<T>(context: Context<T>): T {\n let root = getCurrentRoot()\n\n // Walk up the parent chain looking for the context value\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return contextMap.get(context.id) as T\n }\n root = root.parent\n }\n\n // No provider found, return default value\n return context.defaultValue\n}\n\n/**\n * Checks if a context value is currently provided in the tree.\n *\n * Useful for conditional behavior when a provider may or may not exist.\n *\n * @param context - The context object to check\n * @returns true if a Provider exists above in the tree\n *\n * @example\n * ```tsx\n * function OptionalTheme() {\n * if (hasContext(ThemeContext)) {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>Themed content</div>\n * }\n * return <div>Default content</div>\n * }\n * ```\n */\nexport function hasContext<T>(context: Context<T>): boolean {\n let root = getCurrentRoot()\n\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return true\n }\n root = root.parent\n }\n\n return false\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/fict/fict/packages/runtime/dist/chunk-Z5WRKD7Y.cjs","../src/context.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACsFA,IAAM,eAAA,kBAAiB,IAAI,OAAA,CAA2C,CAAA;AAKtE,SAAS,aAAA,CAAc,IAAA,EAAyC;AAC9D,EAAA,IAAI,IAAA,EAAM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A,CAAI,WAAA,GAAc,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC5C,MAAA,OAAO,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA;AAAA,IAClC;AACA,IAAA,KAAA,EAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAGA,EAAA,OAAO,OAAA,CAAQ,YAAA;AACjB;AAqBO,SAAS,UAAA,CAAc,OAAA,EAA8B;AAC1D,EAAA,IAAI,KAAA,EAAO,8CAAA,CAAe;AAE1B,EAAA,MAAA,CAAO,IAAA,EAAM;AACX,IAAA,MAAM,WAAA,EAAa,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AAC1C,IAAA,GAAA,CAAI,WAAA,GAAc,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC5C,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,KAAA,EAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAEA,EAAA,OAAO,KAAA;AACT;ADrMA;AACA;AACE;AACA;AACA;AACF,wGAAC","file":"/home/runner/work/fict/fict/packages/runtime/dist/chunk-Z5WRKD7Y.cjs","sourcesContent":[null,"/**\n * @fileoverview Context API for Fict\n *\n * Provides a way to pass data through the component tree without having to pass\n * props down manually at every level. Context is designed for:\n *\n * - SSR isolation (different request = different context values)\n * - Multi-instance support (multiple app roots with different values)\n * - Subtree scoping (override values in specific parts of the tree)\n *\n * ## Design Principles\n *\n * 1. **Reuses existing RootContext hierarchy** - Uses parent chain for value lookup,\n * consistent with handleError/handleSuspend mechanisms.\n *\n * 2. **Zero extra root creation overhead** - Provider doesn't create new root,\n * only mounts value on current root.\n *\n * 3. **Auto-aligned with insert/suspense boundaries** - Because they create child\n * roots that inherit parent, context values propagate correctly.\n *\n * ## Usage\n *\n * ```tsx\n * // Create context with default value\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Provide value to subtree\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <ThemedComponent />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume value\n * function ThemedComponent() {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>...</div>\n * }\n * ```\n *\n * @module\n */\n\nimport { createElement } from './dom'\nimport { createRenderEffect } from './effect'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n popRoot,\n pushRoot,\n type RootContext,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport type { BaseProps, FictNode } from './types'\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Context object created by createContext.\n * Contains the Provider component and serves as a key for context lookup.\n */\nexport interface Context<T> {\n /** Unique identifier for this context */\n readonly id: symbol\n /** Default value when no provider is found */\n readonly defaultValue: T\n /** Provider component for supplying context values */\n Provider: ContextProvider<T>\n /** Display name for debugging */\n displayName?: string\n}\n\n/**\n * Props for the Context Provider component\n */\nexport interface ProviderProps<T> extends BaseProps {\n /** The value to provide to the subtree */\n value: T\n}\n\n/**\n * Provider component type\n */\nexport type ContextProvider<T> = (props: ProviderProps<T>) => FictNode\n\n// ============================================================================\n// Internal Context Storage\n// ============================================================================\n\n/**\n * WeakMap to store context values per RootContext.\n * Using WeakMap ensures proper garbage collection when roots are destroyed.\n */\nconst contextStorage = new WeakMap<RootContext, Map<symbol, unknown>>()\n\n/**\n * Get the context map for a root, creating it if needed\n */\nfunction getContextMap(root: RootContext): Map<symbol, unknown> {\n let map = contextStorage.get(root)\n if (!map) {\n map = new Map()\n contextStorage.set(root, map)\n }\n return map\n}\n\n// ============================================================================\n// Context API\n// ============================================================================\n\n/**\n * Creates a new context with the given default value.\n *\n * Context provides a way to pass values through the component tree without\n * explicit props drilling. It's especially useful for:\n *\n * - Theme data\n * - Locale/i18n settings\n * - Authentication state\n * - Feature flags\n * - Any data that many components at different nesting levels need\n *\n * @param defaultValue - The value to use when no Provider is found above in the tree\n * @returns A context object with a Provider component\n *\n * @example\n * ```tsx\n * // Create a theme context\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Use the provider\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <Content />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume the context\n * function Content() {\n * const theme = useContext(ThemeContext)\n * return <div class={`theme-${theme}`}>Hello</div>\n * }\n * ```\n */\nexport function createContext<T>(defaultValue: T): Context<T> {\n const id = Symbol('fict.context')\n\n const context: Context<T> = {\n id,\n defaultValue,\n Provider: null as unknown as ContextProvider<T>,\n }\n\n // Create the Provider component\n context.Provider = function Provider(props: ProviderProps<T>): FictNode {\n const hostRoot = getCurrentRoot()\n\n // Create a child root for the provider's subtree\n // This establishes the provider boundary - children will look up from here\n const providerRoot = createRootContext(hostRoot)\n\n // Store the context value on this root\n const contextMap = getContextMap(providerRoot)\n contextMap.set(id, props.value)\n\n // Create DOM structure\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:ctx')\n fragment.appendChild(marker)\n\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n\n const renderChildren = (children: FictNode) => {\n // Cleanup previous render\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (children == null || children === false) {\n return\n }\n\n const prev = pushRoot(providerRoot)\n let nodes: Node[] = []\n try {\n const output = createElement(children)\n nodes = toNodeArray(output)\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } finally {\n popRoot(prev)\n flushOnMount(providerRoot)\n }\n\n cleanup = () => {\n destroyRoot(providerRoot)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n // Initial render\n createRenderEffect(() => {\n // Update context value on re-render (if value prop changes reactively)\n contextMap.set(id, props.value)\n renderChildren(props.children)\n })\n\n return fragment\n }\n\n return context\n}\n\n/**\n * Reads the current value of a context.\n *\n * useContext looks up through the RootContext parent chain to find the\n * nearest Provider for this context. If no Provider is found, returns\n * the context's default value.\n *\n * @param context - The context object created by createContext\n * @returns The current context value\n *\n * @example\n * ```tsx\n * const ThemeContext = createContext('light')\n *\n * function ThemedButton() {\n * const theme = useContext(ThemeContext)\n * return <button class={theme === 'dark' ? 'btn-dark' : 'btn-light'}>Click</button>\n * }\n * ```\n */\nexport function useContext<T>(context: Context<T>): T {\n let root = getCurrentRoot()\n\n // Walk up the parent chain looking for the context value\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return contextMap.get(context.id) as T\n }\n root = root.parent\n }\n\n // No provider found, return default value\n return context.defaultValue\n}\n\n/**\n * Checks if a context value is currently provided in the tree.\n *\n * Useful for conditional behavior when a provider may or may not exist.\n *\n * @param context - The context object to check\n * @returns true if a Provider exists above in the tree\n *\n * @example\n * ```tsx\n * function OptionalTheme() {\n * if (hasContext(ThemeContext)) {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>Themed content</div>\n * }\n * return <div>Default content</div>\n * }\n * ```\n */\nexport function hasContext<T>(context: Context<T>): boolean {\n let root = getCurrentRoot()\n\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return true\n }\n root = root.parent\n }\n\n return false\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { B as BaseProps, F as FictNode } from './effect-Auji1rz9.js';
1
+ import { B as BaseProps, F as FictNode } from './effect-ClARNUCc.js';
2
2
 
3
3
  /**
4
4
  * @fileoverview Context API for Fict
@@ -1,4 +1,4 @@
1
- import { B as BaseProps, F as FictNode } from './effect-Auji1rz9.cjs';
1
+ import { B as BaseProps, F as FictNode } from './effect-ClARNUCc.cjs';
2
2
 
3
3
  /**
4
4
  * @fileoverview Context API for Fict
@@ -88,8 +88,29 @@ interface BindingHandle {
88
88
  }
89
89
  /** Managed child node with its dispose function */
90
90
  /**
91
- * Check if a value is reactive (a getter function)
92
- * Note: Event handlers (functions that take arguments) are NOT reactive values
91
+ * Check if a value is reactive (a getter function that returns a value).
92
+ *
93
+ * A value is considered reactive if:
94
+ * 1. It's a signal or computed value created by the runtime (marked with Symbol)
95
+ * 2. It's a zero-argument function (getter pattern used by the compiler)
96
+ *
97
+ * NOT considered reactive:
98
+ * - Event handlers (functions that take arguments)
99
+ * - Effect disposers (zero-arg but for cleanup, not value access)
100
+ * - Effect scopes (zero-arg but for scope management)
101
+ *
102
+ * @param value - The value to check
103
+ * @returns true if the value is a reactive getter
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const [count, setCount] = createSignal(0)
108
+ * isReactive(count) // true - signal accessor
109
+ * isReactive(() => 42) // true - getter pattern
110
+ * isReactive((x) => x) // false - takes argument
111
+ * isReactive('hello') // false - not a function
112
+ * isReactive(effectDisposer) // false - effect cleanup function
113
+ * ```
93
114
  */
94
115
  declare function isReactive(value: unknown): value is () => unknown;
95
116
  /**
@@ -88,8 +88,29 @@ interface BindingHandle {
88
88
  }
89
89
  /** Managed child node with its dispose function */
90
90
  /**
91
- * Check if a value is reactive (a getter function)
92
- * Note: Event handlers (functions that take arguments) are NOT reactive values
91
+ * Check if a value is reactive (a getter function that returns a value).
92
+ *
93
+ * A value is considered reactive if:
94
+ * 1. It's a signal or computed value created by the runtime (marked with Symbol)
95
+ * 2. It's a zero-argument function (getter pattern used by the compiler)
96
+ *
97
+ * NOT considered reactive:
98
+ * - Event handlers (functions that take arguments)
99
+ * - Effect disposers (zero-arg but for cleanup, not value access)
100
+ * - Effect scopes (zero-arg but for scope management)
101
+ *
102
+ * @param value - The value to check
103
+ * @returns true if the value is a reactive getter
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const [count, setCount] = createSignal(0)
108
+ * isReactive(count) // true - signal accessor
109
+ * isReactive(() => 42) // true - getter pattern
110
+ * isReactive((x) => x) // false - takes argument
111
+ * isReactive('hello') // false - not a function
112
+ * isReactive(effectDisposer) // false - effect cleanup function
113
+ * ```
93
114
  */
94
115
  declare function isReactive(value: unknown): value is () => unknown;
95
116
  /**
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkQ4EN6BXVcjs = require('./chunk-Q4EN6BXV.cjs');
5
+ var _chunkZ5WRKD7Ycjs = require('./chunk-Z5WRKD7Y.cjs');
6
6
 
7
7
 
8
8
 
@@ -34,7 +34,7 @@ var _chunkQ4EN6BXVcjs = require('./chunk-Q4EN6BXV.cjs');
34
34
 
35
35
 
36
36
 
37
- var _chunk7WAGAQLTcjs = require('./chunk-7WAGAQLT.cjs');
37
+ var _chunkMWI3USXBcjs = require('./chunk-MWI3USXB.cjs');
38
38
 
39
39
  // src/ref.ts
40
40
  function createRef() {
@@ -46,14 +46,15 @@ function ErrorBoundary(props) {
46
46
  const fragment = document.createDocumentFragment();
47
47
  const marker = document.createComment("fict:error-boundary");
48
48
  fragment.appendChild(marker);
49
- const currentView = _chunk7WAGAQLTcjs.signal.call(void 0, _nullishCoalesce(props.children, () => ( null)));
50
- const hostRoot = _chunk7WAGAQLTcjs.getCurrentRoot.call(void 0, );
49
+ const hostRoot = _chunkMWI3USXBcjs.getCurrentRoot.call(void 0, );
51
50
  let cleanup;
52
51
  let activeNodes = [];
53
52
  let renderingFallback = false;
53
+ let reset = () => {
54
+ };
54
55
  const toView = (err) => {
55
56
  if (err != null) {
56
- return typeof props.fallback === "function" ? props.fallback(err) : props.fallback;
57
+ return typeof props.fallback === "function" ? props.fallback(err, reset) : props.fallback;
57
58
  }
58
59
  return _nullishCoalesce(props.children, () => ( null));
59
60
  };
@@ -63,26 +64,25 @@ function ErrorBoundary(props) {
63
64
  cleanup = void 0;
64
65
  }
65
66
  if (activeNodes.length) {
66
- _chunk7WAGAQLTcjs.removeNodes.call(void 0, activeNodes);
67
+ _chunkMWI3USXBcjs.removeNodes.call(void 0, activeNodes);
67
68
  activeNodes = [];
68
69
  }
69
70
  if (value == null || value === false) {
70
71
  return;
71
72
  }
72
- const root = _chunk7WAGAQLTcjs.createRootContext.call(void 0, hostRoot);
73
- const prev = _chunk7WAGAQLTcjs.pushRoot.call(void 0, root);
73
+ const root = _chunkMWI3USXBcjs.createRootContext.call(void 0, hostRoot);
74
+ const prev = _chunkMWI3USXBcjs.pushRoot.call(void 0, root);
74
75
  let nodes = [];
75
76
  try {
76
- const output = _chunk7WAGAQLTcjs.createElement.call(void 0, value);
77
- nodes = _chunk7WAGAQLTcjs.toNodeArray.call(void 0, output);
77
+ const output = _chunkMWI3USXBcjs.createElement.call(void 0, value);
78
+ nodes = _chunkMWI3USXBcjs.toNodeArray.call(void 0, output);
78
79
  const parentNode = marker.parentNode;
79
80
  if (parentNode) {
80
- _chunk7WAGAQLTcjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
81
+ _chunkMWI3USXBcjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
81
82
  }
82
83
  } catch (err) {
83
- _chunk7WAGAQLTcjs.popRoot.call(void 0, prev);
84
- _chunk7WAGAQLTcjs.flushOnMount.call(void 0, root);
85
- _chunk7WAGAQLTcjs.destroyRoot.call(void 0, root);
84
+ _chunkMWI3USXBcjs.popRoot.call(void 0, prev);
85
+ _chunkMWI3USXBcjs.destroyRoot.call(void 0, root);
86
86
  if (renderingFallback) {
87
87
  throw err;
88
88
  }
@@ -97,19 +97,20 @@ function ErrorBoundary(props) {
97
97
  }
98
98
  return;
99
99
  }
100
- _chunk7WAGAQLTcjs.popRoot.call(void 0, prev);
101
- _chunk7WAGAQLTcjs.flushOnMount.call(void 0, root);
100
+ _chunkMWI3USXBcjs.popRoot.call(void 0, prev);
101
+ _chunkMWI3USXBcjs.flushOnMount.call(void 0, root);
102
102
  cleanup = () => {
103
- _chunk7WAGAQLTcjs.destroyRoot.call(void 0, root);
104
- _chunk7WAGAQLTcjs.removeNodes.call(void 0, nodes);
103
+ _chunkMWI3USXBcjs.destroyRoot.call(void 0, root);
104
+ _chunkMWI3USXBcjs.removeNodes.call(void 0, nodes);
105
105
  };
106
106
  activeNodes = nodes;
107
107
  };
108
- _chunk7WAGAQLTcjs.createEffect.call(void 0, () => {
109
- const value = currentView();
110
- renderValue(value);
111
- });
112
- _chunk7WAGAQLTcjs.registerErrorHandler.call(void 0, (err) => {
108
+ reset = () => {
109
+ renderingFallback = false;
110
+ renderValue(toView(null));
111
+ };
112
+ renderValue(_nullishCoalesce(props.children, () => ( null)));
113
+ _chunkMWI3USXBcjs.registerErrorHandler.call(void 0, (err) => {
113
114
  renderValue(toView(err));
114
115
  _optionalChain([props, 'access', _5 => _5.onError, 'optionalCall', _6 => _6(err)]);
115
116
  return true;
@@ -118,7 +119,7 @@ function ErrorBoundary(props) {
118
119
  const isGetter = typeof props.resetKeys === "function" && props.resetKeys.length === 0;
119
120
  const getter = isGetter ? props.resetKeys : void 0;
120
121
  let prev = isGetter ? getter() : props.resetKeys;
121
- _chunk7WAGAQLTcjs.createEffect.call(void 0, () => {
122
+ _chunkMWI3USXBcjs.createEffect.call(void 0, () => {
122
123
  const next = getter ? getter() : props.resetKeys;
123
124
  if (prev !== next) {
124
125
  prev = next;
@@ -147,58 +148,52 @@ function createSuspenseToken() {
147
148
  }
148
149
  var isThenable = (value) => typeof value === "object" && value !== null && typeof value.then === "function";
149
150
  function Suspense(props) {
150
- const currentView = _chunk7WAGAQLTcjs.signal.call(void 0, _nullishCoalesce(props.children, () => ( null)));
151
- const pending = _chunk7WAGAQLTcjs.signal.call(void 0, 0);
151
+ const pending = _chunkMWI3USXBcjs.signal.call(void 0, 0);
152
152
  let resolvedOnce = false;
153
153
  let epoch = 0;
154
- const hostRoot = _chunk7WAGAQLTcjs.getCurrentRoot.call(void 0, );
154
+ const hostRoot = _chunkMWI3USXBcjs.getCurrentRoot.call(void 0, );
155
155
  const toFallback = (err) => typeof props.fallback === "function" ? props.fallback(err) : props.fallback;
156
- const switchView = (view) => {
157
- currentView(view);
158
- renderView(view);
159
- };
160
156
  const renderView = (view) => {
161
157
  if (cleanup) {
162
158
  cleanup();
163
159
  cleanup = void 0;
164
160
  }
165
161
  if (activeNodes.length) {
166
- _chunk7WAGAQLTcjs.removeNodes.call(void 0, activeNodes);
162
+ _chunkMWI3USXBcjs.removeNodes.call(void 0, activeNodes);
167
163
  activeNodes = [];
168
164
  }
169
165
  if (view == null || view === false) {
170
166
  return;
171
167
  }
172
- const root = _chunk7WAGAQLTcjs.createRootContext.call(void 0, hostRoot);
173
- const prev = _chunk7WAGAQLTcjs.pushRoot.call(void 0, root);
168
+ const root = _chunkMWI3USXBcjs.createRootContext.call(void 0, hostRoot);
169
+ const prev = _chunkMWI3USXBcjs.pushRoot.call(void 0, root);
174
170
  let nodes = [];
175
171
  try {
176
- const output = _chunk7WAGAQLTcjs.createElement.call(void 0, view);
177
- nodes = _chunk7WAGAQLTcjs.toNodeArray.call(void 0, output);
178
- const suspendedAttempt = nodes.length > 0 && nodes.every((node) => node instanceof Comment && node.data === "fict:suspend");
172
+ const output = _chunkMWI3USXBcjs.createElement.call(void 0, view);
173
+ nodes = _chunkMWI3USXBcjs.toNodeArray.call(void 0, output);
174
+ const suspendedAttempt = root.suspended || nodes.length > 0 && nodes.every((node) => node instanceof Comment && node.data === "fict:suspend");
179
175
  if (suspendedAttempt) {
180
- _chunk7WAGAQLTcjs.popRoot.call(void 0, prev);
181
- _chunk7WAGAQLTcjs.destroyRoot.call(void 0, root);
176
+ _chunkMWI3USXBcjs.popRoot.call(void 0, prev);
177
+ _chunkMWI3USXBcjs.destroyRoot.call(void 0, root);
182
178
  return;
183
179
  }
184
180
  const parentNode = marker.parentNode;
185
181
  if (parentNode) {
186
- _chunk7WAGAQLTcjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
182
+ _chunkMWI3USXBcjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
187
183
  }
188
184
  } catch (err) {
189
- _chunk7WAGAQLTcjs.popRoot.call(void 0, prev);
190
- _chunk7WAGAQLTcjs.flushOnMount.call(void 0, root);
191
- _chunk7WAGAQLTcjs.destroyRoot.call(void 0, root);
192
- if (!_chunk7WAGAQLTcjs.handleError.call(void 0, err, { source: "render" }, hostRoot)) {
185
+ _chunkMWI3USXBcjs.popRoot.call(void 0, prev);
186
+ _chunkMWI3USXBcjs.destroyRoot.call(void 0, root);
187
+ if (!_chunkMWI3USXBcjs.handleError.call(void 0, err, { source: "render" }, hostRoot)) {
193
188
  throw err;
194
189
  }
195
190
  return;
196
191
  }
197
- _chunk7WAGAQLTcjs.popRoot.call(void 0, prev);
198
- _chunk7WAGAQLTcjs.flushOnMount.call(void 0, root);
192
+ _chunkMWI3USXBcjs.popRoot.call(void 0, prev);
193
+ _chunkMWI3USXBcjs.flushOnMount.call(void 0, root);
199
194
  cleanup = () => {
200
- _chunk7WAGAQLTcjs.destroyRoot.call(void 0, root);
201
- _chunk7WAGAQLTcjs.removeNodes.call(void 0, nodes);
195
+ _chunkMWI3USXBcjs.destroyRoot.call(void 0, root);
196
+ _chunkMWI3USXBcjs.removeNodes.call(void 0, nodes);
202
197
  };
203
198
  activeNodes = nodes;
204
199
  };
@@ -213,10 +208,10 @@ function Suspense(props) {
213
208
  _optionalChain([props, 'access', _7 => _7.onResolve, 'optionalCall', _8 => _8()]);
214
209
  }
215
210
  };
216
- _chunk7WAGAQLTcjs.registerSuspenseHandler.call(void 0, (token) => {
211
+ _chunkMWI3USXBcjs.registerSuspenseHandler.call(void 0, (token) => {
217
212
  const tokenEpoch = epoch;
218
213
  pending(pending() + 1);
219
- switchView(toFallback());
214
+ renderView(toFallback());
220
215
  const thenable = token.then ? token : isThenable(token) ? token : null;
221
216
  if (thenable) {
222
217
  thenable.then(
@@ -227,7 +222,7 @@ function Suspense(props) {
227
222
  const newPending = Math.max(0, pending() - 1);
228
223
  pending(newPending);
229
224
  if (newPending === 0) {
230
- switchView(_nullishCoalesce(props.children, () => ( null)));
225
+ renderView(_nullishCoalesce(props.children, () => ( null)));
231
226
  onResolveMaybe();
232
227
  }
233
228
  },
@@ -238,7 +233,7 @@ function Suspense(props) {
238
233
  const newPending = Math.max(0, pending() - 1);
239
234
  pending(newPending);
240
235
  _optionalChain([props, 'access', _9 => _9.onReject, 'optionalCall', _10 => _10(err)]);
241
- if (!_chunk7WAGAQLTcjs.handleError.call(void 0, err, { source: "render" }, hostRoot)) {
236
+ if (!_chunkMWI3USXBcjs.handleError.call(void 0, err, { source: "render" }, hostRoot)) {
242
237
  throw err;
243
238
  }
244
239
  }
@@ -247,20 +242,18 @@ function Suspense(props) {
247
242
  }
248
243
  return false;
249
244
  });
250
- _chunk7WAGAQLTcjs.createEffect.call(void 0, () => {
251
- renderView(currentView());
252
- });
245
+ renderView(_nullishCoalesce(props.children, () => ( null)));
253
246
  if (props.resetKeys !== void 0) {
254
247
  const isGetter = typeof props.resetKeys === "function" && props.resetKeys.length === 0;
255
248
  const getter = isGetter ? props.resetKeys : void 0;
256
249
  let prev = isGetter ? getter() : props.resetKeys;
257
- _chunk7WAGAQLTcjs.createEffect.call(void 0, () => {
250
+ _chunkMWI3USXBcjs.createEffect.call(void 0, () => {
258
251
  const next = getter ? getter() : props.resetKeys;
259
252
  if (prev !== next) {
260
253
  prev = next;
261
254
  epoch++;
262
255
  pending(0);
263
- switchView(_nullishCoalesce(props.children, () => ( null)));
256
+ renderView(_nullishCoalesce(props.children, () => ( null)));
264
257
  }
265
258
  });
266
259
  }
@@ -291,5 +284,5 @@ function Suspense(props) {
291
284
 
292
285
 
293
286
 
294
- exports.ErrorBoundary = ErrorBoundary; exports.Fragment = _chunk7WAGAQLTcjs.Fragment; exports.Suspense = Suspense; exports.batch = _chunk7WAGAQLTcjs.batch2; exports.createContext = _chunkQ4EN6BXVcjs.createContext; exports.createEffect = _chunk7WAGAQLTcjs.createEffect; exports.createElement = _chunk7WAGAQLTcjs.createElement; exports.createMemo = _chunk7WAGAQLTcjs.createMemo; exports.createPortal = _chunk7WAGAQLTcjs.createPortal; exports.createRef = createRef; exports.createRoot = _chunk7WAGAQLTcjs.createRoot; exports.createSuspenseToken = createSuspenseToken; exports.hasContext = _chunkQ4EN6BXVcjs.hasContext; exports.mergeProps = _chunk7WAGAQLTcjs.mergeProps; exports.onCleanup = _chunk7WAGAQLTcjs.onCleanup; exports.onDestroy = _chunk7WAGAQLTcjs.onDestroy; exports.onMount = _chunk7WAGAQLTcjs.onMount; exports.prop = _chunk7WAGAQLTcjs.prop; exports.render = _chunk7WAGAQLTcjs.render; exports.startTransition = _chunk7WAGAQLTcjs.startTransition; exports.untrack = _chunk7WAGAQLTcjs.untrack2; exports.useContext = _chunkQ4EN6BXVcjs.useContext; exports.useDeferredValue = _chunk7WAGAQLTcjs.useDeferredValue; exports.useTransition = _chunk7WAGAQLTcjs.useTransition;
287
+ exports.ErrorBoundary = ErrorBoundary; exports.Fragment = _chunkMWI3USXBcjs.Fragment; exports.Suspense = Suspense; exports.batch = _chunkMWI3USXBcjs.batch2; exports.createContext = _chunkZ5WRKD7Ycjs.createContext; exports.createEffect = _chunkMWI3USXBcjs.createEffect; exports.createElement = _chunkMWI3USXBcjs.createElement; exports.createMemo = _chunkMWI3USXBcjs.createMemo; exports.createPortal = _chunkMWI3USXBcjs.createPortal; exports.createRef = createRef; exports.createRoot = _chunkMWI3USXBcjs.createRoot; exports.createSuspenseToken = createSuspenseToken; exports.hasContext = _chunkZ5WRKD7Ycjs.hasContext; exports.mergeProps = _chunkMWI3USXBcjs.mergeProps; exports.onCleanup = _chunkMWI3USXBcjs.onCleanup; exports.onDestroy = _chunkMWI3USXBcjs.onDestroy; exports.onMount = _chunkMWI3USXBcjs.onMount; exports.prop = _chunkMWI3USXBcjs.prop; exports.render = _chunkMWI3USXBcjs.render; exports.startTransition = _chunkMWI3USXBcjs.startTransition; exports.untrack = _chunkMWI3USXBcjs.untrack2; exports.useContext = _chunkZ5WRKD7Ycjs.useContext; exports.useDeferredValue = _chunkMWI3USXBcjs.useDeferredValue; exports.useTransition = _chunkMWI3USXBcjs.useTransition;
295
288
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/fict/fict/packages/runtime/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,UAAA,IAAc,WAAA,GAAe,KAAA,CAAM,SAAA,CAA4B,OAAA,IAAW,CAAA;AACzF,IAAA,MAAM,OAAA,EAAS,SAAA,EAAY,KAAA,CAAM,UAAA,EAA8B,KAAA,CAAA;AAC/D,IAAA,IAAI,KAAA,EAAO,SAAA,EAAW,MAAA,CAAQ,EAAA,EAAI,KAAA,CAAM,SAAA;AACxC,IAAA,4CAAA,CAAa,EAAA,GAAM;AACjB,MAAA,MAAM,KAAA,EAAO,OAAA,EAAS,MAAA,CAAO,EAAA,EAAI,KAAA,CAAM,SAAA;AACvC,MAAA,GAAA,CAAI,KAAA,IAAS,IAAA,EAAM;AACjB,QAAA,KAAA,EAAO,IAAA;AACP,QAAA,KAAA,EAAA;AACA,QAAA,OAAA,CAAQ,CAAC,CAAA;AACT,QAAA,UAAA,kBAAW,KAAA,CAAM,QAAA,UAAY,MAAI,CAAA;AAAA,MACnC;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AAEA,EAAA,OAAO,QAAA;AACT;AHiEA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,ipCAAC","file":"/home/runner/work/fict/fict/packages/runtime/dist/index.cjs","sourcesContent":[null,"import type { RefObject } from './types'\n\n/**\n * Create a ref object for DOM element references.\n *\n * @returns A ref object with a `current` property initialized to `null`\n *\n * @example\n * ```tsx\n * import { createRef } from 'fict'\n *\n * function Component() {\n * const inputRef = createRef<HTMLInputElement>()\n *\n * $effect(() => {\n * inputRef.current?.focus()\n * })\n *\n * return <input ref={inputRef} />\n * }\n * ```\n */\nexport function createRef<T extends Element = HTMLElement>(): RefObject<T> {\n return { current: null }\n}\n","import { createElement } from './dom'\nimport { createEffect } from './effect'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n pushRoot,\n popRoot,\n registerErrorHandler,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport { createSignal } from './signal'\nimport type { BaseProps, FictNode } from './types'\n\ninterface ErrorBoundaryProps extends BaseProps {\n fallback: FictNode | ((err: unknown) => FictNode)\n onError?: (err: unknown) => void\n resetKeys?: unknown | (() => unknown)\n}\n\nexport function ErrorBoundary(props: ErrorBoundaryProps): FictNode {\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:error-boundary')\n fragment.appendChild(marker)\n\n const currentView = createSignal<FictNode | null>(props.children ?? null)\n const hostRoot = getCurrentRoot()\n\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n let renderingFallback = false\n\n const toView = (err: unknown | null): FictNode | null => {\n if (err != null) {\n return typeof props.fallback === 'function'\n ? (props.fallback as (e: unknown) => FictNode)(err)\n : props.fallback\n }\n return props.children ?? null\n }\n\n const renderValue = (value: FictNode | null) => {\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (value == null || value === false) {\n return\n }\n\n const root = createRootContext(hostRoot)\n const prev = pushRoot(root)\n let nodes: Node[] = []\n try {\n const output = createElement(value)\n nodes = toNodeArray(output)\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } catch (err) {\n popRoot(prev)\n flushOnMount(root)\n destroyRoot(root)\n // Fall back immediately on render errors, avoid infinite recursion\n if (renderingFallback) {\n throw err\n }\n // nested errors. If fallback rendering also throws, we should NOT reset\n // the flag until we're sure no more recursion is happening.\n renderingFallback = true\n try {\n renderValue(toView(err))\n // Only reset if successful - if renderValue threw, we want to keep\n // renderingFallback = true to prevent infinite recursion\n renderingFallback = false\n props.onError?.(err)\n } catch (fallbackErr) {\n // Fallback rendering failed - keep renderingFallback = true\n // to prevent further attempts, then rethrow\n // If fallback fails, report both errors\n props.onError?.(err)\n throw fallbackErr\n }\n return\n }\n popRoot(prev)\n flushOnMount(root)\n\n cleanup = () => {\n destroyRoot(root)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n createEffect(() => {\n const value = currentView()\n renderValue(value)\n })\n\n registerErrorHandler(err => {\n renderValue(toView(err))\n props.onError?.(err)\n return true\n })\n\n if (props.resetKeys !== undefined) {\n const isGetter =\n typeof props.resetKeys === 'function' && (props.resetKeys as () => unknown).length === 0\n const getter = isGetter ? (props.resetKeys as () => unknown) : undefined\n let prev = isGetter ? getter!() : props.resetKeys\n createEffect(() => {\n const next = getter ? getter() : props.resetKeys\n if (prev !== next) {\n prev = next\n renderValue(toView(null))\n }\n })\n }\n\n return fragment\n}\n","import { createElement } from './dom'\nimport { createEffect } from './effect'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n handleError,\n pushRoot,\n popRoot,\n registerSuspenseHandler,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport { createSignal } from './signal'\nimport type { BaseProps, FictNode, SuspenseToken } from './types'\n\nexport interface SuspenseProps extends BaseProps {\n fallback: FictNode | ((err?: unknown) => FictNode)\n onResolve?: () => void\n onReject?: (err: unknown) => void\n resetKeys?: unknown | (() => unknown)\n}\n\nexport interface SuspenseHandle {\n token: SuspenseToken\n resolve: () => void\n reject: (err: unknown) => void\n}\n\nexport function createSuspenseToken(): SuspenseHandle {\n let resolve!: () => void\n let reject!: (err: unknown) => void\n const promise = new Promise<void>((res, rej) => {\n resolve = res\n reject = rej\n })\n return {\n token: {\n then: promise.then.bind(promise),\n },\n resolve,\n reject,\n }\n}\n\nconst isThenable = (value: unknown): value is PromiseLike<unknown> =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as PromiseLike<unknown>).then === 'function'\n\nexport function Suspense(props: SuspenseProps): FictNode {\n const currentView = createSignal<FictNode | null>(props.children ?? null)\n const pending = createSignal(0)\n let resolvedOnce = false\n let epoch = 0\n const hostRoot = getCurrentRoot()\n\n const toFallback = (err?: unknown) =>\n typeof props.fallback === 'function'\n ? (props.fallback as (e?: unknown) => FictNode)(err)\n : props.fallback\n\n const switchView = (view: FictNode | null) => {\n currentView(view)\n renderView(view)\n }\n\n const renderView = (view: FictNode | null) => {\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (view == null || view === false) {\n return\n }\n\n const root = createRootContext(hostRoot)\n const prev = pushRoot(root)\n let nodes: Node[] = []\n try {\n const output = createElement(view)\n nodes = toNodeArray(output)\n // Suspended view: child threw a suspense token and was handled upstream.\n // Avoid replacing existing fallback content; tear down this attempt.\n const suspendedAttempt =\n nodes.length > 0 &&\n nodes.every(node => node instanceof Comment && (node as Comment).data === 'fict:suspend')\n if (suspendedAttempt) {\n popRoot(prev)\n destroyRoot(root)\n return\n }\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } catch (err) {\n popRoot(prev)\n flushOnMount(root)\n destroyRoot(root)\n if (!handleError(err, { source: 'render' }, hostRoot)) {\n throw err\n }\n return\n }\n popRoot(prev)\n flushOnMount(root)\n\n cleanup = () => {\n destroyRoot(root)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:suspense')\n fragment.appendChild(marker)\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n\n const onResolveMaybe = () => {\n if (!resolvedOnce) {\n resolvedOnce = true\n props.onResolve?.()\n }\n }\n\n registerSuspenseHandler(token => {\n const tokenEpoch = epoch\n pending(pending() + 1)\n switchView(toFallback())\n\n const thenable = (token as SuspenseToken).then\n ? (token as SuspenseToken)\n : isThenable(token)\n ? token\n : null\n\n if (thenable) {\n thenable.then(\n () => {\n // This prevents stale token resolutions from affecting state after\n // a reset. The order is important: check epoch first, then update state.\n if (epoch !== tokenEpoch) {\n // Token is stale (from before a reset), ignore it completely\n return\n }\n // Use Math.max as a defensive measure - pending should never go below 0,\n // but this protects against edge cases where a token might resolve twice\n // or after the component has been reset.\n const newPending = Math.max(0, pending() - 1)\n pending(newPending)\n if (newPending === 0) {\n switchView(props.children ?? null)\n onResolveMaybe()\n }\n },\n err => {\n // Same epoch check - ignore stale tokens\n if (epoch !== tokenEpoch) {\n return\n }\n const newPending = Math.max(0, pending() - 1)\n pending(newPending)\n props.onReject?.(err)\n if (!handleError(err, { source: 'render' }, hostRoot)) {\n throw err\n }\n },\n )\n return true\n }\n\n return false\n })\n\n createEffect(() => {\n renderView(currentView())\n })\n\n if (props.resetKeys !== undefined) {\n const isGetter =\n typeof props.resetKeys === 'function' && (props.resetKeys as () => unknown).length === 0\n const getter = isGetter ? (props.resetKeys as () => unknown) : undefined\n let prev = isGetter ? getter!() : props.resetKeys\n createEffect(() => {\n const next = getter ? getter() : props.resetKeys\n if (prev !== next) {\n prev = next\n epoch++\n pending(0)\n switchView(props.children ?? null)\n }\n })\n }\n\n return fragment\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/fict/fict/packages/runtime/dist/index.cjs","../src/ref.ts","../src/error-boundary.ts","../src/suspense.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AChBO,SAAS,SAAA,CAAA,EAA2D;AACzE,EAAA,OAAO,EAAE,OAAA,EAAS,KAAK,CAAA;AACzB;ADkBA;AACA;AEvBO,SAAS,aAAA,CAAc,KAAA,EAAqC;AACjE,EAAA,MAAM,SAAA,EAAW,QAAA,CAAS,sBAAA,CAAuB,CAAA;AACjD,EAAA,MAAM,OAAA,EAAS,QAAA,CAAS,aAAA,CAAc,qBAAqB,CAAA;AAC3D,EAAA,QAAA,CAAS,WAAA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RefObject } from './types'\n\n/**\n * Create a ref object for DOM element references.\n *\n * @returns A ref object with a `current` property initialized to `null`\n *\n * @example\n * ```tsx\n * import { createRef } from 'fict'\n *\n * function Component() {\n * const inputRef = createRef<HTMLInputElement>()\n *\n * $effect(() => {\n * inputRef.current?.focus()\n * })\n *\n * return <input ref={inputRef} />\n * }\n * ```\n */\nexport function createRef<T extends Element = HTMLElement>(): RefObject<T> {\n return { current: null }\n}\n","import { createElement } from './dom'\nimport { createEffect } from './effect'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n pushRoot,\n popRoot,\n registerErrorHandler,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport type { BaseProps, FictNode } from './types'\n\ninterface ErrorBoundaryProps extends BaseProps {\n fallback: FictNode | ((err: unknown, reset?: () => void) => FictNode)\n onError?: (err: unknown) => void\n resetKeys?: unknown | (() => unknown)\n}\n\nexport function ErrorBoundary(props: ErrorBoundaryProps): FictNode {\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:error-boundary')\n fragment.appendChild(marker)\n\n const hostRoot = getCurrentRoot()\n\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n let renderingFallback = false\n\n let reset = () => {}\n const toView = (err: unknown | null): FictNode | null => {\n if (err != null) {\n return typeof props.fallback === 'function'\n ? (props.fallback as (e: unknown, reset?: () => void) => FictNode)(err, reset)\n : props.fallback\n }\n return props.children ?? null\n }\n\n const renderValue = (value: FictNode | null) => {\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (value == null || value === false) {\n return\n }\n\n const root = createRootContext(hostRoot)\n const prev = pushRoot(root)\n let nodes: Node[] = []\n try {\n const output = createElement(value)\n nodes = toNodeArray(output)\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } catch (err) {\n popRoot(prev)\n destroyRoot(root)\n // Fall back immediately on render errors, avoid infinite recursion\n if (renderingFallback) {\n throw err\n }\n // nested errors. If fallback rendering also throws, we should NOT reset\n // the flag until we're sure no more recursion is happening.\n renderingFallback = true\n try {\n renderValue(toView(err))\n // Only reset if successful - if renderValue threw, we want to keep\n // renderingFallback = true to prevent infinite recursion\n renderingFallback = false\n props.onError?.(err)\n } catch (fallbackErr) {\n // Fallback rendering failed - keep renderingFallback = true\n // to prevent further attempts, then rethrow\n // If fallback fails, report both errors\n props.onError?.(err)\n throw fallbackErr\n }\n return\n }\n popRoot(prev)\n flushOnMount(root)\n\n cleanup = () => {\n destroyRoot(root)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n reset = () => {\n renderingFallback = false\n renderValue(toView(null))\n }\n\n renderValue(props.children ?? null)\n\n registerErrorHandler(err => {\n renderValue(toView(err))\n props.onError?.(err)\n return true\n })\n\n if (props.resetKeys !== undefined) {\n const isGetter =\n typeof props.resetKeys === 'function' && (props.resetKeys as () => unknown).length === 0\n const getter = isGetter ? (props.resetKeys as () => unknown) : undefined\n let prev = isGetter ? getter!() : props.resetKeys\n createEffect(() => {\n const next = getter ? getter() : props.resetKeys\n if (prev !== next) {\n prev = next\n renderValue(toView(null))\n }\n })\n }\n\n return fragment\n}\n","import { createElement } from './dom'\nimport { createEffect } from './effect'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n handleError,\n pushRoot,\n popRoot,\n registerSuspenseHandler,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport { createSignal } from './signal'\nimport type { BaseProps, FictNode, SuspenseToken } from './types'\n\nexport interface SuspenseProps extends BaseProps {\n fallback: FictNode | ((err?: unknown) => FictNode)\n onResolve?: () => void\n onReject?: (err: unknown) => void\n resetKeys?: unknown | (() => unknown)\n}\n\nexport interface SuspenseHandle {\n token: SuspenseToken\n resolve: () => void\n reject: (err: unknown) => void\n}\n\nexport function createSuspenseToken(): SuspenseHandle {\n let resolve!: () => void\n let reject!: (err: unknown) => void\n const promise = new Promise<void>((res, rej) => {\n resolve = res\n reject = rej\n })\n return {\n token: {\n then: promise.then.bind(promise),\n },\n resolve,\n reject,\n }\n}\n\nconst isThenable = (value: unknown): value is PromiseLike<unknown> =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as PromiseLike<unknown>).then === 'function'\n\nexport function Suspense(props: SuspenseProps): FictNode {\n const pending = createSignal(0)\n let resolvedOnce = false\n let epoch = 0\n const hostRoot = getCurrentRoot()\n\n const toFallback = (err?: unknown) =>\n typeof props.fallback === 'function'\n ? (props.fallback as (e?: unknown) => FictNode)(err)\n : props.fallback\n\n const renderView = (view: FictNode | null) => {\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (view == null || view === false) {\n return\n }\n\n const root = createRootContext(hostRoot)\n const prev = pushRoot(root)\n let nodes: Node[] = []\n try {\n const output = createElement(view)\n nodes = toNodeArray(output)\n // Suspended view: child threw a suspense token and was handled upstream.\n // Avoid replacing existing fallback content; tear down this attempt.\n const suspendedAttempt =\n root.suspended ||\n (nodes.length > 0 &&\n nodes.every(node => node instanceof Comment && (node as Comment).data === 'fict:suspend'))\n if (suspendedAttempt) {\n popRoot(prev)\n destroyRoot(root)\n return\n }\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } catch (err) {\n popRoot(prev)\n destroyRoot(root)\n if (!handleError(err, { source: 'render' }, hostRoot)) {\n throw err\n }\n return\n }\n popRoot(prev)\n flushOnMount(root)\n\n cleanup = () => {\n destroyRoot(root)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:suspense')\n fragment.appendChild(marker)\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n\n const onResolveMaybe = () => {\n if (!resolvedOnce) {\n resolvedOnce = true\n props.onResolve?.()\n }\n }\n\n registerSuspenseHandler(token => {\n const tokenEpoch = epoch\n pending(pending() + 1)\n // Directly render fallback instead of using switchView to avoid\n // triggering the effect which would cause duplicate renders\n renderView(toFallback())\n\n const thenable = (token as SuspenseToken).then\n ? (token as SuspenseToken)\n : isThenable(token)\n ? token\n : null\n\n if (thenable) {\n thenable.then(\n () => {\n // This prevents stale token resolutions from affecting state after\n // a reset. The order is important: check epoch first, then update state.\n if (epoch !== tokenEpoch) {\n // Token is stale (from before a reset), ignore it completely\n return\n }\n // Use Math.max as a defensive measure - pending should never go below 0,\n // but this protects against edge cases where a token might resolve twice\n // or after the component has been reset.\n const newPending = Math.max(0, pending() - 1)\n pending(newPending)\n if (newPending === 0) {\n // Directly render children instead of using switchView\n renderView(props.children ?? null)\n onResolveMaybe()\n }\n },\n err => {\n // Same epoch check - ignore stale tokens\n if (epoch !== tokenEpoch) {\n return\n }\n const newPending = Math.max(0, pending() - 1)\n pending(newPending)\n props.onReject?.(err)\n if (!handleError(err, { source: 'render' }, hostRoot)) {\n throw err\n }\n },\n )\n return true\n }\n\n return false\n })\n\n // Initial render - render children directly\n // Note: This will be called synchronously during component creation.\n // If children suspend, the handler above will be called and switch to fallback.\n renderView(props.children ?? null)\n\n if (props.resetKeys !== undefined) {\n const isGetter =\n typeof props.resetKeys === 'function' && (props.resetKeys as () => unknown).length === 0\n const getter = isGetter ? (props.resetKeys as () => unknown) : undefined\n let prev = isGetter ? getter!() : props.resetKeys\n createEffect(() => {\n const next = getter ? getter() : props.resetKeys\n if (prev !== next) {\n prev = next\n epoch++\n pending(0)\n // Directly render children instead of using switchView\n renderView(props.children ?? null)\n }\n })\n }\n\n return fragment\n}\n"]}