@gjsify/canvas2d 0.1.1 → 0.1.3

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.
@@ -1,75 +1,2 @@
1
- // CanvasPattern implementation backed by Cairo SurfacePattern
2
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern
3
-
4
- import Cairo from 'cairo';
5
- import Gdk from 'gi://Gdk?version=4.0';
6
-
7
- /**
8
- * CanvasPattern wrapping a Cairo SurfacePattern.
9
- */
10
- export class CanvasPattern {
11
- private _pattern: Cairo.SurfacePattern;
12
-
13
- private constructor(surface: Cairo.ImageSurface, repetition: string | null) {
14
- this._pattern = new Cairo.SurfacePattern(surface);
15
-
16
- // Set extend mode based on repetition
17
- // setExtend exists at runtime on SurfacePattern but is missing from GIR types
18
- const pat = this._pattern as any;
19
- switch (repetition) {
20
- case 'repeat':
21
- case '':
22
- case null:
23
- pat.setExtend(Cairo.Extend.REPEAT);
24
- break;
25
- case 'repeat-x':
26
- case 'repeat-y':
27
- // Cairo doesn't have separate x/y repeat — use REPEAT as approximation
28
- pat.setExtend(Cairo.Extend.REPEAT);
29
- break;
30
- case 'no-repeat':
31
- pat.setExtend(Cairo.Extend.NONE);
32
- break;
33
- }
34
- }
35
-
36
- /** Create a CanvasPattern from a supported image source. Returns null if unsupported. */
37
- static create(image: any, repetition: string | null): CanvasPattern | null {
38
- // HTMLImageElement (GdkPixbuf-backed)
39
- if ('isPixbuf' in image && typeof (image as any).isPixbuf === 'function' && (image as any).isPixbuf()) {
40
- const pixbuf = (image as any)._pixbuf as import('@girs/gdkpixbuf-2.0').default.Pixbuf;
41
- // Create a Cairo surface from the pixbuf
42
- const w = pixbuf.get_width();
43
- const h = pixbuf.get_height();
44
- const surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
45
- const ctx = new Cairo.Context(surface);
46
- Gdk.cairo_set_source_pixbuf(ctx as any, pixbuf, 0, 0);
47
- ctx.paint();
48
- ctx.$dispose();
49
- return new CanvasPattern(surface, repetition);
50
- }
51
-
52
- // HTMLCanvasElement with a 2D context
53
- if (typeof image?.getContext === 'function') {
54
- const ctx2d = image.getContext('2d');
55
- if (ctx2d && typeof ctx2d._getSurface === 'function') {
56
- const sourceSurface = ctx2d._getSurface() as Cairo.ImageSurface;
57
- const w = sourceSurface.getWidth();
58
- const h = sourceSurface.getHeight();
59
- const surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
60
- const ctx = new Cairo.Context(surface);
61
- ctx.setSourceSurface(sourceSurface, 0, 0);
62
- ctx.paint();
63
- ctx.$dispose();
64
- return new CanvasPattern(surface, repetition);
65
- }
66
- }
67
-
68
- return null;
69
- }
70
-
71
- /** @internal Get the underlying Cairo pattern for rendering. */
72
- _getCairoPattern(): Cairo.SurfacePattern {
73
- return this._pattern;
74
- }
75
- }
1
+ // Moved to @gjsify/canvas2d-core re-exported here for backward compatibility.
2
+ export { CanvasPattern } from '@gjsify/canvas2d-core';