ag-psd 25.0.0 → 27.0.0

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 (58) hide show
  1. package/.v8-cache/v22.13.1-x64-00250a7c/4511bacf +0 -0
  2. package/.v8-cache/v22.13.1-x64-00250a7c/acc36e66 +0 -0
  3. package/.v8-cache/v22.13.1-x64-00250a7c/b3c2fab7 +0 -0
  4. package/.v8-cache/v22.13.1-x64-00250a7c/c314aece +0 -0
  5. package/.v8-cache/v22.13.1-x64-00250a7c/cfc49f4f +0 -0
  6. package/.v8-cache/v22.13.1-x64-00250a7c/d02dd6f7 +0 -0
  7. package/.v8-cache/v22.13.1-x64-00250a7c/e03e2acd +0 -0
  8. package/CHANGELOG.md +6 -0
  9. package/{TODO → TODO.md} +46 -0
  10. package/dist/additionalInfo.js +86 -54
  11. package/dist/additionalInfo.js.map +1 -1
  12. package/dist/bundle.js +683 -194
  13. package/dist/descriptor.js +4 -4
  14. package/dist/descriptor.js.map +1 -1
  15. package/dist/engineData2.d.ts +2 -1
  16. package/dist/engineData2.js +59 -3
  17. package/dist/engineData2.js.map +1 -1
  18. package/dist/helpers.d.ts +1 -0
  19. package/dist/helpers.js.map +1 -1
  20. package/dist/imageResources.js +39 -5
  21. package/dist/imageResources.js.map +1 -1
  22. package/dist/psd.d.ts +26 -0
  23. package/dist/psd.js.map +1 -1
  24. package/dist/psdReader.js +29 -31
  25. package/dist/psdReader.js.map +1 -1
  26. package/dist/psdWriter.js +79 -67
  27. package/dist/psdWriter.js.map +1 -1
  28. package/dist/text.d.ts +13 -2
  29. package/dist/text.js.map +1 -1
  30. package/dist-es/additionalInfo.js +86 -54
  31. package/dist-es/additionalInfo.js.map +1 -1
  32. package/dist-es/descriptor.js +4 -4
  33. package/dist-es/descriptor.js.map +1 -1
  34. package/dist-es/engineData2.d.ts +2 -1
  35. package/dist-es/engineData2.js +59 -3
  36. package/dist-es/engineData2.js.map +1 -1
  37. package/dist-es/helpers.d.ts +1 -0
  38. package/dist-es/helpers.js.map +1 -1
  39. package/dist-es/imageResources.js +41 -7
  40. package/dist-es/imageResources.js.map +1 -1
  41. package/dist-es/psd.d.ts +26 -0
  42. package/dist-es/psd.js.map +1 -1
  43. package/dist-es/psdReader.js +29 -31
  44. package/dist-es/psdReader.js.map +1 -1
  45. package/dist-es/psdWriter.js +79 -67
  46. package/dist-es/psdWriter.js.map +1 -1
  47. package/dist-es/text.d.ts +13 -2
  48. package/dist-es/text.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/additionalInfo.ts +91 -55
  51. package/src/descriptor.ts +5 -4
  52. package/src/engineData2.ts +62 -4
  53. package/src/helpers.ts +1 -0
  54. package/src/imageResources.ts +46 -20
  55. package/src/psd.ts +30 -0
  56. package/src/psdReader.ts +32 -34
  57. package/src/psdWriter.ts +75 -69
  58. package/src/text.ts +16 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v27.0.0
4
+ - Added support for read-only field `text.textPath` with text path information for text layers. This field is extracted from psd.engineData, which is not fully supported yet.
5
+
6
+ ## v26.0.0
7
+ - Added support for `realMask` section
8
+
3
9
  ## v25.0.0
4
10
  - Added support for `blendingRanges` section
5
11
  - Added support for `interpolationMethod` for gradients
@@ -25,6 +25,7 @@ check: https://github.com/TheNicker/libpsd
25
25
 
26
26
  - decompress image data in FEid section
27
27
 
28
+ ```ts
28
29
  if (!channelLength) throw new Error('filterEffect: Empty channel');
29
30
  const compression = readUint16(reader);
30
31
  const data = createImageDataBitDepth(right - left, bottom - top, depth, 1);
@@ -43,4 +44,49 @@ check: https://github.com/TheNicker/libpsd
43
44
  const data = createImageDataBitDepth(right - left, bottom - top, depth, 1);
44
45
  readData(reader, extraLength - 2, data, compression, data.width, data.height, depth, 0, false, 1);
45
46
  target.filterEffectsMasks[target.filterEffectsMasks.length - 1].extra = { top, left, bottom, right, data };
47
+ ```
46
48
 
