psd 4.0.0 → 4.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/README.md +146 -7
- package/dist/descriptor.js +6 -2
- package/dist/descriptor.js.map +1 -1
- package/dist/image.d.ts +28 -4
- package/dist/image.d.ts.map +1 -1
- package/dist/image.js +36 -22
- package/dist/image.js.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/layer-info.d.ts +53 -10
- package/dist/layer-info.d.ts.map +1 -1
- package/dist/layer-info.js +34 -8
- package/dist/layer-info.js.map +1 -1
- package/dist/layer-styles.d.ts +11 -1
- package/dist/layer-styles.d.ts.map +1 -1
- package/dist/layer-styles.js +5 -5
- package/dist/layer-styles.js.map +1 -1
- package/dist/layer.d.ts +32 -0
- package/dist/layer.d.ts.map +1 -1
- package/dist/layer.js +68 -6
- package/dist/layer.js.map +1 -1
- package/dist/linked-files.d.ts +32 -0
- package/dist/linked-files.d.ts.map +1 -0
- package/dist/linked-files.js +45 -0
- package/dist/linked-files.js.map +1 -0
- package/dist/nodes.d.ts +21 -9
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +16 -6
- package/dist/nodes.js.map +1 -1
- package/dist/path-record.d.ts +28 -0
- package/dist/path-record.d.ts.map +1 -1
- package/dist/path-record.js +54 -1
- package/dist/path-record.js.map +1 -1
- package/dist/patterns.d.ts +24 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +108 -0
- package/dist/patterns.js.map +1 -0
- package/dist/png.d.ts +12 -4
- package/dist/png.d.ts.map +1 -1
- package/dist/png.js +68 -31
- package/dist/png.js.map +1 -1
- package/dist/psd.d.ts +13 -2
- package/dist/psd.d.ts.map +1 -1
- package/dist/psd.js +23 -1
- package/dist/psd.js.map +1 -1
- package/dist/resources.d.ts +7 -1
- package/dist/resources.d.ts.map +1 -1
- package/dist/resources.js +18 -0
- package/dist/resources.js.map +1 -1
- package/dist/shapes.d.ts +94 -0
- package/dist/shapes.d.ts.map +1 -0
- package/dist/shapes.js +76 -0
- package/dist/shapes.js.map +1 -0
- package/dist/type-tool.d.ts +60 -11
- package/dist/type-tool.d.ts.map +1 -1
- package/dist/type-tool.js +87 -17
- package/dist/type-tool.js.map +1 -1
- package/package.json +4 -2
- package/src/descriptor.ts +6 -2
- package/src/image.ts +56 -26
- package/src/index.ts +17 -5
- package/src/layer-info.ts +76 -8
- package/src/layer-styles.ts +8 -6
- package/src/layer.ts +79 -6
- package/src/linked-files.ts +66 -0
- package/src/nodes.ts +20 -6
- package/src/path-record.ts +63 -2
- package/src/patterns.ts +113 -0
- package/src/png.ts +76 -31
- package/src/psd.ts +25 -1
- package/src/resources.ts +21 -1
- package/src/shapes.ts +156 -0
- package/src/type-tool.ts +106 -17
package/dist/shapes.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Descriptor } from './descriptor.ts';
|
|
2
|
+
import type { BlendMode } from './layer.ts';
|
|
3
|
+
import { type Gradient, type RGB } from './layer-styles.ts';
|
|
4
|
+
import type { Bounds } from './resources.ts';
|
|
5
|
+
/** A shape's fill or stroke content. One of these is set, depending on its type. */
|
|
6
|
+
export interface ShapeContent {
|
|
7
|
+
/** Undefined for colors that can't be converted, such as book colors. */
|
|
8
|
+
color: RGB | undefined;
|
|
9
|
+
gradient: Gradient | undefined;
|
|
10
|
+
pattern: {
|
|
11
|
+
name: string;
|
|
12
|
+
id: string;
|
|
13
|
+
} | undefined;
|
|
14
|
+
}
|
|
15
|
+
/** The live shape properties Photoshop keeps for each shape tool shape in a layer. */
|
|
16
|
+
export interface VectorShape {
|
|
17
|
+
/** Undefined if the shape was edited into a plain path, or for shape types this library doesn't know. */
|
|
18
|
+
type: 'rectangle' | 'roundedRectangle' | 'line' | 'ellipse' | undefined;
|
|
19
|
+
/** The shape was edited with the path tools, so it only has `index` and `data`. */
|
|
20
|
+
invalidated: boolean;
|
|
21
|
+
/** The shape's path component in the vector mask (`info.vectorMask`). */
|
|
22
|
+
index: number;
|
|
23
|
+
/**
|
|
24
|
+
* The shape's bounds in pixels, as shown in Photoshop's Properties panel. The layer's bounds are
|
|
25
|
+
* larger: they're whole pixels, and include antialiasing and the stroke.
|
|
26
|
+
*/
|
|
27
|
+
bounds: Bounds | undefined;
|
|
28
|
+
/** Rounded rectangle corner radii, in pixels. */
|
|
29
|
+
radii: {
|
|
30
|
+
topLeft: number;
|
|
31
|
+
topRight: number;
|
|
32
|
+
bottomRight: number;
|
|
33
|
+
bottomLeft: number;
|
|
34
|
+
} | undefined;
|
|
35
|
+
/** Line endpoints in pixels, and the line's weight. */
|
|
36
|
+
line: {
|
|
37
|
+
start: {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
};
|
|
41
|
+
end: {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
};
|
|
45
|
+
weight: number;
|
|
46
|
+
} | undefined;
|
|
47
|
+
/** The raw descriptor, for anything not covered above (rotated corners, arrowheads...). */
|
|
48
|
+
data: Descriptor;
|
|
49
|
+
}
|
|
50
|
+
/** A shape layer's stroke settings, and whether its fill and stroke are shown. */
|
|
51
|
+
export interface VectorStroke extends ShapeContent {
|
|
52
|
+
/** Whether the stroke is shown. */
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the fill is shown. The fill's content is in `vectorStrokeContent`, or `solidColor`,
|
|
56
|
+
* `gradientFill` or `patternFill` for older shapes.
|
|
57
|
+
*/
|
|
58
|
+
fillEnabled: boolean;
|
|
59
|
+
/** In pixels. */
|
|
60
|
+
width: number;
|
|
61
|
+
alignment: 'inside' | 'center' | 'outside' | undefined;
|
|
62
|
+
cap: 'butt' | 'round' | 'square' | undefined;
|
|
63
|
+
join: 'miter' | 'round' | 'bevel' | undefined;
|
|
64
|
+
miterLimit: number;
|
|
65
|
+
/** Alternating dash and gap lengths, as multiples of the width. Empty for a solid line. */
|
|
66
|
+
dashes: number[];
|
|
67
|
+
/** In pixels. */
|
|
68
|
+
dashOffset: number;
|
|
69
|
+
/** 0 to 1. */
|
|
70
|
+
opacity: number;
|
|
71
|
+
blendMode: BlendMode | string | undefined;
|
|
72
|
+
/** The raw descriptor, for anything not covered above. */
|
|
73
|
+
data: Descriptor;
|
|
74
|
+
}
|
|
75
|
+
/** The live shape properties Photoshop keeps for a shape layer (`vogk`). */
|
|
76
|
+
export interface VectorOrigination {
|
|
77
|
+
/** One entry per shape tool shape in the layer. */
|
|
78
|
+
shapes: VectorShape[];
|
|
79
|
+
/** The raw descriptor, for anything not covered above. */
|
|
80
|
+
data: Descriptor;
|
|
81
|
+
}
|
|
82
|
+
/** A newer shape layer's fill (`vscg`). */
|
|
83
|
+
export interface VectorFill extends ShapeContent {
|
|
84
|
+
/** The raw descriptor, for anything not covered above. */
|
|
85
|
+
data: Descriptor;
|
|
86
|
+
}
|
|
87
|
+
export declare const shapeContent: (d: Descriptor | undefined) => ShapeContent;
|
|
88
|
+
/** Normalizes the vector origination (`vogk`) descriptor. */
|
|
89
|
+
export declare const readVectorOrigination: (d: Descriptor) => VectorOrigination;
|
|
90
|
+
/** Normalizes the vector fill (`vscg`) descriptor. */
|
|
91
|
+
export declare const readVectorFill: (d: Descriptor) => VectorFill;
|
|
92
|
+
/** Normalizes the vector stroke (`vstk`) descriptor. */
|
|
93
|
+
export declare function readVectorStroke(d: Descriptor): VectorStroke;
|
|
94
|
+
//# sourceMappingURL=shapes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.d.ts","sourceRoot":"","sources":["../src/shapes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAqE,KAAK,QAAQ,EAAE,KAAK,GAAG,EAAE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OAAO,CAAC;IACrB,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IACvD,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC7C,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,2FAA2F;IAC3F,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,iBAAiB;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1C,0DAA0D;IAC1D,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IAChC,mDAAmD;IACnD,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,0DAA0D;IAC1D,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,2CAA2C;AAC3C,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,0DAA0D;IAC1D,IAAI,EAAE,UAAU,CAAC;CAClB;AAwBD,eAAO,MAAM,YAAY,MAAO,UAAU,GAAG,SAAS,KAAG,YAIvD,CAAC;AA4BH,6DAA6D;AAC7D,eAAO,MAAM,qBAAqB,MAAO,UAAU,KAAG,iBAGpD,CAAC;AAEH,sDAAsD;AACtD,eAAO,MAAM,cAAc,MAAO,UAAU,KAAG,UAA+C,CAAC;AAE/F,wDAAwD;AACxD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY,CAiB5D"}
|
package/dist/shapes.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { blendMode, descriptorColor, enumValue, gradient, pattern, percent } from './layer-styles.js';
|
|
2
|
+
const SHAPE_TYPES = { 1: 'rectangle', 2: 'roundedRectangle', 4: 'line', 5: 'ellipse' };
|
|
3
|
+
const ALIGNMENTS = { strokeStyleAlignInside: 'inside', strokeStyleAlignCenter: 'center', strokeStyleAlignOutside: 'outside' };
|
|
4
|
+
const CAPS = { strokeStyleButtCap: 'butt', strokeStyleRoundCap: 'round', strokeStyleSquareCap: 'square' };
|
|
5
|
+
const JOINS = { strokeStyleMiterJoin: 'miter', strokeStyleRoundJoin: 'round', strokeStyleBevelJoin: 'bevel' };
|
|
6
|
+
const lookup = (table, v) => table[enumValue(v)];
|
|
7
|
+
/** Converts a unit value to pixels at the given resolution (pixels per inch). */
|
|
8
|
+
function pixels(v, resolution) {
|
|
9
|
+
switch (v.id) {
|
|
10
|
+
case '#Pxl':
|
|
11
|
+
return v.value;
|
|
12
|
+
case '#Pnt':
|
|
13
|
+
return (v.value * resolution) / 72;
|
|
14
|
+
case '#Mlm':
|
|
15
|
+
return (v.value * resolution) / 25.4;
|
|
16
|
+
default:
|
|
17
|
+
throw new Error(`Unsupported shape unit '${v.id}'`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export const shapeContent = (d) => ({
|
|
21
|
+
color: descriptorColor(d?.['Clr ']),
|
|
22
|
+
gradient: gradient(d?.Grad),
|
|
23
|
+
pattern: pattern(d?.Ptrn),
|
|
24
|
+
});
|
|
25
|
+
function vectorShape(d) {
|
|
26
|
+
const res = d.keyOriginResolution;
|
|
27
|
+
const px = (v) => pixels(v, res);
|
|
28
|
+
const box = d.keyOriginShapeBBox;
|
|
29
|
+
const radii = d.keyOriginRRectRadii;
|
|
30
|
+
const point = (p) => ({ x: p.Hrzn, y: p.Vrtc });
|
|
31
|
+
return {
|
|
32
|
+
type: SHAPE_TYPES[d.keyOriginType],
|
|
33
|
+
invalidated: d.keyShapeInvalidated ?? false,
|
|
34
|
+
index: d.keyOriginIndex,
|
|
35
|
+
bounds: box && { top: px(box['Top ']), left: px(box.Left), bottom: px(box.Btom), right: px(box.Rght) },
|
|
36
|
+
radii: radii && {
|
|
37
|
+
topLeft: px(radii.topLeft),
|
|
38
|
+
topRight: px(radii.topRight),
|
|
39
|
+
bottomRight: px(radii.bottomRight),
|
|
40
|
+
bottomLeft: px(radii.bottomLeft),
|
|
41
|
+
},
|
|
42
|
+
line: d.keyOriginLineStart && {
|
|
43
|
+
start: point(d.keyOriginLineStart),
|
|
44
|
+
end: point(d.keyOriginLineEnd),
|
|
45
|
+
weight: d.keyOriginLineWeight,
|
|
46
|
+
},
|
|
47
|
+
data: d,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Normalizes the vector origination (`vogk`) descriptor. */
|
|
51
|
+
export const readVectorOrigination = (d) => ({
|
|
52
|
+
shapes: (d.keyDescriptorList ?? []).map(vectorShape),
|
|
53
|
+
data: d,
|
|
54
|
+
});
|
|
55
|
+
/** Normalizes the vector fill (`vscg`) descriptor. */
|
|
56
|
+
export const readVectorFill = (d) => ({ ...shapeContent(d), data: d });
|
|
57
|
+
/** Normalizes the vector stroke (`vstk`) descriptor. */
|
|
58
|
+
export function readVectorStroke(d) {
|
|
59
|
+
const res = d.strokeStyleResolution;
|
|
60
|
+
return {
|
|
61
|
+
...shapeContent(d.strokeStyleContent),
|
|
62
|
+
enabled: d.strokeEnabled,
|
|
63
|
+
fillEnabled: d.fillEnabled,
|
|
64
|
+
width: pixels(d.strokeStyleLineWidth, res),
|
|
65
|
+
alignment: lookup(ALIGNMENTS, d.strokeStyleLineAlignment),
|
|
66
|
+
cap: lookup(CAPS, d.strokeStyleLineCapType),
|
|
67
|
+
join: lookup(JOINS, d.strokeStyleLineJoinType),
|
|
68
|
+
miterLimit: d.strokeStyleMiterLimit,
|
|
69
|
+
dashes: d.strokeStyleLineDashSet.map((v) => v.value),
|
|
70
|
+
dashOffset: pixels(d.strokeStyleLineDashOffset, res),
|
|
71
|
+
opacity: percent(d.strokeStyleOpacity),
|
|
72
|
+
blendMode: blendMode(d.strokeStyleBlendMode),
|
|
73
|
+
data: d,
|
|
74
|
+
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QACzD,GAAG,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,sBAAsB,CAAC;QAC3C,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,uBAAuB,CAAC;QAC9C,UAAU,EAAE,CAAC,CAAC,qBAAqB;QACnC,MAAM,EAAE,CAAC,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAY,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/D,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,yBAAyB,EAAE,GAAG,CAAC;QACpD,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC;QACtC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC;QAC5C,IAAI,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
|
package/dist/type-tool.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Descriptor } from './descriptor.ts';
|
|
2
2
|
import { type EngineDict } from './engine-data.ts';
|
|
3
3
|
import type { Reader } from './reader.ts';
|
|
4
|
+
import type { Bounds } from './resources.ts';
|
|
4
5
|
export interface Transform {
|
|
5
6
|
xx: number;
|
|
6
7
|
xy: number;
|
|
@@ -22,7 +23,24 @@ export interface TextRun {
|
|
|
22
23
|
fauxItalic: boolean;
|
|
23
24
|
underline: boolean;
|
|
24
25
|
strikethrough: boolean;
|
|
26
|
+
/** Tracking (letter spacing) in 1/1000 em, as in the Character panel. Multiply by `size / 1000` for pixels. */
|
|
27
|
+
tracking: number;
|
|
28
|
+
/**
|
|
29
|
+
* `'auto'` when the font's kerning is used (Metrics in the Character panel), otherwise manual kerning
|
|
30
|
+
* in 1/1000 em. Photoshop often stores the first character as its own run with a kerning of 0.
|
|
31
|
+
*/
|
|
32
|
+
kerning: number | 'auto';
|
|
33
|
+
/** Baseline shift in pixels before `transform` scales the text, like `size`. Positive values raise the text. */
|
|
34
|
+
baselineShift: number;
|
|
35
|
+
/** Small Caps or All Caps from the Character panel. `text` keeps the case it was typed in. */
|
|
36
|
+
caps: TextCaps;
|
|
37
|
+
/** Superscript or subscript from the Character panel. */
|
|
38
|
+
baseline: TextBaseline;
|
|
25
39
|
}
|
|
40
|
+
declare const CAPS: readonly ['normal', 'small-caps', 'all-caps'];
|
|
41
|
+
export type TextCaps = (typeof CAPS)[number];
|
|
42
|
+
declare const BASELINES: readonly ['normal', 'superscript', 'subscript'];
|
|
43
|
+
export type TextBaseline = (typeof BASELINES)[number];
|
|
26
44
|
declare const ALIGNMENTS: readonly ['left', 'right', 'center', 'justify'];
|
|
27
45
|
export type TextAlignment = (typeof ALIGNMENTS)[number];
|
|
28
46
|
/** A text layer (the `TySh` block). */
|
|
@@ -33,21 +51,50 @@ export declare class TypeTool {
|
|
|
33
51
|
readonly textData: Descriptor;
|
|
34
52
|
/** The raw warp descriptor. */
|
|
35
53
|
readonly warpData: Descriptor;
|
|
36
|
-
readonly left: number;
|
|
37
|
-
readonly top: number;
|
|
38
|
-
readonly right: number;
|
|
39
|
-
readonly bottom: number;
|
|
40
54
|
constructor(r: Reader);
|
|
41
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* The left edge of the text's frame, in pixels relative to the transform origin (`tx`, `ty`) and
|
|
57
|
+
* before the transform. The frame spans the lines around the anchor point for point text, or the box
|
|
58
|
+
* for paragraph text (it can reach beyond the box to fit the first line; see `boxBounds`).
|
|
59
|
+
* Undefined in files from older Photoshop versions.
|
|
60
|
+
*/
|
|
61
|
+
get left(): number | undefined;
|
|
62
|
+
/** See `left`. */
|
|
63
|
+
get top(): number | undefined;
|
|
64
|
+
/** See `left`. */
|
|
65
|
+
get right(): number | undefined;
|
|
66
|
+
/** See `left`. */
|
|
67
|
+
get bottom(): number | undefined;
|
|
68
|
+
/** The tight bounds of the glyphs, relative to the transform origin like `left`/`top`/`right`/`bottom`. */
|
|
69
|
+
get boundingBox(): Bounds | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* The box of paragraph (box) text, exactly as Photoshop draws it, relative to the transform origin and
|
|
72
|
+
* before the transform like `left`/`top`/`right`/`bottom`. Undefined for text without a box, such as
|
|
73
|
+
* point text. Unlike the frame, it doesn't grow to fit the first line, and older Photoshop versions
|
|
74
|
+
* store it too.
|
|
75
|
+
*/
|
|
76
|
+
get boxBounds(): Bounds | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* The text content. Paragraphs are separated by `\r`, and line breaks within a paragraph
|
|
79
|
+
* (Shift+Enter) are `\u0003`; neither displays as a new line in HTML or a terminal.
|
|
80
|
+
*/
|
|
42
81
|
get text(): string;
|
|
43
82
|
/** The parsed EngineData, which holds all styling. Parsed on first access. */
|
|
44
83
|
get engineData(): EngineDict;
|
|
45
84
|
/** Every font referenced by the text. */
|
|
46
85
|
get fonts(): string[];
|
|
47
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* The style of each run of characters, in order. Runs only store what they change from the
|
|
88
|
+
* document's normal style sheet, so the rest comes from that.
|
|
89
|
+
*/
|
|
48
90
|
get runs(): TextRun[];
|
|
49
|
-
/** Unique font sizes, in
|
|
91
|
+
/** Unique font sizes as stored, in pixels before `transform` scales the text. See `pointSizes()`. */
|
|
50
92
|
get sizes(): number[];
|
|
93
|
+
/**
|
|
94
|
+
* Unique font sizes in points, as Photoshop's Character panel shows them: scaled by `transform`
|
|
95
|
+
* and converted at `ppi` pixels per inch (`psd.resources.resolutionInfo.vRes`). Pass 72 for pixels.
|
|
96
|
+
*/
|
|
97
|
+
pointSizes(ppi: number): number[];
|
|
51
98
|
/** Unique text colors (RGBA). */
|
|
52
99
|
get colors(): RGBA[];
|
|
53
100
|
/** Unique explicit leadings (line spacing). */
|
|
@@ -67,10 +114,12 @@ export declare class TypeTool {
|
|
|
67
114
|
leadings: number[];
|
|
68
115
|
};
|
|
69
116
|
runs: TextRun[];
|
|
70
|
-
left: number;
|
|
71
|
-
top: number;
|
|
72
|
-
right: number;
|
|
73
|
-
bottom: number;
|
|
117
|
+
left: number | undefined;
|
|
118
|
+
top: number | undefined;
|
|
119
|
+
right: number | undefined;
|
|
120
|
+
bottom: number | undefined;
|
|
121
|
+
boundingBox: Bounds | undefined;
|
|
122
|
+
boxBounds: Bounds | undefined;
|
|
74
123
|
transform: Transform;
|
|
75
124
|
};
|
|
76
125
|
}
|
package/dist/type-tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-tool.d.ts","sourceRoot":"","sources":["../src/type-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"type-tool.d.ts","sourceRoot":"","sources":["../src/type-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpD,gDAAgD;AAChD,MAAM,WAAW,OAAO;IACtB,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,IAAI,E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-tool.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { readDescriptor } from './descriptor.js';
|
|
2
2
|
import { parseEngineData } from './engine-data.js';
|
|
3
|
+
const CAPS = ['normal', 'small-caps', 'all-caps'];
|
|
4
|
+
const BASELINES = ['normal', 'superscript', 'subscript'];
|
|
5
|
+
const lookup = (values, key, index) => {
|
|
6
|
+
const value = values[index];
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
throw new Error(`Unknown ${key} value: ${index}`);
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
3
11
|
const ALIGNMENTS = ['left', 'right', 'center', 'justify'];
|
|
4
12
|
const readTransform = (r) => ({
|
|
5
13
|
xx: r.float64(),
|
|
@@ -22,10 +30,6 @@ export class TypeTool {
|
|
|
22
30
|
textData;
|
|
23
31
|
/** The raw warp descriptor. */
|
|
24
32
|
warpData;
|
|
25
|
-
left;
|
|
26
|
-
top;
|
|
27
|
-
right;
|
|
28
|
-
bottom;
|
|
29
33
|
#engineData;
|
|
30
34
|
constructor(r) {
|
|
31
35
|
r.skip(2); // version
|
|
@@ -34,12 +38,51 @@ export class TypeTool {
|
|
|
34
38
|
this.textData = readDescriptor(r);
|
|
35
39
|
r.skip(6); // warp version + descriptor version
|
|
36
40
|
this.warpData = readDescriptor(r);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
// The block ends with left, top, right and bottom fields that Photoshop leaves as 0.
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The left edge of the text's frame, in pixels relative to the transform origin (`tx`, `ty`) and
|
|
45
|
+
* before the transform. The frame spans the lines around the anchor point for point text, or the box
|
|
46
|
+
* for paragraph text (it can reach beyond the box to fit the first line; see `boxBounds`).
|
|
47
|
+
* Undefined in files from older Photoshop versions.
|
|
48
|
+
*/
|
|
49
|
+
get left() {
|
|
50
|
+
return this.textData.bounds?.Left.value;
|
|
51
|
+
}
|
|
52
|
+
/** See `left`. */
|
|
53
|
+
get top() {
|
|
54
|
+
return this.textData.bounds?.['Top '].value;
|
|
55
|
+
}
|
|
56
|
+
/** See `left`. */
|
|
57
|
+
get right() {
|
|
58
|
+
return this.textData.bounds?.Rght.value;
|
|
59
|
+
}
|
|
60
|
+
/** See `left`. */
|
|
61
|
+
get bottom() {
|
|
62
|
+
return this.textData.bounds?.Btom.value;
|
|
41
63
|
}
|
|
42
|
-
/** The
|
|
64
|
+
/** The tight bounds of the glyphs, relative to the transform origin like `left`/`top`/`right`/`bottom`. */
|
|
65
|
+
get boundingBox() {
|
|
66
|
+
const box = this.textData.boundingBox;
|
|
67
|
+
return box && { left: box.Left.value, top: box['Top '].value, right: box.Rght.value, bottom: box.Btom.value };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The box of paragraph (box) text, exactly as Photoshop draws it, relative to the transform origin and
|
|
71
|
+
* before the transform like `left`/`top`/`right`/`bottom`. Undefined for text without a box, such as
|
|
72
|
+
* point text. Unlike the frame, it doesn't grow to fit the first line, and older Photoshop versions
|
|
73
|
+
* store it too.
|
|
74
|
+
*/
|
|
75
|
+
get boxBounds() {
|
|
76
|
+
const shape = this.engineData.EngineDict.Rendered.Shapes.Children[0].Cookie.Photoshop;
|
|
77
|
+
if (shape.ShapeType !== 1)
|
|
78
|
+
return undefined;
|
|
79
|
+
const [left, top, right, bottom] = shape.BoxBounds;
|
|
80
|
+
return { left, top, right, bottom };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The text content. Paragraphs are separated by `\r`, and line breaks within a paragraph
|
|
84
|
+
* (Shift+Enter) are `\u0003`; neither displays as a new line in HTML or a terminal.
|
|
85
|
+
*/
|
|
43
86
|
get text() {
|
|
44
87
|
return this.textData['Txt '];
|
|
45
88
|
}
|
|
@@ -51,7 +94,10 @@ export class TypeTool {
|
|
|
51
94
|
get fonts() {
|
|
52
95
|
return this.engineData.ResourceDict.FontSet.map((f) => f.Name);
|
|
53
96
|
}
|
|
54
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* The style of each run of characters, in order. Runs only store what they change from the
|
|
99
|
+
* document's normal style sheet, so the rest comes from that.
|
|
100
|
+
*/
|
|
55
101
|
get runs() {
|
|
56
102
|
const styleRun = this.engineData.EngineDict.StyleRun;
|
|
57
103
|
const lengths = [...styleRun.RunLengthArray];
|
|
@@ -59,27 +105,45 @@ export class TypeTool {
|
|
|
59
105
|
const total = lengths.reduce((sum, n) => sum + n, 0);
|
|
60
106
|
if (total - this.text.length === 1)
|
|
61
107
|
lengths[lengths.length - 1] -= 1;
|
|
62
|
-
const
|
|
108
|
+
const { FontSet, StyleSheetSet, TheNormalStyleSheet } = this.engineData.ResourceDict;
|
|
109
|
+
const defaults = StyleSheetSet[TheNormalStyleSheet].StyleSheetData;
|
|
63
110
|
return styleRun.RunArray.map((run, i) => {
|
|
64
|
-
const s = run.StyleSheet.StyleSheetData;
|
|
111
|
+
const s = { ...defaults, ...run.StyleSheet.StyleSheetData };
|
|
65
112
|
return {
|
|
66
113
|
length: lengths[i] ?? 0,
|
|
67
|
-
font: s.Font === undefined ? undefined :
|
|
114
|
+
font: s.Font === undefined ? undefined : FontSet[s.Font]?.Name,
|
|
68
115
|
size: s.FontSize,
|
|
69
|
-
// Opaque black is sometimes omitted.
|
|
70
116
|
color: s.FillColor ? toRGBA(s.FillColor.Values) : undefined,
|
|
71
117
|
leading: s.AutoLeading === false && s.Leading !== undefined ? s.Leading : 'auto',
|
|
72
118
|
fauxBold: s.FauxBold ?? false,
|
|
73
119
|
fauxItalic: s.FauxItalic ?? false,
|
|
74
120
|
underline: s.Underline ?? false,
|
|
75
121
|
strikethrough: s.Strikethrough ?? false,
|
|
122
|
+
tracking: s.Tracking ?? 0,
|
|
123
|
+
kerning: s.AutoKerning === false ? (s.Kerning ?? 0) : 'auto',
|
|
124
|
+
baselineShift: s.BaselineShift ?? 0,
|
|
125
|
+
caps: lookup(CAPS, 'FontCaps', s.FontCaps ?? 0),
|
|
126
|
+
baseline: lookup(BASELINES, 'FontBaseline', s.FontBaseline ?? 0),
|
|
76
127
|
};
|
|
77
128
|
});
|
|
78
129
|
}
|
|
79
|
-
/** Unique font sizes, in
|
|
130
|
+
/** Unique font sizes as stored, in pixels before `transform` scales the text. See `pointSizes()`. */
|
|
80
131
|
get sizes() {
|
|
81
132
|
return uniq(this.runs.flatMap((r) => (r.size === undefined ? [] : [r.size])));
|
|
82
133
|
}
|
|
134
|
+
/** How much `transform` scales the text vertically, which is what Photoshop scales font sizes by. */
|
|
135
|
+
get #scale() {
|
|
136
|
+
return Math.hypot(this.transform.yx, this.transform.yy);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Unique font sizes in points, as Photoshop's Character panel shows them: scaled by `transform`
|
|
140
|
+
* and converted at `ppi` pixels per inch (`psd.resources.resolutionInfo.vRes`). Pass 72 for pixels.
|
|
141
|
+
*/
|
|
142
|
+
pointSizes(ppi) {
|
|
143
|
+
if (!(ppi > 0))
|
|
144
|
+
throw new Error(`Invalid resolution: ${ppi}`);
|
|
145
|
+
return this.sizes.map((size) => (size * this.#scale * 72) / ppi);
|
|
146
|
+
}
|
|
83
147
|
/** Unique text colors (RGBA). */
|
|
84
148
|
get colors() {
|
|
85
149
|
return uniq(this.runs.map((r) => r.color ?? [0, 0, 0, 255]));
|
|
@@ -90,13 +154,17 @@ export class TypeTool {
|
|
|
90
154
|
}
|
|
91
155
|
/** The alignment of each paragraph. */
|
|
92
156
|
get alignment() {
|
|
93
|
-
|
|
157
|
+
const { ParagraphSheetSet, TheNormalParagraphSheet } = this.engineData.ResourceDict;
|
|
158
|
+
const defaults = ParagraphSheetSet[TheNormalParagraphSheet].Properties;
|
|
159
|
+
return this.engineData.EngineDict.ParagraphRun.RunArray.map(
|
|
160
|
+
// Photoshop leaves Justification out of the normal sheet when it's 0 (left).
|
|
161
|
+
(p) => ALIGNMENTS[Math.min(p.ParagraphSheet.Properties.Justification ?? defaults.Justification ?? 0, 3)]);
|
|
94
162
|
}
|
|
95
163
|
/** CSS for the first style run. Fonts may include Photoshop-internal names. */
|
|
96
164
|
toCSS() {
|
|
97
165
|
const definition = {
|
|
98
166
|
'font-family': this.fonts.join(', '),
|
|
99
|
-
'font-size': this.sizes[0] === undefined ? undefined : `${this.sizes[0]}
|
|
167
|
+
'font-size': this.sizes[0] === undefined ? undefined : `${this.sizes[0] * this.#scale}px`,
|
|
100
168
|
color: `rgba(${this.colors[0].join(', ')})`,
|
|
101
169
|
'text-align': this.alignment[0],
|
|
102
170
|
};
|
|
@@ -121,6 +189,8 @@ export class TypeTool {
|
|
|
121
189
|
top: this.top,
|
|
122
190
|
right: this.right,
|
|
123
191
|
bottom: this.bottom,
|
|
192
|
+
boundingBox: this.boundingBox,
|
|
193
|
+
boxBounds: this.boxBounds,
|
|
124
194
|
transform: this.transform,
|
|
125
195
|
};
|
|
126
196
|
}
|
package/dist/type-tool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-tool.js","sourceRoot":"","sources":["../src/type-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAmB,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAmB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"type-tool.js","sourceRoot":"","sources":["../src/type-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAmB,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAmB,MAAM,kBAAkB,CAAC;AA0CpE,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,CAAU,CAAC;AAE3D,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,CAAU,CAAC;AAGlE,MAAM,MAAM,GAAG,CAAI,MAAoB,EAAE,GAAW,EAAE,KAAa,EAAK,EAAE;IACxE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,KA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|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"author": "Ryan LeFevre (https://github.com/meltingice)",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"keywords": [
|
|
8
9
|
"psd",
|
|
@@ -20,7 +21,8 @@
|
|
|
20
21
|
".": {
|
|
21
22
|
"types": "./dist/index.d.ts",
|
|
22
23
|
"default": "./dist/index.js"
|
|
23
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
24
26
|
},
|
|
25
27
|
"files": [
|
|
26
28
|
"dist",
|
package/src/descriptor.ts
CHANGED
|
@@ -96,9 +96,13 @@ function readItem(r: Reader, type: string): unknown {
|
|
|
96
96
|
const count = r.int32();
|
|
97
97
|
return { id, unit: UNITS[id], values: Array.from({ length: count }, () => r.float64()) };
|
|
98
98
|
}
|
|
99
|
+
case 'ObAr':
|
|
100
|
+
// An undocumented object array: an item count, then a descriptor whose values hold one
|
|
101
|
+
// entry per item, usually as `UnFl` lists (e.g. `{ Hrzn: { values }, Vrtc: { values } }`).
|
|
102
|
+
r.skip(4);
|
|
103
|
+
return readDescriptor(r);
|
|
99
104
|
default:
|
|
100
|
-
//
|
|
101
|
-
// reader, so fail loudly instead of returning garbage.
|
|
105
|
+
// Unknown types would desync the reader, so fail loudly instead of returning garbage.
|
|
102
106
|
throw new Error(`Unsupported descriptor item type '${type}' at offset ${r.pos - 4}`);
|
|
103
107
|
}
|
|
104
108
|
}
|