modern-text 0.3.6 → 0.3.8
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.cjs +76 -73
- package/dist/index.d.cts +117 -122
- package/dist/index.d.mts +117 -122
- package/dist/index.d.ts +117 -122
- package/dist/index.js +4 -4
- package/dist/index.mjs +78 -74
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -3,100 +3,6 @@ export * from 'modern-path2d';
|
|
|
3
3
|
import { Font, Sfnt, GlyphPathCommand } from 'modern-font';
|
|
4
4
|
export * from 'modern-font';
|
|
5
5
|
|
|
6
|
-
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
7
|
-
type WritingMode = 'horizontal-tb' | 'vertical-lr' | 'vertical-rl';
|
|
8
|
-
type TextOrientation = 'mixed' | 'upright' | 'sideways-right' | 'sideways';
|
|
9
|
-
type FontWeight = 'normal' | 'bold' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
10
|
-
type FontStyle = 'normal' | 'italic' | 'oblique' | `oblique ${string}`;
|
|
11
|
-
type FontKerning = 'none' | 'auto' | 'normal';
|
|
12
|
-
type TextWrap = 'wrap' | 'nowrap';
|
|
13
|
-
type TextAlign = 'center' | 'end' | 'left' | 'right' | 'start';
|
|
14
|
-
type VerticalAlign = 'baseline' | 'top' | 'middle' | 'bottom' | 'sub' | 'super' | 'text-top' | 'text-bottom';
|
|
15
|
-
type TextTransform = 'none' | 'uppercase' | 'lowercase';
|
|
16
|
-
type TextDecoration = 'none' | 'underline' | 'line-through';
|
|
17
|
-
type ListStyleType = 'none' | 'disc';
|
|
18
|
-
type ListStyleImage = 'none' | string;
|
|
19
|
-
type ListStyleSize = 'cover' | Sizeable;
|
|
20
|
-
type ListStylePosition = 'inside' | 'outside';
|
|
21
|
-
type HighlightImage = 'none' | string;
|
|
22
|
-
type HighlightSize = 'cover' | Sizeable;
|
|
23
|
-
type HighlightStrokeWidth = Sizeable;
|
|
24
|
-
type HighlightOverflow = 'none' | 'visible' | 'hidden';
|
|
25
|
-
interface TextLineStyle {
|
|
26
|
-
writingMode: WritingMode;
|
|
27
|
-
textWrap: TextWrap;
|
|
28
|
-
textAlign: TextAlign;
|
|
29
|
-
textIndent: number;
|
|
30
|
-
lineHeight: number;
|
|
31
|
-
listStyleType: ListStyleType;
|
|
32
|
-
listStyleImage: ListStyleImage;
|
|
33
|
-
listStyleSize: ListStyleSize;
|
|
34
|
-
listStylePosition: ListStylePosition;
|
|
35
|
-
}
|
|
36
|
-
interface TextInlineStyle {
|
|
37
|
-
verticalAlign: VerticalAlign;
|
|
38
|
-
letterSpacing: number;
|
|
39
|
-
fontSize: number;
|
|
40
|
-
fontWeight: FontWeight;
|
|
41
|
-
fontFamily: string;
|
|
42
|
-
fontStyle: FontStyle;
|
|
43
|
-
fontKerning?: FontKerning;
|
|
44
|
-
textTransform: TextTransform;
|
|
45
|
-
textOrientation: TextOrientation;
|
|
46
|
-
textDecoration: TextDecoration;
|
|
47
|
-
highlightReferImage: HighlightImage;
|
|
48
|
-
highlightImage: HighlightImage;
|
|
49
|
-
highlightSize: HighlightSize;
|
|
50
|
-
highlightStrokeWidth: HighlightStrokeWidth;
|
|
51
|
-
highlightOverflow: HighlightOverflow;
|
|
52
|
-
}
|
|
53
|
-
interface TextDrawStyle {
|
|
54
|
-
color: string | CanvasGradient | CanvasPattern;
|
|
55
|
-
backgroundColor: string | CanvasGradient | CanvasPattern;
|
|
56
|
-
textStrokeWidth: number;
|
|
57
|
-
textStrokeColor: string | CanvasGradient | CanvasPattern;
|
|
58
|
-
shadowColor: string;
|
|
59
|
-
shadowOffsetX: number;
|
|
60
|
-
shadowOffsetY: number;
|
|
61
|
-
shadowBlur: number;
|
|
62
|
-
translateX: number;
|
|
63
|
-
translateY: number;
|
|
64
|
-
skewX: number;
|
|
65
|
-
skewY: number;
|
|
66
|
-
}
|
|
67
|
-
interface TextStyle extends TextLineStyle, TextInlineStyle, TextDrawStyle {
|
|
68
|
-
}
|
|
69
|
-
interface FragmentContent extends Partial<TextStyle> {
|
|
70
|
-
content: string;
|
|
71
|
-
}
|
|
72
|
-
interface ParagraphContent extends Partial<TextStyle> {
|
|
73
|
-
fragments: FragmentContent[];
|
|
74
|
-
}
|
|
75
|
-
type TextContent = string | FragmentContent | ParagraphContent | (string | FragmentContent | ParagraphContent | (string | FragmentContent)[])[];
|
|
76
|
-
|
|
77
|
-
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
78
|
-
declare function uploadColor(style: Partial<TextStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
79
|
-
interface LinearGradient {
|
|
80
|
-
x0: number;
|
|
81
|
-
y0: number;
|
|
82
|
-
x1: number;
|
|
83
|
-
y1: number;
|
|
84
|
-
stops: {
|
|
85
|
-
offset: number;
|
|
86
|
-
color: string;
|
|
87
|
-
}[];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interface DrawShapePathsOptions extends Partial<TextStyle> {
|
|
91
|
-
ctx: CanvasRenderingContext2D;
|
|
92
|
-
path: Path2D;
|
|
93
|
-
fontSize: number;
|
|
94
|
-
clipRect?: BoundingBox;
|
|
95
|
-
}
|
|
96
|
-
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
97
|
-
|
|
98
|
-
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
99
|
-
|
|
100
6
|
declare class Fragment {
|
|
101
7
|
content: string;
|
|
102
8
|
style: Partial<TextStyle>;
|
|
@@ -130,9 +36,9 @@ declare class Character {
|
|
|
130
36
|
get fontSize(): number;
|
|
131
37
|
get fontHeight(): number;
|
|
132
38
|
constructor(content: string, index: number, parent: Fragment);
|
|
133
|
-
protected _getFontSfnt(
|
|
39
|
+
protected _getFontSfnt(fonts?: Record<string, Font>): Sfnt | undefined;
|
|
134
40
|
updateGlyph(sfnt?: Sfnt | undefined): this;
|
|
135
|
-
update(
|
|
41
|
+
update(fonts?: Record<string, Font>): this;
|
|
136
42
|
protected _decoration(): GlyphPathCommand[];
|
|
137
43
|
protected _italic(path: Path2D, startPoint?: VectorLike): void;
|
|
138
44
|
getGlyphMinMax(min?: Vector2, max?: Vector2, withStyle?: boolean): {
|
|
@@ -154,18 +60,6 @@ declare class Paragraph {
|
|
|
154
60
|
addFragment(content: string, style?: Partial<TextStyle>): Fragment;
|
|
155
61
|
}
|
|
156
62
|
|
|
157
|
-
type PromiseLike<T> = T | Promise<T>;
|
|
158
|
-
interface Plugin {
|
|
159
|
-
name: string;
|
|
160
|
-
paths?: Path2D[];
|
|
161
|
-
getBoundingBox?: (text: Text) => BoundingBox | undefined;
|
|
162
|
-
updateOrder?: number;
|
|
163
|
-
update?: (text: Text) => PromiseLike<void>;
|
|
164
|
-
renderOrder?: number;
|
|
165
|
-
render?: (ctx: CanvasRenderingContext2D, text: Text) => PromiseLike<void>;
|
|
166
|
-
}
|
|
167
|
-
declare function definePlugin(options: Plugin): Plugin;
|
|
168
|
-
|
|
169
63
|
interface MeasuredParagraph {
|
|
170
64
|
paragraphIndex: number;
|
|
171
65
|
left: number;
|
|
@@ -225,12 +119,6 @@ declare class Measurer {
|
|
|
225
119
|
measure(dom?: HTMLElement): MeasureDomResult;
|
|
226
120
|
}
|
|
227
121
|
|
|
228
|
-
declare class Parser {
|
|
229
|
-
protected _text: Text;
|
|
230
|
-
constructor(_text: Text);
|
|
231
|
-
parse(): Paragraph[];
|
|
232
|
-
}
|
|
233
|
-
|
|
234
122
|
interface TextRenderOptions {
|
|
235
123
|
view: HTMLCanvasElement;
|
|
236
124
|
pixelRatio?: number;
|
|
@@ -240,6 +128,7 @@ interface TextOptions {
|
|
|
240
128
|
style?: Partial<TextStyle>;
|
|
241
129
|
measureDom?: HTMLElement;
|
|
242
130
|
effects?: Partial<TextStyle>[];
|
|
131
|
+
fonts?: Record<string, Font>;
|
|
243
132
|
}
|
|
244
133
|
interface MeasureResult {
|
|
245
134
|
paragraphs: Paragraph[];
|
|
@@ -263,15 +152,15 @@ declare class Text {
|
|
|
263
152
|
glyphBox: BoundingBox;
|
|
264
153
|
pathBox: BoundingBox;
|
|
265
154
|
boundingBox: BoundingBox;
|
|
266
|
-
parser: Parser;
|
|
267
155
|
measurer: Measurer;
|
|
268
|
-
plugins: Map<string,
|
|
269
|
-
|
|
156
|
+
plugins: Map<string, TextPlugin>;
|
|
157
|
+
fonts?: Record<string, Font>;
|
|
270
158
|
get fontSize(): number;
|
|
271
159
|
get isVertical(): boolean;
|
|
272
160
|
get characters(): Character[];
|
|
273
161
|
constructor(options?: TextOptions);
|
|
274
|
-
use(plugin:
|
|
162
|
+
use(plugin: TextPlugin): this;
|
|
163
|
+
updateParagraphs(): this;
|
|
275
164
|
measure(dom?: HTMLElement | undefined): MeasureResult;
|
|
276
165
|
getGlyphBox(): BoundingBox;
|
|
277
166
|
updatePathBox(): this;
|
|
@@ -281,15 +170,121 @@ declare class Text {
|
|
|
281
170
|
render(options: TextRenderOptions): this;
|
|
282
171
|
}
|
|
283
172
|
|
|
173
|
+
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
174
|
+
type WritingMode = 'horizontal-tb' | 'vertical-lr' | 'vertical-rl';
|
|
175
|
+
type TextOrientation = 'mixed' | 'upright' | 'sideways-right' | 'sideways';
|
|
176
|
+
type FontWeight = 'normal' | 'bold' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
177
|
+
type FontStyle = 'normal' | 'italic' | 'oblique' | `oblique ${string}`;
|
|
178
|
+
type FontKerning = 'none' | 'auto' | 'normal';
|
|
179
|
+
type TextWrap = 'wrap' | 'nowrap';
|
|
180
|
+
type TextAlign = 'center' | 'end' | 'left' | 'right' | 'start';
|
|
181
|
+
type VerticalAlign = 'baseline' | 'top' | 'middle' | 'bottom' | 'sub' | 'super' | 'text-top' | 'text-bottom';
|
|
182
|
+
type TextTransform = 'none' | 'uppercase' | 'lowercase';
|
|
183
|
+
type TextDecoration = 'none' | 'underline' | 'line-through';
|
|
184
|
+
type ListStyleType = 'none' | 'disc';
|
|
185
|
+
type ListStyleImage = 'none' | string;
|
|
186
|
+
type ListStyleSize = 'cover' | Sizeable;
|
|
187
|
+
type ListStylePosition = 'inside' | 'outside';
|
|
188
|
+
type HighlightImage = 'none' | string;
|
|
189
|
+
type HighlightSize = 'cover' | Sizeable;
|
|
190
|
+
type HighlightStrokeWidth = Sizeable;
|
|
191
|
+
type HighlightOverflow = 'none' | 'visible' | 'hidden';
|
|
192
|
+
interface TextLineStyle {
|
|
193
|
+
writingMode: WritingMode;
|
|
194
|
+
textWrap: TextWrap;
|
|
195
|
+
textAlign: TextAlign;
|
|
196
|
+
textIndent: number;
|
|
197
|
+
lineHeight: number;
|
|
198
|
+
listStyleType: ListStyleType;
|
|
199
|
+
listStyleImage: ListStyleImage;
|
|
200
|
+
listStyleSize: ListStyleSize;
|
|
201
|
+
listStylePosition: ListStylePosition;
|
|
202
|
+
}
|
|
203
|
+
interface TextInlineStyle {
|
|
204
|
+
verticalAlign: VerticalAlign;
|
|
205
|
+
letterSpacing: number;
|
|
206
|
+
fontSize: number;
|
|
207
|
+
fontWeight: FontWeight;
|
|
208
|
+
fontFamily: string;
|
|
209
|
+
fontStyle: FontStyle;
|
|
210
|
+
fontKerning?: FontKerning;
|
|
211
|
+
textTransform: TextTransform;
|
|
212
|
+
textOrientation: TextOrientation;
|
|
213
|
+
textDecoration: TextDecoration;
|
|
214
|
+
highlightReferImage: HighlightImage;
|
|
215
|
+
highlightImage: HighlightImage;
|
|
216
|
+
highlightSize: HighlightSize;
|
|
217
|
+
highlightStrokeWidth: HighlightStrokeWidth;
|
|
218
|
+
highlightOverflow: HighlightOverflow;
|
|
219
|
+
}
|
|
220
|
+
interface TextDrawStyle {
|
|
221
|
+
color: string | CanvasGradient | CanvasPattern;
|
|
222
|
+
backgroundColor: string | CanvasGradient | CanvasPattern;
|
|
223
|
+
textStrokeWidth: number;
|
|
224
|
+
textStrokeColor: string | CanvasGradient | CanvasPattern;
|
|
225
|
+
shadowColor: string;
|
|
226
|
+
shadowOffsetX: number;
|
|
227
|
+
shadowOffsetY: number;
|
|
228
|
+
shadowBlur: number;
|
|
229
|
+
translateX: number;
|
|
230
|
+
translateY: number;
|
|
231
|
+
skewX: number;
|
|
232
|
+
skewY: number;
|
|
233
|
+
}
|
|
234
|
+
interface TextStyle extends TextLineStyle, TextInlineStyle, TextDrawStyle {
|
|
235
|
+
}
|
|
236
|
+
interface FragmentContent extends Partial<TextStyle> {
|
|
237
|
+
content: string;
|
|
238
|
+
}
|
|
239
|
+
interface ParagraphContent extends Partial<TextStyle> {
|
|
240
|
+
fragments: FragmentContent[];
|
|
241
|
+
}
|
|
242
|
+
type TextContent = string | FragmentContent | ParagraphContent | (string | FragmentContent | ParagraphContent | (string | FragmentContent)[])[];
|
|
243
|
+
type PromiseLike<T> = T | Promise<T>;
|
|
244
|
+
interface TextPlugin {
|
|
245
|
+
name: string;
|
|
246
|
+
paths?: Path2D[];
|
|
247
|
+
getBoundingBox?: (text: Text) => BoundingBox | undefined;
|
|
248
|
+
updateOrder?: number;
|
|
249
|
+
update?: (text: Text) => PromiseLike<void>;
|
|
250
|
+
renderOrder?: number;
|
|
251
|
+
render?: (ctx: CanvasRenderingContext2D, text: Text) => PromiseLike<void>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
255
|
+
declare function uploadColor(style: Partial<TextStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
256
|
+
interface LinearGradient {
|
|
257
|
+
x0: number;
|
|
258
|
+
y0: number;
|
|
259
|
+
x1: number;
|
|
260
|
+
y1: number;
|
|
261
|
+
stops: {
|
|
262
|
+
offset: number;
|
|
263
|
+
color: string;
|
|
264
|
+
}[];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
interface DrawShapePathsOptions extends Partial<TextStyle> {
|
|
268
|
+
ctx: CanvasRenderingContext2D;
|
|
269
|
+
path: Path2D;
|
|
270
|
+
fontSize: number;
|
|
271
|
+
clipRect?: BoundingBox;
|
|
272
|
+
}
|
|
273
|
+
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
274
|
+
|
|
275
|
+
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
276
|
+
|
|
284
277
|
declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text): void;
|
|
285
278
|
|
|
279
|
+
declare function definePlugin(options: TextPlugin): TextPlugin;
|
|
280
|
+
|
|
286
281
|
declare function measureText(options: TextOptions): MeasureResult;
|
|
287
282
|
|
|
288
|
-
declare function highlight():
|
|
283
|
+
declare function highlight(): TextPlugin;
|
|
289
284
|
|
|
290
|
-
declare function listStyle():
|
|
285
|
+
declare function listStyle(): TextPlugin;
|
|
291
286
|
|
|
292
|
-
declare function render():
|
|
287
|
+
declare function render(): TextPlugin;
|
|
293
288
|
declare function getTransform2D(text: Text, style: Partial<TextStyle>): Matrix3;
|
|
294
289
|
|
|
295
290
|
declare function renderText(options: TextOptions & TextRenderOptions): Text;
|
|
@@ -297,4 +292,4 @@ declare function renderText(options: TextOptions & TextRenderOptions): Text;
|
|
|
297
292
|
declare function isNone(val: string | undefined): boolean;
|
|
298
293
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
299
294
|
|
|
300
|
-
export { Character, type DrawShapePathsOptions, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type HighlightImage, type HighlightOverflow, type HighlightSize, type HighlightStrokeWidth, type LinearGradient, type ListStyleImage, type ListStylePosition, type ListStyleSize, type ListStyleType, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type ParagraphContent,
|
|
295
|
+
export { Character, type DrawShapePathsOptions, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type HighlightImage, type HighlightOverflow, type HighlightSize, type HighlightStrokeWidth, type LinearGradient, type ListStyleImage, type ListStylePosition, type ListStyleSize, type ListStyleType, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type ParagraphContent, type Sizeable, Text, type TextAlign, type TextContent, type TextDecoration, type TextDrawStyle, type TextInlineStyle, type TextLineStyle, type TextOptions, type TextOrientation, type TextPlugin, type TextRenderOptions, type TextStyle, type TextTransform, type TextWrap, type VerticalAlign, type WritingMode, defaultTextStyles, definePlugin, drawPath, filterEmpty, getTransform2D, highlight, isNone, listStyle, measureText, parseColor, render, renderText, setupView, uploadColor, uploadColors };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,100 +3,6 @@ export * from 'modern-path2d';
|
|
|
3
3
|
import { Font, Sfnt, GlyphPathCommand } from 'modern-font';
|
|
4
4
|
export * from 'modern-font';
|
|
5
5
|
|
|
6
|
-
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
7
|
-
type WritingMode = 'horizontal-tb' | 'vertical-lr' | 'vertical-rl';
|
|
8
|
-
type TextOrientation = 'mixed' | 'upright' | 'sideways-right' | 'sideways';
|
|
9
|
-
type FontWeight = 'normal' | 'bold' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
10
|
-
type FontStyle = 'normal' | 'italic' | 'oblique' | `oblique ${string}`;
|
|
11
|
-
type FontKerning = 'none' | 'auto' | 'normal';
|
|
12
|
-
type TextWrap = 'wrap' | 'nowrap';
|
|
13
|
-
type TextAlign = 'center' | 'end' | 'left' | 'right' | 'start';
|
|
14
|
-
type VerticalAlign = 'baseline' | 'top' | 'middle' | 'bottom' | 'sub' | 'super' | 'text-top' | 'text-bottom';
|
|
15
|
-
type TextTransform = 'none' | 'uppercase' | 'lowercase';
|
|
16
|
-
type TextDecoration = 'none' | 'underline' | 'line-through';
|
|
17
|
-
type ListStyleType = 'none' | 'disc';
|
|
18
|
-
type ListStyleImage = 'none' | string;
|
|
19
|
-
type ListStyleSize = 'cover' | Sizeable;
|
|
20
|
-
type ListStylePosition = 'inside' | 'outside';
|
|
21
|
-
type HighlightImage = 'none' | string;
|
|
22
|
-
type HighlightSize = 'cover' | Sizeable;
|
|
23
|
-
type HighlightStrokeWidth = Sizeable;
|
|
24
|
-
type HighlightOverflow = 'none' | 'visible' | 'hidden';
|
|
25
|
-
interface TextLineStyle {
|
|
26
|
-
writingMode: WritingMode;
|
|
27
|
-
textWrap: TextWrap;
|
|
28
|
-
textAlign: TextAlign;
|
|
29
|
-
textIndent: number;
|
|
30
|
-
lineHeight: number;
|
|
31
|
-
listStyleType: ListStyleType;
|
|
32
|
-
listStyleImage: ListStyleImage;
|
|
33
|
-
listStyleSize: ListStyleSize;
|
|
34
|
-
listStylePosition: ListStylePosition;
|
|
35
|
-
}
|
|
36
|
-
interface TextInlineStyle {
|
|
37
|
-
verticalAlign: VerticalAlign;
|
|
38
|
-
letterSpacing: number;
|
|
39
|
-
fontSize: number;
|
|
40
|
-
fontWeight: FontWeight;
|
|
41
|
-
fontFamily: string;
|
|
42
|
-
fontStyle: FontStyle;
|
|
43
|
-
fontKerning?: FontKerning;
|
|
44
|
-
textTransform: TextTransform;
|
|
45
|
-
textOrientation: TextOrientation;
|
|
46
|
-
textDecoration: TextDecoration;
|
|
47
|
-
highlightReferImage: HighlightImage;
|
|
48
|
-
highlightImage: HighlightImage;
|
|
49
|
-
highlightSize: HighlightSize;
|
|
50
|
-
highlightStrokeWidth: HighlightStrokeWidth;
|
|
51
|
-
highlightOverflow: HighlightOverflow;
|
|
52
|
-
}
|
|
53
|
-
interface TextDrawStyle {
|
|
54
|
-
color: string | CanvasGradient | CanvasPattern;
|
|
55
|
-
backgroundColor: string | CanvasGradient | CanvasPattern;
|
|
56
|
-
textStrokeWidth: number;
|
|
57
|
-
textStrokeColor: string | CanvasGradient | CanvasPattern;
|
|
58
|
-
shadowColor: string;
|
|
59
|
-
shadowOffsetX: number;
|
|
60
|
-
shadowOffsetY: number;
|
|
61
|
-
shadowBlur: number;
|
|
62
|
-
translateX: number;
|
|
63
|
-
translateY: number;
|
|
64
|
-
skewX: number;
|
|
65
|
-
skewY: number;
|
|
66
|
-
}
|
|
67
|
-
interface TextStyle extends TextLineStyle, TextInlineStyle, TextDrawStyle {
|
|
68
|
-
}
|
|
69
|
-
interface FragmentContent extends Partial<TextStyle> {
|
|
70
|
-
content: string;
|
|
71
|
-
}
|
|
72
|
-
interface ParagraphContent extends Partial<TextStyle> {
|
|
73
|
-
fragments: FragmentContent[];
|
|
74
|
-
}
|
|
75
|
-
type TextContent = string | FragmentContent | ParagraphContent | (string | FragmentContent | ParagraphContent | (string | FragmentContent)[])[];
|
|
76
|
-
|
|
77
|
-
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
78
|
-
declare function uploadColor(style: Partial<TextStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
79
|
-
interface LinearGradient {
|
|
80
|
-
x0: number;
|
|
81
|
-
y0: number;
|
|
82
|
-
x1: number;
|
|
83
|
-
y1: number;
|
|
84
|
-
stops: {
|
|
85
|
-
offset: number;
|
|
86
|
-
color: string;
|
|
87
|
-
}[];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interface DrawShapePathsOptions extends Partial<TextStyle> {
|
|
91
|
-
ctx: CanvasRenderingContext2D;
|
|
92
|
-
path: Path2D;
|
|
93
|
-
fontSize: number;
|
|
94
|
-
clipRect?: BoundingBox;
|
|
95
|
-
}
|
|
96
|
-
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
97
|
-
|
|
98
|
-
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
99
|
-
|
|
100
6
|
declare class Fragment {
|
|
101
7
|
content: string;
|
|
102
8
|
style: Partial<TextStyle>;
|
|
@@ -130,9 +36,9 @@ declare class Character {
|
|
|
130
36
|
get fontSize(): number;
|
|
131
37
|
get fontHeight(): number;
|
|
132
38
|
constructor(content: string, index: number, parent: Fragment);
|
|
133
|
-
protected _getFontSfnt(
|
|
39
|
+
protected _getFontSfnt(fonts?: Record<string, Font>): Sfnt | undefined;
|
|
134
40
|
updateGlyph(sfnt?: Sfnt | undefined): this;
|
|
135
|
-
update(
|
|
41
|
+
update(fonts?: Record<string, Font>): this;
|
|
136
42
|
protected _decoration(): GlyphPathCommand[];
|
|
137
43
|
protected _italic(path: Path2D, startPoint?: VectorLike): void;
|
|
138
44
|
getGlyphMinMax(min?: Vector2, max?: Vector2, withStyle?: boolean): {
|
|
@@ -154,18 +60,6 @@ declare class Paragraph {
|
|
|
154
60
|
addFragment(content: string, style?: Partial<TextStyle>): Fragment;
|
|
155
61
|
}
|
|
156
62
|
|
|
157
|
-
type PromiseLike<T> = T | Promise<T>;
|
|
158
|
-
interface Plugin {
|
|
159
|
-
name: string;
|
|
160
|
-
paths?: Path2D[];
|
|
161
|
-
getBoundingBox?: (text: Text) => BoundingBox | undefined;
|
|
162
|
-
updateOrder?: number;
|
|
163
|
-
update?: (text: Text) => PromiseLike<void>;
|
|
164
|
-
renderOrder?: number;
|
|
165
|
-
render?: (ctx: CanvasRenderingContext2D, text: Text) => PromiseLike<void>;
|
|
166
|
-
}
|
|
167
|
-
declare function definePlugin(options: Plugin): Plugin;
|
|
168
|
-
|
|
169
63
|
interface MeasuredParagraph {
|
|
170
64
|
paragraphIndex: number;
|
|
171
65
|
left: number;
|
|
@@ -225,12 +119,6 @@ declare class Measurer {
|
|
|
225
119
|
measure(dom?: HTMLElement): MeasureDomResult;
|
|
226
120
|
}
|
|
227
121
|
|
|
228
|
-
declare class Parser {
|
|
229
|
-
protected _text: Text;
|
|
230
|
-
constructor(_text: Text);
|
|
231
|
-
parse(): Paragraph[];
|
|
232
|
-
}
|
|
233
|
-
|
|
234
122
|
interface TextRenderOptions {
|
|
235
123
|
view: HTMLCanvasElement;
|
|
236
124
|
pixelRatio?: number;
|
|
@@ -240,6 +128,7 @@ interface TextOptions {
|
|
|
240
128
|
style?: Partial<TextStyle>;
|
|
241
129
|
measureDom?: HTMLElement;
|
|
242
130
|
effects?: Partial<TextStyle>[];
|
|
131
|
+
fonts?: Record<string, Font>;
|
|
243
132
|
}
|
|
244
133
|
interface MeasureResult {
|
|
245
134
|
paragraphs: Paragraph[];
|
|
@@ -263,15 +152,15 @@ declare class Text {
|
|
|
263
152
|
glyphBox: BoundingBox;
|
|
264
153
|
pathBox: BoundingBox;
|
|
265
154
|
boundingBox: BoundingBox;
|
|
266
|
-
parser: Parser;
|
|
267
155
|
measurer: Measurer;
|
|
268
|
-
plugins: Map<string,
|
|
269
|
-
|
|
156
|
+
plugins: Map<string, TextPlugin>;
|
|
157
|
+
fonts?: Record<string, Font>;
|
|
270
158
|
get fontSize(): number;
|
|
271
159
|
get isVertical(): boolean;
|
|
272
160
|
get characters(): Character[];
|
|
273
161
|
constructor(options?: TextOptions);
|
|
274
|
-
use(plugin:
|
|
162
|
+
use(plugin: TextPlugin): this;
|
|
163
|
+
updateParagraphs(): this;
|
|
275
164
|
measure(dom?: HTMLElement | undefined): MeasureResult;
|
|
276
165
|
getGlyphBox(): BoundingBox;
|
|
277
166
|
updatePathBox(): this;
|
|
@@ -281,15 +170,121 @@ declare class Text {
|
|
|
281
170
|
render(options: TextRenderOptions): this;
|
|
282
171
|
}
|
|
283
172
|
|
|
173
|
+
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
174
|
+
type WritingMode = 'horizontal-tb' | 'vertical-lr' | 'vertical-rl';
|
|
175
|
+
type TextOrientation = 'mixed' | 'upright' | 'sideways-right' | 'sideways';
|
|
176
|
+
type FontWeight = 'normal' | 'bold' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
177
|
+
type FontStyle = 'normal' | 'italic' | 'oblique' | `oblique ${string}`;
|
|
178
|
+
type FontKerning = 'none' | 'auto' | 'normal';
|
|
179
|
+
type TextWrap = 'wrap' | 'nowrap';
|
|
180
|
+
type TextAlign = 'center' | 'end' | 'left' | 'right' | 'start';
|
|
181
|
+
type VerticalAlign = 'baseline' | 'top' | 'middle' | 'bottom' | 'sub' | 'super' | 'text-top' | 'text-bottom';
|
|
182
|
+
type TextTransform = 'none' | 'uppercase' | 'lowercase';
|
|
183
|
+
type TextDecoration = 'none' | 'underline' | 'line-through';
|
|
184
|
+
type ListStyleType = 'none' | 'disc';
|
|
185
|
+
type ListStyleImage = 'none' | string;
|
|
186
|
+
type ListStyleSize = 'cover' | Sizeable;
|
|
187
|
+
type ListStylePosition = 'inside' | 'outside';
|
|
188
|
+
type HighlightImage = 'none' | string;
|
|
189
|
+
type HighlightSize = 'cover' | Sizeable;
|
|
190
|
+
type HighlightStrokeWidth = Sizeable;
|
|
191
|
+
type HighlightOverflow = 'none' | 'visible' | 'hidden';
|
|
192
|
+
interface TextLineStyle {
|
|
193
|
+
writingMode: WritingMode;
|
|
194
|
+
textWrap: TextWrap;
|
|
195
|
+
textAlign: TextAlign;
|
|
196
|
+
textIndent: number;
|
|
197
|
+
lineHeight: number;
|
|
198
|
+
listStyleType: ListStyleType;
|
|
199
|
+
listStyleImage: ListStyleImage;
|
|
200
|
+
listStyleSize: ListStyleSize;
|
|
201
|
+
listStylePosition: ListStylePosition;
|
|
202
|
+
}
|
|
203
|
+
interface TextInlineStyle {
|
|
204
|
+
verticalAlign: VerticalAlign;
|
|
205
|
+
letterSpacing: number;
|
|
206
|
+
fontSize: number;
|
|
207
|
+
fontWeight: FontWeight;
|
|
208
|
+
fontFamily: string;
|
|
209
|
+
fontStyle: FontStyle;
|
|
210
|
+
fontKerning?: FontKerning;
|
|
211
|
+
textTransform: TextTransform;
|
|
212
|
+
textOrientation: TextOrientation;
|
|
213
|
+
textDecoration: TextDecoration;
|
|
214
|
+
highlightReferImage: HighlightImage;
|
|
215
|
+
highlightImage: HighlightImage;
|
|
216
|
+
highlightSize: HighlightSize;
|
|
217
|
+
highlightStrokeWidth: HighlightStrokeWidth;
|
|
218
|
+
highlightOverflow: HighlightOverflow;
|
|
219
|
+
}
|
|
220
|
+
interface TextDrawStyle {
|
|
221
|
+
color: string | CanvasGradient | CanvasPattern;
|
|
222
|
+
backgroundColor: string | CanvasGradient | CanvasPattern;
|
|
223
|
+
textStrokeWidth: number;
|
|
224
|
+
textStrokeColor: string | CanvasGradient | CanvasPattern;
|
|
225
|
+
shadowColor: string;
|
|
226
|
+
shadowOffsetX: number;
|
|
227
|
+
shadowOffsetY: number;
|
|
228
|
+
shadowBlur: number;
|
|
229
|
+
translateX: number;
|
|
230
|
+
translateY: number;
|
|
231
|
+
skewX: number;
|
|
232
|
+
skewY: number;
|
|
233
|
+
}
|
|
234
|
+
interface TextStyle extends TextLineStyle, TextInlineStyle, TextDrawStyle {
|
|
235
|
+
}
|
|
236
|
+
interface FragmentContent extends Partial<TextStyle> {
|
|
237
|
+
content: string;
|
|
238
|
+
}
|
|
239
|
+
interface ParagraphContent extends Partial<TextStyle> {
|
|
240
|
+
fragments: FragmentContent[];
|
|
241
|
+
}
|
|
242
|
+
type TextContent = string | FragmentContent | ParagraphContent | (string | FragmentContent | ParagraphContent | (string | FragmentContent)[])[];
|
|
243
|
+
type PromiseLike<T> = T | Promise<T>;
|
|
244
|
+
interface TextPlugin {
|
|
245
|
+
name: string;
|
|
246
|
+
paths?: Path2D[];
|
|
247
|
+
getBoundingBox?: (text: Text) => BoundingBox | undefined;
|
|
248
|
+
updateOrder?: number;
|
|
249
|
+
update?: (text: Text) => PromiseLike<void>;
|
|
250
|
+
renderOrder?: number;
|
|
251
|
+
render?: (ctx: CanvasRenderingContext2D, text: Text) => PromiseLike<void>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
255
|
+
declare function uploadColor(style: Partial<TextStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
256
|
+
interface LinearGradient {
|
|
257
|
+
x0: number;
|
|
258
|
+
y0: number;
|
|
259
|
+
x1: number;
|
|
260
|
+
y1: number;
|
|
261
|
+
stops: {
|
|
262
|
+
offset: number;
|
|
263
|
+
color: string;
|
|
264
|
+
}[];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
interface DrawShapePathsOptions extends Partial<TextStyle> {
|
|
268
|
+
ctx: CanvasRenderingContext2D;
|
|
269
|
+
path: Path2D;
|
|
270
|
+
fontSize: number;
|
|
271
|
+
clipRect?: BoundingBox;
|
|
272
|
+
}
|
|
273
|
+
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
274
|
+
|
|
275
|
+
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
276
|
+
|
|
284
277
|
declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text): void;
|
|
285
278
|
|
|
279
|
+
declare function definePlugin(options: TextPlugin): TextPlugin;
|
|
280
|
+
|
|
286
281
|
declare function measureText(options: TextOptions): MeasureResult;
|
|
287
282
|
|
|
288
|
-
declare function highlight():
|
|
283
|
+
declare function highlight(): TextPlugin;
|
|
289
284
|
|
|
290
|
-
declare function listStyle():
|
|
285
|
+
declare function listStyle(): TextPlugin;
|
|
291
286
|
|
|
292
|
-
declare function render():
|
|
287
|
+
declare function render(): TextPlugin;
|
|
293
288
|
declare function getTransform2D(text: Text, style: Partial<TextStyle>): Matrix3;
|
|
294
289
|
|
|
295
290
|
declare function renderText(options: TextOptions & TextRenderOptions): Text;
|
|
@@ -297,4 +292,4 @@ declare function renderText(options: TextOptions & TextRenderOptions): Text;
|
|
|
297
292
|
declare function isNone(val: string | undefined): boolean;
|
|
298
293
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
299
294
|
|
|
300
|
-
export { Character, type DrawShapePathsOptions, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type HighlightImage, type HighlightOverflow, type HighlightSize, type HighlightStrokeWidth, type LinearGradient, type ListStyleImage, type ListStylePosition, type ListStyleSize, type ListStyleType, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type ParagraphContent,
|
|
295
|
+
export { Character, type DrawShapePathsOptions, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type HighlightImage, type HighlightOverflow, type HighlightSize, type HighlightStrokeWidth, type LinearGradient, type ListStyleImage, type ListStylePosition, type ListStyleSize, type ListStyleType, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type ParagraphContent, type Sizeable, Text, type TextAlign, type TextContent, type TextDecoration, type TextDrawStyle, type TextInlineStyle, type TextLineStyle, type TextOptions, type TextOrientation, type TextPlugin, type TextRenderOptions, type TextStyle, type TextTransform, type TextWrap, type VerticalAlign, type WritingMode, defaultTextStyles, definePlugin, drawPath, filterEmpty, getTransform2D, highlight, isNone, listStyle, measureText, parseColor, render, renderText, setupView, uploadColor, uploadColors };
|