modern-text 0.5.13 → 0.6.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 +198 -104
- package/dist/index.d.cts +29 -22
- package/dist/index.d.mts +29 -22
- package/dist/index.d.ts +29 -22
- package/dist/index.js +4 -4
- package/dist/index.mjs +198 -105
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -121,8 +121,6 @@ interface MeasureDomResult {
|
|
|
121
121
|
boundingBox: BoundingBox;
|
|
122
122
|
}
|
|
123
123
|
declare class Measurer {
|
|
124
|
-
protected _text: Text;
|
|
125
|
-
constructor(_text: Text);
|
|
126
124
|
protected _styleToDomStyle(style: Partial<TextStyle>): Record<string, any>;
|
|
127
125
|
/**
|
|
128
126
|
* <section style="...">
|
|
@@ -134,17 +132,24 @@ declare class Measurer {
|
|
|
134
132
|
* </ul>
|
|
135
133
|
* </section>
|
|
136
134
|
*/
|
|
137
|
-
|
|
135
|
+
createParagraphDom(paragraphs: Paragraph[], rootStyle: TextStyle): {
|
|
138
136
|
dom: HTMLElement;
|
|
139
137
|
destory: () => void;
|
|
140
138
|
};
|
|
141
|
-
|
|
139
|
+
measureDomText(text: Text): {
|
|
140
|
+
content: string;
|
|
141
|
+
top: number;
|
|
142
|
+
left: number;
|
|
143
|
+
width: number;
|
|
144
|
+
height: number;
|
|
145
|
+
}[];
|
|
146
|
+
measureDom(dom: HTMLElement): {
|
|
142
147
|
paragraphs: MeasuredParagraph[];
|
|
143
148
|
fragments: MeasuredFragment[];
|
|
144
149
|
characters: MeasuredCharacter[];
|
|
145
150
|
};
|
|
146
|
-
|
|
147
|
-
measure(dom?: HTMLElement): MeasureDomResult;
|
|
151
|
+
measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
|
|
152
|
+
measure(paragraphs: Paragraph[], rootStyle: TextStyle, dom?: HTMLElement): MeasureDomResult;
|
|
148
153
|
}
|
|
149
154
|
|
|
150
155
|
interface TextRenderOptions {
|
|
@@ -162,19 +167,19 @@ interface MeasureResult {
|
|
|
162
167
|
declare const defaultTextStyles: TextStyle;
|
|
163
168
|
interface TextEventMap {
|
|
164
169
|
update: {
|
|
165
|
-
text: Text;
|
|
170
|
+
text: Text$1;
|
|
166
171
|
};
|
|
167
172
|
measure: {
|
|
168
|
-
text: Text;
|
|
173
|
+
text: Text$1;
|
|
169
174
|
result: MeasureResult;
|
|
170
175
|
};
|
|
171
176
|
render: {
|
|
172
|
-
text: Text;
|
|
177
|
+
text: Text$1;
|
|
173
178
|
view: HTMLCanvasElement;
|
|
174
179
|
pixelRatio: number;
|
|
175
180
|
};
|
|
176
181
|
}
|
|
177
|
-
declare class Text extends EventEmitter<TextEventMap> {
|
|
182
|
+
declare class Text$1 extends EventEmitter<TextEventMap> {
|
|
178
183
|
debug: boolean;
|
|
179
184
|
content: TextContent;
|
|
180
185
|
style: Partial<TextStyle>;
|
|
@@ -201,14 +206,15 @@ declare class Text extends EventEmitter<TextEventMap> {
|
|
|
201
206
|
fragmentIndex: number;
|
|
202
207
|
characterIndex: number;
|
|
203
208
|
}) => void): this;
|
|
209
|
+
load(): Promise<void>;
|
|
204
210
|
updateParagraphs(): this;
|
|
205
|
-
measure(dom?: HTMLElement | undefined):
|
|
211
|
+
measure(dom?: HTMLElement | undefined): MeasureResult;
|
|
206
212
|
getGlyphBox(): BoundingBox;
|
|
207
213
|
updatePathBox(): this;
|
|
208
214
|
updateBoundingBox(): this;
|
|
209
215
|
requestUpdate(): this;
|
|
210
|
-
update():
|
|
211
|
-
render(options: TextRenderOptions):
|
|
216
|
+
update(): this;
|
|
217
|
+
render(options: TextRenderOptions): void;
|
|
212
218
|
}
|
|
213
219
|
|
|
214
220
|
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
@@ -286,15 +292,15 @@ interface ParagraphContent extends Partial<TextStyle> {
|
|
|
286
292
|
fragments: FragmentContent[];
|
|
287
293
|
}
|
|
288
294
|
type TextContent = string | FragmentContent | ParagraphContent | (string | FragmentContent | ParagraphContent | (string | FragmentContent)[])[];
|
|
289
|
-
type PromiseLike<T> = T | Promise<T>;
|
|
290
295
|
interface TextPlugin {
|
|
291
296
|
name: string;
|
|
292
297
|
paths?: Path2D[];
|
|
293
|
-
getBoundingBox?: (text: Text) => BoundingBox | undefined;
|
|
298
|
+
getBoundingBox?: (text: Text$1) => BoundingBox | undefined;
|
|
299
|
+
update?: (text: Text$1) => void;
|
|
294
300
|
updateOrder?: number;
|
|
295
|
-
|
|
301
|
+
render?: (ctx: CanvasRenderingContext2D, text: Text$1) => void;
|
|
296
302
|
renderOrder?: number;
|
|
297
|
-
|
|
303
|
+
load?: (text: Text$1) => Promise<void>;
|
|
298
304
|
}
|
|
299
305
|
interface TextOptions {
|
|
300
306
|
debug?: boolean;
|
|
@@ -328,23 +334,23 @@ declare function drawPath(options: DrawShapePathsOptions): void;
|
|
|
328
334
|
|
|
329
335
|
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
330
336
|
|
|
331
|
-
declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text): void;
|
|
337
|
+
declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text$1): void;
|
|
332
338
|
|
|
333
339
|
declare function definePlugin(options: TextPlugin): TextPlugin;
|
|
334
340
|
|
|
335
341
|
declare function measureText(options: TextOptions): Promise<MeasureResult>;
|
|
336
342
|
|
|
343
|
+
declare function renderText(options: TextOptions & TextRenderOptions): Promise<void>;
|
|
344
|
+
|
|
337
345
|
declare function highlight(): TextPlugin;
|
|
338
346
|
|
|
339
347
|
declare function listStyle(): TextPlugin;
|
|
340
348
|
|
|
341
349
|
declare function render(): TextPlugin;
|
|
342
|
-
declare function getTransform2D(text: Text, style: Partial<TextStyle>): Matrix3;
|
|
350
|
+
declare function getTransform2D(text: Text$1, style: Partial<TextStyle>): Matrix3;
|
|
343
351
|
|
|
344
352
|
declare function textDecoration(): TextPlugin;
|
|
345
353
|
|
|
346
|
-
declare function renderText(options: TextOptions & TextRenderOptions): Promise<void>;
|
|
347
|
-
|
|
348
354
|
interface ValueContext {
|
|
349
355
|
total: number;
|
|
350
356
|
fontSize: number;
|
|
@@ -356,5 +362,6 @@ declare function isEqualObject(obj1: Record<string, any>, obj2: Record<string, a
|
|
|
356
362
|
declare function isEqualValue(val1: any, val2: any): boolean;
|
|
357
363
|
declare function hexToRgb(hex: string): string | null;
|
|
358
364
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
365
|
+
declare function needsFetch(source: string): boolean;
|
|
359
366
|
|
|
360
|
-
export { Character, type DrawShapePathsOptions, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type HighlightColormap, type HighlightImage, type HighlightLine, type HighlightReferImage, type HighlightSize, type HighlightThickness, type LinearGradient, type ListStyleColormap, 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 TextDecorationLine, type TextDrawStyle, type TextEventMap, 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, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, uploadColor, uploadColors };
|
|
367
|
+
export { Character, type DrawShapePathsOptions, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type HighlightColormap, type HighlightImage, type HighlightLine, type HighlightReferImage, type HighlightSize, type HighlightThickness, type LinearGradient, type ListStyleColormap, 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$1 as Text, type TextAlign, type TextContent, type TextDecorationLine, type TextDrawStyle, type TextEventMap, 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, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, uploadColor, uploadColors };
|
package/dist/index.d.ts
CHANGED
|
@@ -121,8 +121,6 @@ interface MeasureDomResult {
|
|
|
121
121
|
boundingBox: BoundingBox;
|
|
122
122
|
}
|
|
123
123
|
declare class Measurer {
|
|
124
|
-
protected _text: Text;
|
|
125
|
-
constructor(_text: Text);
|
|
126
124
|
protected _styleToDomStyle(style: Partial<TextStyle>): Record<string, any>;
|
|
127
125
|
/**
|
|
128
126
|
* <section style="...">
|
|
@@ -134,17 +132,24 @@ declare class Measurer {
|
|
|
134
132
|
* </ul>
|
|
135
133
|
* </section>
|
|
136
134
|
*/
|
|
137
|
-
|
|
135
|
+
createParagraphDom(paragraphs: Paragraph[], rootStyle: TextStyle): {
|
|
138
136
|
dom: HTMLElement;
|
|
139
137
|
destory: () => void;
|
|
140
138
|
};
|
|
141
|
-
|
|
139
|
+
measureDomText(text: Text): {
|
|
140
|
+
content: string;
|
|
141
|
+
top: number;
|
|
142
|
+
left: number;
|
|
143
|
+
width: number;
|
|
144
|
+
height: number;
|
|
145
|
+
}[];
|
|
146
|
+
measureDom(dom: HTMLElement): {
|
|
142
147
|
paragraphs: MeasuredParagraph[];
|
|
143
148
|
fragments: MeasuredFragment[];
|
|
144
149
|
characters: MeasuredCharacter[];
|
|
145
150
|
};
|
|
146
|
-
|
|
147
|
-
measure(dom?: HTMLElement): MeasureDomResult;
|
|
151
|
+
measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
|
|
152
|
+
measure(paragraphs: Paragraph[], rootStyle: TextStyle, dom?: HTMLElement): MeasureDomResult;
|
|
148
153
|
}
|
|
149
154
|
|
|
150
155
|
interface TextRenderOptions {
|
|
@@ -162,19 +167,19 @@ interface MeasureResult {
|
|
|
162
167
|
declare const defaultTextStyles: TextStyle;
|
|
163
168
|
interface TextEventMap {
|
|
164
169
|
update: {
|
|
165
|
-
text: Text;
|
|
170
|
+
text: Text$1;
|
|
166
171
|
};
|
|
167
172
|
measure: {
|
|
168
|
-
text: Text;
|
|
173
|
+
text: Text$1;
|
|
169
174
|
result: MeasureResult;
|
|
170
175
|
};
|
|
171
176
|
render: {
|
|
172
|
-
text: Text;
|
|
177
|
+
text: Text$1;
|
|
173
178
|
view: HTMLCanvasElement;
|
|
174
179
|
pixelRatio: number;
|
|
175
180
|
};
|
|
176
181
|
}
|
|
177
|
-
declare class Text extends EventEmitter<TextEventMap> {
|
|
182
|
+
declare class Text$1 extends EventEmitter<TextEventMap> {
|
|
178
183
|
debug: boolean;
|
|
179
184
|
content: TextContent;
|
|
180
185
|
style: Partial<TextStyle>;
|
|
@@ -201,14 +206,15 @@ declare class Text extends EventEmitter<TextEventMap> {
|
|
|
201
206
|
fragmentIndex: number;
|
|
202
207
|
characterIndex: number;
|
|
203
208
|
}) => void): this;
|
|
209
|
+
load(): Promise<void>;
|
|
204
210
|
updateParagraphs(): this;
|
|
205
|
-
measure(dom?: HTMLElement | undefined):
|
|
211
|
+
measure(dom?: HTMLElement | undefined): MeasureResult;
|
|
206
212
|
getGlyphBox(): BoundingBox;
|
|
207
213
|
updatePathBox(): this;
|
|
208
214
|
updateBoundingBox(): this;
|
|
209
215
|
requestUpdate(): this;
|
|
210
|
-
update():
|
|
211
|
-
render(options: TextRenderOptions):
|
|
216
|
+
update(): this;
|
|
217
|
+
render(options: TextRenderOptions): void;
|
|
212
218
|
}
|
|
213
219
|
|
|
214
220
|
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
@@ -286,15 +292,15 @@ interface ParagraphContent extends Partial<TextStyle> {
|
|
|
286
292
|
fragments: FragmentContent[];
|
|
287
293
|
}
|
|
288
294
|
type TextContent = string | FragmentContent | ParagraphContent | (string | FragmentContent | ParagraphContent | (string | FragmentContent)[])[];
|
|
289
|
-
type PromiseLike<T> = T | Promise<T>;
|
|
290
295
|
interface TextPlugin {
|
|
291
296
|
name: string;
|
|
292
297
|
paths?: Path2D[];
|
|
293
|
-
getBoundingBox?: (text: Text) => BoundingBox | undefined;
|
|
298
|
+
getBoundingBox?: (text: Text$1) => BoundingBox | undefined;
|
|
299
|
+
update?: (text: Text$1) => void;
|
|
294
300
|
updateOrder?: number;
|
|
295
|
-
|
|
301
|
+
render?: (ctx: CanvasRenderingContext2D, text: Text$1) => void;
|
|
296
302
|
renderOrder?: number;
|
|
297
|
-
|
|
303
|
+
load?: (text: Text$1) => Promise<void>;
|
|
298
304
|
}
|
|
299
305
|
interface TextOptions {
|
|
300
306
|
debug?: boolean;
|
|
@@ -328,23 +334,23 @@ declare function drawPath(options: DrawShapePathsOptions): void;
|
|
|
328
334
|
|
|
329
335
|
declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void;
|
|
330
336
|
|
|
331
|
-
declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text): void;
|
|
337
|
+
declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text$1): void;
|
|
332
338
|
|
|
333
339
|
declare function definePlugin(options: TextPlugin): TextPlugin;
|
|
334
340
|
|
|
335
341
|
declare function measureText(options: TextOptions): Promise<MeasureResult>;
|
|
336
342
|
|
|
343
|
+
declare function renderText(options: TextOptions & TextRenderOptions): Promise<void>;
|
|
344
|
+
|
|
337
345
|
declare function highlight(): TextPlugin;
|
|
338
346
|
|
|
339
347
|
declare function listStyle(): TextPlugin;
|
|
340
348
|
|
|
341
349
|
declare function render(): TextPlugin;
|
|
342
|
-
declare function getTransform2D(text: Text, style: Partial<TextStyle>): Matrix3;
|
|
350
|
+
declare function getTransform2D(text: Text$1, style: Partial<TextStyle>): Matrix3;
|
|
343
351
|
|
|
344
352
|
declare function textDecoration(): TextPlugin;
|
|
345
353
|
|
|
346
|
-
declare function renderText(options: TextOptions & TextRenderOptions): Promise<void>;
|
|
347
|
-
|
|
348
354
|
interface ValueContext {
|
|
349
355
|
total: number;
|
|
350
356
|
fontSize: number;
|
|
@@ -356,5 +362,6 @@ declare function isEqualObject(obj1: Record<string, any>, obj2: Record<string, a
|
|
|
356
362
|
declare function isEqualValue(val1: any, val2: any): boolean;
|
|
357
363
|
declare function hexToRgb(hex: string): string | null;
|
|
358
364
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
365
|
+
declare function needsFetch(source: string): boolean;
|
|
359
366
|
|
|
360
|
-
export { Character, type DrawShapePathsOptions, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type HighlightColormap, type HighlightImage, type HighlightLine, type HighlightReferImage, type HighlightSize, type HighlightThickness, type LinearGradient, type ListStyleColormap, 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 TextDecorationLine, type TextDrawStyle, type TextEventMap, 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, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, uploadColor, uploadColors };
|
|
367
|
+
export { Character, type DrawShapePathsOptions, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type HighlightColormap, type HighlightImage, type HighlightLine, type HighlightReferImage, type HighlightSize, type HighlightThickness, type LinearGradient, type ListStyleColormap, 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$1 as Text, type TextAlign, type TextContent, type TextDecorationLine, type TextDrawStyle, type TextEventMap, 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, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, uploadColor, uploadColors };
|