@gjsify/canvas2d-core 0.3.16 → 0.3.18
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 +1 -191
- package/lib/esm/canvas-gradient.js +1 -28
- package/lib/esm/canvas-path.js +1 -161
- package/lib/esm/canvas-pattern.js +1 -63
- package/lib/esm/canvas-rendering-context-2d.js +1 -975
- package/lib/esm/canvas-state.js +1 -40
- package/lib/esm/color.js +1 -272
- package/lib/esm/image-data.js +1 -25
- package/lib/esm/index.js +1 -8
- package/package.json +11 -11
- package/tmp/.tsbuildinfo +1 -1
package/lib/esm/canvas-state.js
CHANGED
|
@@ -1,40 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/canvas-state.ts
|
|
4
|
-
function createDefaultState() {
|
|
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
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function cloneState(state) {
|
|
31
|
-
return {
|
|
32
|
-
...state,
|
|
33
|
-
fillColor: { ...state.fillColor },
|
|
34
|
-
strokeColor: { ...state.strokeColor },
|
|
35
|
-
lineDash: [...state.lineDash]
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
export { cloneState, createDefaultState };
|
|
1
|
+
import{BLACK as e}from"./color.js";function t(){return{fillStyle:`#000000`,fillColor:{...e},strokeStyle:`#000000`,strokeColor:{...e},lineWidth:1,lineCap:`butt`,lineJoin:`miter`,miterLimit:10,lineDash:[],lineDashOffset:0,globalAlpha:1,globalCompositeOperation:`source-over`,shadowColor:`rgba(0, 0, 0, 0)`,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,font:`10px sans-serif`,textAlign:`start`,textBaseline:`alphabetic`,direction:`ltr`,imageSmoothingEnabled:!0,imageSmoothingQuality:`low`}}function n(e){return{...e,fillColor:{...e.fillColor},strokeColor:{...e.strokeColor},lineDash:[...e.lineDash]}}export{n as cloneState,t as createDefaultState};
|
package/lib/esm/color.js
CHANGED
|
@@ -1,272 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const NAMED_COLORS = {
|
|
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"
|
|
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
|
-
*/
|
|
161
|
-
function parseColor(color) {
|
|
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;
|
|
192
|
-
}
|
|
193
|
-
function parseHex(hex) {
|
|
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
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function parseComponent(value, max) {
|
|
225
|
-
if (value.endsWith("%")) {
|
|
226
|
-
return parseFloat(value) / 100 * max;
|
|
227
|
-
}
|
|
228
|
-
return parseFloat(value);
|
|
229
|
-
}
|
|
230
|
-
function hue2rgb(p, q, t) {
|
|
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;
|
|
237
|
-
}
|
|
238
|
-
function hslToRGBA(h, s, l, a) {
|
|
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
|
-
};
|
|
255
|
-
}
|
|
256
|
-
/** Default color: opaque black */
|
|
257
|
-
const BLACK = {
|
|
258
|
-
r: 0,
|
|
259
|
-
g: 0,
|
|
260
|
-
b: 0,
|
|
261
|
-
a: 1
|
|
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 };
|
|
1
|
+
const e={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkgrey:`#a9a9a9`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,green:`#008000`,greenyellow:`#adff2f`,grey:`#808080`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightgrey:`#d3d3d3`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightslategrey:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,slategrey:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`,transparent:`#00000000`};function t(t){if(!t||typeof t!=`string`)return null;let i=t.trim().toLowerCase(),o=e[i];if(o)return n(o);if(i.startsWith(`#`))return n(i);let s=i.match(/^rgba?\(\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(s)return{r:r(s[1],255)/255,g:r(s[2],255)/255,b:r(s[3],255)/255,a:s[4]===void 0?1:r(s[4],1)};let c=i.match(/^hsla?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(c){let e=parseFloat(c[1]),t=parseFloat(c[2]),n=c[3]===`%`,i=parseFloat(c[4]),o=c[5]===`%`,s=c[6]===void 0?1:r(c[6],1);return e>1&&(e/=360),(n||t>1)&&(t/=100),(o||i>1)&&(i/=100),a(e,t,i,Math.max(0,Math.min(1,s)))}return null}function n(e){let t=e.slice(1),n,r,i,a=1;if(t.length===3)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255;else if(t.length===4)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255,a=parseInt(t[3]+t[3],16)/255;else if(t.length===6)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255;else if(t.length===8)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255,a=parseInt(t.slice(6,8),16)/255;else return null;return{r:n,g:r,b:i,a}}function r(e,t){return e.endsWith(`%`)?parseFloat(e)/100*t:parseFloat(e)}function i(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}function a(e,t,n,r){let a,o,s;if(t===0)a=o=s=n;else{let r=n<.5?n*(1+t):n+t-n*t,c=2*n-r;a=i(c,r,e+1/3),o=i(c,r,e),s=i(c,r,e-1/3)}return{r:a,g:o,b:s,a:r}}const o={r:0,g:0,b:0,a:1},s={r:0,g:0,b:0,a:0};export{o as BLACK,s as TRANSPARENT,t as parseColor};
|
package/lib/esm/image-data.js
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { OurImageData };
|
|
1
|
+
var e=class{constructor(e,t,n){if(this.colorSpace=`srgb`,typeof e==`number`)this.width=e,this.height=t,this.data=new Uint8ClampedArray(this.width*this.height*4);else if(this.data=e,this.width=t,this.height=n??this.data.length/(4*this.width),this.data.length!==this.width*this.height*4)throw RangeError(`Source data length ${this.data.length} is not a multiple of (4 * width=${this.width})`)}};export{e as OurImageData};
|
package/lib/esm/index.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CanvasGradient } from "./canvas-gradient.js";
|
|
3
|
-
import { Path2D } from "./canvas-path.js";
|
|
4
|
-
import { CanvasPattern } from "./canvas-pattern.js";
|
|
5
|
-
import { OurImageData } from "./image-data.js";
|
|
6
|
-
import { CanvasRenderingContext2D } from "./canvas-rendering-context-2d.js";
|
|
7
|
-
|
|
8
|
-
export { CanvasGradient, CanvasPattern, CanvasRenderingContext2D, OurImageData as ImageData, Path2D, parseColor };
|
|
1
|
+
import{parseColor as e}from"./color.js";import{CanvasGradient as t}from"./canvas-gradient.js";import{Path2D as n}from"./canvas-path.js";import{CanvasPattern as r}from"./canvas-pattern.js";import{OurImageData as i}from"./image-data.js";import{CanvasRenderingContext2D as a}from"./canvas-rendering-context-2d.js";export{t as CanvasGradient,r as CanvasPattern,a as CanvasRenderingContext2D,i as ImageData,n as Path2D,e as parseColor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/canvas2d-core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
4
4
|
"description": "Cairo-backed Canvas 2D core (CanvasRenderingContext2D, Path2D, ImageData) — no GTK dependency",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"offscreen"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@girs/gdk-4.0": "4.0.0-4.0.0-rc.
|
|
35
|
-
"@girs/gdkpixbuf-2.0": "2.0.0-4.0.0-rc.
|
|
36
|
-
"@girs/gjs": "4.0.0-rc.
|
|
37
|
-
"@girs/glib-2.0": "2.88.0-4.0.0-rc.
|
|
38
|
-
"@girs/gobject-2.0": "2.88.0-4.0.0-rc.
|
|
39
|
-
"@girs/pango-1.0": "1.57.1-4.0.0-rc.
|
|
40
|
-
"@girs/pangocairo-1.0": "1.0.0-4.0.0-rc.
|
|
34
|
+
"@girs/gdk-4.0": "4.0.0-4.0.0-rc.14",
|
|
35
|
+
"@girs/gdkpixbuf-2.0": "2.0.0-4.0.0-rc.14",
|
|
36
|
+
"@girs/gjs": "4.0.0-rc.14",
|
|
37
|
+
"@girs/glib-2.0": "2.88.0-4.0.0-rc.14",
|
|
38
|
+
"@girs/gobject-2.0": "2.88.0-4.0.0-rc.14",
|
|
39
|
+
"@girs/pango-1.0": "1.57.1-4.0.0-rc.14",
|
|
40
|
+
"@girs/pangocairo-1.0": "1.0.0-4.0.0-rc.14"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@gjsify/cli": "^0.3.
|
|
44
|
-
"@gjsify/unit": "^0.3.
|
|
45
|
-
"@types/node": "^25.6.
|
|
43
|
+
"@gjsify/cli": "^0.3.18",
|
|
44
|
+
"@gjsify/unit": "^0.3.18",
|
|
45
|
+
"@types/node": "^25.6.2",
|
|
46
46
|
"typescript": "^6.0.3"
|
|
47
47
|
}
|
|
48
48
|
}
|