flexium 0.13.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/{chunk-NY6NOGFU.mjs → chunk-J3542Z77.mjs} +2 -2
  2. package/dist/chunk-J3542Z77.mjs.map +1 -0
  3. package/dist/{chunk-DUGPBZZ3.js → chunk-LHOIM4QY.js} +2 -2
  4. package/dist/chunk-LHOIM4QY.js.map +1 -0
  5. package/dist/core.d.cts +6 -1
  6. package/dist/core.d.ts +6 -1
  7. package/dist/core.js +1 -1
  8. package/dist/core.mjs +1 -1
  9. package/dist/core.mjs.map +1 -1
  10. package/dist/dom.d.cts +1 -10
  11. package/dist/dom.d.ts +1 -10
  12. package/dist/dom.js +1 -1
  13. package/dist/dom.mjs +1 -1
  14. package/dist/dom.mjs.map +1 -1
  15. package/dist/index.d.cts +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +1 -1
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/jsx-dev-runtime.js +1 -1
  22. package/dist/jsx-dev-runtime.mjs +1 -1
  23. package/dist/jsx-runtime.js +1 -1
  24. package/dist/jsx-runtime.mjs +1 -1
  25. package/dist/metafile-cjs.json +1 -1
  26. package/dist/metafile-esm.json +1 -1
  27. package/dist/router.js +1 -1
  28. package/dist/router.js.map +1 -1
  29. package/dist/router.mjs +1 -1
  30. package/dist/router.mjs.map +1 -1
  31. package/package.json +2 -17
  32. package/dist/canvas.d.cts +0 -84
  33. package/dist/canvas.d.ts +0 -84
  34. package/dist/canvas.js +0 -2
  35. package/dist/canvas.js.map +0 -1
  36. package/dist/canvas.mjs +0 -2
  37. package/dist/canvas.mjs.map +0 -1
  38. package/dist/chunk-DUGPBZZ3.js.map +0 -1
  39. package/dist/chunk-NY6NOGFU.mjs.map +0 -1
  40. package/dist/interactive.d.cts +0 -84
  41. package/dist/interactive.d.ts +0 -84
  42. package/dist/interactive.js +0 -2
  43. package/dist/interactive.js.map +0 -1
  44. package/dist/interactive.mjs +0 -2
  45. package/dist/interactive.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/canvas/Canvas.tsx","../src/canvas/dom/DrawRect.tsx","../src/canvas/dom/DrawCircle.tsx","../src/canvas/dom/DrawArc.tsx","../src/canvas/dom/DrawLine.tsx","../src/canvas/dom/DrawText.tsx","../src/canvas/dom/DrawPath.tsx"],"names":["drawQueue","queueDraw","node","Canvas","props","width","height","children","style","ref","canvas","ctx","render","child","drawNode","use","jsx","el","getValue","val","isReactive","type","opacity","x","y","w","h","fill","stroke","strokeWidth","radius","startAngle","endAngle","counterclockwise","x1","y1","x2","y2","text","fontSize","fontFamily","fontWeight","textAlign","d","path","DrawRect","DrawCircle","DrawArc","DrawLine","DrawText","DrawPath"],"mappings":"mLAOA,IACMA,CAAAA,CAA8B,GAM7B,SAASC,CAAAA,CAAUC,CAAAA,CAAsB,CAC9CF,CAAAA,CAAU,KAAKE,CAAI,EACrB,CAEO,SAASC,CAAAA,CAAOC,EAAoB,CACzC,GAAM,CAAE,KAAA,CAAAC,EAAO,MAAA,CAAAC,CAAAA,CAAQ,SAAAC,CAAAA,CAAU,KAAA,CAAAC,EAAO,GAAA,CAAAC,CAAI,CAAA,CAAIL,CAAAA,CAE5CM,EACAC,CAAAA,CAAuC,IAAA,CAErCC,EAAS,IAAM,CACf,CAACF,CAAAA,EAAU,CAACC,CAAAA,GAGhBA,CAAAA,CAAI,UAAU,CAAA,CAAG,CAAA,CAAGN,CAAAA,CAAOC,CAAM,EAGjCN,CAAAA,CAAU,MAAA,CAAS,CAAA,CAMf,KAAA,CAAM,OAAA,CAAQO,CAAQ,CAAA,CACxBA,CAAAA,CAAS,QAAQM,CAAAA,EAAS,CACpB,OAAOA,CAAAA,EAAU,YACnBA,CAAAA,GAEJ,CAAC,CAAA,CACQ,OAAON,GAAa,UAAA,EAC7BA,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I,IAAM,CACRd,CAAAA,CAAU,CACR,IAAA,CAAM,OACN,KAAA,CAAAG,CACF,CAAC,EACH,CAAC,EAEM,IACT","file":"canvas.js","sourcesContent":["import { use } from '../core/use'\nimport { isReactive } from '../core/reactive'\nimport type { CanvasProps, CanvasDrawNode } from './types'\n\nexport type { CanvasProps }\n\n// Canvas context for children to access\nlet currentCanvasContext: CanvasRenderingContext2D | null = null\nconst drawQueue: CanvasDrawNode[] = []\n\nexport function getCanvasContext() {\n return currentCanvasContext\n}\n\nexport function queueDraw(node: CanvasDrawNode) {\n drawQueue.push(node)\n}\n\nexport function Canvas(props: CanvasProps) {\n const { width, height, children, style, ref } = props\n\n let canvas: HTMLCanvasElement | undefined\n let ctx: CanvasRenderingContext2D | null = null\n\n const render = () => {\n if (!canvas || !ctx) return\n\n // Clear canvas\n ctx.clearRect(0, 0, width, height)\n\n // Clear draw queue\n drawQueue.length = 0\n\n // Set current context for children\n currentCanvasContext = ctx\n\n // Render children (they will queue draw commands)\n if (Array.isArray(children)) {\n children.forEach(child => {\n if (typeof child === 'function') {\n child()\n }\n })\n } else if (typeof children === 'function') {\n children()\n }\n\n // Execute draw queue\n drawQueue.forEach(node => {\n drawNode(ctx!, node)\n })\n\n // Clear context\n currentCanvasContext = null\n }\n\n use(() => {\n if (canvas) {\n render()\n }\n })\n\n return (\n <canvas\n ref={(el: HTMLCanvasElement) => {\n canvas = el\n ctx = el.getContext('2d')\n if (ref) ref(el)\n render()\n }}\n width={width}\n height={height}\n style={style}\n />\n )\n}\n\nfunction getValue(val: any): any {\n if (isReactive(val)) {\n return val.valueOf?.() ?? val\n }\n return val\n}\n\nfunction drawNode(ctx: CanvasRenderingContext2D, node: CanvasDrawNode) {\n const { type, props } = node\n\n // Apply opacity\n const opacity = getValue(props.opacity)\n if (opacity !== undefined) {\n ctx.globalAlpha = opacity\n }\n\n switch (type) {\n case 'rect': {\n const x = getValue(props.x)\n const y = getValue(props.y)\n const w = getValue(props.width)\n const h = getValue(props.height)\n const fill = getValue(props.fill)\n const stroke = getValue(props.stroke)\n const strokeWidth = getValue(props.strokeWidth)\n\n if (fill) {\n ctx.fillStyle = fill\n ctx.fillRect(x, y, w, h)\n }\n\n if (stroke) {\n ctx.strokeStyle = stroke\n if (strokeWidth) ctx.lineWidth = strokeWidth\n ctx.strokeRect(x, y, w, h)\n }\n break\n }\n\n case 'circle': {\n const x = getValue(props.x)\n const y = getValue(props.y)\n const radius = getValue(props.radius)\n const fill = getValue(props.fill)\n const stroke = getValue(props.stroke)\n const strokeWidth = getValue(props.strokeWidth)\n\n ctx.beginPath()\n ctx.arc(x, y, radius, 0, Math.PI * 2)\n\n if (fill) {\n ctx.fillStyle = fill\n ctx.fill()\n }\n\n if (stroke) {\n ctx.strokeStyle = stroke\n if (strokeWidth) ctx.lineWidth = strokeWidth\n ctx.stroke()\n }\n break\n }\n\n case 'arc': {\n const x = getValue(props.x)\n const y = getValue(props.y)\n const radius = getValue(props.radius)\n const startAngle = getValue(props.startAngle)\n const endAngle = getValue(props.endAngle)\n const counterclockwise = getValue(props.counterclockwise) || false\n const fill = getValue(props.fill)\n const stroke = getValue(props.stroke)\n const strokeWidth = getValue(props.strokeWidth)\n\n ctx.beginPath()\n ctx.arc(x, y, radius, startAngle, endAngle, counterclockwise)\n\n if (fill) {\n ctx.fillStyle = fill\n ctx.fill()\n }\n\n if (stroke) {\n ctx.strokeStyle = stroke\n if (strokeWidth) ctx.lineWidth = strokeWidth\n ctx.stroke()\n }\n break\n }\n\n case 'line': {\n const x1 = getValue(props.x1)\n const y1 = getValue(props.y1)\n const x2 = getValue(props.x2)\n const y2 = getValue(props.y2)\n const stroke = getValue(props.stroke) || 'black'\n const strokeWidth = getValue(props.strokeWidth) || 1\n\n ctx.beginPath()\n ctx.moveTo(x1, y1)\n ctx.lineTo(x2, y2)\n ctx.strokeStyle = stroke\n ctx.lineWidth = strokeWidth\n ctx.stroke()\n break\n }\n\n case 'text': {\n const x = getValue(props.x)\n const y = getValue(props.y)\n const text = getValue(props.text)\n const fill = getValue(props.fill) || 'black'\n const fontSize = getValue(props.fontSize) || 16\n const fontFamily = getValue(props.fontFamily) || 'sans-serif'\n const fontWeight = getValue(props.fontWeight) || 'normal'\n const textAlign = getValue(props.textAlign) || 'left'\n\n ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`\n ctx.textAlign = textAlign as CanvasTextAlign\n ctx.fillStyle = fill\n ctx.fillText(text, x, y)\n break\n }\n\n case 'path': {\n const d = getValue(props.d)\n const fill = getValue(props.fill)\n const stroke = getValue(props.stroke)\n const strokeWidth = getValue(props.strokeWidth)\n\n // Parse SVG path data\n const path = new Path2D(d)\n\n if (fill) {\n ctx.fillStyle = fill\n ctx.fill(path)\n }\n\n if (stroke) {\n ctx.strokeStyle = stroke\n if (strokeWidth) ctx.lineWidth = strokeWidth\n ctx.stroke(path)\n }\n break\n }\n }\n\n // Reset opacity\n if (opacity !== undefined) {\n ctx.globalAlpha = 1\n }\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawRectProps } from '../types'\n\nexport type { DrawRectProps }\n\nexport function DrawRect(props: DrawRectProps) {\n use(() => {\n queueDraw({\n type: 'rect',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawCircleProps } from '../types'\n\nexport type { DrawCircleProps }\n\nexport function DrawCircle(props: DrawCircleProps) {\n use(() => {\n queueDraw({\n type: 'circle',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawArcProps } from '../types'\n\nexport type { DrawArcProps }\n\nexport function DrawArc(props: DrawArcProps) {\n use(() => {\n queueDraw({\n type: 'arc',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawLineProps } from '../types'\n\nexport type { DrawLineProps }\n\nexport function DrawLine(props: DrawLineProps) {\n use(() => {\n queueDraw({\n type: 'line',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawTextProps } from '../types'\n\nexport type { DrawTextProps }\n\nexport function DrawText(props: DrawTextProps) {\n use(() => {\n queueDraw({\n type: 'text',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawPathProps } from '../types'\n\nexport type { DrawPathProps }\n\nexport function DrawPath(props: DrawPathProps) {\n use(() => {\n queueDraw({\n type: 'path',\n props\n })\n })\n\n return null\n}\n"]}
