modern-text 1.2.3 → 1.3.0
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 +35 -19
- package/dist/index.d.cts +31 -27
- package/dist/index.d.mts +31 -27
- package/dist/index.d.ts +31 -27
- package/dist/index.js +5 -5
- package/dist/index.mjs +35 -21
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -255,7 +255,7 @@ class Character {
|
|
|
255
255
|
if (Math.abs(advanceWidth - advanceHeight) > 0.1) {
|
|
256
256
|
y -= (ascender - typoAscender) / (ascender + Math.abs(descender)) * advanceHeight;
|
|
257
257
|
}
|
|
258
|
-
glyphIndex =
|
|
258
|
+
glyphIndex = void 0;
|
|
259
259
|
}
|
|
260
260
|
if (isVertical && !set1.has(content) && (content.codePointAt(0) <= 256 || set2.has(content))) {
|
|
261
261
|
path.addCommands(
|
|
@@ -276,12 +276,12 @@ class Character {
|
|
|
276
276
|
isVertical ? {
|
|
277
277
|
x: point.x,
|
|
278
278
|
y: top - (advanceHeight - advanceWidth) / 2 + baseline
|
|
279
|
-
} :
|
|
279
|
+
} : void 0
|
|
280
280
|
);
|
|
281
281
|
}
|
|
282
282
|
path.rotate(90, point);
|
|
283
283
|
} else {
|
|
284
|
-
if (glyphIndex !==
|
|
284
|
+
if (glyphIndex !== void 0) {
|
|
285
285
|
path.addCommands(
|
|
286
286
|
sfnt.glyphs.get(glyphIndex).getPathCommands(x, y, style.fontSize)
|
|
287
287
|
);
|
|
@@ -291,7 +291,7 @@ class Character {
|
|
|
291
291
|
isVertical ? {
|
|
292
292
|
x: x + advanceWidth / 2,
|
|
293
293
|
y: top + typoAscender / (ascender + Math.abs(descender)) * advanceHeight
|
|
294
|
-
} :
|
|
294
|
+
} : void 0
|
|
295
295
|
);
|
|
296
296
|
}
|
|
297
297
|
} else {
|
|
@@ -299,7 +299,7 @@ class Character {
|
|
|
299
299
|
if (needsItalic) {
|
|
300
300
|
this._italic(
|
|
301
301
|
path,
|
|
302
|
-
isVertical ? { x: x + advanceHeight / 2, y } :
|
|
302
|
+
isVertical ? { x: x + advanceHeight / 2, y } : void 0
|
|
303
303
|
);
|
|
304
304
|
}
|
|
305
305
|
}
|
|
@@ -327,13 +327,13 @@ class Character {
|
|
|
327
327
|
if (this.path.curves[0]?.curves.length) {
|
|
328
328
|
return this.path.getMinMax(min, max, withStyle);
|
|
329
329
|
} else {
|
|
330
|
-
return
|
|
330
|
+
return void 0;
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
getGlyphBoundingBox(withStyle) {
|
|
334
|
-
const minMax = this.getGlyphMinMax(
|
|
334
|
+
const minMax = this.getGlyphMinMax(void 0, void 0, withStyle);
|
|
335
335
|
if (!minMax) {
|
|
336
|
-
return
|
|
336
|
+
return void 0;
|
|
337
337
|
}
|
|
338
338
|
const { min, max } = minMax;
|
|
339
339
|
return new modernPath2d.BoundingBox(min.x, min.y, max.x - min.x, max.y - min.y);
|
|
@@ -447,7 +447,7 @@ function filterEmpty(val) {
|
|
|
447
447
|
return val;
|
|
448
448
|
const res = {};
|
|
449
449
|
for (const key in val) {
|
|
450
|
-
if (val[key] !== "" && val[key] !==
|
|
450
|
+
if (val[key] !== "" && val[key] !== void 0) {
|
|
451
451
|
res[key] = val[key];
|
|
452
452
|
}
|
|
453
453
|
}
|
|
@@ -591,7 +591,7 @@ class Measurer {
|
|
|
591
591
|
const isFlex = Boolean(style.justifyContent || style.alignItems);
|
|
592
592
|
Object.assign(dom.style, {
|
|
593
593
|
boxSizing: "border-box",
|
|
594
|
-
display: isFlex ? "inline-flex" :
|
|
594
|
+
display: isFlex ? "inline-flex" : void 0,
|
|
595
595
|
width: "max-content",
|
|
596
596
|
height: "max-content",
|
|
597
597
|
whiteSpace: "pre-wrap",
|
|
@@ -606,8 +606,8 @@ class Measurer {
|
|
|
606
606
|
listStyleType: "inherit",
|
|
607
607
|
padding: "0",
|
|
608
608
|
margin: "0",
|
|
609
|
-
width: isFlex && isHorizontal ? "100%" :
|
|
610
|
-
height: isFlex && !isHorizontal ? "100%" :
|
|
609
|
+
width: isFlex && isHorizontal ? "100%" : void 0,
|
|
610
|
+
height: isFlex && !isHorizontal ? "100%" : void 0
|
|
611
611
|
});
|
|
612
612
|
paragraphs.forEach((paragraph) => {
|
|
613
613
|
const li = document.createElement("li");
|
|
@@ -660,7 +660,7 @@ class Measurer {
|
|
|
660
660
|
width: rect.width
|
|
661
661
|
};
|
|
662
662
|
}
|
|
663
|
-
return
|
|
663
|
+
return void 0;
|
|
664
664
|
}).filter(Boolean);
|
|
665
665
|
}
|
|
666
666
|
measureDom(dom) {
|
|
@@ -873,6 +873,13 @@ class EventEmitter {
|
|
|
873
873
|
}
|
|
874
874
|
}
|
|
875
875
|
|
|
876
|
+
function background() {
|
|
877
|
+
return {
|
|
878
|
+
name: "background"
|
|
879
|
+
// TODO
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
|
|
876
883
|
function getHighlightStyle(style) {
|
|
877
884
|
const {
|
|
878
885
|
highlight: highlight2,
|
|
@@ -1244,6 +1251,13 @@ function listStyle() {
|
|
|
1244
1251
|
});
|
|
1245
1252
|
}
|
|
1246
1253
|
|
|
1254
|
+
function outline() {
|
|
1255
|
+
return {
|
|
1256
|
+
name: "outline"
|
|
1257
|
+
// TODO
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1247
1261
|
const tempV1 = new modernPath2d.Vector2();
|
|
1248
1262
|
const tempM1 = new modernPath2d.Matrix3();
|
|
1249
1263
|
const tempM2 = new modernPath2d.Matrix3();
|
|
@@ -1278,7 +1292,7 @@ function render() {
|
|
|
1278
1292
|
boxes.push(aabb);
|
|
1279
1293
|
});
|
|
1280
1294
|
});
|
|
1281
|
-
return boxes.length ? modernPath2d.BoundingBox.from(...boxes) :
|
|
1295
|
+
return boxes.length ? modernPath2d.BoundingBox.from(...boxes) : void 0;
|
|
1282
1296
|
},
|
|
1283
1297
|
render: (ctx, text) => {
|
|
1284
1298
|
const { paragraphs, glyphBox, effects, style } = text;
|
|
@@ -1400,7 +1414,7 @@ function textDecoration() {
|
|
|
1400
1414
|
}
|
|
1401
1415
|
prevStyle = style;
|
|
1402
1416
|
} else {
|
|
1403
|
-
prevStyle =
|
|
1417
|
+
prevStyle = void 0;
|
|
1404
1418
|
}
|
|
1405
1419
|
});
|
|
1406
1420
|
groups.forEach((group2) => {
|
|
@@ -1524,7 +1538,7 @@ class Text extends EventEmitter {
|
|
|
1524
1538
|
this.measureDom = options.measureDom;
|
|
1525
1539
|
this.effects = options.effects;
|
|
1526
1540
|
this.fonts = options.fonts;
|
|
1527
|
-
this.use(listStyle()).use(textDecoration()).use(highlight()).use(render());
|
|
1541
|
+
this.use(background()).use(outline()).use(listStyle()).use(textDecoration()).use(highlight()).use(render());
|
|
1528
1542
|
this.updateParagraphs();
|
|
1529
1543
|
}
|
|
1530
1544
|
use(plugin) {
|
|
@@ -1566,7 +1580,7 @@ class Text extends EventEmitter {
|
|
|
1566
1580
|
paragraph.addFragment(f);
|
|
1567
1581
|
} else {
|
|
1568
1582
|
const { content: content2, ...fStyle } = f;
|
|
1569
|
-
if (content2 !==
|
|
1583
|
+
if (content2 !== void 0) {
|
|
1570
1584
|
paragraph.addFragment(content2, fStyle);
|
|
1571
1585
|
}
|
|
1572
1586
|
}
|
|
@@ -1577,14 +1591,14 @@ class Text extends EventEmitter {
|
|
|
1577
1591
|
const paragraph = new Paragraph(pStyle, style);
|
|
1578
1592
|
fragments.forEach((f) => {
|
|
1579
1593
|
const { content: content2, ...fStyle } = f;
|
|
1580
|
-
if (content2 !==
|
|
1594
|
+
if (content2 !== void 0) {
|
|
1581
1595
|
paragraph.addFragment(content2, fStyle);
|
|
1582
1596
|
}
|
|
1583
1597
|
});
|
|
1584
1598
|
paragraphs.push(paragraph);
|
|
1585
1599
|
} else if ("content" in p) {
|
|
1586
1600
|
const { content: pData, ...pStyle } = p;
|
|
1587
|
-
if (pData !==
|
|
1601
|
+
if (pData !== void 0) {
|
|
1588
1602
|
const paragraph = new Paragraph(pStyle, style);
|
|
1589
1603
|
paragraph.addFragment(pData);
|
|
1590
1604
|
paragraphs.push(paragraph);
|
|
@@ -1733,6 +1747,7 @@ exports.Fragment = Fragment;
|
|
|
1733
1747
|
exports.Measurer = Measurer;
|
|
1734
1748
|
exports.Paragraph = Paragraph;
|
|
1735
1749
|
exports.Text = Text;
|
|
1750
|
+
exports.background = background;
|
|
1736
1751
|
exports.definePlugin = definePlugin;
|
|
1737
1752
|
exports.drawPath = drawPath;
|
|
1738
1753
|
exports.filterEmpty = filterEmpty;
|
|
@@ -1746,6 +1761,7 @@ exports.isNone = isNone;
|
|
|
1746
1761
|
exports.listStyle = listStyle;
|
|
1747
1762
|
exports.measureText = measureText;
|
|
1748
1763
|
exports.needsFetch = needsFetch;
|
|
1764
|
+
exports.outline = outline;
|
|
1749
1765
|
exports.parseColor = parseColor;
|
|
1750
1766
|
exports.parseColormap = parseColormap;
|
|
1751
1767
|
exports.parseValueNumber = parseValueNumber;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
1
|
+
import { StyleDeclaration, TextContent, HighlightDeclaration } from 'modern-idoc';
|
|
2
|
+
import { BoundingBox, Path2DDrawStyle, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
3
3
|
import { Fonts, SFNT } from 'modern-font';
|
|
4
4
|
|
|
5
5
|
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
6
|
-
declare function uploadColor(style: Partial<
|
|
6
|
+
declare function uploadColor(style: Partial<StyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
7
7
|
interface LinearGradient {
|
|
8
8
|
x0: number;
|
|
9
9
|
y0: number;
|
|
@@ -15,7 +15,7 @@ interface LinearGradient {
|
|
|
15
15
|
}[];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
interface DrawShapePathsOptions extends Partial<
|
|
18
|
+
interface DrawShapePathsOptions extends Partial<StyleDeclaration>, Partial<Path2DDrawStyle> {
|
|
19
19
|
ctx: CanvasRenderingContext2D;
|
|
20
20
|
path: Path2D;
|
|
21
21
|
fontSize: number;
|
|
@@ -27,13 +27,13 @@ declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, bo
|
|
|
27
27
|
|
|
28
28
|
declare class Fragment {
|
|
29
29
|
content: string;
|
|
30
|
-
style: Partial<
|
|
30
|
+
style: Partial<StyleDeclaration>;
|
|
31
31
|
parent: Paragraph;
|
|
32
32
|
inlineBox: BoundingBox;
|
|
33
33
|
characters: Character[];
|
|
34
|
-
computedStyle:
|
|
34
|
+
computedStyle: StyleDeclaration;
|
|
35
35
|
get computedContent(): string;
|
|
36
|
-
constructor(content: string, style: Partial<
|
|
36
|
+
constructor(content: string, style: Partial<StyleDeclaration> | undefined, parent: Paragraph);
|
|
37
37
|
updateComputedStyle(): this;
|
|
38
38
|
initCharacters(): this;
|
|
39
39
|
}
|
|
@@ -65,7 +65,7 @@ declare class Character {
|
|
|
65
65
|
centerDiviation: number;
|
|
66
66
|
fontStyle?: 'bold' | 'italic';
|
|
67
67
|
get center(): Vector2 | undefined;
|
|
68
|
-
get computedStyle():
|
|
68
|
+
get computedStyle(): StyleDeclaration;
|
|
69
69
|
get isVertical(): boolean;
|
|
70
70
|
get fontSize(): number;
|
|
71
71
|
get fontHeight(): number;
|
|
@@ -79,18 +79,18 @@ declare class Character {
|
|
|
79
79
|
max: Vector2;
|
|
80
80
|
} | undefined;
|
|
81
81
|
getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
|
|
82
|
-
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<
|
|
82
|
+
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<StyleDeclaration>): void;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
declare class Paragraph {
|
|
86
|
-
style: Partial<
|
|
87
|
-
parentStyle:
|
|
86
|
+
style: Partial<StyleDeclaration>;
|
|
87
|
+
parentStyle: StyleDeclaration;
|
|
88
88
|
lineBox: BoundingBox;
|
|
89
89
|
fragments: Fragment[];
|
|
90
|
-
computedStyle:
|
|
91
|
-
constructor(style: Partial<
|
|
90
|
+
computedStyle: StyleDeclaration;
|
|
91
|
+
constructor(style: Partial<StyleDeclaration>, parentStyle: StyleDeclaration);
|
|
92
92
|
updateComputedStyle(): this;
|
|
93
|
-
addFragment(content: string, style?: Partial<
|
|
93
|
+
addFragment(content: string, style?: Partial<StyleDeclaration>): Fragment;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
interface TextPlugin {
|
|
@@ -104,9 +104,9 @@ interface TextPlugin {
|
|
|
104
104
|
load?: (text: Text$1) => Promise<void>;
|
|
105
105
|
}
|
|
106
106
|
interface TextOptions {
|
|
107
|
-
style?: Partial<
|
|
108
|
-
content?:
|
|
109
|
-
effects?: Partial<
|
|
107
|
+
style?: Partial<StyleDeclaration>;
|
|
108
|
+
content?: TextContent;
|
|
109
|
+
effects?: Partial<StyleDeclaration>[];
|
|
110
110
|
debug?: boolean;
|
|
111
111
|
measureDom?: HTMLElement;
|
|
112
112
|
fonts?: Fonts;
|
|
@@ -177,7 +177,7 @@ declare class Measurer {
|
|
|
177
177
|
* </ul>
|
|
178
178
|
* </section>
|
|
179
179
|
*/
|
|
180
|
-
createParagraphDom(paragraphs: Paragraph[], rootStyle:
|
|
180
|
+
createParagraphDom(paragraphs: Paragraph[], rootStyle: StyleDeclaration): {
|
|
181
181
|
dom: HTMLElement;
|
|
182
182
|
destory: () => void;
|
|
183
183
|
};
|
|
@@ -194,7 +194,7 @@ declare class Measurer {
|
|
|
194
194
|
characters: MeasuredCharacter[];
|
|
195
195
|
};
|
|
196
196
|
measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
|
|
197
|
-
measure(paragraphs: Paragraph[], rootStyle:
|
|
197
|
+
measure(paragraphs: Paragraph[], rootStyle: StyleDeclaration, dom?: HTMLElement): MeasureDomResult;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
interface TextRenderOptions {
|
|
@@ -209,7 +209,7 @@ interface MeasureResult {
|
|
|
209
209
|
pathBox: BoundingBox;
|
|
210
210
|
boundingBox: BoundingBox;
|
|
211
211
|
}
|
|
212
|
-
declare const textDefaultStyle:
|
|
212
|
+
declare const textDefaultStyle: StyleDeclaration;
|
|
213
213
|
interface TextEventMap {
|
|
214
214
|
update: {
|
|
215
215
|
text: Text$1;
|
|
@@ -226,12 +226,12 @@ interface TextEventMap {
|
|
|
226
226
|
}
|
|
227
227
|
declare class Text$1 extends EventEmitter<TextEventMap> {
|
|
228
228
|
debug: boolean;
|
|
229
|
-
content:
|
|
230
|
-
style: Partial<
|
|
231
|
-
effects?: Partial<
|
|
229
|
+
content: TextContent;
|
|
230
|
+
style: Partial<StyleDeclaration>;
|
|
231
|
+
effects?: Partial<StyleDeclaration>[];
|
|
232
232
|
measureDom?: HTMLElement;
|
|
233
233
|
needsUpdate: boolean;
|
|
234
|
-
computedStyle:
|
|
234
|
+
computedStyle: StyleDeclaration;
|
|
235
235
|
paragraphs: Paragraph[];
|
|
236
236
|
lineBox: BoundingBox;
|
|
237
237
|
rawGlyphBox: BoundingBox;
|
|
@@ -273,13 +273,17 @@ type RenderTextOptions = TextOptions & TextRenderOptions;
|
|
|
273
273
|
declare function renderText(options: RenderTextOptions, load: true): Promise<void>;
|
|
274
274
|
declare function renderText(options: RenderTextOptions): void;
|
|
275
275
|
|
|
276
|
-
declare function
|
|
276
|
+
declare function background(): TextPlugin;
|
|
277
|
+
|
|
278
|
+
declare function getHighlightStyle(style: StyleDeclaration): HighlightDeclaration;
|
|
277
279
|
declare function highlight(): TextPlugin;
|
|
278
280
|
|
|
279
281
|
declare function listStyle(): TextPlugin;
|
|
280
282
|
|
|
283
|
+
declare function outline(): TextPlugin;
|
|
284
|
+
|
|
281
285
|
declare function render(): TextPlugin;
|
|
282
|
-
declare function getTransform2D(text: Text$1, style: Partial<
|
|
286
|
+
declare function getTransform2D(text: Text$1, style: Partial<StyleDeclaration>): Matrix3;
|
|
283
287
|
|
|
284
288
|
declare function textDecoration(): TextPlugin;
|
|
285
289
|
|
|
@@ -296,4 +300,4 @@ declare function hexToRgb(hex: string): string | null;
|
|
|
296
300
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
297
301
|
declare function needsFetch(source: string): boolean;
|
|
298
302
|
|
|
299
|
-
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, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
|
|
303
|
+
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, background, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, outline, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
1
|
+
import { StyleDeclaration, TextContent, HighlightDeclaration } from 'modern-idoc';
|
|
2
|
+
import { BoundingBox, Path2DDrawStyle, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
3
3
|
import { Fonts, SFNT } from 'modern-font';
|
|
4
4
|
|
|
5
5
|
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
6
|
-
declare function uploadColor(style: Partial<
|
|
6
|
+
declare function uploadColor(style: Partial<StyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
7
7
|
interface LinearGradient {
|
|
8
8
|
x0: number;
|
|
9
9
|
y0: number;
|
|
@@ -15,7 +15,7 @@ interface LinearGradient {
|
|
|
15
15
|
}[];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
interface DrawShapePathsOptions extends Partial<
|
|
18
|
+
interface DrawShapePathsOptions extends Partial<StyleDeclaration>, Partial<Path2DDrawStyle> {
|
|
19
19
|
ctx: CanvasRenderingContext2D;
|
|
20
20
|
path: Path2D;
|
|
21
21
|
fontSize: number;
|
|
@@ -27,13 +27,13 @@ declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, bo
|
|
|
27
27
|
|
|
28
28
|
declare class Fragment {
|
|
29
29
|
content: string;
|
|
30
|
-
style: Partial<
|
|
30
|
+
style: Partial<StyleDeclaration>;
|
|
31
31
|
parent: Paragraph;
|
|
32
32
|
inlineBox: BoundingBox;
|
|
33
33
|
characters: Character[];
|
|
34
|
-
computedStyle:
|
|
34
|
+
computedStyle: StyleDeclaration;
|
|
35
35
|
get computedContent(): string;
|
|
36
|
-
constructor(content: string, style: Partial<
|
|
36
|
+
constructor(content: string, style: Partial<StyleDeclaration> | undefined, parent: Paragraph);
|
|
37
37
|
updateComputedStyle(): this;
|
|
38
38
|
initCharacters(): this;
|
|
39
39
|
}
|
|
@@ -65,7 +65,7 @@ declare class Character {
|
|
|
65
65
|
centerDiviation: number;
|
|
66
66
|
fontStyle?: 'bold' | 'italic';
|
|
67
67
|
get center(): Vector2 | undefined;
|
|
68
|
-
get computedStyle():
|
|
68
|
+
get computedStyle(): StyleDeclaration;
|
|
69
69
|
get isVertical(): boolean;
|
|
70
70
|
get fontSize(): number;
|
|
71
71
|
get fontHeight(): number;
|
|
@@ -79,18 +79,18 @@ declare class Character {
|
|
|
79
79
|
max: Vector2;
|
|
80
80
|
} | undefined;
|
|
81
81
|
getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
|
|
82
|
-
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<
|
|
82
|
+
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<StyleDeclaration>): void;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
declare class Paragraph {
|
|
86
|
-
style: Partial<
|
|
87
|
-
parentStyle:
|
|
86
|
+
style: Partial<StyleDeclaration>;
|
|
87
|
+
parentStyle: StyleDeclaration;
|
|
88
88
|
lineBox: BoundingBox;
|
|
89
89
|
fragments: Fragment[];
|
|
90
|
-
computedStyle:
|
|
91
|
-
constructor(style: Partial<
|
|
90
|
+
computedStyle: StyleDeclaration;
|
|
91
|
+
constructor(style: Partial<StyleDeclaration>, parentStyle: StyleDeclaration);
|
|
92
92
|
updateComputedStyle(): this;
|
|
93
|
-
addFragment(content: string, style?: Partial<
|
|
93
|
+
addFragment(content: string, style?: Partial<StyleDeclaration>): Fragment;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
interface TextPlugin {
|
|
@@ -104,9 +104,9 @@ interface TextPlugin {
|
|
|
104
104
|
load?: (text: Text$1) => Promise<void>;
|
|
105
105
|
}
|
|
106
106
|
interface TextOptions {
|
|
107
|
-
style?: Partial<
|
|
108
|
-
content?:
|
|
109
|
-
effects?: Partial<
|
|
107
|
+
style?: Partial<StyleDeclaration>;
|
|
108
|
+
content?: TextContent;
|
|
109
|
+
effects?: Partial<StyleDeclaration>[];
|
|
110
110
|
debug?: boolean;
|
|
111
111
|
measureDom?: HTMLElement;
|
|
112
112
|
fonts?: Fonts;
|
|
@@ -177,7 +177,7 @@ declare class Measurer {
|
|
|
177
177
|
* </ul>
|
|
178
178
|
* </section>
|
|
179
179
|
*/
|
|
180
|
-
createParagraphDom(paragraphs: Paragraph[], rootStyle:
|
|
180
|
+
createParagraphDom(paragraphs: Paragraph[], rootStyle: StyleDeclaration): {
|
|
181
181
|
dom: HTMLElement;
|
|
182
182
|
destory: () => void;
|
|
183
183
|
};
|
|
@@ -194,7 +194,7 @@ declare class Measurer {
|
|
|
194
194
|
characters: MeasuredCharacter[];
|
|
195
195
|
};
|
|
196
196
|
measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
|
|
197
|
-
measure(paragraphs: Paragraph[], rootStyle:
|
|
197
|
+
measure(paragraphs: Paragraph[], rootStyle: StyleDeclaration, dom?: HTMLElement): MeasureDomResult;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
interface TextRenderOptions {
|
|
@@ -209,7 +209,7 @@ interface MeasureResult {
|
|
|
209
209
|
pathBox: BoundingBox;
|
|
210
210
|
boundingBox: BoundingBox;
|
|
211
211
|
}
|
|
212
|
-
declare const textDefaultStyle:
|
|
212
|
+
declare const textDefaultStyle: StyleDeclaration;
|
|
213
213
|
interface TextEventMap {
|
|
214
214
|
update: {
|
|
215
215
|
text: Text$1;
|
|
@@ -226,12 +226,12 @@ interface TextEventMap {
|
|
|
226
226
|
}
|
|
227
227
|
declare class Text$1 extends EventEmitter<TextEventMap> {
|
|
228
228
|
debug: boolean;
|
|
229
|
-
content:
|
|
230
|
-
style: Partial<
|
|
231
|
-
effects?: Partial<
|
|
229
|
+
content: TextContent;
|
|
230
|
+
style: Partial<StyleDeclaration>;
|
|
231
|
+
effects?: Partial<StyleDeclaration>[];
|
|
232
232
|
measureDom?: HTMLElement;
|
|
233
233
|
needsUpdate: boolean;
|
|
234
|
-
computedStyle:
|
|
234
|
+
computedStyle: StyleDeclaration;
|
|
235
235
|
paragraphs: Paragraph[];
|
|
236
236
|
lineBox: BoundingBox;
|
|
237
237
|
rawGlyphBox: BoundingBox;
|
|
@@ -273,13 +273,17 @@ type RenderTextOptions = TextOptions & TextRenderOptions;
|
|
|
273
273
|
declare function renderText(options: RenderTextOptions, load: true): Promise<void>;
|
|
274
274
|
declare function renderText(options: RenderTextOptions): void;
|
|
275
275
|
|
|
276
|
-
declare function
|
|
276
|
+
declare function background(): TextPlugin;
|
|
277
|
+
|
|
278
|
+
declare function getHighlightStyle(style: StyleDeclaration): HighlightDeclaration;
|
|
277
279
|
declare function highlight(): TextPlugin;
|
|
278
280
|
|
|
279
281
|
declare function listStyle(): TextPlugin;
|
|
280
282
|
|
|
283
|
+
declare function outline(): TextPlugin;
|
|
284
|
+
|
|
281
285
|
declare function render(): TextPlugin;
|
|
282
|
-
declare function getTransform2D(text: Text$1, style: Partial<
|
|
286
|
+
declare function getTransform2D(text: Text$1, style: Partial<StyleDeclaration>): Matrix3;
|
|
283
287
|
|
|
284
288
|
declare function textDecoration(): TextPlugin;
|
|
285
289
|
|
|
@@ -296,4 +300,4 @@ declare function hexToRgb(hex: string): string | null;
|
|
|
296
300
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
297
301
|
declare function needsFetch(source: string): boolean;
|
|
298
302
|
|
|
299
|
-
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, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
|
|
303
|
+
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, background, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, outline, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
1
|
+
import { StyleDeclaration, TextContent, HighlightDeclaration } from 'modern-idoc';
|
|
2
|
+
import { BoundingBox, Path2DDrawStyle, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
3
3
|
import { Fonts, SFNT } from 'modern-font';
|
|
4
4
|
|
|
5
5
|
declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
|
|
6
|
-
declare function uploadColor(style: Partial<
|
|
6
|
+
declare function uploadColor(style: Partial<StyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
7
7
|
interface LinearGradient {
|
|
8
8
|
x0: number;
|
|
9
9
|
y0: number;
|
|
@@ -15,7 +15,7 @@ interface LinearGradient {
|
|
|
15
15
|
}[];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
interface DrawShapePathsOptions extends Partial<
|
|
18
|
+
interface DrawShapePathsOptions extends Partial<StyleDeclaration>, Partial<Path2DDrawStyle> {
|
|
19
19
|
ctx: CanvasRenderingContext2D;
|
|
20
20
|
path: Path2D;
|
|
21
21
|
fontSize: number;
|
|
@@ -27,13 +27,13 @@ declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, bo
|
|
|
27
27
|
|
|
28
28
|
declare class Fragment {
|
|
29
29
|
content: string;
|
|
30
|
-
style: Partial<
|
|
30
|
+
style: Partial<StyleDeclaration>;
|
|
31
31
|
parent: Paragraph;
|
|
32
32
|
inlineBox: BoundingBox;
|
|
33
33
|
characters: Character[];
|
|
34
|
-
computedStyle:
|
|
34
|
+
computedStyle: StyleDeclaration;
|
|
35
35
|
get computedContent(): string;
|
|
36
|
-
constructor(content: string, style: Partial<
|
|
36
|
+
constructor(content: string, style: Partial<StyleDeclaration> | undefined, parent: Paragraph);
|
|
37
37
|
updateComputedStyle(): this;
|
|
38
38
|
initCharacters(): this;
|
|
39
39
|
}
|
|
@@ -65,7 +65,7 @@ declare class Character {
|
|
|
65
65
|
centerDiviation: number;
|
|
66
66
|
fontStyle?: 'bold' | 'italic';
|
|
67
67
|
get center(): Vector2 | undefined;
|
|
68
|
-
get computedStyle():
|
|
68
|
+
get computedStyle(): StyleDeclaration;
|
|
69
69
|
get isVertical(): boolean;
|
|
70
70
|
get fontSize(): number;
|
|
71
71
|
get fontHeight(): number;
|
|
@@ -79,18 +79,18 @@ declare class Character {
|
|
|
79
79
|
max: Vector2;
|
|
80
80
|
} | undefined;
|
|
81
81
|
getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
|
|
82
|
-
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<
|
|
82
|
+
drawTo(ctx: CanvasRenderingContext2D, config?: Partial<StyleDeclaration>): void;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
declare class Paragraph {
|
|
86
|
-
style: Partial<
|
|
87
|
-
parentStyle:
|
|
86
|
+
style: Partial<StyleDeclaration>;
|
|
87
|
+
parentStyle: StyleDeclaration;
|
|
88
88
|
lineBox: BoundingBox;
|
|
89
89
|
fragments: Fragment[];
|
|
90
|
-
computedStyle:
|
|
91
|
-
constructor(style: Partial<
|
|
90
|
+
computedStyle: StyleDeclaration;
|
|
91
|
+
constructor(style: Partial<StyleDeclaration>, parentStyle: StyleDeclaration);
|
|
92
92
|
updateComputedStyle(): this;
|
|
93
|
-
addFragment(content: string, style?: Partial<
|
|
93
|
+
addFragment(content: string, style?: Partial<StyleDeclaration>): Fragment;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
interface TextPlugin {
|
|
@@ -104,9 +104,9 @@ interface TextPlugin {
|
|
|
104
104
|
load?: (text: Text$1) => Promise<void>;
|
|
105
105
|
}
|
|
106
106
|
interface TextOptions {
|
|
107
|
-
style?: Partial<
|
|
108
|
-
content?:
|
|
109
|
-
effects?: Partial<
|
|
107
|
+
style?: Partial<StyleDeclaration>;
|
|
108
|
+
content?: TextContent;
|
|
109
|
+
effects?: Partial<StyleDeclaration>[];
|
|
110
110
|
debug?: boolean;
|
|
111
111
|
measureDom?: HTMLElement;
|
|
112
112
|
fonts?: Fonts;
|
|
@@ -177,7 +177,7 @@ declare class Measurer {
|
|
|
177
177
|
* </ul>
|
|
178
178
|
* </section>
|
|
179
179
|
*/
|
|
180
|
-
createParagraphDom(paragraphs: Paragraph[], rootStyle:
|
|
180
|
+
createParagraphDom(paragraphs: Paragraph[], rootStyle: StyleDeclaration): {
|
|
181
181
|
dom: HTMLElement;
|
|
182
182
|
destory: () => void;
|
|
183
183
|
};
|
|
@@ -194,7 +194,7 @@ declare class Measurer {
|
|
|
194
194
|
characters: MeasuredCharacter[];
|
|
195
195
|
};
|
|
196
196
|
measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
|
|
197
|
-
measure(paragraphs: Paragraph[], rootStyle:
|
|
197
|
+
measure(paragraphs: Paragraph[], rootStyle: StyleDeclaration, dom?: HTMLElement): MeasureDomResult;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
interface TextRenderOptions {
|
|
@@ -209,7 +209,7 @@ interface MeasureResult {
|
|
|
209
209
|
pathBox: BoundingBox;
|
|
210
210
|
boundingBox: BoundingBox;
|
|
211
211
|
}
|
|
212
|
-
declare const textDefaultStyle:
|
|
212
|
+
declare const textDefaultStyle: StyleDeclaration;
|
|
213
213
|
interface TextEventMap {
|
|
214
214
|
update: {
|
|
215
215
|
text: Text$1;
|
|
@@ -226,12 +226,12 @@ interface TextEventMap {
|
|
|
226
226
|
}
|
|
227
227
|
declare class Text$1 extends EventEmitter<TextEventMap> {
|
|
228
228
|
debug: boolean;
|
|
229
|
-
content:
|
|
230
|
-
style: Partial<
|
|
231
|
-
effects?: Partial<
|
|
229
|
+
content: TextContent;
|
|
230
|
+
style: Partial<StyleDeclaration>;
|
|
231
|
+
effects?: Partial<StyleDeclaration>[];
|
|
232
232
|
measureDom?: HTMLElement;
|
|
233
233
|
needsUpdate: boolean;
|
|
234
|
-
computedStyle:
|
|
234
|
+
computedStyle: StyleDeclaration;
|
|
235
235
|
paragraphs: Paragraph[];
|
|
236
236
|
lineBox: BoundingBox;
|
|
237
237
|
rawGlyphBox: BoundingBox;
|
|
@@ -273,13 +273,17 @@ type RenderTextOptions = TextOptions & TextRenderOptions;
|
|
|
273
273
|
declare function renderText(options: RenderTextOptions, load: true): Promise<void>;
|
|
274
274
|
declare function renderText(options: RenderTextOptions): void;
|
|
275
275
|
|
|
276
|
-
declare function
|
|
276
|
+
declare function background(): TextPlugin;
|
|
277
|
+
|
|
278
|
+
declare function getHighlightStyle(style: StyleDeclaration): HighlightDeclaration;
|
|
277
279
|
declare function highlight(): TextPlugin;
|
|
278
280
|
|
|
279
281
|
declare function listStyle(): TextPlugin;
|
|
280
282
|
|
|
283
|
+
declare function outline(): TextPlugin;
|
|
284
|
+
|
|
281
285
|
declare function render(): TextPlugin;
|
|
282
|
-
declare function getTransform2D(text: Text$1, style: Partial<
|
|
286
|
+
declare function getTransform2D(text: Text$1, style: Partial<StyleDeclaration>): Matrix3;
|
|
283
287
|
|
|
284
288
|
declare function textDecoration(): TextPlugin;
|
|
285
289
|
|
|
@@ -296,4 +300,4 @@ declare function hexToRgb(hex: string): string | null;
|
|
|
296
300
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
297
301
|
declare function needsFetch(source: string): boolean;
|
|
298
302
|
|
|
299
|
-
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, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
|
|
303
|
+
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, background, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, outline, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
|