@gjsify/node-gi 0.26.1 → 0.27.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/cairo.js CHANGED
@@ -27,10 +27,10 @@ import native from './index.js';
27
27
 
28
28
  const c = native.__cairo;
29
29
  if (c === undefined) {
30
- throw new Error(
31
- '@gjsify/node-gi/cairo: the native cairo binding is missing from the addon. ' +
32
- 'Rebuild @gjsify/node-gi (node-gyp rebuild) — the addon must link libcairo.',
33
- );
30
+ throw new Error(
31
+ '@gjsify/node-gi/cairo: the native cairo binding is missing from the addon. ' +
32
+ 'Rebuild @gjsify/node-gi (node-gyp rebuild) — the addon must link libcairo.',
33
+ );
34
34
  }
35
35
 
36
36
  // ---- enums (ported verbatim from refs/gjs/modules/core/_cairo.js) -----------
@@ -52,64 +52,64 @@ export const FontWeight = { NORMAL: 0, BOLD: 1 };
52
52
  export const Format = { ARGB32: 0, RGB24: 1, A8: 2, A1: 3, RGB16_565: 4 };
53
53
 
54
54
  export const LineCap = {
55
- BUTT: 0,
56
- ROUND: 1,
57
- SQUARE: 2,
58
- /** @deprecated Historical typo of {@link LineCap.SQUARE}, kept for compatibility. */
59
- SQUASH: 2,
55
+ BUTT: 0,
56
+ ROUND: 1,
57
+ SQUARE: 2,
58
+ /** @deprecated Historical typo of {@link LineCap.SQUARE}, kept for compatibility. */
59
+ SQUASH: 2,
60
60
  };
61
61
 
62
62
  export const LineJoin = { MITER: 0, ROUND: 1, BEVEL: 2 };
63
63
 
64
64
  export const Operator = {
65
- CLEAR: 0,
66
- SOURCE: 1,
67
- OVER: 2,
68
- IN: 3,
69
- OUT: 4,
70
- ATOP: 5,
71
- DEST: 6,
72
- DEST_OVER: 7,
73
- DEST_IN: 8,
74
- DEST_OUT: 9,
75
- DEST_ATOP: 10,
76
- XOR: 11,
77
- ADD: 12,
78
- SATURATE: 13,
79
- MULTIPLY: 14,
80
- SCREEN: 15,
81
- OVERLAY: 16,
82
- DARKEN: 17,
83
- LIGHTEN: 18,
84
- COLOR_DODGE: 19,
85
- COLOR_BURN: 20,
86
- HARD_LIGHT: 21,
87
- SOFT_LIGHT: 22,
88
- DIFFERENCE: 23,
89
- EXCLUSION: 24,
90
- HSL_HUE: 25,
91
- HSL_SATURATION: 26,
92
- HSL_COLOR: 27,
93
- HSL_LUMINOSITY: 28,
65
+ CLEAR: 0,
66
+ SOURCE: 1,
67
+ OVER: 2,
68
+ IN: 3,
69
+ OUT: 4,
70
+ ATOP: 5,
71
+ DEST: 6,
72
+ DEST_OVER: 7,
73
+ DEST_IN: 8,
74
+ DEST_OUT: 9,
75
+ DEST_ATOP: 10,
76
+ XOR: 11,
77
+ ADD: 12,
78
+ SATURATE: 13,
79
+ MULTIPLY: 14,
80
+ SCREEN: 15,
81
+ OVERLAY: 16,
82
+ DARKEN: 17,
83
+ LIGHTEN: 18,
84
+ COLOR_DODGE: 19,
85
+ COLOR_BURN: 20,
86
+ HARD_LIGHT: 21,
87
+ SOFT_LIGHT: 22,
88
+ DIFFERENCE: 23,
89
+ EXCLUSION: 24,
90
+ HSL_HUE: 25,
91
+ HSL_SATURATION: 26,
92
+ HSL_COLOR: 27,
93
+ HSL_LUMINOSITY: 28,
94
94
  };
95
95
 
96
96
  export const PatternType = { SOLID: 0, SURFACE: 1, LINEAR: 2, RADIAL: 3 };
97
97
 
