ag-psd 17.0.3 → 17.0.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v17.0.4
4
+ - Fixed incorrect parsing of external linked files
5
+ - Fixed incorrect parsing of compositorUsed section when some fields are missing
6
+
7
+ ## v17.0.4
8
+ - Fixed saving smart layers without placedLayer.warp field present for newer versions of photoshop
9
+
3
10
  ## v17.0.3
4
11
  - Added extra error checks and fixed writing PSD without placedLayer.warp field present
5
12
 
@@ -865,9 +865,10 @@ addHandler('PlLd', hasKey('placedLayer'), function (reader, target, left) {
865
865
  for (var i = 0; i < 8; i++)
866
866
  (0, psdWriter_1.writeFloat64)(writer, placed.transform[i]);
867
867
  (0, psdWriter_1.writeInt32)(writer, 0); // warp version
868
- var isQuilt = placed.warp && isQuiltWarp(placed.warp);
868
+ var warp = getWarpFromPlacedLayer(placed);
869
+ var isQuilt = isQuiltWarp(warp);
869
870
  var type = isQuilt ? 'quiltWarp' : 'warp';
870
- (0, descriptor_1.writeVersionAndDescriptor)(writer, '', type, encodeWarp(placed.warp || {}), type);
871
+ (0, descriptor_1.writeVersionAndDescriptor)(writer, '', type, encodeWarp(warp), type);
871
872
  });
872
873
  function uint8ToFloat32(array) {
873
874
  return new Float32Array(array.buffer.slice(array.byteOffset), 0, array.byteLength / 4);
@@ -1691,6 +1692,39 @@ function serializeFilterFXItem(f) {
1691
1692
  }
1692
1693
  }
1693
1694
  // let t: any;
