modern-text 1.2.0 → 1.2.2
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 +22 -22
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/index.mjs +22 -22
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -181,13 +181,13 @@ class Character {
|
|
|
181
181
|
get fontHeight() {
|
|
182
182
|
return this.fontSize * this.computedStyle.lineHeight;
|
|
183
183
|
}
|
|
184
|
-
|
|
184
|
+
_getFontSFNT(fonts) {
|
|
185
185
|
const fontFamily = this.computedStyle.fontFamily;
|
|
186
186
|
const _fonts = fonts ?? modernFont.fonts;
|
|
187
187
|
const font = fontFamily ? _fonts.get(fontFamily) : _fonts.fallbackFont;
|
|
188
|
-
return font?.
|
|
188
|
+
return font?.getSFNT();
|
|
189
189
|
}
|
|
190
|
-
updateGlyph(sfnt = this.
|
|
190
|
+
updateGlyph(sfnt = this._getFontSFNT()) {
|
|
191
191
|
if (!sfnt) {
|
|
192
192
|
return this;
|
|
193
193
|
}
|
|
@@ -224,7 +224,7 @@ class Character {
|
|
|
224
224
|
return this;
|
|
225
225
|
}
|
|
226
226
|
update(fonts) {
|
|
227
|
-
const sfnt = this.
|
|
227
|
+
const sfnt = this._getFontSFNT(fonts);
|
|
228
228
|
if (!sfnt) {
|
|
229
229
|
return this;
|
|
230
230
|
}
|
|
@@ -253,7 +253,7 @@ class Character {
|
|
|
253
253
|
if (Math.abs(advanceWidth - advanceHeight) > 0.1) {
|
|
254
254
|
y -= (ascender - typoAscender) / (ascender + Math.abs(descender)) * advanceHeight;
|
|
255
255
|
}
|
|
256
|
-
glyphIndex =
|
|
256
|
+
glyphIndex = undefined;
|
|
257
257
|
}
|
|
258
258
|
if (isVertical && !set1.has(content) && (content.codePointAt(0) <= 256 || set2.has(content))) {
|
|
259
259
|
path.addCommands(
|
|
@@ -274,12 +274,12 @@ class Character {
|
|
|
274
274
|
isVertical ? {
|
|
275
275
|
x: point.x,
|
|
276
276
|
y: top - (advanceHeight - advanceWidth) / 2 + baseline
|
|
277
|
-
} :
|
|
277
|
+
} : undefined
|
|
278
278
|
);
|
|
279
279
|
}
|
|
280
280
|
path.rotate(90, point);
|
|
281
281
|
} else {
|
|
282
|
-
if (glyphIndex !==
|
|
282
|
+
if (glyphIndex !== undefined) {
|
|
283
283
|
path.addCommands(
|
|
284
284
|
sfnt.glyphs.get(glyphIndex).getPathCommands(x, y, style.fontSize)
|
|
285
285
|
);
|
|
@@ -289,7 +289,7 @@ class Character {
|
|
|
289
289
|
isVertical ? {
|
|
290
290
|
x: x + advanceWidth / 2,
|
|
291
291
|
y: top + typoAscender / (ascender + Math.abs(descender)) * advanceHeight
|
|
292
|
-
} :
|
|
292
|
+
} : undefined
|
|
293
293
|
);
|
|
294
294
|
}
|
|
295
295
|
} else {
|
|
@@ -297,7 +297,7 @@ class Character {
|
|
|
297
297
|
if (needsItalic) {
|
|
298
298
|
this._italic(
|
|
299
299
|
path,
|
|
300
|
-
isVertical ? { x: x + advanceHeight / 2, y } :
|
|
300
|
+
isVertical ? { x: x + advanceHeight / 2, y } : undefined
|
|
301
301
|
);
|
|
302
302
|
}
|
|
303
303
|
}
|
|
@@ -325,13 +325,13 @@ class Character {
|
|
|
325
325
|
if (this.path.curves[0]?.curves.length) {
|
|
326
326
|
return this.path.getMinMax(min, max, withStyle);
|
|
327
327
|
} else {
|
|
328
|
-
return
|
|
328
|
+
return undefined;
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
getGlyphBoundingBox(withStyle) {
|
|
332
|
-
const minMax = this.getGlyphMinMax(
|
|
332
|
+
const minMax = this.getGlyphMinMax(undefined, undefined, withStyle);
|
|
333
333
|
if (!minMax) {
|
|
334
|
-
return
|
|
334
|
+
return undefined;
|
|
335
335
|
}
|
|
336
336
|
const { min, max } = minMax;
|
|
337
337
|
return new modernPath2d.BoundingBox(min.x, min.y, max.x - min.x, max.y - min.y);
|
|
@@ -445,7 +445,7 @@ function filterEmpty(val) {
|
|
|
445
445
|
return val;
|
|
446
446
|
const res = {};
|
|
447
447
|
for (const key in val) {
|
|
448
|
-
if (val[key] !== "" && val[key] !==
|
|
448
|
+
if (val[key] !== "" && val[key] !== undefined) {
|
|
449
449
|
res[key] = val[key];
|
|
450
450
|
}
|
|
451
451
|
}
|
|
@@ -589,7 +589,7 @@ class Measurer {
|
|
|
589
589
|
const isFlex = Boolean(style.justifyContent || style.alignItems);
|
|
590
590
|
Object.assign(dom.style, {
|
|
591
591
|
boxSizing: "border-box",
|
|
592
|
-
display: isFlex ? "inline-flex" :
|
|
592
|
+
display: isFlex ? "inline-flex" : undefined,
|
|
593
593
|
width: "max-content",
|
|
594
594
|
height: "max-content",
|
|
595
595
|
whiteSpace: "pre-wrap",
|
|
@@ -604,8 +604,8 @@ class Measurer {
|
|
|
604
604
|
listStyleType: "inherit",
|
|
605
605
|
padding: "0",
|
|
606
606
|
margin: "0",
|
|
607
|
-
width: isFlex && isHorizontal ? "100%" :
|
|
608
|
-
height: isFlex && !isHorizontal ? "100%" :
|
|
607
|
+
width: isFlex && isHorizontal ? "100%" : undefined,
|
|
608
|
+
height: isFlex && !isHorizontal ? "100%" : undefined
|
|
609
609
|
});
|
|
610
610
|
paragraphs.forEach((paragraph) => {
|
|
611
611
|
const li = document.createElement("li");
|
|
@@ -658,7 +658,7 @@ class Measurer {
|
|
|
658
658
|
width: rect.width
|
|
659
659
|
};
|
|
660
660
|
}
|
|
661
|
-
return
|
|
661
|
+
return undefined;
|
|
662
662
|
}).filter(Boolean);
|
|
663
663
|
}
|
|
664
664
|
measureDom(dom) {
|
|
@@ -1276,7 +1276,7 @@ function render() {
|
|
|
1276
1276
|
boxes.push(aabb);
|
|
1277
1277
|
});
|
|
1278
1278
|
});
|
|
1279
|
-
return boxes.length ? modernPath2d.BoundingBox.from(...boxes) :
|
|
1279
|
+
return boxes.length ? modernPath2d.BoundingBox.from(...boxes) : undefined;
|
|
1280
1280
|
},
|
|
1281
1281
|
render: (ctx, text) => {
|
|
1282
1282
|
const { paragraphs, glyphBox, effects, style } = text;
|
|
@@ -1398,7 +1398,7 @@ function textDecoration() {
|
|
|
1398
1398
|
}
|
|
1399
1399
|
prevStyle = style;
|
|
1400
1400
|
} else {
|
|
1401
|
-
prevStyle =
|
|
1401
|
+
prevStyle = undefined;
|
|
1402
1402
|
}
|
|
1403
1403
|
});
|
|
1404
1404
|
groups.forEach((group2) => {
|
|
@@ -1564,7 +1564,7 @@ class Text extends EventEmitter {
|
|
|
1564
1564
|
paragraph.addFragment(f);
|
|
1565
1565
|
} else {
|
|
1566
1566
|
const { content: content2, ...fStyle } = f;
|
|
1567
|
-
if (content2 !==
|
|
1567
|
+
if (content2 !== undefined) {
|
|
1568
1568
|
paragraph.addFragment(content2, fStyle);
|
|
1569
1569
|
}
|
|
1570
1570
|
}
|
|
@@ -1575,14 +1575,14 @@ class Text extends EventEmitter {
|
|
|
1575
1575
|
const paragraph = new Paragraph(pStyle, style);
|
|
1576
1576
|
fragments.forEach((f) => {
|
|
1577
1577
|
const { content: content2, ...fStyle } = f;
|
|
1578
|
-
if (content2 !==
|
|
1578
|
+
if (content2 !== undefined) {
|
|
1579
1579
|
paragraph.addFragment(content2, fStyle);
|
|
1580
1580
|
}
|
|
1581
1581
|
});
|
|
1582
1582
|
paragraphs.push(paragraph);
|
|
1583
1583
|
} else if ("content" in p) {
|
|
1584
1584
|
const { content: pData, ...pStyle } = p;
|
|
1585
|
-
if (pData !==
|
|
1585
|
+
if (pData !== undefined) {
|
|
1586
1586
|
const paragraph = new Paragraph(pStyle, style);
|
|
1587
1587
|
paragraph.addFragment(pData);
|
|
1588
1588
|
paragraphs.push(paragraph);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IDOCStyleDeclaration, IDOCTextContent, IDOCHighlightDeclaration } from 'modern-idoc';
|
|
2
2
|
import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
3
|
-
import { Fonts,
|
|
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
6
|
declare function uploadColor(style: Partial<IDOCStyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
@@ -70,8 +70,8 @@ declare class Character {
|
|
|
70
70
|
get fontSize(): number;
|
|
71
71
|
get fontHeight(): number;
|
|
72
72
|
constructor(content: string, index: number, parent: Fragment);
|
|
73
|
-
protected
|
|
74
|
-
updateGlyph(sfnt?:
|
|
73
|
+
protected _getFontSFNT(fonts?: Fonts): SFNT | undefined;
|
|
74
|
+
updateGlyph(sfnt?: SFNT | undefined): this;
|
|
75
75
|
update(fonts?: Fonts): this;
|
|
76
76
|
protected _italic(path: Path2D, startPoint?: VectorLike): void;
|
|
77
77
|
getGlyphMinMax(min?: Vector2, max?: Vector2, withStyle?: boolean): {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IDOCStyleDeclaration, IDOCTextContent, IDOCHighlightDeclaration } from 'modern-idoc';
|
|
2
2
|
import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
3
|
-
import { Fonts,
|
|
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
6
|
declare function uploadColor(style: Partial<IDOCStyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
@@ -70,8 +70,8 @@ declare class Character {
|
|
|
70
70
|
get fontSize(): number;
|
|
71
71
|
get fontHeight(): number;
|
|
72
72
|
constructor(content: string, index: number, parent: Fragment);
|
|
73
|
-
protected
|
|
74
|
-
updateGlyph(sfnt?:
|
|
73
|
+
protected _getFontSFNT(fonts?: Fonts): SFNT | undefined;
|
|
74
|
+
updateGlyph(sfnt?: SFNT | undefined): this;
|
|
75
75
|
update(fonts?: Fonts): this;
|
|
76
76
|
protected _italic(path: Path2D, startPoint?: VectorLike): void;
|
|
77
77
|
getGlyphMinMax(min?: Vector2, max?: Vector2, withStyle?: boolean): {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IDOCStyleDeclaration, IDOCTextContent, IDOCHighlightDeclaration } from 'modern-idoc';
|
|
2
2
|
import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
|
|
3
|
-
import { Fonts,
|
|
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
6
|
declare function uploadColor(style: Partial<IDOCStyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
|
|
@@ -70,8 +70,8 @@ declare class Character {
|
|
|
70
70
|
get fontSize(): number;
|
|
71
71
|
get fontHeight(): number;
|
|
72
72
|
constructor(content: string, index: number, parent: Fragment);
|
|
73
|
-
protected
|
|
74
|
-
updateGlyph(sfnt?:
|
|
73
|
+
protected _getFontSFNT(fonts?: Fonts): SFNT | undefined;
|
|
74
|
+
updateGlyph(sfnt?: SFNT | undefined): this;
|
|
75
75
|
update(fonts?: Fonts): this;
|
|
76
76
|
protected _italic(path: Path2D, startPoint?: VectorLike): void;
|
|
77
77
|
getGlyphMinMax(min?: Vector2, max?: Vector2, withStyle?: boolean): {
|