package/dist/canvas.mjs DELETED
@@ -1,2 +0,0 @@
1
- import {c,b as b$1}from'./chunk-3AKECLKA.mjs';import'./chunk-NRPWBHKP.mjs';import'./chunk-MI76R42D.mjs';import {a}from'./chunk-NY6NOGFU.mjs';var D=[];function l(t){D.push(t);}function C(t){let{width:y,height:w,children:e,style:u,ref:a$1}=t,s,n=null,i=()=>{!s||!n||(n.clearRect(0,0,y,w),D.length=0,Array.isArray(e)?e.forEach(o=>{typeof o=="function"&&o();}):typeof e=="function"&&e(),D.forEach(o=>{g(n,o);}),null);};return c(()=>{s&&i();}),a("canvas",{ref:o=>{s=o,n=o.getContext("2d"),a$1&&a$1(o),i();},width:y,height:w,style:u})}function r(t){return b$1(t)?t.valueOf?.()??t:t}function g(t,y){let{type:w,props:e}=y,u=r(e.opacity);switch(u!==void 0&&(t.globalAlpha=u),w){case "rect":{let a=r(e.x),s=r(e.y),n=r(e.width),i=r(e.height),o=r(e.fill),f=r(e.stroke),c=r(e.strokeWidth);o&&(t.fillStyle=o,t.fillRect(a,s,n,i)),f&&(t.strokeStyle=f,c&&(t.lineWidth=c),t.strokeRect(a,s,n,i));break}case "circle":{let a=r(e.x),s=r(e.y),n=r(e.radius),i=r(e.fill),o=r(e.stroke),f=r(e.strokeWidth);t.beginPath(),t.arc(a,s,n,0,Math.PI*2),i&&(t.fillStyle=i,t.fill()),o&&(t.strokeStyle=o,f&&(t.lineWidth=f),t.stroke());break}case "arc":{let a=r(e.x),s=r(e.y),n=r(e.radius),i=r(e.startAngle),o=r(e.endAngle),f=r(e.counterclockwise)||false,c=r(e.fill),m=r(e.stroke),h=r(e.strokeWidth);t.beginPath(),t.arc(a,s,n,i,o,f),c&&(t.fillStyle=c,t.fill()),m&&(t.strokeStyle=m,h&&(t.lineWidth=h),t.stroke());break}case "line":{let a=r(e.x1),s=r(e.y1),n=r(e.x2),i=r(e.y2),o=r(e.stroke)||"black",f=r(e.strokeWidth)||1;t.beginPath(),t.moveTo(a,s),t.lineTo(n,i),t.strokeStyle=o,t.lineWidth=f,t.stroke();break}case "text":{let a=r(e.x),s=r(e.y),n=r(e.text),i=r(e.fill)||"black",o=r(e.fontSize)||16,f=r(e.fontFamily)||"sans-serif",c=r(e.fontWeight)||"normal",m=r(e.textAlign)||"left";t.font=`${c} ${o}px ${f}`,t.textAlign=m,t.fillStyle=i,t.fillText(n,a,s);break}case "path":{let a=r(e.d),s=r(e.fill),n=r(e.stroke),i=r(e.strokeWidth),o=new Path2D(a);s&&(t.fillStyle=s,t.fill(o)),n&&(t.strokeStyle=n,i&&(t.lineWidth=i),t.stroke(o));break}}u!==void 0&&(t.globalAlpha=1);}function x(t){return c(()=>{l({type:"rect",props:t});}),null}function v(t){return c(()=>{l({type:"circle",props:t});}),null}function A(t){return c(()=>{l({type:"arc",props:t});}),null}function W(t){return c(()=>{l({type:"line",props:t});}),null}function b(t){return c(()=>{l({type:"text",props:t});}),null}function R(t){return c(()=>{l({type:"path",props:t});}),null}export{C as Canvas,A as DrawArc,v as DrawCircle,W as DrawLine,R as DrawPath,x as DrawRect,b as DrawText};//# sourceMappingURL=canvas.mjs.map
2
- //# sourceMappingURL=canvas.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/canvas/Canvas.tsx","../src/canvas/dom/DrawRect.tsx","../src/canvas/dom/DrawCircle.tsx","../src/canvas/dom/DrawArc.tsx","../src/canvas/dom/DrawLine.tsx","../src/canvas/dom/DrawText.tsx","../src/canvas/dom/DrawPath.tsx"],"names":["drawQueue","queueDraw","node","Canvas","props","width","height","children","style","ref","canvas","ctx","render","child","drawNode","use","jsx","el","getValue","val","isReactive","type","opacity","x","y","w","h","fill","stroke","strokeWidth","radius","startAngle","endAngle","counterclockwise","x1","y1","x2","y2","text","fontSize","fontFamily","fontWeight","textAlign","d","path","DrawRect","DrawCircle","DrawArc","DrawLine","DrawText","DrawPath"],"mappings":"6IAOA,IACMA,CAAAA,CAA8B,GAM7B,SAASC,CAAAA,CAAUC,CAAAA,CAAsB,CAC9CF,CAAAA,CAAU,KAAKE,CAAI,EACrB,CAEO,SAASC,CAAAA,CAAOC,EAAoB,CACzC,GAAM,CAAE,KAAA,CAAAC,EAAO,MAAA,CAAAC,CAAAA,CAAQ,SAAAC,CAAAA,CAAU,KAAA,CAAAC,EAAO,GAAA,CAAAC,GAAI,CAAA,CAAIL,CAAAA,CAE5CM,EACAC,CAAAA,CAAuC,IAAA,CAErCC,EAAS,IAAM,CACf,CAACF,CAAAA,EAAU,CAACC,CAAAA,GAGhBA,CAAAA,CAAI,UAAU,CAAA,CAAG,CAAA,CAAGN,CAAAA,CAAOC,CAAM,EAGjCN,CAAAA,CAAU,MAAA,CAAS,CAAA,CAMf,KAAA,CAAM,OAAA,CAAQO,CAAQ,CAAA,CACxBA,CAAAA,CAAS,QAAQM,CAAAA,EAAS,CACpB,OAAOA,CAAAA,EAAU,YACnBA,CAAAA,GAEJ,CAAC,CAAA,CACQ,OAAON,GAAa,UAAA,EAC7BA,CAAAA,EAAS,CAIXP,CAAAA,CAAU,QAAQE,CAAAA,EAAQ,CACxBY,EAASH,CAAAA,CAAMT,CAAI,EACrB,CAAC,CAAA,CAGsB,IAAA,EACzB,EAEA,OAAAa,CAAAA,CAAI,IAAM,CACJL,GACFE,CAAAA,GAEJ,CAAC,CAAA,CAGCI,EAAC,QAAA,CAAA,CACC,GAAA,CAAMC,GAA0B,CAC9BP,CAAAA,CAASO,EACTN,CAAAA,CAAMM,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A,GAAY,MAAA,GACdX,CAAAA,CAAI,YAAc,CAAA,EAEtB,CC9NO,SAASkC,CAAAA,CAASzC,EAAsB,CAC7C,OAAAW,EAAI,IAAM,CACRd,EAAU,CACR,IAAA,CAAM,MAAA,CACN,KAAA,CAAAG,CACF,CAAC,EACH,CAAC,CAAA,CAEM,IACT,CCTO,SAAS0C,CAAAA,CAAW1C,CAAAA,CAAwB,CACjD,OAAAW,CAAAA,CAAI,IAAM,CACRd,CAAAA,CAAU,CACR,KAAM,QAAA,CACN,KAAA,CAAAG,CACF,CAAC,EACH,CAAC,CAAA,CAEM,IACT,CCTO,SAAS2C,CAAAA,CAAQ3C,CAAAA,CAAqB,CAC3C,OAAAW,EAAI,IAAM,CACRd,EAAU,CACR,IAAA,CAAM,MACN,KAAA,CAAAG,CACF,CAAC,EACH,CAAC,CAAA,CAEM,IACT,CCTO,SAAS4C,CAAAA,CAAS5C,EAAsB,CAC7C,OAAAW,CAAAA,CAAI,IAAM,CACRd,CAAAA,CAAU,CACR,KAAM,MAAA,CACN,KAAA,CAAAG,CACF,CAAC,EACH,CAAC,CAAA,CAEM,IACT,CCTO,SAAS6C,EAAS7C,CAAAA,CAAsB,CAC7C,OAAAW,CAAAA,CAAI,IAAM,CACRd,CAAAA,CAAU,CACR,IAAA,CAAM,MAAA,CACN,MAAAG,CACF,CAAC,EACH,CAAC,CAAA,CAEM,IACT,CCTO,SAAS8C,CAAAA,CAAS9C,CAAAA,CAAsB,CAC7C,OAAAW,CAAAA,CAAI,IAAM,CACRd,CAAAA,CAAU,CACR,IAAA,CAAM,OACN,KAAA,CAAAG,CACF,CAAC,EACH,CAAC,EAEM,IACT","file":"canvas.mjs","sourcesContent":["import { use } from '../core/use'\nimport { isReactive } from '../core/reactive'\nimport type { CanvasProps, CanvasDrawNode } from './types'\n\nexport type { CanvasProps }\n\n// Canvas context for children to access\nlet currentCanvasContext: CanvasRenderingContext2D | null = null\nconst drawQueue: CanvasDrawNode[] = []\n\nexport function getCanvasContext() {\n return currentCanvasContext\n}\n\nexport function queueDraw(node: CanvasDrawNode) {\n drawQueue.push(node)\n}\n\nexport function Canvas(props: CanvasProps) {\n const { width, height, children, style, ref } = props\n\n let canvas: HTMLCanvasElement | undefined\n let ctx: CanvasRenderingContext2D | null = null\n\n const render = () => {\n if (!canvas || !ctx) return\n\n // Clear canvas\n ctx.clearRect(0, 0, width, height)\n\n // Clear draw queue\n drawQueue.length = 0\n\n // Set current context for children\n currentCanvasContext = ctx\n\n // Render children (they will queue draw commands)\n if (Array.isArray(children)) {\n children.forEach(child => {\n if (typeof child === 'function') {\n child()\n }\n })\n } else if (typeof children === 'function') {\n children()\n }\n\n // Execute draw queue\n drawQueue.forEach(node => {\n drawNode(ctx!, node)\n })\n\n // Clear context\n currentCanvasContext = null\n }\n\n use(() => {\n if (canvas) {\n render()\n }\n })\n\n return (\n <canvas\n ref={(el: HTMLCanvasElement) => {\n canvas = el\n ctx = el.getContext('2d')\n if (ref) ref(el)\n render()\n }}\n width={width}\n height={height}\n style={style}\n />\n )\n}\n\nfunction getValue(val: any): any {\n if (isReactive(val)) {\n return val.valueOf?.() ?? val\n }\n return val\n}\n\nfunction drawNode(ctx: CanvasRenderingContext2D, node: CanvasDrawNode) {\n const { type, props } = node\n\n // Apply opacity\n const opacity = getValue(props.opacity)\n if (opacity !== undefined) {\n ctx.globalAlpha = opacity\n }\n\n switch (type) {\n case 'rect': {\n const x = getValue(props.x)\n const y = getValue(props.y)\n const w = getValue(props.width)\n const h = getValue(props.height)\n const fill = getValue(props.fill)\n const stroke = getValue(props.stroke)\n const strokeWidth = getValue(props.strokeWidth)\n\n if (fill) {\n ctx.fillStyle = fill\n ctx.fillRect(x, y, w, h)\n }\n\n if (stroke) {\n ctx.strokeStyle = stroke\n if (strokeWidth) ctx.lineWidth = strokeWidth\n ctx.strokeRect(x, y, w, h)\n }\n break\n }\n\n case 'circle': {\n const x = getValue(props.x)\n const y = getValue(props.y)\n const radius = getValue(props.radius)\n const fill = getValue(props.fill)\n const stroke = getValue(props.stroke)\n const strokeWidth = getValue(props.strokeWidth)\n\n ctx.beginPath()\n ctx.arc(x, y, radius, 0, Math.PI * 2)\n\n if (fill) {\n ctx.fillStyle = fill\n ctx.fill()\n }\n\n if (stroke) {\n ctx.strokeStyle = stroke\n if (strokeWidth) ctx.lineWidth = strokeWidth\n ctx.stroke()\n }\n break\n }\n\n case 'arc': {\n const x = getValue(props.x)\n const y = getValue(props.y)\n const radius = getValue(props.radius)\n const startAngle = getValue(props.startAngle)\n const endAngle = getValue(props.endAngle)\n const counterclockwise = getValue(props.counterclockwise) || false\n const fill = getValue(props.fill)\n const stroke = getValue(props.stroke)\n const strokeWidth = getValue(props.strokeWidth)\n\n ctx.beginPath()\n ctx.arc(x, y, radius, startAngle, endAngle, counterclockwise)\n\n if (fill) {\n ctx.fillStyle = fill\n ctx.fill()\n }\n\n if (stroke) {\n ctx.strokeStyle = stroke\n if (strokeWidth) ctx.lineWidth = strokeWidth\n ctx.stroke()\n }\n break\n }\n\n case 'line': {\n const x1 = getValue(props.x1)\n const y1 = getValue(props.y1)\n const x2 = getValue(props.x2)\n const y2 = getValue(props.y2)\n const stroke = getValue(props.stroke) || 'black'\n const strokeWidth = getValue(props.strokeWidth) || 1\n\n ctx.beginPath()\n ctx.moveTo(x1, y1)\n ctx.lineTo(x2, y2)\n ctx.strokeStyle = stroke\n ctx.lineWidth = strokeWidth\n ctx.stroke()\n break\n }\n\n case 'text': {\n const x = getValue(props.x)\n const y = getValue(props.y)\n const text = getValue(props.text)\n const fill = getValue(props.fill) || 'black'\n const fontSize = getValue(props.fontSize) || 16\n const fontFamily = getValue(props.fontFamily) || 'sans-serif'\n const fontWeight = getValue(props.fontWeight) || 'normal'\n const textAlign = getValue(props.textAlign) || 'left'\n\n ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`\n ctx.textAlign = textAlign as CanvasTextAlign\n ctx.fillStyle = fill\n ctx.fillText(text, x, y)\n break\n }\n\n case 'path': {\n const d = getValue(props.d)\n const fill = getValue(props.fill)\n const stroke = getValue(props.stroke)\n const strokeWidth = getValue(props.strokeWidth)\n\n // Parse SVG path data\n const path = new Path2D(d)\n\n if (fill) {\n ctx.fillStyle = fill\n ctx.fill(path)\n }\n\n if (stroke) {\n ctx.strokeStyle = stroke\n if (strokeWidth) ctx.lineWidth = strokeWidth\n ctx.stroke(path)\n }\n break\n }\n }\n\n // Reset opacity\n if (opacity !== undefined) {\n ctx.globalAlpha = 1\n }\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawRectProps } from '../types'\n\nexport type { DrawRectProps }\n\nexport function DrawRect(props: DrawRectProps) {\n use(() => {\n queueDraw({\n type: 'rect',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawCircleProps } from '../types'\n\nexport type { DrawCircleProps }\n\nexport function DrawCircle(props: DrawCircleProps) {\n use(() => {\n queueDraw({\n type: 'circle',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawArcProps } from '../types'\n\nexport type { DrawArcProps }\n\nexport function DrawArc(props: DrawArcProps) {\n use(() => {\n queueDraw({\n type: 'arc',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawLineProps } from '../types'\n\nexport type { DrawLineProps }\n\nexport function DrawLine(props: DrawLineProps) {\n use(() => {\n queueDraw({\n type: 'line',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawTextProps } from '../types'\n\nexport type { DrawTextProps }\n\nexport function DrawText(props: DrawTextProps) {\n use(() => {\n queueDraw({\n type: 'text',\n props\n })\n })\n\n return null\n}\n","import { use } from '../../core/use'\nimport { queueDraw } from '../Canvas'\nimport type { DrawPathProps } from '../types'\n\nexport type { DrawPathProps }\n\nexport function DrawPath(props: DrawPathProps) {\n use(() => {\n queueDraw({\n type: 'path',\n props\n })\n })\n\n return null\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/jsx-runtime.ts"],"names":["jsx","type","props","key","children","otherProps","jsxs","Fragment"],"mappings":"aAEO,SAASA,CAAAA,CAAIC,CAAAA,CAAWC,CAAAA,CAAYC,CAAAA,CAAkB,CACzD,GAAM,CAAE,QAAA,CAAAC,CAAAA,CAAU,GAAGC,CAAW,CAAA,CAAIH,CAAAA,EAAS,EAAC,CAC9C,OAAO,CACH,IAAA,CAAAD,CAAAA,CACA,KAAA,CAAOI,CAAAA,CACP,QAAA,CAAU,KAAA,CAAM,OAAA,CAAQD,CAAQ,CAAA,CAAIA,CAAAA,CAAYA,CAAAA,EAAY,KAAO,CAACA,CAAQ,CAAA,CAAI,EAAC,CACjF,GAAA,CAAAD,CACJ,CACJ,CAEO,SAASG,CAAAA,CAAKL,CAAAA,CAAWC,CAAAA,CAAYC,CAAAA,CAAkB,CAC1D,OAAOH,CAAAA,CAAIC,CAAAA,CAAMC,CAAAA,CAAOC,CAAG,CAC/B,CAEO,SAASI,CAAAA,CAASL,CAAAA,CAAwB,CAC7C,OAAOA,CAAAA,CAAM,QACjB","file":"chunk-DUGPBZZ3.js","sourcesContent":["import type { FNode, FNodeChild } from './dom'\n\nexport function jsx(type: any, props: any, key?: any): FNode {\n const { children, ...otherProps } = props || {}\n return {\n type,\n props: otherProps,\n children: Array.isArray(children) ? children : (children != null ? [children] : []),\n key\n }\n}\n\nexport function jsxs(type: any, props: any, key?: any): FNode {\n return jsx(type, props, key)\n}\n\nexport function Fragment(props: any): FNodeChild {\n return props.children\n}\n\nexport namespace JSX {\n export interface IntrinsicElements {\n [elemName: string]: any\n }\n export type Element = FNode | FNodeChild\n export interface ElementChildrenAttribute {\n children: {}\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/jsx-runtime.ts"],"names":["jsx","type","props","key","children","otherProps","jsxs","Fragment"],"mappings":"AAEO,SAASA,CAAAA,CAAIC,CAAAA,CAAWC,CAAAA,CAAYC,CAAAA,CAAkB,CACzD,GAAM,CAAE,QAAA,CAAAC,CAAAA,CAAU,GAAGC,CAAW,CAAA,CAAIH,CAAAA,EAAS,EAAC,CAC9C,OAAO,CACH,IAAA,CAAAD,CAAAA,CACA,KAAA,CAAOI,CAAAA,CACP,QAAA,CAAU,KAAA,CAAM,OAAA,CAAQD,CAAQ,CAAA,CAAIA,CAAAA,CAAYA,CAAAA,EAAY,KAAO,CAACA,CAAQ,CAAA,CAAI,EAAC,CACjF,GAAA,CAAAD,CACJ,CACJ,CAEO,SAASG,CAAAA,CAAKL,CAAAA,CAAWC,CAAAA,CAAYC,CAAAA,CAAkB,CAC1D,OAAOH,CAAAA,CAAIC,CAAAA,CAAMC,CAAAA,CAAOC,CAAG,CAC/B,CAEO,SAASI,CAAAA,CAASL,CAAAA,CAAwB,CAC7C,OAAOA,CAAAA,CAAM,QACjB","file":"chunk-NY6NOGFU.mjs","sourcesContent":["import type { FNode, FNodeChild } from './dom'\n\nexport function jsx(type: any, props: any, key?: any): FNode {\n const { children, ...otherProps } = props || {}\n return {\n type,\n props: otherProps,\n children: Array.isArray(children) ? children : (children != null ? [children] : []),\n key\n }\n}\n\nexport function jsxs(type: any, props: any, key?: any): FNode {\n return jsx(type, props, key)\n}\n\nexport function Fragment(props: any): FNodeChild {\n return props.children\n}\n\nexport namespace JSX {\n export interface IntrinsicElements {\n [elemName: string]: any\n }\n export type Element = FNode | FNodeChild\n export interface ElementChildrenAttribute {\n children: {}\n }\n}\n"]}
@@ -1,84 +0,0 @@
1
- declare enum Keys {
2
- ArrowUp = "ArrowUp",
3
- ArrowDown = "ArrowDown",
4
- ArrowLeft = "ArrowLeft",
5
- ArrowRight = "ArrowRight",
6
- KeyW = "KeyW",
7
- KeyA = "KeyA",
8
- KeyS = "KeyS",
9
- KeyD = "KeyD",
10
- Space = "Space",
11
- Enter = "Enter",
12
- Escape = "Escape",
13
- Tab = "Tab",
14
- ShiftLeft = "ShiftLeft",
15
- ShiftRight = "ShiftRight",
16
- ControlLeft = "ControlLeft",
17
- ControlRight = "ControlRight",
18
- AltLeft = "AltLeft",
19
- AltRight = "AltRight",
20
- Digit0 = "Digit0",
21
- Digit1 = "Digit1",
22
- Digit2 = "Digit2",
23
- Digit3 = "Digit3",
24
- Digit4 = "Digit4",
25
- Digit5 = "Digit5",
26
- Digit6 = "Digit6",
27
- Digit7 = "Digit7",
28
- Digit8 = "Digit8",
29
- Digit9 = "Digit9",
30
- KeyE = "KeyE",
31
- KeyQ = "KeyQ",
32
- KeyR = "KeyR",
33
- KeyF = "KeyF"
34
- }
35
- interface KeyboardState {
36
- isPressed: (key: string) => boolean;
37
- isJustPressed: (key: string) => boolean;
38
- isJustReleased: (key: string) => boolean;
39
- getPressedKeys: () => string[];
40
- clearFrameState: () => void;
41
- dispose: () => void;
42
- }
43
- declare enum MouseButton {
44
- Left = 0,
45
- Middle = 1,
46
- Right = 2
47
- }
48
- interface MouseOptions {
49
- canvas?: HTMLCanvasElement | (() => HTMLCanvasElement | undefined);
50
- target?: EventTarget;
51
- }
52
- interface MouseState {
53
- x: number | null;
54
- y: number | null;
55
- deltaX: number;
56
- deltaY: number;
57
- wheelDelta: number;
58
- isPressed: (button: MouseButton) => boolean;
59
- isLeftPressed: () => boolean;
60
- isRightPressed: () => boolean;
61
- isMiddlePressed: () => boolean;
62
- clearFrameState: () => void;
63
- dispose: () => void;
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 useLoop(callbacks: LoopCallbacks): Loop;
79
-
80
- declare function useKeyboard(target?: EventTarget): KeyboardState;
81
-
82
- declare function useMouse(options?: MouseOptions): MouseState;
83
-
84
- export { type KeyboardState, Keys, type Loop, type LoopCallbacks, MouseButton, type MouseOptions, type MouseState, useKeyboard, useLoop, useMouse };
@@ -1,84 +0,0 @@
1
- declare enum Keys {
2
- ArrowUp = "ArrowUp",
3
- ArrowDown = "ArrowDown",
4
- ArrowLeft = "ArrowLeft",
5
- ArrowRight = "ArrowRight",
6
- KeyW = "KeyW",
7
- KeyA = "KeyA",
8
- KeyS = "KeyS",
9
- KeyD = "KeyD",
10
- Space = "Space",
11
- Enter = "Enter",
12
- Escape = "Escape",
13
- Tab = "Tab",
14
- ShiftLeft = "ShiftLeft",
15
- ShiftRight = "ShiftRight",
16
- ControlLeft = "ControlLeft",
17
- ControlRight = "ControlRight",
18
- AltLeft = "AltLeft",
19
- AltRight = "AltRight",
20
- Digit0 = "Digit0",
21
- Digit1 = "Digit1",
22
- Digit2 = "Digit2",
23
- Digit3 = "Digit3",
24
- Digit4 = "Digit4",
25
- Digit5 = "Digit5",
26
- Digit6 = "Digit6",
27
- Digit7 = "Digit7",
28
- Digit8 = "Digit8",
29
- Digit9 = "Digit9",
30
- KeyE = "KeyE",
31
- KeyQ = "KeyQ",
32
- KeyR = "KeyR",
33
- KeyF = "KeyF"
34
- }
35
- interface KeyboardState {
36
- isPressed: (key: string) => boolean;
37
- isJustPressed: (key: string) => boolean;
38
- isJustReleased: (key: string) => boolean;
39
- getPressedKeys: () => string[];
40
- clearFrameState: () => void;
41
- dispose: () => void;
42
- }
43
- declare enum MouseButton {
44
- Left = 0,
45
- Middle = 1,
46
- Right = 2
47
- }
48
- interface MouseOptions {
49
- canvas?: HTMLCanvasElement | (() => HTMLCanvasElement | undefined);
50
- target?: EventTarget;
51
- }
52
- interface MouseState {
53
- x: number | null;
54
- y: number | null;
55
- deltaX: number;
56
- deltaY: number;
57
- wheelDelta: number;
58
- isPressed: (button: MouseButton) => boolean;
59
- isLeftPressed: () => boolean;
60
- isRightPressed: () => boolean;
61
- isMiddlePressed: () => boolean;
62
- clearFrameState: () => void;
63
- dispose: () => void;
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 useLoop(callbacks: LoopCallbacks): Loop;
79
-
80
- declare function useKeyboard(target?: EventTarget): KeyboardState;
81
-
82
- declare function useMouse(options?: MouseOptions): MouseState;
83
-
84
- export { type KeyboardState, Keys, type Loop, type LoopCallbacks, MouseButton, type MouseOptions, type MouseState, useKeyboard, useLoop, useMouse };
@@ -1,2 +0,0 @@
1
- 'use strict';var chunkACYN2UKT_js=require('./chunk-ACYN2UKT.js');require('./chunk-3CKIHQIE.js'),require('./chunk-E6Z7AI4J.js');function F(a){let{fixedFps:n=60,onUpdate:v,onFixedUpdate:o,onRender:y}=a,p=1/n,S=.25,l=false,m=0,t=0,s=0,i=0,u=0,r=null;function d(w){if(!l)return;let D=Math.min((w-m)/1e3,S);if(m=w,v&&v(D),o)for(t+=D;t>=p;)o(p),t-=p;if(y){let h=t/p;y(h);}i++,w-u>=1e3&&(s=i,i=0,u=w),r=requestAnimationFrame(d);}return {start:()=>{l||(l=true,m=performance.now(),t=0,r=requestAnimationFrame(d));},stop:()=>{l=false,r!==null&&(cancelAnimationFrame(r),r=null);},isRunning:()=>l,getFps:()=>s}}var x=(e=>(e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.ArrowLeft="ArrowLeft",e.ArrowRight="ArrowRight",e.KeyW="KeyW",e.KeyA="KeyA",e.KeyS="KeyS",e.KeyD="KeyD",e.Space="Space",e.Enter="Enter",e.Escape="Escape",e.Tab="Tab",e.ShiftLeft="ShiftLeft",e.ShiftRight="ShiftRight",e.ControlLeft="ControlLeft",e.ControlRight="ControlRight",e.AltLeft="AltLeft",e.AltRight="AltRight",e.Digit0="Digit0",e.Digit1="Digit1",e.Digit2="Digit2",e.Digit3="Digit3",e.Digit4="Digit4",e.Digit5="Digit5",e.Digit6="Digit6",e.Digit7="Digit7",e.Digit8="Digit8",e.Digit9="Digit9",e.KeyE="KeyE",e.KeyQ="KeyQ",e.KeyR="KeyR",e.KeyF="KeyF",e))(x||{}),P=(o=>(o[o.Left=0]="Left",o[o.Middle=1]="Middle",o[o.Right=2]="Right",o))(P||{});function C(a=window){let[n,v]=chunkACYN2UKT_js.c(new Set,{key:["keyboard","pressed"]}),[o,y]=chunkACYN2UKT_js.c(new Set,{key:["keyboard","justPressed"]}),[p,S]=chunkACYN2UKT_js.c(new Set,{key:["keyboard","justReleased"]}),l=t=>{let s=t.code,i=n;if(!i.has(s)){let u=new Set(i);u.add(s),v(u);let r=o,d=new Set(r);d.add(s),y(d);}},m=t=>{let s=t.code,i=n,u=new Set(i);u.delete(s),v(u);let r=p,d=new Set(r);d.add(s),S(d);};return a.addEventListener("keydown",l),a.addEventListener("keyup",m),{isPressed:t=>n?.has(t)||false,isJustPressed:t=>o?.has(t)||false,isJustReleased:t=>p?.has(t)||false,getPressedKeys:()=>Array.from(n||[]),clearFrameState:()=>{y(new Set),S(new Set);},dispose:()=>{a.removeEventListener("keydown",l),a.removeEventListener("keyup",m);}}}function J(a={}){let n=a.target||window,v=typeof a.canvas=="function"?a.canvas:()=>a.canvas,[o,y]=chunkACYN2UKT_js.c({x:0,y:0},{key:["mouse","position"]}),[p,S]=chunkACYN2UKT_js.c({x:0,y:0},{key:["mouse","delta"]}),[l,m]=chunkACYN2UKT_js.c(0,{key:["mouse","wheel"]}),[t,s]=chunkACYN2UKT_js.c(new Set,{key:["mouse","buttons"]}),i=0,u=0,r=g=>{let f=g,L=v(),c=f.clientX,E=f.clientY;if(L){let k=L.getBoundingClientRect();c=f.clientX-k.left,E=f.clientY-k.top;}y({x:c,y:E}),S({x:c-i,y:E-u}),i=c,u=E;},d=g=>{let f=g.button,L=t,c=new Set(L);c.add(f),s(c);},w=g=>{let f=g.button,L=t,c=new Set(L);c.delete(f),s(c);},D=g=>{m(g.deltaY);};n.addEventListener("mousemove",r),n.addEventListener("mousedown",d),n.addEventListener("mouseup",w),n.addEventListener("wheel",D);let h=t,R=o,M=p,A=l;return {get x(){return R.x},get y(){return R.y},get deltaX(){return M.x},get deltaY(){return M.y},get wheelDelta(){return A},isPressed:g=>h?.has(g)||false,isLeftPressed:()=>h?.has(0)||false,isRightPressed:()=>h?.has(2)||false,isMiddlePressed:()=>h?.has(1)||false,clearFrameState:()=>{S({x:0,y:0}),m(0);},dispose:()=>{n.removeEventListener("mousemove",r),n.removeEventListener("mousedown",d),n.removeEventListener("mouseup",w),n.removeEventListener("wheel",D);}}}exports.Keys=x;exports.MouseButton=P;exports.useKeyboard=C;exports.useLoop=F;exports.useMouse=J;//# sourceMappingURL=interactive.js.map
2
- //# sourceMappingURL=interactive.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/interactive/loop.ts","../src/interactive/types.ts","../src/interactive/keyboard.ts","../src/interactive/mouse.ts"],"names":["useLoop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","loop","currentTime","delta","alpha","Keys","MouseButton","useKeyboard","target","pressedKeys","setPressedKeys","use","justPressedKeys","setJustPressedKeys","justReleasedKeys","setJustReleasedKeys","handleKeyDown","e","key","currentPressed","newPressed","currentJustPressed","newJustPressed","handleKeyUp","currentJustReleased","newJustReleased","useMouse","options","canvasGetter","position","setPosition","setDelta","wheelDelta","setWheelDelta","buttons","setButtons","lastX","lastY","handleMouseMove","me","canvas","x","y","rect","handleMouseDown","button","currentButtons","newButtons","handleMouseUp","handleWheel","currentPosition","currentDelta","currentWheelDelta"],"mappings":"+HAIO,SAASA,CAAAA,CAAQC,EAAgC,CACtD,GAAM,CAAE,QAAA,CAAAC,CAAAA,CAAW,GAAI,QAAA,CAAAC,CAAAA,CAAU,cAAAC,CAAAA,CAAe,QAAA,CAAAC,CAAS,CAAA,C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G,EAAG,CAAA,CAAG,CAAE,CAAC,CAAA,CACvBE,CAAAA,CAAc,CAAC,EACjB,CAAA,CAEA,OAAA,CAAS,IAAM,CACbzB,CAAAA,CAAO,oBAAoB,WAAA,CAAa8B,CAAe,EACvD9B,CAAAA,CAAO,mBAAA,CAAoB,YAAaoC,CAAe,CAAA,CACvDpC,EAAO,mBAAA,CAAoB,SAAA,CAAWwC,CAAa,CAAA,CACnDxC,CAAAA,CAAO,oBAAoB,OAAA,CAASyC,CAAW,EACjD,CACF,CACF","file":"interactive.js","sourcesContent":["import type { LoopCallbacks, Loop } from './types'\n\nexport type { LoopCallbacks, Loop }\n\nexport function useLoop(callbacks: LoopCallbacks): Loop {\n const { fixedFps = 60, onUpdate, onFixedUpdate, onRender } = callbacks\n\n const fixedDelta = 1 / fixedFps\n const maxDelta = 0.25 // Cap delta at 250ms to prevent spiral of death\n\n let running = false\n let lastTime = 0\n let accumulator = 0\n let fps = 0\n let frameCount = 0\n let fpsTime = 0\n let rafId: number | null = null\n\n function loop(currentTime: number) {\n if (!running) return\n\n // Calculate delta in seconds\n const delta = Math.min((currentTime - lastTime) / 1000, maxDelta)\n lastTime = currentTime\n\n // Variable timestep update\n if (onUpdate) {\n onUpdate(delta)\n }\n\n // Fixed timestep update\n if (onFixedUpdate) {\n accumulator += delta\n\n while (accumulator >= fixedDelta) {\n onFixedUpdate(fixedDelta)\n accumulator -= fixedDelta\n }\n }\n\n // Render with interpolation alpha\n if (onRender) {\n const alpha = accumulator / fixedDelta\n onRender(alpha)\n }\n\n // FPS calculation\n frameCount++\n if (currentTime - fpsTime >= 1000) {\n fps = frameCount\n frameCount = 0\n fpsTime = currentTime\n }\n\n rafId = requestAnimationFrame(loop)\n }\n\n return {\n start: () => {\n if (running) return\n running = true\n lastTime = performance.now()\n accumulator = 0\n rafId = requestAnimationFrame(loop)\n },\n\n stop: () => {\n running = false\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n },\n\n isRunning: () => running,\n\n getFps: () => fps\n }\n}\n","// Keyboard types\nexport enum Keys {\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n KeyW = 'KeyW',\n KeyA = 'KeyA',\n KeyS = 'KeyS',\n KeyD = 'KeyD',\n Space = 'Space',\n Enter = 'Enter',\n Escape = 'Escape',\n Tab = 'Tab',\n ShiftLeft = 'ShiftLeft',\n ShiftRight = 'ShiftRight',\n ControlLeft = 'ControlLeft',\n ControlRight = 'ControlRight',\n AltLeft = 'AltLeft',\n AltRight = 'AltRight',\n Digit0 = 'Digit0',\n Digit1 = 'Digit1',\n Digit2 = 'Digit2',\n Digit3 = 'Digit3',\n Digit4 = 'Digit4',\n Digit5 = 'Digit5',\n Digit6 = 'Digit6',\n Digit7 = 'Digit7',\n Digit8 = 'Digit8',\n Digit9 = 'Digit9',\n KeyE = 'KeyE',\n KeyQ = 'KeyQ',\n KeyR = 'KeyR',\n KeyF = 'KeyF',\n}\n\nexport interface KeyboardState {\n isPressed: (key: string) => boolean\n isJustPressed: (key: string) => boolean\n isJustReleased: (key: string) => boolean\n getPressedKeys: () => string[]\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Mouse types\nexport enum MouseButton {\n Left = 0,\n Middle = 1,\n Right = 2\n}\n\nexport interface MouseOptions {\n canvas?: HTMLCanvasElement | (() => HTMLCanvasElement | undefined)\n target?: EventTarget\n}\n\nexport interface MouseState {\n x: number | null\n y: number | null\n deltaX: number\n deltaY: number\n wheelDelta: number\n isPressed: (button: MouseButton) => boolean\n isLeftPressed: () => boolean\n isRightPressed: () => boolean\n isMiddlePressed: () => boolean\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Loop types\nexport interface LoopCallbacks {\n fixedFps?: number\n onUpdate?: (delta: number) => void\n onFixedUpdate?: (fixedDelta: number) => void\n onRender?: (alpha: number) => void\n}\n\nexport interface Loop {\n start: () => void\n stop: () => void\n isRunning: () => boolean\n getFps: () => number\n}\n","import { use } from '../core/use'\nimport { Keys, type KeyboardState } from './types'\n\nexport { Keys, type KeyboardState }\n\nexport function useKeyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justReleased'] })\n\n const handleKeyDown = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n if (!currentPressed.has(key)) {\n const newPressed = new Set(currentPressed)\n newPressed.add(key)\n setPressedKeys(newPressed)\n\n const currentJustPressed = justPressedKeys as Set<string>\n const newJustPressed = new Set(currentJustPressed)\n newJustPressed.add(key)\n setJustPressedKeys(newJustPressed)\n }\n }\n\n const handleKeyUp = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n const newPressed = new Set(currentPressed)\n newPressed.delete(key)\n setPressedKeys(newPressed)\n\n const currentJustReleased = justReleasedKeys as Set<string>\n const newJustReleased = new Set(currentJustReleased)\n newJustReleased.add(key)\n setJustReleasedKeys(newJustReleased)\n }\n\n target.addEventListener('keydown', handleKeyDown)\n target.addEventListener('keyup', handleKeyUp)\n\n return {\n isPressed: (key: string) => {\n const current = pressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustPressed: (key: string) => {\n const current = justPressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustReleased: (key: string) => {\n const current = justReleasedKeys as Set<string>\n return current?.has(key) || false\n },\n\n getPressedKeys: () => {\n const current = pressedKeys as Set<string>\n return Array.from(current || [])\n },\n\n clearFrameState: () => {\n setJustPressedKeys(new Set<string>())\n setJustReleasedKeys(new Set<string>())\n },\n\n dispose: () => {\n target.removeEventListener('keydown', handleKeyDown)\n target.removeEventListener('keyup', handleKeyUp)\n }\n }\n}\n","import { use } from '../core/use'\nimport { MouseButton, type MouseOptions, type MouseState } from './types'\n\nexport { MouseButton, type MouseOptions, type MouseState }\n\nexport function useMouse(options: MouseOptions = {}): MouseState {\n const target = options.target || window\n const canvasGetter = typeof options.canvas === 'function' ? options.canvas : () => options.canvas as HTMLCanvasElement | undefined\n\n const [position, setPosition] = use({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = use({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = use(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = use<Set<number>>(new Set<number>(), { key: ['mouse', 'buttons'] })\n\n let lastX = 0\n let lastY = 0\n\n const handleMouseMove = (e: Event) => {\n const me = e as MouseEvent\n const canvas = canvasGetter()\n\n let x = me.clientX\n let y = me.clientY\n\n // If canvas is provided, calculate position relative to canvas\n if (canvas) {\n const rect = canvas.getBoundingClientRect()\n x = me.clientX - rect.left\n y = me.clientY - rect.top\n }\n\n setPosition({ x, y })\n setDelta({ x: x - lastX, y: y - lastY })\n lastX = x\n lastY = y\n }\n\n const handleMouseDown = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.add(button)\n setButtons(newButtons)\n }\n\n const handleMouseUp = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.delete(button)\n setButtons(newButtons)\n }\n\n const handleWheel = (e: Event) => {\n const we = e as WheelEvent\n setWheelDelta(we.deltaY)\n }\n\n target.addEventListener('mousemove', handleMouseMove)\n target.addEventListener('mousedown', handleMouseDown)\n target.addEventListener('mouseup', handleMouseUp)\n target.addEventListener('wheel', handleWheel)\n\n const currentButtons = buttons as Set<number>\n const currentPosition = position as { x: number; y: number }\n const currentDelta = delta as { x: number; y: number }\n const currentWheelDelta = wheelDelta as number\n\n return {\n get x() { return currentPosition.x },\n get y() { return currentPosition.y },\n get deltaX() { return currentDelta.x },\n get deltaY() { return currentDelta.y },\n get wheelDelta() { return currentWheelDelta },\n\n isPressed: (button: MouseButton) => currentButtons?.has(button) || false,\n\n isLeftPressed: () => currentButtons?.has(MouseButton.Left) || false,\n\n isRightPressed: () => currentButtons?.has(MouseButton.Right) || false,\n\n isMiddlePressed: () => currentButtons?.has(MouseButton.Middle) || false,\n\n clearFrameState: () => {\n setDelta({ x: 0, y: 0 })\n setWheelDelta(0)\n },\n\n dispose: () => {\n target.removeEventListener('mousemove', handleMouseMove)\n target.removeEventListener('mousedown', handleMouseDown)\n target.removeEventListener('mouseup', handleMouseUp)\n target.removeEventListener('wheel', handleWheel)\n }\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- import {c}from'./chunk-3AKECLKA.mjs';import'./chunk-NRPWBHKP.mjs';import'./chunk-MI76R42D.mjs';function F(a){let{fixedFps:n=60,onUpdate:v,onFixedUpdate:o,onRender:y}=a,p=1/n,S=.25,l=false,m=0,t=0,s=0,i=0,u=0,r=null;function d(w){if(!l)return;let D=Math.min((w-m)/1e3,S);if(m=w,v&&v(D),o)for(t+=D;t>=p;)o(p),t-=p;if(y){let h=t/p;y(h);}i++,w-u>=1e3&&(s=i,i=0,u=w),r=requestAnimationFrame(d);}return {start:()=>{l||(l=true,m=performance.now(),t=0,r=requestAnimationFrame(d));},stop:()=>{l=false,r!==null&&(cancelAnimationFrame(r),r=null);},isRunning:()=>l,getFps:()=>s}}var x=(e=>(e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.ArrowLeft="ArrowLeft",e.ArrowRight="ArrowRight",e.KeyW="KeyW",e.KeyA="KeyA",e.KeyS="KeyS",e.KeyD="KeyD",e.Space="Space",e.Enter="Enter",e.Escape="Escape",e.Tab="Tab",e.ShiftLeft="ShiftLeft",e.ShiftRight="ShiftRight",e.ControlLeft="ControlLeft",e.ControlRight="ControlRight",e.AltLeft="AltLeft",e.AltRight="AltRight",e.Digit0="Digit0",e.Digit1="Digit1",e.Digit2="Digit2",e.Digit3="Digit3",e.Digit4="Digit4",e.Digit5="Digit5",e.Digit6="Digit6",e.Digit7="Digit7",e.Digit8="Digit8",e.Digit9="Digit9",e.KeyE="KeyE",e.KeyQ="KeyQ",e.KeyR="KeyR",e.KeyF="KeyF",e))(x||{}),P=(o=>(o[o.Left=0]="Left",o[o.Middle=1]="Middle",o[o.Right=2]="Right",o))(P||{});function C(a=window){let[n,v]=c(new Set,{key:["keyboard","pressed"]}),[o,y]=c(new Set,{key:["keyboard","justPressed"]}),[p,S]=c(new Set,{key:["keyboard","justReleased"]}),l=t=>{let s=t.code,i=n;if(!i.has(s)){let u=new Set(i);u.add(s),v(u);let r=o,d=new Set(r);d.add(s),y(d);}},m=t=>{let s=t.code,i=n,u=new Set(i);u.delete(s),v(u);let r=p,d=new Set(r);d.add(s),S(d);};return a.addEventListener("keydown",l),a.addEventListener("keyup",m),{isPressed:t=>n?.has(t)||false,isJustPressed:t=>o?.has(t)||false,isJustReleased:t=>p?.has(t)||false,getPressedKeys:()=>Array.from(n||[]),clearFrameState:()=>{y(new Set),S(new Set);},dispose:()=>{a.removeEventListener("keydown",l),a.removeEventListener("keyup",m);}}}function J(a={}){let n=a.target||window,v=typeof a.canvas=="function"?a.canvas:()=>a.canvas,[o,y]=c({x:0,y:0},{key:["mouse","position"]}),[p,S]=c({x:0,y:0},{key:["mouse","delta"]}),[l,m]=c(0,{key:["mouse","wheel"]}),[t,s]=c(new Set,{key:["mouse","buttons"]}),i=0,u=0,r=g=>{let f=g,L=v(),c=f.clientX,E=f.clientY;if(L){let k=L.getBoundingClientRect();c=f.clientX-k.left,E=f.clientY-k.top;}y({x:c,y:E}),S({x:c-i,y:E-u}),i=c,u=E;},d=g=>{let f=g.button,L=t,c=new Set(L);c.add(f),s(c);},w=g=>{let f=g.button,L=t,c=new Set(L);c.delete(f),s(c);},D=g=>{m(g.deltaY);};n.addEventListener("mousemove",r),n.addEventListener("mousedown",d),n.addEventListener("mouseup",w),n.addEventListener("wheel",D);let h=t,R=o,M=p,A=l;return {get x(){return R.x},get y(){return R.y},get deltaX(){return M.x},get deltaY(){return M.y},get wheelDelta(){return A},isPressed:g=>h?.has(g)||false,isLeftPressed:()=>h?.has(0)||false,isRightPressed:()=>h?.has(2)||false,isMiddlePressed:()=>h?.has(1)||false,clearFrameState:()=>{S({x:0,y:0}),m(0);},dispose:()=>{n.removeEventListener("mousemove",r),n.removeEventListener("mousedown",d),n.removeEventListener("mouseup",w),n.removeEventListener("wheel",D);}}}export{x as Keys,P as MouseButton,C as useKeyboard,F as useLoop,J as useMouse};//# sourceMappingURL=interactive.mjs.map
2
- //# sourceMappingURL=interactive.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/interactive/loop.ts","../src/interactive/types.ts","../src/interactive/keyboard.ts","../src/interactive/mouse.ts"],"names":["useLoop","callbacks","fixedFps","onUpdate","onFixedUpdate","onRender","fixedDelta","maxDelta","running","lastTime","accumulator","fps","frameCount","fpsTime","rafId","loop","currentTime","delta","alpha","Keys","MouseButton","useKeyboard","target","pressedKeys","setPressedKeys","use","justPressedKeys","setJustPressedKeys","justReleasedKeys","setJustReleasedKeys","handleKeyDown","e","key","currentPressed","newPressed","currentJustPressed","newJustPressed","handleKeyUp","currentJustReleased","newJustReleased","useMouse","options","canvasGetter","position","setPosition","setDelta","wheelDelta","setWheelDelta","buttons","setButtons","lastX","lastY","handleMouseMove","me","canvas","x","y","rect","handleMouseDown","button","currentButtons","newButtons","handleMouseUp","handleWheel","currentPosition","currentDelta","currentWheelDelta"],"mappings":"+FAIO,SAASA,CAAAA,CAAQC,EAAgC,CACtD,GAAM,CAAE,QAAA,CAAAC,CAAAA,CAAW,GAAI,QAAA,CAAAC,CAAAA,CAAU,cAAAC,CAAAA,CAAe,QAAA,CAAAC,CAAS,CAAA,CAAIJ,CAAAA,CAEvDK,EAAa,CAAA,CAAIJ,CAAAA,CACjBK,EAAW,GAAA,CAEbC,CAAAA,C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,IAAM,CACbzB,CAAAA,CAAO,oBAAoB,WAAA,CAAa8B,CAAe,EACvD9B,CAAAA,CAAO,mBAAA,CAAoB,YAAaoC,CAAe,CAAA,CACvDpC,EAAO,mBAAA,CAAoB,SAAA,CAAWwC,CAAa,CAAA,CACnDxC,CAAAA,CAAO,oBAAoB,OAAA,CAASyC,CAAW,EACjD,CACF,CACF","file":"interactive.mjs","sourcesContent":["import type { LoopCallbacks, Loop } from './types'\n\nexport type { LoopCallbacks, Loop }\n\nexport function useLoop(callbacks: LoopCallbacks): Loop {\n const { fixedFps = 60, onUpdate, onFixedUpdate, onRender } = callbacks\n\n const fixedDelta = 1 / fixedFps\n const maxDelta = 0.25 // Cap delta at 250ms to prevent spiral of death\n\n let running = false\n let lastTime = 0\n let accumulator = 0\n let fps = 0\n let frameCount = 0\n let fpsTime = 0\n let rafId: number | null = null\n\n function loop(currentTime: number) {\n if (!running) return\n\n // Calculate delta in seconds\n const delta = Math.min((currentTime - lastTime) / 1000, maxDelta)\n lastTime = currentTime\n\n // Variable timestep update\n if (onUpdate) {\n onUpdate(delta)\n }\n\n // Fixed timestep update\n if (onFixedUpdate) {\n accumulator += delta\n\n while (accumulator >= fixedDelta) {\n onFixedUpdate(fixedDelta)\n accumulator -= fixedDelta\n }\n }\n\n // Render with interpolation alpha\n if (onRender) {\n const alpha = accumulator / fixedDelta\n onRender(alpha)\n }\n\n // FPS calculation\n frameCount++\n if (currentTime - fpsTime >= 1000) {\n fps = frameCount\n frameCount = 0\n fpsTime = currentTime\n }\n\n rafId = requestAnimationFrame(loop)\n }\n\n return {\n start: () => {\n if (running) return\n running = true\n lastTime = performance.now()\n accumulator = 0\n rafId = requestAnimationFrame(loop)\n },\n\n stop: () => {\n running = false\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n },\n\n isRunning: () => running,\n\n getFps: () => fps\n }\n}\n","// Keyboard types\nexport enum Keys {\n ArrowUp = 'ArrowUp',\n ArrowDown = 'ArrowDown',\n ArrowLeft = 'ArrowLeft',\n ArrowRight = 'ArrowRight',\n KeyW = 'KeyW',\n KeyA = 'KeyA',\n KeyS = 'KeyS',\n KeyD = 'KeyD',\n Space = 'Space',\n Enter = 'Enter',\n Escape = 'Escape',\n Tab = 'Tab',\n ShiftLeft = 'ShiftLeft',\n ShiftRight = 'ShiftRight',\n ControlLeft = 'ControlLeft',\n ControlRight = 'ControlRight',\n AltLeft = 'AltLeft',\n AltRight = 'AltRight',\n Digit0 = 'Digit0',\n Digit1 = 'Digit1',\n Digit2 = 'Digit2',\n Digit3 = 'Digit3',\n Digit4 = 'Digit4',\n Digit5 = 'Digit5',\n Digit6 = 'Digit6',\n Digit7 = 'Digit7',\n Digit8 = 'Digit8',\n Digit9 = 'Digit9',\n KeyE = 'KeyE',\n KeyQ = 'KeyQ',\n KeyR = 'KeyR',\n KeyF = 'KeyF',\n}\n\nexport interface KeyboardState {\n isPressed: (key: string) => boolean\n isJustPressed: (key: string) => boolean\n isJustReleased: (key: string) => boolean\n getPressedKeys: () => string[]\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Mouse types\nexport enum MouseButton {\n Left = 0,\n Middle = 1,\n Right = 2\n}\n\nexport interface MouseOptions {\n canvas?: HTMLCanvasElement | (() => HTMLCanvasElement | undefined)\n target?: EventTarget\n}\n\nexport interface MouseState {\n x: number | null\n y: number | null\n deltaX: number\n deltaY: number\n wheelDelta: number\n isPressed: (button: MouseButton) => boolean\n isLeftPressed: () => boolean\n isRightPressed: () => boolean\n isMiddlePressed: () => boolean\n clearFrameState: () => void\n dispose: () => void\n}\n\n// Loop types\nexport interface LoopCallbacks {\n fixedFps?: number\n onUpdate?: (delta: number) => void\n onFixedUpdate?: (fixedDelta: number) => void\n onRender?: (alpha: number) => void\n}\n\nexport interface Loop {\n start: () => void\n stop: () => void\n isRunning: () => boolean\n getFps: () => number\n}\n","import { use } from '../core/use'\nimport { Keys, type KeyboardState } from './types'\n\nexport { Keys, type KeyboardState }\n\nexport function useKeyboard(target: EventTarget = window): KeyboardState {\n const [pressedKeys, setPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'pressed'] })\n const [justPressedKeys, setJustPressedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justPressed'] })\n const [justReleasedKeys, setJustReleasedKeys] = use<Set<string>>(new Set<string>(), { key: ['keyboard', 'justReleased'] })\n\n const handleKeyDown = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n if (!currentPressed.has(key)) {\n const newPressed = new Set(currentPressed)\n newPressed.add(key)\n setPressedKeys(newPressed)\n\n const currentJustPressed = justPressedKeys as Set<string>\n const newJustPressed = new Set(currentJustPressed)\n newJustPressed.add(key)\n setJustPressedKeys(newJustPressed)\n }\n }\n\n const handleKeyUp = (e: Event) => {\n const key = (e as KeyboardEvent).code\n const currentPressed = pressedKeys as Set<string>\n\n const newPressed = new Set(currentPressed)\n newPressed.delete(key)\n setPressedKeys(newPressed)\n\n const currentJustReleased = justReleasedKeys as Set<string>\n const newJustReleased = new Set(currentJustReleased)\n newJustReleased.add(key)\n setJustReleasedKeys(newJustReleased)\n }\n\n target.addEventListener('keydown', handleKeyDown)\n target.addEventListener('keyup', handleKeyUp)\n\n return {\n isPressed: (key: string) => {\n const current = pressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustPressed: (key: string) => {\n const current = justPressedKeys as Set<string>\n return current?.has(key) || false\n },\n\n isJustReleased: (key: string) => {\n const current = justReleasedKeys as Set<string>\n return current?.has(key) || false\n },\n\n getPressedKeys: () => {\n const current = pressedKeys as Set<string>\n return Array.from(current || [])\n },\n\n clearFrameState: () => {\n setJustPressedKeys(new Set<string>())\n setJustReleasedKeys(new Set<string>())\n },\n\n dispose: () => {\n target.removeEventListener('keydown', handleKeyDown)\n target.removeEventListener('keyup', handleKeyUp)\n }\n }\n}\n","import { use } from '../core/use'\nimport { MouseButton, type MouseOptions, type MouseState } from './types'\n\nexport { MouseButton, type MouseOptions, type MouseState }\n\nexport function useMouse(options: MouseOptions = {}): MouseState {\n const target = options.target || window\n const canvasGetter = typeof options.canvas === 'function' ? options.canvas : () => options.canvas as HTMLCanvasElement | undefined\n\n const [position, setPosition] = use({ x: 0, y: 0 }, { key: ['mouse', 'position'] })\n const [delta, setDelta] = use({ x: 0, y: 0 }, { key: ['mouse', 'delta'] })\n const [wheelDelta, setWheelDelta] = use(0, { key: ['mouse', 'wheel'] })\n const [buttons, setButtons] = use<Set<number>>(new Set<number>(), { key: ['mouse', 'buttons'] })\n\n let lastX = 0\n let lastY = 0\n\n const handleMouseMove = (e: Event) => {\n const me = e as MouseEvent\n const canvas = canvasGetter()\n\n let x = me.clientX\n let y = me.clientY\n\n // If canvas is provided, calculate position relative to canvas\n if (canvas) {\n const rect = canvas.getBoundingClientRect()\n x = me.clientX - rect.left\n y = me.clientY - rect.top\n }\n\n setPosition({ x, y })\n setDelta({ x: x - lastX, y: y - lastY })\n lastX = x\n lastY = y\n }\n\n const handleMouseDown = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.add(button)\n setButtons(newButtons)\n }\n\n const handleMouseUp = (e: Event) => {\n const button = (e as MouseEvent).button\n const currentButtons = buttons as Set<number>\n const newButtons = new Set(currentButtons)\n newButtons.delete(button)\n setButtons(newButtons)\n }\n\n const handleWheel = (e: Event) => {\n const we = e as WheelEvent\n setWheelDelta(we.deltaY)\n }\n\n target.addEventListener('mousemove', handleMouseMove)\n target.addEventListener('mousedown', handleMouseDown)\n target.addEventListener('mouseup', handleMouseUp)\n target.addEventListener('wheel', handleWheel)\n\n const currentButtons = buttons as Set<number>\n const currentPosition = position as { x: number; y: number }\n const currentDelta = delta as { x: number; y: number }\n const currentWheelDelta = wheelDelta as number\n\n return {\n get x() { return currentPosition.x },\n get y() { return currentPosition.y },\n get deltaX() { return currentDelta.x },\n get deltaY() { return currentDelta.y },\n get wheelDelta() { return currentWheelDelta },\n\n isPressed: (button: MouseButton) => currentButtons?.has(button) || false,\n\n isLeftPressed: () => currentButtons?.has(MouseButton.Left) || false,\n\n isRightPressed: () => currentButtons?.has(MouseButton.Right) || false,\n\n isMiddlePressed: () => currentButtons?.has(MouseButton.Middle) || false,\n\n clearFrameState: () => {\n setDelta({ x: 0, y: 0 })\n setWheelDelta(0)\n },\n\n dispose: () => {\n target.removeEventListener('mousemove', handleMouseMove)\n target.removeEventListener('mousedown', handleMouseDown)\n target.removeEventListener('mouseup', handleMouseUp)\n target.removeEventListener('wheel', handleWheel)\n }\n }\n}\n"]}