49
+ ```ts
50
+ export function decodeUtf16String(buffer: Uint8Array) {
51
+ let result = '';
52
+
53
+ for (let i = 0; i < buffer.byteLength;) {
54
+ const w1 = (buffer[i++] << 8) | buffer[i++];
55
+
56
+ if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
57
+ result += String.fromCharCode(w1);
58
+ continue;
59
+ }
60
+
61
+ if ((w1 & 0xFC00) === 0xD800) { // w1 >= 0xD800 && w1 <= 0xDBFF
62
+ throw new Error('Invalid utf-16');
63
+ }
64
+
65
+ if (i === buffer.byteLength) {
66
+ throw new Error('Invalid utf-16');
67
+ }
68
+
69
+ const w2 = (buffer[i++] << 8) | buffer[i++];
70
+
71
+ if ((w2 & 0xFC00) !== 0xDC00) { // w2 < 0xDC00 || w2 > 0xDFFF)
72
+ throw new Error('Invalid utf-16');
73
+ }
74
+
75
+ result += String.fromCharCode(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
76
+ }
77
+
78
+ return result;
79
+ }
80
+
81
+ export function encodeUtf16String(value: string) {
82
+ const buffer = new Uint8Array(value.length * 2);
83
+
84
+ for (let i = 0, j = 0; i < value.length; i++, j += 2) {
85
+ const word = value.charCodeAt(i);
86
+ buffer[j] = (word >> 8) & 0xff;
87
+ buffer[j + 1] = word & 0xff;
88
+ }
89
+
90
+ return buffer;
91
+ }
92
+ ```
@@ -20,6 +20,7 @@ var psdWriter_1 = require("./psdWriter");
20
20
  var descriptor_1 = require("./descriptor");
21
21
  var engineData_1 = require("./engineData");
22
22
  var text_1 = require("./text");
23
+ var engineData2_1 = require("./engineData2");
23
24
  var fromAtoZ = 'abcdefghijklmnopqrstuvwxyz';
24
25
  exports.infoHandlers = [];
25
26
  exports.infoHandlersMap = {};
