modern-text 0.5.8 → 0.5.10
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 +74 -58
- package/dist/index.d.cts +7 -7
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +3 -3
- package/dist/index.mjs +75 -58
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -53,7 +53,7 @@ function parseCssLinearGradient(css, x, y, width, height) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function drawPath(options) {
|
|
56
|
-
const { ctx, path, fontSize } = options;
|
|
56
|
+
const { ctx, path, fontSize, clipRect } = options;
|
|
57
57
|
ctx.save();
|
|
58
58
|
ctx.beginPath();
|
|
59
59
|
const pathStyle = path.style;
|
|
@@ -67,6 +67,11 @@ function drawPath(options) {
|
|
|
67
67
|
shadowBlur: (options.shadowBlur ?? 0) * fontSize,
|
|
68
68
|
shadowColor: options.shadowColor
|
|
69
69
|
};
|
|
70
|
+
if (clipRect) {
|
|
71
|
+
ctx.rect(clipRect.left, clipRect.top, clipRect.width, clipRect.height);
|
|
72
|
+
ctx.clip();
|
|
73
|
+
ctx.beginPath();
|
|
74
|
+
}
|
|
70
75
|
path.drawTo(ctx, style);
|
|
71
76
|
ctx.restore();
|
|
72
77
|
}
|
|
@@ -424,30 +429,6 @@ function filterEmpty(val) {
|
|
|
424
429
|
}
|
|
425
430
|
return res;
|
|
426
431
|
}
|
|
427
|
-
function closestDivisor(dividend, targetDivisor) {
|
|
428
|
-
if (dividend <= 0) {
|
|
429
|
-
throw new Error("Dividend must be a positive integer.");
|
|
430
|
-
}
|
|
431
|
-
const divisors = [];
|
|
432
|
-
for (let i = 1; i <= Math.sqrt(dividend); i++) {
|
|
433
|
-
if (dividend % i === 0) {
|
|
434
|
-
divisors.push(i);
|
|
435
|
-
if (i !== dividend / i) {
|
|
436
|
-
divisors.push(dividend / i);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
let closest = divisors[0];
|
|
441
|
-
let minDifference = Math.abs(closest - targetDivisor);
|
|
442
|
-
for (const divisor of divisors) {
|
|
443
|
-
const difference = Math.abs(divisor - targetDivisor);
|
|
444
|
-
if (difference < minDifference) {
|
|
445
|
-
closest = divisor;
|
|
446
|
-
minDifference = difference;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
return closest;
|
|
450
|
-
}
|
|
451
432
|
|
|
452
433
|
var __defProp$3 = Object.defineProperty;
|
|
453
434
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -559,8 +540,10 @@ class Measurer {
|
|
|
559
540
|
Object.assign(dom.style, {
|
|
560
541
|
width: "max-content",
|
|
561
542
|
height: "max-content",
|
|
543
|
+
whiteSpace: "pre-wrap",
|
|
544
|
+
wordBreak: "break-all",
|
|
562
545
|
...this._styleToDomStyle(computedStyle),
|
|
563
|
-
position: "
|
|
546
|
+
position: "fixed",
|
|
564
547
|
visibility: "hidden"
|
|
565
548
|
});
|
|
566
549
|
const ul = document.createElement("ul");
|
|
@@ -576,9 +559,6 @@ class Measurer {
|
|
|
576
559
|
const span = document.createElement("span");
|
|
577
560
|
Object.assign(span.style, this._styleToDomStyle(fragment.style));
|
|
578
561
|
span.appendChild(document.createTextNode(fragment.content));
|
|
579
|
-
if (/\s/.test(fragment.content)) {
|
|
580
|
-
span.style.whiteSpace = "pre";
|
|
581
|
-
}
|
|
582
562
|
li.appendChild(span);
|
|
583
563
|
});
|
|
584
564
|
ul.appendChild(li);
|
|
@@ -815,10 +795,14 @@ class EventEmitter {
|
|
|
815
795
|
|
|
816
796
|
function highlight() {
|
|
817
797
|
const paths = [];
|
|
798
|
+
const clipRects = [];
|
|
818
799
|
const svgStringToSvgPaths = /* @__PURE__ */ new Map();
|
|
819
|
-
function getPaths(svg) {
|
|
800
|
+
async function getPaths(svg) {
|
|
820
801
|
let result = svgStringToSvgPaths.get(svg);
|
|
821
802
|
if (!result) {
|
|
803
|
+
if (svg.startsWith("http")) {
|
|
804
|
+
svg = await fetch(svg).then((rep) => rep.text());
|
|
805
|
+
}
|
|
822
806
|
const dom = modernPath2d.parseSvgToDom(svg);
|
|
823
807
|
const paths2 = modernPath2d.parseSvg(dom);
|
|
824
808
|
result = { dom, paths: paths2 };
|
|
@@ -829,25 +813,32 @@ function highlight() {
|
|
|
829
813
|
return definePlugin({
|
|
830
814
|
name: "highlight",
|
|
831
815
|
paths,
|
|
832
|
-
update: (text) => {
|
|
816
|
+
update: async (text) => {
|
|
833
817
|
paths.length = 0;
|
|
834
|
-
|
|
818
|
+
let groups = [];
|
|
835
819
|
let group;
|
|
836
820
|
let prevStyle;
|
|
837
821
|
text.forEachCharacter((character) => {
|
|
838
|
-
const { isVertical, computedStyle: style, inlineBox
|
|
822
|
+
const { isVertical, computedStyle: style, inlineBox } = character;
|
|
839
823
|
if (!isNone(style.highlightImage) && character.glyphBox) {
|
|
840
|
-
if (
|
|
824
|
+
if ((!prevStyle || isEqualValue(prevStyle.highlightImage, style.highlightImage) && isEqualValue(prevStyle.highlightColormap, style.highlightColormap) && isEqualValue(prevStyle.highlightLine, style.highlightLine) && isEqualValue(prevStyle.highlightSize, style.highlightSize) && isEqualValue(prevStyle.highlightThickness, style.highlightThickness)) && group?.length && (isVertical ? group[0].inlineBox.left === inlineBox.left : group[0].inlineBox.top === inlineBox.top) && group[0].fontSize === style.fontSize) {
|
|
841
825
|
group.push(character);
|
|
842
826
|
} else {
|
|
843
827
|
group = [];
|
|
844
828
|
group.push(character);
|
|
845
829
|
groups.push(group);
|
|
846
830
|
}
|
|
831
|
+
} else {
|
|
832
|
+
if (group?.length) {
|
|
833
|
+
group = [];
|
|
834
|
+
groups.push(group);
|
|
835
|
+
}
|
|
847
836
|
}
|
|
848
837
|
prevStyle = style;
|
|
849
838
|
});
|
|
850
|
-
groups.filter((characters) => characters.length)
|
|
839
|
+
groups = groups.filter((characters) => characters.length);
|
|
840
|
+
for (let i = 0; i < groups.length; i++) {
|
|
841
|
+
const characters = groups[i];
|
|
851
842
|
const char = characters[0];
|
|
852
843
|
const groupBox = modernPath2d.BoundingBox.from(...characters.map((c) => c.glyphBox));
|
|
853
844
|
const { computedStyle: style } = char;
|
|
@@ -858,12 +849,13 @@ function highlight() {
|
|
|
858
849
|
highlightReferImage,
|
|
859
850
|
highlightColormap,
|
|
860
851
|
highlightLine,
|
|
852
|
+
highlightSize,
|
|
861
853
|
highlightThickness
|
|
862
854
|
} = style;
|
|
863
855
|
const isVertical = writingMode.includes("vertical");
|
|
864
856
|
const thickness = parseValueNumber(highlightThickness, { fontSize, total: groupBox.width }) / groupBox.width;
|
|
865
857
|
const colormap = parseColormap(highlightColormap);
|
|
866
|
-
const { paths: svgPaths, dom: svgDom } = getPaths(highlightImage);
|
|
858
|
+
const { paths: svgPaths, dom: svgDom } = await getPaths(highlightImage);
|
|
867
859
|
const aBox = modernPath2d.getPathsBoundingBox(svgPaths, true);
|
|
868
860
|
const styleScale = fontSize / aBox.width * 2;
|
|
869
861
|
const cBox = new modernPath2d.BoundingBox().copy(groupBox);
|
|
@@ -873,9 +865,13 @@ function highlight() {
|
|
|
873
865
|
cBox.left = groupBox.left + groupBox.width;
|
|
874
866
|
}
|
|
875
867
|
const rawWidth = Math.floor(cBox.width);
|
|
876
|
-
|
|
868
|
+
let userWidth = rawWidth;
|
|
869
|
+
if (highlightSize !== "cover") {
|
|
870
|
+
userWidth = parseValueNumber(highlightSize, { fontSize, total: groupBox.width });
|
|
871
|
+
cBox.width = userWidth;
|
|
872
|
+
}
|
|
877
873
|
if (!isNone(highlightReferImage) && isNone(highlightLine)) {
|
|
878
|
-
const bBox = modernPath2d.getPathsBoundingBox(getPaths(highlightReferImage).paths, true);
|
|
874
|
+
const bBox = modernPath2d.getPathsBoundingBox((await getPaths(highlightReferImage)).paths, true);
|
|
879
875
|
aBox.copy(bBox);
|
|
880
876
|
} else {
|
|
881
877
|
let line;
|
|
@@ -947,12 +943,12 @@ function highlight() {
|
|
|
947
943
|
transform.rotate(-Math.PI / 2);
|
|
948
944
|
}
|
|
949
945
|
transform.translate(cBox.x, cBox.y);
|
|
950
|
-
for (let
|
|
946
|
+
for (let i2 = 0; i2 < Math.ceil(rawWidth / userWidth); i2++) {
|
|
951
947
|
const _transform = transform.clone();
|
|
952
948
|
if (isVertical) {
|
|
953
|
-
_transform.translate(0,
|
|
949
|
+
_transform.translate(0, i2 * cBox.width);
|
|
954
950
|
} else {
|
|
955
|
-
_transform.translate(
|
|
951
|
+
_transform.translate(i2 * cBox.width, 0);
|
|
956
952
|
}
|
|
957
953
|
svgPaths.forEach((originalPath) => {
|
|
958
954
|
const path = originalPath.clone().matrix(_transform);
|
|
@@ -975,17 +971,35 @@ function highlight() {
|
|
|
975
971
|
path.style.stroke = colormap[path.style.stroke];
|
|
976
972
|
}
|
|
977
973
|
paths.push(path);
|
|
974
|
+
if (rawWidth !== userWidth) {
|
|
975
|
+
if (isVertical) {
|
|
976
|
+
clipRects[paths.length - 1] = new modernPath2d.BoundingBox(
|
|
977
|
+
groupBox.left - groupBox.width * 2,
|
|
978
|
+
groupBox.top,
|
|
979
|
+
groupBox.width * 4,
|
|
980
|
+
groupBox.height
|
|
981
|
+
);
|
|
982
|
+
} else {
|
|
983
|
+
clipRects[paths.length - 1] = new modernPath2d.BoundingBox(
|
|
984
|
+
groupBox.left,
|
|
985
|
+
groupBox.top - groupBox.height * 2,
|
|
986
|
+
groupBox.width,
|
|
987
|
+
groupBox.height * 4
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
978
991
|
});
|
|
979
992
|
}
|
|
980
|
-
}
|
|
993
|
+
}
|
|
981
994
|
},
|
|
982
995
|
renderOrder: -1,
|
|
983
996
|
render: (ctx, text) => {
|
|
984
|
-
paths.forEach((path) => {
|
|
997
|
+
paths.forEach((path, index) => {
|
|
985
998
|
drawPath({
|
|
986
999
|
ctx,
|
|
987
1000
|
path,
|
|
988
|
-
fontSize: text.computedStyle.fontSize
|
|
1001
|
+
fontSize: text.computedStyle.fontSize,
|
|
1002
|
+
clipRect: clipRects[index]
|
|
989
1003
|
});
|
|
990
1004
|
if (text.debug) {
|
|
991
1005
|
const box = modernPath2d.getPathsBoundingBox([path]);
|
|
@@ -1444,7 +1458,7 @@ class Text extends EventEmitter {
|
|
|
1444
1458
|
this.paragraphs = paragraphs;
|
|
1445
1459
|
return this;
|
|
1446
1460
|
}
|
|
1447
|
-
measure(dom = this.measureDom) {
|
|
1461
|
+
async measure(dom = this.measureDom) {
|
|
1448
1462
|
const old = {
|
|
1449
1463
|
paragraphs: this.paragraphs,
|
|
1450
1464
|
lineBox: this.lineBox,
|
|
@@ -1461,9 +1475,11 @@ class Text extends EventEmitter {
|
|
|
1461
1475
|
c.update(this.fonts);
|
|
1462
1476
|
});
|
|
1463
1477
|
this.rawGlyphBox = this.getGlyphBox();
|
|
1464
|
-
Array.from(this.plugins.values())
|
|
1465
|
-
|
|
1466
|
-
|
|
1478
|
+
const plugins = Array.from(this.plugins.values());
|
|
1479
|
+
plugins.sort((a, b) => (a.updateOrder ?? 0) - (b.updateOrder ?? 0));
|
|
1480
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
1481
|
+
await plugins[i].update?.(this);
|
|
1482
|
+
}
|
|
1467
1483
|
this.glyphBox = this.getGlyphBox();
|
|
1468
1484
|
this.updatePathBox().updateBoundingBox();
|
|
1469
1485
|
for (const key in old) {
|
|
@@ -1519,26 +1535,28 @@ class Text extends EventEmitter {
|
|
|
1519
1535
|
this.needsUpdate = true;
|
|
1520
1536
|
return this;
|
|
1521
1537
|
}
|
|
1522
|
-
update() {
|
|
1523
|
-
const result = this.measure();
|
|
1538
|
+
async update() {
|
|
1539
|
+
const result = await this.measure();
|
|
1524
1540
|
for (const key in result) {
|
|
1525
1541
|
this[key] = result[key];
|
|
1526
1542
|
}
|
|
1527
1543
|
this.emit("update", { text: this });
|
|
1528
|
-
return this;
|
|
1529
1544
|
}
|
|
1530
|
-
render(options) {
|
|
1545
|
+
async render(options) {
|
|
1531
1546
|
const { view, pixelRatio = 2 } = options;
|
|
1532
1547
|
const ctx = view.getContext("2d");
|
|
1533
1548
|
if (!ctx) {
|
|
1534
|
-
return
|
|
1549
|
+
return;
|
|
1535
1550
|
}
|
|
1536
1551
|
if (this.needsUpdate) {
|
|
1537
|
-
this.update();
|
|
1552
|
+
await this.update();
|
|
1538
1553
|
}
|
|
1539
1554
|
setupView(ctx, pixelRatio, this.boundingBox);
|
|
1540
1555
|
uploadColors(ctx, this);
|
|
1541
|
-
Array.from(this.plugins.values())
|
|
1556
|
+
const plugins = Array.from(this.plugins.values());
|
|
1557
|
+
plugins.sort((a, b) => (a.renderOrder ?? 0) - (b.renderOrder ?? 0));
|
|
1558
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
1559
|
+
const plugin = plugins[i];
|
|
1542
1560
|
if (plugin.render) {
|
|
1543
1561
|
plugin.render?.(ctx, this);
|
|
1544
1562
|
} else if (plugin.paths) {
|
|
@@ -1551,9 +1569,8 @@ class Text extends EventEmitter {
|
|
|
1551
1569
|
});
|
|
1552
1570
|
});
|
|
1553
1571
|
}
|
|
1554
|
-
}
|
|
1572
|
+
}
|
|
1555
1573
|
this.emit("render", { text: this, view, pixelRatio });
|
|
1556
|
-
return this;
|
|
1557
1574
|
}
|
|
1558
1575
|
}
|
|
1559
1576
|
|
|
@@ -1570,7 +1587,6 @@ exports.Fragment = Fragment;
|
|
|
1570
1587
|
exports.Measurer = Measurer;
|
|
1571
1588
|
exports.Paragraph = Paragraph;
|
|
1572
1589
|
exports.Text = Text;
|
|
1573
|
-
exports.closestDivisor = closestDivisor;
|
|
1574
1590
|
exports.defaultTextStyles = defaultTextStyles;
|
|
1575
1591
|
exports.definePlugin = definePlugin;
|
|
1576
1592
|
exports.drawPath = drawPath;
|
package/dist/index.d.cts
CHANGED
|
@@ -202,13 +202,13 @@ declare class Text extends EventEmitter<TextEventMap> {
|
|
|
202
202
|
characterIndex: number;
|
|
203
203
|
}) => void): this;
|
|
204
204
|
updateParagraphs(): this;
|
|
205
|
-
measure(dom?: HTMLElement | undefined): MeasureResult
|
|
205
|
+
measure(dom?: HTMLElement | undefined): Promise<MeasureResult>;
|
|
206
206
|
getGlyphBox(): BoundingBox;
|
|
207
207
|
updatePathBox(): this;
|
|
208
208
|
updateBoundingBox(): this;
|
|
209
209
|
requestUpdate(): this;
|
|
210
|
-
update():
|
|
211
|
-
render(options: TextRenderOptions):
|
|
210
|
+
update(): Promise<void>;
|
|
211
|
+
render(options: TextRenderOptions): Promise<void>;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
@@ -322,6 +322,7 @@ interface DrawShapePathsOptions extends Partial<TextStyle> {
|
|
|
322
322
|
ctx: CanvasRenderingContext2D;
|
|
323
323
|
path: Path2D;
|
|
324
324
|
fontSize: number;
|
|
325
|
+
clipRect?: BoundingBox;
|
|
325
326
|
}
|
|
326
327
|
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
327
328
|
|
|
@@ -331,7 +332,7 @@ declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text): void;
|
|
|
331
332
|
|
|
332
333
|
declare function definePlugin(options: TextPlugin): TextPlugin;
|
|
333
334
|
|
|
334
|
-
declare function measureText(options: TextOptions): MeasureResult
|
|
335
|
+
declare function measureText(options: TextOptions): Promise<MeasureResult>;
|
|
335
336
|
|
|
336
337
|
declare function highlight(): TextPlugin;
|
|
337
338
|
|
|
@@ -342,7 +343,7 @@ declare function getTransform2D(text: Text, style: Partial<TextStyle>): Matrix3;
|
|
|
342
343
|
|
|
343
344
|
declare function textDecoration(): TextPlugin;
|
|
344
345
|
|
|
345
|
-
declare function renderText(options: TextOptions & TextRenderOptions):
|
|
346
|
+
declare function renderText(options: TextOptions & TextRenderOptions): Promise<void>;
|
|
346
347
|
|
|
347
348
|
interface ValueContext {
|
|
348
349
|
total: number;
|
|
@@ -355,6 +356,5 @@ declare function isEqualObject(obj1: Record<string, any>, obj2: Record<string, a
|
|
|
355
356
|
declare function isEqualValue(val1: any, val2: any): boolean;
|
|
356
357
|
declare function hexToRgb(hex: string): string | null;
|
|
357
358
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
358
|
-
declare function closestDivisor(dividend: number, targetDivisor: number): number;
|
|
359
359
|
|
|
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,
|
|
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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -202,13 +202,13 @@ declare class Text extends EventEmitter<TextEventMap> {
|
|
|
202
202
|
characterIndex: number;
|
|
203
203
|
}) => void): this;
|
|
204
204
|
updateParagraphs(): this;
|
|
205
|
-
measure(dom?: HTMLElement | undefined): MeasureResult
|
|
205
|
+
measure(dom?: HTMLElement | undefined): Promise<MeasureResult>;
|
|
206
206
|
getGlyphBox(): BoundingBox;
|
|
207
207
|
updatePathBox(): this;
|
|
208
208
|
updateBoundingBox(): this;
|
|
209
209
|
requestUpdate(): this;
|
|
210
|
-
update():
|
|
211
|
-
render(options: TextRenderOptions):
|
|
210
|
+
update(): Promise<void>;
|
|
211
|
+
render(options: TextRenderOptions): Promise<void>;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
@@ -322,6 +322,7 @@ interface DrawShapePathsOptions extends Partial<TextStyle> {
|
|
|
322
322
|
ctx: CanvasRenderingContext2D;
|
|
323
323
|
path: Path2D;
|
|
324
324
|
fontSize: number;
|
|
325
|
+
clipRect?: BoundingBox;
|
|
325
326
|
}
|
|
326
327
|
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
327
328
|
|
|
@@ -331,7 +332,7 @@ declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text): void;
|
|
|
331
332
|
|
|
332
333
|
declare function definePlugin(options: TextPlugin): TextPlugin;
|
|
333
334
|
|
|
334
|
-
declare function measureText(options: TextOptions): MeasureResult
|
|
335
|
+
declare function measureText(options: TextOptions): Promise<MeasureResult>;
|
|
335
336
|
|
|
336
337
|
declare function highlight(): TextPlugin;
|
|
337
338
|
|
|
@@ -342,7 +343,7 @@ declare function getTransform2D(text: Text, style: Partial<TextStyle>): Matrix3;
|
|
|
342
343
|
|
|
343
344
|
declare function textDecoration(): TextPlugin;
|
|
344
345
|
|
|
345
|
-
declare function renderText(options: TextOptions & TextRenderOptions):
|
|
346
|
+
declare function renderText(options: TextOptions & TextRenderOptions): Promise<void>;
|
|
346
347
|
|
|
347
348
|
interface ValueContext {
|
|
348
349
|
total: number;
|
|
@@ -355,6 +356,5 @@ declare function isEqualObject(obj1: Record<string, any>, obj2: Record<string, a
|
|
|
355
356
|
declare function isEqualValue(val1: any, val2: any): boolean;
|
|
356
357
|
declare function hexToRgb(hex: string): string | null;
|
|
357
358
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
358
|
-
declare function closestDivisor(dividend: number, targetDivisor: number): number;
|
|
359
359
|
|
|
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,
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -202,13 +202,13 @@ declare class Text extends EventEmitter<TextEventMap> {
|
|
|
202
202
|
characterIndex: number;
|
|
203
203
|
}) => void): this;
|
|
204
204
|
updateParagraphs(): this;
|
|
205
|
-
measure(dom?: HTMLElement | undefined): MeasureResult
|
|
205
|
+
measure(dom?: HTMLElement | undefined): Promise<MeasureResult>;
|
|
206
206
|
getGlyphBox(): BoundingBox;
|
|
207
207
|
updatePathBox(): this;
|
|
208
208
|
updateBoundingBox(): this;
|
|
209
209
|
requestUpdate(): this;
|
|
210
|
-
update():
|
|
211
|
-
render(options: TextRenderOptions):
|
|
210
|
+
update(): Promise<void>;
|
|
211
|
+
render(options: TextRenderOptions): Promise<void>;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
@@ -322,6 +322,7 @@ interface DrawShapePathsOptions extends Partial<TextStyle> {
|
|
|
322
322
|
ctx: CanvasRenderingContext2D;
|
|
323
323
|
path: Path2D;
|
|
324
324
|
fontSize: number;
|
|
325
|
+
clipRect?: BoundingBox;
|
|
325
326
|
}
|
|
326
327
|
declare function drawPath(options: DrawShapePathsOptions): void;
|
|
327
328
|
|
|
@@ -331,7 +332,7 @@ declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text): void;
|
|
|
331
332
|
|
|
332
333
|
declare function definePlugin(options: TextPlugin): TextPlugin;
|
|
333
334
|
|
|
334
|
-
declare function measureText(options: TextOptions): MeasureResult
|
|
335
|
+
declare function measureText(options: TextOptions): Promise<MeasureResult>;
|
|
335
336
|
|
|
336
337
|
declare function highlight(): TextPlugin;
|
|
337
338
|
|
|
@@ -342,7 +343,7 @@ declare function getTransform2D(text: Text, style: Partial<TextStyle>): Matrix3;
|
|
|
342
343
|
|
|
343
344
|
declare function textDecoration(): TextPlugin;
|
|
344
345
|
|
|
345
|
-
declare function renderText(options: TextOptions & TextRenderOptions):
|
|
346
|
+
declare function renderText(options: TextOptions & TextRenderOptions): Promise<void>;
|
|
346
347
|
|
|
347
348
|
interface ValueContext {
|
|
348
349
|
total: number;
|
|
@@ -355,6 +356,5 @@ declare function isEqualObject(obj1: Record<string, any>, obj2: Record<string, a
|
|
|
355
356
|
declare function isEqualValue(val1: any, val2: any): boolean;
|
|
356
357
|
declare function hexToRgb(hex: string): string | null;
|
|
357
358
|
declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
358
|
-
declare function closestDivisor(dividend: number, targetDivisor: number): number;
|
|
359
359
|
|
|
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,
|
|
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 };
|