modern-text 1.2.2 → 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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { Path2D, BoundingBox, setCanvasContext, Matrix3, Path2DSet, svgToDOM, svgToPath2DSet, Vector2 } from 'modern-path2d';
1
+ import { Path2D, BoundingBox, setCanvasContext, Path2DSet, Matrix3, svgToDOM, svgToPath2DSet, Vector2 } from 'modern-path2d';
2
2
  import { getDefaultStyle } from 'modern-idoc';
3
3
  import { fonts } from 'modern-font';
4
4
 
@@ -61,6 +61,8 @@ function drawPath(options) {
61
61
  fill: options.color ?? pathStyle.fill,
62
62
  stroke: options.textStrokeColor ?? pathStyle.stroke,
63
63
  strokeWidth: options.textStrokeWidth ? options.textStrokeWidth * fontSize : pathStyle.strokeWidth,
64
+ strokeLinecap: "round",
65
+ strokeLinejoin: "round",
64
66
  shadowOffsetX: (options.shadowOffsetX ?? 0) * fontSize,
65
67
  shadowOffsetY: (options.shadowOffsetY ?? 0) * fontSize,
66
68
  shadowBlur: (options.shadowBlur ?? 0) * fontSize,
@@ -251,7 +253,7 @@ class Character {
251
253
  if (Math.abs(advanceWidth - advanceHeight) > 0.1) {
252
254
  y -= (ascender - typoAscender) / (ascender + Math.abs(descender)) * advanceHeight;
253
255
  }
254
- glyphIndex = undefined;
256
+ glyphIndex = void 0;
255
257
  }
256
258
  if (isVertical && !set1.has(content) && (content.codePointAt(0) <= 256 || set2.has(content))) {
257
259
  path.addCommands(
@@ -272,12 +274,12 @@ class Character {
272
274
  isVertical ? {
273
275
  x: point.x,
274
276
  y: top - (advanceHeight - advanceWidth) / 2 + baseline
275
- } : undefined
277
+ } : void 0
276
278
  );
277
279
  }
278
280
  path.rotate(90, point);
279
281
  } else {
280
- if (glyphIndex !== undefined) {
282
+ if (glyphIndex !== void 0) {
281
283
  path.addCommands(
282
284
  sfnt.glyphs.get(glyphIndex).getPathCommands(x, y, style.fontSize)
283
285
  );
@@ -287,7 +289,7 @@ class Character {
287
289
  isVertical ? {
288
290
  x: x + advanceWidth / 2,
289
291
  y: top + typoAscender / (ascender + Math.abs(descender)) * advanceHeight
290
- } : undefined
292
+ } : void 0
291
293
  );
292
294
  }
293
295
  } else {
@@ -295,7 +297,7 @@ class Character {
295
297
  if (needsItalic) {
296
298
  this._italic(
297
299
  path,
298
- isVertical ? { x: x + advanceHeight / 2, y } : undefined
300
+ isVertical ? { x: x + advanceHeight / 2, y } : void 0
299
301
  );
300
302
  }
301
303
  }
@@ -323,13 +325,13 @@ class Character {
323
325
  if (this.path.curves[0]?.curves.length) {
324
326
  return this.path.getMinMax(min, max, withStyle);
325
327
  } else {
326
- return undefined;
328
+ return void 0;
327
329
  }
328
330
  }
329
331
  getGlyphBoundingBox(withStyle) {
330
- const minMax = this.getGlyphMinMax(undefined, undefined, withStyle);
332
+ const minMax = this.getGlyphMinMax(void 0, void 0, withStyle);
331
333
  if (!minMax) {
332
- return undefined;
334
+ return void 0;
333
335
  }
334
336
  const { min, max } = minMax;
335
337
  return new BoundingBox(min.x, min.y, max.x - min.x, max.y - min.y);
@@ -443,7 +445,7 @@ function filterEmpty(val) {
443
445
  return val;
444
446
  const res = {};
445
447
  for (const key in val) {
446
- if (val[key] !== "" && val[key] !== undefined) {
448
+ if (val[key] !== "" && val[key] !== void 0) {
447
449
  res[key] = val[key];
448
450
  }
449
451
  }
@@ -587,7 +589,7 @@ class Measurer {
587
589
  const isFlex = Boolean(style.justifyContent || style.alignItems);
588
590
  Object.assign(dom.style, {
589
591
  boxSizing: "border-box",
590
- display: isFlex ? "inline-flex" : undefined,
592
+ display: isFlex ? "inline-flex" : void 0,
591
593
  width: "max-content",
592
594
  height: "max-content",
593
595
  whiteSpace: "pre-wrap",
@@ -602,8 +604,8 @@ class Measurer {
602
604
  listStyleType: "inherit",
603
605
  padding: "0",
604
606
  margin: "0",
605
- width: isFlex && isHorizontal ? "100%" : undefined,
606
- height: isFlex && !isHorizontal ? "100%" : undefined
607
+ width: isFlex && isHorizontal ? "100%" : void 0,
608
+ height: isFlex && !isHorizontal ? "100%" : void 0
607
609
  });
608
610
  paragraphs.forEach((paragraph) => {
609
611
  const li = document.createElement("li");
@@ -656,7 +658,7 @@ class Measurer {
656
658
  width: rect.width
657
659
  };
658
660
  }
659
- return undefined;
661
+ return void 0;
660
662
  }).filter(Boolean);
661
663
  }
662
664
  measureDom(dom) {
@@ -869,6 +871,13 @@ class EventEmitter {
869
871
  }
870
872
  }
871
873
 
874
+ function background() {
875
+ return {
876
+ name: "background"
877
+ // TODO
878
+ };
879
+ }
880
+
872
881
  function getHighlightStyle(style) {
873
882
  const {
874
883
  highlight: highlight2,
@@ -1240,6 +1249,13 @@ function listStyle() {
1240
1249
  });
1241
1250
  }
1242
1251
 
1252
+ function outline() {
1253
+ return {
1254
+ name: "outline"
1255
+ // TODO
1256
+ };
1257
+ }
1258
+
1243
1259
  const tempV1 = new Vector2();
1244
1260
  const tempM1 = new Matrix3();
1245
1261
  const tempM2 = new Matrix3();
@@ -1274,7 +1290,7 @@ function render() {
1274
1290
  boxes.push(aabb);
1275
1291
  });
1276
1292
  });
1277
- return boxes.length ? BoundingBox.from(...boxes) : undefined;
1293
+ return boxes.length ? BoundingBox.from(...boxes) : void 0;
1278
1294
  },
