@pixerate/editor 0.116.0 → 0.117.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.
Files changed (61) hide show
  1. package/dist/{chunk-ZYZGEILO.cjs → chunk-2J3LS7JZ.cjs} +203 -203
  2. package/dist/{chunk-ZYZGEILO.cjs.map → chunk-2J3LS7JZ.cjs.map} +1 -1
  3. package/dist/{chunk-TFOPHZ3U.cjs → chunk-7ISPWEJA.cjs} +302 -5
  4. package/dist/chunk-7ISPWEJA.cjs.map +1 -0
  5. package/dist/{chunk-2UT4GXYA.cjs → chunk-BYAWOAST.cjs} +109 -41
  6. package/dist/chunk-BYAWOAST.cjs.map +1 -0
  7. package/dist/{chunk-PAOWHJ5O.cjs → chunk-EBSYZRSW.cjs} +217 -400
  8. package/dist/chunk-EBSYZRSW.cjs.map +1 -0
  9. package/dist/{chunk-XK5LZKBD.js → chunk-HKDTM6VC.js} +298 -1
  10. package/dist/chunk-HKDTM6VC.js.map +1 -0
  11. package/dist/{chunk-D53VQGEJ.js → chunk-IVSNUXW7.js} +79 -2
  12. package/dist/chunk-IVSNUXW7.js.map +1 -0
  13. package/dist/{chunk-ARQ7PQ6Q.js → chunk-JHXMNOMF.js} +71 -3
  14. package/dist/chunk-JHXMNOMF.js.map +1 -0
  15. package/dist/{chunk-HOCPSFGA.cjs → chunk-L2T6EJ5S.cjs} +154 -77
  16. package/dist/chunk-L2T6EJ5S.cjs.map +1 -0
  17. package/dist/{chunk-SEBYNBHW.js → chunk-R2JE6SA7.js} +9 -9
  18. package/dist/{chunk-D53KSJUV.js → chunk-VD2UDVF7.js} +100 -283
  19. package/dist/chunk-VD2UDVF7.js.map +1 -0
  20. package/dist/{export-BXxSGBCq.d.cts → export-DMOuzgZZ.d.cts} +8 -3
  21. package/dist/{export-Dm44YUvS.d.ts → export-Dul1SbPv.d.ts} +8 -3
  22. package/dist/{flow-COCB42TP.d.cts → flow-4-OC-UkQ.d.cts} +22 -1
  23. package/dist/{flow-BMtHAmg4.d.ts → flow-Cb7lkPm8.d.ts} +22 -1
  24. package/dist/image-editor/index.cjs +1112 -1024
  25. package/dist/image-editor/index.cjs.map +1 -1
  26. package/dist/image-editor/index.d.cts +6 -6
  27. package/dist/image-editor/index.d.ts +6 -6
  28. package/dist/image-editor/index.js +124 -36
  29. package/dist/image-editor/index.js.map +1 -1
  30. package/dist/paint/index.cjs +8 -4
  31. package/dist/paint/index.cjs.map +1 -1
  32. package/dist/paint/index.d.cts +2 -2
  33. package/dist/paint/index.d.ts +2 -2
  34. package/dist/paint/index.js +7 -3
  35. package/dist/paint-editor/index.cjs +242 -242
  36. package/dist/paint-editor/index.d.cts +4 -4
  37. package/dist/paint-editor/index.d.ts +4 -4
  38. package/dist/paint-editor/index.js +4 -4
  39. package/dist/raster/index.cjs +6 -4
  40. package/dist/raster/index.cjs.map +1 -1
  41. package/dist/raster/index.d.cts +2 -2
  42. package/dist/raster/index.d.ts +2 -2
  43. package/dist/raster/index.js +27 -25
  44. package/dist/{render-CrmHOgpo.d.ts → render-B05K68_h.d.ts} +9 -1
  45. package/dist/{render-B1K_OoLy.d.cts → render-DnAbIKcs.d.cts} +9 -1
  46. package/dist/vector/index.cjs +11272 -10183
  47. package/dist/vector/index.cjs.map +1 -1
  48. package/dist/vector/index.d.cts +135 -1
  49. package/dist/vector/index.d.ts +135 -1
  50. package/dist/vector/index.js +11179 -10090
  51. package/dist/vector/index.js.map +1 -1
  52. package/package.json +1 -1
  53. package/dist/chunk-2UT4GXYA.cjs.map +0 -1
  54. package/dist/chunk-ARQ7PQ6Q.js.map +0 -1
  55. package/dist/chunk-D53KSJUV.js.map +0 -1
  56. package/dist/chunk-D53VQGEJ.js.map +0 -1
  57. package/dist/chunk-HOCPSFGA.cjs.map +0 -1
  58. package/dist/chunk-PAOWHJ5O.cjs.map +0 -1
  59. package/dist/chunk-TFOPHZ3U.cjs.map +0 -1
  60. package/dist/chunk-XK5LZKBD.js.map +0 -1
  61. /package/dist/{chunk-SEBYNBHW.js.map → chunk-R2JE6SA7.js.map} +0 -0