1695
+ function getWarpFromPlacedLayer(placed) {
1696
+ if (placed.warp)
1697
+ return placed.warp;
1698
+ if (!placed.width || !placed.height)
1699
+ throw new Error('You must provide width and height of the linked image in placedLayer');
1700
+ var w = placed.width;
1701
+ var h = placed.height;
1702
+ var x0 = 0, x1 = w / 3, x2 = w * 2 / 3, x3 = w;
1703
+ var y0 = 0, y1 = h / 3, y2 = h * 2 / 3, y3 = h;
1704
+ return {
1705
+ style: 'custom',
1706
+ value: 0,
1707
+ perspective: 0,
1708
+ perspectiveOther: 0,
1709
+ rotate: 'horizontal',
1710
+ bounds: {
1711
+ top: { value: 0, units: 'Pixels' },
1712
+ left: { value: 0, units: 'Pixels' },
1713
+ bottom: { value: h, units: 'Pixels' },
1714
+ right: { value: w, units: 'Pixels' },
1715
+ },
1716
+ uOrder: 4,
1717
+ vOrder: 4,
1718
+ customEnvelopeWarp: {
1719
+ meshPoints: [
1720
+ { x: x0, y: y0 }, { x: x1, y: y0 }, { x: x2, y: y0 }, { x: x3, y: y0 },
1721
+ { x: x0, y: y1 }, { x: x1, y: y1 }, { x: x2, y: y1 }, { x: x3, y: y1 },
1722
+ { x: x0, y: y2 }, { x: x1, y: y2 }, { x: x2, y: y2 }, { x: x3, y: y2 },
1723
+ { x: x0, y: y3 }, { x: x1, y: y3 }, { x: x2, y: y3 }, { x: x3, y: y3 },
1724
+ ],
1725
+ },
1726
+ };
1727
+ }
1694
1728
  addHandler('SoLd', hasKey('placedLayer'), function (reader, target, left) {
1695
1729
  if ((0, psdReader_1.readSignature)(reader) !== 'soLD')
1696
1730
  throw new Error("Invalid SoLd type");
@@ -1742,44 +1776,12 @@ addHandler('SoLd', hasKey('placedLayer'), function (reader, target, left) {
1742
1776
  (0, psdWriter_1.writeSignature)(writer, 'soLD');
1743
1777
  (0, psdWriter_1.writeInt32)(writer, 4); // version
1744
1778
  var placed = target.placedLayer;
1745
- var warp = placed.warp;
1746
- if (!warp) {
1747
- if (!placed.width || !placed.height)
1748
- throw new Error('You must provide width and height of the linked image in placedLayer');
1749
- var w = placed.width;
1750
- var h = placed.height;
1751
- var x0 = 0, x1 = w / 3, x2 = w * 2 / 3, x3 = w;
1752
- var y0 = 0, y1 = h / 3, y2 = h * 2 / 3, y3 = h;
1753
- warp = {
1754
- style: 'custom',
1755
- value: 0,
1756
- perspective: 0,
1757
- perspectiveOther: 0,
1758
- rotate: 'horizontal',
1759
- bounds: {
1760
- top: { value: 0, units: 'Pixels' },
1761
- left: { value: 0, units: 'Pixels' },
1762
- bottom: { value: h, units: 'Pixels' },
1763
- right: { value: w, units: 'Pixels' },
1764
- },
1765
- uOrder: 4,
1766
- vOrder: 4,
1767
- customEnvelopeWarp: {
1768
- meshPoints: [
1769
- { x: x0, y: y0 }, { x: x1, y: y0 }, { x: x2, y: y0 }, { x: x3, y: y0 },
1770
- { x: x0, y: y1 }, { x: x1, y: y1 }, { x: x2, y: y1 }, { x: x3, y: y1 },
1771
- { x: x0, y: y2 }, { x: x1, y: y2 }, { x: x2, y: y2 }, { x: x3, y: y2 },
1772
- { x: x0, y: y3 }, { x: x1, y: y3 }, { x: x2, y: y3 }, { x: x3, y: y3 },
1773
- ],
1774
- },
1775
- };
1776
- }
1777
1779
  if (!placed.id || typeof placed.id !== 'string' || !/^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(placed.id)) {
1778
1780
  throw new Error('Placed layer ID must be in a GUID format (example: 20953ddb-9391-11ec-b4f1-c15674f50bc4)');
1779
1781
  }
1780
1782
  var desc = __assign(__assign({ Idnt: placed.id, placed: (_a = placed.placed) !== null && _a !== void 0 ? _a : placed.id, PgNm: placed.pageNumber || 1, totalPages: placed.totalPages || 1 }, (placed.crop ? { Crop: placed.crop } : {})), { frameStep: placed.frameStep || { numerator: 0, denominator: 600 }, duration: placed.duration || { numerator: 0, denominator: 600 }, frameCount: placed.frameCount || 0, Annt: 16, Type: placedLayerTypes.indexOf(placed.type), Trnf: placed.transform, nonAffineTransform: (_b = placed.nonAffineTransform) !== null && _b !== void 0 ? _b : placed.transform,
1781
1783
  // quiltWarp: {} as any,
1782
- warp: encodeWarp(warp || {}), 'Sz ': {
1784
+ warp: encodeWarp(getWarpFromPlacedLayer(placed)), 'Sz ': {
1783
1785
  _name: '',
1784
1786
  _classID: 'Pnt ',
1785
1787
  Wdth: placed.width || 0,
@@ -1859,6 +1861,42 @@ else {
1859
1861
  }, function (_writer, _target) {
1860
1862
  });
1861
1863
  }
1864
+ /*
1865
+ interface CAIDesc {
1866
+ enab: boolean;
1867
+ generationalGuid: string;
1868
+ }
1869
+
1870
+ addHandler(
1871
+ 'CAI ', // content credentials ? something to do with generative tech
1872
+ () => false,
1873
+ (reader, _target, left) => {
1874
+ const version = readUint32(reader); // 3
1875
+ const desc = readVersionAndDescriptor(reader) as CAIDesc;
1876
+ console.log('CAI', require('util').inspect(desc, false, 99, true));
1877
+ console.log('CAI', { version });
1878
+ console.log('CAI left', readBytes(reader, left())); // 8 bytes left, all zeroes
1879
+ },
1880
+ (_writer, _target) => {
1881
+ },
1882
+ );
1883
+ */
1884
+ /*
1885
+ interface GenIDesc {
1886
+ isUsingGenTech: number;
1887
+ }
1888
+
1889
+ addHandler(
1890
+ 'GenI', // generative tech
1891
+ () => false,
1892
+ (reader, _target, left) => {
1893
+ const desc = readVersionAndDescriptor(reader) as GenIDesc;
1894
+ console.log('GenI', require('util').inspect(desc, false, 99, true));
1895
+ },
1896
+ (_writer, _target) => {
1897
+ },
1898
+ );
1899
+ */
1862
1900
  function readRect(reader) {
1863
1901
  var top = (0, psdReader_1.readInt32)(reader);
1864
1902
  var left = (0, psdReader_1.readInt32)(reader);
@@ -1975,6 +2013,9 @@ addHandler('lnk2', function (target) { return !!target.linkedFiles && target.lin
1975
2013
  var size = readLength64(reader); // size
1976
2014
  var startOffset = reader.offset;
1977
2015
  var type = (0, psdReader_1.readSignature)(reader);
2016
+ // liFD - linked file data
2017
+ // liFE - linked file external
2018
+ // liFA - linked file alias
1978
2019
  var version = (0, psdReader_1.readInt32)(reader);
1979
2020
  var id = (0, psdReader_1.readPascalString)(reader, 1);
1980
2021
  var name_3 = (0, psdReader_1.readUnicodeString)(reader);
@@ -1984,7 +2025,7 @@ addHandler('lnk2', function (target) { return !!target.linkedFiles && target.lin
1984
2025
  var hasFileOpenDescriptor = (0, psdReader_1.readUint8)(reader);
1985
2026
  var fileOpenDescriptor = hasFileOpenDescriptor ? (0, descriptor_1.readVersionAndDescriptor)(reader) : undefined;
1986
2027
  var linkedFileDescriptor = type === 'liFE' ? (0, descriptor_1.readVersionAndDescriptor)(reader) : undefined;
1987
- var file = { id: id, name: name_3, data: undefined };
2028
+ var file = { id: id, name: name_3 };
1988
2029
  if (fileType)
1989
2030
  file.type = fileType;
1990
2031
  if (fileCreator)
@@ -2012,14 +2053,14 @@ addHandler('lnk2', function (target) { return !!target.linkedFiles && target.lin
2012
2053
  if (type === 'liFA')
2013
2054
  (0, psdReader_1.skipBytes)(reader, 8);
2014
2055
  if (type === 'liFD')
2015
- file.data = (0, psdReader_1.readBytes)(reader, dataSize);
2056
+ file.data = (0, psdReader_1.readBytes)(reader, dataSize); // seems to be a typo in docs
2016
2057
  if (version >= 5)
2017
2058
  file.childDocumentID = (0, psdReader_1.readUnicodeString)(reader);
2018
2059
  if (version >= 6)
2019
2060
  file.assetModTime = (0, psdReader_1.readFloat64)(reader);
2020
2061
  if (version >= 7)
2021
2062
  file.assetLockedState = (0, psdReader_1.readUint8)(reader);
2022
- if (type === 'liFE')
2063
+ if (type === 'liFE' && version === 2)
2023
2064
  file.data = (0, psdReader_1.readBytes)(reader, fileSize);
2024
2065
  if (options.skipLinkedFilesData)
2025
2066
  file.data = undefined;
@@ -2960,11 +3001,15 @@ addHandler('cinf', hasKey('compositorUsed'), function (reader, target, left) {
2960
3001
  description: desc.description,
2961
3002
  reason: desc.reason,
2962
3003
  engine: enumValue(desc.Engn),
2963
- enableCompCore: enumValue(desc.enableCompCore),
2964
- enableCompCoreGPU: enumValue(desc.enableCompCoreGPU),
2965
- compCoreSupport: enumValue(desc.compCoreSupport),
2966
- compCoreGPUSupport: enumValue(desc.compCoreGPUSupport),
2967
3004
  };
3005
+ if (desc.enableCompCore)
3006
+ target.compositorUsed.enableCompCore = enumValue(desc.enableCompCore);
3007
+ if (desc.enableCompCoreGPU)
3008
+ target.compositorUsed.enableCompCoreGPU = enumValue(desc.enableCompCoreGPU);
3009
+ if (desc.compCoreSupport)
3010
+ target.compositorUsed.compCoreSupport = enumValue(desc.compCoreSupport);
3011
+ if (desc.compCoreGPUSupport)
3012
+ target.compositorUsed.compCoreGPUSupport = enumValue(desc.compCoreGPUSupport);
2968
3013
  (0, psdReader_1.skipBytes)(reader, left());
2969
3014
  }, function (writer, target) {
2970
3015
  var cinf = target.compositorUsed;
@@ -2974,12 +3019,16 @@ addHandler('cinf', hasKey('compositorUsed'), function (reader, target, left) {
2974
3019
  description: cinf.description,
2975
3020
  reason: cinf.reason,
2976
3021
  Engn: "Engn.".concat(cinf.engine),
2977
- enableCompCore: "enable.".concat(cinf.enableCompCore),
2978
- enableCompCoreGPU: "enable.".concat(cinf.enableCompCoreGPU),
2979
- // enableCompCoreThreads: `enable.feature`, // TESTING
2980
- compCoreSupport: "reason.".concat(cinf.compCoreSupport),
2981
- compCoreGPUSupport: "reason.".concat(cinf.compCoreGPUSupport),
2982
3022
  };
3023
+ if (cinf.enableCompCore)
3024
+ desc.enableCompCore = "enable.".concat(cinf.enableCompCore);
3025
+ if (cinf.enableCompCoreGPU)
3026
+ desc.enableCompCoreGPU = "enable.".concat(cinf.enableCompCoreGPU);
3027
+ // desc.enableCompCoreThreads = `enable.feature`; // TESTING
3028
+ if (cinf.compCoreSupport)
3029
+ desc.compCoreSupport = "reason.".concat(cinf.compCoreSupport);
3030
+ if (cinf.compCoreGPUSupport)
3031
+ desc.compCoreGPUSupport = "reason.".concat(cinf.compCoreGPUSupport);
2983
3032
  (0, descriptor_1.writeVersionAndDescriptor)(writer, '', 'null', desc);
2984
3033
  });
2985
3034
  // extension settings ?, ignore it