flexium 0.13.0 → 0.13.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 (78) hide show
  1. package/README.md +14 -8
  2. package/dist/canvas.js +1 -1
  3. package/dist/canvas.js.map +1 -1
  4. package/dist/canvas.mjs +1 -1
  5. package/dist/canvas.mjs.map +1 -1
  6. package/dist/chunk-3AKECLKA.mjs +2 -0
  7. package/dist/chunk-3AKECLKA.mjs.map +1 -0
  8. package/dist/chunk-ACYN2UKT.js +2 -0
  9. package/dist/chunk-ACYN2UKT.js.map +1 -0
  10. package/dist/chunk-E6Z7AI4J.js +2 -0
  11. package/dist/chunk-E6Z7AI4J.js.map +1 -0
  12. package/dist/chunk-MI76R42D.mjs +2 -0
  13. package/dist/chunk-MI76R42D.mjs.map +1 -0
  14. package/dist/chunk-PUXZJ7OV.js +2 -0
  15. package/dist/{chunk-X6HXRSMG.js.map → chunk-PUXZJ7OV.js.map} +1 -1
  16. package/dist/chunk-TP5HUAIN.mjs +2 -0
  17. package/dist/{chunk-JUP6RTZA.mjs.map → chunk-TP5HUAIN.mjs.map} +1 -1
  18. package/dist/core.d.cts +32 -2
  19. package/dist/core.d.ts +32 -2
  20. package/dist/core.js +1 -1
  21. package/dist/core.js.map +1 -1
  22. package/dist/core.mjs +1 -1
  23. package/dist/core.mjs.map +1 -1
  24. package/dist/dom.js +1 -1
  25. package/dist/dom.js.map +1 -1
  26. package/dist/dom.mjs +1 -1
  27. package/dist/dom.mjs.map +1 -1
  28. package/dist/index.d.cts +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +1 -1
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/interactive.d.cts +3 -3
  35. package/dist/interactive.d.ts +3 -3
  36. package/dist/interactive.js +1 -1
  37. package/dist/interactive.js.map +1 -1
  38. package/dist/interactive.mjs +1 -1
  39. package/dist/interactive.mjs.map +1 -1
  40. package/dist/metafile-cjs.json +1 -1
  41. package/dist/metafile-esm.json +1 -1
  42. package/dist/render-4HB53K66.mjs +2 -0
  43. package/dist/{render-L57MA662.mjs.map → render-4HB53K66.mjs.map} +1 -1
  44. package/dist/render-MJ2LCNSG.js +2 -0
  45. package/dist/{render-VERKNIPR.js.map → render-MJ2LCNSG.js.map} +1 -1
  46. package/dist/router.js +1 -1
  47. package/dist/router.js.map +1 -1
  48. package/dist/router.mjs +1 -1
  49. package/dist/router.mjs.map +1 -1
  50. package/dist/server.js +1 -1
  51. package/dist/server.js.map +1 -1
  52. package/dist/server.mjs +1 -1
  53. package/dist/server.mjs.map +1 -1
  54. package/package.json +1 -6
  55. package/dist/advanced.d.cts +0 -5
  56. package/dist/advanced.d.ts +0 -5
  57. package/dist/advanced.js +0 -2
  58. package/dist/advanced.js.map +0 -1
  59. package/dist/advanced.mjs +0 -2
  60. package/dist/advanced.mjs.map +0 -1
  61. package/dist/chunk-5PNH2ARD.mjs +0 -2
  62. package/dist/chunk-5PNH2ARD.mjs.map +0 -1
  63. package/dist/chunk-CGB4YXKS.js +0 -2
  64. package/dist/chunk-CGB4YXKS.js.map +0 -1
  65. package/dist/chunk-INJXOHFD.mjs +0 -2
  66. package/dist/chunk-INJXOHFD.mjs.map +0 -1
  67. package/dist/chunk-JUP6RTZA.mjs +0 -2
  68. package/dist/chunk-NDPEE2TQ.mjs +0 -2
  69. package/dist/chunk-NDPEE2TQ.mjs.map +0 -1
  70. package/dist/chunk-UWFVCKRU.js +0 -2
  71. package/dist/chunk-UWFVCKRU.js.map +0 -1
  72. package/dist/chunk-W2L7BLE7.js +0 -2
  73. package/dist/chunk-W2L7BLE7.js.map +0 -1
  74. package/dist/chunk-X6HXRSMG.js +0 -2
  75. package/dist/render-L57MA662.mjs +0 -2
  76. package/dist/render-VERKNIPR.js +0 -2
  77. package/dist/types--emg3Tgw.d.cts +0 -10
  78. package/dist/types--emg3Tgw.d.ts +0 -10
