ag-psd 15.3.1 → 17.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.
- package/CHANGELOG.md +9 -0
- package/README.md +1 -0
- package/dist/additionalInfo.js +864 -157
- package/dist/additionalInfo.js.map +1 -1
- package/dist/bundle.js +1223 -242
- package/dist/descriptor.d.ts +129 -0
- package/dist/descriptor.js +272 -36
- package/dist/descriptor.js.map +1 -1
- package/dist/imageResources.js +9 -17
- package/dist/imageResources.js.map +1 -1
- package/dist/psd.d.ts +450 -74
- package/dist/psdReader.d.ts +2 -0
- package/dist/psdReader.js +30 -13
- package/dist/psdReader.js.map +1 -1
- package/dist/psdWriter.d.ts +4 -0
- package/dist/psdWriter.js +25 -7
- package/dist/psdWriter.js.map +1 -1
- package/dist/text.js +23 -12
- package/dist/text.js.map +1 -1
- package/dist-es/additionalInfo.js +865 -158
- package/dist-es/additionalInfo.js.map +1 -1
- package/dist-es/descriptor.d.ts +129 -0
- package/dist-es/descriptor.js +270 -37
- package/dist-es/descriptor.js.map +1 -1
- package/dist-es/imageResources.js +10 -18
- package/dist-es/imageResources.js.map +1 -1
- package/dist-es/psd.d.ts +450 -74
- package/dist-es/psdReader.d.ts +2 -0
- package/dist-es/psdReader.js +27 -12
- package/dist-es/psdReader.js.map +1 -1
- package/dist-es/psdWriter.d.ts +4 -0
- package/dist-es/psdWriter.js +21 -7
- package/dist-es/psdWriter.js.map +1 -1
- package/dist-es/text.js +23 -12
- package/dist-es/text.js.map +1 -1
- package/package.json +1 -1
- package/src/additionalInfo.ts +1956 -212
- package/src/descriptor.ts +297 -37
- package/src/imageResources.ts +14 -19
- package/src/psd.ts +472 -49
- package/src/psdReader.ts +26 -7
- package/src/psdWriter.ts +24 -8
- package/src/text.ts +22 -14
package/src/psdWriter.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
offsetForChannel, createImageData, fromBlendMode, ChannelID, Compression, clamp,
|
|
5
5
|
LayerMaskFlags, MaskParams, ColorSpace, Bounds, largeAdditionalInfoKeys, RAW_IMAGE_DATA, writeDataZipWithoutPrediction
|
|
6
6
|
} from './helpers';
|
|
7
|
-
import { ExtendedWriteOptions,
|
|
7
|
+
import { ExtendedWriteOptions, infoHandlers } from './additionalInfo';
|
|
8
8
|
import { resourceHandlers } from './imageResources';
|
|
9
9
|
|
|
10
10
|
export interface PsdWriter {
|
|
@@ -43,11 +43,21 @@ export function writeUint16(writer: PsdWriter, value: number) {
|
|
|
43
43
|
writer.view.setUint16(offset, value, false);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
export function writeUint16LE(writer: PsdWriter, value: number) {
|
|
47
|
+
const offset = addSize(writer, 2);
|
|
48
|
+
writer.view.setUint16(offset, value, true);
|
|
49
|
+
}
|
|
50
|
+
|
|
46
51
|
export function writeInt32(writer: PsdWriter, value: number) {
|
|
47
52
|
const offset = addSize(writer, 4);
|
|
48
53
|
writer.view.setInt32(offset, value, false);
|
|
49
54
|
}
|
|
50
55
|
|
|
56
|
+
export function writeInt32LE(writer: PsdWriter, value: number) {
|
|
57
|
+
const offset = addSize(writer, 4);
|
|
58
|
+
writer.view.setInt32(offset, value, true);
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
export function writeUint32(writer: PsdWriter, value: number) {
|
|
52
62
|
const offset = addSize(writer, 4);
|
|
53
63
|
writer.view.setUint32(offset, value, false);
|
|
@@ -110,14 +120,23 @@ export function writePascalString(writer: PsdWriter, text: string, padTo: number
|
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
|
|
113
|
-
export function
|
|
114
|
-
writeUint32(writer, text.length);
|
|
115
|
-
|
|
123
|
+
export function writeUnicodeStringWithoutLength(writer: PsdWriter, text: string) {
|
|
116
124
|
for (let i = 0; i < text.length; i++) {
|
|
117
125
|
writeUint16(writer, text.charCodeAt(i));
|
|
118
126
|
}
|
|
119
127
|
}
|
|
120
128
|
|
|
129
|
+
export function writeUnicodeStringWithoutLengthLE(writer: PsdWriter, text: string) {
|
|
130
|
+
for (let i = 0; i < text.length; i++) {
|
|
131
|
+
writeUint16LE(writer, text.charCodeAt(i));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function writeUnicodeString(writer: PsdWriter, text: string) {
|
|
136
|
+
writeUint32(writer, text.length);
|
|
137
|
+
writeUnicodeStringWithoutLength(writer, text);
|
|
138
|
+
}
|
|
139
|
+
|
|
121
140
|
export function writeUnicodeStringWithPadding(writer: PsdWriter, text: string) {
|
|
122
141
|
writeUint32(writer, text.length + 1);
|
|
123
142
|
|
|
@@ -304,10 +323,7 @@ function writeLayerInfo(tempBuffer: Uint8Array, writer: PsdWriter, psd: Psd, glo
|
|
|
304
323
|
if (layer.vectorMask || (layer.sectionDivider && layer.sectionDivider.type !== SectionDividerType.Other)) {
|
|
305
324
|
flags |= 0x10; // pixel data irrelevant to appearance of document
|
|
306
325
|
}
|
|
307
|
-
if (layer.
|
|
308
|
-
flags |= 0x20; // just guessing this one, might be completely incorrect
|
|
309
|
-
}
|
|
310
|
-
// if ('_2' in layer) flags |= 0x20; // TEMP!!!
|
|
326
|
+
if (layer.effectsOpen) flags |= 0x20;
|
|
311
327
|
|
|
312
328
|
writeUint8(writer, flags);
|
|
313
329
|
writeUint8(writer, 0); // filler
|
package/src/text.ts
CHANGED
|
@@ -263,24 +263,32 @@ const antialias: AntiAlias[] = ['none', 'crisp', 'strong', 'smooth', 'sharp'];
|
|
|
263
263
|
const justification: Justification[] = ['left', 'right', 'center'];
|
|
264
264
|
|
|
265
265
|
function upperFirst(value: string) {
|
|
266
|
-
return value.
|
|
266
|
+
return value.substring(0, 1).toUpperCase() + value.substring(1);
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
function decodeColor(color:
|
|
269
|
+
function decodeColor(color: TypeValues): Color {
|
|
270
270
|
const c = color.Values;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
switch (color.Type) {
|
|
272
|
+
case 0: return { k: c[1] * 255 }; // grayscale (alpha?)
|
|
273
|
+
case 1: return c[0] === 1 ?
|
|
274
|
+
{ r: c[1] * 255, g: c[2] * 255, b: c[3] * 255 } : // rgb
|
|
275
|
+
{ r: c[1] * 255, g: c[2] * 255, b: c[3] * 255, a: c[0] * 255 }; // rgba
|
|
276
|
+
case 2: return { c: c[1] * 255, m: c[2] * 255, y: c[3] * 255, k: c[4] * 255 }; // cmyk (alpha?)
|
|
277
|
+
default: throw new Error('Unknown color type in text layer');
|
|
276
278
|
}
|
|
277
279
|
}
|
|
278
280
|
|
|
279
|
-
function encodeColor(color: Color | undefined) {
|
|
280
|
-
if (color
|
|
281
|
-
return
|
|
281
|
+
function encodeColor(color: Color | undefined): TypeValues {
|
|
282
|
+
if (!color) {
|
|
283
|
+
return { Type: 1, Values: [0, 0, 0, 0] };
|
|
284
|
+
} else if ('r' in color) {
|
|
285
|
+
return { Type: 1, Values: ['a' in color ? color.a / 255 : 1, color.r / 255, color.g / 255, color.b / 255] };
|
|
286
|
+
} else if ('c' in color) {
|
|
287
|
+
return { Type: 2, Values: [1, color.c / 255, color.m / 255, color.y / 255, color.k / 255] };
|
|
288
|
+
} else if ('k' in color) {
|
|
289
|
+
return { Type: 0, Values: [1, color.k / 255] };
|
|
282
290
|
} else {
|
|
283
|
-
|
|
291
|
+
throw new Error('Invalid color type in text layer');
|
|
284
292
|
}
|
|
285
293
|
}
|
|
286
294
|
|
|
@@ -342,7 +350,7 @@ function encodeObject(obj: any, keys: string[], fonts: Font[]) {
|
|
|
342
350
|
} else if (key === 'font') {
|
|
343
351
|
result[Key] = findOrAddFont(fonts, obj[key]);
|
|
344
352
|
} else if (key === 'fillColor' || key === 'strokeColor') {
|
|
345
|
-
result[Key] =
|
|
353
|
+
result[Key] = encodeColor(obj[key]);
|
|
346
354
|
} else {
|
|
347
355
|
result[Key] = obj[key];
|
|
348
356
|
}
|
|
@@ -722,8 +730,8 @@ export function encodeEngineData(data: LayerTextData) {
|
|
|
722
730
|
ShowGrid: !!gridInfo.show,
|
|
723
731
|
GridSize: gridInfo.size ?? 18,
|
|
724
732
|
GridLeading: gridInfo.leading ?? 22,
|
|
725
|
-
GridColor:
|
|
726
|
-
GridLeadingFillColor:
|
|
733
|
+
GridColor: encodeColor(gridInfo.color),
|
|
734
|
+
GridLeadingFillColor: encodeColor(gridInfo.color),
|
|
727
735
|
AlignLineHeightToGridFlags: !!gridInfo.alignLineHeightToGridFlags,
|
|
728
736
|
},
|
|
729
737
|
AntiAlias: antialias.indexOf(data.antiAlias ?? 'sharp'),
|