ag-psd 34.2.2 → 34.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.v8-cache/v26.13.0-x64-310b2ce3/4511bacf +0 -0
  2. package/.v8-cache/v26.13.0-x64-310b2ce3/71df9cb3 +0 -0
  3. package/.v8-cache/v26.13.0-x64-310b2ce3/7ea06cea +0 -0
  4. package/.v8-cache/v26.13.0-x64-310b2ce3/932f0770 +0 -0
  5. package/.v8-cache/v26.13.0-x64-310b2ce3/acc36e66 +0 -0
  6. package/.v8-cache/v26.13.0-x64-310b2ce3/b3c2fab7 +0 -0
  7. package/.v8-cache/v26.13.0-x64-310b2ce3/dc86f000 +0 -0
  8. package/.v8-cache/v26.13.0-x64-310b2ce3/e6735171 +0 -0
  9. package/CHANGELOG.md +4 -0
  10. package/README.md +22 -3
  11. package/dist/abr.js +5 -4
  12. package/dist/abr.js.map +1 -1
  13. package/dist/additionalInfo.js +1 -1
  14. package/dist/additionalInfo.js.map +1 -1
  15. package/dist/bundle.js +30 -18
  16. package/dist/descriptor.js +6 -6
  17. package/dist/descriptor.js.map +1 -1
  18. package/dist/helpers.d.ts +4 -0
  19. package/dist/helpers.js +11 -0
  20. package/dist/helpers.js.map +1 -1
  21. package/dist/imageResources.js +1 -1
  22. package/dist/imageResources.js.map +1 -1
  23. package/dist/text.js +5 -5
  24. package/dist/text.js.map +1 -1
  25. package/dist-es/abr.js +5 -4
  26. package/dist-es/abr.js.map +1 -1
  27. package/dist-es/additionalInfo.js +1 -1
  28. package/dist-es/additionalInfo.js.map +1 -1
  29. package/dist-es/descriptor.js +6 -6
  30. package/dist-es/descriptor.js.map +1 -1
  31. package/dist-es/helpers.d.ts +4 -0
  32. package/dist-es/helpers.js +11 -0
  33. package/dist-es/helpers.js.map +1 -1
  34. package/dist-es/imageResources.js +1 -1
  35. package/dist-es/imageResources.js.map +1 -1
  36. package/dist-es/text.js +5 -5
  37. package/dist-es/text.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/abr.ts +5 -4
  40. package/src/additionalInfo.ts +2 -2
  41. package/src/descriptor.ts +7 -7
  42. package/src/helpers.ts +11 -0
  43. package/src/imageResources.ts +2 -2
  44. package/src/text.ts +5 -5
package/dist/bundle.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.readAbr = readAbr;
5
5
  const descriptor_1 = require("./descriptor");
6
+ const helpers_1 = require("./helpers");
6
7
  const psdReader_1 = require("./psdReader");
7
8
  const dynamicsControl = ['off', 'fade', 'pen pressure', 'pen tilt', 'stylus wheel', 'initial direction', 'direction', 'initial rotation', 'rotation'];
8
9
  const dynamicBrushShapeShapes = ['round point', 'round blunt', 'round curve', 'round angle', 'round fan', 'flat point', 'flat blunt', 'flat curve', 'flat angle', 'flat fan'];
@@ -20,7 +21,7 @@ const toBrushType = new Map([
20
21
  ]);
