ag-psd 32.0.0 → 33.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/.v8-cache/v24.7.0-x64-ef5a0af0/03e19709 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/05135617 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/1130885f +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/226e2801 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/2a19133e +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/4511bacf +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/68416cb2 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/71df9cb3 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/7ea06cea +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/932f0770 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/acc36e66 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/b3c2fab7 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/c314aece +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/cfc49f4f +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/cff9434a +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/dc86f000 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/e03e2acd +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/e6745c2b +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/e6b99945 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/eeeebdfe +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/f6fd8125 +0 -0
- package/CHANGELOG.md +78 -0
- package/LICENSE +5 -0
- package/README.md +3 -6
- package/README_PSD.md +242 -81
- package/dist/abr.d.ts +11 -4
- package/dist/abr.js +357 -230
- package/dist/abr.js.map +1 -1
- package/dist/additionalInfo.d.ts +54 -2
- package/dist/additionalInfo.js +487 -306
- package/dist/additionalInfo.js.map +1 -1
- package/dist/ase.d.ts +6 -1
- package/dist/ase.js +61 -61
- package/dist/ase.js.map +1 -1
- package/dist/bundle.js +1937 -1115
- package/dist/descriptor.d.ts +14 -8
- package/dist/descriptor.js +202 -186
- package/dist/descriptor.js.map +1 -1
- package/dist/helpers.d.ts +1 -1
- package/dist/helpers.js +4 -2
- package/dist/helpers.js.map +1 -1
- package/dist/imageResources.d.ts +15 -3
- package/dist/imageResources.js +503 -142
- package/dist/imageResources.js.map +1 -1
- package/dist/jpeg.js +8 -8
- package/dist/jpeg.js.map +1 -1
- package/dist/psd.d.ts +148 -17
- package/dist/psd.js.map +1 -1
- package/dist/psdReader.d.ts +10 -0
- package/dist/psdReader.js +278 -166
- package/dist/psdReader.js.map +1 -1
- package/dist/psdWriter.d.ts +1 -0
- package/dist/psdWriter.js +77 -62
- package/dist/psdWriter.js.map +1 -1
- package/dist/text.js +17 -6
- package/dist/text.js.map +1 -1
- package/dist/utf8.js +0 -3
- package/dist/utf8.js.map +1 -1
- package/dist-es/abr.d.ts +11 -4
- package/dist-es/abr.js +357 -230
- package/dist-es/abr.js.map +1 -1
- package/dist-es/additionalInfo.d.ts +54 -2
- package/dist-es/additionalInfo.js +487 -306
- package/dist-es/additionalInfo.js.map +1 -1
- package/dist-es/ase.d.ts +6 -1
- package/dist-es/ase.js +61 -61
- package/dist-es/ase.js.map +1 -1
- package/dist-es/descriptor.d.ts +14 -8
- package/dist-es/descriptor.js +202 -186
- package/dist-es/descriptor.js.map +1 -1
- package/dist-es/helpers.d.ts +1 -1
- package/dist-es/helpers.js +4 -2
- package/dist-es/helpers.js.map +1 -1
- package/dist-es/imageResources.d.ts +15 -3
- package/dist-es/imageResources.js +503 -142
- package/dist-es/imageResources.js.map +1 -1
- package/dist-es/jpeg.js +8 -8
- package/dist-es/jpeg.js.map +1 -1
- package/dist-es/psd.d.ts +148 -17
- package/dist-es/psd.js.map +1 -1
- package/dist-es/psdReader.d.ts +10 -0
- package/dist-es/psdReader.js +278 -166
- package/dist-es/psdReader.js.map +1 -1
- package/dist-es/psdWriter.d.ts +1 -0
- package/dist-es/psdWriter.js +77 -62
- package/dist-es/psdWriter.js.map +1 -1
- package/dist-es/text.js +17 -6
- package/dist-es/text.js.map +1 -1
- package/dist-es/utf8.js +0 -3
- package/dist-es/utf8.js.map +1 -1
- package/package.json +2 -2
- package/src/abr.ts +375 -235
- package/src/additionalInfo.ts +663 -420
- package/src/ase.ts +66 -61
- package/src/descriptor.ts +199 -195
- package/src/helpers.ts +4 -1
- package/src/imageResources.ts +632 -168
- package/src/jpeg.ts +8 -8
- package/src/psd.ts +156 -30
- package/src/psdReader.ts +273 -172
- package/src/psdWriter.ts +95 -58
- package/src/text.ts +17 -6
- package/src/utf8.ts +0 -4
package/src/ase.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createReader, readFloat32, readSignature, readUint16, readUint32, readUnicodeStringWithLength } from './psdReader';
|
|
1
|
+
import { createReader, PsdReader, readFloat32, readSignature, readUint16, readUint32, readUnicodeStringWithLength } from './psdReader';
|
|
2
2
|
|
|
3
3
|
export type AseColorType = 'global' | 'spot' | 'normal';
|
|
4
4
|
|
|
@@ -35,79 +35,58 @@ export interface Ase {
|
|
|
35
35
|
colors: (AseGroup | AseColor)[];
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export
|
|
38
|
+
export interface ReadAseOptions {
|
|
39
|
+
logMissingFeatures?: boolean;
|
|
40
|
+
/** Throw on unsupported or invalid blocks instead of skipping them */
|
|
41
|
+
throwForMissingFeatures?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function readAse(buffer: ArrayBufferView, options: ReadAseOptions = {}): Ase {
|
|
39
45
|
const reader = createReader(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
40
46
|
const signature = readSignature(reader); // ASEF
|
|
41
47
|
if (signature !== 'ASEF') throw new Error('Invalid signature');
|
|
42
48
|
const versionMajor = readUint16(reader); // 1
|
|
43
|
-
|
|
44
|
-
if (versionMajor !== 1
|
|
49
|
+
readUint16(reader); // minor version: 0
|
|
50
|
+
if (versionMajor !== 1) throw new Error('Invalid version');
|
|
45
51
|
const blocksCount = readUint32(reader);
|
|
46
|
-
const colorTypes: AseColorType[] = ['global', 'spot', 'normal'];
|
|
47
52
|
const ase: Ase = { colors: [] };
|
|
48
53
|
let group: Ase | AseGroup = ase;
|
|
49
54
|
|
|
50
|
-
for (let i = 0; i < blocksCount; i++) {
|
|
55
|
+
for (let i = 0; i < blocksCount && reader.offset + 6 <= reader.view.byteLength; i++) {
|
|
51
56
|
const type = readUint16(reader);
|
|
52
57
|
const length = readUint32(reader);
|
|
53
|
-
const end = reader.offset + length;
|
|
58
|
+
const end = Math.min(reader.offset + length, reader.view.byteLength);
|
|
59
|
+
// block reader, so invalid lengths can't make us read data of following blocks
|
|
60
|
+
const block = createReader(reader.view.buffer, reader.view.byteOffset + reader.offset, end - reader.offset);
|
|
54
61
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
color
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
b: readFloat32(reader),
|
|
67
|
-
type: colorTypes[readUint16(reader)],
|
|
68
|
-
};
|
|
69
|
-
break;
|
|
70
|
-
case 'CMYK':
|
|
71
|
-
color = {
|
|
72
|
-
c: readFloat32(reader),
|
|
73
|
-
m: readFloat32(reader),
|
|
74
|
-
y: readFloat32(reader),
|
|
75
|
-
k: readFloat32(reader),
|
|
76
|
-
type: colorTypes[readUint16(reader)],
|
|
77
|
-
};
|
|
78
|
-
break;
|
|
79
|
-
case 'Gray':
|
|
80
|
-
color = {
|
|
81
|
-
k: readFloat32(reader),
|
|
82
|
-
type: colorTypes[readUint16(reader)],
|
|
83
|
-
};
|
|
84
|
-
break;
|
|
85
|
-
case 'LAB ':
|
|
86
|
-
color = {
|
|
87
|
-
l: readFloat32(reader),
|
|
88
|
-
a: readFloat32(reader),
|
|
89
|
-
b: readFloat32(reader),
|
|
90
|
-
type: colorTypes[readUint16(reader)],
|
|
91
|
-
};
|
|
92
|
-
break;
|
|
93
|
-
default:
|
|
94
|
-
throw new Error('Invalid color mode');
|
|
62
|
+
try {
|
|
63
|
+
switch (type) {
|
|
64
|
+
case 0x0001: { // color
|
|
65
|
+
const color = readAseColor(block);
|
|
66
|
+
if (color) {
|
|
67
|
+
group.colors.push(color);
|
|
68
|
+
} else {
|
|
69
|
+
if (options.throwForMissingFeatures) throw new Error('Unsupported color mode');
|
|
70
|
+
options.logMissingFeatures && reader.log('Skipped color with unsupported color mode');
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
95
73
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
74
|
+
case 0xC001: { // group start
|
|
75
|
+
const nameLength = readUint16(block);
|
|
76
|
+
const name = readUnicodeStringWithLength(block, nameLength);
|
|
77
|
+
ase.colors.push(group = { name, colors: [] });
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case 0xC002: // group end
|
|
81
|
+
group = ase;
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
if (options.throwForMissingFeatures) throw new Error(`Invalid block type: ${type}`);
|
|
85
|
+
options.logMissingFeatures && reader.log(`Skipped unknown block type: ${type}`);
|
|
105
86
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
default:
|
|
110
|
-
throw new Error('Invalid block type');
|
|
87
|
+
} catch (e) {
|
|
88
|
+
if (options.throwForMissingFeatures) throw e;
|
|
89
|
+
options.logMissingFeatures && reader.log(`Skipped invalid block: ${(e as Error).message}`);
|
|
111
90
|
}
|
|
112
91
|
|
|
113
92
|
reader.offset = end;
|
|
@@ -115,3 +94,29 @@ export function readAse(buffer: ArrayBufferView): Ase {
|
|
|
115
94
|
|
|
116
95
|
return ase;
|
|
117
96
|
}
|
|
97
|
+
|
|
98
|
+
function readAseColor(reader: PsdReader): AseColor | undefined {
|
|
99
|
+
const nameLength = readUint16(reader);
|
|
100
|
+
const name = readUnicodeStringWithLength(reader, nameLength);
|
|
101
|
+
const colorMode = readSignature(reader);
|
|
102
|
+
// NaN and infinite values are replaced with 0
|
|
103
|
+
const value = () => {
|
|
104
|
+
const v = readFloat32(reader);
|
|
105
|
+
return isFinite(v) ? v : 0;
|
|
106
|
+
};
|
|
107
|
+
// color type is sometimes missing, unknown types are treated as process (normal) colors
|
|
108
|
+
const colorType = () => {
|
|
109
|
+
const index = reader.offset + 2 <= reader.view.byteLength ? readUint16(reader) : 2;
|
|
110
|
+
return colorTypes[index] || 'normal';
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
switch (colorMode) {
|
|
114
|
+
case 'RGB ': return { name, color: { r: value(), g: value(), b: value(), type: colorType() } };
|
|
115
|
+
case 'CMYK': return { name, color: { c: value(), m: value(), y: value(), k: value(), type: colorType() } };
|
|
116
|
+
case 'Gray': return { name, color: { k: value(), type: colorType() } };
|
|
117
|
+
case 'LAB ': return { name, color: { l: value(), a: value(), b: value(), type: colorType() } };
|
|
118
|
+
default: return undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const colorTypes: AseColorType[] = ['global', 'spot', 'normal'];
|