@buncanvas/core 0.1.3 → 0.1.5

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