ag-psd 34.0.0 → 34.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -757,6 +757,8 @@ function readVectorMask(reader, vectorMask, width, height, size) {
757
757
  case 2: // Closed subpath Bezier knot, unlinked
758
758
  case 4: // Open subpath Bezier knot, linked
759
759
  case 5: // Open subpath Bezier knot, unlinked
760
+ if (!path)
761
+ throw new Error('Bezier knot record without subpath length record');
760
762
  path.knots.push({ linked: (selector === 1 || selector === 4), points: readBezierKnot(reader, width, height) });
761
763
  break;
762
764
  case 6: // Path fill rule record
@@ -3258,7 +3260,12 @@ function createLnkHandler(tag) {
3258
3260
  const seconds = (0, psdReader_1.readFloat64)(reader);
3259
3261
  const wholeSeconds = Math.floor(seconds);
3260
3262
  const ms = (seconds - wholeSeconds) * 1000;
3261
- file.time = (new Date(Date.UTC(year, month, day, hour, minute, wholeSeconds, ms))).toISOString();
3263
+ try {
3264
+ file.time = (new Date(Date.UTC(year, month, day, hour, minute, wholeSeconds, ms))).toISOString();
3265
+ }
3266
+ catch (_a) {
3267
+ file.time = (new Date(0)).toISOString(); // invalid date
3268
+ }
3262
3269
  }
3263
3270
  const fileSize = type === 'liFE' ? readLength64(reader) : 0;
3264
3271
  if (type === 'liFA')
@@ -3385,6 +3392,10 @@ addHandlerAlias('lnk3', 'lnk2');
3385
3392
  // unicode names of saved paths (path data is stored in image resources 2000-2998)
3386
3393
  addHandler('pths', target => { var _a; return ((_a = target.imageResources) === null || _a === void 0 ? void 0 : _a.savedPaths) !== undefined; }, (reader, _target, left, psd) => {
3387
3394
  var _a, _b;
3395
+ if (reader.imageResourcesWhitelist && !reader.imageResourcesWhitelist.includes('savedPaths')) {
3396
+ (0, psdReader_1.skipBytes)(reader, left());
3397
+ return;
3398
+ }
3388
3399
  const desc = (0, descriptor_1.readVersionAndDescriptor)(reader, true);
3389
3400
  const imageResources = (_a = psd.imageResources) !== null && _a !== void 0 ? _a : (psd.imageResources = {});
3390
3401
  const savedPaths = (_b = imageResources.savedPaths) !== null && _b !== void 0 ? _b : (imageResources.savedPaths = []);
@@ -4202,7 +4213,7 @@ addHandler('Txt2', hasKey('engineData'), (reader, target, left, psd) => {
4202
4213
  const buffer = (0, base64_js_1.toByteArray)(target.engineData);
4203
4214
  (0, psdWriter_1.writeBytes)(writer, buffer);
4204
4215
  });
4205
- addHandler('FEid', hasKey('filterEffectsMasks'), (reader, target, leftBytes) => {
4216
+ addHandler('FEid', hasKey('filterEffectsMasks'), (reader, target, leftBytes, psd) => {
4206
4217
  const version = (0, psdReader_1.readInt32)(reader);
4207
4218
  if (version < 1 || version > 3)
4208
4219
  throw new Error(`Invalid filterEffects version ${version}`);
@@ -4244,7 +4255,7 @@ addHandler('FEid', hasKey('filterEffectsMasks'), (reader, target, leftBytes) =>
4244
4255
  channels.push(undefined);
4245
4256
  }
4246
4257
  }
4247
- target.filterEffectsMasks.push({ id, top, left, bottom, right, depth, channels });
4258
+ target.filterEffectsMasks.push({ id, top, left, bottom, right, depth, colorMode: psd.colorMode, channels });
4248
4259
  if (reader.offset < end && (0, psdReader_1.readUint8)(reader)) {
4249
4260
  const top = (0, psdReader_1.readInt32)(reader);
4250
4261
  const left = (0, psdReader_1.readInt32)(reader);
@@ -8643,6 +8654,7 @@ function initializeCanvas(createCanvasMethod, createImageDataMethod) {
8643
8654
  "use strict";
8644
8655
  Object.defineProperty(exports, "__esModule", { value: true });
8645
8656
  exports.resourceHandlersMap = exports.resourceHandlers = void 0;
8657
+ exports.shouldReadResource = shouldReadResource;
8646
8658
  const base64_js_1 = require("base64-js");
8647
8659
  const additionalInfo_1 = require("./additionalInfo");
8648
8660
  const psdReader_1 = require("./psdReader");
@@ -8652,13 +8664,36 @@ const utf8_1 = require("./utf8");
8652
8664
  const descriptor_1 = require("./descriptor");
8653
8665
  exports.resourceHandlers = [];
8654
8666
  exports.resourceHandlersMap = {};
8667
+ // fields accessed by `has` function, these are the fields that writer stores in the resource
8668
+ function fieldsCheckedBy(has) {
8669
+ const fields = [];
8670
+ const target = new Proxy({}, {
8671
+ get(_, field) {
8672
+ if (typeof field === 'string' && !fields.includes(field))
8673
+ fields.push(field);
8674
+ return undefined;
8675
+ },
8676
+ });
8677
+ try {
8678
+ has(target);
8679
+ }
8680
+ catch (_a) { }
8681
+ return fields;
8682
+ }
8655
8683
  function addHandler(key, has, read, write, options = {}) {
8656
- var _a;
8657
- const handler = { key, keyCount: (_a = options.keyCount) !== null && _a !== void 0 ? _a : 1, has, read, write, name: options.name };
8684
+ var _a, _b;
8685
+ const fields = (_a = options.fields) !== null && _a !== void 0 ? _a : fieldsCheckedBy(has);
8686
+ const handler = { key, keyCount: (_b = options.keyCount) !== null && _b !== void 0 ? _b : 1, has, read, write, name: options.name, fields };
8658
8687
  exports.resourceHandlers.push(handler);
8659
8688
  for (let i = 0; i < handler.keyCount; i++)
8660
8689
  exports.resourceHandlersMap[handler.key + i] = handler;
8661
8690
  }
8691
+ // resources used when reading layers and composite image, they're always read
8692
+ const requiredFields = ['layersGroup', 'layerGroupsEnabledId', 'alphaChannelNames', 'transparencyIndex'];
8693
+ // returns false if resource should be skipped because none of its fields are listed in `imageResourcesWhitelist` read option
8694
+ function shouldReadResource(handler, whitelist) {
8695
+ return !whitelist || handler.fields.some(field => whitelist.includes(field) || requiredFields.includes(field));
8696
+ }
8662
8697
  const LOG_MOCK_HANDLERS = false;
8663
8698
  const RESOLUTION_UNITS = [undefined, 'PPI', 'PPCM'];
8664
8699
  const MEASUREMENT_UNITS = [undefined, 'Inches', 'Centimeters', 'Points', 'Picas', 'Columns'];
@@ -8989,7 +9024,7 @@ addHandler(1007, // Display info (obsolete, replaced by 1077), written back as 1
8989
9024
  // 1077 resource has more precise data and is used if present
8990
9025
  if (!target.alphaChannelDisplayInfo)
8991
9026
  target.alphaChannelDisplayInfo = info;
8992
- }, () => { });
9027
+ }, () => { }, { fields: ['alphaChannelDisplayInfo'] });
8993
9028
  addHandler(1077, // Display info (alpha and spot channels)
8994
9029
  // Display info (alpha and spot channels)
8995
9030
  target => target.alphaChannelDisplayInfo !== undefined, (reader, target, left) => {
@@ -9591,6 +9626,7 @@ const sliceAlignments = ['default'];
9591
9626
  addHandler(1050, // Slices
9592
9627
  // Slices
9593
9628
  target => target.slices ? target.slices.length : 0, (reader, target, leftBytes) => {
9629
+ var _a;
9594
9630
  const version = (0, psdReader_1.readUint32)(reader);
9595
9631
  if (version === 6) {
9596
9632
  if (!target.slices)
@@ -9657,7 +9693,7 @@ target => target.slices ? target.slices.length : 0, (reader, target, leftBytes)
9657
9693
  if (!target.slices)
9658
9694
  target.slices = [];
9659
9695
  target.slices.push({
9660
- groupName: desc.baseName,
9696
+ groupName: (_a = desc.baseName) !== null && _a !== void 0 ? _a : '',
9661
9697
  bounds: boundsFromBounds(desc.bounds),
9662
9698
  slices: desc.slices.map(s => (Object.assign(Object.assign({}, (s['Nm '] ? { name: s['Nm '] } : {})), { id: s.sliceID, groupId: s.groupID, associatedLayerId: 0, origin: descriptor_1.ESliceOrigin.decode(s.origin), type: descriptor_1.ESliceType.decode(s.Type), bounds: boundsFromBounds(s.bounds), url: s.url, target: s.null, message: s.Msge, altTag: s.altTag, cellTextIsHTML: s.cellTextIsHTML, cellText: s.cellText, horizontalAlignment: descriptor_1.ESliceHorzAlign.decode(s.horzAlign), verticalAlignment: descriptor_1.ESliceVertAlign.decode(s.vertAlign), backgroundColorType: descriptor_1.ESliceBGColorType.decode(s.bgColorType), backgroundColor: s.bgColor ? { r: s.bgColor['Rd '], g: s.bgColor['Grn '], b: s.bgColor['Bl '], a: s.bgColor.alpha } : { r: 0, g: 0, b: 0, a: 0 }, topOutset: s.topOutset || 0, leftOutset: s.leftOutset || 0, bottomOutset: s.bottomOutset || 0, rightOutset: s.rightOutset || 0 }))),
9663
9699
  });
@@ -10172,7 +10208,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10172
10208
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
10173
10209
  };
10174
10210
  Object.defineProperty(exports, "__esModule", { value: true });
10175
- exports.getCompositeCanvas = exports.getCompositeImageData = exports.getLayerRealMaskCanvas = exports.getLayerMaskCanvas = exports.getLayerCanvas = exports.getLayerRealMaskImageData = exports.getLayerMaskImageData = exports.getLayerImageData = exports.decodeLayerPixels = exports.byteArrayToBase64 = exports.initializeCanvas = void 0;
10211
+ exports.getFilterEffectsMaskExtraCanvas = exports.getFilterEffectsMaskCanvas = exports.getFilterEffectsMaskExtraImageData = exports.getFilterEffectsMaskImageData = exports.getCompositeCanvas = exports.getCompositeImageData = exports.getLayerRealMaskCanvas = exports.getLayerMaskCanvas = exports.getLayerCanvas = exports.getLayerRealMaskImageData = exports.getLayerMaskImageData = exports.getLayerImageData = exports.decodeLayerPixels = exports.byteArrayToBase64 = exports.initializeCanvas = void 0;
10176
10212
  exports.readPsd = readPsd;
10177
10213
  exports.writePsd = writePsd;
10178
10214
  exports.writePsdUint8Array = writePsdUint8Array;
@@ -10188,6 +10224,10 @@ Object.defineProperty(exports, "getLayerMaskCanvas", { enumerable: true, get: fu
10188
10224
  Object.defineProperty(exports, "getLayerRealMaskCanvas", { enumerable: true, get: function () { return psdReader_1.getLayerRealMaskCanvas; } });
10189
10225
  Object.defineProperty(exports, "getCompositeImageData", { enumerable: true, get: function () { return psdReader_1.getCompositeImageData; } });
10190
10226
  Object.defineProperty(exports, "getCompositeCanvas", { enumerable: true, get: function () { return psdReader_1.getCompositeCanvas; } });
10227
+ Object.defineProperty(exports, "getFilterEffectsMaskImageData", { enumerable: true, get: function () { return psdReader_1.getFilterEffectsMaskImageData; } });
10228
+ Object.defineProperty(exports, "getFilterEffectsMaskExtraImageData", { enumerable: true, get: function () { return psdReader_1.getFilterEffectsMaskExtraImageData; } });
10229
+ Object.defineProperty(exports, "getFilterEffectsMaskCanvas", { enumerable: true, get: function () { return psdReader_1.getFilterEffectsMaskCanvas; } });
10230
+ Object.defineProperty(exports, "getFilterEffectsMaskExtraCanvas", { enumerable: true, get: function () { return psdReader_1.getFilterEffectsMaskExtraCanvas; } });
10191
10231
  const base64_js_1 = require("base64-js");
10192
10232
  __exportStar(require("./abr"), exports);
10193
10233
  __exportStar(require("./csh"), exports);
@@ -11377,6 +11417,10 @@ exports.getLayerRealMaskImageData = getLayerRealMaskImageData;
11377
11417
  exports.getLayerCanvas = getLayerCanvas;
11378
11418
  exports.getLayerMaskCanvas = getLayerMaskCanvas;
11379
11419
  exports.getLayerRealMaskCanvas = getLayerRealMaskCanvas;
11420
+ exports.getFilterEffectsMaskImageData = getFilterEffectsMaskImageData;
11421
+ exports.getFilterEffectsMaskExtraImageData = getFilterEffectsMaskExtraImageData;
11422
+ exports.getFilterEffectsMaskCanvas = getFilterEffectsMaskCanvas;
11423
+ exports.getFilterEffectsMaskExtraCanvas = getFilterEffectsMaskExtraCanvas;
11380
11424
  exports.decodeLayerPixels = decodeLayerPixels;
11381
11425
  exports.readGlobalLayerMaskInfo = readGlobalLayerMaskInfo;
11382
11426
  exports.readAdditionalLayerInfo = readAdditionalLayerInfo;
@@ -11492,6 +11536,9 @@ function readFixedPointPath32(reader) {
11492
11536
  }
11493
11537
  // NOTE: returned array may alias the reader's underlying buffer, never write into it
11494
11538
  function readBytes(reader, length) {
11539
+ // negative length comes from sizes computed from malformed data (e.g. section shorter than its header)
11540
+ if (!(length >= 0))
11541
+ throw new Error(`Invalid length: ${length}`);
11495
11542
  const start = reader.offset;
11496
11543
  const viewLength = reader.view.byteLength;
11497
11544
  reader.offset += length;
@@ -11689,16 +11736,21 @@ function readPsd(reader, readOptions = {}) {
11689
11736
  skipBytes(reader, (nameLength + 1) % 2); // pad to even size
11690
11737
  readSection(reader, 2, left => {
11691
11738
  const handler = imageResources_1.resourceHandlersMap[id];
11692
- const skip = id === 1036 && !!reader.skipThumbnail;
11693
- if (handler && !skip) {
11694
- try {
11695
- handler.read(reader, imageResources, left, { signature, id, name, width, height });
11696
- }
11697
- catch (e) {
11698
- if (reader.throwForMissingFeatures)
11699
- throw e;
11739
+ if (handler) {
11740
+ const skip = (id === 1036 && !!reader.skipThumbnail) || !(0, imageResources_1.shouldReadResource)(handler, reader.imageResourcesWhitelist);
11741
+ if (skip) {
11700
11742
  skipBytes(reader, left());
11701
11743
  }
11744
+ else {
11745
+ try {
11746
+ handler.read(reader, imageResources, left, { signature, id, name, width, height });
11747
+ }
11748
+ catch (e) {
11749
+ if (reader.throwForMissingFeatures)
11750
+ throw e;
11751
+ skipBytes(reader, left());
11752
+ }
11753
+ }
11702
11754
  }
11703
11755
  else {
11704
11756
  reader.logMissingFeatures && reader.log(`Unhandled image resource: ${id} (${left()})`);
@@ -12083,6 +12135,67 @@ function getLayerMaskCanvas(layer) {
12083
12135
  function getLayerRealMaskCanvas(layer) {
12084
12136
  return imageDataToCanvasSafe(getLayerRealMaskImageData(layer));
12085
12137
  }
12138
+ function getFilterEffectsMaskImageData(mask) {
12139
+ const { depth, channels, colorMode = 3 /* ColorMode.RGB */ } = mask;
12140
+ const width = Math.max(0, mask.right - mask.left);
12141
+ const height = Math.max(0, mask.bottom - mask.top);
12142
+ if (!width || !height)
12143
+ return undefined;
12144
+ const cmyk = colorMode === 4 /* ColorMode.CMYK */;
12145
+ if (cmyk && depth !== 8 && depth !== 16)
12146
+ throw new Error('bitsPerChannel not supported');
12147
+ const step = cmyk ? 5 : 4;
12148
+ // channels are color channels, followed by user mask and transparency
12149
+ const transparencyIndex = channels.length - 1;
12150
+ const colorChannels = Math.min(cmyk ? 4 : (colorMode === 1 /* ColorMode.Grayscale */ ? 1 : 3), channels.length - 2);
12151
+ let imageData = createImageDataBitDepth(width, height, depth, step, undefined);
12152
+ for (let i = 0; i < channels.length; i++) {
12153
+ const channel = channels[i];
12154
+ if (!channel)
12155
+ continue;
12156
+ if (i < colorChannels) {
12157
+ readFilterEffectsChannel(channel, imageData, width, height, depth, i, step);
12158
+ }
12159
+ else if (i === transparencyIndex) {
12160
+ readFilterEffectsChannel(channel, imageData, width, height, depth, step - 1, step);
12161
+ }
12162
+ }
12163
+ if (colorMode === 1 /* ColorMode.Grayscale */)
12164
+ setupGrayscale(imageData);
12165
+ if (!channels[transparencyIndex])
12166
+ resetAlpha(imageData, cmyk);
12167
+ if (cmyk) {
12168
+ const cmykData = imageData;
12169
+ imageData = createImageDataBitDepth(cmykData.width, cmykData.height, depth, 4, undefined);
12170
+ cmykToRgb(cmykData, imageData, false);
12171
+ }
12172
+ return imageData;
12173
+ }
12174
+ function getFilterEffectsMaskExtraImageData(mask) {
12175
+ const { extra, depth } = mask;
12176
+ if (!extra)
12177
+ return undefined;
12178
+ const width = Math.max(0, extra.right - extra.left);
12179
+ const height = Math.max(0, extra.bottom - extra.top);
12180
+ if (!width || !height)
12181
+ return undefined;
12182
+ const maskData = createImageDataBitDepth(width, height, depth, 4, undefined);
12183
+ readFilterEffectsChannel(extra, maskData, width, height, depth, 0, 4);
12184
+ setupGrayscale(maskData);
12185
+ resetAlpha(maskData, false);
12186
+ return maskData;
12187
+ }
12188
+ function getFilterEffectsMaskCanvas(mask) {
12189
+ return imageDataToCanvasSafe(getFilterEffectsMaskImageData(mask));
12190
+ }
12191
+ function getFilterEffectsMaskExtraCanvas(mask) {
12192
+ return imageDataToCanvasSafe(getFilterEffectsMaskExtraImageData(mask));
12193
+ }
12194
+ function readFilterEffectsChannel({ compressionMode, data }, pixels, width, height, depth, offset, step) {
12195
+ const reader = createReader(data.buffer, data.byteOffset, data.byteLength);
12196
+ // RLE row lengths are always 4 bytes, same as in PSB files
12197
+ readData(reader, data.byteLength, pixels, compressionMode, width, height, depth, offset, true, step);
12198
+ }
12086
12199
  function imageDataToCanvasSafe(imageData) {
12087
12200
  return imageData && (0, helpers_1.imageDataToCanvas)(imageData);
12088
12201
  }
@@ -12586,11 +12699,11 @@ function decodePredicted(data, width, height) {
12586
12699
  }
12587
12700
  const zipOverflow = new Error('Decompressed data exceeds expected size');
12588
12701
  // inflates data, stopping when output exceeds expected size (protects against zip bombs)
12589
- function inflateLimited(compressed, expectedSize, reader) {
12702
+ function inflateLimited(compressed, expectedSize, reader, raw = false) {
12590
12703
  const output = new Uint8Array(expectedSize);
12591
12704
  let position = 0;
12592
12705
  let overflow = false;
12593
- const inflator = new pako_1.Inflate({ chunkSize: Math.max(1024, Math.min(expectedSize, 0x10000)) });
12706
+ const inflator = new pako_1.Inflate({ chunkSize: Math.max(1024, Math.min(expectedSize, 0x10000)), raw });
12594
12707
  inflator.onData = (chunk) => {
12595
12708
  const data = chunk;
12596
12709
  const count = Math.min(data.length, expectedSize - position);
@@ -12619,6 +12732,12 @@ function inflateLimited(compressed, expectedSize, reader) {
12619
12732
  if (reader)
12620
12733
  warnOrThrow(reader, zipOverflow.message);
12621
12734
  }
12735
+ else if (inflator.err && inflator.msg === 'incorrect data check' && !raw) {
12736
+ // some files have zeroed checksum (filter effects masks written by Photoshop), inflate again skipping zlib header and checksum
12737
+ if (reader)
12738
+ warnOrThrow(reader, `Invalid zip data: ${inflator.msg}`);
12739
+ return inflateLimited(compressed.subarray(2), expectedSize, reader, true);
12740
+ }
12622
12741
  else if (inflator.err) {
12623
12742
  throw new Error(`Invalid zip data: ${inflator.msg}`);
12624
12743
  }
@@ -22,8 +22,10 @@ export interface ResourceHandler {
22
22
  read: (reader: PsdReader, target: InternalImageResources, left: () => number, info: ResourceInfo) => void;
23
23
  write: (writer: PsdWriter, target: InternalImageResources, index: number, document: ResourceDocumentInfo) => void;
24
24
  name?: (target: InternalImageResources, index: number) => string;
25
+ fields: string[];
25
26
  }
26
27
  export declare const resourceHandlers: ResourceHandler[];
27
28
  export declare const resourceHandlersMap: {
28
29
  [key: number]: ResourceHandler;
29
30
  };
31
+ export declare function shouldReadResource(handler: ResourceHandler, whitelist: string[] | undefined): boolean;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resourceHandlersMap = exports.resourceHandlers = void 0;
4
+ exports.shouldReadResource = shouldReadResource;
4
5
  const base64_js_1 = require("base64-js");
5
6
  const additionalInfo_1 = require("./additionalInfo");
6
7
  const psdReader_1 = require("./psdReader");
@@ -10,13 +11,36 @@ const utf8_1 = require("./utf8");
10
11
  const descriptor_1 = require("./descriptor");
11
12
  exports.resourceHandlers = [];
12
13
  exports.resourceHandlersMap = {};
14
+ // fields accessed by `has` function, these are the fields that writer stores in the resource
15
+ function fieldsCheckedBy(has) {
16
+ const fields = [];
17
+ const target = new Proxy({}, {
18
+ get(_, field) {
19
+ if (typeof field === 'string' && !fields.includes(field))
20
+ fields.push(field);
21
+ return undefined;
22
+ },
23
+ });
24
+ try {
25
+ has(target);
26
+ }
27
+ catch (_a) { }
28
+ return fields;
29
+ }
13
30
  function addHandler(key, has, read, write, options = {}) {
14
- var _a;
15
- const handler = { key, keyCount: (_a = options.keyCount) !== null && _a !== void 0 ? _a : 1, has, read, write, name: options.name };
31
+ var _a, _b;
32
+ const fields = (_a = options.fields) !== null && _a !== void 0 ? _a : fieldsCheckedBy(has);
33
+ const handler = { key, keyCount: (_b = options.keyCount) !== null && _b !== void 0 ? _b : 1, has, read, write, name: options.name, fields };
16
34
  exports.resourceHandlers.push(handler);
17
35
  for (let i = 0; i < handler.keyCount; i++)
18
36
  exports.resourceHandlersMap[handler.key + i] = handler;
19
37
  }
38
+ // resources used when reading layers and composite image, they're always read
39
+ const requiredFields = ['layersGroup', 'layerGroupsEnabledId', 'alphaChannelNames', 'transparencyIndex'];
40
+ // returns false if resource should be skipped because none of its fields are listed in `imageResourcesWhitelist` read option
41
+ function shouldReadResource(handler, whitelist) {
42
+ return !whitelist || handler.fields.some(field => whitelist.includes(field) || requiredFields.includes(field));
43
+ }
20
44
  const LOG_MOCK_HANDLERS = false;
21
45
  const RESOLUTION_UNITS = [undefined, 'PPI', 'PPCM'];
22
46
  const MEASUREMENT_UNITS = [undefined, 'Inches', 'Centimeters', 'Points', 'Picas', 'Columns'];
@@ -347,7 +371,7 @@ addHandler(1007, // Display info (obsolete, replaced by 1077), written back as 1
347
371
  // 1077 resource has more precise data and is used if present
348
372
  if (!target.alphaChannelDisplayInfo)
349
373
  target.alphaChannelDisplayInfo = info;
350
- }, () => { });
374
+ }, () => { }, { fields: ['alphaChannelDisplayInfo'] });
351
375
  addHandler(1077, // Display info (alpha and spot channels)
352
376
  // Display info (alpha and spot channels)
353
377
  target => target.alphaChannelDisplayInfo !== undefined, (reader, target, left) => {
@@ -949,6 +973,7 @@ const sliceAlignments = ['default'];
949
973
  addHandler(1050, // Slices
950
974
  // Slices
951
975
  target => target.slices ? target.slices.length : 0, (reader, target, leftBytes) => {
976
+ var _a;
952
977
  const version = (0, psdReader_1.readUint32)(reader);
953
978
  if (version === 6) {
954
979
  if (!target.slices)
@@ -1015,7 +1040,7 @@ target => target.slices ? target.slices.length : 0, (reader, target, leftBytes)
1015
1040
  if (!target.slices)
1016
1041
  target.slices = [];
1017
1042
  target.slices.push({
1018
- groupName: desc.baseName,
1043
+ groupName: (_a = desc.baseName) !== null && _a !== void 0 ? _a : '',
1019
1044
  bounds: boundsFromBounds(desc.bounds),
1020
1045
  slices: desc.slices.map(s => (Object.assign(Object.assign({}, (s['Nm '] ? { name: s['Nm '] } : {})), { id: s.sliceID, groupId: s.groupID, associatedLayerId: 0, origin: descriptor_1.ESliceOrigin.decode(s.origin), type: descriptor_1.ESliceType.decode(s.Type), bounds: boundsFromBounds(s.bounds), url: s.url, target: s.null, message: s.Msge, altTag: s.altTag, cellTextIsHTML: s.cellTextIsHTML, cellText: s.cellText, horizontalAlignment: descriptor_1.ESliceHorzAlign.decode(s.horzAlign), verticalAlignment: descriptor_1.ESliceVertAlign.decode(s.vertAlign), backgroundColorType: descriptor_1.ESliceBGColorType.decode(s.bgColorType), backgroundColor: s.bgColor ? { r: s.bgColor['Rd '], g: s.bgColor['Grn '], b: s.bgColor['Bl '], a: s.bgColor.alpha } : { r: 0, g: 0, b: 0, a: 0 }, topOutset: s.topOutset || 0, leftOutset: s.leftOutset || 0, bottomOutset: s.bottomOutset || 0, rightOutset: s.rightOutset || 0 }))),
1021
1046
  });