@pixerate/editor 0.208.0 → 0.209.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.
@@ -5103,17 +5103,19 @@ var ImageEditorController = (_class12 = class {
5103
5103
  /** The segmentation provider behind `selectSubject` (see `setSegmentationProvider`). */
5104
5104
  __init82() {this.segmentation = null}
5105
5105
  __init83() {this.selectionWorker = null}
5106
+ __init84() {this.documentOpener = null}
5106
5107
  /** The effects provider slot (see `setEffectsProvider`). */
5107
- __init84() {this.effects = new (0, _chunkA3A5TI6Rcjs.EffectsSlot)()}
5108
+ __init85() {this.effects = new (0, _chunkA3A5TI6Rcjs.EffectsSlot)()}
5108
5109
  /** Renders provider effects: effect smart filter results and effect layers. */
5109
- __init85() {this.effectsEngine = new ImageEffectsEngine({ slot: this.effects })}
5110
- __init86() {this.effectRefresh = "none"}
5111
- constructor(options = {}) {;_class12.prototype.__init71.call(this);_class12.prototype.__init72.call(this);_class12.prototype.__init73.call(this);_class12.prototype.__init74.call(this);_class12.prototype.__init75.call(this);_class12.prototype.__init76.call(this);_class12.prototype.__init77.call(this);_class12.prototype.__init78.call(this);_class12.prototype.__init79.call(this);_class12.prototype.__init80.call(this);_class12.prototype.__init81.call(this);_class12.prototype.__init82.call(this);_class12.prototype.__init83.call(this);_class12.prototype.__init84.call(this);_class12.prototype.__init85.call(this);_class12.prototype.__init86.call(this);_class12.prototype.__init87.call(this);_class12.prototype.__init88.call(this);_class12.prototype.__init89.call(this);_class12.prototype.__init90.call(this);_class12.prototype.__init91.call(this);_class12.prototype.__init92.call(this);_class12.prototype.__init93.call(this);_class12.prototype.__init94.call(this);_class12.prototype.__init95.call(this);_class12.prototype.__init96.call(this);_class12.prototype.__init97.call(this);_class12.prototype.__init98.call(this);_class12.prototype.__init99.call(this);_class12.prototype.__init100.call(this);_class12.prototype.__init101.call(this);_class12.prototype.__init102.call(this);
5110
+ __init86() {this.effectsEngine = new ImageEffectsEngine({ slot: this.effects })}
5111
+ __init87() {this.effectRefresh = "none"}
5112
+ constructor(options = {}) {;_class12.prototype.__init71.call(this);_class12.prototype.__init72.call(this);_class12.prototype.__init73.call(this);_class12.prototype.__init74.call(this);_class12.prototype.__init75.call(this);_class12.prototype.__init76.call(this);_class12.prototype.__init77.call(this);_class12.prototype.__init78.call(this);_class12.prototype.__init79.call(this);_class12.prototype.__init80.call(this);_class12.prototype.__init81.call(this);_class12.prototype.__init82.call(this);_class12.prototype.__init83.call(this);_class12.prototype.__init84.call(this);_class12.prototype.__init85.call(this);_class12.prototype.__init86.call(this);_class12.prototype.__init87.call(this);_class12.prototype.__init88.call(this);_class12.prototype.__init89.call(this);_class12.prototype.__init90.call(this);_class12.prototype.__init91.call(this);_class12.prototype.__init92.call(this);_class12.prototype.__init93.call(this);_class12.prototype.__init94.call(this);_class12.prototype.__init95.call(this);_class12.prototype.__init96.call(this);_class12.prototype.__init97.call(this);_class12.prototype.__init98.call(this);_class12.prototype.__init99.call(this);_class12.prototype.__init100.call(this);_class12.prototype.__init101.call(this);_class12.prototype.__init102.call(this);_class12.prototype.__init103.call(this);
5112
5113
  this.effects.subscribe(() => this.queueEffectRefresh("all"));
5113
5114
  this.effectsEngine.subscribe(() => this.queueEffectRefresh("incomplete"));
5114
5115
  if (options.effects) this.effects.set(options.effects);
5115
5116
  if (options.segmentation) this.segmentation = options.segmentation;
5116
5117
  if (options.selectionWorker) this.selectionWorker = new (0, _chunkX4LUGTQXcjs.SelectionWorkerClient)(options.selectionWorker);
5118
+ if (options.openDocument) this.documentOpener = options.openDocument;
5117
5119
  this.maxHistoryDepth = _nullishCoalesce(options.maxHistoryDepth, () => ( 50));
5118
5120
  if (options.textShaper !== void 0) this.textShaperValue = options.textShaper;
5119
5121
  this.maxHistoryBytes = _nullishCoalesce(options.maxHistoryBytes, () => ( 512 * 1024 * 1024));
@@ -5242,7 +5244,7 @@ var ImageEditorController = (_class12 = class {
5242
5244
  * Where layer pixels changed since the last viewport render, when only strokes changed them
5243
5245
  * (the renderer then recomposites just those rectangles); `'all'` after any other change.
5244
5246
  */
5245
- __init87() {this.pendingDirty = "all"}
5247
+ __init88() {this.pendingDirty = "all"}
5246
5248
  notify(strokeRects) {
5247
5249
  if (strokeRects) this.docRevision++;
5248
5250
  if (strokeRects && this.pendingDirty !== "all") this.pendingDirty.push(...strokeRects);
@@ -5311,6 +5313,70 @@ var ImageEditorController = (_class12 = class {
5311
5313
  _optionalChain([this, 'access', _163 => _163.selectionWorker, 'optionalAccess', _164 => _164.terminate, 'call', _165 => _165()]);
5312
5314
  this.selectionWorker = factory ? new (0, _chunkX4LUGTQXcjs.SelectionWorkerClient)(factory) : null;
5313
5315
  }
5316
+ /** Sets (or with `null` removes) how new documents are opened (see `DocumentOpener`). Not an edit. */
5317
+ setDocumentOpener(opener) {
5318
+ if (this.documentOpener === opener) return;
5319
+ this.documentOpener = opener;
5320
+ this.notify();
5321
+ }
5322
+ /** Whether the host can open new documents (the New Document outputs are available). */
5323
+ get canOpenDocuments() {
5324
+ return this.documentOpener !== null;
5325
+ }
5326
+ /**
5327
+ * A new one-layer document from the selection (or `options.selection`) on a pixel layer
5328
+ * (`layerId`, default the active one), the size of this image: the selected pixels on
5329
+ * transparency, or with `withMask` the whole layer masked by the selection. This document is
5330
+ * not changed. `decontaminate` (0..100) cleans the soft edge's colours as the new-layer
5331
+ * outputs do.
5332
+ */
5333
+ documentFromSelection(options = {}) {
5334
+ const id = _nullishCoalesce(options.layerId, () => ( this.state.activeLayerId));
5335
+ if (!id) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("No layer given and none is active; pass layerId (see list_layers).");
5336
+ const layer = _chunkQE7D7TZRcjs.requireLayer.call(void 0, this.state.layers, id).layer;
5337
+ if (layer.type !== "pixel") throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`A new document needs a pixel layer; "${id}" is a ${layer.type} layer.`);
5338
+ const sel = _nullishCoalesce(options.selection, () => ( this.state.selection));
5339
+ if (!_optionalChain([sel, 'optionalAccess', _166 => _166.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select what goes in the new document first.");
5340
+ const { width, height } = this.naturalSize;
5341
+ const surface = this.surfaceOf(layer);
5342
+ let copy;
5343
+ if (options.withMask) {
5344
+ let mask = this.maskFromSelection(sel);
5345
+ if (layer.offset.x || layer.offset.y) mask = { ...mask, surface: _chunk474IQG74cjs.translateSurface.call(void 0, mask.surface, -layer.offset.x, -layer.offset.y) };
5346
+ copy = { ...layer, id: _chunkQE7D7TZRcjs.newLayerId.call(void 0, ), surface, mask };
5347
+ } else {
5348
+ const sb = sel.bounds;
5349
+ const src = { x: sb.x - layer.offset.x, y: sb.y - layer.offset.y, width: sb.width, height: sb.height };
5350
+ const px2 = _chunk474IQG74cjs.readRegion.call(void 0, surface, src);
5351
+ const data = sel.data;
5352
+ for (let y = 0; y < sb.height; y++) {
5353
+ for (let x = 0; x < sb.width; x++) px2[(y * sb.width + x) * 4 + 3] = Math.round(px2[(y * sb.width + x) * 4 + 3] * (data[(sb.y + y) * width + sb.x + x] / 255));
5354
+ }
5355
+ copy = { ...layer, id: _chunkQE7D7TZRcjs.newLayerId.call(void 0, ), surface: _chunk474IQG74cjs.surfaceFromPixels.call(void 0, { width: src.width, height: src.height, data: px2 }, 4, src.x, src.y) };
5356
+ delete copy.mask;
5357
+ }
5358
+ delete copy.source;
5359
+ copy.visible = true;
5360
+ const amount = Math.min(100, Math.max(0, _nullishCoalesce(options.decontaminate, () => ( 0)))) / 100;
5361
+ if (amount > 0) copy = { ...copy, surface: this.decontaminatedSurface(copy, layer, sel, amount, Math.max(4, _nullishCoalesce(options.radius, () => ( 0)))) };
5362
+ const { layers, assets, smartContents } = _chunkQE7D7TZRcjs.serializeLayers.call(void 0, [copy]);
5363
+ const out = {
5364
+ version: _chunkQE7D7TZRcjs.LAYERED_SCHEMA_VERSION,
5365
+ width,
5366
+ height,
5367
+ layers,
5368
+ assets,
5369
+ activeLayerId: copy.id,
5370
+ crop: null,
5371
+ transform: { ...DEFAULT_TRANSFORM },
5372
+ opacity: 1
5373
+ };
5374
+ if (smartContents) out.smartContents = smartContents;
5375
+ if (this.state.bitDepth === 16 || this.state.bitDepth === 32) out.bitDepth = this.state.bitDepth;
5376
+ if (this.state.colorProfile) out.colorProfile = serializeColorProfile(this.state.colorProfile);
5377
+ if (this.state.colorMode) out.colorMode = serializeColorMode(this.state.colorMode);
5378
+ return out;
5379
+ }
5314
5380
  /** Whether the long selections run in a worker. */
5315
5381
  get hasSelectionWorker() {
5316
5382
  return this.selectionWorker !== null;
@@ -5321,10 +5387,10 @@ var ImageEditorController = (_class12 = class {
5321
5387
  * `onProgress` hears its stages. The document is not changed.
5322
5388
  */
5323
5389
  async runSelectionJob(job, pixels, options = {}) {
5324
- _optionalChain([options, 'access', _166 => _166.signal, 'optionalAccess', _167 => _167.throwIfAborted, 'call', _168 => _168()]);
5390
+ _optionalChain([options, 'access', _167 => _167.signal, 'optionalAccess', _168 => _168.throwIfAborted, 'call', _169 => _169()]);
5325
5391
  if (this.selectionWorker) return this.selectionWorker.run(job, pixels, options);
5326
5392
  const result = _chunkX4LUGTQXcjs.runSelectionJob.call(void 0, job, pixels, options.onProgress);
5327
- _optionalChain([options, 'access', _169 => _169.signal, 'optionalAccess', _170 => _170.throwIfAborted, 'call', _171 => _171()]);
5393
+ _optionalChain([options, 'access', _170 => _170.signal, 'optionalAccess', _171 => _171.throwIfAborted, 'call', _172 => _172()]);
5328
5394
  return result;
5329
5395
  }
5330
5396
  /** Registers (or with `null` removes) the segmentation provider. Not an edit: no undo step. */
@@ -5399,8 +5465,8 @@ var ImageEditorController = (_class12 = class {
5399
5465
  */
5400
5466
  async updateEffectFilter(layerId, filterId, changes, commitToHistory = true) {
5401
5467
  const layer = _chunkQE7D7TZRcjs.requireSmartObject.call(void 0, this.state.layers, layerId);
5402
- const was = _optionalChain([layer, 'access', _172 => _172.smartFilters, 'optionalAccess', _173 => _173.filters, 'access', _174 => _174.find, 'call', _175 => _175((f) => f.id === filterId)]);
5403
- if (!was || was.kind !== "effect") throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Smart object "${layer.name || layerId}" has no effect filter "${filterId}"; its filters are ${(_nullishCoalesce(_optionalChain([layer, 'access', _176 => _176.smartFilters, 'optionalAccess', _177 => _177.filters]), () => ( []))).map((f) => `${f.id} (${f.kind === "effect" ? _nullishCoalesce(f.name, () => ( f.effect)) : f.kind})`).join(", ") || "none"}.`);
5468
+ const was = _optionalChain([layer, 'access', _173 => _173.smartFilters, 'optionalAccess', _174 => _174.filters, 'access', _175 => _175.find, 'call', _176 => _176((f) => f.id === filterId)]);
5469
+ if (!was || was.kind !== "effect") throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Smart object "${layer.name || layerId}" has no effect filter "${filterId}"; its filters are ${(_nullishCoalesce(_optionalChain([layer, 'access', _177 => _177.smartFilters, 'optionalAccess', _178 => _178.filters]), () => ( []))).map((f) => `${f.id} (${f.kind === "effect" ? _nullishCoalesce(f.name, () => ( f.effect)) : f.kind})`).join(", ") || "none"}.`);
5404
5470
  const update = {};
5405
5471
  if (changes.values) {
5406
5472
  const d = await this.describeEffect(was.effect);
@@ -5442,7 +5508,7 @@ var ImageEditorController = (_class12 = class {
5442
5508
  const layer = {
5443
5509
  type: "pixel",
5444
5510
  id,
5445
- name: _optionalChain([options, 'access', _178 => _178.name, 'optionalAccess', _179 => _179.trim, 'call', _180 => _180()]) || d.name,
5511
+ name: _optionalChain([options, 'access', _179 => _179.name, 'optionalAccess', _180 => _180.trim, 'call', _181 => _181()]) || d.name,
5446
5512
  visible: true,
5447
5513
  opacity: _nullishCoalesce(options.opacity, () => ( 1)),
5448
5514
  blend: _nullishCoalesce(blend, () => ( "normal")),
@@ -5467,7 +5533,7 @@ var ImageEditorController = (_class12 = class {
5467
5533
  */
5468
5534
  async updateEffectLayer(layerId, changes, commitToHistory = true) {
5469
5535
  const found = _chunkUOGKSVRQcjs.findLayer.call(void 0, this.state.layers, layerId);
5470
- const layer = _optionalChain([found, 'optionalAccess', _181 => _181.layer]);
5536
+ const layer = _optionalChain([found, 'optionalAccess', _182 => _182.layer]);
5471
5537
  if (!layer || layer.type !== "pixel" || !layer.generator) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`"${layerId}" is not an effect layer; add one with add_effect_layer.`);
5472
5538
  _chunkQE7D7TZRcjs.requireUnlocked.call(void 0, layer, "pixels", "draw its effect again");
5473
5539
  const g = layer.generator;
@@ -5496,7 +5562,7 @@ var ImageEditorController = (_class12 = class {
5496
5562
  * and how long it runs, the longest of theirs (ms). Null when none animates.
5497
5563
  */
5498
5564
  getAnimation() {
5499
- const layers = _chunkUOGKSVRQcjs.flattenLayers.call(void 0, this.state.layers).filter((l) => l.type === "pixel" && l.visible && !!_optionalChain([l, 'access', _182 => _182.generator, 'optionalAccess', _183 => _183.animate]));
5565
+ const layers = _chunkUOGKSVRQcjs.flattenLayers.call(void 0, this.state.layers).filter((l) => l.type === "pixel" && l.visible && !!_optionalChain([l, 'access', _183 => _183.generator, 'optionalAccess', _184 => _184.animate]));
5500
5566
  if (!layers.length) return null;
5501
5567
  return { duration: Math.max(...layers.map((l) => l.generator.animate.duration)), layerIds: layers.map((l) => l.id) };
5502
5568
  }
@@ -5513,7 +5579,7 @@ var ImageEditorController = (_class12 = class {
5513
5579
  const { width, height } = this.naturalSize;
5514
5580
  const surfaces = /* @__PURE__ */ new Map();
5515
5581
  for (const l of _chunkUOGKSVRQcjs.flattenLayers.call(void 0, this.state.layers)) {
5516
- if (l.type !== "pixel" || !l.visible || !_optionalChain([l, 'access', _184 => _184.generator, 'optionalAccess', _185 => _185.animate])) continue;
5582
+ if (l.type !== "pixel" || !l.visible || !_optionalChain([l, 'access', _185 => _185.generator, 'optionalAccess', _186 => _186.animate])) continue;
5517
5583
  const g = l.generator;
5518
5584
  const pixels = await this.effectsEngine.renderLayer(g.effect, g.values, { width, height, depth: this.bitDepth, time: (_nullishCoalesce(g.time, () => ( 0))) + time });
5519
5585
  surfaces.set(l.id, effectPixelsToSurface(pixels, this.bitDepth));
@@ -5533,7 +5599,7 @@ var ImageEditorController = (_class12 = class {
5533
5599
  })
5534
5600
  );
5535
5601
  }
5536
- __init88() {this.displayFor = null}
5602
+ __init89() {this.displayFor = null}
5537
5603
  /** Keeps the renderer's display transform in step with the document profile, mode and Proof Setup. */
5538
5604
  syncDisplay() {
5539
5605
  const s = this.state;
@@ -5574,7 +5640,7 @@ var ImageEditorController = (_class12 = class {
5574
5640
  transform: { ...s.transform },
5575
5641
  outputOpacity: s.outputOpacity,
5576
5642
  selection: _nullishCoalesce(s.selection, () => ( null)),
5577
- ..._optionalChain([s, 'access', _186 => _186.channels, 'optionalAccess', _187 => _187.length]) ? { channels: s.channels } : {},
5643
+ ..._optionalChain([s, 'access', _187 => _187.channels, 'optionalAccess', _188 => _188.length]) ? { channels: s.channels } : {},
5578
5644
  source: {
5579
5645
  sourceUrl: s.sourceUrl,
5580
5646
  element: this.imageElement,
@@ -5610,7 +5676,7 @@ var ImageEditorController = (_class12 = class {
5610
5676
  if (entry.colorMode) s.colorMode = entry.colorMode;
5611
5677
  else delete s.colorMode;
5612
5678
  s.selection = entry.selection;
5613
- if (_optionalChain([entry, 'access', _188 => _188.channels, 'optionalAccess', _189 => _189.length])) s.channels = entry.channels;
5679
+ if (_optionalChain([entry, 'access', _189 => _189.channels, 'optionalAccess', _190 => _190.length])) s.channels = entry.channels;
5614
5680
  else delete s.channels;
5615
5681
  if (this.imageElement !== entry.source.element && !this.samplePixelsOverride) this.samplePixels = null;
5616
5682
  this.imageElement = entry.source.element;
@@ -5622,7 +5688,7 @@ var ImageEditorController = (_class12 = class {
5622
5688
  }
5623
5689
  }
5624
5690
  /** Set while `asOneStep` runs: the step is already recorded, so nested commands add none. */
5625
- __init89() {this.historyGrouped = false}
5691
+ __init90() {this.historyGrouped = false}
5626
5692
  /**
5627
5693
  * Runs `fn` as one undo step: history is recorded once, before it, and the commands it calls
5628
5694
  * record none. If `fn` throws, the step is dropped and the state goes back to before it, so a
@@ -5685,7 +5751,7 @@ var ImageEditorController = (_class12 = class {
5685
5751
  get canUndo() {
5686
5752
  return this.undoStack.length > 0;
5687
5753
  }
5688
- __init90() {this.docRevision = 0}
5754
+ __init91() {this.docRevision = 0}
5689
5755
  /**
5690
5756
  * Bumped on every change to the document (an undoable edit, a stroke, undo, redo), not on view
5691
5757
  * or tool changes, nor on `loadImage` (the source image is the host's, not part of the document). `createImageEditorDocument` uses it to tell document changes apart.
@@ -5817,7 +5883,7 @@ var ImageEditorController = (_class12 = class {
5817
5883
  return this.state.layers;
5818
5884
  }
5819
5885
  getLayer(id) {
5820
- return _optionalChain([_chunkUOGKSVRQcjs.findLayer.call(void 0, this.state.layers, id), 'optionalAccess', _190 => _190.layer]);
5886
+ return _optionalChain([_chunkUOGKSVRQcjs.findLayer.call(void 0, this.state.layers, id), 'optionalAccess', _191 => _191.layer]);
5821
5887
  }
5822
5888
  /** The active layer, or `undefined`. */
5823
5889
  getActiveLayer() {
@@ -5830,7 +5896,7 @@ var ImageEditorController = (_class12 = class {
5830
5896
  setActiveLayer(id, target = "pixels") {
5831
5897
  if (id !== null && !this.getLayer(id)) return false;
5832
5898
  const layer = id ? this.getLayer(id) : void 0;
5833
- const t = target === "mask" && _optionalChain([layer, 'optionalAccess', _191 => _191.mask]) ? "mask" : target === "filter-mask" && _optionalChain([layer, 'optionalAccess', _192 => _192.type]) === "smart" && _optionalChain([layer, 'access', _193 => _193.smartFilters, 'optionalAccess', _194 => _194.mask]) ? "filter-mask" : "pixels";
5899
+ const t = target === "mask" && _optionalChain([layer, 'optionalAccess', _192 => _192.mask]) ? "mask" : target === "filter-mask" && _optionalChain([layer, 'optionalAccess', _193 => _193.type]) === "smart" && _optionalChain([layer, 'access', _194 => _194.smartFilters, 'optionalAccess', _195 => _195.mask]) ? "filter-mask" : "pixels";
5834
5900
  if (this.state.activeLayerId === id && this.state.activeTarget === t) return true;
5835
5901
  this.state.activeLayerId = id;
5836
5902
  this.state.activeTarget = t;
@@ -5849,7 +5915,7 @@ var ImageEditorController = (_class12 = class {
5849
5915
  if (!b) return null;
5850
5916
  return { x: b.x + layer.offset.x, y: b.y + layer.offset.y, width: b.width, height: b.height, data: _chunk474IQG74cjs.readRegion.call(void 0, surface, b) };
5851
5917
  }
5852
- __init91() {this.boundsCache = /* @__PURE__ */ new WeakMap()}
5918
+ __init92() {this.boundsCache = /* @__PURE__ */ new WeakMap()}
5853
5919
  /**
5854
5920
  * Document bounds of a layer's non-transparent pixels (pixel layers; the Background's source
5855
5921
  * included), or `null` for an empty or non-pixel layer.
@@ -5992,11 +6058,11 @@ var ImageEditorController = (_class12 = class {
5992
6058
  surfaceOf: (l) => this.surfaceOf(l),
5993
6059
  version: `${this.sourceVersion()}:${this.patternsVersion()}`,
5994
6060
  globalLight: this.state.globalLight,
5995
- pattern: (id) => _nullishCoalesce(_optionalChain([this, 'access', _195 => _195.state, 'access', _196 => _196.patterns, 'optionalAccess', _197 => _197.find, 'call', _198 => _198((p) => p.id === id)]), () => ( null))
6061
+ pattern: (id) => _nullishCoalesce(_optionalChain([this, 'access', _196 => _196.state, 'access', _197 => _197.patterns, 'optionalAccess', _198 => _198.find, 'call', _199 => _199((p) => p.id === id)]), () => ( null))
5996
6062
  };
5997
6063
  }
5998
- __init92() {this.sourceIds = /* @__PURE__ */ new WeakMap()}
5999
- __init93() {this.nextSourceId = 1}
6064
+ __init93() {this.sourceIds = /* @__PURE__ */ new WeakMap()}
6065
+ __init94() {this.nextSourceId = 1}
6000
6066
  /** Changes whenever the Background's source pixels can have changed. */
6001
6067
  sourceVersion() {
6002
6068
  const key = this.samplePixelsOverride ? this.samplePixels : _nullishCoalesce(this.imageElement, () => ( this.samplePixels));
@@ -6045,7 +6111,7 @@ var ImageEditorController = (_class12 = class {
6045
6111
  }
6046
6112
  return fits ? fromPixels(px2) : null;
6047
6113
  }
6048
- __init94() {this.opaqueCache = /* @__PURE__ */ new WeakMap()}
6114
+ __init95() {this.opaqueCache = /* @__PURE__ */ new WeakMap()}
6049
6115
  /** Whether every source pixel is opaque (some legacy renders depend on it). */
6050
6116
  sourceIsOpaque() {
6051
6117
  const s = this.sourceSurface();
@@ -6069,7 +6135,7 @@ var ImageEditorController = (_class12 = class {
6069
6135
  if (!ctx || typeof ctx.getImageData !== "function") return null;
6070
6136
  ctx.drawImage(el, 0, 0, width, height);
6071
6137
  const data = ctx.getImageData(0, 0, width, height);
6072
- if (!_optionalChain([data, 'optionalAccess', _199 => _199.data]) || data.data.length < width * height * 4) return null;
6138
+ if (!_optionalChain([data, 'optionalAccess', _200 => _200.data]) || data.data.length < width * height * 4) return null;
6073
6139
  return { width, height, data: data.data };
6074
6140
  } catch (e24) {
6075
6141
  return null;
@@ -6082,7 +6148,7 @@ var ImageEditorController = (_class12 = class {
6082
6148
  const prev = this.state.layers;
6083
6149
  const depth = this.bitDepth;
6084
6150
  this.state.layers = next;
6085
- _optionalChain([extra, 'optionalCall', _200 => _200()]);
6151
+ _optionalChain([extra, 'optionalCall', _201 => _201()]);
6086
6152
  if (depth !== 8 && this.bitDepth === depth) this.state.layers = keepDeepLayers(prev, this.state.layers);
6087
6153
  if (this.state.activeLayerId && !_chunkUOGKSVRQcjs.findLayer.call(void 0, this.state.layers, this.state.activeLayerId)) {
6088
6154
  this.state.activeLayerId = _chunkQE7D7TZRcjs.activeLayerAfterRemoval.call(void 0, prev, this.state.layers, this.state.activeLayerId);
@@ -6120,7 +6186,7 @@ var ImageEditorController = (_class12 = class {
6120
6186
  const layer = {
6121
6187
  type: "pixel",
6122
6188
  id: init.id && !ids.has(init.id) ? init.id : _chunkQE7D7TZRcjs.newLayerId.call(void 0, ),
6123
- name: _optionalChain([init, 'access', _201 => _201.name, 'optionalAccess', _202 => _202.trim, 'call', _203 => _203()]) || this.nextLayerName(),
6189
+ name: _optionalChain([init, 'access', _202 => _202.name, 'optionalAccess', _203 => _203.trim, 'call', _204 => _204()]) || this.nextLayerName(),
6124
6190
  visible: _nullishCoalesce(init.visible, () => ( true)),
6125
6191
  opacity: _nullishCoalesce(init.opacity, () => ( 1)),
6126
6192
  blend: _nullishCoalesce(blend, () => ( "normal")),
@@ -6147,7 +6213,7 @@ var ImageEditorController = (_class12 = class {
6147
6213
  async decodeImage(image) {
6148
6214
  const trimmed = image.trim();
6149
6215
  let png = null;
6150
- if (/^data:image\/png/i.test(trimmed)) png = _nullishCoalesce(_optionalChain([_chunkOLNIPTB3cjs.parseDataUrl.call(void 0, trimmed), 'optionalAccess', _204 => _204.bytes]), () => ( null));
6216
+ if (/^data:image\/png/i.test(trimmed)) png = _nullishCoalesce(_optionalChain([_chunkOLNIPTB3cjs.parseDataUrl.call(void 0, trimmed), 'optionalAccess', _205 => _205.bytes]), () => ( null));
6151
6217
  else if (/^[A-Za-z0-9+/=\s]+$/.test(trimmed) && trimmed.length > 16) {
6152
6218
  try {
6153
6219
  const bytes = _chunkOLNIPTB3cjs.base64ToBytes.call(void 0, trimmed);
@@ -6196,7 +6262,7 @@ var ImageEditorController = (_class12 = class {
6196
6262
  removeLayer(id) {
6197
6263
  const next = _chunkQE7D7TZRcjs.removeLayer.call(void 0, this.state.layers, id);
6198
6264
  this.commitLayers(next, () => {
6199
- if (this.state.selectedAnnotationId && !_chunkUOGKSVRQcjs.flattenLayers.call(void 0, next).some((l) => _optionalChain([_chunkQE7D7TZRcjs.annotationOfLayer.call(void 0, l), 'optionalAccess', _205 => _205.id]) === this.state.selectedAnnotationId)) {
6265
+ if (this.state.selectedAnnotationId && !_chunkUOGKSVRQcjs.flattenLayers.call(void 0, next).some((l) => _optionalChain([_chunkQE7D7TZRcjs.annotationOfLayer.call(void 0, l), 'optionalAccess', _206 => _206.id]) === this.state.selectedAnnotationId)) {
6200
6266
  this.state.selectedAnnotationId = null;
6201
6267
  }
6202
6268
  });
@@ -6205,9 +6271,9 @@ var ImageEditorController = (_class12 = class {
6205
6271
  moveLayer(id, placement) {
6206
6272
  const next = _chunkQE7D7TZRcjs.moveLayer.call(void 0, this.state.layers, id, placement);
6207
6273
  const loc = _chunkUOGKSVRQcjs.findLayer.call(void 0, next, id);
6208
- if (next === this.state.layers) return { parentId: _nullishCoalesce(_optionalChain([loc, 'access', _206 => _206.parent, 'optionalAccess', _207 => _207.id]), () => ( null)), index: loc.index };
6274
+ if (next === this.state.layers) return { parentId: _nullishCoalesce(_optionalChain([loc, 'access', _207 => _207.parent, 'optionalAccess', _208 => _208.id]), () => ( null)), index: loc.index };
6209
6275
  this.commitLayers(next);
6210
- return { parentId: _nullishCoalesce(_optionalChain([loc, 'access', _208 => _208.parent, 'optionalAccess', _209 => _209.id]), () => ( null)), index: loc.index };
6276
+ return { parentId: _nullishCoalesce(_optionalChain([loc, 'access', _209 => _209.parent, 'optionalAccess', _210 => _210.id]), () => ( null)), index: loc.index };
6211
6277
  }
6212
6278
  /**
6213
6279
  * Changes name, visibility, opacity, fill, blend, clipping, locks or (groups) collapsed state, as
@@ -6224,7 +6290,7 @@ var ImageEditorController = (_class12 = class {
6224
6290
  const group = {
6225
6291
  type: "group",
6226
6292
  id: _chunkQE7D7TZRcjs.newLayerId.call(void 0, "group"),
6227
- name: _optionalChain([init, 'access', _210 => _210.name, 'optionalAccess', _211 => _211.trim, 'call', _212 => _212()]) || "Group",
6293
+ name: _optionalChain([init, 'access', _211 => _211.name, 'optionalAccess', _212 => _212.trim, 'call', _213 => _213()]) || "Group",
6228
6294
  visible: true,
6229
6295
  opacity: 1,
6230
6296
  blend,
@@ -6317,7 +6383,7 @@ var ImageEditorController = (_class12 = class {
6317
6383
  sel = this.layerTransparency(id);
6318
6384
  } else {
6319
6385
  const current = this.state.selection;
6320
- if (!_optionalChain([current, 'optionalAccess', _213 => _213.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, or use reveal-all / hide-all / transparency.");
6386
+ if (!_optionalChain([current, 'optionalAccess', _214 => _214.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, or use reveal-all / hide-all / transparency.");
6321
6387
  sel = from === "hide-selection" ? _chunkQYLWG22Ncjs.invertSelection.call(void 0, current) : current;
6322
6388
  }
6323
6389
  mask = this.maskFromSelection(sel, props);
@@ -6348,7 +6414,7 @@ var ImageEditorController = (_class12 = class {
6348
6414
  const layer = _chunkQE7D7TZRcjs.requireLayer.call(void 0, this.state.layers, id).layer;
6349
6415
  const name = layer.name || id;
6350
6416
  if (layer.type === "shape") throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${name}" is a shape layer, whose path already is its vector mask; change it with set_shape_component, or rasterize the layer first.`);
6351
- if (_optionalChain([layer, 'access', _214 => _214.mask, 'optionalAccess', _215 => _215.source])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${name}" has a depth mask, which cannot be combined with a vector mask; remove the depth mask first.`);
6417
+ if (_optionalChain([layer, 'access', _215 => _215.mask, 'optionalAccess', _216 => _216.source])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${name}" has a depth mask, which cannot be combined with a vector mask; remove the depth mask first.`);
6352
6418
  return layer;
6353
6419
  }
6354
6420
  requireVectorMask(id) {
@@ -6358,10 +6424,10 @@ var ImageEditorController = (_class12 = class {
6358
6424
  }
6359
6425
  /** Components from a path spec: `components`, or one `shape` / `subpaths`. */
6360
6426
  vectorMaskComponents(path) {
6361
- if (_optionalChain([path, 'access', _216 => _216.components, 'optionalAccess', _217 => _217.length]) && (path.shape !== void 0 || path.subpaths !== void 0)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Give components, or shape / subpaths, not both.");
6427
+ if (_optionalChain([path, 'access', _217 => _217.components, 'optionalAccess', _218 => _218.length]) && (path.shape !== void 0 || path.subpaths !== void 0)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Give components, or shape / subpaths, not both.");
6362
6428
  if (path.fillRule !== void 0 && path.fillRule !== "nonzero" && path.fillRule !== "evenodd") throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("fillRule must be nonzero or evenodd.");
6363
- const specs = _optionalChain([path, 'access', _218 => _218.components, 'optionalAccess', _219 => _219.length]) ? path.components : [path];
6364
- return specs.map((c, i) => this.componentFrom(c, _optionalChain([path, 'access', _220 => _220.components, 'optionalAccess', _221 => _221.length]) ? `components[${i}].` : ""));
6429
+ const specs = _optionalChain([path, 'access', _219 => _219.components, 'optionalAccess', _220 => _220.length]) ? path.components : [path];
6430
+ return specs.map((c, i) => this.componentFrom(c, _optionalChain([path, 'access', _221 => _221.components, 'optionalAccess', _222 => _222.length]) ? `components[${i}].` : ""));
6365
6431
  }
6366
6432
  /**
6367
6433
  * Layer › Vector Mask: `reveal-all` (an empty path showing everything), `hide-all` (an empty path
@@ -6378,7 +6444,7 @@ var ImageEditorController = (_class12 = class {
6378
6444
  vm = { components: this.vectorMaskComponents(path) };
6379
6445
  if (path.fillRule === "evenodd") vm.fillRule = "evenodd";
6380
6446
  } else if (from === "reveal-all" || from === "hide-all") {
6381
- if (_optionalChain([path, 'access', _222 => _222.components, 'optionalAccess', _223 => _223.length]) || path.shape !== void 0 || path.subpaths !== void 0) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`A ${from} vector mask starts empty; use from path to give a path.`);
6447
+ if (_optionalChain([path, 'access', _223 => _223.components, 'optionalAccess', _224 => _224.length]) || path.shape !== void 0 || path.subpaths !== void 0) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`A ${from} vector mask starts empty; use from path to give a path.`);
6382
6448
  vm = { components: [], ...from === "reveal-all" ? { inverted: true } : {} };
6383
6449
  } else {
6384
6450
  throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Unknown vector mask source "${String(from)}". Use reveal-all, hide-all, path or selection.`);
@@ -6389,7 +6455,7 @@ var ImageEditorController = (_class12 = class {
6389
6455
  /** The selection's outline as subpaths; throws when nothing is selected or nothing is left to trace. */
6390
6456
  traceSelection(options) {
6391
6457
  const sel = this.state.selection;
6392
- if (!_optionalChain([sel, 'optionalAccess', _224 => _224.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, then make a path from the selection.");
6458
+ if (!_optionalChain([sel, 'optionalAccess', _225 => _225.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, then make a path from the selection.");
6393
6459
  if (options.tolerance !== void 0 && !(options.tolerance >= 0.1 && options.tolerance <= 10)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("tolerance must be from 0.1 to 10 px.");
6394
6460
  const subpaths = selectionToSubpaths(sel, options);
6395
6461
  if (!subpaths.length) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("The selection is too small or too faint to trace (below minArea, or under half selected); lower minArea or threshold.");
@@ -6570,7 +6636,7 @@ var ImageEditorController = (_class12 = class {
6570
6636
  const layer = loc.layer;
6571
6637
  if (layer.type !== "pixel") throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer via copy needs a pixel layer; "${id}" is a ${layer.type} layer.`);
6572
6638
  const sel = this.state.selection;
6573
- if (!_optionalChain([sel, 'optionalAccess', _225 => _225.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select the pixels to copy first.");
6639
+ if (!_optionalChain([sel, 'optionalAccess', _226 => _226.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select the pixels to copy first.");
6574
6640
  if (options.cut) _chunkQE7D7TZRcjs.requireUnlocked.call(void 0, layer, "pixels", "cut from it");
6575
6641
  const surface = this.surfaceOf(layer);
6576
6642
  const sb = sel.bounds;
@@ -6588,14 +6654,14 @@ var ImageEditorController = (_class12 = class {
6588
6654
  const copy = {
6589
6655
  type: "pixel",
6590
6656
  id: _chunkQE7D7TZRcjs.newLayerId.call(void 0, ),
6591
- name: _optionalChain([options, 'access', _226 => _226.name, 'optionalAccess', _227 => _227.trim, 'call', _228 => _228()]) || `${layer.name || "Layer"} ${options.cut ? "cut" : "copy"}`,
6657
+ name: _optionalChain([options, 'access', _227 => _227.name, 'optionalAccess', _228 => _228.trim, 'call', _229 => _229()]) || `${layer.name || "Layer"} ${options.cut ? "cut" : "copy"}`,
6592
6658
  visible: true,
6593
6659
  opacity: 1,
6594
6660
  blend: "normal",
6595
6661
  surface: _chunk474IQG74cjs.surfaceFromPixels.call(void 0, { width: src.width, height: src.height, data: px2 }, 4, src.x, src.y),
6596
6662
  offset: { ...layer.offset }
6597
6663
  };
6598
- let next = _chunkUOGKSVRQcjs.insertLayer.call(void 0, this.state.layers, copy, _nullishCoalesce(_optionalChain([loc, 'access', _229 => _229.parent, 'optionalAccess', _230 => _230.id]), () => ( null)), loc.index + 1);
6664
+ let next = _chunkUOGKSVRQcjs.insertLayer.call(void 0, this.state.layers, copy, _nullishCoalesce(_optionalChain([loc, 'access', _230 => _230.parent, 'optionalAccess', _231 => _231.id]), () => ( null)), loc.index + 1);
6599
6665
  if (kept) {
6600
6666
  const cutLayer = { ...layer, surface: _chunk474IQG74cjs.writeRegion.call(void 0, surface, src, kept) };
6601
6667
  delete cutLayer.source;
@@ -6608,7 +6674,7 @@ var ImageEditorController = (_class12 = class {
6608
6674
  return copy.id;
6609
6675
  }
6610
6676
  // --- Free Transform ---
6611
- __init95() {this.openTransform = null}
6677
+ __init96() {this.openTransform = null}
6612
6678
  /** The Free Transform in progress (see `beginFreeTransform`), or `null`. */
6613
6679
  getFreeTransform() {
6614
6680
  if (this.openTransform && !this.openTransform.isOpen) this.openTransform = null;
@@ -6619,7 +6685,7 @@ var ImageEditorController = (_class12 = class {
6619
6685
  layers: () => this.state.layers,
6620
6686
  activeLayerId: () => this.state.activeLayerId,
6621
6687
  activeTarget: () => this.state.activeTarget,
6622
- selection: () => _optionalChain([this, 'access', _231 => _231.state, 'access', _232 => _232.selection, 'optionalAccess', _233 => _233.bounds]) ? this.state.selection : null,
6688
+ selection: () => _optionalChain([this, 'access', _232 => _232.state, 'access', _233 => _233.selection, 'optionalAccess', _234 => _234.bounds]) ? this.state.selection : null,
6623
6689
  canvas: () => this.naturalSize,
6624
6690
  pixelsOf: (layer) => this.surfaceOf(layer),
6625
6691
  shapeEnv: () => this.shapeEnv(),
@@ -6767,7 +6833,7 @@ var ImageEditorController = (_class12 = class {
6767
6833
  * anything else nests as a layer document. Returns the smart object's id.
6768
6834
  */
6769
6835
  convertToSmartObject(ids, options = {}) {
6770
- const list = _optionalChain([ids, 'optionalAccess', _234 => _234.length]) ? ids : this.state.activeLayerId ? [this.state.activeLayerId] : [];
6836
+ const list = _optionalChain([ids, 'optionalAccess', _235 => _235.length]) ? ids : this.state.activeLayerId ? [this.state.activeLayerId] : [];
6771
6837
  if (!list.length) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("No layers given and none is active; pass layerIds (see list_layers).");
6772
6838
  const res = _chunkQE7D7TZRcjs.convertToSmartObject.call(void 0, this.state.layers, list, this.canvasSize, { surfaceOf: (l) => this.surfaceOf(l), name: options.name });
6773
6839
  this.commitLayers(res.layers, () => {
@@ -6800,8 +6866,8 @@ var ImageEditorController = (_class12 = class {
6800
6866
  width: c.width,
6801
6867
  height: c.height,
6802
6868
  decoded: _chunkQE7D7TZRcjs.isContentsDecoded.call(void 0, c),
6803
- fileType: _nullishCoalesce(_optionalChain([c, 'access', _235 => _235.file, 'optionalAccess', _236 => _236.type]), () => ( null)),
6804
- linkedPath: _nullishCoalesce(_optionalChain([c, 'access', _237 => _237.linked, 'optionalAccess', _238 => _238.path]), () => ( null)),
6869
+ fileType: _nullishCoalesce(_optionalChain([c, 'access', _236 => _236.file, 'optionalAccess', _237 => _237.type]), () => ( null)),
6870
+ linkedPath: _nullishCoalesce(_optionalChain([c, 'access', _238 => _238.linked, 'optionalAccess', _239 => _239.path]), () => ( null)),
6805
6871
  instances: _chunkQE7D7TZRcjs.instancesOf.call(void 0, this.state.layers, c.id),
6806
6872
  layerCount: c.document ? _chunkUOGKSVRQcjs.flattenLayers.call(void 0, c.document.layers).length : 0
6807
6873
  },
@@ -6818,9 +6884,9 @@ var ImageEditorController = (_class12 = class {
6818
6884
  bounds: _chunkQE7D7TZRcjs.transformedBox.call(void 0, g)
6819
6885
  },
6820
6886
  smartFilters: {
6821
- enabled: _nullishCoalesce(_optionalChain([stack, 'optionalAccess', _239 => _239.enabled]), () => ( true)),
6822
- filters: (_nullishCoalesce(_optionalChain([stack, 'optionalAccess', _240 => _240.filters]), () => ( []))).map((f) => f.kind === "psd" ? { id: f.id, kind: "psd", name: f.name, enabled: f.enabled, blend: f.blend, opacity: f.opacity } : { ...f }),
6823
- mask: _optionalChain([stack, 'optionalAccess', _241 => _241.mask]) ? { enabled: stack.mask.enabled !== false, linked: stack.mask.linked !== false, density: _nullishCoalesce(stack.mask.density, () => ( 1)), feather: _nullishCoalesce(stack.mask.feather, () => ( 0)), bounds: _chunk474IQG74cjs.contentBounds.call(void 0, stack.mask.surface), defaultValue: stack.mask.defaultValue } : null
6887
+ enabled: _nullishCoalesce(_optionalChain([stack, 'optionalAccess', _240 => _240.enabled]), () => ( true)),
6888
+ filters: (_nullishCoalesce(_optionalChain([stack, 'optionalAccess', _241 => _241.filters]), () => ( []))).map((f) => f.kind === "psd" ? { id: f.id, kind: "psd", name: f.name, enabled: f.enabled, blend: f.blend, opacity: f.opacity } : { ...f }),
6889
+ mask: _optionalChain([stack, 'optionalAccess', _242 => _242.mask]) ? { enabled: stack.mask.enabled !== false, linked: stack.mask.linked !== false, density: _nullishCoalesce(stack.mask.density, () => ( 1)), feather: _nullishCoalesce(stack.mask.feather, () => ( 0)), bounds: _chunk474IQG74cjs.contentBounds.call(void 0, stack.mask.surface), defaultValue: stack.mask.defaultValue } : null
6824
6890
  },
6825
6891
  bounds: this.getLayerBounds(id)
6826
6892
  };
@@ -6959,7 +7025,7 @@ var ImageEditorController = (_class12 = class {
6959
7025
  * it in the same undo step (Photoshop limits a filter to the selection). Returns whether it did.
6960
7026
  */
6961
7027
  maskFiltersWithSelection(id, useSelection) {
6962
- if (!useSelection || !_optionalChain([this, 'access', _242 => _242.state, 'access', _243 => _243.selection, 'optionalAccess', _244 => _244.bounds])) return false;
7028
+ if (!useSelection || !_optionalChain([this, 'access', _243 => _243.state, 'access', _244 => _244.selection, 'optionalAccess', _245 => _245.bounds])) return false;
6963
7029
  this.setSmartFilterMask(id, "selection", {}, false);
6964
7030
  return true;
6965
7031
  }
@@ -6973,19 +7039,19 @@ var ImageEditorController = (_class12 = class {
6973
7039
  removeSmartFilter(id, filterId) {
6974
7040
  const res = _chunkQE7D7TZRcjs.removeSmartFilter.call(void 0, this.state.layers, id, filterId, this.canvasSize);
6975
7041
  this.commitLayers(res.layers);
6976
- return _nullishCoalesce(_optionalChain([res, 'access', _245 => _245.layer, 'access', _246 => _246.smartFilters, 'optionalAccess', _247 => _247.filters]), () => ( []));
7042
+ return _nullishCoalesce(_optionalChain([res, 'access', _246 => _246.layer, 'access', _247 => _247.smartFilters, 'optionalAccess', _248 => _248.filters]), () => ( []));
6977
7043
  }
6978
7044
  /** Moves one smart filter to `index` (0 = bottom, applied first), as one undo step. Returns the filters. */
6979
7045
  moveSmartFilter(id, filterId, index) {
6980
7046
  const res = _chunkQE7D7TZRcjs.moveSmartFilter.call(void 0, this.state.layers, id, filterId, index, this.canvasSize);
6981
7047
  this.commitLayers(res.layers);
6982
- return _nullishCoalesce(_optionalChain([res, 'access', _248 => _248.layer, 'access', _249 => _249.smartFilters, 'optionalAccess', _250 => _250.filters]), () => ( []));
7048
+ return _nullishCoalesce(_optionalChain([res, 'access', _249 => _249.layer, 'access', _250 => _250.smartFilters, 'optionalAccess', _251 => _251.filters]), () => ( []));
6983
7049
  }
6984
7050
  /** Turns a smart object's whole filter stack on or off (one undo step). */
6985
7051
  setSmartFiltersEnabled(id, enabled) {
6986
7052
  const res = _chunkQE7D7TZRcjs.setSmartFiltersEnabled.call(void 0, this.state.layers, id, enabled, this.canvasSize);
6987
7053
  this.commitLayers(res.layers);
6988
- return _nullishCoalesce(_optionalChain([res, 'access', _251 => _251.layer, 'access', _252 => _252.smartFilters, 'optionalAccess', _253 => _253.enabled]), () => ( true));
7054
+ return _nullishCoalesce(_optionalChain([res, 'access', _252 => _252.layer, 'access', _253 => _253.smartFilters, 'optionalAccess', _254 => _254.enabled]), () => ( true));
6989
7055
  }
6990
7056
  /**
6991
7057
  * Sets the smart filter mask (one undo step): `reveal-all`, `hide-all`, `selection` (the
@@ -6997,11 +7063,11 @@ var ImageEditorController = (_class12 = class {
6997
7063
  let mask;
6998
7064
  if (from === "none") mask = null;
6999
7065
  else if (from === "keep") {
7000
- if (!_optionalChain([layer, 'access', _254 => _254.smartFilters, 'optionalAccess', _255 => _255.mask])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Smart object "${layer.name || id}" has no filter mask; add one with from reveal-all, hide-all or selection.`);
7066
+ if (!_optionalChain([layer, 'access', _255 => _255.smartFilters, 'optionalAccess', _256 => _256.mask])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Smart object "${layer.name || id}" has no filter mask; add one with from reveal-all, hide-all or selection.`);
7001
7067
  mask = withMaskProps(layer.smartFilters.mask, props);
7002
7068
  } else if (from === "selection") {
7003
7069
  const sel = this.state.selection;
7004
- if (!_optionalChain([sel, 'optionalAccess', _256 => _256.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, or use reveal-all / hide-all.");
7070
+ if (!_optionalChain([sel, 'optionalAccess', _257 => _257.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, or use reveal-all / hide-all.");
7005
7071
  mask = this.maskFromSelection(sel, props);
7006
7072
  } else {
7007
7073
  const v = from === "reveal-all" ? 255 : 0;
@@ -7013,7 +7079,7 @@ var ImageEditorController = (_class12 = class {
7013
7079
  if (mask && from !== "keep") this.state.activeTarget = "filter-mask";
7014
7080
  else if (!mask && this.state.activeTarget === "filter-mask") this.state.activeTarget = "pixels";
7015
7081
  }, commitToHistory);
7016
- return _nullishCoalesce(_optionalChain([res, 'access', _257 => _257.layer, 'access', _258 => _258.smartFilters, 'optionalAccess', _259 => _259.mask]), () => ( null));
7082
+ return _nullishCoalesce(_optionalChain([res, 'access', _258 => _258.layer, 'access', _259 => _259.smartFilters, 'optionalAccess', _260 => _260.mask]), () => ( null));
7017
7083
  }
7018
7084
  /**
7019
7085
  * Decodes smart object contents that came as files the synchronous decoders cannot read (a JPEG
@@ -7046,7 +7112,7 @@ var ImageEditorController = (_class12 = class {
7046
7112
  return left;
7047
7113
  }
7048
7114
  // --- Smart object contents (Edit Contents) ---
7049
- __init96() {this.contentsStack = []}
7115
+ __init97() {this.contentsStack = []}
7050
7116
  /** The smart objects whose contents are open (outermost first); empty when the document itself is shown. */
7051
7117
  getEditingContents() {
7052
7118
  return this.contentsStack.map((e) => ({ layerId: e.layerId, name: e.name }));
@@ -7061,7 +7127,7 @@ var ImageEditorController = (_class12 = class {
7061
7127
  if (this.getFreeTransform()) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("A Free Transform is open; commit or cancel it first.");
7062
7128
  const layer = _chunkQE7D7TZRcjs.requireSmartObject.call(void 0, this.state.layers, id);
7063
7129
  const c = layer.contents;
7064
- if (!_chunkQE7D7TZRcjs.isContentsDecoded.call(void 0, c)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`The contents of "${layer.name || id}" are a ${_nullishCoalesce(_optionalChain([c, 'access', _260 => _260.file, 'optionalAccess', _261 => _261.type]), () => ( "file"))} that could not be decoded here; run prepareSmartObjects() in a browser first.`);
7130
+ if (!_chunkQE7D7TZRcjs.isContentsDecoded.call(void 0, c)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`The contents of "${layer.name || id}" are a ${_nullishCoalesce(_optionalChain([c, 'access', _261 => _261.file, 'optionalAccess', _262 => _262.type]), () => ( "file"))} that could not be decoded here; run prepareSmartObjects() in a browser first.`);
7065
7131
  const saved = {
7066
7132
  state: { ...this.state },
7067
7133
  undo: this.undoStack,
@@ -7092,9 +7158,9 @@ var ImageEditorController = (_class12 = class {
7092
7158
  editingContents: this.getEditingContents()
7093
7159
  };
7094
7160
  delete this.state.legacyOutputBlur;
7095
- if (_optionalChain([c, 'access', _262 => _262.document, 'optionalAccess', _263 => _263.globalLight])) this.state.globalLight = c.document.globalLight;
7161
+ if (_optionalChain([c, 'access', _263 => _263.document, 'optionalAccess', _264 => _264.globalLight])) this.state.globalLight = c.document.globalLight;
7096
7162
  else delete this.state.globalLight;
7097
- if (_optionalChain([c, 'access', _264 => _264.document, 'optionalAccess', _265 => _265.patterns, 'optionalAccess', _266 => _266.length])) this.state.patterns = c.document.patterns;
7163
+ if (_optionalChain([c, 'access', _265 => _265.document, 'optionalAccess', _266 => _266.patterns, 'optionalAccess', _267 => _267.length])) this.state.patterns = c.document.patterns;
7098
7164
  else delete this.state.patterns;
7099
7165
  this.imageElement = null;
7100
7166
  this.samplePixels = null;
@@ -7114,23 +7180,23 @@ var ImageEditorController = (_class12 = class {
7114
7180
  closeSmartObjectContents(save = true) {
7115
7181
  const top = this.contentsStack.pop();
7116
7182
  if (!top) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("No smart object contents are open; open them with edit_smart_object_contents.");
7117
- if (_optionalChain([this, 'access', _267 => _267.openTransform, 'optionalAccess', _268 => _268.isOpen])) this.openTransform.cancel();
7183
+ if (_optionalChain([this, 'access', _268 => _268.openTransform, 'optionalAccess', _269 => _269.isOpen])) this.openTransform.cancel();
7118
7184
  this.openTransform = null;
7119
7185
  const edited = this.state;
7120
7186
  const changed = save && this.undoStack.length > 0;
7121
7187
  let next = null;
7122
7188
  if (changed) {
7123
- const layer = _optionalChain([_chunkUOGKSVRQcjs.findLayer.call(void 0, top.saved.state.layers, top.layerId), 'optionalAccess', _269 => _269.layer]);
7124
- const old = _optionalChain([layer, 'optionalAccess', _270 => _270.contents]);
7189
+ const layer = _optionalChain([_chunkUOGKSVRQcjs.findLayer.call(void 0, top.saved.state.layers, top.layerId), 'optionalAccess', _270 => _270.layer]);
7190
+ const old = _optionalChain([layer, 'optionalAccess', _271 => _271.contents]);
7125
7191
  const { width, height } = edited.imageDimensions;
7126
7192
  const only = edited.layers.length === 1 ? edited.layers[0] : null;
7127
- const plain3 = _optionalChain([only, 'optionalAccess', _271 => _271.type]) === "pixel" && only.visible && only.opacity === 1 && only.blend === "normal" && !only.mask && !only.effects && !_optionalChain([only, 'access', _272 => _272.filters, 'optionalAccess', _273 => _273.length]) && !only.clipped && (_nullishCoalesce(only.fillOpacity, () => ( 1))) === 1 && only.source !== "document";
7128
- if (_optionalChain([old, 'optionalAccess', _274 => _274.kind]) === "raster" && plain3) {
7193
+ const plain3 = _optionalChain([only, 'optionalAccess', _272 => _272.type]) === "pixel" && only.visible && only.opacity === 1 && only.blend === "normal" && !only.mask && !only.effects && !_optionalChain([only, 'access', _273 => _273.filters, 'optionalAccess', _274 => _274.length]) && !only.clipped && (_nullishCoalesce(only.fillOpacity, () => ( 1))) === 1 && only.source !== "document";
7194
+ if (_optionalChain([old, 'optionalAccess', _275 => _275.kind]) === "raster" && plain3) {
7129
7195
  const px2 = _chunk474IQG74cjs.readRegion.call(void 0, only.surface, { x: -only.offset.x, y: -only.offset.y, width, height });
7130
7196
  next = _chunkQE7D7TZRcjs.rasterContents.call(void 0, { width, height, data: px2 }, old.name, old.id);
7131
7197
  } else {
7132
7198
  const doc = { layers: edited.layers, globalLight: edited.globalLight, patterns: edited.patterns };
7133
- next = _chunkQE7D7TZRcjs.documentContents.call(void 0, doc, width, height, _optionalChain([old, 'optionalAccess', _275 => _275.kind]) === "document" ? old.name : `${(_nullishCoalesce(_optionalChain([old, 'optionalAccess', _276 => _276.name]), () => ( "Contents"))).replace(/\.\w+$/, "")}.psb`, top.contentsId);
7199
+ next = _chunkQE7D7TZRcjs.documentContents.call(void 0, doc, width, height, _optionalChain([old, 'optionalAccess', _276 => _276.kind]) === "document" ? old.name : `${(_nullishCoalesce(_optionalChain([old, 'optionalAccess', _277 => _277.name]), () => ( "Contents"))).replace(/\.\w+$/, "")}.psb`, top.contentsId);
7134
7200
  }
7135
7201
  }
7136
7202
  const saved = top.saved;
@@ -7155,7 +7221,7 @@ var ImageEditorController = (_class12 = class {
7155
7221
  }
7156
7222
  /** The document's own layers (not the contents open for editing). */
7157
7223
  rootLayers() {
7158
- return _nullishCoalesce(_optionalChain([this, 'access', _277 => _277.contentsStack, 'access', _278 => _278[0], 'optionalAccess', _279 => _279.saved, 'access', _280 => _280.state, 'access', _281 => _281.layers]), () => ( this.state.layers));
7224
+ return _nullishCoalesce(_optionalChain([this, 'access', _278 => _278.contentsStack, 'access', _279 => _279[0], 'optionalAccess', _280 => _280.saved, 'access', _281 => _281.state, 'access', _282 => _282.layers]), () => ( this.state.layers));
7159
7225
  }
7160
7226
  /** Drops every open contents edit (loading another document). */
7161
7227
  abandonContents() {
@@ -7195,7 +7261,7 @@ var ImageEditorController = (_class12 = class {
7195
7261
  this.commitLayers(_chunkQE7D7TZRcjs.setLayerEffects.call(void 0, this.state.layers, id, effects), void 0, commitToHistory);
7196
7262
  return this.getLayerEffects(id);
7197
7263
  }
7198
- __init97() {this.patternIds = /* @__PURE__ */ new WeakMap()}
7264
+ __init98() {this.patternIds = /* @__PURE__ */ new WeakMap()}
7199
7265
  /** Changes whenever the document's pattern list is replaced (the compositor then drops its caches). */
7200
7266
  patternsVersion() {
7201
7267
  const list = this.state.patterns;
@@ -7357,7 +7423,7 @@ var ImageEditorController = (_class12 = class {
7357
7423
  });
7358
7424
  return bg.id;
7359
7425
  }
7360
- __init98() {this.thumbCache = /* @__PURE__ */ new WeakMap()}
7426
+ __init99() {this.thumbCache = /* @__PURE__ */ new WeakMap()}
7361
7427
  /**
7362
7428
  * A small RGBA preview of a pixel layer over the canvas (or of its mask with `mask: true`),
7363
7429
  * longest side `maxSide` px, point-sampled; `null` for layers without pixels.
@@ -7376,7 +7442,7 @@ var ImageEditorController = (_class12 = class {
7376
7442
  const oy = layer.type === "pixel" ? layer.offset.y : 0;
7377
7443
  const key = `${tw}x${th}:${ox},${oy}`;
7378
7444
  let byKey = this.thumbCache.get(surface);
7379
- const hit = _optionalChain([byKey, 'optionalAccess', _282 => _282.get, 'call', _283 => _283(key)]);
7445
+ const hit = _optionalChain([byKey, 'optionalAccess', _283 => _283.get, 'call', _284 => _284(key)]);
7380
7446
  if (hit) return hit;
7381
7447
  const out = new Uint8ClampedArray(tw * th * 4);
7382
7448
  for (let y = 0; y < th; y++) {
@@ -7517,7 +7583,7 @@ var ImageEditorController = (_class12 = class {
7517
7583
  if (layer.mask.source) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${name}" has a depth mask, which is generated, not painted.`);
7518
7584
  _chunkQE7D7TZRcjs.requireUnlocked.call(void 0, layer, "all", action);
7519
7585
  } else if (ch === "filter-mask") {
7520
- if (layer.type !== "smart" || !_optionalChain([layer, 'access', _284 => _284.smartFilters, 'optionalAccess', _285 => _285.mask])) {
7586
+ if (layer.type !== "smart" || !_optionalChain([layer, 'access', _285 => _285.smartFilters, 'optionalAccess', _286 => _286.mask])) {
7521
7587
  throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${name}" has no smart filter mask to ${action}; add one with set_smart_filter_mask, or target pixels or mask.`, `Layer "${name}" has no smart filter mask to ${action}.`);
7522
7588
  }
7523
7589
  if (!_chunkQE7D7TZRcjs.isContentsDecoded.call(void 0, layer.contents)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`The contents of "${name}" are not decoded here, so its filter mask cannot be painted; run prepareSmartObjects() first.`, `The smart object "${name}" is still loading; try again in a moment.`);
@@ -7532,7 +7598,7 @@ var ImageEditorController = (_class12 = class {
7532
7598
  if (!layer.visible) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${name}" is hidden; show it before you ${action}.`);
7533
7599
  const offset = layer.type === "pixel" ? layer.offset : { x: 0, y: 0 };
7534
7600
  const surface = ch === "mask" ? layer.mask.surface : ch === "filter-mask" ? layer.smartFilters.mask.surface : this.surfaceOf(layer);
7535
- const lockTransparency = ch === "pixels" && Boolean(_optionalChain([layer, 'access', _286 => _286.locks, 'optionalAccess', _287 => _287.transparency]));
7601
+ const lockTransparency = ch === "pixels" && Boolean(_optionalChain([layer, 'access', _287 => _287.locks, 'optionalAccess', _288 => _288.transparency]));
7536
7602
  return { id, layer, channel: ch, offset, surface, lockTransparency };
7537
7603
  }
7538
7604
  /** The layer with its pixels (or mask) replaced by `surface`. */
@@ -7576,13 +7642,13 @@ var ImageEditorController = (_class12 = class {
7576
7642
  blend: target.channel !== "pixels" ? "normal" : brush.blend,
7577
7643
  lockTransparency: target.lockTransparency,
7578
7644
  // In Quick Mask mode the selection is what is painted, so it does not limit the stroke.
7579
- selection: target.channel !== "quick-mask" && _optionalChain([this, 'access', _288 => _288.state, 'access', _289 => _289.selection, 'optionalAccess', _290 => _290.bounds]) ? this.state.selection : null,
7645
+ selection: target.channel !== "quick-mask" && _optionalChain([this, 'access', _289 => _289.state, 'access', _290 => _290.selection, 'optionalAccess', _291 => _291.bounds]) ? this.state.selection : null,
7580
7646
  offset: target.offset
7581
7647
  };
7582
7648
  const depth = target.channel !== "filter-mask" && target.channel !== "quick-mask" && this.bitDepth !== 8 ? this.bitDepth : null;
7583
7649
  if (tool === "mixer") return new PaintStrokeSession(this, target, this.mixerStroke(init, brush), apply, depth);
7584
7650
  if (isRetouchTool(tool)) return new PaintStrokeSession(this, target, this.retouchStroke(tool, init, brush, target, apply), apply, depth);
7585
- const gradient = tool === "brush" && _optionalChain([strokePaint, 'optionalAccess', _291 => _291.type]) === "gradient" ? _chunkPQ3H2AANcjs.resolvePaintGradient.call(void 0, strokePaint, { paint: toHex(color), secondary: toHex(background) }) : null;
7651
+ const gradient = tool === "brush" && _optionalChain([strokePaint, 'optionalAccess', _292 => _292.type]) === "gradient" ? _chunkPQ3H2AANcjs.resolvePaintGradient.call(void 0, strokePaint, { paint: toHex(color), secondary: toHex(background) }) : null;
7586
7652
  return new PaintStrokeSession(this, target, new (0, _chunkPQ3H2AANcjs.StrokeCoverage)(brush, gradient, _nullishCoalesce(init.seed, () => ( 0))), apply, depth);
7587
7653
  }
7588
7654
  /** A retouching stroke's start: its settings, what it samples and how it composites. */
@@ -7629,9 +7695,9 @@ var ImageEditorController = (_class12 = class {
7629
7695
  const steps = settings.historySteps;
7630
7696
  const entry = steps > 0 ? _nullishCoalesce(this.undoStack[this.undoStack.length - steps], () => ( this.undoStack[0])) : this.undoStack[0];
7631
7697
  if (!entry) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("There is no earlier state to paint from yet: the History Brush paints a layer as it was some undo steps back. Make a change first.");
7632
- const then = _optionalChain([_chunkUOGKSVRQcjs.findLayer.call(void 0, entry.layers, target.id), 'optionalAccess', _292 => _292.layer]);
7698
+ const then = _optionalChain([_chunkUOGKSVRQcjs.findLayer.call(void 0, entry.layers, target.id), 'optionalAccess', _293 => _293.layer]);
7633
7699
  if (!then) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${target.id}" did not exist ${steps > 0 ? `${steps} steps back` : "in the oldest state"}; choose fewer history steps (historySteps).`);
7634
- const surface = target.channel === "mask" ? _optionalChain([then, 'access', _293 => _293.mask, 'optionalAccess', _294 => _294.surface]) : then.type === "pixel" ? then.surface : void 0;
7700
+ const surface = target.channel === "mask" ? _optionalChain([then, 'access', _294 => _294.mask, 'optionalAccess', _295 => _295.surface]) : then.type === "pixel" ? then.surface : void 0;
7635
7701
  if (!surface) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${target.id}" had no ${target.channel === "mask" ? "mask" : "pixels"} in that state.`);
7636
7702
  const offset2 = then.type === "pixel" ? then.offset : { x: 0, y: 0 };
7637
7703
  const depth = !mask && this.bitDepth !== 8 ? this.bitDepth : null;
@@ -7705,7 +7771,7 @@ var ImageEditorController = (_class12 = class {
7705
7771
  }
7706
7772
  /** A pixel source over a surface (layer pixels or a mask) in layer space at `offset`. */
7707
7773
  surfaceSource(surface, offset) {
7708
- return new (0, _chunk3EHPLDFQcjs.TilePixelSource)((tx, ty) => _nullishCoalesce(_optionalChain([surface, 'access', _295 => _295.tiles, 'access', _296 => _296.get, 'call', _297 => _297(_chunk474IQG74cjs.tileKey.call(void 0, tx, ty)), 'optionalAccess', _298 => _298.data]), () => ( (surface.defaultValue ? defaultTile(surface) : null))), surface.channels, offset);
7774
+ return new (0, _chunk3EHPLDFQcjs.TilePixelSource)((tx, ty) => _nullishCoalesce(_optionalChain([surface, 'access', _296 => _296.tiles, 'access', _297 => _297.get, 'call', _298 => _298(_chunk474IQG74cjs.tileKey.call(void 0, tx, ty)), 'optionalAccess', _299 => _299.data]), () => ( (surface.defaultValue ? defaultTile(surface) : null))), surface.channels, offset);
7709
7775
  }
7710
7776
  /** A pixel source over the composite of the current layers (through `throughId` and below, or all of them), as it is now. */
7711
7777
  compositeSource(throughId, depth = null) {
@@ -7781,7 +7847,7 @@ var ImageEditorController = (_class12 = class {
7781
7847
  paintStroke(init) {
7782
7848
  if (!Array.isArray(init.points) || !init.points.length) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("points must hold at least one { x, y } point.");
7783
7849
  for (const p of init.points) {
7784
- if (!Number.isFinite(_optionalChain([p, 'optionalAccess', _299 => _299.x])) || !Number.isFinite(_optionalChain([p, 'optionalAccess', _300 => _300.y]))) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Every point needs finite x and y (document pixels).");
7850
+ if (!Number.isFinite(_optionalChain([p, 'optionalAccess', _300 => _300.x])) || !Number.isFinite(_optionalChain([p, 'optionalAccess', _301 => _301.y]))) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Every point needs finite x and y (document pixels).");
7785
7851
  }
7786
7852
  const session = this.beginStroke(init);
7787
7853
  session.push(init.points);
@@ -7810,7 +7876,7 @@ var ImageEditorController = (_class12 = class {
7810
7876
  */
7811
7877
  strokeSelection(options) {
7812
7878
  const sel = this.state.selection;
7813
- if (!_optionalChain([sel, 'optionalAccess', _301 => _301.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, then stroke the selection.");
7879
+ if (!_optionalChain([sel, 'optionalAccess', _302 => _302.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, then stroke the selection.");
7814
7880
  const width = options.width;
7815
7881
  if (!(width > 0 && width <= 250)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("width must be greater than 0 and at most 250 px.");
7816
7882
  const location = _nullishCoalesce(options.location, () => ( "outside"));
@@ -7827,7 +7893,7 @@ var ImageEditorController = (_class12 = class {
7827
7893
  */
7828
7894
  cropToSelection() {
7829
7895
  const sel = this.state.selection;
7830
- if (!_optionalChain([sel, 'optionalAccess', _302 => _302.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select the area to keep, then crop to it.");
7896
+ if (!_optionalChain([sel, 'optionalAccess', _303 => _303.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select the area to keep, then crop to it.");
7831
7897
  const crop = { ...sel.bounds };
7832
7898
  this.setCrop(crop);
7833
7899
  return crop;
@@ -7841,7 +7907,7 @@ var ImageEditorController = (_class12 = class {
7841
7907
  */
7842
7908
  contentAwareFill(options = {}) {
7843
7909
  const sel = this.state.selection;
7844
- if (!_optionalChain([sel, 'optionalAccess', _303 => _303.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select what to remove, then fill it.");
7910
+ if (!_optionalChain([sel, 'optionalAccess', _304 => _304.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select what to remove, then fill it.");
7845
7911
  if (this.bitDepth !== 8) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Content-Aware Fill works on 8-bit documents for now; set_bit_depth 8 first, or use spot_heal.");
7846
7912
  const output = _nullishCoalesce(options.output, () => ( "current"));
7847
7913
  if (output !== "current" && output !== "new-layer") throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Unknown output "${String(output)}"; use current or new-layer.`);
@@ -7887,7 +7953,7 @@ var ImageEditorController = (_class12 = class {
7887
7953
  return { layerId: target.id, bounds: { ...b }, output };
7888
7954
  }
7889
7955
  /** The pixel clipboard (Copy / Cut), or null. */
7890
- __init99() {this.clipboard = null}
7956
+ __init100() {this.clipboard = null}
7891
7957
  /** What Copy or Cut last put on the editor's clipboard, or null. */
7892
7958
  getClipboard() {
7893
7959
  return this.clipboard;
@@ -7906,8 +7972,8 @@ var ImageEditorController = (_class12 = class {
7906
7972
  */
7907
7973
  copyPixels(options = {}) {
7908
7974
  const { width, height } = this.naturalSize;
7909
- const sel = _optionalChain([this, 'access', _304 => _304.state, 'access', _305 => _305.selection, 'optionalAccess', _306 => _306.bounds]) ? this.state.selection : null;
7910
- const rect = _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _307 => _307.bounds]), () => ( { x: 0, y: 0, width, height }));
7975
+ const sel = _optionalChain([this, 'access', _305 => _305.state, 'access', _306 => _306.selection, 'optionalAccess', _307 => _307.bounds]) ? this.state.selection : null;
7976
+ const rect = _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _308 => _308.bounds]), () => ( { x: 0, y: 0, width, height }));
7911
7977
  let data;
7912
7978
  if (options.merged) {
7913
7979
  data = new Uint8ClampedArray(this.compositePixels(rect).data);
@@ -7947,7 +8013,7 @@ var ImageEditorController = (_class12 = class {
7947
8013
  pastePixels(mode = "new-layer", image = this.clipboard) {
7948
8014
  if (!image) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("The clipboard is empty; copy_pixels first.");
7949
8015
  if (!PASTE_MODES.includes(mode)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Unknown paste mode "${String(mode)}"; use ${PASTE_MODES.join(", ")}.`);
7950
- const sel = _optionalChain([this, 'access', _308 => _308.state, 'access', _309 => _309.selection, 'optionalAccess', _310 => _310.bounds]) ? this.state.selection : null;
8016
+ const sel = _optionalChain([this, 'access', _309 => _309.state, 'access', _310 => _310.selection, 'optionalAccess', _311 => _311.bounds]) ? this.state.selection : null;
7951
8017
  if ((mode === "into" || mode === "outside") && !sel) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Paste ${mode === "into" ? "Into" : "Outside"} needs a selection; select where it goes first.`);
7952
8018
  const { width, height } = this.naturalSize;
7953
8019
  let x;
@@ -7956,7 +8022,7 @@ var ImageEditorController = (_class12 = class {
7956
8022
  x = image.x;
7957
8023
  y = image.y;
7958
8024
  } else {
7959
- const frame = _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _311 => _311.bounds]), () => ( { x: 0, y: 0, width, height }));
8025
+ const frame = _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _312 => _312.bounds]), () => ( { x: 0, y: 0, width, height }));
7960
8026
  x = Math.round(frame.x + (frame.width - image.width) / 2);
7961
8027
  y = Math.round(frame.y + (frame.height - image.height) / 2);
7962
8028
  }
@@ -7973,8 +8039,8 @@ var ImageEditorController = (_class12 = class {
7973
8039
  if (!(opacity >= 0 && opacity <= 1)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("opacity must be from 0 to 1.");
7974
8040
  const blend = _nullishCoalesce(_chunkQE7D7TZRcjs.parseBlend.call(void 0, options.blend), () => ( "normal"));
7975
8041
  const quickMask = target.channel === "quick-mask";
7976
- const sel = _nullishCoalesce(coverageMask, () => ( (!quickMask && options.useSelection !== false && _optionalChain([this, 'access', _312 => _312.state, 'access', _313 => _313.selection, 'optionalAccess', _314 => _314.bounds]) ? this.state.selection : null)));
7977
- const region = _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _315 => _315.bounds]), () => ( { x: 0, y: 0, width, height }));
8042
+ const sel = _nullishCoalesce(coverageMask, () => ( (!quickMask && options.useSelection !== false && _optionalChain([this, 'access', _313 => _313.state, 'access', _314 => _314.selection, 'optionalAccess', _315 => _315.bounds]) ? this.state.selection : null)));
8043
+ const region = _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _316 => _316.bounds]), () => ( { x: 0, y: 0, width, height }));
7978
8044
  const coverage = new (0, _chunkPQ3H2AANcjs.CoverageMap)();
7979
8045
  const ones = new Float32Array(region.width * region.height);
7980
8046
  if (sel) {
@@ -8099,7 +8165,7 @@ var ImageEditorController = (_class12 = class {
8099
8165
  placeLayer(layers, node, where) {
8100
8166
  if (where.aboveId) {
8101
8167
  const loc = _chunkUOGKSVRQcjs.findLayer.call(void 0, layers, where.aboveId);
8102
- if (loc) return _chunkUOGKSVRQcjs.insertLayer.call(void 0, layers, node, _nullishCoalesce(_optionalChain([loc, 'access', _316 => _316.parent, 'optionalAccess', _317 => _317.id]), () => ( null)), loc.index + 1);
8168
+ if (loc) return _chunkUOGKSVRQcjs.insertLayer.call(void 0, layers, node, _nullishCoalesce(_optionalChain([loc, 'access', _317 => _317.parent, 'optionalAccess', _318 => _318.id]), () => ( null)), loc.index + 1);
8103
8169
  }
8104
8170
  if (where.parentId) {
8105
8171
  const loc = _chunkUOGKSVRQcjs.findLayer.call(void 0, layers, where.parentId);
@@ -8110,11 +8176,11 @@ var ImageEditorController = (_class12 = class {
8110
8176
  const at = Math.max(0, Math.min(nodes.length, Math.round(where.adjustmentIndex)));
8111
8177
  if (at < nodes.length) {
8112
8178
  const loc = _chunkUOGKSVRQcjs.findLayer.call(void 0, layers, nodes[at].id);
8113
- return _chunkUOGKSVRQcjs.insertLayer.call(void 0, layers, node, _nullishCoalesce(_optionalChain([loc, 'access', _318 => _318.parent, 'optionalAccess', _319 => _319.id]), () => ( null)), loc.index);
8179
+ return _chunkUOGKSVRQcjs.insertLayer.call(void 0, layers, node, _nullishCoalesce(_optionalChain([loc, 'access', _319 => _319.parent, 'optionalAccess', _320 => _320.id]), () => ( null)), loc.index);
8114
8180
  }
8115
8181
  if (nodes.length) {
8116
8182
  const loc = _chunkUOGKSVRQcjs.findLayer.call(void 0, layers, nodes[nodes.length - 1].id);
8117
- return _chunkUOGKSVRQcjs.insertLayer.call(void 0, layers, node, _nullishCoalesce(_optionalChain([loc, 'access', _320 => _320.parent, 'optionalAccess', _321 => _321.id]), () => ( null)), loc.index + 1);
8183
+ return _chunkUOGKSVRQcjs.insertLayer.call(void 0, layers, node, _nullishCoalesce(_optionalChain([loc, 'access', _321 => _321.parent, 'optionalAccess', _322 => _322.id]), () => ( null)), loc.index + 1);
8118
8184
  }
8119
8185
  }
8120
8186
  return _chunkUOGKSVRQcjs.insertLayer.call(void 0, layers, node, null, this.defaultInsertIndex(layers));
@@ -8153,7 +8219,7 @@ var ImageEditorController = (_class12 = class {
8153
8219
  enabled: spec.enabled,
8154
8220
  opacity: spec.opacity,
8155
8221
  blend: spec.blend,
8156
- mask: _nullishCoalesce(spec.mask, () => ( (spec.useSelection && _optionalChain([this, 'access', _322 => _322.state, 'access', _323 => _323.selection, 'optionalAccess', _324 => _324.bounds]) ? _chunkQE7D7TZRcjs.layerMaskFromSelection.call(void 0, this.state.selection) : void 0)))
8222
+ mask: _nullishCoalesce(spec.mask, () => ( (spec.useSelection && _optionalChain([this, 'access', _323 => _323.state, 'access', _324 => _324.selection, 'optionalAccess', _325 => _325.bounds]) ? _chunkQE7D7TZRcjs.layerMaskFromSelection.call(void 0, this.state.selection) : void 0)))
8157
8223
  });
8158
8224
  while (ids.has(layer.id)) layer.id = _chunkQE7D7TZRcjs.newLayerId.call(void 0, "adj");
8159
8225
  const { width, height } = this.naturalSize;
@@ -8230,7 +8296,7 @@ var ImageEditorController = (_class12 = class {
8230
8296
  const anchor = nodes[to];
8231
8297
  const without = _chunkUOGKSVRQcjs.mapLayer.call(void 0, layers, id, () => null);
8232
8298
  const loc = _chunkUOGKSVRQcjs.findLayer.call(void 0, without, anchor.id);
8233
- return _chunkUOGKSVRQcjs.insertLayer.call(void 0, without, node, _nullishCoalesce(_optionalChain([loc, 'access', _325 => _325.parent, 'optionalAccess', _326 => _326.id]), () => ( null)), to > from ? loc.index + 1 : loc.index);
8299
+ return _chunkUOGKSVRQcjs.insertLayer.call(void 0, without, node, _nullishCoalesce(_optionalChain([loc, 'access', _326 => _326.parent, 'optionalAccess', _327 => _327.id]), () => ( null)), to > from ? loc.index + 1 : loc.index);
8234
8300
  }
8235
8301
  /** Moves a layer to `toIndex` among the adjustment layers (0 = bottom) as one undo step. Returns false if nothing moved. */
8236
8302
  moveAdjustmentLayer(id, toIndex) {
@@ -8271,7 +8337,7 @@ var ImageEditorController = (_class12 = class {
8271
8337
  return _nullishCoalesce(this.state.selection, () => ( null));
8272
8338
  }
8273
8339
  get hasSelection() {
8274
- return Boolean(_optionalChain([this, 'access', _327 => _327.state, 'access', _328 => _328.selection, 'optionalAccess', _329 => _329.bounds]));
8340
+ return Boolean(_optionalChain([this, 'access', _328 => _328.state, 'access', _329 => _329.selection, 'optionalAccess', _330 => _330.bounds]));
8275
8341
  }
8276
8342
  /** Returns the current canvas (composition) dimensions. */
8277
8343
  getCanvasSize() {
@@ -8363,7 +8429,7 @@ var ImageEditorController = (_class12 = class {
8363
8429
  const prev = normalizeSelection(_nullishCoalesce(this.state.selection, () => ( null)));
8364
8430
  if (prev === next || prev && next && sameSelection(prev, next)) return false;
8365
8431
  this.recordHistory();
8366
- if (!next && _optionalChain([prev, 'optionalAccess', _330 => _330.bounds])) this.lastSelection = prev;
8432
+ if (!next && _optionalChain([prev, 'optionalAccess', _331 => _331.bounds])) this.lastSelection = prev;
8367
8433
  this.state.selection = next;
8368
8434
  this.notify();
8369
8435
  return true;
@@ -8378,7 +8444,7 @@ var ImageEditorController = (_class12 = class {
8378
8444
  return this.setSelection(null);
8379
8445
  }
8380
8446
  /** The selection a Deselect cleared, for `reselect` (not saved, not part of history). */
8381
- __init100() {this.lastSelection = null}
8447
+ __init101() {this.lastSelection = null}
8382
8448
  /** Whether `reselect` has a selection to bring back. */
8383
8449
  canReselect() {
8384
8450
  const { width, height } = this.naturalSize;
@@ -8406,14 +8472,14 @@ var ImageEditorController = (_class12 = class {
8406
8472
  /** Select › Grow: adds connected pixels within `tolerance` of a selected colour (one undo step). */
8407
8473
  async growSelection(options = {}) {
8408
8474
  const sel = this.state.selection;
8409
- if (!_optionalChain([sel, 'optionalAccess', _331 => _331.bounds])) return false;
8475
+ if (!_optionalChain([sel, 'optionalAccess', _332 => _332.bounds])) return false;
8410
8476
  const pixels = await this.requirePixels(options);
8411
8477
  return this.setSelection(growSelection(pixels, sel, options));
8412
8478
  }
8413
8479
  /** Select › Similar: adds every pixel within `tolerance` of a selected colour (one undo step). */
8414
8480
  async selectSimilar(options = {}) {
8415
8481
  const sel = this.state.selection;
8416
- if (!_optionalChain([sel, 'optionalAccess', _332 => _332.bounds])) return false;
8482
+ if (!_optionalChain([sel, 'optionalAccess', _333 => _333.bounds])) return false;
8417
8483
  const pixels = await this.requirePixels(options);
8418
8484
  return this.setSelection(selectSimilar(pixels, sel, options));
8419
8485
  }
@@ -8505,7 +8571,7 @@ var ImageEditorController = (_class12 = class {
8505
8571
  size: options.size,
8506
8572
  grow: m === "add",
8507
8573
  enhanceEdge: options.enhanceEdge,
8508
- selection: m === "add" && _optionalChain([sel, 'optionalAccess', _333 => _333.bounds]) ? _chunkX4LUGTQXcjs.serializeMask.call(void 0, sel) : null
8574
+ selection: m === "add" && _optionalChain([sel, 'optionalAccess', _334 => _334.bounds]) ? _chunkX4LUGTQXcjs.serializeMask.call(void 0, sel) : null
8509
8575
  };
8510
8576
  const { mask } = await this.runSelectionJob(job, pixels, {
8511
8577
  signal: options.signal,
@@ -8525,7 +8591,7 @@ var ImageEditorController = (_class12 = class {
8525
8591
  const { width, height } = this.naturalSize;
8526
8592
  const image = await this.toDataURL({ format: "image/png" });
8527
8593
  const results = await provider.segment({ ...request, image, width, height });
8528
- _optionalChain([request, 'access', _334 => _334.signal, 'optionalAccess', _335 => _335.throwIfAborted, 'call', _336 => _336()]);
8594
+ _optionalChain([request, 'access', _335 => _335.signal, 'optionalAccess', _336 => _336.throwIfAborted, 'call', _337 => _337()]);
8529
8595
  const decoded = [];
8530
8596
  for (const r of _nullishCoalesce(results, () => ( []))) decoded.push({ ...r, mask: r.mask !== void 0 ? await this.decodeMaskImage(r.mask) : void 0 });
8531
8597
  return decoded;
@@ -8542,7 +8608,7 @@ var ImageEditorController = (_class12 = class {
8542
8608
  let union = null;
8543
8609
  for (const r of decoded) {
8544
8610
  const one = segmentsToSelection(width, height, [r]);
8545
- if (!_optionalChain([one, 'optionalAccess', _337 => _337.bounds])) continue;
8611
+ if (!_optionalChain([one, 'optionalAccess', _338 => _338.bounds])) continue;
8546
8612
  if ("rect" in target) {
8547
8613
  const r0 = target.rect;
8548
8614
  const grow = 0.1 * Math.max(r0.width, r0.height);
@@ -8610,7 +8676,7 @@ var ImageEditorController = (_class12 = class {
8610
8676
  if (this.segmentation && options.useModel !== false) {
8611
8677
  const { width, height } = this.naturalSize;
8612
8678
  const sky = segmentsToSelection(width, height, await this.modelSegments({ target: "the sky", signal: options.signal }));
8613
- if (!_optionalChain([sky, 'optionalAccess', _338 => _338.bounds])) return { selection: _nullishCoalesce(this.state.selection, () => ( null)), method: "model", note: "The segmentation model found no sky." };
8679
+ if (!_optionalChain([sky, 'optionalAccess', _339 => _339.bounds])) return { selection: _nullishCoalesce(this.state.selection, () => ( null)), method: "model", note: "The segmentation model found no sky." };
8614
8680
  this.setSelection(sky, _nullishCoalesce(options.mode, () => ( "replace")));
8615
8681
  return { selection: _nullishCoalesce(this.state.selection, () => ( null)), method: "model" };
8616
8682
  }
@@ -8641,7 +8707,7 @@ var ImageEditorController = (_class12 = class {
8641
8707
  try {
8642
8708
  const canvas = await this.renderSource();
8643
8709
  const ctx = canvas.getContext("2d");
8644
- const data2 = _optionalChain([ctx, 'optionalAccess', _339 => _339.getImageData, 'optionalCall', _340 => _340(0, 0, width, height)]);
8710
+ const data2 = _optionalChain([ctx, 'optionalAccess', _340 => _340.getImageData, 'optionalCall', _341 => _341(0, 0, width, height)]);
8645
8711
  if (data2 && data2.data && data2.data.length >= width * height * 4) {
8646
8712
  base = { width, height, data: data2.data };
8647
8713
  this.samplePixels = base;
@@ -8716,7 +8782,7 @@ var ImageEditorController = (_class12 = class {
8716
8782
  /** Select › Modify: grow, shrink, feather, border or smooth by `radius` pixels (one undo step). */
8717
8783
  modifySelection(op, radius) {
8718
8784
  const sel = this.state.selection;
8719
- if (!_optionalChain([sel, 'optionalAccess', _341 => _341.bounds])) return false;
8785
+ if (!_optionalChain([sel, 'optionalAccess', _342 => _342.bounds])) return false;
8720
8786
  return this.setSelection(_chunkQYLWG22Ncjs.modifySelection.call(void 0, sel, op, radius));
8721
8787
  }
8722
8788
  /**
@@ -8725,7 +8791,7 @@ var ImageEditorController = (_class12 = class {
8725
8791
  */
8726
8792
  async refineSelection(params, options = {}) {
8727
8793
  const sel = this.state.selection;
8728
- if (!_optionalChain([sel, 'optionalAccess', _342 => _342.bounds])) return false;
8794
+ if (!_optionalChain([sel, 'optionalAccess', _343 => _343.bounds])) return false;
8729
8795
  const pixels = (_nullishCoalesce(params.radius, () => ( 0))) > 0 ? await this.requirePixels(options) : null;
8730
8796
  return this.setSelection(_chunkX4LUGTQXcjs.refineSelection.call(void 0, pixels, sel, params));
8731
8797
  }
@@ -8747,13 +8813,17 @@ var ImageEditorController = (_class12 = class {
8747
8813
  async refineSelectionTo(params, output = "selection", options = {}) {
8748
8814
  const edits = _nullishCoalesce(options.edits, () => ( []));
8749
8815
  const refineMode = _nullishCoalesce(options.refineMode, () => ( "color"));
8750
- if (!_optionalChain([this, 'access', _343 => _343.state, 'access', _344 => _344.selection, 'optionalAccess', _345 => _345.bounds]) && !edits.length) throw new Error("Nothing is selected; select first, or pass edits that paint a selection.");
8816
+ if (!_optionalChain([this, 'access', _344 => _344.state, 'access', _345 => _345.selection, 'optionalAccess', _346 => _346.bounds]) && !edits.length) throw new Error("Nothing is selected; select first, or pass edits that paint a selection.");
8751
8817
  if (refineMode === "object" && !this.segmentation) {
8752
8818
  throw new Error("Object aware refinement needs a segmentation model (setSegmentationProvider); use refineMode color.");
8753
8819
  }
8754
8820
  const amount = Math.min(100, Math.max(0, _nullishCoalesce(options.decontaminate, () => ( 0)))) / 100;
8755
- const toLayer = output === "new-layer" || output === "new-layer-with-mask";
8756
- if (amount > 0 && !toLayer) throw new Error("Decontaminate colors writes the cleaned colours to a new layer: use output new-layer or new-layer-with-mask.");
8821
+ const toDocument = output === "new-document" || output === "new-document-with-mask";
8822
+ const toLayer = output === "new-layer" || output === "new-layer-with-mask" || toDocument;
8823
+ if (amount > 0 && !toLayer) throw new Error("Decontaminate colors writes the cleaned colours to a new layer or document: use output new-layer, new-layer-with-mask, new-document or new-document-with-mask.");
8824
+ if (toDocument && !this.documentOpener) {
8825
+ throw new Error("This editor cannot open new documents (no document opener is set); use output new-layer or new-layer-with-mask instead.");
8826
+ }
8757
8827
  let layerId;
8758
8828
  if (output !== "selection") {
8759
8829
  layerId = _nullishCoalesce(_nullishCoalesce(options.layerId, () => ( this.state.activeLayerId)), () => ( void 0));
@@ -8766,18 +8836,24 @@ var ImageEditorController = (_class12 = class {
8766
8836
  const { width, height } = this.naturalSize;
8767
8837
  const edited = _chunkX4LUGTQXcjs.applyRefineEdits.call(void 0, pixels, _nullishCoalesce(this.state.selection, () => ( null)), edits, width, height);
8768
8838
  let sel = edited.selection;
8769
- if (!_optionalChain([sel, 'optionalAccess', _346 => _346.bounds])) throw new Error("The edits leave nothing selected; paint with mode add first.");
8839
+ if (!_optionalChain([sel, 'optionalAccess', _347 => _347.bounds])) throw new Error("The edits leave nothing selected; paint with mode add first.");
8770
8840
  if (refineMode === "object") {
8771
8841
  const b = sel.bounds;
8772
8842
  const found = await this.modelObject({ rect: b }, options.signal);
8773
8843
  if (!found) throw new Error("The segmentation model found no object in the selection; use refineMode color.");
8774
8844
  const near = _chunkQYLWG22Ncjs.modifySelection.call(void 0, sel, "expand", Math.max(4, _nullishCoalesce(params.radius, () => ( 8))));
8775
8845
  const clipped = _chunkQYLWG22Ncjs.combineSelections.call(void 0, found, near, "intersect");
8776
- if (!_optionalChain([clipped, 'optionalAccess', _347 => _347.bounds])) throw new Error("The segmentation model found no object in the selection; use refineMode color.");
8846
+ if (!_optionalChain([clipped, 'optionalAccess', _348 => _348.bounds])) throw new Error("The segmentation model found no object in the selection; use refineMode color.");
8777
8847
  sel = clipped;
8778
8848
  }
8779
8849
  const refined = _chunkX4LUGTQXcjs.refineSelection.call(void 0, pixels, sel, params, edited.refineBrush);
8780
8850
  if (!refined.bounds) throw new Error("Refining left nothing selected; use a smaller shiftEdge or contrast.");
8851
+ if (toDocument) {
8852
+ const document2 = this.documentFromSelection({ layerId, withMask: output === "new-document-with-mask", selection: refined, decontaminate: amount * 100, radius: params.radius });
8853
+ const name = `${_chunkQE7D7TZRcjs.requireLayer.call(void 0, this.state.layers, layerId).layer.name || "Layer"} ${output === "new-document" ? "cutout" : "masked"}`;
8854
+ const documentId = await this.documentOpener(document2, { name, from: "select-and-mask" });
8855
+ return { output, layerId, refineMode, ...documentId ? { documentId } : {} };
8856
+ }
8781
8857
  return this.asOneStep(() => {
8782
8858
  this.setSelection(refined);
8783
8859
  if (output === "selection") return { output, refineMode };
@@ -8808,6 +8884,16 @@ var ImageEditorController = (_class12 = class {
8808
8884
  const layer = _chunkQE7D7TZRcjs.requireLayer.call(void 0, this.state.layers, id).layer;
8809
8885
  const source = _chunkQE7D7TZRcjs.requireLayer.call(void 0, this.state.layers, sourceId).layer;
8810
8886
  if (layer.type !== "pixel" || source.type !== "pixel" || !coverage.bounds) return;
8887
+ const surface = this.decontaminatedSurface(layer, source, coverage, amount, radius);
8888
+ const next = _chunkUOGKSVRQcjs.mapLayer.call(void 0, this.state.layers, id, (l) => {
8889
+ const updated = { ...l, surface };
8890
+ delete updated.source;
8891
+ return updated;
8892
+ });
8893
+ this.commitLayers(next);
8894
+ }
8895
+ /** `layer`'s surface with Decontaminate Colors applied along `coverage`'s soft edge, colours read from `source`. */
8896
+ decontaminatedSurface(layer, source, coverage, amount, radius) {
8811
8897
  const { width, height } = this.naturalSize;
8812
8898
  const pad = Math.ceil(radius * 3);
8813
8899
  const b = coverage.bounds;
@@ -8823,12 +8909,7 @@ var ImageEditorController = (_class12 = class {
8823
8909
  for (let y = 0; y < box.height; y++) cov.set(all.subarray((box.y + y) * width + box.x, (box.y + y) * width + box.x + box.width), y * box.width);
8824
8910
  const cleaned = _chunkX4LUGTQXcjs.decontaminateColors.call(void 0, original, cov, box.width, box.height, amount, radius);
8825
8911
  for (let i = 3; i < cleaned.length; i += 4) cleaned[i] = rgba[i];
8826
- const next = _chunkUOGKSVRQcjs.mapLayer.call(void 0, this.state.layers, id, (l) => {
8827
- const updated = { ...l, surface: _chunk474IQG74cjs.writeRegion.call(void 0, surface, src, cleaned) };
8828
- delete updated.source;
8829
- return updated;
8830
- });
8831
- this.commitLayers(next);
8912
+ return _chunk474IQG74cjs.writeRegion.call(void 0, surface, src, cleaned);
8832
8913
  }
8833
8914
  /**
8834
8915
  * Loads a selection from a mask image (an AI segmentation, a saved mask): a data URL / URL or
@@ -8857,7 +8938,7 @@ var ImageEditorController = (_class12 = class {
8857
8938
  let mask;
8858
8939
  if (source === "selection") {
8859
8940
  const sel = this.state.selection;
8860
- if (!_optionalChain([sel, 'optionalAccess', _348 => _348.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, or export a channel or a layer mask.");
8941
+ if (!_optionalChain([sel, 'optionalAccess', _349 => _349.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, or export a channel or a layer mask.");
8861
8942
  mask = sel;
8862
8943
  } else if ("channelId" in source) {
8863
8944
  mask = this.requireChannel(source.channelId).mask;
@@ -8881,7 +8962,7 @@ var ImageEditorController = (_class12 = class {
8881
8962
  const canvas = this.renderer.createCanvas(w, h);
8882
8963
  const ctx = canvas.getContext("2d");
8883
8964
  if (ctx) ctx.drawImage(img, 0, 0, w, h);
8884
- const data = _optionalChain([ctx, 'optionalAccess', _349 => _349.getImageData, 'optionalCall', _350 => _350(0, 0, w, h)]);
8965
+ const data = _optionalChain([ctx, 'optionalAccess', _350 => _350.getImageData, 'optionalCall', _351 => _351(0, 0, w, h)]);
8885
8966
  if (!data) throw new Error("The mask image pixels are not available (no canvas access); pass pixels.");
8886
8967
  return { width: w, height: h, data: data.data };
8887
8968
  }
@@ -8897,7 +8978,7 @@ var ImageEditorController = (_class12 = class {
8897
8978
  const provider = this.segmentation;
8898
8979
  if (!provider) {
8899
8980
  const pixels = await this.requirePixels({});
8900
- _optionalChain([options, 'access', _351 => _351.signal, 'optionalAccess', _352 => _352.throwIfAborted, 'call', _353 => _353()]);
8981
+ _optionalChain([options, 'access', _352 => _352.signal, 'optionalAccess', _353 => _353.throwIfAborted, 'call', _354 => _354()]);
8901
8982
  const { mask: selection, reason } = await this.runSelectionJob({ op: "subject", enhanceEdge: options.enhanceEdge }, pixels, options);
8902
8983
  if (selection.bounds) this.shapeCommand(selection, options);
8903
8984
  const unused = target.trim() ? ` "${target.trim()}" was not used to choose it.` : "";
@@ -8913,17 +8994,17 @@ var ImageEditorController = (_class12 = class {
8913
8994
  const decoded = await this.modelSegments({ target: description, maxSegments: options.maxSegments, signal: options.signal });
8914
8995
  const segments = decoded.map((r) => {
8915
8996
  const one = segmentsToSelection(width, height, [r]);
8916
- return { label: r.label || description, bounds: _nullishCoalesce(_optionalChain([one, 'optionalAccess', _354 => _354.bounds]), () => ( null)), ...r.score !== void 0 ? { score: r.score } : {} };
8997
+ return { label: r.label || description, bounds: _nullishCoalesce(_optionalChain([one, 'optionalAccess', _355 => _355.bounds]), () => ( null)), ...r.score !== void 0 ? { score: r.score } : {} };
8917
8998
  });
8918
8999
  const mask = segmentsToSelection(width, height, decoded);
8919
9000
  if (mask && options.beforeApply) {
8920
9001
  const outlines = decoded.flatMap((r, i) => {
8921
9002
  const rings = segmentationOutlines(r);
8922
- const b = _optionalChain([segments, 'access', _355 => _355[i], 'optionalAccess', _356 => _356.bounds]);
9003
+ const b = _optionalChain([segments, 'access', _356 => _356[i], 'optionalAccess', _357 => _357.bounds]);
8923
9004
  return rings.length ? rings : b ? [[{ x: b.x, y: b.y }, { x: b.x + b.width, y: b.y }, { x: b.x + b.width, y: b.y + b.height }, { x: b.x, y: b.y + b.height }]] : [];
8924
9005
  });
8925
9006
  await options.beforeApply(outlines);
8926
- _optionalChain([options, 'access', _357 => _357.signal, 'optionalAccess', _358 => _358.throwIfAborted, 'call', _359 => _359()]);
9007
+ _optionalChain([options, 'access', _358 => _358.signal, 'optionalAccess', _359 => _359.throwIfAborted, 'call', _360 => _360()]);
8927
9008
  }
8928
9009
  if (mask) this.shapeCommand(mask, options);
8929
9010
  return { segments: segments.filter((s) => s.bounds), method: "model" };
@@ -8956,7 +9037,7 @@ var ImageEditorController = (_class12 = class {
8956
9037
  const view = this.state.maskView;
8957
9038
  if (!view) return null;
8958
9039
  const layer = this.getLayer(view.layerId);
8959
- return _optionalChain([layer, 'optionalAccess', _360 => _360.mask]) && !layer.mask.source ? view : null;
9040
+ return _optionalChain([layer, 'optionalAccess', _361 => _361.mask]) && !layer.mask.source ? view : null;
8960
9041
  }
8961
9042
  /**
8962
9043
  * Shows a layer's mask on the canvas: `gray` alone in grey (Alt-click the mask thumbnail),
@@ -8979,7 +9060,7 @@ var ImageEditorController = (_class12 = class {
8979
9060
  if (!layer.mask) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${layer.name || id}" has no mask to show; add one with add_layer_mask.`);
8980
9061
  if (layer.mask.source) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${layer.name || id}" has a depth mask, which is computed, not painted, so it has no mask view.`);
8981
9062
  const cur = this.state.maskView;
8982
- if (_optionalChain([cur, 'optionalAccess', _361 => _361.layerId]) !== id || cur.mode !== mode) {
9063
+ if (_optionalChain([cur, 'optionalAccess', _362 => _362.layerId]) !== id || cur.mode !== mode) {
8983
9064
  this.state.maskView = { layerId: id, mode };
8984
9065
  this.notify();
8985
9066
  }
@@ -8991,7 +9072,7 @@ var ImageEditorController = (_class12 = class {
8991
9072
  return _nullishCoalesce(this.state.channels, () => ( []));
8992
9073
  }
8993
9074
  getChannel(id) {
8994
- return _nullishCoalesce(_optionalChain([this, 'access', _362 => _362.state, 'access', _363 => _363.channels, 'optionalAccess', _364 => _364.find, 'call', _365 => _365((c) => c.id === id)]), () => ( null));
9075
+ return _nullishCoalesce(_optionalChain([this, 'access', _363 => _363.state, 'access', _364 => _364.channels, 'optionalAccess', _365 => _365.find, 'call', _366 => _366((c) => c.id === id)]), () => ( null));
8995
9076
  }
8996
9077
  requireChannel(id) {
8997
9078
  const channel = this.getChannel(id);
@@ -9020,14 +9101,14 @@ var ImageEditorController = (_class12 = class {
9020
9101
  */
9021
9102
  saveSelection(options = {}) {
9022
9103
  const sel = this.state.selection;
9023
- if (!_optionalChain([sel, 'optionalAccess', _366 => _366.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, then save the selection to a channel.");
9104
+ if (!_optionalChain([sel, 'optionalAccess', _367 => _367.bounds])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Nothing is selected; select first, then save the selection to a channel.");
9024
9105
  const { width, height } = this.naturalSize;
9025
9106
  const sized = sel.width === width && sel.height === height ? sel : _chunkQYLWG22Ncjs.resizeSelection.call(void 0, sel, width, height);
9026
9107
  const channels = [...this.getChannels()];
9027
9108
  if (options.channelId !== void 0) {
9028
9109
  const existing = this.requireChannel(options.channelId);
9029
9110
  const mask = _nullishCoalesce(_chunkQYLWG22Ncjs.combineSelections.call(void 0, existing.mask.bounds ? existing.mask : null, sized, _nullishCoalesce(options.mode, () => ( "replace"))), () => ( _chunkQYLWG22Ncjs.createSelectionMask.call(void 0, width, height)));
9030
- const next = { ...existing, mask, ..._optionalChain([options, 'access', _367 => _367.name, 'optionalAccess', _368 => _368.trim, 'call', _369 => _369()]) ? { name: options.name.trim() } : {} };
9111
+ const next = { ...existing, mask, ..._optionalChain([options, 'access', _368 => _368.name, 'optionalAccess', _369 => _369.trim, 'call', _370 => _370()]) ? { name: options.name.trim() } : {} };
9031
9112
  this.setChannels(channels.map((c) => c.id === existing.id ? next : c));
9032
9113
  return next;
9033
9114
  }
@@ -9038,7 +9119,7 @@ var ImageEditorController = (_class12 = class {
9038
9119
  const channels = this.getChannels();
9039
9120
  const channel = {
9040
9121
  id: this.newChannelId(),
9041
- name: _optionalChain([name, 'optionalAccess', _370 => _370.trim, 'call', _371 => _371()]) || `Alpha ${channels.length + 1}`,
9122
+ name: _optionalChain([name, 'optionalAccess', _371 => _371.trim, 'call', _372 => _372()]) || `Alpha ${channels.length + 1}`,
9042
9123
  mask,
9043
9124
  color: DEFAULT_CHANNEL_COLOR,
9044
9125
  opacity: 0.5,
@@ -9083,7 +9164,7 @@ var ImageEditorController = (_class12 = class {
9083
9164
  /** Duplicates an alpha channel just after it (one undo step). Returns the copy. */
9084
9165
  duplicateChannel(id, name) {
9085
9166
  const channel = this.requireChannel(id);
9086
- const copy = { ...channel, id: this.newChannelId(), name: _optionalChain([name, 'optionalAccess', _372 => _372.trim, 'call', _373 => _373()]) || `${channel.name} copy` };
9167
+ const copy = { ...channel, id: this.newChannelId(), name: _optionalChain([name, 'optionalAccess', _373 => _373.trim, 'call', _374 => _374()]) || `${channel.name} copy` };
9087
9168
  const channels = [...this.getChannels()];
9088
9169
  channels.splice(channels.findIndex((c) => c.id === id) + 1, 0, copy);
9089
9170
  this.setChannels(channels);
@@ -9114,7 +9195,7 @@ var ImageEditorController = (_class12 = class {
9114
9195
  quickMaskSurface() {
9115
9196
  const { width, height } = this.naturalSize;
9116
9197
  const sel = this.state.selection;
9117
- if (!_optionalChain([sel, 'optionalAccess', _374 => _374.bounds])) return _chunk474IQG74cjs.emptySurface.call(void 0, 1, 0);
9198
+ if (!_optionalChain([sel, 'optionalAccess', _375 => _375.bounds])) return _chunk474IQG74cjs.emptySurface.call(void 0, 1, 0);
9118
9199
  return (sel.width === width && sel.height === height ? sel : _chunkQYLWG22Ncjs.resizeSelection.call(void 0, sel, width, height)).surface;
9119
9200
  }
9120
9201
  /** The selection a painted Quick Mask surface stands for (it shares the surface's tiles). */
@@ -9135,7 +9216,7 @@ var ImageEditorController = (_class12 = class {
9135
9216
  */
9136
9217
  applySelectionAsLayerMask(layerId, props = {}) {
9137
9218
  const sel = this.state.selection;
9138
- if (!_optionalChain([sel, 'optionalAccess', _375 => _375.bounds]) || !this.getAdjustmentLayer(layerId)) return false;
9219
+ if (!_optionalChain([sel, 'optionalAccess', _376 => _376.bounds]) || !this.getAdjustmentLayer(layerId)) return false;
9139
9220
  return this.setLayerMask(layerId, this.maskFromSelection(sel, props));
9140
9221
  }
9141
9222
  setLayerMask(layerId, mask, commitToHistory = true) {
@@ -9175,7 +9256,7 @@ var ImageEditorController = (_class12 = class {
9175
9256
  /** A layer's painted mask over the canvas as a selection mask; null without one (or for a depth mask). */
9176
9257
  layerMaskCoverage(layerId) {
9177
9258
  const layer = this.getLayer(layerId);
9178
- if (!_optionalChain([layer, 'optionalAccess', _376 => _376.mask]) || layer.mask.source) return null;
9259
+ if (!_optionalChain([layer, 'optionalAccess', _377 => _377.mask]) || layer.mask.source) return null;
9179
9260
  const { width, height } = this.naturalSize;
9180
9261
  const ox = layer.type === "pixel" ? layer.offset.x : 0;
9181
9262
  const oy = layer.type === "pixel" ? layer.offset.y : 0;
@@ -9210,7 +9291,7 @@ var ImageEditorController = (_class12 = class {
9210
9291
  this.state.layers = _chunkUOGKSVRQcjs.mapLayer.call(void 0, this.state.layers, target.id, (l) => {
9211
9292
  const next = { ...l };
9212
9293
  if (_chunkQE7D7TZRcjs.isDefaultDepthMask.call(void 0, merged)) {
9213
- if (_optionalChain([next, 'access', _377 => _377.mask, 'optionalAccess', _378 => _378.source])) delete next.mask;
9294
+ if (_optionalChain([next, 'access', _378 => _378.mask, 'optionalAccess', _379 => _379.source])) delete next.mask;
9214
9295
  } else next.mask = _chunkQE7D7TZRcjs.depthRasterMask.call(void 0, merged);
9215
9296
  return next;
9216
9297
  });
@@ -9220,7 +9301,7 @@ var ImageEditorController = (_class12 = class {
9220
9301
  resetDepthMask() {
9221
9302
  this.recordHistory();
9222
9303
  const target = this.developLayer();
9223
- if (_optionalChain([target, 'optionalAccess', _379 => _379.mask, 'optionalAccess', _380 => _380.source])) {
9304
+ if (_optionalChain([target, 'optionalAccess', _380 => _380.mask, 'optionalAccess', _381 => _381.source])) {
9224
9305
  this.state.layers = _chunkUOGKSVRQcjs.mapLayer.call(void 0, this.state.layers, target.id, (l) => {
9225
9306
  const next = { ...l };
9226
9307
  delete next.mask;
@@ -9232,7 +9313,7 @@ var ImageEditorController = (_class12 = class {
9232
9313
  // --- Annotations & Layers ---
9233
9314
  /** The layer showing annotation `id`: an annotation layer, or a shape layer migrated from it. */
9234
9315
  annotationLayer(id) {
9235
- return _chunkUOGKSVRQcjs.flattenLayers.call(void 0, this.state.layers).find((l) => (l.type === "annotation" || l.type === "shape" || l.type === "type") && _optionalChain([_chunkQE7D7TZRcjs.annotationOfLayer.call(void 0, l), 'optionalAccess', _381 => _381.id]) === id);
9316
+ return _chunkUOGKSVRQcjs.flattenLayers.call(void 0, this.state.layers).find((l) => (l.type === "annotation" || l.type === "shape" || l.type === "type") && _optionalChain([_chunkQE7D7TZRcjs.annotationOfLayer.call(void 0, l), 'optionalAccess', _382 => _382.id]) === id);
9236
9317
  }
9237
9318
  /** What migrating an annotation needs: the canvas size, patterns and the text shaper. */
9238
9319
  annotationEnv() {
@@ -9250,7 +9331,7 @@ var ImageEditorController = (_class12 = class {
9250
9331
  const fullAnnotation = { ...annotation, id };
9251
9332
  const layer = _chunkQE7D7TZRcjs.annotationLayerFor.call(void 0, fullAnnotation, this.annotationEnv());
9252
9333
  const loc = placement.aboveId ? _chunkUOGKSVRQcjs.findLayer.call(void 0, this.state.layers, placement.aboveId) : null;
9253
- this.state.layers = loc ? _chunkUOGKSVRQcjs.insertLayer.call(void 0, this.state.layers, layer, _nullishCoalesce(_optionalChain([loc, 'access', _382 => _382.parent, 'optionalAccess', _383 => _383.id]), () => ( null)), loc.index + 1) : _chunkUOGKSVRQcjs.insertLayer.call(void 0, this.state.layers, layer, null);
9334
+ this.state.layers = loc ? _chunkUOGKSVRQcjs.insertLayer.call(void 0, this.state.layers, layer, _nullishCoalesce(_optionalChain([loc, 'access', _383 => _383.parent, 'optionalAccess', _384 => _384.id]), () => ( null)), loc.index + 1) : _chunkUOGKSVRQcjs.insertLayer.call(void 0, this.state.layers, layer, null);
9254
9335
  this.state.selectedAnnotationId = id;
9255
9336
  this.notify();
9256
9337
  return id;
@@ -9330,7 +9411,7 @@ var ImageEditorController = (_class12 = class {
9330
9411
  this.notify();
9331
9412
  }
9332
9413
  // --- Rendering & Export ---
9333
- __init101() {this.blankSource = null}
9414
+ __init102() {this.blankSource = null}
9334
9415
  /**
9335
9416
  * What the renderer draws from: the source image, or, for a document without one (an opened
9336
9417
  * PSD, a v3 document loaded on its own), a transparent canvas of the document size, since every
@@ -9373,7 +9454,7 @@ var ImageEditorController = (_class12 = class {
9373
9454
  await this.renderer.renderToCanvas(targetCanvas, source, this.state, {
9374
9455
  ...options,
9375
9456
  // The clone source follows the brush cursor (both editors pass it).
9376
- cloneSourceMarker: _optionalChain([options, 'optionalAccess', _384 => _384.cloneSourceMarker]) !== void 0 ? options.cloneSourceMarker : _optionalChain([options, 'optionalAccess', _385 => _385.brushCursor]) ? this.cloneSourceMarker(options.brushCursor) : null,
9457
+ cloneSourceMarker: _optionalChain([options, 'optionalAccess', _385 => _385.cloneSourceMarker]) !== void 0 ? options.cloneSourceMarker : _optionalChain([options, 'optionalAccess', _386 => _386.brushCursor]) ? this.cloneSourceMarker(options.brushCursor) : null,
9377
9458
  dirty: dirty === "all" ? void 0 : dirty,
9378
9459
  checkpointLayerId: this.state.activeLayerId
9379
9460
  });
@@ -9386,7 +9467,7 @@ var ImageEditorController = (_class12 = class {
9386
9467
  return this.renderer.createCanvas(1, 1);
9387
9468
  }
9388
9469
  this.syncViews();
9389
- if (_optionalChain([options, 'optionalAccess', _386 => _386.layerIds])) {
9470
+ if (_optionalChain([options, 'optionalAccess', _387 => _387.layerIds])) {
9390
9471
  const keep = new Set(options.layerIds);
9391
9472
  const layers = _chunkUOGKSVRQcjs.flattenLayers.call(void 0, this.state.layers).filter((l) => keep.has(l.id));
9392
9473
  return this.renderer.renderExport(source, { ...this.state, layers }, options);
@@ -9540,7 +9621,7 @@ var ImageEditorController = (_class12 = class {
9540
9621
  let px2 = await this.decodeImage(newDataUrl);
9541
9622
  if (px2.width !== width || px2.height !== height) px2 = resizePixels(px2, width, height);
9542
9623
  const data = new Uint8ClampedArray(px2.data);
9543
- const sel = _optionalChain([this, 'access', _387 => _387.state, 'access', _388 => _388.selection, 'optionalAccess', _389 => _389.bounds]) ? this.state.selection : null;
9624
+ const sel = _optionalChain([this, 'access', _388 => _388.state, 'access', _389 => _389.selection, 'optionalAccess', _390 => _390.bounds]) ? this.state.selection : null;
9544
9625
  if (sel) for (let p = 0, i = 3; p < width * height; p++, i += 4) data[i] = Math.round(data[i] * sel.data[p] / 255);
9545
9626
  return this.addPixelLayer({ name: "Inpaint", pixels: { width, height, data } });
9546
9627
  }
@@ -9587,7 +9668,7 @@ var ImageEditorController = (_class12 = class {
9587
9668
  }
9588
9669
  /** Font families the shaper offers (generic families at least). */
9589
9670
  listFonts() {
9590
- return _nullishCoalesce(_optionalChain([this, 'access', _390 => _390.getTextShaper, 'call', _391 => _391(), 'optionalAccess', _392 => _392.families, 'optionalCall', _393 => _393()]), () => ( ["sans-serif", "serif", "monospace"]));
9671
+ return _nullishCoalesce(_optionalChain([this, 'access', _391 => _391.getTextShaper, 'call', _392 => _392(), 'optionalAccess', _393 => _393.families, 'optionalCall', _394 => _394()]), () => ( ["sans-serif", "serif", "monospace"]));
9591
9672
  }
9592
9673
  typeInfo(id) {
9593
9674
  const layer = _chunkQE7D7TZRcjs.requireTypeLayer.call(void 0, this.state.layers, id);
@@ -9661,8 +9742,8 @@ var ImageEditorController = (_class12 = class {
9661
9742
  const layer = this.layoutTypeLayer({ ...init, text, orientation: vertical ? "vertical" : "horizontal" });
9662
9743
  const { width, height } = this.naturalSize;
9663
9744
  const b = _chunk474IQG74cjs.contentBounds.call(void 0, layer.surface);
9664
- const x0 = Math.max(0, _nullishCoalesce(_optionalChain([b, 'optionalAccess', _394 => _394.x]), () => ( 0)));
9665
- const y0 = Math.max(0, _nullishCoalesce(_optionalChain([b, 'optionalAccess', _395 => _395.y]), () => ( 0)));
9745
+ const x0 = Math.max(0, _nullishCoalesce(_optionalChain([b, 'optionalAccess', _395 => _395.x]), () => ( 0)));
9746
+ const y0 = Math.max(0, _nullishCoalesce(_optionalChain([b, 'optionalAccess', _396 => _396.y]), () => ( 0)));
9666
9747
  const x1 = Math.min(width, b ? b.x + b.width : 0);
9667
9748
  const y1 = Math.min(height, b ? b.y + b.height : 0);
9668
9749
  let mask;
@@ -9839,7 +9920,7 @@ var ImageEditorController = (_class12 = class {
9839
9920
  if (colors.size > 1) warnings.push("The text had several colours; the shape takes the first one.");
9840
9921
  const missing = _chunkQAUIZPYIcjs.layoutText.call(void 0, layer, shaper).missingFonts;
9841
9922
  if (missing.length) warnings.push(`Missing fonts were drawn with a fallback: ${missing.join(", ")}.`);
9842
- const first = _nullishCoalesce(_optionalChain([layer, 'access', _396 => _396.runs, 'access', _397 => _397.find, 'call', _398 => _398((r) => r.length > 0), 'optionalAccess', _399 => _399.style]), () => ( _chunkQAUIZPYIcjs.DEFAULT_TEXT_STYLE));
9923
+ const first = _nullishCoalesce(_optionalChain([layer, 'access', _397 => _397.runs, 'access', _398 => _398.find, 'call', _399 => _399((r) => r.length > 0), 'optionalAccess', _400 => _400.style]), () => ( _chunkQAUIZPYIcjs.DEFAULT_TEXT_STYLE));
9843
9924
  const fill = first.opacity !== void 0 && first.opacity !== 1 ? { type: "color", color: first.color, opacity: first.opacity } : { type: "color", color: first.color };
9844
9925
  const shape = _chunkQE7D7TZRcjs.createShapeLayer.call(void 0, { components: [{ op: "combine", subpaths }], fill, stroke: null, name: layer.name }, this.shapeEnv(), layer.id);
9845
9926
  const keep = { visible: layer.visible, opacity: layer.opacity, blend: layer.blend };
@@ -9872,7 +9953,7 @@ var ImageEditorController = (_class12 = class {
9872
9953
  // --- Shape layers ---
9873
9954
  /** What shape rendering needs: the canvas size and the document's patterns. */
9874
9955
  shapeEnv() {
9875
- return { ...this.naturalSize, pattern: (id) => _nullishCoalesce(_optionalChain([this, 'access', _400 => _400.state, 'access', _401 => _401.patterns, 'optionalAccess', _402 => _402.find, 'call', _403 => _403((p) => p.id === id)]), () => ( null)) };
9956
+ return { ...this.naturalSize, pattern: (id) => _nullishCoalesce(_optionalChain([this, 'access', _401 => _401.state, 'access', _402 => _402.patterns, 'optionalAccess', _403 => _403.find, 'call', _404 => _404((p) => p.id === id)]), () => ( null)) };
9876
9957
  }
9877
9958
  /** One component from tool or UI input (validated). */
9878
9959
  componentFrom(spec, path) {
@@ -9915,9 +9996,9 @@ var ImageEditorController = (_class12 = class {
9915
9996
  * open path) and stroked with `stroke`. Goes above the active layer unless placed. Returns its id.
9916
9997
  */
9917
9998
  addShapeLayer(init) {
9918
- const specs = _optionalChain([init, 'access', _404 => _404.components, 'optionalAccess', _405 => _405.length]) ? init.components : [init];
9919
- if (_optionalChain([init, 'access', _406 => _406.components, 'optionalAccess', _407 => _407.length]) && (init.shape !== void 0 || init.subpaths !== void 0)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Give components, or shape / subpaths, not both.");
9920
- const components = specs.map((c, i) => this.componentFrom(c, _optionalChain([init, 'access', _408 => _408.components, 'optionalAccess', _409 => _409.length]) ? `components[${i}].` : ""));
9999
+ const specs = _optionalChain([init, 'access', _405 => _405.components, 'optionalAccess', _406 => _406.length]) ? init.components : [init];
10000
+ if (_optionalChain([init, 'access', _407 => _407.components, 'optionalAccess', _408 => _408.length]) && (init.shape !== void 0 || init.subpaths !== void 0)) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)("Give components, or shape / subpaths, not both.");
10001
+ const components = specs.map((c, i) => this.componentFrom(c, _optionalChain([init, 'access', _409 => _409.components, 'optionalAccess', _410 => _410.length]) ? `components[${i}].` : ""));
9921
10002
  const stroke = init.stroke ? _chunkQE7D7TZRcjs.normalizeShapeStroke.call(void 0, init.stroke, "stroke") : null;
9922
10003
  const openOnly = components.every((c) => !c.live && c.subpaths.every((sp) => !sp.closed));
9923
10004
  const fill = init.fill === void 0 ? stroke && openOnly ? null : _chunkQE7D7TZRcjs.normalizeShapePaint.call(void 0, this.state.paint.foreground, "fill") : init.fill === null ? null : _chunkQE7D7TZRcjs.normalizeShapePaint.call(void 0, init.fill, "fill");
@@ -10028,7 +10109,7 @@ var ImageEditorController = (_class12 = class {
10028
10109
  if (layer.locks) next.locks = layer.locks;
10029
10110
  if (this.state.selectedAnnotationId === layer.annotation.id) this.state.selectedAnnotationId = null;
10030
10111
  } else if (layer.type === "pixel") {
10031
- if (!_optionalChain([layer, 'access', _410 => _410.filters, 'optionalAccess', _411 => _411.length])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${layer.name || id}" is already pixels with no filters to bake.`);
10112
+ if (!_optionalChain([layer, 'access', _411 => _411.filters, 'optionalAccess', _412 => _412.length])) throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Layer "${layer.name || id}" is already pixels with no filters to bake.`);
10032
10113
  _chunkQE7D7TZRcjs.requireUnlocked.call(void 0, layer, "pixels", "rasterize it");
10033
10114
  const spatial = layer.filters.some((f) => f.enabled && f.kind === "blur");
10034
10115
  const content = { ...layer, visible: true, opacity: 1, blend: "normal" };
@@ -10047,7 +10128,7 @@ var ImageEditorController = (_class12 = class {
10047
10128
  return this.rasterizeSmartObject(id);
10048
10129
  } else if (layer.type === "shape" || layer.type === "type") {
10049
10130
  next = layer.type === "shape" ? _chunkQE7D7TZRcjs.shapeAsPixelLayer.call(void 0, layer) : _chunkQE7D7TZRcjs.typeAsPixelLayer.call(void 0, layer);
10050
- if (this.state.selectedAnnotationId && this.state.selectedAnnotationId === _optionalChain([layer, 'access', _412 => _412.annotation, 'optionalAccess', _413 => _413.id])) this.state.selectedAnnotationId = null;
10131
+ if (this.state.selectedAnnotationId && this.state.selectedAnnotationId === _optionalChain([layer, 'access', _413 => _413.annotation, 'optionalAccess', _414 => _414.id])) this.state.selectedAnnotationId = null;
10051
10132
  } else {
10052
10133
  throw new (0, _chunkQE7D7TZRcjs.LayerOperationError)(`Only shape, type and annotation layers, smart objects and pixel layers with filters rasterize; "${layer.name || id}" is a ${layer.type} layer. Merge it down or flatten instead.`);
10053
10134
  }
@@ -10061,8 +10142,8 @@ var ImageEditorController = (_class12 = class {
10061
10142
  const doc = this.state.colorProfile;
10062
10143
  const p = resolveProfile(doc);
10063
10144
  const m = this.state.colorMode;
10064
- const out = { name: _nullishCoalesce(_optionalChain([doc, 'optionalAccess', _414 => _414.name]), () => ( p.description)), builtin: doc ? _nullishCoalesce(doc.builtin, () => ( null)) : "srgb", colorSpace: p.colorSpace, srgb: isSrgb(doc), mode: _nullishCoalesce(_optionalChain([m, 'optionalAccess', _415 => _415.mode]), () => ( "rgb")) };
10065
- if (_optionalChain([m, 'optionalAccess', _416 => _416.mode]) === "cmyk") out.cmykProfile = { name: m.profile.name, builtin: _nullishCoalesce(m.profile.builtin, () => ( null)), intent: m.intent };
10145
+ const out = { name: _nullishCoalesce(_optionalChain([doc, 'optionalAccess', _415 => _415.name]), () => ( p.description)), builtin: doc ? _nullishCoalesce(doc.builtin, () => ( null)) : "srgb", colorSpace: p.colorSpace, srgb: isSrgb(doc), mode: _nullishCoalesce(_optionalChain([m, 'optionalAccess', _416 => _416.mode]), () => ( "rgb")) };
10146
+ if (_optionalChain([m, 'optionalAccess', _417 => _417.mode]) === "cmyk") out.cmykProfile = { name: m.profile.name, builtin: _nullishCoalesce(m.profile.builtin, () => ( null)), intent: m.intent };
10066
10147
  return out;
10067
10148
  }
10068
10149
  /**
@@ -10152,7 +10233,7 @@ var ImageEditorController = (_class12 = class {
10152
10233
  const textEnv = this.textEnv();
10153
10234
  const walk = (layers) => layers.map((l) => {
10154
10235
  let next2 = l;
10155
- if (_optionalChain([l, 'access', _417 => _417.effects, 'optionalAccess', _418 => _418.items, 'access', _419 => _419.length])) next2 = { ...next2, effects: convertColorFields(l.effects, hex) };
10236
+ if (_optionalChain([l, 'access', _418 => _418.effects, 'optionalAccess', _419 => _419.items, 'access', _420 => _420.length])) next2 = { ...next2, effects: convertColorFields(l.effects, hex) };
10156
10237
  if (l.type === "group") {
10157
10238
  if (next2 !== l) converted.push(l.id);
10158
10239
  return { ...next2, children: walk(l.children) };
@@ -10336,8 +10417,8 @@ var ImageEditorController = (_class12 = class {
10336
10417
  else delete s.bitDepth;
10337
10418
  delete s.colorProfile;
10338
10419
  delete s.colorMode;
10339
- if (_optionalChain([result, 'access', _420 => _420.sourceMode, 'optionalAccess', _421 => _421.mode]) === "cmyk") s.colorMode = { mode: "cmyk", profile: result.sourceMode.profile, intent: "relative" };
10340
- else if (_optionalChain([result, 'access', _422 => _422.sourceMode, 'optionalAccess', _423 => _423.mode]) === "lab") s.colorMode = { mode: "lab" };
10420
+ if (_optionalChain([result, 'access', _421 => _421.sourceMode, 'optionalAccess', _422 => _422.mode]) === "cmyk") s.colorMode = { mode: "cmyk", profile: result.sourceMode.profile, intent: "relative" };
10421
+ else if (_optionalChain([result, 'access', _423 => _423.sourceMode, 'optionalAccess', _424 => _424.mode]) === "lab") s.colorMode = { mode: "lab" };
10341
10422
  else if (result.iccProfile) {
10342
10423
  try {
10343
10424
  const doc = documentProfile(result.iccProfile);
@@ -10401,7 +10482,7 @@ var ImageEditorController = (_class12 = class {
10401
10482
  const compositor = new (0, _chunkQE7D7TZRcjs.LayerCompositor)();
10402
10483
  const bakeMask = (layer) => {
10403
10484
  const mask = layer.mask;
10404
- if (!_optionalChain([mask, 'optionalAccess', _424 => _424.source])) return mask;
10485
+ if (!_optionalChain([mask, 'optionalAccess', _425 => _425.source])) return mask;
10405
10486
  add2("Parametric (depth) masks were baked into pixel masks", layer.name);
10406
10487
  const plain3 = { ...layer, mask: { ...mask, density: 1, feather: 0, enabled: true } };
10407
10488
  const ox = layer.type === "pixel" ? layer.offset.x : 0;
@@ -10418,7 +10499,7 @@ var ImageEditorController = (_class12 = class {
10418
10499
  };
10419
10500
  const prepare = async (layer) => {
10420
10501
  const p = await prepareLayer(layer);
10421
- if (_optionalChain([p, 'optionalAccess', _425 => _425.blend]) === "pigment") add2("The Pigment blend mode has no PSD equivalent and was written as Normal", layer.name);
10502
+ if (_optionalChain([p, 'optionalAccess', _426 => _426.blend]) === "pigment") add2("The Pigment blend mode has no PSD equivalent and was written as Normal", layer.name);
10422
10503
  return p;
10423
10504
  };
10424
10505
  const prepareLayer = async (layer) => {
@@ -10461,7 +10542,7 @@ var ImageEditorController = (_class12 = class {
10461
10542
  return out2;
10462
10543
  }
10463
10544
  if (layer.type === "shape" || layer.type === "type") {
10464
- if (layer.type === "type" && _optionalChain([layer, 'access', _426 => _426.missingFonts, 'optionalAccess', _427 => _427.length])) add2(`Type layers drawn with a fallback for missing fonts (${layer.missingFonts.join(", ")}) keep the font names, so Photoshop may draw them differently`, layer.name);
10545
+ if (layer.type === "type" && _optionalChain([layer, 'access', _427 => _427.missingFonts, 'optionalAccess', _428 => _428.length])) add2(`Type layers drawn with a fallback for missing fonts (${layer.missingFonts.join(", ")}) keep the font names, so Photoshop may draw them differently`, layer.name);
10465
10546
  const out2 = { ...layer };
10466
10547
  const mask2 = bakeMask(layer);
10467
10548
  if (mask2) out2.mask = mask2;
@@ -10480,7 +10561,7 @@ var ImageEditorController = (_class12 = class {
10480
10561
  out.surface = this.surfaceOf(layer);
10481
10562
  delete out.source;
10482
10563
  }
10483
- const active = _nullishCoalesce(_optionalChain([layer, 'access', _428 => _428.filters, 'optionalAccess', _429 => _429.filter, 'call', _430 => _430(_chunkQE7D7TZRcjs.isActiveFilter)]), () => ( []));
10564
+ const active = _nullishCoalesce(_optionalChain([layer, 'access', _429 => _429.filters, 'optionalAccess', _430 => _430.filter, 'call', _431 => _431(_chunkQE7D7TZRcjs.isActiveFilter)]), () => ( []));
10484
10565
  if (active.length) {
10485
10566
  add2("Layer filters (develop, blur) were baked into the pixels", layer.name);
10486
10567
  const content = { ...out, visible: true, opacity: 1, blend: "normal" };
@@ -10491,7 +10572,7 @@ var ImageEditorController = (_class12 = class {
10491
10572
  const data = compositor.composite([content], canvas, sources);
10492
10573
  out = { ...out, surface: _chunk474IQG74cjs.surfaceFromPixels.call(void 0, { width, height, data }, 4, -layer.offset.x, -layer.offset.y) };
10493
10574
  }
10494
- if (_optionalChain([layer, 'access', _431 => _431.filters, 'optionalAccess', _432 => _432.some, 'call', _433 => _433((f) => !f.enabled)])) add2("Disabled layer filters were left out", layer.name);
10575
+ if (_optionalChain([layer, 'access', _432 => _432.filters, 'optionalAccess', _433 => _433.some, 'call', _434 => _434((f) => !f.enabled)])) add2("Disabled layer filters were left out", layer.name);
10495
10576
  delete out.filters;
10496
10577
  const mask = bakeMask(layer);
10497
10578
  if (mask) out.mask = mask;
@@ -10555,7 +10636,7 @@ var ImageEditorController = (_class12 = class {
10555
10636
  );
10556
10637
  }
10557
10638
  layers = resizeLegacyMasks(layers, prev, next.dimensions);
10558
- const env = { ...next.dimensions, pattern: (pid) => _nullishCoalesce(_optionalChain([this, 'access', _434 => _434.state, 'access', _435 => _435.patterns, 'optionalAccess', _436 => _436.find, 'call', _437 => _437((p) => p.id === pid)]), () => ( null)) };
10639
+ const env = { ...next.dimensions, pattern: (pid) => _nullishCoalesce(_optionalChain([this, 'access', _435 => _435.state, 'access', _436 => _436.patterns, 'optionalAccess', _437 => _437.find, 'call', _438 => _438((p) => p.id === pid)]), () => ( null)) };
10559
10640
  for (const l of _chunkUOGKSVRQcjs.flattenLayers.call(void 0, layers)) {
10560
10641
  if (l.type === "annotation") {
10561
10642
  layers = _chunkUOGKSVRQcjs.mapLayer.call(void 0, layers, l.id, () => ({ ...l, annotation: scaleAnnotation(l.annotation, sx, sy) }));
@@ -10564,7 +10645,7 @@ var ImageEditorController = (_class12 = class {
10564
10645
  const scaled = a ? scaleAnnotation(a, sx, sy) : null;
10565
10646
  const fromAnnotation = scaled ? _chunkQE7D7TZRcjs.shapeFromAnnotation.call(void 0, scaled) : null;
10566
10647
  const m = [sx, 0, 0, sy, 0, 0];
10567
- const components = _nullishCoalesce(_optionalChain([fromAnnotation, 'optionalAccess', _438 => _438.components]), () => ( _chunkQE7D7TZRcjs.transformShapeComponents.call(void 0, l.components, (p) => ({ x: p.x * sx, y: p.y * sy }), m)));
10648
+ const components = _nullishCoalesce(_optionalChain([fromAnnotation, 'optionalAccess', _439 => _439.components]), () => ( _chunkQE7D7TZRcjs.transformShapeComponents.call(void 0, l.components, (p) => ({ x: p.x * sx, y: p.y * sy }), m)));
10568
10649
  const moved = { ...l, components, ...fromAnnotation ? { fill: fromAnnotation.fill, stroke: fromAnnotation.stroke } : {} };
10569
10650
  if (scaled && fromAnnotation) moved.annotation = scaled;
10570
10651
  else delete moved.annotation;
@@ -10582,7 +10663,7 @@ var ImageEditorController = (_class12 = class {
10582
10663
  this.notify();
10583
10664
  }
10584
10665
  toJSON(options) {
10585
- const root = _optionalChain([this, 'access', _439 => _439.contentsStack, 'access', _440 => _440[0], 'optionalAccess', _441 => _441.saved]);
10666
+ const root = _optionalChain([this, 'access', _440 => _440.contentsStack, 'access', _441 => _441[0], 'optionalAccess', _442 => _442.saved]);
10586
10667
  const current = this.state;
10587
10668
  const element = this.imageElement;
10588
10669
  if (root) {
@@ -10593,8 +10674,8 @@ var ImageEditorController = (_class12 = class {
10593
10674
  let out;
10594
10675
  try {
10595
10676
  out = this.serializeState();
10596
- if (_optionalChain([this, 'access', _442 => _442.state, 'access', _443 => _443.selection, 'optionalAccess', _444 => _444.bounds])) out.selection = _chunkQYLWG22Ncjs.serializeSelection.call(void 0, this.state.selection);
10597
- if (_optionalChain([this, 'access', _445 => _445.state, 'access', _446 => _446.channels, 'optionalAccess', _447 => _447.length])) out.channels = serializeChannels(this.state.channels);
10677
+ if (_optionalChain([this, 'access', _443 => _443.state, 'access', _444 => _444.selection, 'optionalAccess', _445 => _445.bounds])) out.selection = _chunkQYLWG22Ncjs.serializeSelection.call(void 0, this.state.selection);
10678
+ if (_optionalChain([this, 'access', _446 => _446.state, 'access', _447 => _447.channels, 'optionalAccess', _448 => _448.length])) out.channels = serializeChannels(this.state.channels);
10598
10679
  } finally {
10599
10680
  if (root) {
10600
10681
  this.state = current;
@@ -10643,7 +10724,7 @@ var ImageEditorController = (_class12 = class {
10643
10724
  this.notify();
10644
10725
  }
10645
10726
  /** Problems found by the last `loadJSON` / `initialState` of a v3 document (unreadable layers or assets). */
10646
- __init102() {this.lastLoadProblems = []}
10727
+ __init103() {this.lastLoadProblems = []}
10647
10728
  applyStored(raw) {
10648
10729
  const s = this.state;
10649
10730
  const data = migrateSerializedImageEditorState(raw);
@@ -10708,10 +10789,10 @@ var ImageEditorController = (_class12 = class {
10708
10789
  serializeState() {
10709
10790
  const { width, height } = this.naturalSize;
10710
10791
  const view = _chunkQE7D7TZRcjs.legacyView.call(void 0, this.stack(), width, height, null);
10711
- if (view.exact && !this.state.globalLight && !_optionalChain([this, 'access', _448 => _448.state, 'access', _449 => _449.patterns, 'optionalAccess', _450 => _450.length]) && this.bitDepth === 8 && !this.state.colorProfile && !this.state.colorMode) {
10792
+ if (view.exact && !this.state.globalLight && !_optionalChain([this, 'access', _449 => _449.state, 'access', _450 => _450.patterns, 'optionalAccess', _451 => _451.length]) && this.bitDepth === 8 && !this.state.colorProfile && !this.state.colorMode) {
10712
10793
  return {
10713
10794
  // States without adjustment layers keep schema 1, so they round-trip unchanged.
10714
- version: _optionalChain([view, 'access', _451 => _451.adjustments, 'access', _452 => _452.layers, 'optionalAccess', _453 => _453.length]) ? 2 : 1,
10795
+ version: _optionalChain([view, 'access', _452 => _452.adjustments, 'access', _453 => _453.layers, 'optionalAccess', _454 => _454.length]) ? 2 : 1,
10715
10796
  crop: this.state.crop ? { ...this.state.crop } : null,
10716
10797
  transform: { ...this.state.transform },
10717
10798
  adjustments: serializeAdjustments(view.adjustments),
@@ -10736,7 +10817,7 @@ var ImageEditorController = (_class12 = class {
10736
10817
  };
10737
10818
  if (this.state.legacyOutputBlur !== void 0) out.legacyOutputBlur = this.state.legacyOutputBlur;
10738
10819
  if (this.state.globalLight) out.globalLight = { ...this.state.globalLight };
10739
- if (_optionalChain([this, 'access', _454 => _454.state, 'access', _455 => _455.patterns, 'optionalAccess', _456 => _456.length])) out.patterns = _chunkQE7D7TZRcjs.serializePatterns.call(void 0, this.state.patterns);
10820
+ if (_optionalChain([this, 'access', _455 => _455.state, 'access', _456 => _456.patterns, 'optionalAccess', _457 => _457.length])) out.patterns = _chunkQE7D7TZRcjs.serializePatterns.call(void 0, this.state.patterns);
10740
10821
  if (smartContents) out.smartContents = smartContents;
10741
10822
  if (this.state.bitDepth === 16 || this.state.bitDepth === 32) out.bitDepth = this.state.bitDepth;
10742
10823
  if (this.state.colorProfile) out.colorProfile = serializeColorProfile(this.state.colorProfile);
@@ -10746,7 +10827,7 @@ var ImageEditorController = (_class12 = class {
10746
10827
  }, _class12);
10747
10828
  function serializeAdjustments(adjustments) {
10748
10829
  const out = { ...adjustments };
10749
- if (_optionalChain([out, 'access', _457 => _457.layers, 'optionalAccess', _458 => _458.length])) out.layers = JSON.parse(JSON.stringify(out.layers));
10830
+ if (_optionalChain([out, 'access', _458 => _458.layers, 'optionalAccess', _459 => _459.length])) out.layers = JSON.parse(JSON.stringify(out.layers));
10750
10831
  else delete out.layers;
10751
10832
  if (_chunkQE7D7TZRcjs.normalizeProcessVersion.call(void 0, out.process) === _chunkQE7D7TZRcjs.LEGACY_PROCESS_VERSION) {
10752
10833
  delete out.process;
@@ -10782,11 +10863,11 @@ function withDevelop(layer, partial) {
10782
10863
  return { ...layer, filters };
10783
10864
  }
10784
10865
  function withBlur(layer, radius) {
10785
- const existing = _optionalChain([layer, 'access', _459 => _459.filters, 'optionalAccess', _460 => _460.find, 'call', _461 => _461((f) => f.kind === "blur")]);
10866
+ const existing = _optionalChain([layer, 'access', _460 => _460.filters, 'optionalAccess', _461 => _461.find, 'call', _462 => _462((f) => f.kind === "blur")]);
10786
10867
  const filters = (_nullishCoalesce(layer.filters, () => ( []))).filter((f) => f.kind !== "blur");
10787
10868
  if (radius > 0) {
10788
10869
  filters.push({
10789
- id: _nullishCoalesce(_optionalChain([existing, 'optionalAccess', _462 => _462.id]), () => ( (layer.source === "document" ? _chunkQE7D7TZRcjs.BLUR_FILTER_ID : _chunkQE7D7TZRcjs.newLayerId.call(void 0, "flt")))),
10870
+ id: _nullishCoalesce(_optionalChain([existing, 'optionalAccess', _463 => _463.id]), () => ( (layer.source === "document" ? _chunkQE7D7TZRcjs.BLUR_FILTER_ID : _chunkQE7D7TZRcjs.newLayerId.call(void 0, "flt")))),
10790
10871
  kind: "blur",
10791
10872
  enabled: true,
10792
10873
  radius
@@ -10882,7 +10963,7 @@ function collectStateTiles(layers, into) {
10882
10963
  if (l.type === "shape" || l.type === "type") _chunk474IQG74cjs.collectTiles.call(void 0, l.surface, into);
10883
10964
  if (l.type === "smart") {
10884
10965
  _chunk474IQG74cjs.collectTiles.call(void 0, l.surface, into);
10885
- if (_optionalChain([l, 'access', _463 => _463.smartFilters, 'optionalAccess', _464 => _464.mask])) _chunk474IQG74cjs.collectTiles.call(void 0, l.smartFilters.mask.surface, into);
10966
+ if (_optionalChain([l, 'access', _464 => _464.smartFilters, 'optionalAccess', _465 => _465.mask])) _chunk474IQG74cjs.collectTiles.call(void 0, l.smartFilters.mask.surface, into);
10886
10967
  if (l.contents.raster) _chunk474IQG74cjs.collectTiles.call(void 0, l.contents.raster, into);
10887
10968
  if (l.contents.document) collectStateTiles(l.contents.document.layers, into);
10888
10969
  }
@@ -10914,7 +10995,7 @@ function pixelsOnly(layers) {
10914
10995
  for (const l of layers) {
10915
10996
  if (l.type === "adjustment") continue;
10916
10997
  if (l.type === "group") out.push({ ...l, children: pixelsOnly(l.children) });
10917
- else if (l.type === "pixel" && _optionalChain([l, 'access', _465 => _465.filters, 'optionalAccess', _466 => _466.length])) {
10998
+ else if (l.type === "pixel" && _optionalChain([l, 'access', _466 => _466.filters, 'optionalAccess', _467 => _467.length])) {
10918
10999
  const p = { ...l };
10919
11000
  delete p.filters;
10920
11001
  out.push(p);
@@ -10980,7 +11061,7 @@ function toHex(c) {
10980
11061
  return "#" + [c[0], c[1], c[2]].map((v) => Math.round(v).toString(16).padStart(2, "0")).join("");
10981
11062
  }
10982
11063
  function normalizeSelection(mask) {
10983
- return _optionalChain([mask, 'optionalAccess', _467 => _467.bounds]) ? mask : null;
11064
+ return _optionalChain([mask, 'optionalAccess', _468 => _468.bounds]) ? mask : null;
10984
11065
  }
10985
11066
  function sameSelection(a, b) {
10986
11067
  if (a.width !== b.width || a.height !== b.height) return false;
@@ -11190,7 +11271,7 @@ function loadImageEditorDocument(input) {
11190
11271
  }
11191
11272
  const state = { version: 1, ...result.value };
11192
11273
  if (isV2) {
11193
- if (_optionalChain([state, 'access', _468 => _468.adjustments, 'access', _469 => _469.layers, 'optionalAccess', _470 => _470.length])) state.version = 2;
11274
+ if (_optionalChain([state, 'access', _469 => _469.adjustments, 'access', _470 => _470.layers, 'optionalAccess', _471 => _471.length])) state.version = 2;
11194
11275
  result.report.version = 2;
11195
11276
  }
11196
11277
  if (state.selection === void 0) delete state.selection;
@@ -11398,7 +11479,7 @@ function findAdjustmentControl(id) {
11398
11479
  }
11399
11480
  function findLayerControl(kind, id) {
11400
11481
  if (id === "opacity") return ADJUSTMENT_LAYER_OPACITY_CONTROL;
11401
- return _optionalChain([ADJUSTMENT_LAYER_CONTROLS, 'access', _471 => _471[kind], 'optionalAccess', _472 => _472.find, 'call', _473 => _473((c) => c.id === id)]);
11482
+ return _optionalChain([ADJUSTMENT_LAYER_CONTROLS, 'access', _472 => _472[kind], 'optionalAccess', _473 => _473.find, 'call', _474 => _474((c) => c.id === id)]);
11402
11483
  }
11403
11484
  function clampControlValue(spec, v) {
11404
11485
  if (typeof v !== "number" || !Number.isFinite(v)) return spec.default;
@@ -11805,7 +11886,9 @@ var REFINE_OUTPUTS = [
11805
11886
  { id: "selection", label: "Selection" },
11806
11887
  { id: "layer-mask", label: "Layer Mask" },
11807
11888
  { id: "new-layer", label: "New Layer" },
11808
- { id: "new-layer-with-mask", label: "New Layer with Layer Mask" }
11889
+ { id: "new-layer-with-mask", label: "New Layer with Layer Mask" },
11890
+ { id: "new-document", label: "New Document", needsDocuments: true },
11891
+ { id: "new-document-with-mask", label: "New Document with Layer Mask", needsDocuments: true }
11809
11892
  ];
11810
11893
  function describeSelection(mask) {
11811
11894
  if (!mask || !mask.bounds) return "No selection";
@@ -11862,7 +11945,7 @@ function summary(controller) {
11862
11945
  const area = _chunkQYLWG22Ncjs.selectionArea.call(void 0, sel);
11863
11946
  return {
11864
11947
  empty: !sel,
11865
- bounds: _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _474 => _474.bounds]), () => ( null)),
11948
+ bounds: _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _475 => _475.bounds]), () => ( null)),
11866
11949
  /** Σ coverage in pixels. */
11867
11950
  area: Math.round(area),
11868
11951
  percent: Math.round(area / Math.max(1, width * height) * 1e4) / 100,
@@ -11938,7 +12021,7 @@ function createImageSelectionTools(controller) {
11938
12021
  break;
11939
12022
  }
11940
12023
  case "polygon": {
11941
- const list = Array.isArray(points) ? points.map((p) => ({ x: num2(_optionalChain([p, 'optionalAccess', _475 => _475.x]), NaN), y: num2(_optionalChain([p, 'optionalAccess', _476 => _476.y]), NaN) })) : [];
12024
+ const list = Array.isArray(points) ? points.map((p) => ({ x: num2(_optionalChain([p, 'optionalAccess', _476 => _476.x]), NaN), y: num2(_optionalChain([p, 'optionalAccess', _477 => _477.y]), NaN) })) : [];
11942
12025
  if (list.length < 3 || !list.every((p) => Number.isFinite(p.x) && Number.isFinite(p.y))) {
11943
12026
  throw new Error("polygon needs points: at least 3 { x, y } vertices.");
11944
12027
  }
@@ -12027,11 +12110,11 @@ function createImageSelectionTools(controller) {
12027
12110
  shiftEdge: { type: "number", minimum: -100, maximum: 100, description: "Move the edge out (+) or in (-), in percent." },
12028
12111
  output: {
12029
12112
  type: "string",
12030
- enum: ["selection", "layer-mask", "new-layer", "new-layer-with-mask"],
12031
- description: "Where the result goes (default selection). layer-mask keeps every pixel and is easiest to revise; new-layer-with-mask too, on a copy."
12113
+ enum: ["selection", "layer-mask", "new-layer", "new-layer-with-mask", "new-document", "new-document-with-mask"],
12114
+ description: "Where the result goes (default selection). layer-mask keeps every pixel and is easiest to revise; new-layer-with-mask too, on a copy. new-document and new-document-with-mask hand a new one-layer document to the host (only when the host can open documents; this one is unchanged) and return its documentId."
12032
12115
  },
12033
12116
  layerId: { type: "string", description: "The layer for layer outputs (default the active layer; see list_layers). New-layer outputs need a pixel layer." },
12034
- decontaminate: { type: "number", minimum: 0, maximum: 100, description: "Decontaminate Colors amount 0-100 (default 0), only with output new-layer or new-layer-with-mask." },
12117
+ decontaminate: { type: "number", minimum: 0, maximum: 100, description: "Decontaminate Colors amount 0-100 (default 0), only with the new-layer and new-document outputs." },
12035
12118
  edits: {
12036
12119
  type: "array",
12037
12120
  description: "Strokes applied before refining, in order.",
@@ -12066,7 +12149,7 @@ function createImageSelectionTools(controller) {
12066
12149
  },
12067
12150
  annotations: writeAnnotations("Refine the selection edge"),
12068
12151
  handler: async (params) => {
12069
- const edits = Array.isArray(params.edits) ? params.edits.map((e) => e.kind === "object" ? { ...e } : { ...e, points: (_nullishCoalesce(e.points, () => ( []))).map((p) => ({ x: num2(_optionalChain([p, 'optionalAccess', _477 => _477.x]), NaN), y: num2(_optionalChain([p, 'optionalAccess', _478 => _478.y]), NaN) })) }) : [];
12152
+ const edits = Array.isArray(params.edits) ? params.edits.map((e) => e.kind === "object" ? { ...e } : { ...e, points: (_nullishCoalesce(e.points, () => ( []))).map((p) => ({ x: num2(_optionalChain([p, 'optionalAccess', _478 => _478.x]), NaN), y: num2(_optionalChain([p, 'optionalAccess', _479 => _479.y]), NaN) })) }) : [];
12070
12153
  for (const e of edits) {
12071
12154
  if (e.kind === "object") {
12072
12155
  if (!e.rect === !e.point) throw new Error("An object edit takes rect (a box around the object) or point (on it).");
@@ -12230,7 +12313,7 @@ function createImageSelectionTools(controller) {
12230
12313
  },
12231
12314
  annotations: writeAnnotations("Select a polygon (lasso)", true),
12232
12315
  handler: async (args) => {
12233
- const list = Array.isArray(args.points) ? args.points.map((p) => ({ x: num2(_optionalChain([p, 'optionalAccess', _479 => _479.x]), NaN), y: num2(_optionalChain([p, 'optionalAccess', _480 => _480.y]), NaN) })) : [];
12316
+ const list = Array.isArray(args.points) ? args.points.map((p) => ({ x: num2(_optionalChain([p, 'optionalAccess', _480 => _480.x]), NaN), y: num2(_optionalChain([p, 'optionalAccess', _481 => _481.y]), NaN) })) : [];
12234
12317
  if (list.length < 3 || !list.every((p) => Number.isFinite(p.x) && Number.isFinite(p.y))) {
12235
12318
  throw new Error("points needs at least 3 { x, y } vertices in natural image pixels.");
12236
12319
  }
@@ -12267,7 +12350,7 @@ function createImageSelectionTools(controller) {
12267
12350
  },
12268
12351
  annotations: writeAnnotations("Quick Selection"),
12269
12352
  handler: async (args, context) => {
12270
- const strokes = Array.isArray(args.strokes) ? args.strokes.map((s) => Array.isArray(s) ? s.map((p) => ({ x: num2(_optionalChain([p, 'optionalAccess', _481 => _481.x]), NaN), y: num2(_optionalChain([p, 'optionalAccess', _482 => _482.y]), NaN) })) : []) : [];
12353
+ const strokes = Array.isArray(args.strokes) ? args.strokes.map((s) => Array.isArray(s) ? s.map((p) => ({ x: num2(_optionalChain([p, 'optionalAccess', _482 => _482.x]), NaN), y: num2(_optionalChain([p, 'optionalAccess', _483 => _483.y]), NaN) })) : []) : [];
12271
12354
  if (!strokes.length || strokes.some((s) => !s.length || !s.every((p) => Number.isFinite(p.x) && Number.isFinite(p.y)))) {
12272
12355
  throw new Error("strokes needs at least one stroke of { x, y } points in natural image pixels.");
12273
12356
  }
@@ -12276,7 +12359,7 @@ function createImageSelectionTools(controller) {
12276
12359
  mode: _chunkQYLWG22Ncjs.parseSelectionMode.call(void 0, args.mode),
12277
12360
  sampleAllLayers: args.sampleAllLayers,
12278
12361
  enhanceEdge: args.enhanceEdge,
12279
- signal: _optionalChain([context, 'optionalAccess', _483 => _483.signal])
12362
+ signal: _optionalChain([context, 'optionalAccess', _484 => _484.signal])
12280
12363
  });
12281
12364
  return summary(controller);
12282
12365
  }
@@ -12314,7 +12397,7 @@ function createImageSelectionTools(controller) {
12314
12397
  sampleAllLayers: args.sampleAllLayers,
12315
12398
  enhanceEdge: args.enhanceEdge,
12316
12399
  useModel: args.useModel,
12317
- signal: _optionalChain([context, 'optionalAccess', _484 => _484.signal])
12400
+ signal: _optionalChain([context, 'optionalAccess', _485 => _485.signal])
12318
12401
  };
12319
12402
  const { method } = rect ? await controller.selectObject({ rect: { x: num2(rect.x, NaN), y: num2(rect.y, NaN), width: num2(rect.width, NaN), height: num2(rect.height, NaN) } }, options) : await controller.selectObject({ point: { x: num2(point.x, NaN), y: num2(point.y, NaN) } }, options);
12320
12403
  return { ...summary(controller), method };
@@ -12343,7 +12426,7 @@ function createImageSelectionTools(controller) {
12343
12426
  softness: args.softness === void 0 ? void 0 : num2(args.softness, 4),
12344
12427
  mode: _chunkQYLWG22Ncjs.parseSelectionMode.call(void 0, args.mode),
12345
12428
  sampleAllLayers: args.sampleAllLayers,
12346
- signal: _optionalChain([context, 'optionalAccess', _485 => _485.signal])
12429
+ signal: _optionalChain([context, 'optionalAccess', _486 => _486.signal])
12347
12430
  });
12348
12431
  return { ...summary(controller), noiseLevel };
12349
12432
  }
@@ -12371,7 +12454,7 @@ function createImageSelectionTools(controller) {
12371
12454
  mode: _chunkQYLWG22Ncjs.parseSelectionMode.call(void 0, args.mode),
12372
12455
  sampleAllLayers: args.sampleAllLayers,
12373
12456
  useModel: args.useModel,
12374
- signal: _optionalChain([context, 'optionalAccess', _486 => _486.signal])
12457
+ signal: _optionalChain([context, 'optionalAccess', _487 => _487.signal])
12375
12458
  });
12376
12459
  return { ...summary(controller), method, ...note ? { note } : {} };
12377
12460
  }
@@ -12469,7 +12552,7 @@ function createImageSelectionTools(controller) {
12469
12552
  await controller.selectColorRangePreset(args.preset, { ...common, falloff: num2(args.fuzziness, 20) });
12470
12553
  } else {
12471
12554
  const samples = args.samples.map((s, i) => {
12472
- if (typeof _optionalChain([s, 'optionalAccess', _487 => _487.color]) !== "string" || !/^#?[0-9a-f]{6}$/i.test(s.color.trim())) throw new Error(`samples[${i}].color must be #rrggbb.`);
12555
+ if (typeof _optionalChain([s, 'optionalAccess', _488 => _488.color]) !== "string" || !/^#?[0-9a-f]{6}$/i.test(s.color.trim())) throw new Error(`samples[${i}].color must be #rrggbb.`);
12473
12556
  const at = typeof s.x === "number" && typeof s.y === "number" ? { x: s.x, y: s.y } : void 0;
12474
12557
  return at ? { color: s.color, at } : { color: s.color };
12475
12558
  });
@@ -12990,13 +13073,13 @@ function createImageSubjectSelectionTool(controller) {
12990
13073
  handler: async ({ target, maxSegments, mode, feather, enhanceEdge }, context) => {
12991
13074
  if (target !== void 0 && typeof target !== "string") throw new Error("target must be a description in words.");
12992
13075
  if (controller.segmentationProvider && !String(_nullishCoalesce(target, () => ( ""))).trim()) throw new Error("target must describe what to select (a model is set, and it selects by description).");
12993
- const perform = _optionalChain([context, 'optionalAccess', _488 => _488.perform]);
13076
+ const perform = _optionalChain([context, 'optionalAccess', _489 => _489.perform]);
12994
13077
  const { segments, method, note } = await controller.selectSubject(String(_nullishCoalesce(target, () => ( ""))), {
12995
13078
  mode: _chunkQYLWG22Ncjs.parseSelectionMode.call(void 0, mode),
12996
13079
  feather: num2(feather, 0),
12997
13080
  maxSegments: typeof maxSegments === "number" ? Math.max(1, Math.round(maxSegments)) : void 0,
12998
13081
  enhanceEdge: enhanceEdge === true,
12999
- signal: _optionalChain([context, 'optionalAccess', _489 => _489.signal]),
13082
+ signal: _optionalChain([context, 'optionalAccess', _490 => _490.signal]),
13000
13083
  // Under playback the cursor traces what the model found, as a lasso, before it is selected.
13001
13084
  beforeApply: perform ? (outlines) => perform(planOutlineTrace(outlines)) : void 0
13002
13085
  });
@@ -13074,7 +13157,7 @@ async function renderImageRegion(controller, request) {
13074
13157
  const maskView = maskViewCanvas(controller, document);
13075
13158
  if (maskView) context.drawImage(maskView, rect.x, rect.y, rect.width, rect.height, 0, 0, out.width, out.height);
13076
13159
  const selection = state.selection;
13077
- if (_optionalChain([selection, 'optionalAccess', _490 => _490.bounds]) && selection.width === state.imageDimensions.width && selection.height === state.imageDimensions.height) {
13160
+ if (_optionalChain([selection, 'optionalAccess', _491 => _491.bounds]) && selection.width === state.imageDimensions.width && selection.height === state.imageDimensions.height) {
13078
13161
  const shade = selectionShade(selection, document);
13079
13162
  if (shade) context.drawImage(shade, rect.x, rect.y, rect.width, rect.height, 0, 0, out.width, out.height);
13080
13163
  }
@@ -13099,7 +13182,7 @@ function createImageCaptureSurface(controller) {
13099
13182
  return {
13100
13183
  units: "image pixels",
13101
13184
  content: whole,
13102
- selection: () => ({ rect: _nullishCoalesce(_optionalChain([controller, 'access', _491 => _491.getState, 'call', _492 => _492(), 'access', _493 => _493.selection, 'optionalAccess', _494 => _494.bounds]), () => ( null)) }),
13185
+ selection: () => ({ rect: _nullishCoalesce(_optionalChain([controller, 'access', _492 => _492.getState, 'call', _493 => _493(), 'access', _494 => _494.selection, 'optionalAccess', _495 => _495.bounds]), () => ( null)) }),
13103
13186
  overlays: "a shade over unselected pixels, the crop box outline and a layer mask view (set_mask_view)",
13104
13187
  maxScale: 8,
13105
13188
  render: (request) => renderImageRegion(controller, request)
@@ -13433,7 +13516,7 @@ function describeLayer(layer, activeId, boundsOf) {
13433
13516
  out.bounds = boundsOf(layer);
13434
13517
  out.fillOpacity = round3(_nullishCoalesce(layer.fillOpacity, () => ( 1)));
13435
13518
  out.shape = {
13436
- components: layer.components.map((c) => ({ op: c.op, kind: _nullishCoalesce(_optionalChain([c, 'access', _495 => _495.live, 'optionalAccess', _496 => _496.kind]), () => ( "path")) })),
13519
+ components: layer.components.map((c) => ({ op: c.op, kind: _nullishCoalesce(_optionalChain([c, 'access', _496 => _496.live, 'optionalAccess', _497 => _497.kind]), () => ( "path")) })),
13437
13520
  fill: layer.fill ? layer.fill.type : null,
13438
13521
  stroke: layer.stroke ? { width: layer.stroke.width, paint: layer.stroke.paint.type } : null
13439
13522
  };
@@ -13456,8 +13539,8 @@ function describeLayer(layer, activeId, boundsOf) {
13456
13539
  out.bounds = boundsOf(layer);
13457
13540
  out.fillOpacity = round3(_nullishCoalesce(layer.fillOpacity, () => ( 1)));
13458
13541
  out.contents = { id: layer.contents.id, name: layer.contents.name, kind: layer.contents.kind, width: layer.contents.width, height: layer.contents.height };
13459
- out.smartFilters = (_nullishCoalesce(_optionalChain([layer, 'access', _497 => _497.smartFilters, 'optionalAccess', _498 => _498.filters]), () => ( []))).map((f) => ({ id: f.id, kind: f.kind, enabled: f.enabled }));
13460
- out.filterMask = maskSummary(_optionalChain([layer, 'access', _499 => _499.smartFilters, 'optionalAccess', _500 => _500.mask]));
13542
+ out.smartFilters = (_nullishCoalesce(_optionalChain([layer, 'access', _498 => _498.smartFilters, 'optionalAccess', _499 => _499.filters]), () => ( []))).map((f) => ({ id: f.id, kind: f.kind, enabled: f.enabled }));
13543
+ out.filterMask = maskSummary(_optionalChain([layer, 'access', _500 => _500.smartFilters, 'optionalAccess', _501 => _501.mask]));
13461
13544
  break;
13462
13545
  }
13463
13546
  return out;
@@ -13485,7 +13568,7 @@ function createImageLayerTools(controller) {
13485
13568
  if (!loc) return null;
13486
13569
  return {
13487
13570
  ...describeLayer(loc.layer, s.activeLayerId, (x) => controller.getLayerBounds(x.id)),
13488
- parentId: _nullishCoalesce(_optionalChain([loc, 'access', _501 => _501.parent, 'optionalAccess', _502 => _502.id]), () => ( null)),
13571
+ parentId: _nullishCoalesce(_optionalChain([loc, 'access', _502 => _502.parent, 'optionalAccess', _503 => _503.id]), () => ( null)),
13489
13572
  index: loc.index
13490
13573
  };
13491
13574
  };
@@ -13808,7 +13891,7 @@ function createImageLayerTools(controller) {
13808
13891
  if (view !== "gray" && view !== "overlay" && view !== "off") throw new Error(`Unknown view "${String(view)}". Use gray, overlay or off.`);
13809
13892
  const id = view === "off" || layerId === void 0 ? void 0 : exists(layerId);
13810
13893
  const shown = controller.setMaskView(view, id);
13811
- return { view: _nullishCoalesce(_optionalChain([shown, 'optionalAccess', _503 => _503.mode]), () => ( "off")), layerId: _nullishCoalesce(_optionalChain([shown, 'optionalAccess', _504 => _504.layerId]), () => ( null)) };
13894
+ return { view: _nullishCoalesce(_optionalChain([shown, 'optionalAccess', _504 => _504.mode]), () => ( "off")), layerId: _nullishCoalesce(_optionalChain([shown, 'optionalAccess', _505 => _505.layerId]), () => ( null)) };
13812
13895
  }
13813
13896
  };
13814
13897
  const maskProps = {
@@ -14302,26 +14385,26 @@ function snapTo45(from, point) {
14302
14385
  return { x: from.x + Math.cos(a) * len, y: from.y + Math.sin(a) * len };
14303
14386
  }
14304
14387
  var SelectionGesture = (_class13 = class {
14305
- constructor(controller, getOptions) {;_class13.prototype.__init103.call(this);_class13.prototype.__init104.call(this);_class13.prototype.__init105.call(this);_class13.prototype.__init106.call(this);_class13.prototype.__init107.call(this);_class13.prototype.__init108.call(this);_class13.prototype.__init109.call(this);_class13.prototype.__init110.call(this);_class13.prototype.__init111.call(this);_class13.prototype.__init112.call(this);_class13.prototype.__init113.call(this);
14388
+ constructor(controller, getOptions) {;_class13.prototype.__init104.call(this);_class13.prototype.__init105.call(this);_class13.prototype.__init106.call(this);_class13.prototype.__init107.call(this);_class13.prototype.__init108.call(this);_class13.prototype.__init109.call(this);_class13.prototype.__init110.call(this);_class13.prototype.__init111.call(this);_class13.prototype.__init112.call(this);_class13.prototype.__init113.call(this);_class13.prototype.__init114.call(this);
14306
14389
  this.controller = controller;
14307
14390
  this.getOptions = getOptions;
14308
14391
  }
14309
14392
 
14310
14393
 
14311
- __init103() {this.start = null}
14312
- __init104() {this.points = []}
14313
- __init105() {this.current = null}
14314
- __init106() {this.modifiers = {}}
14394
+ __init104() {this.start = null}
14395
+ __init105() {this.points = []}
14396
+ __init106() {this.current = null}
14397
+ __init107() {this.modifiers = {}}
14315
14398
  /** Polygonal lasso corners while one is being drawn. */
14316
- __init107() {this.polygon = null}
14317
- __init108() {this.pressedAt = null}
14318
- __init109() {this.freehand = false}
14319
- __init110() {this.magnetic = null}
14399
+ __init108() {this.polygon = null}
14400
+ __init109() {this.pressedAt = null}
14401
+ __init110() {this.freehand = false}
14402
+ __init111() {this.magnetic = null}
14320
14403
  /** A click this close to the first corner (natural pixels) closes a polygonal lasso. */
14321
- __init111() {this.closeRadius = 8}
14404
+ __init112() {this.closeRadius = 8}
14322
14405
  /** The last error (e.g. pixels unavailable for the wand), for the UI to show. */
14323
- __init112() {this.error = null}
14324
- __init113() {this.pending = Promise.resolve()}
14406
+ __init113() {this.error = null}
14407
+ __init114() {this.pending = Promise.resolve()}
14325
14408
  get active() {
14326
14409
  return this.start !== null || this.polygon !== null || this.magnetic !== null;
14327
14410
  }
@@ -14670,7 +14753,7 @@ function handleSelectionShortcut(controller, e, onError) {
14670
14753
  try {
14671
14754
  fn();
14672
14755
  } catch (err) {
14673
- _optionalChain([onError, 'optionalCall', _505 => _505(err instanceof Error ? err.message : String(err))]);
14756
+ _optionalChain([onError, 'optionalCall', _506 => _506(err instanceof Error ? err.message : String(err))]);
14674
14757
  }
14675
14758
  return true;
14676
14759
  };
@@ -14685,9 +14768,9 @@ function handleMaskViewKey(controller, e) {
14685
14768
  if (e.ctrlKey || e.metaKey || e.altKey || e.key !== "\\") return false;
14686
14769
  const id = controller.getState().activeLayerId;
14687
14770
  const layer = id ? controller.getLayer(id) : null;
14688
- if (!_optionalChain([layer, 'optionalAccess', _506 => _506.mask]) || layer.mask.source) return false;
14771
+ if (!_optionalChain([layer, 'optionalAccess', _507 => _507.mask]) || layer.mask.source) return false;
14689
14772
  const view = controller.getMaskView();
14690
- controller.setMaskView(_optionalChain([view, 'optionalAccess', _507 => _507.layerId]) === layer.id && view.mode === "overlay" ? "off" : "overlay", layer.id);
14773
+ controller.setMaskView(_optionalChain([view, 'optionalAccess', _508 => _508.layerId]) === layer.id && view.mode === "overlay" ? "off" : "overlay", layer.id);
14691
14774
  return true;
14692
14775
  }
14693
14776
  function handleQuickMaskKey(controller, e) {
@@ -14882,14 +14965,14 @@ function handlePaintShortcut(controller, e) {
14882
14965
  return false;
14883
14966
  }
14884
14967
  var PaintGesture = (_class14 = class {
14885
- constructor(controller) {;_class14.prototype.__init114.call(this);_class14.prototype.__init115.call(this);_class14.prototype.__init116.call(this);
14968
+ constructor(controller) {;_class14.prototype.__init115.call(this);_class14.prototype.__init116.call(this);_class14.prototype.__init117.call(this);
14886
14969
  this.controller = controller;
14887
14970
  }
14888
14971
 
14889
- __init114() {this.stroke = null}
14890
- __init115() {this.move = null}
14972
+ __init115() {this.stroke = null}
14973
+ __init116() {this.move = null}
14891
14974
  /** The last refusal (e.g. "layer is locked"), for the editor to show. */
14892
- __init116() {this.error = null}
14975
+ __init117() {this.error = null}
14893
14976
  get active() {
14894
14977
  return Boolean(this.stroke || this.move);
14895
14978
  }
@@ -14901,7 +14984,7 @@ var PaintGesture = (_class14 = class {
14901
14984
  const layer = this.controller.getActiveLayer();
14902
14985
  if (!layer) throw new Error("Select a layer to move in the Layers panel.");
14903
14986
  if (layer.type !== "pixel" && layer.type !== "shape" && layer.type !== "smart") throw new Error(`Only pixel, shape and smart object layers move; "${layer.name}" is a ${layer.type} layer.`);
14904
- if (_optionalChain([layer, 'access', _508 => _508.locks, 'optionalAccess', _509 => _509.all]) || _optionalChain([layer, 'access', _510 => _510.locks, 'optionalAccess', _511 => _511.position])) throw new Error(`Layer "${layer.name}" has its position locked.`);
14987
+ if (_optionalChain([layer, 'access', _509 => _509.locks, 'optionalAccess', _510 => _510.all]) || _optionalChain([layer, 'access', _511 => _511.locks, 'optionalAccess', _512 => _512.position])) throw new Error(`Layer "${layer.name}" has its position locked.`);
14905
14988
  const origin = layer.type === "pixel" ? { ...layer.offset } : layer.type === "smart" ? { ...layer.placement.corners[0] } : (() => {
14906
14989
  const b = _chunkQE7D7TZRcjs.shapeGeometryBounds.call(void 0, layer);
14907
14990
  return b ? { x: b.x, y: b.y } : { x: 0, y: 0 };
@@ -14958,7 +15041,7 @@ var PaintGesture = (_class14 = class {
14958
15041
  this.move = null;
14959
15042
  }
14960
15043
  cancel() {
14961
- _optionalChain([this, 'access', _512 => _512.stroke, 'optionalAccess', _513 => _513.cancel, 'call', _514 => _514()]);
15044
+ _optionalChain([this, 'access', _513 => _513.stroke, 'optionalAccess', _514 => _514.cancel, 'call', _515 => _515()]);
14962
15045
  this.stroke = null;
14963
15046
  this.move = null;
14964
15047
  }
@@ -16039,7 +16122,7 @@ function createImageSmartObjectTools(controller) {
16039
16122
  const layerSummary = (id) => {
16040
16123
  const s = controller.getState();
16041
16124
  const loc = _chunkUOGKSVRQcjs.findLayer.call(void 0, s.layers, id);
16042
- return loc ? { ...describeLayer(loc.layer, s.activeLayerId, (x) => controller.getLayerBounds(x.id)), parentId: _nullishCoalesce(_optionalChain([loc, 'access', _515 => _515.parent, 'optionalAccess', _516 => _516.id]), () => ( null)), index: loc.index } : null;
16125
+ return loc ? { ...describeLayer(loc.layer, s.activeLayerId, (x) => controller.getLayerBounds(x.id)), parentId: _nullishCoalesce(_optionalChain([loc, 'access', _516 => _516.parent, 'optionalAccess', _517 => _517.id]), () => ( null)), index: loc.index } : null;
16043
16126
  };
16044
16127
  const getSmart = {
16045
16128
  name: "get_smart_object",
@@ -16596,7 +16679,7 @@ function createImageShapeTools(controller) {
16596
16679
  const layerSummary = (id) => {
16597
16680
  const s = controller.getState();
16598
16681
  const loc = _chunkUOGKSVRQcjs.findLayer.call(void 0, s.layers, id);
16599
- return loc ? { ...describeLayer(loc.layer, s.activeLayerId, (x) => controller.getLayerBounds(x.id)), parentId: _nullishCoalesce(_optionalChain([loc, 'access', _517 => _517.parent, 'optionalAccess', _518 => _518.id]), () => ( null)), index: loc.index } : null;
16682
+ return loc ? { ...describeLayer(loc.layer, s.activeLayerId, (x) => controller.getLayerBounds(x.id)), parentId: _nullishCoalesce(_optionalChain([loc, 'access', _518 => _518.parent, 'optionalAccess', _519 => _519.id]), () => ( null)), index: loc.index } : null;
16600
16683
  };
16601
16684
  const get = {
16602
16685
  name: "get_shape_layer",
@@ -16813,7 +16896,7 @@ function createImageShapeTools(controller) {
16813
16896
  const mode = args.mode;
16814
16897
  controller.pathToSelection(pathSpec(args), { feather: args.feather, antiAlias: args.antiAlias, mode });
16815
16898
  const sel = controller.getSelection();
16816
- return { empty: !sel, bounds: _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _519 => _519.bounds]), () => ( null)), area: Math.round(sel ? _chunkQYLWG22Ncjs.selectionArea.call(void 0, sel) : 0) };
16899
+ return { empty: !sel, bounds: _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _520 => _520.bounds]), () => ( null)), area: Math.round(sel ? _chunkQYLWG22Ncjs.selectionArea.call(void 0, sel) : 0) };
16817
16900
  }
16818
16901
  };
16819
16902
  const getVectorMask = {
@@ -16844,7 +16927,7 @@ function createImageShapeTools(controller) {
16844
16927
  handler: (args) => {
16845
16928
  const id = layerArg(args.layerId);
16846
16929
  const spec = pathSpec(args);
16847
- const hasPath = _optionalChain([spec, 'access', _520 => _520.components, 'optionalAccess', _521 => _521.length]) || spec.shape !== void 0 || spec.subpaths !== void 0;
16930
+ const hasPath = _optionalChain([spec, 'access', _521 => _521.components, 'optionalAccess', _522 => _522.length]) || spec.shape !== void 0 || spec.subpaths !== void 0;
16848
16931
  const from = _nullishCoalesce(args.from, () => ( (hasPath ? "path" : "reveal-all")));
16849
16932
  if (from !== "selection" && TRACE_KEYS.some((k) => args[k] !== void 0)) throw new Error("tolerance, cornerRoundness and minArea apply only to from selection.");
16850
16933
  controller.addVectorMask(id, from, spec, traceOptions(args));
@@ -16964,7 +17047,7 @@ function createImageTypeTools(controller) {
16964
17047
  const layerSummary = (id) => {
16965
17048
  const s = controller.getState();
16966
17049
  const loc = _chunkUOGKSVRQcjs.findLayer.call(void 0, s.layers, id);
16967
- return loc ? { ...describeLayer(loc.layer, s.activeLayerId, (x) => controller.getLayerBounds(x.id)), parentId: _nullishCoalesce(_optionalChain([loc, 'access', _522 => _522.parent, 'optionalAccess', _523 => _523.id]), () => ( null)), index: loc.index } : null;
17050
+ return loc ? { ...describeLayer(loc.layer, s.activeLayerId, (x) => controller.getLayerBounds(x.id)), parentId: _nullishCoalesce(_optionalChain([loc, 'access', _523 => _523.parent, 'optionalAccess', _524 => _524.id]), () => ( null)), index: loc.index } : null;
16968
17051
  };
16969
17052
  const range = (args) => ({ start: args.start, end: args.end });
16970
17053
  const listFonts = {
@@ -16973,7 +17056,7 @@ function createImageTypeTools(controller) {
16973
17056
  description: "Returns the font families type layers can use here (generic families such as sans-serif always work). Changes nothing.",
16974
17057
  inputSchema: { type: "object", properties: {}, additionalProperties: false },
16975
17058
  annotations: { title: "List fonts", ...READ11 },
16976
- handler: () => ({ families: controller.listFonts(), shaper: _nullishCoalesce(_optionalChain([controller, 'access', _524 => _524.getTextShaper, 'call', _525 => _525(), 'optionalAccess', _526 => _526.id]), () => ( null)) })
17059
+ handler: () => ({ families: controller.listFonts(), shaper: _nullishCoalesce(_optionalChain([controller, 'access', _525 => _525.getTextShaper, 'call', _526 => _526(), 'optionalAccess', _527 => _527.id]), () => ( null)) })
16977
17060
  };
16978
17061
  const get = {
16979
17062
  name: "get_text_layer",
@@ -17129,7 +17212,7 @@ function createImageTypeTools(controller) {
17129
17212
  const init = pick2(args, ["text", "x", "y", "orientation", "box", "style", "paragraph", "rotation", "mode", "feather", "antiAlias"]);
17130
17213
  controller.selectTextShape(init);
17131
17214
  const sel = controller.getSelection();
17132
- return { empty: !sel, bounds: _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _527 => _527.bounds]), () => ( null)), area: Math.round(sel ? _chunkQYLWG22Ncjs.selectionArea.call(void 0, sel) : 0) };
17215
+ return { empty: !sel, bounds: _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _528 => _528.bounds]), () => ( null)), area: Math.round(sel ? _chunkQYLWG22Ncjs.selectionArea.call(void 0, sel) : 0) };
17133
17216
  }
17134
17217
  };
17135
17218
  return [listFonts, get, add2, setText, setStyle, setParagraph, setFrame, setOrientation, toShape, typeMask];
@@ -17308,7 +17391,7 @@ function createImageEditorToolProvider(controller, options = {}) {
17308
17391
  for (const ref of [aboveId, parentId]) {
17309
17392
  if (ref !== void 0 && !controller.getLayer(ref)) throw new Error(`Unknown layer "${ref}". Call list_layers for ids.`);
17310
17393
  }
17311
- if (parentId !== void 0 && _optionalChain([controller, 'access', _528 => _528.getLayer, 'call', _529 => _529(parentId), 'optionalAccess', _530 => _530.type]) !== "group") throw new Error(`Layer "${parentId}" is not a group.`);
17394
+ if (parentId !== void 0 && _optionalChain([controller, 'access', _529 => _529.getLayer, 'call', _530 => _530(parentId), 'optionalAccess', _531 => _531.type]) !== "group") throw new Error(`Layer "${parentId}" is not a group.`);
17312
17395
  const id = controller.addAdjustmentLayer({ kind, params, opacity, blend, name, aboveId, parentId, useSelection: useSelection !== false });
17313
17396
  const layer = controller.getAdjustmentLayer(id);
17314
17397
  return { layer: JSON.parse(JSON.stringify(layer)), index: controller.getAdjustmentLayers().findIndex((l) => l.id === id), masked: Boolean(layer.mask) };
@@ -17545,32 +17628,32 @@ function scaleParams(p, s) {
17545
17628
  return { ...p, radius: p.radius * s, feather: p.feather * s };
17546
17629
  }
17547
17630
  var SelectAndMaskSession = (_class15 = class {
17548
- constructor(controller) {;_class15.prototype.__init117.call(this);_class15.prototype.__init118.call(this);_class15.prototype.__init119.call(this);_class15.prototype.__init120.call(this);_class15.prototype.__init121.call(this);_class15.prototype.__init122.call(this);_class15.prototype.__init123.call(this);_class15.prototype.__init124.call(this);_class15.prototype.__init125.call(this);_class15.prototype.__init126.call(this);_class15.prototype.__init127.call(this);_class15.prototype.__init128.call(this);_class15.prototype.__init129.call(this);
17631
+ constructor(controller) {;_class15.prototype.__init118.call(this);_class15.prototype.__init119.call(this);_class15.prototype.__init120.call(this);_class15.prototype.__init121.call(this);_class15.prototype.__init122.call(this);_class15.prototype.__init123.call(this);_class15.prototype.__init124.call(this);_class15.prototype.__init125.call(this);_class15.prototype.__init126.call(this);_class15.prototype.__init127.call(this);_class15.prototype.__init128.call(this);_class15.prototype.__init129.call(this);_class15.prototype.__init130.call(this);
17549
17632
  this.controller = controller;
17550
17633
  this.base = controller.getSelection();
17551
17634
  this.settingsValue = remembered ? { ...remembered, params: { ...remembered.params }, showOriginal: false } : { ...DEFAULT_SELECT_AND_MASK_SETTINGS, params: { ...DEFAULT_SELECT_AND_MASK_SETTINGS.params } };
17552
17635
  }
17553
17636
 
17554
17637
 
17555
- __init117() {this.editsList = []}
17638
+ __init118() {this.editsList = []}
17556
17639
  /** The edit being painted, shown in the preview but not yet in `edits`. */
17557
- __init118() {this.live = null}
17558
- __init119() {this.dragStart = null}
17559
- __init120() {this.pixels = null}
17560
- __init121() {this.previewPixels = null}
17640
+ __init119() {this.live = null}
17641
+ __init120() {this.dragStart = null}
17642
+ __init121() {this.pixels = null}
17643
+ __init122() {this.previewPixels = null}
17561
17644
 
17562
- __init122() {this.previewMask = null}
17563
- __init123() {this.baseMask = null}
17564
- __init124() {this.listeners = /* @__PURE__ */ new Set()}
17645
+ __init123() {this.previewMask = null}
17646
+ __init124() {this.baseMask = null}
17647
+ __init125() {this.listeners = /* @__PURE__ */ new Set()}
17565
17648
  /** Why the preview could not be made (no pixels), for the UI. */
17566
- __init125() {this.error = null}
17649
+ __init126() {this.error = null}
17567
17650
  /** A note for the UI, such as object aware refinement applying only on OK. */
17568
- __init126() {this.note = null}
17651
+ __init127() {this.note = null}
17569
17652
  /** Bumped each time the preview changes, so a UI can redraw. */
17570
- __init127() {this.revision = 0}
17653
+ __init128() {this.revision = 0}
17571
17654
  /** True while the worker computes a preview. */
17572
- __init128() {this.computing = false}
17573
- __init129() {this.dirty = false}
17655
+ __init129() {this.computing = false}
17656
+ __init130() {this.dirty = false}
17574
17657
  get settings() {
17575
17658
  return this.settingsValue;
17576
17659
  }
@@ -17625,7 +17708,7 @@ var SelectAndMaskSession = (_class15 = class {
17625
17708
  const w = Math.max(1, Math.round(px2.width * s));
17626
17709
  const h = Math.max(1, Math.round(px2.height * s));
17627
17710
  this.previewPixels = scalePixels(px2, w, h);
17628
- this.baseMask = _optionalChain([this, 'access', _531 => _531.base, 'optionalAccess', _532 => _532.bounds]) ? s === 1 ? this.base : _chunkQYLWG22Ncjs.resizeSelection.call(void 0, this.base, w, h) : null;
17711
+ this.baseMask = _optionalChain([this, 'access', _532 => _532.base, 'optionalAccess', _533 => _533.bounds]) ? s === 1 ? this.base : _chunkQYLWG22Ncjs.resizeSelection.call(void 0, this.base, w, h) : null;
17629
17712
  }
17630
17713
  /**
17631
17714
  * Recomputes the preview mask from the base selection, the strokes and the settings: at once on
@@ -17643,7 +17726,7 @@ var SelectAndMaskSession = (_class15 = class {
17643
17726
  const edits = [...this.editsList, ...this.live ? [this.live] : []].map((e) => scaleEdit(e, scale));
17644
17727
  try {
17645
17728
  const { selection, refineBrush } = _chunkX4LUGTQXcjs.applyRefineEdits.call(void 0, px2, this.baseMask, edits, px2.width, px2.height);
17646
- this.previewMask = _optionalChain([selection, 'optionalAccess', _533 => _533.bounds]) ? _chunkX4LUGTQXcjs.refineSelection.call(void 0, px2, selection, scaleParams(this.settingsValue.params, scale), refineBrush) : null;
17729
+ this.previewMask = _optionalChain([selection, 'optionalAccess', _534 => _534.bounds]) ? _chunkX4LUGTQXcjs.refineSelection.call(void 0, px2, selection, scaleParams(this.settingsValue.params, scale), refineBrush) : null;
17647
17730
  this.error = null;
17648
17731
  } catch (err) {
17649
17732
  this.previewMask = null;
@@ -17877,7 +17960,7 @@ var SelectAndMaskSession = (_class15 = class {
17877
17960
  remembered = s.remember ? { ...s, params: { ...s.params } } : null;
17878
17961
  return this.controller.refineSelectionTo(s.params, s.output, {
17879
17962
  edits: [...this.editsList],
17880
- decontaminate: s.output === "new-layer" || s.output === "new-layer-with-mask" ? s.decontaminate : 0,
17963
+ decontaminate: s.output === "selection" || s.output === "layer-mask" ? 0 : s.decontaminate,
17881
17964
  refineMode: s.refineMode
17882
17965
  });
17883
17966
  }
@@ -18031,7 +18114,7 @@ function maskThumbnailClick(controller, layer, e) {
18031
18114
  } else if (e.altKey && !layer.mask.source) {
18032
18115
  const mode = e.shiftKey ? "overlay" : "gray";
18033
18116
  const view = controller.getMaskView();
18034
- controller.setMaskView(_optionalChain([view, 'optionalAccess', _534 => _534.layerId]) === layer.id && view.mode === mode ? "off" : mode, layer.id);
18117
+ controller.setMaskView(_optionalChain([view, 'optionalAccess', _535 => _535.layerId]) === layer.id && view.mode === mode ? "off" : mode, layer.id);
18035
18118
  } else if (e.shiftKey) {
18036
18119
  controller.setLayerMaskProps(layer.id, { enabled: layer.mask.enabled === false });
18037
18120
  } else {
@@ -18095,7 +18178,7 @@ function layerHasThumbnail(layer) {
18095
18178
  return layer.type === "pixel" || layer.type === "shape" || layer.type === "type";
18096
18179
  }
18097
18180
  function layerWarning(layer) {
18098
- if (layer.type === "type" && _optionalChain([layer, 'access', _535 => _535.missingFonts, 'optionalAccess', _536 => _536.length])) {
18181
+ if (layer.type === "type" && _optionalChain([layer, 'access', _536 => _536.missingFonts, 'optionalAccess', _537 => _537.length])) {
18099
18182
  return `Missing ${layer.missingFonts.length === 1 ? "font" : "fonts"}: ${layer.missingFonts.join(", ")}. ${layer.rendering === "stored" ? "Showing the saved pixels until the text is edited." : "Drawn with a fallback font."}`;
18100
18183
  }
18101
18184
  return null;
@@ -18118,16 +18201,16 @@ function layerMenu(controller) {
18118
18201
  const siblings = loc ? loc.parent ? loc.parent.children : s.layers : [];
18119
18202
  const below = loc ? siblings[loc.index - 1] : void 0;
18120
18203
  const hasSel = controller.hasSelection;
18121
- const isPixel = _optionalChain([active, 'optionalAccess', _537 => _537.type]) === "pixel";
18122
- const hasOwnPixels = _optionalChain([active, 'optionalAccess', _538 => _538.type]) === "pixel" || _optionalChain([active, 'optionalAccess', _539 => _539.type]) === "shape" || _optionalChain([active, 'optionalAccess', _540 => _540.type]) === "type" || _optionalChain([active, 'optionalAccess', _541 => _541.type]) === "smart";
18204
+ const isPixel = _optionalChain([active, 'optionalAccess', _538 => _538.type]) === "pixel";
18205
+ const hasOwnPixels = _optionalChain([active, 'optionalAccess', _539 => _539.type]) === "pixel" || _optionalChain([active, 'optionalAccess', _540 => _540.type]) === "shape" || _optionalChain([active, 'optionalAccess', _541 => _541.type]) === "type" || _optionalChain([active, 'optionalAccess', _542 => _542.type]) === "smart";
18123
18206
  return [
18124
18207
  { action: "new-layer", label: "New Layer", enabled: true },
18125
18208
  { action: "new-group", label: "New Group", enabled: true },
18126
18209
  { action: "duplicate", label: "Duplicate Layer", enabled: Boolean(active) },
18127
18210
  { action: "delete", label: "Delete Layer", enabled: Boolean(active) },
18128
18211
  { action: "group-selected", label: "Group Layer", enabled: Boolean(active) },
18129
- { action: "ungroup", label: "Ungroup", enabled: _optionalChain([active, 'optionalAccess', _542 => _542.type]) === "group" },
18130
- { action: "merge-down", label: "Merge Down", enabled: Boolean(_optionalChain([active, 'optionalAccess', _543 => _543.visible]) && _optionalChain([below, 'optionalAccess', _544 => _544.type]) === "pixel") },
18212
+ { action: "ungroup", label: "Ungroup", enabled: _optionalChain([active, 'optionalAccess', _543 => _543.type]) === "group" },
18213
+ { action: "merge-down", label: "Merge Down", enabled: Boolean(_optionalChain([active, 'optionalAccess', _544 => _544.visible]) && _optionalChain([below, 'optionalAccess', _545 => _545.type]) === "pixel") },
18131
18214
  { action: "merge-visible", label: "Merge Visible", enabled: s.layers.some((l) => l.visible) },
18132
18215
  { action: "flatten", label: "Flatten Image", enabled: s.layers.length > 0 },
18133
18216
  { action: "via-copy", label: "Layer via Copy", enabled: isPixel && hasSel },
@@ -18137,27 +18220,27 @@ function layerMenu(controller) {
18137
18220
  { action: "add-mask-hide-selection", label: "Add Mask Hiding Selection", enabled: Boolean(active) && hasSel },
18138
18221
  { action: "add-mask-transparency", label: "Add Mask from Transparency", enabled: hasOwnPixels },
18139
18222
  { action: "select-transparency", label: "Select Layer Pixels", enabled: hasOwnPixels },
18140
- { action: "apply-mask", label: "Apply Layer Mask", enabled: isPixel && Boolean(_optionalChain([active, 'optionalAccess', _545 => _545.mask])) },
18141
- { action: "delete-mask", label: "Delete Layer Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _546 => _546.mask])) },
18142
- { action: "toggle-mask", label: _optionalChain([active, 'optionalAccess', _547 => _547.mask, 'optionalAccess', _548 => _548.enabled]) === false ? "Enable Layer Mask" : "Disable Layer Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _549 => _549.mask])) },
18143
- { action: "toggle-mask-link", label: _optionalChain([active, 'optionalAccess', _550 => _550.mask, 'optionalAccess', _551 => _551.linked]) === false ? "Link Layer Mask" : "Unlink Layer Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _552 => _552.mask]) && !active.mask.source) },
18144
- { action: "add-vector-mask", label: "Add Vector Mask (Reveal All)", enabled: Boolean(active && active.type !== "shape" && !_optionalChain([active, 'access', _553 => _553.mask, 'optionalAccess', _554 => _554.source])) },
18145
- { action: "add-vector-mask-hide", label: "Add Vector Mask (Hide All)", enabled: Boolean(active && active.type !== "shape" && !_optionalChain([active, 'access', _555 => _555.mask, 'optionalAccess', _556 => _556.source])) },
18146
- { action: "add-vector-mask-selection", label: "Add Vector Mask from Selection", enabled: Boolean(active && active.type !== "shape" && !_optionalChain([active, 'access', _557 => _557.mask, 'optionalAccess', _558 => _558.source])) && hasSel },
18147
- { action: "delete-vector-mask", label: "Delete Vector Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _559 => _559.vectorMask])) },
18148
- { action: "toggle-vector-mask", label: _optionalChain([active, 'optionalAccess', _560 => _560.vectorMask, 'optionalAccess', _561 => _561.enabled]) === false ? "Enable Vector Mask" : "Disable Vector Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _562 => _562.vectorMask])) },
18149
- { action: "rasterize-vector-mask", label: "Rasterize Vector Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _563 => _563.vectorMask])) },
18150
- { action: "rasterize", label: "Rasterize Layer", enabled: _optionalChain([active, 'optionalAccess', _564 => _564.type]) === "annotation" || _optionalChain([active, 'optionalAccess', _565 => _565.type]) === "smart" || _optionalChain([active, 'optionalAccess', _566 => _566.type]) === "shape" || _optionalChain([active, 'optionalAccess', _567 => _567.type]) === "type" || isPixel && Boolean(_optionalChain([active, 'optionalAccess', _568 => _568.type]) === "pixel" && _optionalChain([active, 'access', _569 => _569.filters, 'optionalAccess', _570 => _570.length])) },
18223
+ { action: "apply-mask", label: "Apply Layer Mask", enabled: isPixel && Boolean(_optionalChain([active, 'optionalAccess', _546 => _546.mask])) },
18224
+ { action: "delete-mask", label: "Delete Layer Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _547 => _547.mask])) },
18225
+ { action: "toggle-mask", label: _optionalChain([active, 'optionalAccess', _548 => _548.mask, 'optionalAccess', _549 => _549.enabled]) === false ? "Enable Layer Mask" : "Disable Layer Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _550 => _550.mask])) },
18226
+ { action: "toggle-mask-link", label: _optionalChain([active, 'optionalAccess', _551 => _551.mask, 'optionalAccess', _552 => _552.linked]) === false ? "Link Layer Mask" : "Unlink Layer Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _553 => _553.mask]) && !active.mask.source) },
18227
+ { action: "add-vector-mask", label: "Add Vector Mask (Reveal All)", enabled: Boolean(active && active.type !== "shape" && !_optionalChain([active, 'access', _554 => _554.mask, 'optionalAccess', _555 => _555.source])) },
18228
+ { action: "add-vector-mask-hide", label: "Add Vector Mask (Hide All)", enabled: Boolean(active && active.type !== "shape" && !_optionalChain([active, 'access', _556 => _556.mask, 'optionalAccess', _557 => _557.source])) },
18229
+ { action: "add-vector-mask-selection", label: "Add Vector Mask from Selection", enabled: Boolean(active && active.type !== "shape" && !_optionalChain([active, 'access', _558 => _558.mask, 'optionalAccess', _559 => _559.source])) && hasSel },
18230
+ { action: "delete-vector-mask", label: "Delete Vector Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _560 => _560.vectorMask])) },
18231
+ { action: "toggle-vector-mask", label: _optionalChain([active, 'optionalAccess', _561 => _561.vectorMask, 'optionalAccess', _562 => _562.enabled]) === false ? "Enable Vector Mask" : "Disable Vector Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _563 => _563.vectorMask])) },
18232
+ { action: "rasterize-vector-mask", label: "Rasterize Vector Mask", enabled: Boolean(_optionalChain([active, 'optionalAccess', _564 => _564.vectorMask])) },
18233
+ { action: "rasterize", label: "Rasterize Layer", enabled: _optionalChain([active, 'optionalAccess', _565 => _565.type]) === "annotation" || _optionalChain([active, 'optionalAccess', _566 => _566.type]) === "smart" || _optionalChain([active, 'optionalAccess', _567 => _567.type]) === "shape" || _optionalChain([active, 'optionalAccess', _568 => _568.type]) === "type" || isPixel && Boolean(_optionalChain([active, 'optionalAccess', _569 => _569.type]) === "pixel" && _optionalChain([active, 'access', _570 => _570.filters, 'optionalAccess', _571 => _571.length])) },
18151
18234
  { action: "convert-smart", label: "Convert to Smart Object", enabled: Boolean(active && active.type !== "annotation") },
18152
- { action: "edit-contents", label: "Edit Contents", enabled: _optionalChain([active, 'optionalAccess', _571 => _571.type]) === "smart" },
18153
- { action: "smart-via-copy", label: "New Smart Object via Copy", enabled: _optionalChain([active, 'optionalAccess', _572 => _572.type]) === "smart" },
18154
- { action: "add-filter-mask", label: "Add Smart Filter Mask", enabled: _optionalChain([active, 'optionalAccess', _573 => _573.type]) === "smart" && !_optionalChain([active, 'access', _574 => _574.smartFilters, 'optionalAccess', _575 => _575.mask]) },
18155
- { action: "toggle-clip", label: _optionalChain([active, 'optionalAccess', _576 => _576.clipped]) ? "Release Clipping Mask" : "Create Clipping Mask", enabled: Boolean(loc && loc.index > 0) }
18235
+ { action: "edit-contents", label: "Edit Contents", enabled: _optionalChain([active, 'optionalAccess', _572 => _572.type]) === "smart" },
18236
+ { action: "smart-via-copy", label: "New Smart Object via Copy", enabled: _optionalChain([active, 'optionalAccess', _573 => _573.type]) === "smart" },
18237
+ { action: "add-filter-mask", label: "Add Smart Filter Mask", enabled: _optionalChain([active, 'optionalAccess', _574 => _574.type]) === "smart" && !_optionalChain([active, 'access', _575 => _575.smartFilters, 'optionalAccess', _576 => _576.mask]) },
18238
+ { action: "toggle-clip", label: _optionalChain([active, 'optionalAccess', _577 => _577.clipped]) ? "Release Clipping Mask" : "Create Clipping Mask", enabled: Boolean(loc && loc.index > 0) }
18156
18239
  ];
18157
18240
  }
18158
18241
  async function runLayerMenuAction(controller, action) {
18159
18242
  const active = controller.getActiveLayer();
18160
- const id = _optionalChain([active, 'optionalAccess', _577 => _577.id]);
18243
+ const id = _optionalChain([active, 'optionalAccess', _578 => _578.id]);
18161
18244
  try {
18162
18245
  switch (action) {
18163
18246
  case "new-layer":
@@ -18213,10 +18296,10 @@ async function runLayerMenuAction(controller, action) {
18213
18296
  if (id) controller.removeLayerMask(id);
18214
18297
  break;
18215
18298
  case "toggle-mask":
18216
- if (id && _optionalChain([active, 'optionalAccess', _578 => _578.mask])) controller.setLayerMaskProps(id, { enabled: active.mask.enabled === false });
18299
+ if (id && _optionalChain([active, 'optionalAccess', _579 => _579.mask])) controller.setLayerMaskProps(id, { enabled: active.mask.enabled === false });
18217
18300
  break;
18218
18301
  case "toggle-mask-link":
18219
- if (id && _optionalChain([active, 'optionalAccess', _579 => _579.mask])) controller.setLayerMaskProps(id, { linked: active.mask.linked === false });
18302
+ if (id && _optionalChain([active, 'optionalAccess', _580 => _580.mask])) controller.setLayerMaskProps(id, { linked: active.mask.linked === false });
18220
18303
  break;
18221
18304
  case "add-vector-mask":
18222
18305
  case "add-vector-mask-hide":
@@ -18229,7 +18312,7 @@ async function runLayerMenuAction(controller, action) {
18229
18312
  if (id) controller.removeVectorMask(id);
18230
18313
  break;
18231
18314
  case "toggle-vector-mask":
18232
- if (id && _optionalChain([active, 'optionalAccess', _580 => _580.vectorMask])) controller.setVectorMaskProps(id, { enabled: active.vectorMask.enabled === false });
18315
+ if (id && _optionalChain([active, 'optionalAccess', _581 => _581.vectorMask])) controller.setVectorMaskProps(id, { enabled: active.vectorMask.enabled === false });
18233
18316
  break;
18234
18317
  case "rasterize-vector-mask":
18235
18318
  if (id) controller.rasterizeVectorMask(id);
@@ -18250,7 +18333,7 @@ async function runLayerMenuAction(controller, action) {
18250
18333
  if (id) controller.setSmartFilterMask(id, "reveal-all");
18251
18334
  break;
18252
18335
  case "toggle-clip":
18253
- if (id) controller.setLayerProperties(id, { clipped: !_optionalChain([active, 'optionalAccess', _581 => _581.clipped]) });
18336
+ if (id) controller.setLayerProperties(id, { clipped: !_optionalChain([active, 'optionalAccess', _582 => _582.clipped]) });
18254
18337
  break;
18255
18338
  }
18256
18339
  return null;
@@ -18260,7 +18343,7 @@ async function runLayerMenuAction(controller, action) {
18260
18343
  }
18261
18344
  function smartFilterRows(layer) {
18262
18345
  if (layer.type !== "smart") return [];
18263
- const list = _nullishCoalesce(_optionalChain([layer, 'access', _582 => _582.smartFilters, 'optionalAccess', _583 => _583.filters]), () => ( []));
18346
+ const list = _nullishCoalesce(_optionalChain([layer, 'access', _583 => _583.smartFilters, 'optionalAccess', _584 => _584.filters]), () => ( []));
18264
18347
  const rows = list.map((f, index) => ({
18265
18348
  filter: f,
18266
18349
  index,
@@ -18286,8 +18369,8 @@ function extractNormalizedLayerItems(controller, fallbackImageUrl = "") {
18286
18369
  };
18287
18370
  collectSerialized(_nullishCoalesce(serialized.layers, () => ( [])));
18288
18371
  const sLayerMap = new Map(allSerializedLayers.map((sl) => [sl.id, sl]));
18289
- const imgW = _optionalChain([state, 'access', _584 => _584.imageDimensions, 'optionalAccess', _585 => _585.width]) || 1;
18290
- const imgH = _optionalChain([state, 'access', _586 => _586.imageDimensions, 'optionalAccess', _587 => _587.height]) || 1;
18372
+ const imgW = _optionalChain([state, 'access', _585 => _585.imageDimensions, 'optionalAccess', _586 => _586.width]) || 1;
18373
+ const imgH = _optionalChain([state, 'access', _587 => _587.imageDimensions, 'optionalAccess', _588 => _588.height]) || 1;
18291
18374
  return ctrlLayers.map((l) => {
18292
18375
  const bounds = controller.getLayerBounds(l.id) || {
18293
18376
  x: 0,
@@ -18296,8 +18379,8 @@ function extractNormalizedLayerItems(controller, fallbackImageUrl = "") {
18296
18379
  height: imgH
18297
18380
  };
18298
18381
  const sLayer = sLayerMap.get(l.id);
18299
- const assetKey = _optionalChain([sLayer, 'optionalAccess', _588 => _588.asset]);
18300
- const layerDataUrl = assetKey && assets[assetKey] || assets[l.id] || (_optionalChain([sLayer, 'optionalAccess', _589 => _589.source]) === "document" ? fallbackImageUrl : "");
18382
+ const assetKey = _optionalChain([sLayer, 'optionalAccess', _589 => _589.asset]);
18383
+ const layerDataUrl = assetKey && assets[assetKey] || assets[l.id] || (_optionalChain([sLayer, 'optionalAccess', _590 => _590.source]) === "document" ? fallbackImageUrl : "");
18301
18384
  return {
18302
18385
  id: l.id,
18303
18386
  name: l.name || "Untitled Layer",
@@ -18351,9 +18434,9 @@ async function addLayerOfKind(controller, id, init) {
18351
18434
  const cx = Math.round(canvas.width / 2);
18352
18435
  const cy = Math.round(canvas.height / 2);
18353
18436
  return controller.addTextLayer({
18354
- text: _optionalChain([init, 'optionalAccess', _590 => _590.text]) || "New Text",
18355
- x: typeof _optionalChain([init, 'optionalAccess', _591 => _591.x]) === "number" ? init.x : cx - 100,
18356
- y: typeof _optionalChain([init, 'optionalAccess', _592 => _592.y]) === "number" ? init.y : cy,
18437
+ text: _optionalChain([init, 'optionalAccess', _591 => _591.text]) || "New Text",
18438
+ x: typeof _optionalChain([init, 'optionalAccess', _592 => _592.x]) === "number" ? init.x : cx - 100,
18439
+ y: typeof _optionalChain([init, 'optionalAccess', _593 => _593.y]) === "number" ? init.y : cy,
18357
18440
  ...init
18358
18441
  });
18359
18442
  }
@@ -18366,10 +18449,10 @@ async function addLayerOfKind(controller, id, init) {
18366
18449
  return controller.addShapeLayer({
18367
18450
  shape: {
18368
18451
  kind: "rect",
18369
- x: typeof _optionalChain([init, 'optionalAccess', _593 => _593.x]) === "number" ? init.x : cx - Math.round(w / 2),
18370
- y: typeof _optionalChain([init, 'optionalAccess', _594 => _594.y]) === "number" ? init.y : cy - Math.round(h / 2),
18371
- width: typeof _optionalChain([init, 'optionalAccess', _595 => _595.width]) === "number" ? init.width : w,
18372
- height: typeof _optionalChain([init, 'optionalAccess', _596 => _596.height]) === "number" ? init.height : h
18452
+ x: typeof _optionalChain([init, 'optionalAccess', _594 => _594.x]) === "number" ? init.x : cx - Math.round(w / 2),
18453
+ y: typeof _optionalChain([init, 'optionalAccess', _595 => _595.y]) === "number" ? init.y : cy - Math.round(h / 2),
18454
+ width: typeof _optionalChain([init, 'optionalAccess', _596 => _596.width]) === "number" ? init.width : w,
18455
+ height: typeof _optionalChain([init, 'optionalAccess', _597 => _597.height]) === "number" ? init.height : h
18373
18456
  },
18374
18457
  name: "Rectangle",
18375
18458
  ...init
@@ -18384,10 +18467,10 @@ async function addLayerOfKind(controller, id, init) {
18384
18467
  return controller.addShapeLayer({
18385
18468
  shape: {
18386
18469
  kind: "ellipse",
18387
- x: typeof _optionalChain([init, 'optionalAccess', _597 => _597.x]) === "number" ? init.x : cx - Math.round(w / 2),
18388
- y: typeof _optionalChain([init, 'optionalAccess', _598 => _598.y]) === "number" ? init.y : cy - Math.round(h / 2),
18389
- width: typeof _optionalChain([init, 'optionalAccess', _599 => _599.width]) === "number" ? init.width : w,
18390
- height: typeof _optionalChain([init, 'optionalAccess', _600 => _600.height]) === "number" ? init.height : h
18470
+ x: typeof _optionalChain([init, 'optionalAccess', _598 => _598.x]) === "number" ? init.x : cx - Math.round(w / 2),
18471
+ y: typeof _optionalChain([init, 'optionalAccess', _599 => _599.y]) === "number" ? init.y : cy - Math.round(h / 2),
18472
+ width: typeof _optionalChain([init, 'optionalAccess', _600 => _600.width]) === "number" ? init.width : w,
18473
+ height: typeof _optionalChain([init, 'optionalAccess', _601 => _601.height]) === "number" ? init.height : h
18391
18474
  },
18392
18475
  name: "Ellipse",
18393
18476
  ...init
@@ -18448,18 +18531,18 @@ function layerEffectsPanel(layer) {
18448
18531
  if (!layer) return { ...empty, available: false, reason: "Select a layer to add a layer style." };
18449
18532
  if (layer.type === "adjustment") return { ...empty, available: false, reason: "Adjustment layers cannot have a layer style." };
18450
18533
  const fx = layer.effects;
18451
- const readOnly = Boolean(_optionalChain([layer, 'access', _601 => _601.locks, 'optionalAccess', _602 => _602.all]));
18534
+ const readOnly = Boolean(_optionalChain([layer, 'access', _602 => _602.locks, 'optionalAccess', _603 => _603.all]));
18452
18535
  return {
18453
18536
  available: true,
18454
18537
  readOnly,
18455
18538
  reason: readOnly ? "The layer is locked; unlock it to change its layer style." : void 0,
18456
- enabled: _nullishCoalesce(_optionalChain([fx, 'optionalAccess', _603 => _603.enabled]), () => ( true)),
18457
- scale: _nullishCoalesce(_optionalChain([fx, 'optionalAccess', _604 => _604.scale]), () => ( 1)),
18458
- rows: (_nullishCoalesce(_optionalChain([fx, 'optionalAccess', _605 => _605.items]), () => ( []))).map((e) => ({ id: e.id, kind: e.kind, label: _chunkUOGKSVRQcjs.layerEffectLabel.call(void 0, e.kind), enabled: e.enabled }))
18539
+ enabled: _nullishCoalesce(_optionalChain([fx, 'optionalAccess', _604 => _604.enabled]), () => ( true)),
18540
+ scale: _nullishCoalesce(_optionalChain([fx, 'optionalAccess', _605 => _605.scale]), () => ( 1)),
18541
+ rows: (_nullishCoalesce(_optionalChain([fx, 'optionalAccess', _606 => _606.items]), () => ( []))).map((e) => ({ id: e.id, kind: e.kind, label: _chunkUOGKSVRQcjs.layerEffectLabel.call(void 0, e.kind), enabled: e.enabled }))
18459
18542
  };
18460
18543
  }
18461
18544
  function layerEffectsBadge(layer) {
18462
- if (!_optionalChain([layer, 'access', _606 => _606.effects, 'optionalAccess', _607 => _607.items, 'access', _608 => _608.length])) return null;
18545
+ if (!_optionalChain([layer, 'access', _607 => _607.effects, 'optionalAccess', _608 => _608.items, 'access', _609 => _609.length])) return null;
18463
18546
  return _chunkUOGKSVRQcjs.hasActiveEffects.call(void 0, layer.effects) ? "on" : "off";
18464
18547
  }
18465
18548
  var LAYER_EFFECT_MENU = _chunkUOGKSVRQcjs.LAYER_EFFECT_KINDS.map((kind) => ({ kind, label: _chunkUOGKSVRQcjs.layerEffectLabel.call(void 0, kind) }));
@@ -18504,8 +18587,8 @@ function fillControls(f, allowPattern, patterns) {
18504
18587
  }
18505
18588
  function gradientControls(prefix, g) {
18506
18589
  return [
18507
- { key: `${prefix}.stops.0.color`, label: "Start colour", type: "color", value: _nullishCoalesce(_optionalChain([g, 'access', _609 => _609.stops, 'access', _610 => _610[0], 'optionalAccess', _611 => _611.color]), () => ( "#000000")) },
18508
- { key: `${prefix}.stops.last.color`, label: "End colour", type: "color", value: _nullishCoalesce(_optionalChain([g, 'access', _612 => _612.stops, 'access', _613 => _613[g.stops.length - 1], 'optionalAccess', _614 => _614.color]), () => ( "#ffffff")) },
18590
+ { key: `${prefix}.stops.0.color`, label: "Start colour", type: "color", value: _nullishCoalesce(_optionalChain([g, 'access', _610 => _610.stops, 'access', _611 => _611[0], 'optionalAccess', _612 => _612.color]), () => ( "#000000")) },
18591
+ { key: `${prefix}.stops.last.color`, label: "End colour", type: "color", value: _nullishCoalesce(_optionalChain([g, 'access', _613 => _613.stops, 'access', _614 => _614[g.stops.length - 1], 'optionalAccess', _615 => _615.color]), () => ( "#ffffff")) },
18509
18592
  { key: `${prefix}.style`, label: "Style", type: "select", value: g.style, options: opt(["linear", "Linear"], ["radial", "Radial"], ["angle", "Angle"], ["reflected", "Reflected"], ["diamond", "Diamond"]) },
18510
18593
  { key: `${prefix}.angle`, label: "Angle", type: "range", min: -180, max: 180, step: 1, value: g.angle, unit: "\xB0" },
18511
18594
  { key: `${prefix}.scale`, label: "Scale", type: "range", min: 0.1, max: 1.5, step: 0.01, value: g.scale, percent: true, unit: "%" },
@@ -18597,19 +18680,19 @@ function layerEffectControls(e, patterns = []) {
18597
18680
  }
18598
18681
  function fillOfType(current, type, patterns) {
18599
18682
  if (type === "gradient") return { type: "gradient", gradient: _chunkUOGKSVRQcjs.defaultEffectGradient.call(void 0, ) };
18600
- if (type === "pattern") return { type: "pattern", patternId: _nullishCoalesce(_optionalChain([patterns, 'access', _615 => _615[0], 'optionalAccess', _616 => _616.id]), () => ( "checker")), scale: 1 };
18683
+ if (type === "pattern") return { type: "pattern", patternId: _nullishCoalesce(_optionalChain([patterns, 'access', _616 => _616[0], 'optionalAccess', _617 => _617.id]), () => ( "checker")), scale: 1 };
18601
18684
  return { type: "color", color: current.type === "color" ? current.color : "#000000" };
18602
18685
  }
18603
18686
  function effectControlChange(effect, key, value, patterns = []) {
18604
18687
  const [top, ...rest] = key.split(".");
18605
18688
  if (top === "fill" && rest[0] === "type") return { fill: fillOfType(effect.fill, String(value), patterns) };
18606
18689
  if (top === "patternId" && !rest.length) {
18607
- const name = _optionalChain([patternOptions, 'call', _617 => _617(patterns), 'access', _618 => _618.find, 'call', _619 => _619((o) => o.value === value), 'optionalAccess', _620 => _620.label]);
18690
+ const name = _optionalChain([patternOptions, 'call', _618 => _618(patterns), 'access', _619 => _619.find, 'call', _620 => _620((o) => o.value === value), 'optionalAccess', _621 => _621.label]);
18608
18691
  return name ? { patternId: value, name } : { patternId: value };
18609
18692
  }
18610
18693
  if (!rest.length) return { [top]: value };
18611
18694
  if (top === "fill" && rest[0] === "patternId") {
18612
- const name = _optionalChain([patternOptions, 'call', _621 => _621(patterns), 'access', _622 => _622.find, 'call', _623 => _623((o) => o.value === value), 'optionalAccess', _624 => _624.label]);
18695
+ const name = _optionalChain([patternOptions, 'call', _622 => _622(patterns), 'access', _623 => _623.find, 'call', _624 => _624((o) => o.value === value), 'optionalAccess', _625 => _625.label]);
18613
18696
  return { fill: { ...effect.fill, patternId: value, ...name ? { name } : {} } };
18614
18697
  }
18615
18698
  return { [top]: setPath(getPath(effect, top), rest, value) };
@@ -18636,7 +18719,7 @@ function colorPanelView(controller) {
18636
18719
  profileName: profile.name,
18637
18720
  workingSpace: profile.builtin,
18638
18721
  mode: profile.mode,
18639
- cmykProfileName: _nullishCoalesce(_optionalChain([profile, 'access', _625 => _625.cmykProfile, 'optionalAccess', _626 => _626.name]), () => ( null)),
18722
+ cmykProfileName: _nullishCoalesce(_optionalChain([profile, 'access', _626 => _626.cmykProfile, 'optionalAccess', _627 => _627.name]), () => ( null)),
18640
18723
  proof: proof ? { id: _nullishCoalesce(proof.profile.builtin, () => ( null)), name: proof.profile.name, intent: proof.intent, simulatePaper: proof.simulatePaper, gamutWarning: proof.gamutWarning, bpc: proof.bpc } : null
18641
18724
  };
18642
18725
  }
@@ -18819,32 +18902,32 @@ function boxFrameHit(overlay, p, tolerance, band) {
18819
18902
  return null;
18820
18903
  }
18821
18904
  var FreeTransformTool = (_class16 = class {
18822
- constructor(controller, options = {}) {;_class16.prototype.__init130.call(this);_class16.prototype.__init131.call(this);_class16.prototype.__init132.call(this);_class16.prototype.__init133.call(this);_class16.prototype.__init134.call(this);_class16.prototype.__init135.call(this);_class16.prototype.__init136.call(this);_class16.prototype.__init137.call(this);_class16.prototype.__init138.call(this);_class16.prototype.__init139.call(this);_class16.prototype.__init140.call(this);_class16.prototype.__init141.call(this);_class16.prototype.__init142.call(this);_class16.prototype.__init143.call(this);
18905
+ constructor(controller, options = {}) {;_class16.prototype.__init131.call(this);_class16.prototype.__init132.call(this);_class16.prototype.__init133.call(this);_class16.prototype.__init134.call(this);_class16.prototype.__init135.call(this);_class16.prototype.__init136.call(this);_class16.prototype.__init137.call(this);_class16.prototype.__init138.call(this);_class16.prototype.__init139.call(this);_class16.prototype.__init140.call(this);_class16.prototype.__init141.call(this);_class16.prototype.__init142.call(this);_class16.prototype.__init143.call(this);_class16.prototype.__init144.call(this);
18823
18906
  this.controller = controller;
18824
18907
  this.options = options;
18825
18908
  }
18826
18909
 
18827
18910
 
18828
- __init130() {this.sessionRef = null}
18829
- __init131() {this.modeValue = "scale"}
18911
+ __init131() {this.sessionRef = null}
18912
+ __init132() {this.modeValue = "scale"}
18830
18913
  /** The reference point in the untransformed frame's space (follows the transform). */
18831
- __init132() {this.refBox = { x: 0, y: 0 }}
18832
- __init133() {this.corners = null}
18833
- __init134() {this.drag = null}
18914
+ __init133() {this.refBox = { x: 0, y: 0 }}
18915
+ __init134() {this.corners = null}
18916
+ __init135() {this.drag = null}
18834
18917
  /** The warp mesh in the frame's own space (null: no warp). */
18835
- __init135() {this.mesh = null}
18836
- __init136() {this.warpSettings = { style: "custom", bend: 50, horizontal: 0, vertical: 0, orientation: "horizontal", columns: 1, rows: 1 }}
18837
- __init137() {this.pending = false}
18838
- __init138() {this.viewScale = 1}
18918
+ __init136() {this.mesh = null}
18919
+ __init137() {this.warpSettings = { style: "custom", bend: 50, horizontal: 0, vertical: 0, orientation: "horizontal", columns: 1, rows: 1 }}
18920
+ __init138() {this.pending = false}
18921
+ __init139() {this.viewScale = 1}
18839
18922
 
18840
18923
  /** Values typed into the options bar since the last drag (V skew is not recovered from the shape). */
18841
- __init139() {this.typed = {}}
18924
+ __init140() {this.typed = {}}
18842
18925
  /** Width and height scale together when typed (the chain icon). */
18843
- __init140() {this.proportional = true}
18844
- __init141() {this.error = null}
18845
- __init142() {this.lastResult = null}
18926
+ __init141() {this.proportional = true}
18927
+ __init142() {this.error = null}
18928
+ __init143() {this.lastResult = null}
18846
18929
  get active() {
18847
- return Boolean(_optionalChain([this, 'access', _627 => _627.sessionRef, 'optionalAccess', _628 => _628.isOpen]));
18930
+ return Boolean(_optionalChain([this, 'access', _628 => _628.sessionRef, 'optionalAccess', _629 => _629.isOpen]));
18848
18931
  }
18849
18932
  get session() {
18850
18933
  return this.active ? this.sessionRef : null;
@@ -18853,7 +18936,7 @@ var FreeTransformTool = (_class16 = class {
18853
18936
  return this.modeValue;
18854
18937
  }
18855
18938
  get interpolation() {
18856
- return _nullishCoalesce(_optionalChain([this, 'access', _629 => _629.sessionRef, 'optionalAccess', _630 => _630.interpolation]), () => ( "bicubic"));
18939
+ return _nullishCoalesce(_optionalChain([this, 'access', _630 => _630.sessionRef, 'optionalAccess', _631 => _631.interpolation]), () => ( "bicubic"));
18857
18940
  }
18858
18941
  /** Whether the open transform has changed anything yet (a commit would add an undo step). */
18859
18942
  get modified() {
@@ -18863,7 +18946,7 @@ var FreeTransformTool = (_class16 = class {
18863
18946
  const start = s.startGeometry.corners;
18864
18947
  return this.corners.some((p, i) => p.x !== start[i].x || p.y !== start[i].y);
18865
18948
  }
18866
- __init143() {this.listeners = /* @__PURE__ */ new Set()}
18949
+ __init144() {this.listeners = /* @__PURE__ */ new Set()}
18867
18950
  /** Calls `listener` whenever the overlay, readout, mode or error changes. Returns the unsubscribe. */
18868
18951
  subscribe(listener) {
18869
18952
  this.listeners.add(listener);
@@ -18872,7 +18955,7 @@ var FreeTransformTool = (_class16 = class {
18872
18955
  };
18873
18956
  }
18874
18957
  changed() {
18875
- _optionalChain([this, 'access', _631 => _631.options, 'access', _632 => _632.onChange, 'optionalCall', _633 => _633()]);
18958
+ _optionalChain([this, 'access', _632 => _632.options, 'access', _633 => _633.onChange, 'optionalCall', _634 => _634()]);
18876
18959
  for (const l of this.listeners) l();
18877
18960
  }
18878
18961
  /** Opens a Free Transform (default: the selected pixels of the active layer, or the whole layer). Returns an error message or `null`. */
@@ -19265,7 +19348,7 @@ var FreeTransformTool = (_class16 = class {
19265
19348
  }
19266
19349
  /** Abandons the transform and restores everything. */
19267
19350
  cancel() {
19268
- _optionalChain([this, 'access', _634 => _634.sessionRef, 'optionalAccess', _635 => _635.cancel, 'call', _636 => _636()]);
19351
+ _optionalChain([this, 'access', _635 => _635.sessionRef, 'optionalAccess', _636 => _636.cancel, 'call', _637 => _637()]);
19269
19352
  this.sessionRef = null;
19270
19353
  this.corners = null;
19271
19354
  this.mesh = null;
@@ -19321,7 +19404,7 @@ function imageLayerAppliedEffects(layer) {
19321
19404
  const ref = (r) => ({ effect: r.effect, ...r.name ? { name: r.name } : {}, ...r.provider ? { provider: r.provider } : {} });
19322
19405
  if (layer.type === "pixel" && layer.generator) out.push({ id: "generator", ...ref(layer.generator), role: "effect layer", enabled: true, values: layer.generator.values, ...layer.generator.time ? { time: layer.generator.time } : {}, ...layer.generator.animate ? { animate: layer.generator.animate } : {} });
19323
19406
  if (layer.type === "smart")
19324
- (_nullishCoalesce(_optionalChain([layer, 'access', _637 => _637.smartFilters, 'optionalAccess', _638 => _638.filters]), () => ( []))).forEach((f, index) => {
19407
+ (_nullishCoalesce(_optionalChain([layer, 'access', _638 => _638.smartFilters, 'optionalAccess', _639 => _639.filters]), () => ( []))).forEach((f, index) => {
19325
19408
  if (f.kind === "effect") out.push({ id: f.id, ...ref(f), role: "smart filter", enabled: f.enabled && layer.smartFilters.enabled, opacity: f.opacity, blend: f.blend, values: f.values, index });
19326
19409
  });
19327
19410
  return out;
@@ -19473,7 +19556,7 @@ var OTHER_TOOL_LABELS = {
19473
19556
  watermark: "Watermark"
19474
19557
  };
19475
19558
  function imageToolLabel(tool) {
19476
- return _nullishCoalesce(_nullishCoalesce(_optionalChain([PAINT_TOOLS, 'access', _639 => _639.find, 'call', _640 => _640((t) => t.id === tool), 'optionalAccess', _641 => _641.label]), () => ( OTHER_TOOL_LABELS[tool])), () => ( tool));
19559
+ return _nullishCoalesce(_nullishCoalesce(_optionalChain([PAINT_TOOLS, 'access', _640 => _640.find, 'call', _641 => _641((t) => t.id === tool), 'optionalAccess', _642 => _642.label]), () => ( OTHER_TOOL_LABELS[tool])), () => ( tool));
19477
19560
  }
19478
19561
  var IMAGE_TOOL_SHORTCUTS = {
19479
19562
  ...Object.fromEntries(PAINT_TOOLS.filter((t) => t.shortcut).map((t) => [t.id, t.shortcut])),