@gjsify/canvas2d 0.36.0 → 0.37.0
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/lib/types/canvas2d-bridge.d.ts +44 -78
- package/package.json +8 -8
|
@@ -9,23 +9,19 @@ import '@gjsify/canvas2d-core/gdk';
|
|
|
9
9
|
import type { CanvasRenderingContext2D } from '@gjsify/canvas2d-core';
|
|
10
10
|
type Canvas2DReadyCallback = (canvas: globalThis.HTMLCanvasElement, ctx: CanvasRenderingContext2D) => void;
|
|
11
11
|
/**
|
|
12
|
-
* A `Gtk.DrawingArea` subclass that
|
|
13
|
-
*
|
|
14
|
-
* - Blits the Canvas 2D Cairo.ImageSurface onto the DrawingArea each frame
|
|
15
|
-
* - Fires `onReady()` callbacks with (canvas, ctx) once the context is available
|
|
16
|
-
* - Provides `requestAnimationFrame()` backed by GTK frame clock (vsync)
|
|
17
|
-
* - `installGlobals()` sets `globalThis.requestAnimationFrame` and `globalThis.performance`
|
|
12
|
+
* A `Gtk.DrawingArea` subclass that creates an `HTMLCanvasElement` +
|
|
13
|
+
* `CanvasRenderingContext2D` on first draw and blits its Cairo surface each frame.
|
|
18
14
|
*
|
|
19
|
-
*
|
|
15
|
+
* `installGlobals()` must run BEFORE the app code that expects the browser globals:
|
|
20
16
|
* ```ts
|
|
21
17
|
* const widget = new Canvas2DBridge();
|
|
22
|
-
* widget.installGlobals();
|
|
23
|
-
* widget.onReady((canvas, ctx) => {
|
|
24
|
-
* ctx.fillStyle = 'red';
|
|
25
|
-
* ctx.fillRect(0, 0, 100, 100);
|
|
26
|
-
* });
|
|
18
|
+
* widget.installGlobals();
|
|
19
|
+
* widget.onReady((canvas, ctx) => { … });
|
|
27
20
|
* window.set_child(widget);
|
|
28
21
|
* ```
|
|
22
|
+
*
|
|
23
|
+
* No custom 'resize' signal: the one inherited from Gtk.Widget has the same shape as
|
|
24
|
+
* Gtk.GLArea's, so `widget.connect('resize', …)` is one pattern across both bridges.
|
|
29
25
|
*/
|
|
30
26
|
export declare const Canvas2DBridge: {
|
|
31
27
|
new (...args: any[]): GObject.RegisteredPrototype<{
|
|
@@ -40,23 +36,18 @@ export declare const Canvas2DBridge: {
|
|
|
40
36
|
_onDraw(_area: Gtk.DrawingArea, cr: Cairo.Context, width: number, height: number): void;
|
|
41
37
|
/** The HTMLCanvasElement backing this widget. Available after the first draw. */
|
|
42
38
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
43
|
-
/**
|
|
39
|
+
/** The 2D rendering context; available after the first draw. */
|
|
44
40
|
getContext(_id: "2d"): CanvasRenderingContext2D | null;
|
|
45
|
-
/**
|
|
46
|
-
* Register a callback to be invoked once the Canvas 2D context is ready.
|
|
47
|
-
* If the context is already available, the callback fires synchronously.
|
|
48
|
-
*/
|
|
41
|
+
/** Runs `cb` once the 2D context is ready — synchronously if it already is. */
|
|
49
42
|
onReady(cb: Canvas2DReadyCallback): void;
|
|
50
43
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* Call `queue_draw()` after re-rendering to push the new surface to screen.
|
|
44
|
+
* Runs `cb` on every GTK resize, with the canvas dimensions already updated. Call
|
|
45
|
+
* `queue_draw()` after re-rendering to push the new surface to screen.
|
|
54
46
|
*/
|
|
55
47
|
onResize(cb: (width: number, height: number) => void): void;
|
|
56
48
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* Returns 0 (handle — cancel not yet implemented).
|
|
49
|
+
* Browser `requestAnimationFrame`, driven by the vsync-synced GTK frame clock.
|
|
50
|
+
* Always returns 0: there is no `cancelAnimationFrame` here to hand a handle to.
|
|
60
51
|
*/
|
|
61
52
|
requestAnimationFrame(cb: FrameRequestCallback): number;
|
|
62
53
|
/**
|
|
@@ -468,23 +459,18 @@ export declare const Canvas2DBridge: {
|
|
|
468
459
|
_onDraw(_area: Gtk.DrawingArea, cr: Cairo.Context, width: number, height: number): void;
|
|
469
460
|
/** The HTMLCanvasElement backing this widget. Available after the first draw. */
|
|
470
461
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
471
|
-
/**
|
|
462
|
+
/** The 2D rendering context; available after the first draw. */
|
|
472
463
|
getContext(_id: "2d"): CanvasRenderingContext2D | null;
|
|
473
|
-
/**
|
|
474
|
-
* Register a callback to be invoked once the Canvas 2D context is ready.
|
|
475
|
-
* If the context is already available, the callback fires synchronously.
|
|
476
|
-
*/
|
|
464
|
+
/** Runs `cb` once the 2D context is ready — synchronously if it already is. */
|
|
477
465
|
onReady(cb: Canvas2DReadyCallback): void;
|
|
478
466
|
/**
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
* Call `queue_draw()` after re-rendering to push the new surface to screen.
|
|
467
|
+
* Runs `cb` on every GTK resize, with the canvas dimensions already updated. Call
|
|
468
|
+
* `queue_draw()` after re-rendering to push the new surface to screen.
|
|
482
469
|
*/
|
|
483
470
|
onResize(cb: (width: number, height: number) => void): void;
|
|
484
471
|
/**
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
* Returns 0 (handle — cancel not yet implemented).
|
|
472
|
+
* Browser `requestAnimationFrame`, driven by the vsync-synced GTK frame clock.
|
|
473
|
+
* Always returns 0: there is no `cancelAnimationFrame` here to hand a handle to.
|
|
488
474
|
*/
|
|
489
475
|
requestAnimationFrame(cb: FrameRequestCallback): number;
|
|
490
476
|
/**
|
|
@@ -896,23 +882,18 @@ export declare const Canvas2DBridge: {
|
|
|
896
882
|
_onDraw(_area: Gtk.DrawingArea, cr: Cairo.Context, width: number, height: number): void;
|
|
897
883
|
/** The HTMLCanvasElement backing this widget. Available after the first draw. */
|
|
898
884
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
899
|
-
/**
|
|
885
|
+
/** The 2D rendering context; available after the first draw. */
|
|
900
886
|
getContext(_id: "2d"): CanvasRenderingContext2D | null;
|
|
901
|
-
/**
|
|
902
|
-
* Register a callback to be invoked once the Canvas 2D context is ready.
|
|
903
|
-
* If the context is already available, the callback fires synchronously.
|
|
904
|
-
*/
|
|
887
|
+
/** Runs `cb` once the 2D context is ready — synchronously if it already is. */
|
|
905
888
|
onReady(cb: Canvas2DReadyCallback): void;
|
|
906
889
|
/**
|
|
907
|
-
*
|
|
908
|
-
*
|
|
909
|
-
* Call `queue_draw()` after re-rendering to push the new surface to screen.
|
|
890
|
+
* Runs `cb` on every GTK resize, with the canvas dimensions already updated. Call
|
|
891
|
+
* `queue_draw()` after re-rendering to push the new surface to screen.
|
|
910
892
|
*/
|
|
911
893
|
onResize(cb: (width: number, height: number) => void): void;
|
|
912
894
|
/**
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
* Returns 0 (handle — cancel not yet implemented).
|
|
895
|
+
* Browser `requestAnimationFrame`, driven by the vsync-synced GTK frame clock.
|
|
896
|
+
* Always returns 0: there is no `cancelAnimationFrame` here to hand a handle to.
|
|
916
897
|
*/
|
|
917
898
|
requestAnimationFrame(cb: FrameRequestCallback): number;
|
|
918
899
|
/**
|
|
@@ -1324,23 +1305,18 @@ export declare const Canvas2DBridge: {
|
|
|
1324
1305
|
_onDraw(_area: Gtk.DrawingArea, cr: Cairo.Context, width: number, height: number): void;
|
|
1325
1306
|
/** The HTMLCanvasElement backing this widget. Available after the first draw. */
|
|
1326
1307
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
1327
|
-
/**
|
|
1308
|
+
/** The 2D rendering context; available after the first draw. */
|
|
1328
1309
|
getContext(_id: "2d"): CanvasRenderingContext2D | null;
|
|
1329
|
-
/**
|
|
1330
|
-
* Register a callback to be invoked once the Canvas 2D context is ready.
|
|
1331
|
-
* If the context is already available, the callback fires synchronously.
|
|
1332
|
-
*/
|
|
1310
|
+
/** Runs `cb` once the 2D context is ready — synchronously if it already is. */
|
|
1333
1311
|
onReady(cb: Canvas2DReadyCallback): void;
|
|
1334
1312
|
/**
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1337
|
-
* Call `queue_draw()` after re-rendering to push the new surface to screen.
|
|
1313
|
+
* Runs `cb` on every GTK resize, with the canvas dimensions already updated. Call
|
|
1314
|
+
* `queue_draw()` after re-rendering to push the new surface to screen.
|
|
1338
1315
|
*/
|
|
1339
1316
|
onResize(cb: (width: number, height: number) => void): void;
|
|
1340
1317
|
/**
|
|
1341
|
-
*
|
|
1342
|
-
*
|
|
1343
|
-
* Returns 0 (handle — cancel not yet implemented).
|
|
1318
|
+
* Browser `requestAnimationFrame`, driven by the vsync-synced GTK frame clock.
|
|
1319
|
+
* Always returns 0: there is no `cancelAnimationFrame` here to hand a handle to.
|
|
1344
1320
|
*/
|
|
1345
1321
|
requestAnimationFrame(cb: FrameRequestCallback): number;
|
|
1346
1322
|
/**
|
|
@@ -1752,23 +1728,18 @@ export declare const Canvas2DBridge: {
|
|
|
1752
1728
|
_onDraw(_area: Gtk.DrawingArea, cr: Cairo.Context, width: number, height: number): void;
|
|
1753
1729
|
/** The HTMLCanvasElement backing this widget. Available after the first draw. */
|
|
1754
1730
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
1755
|
-
/**
|
|
1731
|
+
/** The 2D rendering context; available after the first draw. */
|
|
1756
1732
|
getContext(_id: "2d"): CanvasRenderingContext2D | null;
|
|
1757
|
-
/**
|
|
1758
|
-
* Register a callback to be invoked once the Canvas 2D context is ready.
|
|
1759
|
-
* If the context is already available, the callback fires synchronously.
|
|
1760
|
-
*/
|
|
1733
|
+
/** Runs `cb` once the 2D context is ready — synchronously if it already is. */
|
|
1761
1734
|
onReady(cb: Canvas2DReadyCallback): void;
|
|
1762
1735
|
/**
|
|
1763
|
-
*
|
|
1764
|
-
*
|
|
1765
|
-
* Call `queue_draw()` after re-rendering to push the new surface to screen.
|
|
1736
|
+
* Runs `cb` on every GTK resize, with the canvas dimensions already updated. Call
|
|
1737
|
+
* `queue_draw()` after re-rendering to push the new surface to screen.
|
|
1766
1738
|
*/
|
|
1767
1739
|
onResize(cb: (width: number, height: number) => void): void;
|
|
1768
1740
|
/**
|
|
1769
|
-
*
|
|
1770
|
-
*
|
|
1771
|
-
* Returns 0 (handle — cancel not yet implemented).
|
|
1741
|
+
* Browser `requestAnimationFrame`, driven by the vsync-synced GTK frame clock.
|
|
1742
|
+
* Always returns 0: there is no `cancelAnimationFrame` here to hand a handle to.
|
|
1772
1743
|
*/
|
|
1773
1744
|
requestAnimationFrame(cb: FrameRequestCallback): number;
|
|
1774
1745
|
/**
|
|
@@ -2180,23 +2151,18 @@ export declare const Canvas2DBridge: {
|
|
|
2180
2151
|
_onDraw(_area: Gtk.DrawingArea, cr: Cairo.Context, width: number, height: number): void;
|
|
2181
2152
|
/** The HTMLCanvasElement backing this widget. Available after the first draw. */
|
|
2182
2153
|
get canvas(): globalThis.HTMLCanvasElement | null;
|
|
2183
|
-
/**
|
|
2154
|
+
/** The 2D rendering context; available after the first draw. */
|
|
2184
2155
|
getContext(_id: "2d"): CanvasRenderingContext2D | null;
|
|
2185
|
-
/**
|
|
2186
|
-
* Register a callback to be invoked once the Canvas 2D context is ready.
|
|
2187
|
-
* If the context is already available, the callback fires synchronously.
|
|
2188
|
-
*/
|
|
2156
|
+
/** Runs `cb` once the 2D context is ready — synchronously if it already is. */
|
|
2189
2157
|
onReady(cb: Canvas2DReadyCallback): void;
|
|
2190
2158
|
/**
|
|
2191
|
-
*
|
|
2192
|
-
*
|
|
2193
|
-
* Call `queue_draw()` after re-rendering to push the new surface to screen.
|
|
2159
|
+
* Runs `cb` on every GTK resize, with the canvas dimensions already updated. Call
|
|
2160
|
+
* `queue_draw()` after re-rendering to push the new surface to screen.
|
|
2194
2161
|
*/
|
|
2195
2162
|
onResize(cb: (width: number, height: number) => void): void;
|
|
2196
2163
|
/**
|
|
2197
|
-
*
|
|
2198
|
-
*
|
|
2199
|
-
* Returns 0 (handle — cancel not yet implemented).
|
|
2164
|
+
* Browser `requestAnimationFrame`, driven by the vsync-synced GTK frame clock.
|
|
2165
|
+
* Always returns 0: there is no `cancelAnimationFrame` here to hand a handle to.
|
|
2200
2166
|
*/
|
|
2201
2167
|
requestAnimationFrame(cb: FrameRequestCallback): number;
|
|
2202
2168
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/canvas2d",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Canvas 2D rendering context for GJS, backed by Cairo",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"@girs/gtk-4.0": "^4.1.0",
|
|
48
48
|
"@girs/pango-1.0": "^4.1.0",
|
|
49
49
|
"@girs/pangocairo-1.0": "^4.1.0",
|
|
50
|
-
"@gjsify/canvas2d-core": "^0.
|
|
51
|
-
"@gjsify/dom-elements": "^0.
|
|
52
|
-
"@gjsify/dom-events": "^0.
|
|
53
|
-
"@gjsify/event-bridge": "^0.
|
|
54
|
-
"@gjsify/utils": "^0.
|
|
50
|
+
"@gjsify/canvas2d-core": "^0.37.0",
|
|
51
|
+
"@gjsify/dom-elements": "^0.37.0",
|
|
52
|
+
"@gjsify/dom-events": "^0.37.0",
|
|
53
|
+
"@gjsify/event-bridge": "^0.37.0",
|
|
54
|
+
"@gjsify/utils": "^0.37.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@gjsify/cli": "^0.
|
|
58
|
-
"@gjsify/unit": "^0.
|
|
57
|
+
"@gjsify/cli": "^0.37.0",
|
|
58
|
+
"@gjsify/unit": "^0.37.0",
|
|
59
59
|
"@types/node": "^25.9.2",
|
|
60
60
|
"typescript": "^6.0.3"
|
|
61
61
|
},
|