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.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -7
- package/dist/index.mjs +2 -2
- package/dist/shared/{modern-text.BUyl2x8m.cjs → modern-text.C6lGlnKL.cjs} +37 -30
- package/dist/shared/{modern-text.BD1kUWDw.mjs → modern-text.DoxsfyuV.mjs} +37 -30
- package/dist/shared/{modern-text.D_VtaVfs.d.ts → modern-text.DpdDwkTw.d.cts} +2 -1
- package/dist/shared/{modern-text.D_VtaVfs.d.cts → modern-text.DpdDwkTw.d.mts} +2 -1
- package/dist/shared/{modern-text.D_VtaVfs.d.mts → modern-text.DpdDwkTw.d.ts} +2 -1
- package/dist/web-components/index.cjs +1 -1
- package/dist/web-components/index.d.cts +1 -1
- package/dist/web-components/index.d.mts +1 -1
- package/dist/web-components/index.d.ts +1 -1
- package/dist/web-components/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as Text } from './shared/modern-text.
|
|
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.
|
|
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 =
|
|
119
|
-
const strokeWidth =
|
|
120
|
-
|
|
125
|
+
const stroke = style.stroke ?? pathStyle.stroke;
|
|
126
|
+
const strokeWidth = style.strokeWidth ? style.strokeWidth * fontSize : pathStyle.strokeWidth;
|
|
127
|
+
return {
|
|
121
128
|
...pathStyle,
|
|
122
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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,
|
|
167
|
+
this.drawPath(path, pathStyle);
|
|
151
168
|
} else {
|
|
152
169
|
ctx.save();
|
|
153
170
|
ctx.beginPath();
|
|
154
|
-
|
|
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 =
|
|
117
|
-
const strokeWidth =
|
|
118
|
-
|
|
123
|
+
const stroke = style.stroke ?? pathStyle.stroke;
|
|
124
|
+
const strokeWidth = style.strokeWidth ? style.strokeWidth * fontSize : pathStyle.strokeWidth;
|
|
125
|
+
return {
|
|
119
126
|
...pathStyle,
|
|
120
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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,
|
|
165
|
+
this.drawPath(path, pathStyle);
|
|
149
166
|
} else {
|
|
150
167
|
ctx.save();
|
|
151
168
|
ctx.beginPath();
|
|
152
|
-
|
|
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
|
|
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
71
|
+
"vitest": "^4.0.5"
|
|
72
72
|
}
|
|
73
73
|
}
|