ag-psd 17.0.1 → 17.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v17.0.3
4
+ - Added extra error checks and fixed writing PSD without placedLayer.warp field present
5
+
6
+ ## v17.0.2
7
+ - Fixed issues with writing some layer effects
8
+
3
9
  ## v17.0.1
4
10
  - Fixed incorrect reading and writing of slice bounds
5
11
  - Fixed missing bounds and boundingBox fields on `layer.text`
@@ -852,6 +852,9 @@ addHandler('PlLd', hasKey('placedLayer'), function (reader, target, left) {
852
852
  var placed = target.placedLayer;
853
853
  (0, psdWriter_1.writeSignature)(writer, 'plcL');
854
854
  (0, psdWriter_1.writeInt32)(writer, 3); // version
855
+ if (!placed.id || typeof placed.id !== 'string' || !/^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(placed.id)) {
856
+ throw new Error('Placed layer ID must be in a GUID format (example: 20953ddb-9391-11ec-b4f1-c15674f50bc4)');
857
+ }
855
858
  (0, psdWriter_1.writePascalString)(writer, placed.id, 1);
856
859
  (0, psdWriter_1.writeInt32)(writer, 1); // pageNumber
857
860
  (0, psdWriter_1.writeInt32)(writer, 1); // totalPages
@@ -1739,9 +1742,44 @@ addHandler('SoLd', hasKey('placedLayer'), function (reader, target, left) {
1739
1742
  (0, psdWriter_1.writeSignature)(writer, 'soLD');
1740
1743
  (0, psdWriter_1.writeInt32)(writer, 4); // version
1741
1744
  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
+ if (!placed.id || typeof placed.id !== 'string' || !/^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(placed.id)) {
1778
+ throw new Error('Placed layer ID must be in a GUID format (example: 20953ddb-9391-11ec-b4f1-c15674f50bc4)');
1779
+ }
1742
1780
  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,
1743
1781
  // quiltWarp: {} as any,
1744
- warp: encodeWarp(placed.warp || {}), 'Sz ': {
1782
+ warp: encodeWarp(warp || {}), 'Sz ': {
1745
1783
  _name: '',
1746
1784
  _classID: 'Pnt ',
1747
1785
  Wdth: placed.width || 0,
@@ -2009,7 +2047,10 @@ addHandler('lnk2', function (target) { return !!target.linkedFiles && target.lin
2009
2047
  var sizeOffset = writer.offset;
2010
2048
  (0, psdWriter_1.writeSignature)(writer, file.data ? 'liFD' : 'liFA');
2011
2049
  (0, psdWriter_1.writeInt32)(writer, version);
2012
- (0, psdWriter_1.writePascalString)(writer, file.id || '', 1);
2050
+ if (!file.id || typeof file.id !== 'string' || !/^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(file.id)) {
2051
+ throw new Error('Linked file ID must be in a GUID format (example: 20953ddb-9391-11ec-b4f1-c15674f50bc4)');
2052
+ }
2053
+ (0, psdWriter_1.writePascalString)(writer, file.id, 1);
2013
2054
  (0, psdWriter_1.writeUnicodeStringWithPadding)(writer, file.name || '');
2014
2055
  (0, psdWriter_1.writeSignature)(writer, file.type ? "".concat(file.type, " ").substring(0, 4) : ' ');
2015
2056
  (0, psdWriter_1.writeSignature)(writer, file.creator ? "".concat(file.creator, " ").substring(0, 4) : '\0\0\0\0');
@@ -2898,14 +2939,14 @@ addHandler('lfx2', function (target) { return target.effects !== undefined && !h
2898
2939
  if (version !== 0)
2899
2940
  throw new Error("Invalid lfx2 version");
2900
2941
  var desc = (0, descriptor_1.readVersionAndDescriptor)(reader);
2901
- // console.log(require('util').inspect(desc, false, 99, true));
2942
+ // console.log('READ', require('util').inspect(desc, false, 99, true));
2902
2943
  // TODO: don't discard if we got it from lmfx
2903
2944
  // discard if read in 'lrFX' section
2904
2945
  target.effects = (0, descriptor_1.parseEffects)(desc, !!options.logMissingFeatures);
2905
2946
  (0, psdReader_1.skipBytes)(reader, left());
2906
2947
  }, function (writer, target, _, options) {
2907
- var desc = (0, descriptor_1.serializeEffects)(target.effects, !!options.logMissingFeatures, false);
2908
- // console.log(require('util').inspect(desc, false, 99, true));
2948
+ var desc = (0, descriptor_1.serializeEffects)(target.effects, !!options.logMissingFeatures, true);
2949
+ // console.log('WRITE', require('util').inspect(desc, false, 99, true));
2909
2950
  (0, psdWriter_1.writeUint32)(writer, 0); // version
2910
2951
  (0, descriptor_1.writeVersionAndDescriptor)(writer, '', 'null', desc);
2911
2952
  });