@buncanvas/core 0.2.0 → 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 +1088 -867
- 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 +12 -4
- package/internal/window/glfwKeyMap.d.ts +368 -0
- package/package.json +4 -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"],
|
|
@@ -438,23 +446,25 @@ var lib = dlopen(dlPath, {
|
|
|
438
446
|
}
|
|
439
447
|
});
|
|
440
448
|
|
|
441
|
-
// BunCanvas/src/Event.js
|
|
442
|
-
class Event {
|
|
443
|
-
type = null;
|
|
444
|
-
target = null;
|
|
445
|
-
timeStamp = performance.now();
|
|
446
|
-
constructor(type, target) {
|
|
447
|
-
this.type = type;
|
|
448
|
-
this.target = target;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
449
|
// BunCanvas/src/Image.ts
|
|
453
450
|
import { ptr } from "bun:ffi";
|
|
451
|
+
|
|
452
|
+
// BunCanvas/internal/pointers.ts
|
|
454
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
|
|
455
466
|
var fRegistry = new FinalizationRegistry((ptr) => {
|
|
456
467
|
lib.symbols.image_destroy(ptr);
|
|
457
|
-
console.log("destroy!");
|
|
458
468
|
});
|
|
459
469
|
function computePath(url) {
|
|
460
470
|
const hash = createHash("sha256").update(url).digest("hex").slice(0, 16);
|
|
@@ -506,15 +516,15 @@ class Image {
|
|
|
506
516
|
if (lib.symbols.image_load(iptr, ptr(tArr))) {
|
|
507
517
|
this.#width = !this.#setWidth ? tArr[0] : this.#width;
|
|
508
518
|
this.#height = !this.#setHeight ? tArr[1] : this.#height;
|
|
509
|
-
self.onload?.call(self, new Event("load", self));
|
|
519
|
+
self.onload?.call(self, attachEventTarget(new Event("load", {}), self));
|
|
510
520
|
} else {
|
|
511
|
-
self.onerror?.call(self, new Event("error", self));
|
|
521
|
+
self.onerror?.call(self, attachEventTarget(new Event("error", {}), self));
|
|
512
522
|
}
|
|
513
523
|
}).catch((ex) => {
|
|
514
524
|
const self = weakThis.deref();
|
|
515
525
|
if (!self)
|
|
516
526
|
return;
|
|
517
|
-
self.onerror?.call(self, new Event("error", self));
|
|
527
|
+
self.onerror?.call(self, attachEventTarget(new Event("error", {}), self));
|
|
518
528
|
}).finally(() => {});
|
|
519
529
|
return;
|
|
520
530
|
} else {
|
|
@@ -531,9 +541,9 @@ class Image {
|
|
|
531
541
|
if (lib.symbols.image_load(_ptr, ptr(tArr))) {
|
|
532
542
|
this.#width = !this.#setWidth ? tArr[0] : this.#width;
|
|
533
543
|
this.#height = !this.#setHeight ? tArr[1] : this.#height;
|
|
534
|
-
self.onload?.call(self, new Event("
|
|
544
|
+
self.onload?.call(self, attachEventTarget(new Event("error", {}), self));
|
|
535
545
|
} else {
|
|
536
|
-
self.onerror?.call(self, new Event("error", self));
|
|
546
|
+
self.onerror?.call(self, attachEventTarget(new Event("error", {}), self));
|
|
537
547
|
}
|
|
538
548
|
clearTimeout(tm);
|
|
539
549
|
}, 0);
|
|
@@ -655,474 +665,243 @@ class TextMetrics {
|
|
|
655
665
|
}
|
|
656
666
|
// BunCanvas/src/MouseEvent.ts
|
|
657
667
|
class MouseEvent extends Event {
|
|
658
|
-
altKey
|
|
659
|
-
button
|
|
660
|
-
buttons
|
|
661
|
-
clientX
|
|
662
|
-
clientY
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
this.ctrlKey = args.ctrlKey;
|
|
680
|
-
this.metaKey = args.metaKey;
|
|
681
|
-
this.screenX = args.screenX;
|
|
682
|
-
this.screenY = args.screenY;
|
|
683
|
-
this.shiftKey = args.shiftKey;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
var proto = MouseEvent.prototype;
|
|
687
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
688
|
-
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
689
|
-
if (key == "constructor") {
|
|
690
|
-
desc && (desc.value.toString = () => {
|
|
691
|
-
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
|
|
692
689
|
});
|
|
693
|
-
|
|
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
|
+
]);
|
|
694
721
|
}
|
|
695
|
-
|
|
696
|
-
|
|
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;
|
|
697
787
|
}
|
|
698
788
|
}
|
|
699
789
|
// BunCanvas/src/WheelEvent.ts
|
|
700
790
|
class WheelEvent extends MouseEvent {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
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;
|
|
707
816
|
}
|
|
708
817
|
}
|
|
709
|
-
// BunCanvas/src/KeyboardEvent.
|
|
710
|
-
var GLFW_KEY_MAP = {
|
|
711
|
-
"-1": "Unknown",
|
|
712
|
-
32: " ",
|
|
713
|
-
39: "'",
|
|
714
|
-
44: ",",
|
|
715
|
-
45: "-",
|
|
716
|
-
46: ".",
|
|
717
|
-
47: "/",
|
|
718
|
-
48: "0",
|
|
719
|
-
49: "1",
|
|
720
|
-
50: "2",
|
|
721
|
-
51: "3",
|
|
722
|
-
52: "4",
|
|
723
|
-
53: "5",
|
|
724
|
-
54: "6",
|
|
725
|
-
55: "7",
|
|
726
|
-
56: "8",
|
|
727
|
-
57: "9",
|
|
728
|
-
59: ";",
|
|
729
|
-
61: "=",
|
|
730
|
-
65: "a",
|
|
731
|
-
66: "b",
|
|
732
|
-
67: "c",
|
|
733
|
-
68: "d",
|
|
734
|
-
69: "e",
|
|
735
|
-
70: "f",
|
|
736
|
-
71: "g",
|
|
737
|
-
72: "h",
|
|
738
|
-
73: "i",
|
|
739
|
-
74: "j",
|
|
740
|
-
75: "k",
|
|
741
|
-
76: "l",
|
|
742
|
-
77: "m",
|
|
743
|
-
78: "n",
|
|
744
|
-
79: "o",
|
|
745
|
-
80: "p",
|
|
746
|
-
81: "q",
|
|
747
|
-
82: "r",
|
|
748
|
-
83: "s",
|
|
749
|
-
84: "t",
|
|
750
|
-
85: "u",
|
|
751
|
-
86: "v",
|
|
752
|
-
87: "w",
|
|
753
|
-
88: "x",
|
|
754
|
-
89: "y",
|
|
755
|
-
90: "z",
|
|
756
|
-
91: "[",
|
|
757
|
-
92: "\\",
|
|
758
|
-
93: "]",
|
|
759
|
-
96: "`",
|
|
760
|
-
161: "World1",
|
|
761
|
-
162: "World2",
|
|
762
|
-
256: "Escape",
|
|
763
|
-
257: "Enter",
|
|
764
|
-
258: "Tab",
|
|
765
|
-
259: "Backspace",
|
|
766
|
-
260: "Insert",
|
|
767
|
-
261: "Delete",
|
|
768
|
-
262: "ArrowRight",
|
|
769
|
-
263: "ArrowLeft",
|
|
770
|
-
264: "ArrowDown",
|
|
771
|
-
265: "ArrowUp",
|
|
772
|
-
266: "PageUp",
|
|
773
|
-
267: "PageDown",
|
|
774
|
-
268: "Home",
|
|
775
|
-
269: "End",
|
|
776
|
-
280: "CapsLock",
|
|
777
|
-
281: "ScrollLock",
|
|
778
|
-
282: "NumLock",
|
|
779
|
-
283: "PrintScreen",
|
|
780
|
-
284: "Pause",
|
|
781
|
-
290: "F1",
|
|
782
|
-
291: "F2",
|
|
783
|
-
292: "F3",
|
|
784
|
-
293: "F4",
|
|
785
|
-
294: "F5",
|
|
786
|
-
295: "F6",
|
|
787
|
-
296: "F7",
|
|
788
|
-
297: "F8",
|
|
789
|
-
298: "F9",
|
|
790
|
-
299: "F10",
|
|
791
|
-
300: "F11",
|
|
792
|
-
301: "F12",
|
|
793
|
-
302: "F13",
|
|
794
|
-
303: "F14",
|
|
795
|
-
304: "F15",
|
|
796
|
-
305: "F16",
|
|
797
|
-
306: "F17",
|
|
798
|
-
307: "F18",
|
|
799
|
-
308: "F19",
|
|
800
|
-
309: "F20",
|
|
801
|
-
310: "F21",
|
|
802
|
-
311: "F22",
|
|
803
|
-
312: "F23",
|
|
804
|
-
313: "F24",
|
|
805
|
-
314: "F25",
|
|
806
|
-
320: "0",
|
|
807
|
-
321: "1",
|
|
808
|
-
322: "2",
|
|
809
|
-
323: "3",
|
|
810
|
-
324: "4",
|
|
811
|
-
325: "5",
|
|
812
|
-
326: "6",
|
|
813
|
-
327: "7",
|
|
814
|
-
328: "8",
|
|
815
|
-
329: "9",
|
|
816
|
-
330: ".",
|
|
817
|
-
331: "/",
|
|
818
|
-
332: "*",
|
|
819
|
-
333: "-",
|
|
820
|
-
334: "+",
|
|
821
|
-
335: "Enter",
|
|
822
|
-
336: "=",
|
|
823
|
-
340: "Shift",
|
|
824
|
-
341: "Control",
|
|
825
|
-
342: "Alt",
|
|
826
|
-
343: "Meta",
|
|
827
|
-
344: "Shift",
|
|
828
|
-
345: "Control",
|
|
829
|
-
346: "Alt",
|
|
830
|
-
347: "Meta",
|
|
831
|
-
348: "ContextMenu"
|
|
832
|
-
};
|
|
833
|
-
var GLFW_KEY_MAP_SHIFT = {
|
|
834
|
-
"-1": "Unknown",
|
|
835
|
-
32: " ",
|
|
836
|
-
39: '"',
|
|
837
|
-
44: "<",
|
|
838
|
-
45: "_",
|
|
839
|
-
46: ">",
|
|
840
|
-
47: "?",
|
|
841
|
-
48: ")",
|
|
842
|
-
49: "!",
|
|
843
|
-
50: "@",
|
|
844
|
-
51: "#",
|
|
845
|
-
52: "$",
|
|
846
|
-
53: "%",
|
|
847
|
-
54: "^",
|
|
848
|
-
55: "&",
|
|
849
|
-
56: "*",
|
|
850
|
-
57: "(",
|
|
851
|
-
59: ":",
|
|
852
|
-
61: "+",
|
|
853
|
-
65: "A",
|
|
854
|
-
66: "B",
|
|
855
|
-
67: "C",
|
|
856
|
-
68: "D",
|
|
857
|
-
69: "E",
|
|
858
|
-
70: "F",
|
|
859
|
-
71: "G",
|
|
860
|
-
72: "H",
|
|
861
|
-
73: "I",
|
|
862
|
-
74: "J",
|
|
863
|
-
75: "K",
|
|
864
|
-
76: "L",
|
|
865
|
-
77: "M",
|
|
866
|
-
78: "N",
|
|
867
|
-
79: "O",
|
|
868
|
-
80: "P",
|
|
869
|
-
81: "Q",
|
|
870
|
-
82: "R",
|
|
871
|
-
83: "S",
|
|
872
|
-
84: "T",
|
|
873
|
-
85: "U",
|
|
874
|
-
86: "V",
|
|
875
|
-
87: "W",
|
|
876
|
-
88: "X",
|
|
877
|
-
89: "Y",
|
|
878
|
-
90: "Z",
|
|
879
|
-
91: "{",
|
|
880
|
-
92: "|",
|
|
881
|
-
93: "}",
|
|
882
|
-
96: "~",
|
|
883
|
-
161: "World1",
|
|
884
|
-
162: "World2",
|
|
885
|
-
256: "Escape",
|
|
886
|
-
257: "Enter",
|
|
887
|
-
258: "Tab",
|
|
888
|
-
259: "Backspace",
|
|
889
|
-
260: "Insert",
|
|
890
|
-
261: "Delete",
|
|
891
|
-
262: "ArrowRight",
|
|
892
|
-
263: "ArrowLeft",
|
|
893
|
-
264: "ArrowDown",
|
|
894
|
-
265: "ArrowUp",
|
|
895
|
-
266: "PageUp",
|
|
896
|
-
267: "PageDown",
|
|
897
|
-
268: "Home",
|
|
898
|
-
269: "End",
|
|
899
|
-
280: "CapsLock",
|
|
900
|
-
281: "ScrollLock",
|
|
901
|
-
282: "NumLock",
|
|
902
|
-
283: "PrintScreen",
|
|
903
|
-
284: "Pause",
|
|
904
|
-
290: "F1",
|
|
905
|
-
291: "F2",
|
|
906
|
-
292: "F3",
|
|
907
|
-
293: "F4",
|
|
908
|
-
294: "F5",
|
|
909
|
-
295: "F6",
|
|
910
|
-
296: "F7",
|
|
911
|
-
297: "F8",
|
|
912
|
-
298: "F9",
|
|
913
|
-
299: "F10",
|
|
914
|
-
300: "F11",
|
|
915
|
-
301: "F12",
|
|
916
|
-
302: "F13",
|
|
917
|
-
303: "F14",
|
|
918
|
-
304: "F15",
|
|
919
|
-
305: "F16",
|
|
920
|
-
306: "F17",
|
|
921
|
-
307: "F18",
|
|
922
|
-
308: "F19",
|
|
923
|
-
309: "F20",
|
|
924
|
-
310: "F21",
|
|
925
|
-
311: "F22",
|
|
926
|
-
312: "F23",
|
|
927
|
-
313: "F24",
|
|
928
|
-
314: "F25",
|
|
929
|
-
320: "0",
|
|
930
|
-
321: "1",
|
|
931
|
-
322: "2",
|
|
932
|
-
323: "3",
|
|
933
|
-
324: "4",
|
|
934
|
-
325: "5",
|
|
935
|
-
326: "6",
|
|
936
|
-
327: "7",
|
|
937
|
-
328: "8",
|
|
938
|
-
329: "9",
|
|
939
|
-
330: ".",
|
|
940
|
-
331: "/",
|
|
941
|
-
332: "*",
|
|
942
|
-
333: "-",
|
|
943
|
-
334: "+",
|
|
944
|
-
335: "Enter",
|
|
945
|
-
336: "=",
|
|
946
|
-
340: "Shift",
|
|
947
|
-
341: "Control",
|
|
948
|
-
342: "Alt",
|
|
949
|
-
343: "Meta",
|
|
950
|
-
344: "Shift",
|
|
951
|
-
345: "Control",
|
|
952
|
-
346: "Alt",
|
|
953
|
-
347: "Meta",
|
|
954
|
-
348: "ContextMenu"
|
|
955
|
-
};
|
|
956
|
-
var GLFW_CODE_MAP = {
|
|
957
|
-
"-1": "Unknown",
|
|
958
|
-
32: "Space",
|
|
959
|
-
39: "Quote",
|
|
960
|
-
44: "Comma",
|
|
961
|
-
45: "Minus",
|
|
962
|
-
46: "Period",
|
|
963
|
-
47: "Slash",
|
|
964
|
-
48: "Digit0",
|
|
965
|
-
49: "Digit1",
|
|
966
|
-
50: "Digit2",
|
|
967
|
-
51: "Digit3",
|
|
968
|
-
52: "Digit4",
|
|
969
|
-
53: "Digit5",
|
|
970
|
-
54: "Digit6",
|
|
971
|
-
55: "Digit7",
|
|
972
|
-
56: "Digit8",
|
|
973
|
-
57: "Digit9",
|
|
974
|
-
59: "Semicolon",
|
|
975
|
-
61: "Equal",
|
|
976
|
-
65: "KeyA",
|
|
977
|
-
66: "KeyB",
|
|
978
|
-
67: "KeyC",
|
|
979
|
-
68: "KeyD",
|
|
980
|
-
69: "KeyE",
|
|
981
|
-
70: "KeyF",
|
|
982
|
-
71: "KeyG",
|
|
983
|
-
72: "KeyH",
|
|
984
|
-
73: "KeyI",
|
|
985
|
-
74: "KeyJ",
|
|
986
|
-
75: "KeyK",
|
|
987
|
-
76: "KeyL",
|
|
988
|
-
77: "KeyM",
|
|
989
|
-
78: "KeyN",
|
|
990
|
-
79: "KeyO",
|
|
991
|
-
80: "KeyP",
|
|
992
|
-
81: "KeyQ",
|
|
993
|
-
82: "KeyR",
|
|
994
|
-
83: "KeyS",
|
|
995
|
-
84: "KeyT",
|
|
996
|
-
85: "KeyU",
|
|
997
|
-
86: "KeyV",
|
|
998
|
-
87: "KeyW",
|
|
999
|
-
88: "KeyX",
|
|
1000
|
-
89: "KeyY",
|
|
1001
|
-
90: "KeyZ",
|
|
1002
|
-
91: "BracketLeft",
|
|
1003
|
-
92: "Backslash",
|
|
1004
|
-
93: "BracketRight",
|
|
1005
|
-
96: "Backquote",
|
|
1006
|
-
161: "IntlBackslash",
|
|
1007
|
-
256: "Escape",
|
|
1008
|
-
257: "Enter",
|
|
1009
|
-
258: "Tab",
|
|
1010
|
-
259: "Backspace",
|
|
1011
|
-
260: "Insert",
|
|
1012
|
-
261: "Delete",
|
|
1013
|
-
262: "ArrowRight",
|
|
1014
|
-
263: "ArrowLeft",
|
|
1015
|
-
264: "ArrowDown",
|
|
1016
|
-
265: "ArrowUp",
|
|
1017
|
-
266: "PageUp",
|
|
1018
|
-
267: "PageDown",
|
|
1019
|
-
268: "Home",
|
|
1020
|
-
269: "End",
|
|
1021
|
-
280: "CapsLock",
|
|
1022
|
-
281: "ScrollLock",
|
|
1023
|
-
282: "NumLock",
|
|
1024
|
-
283: "PrintScreen",
|
|
1025
|
-
284: "Pause",
|
|
1026
|
-
290: "F1",
|
|
1027
|
-
291: "F2",
|
|
1028
|
-
292: "F3",
|
|
1029
|
-
293: "F4",
|
|
1030
|
-
294: "F5",
|
|
1031
|
-
295: "F6",
|
|
1032
|
-
296: "F7",
|
|
1033
|
-
297: "F8",
|
|
1034
|
-
298: "F9",
|
|
1035
|
-
299: "F10",
|
|
1036
|
-
300: "F11",
|
|
1037
|
-
301: "F12",
|
|
1038
|
-
302: "F13",
|
|
1039
|
-
303: "F14",
|
|
1040
|
-
304: "F15",
|
|
1041
|
-
305: "F16",
|
|
1042
|
-
306: "F17",
|
|
1043
|
-
307: "F18",
|
|
1044
|
-
308: "F19",
|
|
1045
|
-
309: "F20",
|
|
1046
|
-
310: "F21",
|
|
1047
|
-
311: "F22",
|
|
1048
|
-
312: "F23",
|
|
1049
|
-
313: "F24",
|
|
1050
|
-
314: "F25",
|
|
1051
|
-
320: "Numpad0",
|
|
1052
|
-
321: "Numpad1",
|
|
1053
|
-
322: "Numpad2",
|
|
1054
|
-
323: "Numpad3",
|
|
1055
|
-
324: "Numpad4",
|
|
1056
|
-
325: "Numpad5",
|
|
1057
|
-
326: "Numpad6",
|
|
1058
|
-
327: "Numpad7",
|
|
1059
|
-
328: "Numpad8",
|
|
1060
|
-
329: "Numpad9",
|
|
1061
|
-
330: "NumpadDecimal",
|
|
1062
|
-
331: "NumpadDivide",
|
|
1063
|
-
332: "NumpadMultiply",
|
|
1064
|
-
333: "NumpadSubtract",
|
|
1065
|
-
334: "NumpadAdd",
|
|
1066
|
-
335: "NumpadEnter",
|
|
1067
|
-
336: "NumpadEqual",
|
|
1068
|
-
340: "ShiftLeft",
|
|
1069
|
-
341: "ControlLeft",
|
|
1070
|
-
342: "AltLeft",
|
|
1071
|
-
343: "MetaLeft",
|
|
1072
|
-
344: "ShiftRight",
|
|
1073
|
-
345: "ControlRight",
|
|
1074
|
-
346: "AltRight",
|
|
1075
|
-
347: "MetaRight",
|
|
1076
|
-
348: "ContextMenu"
|
|
1077
|
-
};
|
|
1078
|
-
|
|
818
|
+
// BunCanvas/src/KeyboardEvent.ts
|
|
1079
819
|
class KeyboardEvent extends Event {
|
|
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
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
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;
|
|
1126
905
|
}
|
|
1127
906
|
}
|
|
1128
907
|
// BunCanvas/src/Canvas.ts
|
|
@@ -2086,12 +1865,12 @@ class DOMMatrix {
|
|
|
2086
1865
|
return new DOMMatrix([m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44]);
|
|
2087
1866
|
}
|
|
2088
1867
|
}
|
|
2089
|
-
var
|
|
2090
|
-
for (const key of Object.getOwnPropertyNames(
|
|
2091
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
1868
|
+
var proto = DOMMatrix.prototype;
|
|
1869
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1870
|
+
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
2092
1871
|
if (key == "constructor") {
|
|
2093
1872
|
desc && (desc.value.toString = () => {
|
|
2094
|
-
return `function ${
|
|
1873
|
+
return `function ${proto.constructor.name}() { [native code] }`;
|
|
2095
1874
|
});
|
|
2096
1875
|
continue;
|
|
2097
1876
|
}
|
|
@@ -2268,8 +2047,109 @@ function isValidColor(str) {
|
|
|
2268
2047
|
return RGB_REGEX.test(normalized) || HSL_HWB_REGEX.test(normalized);
|
|
2269
2048
|
}
|
|
2270
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
|
+
|
|
2271
2152
|
// BunCanvas/src/Canvas.ts
|
|
2272
|
-
var ptrs3 = new WeakMap;
|
|
2273
2153
|
var canvasFinalizationRegistry = new FinalizationRegistry((ptr) => {
|
|
2274
2154
|
lib.symbols.canvas_destroy(ptr);
|
|
2275
2155
|
});
|
|
@@ -2402,14 +2282,16 @@ class CanvasRenderingContext2D {
|
|
|
2402
2282
|
}
|
|
2403
2283
|
const offsetBuffer = new Float32Array(style.offsets);
|
|
2404
2284
|
const nativeFn = isStroke ? lib.symbols.canvas_set_stroke_style_gradient : lib.symbols.canvas_set_fill_style_gradient;
|
|
2405
|
-
return nativeFn(
|
|
2285
|
+
return nativeFn(ptrs.get(this), style.type, ptr3(style.points), count, ptr3(ptrArray), ptr3(offsetBuffer));
|
|
2406
2286
|
}
|
|
2407
2287
|
get canvas() {
|
|
2408
2288
|
return this.#owner;
|
|
2409
2289
|
}
|
|
2410
2290
|
set font(css) {
|
|
2411
|
-
|
|
2412
|
-
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
|
+
}
|
|
2413
2295
|
}
|
|
2414
2296
|
get font() {
|
|
2415
2297
|
return this.#currentState.fontCss;
|
|
@@ -2419,7 +2301,7 @@ class CanvasRenderingContext2D {
|
|
|
2419
2301
|
return;
|
|
2420
2302
|
let res = false;
|
|
2421
2303
|
if (typeof style === "string") {
|
|
2422
|
-
res = lib.symbols.canvas_set_fill_style(
|
|
2304
|
+
res = lib.symbols.canvas_set_fill_style(ptrs.get(this), encodeCString(style));
|
|
2423
2305
|
} else if (style instanceof CanvasGradient) {
|
|
2424
2306
|
res = this.#setStyleGradient(style, false);
|
|
2425
2307
|
}
|
|
@@ -2434,7 +2316,7 @@ class CanvasRenderingContext2D {
|
|
|
2434
2316
|
return;
|
|
2435
2317
|
let res = false;
|
|
2436
2318
|
if (typeof style === "string") {
|
|
2437
|
-
res = lib.symbols.canvas_set_stroke_style(
|
|
2319
|
+
res = lib.symbols.canvas_set_stroke_style(ptrs.get(this), encodeCString(style.trim()));
|
|
2438
2320
|
} else if (style instanceof CanvasGradient) {
|
|
2439
2321
|
res = this.#setStyleGradient(style, true);
|
|
2440
2322
|
}
|
|
@@ -2446,35 +2328,21 @@ class CanvasRenderingContext2D {
|
|
|
2446
2328
|
}
|
|
2447
2329
|
set lineWidth(width) {
|
|
2448
2330
|
let w = width < 1 ? 1 : width;
|
|
2449
|
-
lib.symbols.canvas_set_stroke_width(
|
|
2331
|
+
lib.symbols.canvas_set_stroke_width(ptrs.get(this), w);
|
|
2450
2332
|
this.#currentState.lineWidth = w;
|
|
2451
2333
|
}
|
|
2452
2334
|
get lineWidth() {
|
|
2453
2335
|
return this.#currentState.lineWidth;
|
|
2454
2336
|
}
|
|
2455
2337
|
set globalAlpha(a) {
|
|
2456
|
-
this.#currentState.globalAlpha = lib.symbols.canvas_set_global_alpha(
|
|
2338
|
+
this.#currentState.globalAlpha = lib.symbols.canvas_set_global_alpha(ptrs.get(this), a);
|
|
2457
2339
|
}
|
|
2458
2340
|
get globalAlpha() {
|
|
2459
2341
|
return this.#currentState.globalAlpha;
|
|
2460
2342
|
}
|
|
2461
2343
|
set imageSmoothingQuality(v) {
|
|
2462
|
-
let
|
|
2463
|
-
|
|
2464
|
-
case "low": {
|
|
2465
|
-
res = lib.symbols.canvas_set_image_smoothing_quality(ptrs3.get(this), 1);
|
|
2466
|
-
break;
|
|
2467
|
-
}
|
|
2468
|
-
case "medium": {
|
|
2469
|
-
res = lib.symbols.canvas_set_image_smoothing_quality(ptrs3.get(this), 2);
|
|
2470
|
-
break;
|
|
2471
|
-
}
|
|
2472
|
-
case "high": {
|
|
2473
|
-
res = lib.symbols.canvas_set_image_smoothing_quality(ptrs3.get(this), 3);
|
|
2474
|
-
break;
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
if (res) {
|
|
2344
|
+
let smQuality = CanvasSmoothingQuality[v];
|
|
2345
|
+
if (lib.symbols.canvas_set_image_smoothing_quality(ptrs.get(this), smQuality)) {
|
|
2478
2346
|
this.#currentState.imageSmoothingQuality = v;
|
|
2479
2347
|
}
|
|
2480
2348
|
}
|
|
@@ -2482,13 +2350,15 @@ class CanvasRenderingContext2D {
|
|
|
2482
2350
|
return this.#currentState.imageSmoothingQuality;
|
|
2483
2351
|
}
|
|
2484
2352
|
set imageSmoothingEnabled(v) {
|
|
2485
|
-
|
|
2353
|
+
if (lib.symbols.canvas_set_image_smoothing_enabled(ptrs.get(this), v)) {
|
|
2354
|
+
this.#currentState.imageSmoothingEnabled = v;
|
|
2355
|
+
}
|
|
2486
2356
|
}
|
|
2487
2357
|
get imageSmoothingEnabled() {
|
|
2488
2358
|
return this.#currentState.imageSmoothingEnabled;
|
|
2489
2359
|
}
|
|
2490
2360
|
set filter(v) {
|
|
2491
|
-
if (lib.symbols.canvas_set_filter(
|
|
2361
|
+
if (lib.symbols.canvas_set_filter(ptrs.get(this), encoder.encode(`${v}\x00`))) {
|
|
2492
2362
|
this.#currentState.filter = v;
|
|
2493
2363
|
}
|
|
2494
2364
|
}
|
|
@@ -2496,56 +2366,60 @@ class CanvasRenderingContext2D {
|
|
|
2496
2366
|
return this.#currentState.filter;
|
|
2497
2367
|
}
|
|
2498
2368
|
set globalCompositeOperation(operation) {
|
|
2499
|
-
|
|
2369
|
+
const composite = CanvasBlendMode[operation];
|
|
2370
|
+
if (!composite)
|
|
2371
|
+
return;
|
|
2372
|
+
if (lib.symbols.canvas_set_composite_operation(ptrs.get(this), composite)) {
|
|
2500
2373
|
this.#currentState.compositeOperation = operation;
|
|
2374
|
+
}
|
|
2501
2375
|
}
|
|
2502
2376
|
get globalCompositeOperation() {
|
|
2503
2377
|
return this.#currentState.compositeOperation;
|
|
2504
2378
|
}
|
|
2505
2379
|
fillRect(x, y, w, h) {
|
|
2506
|
-
lib.symbols.canvas_fill_rect(
|
|
2380
|
+
lib.symbols.canvas_fill_rect(ptrs.get(this), x, y, w, h);
|
|
2507
2381
|
}
|
|
2508
2382
|
strokeRect(x, y, w, h) {
|
|
2509
|
-
lib.symbols.canvas_stroke_rect(
|
|
2383
|
+
lib.symbols.canvas_stroke_rect(ptrs.get(this), x, y, w, h);
|
|
2510
2384
|
}
|
|
2511
2385
|
clearRect(x, y, w, h) {
|
|
2512
|
-
lib.symbols.canvas_clear_rect(
|
|
2386
|
+
lib.symbols.canvas_clear_rect(ptrs.get(this), x, y, w, h);
|
|
2513
2387
|
}
|
|
2514
2388
|
fillText(text, x, y, maxWidth = -1) {
|
|
2515
|
-
lib.symbols.canvas_fill_text(
|
|
2389
|
+
lib.symbols.canvas_fill_text(ptrs.get(this), encoder.encode(`${text}\x00`), x, y, maxWidth);
|
|
2516
2390
|
}
|
|
2517
2391
|
strokeText(text, x, y, maxWidth = -1) {
|
|
2518
|
-
lib.symbols.canvas_stroke_text(
|
|
2392
|
+
lib.symbols.canvas_stroke_text(ptrs.get(this), encoder.encode(`${text}\x00`), x, y, maxWidth);
|
|
2519
2393
|
}
|
|
2520
2394
|
beginPath() {
|
|
2521
|
-
lib.symbols.canvas_path_begin(
|
|
2395
|
+
lib.symbols.canvas_path_begin(ptrs.get(this));
|
|
2522
2396
|
}
|
|
2523
2397
|
moveTo(x, y) {
|
|
2524
|
-
lib.symbols.canvas_path_move_to(
|
|
2398
|
+
lib.symbols.canvas_path_move_to(ptrs.get(this), x, y);
|
|
2525
2399
|
}
|
|
2526
2400
|
lineTo(x, y) {
|
|
2527
|
-
lib.symbols.canvas_path_line_to(
|
|
2401
|
+
lib.symbols.canvas_path_line_to(ptrs.get(this), x, y);
|
|
2528
2402
|
}
|
|
2529
2403
|
arc(x, y, radius, startAngle, endAngle) {
|
|
2530
|
-
lib.symbols.canvas_path_arc(
|
|
2404
|
+
lib.symbols.canvas_path_arc(ptrs.get(this), x, y, radius, startAngle, endAngle);
|
|
2531
2405
|
}
|
|
2532
2406
|
ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise = false) {
|
|
2533
|
-
lib.symbols.canvas_path_ellipse(
|
|
2407
|
+
lib.symbols.canvas_path_ellipse(ptrs.get(this), x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
|
|
2534
2408
|
}
|
|
2535
2409
|
arcTo(x1, y1, x2, y2, radius) {
|
|
2536
|
-
lib.symbols.canvas_path_arc_to(
|
|
2410
|
+
lib.symbols.canvas_path_arc_to(ptrs.get(this), x1, y1, x2, y2, radius);
|
|
2537
2411
|
}
|
|
2538
2412
|
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
2539
|
-
lib.symbols.canvas_path_bezier_to(
|
|
2413
|
+
lib.symbols.canvas_path_bezier_to(ptrs.get(this), cp1x, cp1y, cp2x, cp2y, x, y);
|
|
2540
2414
|
}
|
|
2541
2415
|
quadraticCurveTo(cpx, cpy, x, y) {
|
|
2542
|
-
lib.symbols.canvas_path_quad_to(
|
|
2416
|
+
lib.symbols.canvas_path_quad_to(ptrs.get(this), cpx, cpy, x, y);
|
|
2543
2417
|
}
|
|
2544
2418
|
closePath() {
|
|
2545
|
-
lib.symbols.canvas_path_close(
|
|
2419
|
+
lib.symbols.canvas_path_close(ptrs.get(this));
|
|
2546
2420
|
}
|
|
2547
2421
|
rect(x, y, width, height) {
|
|
2548
|
-
lib.symbols.canvas_path_rect(
|
|
2422
|
+
lib.symbols.canvas_path_rect(ptrs.get(this), x, y, width, height);
|
|
2549
2423
|
}
|
|
2550
2424
|
roundRect(x, y, width, height, radii) {
|
|
2551
2425
|
if (radii.constructor.name.toLowerCase().includes("array")) {
|
|
@@ -2553,47 +2427,35 @@ class CanvasRenderingContext2D {
|
|
|
2553
2427
|
if (arr.some(Number.isNaN))
|
|
2554
2428
|
return;
|
|
2555
2429
|
const len = arr.length;
|
|
2556
|
-
lib.symbols.canvas_path_roundrect_array(
|
|
2430
|
+
lib.symbols.canvas_path_roundrect_array(ptrs.get(this), x, y, width, height, ptr3(arr), len);
|
|
2557
2431
|
return;
|
|
2558
2432
|
} else {
|
|
2559
|
-
lib.symbols.canvas_path_roundrect(
|
|
2433
|
+
lib.symbols.canvas_path_roundrect(ptrs.get(this), x, y, width, height, radii);
|
|
2560
2434
|
}
|
|
2561
2435
|
}
|
|
2562
2436
|
fill(path) {
|
|
2563
|
-
|
|
2437
|
+
let _ptr = path ? ptrs.get(path) : null;
|
|
2438
|
+
lib.symbols.canvas_path_fill(ptrs.get(this), _ptr);
|
|
2564
2439
|
}
|
|
2565
2440
|
stroke(path) {
|
|
2566
|
-
|
|
2441
|
+
let _ptr = path ? ptrs.get(path) : null;
|
|
2442
|
+
lib.symbols.canvas_path_stroke(ptrs.get(this), _ptr);
|
|
2567
2443
|
}
|
|
2568
2444
|
set shadowBlur(blur) {
|
|
2569
|
-
lib.symbols.canvas_set_shadow_blur(
|
|
2445
|
+
lib.symbols.canvas_set_shadow_blur(ptrs.get(this), blur);
|
|
2570
2446
|
}
|
|
2571
2447
|
set shadowColor(col) {
|
|
2572
|
-
lib.symbols.canvas_set_shadow_color(
|
|
2448
|
+
lib.symbols.canvas_set_shadow_color(ptrs.get(this), encoder.encode(`${col}\x00`));
|
|
2573
2449
|
}
|
|
2574
2450
|
set shadowOffsetX(x) {
|
|
2575
|
-
lib.symbols.canvas_set_shadow_offsetX(
|
|
2451
|
+
lib.symbols.canvas_set_shadow_offsetX(ptrs.get(this), x);
|
|
2576
2452
|
}
|
|
2577
2453
|
set shadowOffsetY(y) {
|
|
2578
|
-
lib.symbols.canvas_set_shadow_offsetY(
|
|
2454
|
+
lib.symbols.canvas_set_shadow_offsetY(ptrs.get(this), y);
|
|
2579
2455
|
}
|
|
2580
2456
|
set lineJoin(joinType) {
|
|
2581
|
-
let
|
|
2582
|
-
|
|
2583
|
-
case "round": {
|
|
2584
|
-
res = lib.symbols.canvas_set_line_join(ptrs3.get(this), 1);
|
|
2585
|
-
break;
|
|
2586
|
-
}
|
|
2587
|
-
case "bevel": {
|
|
2588
|
-
res = lib.symbols.canvas_set_line_join(ptrs3.get(this), 2);
|
|
2589
|
-
break;
|
|
2590
|
-
}
|
|
2591
|
-
case "miter": {
|
|
2592
|
-
res = lib.symbols.canvas_set_line_join(ptrs3.get(this), 3);
|
|
2593
|
-
break;
|
|
2594
|
-
}
|
|
2595
|
-
}
|
|
2596
|
-
if (res) {
|
|
2457
|
+
let ljType = CanvasLineJoin[joinType];
|
|
2458
|
+
if (lib.symbols.canvas_set_line_join(ptrs.get(this), ljType)) {
|
|
2597
2459
|
this.#currentState.lineJoin = joinType;
|
|
2598
2460
|
}
|
|
2599
2461
|
}
|
|
@@ -2605,41 +2467,41 @@ class CanvasRenderingContext2D {
|
|
|
2605
2467
|
const arr = new Float32Array(_arr);
|
|
2606
2468
|
const len = arr.length;
|
|
2607
2469
|
if (img instanceof Image) {
|
|
2608
|
-
lib.symbols.canvas_draw_image_imageType(
|
|
2470
|
+
lib.symbols.canvas_draw_image_imageType(ptrs.get(this), img.ptr, ptr3(arr), len);
|
|
2609
2471
|
return;
|
|
2610
2472
|
}
|
|
2611
2473
|
if (img instanceof Canvas) {
|
|
2612
|
-
lib.symbols.canvas_draw_image_canvasType(
|
|
2474
|
+
lib.symbols.canvas_draw_image_canvasType(ptrs.get(this), ptrs.get(img), ptr3(arr), len);
|
|
2613
2475
|
return;
|
|
2614
2476
|
}
|
|
2615
2477
|
throw new TypeError("Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(Image or Canvas)'.");
|
|
2616
2478
|
}
|
|
2617
2479
|
getImageData(x, y, w, h) {
|
|
2618
2480
|
const arr = new Uint8ClampedArray(w * h * 4);
|
|
2619
|
-
lib.symbols.canvas_get_image_data(
|
|
2481
|
+
lib.symbols.canvas_get_image_data(ptrs.get(this), x, y, w, h, ptr3(arr));
|
|
2620
2482
|
return new ImageData(arr, w, h);
|
|
2621
2483
|
}
|
|
2622
2484
|
putImageData(data, dx, dy, dirtyX = 0, dirtyY = 0, dirtyWidth = data.width, dirtyHeight = data.height) {
|
|
2623
2485
|
if (!(data instanceof ImageData)) {
|
|
2624
2486
|
throw new TypeError("Failed to execute 'putImageData' on 'CanvasRenderingContext2D': " + "parameter 1 is not of type 'ImageData'");
|
|
2625
2487
|
}
|
|
2626
|
-
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));
|
|
2627
2489
|
}
|
|
2628
2490
|
save() {
|
|
2629
2491
|
this.#savedState?.copyFrom(this.#currentState);
|
|
2630
|
-
lib.symbols.canvas_save(
|
|
2492
|
+
lib.symbols.canvas_save(ptrs.get(this));
|
|
2631
2493
|
}
|
|
2632
2494
|
restore() {
|
|
2633
2495
|
if (!this.#savedState)
|
|
2634
2496
|
return;
|
|
2635
2497
|
this.#currentState?.copyFrom(this.#savedState);
|
|
2636
|
-
lib.symbols.canvas_restore(
|
|
2498
|
+
lib.symbols.canvas_restore(ptrs.get(this));
|
|
2637
2499
|
}
|
|
2638
2500
|
translate(x, y) {
|
|
2639
|
-
lib.symbols.canvas_translate(
|
|
2501
|
+
lib.symbols.canvas_translate(ptrs.get(this), x, y);
|
|
2640
2502
|
}
|
|
2641
2503
|
rotate(deg) {
|
|
2642
|
-
lib.symbols.canvas_rotate(
|
|
2504
|
+
lib.symbols.canvas_rotate(ptrs.get(this), deg);
|
|
2643
2505
|
}
|
|
2644
2506
|
createConicGradient(...args) {
|
|
2645
2507
|
if (args.length < 3)
|
|
@@ -2658,18 +2520,18 @@ class CanvasRenderingContext2D {
|
|
|
2658
2520
|
}
|
|
2659
2521
|
getTransform() {
|
|
2660
2522
|
let arr = new Float32Array(16);
|
|
2661
|
-
lib.symbols.canvas_get_transform(
|
|
2523
|
+
lib.symbols.canvas_get_transform(ptrs.get(this), ptr3(arr));
|
|
2662
2524
|
return new DOMMatrix(arr);
|
|
2663
2525
|
}
|
|
2664
2526
|
setTransform(...args) {
|
|
2665
2527
|
if (args[0] instanceof DOMMatrix)
|
|
2666
|
-
lib.symbols.canvas_set_transform(
|
|
2528
|
+
lib.symbols.canvas_set_transform(ptrs.get(this), args[0].ptr);
|
|
2667
2529
|
if (args.length == 6) {
|
|
2668
2530
|
const mtx = new DOMMatrix([args[0], args[1], args[2], args[3], args[4], args[5]]);
|
|
2669
|
-
lib.symbols.canvas_set_transform(
|
|
2531
|
+
lib.symbols.canvas_set_transform(ptrs.get(this), mtx.ptr);
|
|
2670
2532
|
}
|
|
2671
2533
|
if (args.length == 16)
|
|
2672
|
-
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);
|
|
2673
2535
|
}
|
|
2674
2536
|
transform(a, b, c, d, e, f) {
|
|
2675
2537
|
const tf = this.getTransform();
|
|
@@ -2678,7 +2540,7 @@ class CanvasRenderingContext2D {
|
|
|
2678
2540
|
this.setTransform(tf);
|
|
2679
2541
|
}
|
|
2680
2542
|
resetTransform() {
|
|
2681
|
-
lib.symbols.canvas_reset_transform(
|
|
2543
|
+
lib.symbols.canvas_reset_transform(ptrs.get(this));
|
|
2682
2544
|
}
|
|
2683
2545
|
setLineDash(lines) {
|
|
2684
2546
|
if (lines.constructor.name.toLowerCase().includes("array")) {
|
|
@@ -2691,7 +2553,7 @@ class CanvasRenderingContext2D {
|
|
|
2691
2553
|
const arr = new Float32Array(_a);
|
|
2692
2554
|
if (arr.some(Number.isNaN))
|
|
2693
2555
|
return;
|
|
2694
|
-
lib.symbols.canvas_set_line_dash(
|
|
2556
|
+
lib.symbols.canvas_set_line_dash(ptrs.get(this), ptr3(arr), arr.length, this.#currentState.lineDashOffset);
|
|
2695
2557
|
this.#currentState.lineDash = _a;
|
|
2696
2558
|
return;
|
|
2697
2559
|
}
|
|
@@ -2701,7 +2563,7 @@ class CanvasRenderingContext2D {
|
|
|
2701
2563
|
return this.#currentState.lineDash;
|
|
2702
2564
|
}
|
|
2703
2565
|
clip() {
|
|
2704
|
-
lib.symbols.canvas_path_clip(
|
|
2566
|
+
lib.symbols.canvas_path_clip(ptrs.get(this));
|
|
2705
2567
|
}
|
|
2706
2568
|
set lineDashOffset(v) {
|
|
2707
2569
|
if (this.#currentState.lineDash.length <= 0) {
|
|
@@ -2709,61 +2571,28 @@ class CanvasRenderingContext2D {
|
|
|
2709
2571
|
return;
|
|
2710
2572
|
}
|
|
2711
2573
|
const arr = new Float32Array(this.#currentState.lineDash);
|
|
2712
|
-
lib.symbols.canvas_set_line_dash(
|
|
2574
|
+
lib.symbols.canvas_set_line_dash(ptrs.get(this), ptr3(arr), arr.length, v);
|
|
2713
2575
|
this.#currentState.lineDashOffset = v;
|
|
2714
2576
|
}
|
|
2715
2577
|
set textBaseline(baseline) {
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
case "hanging":
|
|
2722
|
-
bl = 1;
|
|
2723
|
-
break;
|
|
2724
|
-
case "middle":
|
|
2725
|
-
bl = 2;
|
|
2726
|
-
break;
|
|
2727
|
-
case "alphabetic":
|
|
2728
|
-
bl = 3;
|
|
2729
|
-
break;
|
|
2730
|
-
case "ideographic":
|
|
2731
|
-
bl = 4;
|
|
2732
|
-
break;
|
|
2733
|
-
case "bottom":
|
|
2734
|
-
bl = 5;
|
|
2735
|
-
break;
|
|
2736
|
-
}
|
|
2737
|
-
if (bl != -1) {
|
|
2738
|
-
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;
|
|
2739
2583
|
}
|
|
2740
2584
|
}
|
|
2741
2585
|
set textAlign(alignment) {
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
case "right":
|
|
2748
|
-
al = 1;
|
|
2749
|
-
break;
|
|
2750
|
-
case "center":
|
|
2751
|
-
al = 2;
|
|
2752
|
-
break;
|
|
2753
|
-
case "start":
|
|
2754
|
-
al = 3;
|
|
2755
|
-
break;
|
|
2756
|
-
case "end":
|
|
2757
|
-
al = 4;
|
|
2758
|
-
break;
|
|
2759
|
-
}
|
|
2760
|
-
if (al != -1) {
|
|
2761
|
-
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;
|
|
2762
2591
|
}
|
|
2763
2592
|
}
|
|
2764
2593
|
measureText(text) {
|
|
2765
2594
|
const pArr = new Float32Array(12);
|
|
2766
|
-
lib.symbols.canvas_measure_text(
|
|
2595
|
+
lib.symbols.canvas_measure_text(ptrs.get(this), encoder.encode(`${text}\x00`), ptr3(pArr));
|
|
2767
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]);
|
|
2768
2597
|
}
|
|
2769
2598
|
constructor(iptr, cnv, args, token) {
|
|
@@ -2776,7 +2605,7 @@ class CanvasRenderingContext2D {
|
|
|
2776
2605
|
});
|
|
2777
2606
|
const renderContextPtr = lib.symbols.canvas_get_context2D(iptr, cb.ptr, desynchronized, alpha);
|
|
2778
2607
|
this.#owner = cnv;
|
|
2779
|
-
|
|
2608
|
+
ptrs.set(this, renderContextPtr);
|
|
2780
2609
|
}
|
|
2781
2610
|
}
|
|
2782
2611
|
{
|
|
@@ -2803,23 +2632,27 @@ class Canvas {
|
|
|
2803
2632
|
constructor(w = 1, h = 1, options) {
|
|
2804
2633
|
this.#dim[0] = w;
|
|
2805
2634
|
this.#dim[1] = h;
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
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);
|
|
2809
2642
|
canvasFinalizationRegistry.register(this, ptr);
|
|
2810
2643
|
}
|
|
2811
2644
|
get _ptr() {
|
|
2812
|
-
return
|
|
2645
|
+
return ptrs.get(this);
|
|
2813
2646
|
}
|
|
2814
2647
|
set width(v) {
|
|
2815
2648
|
this.#dim[0] = Number.parseInt(v);
|
|
2816
2649
|
this.#rCapture.cb();
|
|
2817
|
-
lib.symbols.canvas_resize(
|
|
2650
|
+
lib.symbols.canvas_resize(ptrs.get(this), this.#dim[0], this.#dim[1]);
|
|
2818
2651
|
}
|
|
2819
2652
|
set height(v) {
|
|
2820
2653
|
this.#dim[1] = Number.parseInt(v);
|
|
2821
2654
|
this.#rCapture.cb();
|
|
2822
|
-
lib.symbols.canvas_resize(
|
|
2655
|
+
lib.symbols.canvas_resize(ptrs.get(this), this.#dim[0], this.#dim[1]);
|
|
2823
2656
|
}
|
|
2824
2657
|
get width() {
|
|
2825
2658
|
return this.#dim[0];
|
|
@@ -2829,7 +2662,7 @@ class Canvas {
|
|
|
2829
2662
|
}
|
|
2830
2663
|
getContext(contextType, args) {
|
|
2831
2664
|
if (contextType == "2d") {
|
|
2832
|
-
return new CanvasRenderingContext2D(
|
|
2665
|
+
return new CanvasRenderingContext2D(ptrs.get(this), this, args, INTERNAL_TOKEN);
|
|
2833
2666
|
}
|
|
2834
2667
|
}
|
|
2835
2668
|
getBoundingClientRect() {
|
|
@@ -2865,43 +2698,45 @@ import { ptr as ptr4 } from "bun:ffi";
|
|
|
2865
2698
|
var p2dFinalizationRegistry = new FinalizationRegistry((ptr) => {
|
|
2866
2699
|
lib.symbols.path2d_destroy(ptr);
|
|
2867
2700
|
});
|
|
2868
|
-
var ptrs4 = new WeakMap;
|
|
2869
2701
|
|
|
2870
2702
|
class Path2D {
|
|
2871
2703
|
constructor(path) {
|
|
2872
2704
|
if (path && path instanceof Path2D) {
|
|
2873
|
-
let
|
|
2874
|
-
|
|
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);
|
|
2875
2710
|
p2dFinalizationRegistry.register(this, _ptr);
|
|
2876
2711
|
} else {
|
|
2877
2712
|
let _ptr = lib.symbols.path2d_create();
|
|
2878
|
-
|
|
2713
|
+
ptrs.set(this, _ptr);
|
|
2879
2714
|
p2dFinalizationRegistry.register(this, _ptr);
|
|
2880
2715
|
}
|
|
2881
2716
|
}
|
|
2882
2717
|
moveTo(x, y) {
|
|
2883
|
-
lib.symbols.path2d_move_to(
|
|
2718
|
+
lib.symbols.path2d_move_to(ptrs.get(this), x, y);
|
|
2884
2719
|
}
|
|
2885
2720
|
lineTo(x, y) {
|
|
2886
|
-
lib.symbols.path2d_line_to(
|
|
2721
|
+
lib.symbols.path2d_line_to(ptrs.get(this), x, y);
|
|
2887
2722
|
}
|
|
2888
2723
|
arc(x, y, radius, startAngle, endAngle) {
|
|
2889
|
-
lib.symbols.path2d_arc(
|
|
2724
|
+
lib.symbols.path2d_arc(ptrs.get(this), x, y, radius, startAngle, endAngle);
|
|
2890
2725
|
}
|
|
2891
2726
|
ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise = false) {
|
|
2892
|
-
lib.symbols.path2d_ellipse(
|
|
2727
|
+
lib.symbols.path2d_ellipse(ptrs.get(this), x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
|
|
2893
2728
|
}
|
|
2894
2729
|
arcTo(x1, y1, x2, y2, radius) {
|
|
2895
|
-
lib.symbols.path2d_arc_to(
|
|
2730
|
+
lib.symbols.path2d_arc_to(ptrs.get(this), x1, y1, x2, y2, radius);
|
|
2896
2731
|
}
|
|
2897
2732
|
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
2898
|
-
lib.symbols.path2d_bezier_to(
|
|
2733
|
+
lib.symbols.path2d_bezier_to(ptrs.get(this), cp1x, cp1y, cp2x, cp2y, x, y);
|
|
2899
2734
|
}
|
|
2900
2735
|
quadraticCurveTo(cpx, cpy, x, y) {
|
|
2901
|
-
lib.symbols.path2d_quad_to(
|
|
2736
|
+
lib.symbols.path2d_quad_to(ptrs.get(this), cpx, cpy, x, y);
|
|
2902
2737
|
}
|
|
2903
2738
|
rect(x, y, width, height) {
|
|
2904
|
-
lib.symbols.path2d_rect(
|
|
2739
|
+
lib.symbols.path2d_rect(ptrs.get(this), x, y, width, height);
|
|
2905
2740
|
}
|
|
2906
2741
|
roundRect(x, y, width, height, radii) {
|
|
2907
2742
|
if (radii.constructor.name.toLowerCase().includes("array")) {
|
|
@@ -2909,25 +2744,22 @@ class Path2D {
|
|
|
2909
2744
|
if (arr.some(Number.isNaN))
|
|
2910
2745
|
return;
|
|
2911
2746
|
const len = arr.length;
|
|
2912
|
-
lib.symbols.path2d_roundrect_array(
|
|
2747
|
+
lib.symbols.path2d_roundrect_array(ptrs.get(this), x, y, width, height, ptr4(arr), len);
|
|
2913
2748
|
return;
|
|
2914
2749
|
} else {
|
|
2915
|
-
lib.symbols.path2d_rect(
|
|
2750
|
+
lib.symbols.path2d_rect(ptrs.get(this), x, y, width, height, radii);
|
|
2916
2751
|
}
|
|
2917
2752
|
}
|
|
2918
2753
|
closePath() {
|
|
2919
|
-
lib.symbols.path2d_close(
|
|
2920
|
-
}
|
|
2921
|
-
get ptr() {
|
|
2922
|
-
return ptrs4.get(this);
|
|
2754
|
+
lib.symbols.path2d_close(ptrs.get(this));
|
|
2923
2755
|
}
|
|
2924
2756
|
}
|
|
2925
|
-
var
|
|
2926
|
-
for (const key of Object.getOwnPropertyNames(
|
|
2927
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
2757
|
+
var proto2 = Path2D.prototype;
|
|
2758
|
+
for (const key of Object.getOwnPropertyNames(proto2)) {
|
|
2759
|
+
const desc = Object.getOwnPropertyDescriptor(proto2, key);
|
|
2928
2760
|
if (key == "constructor") {
|
|
2929
2761
|
desc && (desc.value.toString = () => {
|
|
2930
|
-
return `function ${
|
|
2762
|
+
return `function ${proto2.constructor.name}() { [native code] }`;
|
|
2931
2763
|
});
|
|
2932
2764
|
continue;
|
|
2933
2765
|
}
|
|
@@ -2965,183 +2797,642 @@ self.onmessage = (msg)=>{
|
|
|
2965
2797
|
|
|
2966
2798
|
`;
|
|
2967
2799
|
|
|
2968
|
-
// BunCanvas/
|
|
2969
|
-
var
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
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));
|
|
3260
|
+
#mMoveViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mMoveViewer(), 0, 9 * 8));
|
|
3261
|
+
#mClickViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mClickViewer(), 0, 9 * 8));
|
|
3262
|
+
#mDownViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mDownViewer(), 0, 9 * 8));
|
|
2991
3263
|
#mUpViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mUpViewer(), 0, 9 * 8));
|
|
2992
3264
|
#kDownViewer = new Int32Array(toArrayBuffer(lib.symbols.get_kDownViewer(), 0, 7 * 4));
|
|
2993
3265
|
#kUpViewer = new Int32Array(toArrayBuffer(lib.symbols.get_kUpViewer(), 0, 7 * 4));
|
|
3266
|
+
#wFocusBlurViewer = new Int32Array(toArrayBuffer(lib.symbols.get_wFocusBlurViewer(), 0, 2 * 4));
|
|
2994
3267
|
#mWheelViewer = new Float64Array(toArrayBuffer(lib.symbols.get_mWheelViewer(), 0, 5 * 8));
|
|
2995
|
-
#
|
|
2996
|
-
|
|
2997
|
-
|
|
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
|
+
}
|
|
2998
3302
|
#processEvents() {
|
|
2999
|
-
if (this.#wPropertiesViewer[0]
|
|
3303
|
+
if (this.#wPropertiesViewer[0] !== 0) {
|
|
3000
3304
|
this.#wPropertiesViewer[0] = 0;
|
|
3001
|
-
const details = new Event("resize"
|
|
3002
|
-
|
|
3003
|
-
this.onresize(details);
|
|
3004
|
-
this.#rEvts.forEach((item, key) => {
|
|
3005
|
-
item.cb(details);
|
|
3006
|
-
});
|
|
3305
|
+
const details = new Event("resize");
|
|
3306
|
+
this.dispatchEvent(details);
|
|
3007
3307
|
}
|
|
3008
|
-
if (this.#mMoveViewer[0]
|
|
3308
|
+
if (this.#mMoveViewer[0] !== 0) {
|
|
3009
3309
|
this.#mMoveViewer[0] = 0;
|
|
3010
|
-
const evt = new MouseEvent("
|
|
3011
|
-
target: this,
|
|
3012
|
-
altKey: false,
|
|
3310
|
+
const evt = new MouseEvent("mousemove", {
|
|
3013
3311
|
button: 0,
|
|
3014
3312
|
buttons: this.#mMoveViewer[5],
|
|
3015
3313
|
clientX: this.#mMoveViewer[1],
|
|
3016
3314
|
clientY: this.#mMoveViewer[2],
|
|
3017
3315
|
movementX: this.#mMoveViewer[3],
|
|
3018
3316
|
movementY: this.#mMoveViewer[4],
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
this.#mMoveEvts.forEach((item, key) => {
|
|
3028
|
-
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
|
|
3029
3325
|
});
|
|
3326
|
+
this.dispatchEvent(evt);
|
|
3030
3327
|
}
|
|
3031
|
-
if (this.#mDownViewer[0]
|
|
3328
|
+
if (this.#mDownViewer[0] !== 0) {
|
|
3032
3329
|
this.#mDownViewer[0] = 0;
|
|
3033
|
-
const evt = new MouseEvent("
|
|
3034
|
-
target: this,
|
|
3035
|
-
altKey: this.#mDownViewer[7],
|
|
3036
|
-
button: this.#mDownViewer[3],
|
|
3037
|
-
buttons: this.#mDownViewer[4],
|
|
3330
|
+
const evt = new MouseEvent("mousedown", {
|
|
3038
3331
|
clientX: this.#mDownViewer[1],
|
|
3039
3332
|
clientY: this.#mDownViewer[2],
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
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]),
|
|
3044
3339
|
screenX: this.#mDownViewer[1],
|
|
3045
3340
|
screenY: this.#mDownViewer[2],
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
if (this.onmousedown)
|
|
3049
|
-
this.onmousedown(evt);
|
|
3050
|
-
this.#mDownEvts.forEach((item, key) => {
|
|
3051
|
-
item.cb(evt);
|
|
3341
|
+
bubbles: true,
|
|
3342
|
+
cancelable: true
|
|
3052
3343
|
});
|
|
3344
|
+
this.dispatchEvent(evt);
|
|
3053
3345
|
}
|
|
3054
|
-
if (this.#mUpViewer[0]
|
|
3346
|
+
if (this.#mUpViewer[0] !== 0) {
|
|
3055
3347
|
this.#mUpViewer[0] = 0;
|
|
3056
|
-
const evt = new MouseEvent("
|
|
3057
|
-
target: this,
|
|
3058
|
-
altKey: this.#mUpViewer[7],
|
|
3059
|
-
button: this.#mUpViewer[3],
|
|
3060
|
-
buttons: this.#mUpViewer[4],
|
|
3348
|
+
const evt = new MouseEvent("mouseup", {
|
|
3061
3349
|
clientX: this.#mUpViewer[1],
|
|
3062
3350
|
clientY: this.#mUpViewer[2],
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
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]),
|
|
3067
3357
|
screenX: this.#mUpViewer[1],
|
|
3068
3358
|
screenY: this.#mUpViewer[2],
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
if (this.onmouseup)
|
|
3072
|
-
this.onmouseup(evt);
|
|
3073
|
-
this.#mMUpEvts.forEach((item, key) => {
|
|
3074
|
-
item.cb(evt);
|
|
3359
|
+
bubbles: true,
|
|
3360
|
+
cancelable: true
|
|
3075
3361
|
});
|
|
3362
|
+
this.dispatchEvent(evt);
|
|
3076
3363
|
}
|
|
3077
|
-
if (this.#mClickViewer[0]
|
|
3364
|
+
if (this.#mClickViewer[0] !== 0) {
|
|
3078
3365
|
this.#mClickViewer[0] = 0;
|
|
3079
3366
|
const evt = new MouseEvent("click", {
|
|
3080
|
-
target: this,
|
|
3081
|
-
altKey: this.#mClickViewer[7],
|
|
3082
|
-
button: this.#mClickViewer[3],
|
|
3083
|
-
buttons: this.#mClickViewer[4],
|
|
3084
3367
|
clientX: this.#mClickViewer[1],
|
|
3085
3368
|
clientY: this.#mClickViewer[2],
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
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]),
|
|
3090
3375
|
screenX: this.#mClickViewer[1],
|
|
3091
3376
|
screenY: this.#mClickViewer[2],
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
this.onclick(evt);
|
|
3096
|
-
this.#mClickEvts.forEach((item, key) => {
|
|
3097
|
-
item.cb(evt);
|
|
3377
|
+
detail: 1,
|
|
3378
|
+
bubbles: true,
|
|
3379
|
+
cancelable: true
|
|
3098
3380
|
});
|
|
3381
|
+
this.dispatchEvent(evt);
|
|
3099
3382
|
}
|
|
3100
|
-
if (this.#mWheelViewer[0]
|
|
3383
|
+
if (this.#mWheelViewer[0] !== 0) {
|
|
3101
3384
|
this.#mWheelViewer[0] = 0;
|
|
3102
3385
|
const evt = new WheelEvent("wheel", {
|
|
3103
|
-
target: this,
|
|
3104
|
-
altKey: this.#mMoveViewer[7],
|
|
3105
|
-
button: this.#mWheelViewer[3],
|
|
3106
|
-
buttons: this.#mWheelViewer[4],
|
|
3107
|
-
clientX: this.#mMoveViewer[3],
|
|
3108
|
-
clientY: this.#mMoveViewer[4],
|
|
3109
3386
|
deltaX: -this.#mWheelViewer[1] * 120,
|
|
3110
3387
|
deltaY: -this.#mWheelViewer[2] * 120,
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
this
|
|
3121
|
-
|
|
3122
|
-
|
|
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
|
|
3123
3401
|
});
|
|
3402
|
+
this.dispatchEvent(evt);
|
|
3124
3403
|
}
|
|
3125
|
-
if (this.#kDownViewer[0]
|
|
3404
|
+
if (this.#kDownViewer[0] !== 0) {
|
|
3126
3405
|
this.#kDownViewer[0] = 0;
|
|
3127
|
-
const evt =
|
|
3128
|
-
|
|
3129
|
-
this.onkeydown(evt);
|
|
3130
|
-
this.#keyDownEvts.forEach((item, key) => {
|
|
3131
|
-
item.cb(evt);
|
|
3132
|
-
});
|
|
3406
|
+
const evt = this.#createKeyboardEvent("keydown", this.#kDownViewer);
|
|
3407
|
+
this.dispatchEvent(evt);
|
|
3133
3408
|
}
|
|
3134
|
-
if (this.#kUpViewer[0]
|
|
3409
|
+
if (this.#kUpViewer[0] !== 0) {
|
|
3135
3410
|
this.#kUpViewer[0] = 0;
|
|
3136
|
-
const evt =
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
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"));
|
|
3142
3421
|
}
|
|
3143
3422
|
}
|
|
3144
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
|
+
}
|
|
3145
3436
|
#vsync = true;
|
|
3146
3437
|
get vsync() {
|
|
3147
3438
|
return this.#vsync;
|
|
@@ -3157,14 +3448,6 @@ class Window {
|
|
|
3157
3448
|
lib.symbols.font_add_to_registry(encoder.encode(`${font.family}\x00`), font._nativePtr);
|
|
3158
3449
|
}
|
|
3159
3450
|
};
|
|
3160
|
-
onresize = null;
|
|
3161
|
-
onmousemove = null;
|
|
3162
|
-
onmousedown = null;
|
|
3163
|
-
onmouseup = null;
|
|
3164
|
-
onclick = null;
|
|
3165
|
-
onkeydown = null;
|
|
3166
|
-
onkeyup = null;
|
|
3167
|
-
onwheel = null;
|
|
3168
3451
|
get innerWidth() {
|
|
3169
3452
|
return this.#wPropertiesViewer[1];
|
|
3170
3453
|
}
|
|
@@ -3172,9 +3455,13 @@ class Window {
|
|
|
3172
3455
|
return this.#wPropertiesViewer[2];
|
|
3173
3456
|
}
|
|
3174
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
|
+
}
|
|
3175
3463
|
if (process.platform !== "darwin")
|
|
3176
3464
|
render_thread.ref?.();
|
|
3177
|
-
windowWasCreated = true;
|
|
3178
3465
|
this.#wPropertiesViewer[1] = width;
|
|
3179
3466
|
this.#wPropertiesViewer[2] = height;
|
|
3180
3467
|
const { vsync = true, maxFramerate = 0 } = args ?? {};
|
|
@@ -3209,6 +3496,8 @@ class Window {
|
|
|
3209
3496
|
if (frameSignal === 1) {
|
|
3210
3497
|
lib.symbols.create_window(width, height, titleBuf);
|
|
3211
3498
|
}
|
|
3499
|
+
};
|
|
3500
|
+
const loop = () => {
|
|
3212
3501
|
lib.symbols.signal_frame_ready();
|
|
3213
3502
|
const frameInterval = this.maxFramerate > 0 ? 1000 / this.maxFramerate : 0;
|
|
3214
3503
|
const now = performance.now();
|
|
@@ -3234,7 +3523,9 @@ class Window {
|
|
|
3234
3523
|
}
|
|
3235
3524
|
}
|
|
3236
3525
|
this.#processEvents();
|
|
3526
|
+
setImmediate(loop);
|
|
3237
3527
|
};
|
|
3528
|
+
setImmediate(loop);
|
|
3238
3529
|
} else {
|
|
3239
3530
|
let aaplLib = dlopen2(dlPath, {
|
|
3240
3531
|
setup_render_thread: {
|
|
@@ -3272,81 +3563,6 @@ class Window {
|
|
|
3272
3563
|
loop();
|
|
3273
3564
|
}
|
|
3274
3565
|
}
|
|
3275
|
-
addEventListener(name, fn) {
|
|
3276
|
-
const pop = this.#freeIndex.pop();
|
|
3277
|
-
const usedIndex = pop != null ? pop : this.#eIndex;
|
|
3278
|
-
if (usedIndex == this.#eIndex)
|
|
3279
|
-
this.#eIndex++;
|
|
3280
|
-
if (name == "resize") {
|
|
3281
|
-
this.#rEvts.set(usedIndex, { name, cb: fn });
|
|
3282
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3283
|
-
} else if (name == "mousemove") {
|
|
3284
|
-
this.#mMoveEvts.set(usedIndex, { name, cb: fn });
|
|
3285
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3286
|
-
} else if (name == "mousedown") {
|
|
3287
|
-
this.#mDownEvts.set(usedIndex, { name, cb: fn });
|
|
3288
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3289
|
-
} else if (name == "mouseup") {
|
|
3290
|
-
this.#mMUpEvts.set(usedIndex, { name, cb: fn });
|
|
3291
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3292
|
-
} else if (name == "wheel") {
|
|
3293
|
-
this.#mWheelEvts.set(usedIndex, { name, cb: fn });
|
|
3294
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3295
|
-
} else if (name == "click") {
|
|
3296
|
-
this.#mClickEvts.set(usedIndex, { name, cb: fn });
|
|
3297
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3298
|
-
} else if (name == "keydown") {
|
|
3299
|
-
this.#keyDownEvts.set(usedIndex, { name, cb: fn });
|
|
3300
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3301
|
-
} else if (name == "keyup") {
|
|
3302
|
-
this.#keyUpEvts.set(usedIndex, { name, cb: fn });
|
|
3303
|
-
this.#evtDetails.set(fn, usedIndex);
|
|
3304
|
-
}
|
|
3305
|
-
}
|
|
3306
|
-
removeEventListener(name, fn) {
|
|
3307
|
-
const det = this.#evtDetails.get(fn);
|
|
3308
|
-
if (name == "resize") {
|
|
3309
|
-
if (det != null) {
|
|
3310
|
-
this.#rEvts.delete(det);
|
|
3311
|
-
this.#evtDetails.delete(fn);
|
|
3312
|
-
}
|
|
3313
|
-
} else if (name == "mousemove") {
|
|
3314
|
-
if (det != null) {
|
|
3315
|
-
this.#mMoveEvts.delete(det);
|
|
3316
|
-
this.#evtDetails.delete(fn);
|
|
3317
|
-
}
|
|
3318
|
-
} else if (name == "mousedown") {
|
|
3319
|
-
if (det != null) {
|
|
3320
|
-
this.#mDownEvts.delete(det);
|
|
3321
|
-
this.#evtDetails.delete(fn);
|
|
3322
|
-
}
|
|
3323
|
-
} else if (name == "mouseup") {
|
|
3324
|
-
if (det != null) {
|
|
3325
|
-
this.#mMUpEvts.delete(det);
|
|
3326
|
-
this.#evtDetails.delete(fn);
|
|
3327
|
-
}
|
|
3328
|
-
} else if (name == "wheel") {
|
|
3329
|
-
if (det != null) {
|
|
3330
|
-
this.#mWheelEvts.delete(det);
|
|
3331
|
-
this.#evtDetails.delete(fn);
|
|
3332
|
-
}
|
|
3333
|
-
} else if (name == "click") {
|
|
3334
|
-
if (det != null) {
|
|
3335
|
-
this.#mClickEvts.delete(det);
|
|
3336
|
-
this.#evtDetails.delete(fn);
|
|
3337
|
-
}
|
|
3338
|
-
} else if (name == "keydown") {
|
|
3339
|
-
if (det != null) {
|
|
3340
|
-
this.#keyDownEvts.delete(det);
|
|
3341
|
-
this.#evtDetails.delete(fn);
|
|
3342
|
-
}
|
|
3343
|
-
} else if (name == "keyup") {
|
|
3344
|
-
if (det != null) {
|
|
3345
|
-
this.#keyUpEvts.delete(det);
|
|
3346
|
-
this.#evtDetails.delete(fn);
|
|
3347
|
-
}
|
|
3348
|
-
}
|
|
3349
|
-
}
|
|
3350
3566
|
append(canvas) {
|
|
3351
3567
|
const canvasPtr = canvas._ptr;
|
|
3352
3568
|
if (canvasPtr == undefined) {
|
|
@@ -3355,6 +3571,11 @@ class Window {
|
|
|
3355
3571
|
}
|
|
3356
3572
|
lib.symbols.canvas_append(canvasPtr);
|
|
3357
3573
|
}
|
|
3574
|
+
requestAnimationFrame(callback) {
|
|
3575
|
+
setImmediate(() => {
|
|
3576
|
+
requestedFrames.push(callback);
|
|
3577
|
+
});
|
|
3578
|
+
}
|
|
3358
3579
|
}
|
|
3359
3580
|
{
|
|
3360
3581
|
const proto = Window.prototype;
|
|
@@ -3372,46 +3593,46 @@ class Window {
|
|
|
3372
3593
|
}
|
|
3373
3594
|
}
|
|
3374
3595
|
var rAf;
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
});
|
|
3382
|
-
};
|
|
3383
|
-
rAf.toString = () => `function requestAnimationFrame() { [native code] }`;
|
|
3384
|
-
}
|
|
3596
|
+
rAf = function requestAnimationFrame(callback) {
|
|
3597
|
+
setImmediate(() => {
|
|
3598
|
+
requestedFrames.push(callback);
|
|
3599
|
+
});
|
|
3600
|
+
};
|
|
3601
|
+
rAf.toString = () => `function requestAnimationFrame() { [native code] }`;
|
|
3385
3602
|
var requestAnimationFrame = rAf;
|
|
3386
3603
|
// BunCanvas/src/Audio.ts
|
|
3387
|
-
var
|
|
3604
|
+
var ptrs3 = new WeakMap;
|
|
3388
3605
|
lib.symbols.audio_backend_init();
|
|
3389
3606
|
|
|
3390
3607
|
class Audio {
|
|
3391
3608
|
constructor(path) {
|
|
3392
3609
|
if (path) {
|
|
3393
|
-
|
|
3610
|
+
ptrs3.set(this, lib.symbols.audio_create(encoder.encode(`${path}\x00`)));
|
|
3394
3611
|
} else {
|
|
3395
|
-
|
|
3612
|
+
ptrs3.set(this, lib.symbols.audio_create());
|
|
3396
3613
|
}
|
|
3397
3614
|
}
|
|
3398
3615
|
set src(v) {
|
|
3399
3616
|
lib.symbols.audio_set_src(encodeCString(v));
|
|
3400
3617
|
}
|
|
3401
3618
|
play() {
|
|
3402
|
-
lib.symbols.audio_play(
|
|
3619
|
+
lib.symbols.audio_play(ptrs3.get(this));
|
|
3403
3620
|
}
|
|
3404
3621
|
stop() {
|
|
3405
|
-
lib.symbols.audio_stop(
|
|
3622
|
+
lib.symbols.audio_stop(ptrs3.get(this));
|
|
3406
3623
|
}
|
|
3407
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
|
+
}
|
|
3408
3630
|
export {
|
|
3409
3631
|
Audio,
|
|
3410
3632
|
Canvas,
|
|
3411
3633
|
CanvasGradient,
|
|
3412
3634
|
CanvasRenderingContext2D,
|
|
3413
3635
|
DOMMatrix,
|
|
3414
|
-
Event,
|
|
3415
3636
|
FontFace,
|
|
3416
3637
|
Image,
|
|
3417
3638
|
KeyboardEvent,
|