modern-text 1.10.0 → 1.10.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.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { T as Text } from './shared/modern-text.BD1kUWDw.mjs';
2
- export { C as Canvas2DRenderer, a as Character, F as Fragment, M as Measurer, P as Paragraph, b as backgroundPlugin, f as createSvgLoader, i as createSvgParser, d as definePlugin, q as filterEmpty, g as getHighlightStyle, c as getTransform2D, n as hexToRgb, h as highlightPlugin, k as isEqualObject, m as isEqualValue, l as listStylePlugin, o as outlinePlugin, j as parseColormap, p as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, e as textDefaultStyle } from './shared/modern-text.BD1kUWDw.mjs';
1
+ import { T as Text } from './shared/modern-text.DoxsfyuV.mjs';
2
+ export { C as Canvas2DRenderer, a as Character, F as Fragment, M as Measurer, P as Paragraph, b as backgroundPlugin, f as createSvgLoader, i as createSvgParser, d as definePlugin, q as filterEmpty, g as getHighlightStyle, c as getTransform2D, n as hexToRgb, h as highlightPlugin, k as isEqualObject, m as isEqualValue, l as listStylePlugin, o as outlinePlugin, j as parseColormap, p as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, e as textDefaultStyle } from './shared/modern-text.DoxsfyuV.mjs';
3
3
  import 'modern-idoc';
4
4
  import 'modern-path2d';
5
5
  import 'modern-font';
@@ -82,6 +82,9 @@ class Canvas2DRenderer {
82
82
  case "rgba":
83
83
  canvasGradient.addColorStop(offset, `rgba(${colorStop.value.join(", ")})`);
84
84
  break;
85
+ case "hex":
86
+ canvasGradient.addColorStop(offset, `#${colorStop.value}`);
87
+ break;
85
88
  }
86
89
  });
87
90
  return canvasGradient;
@@ -102,11 +105,8 @@ class Canvas2DRenderer {
102
105
  });
103
106
  };