1279
1295
  render: (ctx, text) => {
1280
1296
  const { paragraphs, glyphBox, effects, style } = text;
@@ -1396,7 +1412,7 @@ function textDecoration() {
1396
1412
  }
1397
1413
  prevStyle = style;
1398
1414
  } else {
1399
- prevStyle = undefined;
1415
+ prevStyle = void 0;
1400
1416
  }
1401
1417
  });
1402
1418
  groups.forEach((group2) => {
@@ -1520,7 +1536,7 @@ class Text extends EventEmitter {
1520
1536
  this.measureDom = options.measureDom;
1521
1537
  this.effects = options.effects;
1522
1538
  this.fonts = options.fonts;
1523
- this.use(listStyle()).use(textDecoration()).use(highlight()).use(render());
1539
+ this.use(background()).use(outline()).use(listStyle()).use(textDecoration()).use(highlight()).use(render());
1524
1540
  this.updateParagraphs();
1525
1541
  }
1526
1542
  use(plugin) {
@@ -1562,7 +1578,7 @@ class Text extends EventEmitter {
1562
1578
  paragraph.addFragment(f);
1563
1579
  } else {
1564
1580
  const { content: content2, ...fStyle } = f;
1565
- if (content2 !== undefined) {
1581
+ if (content2 !== void 0) {
1566
1582
  paragraph.addFragment(content2, fStyle);
1567
1583
  }
1568
1584
  }
@@ -1573,14 +1589,14 @@ class Text extends EventEmitter {
1573
1589
  const paragraph = new Paragraph(pStyle, style);
1574
1590
  fragments.forEach((f) => {
1575
1591
  const { content: content2, ...fStyle } = f;
1576
- if (content2 !== undefined) {
1592
+ if (content2 !== void 0) {
1577
1593
  paragraph.addFragment(content2, fStyle);
1578
1594
  }
1579
1595
  });
1580
1596
  paragraphs.push(paragraph);
1581
1597
  } else if ("content" in p) {
1582
1598
  const { content: pData, ...pStyle } = p;
1583
- if (pData !== undefined) {
1599
+ if (pData !== void 0) {
1584
1600
  const paragraph = new Paragraph(pStyle, style);
1585
1601
  paragraph.addFragment(pData);
1586
1602
  paragraphs.push(paragraph);
@@ -1724,4 +1740,4 @@ function renderText(options, load) {
1724
1740
  return text.render(options);
1725
1741
  }
1726
1742
 
1727
- export { Character, Fragment, Measurer, Paragraph, Text, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
1743
+ export { Character, Fragment, Measurer, Paragraph, Text, 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-text",
3
3
  "type": "module",
4
- "version": "1.2.2",
4
+ "version": "1.3.0",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "Measure and render text in a way that describes the DOM.",
7
7
  "author": "wxm",
@@ -58,21 +58,21 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "modern-font": "^0.4.0",
61
- "modern-idoc": "^0.1.5",
62
- "modern-path2d": "^1.2.6"
61
+ "modern-idoc": "^0.2.10",
62
+ "modern-path2d": "^1.2.10"
63
63
  },
64
64
  "devDependencies": {
65
- "@antfu/eslint-config": "^3.12.2",
66
- "@types/node": "^22.10.5",
67
- "bumpp": "^9.9.3",
65
+ "@antfu/eslint-config": "^4.8.1",
66
+ "@types/node": "^22.13.10",
67
+ "bumpp": "^10.0.3",
68
68
  "conventional-changelog-cli": "^5.0.0",
69
- "eslint": "^9.17.0",
70
- "lint-staged": "^15.3.0",
69
+ "eslint": "^9.22.0",
70
+ "lint-staged": "^15.4.3",
71
71
  "simple-git-hooks": "^2.11.1",
72
- "typescript": "^5.7.3",
73
- "unbuild": "^3.2.0",
74
- "vite": "^6.0.7",
75
- "vitest": "^2.1.8"
72
+ "typescript": "^5.8.2",
73
+ "unbuild": "^3.5.0",
74
+ "vite": "^6.2.1",
75
+ "vitest": "^3.0.8"
76
76
  },
77
77
  "simple-git-hooks": {
78
78
  "pre-commit": "pnpm lint-staged"