@unmade/text-renderer 1.0.0 → 1.1.1
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/__vite-browser-external-CijFC1_R.js +7 -0
- package/dist/baselines/index.d.ts +40 -0
- package/dist/ce-adapter/index.cjs +1 -1
- package/dist/ce-adapter/index.js +154 -152
- package/dist/chunk-3b4jIN3o.js +13 -0
- package/dist/constants.d.ts +5 -0
- package/dist/glyph/svg-glyph-converter.d.ts +42 -0
- package/dist/helpers/bbox.d.ts +33 -0
- package/dist/helpers/matrix.d.ts +8 -0
- package/dist/helpers/point.d.ts +17 -0
- package/dist/helpers/xml.d.ts +1 -0
- package/dist/index.d.ts +16 -249
- package/dist/index.js +1543 -1954
- package/dist/loading/createLoadedFont.d.ts +53 -0
- package/dist/loading/index.d.ts +4 -0
- package/dist/measuring/conversion.d.ts +2 -0
- package/dist/measuring/index.d.ts +28 -0
- package/dist/node/baselines/index.d.ts +40 -0
- package/dist/node/ce-adapter/ce-types.d.ts +171 -0
- package/dist/node/ce-adapter/extractTextPlacements.d.ts +11 -0
- package/dist/node/ce-adapter/index.d.ts +12 -0
- package/dist/node/ce-adapter/mapStateToRendererOptions.d.ts +13 -0
- package/dist/node/ce-adapter/types.d.ts +56 -0
- package/dist/node/constants.d.ts +5 -0
- package/dist/node/glyph/svg-glyph-converter.d.ts +42 -0
- package/dist/node/helpers/bbox.d.ts +33 -0
- package/dist/node/helpers/matrix.d.ts +8 -0
- package/dist/node/helpers/point.d.ts +17 -0
- package/dist/node/helpers/xml.d.ts +1 -0
- package/dist/node/index.d.ts +16 -249
- package/dist/node/index.js +821 -895
- package/dist/node/loading/createLoadedFont.d.ts +53 -0
- package/dist/node/loading/index.d.ts +4 -0
- package/dist/node/measuring/conversion.d.ts +2 -0
- package/dist/node/measuring/index.d.ts +28 -0
- package/dist/node/renderText.d.ts +5 -0
- package/dist/node/rendering/index.d.ts +42 -0
- package/dist/node/svg/index.d.ts +11 -0
- package/dist/node/types.d.ts +72 -0
- package/dist/renderText.d.ts +5 -0
- package/dist/rendering/index.d.ts +42 -0
- package/dist/svg/index.d.ts +11 -0
- package/dist/types.d.ts +72 -0
- package/dist/worker/baselines/index.d.ts +40 -0
- package/dist/worker/ce-adapter/ce-types.d.ts +171 -0
- package/dist/worker/ce-adapter/extractTextPlacements.d.ts +11 -0
- package/dist/worker/ce-adapter/index.d.ts +12 -0
- package/dist/worker/ce-adapter/mapStateToRendererOptions.d.ts +13 -0
- package/dist/worker/ce-adapter/types.d.ts +56 -0
- package/dist/worker/constants.d.ts +5 -0
- package/dist/worker/glyph/svg-glyph-converter.d.ts +42 -0
- package/dist/worker/helpers/bbox.d.ts +33 -0
- package/dist/worker/helpers/matrix.d.ts +8 -0
- package/dist/worker/helpers/point.d.ts +17 -0
- package/dist/worker/helpers/xml.d.ts +1 -0
- package/dist/worker/index.d.ts +16 -249
- package/dist/worker/index.js +8003 -9677
- package/dist/worker/loading/createLoadedFont.d.ts +53 -0
- package/dist/worker/loading/index.d.ts +4 -0
- package/dist/worker/measuring/conversion.d.ts +2 -0
- package/dist/worker/measuring/index.d.ts +28 -0
- package/dist/worker/renderText.d.ts +5 -0
- package/dist/worker/rendering/index.d.ts +42 -0
- package/dist/worker/svg/index.d.ts +11 -0
- package/dist/worker/types.d.ts +72 -0
- package/package.json +11 -10
- package/dist/__vite-browser-external-l0sNRNKZ.js +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,249 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
physicalUnits: MeasurementUnits;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export declare interface ColourInfo {
|
|
21
|
-
readonly hex: string;
|
|
22
|
-
readonly reference?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Maps original hex colour → replacement ColourInfo. */
|
|
26
|
-
export declare type ColourMap = Readonly<Record<string, ColourInfo>>;
|
|
27
|
-
|
|
28
|
-
export declare const DEFAULT_OUTLINE_FACTOR = 0.03125;
|
|
29
|
-
|
|
30
|
-
export declare const DEFAULT_SPACING: TextSpacing;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Generate a path command to curve text and align that text to the top of the box.
|
|
34
|
-
* Uses two quadratic bezier curves — one from the bottom left to the peak, and a
|
|
35
|
-
* second mirrored from the peak to the end.
|
|
36
|
-
*
|
|
37
|
-
* Curved text is not currently supported for multiline text.
|
|
38
|
-
*
|
|
39
|
-
* @returns an SVG path command to draw the curve
|
|
40
|
-
*/
|
|
41
|
-
export declare const generateCurvedBaseline: ({ boxDimensions, baseline, textHeight, verticalAlignment, }: GenerateCurvedBaselineOptions) => string;
|
|
42
|
-
|
|
43
|
-
export declare interface GenerateCurvedBaselineOptions {
|
|
44
|
-
boxDimensions: BoxDimensions;
|
|
45
|
-
baseline: number;
|
|
46
|
-
textHeight: number;
|
|
47
|
-
verticalAlignment: VerticalTextAlignmentValues;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Generate a path as a baseline for straight text
|
|
52
|
-
* This can be called multiple times for multiline text by incrementing the lineNumber parameter
|
|
53
|
-
*
|
|
54
|
-
* @returns an SVG path command to draw the baseline
|
|
55
|
-
*/
|
|
56
|
-
export declare const generateFlatBaseline: ({ boxDimensions, totalTextHeight, baseline, lineHeight, verticalAlignment, lineNumber, }: GenerateFlatBaselineOptions) => string;
|
|
57
|
-
|
|
58
|
-
export declare interface GenerateFlatBaselineOptions {
|
|
59
|
-
boxDimensions: BoxDimensions;
|
|
60
|
-
totalTextHeight: number;
|
|
61
|
-
baseline: number;
|
|
62
|
-
lineHeight: number;
|
|
63
|
-
verticalAlignment?: VerticalTextAlignmentValues;
|
|
64
|
-
lineNumber?: number;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export declare const getFontCache: () => Map<string, LoadedFont>;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get the unique colours used by a font's SVG glyphs.
|
|
71
|
-
*
|
|
72
|
-
* @param font - A loaded font with svgGlyphs populated
|
|
73
|
-
* @returns Array of unique hex colour strings found in the font's SVG glyphs
|
|
74
|
-
*/
|
|
75
|
-
export declare function getFontColours(font: LoadedFont): string[];
|
|
76
|
-
|
|
77
|
-
export declare const getFontSizeFromPhysicalSize: ({ font, boxDimensions, physicalSize, spacing, }: GetFontSizeFromPhysicalSizeOptions) => number;
|
|
78
|
-
|
|
79
|
-
export declare interface GetFontSizeFromPhysicalSizeOptions {
|
|
80
|
-
font: LoadedFont;
|
|
81
|
-
boxDimensions: BoxDimensions;
|
|
82
|
-
physicalSize: PhysicalSize;
|
|
83
|
-
spacing?: TextSpacing;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Async text renderer. Loads font from URL, then delegates to renderText.
|
|
88
|
-
*
|
|
89
|
-
* If the calculated font size causes a TOO_WIDE error and fontSizeFallback is
|
|
90
|
-
* provided, retries once using the fallback as an explicit fontSize override.
|
|
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
|
-
/**
|
|
100
|
-
* Fallback font size (in pixels) to use if the calculated size causes a
|
|
101
|
-
* TOO_WIDE error. Useful when the caller has an authoritative size (e.g.
|
|
102
|
-
* from the CE) that avoids floating-point rounding issues.
|
|
103
|
-
*/
|
|
104
|
-
fontSizeFallback?: number;
|
|
105
|
-
boxDimensions: BoxDimensions;
|
|
106
|
-
spacing?: TextSpacing;
|
|
107
|
-
verticalAlignment?: VerticalTextAlignmentValues;
|
|
108
|
-
baseline?: BaselineType | BaselineConfig;
|
|
109
|
-
horizontalAlignment?: HorizontalTextAlignmentValues;
|
|
110
|
-
fillColour?: ColourInfo;
|
|
111
|
-
strokeColour?: ColourInfo;
|
|
112
|
-
colourMap?: ColourMap;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export declare interface GetTextAsPathDataOptions {
|
|
116
|
-
font: LoadedFont;
|
|
117
|
-
baselinePath: string;
|
|
118
|
-
text: string;
|
|
119
|
-
fontSize: number;
|
|
120
|
-
spacing?: TextSpacing;
|
|
121
|
-
horizontalAlignment?: HorizontalTextAlignmentValues;
|
|
122
|
-
colourMap?: ColourMap;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export declare const getTextMetricsAtFontSize: ({ font, text, fontSize, spacing, }: GetTextMetricsAtFontSizeOptions) => {
|
|
126
|
-
width: number;
|
|
127
|
-
height: number;
|
|
128
|
-
baseline: number;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export declare interface GetTextMetricsAtFontSizeOptions {
|
|
132
|
-
font: LoadedFont;
|
|
133
|
-
text: string;
|
|
134
|
-
fontSize: number;
|
|
135
|
-
spacing?: TextSpacing;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export declare interface GlyphFill {
|
|
139
|
-
readonly pathData: string;
|
|
140
|
-
readonly colour: ColourInfo;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export declare type HorizontalTextAlignmentValues = 'left' | 'centre' | 'right' | 'distributed';
|
|
144
|
-
|
|
145
|
-
export declare const LINE_HEIGHT = 1.1;
|
|
146
|
-
|
|
147
|
-
export declare interface LoadedFont {
|
|
148
|
-
unitsPerEm: number;
|
|
149
|
-
names: {
|
|
150
|
-
fontFamily: string;
|
|
151
|
-
};
|
|
152
|
-
svgGlyphs?: Map<number, SVGGlyphData>;
|
|
153
|
-
charToGlyph(char: string): {
|
|
154
|
-
index: number;
|
|
155
|
-
advanceWidth: number;
|
|
156
|
-
name: string;
|
|
157
|
-
getBoundingBox(): {
|
|
158
|
-
x1: number;
|
|
159
|
-
y1: number;
|
|
160
|
-
x2: number;
|
|
161
|
-
y2: number;
|
|
162
|
-
};
|
|
163
|
-
};
|
|
164
|
-
getPath(text: string, x: number, y: number, fontSize: number, options?: {
|
|
165
|
-
drawSVG?: boolean;
|
|
166
|
-
}): {
|
|
167
|
-
getBoundingBox(): {
|
|
168
|
-
x1: number;
|
|
169
|
-
y1: number;
|
|
170
|
-
x2: number;
|
|
171
|
-
y2: number;
|
|
172
|
-
};
|
|
173
|
-
toPathData(decimals?: number): string;
|
|
174
|
-
};
|
|
175
|
-
getPaths(text: string, x: number, y: number, fontSize: number, options?: {
|
|
176
|
-
drawSVG?: boolean;
|
|
177
|
-
}): Array<{
|
|
178
|
-
getBoundingBox(): {
|
|
179
|
-
x1: number;
|
|
180
|
-
y1: number;
|
|
181
|
-
x2: number;
|
|
182
|
-
y2: number;
|
|
183
|
-
};
|
|
184
|
-
toPathData(decimals?: number): string;
|
|
185
|
-
}>;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export declare const loadFont: (fontUrl: string, fetchSVGGlyphs?: boolean) => Promise<LoadedFont>;
|
|
189
|
-
|
|
190
|
-
export declare type MeasurementUnits = 'mm' | 'in';
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Normalise a baseline option (string shorthand or object) into a BaselineConfig.
|
|
194
|
-
*/
|
|
195
|
-
export declare const normaliseBaselineOption: (baseline: BaselineType | BaselineConfig | undefined) => BaselineConfig;
|
|
196
|
-
|
|
197
|
-
export declare type PhysicalSize = [height: number, units: MeasurementUnits];
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Synchronous text renderer. Requires a pre-loaded font.
|
|
201
|
-
*/
|
|
202
|
-
export declare const renderText: (options: RenderTextOptions) => string;
|
|
203
|
-
|
|
204
|
-
/** Options for synchronous renderText (font already loaded). */
|
|
205
|
-
export declare interface RenderTextOptions {
|
|
206
|
-
text: string;
|
|
207
|
-
font: LoadedFont;
|
|
208
|
-
physicalSize: PhysicalSize;
|
|
209
|
-
/** When provided, bypasses the physicalSize → font size calculation. */
|
|
210
|
-
fontSize?: number;
|
|
211
|
-
boxDimensions: BoxDimensions;
|
|
212
|
-
spacing?: TextSpacing;
|
|
213
|
-
verticalAlignment?: VerticalTextAlignmentValues;
|
|
214
|
-
baseline?: BaselineType | BaselineConfig;
|
|
215
|
-
horizontalAlignment?: HorizontalTextAlignmentValues;
|
|
216
|
-
fillColour?: ColourInfo;
|
|
217
|
-
strokeColour?: ColourInfo;
|
|
218
|
-
colourMap?: ColourMap;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
declare interface SVGGlyphData {
|
|
222
|
-
svg: string;
|
|
223
|
-
viewbox: string;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export declare interface SvgGlyphEntry {
|
|
227
|
-
content: string;
|
|
228
|
-
viewBox: string;
|
|
229
|
-
x: number;
|
|
230
|
-
y: number;
|
|
231
|
-
width: number;
|
|
232
|
-
height: number;
|
|
233
|
-
glyphIndex: number;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export declare interface TextSpacing {
|
|
237
|
-
readonly outlineWidth: number;
|
|
238
|
-
readonly letterSpacing: number;
|
|
239
|
-
readonly letterSpacingOutline: number;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Validate a custom baseline SVG path string.
|
|
244
|
-
*/
|
|
245
|
-
export declare const validateCustomBaselinePath: (path: string) => void;
|
|
246
|
-
|
|
247
|
-
export declare type VerticalTextAlignmentValues = 'centre' | 'top' | 'bottom';
|
|
248
|
-
|
|
249
|
-
export { }
|
|
1
|
+
import { GetRenderedTextOptions } from './types';
|
|
2
|
+
export { type GenerateCurvedBaselineOptions, type GenerateFlatBaselineOptions, generateCurvedBaseline, generateFlatBaseline, normaliseBaselineOption, validateCustomBaselinePath, } from './baselines';
|
|
3
|
+
export { DEFAULT_OUTLINE_FACTOR, DEFAULT_SPACING, LINE_HEIGHT, } from './constants';
|
|
4
|
+
export { getFontColours } from './glyph/svg-glyph-converter';
|
|
5
|
+
export { getFontCache, type LoadedFont, loadFont } from './loading';
|
|
6
|
+
export { type GetFontSizeFromPhysicalSizeOptions, type GetTextMetricsAtFontSizeOptions, getFontSizeFromPhysicalSize, getTextMetricsAtFontSize, } from './measuring';
|
|
7
|
+
export type { GetTextAsPathDataOptions, SvgGlyphEntry } from './rendering';
|
|
8
|
+
export { renderText } from './renderText';
|
|
9
|
+
export type { BaselineConfig, BaselineType, BoxDimensions, ColourInfo, ColourMap, GetRenderedTextOptions, GlyphFill, HorizontalTextAlignmentValues, MeasurementUnits, PhysicalSize, RenderTextOptions, TextSpacing, VerticalTextAlignmentValues, } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Async text renderer. Loads font from URL, then delegates to renderText.
|
|
12
|
+
*
|
|
13
|
+
* If the calculated font size causes a TOO_WIDE error and fontSizeFallback is
|
|
14
|
+
* provided, retries once using the fallback as an explicit fontSize override.
|
|
15
|
+
*/
|
|
16
|
+
export declare const getRenderedText: (options: GetRenderedTextOptions) => Promise<string>;
|