flexium 0.12.11 → 0.12.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas.d.cts +14 -13
- package/dist/canvas.d.ts +14 -13
- package/dist/canvas.js +1 -1
- package/dist/canvas.js.map +1 -1
- package/dist/canvas.mjs +1 -1
- package/dist/canvas.mjs.map +1 -1
- package/dist/chunk-3DKZ2J4D.mjs +2 -0
- package/dist/chunk-3DKZ2J4D.mjs.map +1 -0
- package/dist/chunk-5PNH2ARD.mjs +2 -0
- package/dist/chunk-5PNH2ARD.mjs.map +1 -0
- package/dist/{chunk-7BXR4ZFD.js → chunk-6VIRXD2Y.js} +2 -2
- package/dist/chunk-6VIRXD2Y.js.map +1 -0
- package/dist/chunk-6Z33DLMI.js +2 -0
- package/dist/chunk-6Z33DLMI.js.map +1 -0
- package/dist/chunk-E75BJDOQ.mjs +2 -0
- package/dist/chunk-E75BJDOQ.mjs.map +1 -0
- package/dist/chunk-IWFEXW4F.mjs +2 -0
- package/dist/chunk-IWFEXW4F.mjs.map +1 -0
- package/dist/chunk-JY6CE6RN.mjs +2 -0
- package/dist/chunk-JY6CE6RN.mjs.map +1 -0
- package/dist/chunk-LTT43APF.js +2 -0
- package/dist/chunk-LTT43APF.js.map +1 -0
- package/dist/chunk-PSKDIB7J.js +2 -0
- package/dist/chunk-PSKDIB7J.js.map +1 -0
- package/dist/chunk-UWFVCKRU.js +2 -0
- package/dist/chunk-UWFVCKRU.js.map +1 -0
- package/dist/chunk-WGKD63GN.mjs +2 -0
- package/dist/chunk-WGKD63GN.mjs.map +1 -0
- package/dist/chunk-YWTD32NA.js +2 -0
- package/dist/chunk-YWTD32NA.js.map +1 -0
- package/dist/core.d.cts +91 -15
- package/dist/core.d.ts +91 -15
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/dom.d.cts +154 -9
- package/dist/dom.d.ts +154 -9
- package/dist/dom.js +1 -1
- package/dist/dom.js.map +1 -1
- package/dist/dom.mjs +1 -1
- package/dist/dom.mjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/interactive.d.cts +17 -16
- package/dist/interactive.d.ts +17 -16
- package/dist/interactive.js +1 -1
- package/dist/interactive.js.map +1 -1
- package/dist/interactive.mjs +1 -1
- package/dist/interactive.mjs.map +1 -1
- package/dist/jsx-dev-runtime.d.cts +1 -1
- package/dist/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-runtime.d.cts +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/render-QZAFAGIM.js +2 -0
- package/dist/render-QZAFAGIM.js.map +1 -0
- package/dist/render-UIWHIMS2.mjs +2 -0
- package/dist/render-UIWHIMS2.mjs.map +1 -0
- package/dist/router.d.cts +1 -1
- package/dist/router.d.ts +1 -1
- package/dist/router.js +1 -1
- package/dist/router.js.map +1 -1
- package/dist/router.mjs +1 -1
- package/dist/router.mjs.map +1 -1
- package/dist/server.d.cts +17 -0
- package/dist/server.d.ts +17 -0
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +2 -0
- package/dist/server.mjs.map +1 -0
- package/dist/types-CxlS2F2j.d.cts +19 -0
- package/dist/types-CxlS2F2j.d.ts +19 -0
- package/dist/types-y2GGaXXk.d.cts +9 -0
- package/dist/types-y2GGaXXk.d.ts +9 -0
- package/package.json +6 -1
- package/dist/chunk-44RZHCII.mjs +0 -2
- package/dist/chunk-44RZHCII.mjs.map +0 -1
- package/dist/chunk-7BXR4ZFD.js.map +0 -1
- package/dist/chunk-APAMPY43.js +0 -2
- package/dist/chunk-APAMPY43.js.map +0 -1
- package/dist/chunk-CPJRQL2C.mjs +0 -2
- package/dist/chunk-CPJRQL2C.mjs.map +0 -1
- package/dist/chunk-ECB5HZOQ.mjs +0 -2
- package/dist/chunk-ECB5HZOQ.mjs.map +0 -1
- package/dist/chunk-ENWGYQNU.js +0 -2
- package/dist/chunk-ENWGYQNU.js.map +0 -1
- package/dist/chunk-IA4FEBFE.js +0 -2
- package/dist/chunk-IA4FEBFE.js.map +0 -1
- package/dist/chunk-LUREDEUB.mjs +0 -2
- package/dist/chunk-LUREDEUB.mjs.map +0 -1
- package/dist/chunk-LUW7DIEW.js +0 -2
- package/dist/chunk-LUW7DIEW.js.map +0 -1
- package/dist/chunk-S6WF3XNF.mjs +0 -2
- package/dist/chunk-S6WF3XNF.mjs.map +0 -1
package/dist/dom.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dom/index.ts"],"names":["instanceRegistry","currentRenderingInstance","removeComponentInstance","instance","child","node","renderComponent","fnode","parent","registryParent","effectiveRegistryParent","mergeProps","props","hasExplicitKey","parentRegistry","key","instanceCount","componentName","_","k","newProps","isFirstRender","renderFn","currentVnode","currentProps","pushContext","previousRenderingInstance","result","runWithComponent","newNodes","renderNode","nodeParent","marker","lastNode","tempContainer","newNodesArray","reconciledNodes","reconcile","unsafeEffect","oldKeysSet","nodes","newKeysSet","keysToRemove","dom","value","eventName","setAttribute","render","app","container","f","type","children","el","canReuse","oldNode","newNode","updateAttributes","oldEl","newEl","attr","oldHandlers","newHandlers","event","reconcileChildren","oldChildren","newChildren","maxLen","i","oldChild","newChild","patchNode","ownerInstance","idx","oldNodes","beforeMarker","resultNodes"],"mappings":"4EA4BA,IAAMA,CAAAA,CAAmB,IAAI,OAAA,CAGzBC,CAAAA,CAAwD,KAG5D,SAASC,CAAAA,CAAwBC,CAAAA,CAAsC,CAEnEA,EAAS,QAAA,CAAS,OAAA,CAAQC,CAAAA,EAAS,CAC/BF,EAAwBE,CAAK,EACjC,CAAC,CAAA,CAGDD,EAAS,KAAA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D,CAAAA,CAASD,CAAO,EAE5C,CAGO,SAASlB,CAAAA,CAAUqC,CAAAA,CAAkB7C,EAAkBrB,CAAAA,CAAcmE,CAAAA,CAA4B,CACpG,IAAMR,EAAS,IAAA,CAAK,GAAA,CAAIO,CAAAA,CAAS,MAAA,CAAQ7C,EAAS,MAAM,CAAA,CAClD+C,CAAAA,CAAsB,GAE5B,IAAA,IAASR,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAID,EAAQC,CAAAA,EAAAA,CAAK,CAC7B,IAAMb,CAAAA,CAAUmB,EAASN,CAAC,CAAA,CACpBZ,CAAAA,CAAU3B,CAAAA,CAASuC,CAAC,CAAA,CAEtB,CAACb,CAAAA,EAAWC,CAAAA,EAEZhD,EAAO,YAAA,CAAagD,CAAAA,CAASmB,CAAY,CAAA,CACzCC,EAAY,IAAA,CAAKpB,CAAO,CAAA,EACjBD,CAAAA,EAAW,CAACC,CAAAA,CAEfD,CAAAA,CAAQ,UAAA,EACR/C,CAAAA,CAAO,YAAY+C,CAAO,CAAA,CAEvBA,CAAAA,EAAWC,CAAAA,GAElBe,EAAUhB,CAAAA,CAASC,CAAAA,CAAShD,CAAiB,CAAA,CAC7CoE,EAAY,IAAA,CAAKrB,CAAO,CAAA,EAEhC,CAEA,OAAOqB,CACX","file":"dom.mjs","sourcesContent":["\nimport { pushContext } from '../core/context'\nimport { runWithComponent, type ComponentInstance } from '../core/hook'\nimport { unsafeEffect } from '../core/effect'\n\n// Types\nexport type FNodeChild = FNode | string | number | boolean | null | undefined | FNodeChild[] | (() => FNode)\n\nexport interface FNode {\n type: string | Function\n props: Record<string, any>\n children: FNodeChild[]\n key?: any\n}\n\n// Extended ComponentInstance for DOM tracking\ninterface DOMComponentInstance extends ComponentInstance {\n nodes: Node[]\n parent: HTMLElement\n vnode: any\n props: any\n key?: any\n renderFn?: () => void // Store render function for manual updates\n children: Set<DOMComponentInstance> // Track child component instances\n parentInstance?: DOMComponentInstance // Track parent component instance\n}\n\n// Registry to store component instances by parent and key\nconst instanceRegistry = new WeakMap<HTMLElement, Map<any, DOMComponentInstance>>()\n\n// Current rendering component instance (for tracking parent-child relationships)\nlet currentRenderingInstance: DOMComponentInstance | null = null\n\n// Recursively remove component instance and all its children\nfunction removeComponentInstance(instance: DOMComponentInstance): void {\n // First, recursively remove all child instances\n instance.children.forEach(child => {\n removeComponentInstance(child)\n })\n\n // Remove DOM nodes created by this instance\n instance.nodes.forEach(node => {\n if (node.parentNode) {\n node.parentNode.removeChild(node)\n }\n })\n\n // Clear the children set\n instance.children.clear()\n\n // Remove from parent's children set\n if (instance.parentInstance) {\n instance.parentInstance.children.delete(instance)\n }\n}\n\n// Render a function component with reactive re-rendering\nfunction renderComponent(fnode: any, parent: HTMLElement, registryParent?: HTMLElement): Node[] {\n const effectiveRegistryParent = registryParent || parent\n // Merge props with children\n const mergeProps = (node: any) => {\n const props = { ...node.props }\n if (node.children && node.children.length > 0) {\n props.children = node.children.length === 1\n ? node.children[0]\n : node.children\n }\n return props\n }\n\n // Generate key for this component\n // Use explicit key if provided, otherwise generate auto-key based on render order\n const hasExplicitKey = fnode.key !== undefined\n\n // Get or create registry for this parent\n // Always use the effectiveRegistryParent for registry, not a temp container\n if (!instanceRegistry.has(effectiveRegistryParent)) {\n instanceRegistry.set(effectiveRegistryParent, new Map())\n }\n const parentRegistry = instanceRegistry.get(effectiveRegistryParent)!\n\n // Generate key: explicit key, or auto-increment based on component type\n let key: any\n if (hasExplicitKey) {\n key = fnode.key\n } else {\n // Auto-generate unique key: componentType + instance number\n // Count how many instances of this type already exist\n let instanceCount = 0\n const componentName = fnode.type.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 // Try to reuse existing instance with same key\n if (parentRegistry.has(key)) {\n const instance = parentRegistry.get(key)!\n\n // Update vnode\n instance.vnode = fnode\n\n // Update props (non-reactive) - we'll trigger re-render manually\n const newProps = mergeProps(fnode)\n\n // Always update props (including children)\n instance.props = newProps\n\n // Always clear old children before re-rendering (they will be re-added during render)\n // This must be done BEFORE renderFn is called\n instance.children.clear()\n\n // Manually trigger re-render by calling renderFn\n if (instance.renderFn) {\n instance.renderFn()\n }\n\n return instance.nodes\n }\n\n // Create component instance with regular props (not reactive)\n const instance: DOMComponentInstance = {\n hooks: [],\n hookIndex: 0,\n nodes: [],\n parent,\n vnode: fnode,\n props: mergeProps(fnode), // Regular props, we handle updates manually\n key,\n children: new Set(),\n parentInstance: currentRenderingInstance || undefined\n }\n\n // Register this instance as a child of the current rendering instance\n if (currentRenderingInstance) {\n currentRenderingInstance.children.add(instance)\n }\n\n // Store instance in registry\n parentRegistry.set(key, instance)\n\n // Track if this is the first render\n let isFirstRender = true\n\n // Function to render the component\n const renderFn = () => {\n const currentVnode = instance.vnode\n const currentProps = instance.props\n\n // Check if this is a Context Provider\n const isProvider = (currentVnode.type as any)._contextId !== undefined\n if (isProvider) {\n // Set context value before rendering\n pushContext((currentVnode.type as any)._contextId, currentProps.value)\n }\n\n // Set this instance as the current rendering instance\n const previousRenderingInstance = currentRenderingInstance\n currentRenderingInstance = instance\n\n // Render component with hook context\n const result = runWithComponent(instance, () => currentVnode.type(currentProps))\n\n // DON'T restore currentRenderingInstance yet - we need it for renderNode calls below\n // It will be restored at the end of this function\n\n if (isFirstRender) {\n // First render: create new DOM nodes\n const newNodes = renderNode(result, parent)\n instance.nodes = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\n // Mark nodes as owned by this instance (for reconciliation)\n // Only set ownership if not already owned (child components set ownership first)\n instance.nodes.forEach(node => {\n if (!(node as any).__ownerInstance) {\n (node as any).__ownerInstance = instance\n }\n })\n isFirstRender = false\n } else {\n // Re-render: reconcile with existing DOM\n // Don't early return if nodes is empty - component might render other components\n if (instance.nodes.length === 0) {\n // Component has no DOM nodes yet, might be rendering other components\n // Just re-render without reconciliation\n const newNodes = renderNode(result, parent)\n instance.nodes = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\n // Restore previous rendering instance before returning\n currentRenderingInstance = previousRenderingInstance\n return\n }\n\n const firstNode = instance.nodes[0]\n const nodeParent = firstNode.parentNode as HTMLElement\n\n if (!nodeParent) {\n // Restore previous rendering instance before returning\n currentRenderingInstance = previousRenderingInstance\n return\n }\n\n // Create marker to know where to insert new nodes\n const marker = document.createComment('flexium-marker')\n const lastNode = instance.nodes[instance.nodes.length - 1]\n if (lastNode.nextSibling) {\n nodeParent.insertBefore(marker, lastNode.nextSibling)\n } else {\n nodeParent.appendChild(marker)\n }\n\n // Clear children references - actual cleanup happens via key-based registry\n // Don't call removeComponentInstance here as it removes DOM nodes that reconcile needs\n instance.children.clear()\n\n // Create temporary container for collecting new nodes\n const tempContainer = document.createElement('div')\n\n // Render into temp container, but use actual parent for registry\n const newNodes = renderNode(result, tempContainer, nodeParent)\n const newNodesArray = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\n\n // Use reconcile to patch existing nodes instead of replacing\n const reconciledNodes = reconcile(instance.nodes, newNodesArray, nodeParent, marker)\n\n // Remove marker\n nodeParent.removeChild(marker)\n\n instance.nodes = reconciledNodes\n }\n\n // Restore previous rendering instance after all renderNode calls are done\n currentRenderingInstance = previousRenderingInstance\n }\n\n // Store renderFn for manual updates\n instance.renderFn = renderFn\n\n // Wrap in effect for reactive re-rendering\n unsafeEffect(renderFn)\n\n return instance.nodes\n}\n\nfunction renderNode(fnode: any, parent: HTMLElement, registryParent?: HTMLElement): Node | Node[] | null {\n // Use registryParent for instance lookups if provided, otherwise use parent\n const effectiveRegistryParent = registryParent || parent\n // 1. null/undefined/boolean -> empty text\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n const node = document.createTextNode('');\n parent.appendChild(node);\n return node;\n }\n\n // 2. Primitive (string/number) -> Text\n if (typeof fnode === 'string' || typeof fnode === 'number') {\n const node = document.createTextNode(String(fnode));\n parent.appendChild(node);\n return node;\n }\n\n // 3. Array -> render each item with key-based reconciliation\n if (Array.isArray(fnode)) {\n // Store old registry keys before rendering\n const oldKeysSet = new Set<any>()\n if (instanceRegistry.has(effectiveRegistryParent)) {\n const parentRegistry = instanceRegistry.get(effectiveRegistryParent)!\n parentRegistry.forEach((_, key) => oldKeysSet.add(key))\n }\n\n // Render all children\n const nodes: Node[] = [];\n fnode.forEach((child) => {\n const result = renderNode(child, parent, registryParent);\n if (result) {\n if (Array.isArray(result)) {\n nodes.push(...result);\n } else {\n nodes.push(result);\n }\n }\n });\n\n // After rendering, check which keys are still in the registry (= were reused or created)\n const newKeysSet = new Set<any>()\n if (instanceRegistry.has(effectiveRegistryParent)) {\n const parentRegistry = instanceRegistry.get(effectiveRegistryParent)!\n parentRegistry.forEach((_, key) => newKeysSet.add(key))\n }\n\n // Remove instances that existed before but don't exist now\n if (instanceRegistry.has(effectiveRegistryParent)) {\n const parentRegistry = instanceRegistry.get(effectiveRegistryParent)!\n const keysToRemove: any[] = []\n\n oldKeysSet.forEach(key => {\n if (!newKeysSet.has(key)) {\n const instance = parentRegistry.get(key)\n if (instance) {\n // Recursively remove component instance and all its children\n removeComponentInstance(instance)\n keysToRemove.push(key)\n }\n }\n })\n\n // Clean up registry\n keysToRemove.forEach(key => parentRegistry.delete(key))\n }\n\n return nodes;\n }\n\n // 4. Object (VNode)\n if (typeof fnode === 'object') {\n // 4a. HTML Element (intrinsic)\n if (typeof fnode.type === 'string') {\n const dom = document.createElement(fnode.type);\n\n // Set props/attributes\n if (fnode.props) {\n Object.entries(fnode.props).forEach(([key, value]) => {\n if (key.startsWith('on') && typeof value === 'function') {\n // Event handler: onClick -> click\n const eventName = key.slice(2).toLowerCase();\n dom.addEventListener(eventName, value as EventListener);\n\n // Store handlers for cleanup/reconciliation\n if (!(dom as any).__eventHandlers) {\n (dom as any).__eventHandlers = {};\n }\n (dom as any).__eventHandlers[eventName] = value;\n } else {\n // Regular attribute\n setAttribute(dom, key, value);\n }\n });\n }\n\n // Render children\n if (fnode.children && fnode.children.length > 0) {\n fnode.children.forEach((child: any) => {\n renderNode(child, dom);\n });\n }\n\n parent.appendChild(dom);\n return dom;\n }\n\n // 4b. Function Component\n if (typeof fnode.type === 'function') {\n // Check if this is a Context Provider\n const isProvider = (fnode.type as any)._contextId !== undefined;\n\n if (isProvider) {\n // Context Provider: treat like regular component for reactivity\n // This ensures providers re-render when their children change\n return renderComponent(fnode, parent, registryParent);\n } else {\n // Regular component: use reactive rendering\n return renderComponent(fnode, parent, registryParent);\n }\n }\n }\n\n // Fallback: unknown type\n return null;\n}\n\nexport function render(app: any, container: HTMLElement) {\n container.innerHTML = ''\n\n // Handle raw function components by wrapping them in an FNode\n if (typeof app === 'function') {\n app = { type: app, props: {}, children: [], key: undefined }\n }\n\n renderNode(app, container);\n}\n\n// f() - Create FNodes without JSX\nexport function f(\n type: string | Function,\n props?: any,\n ...children: any[]\n): any {\n return {\n type,\n props: props || {},\n children,\n key: props?.key\n }\n}\n\nfunction setAttribute(el: Element, key: string, value: any) {\n if (value === null || value === undefined) {\n el.removeAttribute(key)\n } else if (key === 'style' && typeof value === 'object') {\n // Handle style object\n Object.assign((el as HTMLElement).style, value)\n } else if (key === 'class') {\n // Handle class specially (className property)\n el.className = String(value)\n } else if (key in el && typeof (el as any)[key] !== 'function') {\n // Property-first approach: use DOM property if available\n // This automatically handles: disabled, checked, value, readonly, etc.\n (el as any)[key] = value\n } else {\n // Fallback to setAttribute for custom/data attributes\n el.setAttribute(key, String(value))\n }\n}\n\n// Reconciliation helpers\nfunction canReuse(oldNode: Node, newNode: Node): boolean {\n if (oldNode.nodeType !== newNode.nodeType) return false\n if (oldNode.nodeType === Node.ELEMENT_NODE && newNode.nodeType === Node.ELEMENT_NODE) {\n return (oldNode as Element).tagName === (newNode as Element).tagName\n }\n return true\n}\n\nfunction updateAttributes(oldEl: Element, newEl: Element): void {\n // Remove old attributes\n const oldAttrs = Array.from(oldEl.attributes)\n oldAttrs.forEach(attr => {\n if (!newEl.hasAttribute(attr.name)) {\n oldEl.removeAttribute(attr.name)\n }\n })\n\n // Set/update new attributes\n const newAttrs = Array.from(newEl.attributes)\n newAttrs.forEach(attr => {\n if (oldEl.getAttribute(attr.name) !== attr.value) {\n // Use DOM property for value/checked to preserve focus\n if (attr.name === 'value' && 'value' in oldEl) {\n (oldEl as HTMLInputElement).value = attr.value\n } else if (attr.name === 'checked' && 'checked' in oldEl) {\n (oldEl as HTMLInputElement).checked = attr.value === 'true' || attr.value === ''\n } else {\n oldEl.setAttribute(attr.name, attr.value)\n }\n }\n })\n\n // Update event handlers\n const oldHandlers = (oldEl as any).__eventHandlers || {}\n const newHandlers = (newEl as any).__eventHandlers || {}\n\n // Remove old handlers\n Object.keys(oldHandlers).forEach(event => {\n if (!newHandlers[event]) {\n oldEl.removeEventListener(event, oldHandlers[event])\n }\n })\n\n // Add/update new handlers\n Object.keys(newHandlers).forEach(event => {\n if (oldHandlers[event] !== newHandlers[event]) {\n if (oldHandlers[event]) {\n oldEl.removeEventListener(event, oldHandlers[event])\n }\n oldEl.addEventListener(event, newHandlers[event])\n }\n })\n\n // Update stored handlers\n if (Object.keys(newHandlers).length > 0) {\n (oldEl as any).__eventHandlers = newHandlers\n } else {\n delete (oldEl as any).__eventHandlers\n }\n\n // Special handling for form input values\n if (oldEl instanceof HTMLInputElement && newEl instanceof HTMLInputElement) {\n if (oldEl.value !== newEl.value) {\n oldEl.value = newEl.value\n }\n if (oldEl.checked !== newEl.checked) {\n oldEl.checked = newEl.checked\n }\n }\n if (oldEl instanceof HTMLTextAreaElement && newEl instanceof HTMLTextAreaElement) {\n if (oldEl.value !== newEl.value) {\n oldEl.value = newEl.value\n }\n }\n if (oldEl instanceof HTMLSelectElement && newEl instanceof HTMLSelectElement) {\n if (oldEl.value !== newEl.value) {\n oldEl.value = newEl.value\n }\n }\n}\n\nfunction reconcileChildren(oldEl: Element, newEl: Element): void {\n const oldChildren = Array.from(oldEl.childNodes)\n const newChildren = Array.from(newEl.childNodes)\n const maxLen = Math.max(oldChildren.length, newChildren.length)\n\n for (let i = 0; i < maxLen; i++) {\n const oldChild = oldChildren[i]\n const newChild = newChildren[i]\n\n if (!oldChild && newChild) {\n // Add new child\n oldEl.appendChild(newChild)\n } else if (oldChild && !newChild) {\n // Remove old child\n oldEl.removeChild(oldChild)\n } else if (oldChild && newChild) {\n // Patch child\n patchNode(oldChild, newChild, oldEl)\n }\n }\n}\n\nfunction patchNode(oldNode: Node, newNode: Node, parent: Element): void {\n if (canReuse(oldNode, newNode)) {\n // Transfer component instance ownership from newNode to oldNode\n // This ensures component instances reference actual DOM nodes after reconciliation\n const ownerInstance = (newNode as any).__ownerInstance as DOMComponentInstance | undefined\n if (ownerInstance) {\n const idx = ownerInstance.nodes.indexOf(newNode)\n if (idx !== -1) {\n ownerInstance.nodes[idx] = oldNode\n }\n ;(oldNode as any).__ownerInstance = ownerInstance\n delete (newNode as any).__ownerInstance\n }\n // Reuse node\n if (oldNode.nodeType === Node.TEXT_NODE) {\n // Update text content\n if (oldNode.nodeValue !== newNode.nodeValue) {\n oldNode.nodeValue = newNode.nodeValue\n }\n } else if (oldNode.nodeType === Node.ELEMENT_NODE) {\n // Update element\n updateAttributes(oldNode as Element, newNode as Element)\n reconcileChildren(oldNode as Element, newNode as Element)\n }\n } else {\n // Different type, replace\n parent.replaceChild(newNode, oldNode)\n }\n}\n\n// Exported for future use (Phase 2: Reactive rendering)\nexport function reconcile(oldNodes: Node[], newNodes: Node[], parent: Node, beforeMarker: Node): Node[] {\n const maxLen = Math.max(oldNodes.length, newNodes.length)\n const resultNodes: Node[] = []\n\n for (let i = 0; i < maxLen; i++) {\n const oldNode = oldNodes[i]\n const newNode = newNodes[i]\n\n if (!oldNode && newNode) {\n // Add new node\n parent.insertBefore(newNode, beforeMarker)\n resultNodes.push(newNode)\n } else if (oldNode && !newNode) {\n // Remove old node\n if (oldNode.parentNode) {\n parent.removeChild(oldNode)\n }\n } else if (oldNode && newNode) {\n // Patch node\n patchNode(oldNode, newNode, parent as Element)\n resultNodes.push(oldNode)\n }\n }\n\n return resultNodes\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","currentResult","unsafeEffect","popContext","Portal","target","portalState","hook","effect","portalWrapper","defaultValue","SuspenseCtx","createContext","suspenseContext","context","Suspense","fallback","pendingSet","pendingCount","setPendingCount","showFallback","setShowFallback","contextValue","promise","c","newCount","content","ErrorBoundary","onError","resetKey","errorState","setErrorState","prevResetKeyRef","lazy","loader","resolved","LazyWrapper","suspense","module","err"],"mappings":"uUAKO,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,C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A,CAAAA,CAASc,CAAAA,CAAW,MAAOA,CAAAA,CAAW,IAAK,EAE7Cd,CAAAA,CAMT,GAAI,CAEF,OAAO/D,CACT,CAAA,OAAE,CAEF,CACF,CCtFO,SAASgF,EACdC,CAAAA,CACkB,CAElB,IAAIC,CAAAA,CAA8C,IAAA,CAC9CZ,CAAAA,CAA+B,KAC/BxD,CAAAA,CAAsB,IAAA,CAGpBqE,EAAepF,CAAAA,EAAyB,CAE5C,GAAImF,CAAAA,CACF,OAAOA,CAAAA,CAASnF,CAAK,CAAA,CAIvB,GAAIe,EACF,MAAMA,CAAAA,CAIR,IAAMsE,CAAAA,CAAWxB,CAAAA,GAGjB,OAAKU,CAAAA,GACHA,CAAAA,CAAUW,CAAAA,EAAO,CACd,IAAA,CAAKI,GAAU,CACdH,CAAAA,CAAWG,EAAO,QACpB,CAAC,EACA,KAAA,CAAMC,CAAAA,EAAO,CACZxE,CAAAA,CAAQwE,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, parent)\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, parent: HTMLElement): 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 const currentResult = 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 { effect } from '../../core/lifecycle'\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 effect(() => {\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 return () => {\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, context } 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 context(SuspenseCtx)\n}\n","import { state } from '../../core/state'\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 [pendingCount, setPendingCount] = state(0)\n const [showFallback, setShowFallback] = state(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 { state } from '../../core/state'\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] = state<{\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
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var o="0.12.
|
|
1
|
+
'use strict';var o="0.12.16";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.12.
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["VERSION"],"mappings":"aAAO,IAAMA,CAAAA,CAAU","file":"index.js","sourcesContent":["export const VERSION = '0.12.16' // Bump version to signify rebuild\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var o="0.12.
|
|
1
|
+
var o="0.12.16";export{o as VERSION};//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["VERSION"],"mappings":"AAAO,IAAMA,CAAAA,CAAU","file":"index.mjs","sourcesContent":["export const VERSION = '0.12.
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["VERSION"],"mappings":"AAAO,IAAMA,CAAAA,CAAU","file":"index.mjs","sourcesContent":["export const VERSION = '0.12.16' // Bump version to signify rebuild\n"]}
|
package/dist/interactive.d.cts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
interface LoopCallbacks {
|
|
2
|
-
fixedFps?: number;
|
|
3
|
-
onUpdate?: (delta: number) => void;
|
|
4
|
-
onFixedUpdate?: (fixedDelta: number) => void;
|
|
5
|
-
onRender?: (alpha: number) => void;
|
|
6
|
-
}
|
|
7
|
-
interface Loop {
|
|
8
|
-
start: () => void;
|
|
9
|
-
stop: () => void;
|
|
10
|
-
isRunning: () => boolean;
|
|
11
|
-
getFps: () => number;
|
|
12
|
-
}
|
|
13
|
-
declare function loop(callbacks: LoopCallbacks): Loop;
|
|
14
|
-
|
|
15
1
|
declare enum Keys {
|
|
16
2
|
ArrowUp = "ArrowUp",
|
|
17
3
|
ArrowDown = "ArrowDown",
|
|
@@ -54,8 +40,6 @@ interface KeyboardState {
|
|
|
54
40
|
clearFrameState: () => void;
|
|
55
41
|
dispose: () => void;
|
|
56
42
|
}
|
|
57
|
-
declare function keyboard(target?: EventTarget): KeyboardState;
|
|
58
|
-
|
|
59
43
|
declare enum MouseButton {
|
|
60
44
|
Left = 0,
|
|
61
45
|
Middle = 1,
|
|
@@ -78,6 +62,23 @@ interface MouseState {
|
|
|
78
62
|
clearFrameState: () => void;
|
|
79
63
|
dispose: () => void;
|
|
80
64
|
}
|
|
65
|
+
interface LoopCallbacks {
|
|
66
|
+
fixedFps?: number;
|
|
67
|
+
onUpdate?: (delta: number) => void;
|
|
68
|
+
onFixedUpdate?: (fixedDelta: number) => void;
|
|
69
|
+
onRender?: (alpha: number) => void;
|
|
70
|
+
}
|
|
71
|
+
interface Loop {
|
|
72
|
+
start: () => void;
|
|
73
|
+
stop: () => void;
|
|
74
|
+
isRunning: () => boolean;
|
|
75
|
+
getFps: () => number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
declare function loop(callbacks: LoopCallbacks): Loop;
|
|
79
|
+
|
|
80
|
+
declare function keyboard(target?: EventTarget): KeyboardState;
|
|
81
|
+
|
|
81
82
|
declare function mouse(options?: MouseOptions): MouseState;
|
|
82
83
|
|
|
83
84
|
export { type KeyboardState, Keys, type Loop, type LoopCallbacks, MouseButton, type MouseOptions, type MouseState, keyboard, loop, mouse };
|
package/dist/interactive.d.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
interface LoopCallbacks {
|
|
2
|
-
fixedFps?: number;
|
|
3
|
-
onUpdate?: (delta: number) => void;
|
|
4
|
-
onFixedUpdate?: (fixedDelta: number) => void;
|
|
5
|
-
onRender?: (alpha: number) => void;
|
|
6
|
-
}
|
|
7
|
-
interface Loop {
|
|
8
|
-
start: () => void;
|
|
9
|
-
stop: () => void;
|
|
10
|
-
isRunning: () => boolean;
|
|
11
|
-
getFps: () => number;
|
|
12
|
-
}
|
|
13
|
-
declare function loop(callbacks: LoopCallbacks): Loop;
|
|
14
|
-
|
|
15
1
|
declare enum Keys {
|
|
16
2
|
ArrowUp = "ArrowUp",
|
|
17
3
|
ArrowDown = "ArrowDown",
|
|
@@ -54,8 +40,6 @@ interface KeyboardState {
|
|
|
54
40
|
clearFrameState: () => void;
|
|
55
41
|
dispose: () => void;
|
|
56
42
|
}
|
|
57
|
-
declare function keyboard(target?: EventTarget): KeyboardState;
|
|
58
|
-
|
|
59
43
|
declare enum MouseButton {
|
|
60
44
|
Left = 0,
|
|
61
45
|
Middle = 1,
|
|
@@ -78,6 +62,23 @@ interface MouseState {
|
|
|
78
62
|
clearFrameState: () => void;
|
|
79
63
|
dispose: () => void;
|
|
80
64
|
}
|
|
65
|
+
interface LoopCallbacks {
|
|
66
|
+
fixedFps?: number;
|
|
67
|
+
onUpdate?: (delta: number) => void;
|
|
68
|
+
onFixedUpdate?: (fixedDelta: number) => void;
|
|
69
|
+
onRender?: (alpha: number) => void;
|
|
70
|
+
}
|
|
71
|
+
interface Loop {
|
|
72
|
+
start: () => void;
|
|
73
|
+
stop: () => void;
|
|
74
|
+
isRunning: () => boolean;
|
|
75
|
+
getFps: () => number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
declare function loop(callbacks: LoopCallbacks): Loop;
|
|
79
|
+
|
|
80
|
+
declare function keyboard(target?: EventTarget): KeyboardState;
|
|
81
|
+
|
|
81
82
|
declare function mouse(options?: MouseOptions): MouseState;
|
|
82
83
|
|
|
83
84
|
export { type KeyboardState, Keys, type Loop, type LoopCallbacks, MouseButton, type MouseOptions, type MouseState, keyboard, loop, mouse };
|
package/dist/interactive.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkLTT43APF_js=require('./chunk-LTT43APF.js');require('./chunk-6VIRXD2Y.js'),require('./chunk-YWTD32NA.js'),require('./chunk-UWFVCKRU.js');function F(a){let{fixedFps:n=60,onUpdate:v,onFixedUpdate:o,onRender:y}=a,p=1/n,S=.25,d=false,m=0,t=0,s=0,i=0,u=0,r=null;function l(w){if(!d)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(l);}return {start:()=>{d||(d=true,m=performance.now(),t=0,r=requestAnimationFrame(l));},stop:()=>{d=false,r!==null&&(cancelAnimationFrame(r),r=null);},isRunning:()=>d,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]=chunkLTT43APF_js.a(new Set,{key:["keyboard","pressed"]}),[o,y]=chunkLTT43APF_js.a(new Set,{key:["keyboard","justPressed"]}),[p,S]=chunkLTT43APF_js.a(new Set,{key:["keyboard","justReleased"]}),d=t=>{let s=t.code,i=n;if(!i.has(s)){let u=new Set(i);u.add(s),v(u);let r=o,l=new Set(r);l.add(s),y(l);}},m=t=>{let s=t.code,i=n,u=new Set(i);u.delete(s),v(u);let r=p,l=new Set(r);l.add(s),S(l);};return a.addEventListener("keydown",d),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",d),a.removeEventListener("keyup",m);}}}function J(a={}){let n=a.target||window,v=typeof a.canvas=="function"?a.canvas:()=>a.canvas,[o,y]=chunkLTT43APF_js.a({x:0,y:0},{key:["mouse","position"]}),[p,S]=chunkLTT43APF_js.a({x:0,y:0},{key:["mouse","delta"]}),[d,m]=chunkLTT43APF_js.a(0,{key:["mouse","wheel"]}),[t,s]=chunkLTT43APF_js.a(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;},l=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",l),n.addEventListener("mouseup",w),n.addEventListener("wheel",D);let h=t,P=o,R=p,A=d;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",l),n.removeEventListener("mouseup",w),n.removeEventListener("wheel",D);}}}exports.Keys=x;exports.MouseButton=k;exports.keyboard=C;exports.loop=F;exports.mouse=J;//# sourceMappingURL=interactive.js.map
|
|
2
2
|
//# sourceMappingURL=interactive.js.map
|
package/dist/interactive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interactive/loop.ts","../src/interactive/keyboard.ts","../src/interactive/mouse.ts"],"names":["loop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","currentTime","delta","alpha","Keys","keyboard","target","pressedKeys","setPressedKeys","state","justPressedKeys","setJustPressedKeys","justReleasedKeys","setJustReleasedKeys","handleKeyDown","e","key","currentPressed","newPressed","currentJustPressed","newJustPressed","handleKeyUp","currentJustReleased","newJustReleased","MouseButton","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":"+HAcO,SAASA,CAAAA,CAAKC,EAAgC,CACnD,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,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Aa,CAAA,CACnDzC,CAAAA,CAAO,oBAAoB,OAAA,CAAS0C,CAAW,EACjD,CACF,CACF","file":"interactive.js","sourcesContent":["export 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\nexport function loop(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","import { state } from '../core/state'\n\nexport enum Keys {\n // Arrow keys\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n\n // WASD\n KeyW = 'KeyW',\n KeyA = 'KeyA',\n KeyS = 'KeyS',\n KeyD = 'KeyD',\n\n // Common keys\n Space = 'Space',\n Enter = 'Enter',\n Escape = 'Escape',\n Tab = 'Tab',\n\n // Modifiers\n ShiftLeft = 'ShiftLeft',\n ShiftRight = 'ShiftRight',\n ControlLeft = 'ControlLeft',\n ControlRight = 'ControlRight',\n AltLeft = 'AltLeft',\n AltRight = 'AltRight',\n\n // Numbers\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\n // Letters (additional common ones)\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\nexport function keyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = state<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = state<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = state<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 { state } from '../core/state'\n\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\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] = state({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = state({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = state(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = state<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":["loop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","currentTime","delta","alpha","Keys","MouseButton","keyboard","target","pressedKeys","setPressedKeys","state","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,CAAKC,EAAgC,CACnD,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,SAASd,CAAAA,CAAKe,EAAqB,CACjC,GAAI,CAACP,CAAAA,CAAS,OAGd,IAAMQ,CAAAA,CAAQ,IAAA,CAAK,GAAA,CAAA,CAAKD,EAAcN,CAAAA,EAAY,GAAA,CAAMF,CAAQ,CAAA,CAShE,GARAE,EAAWM,CAAAA,CAGPZ,CAAAA,EACFA,EAASa,CAAK,CAAA,CAIZZ,EAG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AChDxC,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 loop(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 { state } from '../core/state'\nimport { Keys, type KeyboardState } from './types'\n\nexport { Keys, type KeyboardState }\n\nexport function keyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = state<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = state<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = state<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 { state } from '../core/state'\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] = state({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = state({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = state(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = state<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"]}
|
package/dist/interactive.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a}from'./chunk-
|
|
1
|
+
import {a}from'./chunk-WGKD63GN.mjs';import'./chunk-JY6CE6RN.mjs';import'./chunk-IWFEXW4F.mjs';import'./chunk-5PNH2ARD.mjs';function F(a){let{fixedFps:n=60,onUpdate:v,onFixedUpdate:o,onRender:y}=a,p=1/n,S=.25,d=false,m=0,t=0,s=0,i=0,u=0,r=null;function l(w){if(!d)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(l);}return {start:()=>{d||(d=true,m=performance.now(),t=0,r=requestAnimationFrame(l));},stop:()=>{d=false,r!==null&&(cancelAnimationFrame(r),r=null);},isRunning:()=>d,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$1=window){let[n,v]=a(new Set,{key:["keyboard","pressed"]}),[o,y]=a(new Set,{key:["keyboard","justPressed"]}),[p,S]=a(new Set,{key:["keyboard","justReleased"]}),d=t=>{let s=t.code,i=n;if(!i.has(s)){let u=new Set(i);u.add(s),v(u);let r=o,l=new Set(r);l.add(s),y(l);}},m=t=>{let s=t.code,i=n,u=new Set(i);u.delete(s),v(u);let r=p,l=new Set(r);l.add(s),S(l);};return a$1.addEventListener("keydown",d),a$1.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$1.removeEventListener("keydown",d),a$1.removeEventListener("keyup",m);}}}function J(a$1={}){let n=a$1.target||window,v=typeof a$1.canvas=="function"?a$1.canvas:()=>a$1.canvas,[o,y]=a({x:0,y:0},{key:["mouse","position"]}),[p,S]=a({x:0,y:0},{key:["mouse","delta"]}),[d,m]=a(0,{key:["mouse","wheel"]}),[t,s]=a(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;},l=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",l),n.addEventListener("mouseup",w),n.addEventListener("wheel",D);let h=t,P=o,R=p,A=d;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",l),n.removeEventListener("mouseup",w),n.removeEventListener("wheel",D);}}}export{x as Keys,k as MouseButton,C as keyboard,F as loop,J as mouse};//# sourceMappingURL=interactive.mjs.map
|
|
2
2
|
//# sourceMappingURL=interactive.mjs.map
|
package/dist/interactive.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interactive/loop.ts","../src/interactive/keyboard.ts","../src/interactive/mouse.ts"],"names":["loop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","currentTime","delta","alpha","Keys","keyboard","target","pressedKeys","setPressedKeys","state","justPressedKeys","setJustPressedKeys","justReleasedKeys","setJustReleasedKeys","handleKeyDown","e","key","currentPressed","newPressed","currentJustPressed","newJustPressed","handleKeyUp","currentJustReleased","newJustReleased","MouseButton","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":"+FAcO,SAASA,CAAAA,CAAKC,EAAgC,CACnD,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,SAASd,CAAAA,CAAKe,EAAqB,CACjC,GAAI,CAACP,CAAAA,CAAS,OAGd,IAAMQ,CAAAA,CAAQ,IAAA,CAAK,GAAA,CAAA,CAAKD,EAAcN,CAAAA,EAAY,GAAA,CAAMF,CAAQ,CAAA,CAShE,GARAE,EAAWM,CAAAA,CAGPZ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AAAA,CAAiBZ,EACjBgB,CAAAA,CAAkBrB,CAAAA,CAClBsB,EAAehD,CAAAA,CACfiD,CAAAA,CAAoBpB,EAE1B,OAAO,CACL,IAAI,CAAA,EAAI,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,CAAI,CAAgB,GAAK,KAAA,CAE9D,cAAA,CAAgB,IAAMA,CAAAA,EAAgB,GAAA,CAAI,CAAiB,GAAK,KAAA,CAEhE,eAAA,CAAiB,IAAMA,CAAAA,EAAgB,GAAA,CAAI,CAAkB,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,CACb1B,CAAAA,CAAO,oBAAoB,WAAA,CAAa+B,CAAe,EACvD/B,CAAAA,CAAO,mBAAA,CAAoB,YAAaqC,CAAe,CAAA,CACvDrC,EAAO,mBAAA,CAAoB,SAAA,CAAWyC,CAAa,CAAA,CACnDzC,CAAAA,CAAO,oBAAoB,OAAA,CAAS0C,CAAW,EACjD,CACF,CACF","file":"interactive.mjs","sourcesContent":["export 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\nexport function loop(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","import { state } from '../core/state'\n\nexport enum Keys {\n // Arrow keys\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n\n // WASD\n KeyW = 'KeyW',\n KeyA = 'KeyA',\n KeyS = 'KeyS',\n KeyD = 'KeyD',\n\n // Common keys\n Space = 'Space',\n Enter = 'Enter',\n Escape = 'Escape',\n Tab = 'Tab',\n\n // Modifiers\n ShiftLeft = 'ShiftLeft',\n ShiftRight = 'ShiftRight',\n ControlLeft = 'ControlLeft',\n ControlRight = 'ControlRight',\n AltLeft = 'AltLeft',\n AltRight = 'AltRight',\n\n // Numbers\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\n // Letters (additional common ones)\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\nexport function keyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = state<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = state<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = state<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 { state } from '../core/state'\n\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\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] = state({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = state({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = state(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = state<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":["loop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","currentTime","delta","alpha","Keys","MouseButton","keyboard","target","pressedKeys","setPressedKeys","state","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,CAAKC,EAAgC,CACnD,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,SAASd,CAAAA,CAAKe,EAAqB,CACjC,GAAI,CAACP,CAAAA,CAAS,OAGd,IAAMQ,CAAAA,CAAQ,IAAA,CAAK,GAAA,CAAA,CAAKD,EAAcN,CAAAA,EAAY,GAAA,CAAMF,CAAQ,CAAA,CAShE,GARAE,EAAWM,CAAAA,CAGPZ,CAAAA,EACFA,EAASa,CAAK,CAAA,CAIZZ,EAGF,IAFAM,CAAAA,EAAeM,EAERN,CAAAA,EAAeJ,CAAAA,EACpBF,EAAcE,CAAU,CAAA,CACxBI,GAAeJ,CAAAA,CAKnB,GAAID,EAAU,CACZ,IAAMY,EAAQP,CAAAA,CAAcJ,CAAAA,CAC5BD,EAASY,CAAK,EAChB,CAGAL,CAAAA,EAAAA,CACIG,CAAAA,CAAcF,GAAW,GAAA,GAC3BF,CA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A,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 loop(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 { state } from '../core/state'\nimport { Keys, type KeyboardState } from './types'\n\nexport { Keys, type KeyboardState }\n\nexport function keyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = state<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = state<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = state<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 { state } from '../core/state'\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] = state({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = state({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = state(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = state<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"]}
|
package/dist/jsx-runtime.d.cts
CHANGED
package/dist/jsx-runtime.d.ts
CHANGED