@@ -339,58 +340,55 @@ addHandler('vogk', hasKey('vectorOrigination'), function (reader, target, left)
339
340
  var desc = { keyDescriptorList: [] };
340
341
  for (var i = 0; i < orig.keyDescriptorList.length; i++) {
341
342
  var item = orig.keyDescriptorList[i];
342
- if (item.keyShapeInvalidated) {
343
- desc.keyDescriptorList.push({ keyShapeInvalidated: true, keyOriginIndex: i });
343
+ desc.keyDescriptorList.push({}); // we're adding keyOriginIndex at the end
344
+ var out = desc.keyDescriptorList[desc.keyDescriptorList.length - 1];
345
+ if (item.keyOriginType != null)
346
+ out.keyOriginType = item.keyOriginType;
347
+ if (item.keyOriginResolution != null)
348
+ out.keyOriginResolution = item.keyOriginResolution;
349
+ var radii = item.keyOriginRRectRadii;
350
+ if (radii) {
351
+ out.keyOriginRRectRadii = {
352
+ unitValueQuadVersion: 1,
353
+ topRight: (0, descriptor_1.unitsValue)(radii.topRight, 'topRight'),
354
+ topLeft: (0, descriptor_1.unitsValue)(radii.topLeft, 'topLeft'),
355
+ bottomLeft: (0, descriptor_1.unitsValue)(radii.bottomLeft, 'bottomLeft'),
356
+ bottomRight: (0, descriptor_1.unitsValue)(radii.bottomRight, 'bottomRight'),
357
+ };
344
358
  }
345
- else {
346
- desc.keyDescriptorList.push({}); // we're adding keyOriginIndex at the end
347
- var out = desc.keyDescriptorList[desc.keyDescriptorList.length - 1];
348
- if (item.keyOriginType != null)
349
- out.keyOriginType = item.keyOriginType;
350
- if (item.keyOriginResolution != null)
351
- out.keyOriginResolution = item.keyOriginResolution;
352
- var radii = item.keyOriginRRectRadii;
353
- if (radii) {
354
- out.keyOriginRRectRadii = {
355
- unitValueQuadVersion: 1,
356
- topRight: (0, descriptor_1.unitsValue)(radii.topRight, 'topRight'),
357
- topLeft: (0, descriptor_1.unitsValue)(radii.topLeft, 'topLeft'),
358
- bottomLeft: (0, descriptor_1.unitsValue)(radii.bottomLeft, 'bottomLeft'),
359
- bottomRight: (0, descriptor_1.unitsValue)(radii.bottomRight, 'bottomRight'),
360
- };
361
- }
362
- var box = item.keyOriginShapeBoundingBox;
363
- if (box) {
364
- out.keyOriginShapeBBox = {
365
- unitValueQuadVersion: 1,
366
- 'Top ': (0, descriptor_1.unitsValue)(box.top, 'top'),
367
- Left: (0, descriptor_1.unitsValue)(box.left, 'left'),
368
- Btom: (0, descriptor_1.unitsValue)(box.bottom, 'bottom'),
369
- Rght: (0, descriptor_1.unitsValue)(box.right, 'right'),
370
- };
371
- }
372
- var corners = item.keyOriginBoxCorners;
373
- if (corners && corners.length === 4) {
374
- out.keyOriginBoxCorners = {
375
- rectangleCornerA: { Hrzn: corners[0].x, Vrtc: corners[0].y },
376
- rectangleCornerB: { Hrzn: corners[1].x, Vrtc: corners[1].y },
377
- rectangleCornerC: { Hrzn: corners[2].x, Vrtc: corners[2].y },
378
- rectangleCornerD: { Hrzn: corners[3].x, Vrtc: corners[3].y },
379
- };
380
- }
381
- var transform = item.transform;
382
- if (transform && transform.length === 6) {
383
- out.Trnf = {
384
- xx: transform[0],
385
- xy: transform[1],
386
- yx: transform[2],
387
- yy: transform[3],
388
- tx: transform[4],
389
- ty: transform[5],
390
- };
391
- }
392
- out.keyOriginIndex = i;
359
+ var box = item.keyOriginShapeBoundingBox;
360
+ if (box) {
361
+ out.keyOriginShapeBBox = {
362
+ unitValueQuadVersion: 1,
363
+ 'Top ': (0, descriptor_1.unitsValue)(box.top, 'top'),
364
+ Left: (0, descriptor_1.unitsValue)(box.left, 'left'),
365
+ Btom: (0, descriptor_1.unitsValue)(box.bottom, 'bottom'),
366
+ Rght: (0, descriptor_1.unitsValue)(box.right, 'right'),
367
+ };
393
368
  }
369
+ var corners = item.keyOriginBoxCorners;
370
+ if (corners && corners.length === 4) {
371
+ out.keyOriginBoxCorners = {
372
+ rectangleCornerA: { Hrzn: corners[0].x, Vrtc: corners[0].y },
373
+ rectangleCornerB: { Hrzn: corners[1].x, Vrtc: corners[1].y },
374
+ rectangleCornerC: { Hrzn: corners[2].x, Vrtc: corners[2].y },
375
+ rectangleCornerD: { Hrzn: corners[3].x, Vrtc: corners[3].y },
376
+ };
377
+ }
378
+ var transform = item.transform;
379
+ if (transform && transform.length === 6) {
380
+ out.Trnf = {
381
+ xx: transform[0],
382
+ xy: transform[1],
383
+ yx: transform[2],
384
+ yy: transform[3],
385
+ tx: transform[4],
386
+ ty: transform[5],
387
+ };
388
+ }
389
+ if (item.keyShapeInvalidated != null)
390
+ out.keyShapeInvalidated = item.keyShapeInvalidated;
391
+ out.keyOriginIndex = i;
394
392
  }
395
393
  (0, psdWriter_1.writeInt32)(writer, 1); // version
396
394
  (0, descriptor_1.writeVersionAndDescriptor)(writer, '', 'null', desc);
@@ -862,7 +860,13 @@ function isQuiltWarp(warp) {
862
860
  }
863
861
  function encodeWarp(warp) {
864
862
  var bounds = warp.bounds;
865
- var desc = __assign(__assign({ warpStyle: descriptor_1.warpStyle.encode(warp.style) }, (warp.values ? { warpValues: warp.values } : { warpValue: warp.value || 0 })), { warpPerspective: warp.perspective || 0, warpPerspectiveOther: warp.perspectiveOther || 0, warpRotate: descriptor_1.Ornt.encode(warp.rotate), bounds: {
863
+ var desc = __assign(__assign({ warpStyle: descriptor_1.warpStyle.encode(warp.style) }, (warp.values ? { warpValues: warp.values } : { warpValue: warp.value || 0 })), { warpPerspective: warp.perspective || 0, warpPerspectiveOther: warp.perspectiveOther || 0, warpRotate: descriptor_1.Ornt.encode(warp.rotate), bounds: /*1 ? { // testing
864
+ _classID: 'classFloatRect',
865
+ 'Top ': bounds && bounds.top && bounds.top.value || 0,
866
+ Left: bounds && bounds.left && bounds.left.value || 0,
867
+ Btom: bounds && bounds.bottom && bounds.bottom.value || 0,
868
+ Rght: bounds && bounds.right && bounds.right.value || 0,
869
+ } :*/ {
866
870
  'Top ': (0, descriptor_1.unitsValue)(bounds && bounds.top || { units: 'Pixels', value: 0 }, 'bounds.top'),
867
871
  Left: (0, descriptor_1.unitsValue)(bounds && bounds.left || { units: 'Pixels', value: 0 }, 'bounds.left'),
868
872
  Btom: (0, descriptor_1.unitsValue)(bounds && bounds.bottom || { units: 'Pixels', value: 0 }, 'bounds.bottom'),
@@ -1427,6 +1431,7 @@ function serializeFilterFXItem(f) {
1427
1431
  'Rds ': uvRadius(f.filter),
1428
1432
  }, filterID: 697 });
1429
1433
  case 'gaussian blur': return __assign(__assign({}, base), { Fltr: {
1434
+ // _name: '高斯模糊', // Testing
1430
1435
  _name: 'Gaussian Blur',
1431
1436
  _classID: 'GsnB',
1432
1437
  'Rds ': uvRadius(f.filter),
@@ -3085,11 +3090,38 @@ addHandler('CgEd', function (target) {
3085
3090
  throw new Error('Unhandled CgEd case');
3086
3091
  }
3087
3092
  });
3088
- addHandler('Txt2', hasKey('engineData'), function (reader, target, left) {
3093
+ function getTextLayersSortedByIndex(psd) {
3094
+ var layers = [];
3095
+ function collect(layer) {
3096
+ var _a;
3097
+ if (layer.children) {
3098
+ for (var _i = 0, _b = layer.children; _i < _b.length; _i++) {
3099
+ var child = _b[_i];
3100
+ if (((_a = child.text) === null || _a === void 0 ? void 0 : _a.index) !== undefined) {
3101
+ layers[child.text.index] = child;
3102
+ }
3103
+ collect(child);
3104
+ }
3105
+ }
3106
+ }
3107
+ collect(psd);
3108
+ return layers;
3109
+ }
3110
+ addHandler('Txt2', hasKey('engineData'), function (reader, target, left, psd) {
3089
3111
  var data = (0, psdReader_1.readBytes)(reader, left());
3090
3112
  target.engineData = (0, base64_js_1.fromByteArray)(data);
3091
- // const engineData = parseEngineData(data);
3092
- // const engineData2 = decodeEngineData2(engineData);
3113
+ var layersByIndex = getTextLayersSortedByIndex(psd);
3114
+ var engineData = (0, engineData_1.parseEngineData)(data);
3115
+ var engineData2 = (0, engineData2_1.decodeEngineData2)(engineData);
3116
+ var TextFrameSet = engineData2.ResourceDict.TextFrameSet;
3117
+ if (TextFrameSet) {
3118
+ for (var i = 0; i < TextFrameSet.length; i++) {
3119
+ var layer = layersByIndex[i];
3120
+ if (TextFrameSet[i].path && (layer === null || layer === void 0 ? void 0 : layer.text)) {
3121
+ layer.text.textPath = TextFrameSet[i].path;
3122
+ }
3123
+ }
3124
+ }
3093
3125
  // console.log(require('util').inspect(engineData, false, 99, true));
3094
3126
  // require('fs').writeFileSync('test_data.bin', data);
3095
3127
  // require('fs').writeFileSync('test_data.txt', require('util').inspect(engineData, false, 99, false), 'utf8');