@pyreon/core 0.3.0 → 0.3.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.
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/lifecycle.ts","../src/component.ts","../src/context.ts","../src/h.ts","../src/dynamic.ts","../src/telemetry.ts","../src/error-boundary.ts","../src/for.ts","../src/lazy.ts","../src/map-array.ts","../src/portal.ts","../src/ref.ts","../src/show.ts","../src/suspense.ts"],"sourcesContent":["import type { CleanupFn, LifecycleHooks } from \"./types\"\n\n// The currently-executing component's hook storage, set by the renderer\n// before calling the component function, cleared immediately after.\nlet _current: LifecycleHooks | null = null\n\nexport function setCurrentHooks(hooks: LifecycleHooks | null) {\n _current = hooks\n}\n\nexport function getCurrentHooks(): LifecycleHooks | null {\n return _current\n}\n\n/**\n * Register a callback to run after the component is mounted to the DOM.\n * Optionally return a cleanup function — it will run on unmount.\n */\nexport function onMount(fn: () => CleanupFn | undefined) {\n _current?.mount.push(fn)\n}\n\n/**\n * Register a callback to run when the component is removed from the DOM.\n */\nexport function onUnmount(fn: () => void) {\n _current?.unmount.push(fn)\n}\n\n/**\n * Register a callback to run after each reactive update.\n */\nexport function onUpdate(fn: () => void) {\n _current?.update.push(fn)\n}\n\n/**\n * Register an error handler for this component subtree.\n *\n * When an error is thrown during rendering or in a child component,\n * the nearest `onErrorCaptured` handler is called with the error.\n * Return `true` to mark the error as handled and stop propagation.\n *\n * @example\n * onErrorCaptured((err) => {\n * setError(String(err))\n * return true // handled — don't propagate\n * })\n */\nexport function onErrorCaptured(fn: (err: unknown) => boolean | undefined) {\n _current?.error.push(fn)\n}\n","import { setCurrentHooks } from \"./lifecycle\"\nimport type { ComponentFn, LifecycleHooks, Props, VNode } from \"./types\"\n\n/**\n * Identity wrapper — marks a function as a Pyreon component and preserves its type.\n * Useful for IDE tooling and future compiler optimisations.\n */\nexport function defineComponent<P extends Props>(fn: ComponentFn<P>): ComponentFn<P> {\n return fn\n}\n\n/**\n * Run a component function in a tracked context so that lifecycle hooks\n * registered inside it (onMount, onUnmount, onErrorCaptured, etc.) are captured.\n *\n * Called by the renderer — not intended for user code.\n */\nexport function runWithHooks<P extends Props>(\n fn: ComponentFn<P>,\n props: P,\n): { vnode: VNode | null; hooks: LifecycleHooks } {\n const hooks: LifecycleHooks = { mount: [], unmount: [], update: [], error: [] }\n setCurrentHooks(hooks)\n let vnode: VNode | null = null\n try {\n vnode = fn(props)\n } finally {\n setCurrentHooks(null)\n }\n return { vnode, hooks }\n}\n\n/**\n * Walk up error handlers collected during component rendering.\n * Returns true if any handler marked the error as handled.\n */\nexport function propagateError(err: unknown, hooks: LifecycleHooks): boolean {\n for (const handler of hooks.error) {\n if (handler(err) === true) return true\n }\n return false\n}\n\n// ─── Error boundary stack ────────────────────────────────────────────────────\n// Module-level stack of active ErrorBoundary handlers (innermost last).\n// ErrorBoundary pushes during its own setup (before children mount) so that\n// any child mountComponent error can dispatch up to the nearest boundary.\n\nconst _errorBoundaryStack: ((err: unknown) => boolean)[] = []\n\nexport function pushErrorBoundary(handler: (err: unknown) => boolean): void {\n _errorBoundaryStack.push(handler)\n}\n\nexport function popErrorBoundary(): void {\n _errorBoundaryStack.pop()\n}\n\n/**\n * Dispatch an error to the nearest active ErrorBoundary.\n * Returns true if the boundary handled it, false if none was registered.\n */\nexport function dispatchToErrorBoundary(err: unknown): boolean {\n const handler = _errorBoundaryStack[_errorBoundaryStack.length - 1]\n return handler ? handler(err) : false\n}\n","/**\n * Provide / inject — like React context or Vue provide/inject.\n *\n * Values flow down the component tree without prop-drilling.\n * The renderer maintains the context stack as it walks the VNode tree.\n */\n\nexport interface Context<T> {\n readonly id: symbol\n readonly defaultValue: T\n}\n\nexport function createContext<T>(defaultValue: T): Context<T> {\n return { id: Symbol(\"PyreonContext\"), defaultValue }\n}\n\n// ─── Runtime context stack (managed by the renderer) ─────────────────────────\n\n// Default stack — used for CSR and single-threaded SSR.\n// On Node.js with concurrent requests, @pyreon/runtime-server replaces this with\n// an AsyncLocalStorage-backed provider via setContextStackProvider().\nconst _defaultStack: Map<symbol, unknown>[] = []\nlet _stackProvider: () => Map<symbol, unknown>[] = () => _defaultStack\n\n/**\n * Override the context stack provider. Called by @pyreon/runtime-server to\n * inject an AsyncLocalStorage-backed stack that isolates concurrent SSR requests.\n * Has no effect in the browser (CSR always uses the default module-level stack).\n */\nexport function setContextStackProvider(fn: () => Map<symbol, unknown>[]): void {\n _stackProvider = fn\n}\n\nfunction getStack(): Map<symbol, unknown>[] {\n return _stackProvider()\n}\n\nconst __DEV__ = typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\"\n\nexport function pushContext(values: Map<symbol, unknown>) {\n getStack().push(values)\n}\n\nexport function popContext() {\n const stack = getStack()\n if (__DEV__ && stack.length === 0) {\n return\n }\n stack.pop()\n}\n\n/**\n * Read the nearest provided value for a context.\n * Falls back to `context.defaultValue` if none found.\n */\nexport function useContext<T>(context: Context<T>): T {\n const stack = getStack()\n for (let i = stack.length - 1; i >= 0; i--) {\n const frame = stack[i]\n if (frame?.has(context.id)) {\n return frame.get(context.id) as T\n }\n }\n return context.defaultValue\n}\n\n/**\n * Provide a value for `context` during `fn()`.\n * Used by the renderer when it encounters a `<Provider>` component.\n */\nexport function withContext<T>(context: Context<T>, value: T, fn: () => void) {\n const frame = new Map<symbol, unknown>([[context.id, value]])\n pushContext(frame)\n try {\n fn()\n } finally {\n popContext()\n }\n}\n","import type { ComponentFn, Props, VNode, VNodeChild } from \"./types\"\n\n/** Marker for fragment nodes — renders children without a wrapper element */\nexport const Fragment: unique symbol = Symbol(\"Pyreon.Fragment\")\n\n/**\n * Hyperscript function — the compiled output of JSX.\n * `<div class=\"x\">hello</div>` → `h(\"div\", { class: \"x\" }, \"hello\")`\n *\n * Generic on P so TypeScript validates props match the component's signature\n * at the call site, then stores the result in the loosely-typed VNode.\n */\n/** Shared empty props sentinel — identity-checked in mountElement to skip applyProps. */\nexport const EMPTY_PROPS: Props = {} as Props\n\nexport function h<P extends Props>(\n type: string | ComponentFn<P> | symbol,\n props: P | null,\n ...children: VNodeChild[]\n): VNode {\n return {\n type: type as string | ComponentFn | symbol,\n props: (props ?? EMPTY_PROPS) as Props,\n children: normalizeChildren(children),\n key: (props?.key as string | number | null) ?? null,\n }\n}\n\nfunction normalizeChildren(children: VNodeChild[]): VNodeChild[] {\n // Fast path: no nested arrays — return as-is without allocating\n for (let i = 0; i < children.length; i++) {\n if (Array.isArray(children[i])) {\n return flattenChildren(children)\n }\n }\n return children\n}\n\nfunction flattenChildren(children: VNodeChild[]): VNodeChild[] {\n const result: VNodeChild[] = []\n for (const child of children) {\n if (Array.isArray(child)) {\n result.push(...flattenChildren(child as VNodeChild[]))\n } else {\n result.push(child)\n }\n }\n return result\n}\n","import { h } from \"./h\"\nimport type { ComponentFn, Props, VNode } from \"./types\"\n\nexport interface DynamicProps extends Props {\n component: ComponentFn | string\n}\n\nexport function Dynamic(props: DynamicProps): VNode | null {\n const { component, ...rest } = props\n if (!component) return null\n return h(component as string | ComponentFn, rest as Props)\n}\n","/**\n * Error telemetry — hook into Pyreon's error reporting for Sentry, Datadog, etc.\n *\n * @example\n * import { registerErrorHandler } from \"@pyreon/core\"\n * import * as Sentry from \"@sentry/browser\"\n *\n * registerErrorHandler(ctx => {\n * Sentry.captureException(ctx.error, {\n * extra: { component: ctx.component, phase: ctx.phase },\n * })\n * })\n */\n\nexport interface ErrorContext {\n /** Component function name, or \"Anonymous\" */\n component: string\n /** Lifecycle phase where the error occurred */\n phase: \"setup\" | \"render\" | \"mount\" | \"unmount\" | \"effect\"\n /** The thrown value */\n error: unknown\n /** Unix timestamp (ms) */\n timestamp: number\n /** Component props at the time of the error */\n props?: Record<string, unknown>\n}\n\nexport type ErrorHandler = (ctx: ErrorContext) => void\n\nlet _handlers: ErrorHandler[] = []\n\n/**\n * Register a global error handler. Called whenever a component throws in any\n * lifecycle phase. Returns an unregister function.\n */\nexport function registerErrorHandler(handler: ErrorHandler): () => void {\n _handlers.push(handler)\n return () => {\n _handlers = _handlers.filter((h) => h !== handler)\n }\n}\n\n/**\n * Internal — called by the runtime whenever a component error is caught.\n * Existing console.error calls are preserved; this is additive.\n */\nexport function reportError(ctx: ErrorContext): void {\n for (const h of _handlers) {\n try {\n h(ctx)\n } catch {\n // handler errors must never propagate back into the framework\n }\n }\n}\n","import { signal } from \"@pyreon/reactivity\"\nimport { popErrorBoundary, pushErrorBoundary } from \"./component\"\nimport { onUnmount } from \"./lifecycle\"\nimport { reportError } from \"./telemetry\"\nimport type { VNodeChild, VNodeChildAtom } from \"./types\"\n\n/**\n * ErrorBoundary — catches errors thrown by child components and renders a\n * fallback UI instead of crashing the whole tree.\n *\n * Also reports caught errors to any registered telemetry handlers.\n *\n * How error propagation works:\n * ErrorBoundary pushes a handler onto the module-level boundary stack\n * synchronously during its own setup (before children are mounted).\n * When mountComponent catches a child error, it calls dispatchToErrorBoundary()\n * which invokes the innermost boundary's handler.\n *\n * Usage:\n * h(ErrorBoundary, {\n * fallback: (err) => h(\"p\", null, `Error: ${err}`),\n * children: h(MyComponent, null),\n * })\n *\n * // or with JSX:\n * <ErrorBoundary fallback={(err) => <p>Error: {String(err)}</p>}>\n * <MyComponent />\n * </ErrorBoundary>\n */\nexport function ErrorBoundary(props: {\n /**\n * Rendered when a child throws. Receives the caught error and a `reset`\n * function — calling `reset()` clears the error and re-renders children.\n */\n fallback: (err: unknown, reset: () => void) => VNodeChild\n children?: VNodeChild\n}): VNodeChild {\n const error = signal<unknown>(null)\n const reset = () => error.set(null)\n\n const handler = (err: unknown): boolean => {\n if (error.peek() !== null) return false // already in error state — let outer boundary catch it\n error.set(err)\n reportError({ component: \"ErrorBoundary\", phase: \"render\", error: err, timestamp: Date.now() })\n return true\n }\n\n // Push synchronously — before children are mounted — so child errors see this boundary\n pushErrorBoundary(handler)\n onUnmount(() => popErrorBoundary())\n\n return (): VNodeChildAtom => {\n const err = error()\n if (err != null) return props.fallback(err, reset) as VNodeChildAtom\n const ch = props.children\n return (typeof ch === \"function\" ? ch() : ch) as VNodeChildAtom\n }\n}\n","import type { NativeItem, Props, VNode } from \"./types\"\n\n/**\n * Symbol used as the VNode type for a For list — runtime-dom handles it\n * via mountFor, bypassing the generic VNode reconciler.\n */\nexport const ForSymbol: unique symbol = Symbol(\"pyreon.For\")\n\nexport interface ForProps<T> {\n each: () => T[]\n by: (item: T) => string | number\n children: (item: T) => VNode | NativeItem\n}\n\n/**\n * Efficient reactive list rendering.\n *\n * Unlike a plain `() => items().map(item => h(...))`, For never re-creates\n * VNodes for existing keys — only new keys invoke `children()`. Structural\n * mutations (swap, sort, filter) are O(n) key scan + O(k) DOM moves where k\n * is the number of actually displaced entries.\n *\n * Usage:\n * <For each={items} by={r => r.id}>{r => <li>...</li>}</For>\n */\nexport function For<T>(props: ForProps<T>): VNode {\n return {\n type: ForSymbol as unknown as string,\n props: props as unknown as Props,\n children: [],\n key: null,\n }\n}\n","import { signal } from \"@pyreon/reactivity\"\nimport { h } from \"./h\"\nimport type { LazyComponent } from \"./suspense\"\nimport type { ComponentFn, Props } from \"./types\"\n\nexport function lazy<P extends Props>(\n load: () => Promise<{ default: ComponentFn<P> }>,\n): LazyComponent<P> {\n const loaded = signal<ComponentFn<P> | null>(null)\n const error = signal<Error | null>(null)\n\n load()\n .then((m) => loaded.set(m.default))\n .catch((e) => error.set(e instanceof Error ? e : new Error(String(e))))\n\n const wrapper = ((props: P) => {\n const err = error()\n if (err) throw err\n const comp = loaded()\n return comp ? h(comp as ComponentFn, props as Props) : null\n }) as LazyComponent<P>\n\n wrapper.__loading = () => loaded() === null && error() === null\n return wrapper\n}\n","/**\n * mapArray — keyed reactive list mapping.\n *\n * Creates each mapped item exactly once per key, then reuses it across\n * updates. When the source array is reordered or partially changed, only\n * new keys invoke `map()`; existing entries return the cached result.\n *\n * This makes structural list operations (swap, sort, filter) O(k) in\n * allocations where k is the number of new/removed keys, not O(n).\n *\n * The returned accessor reads `source()` reactively, so it can be passed\n * directly to the keyed-list reconciler.\n */\nexport function mapArray<T, U>(\n source: () => T[],\n getKey: (item: T) => string | number,\n map: (item: T) => U,\n): () => U[] {\n const cache = new Map<string | number, U>()\n\n return () => {\n const items = source()\n const result: U[] = []\n const newKeys = new Set<string | number>()\n\n for (const item of items) {\n const key = getKey(item)\n newKeys.add(key)\n if (!cache.has(key)) {\n cache.set(key, map(item))\n }\n result.push(cache.get(key) as U)\n }\n\n // Evict entries whose keys are no longer present\n for (const key of cache.keys()) {\n if (!newKeys.has(key)) cache.delete(key)\n }\n\n return result\n }\n}\n","import type { Props, VNode, VNodeChild } from \"./types\"\n\n/**\n * Symbol used as the VNode type for a Portal — runtime-dom mounts the\n * children into `target` instead of the normal parent.\n */\nexport const PortalSymbol: unique symbol = Symbol(\"pyreon.Portal\")\n\nexport interface PortalProps {\n /** DOM element to render children into (e.g. document.body). */\n target: Element\n children: VNodeChild\n}\n\n/**\n * Portal — renders `children` into a different DOM node than the\n * current parent tree.\n *\n * Useful for modals, tooltips, dropdowns, and any overlay that needs to\n * escape CSS overflow/stacking context restrictions.\n *\n * @example\n * // Render a modal at document.body level regardless of where in the\n * // component tree <Modal> is used:\n * Portal({ target: document.body, children: h(Modal, { onClose }) })\n *\n * // JSX:\n * <Portal target={document.body}>\n * <Modal onClose={close} />\n * </Portal>\n */\nexport function Portal(props: PortalProps): VNode {\n return {\n type: PortalSymbol as unknown as string,\n props: props as unknown as Props,\n children: [],\n key: null,\n }\n}\n","/**\n * createRef — mutable container for a DOM element or component value.\n *\n * Usage:\n * const inputRef = createRef<HTMLInputElement>()\n * onMount(() => { inputRef.current?.focus() })\n * return <input ref={inputRef} />\n *\n * The runtime sets `ref.current` after the element is inserted into the DOM\n * and clears it to `null` when the element is removed.\n */\n\nexport interface Ref<T = unknown> {\n current: T | null\n}\n\nexport function createRef<T = unknown>(): Ref<T> {\n return { current: null }\n}\n","import type { Props, VNode, VNodeChild, VNodeChildAtom } from \"./types\"\n\n// ─── Show ─────────────────────────────────────────────────────────────────────\n\nexport interface ShowProps extends Props {\n /** Accessor — children render when truthy, fallback when falsy. */\n when: () => unknown\n fallback?: VNodeChild\n children?: VNodeChild\n}\n\n/**\n * Conditionally render children based on a reactive condition.\n *\n * @example\n * h(Show, { when: () => isLoggedIn() },\n * h(Dashboard, null)\n * )\n *\n * // With fallback:\n * h(Show, { when: () => user(), fallback: h(Login, null) },\n * h(Dashboard, null)\n * )\n */\nexport function Show(props: ShowProps): VNode | null {\n // Returns a reactive accessor; the renderer unwraps it at mount time.\n return ((): VNodeChildAtom =>\n (props.when()\n ? (props.children ?? null)\n : (props.fallback ?? null)) as VNodeChildAtom) as unknown as VNode\n}\n\n// ─── Switch / Match ───────────────────────────────────────────────────────────\n\nexport interface MatchProps extends Props {\n /** Accessor — this branch renders when truthy. */\n when: () => unknown\n children?: VNodeChild\n}\n\n/**\n * A branch inside `<Switch>`. Renders when `when()` is truthy.\n * Must be used as a direct child of `Switch`.\n *\n * `Match` acts as a pure type/identity marker — Switch identifies it by checking\n * `vnode.type === Match` rather than by the runtime return value.\n */\nexport function Match(_props: MatchProps): VNode | null {\n // Match is never mounted directly — Switch inspects Match VNodes by type identity.\n return null\n}\n\nexport interface SwitchProps extends Props {\n /** Rendered when no Match branch is truthy. */\n fallback?: VNodeChild\n children?: VNodeChild | VNodeChild[]\n}\n\n/**\n * Multi-branch conditional rendering. Evaluates each `Match` child in order,\n * renders the first whose `when()` is truthy, or `fallback` if none match.\n *\n * @example\n * h(Switch, { fallback: h(\"p\", null, \"404\") },\n * h(Match, { when: () => route() === \"/\" }, h(Home, null)),\n * h(Match, { when: () => route() === \"/about\" }, h(About, null)),\n * )\n */\nfunction isMatchVNode(branch: VNodeChild): branch is VNode {\n return (\n branch !== null &&\n typeof branch === \"object\" &&\n !Array.isArray(branch) &&\n (branch as VNode).type === Match\n )\n}\n\nfunction resolveMatchChildren(matchVNode: VNode): VNodeChildAtom {\n if (matchVNode.children.length === 0) {\n return ((matchVNode.props as unknown as MatchProps).children ?? null) as VNodeChildAtom\n }\n if (matchVNode.children.length === 1) return matchVNode.children[0] as VNodeChildAtom\n return matchVNode.children as unknown as VNodeChildAtom\n}\n\nfunction normalizeBranches(children: SwitchProps[\"children\"]): VNodeChild[] {\n if (Array.isArray(children)) return children\n if (children != null) return [children]\n return []\n}\n\nexport function Switch(props: SwitchProps): VNode | null {\n // Returns a reactive accessor; the renderer unwraps it at mount time.\n return ((): VNodeChildAtom => {\n const branches = normalizeBranches(props.children)\n\n for (const branch of branches) {\n if (!isMatchVNode(branch)) continue\n const matchProps = branch.props as unknown as MatchProps\n if (matchProps.when()) return resolveMatchChildren(branch)\n }\n\n return (props.fallback ?? null) as VNodeChildAtom\n }) as unknown as VNode\n}\n\n// Keep MatchSymbol export for any code that was using it\nexport const MatchSymbol: unique symbol = Symbol(\"pyreon.Match\")\n","import { Fragment, h } from \"./h\"\nimport type { Props, VNode, VNodeChild } from \"./types\"\n\n/** Internal marker attached to lazy()-wrapped components */\nexport type LazyComponent<P extends Props = Props> = ((props: P) => VNode | null) & {\n __loading: () => boolean\n}\n\n/**\n * Suspense — shows `fallback` while a lazy child component is still loading.\n *\n * Works in tandem with `lazy()` from `@pyreon/react-compat` (or `@pyreon/core/lazy`).\n * The child VNode's `.type.__loading()` signal drives the switch.\n *\n * Usage:\n * const Page = lazy(() => import(\"./Page\"))\n *\n * h(Suspense, { fallback: h(Spinner, null) }, h(Page, null))\n * // or with JSX:\n * <Suspense fallback={<Spinner />}><Page /></Suspense>\n */\nexport function Suspense(props: { fallback: VNodeChild; children?: VNodeChild }): VNode {\n return h(Fragment, null, () => {\n const ch = props.children\n const childNode = typeof ch === \"function\" ? ch() : ch\n\n // Check if the child is a VNode whose type is a lazy component still loading\n const isLoading =\n childNode != null &&\n typeof childNode === \"object\" &&\n !Array.isArray(childNode) &&\n typeof (childNode as VNode).type === \"function\" &&\n ((childNode as VNode).type as unknown as LazyComponent).__loading?.()\n\n if (isLoading) {\n const fb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,QAAqC;AACzD,QACE,WAAW,QACX,OAAO,WAAW,YAClB,CAAC,MAAM,QAAQ,OAAO,IACrB,OAAiB,SAAS;;AAI/B,SAAS,qBAAqB,YAAmC;AAC/D,KAAI,WAAW,SAAS,WAAW,EACjC,QAAS,WAAW,MAAgC,YAAY;AAElE,KAAI,WAAW,SAAS,WAAW,EAAG,QAAO,WAAW,SAAS;AACjE,QAAO,WAAW;;AAGpB,SAAS,kBAAkB,UAAiD;AAC1E,KAAI,MAAM,QAAQ,SAAS,CAAE,QAAO;AACpC,KAAI,YAAY,KAAM,QAAO,CAAC,SAAS;AACvC,QAAO,EAAE;;AAGX,SAAgB,OAAO,OAAkC;AAEvD,eAA8B;EAC5B,MAAM,WAAW,kBAAkB,MAAM,SAAS;AAElD,OAAK,MAAM,UAAU,UAAU;AAC7B,OAAI,CAAC,aAAa,OAAO,CAAE;AAE3B,OADmB,OAAO,MACX,MAAM,CAAE,QAAO,qBAAqB,OAAO;;AAG5D,SAAQ,MAAM,YAAY;;;AAK9B,MAAa,cAA6B,OAAO,eAAe;;;;;;;;;;;;;;;;;ACtFhE,SAAgB,SAAS,OAA+D;AACtF,QAAO,EAAE,UAAU,YAAY;EAC7B,MAAM,KAAK,MAAM;EACjB,MAAM,YAAY,OAAO,OAAO,aAAa,IAAI,GAAG;AAUpD,MANE,aAAa,QACb,OAAO,cAAc,YACrB,CAAC,MAAM,QAAQ,UAAU,IACzB,OAAQ,UAAoB,SAAS,cACnC,UAAoB,KAAkC,aAAa,EAExD;GACb,MAAM,KAAK,MAAM;AACjB,UAAO,OAAO,OAAO,aAAa,IAAI,GAAG;;AAE3C,SAAO;GACP"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/lifecycle.ts","../src/component.ts","../src/context.ts","../src/h.ts","../src/dynamic.ts","../src/telemetry.ts","../src/error-boundary.ts","../src/for.ts","../src/lazy.ts","../src/map-array.ts","../src/portal.ts","../src/ref.ts","../src/show.ts","../src/suspense.ts"],"sourcesContent":["import type { CleanupFn, LifecycleHooks } from \"./types\"\n\n// The currently-executing component's hook storage, set by the renderer\n// before calling the component function, cleared immediately after.\nlet _current: LifecycleHooks | null = null\n\nexport function setCurrentHooks(hooks: LifecycleHooks | null) {\n _current = hooks\n}\n\nexport function getCurrentHooks(): LifecycleHooks | null {\n return _current\n}\n\n/**\n * Register a callback to run after the component is mounted to the DOM.\n * Optionally return a cleanup function — it will run on unmount.\n */\nexport function onMount(fn: () => CleanupFn | undefined) {\n _current?.mount.push(fn)\n}\n\n/**\n * Register a callback to run when the component is removed from the DOM.\n */\nexport function onUnmount(fn: () => void) {\n _current?.unmount.push(fn)\n}\n\n/**\n * Register a callback to run after each reactive update.\n */\nexport function onUpdate(fn: () => void) {\n _current?.update.push(fn)\n}\n\n/**\n * Register an error handler for this component subtree.\n *\n * When an error is thrown during rendering or in a child component,\n * the nearest `onErrorCaptured` handler is called with the error.\n * Return `true` to mark the error as handled and stop propagation.\n *\n * @example\n * onErrorCaptured((err) => {\n * setError(String(err))\n * return true // handled — don't propagate\n * })\n */\nexport function onErrorCaptured(fn: (err: unknown) => boolean | undefined) {\n _current?.error.push(fn)\n}\n","import { setCurrentHooks } from \"./lifecycle\"\nimport type { ComponentFn, LifecycleHooks, Props, VNode } from \"./types\"\n\n/**\n * Identity wrapper — marks a function as a Pyreon component and preserves its type.\n * Useful for IDE tooling and future compiler optimisations.\n */\nexport function defineComponent<P extends Props>(fn: ComponentFn<P>): ComponentFn<P> {\n return fn\n}\n\n/**\n * Run a component function in a tracked context so that lifecycle hooks\n * registered inside it (onMount, onUnmount, onErrorCaptured, etc.) are captured.\n *\n * Called by the renderer — not intended for user code.\n */\nexport function runWithHooks<P extends Props>(\n fn: ComponentFn<P>,\n props: P,\n): { vnode: VNode | null; hooks: LifecycleHooks } {\n const hooks: LifecycleHooks = { mount: [], unmount: [], update: [], error: [] }\n setCurrentHooks(hooks)\n let vnode: VNode | null = null\n try {\n vnode = fn(props)\n } finally {\n setCurrentHooks(null)\n }\n return { vnode, hooks }\n}\n\n/**\n * Walk up error handlers collected during component rendering.\n * Returns true if any handler marked the error as handled.\n */\nexport function propagateError(err: unknown, hooks: LifecycleHooks): boolean {\n for (const handler of hooks.error) {\n if (handler(err) === true) return true\n }\n return false\n}\n\n// ─── Error boundary stack ────────────────────────────────────────────────────\n// Module-level stack of active ErrorBoundary handlers (innermost last).\n// ErrorBoundary pushes during its own setup (before children mount) so that\n// any child mountComponent error can dispatch up to the nearest boundary.\n\nconst _errorBoundaryStack: ((err: unknown) => boolean)[] = []\n\nexport function pushErrorBoundary(handler: (err: unknown) => boolean): void {\n _errorBoundaryStack.push(handler)\n}\n\nexport function popErrorBoundary(): void {\n _errorBoundaryStack.pop()\n}\n\n/**\n * Dispatch an error to the nearest active ErrorBoundary.\n * Returns true if the boundary handled it, false if none was registered.\n */\nexport function dispatchToErrorBoundary(err: unknown): boolean {\n const handler = _errorBoundaryStack[_errorBoundaryStack.length - 1]\n return handler ? handler(err) : false\n}\n","/**\n * Provide / inject — like React context or Vue provide/inject.\n *\n * Values flow down the component tree without prop-drilling.\n * The renderer maintains the context stack as it walks the VNode tree.\n */\n\nexport interface Context<T> {\n readonly id: symbol\n readonly defaultValue: T\n}\n\nexport function createContext<T>(defaultValue: T): Context<T> {\n return { id: Symbol(\"PyreonContext\"), defaultValue }\n}\n\n// ─── Runtime context stack (managed by the renderer) ─────────────────────────\n\n// Default stack — used for CSR and single-threaded SSR.\n// On Node.js with concurrent requests, @pyreon/runtime-server replaces this with\n// an AsyncLocalStorage-backed provider via setContextStackProvider().\nconst _defaultStack: Map<symbol, unknown>[] = []\nlet _stackProvider: () => Map<symbol, unknown>[] = () => _defaultStack\n\n/**\n * Override the context stack provider. Called by @pyreon/runtime-server to\n * inject an AsyncLocalStorage-backed stack that isolates concurrent SSR requests.\n * Has no effect in the browser (CSR always uses the default module-level stack).\n */\nexport function setContextStackProvider(fn: () => Map<symbol, unknown>[]): void {\n _stackProvider = fn\n}\n\nfunction getStack(): Map<symbol, unknown>[] {\n return _stackProvider()\n}\n\nconst __DEV__ = typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\"\n\nexport function pushContext(values: Map<symbol, unknown>) {\n getStack().push(values)\n}\n\nexport function popContext() {\n const stack = getStack()\n if (__DEV__ && stack.length === 0) {\n return\n }\n stack.pop()\n}\n\n/**\n * Read the nearest provided value for a context.\n * Falls back to `context.defaultValue` if none found.\n */\nexport function useContext<T>(context: Context<T>): T {\n const stack = getStack()\n for (let i = stack.length - 1; i >= 0; i--) {\n const frame = stack[i]\n if (frame?.has(context.id)) {\n return frame.get(context.id) as T\n }\n }\n return context.defaultValue\n}\n\n/**\n * Provide a value for `context` during `fn()`.\n * Used by the renderer when it encounters a `<Provider>` component.\n */\nexport function withContext<T>(context: Context<T>, value: T, fn: () => void) {\n const frame = new Map<symbol, unknown>([[context.id, value]])\n pushContext(frame)\n try {\n fn()\n } finally {\n popContext()\n }\n}\n","import type { ComponentFn, Props, VNode, VNodeChild } from \"./types\"\n\n/** Marker for fragment nodes — renders children without a wrapper element */\nexport const Fragment: unique symbol = Symbol(\"Pyreon.Fragment\")\n\n/**\n * Hyperscript function — the compiled output of JSX.\n * `<div class=\"x\">hello</div>` → `h(\"div\", { class: \"x\" }, \"hello\")`\n *\n * Generic on P so TypeScript validates props match the component's signature\n * at the call site, then stores the result in the loosely-typed VNode.\n */\n/** Shared empty props sentinel — identity-checked in mountElement to skip applyProps. */\nexport const EMPTY_PROPS: Props = {} as Props\n\n/** Makes `children` optional in P (if present) so it can be passed as rest args to h(). */\ntype PropsWithOptionalChildren<P extends Props> = Omit<P, \"children\"> &\n (\"children\" extends keyof P ? { children?: P[\"children\"] } : unknown)\n\n// Overload: component with typed props — children is optional in the props object\n// because it can be passed as rest args. Extra keys are allowed via `& Props`.\nexport function h<P extends Props>(\n type: ComponentFn<P>,\n props: (PropsWithOptionalChildren<P> & Props) | null,\n ...children: VNodeChild[]\n): VNode\n// Overload: intrinsic element, symbol, generic/dynamic component, or mixed union\n// biome-ignore lint/suspicious/noExplicitAny: accepts any component function for generic components like For<T>\nexport function h(\n type: string | ((props: any) => VNode | null) | symbol,\n props: Props | null,\n ...children: VNodeChild[]\n): VNode\nexport function h<P extends Props>(\n type: string | ComponentFn<P> | symbol,\n props: P | null,\n ...children: VNodeChild[]\n): VNode {\n return {\n type: type as string | ComponentFn | symbol,\n props: (props ?? EMPTY_PROPS) as Props,\n children: normalizeChildren(children),\n key: (props?.key as string | number | null) ?? null,\n }\n}\n\nfunction normalizeChildren(children: VNodeChild[]): VNodeChild[] {\n // Fast path: no nested arrays — return as-is without allocating\n for (let i = 0; i < children.length; i++) {\n if (Array.isArray(children[i])) {\n return flattenChildren(children)\n }\n }\n return children\n}\n\nfunction flattenChildren(children: VNodeChild[]): VNodeChild[] {\n const result: VNodeChild[] = []\n for (const child of children) {\n if (Array.isArray(child)) {\n result.push(...flattenChildren(child as VNodeChild[]))\n } else {\n result.push(child)\n }\n }\n return result\n}\n","import { h } from \"./h\"\nimport type { ComponentFn, Props, VNode } from \"./types\"\n\nexport interface DynamicProps extends Props {\n component: ComponentFn | string\n}\n\nexport function Dynamic(props: DynamicProps): VNode | null {\n const { component, ...rest } = props\n if (!component) return null\n return h(component as string | ComponentFn, rest as Props)\n}\n","/**\n * Error telemetry — hook into Pyreon's error reporting for Sentry, Datadog, etc.\n *\n * @example\n * import { registerErrorHandler } from \"@pyreon/core\"\n * import * as Sentry from \"@sentry/browser\"\n *\n * registerErrorHandler(ctx => {\n * Sentry.captureException(ctx.error, {\n * extra: { component: ctx.component, phase: ctx.phase },\n * })\n * })\n */\n\nexport interface ErrorContext {\n /** Component function name, or \"Anonymous\" */\n component: string\n /** Lifecycle phase where the error occurred */\n phase: \"setup\" | \"render\" | \"mount\" | \"unmount\" | \"effect\"\n /** The thrown value */\n error: unknown\n /** Unix timestamp (ms) */\n timestamp: number\n /** Component props at the time of the error */\n props?: Record<string, unknown>\n}\n\nexport type ErrorHandler = (ctx: ErrorContext) => void\n\nlet _handlers: ErrorHandler[] = []\n\n/**\n * Register a global error handler. Called whenever a component throws in any\n * lifecycle phase. Returns an unregister function.\n */\nexport function registerErrorHandler(handler: ErrorHandler): () => void {\n _handlers.push(handler)\n return () => {\n _handlers = _handlers.filter((h) => h !== handler)\n }\n}\n\n/**\n * Internal — called by the runtime whenever a component error is caught.\n * Existing console.error calls are preserved; this is additive.\n */\nexport function reportError(ctx: ErrorContext): void {\n for (const h of _handlers) {\n try {\n h(ctx)\n } catch {\n // handler errors must never propagate back into the framework\n }\n }\n}\n","import { signal } from \"@pyreon/reactivity\"\nimport { popErrorBoundary, pushErrorBoundary } from \"./component\"\nimport { onUnmount } from \"./lifecycle\"\nimport { reportError } from \"./telemetry\"\nimport type { VNodeChild, VNodeChildAtom } from \"./types\"\n\n/**\n * ErrorBoundary — catches errors thrown by child components and renders a\n * fallback UI instead of crashing the whole tree.\n *\n * Also reports caught errors to any registered telemetry handlers.\n *\n * How error propagation works:\n * ErrorBoundary pushes a handler onto the module-level boundary stack\n * synchronously during its own setup (before children are mounted).\n * When mountComponent catches a child error, it calls dispatchToErrorBoundary()\n * which invokes the innermost boundary's handler.\n *\n * Usage:\n * h(ErrorBoundary, {\n * fallback: (err) => h(\"p\", null, `Error: ${err}`),\n * children: h(MyComponent, null),\n * })\n *\n * // or with JSX:\n * <ErrorBoundary fallback={(err) => <p>Error: {String(err)}</p>}>\n * <MyComponent />\n * </ErrorBoundary>\n */\nexport function ErrorBoundary(props: {\n /**\n * Rendered when a child throws. Receives the caught error and a `reset`\n * function — calling `reset()` clears the error and re-renders children.\n */\n fallback: (err: unknown, reset: () => void) => VNodeChild\n children?: VNodeChild\n}): VNodeChild {\n const error = signal<unknown>(null)\n const reset = () => error.set(null)\n\n const handler = (err: unknown): boolean => {\n if (error.peek() !== null) return false // already in error state — let outer boundary catch it\n error.set(err)\n reportError({ component: \"ErrorBoundary\", phase: \"render\", error: err, timestamp: Date.now() })\n return true\n }\n\n // Push synchronously — before children are mounted — so child errors see this boundary\n pushErrorBoundary(handler)\n onUnmount(() => popErrorBoundary())\n\n return (): VNodeChildAtom => {\n const err = error()\n if (err != null) return props.fallback(err, reset) as VNodeChildAtom\n const ch = props.children\n return (typeof ch === \"function\" ? ch() : ch) as VNodeChildAtom\n }\n}\n","import type { NativeItem, Props, VNode } from \"./types\"\n\n/**\n * Symbol used as the VNode type for a For list — runtime-dom handles it\n * via mountFor, bypassing the generic VNode reconciler.\n */\nexport const ForSymbol: unique symbol = Symbol(\"pyreon.For\")\n\nexport interface ForProps<T> {\n each: () => T[]\n by: (item: T) => string | number\n children: (item: T) => VNode | NativeItem\n}\n\n/**\n * Efficient reactive list rendering.\n *\n * Unlike a plain `() => items().map(item => h(...))`, For never re-creates\n * VNodes for existing keys — only new keys invoke `children()`. Structural\n * mutations (swap, sort, filter) are O(n) key scan + O(k) DOM moves where k\n * is the number of actually displaced entries.\n *\n * Usage:\n * <For each={items} by={r => r.id}>{r => <li>...</li>}</For>\n */\nexport function For<T>(props: ForProps<T>): VNode {\n return {\n type: ForSymbol as unknown as string,\n props: props as unknown as Props,\n children: [],\n key: null,\n }\n}\n","import { signal } from \"@pyreon/reactivity\"\nimport { h } from \"./h\"\nimport type { LazyComponent } from \"./suspense\"\nimport type { ComponentFn, Props } from \"./types\"\n\nexport function lazy<P extends Props>(\n load: () => Promise<{ default: ComponentFn<P> }>,\n): LazyComponent<P> {\n const loaded = signal<ComponentFn<P> | null>(null)\n const error = signal<Error | null>(null)\n\n load()\n .then((m) => loaded.set(m.default))\n .catch((e) => error.set(e instanceof Error ? e : new Error(String(e))))\n\n const wrapper = ((props: P) => {\n const err = error()\n if (err) throw err\n const comp = loaded()\n return comp ? h(comp as ComponentFn, props as Props) : null\n }) as LazyComponent<P>\n\n wrapper.__loading = () => loaded() === null && error() === null\n return wrapper\n}\n","/**\n * mapArray — keyed reactive list mapping.\n *\n * Creates each mapped item exactly once per key, then reuses it across\n * updates. When the source array is reordered or partially changed, only\n * new keys invoke `map()`; existing entries return the cached result.\n *\n * This makes structural list operations (swap, sort, filter) O(k) in\n * allocations where k is the number of new/removed keys, not O(n).\n *\n * The returned accessor reads `source()` reactively, so it can be passed\n * directly to the keyed-list reconciler.\n */\nexport function mapArray<T, U>(\n source: () => T[],\n getKey: (item: T) => string | number,\n map: (item: T) => U,\n): () => U[] {\n const cache = new Map<string | number, U>()\n\n return () => {\n const items = source()\n const result: U[] = []\n const newKeys = new Set<string | number>()\n\n for (const item of items) {\n const key = getKey(item)\n newKeys.add(key)\n if (!cache.has(key)) {\n cache.set(key, map(item))\n }\n result.push(cache.get(key) as U)\n }\n\n // Evict entries whose keys are no longer present\n for (const key of cache.keys()) {\n if (!newKeys.has(key)) cache.delete(key)\n }\n\n return result\n }\n}\n","import type { Props, VNode, VNodeChild } from \"./types\"\n\n/**\n * Symbol used as the VNode type for a Portal — runtime-dom mounts the\n * children into `target` instead of the normal parent.\n */\nexport const PortalSymbol: unique symbol = Symbol(\"pyreon.Portal\")\n\nexport interface PortalProps {\n /** DOM element to render children into (e.g. document.body). */\n target: Element\n children: VNodeChild\n}\n\n/**\n * Portal — renders `children` into a different DOM node than the\n * current parent tree.\n *\n * Useful for modals, tooltips, dropdowns, and any overlay that needs to\n * escape CSS overflow/stacking context restrictions.\n *\n * @example\n * // Render a modal at document.body level regardless of where in the\n * // component tree <Modal> is used:\n * Portal({ target: document.body, children: h(Modal, { onClose }) })\n *\n * // JSX:\n * <Portal target={document.body}>\n * <Modal onClose={close} />\n * </Portal>\n */\nexport function Portal(props: PortalProps): VNode {\n return {\n type: PortalSymbol as unknown as string,\n props: props as unknown as Props,\n children: [],\n key: null,\n }\n}\n","/**\n * createRef — mutable container for a DOM element or component value.\n *\n * Usage:\n * const inputRef = createRef<HTMLInputElement>()\n * onMount(() => { inputRef.current?.focus() })\n * return <input ref={inputRef} />\n *\n * The runtime sets `ref.current` after the element is inserted into the DOM\n * and clears it to `null` when the element is removed.\n */\n\nexport interface Ref<T = unknown> {\n current: T | null\n}\n\nexport function createRef<T = unknown>(): Ref<T> {\n return { current: null }\n}\n","import type { Props, VNode, VNodeChild, VNodeChildAtom } from \"./types\"\n\n// ─── Show ─────────────────────────────────────────────────────────────────────\n\nexport interface ShowProps extends Props {\n /** Accessor — children render when truthy, fallback when falsy. */\n when: () => unknown\n fallback?: VNodeChild\n children?: VNodeChild\n}\n\n/**\n * Conditionally render children based on a reactive condition.\n *\n * @example\n * h(Show, { when: () => isLoggedIn() },\n * h(Dashboard, null)\n * )\n *\n * // With fallback:\n * h(Show, { when: () => user(), fallback: h(Login, null) },\n * h(Dashboard, null)\n * )\n */\nexport function Show(props: ShowProps): VNode | null {\n // Returns a reactive accessor; the renderer unwraps it at mount time.\n return ((): VNodeChildAtom =>\n (props.when()\n ? (props.children ?? null)\n : (props.fallback ?? null)) as VNodeChildAtom) as unknown as VNode\n}\n\n// ─── Switch / Match ───────────────────────────────────────────────────────────\n\nexport interface MatchProps extends Props {\n /** Accessor — this branch renders when truthy. */\n when: () => unknown\n children?: VNodeChild\n}\n\n/**\n * A branch inside `<Switch>`. Renders when `when()` is truthy.\n * Must be used as a direct child of `Switch`.\n *\n * `Match` acts as a pure type/identity marker — Switch identifies it by checking\n * `vnode.type === Match` rather than by the runtime return value.\n */\nexport function Match(_props: MatchProps): VNode | null {\n // Match is never mounted directly — Switch inspects Match VNodes by type identity.\n return null\n}\n\nexport interface SwitchProps extends Props {\n /** Rendered when no Match branch is truthy. */\n fallback?: VNodeChild\n children?: VNodeChild | VNodeChild[]\n}\n\n/**\n * Multi-branch conditional rendering. Evaluates each `Match` child in order,\n * renders the first whose `when()` is truthy, or `fallback` if none match.\n *\n * @example\n * h(Switch, { fallback: h(\"p\", null, \"404\") },\n * h(Match, { when: () => route() === \"/\" }, h(Home, null)),\n * h(Match, { when: () => route() === \"/about\" }, h(About, null)),\n * )\n */\nfunction isMatchVNode(branch: VNodeChild): branch is VNode {\n return (\n branch !== null &&\n typeof branch === \"object\" &&\n !Array.isArray(branch) &&\n (branch as VNode).type === Match\n )\n}\n\nfunction resolveMatchChildren(matchVNode: VNode): VNodeChildAtom {\n if (matchVNode.children.length === 0) {\n return ((matchVNode.props as unknown as MatchProps).children ?? null) as VNodeChildAtom\n }\n if (matchVNode.children.length === 1) return matchVNode.children[0] as VNodeChildAtom\n return matchVNode.children as unknown as VNodeChildAtom\n}\n\nfunction normalizeBranches(children: SwitchProps[\"children\"]): VNodeChild[] {\n if (Array.isArray(children)) return children\n if (children != null) return [children]\n return []\n}\n\nexport function Switch(props: SwitchProps): VNode | null {\n // Returns a reactive accessor; the renderer unwraps it at mount time.\n return ((): VNodeChildAtom => {\n const branches = normalizeBranches(props.children)\n\n for (const branch of branches) {\n if (!isMatchVNode(branch)) continue\n const matchProps = branch.props as unknown as MatchProps\n if (matchProps.when()) return resolveMatchChildren(branch)\n }\n\n return (props.fallback ?? null) as VNodeChildAtom\n }) as unknown as VNode\n}\n\n// Keep MatchSymbol export for any code that was using it\nexport const MatchSymbol: unique symbol = Symbol(\"pyreon.Match\")\n","import { Fragment, h } from \"./h\"\nimport type { Props, VNode, VNodeChild } from \"./types\"\n\n/** Internal marker attached to lazy()-wrapped components */\nexport type LazyComponent<P extends Props = Props> = ((props: P) => VNode | null) & {\n __loading: () => boolean\n}\n\n/**\n * Suspense — shows `fallback` while a lazy child component is still loading.\n *\n * Works in tandem with `lazy()` from `@pyreon/react-compat` (or `@pyreon/core/lazy`).\n * The child VNode's `.type.__loading()` signal drives the switch.\n *\n * Usage:\n * const Page = lazy(() => import(\"./Page\"))\n *\n * h(Suspense, { fallback: h(Spinner, null) }, h(Page, null))\n * // or with JSX:\n * <Suspense fallback={<Spinner />}><Page /></Suspense>\n */\nexport function Suspense(props: { fallback: VNodeChild; children?: VNodeChild }): VNode {\n return h(Fragment, null, () => {\n const ch = props.children\n const childNode = typeof ch === \"function\" ? ch() : ch\n\n // Check if the child is a VNode whose type is a lazy component still loading\n const isLoading =\n childNode != null &&\n typeof childNode === \"object\" &&\n !Array.isArray(childNode) &&\n typeof (childNode as VNode).type === \"function\" &&\n ((childNode as VNode).type as unknown as LazyComponent).__loading?.()\n\n if (isLoading) {\n const fb = props.fallback\n return typeof fb === \"function\" ? fb() : fb\n }\n return childNode\n })\n}\n"],"mappings":";;;AAIA,IAAI,WAAkC;AAEtC,SAAgB,gBAAgB,OAA8B;AAC5D,YAAW;;;;;;AAWb,SAAgB,QAAQ,IAAiC;AACvD,WAAU,MAAM,KAAK,GAAG;;;;;AAM1B,SAAgB,UAAU,IAAgB;AACxC,WAAU,QAAQ,KAAK,GAAG;;;;;AAM5B,SAAgB,SAAS,IAAgB;AACvC,WAAU,OAAO,KAAK,GAAG;;;;;;;;;;;;;;;AAgB3B,SAAgB,gBAAgB,IAA2C;AACzE,WAAU,MAAM,KAAK,GAAG;;;;;;;;;AC3C1B,SAAgB,gBAAiC,IAAoC;AACnF,QAAO;;;;;;;;AAST,SAAgB,aACd,IACA,OACgD;CAChD,MAAM,QAAwB;EAAE,OAAO,EAAE;EAAE,SAAS,EAAE;EAAE,QAAQ,EAAE;EAAE,OAAO,EAAE;EAAE;AAC/E,iBAAgB,MAAM;CACtB,IAAI,QAAsB;AAC1B,KAAI;AACF,UAAQ,GAAG,MAAM;WACT;AACR,kBAAgB,KAAK;;AAEvB,QAAO;EAAE;EAAO;EAAO;;;;;;AAOzB,SAAgB,eAAe,KAAc,OAAgC;AAC3E,MAAK,MAAM,WAAW,MAAM,MAC1B,KAAI,QAAQ,IAAI,KAAK,KAAM,QAAO;AAEpC,QAAO;;AAQT,MAAM,sBAAqD,EAAE;AAE7D,SAAgB,kBAAkB,SAA0C;AAC1E,qBAAoB,KAAK,QAAQ;;AAGnC,SAAgB,mBAAyB;AACvC,qBAAoB,KAAK;;;;;;AAO3B,SAAgB,wBAAwB,KAAuB;CAC7D,MAAM,UAAU,oBAAoB,oBAAoB,SAAS;AACjE,QAAO,UAAU,QAAQ,IAAI,GAAG;;;;;ACpDlC,SAAgB,cAAiB,cAA6B;AAC5D,QAAO;E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YAAY;;;;;;;;;AAkB3B,SAAgB,MAAM,QAAkC;AAEtD,QAAO;;;;;;;;;;;;AAmBT,SAAS,aAAa,QAAqC;AACzD,QACE,WAAW,QACX,OAAO,WAAW,YAClB,CAAC,MAAM,QAAQ,OAAO,IACrB,OAAiB,SAAS;;AAI/B,SAAS,qBAAqB,YAAmC;AAC/D,KAAI,WAAW,SAAS,WAAW,EACjC,QAAS,WAAW,MAAgC,YAAY;AAElE,KAAI,WAAW,SAAS,WAAW,EAAG,QAAO,WAAW,SAAS;AACjE,QAAO,WAAW;;AAGpB,SAAS,kBAAkB,UAAiD;AAC1E,KAAI,MAAM,QAAQ,SAAS,CAAE,QAAO;AACpC,KAAI,YAAY,KAAM,QAAO,CAAC,SAAS;AACvC,QAAO,EAAE;;AAGX,SAAgB,OAAO,OAAkC;AAEvD,eAA8B;EAC5B,MAAM,WAAW,kBAAkB,MAAM,SAAS;AAElD,OAAK,MAAM,UAAU,UAAU;AAC7B,OAAI,CAAC,aAAa,OAAO,CAAE;AAE3B,OADmB,OAAO,MACX,MAAM,CAAE,QAAO,qBAAqB,OAAO;;AAG5D,SAAQ,MAAM,YAAY;;;AAK9B,MAAa,cAA6B,OAAO,eAAe;;;;;;;;;;;;;;;;;ACtFhE,SAAgB,SAAS,OAA+D;AACtF,QAAO,EAAE,UAAU,YAAY;EAC7B,MAAM,KAAK,MAAM;EACjB,MAAM,YAAY,OAAO,OAAO,aAAa,IAAI,GAAG;AAUpD,MANE,aAAa,QACb,OAAO,cAAc,YACrB,CAAC,MAAM,QAAQ,UAAU,IACzB,OAAQ,UAAoB,SAAS,cACnC,UAAoB,KAAkC,aAAa,EAExD;GACb,MAAM,KAAK,MAAM;AACjB,UAAO,OAAO,OAAO,aAAa,IAAI,GAAG;;AAE3C,SAAO;GACP"}
@@ -175,7 +175,12 @@ declare const Fragment: unique symbol;
175
175
  */