@@ -28,17 +28,13 @@ import {
28
28
  newEffectId,
29
29
  normalizeLayerEffects,
30
30
  parseEffectColor,
31
- readDeepRegion,
32
31
  reduceSurface,
33
32
  scaleLayerEffect,
34
- surfaceDepth,
35
- surfaceFromDeepPixels,
36
33
  transformSurface,
37
34
  validateEffectGradient,
38
35
  validateLayerEffects,
39
- warpSurface,
40
- writeDeepRegion
41
- } from "./chunk-D53KSJUV.js";
36
+ warpSurface
37
+ } from "./chunk-VD2UDVF7.js";
42
38
  import {
43
39
  affineFromHomography,
44
40
  applyHomography,
@@ -65,13 +61,17 @@ import {
65
61
  isBlendMode,
66
62
  mixPigmentRgb,
67
63
  normalizeBlendMode,
64
+ readDeepRegion,
68
65
  readRegion,
69
66
  setLum,
67
+ surfaceDepth,
68
+ surfaceFromDeepPixels,
70
69
  surfaceFromPixels,
71
70
  tileKey,
72
71
  tilesInRect,
73
- translateSurface
74
- } from "./chunk-XK5LZKBD.js";
72
+ translateSurface,
73
+ writeDeepRegion
74
+ } from "./chunk-HKDTM6VC.js";
75
75
  import {
76
76
  Transform,
77
77
  builtinProfile,
@@ -11735,4 +11735,4 @@ export {
11735
11735
  smartContentsFile,
11736
11736
  exportPsd
11737
11737
  };
11738
- //# sourceMappingURL=chunk-SEBYNBHW.js.map
11738
+ //# sourceMappingURL=chunk-R2JE6SA7.js.map
@@ -14,263 +14,27 @@ import {
14
14
  blendChannel,
15
15
  blendRgb,
16
16
  contentBounds,
17
+ deepTile,
17
18
  emptySurface,
18
19
  finishTile,
19
20
  isBlendMode,
20
21
  isSeparableBlendMode,
21
22
  mixPigment8,
22
23
  mixPigmentRgb,
24
+ readDeepRegion,
23
25
  readRegion,
26
+ srgbDecode,
27
+ srgbEncode,
28
+ surfaceDepth,
24
29
  surfaceFromPixels,
25
30
  tileKey,
31
+ tileSamples,
26
32
  tilesInRect,
33
+ to32From8,
27
34
  translateSurface,
35
+ writeDeepRegion,
28
36
  writeRegion
29
- } from "./chunk-XK5LZKBD.js";
30
-
31
- // src/raster/deep.ts
32
- var BIT_DEPTHS = [8, 16, 32];
33
- var isBitDepth = (v) => v === 8 || v === 16 || v === 32;
34
- var TILE_PIXELS = TILE * TILE;
35
- function srgbDecode(v) {
36
- return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
37
- }
38
- function srgbEncode(v) {
39
- if (!(v > 0)) return 0;
40
- return v <= 31308e-7 ? v * 12.92 : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
41
- }
42
- var LIN8 = null;
43
- var LIN16 = null;
44
- function lin8() {
45
- if (!LIN8) {
46
- LIN8 = new Float32Array(256);
47
- for (let i = 0; i < 256; i++) LIN8[i] = srgbDecode(i / 255);
48
- }
49
- return LIN8;
50
- }
51
- function lin16() {
52
- if (!LIN16) {
53
- LIN16 = new Float32Array(65536);
54
- for (let i = 0; i < 65536; i++) LIN16[i] = srgbDecode(i / 65535);
55
- }
56
- return LIN16;
57
- }
58
- function encode16(v) {
59
- if (!(v > 0)) return 0;
60
- if (v >= 1) return 65535;
61
- return Math.round(srgbEncode(v) * 65535);
62
- }
63
- var ENC8 = null;
64
- function encode8(v) {
65
- if (!(v > 0)) return 0;
66
- if (v >= 1) return 255;
67
- if (!ENC8) {
68
- ENC8 = new Uint8Array(65536);
69
- for (let i = 0; i < 65536; i++) ENC8[i] = Math.round(srgbEncode(i / 65535) * 255);
70
- }
71
- return ENC8[Math.round(v * 65535)];
72
- }
73
- function to16From8(data, out = new Uint16Array(data.length)) {
74
- for (let i = 0; i < data.length; i++) out[i] = data[i] * 257;
75
- return out;
76
- }
77
- function to32From8(data, channels, out = new Float32Array(data.length)) {
78
- if (channels === 1) {
79
- for (let i = 0; i < data.length; i++) out[i] = data[i] / 255;
80
- return out;
81
- }
82
- const t = lin8();
83
- for (let i = 0; i < data.length; i += 4) {
84
- out[i] = t[data[i]];
85
- out[i + 1] = t[data[i + 1]];
86
- out[i + 2] = t[data[i + 2]];
87
- out[i + 3] = data[i + 3] / 255;
88
- }
89
- return out;
90
- }
91
- function to32From16(data, channels, out = new Float32Array(data.length)) {
92
- if (channels === 1) {
93
- for (let i = 0; i < data.length; i++) out[i] = data[i] / 65535;
94
- return out;
95
- }
96
- const t = lin16();
97
- for (let i = 0; i < data.length; i += 4) {
98
- out[i] = t[data[i]];
99
- out[i + 1] = t[data[i + 1]];
100
- out[i + 2] = t[data[i + 2]];
101
- out[i + 3] = data[i + 3] / 65535;
102
- }
103
- return out;
104
- }
105
- function to16From32(data, channels, out = new Uint16Array(data.length)) {
106
- const unit = (v) => v > 0 ? v < 1 ? Math.round(v * 65535) : 65535 : 0;
107
- if (channels === 1) {
108
- for (let i = 0; i < data.length; i++) out[i] = unit(data[i]);
109
- return out;
110
- }
111
- for (let i = 0; i < data.length; i += 4) {
112
- out[i] = encode16(data[i]);
113
- out[i + 1] = encode16(data[i + 1]);
114
- out[i + 2] = encode16(data[i + 2]);
115
- out[i + 3] = unit(data[i + 3]);
116
- }
117
- return out;
118
- }
119
- function to8From16(data, out = new Uint8ClampedArray(data.length)) {
120
- for (let i = 0; i < data.length; i++) out[i] = Math.round(data[i] / 257);
121
- return out;
122
- }
123
- function to8From32(data, channels, out = new Uint8ClampedArray(data.length)) {
124
- if (channels === 1) {
125
- for (let i = 0; i < data.length; i++) out[i] = Math.round(data[i] * 255);
126
- return out;
127
- }
128
- for (let i = 0; i < data.length; i += 4) {
129
- out[i] = encode8(data[i]);
130
- out[i + 1] = encode8(data[i + 1]);
131
- out[i + 2] = encode8(data[i + 2]);
132
- out[i + 3] = Math.round(Math.min(1, Math.max(0, data[i + 3])) * 255);
133
- }
134
- return out;
135
- }
136
- function proxyOf(deep, channels, out) {
137
- return deep instanceof Uint16Array ? to8From16(deep, out) : to8From32(deep, channels, out);
138
- }
139
- var depthOf = (deep) => deep instanceof Uint16Array ? 16 : 32;
140
- function deepTile(deep, channels, defaultValue = 0) {
141
- const data = proxyOf(deep, channels);
142
- if (deep instanceof Uint16Array) {
143
- let exact = true;
144
- for (let i = 0; i < deep.length; i++) {
145
- if (deep[i] % 257 !== 0) {
146
- exact = false;
147
- break;
148
- }
149
- }
150
- if (exact) return finishTile(data, channels, defaultValue);
151
- } else if (channels === 4 && defaultValue === 0) {
152
- let empty = true;
153
- for (let i = 3; i < deep.length; i += 4) {
154
- if (deep[i] !== 0) {
155
- empty = false;
156
- break;
157
- }
158
- }
159
- if (empty) return null;
160
- }
161
- return { data, uniform: null, deep };
162
- }
163
- function tileSamples16(tile, channels, defaultValue = 0) {
164
- const deep = tile?.deep;
165
- if (deep instanceof Uint16Array) return deep;
166
- if (deep instanceof Float32Array) return to16From32(deep, channels);
167
- if (tile) return to16From8(tile.data);
168
- return new Uint16Array(TILE_PIXELS * channels).fill(defaultValue * 257);
169
- }
170
- function tileSamples32(tile, channels, defaultValue = 0) {
171
- const deep = tile?.deep;
172
- if (deep instanceof Float32Array) return deep;
173
- if (deep instanceof Uint16Array) return to32From16(deep, channels);
174
- if (tile) return to32From8(tile.data, channels);
175
- const out = new Float32Array(TILE_PIXELS * channels);
176
- if (defaultValue) {
177
- if (channels === 1) out.fill(defaultValue / 255);
178
- else to32From8(new Uint8ClampedArray(TILE_PIXELS * 4).fill(defaultValue), 4, out);
179
- }
180
- return out;
181
- }
182
- function tileSamples(tile, channels, depth, defaultValue = 0) {
183
- return depth === 16 ? tileSamples16(tile, channels, defaultValue) : tileSamples32(tile, channels, defaultValue);
184
- }
185
- function surfaceDepth(surface) {
186
- let d = 8;
187
- for (const t of surface.tiles.values()) {
188
- if (t.deep instanceof Float32Array) return 32;
189
- if (t.deep) d = 16;
190
- }
191
- return d;
192
- }
193
- function readDeepRegion(surface, rect, depth) {
194
- const ch = surface.channels;
195
- const w = rect.width;
196
- const h = rect.height;
197
- const out = depth === 16 ? new Uint16Array(w * h * ch) : new Float32Array(w * h * ch);
198
- const fill2 = tileSamples(void 0, ch, depth, surface.defaultValue);
199
- if (surface.defaultValue) for (let i = 0; i < out.length; i += ch) for (let c = 0; c < ch; c++) out[i + c] = fill2[c];
200
- for (const { tx, ty } of tilesInRect(rect)) {
201
- const tile = surface.tiles.get(tileKey(tx, ty));
202
- if (!tile) continue;
203
- const src = tileSamples(tile, ch, depth, surface.defaultValue);
204
- const ox = tx * TILE;
205
- const oy = ty * TILE;
206
- const x0 = Math.max(rect.x, ox);
207
- const y0 = Math.max(rect.y, oy);
208
- const x1 = Math.min(rect.x + w, ox + TILE);
209
- const y1 = Math.min(rect.y + h, oy + TILE);
210
- const span = (x1 - x0) * ch;
211
- for (let yy = y0; yy < y1; yy++) {
212
- const s = ((yy - oy) * TILE + (x0 - ox)) * ch;
213
- const d = ((yy - rect.y) * w + (x0 - rect.x)) * ch;
214
- out.set(src.subarray(s, s + span), d);
215
- }
216
- }
217
- return out;
218
- }
219
- function writeDeepRegion(surface, rect, samples) {
220
- const ch = surface.channels;
221
- const w = rect.width;
222
- const h = rect.height;
223
- if (w <= 0 || h <= 0) return surface;
224
- if (samples.length < w * h * ch) throw new Error(`writeDeepRegion: expected ${w * h * ch} samples, got ${samples.length}`);
225
- const depth = depthOf(samples);
226
- const tiles = new Map(surface.tiles);
227
- for (const { tx, ty } of tilesInRect(rect)) {
228
- const key = tileKey(tx, ty);
229
- const ox = tx * TILE;
230
- const oy = ty * TILE;
231
- const x0 = Math.max(rect.x, ox);
232
- const y0 = Math.max(rect.y, oy);
233
- const x1 = Math.min(rect.x + w, ox + TILE);
234
- const y1 = Math.min(rect.y + h, oy + TILE);
235
- const full = x0 === ox && y0 === oy && x1 === ox + TILE && y1 === oy + TILE;
236
- const base = full ? null : tileSamples(surface.tiles.get(key), ch, depth, surface.defaultValue);
237
- const t = base ? base.slice() : depth === 16 ? new Uint16Array(TILE_PIXELS * ch) : new Float32Array(TILE_PIXELS * ch);
238
- const span = (x1 - x0) * ch;
239
- for (let yy = y0; yy < y1; yy++) {
240
- const s = ((yy - rect.y) * w + (x0 - rect.x)) * ch;
241
- const d = ((yy - oy) * TILE + (x0 - ox)) * ch;
242
- t.set(samples.subarray(s, s + span), d);
243
- }
244
- const tile = deepTile(t, ch, surface.defaultValue);
245
- if (tile) tiles.set(key, tile);
246
- else tiles.delete(key);
247
- }
248
- return new TiledSurface(ch, tiles, surface.defaultValue);
249
- }
250
- function surfaceFromDeepPixels(pixels, channels = 4, x = 0, y = 0, defaultValue = 0) {
251
- return writeDeepRegion(emptySurface(channels, defaultValue), { x, y, width: pixels.width, height: pixels.height }, pixels.data);
252
- }
253
- function convertSurfaceDepth(surface, depth) {
254
- let changed = false;
255
- const tiles = new Map(surface.tiles);
256
- const ch = surface.channels;
257
- for (const [key, tile] of surface.tiles) {
258
- const deep = tile.deep;
259
- if (!deep || depthOf(deep) === depth) continue;
260
- changed = true;
261
- let next;
262
- if (depth === 8) next = finishTile(tile.data, ch, surface.defaultValue);
263
- else next = deepTile(depth === 16 ? to16From32(deep, ch) : to32From16(deep, ch), ch, surface.defaultValue);
264
- if (next) tiles.set(key, next);
265
- else tiles.delete(key);
266
- }
267
- return changed ? new TiledSurface(ch, tiles, surface.defaultValue) : surface;
268
- }
269
- function deepBytes(surface) {
270
- let n = 0;
271
- for (const t of surface.tiles.values()) if (t.deep) n += t.deep.byteLength;
272
- return n;
273
- }
37
+ } from "./chunk-HKDTM6VC.js";
274
38
 