98
98
  export const SurfaceType = {
99
- IMAGE: 0,
100
- PDF: 1,
101
- PS: 2,
102
- XLIB: 3,
103
- XCB: 4,
104
- GLITZ: 5,
105
- QUARTZ: 6,
106
- WIN32: 7,
107
- BEOS: 8,
108
- DIRECTFB: 9,
109
- SVG: 10,
110
- OS2: 11,
111
- WIN32_PRINTING: 12,
112
- QUARTZ_IMAGE: 13,
99
+ IMAGE: 0,
100
+ PDF: 1,
101
+ PS: 2,
102
+ XLIB: 3,
103
+ XCB: 4,
104
+ GLITZ: 5,
105
+ QUARTZ: 6,
106
+ WIN32: 7,
107
+ BEOS: 8,
108
+ DIRECTFB: 9,
109
+ SVG: 10,
110
+ OS2: 11,
111
+ WIN32_PRINTING: 12,
112
+ QUARTZ_IMAGE: 13,
113
113
  };
114
114
 
115
115
  // ---- wrappers ---------------------------------------------------------------
@@ -121,385 +121,385 @@ export const SurfaceType = {
121
121
  const H = '_ptr';
122
122
 
123
123
  function setHandle(obj, handle) {
124
- Object.defineProperty(obj, H, { value: handle, writable: true, configurable: true });
125
- return obj;
124
+ Object.defineProperty(obj, H, { value: handle, writable: true, configurable: true });
125
+ return obj;
126
126
  }
127
127
 
128
128
  // Build a wrapper for an existing native handle WITHOUT running the class
129
129
  // constructor (which would allocate a fresh cairo object) — used by the static
130
130
  // `create*` factories + the foreign from_func factories.
131
131
  function wrapRaw(Klass, handle) {
132
- return setHandle(Object.create(Klass.prototype), handle);
132
+ return setHandle(Object.create(Klass.prototype), handle);
133
133
  }
134
134
 
135
135
  function handleOf(x, what) {
136
- const h = x != null ? x[H] : undefined;
137
- if (h === undefined) throw new TypeError(`expected a ${what}`);
138
- return h;
136
+ const h = x != null ? x[H] : undefined;
137
+ if (h === undefined) throw new TypeError(`expected a ${what}`);
138
+ return h;
139
139
  }
140
140
 
141
141
  /** cairo drawing context. `new cairo.Context(surface)` wraps `cairo_create`. */
142
142
  export class Context {
143
- constructor(surface) {
144
- setHandle(this, c.contextCreate(handleOf(surface, 'cairo.Surface')));
145
- }
146
-
147
- save() {
148
- c.save(this[H]);
149
- }
150
- restore() {
151
- c.restore(this[H]);
152
- }
153
- newPath() {
154
- c.newPath(this[H]);
155
- }
156
- closePath() {
157
- c.closePath(this[H]);
158
- }
159
-
160
- moveTo(x, y) {
161
- c.moveTo(this[H], x, y);
162
- }
163
- lineTo(x, y) {
164
- c.lineTo(this[H], x, y);
165
- }
166
- relMoveTo(dx, dy) {
167
- c.relMoveTo(this[H], dx, dy);
168
- }
169
- relLineTo(dx, dy) {
170
- c.relLineTo(this[H], dx, dy);
171
- }
172
- rectangle(x, y, width, height) {
173
- c.rectangle(this[H], x, y, width, height);
174
- }
175
- arc(xc, yc, radius, angle1, angle2) {
176
- c.arc(this[H], xc, yc, radius, angle1, angle2);
177
- }
178
- arcNegative(xc, yc, radius, angle1, angle2) {
179
- c.arcNegative(this[H], xc, yc, radius, angle1, angle2);
180
- }
181
- curveTo(x1, y1, x2, y2, x3, y3) {
182
- c.curveTo(this[H], x1, y1, x2, y2, x3, y3);
183
- }
184
-
185
- fill() {
186
- c.fill(this[H]);
187
- }
188
- fillPreserve() {
189
- c.fillPreserve(this[H]);
190
- }
191
- stroke() {
192
- c.stroke(this[H]);
193
- }
194
- strokePreserve() {
195
- c.strokePreserve(this[H]);
196
- }
197
- paint() {
198
- c.paint(this[H]);
199
- }
200
- paintWithAlpha(alpha) {
201
- c.paintWithAlpha(this[H], alpha);
202
- }
203
- clip() {
204
- c.clip(this[H]);
205
- }
206
- clipPreserve() {
207
- c.clipPreserve(this[H]);
208
- }
209
-
210
- translate(tx, ty) {
211
- c.translate(this[H], tx, ty);
212
- }
213
- scale(sx, sy) {
214
- c.scale(this[H], sx, sy);
215
- }
216
- rotate(angle) {
217
- c.rotate(this[H], angle);
218
- }
219
- identityMatrix() {
220
- c.identityMatrix(this[H]);
221
- }
222
- newSubPath() {
223
- c.newSubPath(this[H]);
224
- }
225
- /** User → device coordinates as `[x, y]` (GJS return shape). */
226
- userToDevice(x, y) {
227
- return c.userToDevice(this[H], x, y);
228
- }
229
- /** User → device distance (ignores translation) as `[dx, dy]`. */
230
- userToDeviceDistance(dx, dy) {
231
- return c.userToDeviceDistance(this[H], dx, dy);
232
- }
233
- /** Device → user coordinates as `[x, y]`. */
234
- deviceToUser(x, y) {
235
- return c.deviceToUser(this[H], x, y);
236
- }
237
- /** Device → user distance (ignores translation) as `[dx, dy]`. */
238
- deviceToUserDistance(dx, dy) {
239
- return c.deviceToUserDistance(this[H], dx, dy);
240
- }
241
- /** Copy the current path into an owned {@link Path} handle. */
242
- copyPath() {
243
- return wrapRaw(Path, c.copyPath(this[H]));
244
- }
245
- /** Like {@link copyPath} but with curves flattened to line segments. */
246
- copyPathFlat() {
247
- return wrapRaw(Path, c.copyPathFlat(this[H]));
248
- }
249
- appendPath(path) {
250
- c.appendPath(this[H], handleOf(path, 'cairo.Path'));
251
- }
252
- /**
253
- * Set the stroke dash pattern. GJS semantics: holes/undefined entries are
254
- * skipped, a non-positive value throws, an empty array disables dashing.
255
- */
256
- setDash(dashes, offset) {
257
- c.setDash(this[H], dashes, offset);
258
- }
259
- getDashCount() {
260
- return c.getDashCount(this[H]);
261
- }
262
- /**
263
- * The current dash pattern as `[dashes, offset]`.
264
- * Note: GJS ships only `getDashCount`; this is a node-gi convenience.
265
- */
266
- getDash() {
267
- return c.getDash(this[H]);
268
- }
269
- inFill(x, y) {
270
- return c.inFill(this[H], x, y);
271
- }
272
- inStroke(x, y) {
273
- return c.inStroke(this[H], x, y);
274
- }
275
-
276
- setSourceRGB(red, green, blue) {
277
- c.setSourceRGB(this[H], red, green, blue);
278
- }
279
- setSourceRGBA(red, green, blue, alpha) {
280
- c.setSourceRGBA(this[H], red, green, blue, alpha);
281
- }
282
- setSource(pattern) {
283
- c.setSource(this[H], handleOf(pattern, 'cairo.Pattern'));
284
- }
285
- setSourceSurface(surface, x, y) {
286
- c.setSourceSurface(this[H], handleOf(surface, 'cairo.Surface'), x, y);
287
- }
288
- /** The context's current source pattern (a ref of its own — safe to keep). */
289
- getSource() {
290
- return wrapPatternHandle(c.getSource(this[H]));
291
- }
292
-
293
- setLineWidth(width) {
294
- c.setLineWidth(this[H], width);
295
- }
296
- getLineWidth() {
297
- return c.getLineWidth(this[H]);
298
- }
299
- getOperator() {
300
- return c.getOperator(this[H]);
301
- }
302
- getLineCap() {
303
- return c.getLineCap(this[H]);
304
- }
305
- getLineJoin() {
306
- return c.getLineJoin(this[H]);
307
- }
308
- getFillRule() {
309
- return c.getFillRule(this[H]);
310
- }
311
- getAntialias() {
312
- return c.getAntialias(this[H]);
313
- }
314
- getMiterLimit() {
315
- return c.getMiterLimit(this[H]);
316
- }
317
- getTolerance() {
318
- return c.getTolerance(this[H]);
319
- }
320
- hasCurrentPoint() {
321
- return c.hasCurrentPoint(this[H]);
322
- }
323
- /** The current path point as `[x, y]`. */
324
- getCurrentPoint() {
325
- return c.getCurrentPoint(this[H]);
326
- }
327
- /** Current-path bounding box as `[x1, y1, x2, y2]`. */
328
- pathExtents() {
329
- return c.pathExtents(this[H]);
330
- }
331
- /** Fill bounding box as `[x1, y1, x2, y2]`. */
332
- fillExtents() {
333
- return c.fillExtents(this[H]);
334
- }
335
- /** Stroke bounding box as `[x1, y1, x2, y2]`. */
336
- strokeExtents() {
337
- return c.strokeExtents(this[H]);
338
- }
339
- /** Clip bounding box as `[x1, y1, x2, y2]`. */
340
- clipExtents() {
341
- return c.clipExtents(this[H]);
342
- }
343
- setLineCap(lineCap) {
344
- c.setLineCap(this[H], lineCap);
345
- }
346
- setLineJoin(lineJoin) {
347
- c.setLineJoin(this[H], lineJoin);
348
- }
349
- setFillRule(fillRule) {
350
- c.setFillRule(this[H], fillRule);
351
- }
352
- setAntialias(antialias) {
353
- c.setAntialias(this[H], antialias);
354
- }
355
- setOperator(op) {
356
- c.setOperator(this[H], op);
357
- }
358
- setMiterLimit(limit) {
359
- c.setMiterLimit(this[H], limit);
360
- }
361
- setTolerance(tolerance) {
362
- c.setTolerance(this[H], tolerance);
363
- }
364
-
365
- status() {
366
- return c.status(this[H]);
367
- }
368
-
369
- /** Eagerly destroy the underlying `cairo_t` (GJS `$dispose`). */
370
- $dispose() {
371
- c.dispose(this[H]);
372
- }
143
+ constructor(surface) {
144
+ setHandle(this, c.contextCreate(handleOf(surface, 'cairo.Surface')));
145
+ }
146
+
147
+ save() {
148
+ c.save(this[H]);
149
+ }
150
+ restore() {
151
+ c.restore(this[H]);
152
+ }
153
+ newPath() {
154
+ c.newPath(this[H]);
155
+ }
156
+ closePath() {
157
+ c.closePath(this[H]);
158
+ }
159
+
160
+ moveTo(x, y) {
161
+ c.moveTo(this[H], x, y);
162
+ }
163
+ lineTo(x, y) {
164
+ c.lineTo(this[H], x, y);
165
+ }
166
+ relMoveTo(dx, dy) {
167
+ c.relMoveTo(this[H], dx, dy);
168
+ }
169
+ relLineTo(dx, dy) {
170
+ c.relLineTo(this[H], dx, dy);
171
+ }
172
+ rectangle(x, y, width, height) {
173
+ c.rectangle(this[H], x, y, width, height);
174
+ }
175
+ arc(xc, yc, radius, angle1, angle2) {
176
+ c.arc(this[H], xc, yc, radius, angle1, angle2);
177
+ }
178
+ arcNegative(xc, yc, radius, angle1, angle2) {
179
+ c.arcNegative(this[H], xc, yc, radius, angle1, angle2);
180
+ }
181
+ curveTo(x1, y1, x2, y2, x3, y3) {
182
+ c.curveTo(this[H], x1, y1, x2, y2, x3, y3);
183
+ }
184
+
185
+ fill() {
186
+ c.fill(this[H]);
187
+ }
188
+ fillPreserve() {
189
+ c.fillPreserve(this[H]);
190
+ }
191
+ stroke() {
192
+ c.stroke(this[H]);
193
+ }
194
+ strokePreserve() {
195
+ c.strokePreserve(this[H]);
196
+ }
197
+ paint() {
198
+ c.paint(this[H]);
199
+ }
200
+ paintWithAlpha(alpha) {
201
+ c.paintWithAlpha(this[H], alpha);
202
+ }
203
+ clip() {
204
+ c.clip(this[H]);
205
+ }
206
+ clipPreserve() {
207
+ c.clipPreserve(this[H]);
208
+ }
209
+
210
+ translate(tx, ty) {
211
+ c.translate(this[H], tx, ty);
212
+ }
213
+ scale(sx, sy) {
214
+ c.scale(this[H], sx, sy);
215
+ }
216
+ rotate(angle) {
217
+ c.rotate(this[H], angle);
218
+ }
219
+ identityMatrix() {
220
+ c.identityMatrix(this[H]);
221
+ }
222
+ newSubPath() {
223
+ c.newSubPath(this[H]);
224
+ }
225
+ /** User → device coordinates as `[x, y]` (GJS return shape). */
226
+ userToDevice(x, y) {
227
+ return c.userToDevice(this[H], x, y);
228
+ }
229
+ /** User → device distance (ignores translation) as `[dx, dy]`. */
230
+ userToDeviceDistance(dx, dy) {
231
+ return c.userToDeviceDistance(this[H], dx, dy);
232
+ }
233
+ /** Device → user coordinates as `[x, y]`. */
234
+ deviceToUser(x, y) {
235
+ return c.deviceToUser(this[H], x, y);
236
+ }
237
+ /** Device → user distance (ignores translation) as `[dx, dy]`. */
238
+ deviceToUserDistance(dx, dy) {
239
+ return c.deviceToUserDistance(this[H], dx, dy);
240
+ }
241
+ /** Copy the current path into an owned {@link Path} handle. */
242
+ copyPath() {
243
+ return wrapRaw(Path, c.copyPath(this[H]));
244
+ }
245
+ /** Like {@link copyPath} but with curves flattened to line segments. */
246
+ copyPathFlat() {
247
+ return wrapRaw(Path, c.copyPathFlat(this[H]));
248
+ }
249
+ appendPath(path) {
250
+ c.appendPath(this[H], handleOf(path, 'cairo.Path'));
251
+ }
252
+ /**
253
+ * Set the stroke dash pattern. GJS semantics: holes/undefined entries are
254
+ * skipped, a non-positive value throws, an empty array disables dashing.
255
+ */
256
+ setDash(dashes, offset) {
257
+ c.setDash(this[H], dashes, offset);
258
+ }
259
+ getDashCount() {
260
+ return c.getDashCount(this[H]);
261
+ }
262
+ /**
263
+ * The current dash pattern as `[dashes, offset]`.
264
+ * Note: GJS ships only `getDashCount`; this is a node-gi convenience.
265
+ */
266
+ getDash() {
267
+ return c.getDash(this[H]);
268
+ }
269
+ inFill(x, y) {
270
+ return c.inFill(this[H], x, y);
271
+ }
272
+ inStroke(x, y) {
273
+ return c.inStroke(this[H], x, y);
274
+ }
275
+
276
+ setSourceRGB(red, green, blue) {
277
+ c.setSourceRGB(this[H], red, green, blue);
278
+ }
279
+ setSourceRGBA(red, green, blue, alpha) {
280
+ c.setSourceRGBA(this[H], red, green, blue, alpha);
281
+ }
282
+ setSource(pattern) {
283
+ c.setSource(this[H], handleOf(pattern, 'cairo.Pattern'));
284
+ }
285
+ setSourceSurface(surface, x, y) {
286
+ c.setSourceSurface(this[H], handleOf(surface, 'cairo.Surface'), x, y);
287
+ }
288
+ /** The context's current source pattern (a ref of its own — safe to keep). */
289
+ getSource() {
290
+ return wrapPatternHandle(c.getSource(this[H]));
291
+ }
292
+
293
+ setLineWidth(width) {
294
+ c.setLineWidth(this[H], width);
295
+ }
296
+ getLineWidth() {
297
+ return c.getLineWidth(this[H]);
298
+ }
299
+ getOperator() {
300
+ return c.getOperator(this[H]);
301
+ }
302
+ getLineCap() {
303
+ return c.getLineCap(this[H]);
304
+ }
305
+ getLineJoin() {
306
+ return c.getLineJoin(this[H]);
307
+ }
308
+ getFillRule() {
309
+ return c.getFillRule(this[H]);
310
+ }
311
+ getAntialias() {
312
+ return c.getAntialias(this[H]);
313
+ }
314
+ getMiterLimit() {
315
+ return c.getMiterLimit(this[H]);
316
+ }
317
+ getTolerance() {
318
+ return c.getTolerance(this[H]);
319
+ }
320
+ hasCurrentPoint() {
321
+ return c.hasCurrentPoint(this[H]);
322
+ }
323
+ /** The current path point as `[x, y]`. */
324
+ getCurrentPoint() {
325
+ return c.getCurrentPoint(this[H]);
326
+ }
327
+ /** Current-path bounding box as `[x1, y1, x2, y2]`. */
328
+ pathExtents() {
329
+ return c.pathExtents(this[H]);
330
+ }
331
+ /** Fill bounding box as `[x1, y1, x2, y2]`. */
332
+ fillExtents() {
333
+ return c.fillExtents(this[H]);
334
+ }
335
+ /** Stroke bounding box as `[x1, y1, x2, y2]`. */
336
+ strokeExtents() {
337
+ return c.strokeExtents(this[H]);
338
+ }
339
+ /** Clip bounding box as `[x1, y1, x2, y2]`. */
340
+ clipExtents() {
341
+ return c.clipExtents(this[H]);
342
+ }
343
+ setLineCap(lineCap) {
344
+ c.setLineCap(this[H], lineCap);
345
+ }
346
+ setLineJoin(lineJoin) {
347
+ c.setLineJoin(this[H], lineJoin);
348
+ }
349
+ setFillRule(fillRule) {
350
+ c.setFillRule(this[H], fillRule);
351
+ }
352
+ setAntialias(antialias) {
353
+ c.setAntialias(this[H], antialias);
354
+ }
355
+ setOperator(op) {
356
+ c.setOperator(this[H], op);
357
+ }
358
+ setMiterLimit(limit) {
359
+ c.setMiterLimit(this[H], limit);
360
+ }
361
+ setTolerance(tolerance) {
362
+ c.setTolerance(this[H], tolerance);
363
+ }
364
+
365
+ status() {
366
+ return c.status(this[H]);
367
+ }
368
+
369
+ /** Eagerly destroy the underlying `cairo_t` (GJS `$dispose`). */
370
+ $dispose() {
371
+ c.dispose(this[H]);
372
+ }
373
373
  }
374
374
 
375
375
  /** cairo surface base class — the shared Surface API (flush/finish/writeToPNG/…). */
376
376
  export class Surface {
377
- getType() {
378
- return c.surfaceGetType(this[H]);
379
- }
380
- status() {
381
- return c.surfaceStatus(this[H]);
382
- }
383
- flush() {
384
- c.surfaceFlush(this[H]);
385
- }
386
- finish() {
387
- c.surfaceFinish(this[H]);
388
- }
389
- writeToPNG(filename) {
390
- c.surfaceWriteToPNG(this[H], filename);
391
- }
392
- /** Eagerly destroy the underlying `cairo_surface_t` (GJS `$dispose`). */
393
- $dispose() {
394
- c.dispose(this[H]);
395
- }
377
+ getType() {
378
+ return c.surfaceGetType(this[H]);
379
+ }
380
+ status() {
381
+ return c.surfaceStatus(this[H]);
382
+ }
383
+ flush() {
384
+ c.surfaceFlush(this[H]);
385
+ }
386
+ finish() {
387
+ c.surfaceFinish(this[H]);
388
+ }
389
+ writeToPNG(filename) {
390
+ c.surfaceWriteToPNG(this[H], filename);
391
+ }
392
+ /** Eagerly destroy the underlying `cairo_surface_t` (GJS `$dispose`). */
393
+ $dispose() {
394
+ c.dispose(this[H]);
395
+ }
396
396
  }
397
397
 
398
398
  /** An in-memory image surface (`cairo_image_surface_*`). */
399
399
  export class ImageSurface extends Surface {
400
- constructor(format, width, height) {
401
- super();
402
- setHandle(this, c.imageSurfaceCreate(format, width, height));
403
- }
404
-
405
- static create(format, width, height) {
406
- return new ImageSurface(format, width, height);
407
- }
408
- static createFromPNG(filename) {
409
- return wrapRaw(ImageSurface, c.imageSurfaceCreateFromPNG(filename));
410
- }
411
-
412
- getWidth() {
413
- return c.imageSurfaceGetWidth(this[H]);
414
- }
415
- getHeight() {
416
- return c.imageSurfaceGetHeight(this[H]);
417
- }
418
- getStride() {
419
- return c.imageSurfaceGetStride(this[H]);
420
- }
421
- getFormat() {
422
- return c.imageSurfaceGetFormat(this[H]);
423
- }
424
- /**
425
- * The raw pixel buffer as a fresh Uint8Array copy (length = stride * height).
426
- * Note: GJS ships no `getData`; this is a node-gi convenience for headless pixel
427
- * assertions. The buffer is flushed first + copied (independent of the surface).
428
- */
429
- getData() {
430
- return c.imageSurfaceGetData(this[H]);
431
- }
400
+ constructor(format, width, height) {
401
+ super();
402
+ setHandle(this, c.imageSurfaceCreate(format, width, height));
403
+ }
404
+
405
+ static create(format, width, height) {
406
+ return new ImageSurface(format, width, height);
407
+ }
408
+ static createFromPNG(filename) {
409
+ return wrapRaw(ImageSurface, c.imageSurfaceCreateFromPNG(filename));
410
+ }
411
+
412
+ getWidth() {
413
+ return c.imageSurfaceGetWidth(this[H]);
414
+ }
415
+ getHeight() {
416
+ return c.imageSurfaceGetHeight(this[H]);
417
+ }
418
+ getStride() {
419
+ return c.imageSurfaceGetStride(this[H]);
420
+ }
421
+ getFormat() {
422
+ return c.imageSurfaceGetFormat(this[H]);
423
+ }
424
+ /**
425
+ * The raw pixel buffer as a fresh Uint8Array copy (length = stride * height).
426
+ * Note: GJS ships no `getData`; this is a node-gi convenience for headless pixel
427
+ * assertions. The buffer is flushed first + copied (independent of the surface).
428
+ */
429
+ getData() {
430
+ return c.imageSurfaceGetData(this[H]);
431
+ }
432
432
  }
433
433
 
434
434
  /** cairo pattern base class. */
435
435
  export class Pattern {
436
- getType() {
437
- return c.patternGetType(this[H]);
438
- }
439
- status() {
440
- return c.patternStatus(this[H]);
441
- }
442
- /** Eagerly destroy the underlying `cairo_pattern_t` (GJS `$dispose`). */
443
- $dispose() {
444
- c.dispose(this[H]);
445
- }
436
+ getType() {
437
+ return c.patternGetType(this[H]);
438
+ }
439
+ status() {
440
+ return c.patternStatus(this[H]);
441
+ }
442
+ /** Eagerly destroy the underlying `cairo_pattern_t` (GJS `$dispose`). */
443
+ $dispose() {
444
+ c.dispose(this[H]);
445
+ }
446
446
  }
447
447
 
448
448
  /** A solid-color pattern (`cairo_pattern_create_rgb[a]`). */
449
449
  export class SolidPattern extends Pattern {
450
- static createRGB(red, green, blue) {
451
- return wrapRaw(SolidPattern, c.solidPatternCreateRGB(red, green, blue));
452
- }
453
- static createRGBA(red, green, blue, alpha) {
454
- return wrapRaw(SolidPattern, c.solidPatternCreateRGBA(red, green, blue, alpha));
455
- }
450
+ static createRGB(red, green, blue) {
451
+ return wrapRaw(SolidPattern, c.solidPatternCreateRGB(red, green, blue));
452
+ }
453
+ static createRGBA(red, green, blue, alpha) {
454
+ return wrapRaw(SolidPattern, c.solidPatternCreateRGBA(red, green, blue, alpha));
455
+ }
456
456
  }
457
457
 
458
458
  /** Gradient base class — the shared color-stop API (GJS `CairoGradient`). */
459
459
  export class Gradient extends Pattern {
460
- addColorStopRGB(offset, red, green, blue) {
461
- c.patternAddColorStopRGB(this[H], offset, red, green, blue);
462
- }
463
- addColorStopRGBA(offset, red, green, blue, alpha) {
464
- c.patternAddColorStopRGBA(this[H], offset, red, green, blue, alpha);
465
- }
460
+ addColorStopRGB(offset, red, green, blue) {
461
+ c.patternAddColorStopRGB(this[H], offset, red, green, blue);
462
+ }
463
+ addColorStopRGBA(offset, red, green, blue, alpha) {
464
+ c.patternAddColorStopRGBA(this[H], offset, red, green, blue, alpha);
465
+ }
466
466
  }
467
467
 
468
468
  /** A linear gradient (`cairo_pattern_create_linear`). */
469
469
  export class LinearGradient extends Gradient {
470
- constructor(x0, y0, x1, y1) {
471
- super();
472
- setHandle(this, c.linearGradientCreate(x0, y0, x1, y1));
473
- }
470
+ constructor(x0, y0, x1, y1) {
471
+ super();
472
+ setHandle(this, c.linearGradientCreate(x0, y0, x1, y1));
473
+ }
474
474
  }
475
475
 
476
476
  /** A radial gradient (`cairo_pattern_create_radial`). */
477
477
  export class RadialGradient extends Gradient {
478
- constructor(cx0, cy0, radius0, cx1, cy1, radius1) {
479
- super();
480
- setHandle(this, c.radialGradientCreate(cx0, cy0, radius0, cx1, cy1, radius1));
481
- }
478
+ constructor(cx0, cy0, radius0, cx1, cy1, radius1) {
479
+ super();
480
+ setHandle(this, c.radialGradientCreate(cx0, cy0, radius0, cx1, cy1, radius1));
481
+ }
482
482
  }
483
483
 
484
484
  /** A surface-backed pattern (`cairo_pattern_create_for_surface`). */
485
485
  export class SurfacePattern extends Pattern {
486
- constructor(surface) {
487
- super();
488
- setHandle(this, c.surfacePatternCreate(handleOf(surface, 'cairo.Surface')));
489
- }
490
-
491
- setExtend(extend) {
492
- c.patternSetExtend(this[H], extend);
493
- }
494
- getExtend() {
495
- return c.patternGetExtend(this[H]);
496
- }
497
- setFilter(filter) {
498
- c.patternSetFilter(this[H], filter);
499
- }
500
- getFilter() {
501
- return c.patternGetFilter(this[H]);
502
- }
486
+ constructor(surface) {
487
+ super();
488
+ setHandle(this, c.surfacePatternCreate(handleOf(surface, 'cairo.Surface')));
489
+ }
490
+
491
+ setExtend(extend) {
492
+ c.patternSetExtend(this[H], extend);
493
+ }
494
+ getExtend() {
495
+ return c.patternGetExtend(this[H]);
496
+ }
497
+ setFilter(filter) {
498
+ c.patternSetFilter(this[H], filter);
499
+ }
500
+ getFilter() {
501
+ return c.patternGetFilter(this[H]);
502
+ }
503
503
  }
504
504
 
505
505
  /**
@@ -513,18 +513,18 @@ export class Path {}
513
513
  // mirrors gjs_cairo_pattern_from_pattern (MESH/RASTER_SOURCE fall back to the
514
514
  // base Pattern; gjs throws for those, but they are unreachable from this module).
515
515
  function wrapPatternHandle(handle) {
516
- const t = c.patternGetType(handle);
517
- const Klass =
518
- t === PatternType.SOLID
519
- ? SolidPattern
520
- : t === PatternType.SURFACE
521
- ? SurfacePattern
522
- : t === PatternType.LINEAR
523
- ? LinearGradient
524
- : t === PatternType.RADIAL
525
- ? RadialGradient
526
- : Pattern;
527
- return wrapRaw(Klass, handle);
516
+ const t = c.patternGetType(handle);
517
+ const Klass =
518
+ t === PatternType.SOLID
519
+ ? SolidPattern
520
+ : t === PatternType.SURFACE
521
+ ? SurfacePattern
522
+ : t === PatternType.LINEAR
523
+ ? LinearGradient
524
+ : t === PatternType.RADIAL
525
+ ? RadialGradient
526
+ : Pattern;
527
+ return wrapRaw(Klass, handle);
528
528
  }
529
529
 
530
530
  // Register the wrapper factories so the engine's foreign-struct from_func can turn
@@ -532,39 +532,38 @@ function wrapPatternHandle(handle) {
532
532
  // fan out to the concrete subclass by cairo runtime type (mirrors
533
533
  // CairoSurface::from_c_ptr / gjs_cairo_pattern_from_pattern).
534
534
  c.setup({
535
- context: (handle) => wrapRaw(Context, handle),
536
- surface: (handle) =>
537
- wrapRaw(c.surfaceGetType(handle) === SurfaceType.IMAGE ? ImageSurface : Surface, handle),
538
- pattern: (handle) => wrapPatternHandle(handle),
539
- path: (handle) => wrapRaw(Path, handle),
535
+ context: (handle) => wrapRaw(Context, handle),
536
+ surface: (handle) => wrapRaw(c.surfaceGetType(handle) === SurfaceType.IMAGE ? ImageSurface : Surface, handle),
537
+ pattern: (handle) => wrapPatternHandle(handle),
538
+ path: (handle) => wrapRaw(Path, handle),
540
539
  });
541
540
 
542
541
  // The default export mirrors GJS's ESM `cairo` object (enums + constructors), the
543
542
  // shape `import cairo from 'cairo'` returns.
544
543
  const cairo = {
545
- Antialias,
546
- Content,
547
- Extend,
548
- FillRule,
549
- Filter,
550
- FontSlant,
551
- FontWeight,
552
- Format,
553
- LineCap,
554
- LineJoin,
555
- Operator,
556
- PatternType,
557
- SurfaceType,
558
- Context,
559
- Surface,
560
- ImageSurface,
561
- Pattern,
562
- SolidPattern,
563
- Gradient,
564
- LinearGradient,
565
- RadialGradient,
566
- SurfacePattern,
567
- Path,
544
+ Antialias,
545
+ Content,
546
+ Extend,
547
+ FillRule,
548
+ Filter,
549
+ FontSlant,
550
+ FontWeight,
551
+ Format,
552
+ LineCap,
553
+ LineJoin,
554
+ Operator,
555
+ PatternType,
556
+ SurfaceType,
557
+ Context,
558
+ Surface,
559
+ ImageSurface,
560
+ Pattern,
561
+ SolidPattern,
562
+ Gradient,
563
+ LinearGradient,
564
+ RadialGradient,
565
+ SurfacePattern,
566
+ Path,
568
567
  };
569
568
 
570
569
  export default cairo;