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/dist-es/psd.d.ts CHANGED
@@ -1311,10 +1311,10 @@ export interface LayerAdditionalInfo {
1311
1311
  description: string;
1312
1312
  reason: string;
1313
1313
  engine: string;
1314
- enableCompCore: string;
1315
- enableCompCoreGPU: string;
1316
- compCoreSupport: string;
1317
- compCoreGPUSupport: string;
1314
+ enableCompCore?: string;
1315
+ enableCompCoreGPU?: string;
1316
+ compCoreSupport?: string;
1317
+ compCoreGPUSupport?: string;
1318
1318
  };
1319
1319
  artboard?: {
1320
1320
  rect: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-psd",
3
- "version": "17.0.3",
3
+ "version": "17.0.5",
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 ',
@@ -3324,6 +3328,44 @@ if (MOCK_HANDLERS) {
3324
3328
  );
3325
3329
  }
3326
3330
 
3331
+ /*
3332
+ interface CAIDesc {
3333
+ enab: boolean;
3334
+ generationalGuid: string;
3335
+ }
3336
+
3337
+ addHandler(
3338
+ 'CAI ', // content credentials ? something to do with generative tech
3339
+ () => false,
3340
+ (reader, _target, left) => {
3341
+ const version = readUint32(reader); // 3
3342
+ const desc = readVersionAndDescriptor(reader) as CAIDesc;
3343
+ console.log('CAI', require('util').inspect(desc, false, 99, true));
3344
+ console.log('CAI', { version });
3345
+ console.log('CAI left', readBytes(reader, left())); // 8 bytes left, all zeroes
3346
+ },
3347
+ (_writer, _target) => {
3348
+ },
3349
+ );
3350
+ */
3351
+
3352
+ /*
3353
+ interface GenIDesc {
3354
+ isUsingGenTech: number;
3355
+ }
3356
+
3357
+ addHandler(
3358
+ 'GenI', // generative tech
3359
+ () => false,
3360
+ (reader, _target, left) => {
3361
+ const desc = readVersionAndDescriptor(reader) as GenIDesc;
3362
+ console.log('GenI', require('util').inspect(desc, false, 99, true));
3363
+ },
3364
+ (_writer, _target) => {
3365
+ },
3366
+ );
3367
+ */
3368
+
3327
3369
  function readRect(reader: PsdReader) {
3328
3370
  const top = readInt32(reader);
3329
3371
  const left = readInt32(reader);
@@ -3450,6 +3492,9 @@ addHandler(
3450
3492
  let size = readLength64(reader); // size
3451
3493
  const startOffset = reader.offset;
3452
3494
  const type = readSignature(reader) as 'liFD' | 'liFE' | 'liFA';
3495
+ // liFD - linked file data
3496
+ // liFE - linked file external
3497
+ // liFA - linked file alias
3453
3498
  const version = readInt32(reader);
3454
3499
  const id = readPascalString(reader, 1);
3455
3500
  const name = readUnicodeString(reader);
@@ -3459,7 +3504,7 @@ addHandler(
3459
3504
  const hasFileOpenDescriptor = readUint8(reader);
3460
3505
  const fileOpenDescriptor = hasFileOpenDescriptor ? readVersionAndDescriptor(reader) as FileOpenDescriptor : undefined;
3461
3506
  const linkedFileDescriptor = type === 'liFE' ? readVersionAndDescriptor(reader) : undefined;
3462
- const file: LinkedFile = { id, name, data: undefined };
3507
+ const file: LinkedFile = { id, name };
3463
3508
 
3464
3509
  if (fileType) file.type = fileType;
3465
3510
  if (fileCreator) file.creator = fileCreator;
@@ -3487,11 +3532,11 @@ addHandler(
3487
3532
 
3488
3533
  const fileSize = type === 'liFE' ? readLength64(reader) : 0;
3489
3534
  if (type === 'liFA') skipBytes(reader, 8);
3490
- if (type === 'liFD') file.data = readBytes(reader, dataSize);
3535
+ if (type === 'liFD') file.data = readBytes(reader, dataSize); // seems to be a typo in docs
3491
3536
  if (version >= 5) file.childDocumentID = readUnicodeString(reader);
3492
3537
  if (version >= 6) file.assetModTime = readFloat64(reader);
3493
3538
  if (version >= 7) file.assetLockedState = readUint8(reader);
3494
- if (type === 'liFE') file.data = readBytes(reader, fileSize);
3539
+ if (type === 'liFE' && version === 2) file.data = readBytes(reader, fileSize);
3495
3540
 
3496
3541
  if (options.skipLinkedFilesData) file.data = undefined;
3497
3542
 
@@ -4703,11 +4748,11 @@ interface CinfDescriptor {
4703
4748
  description: string;
4704
4749
  reason: string;
4705
4750
  Engn: string; // 'Engn.compCore';
4706
- enableCompCore: string; // 'enable.feature';
4707
- enableCompCoreGPU: string; // 'enable.feature';
4751
+ enableCompCore?: string; // 'enable.feature';
4752
+ enableCompCoreGPU?: string; // 'enable.feature';
4708
4753
  enableCompCoreThreads?: string; // 'enable.feature';
4709
- compCoreSupport: string; // 'reason.supported';
4710
- compCoreGPUSupport: string; // 'reason.featureDisabled';
4754
+ compCoreSupport?: string; // 'reason.supported';
4755
+ compCoreGPUSupport?: string; // 'reason.featureDisabled';
4711
4756
  }
4712
4757
 
4713
4758
  addHandler(
@@ -4724,13 +4769,14 @@ addHandler(
4724
4769
  target.compositorUsed = {
4725
4770
  description: desc.description,
4726
4771
  reason: desc.reason,
4727
- engine: enumValue(desc.Engn),
4728
- enableCompCore: enumValue(desc.enableCompCore),
4729
- enableCompCoreGPU: enumValue(desc.enableCompCoreGPU),
4730
- compCoreSupport: enumValue(desc.compCoreSupport),
4731
- compCoreGPUSupport: enumValue(desc.compCoreGPUSupport),
4772
+ engine: enumValue(desc.Engn)!,
4732
4773
  };
4733
4774
 
4775
+ if (desc.enableCompCore) target.compositorUsed.enableCompCore = enumValue(desc.enableCompCore);
4776
+ if (desc.enableCompCoreGPU) target.compositorUsed.enableCompCoreGPU = enumValue(desc.enableCompCoreGPU);
4777
+ if (desc.compCoreSupport) target.compositorUsed.compCoreSupport = enumValue(desc.compCoreSupport);
4778
+ if (desc.compCoreGPUSupport) target.compositorUsed.compCoreGPUSupport = enumValue(desc.compCoreGPUSupport);
4779
+
4734
4780
  skipBytes(reader, left());
4735
4781
  },
4736
4782
  (writer, target) => {
@@ -4741,12 +4787,14 @@ addHandler(
4741
4787
  description: cinf.description,
4742
4788
  reason: cinf.reason,
4743
4789
  Engn: `Engn.${cinf.engine}`,
4744
- enableCompCore: `enable.${cinf.enableCompCore}`,
4745
- enableCompCoreGPU: `enable.${cinf.enableCompCoreGPU}`,
4746
- // enableCompCoreThreads: `enable.feature`, // TESTING
4747
- compCoreSupport: `reason.${cinf.compCoreSupport}`,
4748
- compCoreGPUSupport: `reason.${cinf.compCoreGPUSupport}`,
4749
4790
  };
4791
+
4792
+ if (cinf.enableCompCore) desc.enableCompCore = `enable.${cinf.enableCompCore}`;
4793
+ if (cinf.enableCompCoreGPU) desc.enableCompCoreGPU = `enable.${cinf.enableCompCoreGPU}`;
4794
+ // desc.enableCompCoreThreads = `enable.feature`; // TESTING
4795
+ if (cinf.compCoreSupport) desc.compCoreSupport = `reason.${cinf.compCoreSupport}`;
4796
+ if (cinf.compCoreGPUSupport) desc.compCoreGPUSupport = `reason.${cinf.compCoreGPUSupport}`;
4797
+
4750
4798
  writeVersionAndDescriptor(writer, '', 'null', desc);
4751
4799
  },
4752
4800
  );
package/src/psd.ts CHANGED
@@ -1345,10 +1345,10 @@ export interface LayerAdditionalInfo {
1345
1345
  description: string;
1346
1346
  reason: string;
1347
1347
  engine: string;
1348
- enableCompCore: string;
1349
- enableCompCoreGPU: string;
1350
- compCoreSupport: string;
1351
- compCoreGPUSupport: string;
1348
+ enableCompCore?: string;
1349
+ enableCompCoreGPU?: string;
1350
+ compCoreSupport?: string;
1351
+ compCoreGPUSupport?: string;
1352
1352
  };
1353
1353
  artboard?: {
1354
1354
  rect: { top: number; left: number; bottom: number; right: number; };