@gjsify/canvas2d-core 0.3.12 → 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.
- package/lib/esm/cairo-utils.js +175 -156
- package/lib/esm/canvas-gradient.js +26 -21
- package/lib/esm/canvas-path.js +160 -103
- package/lib/esm/canvas-pattern.js +60 -55
- package/lib/esm/canvas-rendering-context-2d.js +969 -989
- package/lib/esm/canvas-state.js +35 -34
- package/lib/esm/color.js +259 -234
- package/lib/esm/image-data.js +24 -21
- package/lib/esm/index.js +5 -11
- package/package.json +10 -10
package/lib/esm/canvas-state.js
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
import { BLACK } from "./color.js";
|
|
2
|
+
|
|
3
|
+
//#region src/canvas-state.ts
|
|
2
4
|
function createDefaultState() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
return {
|
|
6
|
+
fillStyle: "#000000",
|
|
7
|
+
fillColor: { ...BLACK },
|
|
8
|
+
strokeStyle: "#000000",
|
|
9
|
+
strokeColor: { ...BLACK },
|
|
10
|
+
lineWidth: 1,
|
|
11
|
+
lineCap: "butt",
|
|
12
|
+
lineJoin: "miter",
|
|
13
|
+
miterLimit: 10,
|
|
14
|
+
lineDash: [],
|
|
15
|
+
lineDashOffset: 0,
|
|
16
|
+
globalAlpha: 1,
|
|
17
|
+
globalCompositeOperation: "source-over",
|
|
18
|
+
shadowColor: "rgba(0, 0, 0, 0)",
|
|
19
|
+
shadowBlur: 0,
|
|
20
|
+
shadowOffsetX: 0,
|
|
21
|
+
shadowOffsetY: 0,
|
|
22
|
+
font: "10px sans-serif",
|
|
23
|
+
textAlign: "start",
|
|
24
|
+
textBaseline: "alphabetic",
|
|
25
|
+
direction: "ltr",
|
|
26
|
+
imageSmoothingEnabled: true,
|
|
27
|
+
imageSmoothingQuality: "low"
|
|
28
|
+
};
|
|
27
29
|
}
|
|
28
30
|
function cloneState(state) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
return {
|
|
32
|
+
...state,
|
|
33
|
+
fillColor: { ...state.fillColor },
|
|
34
|
+
strokeColor: { ...state.strokeColor },
|
|
35
|
+
lineDash: [...state.lineDash]
|
|
36
|
+
};
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { cloneState, createDefaultState };
|
package/lib/esm/color.js
CHANGED
|
@@ -1,247 +1,272 @@
|
|
|
1
|
+
//#region src/color.ts
|
|
1
2
|
const NAMED_COLORS = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
3
|
+
aliceblue: "#f0f8ff",
|
|
4
|
+
antiquewhite: "#faebd7",
|
|
5
|
+
aqua: "#00ffff",
|
|
6
|
+
aquamarine: "#7fffd4",
|
|
7
|
+
azure: "#f0ffff",
|
|
8
|
+
beige: "#f5f5dc",
|
|
9
|
+
bisque: "#ffe4c4",
|
|
10
|
+
black: "#000000",
|
|
11
|
+
blanchedalmond: "#ffebcd",
|
|
12
|
+
blue: "#0000ff",
|
|
13
|
+
blueviolet: "#8a2be2",
|
|
14
|
+
brown: "#a52a2a",
|
|
15
|
+
burlywood: "#deb887",
|
|
16
|
+
cadetblue: "#5f9ea0",
|
|
17
|
+
chartreuse: "#7fff00",
|
|
18
|
+
chocolate: "#d2691e",
|
|
19
|
+
coral: "#ff7f50",
|
|
20
|
+
cornflowerblue: "#6495ed",
|
|
21
|
+
cornsilk: "#fff8dc",
|
|
22
|
+
crimson: "#dc143c",
|
|
23
|
+
cyan: "#00ffff",
|
|
24
|
+
darkblue: "#00008b",
|
|
25
|
+
darkcyan: "#008b8b",
|
|
26
|
+
darkgoldenrod: "#b8860b",
|
|
27
|
+
darkgray: "#a9a9a9",
|
|
28
|
+
darkgreen: "#006400",
|
|
29
|
+
darkgrey: "#a9a9a9",
|
|
30
|
+
darkkhaki: "#bdb76b",
|
|
31
|
+
darkmagenta: "#8b008b",
|
|
32
|
+
darkolivegreen: "#556b2f",
|
|
33
|
+
darkorange: "#ff8c00",
|
|
34
|
+
darkorchid: "#9932cc",
|
|
35
|
+
darkred: "#8b0000",
|
|
36
|
+
darksalmon: "#e9967a",
|
|
37
|
+
darkseagreen: "#8fbc8f",
|
|
38
|
+
darkslateblue: "#483d8b",
|
|
39
|
+
darkslategray: "#2f4f4f",
|
|
40
|
+
darkslategrey: "#2f4f4f",
|
|
41
|
+
darkturquoise: "#00ced1",
|
|
42
|
+
darkviolet: "#9400d3",
|
|
43
|
+
deeppink: "#ff1493",
|
|
44
|
+
deepskyblue: "#00bfff",
|
|
45
|
+
dimgray: "#696969",
|
|
46
|
+
dimgrey: "#696969",
|
|
47
|
+
dodgerblue: "#1e90ff",
|
|
48
|
+
firebrick: "#b22222",
|
|
49
|
+
floralwhite: "#fffaf0",
|
|
50
|
+
forestgreen: "#228b22",
|
|
51
|
+
fuchsia: "#ff00ff",
|
|
52
|
+
gainsboro: "#dcdcdc",
|
|
53
|
+
ghostwhite: "#f8f8ff",
|
|
54
|
+
gold: "#ffd700",
|
|
55
|
+
goldenrod: "#daa520",
|
|
56
|
+
gray: "#808080",
|
|
57
|
+
green: "#008000",
|
|
58
|
+
greenyellow: "#adff2f",
|
|
59
|
+
grey: "#808080",
|
|
60
|
+
honeydew: "#f0fff0",
|
|
61
|
+
hotpink: "#ff69b4",
|
|
62
|
+
indianred: "#cd5c5c",
|
|
63
|
+
indigo: "#4b0082",
|
|
64
|
+
ivory: "#fffff0",
|
|
65
|
+
khaki: "#f0e68c",
|
|
66
|
+
lavender: "#e6e6fa",
|
|
67
|
+
lavenderblush: "#fff0f5",
|
|
68
|
+
lawngreen: "#7cfc00",
|
|
69
|
+
lemonchiffon: "#fffacd",
|
|
70
|
+
lightblue: "#add8e6",
|
|
71
|
+
lightcoral: "#f08080",
|
|
72
|
+
lightcyan: "#e0ffff",
|
|
73
|
+
lightgoldenrodyellow: "#fafad2",
|
|
74
|
+
lightgray: "#d3d3d3",
|
|
75
|
+
lightgreen: "#90ee90",
|
|
76
|
+
lightgrey: "#d3d3d3",
|
|
77
|
+
lightpink: "#ffb6c1",
|
|
78
|
+
lightsalmon: "#ffa07a",
|
|
79
|
+
lightseagreen: "#20b2aa",
|
|
80
|
+
lightskyblue: "#87cefa",
|
|
81
|
+
lightslategray: "#778899",
|
|
82
|
+
lightslategrey: "#778899",
|
|
83
|
+
lightsteelblue: "#b0c4de",
|
|
84
|
+
lightyellow: "#ffffe0",
|
|
85
|
+
lime: "#00ff00",
|
|
86
|
+
limegreen: "#32cd32",
|
|
87
|
+
linen: "#faf0e6",
|
|
88
|
+
magenta: "#ff00ff",
|
|
89
|
+
maroon: "#800000",
|
|
90
|
+
mediumaquamarine: "#66cdaa",
|
|
91
|
+
mediumblue: "#0000cd",
|
|
92
|
+
mediumorchid: "#ba55d3",
|
|
93
|
+
mediumpurple: "#9370db",
|
|
94
|
+
mediumseagreen: "#3cb371",
|
|
95
|
+
mediumslateblue: "#7b68ee",
|
|
96
|
+
mediumspringgreen: "#00fa9a",
|
|
97
|
+
mediumturquoise: "#48d1cc",
|
|
98
|
+
mediumvioletred: "#c71585",
|
|
99
|
+
midnightblue: "#191970",
|
|
100
|
+
mintcream: "#f5fffa",
|
|
101
|
+
mistyrose: "#ffe4e1",
|
|
102
|
+
moccasin: "#ffe4b5",
|
|
103
|
+
navajowhite: "#ffdead",
|
|
104
|
+
navy: "#000080",
|
|
105
|
+
oldlace: "#fdf5e6",
|
|
106
|
+
olive: "#808000",
|
|
107
|
+
olivedrab: "#6b8e23",
|
|
108
|
+
orange: "#ffa500",
|
|
109
|
+
orangered: "#ff4500",
|
|
110
|
+
orchid: "#da70d6",
|
|
111
|
+
palegoldenrod: "#eee8aa",
|
|
112
|
+
palegreen: "#98fb98",
|
|
113
|
+
paleturquoise: "#afeeee",
|
|
114
|
+
palevioletred: "#db7093",
|
|
115
|
+
papayawhip: "#ffefd5",
|
|
116
|
+
peachpuff: "#ffdab9",
|
|
117
|
+
peru: "#cd853f",
|
|
118
|
+
pink: "#ffc0cb",
|
|
119
|
+
plum: "#dda0dd",
|
|
120
|
+
powderblue: "#b0e0e6",
|
|
121
|
+
purple: "#800080",
|
|
122
|
+
rebeccapurple: "#663399",
|
|
123
|
+
red: "#ff0000",
|
|
124
|
+
rosybrown: "#bc8f8f",
|
|
125
|
+
royalblue: "#4169e1",
|
|
126
|
+
saddlebrown: "#8b4513",
|
|
127
|
+
salmon: "#fa8072",
|
|
128
|
+
sandybrown: "#f4a460",
|
|
129
|
+
seagreen: "#2e8b57",
|
|
130
|
+
seashell: "#fff5ee",
|
|
131
|
+
sienna: "#a0522d",
|
|
132
|
+
silver: "#c0c0c0",
|
|
133
|
+
skyblue: "#87ceeb",
|
|
134
|
+
slateblue: "#6a5acd",
|
|
135
|
+
slategray: "#708090",
|
|
136
|
+
slategrey: "#708090",
|
|
137
|
+
snow: "#fffafa",
|
|
138
|
+
springgreen: "#00ff7f",
|
|
139
|
+
steelblue: "#4682b4",
|
|
140
|
+
tan: "#d2b48c",
|
|
141
|
+
teal: "#008080",
|
|
142
|
+
thistle: "#d8bfd8",
|
|
143
|
+
tomato: "#ff6347",
|
|
144
|
+
turquoise: "#40e0d0",
|
|
145
|
+
violet: "#ee82ee",
|
|
146
|
+
wheat: "#f5deb3",
|
|
147
|
+
white: "#ffffff",
|
|
148
|
+
whitesmoke: "#f5f5f5",
|
|
149
|
+
yellow: "#ffff00",
|
|
150
|
+
yellowgreen: "#9acd32",
|
|
151
|
+
transparent: "#00000000"
|
|
151
152
|
};
|
|
153
|
+
/**
|
|
154
|
+
* Parse a CSS color string into RGBA components (0-1 range).
|
|
155
|
+
* Supports: #rgb, #rrggbb, #rgba, #rrggbbaa, rgb(), rgba(), hsl(), hsla(), named colors, 'transparent'.
|
|
156
|
+
*
|
|
157
|
+
* Also handles Excalibur's non-standard HSL format where h/s/l are all in 0-1 range (not degrees/%).
|
|
158
|
+
* Excalibur's Color.toString() returns `hsla(h, s, l, a)` with values in 0-1 normalized form
|
|
159
|
+
* (e.g. Color.White → "hsla(0, 0, 1, 1)", Color.Black → "hsla(0, 0, 0, 1)").
|
|
160
|
+
*/
|
|
152
161
|
function parseColor(color) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
else if (l > 1) l /= 100;
|
|
184
|
-
return hslToRGBA(h, s, l, Math.max(0, Math.min(1, a)));
|
|
185
|
-
}
|
|
186
|
-
return null;
|
|
162
|
+
if (!color || typeof color !== "string") return null;
|
|
163
|
+
const trimmed = color.trim().toLowerCase();
|
|
164
|
+
const named = NAMED_COLORS[trimmed];
|
|
165
|
+
if (named) return parseHex(named);
|
|
166
|
+
if (trimmed.startsWith("#")) return parseHex(trimmed);
|
|
167
|
+
const rgbMatch = trimmed.match(/^rgba?\(\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);
|
|
168
|
+
if (rgbMatch) {
|
|
169
|
+
return {
|
|
170
|
+
r: parseComponent(rgbMatch[1], 255) / 255,
|
|
171
|
+
g: parseComponent(rgbMatch[2], 255) / 255,
|
|
172
|
+
b: parseComponent(rgbMatch[3], 255) / 255,
|
|
173
|
+
a: rgbMatch[4] !== undefined ? parseComponent(rgbMatch[4], 1) : 1
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const hslMatch = trimmed.match(/^hsla?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);
|
|
177
|
+
if (hslMatch) {
|
|
178
|
+
let h = parseFloat(hslMatch[1]);
|
|
179
|
+
let s = parseFloat(hslMatch[2]);
|
|
180
|
+
const sPct = hslMatch[3] === "%";
|
|
181
|
+
let l = parseFloat(hslMatch[4]);
|
|
182
|
+
const lPct = hslMatch[5] === "%";
|
|
183
|
+
const a = hslMatch[6] !== undefined ? parseComponent(hslMatch[6], 1) : 1;
|
|
184
|
+
if (h > 1) h /= 360;
|
|
185
|
+
if (sPct) s /= 100;
|
|
186
|
+
else if (s > 1) s /= 100;
|
|
187
|
+
if (lPct) l /= 100;
|
|
188
|
+
else if (l > 1) l /= 100;
|
|
189
|
+
return hslToRGBA(h, s, l, Math.max(0, Math.min(1, a)));
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
187
192
|
}
|
|
188
193
|
function parseHex(hex) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
194
|
+
const h = hex.slice(1);
|
|
195
|
+
let r, g, b, a = 1;
|
|
196
|
+
if (h.length === 3) {
|
|
197
|
+
r = parseInt(h[0] + h[0], 16) / 255;
|
|
198
|
+
g = parseInt(h[1] + h[1], 16) / 255;
|
|
199
|
+
b = parseInt(h[2] + h[2], 16) / 255;
|
|
200
|
+
} else if (h.length === 4) {
|
|
201
|
+
r = parseInt(h[0] + h[0], 16) / 255;
|
|
202
|
+
g = parseInt(h[1] + h[1], 16) / 255;
|
|
203
|
+
b = parseInt(h[2] + h[2], 16) / 255;
|
|
204
|
+
a = parseInt(h[3] + h[3], 16) / 255;
|
|
205
|
+
} else if (h.length === 6) {
|
|
206
|
+
r = parseInt(h.slice(0, 2), 16) / 255;
|
|
207
|
+
g = parseInt(h.slice(2, 4), 16) / 255;
|
|
208
|
+
b = parseInt(h.slice(4, 6), 16) / 255;
|
|
209
|
+
} else if (h.length === 8) {
|
|
210
|
+
r = parseInt(h.slice(0, 2), 16) / 255;
|
|
211
|
+
g = parseInt(h.slice(2, 4), 16) / 255;
|
|
212
|
+
b = parseInt(h.slice(4, 6), 16) / 255;
|
|
213
|
+
a = parseInt(h.slice(6, 8), 16) / 255;
|
|
214
|
+
} else {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
r,
|
|
219
|
+
g,
|
|
220
|
+
b,
|
|
221
|
+
a
|
|
222
|
+
};
|
|
213
223
|
}
|
|
214
224
|
function parseComponent(value, max) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
225
|
+
if (value.endsWith("%")) {
|
|
226
|
+
return parseFloat(value) / 100 * max;
|
|
227
|
+
}
|
|
228
|
+
return parseFloat(value);
|
|
219
229
|
}
|
|
220
230
|
function hue2rgb(p, q, t) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
231
|
+
if (t < 0) t += 1;
|
|
232
|
+
if (t > 1) t -= 1;
|
|
233
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
234
|
+
if (t < 1 / 2) return q;
|
|
235
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
236
|
+
return p;
|
|
227
237
|
}
|
|
228
238
|
function hslToRGBA(h, s, l, a) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
let r, g, b;
|
|
240
|
+
if (s === 0) {
|
|
241
|
+
r = g = b = l;
|
|
242
|
+
} else {
|
|
243
|
+
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
244
|
+
const p = 2 * l - q;
|
|
245
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
246
|
+
g = hue2rgb(p, q, h);
|
|
247
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
r,
|
|
251
|
+
g,
|
|
252
|
+
b,
|
|
253
|
+
a
|
|
254
|
+
};
|
|
240
255
|
}
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
256
|
+
/** Default color: opaque black */
|
|
257
|
+
const BLACK = {
|
|
258
|
+
r: 0,
|
|
259
|
+
g: 0,
|
|
260
|
+
b: 0,
|
|
261
|
+
a: 1
|
|
247
262
|
};
|
|
263
|
+
/** Transparent black */
|
|
264
|
+
const TRANSPARENT = {
|
|
265
|
+
r: 0,
|
|
266
|
+
g: 0,
|
|
267
|
+
b: 0,
|
|
268
|
+
a: 0
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
//#endregion
|
|
272
|
+
export { BLACK, TRANSPARENT, parseColor };
|
package/lib/esm/image-data.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
//#region src/image-data.ts
|
|
2
|
+
/**
|
|
3
|
+
* ImageData represents the pixel data of a canvas area.
|
|
4
|
+
* Each pixel is 4 bytes: R, G, B, A (0-255 each).
|
|
5
|
+
*/
|
|
6
|
+
var OurImageData = class {
|
|
7
|
+
constructor(swOrData, sh, maybeHeight) {
|
|
8
|
+
this.colorSpace = "srgb";
|
|
9
|
+
if (typeof swOrData === "number") {
|
|
10
|
+
this.width = swOrData;
|
|
11
|
+
this.height = sh;
|
|
12
|
+
this.data = new Uint8ClampedArray(this.width * this.height * 4);
|
|
13
|
+
} else {
|
|
14
|
+
this.data = swOrData;
|
|
15
|
+
this.width = sh;
|
|
16
|
+
this.height = maybeHeight ?? this.data.length / (4 * this.width);
|
|
17
|
+
if (this.data.length !== this.width * this.height * 4) {
|
|
18
|
+
throw new RangeError(`Source data length ${this.data.length} is not a multiple of (4 * width=${this.width})`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
22
|
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { OurImageData };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseColor } from "./color.js";
|
|
2
2
|
import { CanvasGradient } from "./canvas-gradient.js";
|
|
3
|
-
import { CanvasPattern } from "./canvas-pattern.js";
|
|
4
3
|
import { Path2D } from "./canvas-path.js";
|
|
4
|
+
import { CanvasPattern } from "./canvas-pattern.js";
|
|
5
5
|
import { OurImageData } from "./image-data.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
CanvasPattern,
|
|
10
|
-
CanvasRenderingContext2D,
|
|
11
|
-
OurImageData as ImageData,
|
|
12
|
-
Path2D,
|
|
13
|
-
parseColor
|
|
14
|
-
};
|
|
6
|
+
import { CanvasRenderingContext2D } from "./canvas-rendering-context-2d.js";
|
|
7
|
+
|
|
8
|
+
export { CanvasGradient, CanvasPattern, CanvasRenderingContext2D, OurImageData as ImageData, Path2D, parseColor };
|