flexium 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- 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-3AKECLKA.mjs +2 -0
- package/dist/chunk-3AKECLKA.mjs.map +1 -0
- package/dist/chunk-ACYN2UKT.js +2 -0
- package/dist/chunk-ACYN2UKT.js.map +1 -0
- package/dist/chunk-E6Z7AI4J.js +2 -0
- package/dist/chunk-E6Z7AI4J.js.map +1 -0
- package/dist/chunk-MI76R42D.mjs +2 -0
- package/dist/chunk-MI76R42D.mjs.map +1 -0
- package/dist/chunk-PUXZJ7OV.js +2 -0
- package/dist/{chunk-X6HXRSMG.js.map → chunk-PUXZJ7OV.js.map} +1 -1
- package/dist/chunk-TP5HUAIN.mjs +2 -0
- package/dist/{chunk-JUP6RTZA.mjs.map → chunk-TP5HUAIN.mjs.map} +1 -1
- package/dist/core.d.cts +32 -2
- package/dist/core.d.ts +32 -2
- 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.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 +3 -3
- package/dist/interactive.d.ts +3 -3
- 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/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/render-4HB53K66.mjs +2 -0
- package/dist/{render-L57MA662.mjs.map → render-4HB53K66.mjs.map} +1 -1
- package/dist/render-MJ2LCNSG.js +2 -0
- package/dist/{render-VERKNIPR.js.map → render-MJ2LCNSG.js.map} +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.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +1 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -6
- package/dist/advanced.d.cts +0 -5
- package/dist/advanced.d.ts +0 -5
- package/dist/advanced.js +0 -2
- package/dist/advanced.js.map +0 -1
- package/dist/advanced.mjs +0 -2
- package/dist/advanced.mjs.map +0 -1
- package/dist/chunk-5PNH2ARD.mjs +0 -2
- package/dist/chunk-5PNH2ARD.mjs.map +0 -1
- package/dist/chunk-CGB4YXKS.js +0 -2
- package/dist/chunk-CGB4YXKS.js.map +0 -1
- package/dist/chunk-INJXOHFD.mjs +0 -2
- package/dist/chunk-INJXOHFD.mjs.map +0 -1
- package/dist/chunk-JUP6RTZA.mjs +0 -2
- package/dist/chunk-NDPEE2TQ.mjs +0 -2
- package/dist/chunk-NDPEE2TQ.mjs.map +0 -1
- package/dist/chunk-UWFVCKRU.js +0 -2
- package/dist/chunk-UWFVCKRU.js.map +0 -1
- package/dist/chunk-W2L7BLE7.js +0 -2
- package/dist/chunk-W2L7BLE7.js.map +0 -1
- package/dist/chunk-X6HXRSMG.js +0 -2
- package/dist/render-L57MA662.mjs +0 -2
- package/dist/render-VERKNIPR.js +0 -2
- package/dist/types--emg3Tgw.d.cts +0 -10
- package/dist/types--emg3Tgw.d.ts +0 -10
package/README.md
CHANGED
|
@@ -109,13 +109,13 @@ const [doubled] = use(() => count * 2, [count])
|
|
|
109
109
|
|
|
110
110
|
```
|
|
111
111
|
flexium
|
|
112
|
-
├── /core # Core reactivity: use(), sync(),
|
|
112
|
+
├── /core # Core reactivity: use(), sync(), Context
|
|
113
113
|
├── /dom # DOM renderer: render(), hydrate(), Portal, Suspense
|
|
114
114
|
├── /ref # Ref system: useRef(), forwardRef()
|
|
115
115
|
├── /router # SPA routing: Routes, Route, Link, Outlet, useRouter(), useLocation()
|
|
116
116
|
├── /server # SSR: renderToString(), renderToStaticMarkup()
|
|
117
117
|
├── /canvas # Canvas 2D: Canvas, DrawRect, DrawCircle, DrawText
|
|
118
|
-
└── /interactive # Game loop: useLoop(),
|
|
118
|
+
└── /interactive # Game loop: useLoop(), useKeyboard(), useMouse()
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
## Control Flow
|
|
@@ -187,11 +187,11 @@ function App() {
|
|
|
187
187
|
```tsx
|
|
188
188
|
import { use } from 'flexium/core'
|
|
189
189
|
import { Canvas, DrawRect } from 'flexium/canvas'
|
|
190
|
-
import { useLoop,
|
|
190
|
+
import { useLoop, useKeyboard, Keys } from 'flexium/interactive'
|
|
191
191
|
|
|
192
192
|
function Game() {
|
|
193
193
|
const [x, setX] = use(100)
|
|
194
|
-
const kb =
|
|
194
|
+
const kb = useKeyboard()
|
|
195
195
|
|
|
196
196
|
const gameLoop = useLoop({
|
|
197
197
|
fixedFps: 60,
|
|
@@ -264,13 +264,19 @@ import { ErrorBoundary } from 'flexium/dom'
|
|
|
264
264
|
## Context API
|
|
265
265
|
|
|
266
266
|
```tsx
|
|
267
|
-
import { use,
|
|
267
|
+
import { use, Context } from 'flexium/core'
|
|
268
268
|
|
|
269
|
-
|
|
269
|
+
// Create context with default value
|
|
270
|
+
const ThemeCtx = new Context<'light' | 'dark'>('light')
|
|
270
271
|
|
|
271
272
|
function App() {
|
|
273
|
+
const [theme, setTheme] = use<'light' | 'dark'>('light')
|
|
274
|
+
|
|
272
275
|
return (
|
|
273
|
-
<ThemeCtx.Provider value=
|
|
276
|
+
<ThemeCtx.Provider value={theme}>
|
|
277
|
+
<button onclick={() => setTheme(t => t === 'light' ? 'dark' : 'light')}>
|
|
278
|
+
Toggle Theme
|
|
279
|
+
</button>
|
|
274
280
|
<Child />
|
|
275
281
|
</ThemeCtx.Provider>
|
|
276
282
|
)
|
|
@@ -278,7 +284,7 @@ function App() {
|
|
|
278
284
|
|
|
279
285
|
function Child() {
|
|
280
286
|
const [theme] = use(ThemeCtx)
|
|
281
|
-
return <div>
|
|
287
|
+
return <div class={theme}>Current theme: {theme}</div>
|
|
282
288
|
}
|
|
283
289
|
```
|
|
284
290
|
|
package/dist/canvas.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkACYN2UKT_js=require('./chunk-ACYN2UKT.js');require('./chunk-3CKIHQIE.js'),require('./chunk-E6Z7AI4J.js');var chunkDUGPBZZ3_js=require('./chunk-DUGPBZZ3.js');var D=[];function l(t){D.push(t);}function C(t){let{width:y,height:w,children:e,style:u,ref:a}=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 chunkACYN2UKT_js.c(()=>{s&&i();}),chunkDUGPBZZ3_js.a("canvas",{ref:o=>{s=o,n=o.getContext("2d"),a&&a(o),i();},width:y,height:w,style:u})}function r(t){return chunkACYN2UKT_js.b(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 chunkACYN2UKT_js.c(()=>{l({type:"rect",props:t});}),null}function v(t){return chunkACYN2UKT_js.c(()=>{l({type:"circle",props:t});}),null}function A(t){return chunkACYN2UKT_js.c(()=>{l({type:"arc",props:t});}),null}function W(t){return chunkACYN2UKT_js.c(()=>{l({type:"line",props:t});}),null}function b(t){return chunkACYN2UKT_js.c(()=>{l({type:"text",props:t});}),null}function R(t){return chunkACYN2UKT_js.c(()=>{l({type:"path",props:t});}),null}exports.Canvas=C;exports.DrawArc=A;exports.DrawCircle=v;exports.DrawLine=W;exports.DrawPath=R;exports.DrawRect=x;exports.DrawText=b;//# sourceMappingURL=canvas.js.map
|
|
2
2
|
//# sourceMappingURL=canvas.js.map
|
package/dist/canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"8MAOA,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,CAAAA,EAAS,CAIXP,CAAAA,CAAU,QAAQE,CAAAA,EAAQ,CACxBY,EAASH,CAAAA,CAAMT,CAAI,EACrB,CAAC,CAAA,CAGsB,IAAA,EACzB,EAEA,OAAAa,kBAAA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AI,YAAciB,CAAAA,CACdC,CAAAA,GAAalB,EAAI,SAAA,CAAYkB,CAAAA,CAAAA,CACjClB,EAAI,MAAA,CAAOiC,CAAI,CAAA,CAAA,CAEjB,KACF,CACF,CAGItB,CAAAA,GAAY,MAAA,GACdX,CAAAA,CAAI,YAAc,CAAA,EAEtB,CC9NO,SAASkC,CAAAA,CAASzC,EAAsB,CAC7C,OAAAW,mBAAI,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,kBAAAA,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,mBAAI,IAAM,CACRd,EAAU,CACR,IAAA,CAAM,MACN,KAAA,CAAAG,CACF,CAAC,EACH,CAAC,CAAA,CAEM,IACT,CCTO,SAAS4C,CAAAA,CAAS5C,EAAsB,CAC7C,OAAAW,kBAAAA,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,kBAAAA,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,kBAAAA,CAAI,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"]}
|
|
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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T,CCTO,SAAS8C,CAAAA,CAAS9C,CAAAA,CAAsB,CAC7C,OAAAW,kBAAAA,CAAI,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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
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
2
|
//# sourceMappingURL=canvas.mjs.map
|
package/dist/canvas.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"0KAOA,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,OAA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AA,CAAI,YAAciB,CAAAA,CACdC,CAAAA,GAAalB,EAAI,SAAA,CAAYkB,CAAAA,CAAAA,CACjClB,EAAI,MAAA,CAAOiC,CAAI,CAAA,CAAA,CAEjB,KACF,CACF,CAGItB,CAAAA,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
|
+
{"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,CAAA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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"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a,c,d,b as b$2}from'./chunk-NRPWBHKP.mjs';import {d as d$1,b as b$1}from'./chunk-MI76R42D.mjs';var b=Symbol("flexium.reactive"),C=new WeakMap,R=new WeakMap;function m(e){if(e&&e[b])return e;let r=R.get(e);if(r)return r;let s=new Proxy(e,{get(n,i,a){if(i===b)return true;let f=Reflect.get(n,i,a);return j(n,i),f!==null&&typeof f=="object"?m(f):f},set(n,i,a,f){let l=n[i],x=Reflect.set(n,i,a,f);return x&&A(a,l)&&I(n,i),x}});return R.set(e,s),s}function j(e,r){if(!a)return;let s=C.get(e);s||C.set(e,s=new Map);let n=s.get(r);n||s.set(r,n=new Set),c(n);}function I(e,r){let s=C.get(e);if(!s)return;let n=s.get(r);n&&d(n);}function A(e,r){return !Object.is(e,r)}function L(e){return !!(e&&e[b])}var K=0,M=new Map;function E(){if(typeof window<"u")return window.__FLEXIUM_DEVTOOLS__}function O(e,r){let s=E();if(!s)return -1;let n=++K;M.set(e,n);let i={id:n,name:r||`signal_${n}`,value:e.value,type:e.type||"signal",subscribers:0,createdAt:Date.now()};return s.onSignalCreate(i),n}function _(e,r){let s=E();if(!s)return;let n=M.get(e);n!==void 0&&s.onSignalUpdate(n,r);}function V(e){return e&&typeof e=="object"&&"id"in e&&"defaultValue"in e&&"Provider"in e}var P=new Map;function z(e){return JSON.stringify(e)}function B(e,r,s){if(V(e))return [d$1(e),void 0];let n,i;if(Array.isArray(r)?(n=r,i=s):r&&typeof r=="object"&&(i=r),i?.key&&!Array.isArray(i.key))throw new Error("State key must be an array");let a=b$1(()=>m({container:void 0,serializedKey:void 0})),f=i?.key,l=f?z(f):void 0,x=l!==a.serializedKey;if(typeof e=="function"&&n!==void 0){let c=e,o=b$1(()=>({value:void 0,prevDeps:void 0,cleanup:void 0,hasRun:false,params:void 0})),t=true;if(o.hasRun&&o.prevDeps&&(t=n.length!==o.prevDeps.length||n.some((p,d)=>p!==o.prevDeps[d])),t){o.cleanup&&(o.cleanup(),o.cleanup=void 0);let p={onCleanup:y=>{o.cleanup=y;},params:o.params},d=c(p);if(d instanceof Promise)throw new Error("deps with async functions is not supported. Use use(asyncFn) without deps for async resources.");o.value=d,o.prevDeps=[...n],o.hasRun=true;}let v={refetch:async()=>{},get loading(){return false},get error(){return null},get status(){return "success"}};return [o.value,v]}if(!a.container||x)if(a.serializedKey=l,l&&P.has(l))a.container=P.get(l);else {let c;if(typeof e=="function"){let o=e,t=m({type:"resource",value:void 0,loading:true,error:null,status:"idle",cleanup:void 0,params:void 0,run:()=>{}}),v=p=>{t.cleanup&&(t.cleanup(),t.cleanup=void 0),t.params=p;try{let d={onCleanup:g=>{t.cleanup=g;},params:t.params},y=o(d);y instanceof Promise?(t.loading=!0,t.status="loading",t.error=null,y.then(g=>{t.value=g,t.status="success",t.loading=!1;}).catch(g=>{t.error=g,t.status="error",t.loading=!1;})):(t.value=y,t.status="success",t.loading=!1,t.error=null);}catch(d){t.error=d,t.status="error",t.loading=false;}};t.run=v,b$2(()=>v()),c=t;}else c=m({type:"signal",value:e}),O(c,i?.name);l&&P.set(l,c),a.container=c;}let u=a.container,w=u.value;return u.type==="signal"?[w,o=>{typeof o=="function"?u.value=o(u.value):u.value=o,_(u,u.value);}]:[w,{refetch:async o=>{u.run(o);},get loading(){return u.loading},get error(){return u.error},get status(){return u.status}}]}export{m as a,L as b,B as c};//# sourceMappingURL=chunk-3AKECLKA.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-3AKECLKA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/reactive.ts","../src/core/devtools.ts","../src/core/use.ts"],"names":["REACTIVE_SIGNAL","targetMap","reactiveMap","reactive","target","existingProxy","proxy","key","receiver","res","track","value","oldValue","result","hasChanged","trigger","activeEffect","depsMap","dep","trackEffect","triggerEffects","isReactive","signalIdCounter","signalRegistry","getDevToolsHook","registerSignal","container","name","hook","id","info","updateSignal","isContext","globalRegistry","serializeKey","use","input","depsOrOptions","thirdArg","getContextValue","deps","options","stateRef","currentKey","serializedKey","keyChanged","fn","memoState","d","i","ctx","control","newContainer","state","run","params","data","err","unsafeEffect","currentValue","newValue"],"mappings":"uGAEO,IAAMA,CAAAA,CAAkB,OAAO,kBAAkB,CAAA,CAIlDC,EAAY,IAAI,OAAA,CAGhBC,EAAc,IAAI,OAAA,CAEjB,SAASC,CAAAA,CAA2BC,CAAAA,CAAc,CACrD,GAAIA,CAAAA,EAAWA,EAAeJ,CAAe,CAAA,CACzC,OAAOI,CAAAA,CAGX,IAAMC,EAAgBH,CAAAA,CAAY,GAAA,CAAIE,CAAM,CAAA,CAC5C,GAAIC,EACA,OAAOA,CAAAA,CAGX,IAAMC,CAAAA,CAAQ,IAAI,MAAMF,CAAAA,CAAQ,CAC5B,IAAIA,CAAAA,CAAQG,CAAAA,CAAKC,EAAU,CACvB,GAAID,CAAAA,GAAQP,CAAAA,CAAiB,OAAO,KAAA,CAEpC,IAAMS,CAAAA,CAAM,OAAA,CAAQ,IAAIL,CAAAA,CAAQG,CAAAA,CAAKC,CAAQ,CAAA,CAI7C,OAFAE,EAAMN,CAAAA,CAAQG,CAAG,EAEbE,CAAAA,GAAQ,IAAA,EAAQ,OAAOA,CAAAA,EAAQ,QAAA,CACxBN,EAASM,CAAG,CAAA,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AAAA,CAAa,IAAMJ,GAAK,CAAA,CAExBF,EAAeC,EACjB,CAAA,KAEED,EAAejD,CAAAA,CAAS,CACtB,KAAM,QAAA,CACN,KAAA,CAAOiC,CACT,CAAC,CAAA,CAGDX,EAAe2B,CAAAA,CAAcX,CAAAA,EAAS,IAAI,CAAA,CAIxCG,CAAAA,EACFX,CAAAA,CAAe,GAAA,CAAIW,CAAAA,CAAeQ,CAAY,EAGhDV,CAAAA,CAAS,SAAA,CAAYU,EACvB,CAGF,IAAM1B,EAAYgB,CAAAA,CAAS,SAAA,CAGrBiB,EAAejC,CAAAA,CAAU,KAAA,CAE/B,OAAIA,CAAAA,CAAU,IAAA,GAAS,SASd,CAACiC,CAAAA,CARmBC,GAAa,CAClC,OAAOA,CAAAA,EAAa,UAAA,CACtBlC,CAAAA,CAAU,KAAA,CAASkC,EAAsBlC,CAAAA,CAAU,KAAK,EAExDA,CAAAA,CAAU,KAAA,CAAQkC,EAEpB7B,CAAAA,CAAaL,CAAAA,CAAWA,EAAU,KAAK,EACzC,CAC4B,CAAA,CASrB,CAACiC,EAN4B,CAClC,OAAA,CAAS,MAAOJ,CAAAA,EAAe,CAAE7B,CAAAA,CAAU,GAAA,CAAI6B,CAAM,EAAE,EACvD,IAAI,OAAA,EAAU,CAAE,OAAO7B,CAAAA,CAAU,OAAQ,CAAA,CACzC,IAAI,OAAQ,CAAE,OAAOA,EAAU,KAAM,CAAA,CACrC,IAAI,MAAA,EAAS,CAAE,OAAOA,CAAAA,CAAU,MAAO,CACzC,CAC6B,CAEjC","file":"chunk-3AKECLKA.mjs","sourcesContent":["import { activeEffect, trackEffect, triggerEffects } from './lifecycle'\n\nexport const REACTIVE_SIGNAL = Symbol('flexium.reactive')\n\ntype Dep = Set<any>\ntype KeyToDepMap = Map<any, Dep>\nconst targetMap = new WeakMap<any, KeyToDepMap>()\n\n// WeakMap to store existing proxies to avoid duplicates\nconst reactiveMap = new WeakMap<object, any>()\n\nexport function reactive<T extends object>(target: T): T {\n if (target && (target as any)[REACTIVE_SIGNAL]) {\n return target\n }\n\n const existingProxy = reactiveMap.get(target)\n if (existingProxy) {\n return existingProxy\n }\n\n const proxy = new Proxy(target, {\n get(target, key, receiver) {\n if (key === REACTIVE_SIGNAL) return true\n\n const res = Reflect.get(target, key, receiver)\n\n track(target, key)\n\n if (res !== null && typeof res === 'object') {\n return reactive(res)\n }\n\n return res\n },\n set(target, key, value, receiver) {\n const oldValue = (target as any)[key]\n const result = Reflect.set(target, key, value, receiver)\n\n if (result && hasChanged(value, oldValue)) {\n trigger(target, key)\n }\n\n return result\n }\n })\n\n reactiveMap.set(target, proxy)\n return proxy\n}\n\nexport function track(target: object, key: unknown) {\n if (!activeEffect) return\n\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n targetMap.set(target, (depsMap = new Map()))\n }\n\n let dep = depsMap.get(key)\n if (!dep) {\n depsMap.set(key, (dep = new Set()))\n }\n\n trackEffect(dep)\n}\n\nexport function trigger(target: object, key: unknown) {\n const depsMap = targetMap.get(target)\n if (!depsMap) return\n\n const dep = depsMap.get(key)\n if (dep) {\n triggerEffects(dep)\n }\n}\n\nfunction hasChanged(value: any, oldValue: any): boolean {\n return !Object.is(value, oldValue)\n}\n\nexport function isReactive(value: unknown): boolean {\n return !!(value && (value as any)[REACTIVE_SIGNAL])\n}\n","// DevTools integration for Flexium\n// This module provides hooks for browser DevTools extension\n\ninterface SignalInfo {\n id: number\n name: string\n value: unknown\n type: string\n subscribers: number\n createdAt: number\n}\n\ninterface DevToolsHook {\n signals: Map<number, SignalInfo>\n onSignalCreate: (info: SignalInfo) => void\n onSignalUpdate: (id: number, value: unknown) => void\n onRender: (event: { timestamp: number; componentName: string; trigger: string; duration: number }) => void\n}\n\ndeclare global {\n interface Window {\n __FLEXIUM_DEVTOOLS__?: DevToolsHook\n }\n}\n\nlet signalIdCounter = 0\nconst signalRegistry = new Map<object, number>()\n\nfunction getDevToolsHook(): DevToolsHook | undefined {\n if (typeof window !== 'undefined') {\n return window.__FLEXIUM_DEVTOOLS__\n }\n return undefined\n}\n\nexport function registerSignal(container: object, name?: string): number {\n const hook = getDevToolsHook()\n if (!hook) return -1\n\n const id = ++signalIdCounter\n signalRegistry.set(container, id)\n\n const info: SignalInfo = {\n id,\n name: name || `signal_${id}`,\n value: (container as any).value,\n type: (container as any).type || 'signal',\n subscribers: 0,\n createdAt: Date.now(),\n }\n\n hook.onSignalCreate(info)\n return id\n}\n\nexport function updateSignal(container: object, value: unknown): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n const id = signalRegistry.get(container)\n if (id !== undefined) {\n hook.onSignalUpdate(id, value)\n }\n}\n\nexport function reportRender(componentName: string, trigger: string, duration: number): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n hook.onRender({\n timestamp: Date.now(),\n componentName,\n trigger,\n duration,\n })\n}\n\nexport function isDevToolsEnabled(): boolean {\n return getDevToolsHook() !== undefined\n}\n","import { reactive } from './reactive'\nimport { unsafeEffect } from './lifecycle'\nimport { hook } from './hook'\nimport { registerSignal, updateSignal } from './devtools'\nimport { Context, getContextValue } from './context'\n\n// Re-export Context class only (other functions are internal)\nexport { Context } from './context'\n\nfunction isContext(value: any): value is Context<any> {\n return value && typeof value === 'object' && 'id' in value && 'defaultValue' in value && 'Provider' in value\n}\n\n// Types\nexport type Setter<T> = (newValue: T | ((prev: T) => T)) => void\n\nexport type ResourceControl<P = void> = {\n refetch: (params?: P) => Promise<void>\n readonly loading: boolean\n readonly error: unknown\n readonly status: 'idle' | 'loading' | 'success' | 'error'\n}\n\nexport interface UseContext<P = void> {\n onCleanup: (fn: () => void) => void\n params?: P\n}\n\nexport interface UseOptions {\n key?: unknown[]\n name?: string\n}\n\n// Global State Registry\nconst globalRegistry = new Map<string, any>()\n\nfunction serializeKey(key: unknown[]): string {\n return JSON.stringify(key)\n}\n\n// Overloads\nexport function use<T>(ctx: Context<T>): [T, undefined]\n\nexport function use<T, P = void>(\n fn: (ctx: UseContext<P>) => Promise<T>,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T | undefined, ResourceControl<P>]\n\nexport function use<T>(\n fn: (ctx: UseContext) => T,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T, ResourceControl]\n\nexport function use<T>(\n initialValue: T extends Function ? never : T,\n options?: UseOptions\n): [T, Setter<T>]\n\nexport function use<T, P = void>(\n input: T | Context<T> | ((ctx: UseContext<P>) => T) | ((ctx: UseContext<P>) => Promise<T>),\n depsOrOptions?: any[] | UseOptions,\n thirdArg?: UseOptions\n): any {\n // Context mode: use(SomeContext) returns [value, undefined] tuple for UX consistency\n if (isContext(input)) {\n const value = getContextValue(input)\n return [value, undefined]\n }\n\n // Normalize arguments:\n // - use(value, { key }) → options only\n // - use(fn, [deps]) → deps only\n // - use(fn, [deps], { key }) → deps + options\n let deps: any[] | undefined\n let options: UseOptions | undefined\n\n if (Array.isArray(depsOrOptions)) {\n deps = depsOrOptions\n options = thirdArg // third arg is options when second is deps array\n } else if (depsOrOptions && typeof depsOrOptions === 'object') {\n options = depsOrOptions as UseOptions\n }\n\n // Validate key if provided\n if (options?.key && !Array.isArray(options.key)) {\n throw new Error('State key must be an array')\n }\n\n // Hook Wrapper: Store container reference and track key\n const stateRef = hook(() => {\n return reactive({\n container: undefined as any,\n serializedKey: undefined as any\n })\n })\n\n // Compute serialized key\n const currentKey = options?.key\n const serializedKey = currentKey ? serializeKey(currentKey) : undefined\n\n // Check if key has changed\n const keyChanged = serializedKey !== stateRef.serializedKey\n\n // DEPS MODE: Function with explicit deps array\n if (typeof input === 'function' && deps !== undefined) {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n const memoState = hook(() => ({\n value: undefined as T | undefined,\n prevDeps: undefined as any[] | undefined,\n cleanup: undefined as (() => void) | undefined,\n hasRun: false,\n params: undefined as P | undefined\n }))\n\n let hasChanged = true\n if (memoState.hasRun && memoState.prevDeps) {\n hasChanged = deps.length !== memoState.prevDeps.length ||\n deps.some((d, i) => d !== memoState.prevDeps![i])\n }\n\n if (hasChanged) {\n // Run previous cleanup\n if (memoState.cleanup) {\n memoState.cleanup()\n memoState.cleanup = undefined\n }\n\n // Create context with onCleanup\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n memoState.cleanup = fn\n },\n params: memoState.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n throw new Error('deps with async functions is not supported. Use use(asyncFn) without deps for async resources.')\n }\n\n memoState.value = result\n memoState.prevDeps = [...deps]\n memoState.hasRun = true\n }\n\n const control: ResourceControl<P> = {\n refetch: async () => {},\n get loading() { return false },\n get error() { return null },\n get status() { return 'success' as const }\n }\n\n return [memoState.value, control]\n }\n\n // If key changed or first time, get/create container\n if (!stateRef.container || keyChanged) {\n stateRef.serializedKey = serializedKey\n\n // Check Registry FIRST\n if (serializedKey && globalRegistry.has(serializedKey)) {\n stateRef.container = globalRegistry.get(serializedKey)\n } else {\n let newContainer: any\n\n // Function (Computed or Resource)\n if (typeof input === 'function') {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n // State for async/computed\n const state = reactive({\n type: 'resource',\n value: undefined as T | undefined,\n loading: true,\n error: null as any,\n status: 'idle' as 'idle' | 'loading' | 'success' | 'error',\n cleanup: undefined as (() => void) | undefined,\n params: undefined as P | undefined,\n run: () => {}\n })\n\n const run = (params?: P) => {\n // Run previous cleanup\n if (state.cleanup) {\n state.cleanup()\n state.cleanup = undefined\n }\n\n // Store params for context\n state.params = params\n\n try {\n // Create context\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n state.cleanup = fn\n },\n params: state.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n state.loading = true\n state.status = 'loading'\n state.error = null\n\n result\n .then(data => {\n state.value = data\n state.status = 'success'\n state.loading = false\n })\n .catch(err => {\n state.error = err\n state.status = 'error'\n state.loading = false\n })\n } else {\n state.value = result\n state.status = 'success'\n state.loading = false\n state.error = null\n }\n } catch (err) {\n state.error = err\n state.status = 'error'\n state.loading = false\n }\n }\n\n state.run = run\n\n // Make it reactive!\n unsafeEffect(() => run())\n\n newContainer = state\n } else {\n // Value (Signal)\n newContainer = reactive({\n type: 'signal',\n value: input\n })\n\n // Register with DevTools\n registerSignal(newContainer, options?.name)\n }\n\n // Register in global registry if needed\n if (serializedKey) {\n globalRegistry.set(serializedKey, newContainer)\n }\n\n stateRef.container = newContainer\n }\n }\n\n const container = stateRef.container\n\n // Access container.value to track dependency\n const currentValue = container.value\n\n if (container.type === 'signal') {\n const setter: Setter<T> = (newValue) => {\n if (typeof newValue === 'function') {\n container.value = (newValue as Function)(container.value)\n } else {\n container.value = newValue\n }\n updateSignal(container, container.value)\n }\n return [currentValue, setter]\n } else {\n // Resource / Computed\n const control: ResourceControl<P> = {\n refetch: async (params?: P) => { container.run(params) },\n get loading() { return container.loading },\n get error() { return container.error },\n get status() { return container.status }\n }\n return [currentValue, control]\n }\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunk3CKIHQIE_js=require('./chunk-3CKIHQIE.js'),chunkE6Z7AI4J_js=require('./chunk-E6Z7AI4J.js');var b=Symbol("flexium.reactive"),C=new WeakMap,R=new WeakMap;function m(e){if(e&&e[b])return e;let r=R.get(e);if(r)return r;let s=new Proxy(e,{get(n,i,a){if(i===b)return true;let f=Reflect.get(n,i,a);return j(n,i),f!==null&&typeof f=="object"?m(f):f},set(n,i,a,f){let l=n[i],x=Reflect.set(n,i,a,f);return x&&A(a,l)&&I(n,i),x}});return R.set(e,s),s}function j(e,r){if(!chunk3CKIHQIE_js.a)return;let s=C.get(e);s||C.set(e,s=new Map);let n=s.get(r);n||s.set(r,n=new Set),chunk3CKIHQIE_js.c(n);}function I(e,r){let s=C.get(e);if(!s)return;let n=s.get(r);n&&chunk3CKIHQIE_js.d(n);}function A(e,r){return !Object.is(e,r)}function L(e){return !!(e&&e[b])}var K=0,M=new Map;function E(){if(typeof window<"u")return window.__FLEXIUM_DEVTOOLS__}function O(e,r){let s=E();if(!s)return -1;let n=++K;M.set(e,n);let i={id:n,name:r||`signal_${n}`,value:e.value,type:e.type||"signal",subscribers:0,createdAt:Date.now()};return s.onSignalCreate(i),n}function _(e,r){let s=E();if(!s)return;let n=M.get(e);n!==void 0&&s.onSignalUpdate(n,r);}function V(e){return e&&typeof e=="object"&&"id"in e&&"defaultValue"in e&&"Provider"in e}var P=new Map;function z(e){return JSON.stringify(e)}function B(e,r,s){if(V(e))return [chunkE6Z7AI4J_js.d(e),void 0];let n,i;if(Array.isArray(r)?(n=r,i=s):r&&typeof r=="object"&&(i=r),i?.key&&!Array.isArray(i.key))throw new Error("State key must be an array");let a=chunkE6Z7AI4J_js.b(()=>m({container:void 0,serializedKey:void 0})),f=i?.key,l=f?z(f):void 0,x=l!==a.serializedKey;if(typeof e=="function"&&n!==void 0){let c=e,o=chunkE6Z7AI4J_js.b(()=>({value:void 0,prevDeps:void 0,cleanup:void 0,hasRun:false,params:void 0})),t=true;if(o.hasRun&&o.prevDeps&&(t=n.length!==o.prevDeps.length||n.some((p,d)=>p!==o.prevDeps[d])),t){o.cleanup&&(o.cleanup(),o.cleanup=void 0);let p={onCleanup:y=>{o.cleanup=y;},params:o.params},d=c(p);if(d instanceof Promise)throw new Error("deps with async functions is not supported. Use use(asyncFn) without deps for async resources.");o.value=d,o.prevDeps=[...n],o.hasRun=true;}let v={refetch:async()=>{},get loading(){return false},get error(){return null},get status(){return "success"}};return [o.value,v]}if(!a.container||x)if(a.serializedKey=l,l&&P.has(l))a.container=P.get(l);else {let c;if(typeof e=="function"){let o=e,t=m({type:"resource",value:void 0,loading:true,error:null,status:"idle",cleanup:void 0,params:void 0,run:()=>{}}),v=p=>{t.cleanup&&(t.cleanup(),t.cleanup=void 0),t.params=p;try{let d={onCleanup:g=>{t.cleanup=g;},params:t.params},y=o(d);y instanceof Promise?(t.loading=!0,t.status="loading",t.error=null,y.then(g=>{t.value=g,t.status="success",t.loading=!1;}).catch(g=>{t.error=g,t.status="error",t.loading=!1;})):(t.value=y,t.status="success",t.loading=!1,t.error=null);}catch(d){t.error=d,t.status="error",t.loading=false;}};t.run=v,chunk3CKIHQIE_js.b(()=>v()),c=t;}else c=m({type:"signal",value:e}),O(c,i?.name);l&&P.set(l,c),a.container=c;}let u=a.container,w=u.value;return u.type==="signal"?[w,o=>{typeof o=="function"?u.value=o(u.value):u.value=o,_(u,u.value);}]:[w,{refetch:async o=>{u.run(o);},get loading(){return u.loading},get error(){return u.error},get status(){return u.status}}]}exports.a=m;exports.b=L;exports.c=B;//# sourceMappingURL=chunk-ACYN2UKT.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-ACYN2UKT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/reactive.ts","../src/core/devtools.ts","../src/core/use.ts"],"names":["REACTIVE_SIGNAL","targetMap","reactiveMap","reactive","target","existingProxy","proxy","key","receiver","res","track","value","oldValue","result","hasChanged","trigger","activeEffect","depsMap","dep","trackEffect","triggerEffects","isReactive","signalIdCounter","signalRegistry","getDevToolsHook","registerSignal","container","name","hook","id","info","updateSignal","isContext","globalRegistry","serializeKey","use","input","depsOrOptions","thirdArg","getContextValue","deps","options","stateRef","currentKey","serializedKey","keyChanged","fn","memoState","d","i","ctx","control","newContainer","state","run","params","data","err","unsafeEffect","currentValue","newValue"],"mappings":"iHAEO,IAAMA,CAAAA,CAAkB,OAAO,kBAAkB,CAAA,CAIlDC,EAAY,IAAI,OAAA,CAGhBC,EAAc,IAAI,OAAA,CAEjB,SAASC,CAAAA,CAA2BC,CAAAA,CAAc,CACrD,GAAIA,CAAAA,EAAWA,EAAeJ,CAAe,CAAA,CACzC,OAAOI,CAAAA,CAGX,IAAMC,EAAgBH,CAAAA,CAAY,GAAA,CAAIE,CAAM,CAAA,CAC5C,GAAIC,EACA,OAAOA,CAAAA,CAGX,IAAMC,CAAAA,CAAQ,IAAI,MAAMF,CAAAA,CAAQ,CAC5B,IAAIA,CAAAA,CAAQG,CAAAA,CAAKC,E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C6B,CAEjC","file":"chunk-ACYN2UKT.js","sourcesContent":["import { activeEffect, trackEffect, triggerEffects } from './lifecycle'\n\nexport const REACTIVE_SIGNAL = Symbol('flexium.reactive')\n\ntype Dep = Set<any>\ntype KeyToDepMap = Map<any, Dep>\nconst targetMap = new WeakMap<any, KeyToDepMap>()\n\n// WeakMap to store existing proxies to avoid duplicates\nconst reactiveMap = new WeakMap<object, any>()\n\nexport function reactive<T extends object>(target: T): T {\n if (target && (target as any)[REACTIVE_SIGNAL]) {\n return target\n }\n\n const existingProxy = reactiveMap.get(target)\n if (existingProxy) {\n return existingProxy\n }\n\n const proxy = new Proxy(target, {\n get(target, key, receiver) {\n if (key === REACTIVE_SIGNAL) return true\n\n const res = Reflect.get(target, key, receiver)\n\n track(target, key)\n\n if (res !== null && typeof res === 'object') {\n return reactive(res)\n }\n\n return res\n },\n set(target, key, value, receiver) {\n const oldValue = (target as any)[key]\n const result = Reflect.set(target, key, value, receiver)\n\n if (result && hasChanged(value, oldValue)) {\n trigger(target, key)\n }\n\n return result\n }\n })\n\n reactiveMap.set(target, proxy)\n return proxy\n}\n\nexport function track(target: object, key: unknown) {\n if (!activeEffect) return\n\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n targetMap.set(target, (depsMap = new Map()))\n }\n\n let dep = depsMap.get(key)\n if (!dep) {\n depsMap.set(key, (dep = new Set()))\n }\n\n trackEffect(dep)\n}\n\nexport function trigger(target: object, key: unknown) {\n const depsMap = targetMap.get(target)\n if (!depsMap) return\n\n const dep = depsMap.get(key)\n if (dep) {\n triggerEffects(dep)\n }\n}\n\nfunction hasChanged(value: any, oldValue: any): boolean {\n return !Object.is(value, oldValue)\n}\n\nexport function isReactive(value: unknown): boolean {\n return !!(value && (value as any)[REACTIVE_SIGNAL])\n}\n","// DevTools integration for Flexium\n// This module provides hooks for browser DevTools extension\n\ninterface SignalInfo {\n id: number\n name: string\n value: unknown\n type: string\n subscribers: number\n createdAt: number\n}\n\ninterface DevToolsHook {\n signals: Map<number, SignalInfo>\n onSignalCreate: (info: SignalInfo) => void\n onSignalUpdate: (id: number, value: unknown) => void\n onRender: (event: { timestamp: number; componentName: string; trigger: string; duration: number }) => void\n}\n\ndeclare global {\n interface Window {\n __FLEXIUM_DEVTOOLS__?: DevToolsHook\n }\n}\n\nlet signalIdCounter = 0\nconst signalRegistry = new Map<object, number>()\n\nfunction getDevToolsHook(): DevToolsHook | undefined {\n if (typeof window !== 'undefined') {\n return window.__FLEXIUM_DEVTOOLS__\n }\n return undefined\n}\n\nexport function registerSignal(container: object, name?: string): number {\n const hook = getDevToolsHook()\n if (!hook) return -1\n\n const id = ++signalIdCounter\n signalRegistry.set(container, id)\n\n const info: SignalInfo = {\n id,\n name: name || `signal_${id}`,\n value: (container as any).value,\n type: (container as any).type || 'signal',\n subscribers: 0,\n createdAt: Date.now(),\n }\n\n hook.onSignalCreate(info)\n return id\n}\n\nexport function updateSignal(container: object, value: unknown): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n const id = signalRegistry.get(container)\n if (id !== undefined) {\n hook.onSignalUpdate(id, value)\n }\n}\n\nexport function reportRender(componentName: string, trigger: string, duration: number): void {\n const hook = getDevToolsHook()\n if (!hook) return\n\n hook.onRender({\n timestamp: Date.now(),\n componentName,\n trigger,\n duration,\n })\n}\n\nexport function isDevToolsEnabled(): boolean {\n return getDevToolsHook() !== undefined\n}\n","import { reactive } from './reactive'\nimport { unsafeEffect } from './lifecycle'\nimport { hook } from './hook'\nimport { registerSignal, updateSignal } from './devtools'\nimport { Context, getContextValue } from './context'\n\n// Re-export Context class only (other functions are internal)\nexport { Context } from './context'\n\nfunction isContext(value: any): value is Context<any> {\n return value && typeof value === 'object' && 'id' in value && 'defaultValue' in value && 'Provider' in value\n}\n\n// Types\nexport type Setter<T> = (newValue: T | ((prev: T) => T)) => void\n\nexport type ResourceControl<P = void> = {\n refetch: (params?: P) => Promise<void>\n readonly loading: boolean\n readonly error: unknown\n readonly status: 'idle' | 'loading' | 'success' | 'error'\n}\n\nexport interface UseContext<P = void> {\n onCleanup: (fn: () => void) => void\n params?: P\n}\n\nexport interface UseOptions {\n key?: unknown[]\n name?: string\n}\n\n// Global State Registry\nconst globalRegistry = new Map<string, any>()\n\nfunction serializeKey(key: unknown[]): string {\n return JSON.stringify(key)\n}\n\n// Overloads\nexport function use<T>(ctx: Context<T>): [T, undefined]\n\nexport function use<T, P = void>(\n fn: (ctx: UseContext<P>) => Promise<T>,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T | undefined, ResourceControl<P>]\n\nexport function use<T>(\n fn: (ctx: UseContext) => T,\n depsOrOptions?: any[] | UseOptions,\n options?: UseOptions\n): [T, ResourceControl]\n\nexport function use<T>(\n initialValue: T extends Function ? never : T,\n options?: UseOptions\n): [T, Setter<T>]\n\nexport function use<T, P = void>(\n input: T | Context<T> | ((ctx: UseContext<P>) => T) | ((ctx: UseContext<P>) => Promise<T>),\n depsOrOptions?: any[] | UseOptions,\n thirdArg?: UseOptions\n): any {\n // Context mode: use(SomeContext) returns [value, undefined] tuple for UX consistency\n if (isContext(input)) {\n const value = getContextValue(input)\n return [value, undefined]\n }\n\n // Normalize arguments:\n // - use(value, { key }) → options only\n // - use(fn, [deps]) → deps only\n // - use(fn, [deps], { key }) → deps + options\n let deps: any[] | undefined\n let options: UseOptions | undefined\n\n if (Array.isArray(depsOrOptions)) {\n deps = depsOrOptions\n options = thirdArg // third arg is options when second is deps array\n } else if (depsOrOptions && typeof depsOrOptions === 'object') {\n options = depsOrOptions as UseOptions\n }\n\n // Validate key if provided\n if (options?.key && !Array.isArray(options.key)) {\n throw new Error('State key must be an array')\n }\n\n // Hook Wrapper: Store container reference and track key\n const stateRef = hook(() => {\n return reactive({\n container: undefined as any,\n serializedKey: undefined as any\n })\n })\n\n // Compute serialized key\n const currentKey = options?.key\n const serializedKey = currentKey ? serializeKey(currentKey) : undefined\n\n // Check if key has changed\n const keyChanged = serializedKey !== stateRef.serializedKey\n\n // DEPS MODE: Function with explicit deps array\n if (typeof input === 'function' && deps !== undefined) {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n const memoState = hook(() => ({\n value: undefined as T | undefined,\n prevDeps: undefined as any[] | undefined,\n cleanup: undefined as (() => void) | undefined,\n hasRun: false,\n params: undefined as P | undefined\n }))\n\n let hasChanged = true\n if (memoState.hasRun && memoState.prevDeps) {\n hasChanged = deps.length !== memoState.prevDeps.length ||\n deps.some((d, i) => d !== memoState.prevDeps![i])\n }\n\n if (hasChanged) {\n // Run previous cleanup\n if (memoState.cleanup) {\n memoState.cleanup()\n memoState.cleanup = undefined\n }\n\n // Create context with onCleanup\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n memoState.cleanup = fn\n },\n params: memoState.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n throw new Error('deps with async functions is not supported. Use use(asyncFn) without deps for async resources.')\n }\n\n memoState.value = result\n memoState.prevDeps = [...deps]\n memoState.hasRun = true\n }\n\n const control: ResourceControl<P> = {\n refetch: async () => {},\n get loading() { return false },\n get error() { return null },\n get status() { return 'success' as const }\n }\n\n return [memoState.value, control]\n }\n\n // If key changed or first time, get/create container\n if (!stateRef.container || keyChanged) {\n stateRef.serializedKey = serializedKey\n\n // Check Registry FIRST\n if (serializedKey && globalRegistry.has(serializedKey)) {\n stateRef.container = globalRegistry.get(serializedKey)\n } else {\n let newContainer: any\n\n // Function (Computed or Resource)\n if (typeof input === 'function') {\n const fn = input as (ctx: UseContext<P>) => T | Promise<T>\n\n // State for async/computed\n const state = reactive({\n type: 'resource',\n value: undefined as T | undefined,\n loading: true,\n error: null as any,\n status: 'idle' as 'idle' | 'loading' | 'success' | 'error',\n cleanup: undefined as (() => void) | undefined,\n params: undefined as P | undefined,\n run: () => {}\n })\n\n const run = (params?: P) => {\n // Run previous cleanup\n if (state.cleanup) {\n state.cleanup()\n state.cleanup = undefined\n }\n\n // Store params for context\n state.params = params\n\n try {\n // Create context\n const ctx: UseContext<P> = {\n onCleanup: (fn) => {\n state.cleanup = fn\n },\n params: state.params\n }\n\n const result = fn(ctx)\n\n if (result instanceof Promise) {\n state.loading = true\n state.status = 'loading'\n state.error = null\n\n result\n .then(data => {\n state.value = data\n state.status = 'success'\n state.loading = false\n })\n .catch(err => {\n state.error = err\n state.status = 'error'\n state.loading = false\n })\n } else {\n state.value = result\n state.status = 'success'\n state.loading = false\n state.error = null\n }\n } catch (err) {\n state.error = err\n state.status = 'error'\n state.loading = false\n }\n }\n\n state.run = run\n\n // Make it reactive!\n unsafeEffect(() => run())\n\n newContainer = state\n } else {\n // Value (Signal)\n newContainer = reactive({\n type: 'signal',\n value: input\n })\n\n // Register with DevTools\n registerSignal(newContainer, options?.name)\n }\n\n // Register in global registry if needed\n if (serializedKey) {\n globalRegistry.set(serializedKey, newContainer)\n }\n\n stateRef.container = newContainer\n }\n }\n\n const container = stateRef.container\n\n // Access container.value to track dependency\n const currentValue = container.value\n\n if (container.type === 'signal') {\n const setter: Setter<T> = (newValue) => {\n if (typeof newValue === 'function') {\n container.value = (newValue as Function)(container.value)\n } else {\n container.value = newValue\n }\n updateSignal(container, container.value)\n }\n return [currentValue, setter]\n } else {\n // Resource / Computed\n const control: ResourceControl<P> = {\n refetch: async (params?: P) => { container.run(params) },\n get loading() { return container.loading },\n get error() { return container.error },\n get status() { return container.status }\n }\n return [currentValue, control]\n }\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var r=null;function u(n,e){let t=r;r=n,n.hookIndex=0;try{return e()}finally{r=t;}}function i(n){if(!r)return n();let e=r,{hooks:t,hookIndex:a}=e;if(a<t.length)return e.hookIndex++,t[a];let s=n();return t.push(s),e.hookIndex++,s}var o=new Map,l=class{constructor(e){this.id=Symbol("context"),this.defaultValue=e,this.Provider=t=>t.children,this.Provider._contextId=this.id;}};function p(n){return o.has(n.id)?o.get(n.id):n.defaultValue}function h(n,e){let t=o.get(n);return o.set(n,e),t}function d(n,e){e===void 0?o.delete(n):o.set(n,e);}exports.a=u;exports.b=i;exports.c=l;exports.d=p;exports.e=h;exports.f=d;//# sourceMappingURL=chunk-E6Z7AI4J.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-E6Z7AI4J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/hook.ts","../src/core/context.ts"],"names":["currentComponent","runWithComponent","component","fn","prev","hook","factory","instance","hooks","hookIndex","value","contextMap","Context","defaultValue","props","getContextValue","ctx","pushContext","id","popContext","prevValue"],"mappings":"aAMA,IAAIA,CAAAA,CAA6C,IAAA,CAM1C,SAASC,CAAAA,CAAoBC,EAA8BC,CAAAA,CAAgB,CAC9E,IAAMC,CAAAA,CAAOJ,EACbA,CAAAA,CAAmBE,CAAAA,CACnBA,CAAAA,CAAU,SAAA,CAAY,EACtB,GAAI,CACA,OAAOC,CAAAA,EACX,CAAA,OAAE,CACEH,CAAAA,CAAmBI,EACvB,CACJ,CAEO,SAASC,CAAAA,CAAQC,EAAqB,CACzC,GAAI,CAACN,CAAAA,CAED,OAAOM,CAAAA,EAAQ,CAGnB,IAAMC,CAAAA,CAAWP,CAAAA,CACX,CAAE,KAAA,CAAAQ,CAAAA,CAAO,UAAAC,CAAU,CAAA,CAAIF,CAAAA,CAE7B,GAAIE,EAAYD,CAAAA,CAAM,MAAA,CAElB,OAAAD,CAAAA,CAAS,YACFC,CAAAA,CAAMC,CAAS,CAAA,CAI1B,IAAMC,EAAQJ,CAAAA,EAAQ,CACtB,OAAAE,CAAAA,CAAM,KAAKE,CAAK,CAAA,CAChBH,CAAAA,CAAS,SAAA,EAAA,CAEFG,CACX,CC5CA,IAAMC,CAAAA,CAAa,IAAI,IAuBVC,CAAAA,CAAN,KAAiB,CAKpB,WAAA,CAAYC,CAAAA,CAAiB,CACzB,IAAA,CAAK,EAAA,CAAK,OAAO,SAAS,CAAA,CAC1B,IAAA,CAAK,YAAA,CAAeA,EACpB,IAAA,CAAK,QAAA,CAAYC,CAAAA,EAAuCA,CAAAA,CAAM,SAC5D,IAAA,CAAK,QAAA,CAAiB,UAAA,CAAa,IAAA,CAAK,GAC9C,CACJ,EAGO,SAASC,CAAAA,CAAmBC,EAAoB,CACnD,OAAOL,CAAAA,CAAW,GAAA,CAAIK,EAAI,EAAE,CAAA,CAAIL,CAAAA,CAAW,GAAA,CAAIK,EAAI,EAAE,CAAA,CAAIA,CAAAA,CAAI,YACjE,CAGO,SAASC,CAAAA,CAAYC,CAAAA,CAAYR,EAAY,CAChD,IAAMN,CAAAA,CAAOO,CAAAA,CAAW,IAAIO,CAAE,CAAA,CAC9B,OAAAP,CAAAA,CAAW,IAAIO,CAAAA,CAAIR,CAAK,CAAA,CACjBN,CACX,CAGO,SAASe,CAAAA,CAAWD,CAAAA,CAAYE,CAAAA,CAAgB,CAC/CA,CAAAA,GAAc,MAAA,CACdT,CAAAA,CAAW,MAAA,CAAOO,CAAE,CAAA,CAEpBP,CAAAA,CAAW,GAAA,CAAIO,CAAAA,CAAIE,CAAS,EAEpC","file":"chunk-E6Z7AI4J.js","sourcesContent":["\nexport interface ComponentInstance {\n hooks: any[]\n hookIndex: number\n}\n\nlet currentComponent: ComponentInstance | null = null\n\nexport function getComponent(): ComponentInstance | null {\n return currentComponent\n}\n\nexport function runWithComponent<T>(component: ComponentInstance, fn: () => T): T {\n const prev = currentComponent\n currentComponent = component\n component.hookIndex = 0\n try {\n return fn()\n } finally {\n currentComponent = prev\n }\n}\n\nexport function hook<T>(factory: () => T): T {\n if (!currentComponent) {\n // Outside component: just run factory\n return factory()\n }\n\n const instance = currentComponent\n const { hooks, hookIndex } = instance\n\n if (hookIndex < hooks.length) {\n // Return existing hook\n instance.hookIndex++\n return hooks[hookIndex] as T\n }\n\n // Create new hook\n const value = factory()\n hooks.push(value)\n instance.hookIndex++\n\n return value\n}\n","const contextMap = new Map<symbol, any>()\n\n/**\n * Context for passing data through the component tree\n *\n * @example\n * ```tsx\n * const ThemeContext = new Context('light')\n *\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <Child />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * function Child() {\n * const [theme] = use(ThemeContext)\n * return <div>{theme}</div>\n * }\n * ```\n */\nexport class Context<T> {\n readonly id: symbol\n readonly defaultValue: T\n readonly Provider: (props: { value: T; children: any }) => any\n\n constructor(defaultValue: T) {\n this.id = Symbol('context')\n this.defaultValue = defaultValue\n this.Provider = (props: { value: T; children: any }) => props.children\n ;(this.Provider as any)._contextId = this.id\n }\n}\n\n// Internal: get context value (used by use.ts)\nexport function getContextValue<T>(ctx: Context<T>): T {\n return contextMap.has(ctx.id) ? contextMap.get(ctx.id) : ctx.defaultValue\n}\n\n// Internal helpers for renderer\nexport function pushContext(id: symbol, value: any) {\n const prev = contextMap.get(id)\n contextMap.set(id, value)\n return prev\n}\n\n\nexport function popContext(id: symbol, prevValue: any) {\n if (prevValue === undefined) {\n contextMap.delete(id)\n } else {\n contextMap.set(id, prevValue)\n }\n}\n\nexport function snapshotContext(): Map<symbol, any> {\n return new Map(contextMap)\n}\n\nexport function runWithContext<R>(snapshot: Map<symbol, any>, fn: () => R): R {\n // 1. Save current context\n const prevContext = new Map(contextMap)\n\n // 2. Apply snapshot\n contextMap.clear()\n snapshot.forEach((value, key) => contextMap.set(key, value))\n\n try {\n return fn()\n } finally {\n // 3. Restore previous context\n contextMap.clear()\n prevContext.forEach((value, key) => contextMap.set(key, value))\n }\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=null;function u(n,e){let t=r;r=n,n.hookIndex=0;try{return e()}finally{r=t;}}function i(n){if(!r)return n();let e=r,{hooks:t,hookIndex:a}=e;if(a<t.length)return e.hookIndex++,t[a];let s=n();return t.push(s),e.hookIndex++,s}var o=new Map,l=class{constructor(e){this.id=Symbol("context"),this.defaultValue=e,this.Provider=t=>t.children,this.Provider._contextId=this.id;}};function p(n){return o.has(n.id)?o.get(n.id):n.defaultValue}function h(n,e){let t=o.get(n);return o.set(n,e),t}function d(n,e){e===void 0?o.delete(n):o.set(n,e);}export{u as a,i as b,l as c,p as d,h as e,d as f};//# sourceMappingURL=chunk-MI76R42D.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-MI76R42D.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/hook.ts","../src/core/context.ts"],"names":["currentComponent","runWithComponent","component","fn","prev","hook","factory","instance","hooks","hookIndex","value","contextMap","Context","defaultValue","props","getContextValue","ctx","pushContext","id","popContext","prevValue"],"mappings":"AAMA,IAAIA,CAAAA,CAA6C,IAAA,CAM1C,SAASC,CAAAA,CAAoBC,EAA8BC,CAAAA,CAAgB,CAC9E,IAAMC,CAAAA,CAAOJ,EACbA,CAAAA,CAAmBE,CAAAA,CACnBA,CAAAA,CAAU,SAAA,CAAY,EACtB,GAAI,CACA,OAAOC,CAAAA,EACX,CAAA,OAAE,CACEH,CAAAA,CAAmBI,EACvB,CACJ,CAEO,SAASC,CAAAA,CAAQC,EAAqB,CACzC,GAAI,CAACN,CAAAA,CAED,OAAOM,CAAAA,EAAQ,CAGnB,IAAMC,CAAAA,CAAWP,CAAAA,CACX,CAAE,KAAA,CAAAQ,CAAAA,CAAO,UAAAC,CAAU,CAAA,CAAIF,CAAAA,CAE7B,GAAIE,EAAYD,CAAAA,CAAM,MAAA,CAElB,OAAAD,CAAAA,CAAS,YACFC,CAAAA,CAAMC,CAAS,CAAA,CAI1B,IAAMC,EAAQJ,CAAAA,EAAQ,CACtB,OAAAE,CAAAA,CAAM,KAAKE,CAAK,CAAA,CAChBH,CAAAA,CAAS,SAAA,EAAA,CAEFG,CACX,CC5CA,IAAMC,CAAAA,CAAa,IAAI,IAuBVC,CAAAA,CAAN,KAAiB,CAKpB,WAAA,CAAYC,CAAAA,CAAiB,CACzB,IAAA,CAAK,EAAA,CAAK,OAAO,SAAS,CAAA,CAC1B,IAAA,CAAK,YAAA,CAAeA,EACpB,IAAA,CAAK,QAAA,CAAYC,CAAAA,EAAuCA,CAAAA,CAAM,SAC5D,IAAA,CAAK,QAAA,CAAiB,UAAA,CAAa,IAAA,CAAK,GAC9C,CACJ,EAGO,SAASC,CAAAA,CAAmBC,EAAoB,CACnD,OAAOL,CAAAA,CAAW,GAAA,CAAIK,EAAI,EAAE,CAAA,CAAIL,CAAAA,CAAW,GAAA,CAAIK,EAAI,EAAE,CAAA,CAAIA,CAAAA,CAAI,YACjE,CAGO,SAASC,CAAAA,CAAYC,CAAAA,CAAYR,EAAY,CAChD,IAAMN,CAAAA,CAAOO,CAAAA,CAAW,IAAIO,CAAE,CAAA,CAC9B,OAAAP,CAAAA,CAAW,IAAIO,CAAAA,CAAIR,CAAK,CAAA,CACjBN,CACX,CAGO,SAASe,CAAAA,CAAWD,CAAAA,CAAYE,CAAAA,CAAgB,CAC/CA,CAAAA,GAAc,MAAA,CACdT,CAAAA,CAAW,MAAA,CAAOO,CAAE,CAAA,CAEpBP,CAAAA,CAAW,GAAA,CAAIO,CAAAA,CAAIE,CAAS,EAEpC","file":"chunk-MI76R42D.mjs","sourcesContent":["\nexport interface ComponentInstance {\n hooks: any[]\n hookIndex: number\n}\n\nlet currentComponent: ComponentInstance | null = null\n\nexport function getComponent(): ComponentInstance | null {\n return currentComponent\n}\n\nexport function runWithComponent<T>(component: ComponentInstance, fn: () => T): T {\n const prev = currentComponent\n currentComponent = component\n component.hookIndex = 0\n try {\n return fn()\n } finally {\n currentComponent = prev\n }\n}\n\nexport function hook<T>(factory: () => T): T {\n if (!currentComponent) {\n // Outside component: just run factory\n return factory()\n }\n\n const instance = currentComponent\n const { hooks, hookIndex } = instance\n\n if (hookIndex < hooks.length) {\n // Return existing hook\n instance.hookIndex++\n return hooks[hookIndex] as T\n }\n\n // Create new hook\n const value = factory()\n hooks.push(value)\n instance.hookIndex++\n\n return value\n}\n","const contextMap = new Map<symbol, any>()\n\n/**\n * Context for passing data through the component tree\n *\n * @example\n * ```tsx\n * const ThemeContext = new Context('light')\n *\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <Child />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * function Child() {\n * const [theme] = use(ThemeContext)\n * return <div>{theme}</div>\n * }\n * ```\n */\nexport class Context<T> {\n readonly id: symbol\n readonly defaultValue: T\n readonly Provider: (props: { value: T; children: any }) => any\n\n constructor(defaultValue: T) {\n this.id = Symbol('context')\n this.defaultValue = defaultValue\n this.Provider = (props: { value: T; children: any }) => props.children\n ;(this.Provider as any)._contextId = this.id\n }\n}\n\n// Internal: get context value (used by use.ts)\nexport function getContextValue<T>(ctx: Context<T>): T {\n return contextMap.has(ctx.id) ? contextMap.get(ctx.id) : ctx.defaultValue\n}\n\n// Internal helpers for renderer\nexport function pushContext(id: symbol, value: any) {\n const prev = contextMap.get(id)\n contextMap.set(id, value)\n return prev\n}\n\n\nexport function popContext(id: symbol, prevValue: any) {\n if (prevValue === undefined) {\n contextMap.delete(id)\n } else {\n contextMap.set(id, prevValue)\n }\n}\n\nexport function snapshotContext(): Map<symbol, any> {\n return new Map(contextMap)\n}\n\nexport function runWithContext<R>(snapshot: Map<symbol, any>, fn: () => R): R {\n // 1. Save current context\n const prevContext = new Map(contextMap)\n\n // 2. Apply snapshot\n contextMap.clear()\n snapshot.forEach((value, key) => contextMap.set(key, value))\n\n try {\n return fn()\n } finally {\n // 3. Restore previous context\n contextMap.clear()\n prevContext.forEach((value, key) => contextMap.set(key, value))\n }\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunk3CKIHQIE_js=require('./chunk-3CKIHQIE.js'),chunkE6Z7AI4J_js=require('./chunk-E6Z7AI4J.js');var p=new WeakMap,h=null;function E(e){e.children.forEach(n=>{E(n);}),e.nodes.forEach(n=>{n.parentNode&&n.parentNode.removeChild(n);}),e.children.clear(),e.parentInstance&&e.parentInstance.children.delete(e);}function S(e,n,o){let c=o||n,r=f=>{let u={...f.props};return f.children&&f.children.length>0&&(u.children=f.children.length===1?f.children[0]:f.children),u},a=e.key!==void 0;p.has(c)||p.set(c,new Map);let t=p.get(c),i;if(a)i=e.key;else {let f=0,u=e.type.name||"anonymous";t.forEach((b,l)=>{typeof l=="string"&&l.startsWith(`__auto_${u}_`)&&f++;}),i=`__auto_${u}_${f}`;}if(t.has(i)){let f=t.get(i);f.fnode=e;let u=r(e);return f.props=u,f.children.clear(),f.renderFn&&f.renderFn(),f.nodes}let s={hooks:[],hookIndex:0,nodes:[],parent:n,fnode:e,props:r(e),key:i,children:new Set,parentInstance:h||void 0};h&&h.children.add(s),t.set(i,s);let d=true,_=()=>{let f=s.fnode,u=s.props;f.type._contextId!==void 0&&chunkE6Z7AI4J_js.e(f.type._contextId,u.value);let l=h;h=s;let v=chunkE6Z7AI4J_js.a(s,()=>f.type(u));if(d){let g=y(v,n);s.nodes=g?Array.isArray(g)?g:[g]:[],s.nodes.forEach(m=>{m.__ownerInstance||(m.__ownerInstance=s);}),d=false;}else {if(s.nodes.length===0){let C=y(v,n);s.nodes=C?Array.isArray(C)?C:[C]:[],h=l;return}let m=s.nodes[0].parentNode;if(!m){h=l;return}let M=document.createComment("flexium-marker"),I=s.nodes[s.nodes.length-1];I.nextSibling?m.insertBefore(M,I.nextSibling):m.appendChild(M),s.children.clear();let x=document.createElement("div"),T=y(v,x,m),O=T?Array.isArray(T)?T:[T]:[],R=P(s.nodes,O,m,M);m.removeChild(M),s.nodes=R;}h=l;};return s.renderFn=_,chunk3CKIHQIE_js.b(_),s.nodes}function y(e,n,o){let c=o||n;if(e==null||typeof e=="boolean"){let r=document.createTextNode("");return n.appendChild(r),r}if(typeof e=="string"||typeof e=="number"){let r=document.createTextNode(String(e));return n.appendChild(r),r}if(Array.isArray(e)){let r=new Set;p.has(c)&&p.get(c).forEach((s,d)=>r.add(d));let a=[];e.forEach(i=>{let s=y(i,n,o);s&&(Array.isArray(s)?a.push(...s):a.push(s));});let t=new Set;if(p.has(c)&&p.get(c).forEach((s,d)=>t.add(d)),p.has(c)){let i=p.get(c),s=[];r.forEach(d=>{if(!t.has(d)){let _=i.get(d);_&&(E(_),s.push(d));}}),s.forEach(d=>i.delete(d));}return a}if(typeof e=="object"){if(typeof e.type=="string"){let r=document.createElement(e.type);return e.props&&Object.entries(e.props).forEach(([a,t])=>{if(a==="ref")typeof t=="function"?t(r):t&&typeof t=="object"&&"current"in t&&(t.current=r);else if(a.startsWith("on")&&typeof t=="function"){let i=a.slice(2).toLowerCase();r.addEventListener(i,t),r.__eventHandlers||(r.__eventHandlers={}),r.__eventHandlers[i]=t;}else a!=="ref"&&D(r,a,t);}),e.children&&e.children.length>0&&e.children.forEach(a=>{y(a,r);}),n.appendChild(r),r}if(typeof e.type=="function")return S(e,n,o)}return null}function D(e,n,o){o==null?e.removeAttribute(n):n==="style"&&typeof o=="object"?Object.assign(e.style,o):n==="class"?e.className=String(o):n in e&&typeof e[n]!="function"?e[n]=o:e.setAttribute(n,String(o));}function j(e,n){return e.nodeType!==n.nodeType?false:e.nodeType===Node.ELEMENT_NODE&&n.nodeType===Node.ELEMENT_NODE?e.tagName===n.tagName:true}function k(e,n){Array.from(e.attributes).forEach(t=>{n.hasAttribute(t.name)||e.removeAttribute(t.name);}),Array.from(n.attributes).forEach(t=>{e.getAttribute(t.name)!==t.value&&(t.name==="value"&&"value"in e?e.value=t.value:t.name==="checked"&&"checked"in e?e.checked=t.value==="true"||t.value==="":e.setAttribute(t.name,t.value));});let r=e.__eventHandlers||{},a=n.__eventHandlers||{};Object.keys(r).forEach(t=>{a[t]||e.removeEventListener(t,r[t]);}),Object.keys(a).forEach(t=>{r[t]!==a[t]&&(r[t]&&e.removeEventListener(t,r[t]),e.addEventListener(t,a[t]));}),Object.keys(a).length>0?e.__eventHandlers=a:delete e.__eventHandlers,e instanceof HTMLInputElement&&n instanceof HTMLInputElement&&(e.value!==n.value&&(e.value=n.value),e.checked!==n.checked&&(e.checked=n.checked)),e instanceof HTMLTextAreaElement&&n instanceof HTMLTextAreaElement&&e.value!==n.value&&(e.value=n.value),e instanceof HTMLSelectElement&&n instanceof HTMLSelectElement&&e.value!==n.value&&(e.value=n.value);}function F(e,n){let o=Array.from(e.childNodes),c=Array.from(n.childNodes),r=Math.max(o.length,c.length);for(let a=0;a<r;a++){let t=o[a],i=c[a];!t&&i?e.appendChild(i):t&&!i?e.removeChild(t):t&&i&&H(t,i,e);}}function H(e,n,o){if(j(e,n)){let c=n.__ownerInstance;if(c){let r=c.nodes.indexOf(n);r!==-1&&(c.nodes[r]=e),e.__ownerInstance=c,delete n.__ownerInstance;}e.nodeType===Node.TEXT_NODE?e.nodeValue!==n.nodeValue&&(e.nodeValue=n.nodeValue):e.nodeType===Node.ELEMENT_NODE&&(k(e,n),F(e,n));}else o.replaceChild(n,e);}function P(e,n,o,c){let r=Math.max(e.length,n.length),a=[];for(let t=0;t<r;t++){let i=e[t],s=n[t];!i&&s?(o.insertBefore(s,c),a.push(s)):i&&!s?i.parentNode&&o.removeChild(i):i&&s&&(H(i,s,o),a.push(i));}return a}function $(e,n){n.innerHTML="",typeof e=="function"&&(e={type:e,props:{},children:[],key:void 0}),y(e,n);}exports.a=P;exports.b=$;//# sourceMappingURL=chunk-PUXZJ7OV.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-PUXZJ7OV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dom/render.ts"],"names":["instanceRegistry","currentRenderingInstance","removeComponentInstance","instance","child","node","renderComponent","fnode","parent","registryParent","effectiveRegistryParent","mergeProps","props","hasExplicitKey","parentRegistry","key","instanceCount","componentName","_","k","newProps","isFirstRender","renderFn","currentFnode","currentProps","pushContext","previousRenderingInstance","result","runWithComponent","newNodes","renderNode","nodeParent","marker","lastNode","tempContainer","newNodesArray","reconciledNodes","reconcile","unsafeEffect","oldKeysSet","nodes","newKeysSet","keysToRemove","dom","value","eventName","setAttribute","el","canReuse","oldNode","newNode","updateAttributes","oldEl","newEl","attr","oldHandlers","newHandlers","event","reconcileChildren","oldChildren","newChildren","maxLen","i","oldChild","newChild","patchNode","own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A4B,CACpG,IAAMR,CAAAA,CAAS,KAAK,GAAA,CAAIO,CAAAA,CAAS,MAAA,CAAQvC,CAAAA,CAAS,MAAM,CAAA,CAClDyC,CAAAA,CAAsB,EAAC,CAE7B,QAASR,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAID,CAAAA,CAAQC,CAAAA,EAAAA,CAAK,CAC7B,IAAMb,CAAAA,CAAUmB,EAASN,CAAC,CAAA,CACpBZ,CAAAA,CAAUrB,CAAAA,CAASiC,CAAC,CAAA,CAEtB,CAACb,CAAAA,EAAWC,CAAAA,EACZ1C,EAAO,YAAA,CAAa0C,CAAAA,CAASmB,CAAY,CAAA,CACzCC,EAAY,IAAA,CAAKpB,CAAO,CAAA,EACjBD,CAAAA,EAAW,CAACC,CAAAA,CACfD,CAAAA,CAAQ,UAAA,EACRzC,CAAAA,CAAO,YAAYyC,CAAO,CAAA,CAEvBA,CAAAA,EAAWC,CAAAA,GAClBe,EAAUhB,CAAAA,CAASC,CAAAA,CAAS1C,CAAiB,CAAA,CAC7C8D,CAAAA,CAAY,IAAA,CAAKrB,CAAO,CAAA,EAEhC,CAEA,OAAOqB,CACX,CAEO,SAASC,EAAOC,CAAAA,CAAUC,CAAAA,CAAwB,CACrDA,CAAAA,CAAU,UAAY,EAAA,CAElB,OAAOD,CAAAA,EAAQ,UAAA,GACfA,EAAM,CAAE,IAAA,CAAMA,CAAAA,CAAK,KAAA,CAAO,EAAC,CAAG,QAAA,CAAU,EAAC,CAAG,IAAK,MAAU,CAAA,CAAA,CAG/D1C,CAAAA,CAAW0C,CAAAA,CAAKC,CAAS,EAC7B","file":"chunk-X6HXRSMG.js","sourcesContent":["import { pushContext } from '../core/context'\nimport { runWithComponent, type ComponentInstance } from '../core/hook'\nimport { unsafeEffect } from '../core/lifecycle'\n\n// Extended ComponentInstance for DOM tracking\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 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 instance.children.forEach(child => {\n removeComponentInstance(child)\n })\n\n instance.nodes.forEach(node => {\n if (node.parentNode) {\n node.parentNode.removeChild(node)\n }\n })\n\n instance.children.clear()\n\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\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 const hasExplicitKey = fnode.key !== undefined\n\n if (!instanceRegistry.has(effectiveRegistryParent)) {\n instanceRegistry.set(effectiveRegistryParent, new Map())\n }\n const parentRegistry = instanceRegistry.get(effectiveRegistryParent)!\n\n let key: any\n if (hasExplicitKey) {\n key = fnode.key\n } else {\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 if (parentRegistry.has(key)) {\n const instance = parentRegistry.get(key)!\n instance.fnode = fnode\n const newProps = mergeProps(fnode)\n instance.props = newProps\n instance.children.clear()\n\n if (instance.renderFn) {\n instance.renderFn()\n }\n\n return instance.nodes\n }\n\n const instance: DOMComponentInstance = {\n hooks: [],\n hookIndex: 0,\n nodes: [],\n parent,\n fnode: fnode,\n props: mergeProps(fnode),\n key,\n children: new Set(),\n parentInstance: currentRenderingInstance || undefined\n }\n\n if (currentRenderingInstance) {\n currentRenderingInstance.children.add(instance)\n }\n\n parentRegistry.set(key, instance)\n\n let isFirstRender = true\n\n const renderFn = () => {\n const currentFnode = instance.fnode\n const currentProps = instance.props\n\n const isProvider = (currentFnode.type as any)._contextId !== undefined\n if (isProvider) {\n pushContext((currentFnode.type as any)._contextId, currentProps.value)\n }\n\n const previousRenderingInstance = currentRenderingInstance\n currentRenderingInstance = instance\n\n const result = runWithComponent(instance, () => currentFnode.type(currentProps))\n\n if (isFirstRender) {\n const newNodes = renderNode(result, parent)\n instance.nodes = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\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 if (instance.nodes.length === 0) {\n const newNodes = renderNode(result, parent)\n instance.nodes = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\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 currentRenderingInstance = previousRenderingInstance\n return\n }\n\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 instance.children.clear()\n\n const tempContainer = document.createElement('div')\n const newNodes = renderNode(result, tempContainer, nodeParent)\n const newNodesArray = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\n\n const reconciledNodes = reconcile(instance.nodes, newNodesArray, nodeParent, marker)\n\n nodeParent.removeChild(marker)\n\n instance.nodes = reconciledNodes\n }\n\n currentRenderingInstance = previousRenderingInstance\n }\n\n instance.renderFn = renderFn\n\n unsafeEffect(renderFn)\n\n return instance.nodes\n}\n\nfunction renderNode(fnode: any, parent: HTMLElement, registryParent?: HTMLElement): Node | Node[] | null {\n const effectiveRegistryParent = registryParent || parent\n\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n const node = document.createTextNode('')\n parent.appendChild(node)\n return node\n }\n\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 if (Array.isArray(fnode)) {\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 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 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 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 removeComponentInstance(instance)\n keysToRemove.push(key)\n }\n }\n })\n\n keysToRemove.forEach(key => parentRegistry.delete(key))\n }\n\n return nodes\n }\n\n if (typeof fnode === 'object') {\n if (typeof fnode.type === 'string') {\n const dom = document.createElement(fnode.type)\n\n if (fnode.props) {\n Object.entries(fnode.props).forEach(([key, value]) => {\n if (key === 'ref') {\n // Handle both callback refs and RefObject\n if (typeof value === 'function') {\n value(dom)\n } else if (value && typeof value === 'object' && 'current' in value) {\n value.current = dom\n }\n } else if (key.startsWith('on') && typeof value === 'function') {\n const eventName = key.slice(2).toLowerCase()\n dom.addEventListener(eventName, value as EventListener)\n\n if (!(dom as any).__eventHandlers) {\n (dom as any).__eventHandlers = {}\n }\n (dom as any).__eventHandlers[eventName] = value\n } else if (key !== 'ref') {\n setAttribute(dom, key, value)\n }\n })\n }\n\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 if (typeof fnode.type === 'function') {\n return renderComponent(fnode, parent, registryParent)\n }\n }\n\n return null\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 Object.assign((el as HTMLElement).style, value)\n } else if (key === 'class') {\n el.className = String(value)\n } else if (key in el && typeof (el as any)[key] !== 'function') {\n (el as any)[key] = value\n } else {\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 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 const newAttrs = Array.from(newEl.attributes)\n newAttrs.forEach(attr => {\n if (oldEl.getAttribute(attr.name) !== attr.value) {\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 const oldHandlers = (oldEl as any).__eventHandlers || {}\n const newHandlers = (newEl as any).__eventHandlers || {}\n\n Object.keys(oldHandlers).forEach(event => {\n if (!newHandlers[event]) {\n oldEl.removeEventListener(event, oldHandlers[event])\n }\n })\n\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 if (Object.keys(newHandlers).length > 0) {\n (oldEl as any).__eventHandlers = newHandlers\n } else {\n delete (oldEl as any).__eventHandlers\n }\n\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 oldEl.appendChild(newChild)\n } else if (oldChild && !newChild) {\n oldEl.removeChild(oldChild)\n } else if (oldChild && newChild) {\n patchNode(oldChild, newChild, oldEl)\n }\n }\n}\n\nfunction patchNode(oldNode: Node, newNode: Node, parent: Element): void {\n if (canReuse(oldNode, newNode)) {\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\n if (oldNode.nodeType === Node.TEXT_NODE) {\n if (oldNode.nodeValue !== newNode.nodeValue) {\n oldNode.nodeValue = newNode.nodeValue\n }\n } else if (oldNode.nodeType === Node.ELEMENT_NODE) {\n updateAttributes(oldNode as Element, newNode as Element)\n reconcileChildren(oldNode as Element, newNode as Element)\n }\n } else {\n parent.replaceChild(newNode, oldNode)\n }\n}\n\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 parent.insertBefore(newNode, beforeMarker)\n resultNodes.push(newNode)\n } else if (oldNode && !newNode) {\n if (oldNode.parentNode) {\n parent.removeChild(oldNode)\n }\n } else if (oldNode && newNode) {\n patchNode(oldNode, newNode, parent as Element)\n resultNodes.push(oldNode)\n }\n }\n\n return resultNodes\n}\n\nexport function render(app: any, container: HTMLElement) {\n container.innerHTML = ''\n\n if (typeof app === 'function') {\n app = { type: app, props: {}, children: [], key: undefined }\n }\n\n renderNode(app, container)\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/dom/render.ts"],"names":["instanceRegistry","currentRenderingInstance","removeComponentInstance","instance","child","node","renderComponent","fnode","parent","registryParent","effectiveRegistryParent","mergeProps","props","hasExplicitKey","parentRegistry","key","instanceCount","componentName","_","k","newProps","isFirstRender","renderFn","currentFnode","currentProps","pushContext","previousRenderingInstance","result","runWithComponent","newNodes","renderNode","nodeParent","marker","lastNode","tempContainer","newNodesArray","reconciledNodes","reconcile","unsafeEffect","oldKeysSet","nodes","newKeysSet","keysToRemove","dom","value","eventName","setAttribute","el","canReuse","oldNode","newNode","updateAttributes","oldEl","newEl","attr","oldHandlers","newHandlers","event","reconcileChildren","oldChildren","newChildren","maxLen","i","oldChild","newChild","patchNode","ownerInstance","idx","oldNodes","beforeMarker","resultNodes","render","app","container"],"mappings":"iHAiBA,IAAMA,CAAAA,CAAmB,IAAI,OAAA,CAGzBC,CAAAA,CAAwD,KAG5D,SAASC,CAAAA,CAAwBC,CAAAA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AAA,CAAI,CAAA,CAAGA,CAAAA,CAAID,CAAAA,CAAQC,CAAAA,EAAAA,CAAK,CAC7B,IAAMb,CAAAA,CAAUmB,EAASN,CAAC,CAAA,CACpBZ,CAAAA,CAAUrB,CAAAA,CAASiC,CAAC,CAAA,CAEtB,CAACb,CAAAA,EAAWC,CAAAA,EACZ1C,EAAO,YAAA,CAAa0C,CAAAA,CAASmB,CAAY,CAAA,CACzCC,EAAY,IAAA,CAAKpB,CAAO,CAAA,EACjBD,CAAAA,EAAW,CAACC,CAAAA,CACfD,CAAAA,CAAQ,UAAA,EACRzC,CAAAA,CAAO,YAAYyC,CAAO,CAAA,CAEvBA,CAAAA,EAAWC,CAAAA,GAClBe,EAAUhB,CAAAA,CAASC,CAAAA,CAAS1C,CAAiB,CAAA,CAC7C8D,CAAAA,CAAY,IAAA,CAAKrB,CAAO,CAAA,EAEhC,CAEA,OAAOqB,CACX,CAEO,SAASC,EAAOC,CAAAA,CAAUC,CAAAA,CAAwB,CACrDA,CAAAA,CAAU,UAAY,EAAA,CAElB,OAAOD,CAAAA,EAAQ,UAAA,GACfA,EAAM,CAAE,IAAA,CAAMA,CAAAA,CAAK,KAAA,CAAO,EAAC,CAAG,QAAA,CAAU,EAAC,CAAG,IAAK,MAAU,CAAA,CAAA,CAG/D1C,CAAAA,CAAW0C,CAAAA,CAAKC,CAAS,EAC7B","file":"chunk-PUXZJ7OV.js","sourcesContent":["import { pushContext } from '../core/context'\nimport { runWithComponent, type ComponentInstance } from '../core/hook'\nimport { unsafeEffect } from '../core/lifecycle'\n\n// Extended ComponentInstance for DOM tracking\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 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 instance.children.forEach(child => {\n removeComponentInstance(child)\n })\n\n instance.nodes.forEach(node => {\n if (node.parentNode) {\n node.parentNode.removeChild(node)\n }\n })\n\n instance.children.clear()\n\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\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 const hasExplicitKey = fnode.key !== undefined\n\n if (!instanceRegistry.has(effectiveRegistryParent)) {\n instanceRegistry.set(effectiveRegistryParent, new Map())\n }\n const parentRegistry = instanceRegistry.get(effectiveRegistryParent)!\n\n let key: any\n if (hasExplicitKey) {\n key = fnode.key\n } else {\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 if (parentRegistry.has(key)) {\n const instance = parentRegistry.get(key)!\n instance.fnode = fnode\n const newProps = mergeProps(fnode)\n instance.props = newProps\n instance.children.clear()\n\n if (instance.renderFn) {\n instance.renderFn()\n }\n\n return instance.nodes\n }\n\n const instance: DOMComponentInstance = {\n hooks: [],\n hookIndex: 0,\n nodes: [],\n parent,\n fnode: fnode,\n props: mergeProps(fnode),\n key,\n children: new Set(),\n parentInstance: currentRenderingInstance || undefined\n }\n\n if (currentRenderingInstance) {\n currentRenderingInstance.children.add(instance)\n }\n\n parentRegistry.set(key, instance)\n\n let isFirstRender = true\n\n const renderFn = () => {\n const currentFnode = instance.fnode\n const currentProps = instance.props\n\n const isProvider = (currentFnode.type as any)._contextId !== undefined\n if (isProvider) {\n pushContext((currentFnode.type as any)._contextId, currentProps.value)\n }\n\n const previousRenderingInstance = currentRenderingInstance\n currentRenderingInstance = instance\n\n const result = runWithComponent(instance, () => currentFnode.type(currentProps))\n\n if (isFirstRender) {\n const newNodes = renderNode(result, parent)\n instance.nodes = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\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 if (instance.nodes.length === 0) {\n const newNodes = renderNode(result, parent)\n instance.nodes = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\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 currentRenderingInstance = previousRenderingInstance\n return\n }\n\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 instance.children.clear()\n\n const tempContainer = document.createElement('div')\n const newNodes = renderNode(result, tempContainer, nodeParent)\n const newNodesArray = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\n\n const reconciledNodes = reconcile(instance.nodes, newNodesArray, nodeParent, marker)\n\n nodeParent.removeChild(marker)\n\n instance.nodes = reconciledNodes\n }\n\n currentRenderingInstance = previousRenderingInstance\n }\n\n instance.renderFn = renderFn\n\n unsafeEffect(renderFn)\n\n return instance.nodes\n}\n\nfunction renderNode(fnode: any, parent: HTMLElement, registryParent?: HTMLElement): Node | Node[] | null {\n const effectiveRegistryParent = registryParent || parent\n\n if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n const node = document.createTextNode('')\n parent.appendChild(node)\n return node\n }\n\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 if (Array.isArray(fnode)) {\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 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 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 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 removeComponentInstance(instance)\n keysToRemove.push(key)\n }\n }\n })\n\n keysToRemove.forEach(key => parentRegistry.delete(key))\n }\n\n return nodes\n }\n\n if (typeof fnode === 'object') {\n if (typeof fnode.type === 'string') {\n const dom = document.createElement(fnode.type)\n\n if (fnode.props) {\n Object.entries(fnode.props).forEach(([key, value]) => {\n if (key === 'ref') {\n // Handle both callback refs and RefObject\n if (typeof value === 'function') {\n value(dom)\n } else if (value && typeof value === 'object' && 'current' in value) {\n value.current = dom\n }\n } else if (key.startsWith('on') && typeof value === 'function') {\n const eventName = key.slice(2).toLowerCase()\n dom.addEventListener(eventName, value as EventListener)\n\n if (!(dom as any).__eventHandlers) {\n (dom as any).__eventHandlers = {}\n }\n (dom as any).__eventHandlers[eventName] = value\n } else if (key !== 'ref') {\n setAttribute(dom, key, value)\n }\n })\n }\n\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 if (typeof fnode.type === 'function') {\n return renderComponent(fnode, parent, registryParent)\n }\n }\n\n return null\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 Object.assign((el as HTMLElement).style, value)\n } else if (key === 'class') {\n el.className = String(value)\n } else if (key in el && typeof (el as any)[key] !== 'function') {\n (el as any)[key] = value\n } else {\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 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 const newAttrs = Array.from(newEl.attributes)\n newAttrs.forEach(attr => {\n if (oldEl.getAttribute(attr.name) !== attr.value) {\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 const oldHandlers = (oldEl as any).__eventHandlers || {}\n const newHandlers = (newEl as any).__eventHandlers || {}\n\n Object.keys(oldHandlers).forEach(event => {\n if (!newHandlers[event]) {\n oldEl.removeEventListener(event, oldHandlers[event])\n }\n })\n\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 if (Object.keys(newHandlers).length > 0) {\n (oldEl as any).__eventHandlers = newHandlers\n } else {\n delete (oldEl as any).__eventHandlers\n }\n\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 oldEl.appendChild(newChild)\n } else if (oldChild && !newChild) {\n oldEl.removeChild(oldChild)\n } else if (oldChild && newChild) {\n patchNode(oldChild, newChild, oldEl)\n }\n }\n}\n\nfunction patchNode(oldNode: Node, newNode: Node, parent: Element): void {\n if (canReuse(oldNode, newNode)) {\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\n if (oldNode.nodeType === Node.TEXT_NODE) {\n if (oldNode.nodeValue !== newNode.nodeValue) {\n oldNode.nodeValue = newNode.nodeValue\n }\n } else if (oldNode.nodeType === Node.ELEMENT_NODE) {\n updateAttributes(oldNode as Element, newNode as Element)\n reconcileChildren(oldNode as Element, newNode as Element)\n }\n } else {\n parent.replaceChild(newNode, oldNode)\n }\n}\n\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 parent.insertBefore(newNode, beforeMarker)\n resultNodes.push(newNode)\n } else if (oldNode && !newNode) {\n if (oldNode.parentNode) {\n parent.removeChild(oldNode)\n }\n } else if (oldNode && newNode) {\n patchNode(oldNode, newNode, parent as Element)\n resultNodes.push(oldNode)\n }\n }\n\n return resultNodes\n}\n\nexport function render(app: any, container: HTMLElement) {\n container.innerHTML = ''\n\n if (typeof app === 'function') {\n app = { type: app, props: {}, children: [], key: undefined }\n }\n\n renderNode(app, container)\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {b}from'./chunk-NRPWBHKP.mjs';import {e,a}from'./chunk-MI76R42D.mjs';var p=new WeakMap,h=null;function E(e){e.children.forEach(n=>{E(n);}),e.nodes.forEach(n=>{n.parentNode&&n.parentNode.removeChild(n);}),e.children.clear(),e.parentInstance&&e.parentInstance.children.delete(e);}function S(e$1,n,o){let c=o||n,r=f=>{let u={...f.props};return f.children&&f.children.length>0&&(u.children=f.children.length===1?f.children[0]:f.children),u},a$1=e$1.key!==void 0;p.has(c)||p.set(c,new Map);let t=p.get(c),i;if(a$1)i=e$1.key;else {let f=0,u=e$1.type.name||"anonymous";t.forEach((b,l)=>{typeof l=="string"&&l.startsWith(`__auto_${u}_`)&&f++;}),i=`__auto_${u}_${f}`;}if(t.has(i)){let f=t.get(i);f.fnode=e$1;let u=r(e$1);return f.props=u,f.children.clear(),f.renderFn&&f.renderFn(),f.nodes}let s={hooks:[],hookIndex:0,nodes:[],parent:n,fnode:e$1,props:r(e$1),key:i,children:new Set,parentInstance:h||void 0};h&&h.children.add(s),t.set(i,s);let d=true,_=()=>{let f=s.fnode,u=s.props;f.type._contextId!==void 0&&e(f.type._contextId,u.value);let l=h;h=s;let v=a(s,()=>f.type(u));if(d){let g=y(v,n);s.nodes=g?Array.isArray(g)?g:[g]:[],s.nodes.forEach(m=>{m.__ownerInstance||(m.__ownerInstance=s);}),d=false;}else {if(s.nodes.length===0){let C=y(v,n);s.nodes=C?Array.isArray(C)?C:[C]:[],h=l;return}let m=s.nodes[0].parentNode;if(!m){h=l;return}let M=document.createComment("flexium-marker"),I=s.nodes[s.nodes.length-1];I.nextSibling?m.insertBefore(M,I.nextSibling):m.appendChild(M),s.children.clear();let x=document.createElement("div"),T=y(v,x,m),O=T?Array.isArray(T)?T:[T]:[],R=P(s.nodes,O,m,M);m.removeChild(M),s.nodes=R;}h=l;};return s.renderFn=_,b(_),s.nodes}function y(e,n,o){let c=o||n;if(e==null||typeof e=="boolean"){let r=document.createTextNode("");return n.appendChild(r),r}if(typeof e=="string"||typeof e=="number"){let r=document.createTextNode(String(e));return n.appendChild(r),r}if(Array.isArray(e)){let r=new Set;p.has(c)&&p.get(c).forEach((s,d)=>r.add(d));let a=[];e.forEach(i=>{let s=y(i,n,o);s&&(Array.isArray(s)?a.push(...s):a.push(s));});let t=new Set;if(p.has(c)&&p.get(c).forEach((s,d)=>t.add(d)),p.has(c)){let i=p.get(c),s=[];r.forEach(d=>{if(!t.has(d)){let _=i.get(d);_&&(E(_),s.push(d));}}),s.forEach(d=>i.delete(d));}return a}if(typeof e=="object"){if(typeof e.type=="string"){let r=document.createElement(e.type);return e.props&&Object.entries(e.props).forEach(([a,t])=>{if(a==="ref")typeof t=="function"?t(r):t&&typeof t=="object"&&"current"in t&&(t.current=r);else if(a.startsWith("on")&&typeof t=="function"){let i=a.slice(2).toLowerCase();r.addEventListener(i,t),r.__eventHandlers||(r.__eventHandlers={}),r.__eventHandlers[i]=t;}else a!=="ref"&&D(r,a,t);}),e.children&&e.children.length>0&&e.children.forEach(a=>{y(a,r);}),n.appendChild(r),r}if(typeof e.type=="function")return S(e,n,o)}return null}function D(e,n,o){o==null?e.removeAttribute(n):n==="style"&&typeof o=="object"?Object.assign(e.style,o):n==="class"?e.className=String(o):n in e&&typeof e[n]!="function"?e[n]=o:e.setAttribute(n,String(o));}function j(e,n){return e.nodeType!==n.nodeType?false:e.nodeType===Node.ELEMENT_NODE&&n.nodeType===Node.ELEMENT_NODE?e.tagName===n.tagName:true}function k(e,n){Array.from(e.attributes).forEach(t=>{n.hasAttribute(t.name)||e.removeAttribute(t.name);}),Array.from(n.attributes).forEach(t=>{e.getAttribute(t.name)!==t.value&&(t.name==="value"&&"value"in e?e.value=t.value:t.name==="checked"&&"checked"in e?e.checked=t.value==="true"||t.value==="":e.setAttribute(t.name,t.value));});let r=e.__eventHandlers||{},a=n.__eventHandlers||{};Object.keys(r).forEach(t=>{a[t]||e.removeEventListener(t,r[t]);}),Object.keys(a).forEach(t=>{r[t]!==a[t]&&(r[t]&&e.removeEventListener(t,r[t]),e.addEventListener(t,a[t]));}),Object.keys(a).length>0?e.__eventHandlers=a:delete e.__eventHandlers,e instanceof HTMLInputElement&&n instanceof HTMLInputElement&&(e.value!==n.value&&(e.value=n.value),e.checked!==n.checked&&(e.checked=n.checked)),e instanceof HTMLTextAreaElement&&n instanceof HTMLTextAreaElement&&e.value!==n.value&&(e.value=n.value),e instanceof HTMLSelectElement&&n instanceof HTMLSelectElement&&e.value!==n.value&&(e.value=n.value);}function F(e,n){let o=Array.from(e.childNodes),c=Array.from(n.childNodes),r=Math.max(o.length,c.length);for(let a=0;a<r;a++){let t=o[a],i=c[a];!t&&i?e.appendChild(i):t&&!i?e.removeChild(t):t&&i&&H(t,i,e);}}function H(e,n,o){if(j(e,n)){let c=n.__ownerInstance;if(c){let r=c.nodes.indexOf(n);r!==-1&&(c.nodes[r]=e),e.__ownerInstance=c,delete n.__ownerInstance;}e.nodeType===Node.TEXT_NODE?e.nodeValue!==n.nodeValue&&(e.nodeValue=n.nodeValue):e.nodeType===Node.ELEMENT_NODE&&(k(e,n),F(e,n));}else o.replaceChild(n,e);}function P(e,n,o,c){let r=Math.max(e.length,n.length),a=[];for(let t=0;t<r;t++){let i=e[t],s=n[t];!i&&s?(o.insertBefore(s,c),a.push(s)):i&&!s?i.parentNode&&o.removeChild(i):i&&s&&(H(i,s,o),a.push(i));}return a}function $(e,n){n.innerHTML="",typeof e=="function"&&(e={type:e,props:{},children:[],key:void 0}),y(e,n);}export{P as a,$ as b};//# sourceMappingURL=chunk-TP5HUAIN.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-TP5HUAIN.mjs.map
|