@pixerate/editor 0.189.0 → 0.190.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 (31) hide show
  1. package/dist/{chunk-ZEHTUR7Z.js → chunk-7ZWLDVFH.js} +971 -753
  2. package/dist/{chunk-ED4L4UD6.cjs → chunk-T4U4O6DS.cjs} +1005 -787
  3. package/dist/image-editor/controller.d.cts +51 -1
  4. package/dist/image-editor/controller.d.ts +51 -1
  5. package/dist/image-editor/free-transform.d.cts +3 -6
  6. package/dist/image-editor/free-transform.d.ts +3 -6
  7. package/dist/image-editor/index.cjs +1219 -901
  8. package/dist/image-editor/index.d.cts +1 -0
  9. package/dist/image-editor/index.d.ts +1 -0
  10. package/dist/image-editor/index.js +321 -3
  11. package/dist/image-editor/layer-tools.d.cts +1 -1
  12. package/dist/image-editor/layer-tools.d.ts +1 -1
  13. package/dist/image-editor/layers/compositor.d.cts +3 -0
  14. package/dist/image-editor/layers/compositor.d.ts +3 -0
  15. package/dist/image-editor/layers/model.d.cts +23 -0
  16. package/dist/image-editor/layers/model.d.ts +23 -0
  17. package/dist/image-editor/layers/panel.d.cts +11 -1
  18. package/dist/image-editor/layers/panel.d.ts +11 -1
  19. package/dist/image-editor/layers/serialize.d.cts +11 -0
  20. package/dist/image-editor/layers/serialize.d.ts +11 -0
  21. package/dist/image-editor/layers/shape.d.cts +5 -0
  22. package/dist/image-editor/layers/shape.d.ts +5 -0
  23. package/dist/image-editor/layers/vector-mask.d.cts +51 -0
  24. package/dist/image-editor/layers/vector-mask.d.ts +51 -0
  25. package/dist/image-editor/psd/import.d.cts +0 -7
  26. package/dist/image-editor/psd/import.d.ts +0 -7
  27. package/dist/paint-editor/index.cjs +6 -6
  28. package/dist/paint-editor/index.js +1 -1
  29. package/package.json +1 -1
  30. package/skills/pixerate-image-editor/SKILL.md +6 -0
  31. package/skills/pixerate-image-selection-masking/SKILL.md +6 -2
@@ -2589,192 +2589,6 @@ function removeAlpha(imageData) {
2589
2589
  }
2590
2590
  }
2591
2591
 
2592
- // src/text/types.ts
2593
- var TEXT_ALIGNS = ["left", "center", "right", "justify"];
2594
-
2595
- // src/image-editor/layers/model.ts
2596
- var MAX_EFFECT_ANIMATION_MS = 6e4;
2597
- var SHAPE_OPERATIONS = ["combine", "subtract", "intersect", "exclude"];
2598
- var LIVE_SHAPE_KINDS = ["rect", "ellipse", "polygon", "star", "line"];
2599
- var idCounter = 0;
2600
- function newLayerId(prefix = "layer") {
2601
- return `${prefix}_${Date.now().toString(36)}_${(++idCounter).toString(36)}`;
2602
- }
2603
- function pixelLayers(layers) {
2604
- return _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).filter((l) => l.type === "pixel");
2605
- }
2606
- function developFilter(layer) {
2607
- return _optionalChain([layer, 'access', _14 => _14.filters, 'optionalAccess', _15 => _15.find, 'call', _16 => _16((f) => f.kind === "develop")]);
2608
- }
2609
- function blurFilter(layer) {
2610
- return _optionalChain([layer, 'access', _17 => _17.filters, 'optionalAccess', _18 => _18.find, 'call', _19 => _19((f) => f.kind === "blur")]);
2611
- }
2612
- function isActiveFilter(f) {
2613
- if (!f.enabled) return false;
2614
- if (f.kind === "blur") return Math.min(Math.round(f.radius), 40) >= 1;
2615
- return Boolean(f.brightness || f.contrast || f.saturation || f.exposure || f.temperature || f.tint);
2616
- }
2617
- function isSpatialFilter(f) {
2618
- return f.kind === "blur";
2619
- }
2620
- function pixelLayerBounds(layer, surface = layer.surface) {
2621
- const b = surface.bounds;
2622
- if (!b) return null;
2623
- return { x: b.x + layer.offset.x, y: b.y + layer.offset.y, width: b.width, height: b.height };
2624
- }
2625
- function layerTypeLabel(type) {
2626
- return type === "pixel" ? "Pixel layer" : type === "adjustment" ? "Adjustment layer" : type === "group" ? "Group" : type === "smart" ? "Smart object" : type === "shape" ? "Shape layer" : type === "type" ? "Type layer" : "Annotation";
2627
- }
2628
- function hasSurface(layer) {
2629
- return layer.type === "pixel" || layer.type === "smart" || layer.type === "shape" || layer.type === "type";
2630
- }
2631
- function isRenderedLayer(layer) {
2632
- return layer.type === "smart" || layer.type === "shape" || layer.type === "type";
2633
- }
2634
- function shapeLayers(layers) {
2635
- return _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).filter((l) => l.type === "shape");
2636
- }
2637
- function smartObjectLayers(layers) {
2638
- return _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).filter((l) => l.type === "smart");
2639
- }
2640
-
2641
- // src/image-editor/layers/compositor.ts
2642
- var legacyViewCache = /* @__PURE__ */ new WeakMap();
2643
- function adjustmentNodeAsLayer(node) {
2644
- let view = legacyViewCache.get(node);
2645
- if (!view) {
2646
- view = {
2647
- id: node.id,
2648
- kind: node.kind,
2649
- enabled: node.visible,
2650
- opacity: node.opacity,
2651
- blend: node.blend,
2652
- params: node.params
2653
- };
2654
- legacyViewCache.set(node, view);
2655
- }
2656
- return view;
2657
- }
2658
- function developAdjustments(f) {
2659
- return {
2660
- brightness: f.brightness,
2661
- contrast: f.contrast,
2662
- saturation: f.saturation,
2663
- exposure: f.exposure,
2664
- temperature: f.temperature,
2665
- tint: _nullishCoalesce(f.tint, () => ( 0)),
2666
- blur: 0,
2667
- opacity: 1,
2668
- process: f.process
2669
- };
2670
- }
2671
- function applyPixelFilters(data, filters) {
2672
- for (const f of filters) {
2673
- if (!isActiveFilter(f) || f.kind !== "develop") continue;
2674
- const adj = developAdjustments(f);
2675
- if (normalizeProcessVersion(adj.process) === LATEST_PROCESS_VERSION) applyProcess2Adjustments({ data }, adj);
2676
- else applyLegacyAdjustments({ data }, adj);
2677
- }
2678
- }
2679
- function depthMaskAlpha(depth, options) {
2680
- const { mode, depthRange, softness, invert } = options;
2681
- let v = invert ? 255 - depth : depth;
2682
- const soft = Math.max(1, softness || 10);
2683
- const [lo, hi] = depthRange;
2684
- if (mode === "threshold") {
2685
- if (v >= hi + soft) return 0;
2686
- if (v > hi) return Math.round((hi + soft - v) / soft * 255);
2687
- if (v >= lo) return 255;
2688
- if (v < lo - soft) return 0;
2689
- return Math.round((v - (lo - soft)) / soft * 255);
2690
- }
2691
- v += lo;
2692
- return v < 0 ? 0 : v > 255 ? 255 : v;
2693
- }
2694
- function runLayerFilters(data, width, height, filters) {
2695
- for (const f of filters) {
2696
- if (!isActiveFilter(f)) continue;
2697
- if (f.kind === "develop") applyPixelFilters(data, [f]);
2698
- else if (f.kind === "blur") applyBoxBlur({ width, height, data }, Math.min(Math.round(f.radius), 40));
2699
- }
2700
- }
2701
- function runLayerFiltersFloat(data, width, height, filters, linear) {
2702
- for (const f of filters) {
2703
- if (!isActiveFilter(f)) continue;
2704
- if (f.kind === "blur") applyBoxBlurFloat({ width, height, data }, Math.min(Math.round(f.radius), 40));
2705
- else if (f.kind === "develop") {
2706
- const adj = developAdjustments(f);
2707
- if (normalizeProcessVersion(adj.process) === LATEST_PROCESS_VERSION) applyProcess2Float(data, adj, linear);
2708
- else applyLegacyFloat(data, adj, linear);
2709
- }
2710
- }
2711
- }
2712
- function filterReach(filters) {
2713
- let r = 0;
2714
- for (const f of filters) if (isActiveFilter(f) && f.kind === "blur") r += Math.min(Math.round(f.radius), 40);
2715
- return r;
2716
- }
2717
- var filterSpecCache = /* @__PURE__ */ new WeakMap();
2718
- function pixelFilterSpec(layer) {
2719
- const list2 = layer.filters;
2720
- if (!_optionalChain([list2, 'optionalAccess', _20 => _20.length])) return null;
2721
- if (filterSpecCache.has(list2)) return filterSpecCache.get(list2);
2722
- const filters = list2.filter(isActiveFilter);
2723
- let spec = null;
2724
- if (filters.length) {
2725
- const spatial = filters.some(isSpatialFilter);
2726
- spec = {
2727
- key: JSON.stringify(filters),
2728
- spatial,
2729
- apply: (data, width, height) => runLayerFilters(data, width, height, filters)
2730
- };
2731
- }
2732
- filterSpecCache.set(list2, spec);
2733
- return spec;
2734
- }
2735
- var PHOTO_PROFILE = {
2736
- isFilterLayer: (l) => l.type === "adjustment",
2737
- applyFilterRun: (layers, acc, _r, masks) => {
2738
- const views = layers.map(adjustmentNodeAsLayer);
2739
- applyAdjustmentLayers({ data: acc }, views, masks);
2740
- },
2741
- contentTile: (l, r, sources) => l.type === "annotation" ? _nullishCoalesce(_optionalChain([sources, 'access', _21 => _21.rasterizeAnnotation, 'optionalCall', _22 => _22(l.annotation, r)]), () => ( null)) : null,
2742
- /** Annotation layers draw with their annotation's blend mode unless the layer sets one. */
2743
- contentBlend: (l) => l.type === "annotation" && l.blend === "normal" && l.annotation.blend ? l.annotation.blend : l.blend,
2744
- layerKey: (l) => l.type === "pixel" ? [_nullishCoalesce(l.filters, () => ( null)), _nullishCoalesce(l.source, () => ( null))] : l.type === "adjustment" ? [l.kind, l.params] : l.type === "annotation" ? l.annotation : void 0,
2745
- pixelFilters: (l) => l.type === "pixel" ? pixelFilterSpec(l) : null,
2746
- /**
2747
- * A smart object draws its rendered pixels (contents → placement → smart filters) like a pixel
2748
- * layer, and a shape layer the pixels rendered from its paths.
2749
- */
2750
- isPixelLike: (l) => l.type === "smart" || l.type === "shape" || l.type === "type",
2751
- maskSourcePlane: (source, W, H, sources) => {
2752
- const opts = source;
2753
- const depth = _nullishCoalesce(_optionalChain([sources, 'access', _23 => _23.depthMap, 'optionalCall', _24 => _24(opts)]), () => ( null));
2754
- if (!depth || depth.width !== W || depth.height !== H) return null;
2755
- const v = new Float32Array(W * H);
2756
- for (let i = 0; i < v.length; i++) v[i] = depthMaskAlpha(depth.data[i * 4], opts) / 255;
2757
- return v;
2758
- }
2759
- };
2760
- var LayerCompositor = class extends _chunkHGTDMKNEcjs.RasterCompositor {
2761
- constructor(options = {}) {
2762
- super(PHOTO_PROFILE, options);
2763
- }
2764
- };
2765
- function compositeDeep(layers, rect, sources, depth) {
2766
- const deep = new (0, _chunkHGTDMKNEcjs.DeepCompositor)(new LayerCompositor(), PHOTO_PROFILE, {
2767
- applyFilterRunDeep: (run, acc, _r, masks) => applyAdjustmentLayersFloat(acc, run.map(adjustmentNodeAsLayer), masks),
2768
- pixelFiltersDeep: (l) => {
2769
- if (l.type !== "pixel") return null;
2770
- const filters = (_nullishCoalesce(l.filters, () => ( []))).filter(isActiveFilter);
2771
- if (!filters.length) return null;
2772
- return { reach: filterReach(filters), apply: (data, width, height, linear) => runLayerFiltersFloat(data, width, height, filters, linear) };
2773
- }
2774
- }, depth);
2775
- return deep.composite(layers, rect, sources);
2776
- }
2777
-
2778
2592
  // src/image-editor/layers/vector-raster.ts
2779
2593
  var FLATNESS = 0.01;