176
176
  /** Shared empty props sentinel — identity-checked in mountElement to skip applyProps. */
177
177
  declare const EMPTY_PROPS: Props;
178
- declare function h<P extends Props>(type: string | ComponentFn<P> | symbol, props: P | null, ...children: VNodeChild[]): VNode;
178
+ /** Makes `children` optional in P (if present) so it can be passed as rest args to h(). */
179
+ type PropsWithOptionalChildren<P extends Props> = Omit<P, "children"> & ("children" extends keyof P ? {
180
+ children?: P["children"];
181
+ } : unknown);
182
+ declare function h<P extends Props>(type: ComponentFn<P>, props: (PropsWithOptionalChildren<P> & Props) | null, ...children: VNodeChild[]): VNode;
183
+ declare function h(type: string | ((props: any) => VNode | null) | symbol, props: Props | null, ...children: VNodeChild[]): VNode;
179
184
  //#endregion
180
185
  //#region src/suspense.d.ts
181
186
  /** Internal marker attached to lazy()-wrapped components */
@@ -1 +1 @@
1
- {"version":3,"file":"index2.d.ts","names":[],"sources":["../../src/types.ts","../../src/component.ts","../../src/context.ts","../../src/dynamic.ts","../../src/error-boundary.ts","../../src/for.ts","../../src/h.ts","../../src/suspense.ts","../../src/lazy.ts","../../src/lifecycle.ts","../../src/map-array.ts","../../src/portal.ts","../../src/ref.ts","../../src/show.ts","../../src/telemetry.ts"],"mappings":";KAGY,cAAA,GAAiB,KAAA,GAAQ,KAAA;AAAA,KACzB,UAAA,GAAa,cAAA,UAAwB,cAAA;AAAA,UAEhC,KAAA;;EAEf,IAAA,WAAe,WAAA;EACf,KAAA,EAAO,KAAA;EACP,QAAA,EAAU,UAAA;EACV,GAAA;AAAA;AAAA,KAKU,KAAA,GAAQ,MAAA;;AAVpB;;;KAkBY,WAAA,WAAsB,KAAA,GAAQ,KAAA,KAAU,KAAA,EAAO,CAAA,KAAM,KAAA;;;;UAKhD,iBAAA;EACf,KAAA,EAAO,KAAA;EAtBQ;EAwBf,MAAA;EACA,OAAA;AAAA;AAAA,KAMU,SAAA;;;;AAvBZ;;UAgCiB,UAAA;EAAA,SACN,UAAA;EACT,EAAA,EAAI,WAAA;EACJ,OAAA;AAAA;AAAA,UAGe,cAAA;EACf,KAAA,SAAc,SAAA;EACd,OAAA;EACA,MAAA;EAjC+D;E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;;;;;;;;;;;;;AAAA,iBWyBgB,MAAA,CAAO,KAAA,EAAO,WAAA,GAAc,KAAA;;;;AX5B5C;;;;;AACA;;;;;UYQiB,GAAA;EACf,OAAA,EAAS,CAAA;AAAA;AAAA,iBAGK,SAAA,aAAA,CAAA,GAA0B,GAAA,CAAI,CAAA;;;UCZ7B,SAAA,SAAkB,KAAA;EbDT;EaGxB,IAAA;EACA,QAAA,GAAW,UAAA;EACX,QAAA,GAAW,UAAA;AAAA;;;;;AbFb;;;;;;;;;iBakBgB,IAAA,CAAK,KAAA,EAAO,SAAA,GAAY,KAAA;AAAA,UAUvB,UAAA,SAAmB,KAAA;EbzB3B;Ea2BP,IAAA;EACA,QAAA,GAAW,UAAA;AAAA;;;AbrBb;;;;;iBa+BgB,KAAA,CAAM,MAAA,EAAQ,UAAA,GAAa,KAAA;AAAA,UAK1B,WAAA,SAAoB,KAAA;Eb5Bd;Ea8BrB,QAAA,GAAW,UAAA;EACX,QAAA,GAAW,UAAA,GAAa,UAAA;AAAA;AAAA,iBAoCV,MAAA,CAAO,KAAA,EAAO,WAAA,GAAc,KAAA;AAAA,cAgB/B,WAAA;;;;AbxGb;;;;;AACA;;;;;AAEA;;UcQiB,YAAA;EdNA;EcQf,SAAA;EdNU;EcQV,KAAA;EdRoB;EcUpB,KAAA;EdZe;Eccf,SAAA;EdbO;EceP,KAAA,GAAQ,MAAA;AAAA;AAAA,KAGE,YAAA,IAAgB,GAAA,EAAK,YAAA;;;AdXjC;;iBcmBgB,oBAAA,CAAqB,OAAA,EAAS,YAAA;;;AdX9C;;iBcsBgB,WAAA,CAAY,GAAA,EAAK,YAAA"}
1
+ {"version":3,"file":"index2.d.ts","names":[],"sources":["../../src/types.ts","../../src/component.ts","../../src/context.ts","../../src/dynamic.ts","../../src/error-boundary.ts","../../src/for.ts","../../src/h.ts","../../src/suspense.ts","../../src/lazy.ts","../../src/lifecycle.ts","../../src/map-array.ts","../../src/portal.ts","../../src/ref.ts","../../src/show.ts","../../src/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;Ea2BP,IAAA;EACA,QAAA,GAAW,UAAA;AAAA;;;AbrBb;;;;;iBa+BgB,KAAA,CAAM,MAAA,EAAQ,UAAA,GAAa,KAAA;AAAA,UAK1B,WAAA,SAAoB,KAAA;Eb5Bd;Ea8BrB,QAAA,GAAW,UAAA;EACX,QAAA,GAAW,UAAA,GAAa,UAAA;AAAA;AAAA,iBAoCV,MAAA,CAAO,KAAA,EAAO,WAAA,GAAc,KAAA;AAAA,cAgB/B,WAAA;;;;AbxGb;;;;;AACA;;;;;AAEA;;UcQiB,YAAA;EdNA;EcQf,SAAA;EdNU;EcQV,KAAA;EdRoB;EcUpB,KAAA;EdZe;Eccf,SAAA;EdbO;EceP,KAAA,GAAQ,MAAA;AAAA;AAAA,KAGE,YAAA,IAAgB,GAAA,EAAK,YAAA;;;AdXjC;;iBcmBgB,oBAAA,CAAqB,OAAA,EAAS,YAAA;;;AdX9C;;iBcsBgB,WAAA,CAAY,GAAA,EAAK,YAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyreon/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Core component model and lifecycle for Pyreon",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,7 +49,7 @@
49
49
  "prepublishOnly": "bun run build"
50
50
  },
51
51
  "dependencies": {
52
- "@pyreon/reactivity": "^0.3.0"
52
+ "@pyreon/reactivity": "^0.3.1"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"
package/src/env.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Minimal process type — just enough for `process.env.NODE_ENV` checks.
3
+ * Avoids requiring @types/node in consumers that import pyreon source
4
+ * via the `"bun"` export condition.
5
+ */
6
+ declare var process: { env: { NODE_ENV?: string } }
package/src/h.ts CHANGED
@@ -13,6 +13,24 @@ export const Fragment: unique symbol = Symbol("Pyreon.Fragment")
13
13
  /** Shared empty props sentinel — identity-checked in mountElement to skip applyProps. */
14
14
  export const EMPTY_PROPS: Props = {} as Props
15
15
 
16
+ /** Makes `children` optional in P (if present) so it can be passed as rest args to h(). */
17
+ type PropsWithOptionalChildren<P extends Props> = Omit<P, "children"> &
18
+ ("children" extends keyof P ? { children?: P["children"] } : unknown)
19
+
20
+ // Overload: component with typed props — children is optional in the props object
21
+ // because it can be passed as rest args. Extra keys are allowed via `& Props`.
22
+ export function h<P extends Props>(
23
+ type: ComponentFn<P>,
24
+ props: (PropsWithOptionalChildren<P> & Props) | null,
25
+ ...children: VNodeChild[]
26
+ ): VNode
27
+ // Overload: intrinsic element, symbol, generic/dynamic component, or mixed union
28
+ // biome-ignore lint/suspicious/noExplicitAny: accepts any component function for generic components like For<T>
29
+ export function h(
30
+ type: string | ((props: any) => VNode | null) | symbol,
31
+ props: Props | null,
32
+ ...children: VNodeChild[]
33
+ ): VNode
16
34
  export function h<P extends Props>(
17
35
  type: string | ComponentFn<P> | symbol,
18
36
  props: P | null,