ag-psd 17.0.3 → 17.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-psd",
3
- "version": "17.0.3",
3
+ "version": "17.0.4",
4
4
  "description": "Library for reading and writing PSD files",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist-es/index.js",
@@ -9,7 +9,7 @@ import {
9
9
  CurvesAdjustment, CurvesAdjustmentChannel, HueSaturationAdjustment, HueSaturationAdjustmentChannel,
10
10
  PresetInfo, Color, ColorBalanceValues, WriteOptions, LinkedFile, PlacedLayerType, Warp, KeyDescriptorItem,
11
11
  BooleanOperation, LayerEffectsInfo, Annotation, LayerVectorMask, AnimationFrame, Timeline, PlacedLayerFilter,
12
- UnitsValue, Filter,
12
+ UnitsValue, Filter, PlacedLayer,
13
13
  } from './psd';
14
14
  import {
15
15
  PsdReader, readSignature, readUnicodeString, skipBytes, readUint32, readUint8, readFloat64, readUint16,
@@ -1162,9 +1162,10 @@ addHandler(
1162
1162
  writeInt32(writer, placedLayerTypes.indexOf(placed.type));
1163
1163
  for (let i = 0; i < 8; i++) writeFloat64(writer, placed.transform[i]);
1164
1164
  writeInt32(writer, 0); // warp version
1165
- const isQuilt = placed.warp && isQuiltWarp(placed.warp);
1165
+ const warp = getWarpFromPlacedLayer(placed);
1166
+ const isQuilt = isQuiltWarp(warp);
1166
1167
  const type = isQuilt ? 'quiltWarp' : 'warp';
1167
- writeVersionAndDescriptor(writer, '', type, encodeWarp(placed.warp || {}), type);
1168
+ writeVersionAndDescriptor(writer, '', type, encodeWarp(warp), type);
1168
1169
  },
1169
1170
  );
1170
1171
 
@@ -3116,6 +3117,41 @@ interface SoLdDescriptor {
3116
3117
 
3117
3118
  // let t: any;
3118
3119
 
3120
+ function getWarpFromPlacedLayer(placed: PlacedLayer): Warp {
3121
+ if (placed.warp) return placed.warp;
3122
+
3123
+ if (!placed.width || !placed.height) throw new Error('You must provide width and height of the linked image in placedLayer');
3124
+
3125
+ const w = placed.width;
3126
+ const h = placed.height;
3127
+ const x0 = 0, x1 = w / 3, x2 = w * 2 / 3, x3 = w;
3128
+ const y0 = 0, y1 = h / 3, y2 = h * 2 / 3, y3 = h;
3129
+
3130
+ return {
3131
+ style: 'custom',
3132
+ value: 0,
3133
+ perspective: 0,
3134
+ perspectiveOther: 0,
3135
+ rotate: 'horizontal',
3136
+ bounds: {
3137
+ top: { value: 0, units: 'Pixels' },
3138
+ left: { value: 0, units: 'Pixels' },
3139
+ bottom: { value: h, units: 'Pixels' },
3140
+ right: { value: w, units: 'Pixels' },
3141
+ },
3142
+ uOrder: 4,
3143
+ vOrder: 4,
3144
+ customEnvelopeWarp: {
3145
+ meshPoints: [
3146
+ { x: x0, y: y0 }, { x: x1, y: y0 }, { x: x2, y: y0 }, { x: x3, y: y0 },
3147
+ { x: x0, y: y1 }, { x: x1, y: y1 }, { x: x2, y: y1 }, { x: x3, y: y1 },
3148
+ { x: x0, y: y2 }, { x: x1, y: y2 }, { x: x2, y: y2 }, { x: x3, y: y2 },
3149
+ { x: x0, y: y3 }, { x: x1, y: y3 }, { x: x2, y: y3 }, { x: x3, y: y3 },
3150
+ ],
3151
+ },
3152
+ };
3153
+ }
3154
+
3119
3155
  addHandler(
3120
3156
  'SoLd',
3121
3157
  hasKey('placedLayer'),
@@ -3171,38 +3207,6 @@ addHandler(
3171
3207
  writeInt32(writer, 4); // version
3172
3208
 
3173
3209
  const placed = target.placedLayer!;
3174
- let warp = placed.warp;
3175
-
3176
- if (!warp) {
3177
- if (!placed.width || !placed.height) throw new Error('You must provide width and height of the linked image in placedLayer');
3178
- const w = placed.width;
3179
- const h = placed.height;
3180
- const x0 = 0, x1 = w / 3, x2 = w * 2 / 3, x3 = w;
3181
- const y0 = 0, y1 = h / 3, y2 = h * 2 / 3, y3 = h;
3182
- warp = {
3183
- style: 'custom',
3184
- value: 0,
3185
- perspective: 0,
3186
- perspectiveOther: 0,
3187
- rotate: 'horizontal',
3188
- bounds: {
3189
- top: { value: 0, units: 'Pixels' },
3190
- left: { value: 0, units: 'Pixels' },
3191
- bottom: { value: h, units: 'Pixels' },
3192
- right: { value: w, units: 'Pixels' },
3193
- },
3194
- uOrder: 4,
3195
- vOrder: 4,
3196
- customEnvelopeWarp: {
3197
- meshPoints: [
3198
- { x: x0, y: y0 }, { x: x1, y: y0 }, { x: x2, y: y0 }, { x: x3, y: y0 },
3199
- { x: x0, y: y1 }, { x: x1, y: y1 }, { x: x2, y: y1 }, { x: x3, y: y1 },
3200
- { x: x0, y: y2 }, { x: x1, y: y2 }, { x: x2, y: y2 }, { x: x3, y: y2 },
3201
- { x: x0, y: y3 }, { x: x1, y: y3 }, { x: x2, y: y3 }, { x: x3, y: y3 },
3202
- ],
3203
- },
3204
- };
3205
- }
3206
3210
 
3207
3211
  if (!placed.id || typeof placed.id !== 'string' || !/^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(placed.id)) {
3208
3212
  throw new Error('Placed layer ID must be in a GUID format (example: 20953ddb-9391-11ec-b4f1-c15674f50bc4)');
@@ -3222,7 +3226,7 @@ addHandler(
3222
3226
  Trnf: placed.transform,
3223
3227
  nonAffineTransform: placed.nonAffineTransform ?? placed.transform,
3224
3228
  // quiltWarp: {} as any,
3225
- warp: encodeWarp(warp || {}),
3229
+ warp: encodeWarp(getWarpFromPlacedLayer(placed)),
3226
3230
  'Sz ': {
3227
3231
  _name: '',
3228
3232
  _classID: 'Pnt ',