275
39
  // src/raster/effects/model.ts
276
40
  var DEFAULT_GLOBAL_LIGHT = { angle: 120, altitude: 30 };
@@ -2580,8 +2344,8 @@ function renderLayerEffects(effects, layer, backdrop, canvas, ctx) {
2580
2344
  }
2581
2345
 
2582
2346
  // src/raster/compositor.ts
2583
- var TILE_PIXELS2 = TILE * TILE;
2584
- var TILE_BYTES = TILE_PIXELS2 * 4;
2347
+ var TILE_PIXELS = TILE * TILE;
2348
+ var TILE_BYTES = TILE_PIXELS * 4;
2585
2349
  function sameSig(a, b) {
2586
2350
  if (!a || a.key !== b.key || a.refs.length !== b.refs.length) return false;
2587
2351
  for (let i = 0; i < a.refs.length; i++) if (a.refs[i] !== b.refs[i]) return false;
@@ -3601,13 +3365,13 @@ function hasTilesIn(src, r) {
3601
3365
  for (const { tx, ty } of tilesInRect(r)) if (src.getTile(tx, ty)) return true;
3602
3366
  return false;
3603
3367
  }
3604
- function readWindow(src, srcRect, rect) {
3368
+ function readWindow(src, srcRect, rect, depth = null) {
3605
3369
  const n = src.channels === 4 ? 4 : 2;
3606
3370
  const data = new Float32Array(rect.width * rect.height * n);
3607
3371
  const win = { x: rect.x, y: rect.y, w: rect.width, h: rect.height, n, data };
3608
3372
  const r = intersect(rect, srcRect);
3609
3373
  if (!r) return win;
3610
- const px = readRegion(src, r);
3374
+ const px = depth ? readScaled(src, r, depth) : readRegion(src, r);
3611
3375
  for (let y = 0; y < r.height; y++) {
3612
3376
  let s = y * r.width * src.channels;
3613
3377
  let d = ((r.y - rect.y + y) * rect.width + (r.x - rect.x)) * n;
@@ -3741,7 +3505,44 @@ function store(out, o, acc, ch, def) {
3741
3505
  out[o] = acc[0] + def * (1 - inside);
3742
3506
  return true;
3743
3507
  }
3744
- function boxReduce(src, srcRect, kx, ky) {
3508
+ function resampleDepth(src, step) {
3509
+ if (src.channels !== 4 || src.defaultValue !== 0 || step !== 1) return null;
3510
+ const d = surfaceDepth(src);
3511
+ return d === 8 ? null : d;
3512
+ }
3513
+ function readScaled(src, rect, depth) {
3514
+ const d = readDeepRegion(src, rect, depth);
3515
+ const out = new Float32Array(d.length);
3516
+ const k = depth === 16 ? 1 / 257 : 255;
3517
+ for (let i = 0; i < d.length; i++) out[i] = d[i] * k;
3518
+ return out;
3519
+ }
3520
+ function fromScaled(v, depth) {
3521
+ if (depth === 16) {
3522
+ const out2 = new Uint16Array(v.length);
3523
+ for (let i = 0; i < v.length; i++) {
3524
+ const x = Math.round(v[i] * 257);
3525
+ out2[i] = x <= 0 ? 0 : x >= 65535 ? 65535 : x;
3526
+ }
3527
+ return out2;
3528
+ }
3529
+ const out = new Float32Array(v.length);
3530
+ for (let i = 0; i < v.length; i++) {
3531
+ const x = v[i] / 255;
3532
+ out[i] = (i & 3) === 3 ? x <= 0 ? 0 : x >= 1 ? 1 : x : x;
3533
+ }
3534
+ return out;
3535
+ }
3536
+ function storeScaled(out, o, acc) {
3537
+ const al = acc[3] > 1 ? 1 : acc[3];
3538
+ if (!(al > 1e-6)) return false;
3539
+ out[o] = acc[0] / al;
3540
+ out[o + 1] = acc[1] / al;
3541
+ out[o + 2] = acc[2] / al;
3542
+ out[o + 3] = al * 255;
3543
+ return true;
3544
+ }
3545
+ function boxReduce(src, srcRect, kx, ky, depth = null) {
3745
3546
  const ch = src.channels;
3746
3547
  const rx0 = Math.floor(srcRect.x / kx);
3747
3548
  const ry0 = Math.floor(srcRect.y / ky);
@@ -3755,8 +3556,8 @@ function boxReduce(src, srcRect, kx, ky) {
3755
3556
  for (let ry = ry0; ry < ry1; ry += rowsPer) {
3756
3557
  const rows = Math.min(rowsPer, ry1 - ry);
3757
3558
  const strip = { x: rx0 * kx, y: ry * ky, width: rw * kx, height: rows * ky };
3758
- const px = readRegion(src, strip);
3759
- const red = new Uint8ClampedArray(rw * rows * ch);
3559
+ const px = depth ? readScaled(src, strip, depth) : readRegion(src, strip);
3560
+ const red = depth ? new Float32Array(rw * rows * ch) : new Uint8ClampedArray(rw * rows * ch);
3760
3561
  for (let j = 0; j < rows; j++) {
3761
3562
  for (let i = 0; i < rw; i++) {
3762
3563
  if (ch === 4) {
@@ -3791,7 +3592,8 @@ function boxReduce(src, srcRect, kx, ky) {
3791
3592
  }
3792
3593
  }
3793
3594
  }
3794
- out = writeRegion(out, { x: rx0, y: ry, width: rw, height: rows }, red);
3595
+ const region = { x: rx0, y: ry, width: rw, height: rows };
3596
+ out = depth ? writeDeepRegion(out, region, fromScaled(red, depth)) : writeRegion(out, region, red);
3795
3597
  }
3796
3598
  return { surface: out, rect };
3797
3599
  }
@@ -3840,11 +3642,18 @@ function transformSurface(src, h, options = {}) {
3840
3642
  const empty = emptySurface(ch, def);
3841
3643
  const given = options.source;
3842
3644
  const step = normalizeStep(options.step);
3645
+ const depth = resampleDepth(src, step);
3843
3646
  if (isIdentityHomography(h, 1e-12) && !given && !options.clip) return src;
3844
3647
  const dx = h[2] / h[8];
3845
3648
  const dy = h[5] / h[8];
3846
3649
  if (!given && !options.clip && isIdentityHomography([h[0], h[1], 0, h[3], h[4], 0, h[6], h[7], h[8]], 1e-12) && Math.abs(dx - Math.round(dx)) < 1e-9 && Math.abs(dy - Math.round(dy)) < 1e-9) {
3847
- return translateSurface(src, Math.round(dx), Math.round(dy));
3650
+ const mx = Math.round(dx);
3651
+ const my = Math.round(dy);
3652
+ const b = src.bounds;
3653
+ if (depth && b && (mx % TILE !== 0 || my % TILE !== 0)) {
3654
+ return writeDeepRegion(emptySurface(ch, def), { ...b, x: b.x + mx, y: b.y + my }, readDeepRegion(src, b, depth));
3655
+ }
3656
+ return translateSurface(src, mx, my);
3848
3657
  }
3849
3658
  let srcRect = given ? intersect(given, given) : contentBounds(src);
3850
3659
  if (!srcRect) return empty;
@@ -3858,7 +3667,7 @@ function transformSurface(src, h, options = {}) {
3858
3667
  const kx = reduction(su);
3859
3668
  const ky = reduction(sv);
3860
3669
  if (kx > 1 || ky > 1) {
3861
- const red = boxReduce(src, srcRect, kx, ky);
3670
+ const red = boxReduce(src, srcRect, kx, ky, depth);
3862
3671
  S = red.surface;
3863
3672
  srcRect = red.rect;
3864
3673
  H = multiplyHomographies([kx, 0, 0, 0, ky, 0, 0, 0, 1], H);
@@ -3942,9 +3751,10 @@ function transformSurface(src, h, options = {}) {
3942
3751
  if (!foot) continue;
3943
3752
  const readable = intersect(foot, sr);
3944
3753
  if (!readable || !hasTilesIn(S, readable)) continue;
3945
- const win = readWindow(S, sr, foot);
3754
+ const win = readWindow(S, sr, foot, depth);
3946
3755
  const out = new Uint8ClampedArray(TILE * TILE * ch);
3947
3756
  if (def) out.fill(def);
3757
+ const deepOut = depth ? new Float32Array(TILE * TILE * 4) : null;
3948
3758
  let any = false;
3949
3759
  const ox = tx * TILE;
3950
3760
  const oy = ty * TILE;
@@ -3973,6 +3783,10 @@ function transformSurface(src, h, options = {}) {
3973
3783
  sv = widen(s[1]);
3974
3784
  }
3975
3785
  sample(win, interp, u, v, su, sv, acc);
3786
+ if (deepOut) {
3787
+ if (storeScaled(deepOut, ((y - oy) * TILE + (x - ox)) * 4, acc)) any = true;
3788
+ continue;
3789
+ }
3976
3790
  if (!store(scratch, 0, acc, ch, def)) continue;
3977
3791
  rowSet[bi] = 1;
3978
3792
  rowVals[bi] = ch === 4 ? scratchWord[0] : scratch[0];
@@ -3995,7 +3809,7 @@ function transformSurface(src, h, options = {}) {
3995
3809
  }
3996
3810
  }
3997
3811
  if (!any) continue;
3998
- const tile = finishTile(out, ch, def);
3812
+ const tile = deepOut ? deepTile(fromScaled(deepOut, depth), 4, def) : finishTile(out, ch, def);
3999
3813
  if (tile) tiles.set(tileKey(tx, ty), tile);
4000
3814
  }
4001
3815
  return assemble(src, tiles);
@@ -4011,6 +3825,7 @@ function warpSurface(src, f, options = {}) {
4011
3825
  const sr = options.source ? intersect(options.source, options.source) : contentBounds(src);
4012
3826
  if (!sr) return empty;
4013
3827
  const step = normalizeStep(options.step);
3828
+ const depth = resampleDepth(src, step);
4014
3829
  const nx = Math.min(MAX_CELLS, Math.max(1, Math.ceil(sr.width / CELL)));
4015
3830
  const ny = Math.min(MAX_CELLS, Math.max(1, Math.ceil(sr.height / CELL)));
4016
3831
  const w1 = nx + 1;
@@ -4178,9 +3993,10 @@ function warpSurface(src, f, options = {}) {
4178
3993
  if (fx0 > fx1) continue;
4179
3994
  const foot = intersect({ x: Math.floor(fx0) - 3, y: Math.floor(fy0) - 3, width: Math.ceil(fx1) - Math.floor(fx0) + 6, height: Math.ceil(fy1) - Math.floor(fy0) + 6 }, sr);
4180
3995
  if (!foot || !hasTilesIn(src, foot)) continue;
4181
- const win = readWindow(src, sr, foot);
3996
+ const win = readWindow(src, sr, foot, depth);
4182
3997
  const out = new Uint8ClampedArray(TILE * TILE * ch);
4183
3998
  if (def) out.fill(def);
3999
+ const deepOut = depth ? new Float32Array(TILE * TILE * 4) : null;
4184
4000
  let any = false;
4185
4001
  const ox = ttx * TILE;
4186
4002
  const oy = tty * TILE;
@@ -4214,7 +4030,8 @@ function warpSurface(src, f, options = {}) {
4214
4030
  pointAt(o, acc);
4215
4031
  const x = t.x + o % tw;
4216
4032
  const y = t.y + Math.floor(o / tw);
4217
- if (store(out, ((y - oy) * TILE + (x - ox)) * ch, acc, ch, def)) any = true;
4033
+ const o4 = ((y - oy) * TILE + (x - ox)) * ch;
4034
+ if (deepOut ? storeScaled(deepOut, o4, acc) : store(out, o4, acc, ch, def)) any = true;
4218
4035
  }
4219
4036
  } else {
4220
4037
  for (let by = 0; by < th; by += step) {
@@ -4233,7 +4050,7 @@ function warpSurface(src, f, options = {}) {
4233
4050
  }
4234
4051
  }
4235
4052
  if (!any) continue;
4236
- const tile = finishTile(out, ch, def);
4053
+ const tile = deepOut ? deepTile(fromScaled(deepOut, depth), 4, def) : finishTile(out, ch, def);
4237
4054
  if (tile) tiles.set(tileKey(ttx, tty), tile);
4238
4055
  }
4239
4056
  }
@@ -4244,12 +4061,34 @@ function compositeSurfaceOver(base, top) {
4244
4061
  if (!top.tiles.size) return base;
4245
4062
  const ch = base.channels;
4246
4063
  const tiles = new Map(base.tiles);
4064
+ const bd = ch === 4 && base.defaultValue === 0 ? Math.max(surfaceDepth(base), surfaceDepth(top)) : 8;
4065
+ const depth = bd === 8 ? null : bd;
4247
4066
  for (const [key, t] of top.tiles) {
4248
4067
  const under = base.tiles.get(key);
4249
4068
  if (!under && ch === 4) {
4250
4069
  tiles.set(key, t);
4251
4070
  continue;
4252
4071
  }
4072
+ if (depth) {
4073
+ const k = depth === 16 ? 65535 : 1;
4074
+ const d2 = tileSamples(under, 4, depth, 0).slice();
4075
+ const sd = tileSamples(t, 4, depth, 0);
4076
+ for (let i = 0; i < d2.length; i += 4) {
4077
+ const ta = Math.min(1, sd[i + 3] / k);
4078
+ if (ta <= 0) continue;
4079
+ const da = d2[i + 3] / k;
4080
+ const oa = ta + da * (1 - ta);
4081
+ for (let c = 0; c < 3; c++) {
4082
+ const v = (sd[i + c] * ta + d2[i + c] * da * (1 - ta)) / oa;
4083
+ d2[i + c] = depth === 16 ? Math.round(v) : v;
4084
+ }
4085
+ d2[i + 3] = depth === 16 ? Math.round(oa * k) : oa;
4086
+ }
4087
+ const tile2 = deepTile(d2, 4, 0);
4088
+ if (tile2) tiles.set(key, tile2);
4089
+ else tiles.delete(key);
4090
+ continue;
4091
+ }
4253
4092
  const d = new Uint8ClampedArray(TILE * TILE * ch);
4254
4093
  if (under) d.set(under.data);
4255
4094
  else if (base.defaultValue) d.fill(base.defaultValue);
@@ -4284,28 +4123,6 @@ function compositeSurfaceOver(base, top) {
4284
4123
  }
4285
4124
 
4286
4125
  export {
4287
- BIT_DEPTHS,
4288
- isBitDepth,
4289
- srgbDecode,
4290
- srgbEncode,
4291
- to16From8,
4292
- to32From8,
4293
- to32From16,
4294
- to16From32,
4295
- to8From16,
4296
- to8From32,
4297
- proxyOf,
4298
- depthOf,
4299
- deepTile,
4300
- tileSamples16,
4301
- tileSamples32,
4302
- tileSamples,
4303
- surfaceDepth,
4304
- readDeepRegion,
4305
- writeDeepRegion,
4306
- surfaceFromDeepPixels,
4307
- convertSurfaceDepth,
4308
- deepBytes,
4309
4126
  DEFAULT_GLOBAL_LIGHT,
4310
4127
  LAYER_EFFECT_KINDS,
4311
4128
  layerEffectLabel,
@@ -4369,4 +4186,4 @@ export {
4369
4186
  warpSurface,
4370
4187
  compositeSurfaceOver
4371
4188
  };
4372
- //# sourceMappingURL=chunk-D53KSJUV.js.map
4189
+ //# sourceMappingURL=chunk-VD2UDVF7.js.map