@pixerate/editor 0.207.0 → 0.208.0
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/dist/animation-editor/index.cjs +60 -59
- package/dist/animation-editor/index.js +6 -5
- package/dist/{brushstrokeRender-7LXCU7PD.js → brushstrokeRender-C3UU6GVC.js} +5 -4
- package/dist/{brushstrokeRender-VO4ZTWVA.cjs → brushstrokeRender-EAJNE6WP.cjs} +12 -11
- package/dist/canvas/index.cjs +8 -8
- package/dist/canvas/index.js +1 -1
- package/dist/{chunk-2N2QPO3H.js → chunk-2PBZBRP5.js} +9 -7
- package/dist/{chunk-7NW46N7I.cjs → chunk-3EHPLDFQ.cjs} +54 -52
- package/dist/{chunk-H367YTXI.js → chunk-42TWUPNJ.js} +13 -387
- package/dist/chunk-474IQG74.cjs +384 -0
- package/dist/{chunk-MLC7HUHO.js → chunk-BGOCAUXH.js} +1 -1
- package/dist/chunk-DWYQPL2A.js +2010 -0
- package/dist/{chunk-YXKLVD56.js → chunk-F7YA3MMC.js} +2 -2
- package/dist/{chunk-ZZGPYNS2.js → chunk-G4E6RUPC.js} +1 -1
- package/dist/chunk-HVVR5PZW.js +384 -0
- package/dist/{chunk-FR2Q2LVF.cjs → chunk-I7G3RSUJ.cjs} +35 -35
- package/dist/chunk-K6PXS6DO.cjs +102 -0
- package/dist/{chunk-ZIDUPSP4.js → chunk-KFIOEOCQ.js} +24 -761
- package/dist/{chunk-V7GWZIZK.cjs → chunk-KWNMBMKG.cjs} +23 -21
- package/dist/chunk-L3G23N5Y.js +763 -0
- package/dist/{chunk-GHCXLQ47.js → chunk-NDMXB4PR.js} +2 -2
- package/dist/{chunk-CWM3CUUX.cjs → chunk-OLNIPTB3.cjs} +39 -413
- package/dist/{chunk-EBDCRTZI.cjs → chunk-PQ3H2AAN.cjs} +92 -90
- package/dist/{chunk-BRKVNXDZ.cjs → chunk-QAUIZPYI.cjs} +7 -7
- package/dist/{chunk-UYXL6ZWQ.cjs → chunk-QE7D7TZR.cjs} +494 -1231
- package/dist/chunk-QYLWG22N.cjs +763 -0
- package/dist/{chunk-YQ5C5BVK.cjs → chunk-ROVK6AXX.cjs} +60 -60
- package/dist/{chunk-HGTDMKNE.cjs → chunk-UOGKSVRQ.cjs} +126 -221
- package/dist/{chunk-EL5PAHNP.js → chunk-USQCKRZG.js} +6 -4
- package/dist/{chunk-36OKQDCF.js → chunk-WJ2RBZMM.js} +5 -3
- package/dist/chunk-X4LUGTQX.cjs +2010 -0
- package/dist/{chunk-NQMP3CWF.js → chunk-YBJXCQTR.js} +15 -110
- package/dist/chunk-ZIF4UJJ6.js +102 -0
- package/dist/{chunk-WTW7QRTS.cjs → chunk-ZMHPQ6HP.cjs} +1 -1
- package/dist/image-editor/controller.d.cts +28 -3
- package/dist/image-editor/controller.d.ts +28 -3
- package/dist/image-editor/index.cjs +1726 -3359
- package/dist/image-editor/index.js +241 -1874
- package/dist/image-editor/selection/index.d.cts +1 -0
- package/dist/image-editor/selection/index.d.ts +1 -0
- package/dist/image-editor/selection/segment/focus.d.cts +2 -0
- package/dist/image-editor/selection/segment/focus.d.ts +2 -0
- package/dist/image-editor/selection/segment/grabcut.d.cts +4 -2
- package/dist/image-editor/selection/segment/grabcut.d.ts +4 -2
- package/dist/image-editor/selection/segment/sky.d.cts +2 -0
- package/dist/image-editor/selection/segment/sky.d.ts +2 -0
- package/dist/image-editor/selection/segment/subject.d.cts +2 -1
- package/dist/image-editor/selection/segment/subject.d.ts +2 -1
- package/dist/image-editor/selection/segment/work.d.cts +5 -0
- package/dist/image-editor/selection/segment/work.d.ts +5 -0
- package/dist/image-editor/selection/select-and-mask.d.cts +12 -2
- package/dist/image-editor/selection/select-and-mask.d.ts +12 -2
- package/dist/image-editor/selection/worker.d.cts +126 -0
- package/dist/image-editor/selection/worker.d.ts +126 -0
- package/dist/image-editor/selection-worker.cjs +14 -0
- package/dist/image-editor/selection-worker.d.cts +12 -0
- package/dist/image-editor/selection-worker.d.ts +12 -0
- package/dist/image-editor/selection-worker.js +14 -0
- package/dist/image-editor/types.d.cts +8 -0
- package/dist/image-editor/types.d.ts +8 -0
- package/dist/paint/index.cjs +6 -5
- package/dist/paint/index.js +5 -4
- package/dist/paint-editor/index.cjs +394 -390
- package/dist/paint-editor/index.js +18 -14
- package/dist/raster/index.cjs +22 -18
- package/dist/raster/index.js +29 -25
- package/dist/vector/index.cjs +986 -985
- package/dist/vector/index.js +6 -5
- package/package.json +11 -1
|
@@ -20,13 +20,13 @@ import {
|
|
|
20
20
|
randSigned,
|
|
21
21
|
rasterizeDab,
|
|
22
22
|
readPaintSource
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-2PBZBRP5.js";
|
|
24
24
|
import {
|
|
25
25
|
TILE,
|
|
26
26
|
TiledSurface,
|
|
27
27
|
finishTile,
|
|
28
28
|
tileKey
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-HVVR5PZW.js";
|
|
30
30
|
|
|
31
31
|
// src/paint-editor/paper.ts
|
|
32
32
|
var PAPER_FAMILIES = ["watercolor", "drawing", "pastel", "canvas", "panel", "smooth"];
|
|
@@ -74,7 +74,7 @@ function profileAlongPolyline(points, values, count = 32) {
|
|
|
74
74
|
var round3 = (v) => Math.round(v * 1e3) / 1e3;
|
|
75
75
|
var loading = null;
|
|
76
76
|
function loadCanvasBrushstrokeRenderer() {
|
|
77
|
-
loading ??= import("./brushstrokeRender-
|
|
77
|
+
loading ??= import("./brushstrokeRender-C3UU6GVC.js").catch((error) => {
|
|
78
78
|
loading = null;
|
|
79
79
|
throw error;
|
|
80
80
|
});
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
// src/raster/surface.ts
|
|
2
|
+
var TILE = 256;
|
|
3
|
+
var TILE_SHIFT = 8;
|
|
4
|
+
var TILE_PIXELS = TILE * TILE;
|
|
5
|
+
var KEY_OFFSET = 1 << 15;
|
|
6
|
+
var KEY_SPAN = 1 << 16;
|
|
7
|
+
function tileKey(tx, ty) {
|
|
8
|
+
return (ty + KEY_OFFSET) * KEY_SPAN + (tx + KEY_OFFSET);
|
|
9
|
+
}
|
|
10
|
+
function tileCoord(key) {
|
|
11
|
+
return { tx: key % KEY_SPAN - KEY_OFFSET, ty: Math.floor(key / KEY_SPAN) - KEY_OFFSET };
|
|
12
|
+
}
|
|
13
|
+
function tileRect(tx, ty) {
|
|
14
|
+
return { x: tx * TILE, y: ty * TILE, width: TILE, height: TILE };
|
|
15
|
+
}
|
|
16
|
+
var nextSurfaceId = 1;
|
|
17
|
+
var TiledSurface = class {
|
|
18
|
+
constructor(channels, tiles, defaultValue = 0) {
|
|
19
|
+
this.channels = channels;
|
|
20
|
+
this.tiles = tiles;
|
|
21
|
+
this.defaultValue = defaultValue;
|
|
22
|
+
}
|
|
23
|
+
channels;
|
|
24
|
+
tiles;
|
|
25
|
+
defaultValue;
|
|
26
|
+
/** Unique per instance: a cache key that changes whenever the pixels can have changed. */
|
|
27
|
+
id = nextSurfaceId++;
|
|
28
|
+
boundsCache;
|
|
29
|
+
/** Bounds of the stored (non-default) tiles, tile-aligned; `null` when there are none. */
|
|
30
|
+
get bounds() {
|
|
31
|
+
if (this.boundsCache === void 0) this.boundsCache = tileUnion(this.tiles.keys());
|
|
32
|
+
return this.boundsCache;
|
|
33
|
+
}
|
|
34
|
+
get tileCount() {
|
|
35
|
+
return this.tiles.size;
|
|
36
|
+
}
|
|
37
|
+
getTile(tx, ty) {
|
|
38
|
+
return this.tiles.get(tileKey(tx, ty));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function tileUnion(keys) {
|
|
42
|
+
let x0 = Infinity;
|
|
43
|
+
let y0 = Infinity;
|
|
44
|
+
let x1 = -Infinity;
|
|
45
|
+
let y1 = -Infinity;
|
|
46
|
+
for (const key of keys) {
|
|
47
|
+
const { tx, ty } = tileCoord(key);
|
|
48
|
+
if (tx < x0) x0 = tx;
|
|
49
|
+
if (ty < y0) y0 = ty;
|
|
50
|
+
if (tx > x1) x1 = tx;
|
|
51
|
+
if (ty > y1) y1 = ty;
|
|
52
|
+
}
|
|
53
|
+
if (x0 === Infinity) return null;
|
|
54
|
+
return { x: x0 * TILE, y: y0 * TILE, width: (x1 - x0 + 1) * TILE, height: (y1 - y0 + 1) * TILE };
|
|
55
|
+
}
|
|
56
|
+
var uniformTiles = /* @__PURE__ */ new Map();
|
|
57
|
+
var UNIFORM_LIMIT = 64;
|
|
58
|
+
function packPixel(data, offset, channels) {
|
|
59
|
+
return channels === 1 ? data[offset] : (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
|
|
60
|
+
}
|
|
61
|
+
function uniformTile(channels, value) {
|
|
62
|
+
const key = `${channels}:${value}`;
|
|
63
|
+
let tile = uniformTiles.get(key);
|
|
64
|
+
if (tile) return tile;
|
|
65
|
+
const data = new Uint8ClampedArray(TILE_PIXELS * channels);
|
|
66
|
+
if (channels === 1) data.fill(value);
|
|
67
|
+
else if (value !== 0) {
|
|
68
|
+
const r = value >>> 24;
|
|
69
|
+
const g = value >>> 16 & 255;
|
|
70
|
+
const b = value >>> 8 & 255;
|
|
71
|
+
const a = value & 255;
|
|
72
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
73
|
+
data[i] = r;
|
|
74
|
+
data[i + 1] = g;
|
|
75
|
+
data[i + 2] = b;
|
|
76
|
+
data[i + 3] = a;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
tile = { data, uniform: value };
|
|
80
|
+
if (uniformTiles.size >= UNIFORM_LIMIT) uniformTiles.delete(uniformTiles.keys().next().value);
|
|
81
|
+
uniformTiles.set(key, tile);
|
|
82
|
+
return tile;
|
|
83
|
+
}
|
|
84
|
+
function packRgba(r, g, b, a) {
|
|
85
|
+
return (r << 24 | g << 16 | b << 8 | a) >>> 0;
|
|
86
|
+
}
|
|
87
|
+
function defaultPacked(channels, defaultValue) {
|
|
88
|
+
return channels === 1 ? defaultValue : packRgba(defaultValue, defaultValue, defaultValue, defaultValue);
|
|
89
|
+
}
|
|
90
|
+
function uniformValue(data, channels) {
|
|
91
|
+
if (channels === 1) {
|
|
92
|
+
const v = data[0];
|
|
93
|
+
for (let i = 1; i < data.length; i++) if (data[i] !== v) return null;
|
|
94
|
+
return v;
|
|
95
|
+
}
|
|
96
|
+
const words = new Uint32Array(data.buffer, data.byteOffset, data.length >> 2);
|
|
97
|
+
const w = words[0];
|
|
98
|
+
for (let i = 1; i < words.length; i++) if (words[i] !== w) return null;
|
|
99
|
+
return packPixel(data, 0, 4);
|
|
100
|
+
}
|
|
101
|
+
function finishTile(data, channels, defaultValue) {
|
|
102
|
+
const u = uniformValue(data, channels);
|
|
103
|
+
if (u === null) return { data, uniform: null };
|
|
104
|
+
if (u === defaultPacked(channels, defaultValue)) return null;
|
|
105
|
+
return uniformTile(channels, u);
|
|
106
|
+
}
|
|
107
|
+
function emptySurface(channels = 4, defaultValue = 0) {
|
|
108
|
+
return new TiledSurface(channels, /* @__PURE__ */ new Map(), defaultValue);
|
|
109
|
+
}
|
|
110
|
+
function solidSurface(channels, rect, value, defaultValue = 0) {
|
|
111
|
+
const bytes = new Uint8ClampedArray(channels);
|
|
112
|
+
if (channels === 1) bytes[0] = value;
|
|
113
|
+
else {
|
|
114
|
+
bytes[0] = value >>> 24;
|
|
115
|
+
bytes[1] = value >>> 16 & 255;
|
|
116
|
+
bytes[2] = value >>> 8 & 255;
|
|
117
|
+
bytes[3] = value & 255;
|
|
118
|
+
}
|
|
119
|
+
return fillRect(emptySurface(channels, defaultValue), rect, bytes);
|
|
120
|
+
}
|
|
121
|
+
function surfaceFromPixels(pixels, channels = 4, x = 0, y = 0, defaultValue = 0) {
|
|
122
|
+
return writeRegion(emptySurface(channels, defaultValue), { x, y, width: pixels.width, height: pixels.height }, pixels.data);
|
|
123
|
+
}
|
|
124
|
+
function tilesInRect(rect) {
|
|
125
|
+
const out = [];
|
|
126
|
+
if (rect.width <= 0 || rect.height <= 0) return out;
|
|
127
|
+
const tx0 = Math.floor(rect.x / TILE);
|
|
128
|
+
const ty0 = Math.floor(rect.y / TILE);
|
|
129
|
+
const tx1 = Math.floor((rect.x + rect.width - 1) / TILE);
|
|
130
|
+
const ty1 = Math.floor((rect.y + rect.height - 1) / TILE);
|
|
131
|
+
for (let ty = ty0; ty <= ty1; ty++) for (let tx = tx0; tx <= tx1; tx++) out.push({ tx, ty });
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
function readRegion(surface, rect, out) {
|
|
135
|
+
const ch = surface.channels;
|
|
136
|
+
const w = rect.width;
|
|
137
|
+
const h = rect.height;
|
|
138
|
+
const dst = out ?? new Uint8ClampedArray(w * h * ch);
|
|
139
|
+
if (surface.defaultValue !== 0) dst.fill(surface.defaultValue);
|
|
140
|
+
else if (out) dst.fill(0);
|
|
141
|
+
for (const { tx, ty } of tilesInRect(rect)) {
|
|
142
|
+
const tile = surface.getTile(tx, ty);
|
|
143
|
+
if (!tile) continue;
|
|
144
|
+
const ox = tx * TILE;
|
|
145
|
+
const oy = ty * TILE;
|
|
146
|
+
const x0 = Math.max(rect.x, ox);
|
|
147
|
+
const y0 = Math.max(rect.y, oy);
|
|
148
|
+
const x1 = Math.min(rect.x + w, ox + TILE);
|
|
149
|
+
const y1 = Math.min(rect.y + h, oy + TILE);
|
|
150
|
+
const span = (x1 - x0) * ch;
|
|
151
|
+
for (let yy = y0; yy < y1; yy++) {
|
|
152
|
+
const s = ((yy - oy) * TILE + (x0 - ox)) * ch;
|
|
153
|
+
const d = ((yy - rect.y) * w + (x0 - rect.x)) * ch;
|
|
154
|
+
dst.set(tile.data.subarray(s, s + span), d);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return dst;
|
|
158
|
+
}
|
|
159
|
+
function readPixel(surface, x, y) {
|
|
160
|
+
const tile = surface.getTile(Math.floor(x / TILE), Math.floor(y / TILE));
|
|
161
|
+
const ch = surface.channels;
|
|
162
|
+
if (!tile) return new Array(ch).fill(surface.defaultValue);
|
|
163
|
+
const i = ((y & TILE - 1) * TILE + (x & TILE - 1)) * ch;
|
|
164
|
+
return Array.from(tile.data.subarray(i, i + ch));
|
|
165
|
+
}
|
|
166
|
+
function contentBounds(surface) {
|
|
167
|
+
const ch = surface.channels;
|
|
168
|
+
const def = surface.defaultValue;
|
|
169
|
+
let x0 = Infinity;
|
|
170
|
+
let y0 = Infinity;
|
|
171
|
+
let x1 = -Infinity;
|
|
172
|
+
let y1 = -Infinity;
|
|
173
|
+
for (const [key, tile] of surface.tiles) {
|
|
174
|
+
const { tx, ty } = tileCoord(key);
|
|
175
|
+
const ox = tx * TILE;
|
|
176
|
+
const oy = ty * TILE;
|
|
177
|
+
if (tile.uniform !== null) {
|
|
178
|
+
if (ox < x0) x0 = ox;
|
|
179
|
+
if (oy < y0) y0 = oy;
|
|
180
|
+
if (ox + TILE - 1 > x1) x1 = ox + TILE - 1;
|
|
181
|
+
if (oy + TILE - 1 > y1) y1 = oy + TILE - 1;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const d = tile.data;
|
|
185
|
+
for (let y = 0; y < TILE; y++) {
|
|
186
|
+
let first = -1;
|
|
187
|
+
let last = -1;
|
|
188
|
+
const row = y * TILE * ch;
|
|
189
|
+
for (let x = 0; x < TILE; x++) {
|
|
190
|
+
const i = row + x * ch;
|
|
191
|
+
let differs = false;
|
|
192
|
+
for (let c = 0; c < ch; c++) if (d[i + c] !== def) differs = true;
|
|
193
|
+
if (differs) {
|
|
194
|
+
if (first < 0) first = x;
|
|
195
|
+
last = x;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (first < 0) continue;
|
|
199
|
+
if (ox + first < x0) x0 = ox + first;
|
|
200
|
+
if (ox + last > x1) x1 = ox + last;
|
|
201
|
+
if (oy + y < y0) y0 = oy + y;
|
|
202
|
+
if (oy + y > y1) y1 = oy + y;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (x0 === Infinity) return null;
|
|
206
|
+
return { x: x0, y: y0, width: x1 - x0 + 1, height: y1 - y0 + 1 };
|
|
207
|
+
}
|
|
208
|
+
var SurfaceDraft = class {
|
|
209
|
+
constructor(base) {
|
|
210
|
+
this.base = base;
|
|
211
|
+
}
|
|
212
|
+
base;
|
|
213
|
+
copies = /* @__PURE__ */ new Map();
|
|
214
|
+
get channels() {
|
|
215
|
+
return this.base.channels;
|
|
216
|
+
}
|
|
217
|
+
/** The writable data of tile (tx, ty), copied from the base on first use. */
|
|
218
|
+
tile(tx, ty) {
|
|
219
|
+
const key = tileKey(tx, ty);
|
|
220
|
+
let data = this.copies.get(key);
|
|
221
|
+
if (data) return data;
|
|
222
|
+
const src = this.base.tiles.get(key);
|
|
223
|
+
if (src) data = new Uint8ClampedArray(src.data);
|
|
224
|
+
else {
|
|
225
|
+
data = new Uint8ClampedArray(TILE_PIXELS * this.base.channels);
|
|
226
|
+
if (this.base.defaultValue !== 0) data.fill(this.base.defaultValue);
|
|
227
|
+
}
|
|
228
|
+
this.copies.set(key, data);
|
|
229
|
+
return data;
|
|
230
|
+
}
|
|
231
|
+
/** Replaces a whole tile with `data` (owned by the draft from now on). */
|
|
232
|
+
replace(tx, ty, data) {
|
|
233
|
+
this.copies.set(tileKey(tx, ty), data);
|
|
234
|
+
}
|
|
235
|
+
/** The current data of a tile without copying it (base tile, draft copy or `null` for default). */
|
|
236
|
+
peek(tx, ty) {
|
|
237
|
+
const key = tileKey(tx, ty);
|
|
238
|
+
return this.copies.get(key) ?? this.base.tiles.get(key)?.data ?? null;
|
|
239
|
+
}
|
|
240
|
+
/** Keys of the tiles changed so far. */
|
|
241
|
+
get touched() {
|
|
242
|
+
return [...this.copies.keys()];
|
|
243
|
+
}
|
|
244
|
+
/** A new surface with the draft's tiles; the draft must not be used afterwards. */
|
|
245
|
+
commit() {
|
|
246
|
+
if (!this.copies.size) return this.base;
|
|
247
|
+
const tiles = new Map(this.base.tiles);
|
|
248
|
+
const { channels, defaultValue } = this.base;
|
|
249
|
+
for (const [key, data] of this.copies) {
|
|
250
|
+
const tile = finishTile(data, channels, defaultValue);
|
|
251
|
+
if (tile) tiles.set(key, tile);
|
|
252
|
+
else tiles.delete(key);
|
|
253
|
+
}
|
|
254
|
+
return new TiledSurface(channels, tiles, defaultValue);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
function writeRegion(surface, rect, data) {
|
|
258
|
+
const ch = surface.channels;
|
|
259
|
+
const w = rect.width;
|
|
260
|
+
const h = rect.height;
|
|
261
|
+
if (w <= 0 || h <= 0) return surface;
|
|
262
|
+
if (data.length < w * h * ch) throw new Error(`writeRegion: expected ${w * h * ch} bytes, got ${data.length}`);
|
|
263
|
+
const draft = new SurfaceDraft(surface);
|
|
264
|
+
const src = data;
|
|
265
|
+
const canSubarray = typeof src.subarray === "function";
|
|
266
|
+
for (const { tx, ty } of tilesInRect(rect)) {
|
|
267
|
+
const ox = tx * TILE;
|
|
268
|
+
const oy = ty * TILE;
|
|
269
|
+
const x0 = Math.max(rect.x, ox);
|
|
270
|
+
const y0 = Math.max(rect.y, oy);
|
|
271
|
+
const x1 = Math.min(rect.x + w, ox + TILE);
|
|
272
|
+
const y1 = Math.min(rect.y + h, oy + TILE);
|
|
273
|
+
const full = x0 === ox && y0 === oy && x1 === ox + TILE && y1 === oy + TILE;
|
|
274
|
+
const t = full ? new Uint8ClampedArray(TILE_PIXELS * ch) : draft.tile(tx, ty);
|
|
275
|
+
const span = (x1 - x0) * ch;
|
|
276
|
+
for (let yy = y0; yy < y1; yy++) {
|
|
277
|
+
const s = ((yy - rect.y) * w + (x0 - rect.x)) * ch;
|
|
278
|
+
const d = ((yy - oy) * TILE + (x0 - ox)) * ch;
|
|
279
|
+
if (canSubarray) t.set(src.subarray(s, s + span), d);
|
|
280
|
+
else for (let k = 0; k < span; k++) t[d + k] = src[s + k];
|
|
281
|
+
}
|
|
282
|
+
if (full) draft.replace(tx, ty, t);
|
|
283
|
+
}
|
|
284
|
+
return draft.commit();
|
|
285
|
+
}
|
|
286
|
+
function fillRect(surface, rect, bytes) {
|
|
287
|
+
const ch = surface.channels;
|
|
288
|
+
if (rect.width <= 0 || rect.height <= 0) return surface;
|
|
289
|
+
const tiles = new Map(surface.tiles);
|
|
290
|
+
const draft = new SurfaceDraft(surface);
|
|
291
|
+
const value = packPixel(bytes, 0, ch);
|
|
292
|
+
const isDefault = value === defaultPacked(ch, surface.defaultValue);
|
|
293
|
+
for (const { tx, ty } of tilesInRect(rect)) {
|
|
294
|
+
const ox = tx * TILE;
|
|
295
|
+
const oy = ty * TILE;
|
|
296
|
+
const x0 = Math.max(rect.x, ox);
|
|
297
|
+
const y0 = Math.max(rect.y, oy);
|
|
298
|
+
const x1 = Math.min(rect.x + rect.width, ox + TILE);
|
|
299
|
+
const y1 = Math.min(rect.y + rect.height, oy + TILE);
|
|
300
|
+
const key = tileKey(tx, ty);
|
|
301
|
+
if (x0 === ox && y0 === oy && x1 === ox + TILE && y1 === oy + TILE) {
|
|
302
|
+
if (isDefault) tiles.delete(key);
|
|
303
|
+
else tiles.set(key, uniformTile(ch, value));
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const t = draft.tile(tx, ty);
|
|
307
|
+
for (let yy = y0; yy < y1; yy++) {
|
|
308
|
+
let d = ((yy - oy) * TILE + (x0 - ox)) * ch;
|
|
309
|
+
for (let xx = x0; xx < x1; xx++, d += ch) for (let c = 0; c < ch; c++) t[d + c] = bytes[c];
|
|
310
|
+
}
|
|
311
|
+
const tile = finishTile(t, ch, surface.defaultValue);
|
|
312
|
+
if (tile) tiles.set(key, tile);
|
|
313
|
+
else tiles.delete(key);
|
|
314
|
+
}
|
|
315
|
+
return new TiledSurface(ch, tiles, surface.defaultValue);
|
|
316
|
+
}
|
|
317
|
+
function translateSurface(surface, dx, dy) {
|
|
318
|
+
dx = Math.round(dx);
|
|
319
|
+
dy = Math.round(dy);
|
|
320
|
+
if (!dx && !dy) return surface;
|
|
321
|
+
if (dx % TILE === 0 && dy % TILE === 0) {
|
|
322
|
+
const tiles = /* @__PURE__ */ new Map();
|
|
323
|
+
for (const [key, tile] of surface.tiles) {
|
|
324
|
+
const { tx, ty } = tileCoord(key);
|
|
325
|
+
tiles.set(tileKey(tx + dx / TILE, ty + dy / TILE), tile);
|
|
326
|
+
}
|
|
327
|
+
return new TiledSurface(surface.channels, tiles, surface.defaultValue);
|
|
328
|
+
}
|
|
329
|
+
const b = surface.bounds;
|
|
330
|
+
if (!b) return surface;
|
|
331
|
+
const data = readRegion(surface, b);
|
|
332
|
+
return writeRegion(emptySurface(surface.channels, surface.defaultValue), { ...b, x: b.x + dx, y: b.y + dy }, data);
|
|
333
|
+
}
|
|
334
|
+
function surfaceBytes(surface) {
|
|
335
|
+
let n = 0;
|
|
336
|
+
for (const tile of surface.tiles.values()) if (tile.uniform === null) n += tile.data.byteLength;
|
|
337
|
+
return n;
|
|
338
|
+
}
|
|
339
|
+
function collectTiles(surface, into) {
|
|
340
|
+
for (const tile of surface.tiles.values()) if (tile.uniform === null) into.add(tile);
|
|
341
|
+
}
|
|
342
|
+
function surfacesEqual(a, b) {
|
|
343
|
+
if (a === b) return true;
|
|
344
|
+
if (a.channels !== b.channels || a.defaultValue !== b.defaultValue || a.tiles.size !== b.tiles.size) return false;
|
|
345
|
+
for (const [key, ta] of a.tiles) {
|
|
346
|
+
const tb = b.tiles.get(key);
|
|
347
|
+
if (!tb) return false;
|
|
348
|
+
if (ta === tb) continue;
|
|
349
|
+
if (ta.uniform !== null || tb.uniform !== null) {
|
|
350
|
+
if (ta.uniform !== tb.uniform) return false;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const x = ta.data;
|
|
354
|
+
const y = tb.data;
|
|
355
|
+
for (let i = 0; i < x.length; i++) if (x[i] !== y[i]) return false;
|
|
356
|
+
}
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export {
|
|
361
|
+
TILE,
|
|
362
|
+
TILE_SHIFT,
|
|
363
|
+
tileKey,
|
|
364
|
+
tileCoord,
|
|
365
|
+
tileRect,
|
|
366
|
+
TiledSurface,
|
|
367
|
+
uniformTile,
|
|
368
|
+
packRgba,
|
|
369
|
+
finishTile,
|
|
370
|
+
emptySurface,
|
|
371
|
+
solidSurface,
|
|
372
|
+
surfaceFromPixels,
|
|
373
|
+
tilesInRect,
|
|
374
|
+
readRegion,
|
|
375
|
+
readPixel,
|
|
376
|
+
contentBounds,
|
|
377
|
+
SurfaceDraft,
|
|
378
|
+
writeRegion,
|
|
379
|
+
fillRect,
|
|
380
|
+
translateSurface,
|
|
381
|
+
surfaceBytes,
|
|
382
|
+
collectTiles,
|
|
383
|
+
surfacesEqual
|
|
384
|
+
};
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkQAUIZPYIcjs = require('./chunk-QAUIZPYI.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -37,7 +37,7 @@ var lerpP = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
|
|
37
37
|
var toP = (v) => [v.x, v.y];
|
|
38
38
|
var mapP = (m, p) => [m[0] * p[0] + m[2] * p[1] + m[4], m[1] * p[0] + m[3] * p[1] + m[5]];
|
|
39
39
|
var curvesOf = (c) => Math.max(0, (c.pts.length - 1) / 3) | 0;
|
|
40
|
-
function subpathToMorphContour(sp, m =
|
|
40
|
+
function subpathToMorphContour(sp, m = _chunkQAUIZPYIcjs.IDENTITY_MATRIX) {
|
|
41
41
|
const n = sp.anchors.length;
|
|
42
42
|
if (!n) return null;
|
|
43
43
|
const first = mapP(m, toP(sp.anchors[0]));
|
|
@@ -67,8 +67,8 @@ function isStraight(p0, p1, p2, p3) {
|
|
|
67
67
|
const u2 = along(p2);
|
|
68
68
|
return off(p1) < tol && off(p2) < tol && u1 >= -1e-9 && u1 <= 1 + 1e-9 && u2 >= -1e-9 && u2 <= 1 + 1e-9;
|
|
69
69
|
}
|
|
70
|
-
function morphContourToSubpath(c, m =
|
|
71
|
-
const pts =
|
|
70
|
+
function morphContourToSubpath(c, m = _chunkQAUIZPYIcjs.IDENTITY_MATRIX, closed = c.closed) {
|
|
71
|
+
const pts = _chunkQAUIZPYIcjs.isIdentityMatrix.call(void 0, m) ? c.pts : c.pts.map((p) => mapP(m, p));
|
|
72
72
|
const curves = curvesOf(c);
|
|
73
73
|
const dropLast = closed && c.closed && curves > 0;
|
|
74
74
|
const count = dropLast ? curves : curves + 1;
|
|
@@ -84,7 +84,7 @@ function morphContourToSubpath(c, m = _chunkBRKVNXDZcjs.IDENTITY_MATRIX, closed
|
|
|
84
84
|
anchors[(k + 1) % count].in = { x: p2[0], y: p2[1] };
|
|
85
85
|
}
|
|
86
86
|
for (const a of anchors) {
|
|
87
|
-
const type =
|
|
87
|
+
const type = _chunkQAUIZPYIcjs.inferAnchorType.call(void 0, a);
|
|
88
88
|
if (type !== "corner") a.type = type;
|
|
89
89
|
}
|
|
90
90
|
const isClosed = closed && curves > 0;
|
|
@@ -267,7 +267,7 @@ function bestStart(fixed, free, useShapeContext) {
|
|
|
267
267
|
return best;
|
|
268
268
|
}
|
|
269
269
|
function placeIn(c, from, to) {
|
|
270
|
-
const b =
|
|
270
|
+
const b = _chunkQAUIZPYIcjs.unionBounds.call(void 0, [boundsOfPoints(c.pts)]);
|
|
271
271
|
const p = b ? [b.x + b.width / 2, b.y + b.height / 2] : c.pts[0];
|
|
272
272
|
if (!from || !to) return p;
|
|
273
273
|
const fx = from.width > 0 ? (p[0] - from.x) / from.width : 0.5;
|
|
@@ -456,7 +456,7 @@ function interpolateVectorColor(a, b, t) {
|
|
|
456
456
|
}
|
|
457
457
|
function resampleGradientStops(g, offsets) {
|
|
458
458
|
return offsets.map((offset) => {
|
|
459
|
-
const s =
|
|
459
|
+
const s = _chunkQAUIZPYIcjs.sampleVectorGradient.call(void 0, g, offset);
|
|
460
460
|
return s.opacity < 1 ? { offset, color: s.color, opacity: Math.round(s.opacity * 1e4) / 1e4 } : { offset, color: s.color };
|
|
461
461
|
});
|
|
462
462
|
}
|
|
@@ -467,11 +467,11 @@ function lerpAngle(a, b, t) {
|
|
|
467
467
|
var lerpPoint = (a, b, t) => ({ x: lerpN(a.x, b.x, t), y: lerpN(a.y, b.y, t) });
|
|
468
468
|
var sameColourModel = (a, b) => (_nullishCoalesce(a.interpolation, () => ( "srgb"))) === (_nullishCoalesce(b.interpolation, () => ( "srgb"))) && (_nullishCoalesce(a.smoothness, () => ( 0))) === (_nullishCoalesce(b.smoothness, () => ( 0)));
|
|
469
469
|
function lerpStops(a, b, t) {
|
|
470
|
-
let stopsA =
|
|
471
|
-
let stopsB =
|
|
470
|
+
let stopsA = _chunkQAUIZPYIcjs.sortedVectorGradientStops.call(void 0, a);
|
|
471
|
+
let stopsB = _chunkQAUIZPYIcjs.sortedVectorGradientStops.call(void 0, b);
|
|
472
472
|
const resampled = stopsA.length !== stopsB.length || !sameColourModel(a, b);
|
|
473
473
|
if (resampled) {
|
|
474
|
-
const offs = [...
|
|
474
|
+
const offs = [..._chunkQAUIZPYIcjs.expandVectorGradientStops.call(void 0, a), ..._chunkQAUIZPYIcjs.expandVectorGradientStops.call(void 0, b), ...stopsA, ...stopsB].map((s) => s.offset).filter(Number.isFinite).sort((x, y) => x - y);
|
|
475
475
|
const common = offs.filter((o, i) => i === 0 || o - offs[i - 1] > 1e-4);
|
|
476
476
|
stopsA = resampleGradientStops(a, common);
|
|
477
477
|
stopsB = resampleGradientStops(b, common);
|
|
@@ -498,8 +498,8 @@ function lerpGradient(a, b, t) {
|
|
|
498
498
|
}
|
|
499
499
|
if (near.spread && near.spread !== "pad") out.spread = near.spread;
|
|
500
500
|
if (near.strokeMode && near.strokeMode !== "within") out.strokeMode = near.strokeMode;
|
|
501
|
-
const ea =
|
|
502
|
-
const eb =
|
|
501
|
+
const ea = _chunkQAUIZPYIcjs.hasExplicitGradientGeometry.call(void 0, a);
|
|
502
|
+
const eb = _chunkQAUIZPYIcjs.hasExplicitGradientGeometry.call(void 0, b);
|
|
503
503
|
if (!ea && !eb) {
|
|
504
504
|
if (a.angle !== void 0 || b.angle !== void 0 || a.type === "linear" || a.type === "reflected") {
|
|
505
505
|
const fallback = a.type === "linear" || a.type === "reflected" ? 180 : 90;
|
|
@@ -512,10 +512,10 @@ function lerpGradient(a, b, t) {
|
|
|
512
512
|
}
|
|
513
513
|
return out;
|
|
514
514
|
}
|
|
515
|
-
const pa =
|
|
516
|
-
const pb =
|
|
515
|
+
const pa = _chunkQAUIZPYIcjs.vectorGradientPoints.call(void 0, a);
|
|
516
|
+
const pb = _chunkQAUIZPYIcjs.vectorGradientPoints.call(void 0, b);
|
|
517
517
|
if (pa.units !== pb.units) {
|
|
518
|
-
const src =
|
|
518
|
+
const src = _chunkQAUIZPYIcjs.explicitVectorGradient.call(void 0, near);
|
|
519
519
|
return { ...src, stops: out.stops, ...out.interpolation ? { interpolation: out.interpolation } : {}, ...out.smoothness ? { smoothness: out.smoothness } : {} };
|
|
520
520
|
}
|
|
521
521
|
out.start = lerpPoint(pa.start, pb.start, t);
|
|
@@ -535,14 +535,14 @@ function solidLike(color, like) {
|
|
|
535
535
|
function interpolateVectorPaint(a, b, t) {
|
|
536
536
|
if (t <= 0) return a;
|
|
537
537
|
if (t >= 1) return b;
|
|
538
|
-
const pa =
|
|
539
|
-
const pb =
|
|
538
|
+
const pa = _chunkQAUIZPYIcjs.hasPaint.call(void 0, a);
|
|
539
|
+
const pb = _chunkQAUIZPYIcjs.hasPaint.call(void 0, b);
|
|
540
540
|
if (!pa && !pb) return t < 0.5 ? a : b;
|
|
541
541
|
if (typeof a === "string" && pa && typeof b === "string" && pb) return interpolateVectorColor(a, b, t);
|
|
542
542
|
if (!pa && typeof b === "string") return interpolateVectorColor("transparent", b, t);
|
|
543
543
|
if (!pb && typeof a === "string") return interpolateVectorColor(a, "transparent", t);
|
|
544
|
-
const ga = pa &&
|
|
545
|
-
const gb = pb &&
|
|
544
|
+
const ga = pa && _chunkQAUIZPYIcjs.isVectorGradient.call(void 0, a) ? a : null;
|
|
545
|
+
const gb = pb && _chunkQAUIZPYIcjs.isVectorGradient.call(void 0, b) ? b : null;
|
|
546
546
|
if (ga && gb) return _nullishCoalesce(lerpGradient(ga, gb, t), () => ( (t < 0.5 ? a : b)));
|
|
547
547
|
if (gb) return _nullishCoalesce(lerpGradient(solidLike(pa ? a : null, gb), gb, t), () => ( b));
|
|
548
548
|
if (ga) return _nullishCoalesce(lerpGradient(ga, solidLike(pb ? b : null, ga), t), () => ( a));
|
|
@@ -553,8 +553,8 @@ function interpolateWidthProfiles(a, b, t) {
|
|
|
553
553
|
const at = [..._nullishCoalesce(a, () => ( [])), ..._nullishCoalesce(b, () => ( [])), { t: 0 }, { t: 1 }].map((p) => p.t).sort((x, y) => x - y);
|
|
554
554
|
const ts = at.filter((v, i) => i === 0 || v - at[i - 1] > 1e-6);
|
|
555
555
|
return ts.map((pos) => {
|
|
556
|
-
const x =
|
|
557
|
-
const y =
|
|
556
|
+
const x = _chunkQAUIZPYIcjs.widthProfileAt.call(void 0, a, pos);
|
|
557
|
+
const y = _chunkQAUIZPYIcjs.widthProfileAt.call(void 0, b, pos);
|
|
558
558
|
return { t: pos, left: lerpN(x.left, y.left, t), right: lerpN(x.right, y.right, t) };
|
|
559
559
|
});
|
|
560
560
|
}
|
|
@@ -597,7 +597,7 @@ function reversedStyle(s) {
|
|
|
597
597
|
out.endArrow = s.startArrow;
|
|
598
598
|
out.startArrowScale = s.endArrowScale;
|
|
599
599
|
out.endArrowScale = s.startArrowScale;
|
|
600
|
-
if (_optionalChain([s, 'access', _6 => _6.strokeWidthProfile, 'optionalAccess', _7 => _7.length])) out.strokeWidthProfile =
|
|
600
|
+
if (_optionalChain([s, 'access', _6 => _6.strokeWidthProfile, 'optionalAccess', _7 => _7.length])) out.strokeWidthProfile = _chunkQAUIZPYIcjs.reverseWidthProfile.call(void 0, s.strokeWidthProfile);
|
|
601
601
|
for (const k of ["startArrow", "endArrow", "startArrowScale", "endArrowScale"]) if (out[k] === void 0) delete out[k];
|
|
602
602
|
return out;
|
|
603
603
|
}
|
|
@@ -623,19 +623,19 @@ function styleOf(n) {
|
|
|
623
623
|
return out;
|
|
624
624
|
}
|
|
625
625
|
function contoursOf(node, m) {
|
|
626
|
-
return
|
|
626
|
+
return _chunkQAUIZPYIcjs.expandVectorCorners.call(void 0, node.subpaths).map((sp) => subpathToMorphContour(sp, m)).filter((c) => !!c);
|
|
627
627
|
}
|
|
628
|
-
function preparePathMorph(a, b, options, ma =
|
|
628
|
+
function preparePathMorph(a, b, options, ma = _chunkQAUIZPYIcjs.nodeMatrix.call(void 0, a), mb = _chunkQAUIZPYIcjs.nodeMatrix.call(void 0, b)) {
|
|
629
629
|
const corr = correspondMorphContours(contoursOf(a, ma), contoursOf(b, mb), options);
|
|
630
630
|
const sim = procrustes(corr.a, corr.b);
|
|
631
631
|
const styleA = styleOf(a);
|
|
632
632
|
const styleB = corr.reversed ? reversedStyle(styleOf(b)) : styleOf(b);
|
|
633
|
-
const rigid = !
|
|
633
|
+
const rigid = !_chunkQAUIZPYIcjs.isIdentityMatrix.call(void 0, ma) || !_chunkQAUIZPYIcjs.isIdentityMatrix.call(void 0, mb);
|
|
634
634
|
const id = _nullishCoalesce(options.id, () => ( a.id));
|
|
635
635
|
return (t) => {
|
|
636
636
|
const contours = interpolateMorphContours(corr.a, corr.b, t, { linear: options.linear, rigidity: options.rigidity, similarity: sim });
|
|
637
|
-
const m = rigid ? interpolateRigidMatrix(ma, mb, t) :
|
|
638
|
-
const back = rigid ?
|
|
637
|
+
const m = rigid ? interpolateRigidMatrix(ma, mb, t) : _chunkQAUIZPYIcjs.IDENTITY_MATRIX;
|
|
638
|
+
const back = rigid ? _chunkQAUIZPYIcjs.invertMatrix.call(void 0, m) : _chunkQAUIZPYIcjs.IDENTITY_MATRIX;
|
|
639
639
|
const subpaths = contours.map((c, k) => {
|
|
640
640
|
const closed = t <= 0 ? corr.a[k].closed : t >= 1 ? corr.b[k].closed : corr.a[k].closed && corr.b[k].closed;
|
|
641
641
|
return morphContourToSubpath({ closed: corr.a[k].closed && corr.b[k].closed, pts: c.pts }, back, closed);
|
|
@@ -643,14 +643,14 @@ function preparePathMorph(a, b, options, ma = _chunkBRKVNXDZcjs.nodeMatrix.call(
|
|
|
643
643
|
const node = { id, type: "path", subpaths, ...interpolateVectorStyle(styleA, styleB, t) };
|
|
644
644
|
const opacity = lerpN(_nullishCoalesce(a.opacity, () => ( 1)), _nullishCoalesce(b.opacity, () => ( 1)), t);
|
|
645
645
|
if (opacity < 1) node.opacity = opacity;
|
|
646
|
-
if (rigid && !
|
|
646
|
+
if (rigid && !_chunkQAUIZPYIcjs.isIdentityMatrix.call(void 0, m)) node.transform = m;
|
|
647
647
|
return node;
|
|
648
648
|
};
|
|
649
649
|
}
|
|
650
|
-
function flattenPaths(node, parent =
|
|
651
|
-
const m =
|
|
650
|
+
function flattenPaths(node, parent = _chunkQAUIZPYIcjs.IDENTITY_MATRIX) {
|
|
651
|
+
const m = _chunkQAUIZPYIcjs.multiplyMatrices.call(void 0, _chunkQAUIZPYIcjs.nodeMatrix.call(void 0, node), parent);
|
|
652
652
|
if (node.type === "path") return [{ path: node, m, opacity: 1 }];
|
|
653
|
-
if (node.type === "text" || node.type === "instance") return flattenPaths(
|
|
653
|
+
if (node.type === "text" || node.type === "instance") return flattenPaths(_chunkQAUIZPYIcjs.expandVectorAppearance.call(void 0, node), parent);
|
|
654
654
|
const o = _nullishCoalesce(node.opacity, () => ( 1));
|
|
655
655
|
return node.children.filter((c) => c.visible !== false).flatMap((c) => flattenPaths(c, m)).map((e) => ({ ...e, opacity: e.opacity * o }));
|
|
656
656
|
}
|
|
@@ -672,8 +672,8 @@ function createVectorMorph(a, b, options = {}) {
|
|
|
672
672
|
}
|
|
673
673
|
const pa = flattenPaths(a);
|
|
674
674
|
const pb = flattenPaths(b);
|
|
675
|
-
const ba =
|
|
676
|
-
const bb =
|
|
675
|
+
const ba = _chunkQAUIZPYIcjs.unionBounds.call(void 0, pa.map((e) => placedBounds(e.path, e.m)));
|
|
676
|
+
const bb = _chunkQAUIZPYIcjs.unionBounds.call(void 0, pb.map((e) => placedBounds(e.path, e.m)));
|
|
677
677
|
const id = _nullishCoalesce(options.id, () => ( a.id));
|
|
678
678
|
const parts = [];
|
|
679
679
|
const opacities = [];
|
|
@@ -685,10 +685,10 @@ function createVectorMorph(a, b, options = {}) {
|
|
|
685
685
|
parts.push(preparePathMorph(x.path, y.path, sub, x.m, y.m));
|
|
686
686
|
opacities.push([x.opacity, y.opacity]);
|
|
687
687
|
} else if (x) {
|
|
688
|
-
parts.push(preparePathMorph(x.path, collapsedPath(x.path, x.m, ba, bb), sub, x.m,
|
|
688
|
+
parts.push(preparePathMorph(x.path, collapsedPath(x.path, x.m, ba, bb), sub, x.m, _chunkQAUIZPYIcjs.IDENTITY_MATRIX));
|
|
689
689
|
opacities.push([x.opacity, x.opacity]);
|
|
690
690
|
} else if (y) {
|
|
691
|
-
parts.push(preparePathMorph(collapsedPath(y.path, y.m, bb, ba), y.path, sub,
|
|
691
|
+
parts.push(preparePathMorph(collapsedPath(y.path, y.m, bb, ba), y.path, sub, _chunkQAUIZPYIcjs.IDENTITY_MATRIX, y.m));
|
|
692
692
|
opacities.push([y.opacity, y.opacity]);
|
|
693
693
|
}
|
|
694
694
|
}
|