@buncanvas/core 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +137 -11
  2. package/index.js +3350 -2
  3. package/package.json +4 -4
package/index.js CHANGED
@@ -1,5 +1,2877 @@
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
+
3
+ // BunCanvas/src/Image.ts
4
+ import { createHash } from "crypto";
5
+ import { basename, join } from "path";
6
+ import { tmpdir } from "os";
7
+
8
+ // BunCanvas/internal/symbols.js
9
+ import { dlopen, FFIType, suffix } from "bun:ffi";
10
+ import { createRequire } from "module";
11
+ var nativeLib;
12
+ try {
13
+ if (!process.argv.includes("--XX:BunCanvas.IgnoreImport")) {
14
+ nativeLib = require(`@buncanvas/native-${process.platform}-${process.arch}`);
15
+ } else {
16
+ nativeLib = `BunCanvas.${process.arch}.${suffix}`;
17
+ }
18
+ } catch (ex) {
19
+ const req = createRequire(import.meta.url);
20
+ console.log("first failed!", ex);
21
+ nativeLib = req.resolve(`@buncanvas/native-${process.platform}-${process.arch}`);
22
+ }
23
+ console.log(nativeLib);
24
+ if (!nativeLib) {
25
+ console.error(`BunCanvas.${process.arch}.${suffix} binary was not found in the working directory!`);
26
+ process.exit(-1);
27
+ }
28
+ var dlPath = nativeLib;
29
+ var encoder = new TextEncoder;
30
+ var encodedCache = new Map;
31
+ function encodeCString(str) {
32
+ let buf = encodedCache.get(str);
33
+ if (buf)
34
+ return buf;
35
+ buf = encoder.encode(str + "\x00");
36
+ encodedCache.set(str, buf);
37
+ return buf;
38
+ }
39
+ var lib = dlopen(dlPath, {
40
+ glfw_init: {
41
+ args: [],
42
+ returns: "void"
43
+ },
44
+ get_wPropertiesViewer: {
45
+ args: [],
46
+ returns: "ptr"
47
+ },
48
+ get_mMoveViewer: {
49
+ args: [],
50
+ returns: "ptr"
51
+ },
52
+ get_mClickViewer: {
53
+ args: [],
54
+ returns: "ptr"
55
+ },
56
+ get_mDownViewer: {
57
+ args: [],
58
+ returns: "ptr"
59
+ },
60
+ get_mUpViewer: {
61
+ args: [],
62
+ returns: "ptr"
63
+ },
64
+ get_kDownViewer: {
65
+ args: [],
66
+ returns: "ptr"
67
+ },
68
+ get_kUpViewer: {
69
+ args: [],
70
+ returns: "ptr"
71
+ },
72
+ get_mWheelViewer: {
73
+ args: [],
74
+ returns: "ptr"
75
+ },
76
+ signal_frame_ready: {
77
+ args: [],
78
+ returns: "void"
79
+ },
80
+ set_vsync: {
81
+ args: ["bool"],
82
+ returns: "void"
83
+ },
84
+ create_window: {
85
+ args: ["int", "int", "cstring"],
86
+ returns: "void"
87
+ },
88
+ update_window: {
89
+ args: ["ptr"],
90
+ returns: "void"
91
+ },
92
+ destroy_window: {
93
+ args: [],
94
+ returns: "void"
95
+ },
96
+ canvas_init_gpu_context: {
97
+ args: [],
98
+ returns: "bool"
99
+ },
100
+ canvas_flush_gpu: {
101
+ args: [],
102
+ returns: "void"
103
+ },
104
+ canvas_create: {
105
+ args: ["int", "int", "bool"],
106
+ returns: "ptr"
107
+ },
108
+ canvas_resize: {
109
+ args: ["ptr", "int", "int"],
110
+ returns: "void"
111
+ },
112
+ canvas_append: {
113
+ args: ["ptr"],
114
+ returns: "void"
115
+ },
116
+ canvas_get_context2D: {
117
+ args: ["ptr", "ptr", "bool", "bool"],
118
+ returns: "ptr"
119
+ },
120
+ canvas_set_fill_style: {
121
+ args: ["ptr", "cstring"],
122
+ returns: "bool"
123
+ },
124
+ canvas_set_fill_style_gradient: {
125
+ args: ["ptr", "int", "ptr", "int", "ptr", "ptr"],
126
+ returns: "bool"
127
+ },
128
+ canvas_set_stroke_style: {
129
+ args: ["ptr", "cstring"],
130
+ returns: "bool"
131
+ },
132
+ canvas_set_stroke_style_gradient: {
133
+ args: ["ptr", "int", "ptr", "int", "ptr", "ptr"],
134
+ returns: "bool"
135
+ },
136
+ canvas_set_stroke_width: {
137
+ args: ["ptr", "float"],
138
+ returns: "bool"
139
+ },
140
+ canvas_fill_rect: {
141
+ args: ["ptr", "int", "int", "int", "int"],
142
+ returns: "void"
143
+ },
144
+ canvas_stroke_rect: {
145
+ args: ["ptr", "int", "int", "int", "int"],
146
+ returns: "void"
147
+ },
148
+ canvas_clear_rect: {
149
+ args: ["ptr", "int", "int", "int", "int"],
150
+ returns: "void"
151
+ },
152
+ canvas_path_begin: {
153
+ args: ["ptr"],
154
+ returns: "void"
155
+ },
156
+ canvas_path_move_to: {
157
+ args: ["ptr", "int", "int"],
158
+ returns: "void"
159
+ },
160
+ canvas_path_line_to: {
161
+ args: ["ptr", "int", "int"],
162
+ returns: "void"
163
+ },
164
+ canvas_path_arc: {
165
+ args: ["ptr", "float", "float", "float", "float", "float"],
166
+ returns: "void"
167
+ },
168
+ canvas_path_arc_to: {
169
+ args: ["ptr", "float", "float", "float", "float", "float"],
170
+ returns: "void"
171
+ },
172
+ canvas_path_bezier_to: {
173
+ args: ["ptr", "float", "float", "float", "float", "float", "float"],
174
+ returns: "void"
175
+ },
176
+ canvas_path_quad_to: {
177
+ args: ["ptr", "float", "float", "float", "float"],
178
+ returns: "void"
179
+ },
180
+ canvas_path_ellipse: {
181
+ args: ["ptr", "float", "float", "float", "float", "float", "float", "float", "bool"],
182
+ returns: "void"
183
+ },
184
+ canvas_path_fill: {
185
+ args: ["ptr", "ptr"],
186
+ returns: "void"
187
+ },
188
+ canvas_path_stroke: {
189
+ args: ["ptr", "ptr"],
190
+ returns: "void"
191
+ },
192
+ canvas_path_close: {
193
+ args: ["ptr"],
194
+ returns: "void"
195
+ },
196
+ canvas_path_rect: {
197
+ args: ["ptr", "float", "float", "float", "float"],
198
+ returns: "void"
199
+ },
200
+ canvas_path_roundrect: {
201
+ args: ["ptr", "float", "float", "float", "float", "float"],
202
+ returns: "void"
203
+ },
204
+ canvas_path_roundrect_array: {
205
+ args: ["ptr", "float", "float", "float", "float", "ptr", "int"],
206
+ returns: "void"
207
+ },
208
+ canvas_set_composite_operation: {
209
+ args: ["ptr", "cstring"],
210
+ returns: "bool"
211
+ },
212
+ canvas_draw_image_imageType: {
213
+ args: ["ptr", "ptr", "ptr", "int"],
214
+ returns: "void"
215
+ },
216
+ canvas_draw_image_canvasType: {
217
+ args: ["ptr", "ptr", "ptr", "int"],
218
+ returns: "void"
219
+ },
220
+ canvas_get_image_data: {
221
+ args: ["ptr", "int", "int", "int", "int", "ptr"],
222
+ returns: "bool"
223
+ },
224
+ canvas_put_image_data: {
225
+ args: ["ptr", "int", "int", "int", "int", "ptr"],
226
+ returns: "bool"
227
+ },
228
+ canvas_set_global_alpha: {
229
+ args: ["ptr", "float"],
230
+ returns: "float"
231
+ },
232
+ canvas_save: {
233
+ args: ["ptr"],
234
+ returns: "float"
235
+ },
236
+ canvas_restore: {
237
+ args: ["ptr"],
238
+ returns: "float"
239
+ },
240
+ canvas_translate: {
241
+ args: ["ptr", "float", "float"],
242
+ returns: "void"
243
+ },
244
+ canvas_rotate: {
245
+ args: ["ptr", "float"],
246
+ returns: "float"
247
+ },
248
+ canvas_set_font: {
249
+ args: ["ptr", "cstring"],
250
+ returns: "bool"
251
+ },
252
+ canvas_fill_text: {
253
+ args: ["ptr", "cstring", "float", "float", "float"],
254
+ returns: "void"
255
+ },
256
+ canvas_stroke_text: {
257
+ args: ["ptr", "cstring", "float", "float", "float"],
258
+ returns: "void"
259
+ },
260
+ canvas_set_shadow_blur: {
261
+ args: ["ptr", "float"],
262
+ returns: "void"
263
+ },
264
+ canvas_set_shadow_color: {
265
+ args: ["ptr", "cstring"],
266
+ returns: "void"
267
+ },
268
+ canvas_set_shadow_offsetX: {
269
+ args: ["ptr", "float"],
270
+ returns: "void"
271
+ },
272
+ canvas_set_shadow_offsetY: {
273
+ args: ["ptr", "float"],
274
+ returns: "void"
275
+ },
276
+ canvas_set_image_smoothing_quality: {
277
+ args: ["ptr", "int"],
278
+ returns: "bool"
279
+ },
280
+ canvas_set_image_smoothing_enabled: {
281
+ args: ["ptr", "bool"],
282
+ returns: "bool"
283
+ },
284
+ canvas_get_transform: {
285
+ args: ["ptr", "ptr"],
286
+ returns: "void"
287
+ },
288
+ canvas_set_transform: {
289
+ args: ["ptr", "ptr"],
290
+ returns: "void"
291
+ },
292
+ canvas_reset_transform: {
293
+ args: ["ptr"],
294
+ returns: "void"
295
+ },
296
+ canvas_set_filter: {
297
+ args: ["ptr", "cstring"],
298
+ returns: "bool"
299
+ },
300
+ canvas_set_line_dash: {
301
+ args: ["ptr", "ptr", "int", "float"],
302
+ returns: "bool"
303
+ },
304
+ canvas_set_line_join: {
305
+ args: ["ptr", "int"],
306
+ returns: "bool"
307
+ },
308
+ canvas_path_clip: {
309
+ args: ["ptr"],
310
+ returns: "void"
311
+ },
312
+ canvas_set_text_baseline: {
313
+ args: ["ptr", "int"],
314
+ returns: "void"
315
+ },
316
+ canvas_set_text_align: {
317
+ args: ["ptr", "int"],
318
+ returns: "void"
319
+ },
320
+ canvas_measure_text: {
321
+ args: ["ptr", "cstring", "ptr"],
322
+ returns: "void"
323
+ },
324
+ canvas_destroy: {
325
+ args: ["ptr"],
326
+ returns: "void"
327
+ },
328
+ image_create: {
329
+ args: [],
330
+ returns: "ptr"
331
+ },
332
+ images_cleanup: {
333
+ args: [],
334
+ returns: "void"
335
+ },
336
+ image_set_src: {
337
+ args: ["ptr", "cstring", "bool"],
338
+ returns: "void"
339
+ },
340
+ image_load: {
341
+ args: ["ptr", "ptr"],
342
+ returns: "bool"
343
+ },
344
+ image_destroy: {
345
+ args: ["ptr"],
346
+ returns: "void"
347
+ },
348
+ font_load: {
349
+ args: ["cstring"],
350
+ returns: "ptr"
351
+ },
352
+ audio_backend_init: {
353
+ args: [],
354
+ returns: "void"
355
+ },
356
+ audio_create: {
357
+ args: ["cstring"],
358
+ returns: "ptr"
359
+ },
360
+ audio_set_src: {
361
+ args: ["ptr", "cstring"],
362
+ returns: "void"
363
+ },
364
+ audio_play: {
365
+ args: ["ptr"],
366
+ returns: "void"
367
+ },
368
+ audio_stop: {
369
+ args: ["ptr"],
370
+ returns: "void"
371
+ },
372
+ audio_destroy: {
373
+ args: ["ptr"],
374
+ returns: "void"
375
+ },
376
+ path2d_create: {
377
+ args: [],
378
+ returns: "ptr"
379
+ },
380
+ path2d_create_from_copy: {
381
+ args: ["ptr"],
382
+ returns: "ptr"
383
+ },
384
+ path2d_destroy: {
385
+ args: ["ptr"],
386
+ returns: "void"
387
+ },
388
+ path2d_move_to: {
389
+ args: ["ptr", "int", "int"],
390
+ returns: "void"
391
+ },
392
+ path2d_line_to: {
393
+ args: ["ptr", "int", "int"],
394
+ returns: "void"
395
+ },
396
+ path2d_arc: {
397
+ args: ["ptr", "float", "float", "float", "float", "float"],
398
+ returns: "void"
399
+ },
400
+ path2d_arc_to: {
401
+ args: ["ptr", "float", "float", "float", "float", "float"],
402
+ returns: "void"
403
+ },
404
+ path2d_bezier_to: {
405
+ args: ["ptr", "float", "float", "float", "float", "float", "float"],
406
+ returns: "void"
407
+ },
408
+ path2d_quad_to: {
409
+ args: ["ptr", "float", "float", "float", "float"],
410
+ returns: "void"
411
+ },
412
+ path2d_ellipse: {
413
+ args: ["ptr", "float", "float", "float", "float", "float", "float", "float", "bool"],
414
+ returns: "void"
415
+ },
416
+ path2d_close: {
417
+ args: ["ptr"],
418
+ returns: "void"
419
+ },
420
+ path2d_rect: {
421
+ args: ["ptr", "float", "float", "float", "float"],
422
+ returns: "void"
423
+ },
424
+ path2d_roundrect: {
425
+ args: ["ptr", "float", "float", "float", "float", "float"],
426
+ returns: "void"
427
+ },
428
+ path2d_roundrect_array: {
429
+ args: ["ptr", "float", "float", "float", "float", "ptr", "int"],
430
+ returns: "void"
431
+ },
432
+ font_add_to_registry: {
433
+ args: ["cstring", "ptr"],
434
+ returns: "void"
435
+ }
436
+ });
437
+
438
+ // BunCanvas/src/Event.js
439
+ class Event {
440
+ type = null;
441
+ target = null;
442
+ timeStamp = performance.now();
443
+ constructor(type, target) {
444
+ this.type = type;
445
+ this.target = target;
446
+ }
447
+ }
448
+
449
+ // BunCanvas/src/Image.ts
450
+ import { ptr } from "bun:ffi";
451
+ var ptrs = new WeakMap;
452
+ var fRegistry = new FinalizationRegistry((ptr) => {
453
+ lib.symbols.image_destroy(ptr);
454
+ console.log("destroy!");
455
+ });
456
+ function computePath(url) {
457
+ const hash = createHash("sha256").update(url).digest("hex").slice(0, 16);
458
+ const parsed = new URL(url);
459
+ const filename = basename(parsed.pathname) || "index";
460
+ return join(tmpdir(), `${hash}-${filename}`);
461
+ }
462
+ function fetchToTemp(url, precomputedPath) {
463
+ return (async () => {
464
+ let path = precomputedPath ?? computePath(url);
465
+ const response = await fetch(url);
466
+ if (!response.ok || !response.body) {
467
+ throw new Error(`HTTP ${response.status}: ${url}`);
468
+ }
469
+ const buf = await response.arrayBuffer();
470
+ await Bun.write(path, buf);
471
+ return path;
472
+ })();
473
+ }
474
+ var urlRegex = /^https?:\/\/(?:www\.)?[^\s/$.?#].[^\s]*$/;
475
+
476
+ class Image {
477
+ #queue = null;
478
+ #width = 0;
479
+ #setWidth = false;
480
+ #height = 0;
481
+ #setHeight = false;
482
+ #src = "";
483
+ constructor() {
484
+ let ptr = lib.symbols.image_create();
485
+ ptrs.set(this, ptr);
486
+ fRegistry.register(this, ptr);
487
+ }
488
+ onload = null;
489
+ onerror = null;
490
+ set src(path) {
491
+ this.#src = path;
492
+ if (urlRegex.test(path)) {
493
+ const weakThis = new WeakRef(this);
494
+ const precomp = computePath(path);
495
+ const iptr = ptrs.get(this);
496
+ lib.symbols.image_set_src(iptr, encoder.encode(`${precomp}\x00`), true);
497
+ fetchToTemp(path, precomp).then(() => {
498
+ const tArr = new Int32Array(2);
499
+ const self = weakThis.deref();
500
+ if (!self) {
501
+ return;
502
+ }
503
+ if (lib.symbols.image_load(iptr, ptr(tArr))) {
504
+ this.#width = !this.#setWidth ? tArr[0] : this.#width;
505
+ this.#height = !this.#setHeight ? tArr[1] : this.#height;
506
+ self.onload?.call(self, new Event("load", self));
507
+ } else {
508
+ self.onerror?.call(self, new Event("error", self));
509
+ }
510
+ }).catch((ex) => {
511
+ const self = weakThis.deref();
512
+ if (!self)
513
+ return;
514
+ self.onerror?.call(self, new Event("error", self));
515
+ }).finally(() => {});
516
+ return;
517
+ } else {
518
+ const weakThis = new WeakRef(this);
519
+ lib.symbols.image_set_src(ptrs.get(this), encoder.encode(`${path}\x00`), false);
520
+ let tm = setTimeout(() => {
521
+ const self = weakThis.deref();
522
+ if (!self) {
523
+ clearTimeout(tm);
524
+ return;
525
+ }
526
+ const _ptr = ptrs.get(self);
527
+ const tArr = new Int32Array(2);
528
+ if (lib.symbols.image_load(_ptr, ptr(tArr))) {
529
+ this.#width = !this.#setWidth ? tArr[0] : this.#width;
530
+ this.#height = !this.#setHeight ? tArr[1] : this.#height;
531
+ self.onload?.call(self, new Event("load", self));
532
+ } else {
533
+ self.onerror?.call(self, new Event("error", self));
534
+ }
535
+ clearTimeout(tm);
536
+ }, 0);
537
+ }
538
+ }
539
+ get src() {
540
+ return this.#src;
541
+ }
542
+ get ptr() {
543
+ return ptrs.get(this);
544
+ }
545
+ get width() {
546
+ return this.#width;
547
+ }
548
+ get height() {
549
+ return this.#height;
550
+ }
551
+ set width(v) {
552
+ this.#setWidth = true;
553
+ this.#width = v;
554
+ }
555
+ set height(v) {
556
+ this.#setHeight = true;
557
+ this.#height = v;
558
+ }
559
+ }
560
+ {
561
+ const proto = Image.prototype;
562
+ for (const key of Object.getOwnPropertyNames(proto)) {
563
+ const desc = Object.getOwnPropertyDescriptor(proto, key);
564
+ if (key == "constructor") {
565
+ desc && (desc.value.toString = () => {
566
+ return `function ${proto.constructor.name}() { [native code] }`;
567
+ });
568
+ continue;
569
+ }
570
+ if (typeof desc?.value === "function") {
571
+ desc.value.toString = () => `function ${key}() { [native code] }`;
572
+ }
573
+ }
574
+ }
575
+ // BunCanvas/src/FontFace.js
576
+ var ptrs2 = new WeakMap;
577
+
578
+ class FontFace {
579
+ #fontName = "";
580
+ #path = "";
581
+ _nativePtr = null;
582
+ constructor(fontName, path) {
583
+ this.#fontName = fontName.toLowerCase();
584
+ this.#path = path.trim().replaceAll("url(", "").replaceAll('"', "").replaceAll("'", "").replaceAll(")", "").trim();
585
+ }
586
+ get family() {
587
+ return this.#fontName;
588
+ }
589
+ async load() {
590
+ return new Promise((resolve, reject) => {
591
+ this._nativePtr = lib.symbols.font_load(encoder.encode(`${this.#path}\x00`));
592
+ console.log(this._nativePtr, this.#path);
593
+ if (this._nativePtr) {
594
+ resolve();
595
+ } else {
596
+ reject();
597
+ }
598
+ });
599
+ }
600
+ }
601
+ {
602
+ const proto = FontFace.prototype;
603
+ for (const key of Object.getOwnPropertyNames(proto)) {
604
+ const desc = Object.getOwnPropertyDescriptor(proto, key);
605
+ if (key == "constructor") {
606
+ desc && (desc.value.toString = () => {
607
+ return `function ${proto.constructor.name}() { [native code] }`;
608
+ });
609
+ continue;
610
+ }
611
+ if (typeof desc?.value === "function") {
612
+ desc.value.toString = () => `function ${key}() { [native code] }`;
613
+ }
614
+ }
615
+ }
616
+ // BunCanvas/src/TextMetrics.ts
617
+ class TextMetrics {
618
+ width;
619
+ actualBoundingBoxLeft;
620
+ actualBoundingBoxRight;
621
+ actualBoundingBoxAscent;
622
+ actualBoundingBoxDescent;
623
+ fontBoundingBoxAscent;
624
+ fontBoundingBoxDescent;
625
+ emHeightAscent;
626
+ emHeightDescent;
627
+ alphabeticBaseline;
628
+ hangingBaseline;
629
+ ideographicBaseline;
630
+ constructor(width, actualBoundingBoxLeft, actualBoundingBoxRight, actualBoundingBoxAscent, actualBoundingBoxDescent, fontBoundingBoxAscent, fontBoundingBoxDescent, emHeightAscent, emHeightDescent, alphabeticBaseline, hangingBaseline, ideographicBaseline) {
631
+ this.width = width;
632
+ this.actualBoundingBoxLeft = actualBoundingBoxLeft;
633
+ this.actualBoundingBoxRight = actualBoundingBoxRight;
634
+ this.actualBoundingBoxAscent = actualBoundingBoxAscent;
635
+ this.actualBoundingBoxDescent = actualBoundingBoxDescent;
636
+ this.fontBoundingBoxAscent = fontBoundingBoxAscent;
637
+ this.fontBoundingBoxDescent = fontBoundingBoxDescent;
638
+ this.emHeightAscent = emHeightAscent;
639
+ this.emHeightDescent = emHeightDescent;
640
+ this.alphabeticBaseline = alphabeticBaseline;
641
+ this.hangingBaseline = hangingBaseline;
642
+ this.ideographicBaseline = ideographicBaseline;
643
+ }
644
+ }
645
+ // BunCanvas/src/MouseEvent.ts
646
+ class MouseEvent extends Event {
647
+ altKey = false;
648
+ button = 0;
649
+ buttons = 0;
650
+ clientX = 0;
651
+ clientY = 0;
652
+ movementX = 0;
653
+ movementY = 0;
654
+ ctrlKey = false;
655
+ metaKey = false;
656
+ screenX = 0;
657
+ screenY = 0;
658
+ shiftKey = false;
659
+ constructor(type, args = { altKey: false, button: 0, buttons: 0, clientX: 0, clientY: 0, movementX: 0, movementY: 0, ctrlKey: false, metaKey: false, screenX: 0, screenY: 0, shiftKey: false, target: null }) {
660
+ super(type, args.target);
661
+ this.altKey = args.altKey;
662
+ this.button = args.button;
663
+ this.buttons = args.buttons;
664
+ this.clientX = args.clientX;
665
+ this.clientY = args.clientY;
666
+ this.movementX = args.movementX;
667
+ this.movementY = args.movementY;
668
+ this.ctrlKey = args.ctrlKey;
669
+ this.metaKey = args.metaKey;
670
+ this.screenX = args.screenX;
671
+ this.screenY = args.screenY;
672
+ this.shiftKey = args.shiftKey;
673
+ }
674
+ }
675
+ var proto = MouseEvent.prototype;
676
+ for (const key of Object.getOwnPropertyNames(proto)) {
677
+ const desc = Object.getOwnPropertyDescriptor(proto, key);
678
+ if (key == "constructor") {
679
+ desc && (desc.value.toString = () => {
680
+ return `function ${proto.constructor.name}() { [native code] }`;
681
+ });
682
+ continue;
683
+ }
684
+ if (typeof desc?.value === "function") {
685
+ desc.value.toString = () => `function ${key}() { [native code] }`;
686
+ }
687
+ }
688
+ // BunCanvas/src/WheelEvent.ts
689
+ class WheelEvent extends MouseEvent {
690
+ deltaX = 0;
691
+ deltaY = 0;
692
+ constructor(type, args = { altKey: false, button: 0, buttons: 0, clientX: 0, clientY: 0, movementX: 0, movementY: 0, deltaX: 0, deltaY: 0, ctrlKey: false, metaKey: false, screenX: 0, screenY: 0, shiftKey: false, target: null }) {
693
+ super(type, args);
694
+ this.deltaX = args.deltaX ?? 0;
695
+ this.deltaY = args.deltaY ?? 0;
696
+ }
697
+ }
698
+ // BunCanvas/src/KeyboardEvent.js
699
+ var GLFW_KEY_MAP = {
700
+ "-1": "Unknown",
701
+ 32: " ",
702
+ 39: "'",
703
+ 44: ",",
704
+ 45: "-",
705
+ 46: ".",
706
+ 47: "/",
707
+ 48: "0",
708
+ 49: "1",
709
+ 50: "2",
710
+ 51: "3",
711
+ 52: "4",
712
+ 53: "5",
713
+ 54: "6",
714
+ 55: "7",
715
+ 56: "8",
716
+ 57: "9",
717
+ 59: ";",
718
+ 61: "=",
719
+ 65: "a",
720
+ 66: "b",
721
+ 67: "c",
722
+ 68: "d",
723
+ 69: "e",
724
+ 70: "f",
725
+ 71: "g",
726
+ 72: "h",
727
+ 73: "i",
728
+ 74: "j",
729
+ 75: "k",
730
+ 76: "l",
731
+ 77: "m",
732
+ 78: "n",
733
+ 79: "o",
734
+ 80: "p",
735
+ 81: "q",
736
+ 82: "r",
737
+ 83: "s",
738
+ 84: "t",
739
+ 85: "u",
740
+ 86: "v",
741
+ 87: "w",
742
+ 88: "x",
743
+ 89: "y",
744
+ 90: "z",
745
+ 91: "[",
746
+ 92: "\\",
747
+ 93: "]",
748
+ 96: "`",
749
+ 161: "World1",
750
+ 162: "World2",
751
+ 256: "Escape",
752
+ 257: "Enter",
753
+ 258: "Tab",
754
+ 259: "Backspace",
755
+ 260: "Insert",
756
+ 261: "Delete",
757
+ 262: "ArrowRight",
758
+ 263: "ArrowLeft",
759
+ 264: "ArrowDown",
760
+ 265: "ArrowUp",
761
+ 266: "PageUp",
762
+ 267: "PageDown",
763
+ 268: "Home",
764
+ 269: "End",
765
+ 280: "CapsLock",
766
+ 281: "ScrollLock",
767
+ 282: "NumLock",
768
+ 283: "PrintScreen",
769
+ 284: "Pause",
770
+ 290: "F1",
771
+ 291: "F2",
772
+ 292: "F3",
773
+ 293: "F4",
774
+ 294: "F5",
775
+ 295: "F6",
776
+ 296: "F7",
777
+ 297: "F8",
778
+ 298: "F9",
779
+ 299: "F10",
780
+ 300: "F11",
781
+ 301: "F12",
782
+ 302: "F13",
783
+ 303: "F14",
784
+ 304: "F15",
785
+ 305: "F16",
786
+ 306: "F17",
787
+ 307: "F18",
788
+ 308: "F19",
789
+ 309: "F20",
790
+ 310: "F21",
791
+ 311: "F22",
792
+ 312: "F23",
793
+ 313: "F24",
794
+ 314: "F25",
795
+ 320: "0",
796
+ 321: "1",
797
+ 322: "2",
798
+ 323: "3",
799
+ 324: "4",
800
+ 325: "5",
801
+ 326: "6",
802
+ 327: "7",
803
+ 328: "8",
804
+ 329: "9",
805
+ 330: ".",
806
+ 331: "/",
807
+ 332: "*",
808
+ 333: "-",
809
+ 334: "+",
810
+ 335: "Enter",
811
+ 336: "=",
812
+ 340: "Shift",
813
+ 341: "Control",
814
+ 342: "Alt",
815
+ 343: "Meta",
816
+ 344: "Shift",
817
+ 345: "Control",
818
+ 346: "Alt",
819
+ 347: "Meta",
820
+ 348: "ContextMenu"
821
+ };
822
+ var GLFW_KEY_MAP_SHIFT = {
823
+ "-1": "Unknown",
824
+ 32: " ",
825
+ 39: '"',
826
+ 44: "<",
827
+ 45: "_",
828
+ 46: ">",
829
+ 47: "?",
830
+ 48: ")",
831
+ 49: "!",
832
+ 50: "@",
833
+ 51: "#",
834
+ 52: "$",
835
+ 53: "%",
836
+ 54: "^",
837
+ 55: "&",
838
+ 56: "*",
839
+ 57: "(",
840
+ 59: ":",
841
+ 61: "+",
842
+ 65: "A",
843
+ 66: "B",
844
+ 67: "C",
845
+ 68: "D",
846
+ 69: "E",
847
+ 70: "F",
848
+ 71: "G",
849
+ 72: "H",
850
+ 73: "I",
851
+ 74: "J",
852
+ 75: "K",
853
+ 76: "L",
854
+ 77: "M",
855
+ 78: "N",
856
+ 79: "O",
857
+ 80: "P",
858
+ 81: "Q",
859
+ 82: "R",
860
+ 83: "S",
861
+ 84: "T",
862
+ 85: "U",
863
+ 86: "V",
864
+ 87: "W",
865
+ 88: "X",
866
+ 89: "Y",
867
+ 90: "Z",
868
+ 91: "{",
869
+ 92: "|",
870
+ 93: "}",
871
+ 96: "~",
872
+ 161: "World1",
873
+ 162: "World2",
874
+ 256: "Escape",
875
+ 257: "Enter",
876
+ 258: "Tab",
877
+ 259: "Backspace",
878
+ 260: "Insert",
879
+ 261: "Delete",
880
+ 262: "ArrowRight",
881
+ 263: "ArrowLeft",
882
+ 264: "ArrowDown",
883
+ 265: "ArrowUp",
884
+ 266: "PageUp",
885
+ 267: "PageDown",
886
+ 268: "Home",
887
+ 269: "End",
888
+ 280: "CapsLock",
889
+ 281: "ScrollLock",
890
+ 282: "NumLock",
891
+ 283: "PrintScreen",
892
+ 284: "Pause",
893
+ 290: "F1",
894
+ 291: "F2",
895
+ 292: "F3",
896
+ 293: "F4",
897
+ 294: "F5",
898
+ 295: "F6",
899
+ 296: "F7",
900
+ 297: "F8",
901
+ 298: "F9",
902
+ 299: "F10",
903
+ 300: "F11",
904
+ 301: "F12",
905
+ 302: "F13",
906
+ 303: "F14",
907
+ 304: "F15",
908
+ 305: "F16",
909
+ 306: "F17",
910
+ 307: "F18",
911
+ 308: "F19",
912
+ 309: "F20",
913
+ 310: "F21",
914
+ 311: "F22",
915
+ 312: "F23",
916
+ 313: "F24",
917
+ 314: "F25",
918
+ 320: "0",
919
+ 321: "1",
920
+ 322: "2",
921
+ 323: "3",
922
+ 324: "4",
923
+ 325: "5",
924
+ 326: "6",
925
+ 327: "7",
926
+ 328: "8",
927
+ 329: "9",
928
+ 330: ".",
929
+ 331: "/",
930
+ 332: "*",
931
+ 333: "-",
932
+ 334: "+",
933
+ 335: "Enter",
934
+ 336: "=",
935
+ 340: "Shift",
936
+ 341: "Control",
937
+ 342: "Alt",
938
+ 343: "Meta",
939
+ 344: "Shift",
940
+ 345: "Control",
941
+ 346: "Alt",
942
+ 347: "Meta",
943
+ 348: "ContextMenu"
944
+ };
945
+ var GLFW_CODE_MAP = {
946
+ "-1": "Unknown",
947
+ 32: "Space",
948
+ 39: "Quote",
949
+ 44: "Comma",
950
+ 45: "Minus",
951
+ 46: "Period",
952
+ 47: "Slash",
953
+ 48: "Digit0",
954
+ 49: "Digit1",
955
+ 50: "Digit2",
956
+ 51: "Digit3",
957
+ 52: "Digit4",
958
+ 53: "Digit5",
959
+ 54: "Digit6",
960
+ 55: "Digit7",
961
+ 56: "Digit8",
962
+ 57: "Digit9",
963
+ 59: "Semicolon",
964
+ 61: "Equal",
965
+ 65: "KeyA",
966
+ 66: "KeyB",
967
+ 67: "KeyC",
968
+ 68: "KeyD",
969
+ 69: "KeyE",
970
+ 70: "KeyF",
971
+ 71: "KeyG",
972
+ 72: "KeyH",
973
+ 73: "KeyI",
974
+ 74: "KeyJ",
975
+ 75: "KeyK",
976
+ 76: "KeyL",
977
+ 77: "KeyM",
978
+ 78: "KeyN",
979
+ 79: "KeyO",
980
+ 80: "KeyP",
981
+ 81: "KeyQ",
982
+ 82: "KeyR",
983
+ 83: "KeyS",
984
+ 84: "KeyT",
985
+ 85: "KeyU",
986
+ 86: "KeyV",
987
+ 87: "KeyW",
988
+ 88: "KeyX",
989
+ 89: "KeyY",
990
+ 90: "KeyZ",
991
+ 91: "BracketLeft",
992
+ 92: "Backslash",
993
+ 93: "BracketRight",
994
+ 96: "Backquote",
995
+ 161: "IntlBackslash",
996
+ 256: "Escape",
997
+ 257: "Enter",
998
+ 258: "Tab",
999
+ 259: "Backspace",
1000
+ 260: "Insert",
1001
+ 261: "Delete",
1002
+ 262: "ArrowRight",
1003
+ 263: "ArrowLeft",
1004
+ 264: "ArrowDown",
1005
+ 265: "ArrowUp",
1006
+ 266: "PageUp",
1007
+ 267: "PageDown",
1008
+ 268: "Home",
1009
+ 269: "End",
1010
+ 280: "CapsLock",
1011
+ 281: "ScrollLock",
1012
+ 282: "NumLock",
1013
+ 283: "PrintScreen",
1014
+ 284: "Pause",
1015
+ 290: "F1",
1016
+ 291: "F2",
1017
+ 292: "F3",
1018
+ 293: "F4",
1019
+ 294: "F5",
1020
+ 295: "F6",
1021
+ 296: "F7",
1022
+ 297: "F8",
1023
+ 298: "F9",
1024
+ 299: "F10",
1025
+ 300: "F11",
1026
+ 301: "F12",
1027
+ 302: "F13",
1028
+ 303: "F14",
1029
+ 304: "F15",
1030
+ 305: "F16",
1031
+ 306: "F17",
1032
+ 307: "F18",
1033
+ 308: "F19",
1034
+ 309: "F20",
1035
+ 310: "F21",
1036
+ 311: "F22",
1037
+ 312: "F23",
1038
+ 313: "F24",
1039
+ 314: "F25",
1040
+ 320: "Numpad0",
1041
+ 321: "Numpad1",
1042
+ 322: "Numpad2",
1043
+ 323: "Numpad3",
1044
+ 324: "Numpad4",
1045
+ 325: "Numpad5",
1046
+ 326: "Numpad6",
1047
+ 327: "Numpad7",
1048
+ 328: "Numpad8",
1049
+ 329: "Numpad9",
1050
+ 330: "NumpadDecimal",
1051
+ 331: "NumpadDivide",
1052
+ 332: "NumpadMultiply",
1053
+ 333: "NumpadSubtract",
1054
+ 334: "NumpadAdd",
1055
+ 335: "NumpadEnter",
1056
+ 336: "NumpadEqual",
1057
+ 340: "ShiftLeft",
1058
+ 341: "ControlLeft",
1059
+ 342: "AltLeft",
1060
+ 343: "MetaLeft",
1061
+ 344: "ShiftRight",
1062
+ 345: "ControlRight",
1063
+ 346: "AltRight",
1064
+ 347: "MetaRight",
1065
+ 348: "ContextMenu"
1066
+ };
1067
+
1068
+ class KeyboardEvent extends Event {
1069
+ target = null;
1070
+ key = "";
1071
+ code = "";
1072
+ location = 0;
1073
+ repeat = false;
1074
+ ctrlKey = false;
1075
+ shiftKey = false;
1076
+ altKey = false;
1077
+ metaKey = false;
1078
+ constructor(type, args = {
1079
+ target: null,
1080
+ key: "",
1081
+ code: "",
1082
+ location: 0,
1083
+ repeat: false,
1084
+ ctrlKey: false,
1085
+ shiftKey: false,
1086
+ altKey: false,
1087
+ metaKey: false
1088
+ }, kcode = null, target = null, repeat = false, shiftKey = false, ctrlKey = false, altKey = false, metaKey = false) {
1089
+ super(type, args ? args.target : target);
1090
+ if (!!args) {
1091
+ this.key = args.key;
1092
+ this.code = args.code;
1093
+ this.location = args.location;
1094
+ this.repeat = args.repeat;
1095
+ this.ctrlKey = args.ctrlKey;
1096
+ this.shiftKey = args.shiftKey;
1097
+ this.altKey = args.altKey;
1098
+ this.metaKey = args.metaKey;
1099
+ } else {
1100
+ const glfwKey = kcode;
1101
+ if (glfwKey >= 65 && glfwKey <= 90) {
1102
+ let c = String.fromCharCode(glfwKey);
1103
+ this.key = shiftKey ?? args.shiftKey ? c : c.toLowerCase();
1104
+ } else {
1105
+ this.key = shiftKey ?? args.shiftKey ? GLFW_KEY_MAP_SHIFT[kcode] : GLFW_KEY_MAP[kcode];
1106
+ }
1107
+ this.code = GLFW_CODE_MAP[kcode];
1108
+ this.location = 0;
1109
+ this.repeat = false;
1110
+ this.shiftKey = shiftKey;
1111
+ this.ctrlKey = ctrlKey;
1112
+ this.altKey = altKey;
1113
+ this.metaKey = metaKey;
1114
+ }
1115
+ }
1116
+ }
1117
+ // BunCanvas/src/Canvas.ts
1118
+ import { ptr as ptr3, JSCallback } from "bun:ffi";
1119
+
1120
+ // BunCanvas/src/ImageData.ts
1121
+ class ImageData {
1122
+ width;
1123
+ height;
1124
+ data;
1125
+ constructor(width, height, data) {
1126
+ this.width = width;
1127
+ this.height = height;
1128
+ this.data = data;
1129
+ }
1130
+ }
1131
+
1132
+ // BunCanvas/dom/DOMMatrix.ts
1133
+ import { ptr as ptr2 } from "bun:ffi";
1134
+ function isMatrixArray(value) {
1135
+ return value == undefined || Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
1136
+ }
1137
+ function multipliedMatrices(a, b) {
1138
+ const out = new Float64Array(16);
1139
+ out[0] = a[0] * b[0] + a[1] * b[4] + a[2] * b[8] + a[3] * b[12];
1140
+ out[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[9] + a[3] * b[13];
1141
+ out[2] = a[0] * b[2] + a[1] * b[6] + a[2] * b[10] + a[3] * b[14];
1142
+ out[3] = a[0] * b[3] + a[1] * b[7] + a[2] * b[11] + a[3] * b[15];
1143
+ out[4] = a[4] * b[0] + a[5] * b[4] + a[6] * b[8] + a[7] * b[12];
1144
+ out[5] = a[4] * b[1] + a[5] * b[5] + a[6] * b[9] + a[7] * b[13];
1145
+ out[6] = a[4] * b[2] + a[5] * b[6] + a[6] * b[10] + a[7] * b[14];
1146
+ out[7] = a[4] * b[3] + a[5] * b[7] + a[6] * b[11] + a[7] * b[15];
1147
+ out[8] = a[8] * b[0] + a[9] * b[4] + a[10] * b[8] + a[11] * b[12];
1148
+ out[9] = a[8] * b[1] + a[9] * b[5] + a[10] * b[9] + a[11] * b[13];
1149
+ out[10] = a[8] * b[2] + a[9] * b[6] + a[10] * b[10] + a[11] * b[14];
1150
+ out[11] = a[8] * b[3] + a[9] * b[7] + a[10] * b[11] + a[11] * b[15];
1151
+ out[12] = a[12] * b[0] + a[13] * b[4] + a[14] * b[8] + a[15] * b[12];
1152
+ out[13] = a[12] * b[1] + a[13] * b[5] + a[14] * b[9] + a[15] * b[13];
1153
+ out[14] = a[12] * b[2] + a[13] * b[6] + a[14] * b[10] + a[15] * b[14];
1154
+ out[15] = a[12] * b[3] + a[13] * b[7] + a[14] * b[11] + a[15] * b[15];
1155
+ return out;
1156
+ }
1157
+ function throwParseErrorDMatrix(fName, pString) {
1158
+ throw new SyntaxError(`Failed to execute '${fName}' on 'DOMMatrix': Failed to parse '${pString}'.`);
1159
+ }
1160
+
1161
+ class DOMMatrix {
1162
+ #internal = new Float64Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
1163
+ #isIdentity = true;
1164
+ #computeIdentity() {
1165
+ this.#isIdentity = this.#internal[0] == 1 && this.#internal[1] == 0 && this.#internal[2] == 0 && this.#internal[3] == 0 && this.#internal[4] == 0 && this.#internal[5] == 1 && this.#internal[6] == 0 && this.#internal[7] == 0 && this.#internal[8] == 0 && this.#internal[9] == 0 && this.#internal[10] == 1 && this.#internal[11] == 0 && this.#internal[12] == 0 && this.#internal[13] == 0 && this.#internal[14] == 0 && this.#internal[15] == 1;
1166
+ }
1167
+ get a() {
1168
+ return this.m11;
1169
+ }
1170
+ set a(v) {
1171
+ this.m11 = v;
1172
+ }
1173
+ get b() {
1174
+ return this.m12;
1175
+ }
1176
+ set b(v) {
1177
+ this.m12 = v;
1178
+ }
1179
+ get c() {
1180
+ return this.m21;
1181
+ }
1182
+ set c(v) {
1183
+ this.m21 = v;
1184
+ }
1185
+ get d() {
1186
+ return this.m22;
1187
+ }
1188
+ set d(v) {
1189
+ this.m22 = v;
1190
+ }
1191
+ get e() {
1192
+ return this.m41;
1193
+ }
1194
+ set e(v) {
1195
+ this.m41 = v;
1196
+ }
1197
+ get f() {
1198
+ return this.m42;
1199
+ }
1200
+ set f(v) {
1201
+ this.m42 = v;
1202
+ }
1203
+ is2D = true;
1204
+ get isIdentity() {
1205
+ return this.#isIdentity;
1206
+ }
1207
+ get m11() {
1208
+ return this.#internal[0];
1209
+ }
1210
+ set m11(v) {
1211
+ this.#internal[0] = v;
1212
+ if (!this.#isIdentity) {
1213
+ if (v == 1)
1214
+ this.#computeIdentity();
1215
+ } else {
1216
+ if (v != 1)
1217
+ this.#isIdentity = false;
1218
+ }
1219
+ }
1220
+ get m12() {
1221
+ return this.#internal[4];
1222
+ }
1223
+ set m12(v) {
1224
+ this.#internal[4] = v;
1225
+ if (!this.#isIdentity) {
1226
+ if (v == 0)
1227
+ this.#computeIdentity();
1228
+ } else {
1229
+ if (v != 0)
1230
+ this.#isIdentity = false;
1231
+ }
1232
+ }
1233
+ get m13() {
1234
+ return this.#internal[8];
1235
+ }
1236
+ set m13(v) {
1237
+ this.#internal[8] = v;
1238
+ if (!this.#isIdentity) {
1239
+ if (v == 0)
1240
+ this.#computeIdentity();
1241
+ } else {
1242
+ if (v != 0)
1243
+ this.#isIdentity = false;
1244
+ }
1245
+ }
1246
+ get m14() {
1247
+ return this.#internal[12];
1248
+ }
1249
+ set m14(v) {
1250
+ this.#internal[12] = v;
1251
+ if (!this.#isIdentity) {
1252
+ if (v == 0)
1253
+ this.#computeIdentity();
1254
+ } else {
1255
+ if (v != 0)
1256
+ this.#isIdentity = false;
1257
+ }
1258
+ }
1259
+ get m21() {
1260
+ return this.#internal[1];
1261
+ }
1262
+ set m21(v) {
1263
+ this.#internal[1] = v;
1264
+ if (!this.#isIdentity) {
1265
+ if (v == 0)
1266
+ this.#computeIdentity();
1267
+ } else {
1268
+ if (v != 0)
1269
+ this.#isIdentity = false;
1270
+ }
1271
+ }
1272
+ get m22() {
1273
+ return this.#internal[5];
1274
+ }
1275
+ set m22(v) {
1276
+ this.#internal[5] = v;
1277
+ if (!this.#isIdentity) {
1278
+ if (v == 1)
1279
+ this.#computeIdentity();
1280
+ } else {
1281
+ if (v != 1)
1282
+ this.#isIdentity = false;
1283
+ }
1284
+ }
1285
+ get m23() {
1286
+ return this.#internal[9];
1287
+ }
1288
+ set m23(v) {
1289
+ this.#internal[9] = v;
1290
+ if (!this.#isIdentity) {
1291
+ if (v == 0)
1292
+ this.#computeIdentity();
1293
+ } else {
1294
+ if (v != 0)
1295
+ this.#isIdentity = false;
1296
+ }
1297
+ }
1298
+ get m24() {
1299
+ return this.#internal[13];
1300
+ }
1301
+ set m24(v) {
1302
+ this.#internal[13] = v;
1303
+ if (!this.#isIdentity) {
1304
+ if (v == 0)
1305
+ this.#computeIdentity();
1306
+ } else {
1307
+ if (v != 0)
1308
+ this.#isIdentity = false;
1309
+ }
1310
+ }
1311
+ get m31() {
1312
+ return this.#internal[2];
1313
+ }
1314
+ set m31(v) {
1315
+ this.#internal[2] = v;
1316
+ if (!this.#isIdentity) {
1317
+ if (v == 0)
1318
+ this.#computeIdentity();
1319
+ } else {
1320
+ if (v != 0)
1321
+ this.#isIdentity = false;
1322
+ }
1323
+ }
1324
+ get m32() {
1325
+ return this.#internal[6];
1326
+ }
1327
+ set m32(v) {
1328
+ this.#internal[6] = v;
1329
+ if (!this.#isIdentity) {
1330
+ if (v == 0)
1331
+ this.#computeIdentity();
1332
+ } else {
1333
+ if (v != 0)
1334
+ this.#isIdentity = false;
1335
+ }
1336
+ }
1337
+ get m33() {
1338
+ return this.#internal[10];
1339
+ }
1340
+ set m33(v) {
1341
+ this.#internal[10] = v;
1342
+ if (!this.#isIdentity) {
1343
+ if (v == 1)
1344
+ this.#computeIdentity();
1345
+ } else {
1346
+ if (v != 1)
1347
+ this.#isIdentity = false;
1348
+ }
1349
+ }
1350
+ get m34() {
1351
+ return this.#internal[14];
1352
+ }
1353
+ set m34(v) {
1354
+ this.#internal[14] = v;
1355
+ if (!this.#isIdentity) {
1356
+ if (v == 0)
1357
+ this.#computeIdentity();
1358
+ } else {
1359
+ if (v != 0)
1360
+ this.#isIdentity = false;
1361
+ }
1362
+ }
1363
+ get m41() {
1364
+ return this.#internal[3];
1365
+ }
1366
+ set m41(v) {
1367
+ this.#internal[3] = v;
1368
+ if (!this.#isIdentity) {
1369
+ if (v == 0)
1370
+ this.#computeIdentity();
1371
+ } else {
1372
+ if (v != 0)
1373
+ this.#isIdentity = false;
1374
+ }
1375
+ }
1376
+ get m42() {
1377
+ return this.#internal[7];
1378
+ }
1379
+ set m42(v) {
1380
+ this.#internal[7] = v;
1381
+ if (!this.#isIdentity) {
1382
+ if (v == 0)
1383
+ this.#computeIdentity();
1384
+ } else {
1385
+ if (v != 0)
1386
+ this.#isIdentity = false;
1387
+ }
1388
+ }
1389
+ get m43() {
1390
+ return this.#internal[11];
1391
+ }
1392
+ set m43(v) {
1393
+ this.#internal[11] = v;
1394
+ if (!this.#isIdentity) {
1395
+ if (v == 0)
1396
+ this.#computeIdentity();
1397
+ } else {
1398
+ if (v != 0)
1399
+ this.#isIdentity = false;
1400
+ }
1401
+ }
1402
+ get m44() {
1403
+ return this.#internal[15];
1404
+ }
1405
+ set m44(v) {
1406
+ this.#internal[15] = v;
1407
+ if (!this.#isIdentity) {
1408
+ if (v == 1)
1409
+ this.#computeIdentity();
1410
+ } else {
1411
+ if (v != 1)
1412
+ this.#isIdentity = false;
1413
+ }
1414
+ }
1415
+ multiplySelf(other) {
1416
+ const a = this.#internal;
1417
+ const b = other.#internal;
1418
+ this.#internal.set(multipliedMatrices(a, b));
1419
+ this.is2D &&= other.is2D;
1420
+ return this;
1421
+ }
1422
+ preMultiplySelf(other) {
1423
+ const a = this.#internal;
1424
+ const b = other.#internal;
1425
+ this.#internal.set(multipliedMatrices(b, a));
1426
+ this.is2D &&= other.is2D;
1427
+ return this;
1428
+ }
1429
+ translateSelf(tx = 0, ty = 0, tz = 0) {
1430
+ const t = new Float64Array([
1431
+ 1,
1432
+ 0,
1433
+ 0,
1434
+ tx,
1435
+ 0,
1436
+ 1,
1437
+ 0,
1438
+ ty,
1439
+ 0,
1440
+ 0,
1441
+ 1,
1442
+ tz,
1443
+ 0,
1444
+ 0,
1445
+ 0,
1446
+ 1
1447
+ ]);
1448
+ this.#internal.set(multipliedMatrices(this.#internal, t));
1449
+ if (tz !== 0)
1450
+ this.is2D = false;
1451
+ return this;
1452
+ }
1453
+ scaleSelf(scaleX = 1, scaleY = scaleX, scaleZ = 1, originX = 0, originY = 0, originZ = 0) {
1454
+ if (originX || originY || originZ)
1455
+ this.translateSelf(originX, originY, originZ);
1456
+ const s = new Float64Array([
1457
+ scaleX,
1458
+ 0,
1459
+ 0,
1460
+ 0,
1461
+ 0,
1462
+ scaleY,
1463
+ 0,
1464
+ 0,
1465
+ 0,
1466
+ 0,
1467
+ scaleZ,
1468
+ 0,
1469
+ 0,
1470
+ 0,
1471
+ 0,
1472
+ 1
1473
+ ]);
1474
+ this.#internal.set(multipliedMatrices(this.#internal, s));
1475
+ if (originX || originY || originZ)
1476
+ this.translateSelf(-originX, -originY, -originZ);
1477
+ if (scaleZ !== 1 || originZ !== 0)
1478
+ this.is2D = false;
1479
+ return this;
1480
+ }
1481
+ scale3dSelf(scale, originX = 0, originY = 0, originZ = 0) {
1482
+ return this.scaleSelf(scale, scale, scale, originX, originY, originZ);
1483
+ }
1484
+ rotateSelf(...args) {
1485
+ if (args[1] === undefined && args[2] === undefined) {
1486
+ args[2] = args[0];
1487
+ args[0] = 0;
1488
+ args[1] = 0;
1489
+ } else {
1490
+ args[1] ??= 0;
1491
+ args[2] ??= 0;
1492
+ }
1493
+ const rx = args[0] * Math.PI / 180;
1494
+ const ry = args[1] * Math.PI / 180;
1495
+ const rz = args[2] * Math.PI / 180;
1496
+ const sx = Math.sin(rx), cx = Math.cos(rx);
1497
+ const sy = Math.sin(ry), cy = Math.cos(ry);
1498
+ const sz = Math.sin(rz), cz = Math.cos(rz);
1499
+ if (args[2] !== 0) {
1500
+ this.#internal.set(multipliedMatrices(this.#internal, new Float64Array([
1501
+ cz,
1502
+ -sz,
1503
+ 0,
1504
+ 0,
1505
+ sz,
1506
+ cz,
1507
+ 0,
1508
+ 0,
1509
+ 0,
1510
+ 0,
1511
+ 1,
1512
+ 0,
1513
+ 0,
1514
+ 0,
1515
+ 0,
1516
+ 1
1517
+ ])));
1518
+ }
1519
+ if (args[1] !== 0) {
1520
+ this.#internal.set(multipliedMatrices(new Float64Array([
1521
+ cy,
1522
+ 0,
1523
+ sy,
1524
+ 0,
1525
+ 0,
1526
+ 1,
1527
+ 0,
1528
+ 0,
1529
+ -sy,
1530
+ 0,
1531
+ cy,
1532
+ 0,
1533
+ 0,
1534
+ 0,
1535
+ 0,
1536
+ 1
1537
+ ]), this.#internal));
1538
+ }
1539
+ if (args[0] !== 0) {
1540
+ this.#internal.set(multipliedMatrices(new Float64Array([
1541
+ 1,
1542
+ 0,
1543
+ 0,
1544
+ 0,
1545
+ 0,
1546
+ cx,
1547
+ -sx,
1548
+ 0,
1549
+ 0,
1550
+ sx,
1551
+ cx,
1552
+ 0,
1553
+ 0,
1554
+ 0,
1555
+ 0,
1556
+ 1
1557
+ ]), this.#internal));
1558
+ }
1559
+ if (args[0] !== 0 || args[1] !== 0)
1560
+ this.is2D = false;
1561
+ return this;
1562
+ }
1563
+ rotateAxisAngleSelf(x = 0, y = 0, z = 1, angle = 0) {
1564
+ const length = Math.hypot(x, y, z);
1565
+ if (length === 0)
1566
+ return this;
1567
+ x /= length;
1568
+ y /= length;
1569
+ z /= length;
1570
+ const rad = angle * Math.PI / 180;
1571
+ const s = Math.sin(rad);
1572
+ const c = Math.cos(rad);
1573
+ const t = 1 - c;
1574
+ const r = new Float64Array([
1575
+ t * x * x + c,
1576
+ t * x * y - s * z,
1577
+ t * x * z + s * y,
1578
+ 0,
1579
+ t * x * y + s * z,
1580
+ t * y * y + c,
1581
+ t * y * z - s * x,
1582
+ 0,
1583
+ t * x * z - s * y,
1584
+ t * y * z + s * x,
1585
+ t * z * z + c,
1586
+ 0,
1587
+ 0,
1588
+ 0,
1589
+ 0,
1590
+ 1
1591
+ ]);
1592
+ this.#internal.set(multipliedMatrices(this.#internal, r));
1593
+ if (x !== 0 || y !== 0)
1594
+ this.is2D = false;
1595
+ return this;
1596
+ }
1597
+ rotateFromVectorSelf(x = 0, y = 0) {
1598
+ if (x === 0 && y === 0)
1599
+ return this;
1600
+ const angle = Math.atan2(y, x) * 180 / Math.PI;
1601
+ return this.rotateSelf(angle);
1602
+ }
1603
+ skewXSelf(sx = 0) {
1604
+ const t = Math.tan(sx * Math.PI / 180);
1605
+ this.#internal.set(multipliedMatrices(this.#internal, new Float64Array([
1606
+ 1,
1607
+ t,
1608
+ 0,
1609
+ 0,
1610
+ 0,
1611
+ 1,
1612
+ 0,
1613
+ 0,
1614
+ 0,
1615
+ 0,
1616
+ 1,
1617
+ 0,
1618
+ 0,
1619
+ 0,
1620
+ 0,
1621
+ 1
1622
+ ])));
1623
+ return this;
1624
+ }
1625
+ skewYSelf(sy = 0) {
1626
+ const t = Math.tan(sy * Math.PI / 180);
1627
+ this.#internal.set(multipliedMatrices(this.#internal, new Float64Array([
1628
+ 1,
1629
+ 0,
1630
+ 0,
1631
+ 0,
1632
+ t,
1633
+ 1,
1634
+ 0,
1635
+ 0,
1636
+ 0,
1637
+ 0,
1638
+ 1,
1639
+ 0,
1640
+ 0,
1641
+ 0,
1642
+ 0,
1643
+ 1
1644
+ ])));
1645
+ return this;
1646
+ }
1647
+ #parseTransformList(value) {
1648
+ const transforms = [];
1649
+ let i = 0;
1650
+ while (i < value.length) {
1651
+ while (/\s/.test(value[i]))
1652
+ i++;
1653
+ if (i >= value.length)
1654
+ break;
1655
+ const nameStart = i;
1656
+ while (/[A-Za-z0-9]/.test(value[i]))
1657
+ i++;
1658
+ const name = value.substring(nameStart, i);
1659
+ while (/\s/.test(value[i]))
1660
+ i++;
1661
+ if (value[i] !== "(")
1662
+ return "error";
1663
+ i++;
1664
+ let depth = 1;
1665
+ const argsStart = i;
1666
+ while (i < value.length && depth > 0) {
1667
+ if (value[i] === "(")
1668
+ depth++;
1669
+ else if (value[i] === ")")
1670
+ depth--;
1671
+ i++;
1672
+ }
1673
+ if (depth !== 0)
1674
+ return "error";
1675
+ transforms.push({
1676
+ name,
1677
+ args: value.substring(argsStart, i - 1)
1678
+ });
1679
+ }
1680
+ return transforms;
1681
+ }
1682
+ #splitArguments(args) {
1683
+ const result = [];
1684
+ let current = "";
1685
+ let depth = 0;
1686
+ for (const c of args) {
1687
+ if (c === "(")
1688
+ depth++;
1689
+ if (c === ")")
1690
+ depth--;
1691
+ if ((c === "," || /\s/.test(c)) && depth === 0) {
1692
+ if (current.length) {
1693
+ result.push(current);
1694
+ current = "";
1695
+ }
1696
+ continue;
1697
+ }
1698
+ current += c;
1699
+ }
1700
+ if (current.length)
1701
+ result.push(current);
1702
+ return result;
1703
+ }
1704
+ #parseAngle(value) {
1705
+ if (value.endsWith("deg"))
1706
+ return Number.parseFloat(value);
1707
+ if (value.endsWith("rad"))
1708
+ return Number.parseFloat(value) * 180 / Math.PI;
1709
+ if (value.endsWith("grad"))
1710
+ return Number.parseFloat(value) * 0.9;
1711
+ if (value.endsWith("turn"))
1712
+ return Number.parseFloat(value) * 360;
1713
+ return Number.parseFloat(value);
1714
+ }
1715
+ #parseLength(value) {
1716
+ if (!value)
1717
+ return null;
1718
+ const rootFontSize = 16;
1719
+ const parentFontSize = 16;
1720
+ const exSize = 8;
1721
+ const chSize = 8;
1722
+ if (value.endsWith("px"))
1723
+ return Number.parseFloat(value);
1724
+ if (value.endsWith("pt"))
1725
+ return Number.parseFloat(value) * 1.3333333730697632;
1726
+ if (value.endsWith("pc"))
1727
+ return Number.parseFloat(value) * 16;
1728
+ if (value.endsWith("in"))
1729
+ return Number.parseFloat(value) * 96;
1730
+ if (value.endsWith("cm"))
1731
+ return Number.parseFloat(value) * 37.79527559055118;
1732
+ if (value.endsWith("mm"))
1733
+ return Number.parseFloat(value) * 3.7795275590551185;
1734
+ if (value.endsWith("q"))
1735
+ return Number.parseFloat(value) * 0.9448818897637796;
1736
+ if (value.endsWith("em"))
1737
+ return Number.parseFloat(value) * parentFontSize;
1738
+ if (value.endsWith("rem"))
1739
+ return Number.parseFloat(value) * rootFontSize;
1740
+ if (value.endsWith("ex"))
1741
+ return Number.parseFloat(value) * exSize;
1742
+ if (value.endsWith("ch"))
1743
+ return Number.parseFloat(value) * chSize;
1744
+ if (value.endsWith("%"))
1745
+ return Number.parseFloat(value) * parentFontSize / 100;
1746
+ if (value.endsWith("px")) {
1747
+ return Number.parseFloat(value);
1748
+ } else if (value.endsWith("pt")) {
1749
+ return Number.parseFloat(value) * 1.3333333730697632;
1750
+ }
1751
+ return null;
1752
+ }
1753
+ setMatrixValue(value) {
1754
+ value = value.trim();
1755
+ if (value.length === 0)
1756
+ throw new DOMException("Invalid transform.", "SyntaxError");
1757
+ const transforms = this.#parseTransformList(value);
1758
+ if (transforms == "error") {
1759
+ throwParseErrorDMatrix("setMatrixValue", value);
1760
+ return;
1761
+ }
1762
+ for (const transform of transforms) {
1763
+ const args = this.#splitArguments(transform.args);
1764
+ switch (transform.name) {
1765
+ case "matrix": {
1766
+ if (args.length !== 6)
1767
+ throw new DOMException("matrix() requires 6 arguments.", "SyntaxError");
1768
+ let a = Number.parseFloat(args[0]);
1769
+ let b = Number.parseFloat(args[1]);
1770
+ let c = Number.parseFloat(args[2]);
1771
+ let d = Number.parseFloat(args[3]);
1772
+ if (isNaN(a) || isNaN(b) || isNaN(c) || isNaN(d))
1773
+ throwParseErrorDMatrix("setMatrixValue", value);
1774
+ this.a = a;
1775
+ this.b = b;
1776
+ this.c = c;
1777
+ this.d = d;
1778
+ this.e = this.#parseLength(args[4]);
1779
+ this.f = this.#parseLength(args[5]);
1780
+ this.is2D = true;
1781
+ break;
1782
+ }
1783
+ case "matrix3d": {
1784
+ if (args.length !== 16)
1785
+ throwParseErrorDMatrix("setMatrixValue", value);
1786
+ for (let i = 0;i < 16; i++)
1787
+ this.#internal[i] = Number.parseFloat(args[i]);
1788
+ this.is2D = false;
1789
+ break;
1790
+ }
1791
+ case "translate": {
1792
+ if (args.length < 1 || args.length > 2)
1793
+ throwParseErrorDMatrix("setMatrixValue", value);
1794
+ let lx = this.#parseLength(args[0]);
1795
+ let ly = this.#parseLength(args[1]);
1796
+ if (!lx) {
1797
+ throwParseErrorDMatrix("setMatrixValue", value);
1798
+ return;
1799
+ }
1800
+ const tx = lx;
1801
+ const ty = args.length === 2 ? ly ?? 0 : 0;
1802
+ this.translateSelf(tx, ty);
1803
+ break;
1804
+ }
1805
+ case "translateX": {
1806
+ if (args.length !== 1)
1807
+ throwParseErrorDMatrix("setMatrixValue", value);
1808
+ let l = this.#parseLength(args[0]);
1809
+ if (!l) {
1810
+ throwParseErrorDMatrix("setMatrixValue", value);
1811
+ return;
1812
+ }
1813
+ this.translateSelf(l, 0);
1814
+ break;
1815
+ }
1816
+ case "translateY": {
1817
+ if (args.length !== 1)
1818
+ throwParseErrorDMatrix("setMatrixValue", value);
1819
+ let l = this.#parseLength(args[0]);
1820
+ if (!l) {
1821
+ throwParseErrorDMatrix("setMatrixValue", value);
1822
+ return;
1823
+ }
1824
+ this.translateSelf(0, l);
1825
+ break;
1826
+ }
1827
+ case "translateZ": {
1828
+ if (args.length !== 1)
1829
+ throwParseErrorDMatrix("setMatrixValue", value);
1830
+ let l = this.#parseLength(args[0]);
1831
+ if (!l) {
1832
+ throwParseErrorDMatrix("setMatrixValue", value);
1833
+ return;
1834
+ }
1835
+ this.translateSelf(0, 0, l);
1836
+ break;
1837
+ }
1838
+ case "translate3d": {
1839
+ if (args.length !== 3)
1840
+ throwParseErrorDMatrix("setMatrixValue", value);
1841
+ let la = this.#parseLength(args[0]);
1842
+ let lb = this.#parseLength(args[0]);
1843
+ let lc = this.#parseLength(args[0]);
1844
+ if (!la || !lb || !lc) {
1845
+ throwParseErrorDMatrix("setMatrixValue", value);
1846
+ return;
1847
+ }
1848
+ this.translateSelf(la, lb, lc);
1849
+ break;
1850
+ }
1851
+ case "scale": {
1852
+ if (args.length < 1 || args.length > 2)
1853
+ throwParseErrorDMatrix("setMatrixValue", value);
1854
+ const sx = Number.parseFloat(args[0]);
1855
+ const sy = args.length === 2 ? Number.parseFloat(args[1]) : sx;
1856
+ this.scaleSelf(sx, sy);
1857
+ break;
1858
+ }
1859
+ case "scaleX": {
1860
+ if (args.length !== 1)
1861
+ throwParseErrorDMatrix("setMatrixValue", value);
1862
+ this.scaleSelf(Number.parseFloat(args[0]), 1);
1863
+ break;
1864
+ }
1865
+ case "scaleY": {
1866
+ if (args.length !== 1)
1867
+ throwParseErrorDMatrix("setMatrixValue", value);
1868
+ this.scaleSelf(1, Number.parseFloat(args[0]));
1869
+ break;
1870
+ }
1871
+ case "scaleZ": {
1872
+ if (args.length !== 1)
1873
+ throwParseErrorDMatrix("setMatrixValue", value);
1874
+ this.scaleSelf(1, 1, Number.parseFloat(args[0]));
1875
+ break;
1876
+ }
1877
+ case "scale3d": {
1878
+ if (args.length !== 3)
1879
+ throwParseErrorDMatrix("setMatrixValue", value);
1880
+ this.scale3dSelf(Number.parseFloat(args[0]), Number.parseFloat(args[1]), Number.parseFloat(args[2]));
1881
+ break;
1882
+ }
1883
+ case "rotate": {
1884
+ if (args.length !== 1)
1885
+ throwParseErrorDMatrix("setMatrixValue", value);
1886
+ this.rotateSelf(this.#parseAngle(args[0]));
1887
+ break;
1888
+ }
1889
+ case "rotateX": {
1890
+ if (args.length !== 1)
1891
+ throwParseErrorDMatrix("setMatrixValue", value);
1892
+ this.rotateSelf(this.#parseAngle(args[0]), 0, 0);
1893
+ break;
1894
+ }
1895
+ case "rotateY": {
1896
+ if (args.length !== 1)
1897
+ throwParseErrorDMatrix("setMatrixValue", value);
1898
+ this.rotateSelf(0, this.#parseAngle(args[0]), 0);
1899
+ break;
1900
+ }
1901
+ case "rotateZ": {
1902
+ if (args.length !== 1)
1903
+ throwParseErrorDMatrix("setMatrixValue", value);
1904
+ this.rotateSelf(0, 0, this.#parseAngle(args[0]));
1905
+ break;
1906
+ }
1907
+ case "rotate3d": {
1908
+ if (args.length !== 4)
1909
+ throwParseErrorDMatrix("setMatrixValue", value);
1910
+ this.rotateAxisAngleSelf(Number.parseFloat(args[0]), Number.parseFloat(args[1]), Number.parseFloat(args[2]), this.#parseAngle(args[3]));
1911
+ break;
1912
+ }
1913
+ case "skew": {
1914
+ if (args.length < 1 || args.length > 2)
1915
+ throwParseErrorDMatrix("setMatrixValue", value);
1916
+ this.skewXSelf(this.#parseAngle(args[0]));
1917
+ if (args.length === 2)
1918
+ this.skewYSelf(this.#parseAngle(args[1]));
1919
+ break;
1920
+ }
1921
+ case "skewX": {
1922
+ if (args.length !== 1)
1923
+ throwParseErrorDMatrix("setMatrixValue", value);
1924
+ this.skewXSelf(this.#parseAngle(args[0]));
1925
+ break;
1926
+ }
1927
+ case "skewY": {
1928
+ if (args.length !== 1)
1929
+ throwParseErrorDMatrix("setMatrixValue", value);
1930
+ this.skewYSelf(this.#parseAngle(args[0]));
1931
+ break;
1932
+ }
1933
+ case "perspective": {
1934
+ if (args.length !== 1)
1935
+ throwParseErrorDMatrix("setMatrixValue", value);
1936
+ const d = this.#parseLength(args[0]);
1937
+ if (d === 0 || !d) {
1938
+ throwParseErrorDMatrix("setMatrixValue", value);
1939
+ return;
1940
+ }
1941
+ this.#internal.set(multipliedMatrices(this.#internal, new Float64Array([
1942
+ 1,
1943
+ 0,
1944
+ 0,
1945
+ 0,
1946
+ 0,
1947
+ 1,
1948
+ 0,
1949
+ 0,
1950
+ 0,
1951
+ 0,
1952
+ 1,
1953
+ -1 / d,
1954
+ 0,
1955
+ 0,
1956
+ 0,
1957
+ 1
1958
+ ])));
1959
+ this.is2D = false;
1960
+ break;
1961
+ }
1962
+ default:
1963
+ throwParseErrorDMatrix("setMatrixValue", value);
1964
+ }
1965
+ }
1966
+ return this;
1967
+ }
1968
+ toString() {
1969
+ 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})`;
1970
+ }
1971
+ constructor(...args) {
1972
+ if (!isMatrixArray(args[0]))
1973
+ throw new SyntaxError(`Failed to construct 'DOMMatrix': Failed to parse '${args[0]}'.`);
1974
+ if (args[0]) {
1975
+ const len = args[0].length;
1976
+ if (len != 6 && len != 16)
1977
+ throw new TypeError(`Failed to construct 'DOMMatrix': The sequence must contain 6 elements for a 2D matrix or 16 elements for a 3D matrix.`);
1978
+ let matrix = args[0];
1979
+ if (len == 6) {
1980
+ this.a = matrix[0];
1981
+ this.b = matrix[1];
1982
+ this.c = matrix[2];
1983
+ this.d = matrix[3];
1984
+ this.e = matrix[4];
1985
+ this.f = matrix[5];
1986
+ } else {
1987
+ let index = 0;
1988
+ for (const item of matrix) {
1989
+ this.#internal[index] = item;
1990
+ index++;
1991
+ }
1992
+ }
1993
+ this.#isIdentity = matrix[0] == 1 && matrix[1] == 0 && matrix[2] == 0 && matrix[3] == 0 && matrix[4] == 0 && matrix[5] == 1 && matrix[6] == 0 && matrix[7] == 0 && matrix[8] == 0 && matrix[9] == 0 && matrix[10] == 1 && matrix[11] == 0 && matrix[12] == 0 && matrix[13] == 0 && matrix[14] == 0 && matrix[15] == 1;
1994
+ }
1995
+ }
1996
+ get ptr() {
1997
+ return ptr2(this.#internal);
1998
+ }
1999
+ static fromFloat32Array(arr) {
2000
+ if (arr instanceof Float32Array)
2001
+ return new DOMMatrix(arr);
2002
+ throw new TypeError(`Failed to execute 'fromFloat32Array' on 'DOMMatrix': parameter 1 is not of type 'Float32Array'.`);
2003
+ }
2004
+ static fromFloat64Array(arr) {
2005
+ if (arr instanceof Float64Array)
2006
+ return new DOMMatrix(arr);
2007
+ throw new TypeError(`Failed to execute 'fromFloat64Array' on 'DOMMatrix': parameter 1 is not of type 'Float64Array'.`);
2008
+ }
2009
+ static fromMatrix(arr) {
2010
+ if (!arr)
2011
+ return new DOMMatrix;
2012
+ if (arr.a != arr.m11 || arr.b != arr.m21 || arr.c != arr.m12 || arr.d != arr.m22 || arr.e != arr.m41 || arr.f != arr.m42)
2013
+ throw new TypeError(`Failed to execute 'fromMatrix' on 'DOMMatrix': Property mismatch on matrix initialization.`);
2014
+ let a = arr.a ?? undefined;
2015
+ let b = arr.b ?? undefined;
2016
+ let c = arr.c ?? undefined;
2017
+ let d = arr.d ?? undefined;
2018
+ let e = arr.e ?? undefined;
2019
+ let f = arr.f ?? undefined;
2020
+ let m11 = arr.m11 ?? a ?? 1;
2021
+ let m12 = arr.m12 ?? b ?? 0;
2022
+ let m13 = arr.m13 ?? 0;
2023
+ let m14 = arr.m14 ?? 0;
2024
+ let m21 = arr.m21 ?? c ?? 0;
2025
+ let m22 = arr.m22 ?? d ?? 1;
2026
+ let m23 = arr.m23 ?? 0;
2027
+ let m24 = arr.m24 ?? 0;
2028
+ let m31 = arr.m31 ?? 0;
2029
+ let m32 = arr.m32 ?? 0;
2030
+ let m33 = arr.m33 ?? 1;
2031
+ let m34 = arr.m34 ?? 0;
2032
+ let m41 = arr.m41 ?? e ?? 0;
2033
+ let m42 = arr.m42 ?? f ?? 0;
2034
+ let m43 = arr.m43 ?? 0;
2035
+ let m44 = arr.m44 ?? 1;
2036
+ return new DOMMatrix([m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44]);
2037
+ }
2038
+ }
2039
+ var proto2 = DOMMatrix.prototype;
2040
+ for (const key of Object.getOwnPropertyNames(proto2)) {
2041
+ const desc = Object.getOwnPropertyDescriptor(proto2, key);
2042
+ if (key == "constructor") {
2043
+ desc && (desc.value.toString = () => {
2044
+ return `function ${proto2.constructor.name}() { [native code] }`;
2045
+ });
2046
+ continue;
2047
+ }
2048
+ if (typeof desc?.value === "function") {
2049
+ desc.value.toString = () => `function ${key}() { [native code] }`;
2050
+ }
2051
+ }
2052
+
2053
+ // BunCanvas/internal/colorCheck.ts
2054
+ var NAMED_COLORS = new Set([
2055
+ "aliceblue",
2056
+ "antiquewhite",
2057
+ "aqua",
2058
+ "aquamarine",
2059
+ "azure",
2060
+ "beige",
2061
+ "bisque",
2062
+ "black",
2063
+ "blanchedalmond",
2064
+ "blue",
2065
+ "blueviolet",
2066
+ "brown",
2067
+ "burlywood",
2068
+ "cadetblue",
2069
+ "chartreuse",
2070
+ "chocolate",
2071
+ "coral",
2072
+ "cornflowerblue",
2073
+ "cornsilk",
2074
+ "crimson",
2075
+ "cyan",
2076
+ "darkblue",
2077
+ "darkcyan",
2078
+ "darkgoldenrod",
2079
+ "darkgray",
2080
+ "darkgreen",
2081
+ "darkgrey",
2082
+ "darkkhaki",
2083
+ "darkmagenta",
2084
+ "darkolivegreen",
2085
+ "darkorange",
2086
+ "darkorchid",
2087
+ "darkred",
2088
+ "darksalmon",
2089
+ "darkseagreen",
2090
+ "darkslateblue",
2091
+ "darkslategray",
2092
+ "darkslategrey",
2093
+ "darkturquoise",
2094
+ "darkviolet",
2095
+ "deeppink",
2096
+ "deepskyblue",
2097
+ "dimgray",
2098
+ "dimgrey",
2099
+ "dodgerblue",
2100
+ "firebrick",
2101
+ "floralwhite",
2102
+ "forestgreen",
2103
+ "fuchsia",
2104
+ "gainsboro",
2105
+ "ghostwhite",
2106
+ "gold",
2107
+ "goldenrod",
2108
+ "gray",
2109
+ "green",
2110
+ "greenyellow",
2111
+ "grey",
2112
+ "honeydew",
2113
+ "hotpink",
2114
+ "indianred",
2115
+ "indigo",
2116
+ "ivory",
2117
+ "khaki",
2118
+ "lavender",
2119
+ "lavenderblush",
2120
+ "lawngreen",
2121
+ "lemonchiffon",
2122
+ "lightblue",
2123
+ "lightcoral",
2124
+ "lightcyan",
2125
+ "lightgoldenrodyellow",
2126
+ "lightgray",
2127
+ "lightgreen",
2128
+ "lightgrey",
2129
+ "lightpink",
2130
+ "lightsalmon",
2131
+ "lightseagreen",
2132
+ "lightskyblue",
2133
+ "lightslategray",
2134
+ "lightslategrey",
2135
+ "lightsteelblue",
2136
+ "lightyellow",
2137
+ "lime",
2138
+ "limegreen",
2139
+ "linen",
2140
+ "magenta",
2141
+ "maroon",
2142
+ "mediumaquamarine",
2143
+ "mediumblue",
2144
+ "mediumorchid",
2145
+ "mediumpurple",
2146
+ "mediumseagreen",
2147
+ "mediumslateblue",
2148
+ "mediumspringgreen",
2149
+ "mediumturquoise",
2150
+ "mediumvioletred",
2151
+ "midnightblue",
2152
+ "mintcream",
2153
+ "mistyrose",
2154
+ "moccasin",
2155
+ "navajowhite",
2156
+ "navy",
2157
+ "oldlace",
2158
+ "olive",
2159
+ "olivedrab",
2160
+ "orange",
2161
+ "orangered",
2162
+ "orchid",
2163
+ "palegoldenrod",
2164
+ "palegreen",
2165
+ "paleturquoise",
2166
+ "palevioletred",
2167
+ "papayawhip",
2168
+ "peachpuff",
2169
+ "peru",
2170
+ "pink",
2171
+ "plum",
2172
+ "powderblue",
2173
+ "purple",
2174
+ "rebeccapurple",
2175
+ "red",
2176
+ "rosybrown",
2177
+ "royalblue",
2178
+ "saddlebrown",
2179
+ "salmon",
2180
+ "sandybrown",
2181
+ "seagreen",
2182
+ "seashell",
2183
+ "sienna",
2184
+ "silver",
2185
+ "skyblue",
2186
+ "slateblue",
2187
+ "slategray",
2188
+ "slategrey",
2189
+ "snow",
2190
+ "springgreen",
2191
+ "steelblue",
2192
+ "tan",
2193
+ "teal",
2194
+ "thistle",
2195
+ "tomato",
2196
+ "transparent",
2197
+ "turquoise",
2198
+ "violet",
2199
+ "wheat",
2200
+ "white",
2201
+ "whitesmoke",
2202
+ "yellow",
2203
+ "yellowgreen"
2204
+ ]);
2205
+ var HEX_REGEX = /^#(?:[0-9a-fA-F]{3,4}){1,2}$/;
2206
+ var RGB_REGEX = /^rgba?\(\s*(?:\d+(?:\.\d+)?%?|\.\d+%?)\s*[, ]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?)\s*[, ]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?)(?:\s*[,/]\s*(?:\d+(?:\.\d+)?%?|\.\d+%?))?\s*\)$/i;
2207
+ var HSL_HWB_REGEX = /^(?: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;
2208
+ function isValidColor(str) {
2209
+ if (typeof str !== "string")
2210
+ return false;
2211
+ const normalized = str.trim().toLowerCase();
2212
+ if (normalized === "")
2213
+ return false;
2214
+ if (NAMED_COLORS.has(normalized))
2215
+ return true;
2216
+ if (normalized.startsWith("#"))
2217
+ return HEX_REGEX.test(normalized);
2218
+ return RGB_REGEX.test(normalized) || HSL_HWB_REGEX.test(normalized);
2219
+ }
2220
+
2221
+ // BunCanvas/src/Canvas.ts
2222
+ var ptrs3 = new WeakMap;
2223
+ var canvasFinalizationRegistry = new FinalizationRegistry((ptr) => {
2224
+ lib.symbols.canvas_destroy(ptr);
2225
+ console.log("destroyed Canvas!");
2226
+ });
2227
+ class CanvasGradient {
2228
+ type;
2229
+ points = new Float32Array(6);
2230
+ offsets = [];
2231
+ colors = [];
2232
+ constructor(...args) {
2233
+ this.type = args[0];
2234
+ switch (this.type) {
2235
+ case 0 /* Linear */: {
2236
+ this.points[0] = args[1];
2237
+ this.points[1] = args[2];
2238
+ this.points[2] = args[3];
2239
+ this.points[3] = args[4];
2240
+ break;
2241
+ }
2242
+ case 1 /* Radial */: {
2243
+ this.points[0] = args[1];
2244
+ this.points[1] = args[2];
2245
+ this.points[2] = args[3];
2246
+ this.points[3] = args[4];
2247
+ this.points[4] = args[5];
2248
+ this.points[5] = args[6];
2249
+ break;
2250
+ }
2251
+ case 2 /* Conic */: {
2252
+ this.points[0] = args[1];
2253
+ this.points[1] = args[2];
2254
+ this.points[2] = args[3];
2255
+ break;
2256
+ }
2257
+ }
2258
+ }
2259
+ addColorStop(offset, color) {
2260
+ if (offset < 0 || offset > 1)
2261
+ throw new RangeError(`Failed to execute 'addColorStop' on 'CanvasGradient': The provided value (${offset}) is outside the range (0.0, 1.0).`);
2262
+ if (!isValidColor(color))
2263
+ throw new SyntaxError(`Failed to execute 'addColorStop' on 'CanvasGradient': The value provided ('${color}') could not be parsed as a color.`);
2264
+ const idx = this.offsets.findIndex((o) => o > offset);
2265
+ const insertIdx = idx === -1 ? this.offsets.length : idx;
2266
+ this.offsets.splice(insertIdx, 0, offset);
2267
+ this.colors.splice(insertIdx, 0, encodeCString(color));
2268
+ }
2269
+ }
2270
+
2271
+ class Render2DState {
2272
+ lineWidth = 0;
2273
+ globalAlpha = 1;
2274
+ imageSmoothingQuality = "low";
2275
+ imageSmoothingEnabled = true;
2276
+ fillStyle = "#000000";
2277
+ strokeStyle = "#000000";
2278
+ compositeOperation = "source-over";
2279
+ filter = "none";
2280
+ fontCss = "10px sans-serif";
2281
+ textBaseline = "alphabetic";
2282
+ textAlign = "start";
2283
+ lineDash = [];
2284
+ lineDashOffset = 0;
2285
+ lineJoin = "miter";
2286
+ constructor(other) {
2287
+ if (other instanceof Render2DState) {
2288
+ this.lineWidth = other.lineWidth;
2289
+ this.globalAlpha = other.globalAlpha;
2290
+ this.imageSmoothingQuality = other.imageSmoothingQuality;
2291
+ this.imageSmoothingEnabled = other.imageSmoothingEnabled;
2292
+ this.fillStyle = other.fillStyle;
2293
+ this.strokeStyle = other.strokeStyle;
2294
+ this.compositeOperation = other.compositeOperation;
2295
+ this.filter = other.filter;
2296
+ this.fontCss = other.fontCss;
2297
+ this.textBaseline = other.textBaseline;
2298
+ this.textAlign = other.textAlign;
2299
+ this.lineDash = other.lineDash;
2300
+ this.lineDashOffset = other.lineDashOffset;
2301
+ this.lineJoin = other.lineJoin;
2302
+ }
2303
+ }
2304
+ copyFrom(other) {
2305
+ if (other instanceof Render2DState) {
2306
+ this.lineWidth = other.lineWidth;
2307
+ this.globalAlpha = other.globalAlpha;
2308
+ this.imageSmoothingQuality = other.imageSmoothingQuality;
2309
+ this.imageSmoothingEnabled = other.imageSmoothingEnabled;
2310
+ this.fillStyle = other.fillStyle;
2311
+ this.strokeStyle = other.strokeStyle;
2312
+ this.compositeOperation = other.compositeOperation;
2313
+ this.filter = other.filter;
2314
+ this.fontCss = other.fontCss;
2315
+ this.textBaseline = other.textBaseline;
2316
+ this.textAlign = other.textAlign;
2317
+ this.lineDash = other.lineDash;
2318
+ this.lineDashOffset = other.lineDashOffset;
2319
+ this.lineJoin = other.lineJoin;
2320
+ }
2321
+ }
2322
+ }
2323
+
2324
+ class CanvasRenderingContext2D {
2325
+ #currentState = new Render2DState;
2326
+ #savedState = new Render2DState;
2327
+ #owner;
2328
+ #reset() {
2329
+ this.#currentState = new Render2DState;
2330
+ }
2331
+ #setStyleGradient(style, isStroke) {
2332
+ const count = style.colors.length;
2333
+ const ptrArray = new BigUint64Array(count);
2334
+ for (let i = 0;i < count; i++) {
2335
+ ptrArray[i] = BigInt(ptr3(style.colors[i]));
2336
+ }
2337
+ const offsetBuffer = new Float32Array(style.offsets);
2338
+ const nativeFn = isStroke ? lib.symbols.canvas_set_stroke_style_gradient : lib.symbols.canvas_set_fill_style_gradient;
2339
+ return nativeFn(ptrs3.get(this), style.type, ptr3(style.points), count, ptr3(ptrArray), ptr3(offsetBuffer));
2340
+ }
2341
+ get canvas() {
2342
+ return this.#owner;
2343
+ }
2344
+ set font(css) {
2345
+ this.#currentState.fontCss = css.trim().toLowerCase();
2346
+ lib.symbols.canvas_set_font(ptrs3.get(this), encoder.encode(`${this.#currentState.fontCss}\x00`));
2347
+ }
2348
+ get font() {
2349
+ return this.#currentState.fontCss;
2350
+ }
2351
+ set fillStyle(style) {
2352
+ if (style == this.#currentState.fillStyle)
2353
+ return;
2354
+ let res = false;
2355
+ if (typeof style === "string") {
2356
+ res = lib.symbols.canvas_set_fill_style(ptrs3.get(this), encodeCString(style));
2357
+ } else if (style instanceof CanvasGradient) {
2358
+ res = this.#setStyleGradient(style, false);
2359
+ }
2360
+ if (res)
2361
+ this.#currentState.fillStyle = style;
2362
+ }
2363
+ get fillStyle() {
2364
+ return this.#currentState.fillStyle;
2365
+ }
2366
+ set strokeStyle(style) {
2367
+ if (style == this.#currentState.strokeStyle)
2368
+ return;
2369
+ let res = false;
2370
+ if (typeof style === "string") {
2371
+ res = lib.symbols.canvas_set_stroke_style(ptrs3.get(this), encoder.encode(`${style.trim()}\x00`));
2372
+ } else if (style instanceof CanvasGradient) {
2373
+ res = this.#setStyleGradient(style, true);
2374
+ }
2375
+ if (res)
2376
+ this.#currentState.strokeStyle = style;
2377
+ }
2378
+ get strokeStyle() {
2379
+ return this.#currentState.strokeStyle;
2380
+ }
2381
+ set lineWidth(width) {
2382
+ let w = width < 1 ? 1 : width;
2383
+ lib.symbols.canvas_set_stroke_width(ptrs3.get(this), w);
2384
+ this.#currentState.lineWidth = w;
2385
+ }
2386
+ get lineWidth() {
2387
+ return this.#currentState.lineWidth;
2388
+ }
2389
+ set globalAlpha(a) {
2390
+ this.#currentState.globalAlpha = lib.symbols.canvas_set_global_alpha(ptrs3.get(this), a);
2391
+ }
2392
+ get globalAlpha() {
2393
+ return this.#currentState.globalAlpha;
2394
+ }
2395
+ set imageSmoothingQuality(v) {
2396
+ let res = false;
2397
+ switch (v) {
2398
+ case "low": {
2399
+ res = lib.symbols.canvas_set_image_smoothing_quality(ptrs3.get(this), 1);
2400
+ break;
2401
+ }
2402
+ case "medium": {
2403
+ res = lib.symbols.canvas_set_image_smoothing_quality(ptrs3.get(this), 2);
2404
+ break;
2405
+ }
2406
+ case "high": {
2407
+ res = lib.symbols.canvas_set_image_smoothing_quality(ptrs3.get(this), 3);
2408
+ break;
2409
+ }
2410
+ }
2411
+ if (res) {
2412
+ this.#currentState.imageSmoothingQuality = v;
2413
+ }
2414
+ }
2415
+ get imageSmoothingQuality() {
2416
+ return this.#currentState.imageSmoothingQuality;
2417
+ }
2418
+ set imageSmoothingEnabled(v) {
2419
+ this.#currentState.imageSmoothingEnabled = lib.symbols.canvas_set_image_smoothing_enabled(ptrs3.get(this), v);
2420
+ }
2421
+ get imageSmoothingEnabled() {
2422
+ return this.#currentState.imageSmoothingEnabled;
2423
+ }
2424
+ set filter(v) {
2425
+ if (lib.symbols.canvas_set_filter(ptrs3.get(this), encoder.encode(`${v}\x00`))) {
2426
+ this.#currentState.filter = v;
2427
+ }
2428
+ }
2429
+ get filter() {
2430
+ return this.#currentState.filter;
2431
+ }
2432
+ set globalCompositeOperation(operation) {
2433
+ if (lib.symbols.canvas_set_composite_operation(ptrs3.get(this), encoder.encode(`${operation}\x00`)) == true)
2434
+ this.#currentState.compositeOperation = operation;
2435
+ }
2436
+ get globalCompositeOperation() {
2437
+ return this.#currentState.compositeOperation;
2438
+ }
2439
+ fillRect(x, y, w, h) {
2440
+ lib.symbols.canvas_fill_rect(ptrs3.get(this), x, y, w, h);
2441
+ }
2442
+ strokeRect(x, y, w, h) {
2443
+ lib.symbols.canvas_stroke_rect(ptrs3.get(this), x, y, w, h);
2444
+ }
2445
+ clearRect(x, y, w, h) {
2446
+ lib.symbols.canvas_clear_rect(ptrs3.get(this), x, y, w, h);
2447
+ }
2448
+ fillText(text, x, y, maxWidth = -1) {
2449
+ lib.symbols.canvas_fill_text(ptrs3.get(this), encoder.encode(`${text}\x00`), x, y, maxWidth);
2450
+ }
2451
+ strokeText(text, x, y, maxWidth = -1) {
2452
+ lib.symbols.canvas_stroke_text(ptrs3.get(this), encoder.encode(`${text}\x00`), x, y, maxWidth);
2453
+ }
2454
+ beginPath() {
2455
+ lib.symbols.canvas_path_begin(ptrs3.get(this));
2456
+ }
2457
+ moveTo(x, y) {
2458
+ lib.symbols.canvas_path_move_to(ptrs3.get(this), x, y);
2459
+ }
2460
+ lineTo(x, y) {
2461
+ lib.symbols.canvas_path_line_to(ptrs3.get(this), x, y);
2462
+ }
2463
+ arc(x, y, radius, startAngle, endAngle) {
2464
+ lib.symbols.canvas_path_arc(ptrs3.get(this), x, y, radius, startAngle, endAngle);
2465
+ }
2466
+ ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise = false) {
2467
+ lib.symbols.canvas_path_ellipse(ptrs3.get(this), x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
2468
+ }
2469
+ arcTo(x1, y1, x2, y2, radius) {
2470
+ lib.symbols.canvas_path_arc_to(ptrs3.get(this), x1, y1, x2, y2, radius);
2471
+ }
2472
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
2473
+ lib.symbols.canvas_path_bezier_to(ptrs3.get(this), cp1x, cp1y, cp2x, cp2y, x, y);
2474
+ }
2475
+ quadraticCurveTo(cpx, cpy, x, y) {
2476
+ lib.symbols.canvas_path_quad_to(ptrs3.get(this), cpx, cpy, x, y);
2477
+ }
2478
+ closePath() {
2479
+ lib.symbols.canvas_path_close(ptrs3.get(this));
2480
+ }
2481
+ rect(x, y, width, height) {
2482
+ lib.symbols.canvas_path_rect(ptrs3.get(this), x, y, width, height);
2483
+ }
2484
+ roundRect(x, y, width, height, radii) {
2485
+ if (radii.constructor.name.toLowerCase().includes("array")) {
2486
+ const arr = new Float32Array(radii);
2487
+ if (arr.some(Number.isNaN))
2488
+ return;
2489
+ const len = arr.length;
2490
+ lib.symbols.canvas_path_roundrect_array(ptrs3.get(this), x, y, width, height, ptr3(arr), len);
2491
+ return;
2492
+ } else {
2493
+ lib.symbols.canvas_path_roundrect(ptrs3.get(this), x, y, width, height, radii);
2494
+ }
2495
+ }
2496
+ fill(path) {
2497
+ lib.symbols.canvas_path_fill(ptrs3.get(this), path ? path.ptr : undefined);
2498
+ }
2499
+ stroke(path) {
2500
+ lib.symbols.canvas_path_stroke(ptrs3.get(this), path ? path.ptr : undefined);
2501
+ }
2502
+ set shadowBlur(blur) {
2503
+ lib.symbols.canvas_set_shadow_blur(ptrs3.get(this), blur);
2504
+ }
2505
+ set shadowColor(col) {
2506
+ lib.symbols.canvas_set_shadow_color(ptrs3.get(this), encoder.encode(`${col}\x00`));
2507
+ }
2508
+ set shadowOffsetX(x) {
2509
+ lib.symbols.canvas_set_shadow_offsetX(ptrs3.get(this), x);
2510
+ }
2511
+ set shadowOffsetY(y) {
2512
+ lib.symbols.canvas_set_shadow_offsetY(ptrs3.get(this), y);
2513
+ }
2514
+ set lineJoin(joinType) {
2515
+ let res = false;
2516
+ switch (joinType) {
2517
+ case "round": {
2518
+ res = lib.symbols.canvas_set_line_join(ptrs3.get(this), 1);
2519
+ break;
2520
+ }
2521
+ case "bevel": {
2522
+ res = lib.symbols.canvas_set_line_join(ptrs3.get(this), 2);
2523
+ break;
2524
+ }
2525
+ case "miter": {
2526
+ res = lib.symbols.canvas_set_line_join(ptrs3.get(this), 3);
2527
+ break;
2528
+ }
2529
+ }
2530
+ if (res) {
2531
+ this.#currentState.lineJoin = joinType;
2532
+ }
2533
+ }
2534
+ get lineJoin() {
2535
+ return this.#currentState.lineJoin;
2536
+ }
2537
+ drawImage(img, ...args) {
2538
+ let _arr = args.length == 2 ? [...args, img.width, img.height] : args;
2539
+ const arr = new Float32Array(_arr);
2540
+ const len = arr.length;
2541
+ if (img instanceof Image) {
2542
+ lib.symbols.canvas_draw_image_imageType(ptrs3.get(this), img.ptr, ptr3(arr), len);
2543
+ return;
2544
+ }
2545
+ if (img instanceof Canvas) {
2546
+ lib.symbols.canvas_draw_image_canvasType(ptrs3.get(this), ptrs3.get(img), ptr3(arr), len);
2547
+ return;
2548
+ }
2549
+ throw new TypeError("Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(Image or Canvas)'.");
2550
+ }
2551
+ getImageData(x, y, w, h) {
2552
+ const arr = new Uint8Array(w * h * 4);
2553
+ lib.symbols.canvas_get_image_data(ptrs3.get(this), x, y, w, h, ptr3(arr));
2554
+ return new ImageData(w, h, arr);
2555
+ }
2556
+ putImageData(data, dx, dy, dirtyX = 0, dirtyY = 0, dirtyWidth = data.width, dirtyHeight = data.height) {
2557
+ if (!(data instanceof ImageData)) {
2558
+ throw new TypeError("Failed to execute 'putImageData' on 'CanvasRenderingContext2D': " + "parameter 1 is not of type 'ImageData'");
2559
+ }
2560
+ lib.symbols.canvas_put_image_data(ptrs3.get(this), dx, dy, data.width, data.height, dirtyX, dirtyY, dirtyWidth, dirtyHeight, ptr3(data.data));
2561
+ }
2562
+ save() {
2563
+ this.#savedState?.copyFrom(this.#currentState);
2564
+ lib.symbols.canvas_save(ptrs3.get(this));
2565
+ }
2566
+ restore() {
2567
+ if (!this.#savedState)
2568
+ return;
2569
+ this.#currentState?.copyFrom(this.#savedState);
2570
+ lib.symbols.canvas_restore(ptrs3.get(this));
2571
+ }
2572
+ translate(x, y) {
2573
+ lib.symbols.canvas_translate(ptrs3.get(this), x, y);
2574
+ }
2575
+ rotate(deg) {
2576
+ lib.symbols.canvas_rotate(ptrs3.get(this), deg);
2577
+ }
2578
+ createConicGradient(...args) {
2579
+ if (args.length < 3)
2580
+ throw new TypeError(`Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': 3 arguments required, but only ${args.length} present.`);
2581
+ return new CanvasGradient(2 /* Conic */, ...args);
2582
+ }
2583
+ createLinearGradient(...args) {
2584
+ if (args.length < 4)
2585
+ throw new TypeError(`Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': 4 arguments required, but only ${args.length} present.`);
2586
+ return new CanvasGradient(0 /* Linear */, ...args);
2587
+ }
2588
+ createRadialGradient(...args) {
2589
+ if (args.length < 6)
2590
+ throw new TypeError(`Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': 6 arguments required, but only ${args.length} present.`);
2591
+ return new CanvasGradient(1 /* Radial */, ...args);
2592
+ }
2593
+ getTransform() {
2594
+ let arr = new Float32Array(16);
2595
+ lib.symbols.canvas_get_transform(ptrs3.get(this), ptr3(arr));
2596
+ return new DOMMatrix(arr);
2597
+ }
2598
+ setTransform(...args) {
2599
+ if (args[0] instanceof DOMMatrix)
2600
+ lib.symbols.canvas_set_transform(ptrs3.get(this), args[0].ptr);
2601
+ if (args.length == 6) {
2602
+ const mtx = new DOMMatrix([args[0], args[1], args[2], args[3], args[4], args[5]]);
2603
+ lib.symbols.canvas_set_transform(ptrs3.get(this), mtx.ptr);
2604
+ }
2605
+ if (args.length == 16)
2606
+ lib.symbols.canvas_set_transform(ptrs3.get(this), new DOMMatrix([args[0], args[1], args[2], args[3], args[4], args[5], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15]]).ptr);
2607
+ }
2608
+ transform(a, b, c, d, e, f) {
2609
+ const tf = this.getTransform();
2610
+ const mul = new DOMMatrix([a, b, c, d, e, f]);
2611
+ tf.multiplySelf(mul);
2612
+ this.setTransform(tf);
2613
+ }
2614
+ resetTransform() {
2615
+ lib.symbols.canvas_reset_transform(ptrs3.get(this));
2616
+ }
2617
+ setLineDash(lines) {
2618
+ if (lines.constructor.name.toLowerCase().includes("array")) {
2619
+ let _a;
2620
+ if (lines.length & 1) {
2621
+ _a = lines.concat(Array.from(lines));
2622
+ } else {
2623
+ _a = lines;
2624
+ }
2625
+ const arr = new Float32Array(_a);
2626
+ if (arr.some(Number.isNaN))
2627
+ return;
2628
+ lib.symbols.canvas_set_line_dash(ptrs3.get(this), ptr3(arr), arr.length, this.#currentState.lineDashOffset);
2629
+ this.#currentState.lineDash = _a;
2630
+ return;
2631
+ }
2632
+ throw new TypeError(`Failed to execute 'setLineDash' on 'CanvasRenderingContext2D': The provided value cannot be converted to a sequence.`);
2633
+ }
2634
+ getLineDash() {
2635
+ return this.#currentState.lineDash;
2636
+ }
2637
+ clip() {
2638
+ lib.symbols.canvas_path_clip(ptrs3.get(this));
2639
+ }
2640
+ set lineDashOffset(v) {
2641
+ if (this.#currentState.lineDash.length <= 0) {
2642
+ this.#currentState.lineDashOffset = 0;
2643
+ return;
2644
+ }
2645
+ const arr = new Float32Array(this.#currentState.lineDash);
2646
+ lib.symbols.canvas_set_line_dash(ptrs3.get(this), ptr3(arr), arr.length, v);
2647
+ this.#currentState.lineDashOffset = v;
2648
+ }
2649
+ set textBaseline(baseline) {
2650
+ let bl = -1;
2651
+ switch (baseline) {
2652
+ case "top":
2653
+ bl = 0;
2654
+ break;
2655
+ case "hanging":
2656
+ bl = 1;
2657
+ break;
2658
+ case "middle":
2659
+ bl = 2;
2660
+ break;
2661
+ case "alphabetic":
2662
+ bl = 3;
2663
+ break;
2664
+ case "ideographic":
2665
+ bl = 4;
2666
+ break;
2667
+ case "bottom":
2668
+ bl = 5;
2669
+ break;
2670
+ }
2671
+ if (bl != -1) {
2672
+ lib.symbols.canvas_set_text_baseline(ptrs3.get(this), bl);
2673
+ }
2674
+ }
2675
+ set textAlign(alignment) {
2676
+ let al = -1;
2677
+ switch (alignment) {
2678
+ case "left":
2679
+ al = 0;
2680
+ break;
2681
+ case "right":
2682
+ al = 1;
2683
+ break;
2684
+ case "center":
2685
+ al = 2;
2686
+ break;
2687
+ case "start":
2688
+ al = 3;
2689
+ break;
2690
+ case "end":
2691
+ al = 4;
2692
+ break;
2693
+ }
2694
+ if (al != -1) {
2695
+ lib.symbols.canvas_set_text_align(ptrs3.get(this), al);
2696
+ }
2697
+ }
2698
+ measureText(text) {
2699
+ const pArr = new Float32Array(12);
2700
+ lib.symbols.canvas_measure_text(ptrs3.get(this), encoder.encode(`${text}\x00`), ptr3(pArr));
2701
+ return new TextMetrics(pArr[0], pArr[1], pArr[2], pArr[3], pArr[4], pArr[5], pArr[6], pArr[7], pArr[8], pArr[9], pArr[10], pArr[11]);
2702
+ }
2703
+ constructor(iptr, cnv, args) {
2704
+ const { desynchronized = false, alpha = true } = args ?? {};
2705
+ const cb = new JSCallback(this.#reset.bind(this), {
2706
+ args: [],
2707
+ returns: "void"
2708
+ });
2709
+ const renderContextPtr = lib.symbols.canvas_get_context2D(iptr, cb.ptr, desynchronized, alpha);
2710
+ this.#owner = cnv;
2711
+ ptrs3.set(this, renderContextPtr);
2712
+ }
2713
+ }
2714
+ {
2715
+ const proto = CanvasRenderingContext2D.prototype;
2716
+ for (const key of Object.getOwnPropertyNames(proto)) {
2717
+ const desc = Object.getOwnPropertyDescriptor(proto, key);
2718
+ if (key == "constructor") {
2719
+ desc && (desc.value.toString = () => {
2720
+ return `function ${proto.constructor.name}() { [native code] }`;
2721
+ });
2722
+ continue;
2723
+ }
2724
+ if (typeof desc?.value === "function") {
2725
+ desc.value.toString = () => `function ${key}() { [native code] }`;
2726
+ }
2727
+ }
2728
+ }
2729
+
2730
+ class Canvas {
2731
+ #dim = new Float64Array(2);
2732
+ #rCapture = {
2733
+ cb: () => {}
2734
+ };
2735
+ constructor(w = 1, h = 1, options) {
2736
+ this.#dim[0] = w;
2737
+ this.#dim[1] = h;
2738
+ const { gpu = true } = options ?? {};
2739
+ let ptr = lib.symbols.canvas_create(w, h, gpu);
2740
+ ptrs3.set(this, ptr);
2741
+ canvasFinalizationRegistry.register(this, ptr);
2742
+ }
2743
+ get _ptr() {
2744
+ return ptrs3.get(this);
2745
+ }
2746
+ set width(v) {
2747
+ this.#dim[0] = Number.parseInt(v);
2748
+ this.#rCapture.cb();
2749
+ lib.symbols.canvas_resize(ptrs3.get(this), this.#dim[0], this.#dim[1]);
2750
+ }
2751
+ set height(v) {
2752
+ this.#dim[1] = Number.parseInt(v);
2753
+ this.#rCapture.cb();
2754
+ lib.symbols.canvas_resize(ptrs3.get(this), this.#dim[0], this.#dim[1]);
2755
+ }
2756
+ get width() {
2757
+ return this.#dim[0];
2758
+ }
2759
+ get height() {
2760
+ return this.#dim[1];
2761
+ }
2762
+ getContext(contextType, args) {
2763
+ if (contextType == "2d") {
2764
+ return new CanvasRenderingContext2D(ptrs3.get(this), this, args);
2765
+ }
2766
+ }
2767
+ getBoundingClientRect() {
2768
+ return {
2769
+ x: 0,
2770
+ y: 0,
2771
+ width: this.#dim[0],
2772
+ height: this.#dim[1],
2773
+ top: 0,
2774
+ bottom: this.#dim[1],
2775
+ left: 0,
2776
+ right: this.#dim[0]
2777
+ };
2778
+ }
2779
+ }
2780
+ {
2781
+ const proto = Canvas.prototype;
2782
+ for (const key of Object.getOwnPropertyNames(proto)) {
2783
+ const desc = Object.getOwnPropertyDescriptor(proto, key);
2784
+ if (key == "constructor") {
2785
+ desc && (desc.value.toString = () => {
2786
+ return `function ${proto.constructor.name}() { [native code] }`;
2787
+ });
2788
+ continue;
2789
+ }
2790
+ if (typeof desc?.value === "function") {
2791
+ desc.value.toString = () => `function ${key}() { [native code] }`;
2792
+ }
2793
+ }
2794
+ }
2795
+ // BunCanvas/src/Path2D.ts
2796
+ import { ptr as ptr4 } from "bun:ffi";
2797
+ var p2dFinalizationRegistry = new FinalizationRegistry((ptr) => {
2798
+ lib.symbols.path2d_destroy(ptr);
2799
+ });
2800
+ var ptrs4 = new WeakMap;
2801
+
2802
+ class Path2D {
2803
+ constructor(path) {
2804
+ if (path && path instanceof Path2D) {
2805
+ let _ptr = lib.symbols.path2d_create_from_copy(path.ptr);
2806
+ ptrs4.set(this, _ptr);
2807
+ p2dFinalizationRegistry.register(this, _ptr);
2808
+ } else {
2809
+ let _ptr = lib.symbols.path2d_create();
2810
+ ptrs4.set(this, _ptr);
2811
+ p2dFinalizationRegistry.register(this, _ptr);
2812
+ }
2813
+ }
2814
+ moveTo(x, y) {
2815
+ lib.symbols.path2d_move_to(ptrs4.get(this), x, y);
2816
+ }
2817
+ lineTo(x, y) {
2818
+ lib.symbols.path2d_line_to(ptrs4.get(this), x, y);
2819
+ }
2820
+ arc(x, y, radius, startAngle, endAngle) {
2821
+ lib.symbols.path2d_arc(ptrs4.get(this), x, y, radius, startAngle, endAngle);
2822
+ }
2823
+ ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise = false) {
2824
+ lib.symbols.path2d_ellipse(ptrs4.get(this), x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
2825
+ }
2826
+ arcTo(x1, y1, x2, y2, radius) {
2827
+ lib.symbols.path2d_arc_to(ptrs4.get(this), x1, y1, x2, y2, radius);
2828
+ }
2829
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
2830
+ lib.symbols.path2d_bezier_to(ptrs4.get(this), cp1x, cp1y, cp2x, cp2y, x, y);
2831
+ }
2832
+ quadraticCurveTo(cpx, cpy, x, y) {
2833
+ lib.symbols.path2d_quad_to(ptrs4.get(this), cpx, cpy, x, y);
2834
+ }
2835
+ rect(x, y, width, height) {
2836
+ lib.symbols.path2d_rect(ptrs4.get(this), x, y, width, height);
2837
+ }
2838
+ roundRect(x, y, width, height, radii) {
2839
+ if (radii.constructor.name.toLowerCase().includes("array")) {
2840
+ const arr = new Float32Array(radii);
2841
+ if (arr.some(Number.isNaN))
2842
+ return;
2843
+ const len = arr.length;
2844
+ lib.symbols.path2d_roundrect_array(ptrs4.get(this), x, y, width, height, ptr4(arr), len);
2845
+ return;
2846
+ } else {
2847
+ lib.symbols.path2d_rect(ptrs4.get(this), x, y, width, height, radii);
2848
+ }
2849
+ }
2850
+ closePath() {
2851
+ lib.symbols.path2d_close(ptrs4.get(this));
2852
+ }
2853
+ get ptr() {
2854
+ return ptrs4.get(this);
2855
+ }
2856
+ }
2857
+ var proto3 = Path2D.prototype;
2858
+ for (const key of Object.getOwnPropertyNames(proto3)) {
2859
+ const desc = Object.getOwnPropertyDescriptor(proto3, key);
2860
+ if (key == "constructor") {
2861
+ desc && (desc.value.toString = () => {
2862
+ return `function ${proto3.constructor.name}() { [native code] }`;
2863
+ });
2864
+ continue;
2865
+ }
2866
+ if (typeof desc?.value === "function") {
2867
+ desc.value.toString = () => `function ${key}() { [native code] }`;
2868
+ }
2869
+ }
2870
+ // BunCanvas/src/Window.ts
2871
+ import { dlopen as dlopen2, toArrayBuffer } from "bun:ffi";
2872
+
2873
+ // BunCanvas/internal/WindowThread.js
2874
+ var WindowThread_default = `import { dlopen, FFIType, JSCallback } from "bun:ffi";
3
2875
 
4
2876
  const MessagePost = new JSCallback((instruction)=>{
5
2877
  self.postMessage(instruction);
@@ -23,4 +2895,480 @@ self.onmessage = (msg)=>{
23
2895
  self.postMessage(2)
24
2896
  }
25
2897
 
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 Tt=!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?.();Tt=!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 C=0;C<k;C++)G[C](x)}m=!1})}this.#_()}}else{let h=$t(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 Ot=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,Ot as requestAnimationFrame};
2898
+ `;
2899
+
2900
+ // BunCanvas/src/Window.ts
2901
+ var requestedFrames = [];
2902
+ var render_thread;
2903
+ lib.symbols.glfw_init();
2904
+ if (process.platform !== "darwin") {
2905
+ render_thread = new Worker(URL.createObjectURL(new Blob([WindowThread_default], { type: "application/javascript" })), { ref: false });
2906
+ }
2907
+ lib.symbols.canvas_init_gpu_context();
2908
+ var windowWasCreated = false;
2909
+
2910
+ class Window {
2911
+ #rEvts = new Map;
2912
+ #mMoveEvts = new Map;
2913
+ #mDownEvts = new Map;
2914
+ #mMUpEvts = new Map;
2915
+ #mWheelEvts = new Map;
2916
+ #mClickEvts = new Map;
2917
+ #keyDownEvts = new Map;
2918
+ #keyUpEvts = new Map;
2919
+ #wPropertiesViewer = new Int32Array(toArrayBuffer(lib.symbols.get_wPropertiesViewer(), 0, 4 * 4));
2920
+ #mMoveViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mMoveViewer(), 0, 9 * 8));
2921
+ #mClickViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mClickViewer(), 0, 9 * 8));
2922
+ #mDownViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mDownViewer(), 0, 9 * 8));
2923
+ #mUpViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mUpViewer(), 0, 9 * 8));
2924
+ #kDownViewer = new Int32Array(toArrayBuffer(lib.symbols.get_kDownViewer(), 0, 7 * 4));
2925
+ #kUpViewer = new Int32Array(toArrayBuffer(lib.symbols.get_kUpViewer(), 0, 7 * 4));
2926
+ #mWheelViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mWheelViewer(), 0, 5 * 8));
2927
+ #evtDetails = new WeakMap;
2928
+ #freeIndex = new Array;
2929
+ #eIndex = 0;
2930
+ #processEvents() {
2931
+ if (this.#wPropertiesViewer[0] != 0) {
2932
+ this.#wPropertiesViewer[0] = 0;
2933
+ const details = new Event("resize", this);
2934
+ if (this.onresize)
2935
+ this.onresize(details);
2936
+ this.#rEvts.forEach((item, key) => {
2937
+ item.cb(details);
2938
+ });
2939
+ }
2940
+ if (this.#mMoveViewer[0] != 0) {
2941
+ this.#mMoveViewer[0] = 0;
2942
+ const evt = new MouseEvent("move", {
2943
+ target: this,
2944
+ altKey: false,
2945
+ button: 0,
2946
+ buttons: this.#mMoveViewer[5],
2947
+ clientX: this.#mMoveViewer[1],
2948
+ clientY: this.#mMoveViewer[2],
2949
+ movementX: this.#mMoveViewer[3],
2950
+ movementY: this.#mMoveViewer[4],
2951
+ ctrlKey: false,
2952
+ metaKey: false,
2953
+ screenX: 0,
2954
+ screenY: 0,
2955
+ shiftKey: false
2956
+ });
2957
+ if (this.onmousemove)
2958
+ this.onmousemove(evt);
2959
+ this.#mMoveEvts.forEach((item, key) => {
2960
+ item.cb(evt);
2961
+ });
2962
+ }
2963
+ if (this.#mMoveViewer[0] != 0) {
2964
+ this.#mMoveViewer[0] = 0;
2965
+ const evt = new MouseEvent("move", {
2966
+ target: this,
2967
+ altKey: false,
2968
+ button: 0,
2969
+ buttons: this.#mMoveViewer[5],
2970
+ clientX: this.#mMoveViewer[1],
2971
+ clientY: this.#mMoveViewer[2],
2972
+ movementX: this.#mMoveViewer[3],
2973
+ movementY: this.#mMoveViewer[4],
2974
+ ctrlKey: false,
2975
+ metaKey: false,
2976
+ screenX: 0,
2977
+ screenY: 0,
2978
+ shiftKey: false
2979
+ });
2980
+ if (this.onmousemove)
2981
+ this.onmousemove(evt);
2982
+ this.#mMoveEvts.forEach((item, key) => {
2983
+ item.cb(evt);
2984
+ });
2985
+ }
2986
+ if (this.#mDownViewer[0] != 0) {
2987
+ this.#mDownViewer[0] = 0;
2988
+ const evt = new MouseEvent("down", {
2989
+ target: this,
2990
+ altKey: this.#mDownViewer[7],
2991
+ button: this.#mDownViewer[3],
2992
+ buttons: this.#mDownViewer[4],
2993
+ clientX: this.#mDownViewer[1],
2994
+ clientY: this.#mDownViewer[2],
2995
+ movementX: 0,
2996
+ movementY: 0,
2997
+ ctrlKey: this.#mDownViewer[6],
2998
+ metaKey: this.#mDownViewer[8],
2999
+ screenX: this.#mDownViewer[1],
3000
+ screenY: this.#mDownViewer[2],
3001
+ shiftKey: this.#mDownViewer[5]
3002
+ });
3003
+ if (this.onmousedown)
3004
+ this.onmousedown(evt);
3005
+ this.#mDownEvts.forEach((item, key) => {
3006
+ item.cb(evt);
3007
+ });
3008
+ }
3009
+ if (this.#mUpViewer[0] != 0) {
3010
+ this.#mUpViewer[0] = 0;
3011
+ const evt = new MouseEvent("up", {
3012
+ target: this,
3013
+ altKey: this.#mUpViewer[7],
3014
+ button: this.#mUpViewer[3],
3015
+ buttons: this.#mUpViewer[4],
3016
+ clientX: this.#mUpViewer[1],
3017
+ clientY: this.#mUpViewer[2],
3018
+ movementX: 0,
3019
+ movementY: 0,
3020
+ ctrlKey: this.#mUpViewer[6],
3021
+ metaKey: this.#mUpViewer[8],
3022
+ screenX: this.#mUpViewer[1],
3023
+ screenY: this.#mUpViewer[2],
3024
+ shiftKey: this.#mUpViewer[5]
3025
+ });
3026
+ if (this.onmouseup)
3027
+ this.onmouseup(evt);
3028
+ this.#mMUpEvts.forEach((item, key) => {
3029
+ item.cb(evt);
3030
+ });
3031
+ }
3032
+ if (this.#mClickViewer[0] != 0) {
3033
+ this.#mClickViewer[0] = 0;
3034
+ const evt = new MouseEvent("click", {
3035
+ target: this,
3036
+ altKey: this.#mClickViewer[7],
3037
+ button: this.#mClickViewer[3],
3038
+ buttons: this.#mClickViewer[4],
3039
+ clientX: this.#mClickViewer[1],
3040
+ clientY: this.#mClickViewer[2],
3041
+ movementX: 0,
3042
+ movementY: 0,
3043
+ ctrlKey: this.#mClickViewer[6],
3044
+ metaKey: this.#mClickViewer[8],
3045
+ screenX: this.#mClickViewer[1],
3046
+ screenY: this.#mClickViewer[2],
3047
+ shiftKey: this.#mClickViewer[5]
3048
+ });
3049
+ if (this.onclick)
3050
+ this.onclick(evt);
3051
+ this.#mClickEvts.forEach((item, key) => {
3052
+ item.cb(evt);
3053
+ });
3054
+ }
3055
+ if (this.#mWheelViewer[0] != 0) {
3056
+ this.#mWheelViewer[0] = 0;
3057
+ const evt = new WheelEvent("wheel", {
3058
+ target: this,
3059
+ altKey: this.#mMoveViewer[7],
3060
+ button: this.#mWheelViewer[3],
3061
+ buttons: this.#mWheelViewer[4],
3062
+ clientX: this.#mMoveViewer[3],
3063
+ clientY: this.#mMoveViewer[4],
3064
+ deltaX: -this.#mWheelViewer[1] * 120,
3065
+ deltaY: -this.#mWheelViewer[2] * 120,
3066
+ movementX: 0,
3067
+ movementY: 0,
3068
+ ctrlKey: this.#mMoveViewer[6],
3069
+ metaKey: this.#mMoveViewer[8],
3070
+ screenX: this.#mMoveViewer[3],
3071
+ screenY: this.#mMoveViewer[4],
3072
+ shiftKey: this.#mMoveViewer[5]
3073
+ });
3074
+ if (this.onwheel)
3075
+ this.onwheel(evt);
3076
+ this.#mWheelEvts.forEach((item, key) => {
3077
+ item.cb(evt);
3078
+ });
3079
+ }
3080
+ if (this.#kDownViewer[0] != 0) {
3081
+ this.#kDownViewer[0] = 0;
3082
+ const evt = new KeyboardEvent("down", null, this.#kDownViewer[2], this, this.#kDownViewer[1], this.#kDownViewer[3], this.#kDownViewer[4], this.#kDownViewer[5], this.#kDownViewer[6]);
3083
+ if (this.onkeydown)
3084
+ this.onkeydown(evt);
3085
+ this.#keyDownEvts.forEach((item, key) => {
3086
+ item.cb(evt);
3087
+ });
3088
+ }
3089
+ if (this.#kUpViewer[0] != 0) {
3090
+ this.#kUpViewer[0] = 0;
3091
+ const evt = new KeyboardEvent("up", null, this.#kUpViewer[2], this, this.#kUpViewer[1], this.#kUpViewer[3], this.#kUpViewer[4], this.#kUpViewer[5], this.#kUpViewer[6]);
3092
+ if (this.onkeyup)
3093
+ this.onkeyup(evt);
3094
+ this.#keyUpEvts.forEach((item, key) => {
3095
+ item.cb(evt);
3096
+ });
3097
+ }
3098
+ }
3099
+ maxFramerate = 0;
3100
+ #vsync = true;
3101
+ get vsync() {
3102
+ return this.#vsync;
3103
+ }
3104
+ set vsync(v) {
3105
+ this.#vsync = v;
3106
+ lib.symbols.set_vsync(v);
3107
+ }
3108
+ fonts = {
3109
+ add(font) {
3110
+ if (!font._nativePtr)
3111
+ throw new TypeError("Font was not loaded");
3112
+ lib.symbols.font_add_to_registry(encoder.encode(`${font.family}\x00`), font._nativePtr);
3113
+ }
3114
+ };
3115
+ onresize = null;
3116
+ onmousemove = null;
3117
+ onmousedown = null;
3118
+ onmouseup = null;
3119
+ onclick = null;
3120
+ onkeydown = null;
3121
+ onkeyup = null;
3122
+ onwheel = null;
3123
+ get innerWidth() {
3124
+ return this.#wPropertiesViewer[1];
3125
+ }
3126
+ get innerHeight() {
3127
+ return this.#wPropertiesViewer[2];
3128
+ }
3129
+ constructor(width, height, title = "App", args) {
3130
+ if (process.platform !== "darwin")
3131
+ render_thread.ref?.();
3132
+ windowWasCreated = true;
3133
+ this.#wPropertiesViewer[1] = width;
3134
+ this.#wPropertiesViewer[2] = height;
3135
+ const { vsync = true, maxFramerate = 0 } = args ?? {};
3136
+ this.#vsync = vsync;
3137
+ this.maxFramerate = maxFramerate;
3138
+ let lastFrame = performance.now();
3139
+ if (process.platform !== "darwin") {
3140
+ render_thread.onerror = (msg) => {
3141
+ console.error("Render thread error:", msg);
3142
+ };
3143
+ const titleBuf = encoder.encode(`${title}\x00`);
3144
+ render_thread.postMessage({
3145
+ w: width,
3146
+ h: height,
3147
+ t: titleBuf,
3148
+ vsync: this.#vsync,
3149
+ nativePath: dlPath
3150
+ });
3151
+ let pendingFrame = false;
3152
+ let lastFrame = performance.now();
3153
+ render_thread.onmessage = (msg) => {
3154
+ const frameSignal = msg.data;
3155
+ if (frameSignal === 2) {
3156
+ lib.symbols.destroy_window();
3157
+ lib.symbols.images_cleanup();
3158
+ process.exit(0);
3159
+ return;
3160
+ }
3161
+ if (frameSignal === 1) {
3162
+ lib.symbols.create_window(width, height, titleBuf);
3163
+ }
3164
+ lib.symbols.signal_frame_ready();
3165
+ const frameInterval = this.maxFramerate > 0 ? 1000 / this.maxFramerate : 0;
3166
+ const now = performance.now();
3167
+ const delta = now - lastFrame;
3168
+ if (frameInterval === 0 || this.#vsync || delta >= frameInterval) {
3169
+ if (frameInterval > 0) {
3170
+ lastFrame = now - delta % frameInterval;
3171
+ }
3172
+ if (!pendingFrame) {
3173
+ pendingFrame = true;
3174
+ lib.symbols.canvas_flush_gpu();
3175
+ setImmediate(() => {
3176
+ const queueLen = requestedFrames.length;
3177
+ if (queueLen > 0) {
3178
+ const framesToProcess = requestedFrames;
3179
+ requestedFrames = [];
3180
+ for (let i = 0;i < queueLen; i++) {
3181
+ framesToProcess[i](now);
3182
+ }
3183
+ }
3184
+ pendingFrame = false;
3185
+ });
3186
+ }
3187
+ }
3188
+ this.#processEvents();
3189
+ };
3190
+ } else {
3191
+ let aaplLib = dlopen2(dlPath, {
3192
+ setup_render_thread: {
3193
+ args: ["int", "int", "cstring", "ptr", "bool"],
3194
+ returns: "void"
3195
+ }
3196
+ });
3197
+ const titleBuf = encoder.encode(`${title}\x00`);
3198
+ aaplLib.symbols.setup_render_thread(width, height, titleBuf, 0, vsync);
3199
+ lib.symbols.create_window(width, height, titleBuf);
3200
+ const frameInterval = this.maxFramerate > 0 ? 1000 / this.maxFramerate : 0;
3201
+ let lastFrameTime = performance.now();
3202
+ const loop = () => {
3203
+ if (this.#wPropertiesViewer[3] == 1) {
3204
+ lib.symbols.destroy_window();
3205
+ process.exit(0);
3206
+ return;
3207
+ }
3208
+ const now = performance.now();
3209
+ const delta = now - lastFrameTime;
3210
+ if (frameInterval === 0 || delta >= frameInterval) {
3211
+ lastFrameTime = frameInterval > 0 ? now - delta % frameInterval : now;
3212
+ this.#processEvents();
3213
+ if (requestedFrames.length > 0) {
3214
+ const framesToProcess = requestedFrames;
3215
+ requestedFrames = [];
3216
+ for (let i = 0;i < framesToProcess.length; i++) {
3217
+ framesToProcess[i](now);
3218
+ }
3219
+ }
3220
+ lib.symbols.update_window();
3221
+ }
3222
+ setImmediate(loop);
3223
+ };
3224
+ loop();
3225
+ }
3226
+ }
3227
+ addEventListener(name, fn) {
3228
+ const pop = this.#freeIndex.pop();
3229
+ const usedIndex = pop != null ? pop : this.#eIndex;
3230
+ if (usedIndex == this.#eIndex)
3231
+ this.#eIndex++;
3232
+ if (name == "resize") {
3233
+ this.#rEvts.set(usedIndex, { name, cb: fn });
3234
+ this.#evtDetails.set(fn, usedIndex);
3235
+ } else if (name == "mousemove") {
3236
+ this.#mMoveEvts.set(usedIndex, { name, cb: fn });
3237
+ this.#evtDetails.set(fn, usedIndex);
3238
+ } else if (name == "mousedown") {
3239
+ this.#mDownEvts.set(usedIndex, { name, cb: fn });
3240
+ this.#evtDetails.set(fn, usedIndex);
3241
+ } else if (name == "mouseup") {
3242
+ this.#mMUpEvts.set(usedIndex, { name, cb: fn });
3243
+ this.#evtDetails.set(fn, usedIndex);
3244
+ } else if (name == "wheel") {
3245
+ this.#mWheelEvts.set(usedIndex, { name, cb: fn });
3246
+ this.#evtDetails.set(fn, usedIndex);
3247
+ } else if (name == "click") {
3248
+ this.#mClickEvts.set(usedIndex, { name, cb: fn });
3249
+ this.#evtDetails.set(fn, usedIndex);
3250
+ } else if (name == "keydown") {
3251
+ this.#keyDownEvts.set(usedIndex, { name, cb: fn });
3252
+ this.#evtDetails.set(fn, usedIndex);
3253
+ } else if (name == "keyup") {
3254
+ this.#keyUpEvts.set(usedIndex, { name, cb: fn });
3255
+ this.#evtDetails.set(fn, usedIndex);
3256
+ }
3257
+ }
3258
+ removeEventListener(name, fn) {
3259
+ const det = this.#evtDetails.get(fn);
3260
+ if (name == "resize") {
3261
+ if (det != null) {
3262
+ this.#rEvts.delete(det);
3263
+ this.#evtDetails.delete(fn);
3264
+ }
3265
+ } else if (name == "mousemove") {
3266
+ if (det != null) {
3267
+ this.#mMoveEvts.delete(det);
3268
+ this.#evtDetails.delete(fn);
3269
+ }
3270
+ } else if (name == "mousedown") {
3271
+ if (det != null) {
3272
+ this.#mDownEvts.delete(det);
3273
+ this.#evtDetails.delete(fn);
3274
+ }
3275
+ } else if (name == "mouseup") {
3276
+ if (det != null) {
3277
+ this.#mMUpEvts.delete(det);
3278
+ this.#evtDetails.delete(fn);
3279
+ }
3280
+ } else if (name == "wheel") {
3281
+ if (det != null) {
3282
+ this.#mWheelEvts.delete(det);
3283
+ this.#evtDetails.delete(fn);
3284
+ }
3285
+ } else if (name == "click") {
3286
+ if (det != null) {
3287
+ this.#mClickEvts.delete(det);
3288
+ this.#evtDetails.delete(fn);
3289
+ }
3290
+ } else if (name == "keydown") {
3291
+ if (det != null) {
3292
+ this.#keyDownEvts.delete(det);
3293
+ this.#evtDetails.delete(fn);
3294
+ }
3295
+ } else if (name == "keyup") {
3296
+ if (det != null) {
3297
+ this.#keyUpEvts.delete(det);
3298
+ this.#evtDetails.delete(fn);
3299
+ }
3300
+ }
3301
+ }
3302
+ append(canvas) {
3303
+ const canvasPtr = canvas._ptr;
3304
+ if (canvasPtr == undefined) {
3305
+ console.error("Canvas was not found");
3306
+ return;
3307
+ }
3308
+ lib.symbols.canvas_append(canvasPtr);
3309
+ }
3310
+ }
3311
+ {
3312
+ const proto = Window.prototype;
3313
+ for (const key of Object.getOwnPropertyNames(proto)) {
3314
+ const desc = Object.getOwnPropertyDescriptor(proto, key);
3315
+ if (key == "constructor") {
3316
+ desc && (desc.value.toString = () => {
3317
+ return `function ${proto.constructor.name}() { [native code] }`;
3318
+ });
3319
+ continue;
3320
+ }
3321
+ if (typeof desc?.value === "function") {
3322
+ desc.value.toString = () => `function ${key}() { [native code] }`;
3323
+ }
3324
+ }
3325
+ }
3326
+ var rAf;
3327
+ if (globalThis.requestAnimationFrame) {
3328
+ rAf = globalThis.requestAnimationFrame;
3329
+ } else {
3330
+ rAf = function requestAnimationFrame(callback) {
3331
+ setImmediate(() => {
3332
+ requestedFrames.push(callback);
3333
+ });
3334
+ };
3335
+ rAf.toString = () => `function requestAnimationFrame() { [native code] }`;
3336
+ }
3337
+ var requestAnimationFrame = rAf;
3338
+ // BunCanvas/src/Audio.ts
3339
+ var ptrs5 = new WeakMap;
3340
+ lib.symbols.audio_backend_init();
3341
+
3342
+ class Audio {
3343
+ constructor(path) {
3344
+ if (path) {
3345
+ ptrs5.set(this, lib.symbols.audio_create(encoder.encode(`${path}\x00`)));
3346
+ } else {
3347
+ ptrs5.set(this, lib.symbols.audio_create());
3348
+ }
3349
+ }
3350
+ set src(v) {
3351
+ lib.symbols.audio_set_src(encodeCString(v));
3352
+ }
3353
+ play() {
3354
+ lib.symbols.audio_play(ptrs5.get(this));
3355
+ }
3356
+ stop() {
3357
+ lib.symbols.audio_stop(ptrs5.get(this));
3358
+ }
3359
+ }
3360
+ export {
3361
+ Audio,
3362
+ Canvas,
3363
+ DOMMatrix,
3364
+ Event,
3365
+ FontFace,
3366
+ Image,
3367
+ KeyboardEvent,
3368
+ MouseEvent,
3369
+ Path2D,
3370
+ TextMetrics,
3371
+ WheelEvent,
3372
+ Window,
3373
+ requestAnimationFrame
3374
+ };