@unmade/text-renderer 0.1.2 → 0.1.4
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/dist/{index-DXUVTcJ6.cjs → index-BFEQ7yc6.cjs} +1 -1
- package/dist/{index-CbwzwF5C.js → index-F17NutRZ.js} +13 -12
- package/dist/index.cjs +8 -8
- package/dist/index.d.ts +138 -28
- package/dist/index.js +2951 -2514
- package/dist/node/index.cjs +8 -8
- package/dist/node/index.d.ts +138 -28
- package/dist/node/index.js +2963 -2526
- package/dist/worker/index.cjs +25 -8
- package/dist/worker/index.d.ts +138 -28
- package/dist/worker/index.js +12679 -4280
- package/package.json +8 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { default as default_2 } from 'opentype.js';
|
|
2
2
|
import { SVGGlyphData } from '@unmade/svg-glyphs';
|
|
3
3
|
|
|
4
|
+
export declare type BaselineConfig = {
|
|
5
|
+
type: 'flat';
|
|
6
|
+
} | {
|
|
7
|
+
type: 'curved';
|
|
8
|
+
} | {
|
|
9
|
+
type: 'custom';
|
|
10
|
+
path: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
4
13
|
export declare type BaselineType = 'flat' | 'curved';
|
|
5
14
|
|
|
6
15
|
export declare type BoxDimensions = {
|
|
@@ -11,52 +20,120 @@ export declare type BoxDimensions = {
|
|
|
11
20
|
physicalUnits: MeasurementUnits;
|
|
12
21
|
};
|
|
13
22
|
|
|
23
|
+
export declare interface ColourInfo {
|
|
24
|
+
readonly hex: string;
|
|
25
|
+
readonly reference?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Maps original hex colour → replacement ColourInfo. */
|
|
29
|
+
export declare type ColourMap = Readonly<Record<string, ColourInfo>>;
|
|
30
|
+
|
|
14
31
|
export declare const DEFAULT_OUTLINE_FACTOR = 0.03125;
|
|
15
32
|
|
|
33
|
+
export declare const DEFAULT_SPACING: TextSpacing;
|
|
34
|
+
|
|
16
35
|
/**
|
|
17
|
-
* Generate a path command to curve text and align that text to the top of the box
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* SVG Quadratic curves require two sets of coordinates - a control point and end point, with the start point being the end point of the previous command
|
|
21
|
-
* [1] https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#B%C3%A9zier_Curves
|
|
36
|
+
* Generate a path command to curve text and align that text to the top of the box.
|
|
37
|
+
* Uses two quadratic bezier curves — one from the bottom left to the peak, and a
|
|
38
|
+
* second mirrored from the peak to the end.
|
|
22
39
|
*
|
|
23
|
-
* Curved text is not currently supported for multiline text
|
|
40
|
+
* Curved text is not currently supported for multiline text.
|
|
24
41
|
*
|
|
25
|
-
* @param boxWidth - the width of the box
|
|
26
|
-
* @param boxHeight - the height of the box
|
|
27
|
-
* @param textBaselineYPosition - the distance from the top of rendered text to the baseline
|
|
28
|
-
* @param textHeight - the height of the text being rendered
|
|
29
|
-
* @param verticalAlignment - the vertical alignment of the text
|
|
30
42
|
* @returns an SVG path command to draw the curve
|
|
31
43
|
*/
|
|
32
|
-
export declare const generateCurvedBaseline: (boxDimensions
|
|
44
|
+
export declare const generateCurvedBaseline: ({ boxDimensions, baseline, textHeight, verticalAlignment, }: GenerateCurvedBaselineOptions) => string;
|
|
45
|
+
|
|
46
|
+
export declare interface GenerateCurvedBaselineOptions {
|
|
47
|
+
boxDimensions: BoxDimensions;
|
|
48
|
+
baseline: number;
|
|
49
|
+
textHeight: number;
|
|
50
|
+
verticalAlignment: VerticalTextAlignmentValues;
|
|
51
|
+
}
|
|
33
52
|
|
|
34
53
|
/**
|
|
35
54
|
* Generate a path as a baseline for straight text
|
|
36
55
|
* This can be called multiple times for multiline text by incrementing the lineNumber parameter
|
|
37
56
|
*
|
|
38
|
-
* @
|
|
39
|
-
* @param totalHeightOfAllTextLines - combined measured height of all lines of text
|
|
40
|
-
* @param textBaselineYPosition - the y position of the measured baseline for this specific line of text
|
|
41
|
-
* @param heightOfThisTextLine - the height of this specific line of text
|
|
42
|
-
* @param verticalAlignment - vertical alignment of the text within the box
|
|
43
|
-
* @param lineNumber - the line number of this text line (starting from 0)
|
|
44
|
-
* @returns an SVG path command to draw the curve
|
|
57
|
+
* @returns an SVG path command to draw the baseline
|
|
45
58
|
*/
|
|
46
|
-
export declare const generateFlatBaseline: (boxDimensions
|
|
59
|
+
export declare const generateFlatBaseline: ({ boxDimensions, totalTextHeight, baseline, lineHeight, verticalAlignment, lineNumber, }: GenerateFlatBaselineOptions) => string;
|
|
60
|
+
|
|
61
|
+
export declare interface GenerateFlatBaselineOptions {
|
|
62
|
+
boxDimensions: BoxDimensions;
|
|
63
|
+
totalTextHeight: number;
|
|
64
|
+
baseline: number;
|
|
65
|
+
lineHeight: number;
|
|
66
|
+
verticalAlignment?: VerticalTextAlignmentValues;
|
|
67
|
+
lineNumber?: number;
|
|
68
|
+
}
|
|
47
69
|
|
|
48
70
|
export declare const getFontCache: () => Map<any, any>;
|
|
49
71
|
|
|
50
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Get the unique colours used by a font's SVG glyphs.
|
|
74
|
+
*
|
|
75
|
+
* @param font - A loaded font with svgGlyphs populated
|
|
76
|
+
* @returns Array of unique hex colour strings found in the font's SVG glyphs
|
|
77
|
+
*/
|
|
78
|
+
export declare function getFontColours(font: LoadedFont): string[];
|
|
79
|
+
|
|
80
|
+
export declare const getFontSizeFromPhysicalSize: ({ font, boxDimensions, physicalSize, spacing, }: GetFontSizeFromPhysicalSizeOptions) => number;
|
|
51
81
|
|
|
52
|
-
export declare
|
|
82
|
+
export declare interface GetFontSizeFromPhysicalSizeOptions {
|
|
83
|
+
font: LoadedFont;
|
|
84
|
+
boxDimensions: BoxDimensions;
|
|
85
|
+
physicalSize: PhysicalSize;
|
|
86
|
+
spacing?: TextSpacing;
|
|
87
|
+
}
|
|
53
88
|
|
|
54
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Async text renderer. Loads font from URL, then delegates to renderText.
|
|
91
|
+
*/
|
|
92
|
+
export declare const getRenderedText: (options: GetRenderedTextOptions) => Promise<string>;
|
|
93
|
+
|
|
94
|
+
/** Options for async getRenderedText (loads font from URL). */
|
|
95
|
+
export declare interface GetRenderedTextOptions {
|
|
96
|
+
text: string;
|
|
97
|
+
fontUrl: string;
|
|
98
|
+
physicalSize: PhysicalSize;
|
|
99
|
+
boxDimensions: BoxDimensions;
|
|
100
|
+
spacing?: TextSpacing;
|
|
101
|
+
verticalAlignment?: VerticalTextAlignmentValues;
|
|
102
|
+
baseline?: BaselineType | BaselineConfig;
|
|
103
|
+
horizontalAlignment?: HorizontalTextAlignmentValues;
|
|
104
|
+
fillColour?: ColourInfo;
|
|
105
|
+
strokeColour?: ColourInfo;
|
|
106
|
+
colourMap?: ColourMap;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export declare interface GetTextAsPathDataOptions {
|
|
110
|
+
font: LoadedFont;
|
|
111
|
+
baselinePath: string;
|
|
112
|
+
text: string;
|
|
113
|
+
fontSize: number;
|
|
114
|
+
spacing?: TextSpacing;
|
|
115
|
+
horizontalAlignment?: HorizontalTextAlignmentValues;
|
|
116
|
+
colourMap?: ColourMap;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export declare const getTextMetricsAtFontSize: ({ font, text, fontSize, spacing, }: GetTextMetricsAtFontSizeOptions) => {
|
|
55
120
|
width: number;
|
|
56
121
|
height: number;
|
|
57
122
|
baseline: number;
|
|
58
123
|
};
|
|
59
124
|
|
|
125
|
+
export declare interface GetTextMetricsAtFontSizeOptions {
|
|
126
|
+
font: LoadedFont;
|
|
127
|
+
text: string;
|
|
128
|
+
fontSize: number;
|
|
129
|
+
spacing?: TextSpacing;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export declare interface GlyphFill {
|
|
133
|
+
readonly pathData: string;
|
|
134
|
+
readonly colour: ColourInfo;
|
|
135
|
+
}
|
|
136
|
+
|
|
60
137
|
export declare type HorizontalTextAlignmentValues = 'left' | 'centre' | 'right' | 'distributed';
|
|
61
138
|
|
|
62
139
|
export declare const LINE_HEIGHT = 1.1;
|
|
@@ -71,21 +148,54 @@ export declare const loadOpentypeFont: (fontUrl: string, fetchSVGGlyphs?: boolea
|
|
|
71
148
|
|
|
72
149
|
export declare type MeasurementUnits = 'mm' | 'in';
|
|
73
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Normalise a baseline option (string shorthand or object) into a BaselineConfig.
|
|
153
|
+
*/
|
|
154
|
+
export declare const normaliseBaselineOption: (baseline: BaselineType | BaselineConfig | undefined) => BaselineConfig;
|
|
155
|
+
|
|
74
156
|
export declare type PhysicalSize = [height: number, units: MeasurementUnits];
|
|
75
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Synchronous text renderer. Requires a pre-loaded font.
|
|
160
|
+
*/
|
|
161
|
+
export declare const renderText: (options: RenderTextOptions) => string;
|
|
162
|
+
|
|
163
|
+
/** Options for synchronous renderText (font already loaded). */
|
|
76
164
|
export declare interface RenderTextOptions {
|
|
77
165
|
text: string;
|
|
78
|
-
|
|
166
|
+
font: LoadedFont;
|
|
79
167
|
physicalSize: PhysicalSize;
|
|
80
168
|
boxDimensions: BoxDimensions;
|
|
81
|
-
|
|
169
|
+
spacing?: TextSpacing;
|
|
82
170
|
verticalAlignment?: VerticalTextAlignmentValues;
|
|
83
|
-
baseline?: BaselineType;
|
|
171
|
+
baseline?: BaselineType | BaselineConfig;
|
|
84
172
|
horizontalAlignment?: HorizontalTextAlignmentValues;
|
|
85
|
-
fillColour?:
|
|
86
|
-
strokeColour?:
|
|
173
|
+
fillColour?: ColourInfo;
|
|
174
|
+
strokeColour?: ColourInfo;
|
|
175
|
+
colourMap?: ColourMap;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export declare interface SvgGlyphEntry {
|
|
179
|
+
content: string;
|
|
180
|
+
viewBox: string;
|
|
181
|
+
x: number;
|
|
182
|
+
y: number;
|
|
183
|
+
width: number;
|
|
184
|
+
height: number;
|
|
185
|
+
glyphIndex: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export declare interface TextSpacing {
|
|
189
|
+
readonly outlineWidth: number;
|
|
190
|
+
readonly letterSpacing: number;
|
|
191
|
+
readonly letterSpacingOutline: number;
|
|
87
192
|
}
|
|
88
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Validate a custom baseline SVG path string.
|
|
196
|
+
*/
|
|
197
|
+
export declare const validateCustomBaselinePath: (path: string) => void;
|
|
198
|
+
|
|
89
199
|
export declare type VerticalTextAlignmentValues = 'centre' | 'top' | 'bottom';
|
|
90
200
|
|
|
91
201
|
export { }
|