ag-psd 15.1.0 → 15.3.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.
@@ -71,13 +71,15 @@ addHandler('TySh', hasKey('text'), function (reader, target, leftBytes) {
71
71
  },
72
72
  };
73
73
  if (text.EngineData) {
74
- var engineData = decodeEngineData(parseEngineData(text.EngineData));
74
+ var engineData = parseEngineData(text.EngineData);
75
+ var textData = decodeEngineData(engineData);
76
+ // require('fs').writeFileSync(`layer-${target.name}.txt`, require('util').inspect(engineData, false, 99, false), 'utf8');
75
77
  // const before = parseEngineData(text.EngineData);
76
78
  // const after = encodeEngineData(engineData);
77
79
  // require('fs').writeFileSync('before.txt', require('util').inspect(before, false, 99, false), 'utf8');
78
80
  // require('fs').writeFileSync('after.txt', require('util').inspect(after, false, 99, false), 'utf8');
79
81
  // console.log(require('util').inspect(parseEngineData(text.EngineData), false, 99, true));
80
- target.text = __assign(__assign({}, target.text), engineData);
82
+ target.text = __assign(__assign({}, target.text), textData);
81
83
  // console.log(require('util').inspect(target.text, false, 99, true));
82
84
  }
83
85
  skipBytes(reader, leftBytes());
@@ -857,6 +859,173 @@ addHandler('PlLd', hasKey('placedLayer'), function (reader, target, left) {
857
859
  var type = isQuilt ? 'quiltWarp' : 'warp';
858
860
  writeVersionAndDescriptor(writer, '', type, encodeWarp(placed.warp || {}), type);
859
861
  });