21
22
  function parseDynamics(desc) {
22
23
  return {
23
- control: dynamicsControl[desc.bVTy],
24
+ control: (0, helpers_1.arrayItem)(dynamicsControl, desc.bVTy),
24
25
  steps: desc.fStp,
25
26
  jitter: (0, descriptor_1.parsePercent)(desc.jitter),
26
27
  minimum: (0, descriptor_1.parsePercent)(desc['Mnm ']),
@@ -58,7 +59,7 @@ function parseBrushShape(desc) {
58
59
  case 'dBrush':
59
60
  return {
60
61
  type: 'dynamic',
61
- shape: dynamicBrushShapeShapes[desc['Shp ']],
62
+ shape: (0, helpers_1.arrayItem)(dynamicBrushShapeShapes, desc['Shp ']),
62
63
  angle: (0, descriptor_1.parseAngle)(desc.Angl),
63
64
  size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'),
64
65
  density: (0, descriptor_1.parsePercent)(desc.Dnst),
@@ -73,9 +74,9 @@ function parseBrushShape(desc) {
73
74
  flipY: desc.flipY,
74
75
  };
75
76
  case 'dTips': {
76
- return Object.assign(Object.assign({ type: 'tips', angle: (0, descriptor_1.parseAngle)(desc.Angl), size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'), shape: dynamicBrushShapeShapes[desc['Shp ']], physics: desc.physics, spacing: (0, descriptor_1.parsePercent)(desc.Spcn), spacingOn: desc.Intr, flipX: desc.flipX, flipY: desc.flipY,
77
+ return Object.assign(Object.assign({ type: 'tips', angle: (0, descriptor_1.parseAngle)(desc.Angl), size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'), shape: (0, helpers_1.arrayItem)(dynamicBrushShapeShapes, desc['Shp ']), physics: desc.physics, spacing: (0, descriptor_1.parsePercent)(desc.Spcn), spacingOn: desc.Intr, flipX: desc.flipX, flipY: desc.flipY,
77
78
  // tips:
78
- tipsType: tipsBrushShapeShapes[desc.dtipsType], tipsLengthRatio: (0, descriptor_1.parsePercent)(desc.dtipsLengthRatio), tipsHardness: (0, descriptor_1.parsePercent)(desc.dtipsHardness) }, ((desc.dtipsGridSize && desc.dtipsErodibleTipHeightMap) ? {
79
+ tipsType: (0, helpers_1.arrayItem)(tipsBrushShapeShapes, desc.dtipsType), tipsLengthRatio: (0, descriptor_1.parsePercent)(desc.dtipsLengthRatio), tipsHardness: (0, descriptor_1.parsePercent)(desc.dtipsHardness) }, ((desc.dtipsGridSize && desc.dtipsErodibleTipHeightMap) ? {
79
80
  tipsGridSize: desc.dtipsGridSize,
80
81
  tipsErodibleTipHeightMap: parseHeightmap(desc.dtipsErodibleTipHeightMap),
81
82
  } : {})), {
@@ -507,7 +508,7 @@ function parseBrush(brush) {
507
508
  return b;
508
509
  }
509
510
 
510
- },{"./descriptor":5,"./psdReader":14}],2:[function(require,module,exports){
511
+ },{"./descriptor":5,"./helpers":9,"./psdReader":14}],2:[function(require,module,exports){
511
512
  "use strict";
512
513
  var __rest = (this && this.__rest) || function (s, e) {
513
514
  var t = {};
@@ -3058,7 +3059,7 @@ addHandler('SoLd', target => !!target.placedLayer && !target.placedLayer.externa
3058
3059
  target.placedLayer = {
3059
3060
  id: desc.Idnt,
3060
3061
  placed: desc.placed,
3061
- type: placedLayerTypes[desc.Type],
3062
+ type: (0, helpers_1.arrayItem)(placedLayerTypes, desc.Type),
3062
3063
  pageNumber: desc.PgNm,
3063
3064
  totalPages: desc.totalPages,
3064
3065
  frameStep: (0, descriptor_1.frac)(desc.frameStep),
@@ -5332,7 +5333,7 @@ function getTypeByKey(key, value, root, parent) {
5332
5333
  return 'long';
5333
5334
  }
5334
5335
  else {
5335
- return fieldToType[key];
5336
+ return (0, helpers_1.ownValue)(fieldToType, key);
5336
5337
  }
5337
5338
  }
5338
5339
  function readAsciiStringOrClassId(reader) {
@@ -5389,9 +5390,9 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
5389
5390
  for (const key of keys) {
5390
5391
  let type = getTypeByKey(key, value[key], root, value);
5391
5392
  let childRoot = root;
5392
- let extType = fieldToExtType[key];
5393
+ let extType = (0, helpers_1.ownValue)(fieldToExtType, key);
5393
5394
  if (classId === exports.cameraRawFilterClassID) {
5394
- type = (_a = exports.cameraRawFilterKeyTypes[key]) !== null && _a !== void 0 ? _a : 'long'; // other settings are integer levels
5395
+ type = (_a = (0, helpers_1.ownValue)(exports.cameraRawFilterKeyTypes, key)) !== null && _a !== void 0 ? _a : 'long'; // other settings are integer levels
5395
5396
  childRoot = exports.cameraRawFilterClassID; // lists (curves) contain integer levels
5396
5397
  }
5397
5398
  if (key === 'bounds' && root === 'text') {
@@ -5649,9 +5650,9 @@ function writeOSType(writer, type, value, key, extType, root) {
5649
5650
  throw new Error(`Invalid list value: ${JSON.stringify(value)}, key: ${key}`);
5650
5651
  (0, psdWriter_1.writeInt32)(writer, value.length);
5651
5652
  for (let i = 0; i < value.length; i++) {
5652
- const type = root === exports.cameraRawFilterClassID ? 'long' : ((_a = fieldToArrayType[key]) !== null && _a !== void 0 ? _a : guessOSType(value[i]));
5653
+ const type = root === exports.cameraRawFilterClassID ? 'long' : ((_a = (0, helpers_1.ownValue)(fieldToArrayType, key)) !== null && _a !== void 0 ? _a : guessOSType(value[i]));
5653
5654
  (0, psdWriter_1.writeSignature)(writer, type || 'long');
5654
- writeOSType(writer, type || 'long', value[i], `${key}[]`, fieldToArrayExtType[key], root);
5655
+ writeOSType(writer, type || 'long', value[i], `${key}[]`, (0, helpers_1.ownValue)(fieldToArrayExtType, key), root);
5655
5656
  if (writer.logMissingFeatures && !type)
5656
5657
  writer.log(`Missing descriptor array type for: '${key}' in`, value);
5657
5658
  }
@@ -5727,7 +5728,7 @@ function writeOSType(writer, type, value, key, extType, root) {
5727
5728
  case 'ObAr': { // Object array
5728
5729
  (0, psdWriter_1.writeInt32)(writer, 16); // version
5729
5730
  (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, ''); // name
5730
- const type = ObArTypes[key];
5731
+ const type = (0, helpers_1.ownValue)(ObArTypes, key);
5731
5732
  if (!type)
5732
5733
  throw new Error(`Not implemented ObArType for: ${key}`);
5733
5734
  writeAsciiStringOrClassId(writer, type);
@@ -8328,6 +8329,8 @@ exports.offsetForChannel = offsetForChannel;
8328
8329
  exports.normalizeLabAB = normalizeLabAB;
8329
8330
  exports.denormalizeLabAB = denormalizeLabAB;
8330
8331
  exports.clamp = clamp;
8332
+ exports.arrayItem = arrayItem;
8333
+ exports.ownValue = ownValue;
8331
8334
  exports.hasAlpha = hasAlpha;
8332
8335
  exports.cmykToRgbValues = cmykToRgbValues;
8333
8336
  exports.rgbToCmykValues = rgbToCmykValues;
@@ -8463,6 +8466,15 @@ function denormalizeLabAB(value, scale = 1) {
8463
8466
  function clamp(value, min, max) {
8464
8467
  return value < min ? min : (value > max ? max : value);
8465
8468
  }
8469
+ // index read from a file can be any type (e.g. string '__proto__' or a list coerced to 'length'),
8470
+ // only integer indexes within the array return an item, so inherited properties are never returned
8471
+ function arrayItem(array, index) {
8472
+ return (typeof index === 'number' && Number.isInteger(index) && index >= 0 && index < array.length) ? array[index] : undefined;
8473
+ }
8474
+ // key read from a file can be a name of an inherited property (e.g. 'constructor' or 'toString')
8475
+ function ownValue(dict, key) {
8476
+ return Object.prototype.hasOwnProperty.call(dict, key) ? dict[key] : undefined;
8477
+ }
8466
8478
  function hasAlpha(data) {
8467
8479
  const size = data.width * data.height * 4;
8468
8480
  const max = data.data instanceof Float32Array ? 1 : (data.data instanceof Uint16Array ? 0xffff : 0xff);
@@ -9744,7 +9756,7 @@ target => target.onionSkins !== undefined, (reader, target) => {
9744
9756
  frameSpacing: desc.Spcn,
9745
9757
  minOpacity: desc.minOpacity / 100,
9746
9758
  maxOpacity: desc.maxOpacity / 100,
9747
- blendMode: onionSkinsBlendModes[desc.BlnM] || 'normal',
9759
+ blendMode: (0, helpers_1.arrayItem)(onionSkinsBlendModes, desc.BlnM) || 'normal',
9748
9760
  };
9749
9761
  }, (writer, target) => {
9750
9762
  const onionSkins = target.onionSkins;
@@ -15017,7 +15029,7 @@ function decodeGridInfo(grid) {
15017
15029
  return isDefault ? undefined : result;
15018
15030
  }
15019
15031
  function decodeEngineData(engineData) {
15020
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
15032
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
15021
15033
  // console.log('engineData', require('util').inspect(engineData, false, 99, true));
15022
15034
  const engineDict = engineData.EngineDict;
15023
15035
  const resourceDict = engineData.ResourceDict;
@@ -15037,7 +15049,7 @@ function decodeEngineData(engineData) {
15037
15049
  }
15038
15050
  const result = {
15039
15051
  text,
15040
- antiAlias: (_a = antialias[engineDict.AntiAlias]) !== null && _a !== void 0 ? _a : 'smooth',
15052
+ antiAlias: (_a = (0, helpers_1.arrayItem)(antialias, engineDict.AntiAlias)) !== null && _a !== void 0 ? _a : 'smooth',
15041
15053
  useFractionalGlyphWidths: !!engineDict.UseFractionalGlyphWidths,
15042
15054
  superscriptSize: resourceDict.SuperscriptSize,
15043
15055
  superscriptPosition: resourceDict.SuperscriptPosition,
@@ -15090,9 +15102,9 @@ function decodeEngineData(engineData) {
15090
15102
  // const styleSheetData = styleSheetSet[theNormalStyleSheet].StyleSheetData;
15091
15103
  const styleRun = engineDict.StyleRun;
15092
15104
  // style runs without a font use the font of the normal style sheet
15093
- const normalStyleSheet = (_j = (_g = resourceDict.StyleSheetSet) === null || _g === void 0 ? void 0 : _g[(_h = resourceDict.TheNormalStyleSheet) !== null && _h !== void 0 ? _h : 0]) === null || _j === void 0 ? void 0 : _j.StyleSheetData;
15094
- const normalFontIndex = normalStyleSheet === null || normalStyleSheet === void 0 ? void 0 : normalStyleSheet.Font;
15095
- const normalFont = (_k = (normalFontIndex !== undefined ? fonts[normalFontIndex] : undefined)) !== null && _k !== void 0 ? _k : fonts[0];
15105
+ const styleSheetSet = Array.isArray(resourceDict.StyleSheetSet) ? resourceDict.StyleSheetSet : [];
15106
+ const normalStyleSheet = (_h = (0, helpers_1.arrayItem)(styleSheetSet, (_g = resourceDict.TheNormalStyleSheet) !== null && _g !== void 0 ? _g : 0)) === null || _h === void 0 ? void 0 : _h.StyleSheetData;
15107
+ const normalFont = (_j = (0, helpers_1.arrayItem)(fonts, normalStyleSheet === null || normalStyleSheet === void 0 ? void 0 : normalStyleSheet.Font)) !== null && _j !== void 0 ? _j : fonts[0];
15096
15108
  result.style = {}; // decodeStyle(styleSheetData, fonts);
15097
15109
  result.styleRuns = [];
15098
15110
  for (let i = 0; i < styleRun.RunArray.length; i++) {
@@ -444,7 +444,7 @@ function getTypeByKey(key, value, root, parent) {
444
444
  return 'long';
445
445
  }
446
446
  else {
447
- return fieldToType[key];
447
+ return (0, helpers_1.ownValue)(fieldToType, key);
448
448
  }
449
449
  }
450
450
  function readAsciiStringOrClassId(reader) {
@@ -501,9 +501,9 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
501
501
  for (const key of keys) {
502
502
  let type = getTypeByKey(key, value[key], root, value);
503
503
  let childRoot = root;
504
- let extType = fieldToExtType[key];
504
+ let extType = (0, helpers_1.ownValue)(fieldToExtType, key);
505
505
  if (classId === exports.cameraRawFilterClassID) {
506
- type = (_a = exports.cameraRawFilterKeyTypes[key]) !== null && _a !== void 0 ? _a : 'long'; // other settings are integer levels
506
+ type = (_a = (0, helpers_1.ownValue)(exports.cameraRawFilterKeyTypes, key)) !== null && _a !== void 0 ? _a : 'long'; // other settings are integer levels
507
507
  childRoot = exports.cameraRawFilterClassID; // lists (curves) contain integer levels
508
508
  }
509
509
  if (key === 'bounds' && root === 'text') {
@@ -761,9 +761,9 @@ function writeOSType(writer, type, value, key, extType, root) {
761
761
  throw new Error(`Invalid list value: ${JSON.stringify(value)}, key: ${key}`);
762
762
  (0, psdWriter_1.writeInt32)(writer, value.length);
763
763
  for (let i = 0; i < value.length; i++) {
764
- const type = root === exports.cameraRawFilterClassID ? 'long' : ((_a = fieldToArrayType[key]) !== null && _a !== void 0 ? _a : guessOSType(value[i]));
764
+ const type = root === exports.cameraRawFilterClassID ? 'long' : ((_a = (0, helpers_1.ownValue)(fieldToArrayType, key)) !== null && _a !== void 0 ? _a : guessOSType(value[i]));
765
765
  (0, psdWriter_1.writeSignature)(writer, type || 'long');
766
- writeOSType(writer, type || 'long', value[i], `${key}[]`, fieldToArrayExtType[key], root);
766
+ writeOSType(writer, type || 'long', value[i], `${key}[]`, (0, helpers_1.ownValue)(fieldToArrayExtType, key), root);
767
767
  if (writer.logMissingFeatures && !type)
768
768
  writer.log(`Missing descriptor array type for: '${key}' in`, value);
769
769
  }
@@ -839,7 +839,7 @@ function writeOSType(writer, type, value, key, extType, root) {
839
839
  case 'ObAr': { // Object array
840
840
  (0, psdWriter_1.writeInt32)(writer, 16); // version
841
841
  (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, ''); // name
842
- const type = ObArTypes[key];
842
+ const type = (0, helpers_1.ownValue)(ObArTypes, key);
843
843
  if (!type)
844
844
  throw new Error(`Not implemented ObArType for: ${key}`);
845
845
  writeAsciiStringOrClassId(writer, type);