@buncanvas/core 0.1.7 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +0 -1
- package/index.js +1094 -888
- package/internal/attachEventTarget.d.ts +1 -0
- package/internal/canvas/blendModes.d.ts +30 -0
- package/internal/canvas/lineJoin.d.ts +7 -0
- package/internal/canvas/smoothingQuality.d.ts +7 -0
- package/internal/canvas/textAlignment.d.ts +9 -0
- package/internal/canvas/textBaseline.d.ts +10 -0
- package/internal/native/enums.d.ts +61 -0
- package/internal/symbols.d.ts +16 -4
- package/internal/window/glfwKeyMap.d.ts +368 -0
- package/package.json +5 -4
- package/src/Canvas.d.ts +11 -6
- package/src/Image.d.ts +0 -1
- package/src/KeyboardEvent.d.ts +43 -22
- package/src/MouseEvent.d.ts +51 -14
- package/src/Path2D.d.ts +1 -2
- package/src/WheelEvent.d.ts +16 -4
- package/src/Window.d.ts +26 -12
- package/src/Event.d.ts +0 -6
package/index.js
CHANGED
|
@@ -72,6 +72,10 @@ var lib = dlopen(dlPath, {
|
|
|
72
72
|
args: [],
|
|
73
73
|
returns: "ptr"
|
|
74
74
|
},
|
|
75
|
+
get_wFocusBlurViewer: {
|
|
76
|
+
args: [],
|
|
77
|
+
returns: "ptr"
|
|
78
|
+
},
|
|
75
79
|
signal_frame_ready: {
|
|
76
80
|
args: [],
|
|
77
81
|
returns: "void"
|
|
@@ -84,6 +88,10 @@ var lib = dlopen(dlPath, {
|
|
|
84
88
|
args: ["int", "int", "cstring"],
|
|
85
89
|
returns: "void"
|
|
86
90
|
},
|
|
91
|
+
window_set_fullscreen: {
|
|
92
|
+
args: ["bool"],
|
|
93
|
+
returns: "void"
|
|
94
|
+
},
|
|
87
95
|
update_window: {
|
|
88
96
|
args: ["ptr"],
|
|
89
97
|
returns: "void"
|
|
@@ -205,7 +213,7 @@ var lib = dlopen(dlPath, {
|
|
|
205
213
|
returns: "void"
|
|
206
214
|
},
|
|
207
215
|
canvas_set_composite_operation: {
|
|
208
|
-
args: ["ptr", "
|
|
216
|
+
args: ["ptr", "int"],
|
|
209
217
|
returns: "bool"
|
|
210
218
|
},
|
|
211
219
|
canvas_draw_image_imageType: {
|
|
@@ -301,7 +309,7 @@ var lib = dlopen(dlPath, {
|
|
|
301
309
|
returns: "bool"
|
|
302
310
|
},
|
|
303
311
|
canvas_set_line_join: {
|
|
304
|
-
args: ["ptr", "
|
|
312
|
+
args: ["ptr", "i8"],
|
|
305
313
|
returns: "bool"
|
|
306
314
|
},
|
|
307
315
|
canvas_path_clip: {
|
|
@@ -310,11 +318,11 @@ var lib = dlopen(dlPath, {
|
|
|
310
318
|
},
|
|
311
319
|
canvas_set_text_baseline: {
|
|
312
320
|
args: ["ptr", "int"],
|
|
313
|
-
returns: "
|
|
321
|
+
returns: "bool"
|
|
314
322
|
},
|
|
315
323
|
canvas_set_text_align: {
|
|
316
324
|
args: ["ptr", "int"],
|
|
317
|
-
returns: "
|
|
325
|
+
returns: "bool"
|
|
318
326
|
},
|
|
319
327
|
canvas_measure_text: {
|
|
320
328
|
args: ["ptr", "cstring", "ptr"],
|
|
@@ -324,6 +332,10 @@ var lib = dlopen(dlPath, {
|
|
|
324
332
|
args: ["ptr"],
|
|
325
333
|
returns: "void"
|
|
326
334
|
},
|
|
335
|
+
canvas_destroy_all: {
|
|
336
|
+
args: [],
|
|
337
|
+
returns: "void"
|
|
338
|
+
},
|
|
327
339
|
image_create: {
|
|
328
340
|
args: [],
|
|
329
341
|
returns: "ptr"
|
|
@@ -434,23 +446,25 @@ var lib = dlopen(dlPath, {
|
|
|
434
446
|
}
|
|
435
447
|
});
|
|
436
448
|
|
|
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
449
|
// BunCanvas/src/Image.ts
|
|
449
450
|
import { ptr } from "bun:ffi";
|
|
451
|
+
|
|
452
|
+
// BunCanvas/internal/pointers.ts
|
|
450
453
|
var ptrs = new WeakMap;
|
|
454
|
+
|
|
455
|
+
// BunCanvas/internal/attachEventTarget.ts
|
|
456
|
+
function attachEventTarget(event, target) {
|
|
457
|
+
Object.defineProperty(event, "target", {
|
|
458
|
+
value: target,
|
|
459
|
+
enumerable: true,
|
|
460
|
+
configurable: true
|
|
461
|
+
});
|
|
462
|
+
return event;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// BunCanvas/src/Image.ts
|
|
451
466
|
var fRegistry = new FinalizationRegistry((ptr) => {
|
|
452
467
|
lib.symbols.image_destroy(ptr);
|
|
453
|
-
console.log("destroy!");
|
|
454
468
|
});
|
|
455
469
|
function computePath(url) {
|
|
456
470
|
const hash = createHash("sha256").update(url).digest("hex").slice(0, 16);
|
|
@@ -502,15 +516,15 @@ class Image {
|
|
|
502
516
|
if (lib.symbols.image_load(iptr, ptr(tArr))) {
|
|
503
517
|
this.#width = !this.#setWidth ? tArr[0] : this.#width;
|
|
504
518
|
this.#height = !this.#setHeight ? tArr[1] : this.#height;
|
|
505
|
-
self.onload?.call(self, new Event("load", self));
|
|
519
|
+
self.onload?.call(self, attachEventTarget(new Event("load", {}), self));
|
|
506
520
|
} else {
|
|
507
|
-
self.onerror?.call(self, new Event("error", self));
|
|
521
|
+
self.onerror?.call(self, attachEventTarget(new Event("error", {}), self));
|
|
508
522
|
}
|
|
509
523
|
}).catch((ex) => {
|
|
510
524
|
const self = weakThis.deref();
|
|
511
525
|
if (!self)
|
|
512
526
|
return;
|
|
513
|
-
self.onerror?.call(self, new Event("error", self));
|
|
527
|
+
self.onerror?.call(self, attachEventTarget(new Event("error", {}), self));
|
|
514
528
|
}).finally(() => {});
|
|
515
529
|
return;
|
|
516
530
|
} else {
|
|
@@ -527,9 +541,9 @@ class Image {
|
|
|
527
541
|
if (lib.symbols.image_load(_ptr, ptr(tArr))) {
|
|
528
542
|
this.#width = !this.#setWidth ? tArr[0] : this.#width;
|
|
529
543
|
this.#height = !this.#setHeight ? tArr[1] : this.#height;
|
|
530
|
-
self.onload?.call(self, new Event("
|
|
544
|
+
self.onload?.call(self, attachEventTarget(new Event("error", {}), self));
|
|
531
545
|
} else {
|
|
532
|
-
self.onerror?.call(self, new Event("error", self));
|
|
546
|
+
self.onerror?.call(self, attachEventTarget(new Event("error", {}), self));
|
|
533
547
|
}
|
|
534
548
|
clearTimeout(tm);
|
|
535
549
|
}, 0);
|
|
@@ -651,474 +665,243 @@ class TextMetrics {
|
|
|
651
665
|
}
|
|
652
666
|
// BunCanvas/src/MouseEvent.ts
|
|
653
667
|
class MouseEvent extends Event {
|
|
654
|
-
altKey
|
|
655
|
-
button
|
|
656
|
-
buttons
|
|
657
|
-
clientX
|
|
658
|
-
clientY
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
this.ctrlKey = args.ctrlKey;
|
|
676
|
-
this.metaKey = args.metaKey;
|
|
677
|
-
this.screenX = args.screenX;
|
|
678
|
-
this.screenY = args.screenY;
|
|
679
|
-
this.shiftKey = args.shiftKey;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
var proto = MouseEvent.prototype;
|
|
683
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
684
|
-
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
685
|
-
if (key == "constructor") {
|
|
686
|
-
desc && (desc.value.toString = () => {
|
|
687
|
-
return `function ${proto.constructor.name}() { [native code] }`;
|
|
668
|
+
#altKey;
|
|
669
|
+
#button;
|
|
670
|
+
#buttons;
|
|
671
|
+
#clientX;
|
|
672
|
+
#clientY;
|
|
673
|
+
#ctrlKey;
|
|
674
|
+
#detail;
|
|
675
|
+
#metaKey;
|
|
676
|
+
#movementX;
|
|
677
|
+
#movementY;
|
|
678
|
+
#relatedTarget;
|
|
679
|
+
#screenX;
|
|
680
|
+
#screenY;
|
|
681
|
+
#shiftKey;
|
|
682
|
+
#view;
|
|
683
|
+
#modifiers;
|
|
684
|
+
constructor(type, eventInitDict = {}) {
|
|
685
|
+
super(type, {
|
|
686
|
+
bubbles: eventInitDict.bubbles ?? false,
|
|
687
|
+
cancelable: eventInitDict.cancelable ?? false,
|
|
688
|
+
composed: eventInitDict.composed ?? false
|
|
688
689
|
});
|
|
689
|
-
|
|
690
|
+
this.#altKey = Boolean(eventInitDict.altKey);
|
|
691
|
+
this.#button = Number(eventInitDict.button ?? 0);
|
|
692
|
+
this.#buttons = Number(eventInitDict.buttons ?? 0);
|
|
693
|
+
this.#clientX = Number(eventInitDict.clientX ?? 0);
|
|
694
|
+
this.#clientY = Number(eventInitDict.clientY ?? 0);
|
|
695
|
+
this.#ctrlKey = Boolean(eventInitDict.ctrlKey);
|
|
696
|
+
this.#detail = Number(eventInitDict.detail ?? 0);
|
|
697
|
+
this.#metaKey = Boolean(eventInitDict.metaKey);
|
|
698
|
+
this.#movementX = Number(eventInitDict.movementX ?? 0);
|
|
699
|
+
this.#movementY = Number(eventInitDict.movementY ?? 0);
|
|
700
|
+
this.#relatedTarget = eventInitDict.relatedTarget ?? null;
|
|
701
|
+
this.#screenX = Number(eventInitDict.screenX ?? 0);
|
|
702
|
+
this.#screenY = Number(eventInitDict.screenY ?? 0);
|
|
703
|
+
this.#shiftKey = Boolean(eventInitDict.shiftKey);
|
|
704
|
+
this.#view = eventInitDict.view ?? null;
|
|
705
|
+
this.#modifiers = new Map([
|
|
706
|
+
["Alt", this.#altKey],
|
|
707
|
+
["Control", this.#ctrlKey],
|
|
708
|
+
["Meta", this.#metaKey],
|
|
709
|
+
["Shift", this.#shiftKey],
|
|
710
|
+
["AltGraph", Boolean(eventInitDict.modifierAltGraph)],
|
|
711
|
+
["CapsLock", Boolean(eventInitDict.modifierCapsLock)],
|
|
712
|
+
["Fn", Boolean(eventInitDict.modifierFn)],
|
|
713
|
+
["FnLock", Boolean(eventInitDict.modifierFnLock)],
|
|
714
|
+
["Hyper", Boolean(eventInitDict.modifierHyper)],
|
|
715
|
+
["NumLock", Boolean(eventInitDict.modifierNumLock)],
|
|
716
|
+
["ScrollLock", Boolean(eventInitDict.modifierScrollLock)],
|
|
717
|
+
["Super", Boolean(eventInitDict.modifierSuper)],
|
|
718
|
+
["Symbol", Boolean(eventInitDict.modifierSymbol)],
|
|
719
|
+
["SymbolLock", Boolean(eventInitDict.modifierSymbolLock)]
|
|
720
|
+
]);
|
|
690
721
|
}
|
|
691
|
-
|
|
692
|
-
|
|
722
|
+
get altKey() {
|
|
723
|
+
return this.#altKey;
|
|
724
|
+
}
|
|
725
|
+
get button() {
|
|
726
|
+
return this.#button;
|
|
727
|
+
}
|
|
728
|
+
get buttons() {
|
|
729
|
+
return this.#buttons;
|
|
730
|
+
}
|
|
731
|
+
get clientX() {
|
|
732
|
+
return this.#clientX;
|
|
733
|
+
}
|
|
734
|
+
get clientY() {
|
|
735
|
+
return this.#clientY;
|
|
736
|
+
}
|
|
737
|
+
get ctrlKey() {
|
|
738
|
+
return this.#ctrlKey;
|
|
739
|
+
}
|
|
740
|
+
get metaKey() {
|
|
741
|
+
return this.#metaKey;
|
|
742
|
+
}
|
|
743
|
+
get movementX() {
|
|
744
|
+
return this.#movementX;
|
|
745
|
+
}
|
|
746
|
+
get movementY() {
|
|
747
|
+
return this.#movementY;
|
|
748
|
+
}
|
|
749
|
+
get relatedTarget() {
|
|
750
|
+
return this.#relatedTarget;
|
|
751
|
+
}
|
|
752
|
+
get screenX() {
|
|
753
|
+
return this.#screenX;
|
|
754
|
+
}
|
|
755
|
+
get screenY() {
|
|
756
|
+
return this.#screenY;
|
|
757
|
+
}
|
|
758
|
+
get shiftKey() {
|
|
759
|
+
return this.#shiftKey;
|
|
760
|
+
}
|
|
761
|
+
get x() {
|
|
762
|
+
return this.#clientX;
|
|
763
|
+
}
|
|
764
|
+
get y() {
|
|
765
|
+
return this.#clientY;
|
|
766
|
+
}
|
|
767
|
+
get pageX() {
|
|
768
|
+
return this.#clientX + (this.#view?.scrollX ?? 0);
|
|
769
|
+
}
|
|
770
|
+
get pageY() {
|
|
771
|
+
return this.#clientY + (this.#view?.scrollY ?? 0);
|
|
772
|
+
}
|
|
773
|
+
get offsetX() {
|
|
774
|
+
return this.#clientX;
|
|
775
|
+
}
|
|
776
|
+
get offsetY() {
|
|
777
|
+
return this.#clientY;
|
|
778
|
+
}
|
|
779
|
+
get detail() {
|
|
780
|
+
return this.#detail;
|
|
781
|
+
}
|
|
782
|
+
get view() {
|
|
783
|
+
return this.#view;
|
|
784
|
+
}
|
|
785
|
+
getModifierState(keyArg) {
|
|
786
|
+
return this.#modifiers.get(keyArg) ?? false;
|
|
693
787
|
}
|
|
694
788
|
}
|
|
695
789
|
// BunCanvas/src/WheelEvent.ts
|
|
696
790
|
class WheelEvent extends MouseEvent {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
791
|
+
static DOM_DELTA_PIXEL = 0;
|
|
792
|
+
static DOM_DELTA_LINE = 1;
|
|
793
|
+
static DOM_DELTA_PAGE = 2;
|
|
794
|
+
#deltaX;
|
|
795
|
+
#deltaY;
|
|
796
|
+
#deltaZ;
|
|
797
|
+
#deltaMode;
|
|
798
|
+
constructor(type, eventInitDict = {}) {
|
|
799
|
+
super(type, eventInitDict);
|
|
800
|
+
this.#deltaX = Number(eventInitDict.deltaX ?? 0);
|
|
801
|
+
this.#deltaY = Number(eventInitDict.deltaY ?? 0);
|
|
802
|
+
this.#deltaZ = Number(eventInitDict.deltaZ ?? 0);
|
|
803
|
+
this.#deltaMode = Number(eventInitDict.deltaMode ?? WheelEvent.DOM_DELTA_PIXEL);
|
|
804
|
+
}
|
|
805
|
+
get deltaX() {
|
|
806
|
+
return this.#deltaX;
|
|
807
|
+
}
|
|
808
|
+
get deltaY() {
|
|
809
|
+
return this.#deltaY;
|
|
810
|
+
}
|
|
811
|
+
get deltaZ() {
|
|
812
|
+
return this.#deltaZ;
|
|
813
|
+
}
|
|
814
|
+
get deltaMode() {
|
|
815
|
+
return this.#deltaMode;
|
|
703
816
|
}
|
|
704
817
|
}
|
|
705
|
-
// BunCanvas/src/KeyboardEvent.
|
|
706
|
-
var GLFW_KEY_MAP = {
|
|
707
|
-
"-1": "Unknown",
|
|
708
|
-
32: " ",
|
|
709
|
-
39: "'",
|
|
710
|
-
44: ",",
|
|
711
|
-
45: "-",
|
|
712
|
-
46: ".",
|
|
713
|
-
47: "/",
|
|
714
|
-
48: "0",
|
|
715
|
-
49: "1",
|
|
716
|
-
50: "2",
|
|
717
|
-
51: "3",
|
|
718
|
-
52: "4",
|
|
719
|
-
53: "5",
|
|
720
|
-
54: "6",
|
|
721
|
-
55: "7",
|
|
722
|
-
56: "8",
|
|
723
|
-
57: "9",
|
|
724
|
-
59: ";",
|
|
725
|
-
61: "=",
|
|
726
|
-
65: "a",
|
|
727
|
-
66: "b",
|
|
728
|
-
67: "c",
|
|
729
|
-
68: "d",
|
|
730
|
-
69: "e",
|
|
731
|
-
70: "f",
|
|
732
|
-
71: "g",
|
|
733
|
-
72: "h",
|
|
734
|
-
73: "i",
|
|
735
|
-
74: "j",
|
|
736
|
-
75: "k",
|
|
737
|
-
76: "l",
|
|
738
|
-
77: "m",
|
|
739
|
-
78: "n",
|
|
740
|
-
79: "o",
|
|
741
|
-
80: "p",
|
|
742
|
-
81: "q",
|
|
743
|
-
82: "r",
|
|
744
|
-
83: "s",
|
|
745
|
-
84: "t",
|
|
746
|
-
85: "u",
|
|
747
|
-
86: "v",
|
|
748
|
-
87: "w",
|
|
749
|
-
88: "x",
|
|
750
|
-
89: "y",
|
|
751
|
-
90: "z",
|
|
752
|
-
91: "[",
|
|
753
|
-
92: "\\",
|
|
754
|
-
93: "]",
|
|
755
|
-
96: "`",
|
|
756
|
-
161: "World1",
|
|
757
|
-
162: "World2",
|
|
758
|
-
256: "Escape",
|
|
759
|
-
257: "Enter",
|
|
760
|
-
258: "Tab",
|
|
761
|
-
259: "Backspace",
|
|
762
|
-
260: "Insert",
|
|
763
|
-
261: "Delete",
|
|
764
|
-
262: "ArrowRight",
|
|
765
|
-
263: "ArrowLeft",
|
|
766
|
-
264: "ArrowDown",
|
|
767
|
-
265: "ArrowUp",
|
|
768
|
-
266: "PageUp",
|
|
769
|
-
267: "PageDown",
|
|
770
|
-
268: "Home",
|
|
771
|
-
269: "End",
|
|
772
|
-
280: "CapsLock",
|
|
773
|
-
281: "ScrollLock",
|
|
774
|
-
282: "NumLock",
|
|
775
|
-
283: "PrintScreen",
|
|
776
|
-
284: "Pause",
|
|
777
|
-
290: "F1",
|
|
778
|
-
291: "F2",
|
|
779
|
-
292: "F3",
|
|
780
|
-
293: "F4",
|
|
781
|
-
294: "F5",
|
|
782
|
-
295: "F6",
|
|
783
|
-
296: "F7",
|
|
784
|
-
297: "F8",
|
|
785
|
-
298: "F9",
|
|
786
|
-
299: "F10",
|
|
787
|
-
300: "F11",
|
|
788
|
-
301: "F12",
|
|
789
|
-
302: "F13",
|
|
790
|
-
303: "F14",
|
|
791
|
-
304: "F15",
|
|
792
|
-
305: "F16",
|
|
793
|
-
306: "F17",
|
|
794
|
-
307: "F18",
|
|
795
|
-
308: "F19",
|
|
796
|
-
309: "F20",
|
|
797
|
-
310: "F21",
|
|
798
|
-
311: "F22",
|
|
799
|
-
312: "F23",
|
|
800
|
-
313: "F24",
|
|
801
|
-
314: "F25",
|
|
802
|
-
320: "0",
|
|
803
|
-
321: "1",
|
|
804
|
-
322: "2",
|
|
805
|
-
323: "3",
|
|
806
|
-
324: "4",
|
|
807
|
-
325: "5",
|
|
808
|
-
326: "6",
|
|
809
|
-
327: "7",
|
|
810
|
-
328: "8",
|
|
811
|
-
329: "9",
|
|
812
|
-
330: ".",
|
|
813
|
-
331: "/",
|
|
814
|
-
332: "*",
|
|
815
|
-
333: "-",
|
|
816
|
-
334: "+",
|
|
817
|
-
335: "Enter",
|
|
818
|
-
336: "=",
|
|
819
|
-
340: "Shift",
|
|
820
|
-
341: "Control",
|
|
821
|
-
342: "Alt",
|
|
822
|
-
343: "Meta",
|
|
823
|
-
344: "Shift",
|
|
824
|
-
345: "Control",
|
|
825
|
-
346: "Alt",
|
|
826
|
-
347: "Meta",
|
|
827
|
-
348: "ContextMenu"
|
|
828
|
-
};
|
|
829
|
-
var GLFW_KEY_MAP_SHIFT = {
|
|
830
|
-
"-1": "Unknown",
|
|
831
|
-
32: " ",
|
|
832
|
-
39: '"',
|
|
833
|
-
44: "<",
|
|
834
|
-
45: "_",
|
|
835
|
-
46: ">",
|
|
836
|
-
47: "?",
|
|
837
|
-
48: ")",
|
|
838
|
-
49: "!",
|
|
839
|
-
50: "@",
|
|
840
|
-
51: "#",
|
|
841
|
-
52: "$",
|
|
842
|
-
53: "%",
|
|
843
|
-
54: "^",
|
|
844
|
-
55: "&",
|
|
845
|
-
56: "*",
|
|
846
|
-
57: "(",
|
|
847
|
-
59: ":",
|
|
848
|
-
61: "+",
|
|
849
|
-
65: "A",
|
|
850
|
-
66: "B",
|
|
851
|
-
67: "C",
|
|
852
|
-
68: "D",
|
|
853
|
-
69: "E",
|
|
854
|
-
70: "F",
|
|
855
|
-
71: "G",
|
|
856
|
-
72: "H",
|
|
857
|
-
73: "I",
|
|
858
|
-
74: "J",
|
|
859
|
-
75: "K",
|
|
860
|
-
76: "L",
|
|
861
|
-
77: "M",
|
|
862
|
-
78: "N",
|
|
863
|
-
79: "O",
|
|
864
|
-
80: "P",
|
|
865
|
-
81: "Q",
|
|
866
|
-
82: "R",
|
|
867
|
-
83: "S",
|
|
868
|
-
84: "T",
|
|
869
|
-
85: "U",
|
|
870
|
-
86: "V",
|
|
871
|
-
87: "W",
|
|
872
|
-
88: "X",
|
|
873
|
-
89: "Y",
|
|
874
|
-
90: "Z",
|
|
875
|
-
91: "{",
|
|
876
|
-
92: "|",
|
|
877
|
-
93: "}",
|
|
878
|
-
96: "~",
|
|
879
|
-
161: "World1",
|
|
880
|
-
162: "World2",
|
|
881
|
-
256: "Escape",
|
|
882
|
-
257: "Enter",
|
|
883
|
-
258: "Tab",
|
|
884
|
-
259: "Backspace",
|
|
885
|
-
260: "Insert",
|
|
886
|
-
261: "Delete",
|
|
887
|
-
262: "ArrowRight",
|
|
888
|
-
263: "ArrowLeft",
|
|
889
|
-
264: "ArrowDown",
|
|
890
|
-
265: "ArrowUp",
|
|
891
|
-
266: "PageUp",
|
|
892
|
-
267: "PageDown",
|
|
893
|
-
268: "Home",
|
|
894
|
-
269: "End",
|
|
895
|
-
280: "CapsLock",
|
|
896
|
-
281: "ScrollLock",
|
|
897
|
-
282: "NumLock",
|
|
898
|
-
283: "PrintScreen",
|
|
899
|
-
284: "Pause",
|
|
900
|
-
290: "F1",
|
|
901
|
-
291: "F2",
|
|
902
|
-
292: "F3",
|
|
903
|
-
293: "F4",
|
|
904
|
-
294: "F5",
|
|
905
|
-
295: "F6",
|
|
906
|
-
296: "F7",
|
|
907
|
-
297: "F8",
|
|
908
|
-
298: "F9",
|
|
909
|
-
299: "F10",
|
|
910
|
-
300: "F11",
|
|
911
|
-
301: "F12",
|
|
912
|
-
302: "F13",
|
|
913
|
-
303: "F14",
|
|
914
|
-
304: "F15",
|
|
915
|
-
305: "F16",
|
|
916
|
-
306: "F17",
|
|
917
|
-
307: "F18",
|
|
918
|
-
308: "F19",
|
|
919
|
-
309: "F20",
|
|
920
|
-
310: "F21",
|
|
921
|
-
311: "F22",
|
|
922
|
-
312: "F23",
|
|
923
|
-
313: "F24",
|
|
924
|
-
314: "F25",
|
|
925
|
-
320: "0",
|
|
926
|
-
321: "1",
|
|
927
|
-
322: "2",
|
|
928
|
-
323: "3",
|
|
929
|
-
324: "4",
|
|
930
|
-
325: "5",
|
|
931
|
-
326: "6",
|
|
932
|
-
327: "7",
|
|
933
|
-
328: "8",
|
|
934
|
-
329: "9",
|
|
935
|
-
330: ".",
|
|
936
|
-
331: "/",
|
|
937
|
-
332: "*",
|
|
938
|
-
333: "-",
|
|
939
|
-
334: "+",
|
|
940
|
-
335: "Enter",
|
|
941
|
-
336: "=",
|
|
942
|
-
340: "Shift",
|
|
943
|
-
341: "Control",
|
|
944
|
-
342: "Alt",
|
|
945
|
-
343: "Meta",
|
|
946
|
-
344: "Shift",
|
|
947
|
-
345: "Control",
|
|
948
|
-
346: "Alt",
|
|
949
|
-
347: "Meta",
|
|
950
|
-
348: "ContextMenu"
|
|
951
|
-
};
|
|
952
|
-
var GLFW_CODE_MAP = {
|
|
953
|
-
"-1": "Unknown",
|
|
954
|
-
32: "Space",
|
|
955
|
-
39: "Quote",
|
|
956
|
-
44: "Comma",
|
|
957
|
-
45: "Minus",
|
|
958
|
-
46: "Period",
|
|
959
|
-
47: "Slash",
|
|
960
|
-
48: "Digit0",
|
|
961
|
-
49: "Digit1",
|
|
962
|
-
50: "Digit2",
|
|
963
|
-
51: "Digit3",
|
|
964
|
-
52: "Digit4",
|
|
965
|
-
53: "Digit5",
|
|
966
|
-
54: "Digit6",
|
|
967
|
-
55: "Digit7",
|
|
968
|
-
56: "Digit8",
|
|
969
|
-
57: "Digit9",
|
|
970
|
-
59: "Semicolon",
|
|
971
|
-
61: "Equal",
|
|
972
|
-
65: "KeyA",
|
|
973
|
-
66: "KeyB",
|
|
974
|
-
67: "KeyC",
|
|
975
|
-
68: "KeyD",
|
|
976
|
-
69: "KeyE",
|
|
977
|
-
70: "KeyF",
|
|
978
|
-
71: "KeyG",
|
|
979
|
-
72: "KeyH",
|
|
980
|
-
73: "KeyI",
|
|
981
|
-
74: "KeyJ",
|
|
982
|
-
75: "KeyK",
|
|
983
|
-
76: "KeyL",
|
|
984
|
-
77: "KeyM",
|
|
985
|
-
78: "KeyN",
|
|
986
|
-
79: "KeyO",
|
|
987
|
-
80: "KeyP",
|
|
988
|
-
81: "KeyQ",
|
|
989
|
-
82: "KeyR",
|
|
990
|
-
83: "KeyS",
|
|
991
|
-
84: "KeyT",
|
|
992
|
-
85: "KeyU",
|
|
993
|
-
86: "KeyV",
|
|
994
|
-
87: "KeyW",
|
|
995
|
-
88: "KeyX",
|
|
996
|
-
89: "KeyY",
|
|
997
|
-
90: "KeyZ",
|
|
998
|
-
91: "BracketLeft",
|
|
999
|
-
92: "Backslash",
|
|
1000
|
-
93: "BracketRight",
|
|
1001
|
-
96: "Backquote",
|
|
1002
|
-
161: "IntlBackslash",
|
|
1003
|
-
256: "Escape",
|
|
1004
|
-
257: "Enter",
|
|
1005
|
-
258: "Tab",
|
|
1006
|
-
259: "Backspace",
|
|
1007
|
-
260: "Insert",
|
|
1008
|
-
261: "Delete",
|
|
1009
|
-
262: "ArrowRight",
|
|
1010
|
-
263: "ArrowLeft",
|
|
1011
|
-
264: "ArrowDown",
|
|
1012
|
-
265: "ArrowUp",
|
|
1013
|
-
266: "PageUp",
|
|
1014
|
-
267: "PageDown",
|
|
1015
|
-
268: "Home",
|
|
1016
|
-
269: "End",
|
|
1017
|
-
280: "CapsLock",
|
|
1018
|
-
281: "ScrollLock",
|
|
1019
|
-
282: "NumLock",
|
|
1020
|
-
283: "PrintScreen",
|
|
1021
|
-
284: "Pause",
|
|
1022
|
-
290: "F1",
|
|
1023
|
-
291: "F2",
|
|
1024
|
-
292: "F3",
|
|
1025
|
-
293: "F4",
|
|
1026
|
-
294: "F5",
|
|
1027
|
-
295: "F6",
|
|
1028
|
-
296: "F7",
|
|
1029
|
-
297: "F8",
|
|
1030
|
-
298: "F9",
|
|
1031
|
-
299: "F10",
|
|
1032
|
-
300: "F11",
|
|
1033
|
-
301: "F12",
|
|
1034
|
-
302: "F13",
|
|
1035
|
-
303: "F14",
|
|
1036
|
-
304: "F15",
|
|
1037
|
-
305: "F16",
|
|
1038
|
-
306: "F17",
|
|
1039
|
-
307: "F18",
|
|
1040
|
-
308: "F19",
|
|
1041
|
-
309: "F20",
|
|
1042
|
-
310: "F21",
|
|
1043
|
-
311: "F22",
|
|
1044
|
-
312: "F23",
|
|
1045
|
-
313: "F24",
|
|
1046
|
-
314: "F25",
|
|
1047
|
-
320: "Numpad0",
|
|
1048
|
-
321: "Numpad1",
|
|
1049
|
-
322: "Numpad2",
|
|
1050
|
-
323: "Numpad3",
|
|
1051
|
-
324: "Numpad4",
|
|
1052
|
-
325: "Numpad5",
|
|
1053
|
-
326: "Numpad6",
|
|
1054
|
-
327: "Numpad7",
|
|
1055
|
-
328: "Numpad8",
|
|
1056
|
-
329: "Numpad9",
|
|
1057
|
-
330: "NumpadDecimal",
|
|
1058
|
-
331: "NumpadDivide",
|
|
1059
|
-
332: "NumpadMultiply",
|
|
1060
|
-
333: "NumpadSubtract",
|
|
1061
|
-
334: "NumpadAdd",
|
|
1062
|
-
335: "NumpadEnter",
|
|
1063
|
-
336: "NumpadEqual",
|
|
1064
|
-
340: "ShiftLeft",
|
|
1065
|
-
341: "ControlLeft",
|
|
1066
|
-
342: "AltLeft",
|
|
1067
|
-
343: "MetaLeft",
|
|
1068
|
-
344: "ShiftRight",
|
|
1069
|
-
345: "ControlRight",
|
|
1070
|
-
346: "AltRight",
|
|
1071
|
-
347: "MetaRight",
|
|
1072
|
-
348: "ContextMenu"
|
|
1073
|
-
};
|
|
1074
|
-
|
|
818
|
+
// BunCanvas/src/KeyboardEvent.ts
|
|
1075
819
|
class KeyboardEvent extends Event {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
820
|
+
static DOM_KEY_LOCATION_STANDARD = 0;
|
|
821
|
+
static DOM_KEY_LOCATION_LEFT = 1;
|
|
822
|
+
static DOM_KEY_LOCATION_RIGHT = 2;
|
|
823
|
+
static DOM_KEY_LOCATION_NUMPAD = 3;
|
|
824
|
+
#altKey;
|
|
825
|
+
#code;
|
|
826
|
+
#ctrlKey;
|
|
827
|
+
#detail;
|
|
828
|
+
#isComposing;
|
|
829
|
+
#key;
|
|
830
|
+
#location;
|
|
831
|
+
#metaKey;
|
|
832
|
+
#repeat;
|
|
833
|
+
#shiftKey;
|
|
834
|
+
#view;
|
|
835
|
+
#modifiers;
|
|
836
|
+
constructor(type, eventInitDict = {}) {
|
|
837
|
+
super(type, {
|
|
838
|
+
bubbles: eventInitDict.bubbles ?? false,
|
|
839
|
+
cancelable: eventInitDict.cancelable ?? false,
|
|
840
|
+
composed: eventInitDict.composed ?? false
|
|
841
|
+
});
|
|
842
|
+
this.#altKey = Boolean(eventInitDict.altKey);
|
|
843
|
+
this.#code = String(eventInitDict.code ?? "");
|
|
844
|
+
this.#ctrlKey = Boolean(eventInitDict.ctrlKey);
|
|
845
|
+
this.#detail = Number(eventInitDict.detail ?? 0);
|
|
846
|
+
this.#isComposing = Boolean(eventInitDict.isComposing);
|
|
847
|
+
this.#key = String(eventInitDict.key ?? "");
|
|
848
|
+
this.#location = Number(eventInitDict.location ?? KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
|
849
|
+
this.#metaKey = Boolean(eventInitDict.metaKey);
|
|
850
|
+
this.#repeat = Boolean(eventInitDict.repeat);
|
|
851
|
+
this.#shiftKey = Boolean(eventInitDict.shiftKey);
|
|
852
|
+
this.#view = eventInitDict.view ?? null;
|
|
853
|
+
this.#modifiers = new Map([
|
|
854
|
+
["Alt", this.#altKey],
|
|
855
|
+
["Control", this.#ctrlKey],
|
|
856
|
+
["Meta", this.#metaKey],
|
|
857
|
+
["Shift", this.#shiftKey],
|
|
858
|
+
["AltGraph", Boolean(eventInitDict.modifierAltGraph)],
|
|
859
|
+
["CapsLock", Boolean(eventInitDict.modifierCapsLock)],
|
|
860
|
+
["Fn", Boolean(eventInitDict.modifierFn)],
|
|
861
|
+
["FnLock", Boolean(eventInitDict.modifierFnLock)],
|
|
862
|
+
["Hyper", Boolean(eventInitDict.modifierHyper)],
|
|
863
|
+
["NumLock", Boolean(eventInitDict.modifierNumLock)],
|
|
864
|
+
["ScrollLock", Boolean(eventInitDict.modifierScrollLock)],
|
|
865
|
+
["Super", Boolean(eventInitDict.modifierSuper)],
|
|
866
|
+
["Symbol", Boolean(eventInitDict.modifierSymbol)],
|
|
867
|
+
["SymbolLock", Boolean(eventInitDict.modifierSymbolLock)]
|
|
868
|
+
]);
|
|
869
|
+
}
|
|
870
|
+
get altKey() {
|
|
871
|
+
return this.#altKey;
|
|
872
|
+
}
|
|
873
|
+
get code() {
|
|
874
|
+
return this.#code;
|
|
875
|
+
}
|
|
876
|
+
get ctrlKey() {
|
|
877
|
+
return this.#ctrlKey;
|
|
878
|
+
}
|
|
879
|
+
get isComposing() {
|
|
880
|
+
return this.#isComposing;
|
|
881
|
+
}
|
|
882
|
+
get key() {
|
|
883
|
+
return this.#key;
|
|
884
|
+
}
|
|
885
|
+
get location() {
|
|
886
|
+
return this.#location;
|
|
887
|
+
}
|
|
888
|
+
get metaKey() {
|
|
889
|
+
return this.#metaKey;
|
|
890
|
+
}
|
|
891
|
+
get repeat() {
|
|
892
|
+
return this.#repeat;
|
|
893
|
+
}
|
|
894
|
+
get shiftKey() {
|
|
895
|
+
return this.#shiftKey;
|
|
896
|
+
}
|
|
897
|
+
get detail() {
|
|
898
|
+
return this.#detail;
|
|
899
|
+
}
|
|
900
|
+
get view() {
|
|
901
|
+
return this.#view;
|
|
902
|
+
}
|
|
903
|
+
getModifierState(keyArg) {
|
|
904
|
+
return this.#modifiers.get(keyArg) ?? false;
|
|
1122
905
|
}
|
|
1123
906
|
}
|
|
1124
907
|
// BunCanvas/src/Canvas.ts
|
|
@@ -2082,12 +1865,12 @@ class DOMMatrix {
|
|
|
2082
1865
|
return new DOMMatrix([m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44]);
|
|
2083
1866
|
}
|
|
2084
1867
|
}
|
|
2085
|
-
var
|
|
2086
|
-
for (const key of Object.getOwnPropertyNames(
|
|
2087
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
1868
|
+
var proto = DOMMatrix.prototype;
|
|
1869
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1870
|
+
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
2088
1871
|
if (key == "constructor") {
|
|
2089
1872
|
desc && (desc.value.toString = () => {
|
|
2090
|
-
return `function ${
|
|
1873
|
+
return `function ${proto.constructor.name}() { [native code] }`;
|
|
2091
1874
|
});
|
|
2092
1875
|
continue;
|
|
2093
1876
|
}
|
|
@@ -2264,8 +2047,109 @@ function isValidColor(str) {
|
|
|
2264
2047
|
return RGB_REGEX.test(normalized) || HSL_HWB_REGEX.test(normalized);
|
|
2265
2048
|
}
|
|
2266
2049
|
|
|
2050
|
+
// BunCanvas/internal/native/enums.ts
|
|
2051
|
+
//!< r = 0
|
|
2052
|
+
//!< r = s
|
|
2053
|
+
//!< r = d
|
|
2054
|
+
//!< r = s + (1-sa)*d
|
|
2055
|
+
//!< r = d + (1-da)*s
|
|
2056
|
+
//!< r = s * da
|
|
2057
|
+
//!< r = d * sa
|
|
2058
|
+
//!< r = s * (1-da)
|
|
2059
|
+
//!< r = d * (1-sa)
|
|
2060
|
+
//!< r = s*da + d*(1-sa)
|
|
2061
|
+
//!< r = d*sa + s*(1-da)
|
|
2062
|
+
//!< r = s*(1-da) + d*(1-sa)
|
|
2063
|
+
//!< r = min(s + d, 1)
|
|
2064
|
+
//!< r = s*d
|
|
2065
|
+
//!< r = s + d - s*d
|
|
2066
|
+
//!< multiply or screen, depending on destination
|
|
2067
|
+
//!< rc = s + d - max(s*da, d*sa), ra = kSrcOver
|
|
2068
|
+
//!< rc = s + d - min(s*da, d*sa), ra = kSrcOver
|
|
2069
|
+
//!< brighten destination to reflect source
|
|
2070
|
+
//!< darken destination to reflect source
|
|
2071
|
+
//!< multiply or screen, depending on source
|
|
2072
|
+
//!< lighten or darken, depending on source
|
|
2073
|
+
//!< rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver
|
|
2074
|
+
//!< rc = s + d - two(s*d), ra = kSrcOver
|
|
2075
|
+
//!< r = s*(1-da) + d*(1-sa) + s*d
|
|
2076
|
+
//!< hue of source with saturation and luminosity of destination
|
|
2077
|
+
//!< saturation of source with hue and luminosity of destination
|
|
2078
|
+
//!< hue and saturation of source with luminosity of destination
|
|
2079
|
+
//!< luminosity of source with hue and saturation of destination
|
|
2080
|
+
//!< last porter duff blend mode
|
|
2081
|
+
//!< last blend mode operating separately on components
|
|
2082
|
+
//!< last valid value
|
|
2083
|
+
//!< extends to miter limit
|
|
2084
|
+
//!< adds circle
|
|
2085
|
+
//!< connects outside edges
|
|
2086
|
+
//!< equivalent to the largest value for Join
|
|
2087
|
+
//!< equivalent to kMiter_Join
|
|
2088
|
+
|
|
2089
|
+
// BunCanvas/internal/canvas/blendModes.ts
|
|
2090
|
+
var CanvasBlendMode = {
|
|
2091
|
+
"source-over": 3 /* kSrcOver */,
|
|
2092
|
+
"source-in": 5 /* kSrcIn */,
|
|
2093
|
+
"source-out": 7 /* kSrcOut */,
|
|
2094
|
+
"source-atop": 9 /* kSrcATop */,
|
|
2095
|
+
"destination-over": 4 /* kDstOver */,
|
|
2096
|
+
"destination-in": 6 /* kDstIn */,
|
|
2097
|
+
"destination-out": 8 /* kDstOut */,
|
|
2098
|
+
"destination-atop": 10 /* kDstATop */,
|
|
2099
|
+
lighter: 17 /* kLighten */,
|
|
2100
|
+
copy: 1 /* kSrc */,
|
|
2101
|
+
xor: 11 /* kXor */,
|
|
2102
|
+
multiply: 24 /* kMultiply */,
|
|
2103
|
+
screen: 14 /* kScreen */,
|
|
2104
|
+
overlay: 15 /* kOverlay */,
|
|
2105
|
+
darken: 16 /* kDarken */,
|
|
2106
|
+
lighten: 17 /* kLighten */,
|
|
2107
|
+
"color-dodge": 18 /* kColorDodge */,
|
|
2108
|
+
"color-burn": 19 /* kColorBurn */,
|
|
2109
|
+
"hard-light": 20 /* kHardLight */,
|
|
2110
|
+
"soft-light": 21 /* kSoftLight */,
|
|
2111
|
+
difference: 22 /* kDifference */,
|
|
2112
|
+
exclusion: 23 /* kExclusion */,
|
|
2113
|
+
hue: 25 /* kHue */,
|
|
2114
|
+
saturation: 26 /* kSaturation */,
|
|
2115
|
+
color: 27 /* kColor */,
|
|
2116
|
+
luminosity: 28 /* kLuminosity */
|
|
2117
|
+
};
|
|
2118
|
+
|
|
2119
|
+
// BunCanvas/internal/canvas/textAlignment.ts
|
|
2120
|
+
var CanvasTextAlignment = {
|
|
2121
|
+
left: 0 /* Left */,
|
|
2122
|
+
right: 1 /* Right */,
|
|
2123
|
+
center: 2 /* Center */,
|
|
2124
|
+
start: 3 /* Start */,
|
|
2125
|
+
end: 4 /* End */
|
|
2126
|
+
};
|
|
2127
|
+
|
|
2128
|
+
// BunCanvas/internal/canvas/textBaseline.ts
|
|
2129
|
+
var CanvasTextBaseline = {
|
|
2130
|
+
top: 0 /* Top */,
|
|
2131
|
+
hanging: 1 /* Hanging */,
|
|
2132
|
+
middle: 2 /* Middle */,
|
|
2133
|
+
alphabetic: 3 /* Alphabetic */,
|
|
2134
|
+
ideographic: 4 /* Ideographic */,
|
|
2135
|
+
bottom: 5 /* Bottom */
|
|
2136
|
+
};
|
|
2137
|
+
|
|
2138
|
+
// BunCanvas/internal/canvas/lineJoin.ts
|
|
2139
|
+
var CanvasLineJoin = {
|
|
2140
|
+
round: 1 /* kRound_Join */,
|
|
2141
|
+
bevel: 2 /* kBevel_Join */,
|
|
2142
|
+
miter: 0 /* kMiter_Join */
|
|
2143
|
+
};
|
|
2144
|
+
|
|
2145
|
+
// BunCanvas/internal/canvas/smoothingQuality.ts
|
|
2146
|
+
var CanvasSmoothingQuality = {
|
|
2147
|
+
low: 0 /* Low */,
|
|
2148
|
+
medium: 1 /* Medium */,
|
|
2149
|
+
high: 2 /* High */
|
|
2150
|
+
};
|
|
2151
|
+
|
|
2267
2152
|
// BunCanvas/src/Canvas.ts
|
|
2268
|
-
var ptrs3 = new WeakMap;
|
|
2269
2153
|
var canvasFinalizationRegistry = new FinalizationRegistry((ptr) => {
|
|
2270
2154
|
lib.symbols.canvas_destroy(ptr);
|
|
2271
2155
|
});
|
|
@@ -2398,14 +2282,16 @@ class CanvasRenderingContext2D {
|
|
|
2398
2282
|
}
|
|
2399
2283
|
const offsetBuffer = new Float32Array(style.offsets);
|
|
2400
2284
|
const nativeFn = isStroke ? lib.symbols.canvas_set_stroke_style_gradient : lib.symbols.canvas_set_fill_style_gradient;
|
|
2401
|
-
return nativeFn(
|
|
2285
|
+
return nativeFn(ptrs.get(this), style.type, ptr3(style.points), count, ptr3(ptrArray), ptr3(offsetBuffer));
|
|
2402
2286
|
}
|
|
2403
2287
|
get canvas() {
|
|
2404
2288
|
return this.#owner;
|
|
2405
2289
|
}
|
|
2406
2290
|
set font(css) {
|
|
2407
|
-
|
|
2408
|
-
lib.symbols.canvas_set_font(
|
|
2291
|
+
const normalized = css.trim().toLowerCase();
|
|
2292
|
+
if (lib.symbols.canvas_set_font(ptrs.get(this), encoder.encode(`${normalized}\x00`))) {
|
|
2293
|
+
this.#currentState.fontCss = normalized;
|
|
2294
|
+
}
|
|
2409
2295
|
}
|
|
2410
2296
|
get font() {
|
|
2411
2297
|
return this.#currentState.fontCss;
|
|
@@ -2415,7 +2301,7 @@ class CanvasRenderingContext2D {
|
|
|
2415
2301
|
return;
|
|
2416
2302
|
let res = false;
|
|
2417
2303
|
if (typeof style === "string") {
|
|
2418
|
-
res = lib.symbols.canvas_set_fill_style(
|
|
2304
|
+
res = lib.symbols.canvas_set_fill_style(ptrs.get(this), encodeCString(style));
|
|
2419
2305
|
} else if (style instanceof CanvasGradient) {
|
|
2420
2306
|
res = this.#setStyleGradient(style, false);
|
|
2421
2307
|
}
|
|
@@ -2430,7 +2316,7 @@ class CanvasRenderingContext2D {
|
|
|
2430
2316
|
return;
|
|
2431
2317
|
let res = false;
|
|
2432
2318
|
if (typeof style === "string") {
|
|
2433
|
-
res = lib.symbols.canvas_set_stroke_style(
|
|
2319
|
+
res = lib.symbols.canvas_set_stroke_style(ptrs.get(this), encodeCString(style.trim()));
|
|
2434
2320
|
} else if (style instanceof CanvasGradient) {
|
|
2435
2321
|
res = this.#setStyleGradient(style, true);
|
|
2436
2322
|
}
|
|
@@ -2442,35 +2328,21 @@ class CanvasRenderingContext2D {
|
|
|
2442
2328
|
}
|
|
2443
2329
|
set lineWidth(width) {
|
|
2444
2330
|
let w = width < 1 ? 1 : width;
|
|
2445
|
-
lib.symbols.canvas_set_stroke_width(
|
|
2331
|
+
lib.symbols.canvas_set_stroke_width(ptrs.get(this), w);
|
|
2446
2332
|
this.#currentState.lineWidth = w;
|
|
2447
2333
|
}
|
|
2448
2334
|
get lineWidth() {
|
|
2449
2335
|
return this.#currentState.lineWidth;
|
|
2450
2336
|
}
|
|
2451
2337
|
set globalAlpha(a) {
|
|
2452
|
-
this.#currentState.globalAlpha = lib.symbols.canvas_set_global_alpha(
|
|
2338
|
+
this.#currentState.globalAlpha = lib.symbols.canvas_set_global_alpha(ptrs.get(this), a);
|
|
2453
2339
|
}
|
|
2454
2340
|
get globalAlpha() {
|
|
2455
2341
|
return this.#currentState.globalAlpha;
|
|
2456
2342
|
}
|
|
2457
2343
|
set imageSmoothingQuality(v) {
|
|
2458
|
-
let
|
|
2459
|
-
|
|
2460
|
-
case "low": {
|
|
2461
|
-
res = lib.symbols.canvas_set_image_smoothing_quality(ptrs3.get(this), 1);
|
|
2462
|
-
break;
|
|
2463
|
-
}
|
|
2464
|
-
case "medium": {
|
|
2465
|
-
res = lib.symbols.canvas_set_image_smoothing_quality(ptrs3.get(this), 2);
|
|
2466
|
-
break;
|
|
2467
|
-
}
|
|
2468
|
-
case "high": {
|
|
2469
|
-
res = lib.symbols.canvas_set_image_smoothing_quality(ptrs3.get(this), 3);
|
|
2470
|
-
break;
|
|
2471
|
-
}
|
|
2472
|
-
}
|
|
2473
|
-
if (res) {
|
|
2344
|
+
let smQuality = CanvasSmoothingQuality[v];
|
|
2345
|
+
if (lib.symbols.canvas_set_image_smoothing_quality(ptrs.get(this), smQuality)) {
|
|
2474
2346
|
this.#currentState.imageSmoothingQuality = v;
|
|
2475
2347
|
}
|
|
2476
2348
|
}
|
|
@@ -2478,13 +2350,15 @@ class CanvasRenderingContext2D {
|
|
|
2478
2350
|
return this.#currentState.imageSmoothingQuality;
|
|
2479
2351
|
}
|
|
2480
2352
|
set imageSmoothingEnabled(v) {
|
|
2481
|
-
|
|
2353
|
+
if (lib.symbols.canvas_set_image_smoothing_enabled(ptrs.get(this), v)) {
|
|
2354
|
+
this.#currentState.imageSmoothingEnabled = v;
|
|
2355
|
+
}
|
|
2482
2356
|
}
|
|
2483
2357
|
get imageSmoothingEnabled() {
|
|
2484
2358
|
return this.#currentState.imageSmoothingEnabled;
|
|
2485
2359
|
}
|
|
2486
2360
|
set filter(v) {
|
|
2487
|
-
if (lib.symbols.canvas_set_filter(
|
|
2361
|
+
if (lib.symbols.canvas_set_filter(ptrs.get(this), encoder.encode(`${v}\x00`))) {
|
|
2488
2362
|
this.#currentState.filter = v;
|
|
2489
2363
|
}
|
|
2490
2364
|
}
|
|
@@ -2492,56 +2366,60 @@ class CanvasRenderingContext2D {
|
|
|
2492
2366
|
return this.#currentState.filter;
|
|
2493
2367
|
}
|
|
2494
2368
|
set globalCompositeOperation(operation) {
|
|
2495
|
-
|
|
2369
|
+
const composite = CanvasBlendMode[operation];
|
|
2370
|
+
if (!composite)
|
|
2371
|
+
return;
|
|
2372
|
+
if (lib.symbols.canvas_set_composite_operation(ptrs.get(this), composite)) {
|
|
2496
2373
|
this.#currentState.compositeOperation = operation;
|
|
2374
|
+
}
|
|
2497
2375
|
}
|
|
2498
2376
|
get globalCompositeOperation() {
|
|
2499
2377
|
return this.#currentState.compositeOperation;
|
|
2500
2378
|
}
|
|
2501
2379
|
fillRect(x, y, w, h) {
|
|
2502
|
-
lib.symbols.canvas_fill_rect(
|
|
2380
|
+
lib.symbols.canvas_fill_rect(ptrs.get(this), x, y, w, h);
|
|
2503
2381
|
}
|
|
2504
2382
|
strokeRect(x, y, w, h) {
|
|
2505
|
-
lib.symbols.canvas_stroke_rect(
|
|
2383
|
+
lib.symbols.canvas_stroke_rect(ptrs.get(this), x, y, w, h);
|
|
2506
2384
|
}
|
|
2507
2385
|
clearRect(x, y, w, h) {
|
|
2508
|
-
lib.symbols.canvas_clear_rect(
|
|
2386
|
+
lib.symbols.canvas_clear_rect(ptrs.get(this), x, y, w, h);
|
|
2509
2387
|
}
|
|
2510
2388
|
fillText(text, x, y, maxWidth = -1) {
|
|
2511
|
-
lib.symbols.canvas_fill_text(
|
|
2389
|
+
lib.symbols.canvas_fill_text(ptrs.get(this), encoder.encode(`${text}\x00`), x, y, maxWidth);
|
|
2512
2390
|
}
|
|
2513
2391
|
strokeText(text, x, y, maxWidth = -1) {
|
|
2514
|
-
lib.symbols.canvas_stroke_text(
|
|
2392
|
+
lib.symbols.canvas_stroke_text(ptrs.get(this), encoder.encode(`${text}\x00`), x, y, maxWidth);
|
|
2515
2393
|
}
|
|
2516
2394
|
beginPath() {
|
|
2517
|
-
lib.symbols.canvas_path_begin(
|
|
2395
|
+
lib.symbols.canvas_path_begin(ptrs.get(this));
|
|
2518
2396
|
}
|
|
2519
2397
|
moveTo(x, y) {
|
|
2520
|
-
lib.symbols.canvas_path_move_to(
|
|
2398
|
+
lib.symbols.canvas_path_move_to(ptrs.get(this), x, y);
|
|
2521
2399
|
}
|
|
2522
2400
|
lineTo(x, y) {
|
|
2523
|
-
lib.symbols.canvas_path_line_to(
|
|
2401
|
+
lib.symbols.canvas_path_line_to(ptrs.get(this), x, y);
|
|
2524
2402
|
}
|
|
2525
2403
|
arc(x, y, radius, startAngle, endAngle) {
|
|
2526
|
-
lib.symbols.canvas_path_arc(
|
|
2404
|
+
lib.symbols.canvas_path_arc(ptrs.get(this), x, y, radius, startAngle, endAngle);
|
|
2527
2405
|
}
|
|
2528
2406
|
ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise = false) {
|
|
2529
|
-
lib.symbols.canvas_path_ellipse(
|
|
2407
|
+
lib.symbols.canvas_path_ellipse(ptrs.get(this), x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
|
|
2530
2408
|
}
|
|
2531
2409
|
arcTo(x1, y1, x2, y2, radius) {
|
|
2532
|
-
lib.symbols.canvas_path_arc_to(
|
|
2410
|
+
lib.symbols.canvas_path_arc_to(ptrs.get(this), x1, y1, x2, y2, radius);
|
|
2533
2411
|
}
|
|
2534
2412
|
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
2535
|
-
lib.symbols.canvas_path_bezier_to(
|
|
2413
|
+
lib.symbols.canvas_path_bezier_to(ptrs.get(this), cp1x, cp1y, cp2x, cp2y, x, y);
|
|
2536
2414
|
}
|
|
2537
2415
|
quadraticCurveTo(cpx, cpy, x, y) {
|
|
2538
|
-
lib.symbols.canvas_path_quad_to(
|
|
2416
|
+
lib.symbols.canvas_path_quad_to(ptrs.get(this), cpx, cpy, x, y);
|
|
2539
2417
|
}
|
|
2540
2418
|
closePath() {
|
|
2541
|
-
lib.symbols.canvas_path_close(
|
|
2419
|
+
lib.symbols.canvas_path_close(ptrs.get(this));
|
|
2542
2420
|
}
|
|
2543
2421
|
rect(x, y, width, height) {
|
|
2544
|
-
lib.symbols.canvas_path_rect(
|
|
2422
|
+
lib.symbols.canvas_path_rect(ptrs.get(this), x, y, width, height);
|
|
2545
2423
|
}
|
|
2546
2424
|
roundRect(x, y, width, height, radii) {
|
|
2547
2425
|
if (radii.constructor.name.toLowerCase().includes("array")) {
|
|
@@ -2549,47 +2427,35 @@ class CanvasRenderingContext2D {
|
|
|
2549
2427
|
if (arr.some(Number.isNaN))
|
|
2550
2428
|
return;
|
|
2551
2429
|
const len = arr.length;
|
|
2552
|
-
lib.symbols.canvas_path_roundrect_array(
|
|
2430
|
+
lib.symbols.canvas_path_roundrect_array(ptrs.get(this), x, y, width, height, ptr3(arr), len);
|
|
2553
2431
|
return;
|
|
2554
2432
|
} else {
|
|
2555
|
-
lib.symbols.canvas_path_roundrect(
|
|
2433
|
+
lib.symbols.canvas_path_roundrect(ptrs.get(this), x, y, width, height, radii);
|
|
2556
2434
|
}
|
|
2557
2435
|
}
|
|
2558
2436
|
fill(path) {
|
|
2559
|
-
|
|
2437
|
+
let _ptr = path ? ptrs.get(path) : null;
|
|
2438
|
+
lib.symbols.canvas_path_fill(ptrs.get(this), _ptr);
|
|
2560
2439
|
}
|
|
2561
2440
|
stroke(path) {
|
|
2562
|
-
|
|
2441
|
+
let _ptr = path ? ptrs.get(path) : null;
|
|
2442
|
+
lib.symbols.canvas_path_stroke(ptrs.get(this), _ptr);
|
|
2563
2443
|
}
|
|
2564
2444
|
set shadowBlur(blur) {
|
|
2565
|
-
lib.symbols.canvas_set_shadow_blur(
|
|
2445
|
+
lib.symbols.canvas_set_shadow_blur(ptrs.get(this), blur);
|
|
2566
2446
|
}
|
|
2567
2447
|
set shadowColor(col) {
|
|
2568
|
-
lib.symbols.canvas_set_shadow_color(
|
|
2448
|
+
lib.symbols.canvas_set_shadow_color(ptrs.get(this), encoder.encode(`${col}\x00`));
|
|
2569
2449
|
}
|
|
2570
2450
|
set shadowOffsetX(x) {
|
|
2571
|
-
lib.symbols.canvas_set_shadow_offsetX(
|
|
2451
|
+
lib.symbols.canvas_set_shadow_offsetX(ptrs.get(this), x);
|
|
2572
2452
|
}
|
|
2573
2453
|
set shadowOffsetY(y) {
|
|
2574
|
-
lib.symbols.canvas_set_shadow_offsetY(
|
|
2454
|
+
lib.symbols.canvas_set_shadow_offsetY(ptrs.get(this), y);
|
|
2575
2455
|
}
|
|
2576
2456
|
set lineJoin(joinType) {
|
|
2577
|
-
let
|
|
2578
|
-
|
|
2579
|
-
case "round": {
|
|
2580
|
-
res = lib.symbols.canvas_set_line_join(ptrs3.get(this), 1);
|
|
2581
|
-
break;
|
|
2582
|
-
}
|
|
2583
|
-
case "bevel": {
|
|
2584
|
-
res = lib.symbols.canvas_set_line_join(ptrs3.get(this), 2);
|
|
2585
|
-
break;
|
|
2586
|
-
}
|
|
2587
|
-
case "miter": {
|
|
2588
|
-
res = lib.symbols.canvas_set_line_join(ptrs3.get(this), 3);
|
|
2589
|
-
break;
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
if (res) {
|
|
2457
|
+
let ljType = CanvasLineJoin[joinType];
|
|
2458
|
+
if (lib.symbols.canvas_set_line_join(ptrs.get(this), ljType)) {
|
|
2593
2459
|
this.#currentState.lineJoin = joinType;
|
|
2594
2460
|
}
|
|
2595
2461
|
}
|
|
@@ -2601,41 +2467,41 @@ class CanvasRenderingContext2D {
|
|
|
2601
2467
|
const arr = new Float32Array(_arr);
|
|
2602
2468
|
const len = arr.length;
|
|
2603
2469
|
if (img instanceof Image) {
|
|
2604
|
-
lib.symbols.canvas_draw_image_imageType(
|
|
2470
|
+
lib.symbols.canvas_draw_image_imageType(ptrs.get(this), img.ptr, ptr3(arr), len);
|
|
2605
2471
|
return;
|
|
2606
2472
|
}
|
|
2607
2473
|
if (img instanceof Canvas) {
|
|
2608
|
-
lib.symbols.canvas_draw_image_canvasType(
|
|
2474
|
+
lib.symbols.canvas_draw_image_canvasType(ptrs.get(this), ptrs.get(img), ptr3(arr), len);
|
|
2609
2475
|
return;
|
|
2610
2476
|
}
|
|
2611
2477
|
throw new TypeError("Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(Image or Canvas)'.");
|
|
2612
2478
|
}
|
|
2613
2479
|
getImageData(x, y, w, h) {
|
|
2614
2480
|
const arr = new Uint8ClampedArray(w * h * 4);
|
|
2615
|
-
lib.symbols.canvas_get_image_data(
|
|
2481
|
+
lib.symbols.canvas_get_image_data(ptrs.get(this), x, y, w, h, ptr3(arr));
|
|
2616
2482
|
return new ImageData(arr, w, h);
|
|
2617
2483
|
}
|
|
2618
2484
|
putImageData(data, dx, dy, dirtyX = 0, dirtyY = 0, dirtyWidth = data.width, dirtyHeight = data.height) {
|
|
2619
2485
|
if (!(data instanceof ImageData)) {
|
|
2620
2486
|
throw new TypeError("Failed to execute 'putImageData' on 'CanvasRenderingContext2D': " + "parameter 1 is not of type 'ImageData'");
|
|
2621
2487
|
}
|
|
2622
|
-
lib.symbols.canvas_put_image_data(
|
|
2488
|
+
lib.symbols.canvas_put_image_data(ptrs.get(this), dx, dy, data.width, data.height, dirtyX, dirtyY, dirtyWidth, dirtyHeight, ptr3(data.data));
|
|
2623
2489
|
}
|
|
2624
2490
|
save() {
|
|
2625
2491
|
this.#savedState?.copyFrom(this.#currentState);
|
|
2626
|
-
lib.symbols.canvas_save(
|
|
2492
|
+
lib.symbols.canvas_save(ptrs.get(this));
|
|
2627
2493
|
}
|
|
2628
2494
|
restore() {
|
|
2629
2495
|
if (!this.#savedState)
|
|
2630
2496
|
return;
|
|
2631
2497
|
this.#currentState?.copyFrom(this.#savedState);
|
|
2632
|
-
lib.symbols.canvas_restore(
|
|
2498
|
+
lib.symbols.canvas_restore(ptrs.get(this));
|
|
2633
2499
|
}
|
|
2634
2500
|
translate(x, y) {
|
|
2635
|
-
lib.symbols.canvas_translate(
|
|
2501
|
+
lib.symbols.canvas_translate(ptrs.get(this), x, y);
|
|
2636
2502
|
}
|
|
2637
2503
|
rotate(deg) {
|
|
2638
|
-
lib.symbols.canvas_rotate(
|
|
2504
|
+
lib.symbols.canvas_rotate(ptrs.get(this), deg);
|
|
2639
2505
|
}
|
|
2640
2506
|
createConicGradient(...args) {
|
|
2641
2507
|
if (args.length < 3)
|
|
@@ -2654,18 +2520,18 @@ class CanvasRenderingContext2D {
|
|
|
2654
2520
|
}
|
|
2655
2521
|
getTransform() {
|
|
2656
2522
|
let arr = new Float32Array(16);
|
|
2657
|
-
lib.symbols.canvas_get_transform(
|
|
2523
|
+
lib.symbols.canvas_get_transform(ptrs.get(this), ptr3(arr));
|
|
2658
2524
|
return new DOMMatrix(arr);
|
|
2659
2525
|
}
|
|
2660
2526
|
setTransform(...args) {
|
|
2661
2527
|
if (args[0] instanceof DOMMatrix)
|
|
2662
|
-
lib.symbols.canvas_set_transform(
|
|
2528
|
+
lib.symbols.canvas_set_transform(ptrs.get(this), args[0].ptr);
|
|
2663
2529
|
if (args.length == 6) {
|
|
2664
2530
|
const mtx = new DOMMatrix([args[0], args[1], args[2], args[3], args[4], args[5]]);
|
|
2665
|
-
lib.symbols.canvas_set_transform(
|
|
2531
|
+
lib.symbols.canvas_set_transform(ptrs.get(this), mtx.ptr);
|
|
2666
2532
|
}
|
|
2667
2533
|
if (args.length == 16)
|
|
2668
|
-
lib.symbols.canvas_set_transform(
|
|
2534
|
+
lib.symbols.canvas_set_transform(ptrs.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);
|
|
2669
2535
|
}
|
|
2670
2536
|
transform(a, b, c, d, e, f) {
|
|
2671
2537
|
const tf = this.getTransform();
|
|
@@ -2674,7 +2540,7 @@ class CanvasRenderingContext2D {
|
|
|
2674
2540
|
this.setTransform(tf);
|
|
2675
2541
|
}
|
|
2676
2542
|
resetTransform() {
|
|
2677
|
-
lib.symbols.canvas_reset_transform(
|
|
2543
|
+
lib.symbols.canvas_reset_transform(ptrs.get(this));
|
|
2678
2544
|
}
|
|
2679
2545
|
setLineDash(lines) {
|
|
2680
2546
|
if (lines.constructor.name.toLowerCase().includes("array")) {
|
|
@@ -2687,7 +2553,7 @@ class CanvasRenderingContext2D {
|
|
|
2687
2553
|
const arr = new Float32Array(_a);
|
|
2688
2554
|
if (arr.some(Number.isNaN))
|
|
2689
2555
|
return;
|
|
2690
|
-
lib.symbols.canvas_set_line_dash(
|
|
2556
|
+
lib.symbols.canvas_set_line_dash(ptrs.get(this), ptr3(arr), arr.length, this.#currentState.lineDashOffset);
|
|
2691
2557
|
this.#currentState.lineDash = _a;
|
|
2692
2558
|
return;
|
|
2693
2559
|
}
|
|
@@ -2697,7 +2563,7 @@ class CanvasRenderingContext2D {
|
|
|
2697
2563
|
return this.#currentState.lineDash;
|
|
2698
2564
|
}
|
|
2699
2565
|
clip() {
|
|
2700
|
-
lib.symbols.canvas_path_clip(
|
|
2566
|
+
lib.symbols.canvas_path_clip(ptrs.get(this));
|
|
2701
2567
|
}
|
|
2702
2568
|
set lineDashOffset(v) {
|
|
2703
2569
|
if (this.#currentState.lineDash.length <= 0) {
|
|
@@ -2705,61 +2571,28 @@ class CanvasRenderingContext2D {
|
|
|
2705
2571
|
return;
|
|
2706
2572
|
}
|
|
2707
2573
|
const arr = new Float32Array(this.#currentState.lineDash);
|
|
2708
|
-
lib.symbols.canvas_set_line_dash(
|
|
2574
|
+
lib.symbols.canvas_set_line_dash(ptrs.get(this), ptr3(arr), arr.length, v);
|
|
2709
2575
|
this.#currentState.lineDashOffset = v;
|
|
2710
2576
|
}
|
|
2711
2577
|
set textBaseline(baseline) {
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
case "hanging":
|
|
2718
|
-
bl = 1;
|
|
2719
|
-
break;
|
|
2720
|
-
case "middle":
|
|
2721
|
-
bl = 2;
|
|
2722
|
-
break;
|
|
2723
|
-
case "alphabetic":
|
|
2724
|
-
bl = 3;
|
|
2725
|
-
break;
|
|
2726
|
-
case "ideographic":
|
|
2727
|
-
bl = 4;
|
|
2728
|
-
break;
|
|
2729
|
-
case "bottom":
|
|
2730
|
-
bl = 5;
|
|
2731
|
-
break;
|
|
2732
|
-
}
|
|
2733
|
-
if (bl != -1) {
|
|
2734
|
-
lib.symbols.canvas_set_text_baseline(ptrs3.get(this), bl);
|
|
2578
|
+
const bl = CanvasTextBaseline[baseline];
|
|
2579
|
+
if (!bl)
|
|
2580
|
+
return;
|
|
2581
|
+
if (lib.symbols.canvas_set_text_baseline(ptrs.get(this), bl)) {
|
|
2582
|
+
this.#currentState.textBaseline = baseline;
|
|
2735
2583
|
}
|
|
2736
2584
|
}
|
|
2737
2585
|
set textAlign(alignment) {
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
case "right":
|
|
2744
|
-
al = 1;
|
|
2745
|
-
break;
|
|
2746
|
-
case "center":
|
|
2747
|
-
al = 2;
|
|
2748
|
-
break;
|
|
2749
|
-
case "start":
|
|
2750
|
-
al = 3;
|
|
2751
|
-
break;
|
|
2752
|
-
case "end":
|
|
2753
|
-
al = 4;
|
|
2754
|
-
break;
|
|
2755
|
-
}
|
|
2756
|
-
if (al != -1) {
|
|
2757
|
-
lib.symbols.canvas_set_text_align(ptrs3.get(this), al);
|
|
2586
|
+
const al = CanvasTextAlignment[alignment];
|
|
2587
|
+
if (!al)
|
|
2588
|
+
return;
|
|
2589
|
+
if (lib.symbols.canvas_set_text_align(ptrs.get(this), al)) {
|
|
2590
|
+
this.#currentState.textAlign = alignment;
|
|
2758
2591
|
}
|
|
2759
2592
|
}
|
|
2760
2593
|
measureText(text) {
|
|
2761
2594
|
const pArr = new Float32Array(12);
|
|
2762
|
-
lib.symbols.canvas_measure_text(
|
|
2595
|
+
lib.symbols.canvas_measure_text(ptrs.get(this), encoder.encode(`${text}\x00`), ptr3(pArr));
|
|
2763
2596
|
return new TextMetrics(INTERNAL_TOKEN, pArr[0], pArr[1], pArr[2], pArr[3], pArr[4], pArr[5], pArr[6], pArr[7], pArr[8], pArr[9], pArr[10], pArr[11]);
|
|
2764
2597
|
}
|
|
2765
2598
|
constructor(iptr, cnv, args, token) {
|
|
@@ -2772,7 +2605,7 @@ class CanvasRenderingContext2D {
|
|
|
2772
2605
|
});
|
|
2773
2606
|
const renderContextPtr = lib.symbols.canvas_get_context2D(iptr, cb.ptr, desynchronized, alpha);
|
|
2774
2607
|
this.#owner = cnv;
|
|
2775
|
-
|
|
2608
|
+
ptrs.set(this, renderContextPtr);
|
|
2776
2609
|
}
|
|
2777
2610
|
}
|
|
2778
2611
|
{
|
|
@@ -2799,23 +2632,27 @@ class Canvas {
|
|
|
2799
2632
|
constructor(w = 1, h = 1, options) {
|
|
2800
2633
|
this.#dim[0] = w;
|
|
2801
2634
|
this.#dim[1] = h;
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2635
|
+
let ptr;
|
|
2636
|
+
if (Bun.isMainThread) {
|
|
2637
|
+
ptr = lib.symbols.canvas_create(w, h, options ? options.gpu : true);
|
|
2638
|
+
} else {
|
|
2639
|
+
ptr = lib.symbols.canvas_create(w, h, false);
|
|
2640
|
+
}
|
|
2641
|
+
ptrs.set(this, ptr);
|
|
2805
2642
|
canvasFinalizationRegistry.register(this, ptr);
|
|
2806
2643
|
}
|
|
2807
2644
|
get _ptr() {
|
|
2808
|
-
return
|
|
2645
|
+
return ptrs.get(this);
|
|
2809
2646
|
}
|
|
2810
2647
|
set width(v) {
|
|
2811
2648
|
this.#dim[0] = Number.parseInt(v);
|
|
2812
2649
|
this.#rCapture.cb();
|
|
2813
|
-
lib.symbols.canvas_resize(
|
|
2650
|
+
lib.symbols.canvas_resize(ptrs.get(this), this.#dim[0], this.#dim[1]);
|
|
2814
2651
|
}
|
|
2815
2652
|
set height(v) {
|
|
2816
2653
|
this.#dim[1] = Number.parseInt(v);
|
|
2817
2654
|
this.#rCapture.cb();
|
|
2818
|
-
lib.symbols.canvas_resize(
|
|
2655
|
+
lib.symbols.canvas_resize(ptrs.get(this), this.#dim[0], this.#dim[1]);
|
|
2819
2656
|
}
|
|
2820
2657
|
get width() {
|
|
2821
2658
|
return this.#dim[0];
|
|
@@ -2825,7 +2662,7 @@ class Canvas {
|
|
|
2825
2662
|
}
|
|
2826
2663
|
getContext(contextType, args) {
|
|
2827
2664
|
if (contextType == "2d") {
|
|
2828
|
-
return new CanvasRenderingContext2D(
|
|
2665
|
+
return new CanvasRenderingContext2D(ptrs.get(this), this, args, INTERNAL_TOKEN);
|
|
2829
2666
|
}
|
|
2830
2667
|
}
|
|
2831
2668
|
getBoundingClientRect() {
|
|
@@ -2861,43 +2698,45 @@ import { ptr as ptr4 } from "bun:ffi";
|
|
|
2861
2698
|
var p2dFinalizationRegistry = new FinalizationRegistry((ptr) => {
|
|
2862
2699
|
lib.symbols.path2d_destroy(ptr);
|
|
2863
2700
|
});
|
|
2864
|
-
var ptrs4 = new WeakMap;
|
|
2865
2701
|
|
|
2866
2702
|
class Path2D {
|
|
2867
2703
|
constructor(path) {
|
|
2868
2704
|
if (path && path instanceof Path2D) {
|
|
2869
|
-
let
|
|
2870
|
-
|
|
2705
|
+
let ptr = ptrs.get(path);
|
|
2706
|
+
if (!ptr)
|
|
2707
|
+
return;
|
|
2708
|
+
let _ptr = lib.symbols.path2d_create_from_copy(ptr);
|
|
2709
|
+
ptrs.set(this, _ptr);
|
|
2871
2710
|
p2dFinalizationRegistry.register(this, _ptr);
|
|
2872
2711
|
} else {
|
|
2873
2712
|
let _ptr = lib.symbols.path2d_create();
|
|
2874
|
-
|
|
2713
|
+
ptrs.set(this, _ptr);
|
|
2875
2714
|
p2dFinalizationRegistry.register(this, _ptr);
|
|
2876
2715
|
}
|
|
2877
2716
|
}
|
|
2878
2717
|
moveTo(x, y) {
|
|
2879
|
-
lib.symbols.path2d_move_to(
|
|
2718
|
+
lib.symbols.path2d_move_to(ptrs.get(this), x, y);
|
|
2880
2719
|
}
|
|
2881
2720
|
lineTo(x, y) {
|
|
2882
|
-
lib.symbols.path2d_line_to(
|
|
2721
|
+
lib.symbols.path2d_line_to(ptrs.get(this), x, y);
|
|
2883
2722
|
}
|
|
2884
2723
|
arc(x, y, radius, startAngle, endAngle) {
|
|
2885
|
-
lib.symbols.path2d_arc(
|
|
2724
|
+
lib.symbols.path2d_arc(ptrs.get(this), x, y, radius, startAngle, endAngle);
|
|
2886
2725
|
}
|
|
2887
2726
|
ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise = false) {
|
|
2888
|
-
lib.symbols.path2d_ellipse(
|
|
2727
|
+
lib.symbols.path2d_ellipse(ptrs.get(this), x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
|
|
2889
2728
|
}
|
|
2890
2729
|
arcTo(x1, y1, x2, y2, radius) {
|
|
2891
|
-
lib.symbols.path2d_arc_to(
|
|
2730
|
+
lib.symbols.path2d_arc_to(ptrs.get(this), x1, y1, x2, y2, radius);
|
|
2892
2731
|
}
|
|
2893
2732
|
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
2894
|
-
lib.symbols.path2d_bezier_to(
|
|
2733
|
+
lib.symbols.path2d_bezier_to(ptrs.get(this), cp1x, cp1y, cp2x, cp2y, x, y);
|
|
2895
2734
|
}
|
|
2896
2735
|
quadraticCurveTo(cpx, cpy, x, y) {
|
|
2897
|
-
lib.symbols.path2d_quad_to(
|
|
2736
|
+
lib.symbols.path2d_quad_to(ptrs.get(this), cpx, cpy, x, y);
|
|
2898
2737
|
}
|
|
2899
2738
|
rect(x, y, width, height) {
|
|
2900
|
-
lib.symbols.path2d_rect(
|
|
2739
|
+
lib.symbols.path2d_rect(ptrs.get(this), x, y, width, height);
|
|
2901
2740
|
}
|
|
2902
2741
|
roundRect(x, y, width, height, radii) {
|
|
2903
2742
|
if (radii.constructor.name.toLowerCase().includes("array")) {
|
|
@@ -2905,25 +2744,22 @@ class Path2D {
|
|
|
2905
2744
|
if (arr.some(Number.isNaN))
|
|
2906
2745
|
return;
|
|
2907
2746
|
const len = arr.length;
|
|
2908
|
-
lib.symbols.path2d_roundrect_array(
|
|
2747
|
+
lib.symbols.path2d_roundrect_array(ptrs.get(this), x, y, width, height, ptr4(arr), len);
|
|
2909
2748
|
return;
|
|
2910
2749
|
} else {
|
|
2911
|
-
lib.symbols.path2d_rect(
|
|
2750
|
+
lib.symbols.path2d_rect(ptrs.get(this), x, y, width, height, radii);
|
|
2912
2751
|
}
|
|
2913
2752
|
}
|
|
2914
2753
|
closePath() {
|
|
2915
|
-
lib.symbols.path2d_close(
|
|
2916
|
-
}
|
|
2917
|
-
get ptr() {
|
|
2918
|
-
return ptrs4.get(this);
|
|
2754
|
+
lib.symbols.path2d_close(ptrs.get(this));
|
|
2919
2755
|
}
|
|
2920
2756
|
}
|
|
2921
|
-
var
|
|
2922
|
-
for (const key of Object.getOwnPropertyNames(
|
|
2923
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
2757
|
+
var proto2 = Path2D.prototype;
|
|
2758
|
+
for (const key of Object.getOwnPropertyNames(proto2)) {
|
|
2759
|
+
const desc = Object.getOwnPropertyDescriptor(proto2, key);
|
|
2924
2760
|
if (key == "constructor") {
|
|
2925
2761
|
desc && (desc.value.toString = () => {
|
|
2926
|
-
return `function ${
|
|
2762
|
+
return `function ${proto2.constructor.name}() { [native code] }`;
|
|
2927
2763
|
});
|
|
2928
2764
|
continue;
|
|
2929
2765
|
}
|
|
@@ -2961,206 +2797,642 @@ self.onmessage = (msg)=>{
|
|
|
2961
2797
|
|
|
2962
2798
|
`;
|
|
2963
2799
|
|
|
2964
|
-
// BunCanvas/
|
|
2965
|
-
var
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2800
|
+
// BunCanvas/internal/window/glfwKeyMap.ts
|
|
2801
|
+
var GLFW_KEY_MAP = {
|
|
2802
|
+
"-1": "Unknown",
|
|
2803
|
+
32: " ",
|
|
2804
|
+
39: "'",
|
|
2805
|
+
44: ",",
|
|
2806
|
+
45: "-",
|
|
2807
|
+
46: ".",
|
|
2808
|
+
47: "/",
|
|
2809
|
+
48: "0",
|
|
2810
|
+
49: "1",
|
|
2811
|
+
50: "2",
|
|
2812
|
+
51: "3",
|
|
2813
|
+
52: "4",
|
|
2814
|
+
53: "5",
|
|
2815
|
+
54: "6",
|
|
2816
|
+
55: "7",
|
|
2817
|
+
56: "8",
|
|
2818
|
+
57: "9",
|
|
2819
|
+
59: ";",
|
|
2820
|
+
61: "=",
|
|
2821
|
+
65: "a",
|
|
2822
|
+
66: "b",
|
|
2823
|
+
67: "c",
|
|
2824
|
+
68: "d",
|
|
2825
|
+
69: "e",
|
|
2826
|
+
70: "f",
|
|
2827
|
+
71: "g",
|
|
2828
|
+
72: "h",
|
|
2829
|
+
73: "i",
|
|
2830
|
+
74: "j",
|
|
2831
|
+
75: "k",
|
|
2832
|
+
76: "l",
|
|
2833
|
+
77: "m",
|
|
2834
|
+
78: "n",
|
|
2835
|
+
79: "o",
|
|
2836
|
+
80: "p",
|
|
2837
|
+
81: "q",
|
|
2838
|
+
82: "r",
|
|
2839
|
+
83: "s",
|
|
2840
|
+
84: "t",
|
|
2841
|
+
85: "u",
|
|
2842
|
+
86: "v",
|
|
2843
|
+
87: "w",
|
|
2844
|
+
88: "x",
|
|
2845
|
+
89: "y",
|
|
2846
|
+
90: "z",
|
|
2847
|
+
91: "[",
|
|
2848
|
+
92: "\\",
|
|
2849
|
+
93: "]",
|
|
2850
|
+
96: "`",
|
|
2851
|
+
161: "World1",
|
|
2852
|
+
162: "World2",
|
|
2853
|
+
256: "Escape",
|
|
2854
|
+
257: "Enter",
|
|
2855
|
+
258: "Tab",
|
|
2856
|
+
259: "Backspace",
|
|
2857
|
+
260: "Insert",
|
|
2858
|
+
261: "Delete",
|
|
2859
|
+
262: "ArrowRight",
|
|
2860
|
+
263: "ArrowLeft",
|
|
2861
|
+
264: "ArrowDown",
|
|
2862
|
+
265: "ArrowUp",
|
|
2863
|
+
266: "PageUp",
|
|
2864
|
+
267: "PageDown",
|
|
2865
|
+
268: "Home",
|
|
2866
|
+
269: "End",
|
|
2867
|
+
280: "CapsLock",
|
|
2868
|
+
281: "ScrollLock",
|
|
2869
|
+
282: "NumLock",
|
|
2870
|
+
283: "PrintScreen",
|
|
2871
|
+
284: "Pause",
|
|
2872
|
+
290: "F1",
|
|
2873
|
+
291: "F2",
|
|
2874
|
+
292: "F3",
|
|
2875
|
+
293: "F4",
|
|
2876
|
+
294: "F5",
|
|
2877
|
+
295: "F6",
|
|
2878
|
+
296: "F7",
|
|
2879
|
+
297: "F8",
|
|
2880
|
+
298: "F9",
|
|
2881
|
+
299: "F10",
|
|
2882
|
+
300: "F11",
|
|
2883
|
+
301: "F12",
|
|
2884
|
+
302: "F13",
|
|
2885
|
+
303: "F14",
|
|
2886
|
+
304: "F15",
|
|
2887
|
+
305: "F16",
|
|
2888
|
+
306: "F17",
|
|
2889
|
+
307: "F18",
|
|
2890
|
+
308: "F19",
|
|
2891
|
+
309: "F20",
|
|
2892
|
+
310: "F21",
|
|
2893
|
+
311: "F22",
|
|
2894
|
+
312: "F23",
|
|
2895
|
+
313: "F24",
|
|
2896
|
+
314: "F25",
|
|
2897
|
+
320: "0",
|
|
2898
|
+
321: "1",
|
|
2899
|
+
322: "2",
|
|
2900
|
+
323: "3",
|
|
2901
|
+
324: "4",
|
|
2902
|
+
325: "5",
|
|
2903
|
+
326: "6",
|
|
2904
|
+
327: "7",
|
|
2905
|
+
328: "8",
|
|
2906
|
+
329: "9",
|
|
2907
|
+
330: ".",
|
|
2908
|
+
331: "/",
|
|
2909
|
+
332: "*",
|
|
2910
|
+
333: "-",
|
|
2911
|
+
334: "+",
|
|
2912
|
+
335: "Enter",
|
|
2913
|
+
336: "=",
|
|
2914
|
+
340: "Shift",
|
|
2915
|
+
341: "Control",
|
|
2916
|
+
342: "Alt",
|
|
2917
|
+
343: "Meta",
|
|
2918
|
+
344: "Shift",
|
|
2919
|
+
345: "Control",
|
|
2920
|
+
346: "Alt",
|
|
2921
|
+
347: "Meta",
|
|
2922
|
+
348: "ContextMenu"
|
|
2923
|
+
};
|
|
2924
|
+
var GLFW_KEY_MAP_SHIFT = {
|
|
2925
|
+
"-1": "Unknown",
|
|
2926
|
+
32: " ",
|
|
2927
|
+
39: '"',
|
|
2928
|
+
44: "<",
|
|
2929
|
+
45: "_",
|
|
2930
|
+
46: ">",
|
|
2931
|
+
47: "?",
|
|
2932
|
+
48: ")",
|
|
2933
|
+
49: "!",
|
|
2934
|
+
50: "@",
|
|
2935
|
+
51: "#",
|
|
2936
|
+
52: "$",
|
|
2937
|
+
53: "%",
|
|
2938
|
+
54: "^",
|
|
2939
|
+
55: "&",
|
|
2940
|
+
56: "*",
|
|
2941
|
+
57: "(",
|
|
2942
|
+
59: ":",
|
|
2943
|
+
61: "+",
|
|
2944
|
+
65: "A",
|
|
2945
|
+
66: "B",
|
|
2946
|
+
67: "C",
|
|
2947
|
+
68: "D",
|
|
2948
|
+
69: "E",
|
|
2949
|
+
70: "F",
|
|
2950
|
+
71: "G",
|
|
2951
|
+
72: "H",
|
|
2952
|
+
73: "I",
|
|
2953
|
+
74: "J",
|
|
2954
|
+
75: "K",
|
|
2955
|
+
76: "L",
|
|
2956
|
+
77: "M",
|
|
2957
|
+
78: "N",
|
|
2958
|
+
79: "O",
|
|
2959
|
+
80: "P",
|
|
2960
|
+
81: "Q",
|
|
2961
|
+
82: "R",
|
|
2962
|
+
83: "S",
|
|
2963
|
+
84: "T",
|
|
2964
|
+
85: "U",
|
|
2965
|
+
86: "V",
|
|
2966
|
+
87: "W",
|
|
2967
|
+
88: "X",
|
|
2968
|
+
89: "Y",
|
|
2969
|
+
90: "Z",
|
|
2970
|
+
91: "{",
|
|
2971
|
+
92: "|",
|
|
2972
|
+
93: "}",
|
|
2973
|
+
96: "~",
|
|
2974
|
+
161: "World1",
|
|
2975
|
+
162: "World2",
|
|
2976
|
+
256: "Escape",
|
|
2977
|
+
257: "Enter",
|
|
2978
|
+
258: "Tab",
|
|
2979
|
+
259: "Backspace",
|
|
2980
|
+
260: "Insert",
|
|
2981
|
+
261: "Delete",
|
|
2982
|
+
262: "ArrowRight",
|
|
2983
|
+
263: "ArrowLeft",
|
|
2984
|
+
264: "ArrowDown",
|
|
2985
|
+
265: "ArrowUp",
|
|
2986
|
+
266: "PageUp",
|
|
2987
|
+
267: "PageDown",
|
|
2988
|
+
268: "Home",
|
|
2989
|
+
269: "End",
|
|
2990
|
+
280: "CapsLock",
|
|
2991
|
+
281: "ScrollLock",
|
|
2992
|
+
282: "NumLock",
|
|
2993
|
+
283: "PrintScreen",
|
|
2994
|
+
284: "Pause",
|
|
2995
|
+
290: "F1",
|
|
2996
|
+
291: "F2",
|
|
2997
|
+
292: "F3",
|
|
2998
|
+
293: "F4",
|
|
2999
|
+
294: "F5",
|
|
3000
|
+
295: "F6",
|
|
3001
|
+
296: "F7",
|
|
3002
|
+
297: "F8",
|
|
3003
|
+
298: "F9",
|
|
3004
|
+
299: "F10",
|
|
3005
|
+
300: "F11",
|
|
3006
|
+
301: "F12",
|
|
3007
|
+
302: "F13",
|
|
3008
|
+
303: "F14",
|
|
3009
|
+
304: "F15",
|
|
3010
|
+
305: "F16",
|
|
3011
|
+
306: "F17",
|
|
3012
|
+
307: "F18",
|
|
3013
|
+
308: "F19",
|
|
3014
|
+
309: "F20",
|
|
3015
|
+
310: "F21",
|
|
3016
|
+
311: "F22",
|
|
3017
|
+
312: "F23",
|
|
3018
|
+
313: "F24",
|
|
3019
|
+
314: "F25",
|
|
3020
|
+
320: "0",
|
|
3021
|
+
321: "1",
|
|
3022
|
+
322: "2",
|
|
3023
|
+
323: "3",
|
|
3024
|
+
324: "4",
|
|
3025
|
+
325: "5",
|
|
3026
|
+
326: "6",
|
|
3027
|
+
327: "7",
|
|
3028
|
+
328: "8",
|
|
3029
|
+
329: "9",
|
|
3030
|
+
330: ".",
|
|
3031
|
+
331: "/",
|
|
3032
|
+
332: "*",
|
|
3033
|
+
333: "-",
|
|
3034
|
+
334: "+",
|
|
3035
|
+
335: "Enter",
|
|
3036
|
+
336: "=",
|
|
3037
|
+
340: "Shift",
|
|
3038
|
+
341: "Control",
|
|
3039
|
+
342: "Alt",
|
|
3040
|
+
343: "Meta",
|
|
3041
|
+
344: "Shift",
|
|
3042
|
+
345: "Control",
|
|
3043
|
+
346: "Alt",
|
|
3044
|
+
347: "Meta",
|
|
3045
|
+
348: "ContextMenu"
|
|
3046
|
+
};
|
|
3047
|
+
var GLFW_CODE_MAP = {
|
|
3048
|
+
"-1": "Unknown",
|
|
3049
|
+
32: "Space",
|
|
3050
|
+
39: "Quote",
|
|
3051
|
+
44: "Comma",
|
|
3052
|
+
45: "Minus",
|
|
3053
|
+
46: "Period",
|
|
3054
|
+
47: "Slash",
|
|
3055
|
+
48: "Digit0",
|
|
3056
|
+
49: "Digit1",
|
|
3057
|
+
50: "Digit2",
|
|
3058
|
+
51: "Digit3",
|
|
3059
|
+
52: "Digit4",
|
|
3060
|
+
53: "Digit5",
|
|
3061
|
+
54: "Digit6",
|
|
3062
|
+
55: "Digit7",
|
|
3063
|
+
56: "Digit8",
|
|
3064
|
+
57: "Digit9",
|
|
3065
|
+
59: "Semicolon",
|
|
3066
|
+
61: "Equal",
|
|
3067
|
+
65: "KeyA",
|
|
3068
|
+
66: "KeyB",
|
|
3069
|
+
67: "KeyC",
|
|
3070
|
+
68: "KeyD",
|
|
3071
|
+
69: "KeyE",
|
|
3072
|
+
70: "KeyF",
|
|
3073
|
+
71: "KeyG",
|
|
3074
|
+
72: "KeyH",
|
|
3075
|
+
73: "KeyI",
|
|
3076
|
+
74: "KeyJ",
|
|
3077
|
+
75: "KeyK",
|
|
3078
|
+
76: "KeyL",
|
|
3079
|
+
77: "KeyM",
|
|
3080
|
+
78: "KeyN",
|
|
3081
|
+
79: "KeyO",
|
|
3082
|
+
80: "KeyP",
|
|
3083
|
+
81: "KeyQ",
|
|
3084
|
+
82: "KeyR",
|
|
3085
|
+
83: "KeyS",
|
|
3086
|
+
84: "KeyT",
|
|
3087
|
+
85: "KeyU",
|
|
3088
|
+
86: "KeyV",
|
|
3089
|
+
87: "KeyW",
|
|
3090
|
+
88: "KeyX",
|
|
3091
|
+
89: "KeyY",
|
|
3092
|
+
90: "KeyZ",
|
|
3093
|
+
91: "BracketLeft",
|
|
3094
|
+
92: "Backslash",
|
|
3095
|
+
93: "BracketRight",
|
|
3096
|
+
96: "Backquote",
|
|
3097
|
+
161: "IntlBackslash",
|
|
3098
|
+
256: "Escape",
|
|
3099
|
+
257: "Enter",
|
|
3100
|
+
258: "Tab",
|
|
3101
|
+
259: "Backspace",
|
|
3102
|
+
260: "Insert",
|
|
3103
|
+
261: "Delete",
|
|
3104
|
+
262: "ArrowRight",
|
|
3105
|
+
263: "ArrowLeft",
|
|
3106
|
+
264: "ArrowDown",
|
|
3107
|
+
265: "ArrowUp",
|
|
3108
|
+
266: "PageUp",
|
|
3109
|
+
267: "PageDown",
|
|
3110
|
+
268: "Home",
|
|
3111
|
+
269: "End",
|
|
3112
|
+
280: "CapsLock",
|
|
3113
|
+
281: "ScrollLock",
|
|
3114
|
+
282: "NumLock",
|
|
3115
|
+
283: "PrintScreen",
|
|
3116
|
+
284: "Pause",
|
|
3117
|
+
290: "F1",
|
|
3118
|
+
291: "F2",
|
|
3119
|
+
292: "F3",
|
|
3120
|
+
293: "F4",
|
|
3121
|
+
294: "F5",
|
|
3122
|
+
295: "F6",
|
|
3123
|
+
296: "F7",
|
|
3124
|
+
297: "F8",
|
|
3125
|
+
298: "F9",
|
|
3126
|
+
299: "F10",
|
|
3127
|
+
300: "F11",
|
|
3128
|
+
301: "F12",
|
|
3129
|
+
302: "F13",
|
|
3130
|
+
303: "F14",
|
|
3131
|
+
304: "F15",
|
|
3132
|
+
305: "F16",
|
|
3133
|
+
306: "F17",
|
|
3134
|
+
307: "F18",
|
|
3135
|
+
308: "F19",
|
|
3136
|
+
309: "F20",
|
|
3137
|
+
310: "F21",
|
|
3138
|
+
311: "F22",
|
|
3139
|
+
312: "F23",
|
|
3140
|
+
313: "F24",
|
|
3141
|
+
314: "F25",
|
|
3142
|
+
320: "Numpad0",
|
|
3143
|
+
321: "Numpad1",
|
|
3144
|
+
322: "Numpad2",
|
|
3145
|
+
323: "Numpad3",
|
|
3146
|
+
324: "Numpad4",
|
|
3147
|
+
325: "Numpad5",
|
|
3148
|
+
326: "Numpad6",
|
|
3149
|
+
327: "Numpad7",
|
|
3150
|
+
328: "Numpad8",
|
|
3151
|
+
329: "Numpad9",
|
|
3152
|
+
330: "NumpadDecimal",
|
|
3153
|
+
331: "NumpadDivide",
|
|
3154
|
+
332: "NumpadMultiply",
|
|
3155
|
+
333: "NumpadSubtract",
|
|
3156
|
+
334: "NumpadAdd",
|
|
3157
|
+
335: "NumpadEnter",
|
|
3158
|
+
336: "NumpadEqual",
|
|
3159
|
+
340: "ShiftLeft",
|
|
3160
|
+
341: "ControlLeft",
|
|
3161
|
+
342: "AltLeft",
|
|
3162
|
+
343: "MetaLeft",
|
|
3163
|
+
344: "ShiftRight",
|
|
3164
|
+
345: "ControlRight",
|
|
3165
|
+
346: "AltRight",
|
|
3166
|
+
347: "MetaRight",
|
|
3167
|
+
348: "ContextMenu"
|
|
3168
|
+
};
|
|
3169
|
+
|
|
3170
|
+
// BunCanvas/src/Window.ts
|
|
3171
|
+
var requestedFrames = [];
|
|
3172
|
+
var render_thread;
|
|
3173
|
+
if (Bun.isMainThread) {
|
|
3174
|
+
lib.symbols.glfw_init();
|
|
3175
|
+
if (process.platform !== "darwin") {
|
|
3176
|
+
render_thread = new Worker(URL.createObjectURL(new Blob([WindowThread_default], { type: "application/javascript" })), { ref: false });
|
|
3177
|
+
}
|
|
3178
|
+
lib.symbols.canvas_init_gpu_context();
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
class Window extends EventTarget {
|
|
3182
|
+
#setHandler(type, current, next) {
|
|
3183
|
+
if (current) {
|
|
3184
|
+
this.removeEventListener(type, current);
|
|
3185
|
+
}
|
|
3186
|
+
if (next) {
|
|
3187
|
+
this.addEventListener(type, next);
|
|
3188
|
+
}
|
|
3189
|
+
return next;
|
|
3190
|
+
}
|
|
3191
|
+
#resizeHandler = null;
|
|
3192
|
+
#mousemoveHandler = null;
|
|
3193
|
+
#mousedownHandler = null;
|
|
3194
|
+
#mouseupHandler = null;
|
|
3195
|
+
#clickHandler = null;
|
|
3196
|
+
#keydownHandler = null;
|
|
3197
|
+
#keyupHandler = null;
|
|
3198
|
+
#wheelHandler = null;
|
|
3199
|
+
get onresize() {
|
|
3200
|
+
return this.#resizeHandler;
|
|
3201
|
+
}
|
|
3202
|
+
set onresize(fn) {
|
|
3203
|
+
this.#resizeHandler = this.#setHandler("resize", this.#resizeHandler, fn);
|
|
3204
|
+
}
|
|
3205
|
+
get onmousemove() {
|
|
3206
|
+
return this.#mousemoveHandler;
|
|
3207
|
+
}
|
|
3208
|
+
set onmousemove(fn) {
|
|
3209
|
+
this.#mousemoveHandler = this.#setHandler("mousemove", this.#mousemoveHandler, fn);
|
|
3210
|
+
}
|
|
3211
|
+
get onmousedown() {
|
|
3212
|
+
return this.#mousedownHandler;
|
|
3213
|
+
}
|
|
3214
|
+
set onmousedown(fn) {
|
|
3215
|
+
this.#mousedownHandler = this.#setHandler("mousedown", this.#mousedownHandler, fn);
|
|
3216
|
+
}
|
|
3217
|
+
get onmouseup() {
|
|
3218
|
+
return this.#mouseupHandler;
|
|
3219
|
+
}
|
|
3220
|
+
set onmouseup(fn) {
|
|
3221
|
+
this.#mouseupHandler = this.#setHandler("mouseup", this.#mouseupHandler, fn);
|
|
3222
|
+
}
|
|
3223
|
+
get onclick() {
|
|
3224
|
+
return this.#clickHandler;
|
|
3225
|
+
}
|
|
3226
|
+
set onclick(fn) {
|
|
3227
|
+
this.#clickHandler = this.#setHandler("click", this.#clickHandler, fn);
|
|
3228
|
+
}
|
|
3229
|
+
get onkeydown() {
|
|
3230
|
+
return this.#keydownHandler;
|
|
3231
|
+
}
|
|
3232
|
+
set onkeydown(fn) {
|
|
3233
|
+
this.#keydownHandler = this.#setHandler("keydown", this.#keydownHandler, fn);
|
|
3234
|
+
}
|
|
3235
|
+
get onkeyup() {
|
|
3236
|
+
return this.#keyupHandler;
|
|
3237
|
+
}
|
|
3238
|
+
set onkeyup(fn) {
|
|
3239
|
+
this.#keyupHandler = this.#setHandler("keyup", this.#keyupHandler, fn);
|
|
3240
|
+
}
|
|
3241
|
+
get onwheel() {
|
|
3242
|
+
return this.#wheelHandler;
|
|
3243
|
+
}
|
|
3244
|
+
set onwheel(fn) {
|
|
3245
|
+
this.#wheelHandler = this.#setHandler("wheel", this.#wheelHandler, fn);
|
|
3246
|
+
}
|
|
3247
|
+
get onfocus() {
|
|
3248
|
+
return this.#wheelHandler;
|
|
3249
|
+
}
|
|
3250
|
+
set onfocus(fn) {
|
|
3251
|
+
this.#wheelHandler = this.#setHandler("focus", this.#wheelHandler, fn);
|
|
3252
|
+
}
|
|
3253
|
+
get onblur() {
|
|
3254
|
+
return this.#wheelHandler;
|
|
3255
|
+
}
|
|
3256
|
+
set onblur(fn) {
|
|
3257
|
+
this.#wheelHandler = this.#setHandler("blur", this.#wheelHandler, fn);
|
|
3258
|
+
}
|
|
3259
|
+
#wPropertiesViewer = new Int32Array(toArrayBuffer(lib.symbols.get_wPropertiesViewer(), 0, 4 * 4));
|
|
2984
3260
|
#mMoveViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mMoveViewer(), 0, 9 * 8));
|
|
2985
3261
|
#mClickViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mClickViewer(), 0, 9 * 8));
|
|
2986
3262
|
#mDownViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mDownViewer(), 0, 9 * 8));
|
|
2987
3263
|
#mUpViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mUpViewer(), 0, 9 * 8));
|
|
2988
3264
|
#kDownViewer = new Int32Array(toArrayBuffer(lib.symbols.get_kDownViewer(), 0, 7 * 4));
|
|
2989
3265
|
#kUpViewer = new Int32Array(toArrayBuffer(lib.symbols.get_kUpViewer(), 0, 7 * 4));
|
|
3266
|
+
#wFocusBlurViewer = new Int32Array(toArrayBuffer(lib.symbols.get_wFocusBlurViewer(), 0, 2 * 4));
|
|
2990
3267
|
#mWheelViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mWheelViewer(), 0, 5 * 8));
|
|
2991
|
-
#
|
|
2992
|
-
|
|
2993
|
-
|
|
3268
|
+
#getGlfwKeyLocation(kcode) {
|
|
3269
|
+
if (kcode >= 320 && kcode <= 336) {
|
|
3270
|
+
return KeyboardEvent.DOM_KEY_LOCATION_NUMPAD;
|
|
3271
|
+
}
|
|
3272
|
+
if (kcode >= 340 && kcode <= 343) {
|
|
3273
|
+
return KeyboardEvent.DOM_KEY_LOCATION_LEFT;
|
|
3274
|
+
}
|
|
3275
|
+
if (kcode >= 344 && kcode <= 347) {
|
|
3276
|
+
return KeyboardEvent.DOM_KEY_LOCATION_RIGHT;
|
|
3277
|
+
}
|
|
3278
|
+
return KeyboardEvent.DOM_KEY_LOCATION_STANDARD;
|
|
3279
|
+
}
|
|
3280
|
+
#createKeyboardEvent(type, viewer) {
|
|
3281
|
+
const repeat = Boolean(viewer[1]);
|
|
3282
|
+
const kcode = viewer[2];
|
|
3283
|
+
const shiftKey = Boolean(viewer[3]);
|
|
3284
|
+
const ctrlKey = Boolean(viewer[4]);
|
|
3285
|
+
const altKey = Boolean(viewer[5]);
|
|
3286
|
+
const metaKey = Boolean(viewer[6]);
|
|
3287
|
+
const key = shiftKey ? GLFW_KEY_MAP_SHIFT[kcode] ?? "Unknown" : GLFW_KEY_MAP[kcode] ?? "Unknown";
|
|
3288
|
+
const code = GLFW_CODE_MAP[kcode] ?? "Unknown";
|
|
3289
|
+
return new KeyboardEvent(type, {
|
|
3290
|
+
key,
|
|
3291
|
+
code,
|
|
3292
|
+
location: this.#getGlfwKeyLocation(Number(kcode)),
|
|
3293
|
+
repeat,
|
|
3294
|
+
shiftKey,
|
|
3295
|
+
ctrlKey,
|
|
3296
|
+
altKey,
|
|
3297
|
+
metaKey,
|
|
3298
|
+
bubbles: true,
|
|
3299
|
+
cancelable: true
|
|
3300
|
+
});
|
|
3301
|
+
}
|
|
2994
3302
|
#processEvents() {
|
|
2995
|
-
if (this.#wPropertiesViewer[0]
|
|
3303
|
+
if (this.#wPropertiesViewer[0] !== 0) {
|
|
2996
3304
|
this.#wPropertiesViewer[0] = 0;
|
|
2997
|
-
const details = new Event("resize"
|
|
2998
|
-
|
|
2999
|
-
this.onresize(details);
|
|
3000
|
-
this.#rEvts.forEach((item, key) => {
|
|
3001
|
-
item.cb(details);
|
|
3002
|
-
});
|
|
3305
|
+
const details = new Event("resize");
|
|
3306
|
+
this.dispatchEvent(details);
|
|
3003
3307
|
}
|
|
3004
|
-
if (this.#mMoveViewer[0]
|
|
3308
|
+
if (this.#mMoveViewer[0] !== 0) {
|
|
3005
3309
|
this.#mMoveViewer[0] = 0;
|
|
3006
|
-
const evt = new MouseEvent("
|
|
3007
|
-
target: this,
|
|
3008
|
-
altKey: false,
|
|
3310
|
+
const evt = new MouseEvent("mousemove", {
|
|
3009
3311
|
button: 0,
|
|
3010
3312
|
buttons: this.#mMoveViewer[5],
|
|
3011
3313
|
clientX: this.#mMoveViewer[1],
|
|
3012
3314
|
clientY: this.#mMoveViewer[2],
|
|
3013
3315
|
movementX: this.#mMoveViewer[3],
|
|
3014
3316
|
movementY: this.#mMoveViewer[4],
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
this.#mMoveEvts.forEach((item, key) => {
|
|
3024
|
-
item.cb(evt);
|
|
3317
|
+
screenX: this.#mMoveViewer[1],
|
|
3318
|
+
screenY: this.#mMoveViewer[2],
|
|
3319
|
+
shiftKey: Boolean(this.#mMoveViewer[6]),
|
|
3320
|
+
ctrlKey: Boolean(this.#mMoveViewer[7]),
|
|
3321
|
+
altKey: Boolean(this.#mMoveViewer[8]),
|
|
3322
|
+
metaKey: Boolean(this.#mMoveViewer[9]),
|
|
3323
|
+
bubbles: true,
|
|
3324
|
+
cancelable: true
|
|
3025
3325
|
});
|
|
3326
|
+
this.dispatchEvent(evt);
|
|
3026
3327
|
}
|
|
3027
|
-
if (this.#
|
|
3028
|
-
this.#mMoveViewer[0] = 0;
|
|
3029
|
-
const evt = new MouseEvent("move", {
|
|
3030
|
-
target: this,
|
|
3031
|
-
altKey: false,
|
|
3032
|
-
button: 0,
|
|
3033
|
-
buttons: this.#mMoveViewer[5],
|
|
3034
|
-
clientX: this.#mMoveViewer[1],
|
|
3035
|
-
clientY: this.#mMoveViewer[2],
|
|
3036
|
-
movementX: this.#mMoveViewer[3],
|
|
3037
|
-
movementY: this.#mMoveViewer[4],
|
|
3038
|
-
ctrlKey: false,
|
|
3039
|
-
metaKey: false,
|
|
3040
|
-
screenX: 0,
|
|
3041
|
-
screenY: 0,
|
|
3042
|
-
shiftKey: false
|
|
3043
|
-
});
|
|
3044
|
-
if (this.onmousemove)
|
|
3045
|
-
this.onmousemove(evt);
|
|
3046
|
-
this.#mMoveEvts.forEach((item, key) => {
|
|
3047
|
-
item.cb(evt);
|
|
3048
|
-
});
|
|
3049
|
-
}
|
|
3050
|
-
if (this.#mDownViewer[0] != 0) {
|
|
3328
|
+
if (this.#mDownViewer[0] !== 0) {
|
|
3051
3329
|
this.#mDownViewer[0] = 0;
|
|
3052
|
-
const evt = new MouseEvent("
|
|
3053
|
-
target: this,
|
|
3054
|
-
altKey: this.#mDownViewer[7],
|
|
3055
|
-
button: this.#mDownViewer[3],
|
|
3056
|
-
buttons: this.#mDownViewer[4],
|
|
3330
|
+
const evt = new MouseEvent("mousedown", {
|
|
3057
3331
|
clientX: this.#mDownViewer[1],
|
|
3058
3332
|
clientY: this.#mDownViewer[2],
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3333
|
+
button: this.#mDownViewer[3],
|
|
3334
|
+
buttons: this.#mDownViewer[4],
|
|
3335
|
+
shiftKey: Boolean(this.#mDownViewer[5]),
|
|
3336
|
+
ctrlKey: Boolean(this.#mDownViewer[6]),
|
|
3337
|
+
altKey: Boolean(this.#mDownViewer[7]),
|
|
3338
|
+
metaKey: Boolean(this.#mDownViewer[8]),
|
|
3063
3339
|
screenX: this.#mDownViewer[1],
|
|
3064
3340
|
screenY: this.#mDownViewer[2],
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
if (this.onmousedown)
|
|
3068
|
-
this.onmousedown(evt);
|
|
3069
|
-
this.#mDownEvts.forEach((item, key) => {
|
|
3070
|
-
item.cb(evt);
|
|
3341
|
+
bubbles: true,
|
|
3342
|
+
cancelable: true
|
|
3071
3343
|
});
|
|
3344
|
+
this.dispatchEvent(evt);
|
|
3072
3345
|
}
|
|
3073
|
-
if (this.#mUpViewer[0]
|
|
3346
|
+
if (this.#mUpViewer[0] !== 0) {
|
|
3074
3347
|
this.#mUpViewer[0] = 0;
|
|
3075
|
-
const evt = new MouseEvent("
|
|
3076
|
-
target: this,
|
|
3077
|
-
altKey: this.#mUpViewer[7],
|
|
3078
|
-
button: this.#mUpViewer[3],
|
|
3079
|
-
buttons: this.#mUpViewer[4],
|
|
3348
|
+
const evt = new MouseEvent("mouseup", {
|
|
3080
3349
|
clientX: this.#mUpViewer[1],
|
|
3081
3350
|
clientY: this.#mUpViewer[2],
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3351
|
+
button: this.#mUpViewer[3],
|
|
3352
|
+
buttons: this.#mUpViewer[4],
|
|
3353
|
+
shiftKey: Boolean(this.#mUpViewer[5]),
|
|
3354
|
+
ctrlKey: Boolean(this.#mUpViewer[6]),
|
|
3355
|
+
altKey: Boolean(this.#mUpViewer[7]),
|
|
3356
|
+
metaKey: Boolean(this.#mUpViewer[8]),
|
|
3086
3357
|
screenX: this.#mUpViewer[1],
|
|
3087
3358
|
screenY: this.#mUpViewer[2],
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
if (this.onmouseup)
|
|
3091
|
-
this.onmouseup(evt);
|
|
3092
|
-
this.#mMUpEvts.forEach((item, key) => {
|
|
3093
|
-
item.cb(evt);
|
|
3359
|
+
bubbles: true,
|
|
3360
|
+
cancelable: true
|
|
3094
3361
|
});
|
|
3362
|
+
this.dispatchEvent(evt);
|
|
3095
3363
|
}
|
|
3096
|
-
if (this.#mClickViewer[0]
|
|
3364
|
+
if (this.#mClickViewer[0] !== 0) {
|
|
3097
3365
|
this.#mClickViewer[0] = 0;
|
|
3098
3366
|
const evt = new MouseEvent("click", {
|
|
3099
|
-
target: this,
|
|
3100
|
-
altKey: this.#mClickViewer[7],
|
|
3101
|
-
button: this.#mClickViewer[3],
|
|
3102
|
-
buttons: this.#mClickViewer[4],
|
|
3103
3367
|
clientX: this.#mClickViewer[1],
|
|
3104
3368
|
clientY: this.#mClickViewer[2],
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3369
|
+
button: this.#mClickViewer[3],
|
|
3370
|
+
buttons: this.#mClickViewer[4],
|
|
3371
|
+
shiftKey: Boolean(this.#mClickViewer[5]),
|
|
3372
|
+
ctrlKey: Boolean(this.#mClickViewer[6]),
|
|
3373
|
+
altKey: Boolean(this.#mClickViewer[7]),
|
|
3374
|
+
metaKey: Boolean(this.#mClickViewer[8]),
|
|
3109
3375
|
screenX: this.#mClickViewer[1],
|
|
3110
3376
|
screenY: this.#mClickViewer[2],
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
this.onclick(evt);
|
|
3115
|
-
this.#mClickEvts.forEach((item, key) => {
|
|
3116
|
-
item.cb(evt);
|
|
3377
|
+
detail: 1,
|
|
3378
|
+
bubbles: true,
|
|
3379
|
+
cancelable: true
|
|
3117
3380
|
});
|
|
3381
|
+
this.dispatchEvent(evt);
|
|
3118
3382
|
}
|
|
3119
|
-
if (this.#mWheelViewer[0]
|
|
3383
|
+
if (this.#mWheelViewer[0] !== 0) {
|
|
3120
3384
|
this.#mWheelViewer[0] = 0;
|
|
3121
3385
|
const evt = new WheelEvent("wheel", {
|
|
3122
|
-
target: this,
|
|
3123
|
-
altKey: this.#mMoveViewer[7],
|
|
3124
|
-
button: this.#mWheelViewer[3],
|
|
3125
|
-
buttons: this.#mWheelViewer[4],
|
|
3126
|
-
clientX: this.#mMoveViewer[3],
|
|
3127
|
-
clientY: this.#mMoveViewer[4],
|
|
3128
3386
|
deltaX: -this.#mWheelViewer[1] * 120,
|
|
3129
3387
|
deltaY: -this.#mWheelViewer[2] * 120,
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
this
|
|
3140
|
-
|
|
3141
|
-
|
|
3388
|
+
deltaMode: WheelEvent.DOM_DELTA_PIXEL,
|
|
3389
|
+
button: this.#mWheelViewer[3],
|
|
3390
|
+
buttons: this.#mWheelViewer[4],
|
|
3391
|
+
clientX: this.#mMoveViewer[1],
|
|
3392
|
+
clientY: this.#mMoveViewer[2],
|
|
3393
|
+
screenX: this.#mMoveViewer[1],
|
|
3394
|
+
screenY: this.#mMoveViewer[2],
|
|
3395
|
+
shiftKey: Boolean(this.#mMoveViewer[6]),
|
|
3396
|
+
ctrlKey: Boolean(this.#mMoveViewer[7]),
|
|
3397
|
+
altKey: Boolean(this.#mMoveViewer[8]),
|
|
3398
|
+
metaKey: Boolean(this.#mMoveViewer[9]),
|
|
3399
|
+
bubbles: true,
|
|
3400
|
+
cancelable: true
|
|
3142
3401
|
});
|
|
3402
|
+
this.dispatchEvent(evt);
|
|
3143
3403
|
}
|
|
3144
|
-
if (this.#kDownViewer[0]
|
|
3404
|
+
if (this.#kDownViewer[0] !== 0) {
|
|
3145
3405
|
this.#kDownViewer[0] = 0;
|
|
3146
|
-
const evt =
|
|
3147
|
-
|
|
3148
|
-
this.onkeydown(evt);
|
|
3149
|
-
this.#keyDownEvts.forEach((item, key) => {
|
|
3150
|
-
item.cb(evt);
|
|
3151
|
-
});
|
|
3406
|
+
const evt = this.#createKeyboardEvent("keydown", this.#kDownViewer);
|
|
3407
|
+
this.dispatchEvent(evt);
|
|
3152
3408
|
}
|
|
3153
|
-
if (this.#kUpViewer[0]
|
|
3409
|
+
if (this.#kUpViewer[0] !== 0) {
|
|
3154
3410
|
this.#kUpViewer[0] = 0;
|
|
3155
|
-
const evt =
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3411
|
+
const evt = this.#createKeyboardEvent("keyup", this.#kUpViewer);
|
|
3412
|
+
this.dispatchEvent(evt);
|
|
3413
|
+
}
|
|
3414
|
+
if (this.#wFocusBlurViewer[0] !== 0) {
|
|
3415
|
+
this.#wFocusBlurViewer[0] = 0;
|
|
3416
|
+
this.dispatchEvent(new Event("focus"));
|
|
3417
|
+
}
|
|
3418
|
+
if (this.#wFocusBlurViewer[1] !== 0) {
|
|
3419
|
+
this.#wFocusBlurViewer[1] = 0;
|
|
3420
|
+
this.dispatchEvent(new Event("blur"));
|
|
3161
3421
|
}
|
|
3162
3422
|
}
|
|
3163
3423
|
maxFramerate = 0;
|
|
3424
|
+
#isFullscreen = false;
|
|
3425
|
+
get fullscreen() {
|
|
3426
|
+
return this.#isFullscreen;
|
|
3427
|
+
}
|
|
3428
|
+
set fullscreen(v) {
|
|
3429
|
+
lib.symbols.window_set_fullscreen(v);
|
|
3430
|
+
this.#isFullscreen = v;
|
|
3431
|
+
}
|
|
3432
|
+
toggleFullscreen() {
|
|
3433
|
+
this.#isFullscreen = this.#isFullscreen ? false : true;
|
|
3434
|
+
lib.symbols.window_set_fullscreen(this.#isFullscreen);
|
|
3435
|
+
}
|
|
3164
3436
|
#vsync = true;
|
|
3165
3437
|
get vsync() {
|
|
3166
3438
|
return this.#vsync;
|
|
@@ -3176,14 +3448,6 @@ class Window {
|
|
|
3176
3448
|
lib.symbols.font_add_to_registry(encoder.encode(`${font.family}\x00`), font._nativePtr);
|
|
3177
3449
|
}
|
|
3178
3450
|
};
|
|
3179
|
-
onresize = null;
|
|
3180
|
-
onmousemove = null;
|
|
3181
|
-
onmousedown = null;
|
|
3182
|
-
onmouseup = null;
|
|
3183
|
-
onclick = null;
|
|
3184
|
-
onkeydown = null;
|
|
3185
|
-
onkeyup = null;
|
|
3186
|
-
onwheel = null;
|
|
3187
3451
|
get innerWidth() {
|
|
3188
3452
|
return this.#wPropertiesViewer[1];
|
|
3189
3453
|
}
|
|
@@ -3191,9 +3455,13 @@ class Window {
|
|
|
3191
3455
|
return this.#wPropertiesViewer[2];
|
|
3192
3456
|
}
|
|
3193
3457
|
constructor(width, height, title = "App", args) {
|
|
3458
|
+
super();
|
|
3459
|
+
if (!Bun.isMainThread) {
|
|
3460
|
+
console.error(`[CRIT_ERR] Creating the window in a worker thread is unsupported.`);
|
|
3461
|
+
process.exit(-1);
|
|
3462
|
+
}
|
|
3194
3463
|
if (process.platform !== "darwin")
|
|
3195
3464
|
render_thread.ref?.();
|
|
3196
|
-
windowWasCreated = true;
|
|
3197
3465
|
this.#wPropertiesViewer[1] = width;
|
|
3198
3466
|
this.#wPropertiesViewer[2] = height;
|
|
3199
3467
|
const { vsync = true, maxFramerate = 0 } = args ?? {};
|
|
@@ -3212,10 +3480,14 @@ class Window {
|
|
|
3212
3480
|
nativePath: dlPath
|
|
3213
3481
|
});
|
|
3214
3482
|
let pendingFrame = false;
|
|
3483
|
+
let shuttingDown = false;
|
|
3215
3484
|
let lastFrame = performance.now();
|
|
3216
3485
|
render_thread.onmessage = (msg) => {
|
|
3217
3486
|
const frameSignal = msg.data;
|
|
3218
3487
|
if (frameSignal == 2) {
|
|
3488
|
+
if (shuttingDown)
|
|
3489
|
+
return;
|
|
3490
|
+
shuttingDown = true;
|
|
3219
3491
|
lib.symbols.destroy_window();
|
|
3220
3492
|
lib.symbols.images_cleanup();
|
|
3221
3493
|
process.exit(0);
|
|
@@ -3224,6 +3496,8 @@ class Window {
|
|
|
3224
3496
|
if (frameSignal === 1) {
|
|
3225
3497
|
lib.symbols.create_window(width, height, titleBuf);
|
|
3226
3498
|
}
|
|
3499
|
+
};
|
|
3500
|
+
const loop = () => {
|
|
3227
3501
|
lib.symbols.signal_frame_ready();
|
|
3228
3502
|
const frameInterval = this.maxFramerate > 0 ? 1000 / this.maxFramerate : 0;
|
|
3229
3503
|
const now = performance.now();
|
|
@@ -3234,7 +3508,6 @@ class Window {
|
|
|
3234
3508
|
}
|
|
3235
3509
|
if (!pendingFrame) {
|
|
3236
3510
|
pendingFrame = true;
|
|
3237
|
-
lib.symbols.canvas_flush_gpu();
|
|
3238
3511
|
setImmediate(() => {
|
|
3239
3512
|
const queueLen = requestedFrames.length;
|
|
3240
3513
|
if (queueLen > 0) {
|
|
@@ -3244,12 +3517,15 @@ class Window {
|
|
|
3244
3517
|
framesToProcess[i](now);
|
|
3245
3518
|
}
|
|
3246
3519
|
}
|
|
3520
|
+
lib.symbols.canvas_flush_gpu();
|
|
3247
3521
|
pendingFrame = false;
|
|
3248
3522
|
});
|
|
3249
3523
|
}
|
|
3250
3524
|
}
|
|
3251
3525
|
this.#processEvents();
|
|
3526
|
+
setImmediate(loop);
|
|
3252
3527
|
};
|
|
3528
|
+
setImmediate(loop);
|
|
3253
3529
|
} else {
|
|
3254
3530
|
let aaplLib = dlopen2(dlPath, {
|
|
3255
3531
|
setup_render_thread: {
|
|
@@ -3287,81 +3563,6 @@ class Window {
|
|
|
3287
3563
|
loop();
|
|
3288
3564
|
}
|
|
3289
3565
|
}
|
|
3290
|
-
addEventListener(name, fn) {
|
|
3291
|
-
const pop = this.#freeIndex.pop();
|
|
3292
|
-
const usedIndex = pop != null ? pop : this.#eIndex;
|
|
3293
|
-
if (usedIndex == this.#eIndex)
|
|
3294
|
-
this.#eIndex++;
|
|
3295
|
-
if (name == "resize") {
|
|
3296
|
-
this.#rEvts.set(usedIndex, { name, cb: fn });
|
|
3297
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3298
|
-
} else if (name == "mousemove") {
|
|
3299
|
-
this.#mMoveEvts.set(usedIndex, { name, cb: fn });
|
|
3300
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3301
|
-
} else if (name == "mousedown") {
|
|
3302
|
-
this.#mDownEvts.set(usedIndex, { name, cb: fn });
|
|
3303
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3304
|
-
} else if (name == "mouseup") {
|
|
3305
|
-
this.#mMUpEvts.set(usedIndex, { name, cb: fn });
|
|
3306
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3307
|
-
} else if (name == "wheel") {
|
|
3308
|
-
this.#mWheelEvts.set(usedIndex, { name, cb: fn });
|
|
3309
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3310
|
-
} else if (name == "click") {
|
|
3311
|
-
this.#mClickEvts.set(usedIndex, { name, cb: fn });
|
|
3312
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3313
|
-
} else if (name == "keydown") {
|
|
3314
|
-
this.#keyDownEvts.set(usedIndex, { name, cb: fn });
|
|
3315
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3316
|
-
} else if (name == "keyup") {
|
|
3317
|
-
this.#keyUpEvts.set(usedIndex, { name, cb: fn });
|
|
3318
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3319
|
-
}
|
|
3320
|
-
}
|
|
3321
|
-
removeEventListener(name, fn) {
|
|
3322
|
-
const det = this.#evtDetails.get(fn);
|
|
3323
|
-
if (name == "resize") {
|
|
3324
|
-
if (det != null) {
|
|
3325
|
-
this.#rEvts.delete(det);
|
|
3326
|
-
this.#evtDetails.delete(fn);
|
|
3327
|
-
}
|
|
3328
|
-
} else if (name == "mousemove") {
|
|
3329
|
-
if (det != null) {
|
|
3330
|
-
this.#mMoveEvts.delete(det);
|
|
3331
|
-
this.#evtDetails.delete(fn);
|
|
3332
|
-
}
|
|
3333
|
-
} else if (name == "mousedown") {
|
|
3334
|
-
if (det != null) {
|
|
3335
|
-
this.#mDownEvts.delete(det);
|
|
3336
|
-
this.#evtDetails.delete(fn);
|
|
3337
|
-
}
|
|
3338
|
-
} else if (name == "mouseup") {
|
|
3339
|
-
if (det != null) {
|
|
3340
|
-
this.#mMUpEvts.delete(det);
|
|
3341
|
-
this.#evtDetails.delete(fn);
|
|
3342
|
-
}
|
|
3343
|
-
} else if (name == "wheel") {
|
|
3344
|
-
if (det != null) {
|
|
3345
|
-
this.#mWheelEvts.delete(det);
|
|
3346
|
-
this.#evtDetails.delete(fn);
|
|
3347
|
-
}
|
|
3348
|
-
} else if (name == "click") {
|
|
3349
|
-
if (det != null) {
|
|
3350
|
-
this.#mClickEvts.delete(det);
|
|
3351
|
-
this.#evtDetails.delete(fn);
|
|
3352
|
-
}
|
|
3353
|
-
} else if (name == "keydown") {
|
|
3354
|
-
if (det != null) {
|
|
3355
|
-
this.#keyDownEvts.delete(det);
|
|
3356
|
-
this.#evtDetails.delete(fn);
|
|
3357
|
-
}
|
|
3358
|
-
} else if (name == "keyup") {
|
|
3359
|
-
if (det != null) {
|
|
3360
|
-
this.#keyUpEvts.delete(det);
|
|
3361
|
-
this.#evtDetails.delete(fn);
|
|
3362
|
-
}
|
|
3363
|
-
}
|
|
3364
|
-
}
|
|
3365
3566
|
append(canvas) {
|
|
3366
3567
|
const canvasPtr = canvas._ptr;
|
|
3367
3568
|
if (canvasPtr == undefined) {
|
|
@@ -3370,6 +3571,11 @@ class Window {
|
|
|
3370
3571
|
}
|
|
3371
3572
|
lib.symbols.canvas_append(canvasPtr);
|
|
3372
3573
|
}
|
|
3574
|
+
requestAnimationFrame(callback) {
|
|
3575
|
+
setImmediate(() => {
|
|
3576
|
+
requestedFrames.push(callback);
|
|
3577
|
+
});
|
|
3578
|
+
}
|
|
3373
3579
|
}
|
|
3374
3580
|
{
|
|
3375
3581
|
const proto = Window.prototype;
|
|
@@ -3387,46 +3593,46 @@ class Window {
|
|
|
3387
3593
|
}
|
|
3388
3594
|
}
|
|
3389
3595
|
var rAf;
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
});
|
|
3397
|
-
};
|
|
3398
|
-
rAf.toString = () => `function requestAnimationFrame() { [native code] }`;
|
|
3399
|
-
}
|
|
3596
|
+
rAf = function requestAnimationFrame(callback) {
|
|
3597
|
+
setImmediate(() => {
|
|
3598
|
+
requestedFrames.push(callback);
|
|
3599
|
+
});
|
|
3600
|
+
};
|
|
3601
|
+
rAf.toString = () => `function requestAnimationFrame() { [native code] }`;
|
|
3400
3602
|
var requestAnimationFrame = rAf;
|
|
3401
3603
|
// BunCanvas/src/Audio.ts
|
|
3402
|
-
var
|
|
3604
|
+
var ptrs3 = new WeakMap;
|
|
3403
3605
|
lib.symbols.audio_backend_init();
|
|
3404
3606
|
|
|
3405
3607
|
class Audio {
|
|
3406
3608
|
constructor(path) {
|
|
3407
3609
|
if (path) {
|
|
3408
|
-
|
|
3610
|
+
ptrs3.set(this, lib.symbols.audio_create(encoder.encode(`${path}\x00`)));
|
|
3409
3611
|
} else {
|
|
3410
|
-
|
|
3612
|
+
ptrs3.set(this, lib.symbols.audio_create());
|
|
3411
3613
|
}
|
|
3412
3614
|
}
|
|
3413
3615
|
set src(v) {
|
|
3414
3616
|
lib.symbols.audio_set_src(encodeCString(v));
|
|
3415
3617
|
}
|
|
3416
3618
|
play() {
|
|
3417
|
-
lib.symbols.audio_play(
|
|
3619
|
+
lib.symbols.audio_play(ptrs3.get(this));
|
|
3418
3620
|
}
|
|
3419
3621
|
stop() {
|
|
3420
|
-
lib.symbols.audio_stop(
|
|
3622
|
+
lib.symbols.audio_stop(ptrs3.get(this));
|
|
3421
3623
|
}
|
|
3422
3624
|
}
|
|
3625
|
+
|
|
3626
|
+
// BunCanvas/index.ts
|
|
3627
|
+
if (!process.versions.bun) {
|
|
3628
|
+
throw new Error("BunCanvas only supports Bun! Other runtimes like Node or Deno are unsupported.");
|
|
3629
|
+
}
|
|
3423
3630
|
export {
|
|
3424
3631
|
Audio,
|
|
3425
3632
|
Canvas,
|
|
3426
3633
|
CanvasGradient,
|
|
3427
3634
|
CanvasRenderingContext2D,
|
|
3428
3635
|
DOMMatrix,
|
|
3429
|
-
Event,
|
|
3430
3636
|
FontFace,
|
|
3431
3637
|
Image,
|
|
3432
3638
|
KeyboardEvent,
|