@gjsify/canvas2d-core 0.3.13 → 0.3.14

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,58 +1,63 @@
1
1
  import Cairo from "cairo";
2
2
  import Gdk from "gi://Gdk?version=4.0";
3
- class CanvasPattern {
4
- constructor(surface, repetition) {
5
- this._pattern = new Cairo.SurfacePattern(surface);
6
- const pat = this._pattern;
7
- switch (repetition) {
8
- case "repeat":
9
- case "":
10
- case null:
11
- pat.setExtend(Cairo.Extend.REPEAT);
12
- break;
13
- case "repeat-x":
14
- case "repeat-y":
15
- pat.setExtend(Cairo.Extend.REPEAT);
16
- break;
17
- case "no-repeat":
18
- pat.setExtend(Cairo.Extend.NONE);
19
- break;
20
- }
21
- }
22
- /** Create a CanvasPattern from a supported image source. Returns null if unsupported. */
23
- static create(image, repetition) {
24
- if ("isPixbuf" in image && typeof image.isPixbuf === "function" && image.isPixbuf()) {
25
- const pixbuf = image._pixbuf;
26
- const w = pixbuf.get_width();
27
- const h = pixbuf.get_height();
28
- const surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
29
- const ctx = new Cairo.Context(surface);
30
- Gdk.cairo_set_source_pixbuf(ctx, pixbuf, 0, 0);
31
- ctx.paint();
32
- ctx.$dispose();
33
- return new CanvasPattern(surface, repetition);
34
- }
35
- if (typeof image?.getContext === "function") {
36
- const ctx2d = image.getContext("2d");
37
- if (ctx2d && typeof ctx2d._getSurface === "function") {
38
- const sourceSurface = ctx2d._getSurface();
39
- const w = sourceSurface.getWidth();
40
- const h = sourceSurface.getHeight();
41
- const surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
42
- const ctx = new Cairo.Context(surface);
43
- ctx.setSourceSurface(sourceSurface, 0, 0);
44
- ctx.paint();
45
- ctx.$dispose();
46
- return new CanvasPattern(surface, repetition);
47
- }
48
- }
49
- return null;
50
- }
51
- /** @internal Get the underlying Cairo pattern for rendering. */
52
- _getCairoPattern() {
53
- return this._pattern;
54
- }
55
- }
56
- export {
57
- CanvasPattern
3
+
4
+ //#region src/canvas-pattern.ts
5
+ /**
6
+ * CanvasPattern wrapping a Cairo SurfacePattern.
7
+ */
8
+ var CanvasPattern = class CanvasPattern {
9
+ constructor(surface, repetition) {
10
+ this._pattern = new Cairo.SurfacePattern(surface);
11
+ const pat = this._pattern;
12
+ switch (repetition) {
13
+ case "repeat":
14
+ case "":
15
+ case null:
16
+ pat.setExtend(Cairo.Extend.REPEAT);
17
+ break;
18
+ case "repeat-x":
19
+ case "repeat-y":
20
+ pat.setExtend(Cairo.Extend.REPEAT);
21
+ break;
22
+ case "no-repeat":
23
+ pat.setExtend(Cairo.Extend.NONE);
24
+ break;
25
+ }
26
+ }
27
+ /** Create a CanvasPattern from a supported image source. Returns null if unsupported. */
28
+ static create(image, repetition) {
29
+ if ("isPixbuf" in image && typeof image.isPixbuf === "function" && image.isPixbuf()) {
30
+ const pixbuf = image._pixbuf;
31
+ const w = pixbuf.get_width();
32
+ const h = pixbuf.get_height();
33
+ const surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
34
+ const ctx = new Cairo.Context(surface);
35
+ Gdk.cairo_set_source_pixbuf(ctx, pixbuf, 0, 0);
36
+ ctx.paint();
37
+ ctx.$dispose();
38
+ return new CanvasPattern(surface, repetition);
39
+ }
40
+ if (typeof image?.getContext === "function") {
41
+ const ctx2d = image.getContext("2d");
42
+ if (ctx2d && typeof ctx2d._getSurface === "function") {
43
+ const sourceSurface = ctx2d._getSurface();
44
+ const w = sourceSurface.getWidth();
45
+ const h = sourceSurface.getHeight();
46
+ const surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
47
+ const ctx = new Cairo.Context(surface);
48
+ ctx.setSourceSurface(sourceSurface, 0, 0);
49
+ ctx.paint();
50
+ ctx.$dispose();
51
+ return new CanvasPattern(surface, repetition);
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+ /** @internal Get the underlying Cairo pattern for rendering. */
57
+ _getCairoPattern() {
58
+ return this._pattern;
59
+ }
58
60
  };
61
+
62
+ //#endregion
63
+ export { CanvasPattern };