modern-text 1.1.0 → 1.2.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 +23 -23
- package/dist/index.js +5 -5
- package/dist/index.mjs +24 -24
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -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) {
|
|
@@ -909,10 +909,10 @@ function highlight() {
|
|
|
909
909
|
function getPaths(svg) {
|
|
910
910
|
let result = parsed.get(svg);
|
|
911
911
|
if (!result) {
|
|
912
|
-
const dom = modernPath2d.
|
|
912
|
+
const dom = modernPath2d.svgToDOM(
|
|
913
913
|
needsFetch(svg) ? loaded.get(svg) ?? svg : svg
|
|
914
914
|
);
|
|
915
|
-
const pathSet = modernPath2d.
|
|
915
|
+
const pathSet = modernPath2d.svgToPath2DSet(dom);
|
|
916
916
|
result = { dom, pathSet };
|
|
917
917
|
parsed.set(svg, result);
|
|
918
918
|
}
|
|
@@ -1097,7 +1097,7 @@ function highlight() {
|
|
|
1097
1097
|
_transform.translate(i2 * cBox.width, 0);
|
|
1098
1098
|
}
|
|
1099
1099
|
svgPathSet.paths.forEach((originalPath) => {
|
|
1100
|
-
const path = originalPath.clone().
|
|
1100
|
+
const path = originalPath.clone().applyTransform(_transform);
|
|
1101
1101
|
if (path.style.strokeWidth) {
|
|
1102
1102
|
path.style.strokeWidth *= styleScale * _thickness;
|
|
1103
1103
|
}
|
|
@@ -1200,7 +1200,7 @@ function listStyle() {
|
|
|
1200
1200
|
if (!image) {
|
|
1201
1201
|
return;
|
|
1202
1202
|
}
|
|
1203
|
-
const imagePathSet = modernPath2d.
|
|
1203
|
+
const imagePathSet = modernPath2d.svgToPath2DSet(image);
|
|
1204
1204
|
const imageBox = imagePathSet.getBoundingBox();
|
|
1205
1205
|
let prevChar;
|
|
1206
1206
|
paragraph.fragments.forEach((f) => {
|
|
@@ -1225,7 +1225,7 @@ function listStyle() {
|
|
|
1225
1225
|
}
|
|
1226
1226
|
paths.push(...imagePathSet.paths.map((p) => {
|
|
1227
1227
|
const path = p.clone();
|
|
1228
|
-
path.
|
|
1228
|
+
path.applyTransform(m);
|
|
1229
1229
|
if (path.style.fill && path.style.fill in colormap) {
|
|
1230
1230
|
path.style.fill = colormap[path.style.fill];
|
|
1231
1231
|
}
|
|
@@ -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);
|