ag-psd 34.2.1 → 34.2.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/.v8-cache/v26.13.0-x64-310b2ce3/4511bacf +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/71df9cb3 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/7ea06cea +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/932f0770 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/acc36e66 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/b3c2fab7 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/dc86f000 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/e6735171 +0 -0
- package/CHANGELOG.md +9 -0
- package/README.md +33 -5
- package/dist/abr.js +5 -4
- package/dist/abr.js.map +1 -1
- package/dist/additionalInfo.js +1 -1
- package/dist/additionalInfo.js.map +1 -1
- package/dist/bundle.js +43 -25
- package/dist/descriptor.d.ts +1 -1
- package/dist/descriptor.js +18 -12
- package/dist/descriptor.js.map +1 -1
- package/dist/helpers.d.ts +4 -0
- package/dist/helpers.js +11 -0
- package/dist/helpers.js.map +1 -1
- package/dist/imageResources.js +1 -1
- package/dist/imageResources.js.map +1 -1
- package/dist/text.js +5 -5
- package/dist/text.js.map +1 -1
- package/dist-es/abr.js +5 -4
- package/dist-es/abr.js.map +1 -1
- package/dist-es/additionalInfo.js +1 -1
- package/dist-es/additionalInfo.js.map +1 -1
- package/dist-es/descriptor.d.ts +1 -1
- package/dist-es/descriptor.js +18 -12
- package/dist-es/descriptor.js.map +1 -1
- package/dist-es/helpers.d.ts +4 -0
- package/dist-es/helpers.js +11 -0
- package/dist-es/helpers.js.map +1 -1
- package/dist-es/imageResources.js +1 -1
- package/dist-es/imageResources.js.map +1 -1
- package/dist-es/text.js +5 -5
- package/dist-es/text.js.map +1 -1
- package/package.json +1 -1
- package/src/abr.ts +5 -4
- package/src/additionalInfo.ts +2 -2
- package/src/descriptor.ts +20 -13
- package/src/helpers.ts +11 -0
- package/src/imageResources.ts +2 -2
- package/src/text.ts +5 -5
package/dist/bundle.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.readAbr = readAbr;
|
|
5
5
|
const descriptor_1 = require("./descriptor");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
6
7
|
const psdReader_1 = require("./psdReader");
|
|
7
8
|
const dynamicsControl = ['off', 'fade', 'pen pressure', 'pen tilt', 'stylus wheel', 'initial direction', 'direction', 'initial rotation', 'rotation'];
|
|
8
9
|
const dynamicBrushShapeShapes = ['round point', 'round blunt', 'round curve', 'round angle', 'round fan', 'flat point', 'flat blunt', 'flat curve', 'flat angle', 'flat fan'];
|
|
@@ -20,7 +21,7 @@ const toBrushType = new Map([
|
|
|
20
21
|
]);
|
|
21
22
|
function parseDynamics(desc) {
|
|
22
23
|
return {
|
|
23
|
-
control: dynamicsControl
|
|
24
|
+
control: (0, helpers_1.arrayItem)(dynamicsControl, desc.bVTy),
|
|
24
25
|
steps: desc.fStp,
|
|
25
26
|
jitter: (0, descriptor_1.parsePercent)(desc.jitter),
|
|
26
27
|
minimum: (0, descriptor_1.parsePercent)(desc['Mnm ']),
|
|
@@ -58,7 +59,7 @@ function parseBrushShape(desc) {
|
|
|
58
59
|
case 'dBrush':
|
|
59
60
|
return {
|
|
60
61
|
type: 'dynamic',
|
|
61
|
-
shape: dynamicBrushShapeShapes
|
|
62
|
+
shape: (0, helpers_1.arrayItem)(dynamicBrushShapeShapes, desc['Shp ']),
|
|
62
63
|
angle: (0, descriptor_1.parseAngle)(desc.Angl),
|
|
63
64
|
size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'),
|
|
64
65
|
density: (0, descriptor_1.parsePercent)(desc.Dnst),
|
|
@@ -73,9 +74,9 @@ function parseBrushShape(desc) {
|
|
|
73
74
|
flipY: desc.flipY,
|
|
74
75
|
};
|
|
75
76
|
case 'dTips': {
|
|
76
|
-
return Object.assign(Object.assign({ type: 'tips', angle: (0, descriptor_1.parseAngle)(desc.Angl), size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'), shape: dynamicBrushShapeShapes
|
|
77
|
+
return Object.assign(Object.assign({ type: 'tips', angle: (0, descriptor_1.parseAngle)(desc.Angl), size: (0, descriptor_1.parseUnitsToNumber)(desc.Dmtr, 'Pixels'), shape: (0, helpers_1.arrayItem)(dynamicBrushShapeShapes, desc['Shp ']), physics: desc.physics, spacing: (0, descriptor_1.parsePercent)(desc.Spcn), spacingOn: desc.Intr, flipX: desc.flipX, flipY: desc.flipY,
|
|
77
78
|
// tips:
|
|
78
|
-
tipsType: tipsBrushShapeShapes
|
|
79
|
+
tipsType: (0, helpers_1.arrayItem)(tipsBrushShapeShapes, desc.dtipsType), tipsLengthRatio: (0, descriptor_1.parsePercent)(desc.dtipsLengthRatio), tipsHardness: (0, descriptor_1.parsePercent)(desc.dtipsHardness) }, ((desc.dtipsGridSize && desc.dtipsErodibleTipHeightMap) ? {
|
|
79
80
|
tipsGridSize: desc.dtipsGridSize,
|
|
80
81
|
tipsErodibleTipHeightMap: parseHeightmap(desc.dtipsErodibleTipHeightMap),
|
|
81
82
|
} : {})), {
|
|
@@ -507,7 +508,7 @@ function parseBrush(brush) {
|
|
|
507
508
|
return b;
|
|
508
509
|
}
|
|
509
510
|
|
|
510
|
-
},{"./descriptor":5,"./psdReader":14}],2:[function(require,module,exports){
|
|
511
|
+
},{"./descriptor":5,"./helpers":9,"./psdReader":14}],2:[function(require,module,exports){
|
|
511
512
|
"use strict";
|
|
512
513
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
513
514
|
var t = {};
|
|
@@ -3058,7 +3059,7 @@ addHandler('SoLd', target => !!target.placedLayer && !target.placedLayer.externa
|
|
|
3058
3059
|
target.placedLayer = {
|
|
3059
3060
|
id: desc.Idnt,
|
|
3060
3061
|
placed: desc.placed,
|
|
3061
|
-
type: placedLayerTypes
|
|
3062
|
+
type: (0, helpers_1.arrayItem)(placedLayerTypes, desc.Type),
|
|
3062
3063
|
pageNumber: desc.PgNm,
|
|
3063
3064
|
totalPages: desc.totalPages,
|
|
3064
3065
|
frameStep: (0, descriptor_1.frac)(desc.frameStep),
|
|
@@ -4933,6 +4934,7 @@ exports.unitsPercentF = unitsPercentF;
|
|
|
4933
4934
|
exports.unitsValue = unitsValue;
|
|
4934
4935
|
exports.frac = frac;
|
|
4935
4936
|
const helpers_1 = require("./helpers");
|
|
4937
|
+
const engineData_1 = require("./engineData");
|
|
4936
4938
|
const psdReader_1 = require("./psdReader");
|
|
4937
4939
|
const psdWriter_1 = require("./psdWriter");
|
|
4938
4940
|
const unitsMap = new Map([
|
|
@@ -5331,7 +5333,7 @@ function getTypeByKey(key, value, root, parent) {
|
|
|
5331
5333
|
return 'long';
|
|
5332
5334
|
}
|
|
5333
5335
|
else {
|
|
5334
|
-
return fieldToType
|
|
5336
|
+
return (0, helpers_1.ownValue)(fieldToType, key);
|
|
5335
5337
|
}
|
|
5336
5338
|
}
|
|
5337
5339
|
function readAsciiStringOrClassId(reader) {
|
|
@@ -5352,7 +5354,7 @@ function writeAsciiStringOrClassId(writer, value) {
|
|
|
5352
5354
|
}
|
|
5353
5355
|
}
|
|
5354
5356
|
}
|
|
5355
|
-
function readDescriptorStructure(reader, includeClass) {
|
|
5357
|
+
function readDescriptorStructure(reader, includeClass, depth = 0) {
|
|
5356
5358
|
const struct = readClassStructure(reader);
|
|
5357
5359
|
const object = includeClass ? { _name: struct.name, _classID: struct.classID } : {};
|
|
5358
5360
|
// console.log('>> ', struct);
|
|
@@ -5361,9 +5363,9 @@ function readDescriptorStructure(reader, includeClass) {
|
|
|
5361
5363
|
const key = readAsciiStringOrClassId(reader);
|
|
5362
5364
|
const type = (0, psdReader_1.readSignature)(reader);
|
|
5363
5365
|
// console.log(`> '${key}' '${type}'`);
|
|
5364
|
-
const data = readOSType(reader, type, includeClass);
|
|
5366
|
+
const data = readOSType(reader, type, includeClass, depth + 1);
|
|
5365
5367
|
// if (!getTypeByKey(key, data)) console.log(`> '${key}' '${type}'`, data);
|
|
5366
|
-
object
|
|
5368
|
+
(0, engineData_1.setProperty)(object, key, data); // key comes from the file, '__proto__' must not change the prototype
|
|
5367
5369
|
}
|
|
5368
5370
|
return object;
|
|
5369
5371
|
}
|
|
@@ -5388,9 +5390,9 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
|
5388
5390
|
for (const key of keys) {
|
|
5389
5391
|
let type = getTypeByKey(key, value[key], root, value);
|
|
5390
5392
|
let childRoot = root;
|
|
5391
|
-
let extType = fieldToExtType
|
|
5393
|
+
let extType = (0, helpers_1.ownValue)(fieldToExtType, key);
|
|
5392
5394
|
if (classId === exports.cameraRawFilterClassID) {
|
|
5393
|
-
type = (_a = exports.cameraRawFilterKeyTypes
|
|
5395
|
+
type = (_a = (0, helpers_1.ownValue)(exports.cameraRawFilterKeyTypes, key)) !== null && _a !== void 0 ? _a : 'long'; // other settings are integer levels
|
|
5394
5396
|
childRoot = exports.cameraRawFilterClassID; // lists (curves) contain integer levels
|
|
5395
5397
|
}
|
|
5396
5398
|
if (key === 'bounds' && root === 'text') {
|
|
@@ -5519,20 +5521,25 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
|
5519
5521
|
writer.log(`Missing descriptor field type for: '${key}' in`, value);
|
|
5520
5522
|
}
|
|
5521
5523
|
}
|
|
5522
|
-
|
|
5524
|
+
// descriptors nest via lists (VlLs) and nested descriptors (Objc); a crafted file can nest them
|
|
5525
|
+
// arbitrarily deep, which would overflow the call stack (RangeError), so the depth is capped
|
|
5526
|
+
const maxDescriptorDepth = 1000;
|
|
5527
|
+
function readOSType(reader, type, includeClass, depth) {
|
|
5528
|
+
if (depth > maxDescriptorDepth)
|
|
5529
|
+
throw new Error('Descriptor is nested too deeply');
|
|
5523
5530
|
switch (type) {
|
|
5524
5531
|
case 'obj ': // Reference
|
|
5525
5532
|
return readReferenceStructure(reader);
|
|
5526
5533
|
case 'Objc': // Descriptor
|
|
5527
5534
|
case 'GlbO': // GlobalObject same as Descriptor
|
|
5528
|
-
return readDescriptorStructure(reader, includeClass);
|
|
5535
|
+
return readDescriptorStructure(reader, includeClass, depth + 1);
|
|
5529
5536
|
case 'VlLs': { // List
|
|
5530
5537
|
const length = (0, psdReader_1.readInt32)(reader);
|
|
5531
5538
|
const items = [];
|
|
5532
5539
|
for (let i = 0; i < length; i++) {
|
|
5533
5540
|
const itemType = (0, psdReader_1.readSignature)(reader);
|
|
5534
5541
|
// console.log(' >', itemType);
|
|
5535
|
-
items.push(readOSType(reader, itemType, includeClass));
|
|
5542
|
+
items.push(readOSType(reader, itemType, includeClass, depth + 1));
|
|
5536
5543
|
}
|
|
5537
5544
|
return items;
|
|
5538
5545
|
}
|
|
@@ -5643,9 +5650,9 @@ function writeOSType(writer, type, value, key, extType, root) {
|
|
|
5643
5650
|
throw new Error(`Invalid list value: ${JSON.stringify(value)}, key: ${key}`);
|
|
5644
5651
|
(0, psdWriter_1.writeInt32)(writer, value.length);
|
|
5645
5652
|
for (let i = 0; i < value.length; i++) {
|
|
5646
|
-
const type = root === exports.cameraRawFilterClassID ? 'long' : ((_a = fieldToArrayType
|
|
5653
|
+
const type = root === exports.cameraRawFilterClassID ? 'long' : ((_a = (0, helpers_1.ownValue)(fieldToArrayType, key)) !== null && _a !== void 0 ? _a : guessOSType(value[i]));
|
|
5647
5654
|
(0, psdWriter_1.writeSignature)(writer, type || 'long');
|
|
5648
|
-
writeOSType(writer, type || 'long', value[i], `${key}[]`, fieldToArrayExtType
|
|
5655
|
+
writeOSType(writer, type || 'long', value[i], `${key}[]`, (0, helpers_1.ownValue)(fieldToArrayExtType, key), root);
|
|
5649
5656
|
if (writer.logMissingFeatures && !type)
|
|
5650
5657
|
writer.log(`Missing descriptor array type for: '${key}' in`, value);
|
|
5651
5658
|
}
|
|
@@ -5721,7 +5728,7 @@ function writeOSType(writer, type, value, key, extType, root) {
|
|
|
5721
5728
|
case 'ObAr': { // Object array
|
|
5722
5729
|
(0, psdWriter_1.writeInt32)(writer, 16); // version
|
|
5723
5730
|
(0, psdWriter_1.writeUnicodeStringWithPadding)(writer, ''); // name
|
|
5724
|
-
const type = ObArTypes
|
|
5731
|
+
const type = (0, helpers_1.ownValue)(ObArTypes, key);
|
|
5725
5732
|
if (!type)
|
|
5726
5733
|
throw new Error(`Not implemented ObArType for: ${key}`);
|
|
5727
5734
|
writeAsciiStringOrClassId(writer, type);
|
|
@@ -7215,7 +7222,7 @@ exports.patternColorHandling = (0, helpers_1.createEnum)('', 'convert', {
|
|
|
7215
7222
|
'luminance only': 'lumi',
|
|
7216
7223
|
});
|
|
7217
7224
|
|
|
7218
|
-
},{"./helpers":9,"./psdReader":14,"./psdWriter":15}],6:[function(require,module,exports){
|
|
7225
|
+
},{"./engineData":7,"./helpers":9,"./psdReader":14,"./psdWriter":15}],6:[function(require,module,exports){
|
|
7219
7226
|
"use strict";
|
|
7220
7227
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7221
7228
|
exports.readEffects = readEffects;
|
|
@@ -8322,6 +8329,8 @@ exports.offsetForChannel = offsetForChannel;
|
|
|
8322
8329
|
exports.normalizeLabAB = normalizeLabAB;
|
|
8323
8330
|
exports.denormalizeLabAB = denormalizeLabAB;
|
|
8324
8331
|
exports.clamp = clamp;
|
|
8332
|
+
exports.arrayItem = arrayItem;
|
|
8333
|
+
exports.ownValue = ownValue;
|
|
8325
8334
|
exports.hasAlpha = hasAlpha;
|
|
8326
8335
|
exports.cmykToRgbValues = cmykToRgbValues;
|
|
8327
8336
|
exports.rgbToCmykValues = rgbToCmykValues;
|
|
@@ -8457,6 +8466,15 @@ function denormalizeLabAB(value, scale = 1) {
|
|
|
8457
8466
|
function clamp(value, min, max) {
|
|
8458
8467
|
return value < min ? min : (value > max ? max : value);
|
|
8459
8468
|
}
|
|
8469
|
+
// index read from a file can be any type (e.g. string '__proto__' or a list coerced to 'length'),
|
|
8470
|
+
// only integer indexes within the array return an item, so inherited properties are never returned
|
|
8471
|
+
function arrayItem(array, index) {
|
|
8472
|
+
return (typeof index === 'number' && Number.isInteger(index) && index >= 0 && index < array.length) ? array[index] : undefined;
|
|
8473
|
+
}
|
|
8474
|
+
// key read from a file can be a name of an inherited property (e.g. 'constructor' or 'toString')
|
|
8475
|
+
function ownValue(dict, key) {
|
|
8476
|
+
return Object.prototype.hasOwnProperty.call(dict, key) ? dict[key] : undefined;
|
|
8477
|
+
}
|
|
8460
8478
|
function hasAlpha(data) {
|
|
8461
8479
|
const size = data.width * data.height * 4;
|
|
8462
8480
|
const max = data.data instanceof Float32Array ? 1 : (data.data instanceof Uint16Array ? 0xffff : 0xff);
|
|
@@ -9738,7 +9756,7 @@ target => target.onionSkins !== undefined, (reader, target) => {
|
|
|
9738
9756
|
frameSpacing: desc.Spcn,
|
|
9739
9757
|
minOpacity: desc.minOpacity / 100,
|
|
9740
9758
|
maxOpacity: desc.maxOpacity / 100,
|
|
9741
|
-
blendMode: onionSkinsBlendModes
|
|
9759
|
+
blendMode: (0, helpers_1.arrayItem)(onionSkinsBlendModes, desc.BlnM) || 'normal',
|
|
9742
9760
|
};
|
|
9743
9761
|
}, (writer, target) => {
|
|
9744
9762
|
const onionSkins = target.onionSkins;
|
|
@@ -15011,7 +15029,7 @@ function decodeGridInfo(grid) {
|
|
|
15011
15029
|
return isDefault ? undefined : result;
|
|
15012
15030
|
}
|
|
15013
15031
|
function decodeEngineData(engineData) {
|
|
15014
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
15032
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
15015
15033
|
// console.log('engineData', require('util').inspect(engineData, false, 99, true));
|
|
15016
15034
|
const engineDict = engineData.EngineDict;
|
|
15017
15035
|
const resourceDict = engineData.ResourceDict;
|
|
@@ -15031,7 +15049,7 @@ function decodeEngineData(engineData) {
|
|
|
15031
15049
|
}
|
|
15032
15050
|
const result = {
|
|
15033
15051
|
text,
|
|
15034
|
-
antiAlias: (_a = antialias
|
|
15052
|
+
antiAlias: (_a = (0, helpers_1.arrayItem)(antialias, engineDict.AntiAlias)) !== null && _a !== void 0 ? _a : 'smooth',
|
|
15035
15053
|
useFractionalGlyphWidths: !!engineDict.UseFractionalGlyphWidths,
|
|
15036
15054
|
superscriptSize: resourceDict.SuperscriptSize,
|
|
15037
15055
|
superscriptPosition: resourceDict.SuperscriptPosition,
|
|
@@ -15084,9 +15102,9 @@ function decodeEngineData(engineData) {
|
|
|
15084
15102
|
// const styleSheetData = styleSheetSet[theNormalStyleSheet].StyleSheetData;
|
|
15085
15103
|
const styleRun = engineDict.StyleRun;
|
|
15086
15104
|
// style runs without a font use the font of the normal style sheet
|
|
15087
|
-
const
|
|
15088
|
-
const
|
|
15089
|
-
const normalFont = (
|
|
15105
|
+
const styleSheetSet = Array.isArray(resourceDict.StyleSheetSet) ? resourceDict.StyleSheetSet : [];
|
|
15106
|
+
const normalStyleSheet = (_h = (0, helpers_1.arrayItem)(styleSheetSet, (_g = resourceDict.TheNormalStyleSheet) !== null && _g !== void 0 ? _g : 0)) === null || _h === void 0 ? void 0 : _h.StyleSheetData;
|
|
15107
|
+
const normalFont = (_j = (0, helpers_1.arrayItem)(fonts, normalStyleSheet === null || normalStyleSheet === void 0 ? void 0 : normalStyleSheet.Font)) !== null && _j !== void 0 ? _j : fonts[0];
|
|
15090
15108
|
result.style = {}; // decodeStyle(styleSheetData, fonts);
|
|
15091
15109
|
result.styleRuns = [];
|
|
15092
15110
|
for (let i = 0; i < styleRun.RunArray.length; i++) {
|
package/dist/descriptor.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const cameraRawFilterKeyTypes: Dict;
|
|
|
9
9
|
export declare const layerStateRoot = "layerState";
|
|
10
10
|
export declare function readAsciiStringOrClassId(reader: PsdReader): string;
|
|
11
11
|
export declare function writeAsciiStringOrClassId(writer: PsdWriter, value: string): void;
|
|
12
|
-
export declare function readDescriptorStructure(reader: PsdReader, includeClass: boolean): any;
|
|
12
|
+
export declare function readDescriptorStructure(reader: PsdReader, includeClass: boolean, depth?: number): any;
|
|
13
13
|
export declare const outputSettingsRoot = "outputSettings";
|
|
14
14
|
export declare function writeDescriptorStructure(writer: PsdWriter, name: string, classId: string, value: any, root: string): void;
|
|
15
15
|
export interface DescriptorReferenceItem {
|
package/dist/descriptor.js
CHANGED
|
@@ -45,6 +45,7 @@ exports.unitsPercentF = unitsPercentF;
|
|
|
45
45
|
exports.unitsValue = unitsValue;
|
|
46
46
|
exports.frac = frac;
|
|
47
47
|
const helpers_1 = require("./helpers");
|
|
48
|
+
const engineData_1 = require("./engineData");
|
|
48
49
|
const psdReader_1 = require("./psdReader");
|
|
49
50
|
const psdWriter_1 = require("./psdWriter");
|
|
50
51
|
const unitsMap = new Map([
|
|
@@ -443,7 +444,7 @@ function getTypeByKey(key, value, root, parent) {
|
|
|
443
444
|
return 'long';
|
|
444
445
|
}
|
|
445
446
|
else {
|
|
446
|
-
return fieldToType
|
|
447
|
+
return (0, helpers_1.ownValue)(fieldToType, key);
|
|
447
448
|
}
|
|
448
449
|
}
|
|
449
450
|
function readAsciiStringOrClassId(reader) {
|
|
@@ -464,7 +465,7 @@ function writeAsciiStringOrClassId(writer, value) {
|
|
|
464
465
|
}
|
|
465
466
|
}
|
|
466
467
|
}
|
|
467
|
-
function readDescriptorStructure(reader, includeClass) {
|
|
468
|
+
function readDescriptorStructure(reader, includeClass, depth = 0) {
|
|
468
469
|
const struct = readClassStructure(reader);
|
|
469
470
|
const object = includeClass ? { _name: struct.name, _classID: struct.classID } : {};
|
|
470
471
|
// console.log('>> ', struct);
|
|
@@ -473,9 +474,9 @@ function readDescriptorStructure(reader, includeClass) {
|
|
|
473
474
|
const key = readAsciiStringOrClassId(reader);
|
|
474
475
|
const type = (0, psdReader_1.readSignature)(reader);
|
|
475
476
|
// console.log(`> '${key}' '${type}'`);
|
|
476
|
-
const data = readOSType(reader, type, includeClass);
|
|
477
|
+
const data = readOSType(reader, type, includeClass, depth + 1);
|
|
477
478
|
// if (!getTypeByKey(key, data)) console.log(`> '${key}' '${type}'`, data);
|
|
478
|
-
object
|
|
479
|
+
(0, engineData_1.setProperty)(object, key, data); // key comes from the file, '__proto__' must not change the prototype
|
|
479
480
|
}
|
|
480
481
|
return object;
|
|
481
482
|
}
|
|
@@ -500,9 +501,9 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
|
500
501
|
for (const key of keys) {
|
|
501
502
|
let type = getTypeByKey(key, value[key], root, value);
|
|
502
503
|
let childRoot = root;
|
|
503
|
-
let extType = fieldToExtType
|
|
504
|
+
let extType = (0, helpers_1.ownValue)(fieldToExtType, key);
|
|
504
505
|
if (classId === exports.cameraRawFilterClassID) {
|
|
505
|
-
type = (_a = exports.cameraRawFilterKeyTypes
|
|
506
|
+
type = (_a = (0, helpers_1.ownValue)(exports.cameraRawFilterKeyTypes, key)) !== null && _a !== void 0 ? _a : 'long'; // other settings are integer levels
|
|
506
507
|
childRoot = exports.cameraRawFilterClassID; // lists (curves) contain integer levels
|
|
507
508
|
}
|
|
508
509
|
if (key === 'bounds' && root === 'text') {
|
|
@@ -631,20 +632,25 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
|
631
632
|
writer.log(`Missing descriptor field type for: '${key}' in`, value);
|
|
632
633
|
}
|
|
633
634
|
}
|
|
634
|
-
|
|
635
|
+
// descriptors nest via lists (VlLs) and nested descriptors (Objc); a crafted file can nest them
|
|
636
|
+
// arbitrarily deep, which would overflow the call stack (RangeError), so the depth is capped
|
|
637
|
+
const maxDescriptorDepth = 1000;
|
|
638
|
+
function readOSType(reader, type, includeClass, depth) {
|
|
639
|
+
if (depth > maxDescriptorDepth)
|
|
640
|
+
throw new Error('Descriptor is nested too deeply');
|
|
635
641
|
switch (type) {
|
|
636
642
|
case 'obj ': // Reference
|
|
637
643
|
return readReferenceStructure(reader);
|
|
638
644
|
case 'Objc': // Descriptor
|
|
639
645
|
case 'GlbO': // GlobalObject same as Descriptor
|
|
640
|
-
return readDescriptorStructure(reader, includeClass);
|
|
646
|
+
return readDescriptorStructure(reader, includeClass, depth + 1);
|
|
641
647
|
case 'VlLs': { // List
|
|
642
648
|
const length = (0, psdReader_1.readInt32)(reader);
|
|
643
649
|
const items = [];
|
|
644
650
|
for (let i = 0; i < length; i++) {
|
|
645
651
|
const itemType = (0, psdReader_1.readSignature)(reader);
|
|
646
652
|
// console.log(' >', itemType);
|
|
647
|
-
items.push(readOSType(reader, itemType, includeClass));
|
|
653
|
+
items.push(readOSType(reader, itemType, includeClass, depth + 1));
|
|
648
654
|
}
|
|
649
655
|
return items;
|
|
650
656
|
}
|
|
@@ -755,9 +761,9 @@ function writeOSType(writer, type, value, key, extType, root) {
|
|
|
755
761
|
throw new Error(`Invalid list value: ${JSON.stringify(value)}, key: ${key}`);
|
|
756
762
|
(0, psdWriter_1.writeInt32)(writer, value.length);
|
|
757
763
|
for (let i = 0; i < value.length; i++) {
|
|
758
|
-
const type = root === exports.cameraRawFilterClassID ? 'long' : ((_a = fieldToArrayType
|
|
764
|
+
const type = root === exports.cameraRawFilterClassID ? 'long' : ((_a = (0, helpers_1.ownValue)(fieldToArrayType, key)) !== null && _a !== void 0 ? _a : guessOSType(value[i]));
|
|
759
765
|
(0, psdWriter_1.writeSignature)(writer, type || 'long');
|
|
760
|
-
writeOSType(writer, type || 'long', value[i], `${key}[]`, fieldToArrayExtType
|
|
766
|
+
writeOSType(writer, type || 'long', value[i], `${key}[]`, (0, helpers_1.ownValue)(fieldToArrayExtType, key), root);
|
|
761
767
|
if (writer.logMissingFeatures && !type)
|
|
762
768
|
writer.log(`Missing descriptor array type for: '${key}' in`, value);
|
|
763
769
|
}
|
|
@@ -833,7 +839,7 @@ function writeOSType(writer, type, value, key, extType, root) {
|
|
|
833
839
|
case 'ObAr': { // Object array
|
|
834
840
|
(0, psdWriter_1.writeInt32)(writer, 16); // version
|
|
835
841
|
(0, psdWriter_1.writeUnicodeStringWithPadding)(writer, ''); // name
|
|
836
|
-
const type = ObArTypes
|
|
842
|
+
const type = (0, helpers_1.ownValue)(ObArTypes, key);
|
|
837
843
|
if (!type)
|
|
838
844
|
throw new Error(`Not implemented ObArType for: ${key}`);
|
|
839
845
|
writeAsciiStringOrClassId(writer, type);
|