862
+ function uint8ToFloat32(array) {
863
+ return new Float32Array(array.buffer.slice(array.byteOffset), 0, array.byteLength / 4);
864
+ }
865
+ function uint8ToUint32(array) {
866
+ return new Uint32Array(array.buffer.slice(array.byteOffset), 0, array.byteLength / 4);
867
+ }
868
+ function toUint8(array) {
869
+ return new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
870
+ }
871
+ function arrayToPoints(array) {
872
+ var points = [];
873
+ for (var i = 0; i < array.length; i += 2) {
874
+ points.push({ x: array[i], y: array[i + 1] });
875
+ }
876
+ return points;
877
+ }
878
+ function pointsToArray(points) {
879
+ var array = [];
880
+ for (var i = 0; i < points.length; i++) {
881
+ array.push(points[i].x, points[i].y);
882
+ }
883
+ return array;
884
+ }
885
+ function uin8ToPoints(array) {
886
+ return arrayToPoints(uint8ToFloat32(array));
887
+ }
888
+ function hrznVrtcToPoint(desc) {
889
+ return {
890
+ x: parseUnits(desc.Hrzn),
891
+ y: parseUnits(desc.Vrtc),
892
+ };
893
+ }
894
+ function pointToHrznVrtc(point) {
895
+ return {
896
+ Hrzn: unitsValue(point.x, 'x'),
897
+ Vrtc: unitsValue(point.y, 'y'),
898
+ };
899
+ }
900
+ function parseFilterFX(desc) {
901
+ return {
902
+ enabled: desc.enab,
903
+ validAtPosition: desc.validAtPosition,
904
+ maskEnabled: desc.filterMaskEnable,
905
+ maskLinked: desc.filterMaskLinked,
906
+ maskExtendWithWhite: desc.filterMaskExtendWithWhite,
907
+ list: desc.filterFXList.map(function (f) { return ({
908
+ id: f.filterID,
909
+ name: f['Nm '],
910
+ opacity: parsePercent(f.blendOptions.Opct),
911
+ blendMode: BlnM.decode(f.blendOptions['Md ']),
912
+ enabled: f.enab,
913
+ hasOptions: f.hasoptions,
914
+ foregroundColor: parseColor(f.FrgC),
915
+ backgroundColor: parseColor(f.BckC),
916
+ filter: {
917
+ rigidType: f.Fltr.rigidType,
918
+ bounds: [
919
+ { x: f.Fltr.PuX0, y: f.Fltr.PuY0, },
920
+ { x: f.Fltr.PuX1, y: f.Fltr.PuY1, },
921
+ { x: f.Fltr.PuX2, y: f.Fltr.PuY2, },
922
+ { x: f.Fltr.PuX3, y: f.Fltr.PuY3, },
923
+ ],
924
+ puppetShapeList: f.Fltr.puppetShapeList.map(function (p) { return ({
925
+ rigidType: p.rigidType,
926
+ // TODO: VrsM
927
+ // TODO: VrsN
928
+ originalVertexArray: uin8ToPoints(p.originalVertexArray),
929
+ deformedVertexArray: uin8ToPoints(p.deformedVertexArray),
930
+ indexArray: Array.from(uint8ToUint32(p.indexArray)),
931
+ pinOffsets: arrayToPoints(p.pinOffsets),
932
+ posFinalPins: arrayToPoints(p.posFinalPins),
933
+ pinVertexIndices: p.pinVertexIndices,
934
+ selectedPin: p.selectedPin,
935
+ pinPosition: arrayToPoints(p.PinP),
936
+ pinRotation: p.PnRt,
937
+ pinOverlay: p.PnOv,
938
+ pinDepth: p.PnDp,
939
+ meshQuality: p.meshQuality,
940
+ meshExpansion: p.meshExpansion,
941
+ meshRigidity: p.meshRigidity,
942
+ imageResolution: p.imageResolution,
943
+ meshBoundaryPath: {
944
+ pathComponents: p.meshBoundaryPath.pathComponents.map(function (c) { return ({
945
+ shapeOperation: c.shapeOperation.split('.')[1],
946
+ paths: c.SbpL.map(function (t) { return ({
947
+ closed: t.Clsp,
948
+ points: t['Pts '].map(function (pt) { return ({
949
+ anchor: hrznVrtcToPoint(pt.Anch),
950
+ forward: hrznVrtcToPoint(pt['Fwd ']),
951
+ backward: hrznVrtcToPoint(pt['Bwd ']),
952
+ smooth: pt.Smoo,
953
+ }); }),
954
+ }); }),
955
+ }); }),
956
+ },
957
+ }); }),
958
+ },
959
+ }); }),
960
+ };
961
+ }
962
+ function serializeFilterFX(filter) {
963
+ return {
964
+ enab: filter.enabled,
965
+ validAtPosition: filter.validAtPosition,
966
+ filterMaskEnable: filter.maskEnabled,
967
+ filterMaskLinked: filter.maskLinked,
968
+ filterMaskExtendWithWhite: filter.maskExtendWithWhite,
969
+ filterFXList: filter.list.map(function (f) { return ({
970
+ 'Nm ': f.name,
971
+ blendOptions: {
972
+ Opct: unitsPercent(f.opacity),
973
+ 'Md ': BlnM.encode(f.blendMode),
974
+ },
975
+ enab: f.enabled,
976
+ hasoptions: f.hasOptions,
977
+ FrgC: serializeColor(f.foregroundColor),
978
+ BckC: serializeColor(f.backgroundColor),
979
+ Fltr: {
980
+ 'null': ['Ordn.Trgt'],
981
+ rigidType: f.filter.rigidType,
982
+ puppetShapeList: f.filter.puppetShapeList.map(function (p) { return ({
983
+ rigidType: p.rigidType,
984
+ VrsM: 1,
985
+ VrsN: 0,
986
+ originalVertexArray: toUint8(new Float32Array(pointsToArray(p.originalVertexArray))),
987
+ deformedVertexArray: toUint8(new Float32Array(pointsToArray(p.deformedVertexArray))),
988
+ indexArray: toUint8(new Uint32Array(p.indexArray)),
989
+ pinOffsets: pointsToArray(p.pinOffsets),
990
+ posFinalPins: pointsToArray(p.posFinalPins),
991
+ selectedPin: p.selectedPin,
992
+ pinVertexIndices: p.pinVertexIndices,
993
+ PinP: pointsToArray(p.pinPosition),
994
+ PnRt: p.pinRotation,
995
+ PnOv: p.pinOverlay,
996
+ PnDp: p.pinDepth,
997
+ meshQuality: p.meshQuality,
998
+ meshExpansion: p.meshExpansion,
999
+ meshRigidity: p.meshRigidity,
1000
+ imageResolution: p.imageResolution,
1001
+ meshBoundaryPath: {
1002
+ pathComponents: p.meshBoundaryPath.pathComponents.map(function (c) { return ({
1003
+ shapeOperation: "shapeOperation.".concat(c.shapeOperation),
1004
+ SbpL: c.paths.map(function (path) { return ({
1005
+ Clsp: path.closed,
1006
+ 'Pts ': path.points.map(function (pt) { return ({
1007
+ Anch: pointToHrznVrtc(pt.anchor),
1008
+ 'Fwd ': pointToHrznVrtc(pt.forward),
1009
+ 'Bwd ': pointToHrznVrtc(pt.backward),
1010
+ Smoo: pt.smooth,
1011
+ }); }),
1012
+ }); }),
1013
+ }); }),
1014
+ },
1015
+ }); }),
1016
+ PuX0: f.filter.bounds[0].x,
1017
+ PuX1: f.filter.bounds[1].x,
1018
+ PuX2: f.filter.bounds[2].x,
1019
+ PuX3: f.filter.bounds[3].x,
1020
+ PuY0: f.filter.bounds[0].y,
1021
+ PuY1: f.filter.bounds[1].y,
1022
+ PuY2: f.filter.bounds[2].y,
1023
+ PuY3: f.filter.bounds[3].y,
1024
+ },
1025
+ filterID: f.id,
1026
+ }); }),
1027
+ };
1028
+ }
860
1029
  addHandler('SoLd', hasKey('placedLayer'), function (reader, target, left) {
861
1030
  if (readSignature(reader) !== 'soLD')
862
1031
  throw new Error("Invalid SoLd type");
@@ -867,6 +1036,8 @@ addHandler('SoLd', hasKey('placedLayer'), function (reader, target, left) {
867
1036
  // console.log('SoLd', require('util').inspect(desc, false, 99, true));
868
1037
  // console.log('SoLd.warp', require('util').inspect(desc.warp, false, 99, true));
869
1038
  // console.log('SoLd.quiltWarp', require('util').inspect(desc.quiltWarp, false, 99, true));
1039
+ // desc.filterFX!.filterFXList[0].Fltr.puppetShapeList[0].meshBoundaryPath.pathComponents[0].SbpL[0]['Pts '] = [];
1040
+ // console.log('filterFX', require('util').inspect(desc.filterFX, false, 99, true));
870
1041
  target.placedLayer = {
871
1042
  id: desc.Idnt,
872
1043
  placed: desc.placed,
@@ -891,6 +1062,8 @@ addHandler('SoLd', hasKey('placedLayer'), function (reader, target, left) {
891
1062
  target.placedLayer.comp = desc.comp;
892
1063
  if (desc.compInfo)
893
1064
  target.placedLayer.compInfo = desc.compInfo;
1065
+ if (desc.filterFX)
1066
+ target.placedLayer.filter = parseFilterFX(desc.filterFX);
894
1067
  skipBytes(reader, left()); // HACK
895
1068
  }, function (writer, target) {
896
1069
  var _a, _b;
@@ -901,6 +1074,8 @@ addHandler('SoLd', hasKey('placedLayer'), function (reader, target, left) {
901
1074
  Wdth: placed.width || 0,
902
1075
  Hght: placed.height || 0, // TODO: find size ?
903
1076
  }, Rslt: placed.resolution ? unitsValue(placed.resolution, 'resolution') : { units: 'Density', value: 72 } });
1077
+ if (placed.filter)
1078
+ desc.filterFX = serializeFilterFX(placed.filter);
904
1079
  if (placed.warp && isQuiltWarp(placed.warp)) {
905
1080
  var quiltWarp = encodeWarp(placed.warp);
906
1081
  desc.quiltWarp = quiltWarp;
@@ -2011,4 +2186,85 @@ addHandler('tsly', hasKey('transparencyShapesLayer'), function (reader, target)
2011
2186
  writeUint8(writer, target.transparencyShapesLayer ? 1 : 0);
2012
2187
  writeZeros(writer, 3);
2013
2188
  });
2189
+ /*addHandler(
2190
+ 'FEid',
2191
+ hasKey('filterEffects'),
2192
+ (reader, _target) => {
2193
+ const version = readInt32(reader);
2194
+ if (version < 1 || version > 3) throw new Error(`Invalid filterEffects version ${version}`);
2195
+
2196
+ if (readUint32(reader)) throw new Error('filterEffects: 64 bit length is not supported');
2197
+ const length = readUint32(reader);
2198
+ const end = reader.offset + length;
2199
+
2200
+ while (reader.offset < end) {
2201
+ console.log('bytes to go', end - reader.offset, 'at', reader.offset.toString(16));
2202
+ //
2203
+ const id = readPascalString(reader, 1);
2204
+ const effectVersion = readInt32(reader);
2205
+ if (effectVersion !== 1) throw new Error(`Invalid filterEffect version ${effectVersion}`);
2206
+ if (readUint32(reader)) throw new Error('filterEffect: 64 bit length is not supported');
2207
+ const effectLength = readUint32(reader);
2208
+ const endOfEffect = reader.offset + effectLength;
2209
+ const top = readInt32(reader);
2210
+ const left = readInt32(reader);
2211
+ const bottom = readInt32(reader);
2212
+ const right = readInt32(reader);
2213
+ const depth = readInt32(reader);
2214
+ const maxChannels = readInt32(reader);
2215
+ const channels: any[] = [];
2216
+
2217
+ for (let i = 0; i < (maxChannels + 2); i++) {
2218
+ const exists = readInt32(reader);
2219
+ if (exists) {
2220
+ if (readUint32(reader)) throw new Error('filterEffect: 64 bit length is not supported');
2221
+ const channelLength = readUint32(reader);
2222
+ const compressionMode = readUint16(reader);
2223
+ const data = readBytes(reader, channelLength - 2);
2224
+ channels.push({ channelLength, compressionMode, data: data?.length + ' bytes' });
2225
+ // if (c < 3 || c == 25) e_ = _F.Cn(!0, rL, m, b.rect.F, b.rect.V, X, rp);
2226
+ // if (c == 0) _c.S = e_;
2227
+ // if (c == 1) _c.v = e_;
2228
+ // if (c == 2) _c.e = e_;
2229
+ // if (c == 25) _c.w = e_;
2230
+ } else {
2231
+ channels.push(undefined);
2232
+ }
2233
+ }
2234
+
2235
+ console.log('left at the end', endOfEffect - reader.offset);
2236
+ if (endOfEffect > reader.offset) {
2237
+ if (readUint8(reader)) {
2238
+ const compressionMode = readUint16(reader);
2239
+ const data = endOfEffect > reader.offset ? readBytes(reader, endOfEffect - reader.offset) : undefined;
2240
+ console.log('extra data', { compressionMode, data: data?.length + ' bytes' });
2241
+ } else {
2242
+ console.log('no extra');
2243
+ }
2244
+ }
2245
+
2246
+ console.log('effect', {
2247
+ id,
2248
+ effectVersion,
2249
+ effectLength,
2250
+ top,
2251
+ left,
2252
+ bottom,
2253
+ right,
2254
+ depth,
2255
+ maxChannels,
2256
+ channels,
2257
+ });
2258
+
2259
+ console.log('bytes left after effect', endOfEffect - reader.offset);
2260
+ // if (length % 4) skipBytes(reader, 4 - length % 4);
2261
+ }
2262
+
2263
+ console.log({ version, length });
2264
+ },
2265
+ (_writer, _target) => {
2266
+ },
2267
+ );
2268
+
2269
+ addHandlerAlias('FXid', 'FEid');*/
2014
2270
  //# sourceMappingURL=additionalInfo.js.map