package/dist/dom.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dom/f.ts","../src/dom/hydrate.ts","../src/dom/components/Portal.tsx","../src/dom/components/suspenseContext.ts","../src/dom/components/Suspense.tsx","../src/dom/components/ErrorBoundary.tsx","../src/dom/components/lazy.ts"],"names":["f","type","props","children","hydrationCursor","hydratedInstanceRegistry","currentHydratingInstance","hydrate","app","container","options","state","onHydrated","onMismatch","fnode","isFNode","hydrateNode","error","render","value","parent","skipEmptyTextNodes","hydrateTextNode","nodes","child","result","hydrateComponent","hydrateElement","text","current","tag","key","eventName","savedCursor","Component","contextId","isProvider","prevContextValue","pushContext","parentRegistry","hasExplicitKey","instanceCount","componentName","_","k","instance","previousHydratingInstance","runWithComponent","isFirstRender","renderFn","currentProps","unsafeEffect","popContext","Portal","target","portalState","hook","use","onCleanup","portalWrapper","defaultValue","SuspenseCtx","createContext","suspenseContext","useContext","Suspense","fallback","pendingSet","setPendingCount","showFallback","setShowFallback","contextValue","promise","c","newCount","content","ErrorBoundary","onError","resetKey","errorState","setErrorState","prevResetKeyRef","lazy","loader","resolved","LazyWrapper","suspense","module","err"],"mappings":"wSAKO,SAASA,CAAAA,CACZC,CAAAA,CACAC,CAAAA,CAAAA,GACGC,CAAAA,CACE,CACL,OAAO,CACH,IAAA,CAAAF,CAAAA,CACA,KAAA,CAAOC,CAAAA,EAAS,GAChB,QAAA,CAAAC,CAAAA,CACA,GAAA,CAAKD,CAAAA,EAAO,GAChB,CACJ,CCTA,IACIE,CAAAA,CAA+B,IAAA,CAkC7BC,EAA2B,IAAI,OAAA,CACjCC,CAAAA,CAAwD,KAarD,SAASC,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CAA0B,EAAC,CACrB,CACN,GAAM,CAAE,MAAAC,CAAAA,CAAO,UAAA,CAAAC,CAAAA,CAAY,UAAA,CAAAC,CAAW,CAAA,CAAIH,CAAAA,CAO1CN,CAAAA,CAAkBK,CAAAA,CAAU,WAE5B,GAAI,C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ACb,OAAI,OAAOb,CAAAA,EAAa,UAAA,CACfA,CAAAA,CAASa,CAAAA,CAAW,MAAOA,CAAAA,CAAW,IAAK,EAE7Cb,CAAAA,CAMT,GAAI,CAEF,OAAO/D,CACT,CAAA,OAAE,CAEF,CACF,CCtFO,SAAS+E,EACdC,CAAAA,CACkB,CAElB,IAAIC,CAAAA,CAA8C,IAAA,CAC9CZ,CAAAA,CAA+B,KAC/BvD,CAAAA,CAAsB,IAAA,CAGpBoE,EAAenF,CAAAA,EAAyB,CAE5C,GAAIkF,CAAAA,CACF,OAAOA,CAAAA,CAASlF,CAAK,CAAA,CAIvB,GAAIe,EACF,MAAMA,CAAAA,CAIR,IAAMqE,CAAAA,CAAWvB,CAAAA,GAGjB,OAAKS,CAAAA,GACHA,CAAAA,CAAUW,CAAAA,EAAO,CACd,IAAA,CAAKI,GAAU,CACdH,CAAAA,CAAWG,EAAO,QACpB,CAAC,EACA,KAAA,CAAMC,CAAAA,EAAO,CACZvE,CAAAA,CAAQuE,CAAAA,YAAe,KAAA,CAAQA,EAAM,IAAI,KAAA,CAAM,OAAOA,CAAG,CAAC,EAC5D,CAAC,CAAA,CAAA,CAIDF,CAAAA,CAAS,WAAA,EACXA,CAAAA,CAAS,QAAA,CAASd,CAAO,CAAA,CAIpB,IACT,EAGC,OAACa,CAAAA,CAAiC,MAAQ,IAAA,CACzCA,CAAAA,CAAiC,OAAA,CAAUF,CAAAA,CAEtCE,CACT","file":"dom.mjs","sourcesContent":["import type { FNode } from './types'\n\n/**\n * f() - Create FNodes without JSX\n */\nexport function f(\n type: string | Function,\n props?: any,\n ...children: any[]\n): FNode {\n return {\n type,\n props: props || {},\n children,\n key: props?.key\n }\n}\n","import type { FNode, FNodeChild } from './types'\nimport type { SerializedState } from '../server/types'\nimport { runWithComponent, type ComponentInstance } from '../core/hook'\nimport { pushContext, popContext } from '../core/context'\nimport { unsafeEffect } from '../core/lifecycle'\n\n// Hydration state\nlet isHydrating = false\nlet hydrationCursor: Node | null = null\nlet hydrationState: SerializedState | null = null\n\nexport interface HydrateOptions {\n /**\n * Serialized state from server\n * Typically embedded in HTML as JSON script tag\n */\n state?: SerializedState\n\n /**\n * Called when hydration completes successfully\n */\n onHydrated?: () => void\n\n /**\n * Called when hydration fails (falls back to full render)\n */\n onMismatch?: (error: Error) => void\n}\n\n// Extended ComponentInstance for DOM tracking (same as render.ts)\ninterface DOMComponentInstance extends ComponentInstance {\n nodes: Node[]\n parent: HTMLElement\n fnode: any\n props: any\n key?: any\n renderFn?: () => void\n children: Set<DOMComponentInstance>\n parentInstance?: DOMComponentInstance\n}\n\n// Registry for hydrated components\nconst hydratedInstanceRegistry = new WeakMap<HTMLElement, Map<any, DOMComponentInstance>>()\nlet currentHydratingInstance: DOMComponentInstance | null = null\n\nexport function getIsHydrating(): boolean {\n return isHydrating\n}\n\nexport function getHydrationState(): SerializedState | null {\n return hydrationState\n}\n\n/**\n * Hydrate server-rendered HTML with client-side interactivity\n */\nexport function hydrate(\n app: FNodeChild | (() => FNodeChild),\n container: HTMLElement,\n options: HydrateOptions = {}\n): void {\n const { state, onHydrated, onMismatch } = options\n\n // Store state for rehydration\n hydrationState = state || null\n\n // Initialize hydration mode\n isHydrating = true\n hydrationCursor = container.firstChild\n\n try {\n // Normalize input\n let fnode: FNodeChild\n if (typeof app === 'function' && !isFNode(app)) {\n fnode = { type: app, props: {}, children: [], key: undefined }\n } else {\n fnode = app\n }\n\n // Hydrate the tree\n hydrateNode(fnode, container)\n\n onHydrated?.()\n } catch (error) {\n // Hydration mismatch - fall back to full render\n console.warn('[Flexium] Hydration mismatch, falling back to full render:', error)\n onMismatch?.(error as Error)\n\n // Clear and re-render\n container.innerHTML = ''\n // Import dynamically to avoid circular deps\n import('./render').then(({ render }) => {\n render(app, container)\n })\n } finally {\n isHydrating = false\n hydrationCursor = null\n hydrationState = null\n }\n}\n\nfunction isFNode(value: any): value is FNode {\n return value && typeof value === 'object' && 'type' in value && 'props' in value\n}\n\nfunction hydrateNode(fnode: FNodeChild, parent: HTMLElement): Node | Node[] | null {\n // Null/undefined/boolean -> skip empty text nodes\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n // Server might have rendered an empty text node\n skipEmptyTextNodes()\n return null\n }\n\n // String/number -> expect text node\n if (typeof fnode === 'string' || typeof fnode === 'number') {\n return hydrateTextNode(String(fnode))\n }\n\n // Array -> hydrate each child\n if (Array.isArray(fnode)) {\n const nodes: Node[] = []\n for (const child of fnode) {\n const result = hydrateNode(child, parent)\n if (result) {\n if (Array.isArray(result)) {\n nodes.push(...result)\n } else {\n nodes.push(result)\n }\n }\n }\n return nodes\n }\n\n // Function (standalone) -> wrap in FNode and hydrate\n if (typeof fnode === 'function') {\n const wrappedFnode: FNode = { type: fnode, props: {}, children: [], key: undefined }\n return hydrateComponent(wrappedFnode, parent)\n }\n\n // Object (FNode)\n if (typeof fnode === 'object' && isFNode(fnode)) {\n if (typeof fnode.type === 'string') {\n return hydrateElement(fnode)\n }\n\n if (typeof fnode.type === 'function') {\n return hydrateComponent(fnode, parent)\n }\n }\n\n return null\n}\n\nfunction skipEmptyTextNodes(): void {\n while (\n hydrationCursor &&\n hydrationCursor.nodeType === Node.TEXT_NODE &&\n (!hydrationCursor.textContent || hydrationCursor.textContent.trim() === '')\n ) {\n hydrationCursor = hydrationCursor.nextSibling\n }\n}\n\nfunction hydrateTextNode(text: string): Node | null {\n skipEmptyTextNodes()\n\n const current = hydrationCursor\n\n if (!current) {\n // No node to hydrate - this is okay for conditional rendering\n return null\n }\n\n if (current.nodeType !== Node.TEXT_NODE) {\n // Try to find a text node nearby (whitespace handling)\n if (text.trim() === '') {\n return null\n }\n throw new Error(`Hydration mismatch: expected text node \"${text}\", got ${current.nodeName}`)\n }\n\n // Update cursor\n hydrationCursor = current.nextSibling\n\n return current\n}\n\nfunction hydrateElement(fnode: FNode): Node {\n skipEmptyTextNodes()\n\n const current = hydrationCursor as Element\n const tag = fnode.type as string\n\n // Validate element type\n if (!current || current.nodeType !== Node.ELEMENT_NODE) {\n throw new Error(`Hydration mismatch: expected element <${tag}>, got ${current?.nodeName || 'nothing'}`)\n }\n\n if (current.tagName.toLowerCase() !== tag.toLowerCase()) {\n throw new Error(`Hydration mismatch: expected <${tag}>, got <${current.tagName.toLowerCase()}>`)\n }\n\n // Attach event handlers and refs (don't modify DOM structure)\n if (fnode.props) {\n for (const [key, value] of Object.entries(fnode.props)) {\n if (key === 'ref') {\n if (typeof value === 'function') {\n value(current)\n } else if (value && typeof value === 'object' && 'current' in value) {\n value.current = current\n }\n } else if (key.startsWith('on') && typeof value === 'function') {\n const eventName = key.slice(2).toLowerCase()\n current.addEventListener(eventName, value as EventListener)\n\n // Store for reconciliation\n if (!(current as any).__eventHandlers) {\n (current as any).__eventHandlers = {}\n }\n (current as any).__eventHandlers[eventName] = value\n }\n }\n }\n\n // Move cursor past this element\n hydrationCursor = current.nextSibling\n\n // Hydrate children\n if (fnode.children && fnode.children.length > 0) {\n const savedCursor = hydrationCursor\n\n hydrationCursor = current.firstChild\n\n for (const child of fnode.children) {\n hydrateNode(child, current as HTMLElement)\n }\n\n hydrationCursor = savedCursor\n }\n\n return current\n}\n\nfunction hydrateComponent(fnode: FNode, parent: HTMLElement): Node | Node[] | null {\n const Component = fnode.type as Function\n\n // Merge props\n const props = { ...fnode.props }\n if (fnode.children && fnode.children.length > 0) {\n props.children = fnode.children.length === 1\n ? fnode.children[0]\n : fnode.children\n }\n\n // Handle context providers\n const contextId = (Component as any)._contextId\n const isProvider = contextId !== undefined\n let prevContextValue: any\n\n if (isProvider) {\n prevContextValue = pushContext(contextId, props.value)\n }\n\n // Generate key (same logic as render.ts)\n if (!hydratedInstanceRegistry.has(parent)) {\n hydratedInstanceRegistry.set(parent, new Map())\n }\n const parentRegistry = hydratedInstanceRegistry.get(parent)!\n\n const hasExplicitKey = fnode.key !== undefined\n let key: any\n if (hasExplicitKey) {\n key = fnode.key\n } else {\n let instanceCount = 0\n const componentName = (Component as any).name || 'anonymous'\n parentRegistry.forEach((_, k) => {\n if (typeof k === 'string' && k.startsWith(`__auto_${componentName}_`)) {\n instanceCount++\n }\n })\n key = `__auto_${componentName}_${instanceCount}`\n }\n\n // Create component instance\n const instance: DOMComponentInstance = {\n hooks: [],\n hookIndex: 0,\n nodes: [],\n parent,\n fnode,\n props,\n key,\n children: new Set(),\n parentInstance: currentHydratingInstance || undefined\n }\n\n if (currentHydratingInstance) {\n currentHydratingInstance.children.add(instance)\n }\n\n parentRegistry.set(key, instance)\n\n const previousHydratingInstance = currentHydratingInstance\n currentHydratingInstance = instance\n\n try {\n // First render during hydration - just match DOM\n const result = runWithComponent(instance, () => Component(props))\n const nodes = hydrateNode(result, parent)\n instance.nodes = nodes ? (Array.isArray(nodes) ? nodes : [nodes]) : []\n\n // Set up reactive re-rendering for future updates\n let isFirstRender = true\n const renderFn = () => {\n if (isFirstRender) {\n isFirstRender = false\n return // Skip first render, already done during hydration\n }\n\n // Re-render logic (same as render.ts but simplified)\n const currentProps = instance.props\n runWithComponent(instance, () => Component(currentProps))\n\n // For subsequent renders, use full render path\n // This will be handled by the normal reconciliation\n }\n\n instance.renderFn = renderFn\n unsafeEffect(renderFn)\n\n return instance.nodes\n } finally {\n currentHydratingInstance = previousHydratingInstance\n\n if (isProvider) {\n popContext(contextId, prevContextValue)\n }\n }\n}\n","import { use } from '../../core/use'\nimport { hook } from '../../core/hook'\nimport { render } from '../render'\nimport type { PortalProps } from './types'\n\n/**\n * Portal component that renders children into a different DOM node\n *\n * @example\n * ```tsx\n * function Modal({ isOpen, onClose, children }) {\n * if (!isOpen) return null\n *\n * return (\n * <Portal target={document.body}>\n * <div class=\"modal-backdrop\" onClick={onClose}>\n * <div class=\"modal-content\" onClick={e => e.stopPropagation()}>\n * {children}\n * </div>\n * </div>\n * </Portal>\n * )\n * }\n * ```\n */\nexport function Portal(props: PortalProps): null {\n const { target, children } = props\n\n // Store rendered container for cleanup\n const portalState = hook(() => ({\n container: null as HTMLElement | null,\n mounted: false\n }))\n\n use(({ onCleanup }) => {\n // Resolve target container\n let container: HTMLElement | null = null\n\n if (typeof target === 'string') {\n container = document.querySelector(target)\n } else if (target instanceof HTMLElement) {\n container = target\n }\n\n if (!container) {\n console.warn('[Flexium Portal] Target container not found:', target)\n return\n }\n\n // Create a wrapper div to contain portal content\n const portalWrapper = document.createElement('div')\n portalWrapper.setAttribute('data-flexium-portal', 'true')\n container.appendChild(portalWrapper)\n\n portalState.container = portalWrapper\n portalState.mounted = true\n\n // Render children into the portal wrapper\n render(children, portalWrapper)\n\n // Cleanup function\n onCleanup(() => {\n if (portalWrapper.parentNode) {\n portalWrapper.parentNode.removeChild(portalWrapper)\n }\n portalState.container = null\n portalState.mounted = false\n })\n }, [target, children])\n\n // Portal renders nothing in its original location\n return null\n}\n","import { createContext, useContext } from '../../core/context'\nimport type { SuspenseContextValue } from './types'\n\nconst defaultValue: SuspenseContextValue = {\n register: () => {},\n hasBoundary: false\n}\n\nexport const SuspenseCtx = createContext<SuspenseContextValue>(defaultValue)\n\nexport function suspenseContext(): SuspenseContextValue {\n return useContext(SuspenseCtx)\n}\n","import { use } from '../../core/use'\nimport { hook } from '../../core/hook'\nimport { SuspenseCtx } from './suspenseContext'\nimport type { SuspenseProps, SuspenseContextValue } from './types'\nimport type { FNodeChild } from '../types'\n\n/**\n * Suspense component that shows fallback while children are loading\n *\n * @example\n * ```tsx\n * const Dashboard = lazy(() => import('./Dashboard'))\n *\n * function App() {\n * return (\n * <Suspense fallback={<div>Loading...</div>}>\n * <Dashboard />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function Suspense(props: SuspenseProps): FNodeChild {\n const { fallback, children } = props\n\n // Track pending promises using hook for mutable Set\n const pendingSet = hook(() => new Set<Promise<any>>())\n const [, setPendingCount] = use(0)\n const [showFallback, setShowFallback] = use(false)\n\n // Register function for lazy components\n const register = (promise: Promise<any>) => {\n if (!pendingSet.has(promise)) {\n // Add to pending set\n pendingSet.add(promise)\n setPendingCount(c => c + 1)\n setShowFallback(true)\n\n // Wait for resolution\n promise.finally(() => {\n pendingSet.delete(promise)\n setPendingCount(c => {\n const newCount = c - 1\n if (newCount === 0) {\n setShowFallback(false)\n }\n return newCount\n })\n })\n }\n }\n\n const contextValue: SuspenseContextValue = {\n register,\n hasBoundary: true\n }\n\n // Render fallback or children based on pending state\n const content = showFallback ? fallback : children\n\n // Wrap content with Suspense context provider\n return {\n type: SuspenseCtx.Provider,\n props: { value: contextValue },\n children: [content],\n key: undefined\n } as any\n}\n","import { use } from '../../core/use'\nimport { hook } from '../../core/hook'\nimport type { FNodeChild } from '../types'\nimport type { ErrorInfo, ErrorBoundaryProps } from './types'\n\n// Component name stack for error messages\nlet componentNameStack: string[] = []\n\nexport function pushComponentName(name: string): void {\n componentNameStack.push(name)\n}\n\nexport function popComponentName(): void {\n componentNameStack.pop()\n}\n\nexport function getComponentStack(): string {\n return componentNameStack\n .map(name => ` at ${name}`)\n .reverse()\n .join('\\n')\n}\n\n// Stack of error boundaries for nested error propagation\ninterface ErrorBoundaryInstance {\n handleError: (error: Error, phase: 'render' | 'effect' | 'event') => void\n}\n\nlet errorBoundaryStack: ErrorBoundaryInstance[] = []\n\nexport function pushErrorBoundary(instance: ErrorBoundaryInstance): void {\n errorBoundaryStack.push(instance)\n}\n\nexport function popErrorBoundary(): void {\n errorBoundaryStack.pop()\n}\n\nexport function getNearestErrorBoundary(): ErrorBoundaryInstance | null {\n return errorBoundaryStack[errorBoundaryStack.length - 1] || null\n}\n\n/**\n * ErrorBoundary component that catches errors in its children and displays fallback UI\n *\n * @example\n * ```tsx\n * <ErrorBoundary\n * fallback={(error, info) => <div>Error: {error.message}</div>}\n * onError={(error, info) => console.error(error)}\n * >\n * <App />\n * </ErrorBoundary>\n * ```\n */\nexport function ErrorBoundary(props: ErrorBoundaryProps): FNodeChild {\n const { fallback, onError, children, resetKey } = props\n\n // Error state\n const [errorState, setErrorState] = use<{\n error: Error | null\n info: ErrorInfo | null\n }>({ error: null, info: null })\n\n // Track reset key changes to clear error\n const prevResetKeyRef = hook(() => ({ current: resetKey }))\n\n if (resetKey !== prevResetKeyRef.current) {\n prevResetKeyRef.current = resetKey\n if (errorState.error !== null) {\n setErrorState({ error: null, info: null })\n }\n }\n\n // Error boundary instance\n const boundaryInstance: ErrorBoundaryInstance = {\n handleError: (error: Error, phase: 'render' | 'effect' | 'event') => {\n const info: ErrorInfo = {\n componentStack: getComponentStack(),\n phase\n }\n\n // Call error callback\n onError?.(error, info)\n\n // Update error state (triggers re-render with fallback)\n setErrorState({ error, info })\n }\n }\n\n // If we have an error, render fallback\n if (errorState.error) {\n if (typeof fallback === 'function') {\n return fallback(errorState.error, errorState.info!)\n }\n return fallback\n }\n\n // Push boundary onto stack for children to use\n pushErrorBoundary(boundaryInstance)\n\n try {\n // Return children - they will be rendered with this boundary active\n return children\n } finally {\n popErrorBoundary()\n }\n}\n","import { suspenseContext } from './suspenseContext'\nimport type { FNodeChild } from '../types'\nimport type { LazyComponent } from './types'\n\n/**\n * Creates a lazy-loaded component for code splitting\n *\n * @example\n * ```tsx\n * const Dashboard = lazy(() => import('./Dashboard'))\n * const Settings = lazy(() => import('./Settings'))\n *\n * function App() {\n * return (\n * <Suspense fallback={<div>Loading...</div>}>\n * <Dashboard />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function lazy<P = {}>(\n loader: () => Promise<{ default: (props: P) => FNodeChild }>\n): LazyComponent<P> {\n // Shared state across all instances\n let resolved: ((props: P) => FNodeChild) | null = null\n let promise: Promise<any> | null = null\n let error: Error | null = null\n\n // The wrapper component\n const LazyWrapper = (props: P): FNodeChild => {\n // If already resolved, render immediately\n if (resolved) {\n return resolved(props)\n }\n\n // If error occurred, throw it (will be caught by ErrorBoundary)\n if (error) {\n throw error\n }\n\n // Get suspense context\n const suspense = suspenseContext()\n\n // Start loading if not already\n if (!promise) {\n promise = loader()\n .then(module => {\n resolved = module.default\n })\n .catch(err => {\n error = err instanceof Error ? err : new Error(String(err))\n })\n }\n\n // Register with suspense boundary if available\n if (suspense.hasBoundary) {\n suspense.register(promise)\n }\n\n // Return null - Suspense will show fallback\n return null\n }\n\n // Mark as lazy component\n ;(LazyWrapper as LazyComponent<P>)._lazy = true\n ;(LazyWrapper as LazyComponent<P>)._loader = loader\n\n return LazyWrapper as LazyComponent<P>\n}\n"]}
1
+ {"version":3,"sources":["../src/dom/f.ts","../src/dom/hydrate.ts","../src/dom/components/Portal.tsx","../src/dom/components/suspenseContext.ts","../src/dom/components/Suspense.tsx","../src/dom/components/ErrorBoundary.tsx","../src/dom/components/lazy.ts"],"names":["f","type","props","children","hydrationCursor","hydratedInstanceRegistry","currentHydratingInstance","hydrate","app","container","options","state","onHydrated","onMismatch","fnode","isFNode","hydrateNode","error","render","value","parent","skipEmptyTextNodes","hydrateTextNode","nodes","child","result","hydrateComponent","hydrateElement","text","current","tag","key","eventName","savedCursor","Component","contextId","isProvider","prevContextValue","pushContext","parentRegistry","hasExplicitKey","instanceCount","componentName","_","k","instance","previousHydratingInstance","runWithComponent","isFirstRender","renderFn","currentProps","unsafeEffect","popContext","Portal","target","portalState","hook","use","onCleanup","portalWrapper","defaultValue","SuspenseCtx","Context","suspenseContext","Suspense","fallback","pendingSet","setPendingCount","showFallback","setShowFallback","contextValue","promise","newCount","content","ErrorBoundary","onError","resetKey","errorState","setErrorState","prevResetKeyRef","lazy","loader","resolved","LazyWrapper","suspense","module","err"],"mappings":"qPAKO,SAASA,CAAAA,CACZC,CAAAA,CACAC,CAAAA,CAAAA,GACGC,CAAAA,CACE,CACL,OAAO,CACH,IAAA,CAAAF,CAAAA,CACA,KAAA,CAAOC,CAAAA,EAAS,GAChB,QAAA,CAAAC,CAAAA,CACA,GAAA,CAAKD,CAAAA,EAAO,GAChB,CACJ,CCTA,IACIE,CAAAA,CAA+B,IAAA,CAkC7BC,EAA2B,IAAI,OAAA,CACjCC,CAAAA,CAAwD,KAarD,SAASC,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CAA0B,EAAC,CACrB,CACN,GAAM,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C/BA,CAAAA,CAAgB,OAAA,CAAUH,EACtBC,CAAAA,CAAW,KAAA,GAAU,MACvBC,CAAAA,CAAc,CAAE,MAAO,IAAA,CAAM,IAAA,CAAM,IAAK,CAAC,CAAA,CAAA,CAqB7C,GAAID,CAAAA,CAAW,MACb,OAAI,OAAOZ,CAAAA,EAAa,UAAA,CACfA,CAAAA,CAASY,CAAAA,CAAW,MAAOA,CAAAA,CAAW,IAAK,EAE7CZ,CAAAA,CAMT,GAAI,CAEF,OAAO9D,CACT,CAAA,OAAE,CAEF,CACF,CCtFO,SAAS6E,EACdC,CAAAA,CACkB,CAElB,IAAIC,CAAAA,CAA8C,IAAA,CAC9CX,CAAAA,CAA+B,KAC/BtD,CAAAA,CAAsB,IAAA,CAGpBkE,EAAejF,CAAAA,EAAyB,CAE5C,GAAIgF,CAAAA,CACF,OAAOA,CAAAA,CAAShF,CAAK,CAAA,CAIvB,GAAIe,EACF,MAAMA,CAAAA,CAIR,IAAMmE,CAAAA,CAAWrB,CAAAA,GAGjB,OAAKQ,CAAAA,GACHA,CAAAA,CAAUU,CAAAA,EAAO,CACd,IAAA,CAAKI,GAAU,CACdH,CAAAA,CAAWG,EAAO,QACpB,CAAC,EACA,KAAA,CAAMC,CAAAA,EAAO,CACZrE,CAAAA,CAAQqE,CAAAA,YAAe,KAAA,CAAQA,EAAM,IAAI,KAAA,CAAM,OAAOA,CAAG,CAAC,EAC5D,CAAC,CAAA,CAAA,CAIDF,CAAAA,CAAS,WAAA,EACXA,CAAAA,CAAS,QAAA,CAASb,CAAO,CAAA,CAIpB,IACT,EAGC,OAACY,CAAAA,CAAiC,MAAQ,IAAA,CACzCA,CAAAA,CAAiC,OAAA,CAAUF,CAAAA,CAEtCE,CACT","file":"dom.mjs","sourcesContent":["import type { FNode } from './types'\n\n/**\n * f() - Create FNodes without JSX\n */\nexport function f(\n type: string | Function,\n props?: any,\n ...children: any[]\n): FNode {\n return {\n type,\n props: props || {},\n children,\n key: props?.key\n }\n}\n","import type { FNode, FNodeChild } from './types'\nimport type { SerializedState } from '../server/types'\nimport { runWithComponent, type ComponentInstance } from '../core/hook'\nimport { pushContext, popContext } from '../core/context'\nimport { unsafeEffect } from '../core/lifecycle'\n\n// Hydration state\nlet isHydrating = false\nlet hydrationCursor: Node | null = null\nlet hydrationState: SerializedState | null = null\n\nexport interface HydrateOptions {\n /**\n * Serialized state from server\n * Typically embedded in HTML as JSON script tag\n */\n state?: SerializedState\n\n /**\n * Called when hydration completes successfully\n */\n onHydrated?: () => void\n\n /**\n * Called when hydration fails (falls back to full render)\n */\n onMismatch?: (error: Error) => void\n}\n\n// Extended ComponentInstance for DOM tracking (same as render.ts)\ninterface DOMComponentInstance extends ComponentInstance {\n nodes: Node[]\n parent: HTMLElement\n fnode: any\n props: any\n key?: any\n renderFn?: () => void\n children: Set<DOMComponentInstance>\n parentInstance?: DOMComponentInstance\n}\n\n// Registry for hydrated components\nconst hydratedInstanceRegistry = new WeakMap<HTMLElement, Map<any, DOMComponentInstance>>()\nlet currentHydratingInstance: DOMComponentInstance | null = null\n\nexport function getIsHydrating(): boolean {\n return isHydrating\n}\n\nexport function getHydrationState(): SerializedState | null {\n return hydrationState\n}\n\n/**\n * Hydrate server-rendered HTML with client-side interactivity\n */\nexport function hydrate(\n app: FNodeChild | (() => FNodeChild),\n container: HTMLElement,\n options: HydrateOptions = {}\n): void {\n const { state, onHydrated, onMismatch } = options\n\n // Store state for rehydration\n hydrationState = state || null\n\n // Initialize hydration mode\n isHydrating = true\n hydrationCursor = container.firstChild\n\n try {\n // Normalize input\n let fnode: FNodeChild\n if (typeof app === 'function' && !isFNode(app)) {\n fnode = { type: app, props: {}, children: [], key: undefined }\n } else {\n fnode = app\n }\n\n // Hydrate the tree\n hydrateNode(fnode, container)\n\n onHydrated?.()\n } catch (error) {\n // Hydration mismatch - fall back to full render\n console.warn('[Flexium] Hydration mismatch, falling back to full render:', error)\n onMismatch?.(error as Error)\n\n // Clear and re-render\n container.innerHTML = ''\n // Import dynamically to avoid circular deps\n import('./render').then(({ render }) => {\n render(app, container)\n })\n } finally {\n isHydrating = false\n hydrationCursor = null\n hydrationState = null\n }\n}\n\nfunction isFNode(value: any): value is FNode {\n return value && typeof value === 'object' && 'type' in value && 'props' in value\n}\n\nfunction hydrateNode(fnode: FNodeChild, parent: HTMLElement): Node | Node[] | null {\n // Null/undefined/boolean -> skip empty text nodes\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n // Server might have rendered an empty text node\n skipEmptyTextNodes()\n return null\n }\n\n // String/number -> expect text node\n if (typeof fnode === 'string' || typeof fnode === 'number') {\n return hydrateTextNode(String(fnode))\n }\n\n // Array -> hydrate each child\n if (Array.isArray(fnode)) {\n const nodes: Node[] = []\n for (const child of fnode) {\n const result = hydrateNode(child, parent)\n if (result) {\n if (Array.isArray(result)) {\n nodes.push(...result)\n } else {\n nodes.push(result)\n }\n }\n }\n return nodes\n }\n\n // Function (standalone) -> wrap in FNode and hydrate\n if (typeof fnode === 'function') {\n const wrappedFnode: FNode = { type: fnode, props: {}, children: [], key: undefined }\n return hydrateComponent(wrappedFnode, parent)\n }\n\n // Object (FNode)\n if (typeof fnode === 'object' && isFNode(fnode)) {\n if (typeof fnode.type === 'string') {\n return hydrateElement(fnode)\n }\n\n if (typeof fnode.type === 'function') {\n return hydrateComponent(fnode, parent)\n }\n }\n\n return null\n}\n\nfunction skipEmptyTextNodes(): void {\n while (\n hydrationCursor &&\n hydrationCursor.nodeType === Node.TEXT_NODE &&\n (!hydrationCursor.textContent || hydrationCursor.textContent.trim() === '')\n ) {\n hydrationCursor = hydrationCursor.nextSibling\n }\n}\n\nfunction hydrateTextNode(text: string): Node | null {\n skipEmptyTextNodes()\n\n const current = hydrationCursor\n\n if (!current) {\n // No node to hydrate - this is okay for conditional rendering\n return null\n }\n\n if (current.nodeType !== Node.TEXT_NODE) {\n // Try to find a text node nearby (whitespace handling)\n if (text.trim() === '') {\n return null\n }\n throw new Error(`Hydration mismatch: expected text node \"${text}\", got ${current.nodeName}`)\n }\n\n // Update cursor\n hydrationCursor = current.nextSibling\n\n return current\n}\n\nfunction hydrateElement(fnode: FNode): Node {\n skipEmptyTextNodes()\n\n const current = hydrationCursor as Element\n const tag = fnode.type as string\n\n // Validate element type\n if (!current || current.nodeType !== Node.ELEMENT_NODE) {\n throw new Error(`Hydration mismatch: expected element <${tag}>, got ${current?.nodeName || 'nothing'}`)\n }\n\n if (current.tagName.toLowerCase() !== tag.toLowerCase()) {\n throw new Error(`Hydration mismatch: expected <${tag}>, got <${current.tagName.toLowerCase()}>`)\n }\n\n // Attach event handlers and refs (don't modify DOM structure)\n if (fnode.props) {\n for (const [key, value] of Object.entries(fnode.props)) {\n if (key === 'ref') {\n if (typeof value === 'function') {\n value(current)\n } else if (value && typeof value === 'object' && 'current' in value) {\n value.current = current\n }\n } else if (key.startsWith('on') && typeof value === 'function') {\n const eventName = key.slice(2).toLowerCase()\n current.addEventListener(eventName, value as EventListener)\n\n // Store for reconciliation\n if (!(current as any).__eventHandlers) {\n (current as any).__eventHandlers = {}\n }\n (current as any).__eventHandlers[eventName] = value\n }\n }\n }\n\n // Move cursor past this element\n hydrationCursor = current.nextSibling\n\n // Hydrate children\n if (fnode.children && fnode.children.length > 0) {\n const savedCursor = hydrationCursor\n\n hydrationCursor = current.firstChild\n\n for (const child of fnode.children) {\n hydrateNode(child, current as HTMLElement)\n }\n\n hydrationCursor = savedCursor\n }\n\n return current\n}\n\nfunction hydrateComponent(fnode: FNode, parent: HTMLElement): Node | Node[] | null {\n const Component = fnode.type as Function\n\n // Merge props\n const props = { ...fnode.props }\n if (fnode.children && fnode.children.length > 0) {\n props.children = fnode.children.length === 1\n ? fnode.children[0]\n : fnode.children\n }\n\n // Handle context providers\n const contextId = (Component as any)._contextId\n const isProvider = contextId !== undefined\n let prevContextValue: any\n\n if (isProvider) {\n prevContextValue = pushContext(contextId, props.value)\n }\n\n // Generate key (same logic as render.ts)\n if (!hydratedInstanceRegistry.has(parent)) {\n hydratedInstanceRegistry.set(parent, new Map())\n }\n const parentRegistry = hydratedInstanceRegistry.get(parent)!\n\n const hasExplicitKey = fnode.key !== undefined\n let key: any\n if (hasExplicitKey) {\n key = fnode.key\n } else {\n let instanceCount = 0\n const componentName = (Component as any).name || 'anonymous'\n parentRegistry.forEach((_, k) => {\n if (typeof k === 'string' && k.startsWith(`__auto_${componentName}_`)) {\n instanceCount++\n }\n })\n key = `__auto_${componentName}_${instanceCount}`\n }\n\n // Create component instance\n const instance: DOMComponentInstance = {\n hooks: [],\n hookIndex: 0,\n nodes: [],\n parent,\n fnode,\n props,\n key,\n children: new Set(),\n parentInstance: currentHydratingInstance || undefined\n }\n\n if (currentHydratingInstance) {\n currentHydratingInstance.children.add(instance)\n }\n\n parentRegistry.set(key, instance)\n\n const previousHydratingInstance = currentHydratingInstance\n currentHydratingInstance = instance\n\n try {\n // First render during hydration - just match DOM\n const result = runWithComponent(instance, () => Component(props))\n const nodes = hydrateNode(result, parent)\n instance.nodes = nodes ? (Array.isArray(nodes) ? nodes : [nodes]) : []\n\n // Set up reactive re-rendering for future updates\n let isFirstRender = true\n const renderFn = () => {\n if (isFirstRender) {\n isFirstRender = false\n return // Skip first render, already done during hydration\n }\n\n // Re-render logic (same as render.ts but simplified)\n const currentProps = instance.props\n runWithComponent(instance, () => Component(currentProps))\n\n // For subsequent renders, use full render path\n // This will be handled by the normal reconciliation\n }\n\n instance.renderFn = renderFn\n unsafeEffect(renderFn)\n\n return instance.nodes\n } finally {\n currentHydratingInstance = previousHydratingInstance\n\n if (isProvider) {\n popContext(contextId, prevContextValue)\n }\n }\n}\n","import { use } from '../../core/use'\nimport { hook } from '../../core/hook'\nimport { render } from '../render'\nimport type { PortalProps } from './types'\n\n/**\n * Portal component that renders children into a different DOM node\n *\n * @example\n * ```tsx\n * function Modal({ isOpen, onClose, children }) {\n * if (!isOpen) return null\n *\n * return (\n * <Portal target={document.body}>\n * <div class=\"modal-backdrop\" onClick={onClose}>\n * <div class=\"modal-content\" onClick={e => e.stopPropagation()}>\n * {children}\n * </div>\n * </div>\n * </Portal>\n * )\n * }\n * ```\n */\nexport function Portal(props: PortalProps): null {\n const { target, children } = props\n\n // Store rendered container for cleanup\n const portalState = hook(() => ({\n container: null as HTMLElement | null,\n mounted: false\n }))\n\n use(({ onCleanup }) => {\n // Resolve target container\n let container: HTMLElement | null = null\n\n if (typeof target === 'string') {\n container = document.querySelector(target)\n } else if (target instanceof HTMLElement) {\n container = target\n }\n\n if (!container) {\n console.warn('[Flexium Portal] Target container not found:', target)\n return\n }\n\n // Create a wrapper div to contain portal content\n const portalWrapper = document.createElement('div')\n portalWrapper.setAttribute('data-flexium-portal', 'true')\n container.appendChild(portalWrapper)\n\n portalState.container = portalWrapper\n portalState.mounted = true\n\n // Render children into the portal wrapper\n render(children, portalWrapper)\n\n // Cleanup function\n onCleanup(() => {\n if (portalWrapper.parentNode) {\n portalWrapper.parentNode.removeChild(portalWrapper)\n }\n portalState.container = null\n portalState.mounted = false\n })\n }, [target, children])\n\n // Portal renders nothing in its original location\n return null\n}\n","import { Context } from '../../core/context'\nimport { use } from '../../core/use'\nimport type { SuspenseContextValue } from './types'\n\nconst defaultValue: SuspenseContextValue = {\n register: () => {},\n hasBoundary: false\n}\n\nexport const SuspenseCtx = new Context<SuspenseContextValue>(defaultValue)\n\nexport function suspenseContext(): SuspenseContextValue {\n const [value] = use(SuspenseCtx)\n return value\n}\n","import { use } from '../../core/use'\nimport { hook } from '../../core/hook'\nimport { SuspenseCtx } from './suspenseContext'\nimport type { SuspenseProps, SuspenseContextValue } from './types'\nimport type { FNodeChild } from '../types'\n\n/**\n * Suspense component that shows fallback while children are loading\n *\n * @example\n * ```tsx\n * const Dashboard = lazy(() => import('./Dashboard'))\n *\n * function App() {\n * return (\n * <Suspense fallback={<div>Loading...</div>}>\n * <Dashboard />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function Suspense(props: SuspenseProps): FNodeChild {\n const { fallback, children } = props\n\n // Track pending promises using hook for mutable Set\n const pendingSet = hook(() => new Set<Promise<any>>())\n const [, setPendingCount] = use(0)\n const [showFallback, setShowFallback] = use(false)\n\n // Register function for lazy components\n const register = (promise: Promise<any>) => {\n if (!pendingSet.has(promise)) {\n // Add to pending set\n pendingSet.add(promise)\n setPendingCount(c => c + 1)\n setShowFallback(true)\n\n // Wait for resolution\n promise.finally(() => {\n pendingSet.delete(promise)\n setPendingCount(c => {\n const newCount = c - 1\n if (newCount === 0) {\n setShowFallback(false)\n }\n return newCount\n })\n })\n }\n }\n\n const contextValue: SuspenseContextValue = {\n register,\n hasBoundary: true\n }\n\n // Render fallback or children based on pending state\n const content = showFallback ? fallback : children\n\n // Wrap content with Suspense context provider\n return {\n type: SuspenseCtx.Provider,\n props: { value: contextValue },\n children: [content],\n key: undefined\n } as any\n}\n","import { use } from '../../core/use'\nimport { hook } from '../../core/hook'\nimport type { FNodeChild } from '../types'\nimport type { ErrorInfo, ErrorBoundaryProps } from './types'\n\n// Component name stack for error messages\nlet componentNameStack: string[] = []\n\nexport function pushComponentName(name: string): void {\n componentNameStack.push(name)\n}\n\nexport function popComponentName(): void {\n componentNameStack.pop()\n}\n\nexport function getComponentStack(): string {\n return componentNameStack\n .map(name => ` at ${name}`)\n .reverse()\n .join('\\n')\n}\n\n// Stack of error boundaries for nested error propagation\ninterface ErrorBoundaryInstance {\n handleError: (error: Error, phase: 'render' | 'effect' | 'event') => void\n}\n\nlet errorBoundaryStack: ErrorBoundaryInstance[] = []\n\nexport function pushErrorBoundary(instance: ErrorBoundaryInstance): void {\n errorBoundaryStack.push(instance)\n}\n\nexport function popErrorBoundary(): void {\n errorBoundaryStack.pop()\n}\n\nexport function getNearestErrorBoundary(): ErrorBoundaryInstance | null {\n return errorBoundaryStack[errorBoundaryStack.length - 1] || null\n}\n\n/**\n * ErrorBoundary component that catches errors in its children and displays fallback UI\n *\n * @example\n * ```tsx\n * <ErrorBoundary\n * fallback={(error, info) => <div>Error: {error.message}</div>}\n * onError={(error, info) => console.error(error)}\n * >\n * <App />\n * </ErrorBoundary>\n * ```\n */\nexport function ErrorBoundary(props: ErrorBoundaryProps): FNodeChild {\n const { fallback, onError, children, resetKey } = props\n\n // Error state\n const [errorState, setErrorState] = use<{\n error: Error | null\n info: ErrorInfo | null\n }>({ error: null, info: null })\n\n // Track reset key changes to clear error\n const prevResetKeyRef = hook(() => ({ current: resetKey }))\n\n if (resetKey !== prevResetKeyRef.current) {\n prevResetKeyRef.current = resetKey\n if (errorState.error !== null) {\n setErrorState({ error: null, info: null })\n }\n }\n\n // Error boundary instance\n const boundaryInstance: ErrorBoundaryInstance = {\n handleError: (error: Error, phase: 'render' | 'effect' | 'event') => {\n const info: ErrorInfo = {\n componentStack: getComponentStack(),\n phase\n }\n\n // Call error callback\n onError?.(error, info)\n\n // Update error state (triggers re-render with fallback)\n setErrorState({ error, info })\n }\n }\n\n // If we have an error, render fallback\n if (errorState.error) {\n if (typeof fallback === 'function') {\n return fallback(errorState.error, errorState.info!)\n }\n return fallback\n }\n\n // Push boundary onto stack for children to use\n pushErrorBoundary(boundaryInstance)\n\n try {\n // Return children - they will be rendered with this boundary active\n return children\n } finally {\n popErrorBoundary()\n }\n}\n","import { suspenseContext } from './suspenseContext'\nimport type { FNodeChild } from '../types'\nimport type { LazyComponent } from './types'\n\n/**\n * Creates a lazy-loaded component for code splitting\n *\n * @example\n * ```tsx\n * const Dashboard = lazy(() => import('./Dashboard'))\n * const Settings = lazy(() => import('./Settings'))\n *\n * function App() {\n * return (\n * <Suspense fallback={<div>Loading...</div>}>\n * <Dashboard />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function lazy<P = {}>(\n loader: () => Promise<{ default: (props: P) => FNodeChild }>\n): LazyComponent<P> {\n // Shared state across all instances\n let resolved: ((props: P) => FNodeChild) | null = null\n let promise: Promise<any> | null = null\n let error: Error | null = null\n\n // The wrapper component\n const LazyWrapper = (props: P): FNodeChild => {\n // If already resolved, render immediately\n if (resolved) {\n return resolved(props)\n }\n\n // If error occurred, throw it (will be caught by ErrorBoundary)\n if (error) {\n throw error\n }\n\n // Get suspense context\n const suspense = suspenseContext()\n\n // Start loading if not already\n if (!promise) {\n promise = loader()\n .then(module => {\n resolved = module.default\n })\n .catch(err => {\n error = err instanceof Error ? err : new Error(String(err))\n })\n }\n\n // Register with suspense boundary if available\n if (suspense.hasBoundary) {\n suspense.register(promise)\n }\n\n // Return null - Suspense will show fallback\n return null\n }\n\n // Mark as lazy component\n ;(LazyWrapper as LazyComponent<P>)._lazy = true\n ;(LazyWrapper as LazyComponent<P>)._loader = loader\n\n return LazyWrapper as LazyComponent<P>\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- declare const VERSION = "0.13.0";
1
+ declare const VERSION = "0.13.1";
2
2
 
3
3
  export { VERSION };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const VERSION = "0.13.0";
1
+ declare const VERSION = "0.13.1";
2
2
 
3
3
  export { VERSION };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var o="0.13.0";exports.VERSION=o;//# sourceMappingURL=index.js.map
1
+ 'use strict';var o="0.13.1";exports.VERSION=o;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["VERSION"],"mappings":"aAAO,IAAMA,CAAAA,CAAU","file":"index.js","sourcesContent":["export const VERSION = '0.13.0' // Bump version to signify rebuild\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["VERSION"],"mappings":"aAAO,IAAMA,CAAAA,CAAU","file":"index.js","sourcesContent":["export const VERSION = '0.13.1' // Bump version to signify rebuild\n"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var o="0.13.0";export{o as VERSION};//# sourceMappingURL=index.mjs.map
1
+ var o="0.13.1";export{o as VERSION};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["VERSION"],"mappings":"AAAO,IAAMA,CAAAA,CAAU","file":"index.mjs","sourcesContent":["export const VERSION = '0.13.0' // Bump version to signify rebuild\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["VERSION"],"mappings":"AAAO,IAAMA,CAAAA,CAAU","file":"index.mjs","sourcesContent":["export const VERSION = '0.13.1' // Bump version to signify rebuild\n"]}
@@ -77,8 +77,8 @@ interface Loop {
77
77
 
78
78
  declare function useLoop(callbacks: LoopCallbacks): Loop;
79
79
 
80
- declare function keyboard(target?: EventTarget): KeyboardState;
80
+ declare function useKeyboard(target?: EventTarget): KeyboardState;
81
81
 
82
- declare function mouse(options?: MouseOptions): MouseState;
82
+ declare function useMouse(options?: MouseOptions): MouseState;
83
83
 
84
- export { type KeyboardState, Keys, type Loop, type LoopCallbacks, MouseButton, type MouseOptions, type MouseState, keyboard, mouse, useLoop };
84
+ export { type KeyboardState, Keys, type Loop, type LoopCallbacks, MouseButton, type MouseOptions, type MouseState, useKeyboard, useLoop, useMouse };
@@ -77,8 +77,8 @@ interface Loop {
77
77
 
78
78
  declare function useLoop(callbacks: LoopCallbacks): Loop;
79
79
 
80
- declare function keyboard(target?: EventTarget): KeyboardState;
80
+ declare function useKeyboard(target?: EventTarget): KeyboardState;
81
81
 
82
- declare function mouse(options?: MouseOptions): MouseState;
82
+ declare function useMouse(options?: MouseOptions): MouseState;
83
83
 
84
- export { type KeyboardState, Keys, type Loop, type LoopCallbacks, MouseButton, type MouseOptions, type MouseState, keyboard, mouse, useLoop };
84
+ export { type KeyboardState, Keys, type Loop, type LoopCallbacks, MouseButton, type MouseOptions, type MouseState, useKeyboard, useLoop, useMouse };
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkW2L7BLE7_js=require('./chunk-W2L7BLE7.js');require('./chunk-3CKIHQIE.js'),require('./chunk-UWFVCKRU.js'),require('./chunk-CGB4YXKS.js');function F(a){let{fixedFps:n=60,onUpdate:v,onFixedUpdate:o,onRender:y}=a,p=1/n,S=.25,l=false,m=0,t=0,s=0,i=0,u=0,r=null;function d(w){if(!l)return;let D=Math.min((w-m)/1e3,S);if(m=w,v&&v(D),o)for(t+=D;t>=p;)o(p),t-=p;if(y){let h=t/p;y(h);}i++,w-u>=1e3&&(s=i,i=0,u=w),r=requestAnimationFrame(d);}return {start:()=>{l||(l=true,m=performance.now(),t=0,r=requestAnimationFrame(d));},stop:()=>{l=false,r!==null&&(cancelAnimationFrame(r),r=null);},isRunning:()=>l,getFps:()=>s}}var x=(e=>(e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.ArrowLeft="ArrowLeft",e.ArrowRight="ArrowRight",e.KeyW="KeyW",e.KeyA="KeyA",e.KeyS="KeyS",e.KeyD="KeyD",e.Space="Space",e.Enter="Enter",e.Escape="Escape",e.Tab="Tab",e.ShiftLeft="ShiftLeft",e.ShiftRight="ShiftRight",e.ControlLeft="ControlLeft",e.ControlRight="ControlRight",e.AltLeft="AltLeft",e.AltRight="AltRight",e.Digit0="Digit0",e.Digit1="Digit1",e.Digit2="Digit2",e.Digit3="Digit3",e.Digit4="Digit4",e.Digit5="Digit5",e.Digit6="Digit6",e.Digit7="Digit7",e.Digit8="Digit8",e.Digit9="Digit9",e.KeyE="KeyE",e.KeyQ="KeyQ",e.KeyR="KeyR",e.KeyF="KeyF",e))(x||{}),k=(o=>(o[o.Left=0]="Left",o[o.Middle=1]="Middle",o[o.Right=2]="Right",o))(k||{});function C(a=window){let[n,v]=chunkW2L7BLE7_js.c(new Set,{key:["keyboard","pressed"]}),[o,y]=chunkW2L7BLE7_js.c(new Set,{key:["keyboard","justPressed"]}),[p,S]=chunkW2L7BLE7_js.c(new Set,{key:["keyboard","justReleased"]}),l=t=>{let s=t.code,i=n;if(!i.has(s)){let u=new Set(i);u.add(s),v(u);let r=o,d=new Set(r);d.add(s),y(d);}},m=t=>{let s=t.code,i=n,u=new Set(i);u.delete(s),v(u);let r=p,d=new Set(r);d.add(s),S(d);};return a.addEventListener("keydown",l),a.addEventListener("keyup",m),{isPressed:t=>n?.has(t)||false,isJustPressed:t=>o?.has(t)||false,isJustReleased:t=>p?.has(t)||false,getPressedKeys:()=>Array.from(n||[]),clearFrameState:()=>{y(new Set),S(new Set);},dispose:()=>{a.removeEventListener("keydown",l),a.removeEventListener("keyup",m);}}}function J(a={}){let n=a.target||window,v=typeof a.canvas=="function"?a.canvas:()=>a.canvas,[o,y]=chunkW2L7BLE7_js.c({x:0,y:0},{key:["mouse","position"]}),[p,S]=chunkW2L7BLE7_js.c({x:0,y:0},{key:["mouse","delta"]}),[l,m]=chunkW2L7BLE7_js.c(0,{key:["mouse","wheel"]}),[t,s]=chunkW2L7BLE7_js.c(new Set,{key:["mouse","buttons"]}),i=0,u=0,r=g=>{let f=g,L=v(),c=f.clientX,E=f.clientY;if(L){let M=L.getBoundingClientRect();c=f.clientX-M.left,E=f.clientY-M.top;}y({x:c,y:E}),S({x:c-i,y:E-u}),i=c,u=E;},d=g=>{let f=g.button,L=t,c=new Set(L);c.add(f),s(c);},w=g=>{let f=g.button,L=t,c=new Set(L);c.delete(f),s(c);},D=g=>{m(g.deltaY);};n.addEventListener("mousemove",r),n.addEventListener("mousedown",d),n.addEventListener("mouseup",w),n.addEventListener("wheel",D);let h=t,P=o,R=p,A=l;return {get x(){return P.x},get y(){return P.y},get deltaX(){return R.x},get deltaY(){return R.y},get wheelDelta(){return A},isPressed:g=>h?.has(g)||false,isLeftPressed:()=>h?.has(0)||false,isRightPressed:()=>h?.has(2)||false,isMiddlePressed:()=>h?.has(1)||false,clearFrameState:()=>{S({x:0,y:0}),m(0);},dispose:()=>{n.removeEventListener("mousemove",r),n.removeEventListener("mousedown",d),n.removeEventListener("mouseup",w),n.removeEventListener("wheel",D);}}}exports.Keys=x;exports.MouseButton=k;exports.keyboard=C;exports.mouse=J;exports.useLoop=F;//# sourceMappingURL=interactive.js.map
1
+ 'use strict';var chunkACYN2UKT_js=require('./chunk-ACYN2UKT.js');require('./chunk-3CKIHQIE.js'),require('./chunk-E6Z7AI4J.js');function F(a){let{fixedFps:n=60,onUpdate:v,onFixedUpdate:o,onRender:y}=a,p=1/n,S=.25,l=false,m=0,t=0,s=0,i=0,u=0,r=null;function d(w){if(!l)return;let D=Math.min((w-m)/1e3,S);if(m=w,v&&v(D),o)for(t+=D;t>=p;)o(p),t-=p;if(y){let h=t/p;y(h);}i++,w-u>=1e3&&(s=i,i=0,u=w),r=requestAnimationFrame(d);}return {start:()=>{l||(l=true,m=performance.now(),t=0,r=requestAnimationFrame(d));},stop:()=>{l=false,r!==null&&(cancelAnimationFrame(r),r=null);},isRunning:()=>l,getFps:()=>s}}var x=(e=>(e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.ArrowLeft="ArrowLeft",e.ArrowRight="ArrowRight",e.KeyW="KeyW",e.KeyA="KeyA",e.KeyS="KeyS",e.KeyD="KeyD",e.Space="Space",e.Enter="Enter",e.Escape="Escape",e.Tab="Tab",e.ShiftLeft="ShiftLeft",e.ShiftRight="ShiftRight",e.ControlLeft="ControlLeft",e.ControlRight="ControlRight",e.AltLeft="AltLeft",e.AltRight="AltRight",e.Digit0="Digit0",e.Digit1="Digit1",e.Digit2="Digit2",e.Digit3="Digit3",e.Digit4="Digit4",e.Digit5="Digit5",e.Digit6="Digit6",e.Digit7="Digit7",e.Digit8="Digit8",e.Digit9="Digit9",e.KeyE="KeyE",e.KeyQ="KeyQ",e.KeyR="KeyR",e.KeyF="KeyF",e))(x||{}),P=(o=>(o[o.Left=0]="Left",o[o.Middle=1]="Middle",o[o.Right=2]="Right",o))(P||{});function C(a=window){let[n,v]=chunkACYN2UKT_js.c(new Set,{key:["keyboard","pressed"]}),[o,y]=chunkACYN2UKT_js.c(new Set,{key:["keyboard","justPressed"]}),[p,S]=chunkACYN2UKT_js.c(new Set,{key:["keyboard","justReleased"]}),l=t=>{let s=t.code,i=n;if(!i.has(s)){let u=new Set(i);u.add(s),v(u);let r=o,d=new Set(r);d.add(s),y(d);}},m=t=>{let s=t.code,i=n,u=new Set(i);u.delete(s),v(u);let r=p,d=new Set(r);d.add(s),S(d);};return a.addEventListener("keydown",l),a.addEventListener("keyup",m),{isPressed:t=>n?.has(t)||false,isJustPressed:t=>o?.has(t)||false,isJustReleased:t=>p?.has(t)||false,getPressedKeys:()=>Array.from(n||[]),clearFrameState:()=>{y(new Set),S(new Set);},dispose:()=>{a.removeEventListener("keydown",l),a.removeEventListener("keyup",m);}}}function J(a={}){let n=a.target||window,v=typeof a.canvas=="function"?a.canvas:()=>a.canvas,[o,y]=chunkACYN2UKT_js.c({x:0,y:0},{key:["mouse","position"]}),[p,S]=chunkACYN2UKT_js.c({x:0,y:0},{key:["mouse","delta"]}),[l,m]=chunkACYN2UKT_js.c(0,{key:["mouse","wheel"]}),[t,s]=chunkACYN2UKT_js.c(new Set,{key:["mouse","buttons"]}),i=0,u=0,r=g=>{let f=g,L=v(),c=f.clientX,E=f.clientY;if(L){let k=L.getBoundingClientRect();c=f.clientX-k.left,E=f.clientY-k.top;}y({x:c,y:E}),S({x:c-i,y:E-u}),i=c,u=E;},d=g=>{let f=g.button,L=t,c=new Set(L);c.add(f),s(c);},w=g=>{let f=g.button,L=t,c=new Set(L);c.delete(f),s(c);},D=g=>{m(g.deltaY);};n.addEventListener("mousemove",r),n.addEventListener("mousedown",d),n.addEventListener("mouseup",w),n.addEventListener("wheel",D);let h=t,R=o,M=p,A=l;return {get x(){return R.x},get y(){return R.y},get deltaX(){return M.x},get deltaY(){return M.y},get wheelDelta(){return A},isPressed:g=>h?.has(g)||false,isLeftPressed:()=>h?.has(0)||false,isRightPressed:()=>h?.has(2)||false,isMiddlePressed:()=>h?.has(1)||false,clearFrameState:()=>{S({x:0,y:0}),m(0);},dispose:()=>{n.removeEventListener("mousemove",r),n.removeEventListener("mousedown",d),n.removeEventListener("mouseup",w),n.removeEventListener("wheel",D);}}}exports.Keys=x;exports.MouseButton=P;exports.useKeyboard=C;exports.useLoop=F;exports.useMouse=J;//# sourceMappingURL=interactive.js.map
2
2
  //# sourceMappingURL=interactive.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interactive/loop.ts","../src/interactive/types.ts","../src/interactive/keyboard.ts","../src/interactive/mouse.ts"],"names":["useLoop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","loop","currentTime","delta","alpha","Keys","MouseButton","keyboard","target","pressedKeys","setPressedKeys","use","justPressedKeys","setJustPressedKeys","justReleasedKeys","setJustReleasedKeys","handleKeyDown","e","key","currentPressed","newPressed","currentJustPressed","newJustPressed","handleKeyUp","currentJustReleased","newJustReleased","mouse","options","canvasGetter","position","setPosition","setDelta","wheelDelta","setWheelDelta","buttons","setButtons","lastX","lastY","handleMouseMove","me","canvas","x","y","rect","handleMouseDown","button","currentButtons","newButtons","handleMouseUp","handleWheel","currentPosition","currentDelta","currentWheelDelta"],"mappings":"8JAIO,SAASA,CAAAA,CAAQC,EAAgC,CACtD,GAAM,CAAE,QAAA,CAAAC,CAAAA,CAAW,GAAI,QAAA,CAAAC,CAAAA,CAAU,cAAAC,CAAAA,CAAe,QAAA,CAAAC,CAAS,CAAA,CAAIJ,CAAAA,CAEvDK,EAAa,CAAA,CAAIJ,CAAAA,CACjBK,EAAW,GAAA,CAEbC,CAAAA,CAAU,MACVC,CAAAA,CAAW,CAAA,CACXC,EAAc,CAAA,CACdC,CAAAA,CAAM,EACNC,CAAAA,CAAa,CAAA,CACbC,EAAU,CAAA,CACVC,CAAAA,CAAuB,KAE3B,SAASC,CAAAA,CAAKC,EAAqB,CACjC,GAAI,CAACR,CAAAA,CAAS,OAGd,IAAMS,CAAAA,CAAQ,IAAA,CAAK,GAAA,CAAA,CAAKD,EAAcP,CAAAA,EAAY,GAAA,CAAMF,CAAQ,CAAA,CAShE,GARAE,EAAWO,CAAAA,CAGPb,CAAAA,EACFA,EAASc,CAAK,CAAA,CAIZb,EAGF,IAF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CAAAA,CAAO,iBAAiB,OAAA,CAASyC,CAAW,EAE5C,IAAMH,CAAAA,CAAiBZ,EACjBgB,CAAAA,CAAkBrB,CAAAA,CAClBsB,EAAehD,CAAAA,CACfiD,CAAAA,CAAoBpB,CAAAA,CAE1B,OAAO,CACL,IAAI,GAAI,CAAE,OAAOkB,EAAgB,CAAE,CAAA,CACnC,IAAI,CAAA,EAAI,CAAE,OAAOA,CAAAA,CAAgB,CAAE,EACnC,IAAI,MAAA,EAAS,CAAE,OAAOC,CAAAA,CAAa,CAAE,CAAA,CACrC,IAAI,QAAS,CAAE,OAAOA,EAAa,CAAE,CAAA,CACrC,IAAI,UAAA,EAAa,CAAE,OAAOC,CAAkB,CAAA,CAE5C,UAAYP,CAAAA,EAAwBC,CAAAA,EAAgB,IAAID,CAAM,CAAA,EAAK,MAEnE,aAAA,CAAe,IAAMC,GAAgB,GAAA,CAAA,CAAoB,CAAA,EAAK,KAAA,CAE9D,cAAA,CAAgB,IAAMA,CAAAA,EAAgB,KAAqB,CAAA,EAAK,KAAA,CAEhE,gBAAiB,IAAMA,CAAAA,EAAgB,KAAsB,CAAA,EAAK,KAAA,CAElE,gBAAiB,IAAM,CACrBf,EAAS,CAAE,CAAA,CAAG,EAAG,CAAA,CAAG,CAAE,CAAC,CAAA,CACvBE,CAAAA,CAAc,CAAC,EACjB,CAAA,CAEA,OAAA,CAAS,IAAM,CACbzB,CAAAA,CAAO,oBAAoB,WAAA,CAAa8B,CAAe,EACvD9B,CAAAA,CAAO,mBAAA,CAAoB,YAAaoC,CAAe,CAAA,CACvDpC,EAAO,mBAAA,CAAoB,SAAA,CAAWwC,CAAa,CAAA,CACnDxC,CAAAA,CAAO,oBAAoB,OAAA,CAASyC,CAAW,EACjD,CACF,CACF","file":"interactive.js","sourcesContent":["import type { LoopCallbacks, Loop } from './types'\n\nexport type { LoopCallbacks, Loop }\n\nexport function useLoop(callbacks: LoopCallbacks): Loop {\n const { fixedFps = 60, onUpdate, onFixedUpdate, onRender } = callbacks\n\n const fixedDelta = 1 / fixedFps\n const maxDelta = 0.25 // Cap delta at 250ms to prevent spiral of death\n\n let running = false\n let lastTime = 0\n let accumulator = 0\n let fps = 0\n let frameCount = 0\n let fpsTime = 0\n let rafId: number | null = null\n\n function loop(currentTime: number) {\n if (!running) return\n\n // Calculate delta in seconds\n const delta = Math.min((currentTime - lastTime) / 1000, maxDelta)\n lastTime = currentTime\n\n // Variable timestep update\n if (onUpdate) {\n onUpdate(delta)\n }\n\n // Fixed timestep update\n if (onFixedUpdate) {\n accumulator += delta\n\n while (accumulator >= fixedDelta) {\n onFixedUpdate(fixedDelta)\n accumulator -= fixedDelta\n }\n }\n\n // Render with interpolation alpha\n if (onRender) {\n const alpha = accumulator / fixedDelta\n onRender(alpha)\n }\n\n // FPS calculation\n frameCount++\n if (currentTime - fpsTime >= 1000) {\n fps = frameCount\n frameCount = 0\n fpsTime = currentTime\n }\n\n rafId = requestAnimationFrame(loop)\n }\n\n return {\n start: () => {\n if (running) return\n running = true\n lastTime = performance.now()\n accumulator = 0\n rafId = requestAnimationFrame(loop)\n },\n\n stop: () => {\n running = false\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n },\n\n isRunning: () => running,\n\n getFps: () => fps\n }\n}\n","// Keyboard types\nexport enum Keys {\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n KeyW = 'KeyW',\n KeyA = 'KeyA',\n KeyS = 'KeyS',\n KeyD = 'KeyD',\n Space = 'Space',\n Enter = 'Enter',\n Escape = 'Escape',\n Tab = 'Tab',\n ShiftLeft = 'ShiftLeft',\n ShiftRight = 'ShiftRight',\n ControlLeft = 'ControlLeft',\n ControlRight = 'ControlRight',\n AltLeft = 'AltLeft',\n AltRight = 'AltRight',\n Digit0 = 'Digit0',\n Digit1 = 'Digit1',\n Digit2 = 'Digit2',\n Digit3 = 'Digit3',\n Digit4 = 'Digit4',\n Digit5 = 'Digit5',\n Digit6 = 'Digit6',\n Digit7 = 'Digit7',\n Digit8 = 'Digit8',\n Digit9 = 'Digit9',\n KeyE = 'KeyE',\n KeyQ = 'KeyQ',\n KeyR = 'KeyR',\n KeyF = 'KeyF',\n}\n\nexport interface KeyboardState {\n isPressed: (key: string) => boolean\n isJustPressed: (key: string) => boolean\n isJustReleased: (key: string) => boolean\n getPressedKeys: () => string[]\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Mouse types\nexport enum MouseButton {\n Left = 0,\n Middle = 1,\n Right = 2\n}\n\nexport interface MouseOptions {\n canvas?: HTMLCanvasElement | (() => HTMLCanvasElement | undefined)\n target?: EventTarget\n}\n\nexport interface MouseState {\n x: number | null\n y: number | null\n deltaX: number\n deltaY: number\n wheelDelta: number\n isPressed: (button: MouseButton) => boolean\n isLeftPressed: () => boolean\n isRightPressed: () => boolean\n isMiddlePressed: () => boolean\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Loop types\nexport interface LoopCallbacks {\n fixedFps?: number\n onUpdate?: (delta: number) => void\n onFixedUpdate?: (fixedDelta: number) => void\n onRender?: (alpha: number) => void\n}\n\nexport interface Loop {\n start: () => void\n stop: () => void\n isRunning: () => boolean\n getFps: () => number\n}\n","import { use } from '../core/use'\nimport { Keys, type KeyboardState } from './types'\n\nexport { Keys, type KeyboardState }\n\nexport function keyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justReleased'] })\n\n const handleKeyDown = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n if (!currentPressed.has(key)) {\n const newPressed = new Set(currentPressed)\n newPressed.add(key)\n setPressedKeys(newPressed)\n\n const currentJustPressed = justPressedKeys as Set<string>\n const newJustPressed = new Set(currentJustPressed)\n newJustPressed.add(key)\n setJustPressedKeys(newJustPressed)\n }\n }\n\n const handleKeyUp = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n const newPressed = new Set(currentPressed)\n newPressed.delete(key)\n setPressedKeys(newPressed)\n\n const currentJustReleased = justReleasedKeys as Set<string>\n const newJustReleased = new Set(currentJustReleased)\n newJustReleased.add(key)\n setJustReleasedKeys(newJustReleased)\n }\n\n target.addEventListener('keydown', handleKeyDown)\n target.addEventListener('keyup', handleKeyUp)\n\n return {\n isPressed: (key: string) => {\n const current = pressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustPressed: (key: string) => {\n const current = justPressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustReleased: (key: string) => {\n const current = justReleasedKeys as Set<string>\n return current?.has(key) || false\n },\n\n getPressedKeys: () => {\n const current = pressedKeys as Set<string>\n return Array.from(current || [])\n },\n\n clearFrameState: () => {\n setJustPressedKeys(new Set<string>())\n setJustReleasedKeys(new Set<string>())\n },\n\n dispose: () => {\n target.removeEventListener('keydown', handleKeyDown)\n target.removeEventListener('keyup', handleKeyUp)\n }\n }\n}\n","import { use } from '../core/use'\nimport { MouseButton, type MouseOptions, type MouseState } from './types'\n\nexport { MouseButton, type MouseOptions, type MouseState }\n\nexport function mouse(options: MouseOptions = {}): MouseState {\n const target = options.target || window\n const canvasGetter = typeof options.canvas === 'function' ? options.canvas : () => options.canvas as HTMLCanvasElement | undefined\n\n const [position, setPosition] = use({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = use({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = use(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = use<Set<number>>(new Set<number>(), { key: ['mouse', 'buttons'] })\n\n let lastX = 0\n let lastY = 0\n\n const handleMouseMove = (e: Event) => {\n const me = e as MouseEvent\n const canvas = canvasGetter()\n\n let x = me.clientX\n let y = me.clientY\n\n // If canvas is provided, calculate position relative to canvas\n if (canvas) {\n const rect = canvas.getBoundingClientRect()\n x = me.clientX - rect.left\n y = me.clientY - rect.top\n }\n\n setPosition({ x, y })\n setDelta({ x: x - lastX, y: y - lastY })\n lastX = x\n lastY = y\n }\n\n const handleMouseDown = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.add(button)\n setButtons(newButtons)\n }\n\n const handleMouseUp = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.delete(button)\n setButtons(newButtons)\n }\n\n const handleWheel = (e: Event) => {\n const we = e as WheelEvent\n setWheelDelta(we.deltaY)\n }\n\n target.addEventListener('mousemove', handleMouseMove)\n target.addEventListener('mousedown', handleMouseDown)\n target.addEventListener('mouseup', handleMouseUp)\n target.addEventListener('wheel', handleWheel)\n\n const currentButtons = buttons as Set<number>\n const currentPosition = position as { x: number; y: number }\n const currentDelta = delta as { x: number; y: number }\n const currentWheelDelta = wheelDelta as number\n\n return {\n get x() { return currentPosition.x },\n get y() { return currentPosition.y },\n get deltaX() { return currentDelta.x },\n get deltaY() { return currentDelta.y },\n get wheelDelta() { return currentWheelDelta },\n\n isPressed: (button: MouseButton) => currentButtons?.has(button) || false,\n\n isLeftPressed: () => currentButtons?.has(MouseButton.Left) || false,\n\n isRightPressed: () => currentButtons?.has(MouseButton.Right) || false,\n\n isMiddlePressed: () => currentButtons?.has(MouseButton.Middle) || false,\n\n clearFrameState: () => {\n setDelta({ x: 0, y: 0 })\n setWheelDelta(0)\n },\n\n dispose: () => {\n target.removeEventListener('mousemove', handleMouseMove)\n target.removeEventListener('mousedown', handleMouseDown)\n target.removeEventListener('mouseup', handleMouseUp)\n target.removeEventListener('wheel', handleWheel)\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/interactive/loop.ts","../src/interactive/types.ts","../src/interactive/keyboard.ts","../src/interactive/mouse.ts"],"names":["useLoop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","loop","currentTime","delta","alpha","Keys","MouseButton","useKeyboard","target","pressedKeys","setPressedKeys","use","justPressedKeys","setJustPressedKeys","justReleasedKeys","setJustReleasedKeys","handleKeyDown","e","key","currentPressed","newPressed","currentJustPressed","newJustPressed","handleKeyUp","currentJustReleased","newJustReleased","useMouse","options","canvasGetter","position","setPosition","setDelta","wheelDelta","setWheelDelta","buttons","setButtons","lastX","lastY","handleMouseMove","me","canvas","x","y","rect","handleMouseDown","button","currentButtons","newButtons","handleMouseUp","handleWheel","currentPosition","currentDelta","currentWheelDelta"],"mappings":"+HAIO,SAASA,CAAAA,CAAQC,EAAgC,CACtD,GAAM,CAAE,QAAA,CAAAC,CAAAA,CAAW,GAAI,QAAA,CAAAC,CAAAA,CAAU,cAAAC,CAAAA,CAAe,QAAA,CAAAC,CAAS,CAAA,CAAIJ,CAAAA,CAEvDK,EAAa,CAAA,CAAIJ,CAAAA,CACjBK,EAAW,GAAA,CAEbC,CAAAA,CAAU,MACVC,CAAAA,CAAW,CAAA,CACXC,EAAc,CAAA,CACdC,CAAAA,CAAM,EACNC,CAAAA,CAAa,CAAA,CACbC,EAAU,CAAA,CACVC,CAAAA,CAAuB,KAE3B,SAASC,CAAAA,CAAKC,EAAqB,CACjC,GAAI,CAACR,CAAAA,CAAS,OAGd,IAAMS,CAAAA,CAAQ,IAAA,CAAK,GAAA,CAAA,CAAKD,EAAcP,CAAAA,EAAY,GAAA,CAAMF,CAAQ,CAAA,CAShE,GARAE,EAAWO,CAAAA,CAGPb,CAAAA,EACFA,EAASc,CAAK,CAAA,CAIZb,EAGF,IAFAM,CAAAA,EAAeO,EAERP,CAAAA,EAAeJ,CAAAA,EACpBF,EAAcE,CAAU,CAAA,CACxBI,GAAe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A,CAAkBrB,CAAAA,CAClBsB,EAAehD,CAAAA,CACfiD,CAAAA,CAAoBpB,CAAAA,CAE1B,OAAO,CACL,IAAI,GAAI,CAAE,OAAOkB,EAAgB,CAAE,CAAA,CACnC,IAAI,CAAA,EAAI,CAAE,OAAOA,CAAAA,CAAgB,CAAE,EACnC,IAAI,MAAA,EAAS,CAAE,OAAOC,CAAAA,CAAa,CAAE,CAAA,CACrC,IAAI,QAAS,CAAE,OAAOA,EAAa,CAAE,CAAA,CACrC,IAAI,UAAA,EAAa,CAAE,OAAOC,CAAkB,CAAA,CAE5C,UAAYP,CAAAA,EAAwBC,CAAAA,EAAgB,IAAID,CAAM,CAAA,EAAK,MAEnE,aAAA,CAAe,IAAMC,GAAgB,GAAA,CAAA,CAAoB,CAAA,EAAK,KAAA,CAE9D,cAAA,CAAgB,IAAMA,CAAAA,EAAgB,KAAqB,CAAA,EAAK,KAAA,CAEhE,gBAAiB,IAAMA,CAAAA,EAAgB,KAAsB,CAAA,EAAK,KAAA,CAElE,gBAAiB,IAAM,CACrBf,EAAS,CAAE,CAAA,CAAG,EAAG,CAAA,CAAG,CAAE,CAAC,CAAA,CACvBE,CAAAA,CAAc,CAAC,EACjB,CAAA,CAEA,OAAA,CAAS,IAAM,CACbzB,CAAAA,CAAO,oBAAoB,WAAA,CAAa8B,CAAe,EACvD9B,CAAAA,CAAO,mBAAA,CAAoB,YAAaoC,CAAe,CAAA,CACvDpC,EAAO,mBAAA,CAAoB,SAAA,CAAWwC,CAAa,CAAA,CACnDxC,CAAAA,CAAO,oBAAoB,OAAA,CAASyC,CAAW,EACjD,CACF,CACF","file":"interactive.js","sourcesContent":["import type { LoopCallbacks, Loop } from './types'\n\nexport type { LoopCallbacks, Loop }\n\nexport function useLoop(callbacks: LoopCallbacks): Loop {\n const { fixedFps = 60, onUpdate, onFixedUpdate, onRender } = callbacks\n\n const fixedDelta = 1 / fixedFps\n const maxDelta = 0.25 // Cap delta at 250ms to prevent spiral of death\n\n let running = false\n let lastTime = 0\n let accumulator = 0\n let fps = 0\n let frameCount = 0\n let fpsTime = 0\n let rafId: number | null = null\n\n function loop(currentTime: number) {\n if (!running) return\n\n // Calculate delta in seconds\n const delta = Math.min((currentTime - lastTime) / 1000, maxDelta)\n lastTime = currentTime\n\n // Variable timestep update\n if (onUpdate) {\n onUpdate(delta)\n }\n\n // Fixed timestep update\n if (onFixedUpdate) {\n accumulator += delta\n\n while (accumulator >= fixedDelta) {\n onFixedUpdate(fixedDelta)\n accumulator -= fixedDelta\n }\n }\n\n // Render with interpolation alpha\n if (onRender) {\n const alpha = accumulator / fixedDelta\n onRender(alpha)\n }\n\n // FPS calculation\n frameCount++\n if (currentTime - fpsTime >= 1000) {\n fps = frameCount\n frameCount = 0\n fpsTime = currentTime\n }\n\n rafId = requestAnimationFrame(loop)\n }\n\n return {\n start: () => {\n if (running) return\n running = true\n lastTime = performance.now()\n accumulator = 0\n rafId = requestAnimationFrame(loop)\n },\n\n stop: () => {\n running = false\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n },\n\n isRunning: () => running,\n\n getFps: () => fps\n }\n}\n","// Keyboard types\nexport enum Keys {\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n KeyW = 'KeyW',\n KeyA = 'KeyA',\n KeyS = 'KeyS',\n KeyD = 'KeyD',\n Space = 'Space',\n Enter = 'Enter',\n Escape = 'Escape',\n Tab = 'Tab',\n ShiftLeft = 'ShiftLeft',\n ShiftRight = 'ShiftRight',\n ControlLeft = 'ControlLeft',\n ControlRight = 'ControlRight',\n AltLeft = 'AltLeft',\n AltRight = 'AltRight',\n Digit0 = 'Digit0',\n Digit1 = 'Digit1',\n Digit2 = 'Digit2',\n Digit3 = 'Digit3',\n Digit4 = 'Digit4',\n Digit5 = 'Digit5',\n Digit6 = 'Digit6',\n Digit7 = 'Digit7',\n Digit8 = 'Digit8',\n Digit9 = 'Digit9',\n KeyE = 'KeyE',\n KeyQ = 'KeyQ',\n KeyR = 'KeyR',\n KeyF = 'KeyF',\n}\n\nexport interface KeyboardState {\n isPressed: (key: string) => boolean\n isJustPressed: (key: string) => boolean\n isJustReleased: (key: string) => boolean\n getPressedKeys: () => string[]\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Mouse types\nexport enum MouseButton {\n Left = 0,\n Middle = 1,\n Right = 2\n}\n\nexport interface MouseOptions {\n canvas?: HTMLCanvasElement | (() => HTMLCanvasElement | undefined)\n target?: EventTarget\n}\n\nexport interface MouseState {\n x: number | null\n y: number | null\n deltaX: number\n deltaY: number\n wheelDelta: number\n isPressed: (button: MouseButton) => boolean\n isLeftPressed: () => boolean\n isRightPressed: () => boolean\n isMiddlePressed: () => boolean\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Loop types\nexport interface LoopCallbacks {\n fixedFps?: number\n onUpdate?: (delta: number) => void\n onFixedUpdate?: (fixedDelta: number) => void\n onRender?: (alpha: number) => void\n}\n\nexport interface Loop {\n start: () => void\n stop: () => void\n isRunning: () => boolean\n getFps: () => number\n}\n","import { use } from '../core/use'\nimport { Keys, type KeyboardState } from './types'\n\nexport { Keys, type KeyboardState }\n\nexport function useKeyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justReleased'] })\n\n const handleKeyDown = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n if (!currentPressed.has(key)) {\n const newPressed = new Set(currentPressed)\n newPressed.add(key)\n setPressedKeys(newPressed)\n\n const currentJustPressed = justPressedKeys as Set<string>\n const newJustPressed = new Set(currentJustPressed)\n newJustPressed.add(key)\n setJustPressedKeys(newJustPressed)\n }\n }\n\n const handleKeyUp = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n const newPressed = new Set(currentPressed)\n newPressed.delete(key)\n setPressedKeys(newPressed)\n\n const currentJustReleased = justReleasedKeys as Set<string>\n const newJustReleased = new Set(currentJustReleased)\n newJustReleased.add(key)\n setJustReleasedKeys(newJustReleased)\n }\n\n target.addEventListener('keydown', handleKeyDown)\n target.addEventListener('keyup', handleKeyUp)\n\n return {\n isPressed: (key: string) => {\n const current = pressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustPressed: (key: string) => {\n const current = justPressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustReleased: (key: string) => {\n const current = justReleasedKeys as Set<string>\n return current?.has(key) || false\n },\n\n getPressedKeys: () => {\n const current = pressedKeys as Set<string>\n return Array.from(current || [])\n },\n\n clearFrameState: () => {\n setJustPressedKeys(new Set<string>())\n setJustReleasedKeys(new Set<string>())\n },\n\n dispose: () => {\n target.removeEventListener('keydown', handleKeyDown)\n target.removeEventListener('keyup', handleKeyUp)\n }\n }\n}\n","import { use } from '../core/use'\nimport { MouseButton, type MouseOptions, type MouseState } from './types'\n\nexport { MouseButton, type MouseOptions, type MouseState }\n\nexport function useMouse(options: MouseOptions = {}): MouseState {\n const target = options.target || window\n const canvasGetter = typeof options.canvas === 'function' ? options.canvas : () => options.canvas as HTMLCanvasElement | undefined\n\n const [position, setPosition] = use({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = use({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = use(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = use<Set<number>>(new Set<number>(), { key: ['mouse', 'buttons'] })\n\n let lastX = 0\n let lastY = 0\n\n const handleMouseMove = (e: Event) => {\n const me = e as MouseEvent\n const canvas = canvasGetter()\n\n let x = me.clientX\n let y = me.clientY\n\n // If canvas is provided, calculate position relative to canvas\n if (canvas) {\n const rect = canvas.getBoundingClientRect()\n x = me.clientX - rect.left\n y = me.clientY - rect.top\n }\n\n setPosition({ x, y })\n setDelta({ x: x - lastX, y: y - lastY })\n lastX = x\n lastY = y\n }\n\n const handleMouseDown = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.add(button)\n setButtons(newButtons)\n }\n\n const handleMouseUp = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.delete(button)\n setButtons(newButtons)\n }\n\n const handleWheel = (e: Event) => {\n const we = e as WheelEvent\n setWheelDelta(we.deltaY)\n }\n\n target.addEventListener('mousemove', handleMouseMove)\n target.addEventListener('mousedown', handleMouseDown)\n target.addEventListener('mouseup', handleMouseUp)\n target.addEventListener('wheel', handleWheel)\n\n const currentButtons = buttons as Set<number>\n const currentPosition = position as { x: number; y: number }\n const currentDelta = delta as { x: number; y: number }\n const currentWheelDelta = wheelDelta as number\n\n return {\n get x() { return currentPosition.x },\n get y() { return currentPosition.y },\n get deltaX() { return currentDelta.x },\n get deltaY() { return currentDelta.y },\n get wheelDelta() { return currentWheelDelta },\n\n isPressed: (button: MouseButton) => currentButtons?.has(button) || false,\n\n isLeftPressed: () => currentButtons?.has(MouseButton.Left) || false,\n\n isRightPressed: () => currentButtons?.has(MouseButton.Right) || false,\n\n isMiddlePressed: () => currentButtons?.has(MouseButton.Middle) || false,\n\n clearFrameState: () => {\n setDelta({ x: 0, y: 0 })\n setWheelDelta(0)\n },\n\n dispose: () => {\n target.removeEventListener('mousemove', handleMouseMove)\n target.removeEventListener('mousedown', handleMouseDown)\n target.removeEventListener('mouseup', handleMouseUp)\n target.removeEventListener('wheel', handleWheel)\n }\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- import {c}from'./chunk-INJXOHFD.mjs';import'./chunk-NRPWBHKP.mjs';import'./chunk-5PNH2ARD.mjs';import'./chunk-NDPEE2TQ.mjs';function F(a){let{fixedFps:n=60,onUpdate:v,onFixedUpdate:o,onRender:y}=a,p=1/n,S=.25,l=false,m=0,t=0,s=0,i=0,u=0,r=null;function d(w){if(!l)return;let D=Math.min((w-m)/1e3,S);if(m=w,v&&v(D),o)for(t+=D;t>=p;)o(p),t-=p;if(y){let h=t/p;y(h);}i++,w-u>=1e3&&(s=i,i=0,u=w),r=requestAnimationFrame(d);}return {start:()=>{l||(l=true,m=performance.now(),t=0,r=requestAnimationFrame(d));},stop:()=>{l=false,r!==null&&(cancelAnimationFrame(r),r=null);},isRunning:()=>l,getFps:()=>s}}var x=(e=>(e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.ArrowLeft="ArrowLeft",e.ArrowRight="ArrowRight",e.KeyW="KeyW",e.KeyA="KeyA",e.KeyS="KeyS",e.KeyD="KeyD",e.Space="Space",e.Enter="Enter",e.Escape="Escape",e.Tab="Tab",e.ShiftLeft="ShiftLeft",e.ShiftRight="ShiftRight",e.ControlLeft="ControlLeft",e.ControlRight="ControlRight",e.AltLeft="AltLeft",e.AltRight="AltRight",e.Digit0="Digit0",e.Digit1="Digit1",e.Digit2="Digit2",e.Digit3="Digit3",e.Digit4="Digit4",e.Digit5="Digit5",e.Digit6="Digit6",e.Digit7="Digit7",e.Digit8="Digit8",e.Digit9="Digit9",e.KeyE="KeyE",e.KeyQ="KeyQ",e.KeyR="KeyR",e.KeyF="KeyF",e))(x||{}),k=(o=>(o[o.Left=0]="Left",o[o.Middle=1]="Middle",o[o.Right=2]="Right",o))(k||{});function C(a=window){let[n,v]=c(new Set,{key:["keyboard","pressed"]}),[o,y]=c(new Set,{key:["keyboard","justPressed"]}),[p,S]=c(new Set,{key:["keyboard","justReleased"]}),l=t=>{let s=t.code,i=n;if(!i.has(s)){let u=new Set(i);u.add(s),v(u);let r=o,d=new Set(r);d.add(s),y(d);}},m=t=>{let s=t.code,i=n,u=new Set(i);u.delete(s),v(u);let r=p,d=new Set(r);d.add(s),S(d);};return a.addEventListener("keydown",l),a.addEventListener("keyup",m),{isPressed:t=>n?.has(t)||false,isJustPressed:t=>o?.has(t)||false,isJustReleased:t=>p?.has(t)||false,getPressedKeys:()=>Array.from(n||[]),clearFrameState:()=>{y(new Set),S(new Set);},dispose:()=>{a.removeEventListener("keydown",l),a.removeEventListener("keyup",m);}}}function J(a={}){let n=a.target||window,v=typeof a.canvas=="function"?a.canvas:()=>a.canvas,[o,y]=c({x:0,y:0},{key:["mouse","position"]}),[p,S]=c({x:0,y:0},{key:["mouse","delta"]}),[l,m]=c(0,{key:["mouse","wheel"]}),[t,s]=c(new Set,{key:["mouse","buttons"]}),i=0,u=0,r=g=>{let f=g,L=v(),c=f.clientX,E=f.clientY;if(L){let M=L.getBoundingClientRect();c=f.clientX-M.left,E=f.clientY-M.top;}y({x:c,y:E}),S({x:c-i,y:E-u}),i=c,u=E;},d=g=>{let f=g.button,L=t,c=new Set(L);c.add(f),s(c);},w=g=>{let f=g.button,L=t,c=new Set(L);c.delete(f),s(c);},D=g=>{m(g.deltaY);};n.addEventListener("mousemove",r),n.addEventListener("mousedown",d),n.addEventListener("mouseup",w),n.addEventListener("wheel",D);let h=t,P=o,R=p,A=l;return {get x(){return P.x},get y(){return P.y},get deltaX(){return R.x},get deltaY(){return R.y},get wheelDelta(){return A},isPressed:g=>h?.has(g)||false,isLeftPressed:()=>h?.has(0)||false,isRightPressed:()=>h?.has(2)||false,isMiddlePressed:()=>h?.has(1)||false,clearFrameState:()=>{S({x:0,y:0}),m(0);},dispose:()=>{n.removeEventListener("mousemove",r),n.removeEventListener("mousedown",d),n.removeEventListener("mouseup",w),n.removeEventListener("wheel",D);}}}export{x as Keys,k as MouseButton,C as keyboard,J as mouse,F as useLoop};//# sourceMappingURL=interactive.mjs.map
1
+ import {c}from'./chunk-3AKECLKA.mjs';import'./chunk-NRPWBHKP.mjs';import'./chunk-MI76R42D.mjs';function F(a){let{fixedFps:n=60,onUpdate:v,onFixedUpdate:o,onRender:y}=a,p=1/n,S=.25,l=false,m=0,t=0,s=0,i=0,u=0,r=null;function d(w){if(!l)return;let D=Math.min((w-m)/1e3,S);if(m=w,v&&v(D),o)for(t+=D;t>=p;)o(p),t-=p;if(y){let h=t/p;y(h);}i++,w-u>=1e3&&(s=i,i=0,u=w),r=requestAnimationFrame(d);}return {start:()=>{l||(l=true,m=performance.now(),t=0,r=requestAnimationFrame(d));},stop:()=>{l=false,r!==null&&(cancelAnimationFrame(r),r=null);},isRunning:()=>l,getFps:()=>s}}var x=(e=>(e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.ArrowLeft="ArrowLeft",e.ArrowRight="ArrowRight",e.KeyW="KeyW",e.KeyA="KeyA",e.KeyS="KeyS",e.KeyD="KeyD",e.Space="Space",e.Enter="Enter",e.Escape="Escape",e.Tab="Tab",e.ShiftLeft="ShiftLeft",e.ShiftRight="ShiftRight",e.ControlLeft="ControlLeft",e.ControlRight="ControlRight",e.AltLeft="AltLeft",e.AltRight="AltRight",e.Digit0="Digit0",e.Digit1="Digit1",e.Digit2="Digit2",e.Digit3="Digit3",e.Digit4="Digit4",e.Digit5="Digit5",e.Digit6="Digit6",e.Digit7="Digit7",e.Digit8="Digit8",e.Digit9="Digit9",e.KeyE="KeyE",e.KeyQ="KeyQ",e.KeyR="KeyR",e.KeyF="KeyF",e))(x||{}),P=(o=>(o[o.Left=0]="Left",o[o.Middle=1]="Middle",o[o.Right=2]="Right",o))(P||{});function C(a=window){let[n,v]=c(new Set,{key:["keyboard","pressed"]}),[o,y]=c(new Set,{key:["keyboard","justPressed"]}),[p,S]=c(new Set,{key:["keyboard","justReleased"]}),l=t=>{let s=t.code,i=n;if(!i.has(s)){let u=new Set(i);u.add(s),v(u);let r=o,d=new Set(r);d.add(s),y(d);}},m=t=>{let s=t.code,i=n,u=new Set(i);u.delete(s),v(u);let r=p,d=new Set(r);d.add(s),S(d);};return a.addEventListener("keydown",l),a.addEventListener("keyup",m),{isPressed:t=>n?.has(t)||false,isJustPressed:t=>o?.has(t)||false,isJustReleased:t=>p?.has(t)||false,getPressedKeys:()=>Array.from(n||[]),clearFrameState:()=>{y(new Set),S(new Set);},dispose:()=>{a.removeEventListener("keydown",l),a.removeEventListener("keyup",m);}}}function J(a={}){let n=a.target||window,v=typeof a.canvas=="function"?a.canvas:()=>a.canvas,[o,y]=c({x:0,y:0},{key:["mouse","position"]}),[p,S]=c({x:0,y:0},{key:["mouse","delta"]}),[l,m]=c(0,{key:["mouse","wheel"]}),[t,s]=c(new Set,{key:["mouse","buttons"]}),i=0,u=0,r=g=>{let f=g,L=v(),c=f.clientX,E=f.clientY;if(L){let k=L.getBoundingClientRect();c=f.clientX-k.left,E=f.clientY-k.top;}y({x:c,y:E}),S({x:c-i,y:E-u}),i=c,u=E;},d=g=>{let f=g.button,L=t,c=new Set(L);c.add(f),s(c);},w=g=>{let f=g.button,L=t,c=new Set(L);c.delete(f),s(c);},D=g=>{m(g.deltaY);};n.addEventListener("mousemove",r),n.addEventListener("mousedown",d),n.addEventListener("mouseup",w),n.addEventListener("wheel",D);let h=t,R=o,M=p,A=l;return {get x(){return R.x},get y(){return R.y},get deltaX(){return M.x},get deltaY(){return M.y},get wheelDelta(){return A},isPressed:g=>h?.has(g)||false,isLeftPressed:()=>h?.has(0)||false,isRightPressed:()=>h?.has(2)||false,isMiddlePressed:()=>h?.has(1)||false,clearFrameState:()=>{S({x:0,y:0}),m(0);},dispose:()=>{n.removeEventListener("mousemove",r),n.removeEventListener("mousedown",d),n.removeEventListener("mouseup",w),n.removeEventListener("wheel",D);}}}export{x as Keys,P as MouseButton,C as useKeyboard,F as useLoop,J as useMouse};//# sourceMappingURL=interactive.mjs.map
2
2
  //# sourceMappingURL=interactive.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interactive/loop.ts","../src/interactive/types.ts","../src/interactive/keyboard.ts","../src/interactive/mouse.ts"],"names":["useLoop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","loop","currentTime","delta","alpha","Keys","MouseButton","keyboard","target","pressedKeys","setPressedKeys","use","justPressedKeys","setJustPressedKeys","justReleasedKeys","setJustReleasedKeys","handleKeyDown","e","key","currentPressed","newPressed","currentJustPressed","newJustPressed","handleKeyUp","currentJustReleased","newJustReleased","mouse","options","canvasGetter","position","setPosition","setDelta","wheelDelta","setWheelDelta","buttons","setButtons","lastX","lastY","handleMouseMove","me","canvas","x","y","rect","handleMouseDown","button","currentButtons","newButtons","handleMouseUp","handleWheel","currentPosition","currentDelta","currentWheelDelta"],"mappings":"4HAIO,SAASA,CAAAA,CAAQC,EAAgC,CACtD,GAAM,CAAE,QAAA,CAAAC,CAAAA,CAAW,GAAI,QAAA,CAAAC,CAAAA,CAAU,cAAAC,CAAAA,CAAe,QAAA,CAAAC,CAAS,CAAA,CAAIJ,CAAAA,CAEvDK,EAAa,CAAA,CAAIJ,CAAAA,CACjBK,EAAW,GAAA,CAEbC,CAAAA,CAAU,MACVC,CAAAA,CAAW,CAAA,CACXC,EAAc,CAAA,CACdC,CAAAA,CAAM,EACNC,CAAAA,CAAa,CAAA,CACbC,EAAU,CAAA,CACVC,CAAAA,CAAuB,KAE3B,SAASC,CAAAA,CAAKC,EAAqB,CACjC,GAAI,CAACR,CAAAA,CAAS,OAGd,IAAMS,CAAAA,CAAQ,IAAA,CAAK,GAAA,CAAA,CAAKD,EAAcP,CAAAA,EAAY,GAAA,CAAMF,CAAQ,CAAA,CAShE,GARAE,EAAWO,CAAAA,CAGPb,CAAAA,EACFA,EAASc,CAAK,CAAA,CAIZb,EAGF,IAFAM,CAAAA,EAAeO,EAERP,CAAAA,EAAeJ,CAAAA,EACpBF,EAAcE,CAAU,CAAA,CACxBI,GAAeJ,CAAAA,CAKnB,GAAID,EAAU,CACZ,IAAMa,EAAQR,CAAAA,CAAcJ,CAAAA,CAC5BD,EAASa,CAAK,EAChB,CAGAN,CAAAA,EAAAA,CACII,CAAA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nC,IAAI,CAAA,EAAI,CAAE,OAAOA,CAAAA,CAAgB,CAAE,EACnC,IAAI,MAAA,EAAS,CAAE,OAAOC,CAAAA,CAAa,CAAE,CAAA,CACrC,IAAI,QAAS,CAAE,OAAOA,EAAa,CAAE,CAAA,CACrC,IAAI,UAAA,EAAa,CAAE,OAAOC,CAAkB,CAAA,CAE5C,UAAYP,CAAAA,EAAwBC,CAAAA,EAAgB,IAAID,CAAM,CAAA,EAAK,MAEnE,aAAA,CAAe,IAAMC,GAAgB,GAAA,CAAA,CAAoB,CAAA,EAAK,KAAA,CAE9D,cAAA,CAAgB,IAAMA,CAAAA,EAAgB,KAAqB,CAAA,EAAK,KAAA,CAEhE,gBAAiB,IAAMA,CAAAA,EAAgB,KAAsB,CAAA,EAAK,KAAA,CAElE,gBAAiB,IAAM,CACrBf,EAAS,CAAE,CAAA,CAAG,EAAG,CAAA,CAAG,CAAE,CAAC,CAAA,CACvBE,CAAAA,CAAc,CAAC,EACjB,CAAA,CAEA,OAAA,CAAS,IAAM,CACbzB,CAAAA,CAAO,oBAAoB,WAAA,CAAa8B,CAAe,EACvD9B,CAAAA,CAAO,mBAAA,CAAoB,YAAaoC,CAAe,CAAA,CACvDpC,EAAO,mBAAA,CAAoB,SAAA,CAAWwC,CAAa,CAAA,CACnDxC,CAAAA,CAAO,oBAAoB,OAAA,CAASyC,CAAW,EACjD,CACF,CACF","file":"interactive.mjs","sourcesContent":["import type { LoopCallbacks, Loop } from './types'\n\nexport type { LoopCallbacks, Loop }\n\nexport function useLoop(callbacks: LoopCallbacks): Loop {\n const { fixedFps = 60, onUpdate, onFixedUpdate, onRender } = callbacks\n\n const fixedDelta = 1 / fixedFps\n const maxDelta = 0.25 // Cap delta at 250ms to prevent spiral of death\n\n let running = false\n let lastTime = 0\n let accumulator = 0\n let fps = 0\n let frameCount = 0\n let fpsTime = 0\n let rafId: number | null = null\n\n function loop(currentTime: number) {\n if (!running) return\n\n // Calculate delta in seconds\n const delta = Math.min((currentTime - lastTime) / 1000, maxDelta)\n lastTime = currentTime\n\n // Variable timestep update\n if (onUpdate) {\n onUpdate(delta)\n }\n\n // Fixed timestep update\n if (onFixedUpdate) {\n accumulator += delta\n\n while (accumulator >= fixedDelta) {\n onFixedUpdate(fixedDelta)\n accumulator -= fixedDelta\n }\n }\n\n // Render with interpolation alpha\n if (onRender) {\n const alpha = accumulator / fixedDelta\n onRender(alpha)\n }\n\n // FPS calculation\n frameCount++\n if (currentTime - fpsTime >= 1000) {\n fps = frameCount\n frameCount = 0\n fpsTime = currentTime\n }\n\n rafId = requestAnimationFrame(loop)\n }\n\n return {\n start: () => {\n if (running) return\n running = true\n lastTime = performance.now()\n accumulator = 0\n rafId = requestAnimationFrame(loop)\n },\n\n stop: () => {\n running = false\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n },\n\n isRunning: () => running,\n\n getFps: () => fps\n }\n}\n","// Keyboard types\nexport enum Keys {\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n KeyW = 'KeyW',\n KeyA = 'KeyA',\n KeyS = 'KeyS',\n KeyD = 'KeyD',\n Space = 'Space',\n Enter = 'Enter',\n Escape = 'Escape',\n Tab = 'Tab',\n ShiftLeft = 'ShiftLeft',\n ShiftRight = 'ShiftRight',\n ControlLeft = 'ControlLeft',\n ControlRight = 'ControlRight',\n AltLeft = 'AltLeft',\n AltRight = 'AltRight',\n Digit0 = 'Digit0',\n Digit1 = 'Digit1',\n Digit2 = 'Digit2',\n Digit3 = 'Digit3',\n Digit4 = 'Digit4',\n Digit5 = 'Digit5',\n Digit6 = 'Digit6',\n Digit7 = 'Digit7',\n Digit8 = 'Digit8',\n Digit9 = 'Digit9',\n KeyE = 'KeyE',\n KeyQ = 'KeyQ',\n KeyR = 'KeyR',\n KeyF = 'KeyF',\n}\n\nexport interface KeyboardState {\n isPressed: (key: string) => boolean\n isJustPressed: (key: string) => boolean\n isJustReleased: (key: string) => boolean\n getPressedKeys: () => string[]\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Mouse types\nexport enum MouseButton {\n Left = 0,\n Middle = 1,\n Right = 2\n}\n\nexport interface MouseOptions {\n canvas?: HTMLCanvasElement | (() => HTMLCanvasElement | undefined)\n target?: EventTarget\n}\n\nexport interface MouseState {\n x: number | null\n y: number | null\n deltaX: number\n deltaY: number\n wheelDelta: number\n isPressed: (button: MouseButton) => boolean\n isLeftPressed: () => boolean\n isRightPressed: () => boolean\n isMiddlePressed: () => boolean\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Loop types\nexport interface LoopCallbacks {\n fixedFps?: number\n onUpdate?: (delta: number) => void\n onFixedUpdate?: (fixedDelta: number) => void\n onRender?: (alpha: number) => void\n}\n\nexport interface Loop {\n start: () => void\n stop: () => void\n isRunning: () => boolean\n getFps: () => number\n}\n","import { use } from '../core/use'\nimport { Keys, type KeyboardState } from './types'\n\nexport { Keys, type KeyboardState }\n\nexport function keyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justReleased'] })\n\n const handleKeyDown = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n if (!currentPressed.has(key)) {\n const newPressed = new Set(currentPressed)\n newPressed.add(key)\n setPressedKeys(newPressed)\n\n const currentJustPressed = justPressedKeys as Set<string>\n const newJustPressed = new Set(currentJustPressed)\n newJustPressed.add(key)\n setJustPressedKeys(newJustPressed)\n }\n }\n\n const handleKeyUp = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n const newPressed = new Set(currentPressed)\n newPressed.delete(key)\n setPressedKeys(newPressed)\n\n const currentJustReleased = justReleasedKeys as Set<string>\n const newJustReleased = new Set(currentJustReleased)\n newJustReleased.add(key)\n setJustReleasedKeys(newJustReleased)\n }\n\n target.addEventListener('keydown', handleKeyDown)\n target.addEventListener('keyup', handleKeyUp)\n\n return {\n isPressed: (key: string) => {\n const current = pressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustPressed: (key: string) => {\n const current = justPressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustReleased: (key: string) => {\n const current = justReleasedKeys as Set<string>\n return current?.has(key) || false\n },\n\n getPressedKeys: () => {\n const current = pressedKeys as Set<string>\n return Array.from(current || [])\n },\n\n clearFrameState: () => {\n setJustPressedKeys(new Set<string>())\n setJustReleasedKeys(new Set<string>())\n },\n\n dispose: () => {\n target.removeEventListener('keydown', handleKeyDown)\n target.removeEventListener('keyup', handleKeyUp)\n }\n }\n}\n","import { use } from '../core/use'\nimport { MouseButton, type MouseOptions, type MouseState } from './types'\n\nexport { MouseButton, type MouseOptions, type MouseState }\n\nexport function mouse(options: MouseOptions = {}): MouseState {\n const target = options.target || window\n const canvasGetter = typeof options.canvas === 'function' ? options.canvas : () => options.canvas as HTMLCanvasElement | undefined\n\n const [position, setPosition] = use({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = use({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = use(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = use<Set<number>>(new Set<number>(), { key: ['mouse', 'buttons'] })\n\n let lastX = 0\n let lastY = 0\n\n const handleMouseMove = (e: Event) => {\n const me = e as MouseEvent\n const canvas = canvasGetter()\n\n let x = me.clientX\n let y = me.clientY\n\n // If canvas is provided, calculate position relative to canvas\n if (canvas) {\n const rect = canvas.getBoundingClientRect()\n x = me.clientX - rect.left\n y = me.clientY - rect.top\n }\n\n setPosition({ x, y })\n setDelta({ x: x - lastX, y: y - lastY })\n lastX = x\n lastY = y\n }\n\n const handleMouseDown = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.add(button)\n setButtons(newButtons)\n }\n\n const handleMouseUp = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.delete(button)\n setButtons(newButtons)\n }\n\n const handleWheel = (e: Event) => {\n const we = e as WheelEvent\n setWheelDelta(we.deltaY)\n }\n\n target.addEventListener('mousemove', handleMouseMove)\n target.addEventListener('mousedown', handleMouseDown)\n target.addEventListener('mouseup', handleMouseUp)\n target.addEventListener('wheel', handleWheel)\n\n const currentButtons = buttons as Set<number>\n const currentPosition = position as { x: number; y: number }\n const currentDelta = delta as { x: number; y: number }\n const currentWheelDelta = wheelDelta as number\n\n return {\n get x() { return currentPosition.x },\n get y() { return currentPosition.y },\n get deltaX() { return currentDelta.x },\n get deltaY() { return currentDelta.y },\n get wheelDelta() { return currentWheelDelta },\n\n isPressed: (button: MouseButton) => currentButtons?.has(button) || false,\n\n isLeftPressed: () => currentButtons?.has(MouseButton.Left) || false,\n\n isRightPressed: () => currentButtons?.has(MouseButton.Right) || false,\n\n isMiddlePressed: () => currentButtons?.has(MouseButton.Middle) || false,\n\n clearFrameState: () => {\n setDelta({ x: 0, y: 0 })\n setWheelDelta(0)\n },\n\n dispose: () => {\n target.removeEventListener('mousemove', handleMouseMove)\n target.removeEventListener('mousedown', handleMouseDown)\n target.removeEventListener('mouseup', handleMouseUp)\n target.removeEventListener('wheel', handleWheel)\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/interactive/loop.ts","../src/interactive/types.ts","../src/interactive/keyboard.ts","../src/interactive/mouse.ts"],"names":["useLoop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","loop","currentTime","delta","alpha","Keys","MouseButton","useKeyboard","target","pressedKeys","setPressedKeys","use","justPressedKeys","setJustPressedKeys","justReleasedKeys","setJustReleasedKeys","handleKeyDown","e","key","currentPressed","newPressed","currentJustPressed","newJustPressed","handleKeyUp","currentJustReleased","newJustReleased","useMouse","options","canvasGetter","position","setPosition","setDelta","wheelDelta","setWheelDelta","buttons","setButtons","lastX","lastY","handleMouseMove","me","canvas","x","y","rect","handleMouseDown","button","currentButtons","newButtons","handleMouseUp","handleWheel","currentPosition","currentDelta","currentWheelDelta"],"mappings":"+FAIO,SAASA,CAAAA,CAAQC,EAAgC,CACtD,GAAM,CAAE,QAAA,CAAAC,CAAAA,CAAW,GAAI,QAAA,CAAAC,CAAAA,CAAU,cAAAC,CAAAA,CAAe,QAAA,CAAAC,CAAS,CAAA,CAAIJ,CAAAA,CAEvDK,EAAa,CAAA,CAAIJ,CAAAA,CACjBK,EAAW,GAAA,CAEbC,CAAAA,CAAU,MACVC,CAAAA,CAAW,CAAA,CACXC,EAAc,CAAA,CACdC,CAAAA,CAAM,EACNC,CAAAA,CAAa,CAAA,CACbC,EAAU,CAAA,CACVC,CAAAA,CAAuB,KAE3B,SAASC,CAAAA,CAAKC,EAAqB,CACjC,GAAI,CAACR,CAAAA,CAAS,OAGd,IAAMS,CAAAA,CAAQ,IAAA,CAAK,GAAA,CAAA,CAAKD,EAAcP,CAAAA,EAAY,GAAA,CAAMF,CAAQ,CAAA,CAShE,GARAE,EAAWO,CAAAA,CAGPb,CAAAA,EACFA,EAASc,CAAK,CAAA,CAIZb,EAGF,IAFAM,CAAAA,EAAeO,EAERP,CAAAA,EAAeJ,CAAAA,EACpBF,EAAcE,CAAU,CAAA,CACxBI,GAAeJ,CAAAA,CAKnB,GAAID,EAAU,CACZ,IAAMa,EAAQR,CAAAA,CAAcJ,CAAAA,CAC5BD,EAASa,CAAK,EAChB,CAGAN,CAAAA,EAAAA,CACII,CAAAA,CAAcH,GAAW,GAAA,GAC3BF,CAAAA,CAAMC,EACNA,CAAAA,CAAa,CAAA,CACbC,EAAUG,CAAAA,C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,CAAAA,CAAa,CAAE,CAAA,CACrC,IAAI,QAAS,CAAE,OAAOA,EAAa,CAAE,CAAA,CACrC,IAAI,UAAA,EAAa,CAAE,OAAOC,CAAkB,CAAA,CAE5C,UAAYP,CAAAA,EAAwBC,CAAAA,EAAgB,IAAID,CAAM,CAAA,EAAK,MAEnE,aAAA,CAAe,IAAMC,GAAgB,GAAA,CAAA,CAAoB,CAAA,EAAK,KAAA,CAE9D,cAAA,CAAgB,IAAMA,CAAAA,EAAgB,KAAqB,CAAA,EAAK,KAAA,CAEhE,gBAAiB,IAAMA,CAAAA,EAAgB,KAAsB,CAAA,EAAK,KAAA,CAElE,gBAAiB,IAAM,CACrBf,EAAS,CAAE,CAAA,CAAG,EAAG,CAAA,CAAG,CAAE,CAAC,CAAA,CACvBE,CAAAA,CAAc,CAAC,EACjB,CAAA,CAEA,OAAA,CAAS,IAAM,CACbzB,CAAAA,CAAO,oBAAoB,WAAA,CAAa8B,CAAe,EACvD9B,CAAAA,CAAO,mBAAA,CAAoB,YAAaoC,CAAe,CAAA,CACvDpC,EAAO,mBAAA,CAAoB,SAAA,CAAWwC,CAAa,CAAA,CACnDxC,CAAAA,CAAO,oBAAoB,OAAA,CAASyC,CAAW,EACjD,CACF,CACF","file":"interactive.mjs","sourcesContent":["import type { LoopCallbacks, Loop } from './types'\n\nexport type { LoopCallbacks, Loop }\n\nexport function useLoop(callbacks: LoopCallbacks): Loop {\n const { fixedFps = 60, onUpdate, onFixedUpdate, onRender } = callbacks\n\n const fixedDelta = 1 / fixedFps\n const maxDelta = 0.25 // Cap delta at 250ms to prevent spiral of death\n\n let running = false\n let lastTime = 0\n let accumulator = 0\n let fps = 0\n let frameCount = 0\n let fpsTime = 0\n let rafId: number | null = null\n\n function loop(currentTime: number) {\n if (!running) return\n\n // Calculate delta in seconds\n const delta = Math.min((currentTime - lastTime) / 1000, maxDelta)\n lastTime = currentTime\n\n // Variable timestep update\n if (onUpdate) {\n onUpdate(delta)\n }\n\n // Fixed timestep update\n if (onFixedUpdate) {\n accumulator += delta\n\n while (accumulator >= fixedDelta) {\n onFixedUpdate(fixedDelta)\n accumulator -= fixedDelta\n }\n }\n\n // Render with interpolation alpha\n if (onRender) {\n const alpha = accumulator / fixedDelta\n onRender(alpha)\n }\n\n // FPS calculation\n frameCount++\n if (currentTime - fpsTime >= 1000) {\n fps = frameCount\n frameCount = 0\n fpsTime = currentTime\n }\n\n rafId = requestAnimationFrame(loop)\n }\n\n return {\n start: () => {\n if (running) return\n running = true\n lastTime = performance.now()\n accumulator = 0\n rafId = requestAnimationFrame(loop)\n },\n\n stop: () => {\n running = false\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n },\n\n isRunning: () => running,\n\n getFps: () => fps\n }\n}\n","// Keyboard types\nexport enum Keys {\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n KeyW = 'KeyW',\n KeyA = 'KeyA',\n KeyS = 'KeyS',\n KeyD = 'KeyD',\n Space = 'Space',\n Enter = 'Enter',\n Escape = 'Escape',\n Tab = 'Tab',\n ShiftLeft = 'ShiftLeft',\n ShiftRight = 'ShiftRight',\n ControlLeft = 'ControlLeft',\n ControlRight = 'ControlRight',\n AltLeft = 'AltLeft',\n AltRight = 'AltRight',\n Digit0 = 'Digit0',\n Digit1 = 'Digit1',\n Digit2 = 'Digit2',\n Digit3 = 'Digit3',\n Digit4 = 'Digit4',\n Digit5 = 'Digit5',\n Digit6 = 'Digit6',\n Digit7 = 'Digit7',\n Digit8 = 'Digit8',\n Digit9 = 'Digit9',\n KeyE = 'KeyE',\n KeyQ = 'KeyQ',\n KeyR = 'KeyR',\n KeyF = 'KeyF',\n}\n\nexport interface KeyboardState {\n isPressed: (key: string) => boolean\n isJustPressed: (key: string) => boolean\n isJustReleased: (key: string) => boolean\n getPressedKeys: () => string[]\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Mouse types\nexport enum MouseButton {\n Left = 0,\n Middle = 1,\n Right = 2\n}\n\nexport interface MouseOptions {\n canvas?: HTMLCanvasElement | (() => HTMLCanvasElement | undefined)\n target?: EventTarget\n}\n\nexport interface MouseState {\n x: number | null\n y: number | null\n deltaX: number\n deltaY: number\n wheelDelta: number\n isPressed: (button: MouseButton) => boolean\n isLeftPressed: () => boolean\n isRightPressed: () => boolean\n isMiddlePressed: () => boolean\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Loop types\nexport interface LoopCallbacks {\n fixedFps?: number\n onUpdate?: (delta: number) => void\n onFixedUpdate?: (fixedDelta: number) => void\n onRender?: (alpha: number) => void\n}\n\nexport interface Loop {\n start: () => void\n stop: () => void\n isRunning: () => boolean\n getFps: () => number\n}\n","import { use } from '../core/use'\nimport { Keys, type KeyboardState } from './types'\n\nexport { Keys, type KeyboardState }\n\nexport function useKeyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justReleased'] })\n\n const handleKeyDown = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n if (!currentPressed.has(key)) {\n const newPressed = new Set(currentPressed)\n newPressed.add(key)\n setPressedKeys(newPressed)\n\n const currentJustPressed = justPressedKeys as Set<string>\n const newJustPressed = new Set(currentJustPressed)\n newJustPressed.add(key)\n setJustPressedKeys(newJustPressed)\n }\n }\n\n const handleKeyUp = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n const newPressed = new Set(currentPressed)\n newPressed.delete(key)\n setPressedKeys(newPressed)\n\n const currentJustReleased = justReleasedKeys as Set<string>\n const newJustReleased = new Set(currentJustReleased)\n newJustReleased.add(key)\n setJustReleasedKeys(newJustReleased)\n }\n\n target.addEventListener('keydown', handleKeyDown)\n target.addEventListener('keyup', handleKeyUp)\n\n return {\n isPressed: (key: string) => {\n const current = pressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustPressed: (key: string) => {\n const current = justPressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustReleased: (key: string) => {\n const current = justReleasedKeys as Set<string>\n return current?.has(key) || false\n },\n\n getPressedKeys: () => {\n const current = pressedKeys as Set<string>\n return Array.from(current || [])\n },\n\n clearFrameState: () => {\n setJustPressedKeys(new Set<string>())\n setJustReleasedKeys(new Set<string>())\n },\n\n dispose: () => {\n target.removeEventListener('keydown', handleKeyDown)\n target.removeEventListener('keyup', handleKeyUp)\n }\n }\n}\n","import { use } from '../core/use'\nimport { MouseButton, type MouseOptions, type MouseState } from './types'\n\nexport { MouseButton, type MouseOptions, type MouseState }\n\nexport function useMouse(options: MouseOptions = {}): MouseState {\n const target = options.target || window\n const canvasGetter = typeof options.canvas === 'function' ? options.canvas : () => options.canvas as HTMLCanvasElement | undefined\n\n const [position, setPosition] = use({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = use({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = use(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = use<Set<number>>(new Set<number>(), { key: ['mouse', 'buttons'] })\n\n let lastX = 0\n let lastY = 0\n\n const handleMouseMove = (e: Event) => {\n const me = e as MouseEvent\n const canvas = canvasGetter()\n\n let x = me.clientX\n let y = me.clientY\n\n // If canvas is provided, calculate position relative to canvas\n if (canvas) {\n const rect = canvas.getBoundingClientRect()\n x = me.clientX - rect.left\n y = me.clientY - rect.top\n }\n\n setPosition({ x, y })\n setDelta({ x: x - lastX, y: y - lastY })\n lastX = x\n lastY = y\n }\n\n const handleMouseDown = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.add(button)\n setButtons(newButtons)\n }\n\n const handleMouseUp = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.delete(button)\n setButtons(newButtons)\n }\n\n const handleWheel = (e: Event) => {\n const we = e as WheelEvent\n setWheelDelta(we.deltaY)\n }\n\n target.addEventListener('mousemove', handleMouseMove)\n target.addEventListener('mousedown', handleMouseDown)\n target.addEventListener('mouseup', handleMouseUp)\n target.addEventListener('wheel', handleWheel)\n\n const currentButtons = buttons as Set<number>\n const currentPosition = position as { x: number; y: number }\n const currentDelta = delta as { x: number; y: number }\n const currentWheelDelta = wheelDelta as number\n\n return {\n get x() { return currentPosition.x },\n get y() { return currentPosition.y },\n get deltaX() { return currentDelta.x },\n get deltaY() { return currentDelta.y },\n get wheelDelta() { return currentWheelDelta },\n\n isPressed: (button: MouseButton) => currentButtons?.has(button) || false,\n\n isLeftPressed: () => currentButtons?.has(MouseButton.Left) || false,\n\n isRightPressed: () => currentButtons?.has(MouseButton.Right) || false,\n\n isMiddlePressed: () => currentButtons?.has(MouseButton.Middle) || false,\n\n clearFrameState: () => {\n setDelta({ x: 0, y: 0 })\n setWheelDelta(0)\n },\n\n dispose: () => {\n target.removeEventListener('mousemove', handleMouseMove)\n target.removeEventListener('mousedown', handleMouseDown)\n target.removeEventListener('mouseup', handleMouseUp)\n target.removeEventListener('wheel', handleWheel)\n }\n }\n}\n"]}