modern-text 1.0.0 → 1.0.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/index.cjs +2 -40
- package/dist/index.d.cts +63 -158
- package/dist/index.d.mts +63 -158
- package/dist/index.d.ts +63 -158
- package/dist/index.js +3 -3
- package/dist/index.mjs +2 -40
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const modernPath2d = require('modern-path2d');
|
|
4
|
+
const modernIdoc = require('modern-idoc');
|
|
4
5
|
const modernFont = require('modern-font');
|
|
5
6
|
|
|
6
7
|
function parseColor(ctx, source, box) {
|
|
@@ -1481,46 +1482,7 @@ function textDecoration() {
|
|
|
1481
1482
|
});
|
|
1482
1483
|
}
|
|
1483
1484
|
|
|
1484
|
-
const defaultTextStyles =
|
|
1485
|
-
writingMode: "horizontal-tb",
|
|
1486
|
-
verticalAlign: "baseline",
|
|
1487
|
-
lineHeight: 1.2,
|
|
1488
|
-
letterSpacing: 0,
|
|
1489
|
-
// font
|
|
1490
|
-
fontSize: 14,
|
|
1491
|
-
fontWeight: "normal",
|
|
1492
|
-
fontFamily: "",
|
|
1493
|
-
fontStyle: "normal",
|
|
1494
|
-
fontKerning: "normal",
|
|
1495
|
-
// text
|
|
1496
|
-
textWrap: "wrap",
|
|
1497
|
-
textAlign: "start",
|
|
1498
|
-
textIndent: 0,
|
|
1499
|
-
textTransform: "none",
|
|
1500
|
-
textOrientation: "mixed",
|
|
1501
|
-
textDecoration: "none",
|
|
1502
|
-
// textStroke
|
|
1503
|
-
textStrokeWidth: 0,
|
|
1504
|
-
textStrokeColor: "#000",
|
|
1505
|
-
// color
|
|
1506
|
-
color: "#000",
|
|
1507
|
-
backgroundColor: "rgba(0, 0, 0, 0)",
|
|
1508
|
-
// listStyle
|
|
1509
|
-
listStyleType: "none",
|
|
1510
|
-
listStyleImage: "none",
|
|
1511
|
-
listStyleColormap: "none",
|
|
1512
|
-
listStyleSize: "cover",
|
|
1513
|
-
listStylePosition: "outside",
|
|
1514
|
-
// shadow
|
|
1515
|
-
shadowColor: "rgba(0, 0, 0, 0)",
|
|
1516
|
-
shadowOffsetX: 0,
|
|
1517
|
-
shadowOffsetY: 0,
|
|
1518
|
-
shadowBlur: 0,
|
|
1519
|
-
translateX: 0,
|
|
1520
|
-
translateY: 0,
|
|
1521
|
-
skewX: 0,
|
|
1522
|
-
skewY: 0
|
|
1523
|
-
};
|
|
1485
|
+
const defaultTextStyles = modernIdoc.getDefaultTextStyle();
|
|
1524
1486
|
class Text extends EventEmitter {
|
|
1525
1487
|
debug;
|
|
1526
1488
|
content;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
|
+
import { ITextStyle, ITextContent, Highlight } from 'modern-idoc';
|
|
1
2
|
import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
2
3
|
import { Fonts, Sfnt } from 'modern-font';
|
|
3
4
|
|
|
5
|
+
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
6
|
+
declare function uploadColor(style: Partial<ITextStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
7
|
+
interface LinearGradient {
|
|
8
|
+
x0: number;
|
|
9
|
+
y0: number;
|
|
10
|
+
x1: number;
|
|
11
|
+
y1: number;
|
|
12
|
+
stops: {
|
|
13
|
+
offset: number;
|
|
14
|
+
color: string;
|
|
15
|
+
}[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface DrawShapePathsOptions extends Partial<ITextStyle> {
|
|
19
|
+
ctx: CanvasRenderingContext2D;
|
|
20
|
+
path: Path2D;
|
|
21
|
+
fontSize: number;
|
|
22
|
+
clipRect?: BoundingBox;
|
|
23
|
+
}
|
|
24
|
+
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
25
|
+
|
|
26
|
+
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
27
|
+
|
|
4
28
|
declare class Fragment {
|
|
5
29
|
content: string;
|
|
6
|
-
style: Partial<
|
|
30
|
+
style: Partial<ITextStyle>;
|
|
7
31
|
parent: Paragraph;
|
|
8
32
|
inlineBox: BoundingBox;
|
|
9
33
|
characters: Character[];
|
|
10
|
-
computedStyle:
|
|
34
|
+
computedStyle: ITextStyle;
|
|
11
35
|
get computedContent(): string;
|
|
12
|
-
constructor(content: string, style: Partial<
|
|
36
|
+
constructor(content: string, style: Partial<ITextStyle> | undefined, parent: Paragraph);
|
|
13
37
|
updateComputedStyle(): this;
|
|
14
38
|
initCharacters(): this;
|
|
15
39
|
}
|
|
@@ -41,7 +65,7 @@ declare class Character {
|
|
|
41
65
|
centerDiviation: number;
|
|
42
66
|
fontStyle?: 'bold' | 'italic';
|
|
43
67
|
get center(): Vector2 | undefined;
|
|
44
|
-
get computedStyle():
|
|
68
|
+
get computedStyle(): ITextStyle;
|
|
45
69
|
get isVertical(): boolean;
|
|
46
70
|
get fontSize(): number;
|
|
47
71
|
get fontHeight(): number;
|
|
@@ -55,18 +79,37 @@ declare class Character {
|
|
|
55
79
|
max: Vector2;
|
|
56
80
|
} | undefined;
|
|
57
81
|
getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
|
|
58
|
-
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<
|
|
82
|
+
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<ITextStyle>): void;
|
|
59
83
|
}
|
|
60
84
|
|
|
61
85
|
declare class Paragraph {
|
|
62
|
-
style: Partial<
|
|
63
|
-
parentStyle:
|
|
86
|
+
style: Partial<ITextStyle>;
|
|
87
|
+
parentStyle: ITextStyle;
|
|
64
88
|
lineBox: BoundingBox;
|
|
65
89
|
fragments: Fragment[];
|
|
66
|
-
computedStyle:
|
|
67
|
-
constructor(style: Partial<
|
|
90
|
+
computedStyle: ITextStyle;
|
|
91
|
+
constructor(style: Partial<ITextStyle>, parentStyle: ITextStyle);
|
|
68
92
|
updateComputedStyle(): this;
|
|
69
|
-
addFragment(content: string, style?: Partial<
|
|
93
|
+
addFragment(content: string, style?: Partial<ITextStyle>): Fragment;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface TextPlugin {
|
|
97
|
+
name: string;
|
|
98
|
+
paths?: Path2D[];
|
|
99
|
+
getBoundingBox?: (text: Text$1) => BoundingBox | undefined;
|
|
100
|
+
update?: (text: Text$1) => void;
|
|
101
|
+
updateOrder?: number;
|
|
102
|
+
render?: (ctx: CanvasRenderingContext2D, text: Text$1) => void;
|
|
103
|
+
renderOrder?: number;
|
|
104
|
+
load?: (text: Text$1) => Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
interface TextOptions {
|
|
107
|
+
debug?: boolean;
|
|
108
|
+
content?: ITextContent;
|
|
109
|
+
style?: Partial<ITextStyle>;
|
|
110
|
+
measureDom?: HTMLElement;
|
|
111
|
+
effects?: Partial<ITextStyle>[];
|
|
112
|
+
fonts?: Fonts;
|
|
70
113
|
}
|
|
71
114
|
|
|
72
115
|
type EventListenerValue<T = any> = (ev: T) => void;
|
|
@@ -133,7 +176,7 @@ declare class Measurer {
|
|
|
133
176
|
* </ul>
|
|
134
177
|
* </section>
|
|
135
178
|
*/
|
|
136
|
-
createParagraphDom(paragraphs: Paragraph[], rootStyle:
|
|
179
|
+
createParagraphDom(paragraphs: Paragraph[], rootStyle: ITextStyle): {
|
|
137
180
|
dom: HTMLElement;
|
|
138
181
|
destory: () => void;
|
|
139
182
|
};
|
|
@@ -150,7 +193,7 @@ declare class Measurer {
|
|
|
150
193
|
characters: MeasuredCharacter[];
|
|
151
194
|
};
|
|
152
195
|
measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
|
|
153
|
-
measure(paragraphs: Paragraph[], rootStyle:
|
|
196
|
+
measure(paragraphs: Paragraph[], rootStyle: ITextStyle, dom?: HTMLElement): MeasureDomResult;
|
|
154
197
|
}
|
|
155
198
|
|
|
156
199
|
interface TextRenderOptions {
|
|
@@ -165,7 +208,7 @@ interface MeasureResult {
|
|
|
165
208
|
pathBox: BoundingBox;
|
|
166
209
|
boundingBox: BoundingBox;
|
|
167
210
|
}
|
|
168
|
-
declare const defaultTextStyles:
|
|
211
|
+
declare const defaultTextStyles: ITextStyle;
|
|
169
212
|
interface TextEventMap {
|
|
170
213
|
update: {
|
|
171
214
|
text: Text$1;
|
|
@@ -182,12 +225,12 @@ interface TextEventMap {
|
|
|
182
225
|
}
|
|
183
226
|
declare class Text$1 extends EventEmitter<TextEventMap> {
|
|
184
227
|
debug: boolean;
|
|
185
|
-
content:
|
|
186
|
-
style: Partial<
|
|
187
|
-
effects?: Partial<
|
|
228
|
+
content: ITextContent;
|
|
229
|
+
style: Partial<ITextStyle>;
|
|
230
|
+
effects?: Partial<ITextStyle>[];
|
|
188
231
|
measureDom?: HTMLElement;
|
|
189
232
|
needsUpdate: boolean;
|
|
190
|
-
computedStyle:
|
|
233
|
+
computedStyle: ITextStyle;
|
|
191
234
|
paragraphs: Paragraph[];
|
|
192
235
|
lineBox: BoundingBox;
|
|
193
236
|
rawGlyphBox: BoundingBox;
|
|
@@ -218,144 +261,6 @@ declare class Text$1 extends EventEmitter<TextEventMap> {
|
|
|
218
261
|
render(options: TextRenderOptions): void;
|
|
219
262
|
}
|
|
220
263
|
|
|
221
|
-
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
222
|
-
type WritingMode = 'horizontal-tb' | 'vertical-lr' | 'vertical-rl';
|
|
223
|
-
type TextOrientation = 'mixed' | 'upright' | 'sideways-right' | 'sideways';
|
|
224
|
-
type FontWeight = 'normal' | 'bold' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
225
|
-
type FontStyle = 'normal' | 'italic' | 'oblique' | `oblique ${string}`;
|
|
226
|
-
type FontKerning = 'none' | 'auto' | 'normal';
|
|
227
|
-
type TextWrap = 'wrap' | 'nowrap';
|
|
228
|
-
type TextAlign = 'center' | 'end' | 'left' | 'right' | 'start';
|
|
229
|
-
type VerticalAlign = 'baseline' | 'top' | 'middle' | 'bottom' | 'sub' | 'super' | 'text-top' | 'text-bottom';
|
|
230
|
-
type TextTransform = 'none' | 'uppercase' | 'lowercase';
|
|
231
|
-
type TextDecorationLine = 'none' | 'underline' | 'line-through' | 'overline';
|
|
232
|
-
type ListStyleType = 'none' | 'disc';
|
|
233
|
-
type ListStyleImage = 'none' | string;
|
|
234
|
-
type ListStyleColormap = 'none' | Record<string, string>;
|
|
235
|
-
type ListStyleSize = 'cover' | Sizeable;
|
|
236
|
-
type ListStylePosition = 'inside' | 'outside';
|
|
237
|
-
type HighlightLine = TextDecorationLine | 'outline';
|
|
238
|
-
type HighlightImage = 'none' | string;
|
|
239
|
-
type HighlightReferImage = 'none' | string;
|
|
240
|
-
type HighlightColormap = 'none' | Record<string, string>;
|
|
241
|
-
type HighlightSize = 'cover' | Sizeable;
|
|
242
|
-
type HighlightThickness = Sizeable;
|
|
243
|
-
interface TextLineStyle {
|
|
244
|
-
writingMode: WritingMode;
|
|
245
|
-
textWrap: TextWrap;
|
|
246
|
-
textAlign: TextAlign;
|
|
247
|
-
textIndent: number;
|
|
248
|
-
lineHeight: number;
|
|
249
|
-
listStyleType: ListStyleType;
|
|
250
|
-
listStyleImage: ListStyleImage;
|
|
251
|
-
listStyleColormap: ListStyleColormap;
|
|
252
|
-
listStyleSize: ListStyleSize;
|
|
253
|
-
listStylePosition: ListStylePosition;
|
|
254
|
-
}
|
|
255
|
-
interface HighlightStyle {
|
|
256
|
-
image: HighlightImage;
|
|
257
|
-
referImage: HighlightReferImage;
|
|
258
|
-
colormap: HighlightColormap;
|
|
259
|
-
line: HighlightLine;
|
|
260
|
-
size: HighlightSize;
|
|
261
|
-
thickness: HighlightThickness;
|
|
262
|
-
}
|
|
263
|
-
interface TextHighlightStyle {
|
|
264
|
-
highlight?: Partial<HighlightStyle>;
|
|
265
|
-
highlightImage?: HighlightImage;
|
|
266
|
-
highlightReferImage?: HighlightReferImage;
|
|
267
|
-
highlightColormap?: HighlightColormap;
|
|
268
|
-
highlightLine?: HighlightLine;
|
|
269
|
-
highlightSize?: HighlightSize;
|
|
270
|
-
highlightThickness?: HighlightThickness;
|
|
271
|
-
}
|
|
272
|
-
interface TextInlineStyle extends TextHighlightStyle {
|
|
273
|
-
verticalAlign: VerticalAlign;
|
|
274
|
-
letterSpacing: number;
|
|
275
|
-
fontSize: number;
|
|
276
|
-
fontWeight: FontWeight;
|
|
277
|
-
fontFamily: string;
|
|
278
|
-
fontStyle: FontStyle;
|
|
279
|
-
fontKerning?: FontKerning;
|
|
280
|
-
textTransform: TextTransform;
|
|
281
|
-
textOrientation: TextOrientation;
|
|
282
|
-
textDecoration: TextDecorationLine;
|
|
283
|
-
}
|
|
284
|
-
interface TextDrawStyle {
|
|
285
|
-
color: string | CanvasGradient | CanvasPattern;
|
|
286
|
-
backgroundColor: string | CanvasGradient | CanvasPattern;
|
|
287
|
-
textStrokeWidth: number;
|
|
288
|
-
textStrokeColor: string | CanvasGradient | CanvasPattern;
|
|
289
|
-
shadowColor: string;
|
|
290
|
-
shadowOffsetX: number;
|
|
291
|
-
shadowOffsetY: number;
|
|
292
|
-
shadowBlur: number;
|
|
293
|
-
translateX: number;
|
|
294
|
-
translateY: number;
|
|
295
|
-
skewX: number;
|
|
296
|
-
skewY: number;
|
|
297
|
-
}
|
|
298
|
-
interface TextStyle extends TextLineStyle, TextInlineStyle, TextDrawStyle {
|
|
299
|
-
marginLeft?: number;
|
|
300
|
-
marginTop?: number;
|
|
301
|
-
marginRight?: number;
|
|
302
|
-
marginBottom?: number;
|
|
303
|
-
paddingLeft?: number;
|
|
304
|
-
paddingTop?: number;
|
|
305
|
-
paddingRight?: number;
|
|
306
|
-
paddingBottom?: number;
|
|
307
|
-
width?: number;
|
|
308
|
-
height?: number;
|
|
309
|
-
}
|
|
310
|
-
interface FragmentContent extends Partial<TextStyle> {
|
|
311
|
-
content: string;
|
|
312
|
-
}
|
|
313
|
-
interface ParagraphContent extends Partial<TextStyle> {
|
|
314
|
-
fragments: FragmentContent[];
|
|
315
|
-
}
|
|
316
|
-
type TextContent = string | FragmentContent | ParagraphContent | (string | FragmentContent | ParagraphContent | (string | FragmentContent)[])[];
|
|
317
|
-
interface TextPlugin {
|
|
318
|
-
name: string;
|
|
319
|
-
paths?: Path2D[];
|
|
320
|
-
getBoundingBox?: (text: Text$1) => BoundingBox | undefined;
|
|
321
|
-
update?: (text: Text$1) => void;
|
|
322
|
-
updateOrder?: number;
|
|
323
|
-
render?: (ctx: CanvasRenderingContext2D, text: Text$1) => void;
|
|
324
|
-
renderOrder?: number;
|
|
325
|
-
load?: (text: Text$1) => Promise<void>;
|
|
326
|
-
}
|
|
327
|
-
interface TextOptions {
|
|
328
|
-
debug?: boolean;
|
|
329
|
-
content?: TextContent;
|
|
330
|
-
style?: Partial<TextStyle>;
|
|
331
|
-
measureDom?: HTMLElement;
|
|
332
|
-
effects?: Partial<TextStyle>[];
|
|
333
|
-
fonts?: Fonts;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
337
|
-
declare function uploadColor(style: Partial<TextStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
338
|
-
interface LinearGradient {
|
|
339
|
-
x0: number;
|
|
340
|
-
y0: number;
|
|
341
|
-
x1: number;
|
|
342
|
-
y1: number;
|
|
343
|
-
stops: {
|
|
344
|
-
offset: number;
|
|
345
|
-
color: string;
|
|
346
|
-
}[];
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
interface DrawShapePathsOptions extends Partial<TextStyle> {
|
|
350
|
-
ctx: CanvasRenderingContext2D;
|
|
351
|
-
path: Path2D;
|
|
352
|
-
fontSize: number;
|
|
353
|
-
clipRect?: BoundingBox;
|
|
354
|
-
}
|
|
355
|
-
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
356
|
-
|
|
357
|
-
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
358
|
-
|
|
359
264
|
declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text$1): void;
|
|
360
265
|
|
|
361
266
|
declare function definePlugin(options: TextPlugin): TextPlugin;
|
|
@@ -375,13 +280,13 @@ declare function renderText(options: RenderTextOptions & {
|
|
|
375
280
|
load?: false;
|
|
376
281
|
}): void;
|
|
377
282
|
|
|
378
|
-
declare function getHighlightStyle(style:
|
|
283
|
+
declare function getHighlightStyle(style: ITextStyle): Highlight;
|
|
379
284
|
declare function highlight(): TextPlugin;
|
|
380
285
|
|
|
381
286
|
declare function listStyle(): TextPlugin;
|
|
382
287
|
|
|
383
288
|
declare function render(): TextPlugin;
|
|
384
|
-
declare function getTransform2D(text: Text$1, style: Partial<
|
|
289
|
+
declare function getTransform2D(text: Text$1, style: Partial<ITextStyle>): Matrix3;
|
|
385
290
|
|
|
386
291
|
declare function textDecoration(): TextPlugin;
|
|
387
292
|
|
|
@@ -398,4 +303,4 @@ declare function hexToRgb(hex: string): string | null;
|
|
|
398
303
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
399
304
|
declare function needsFetch(source: string): boolean;
|
|
400
305
|
|
|
401
|
-
export { Character, type DrawShapePathsOptions,
|
|
306
|
+
export { Character, type DrawShapePathsOptions, Fragment, type LinearGradient, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type RenderTextOptions, Text$1 as Text, type TextEventMap, type TextOptions, type TextPlugin, type TextRenderOptions, defaultTextStyles, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, uploadColor, uploadColors };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
|
+
import { ITextStyle, ITextContent, Highlight } from 'modern-idoc';
|
|
1
2
|
import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
2
3
|
import { Fonts, Sfnt } from 'modern-font';
|
|
3
4
|
|
|
5
|
+
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
6
|
+
declare function uploadColor(style: Partial<ITextStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
7
|
+
interface LinearGradient {
|
|
8
|
+
x0: number;
|
|
9
|
+
y0: number;
|
|
10
|
+
x1: number;
|
|
11
|
+
y1: number;
|
|
12
|
+
stops: {
|
|
13
|
+
offset: number;
|
|
14
|
+
color: string;
|
|
15
|
+
}[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface DrawShapePathsOptions extends Partial<ITextStyle> {
|
|
19
|
+
ctx: CanvasRenderingContext2D;
|
|
20
|
+
path: Path2D;
|
|
21
|
+
fontSize: number;
|
|
22
|
+
clipRect?: BoundingBox;
|
|
23
|
+
}
|
|
24
|
+
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
25
|
+
|
|
26
|
+
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
27
|
+
|
|
4
28
|
declare class Fragment {
|
|
5
29
|
content: string;
|
|
6
|
-
style: Partial<
|
|
30
|
+
style: Partial<ITextStyle>;
|
|
7
31
|
parent: Paragraph;
|
|
8
32
|
inlineBox: BoundingBox;
|
|
9
33
|
characters: Character[];
|
|
10
|
-
computedStyle:
|
|
34
|
+
computedStyle: ITextStyle;
|
|
11
35
|
get computedContent(): string;
|
|
12
|
-
constructor(content: string, style: Partial<
|
|
36
|
+
constructor(content: string, style: Partial<ITextStyle> | undefined, parent: Paragraph);
|
|
13
37
|
updateComputedStyle(): this;
|
|
14
38
|
initCharacters(): this;
|
|
15
39
|
}
|
|
@@ -41,7 +65,7 @@ declare class Character {
|
|
|
41
65
|
centerDiviation: number;
|
|
42
66
|
fontStyle?: 'bold' | 'italic';
|
|
43
67
|
get center(): Vector2 | undefined;
|
|
44
|
-
get computedStyle():
|
|
68
|
+
get computedStyle(): ITextStyle;
|
|
45
69
|
get isVertical(): boolean;
|
|
46
70
|
get fontSize(): number;
|
|
47
71
|
get fontHeight(): number;
|
|
@@ -55,18 +79,37 @@ declare class Character {
|
|
|
55
79
|
max: Vector2;
|
|
56
80
|
} | undefined;
|
|
57
81
|
getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
|
|
58
|
-
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<
|
|
82
|
+
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<ITextStyle>): void;
|
|
59
83
|
}
|
|
60
84
|
|
|
61
85
|
declare class Paragraph {
|
|
62
|
-
style: Partial<
|
|
63
|
-
parentStyle:
|
|
86
|
+
style: Partial<ITextStyle>;
|
|
87
|
+
parentStyle: ITextStyle;
|
|
64
88
|
lineBox: BoundingBox;
|
|
65
89
|
fragments: Fragment[];
|
|
66
|
-
computedStyle:
|
|
67
|
-
constructor(style: Partial<
|
|
90
|
+
computedStyle: ITextStyle;
|
|
91
|
+
constructor(style: Partial<ITextStyle>, parentStyle: ITextStyle);
|
|
68
92
|
updateComputedStyle(): this;
|
|
69
|
-
addFragment(content: string, style?: Partial<
|
|
93
|
+
addFragment(content: string, style?: Partial<ITextStyle>): Fragment;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface TextPlugin {
|
|
97
|
+
name: string;
|
|
98
|
+
paths?: Path2D[];
|
|
99
|
+
getBoundingBox?: (text: Text$1) => BoundingBox | undefined;
|
|
100
|
+
update?: (text: Text$1) => void;
|
|
101
|
+
updateOrder?: number;
|
|
102
|
+
render?: (ctx: CanvasRenderingContext2D, text: Text$1) => void;
|
|
103
|
+
renderOrder?: number;
|
|
104
|
+
load?: (text: Text$1) => Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
interface TextOptions {
|
|
107
|
+
debug?: boolean;
|
|
108
|
+
content?: ITextContent;
|
|
109
|
+
style?: Partial<ITextStyle>;
|
|
110
|
+
measureDom?: HTMLElement;
|
|
111
|
+
effects?: Partial<ITextStyle>[];
|
|
112
|
+
fonts?: Fonts;
|
|
70
113
|
}
|
|
71
114
|
|
|
72
115
|
type EventListenerValue<T = any> = (ev: T) => void;
|
|
@@ -133,7 +176,7 @@ declare class Measurer {
|
|
|
133
176
|
* </ul>
|
|
134
177
|
* </section>
|
|
135
178
|
*/
|
|
136
|
-
createParagraphDom(paragraphs: Paragraph[], rootStyle:
|
|
179
|
+
createParagraphDom(paragraphs: Paragraph[], rootStyle: ITextStyle): {
|
|
137
180
|
dom: HTMLElement;
|
|
138
181
|
destory: () => void;
|
|
139
182
|
};
|
|
@@ -150,7 +193,7 @@ declare class Measurer {
|
|
|
150
193
|
characters: MeasuredCharacter[];
|
|
151
194
|
};
|
|
152
195
|
measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
|
|
153
|
-
measure(paragraphs: Paragraph[], rootStyle:
|
|
196
|
+
measure(paragraphs: Paragraph[], rootStyle: ITextStyle, dom?: HTMLElement): MeasureDomResult;
|
|
154
197
|
}
|
|
155
198
|
|
|
156
199
|
interface TextRenderOptions {
|
|
@@ -165,7 +208,7 @@ interface MeasureResult {
|
|
|
165
208
|
pathBox: BoundingBox;
|
|
166
209
|
boundingBox: BoundingBox;
|
|
167
210
|
}
|
|
168
|
-
declare const defaultTextStyles:
|
|
211
|
+
declare const defaultTextStyles: ITextStyle;
|
|
169
212
|
interface TextEventMap {
|
|
170
213
|
update: {
|
|
171
214
|
text: Text$1;
|
|
@@ -182,12 +225,12 @@ interface TextEventMap {
|
|
|
182
225
|
}
|
|
183
226
|
declare class Text$1 extends EventEmitter<TextEventMap> {
|
|
184
227
|
debug: boolean;
|
|
185
|
-
content:
|
|
186
|
-
style: Partial<
|
|
187
|
-
effects?: Partial<
|
|
228
|
+
content: ITextContent;
|
|
229
|
+
style: Partial<ITextStyle>;
|
|
230
|
+
effects?: Partial<ITextStyle>[];
|
|
188
231
|
measureDom?: HTMLElement;
|
|
189
232
|
needsUpdate: boolean;
|
|
190
|
-
computedStyle:
|
|
233
|
+
computedStyle: ITextStyle;
|
|
191
234
|
paragraphs: Paragraph[];
|
|
192
235
|
lineBox: BoundingBox;
|
|
193
236
|
rawGlyphBox: BoundingBox;
|
|
@@ -218,144 +261,6 @@ declare class Text$1 extends EventEmitter<TextEventMap> {
|
|
|
218
261
|
render(options: TextRenderOptions): void;
|
|
219
262
|
}
|
|
220
263
|
|
|
221
|
-
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
222
|
-
type WritingMode = 'horizontal-tb' | 'vertical-lr' | 'vertical-rl';
|
|
223
|
-
type TextOrientation = 'mixed' | 'upright' | 'sideways-right' | 'sideways';
|
|
224
|
-
type FontWeight = 'normal' | 'bold' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
225
|
-
type FontStyle = 'normal' | 'italic' | 'oblique' | `oblique ${string}`;
|
|
226
|
-
type FontKerning = 'none' | 'auto' | 'normal';
|
|
227
|
-
type TextWrap = 'wrap' | 'nowrap';
|
|
228
|
-
type TextAlign = 'center' | 'end' | 'left' | 'right' | 'start';
|
|
229
|
-
type VerticalAlign = 'baseline' | 'top' | 'middle' | 'bottom' | 'sub' | 'super' | 'text-top' | 'text-bottom';
|
|
230
|
-
type TextTransform = 'none' | 'uppercase' | 'lowercase';
|
|
231
|
-
type TextDecorationLine = 'none' | 'underline' | 'line-through' | 'overline';
|
|
232
|
-
type ListStyleType = 'none' | 'disc';
|
|
233
|
-
type ListStyleImage = 'none' | string;
|
|
234
|
-
type ListStyleColormap = 'none' | Record<string, string>;
|
|
235
|
-
type ListStyleSize = 'cover' | Sizeable;
|
|
236
|
-
type ListStylePosition = 'inside' | 'outside';
|
|
237
|
-
type HighlightLine = TextDecorationLine | 'outline';
|
|
238
|
-
type HighlightImage = 'none' | string;
|
|
239
|
-
type HighlightReferImage = 'none' | string;
|
|
240
|
-
type HighlightColormap = 'none' | Record<string, string>;
|
|
241
|
-
type HighlightSize = 'cover' | Sizeable;
|
|
242
|
-
type HighlightThickness = Sizeable;
|
|
243
|
-
interface TextLineStyle {
|
|
244
|
-
writingMode: WritingMode;
|
|
245
|
-
textWrap: TextWrap;
|
|
246
|
-
textAlign: TextAlign;
|
|
247
|
-
textIndent: number;
|
|
248
|
-
lineHeight: number;
|
|
249
|
-
listStyleType: ListStyleType;
|
|
250
|
-
listStyleImage: ListStyleImage;
|
|
251
|
-
listStyleColormap: ListStyleColormap;
|
|
252
|
-
listStyleSize: ListStyleSize;
|
|
253
|
-
listStylePosition: ListStylePosition;
|
|
254
|
-
}
|
|
255
|
-
interface HighlightStyle {
|
|
256
|
-
image: HighlightImage;
|
|
257
|
-
referImage: HighlightReferImage;
|
|
258
|
-
colormap: HighlightColormap;
|
|
259
|
-
line: HighlightLine;
|
|
260
|
-
size: HighlightSize;
|
|
261
|
-
thickness: HighlightThickness;
|
|
262
|
-
}
|
|
263
|
-
interface TextHighlightStyle {
|
|
264
|
-
highlight?: Partial<HighlightStyle>;
|
|
265
|
-
highlightImage?: HighlightImage;
|
|
266
|
-
highlightReferImage?: HighlightReferImage;
|
|
267
|
-
highlightColormap?: HighlightColormap;
|
|
268
|
-
highlightLine?: HighlightLine;
|
|
269
|
-
highlightSize?: HighlightSize;
|
|
270
|
-
highlightThickness?: HighlightThickness;
|
|
271
|
-
}
|
|
272
|
-
interface TextInlineStyle extends TextHighlightStyle {
|
|
273
|
-
verticalAlign: VerticalAlign;
|
|
274
|
-
letterSpacing: number;
|
|
275
|
-
fontSize: number;
|
|
276
|
-
fontWeight: FontWeight;
|
|
277
|
-
fontFamily: string;
|
|
278
|
-
fontStyle: FontStyle;
|
|
279
|
-
fontKerning?: FontKerning;
|
|
280
|
-
textTransform: TextTransform;
|
|
281
|
-
textOrientation: TextOrientation;
|
|
282
|
-
textDecoration: TextDecorationLine;
|
|
283
|
-
}
|
|
284
|
-
interface TextDrawStyle {
|
|
285
|
-
color: string | CanvasGradient | CanvasPattern;
|
|
286
|
-
backgroundColor: string | CanvasGradient | CanvasPattern;
|
|
287
|
-
textStrokeWidth: number;
|
|
288
|
-
textStrokeColor: string | CanvasGradient | CanvasPattern;
|
|
289
|
-
shadowColor: string;
|
|
290
|
-
shadowOffsetX: number;
|
|
291
|
-
shadowOffsetY: number;
|
|
292
|
-
shadowBlur: number;
|
|
293
|
-
translateX: number;
|
|
294
|
-
translateY: number;
|
|
295
|
-
skewX: number;
|
|
296
|
-
skewY: number;
|
|
297
|
-
}
|
|
298
|
-
interface TextStyle extends TextLineStyle, TextInlineStyle, TextDrawStyle {
|
|
299
|
-
marginLeft?: number;
|
|
300
|
-
marginTop?: number;
|
|
301
|
-
marginRight?: number;
|
|
302
|
-
marginBottom?: number;
|
|
303
|
-
paddingLeft?: number;
|
|
304
|
-
paddingTop?: number;
|
|
305
|
-
paddingRight?: number;
|
|
306
|
-
paddingBottom?: number;
|
|
307
|
-
width?: number;
|
|
308
|
-
height?: number;
|
|
309
|
-
}
|
|
310
|
-
interface FragmentContent extends Partial<TextStyle> {
|
|
311
|
-
content: string;
|
|
312
|
-
}
|
|
313
|
-
interface ParagraphContent extends Partial<TextStyle> {
|
|
314
|
-
fragments: FragmentContent[];
|
|
315
|
-
}
|
|
316
|
-
type TextContent = string | FragmentContent | ParagraphContent | (string | FragmentContent | ParagraphContent | (string | FragmentContent)[])[];
|
|
317
|
-
interface TextPlugin {
|
|
318
|
-
name: string;
|
|
319
|
-
paths?: Path2D[];
|
|
320
|
-
getBoundingBox?: (text: Text$1) => BoundingBox | undefined;
|
|
321
|
-
update?: (text: Text$1) => void;
|
|
322
|
-
updateOrder?: number;
|
|
323
|
-
render?: (ctx: CanvasRenderingContext2D, text: Text$1) => void;
|
|
324
|
-
renderOrder?: number;
|
|
325
|
-
load?: (text: Text$1) => Promise<void>;
|
|
326
|
-
}
|
|
327
|
-
interface TextOptions {
|
|
328
|
-
debug?: boolean;
|
|
329
|
-
content?: TextContent;
|
|
330
|
-
style?: Partial<TextStyle>;
|
|
331
|
-
measureDom?: HTMLElement;
|
|
332
|
-
effects?: Partial<TextStyle>[];
|
|
333
|
-
fonts?: Fonts;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
337
|
-
declare function uploadColor(style: Partial<TextStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
338
|
-
interface LinearGradient {
|
|
339
|
-
x0: number;
|
|
340
|
-
y0: number;
|
|
341
|
-
x1: number;
|
|
342
|
-
y1: number;
|
|
343
|
-
stops: {
|
|
344
|
-
offset: number;
|
|
345
|
-
color: string;
|
|
346
|
-
}[];
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
interface DrawShapePathsOptions extends Partial<TextStyle> {
|
|
350
|
-
ctx: CanvasRenderingContext2D;
|
|
351
|
-
path: Path2D;
|
|
352
|
-
fontSize: number;
|
|
353
|
-
clipRect?: BoundingBox;
|
|
354
|
-
}
|
|
355
|
-
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
356
|
-
|
|
357
|
-
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
358
|
-
|
|
359
264
|
declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text$1): void;
|
|
360
265
|
|
|
361
266
|
declare function definePlugin(options: TextPlugin): TextPlugin;
|
|
@@ -375,13 +280,13 @@ declare function renderText(options: RenderTextOptions & {
|
|
|
375
280
|
load?: false;
|
|
376
281
|
}): void;
|
|
377
282
|
|
|
378
|
-
declare function getHighlightStyle(style:
|
|
283
|
+
declare function getHighlightStyle(style: ITextStyle): Highlight;
|
|
379
284
|
declare function highlight(): TextPlugin;
|
|
380
285
|
|
|
381
286
|
declare function listStyle(): TextPlugin;
|
|
382
287
|
|
|
383
288
|
declare function render(): TextPlugin;
|
|
384
|
-
declare function getTransform2D(text: Text$1, style: Partial<
|
|
289
|
+
declare function getTransform2D(text: Text$1, style: Partial<ITextStyle>): Matrix3;
|
|
385
290
|
|
|
386
291
|
declare function textDecoration(): TextPlugin;
|
|
387
292
|
|
|
@@ -398,4 +303,4 @@ declare function hexToRgb(hex: string): string | null;
|
|
|
398
303
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
399
304
|
declare function needsFetch(source: string): boolean;
|
|
400
305
|
|
|
401
|
-
export { Character, type DrawShapePathsOptions,
|
|
306
|
+
export { Character, type DrawShapePathsOptions, Fragment, type LinearGradient, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type RenderTextOptions, Text$1 as Text, type TextEventMap, type TextOptions, type TextPlugin, type TextRenderOptions, defaultTextStyles, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, uploadColor, uploadColors };
|