@gjsify/canvas2d 0.36.0 → 0.38.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.
@@ -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 handles Canvas 2D bootstrapping:
13
- * - Creates an `HTMLCanvasElement` + `CanvasRenderingContext2D` on first draw
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
- * Usage:
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(); // sets globalThis.requestAnimationFrame
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
- /** Get the 2D rendering context. Available after the first draw. */
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
- * Register a callback invoked whenever the GTK widget is resized.
52
- * Canvas dimensions are already updated when the callback fires.
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
- * Schedules a single animation frame callback, matching the browser `requestAnimationFrame` API.
58
- * Backed by GTK frame clock (vsync-synced, typically ~60 FPS).
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
- /** Get the 2D rendering context. Available after the first draw. */
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
- * Register a callback invoked whenever the GTK widget is resized.
480
- * Canvas dimensions are already updated when the callback fires.
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
- * Schedules a single animation frame callback, matching the browser `requestAnimationFrame` API.
486
- * Backed by GTK frame clock (vsync-synced, typically ~60 FPS).
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
- /** Get the 2D rendering context. Available after the first draw. */
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
- * Register a callback invoked whenever the GTK widget is resized.
908
- * Canvas dimensions are already updated when the callback fires.
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
- * Schedules a single animation frame callback, matching the browser `requestAnimationFrame` API.
914
- * Backed by GTK frame clock (vsync-synced, typically ~60 FPS).
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
- /** Get the 2D rendering context. Available after the first draw. */
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
- * Register a callback invoked whenever the GTK widget is resized.
1336
- * Canvas dimensions are already updated when the callback fires.
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
- * Schedules a single animation frame callback, matching the browser `requestAnimationFrame` API.
1342
- * Backed by GTK frame clock (vsync-synced, typically ~60 FPS).
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
- /** Get the 2D rendering context. Available after the first draw. */
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
- * Register a callback invoked whenever the GTK widget is resized.
1764
- * Canvas dimensions are already updated when the callback fires.
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
- * Schedules a single animation frame callback, matching the browser `requestAnimationFrame` API.
1770
- * Backed by GTK frame clock (vsync-synced, typically ~60 FPS).
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
- /** Get the 2D rendering context. Available after the first draw. */
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
- * Register a callback invoked whenever the GTK widget is resized.
2192
- * Canvas dimensions are already updated when the callback fires.
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
- * Schedules a single animation frame callback, matching the browser `requestAnimationFrame` API.
2198
- * Backed by GTK frame clock (vsync-synced, typically ~60 FPS).
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.36.0",
3
+ "version": "0.38.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.36.0",
51
- "@gjsify/dom-elements": "^0.36.0",
52
- "@gjsify/dom-events": "^0.36.0",
53
- "@gjsify/event-bridge": "^0.36.0",
54
- "@gjsify/utils": "^0.36.0"
50
+ "@gjsify/canvas2d-core": "^0.38.0",
51
+ "@gjsify/dom-elements": "^0.38.0",
52
+ "@gjsify/dom-events": "^0.38.0",
53
+ "@gjsify/event-bridge": "^0.38.0",
54
+ "@gjsify/utils": "^0.38.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@gjsify/cli": "^0.36.0",
58
- "@gjsify/unit": "^0.36.0",
57
+ "@gjsify/cli": "^0.38.0",
58
+ "@gjsify/unit": "^0.38.0",
59
59
  "@types/node": "^25.9.2",
60
60
  "typescript": "^6.0.3"
61
61
  },