ag-psd 30.1.1 → 30.2.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.
- package/.v8-cache/v24.13.1-x64-cf738c9d/017325ac +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/043c7b90 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/05135617 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/059f8558 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/0706ecb8 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/0db754a7 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/1130885f +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/15f0e479 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/20477c23 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/20dfa422 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/2a19133e +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/2b069ee0 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/2de09439 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/2e44f5f0 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/2fb229a9 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/3144b401 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/37481985 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/4511bacf +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/49d22b79 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/4f5702bd +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/514cc428 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/57d3380b +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/6024ce3f +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/61735b23 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/63dbdb75 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/6cbfc0ec +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/6f08372c +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/7100ee08 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/71df9cb3 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/75e41e43 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/7ea06cea +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/8568576b +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/87372817 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/87cf2209 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/932f0770 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/a79a40bb +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/a7e80865 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/acc36e66 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/b3c2fab7 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/b69ed3a3 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/bdff1628 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/c0b789d2 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/c314aece +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/cfc49f4f +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/cff9434a +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/d02dd6f7 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/dc86f000 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/de74e659 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/e03e2acd +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/e158d332 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/e6735171 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/e6745c2b +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/e6b99945 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/eeeebdfe +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/fbca6276 +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/fc97d72d +0 -0
- package/.v8-cache/v24.13.1-x64-cf738c9d/fd0a2987 +0 -0
- package/CHANGELOG.md +3 -0
- package/README.md +1 -1
- package/README_PSD.md +1 -1
- package/dist/abr.js +43 -56
- package/dist/abr.js.map +1 -1
- package/dist/additionalInfo.js +770 -808
- package/dist/additionalInfo.js.map +1 -1
- package/dist/ase.js +21 -21
- package/dist/ase.js.map +1 -1
- package/dist/bundle.js +2592 -2778
- package/dist/csh.js +18 -29
- package/dist/csh.js.map +1 -1
- package/dist/descriptor.js +234 -269
- package/dist/descriptor.js.map +1 -1
- package/dist/effectsHelpers.js +91 -112
- package/dist/effectsHelpers.js.map +1 -1
- package/dist/engineData.js +45 -51
- package/dist/engineData.js.map +1 -1
- package/dist/engineData2.js +8 -9
- package/dist/engineData2.js.map +1 -1
- package/dist/helpers.js +75 -81
- package/dist/helpers.js.map +1 -1
- package/dist/imageResources.js +342 -381
- package/dist/imageResources.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/initializeCanvas.js +2 -2
- package/dist/initializeCanvas.js.map +1 -1
- package/dist/jpeg.js +279 -279
- package/dist/jpeg.js.map +1 -1
- package/dist/psdReader.js +336 -347
- package/dist/psdReader.js.map +1 -1
- package/dist/psdWriter.d.ts +2 -1
- package/dist/psdWriter.js +225 -206
- package/dist/psdWriter.js.map +1 -1
- package/dist/text.js +98 -122
- package/dist/text.js.map +1 -1
- package/dist/utf8.js +22 -22
- package/dist/utf8.js.map +1 -1
- package/dist-es/abr.js +41 -54
- package/dist-es/abr.js.map +1 -1
- package/dist-es/additionalInfo.js +765 -803
- package/dist-es/additionalInfo.js.map +1 -1
- package/dist-es/ase.js +20 -20
- package/dist-es/ase.js.map +1 -1
- package/dist-es/csh.js +16 -27
- package/dist-es/csh.js.map +1 -1
- package/dist-es/descriptor.js +284 -319
- package/dist-es/descriptor.js.map +1 -1
- package/dist-es/effectsHelpers.js +88 -109
- package/dist-es/effectsHelpers.js.map +1 -1
- package/dist-es/engineData.js +45 -51
- package/dist-es/engineData.js.map +1 -1
- package/dist-es/engineData2.js +8 -9
- package/dist-es/engineData2.js.map +1 -1
- package/dist-es/helpers.js +79 -85
- package/dist-es/helpers.js.map +1 -1
- package/dist-es/imageResources.js +338 -377
- package/dist-es/imageResources.js.map +1 -1
- package/dist-es/index.js +4 -4
- package/dist-es/index.js.map +1 -1
- package/dist-es/jpeg.js +279 -279
- package/dist-es/jpeg.js.map +1 -1
- package/dist-es/psdReader.js +333 -344
- package/dist-es/psdReader.js.map +1 -1
- package/dist-es/psdWriter.d.ts +2 -1
- package/dist-es/psdWriter.js +220 -202
- package/dist-es/psdWriter.js.map +1 -1
- package/dist-es/text.js +98 -122
- package/dist-es/text.js.map +1 -1
- package/dist-es/utf8.js +22 -22
- package/dist-es/utf8.js.map +1 -1
- package/package.json +1 -1
- package/publish.js +24 -0
- package/src/additionalInfo.ts +15 -11
- package/src/psdWriter.ts +76 -1
- package/tsconfig.json +4 -3
package/dist/descriptor.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
3
|
var t = {};
|
|
15
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -24,15 +13,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
24
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
14
|
exports.ESliceOrigin = exports.ESliceVertAlign = exports.ESliceHorzAlign = exports.ESliceType = exports.FrFl = exports.FStl = exports.ClrS = exports.gradientInterpolationMethodType = exports.stdTrackID = exports.animInterpStyleEnum = exports.GrdT = exports.IGSr = exports.BETE = exports.BESs = exports.bvlT = exports.BESl = exports.BlnM = exports.warpStyle = exports.Annt = exports.Ornt = exports.textGridding = exports.frac = exports.unitsValue = exports.unitsPercentF = exports.unitsPercent = exports.unitsAngle = exports.parseUnitsToNumber = exports.parseUnitsOrNumber = exports.parseUnits = exports.parsePercentOrAngle = exports.parsePercent = exports.parseAngle = exports.serializeColor = exports.parseColor = exports.serializeVectorContent = exports.parseVectorContent = exports.serializeTrackList = exports.parseTrackList = exports.parseEffects = exports.serializeEffects = exports.boundsToDescBounds = exports.descBoundsToBounds = exports.xyToHorzVrtc = exports.horzVrtcToXY = exports.writeVersionAndDescriptor = exports.readVersionAndDescriptor = exports.writeDescriptorStructure = exports.readDescriptorStructure = exports.readAsciiStringOrClassId = exports.setLogErrors = void 0;
|
|
26
15
|
exports.presetKindType = exports.prjM = exports.FlMd = exports.IntC = exports.IntE = exports.Drct = exports.WndM = exports.CntE = exports.FlCl = exports.ExtR = exports.ExtT = exports.DfsM = exports.blurType = exports.Lns = exports.MztT = exports.Chnl = exports.Dstr = exports.ZZTy = exports.Wvtp = exports.SphM = exports.RplS = exports.Cnvr = exports.UndA = exports.DspM = exports.SmBQ = exports.SmBM = exports.BlrQ = exports.BlrM = exports.strokeStyleLineAlignment = exports.strokeStyleLineJoinType = exports.strokeStyleLineCapType = exports.ESliceBGColorType = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
const helpers_1 = require("./helpers");
|
|
17
|
+
const psdReader_1 = require("./psdReader");
|
|
18
|
+
const psdWriter_1 = require("./psdWriter");
|
|
30
19
|
function revMap(map) {
|
|
31
|
-
|
|
32
|
-
Object.keys(map).forEach(
|
|
20
|
+
const result = {};
|
|
21
|
+
Object.keys(map).forEach(key => result[map[key]] = key);
|
|
33
22
|
return result;
|
|
34
23
|
}
|
|
35
|
-
|
|
24
|
+
const unitsMap = {
|
|
36
25
|
'#Ang': 'Angle',
|
|
37
26
|
'#Rsl': 'Density',
|
|
38
27
|
'#Rlt': 'Distance',
|
|
@@ -45,18 +34,18 @@ var unitsMap = {
|
|
|
45
34
|
'RrIn': 'Inches',
|
|
46
35
|
'RrCm': 'Centimeters',
|
|
47
36
|
};
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
const unitsMapRev = revMap(unitsMap);
|
|
38
|
+
let logErrors = false;
|
|
50
39
|
function setLogErrors(value) {
|
|
51
40
|
logErrors = value;
|
|
52
41
|
}
|
|
53
42
|
exports.setLogErrors = setLogErrors;
|
|
54
43
|
function makeType(name, classID) {
|
|
55
|
-
return { name
|
|
44
|
+
return { name, classID };
|
|
56
45
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
46
|
+
const nullType = makeType('', 'null');
|
|
47
|
+
const USE_CHINESE = false; // Testing
|
|
48
|
+
const fieldToExtType = {
|
|
60
49
|
strokeStyleContent: makeType('', 'solidColorLayer'),
|
|
61
50
|
printProofSetup: makeType(USE_CHINESE ? '校样设置' : 'Proof Setup', 'proofSetup'),
|
|
62
51
|
Grad: makeType(USE_CHINESE ? '渐变' : 'Gradient', 'Grdn'),
|
|
@@ -139,7 +128,7 @@ var fieldToExtType = {
|
|
|
139
128
|
FXRefPoint: nullType,
|
|
140
129
|
ClMg: makeType('', 'ClMg'),
|
|
141
130
|
};
|
|
142
|
-
|
|
131
|
+
const fieldToArrayExtType = {
|
|
143
132
|
'Crv ': makeType('', 'CrPt'),
|
|
144
133
|
Clrs: makeType('', 'Clrt'),
|
|
145
134
|
Trns: makeType('', 'TrnS'),
|
|
@@ -172,7 +161,7 @@ var fieldToArrayExtType = {
|
|
|
172
161
|
list: nullType,
|
|
173
162
|
Adjs: makeType('', 'CrvA'),
|
|
174
163
|
};
|
|
175
|
-
|
|
164
|
+
const typeToField = {
|
|
176
165
|
'TEXT': [
|
|
177
166
|
'Txt ', 'printerName', 'Nm ', 'Idnt', 'blackAndWhitePresetFileName', 'LUT3DFileName',
|
|
178
167
|
'presetFileName', 'curvesPresetFileName', 'mixerPresetFileName', 'placed', 'description', 'reason',
|
|
@@ -246,10 +235,10 @@ var typeToField = {
|
|
|
246
235
|
'obj ': ['null', 'Chnl'],
|
|
247
236
|
'Pth ': ['DspF'],
|
|
248
237
|
};
|
|
249
|
-
|
|
238
|
+
const channels = [
|
|
250
239
|
'Rd ', 'Grn ', 'Bl ', 'Yllw', 'Ylw ', 'Cyn ', 'Mgnt', 'Blck', 'Gry ', 'Lmnc', 'A ', 'B ',
|
|
251
240
|
];
|
|
252
|
-
|
|
241
|
+
const fieldToArrayType = {
|
|
253
242
|
'Mnm ': 'long',
|
|
254
243
|
'Mxm ': 'long',
|
|
255
244
|
FrLs: 'long',
|
|
@@ -289,21 +278,17 @@ var fieldToArrayType = {
|
|
|
289
278
|
compList: 'long',
|
|
290
279
|
Chnl: 'enum',
|
|
291
280
|
};
|
|
292
|
-
|
|
293
|
-
for (
|
|
294
|
-
|
|
295
|
-
for (var _b = 0, _c = typeToField[type]; _b < _c.length; _b++) {
|
|
296
|
-
var field = _c[_b];
|
|
281
|
+
const fieldToType = {};
|
|
282
|
+
for (const type of Object.keys(typeToField)) {
|
|
283
|
+
for (const field of typeToField[type]) {
|
|
297
284
|
fieldToType[field] = type;
|
|
298
285
|
}
|
|
299
286
|
}
|
|
300
|
-
for (
|
|
301
|
-
var field = _e[_d];
|
|
287
|
+
for (const field of Object.keys(fieldToExtType)) {
|
|
302
288
|
if (!fieldToType[field])
|
|
303
289
|
fieldToType[field] = 'Objc';
|
|
304
290
|
}
|
|
305
|
-
for (
|
|
306
|
-
var field = _g[_f];
|
|
291
|
+
for (const field of Object.keys(fieldToArrayExtType)) {
|
|
307
292
|
fieldToArrayType[field] = 'Objc';
|
|
308
293
|
}
|
|
309
294
|
function getTypeByKey(key, value, root, parent) {
|
|
@@ -347,7 +332,7 @@ function getTypeByKey(key, value, root, parent) {
|
|
|
347
332
|
}
|
|
348
333
|
}
|
|
349
334
|
function readAsciiStringOrClassId(reader) {
|
|
350
|
-
|
|
335
|
+
const length = (0, psdReader_1.readInt32)(reader);
|
|
351
336
|
return (0, psdReader_1.readAsciiString)(reader, length || 4);
|
|
352
337
|
}
|
|
353
338
|
exports.readAsciiStringOrClassId = readAsciiStringOrClassId;
|
|
@@ -360,21 +345,21 @@ function writeAsciiStringOrClassId(writer, value) {
|
|
|
360
345
|
else {
|
|
361
346
|
// write ascii string
|
|
362
347
|
(0, psdWriter_1.writeInt32)(writer, value.length);
|
|
363
|
-
for (
|
|
348
|
+
for (let i = 0; i < value.length; i++) {
|
|
364
349
|
(0, psdWriter_1.writeUint8)(writer, value.charCodeAt(i));
|
|
365
350
|
}
|
|
366
351
|
}
|
|
367
352
|
}
|
|
368
353
|
function readDescriptorStructure(reader, includeClass) {
|
|
369
|
-
|
|
370
|
-
|
|
354
|
+
const struct = readClassStructure(reader);
|
|
355
|
+
const object = includeClass ? { _name: struct.name, _classID: struct.classID } : {};
|
|
371
356
|
// console.log('>> ', struct);
|
|
372
|
-
|
|
373
|
-
for (
|
|
374
|
-
|
|
375
|
-
|
|
357
|
+
const itemsCount = (0, psdReader_1.readUint32)(reader);
|
|
358
|
+
for (let i = 0; i < itemsCount; i++) {
|
|
359
|
+
const key = readAsciiStringOrClassId(reader);
|
|
360
|
+
const type = (0, psdReader_1.readSignature)(reader);
|
|
376
361
|
// console.log(`> '${key}' '${type}'`);
|
|
377
|
-
|
|
362
|
+
const data = readOSType(reader, type, includeClass);
|
|
378
363
|
// if (!getTypeByKey(key, data)) console.log(`> '${key}' '${type}'`, data);
|
|
379
364
|
object[key] = data;
|
|
380
365
|
}
|
|
@@ -387,19 +372,18 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
|
387
372
|
// write class structure
|
|
388
373
|
(0, psdWriter_1.writeUnicodeStringWithPadding)(writer, name);
|
|
389
374
|
writeAsciiStringOrClassId(writer, classId);
|
|
390
|
-
|
|
391
|
-
|
|
375
|
+
const keys = Object.keys(value);
|
|
376
|
+
let keyCount = keys.length;
|
|
392
377
|
if ('_name' in value)
|
|
393
378
|
keyCount--;
|
|
394
379
|
if ('_classID' in value)
|
|
395
380
|
keyCount--;
|
|
396
381
|
(0, psdWriter_1.writeUint32)(writer, keyCount);
|
|
397
|
-
for (
|
|
398
|
-
var key = keys_1[_i];
|
|
382
|
+
for (const key of keys) {
|
|
399
383
|
if (key === '_name' || key === '_classID')
|
|
400
384
|
continue;
|
|
401
|
-
|
|
402
|
-
|
|
385
|
+
let type = getTypeByKey(key, value[key], root, value);
|
|
386
|
+
let extType = fieldToExtType[key];
|
|
403
387
|
if (key === 'bounds' && root === 'text') {
|
|
404
388
|
extType = makeType('', 'bounds');
|
|
405
389
|
}
|
|
@@ -503,7 +487,7 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
|
503
487
|
(0, psdWriter_1.writeSignature)(writer, type || 'long');
|
|
504
488
|
writeOSType(writer, type || 'long', value[key], key, extType, root);
|
|
505
489
|
if (logErrors && !type)
|
|
506
|
-
console.log(
|
|
490
|
+
console.log(`Missing descriptor field type for: '${key}' in`, value);
|
|
507
491
|
}
|
|
508
492
|
}
|
|
509
493
|
exports.writeDescriptorStructure = writeDescriptorStructure;
|
|
@@ -515,10 +499,10 @@ function readOSType(reader, type, includeClass) {
|
|
|
515
499
|
case 'GlbO': // GlobalObject same as Descriptor
|
|
516
500
|
return readDescriptorStructure(reader, includeClass);
|
|
517
501
|
case 'VlLs': { // List
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
for (
|
|
521
|
-
|
|
502
|
+
const length = (0, psdReader_1.readInt32)(reader);
|
|
503
|
+
const items = [];
|
|
504
|
+
for (let i = 0; i < length; i++) {
|
|
505
|
+
const itemType = (0, psdReader_1.readSignature)(reader);
|
|
522
506
|
// console.log(' >', itemType);
|
|
523
507
|
items.push(readOSType(reader, itemType, includeClass));
|
|
524
508
|
}
|
|
@@ -527,32 +511,32 @@ function readOSType(reader, type, includeClass) {
|
|
|
527
511
|
case 'doub': // Double
|
|
528
512
|
return (0, psdReader_1.readFloat64)(reader);
|
|
529
513
|
case 'UntF': { // Unit double
|
|
530
|
-
|
|
531
|
-
|
|
514
|
+
const units = (0, psdReader_1.readSignature)(reader);
|
|
515
|
+
const value = (0, psdReader_1.readFloat64)(reader);
|
|
532
516
|
if (!unitsMap[units])
|
|
533
|
-
throw new Error(
|
|
534
|
-
return { units: unitsMap[units], value
|
|
517
|
+
throw new Error(`Invalid units: ${units}`);
|
|
518
|
+
return { units: unitsMap[units], value };
|
|
535
519
|
}
|
|
536
520
|
case 'UnFl': { // Unit float
|
|
537
|
-
|
|
538
|
-
|
|
521
|
+
const units = (0, psdReader_1.readSignature)(reader);
|
|
522
|
+
const value = (0, psdReader_1.readFloat32)(reader);
|
|
539
523
|
if (!unitsMap[units])
|
|
540
|
-
throw new Error(
|
|
541
|
-
return { units: unitsMap[units], value
|
|
524
|
+
throw new Error(`Invalid units: ${units}`);
|
|
525
|
+
return { units: unitsMap[units], value };
|
|
542
526
|
}
|
|
543
527
|
case 'TEXT': // String
|
|
544
528
|
return (0, psdReader_1.readUnicodeString)(reader);
|
|
545
529
|
case 'enum': { // Enumerated
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
return
|
|
530
|
+
const enumType = readAsciiStringOrClassId(reader);
|
|
531
|
+
const value = readAsciiStringOrClassId(reader);
|
|
532
|
+
return `${enumType}.${value}`;
|
|
549
533
|
}
|
|
550
534
|
case 'long': // Integer
|
|
551
535
|
return (0, psdReader_1.readInt32)(reader);
|
|
552
536
|
case 'comp': { // Large Integer
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
return { low
|
|
537
|
+
const low = (0, psdReader_1.readUint32)(reader);
|
|
538
|
+
const high = (0, psdReader_1.readUint32)(reader);
|
|
539
|
+
return { low, high };
|
|
556
540
|
}
|
|
557
541
|
case 'bool': // Boolean
|
|
558
542
|
return !!(0, psdReader_1.readUint8)(reader);
|
|
@@ -560,45 +544,45 @@ function readOSType(reader, type, includeClass) {
|
|
|
560
544
|
case 'GlbC': // Class
|
|
561
545
|
return readClassStructure(reader);
|
|
562
546
|
case 'alis': { // Alias
|
|
563
|
-
|
|
564
|
-
return (0, psdReader_1.readAsciiString)(reader,
|
|
547
|
+
const length = (0, psdReader_1.readInt32)(reader);
|
|
548
|
+
return (0, psdReader_1.readAsciiString)(reader, length);
|
|
565
549
|
}
|
|
566
550
|
case 'tdta': { // Raw Data
|
|
567
|
-
|
|
568
|
-
return (0, psdReader_1.readBytes)(reader,
|
|
551
|
+
const length = (0, psdReader_1.readInt32)(reader);
|
|
552
|
+
return (0, psdReader_1.readBytes)(reader, length);
|
|
569
553
|
}
|
|
570
554
|
case 'ObAr': { // Object array
|
|
571
555
|
(0, psdReader_1.readInt32)(reader); // version: 16
|
|
572
556
|
(0, psdReader_1.readUnicodeString)(reader); // name: ''
|
|
573
557
|
readAsciiStringOrClassId(reader); // 'rationalPoint'
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
for (
|
|
577
|
-
|
|
558
|
+
const length = (0, psdReader_1.readInt32)(reader);
|
|
559
|
+
const items = [];
|
|
560
|
+
for (let i = 0; i < length; i++) {
|
|
561
|
+
const type1 = readAsciiStringOrClassId(reader); // type Hrzn | Vrtc
|
|
578
562
|
(0, psdReader_1.readSignature)(reader); // UnFl
|
|
579
563
|
(0, psdReader_1.readSignature)(reader); // units ? '#Pxl'
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
for (
|
|
564
|
+
const valuesCount = (0, psdReader_1.readInt32)(reader);
|
|
565
|
+
const values = [];
|
|
566
|
+
for (let j = 0; j < valuesCount; j++) {
|
|
583
567
|
values.push((0, psdReader_1.readFloat64)(reader));
|
|
584
568
|
}
|
|
585
|
-
items.push({ type: type1, values
|
|
569
|
+
items.push({ type: type1, values });
|
|
586
570
|
}
|
|
587
571
|
return items;
|
|
588
572
|
}
|
|
589
573
|
case 'Pth ': { // File path
|
|
590
574
|
/*const length =*/ (0, psdReader_1.readInt32)(reader); // total size of all fields below
|
|
591
|
-
|
|
575
|
+
const sig = (0, psdReader_1.readSignature)(reader);
|
|
592
576
|
/*const pathSize =*/ (0, psdReader_1.readInt32LE)(reader); // the same as length
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
return { sig
|
|
577
|
+
const charsCount = (0, psdReader_1.readInt32LE)(reader);
|
|
578
|
+
const path = (0, psdReader_1.readUnicodeStringWithLengthLE)(reader, charsCount);
|
|
579
|
+
return { sig, path };
|
|
596
580
|
}
|
|
597
581
|
default:
|
|
598
|
-
throw new Error(
|
|
582
|
+
throw new Error(`Invalid TySh descriptor OSType: ${type} at ${reader.offset.toString(16)}`);
|
|
599
583
|
}
|
|
600
584
|
}
|
|
601
|
-
|
|
585
|
+
const ObArTypes = {
|
|
602
586
|
meshPoints: 'rationalPoint',
|
|
603
587
|
quiltSliceX: 'UntF',
|
|
604
588
|
quiltSliceY: 'UntF',
|
|
@@ -611,40 +595,40 @@ function writeOSType(writer, type, value, key, extType, root) {
|
|
|
611
595
|
case 'Objc': // Descriptor
|
|
612
596
|
case 'GlbO': { // GlobalObject same as Descriptor
|
|
613
597
|
if (typeof value !== 'object')
|
|
614
|
-
throw new Error(
|
|
598
|
+
throw new Error(`Invalid struct value: ${JSON.stringify(value)}, key: ${key}`);
|
|
615
599
|
if (!extType)
|
|
616
|
-
throw new Error(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
writeDescriptorStructure(writer,
|
|
600
|
+
throw new Error(`Missing ext type for: '${key}' (${JSON.stringify(value)})`);
|
|
601
|
+
const name = value._name || extType.name;
|
|
602
|
+
const classID = value._classID || extType.classID;
|
|
603
|
+
writeDescriptorStructure(writer, name, classID, value, root);
|
|
620
604
|
break;
|
|
621
605
|
}
|
|
622
606
|
case 'VlLs': // List
|
|
623
607
|
if (!Array.isArray(value))
|
|
624
|
-
throw new Error(
|
|
608
|
+
throw new Error(`Invalid list value: ${JSON.stringify(value)}, key: ${key}`);
|
|
625
609
|
(0, psdWriter_1.writeInt32)(writer, value.length);
|
|
626
|
-
for (
|
|
627
|
-
|
|
628
|
-
(0, psdWriter_1.writeSignature)(writer,
|
|
629
|
-
writeOSType(writer,
|
|
630
|
-
if (logErrors && !
|
|
631
|
-
console.log(
|
|
610
|
+
for (let i = 0; i < value.length; i++) {
|
|
611
|
+
const type = fieldToArrayType[key];
|
|
612
|
+
(0, psdWriter_1.writeSignature)(writer, type || 'long');
|
|
613
|
+
writeOSType(writer, type || 'long', value[i], `${key}[]`, fieldToArrayExtType[key], root);
|
|
614
|
+
if (logErrors && !type)
|
|
615
|
+
console.log(`Missing descriptor array type for: '${key}' in`, value);
|
|
632
616
|
}
|
|
633
617
|
break;
|
|
634
618
|
case 'doub': // Double
|
|
635
619
|
if (typeof value !== 'number')
|
|
636
|
-
throw new Error(
|
|
620
|
+
throw new Error(`Invalid number value: ${JSON.stringify(value)}, key: ${key}`);
|
|
637
621
|
(0, psdWriter_1.writeFloat64)(writer, value);
|
|
638
622
|
break;
|
|
639
623
|
case 'UntF': // Unit double
|
|
640
624
|
if (!unitsMapRev[value.units])
|
|
641
|
-
throw new Error(
|
|
625
|
+
throw new Error(`Invalid units: ${value.units} in ${key}`);
|
|
642
626
|
(0, psdWriter_1.writeSignature)(writer, unitsMapRev[value.units]);
|
|
643
627
|
(0, psdWriter_1.writeFloat64)(writer, value.value);
|
|
644
628
|
break;
|
|
645
629
|
case 'UnFl': // Unit float
|
|
646
630
|
if (!unitsMapRev[value.units])
|
|
647
|
-
throw new Error(
|
|
631
|
+
throw new Error(`Invalid units: ${value.units} in ${key}`);
|
|
648
632
|
(0, psdWriter_1.writeSignature)(writer, unitsMapRev[value.units]);
|
|
649
633
|
(0, psdWriter_1.writeFloat32)(writer, value.value);
|
|
650
634
|
break;
|
|
@@ -653,22 +637,22 @@ function writeOSType(writer, type, value, key, extType, root) {
|
|
|
653
637
|
break;
|
|
654
638
|
case 'enum': { // Enumerated
|
|
655
639
|
if (typeof value !== 'string')
|
|
656
|
-
throw new Error(
|
|
657
|
-
|
|
640
|
+
throw new Error(`Invalid enum value: ${JSON.stringify(value)}, key: ${key}`);
|
|
641
|
+
const [_type, val] = value.split('.');
|
|
658
642
|
writeAsciiStringOrClassId(writer, _type);
|
|
659
643
|
writeAsciiStringOrClassId(writer, val);
|
|
660
644
|
break;
|
|
661
645
|
}
|
|
662
646
|
case 'long': // Integer
|
|
663
647
|
if (typeof value !== 'number')
|
|
664
|
-
throw new Error(
|
|
648
|
+
throw new Error(`Invalid integer value: ${JSON.stringify(value)}, key: ${key}`);
|
|
665
649
|
(0, psdWriter_1.writeInt32)(writer, value);
|
|
666
650
|
break;
|
|
667
651
|
// case 'comp': // Large Integer
|
|
668
652
|
// writeLargeInteger(reader);
|
|
669
653
|
case 'bool': // Boolean
|
|
670
654
|
if (typeof value !== 'boolean')
|
|
671
|
-
throw new Error(
|
|
655
|
+
throw new Error(`Invalid boolean value: ${JSON.stringify(value)}, key: ${key}`);
|
|
672
656
|
(0, psdWriter_1.writeUint8)(writer, value ? 1 : 0);
|
|
673
657
|
break;
|
|
674
658
|
// case 'type': // Class
|
|
@@ -683,44 +667,44 @@ function writeOSType(writer, type, value, key, extType, root) {
|
|
|
683
667
|
case 'ObAr': { // Object array
|
|
684
668
|
(0, psdWriter_1.writeInt32)(writer, 16); // version
|
|
685
669
|
(0, psdWriter_1.writeUnicodeStringWithPadding)(writer, ''); // name
|
|
686
|
-
|
|
687
|
-
if (!
|
|
688
|
-
throw new Error(
|
|
689
|
-
writeAsciiStringOrClassId(writer,
|
|
670
|
+
const type = ObArTypes[key];
|
|
671
|
+
if (!type)
|
|
672
|
+
throw new Error(`Not implemented ObArType for: ${key}`);
|
|
673
|
+
writeAsciiStringOrClassId(writer, type);
|
|
690
674
|
(0, psdWriter_1.writeInt32)(writer, value.length);
|
|
691
|
-
for (
|
|
675
|
+
for (let i = 0; i < value.length; i++) {
|
|
692
676
|
writeAsciiStringOrClassId(writer, value[i].type); // Hrzn | Vrtc
|
|
693
677
|
(0, psdWriter_1.writeSignature)(writer, 'UnFl');
|
|
694
678
|
(0, psdWriter_1.writeSignature)(writer, '#Pxl');
|
|
695
679
|
(0, psdWriter_1.writeInt32)(writer, value[i].values.length);
|
|
696
|
-
for (
|
|
680
|
+
for (let j = 0; j < value[i].values.length; j++) {
|
|
697
681
|
(0, psdWriter_1.writeFloat64)(writer, value[i].values[j]);
|
|
698
682
|
}
|
|
699
683
|
}
|
|
700
684
|
break;
|
|
701
685
|
}
|
|
702
686
|
case 'Pth ': { // File path
|
|
703
|
-
|
|
704
|
-
(0, psdWriter_1.writeInt32)(writer,
|
|
687
|
+
const length = 4 + 4 + 4 + value.path.length * 2;
|
|
688
|
+
(0, psdWriter_1.writeInt32)(writer, length);
|
|
705
689
|
(0, psdWriter_1.writeSignature)(writer, value.sig);
|
|
706
|
-
(0, psdWriter_1.writeInt32LE)(writer,
|
|
690
|
+
(0, psdWriter_1.writeInt32LE)(writer, length);
|
|
707
691
|
(0, psdWriter_1.writeInt32LE)(writer, value.path.length);
|
|
708
692
|
(0, psdWriter_1.writeUnicodeStringWithoutLengthLE)(writer, value.path);
|
|
709
693
|
break;
|
|
710
694
|
}
|
|
711
695
|
default:
|
|
712
|
-
throw new Error(
|
|
696
|
+
throw new Error(`Not implemented descriptor OSType: ${type}`);
|
|
713
697
|
}
|
|
714
698
|
}
|
|
715
699
|
function readReferenceStructure(reader) {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
for (
|
|
719
|
-
|
|
700
|
+
const itemsCount = (0, psdReader_1.readInt32)(reader);
|
|
701
|
+
const items = [];
|
|
702
|
+
for (let i = 0; i < itemsCount; i++) {
|
|
703
|
+
const type = (0, psdReader_1.readSignature)(reader);
|
|
720
704
|
switch (type) {
|
|
721
705
|
case 'prop': { // Property
|
|
722
706
|
readClassStructure(reader);
|
|
723
|
-
|
|
707
|
+
const keyID = readAsciiStringOrClassId(reader);
|
|
724
708
|
items.push(keyID);
|
|
725
709
|
break;
|
|
726
710
|
}
|
|
@@ -729,9 +713,9 @@ function readReferenceStructure(reader) {
|
|
|
729
713
|
break;
|
|
730
714
|
case 'Enmr': { // Enumerated Reference
|
|
731
715
|
readClassStructure(reader);
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
items.push(
|
|
716
|
+
const typeID = readAsciiStringOrClassId(reader);
|
|
717
|
+
const value = readAsciiStringOrClassId(reader);
|
|
718
|
+
items.push(`${typeID}.${value}`);
|
|
735
719
|
break;
|
|
736
720
|
}
|
|
737
721
|
case 'rele': { // Offset
|
|
@@ -752,16 +736,16 @@ function readReferenceStructure(reader) {
|
|
|
752
736
|
break;
|
|
753
737
|
}
|
|
754
738
|
default:
|
|
755
|
-
throw new Error(
|
|
739
|
+
throw new Error(`Invalid descriptor reference type: ${type}`);
|
|
756
740
|
}
|
|
757
741
|
}
|
|
758
742
|
return items;
|
|
759
743
|
}
|
|
760
744
|
function writeReferenceStructure(writer, _key, items) {
|
|
761
745
|
(0, psdWriter_1.writeInt32)(writer, items.length);
|
|
762
|
-
for (
|
|
763
|
-
|
|
764
|
-
|
|
746
|
+
for (let i = 0; i < items.length; i++) {
|
|
747
|
+
const value = items[i];
|
|
748
|
+
let type = 'unknown';
|
|
765
749
|
if (typeof value === 'string') {
|
|
766
750
|
if (/^[a-z ]+\.[a-z ]+$/i.test(value)) {
|
|
767
751
|
type = 'Enmr';
|
|
@@ -775,7 +759,7 @@ function writeReferenceStructure(writer, _key, items) {
|
|
|
775
759
|
// case 'prop': // Property
|
|
776
760
|
// case 'Clss': // Class
|
|
777
761
|
case 'Enmr': { // Enumerated Reference
|
|
778
|
-
|
|
762
|
+
const [typeID, enumValue] = value.split('.');
|
|
779
763
|
writeClassStructure(writer, '\0', typeID);
|
|
780
764
|
writeAsciiStringOrClassId(writer, typeID);
|
|
781
765
|
writeAsciiStringOrClassId(writer, enumValue);
|
|
@@ -790,32 +774,30 @@ function writeReferenceStructure(writer, _key, items) {
|
|
|
790
774
|
break;
|
|
791
775
|
}
|
|
792
776
|
default:
|
|
793
|
-
throw new Error(
|
|
777
|
+
throw new Error(`Invalid descriptor reference type: ${type}`);
|
|
794
778
|
}
|
|
795
779
|
}
|
|
796
780
|
return items;
|
|
797
781
|
}
|
|
798
782
|
function readClassStructure(reader) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
return { name
|
|
783
|
+
const name = (0, psdReader_1.readUnicodeString)(reader);
|
|
784
|
+
const classID = readAsciiStringOrClassId(reader);
|
|
785
|
+
return { name, classID };
|
|
802
786
|
}
|
|
803
787
|
function writeClassStructure(writer, name, classID) {
|
|
804
788
|
(0, psdWriter_1.writeUnicodeString)(writer, name);
|
|
805
789
|
writeAsciiStringOrClassId(writer, classID);
|
|
806
790
|
}
|
|
807
|
-
function readVersionAndDescriptor(reader, includeClass) {
|
|
808
|
-
|
|
809
|
-
var version = (0, psdReader_1.readUint32)(reader);
|
|
791
|
+
function readVersionAndDescriptor(reader, includeClass = false) {
|
|
792
|
+
const version = (0, psdReader_1.readUint32)(reader);
|
|
810
793
|
if (version !== 16)
|
|
811
|
-
throw new Error(
|
|
812
|
-
|
|
794
|
+
throw new Error(`Invalid descriptor version: ${version}`);
|
|
795
|
+
const desc = readDescriptorStructure(reader, includeClass);
|
|
813
796
|
// console.log(require('util').inspect(desc, false, 99, true));
|
|
814
797
|
return desc;
|
|
815
798
|
}
|
|
816
799
|
exports.readVersionAndDescriptor = readVersionAndDescriptor;
|
|
817
|
-
function writeVersionAndDescriptor(writer, name, classID, descriptor, root) {
|
|
818
|
-
if (root === void 0) { root = ''; }
|
|
800
|
+
function writeVersionAndDescriptor(writer, name, classID, descriptor, root = '') {
|
|
819
801
|
(0, psdWriter_1.writeUint32)(writer, 16); // version
|
|
820
802
|
writeDescriptorStructure(writer, name, classID, descriptor, root);
|
|
821
803
|
}
|
|
@@ -838,18 +820,16 @@ function descBoundsToBounds(desc) {
|
|
|
838
820
|
}
|
|
839
821
|
exports.descBoundsToBounds = descBoundsToBounds;
|
|
840
822
|
function boundsToDescBounds(bounds) {
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
_a.Btom = unitsValue(bounds.bottom, 'bounds.bottom'),
|
|
848
|
-
_a;
|
|
823
|
+
return {
|
|
824
|
+
Left: unitsValue(bounds.left, 'bounds.left'),
|
|
825
|
+
['Top ']: unitsValue(bounds.top, 'bounds.top'),
|
|
826
|
+
Rght: unitsValue(bounds.right, 'bounds.right'),
|
|
827
|
+
Btom: unitsValue(bounds.bottom, 'bounds.bottom'),
|
|
828
|
+
};
|
|
849
829
|
}
|
|
850
830
|
exports.boundsToDescBounds = boundsToDescBounds;
|
|
851
831
|
function parseFxObject(fx) {
|
|
852
|
-
|
|
832
|
+
const stroke = {
|
|
853
833
|
enabled: !!fx.enab,
|
|
854
834
|
position: exports.FStl.decode(fx.Styl),
|
|
855
835
|
fillType: exports.FrFl.decode(fx.PntT),
|
|
@@ -872,7 +852,7 @@ function parseFxObject(fx) {
|
|
|
872
852
|
return stroke;
|
|
873
853
|
}
|
|
874
854
|
function serializeFxObject(stroke) {
|
|
875
|
-
|
|
855
|
+
let FrFX = {};
|
|
876
856
|
FrFX.enab = !!stroke.enabled;
|
|
877
857
|
if (stroke.present !== undefined)
|
|
878
858
|
FrFX.present = !!stroke.present;
|
|
@@ -886,46 +866,45 @@ function serializeFxObject(stroke) {
|
|
|
886
866
|
if (stroke.color)
|
|
887
867
|
FrFX['Clr '] = serializeColor(stroke.color);
|
|
888
868
|
if (stroke.gradient)
|
|
889
|
-
FrFX =
|
|
869
|
+
FrFX = Object.assign(Object.assign({}, FrFX), serializeGradientContent(stroke.gradient));
|
|
890
870
|
if (stroke.pattern)
|
|
891
|
-
FrFX =
|
|
871
|
+
FrFX = Object.assign(Object.assign({}, FrFX), serializePatternContent(stroke.pattern));
|
|
892
872
|
if (stroke.overprint !== undefined)
|
|
893
873
|
FrFX.overprint = !!stroke.overprint;
|
|
894
874
|
return FrFX;
|
|
895
875
|
}
|
|
896
876
|
function serializeEffects(e, log, multi) {
|
|
897
877
|
var _a, _b, _c;
|
|
898
|
-
|
|
878
|
+
const info = multi ? {
|
|
899
879
|
'Scl ': unitsPercentF((_a = e.scale) !== null && _a !== void 0 ? _a : 1),
|
|
900
880
|
masterFXSwitch: !e.disabled,
|
|
901
881
|
} : {
|
|
902
882
|
masterFXSwitch: !e.disabled,
|
|
903
883
|
'Scl ': unitsPercentF((_b = e.scale) !== null && _b !== void 0 ? _b : 1),
|
|
904
884
|
};
|
|
905
|
-
|
|
906
|
-
for (
|
|
907
|
-
var key = arrayKeys_1[_i];
|
|
885
|
+
const arrayKeys = ['dropShadow', 'innerShadow', 'solidFill', 'gradientOverlay', 'stroke'];
|
|
886
|
+
for (const key of arrayKeys) {
|
|
908
887
|
if (e[key] && !Array.isArray(e[key]))
|
|
909
|
-
throw new Error(
|
|
888
|
+
throw new Error(`${key} should be an array`);
|
|
910
889
|
}
|
|
911
|
-
|
|
912
|
-
|
|
890
|
+
const useMulti = (arr) => !!arr && arr.length > 1 && multi;
|
|
891
|
+
const useSingle = (arr) => !!arr && arr.length >= 1 && (!multi || arr.length === 1);
|
|
913
892
|
if (useSingle(e.dropShadow))
|
|
914
893
|
info.DrSh = serializeEffectObject(e.dropShadow[0], 'dropShadow', log);
|
|
915
894
|
if (useMulti(e.dropShadow))
|
|
916
|
-
info.dropShadowMulti = e.dropShadow.map(
|
|
895
|
+
info.dropShadowMulti = e.dropShadow.map(i => serializeEffectObject(i, 'dropShadow', log));
|
|
917
896
|
if (useSingle(e.innerShadow))
|
|
918
897
|
info.IrSh = serializeEffectObject(e.innerShadow[0], 'innerShadow', log);
|
|
919
898
|
if (useMulti(e.innerShadow))
|
|
920
|
-
info.innerShadowMulti = e.innerShadow.map(
|
|
899
|
+
info.innerShadowMulti = e.innerShadow.map(i => serializeEffectObject(i, 'innerShadow', log));
|
|
921
900
|
if (e.outerGlow)
|
|
922
901
|
info.OrGl = serializeEffectObject(e.outerGlow, 'outerGlow', log);
|
|
923
902
|
if (useMulti(e.solidFill))
|
|
924
|
-
info.solidFillMulti = e.solidFill.map(
|
|
903
|
+
info.solidFillMulti = e.solidFill.map(i => serializeEffectObject(i, 'solidFill', log));
|
|
925
904
|
if (useMulti(e.gradientOverlay))
|
|
926
|
-
info.gradientFillMulti = e.gradientOverlay.map(
|
|
905
|
+
info.gradientFillMulti = e.gradientOverlay.map(i => serializeEffectObject(i, 'gradientOverlay', log));
|
|
927
906
|
if (useMulti(e.stroke))
|
|
928
|
-
info.frameFXMulti = e.stroke.map(
|
|
907
|
+
info.frameFXMulti = e.stroke.map(i => serializeFxObject(i));
|
|
929
908
|
if (e.innerGlow)
|
|
930
909
|
info.IrGl = serializeEffectObject(e.innerGlow, 'innerGlow', log);
|
|
931
910
|
if (e.bevel)
|
|
@@ -942,12 +921,10 @@ function serializeEffects(e, log, multi) {
|
|
|
942
921
|
info.FrFX = serializeFxObject((_c = e.stroke) === null || _c === void 0 ? void 0 : _c[0]);
|
|
943
922
|
if (multi) {
|
|
944
923
|
info.numModifyingFX = 0;
|
|
945
|
-
for (
|
|
946
|
-
|
|
947
|
-
var value = e[key];
|
|
924
|
+
for (const key of Object.keys(e)) {
|
|
925
|
+
const value = e[key];
|
|
948
926
|
if (Array.isArray(value)) {
|
|
949
|
-
for (
|
|
950
|
-
var effect = value_1[_f];
|
|
927
|
+
for (const effect of value) {
|
|
951
928
|
if (effect.enabled)
|
|
952
929
|
info.numModifyingFX++;
|
|
953
930
|
}
|
|
@@ -961,8 +938,8 @@ function serializeEffects(e, log, multi) {
|
|
|
961
938
|
}
|
|
962
939
|
exports.serializeEffects = serializeEffects;
|
|
963
940
|
function parseEffects(info, log) {
|
|
964
|
-
|
|
965
|
-
|
|
941
|
+
const effects = {};
|
|
942
|
+
const { masterFXSwitch, DrSh, dropShadowMulti, IrSh, innerShadowMulti, OrGl, IrGl, ebbl, SoFi, solidFillMulti, patternFill, GrFl, gradientFillMulti, ChFX, FrFX, frameFXMulti, numModifyingFX } = info, rest = __rest(info, ["masterFXSwitch", "DrSh", "dropShadowMulti", "IrSh", "innerShadowMulti", "OrGl", "IrGl", "ebbl", "SoFi", "solidFillMulti", "patternFill", "GrFl", "gradientFillMulti", "ChFX", "FrFX", "frameFXMulti", "numModifyingFX"]);
|
|
966
943
|
if (!masterFXSwitch)
|
|
967
944
|
effects.disabled = true;
|
|
968
945
|
if (info['Scl '])
|
|
@@ -970,11 +947,11 @@ function parseEffects(info, log) {
|
|
|
970
947
|
if (DrSh)
|
|
971
948
|
effects.dropShadow = [parseEffectObject(DrSh, log)];
|
|
972
949
|
if (dropShadowMulti)
|
|
973
|
-
effects.dropShadow = dropShadowMulti.map(
|
|
950
|
+
effects.dropShadow = dropShadowMulti.map(i => parseEffectObject(i, log));
|
|
974
951
|
if (IrSh)
|
|
975
952
|
effects.innerShadow = [parseEffectObject(IrSh, log)];
|
|
976
953
|
if (innerShadowMulti)
|
|
977
|
-
effects.innerShadow = innerShadowMulti.map(
|
|
954
|
+
effects.innerShadow = innerShadowMulti.map(i => parseEffectObject(i, log));
|
|
978
955
|
if (OrGl)
|
|
979
956
|
effects.outerGlow = parseEffectObject(OrGl, log);
|
|
980
957
|
if (IrGl)
|
|
@@ -984,76 +961,70 @@ function parseEffects(info, log) {
|
|
|
984
961
|
if (SoFi)
|
|
985
962
|
effects.solidFill = [parseEffectObject(SoFi, log)];
|
|
986
963
|
if (solidFillMulti)
|
|
987
|
-
effects.solidFill = solidFillMulti.map(
|
|
964
|
+
effects.solidFill = solidFillMulti.map(i => parseEffectObject(i, log));
|
|
988
965
|
if (patternFill)
|
|
989
966
|
effects.patternOverlay = parseEffectObject(patternFill, log);
|
|
990
967
|
if (GrFl)
|
|
991
968
|
effects.gradientOverlay = [parseEffectObject(GrFl, log)];
|
|
992
969
|
if (gradientFillMulti)
|
|
993
|
-
effects.gradientOverlay = gradientFillMulti.map(
|
|
970
|
+
effects.gradientOverlay = gradientFillMulti.map(i => parseEffectObject(i, log));
|
|
994
971
|
if (ChFX)
|
|
995
972
|
effects.satin = parseEffectObject(ChFX, log);
|
|
996
973
|
if (FrFX)
|
|
997
974
|
effects.stroke = [parseFxObject(FrFX)];
|
|
998
975
|
if (frameFXMulti)
|
|
999
|
-
effects.stroke = frameFXMulti.map(
|
|
976
|
+
effects.stroke = frameFXMulti.map(i => parseFxObject(i));
|
|
1000
977
|
if (log && Object.keys(rest).length > 1)
|
|
1001
978
|
console.log('Unhandled effect keys:', rest);
|
|
1002
979
|
return effects;
|
|
1003
980
|
}
|
|
1004
981
|
exports.parseEffects = parseEffects;
|
|
1005
982
|
function parseKeyList(keyList, logMissingFeatures) {
|
|
1006
|
-
|
|
1007
|
-
for (
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
983
|
+
const keys = [];
|
|
984
|
+
for (let j = 0; j < keyList.length; j++) {
|
|
985
|
+
const key = keyList[j];
|
|
986
|
+
const { time: { denominator, numerator }, selected, animKey } = key;
|
|
987
|
+
const time = { numerator, denominator };
|
|
988
|
+
const interpolation = exports.animInterpStyleEnum.decode(key.animInterpStyle);
|
|
1012
989
|
switch (animKey.Type) {
|
|
1013
990
|
case 'keyType.Opct':
|
|
1014
|
-
keys.push({ interpolation
|
|
991
|
+
keys.push({ interpolation, time, selected, type: 'opacity', value: parsePercent(animKey.Opct) });
|
|
1015
992
|
break;
|
|
1016
993
|
case 'keyType.Pstn':
|
|
1017
|
-
keys.push({ interpolation
|
|
994
|
+
keys.push({ interpolation, time, selected, type: 'position', x: animKey.Hrzn, y: animKey.Vrtc });
|
|
1018
995
|
break;
|
|
1019
996
|
case 'keyType.Trnf':
|
|
1020
997
|
keys.push({
|
|
1021
|
-
interpolation:
|
|
1022
|
-
time: time,
|
|
1023
|
-
selected: selected,
|
|
1024
|
-
type: 'transform',
|
|
998
|
+
interpolation, time, selected, type: 'transform',
|
|
1025
999
|
scale: horzVrtcToXY(animKey['Scl ']), skew: horzVrtcToXY(animKey.Skew), rotation: animKey.rotation, translation: horzVrtcToXY(animKey.translation)
|
|
1026
1000
|
});
|
|
1027
1001
|
break;
|
|
1028
1002
|
case 'keyType.sheetStyle': {
|
|
1029
|
-
|
|
1003
|
+
const key = { interpolation, time, selected, type: 'style' };
|
|
1030
1004
|
if (animKey.sheetStyle.Lefx)
|
|
1031
|
-
|
|
1032
|
-
keys.push(
|
|
1005
|
+
key.style = parseEffects(animKey.sheetStyle.Lefx, logMissingFeatures);
|
|
1006
|
+
keys.push(key);
|
|
1033
1007
|
break;
|
|
1034
1008
|
}
|
|
1035
1009
|
case 'keyType.globalLighting': {
|
|
1036
1010
|
keys.push({
|
|
1037
|
-
interpolation:
|
|
1038
|
-
time: time,
|
|
1039
|
-
selected: selected,
|
|
1040
|
-
type: 'globalLighting',
|
|
1011
|
+
interpolation, time, selected, type: 'globalLighting',
|
|
1041
1012
|
globalAngle: animKey.gblA, globalAltitude: animKey.globalAltitude
|
|
1042
1013
|
});
|
|
1043
1014
|
break;
|
|
1044
1015
|
}
|
|
1045
|
-
default: throw new Error(
|
|
1016
|
+
default: throw new Error(`Unsupported keyType value`);
|
|
1046
1017
|
}
|
|
1047
1018
|
}
|
|
1048
1019
|
return keys;
|
|
1049
1020
|
}
|
|
1050
1021
|
function serializeKeyList(keys) {
|
|
1051
|
-
|
|
1052
|
-
for (
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1022
|
+
const keyList = [];
|
|
1023
|
+
for (let j = 0; j < keys.length; j++) {
|
|
1024
|
+
const key = keys[j];
|
|
1025
|
+
const { time, selected = false, interpolation } = key;
|
|
1026
|
+
const animInterpStyle = exports.animInterpStyleEnum.encode(interpolation);
|
|
1027
|
+
let animKey;
|
|
1057
1028
|
switch (key.type) {
|
|
1058
1029
|
case 'opacity':
|
|
1059
1030
|
animKey = { Type: 'keyType.Opct', Opct: unitsPercent(key.value) };
|
|
@@ -1073,17 +1044,17 @@ function serializeKeyList(keys) {
|
|
|
1073
1044
|
animKey = { Type: 'keyType.globalLighting', gblA: key.globalAngle, globalAltitude: key.globalAltitude };
|
|
1074
1045
|
break;
|
|
1075
1046
|
}
|
|
1076
|
-
default: throw new Error(
|
|
1047
|
+
default: throw new Error(`Unsupported keyType value`);
|
|
1077
1048
|
}
|
|
1078
|
-
keyList.push({ Vrsn: 1, animInterpStyle
|
|
1049
|
+
keyList.push({ Vrsn: 1, animInterpStyle, time, animKey, selected });
|
|
1079
1050
|
}
|
|
1080
1051
|
return keyList;
|
|
1081
1052
|
}
|
|
1082
1053
|
function parseTrackList(trackList, logMissingFeatures) {
|
|
1083
|
-
|
|
1084
|
-
for (
|
|
1085
|
-
|
|
1086
|
-
|
|
1054
|
+
const tracks = [];
|
|
1055
|
+
for (let i = 0; i < trackList.length; i++) {
|
|
1056
|
+
const tr = trackList[i];
|
|
1057
|
+
const track = {
|
|
1087
1058
|
type: exports.stdTrackID.decode(tr.trackID),
|
|
1088
1059
|
enabled: tr.enab,
|
|
1089
1060
|
keys: parseKeyList(tr.keyList, logMissingFeatures),
|
|
@@ -1101,10 +1072,10 @@ function parseTrackList(trackList, logMissingFeatures) {
|
|
|
1101
1072
|
}
|
|
1102
1073
|
exports.parseTrackList = parseTrackList;
|
|
1103
1074
|
function serializeTrackList(tracks) {
|
|
1104
|
-
|
|
1105
|
-
for (
|
|
1106
|
-
|
|
1107
|
-
trackList.push(
|
|
1075
|
+
const trackList = [];
|
|
1076
|
+
for (let i = 0; i < tracks.length; i++) {
|
|
1077
|
+
const t = tracks[i];
|
|
1078
|
+
trackList.push(Object.assign(Object.assign({ trackID: exports.stdTrackID.encode(t.type), Vrsn: 1, enab: !!t.enabled, Effc: !!t.effectParams }, (t.effectParams ? {
|
|
1108
1079
|
effectParams: {
|
|
1109
1080
|
keyList: serializeKeyList(t.keys),
|
|
1110
1081
|
fillCanvas: t.effectParams.fillCanvas,
|
|
@@ -1116,10 +1087,9 @@ function serializeTrackList(tracks) {
|
|
|
1116
1087
|
}
|
|
1117
1088
|
exports.serializeTrackList = serializeTrackList;
|
|
1118
1089
|
function parseEffectObject(obj, reportErrors) {
|
|
1119
|
-
|
|
1120
|
-
for (
|
|
1121
|
-
|
|
1122
|
-
var val = obj[key];
|
|
1090
|
+
const result = {};
|
|
1091
|
+
for (const key of Object.keys(obj)) {
|
|
1092
|
+
const val = obj[key];
|
|
1123
1093
|
switch (key) {
|
|
1124
1094
|
case 'enab':
|
|
1125
1095
|
result.enabled = !!val;
|
|
@@ -1242,7 +1212,7 @@ function parseEffectObject(obj, reportErrors) {
|
|
|
1242
1212
|
case 'TrnS':
|
|
1243
1213
|
result.contour = {
|
|
1244
1214
|
name: val['Nm '],
|
|
1245
|
-
curve: val['Crv '].map(
|
|
1215
|
+
curve: val['Crv '].map(p => ({ x: p.Hrzn, y: p.Vrtc })),
|
|
1246
1216
|
};
|
|
1247
1217
|
break;
|
|
1248
1218
|
case 'Grad':
|
|
@@ -1260,22 +1230,21 @@ function parseEffectObject(obj, reportErrors) {
|
|
|
1260
1230
|
case '_classID':
|
|
1261
1231
|
break;
|
|
1262
1232
|
default:
|
|
1263
|
-
reportErrors && console.log(
|
|
1233
|
+
reportErrors && console.log(`Invalid effect key: '${key}', value:`, val);
|
|
1264
1234
|
}
|
|
1265
1235
|
}
|
|
1266
1236
|
return result;
|
|
1267
1237
|
}
|
|
1268
1238
|
function serializeEffectObject(obj, objName, reportErrors) {
|
|
1269
|
-
|
|
1239
|
+
const result = {
|
|
1270
1240
|
enab: false,
|
|
1271
1241
|
};
|
|
1272
1242
|
if (objName === 'dropShadow') {
|
|
1273
1243
|
result.TrnS = { 'Nm ': '', 'Crv ': [] };
|
|
1274
1244
|
}
|
|
1275
|
-
for (
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
var val = obj[key];
|
|
1245
|
+
for (const objKey of Object.keys(obj)) {
|
|
1246
|
+
const key = objKey;
|
|
1247
|
+
const val = obj[key];
|
|
1279
1248
|
switch (key) {
|
|
1280
1249
|
case 'enabled':
|
|
1281
1250
|
result.enab = !!val;
|
|
@@ -1401,7 +1370,7 @@ function serializeEffectObject(obj, objName, reportErrors) {
|
|
|
1401
1370
|
case 'contour': {
|
|
1402
1371
|
result[objName === 'satin' ? 'MpgS' : 'TrnS'] = {
|
|
1403
1372
|
'Nm ': val.name,
|
|
1404
|
-
'Crv ': val.curve.map(
|
|
1373
|
+
'Crv ': val.curve.map(p => ({ Hrzn: p.x, Vrtc: p.y })),
|
|
1405
1374
|
};
|
|
1406
1375
|
break;
|
|
1407
1376
|
}
|
|
@@ -1417,28 +1386,28 @@ function serializeEffectObject(obj, objName, reportErrors) {
|
|
|
1417
1386
|
result[key] = val;
|
|
1418
1387
|
break;
|
|
1419
1388
|
default:
|
|
1420
|
-
reportErrors && console.log(
|
|
1389
|
+
reportErrors && console.log(`Invalid effect key: '${key}', value:`, val);
|
|
1421
1390
|
}
|
|
1422
1391
|
}
|
|
1423
1392
|
return result;
|
|
1424
1393
|
}
|
|
1425
1394
|
function parseGradient(grad) {
|
|
1426
1395
|
if (grad.GrdF === 'GrdF.CstS') {
|
|
1427
|
-
|
|
1396
|
+
const samples = grad.Intr || 4096;
|
|
1428
1397
|
return {
|
|
1429
1398
|
type: 'solid',
|
|
1430
1399
|
name: grad['Nm '],
|
|
1431
1400
|
smoothness: grad.Intr / 4096,
|
|
1432
|
-
colorStops: grad.Clrs.map(
|
|
1401
|
+
colorStops: grad.Clrs.map(s => ({
|
|
1433
1402
|
color: parseColor(s['Clr ']),
|
|
1434
|
-
location: s.Lctn /
|
|
1403
|
+
location: s.Lctn / samples,
|
|
1435
1404
|
midpoint: s.Mdpn / 100,
|
|
1436
|
-
})
|
|
1437
|
-
opacityStops: grad.Trns.map(
|
|
1405
|
+
})),
|
|
1406
|
+
opacityStops: grad.Trns.map(s => ({
|
|
1438
1407
|
opacity: parsePercent(s.Opct),
|
|
1439
|
-
location: s.Lctn /
|
|
1408
|
+
location: s.Lctn / samples,
|
|
1440
1409
|
midpoint: s.Mdpn / 100,
|
|
1441
|
-
})
|
|
1410
|
+
})),
|
|
1442
1411
|
};
|
|
1443
1412
|
}
|
|
1444
1413
|
else {
|
|
@@ -1450,33 +1419,33 @@ function parseGradient(grad) {
|
|
|
1450
1419
|
randomSeed: grad.RndS,
|
|
1451
1420
|
restrictColors: !!grad.VctC,
|
|
1452
1421
|
addTransparency: !!grad.ShTr,
|
|
1453
|
-
min: grad['Mnm '].map(
|
|
1454
|
-
max: grad['Mxm '].map(
|
|
1422
|
+
min: grad['Mnm '].map(x => x / 100),
|
|
1423
|
+
max: grad['Mxm '].map(x => x / 100),
|
|
1455
1424
|
};
|
|
1456
1425
|
}
|
|
1457
1426
|
}
|
|
1458
1427
|
function serializeGradient(grad) {
|
|
1459
1428
|
var _a, _b;
|
|
1460
1429
|
if (grad.type === 'solid') {
|
|
1461
|
-
|
|
1430
|
+
const samples = Math.round(((_a = grad.smoothness) !== null && _a !== void 0 ? _a : 1) * 4096);
|
|
1462
1431
|
return {
|
|
1463
1432
|
'Nm ': grad.name || '',
|
|
1464
1433
|
GrdF: 'GrdF.CstS',
|
|
1465
|
-
Intr:
|
|
1466
|
-
Clrs: grad.colorStops.map(
|
|
1434
|
+
Intr: samples,
|
|
1435
|
+
Clrs: grad.colorStops.map(s => {
|
|
1467
1436
|
var _a;
|
|
1468
1437
|
return ({
|
|
1469
1438
|
'Clr ': serializeColor(s.color),
|
|
1470
1439
|
Type: 'Clry.UsrS',
|
|
1471
|
-
Lctn: Math.round(s.location *
|
|
1440
|
+
Lctn: Math.round(s.location * samples),
|
|
1472
1441
|
Mdpn: Math.round(((_a = s.midpoint) !== null && _a !== void 0 ? _a : 0.5) * 100),
|
|
1473
1442
|
});
|
|
1474
1443
|
}),
|
|
1475
|
-
Trns: grad.opacityStops.map(
|
|
1444
|
+
Trns: grad.opacityStops.map(s => {
|
|
1476
1445
|
var _a;
|
|
1477
1446
|
return ({
|
|
1478
1447
|
Opct: unitsPercent(s.opacity),
|
|
1479
|
-
Lctn: Math.round(s.location *
|
|
1448
|
+
Lctn: Math.round(s.location * samples),
|
|
1480
1449
|
Mdpn: Math.round(((_a = s.midpoint) !== null && _a !== void 0 ? _a : 0.5) * 100),
|
|
1481
1450
|
});
|
|
1482
1451
|
}),
|
|
@@ -1491,13 +1460,13 @@ function serializeGradient(grad) {
|
|
|
1491
1460
|
ClrS: exports.ClrS.encode(grad.colorModel),
|
|
1492
1461
|
RndS: grad.randomSeed || 0,
|
|
1493
1462
|
Smth: Math.round(((_b = grad.roughness) !== null && _b !== void 0 ? _b : 1) * 4096),
|
|
1494
|
-
'Mnm ': (grad.min || [0, 0, 0, 0]).map(
|
|
1495
|
-
'Mxm ': (grad.max || [1, 1, 1, 1]).map(
|
|
1463
|
+
'Mnm ': (grad.min || [0, 0, 0, 0]).map(x => x * 100),
|
|
1464
|
+
'Mxm ': (grad.max || [1, 1, 1, 1]).map(x => x * 100),
|
|
1496
1465
|
};
|
|
1497
1466
|
}
|
|
1498
1467
|
}
|
|
1499
1468
|
function parseGradientContent(descriptor) {
|
|
1500
|
-
|
|
1469
|
+
const result = parseGradient(descriptor.Grad);
|
|
1501
1470
|
result.style = exports.GrdT.decode(descriptor.Type);
|
|
1502
1471
|
if (descriptor.Dthr !== undefined)
|
|
1503
1472
|
result.dither = descriptor.Dthr;
|
|
@@ -1520,7 +1489,7 @@ function parseGradientContent(descriptor) {
|
|
|
1520
1489
|
return result;
|
|
1521
1490
|
}
|
|
1522
1491
|
function parsePatternContent(descriptor) {
|
|
1523
|
-
|
|
1492
|
+
const result = {
|
|
1524
1493
|
name: descriptor.Ptrn['Nm '],
|
|
1525
1494
|
id: descriptor.Ptrn.Idnt,
|
|
1526
1495
|
};
|
|
@@ -1535,7 +1504,7 @@ function parseVectorContent(descriptor) {
|
|
|
1535
1504
|
return parseGradientContent(descriptor);
|
|
1536
1505
|
}
|
|
1537
1506
|
else if ('Ptrn' in descriptor) {
|
|
1538
|
-
return
|
|
1507
|
+
return Object.assign({ type: 'pattern' }, parsePatternContent(descriptor));
|
|
1539
1508
|
}
|
|
1540
1509
|
else if ('Clr ' in descriptor) {
|
|
1541
1510
|
return { type: 'color', color: parseColor(descriptor['Clr ']) };
|
|
@@ -1546,7 +1515,7 @@ function parseVectorContent(descriptor) {
|
|
|
1546
1515
|
}
|
|
1547
1516
|
exports.parseVectorContent = parseVectorContent;
|
|
1548
1517
|
function serializeGradientContent(content) {
|
|
1549
|
-
|
|
1518
|
+
const result = {};
|
|
1550
1519
|
if (content.dither !== undefined)
|
|
1551
1520
|
result.Dthr = content.dither;
|
|
1552
1521
|
if (content.interpolationMethod !== undefined)
|
|
@@ -1570,7 +1539,7 @@ function serializeGradientContent(content) {
|
|
|
1570
1539
|
return result;
|
|
1571
1540
|
}
|
|
1572
1541
|
function serializePatternContent(content) {
|
|
1573
|
-
|
|
1542
|
+
const result = {
|
|
1574
1543
|
Ptrn: {
|
|
1575
1544
|
'Nm ': content.name || '',
|
|
1576
1545
|
Idnt: content.id || '',
|
|
@@ -1649,7 +1618,7 @@ function parseAngle(x) {
|
|
|
1649
1618
|
if (x === undefined)
|
|
1650
1619
|
return 0;
|
|
1651
1620
|
if (x.units !== 'Angle')
|
|
1652
|
-
throw new Error(
|
|
1621
|
+
throw new Error(`Invalid units: ${x.units}`);
|
|
1653
1622
|
return x.value;
|
|
1654
1623
|
}
|
|
1655
1624
|
exports.parseAngle = parseAngle;
|
|
@@ -1657,7 +1626,7 @@ function parsePercent(x) {
|
|
|
1657
1626
|
if (x === undefined)
|
|
1658
1627
|
return 1;
|
|
1659
1628
|
if (x.units !== 'Percent')
|
|
1660
|
-
throw new Error(
|
|
1629
|
+
throw new Error(`Invalid units: ${x.units}`);
|
|
1661
1630
|
return x.value / 100;
|
|
1662
1631
|
}
|
|
1663
1632
|
exports.parsePercent = parsePercent;
|
|
@@ -1668,29 +1637,26 @@ function parsePercentOrAngle(x) {
|
|
|
1668
1637
|
return x.value / 100;
|
|
1669
1638
|
if (x.units === 'Angle')
|
|
1670
1639
|
return x.value / 360;
|
|
1671
|
-
throw new Error(
|
|
1640
|
+
throw new Error(`Invalid units: ${x.units}`);
|
|
1672
1641
|
}
|
|
1673
1642
|
exports.parsePercentOrAngle = parsePercentOrAngle;
|
|
1674
|
-
function parseUnits(
|
|
1675
|
-
var units = _a.units, value = _a.value;
|
|
1643
|
+
function parseUnits({ units, value }) {
|
|
1676
1644
|
if (units !== 'Pixels' && units !== 'Millimeters' && units !== 'Points' && units !== 'None' &&
|
|
1677
1645
|
units !== 'Picas' && units !== 'Inches' && units !== 'Centimeters' && units !== 'Density') {
|
|
1678
|
-
throw new Error(
|
|
1646
|
+
throw new Error(`Invalid units: ${JSON.stringify({ units, value })}`);
|
|
1679
1647
|
}
|
|
1680
|
-
return { value
|
|
1648
|
+
return { value, units };
|
|
1681
1649
|
}
|
|
1682
1650
|
exports.parseUnits = parseUnits;
|
|
1683
|
-
function parseUnitsOrNumber(value, units) {
|
|
1684
|
-
if (units === void 0) { units = 'Pixels'; }
|
|
1651
|
+
function parseUnitsOrNumber(value, units = 'Pixels') {
|
|
1685
1652
|
if (typeof value === 'number')
|
|
1686
|
-
return { value
|
|
1653
|
+
return { value, units };
|
|
1687
1654
|
return parseUnits(value);
|
|
1688
1655
|
}
|
|
1689
1656
|
exports.parseUnitsOrNumber = parseUnitsOrNumber;
|
|
1690
|
-
function parseUnitsToNumber(
|
|
1691
|
-
var units = _a.units, value = _a.value;
|
|
1657
|
+
function parseUnitsToNumber({ units, value }, expectedUnits) {
|
|
1692
1658
|
if (units !== expectedUnits)
|
|
1693
|
-
throw new Error(
|
|
1659
|
+
throw new Error(`Invalid units: ${JSON.stringify({ units, value })}`);
|
|
1694
1660
|
return value;
|
|
1695
1661
|
}
|
|
1696
1662
|
exports.parseUnitsToNumber = parseUnitsToNumber;
|
|
@@ -1710,20 +1676,19 @@ function unitsValue(x, key) {
|
|
|
1710
1676
|
if (x == null)
|
|
1711
1677
|
return { units: 'Pixels', value: 0 };
|
|
1712
1678
|
if (typeof x !== 'object')
|
|
1713
|
-
throw new Error(
|
|
1714
|
-
|
|
1679
|
+
throw new Error(`Invalid value: ${JSON.stringify(x)} (key: ${key}) (should have value and units)`);
|
|
1680
|
+
const { units, value } = x;
|
|
1715
1681
|
if (typeof value !== 'number')
|
|
1716
|
-
throw new Error(
|
|
1682
|
+
throw new Error(`Invalid value in ${JSON.stringify(x)} (key: ${key})`);
|
|
1717
1683
|
if (units !== 'Pixels' && units !== 'Millimeters' && units !== 'Points' && units !== 'None' &&
|
|
1718
1684
|
units !== 'Picas' && units !== 'Inches' && units !== 'Centimeters' && units !== 'Density') {
|
|
1719
|
-
throw new Error(
|
|
1685
|
+
throw new Error(`Invalid units in ${JSON.stringify(x)} (key: ${key})`);
|
|
1720
1686
|
}
|
|
1721
|
-
return { units
|
|
1687
|
+
return { units, value };
|
|
1722
1688
|
}
|
|
1723
1689
|
exports.unitsValue = unitsValue;
|
|
1724
|
-
function frac(
|
|
1725
|
-
|
|
1726
|
-
return { numerator: numerator, denominator: denominator };
|
|
1690
|
+
function frac({ numerator, denominator }) {
|
|
1691
|
+
return { numerator, denominator };
|
|
1727
1692
|
}
|
|
1728
1693
|
exports.frac = frac;
|
|
1729
1694
|
exports.textGridding = (0, helpers_1.createEnum)('textGridding', 'none', {
|