@buncanvas/core 0.1.2 → 0.1.3
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 +137 -11
- package/index.js +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,23 +1,149 @@
|
|
|
1
|
-
#
|
|
1
|
+
# BunCanvas 🎨
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A fast, lightweight 2D graphics canvas binding for the **Bun** JavaScript runtime, powered by native Google Skia rendering.
|
|
4
|
+
|
|
5
|
+
BunCanvas brings hardware-accelerated 2D drawing capabilities directly to desktop applications—without needing a browser, DOM environment, or heavy webview dependencies.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ⚙️ Installation
|
|
10
|
+
|
|
11
|
+
Add `BunCanvas` to your project via Bun:
|
|
4
12
|
|
|
5
13
|
```bash
|
|
6
|
-
bun
|
|
14
|
+
bun add @buncanvas/core
|
|
15
|
+
Note: BunCanvas automatically resolves and installs the matching native binary (.so, .dll, or .dylib) for your platform via optionalDependencies.
|
|
7
16
|
```
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
## 🚀 Quick Start
|
|
19
|
+
Here is a minimal example that opens a window and renders a simple rectangle.
|
|
10
20
|
|
|
11
|
-
```
|
|
12
|
-
|
|
21
|
+
```JavaScript
|
|
22
|
+
import { Window, Canvas } from "@buncanvas/core";
|
|
23
|
+
|
|
24
|
+
// 1. Create a native window
|
|
25
|
+
const win = new Window(800, 600, {
|
|
26
|
+
title: "BunCanvas Quickstart",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 2. Create a 2D drawing canvas matching the window size
|
|
30
|
+
const canvas = new Canvas(800, 600);
|
|
31
|
+
const ctx = canvas.getContext("2d");
|
|
32
|
+
|
|
33
|
+
// 3. Draw onto the canvas context
|
|
34
|
+
ctx.fillStyle = "#3498db";
|
|
35
|
+
ctx.fillRect(50, 50, 200, 150);
|
|
36
|
+
|
|
37
|
+
// 4. Attach the canvas to the window frame
|
|
38
|
+
win.append(canvas);
|
|
13
39
|
```
|
|
14
40
|
|
|
15
|
-
|
|
41
|
+
## 🎨 Code Examples
|
|
42
|
+
1. Animated Bouncing Ball (Render Loop)
|
|
43
|
+
Use requestAnimationFrame to manage a smooth render loop for real-time graphics and physics.
|
|
16
44
|
|
|
17
|
-
```
|
|
18
|
-
|
|
45
|
+
```JavaScript
|
|
46
|
+
import { Window, Canvas } from "@buncanvas/core";
|
|
47
|
+
|
|
48
|
+
const WIDTH = 800;
|
|
49
|
+
const HEIGHT = 600;
|
|
50
|
+
|
|
51
|
+
const win = new Window(WIDTH, HEIGHT, { title: "Animation Example" });
|
|
52
|
+
const canvas = new Canvas(WIDTH, HEIGHT);
|
|
53
|
+
const ctx = canvas.getContext("2d");
|
|
54
|
+
|
|
55
|
+
win.append(canvas);
|
|
56
|
+
|
|
57
|
+
// Ball state
|
|
58
|
+
let x = 100;
|
|
59
|
+
let y = 100;
|
|
60
|
+
let vx = 4;
|
|
61
|
+
let vy = 3;
|
|
62
|
+
const radius = 25;
|
|
63
|
+
|
|
64
|
+
function render(timestamp) {
|
|
65
|
+
// Clear screen
|
|
66
|
+
ctx.fillStyle = "#1e1e2e";
|
|
67
|
+
ctx.fillRect(0, 0, WIDTH, HEIGHT);
|
|
68
|
+
|
|
69
|
+
// Update position
|
|
70
|
+
x += vx;
|
|
71
|
+
y += vy;
|
|
72
|
+
|
|
73
|
+
// Bounce off edges
|
|
74
|
+
if (x - radius < 0 || x + radius > WIDTH) vx *= -1;
|
|
75
|
+
if (y - radius < 0 || y + radius > HEIGHT) vy *= -1;
|
|
76
|
+
|
|
77
|
+
// Draw circle
|
|
78
|
+
ctx.beginPath();
|
|
79
|
+
ctx.arc(x, y, radius, 0, Math.PI * 2);
|
|
80
|
+
ctx.fillStyle = "#ff5555";
|
|
81
|
+
ctx.fill();
|
|
82
|
+
ctx.lineWidth = 3;
|
|
83
|
+
ctx.strokeStyle = "#ffffff";
|
|
84
|
+
ctx.stroke();
|
|
85
|
+
|
|
86
|
+
// Schedule next frame
|
|
87
|
+
requestAnimationFrame(render);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Start loop
|
|
91
|
+
requestAnimationFrame(render);
|
|
19
92
|
```
|
|
20
93
|
|
|
21
|
-
|
|
94
|
+
## 2. Gradient & Path Drawing
|
|
95
|
+
BunCanvas supports complex paths, transformations, and gradient shaders.
|
|
96
|
+
|
|
97
|
+
```JavaScript
|
|
98
|
+
import { Window, Canvas } from "@buncanvas/core";
|
|
99
|
+
|
|
100
|
+
const win = new Window(600, 600, { title: "Gradient & Paths" });
|
|
101
|
+
const canvas = new Canvas(600, 600);
|
|
102
|
+
const ctx = canvas.getContext("2d");
|
|
103
|
+
|
|
104
|
+
// Create linear gradient
|
|
105
|
+
const gradient = ctx.createLinearGradient(0, 0, 600, 600);
|
|
106
|
+
gradient.addColorStop(0, "#8e44ad");
|
|
107
|
+
gradient.addColorStop(1, "#f39c12");
|
|
108
|
+
|
|
109
|
+
ctx.fillStyle = gradient;
|
|
110
|
+
ctx.fillRect(0, 0, 600, 600);
|
|
111
|
+
|
|
112
|
+
// Draw a star shape
|
|
113
|
+
ctx.save();
|
|
114
|
+
ctx.translate(300, 300);
|
|
115
|
+
ctx.fillStyle = "#ffffff";
|
|
116
|
+
ctx.beginPath();
|
|
117
|
+
|
|
118
|
+
for (let i = 0; i < 5; i++) {
|
|
119
|
+
ctx.lineTo(Math.cos(((18 + i * 72) * Math.PI) / 180) * 120, -Math.sin(((18 + i * 72) * Math.PI) / 180) * 120);
|
|
120
|
+
ctx.lineTo(Math.cos(((54 + i * 72) * Math.PI) / 180) * 50, -Math.sin(((54 + i * 72) * Math.PI) / 180) * 50);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
ctx.closePath();
|
|
124
|
+
ctx.fill();
|
|
125
|
+
ctx.restore();
|
|
126
|
+
|
|
127
|
+
win.append(canvas);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## 🛠️ API Reference Summary
|
|
131
|
+
`new Window(width, height, options)` Creates a desktop window frame.
|
|
132
|
+
|
|
133
|
+
`width`: number - Initial window width in pixels.
|
|
134
|
+
|
|
135
|
+
`height`: number - Initial window height in pixels.
|
|
136
|
+
|
|
137
|
+
`options`: object (Optional)
|
|
138
|
+
|
|
139
|
+
`title`: string - Title bar text.
|
|
140
|
+
|
|
141
|
+
`window.append(canvas)`: Binds a Canvas instance to render inside the window viewport.
|
|
142
|
+
|
|
143
|
+
`new Canvas(width, height)` Creates an off-screen 2D drawing surface.
|
|
144
|
+
|
|
145
|
+
`canvas.getContext('2d')`: Returns the 2D rendering context supporting standard canvas operations (fillRect, arc, save, restore, etc.).
|
|
146
|
+
|
|
147
|
+
`requestAnimationFrame(callback)` Schedules a frame update for continuous rendering.
|
|
22
148
|
|
|
23
|
-
|
|
149
|
+
Refer to <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D">CanvasRenderingContext2D</a> for other drawing methods.
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var U=import.meta.require;import{createHash as dt}from"crypto";import{basename as pt,join as gt}from"path";import{tmpdir as bt}from"os";import{dlopen as ft,FFIType as Xt,suffix as et}from"bun:ffi";var K;if(!process.argv.includes("--XX:BunCanvas.IgnoreImport"))K=U(`@buncanvas/native-${process.platform}-${process.arch}`);else K=`BunCanvas.${process.arch}.${et}`;console.log(K);if(!K)console.error(`BunCanvas.${process.arch}.${et} binary was not found in the working directory!`),process.exit(-1);var V=K,u=new TextEncoder,tt=new Map;function N(t){let e=tt.get(t);if(e)return e;return e=u.encode(t+"\x00"),tt.set(t,e),e}var n=ft(V,{glfw_init:{args:[],returns:"void"},get_wPropertiesViewer:{args:[],returns:"ptr"},get_mMoveViewer:{args:[],returns:"ptr"},get_mClickViewer:{args:[],returns:"ptr"},get_mDownViewer:{args:[],returns:"ptr"},get_mUpViewer:{args:[],returns:"ptr"},get_kDownViewer:{args:[],returns:"ptr"},get_kUpViewer:{args:[],returns:"ptr"},get_mWheelViewer:{args:[],returns:"ptr"},signal_frame_ready:{args:[],returns:"void"},set_vsync:{args:["bool"],returns:"void"},create_window:{args:["int","int","cstring"],returns:"void"},update_window:{args:["ptr"],returns:"void"},destroy_window:{args:[],returns:"void"},canvas_init_gpu_context:{args:[],returns:"bool"},canvas_flush_gpu:{args:[],returns:"void"},canvas_create:{args:["int","int","bool"],returns:"ptr"},canvas_resize:{args:["ptr","int","int"],returns:"void"},canvas_append:{args:["ptr"],returns:"void"},canvas_get_context2D:{args:["ptr","ptr","bool","bool"],returns:"ptr"},canvas_set_fill_style:{args:["ptr","cstring"],returns:"bool"},canvas_set_fill_style_gradient:{args:["ptr","int","ptr","int","ptr","ptr"],returns:"bool"},canvas_set_stroke_style:{args:["ptr","cstring"],returns:"bool"},canvas_set_stroke_style_gradient:{args:["ptr","int","ptr","int","ptr","ptr"],returns:"bool"},canvas_set_stroke_width:{args:["ptr","float"],returns:"bool"},canvas_fill_rect:{args:["ptr","int","int","int","int"],returns:"void"},canvas_stroke_rect:{args:["ptr","int","int","int","int"],returns:"void"},canvas_clear_rect:{args:["ptr","int","int","int","int"],returns:"void"},canvas_path_begin:{args:["ptr"],returns:"void"},canvas_path_move_to:{args:["ptr","int","int"],returns:"void"},canvas_path_line_to:{args:["ptr","int","int"],returns:"void"},canvas_path_arc:{args:["ptr","float","float","float","float","float"],returns:"void"},canvas_path_arc_to:{args:["ptr","float","float","float","float","float"],returns:"void"},canvas_path_bezier_to:{args:["ptr","float","float","float","float","float","float"],returns:"void"},canvas_path_quad_to:{args:["ptr","float","float","float","float"],returns:"void"},canvas_path_ellipse:{args:["ptr","float","float","float","float","float","float","float","bool"],returns:"void"},canvas_path_fill:{args:["ptr","ptr"],returns:"void"},canvas_path_stroke:{args:["ptr","ptr"],returns:"void"},canvas_path_close:{args:["ptr"],returns:"void"},canvas_path_rect:{args:["ptr","float","float","float","float"],returns:"void"},canvas_path_roundrect:{args:["ptr","float","float","float","float","float"],returns:"void"},canvas_path_roundrect_array:{args:["ptr","float","float","float","float","ptr","int"],returns:"void"},canvas_set_composite_operation:{args:["ptr","cstring"],returns:"bool"},canvas_draw_image_imageType:{args:["ptr","ptr","ptr","int"],returns:"void"},canvas_draw_image_canvasType:{args:["ptr","ptr","ptr","int"],returns:"void"},canvas_get_image_data:{args:["ptr","int","int","int","int","ptr"],returns:"bool"},canvas_put_image_data:{args:["ptr","int","int","int","int","ptr"],returns:"bool"},canvas_set_global_alpha:{args:["ptr","float"],returns:"float"},canvas_save:{args:["ptr"],returns:"float"},canvas_restore:{args:["ptr"],returns:"float"},canvas_translate:{args:["ptr","float","float"],returns:"void"},canvas_rotate:{args:["ptr","float"],returns:"float"},canvas_set_font:{args:["ptr","cstring"],returns:"bool"},canvas_fill_text:{args:["ptr","cstring","float","float","float"],returns:"void"},canvas_stroke_text:{args:["ptr","cstring","float","float","float"],returns:"void"},canvas_set_shadow_blur:{args:["ptr","float"],returns:"void"},canvas_set_shadow_color:{args:["ptr","cstring"],returns:"void"},canvas_set_shadow_offsetX:{args:["ptr","float"],returns:"void"},canvas_set_shadow_offsetY:{args:["ptr","float"],returns:"void"},canvas_set_image_smoothing_quality:{args:["ptr","int"],returns:"bool"},canvas_set_image_smoothing_enabled:{args:["ptr","bool"],returns:"bool"},canvas_get_transform:{args:["ptr","ptr"],returns:"void"},canvas_set_transform:{args:["ptr","ptr"],returns:"void"},canvas_reset_transform:{args:["ptr"],returns:"void"},canvas_set_filter:{args:["ptr","cstring"],returns:"bool"},canvas_set_line_dash:{args:["ptr","ptr","int","float"],returns:"bool"},canvas_set_line_join:{args:["ptr","int"],returns:"bool"},canvas_path_clip:{args:["ptr"],returns:"void"},canvas_set_text_baseline:{args:["ptr","int"],returns:"void"},canvas_set_text_align:{args:["ptr","int"],returns:"void"},canvas_measure_text:{args:["ptr","cstring","ptr"],returns:"void"},canvas_destroy:{args:["ptr"],returns:"void"},image_create:{args:[],returns:"ptr"},images_cleanup:{args:[],returns:"void"},image_set_src:{args:["ptr","cstring","bool"],returns:"void"},image_load:{args:["ptr","ptr"],returns:"bool"},image_destroy:{args:["ptr"],returns:"void"},font_load:{args:["cstring"],returns:"ptr"},audio_backend_init:{args:[],returns:"void"},audio_create:{args:["cstring"],returns:"ptr"},audio_set_src:{args:["ptr","cstring"],returns:"void"},audio_play:{args:["ptr"],returns:"void"},audio_stop:{args:["ptr"],returns:"void"},audio_destroy:{args:["ptr"],returns:"void"},path2d_create:{args:[],returns:"ptr"},path2d_create_from_copy:{args:["ptr"],returns:"ptr"},path2d_destroy:{args:["ptr"],returns:"void"},path2d_move_to:{args:["ptr","int","int"],returns:"void"},path2d_line_to:{args:["ptr","int","int"],returns:"void"},path2d_arc:{args:["ptr","float","float","float","float","float"],returns:"void"},path2d_arc_to:{args:["ptr","float","float","float","float","float"],returns:"void"},path2d_bezier_to:{args:["ptr","float","float","float","float","float","float"],returns:"void"},path2d_quad_to:{args:["ptr","float","float","float","float"],returns:"void"},path2d_ellipse:{args:["ptr","float","float","float","float","float","float","float","bool"],returns:"void"},path2d_close:{args:["ptr"],returns:"void"},path2d_rect:{args:["ptr","float","float","float","float"],returns:"void"},path2d_roundrect:{args:["ptr","float","float","float","float","float"],returns:"void"},path2d_roundrect_array:{args:["ptr","float","float","float","float","ptr","int"],returns:"void"},font_add_to_registry:{args:["cstring","ptr"],returns:"void"}});class d{type=null;target=null;timeStamp=performance.now();constructor(t,e){this.type=t,this.target=e}}import{ptr as st}from"bun:ffi";var P=new WeakMap,yt=new FinalizationRegistry((t)=>{n.symbols.image_destroy(t),console.log("destroy!")});function rt(t){let e=dt("sha256").update(t).digest("hex").slice(0,16),s=new URL(t),r=pt(s.pathname)||"index";return gt(bt(),`${e}-${r}`)}function _t(t,e){return(async()=>{let s=e??rt(t),r=await fetch(t);if(!r.ok||!r.body)throw Error(`HTTP ${r.status}: ${t}`);let i=await r.arrayBuffer();return await Bun.write(s,i),s})()}var wt=/^https?:\/\/(?:www\.)?[^\s/$.?#].[^\s]*$/;class T{#t=null;#e=0;#s=!1;#a=0;#l=!1;#i="";constructor(){let t=n.symbols.image_create();P.set(this,t),yt.register(this,t)}onload=null;onerror=null;set src(t){if(this.#i=t,wt.test(t)){let e=new WeakRef(this),s=rt(t),r=P.get(this);n.symbols.image_set_src(r,u.encode(`${s}\x00`),!0),_t(t,s).then(()=>{let i=new Int32Array(2),o=e.deref();if(!o)return;if(n.symbols.image_load(r,st(i)))this.#e=!this.#s?i[0]:this.#e,this.#a=!this.#l?i[1]:this.#a,o.onload?.call(o,new d("load",o));else o.onerror?.call(o,new d("error",o))}).catch((i)=>{let o=e.deref();if(!o)return;o.onerror?.call(o,new d("error",o))}).finally(()=>{});return}else{let e=new WeakRef(this);n.symbols.image_set_src(P.get(this),u.encode(`${t}\x00`),!1);let s=setTimeout(()=>{let r=e.deref();if(!r){clearTimeout(s);return}let i=P.get(r),o=new Int32Array(2);if(n.symbols.image_load(i,st(o)))this.#e=!this.#s?o[0]:this.#e,this.#a=!this.#l?o[1]:this.#a,r.onload?.call(r,new d("load",r));else r.onerror?.call(r,new d("error",r));clearTimeout(s)},0)}}get src(){return this.#i}get ptr(){return P.get(this)}get width(){return this.#e}get height(){return this.#a}set width(t){this.#s=!0,this.#e=t}set height(t){this.#l=!0,this.#a=t}}{let t=T.prototype;for(let e of Object.getOwnPropertyNames(t)){let s=Object.getOwnPropertyDescriptor(t,e);if(e=="constructor"){s&&(s.value.toString=()=>`function ${t.constructor.name}() { [native code] }`);continue}if(typeof s?.value==="function")s.value.toString=()=>`function ${e}() { [native code] }`}}class j{#t="";#e="";_nativePtr=null;constructor(t,e){this.#t=t.toLowerCase(),this.#e=e.trim().replaceAll("url(","").replaceAll('"',"").replaceAll("'","").replaceAll(")","").trim()}get family(){return this.#t}async load(){return new Promise((t,e)=>{if(this._nativePtr=n.symbols.font_load(u.encode(`${this.#e}\x00`)),console.log(this._nativePtr,this.#e),this._nativePtr)t();else e()})}}{let t=j.prototype;for(let e of Object.getOwnPropertyNames(t)){let s=Object.getOwnPropertyDescriptor(t,e);if(e=="constructor"){s&&(s.value.toString=()=>`function ${t.constructor.name}() { [native code] }`);continue}if(typeof s?.value==="function")s.value.toString=()=>`function ${e}() { [native code] }`}}class W{width;actualBoundingBoxLeft;actualBoundingBoxRight;actualBoundingBoxAscent;actualBoundingBoxDescent;fontBoundingBoxAscent;fontBoundingBoxDescent;emHeightAscent;emHeightDescent;alphabeticBaseline;hangingBaseline;ideographicBaseline;constructor(t,e,s,r,i,o,l,h,m,f,g,F){this.width=t,this.actualBoundingBoxLeft=e,this.actualBoundingBoxRight=s,this.actualBoundingBoxAscent=r,this.actualBoundingBoxDescent=i,this.fontBoundingBoxAscent=o,this.fontBoundingBoxDescent=l,this.emHeightAscent=h,this.emHeightDescent=m,this.alphabeticBaseline=f,this.hangingBaseline=g,this.ideographicBaseline=F}}class w extends d{altKey=!1;button=0;buttons=0;clientX=0;clientY=0;movementX=0;movementY=0;ctrlKey=!1;metaKey=!1;screenX=0;screenY=0;shiftKey=!1;constructor(t,e={altKey:!1,button:0,buttons:0,clientX:0,clientY:0,movementX:0,movementY:0,ctrlKey:!1,metaKey:!1,screenX:0,screenY:0,shiftKey:!1,target:null}){super(t,e.target);this.altKey=e.altKey,this.button=e.button,this.buttons=e.buttons,this.clientX=e.clientX,this.clientY=e.clientY,this.movementX=e.movementX,this.movementY=e.movementY,this.ctrlKey=e.ctrlKey,this.metaKey=e.metaKey,this.screenX=e.screenX,this.screenY=e.screenY,this.shiftKey=e.shiftKey}}var z=w.prototype;for(let t of Object.getOwnPropertyNames(z)){let e=Object.getOwnPropertyDescriptor(z,t);if(t=="constructor"){e&&(e.value.toString=()=>`function ${z.constructor.name}() { [native code] }`);continue}if(typeof e?.value==="function")e.value.toString=()=>`function ${t}() { [native code] }`}class I extends w{deltaX=0;deltaY=0;constructor(t,e={altKey:!1,button:0,buttons:0,clientX:0,clientY:0,movementX:0,movementY:0,deltaX:0,deltaY:0,ctrlKey:!1,metaKey:!1,screenX:0,screenY:0,shiftKey:!1,target:null}){super(t,e);this.deltaX=e.deltaX??0,this.deltaY=e.deltaY??0}}var vt={"-1":"Unknown",32:" ",39:"'",44:",",45:"-",46:".",47:"/",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"[",92:"\\",93:"]",96:"`",161:"World1",162:"World2",256:"Escape",257:"Enter",258:"Tab",259:"Backspace",260:"Insert",261:"Delete",262:"ArrowRight",263:"ArrowLeft",264:"ArrowDown",265:"ArrowUp",266:"PageUp",267:"PageDown",268:"Home",269:"End",280:"CapsLock",281:"ScrollLock",282:"NumLock",283:"PrintScreen",284:"Pause",290:"F1",291:"F2",292:"F3",293:"F4",294:"F5",295:"F6",296:"F7",297:"F8",298:"F9",299:"F10",300:"F11",301:"F12",302:"F13",303:"F14",304:"F15",305:"F16",306:"F17",307:"F18",308:"F19",309:"F20",310:"F21",311:"F22",312:"F23",313:"F24",314:"F25",320:"0",321:"1",322:"2",323:"3",324:"4",325:"5",326:"6",327:"7",328:"8",329:"9",330:".",331:"/",332:"*",333:"-",334:"+",335:"Enter",336:"=",340:"Shift",341:"Control",342:"Alt",343:"Meta",344:"Shift",345:"Control",346:"Alt",347:"Meta",348:"ContextMenu"},Ft={"-1":"Unknown",32:" ",39:'"',44:"<",45:"_",46:">",47:"?",48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",91:"{",92:"|",93:"}",96:"~",161:"World1",162:"World2",256:"Escape",257:"Enter",258:"Tab",259:"Backspace",260:"Insert",261:"Delete",262:"ArrowRight",263:"ArrowLeft",264:"ArrowDown",265:"ArrowUp",266:"PageUp",267:"PageDown",268:"Home",269:"End",280:"CapsLock",281:"ScrollLock",282:"NumLock",283:"PrintScreen",284:"Pause",290:"F1",291:"F2",292:"F3",293:"F4",294:"F5",295:"F6",296:"F7",297:"F8",298:"F9",299:"F10",300:"F11",301:"F12",302:"F13",303:"F14",304:"F15",305:"F16",306:"F17",307:"F18",308:"F19",309:"F20",310:"F21",311:"F22",312:"F23",313:"F24",314:"F25",320:"0",321:"1",322:"2",323:"3",324:"4",325:"5",326:"6",327:"7",328:"8",329:"9",330:".",331:"/",332:"*",333:"-",334:"+",335:"Enter",336:"=",340:"Shift",341:"Control",342:"Alt",343:"Meta",344:"Shift",345:"Control",346:"Alt",347:"Meta",348:"ContextMenu"},xt={"-1":"Unknown",32:"Space",39:"Quote",44:"Comma",45:"Minus",46:"Period",47:"Slash",48:"Digit0",49:"Digit1",50:"Digit2",51:"Digit3",52:"Digit4",53:"Digit5",54:"Digit6",55:"Digit7",56:"Digit8",57:"Digit9",59:"Semicolon",61:"Equal",65:"KeyA",66:"KeyB",67:"KeyC",68:"KeyD",69:"KeyE",70:"KeyF",71:"KeyG",72:"KeyH",73:"KeyI",74:"KeyJ",75:"KeyK",76:"KeyL",77:"KeyM",78:"KeyN",79:"KeyO",80:"KeyP",81:"KeyQ",82:"KeyR",83:"KeyS",84:"KeyT",85:"KeyU",86:"KeyV",87:"KeyW",88:"KeyX",89:"KeyY",90:"KeyZ",91:"BracketLeft",92:"Backslash",93:"BracketRight",96:"Backquote",161:"IntlBackslash",256:"Escape",257:"Enter",258:"Tab",259:"Backspace",260:"Insert",261:"Delete",262:"ArrowRight",263:"ArrowLeft",264:"ArrowDown",265:"ArrowUp",266:"PageUp",267:"PageDown",268:"Home",269:"End",280:"CapsLock",281:"ScrollLock",282:"NumLock",283:"PrintScreen",284:"Pause",290:"F1",291:"F2",292:"F3",293:"F4",294:"F5",295:"F6",296:"F7",297:"F8",298:"F9",299:"F10",300:"F11",301:"F12",302:"F13",303:"F14",304:"F15",305:"F16",306:"F17",307:"F18",308:"F19",309:"F20",310:"F21",311:"F22",312:"F23",313:"F24",314:"F25",320:"Numpad0",321:"Numpad1",322:"Numpad2",323:"Numpad3",324:"Numpad4",325:"Numpad5",326:"Numpad6",327:"Numpad7",328:"Numpad8",329:"Numpad9",330:"NumpadDecimal",331:"NumpadDivide",332:"NumpadMultiply",333:"NumpadSubtract",334:"NumpadAdd",335:"NumpadEnter",336:"NumpadEqual",340:"ShiftLeft",341:"ControlLeft",342:"AltLeft",343:"MetaLeft",344:"ShiftRight",345:"ControlRight",346:"AltRight",347:"MetaRight",348:"ContextMenu"};class O extends d{target=null;key="";code="";location=0;repeat=!1;ctrlKey=!1;shiftKey=!1;altKey=!1;metaKey=!1;constructor(t,e={target:null,key:"",code:"",location:0,repeat:!1,ctrlKey:!1,shiftKey:!1,altKey:!1,metaKey:!1},s=null,r=null,i=!1,o=!1,l=!1,h=!1,m=!1){super(t,e?e.target:r);if(e)this.key=e.key,this.code=e.code,this.location=e.location,this.repeat=e.repeat,this.ctrlKey=e.ctrlKey,this.shiftKey=e.shiftKey,this.altKey=e.altKey,this.metaKey=e.metaKey;else{let f=s;if(f>=65&&f<=90){let g=String.fromCharCode(f);this.key=o??e.shiftKey?g:g.toLowerCase()}else this.key=o??e.shiftKey?Ft[s]:vt[s];this.code=xt[s],this.location=0,this.repeat=!1,this.shiftKey=o,this.ctrlKey=l,this.altKey=h,this.metaKey=m}}}import{ptr as y,JSCallback as Ct}from"bun:ffi";class L{width;height;data;constructor(t,e,s){this.width=t,this.height=e,this.data=s}}import{ptr as kt}from"bun:ffi";function Mt(t){return t==null||Array.isArray(t)||ArrayBuffer.isView(t)&&!(t instanceof DataView)}function v(t,e){let s=new Float64Array(16);return s[0]=t[0]*e[0]+t[1]*e[4]+t[2]*e[8]+t[3]*e[12],s[1]=t[0]*e[1]+t[1]*e[5]+t[2]*e[9]+t[3]*e[13],s[2]=t[0]*e[2]+t[1]*e[6]+t[2]*e[10]+t[3]*e[14],s[3]=t[0]*e[3]+t[1]*e[7]+t[2]*e[11]+t[3]*e[15],s[4]=t[4]*e[0]+t[5]*e[4]+t[6]*e[8]+t[7]*e[12],s[5]=t[4]*e[1]+t[5]*e[5]+t[6]*e[9]+t[7]*e[13],s[6]=t[4]*e[2]+t[5]*e[6]+t[6]*e[10]+t[7]*e[14],s[7]=t[4]*e[3]+t[5]*e[7]+t[6]*e[11]+t[7]*e[15],s[8]=t[8]*e[0]+t[9]*e[4]+t[10]*e[8]+t[11]*e[12],s[9]=t[8]*e[1]+t[9]*e[5]+t[10]*e[9]+t[11]*e[13],s[10]=t[8]*e[2]+t[9]*e[6]+t[10]*e[10]+t[11]*e[14],s[11]=t[8]*e[3]+t[9]*e[7]+t[10]*e[11]+t[11]*e[15],s[12]=t[12]*e[0]+t[13]*e[4]+t[14]*e[8]+t[15]*e[12],s[13]=t[12]*e[1]+t[13]*e[5]+t[14]*e[9]+t[15]*e[13],s[14]=t[12]*e[2]+t[13]*e[6]+t[14]*e[10]+t[15]*e[14],s[15]=t[12]*e[3]+t[13]*e[7]+t[14]*e[11]+t[15]*e[15],s}function c(t,e){throw SyntaxError(`Failed to execute '${t}' on 'DOMMatrix': Failed to parse '${e}'.`)}class b{#t=new Float64Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);#e=!0;#s(){this.#e=this.#t[0]==1&&this.#t[1]==0&&this.#t[2]==0&&this.#t[3]==0&&this.#t[4]==0&&this.#t[5]==1&&this.#t[6]==0&&this.#t[7]==0&&this.#t[8]==0&&this.#t[9]==0&&this.#t[10]==1&&this.#t[11]==0&&this.#t[12]==0&&this.#t[13]==0&&this.#t[14]==0&&this.#t[15]==1}get a(){return this.m11}set a(t){this.m11=t}get b(){return this.m12}set b(t){this.m12=t}get c(){return this.m21}set c(t){this.m21=t}get d(){return this.m22}set d(t){this.m22=t}get e(){return this.m41}set e(t){this.m41=t}get f(){return this.m42}set f(t){this.m42=t}is2D=!0;get isIdentity(){return this.#e}get m11(){return this.#t[0]}set m11(t){if(this.#t[0]=t,!this.#e){if(t==1)this.#s()}else if(t!=1)this.#e=!1}get m12(){return this.#t[4]}set m12(t){if(this.#t[4]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m13(){return this.#t[8]}set m13(t){if(this.#t[8]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m14(){return this.#t[12]}set m14(t){if(this.#t[12]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m21(){return this.#t[1]}set m21(t){if(this.#t[1]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m22(){return this.#t[5]}set m22(t){if(this.#t[5]=t,!this.#e){if(t==1)this.#s()}else if(t!=1)this.#e=!1}get m23(){return this.#t[9]}set m23(t){if(this.#t[9]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m24(){return this.#t[13]}set m24(t){if(this.#t[13]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m31(){return this.#t[2]}set m31(t){if(this.#t[2]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m32(){return this.#t[6]}set m32(t){if(this.#t[6]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m33(){return this.#t[10]}set m33(t){if(this.#t[10]=t,!this.#e){if(t==1)this.#s()}else if(t!=1)this.#e=!1}get m34(){return this.#t[14]}set m34(t){if(this.#t[14]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m41(){return this.#t[3]}set m41(t){if(this.#t[3]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m42(){return this.#t[7]}set m42(t){if(this.#t[7]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m43(){return this.#t[11]}set m43(t){if(this.#t[11]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m44(){return this.#t[15]}set m44(t){if(this.#t[15]=t,!this.#e){if(t==1)this.#s()}else if(t!=1)this.#e=!1}multiplySelf(t){let e=this.#t,s=t.#t;return this.#t.set(v(e,s)),this.is2D&&=t.is2D,this}preMultiplySelf(t){let e=this.#t,s=t.#t;return this.#t.set(v(s,e)),this.is2D&&=t.is2D,this}translateSelf(t=0,e=0,s=0){let r=new Float64Array([1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1]);if(this.#t.set(v(this.#t,r)),s!==0)this.is2D=!1;return this}scaleSelf(t=1,e=t,s=1,r=0,i=0,o=0){if(r||i||o)this.translateSelf(r,i,o);let l=new Float64Array([t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1]);if(this.#t.set(v(this.#t,l)),r||i||o)this.translateSelf(-r,-i,-o);if(s!==1||o!==0)this.is2D=!1;return this}scale3dSelf(t,e=0,s=0,r=0){return this.scaleSelf(t,t,t,e,s,r)}rotateSelf(...t){if(t[1]===void 0&&t[2]===void 0)t[2]=t[0],t[0]=0,t[1]=0;else t[1]??=0,t[2]??=0;let e=t[0]*Math.PI/180,s=t[1]*Math.PI/180,r=t[2]*Math.PI/180,i=Math.sin(e),o=Math.cos(e),l=Math.sin(s),h=Math.cos(s),m=Math.sin(r),f=Math.cos(r);if(t[2]!==0)this.#t.set(v(this.#t,new Float64Array([f,-m,0,0,m,f,0,0,0,0,1,0,0,0,0,1])));if(t[1]!==0)this.#t.set(v(new Float64Array([h,0,l,0,0,1,0,0,-l,0,h,0,0,0,0,1]),this.#t));if(t[0]!==0)this.#t.set(v(new Float64Array([1,0,0,0,0,o,-i,0,0,i,o,0,0,0,0,1]),this.#t));if(t[0]!==0||t[1]!==0)this.is2D=!1;return this}rotateAxisAngleSelf(t=0,e=0,s=1,r=0){let i=Math.hypot(t,e,s);if(i===0)return this;t/=i,e/=i,s/=i;let o=r*Math.PI/180,l=Math.sin(o),h=Math.cos(o),m=1-h,f=new Float64Array([m*t*t+h,m*t*e-l*s,m*t*s+l*e,0,m*t*e+l*s,m*e*e+h,m*e*s-l*t,0,m*t*s-l*e,m*e*s+l*t,m*s*s+h,0,0,0,0,1]);if(this.#t.set(v(this.#t,f)),t!==0||e!==0)this.is2D=!1;return this}rotateFromVectorSelf(t=0,e=0){if(t===0&&e===0)return this;let s=Math.atan2(e,t)*180/Math.PI;return this.rotateSelf(s)}skewXSelf(t=0){let e=Math.tan(t*Math.PI/180);return this.#t.set(v(this.#t,new Float64Array([1,e,0,0,0,1,0,0,0,0,1,0,0,0,0,1]))),this}skewYSelf(t=0){let e=Math.tan(t*Math.PI/180);return this.#t.set(v(this.#t,new Float64Array([1,0,0,0,e,1,0,0,0,0,1,0,0,0,0,1]))),this}#a(t){let e=[],s=0;while(s<t.length){while(/\s/.test(t[s]))s++;if(s>=t.length)break;let r=s;while(/[A-Za-z0-9]/.test(t[s]))s++;let i=t.substring(r,s);while(/\s/.test(t[s]))s++;if(t[s]!=="(")return"error";s++;let o=1,l=s;while(s<t.length&&o>0){if(t[s]==="(")o++;else if(t[s]===")")o--;s++}if(o!==0)return"error";e.push({name:i,args:t.substring(l,s-1)})}return e}#l(t){let e=[],s="",r=0;for(let i of t){if(i==="(")r++;if(i===")")r--;if((i===","||/\s/.test(i))&&r===0){if(s.length)e.push(s),s="";continue}s+=i}if(s.length)e.push(s);return e}#i(t){if(t.endsWith("deg"))return Number.parseFloat(t);if(t.endsWith("rad"))return Number.parseFloat(t)*180/Math.PI;if(t.endsWith("grad"))return Number.parseFloat(t)*0.9;if(t.endsWith("turn"))return Number.parseFloat(t)*360;return Number.parseFloat(t)}#o(t){if(!t)return null;let e=16,s=16,r=8,i=8;if(t.endsWith("px"))return Number.parseFloat(t);if(t.endsWith("pt"))return Number.parseFloat(t)*1.3333333730697632;if(t.endsWith("pc"))return Number.parseFloat(t)*16;if(t.endsWith("in"))return Number.parseFloat(t)*96;if(t.endsWith("cm"))return Number.parseFloat(t)*37.79527559055118;if(t.endsWith("mm"))return Number.parseFloat(t)*3.7795275590551185;if(t.endsWith("q"))return Number.parseFloat(t)*0.9448818897637796;if(t.endsWith("em"))return Number.parseFloat(t)*s;if(t.endsWith("rem"))return Number.parseFloat(t)*e;if(t.endsWith("ex"))return Number.parseFloat(t)*r;if(t.endsWith("ch"))return Number.parseFloat(t)*i;if(t.endsWith("%"))return Number.parseFloat(t)*s/100;if(t.endsWith("px"))return Number.parseFloat(t);else if(t.endsWith("pt"))return Number.parseFloat(t)*1.3333333730697632;return null}setMatrixValue(t){if(t=t.trim(),t.length===0)throw new DOMException("Invalid transform.","SyntaxError");let e=this.#a(t);if(e=="error"){c("setMatrixValue",t);return}for(let s of e){let r=this.#l(s.args);switch(s.name){case"matrix":{if(r.length!==6)throw new DOMException("matrix() requires 6 arguments.","SyntaxError");let i=Number.parseFloat(r[0]),o=Number.parseFloat(r[1]),l=Number.parseFloat(r[2]),h=Number.parseFloat(r[3]);if(isNaN(i)||isNaN(o)||isNaN(l)||isNaN(h))c("setMatrixValue",t);this.a=i,this.b=o,this.c=l,this.d=h,this.e=this.#o(r[4]),this.f=this.#o(r[5]),this.is2D=!0;break}case"matrix3d":{if(r.length!==16)c("setMatrixValue",t);for(let i=0;i<16;i++)this.#t[i]=Number.parseFloat(r[i]);this.is2D=!1;break}case"translate":{if(r.length<1||r.length>2)c("setMatrixValue",t);let i=this.#o(r[0]),o=this.#o(r[1]);if(!i){c("setMatrixValue",t);return}let l=i,h=r.length===2?o??0:0;this.translateSelf(l,h);break}case"translateX":{if(r.length!==1)c("setMatrixValue",t);let i=this.#o(r[0]);if(!i){c("setMatrixValue",t);return}this.translateSelf(i,0);break}case"translateY":{if(r.length!==1)c("setMatrixValue",t);let i=this.#o(r[0]);if(!i){c("setMatrixValue",t);return}this.translateSelf(0,i);break}case"translateZ":{if(r.length!==1)c("setMatrixValue",t);let i=this.#o(r[0]);if(!i){c("setMatrixValue",t);return}this.translateSelf(0,0,i);break}case"translate3d":{if(r.length!==3)c("setMatrixValue",t);let i=this.#o(r[0]),o=this.#o(r[0]),l=this.#o(r[0]);if(!i||!o||!l){c("setMatrixValue",t);return}this.translateSelf(i,o,l);break}case"scale":{if(r.length<1||r.length>2)c("setMatrixValue",t);let i=Number.parseFloat(r[0]),o=r.length===2?Number.parseFloat(r[1]):i;this.scaleSelf(i,o);break}case"scaleX":{if(r.length!==1)c("setMatrixValue",t);this.scaleSelf(Number.parseFloat(r[0]),1);break}case"scaleY":{if(r.length!==1)c("setMatrixValue",t);this.scaleSelf(1,Number.parseFloat(r[0]));break}case"scaleZ":{if(r.length!==1)c("setMatrixValue",t);this.scaleSelf(1,1,Number.parseFloat(r[0]));break}case"scale3d":{if(r.length!==3)c("setMatrixValue",t);this.scale3dSelf(Number.parseFloat(r[0]),Number.parseFloat(r[1]),Number.parseFloat(r[2]));break}case"rotate":{if(r.length!==1)c("setMatrixValue",t);this.rotateSelf(this.#i(r[0]));break}case"rotateX":{if(r.length!==1)c("setMatrixValue",t);this.rotateSelf(this.#i(r[0]),0,0);break}case"rotateY":{if(r.length!==1)c("setMatrixValue",t);this.rotateSelf(0,this.#i(r[0]),0);break}case"rotateZ":{if(r.length!==1)c("setMatrixValue",t);this.rotateSelf(0,0,this.#i(r[0]));break}case"rotate3d":{if(r.length!==4)c("setMatrixValue",t);this.rotateAxisAngleSelf(Number.parseFloat(r[0]),Number.parseFloat(r[1]),Number.parseFloat(r[2]),this.#i(r[3]));break}case"skew":{if(r.length<1||r.length>2)c("setMatrixValue",t);if(this.skewXSelf(this.#i(r[0])),r.length===2)this.skewYSelf(this.#i(r[1]));break}case"skewX":{if(r.length!==1)c("setMatrixValue",t);this.skewXSelf(this.#i(r[0]));break}case"skewY":{if(r.length!==1)c("setMatrixValue",t);this.skewYSelf(this.#i(r[0]));break}case"perspective":{if(r.length!==1)c("setMatrixValue",t);let i=this.#o(r[0]);if(i===0||!i){c("setMatrixValue",t);return}this.#t.set(v(this.#t,new Float64Array([1,0,0,0,0,1,0,0,0,0,1,-1/i,0,0,0,1]))),this.is2D=!1;break}default:c("setMatrixValue",t)}}return this}toString(){return this.is2D?`matrix(${this.a}, ${this.b}, ${this.c}, ${this.d}, ${this.e}, ${this.f})`:`matrix3d(${this.m11}, ${this.m12}, ${this.m13}, ${this.m14}, ${this.m21}, ${this.m22}, ${this.m23}, ${this.m24}, ${this.m31}, ${this.m32}, ${this.m33}, ${this.m34}, ${this.m41}, ${this.m42}, ${this.m43}, ${this.m44})`}constructor(...t){if(!Mt(t[0]))throw SyntaxError(`Failed to construct 'DOMMatrix': Failed to parse '${t[0]}'.`);if(t[0]){let e=t[0].length;if(e!=6&&e!=16)throw TypeError("Failed to construct 'DOMMatrix': The sequence must contain 6 elements for a 2D matrix or 16 elements for a 3D matrix.");let s=t[0];if(e==6)this.a=s[0],this.b=s[1],this.c=s[2],this.d=s[3],this.e=s[4],this.f=s[5];else{let r=0;for(let i of s)this.#t[r]=i,r++}this.#e=s[0]==1&&s[1]==0&&s[2]==0&&s[3]==0&&s[4]==0&&s[5]==1&&s[6]==0&&s[7]==0&&s[8]==0&&s[9]==0&&s[10]==1&&s[11]==0&&s[12]==0&&s[13]==0&&s[14]==0&&s[15]==1}}get ptr(){return kt(this.#t)}static fromFloat32Array(t){if(t instanceof Float32Array)return new b(t);throw TypeError("Failed to execute 'fromFloat32Array' on 'DOMMatrix': parameter 1 is not of type 'Float32Array'.")}static fromFloat64Array(t){if(t instanceof Float64Array)return new b(t);throw TypeError("Failed to execute 'fromFloat64Array' on 'DOMMatrix': parameter 1 is not of type 'Float64Array'.")}static fromMatrix(t){if(!t)return new b;if(t.a!=t.m11||t.b!=t.m21||t.c!=t.m12||t.d!=t.m22||t.e!=t.m41||t.f!=t.m42)throw TypeError("Failed to execute 'fromMatrix' on 'DOMMatrix': Property mismatch on matrix initialization.");let e=t.a??void 0,s=t.b??void 0,r=t.c??void 0,i=t.d??void 0,o=t.e??void 0,l=t.f??void 0,h=t.m11??e??1,m=t.m12??s??0,f=t.m13??0,g=t.m14??0,F=t.m21??r??0,_=t.m22??i??1,x=t.m23??0,S=t.m24??0,k=t.m31??0,G=t.m32??0,C=t.m33??1,lt=t.m34??0,ht=t.m41??o??0,ct=t.m42??l??0,mt=t.m43??0,ut=t.m44??1;return new b([h,m,f,g,F,_,x,S,k,G,C,lt,ht,ct,mt,ut])}}var H=b.prototype;for(let t of Object.getOwnPropertyNames(H)){let e=Object.getOwnPropertyDescriptor(H,t);if(t=="constructor"){e&&(e.value.toString=()=>`function ${H.constructor.name}() { [native code] }`);continue}if(typeof e?.value==="function")e.value.toString=()=>`function ${t}() { [native code] }`}var St=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]),At=/^#(?:[0-9a-fA-F]{3,4}){1,2}$/,Dt=/^rgba?\(\s*(?:\d+(?:\.\d+)?%?|\.\d+%?)\s*[, ]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?)\s*[, ]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?)(?:\s*[,/]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?))?\s*\)$/i,Et=/^(?:hsl|hsla|hwb)\(\s*(?:\d+(?:\.\d+)?(?:deg|rad|turn)?|\.\d+(?:deg|rad|turn)?)\s*[, ]\s*(?:\d+(?:\.\d+)?%|\.\d+%)\s*[, ]\s*(?:\d+(?:\.\d+)?%|\.\d+%)(?:\s*[,/]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?))?\s*\)$/i;function nt(t){if(typeof t!=="string")return!1;let e=t.trim().toLowerCase();if(e==="")return!1;if(St.has(e))return!0;if(e.startsWith("#"))return At.test(e);return Dt.test(e)||Et.test(e)}var a=new WeakMap,Kt=new FinalizationRegistry((t)=>{n.symbols.canvas_destroy(t),console.log("destroyed Canvas!")});class D{type;points=new Float32Array(6);offsets=[];colors=[];constructor(...t){switch(this.type=t[0],this.type){case 0:{this.points[0]=t[1],this.points[1]=t[2],this.points[2]=t[3],this.points[3]=t[4];break}case 1:{this.points[0]=t[1],this.points[1]=t[2],this.points[2]=t[3],this.points[3]=t[4],this.points[4]=t[5],this.points[5]=t[6];break}case 2:{this.points[0]=t[1],this.points[1]=t[2],this.points[2]=t[3];break}}}addColorStop(t,e){if(t<0||t>1)throw RangeError(`Failed to execute 'addColorStop' on 'CanvasGradient': The provided value (${t}) is outside the range (0.0, 1.0).`);if(!nt(e))throw SyntaxError(`Failed to execute 'addColorStop' on 'CanvasGradient': The value provided ('${e}') could not be parsed as a color.`);let s=this.offsets.findIndex((i)=>i>t),r=s===-1?this.offsets.length:s;this.offsets.splice(r,0,t),this.colors.splice(r,0,N(e))}}class E{lineWidth=0;globalAlpha=1;imageSmoothingQuality="low";imageSmoothingEnabled=!0;fillStyle="#000000";strokeStyle="#000000";compositeOperation="source-over";filter="none";fontCss="10px sans-serif";textBaseline="alphabetic";textAlign="start";lineDash=[];lineDashOffset=0;lineJoin="miter";constructor(t){if(t instanceof E)this.lineWidth=t.lineWidth,this.globalAlpha=t.globalAlpha,this.imageSmoothingQuality=t.imageSmoothingQuality,this.imageSmoothingEnabled=t.imageSmoothingEnabled,this.fillStyle=t.fillStyle,this.strokeStyle=t.strokeStyle,this.compositeOperation=t.compositeOperation,this.filter=t.filter,this.fontCss=t.fontCss,this.textBaseline=t.textBaseline,this.textAlign=t.textAlign,this.lineDash=t.lineDash,this.lineDashOffset=t.lineDashOffset,this.lineJoin=t.lineJoin}copyFrom(t){if(t instanceof E)this.lineWidth=t.lineWidth,this.globalAlpha=t.globalAlpha,this.imageSmoothingQuality=t.imageSmoothingQuality,this.imageSmoothingEnabled=t.imageSmoothingEnabled,this.fillStyle=t.fillStyle,this.strokeStyle=t.strokeStyle,this.compositeOperation=t.compositeOperation,this.filter=t.filter,this.fontCss=t.fontCss,this.textBaseline=t.textBaseline,this.textAlign=t.textAlign,this.lineDash=t.lineDash,this.lineDashOffset=t.lineDashOffset,this.lineJoin=t.lineJoin}}class J{#t=new E;#e=new E;#s;#a(){this.#t=new E}#l(t,e){let s=t.colors.length,r=new BigUint64Array(s);for(let l=0;l<s;l++)r[l]=BigInt(y(t.colors[l]));let i=new Float32Array(t.offsets);return(e?n.symbols.canvas_set_stroke_style_gradient:n.symbols.canvas_set_fill_style_gradient)(a.get(this),t.type,y(t.points),s,y(r),y(i))}get canvas(){return this.#s}set font(t){this.#t.fontCss=t.trim().toLowerCase(),n.symbols.canvas_set_font(a.get(this),u.encode(`${this.#t.fontCss}\x00`))}get font(){return this.#t.fontCss}set fillStyle(t){if(t==this.#t.fillStyle)return;let e=!1;if(typeof t==="string")e=n.symbols.canvas_set_fill_style(a.get(this),N(t));else if(t instanceof D)e=this.#l(t,!1);if(e)this.#t.fillStyle=t}get fillStyle(){return this.#t.fillStyle}set strokeStyle(t){if(t==this.#t.strokeStyle)return;let e=!1;if(typeof t==="string")e=n.symbols.canvas_set_stroke_style(a.get(this),u.encode(`${t.trim()}\x00`));else if(t instanceof D)e=this.#l(t,!0);if(e)this.#t.strokeStyle=t}get strokeStyle(){return this.#t.strokeStyle}set lineWidth(t){let e=t<1?1:t;n.symbols.canvas_set_stroke_width(a.get(this),e),this.#t.lineWidth=e}get lineWidth(){return this.#t.lineWidth}set globalAlpha(t){this.#t.globalAlpha=n.symbols.canvas_set_global_alpha(a.get(this),t)}get globalAlpha(){return this.#t.globalAlpha}set imageSmoothingQuality(t){let e=!1;switch(t){case"low":{e=n.symbols.canvas_set_image_smoothing_quality(a.get(this),1);break}case"medium":{e=n.symbols.canvas_set_image_smoothing_quality(a.get(this),2);break}case"high":{e=n.symbols.canvas_set_image_smoothing_quality(a.get(this),3);break}}if(e)this.#t.imageSmoothingQuality=t}get imageSmoothingQuality(){return this.#t.imageSmoothingQuality}set imageSmoothingEnabled(t){this.#t.imageSmoothingEnabled=n.symbols.canvas_set_image_smoothing_enabled(a.get(this),t)}get imageSmoothingEnabled(){return this.#t.imageSmoothingEnabled}set filter(t){if(n.symbols.canvas_set_filter(a.get(this),u.encode(`${t}\x00`)))this.#t.filter=t}get filter(){return this.#t.filter}set globalCompositeOperation(t){if(n.symbols.canvas_set_composite_operation(a.get(this),u.encode(`${t}\x00`))==!0)this.#t.compositeOperation=t}get globalCompositeOperation(){return this.#t.compositeOperation}fillRect(t,e,s,r){n.symbols.canvas_fill_rect(a.get(this),t,e,s,r)}strokeRect(t,e,s,r){n.symbols.canvas_stroke_rect(a.get(this),t,e,s,r)}clearRect(t,e,s,r){n.symbols.canvas_clear_rect(a.get(this),t,e,s,r)}fillText(t,e,s,r=-1){n.symbols.canvas_fill_text(a.get(this),u.encode(`${t}\x00`),e,s,r)}strokeText(t,e,s,r=-1){n.symbols.canvas_stroke_text(a.get(this),u.encode(`${t}\x00`),e,s,r)}beginPath(){n.symbols.canvas_path_begin(a.get(this))}moveTo(t,e){n.symbols.canvas_path_move_to(a.get(this),t,e)}lineTo(t,e){n.symbols.canvas_path_line_to(a.get(this),t,e)}arc(t,e,s,r,i){n.symbols.canvas_path_arc(a.get(this),t,e,s,r,i)}ellipse(t,e,s,r,i,o,l,h=!1){n.symbols.canvas_path_ellipse(a.get(this),t,e,s,r,i,o,l,h)}arcTo(t,e,s,r,i){n.symbols.canvas_path_arc_to(a.get(this),t,e,s,r,i)}bezierCurveTo(t,e,s,r,i,o){n.symbols.canvas_path_bezier_to(a.get(this),t,e,s,r,i,o)}quadraticCurveTo(t,e,s,r){n.symbols.canvas_path_quad_to(a.get(this),t,e,s,r)}closePath(){n.symbols.canvas_path_close(a.get(this))}rect(t,e,s,r){n.symbols.canvas_path_rect(a.get(this),t,e,s,r)}roundRect(t,e,s,r,i){if(i.constructor.name.toLowerCase().includes("array")){let o=new Float32Array(i);if(o.some(Number.isNaN))return;let l=o.length;n.symbols.canvas_path_roundrect_array(a.get(this),t,e,s,r,y(o),l);return}else n.symbols.canvas_path_roundrect(a.get(this),t,e,s,r,i)}fill(t){n.symbols.canvas_path_fill(a.get(this),t?t.ptr:void 0)}stroke(t){n.symbols.canvas_path_stroke(a.get(this),t?t.ptr:void 0)}set shadowBlur(t){n.symbols.canvas_set_shadow_blur(a.get(this),t)}set shadowColor(t){n.symbols.canvas_set_shadow_color(a.get(this),u.encode(`${t}\x00`))}set shadowOffsetX(t){n.symbols.canvas_set_shadow_offsetX(a.get(this),t)}set shadowOffsetY(t){n.symbols.canvas_set_shadow_offsetY(a.get(this),t)}set lineJoin(t){let e=!1;switch(t){case"round":{e=n.symbols.canvas_set_line_join(a.get(this),1);break}case"bevel":{e=n.symbols.canvas_set_line_join(a.get(this),2);break}case"miter":{e=n.symbols.canvas_set_line_join(a.get(this),3);break}}if(e)this.#t.lineJoin=t}get lineJoin(){return this.#t.lineJoin}drawImage(t,...e){let s=e.length==2?[...e,t.width,t.height]:e,r=new Float32Array(s),i=r.length;if(t instanceof T){n.symbols.canvas_draw_image_imageType(a.get(this),t.ptr,y(r),i);return}if(t instanceof X){n.symbols.canvas_draw_image_canvasType(a.get(this),a.get(t),y(r),i);return}throw TypeError("Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(Image or Canvas)'.")}getImageData(t,e,s,r){let i=new Uint8Array(s*r*4);return n.symbols.canvas_get_image_data(a.get(this),t,e,s,r,y(i)),new L(s,r,i)}putImageData(t,e,s,r=0,i=0,o=t.width,l=t.height){if(!(t instanceof L))throw TypeError("Failed to execute 'putImageData' on 'CanvasRenderingContext2D': parameter 1 is not of type 'ImageData'");n.symbols.canvas_put_image_data(a.get(this),e,s,t.width,t.height,r,i,o,l,y(t.data))}save(){this.#e?.copyFrom(this.#t),n.symbols.canvas_save(a.get(this))}restore(){if(!this.#e)return;this.#t?.copyFrom(this.#e),n.symbols.canvas_restore(a.get(this))}translate(t,e){n.symbols.canvas_translate(a.get(this),t,e)}rotate(t){n.symbols.canvas_rotate(a.get(this),t)}createConicGradient(...t){if(t.length<3)throw TypeError(`Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': 3 arguments required, but only ${t.length} present.`);return new D(2,...t)}createLinearGradient(...t){if(t.length<4)throw TypeError(`Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': 4 arguments required, but only ${t.length} present.`);return new D(0,...t)}createRadialGradient(...t){if(t.length<6)throw TypeError(`Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': 6 arguments required, but only ${t.length} present.`);return new D(1,...t)}getTransform(){let t=new Float32Array(16);return n.symbols.canvas_get_transform(a.get(this),y(t)),new b(t)}setTransform(...t){if(t[0]instanceof b)n.symbols.canvas_set_transform(a.get(this),t[0].ptr);if(t.length==6){let e=new b([t[0],t[1],t[2],t[3],t[4],t[5]]);n.symbols.canvas_set_transform(a.get(this),e.ptr)}if(t.length==16)n.symbols.canvas_set_transform(a.get(this),new b([t[0],t[1],t[2],t[3],t[4],t[5],t[5],t[6],t[7],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15]]).ptr)}transform(t,e,s,r,i,o){let l=this.getTransform(),h=new b([t,e,s,r,i,o]);l.multiplySelf(h),this.setTransform(l)}resetTransform(){n.symbols.canvas_reset_transform(a.get(this))}setLineDash(t){if(t.constructor.name.toLowerCase().includes("array")){let e;if(t.length&1)e=t.concat(Array.from(t));else e=t;let s=new Float32Array(e);if(s.some(Number.isNaN))return;n.symbols.canvas_set_line_dash(a.get(this),y(s),s.length,this.#t.lineDashOffset),this.#t.lineDash=e;return}throw TypeError("Failed to execute 'setLineDash' on 'CanvasRenderingContext2D': The provided value cannot be converted to a sequence.")}getLineDash(){return this.#t.lineDash}clip(){n.symbols.canvas_path_clip(a.get(this))}set lineDashOffset(t){if(this.#t.lineDash.length<=0){this.#t.lineDashOffset=0;return}let e=new Float32Array(this.#t.lineDash);n.symbols.canvas_set_line_dash(a.get(this),y(e),e.length,t),this.#t.lineDashOffset=t}set textBaseline(t){let e=-1;switch(t){case"top":e=0;break;case"hanging":e=1;break;case"middle":e=2;break;case"alphabetic":e=3;break;case"ideographic":e=4;break;case"bottom":e=5;break}if(e!=-1)n.symbols.canvas_set_text_baseline(a.get(this),e)}set textAlign(t){let e=-1;switch(t){case"left":e=0;break;case"right":e=1;break;case"center":e=2;break;case"start":e=3;break;case"end":e=4;break}if(e!=-1)n.symbols.canvas_set_text_align(a.get(this),e)}measureText(t){let e=new Float32Array(12);return n.symbols.canvas_measure_text(a.get(this),u.encode(`${t}\x00`),y(e)),new W(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8],e[9],e[10],e[11])}constructor(t,e,s){let{desynchronized:r=!1,alpha:i=!0}=s??{},o=new Ct(this.#a.bind(this),{args:[],returns:"void"}),l=n.symbols.canvas_get_context2D(t,o.ptr,r,i);this.#s=e,a.set(this,l)}}{let t=J.prototype;for(let e of Object.getOwnPropertyNames(t)){let s=Object.getOwnPropertyDescriptor(t,e);if(e=="constructor"){s&&(s.value.toString=()=>`function ${t.constructor.name}() { [native code] }`);continue}if(typeof s?.value==="function")s.value.toString=()=>`function ${e}() { [native code] }`}}class X{#t=new Float64Array(2);#e={cb:()=>{}};constructor(t=1,e=1,s){this.#t[0]=t,this.#t[1]=e;let{gpu:r=!0}=s??{},i=n.symbols.canvas_create(t,e,r);a.set(this,i),Kt.register(this,i)}get _ptr(){return a.get(this)}set width(t){this.#t[0]=Number.parseInt(t),this.#e.cb(),n.symbols.canvas_resize(a.get(this),this.#t[0],this.#t[1])}set height(t){this.#t[1]=Number.parseInt(t),this.#e.cb(),n.symbols.canvas_resize(a.get(this),this.#t[0],this.#t[1])}get width(){return this.#t[0]}get height(){return this.#t[1]}getContext(t,e){if(t=="2d")return new J(a.get(this),this,e)}getBoundingClientRect(){return{x:0,y:0,width:this.#t[0],height:this.#t[1],top:0,bottom:this.#t[1],left:0,right:this.#t[0]}}}{let t=X.prototype;for(let e of Object.getOwnPropertyNames(t)){let s=Object.getOwnPropertyDescriptor(t,e);if(e=="constructor"){s&&(s.value.toString=()=>`function ${t.constructor.name}() { [native code] }`);continue}if(typeof s?.value==="function")s.value.toString=()=>`function ${e}() { [native code] }`}}import{ptr as Nt}from"bun:ffi";var it=new FinalizationRegistry((t)=>{n.symbols.path2d_destroy(t)}),p=new WeakMap;class Y{constructor(t){if(t&&t instanceof Y){let e=n.symbols.path2d_create_from_copy(t.ptr);p.set(this,e),it.register(this,e)}else{let e=n.symbols.path2d_create();p.set(this,e),it.register(this,e)}}moveTo(t,e){n.symbols.path2d_move_to(p.get(this),t,e)}lineTo(t,e){n.symbols.path2d_line_to(p.get(this),t,e)}arc(t,e,s,r,i){n.symbols.path2d_arc(p.get(this),t,e,s,r,i)}ellipse(t,e,s,r,i,o,l,h=!1){n.symbols.path2d_ellipse(p.get(this),t,e,s,r,i,o,l,h)}arcTo(t,e,s,r,i){n.symbols.path2d_arc_to(p.get(this),t,e,s,r,i)}bezierCurveTo(t,e,s,r,i,o){n.symbols.path2d_bezier_to(p.get(this),t,e,s,r,i,o)}quadraticCurveTo(t,e,s,r){n.symbols.path2d_quad_to(p.get(this),t,e,s,r)}rect(t,e,s,r){n.symbols.path2d_rect(p.get(this),t,e,s,r)}roundRect(t,e,s,r,i){if(i.constructor.name.toLowerCase().includes("array")){let o=new Float32Array(i);if(o.some(Number.isNaN))return;let l=o.length;n.symbols.path2d_roundrect_array(p.get(this),t,e,s,r,Nt(o),l);return}else n.symbols.path2d_rect(p.get(this),t,e,s,r,i)}closePath(){n.symbols.path2d_close(p.get(this))}get ptr(){return p.get(this)}}var Q=Y.prototype;for(let t of Object.getOwnPropertyNames(Q)){let e=Object.getOwnPropertyDescriptor(Q,t);if(t=="constructor"){e&&(e.value.toString=()=>`function ${Q.constructor.name}() { [native code] }`);continue}if(typeof e?.value==="function")e.value.toString=()=>`function ${t}() { [native code] }`}import{dlopen as $t,toArrayBuffer as M}from"bun:ffi";var ot=`import { dlopen, FFIType, JSCallback } from "bun:ffi";
|
|
2
|
+
var U=import.meta.require;import{createHash as pt}from"crypto";import{basename as gt,join as bt}from"path";import{tmpdir as yt}from"os";import{dlopen as ft,FFIType as Yt,suffix as et}from"bun:ffi";import{createRequire as dt}from"module";var D;try{if(!process.argv.includes("--XX:BunCanvas.IgnoreImport"))D=U(`@buncanvas/native-${process.platform}-${process.arch}`);else D=`BunCanvas.${process.arch}.${et}`}catch{D=dt(import.meta.url).resolve(`@buncanvas/native-${process.platform}-${process.arch}`)}console.log(D);if(!D)console.error(`BunCanvas.${process.arch}.${et} binary was not found in the working directory!`),process.exit(-1);var V=D,u=new TextEncoder,tt=new Map;function N(t){let e=tt.get(t);if(e)return e;return e=u.encode(t+"\x00"),tt.set(t,e),e}var n=ft(V,{glfw_init:{args:[],returns:"void"},get_wPropertiesViewer:{args:[],returns:"ptr"},get_mMoveViewer:{args:[],returns:"ptr"},get_mClickViewer:{args:[],returns:"ptr"},get_mDownViewer:{args:[],returns:"ptr"},get_mUpViewer:{args:[],returns:"ptr"},get_kDownViewer:{args:[],returns:"ptr"},get_kUpViewer:{args:[],returns:"ptr"},get_mWheelViewer:{args:[],returns:"ptr"},signal_frame_ready:{args:[],returns:"void"},set_vsync:{args:["bool"],returns:"void"},create_window:{args:["int","int","cstring"],returns:"void"},update_window:{args:["ptr"],returns:"void"},destroy_window:{args:[],returns:"void"},canvas_init_gpu_context:{args:[],returns:"bool"},canvas_flush_gpu:{args:[],returns:"void"},canvas_create:{args:["int","int","bool"],returns:"ptr"},canvas_resize:{args:["ptr","int","int"],returns:"void"},canvas_append:{args:["ptr"],returns:"void"},canvas_get_context2D:{args:["ptr","ptr","bool","bool"],returns:"ptr"},canvas_set_fill_style:{args:["ptr","cstring"],returns:"bool"},canvas_set_fill_style_gradient:{args:["ptr","int","ptr","int","ptr","ptr"],returns:"bool"},canvas_set_stroke_style:{args:["ptr","cstring"],returns:"bool"},canvas_set_stroke_style_gradient:{args:["ptr","int","ptr","int","ptr","ptr"],returns:"bool"},canvas_set_stroke_width:{args:["ptr","float"],returns:"bool"},canvas_fill_rect:{args:["ptr","int","int","int","int"],returns:"void"},canvas_stroke_rect:{args:["ptr","int","int","int","int"],returns:"void"},canvas_clear_rect:{args:["ptr","int","int","int","int"],returns:"void"},canvas_path_begin:{args:["ptr"],returns:"void"},canvas_path_move_to:{args:["ptr","int","int"],returns:"void"},canvas_path_line_to:{args:["ptr","int","int"],returns:"void"},canvas_path_arc:{args:["ptr","float","float","float","float","float"],returns:"void"},canvas_path_arc_to:{args:["ptr","float","float","float","float","float"],returns:"void"},canvas_path_bezier_to:{args:["ptr","float","float","float","float","float","float"],returns:"void"},canvas_path_quad_to:{args:["ptr","float","float","float","float"],returns:"void"},canvas_path_ellipse:{args:["ptr","float","float","float","float","float","float","float","bool"],returns:"void"},canvas_path_fill:{args:["ptr","ptr"],returns:"void"},canvas_path_stroke:{args:["ptr","ptr"],returns:"void"},canvas_path_close:{args:["ptr"],returns:"void"},canvas_path_rect:{args:["ptr","float","float","float","float"],returns:"void"},canvas_path_roundrect:{args:["ptr","float","float","float","float","float"],returns:"void"},canvas_path_roundrect_array:{args:["ptr","float","float","float","float","ptr","int"],returns:"void"},canvas_set_composite_operation:{args:["ptr","cstring"],returns:"bool"},canvas_draw_image_imageType:{args:["ptr","ptr","ptr","int"],returns:"void"},canvas_draw_image_canvasType:{args:["ptr","ptr","ptr","int"],returns:"void"},canvas_get_image_data:{args:["ptr","int","int","int","int","ptr"],returns:"bool"},canvas_put_image_data:{args:["ptr","int","int","int","int","ptr"],returns:"bool"},canvas_set_global_alpha:{args:["ptr","float"],returns:"float"},canvas_save:{args:["ptr"],returns:"float"},canvas_restore:{args:["ptr"],returns:"float"},canvas_translate:{args:["ptr","float","float"],returns:"void"},canvas_rotate:{args:["ptr","float"],returns:"float"},canvas_set_font:{args:["ptr","cstring"],returns:"bool"},canvas_fill_text:{args:["ptr","cstring","float","float","float"],returns:"void"},canvas_stroke_text:{args:["ptr","cstring","float","float","float"],returns:"void"},canvas_set_shadow_blur:{args:["ptr","float"],returns:"void"},canvas_set_shadow_color:{args:["ptr","cstring"],returns:"void"},canvas_set_shadow_offsetX:{args:["ptr","float"],returns:"void"},canvas_set_shadow_offsetY:{args:["ptr","float"],returns:"void"},canvas_set_image_smoothing_quality:{args:["ptr","int"],returns:"bool"},canvas_set_image_smoothing_enabled:{args:["ptr","bool"],returns:"bool"},canvas_get_transform:{args:["ptr","ptr"],returns:"void"},canvas_set_transform:{args:["ptr","ptr"],returns:"void"},canvas_reset_transform:{args:["ptr"],returns:"void"},canvas_set_filter:{args:["ptr","cstring"],returns:"bool"},canvas_set_line_dash:{args:["ptr","ptr","int","float"],returns:"bool"},canvas_set_line_join:{args:["ptr","int"],returns:"bool"},canvas_path_clip:{args:["ptr"],returns:"void"},canvas_set_text_baseline:{args:["ptr","int"],returns:"void"},canvas_set_text_align:{args:["ptr","int"],returns:"void"},canvas_measure_text:{args:["ptr","cstring","ptr"],returns:"void"},canvas_destroy:{args:["ptr"],returns:"void"},image_create:{args:[],returns:"ptr"},images_cleanup:{args:[],returns:"void"},image_set_src:{args:["ptr","cstring","bool"],returns:"void"},image_load:{args:["ptr","ptr"],returns:"bool"},image_destroy:{args:["ptr"],returns:"void"},font_load:{args:["cstring"],returns:"ptr"},audio_backend_init:{args:[],returns:"void"},audio_create:{args:["cstring"],returns:"ptr"},audio_set_src:{args:["ptr","cstring"],returns:"void"},audio_play:{args:["ptr"],returns:"void"},audio_stop:{args:["ptr"],returns:"void"},audio_destroy:{args:["ptr"],returns:"void"},path2d_create:{args:[],returns:"ptr"},path2d_create_from_copy:{args:["ptr"],returns:"ptr"},path2d_destroy:{args:["ptr"],returns:"void"},path2d_move_to:{args:["ptr","int","int"],returns:"void"},path2d_line_to:{args:["ptr","int","int"],returns:"void"},path2d_arc:{args:["ptr","float","float","float","float","float"],returns:"void"},path2d_arc_to:{args:["ptr","float","float","float","float","float"],returns:"void"},path2d_bezier_to:{args:["ptr","float","float","float","float","float","float"],returns:"void"},path2d_quad_to:{args:["ptr","float","float","float","float"],returns:"void"},path2d_ellipse:{args:["ptr","float","float","float","float","float","float","float","bool"],returns:"void"},path2d_close:{args:["ptr"],returns:"void"},path2d_rect:{args:["ptr","float","float","float","float"],returns:"void"},path2d_roundrect:{args:["ptr","float","float","float","float","float"],returns:"void"},path2d_roundrect_array:{args:["ptr","float","float","float","float","ptr","int"],returns:"void"},font_add_to_registry:{args:["cstring","ptr"],returns:"void"}});class d{type=null;target=null;timeStamp=performance.now();constructor(t,e){this.type=t,this.target=e}}import{ptr as st}from"bun:ffi";var P=new WeakMap,_t=new FinalizationRegistry((t)=>{n.symbols.image_destroy(t),console.log("destroy!")});function rt(t){let e=pt("sha256").update(t).digest("hex").slice(0,16),s=new URL(t),r=gt(s.pathname)||"index";return bt(yt(),`${e}-${r}`)}function wt(t,e){return(async()=>{let s=e??rt(t),r=await fetch(t);if(!r.ok||!r.body)throw Error(`HTTP ${r.status}: ${t}`);let i=await r.arrayBuffer();return await Bun.write(s,i),s})()}var vt=/^https?:\/\/(?:www\.)?[^\s/$.?#].[^\s]*$/;class T{#t=null;#e=0;#s=!1;#a=0;#l=!1;#i="";constructor(){let t=n.symbols.image_create();P.set(this,t),_t.register(this,t)}onload=null;onerror=null;set src(t){if(this.#i=t,vt.test(t)){let e=new WeakRef(this),s=rt(t),r=P.get(this);n.symbols.image_set_src(r,u.encode(`${s}\x00`),!0),wt(t,s).then(()=>{let i=new Int32Array(2),o=e.deref();if(!o)return;if(n.symbols.image_load(r,st(i)))this.#e=!this.#s?i[0]:this.#e,this.#a=!this.#l?i[1]:this.#a,o.onload?.call(o,new d("load",o));else o.onerror?.call(o,new d("error",o))}).catch((i)=>{let o=e.deref();if(!o)return;o.onerror?.call(o,new d("error",o))}).finally(()=>{});return}else{let e=new WeakRef(this);n.symbols.image_set_src(P.get(this),u.encode(`${t}\x00`),!1);let s=setTimeout(()=>{let r=e.deref();if(!r){clearTimeout(s);return}let i=P.get(r),o=new Int32Array(2);if(n.symbols.image_load(i,st(o)))this.#e=!this.#s?o[0]:this.#e,this.#a=!this.#l?o[1]:this.#a,r.onload?.call(r,new d("load",r));else r.onerror?.call(r,new d("error",r));clearTimeout(s)},0)}}get src(){return this.#i}get ptr(){return P.get(this)}get width(){return this.#e}get height(){return this.#a}set width(t){this.#s=!0,this.#e=t}set height(t){this.#l=!0,this.#a=t}}{let t=T.prototype;for(let e of Object.getOwnPropertyNames(t)){let s=Object.getOwnPropertyDescriptor(t,e);if(e=="constructor"){s&&(s.value.toString=()=>`function ${t.constructor.name}() { [native code] }`);continue}if(typeof s?.value==="function")s.value.toString=()=>`function ${e}() { [native code] }`}}class j{#t="";#e="";_nativePtr=null;constructor(t,e){this.#t=t.toLowerCase(),this.#e=e.trim().replaceAll("url(","").replaceAll('"',"").replaceAll("'","").replaceAll(")","").trim()}get family(){return this.#t}async load(){return new Promise((t,e)=>{if(this._nativePtr=n.symbols.font_load(u.encode(`${this.#e}\x00`)),console.log(this._nativePtr,this.#e),this._nativePtr)t();else e()})}}{let t=j.prototype;for(let e of Object.getOwnPropertyNames(t)){let s=Object.getOwnPropertyDescriptor(t,e);if(e=="constructor"){s&&(s.value.toString=()=>`function ${t.constructor.name}() { [native code] }`);continue}if(typeof s?.value==="function")s.value.toString=()=>`function ${e}() { [native code] }`}}class W{width;actualBoundingBoxLeft;actualBoundingBoxRight;actualBoundingBoxAscent;actualBoundingBoxDescent;fontBoundingBoxAscent;fontBoundingBoxDescent;emHeightAscent;emHeightDescent;alphabeticBaseline;hangingBaseline;ideographicBaseline;constructor(t,e,s,r,i,o,l,h,m,f,g,F){this.width=t,this.actualBoundingBoxLeft=e,this.actualBoundingBoxRight=s,this.actualBoundingBoxAscent=r,this.actualBoundingBoxDescent=i,this.fontBoundingBoxAscent=o,this.fontBoundingBoxDescent=l,this.emHeightAscent=h,this.emHeightDescent=m,this.alphabeticBaseline=f,this.hangingBaseline=g,this.ideographicBaseline=F}}class w extends d{altKey=!1;button=0;buttons=0;clientX=0;clientY=0;movementX=0;movementY=0;ctrlKey=!1;metaKey=!1;screenX=0;screenY=0;shiftKey=!1;constructor(t,e={altKey:!1,button:0,buttons:0,clientX:0,clientY:0,movementX:0,movementY:0,ctrlKey:!1,metaKey:!1,screenX:0,screenY:0,shiftKey:!1,target:null}){super(t,e.target);this.altKey=e.altKey,this.button=e.button,this.buttons=e.buttons,this.clientX=e.clientX,this.clientY=e.clientY,this.movementX=e.movementX,this.movementY=e.movementY,this.ctrlKey=e.ctrlKey,this.metaKey=e.metaKey,this.screenX=e.screenX,this.screenY=e.screenY,this.shiftKey=e.shiftKey}}var z=w.prototype;for(let t of Object.getOwnPropertyNames(z)){let e=Object.getOwnPropertyDescriptor(z,t);if(t=="constructor"){e&&(e.value.toString=()=>`function ${z.constructor.name}() { [native code] }`);continue}if(typeof e?.value==="function")e.value.toString=()=>`function ${t}() { [native code] }`}class I extends w{deltaX=0;deltaY=0;constructor(t,e={altKey:!1,button:0,buttons:0,clientX:0,clientY:0,movementX:0,movementY:0,deltaX:0,deltaY:0,ctrlKey:!1,metaKey:!1,screenX:0,screenY:0,shiftKey:!1,target:null}){super(t,e);this.deltaX=e.deltaX??0,this.deltaY=e.deltaY??0}}var Ft={"-1":"Unknown",32:" ",39:"'",44:",",45:"-",46:".",47:"/",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"[",92:"\\",93:"]",96:"`",161:"World1",162:"World2",256:"Escape",257:"Enter",258:"Tab",259:"Backspace",260:"Insert",261:"Delete",262:"ArrowRight",263:"ArrowLeft",264:"ArrowDown",265:"ArrowUp",266:"PageUp",267:"PageDown",268:"Home",269:"End",280:"CapsLock",281:"ScrollLock",282:"NumLock",283:"PrintScreen",284:"Pause",290:"F1",291:"F2",292:"F3",293:"F4",294:"F5",295:"F6",296:"F7",297:"F8",298:"F9",299:"F10",300:"F11",301:"F12",302:"F13",303:"F14",304:"F15",305:"F16",306:"F17",307:"F18",308:"F19",309:"F20",310:"F21",311:"F22",312:"F23",313:"F24",314:"F25",320:"0",321:"1",322:"2",323:"3",324:"4",325:"5",326:"6",327:"7",328:"8",329:"9",330:".",331:"/",332:"*",333:"-",334:"+",335:"Enter",336:"=",340:"Shift",341:"Control",342:"Alt",343:"Meta",344:"Shift",345:"Control",346:"Alt",347:"Meta",348:"ContextMenu"},xt={"-1":"Unknown",32:" ",39:'"',44:"<",45:"_",46:">",47:"?",48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",91:"{",92:"|",93:"}",96:"~",161:"World1",162:"World2",256:"Escape",257:"Enter",258:"Tab",259:"Backspace",260:"Insert",261:"Delete",262:"ArrowRight",263:"ArrowLeft",264:"ArrowDown",265:"ArrowUp",266:"PageUp",267:"PageDown",268:"Home",269:"End",280:"CapsLock",281:"ScrollLock",282:"NumLock",283:"PrintScreen",284:"Pause",290:"F1",291:"F2",292:"F3",293:"F4",294:"F5",295:"F6",296:"F7",297:"F8",298:"F9",299:"F10",300:"F11",301:"F12",302:"F13",303:"F14",304:"F15",305:"F16",306:"F17",307:"F18",308:"F19",309:"F20",310:"F21",311:"F22",312:"F23",313:"F24",314:"F25",320:"0",321:"1",322:"2",323:"3",324:"4",325:"5",326:"6",327:"7",328:"8",329:"9",330:".",331:"/",332:"*",333:"-",334:"+",335:"Enter",336:"=",340:"Shift",341:"Control",342:"Alt",343:"Meta",344:"Shift",345:"Control",346:"Alt",347:"Meta",348:"ContextMenu"},kt={"-1":"Unknown",32:"Space",39:"Quote",44:"Comma",45:"Minus",46:"Period",47:"Slash",48:"Digit0",49:"Digit1",50:"Digit2",51:"Digit3",52:"Digit4",53:"Digit5",54:"Digit6",55:"Digit7",56:"Digit8",57:"Digit9",59:"Semicolon",61:"Equal",65:"KeyA",66:"KeyB",67:"KeyC",68:"KeyD",69:"KeyE",70:"KeyF",71:"KeyG",72:"KeyH",73:"KeyI",74:"KeyJ",75:"KeyK",76:"KeyL",77:"KeyM",78:"KeyN",79:"KeyO",80:"KeyP",81:"KeyQ",82:"KeyR",83:"KeyS",84:"KeyT",85:"KeyU",86:"KeyV",87:"KeyW",88:"KeyX",89:"KeyY",90:"KeyZ",91:"BracketLeft",92:"Backslash",93:"BracketRight",96:"Backquote",161:"IntlBackslash",256:"Escape",257:"Enter",258:"Tab",259:"Backspace",260:"Insert",261:"Delete",262:"ArrowRight",263:"ArrowLeft",264:"ArrowDown",265:"ArrowUp",266:"PageUp",267:"PageDown",268:"Home",269:"End",280:"CapsLock",281:"ScrollLock",282:"NumLock",283:"PrintScreen",284:"Pause",290:"F1",291:"F2",292:"F3",293:"F4",294:"F5",295:"F6",296:"F7",297:"F8",298:"F9",299:"F10",300:"F11",301:"F12",302:"F13",303:"F14",304:"F15",305:"F16",306:"F17",307:"F18",308:"F19",309:"F20",310:"F21",311:"F22",312:"F23",313:"F24",314:"F25",320:"Numpad0",321:"Numpad1",322:"Numpad2",323:"Numpad3",324:"Numpad4",325:"Numpad5",326:"Numpad6",327:"Numpad7",328:"Numpad8",329:"Numpad9",330:"NumpadDecimal",331:"NumpadDivide",332:"NumpadMultiply",333:"NumpadSubtract",334:"NumpadAdd",335:"NumpadEnter",336:"NumpadEqual",340:"ShiftLeft",341:"ControlLeft",342:"AltLeft",343:"MetaLeft",344:"ShiftRight",345:"ControlRight",346:"AltRight",347:"MetaRight",348:"ContextMenu"};class O extends d{target=null;key="";code="";location=0;repeat=!1;ctrlKey=!1;shiftKey=!1;altKey=!1;metaKey=!1;constructor(t,e={target:null,key:"",code:"",location:0,repeat:!1,ctrlKey:!1,shiftKey:!1,altKey:!1,metaKey:!1},s=null,r=null,i=!1,o=!1,l=!1,h=!1,m=!1){super(t,e?e.target:r);if(e)this.key=e.key,this.code=e.code,this.location=e.location,this.repeat=e.repeat,this.ctrlKey=e.ctrlKey,this.shiftKey=e.shiftKey,this.altKey=e.altKey,this.metaKey=e.metaKey;else{let f=s;if(f>=65&&f<=90){let g=String.fromCharCode(f);this.key=o??e.shiftKey?g:g.toLowerCase()}else this.key=o??e.shiftKey?xt[s]:Ft[s];this.code=kt[s],this.location=0,this.repeat=!1,this.shiftKey=o,this.ctrlKey=l,this.altKey=h,this.metaKey=m}}}import{ptr as y,JSCallback as Kt}from"bun:ffi";class L{width;height;data;constructor(t,e,s){this.width=t,this.height=e,this.data=s}}import{ptr as Mt}from"bun:ffi";function St(t){return t==null||Array.isArray(t)||ArrayBuffer.isView(t)&&!(t instanceof DataView)}function v(t,e){let s=new Float64Array(16);return s[0]=t[0]*e[0]+t[1]*e[4]+t[2]*e[8]+t[3]*e[12],s[1]=t[0]*e[1]+t[1]*e[5]+t[2]*e[9]+t[3]*e[13],s[2]=t[0]*e[2]+t[1]*e[6]+t[2]*e[10]+t[3]*e[14],s[3]=t[0]*e[3]+t[1]*e[7]+t[2]*e[11]+t[3]*e[15],s[4]=t[4]*e[0]+t[5]*e[4]+t[6]*e[8]+t[7]*e[12],s[5]=t[4]*e[1]+t[5]*e[5]+t[6]*e[9]+t[7]*e[13],s[6]=t[4]*e[2]+t[5]*e[6]+t[6]*e[10]+t[7]*e[14],s[7]=t[4]*e[3]+t[5]*e[7]+t[6]*e[11]+t[7]*e[15],s[8]=t[8]*e[0]+t[9]*e[4]+t[10]*e[8]+t[11]*e[12],s[9]=t[8]*e[1]+t[9]*e[5]+t[10]*e[9]+t[11]*e[13],s[10]=t[8]*e[2]+t[9]*e[6]+t[10]*e[10]+t[11]*e[14],s[11]=t[8]*e[3]+t[9]*e[7]+t[10]*e[11]+t[11]*e[15],s[12]=t[12]*e[0]+t[13]*e[4]+t[14]*e[8]+t[15]*e[12],s[13]=t[12]*e[1]+t[13]*e[5]+t[14]*e[9]+t[15]*e[13],s[14]=t[12]*e[2]+t[13]*e[6]+t[14]*e[10]+t[15]*e[14],s[15]=t[12]*e[3]+t[13]*e[7]+t[14]*e[11]+t[15]*e[15],s}function c(t,e){throw SyntaxError(`Failed to execute '${t}' on 'DOMMatrix': Failed to parse '${e}'.`)}class b{#t=new Float64Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);#e=!0;#s(){this.#e=this.#t[0]==1&&this.#t[1]==0&&this.#t[2]==0&&this.#t[3]==0&&this.#t[4]==0&&this.#t[5]==1&&this.#t[6]==0&&this.#t[7]==0&&this.#t[8]==0&&this.#t[9]==0&&this.#t[10]==1&&this.#t[11]==0&&this.#t[12]==0&&this.#t[13]==0&&this.#t[14]==0&&this.#t[15]==1}get a(){return this.m11}set a(t){this.m11=t}get b(){return this.m12}set b(t){this.m12=t}get c(){return this.m21}set c(t){this.m21=t}get d(){return this.m22}set d(t){this.m22=t}get e(){return this.m41}set e(t){this.m41=t}get f(){return this.m42}set f(t){this.m42=t}is2D=!0;get isIdentity(){return this.#e}get m11(){return this.#t[0]}set m11(t){if(this.#t[0]=t,!this.#e){if(t==1)this.#s()}else if(t!=1)this.#e=!1}get m12(){return this.#t[4]}set m12(t){if(this.#t[4]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m13(){return this.#t[8]}set m13(t){if(this.#t[8]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m14(){return this.#t[12]}set m14(t){if(this.#t[12]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m21(){return this.#t[1]}set m21(t){if(this.#t[1]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m22(){return this.#t[5]}set m22(t){if(this.#t[5]=t,!this.#e){if(t==1)this.#s()}else if(t!=1)this.#e=!1}get m23(){return this.#t[9]}set m23(t){if(this.#t[9]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m24(){return this.#t[13]}set m24(t){if(this.#t[13]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m31(){return this.#t[2]}set m31(t){if(this.#t[2]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m32(){return this.#t[6]}set m32(t){if(this.#t[6]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m33(){return this.#t[10]}set m33(t){if(this.#t[10]=t,!this.#e){if(t==1)this.#s()}else if(t!=1)this.#e=!1}get m34(){return this.#t[14]}set m34(t){if(this.#t[14]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m41(){return this.#t[3]}set m41(t){if(this.#t[3]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m42(){return this.#t[7]}set m42(t){if(this.#t[7]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m43(){return this.#t[11]}set m43(t){if(this.#t[11]=t,!this.#e){if(t==0)this.#s()}else if(t!=0)this.#e=!1}get m44(){return this.#t[15]}set m44(t){if(this.#t[15]=t,!this.#e){if(t==1)this.#s()}else if(t!=1)this.#e=!1}multiplySelf(t){let e=this.#t,s=t.#t;return this.#t.set(v(e,s)),this.is2D&&=t.is2D,this}preMultiplySelf(t){let e=this.#t,s=t.#t;return this.#t.set(v(s,e)),this.is2D&&=t.is2D,this}translateSelf(t=0,e=0,s=0){let r=new Float64Array([1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1]);if(this.#t.set(v(this.#t,r)),s!==0)this.is2D=!1;return this}scaleSelf(t=1,e=t,s=1,r=0,i=0,o=0){if(r||i||o)this.translateSelf(r,i,o);let l=new Float64Array([t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1]);if(this.#t.set(v(this.#t,l)),r||i||o)this.translateSelf(-r,-i,-o);if(s!==1||o!==0)this.is2D=!1;return this}scale3dSelf(t,e=0,s=0,r=0){return this.scaleSelf(t,t,t,e,s,r)}rotateSelf(...t){if(t[1]===void 0&&t[2]===void 0)t[2]=t[0],t[0]=0,t[1]=0;else t[1]??=0,t[2]??=0;let e=t[0]*Math.PI/180,s=t[1]*Math.PI/180,r=t[2]*Math.PI/180,i=Math.sin(e),o=Math.cos(e),l=Math.sin(s),h=Math.cos(s),m=Math.sin(r),f=Math.cos(r);if(t[2]!==0)this.#t.set(v(this.#t,new Float64Array([f,-m,0,0,m,f,0,0,0,0,1,0,0,0,0,1])));if(t[1]!==0)this.#t.set(v(new Float64Array([h,0,l,0,0,1,0,0,-l,0,h,0,0,0,0,1]),this.#t));if(t[0]!==0)this.#t.set(v(new Float64Array([1,0,0,0,0,o,-i,0,0,i,o,0,0,0,0,1]),this.#t));if(t[0]!==0||t[1]!==0)this.is2D=!1;return this}rotateAxisAngleSelf(t=0,e=0,s=1,r=0){let i=Math.hypot(t,e,s);if(i===0)return this;t/=i,e/=i,s/=i;let o=r*Math.PI/180,l=Math.sin(o),h=Math.cos(o),m=1-h,f=new Float64Array([m*t*t+h,m*t*e-l*s,m*t*s+l*e,0,m*t*e+l*s,m*e*e+h,m*e*s-l*t,0,m*t*s-l*e,m*e*s+l*t,m*s*s+h,0,0,0,0,1]);if(this.#t.set(v(this.#t,f)),t!==0||e!==0)this.is2D=!1;return this}rotateFromVectorSelf(t=0,e=0){if(t===0&&e===0)return this;let s=Math.atan2(e,t)*180/Math.PI;return this.rotateSelf(s)}skewXSelf(t=0){let e=Math.tan(t*Math.PI/180);return this.#t.set(v(this.#t,new Float64Array([1,e,0,0,0,1,0,0,0,0,1,0,0,0,0,1]))),this}skewYSelf(t=0){let e=Math.tan(t*Math.PI/180);return this.#t.set(v(this.#t,new Float64Array([1,0,0,0,e,1,0,0,0,0,1,0,0,0,0,1]))),this}#a(t){let e=[],s=0;while(s<t.length){while(/\s/.test(t[s]))s++;if(s>=t.length)break;let r=s;while(/[A-Za-z0-9]/.test(t[s]))s++;let i=t.substring(r,s);while(/\s/.test(t[s]))s++;if(t[s]!=="(")return"error";s++;let o=1,l=s;while(s<t.length&&o>0){if(t[s]==="(")o++;else if(t[s]===")")o--;s++}if(o!==0)return"error";e.push({name:i,args:t.substring(l,s-1)})}return e}#l(t){let e=[],s="",r=0;for(let i of t){if(i==="(")r++;if(i===")")r--;if((i===","||/\s/.test(i))&&r===0){if(s.length)e.push(s),s="";continue}s+=i}if(s.length)e.push(s);return e}#i(t){if(t.endsWith("deg"))return Number.parseFloat(t);if(t.endsWith("rad"))return Number.parseFloat(t)*180/Math.PI;if(t.endsWith("grad"))return Number.parseFloat(t)*0.9;if(t.endsWith("turn"))return Number.parseFloat(t)*360;return Number.parseFloat(t)}#o(t){if(!t)return null;let e=16,s=16,r=8,i=8;if(t.endsWith("px"))return Number.parseFloat(t);if(t.endsWith("pt"))return Number.parseFloat(t)*1.3333333730697632;if(t.endsWith("pc"))return Number.parseFloat(t)*16;if(t.endsWith("in"))return Number.parseFloat(t)*96;if(t.endsWith("cm"))return Number.parseFloat(t)*37.79527559055118;if(t.endsWith("mm"))return Number.parseFloat(t)*3.7795275590551185;if(t.endsWith("q"))return Number.parseFloat(t)*0.9448818897637796;if(t.endsWith("em"))return Number.parseFloat(t)*s;if(t.endsWith("rem"))return Number.parseFloat(t)*e;if(t.endsWith("ex"))return Number.parseFloat(t)*r;if(t.endsWith("ch"))return Number.parseFloat(t)*i;if(t.endsWith("%"))return Number.parseFloat(t)*s/100;if(t.endsWith("px"))return Number.parseFloat(t);else if(t.endsWith("pt"))return Number.parseFloat(t)*1.3333333730697632;return null}setMatrixValue(t){if(t=t.trim(),t.length===0)throw new DOMException("Invalid transform.","SyntaxError");let e=this.#a(t);if(e=="error"){c("setMatrixValue",t);return}for(let s of e){let r=this.#l(s.args);switch(s.name){case"matrix":{if(r.length!==6)throw new DOMException("matrix() requires 6 arguments.","SyntaxError");let i=Number.parseFloat(r[0]),o=Number.parseFloat(r[1]),l=Number.parseFloat(r[2]),h=Number.parseFloat(r[3]);if(isNaN(i)||isNaN(o)||isNaN(l)||isNaN(h))c("setMatrixValue",t);this.a=i,this.b=o,this.c=l,this.d=h,this.e=this.#o(r[4]),this.f=this.#o(r[5]),this.is2D=!0;break}case"matrix3d":{if(r.length!==16)c("setMatrixValue",t);for(let i=0;i<16;i++)this.#t[i]=Number.parseFloat(r[i]);this.is2D=!1;break}case"translate":{if(r.length<1||r.length>2)c("setMatrixValue",t);let i=this.#o(r[0]),o=this.#o(r[1]);if(!i){c("setMatrixValue",t);return}let l=i,h=r.length===2?o??0:0;this.translateSelf(l,h);break}case"translateX":{if(r.length!==1)c("setMatrixValue",t);let i=this.#o(r[0]);if(!i){c("setMatrixValue",t);return}this.translateSelf(i,0);break}case"translateY":{if(r.length!==1)c("setMatrixValue",t);let i=this.#o(r[0]);if(!i){c("setMatrixValue",t);return}this.translateSelf(0,i);break}case"translateZ":{if(r.length!==1)c("setMatrixValue",t);let i=this.#o(r[0]);if(!i){c("setMatrixValue",t);return}this.translateSelf(0,0,i);break}case"translate3d":{if(r.length!==3)c("setMatrixValue",t);let i=this.#o(r[0]),o=this.#o(r[0]),l=this.#o(r[0]);if(!i||!o||!l){c("setMatrixValue",t);return}this.translateSelf(i,o,l);break}case"scale":{if(r.length<1||r.length>2)c("setMatrixValue",t);let i=Number.parseFloat(r[0]),o=r.length===2?Number.parseFloat(r[1]):i;this.scaleSelf(i,o);break}case"scaleX":{if(r.length!==1)c("setMatrixValue",t);this.scaleSelf(Number.parseFloat(r[0]),1);break}case"scaleY":{if(r.length!==1)c("setMatrixValue",t);this.scaleSelf(1,Number.parseFloat(r[0]));break}case"scaleZ":{if(r.length!==1)c("setMatrixValue",t);this.scaleSelf(1,1,Number.parseFloat(r[0]));break}case"scale3d":{if(r.length!==3)c("setMatrixValue",t);this.scale3dSelf(Number.parseFloat(r[0]),Number.parseFloat(r[1]),Number.parseFloat(r[2]));break}case"rotate":{if(r.length!==1)c("setMatrixValue",t);this.rotateSelf(this.#i(r[0]));break}case"rotateX":{if(r.length!==1)c("setMatrixValue",t);this.rotateSelf(this.#i(r[0]),0,0);break}case"rotateY":{if(r.length!==1)c("setMatrixValue",t);this.rotateSelf(0,this.#i(r[0]),0);break}case"rotateZ":{if(r.length!==1)c("setMatrixValue",t);this.rotateSelf(0,0,this.#i(r[0]));break}case"rotate3d":{if(r.length!==4)c("setMatrixValue",t);this.rotateAxisAngleSelf(Number.parseFloat(r[0]),Number.parseFloat(r[1]),Number.parseFloat(r[2]),this.#i(r[3]));break}case"skew":{if(r.length<1||r.length>2)c("setMatrixValue",t);if(this.skewXSelf(this.#i(r[0])),r.length===2)this.skewYSelf(this.#i(r[1]));break}case"skewX":{if(r.length!==1)c("setMatrixValue",t);this.skewXSelf(this.#i(r[0]));break}case"skewY":{if(r.length!==1)c("setMatrixValue",t);this.skewYSelf(this.#i(r[0]));break}case"perspective":{if(r.length!==1)c("setMatrixValue",t);let i=this.#o(r[0]);if(i===0||!i){c("setMatrixValue",t);return}this.#t.set(v(this.#t,new Float64Array([1,0,0,0,0,1,0,0,0,0,1,-1/i,0,0,0,1]))),this.is2D=!1;break}default:c("setMatrixValue",t)}}return this}toString(){return this.is2D?`matrix(${this.a}, ${this.b}, ${this.c}, ${this.d}, ${this.e}, ${this.f})`:`matrix3d(${this.m11}, ${this.m12}, ${this.m13}, ${this.m14}, ${this.m21}, ${this.m22}, ${this.m23}, ${this.m24}, ${this.m31}, ${this.m32}, ${this.m33}, ${this.m34}, ${this.m41}, ${this.m42}, ${this.m43}, ${this.m44})`}constructor(...t){if(!St(t[0]))throw SyntaxError(`Failed to construct 'DOMMatrix': Failed to parse '${t[0]}'.`);if(t[0]){let e=t[0].length;if(e!=6&&e!=16)throw TypeError("Failed to construct 'DOMMatrix': The sequence must contain 6 elements for a 2D matrix or 16 elements for a 3D matrix.");let s=t[0];if(e==6)this.a=s[0],this.b=s[1],this.c=s[2],this.d=s[3],this.e=s[4],this.f=s[5];else{let r=0;for(let i of s)this.#t[r]=i,r++}this.#e=s[0]==1&&s[1]==0&&s[2]==0&&s[3]==0&&s[4]==0&&s[5]==1&&s[6]==0&&s[7]==0&&s[8]==0&&s[9]==0&&s[10]==1&&s[11]==0&&s[12]==0&&s[13]==0&&s[14]==0&&s[15]==1}}get ptr(){return Mt(this.#t)}static fromFloat32Array(t){if(t instanceof Float32Array)return new b(t);throw TypeError("Failed to execute 'fromFloat32Array' on 'DOMMatrix': parameter 1 is not of type 'Float32Array'.")}static fromFloat64Array(t){if(t instanceof Float64Array)return new b(t);throw TypeError("Failed to execute 'fromFloat64Array' on 'DOMMatrix': parameter 1 is not of type 'Float64Array'.")}static fromMatrix(t){if(!t)return new b;if(t.a!=t.m11||t.b!=t.m21||t.c!=t.m12||t.d!=t.m22||t.e!=t.m41||t.f!=t.m42)throw TypeError("Failed to execute 'fromMatrix' on 'DOMMatrix': Property mismatch on matrix initialization.");let e=t.a??void 0,s=t.b??void 0,r=t.c??void 0,i=t.d??void 0,o=t.e??void 0,l=t.f??void 0,h=t.m11??e??1,m=t.m12??s??0,f=t.m13??0,g=t.m14??0,F=t.m21??r??0,_=t.m22??i??1,x=t.m23??0,S=t.m24??0,k=t.m31??0,G=t.m32??0,K=t.m33??1,lt=t.m34??0,ht=t.m41??o??0,ct=t.m42??l??0,mt=t.m43??0,ut=t.m44??1;return new b([h,m,f,g,F,_,x,S,k,G,K,lt,ht,ct,mt,ut])}}var H=b.prototype;for(let t of Object.getOwnPropertyNames(H)){let e=Object.getOwnPropertyDescriptor(H,t);if(t=="constructor"){e&&(e.value.toString=()=>`function ${H.constructor.name}() { [native code] }`);continue}if(typeof e?.value==="function")e.value.toString=()=>`function ${t}() { [native code] }`}var At=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]),Dt=/^#(?:[0-9a-fA-F]{3,4}){1,2}$/,Et=/^rgba?\(\s*(?:\d+(?:\.\d+)?%?|\.\d+%?)\s*[, ]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?)\s*[, ]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?)(?:\s*[,/]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?))?\s*\)$/i,Ct=/^(?:hsl|hsla|hwb)\(\s*(?:\d+(?:\.\d+)?(?:deg|rad|turn)?|\.\d+(?:deg|rad|turn)?)\s*[, ]\s*(?:\d+(?:\.\d+)?%|\.\d+%)\s*[, ]\s*(?:\d+(?:\.\d+)?%|\.\d+%)(?:\s*[,/]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?))?\s*\)$/i;function nt(t){if(typeof t!=="string")return!1;let e=t.trim().toLowerCase();if(e==="")return!1;if(At.has(e))return!0;if(e.startsWith("#"))return Dt.test(e);return Et.test(e)||Ct.test(e)}var a=new WeakMap,Nt=new FinalizationRegistry((t)=>{n.symbols.canvas_destroy(t),console.log("destroyed Canvas!")});class E{type;points=new Float32Array(6);offsets=[];colors=[];constructor(...t){switch(this.type=t[0],this.type){case 0:{this.points[0]=t[1],this.points[1]=t[2],this.points[2]=t[3],this.points[3]=t[4];break}case 1:{this.points[0]=t[1],this.points[1]=t[2],this.points[2]=t[3],this.points[3]=t[4],this.points[4]=t[5],this.points[5]=t[6];break}case 2:{this.points[0]=t[1],this.points[1]=t[2],this.points[2]=t[3];break}}}addColorStop(t,e){if(t<0||t>1)throw RangeError(`Failed to execute 'addColorStop' on 'CanvasGradient': The provided value (${t}) is outside the range (0.0, 1.0).`);if(!nt(e))throw SyntaxError(`Failed to execute 'addColorStop' on 'CanvasGradient': The value provided ('${e}') could not be parsed as a color.`);let s=this.offsets.findIndex((i)=>i>t),r=s===-1?this.offsets.length:s;this.offsets.splice(r,0,t),this.colors.splice(r,0,N(e))}}class C{lineWidth=0;globalAlpha=1;imageSmoothingQuality="low";imageSmoothingEnabled=!0;fillStyle="#000000";strokeStyle="#000000";compositeOperation="source-over";filter="none";fontCss="10px sans-serif";textBaseline="alphabetic";textAlign="start";lineDash=[];lineDashOffset=0;lineJoin="miter";constructor(t){if(t instanceof C)this.lineWidth=t.lineWidth,this.globalAlpha=t.globalAlpha,this.imageSmoothingQuality=t.imageSmoothingQuality,this.imageSmoothingEnabled=t.imageSmoothingEnabled,this.fillStyle=t.fillStyle,this.strokeStyle=t.strokeStyle,this.compositeOperation=t.compositeOperation,this.filter=t.filter,this.fontCss=t.fontCss,this.textBaseline=t.textBaseline,this.textAlign=t.textAlign,this.lineDash=t.lineDash,this.lineDashOffset=t.lineDashOffset,this.lineJoin=t.lineJoin}copyFrom(t){if(t instanceof C)this.lineWidth=t.lineWidth,this.globalAlpha=t.globalAlpha,this.imageSmoothingQuality=t.imageSmoothingQuality,this.imageSmoothingEnabled=t.imageSmoothingEnabled,this.fillStyle=t.fillStyle,this.strokeStyle=t.strokeStyle,this.compositeOperation=t.compositeOperation,this.filter=t.filter,this.fontCss=t.fontCss,this.textBaseline=t.textBaseline,this.textAlign=t.textAlign,this.lineDash=t.lineDash,this.lineDashOffset=t.lineDashOffset,this.lineJoin=t.lineJoin}}class J{#t=new C;#e=new C;#s;#a(){this.#t=new C}#l(t,e){let s=t.colors.length,r=new BigUint64Array(s);for(let l=0;l<s;l++)r[l]=BigInt(y(t.colors[l]));let i=new Float32Array(t.offsets);return(e?n.symbols.canvas_set_stroke_style_gradient:n.symbols.canvas_set_fill_style_gradient)(a.get(this),t.type,y(t.points),s,y(r),y(i))}get canvas(){return this.#s}set font(t){this.#t.fontCss=t.trim().toLowerCase(),n.symbols.canvas_set_font(a.get(this),u.encode(`${this.#t.fontCss}\x00`))}get font(){return this.#t.fontCss}set fillStyle(t){if(t==this.#t.fillStyle)return;let e=!1;if(typeof t==="string")e=n.symbols.canvas_set_fill_style(a.get(this),N(t));else if(t instanceof E)e=this.#l(t,!1);if(e)this.#t.fillStyle=t}get fillStyle(){return this.#t.fillStyle}set strokeStyle(t){if(t==this.#t.strokeStyle)return;let e=!1;if(typeof t==="string")e=n.symbols.canvas_set_stroke_style(a.get(this),u.encode(`${t.trim()}\x00`));else if(t instanceof E)e=this.#l(t,!0);if(e)this.#t.strokeStyle=t}get strokeStyle(){return this.#t.strokeStyle}set lineWidth(t){let e=t<1?1:t;n.symbols.canvas_set_stroke_width(a.get(this),e),this.#t.lineWidth=e}get lineWidth(){return this.#t.lineWidth}set globalAlpha(t){this.#t.globalAlpha=n.symbols.canvas_set_global_alpha(a.get(this),t)}get globalAlpha(){return this.#t.globalAlpha}set imageSmoothingQuality(t){let e=!1;switch(t){case"low":{e=n.symbols.canvas_set_image_smoothing_quality(a.get(this),1);break}case"medium":{e=n.symbols.canvas_set_image_smoothing_quality(a.get(this),2);break}case"high":{e=n.symbols.canvas_set_image_smoothing_quality(a.get(this),3);break}}if(e)this.#t.imageSmoothingQuality=t}get imageSmoothingQuality(){return this.#t.imageSmoothingQuality}set imageSmoothingEnabled(t){this.#t.imageSmoothingEnabled=n.symbols.canvas_set_image_smoothing_enabled(a.get(this),t)}get imageSmoothingEnabled(){return this.#t.imageSmoothingEnabled}set filter(t){if(n.symbols.canvas_set_filter(a.get(this),u.encode(`${t}\x00`)))this.#t.filter=t}get filter(){return this.#t.filter}set globalCompositeOperation(t){if(n.symbols.canvas_set_composite_operation(a.get(this),u.encode(`${t}\x00`))==!0)this.#t.compositeOperation=t}get globalCompositeOperation(){return this.#t.compositeOperation}fillRect(t,e,s,r){n.symbols.canvas_fill_rect(a.get(this),t,e,s,r)}strokeRect(t,e,s,r){n.symbols.canvas_stroke_rect(a.get(this),t,e,s,r)}clearRect(t,e,s,r){n.symbols.canvas_clear_rect(a.get(this),t,e,s,r)}fillText(t,e,s,r=-1){n.symbols.canvas_fill_text(a.get(this),u.encode(`${t}\x00`),e,s,r)}strokeText(t,e,s,r=-1){n.symbols.canvas_stroke_text(a.get(this),u.encode(`${t}\x00`),e,s,r)}beginPath(){n.symbols.canvas_path_begin(a.get(this))}moveTo(t,e){n.symbols.canvas_path_move_to(a.get(this),t,e)}lineTo(t,e){n.symbols.canvas_path_line_to(a.get(this),t,e)}arc(t,e,s,r,i){n.symbols.canvas_path_arc(a.get(this),t,e,s,r,i)}ellipse(t,e,s,r,i,o,l,h=!1){n.symbols.canvas_path_ellipse(a.get(this),t,e,s,r,i,o,l,h)}arcTo(t,e,s,r,i){n.symbols.canvas_path_arc_to(a.get(this),t,e,s,r,i)}bezierCurveTo(t,e,s,r,i,o){n.symbols.canvas_path_bezier_to(a.get(this),t,e,s,r,i,o)}quadraticCurveTo(t,e,s,r){n.symbols.canvas_path_quad_to(a.get(this),t,e,s,r)}closePath(){n.symbols.canvas_path_close(a.get(this))}rect(t,e,s,r){n.symbols.canvas_path_rect(a.get(this),t,e,s,r)}roundRect(t,e,s,r,i){if(i.constructor.name.toLowerCase().includes("array")){let o=new Float32Array(i);if(o.some(Number.isNaN))return;let l=o.length;n.symbols.canvas_path_roundrect_array(a.get(this),t,e,s,r,y(o),l);return}else n.symbols.canvas_path_roundrect(a.get(this),t,e,s,r,i)}fill(t){n.symbols.canvas_path_fill(a.get(this),t?t.ptr:void 0)}stroke(t){n.symbols.canvas_path_stroke(a.get(this),t?t.ptr:void 0)}set shadowBlur(t){n.symbols.canvas_set_shadow_blur(a.get(this),t)}set shadowColor(t){n.symbols.canvas_set_shadow_color(a.get(this),u.encode(`${t}\x00`))}set shadowOffsetX(t){n.symbols.canvas_set_shadow_offsetX(a.get(this),t)}set shadowOffsetY(t){n.symbols.canvas_set_shadow_offsetY(a.get(this),t)}set lineJoin(t){let e=!1;switch(t){case"round":{e=n.symbols.canvas_set_line_join(a.get(this),1);break}case"bevel":{e=n.symbols.canvas_set_line_join(a.get(this),2);break}case"miter":{e=n.symbols.canvas_set_line_join(a.get(this),3);break}}if(e)this.#t.lineJoin=t}get lineJoin(){return this.#t.lineJoin}drawImage(t,...e){let s=e.length==2?[...e,t.width,t.height]:e,r=new Float32Array(s),i=r.length;if(t instanceof T){n.symbols.canvas_draw_image_imageType(a.get(this),t.ptr,y(r),i);return}if(t instanceof X){n.symbols.canvas_draw_image_canvasType(a.get(this),a.get(t),y(r),i);return}throw TypeError("Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(Image or Canvas)'.")}getImageData(t,e,s,r){let i=new Uint8Array(s*r*4);return n.symbols.canvas_get_image_data(a.get(this),t,e,s,r,y(i)),new L(s,r,i)}putImageData(t,e,s,r=0,i=0,o=t.width,l=t.height){if(!(t instanceof L))throw TypeError("Failed to execute 'putImageData' on 'CanvasRenderingContext2D': parameter 1 is not of type 'ImageData'");n.symbols.canvas_put_image_data(a.get(this),e,s,t.width,t.height,r,i,o,l,y(t.data))}save(){this.#e?.copyFrom(this.#t),n.symbols.canvas_save(a.get(this))}restore(){if(!this.#e)return;this.#t?.copyFrom(this.#e),n.symbols.canvas_restore(a.get(this))}translate(t,e){n.symbols.canvas_translate(a.get(this),t,e)}rotate(t){n.symbols.canvas_rotate(a.get(this),t)}createConicGradient(...t){if(t.length<3)throw TypeError(`Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': 3 arguments required, but only ${t.length} present.`);return new E(2,...t)}createLinearGradient(...t){if(t.length<4)throw TypeError(`Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': 4 arguments required, but only ${t.length} present.`);return new E(0,...t)}createRadialGradient(...t){if(t.length<6)throw TypeError(`Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': 6 arguments required, but only ${t.length} present.`);return new E(1,...t)}getTransform(){let t=new Float32Array(16);return n.symbols.canvas_get_transform(a.get(this),y(t)),new b(t)}setTransform(...t){if(t[0]instanceof b)n.symbols.canvas_set_transform(a.get(this),t[0].ptr);if(t.length==6){let e=new b([t[0],t[1],t[2],t[3],t[4],t[5]]);n.symbols.canvas_set_transform(a.get(this),e.ptr)}if(t.length==16)n.symbols.canvas_set_transform(a.get(this),new b([t[0],t[1],t[2],t[3],t[4],t[5],t[5],t[6],t[7],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15]]).ptr)}transform(t,e,s,r,i,o){let l=this.getTransform(),h=new b([t,e,s,r,i,o]);l.multiplySelf(h),this.setTransform(l)}resetTransform(){n.symbols.canvas_reset_transform(a.get(this))}setLineDash(t){if(t.constructor.name.toLowerCase().includes("array")){let e;if(t.length&1)e=t.concat(Array.from(t));else e=t;let s=new Float32Array(e);if(s.some(Number.isNaN))return;n.symbols.canvas_set_line_dash(a.get(this),y(s),s.length,this.#t.lineDashOffset),this.#t.lineDash=e;return}throw TypeError("Failed to execute 'setLineDash' on 'CanvasRenderingContext2D': The provided value cannot be converted to a sequence.")}getLineDash(){return this.#t.lineDash}clip(){n.symbols.canvas_path_clip(a.get(this))}set lineDashOffset(t){if(this.#t.lineDash.length<=0){this.#t.lineDashOffset=0;return}let e=new Float32Array(this.#t.lineDash);n.symbols.canvas_set_line_dash(a.get(this),y(e),e.length,t),this.#t.lineDashOffset=t}set textBaseline(t){let e=-1;switch(t){case"top":e=0;break;case"hanging":e=1;break;case"middle":e=2;break;case"alphabetic":e=3;break;case"ideographic":e=4;break;case"bottom":e=5;break}if(e!=-1)n.symbols.canvas_set_text_baseline(a.get(this),e)}set textAlign(t){let e=-1;switch(t){case"left":e=0;break;case"right":e=1;break;case"center":e=2;break;case"start":e=3;break;case"end":e=4;break}if(e!=-1)n.symbols.canvas_set_text_align(a.get(this),e)}measureText(t){let e=new Float32Array(12);return n.symbols.canvas_measure_text(a.get(this),u.encode(`${t}\x00`),y(e)),new W(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8],e[9],e[10],e[11])}constructor(t,e,s){let{desynchronized:r=!1,alpha:i=!0}=s??{},o=new Kt(this.#a.bind(this),{args:[],returns:"void"}),l=n.symbols.canvas_get_context2D(t,o.ptr,r,i);this.#s=e,a.set(this,l)}}{let t=J.prototype;for(let e of Object.getOwnPropertyNames(t)){let s=Object.getOwnPropertyDescriptor(t,e);if(e=="constructor"){s&&(s.value.toString=()=>`function ${t.constructor.name}() { [native code] }`);continue}if(typeof s?.value==="function")s.value.toString=()=>`function ${e}() { [native code] }`}}class X{#t=new Float64Array(2);#e={cb:()=>{}};constructor(t=1,e=1,s){this.#t[0]=t,this.#t[1]=e;let{gpu:r=!0}=s??{},i=n.symbols.canvas_create(t,e,r);a.set(this,i),Nt.register(this,i)}get _ptr(){return a.get(this)}set width(t){this.#t[0]=Number.parseInt(t),this.#e.cb(),n.symbols.canvas_resize(a.get(this),this.#t[0],this.#t[1])}set height(t){this.#t[1]=Number.parseInt(t),this.#e.cb(),n.symbols.canvas_resize(a.get(this),this.#t[0],this.#t[1])}get width(){return this.#t[0]}get height(){return this.#t[1]}getContext(t,e){if(t=="2d")return new J(a.get(this),this,e)}getBoundingClientRect(){return{x:0,y:0,width:this.#t[0],height:this.#t[1],top:0,bottom:this.#t[1],left:0,right:this.#t[0]}}}{let t=X.prototype;for(let e of Object.getOwnPropertyNames(t)){let s=Object.getOwnPropertyDescriptor(t,e);if(e=="constructor"){s&&(s.value.toString=()=>`function ${t.constructor.name}() { [native code] }`);continue}if(typeof s?.value==="function")s.value.toString=()=>`function ${e}() { [native code] }`}}import{ptr as Pt}from"bun:ffi";var it=new FinalizationRegistry((t)=>{n.symbols.path2d_destroy(t)}),p=new WeakMap;class Y{constructor(t){if(t&&t instanceof Y){let e=n.symbols.path2d_create_from_copy(t.ptr);p.set(this,e),it.register(this,e)}else{let e=n.symbols.path2d_create();p.set(this,e),it.register(this,e)}}moveTo(t,e){n.symbols.path2d_move_to(p.get(this),t,e)}lineTo(t,e){n.symbols.path2d_line_to(p.get(this),t,e)}arc(t,e,s,r,i){n.symbols.path2d_arc(p.get(this),t,e,s,r,i)}ellipse(t,e,s,r,i,o,l,h=!1){n.symbols.path2d_ellipse(p.get(this),t,e,s,r,i,o,l,h)}arcTo(t,e,s,r,i){n.symbols.path2d_arc_to(p.get(this),t,e,s,r,i)}bezierCurveTo(t,e,s,r,i,o){n.symbols.path2d_bezier_to(p.get(this),t,e,s,r,i,o)}quadraticCurveTo(t,e,s,r){n.symbols.path2d_quad_to(p.get(this),t,e,s,r)}rect(t,e,s,r){n.symbols.path2d_rect(p.get(this),t,e,s,r)}roundRect(t,e,s,r,i){if(i.constructor.name.toLowerCase().includes("array")){let o=new Float32Array(i);if(o.some(Number.isNaN))return;let l=o.length;n.symbols.path2d_roundrect_array(p.get(this),t,e,s,r,Pt(o),l);return}else n.symbols.path2d_rect(p.get(this),t,e,s,r,i)}closePath(){n.symbols.path2d_close(p.get(this))}get ptr(){return p.get(this)}}var Q=Y.prototype;for(let t of Object.getOwnPropertyNames(Q)){let e=Object.getOwnPropertyDescriptor(Q,t);if(t=="constructor"){e&&(e.value.toString=()=>`function ${Q.constructor.name}() { [native code] }`);continue}if(typeof e?.value==="function")e.value.toString=()=>`function ${t}() { [native code] }`}import{dlopen as Tt,toArrayBuffer as M}from"bun:ffi";var ot=`import { dlopen, FFIType, JSCallback } from "bun:ffi";
|
|
3
3
|
|
|
4
4
|
const MessagePost = new JSCallback((instruction)=>{
|
|
5
5
|
self.postMessage(instruction);
|
|
@@ -23,4 +23,4 @@ self.onmessage = (msg)=>{
|
|
|
23
23
|
self.postMessage(2)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
`;var A=[],B;n.symbols.glfw_init();if(process.platform!=="darwin")B=new Worker(URL.createObjectURL(new Blob([ot],{type:"application/javascript"})),{ref:!1});n.symbols.canvas_init_gpu_context();var
|
|
26
|
+
`;var A=[],B;n.symbols.glfw_init();if(process.platform!=="darwin")B=new Worker(URL.createObjectURL(new Blob([ot],{type:"application/javascript"})),{ref:!1});n.symbols.canvas_init_gpu_context();var Ot=!1;class Z{#t=new Map;#e=new Map;#s=new Map;#a=new Map;#l=new Map;#i=new Map;#o=new Map;#b=new Map;#d=new Int32Array(M(n.symbols.get_wPropertiesViewer(),0,16));#r=new Float64Array(M(n.symbols.get_mMoveViewer(),0,72));#h=new Float64Array(M(n.symbols.get_mClickViewer(),0,72));#c=new Float64Array(M(n.symbols.get_mDownViewer(),0,72));#m=new Float64Array(M(n.symbols.get_mUpViewer(),0,72));#u=new Int32Array(M(n.symbols.get_kDownViewer(),0,28));#f=new Int32Array(M(n.symbols.get_kUpViewer(),0,28));#p=new Float64Array(M(n.symbols.get_mWheelViewer(),0,40));#n=new WeakMap;#w=[];#y=0;#_(){if(this.#d[0]!=0){this.#d[0]=0;let t=new d("resize",this);if(this.onresize)this.onresize(t);this.#t.forEach((e,s)=>{e.cb(t)})}if(this.#r[0]!=0){this.#r[0]=0;let t=new w("move",{target:this,altKey:!1,button:0,buttons:this.#r[5],clientX:this.#r[1],clientY:this.#r[2],movementX:this.#r[3],movementY:this.#r[4],ctrlKey:!1,metaKey:!1,screenX:0,screenY:0,shiftKey:!1});if(this.onmousemove)this.onmousemove(t);this.#e.forEach((e,s)=>{e.cb(t)})}if(this.#r[0]!=0){this.#r[0]=0;let t=new w("move",{target:this,altKey:!1,button:0,buttons:this.#r[5],clientX:this.#r[1],clientY:this.#r[2],movementX:this.#r[3],movementY:this.#r[4],ctrlKey:!1,metaKey:!1,screenX:0,screenY:0,shiftKey:!1});if(this.onmousemove)this.onmousemove(t);this.#e.forEach((e,s)=>{e.cb(t)})}if(this.#c[0]!=0){this.#c[0]=0;let t=new w("down",{target:this,altKey:this.#c[7],button:this.#c[3],buttons:this.#c[4],clientX:this.#c[1],clientY:this.#c[2],movementX:0,movementY:0,ctrlKey:this.#c[6],metaKey:this.#c[8],screenX:this.#c[1],screenY:this.#c[2],shiftKey:this.#c[5]});if(this.onmousedown)this.onmousedown(t);this.#s.forEach((e,s)=>{e.cb(t)})}if(this.#m[0]!=0){this.#m[0]=0;let t=new w("up",{target:this,altKey:this.#m[7],button:this.#m[3],buttons:this.#m[4],clientX:this.#m[1],clientY:this.#m[2],movementX:0,movementY:0,ctrlKey:this.#m[6],metaKey:this.#m[8],screenX:this.#m[1],screenY:this.#m[2],shiftKey:this.#m[5]});if(this.onmouseup)this.onmouseup(t);this.#a.forEach((e,s)=>{e.cb(t)})}if(this.#h[0]!=0){this.#h[0]=0;let t=new w("click",{target:this,altKey:this.#h[7],button:this.#h[3],buttons:this.#h[4],clientX:this.#h[1],clientY:this.#h[2],movementX:0,movementY:0,ctrlKey:this.#h[6],metaKey:this.#h[8],screenX:this.#h[1],screenY:this.#h[2],shiftKey:this.#h[5]});if(this.onclick)this.onclick(t);this.#i.forEach((e,s)=>{e.cb(t)})}if(this.#p[0]!=0){this.#p[0]=0;let t=new I("wheel",{target:this,altKey:this.#r[7],button:this.#p[3],buttons:this.#p[4],clientX:this.#r[3],clientY:this.#r[4],deltaX:-this.#p[1]*120,deltaY:-this.#p[2]*120,movementX:0,movementY:0,ctrlKey:this.#r[6],metaKey:this.#r[8],screenX:this.#r[3],screenY:this.#r[4],shiftKey:this.#r[5]});if(this.onwheel)this.onwheel(t);this.#l.forEach((e,s)=>{e.cb(t)})}if(this.#u[0]!=0){this.#u[0]=0;let t=new O("down",null,this.#u[2],this,this.#u[1],this.#u[3],this.#u[4],this.#u[5],this.#u[6]);if(this.onkeydown)this.onkeydown(t);this.#o.forEach((e,s)=>{e.cb(t)})}if(this.#f[0]!=0){this.#f[0]=0;let t=new O("up",null,this.#f[2],this,this.#f[1],this.#f[3],this.#f[4],this.#f[5],this.#f[6]);if(this.onkeyup)this.onkeyup(t);this.#b.forEach((e,s)=>{e.cb(t)})}}maxFramerate=0;#g=!0;get vsync(){return this.#g}set vsync(t){this.#g=t,n.symbols.set_vsync(t)}fonts={add(t){if(!t._nativePtr)throw TypeError("Font was not loaded");n.symbols.font_add_to_registry(u.encode(`${t.family}\x00`),t._nativePtr)}};onresize=null;onmousemove=null;onmousedown=null;onmouseup=null;onclick=null;onkeydown=null;onkeyup=null;onwheel=null;get innerWidth(){return this.#d[1]}get innerHeight(){return this.#d[2]}constructor(t,e,s="App",r){if(process.platform!=="darwin")B.ref?.();Ot=!0,this.#d[1]=t,this.#d[2]=e;let{vsync:i=!0,maxFramerate:o=0}=r??{};this.#g=i,this.maxFramerate=o;let l=performance.now();if(process.platform!=="darwin"){B.onerror=(g)=>{console.error("Render thread error:",g)};let h=u.encode(`${s}\x00`);B.postMessage({w:t,h:e,t:h,vsync:this.#g,nativePath:V});let m=!1,f=performance.now();B.onmessage=(g)=>{let F=g.data;if(F===2){n.symbols.destroy_window(),n.symbols.images_cleanup(),process.exit(0);return}if(F===1)n.symbols.create_window(t,e,h);n.symbols.signal_frame_ready();let _=this.maxFramerate>0?1000/this.maxFramerate:0,x=performance.now(),S=x-f;if(_===0||this.#g||S>=_){if(_>0)f=x-S%_;if(!m)m=!0,n.symbols.canvas_flush_gpu(),setImmediate(()=>{let k=A.length;if(k>0){let G=A;A=[];for(let K=0;K<k;K++)G[K](x)}m=!1})}this.#_()}}else{let h=Tt(V,{setup_render_thread:{args:["int","int","cstring","ptr","bool"],returns:"void"}}),m=u.encode(`${s}\x00`);h.symbols.setup_render_thread(t,e,m,0,i),n.symbols.create_window(t,e,m);let f=this.maxFramerate>0?1000/this.maxFramerate:0,g=performance.now(),F=()=>{if(this.#d[3]==1){n.symbols.destroy_window(),process.exit(0);return}let _=performance.now(),x=_-g;if(f===0||x>=f){if(g=f>0?_-x%f:_,this.#_(),A.length>0){let S=A;A=[];for(let k=0;k<S.length;k++)S[k](_)}n.symbols.update_window()}setImmediate(F)};F()}}addEventListener(t,e){let s=this.#w.pop(),r=s!=null?s:this.#y;if(r==this.#y)this.#y++;if(t=="resize")this.#t.set(r,{name:t,cb:e}),this.#n.set(e,r);else if(t=="mousemove")this.#e.set(r,{name:t,cb:e}),this.#n.set(e,r);else if(t=="mousedown")this.#s.set(r,{name:t,cb:e}),this.#n.set(e,r);else if(t=="mouseup")this.#a.set(r,{name:t,cb:e}),this.#n.set(e,r);else if(t=="wheel")this.#l.set(r,{name:t,cb:e}),this.#n.set(e,r);else if(t=="click")this.#i.set(r,{name:t,cb:e}),this.#n.set(e,r);else if(t=="keydown")this.#o.set(r,{name:t,cb:e}),this.#n.set(e,r);else if(t=="keyup")this.#b.set(r,{name:t,cb:e}),this.#n.set(e,r)}removeEventListener(t,e){let s=this.#n.get(e);if(t=="resize"){if(s!=null)this.#t.delete(s),this.#n.delete(e)}else if(t=="mousemove"){if(s!=null)this.#e.delete(s),this.#n.delete(e)}else if(t=="mousedown"){if(s!=null)this.#s.delete(s),this.#n.delete(e)}else if(t=="mouseup"){if(s!=null)this.#a.delete(s),this.#n.delete(e)}else if(t=="wheel"){if(s!=null)this.#l.delete(s),this.#n.delete(e)}else if(t=="click"){if(s!=null)this.#i.delete(s),this.#n.delete(e)}else if(t=="keydown"){if(s!=null)this.#o.delete(s),this.#n.delete(e)}else if(t=="keyup"){if(s!=null)this.#b.delete(s),this.#n.delete(e)}}append(t){let e=t._ptr;if(e==null){console.error("Canvas was not found");return}n.symbols.canvas_append(e)}}{let t=Z.prototype;for(let e of Object.getOwnPropertyNames(t)){let s=Object.getOwnPropertyDescriptor(t,e);if(e=="constructor"){s&&(s.value.toString=()=>`function ${t.constructor.name}() { [native code] }`);continue}if(typeof s?.value==="function")s.value.toString=()=>`function ${e}() { [native code] }`}}var R;if(globalThis.requestAnimationFrame)R=globalThis.requestAnimationFrame;else R=function(e){setImmediate(()=>{A.push(e)})},R.toString=()=>"function requestAnimationFrame() { [native code] }";var Bt=R;var q=new WeakMap;n.symbols.audio_backend_init();class at{constructor(t){if(t)q.set(this,n.symbols.audio_create(u.encode(`${t}\x00`)));else q.set(this,n.symbols.audio_create())}set src(t){n.symbols.audio_set_src(N(t))}play(){n.symbols.audio_play(q.get(this))}stop(){n.symbols.audio_stop(q.get(this))}}export{at as Audio,X as Canvas,b as DOMMatrix,d as Event,j as FontFace,T as Image,O as KeyboardEvent,w as MouseEvent,Y as Path2D,W as TextMetrics,I as WheelEvent,Z as Window,Bt as requestAnimationFrame};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@buncanvas/core",
|
|
3
3
|
"module": "index.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.3",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"typescript": "^7"
|
|
14
14
|
},
|
|
15
15
|
"optionalDependencies": {
|
|
16
|
-
"@buncanvas/native-linux-x64": "0.1.
|
|
17
|
-
"@buncanvas/native-win32-x64": "0.1.
|
|
16
|
+
"@buncanvas/native-linux-x64": "0.1.1",
|
|
17
|
+
"@buncanvas/native-win32-x64": "0.1.1",
|
|
18
18
|
"@buncanvas/native-darwin-arm64": "0.1.2"
|
|
19
19
|
}
|
|
20
20
|
}
|