104
107
  drawPath = (path, options = {}) => {
108
+ const { clipRect } = options;
105
109
  const ctx = this.context;
106
- const {
107
- fontSize = this.text.computedStyle.fontSize,
108
- clipRect
109
- } = options;
110
110
  ctx.save();
111
111
  ctx.beginPath();
112
112
  if (clipRect) {
@@ -114,23 +114,30 @@ class Canvas2DRenderer {
114
114
  ctx.clip();
115
115
  ctx.beginPath();
116
116
  }
117
+ path.drawTo(ctx, this._mergePathStyle(path, options));
118
+ ctx.restore();
119
+ };
120
+ _mergePathStyle(path, style) {
121
+ const {
122
+ fontSize = this.text.computedStyle.fontSize
123
+ } = style;
117
124
  const pathStyle = path.style;
118
- const stroke = options.textStrokeColor ?? pathStyle.stroke;
119
- const strokeWidth = options.textStrokeWidth ? options.textStrokeWidth * fontSize : pathStyle.strokeWidth;
120
- path.drawTo(ctx, {
125
+ const stroke = style.stroke ?? pathStyle.stroke;
126
+ const strokeWidth = style.strokeWidth ? style.strokeWidth * fontSize : pathStyle.strokeWidth;
127
+ return {
121
128
  ...pathStyle,
122
- fill: options.color ?? pathStyle.fill,
129
+ ...style,
130
+ fill: style.fill ?? pathStyle.fill,
123
131
  stroke: strokeWidth === void 0 || strokeWidth > 0 ? stroke : void 0,
132
+ strokeLinecap: style.strokeLinecap ?? pathStyle.strokeLinecap ?? "round",
133
+ strokeLinejoin: style.strokeLinejoin ?? pathStyle.strokeLinejoin ?? "round",
124
134
  strokeWidth,
125
- strokeLinecap: "round",
126
- strokeLinejoin: "round",
127
- shadowOffsetX: (options.shadowOffsetX ?? 0) * fontSize,
128
- shadowOffsetY: (options.shadowOffsetY ?? 0) * fontSize,
129
- shadowBlur: (options.shadowBlur ?? 0) * fontSize,
130
- shadowColor: options.shadowColor
131
- });
132
- ctx.restore();
133
- };
135
+ shadowOffsetX: (style.shadowOffsetX ?? 0) * fontSize,
136
+ shadowOffsetY: (style.shadowOffsetY ?? 0) * fontSize,
137
+ shadowBlur: (style.shadowBlur ?? 0) * fontSize,
138
+ shadowColor: style.shadowColor
139
+ };
140
+ }
134
141
  drawCharacter = (character, userStyle = {}) => {
135
142
  const ctx = this.context;
136
143
  const {
@@ -140,28 +147,28 @@ class Canvas2DRenderer {
140
147
  isVertical,
141
148
  content,
142
149
  inlineBox,
143
- baseline
150
+ baseline,
151
+ computedFill,
152
+ computedOutline
144
153
  } = character;
145
154
  const style = {
146
155
  ...computedStyle,
147
156
  ...userStyle
148
157
  };
158
+ const pathStyle = {
159
+ strokeLinecap: computedOutline?.lineCap,
160
+ strokeLinejoin: computedOutline?.lineJoin,
161
+ ...style,
162
+ fill: userStyle.color ?? computedFill?.color ?? computedStyle.color,
163
+ strokeWidth: userStyle.textStrokeWidth ?? computedOutline?.width ?? computedStyle.textStrokeWidth,
164
+ stroke: userStyle.textStrokeColor ?? computedOutline?.color ?? computedStyle.textStrokeColor
165
+ };
149
166
  if (glyphBox) {
150
- this.drawPath(path, style);
167
+ this.drawPath(path, pathStyle);
151
168
  } else {
152
169
  ctx.save();
153
170
  ctx.beginPath();
154
- const pathStyle = path.style;
155
- modernPath2d.setCanvasContext(ctx, {
156
- ...pathStyle,
157
- fill: style.color ?? pathStyle.fill,
158
- stroke: style.textStrokeColor ?? pathStyle.stroke,
159
- strokeWidth: style.textStrokeWidth ? style.textStrokeWidth * style.fontSize : pathStyle.strokeWidth,
160
- shadowOffsetX: (style.shadowOffsetX ?? 0) * style.fontSize,
161
- shadowOffsetY: (style.shadowOffsetY ?? 0) * style.fontSize,
162
- shadowBlur: (style.shadowBlur ?? 0) * style.fontSize,
163
- shadowColor: style.shadowColor
164
- });
171
+ modernPath2d.setCanvasContext(ctx, this._mergePathStyle(path, pathStyle));
165
172
  ctx.font = `${style.fontSize}px ${style.fontFamily}`;
166
173
  if (isVertical) {
167
174
  ctx.textBaseline = "middle";
@@ -80,6 +80,9 @@ class Canvas2DRenderer {
80
80
  case "rgba":
81
81
  canvasGradient.addColorStop(offset, `rgba(${colorStop.value.join(", ")})`);
82
82
  break;
83
+ case "hex":
84
+ canvasGradient.addColorStop(offset, `#${colorStop.value}`);
85
+ break;
83
86
  }
84
87
  });
85
88
  return canvasGradient;
@@ -100,11 +103,8 @@ class Canvas2DRenderer {
100
103
  });
101
104
  };