2780
2594
  function flattenPath(path, tolerance = FLATNESS) {
@@ -3108,355 +2922,59 @@ function combineCoverage(a, b, op, n) {
3108
2922
  return out;
3109
2923
  }
3110
2924
 
3111
- // src/image-editor/layers/ops.ts
3112
- var LayerOperationError = class extends Error {
3113
-
3114
- constructor(message, userMessage) {
3115
- super(message);
3116
- this.name = "LayerOperationError";
3117
- if (userMessage) this.userMessage = userMessage;
3118
- }
3119
- };
3120
- function userErrorMessage(err) {
3121
- if (err instanceof LayerOperationError && err.userMessage) return err.userMessage;
3122
- return err instanceof Error ? err.message : String(err);
2925
+ // src/text/types.ts
2926
+ var TEXT_ALIGNS = ["left", "center", "right", "justify"];
2927
+
2928
+ // src/image-editor/layers/model.ts
2929
+ var MAX_EFFECT_ANIMATION_MS = 6e4;
2930
+ var SHAPE_OPERATIONS = ["combine", "subtract", "intersect", "exclude"];
2931
+ var LIVE_SHAPE_KINDS = ["rect", "ellipse", "polygon", "star", "line"];
2932
+ var idCounter = 0;
2933
+ function newLayerId(prefix = "layer") {
2934
+ return `${prefix}_${Date.now().toString(36)}_${(++idCounter).toString(36)}`;
3123
2935
  }
3124
- function isPaintableLayer(layer) {
3125
- return layer.type === "pixel" && layer.visible && !_chunkHGTDMKNEcjs.isLayerLocked.call(void 0, layer, "pixels");
2936
+ function pixelLayers(layers) {
2937
+ return _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).filter((l) => l.type === "pixel");
3126
2938
  }
3127
- function defaultActiveLayerId(layers) {
3128
- const pixels = _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).filter((l) => l.type === "pixel");
3129
- for (let i = pixels.length - 1; i >= 0; i--) if (isPaintableLayer(pixels[i])) return pixels[i].id;
3130
- return _nullishCoalesce(_optionalChain([pixels, 'access', _25 => _25[pixels.length - 1], 'optionalAccess', _26 => _26.id]), () => ( null));
2939
+ function developFilter(layer) {
2940
+ return _optionalChain([layer, 'access', _14 => _14.filters, 'optionalAccess', _15 => _15.find, 'call', _16 => _16((f) => f.kind === "develop")]);
3131
2941
  }
3132
- function activeLayerAfterRemoval(prev, next, removedId) {
3133
- const before = _chunkHGTDMKNEcjs.flattenLayers.call(void 0, prev);
3134
- const at = before.findIndex((l) => l.id === removedId);
3135
- for (let i = at - 1; i >= 0; i--) {
3136
- const loc = _chunkHGTDMKNEcjs.findLayer.call(void 0, next, before[i].id);
3137
- if (loc && isPaintableLayer(loc.layer)) return loc.layer.id;
3138
- }
3139
- return defaultActiveLayerId(next);
2942
+ function blurFilter(layer) {
2943
+ return _optionalChain([layer, 'access', _17 => _17.filters, 'optionalAccess', _18 => _18.find, 'call', _19 => _19((f) => f.kind === "blur")]);
3140
2944
  }
3141
- var fail = (message) => {
3142
- throw new LayerOperationError(message);
3143
- };
3144
- function requireLayer(layers, id) {
3145
- const loc = _chunkHGTDMKNEcjs.findLayer.call(void 0, layers, id);
3146
- if (!loc) {
3147
- const ids = _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).map((l) => l.id);
3148
- fail(`Unknown layer "${id}". ${ids.length ? `Layers: ${ids.join(", ")}.` : "The document has no layers."} Call list_layers for ids.`);
3149
- }
3150
- return loc;
2945
+ function isActiveFilter(f) {
2946
+ if (!f.enabled) return false;
2947
+ if (f.kind === "blur") return Math.min(Math.round(f.radius), 40) >= 1;
2948
+ return Boolean(f.brightness || f.contrast || f.saturation || f.exposure || f.temperature || f.tint);
3151
2949
  }
3152
- function requireUnlocked(layer, what, action) {
3153
- if (_chunkHGTDMKNEcjs.isLayerLocked.call(void 0, layer, "all")) fail(`Layer "${layer.name || layer.id}" is locked (all); unlock it before you ${action}.`);
3154
- if (what !== "all" && _chunkHGTDMKNEcjs.isLayerLocked.call(void 0, layer, what)) fail(`Layer "${layer.name || layer.id}" has its ${what} locked; unlock it before you ${action}.`);
2950
+ function isSpatialFilter(f) {
2951
+ return f.kind === "blur";
3155
2952
  }
3156
- function placeLayer(layers, layer, placement = {}, defaultIndex) {
3157
- const given = [placement.aboveId, placement.belowId, placement.parentId].filter((v) => v !== void 0).length;
3158
- if (given > 1) fail("Give only one of aboveId, belowId and parentId.");
3159
- if (placement.aboveId || placement.belowId) {
3160
- const ref = requireLayer(layers, _nullishCoalesce(placement.aboveId, () => ( placement.belowId)));
3161
- return _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, layer, _nullishCoalesce(_optionalChain([ref, 'access', _27 => _27.parent, 'optionalAccess', _28 => _28.id]), () => ( null)), ref.index + (placement.aboveId ? 1 : 0));
3162
- }
3163
- if (placement.parentId) {
3164
- const ref = requireLayer(layers, placement.parentId);
3165
- if (ref.layer.type !== "group") fail(`Layer "${placement.parentId}" is not a group; parentId must be a group id.`);
3166
- return _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, layer, ref.layer.id, placement.index);
3167
- }
3168
- return _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, layer, null, _nullishCoalesce(placement.index, () => ( defaultIndex)));
2953
+ function pixelLayerBounds(layer, surface = layer.surface) {
2954
+ const b = surface.bounds;
2955
+ if (!b) return null;
2956
+ return { x: b.x + layer.offset.x, y: b.y + layer.offset.y, width: b.width, height: b.height };
3169
2957
  }
3170
- function removeLayer(layers, id) {
3171
- const loc = requireLayer(layers, id);
3172
- requireUnlocked(loc.layer, "all", "delete it");
3173
- return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => null);
3174
- }
3175
- function moveLayer(layers, id, placement) {
3176
- const loc = requireLayer(layers, id);
3177
- requireUnlocked(loc.layer, "all", "move it");
3178
- const target = _nullishCoalesce(_nullishCoalesce(placement.aboveId, () => ( placement.belowId)), () => ( placement.parentId));
3179
- if (target === id) fail("A layer cannot be placed relative to itself.");
3180
- if (target && loc.layer.type === "group" && _chunkHGTDMKNEcjs.flattenLayers.call(void 0, loc.layer.children).some((l) => l.id === target)) {
3181
- fail(`Group "${id}" cannot be moved into its own child "${target}".`);
3182
- }
3183
- if (target) requireLayer(layers, target);
3184
- if (!target && placement.index === void 0) fail("Give aboveId, belowId, parentId or index.");
3185
- const without = _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => null);
3186
- return placeLayer(without, loc.layer, placement);
3187
- }
3188
- function withNewIds(layer) {
3189
- const next = { ...layer, id: newLayerId(layer.type === "adjustment" ? "adj" : layer.type) };
3190
- if (next.type === "group") next.children = next.children.map(withNewIds);
3191
- if (next.type === "annotation") next.annotation = { ...next.annotation, id: next.id };
3192
- if (next.type === "shape" || next.type === "type") delete next.annotation;
3193
- if (next.type === "smart" && _optionalChain([next, 'access', _29 => _29.psd, 'optionalAccess', _30 => _30.placed])) {
3194
- next.psd = { ...next.psd };
3195
- delete next.psd.placed;
3196
- }
3197
- return next;
3198
- }
3199
- function duplicateLayer(layers, id, name) {
3200
- const loc = requireLayer(layers, id);
3201
- const copy = withNewIds(loc.layer);
3202
- copy.name = _nullishCoalesce(name, () => ( `${loc.layer.name || "Layer"} copy`));
3203
- delete copy.locks;
3204
- return { layers: _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, copy, _nullishCoalesce(_optionalChain([loc, 'access', _31 => _31.parent, 'optionalAccess', _32 => _32.id]), () => ( null)), loc.index + 1), id: copy.id };
3205
- }
3206
- function setLayerProperties(layers, id, props) {
3207
- const loc = requireLayer(layers, id);
3208
- const layer = loc.layer;
3209
- const onlyUnlocking = Object.keys(props).every((k) => k === "locks" || k === "visible" || k === "collapsed");
3210
- if (!onlyUnlocking) requireUnlocked(layer, "all", "change its properties");
3211
- const next = { ...layer };
3212
- if (props.name !== void 0) {
3213
- if (typeof props.name !== "string" || !props.name.trim()) fail("name must be a non-empty string.");
3214
- next.name = props.name.trim();
3215
- }
3216
- if (props.visible !== void 0) next.visible = Boolean(props.visible);
3217
- if (props.opacity !== void 0) {
3218
- if (!(typeof props.opacity === "number" && props.opacity >= 0 && props.opacity <= 1)) fail("opacity must be a number from 0 to 1.");
3219
- next.opacity = props.opacity;
3220
- }
3221
- if (props.fillOpacity !== void 0) {
3222
- if (layer.type !== "pixel" && layer.type !== "smart" && layer.type !== "shape" && layer.type !== "type") fail(`fillOpacity applies to pixel, shape, type and smart object layers; "${id}" is a ${layer.type} layer.`);
3223
- if (!(typeof props.fillOpacity === "number" && props.fillOpacity >= 0 && props.fillOpacity <= 1)) fail("fillOpacity must be a number from 0 to 1.");
3224
- const p = next;
3225
- if (props.fillOpacity === 1) delete p.fillOpacity;
3226
- else p.fillOpacity = props.fillOpacity;
3227
- }
3228
- if (props.blend !== void 0) {
3229
- if (props.blend === "pass-through") {
3230
- if (layer.type !== "group") fail("pass-through is only for groups.");
3231
- } else if (!_chunkCWM3CUUXcjs.isBlendMode.call(void 0, props.blend)) fail(`Unknown blend mode "${props.blend}".`);
3232
- next.blend = props.blend;
3233
- }
3234
- if (props.clipped !== void 0) {
3235
- if (props.clipped && loc.index === 0) fail("The bottom layer of a group or the stack has nothing below to clip to.");
3236
- if (props.clipped) next.clipped = true;
3237
- else delete next.clipped;
3238
- }
3239
- if (props.locks !== void 0) {
3240
- const locks = {};
3241
- for (const k of ["pixels", "transparency", "position", "all"]) if (props.locks[k]) locks[k] = true;
3242
- if (Object.keys(locks).length) next.locks = locks;
3243
- else delete next.locks;
3244
- }
3245
- if (props.collapsed !== void 0) {
3246
- if (layer.type !== "group") fail("collapsed applies to groups.");
3247
- const g = next;
3248
- if (props.collapsed) g.collapsed = true;
3249
- else delete g.collapsed;
3250
- }
3251
- return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => next);
3252
- }
3253
- function groupLayers(layers, ids, name = "Group") {
3254
- if (!ids.length) fail("Give at least one layer id to group.");
3255
- const locs = ids.map((id) => requireLayer(layers, id));
3256
- const parent = _nullishCoalesce(_optionalChain([locs, 'access', _33 => _33[0], 'access', _34 => _34.parent, 'optionalAccess', _35 => _35.id]), () => ( null));
3257
- if (locs.some((l) => (_nullishCoalesce(_optionalChain([l, 'access', _36 => _36.parent, 'optionalAccess', _37 => _37.id]), () => ( null))) !== parent)) fail("Layers to group must share one parent; move them next to each other first.");
3258
- for (const l of locs) requireUnlocked(l.layer, "all", "group it");
3259
- const ordered = [...new Set(locs)].sort((a, b) => a.index - b.index);
3260
- const top = ordered[ordered.length - 1].index;
3261
- const below = ordered.filter((l) => l.index < top).length;
3262
- const group = {
3263
- type: "group",
3264
- id: newLayerId("group"),
3265
- name,
3266
- visible: true,
3267
- opacity: 1,
3268
- blend: "pass-through",
3269
- children: ordered.map((l) => {
3270
- const c = { ...l.layer };
3271
- return c;
3272
- })
3273
- };
3274
- if (_optionalChain([group, 'access', _38 => _38.children, 'access', _39 => _39[0], 'optionalAccess', _40 => _40.clipped])) {
3275
- const c = { ...group.children[0] };
3276
- delete c.clipped;
3277
- group.children[0] = c;
3278
- }
3279
- let out = layers;
3280
- for (const l of ordered) out = _chunkHGTDMKNEcjs.mapLayer.call(void 0, out, l.layer.id, () => null);
3281
- return { layers: _chunkHGTDMKNEcjs.insertLayer.call(void 0, out, group, parent, top - below), id: group.id };
3282
- }
3283
- function ungroupLayer(layers, id) {
3284
- const loc = requireLayer(layers, id);
3285
- if (loc.layer.type !== "group") fail(`Layer "${id}" is not a group.`);
3286
- requireUnlocked(loc.layer, "all", "ungroup it");
3287
- const group = loc.layer;
3288
- let out = _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => null);
3289
- group.children.forEach((c, i) => {
3290
- out = _chunkHGTDMKNEcjs.insertLayer.call(void 0, out, c, _nullishCoalesce(_optionalChain([loc, 'access', _41 => _41.parent, 'optionalAccess', _42 => _42.id]), () => ( null)), loc.index + i);
3291
- });
3292
- return { layers: out, ids: group.children.map((c) => c.id) };
3293
- }
3294
- function offsetLayer(layers, id, offset) {
3295
- const loc = requireLayer(layers, id);
3296
- if (loc.layer.type !== "pixel") fail(`Only pixel layers move; "${id}" is a ${loc.layer.type} layer.`);
3297
- requireUnlocked(loc.layer, "position", "move it");
3298
- if (!Number.isFinite(offset.x) || !Number.isFinite(offset.y)) fail("x and y must be numbers.");
3299
- const layer = loc.layer;
3300
- const next = { ...layer, offset: { x: Math.round(offset.x), y: Math.round(offset.y) } };
3301
- const mask = layer.mask;
3302
- if (mask && mask.linked === false && !mask.source) {
3303
- next.mask = { ...mask, surface: _chunkCWM3CUUXcjs.translateSurface.call(void 0, mask.surface, layer.offset.x - next.offset.x, layer.offset.y - next.offset.y) };
3304
- }
3305
- return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => next);
3306
- }
3307
- function setLayerMask(layers, id, mask) {
3308
- const loc = requireLayer(layers, id);
3309
- requireUnlocked(loc.layer, "all", "change its mask");
3310
- return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, (l) => {
3311
- const next = { ...l };
3312
- if (mask) next.mask = mask;
3313
- else delete next.mask;
3314
- return next;
3315
- });
3316
- }
3317
- var DEVELOP_FIELDS = ["brightness", "contrast", "saturation", "exposure", "temperature", "tint"];
3318
- function normalizeFilter(raw, id = newLayerId("flt")) {
3319
- const enabled = raw.enabled !== false;
3320
- if (raw.kind === "blur") {
3321
- const r = raw.radius;
3322
- if (r !== void 0 && !(typeof r === "number" && r >= 0 && r <= 50)) fail("blur radius must be a number from 0 to 50 px.");
3323
- return { id, kind: "blur", enabled, radius: typeof r === "number" ? r : 2 };
3324
- }
3325
- if (raw.kind !== "develop") fail(`Unknown filter kind "${raw.kind}". Use develop or blur.`);
3326
- const out = { id, kind: "develop", enabled, brightness: 0, contrast: 0, saturation: 0, exposure: 0, temperature: 0, tint: 0, process: 2 };
3327
- for (const k of DEVELOP_FIELDS) {
3328
- const v = raw[k];
3329
- if (v === void 0) continue;
3330
- if (!(typeof v === "number" && v >= -100 && v <= 100)) fail(`${k} must be a number from -100 to 100.`);
3331
- out[k] = v;
3332
- }
3333
- const p = raw.process;
3334
- if (p !== void 0) {
3335
- if (p !== 1 && p !== 2) fail("process must be 1 or 2.");
3336
- out.process = p;
3337
- }
3338
- return out;
3339
- }
3340
- function requirePixelLayer(layers, id) {
3341
- const loc = requireLayer(layers, id);
3342
- if (loc.layer.type !== "pixel") fail(`Filters belong to pixel layers; "${id}" is a ${loc.layer.type} layer.`);
3343
- requireUnlocked(loc.layer, "all", "change its filters");
3344
- return loc.layer;
3345
- }
3346
- function addLayerFilter(layers, id, filter) {
3347
- const layer = requirePixelLayer(layers, id);
3348
- if (_optionalChain([layer, 'access', _43 => _43.filters, 'optionalAccess', _44 => _44.some, 'call', _45 => _45((f) => f.kind === filter.kind)])) fail(`Layer "${id}" already has a ${filter.kind} filter; change it with update_layer_filter.`);
3349
- return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => ({ ...layer, filters: [..._nullishCoalesce(layer.filters, () => ( [])), filter] }));
3350
- }
3351
- function updateLayerFilter(layers, id, filterId, changes) {
3352
- const layer = requirePixelLayer(layers, id);
3353
- const i = (_nullishCoalesce(layer.filters, () => ( []))).findIndex((f) => f.id === filterId);
3354
- if (i === -1) fail(`Layer "${id}" has no filter "${filterId}". Filters: ${(_nullishCoalesce(layer.filters, () => ( []))).map((f) => f.id).join(", ") || "none"}.`);
3355
- const current = layer.filters[i];
3356
- if ("kind" in changes && changes.kind !== current.kind) fail("A filter kind cannot change; remove it and add another.");
3357
- const merged2 = normalizeFilter({ ...current, ...changes, kind: current.kind }, current.id);
3358
- const filters = [...layer.filters];
3359
- filters[i] = merged2;
3360
- return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => ({ ...layer, filters }));
3361
- }
3362
- function removeLayerFilter(layers, id, filterId) {
3363
- const layer = requirePixelLayer(layers, id);
3364
- if (!(_nullishCoalesce(layer.filters, () => ( []))).some((f) => f.id === filterId)) fail(`Layer "${id}" has no filter "${filterId}".`);
3365
- const filters = layer.filters.filter((f) => f.id !== filterId);
3366
- const next = { ...layer };
3367
- if (filters.length) next.filters = filters;
3368
- else delete next.filters;
3369
- return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => next);
3370
- }
3371
- function requireEffectLayer(layers, id, action) {
3372
- const layer = requireLayer(layers, id).layer;
3373
- if (layer.type === "adjustment") fail(`Layer "${layer.name || id}" is an adjustment layer; effects go on pixel, annotation and group layers.`);
3374
- requireUnlocked(layer, "all", action);
3375
- return layer;
3376
- }
3377
- function layerEffectsOf(layer) {
3378
- return _nullishCoalesce(layer.effects, () => ( { enabled: true, items: [] }));
3379
- }
3380
- function guard(fn) {
3381
- try {
3382
- return fn();
3383
- } catch (e) {
3384
- if (e instanceof _chunkHGTDMKNEcjs.LayerEffectError) fail(e.message);
3385
- throw e;
3386
- }
3387
- }
3388
- function setLayerEffects(layers, id, effects) {
3389
- const layer = requireEffectLayer(layers, id, "change its effects");
3390
- const next = { ...layer };
3391
- if (effects && (effects.items.length || effects.psd || effects.scale !== void 0 || !effects.enabled)) {
3392
- guard(() => _chunkHGTDMKNEcjs.validateLayerEffects.call(void 0, effects));
3393
- next.effects = effects;
3394
- } else delete next.effects;
3395
- return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => next);
3396
- }
3397
- function addLayerEffect(layers, id, kind, params = {}, index) {
3398
- if (!_chunkHGTDMKNEcjs.isLayerEffectKind.call(void 0, kind)) fail(`Unknown effect kind "${String(kind)}". Kinds: ${_chunkHGTDMKNEcjs.LAYER_EFFECT_KINDS.join(", ")}.`);
3399
- const layer = requireEffectLayer(layers, id, "add effects");
3400
- const current = layerEffectsOf(layer);
3401
- const ids = new Set(current.items.map((e) => e.id));
3402
- let effectId = _chunkHGTDMKNEcjs.newEffectId.call(void 0, );
3403
- while (ids.has(effectId)) effectId = _chunkHGTDMKNEcjs.newEffectId.call(void 0, );
3404
- const { id: _ignored, kind: _kind, ...rest } = params;
3405
- const effect = guard(() => _chunkHGTDMKNEcjs.mergeLayerEffect.call(void 0, _chunkHGTDMKNEcjs.defaultLayerEffect.call(void 0, kind, effectId), rest));
3406
- const items = [...current.items];
3407
- const at = index === void 0 ? items.length : Math.max(0, Math.min(items.length, Math.floor(index)));
3408
- items.splice(at, 0, effect);
3409
- return { layers: setLayerEffects(layers, id, { ...current, items }), effect };
3410
- }
3411
- function requireEffect(layer, effectId) {
3412
- const items = _nullishCoalesce(_optionalChain([layer, 'access', _46 => _46.effects, 'optionalAccess', _47 => _47.items]), () => ( []));
3413
- const i = items.findIndex((e) => e.id === effectId);
3414
- if (i === -1) fail(`Layer "${layer.name || layer.id}" has no effect "${effectId}". Effects: ${items.map((e) => `${e.id} (${e.kind})`).join(", ") || "none"}; call list_layer_effects.`);
3415
- return i;
3416
- }
3417
- function updateLayerEffect(layers, id, effectId, changes) {
3418
- const layer = requireEffectLayer(layers, id, "change its effects");
3419
- const i = requireEffect(layer, effectId);
3420
- const current = layer.effects;
3421
- const items = [...current.items];
3422
- items[i] = guard(() => _chunkHGTDMKNEcjs.mergeLayerEffect.call(void 0, items[i], changes));
3423
- return setLayerEffects(layers, id, { ...current, items });
2958
+ function layerTypeLabel(type) {
2959
+ return type === "pixel" ? "Pixel layer" : type === "adjustment" ? "Adjustment layer" : type === "group" ? "Group" : type === "smart" ? "Smart object" : type === "shape" ? "Shape layer" : type === "type" ? "Type layer" : "Annotation";
3424
2960
  }
3425
- function removeLayerEffect(layers, id, effectId) {
3426
- const layer = requireEffectLayer(layers, id, "change its effects");
3427
- requireEffect(layer, effectId);
3428
- const current = layer.effects;
3429
- return setLayerEffects(layers, id, { ...current, items: current.items.filter((e) => e.id !== effectId) });
2961
+ function hasSurface(layer) {
2962
+ return layer.type === "pixel" || layer.type === "smart" || layer.type === "shape" || layer.type === "type";
3430
2963
  }
3431
- function setLayerEffectsEnabled(layers, id, enabled, scale) {
3432
- const layer = requireEffectLayer(layers, id, "change its effects");
3433
- if (scale !== void 0 && !(Number.isFinite(scale) && scale >= 0.01 && scale <= 10)) fail(`scale must be from 0.01 to 10 (1 = 100 %), got ${scale}.`);
3434
- const current = layerEffectsOf(layer);
3435
- const next = { ...current, enabled };
3436
- if (scale !== void 0) {
3437
- if (scale === 1) delete next.scale;
3438
- else next.scale = scale;
3439
- }
3440
- return setLayerEffects(layers, id, next);
2964
+ function isRenderedLayer(layer) {
2965
+ return layer.type === "smart" || layer.type === "shape" || layer.type === "type";
3441
2966
  }
3442
- function parseBlend(value, allowPassThrough = false) {
3443
- if (value === void 0) return void 0;
3444
- if (value === "pass-through" && allowPassThrough) return value;
3445
- if (!_chunkCWM3CUUXcjs.isBlendMode.call(void 0, value)) fail(`Unknown blend mode "${String(value)}".`);
3446
- return value;
2967
+ function shapeLayers(layers) {
2968
+ return _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).filter((l) => l.type === "shape");
3447
2969
  }
3448
- function unionRect(a, b) {
3449
- if (!a) return b;
3450
- if (!b) return a;
3451
- const x = Math.min(a.x, b.x);
3452
- const y = Math.min(a.y, b.y);
3453
- return { x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
2970
+ function smartObjectLayers(layers) {
2971
+ return _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).filter((l) => l.type === "smart");
3454
2972
  }
3455
2973
 
3456
2974
  // src/image-editor/layers/shape.ts
3457
2975
  var SHAPE_RENDER_MARGIN = _chunkHGTDMKNEcjs.MAX_EFFECT_REACH;
3458
2976
  var DEFAULT_MITER_LIMIT = 100;
3459
- var fail2 = (message) => {
2977
+ var fail = (message) => {
3460
2978
  throw new LayerOperationError(message);
3461
2979
  };
3462
2980
  var orientation = (anchors) => {
@@ -3597,7 +3115,7 @@ function closedOutline(path) {
3597
3115
  function strokeArea(path, stroke, double) {
3598
3116
  const w = stroke.width * (double ? 2 : 1);
3599
3117
  if (!(w > 0) || !path.length) return [];
3600
- const dashes = _optionalChain([stroke, 'access', _48 => _48.dashes, 'optionalAccess', _49 => _49.length]) && stroke.dashes.some((d) => d > 0) ? stroke.dashes.map((d) => d * stroke.width) : void 0;
3118
+ const dashes = _optionalChain([stroke, 'access', _20 => _20.dashes, 'optionalAccess', _21 => _21.length]) && stroke.dashes.some((d) => d > 0) ? stroke.dashes.map((d) => d * stroke.width) : void 0;
3601
3119
  const options = {
3602
3120
  width: w,
3603
3121
  cap: _nullishCoalesce(stroke.cap, () => ( "butt")),
@@ -3667,13 +3185,17 @@ function fillCoverage(geo, rect, rule, inverted = false) {
3667
3185
  });
3668
3186
  return acc;
3669
3187
  }
3188
+ function componentsCoverage(components, rect, rule = "nonzero", inverted = false) {
3189
+ const geo = { fills: components.map((c) => ({ op: c.op, flat: flattenPath(componentPath(c)) })) };
3190
+ return _nullishCoalesce(fillCoverage(geo, rect, rule, inverted), () => ( new Float32Array(rect.width * rect.height)));
3191
+ }
3670
3192
  function paintContext(env) {
3671
3193
  const tiles = /* @__PURE__ */ new Map();
3672
3194
  return {
3673
3195
  light: _chunkHGTDMKNEcjs.DEFAULT_GLOBAL_LIGHT,
3674
3196
  pattern: (id) => {
3675
3197
  if (tiles.has(id)) return tiles.get(id);
3676
- const p = _nullishCoalesce(_optionalChain([env, 'access', _50 => _50.pattern, 'optionalCall', _51 => _51(id)]), () => ( _chunkHGTDMKNEcjs.builtinPattern.call(void 0, id)));
3198
+ const p = _nullishCoalesce(_optionalChain([env, 'access', _22 => _22.pattern, 'optionalCall', _23 => _23(id)]), () => ( _chunkHGTDMKNEcjs.builtinPattern.call(void 0, id)));
3677
3199
  const t = p && p.width > 0 && p.height > 0 && p.data.length >= p.width * p.height * 4 ? new (0, _chunkHGTDMKNEcjs.PatternTile)(p) : null;
3678
3200
  tiles.set(id, t);
3679
3201
  return t;
@@ -3706,9 +3228,9 @@ function renderShapeRect(layer, rect, env, ctx = paintContext(env)) {
3706
3228
  const canvas = { x: 0, y: 0, width: env.width, height: env.height };
3707
3229
  const anchor = { x: geo.frame.x, y: geo.frame.y };
3708
3230
  const fc = fCov ? _chunkHGTDMKNEcjs.effectFillColors.call(void 0, layer.fill, rect, geo.frame, canvas, anchor, ctx) : null;
3709
- const fo = _nullishCoalesce(_optionalChain([layer, 'access', _52 => _52.fill, 'optionalAccess', _53 => _53.opacity]), () => ( 1));
3231
+ const fo = _nullishCoalesce(_optionalChain([layer, 'access', _24 => _24.fill, 'optionalAccess', _25 => _25.opacity]), () => ( 1));
3710
3232
  const sc = sCov ? _chunkHGTDMKNEcjs.effectFillColors.call(void 0, layer.stroke.paint, rect, geo.frame, canvas, anchor, ctx) : null;
3711
- const so = _nullishCoalesce(_optionalChain([layer, 'access', _54 => _54.stroke, 'optionalAccess', _55 => _55.paint, 'access', _56 => _56.opacity]), () => ( 1));
3233
+ const so = _nullishCoalesce(_optionalChain([layer, 'access', _26 => _26.stroke, 'optionalAccess', _27 => _27.paint, 'access', _28 => _28.opacity]), () => ( 1));
3712
3234
  const out = new Uint8ClampedArray(n * 4);
3713
3235
  let any = false;
3714
3236
  for (let i = 0; i < n; i++) {
@@ -3766,31 +3288,31 @@ function rerenderShape(layer, env) {
3766
3288
  }
3767
3289
  var isNum = (v) => typeof v === "number" && Number.isFinite(v);
3768
3290
  function requireNum(v, path, min = -Infinity, max = Infinity) {
3769
- if (!isNum(v)) fail2(`${path} must be a finite number.`);
3770
- if (v < min || v > max) fail2(`${path} must be between ${min} and ${max}, got ${v}.`);
3291
+ if (!isNum(v)) fail(`${path} must be a finite number.`);
3292
+ if (v < min || v > max) fail(`${path} must be between ${min} and ${max}, got ${v}.`);
3771
3293
  return v;
3772
3294
  }
3773
3295
  function normalizeShapePaint(v, path = "paint") {
3774
3296
  if (typeof v === "string") {
3775
3297
  const c = _chunkA2IS7EHEcjs.parseCssColor.call(void 0, v);
3776
- if (!c) return fail2(`${path}: "${v}" is not a colour; use #rrggbb (or #rrggbbaa, rgb(), a CSS colour name).`);
3298
+ if (!c) return fail(`${path}: "${v}" is not a colour; use #rrggbb (or #rrggbbaa, rgb(), a CSS colour name).`);
3777
3299
  return c.alpha < 1 ? { type: "color", color: c.hex, opacity: c.alpha } : { type: "color", color: c.hex };
3778
3300
  }
3779
- if (!v || typeof v !== "object") return fail2(`${path} must be a colour string or an object with type color, gradient or pattern.`);
3301
+ if (!v || typeof v !== "object") return fail(`${path} must be a colour string or an object with type color, gradient or pattern.`);
3780
3302
  const o = v;
3781
3303
  const opacity = o.opacity === void 0 ? void 0 : requireNum(o.opacity, `${path}.opacity`, 0, 1);
3782
3304
  const withOpacity = (p) => opacity !== void 0 && opacity !== 1 ? { ...p, opacity } : p;
3783
3305
  if (o.type === "color") {
3784
3306
  const c = _chunkA2IS7EHEcjs.parseCssColor.call(void 0, o.color);
3785
- if (!c) return fail2(`${path}.color must be a colour such as #rrggbb.`);
3307
+ if (!c) return fail(`${path}.color must be a colour such as #rrggbb.`);
3786
3308
  const op = (_nullishCoalesce(opacity, () => ( 1))) * c.alpha;
3787
3309
  return op !== 1 ? { type: "color", color: c.hex, opacity: op } : { type: "color", color: c.hex };
3788
3310
  }
3789
3311
  if (o.type === "gradient") {
3790
3312
  const g = o.gradient;
3791
- if (!g || typeof g !== "object") return fail2(`${path}.gradient is required: { stops: [{ position, color }], style, angle, \u2026 }.`);
3313
+ if (!g || typeof g !== "object") return fail(`${path}.gradient is required: { stops: [{ position, color }], style, angle, \u2026 }.`);
3792
3314
  const gradient = {
3793
- stops: Array.isArray(g.stops) ? g.stops.map((s) => ({ position: s.position, color: _nullishCoalesce(_optionalChain([_chunkA2IS7EHEcjs.parseCssColor.call(void 0, s.color), 'optionalAccess', _57 => _57.hex]), () => ( s.color)) })) : [],
3315
+ stops: Array.isArray(g.stops) ? g.stops.map((s) => ({ position: s.position, color: _nullishCoalesce(_optionalChain([_chunkA2IS7EHEcjs.parseCssColor.call(void 0, s.color), 'optionalAccess', _29 => _29.hex]), () => ( s.color)) })) : [],
3794
3316
  ...g.opacityStops ? { opacityStops: g.opacityStops } : {},
3795
3317
  style: _nullishCoalesce(g.style, () => ( "linear")),
3796
3318
  angle: _nullishCoalesce(g.angle, () => ( 90)),
@@ -3802,52 +3324,52 @@ function normalizeShapePaint(v, path = "paint") {
3802
3324
  try {
3803
3325
  _chunkHGTDMKNEcjs.validateEffectGradient.call(void 0, gradient, `${path}.gradient`);
3804
3326
  } catch (e) {
3805
- if (e instanceof _chunkHGTDMKNEcjs.LayerEffectError) fail2(e.message);
3327
+ if (e instanceof _chunkHGTDMKNEcjs.LayerEffectError) fail(e.message);
3806
3328
  throw e;
3807
3329
  }
3808
- if (gradient.stops.length < 1) fail2(`${path}.gradient.stops needs at least one { position, color }.`);
3330
+ if (gradient.stops.length < 1) fail(`${path}.gradient.stops needs at least one { position, color }.`);
3809
3331
  return withOpacity({ type: "gradient", gradient });
3810
3332
  }
3811
3333
  if (o.type === "pattern") {
3812
- if (typeof o.patternId !== "string" || !o.patternId) fail2(`${path}.patternId is required (a document or built-in pattern id).`);
3334
+ if (typeof o.patternId !== "string" || !o.patternId) fail(`${path}.patternId is required (a document or built-in pattern id).`);
3813
3335
  const p = { type: "pattern", patternId: o.patternId, scale: o.scale === void 0 ? 1 : requireNum(o.scale, `${path}.scale`, 0.01, 10) };
3814
3336
  if (typeof o.name === "string") p.name = o.name;
3815
3337
  if (o.angle !== void 0) p.angle = requireNum(o.angle, `${path}.angle`, -360, 360);
3816
3338
  if (o.link !== void 0) p.link = Boolean(o.link);
3817
3339
  if (o.phase !== void 0) {
3818
3340
  const ph = o.phase;
3819
- p.phase = { x: requireNum(_optionalChain([ph, 'optionalAccess', _58 => _58.x]), `${path}.phase.x`), y: requireNum(_optionalChain([ph, 'optionalAccess', _59 => _59.y]), `${path}.phase.y`) };
3341
+ p.phase = { x: requireNum(_optionalChain([ph, 'optionalAccess', _30 => _30.x]), `${path}.phase.x`), y: requireNum(_optionalChain([ph, 'optionalAccess', _31 => _31.y]), `${path}.phase.y`) };
3820
3342
  }
3821
3343
  return withOpacity(p);
3822
3344
  }
3823
- return fail2(`${path}.type must be color, gradient or pattern, got ${JSON.stringify(o.type)}.`);
3345
+ return fail(`${path}.type must be color, gradient or pattern, got ${JSON.stringify(o.type)}.`);
3824
3346
  }
3825
3347
  function normalizeShapeStroke(v, path = "stroke", base) {
3826
- if (!v || typeof v !== "object") return fail2(`${path} must be an object { width, paint, align?, cap?, join?, miterLimit?, dashes?, dashOffset? } or null.`);
3348
+ if (!v || typeof v !== "object") return fail(`${path} must be an object { width, paint, align?, cap?, join?, miterLimit?, dashes?, dashOffset? } or null.`);
3827
3349
  const o = v;
3828
3350
  const width = o.width === void 0 && base ? base.width : requireNum(o.width, `${path}.width`, 0, 1e4);
3829
3351
  const paint = o.paint === void 0 && base ? base.paint : o.paint === void 0 && o.color !== void 0 ? normalizeShapePaint(o.color, `${path}.color`) : normalizeShapePaint(o.paint, `${path}.paint`);
3830
3352
  const out = { width, paint };
3831
3353
  const pick = (k, allowed) => {
3832
- const value = o[k] === void 0 ? _optionalChain([base, 'optionalAccess', _60 => _60[k]]) : o[k];
3354
+ const value = o[k] === void 0 ? _optionalChain([base, 'optionalAccess', _32 => _32[k]]) : o[k];
3833
3355
  if (value === void 0) return;
3834
- if (!allowed.includes(value)) fail2(`${path}.${k} must be one of ${allowed.join(", ")}, got ${JSON.stringify(value)}.`);
3356
+ if (!allowed.includes(value)) fail(`${path}.${k} must be one of ${allowed.join(", ")}, got ${JSON.stringify(value)}.`);
3835
3357
  if (value !== (k === "align" ? "center" : k === "cap" ? "butt" : "miter")) out[k] = value;
3836
3358
  };
3837
3359
  pick("align", ["inside", "center", "outside"]);
3838
3360
  pick("cap", ["butt", "round", "square"]);
3839
3361
  pick("join", ["miter", "round", "bevel"]);
3840
- const miter = o.miterLimit === void 0 ? _optionalChain([base, 'optionalAccess', _61 => _61.miterLimit]) : requireNum(o.miterLimit, `${path}.miterLimit`, 1, 500);
3362
+ const miter = o.miterLimit === void 0 ? _optionalChain([base, 'optionalAccess', _33 => _33.miterLimit]) : requireNum(o.miterLimit, `${path}.miterLimit`, 1, 500);
3841
3363
  if (miter !== void 0 && miter !== DEFAULT_MITER_LIMIT) out.miterLimit = miter;
3842
- const dashes = o.dashes === void 0 ? _optionalChain([base, 'optionalAccess', _62 => _62.dashes]) : o.dashes;
3364
+ const dashes = o.dashes === void 0 ? _optionalChain([base, 'optionalAccess', _34 => _34.dashes]) : o.dashes;
3843
3365
  if (dashes !== void 0 && dashes !== null) {
3844
- if (!Array.isArray(dashes) || dashes.length > 32 || !dashes.every((d) => isNum(d) && d >= 0 && d <= 1e4)) fail2(`${path}.dashes must be at most 32 lengths 0..10000 (multiples of the width).`);
3366
+ if (!Array.isArray(dashes) || dashes.length > 32 || !dashes.every((d) => isNum(d) && d >= 0 && d <= 1e4)) fail(`${path}.dashes must be at most 32 lengths 0..10000 (multiples of the width).`);
3845
3367
  if (dashes.length) {
3846
- if (dashes.reduce((s, d) => s + d, 0) < 0.01) fail2(`${path}.dashes must add up to at least 0.01 widths.`);
3368
+ if (dashes.reduce((s, d) => s + d, 0) < 0.01) fail(`${path}.dashes must add up to at least 0.01 widths.`);
3847
3369
  out.dashes = [...dashes];
3848
3370
  }
3849
3371
  }
3850
- const offset = o.dashOffset === void 0 ? _optionalChain([base, 'optionalAccess', _63 => _63.dashOffset]) : requireNum(o.dashOffset, `${path}.dashOffset`, -1e6, 1e6);
3372
+ const offset = o.dashOffset === void 0 ? _optionalChain([base, 'optionalAccess', _35 => _35.dashOffset]) : requireNum(o.dashOffset, `${path}.dashOffset`, -1e6, 1e6);
3851
3373
  if (offset) out.dashOffset = offset;
3852
3374
  return out;
3853
3375
  }
@@ -3861,7 +3383,7 @@ function box(o, path) {
3861
3383
  }
3862
3384
  function arrowhead(v, path) {
3863
3385
  if (v === null || v === void 0 || v === false) return null;
3864
- if (typeof v !== "object") return fail2(`${path} must be { width, length, concavity? } in pixels, or null.`);
3386
+ if (typeof v !== "object") return fail(`${path} must be { width, length, concavity? } in pixels, or null.`);
3865
3387
  const o = v;
3866
3388
  const head = { width: requireNum(o.width, `${path}.width`, 0, 1e5), length: requireNum(o.length, `${path}.length`, 0, 1e5) };
3867
3389
  if (o.concavity !== void 0 && o.concavity !== 0) head.concavity = requireNum(o.concavity, `${path}.concavity`, -0.5, 0.5);
@@ -3869,13 +3391,13 @@ function arrowhead(v, path) {
3869
3391
  }
3870
3392
  function matrixArg(v, path) {
3871
3393
  if (v === void 0 || v === null) return void 0;
3872
- if (!Array.isArray(v) || v.length !== 6 || !v.every(isNum)) fail2(`${path} must be six numbers [a, b, c, d, e, f].`);
3394
+ if (!Array.isArray(v) || v.length !== 6 || !v.every(isNum)) fail(`${path} must be six numbers [a, b, c, d, e, f].`);
3873
3395
  const m = v;
3874
- if (Math.abs(m[0] * m[3] - m[1] * m[2]) < 1e-12) fail2(`${path} is singular.`);
3396
+ if (Math.abs(m[0] * m[3] - m[1] * m[2]) < 1e-12) fail(`${path} is singular.`);
3875
3397
  return _chunkEGZM52EOcjs.isIdentityMatrix.call(void 0, m) ? void 0 : [...m];
3876
3398
  }
3877
3399
  function normalizeLiveShape(v, path = "shape") {
3878
- if (!v || typeof v !== "object") return fail2(`${path} must be an object with kind ${LIVE_SHAPE_KINDS.join(", ")}.`);
3400
+ if (!v || typeof v !== "object") return fail(`${path} must be an object with kind ${LIVE_SHAPE_KINDS.join(", ")}.`);
3879
3401
  const o = v;
3880
3402
  const transform = matrixArg(o.transform, `${path}.transform`);
3881
3403
  const t = transform ? { transform } : {};
@@ -3886,7 +3408,7 @@ function normalizeLiveShape(v, path = "shape") {
3886
3408
  if (o.radii !== void 0 || o.radius !== void 0) {
3887
3409
  const r = _nullishCoalesce(o.radii, () => ( o.radius));
3888
3410
  const list2 = typeof r === "number" ? [r, r, r, r] : r;
3889
- if (!Array.isArray(list2) || list2.length !== 4 || !list2.every((x) => isNum(x) && x >= 0)) fail2(`${path}.radii must be four radii \u2265 0 [top-left, top-right, bottom-right, bottom-left] (or radius, one number).`);
3411
+ if (!Array.isArray(list2) || list2.length !== 4 || !list2.every((x) => isNum(x) && x >= 0)) fail(`${path}.radii must be four radii \u2265 0 [top-left, top-right, bottom-right, bottom-left] (or radius, one number).`);
3890
3412
  if (list2.some((x) => x > 0)) radii = [...list2];
3891
3413
  }
3892
3414
  return { kind: "rect", ...b, ...radii ? { radii } : {}, ...t };
@@ -3917,16 +3439,16 @@ function normalizeLiveShape(v, path = "shape") {
3917
3439
  const e = arrowhead(o.endArrow, `${path}.endArrow`);
3918
3440
  if (s) line.startArrow = s;
3919
3441
  if (e) line.endArrow = e;
3920
- if (line.x1 === line.x2 && line.y1 === line.y2) fail2(`${path}: the line's two ends are the same point.`);
3442
+ if (line.x1 === line.x2 && line.y1 === line.y2) fail(`${path}: the line's two ends are the same point.`);
3921
3443
  return line;
3922
3444
  }
3923
3445
  default:
3924
- return fail2(`${path}.kind must be one of ${LIVE_SHAPE_KINDS.join(", ")}, got ${JSON.stringify(o.kind)}.`);
3446
+ return fail(`${path}.kind must be one of ${LIVE_SHAPE_KINDS.join(", ")}, got ${JSON.stringify(o.kind)}.`);
3925
3447
  }
3926
3448
  }
3927
3449
  function point(v, path) {
3928
3450
  const p = v;
3929
- if (!p || typeof p !== "object") return fail2(`${path} must be { x, y } in document pixels.`);
3451
+ if (!p || typeof p !== "object") return fail(`${path} must be { x, y } in document pixels.`);
3930
3452
  return { x: requireNum(p.x, `${path}.x`), y: requireNum(p.y, `${path}.y`) };
3931
3453
  }
3932
3454
  function normalizeSubpaths(v, path = "subpaths") {
@@ -3935,15 +3457,15 @@ function normalizeSubpaths(v, path = "subpaths") {
3935
3457
  try {
3936
3458
  subs = _chunkEGZM52EOcjs.bezierToSubpaths.call(void 0, v);
3937
3459
  } catch (e5) {
3938
- return fail2(`${path}: could not read the SVG path data.`);
3460
+ return fail(`${path}: could not read the SVG path data.`);
3939
3461
  }
3940
- if (!subs.length || !subs.every((s) => s.anchors.every((a) => isNum(a.x) && isNum(a.y)))) fail2(`${path}: the SVG path data holds no drawable subpath.`);
3462
+ if (!subs.length || !subs.every((s) => s.anchors.every((a) => isNum(a.x) && isNum(a.y)))) fail(`${path}: the SVG path data holds no drawable subpath.`);
3941
3463
  return subs;
3942
3464
  }
3943
- if (!Array.isArray(v) || !v.length) return fail2(`${path} must be a non-empty array of { anchors: [{ x, y, in?, out? }], closed } (or SVG path data).`);
3465
+ if (!Array.isArray(v) || !v.length) return fail(`${path} must be a non-empty array of { anchors: [{ x, y, in?, out? }], closed } (or SVG path data).`);
3944
3466
  return v.map((s, i) => {
3945
3467
  const sp = s;
3946
- if (!sp || !Array.isArray(sp.anchors) || sp.anchors.length < 1) fail2(`${path}[${i}].anchors must be a non-empty array.`);
3468
+ if (!sp || !Array.isArray(sp.anchors) || sp.anchors.length < 1) fail(`${path}[${i}].anchors must be a non-empty array.`);
3947
3469
  const anchors = sp.anchors.map((a, j) => {
3948
3470
  const at = `${path}[${i}].anchors[${j}]`;
3949
3471
  const p = point(a, at);
@@ -3963,16 +3485,16 @@ function normalizeSubpaths(v, path = "subpaths") {
3963
3485
  }
3964
3486
  function requireOperation(v, path = "op") {
3965
3487
  if (v === void 0) return "combine";
3966
- if (!SHAPE_OPERATIONS.includes(v)) fail2(`${path} must be one of ${SHAPE_OPERATIONS.join(", ")}, got ${JSON.stringify(v)}.`);
3488
+ if (!SHAPE_OPERATIONS.includes(v)) fail(`${path} must be one of ${SHAPE_OPERATIONS.join(", ")}, got ${JSON.stringify(v)}.`);
3967
3489
  return v;
3968
3490
  }
3969
3491
  function requireShapeLayer(layers, id) {
3970
3492
  const layer = requireLayer(layers, id).layer;
3971
- if (layer.type !== "shape") fail2(`Layer "${layer.name || id}" is a ${layer.type} layer, not a shape layer; list_layers shows each layer's type.`);
3493
+ if (layer.type !== "shape") fail(`Layer "${layer.name || id}" is a ${layer.type} layer, not a shape layer; list_layers shows each layer's type.`);
3972
3494
  return layer;
3973
3495
  }
3974
3496
  function createShapeLayer(init, env, id = newLayerId()) {
3975
- if (!init.components.length) fail2("A shape needs at least one component.");
3497
+ if (!init.components.length) fail("A shape needs at least one component.");
3976
3498
  const layer = {
3977
3499
  type: "shape",
3978
3500
  id,
@@ -3991,7 +3513,7 @@ function createShapeLayer(init, env, id = newLayerId()) {
3991
3513
  return rerenderShape(layer, env);
3992
3514
  }
3993
3515
  function defaultShapeName(c) {
3994
- switch (_optionalChain([c, 'optionalAccess', _64 => _64.live, 'optionalAccess', _65 => _65.kind])) {
3516
+ switch (_optionalChain([c, 'optionalAccess', _36 => _36.live, 'optionalAccess', _37 => _37.kind])) {
3995
3517
  case "rect":
3996
3518
  return "Rectangle";
3997
3519
  case "ellipse":
@@ -4012,7 +3534,7 @@ function updateShapeLayer(layers, id, change, env, action = "edit it") {
4012
3534
  const patch = change(current);
4013
3535
  const next = { ...current, ...patch };
4014
3536
  if (!("annotation" in patch)) delete next.annotation;
4015
- if (!next.components.length) fail2("A shape needs at least one component; delete the layer instead.");
3537
+ if (!next.components.length) fail("A shape needs at least one component; delete the layer instead.");
4016
3538
  const rendered = rerenderShape(next, env);
4017
3539
  return { layers: _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => rendered), layer: rendered };
4018
3540
  }
@@ -4036,7 +3558,7 @@ function mergeShapeComponents(components, fillRule = "nonzero") {
4036
3558
  if (components.length < 2) return [...components];
4037
3559
  const path = shapeOutline(components, fillRule);
4038
3560
  const subpaths = _chunkEGZM52EOcjs.bezierToSubpaths.call(void 0, path);
4039
- if (!subpaths.length) fail2("The components combine to nothing (the operations remove every area), so there is nothing to merge into.");
3561
+ if (!subpaths.length) fail("The components combine to nothing (the operations remove every area), so there is nothing to merge into.");
4040
3562
  return [{ op: "combine", subpaths }];
4041
3563
  }
4042
3564
  function shapeAsPixelLayer(layer) {
@@ -4107,19 +3629,644 @@ function shapeFromAnnotation(a) {
4107
3629
  return null;
4108
3630
  }
4109
3631
  }
4110
- function annotationBlend(a, layerBlend) {
4111
- if (layerBlend !== "normal") return layerBlend;
4112
- return a.blend && _chunkCWM3CUUXcjs.isBlendMode.call(void 0, a.blend) ? a.blend : "normal";
4113
- }
4114
- function annotationOfShape(layer) {
4115
- const a = layer.annotation;
4116
- if (!a) return null;
4117
- const blend = layer.blend;
4118
- if ((_nullishCoalesce(a.blend, () => ( "normal"))) === blend) return a;
4119
- const out = { ...a };
4120
- if (blend === "normal") delete out.blend;
4121
- else out.blend = blend;
4122
- return out;
3632
+ function annotationBlend(a, layerBlend) {
3633
+ if (layerBlend !== "normal") return layerBlend;
3634
+ return a.blend && _chunkCWM3CUUXcjs.isBlendMode.call(void 0, a.blend) ? a.blend : "normal";
3635
+ }
3636
+ function annotationOfShape(layer) {
3637
+ const a = layer.annotation;
3638
+ if (!a) return null;
3639
+ const blend = layer.blend;
3640
+ if ((_nullishCoalesce(a.blend, () => ( "normal"))) === blend) return a;
3641
+ const out = { ...a };
3642
+ if (blend === "normal") delete out.blend;
3643
+ else out.blend = blend;
3644
+ return out;
3645
+ }
3646
+
3647
+ // src/image-editor/layers/vector-mask.ts
3648
+ function isActiveVectorMask(vm) {
3649
+ return Boolean(vm && vm.enabled !== false);
3650
+ }
3651
+ function vectorMaskCoverage(vm, width, height) {
3652
+ let v = componentsCoverage(vm.components, { x: 0, y: 0, width, height }, _nullishCoalesce(vm.fillRule, () => ( "nonzero")), vm.inverted === true);
3653
+ if ((_nullishCoalesce(vm.feather, () => ( 0))) > 0) v = _chunkHGTDMKNEcjs.gaussianBlur.call(void 0, v, width, height, vm.feather, "clamp");
3654
+ const density = _nullishCoalesce(vm.density, () => ( 1));
3655
+ if (density !== 1) for (let i = 0; i < v.length; i++) v[i] = 1 - density * (1 - v[i]);
3656
+ return v;
3657
+ }
3658
+ function outsideValue(vm) {
3659
+ return 1 - (_nullishCoalesce(vm.density, () => ( 1))) * (1 - (vm.inverted ? 1 : 0));
3660
+ }
3661
+ function rasterCoverage(mask, ox, oy, width, height) {
3662
+ const bytes = _chunkCWM3CUUXcjs.readRegion.call(void 0, mask.surface, { x: -ox, y: -oy, width, height });
3663
+ let v = new Float32Array(width * height);
3664
+ for (let i = 0; i < v.length; i++) v[i] = bytes[i] / 255;
3665
+ if ((_nullishCoalesce(mask.feather, () => ( 0))) > 0) v = _chunkHGTDMKNEcjs.gaussianBlur.call(void 0, v, width, height, mask.feather, "clamp");
3666
+ const density = _nullishCoalesce(mask.density, () => ( 1));
3667
+ if (density !== 1) for (let i = 0; i < v.length; i++) v[i] = 1 - density * (1 - v[i]);
3668
+ return v;
3669
+ }
3670
+ var layerOffset = (layer) => layer.type === "pixel" ? layer.offset : { x: 0, y: 0 };
3671
+ function effectiveLayerMask(layer, width, height) {
3672
+ const vm = layer.vectorMask;
3673
+ const raster = layer.mask;
3674
+ if (!isActiveVectorMask(vm) || _optionalChain([raster, 'optionalAccess', _38 => _38.source]) || width < 1 || height < 1) return raster;
3675
+ const { x: ox, y: oy } = layerOffset(layer);
3676
+ const v = vectorMaskCoverage(vm, width, height);
3677
+ let outside = outsideValue(vm);
3678
+ if (raster && raster.enabled !== false) {
3679
+ const r = rasterCoverage(raster, ox, oy, width, height);
3680
+ for (let i = 0; i < v.length; i++) v[i] *= r[i];
3681
+ outside *= 1 - (_nullishCoalesce(raster.density, () => ( 1))) * (1 - raster.defaultValue / 255);
3682
+ }
3683
+ const bytes = new Uint8ClampedArray(v.length);
3684
+ for (let i = 0; i < v.length; i++) bytes[i] = Math.round(v[i] * 255);
3685
+ const defaultValue = outside >= 0.5 ? 255 : 0;
3686
+ return { surface: _chunkCWM3CUUXcjs.writeRegion.call(void 0, _chunkCWM3CUUXcjs.emptySurface.call(void 0, 1, defaultValue), { x: -ox, y: -oy, width, height }, bytes), defaultValue };
3687
+ }
3688
+ var resolved = /* @__PURE__ */ new WeakMap();
3689
+ function hasVectorMask(layers) {
3690
+ for (const l of layers) {
3691
+ if (isActiveVectorMask(l.vectorMask)) return true;
3692
+ if (l.type === "group" && hasVectorMask(l.children)) return true;
3693
+ }
3694
+ return false;
3695
+ }
3696
+ function resolveVectorMasks(layers, width, height) {
3697
+ if (!hasVectorMask(layers)) return layers;
3698
+ return layers.map((l) => resolveLayer(l, width, height));
3699
+ }
3700
+ function resolveLayer(layer, width, height) {
3701
+ let next = layer;
3702
+ if (layer.type === "group" && hasVectorMask(layer.children)) {
3703
+ const key2 = `${width}x${height}`;
3704
+ const hit2 = resolved.get(layer);
3705
+ if (_optionalChain([hit2, 'optionalAccess', _39 => _39.key]) === key2) return hit2.layer;
3706
+ next = { ...layer, children: layer.children.map((c) => resolveLayer(c, width, height)) };
3707
+ if (!isActiveVectorMask(layer.vectorMask)) {
3708
+ resolved.set(layer, { key: key2, layer: next });
3709
+ return next;
3710
+ }
3711
+ }
3712
+ if (!isActiveVectorMask(layer.vectorMask)) return layer;
3713
+ const key = `${width}x${height}:v`;
3714
+ const hit = resolved.get(layer);
3715
+ if (_optionalChain([hit, 'optionalAccess', _40 => _40.key]) === key) return hit.layer;
3716
+ const mask = effectiveLayerMask(layer, width, height);
3717
+ const out = { ...next, mask };
3718
+ delete out.vectorMask;
3719
+ if (!mask) delete out.mask;
3720
+ resolved.set(layer, { key, layer: out });
3721
+ return out;
3722
+ }
3723
+ function offsetVectorMask(vm, dx, dy) {
3724
+ if (!dx && !dy) return vm;
3725
+ return { ...vm, components: vm.components.map((c) => ({ ...c, subpaths: mapSubpaths(c.subpaths, (p) => ({ x: p.x + dx, y: p.y + dy })), ...c.live ? { live: offsetLive(c.live, dx, dy) } : {} })) };
3726
+ }
3727
+ function offsetLive(live, dx, dy) {
3728
+ if (live.kind === "line") return { ...live, x1: live.x1 + dx, y1: live.y1 + dy, x2: live.x2 + dx, y2: live.y2 + dy };
3729
+ return { ...live, x: live.x + dx, y: live.y + dy };
3730
+ }
3731
+ function transformVectorMask(vm, f, affine) {
3732
+ return { ...vm, components: transformShapeComponents(vm.components, f, affine) };
3733
+ }
3734
+ function followLayerMove(layer, dx, dy) {
3735
+ const vm = layer.vectorMask;
3736
+ if (!vm || vm.linked === false || !dx && !dy) return layer;
3737
+ return { ...layer, vectorMask: offsetVectorMask(vm, dx, dy) };
3738
+ }
3739
+ function vectorMaskBounds(vm) {
3740
+ let x0 = Infinity;
3741
+ let y0 = Infinity;
3742
+ let x1 = -Infinity;
3743
+ let y1 = -Infinity;
3744
+ for (const c of vm.components) {
3745
+ for (const sp of c.subpaths) {
3746
+ for (const a of sp.anchors) {
3747
+ for (const p of [a, a.in, a.out]) {
3748
+ if (!p) continue;
3749
+ x0 = Math.min(x0, p.x);
3750
+ y0 = Math.min(y0, p.y);
3751
+ x1 = Math.max(x1, p.x);
3752
+ y1 = Math.max(y1, p.y);
3753
+ }
3754
+ }
3755
+ }
3756
+ }
3757
+ return x0 === Infinity ? null : { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
3758
+ }
3759
+ var thumbCache = /* @__PURE__ */ new WeakMap();
3760
+ function vectorMaskThumbnail(vm, width, height, maxSide = 64) {
3761
+ const key = `${width}x${height}:${maxSide}`;
3762
+ const hit = thumbCache.get(vm);
3763
+ if (_optionalChain([hit, 'optionalAccess', _41 => _41.key]) === key) return hit.pixels;
3764
+ const k = Math.min(1, maxSide / Math.max(1, width, height));
3765
+ const tw = Math.max(1, Math.round(width * k));
3766
+ const th = Math.max(1, Math.round(height * k));
3767
+ const scaled = transformVectorMask(vm, (p) => ({ x: p.x * k, y: p.y * k }), [k, 0, 0, k, 0, 0]);
3768
+ const cov = componentsCoverage(scaled.components, { x: 0, y: 0, width: tw, height: th }, _nullishCoalesce(vm.fillRule, () => ( "nonzero")), vm.inverted === true);
3769
+ const data = new Uint8ClampedArray(tw * th * 4);
3770
+ for (let i = 0; i < cov.length; i++) {
3771
+ const v = Math.round(Math.min(1, Math.max(0, cov[i])) * 255);
3772
+ data[i * 4] = data[i * 4 + 1] = data[i * 4 + 2] = v;
3773
+ data[i * 4 + 3] = 255;
3774
+ }
3775
+ const pixels = { width: tw, height: th, data };
3776
+ thumbCache.set(vm, { key, pixels });
3777
+ return pixels;
3778
+ }
3779
+
3780
+ // src/image-editor/layers/ops.ts
3781
+ var LayerOperationError = class extends Error {
3782
+
3783
+ constructor(message, userMessage) {
3784
+ super(message);
3785
+ this.name = "LayerOperationError";
3786
+ if (userMessage) this.userMessage = userMessage;
3787
+ }
3788
+ };
3789
+ function userErrorMessage(err) {
3790
+ if (err instanceof LayerOperationError && err.userMessage) return err.userMessage;
3791
+ return err instanceof Error ? err.message : String(err);
3792
+ }
3793
+ function isPaintableLayer(layer) {
3794
+ return layer.type === "pixel" && layer.visible && !_chunkHGTDMKNEcjs.isLayerLocked.call(void 0, layer, "pixels");
3795
+ }
3796
+ function defaultActiveLayerId(layers) {
3797
+ const pixels = _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).filter((l) => l.type === "pixel");
3798
+ for (let i = pixels.length - 1; i >= 0; i--) if (isPaintableLayer(pixels[i])) return pixels[i].id;
3799
+ return _nullishCoalesce(_optionalChain([pixels, 'access', _42 => _42[pixels.length - 1], 'optionalAccess', _43 => _43.id]), () => ( null));
3800
+ }
3801
+ function activeLayerAfterRemoval(prev, next, removedId) {
3802
+ const before = _chunkHGTDMKNEcjs.flattenLayers.call(void 0, prev);
3803
+ const at = before.findIndex((l) => l.id === removedId);
3804
+ for (let i = at - 1; i >= 0; i--) {
3805
+ const loc = _chunkHGTDMKNEcjs.findLayer.call(void 0, next, before[i].id);
3806
+ if (loc && isPaintableLayer(loc.layer)) return loc.layer.id;
3807
+ }
3808
+ return defaultActiveLayerId(next);
3809
+ }
3810
+ var fail2 = (message) => {
3811
+ throw new LayerOperationError(message);
3812
+ };
3813
+ function requireLayer(layers, id) {
3814
+ const loc = _chunkHGTDMKNEcjs.findLayer.call(void 0, layers, id);
3815
+ if (!loc) {
3816
+ const ids = _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).map((l) => l.id);
3817
+ fail2(`Unknown layer "${id}". ${ids.length ? `Layers: ${ids.join(", ")}.` : "The document has no layers."} Call list_layers for ids.`);
3818
+ }
3819
+ return loc;
3820
+ }
3821
+ function requireUnlocked(layer, what, action) {
3822
+ if (_chunkHGTDMKNEcjs.isLayerLocked.call(void 0, layer, "all")) fail2(`Layer "${layer.name || layer.id}" is locked (all); unlock it before you ${action}.`);
3823
+ if (what !== "all" && _chunkHGTDMKNEcjs.isLayerLocked.call(void 0, layer, what)) fail2(`Layer "${layer.name || layer.id}" has its ${what} locked; unlock it before you ${action}.`);
3824
+ }
3825
+ function placeLayer(layers, layer, placement = {}, defaultIndex) {
3826
+ const given = [placement.aboveId, placement.belowId, placement.parentId].filter((v) => v !== void 0).length;
3827
+ if (given > 1) fail2("Give only one of aboveId, belowId and parentId.");
3828
+ if (placement.aboveId || placement.belowId) {
3829
+ const ref = requireLayer(layers, _nullishCoalesce(placement.aboveId, () => ( placement.belowId)));
3830
+ return _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, layer, _nullishCoalesce(_optionalChain([ref, 'access', _44 => _44.parent, 'optionalAccess', _45 => _45.id]), () => ( null)), ref.index + (placement.aboveId ? 1 : 0));
3831
+ }
3832
+ if (placement.parentId) {
3833
+ const ref = requireLayer(layers, placement.parentId);
3834
+ if (ref.layer.type !== "group") fail2(`Layer "${placement.parentId}" is not a group; parentId must be a group id.`);
3835
+ return _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, layer, ref.layer.id, placement.index);
3836
+ }
3837
+ return _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, layer, null, _nullishCoalesce(placement.index, () => ( defaultIndex)));
3838
+ }
3839
+ function removeLayer(layers, id) {
3840
+ const loc = requireLayer(layers, id);
3841
+ requireUnlocked(loc.layer, "all", "delete it");
3842
+ return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => null);
3843
+ }
3844
+ function moveLayer(layers, id, placement) {
3845
+ const loc = requireLayer(layers, id);
3846
+ requireUnlocked(loc.layer, "all", "move it");
3847
+ const target = _nullishCoalesce(_nullishCoalesce(placement.aboveId, () => ( placement.belowId)), () => ( placement.parentId));
3848
+ if (target === id) fail2("A layer cannot be placed relative to itself.");
3849
+ if (target && loc.layer.type === "group" && _chunkHGTDMKNEcjs.flattenLayers.call(void 0, loc.layer.children).some((l) => l.id === target)) {
3850
+ fail2(`Group "${id}" cannot be moved into its own child "${target}".`);
3851
+ }
3852
+ if (target) requireLayer(layers, target);
3853
+ if (!target && placement.index === void 0) fail2("Give aboveId, belowId, parentId or index.");
3854
+ const without = _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => null);
3855
+ return placeLayer(without, loc.layer, placement);
3856
+ }
3857
+ function withNewIds(layer) {
3858
+ const next = { ...layer, id: newLayerId(layer.type === "adjustment" ? "adj" : layer.type) };
3859
+ if (next.type === "group") next.children = next.children.map(withNewIds);
3860
+ if (next.type === "annotation") next.annotation = { ...next.annotation, id: next.id };
3861
+ if (next.type === "shape" || next.type === "type") delete next.annotation;
3862
+ if (next.type === "smart" && _optionalChain([next, 'access', _46 => _46.psd, 'optionalAccess', _47 => _47.placed])) {
3863
+ next.psd = { ...next.psd };
3864
+ delete next.psd.placed;
3865
+ }
3866
+ return next;
3867
+ }
3868
+ function duplicateLayer(layers, id, name) {
3869
+ const loc = requireLayer(layers, id);
3870
+ const copy = withNewIds(loc.layer);
3871
+ copy.name = _nullishCoalesce(name, () => ( `${loc.layer.name || "Layer"} copy`));
3872
+ delete copy.locks;
3873
+ return { layers: _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, copy, _nullishCoalesce(_optionalChain([loc, 'access', _48 => _48.parent, 'optionalAccess', _49 => _49.id]), () => ( null)), loc.index + 1), id: copy.id };
3874
+ }
3875
+ function setLayerProperties(layers, id, props) {
3876
+ const loc = requireLayer(layers, id);
3877
+ const layer = loc.layer;
3878
+ const onlyUnlocking = Object.keys(props).every((k) => k === "locks" || k === "visible" || k === "collapsed");
3879
+ if (!onlyUnlocking) requireUnlocked(layer, "all", "change its properties");
3880
+ const next = { ...layer };
3881
+ if (props.name !== void 0) {
3882
+ if (typeof props.name !== "string" || !props.name.trim()) fail2("name must be a non-empty string.");
3883
+ next.name = props.name.trim();
3884
+ }
3885
+ if (props.visible !== void 0) next.visible = Boolean(props.visible);
3886
+ if (props.opacity !== void 0) {
3887
+ if (!(typeof props.opacity === "number" && props.opacity >= 0 && props.opacity <= 1)) fail2("opacity must be a number from 0 to 1.");
3888
+ next.opacity = props.opacity;
3889
+ }
3890
+ if (props.fillOpacity !== void 0) {
3891
+ if (layer.type !== "pixel" && layer.type !== "smart" && layer.type !== "shape" && layer.type !== "type") fail2(`fillOpacity applies to pixel, shape, type and smart object layers; "${id}" is a ${layer.type} layer.`);
3892
+ if (!(typeof props.fillOpacity === "number" && props.fillOpacity >= 0 && props.fillOpacity <= 1)) fail2("fillOpacity must be a number from 0 to 1.");
3893
+ const p = next;
3894
+ if (props.fillOpacity === 1) delete p.fillOpacity;
3895
+ else p.fillOpacity = props.fillOpacity;
3896
+ }
3897
+ if (props.blend !== void 0) {
3898
+ if (props.blend === "pass-through") {
3899
+ if (layer.type !== "group") fail2("pass-through is only for groups.");
3900
+ } else if (!_chunkCWM3CUUXcjs.isBlendMode.call(void 0, props.blend)) fail2(`Unknown blend mode "${props.blend}".`);
3901
+ next.blend = props.blend;
3902
+ }
3903
+ if (props.clipped !== void 0) {
3904
+ if (props.clipped && loc.index === 0) fail2("The bottom layer of a group or the stack has nothing below to clip to.");
3905
+ if (props.clipped) next.clipped = true;
3906
+ else delete next.clipped;
3907
+ }
3908
+ if (props.locks !== void 0) {
3909
+ const locks = {};
3910
+ for (const k of ["pixels", "transparency", "position", "all"]) if (props.locks[k]) locks[k] = true;
3911
+ if (Object.keys(locks).length) next.locks = locks;
3912
+ else delete next.locks;
3913
+ }
3914
+ if (props.collapsed !== void 0) {
3915
+ if (layer.type !== "group") fail2("collapsed applies to groups.");
3916
+ const g = next;
3917
+ if (props.collapsed) g.collapsed = true;
3918
+ else delete g.collapsed;
3919
+ }
3920
+ return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => next);
3921
+ }
3922
+ function groupLayers(layers, ids, name = "Group") {
3923
+ if (!ids.length) fail2("Give at least one layer id to group.");
3924
+ const locs = ids.map((id) => requireLayer(layers, id));
3925
+ const parent = _nullishCoalesce(_optionalChain([locs, 'access', _50 => _50[0], 'access', _51 => _51.parent, 'optionalAccess', _52 => _52.id]), () => ( null));
3926
+ if (locs.some((l) => (_nullishCoalesce(_optionalChain([l, 'access', _53 => _53.parent, 'optionalAccess', _54 => _54.id]), () => ( null))) !== parent)) fail2("Layers to group must share one parent; move them next to each other first.");
3927
+ for (const l of locs) requireUnlocked(l.layer, "all", "group it");
3928
+ const ordered = [...new Set(locs)].sort((a, b) => a.index - b.index);
3929
+ const top = ordered[ordered.length - 1].index;
3930
+ const below = ordered.filter((l) => l.index < top).length;
3931
+ const group = {
3932
+ type: "group",
3933
+ id: newLayerId("group"),
3934
+ name,
3935
+ visible: true,
3936
+ opacity: 1,
3937
+ blend: "pass-through",
3938
+ children: ordered.map((l) => {
3939
+ const c = { ...l.layer };
3940
+ return c;
3941
+ })
3942
+ };
3943
+ if (_optionalChain([group, 'access', _55 => _55.children, 'access', _56 => _56[0], 'optionalAccess', _57 => _57.clipped])) {
3944
+ const c = { ...group.children[0] };
3945
+ delete c.clipped;
3946
+ group.children[0] = c;
3947
+ }
3948
+ let out = layers;
3949
+ for (const l of ordered) out = _chunkHGTDMKNEcjs.mapLayer.call(void 0, out, l.layer.id, () => null);
3950
+ return { layers: _chunkHGTDMKNEcjs.insertLayer.call(void 0, out, group, parent, top - below), id: group.id };
3951
+ }
3952
+ function ungroupLayer(layers, id) {
3953
+ const loc = requireLayer(layers, id);
3954
+ if (loc.layer.type !== "group") fail2(`Layer "${id}" is not a group.`);
3955
+ requireUnlocked(loc.layer, "all", "ungroup it");
3956
+ const group = loc.layer;
3957
+ let out = _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => null);
3958
+ group.children.forEach((c, i) => {
3959
+ out = _chunkHGTDMKNEcjs.insertLayer.call(void 0, out, c, _nullishCoalesce(_optionalChain([loc, 'access', _58 => _58.parent, 'optionalAccess', _59 => _59.id]), () => ( null)), loc.index + i);
3960
+ });
3961
+ return { layers: out, ids: group.children.map((c) => c.id) };
3962
+ }
3963
+ function offsetLayer(layers, id, offset) {
3964
+ const loc = requireLayer(layers, id);
3965
+ if (loc.layer.type !== "pixel") fail2(`Only pixel layers move; "${id}" is a ${loc.layer.type} layer.`);
3966
+ requireUnlocked(loc.layer, "position", "move it");
3967
+ if (!Number.isFinite(offset.x) || !Number.isFinite(offset.y)) fail2("x and y must be numbers.");
3968
+ const layer = loc.layer;
3969
+ const next = { ...layer, offset: { x: Math.round(offset.x), y: Math.round(offset.y) } };
3970
+ const mask = layer.mask;
3971
+ if (mask && mask.linked === false && !mask.source) {
3972
+ next.mask = { ...mask, surface: _chunkCWM3CUUXcjs.translateSurface.call(void 0, mask.surface, layer.offset.x - next.offset.x, layer.offset.y - next.offset.y) };
3973
+ }
3974
+ return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => followLayerMove(next, next.offset.x - layer.offset.x, next.offset.y - layer.offset.y));
3975
+ }
3976
+ function setLayerMask(layers, id, mask) {
3977
+ const loc = requireLayer(layers, id);
3978
+ requireUnlocked(loc.layer, "all", "change its mask");
3979
+ return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, (l) => {
3980
+ const next = { ...l };
3981
+ if (mask) next.mask = mask;
3982
+ else delete next.mask;
3983
+ return next;
3984
+ });
3985
+ }
3986
+ var DEVELOP_FIELDS = ["brightness", "contrast", "saturation", "exposure", "temperature", "tint"];
3987
+ function normalizeFilter(raw, id = newLayerId("flt")) {
3988
+ const enabled = raw.enabled !== false;
3989
+ if (raw.kind === "blur") {
3990
+ const r = raw.radius;
3991
+ if (r !== void 0 && !(typeof r === "number" && r >= 0 && r <= 50)) fail2("blur radius must be a number from 0 to 50 px.");
3992
+ return { id, kind: "blur", enabled, radius: typeof r === "number" ? r : 2 };
3993
+ }
3994
+ if (raw.kind !== "develop") fail2(`Unknown filter kind "${raw.kind}". Use develop or blur.`);
3995
+ const out = { id, kind: "develop", enabled, brightness: 0, contrast: 0, saturation: 0, exposure: 0, temperature: 0, tint: 0, process: 2 };
3996
+ for (const k of DEVELOP_FIELDS) {
3997
+ const v = raw[k];
3998
+ if (v === void 0) continue;
3999
+ if (!(typeof v === "number" && v >= -100 && v <= 100)) fail2(`${k} must be a number from -100 to 100.`);
4000
+ out[k] = v;
4001
+ }
4002
+ const p = raw.process;
4003
+ if (p !== void 0) {
4004
+ if (p !== 1 && p !== 2) fail2("process must be 1 or 2.");
4005
+ out.process = p;
4006
+ }
4007
+ return out;
4008
+ }
4009
+ function requirePixelLayer(layers, id) {
4010
+ const loc = requireLayer(layers, id);
4011
+ if (loc.layer.type !== "pixel") fail2(`Filters belong to pixel layers; "${id}" is a ${loc.layer.type} layer.`);
4012
+ requireUnlocked(loc.layer, "all", "change its filters");
4013
+ return loc.layer;
4014
+ }
4015
+ function addLayerFilter(layers, id, filter) {
4016
+ const layer = requirePixelLayer(layers, id);
4017
+ if (_optionalChain([layer, 'access', _60 => _60.filters, 'optionalAccess', _61 => _61.some, 'call', _62 => _62((f) => f.kind === filter.kind)])) fail2(`Layer "${id}" already has a ${filter.kind} filter; change it with update_layer_filter.`);
4018
+ return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => ({ ...layer, filters: [..._nullishCoalesce(layer.filters, () => ( [])), filter] }));
4019
+ }
4020
+ function updateLayerFilter(layers, id, filterId, changes) {
4021
+ const layer = requirePixelLayer(layers, id);
4022
+ const i = (_nullishCoalesce(layer.filters, () => ( []))).findIndex((f) => f.id === filterId);
4023
+ if (i === -1) fail2(`Layer "${id}" has no filter "${filterId}". Filters: ${(_nullishCoalesce(layer.filters, () => ( []))).map((f) => f.id).join(", ") || "none"}.`);
4024
+ const current = layer.filters[i];
4025
+ if ("kind" in changes && changes.kind !== current.kind) fail2("A filter kind cannot change; remove it and add another.");
4026
+ const merged2 = normalizeFilter({ ...current, ...changes, kind: current.kind }, current.id);
4027
+ const filters = [...layer.filters];
4028
+ filters[i] = merged2;
4029
+ return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => ({ ...layer, filters }));
4030
+ }
4031
+ function removeLayerFilter(layers, id, filterId) {
4032
+ const layer = requirePixelLayer(layers, id);
4033
+ if (!(_nullishCoalesce(layer.filters, () => ( []))).some((f) => f.id === filterId)) fail2(`Layer "${id}" has no filter "${filterId}".`);
4034
+ const filters = layer.filters.filter((f) => f.id !== filterId);
4035
+ const next = { ...layer };
4036
+ if (filters.length) next.filters = filters;
4037
+ else delete next.filters;
4038
+ return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => next);
4039
+ }
4040
+ function requireEffectLayer(layers, id, action) {
4041
+ const layer = requireLayer(layers, id).layer;
4042
+ if (layer.type === "adjustment") fail2(`Layer "${layer.name || id}" is an adjustment layer; effects go on pixel, annotation and group layers.`);
4043
+ requireUnlocked(layer, "all", action);
4044
+ return layer;
4045
+ }
4046
+ function layerEffectsOf(layer) {
4047
+ return _nullishCoalesce(layer.effects, () => ( { enabled: true, items: [] }));
4048
+ }
4049
+ function guard(fn) {
4050
+ try {
4051
+ return fn();
4052
+ } catch (e) {
4053
+ if (e instanceof _chunkHGTDMKNEcjs.LayerEffectError) fail2(e.message);
4054
+ throw e;
4055
+ }
4056
+ }
4057
+ function setLayerEffects(layers, id, effects) {
4058
+ const layer = requireEffectLayer(layers, id, "change its effects");
4059
+ const next = { ...layer };
4060
+ if (effects && (effects.items.length || effects.psd || effects.scale !== void 0 || !effects.enabled)) {
4061
+ guard(() => _chunkHGTDMKNEcjs.validateLayerEffects.call(void 0, effects));
4062
+ next.effects = effects;
4063
+ } else delete next.effects;
4064
+ return _chunkHGTDMKNEcjs.mapLayer.call(void 0, layers, id, () => next);
4065
+ }
4066
+ function addLayerEffect(layers, id, kind, params = {}, index) {
4067
+ if (!_chunkHGTDMKNEcjs.isLayerEffectKind.call(void 0, kind)) fail2(`Unknown effect kind "${String(kind)}". Kinds: ${_chunkHGTDMKNEcjs.LAYER_EFFECT_KINDS.join(", ")}.`);
4068
+ const layer = requireEffectLayer(layers, id, "add effects");
4069
+ const current = layerEffectsOf(layer);
4070
+ const ids = new Set(current.items.map((e) => e.id));
4071
+ let effectId = _chunkHGTDMKNEcjs.newEffectId.call(void 0, );
4072
+ while (ids.has(effectId)) effectId = _chunkHGTDMKNEcjs.newEffectId.call(void 0, );
4073
+ const { id: _ignored, kind: _kind, ...rest } = params;
4074
+ const effect = guard(() => _chunkHGTDMKNEcjs.mergeLayerEffect.call(void 0, _chunkHGTDMKNEcjs.defaultLayerEffect.call(void 0, kind, effectId), rest));
4075
+ const items = [...current.items];
4076
+ const at = index === void 0 ? items.length : Math.max(0, Math.min(items.length, Math.floor(index)));
4077
+ items.splice(at, 0, effect);
4078
+ return { layers: setLayerEffects(layers, id, { ...current, items }), effect };
4079
+ }
4080
+ function requireEffect(layer, effectId) {
4081
+ const items = _nullishCoalesce(_optionalChain([layer, 'access', _63 => _63.effects, 'optionalAccess', _64 => _64.items]), () => ( []));
4082
+ const i = items.findIndex((e) => e.id === effectId);
4083
+ if (i === -1) fail2(`Layer "${layer.name || layer.id}" has no effect "${effectId}". Effects: ${items.map((e) => `${e.id} (${e.kind})`).join(", ") || "none"}; call list_layer_effects.`);
4084
+ return i;
4085
+ }
4086
+ function updateLayerEffect(layers, id, effectId, changes) {
4087
+ const layer = requireEffectLayer(layers, id, "change its effects");
4088
+ const i = requireEffect(layer, effectId);
4089
+ const current = layer.effects;
4090
+ const items = [...current.items];
4091
+ items[i] = guard(() => _chunkHGTDMKNEcjs.mergeLayerEffect.call(void 0, items[i], changes));
4092
+ return setLayerEffects(layers, id, { ...current, items });
4093
+ }
4094
+ function removeLayerEffect(layers, id, effectId) {
4095
+ const layer = requireEffectLayer(layers, id, "change its effects");
4096
+ requireEffect(layer, effectId);
4097
+ const current = layer.effects;
4098
+ return setLayerEffects(layers, id, { ...current, items: current.items.filter((e) => e.id !== effectId) });
4099
+ }
4100
+ function setLayerEffectsEnabled(layers, id, enabled, scale) {
4101
+ const layer = requireEffectLayer(layers, id, "change its effects");
4102
+ if (scale !== void 0 && !(Number.isFinite(scale) && scale >= 0.01 && scale <= 10)) fail2(`scale must be from 0.01 to 10 (1 = 100 %), got ${scale}.`);
4103
+ const current = layerEffectsOf(layer);
4104
+ const next = { ...current, enabled };
4105
+ if (scale !== void 0) {
4106
+ if (scale === 1) delete next.scale;
4107
+ else next.scale = scale;
4108
+ }
4109
+ return setLayerEffects(layers, id, next);
4110
+ }
4111
+ function parseBlend(value, allowPassThrough = false) {
4112
+ if (value === void 0) return void 0;
4113
+ if (value === "pass-through" && allowPassThrough) return value;
4114
+ if (!_chunkCWM3CUUXcjs.isBlendMode.call(void 0, value)) fail2(`Unknown blend mode "${String(value)}".`);
4115
+ return value;
4116
+ }
4117
+ function unionRect(a, b) {
4118
+ if (!a) return b;
4119
+ if (!b) return a;
4120
+ const x = Math.min(a.x, b.x);
4121
+ const y = Math.min(a.y, b.y);
4122
+ return { x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
4123
+ }
4124
+
4125
+ // src/image-editor/layers/compositor.ts
4126
+ var legacyViewCache = /* @__PURE__ */ new WeakMap();
4127
+ function adjustmentNodeAsLayer(node) {
4128
+ let view = legacyViewCache.get(node);
4129
+ if (!view) {
4130
+ view = {
4131
+ id: node.id,
4132
+ kind: node.kind,
4133
+ enabled: node.visible,
4134
+ opacity: node.opacity,
4135
+ blend: node.blend,
4136
+ params: node.params
4137
+ };
4138
+ legacyViewCache.set(node, view);
4139
+ }
4140
+ return view;
4141
+ }
4142
+ function developAdjustments(f) {
4143
+ return {
4144
+ brightness: f.brightness,
4145
+ contrast: f.contrast,
4146
+ saturation: f.saturation,
4147
+ exposure: f.exposure,
4148
+ temperature: f.temperature,
4149
+ tint: _nullishCoalesce(f.tint, () => ( 0)),
4150
+ blur: 0,
4151
+ opacity: 1,
4152
+ process: f.process
4153
+ };
4154
+ }
4155
+ function applyPixelFilters(data, filters) {
4156
+ for (const f of filters) {
4157
+ if (!isActiveFilter(f) || f.kind !== "develop") continue;
4158
+ const adj = developAdjustments(f);
4159
+ if (normalizeProcessVersion(adj.process) === LATEST_PROCESS_VERSION) applyProcess2Adjustments({ data }, adj);
4160
+ else applyLegacyAdjustments({ data }, adj);
4161
+ }
4162
+ }
4163
+ function depthMaskAlpha(depth, options) {
4164
+ const { mode, depthRange, softness, invert } = options;
4165
+ let v = invert ? 255 - depth : depth;
4166
+ const soft = Math.max(1, softness || 10);
4167
+ const [lo, hi] = depthRange;
4168
+ if (mode === "threshold") {
4169
+ if (v >= hi + soft) return 0;
4170
+ if (v > hi) return Math.round((hi + soft - v) / soft * 255);
4171
+ if (v >= lo) return 255;
4172
+ if (v < lo - soft) return 0;
4173
+ return Math.round((v - (lo - soft)) / soft * 255);
4174
+ }
4175
+ v += lo;
4176
+ return v < 0 ? 0 : v > 255 ? 255 : v;
4177
+ }
4178
+ function runLayerFilters(data, width, height, filters) {
4179
+ for (const f of filters) {
4180
+ if (!isActiveFilter(f)) continue;
4181
+ if (f.kind === "develop") applyPixelFilters(data, [f]);
4182
+ else if (f.kind === "blur") applyBoxBlur({ width, height, data }, Math.min(Math.round(f.radius), 40));
4183
+ }
4184
+ }
4185
+ function runLayerFiltersFloat(data, width, height, filters, linear) {
4186
+ for (const f of filters) {
4187
+ if (!isActiveFilter(f)) continue;
4188
+ if (f.kind === "blur") applyBoxBlurFloat({ width, height, data }, Math.min(Math.round(f.radius), 40));
4189
+ else if (f.kind === "develop") {
4190
+ const adj = developAdjustments(f);
4191
+ if (normalizeProcessVersion(adj.process) === LATEST_PROCESS_VERSION) applyProcess2Float(data, adj, linear);
4192
+ else applyLegacyFloat(data, adj, linear);
4193
+ }
4194
+ }
4195
+ }
4196
+ function filterReach(filters) {
4197
+ let r = 0;
4198
+ for (const f of filters) if (isActiveFilter(f) && f.kind === "blur") r += Math.min(Math.round(f.radius), 40);
4199
+ return r;
4200
+ }
4201
+ var filterSpecCache = /* @__PURE__ */ new WeakMap();
4202
+ function pixelFilterSpec(layer) {
4203
+ const list2 = layer.filters;
4204
+ if (!_optionalChain([list2, 'optionalAccess', _65 => _65.length])) return null;
4205
+ if (filterSpecCache.has(list2)) return filterSpecCache.get(list2);
4206
+ const filters = list2.filter(isActiveFilter);
4207
+ let spec = null;
4208
+ if (filters.length) {
4209
+ const spatial = filters.some(isSpatialFilter);
4210
+ spec = {
4211
+ key: JSON.stringify(filters),
4212
+ spatial,
4213
+ apply: (data, width, height) => runLayerFilters(data, width, height, filters)
4214
+ };
4215
+ }
4216
+ filterSpecCache.set(list2, spec);
4217
+ return spec;
4218
+ }
4219
+ var PHOTO_PROFILE = {
4220
+ isFilterLayer: (l) => l.type === "adjustment",
4221
+ applyFilterRun: (layers, acc, _r, masks) => {
4222
+ const views = layers.map(adjustmentNodeAsLayer);
4223
+ applyAdjustmentLayers({ data: acc }, views, masks);
4224
+ },
4225
+ contentTile: (l, r, sources) => l.type === "annotation" ? _nullishCoalesce(_optionalChain([sources, 'access', _66 => _66.rasterizeAnnotation, 'optionalCall', _67 => _67(l.annotation, r)]), () => ( null)) : null,
4226
+ /** Annotation layers draw with their annotation's blend mode unless the layer sets one. */
4227
+ contentBlend: (l) => l.type === "annotation" && l.blend === "normal" && l.annotation.blend ? l.annotation.blend : l.blend,
4228
+ layerKey: (l) => l.type === "pixel" ? [_nullishCoalesce(l.filters, () => ( null)), _nullishCoalesce(l.source, () => ( null))] : l.type === "adjustment" ? [l.kind, l.params] : l.type === "annotation" ? l.annotation : void 0,
4229
+ pixelFilters: (l) => l.type === "pixel" ? pixelFilterSpec(l) : null,
4230
+ /**
4231
+ * A smart object draws its rendered pixels (contents → placement → smart filters) like a pixel
4232
+ * layer, and a shape layer the pixels rendered from its paths.
4233
+ */
4234
+ isPixelLike: (l) => l.type === "smart" || l.type === "shape" || l.type === "type",
4235
+ maskSourcePlane: (source, W, H, sources) => {
4236
+ const opts = source;
4237
+ const depth = _nullishCoalesce(_optionalChain([sources, 'access', _68 => _68.depthMap, 'optionalCall', _69 => _69(opts)]), () => ( null));
4238
+ if (!depth || depth.width !== W || depth.height !== H) return null;
4239
+ const v = new Float32Array(W * H);
4240
+ for (let i = 0; i < v.length; i++) v[i] = depthMaskAlpha(depth.data[i * 4], opts) / 255;
4241
+ return v;
4242
+ }
4243
+ };
4244
+ var LayerCompositor = class extends _chunkHGTDMKNEcjs.RasterCompositor {
4245
+ constructor(options = {}) {
4246
+ super(PHOTO_PROFILE, options);
4247
+ }
4248
+ // Vector masks reach the engine as part of each layer's raster mask (see `resolveVectorMasks`).
4249
+ composite(layers, rect, sources, options) {
4250
+ return super.composite(resolveVectorMasks(layers, sources.width, sources.height), rect, sources, options);
4251
+ }
4252
+ compositeTiles(layers, rect, sources, onTile, options) {
4253
+ super.compositeTiles(resolveVectorMasks(layers, sources.width, sources.height), rect, sources, onTile, options);
4254
+ }
4255
+ tile(layers, tx, ty, sources) {
4256
+ return super.tile(resolveVectorMasks(layers, sources.width, sources.height), tx, ty, sources);
4257
+ }
4258
+ };
4259
+ function compositeDeep(layers, rect, sources, depth) {
4260
+ const deep = new (0, _chunkHGTDMKNEcjs.DeepCompositor)(new LayerCompositor(), PHOTO_PROFILE, {
4261
+ applyFilterRunDeep: (run, acc, _r, masks) => applyAdjustmentLayersFloat(acc, run.map(adjustmentNodeAsLayer), masks),
4262
+ pixelFiltersDeep: (l) => {
4263
+ if (l.type !== "pixel") return null;
4264
+ const filters = (_nullishCoalesce(l.filters, () => ( []))).filter(isActiveFilter);
4265
+ if (!filters.length) return null;
4266
+ return { reach: filterReach(filters), apply: (data, width, height, linear) => runLayerFiltersFloat(data, width, height, filters, linear) };
4267
+ }
4268
+ }, depth);
4269
+ return deep.composite(resolveVectorMasks(layers, sources.width, sources.height), rect, sources);
4123
4270
  }
4124
4271
 
4125
4272
  // src/image-editor/layers/text.ts
@@ -4186,7 +4333,7 @@ function textOutlines(layer, shaper) {
4186
4333
  }
4187
4334
  var rgbOf = (hex) => {
4188
4335
  const c = _chunkA2IS7EHEcjs.parseCssColor.call(void 0, hex);
4189
- const h = (_nullishCoalesce(_optionalChain([c, 'optionalAccess', _66 => _66.hex]), () => ( "#000000"))).slice(1);
4336
+ const h = (_nullishCoalesce(_optionalChain([c, 'optionalAccess', _70 => _70.hex]), () => ( "#000000"))).slice(1);
4190
4337
  return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];
4191
4338
  };
4192
4339
  function renderOutlines(layer, shaper, region) {
@@ -4402,7 +4549,7 @@ function createTypeLayer(init, env, id = newLayerId(), lenient = false) {
4402
4549
  surface: _chunkCWM3CUUXcjs.emptySurface.call(void 0, 4),
4403
4550
  offset: { x: 0, y: 0 }
4404
4551
  };
4405
- if (!layer.runs.length) layer.runs = [{ length: 0, style: _nullishCoalesce(_optionalChain([init, 'access', _67 => _67.runs, 'access', _68 => _68[0], 'optionalAccess', _69 => _69.style]), () => ( _chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE)) }];
4552
+ if (!layer.runs.length) layer.runs = [{ length: 0, style: _nullishCoalesce(_optionalChain([init, 'access', _71 => _71.runs, 'access', _72 => _72[0], 'optionalAccess', _73 => _73.style]), () => ( _chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE)) }];
4406
4553
  if (init.transform && !_chunkEGZM52EOcjs.isIdentityMatrix.call(void 0, init.transform)) layer.transform = init.transform;
4407
4554
  if (lenient && !renderText(layer, env)) return { ...layer, rendering: "stored" };
4408
4555
  return rerenderText(layer, env);
@@ -4413,7 +4560,7 @@ function updateTypeLayer(layers, id, change, env, action = "edit it") {
4413
4560
  const patch = change(current);
4414
4561
  const next = { ...current, ...patch };
4415
4562
  if (!("annotation" in patch)) delete next.annotation;
4416
- if ("text" in patch || "runs" in patch) next.runs = _chunkEGZM52EOcjs.fitRuns.call(void 0, next.runs, next.text.length, _nullishCoalesce(_optionalChain([current, 'access', _70 => _70.runs, 'access', _71 => _71[0], 'optionalAccess', _72 => _72.style]), () => ( _chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE)));
4563
+ if ("text" in patch || "runs" in patch) next.runs = _chunkEGZM52EOcjs.fitRuns.call(void 0, next.runs, next.text.length, _nullishCoalesce(_optionalChain([current, 'access', _74 => _74.runs, 'access', _75 => _75[0], 'optionalAccess', _76 => _76.style]), () => ( _chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE)));
4417
4564
  if (!next.runs.length) next.runs = [{ length: 0, style: _chunkEGZM52EOcjs.styleAt.call(void 0, current.runs, 0, _chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE) }];
4418
4565
  if ("text" in patch || "paragraphs" in patch) next.paragraphs = _chunkEGZM52EOcjs.fitParagraphRuns.call(void 0, next.paragraphs, next.text);
4419
4566
  const rendered = rerenderText(next, env);
@@ -4700,7 +4847,7 @@ function legacyView(stack, width, height, activeLayerId = null) {
4700
4847
  const { layers } = stack;
4701
4848
  const target = developTarget(layers, activeLayerId);
4702
4849
  const develop = target ? developFilter(target) : void 0;
4703
- const blur = _nullishCoalesce(_nullishCoalesce(stack.legacyOutputBlur, () => ( (target ? _optionalChain([blurFilter, 'call', _73 => _73(target), 'optionalAccess', _74 => _74.radius]) : void 0))), () => ( 0));
4850
+ const blur = _nullishCoalesce(_nullishCoalesce(stack.legacyOutputBlur, () => ( (target ? _optionalChain([blurFilter, 'call', _77 => _77(target), 'optionalAccess', _78 => _78.radius]) : void 0))), () => ( 0));
4704
4851
  const adjustments = {
4705
4852
  ...DEFAULT_ADJUSTMENTS_VALUES,
4706
4853
  ...develop ? {
@@ -4729,7 +4876,7 @@ function legacyView(stack, width, height, activeLayerId = null) {
4729
4876
  };
4730
4877
  walk(layers);
4731
4878
  if (adjNodes.length) adjustments.layers = adjNodes.map((n) => legacyAdjustmentLayer(n, width, height));
4732
- const depthSource = _optionalChain([target, 'optionalAccess', _75 => _75.mask, 'optionalAccess', _76 => _76.source]);
4879
+ const depthSource = _optionalChain([target, 'optionalAccess', _79 => _79.mask, 'optionalAccess', _80 => _80.source]);
4733
4880
  const depthMask = depthSource ? { ...depthSource, depthRange: [...depthSource.depthRange] } : { ...DEFAULT_DEPTH_MASK_VALUES, depthRange: [...DEFAULT_DEPTH_MASK_VALUES.depthRange] };
4734
4881
  return { adjustments, depthMask, annotations, exact: isLegacyShape(stack) };
4735
4882
  }
@@ -4754,7 +4901,7 @@ function isLegacyShape(stack) {
4754
4901
  let adjustments = 0;
4755
4902
  for (; i < layers.length && layers[i].type === "adjustment"; i++) {
4756
4903
  const l = layers[i];
4757
- if (l.clipped || l.locks || _optionalChain([l, 'access', _77 => _77.mask, 'optionalAccess', _78 => _78.source]) || l.effects) return false;
4904
+ if (l.clipped || l.locks || _optionalChain([l, 'access', _81 => _81.mask, 'optionalAccess', _82 => _82.source]) || l.effects) return false;
4758
4905
  adjustments++;
4759
4906
  }
4760
4907
  for (; i < layers.length; i++) {
@@ -4961,7 +5108,7 @@ function isContentsDecoded(contents) {
4961
5108
  }
4962
5109
  function requireDecoded(layer, action) {
4963
5110
  if (isContentsDecoded(layer.contents)) return;
4964
- const what = _optionalChain([layer, 'access', _79 => _79.contents, 'access', _80 => _80.file, 'optionalAccess', _81 => _81.type]) ? `a ${layer.contents.file.type.toUpperCase()} file` : "a file";
5111
+ const what = _optionalChain([layer, 'access', _83 => _83.contents, 'access', _84 => _84.file, 'optionalAccess', _85 => _85.type]) ? `a ${layer.contents.file.type.toUpperCase()} file` : "a file";
4965
5112
  fail4(
4966
5113
  `The contents of smart object "${layer.name || layer.id}" are ${what} that could not be decoded here, so it cannot ${action}. Run prepareSmartObjects() in a browser first, or rasterize it.`
4967
5114
  );
@@ -4986,7 +5133,7 @@ function contentsSurface(contents) {
4986
5133
  width: W,
4987
5134
  height: H,
4988
5135
  globalLight: doc.globalLight,
4989
- pattern: (id) => _nullishCoalesce(_optionalChain([doc, 'access', _82 => _82.patterns, 'optionalAccess', _83 => _83.find, 'call', _84 => _84((p) => p.id === id)]), () => ( null))
5136
+ pattern: (id) => _nullishCoalesce(_optionalChain([doc, 'access', _86 => _86.patterns, 'optionalAccess', _87 => _87.find, 'call', _88 => _88((p) => p.id === id)]), () => ( null))
4990
5137
  });
4991
5138
  s = _chunkCWM3CUUXcjs.surfaceFromPixels.call(void 0, { width: W, height: H, data }, 4, 0, 0);
4992
5139
  }
@@ -5021,7 +5168,7 @@ function placeContents(layer, canvas, options = {}) {
5021
5168
  const preview = Boolean(options.step && options.step > 1) || Boolean(options.clip);
5022
5169
  const key = placementKey(placement, canvas);
5023
5170
  if (!preview) {
5024
- const hit = _optionalChain([placedCache, 'access', _85 => _85.get, 'call', _86 => _86(contents), 'optionalAccess', _87 => _87.get, 'call', _88 => _88(key)]);
5171
+ const hit = _optionalChain([placedCache, 'access', _89 => _89.get, 'call', _90 => _90(contents), 'optionalAccess', _91 => _91.get, 'call', _92 => _92(key)]);
5025
5172
  if (hit) return hit;
5026
5173
  }
5027
5174
  const src = contentsSurface(contents);
@@ -5048,10 +5195,10 @@ function placeContents(layer, canvas, options = {}) {
5048
5195
  let k = 1;
5049
5196
  if (step > 1) {
5050
5197
  k = step;
5051
- let r = _optionalChain([options, 'access', _89 => _89.reduced, 'optionalAccess', _90 => _90.get, 'call', _91 => _91(k)]);
5198
+ let r = _optionalChain([options, 'access', _93 => _93.reduced, 'optionalAccess', _94 => _94.get, 'call', _95 => _95(k)]);
5052
5199
  if (!r) {
5053
5200
  r = _chunkHGTDMKNEcjs.reduceSurface.call(void 0, src, k);
5054
- _optionalChain([options, 'access', _92 => _92.reduced, 'optionalAccess', _93 => _93.set, 'call', _94 => _94(k, r)]);
5201
+ _optionalChain([options, 'access', _96 => _96.reduced, 'optionalAccess', _97 => _97.set, 'call', _98 => _98(k, r)]);
5055
5202
  }
5056
5203
  source = r;
5057
5204
  }
@@ -5084,15 +5231,15 @@ function placeContents(layer, canvas, options = {}) {
5084
5231
  return out;
5085
5232
  }
5086
5233
  function activeSmartFilters(stack) {
5087
- if (!_optionalChain([stack, 'optionalAccess', _95 => _95.enabled])) return [];
5234
+ if (!_optionalChain([stack, 'optionalAccess', _99 => _99.enabled])) return [];
5088
5235
  return stack.filters.filter((f) => f.kind !== "psd" && f.kind !== "effect" && isActiveFilter(f) && f.opacity > 0);
5089
5236
  }
5090
5237
  function activeEffectSmartFilters(stack) {
5091
- if (!_optionalChain([stack, 'optionalAccess', _96 => _96.enabled])) return [];
5238
+ if (!_optionalChain([stack, 'optionalAccess', _100 => _100.enabled])) return [];
5092
5239
  return stack.filters.filter((f) => f.kind === "effect" && f.enabled && f.opacity > 0);
5093
5240
  }
5094
5241
  function runnableSmartFilters(stack) {
5095
- if (!_optionalChain([stack, 'optionalAccess', _97 => _97.enabled])) return [];
5242
+ if (!_optionalChain([stack, 'optionalAccess', _101 => _101.enabled])) return [];
5096
5243
  return stack.filters.filter((f) => f.opacity > 0 && (f.kind === "effect" ? f.enabled : f.kind !== "psd" && isActiveFilter(f)));
5097
5244
  }
5098
5245
  function filterMaskCoverage(mask, canvas) {
@@ -5118,7 +5265,7 @@ function applySmartFilters(placed, stack, canvas) {
5118
5265
  if (!active.length || !(canvas.width > 0 && canvas.height > 0)) return placed;
5119
5266
  const W = canvas.width;
5120
5267
  const H = canvas.height;
5121
- const token = active.some((f) => f.kind === "effect") ? _nullishCoalesce(_optionalChain([canvas, 'access', _98 => _98.effects, 'optionalAccess', _99 => _99.token]), () => ( -1)) : 0;
5268
+ const token = active.some((f) => f.kind === "effect") ? _nullishCoalesce(_optionalChain([canvas, 'access', _102 => _102.effects, 'optionalAccess', _103 => _103.token]), () => ( -1)) : 0;
5122
5269
  const key = JSON.stringify([W, H, token, active.map((f) => ({ ...f, id: void 0 }))]);
5123
5270
  let entry = filteredCache.get(placed);
5124
5271
  let incomplete = false;
@@ -5130,9 +5277,9 @@ function applySmartFilters(placed, stack, canvas) {
5130
5277
  if (f.kind === "effect") {
5131
5278
  if (incomplete) continue;
5132
5279
  const inputKey = JSON.stringify([surfaceId(placed), W, H, active.slice(0, i + 1).map((x) => ({ ...x, id: void 0, blend: x === f ? void 0 : x.blend, opacity: x === f ? void 0 : x.opacity }))]);
5133
- const r = _optionalChain([canvas, 'access', _100 => _100.effects, 'optionalAccess', _101 => _101.resolve, 'call', _102 => _102(f, acc, W, H, inputKey)]);
5134
- if (!_optionalChain([r, 'optionalAccess', _103 => _103.result])) {
5135
- if (_optionalChain([r, 'optionalAccess', _104 => _104.pending])) incomplete = true;
5280
+ const r = _optionalChain([canvas, 'access', _104 => _104.effects, 'optionalAccess', _105 => _105.resolve, 'call', _106 => _106(f, acc, W, H, inputKey)]);
5281
+ if (!_optionalChain([r, 'optionalAccess', _107 => _107.result])) {
5282
+ if (_optionalChain([r, 'optionalAccess', _108 => _108.pending])) incomplete = true;
5136
5283
  continue;
5137
5284
  }
5138
5285
  out2 = new Uint8ClampedArray(r.result);
@@ -5183,7 +5330,7 @@ function rerender(layer, canvas, action = "change") {
5183
5330
  return { ...layer, surface: renderSmartObject(layer, canvas) };
5184
5331
  }
5185
5332
  function normalizePlacement(raw, contents) {
5186
- const c = _optionalChain([raw, 'optionalAccess', _105 => _105.corners]);
5333
+ const c = _optionalChain([raw, 'optionalAccess', _109 => _109.corners]);
5187
5334
  if (!Array.isArray(c) || c.length !== 4 || !c.every((p) => p && Number.isFinite(p.x) && Number.isFinite(p.y))) {
5188
5335
  fail4("corners must be four finite points [top-left, top-right, bottom-right, bottom-left] in document pixels.");
5189
5336
  }
@@ -5228,7 +5375,7 @@ function setSmartPlacement(layers, id, placement, canvas) {
5228
5375
  masksMoved ||= m !== layer.mask;
5229
5376
  next.mask = m;
5230
5377
  }
5231
- if (_optionalChain([next, 'access', _106 => _106.smartFilters, 'optionalAccess', _107 => _107.mask])) {
5378
+ if (_optionalChain([next, 'access', _110 => _110.smartFilters, 'optionalAccess', _111 => _111.mask])) {
5232
5379
  const m = followMask(next.smartFilters.mask, layer, next);
5233
5380
  masksMoved ||= m !== next.smartFilters.mask;
5234
5381
  next.smartFilters = { ...next.smartFilters, mask: m };
@@ -5246,12 +5393,13 @@ function offsetSmartObject(layers, id, dx, dy, canvas) {
5246
5393
  let next = { ...layer, placement: { ...layer.placement, corners } };
5247
5394
  const moveMask = (m2) => m2 && m2.linked !== false && !m2.source ? { ...m2, surface: _chunkCWM3CUUXcjs.translateSurface.call(void 0, m2.surface, mx, my) } : m2;
5248
5395
  if (layer.mask) next.mask = moveMask(layer.mask);
5249
- if (_optionalChain([layer, 'access', _108 => _108.smartFilters, 'optionalAccess', _109 => _109.mask])) next.smartFilters = { ...layer.smartFilters, mask: moveMask(layer.smartFilters.mask) };
5396
+ if (_optionalChain([layer, 'access', _112 => _112.smartFilters, 'optionalAccess', _113 => _113.mask])) next.smartFilters = { ...layer.smartFilters, mask: moveMask(layer.smartFilters.mask) };
5397
+ next = followLayerMove(next, mx, my);
5250
5398
  const spatial = activeSmartFilters(layer.smartFilters).some((f) => f.kind === "blur") || activeEffectSmartFilters(layer.smartFilters).length > 0;
5251
5399
  const b = _chunkCWM3CUUXcjs.contentBounds.call(void 0, layer.surface);
5252
5400
  const m = SMART_RENDER_MARGIN;
5253
5401
  const cut = b && (b.x <= -m || b.y <= -m || b.x + b.width >= canvas.width + m || b.y + b.height >= canvas.height + m);
5254
- if (!spatial && !cut && !(_optionalChain([next, 'access', _110 => _110.smartFilters, 'optionalAccess', _111 => _111.mask]) && activeSmartFilters(next.smartFilters).length && next.smartFilters.mask.linked === false)) {
5402
+ if (!spatial && !cut && !(_optionalChain([next, 'access', _114 => _114.smartFilters, 'optionalAccess', _115 => _115.mask]) && activeSmartFilters(next.smartFilters).length && next.smartFilters.mask.linked === false)) {
5255
5403
  next = { ...next, surface: _chunkCWM3CUUXcjs.translateSurface.call(void 0, layer.surface, mx, my) };
5256
5404
  } else {
5257
5405
  next = rerender(next, canvas, "move");
@@ -5276,7 +5424,7 @@ function translateLayer(layer, dx, dy) {
5276
5424
  mask: moveMask(layer.mask)
5277
5425
  };
5278
5426
  if (!next.mask) delete next.mask;
5279
- if (_optionalChain([layer, 'access', _112 => _112.smartFilters, 'optionalAccess', _113 => _113.mask])) next.smartFilters = { ...layer.smartFilters, mask: moveMask(layer.smartFilters.mask) };
5427
+ if (_optionalChain([layer, 'access', _116 => _116.smartFilters, 'optionalAccess', _117 => _117.mask])) next.smartFilters = { ...layer.smartFilters, mask: moveMask(layer.smartFilters.mask) };
5280
5428
  return next;
5281
5429
  }
5282
5430
  case "group": {
@@ -5336,14 +5484,14 @@ function union(a, b) {
5336
5484
  return { x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
5337
5485
  }
5338
5486
  function asSmartFilters(filters) {
5339
- if (!_optionalChain([filters, 'optionalAccess', _114 => _114.length])) return void 0;
5487
+ if (!_optionalChain([filters, 'optionalAccess', _118 => _118.length])) return void 0;
5340
5488
  return { enabled: true, filters: filters.map((f) => ({ ...f, blend: "normal", opacity: 1 })) };
5341
5489
  }
5342
5490
  function convertToSmartObject(layers, ids, canvas, options) {
5343
5491
  if (!ids.length) fail4("Give at least one layer id to convert.");
5344
5492
  const locs = [...new Set(ids)].map((id) => requireLayer(layers, id));
5345
- const parent = _nullishCoalesce(_optionalChain([locs, 'access', _115 => _115[0], 'access', _116 => _116.parent, 'optionalAccess', _117 => _117.id]), () => ( null));
5346
- if (locs.some((l) => (_nullishCoalesce(_optionalChain([l, 'access', _118 => _118.parent, 'optionalAccess', _119 => _119.id]), () => ( null))) !== parent)) fail4("Layers to convert must share one parent; move them next to each other first.");
5493
+ const parent = _nullishCoalesce(_optionalChain([locs, 'access', _119 => _119[0], 'access', _120 => _120.parent, 'optionalAccess', _121 => _121.id]), () => ( null));
5494
+ if (locs.some((l) => (_nullishCoalesce(_optionalChain([l, 'access', _122 => _122.parent, 'optionalAccess', _123 => _123.id]), () => ( null))) !== parent)) fail4("Layers to convert must share one parent; move them next to each other first.");
5347
5495
  for (const l of locs) requireUnlocked(l.layer, "all", "convert it");
5348
5496
  const ordered = locs.sort((a, b) => a.index - b.index);
5349
5497
  const top = ordered[ordered.length - 1];
@@ -5389,9 +5537,9 @@ function convertToSmartObject(layers, ids, canvas, options) {
5389
5537
  const nested = ordered.map((l) => {
5390
5538
  let layer = l.layer;
5391
5539
  if (layer.type === "pixel" && layer.source === "document") {
5392
- const resolved = { ...layer, surface: options.surfaceOf(layer) };
5393
- delete resolved.source;
5394
- layer = resolved;
5540
+ const resolved2 = { ...layer, surface: options.surfaceOf(layer) };
5541
+ delete resolved2.source;
5542
+ layer = resolved2;
5395
5543
  }
5396
5544
  if (_chunkHGTDMKNEcjs.flattenLayers.call(void 0, [layer]).some((x) => x.type === "pixel" && x.source === "document")) fail4(`Layer "${layer.name || layer.id}" holds the document image inside a group; convert the Background on its own.`);
5397
5545
  return translateLayer(layer, -b.x, -b.y);
@@ -5401,7 +5549,7 @@ function convertToSmartObject(layers, ids, canvas, options) {
5401
5549
  delete first.clipped;
5402
5550
  nested[0] = first;
5403
5551
  }
5404
- const name = _optionalChain([options, 'access', _120 => _120.name, 'optionalAccess', _121 => _121.trim, 'call', _122 => _122()]) || top.layer.name || "Smart Object";
5552
+ const name = _optionalChain([options, 'access', _124 => _124.name, 'optionalAccess', _125 => _125.trim, 'call', _126 => _126()]) || top.layer.name || "Smart Object";
5405
5553
  const contents = documentContents({ layers: nested }, b.width, b.height, `${name}.psb`);
5406
5554
  smart = {
5407
5555
  type: "smart",
@@ -5416,7 +5564,7 @@ function convertToSmartObject(layers, ids, canvas, options) {
5416
5564
  offset: { x: 0, y: 0 }
5417
5565
  };
5418
5566
  }
5419
- if (_optionalChain([options, 'access', _123 => _123.name, 'optionalAccess', _124 => _124.trim, 'call', _125 => _125()])) smart.name = options.name.trim();
5567
+ if (_optionalChain([options, 'access', _127 => _127.name, 'optionalAccess', _128 => _128.trim, 'call', _129 => _129()])) smart.name = options.name.trim();
5420
5568
  smart = { ...smart, surface: renderSmartObject(smart, canvas) };
5421
5569
  const below = ordered.filter((l) => l.index < top.index).length;
5422
5570
  let out = layers;
@@ -5446,12 +5594,12 @@ function rasterizeSmartObject(layers, id) {
5446
5594
  function copySmartObject(layers, id, linked, name) {
5447
5595
  const loc = requireLayer(layers, id);
5448
5596
  const layer = requireSmartObject(layers, id);
5449
- const copy = { ...layer, id: newLayerId("smart"), name: _optionalChain([name, 'optionalAccess', _126 => _126.trim, 'call', _127 => _127()]) || `${layer.name || "Smart Object"} copy` };
5597
+ const copy = { ...layer, id: newLayerId("smart"), name: _optionalChain([name, 'optionalAccess', _130 => _130.trim, 'call', _131 => _131()]) || `${layer.name || "Smart Object"} copy` };
5450
5598
  delete copy.locks;
5451
5599
  delete copy.psd;
5452
5600
  if (!linked) copy.contents = { ...layer.contents, id: newContentsId() };
5453
5601
  if (copy.smartFilters) copy.smartFilters = { ...copy.smartFilters, filters: copy.smartFilters.filters.map((f) => ({ ...f, id: newLayerId("flt") })) };
5454
- return { layers: _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, copy, _nullishCoalesce(_optionalChain([loc, 'access', _128 => _128.parent, 'optionalAccess', _129 => _129.id]), () => ( null)), loc.index + 1), layer: copy };
5602
+ return { layers: _chunkHGTDMKNEcjs.insertLayer.call(void 0, layers, copy, _nullishCoalesce(_optionalChain([loc, 'access', _132 => _132.parent, 'optionalAccess', _133 => _133.id]), () => ( null)), loc.index + 1), layer: copy };
5455
5603
  }
5456
5604
  function instancesOf(layers, contentsId) {
5457
5605
  return _chunkHGTDMKNEcjs.flattenLayers.call(void 0, layers).filter((l) => l.type === "smart" && l.contents.id === contentsId).map((l) => l.id);
@@ -5523,7 +5671,7 @@ function stackOf(layer) {
5523
5671
  return _nullishCoalesce(layer.smartFilters, () => ( { enabled: true, filters: [] }));
5524
5672
  }
5525
5673
  function requireFilter(layer, filterId) {
5526
- const list2 = _nullishCoalesce(_optionalChain([layer, 'access', _130 => _130.smartFilters, 'optionalAccess', _131 => _131.filters]), () => ( []));
5674
+ const list2 = _nullishCoalesce(_optionalChain([layer, 'access', _134 => _134.smartFilters, 'optionalAccess', _135 => _135.filters]), () => ( []));
5527
5675
  const i = list2.findIndex((f) => f.id === filterId);
5528
5676
  if (i === -1) fail4(`Smart object "${layer.name || layer.id}" has no smart filter "${filterId}". Filters: ${list2.map((f) => `${f.id} (${f.kind})`).join(", ") || "none"}; call get_smart_object.`);
5529
5677
  return i;
@@ -5590,7 +5738,7 @@ function setSmartFiltersEnabled(layers, id, enabled, canvas) {
5590
5738
  }
5591
5739
  function setSmartFilterMask(layers, id, mask, canvas) {
5592
5740
  const layer = editableSmart(layers, id);
5593
- if (_optionalChain([mask, 'optionalAccess', _132 => _132.source])) fail4("A smart filter mask is painted, not generated; use a raster mask.");
5741
+ if (_optionalChain([mask, 'optionalAccess', _136 => _136.source])) fail4("A smart filter mask is painted, not generated; use a raster mask.");
5594
5742
  const stack = { ...stackOf(layer) };
5595
5743
  if (mask) stack.mask = mask;
5596
5744
  else delete stack.mask;
@@ -5683,6 +5831,7 @@ function baseFields(layer, ctx) {
5683
5831
  };
5684
5832
  if (layer.clipped) out.clipped = true;
5685
5833
  if (layer.mask) out.mask = serializeMask(layer.mask, `${layer.id}-mask`, ctx);
5834
+ if (layer.vectorMask) out.vectorMask = serializeVectorMask(layer.vectorMask);
5686
5835
  if (layer.locks && Object.values(layer.locks).some(Boolean)) out.locks = { ...layer.locks };
5687
5836
  if (layer.effects) out.effects = serializeEffects(layer.effects);
5688
5837
  return out;
@@ -5707,6 +5856,36 @@ function deserializeEffects(raw) {
5707
5856
  }
5708
5857
  return _chunkHGTDMKNEcjs.normalizeLayerEffects.call(void 0, { ...r, psd });
5709
5858
  }
5859
+ function serializeVectorMask(vm) {
5860
+ const out = { components: JSON.parse(JSON.stringify(vm.components)) };
5861
+ if (vm.fillRule === "evenodd") out.fillRule = "evenodd";
5862
+ if (vm.inverted) out.inverted = true;
5863
+ if (vm.enabled === false) out.enabled = false;
5864
+ if (vm.linked === false) out.linked = false;
5865
+ if (vm.density !== void 0 && vm.density !== 1) out.density = vm.density;
5866
+ if (vm.feather) out.feather = vm.feather;
5867
+ return out;
5868
+ }
5869
+ function readVectorMask(r) {
5870
+ if (!Array.isArray(r.components)) throw new Error("its components are missing");
5871
+ const components = r.components.map((raw, i) => {
5872
+ const c = raw;
5873
+ const op = requireOperation(_optionalChain([c, 'optionalAccess', _137 => _137.op]), `components[${i}].op`);
5874
+ if (_optionalChain([c, 'optionalAccess', _138 => _138.live])) {
5875
+ const live = normalizeLiveShape(c.live, `components[${i}].live`);
5876
+ return { op, subpaths: liveShapeSubpaths(live), live };
5877
+ }
5878
+ return { op, subpaths: Array.isArray(_optionalChain([c, 'optionalAccess', _139 => _139.subpaths])) && !c.subpaths.length ? [] : normalizeSubpaths(_optionalChain([c, 'optionalAccess', _140 => _140.subpaths]), `components[${i}].subpaths`) };
5879
+ });
5880
+ const vm = { components };
5881
+ if (r.fillRule === "evenodd") vm.fillRule = "evenodd";
5882
+ if (r.inverted === true) vm.inverted = true;
5883
+ if (r.enabled === false) vm.enabled = false;
5884
+ if (r.linked === false) vm.linked = false;
5885
+ if (typeof r.density === "number" && r.density !== 1) vm.density = num2(r.density, 0, 1, 1);
5886
+ if (typeof r.feather === "number" && r.feather > 0) vm.feather = num2(r.feather, 0, 1e3, 0);
5887
+ return vm;
5888
+ }
5710
5889
  function serializeMask(mask, hint, ctx) {
5711
5890
  const out = { defaultValue: mask.defaultValue };
5712
5891
  if (!mask.source) {
@@ -5742,7 +5921,7 @@ function serializeLayer(layer, ctx) {
5742
5921
  }
5743
5922
  }
5744
5923
  if (layer.fillOpacity !== void 0 && layer.fillOpacity !== 1) out.fillOpacity = layer.fillOpacity;
5745
- if (_optionalChain([layer, 'access', _133 => _133.filters, 'optionalAccess', _134 => _134.length])) out.filters = JSON.parse(JSON.stringify(layer.filters));
5924
+ if (_optionalChain([layer, 'access', _141 => _141.filters, 'optionalAccess', _142 => _142.length])) out.filters = JSON.parse(JSON.stringify(layer.filters));
5746
5925
  if (layer.generator) out.generator = JSON.parse(JSON.stringify(layer.generator));
5747
5926
  if (layer.source !== "document") {
5748
5927
  const deep = encodeDeepSurface(layer.surface);
@@ -5785,12 +5964,12 @@ function serializeType(layer, base, ctx) {
5785
5964
  out.x = enc.x;
5786
5965
  out.y = enc.y;
5787
5966
  }
5788
- if (_optionalChain([layer, 'access', _135 => _135.missingFonts, 'optionalAccess', _136 => _136.length])) out.missingFonts = [...layer.missingFonts];
5967
+ if (_optionalChain([layer, 'access', _143 => _143.missingFonts, 'optionalAccess', _144 => _144.length])) out.missingFonts = [...layer.missingFonts];
5789
5968
  if (layer.annotation) out.annotation = JSON.parse(JSON.stringify(layer.annotation));
5790
- if (_optionalChain([layer, 'access', _137 => _137.psd, 'optionalAccess', _138 => _138.tySh]) || _optionalChain([layer, 'access', _139 => _139.psd, 'optionalAccess', _140 => _140.blocks, 'optionalAccess', _141 => _141.length])) {
5969
+ if (_optionalChain([layer, 'access', _145 => _145.psd, 'optionalAccess', _146 => _146.tySh]) || _optionalChain([layer, 'access', _147 => _147.psd, 'optionalAccess', _148 => _148.blocks, 'optionalAccess', _149 => _149.length])) {
5791
5970
  out.psd = {};
5792
5971
  if (layer.psd.tySh) out.psd.tySh = _chunkCWM3CUUXcjs.bytesToBase64.call(void 0, layer.psd.tySh);
5793
- if (_optionalChain([layer, 'access', _142 => _142.psd, 'access', _143 => _143.blocks, 'optionalAccess', _144 => _144.length])) out.psd.blocks = layer.psd.blocks.map((b) => ({ key: b.key, data: _chunkCWM3CUUXcjs.bytesToBase64.call(void 0, b.data) }));
5972
+ if (_optionalChain([layer, 'access', _150 => _150.psd, 'access', _151 => _151.blocks, 'optionalAccess', _152 => _152.length])) out.psd.blocks = layer.psd.blocks.map((b) => ({ key: b.key, data: _chunkCWM3CUUXcjs.bytesToBase64.call(void 0, b.data) }));
5794
5973
  if (layer.psd.signature) out.psd.signature = layer.psd.signature;
5795
5974
  }
5796
5975
  return out;
@@ -5800,15 +5979,15 @@ function readType(r, base, ctx) {
5800
5979
  try {
5801
5980
  const text3 = normalizeText(_nullishCoalesce(r.text, () => ( "")));
5802
5981
  const runs = (Array.isArray(r.runs) ? r.runs : []).map((run, i) => ({
5803
- length: Math.max(0, Math.floor(num2(_optionalChain([run, 'optionalAccess', _145 => _145.length]), 0, 1e9, 0))),
5804
- style: patchTextStyle(_chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE, _optionalChain([run, 'optionalAccess', _146 => _146.style]) && typeof run.style === "object" ? run.style : {}, `runs[${i}].style`)
5982
+ length: Math.max(0, Math.floor(num2(_optionalChain([run, 'optionalAccess', _153 => _153.length]), 0, 1e9, 0))),
5983
+ style: patchTextStyle(_chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE, _optionalChain([run, 'optionalAccess', _154 => _154.style]) && typeof run.style === "object" ? run.style : {}, `runs[${i}].style`)
5805
5984
  }));
5806
5985
  const paragraphs = (Array.isArray(r.paragraphs) ? r.paragraphs : []).map((p, i) => ({
5807
- length: Math.max(0, Math.floor(num2(_optionalChain([p, 'optionalAccess', _147 => _147.length]), 0, 1e9, 0))),
5808
- style: patchParagraphStyle({}, _optionalChain([p, 'optionalAccess', _148 => _148.style]) && typeof p.style === "object" ? p.style : {}, `paragraphs[${i}].style`)
5986
+ length: Math.max(0, Math.floor(num2(_optionalChain([p, 'optionalAccess', _155 => _155.length]), 0, 1e9, 0))),
5987
+ style: patchParagraphStyle({}, _optionalChain([p, 'optionalAccess', _156 => _156.style]) && typeof p.style === "object" ? p.style : {}, `paragraphs[${i}].style`)
5809
5988
  }));
5810
5989
  const f = r.frame;
5811
- const frame = _optionalChain([f, 'optionalAccess', _149 => _149.kind]) === "box" ? { kind: "box", width: num2(f.width, 1, 1e6, 100), height: num2(f.height, 1, 1e6, 100) } : _optionalChain([f, 'optionalAccess', _150 => _150.origin]) === "top" ? { kind: "point", origin: "top" } : { kind: "point" };
5990
+ const frame = _optionalChain([f, 'optionalAccess', _157 => _157.kind]) === "box" ? { kind: "box", width: num2(f.width, 1, 1e6, 100), height: num2(f.height, 1, 1e6, 100) } : _optionalChain([f, 'optionalAccess', _158 => _158.origin]) === "top" ? { kind: "point", origin: "top" } : { kind: "point" };
5812
5991
  const m = Array.isArray(r.transform) && r.transform.length === 6 && r.transform.every((v) => typeof v === "number" && Number.isFinite(v)) ? r.transform : void 0;
5813
5992
  const layer = {
5814
5993
  ...base,
@@ -5820,7 +5999,7 @@ function readType(r, base, ctx) {
5820
5999
  surface: _chunkCWM3CUUXcjs.emptySurface.call(void 0, 4),
5821
6000
  offset: { x: 0, y: 0 }
5822
6001
  };
5823
- if (!layer.runs.length) layer.runs = [{ length: 0, style: _nullishCoalesce(_optionalChain([runs, 'access', _151 => _151[0], 'optionalAccess', _152 => _152.style]), () => ( _chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE)) }];
6002
+ if (!layer.runs.length) layer.runs = [{ length: 0, style: _nullishCoalesce(_optionalChain([runs, 'access', _159 => _159[0], 'optionalAccess', _160 => _160.style]), () => ( _chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE)) }];
5824
6003
  if (m) layer.transform = m;
5825
6004
  if (r.antiAlias === false) layer.antiAlias = false;
5826
6005
  if (typeof r.fillOpacity === "number" && r.fillOpacity !== 1) layer.fillOpacity = num2(r.fillOpacity, 0, 1, 1);
@@ -5831,10 +6010,10 @@ function readType(r, base, ctx) {
5831
6010
  if (typeof r.psd.tySh === "string") psd.tySh = _chunkCWM3CUUXcjs.base64ToBytes.call(void 0, r.psd.tySh);
5832
6011
  if (Array.isArray(r.psd.blocks)) psd.blocks = r.psd.blocks.filter((b) => b && typeof b.key === "string" && typeof b.data === "string").map((b) => ({ key: b.key, data: _chunkCWM3CUUXcjs.base64ToBytes.call(void 0, b.data) }));
5833
6012
  if (typeof r.psd.signature === "string") psd.signature = r.psd.signature;
5834
- if (psd.tySh || _optionalChain([psd, 'access', _153 => _153.blocks, 'optionalAccess', _154 => _154.length])) layer.psd = psd;
6013
+ if (psd.tySh || _optionalChain([psd, 'access', _161 => _161.blocks, 'optionalAccess', _162 => _162.length])) layer.psd = psd;
5835
6014
  }
5836
6015
  if (typeof r.asset === "string") return { ...layer, surface: readSurface(r.asset, r.x, r.y, 4, 0, ctx, label), rendering: "stored" };
5837
- const env = { ..._nullishCoalesce(ctx.canvas, () => ( { width: 1, height: 1 })), shaper: _nullishCoalesce(_optionalChain([ctx, 'access', _155 => _155.text, 'optionalAccess', _156 => _156.shaper]), () => ( null)), createCanvas: _optionalChain([ctx, 'access', _157 => _157.text, 'optionalAccess', _158 => _158.createCanvas]) };
6016
+ const env = { ..._nullishCoalesce(ctx.canvas, () => ( { width: 1, height: 1 })), shaper: _nullishCoalesce(_optionalChain([ctx, 'access', _163 => _163.text, 'optionalAccess', _164 => _164.shaper]), () => ( null)), createCanvas: _optionalChain([ctx, 'access', _165 => _165.text, 'optionalAccess', _166 => _166.createCanvas]) };
5838
6017
  try {
5839
6018
  return rerenderText(layer, env);
5840
6019
  } catch (e8) {
@@ -5857,7 +6036,7 @@ function serializeShape(layer, base) {
5857
6036
  if (layer.inverted) out.inverted = true;
5858
6037
  if (layer.fillOpacity !== void 0 && layer.fillOpacity !== 1) out.fillOpacity = layer.fillOpacity;
5859
6038
  if (layer.annotation) out.annotation = JSON.parse(JSON.stringify(layer.annotation));
5860
- if (_optionalChain([layer, 'access', _159 => _159.psd, 'optionalAccess', _160 => _160.blocks, 'optionalAccess', _161 => _161.length])) out.psd = { blocks: layer.psd.blocks.map((b) => ({ key: b.key, data: _chunkCWM3CUUXcjs.bytesToBase64.call(void 0, b.data) })), ...layer.psd.signature ? { signature: layer.psd.signature } : {} };
6039
+ if (_optionalChain([layer, 'access', _167 => _167.psd, 'optionalAccess', _168 => _168.blocks, 'optionalAccess', _169 => _169.length])) out.psd = { blocks: layer.psd.blocks.map((b) => ({ key: b.key, data: _chunkCWM3CUUXcjs.bytesToBase64.call(void 0, b.data) })), ...layer.psd.signature ? { signature: layer.psd.signature } : {} };
5861
6040
  return out;
5862
6041
  }
5863
6042
  function readShape(r, base, ctx) {
@@ -5871,12 +6050,12 @@ function readShape(r, base, ctx) {
5871
6050
  if (!data) {
5872
6051
  if (!Array.isArray(r.components) || !r.components.length) throw new Error("it has no components");
5873
6052
  const components = r.components.map((c, i) => {
5874
- const op = requireOperation(_optionalChain([c, 'optionalAccess', _162 => _162.op]), `components[${i}].op`);
5875
- if (_optionalChain([c, 'optionalAccess', _163 => _163.live])) {
6053
+ const op = requireOperation(_optionalChain([c, 'optionalAccess', _170 => _170.op]), `components[${i}].op`);
6054
+ if (_optionalChain([c, 'optionalAccess', _171 => _171.live])) {
5876
6055
  const live = normalizeLiveShape(c.live, `components[${i}].live`);
5877
6056
  return { op, subpaths: liveShapeSubpaths(live), live };
5878
6057
  }
5879
- return { op, subpaths: Array.isArray(_optionalChain([c, 'optionalAccess', _164 => _164.subpaths])) && !c.subpaths.length ? [] : normalizeSubpaths(_optionalChain([c, 'optionalAccess', _165 => _165.subpaths]), `components[${i}].subpaths`) };
6058
+ return { op, subpaths: Array.isArray(_optionalChain([c, 'optionalAccess', _172 => _172.subpaths])) && !c.subpaths.length ? [] : normalizeSubpaths(_optionalChain([c, 'optionalAccess', _173 => _173.subpaths]), `components[${i}].subpaths`) };
5880
6059
  });
5881
6060
  data = {
5882
6061
  components,
@@ -5947,7 +6126,7 @@ function serializeContents(c, ctx) {
5947
6126
  if (c.kind === "document" && c.document) {
5948
6127
  out.layers = c.document.layers.map((l) => serializeLayer(l, ctx));
5949
6128
  if (c.document.globalLight) out.globalLight = { ...c.document.globalLight };
5950
- if (_optionalChain([c, 'access', _166 => _166.document, 'access', _167 => _167.patterns, 'optionalAccess', _168 => _168.length])) out.patterns = serializePatterns(c.document.patterns);
6129
+ if (_optionalChain([c, 'access', _174 => _174.document, 'access', _175 => _175.patterns, 'optionalAccess', _176 => _176.length])) out.patterns = serializePatterns(c.document.patterns);
5951
6130
  }
5952
6131
  if (c.file) out.file = { type: c.file.type, data: _chunkCWM3CUUXcjs.bytesToBase64.call(void 0, c.file.bytes) };
5953
6132
  if (c.linked) out.linked = { path: c.linked.path };
@@ -6114,6 +6293,13 @@ function deserializeLayer(raw, ctx) {
6114
6293
  if (r.clipped === true) base.clipped = true;
6115
6294
  const mask = readMask(r.mask, ctx, `Layer "${base.name || id}"`);
6116
6295
  if (mask) base.mask = mask;
6296
+ if (r.vectorMask && typeof r.vectorMask === "object" && r.type !== "shape") {
6297
+ try {
6298
+ base.vectorMask = readVectorMask(r.vectorMask);
6299
+ } catch (err) {
6300
+ ctx.problems.push(`The vector mask of layer "${base.name || id}" could not be read (${err instanceof Error ? err.message : String(err)}); it was left out.`);
6301
+ }
6302
+ }
6117
6303
  if (r.locks && typeof r.locks === "object") {
6118
6304
  const locks = {};
6119
6305
  for (const k of ["pixels", "transparency", "position", "all"]) if (r.locks[k] === true) locks[k] = true;
@@ -6127,7 +6313,7 @@ function deserializeLayer(raw, ctx) {
6127
6313
  ...base,
6128
6314
  type: "pixel",
6129
6315
  surface: r.source === "document" ? _chunkCWM3CUUXcjs.emptySurface.call(void 0, 4) : readSurface(r.asset, r.x, r.y, 4, 0, ctx, `Layer "${base.name || id}"`),
6130
- offset: { x: Math.round(num2(_optionalChain([r, 'access', _169 => _169.offset, 'optionalAccess', _170 => _170.x]), -1e7, 1e7, 0)), y: Math.round(num2(_optionalChain([r, 'access', _171 => _171.offset, 'optionalAccess', _172 => _172.y]), -1e7, 1e7, 0)) }
6316
+ offset: { x: Math.round(num2(_optionalChain([r, 'access', _177 => _177.offset, 'optionalAccess', _178 => _178.x]), -1e7, 1e7, 0)), y: Math.round(num2(_optionalChain([r, 'access', _179 => _179.offset, 'optionalAccess', _180 => _180.y]), -1e7, 1e7, 0)) }
6131
6317
  };
6132
6318
  if (r.source === "document") layer.source = "document";
6133
6319
  else if (r.deep) layer.surface = decodeDeepSurface(layer.surface, r.deep, ctx.problems, `Layer "${base.name || id}"`);
@@ -6136,7 +6322,7 @@ function deserializeLayer(raw, ctx) {
6136
6322
  if (filters) layer.filters = filters;
6137
6323
  const generator = readEffectRef(r.generator);
6138
6324
  if (generator) {
6139
- const duration = _optionalChain([r, 'access', _173 => _173.generator, 'access', _174 => _174.animate, 'optionalAccess', _175 => _175.duration]);
6325
+ const duration = _optionalChain([r, 'access', _181 => _181.generator, 'access', _182 => _182.animate, 'optionalAccess', _183 => _183.duration]);
6140
6326
  layer.generator = {
6141
6327
  ...generator,
6142
6328
  ...typeof r.generator.time === "number" && r.generator.time > 0 ? { time: r.generator.time } : {},
@@ -6167,7 +6353,7 @@ function deserializeLayer(raw, ctx) {
6167
6353
  return null;
6168
6354
  }
6169
6355
  const annotation = JSON.parse(JSON.stringify({ ...a, id: typeof a.id === "string" ? a.id : id }));
6170
- const migrated = annotationLayerFor(annotation, { ..._nullishCoalesce(ctx.canvas, () => ( { width: 1, height: 1 })), shaper: _nullishCoalesce(_optionalChain([ctx, 'access', _176 => _176.text, 'optionalAccess', _177 => _177.shaper]), () => ( null)), createCanvas: _optionalChain([ctx, 'access', _178 => _178.text, 'optionalAccess', _179 => _179.createCanvas]) });
6356
+ const migrated = annotationLayerFor(annotation, { ..._nullishCoalesce(ctx.canvas, () => ( { width: 1, height: 1 })), shaper: _nullishCoalesce(_optionalChain([ctx, 'access', _184 => _184.text, 'optionalAccess', _185 => _185.shaper]), () => ( null)), createCanvas: _optionalChain([ctx, 'access', _186 => _186.text, 'optionalAccess', _187 => _187.createCanvas]) });
6171
6357
  if (migrated.type === "shape" || migrated.type === "type") {
6172
6358
  const blend = base.blend === "normal" ? migrated.blend : base.blend;
6173
6359
  return { ...migrated, ...base, blend, id, name: base.name };
@@ -6745,7 +6931,7 @@ function descriptor(classId, items = []) {
6745
6931
  return { name: "", classId, items };
6746
6932
  }
6747
6933
  function descGet(d, key) {
6748
- return _optionalChain([d, 'access', _180 => _180.items, 'access', _181 => _181.find, 'call', _182 => _182(([k]) => k === key), 'optionalAccess', _183 => _183[1]]);
6934
+ return _optionalChain([d, 'access', _188 => _188.items, 'access', _189 => _189.find, 'call', _190 => _190(([k]) => k === key), 'optionalAccess', _191 => _191[1]]);
6749
6935
  }
6750
6936
  function descNumber(d, key) {
6751
6937
  const v = descGet(d, key);
@@ -6755,7 +6941,7 @@ function descNumber(d, key) {
6755
6941
  }
6756
6942
  function descBool(d, key) {
6757
6943
  const v = descGet(d, key);
6758
- return _optionalChain([v, 'optionalAccess', _184 => _184.type]) === "bool" ? v.value : void 0;
6944
+ return _optionalChain([v, 'optionalAccess', _192 => _192.type]) === "bool" ? v.value : void 0;
6759
6945
  }
6760
6946
  function descObject(d, key) {
6761
6947
  const v = descGet(d, key);
@@ -7337,97 +7523,6 @@ function writeAdjustmentBlock(kind, params) {
7337
7523
  throw new Error(`Unknown adjustment kind "${kind}".`);
7338
7524
  }
7339
7525
 
7340
- // src/image-editor/psd/channels.ts
7341
- var hexToRgb2 = (hex) => {
7342
- const v = parseInt(_nullishCoalesce(_optionalChain([/^#?([0-9a-f]{6})$/i, 'access', _185 => _185.exec, 'call', _186 => _186(hex), 'optionalAccess', _187 => _187[1]]), () => ( "ff0000")), 16);
7343
- return [v >> 16 & 255, v >> 8 & 255, v & 255];
7344
- };
7345
- var rgbToHex = (r, g, b) => `#${[r, g, b].map((c) => c.toString(16).padStart(2, "0")).join("")}`;
7346
- function alphaChannelResources(channels) {
7347
- if (!channels.length) return [];
7348
- const names = new PsdWriter();
7349
- for (const c of channels) names.pascal(encodeLegacyName(c.name), 1);
7350
- const unicode = new PsdWriter();
7351
- for (const c of channels) unicode.unicode(c.name);
7352
- const display = new PsdWriter();
7353
- display.u32(1);
7354
- for (const c of channels) {
7355
- const [r, g, b] = hexToRgb2(c.color);
7356
- display.u16(0);
7357
- for (const v of [r, g, b, 0]) display.u16(v * 257);
7358
- display.u16(Math.round(Math.min(1, Math.max(0, c.opacity)) * 100));
7359
- display.u8(c.indicates === "selected" ? 0 : 1);
7360
- display.u8(0);
7361
- }
7362
- return [
7363
- { id: 1006, name: "", data: names.result() },
7364
- { id: 1045, name: "", data: unicode.result() },
7365
- { id: 1077, name: "", data: display.result() }
7366
- ];
7367
- }
7368
- function planeTo8(plane, n, depth) {
7369
- if (depth === 8) return plane.slice(0, n);
7370
- const out = new Uint8Array(n);
7371
- const view = new DataView(plane.buffer, plane.byteOffset, plane.byteLength);
7372
- for (let i = 0; i < n; i++) {
7373
- if (depth === 16) out[i] = plane[2 * i];
7374
- else out[i] = Math.round(Math.min(1, Math.max(0, view.getFloat32(4 * i, false))) * 255);
7375
- }
7376
- return out;
7377
- }
7378
- function readAlphaChannels(planes, header, first, resource2, warn) {
7379
- const count = header.channels - first;
7380
- if (count <= 0 || header.depth === 1) return [];
7381
- const size = rowBytes(header.width, header.depth) * header.height;
7382
- const n = header.width * header.height;
7383
- const names = [];
7384
- const unicode = resource2(1045);
7385
- if (unicode) {
7386
- const r = new PsdReader(unicode);
7387
- while (r.remaining >= 4 && names.length < count) names.push(r.unicode().replace(/\0+$/, ""));
7388
- } else {
7389
- const legacy = resource2(1006);
7390
- if (legacy) {
7391
- const r = new PsdReader(legacy);
7392
- while (r.remaining >= 1 && names.length < count) names.push(new TextDecoder("latin1").decode(r.pascal(1)));
7393
- }
7394
- }
7395
- const display = [];
7396
- const info = resource2(1077);
7397
- if (info && info.length >= 4) {
7398
- const r = new PsdReader(info);
7399
- r.u32();
7400
- while (r.remaining >= 14 && display.length < count) {
7401
- r.u16();
7402
- const [cr, cg, cb] = [r.u16(), r.u16(), r.u16()];
7403
- r.u16();
7404
- const opacity = r.u16();
7405
- const kind = r.u8();
7406
- r.u8();
7407
- display.push({ color: rgbToHex(cr >> 8, cg >> 8, cb >> 8), opacity: Math.min(100, opacity) / 100, kind });
7408
- }
7409
- }
7410
- const out = [];
7411
- for (let i = 0; i < count; i++) {
7412
- const start = (first + i) * size;
7413
- if (start + size > planes.length) break;
7414
- const d = display[i];
7415
- const name = names[i] || `Alpha ${i + 1}`;
7416
- if (_optionalChain([d, 'optionalAccess', _188 => _188.kind]) === 2) {
7417
- warn(`Spot colour channel "${name}" is not supported and was left out.`);
7418
- continue;
7419
- }
7420
- out.push({
7421
- name,
7422
- data: planeTo8(planes.subarray(start, start + size), n, header.depth),
7423
- color: _nullishCoalesce(_optionalChain([d, 'optionalAccess', _189 => _189.color]), () => ( "#ff0000")),
7424
- opacity: _nullishCoalesce(_optionalChain([d, 'optionalAccess', _190 => _190.opacity]), () => ( 0.5)),
7425
- indicates: _optionalChain([d, 'optionalAccess', _191 => _191.kind]) === 0 ? "selected" : "masked"
7426
- });
7427
- }
7428
- return out;
7429
- }
7430
-
7431
7526
  // src/image-editor/psd/paths.ts
7432
7527
  var RECORD = 26;
7433
7528
  var fixed = (v) => v / 16777216;
@@ -7487,6 +7582,8 @@ function writePathRecords(path) {
7487
7582
  return w.result();
7488
7583
  }
7489
7584
  var VMSK_INVERT = 1;
7585
+ var VMSK_NOT_LINKED = 2;
7586
+ var VMSK_DISABLED = 4;
7490
7587
  function readVectorBlock(data) {
7491
7588
  if (data.length < 8) return null;
7492
7589
  const r = new PsdReader(data);
@@ -7557,6 +7654,97 @@ function vectorBlockForComponents(components, inverted, width, height, flags = 0
7557
7654
  return writeVectorBlock({ subpaths, initialFill: subpaths.length === 0 && inverted }, flags & ~VMSK_INVERT | (inverted && subpaths.length ? VMSK_INVERT : 0));
7558
7655
  }
7559
7656
 
7657
+ // src/image-editor/psd/channels.ts
7658
+ var hexToRgb2 = (hex) => {
7659
+ const v = parseInt(_nullishCoalesce(_optionalChain([/^#?([0-9a-f]{6})$/i, 'access', _193 => _193.exec, 'call', _194 => _194(hex), 'optionalAccess', _195 => _195[1]]), () => ( "ff0000")), 16);
7660
+ return [v >> 16 & 255, v >> 8 & 255, v & 255];
7661
+ };
7662
+ var rgbToHex = (r, g, b) => `#${[r, g, b].map((c) => c.toString(16).padStart(2, "0")).join("")}`;
7663
+ function alphaChannelResources(channels) {
7664
+ if (!channels.length) return [];
7665
+ const names = new PsdWriter();
7666
+ for (const c of channels) names.pascal(encodeLegacyName(c.name), 1);
7667
+ const unicode = new PsdWriter();
7668
+ for (const c of channels) unicode.unicode(c.name);
7669
+ const display = new PsdWriter();
7670
+ display.u32(1);
7671
+ for (const c of channels) {
7672
+ const [r, g, b] = hexToRgb2(c.color);
7673
+ display.u16(0);
7674
+ for (const v of [r, g, b, 0]) display.u16(v * 257);
7675
+ display.u16(Math.round(Math.min(1, Math.max(0, c.opacity)) * 100));
7676
+ display.u8(c.indicates === "selected" ? 0 : 1);
7677
+ display.u8(0);
7678
+ }
7679
+ return [
7680
+ { id: 1006, name: "", data: names.result() },
7681
+ { id: 1045, name: "", data: unicode.result() },
7682
+ { id: 1077, name: "", data: display.result() }
7683
+ ];
7684
+ }
7685
+ function planeTo8(plane, n, depth) {
7686
+ if (depth === 8) return plane.slice(0, n);
7687
+ const out = new Uint8Array(n);
7688
+ const view = new DataView(plane.buffer, plane.byteOffset, plane.byteLength);
7689
+ for (let i = 0; i < n; i++) {
7690
+ if (depth === 16) out[i] = plane[2 * i];
7691
+ else out[i] = Math.round(Math.min(1, Math.max(0, view.getFloat32(4 * i, false))) * 255);
7692
+ }
7693
+ return out;
7694
+ }
7695
+ function readAlphaChannels(planes, header, first, resource2, warn) {
7696
+ const count = header.channels - first;
7697
+ if (count <= 0 || header.depth === 1) return [];
7698
+ const size = rowBytes(header.width, header.depth) * header.height;
7699
+ const n = header.width * header.height;
7700
+ const names = [];
7701
+ const unicode = resource2(1045);
7702
+ if (unicode) {
7703
+ const r = new PsdReader(unicode);
7704
+ while (r.remaining >= 4 && names.length < count) names.push(r.unicode().replace(/\0+$/, ""));
7705
+ } else {
7706
+ const legacy = resource2(1006);
7707
+ if (legacy) {
7708
+ const r = new PsdReader(legacy);
7709
+ while (r.remaining >= 1 && names.length < count) names.push(new TextDecoder("latin1").decode(r.pascal(1)));
7710
+ }
7711
+ }
7712
+ const display = [];
7713
+ const info = resource2(1077);
7714
+ if (info && info.length >= 4) {
7715
+ const r = new PsdReader(info);
7716
+ r.u32();
7717
+ while (r.remaining >= 14 && display.length < count) {
7718
+ r.u16();
7719
+ const [cr, cg, cb] = [r.u16(), r.u16(), r.u16()];
7720
+ r.u16();
7721
+ const opacity = r.u16();
7722
+ const kind = r.u8();
7723
+ r.u8();
7724
+ display.push({ color: rgbToHex(cr >> 8, cg >> 8, cb >> 8), opacity: Math.min(100, opacity) / 100, kind });
7725
+ }
7726
+ }
7727
+ const out = [];
7728
+ for (let i = 0; i < count; i++) {
7729
+ const start = (first + i) * size;
7730
+ if (start + size > planes.length) break;
7731
+ const d = display[i];
7732
+ const name = names[i] || `Alpha ${i + 1}`;
7733
+ if (_optionalChain([d, 'optionalAccess', _196 => _196.kind]) === 2) {
7734
+ warn(`Spot colour channel "${name}" is not supported and was left out.`);
7735
+ continue;
7736
+ }
7737
+ out.push({
7738
+ name,
7739
+ data: planeTo8(planes.subarray(start, start + size), n, header.depth),
7740
+ color: _nullishCoalesce(_optionalChain([d, 'optionalAccess', _197 => _197.color]), () => ( "#ff0000")),
7741
+ opacity: _nullishCoalesce(_optionalChain([d, 'optionalAccess', _198 => _198.opacity]), () => ( 0.5)),
7742
+ indicates: _optionalChain([d, 'optionalAccess', _199 => _199.kind]) === 0 ? "selected" : "masked"
7743
+ });
7744
+ }
7745
+ return out;
7746
+ }
7747
+
7560
7748
  // src/image-editor/psd/shapes.ts
7561
7749
  var SHAPE_PSD_KEYS = ["vsms", "vmsk", "vscg", "vstk", "vogk", "SoCo", "GdFl", "PtFl"];
7562
7750
  var unit = (u, value) => ({ type: "UntF", unit: u, value });
@@ -7567,7 +7755,7 @@ var enumV = (typeId, value) => ({ type: "enum", typeId, value });
7567
7755
  var obj = (d) => ({ type: "Objc", value: d });
7568
7756
  var enumOf = (d, key) => {
7569
7757
  const v = descGet(d, key);
7570
- return _optionalChain([v, 'optionalAccess', _192 => _192.type]) === "enum" ? v.value : void 0;
7758
+ return _optionalChain([v, 'optionalAccess', _200 => _200.type]) === "enum" ? v.value : void 0;
7571
7759
  };
7572
7760
  function read(data) {
7573
7761
  try {
@@ -7649,7 +7837,7 @@ function strokeFromVstk(data, dpi, notes) {
7649
7837
  const miter = descNumber(d, "strokeStyleMiterLimit");
7650
7838
  if (miter !== void 0 && miter !== 100) stroke.miterLimit = Math.max(1, Math.min(500, miter));
7651
7839
  const dashes = descGet(d, "strokeStyleLineDashSet");
7652
- if (_optionalChain([dashes, 'optionalAccess', _193 => _193.type]) === "VlLs") {
7840
+ if (_optionalChain([dashes, 'optionalAccess', _201 => _201.type]) === "VlLs") {
7653
7841
  const list2 = dashes.items.map((v) => v.type === "UntF" || v.type === "doub" || v.type === "long" ? v.value : NaN).filter((v) => Number.isFinite(v) && v >= 0);
7654
7842
  if (list2.length && list2.some((v) => v > 0)) stroke.dashes = list2;
7655
7843
  }
@@ -7801,7 +7989,7 @@ function vogkBytes(components, dpi) {
7801
7989
  ["keyOriginLineArrowEnd", boolV(Boolean(live.endArrow))],
7802
7990
  ["keyOriginLineArrWdth", dbl(head ? head.width / w * 100 : 0)],
7803
7991
  ["keyOriginLineArrLngth", dbl(head ? head.length / w * 100 : 0)],
7804
- ["keyOriginLineArrConc", long2(_optionalChain([head, 'optionalAccess', _194 => _194.concavity]) ? head.concavity * 100 : 0)]
7992
+ ["keyOriginLineArrConc", long2(_optionalChain([head, 'optionalAccess', _202 => _202.concavity]) ? head.concavity * 100 : 0)]
7805
7993
  ];
7806
7994
  }
7807
7995
  const m = live.transform;
@@ -7834,7 +8022,7 @@ function shapeSignature(layer) {
7834
8022
  return JSON.stringify([layer.components, layer.fill, layer.stroke, _nullishCoalesce(layer.fillRule, () => ( "nonzero")), Boolean(layer.inverted)]);
7835
8023
  }
7836
8024
  function shapeFromBlocks(blocks, width, height, dpi, notes) {
7837
- const block = (k) => _optionalChain([blocks, 'access', _195 => _195.find, 'call', _196 => _196((b) => b.key === k), 'optionalAccess', _197 => _197.data]);
8025
+ const block = (k) => _optionalChain([blocks, 'access', _203 => _203.find, 'call', _204 => _204((b) => b.key === k), 'optionalAccess', _205 => _205.data]);
7838
8026
  const vector = _nullishCoalesce(block("vsms"), () => ( block("vmsk")));
7839
8027
  const path = vector ? componentsFromVectorBlock(vector, width, height) : null;
7840
8028
  if (!path) return null;
@@ -7889,18 +8077,18 @@ function sameExtent(sub, c) {
7889
8077
  return a.every((v, i) => Math.abs(v - b[i]) < 1);
7890
8078
  }
7891
8079
  function shapeBlocks(layer, width, height, dpi, notes) {
7892
- const kept = _optionalChain([layer, 'access', _198 => _198.psd, 'optionalAccess', _199 => _199.blocks]);
7893
- if (_optionalChain([kept, 'optionalAccess', _200 => _200.length]) && _optionalChain([layer, 'access', _201 => _201.psd, 'optionalAccess', _202 => _202.signature]) === shapeSignature(layer)) return kept.map((b) => ({ key: b.key, data: b.data }));
8080
+ const kept = _optionalChain([layer, 'access', _206 => _206.psd, 'optionalAccess', _207 => _207.blocks]);
8081
+ if (_optionalChain([kept, 'optionalAccess', _208 => _208.length]) && _optionalChain([layer, 'access', _209 => _209.psd, 'optionalAccess', _210 => _210.signature]) === shapeSignature(layer)) return kept.map((b) => ({ key: b.key, data: b.data }));
7894
8082
  const out = [];
7895
8083
  out.push({ key: "vsms", data: vectorBlockForComponents(layer.components, Boolean(layer.inverted), width, height) });
7896
8084
  if (layer.fillRule === "evenodd" && layer.components.some((c) => c.subpaths.length > 1)) notes.add("Even-odd fill rules were written as nonzero (Photoshop fills shapes nonzero)");
7897
8085
  const fill = _nullishCoalesce(layer.fill, () => ( { type: "color", color: "#000000" }));
7898
- if (_optionalChain([layer, 'access', _203 => _203.fill, 'optionalAccess', _204 => _204.opacity]) !== void 0 && layer.fill.opacity < 1) notes.add("Shape fill opacity has no PSD equivalent and was written as 100 % (use the layer fill opacity)");
8086
+ if (_optionalChain([layer, 'access', _211 => _211.fill, 'optionalAccess', _212 => _212.opacity]) !== void 0 && layer.fill.opacity < 1) notes.add("Shape fill opacity has no PSD equivalent and was written as 100 % (use the layer fill opacity)");
7899
8087
  out.push({ key: "vscg", data: vscgBytes(fill) });
7900
8088
  if (layer.stroke || !layer.fill) out.push({ key: "vstk", data: vstkBytes(layer.stroke, Boolean(layer.fill), dpi) });
7901
8089
  const vogk = vogkBytes(layer.components, dpi);
7902
8090
  if (vogk) out.push({ key: "vogk", data: vogk });
7903
- if (layer.components.some((c) => _optionalChain([c, 'access', _205 => _205.live, 'optionalAccess', _206 => _206.kind]) === "line" && (c.live.startArrow && c.live.endArrow && JSON.stringify(c.live.startArrow) !== JSON.stringify(c.live.endArrow) || false))) {
8091
+ if (layer.components.some((c) => _optionalChain([c, 'access', _213 => _213.live, 'optionalAccess', _214 => _214.kind]) === "line" && (c.live.startArrow && c.live.endArrow && JSON.stringify(c.live.startArrow) !== JSON.stringify(c.live.endArrow) || false))) {
7904
8092
  notes.add("Lines with different start and end arrowheads were written with one arrowhead size (Photoshop has one)");
7905
8093
  }
7906
8094
  return out;
@@ -8109,7 +8297,7 @@ var E = {
8109
8297
  bool: (value) => ({ t: "bool", value })
8110
8298
  };
8111
8299
  function eGet(v, key) {
8112
- return _optionalChain([v, 'optionalAccess', _207 => _207.t]) === "dict" ? _optionalChain([v, 'access', _208 => _208.items, 'access', _209 => _209.find, 'call', _210 => _210(([k]) => k === key), 'optionalAccess', _211 => _211[1]]) : void 0;
8300
+ return _optionalChain([v, 'optionalAccess', _215 => _215.t]) === "dict" ? _optionalChain([v, 'access', _216 => _216.items, 'access', _217 => _217.find, 'call', _218 => _218(([k]) => k === key), 'optionalAccess', _219 => _219[1]]) : void 0;
8113
8301
  }
8114
8302
  function ePath(v, keys) {
8115
8303
  return keys.reduce((at, k) => eGet(at, k), v);
@@ -8127,7 +8315,7 @@ function eStr(v) {
8127
8315
  return v && (v.t === "string" || v.t === "name") ? v.value : void 0;
8128
8316
  }
8129
8317
  function eArray(v) {
8130
- return _optionalChain([v, 'optionalAccess', _212 => _212.t]) === "array" ? v.items : [];
8318
+ return _optionalChain([v, 'optionalAccess', _220 => _220.t]) === "array" ? v.items : [];
8131
8319
  }
8132
8320
  function eSet(d, key, value) {
8133
8321
  if (d.t !== "dict") return;
@@ -8229,7 +8417,7 @@ function fontFromPostScript(ps) {
8229
8417
  }
8230
8418
  family += suffix;
8231
8419
  const s = style.toLowerCase();
8232
- const weight = _nullishCoalesce(_optionalChain([WEIGHTS, 'access', _213 => _213.find, 'call', _214 => _214(([re]) => re.test(s)), 'optionalAccess', _215 => _215[1]]), () => ( 400));
8420
+ const weight = _nullishCoalesce(_optionalChain([WEIGHTS, 'access', _221 => _221.find, 'call', _222 => _222(([re]) => re.test(s)), 'optionalAccess', _223 => _223[1]]), () => ( 400));
8233
8421
  return { family: family || ps, weight, italic: /italic|oblique|it$/.test(s) };
8234
8422
  }
8235
8423
  var STYLE_NAMES = [
@@ -8254,7 +8442,7 @@ var hex2 = (v) => Math.round(Math.max(0, Math.min(1, v)) * 255).toString(16).pad
8254
8442
  function merged(levels) {
8255
8443
  const items = [];
8256
8444
  for (const l of levels) {
8257
- if (_optionalChain([l, 'optionalAccess', _216 => _216.t]) !== "dict") continue;
8445
+ if (_optionalChain([l, 'optionalAccess', _224 => _224.t]) !== "dict") continue;
8258
8446
  for (const [k, v] of l.items) if (!items.some(([o]) => o === k)) items.push([k, v]);
8259
8447
  }
8260
8448
  return E.dict(items);
@@ -8325,10 +8513,10 @@ function typeFromTySh(data, notes) {
8325
8513
  const t = parseTySh(data);
8326
8514
  if (!t) return null;
8327
8515
  const txtV = descGet(t.text, "Txt ");
8328
- const txt = _optionalChain([txtV, 'optionalAccess', _217 => _217.type]) === "TEXT" ? txtV.value.replace(/\0+$/, "") : void 0;
8516
+ const txt = _optionalChain([txtV, 'optionalAccess', _225 => _225.type]) === "TEXT" ? txtV.value.replace(/\0+$/, "") : void 0;
8329
8517
  const ed = descGet(t.text, "EngineData");
8330
8518
  let engine = null;
8331
- if (_optionalChain([ed, 'optionalAccess', _218 => _218.type]) === "tdta") {
8519
+ if (_optionalChain([ed, 'optionalAccess', _226 => _226.type]) === "tdta") {
8332
8520
  try {
8333
8521
  engine = parseEngineData(ed.data);
8334
8522
  } catch (e18) {
@@ -8336,12 +8524,12 @@ function typeFromTySh(data, notes) {
8336
8524
  }
8337
8525
  }
8338
8526
  const anti = descGet(t.text, "AntA");
8339
- const antiAlias = !(_optionalChain([anti, 'optionalAccess', _219 => _219.type]) === "enum" && (anti.value === "Anno" || anti.value === "antiAliasNone"));
8527
+ const antiAlias = !(_optionalChain([anti, 'optionalAccess', _227 => _227.type]) === "enum" && (anti.value === "Anno" || anti.value === "antiAliasNone"));
8340
8528
  const ornt = descGet(t.text, "Ornt");
8341
- if (_optionalChain([ornt, 'optionalAccess', _220 => _220.type]) === "enum" && ornt.value === "Vrtc") notes.add("vertical type is laid out horizontally");
8529
+ if (_optionalChain([ornt, 'optionalAccess', _228 => _228.type]) === "enum" && ornt.value === "Vrtc") notes.add("vertical type is laid out horizontally");
8342
8530
  if (t.warp) {
8343
8531
  const style = descGet(t.warp, "warpStyle");
8344
- if (_optionalChain([style, 'optionalAccess', _221 => _221.type]) === "enum" && style.value !== "warpNone") notes.add("warped text is drawn without its warp when edited");
8532
+ if (_optionalChain([style, 'optionalAccess', _229 => _229.type]) === "enum" && style.value !== "warpNone") notes.add("warped text is drawn without its warp when edited");
8345
8533
  }
8346
8534
  const edText = _nullishCoalesce(eStr(ePath(_nullishCoalesce(engine, () => ( void 0)), ["EngineDict", "Editor", "Text"])), () => ( ""));
8347
8535
  const text3 = (_nullishCoalesce(txt, () => ( edText.replace(/\r$/, "")))).replace(/\r\n?/g, "\n");
@@ -8390,7 +8578,7 @@ function typeFromTySh(data, notes) {
8390
8578
  let at = 0;
8391
8579
  runs = ssheets.map((sheet, i) => {
8392
8580
  const own = named(styleSet, sheet);
8393
- const paraDefault = _optionalChain([paraBases, 'access', _222 => _222[paraAt(at)], 'optionalAccess', _223 => _223.charDefault]);
8581
+ const paraDefault = _optionalChain([paraBases, 'access', _230 => _230[paraAt(at)], 'optionalAccess', _231 => _231.charDefault]);
8394
8582
  at += _nullishCoalesce(slens[i], () => ( 0));
8395
8583
  const d = merged([eGet(sheet, "StyleSheetData"), eGet(own, "StyleSheetData"), eGet(paraDefault, "StyleSheetData"), eGet(normalStyle, "StyleSheetData")]);
8396
8584
  return { length: _nullishCoalesce(slens[i], () => ( 0)), style: charStyle(d, fonts, notes) };
@@ -8469,8 +8657,8 @@ var fontEntry = (name) => E.dict([
8469
8657
  ["Synthetic", E.int(0)]
8470
8658
  ]);
8471
8659
  function buildEngineData(layer, template) {
8472
- const e = _optionalChain([template, 'optionalAccess', _224 => _224.t]) === "dict" ? eClone(template) : E.dict([["EngineDict", E.dict()], ["ResourceDict", E.dict()]]);
8473
- if (_optionalChain([eGet, 'call', _225 => _225(e, "EngineDict"), 'optionalAccess', _226 => _226.t]) !== "dict") eSet(e, "EngineDict", E.dict());
8660
+ const e = _optionalChain([template, 'optionalAccess', _232 => _232.t]) === "dict" ? eClone(template) : E.dict([["EngineDict", E.dict()], ["ResourceDict", E.dict()]]);
8661
+ if (_optionalChain([eGet, 'call', _233 => _233(e, "EngineDict"), 'optionalAccess', _234 => _234.t]) !== "dict") eSet(e, "EngineDict", E.dict());
8474
8662
  const dict = eGet(e, "EngineDict");
8475
8663
  const text3 = layer.text.replace(/\n/g, "\r");
8476
8664
  const edText = `${text3}\r`;
@@ -8549,7 +8737,7 @@ function buildEngineData(layer, template) {
8549
8737
  eSet(e, key, rd);
8550
8738
  }
8551
8739
  eSet(rd, "FontSet", fontSet);
8552
- if (!eGet(rd, "StyleSheetSet")) eSet(rd, "StyleSheetSet", E.array([E.dict([["Name", E.str("Normal RGB")], ["StyleSheetData", styleSheetData(_nullishCoalesce(_optionalChain([runs, 'access', _227 => _227[0], 'optionalAccess', _228 => _228.style]), () => ( _chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE)), 0)]])]));
8740
+ if (!eGet(rd, "StyleSheetSet")) eSet(rd, "StyleSheetSet", E.array([E.dict([["Name", E.str("Normal RGB")], ["StyleSheetData", styleSheetData(_nullishCoalesce(_optionalChain([runs, 'access', _235 => _235[0], 'optionalAccess', _236 => _236.style]), () => ( _chunkEGZM52EOcjs.DEFAULT_TEXT_STYLE)), 0)]])]));
8553
8741
  if (!eGet(rd, "ParagraphSheetSet")) eSet(rd, "ParagraphSheetSet", E.array([E.dict([["Name", E.str("Normal RGB")], ["DefaultStyleSheet", E.int(0)], ["Properties", paragraphProperties({})]])]));
8554
8742
  if (!eGet(rd, "TheNormalStyleSheet")) eSet(rd, "TheNormalStyleSheet", E.int(0));
8555
8743
  if (!eGet(rd, "TheNormalParagraphSheet")) eSet(rd, "TheNormalParagraphSheet", E.int(0));
@@ -8570,12 +8758,12 @@ function inkBounds2(layer) {
8570
8758
  return [Math.min(...pts.map((p) => p.x)), Math.min(...pts.map((p) => p.y)), Math.max(...pts.map((p) => p.x)), Math.max(...pts.map((p) => p.y))];
8571
8759
  }
8572
8760
  function tyShForLayer(layer) {
8573
- const raw = _optionalChain([layer, 'access', _229 => _229.psd, 'optionalAccess', _230 => _230.tySh]);
8574
- if (raw && _optionalChain([layer, 'access', _231 => _231.psd, 'optionalAccess', _232 => _232.signature]) === typeSignature(layer)) return raw;
8761
+ const raw = _optionalChain([layer, 'access', _237 => _237.psd, 'optionalAccess', _238 => _238.tySh]);
8762
+ if (raw && _optionalChain([layer, 'access', _239 => _239.psd, 'optionalAccess', _240 => _240.signature]) === typeSignature(layer)) return raw;
8575
8763
  const old = raw ? parseTySh(raw) : null;
8576
8764
  const oldEd = old ? descGet(old.text, "EngineData") : void 0;
8577
8765
  let template = null;
8578
- if (_optionalChain([oldEd, 'optionalAccess', _233 => _233.type]) === "tdta") {
8766
+ if (_optionalChain([oldEd, 'optionalAccess', _241 => _241.type]) === "tdta") {
8579
8767
  try {
8580
8768
  template = parseEngineData(oldEd.data);
8581
8769
  } catch (e19) {
@@ -8607,8 +8795,8 @@ function tyShForLayer(layer) {
8607
8795
  set("boundingBox", rect("boundingBox"));
8608
8796
  if (!descGet(text3, "TextIndex")) set("TextIndex", { type: "long", value: 0 });
8609
8797
  set("EngineData", { type: "tdta", data: writeEngineData(engine) });
8610
- const warpStyle = _optionalChain([old, 'optionalAccess', _234 => _234.warp]) ? descGet(old.warp, "warpStyle") : void 0;
8611
- const warp = _optionalChain([old, 'optionalAccess', _235 => _235.warp]) && _optionalChain([warpStyle, 'optionalAccess', _236 => _236.type]) === "enum" && warpStyle.value === "warpNone" ? old.warp : null;
8798
+ const warpStyle = _optionalChain([old, 'optionalAccess', _242 => _242.warp]) ? descGet(old.warp, "warpStyle") : void 0;
8799
+ const warp = _optionalChain([old, 'optionalAccess', _243 => _243.warp]) && _optionalChain([warpStyle, 'optionalAccess', _244 => _244.type]) === "enum" && warpStyle.value === "warpNone" ? old.warp : null;
8612
8800
  return writeTySh({ transform: textMatrix(layer), text: text3, warp, tail: new Uint8Array(16) });
8613
8801
  }
8614
8802
 
@@ -8622,15 +8810,15 @@ var textV = (value) => ({ type: "TEXT", value });
8622
8810
  var obj2 = (d) => ({ type: "Objc", value: d });
8623
8811
  var text = (d, key) => {
8624
8812
  const v = descGet(d, key);
8625
- return _optionalChain([v, 'optionalAccess', _237 => _237.type]) === "TEXT" ? v.value : void 0;
8813
+ return _optionalChain([v, 'optionalAccess', _245 => _245.type]) === "TEXT" ? v.value : void 0;
8626
8814
  };
8627
8815
  var enumOf2 = (d, key) => {
8628
8816
  const v = descGet(d, key);
8629
- return _optionalChain([v, 'optionalAccess', _238 => _238.type]) === "enum" ? v.value : void 0;
8817
+ return _optionalChain([v, 'optionalAccess', _246 => _246.type]) === "enum" ? v.value : void 0;
8630
8818
  };
8631
8819
  var numbers = (d, key) => {
8632
8820
  const v = descGet(d, key);
8633
- if (_optionalChain([v, 'optionalAccess', _239 => _239.type]) !== "VlLs") return null;
8821
+ if (_optionalChain([v, 'optionalAccess', _247 => _247.type]) !== "VlLs") return null;
8634
8822
  const out = [];
8635
8823
  for (const it of v.items) {
8636
8824
  if (it.type === "doub" || it.type === "UntF" || it.type === "long") out.push(it.value);
@@ -8825,8 +9013,8 @@ function filterMaskItem(placed, mask, area) {
8825
9013
  const painted = _chunkCWM3CUUXcjs.contentBounds.call(void 0, mask.surface);
8826
9014
  let b = _nullishCoalesce(painted, () => ( { x: 0, y: 0, width: 1, height: 1 }));
8827
9015
  if (mask.defaultValue !== 255 && area) {
8828
- const x0 = Math.min(area.x, _nullishCoalesce(_optionalChain([painted, 'optionalAccess', _240 => _240.x]), () => ( area.x)));
8829
- const y0 = Math.min(area.y, _nullishCoalesce(_optionalChain([painted, 'optionalAccess', _241 => _241.y]), () => ( area.y)));
9016
+ const x0 = Math.min(area.x, _nullishCoalesce(_optionalChain([painted, 'optionalAccess', _248 => _248.x]), () => ( area.x)));
9017
+ const y0 = Math.min(area.y, _nullishCoalesce(_optionalChain([painted, 'optionalAccess', _249 => _249.y]), () => ( area.y)));
8830
9018
  const x1 = Math.max(area.x + area.width, painted ? painted.x + painted.width : 0);
8831
9019
  const y1 = Math.max(area.y + area.height, painted ? painted.y + painted.height : 0);
8832
9020
  b = { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
@@ -8846,7 +9034,7 @@ function filterMaskItem(placed, mask, area) {
8846
9034
  }
8847
9035
  var warpStyleOf = (name) => {
8848
9036
  if (!name.startsWith("warp")) return null;
8849
- const s = _optionalChain([name, 'access', _242 => _242[4], 'optionalAccess', _243 => _243.toLowerCase, 'call', _244 => _244()]) + name.slice(5);
9037
+ const s = _optionalChain([name, 'access', _250 => _250[4], 'optionalAccess', _251 => _251.toLowerCase, 'call', _252 => _252()]) + name.slice(5);
8850
9038
  return _chunkEGZM52EOcjs.WARP_STYLES.includes(s) ? s : null;
8851
9039
  };
8852
9040
  function warpFromDescriptor(w, contents) {
@@ -8868,7 +9056,7 @@ function warpFromDescriptor(w, contents) {
8868
9056
  if (!arr || arr.type !== "ObAr") return void 0;
8869
9057
  const xs = descGet(arr.body, "Hrzn");
8870
9058
  const ys = descGet(arr.body, "Vrtc");
8871
- if (_optionalChain([xs, 'optionalAccess', _245 => _245.type]) !== "UnFl" || _optionalChain([ys, 'optionalAccess', _246 => _246.type]) !== "UnFl" || xs.values.length !== 16 || ys.values.length !== 16) return void 0;
9059
+ if (_optionalChain([xs, 'optionalAccess', _253 => _253.type]) !== "UnFl" || _optionalChain([ys, 'optionalAccess', _254 => _254.type]) !== "UnFl" || xs.values.length !== 16 || ys.values.length !== 16) return void 0;
8872
9060
  mesh = { us: [0, 1], vs: [0, 1], points: xs.values.map((x, i) => ({ x, y: ys.values[i] })) };
8873
9061
  const px2 = mesh.points.map((p) => p.x);
8874
9062
  const py = mesh.points.map((p) => p.y);
@@ -9035,13 +9223,13 @@ function blendOptions(f) {
9035
9223
  function smartFiltersFromPsd(fx, newId, notes) {
9036
9224
  const filters = [];
9037
9225
  const list2 = descGet(fx, "filterFXList");
9038
- for (const v of _optionalChain([list2, 'optionalAccess', _247 => _247.type]) === "VlLs" ? list2.items : []) {
9226
+ for (const v of _optionalChain([list2, 'optionalAccess', _255 => _255.type]) === "VlLs" ? list2.items : []) {
9039
9227
  if (v.type !== "Objc" && v.type !== "GlbO") continue;
9040
9228
  const item = v.value;
9041
9229
  const { blend, opacity } = blendOptionsOf(item);
9042
9230
  const enabled = descBool(item, "enab") !== false;
9043
9231
  const fltr = descObject(item, "Fltr");
9044
- const radius = _optionalChain([fltr, 'optionalAccess', _248 => _248.classId]) === BOX_BLUR.classId ? descNumber(fltr, "Rds ") : void 0;
9232
+ const radius = _optionalChain([fltr, 'optionalAccess', _256 => _256.classId]) === BOX_BLUR.classId ? descNumber(fltr, "Rds ") : void 0;
9045
9233
  if (radius !== void 0 && radius >= 0 && radius <= 50) {
9046
9234
  filters.push({ id: newId(), kind: "blur", enabled, radius, blend, opacity });
9047
9235
  continue;
@@ -9394,7 +9582,7 @@ function readPsd(bytes) {
9394
9582
  return { header, colorModeData, resources, layers, mergedAlpha, globalBlocks, imageCompression, imageData: r.rest() };
9395
9583
  }
9396
9584
  function layerBlock(rec, key) {
9397
- return _optionalChain([rec, 'access', _249 => _249.blocks, 'access', _250 => _250.find, 'call', _251 => _251((b) => b.key === key), 'optionalAccess', _252 => _252.data]);
9585
+ return _optionalChain([rec, 'access', _257 => _257.blocks, 'access', _258 => _258.find, 'call', _259 => _259((b) => b.key === key), 'optionalAccess', _260 => _260.data]);
9398
9586
  }
9399
9587
  function layerName(rec) {
9400
9588
  const luni = layerBlock(rec, "luni");
@@ -9425,7 +9613,7 @@ function u8Block(rec, key) {
9425
9613
  function layerTree(file) {
9426
9614
  const stack = [[]];
9427
9615
  file.layers.forEach((rec, index) => {
9428
- const kind = _nullishCoalesce(_optionalChain([sectionDivider, 'call', _253 => _253(rec), 'optionalAccess', _254 => _254.kind]), () => ( SECTION_OTHER));
9616
+ const kind = _nullishCoalesce(_optionalChain([sectionDivider, 'call', _261 => _261(rec), 'optionalAccess', _262 => _262.kind]), () => ( SECTION_OTHER));
9429
9617
  if (kind === SECTION_DIVIDER) {
9430
9618
  stack.push([]);
9431
9619
  } else if (kind === SECTION_OPEN || kind === SECTION_CLOSED) {
@@ -9443,7 +9631,7 @@ function layerTree(file) {
9443
9631
  }
9444
9632
  function channelRect(rec, id) {
9445
9633
  if (id === CHANNEL_USER_MASK && rec.mask) return rec.mask.rect;
9446
- if (id === CHANNEL_REAL_USER_MASK && rec.mask) return _nullishCoalesce(_optionalChain([rec, 'access', _255 => _255.mask, 'access', _256 => _256.real, 'optionalAccess', _257 => _257.rect]), () => ( rec.mask.rect));
9634
+ if (id === CHANNEL_REAL_USER_MASK && rec.mask) return _nullishCoalesce(_optionalChain([rec, 'access', _263 => _263.mask, 'access', _264 => _264.real, 'optionalAccess', _265 => _265.rect]), () => ( rec.mask.rect));
9447
9635
  return rec.rect;
9448
9636
  }
9449
9637
  function decodeLayerChannel(file, rec, id) {
@@ -9461,7 +9649,7 @@ function decodeMergedImage(file) {
9461
9649
  return decodePlanes(file.imageCompression, file.imageData, { planes: channels, width, height, depth, psb });
9462
9650
  }
9463
9651
  function resource(file, id) {
9464
- return _optionalChain([file, 'access', _258 => _258.resources, 'access', _259 => _259.find, 'call', _260 => _260((r) => r.id === id), 'optionalAccess', _261 => _261.data]);
9652
+ return _optionalChain([file, 'access', _266 => _266.resources, 'access', _267 => _267.find, 'call', _268 => _268((r) => r.id === id), 'optionalAccess', _269 => _269.data]);
9465
9653
  }
9466
9654
  function resolution(file) {
9467
9655
  const d = resource(file, 1005);
@@ -10188,9 +10376,22 @@ function baseProps(ctx, rec, name, notes) {
10188
10376
  ctx.warn.add("Artboards are not supported; they came in as plain groups, without their background colour and clipping", name);
10189
10377
  notes.push("artboard imported as a group");
10190
10378
  }
10191
- if (rec.blocks.some((b) => VECTOR_KEYS.includes(b.key)) && psdKind(rec) === "pixel") {
10192
- ctx.warn.add("Vector masks are not supported and were ignored", name);
10193
- notes.push("vector mask ignored");
10379
+ const vectorBlock = psdKind(rec) === "shape" ? void 0 : _nullishCoalesce(rec.blocks.find((b) => b.key === "vsms"), () => ( rec.blocks.find((b) => b.key === "vmsk")));
10380
+ if (vectorBlock) {
10381
+ const read2 = componentsFromVectorBlock(vectorBlock.data, ctx.file.header.width, ctx.file.header.height);
10382
+ if (read2) {
10383
+ const vm = { components: read2.components };
10384
+ if (read2.inverted) vm.inverted = true;
10385
+ if (read2.flags & VMSK_NOT_LINKED) vm.linked = false;
10386
+ if (read2.flags & VMSK_DISABLED) vm.enabled = false;
10387
+ const m = rec.mask;
10388
+ if (_optionalChain([m, 'optionalAccess', _270 => _270.vectorDensity]) !== void 0 && m.vectorDensity < 255) vm.density = percent(m.vectorDensity);
10389
+ if (_optionalChain([m, 'optionalAccess', _271 => _271.vectorFeather]) !== void 0 && m.vectorFeather > 0) vm.feather = Math.min(1e3, m.vectorFeather);
10390
+ props.vectorMask = vm;
10391
+ } else {
10392
+ ctx.warn.add("A vector mask could not be read and was ignored", name);
10393
+ notes.push("vector mask ignored");
10394
+ }
10194
10395
  }
10195
10396
  return props;
10196
10397
  }
@@ -10245,7 +10446,7 @@ function importNode(ctx, node, depth) {
10245
10446
  if (node.children) {
10246
10447
  const props2 = baseProps(ctx, rec, name, notes);
10247
10448
  const divider = sectionDivider(rec);
10248
- const key = _nullishCoalesce(_optionalChain([divider, 'optionalAccess', _262 => _262.blendKey]), () => ( rec.blendKey));
10449
+ const key = _nullishCoalesce(_optionalChain([divider, 'optionalAccess', _272 => _272.blendKey]), () => ( rec.blendKey));
10249
10450
  const groupBlend = key === "pass" ? "pass-through" : _nullishCoalesce(PSD_BLEND_KEYS[key], () => ( "normal"));
10250
10451
  const children = [];
10251
10452
  for (const child of node.children) {
@@ -10255,7 +10456,7 @@ function importNode(ctx, node, depth) {
10255
10456
  const group = { type: "group", id: ctx.newId(name), ...props2, blend: groupBlend, children };
10256
10457
  const effects2 = recordEffects(ctx, rec, name, notes, true);
10257
10458
  if (effects2) group.effects = effects2;
10258
- if (_optionalChain([divider, 'optionalAccess', _263 => _263.kind]) === SECTION_CLOSED) group.collapsed = true;
10459
+ if (_optionalChain([divider, 'optionalAccess', _273 => _273.kind]) === SECTION_CLOSED) group.collapsed = true;
10259
10460
  const mask2 = recordMask(ctx, rec, name);
10260
10461
  if (mask2) group.mask = mask2;
10261
10462
  entry.type = "group";
@@ -10478,7 +10679,7 @@ function importSmart(ctx, rec, name, notes, props) {
10478
10679
  const file = ctx.linked.get(placed.idnt);
10479
10680
  contents = {
10480
10681
  id: placed.idnt || ctx.newId(`${name}-contents`),
10481
- name: _optionalChain([file, 'optionalAccess', _264 => _264.name]) || `${name}.png`,
10682
+ name: _optionalChain([file, 'optionalAccess', _274 => _274.name]) || `${name}.png`,
10482
10683
  width,
10483
10684
  height,
10484
10685
  kind: "raster",
@@ -10635,7 +10836,7 @@ function psdToLayers(file, options = {}) {
10635
10836
  if (mode !== "rgb" && header.depth > 8 && header.colorMode !== MODE_INDEXED && header.colorMode !== MODE_BITMAP) {
10636
10837
  warn.extra.push(`The file is ${header.depth}-bit ${mode}; it was converted to ${header.depth}-bit RGB.`);
10637
10838
  } else if (mode !== "rgb" || header.depth !== 8 && header.depth !== 16 && header.depth !== 32) {
10638
- const how = header.colorMode === MODE_CMYK ? ` through ${_nullishCoalesce(_optionalChain([cmykProfile, 'optionalAccess', _265 => _265.name]), () => ( "its profile"))}` : "";
10839
+ const how = header.colorMode === MODE_CMYK ? ` through ${_nullishCoalesce(_optionalChain([cmykProfile, 'optionalAccess', _275 => _275.name]), () => ( "its profile"))}` : "";
10639
10840
  warn.extra.push(`The file is ${header.depth}-bit ${mode}; it was converted to 8-bit RGB${how}.`);
10640
10841
  }
10641
10842
  let layers = [];
@@ -10752,15 +10953,15 @@ var pct = (d, key, fallback) => num3(d, key, fallback * 100) / 100;
10752
10953
  var bool = (d, key) => descBool(d, key) === true;
10753
10954
  var enumOf3 = (d, key) => {
10754
10955
  const v = descGet(d, key);
10755
- return _optionalChain([v, 'optionalAccess', _266 => _266.type]) === "enum" ? v.value : void 0;
10956
+ return _optionalChain([v, 'optionalAccess', _276 => _276.type]) === "enum" ? v.value : void 0;
10756
10957
  };
10757
10958
  var text2 = (d, key) => {
10758
10959
  const v = d ? descGet(d, key) : void 0;
10759
- return _optionalChain([v, 'optionalAccess', _267 => _267.type]) === "TEXT" ? v.value : "";
10960
+ return _optionalChain([v, 'optionalAccess', _277 => _277.type]) === "TEXT" ? v.value : "";
10760
10961
  };
10761
10962
  var list = (d, key) => {
10762
10963
  const v = descGet(d, key);
10763
- if (_optionalChain([v, 'optionalAccess', _268 => _268.type]) !== "VlLs") return [];
10964
+ if (_optionalChain([v, 'optionalAccess', _278 => _278.type]) !== "VlLs") return [];
10764
10965
  return v.items.flatMap((it) => it.type === "Objc" || it.type === "GlbO" ? [it.value] : []);
10765
10966
  };
10766
10967
  var clamp3 = (v, lo, hi) => Number.isFinite(v) ? Math.min(hi, Math.max(lo, v)) : lo;
@@ -10830,8 +11031,8 @@ function contourOf(d, key) {
10830
11031
  return { name, points };
10831
11032
  }
10832
11033
  function contourDesc(c) {
10833
- const name = _nullishCoalesce(_optionalChain([c, 'optionalAccess', _269 => _269.name]), () => ( "Linear"));
10834
- const points = _nullishCoalesce(_optionalChain([c, 'optionalAccess', _270 => _270.points]), () => ( [
11034
+ const name = _nullishCoalesce(_optionalChain([c, 'optionalAccess', _279 => _279.name]), () => ( "Linear"));
11035
+ const points = _nullishCoalesce(_optionalChain([c, 'optionalAccess', _280 => _280.points]), () => ( [
10835
11036
  { input: 0, output: 0 },
10836
11037
  { input: 1, output: 1 }
10837
11038
  ]));
@@ -10866,7 +11067,7 @@ function gradientOf(d, notes) {
10866
11067
  { position: 0, color: "#000000" },
10867
11068
  { position: 1, color: "#ffffff" }
10868
11069
  ],
10869
- style: _nullishCoalesce(_optionalChain([GRADIENT_STYLES, 'access', _271 => _271.find, 'call', _272 => _272(([, id]) => id === enumOf3(d, "Type")), 'optionalAccess', _273 => _273[0]]), () => ( "linear")),
11070
+ style: _nullishCoalesce(_optionalChain([GRADIENT_STYLES, 'access', _281 => _281.find, 'call', _282 => _282(([, id]) => id === enumOf3(d, "Type")), 'optionalAccess', _283 => _283[0]]), () => ( "linear")),
10870
11071
  angle: clamp3(num3(d, "Angl", 90), -360, 360),
10871
11072
  scale: clamp3(pct(d, "Scl ", 1), 0.1, 1.5),
10872
11073
  reverse: bool(d, "Rvrs"),
@@ -10920,7 +11121,7 @@ function gradientItems(g) {
10920
11121
  )
10921
11122
  )
10922
11123
  };
10923
- const op = _optionalChain([g, 'access', _274 => _274.opacityStops, 'optionalAccess', _275 => _275.length]) ? g.opacityStops : g.stops.map((s) => ({ position: s.position, opacity: 1 }));
11124
+ const op = _optionalChain([g, 'access', _284 => _284.opacityStops, 'optionalAccess', _285 => _285.length]) ? g.opacityStops : g.stops.map((s) => ({ position: s.position, opacity: 1 }));
10924
11125
  const trns = {
10925
11126
  type: "VlLs",
10926
11127
  items: op.map(
@@ -11417,9 +11618,9 @@ function prepareNestedLayers(layers) {
11417
11618
  if (l.type === "annotation") continue;
11418
11619
  let next = l;
11419
11620
  if (l.type === "group") next = { ...l, children: prepareNestedLayers(l.children) };
11420
- else if (l.type === "pixel" && (_optionalChain([l, 'access', _276 => _276.filters, 'optionalAccess', _277 => _277.length]) || l.source === "document")) {
11621
+ else if (l.type === "pixel" && (_optionalChain([l, 'access', _286 => _286.filters, 'optionalAccess', _287 => _287.length]) || l.source === "document")) {
11421
11622
  const p = { ...l };
11422
- if (_optionalChain([l, 'access', _278 => _278.filters, 'optionalAccess', _279 => _279.some, 'call', _280 => _280(isActiveFilter)])) {
11623
+ if (_optionalChain([l, 'access', _288 => _288.filters, 'optionalAccess', _289 => _289.some, 'call', _290 => _290(isActiveFilter)])) {
11423
11624
  const b = l.surface.bounds;
11424
11625
  if (b) {
11425
11626
  const r = { x: b.x + l.offset.x - 64, y: b.y + l.offset.y - 64, width: b.width + 128, height: b.height + 128 };
@@ -11436,7 +11637,7 @@ function prepareNestedLayers(layers) {
11436
11637
  delete p.source;
11437
11638
  next = p;
11438
11639
  }
11439
- if (_optionalChain([next, 'access', _281 => _281.mask, 'optionalAccess', _282 => _282.source])) {
11640
+ if (_optionalChain([next, 'access', _291 => _291.mask, 'optionalAccess', _292 => _292.source])) {
11440
11641
  next = { ...next };
11441
11642
  delete next.mask;
11442
11643
  }
@@ -11539,10 +11740,17 @@ function exportPsd(input) {
11539
11740
  if (fx) blocks.push(fx);
11540
11741
  const locks = lockBits(layer);
11541
11742
  if (locks) blocks.push({ key: "lspf", data: u32Bytes(locks >>> 0) });
11743
+ const vm = layer.type !== "shape" ? layer.vectorMask : void 0;
11744
+ if (vm) {
11745
+ const flags = (vm.linked === false ? VMSK_NOT_LINKED : 0) | (vm.enabled === false ? VMSK_DISABLED : 0);
11746
+ blocks.push({ key: "vmsk", data: vectorBlockForComponents(vm.components, vm.inverted === true, width, height, flags) });
11747
+ if ((_nullishCoalesce(vm.density, () => ( 1))) !== 1 || (_nullishCoalesce(vm.feather, () => ( 0))) > 0) note("Vector mask density and feather are not written; the paths are", layer.name);
11748
+ if (vm.fillRule === "evenodd") note("Vector masks are written with the nonzero fill rule (Photoshop has no even-odd paths)", layer.name);
11749
+ }
11542
11750
  return {
11543
11751
  opacity: Math.round(Math.min(1, Math.max(0, layer.opacity)) * 255),
11544
11752
  clipping: layer.clipped ? 1 : 0,
11545
- flags: (layer.visible ? 0 : LAYER_FLAG_HIDDEN) | (_optionalChain([layer, 'access', _283 => _283.locks, 'optionalAccess', _284 => _284.transparency]) ? LAYER_FLAG_TRANSPARENCY_PROTECTED : 0),
11753
+ flags: (layer.visible ? 0 : LAYER_FLAG_HIDDEN) | (_optionalChain([layer, 'access', _293 => _293.locks, 'optionalAccess', _294 => _294.transparency]) ? LAYER_FLAG_TRANSPARENCY_PROTECTED : 0),
11546
11754
  legacyName: name,
11547
11755
  blocks
11548
11756
  };
@@ -11599,7 +11807,7 @@ function exportPsd(input) {
11599
11807
  }
11600
11808
  case "pixel": {
11601
11809
  if (layer.source === "document") throw new PsdError(`Layer "${layer.name}" reads the document image; resolve its pixels before export.`);
11602
- if (_optionalChain([layer, 'access', _285 => _285.filters, 'optionalAccess', _286 => _286.some, 'call', _287 => _287(isActiveFilter)])) throw new PsdError(`Layer "${layer.name}" has live filters; bake them before export.`);
11810
+ if (_optionalChain([layer, 'access', _295 => _295.filters, 'optionalAccess', _296 => _296.some, 'call', _297 => _297(isActiveFilter)])) throw new PsdError(`Layer "${layer.name}" has live filters; bake them before export.`);
11603
11811
  const extra = [];
11604
11812
  if (layer.fillOpacity !== void 0 && layer.fillOpacity < 1) {
11605
11813
  extra.push({ key: "iOpa", data: Uint8Array.from([Math.round(Math.max(0, layer.fillOpacity) * 255), 0, 0, 0]) });
@@ -11631,7 +11839,7 @@ function exportPsd(input) {
11631
11839
  if (c.linked) note("Linked smart objects were embedded (their preview is written as the contents)", layer.name);
11632
11840
  linkedFiles.set(idnt, smartContentsFile(c));
11633
11841
  }
11634
- let placedId = _nullishCoalesce(_optionalChain([layer, 'access', _288 => _288.psd, 'optionalAccess', _289 => _289.placed]), () => ( psdUuid(`${layer.id}:placed`)));
11842
+ let placedId = _nullishCoalesce(_optionalChain([layer, 'access', _298 => _298.psd, 'optionalAccess', _299 => _299.placed]), () => ( psdUuid(`${layer.id}:placed`)));
11635
11843
  if (placedIds.has(placedId)) placedId = psdUuid(`${layer.id}:placed:${placedIds.size}`);
11636
11844
  placedIds.add(placedId);
11637
11845
  if (placedUnchanged(layer, idnt, placedId)) {
@@ -11641,12 +11849,12 @@ function exportPsd(input) {
11641
11849
  const filterFX = layer.smartFilters ? filterFXDescriptor(layer.smartFilters, dropped) : void 0;
11642
11850
  if (dropped.length) note("Develop smart filters have no Photoshop filter and were left out of the filter list (the layer\u2019s pixels still show them)", layer.name);
11643
11851
  const raw = layer.psd && layer.psd.key !== "PlLd" ? parsePlaced(layer.psd.key, layer.psd.data) : null;
11644
- const spec = { idnt, placed: placedId, placement: layer.placement, size: { width: c.width, height: c.height }, filterFX, template: _optionalChain([raw, 'optionalAccess', _290 => _290.descriptor]) };
11852
+ const spec = { idnt, placed: placedId, placement: layer.placement, size: { width: c.width, height: c.height }, filterFX, template: _optionalChain([raw, 'optionalAccess', _300 => _300.descriptor]) };
11645
11853
  const wnotes = [];
11646
11854
  extra.push({ key: "PlLd", data: plldBytes(spec) }, { key: "SoLd", data: soldBytes(spec, wnotes) });
11647
11855
  for (const n2 of wnotes) note(`A smart object: ${n2}`, layer.name);
11648
11856
  }
11649
- const fm = _optionalChain([layer, 'access', _291 => _291.smartFilters, 'optionalAccess', _292 => _292.mask]);
11857
+ const fm = _optionalChain([layer, 'access', _301 => _301.smartFilters, 'optionalAccess', _302 => _302.mask]);
11650
11858
  if (fm && !fm.source) filterItems.push(filterMaskItem(placedId, fm, { x: 0, y: 0, width, height }));
11651
11859
  const rec = { ...common2(layer, extra), rect: EMPTY_RECT, channels: [], blendKey: _nullishCoalesce(BLEND_TO_PSD[layer.blend], () => ( "norm")) };
11652
11860
  const bounds = _chunkCWM3CUUXcjs.contentBounds.call(void 0, layer.surface);
@@ -11674,8 +11882,8 @@ function exportPsd(input) {
11674
11882
  const losses = /* @__PURE__ */ new Set();
11675
11883
  for (const b of shapeBlocks(layer, width, height, _nullishCoalesce(input.resolution, () => ( 72)), losses)) extra.push({ key: b.key, data: padEven(b.data) });
11676
11884
  for (const n2 of losses) note(n2, layer.name);
11677
- if (_optionalChain([layer, 'access', _293 => _293.fill, 'optionalAccess', _294 => _294.type]) === "pattern") patternIds2.add(layer.fill.patternId);
11678
- if (_optionalChain([layer, 'access', _295 => _295.stroke, 'optionalAccess', _296 => _296.paint, 'access', _297 => _297.type]) === "pattern") patternIds2.add(layer.stroke.paint.patternId);
11885
+ if (_optionalChain([layer, 'access', _303 => _303.fill, 'optionalAccess', _304 => _304.type]) === "pattern") patternIds2.add(layer.fill.patternId);
11886
+ if (_optionalChain([layer, 'access', _305 => _305.stroke, 'optionalAccess', _306 => _306.paint, 'access', _307 => _307.type]) === "pattern") patternIds2.add(layer.stroke.paint.patternId);
11679
11887
  } else {
11680
11888
  extra.push({ key: "TySh", data: padEven(tyShForLayer(layer)) });
11681
11889
  }
@@ -11743,7 +11951,7 @@ function exportPsd(input) {
11743
11951
  { id: 1005, name: "", data: rw.result() },
11744
11952
  { id: 1057, name: "", data: version.result() }
11745
11953
  ];
11746
- if (_optionalChain([input, 'access', _298 => _298.iccProfile, 'optionalAccess', _299 => _299.length])) resources.push({ id: 1039, name: "", data: input.iccProfile });
11954
+ if (_optionalChain([input, 'access', _308 => _308.iccProfile, 'optionalAccess', _309 => _309.length])) resources.push({ id: 1039, name: "", data: input.iccProfile });
11747
11955
  resources.push(...alphaChannelResources(_nullishCoalesce(input.alphaChannels, () => ( []))));
11748
11956
  if (input.globalLight) {
11749
11957
  const i32 = (v) => {
@@ -12163,4 +12371,14 @@ function exportPsd(input) {
12163
12371
 
12164
12372
 
12165
12373
 
12166
- exports.LEGACY_PROCESS_VERSION = LEGACY_PROCESS_VERSION; exports.LATEST_PROCESS_VERSION = LATEST_PROCESS_VERSION; exports.normalizeProcessVersion = normalizeProcessVersion; exports.srgbToLinear = srgbToLinear; exports.linearToSrgb = linearToSrgb; exports.LUMA_709 = LUMA_709; exports.IDENTITY_MATRIX3 = IDENTITY_MATRIX3; exports.mulMatrix3 = mulMatrix3; exports.applyMatrix3 = applyMatrix3; exports.invertMatrix3 = invertMatrix3; exports.D65 = D65; exports.bradfordAdaptation = bradfordAdaptation; exports.wbMatrix = wbMatrix; exports.linearSrgbToXy = linearSrgbToXy; exports.TINT_SCALE = TINT_SCALE; exports.MIN_KELVIN = MIN_KELVIN; exports.MAX_KELVIN = MAX_KELVIN; exports.xyToUv = xyToUv; exports.uvToXy = uvToXy; exports.tempTintToXy = tempTintToXy; exports.xyToTempTint = xyToTempTint; exports.AS_SHOT_KELVIN = AS_SHOT_KELVIN; exports.MIRED_PER_TEMPERATURE_UNIT = MIRED_PER_TEMPERATURE_UNIT; exports.temperatureToKelvin = temperatureToKelvin; exports.kelvinToTemperature = kelvinToTemperature; exports.whiteBalanceMatrix = whiteBalanceMatrix; exports.whiteBalanceFromSample = whiteBalanceFromSample; exports.TONE_LUT_SIZE = TONE_LUT_SIZE; exports.toneCurve = toneCurve; exports.buildToneLut = buildToneLut; exports.sampleToneLut = sampleToneLut; exports.normalizeAngle = normalizeAngle; exports.isQuarterTurnSwapped = isQuarterTurnSwapped; exports.getRotatedSize = getRotatedSize; exports.projectImagePoint = projectImagePoint; exports.unprojectCanvasPoint = unprojectCanvasPoint; exports.applyImageProjectionToContext = applyImageProjectionToContext; exports.projectImageRect = projectImageRect; exports.clampCropToImage = clampCropToImage; exports.getViewportProjection = getViewportProjection; exports.getViewportMetrics = getViewportMetrics; exports.canvasToImagePoint = canvasToImagePoint; exports.imageToCanvasPoint = imageToCanvasPoint; exports.mapCropHandle = mapCropHandle; exports.hitTestCrop = hitTestCrop; exports.getCropCursor = getCropCursor; exports.calculateCropDrag = calculateCropDrag; exports.getAnnotationBounds = getAnnotationBounds; exports.hitTestAnnotation = hitTestAnnotation; exports.SELECTION_MODES = SELECTION_MODES; exports.isSelectionMode = isSelectionMode; exports.parseSelectionMode = parseSelectionMode; exports.computeSelectionBounds = computeSelectionBounds; exports.selectionFromTiles = selectionFromTiles; exports.createSelectionMask = createSelectionMask; exports.selectionFromRegion = selectionFromRegion; exports.fullSelection = fullSelection; exports.isSelectionEmpty = isSelectionEmpty; exports.selectionValueAt = selectionValueAt; exports.coverageToByte = coverageToByte; exports.selectionFromCoverage = selectionFromCoverage; exports.selectionToCoverage = selectionToCoverage; exports.selectionArea = selectionArea; exports.combineSelections = combineSelections; exports.invertSelection = invertSelection; exports.resizeSelection = resizeSelection; exports.selectionFromPixels = selectionFromPixels; exports.selectionToPixels = selectionToPixels; exports.encodeSelectionRle = encodeSelectionRle; exports.decodeSelectionRle = decodeSelectionRle; exports.serializeSelection = serializeSelection; exports.deserializeSelection = deserializeSelection; exports.hashMaskContent = hashMaskContent; exports.EMPTY_DISTANCE = EMPTY_DISTANCE; exports.distanceTransform = distanceTransform; exports.expandCoverage = expandCoverage; exports.contractCoverage = contractCoverage; exports.borderCoverage = borderCoverage; exports.smoothCoverage = smoothCoverage; exports.featherCoverage = featherCoverage; exports.greyMorphology = greyMorphology; exports.shiftCoverage = shiftCoverage; exports.SELECTION_MODIFY_OPS = SELECTION_MODIFY_OPS; exports.modifySelection = modifySelection; exports.layerMaskSelection = layerMaskSelection; exports.normalizeLayerMask = normalizeLayerMask; exports.layerMaskFromSelection = layerMaskFromSelection; exports.updateLayerMaskProps = updateLayerMaskProps; exports.decodeLayerMask = decodeLayerMask; exports.layerMaskKey = layerMaskKey; exports.layerMaskCoverage = layerMaskCoverage; exports.projectMaskCoverage = projectMaskCoverage; exports.buildLayerMaskPlanes = buildLayerMaskPlanes; exports.ADJUSTMENT_LUT_SIZE = ADJUSTMENT_LUT_SIZE; exports.sampleLut = sampleLut; exports.ADJUSTMENT_KINDS = ADJUSTMENT_KINDS; exports.isAdjustmentKind = isAdjustmentKind; exports.adjustmentKindLabel = adjustmentKindLabel; exports.HUE_RANGE_LABELS = HUE_RANGE_LABELS; exports.neutralHueRange = neutralHueRange; exports.identityCurve = identityCurve; exports.identityLevels = identityLevels; exports.defaultAdjustmentParams = defaultAdjustmentParams; exports.createAdjustmentLayer = createAdjustmentLayer; exports.normalizeAdjustmentLayer = normalizeAdjustmentLayer; exports.normalizeAdjustmentLayers = normalizeAdjustmentLayers; exports.curveLutFromLevels = curveLutFromLevels; exports.levelsValue = levelsValue; exports.rgbToHsl = rgbToHsl; exports.hslToRgb = hslToRgb; exports.hueRangeWeight = hueRangeWeight; exports.hueRangeTables = hueRangeTables; exports.hueSaturation = hueSaturation; exports.rangeLightness = rangeLightness; exports.VIBRANCE_GREY = VIBRANCE_GREY; exports.vibranceLinear = vibranceLinear; exports.vibrancePixel = vibrancePixel; exports.colorBalanceChannel = colorBalanceChannel; exports.blackWhiteGray = blackWhiteGray; exports.D50 = D50; exports.XYZ_D50_TO_SRGB = XYZ_D50_TO_SRGB; exports.photoFilterMatrix = photoFilterMatrix; exports.posterizeValue = posterizeValue; exports.rgbToGray = rgbToGray; exports.hexToRgb = hexToRgb; exports.toneLuts = toneLuts; exports.compileAdjustmentLayer = compileAdjustmentLayer; exports.activeAdjustmentLayers = activeAdjustmentLayers; exports.evaluateAdjustmentLayers = evaluateAdjustmentLayers; exports.applyAdjustmentLayers = applyAdjustmentLayers; exports.applyAdjustmentLayersFloat = applyAdjustmentLayersFloat; exports.adjustmentLayersKey = adjustmentLayersKey; exports.applyAdjustments = applyAdjustments; exports.applyLegacyAdjustments = applyLegacyAdjustments; exports.applyLegacyFloat = applyLegacyFloat; exports.applyProcess2Adjustments = applyProcess2Adjustments; exports.applyProcess2Float = applyProcess2Float; exports.applyBoxBlurFloat = applyBoxBlurFloat; exports.applyBoxBlur = applyBoxBlur; exports.applyDepthMask = applyDepthMask; exports.removeAlpha = removeAlpha; exports.TEXT_ALIGNS = TEXT_ALIGNS; exports.MAX_EFFECT_ANIMATION_MS = MAX_EFFECT_ANIMATION_MS; exports.SHAPE_OPERATIONS = SHAPE_OPERATIONS; exports.LIVE_SHAPE_KINDS = LIVE_SHAPE_KINDS; exports.newLayerId = newLayerId; exports.pixelLayers = pixelLayers; exports.developFilter = developFilter; exports.blurFilter = blurFilter; exports.isActiveFilter = isActiveFilter; exports.isSpatialFilter = isSpatialFilter; exports.pixelLayerBounds = pixelLayerBounds; exports.layerTypeLabel = layerTypeLabel; exports.hasSurface = hasSurface; exports.isRenderedLayer = isRenderedLayer; exports.shapeLayers = shapeLayers; exports.smartObjectLayers = smartObjectLayers; exports.adjustmentNodeAsLayer = adjustmentNodeAsLayer; exports.depthMaskAlpha = depthMaskAlpha; exports.runLayerFilters = runLayerFilters; exports.runLayerFiltersFloat = runLayerFiltersFloat; exports.LayerCompositor = LayerCompositor; exports.compositeDeep = compositeDeep; exports.DEFAULT_ADJUSTMENTS_VALUES = DEFAULT_ADJUSTMENTS_VALUES; exports.DEFAULT_TRANSFORM_VALUES = DEFAULT_TRANSFORM_VALUES; exports.DEFAULT_DEPTH_MASK_VALUES = DEFAULT_DEPTH_MASK_VALUES; exports.flattenPath = flattenPath; exports.rasterizeCoverage = rasterizeCoverage; exports.LayerOperationError = LayerOperationError; exports.userErrorMessage = userErrorMessage; exports.isPaintableLayer = isPaintableLayer; exports.defaultActiveLayerId = defaultActiveLayerId; exports.activeLayerAfterRemoval = activeLayerAfterRemoval; exports.requireLayer = requireLayer; exports.requireUnlocked = requireUnlocked; exports.placeLayer = placeLayer; exports.removeLayer = removeLayer; exports.moveLayer = moveLayer; exports.withNewIds = withNewIds; exports.duplicateLayer = duplicateLayer; exports.setLayerProperties = setLayerProperties; exports.groupLayers = groupLayers; exports.ungroupLayer = ungroupLayer; exports.offsetLayer = offsetLayer; exports.setLayerMask = setLayerMask; exports.normalizeFilter = normalizeFilter; exports.addLayerFilter = addLayerFilter; exports.updateLayerFilter = updateLayerFilter; exports.removeLayerFilter = removeLayerFilter; exports.layerEffectsOf = layerEffectsOf; exports.setLayerEffects = setLayerEffects; exports.addLayerEffect = addLayerEffect; exports.updateLayerEffect = updateLayerEffect; exports.removeLayerEffect = removeLayerEffect; exports.setLayerEffectsEnabled = setLayerEffectsEnabled; exports.parseBlend = parseBlend; exports.unionRect = unionRect; exports.SHAPE_RENDER_MARGIN = SHAPE_RENDER_MARGIN; exports.DEFAULT_MITER_LIMIT = DEFAULT_MITER_LIMIT; exports.mapSubpaths = mapSubpaths; exports.liveShapeSubpaths = liveShapeSubpaths; exports.liveComponent = liveComponent; exports.componentPath = componentPath; exports.shapeOutline = shapeOutline; exports.shapeGeometryBounds = shapeGeometryBounds; exports.shapeRenderClip = shapeRenderClip; exports.renderShapeRect = renderShapeRect; exports.renderShape = renderShape; exports.rerenderShape = rerenderShape; exports.normalizeShapePaint = normalizeShapePaint; exports.normalizeShapeStroke = normalizeShapeStroke; exports.normalizeLiveShape = normalizeLiveShape; exports.normalizeSubpaths = normalizeSubpaths; exports.requireOperation = requireOperation; exports.requireShapeLayer = requireShapeLayer; exports.createShapeLayer = createShapeLayer; exports.defaultShapeName = defaultShapeName; exports.updateShapeLayer = updateShapeLayer; exports.transformShapeComponents = transformShapeComponents; exports.offsetShape = offsetShape; exports.mergeShapeComponents = mergeShapeComponents; exports.shapeAsPixelLayer = shapeAsPixelLayer; exports.shapeFromAnnotation = shapeFromAnnotation; exports.annotationBlend = annotationBlend; exports.annotationOfShape = annotationOfShape; exports.TEXT_RENDER_MARGIN = TEXT_RENDER_MARGIN; exports.textMatrix = textMatrix; exports.textOutlines = textOutlines; exports.renderText = renderText; exports.rerenderText = rerenderText; exports.TEXT_STYLE_FIELDS = TEXT_STYLE_FIELDS; exports.patchTextStyle = patchTextStyle; exports.PARAGRAPH_STYLE_FIELDS = PARAGRAPH_STYLE_FIELDS; exports.patchParagraphStyle = patchParagraphStyle; exports.textRange = textRange; exports.requireTypeLayer = requireTypeLayer; exports.normalizeText = normalizeText; exports.typeLayerName = typeLayerName; exports.createTypeLayer = createTypeLayer; exports.updateTypeLayer = updateTypeLayer; exports.replaceTextRange = replaceTextRange; exports.transformTypeLayer = transformTypeLayer; exports.typeFrame = typeFrame; exports.typeAsPixelLayer = typeAsPixelLayer; exports.toTextSpace = toTextSpace; exports.typeFromAnnotation = typeFromAnnotation; exports.annotationOfType = annotationOfType; exports.BACKGROUND_LAYER_ID = BACKGROUND_LAYER_ID; exports.BACKGROUND_LAYER_NAME = BACKGROUND_LAYER_NAME; exports.DEVELOP_FILTER_ID = DEVELOP_FILTER_ID; exports.BLUR_FILTER_ID = BLUR_FILTER_ID; exports.rasterMaskFromLegacy = rasterMaskFromLegacy; exports.hasResampledLegacyMask = hasResampledLegacyMask; exports.legacyMaskOf = legacyMaskOf; exports.isDefaultDepthMask = isDefaultDepthMask; exports.developFromAdjustments = developFromAdjustments; exports.annotationLayerName = annotationLayerName; exports.annotationLayerFor = annotationLayerFor; exports.annotationOfLayer = annotationOfLayer; exports.adjustmentNodeFromLegacy = adjustmentNodeFromLegacy; exports.backgroundLayer = backgroundLayer; exports.depthRasterMask = depthRasterMask; exports.layersFromLegacy = layersFromLegacy; exports.legacyAdjustmentLayer = legacyAdjustmentLayer; exports.developTarget = developTarget; exports.legacyView = legacyView; exports.isLegacyShape = isLegacyShape; exports.FREE_TRANSFORM_MODES = FREE_TRANSFORM_MODES; exports.TRANSFORM_ANCHORS = TRANSFORM_ANCHORS; exports.ANCHOR_FRACTION = ANCHOR_FRACTION; exports.isTransformAnchor = isTransformAnchor; exports.identityTransform = identityTransform; exports.cornersFromMatrix = cornersFromMatrix; exports.matrixFromCorners = matrixFromCorners; exports.transformHomography = transformHomography; exports.hasWarp = hasWarp; exports.isIdentityTransform = isIdentityTransform; exports.transformMap = transformMap; exports.transformedPoint = transformedPoint; exports.anchorPoint = anchorPoint; exports.transformedBox = transformedBox; exports.referencePoint = referencePoint; exports.matrixFromParams = matrixFromParams; exports.describeTransform = describeTransform; exports.applyParams = applyParams; exports.flipCorners = flipCorners; exports.boxPointOf = boxPointOf; exports.presetWarp = presetWarp; exports.isValidWarp = isValidWarp; exports.geometryHomography = geometryHomography; exports.SMART_RENDER_MARGIN = SMART_RENDER_MARGIN; exports.isSmartSurfaceIncomplete = isSmartSurfaceIncomplete; exports.newContentsId = newContentsId; exports.contentsBox = contentsBox; exports.placementGeometry = placementGeometry; exports.placementAt = placementAt; exports.isContentsDecoded = isContentsDecoded; exports.requireSmartObject = requireSmartObject; exports.contentsSurface = contentsSurface; exports.rasterContents = rasterContents; exports.documentContents = documentContents; exports.placeContents = placeContents; exports.activeSmartFilters = activeSmartFilters; exports.activeEffectSmartFilters = activeEffectSmartFilters; exports.filterMaskCoverage = filterMaskCoverage; exports.applySmartFilters = applySmartFilters; exports.renderSmartObject = renderSmartObject; exports.rerender = rerender; exports.normalizePlacement = normalizePlacement; exports.setSmartPlacement = setSmartPlacement; exports.offsetSmartObject = offsetSmartObject; exports.translateLayer = translateLayer; exports.convertToSmartObject = convertToSmartObject; exports.rasterizeSmartObject = rasterizeSmartObject; exports.copySmartObject = copySmartObject; exports.instancesOf = instancesOf; exports.replaceContents = replaceContents; exports.normalizeSmartFilter = normalizeSmartFilter; exports.addSmartFilter = addSmartFilter; exports.updateSmartFilter = updateSmartFilter; exports.removeSmartFilter = removeSmartFilter; exports.moveSmartFilter = moveSmartFilter; exports.setSmartFiltersEnabled = setSmartFiltersEnabled; exports.setSmartFilterMask = setSmartFilterMask; exports.withFilterMaskSurface = withFilterMaskSurface; exports.placementBounds = placementBounds; exports.LAYERED_SCHEMA_VERSION = LAYERED_SCHEMA_VERSION; exports.serializePatterns = serializePatterns; exports.deserializePatterns = deserializePatterns; exports.encodeSurface = encodeSurface; exports.encodeDeepSurface = encodeDeepSurface; exports.decodeDeepSurface = decodeDeepSurface; exports.serializeEffects = serializeEffects; exports.deserializeEffects = deserializeEffects; exports.serializeLayer = serializeLayer; exports.serializeContents = serializeContents; exports.serializeLayers = serializeLayers; exports.serializeLayersExternal = serializeLayersExternal; exports.resolveExternalAssets = resolveExternalAssets; exports.decodePngDataUrl = decodePngDataUrl; exports.deserializeLayer = deserializeLayer; exports.deserializeLayers = deserializeLayers; exports.PsdError = PsdError; exports.decodePlanes = decodePlanes; exports.encodeRle = encodeRle; exports.parseVersionedDescriptor = parseVersionedDescriptor; exports.versionedDescriptorBytes = versionedDescriptorBytes; exports.ADJUSTMENT_KEYS = ADJUSTMENT_KEYS; exports.SUPPORTED_ADJUSTMENT_KEYS = SUPPORTED_ADJUSTMENT_KEYS; exports.parseAdjustmentBlock = parseAdjustmentBlock; exports.writeAdjustmentBlock = writeAdjustmentBlock; exports.parseLfx2 = parseLfx2; exports.writeLfx2 = writeLfx2; exports.parseLrfx = parseLrfx; exports.BROWSER_IMAGE_TYPES = BROWSER_IMAGE_TYPES; exports.readPsd = readPsd; exports.layerName = layerName; exports.layerTree = layerTree; exports.decodeLayerChannel = decodeLayerChannel; exports.decodeMergedImage = decodeMergedImage; exports.writePsd = writePsd; exports.PATTERN_BLOCK_KEYS = PATTERN_BLOCK_KEYS; exports.parsePatternBlock = parsePatternBlock; exports.psdPatternToEffectPattern = psdPatternToEffectPattern; exports.writePatternBlock = writePatternBlock; exports.PSD_BLEND_KEYS = PSD_BLEND_KEYS; exports.psdToLayers = psdToLayers; exports.importPsd = importPsd; exports.smartContentsFile = smartContentsFile; exports.exportPsd = exportPsd;
12374
+
12375
+
12376
+
12377
+
12378
+
12379
+
12380
+
12381
+
12382
+
12383
+
12384
+ exports.LEGACY_PROCESS_VERSION = LEGACY_PROCESS_VERSION; exports.LATEST_PROCESS_VERSION = LATEST_PROCESS_VERSION; exports.normalizeProcessVersion = normalizeProcessVersion; exports.srgbToLinear = srgbToLinear; exports.linearToSrgb = linearToSrgb; exports.LUMA_709 = LUMA_709; exports.IDENTITY_MATRIX3 = IDENTITY_MATRIX3; exports.mulMatrix3 = mulMatrix3; exports.applyMatrix3 = applyMatrix3; exports.invertMatrix3 = invertMatrix3; exports.D65 = D65; exports.bradfordAdaptation = bradfordAdaptation; exports.wbMatrix = wbMatrix; exports.linearSrgbToXy = linearSrgbToXy; exports.TINT_SCALE = TINT_SCALE; exports.MIN_KELVIN = MIN_KELVIN; exports.MAX_KELVIN = MAX_KELVIN; exports.xyToUv = xyToUv; exports.uvToXy = uvToXy; exports.tempTintToXy = tempTintToXy; exports.xyToTempTint = xyToTempTint; exports.AS_SHOT_KELVIN = AS_SHOT_KELVIN; exports.MIRED_PER_TEMPERATURE_UNIT = MIRED_PER_TEMPERATURE_UNIT; exports.temperatureToKelvin = temperatureToKelvin; exports.kelvinToTemperature = kelvinToTemperature; exports.whiteBalanceMatrix = whiteBalanceMatrix; exports.whiteBalanceFromSample = whiteBalanceFromSample; exports.TONE_LUT_SIZE = TONE_LUT_SIZE; exports.toneCurve = toneCurve; exports.buildToneLut = buildToneLut; exports.sampleToneLut = sampleToneLut; exports.normalizeAngle = normalizeAngle; exports.isQuarterTurnSwapped = isQuarterTurnSwapped; exports.getRotatedSize = getRotatedSize; exports.projectImagePoint = projectImagePoint; exports.unprojectCanvasPoint = unprojectCanvasPoint; exports.applyImageProjectionToContext = applyImageProjectionToContext; exports.projectImageRect = projectImageRect; exports.clampCropToImage = clampCropToImage; exports.getViewportProjection = getViewportProjection; exports.getViewportMetrics = getViewportMetrics; exports.canvasToImagePoint = canvasToImagePoint; exports.imageToCanvasPoint = imageToCanvasPoint; exports.mapCropHandle = mapCropHandle; exports.hitTestCrop = hitTestCrop; exports.getCropCursor = getCropCursor; exports.calculateCropDrag = calculateCropDrag; exports.getAnnotationBounds = getAnnotationBounds; exports.hitTestAnnotation = hitTestAnnotation; exports.SELECTION_MODES = SELECTION_MODES; exports.isSelectionMode = isSelectionMode; exports.parseSelectionMode = parseSelectionMode; exports.computeSelectionBounds = computeSelectionBounds; exports.selectionFromTiles = selectionFromTiles; exports.createSelectionMask = createSelectionMask; exports.selectionFromRegion = selectionFromRegion; exports.fullSelection = fullSelection; exports.isSelectionEmpty = isSelectionEmpty; exports.selectionValueAt = selectionValueAt; exports.coverageToByte = coverageToByte; exports.selectionFromCoverage = selectionFromCoverage; exports.selectionToCoverage = selectionToCoverage; exports.selectionArea = selectionArea; exports.combineSelections = combineSelections; exports.invertSelection = invertSelection; exports.resizeSelection = resizeSelection; exports.selectionFromPixels = selectionFromPixels; exports.selectionToPixels = selectionToPixels; exports.encodeSelectionRle = encodeSelectionRle; exports.decodeSelectionRle = decodeSelectionRle; exports.serializeSelection = serializeSelection; exports.deserializeSelection = deserializeSelection; exports.hashMaskContent = hashMaskContent; exports.EMPTY_DISTANCE = EMPTY_DISTANCE; exports.distanceTransform = distanceTransform; exports.expandCoverage = expandCoverage; exports.contractCoverage = contractCoverage; exports.borderCoverage = borderCoverage; exports.smoothCoverage = smoothCoverage; exports.featherCoverage = featherCoverage; exports.greyMorphology = greyMorphology; exports.shiftCoverage = shiftCoverage; exports.SELECTION_MODIFY_OPS = SELECTION_MODIFY_OPS; exports.modifySelection = modifySelection; exports.layerMaskSelection = layerMaskSelection; exports.normalizeLayerMask = normalizeLayerMask; exports.layerMaskFromSelection = layerMaskFromSelection; exports.updateLayerMaskProps = updateLayerMaskProps; exports.decodeLayerMask = decodeLayerMask; exports.layerMaskKey = layerMaskKey; exports.layerMaskCoverage = layerMaskCoverage; exports.projectMaskCoverage = projectMaskCoverage; exports.buildLayerMaskPlanes = buildLayerMaskPlanes; exports.ADJUSTMENT_LUT_SIZE = ADJUSTMENT_LUT_SIZE; exports.sampleLut = sampleLut; exports.ADJUSTMENT_KINDS = ADJUSTMENT_KINDS; exports.isAdjustmentKind = isAdjustmentKind; exports.adjustmentKindLabel = adjustmentKindLabel; exports.HUE_RANGE_LABELS = HUE_RANGE_LABELS; exports.neutralHueRange = neutralHueRange; exports.identityCurve = identityCurve; exports.identityLevels = identityLevels; exports.defaultAdjustmentParams = defaultAdjustmentParams; exports.createAdjustmentLayer = createAdjustmentLayer; exports.normalizeAdjustmentLayer = normalizeAdjustmentLayer; exports.normalizeAdjustmentLayers = normalizeAdjustmentLayers; exports.curveLutFromLevels = curveLutFromLevels; exports.levelsValue = levelsValue; exports.rgbToHsl = rgbToHsl; exports.hslToRgb = hslToRgb; exports.hueRangeWeight = hueRangeWeight; exports.hueRangeTables = hueRangeTables; exports.hueSaturation = hueSaturation; exports.rangeLightness = rangeLightness; exports.VIBRANCE_GREY = VIBRANCE_GREY; exports.vibranceLinear = vibranceLinear; exports.vibrancePixel = vibrancePixel; exports.colorBalanceChannel = colorBalanceChannel; exports.blackWhiteGray = blackWhiteGray; exports.D50 = D50; exports.XYZ_D50_TO_SRGB = XYZ_D50_TO_SRGB; exports.photoFilterMatrix = photoFilterMatrix; exports.posterizeValue = posterizeValue; exports.rgbToGray = rgbToGray; exports.hexToRgb = hexToRgb; exports.toneLuts = toneLuts; exports.compileAdjustmentLayer = compileAdjustmentLayer; exports.activeAdjustmentLayers = activeAdjustmentLayers; exports.evaluateAdjustmentLayers = evaluateAdjustmentLayers; exports.applyAdjustmentLayers = applyAdjustmentLayers; exports.applyAdjustmentLayersFloat = applyAdjustmentLayersFloat; exports.adjustmentLayersKey = adjustmentLayersKey; exports.applyAdjustments = applyAdjustments; exports.applyLegacyAdjustments = applyLegacyAdjustments; exports.applyLegacyFloat = applyLegacyFloat; exports.applyProcess2Adjustments = applyProcess2Adjustments; exports.applyProcess2Float = applyProcess2Float; exports.applyBoxBlurFloat = applyBoxBlurFloat; exports.applyBoxBlur = applyBoxBlur; exports.applyDepthMask = applyDepthMask; exports.removeAlpha = removeAlpha; exports.flattenPath = flattenPath; exports.rasterizeCoverage = rasterizeCoverage; exports.TEXT_ALIGNS = TEXT_ALIGNS; exports.MAX_EFFECT_ANIMATION_MS = MAX_EFFECT_ANIMATION_MS; exports.SHAPE_OPERATIONS = SHAPE_OPERATIONS; exports.LIVE_SHAPE_KINDS = LIVE_SHAPE_KINDS; exports.newLayerId = newLayerId; exports.pixelLayers = pixelLayers; exports.developFilter = developFilter; exports.blurFilter = blurFilter; exports.isActiveFilter = isActiveFilter; exports.isSpatialFilter = isSpatialFilter; exports.pixelLayerBounds = pixelLayerBounds; exports.layerTypeLabel = layerTypeLabel; exports.hasSurface = hasSurface; exports.isRenderedLayer = isRenderedLayer; exports.shapeLayers = shapeLayers; exports.smartObjectLayers = smartObjectLayers; exports.LayerOperationError = LayerOperationError; exports.userErrorMessage = userErrorMessage; exports.isPaintableLayer = isPaintableLayer; exports.defaultActiveLayerId = defaultActiveLayerId; exports.activeLayerAfterRemoval = activeLayerAfterRemoval; exports.requireLayer = requireLayer; exports.requireUnlocked = requireUnlocked; exports.placeLayer = placeLayer; exports.removeLayer = removeLayer; exports.moveLayer = moveLayer; exports.withNewIds = withNewIds; exports.duplicateLayer = duplicateLayer; exports.setLayerProperties = setLayerProperties; exports.groupLayers = groupLayers; exports.ungroupLayer = ungroupLayer; exports.offsetLayer = offsetLayer; exports.setLayerMask = setLayerMask; exports.normalizeFilter = normalizeFilter; exports.addLayerFilter = addLayerFilter; exports.updateLayerFilter = updateLayerFilter; exports.removeLayerFilter = removeLayerFilter; exports.layerEffectsOf = layerEffectsOf; exports.setLayerEffects = setLayerEffects; exports.addLayerEffect = addLayerEffect; exports.updateLayerEffect = updateLayerEffect; exports.removeLayerEffect = removeLayerEffect; exports.setLayerEffectsEnabled = setLayerEffectsEnabled; exports.parseBlend = parseBlend; exports.unionRect = unionRect; exports.SHAPE_RENDER_MARGIN = SHAPE_RENDER_MARGIN; exports.DEFAULT_MITER_LIMIT = DEFAULT_MITER_LIMIT; exports.mapSubpaths = mapSubpaths; exports.liveShapeSubpaths = liveShapeSubpaths; exports.liveComponent = liveComponent; exports.componentPath = componentPath; exports.shapeOutline = shapeOutline; exports.shapeGeometryBounds = shapeGeometryBounds; exports.componentsCoverage = componentsCoverage; exports.shapeRenderClip = shapeRenderClip; exports.renderShapeRect = renderShapeRect; exports.renderShape = renderShape; exports.rerenderShape = rerenderShape; exports.normalizeShapePaint = normalizeShapePaint; exports.normalizeShapeStroke = normalizeShapeStroke; exports.normalizeLiveShape = normalizeLiveShape; exports.normalizeSubpaths = normalizeSubpaths; exports.requireOperation = requireOperation; exports.requireShapeLayer = requireShapeLayer; exports.createShapeLayer = createShapeLayer; exports.defaultShapeName = defaultShapeName; exports.updateShapeLayer = updateShapeLayer; exports.transformShapeComponents = transformShapeComponents; exports.offsetShape = offsetShape; exports.mergeShapeComponents = mergeShapeComponents; exports.shapeAsPixelLayer = shapeAsPixelLayer; exports.shapeFromAnnotation = shapeFromAnnotation; exports.annotationBlend = annotationBlend; exports.annotationOfShape = annotationOfShape; exports.isActiveVectorMask = isActiveVectorMask; exports.vectorMaskCoverage = vectorMaskCoverage; exports.effectiveLayerMask = effectiveLayerMask; exports.resolveVectorMasks = resolveVectorMasks; exports.offsetVectorMask = offsetVectorMask; exports.transformVectorMask = transformVectorMask; exports.followLayerMove = followLayerMove; exports.vectorMaskBounds = vectorMaskBounds; exports.vectorMaskThumbnail = vectorMaskThumbnail; exports.adjustmentNodeAsLayer = adjustmentNodeAsLayer; exports.depthMaskAlpha = depthMaskAlpha; exports.runLayerFilters = runLayerFilters; exports.runLayerFiltersFloat = runLayerFiltersFloat; exports.LayerCompositor = LayerCompositor; exports.compositeDeep = compositeDeep; exports.DEFAULT_ADJUSTMENTS_VALUES = DEFAULT_ADJUSTMENTS_VALUES; exports.DEFAULT_TRANSFORM_VALUES = DEFAULT_TRANSFORM_VALUES; exports.DEFAULT_DEPTH_MASK_VALUES = DEFAULT_DEPTH_MASK_VALUES; exports.TEXT_RENDER_MARGIN = TEXT_RENDER_MARGIN; exports.textMatrix = textMatrix; exports.textOutlines = textOutlines; exports.renderText = renderText; exports.rerenderText = rerenderText; exports.TEXT_STYLE_FIELDS = TEXT_STYLE_FIELDS; exports.patchTextStyle = patchTextStyle; exports.PARAGRAPH_STYLE_FIELDS = PARAGRAPH_STYLE_FIELDS; exports.patchParagraphStyle = patchParagraphStyle; exports.textRange = textRange; exports.requireTypeLayer = requireTypeLayer; exports.normalizeText = normalizeText; exports.typeLayerName = typeLayerName; exports.createTypeLayer = createTypeLayer; exports.updateTypeLayer = updateTypeLayer; exports.replaceTextRange = replaceTextRange; exports.transformTypeLayer = transformTypeLayer; exports.typeFrame = typeFrame; exports.typeAsPixelLayer = typeAsPixelLayer; exports.toTextSpace = toTextSpace; exports.typeFromAnnotation = typeFromAnnotation; exports.annotationOfType = annotationOfType; exports.BACKGROUND_LAYER_ID = BACKGROUND_LAYER_ID; exports.BACKGROUND_LAYER_NAME = BACKGROUND_LAYER_NAME; exports.DEVELOP_FILTER_ID = DEVELOP_FILTER_ID; exports.BLUR_FILTER_ID = BLUR_FILTER_ID; exports.rasterMaskFromLegacy = rasterMaskFromLegacy; exports.hasResampledLegacyMask = hasResampledLegacyMask; exports.legacyMaskOf = legacyMaskOf; exports.isDefaultDepthMask = isDefaultDepthMask; exports.developFromAdjustments = developFromAdjustments; exports.annotationLayerName = annotationLayerName; exports.annotationLayerFor = annotationLayerFor; exports.annotationOfLayer = annotationOfLayer; exports.adjustmentNodeFromLegacy = adjustmentNodeFromLegacy; exports.backgroundLayer = backgroundLayer; exports.depthRasterMask = depthRasterMask; exports.layersFromLegacy = layersFromLegacy; exports.legacyAdjustmentLayer = legacyAdjustmentLayer; exports.developTarget = developTarget; exports.legacyView = legacyView; exports.isLegacyShape = isLegacyShape; exports.FREE_TRANSFORM_MODES = FREE_TRANSFORM_MODES; exports.TRANSFORM_ANCHORS = TRANSFORM_ANCHORS; exports.ANCHOR_FRACTION = ANCHOR_FRACTION; exports.isTransformAnchor = isTransformAnchor; exports.identityTransform = identityTransform; exports.cornersFromMatrix = cornersFromMatrix; exports.matrixFromCorners = matrixFromCorners; exports.transformHomography = transformHomography; exports.hasWarp = hasWarp; exports.isIdentityTransform = isIdentityTransform; exports.transformMap = transformMap; exports.transformedPoint = transformedPoint; exports.anchorPoint = anchorPoint; exports.transformedBox = transformedBox; exports.referencePoint = referencePoint; exports.matrixFromParams = matrixFromParams; exports.describeTransform = describeTransform; exports.applyParams = applyParams; exports.flipCorners = flipCorners; exports.boxPointOf = boxPointOf; exports.presetWarp = presetWarp; exports.isValidWarp = isValidWarp; exports.geometryHomography = geometryHomography; exports.SMART_RENDER_MARGIN = SMART_RENDER_MARGIN; exports.isSmartSurfaceIncomplete = isSmartSurfaceIncomplete; exports.newContentsId = newContentsId; exports.contentsBox = contentsBox; exports.placementGeometry = placementGeometry; exports.placementAt = placementAt; exports.isContentsDecoded = isContentsDecoded; exports.requireSmartObject = requireSmartObject; exports.contentsSurface = contentsSurface; exports.rasterContents = rasterContents; exports.documentContents = documentContents; exports.placeContents = placeContents; exports.activeSmartFilters = activeSmartFilters; exports.activeEffectSmartFilters = activeEffectSmartFilters; exports.filterMaskCoverage = filterMaskCoverage; exports.applySmartFilters = applySmartFilters; exports.renderSmartObject = renderSmartObject; exports.rerender = rerender; exports.normalizePlacement = normalizePlacement; exports.setSmartPlacement = setSmartPlacement; exports.offsetSmartObject = offsetSmartObject; exports.translateLayer = translateLayer; exports.convertToSmartObject = convertToSmartObject; exports.rasterizeSmartObject = rasterizeSmartObject; exports.copySmartObject = copySmartObject; exports.instancesOf = instancesOf; exports.replaceContents = replaceContents; exports.normalizeSmartFilter = normalizeSmartFilter; exports.addSmartFilter = addSmartFilter; exports.updateSmartFilter = updateSmartFilter; exports.removeSmartFilter = removeSmartFilter; exports.moveSmartFilter = moveSmartFilter; exports.setSmartFiltersEnabled = setSmartFiltersEnabled; exports.setSmartFilterMask = setSmartFilterMask; exports.withFilterMaskSurface = withFilterMaskSurface; exports.placementBounds = placementBounds; exports.LAYERED_SCHEMA_VERSION = LAYERED_SCHEMA_VERSION; exports.serializePatterns = serializePatterns; exports.deserializePatterns = deserializePatterns; exports.encodeSurface = encodeSurface; exports.encodeDeepSurface = encodeDeepSurface; exports.decodeDeepSurface = decodeDeepSurface; exports.serializeEffects = serializeEffects; exports.deserializeEffects = deserializeEffects; exports.serializeLayer = serializeLayer; exports.serializeContents = serializeContents; exports.serializeLayers = serializeLayers; exports.serializeLayersExternal = serializeLayersExternal; exports.resolveExternalAssets = resolveExternalAssets; exports.decodePngDataUrl = decodePngDataUrl; exports.deserializeLayer = deserializeLayer; exports.deserializeLayers = deserializeLayers; exports.PsdError = PsdError; exports.decodePlanes = decodePlanes; exports.encodeRle = encodeRle; exports.parseVersionedDescriptor = parseVersionedDescriptor; exports.versionedDescriptorBytes = versionedDescriptorBytes; exports.ADJUSTMENT_KEYS = ADJUSTMENT_KEYS; exports.SUPPORTED_ADJUSTMENT_KEYS = SUPPORTED_ADJUSTMENT_KEYS; exports.parseAdjustmentBlock = parseAdjustmentBlock; exports.writeAdjustmentBlock = writeAdjustmentBlock; exports.parseLfx2 = parseLfx2; exports.writeLfx2 = writeLfx2; exports.parseLrfx = parseLrfx; exports.BROWSER_IMAGE_TYPES = BROWSER_IMAGE_TYPES; exports.readPsd = readPsd; exports.layerName = layerName; exports.layerTree = layerTree; exports.decodeLayerChannel = decodeLayerChannel; exports.decodeMergedImage = decodeMergedImage; exports.writePsd = writePsd; exports.PATTERN_BLOCK_KEYS = PATTERN_BLOCK_KEYS; exports.parsePatternBlock = parsePatternBlock; exports.psdPatternToEffectPattern = psdPatternToEffectPattern; exports.writePatternBlock = writePatternBlock; exports.PSD_BLEND_KEYS = PSD_BLEND_KEYS; exports.psdToLayers = psdToLayers; exports.importPsd = importPsd; exports.smartContentsFile = smartContentsFile; exports.exportPsd = exportPsd;