102
105
  drawPath = (path, options = {}) => {
106
+ const { clipRect } = options;
103
107
  const ctx = this.context;
104
- const {
105
- fontSize = this.text.computedStyle.fontSize,
106
- clipRect
107
- } = options;
108
108
  ctx.save();
109
109
  ctx.beginPath();
110
110
  if (clipRect) {
@@ -112,23 +112,30 @@ class Canvas2DRenderer {
112
112
  ctx.clip();
113
113
  ctx.beginPath();
114
114
  }
115
+ path.drawTo(ctx, this._mergePathStyle(path, options));
116
+ ctx.restore();
117
+ };
118
+ _mergePathStyle(path, style) {
119
+ const {
120
+ fontSize = this.text.computedStyle.fontSize
121
+ } = style;
115
122
  const pathStyle = path.style;
116
- const stroke = options.textStrokeColor ?? pathStyle.stroke;
117
- const strokeWidth = options.textStrokeWidth ? options.textStrokeWidth * fontSize : pathStyle.strokeWidth;
118
- path.drawTo(ctx, {
123
+ const stroke = style.stroke ?? pathStyle.stroke;
124
+ const strokeWidth = style.strokeWidth ? style.strokeWidth * fontSize : pathStyle.strokeWidth;
125
+ return {
119
126
  ...pathStyle,
120
- fill: options.color ?? pathStyle.fill,
127
+ ...style,
128
+ fill: style.fill ?? pathStyle.fill,
121
129
  stroke: strokeWidth === void 0 || strokeWidth > 0 ? stroke : void 0,
130
+ strokeLinecap: style.strokeLinecap ?? pathStyle.strokeLinecap ?? "round",
131
+ strokeLinejoin: style.strokeLinejoin ?? pathStyle.strokeLinejoin ?? "round",
122
132
  strokeWidth,
123
- strokeLinecap: "round",
124
- strokeLinejoin: "round",
125
- shadowOffsetX: (options.shadowOffsetX ?? 0) * fontSize,
126
- shadowOffsetY: (options.shadowOffsetY ?? 0) * fontSize,
127
- shadowBlur: (options.shadowBlur ?? 0) * fontSize,
128
- shadowColor: options.shadowColor
129
- });
130
- ctx.restore();
131
- };
133
+ shadowOffsetX: (style.shadowOffsetX ?? 0) * fontSize,
134
+ shadowOffsetY: (style.shadowOffsetY ?? 0) * fontSize,
135
+ shadowBlur: (style.shadowBlur ?? 0) * fontSize,
136
+ shadowColor: style.shadowColor
137
+ };
138
+ }
132
139
  drawCharacter = (character, userStyle = {}) => {
133
140
  const ctx = this.context;
134
141
  const {
@@ -138,28 +145,28 @@ class Canvas2DRenderer {
138
145
  isVertical,
139
146
  content,
140
147
  inlineBox,
141
- baseline
148
+ baseline,
149
+ computedFill,
150
+ computedOutline
142
151
  } = character;
143
152
  const style = {
144
153
  ...computedStyle,
145
154
  ...userStyle
146
155
  };
156
+ const pathStyle = {
157
+ strokeLinecap: computedOutline?.lineCap,
158
+ strokeLinejoin: computedOutline?.lineJoin,
159
+ ...style,
160
+ fill: userStyle.color ?? computedFill?.color ?? computedStyle.color,
161
+ strokeWidth: userStyle.textStrokeWidth ?? computedOutline?.width ?? computedStyle.textStrokeWidth,
162
+ stroke: userStyle.textStrokeColor ?? computedOutline?.color ?? computedStyle.textStrokeColor
163
+ };
147
164
  if (glyphBox) {
148
- this.drawPath(path, style);
165
+ this.drawPath(path, pathStyle);
149
166
  } else {
150
167
  ctx.save();
151
168
  ctx.beginPath();
152
- const pathStyle = path.style;
153
- setCanvasContext(ctx, {
154
- ...pathStyle,
155
- fill: style.color ?? pathStyle.fill,
156
- stroke: style.textStrokeColor ?? pathStyle.stroke,
157
- strokeWidth: style.textStrokeWidth ? style.textStrokeWidth * style.fontSize : pathStyle.strokeWidth,
158
- shadowOffsetX: (style.shadowOffsetX ?? 0) * style.fontSize,
159
- shadowOffsetY: (style.shadowOffsetY ?? 0) * style.fontSize,
160
- shadowBlur: (style.shadowBlur ?? 0) * style.fontSize,
161
- shadowColor: style.shadowColor
162
- });
169
+ setCanvasContext(ctx, this._mergePathStyle(path, pathStyle));
163
170
  ctx.font = `${style.fontSize}px ${style.fontFamily}`;
164
171
  if (isVertical) {
165
172
  ctx.textBaseline = "middle";
@@ -1,5 +1,5 @@
1
1
  import { NormalizedStyle, NormalizedFill, NormalizedOutline, FullStyle, TextObject, ReactivableEvents, Reactivable, NormalizedText } from 'modern-idoc';
2
- import { BoundingBox, Path2D, Vector2, VectorLike, Path2DSet, Path2DDrawStyle } from 'modern-path2d';
2
+ import { BoundingBox, Path2D, Vector2, VectorLike, Path2DSet, Path2DDrawStyle, Path2DStyle } from 'modern-path2d';
3
3
  import { Fonts, SFNT } from 'modern-font';
4
4
 
5
5
  declare class Fragment {
@@ -256,6 +256,7 @@ declare class Canvas2DRenderer {
256
256
  protected _uploadedStyles: string[];
257
257
  uploadColor: (style: NormalizedStyle, box: BoundingBox) => void;
258
258
  drawPath: (path: Path2D, options?: DrawShapePathsOptions) => void;
259
+ protected _mergePathStyle(path: Path2D, style: Partial<Path2DStyle>): Partial<Path2DStyle>;
259
260
  drawCharacter: (character: Character, userStyle?: NormalizedStyle) => void;
260
261
  }
261
262
 
@@ -1,5 +1,5 @@
1
1
  import { NormalizedStyle, NormalizedFill, NormalizedOutline, FullStyle, TextObject, ReactivableEvents, Reactivable, NormalizedText } from 'modern-idoc';
2
- import { BoundingBox, Path2D, Vector2, VectorLike, Path2DSet, Path2DDrawStyle } from 'modern-path2d';
2
+ import { BoundingBox, Path2D, Vector2, VectorLike, Path2DSet, Path2DDrawStyle, Path2DStyle } from 'modern-path2d';
3
3
  import { Fonts, SFNT } from 'modern-font';
4
4
 
5
5
  declare class Fragment {
@@ -256,6 +256,7 @@ declare class Canvas2DRenderer {
256
256
  protected _uploadedStyles: string[];
257
257
  uploadColor: (style: NormalizedStyle, box: BoundingBox) => void;
258
258
  drawPath: (path: Path2D, options?: DrawShapePathsOptions) => void;
259
+ protected _mergePathStyle(path: Path2D, style: Partial<Path2DStyle>): Partial<Path2DStyle>;
259
260
  drawCharacter: (character: Character, userStyle?: NormalizedStyle) => void;
260
261
  }
261
262
 
@@ -1,5 +1,5 @@
1
1
  import { NormalizedStyle, NormalizedFill, NormalizedOutline, FullStyle, TextObject, ReactivableEvents, Reactivable, NormalizedText } from 'modern-idoc';
2
- import { BoundingBox, Path2D, Vector2, VectorLike, Path2DSet, Path2DDrawStyle } from 'modern-path2d';
2
+ import { BoundingBox, Path2D, Vector2, VectorLike, Path2DSet, Path2DDrawStyle, Path2DStyle } from 'modern-path2d';
3
3
  import { Fonts, SFNT } from 'modern-font';
4
4
 
5
5
  declare class Fragment {
@@ -256,6 +256,7 @@ declare class Canvas2DRenderer {
256
256
  protected _uploadedStyles: string[];
257
257
  uploadColor: (style: NormalizedStyle, box: BoundingBox) => void;
258
258
  drawPath: (path: Path2D, options?: DrawShapePathsOptions) => void;
259
+ protected _mergePathStyle(path: Path2D, style: Partial<Path2DStyle>): Partial<Path2DStyle>;
259
260
  drawCharacter: (character: Character, userStyle?: NormalizedStyle) => void;
260
261
  }
261
262
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  const diff = require('diff');
4
4
  const modernIdoc = require('modern-idoc');
5
- const Text = require('../shared/modern-text.BUyl2x8m.cjs');
5
+ const Text = require('../shared/modern-text.C6lGlnKL.cjs');
6
6
  require('modern-path2d');
7
7
  require('modern-font');
8
8
 
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.D_VtaVfs.cjs';
2
+ import { T as Text } from '../shared/modern-text.DpdDwkTw.cjs';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.D_VtaVfs.mjs';
2
+ import { T as Text } from '../shared/modern-text.DpdDwkTw.mjs';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.D_VtaVfs.js';
2
+ import { T as Text } from '../shared/modern-text.DpdDwkTw.js';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import { diffChars } from 'diff';
2
2
  import { isCRLF, textContentToString, normalizeCRLF, normalizeTextContent, property } from 'modern-idoc';
3
- import { T as Text } from '../shared/modern-text.BD1kUWDw.mjs';
3
+ import { T as Text } from '../shared/modern-text.DoxsfyuV.mjs';
4
4
  import 'modern-path2d';
5
5
  import 'modern-font';
6
6
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-text",
3
3
  "type": "module",
4
- "version": "1.10.0",
4
+ "version": "1.10.2",
5
5
  "packageManager": "pnpm@10.18.1",
6
6
  "description": "Measure and render text in a way that describes the DOM.",
7
7
  "author": "wxm",
@@ -60,7 +60,7 @@
60
60
  "modern-path2d": "^1.4.10"
61
61
  },
62
62
  "devDependencies": {
63
- "@antfu/eslint-config": "^6.1.0",
63
+ "@antfu/eslint-config": "^6.2.0",
64
64
  "@types/node": "^24.9.2",
65
65
  "bumpp": "^10.3.1",
66
66
  "conventional-changelog-cli": "^5.0.0",
@@ -68,6 +68,6 @@
68
68
  "typescript": "^5.9.3",
69
69
  "unbuild": "^3.6.1",
70
70
  "vite": "^7.1.12",
71
- "vitest": "^4.0.4"
71
+ "vitest": "^4.0.5"
72
72
  }
73
73
  }