modern-text 2.1.0 → 2.1.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.
Files changed (28) hide show
  1. package/README.md +27 -18
  2. package/dist/deformations/index.cjs +1 -1
  3. package/dist/deformations/index.d.cts +2 -2
  4. package/dist/deformations/index.d.mts +2 -2
  5. package/dist/deformations/index.d.ts +2 -2
  6. package/dist/deformations/index.mjs +1 -1
  7. package/dist/index.cjs +2 -2
  8. package/dist/index.d.cts +4 -4
  9. package/dist/index.d.mts +4 -4
  10. package/dist/index.d.ts +4 -4
  11. package/dist/index.js +8 -7
  12. package/dist/index.mjs +3 -3
  13. package/dist/shared/{modern-text.CGZmjNV0.d.ts → modern-text.1LMQ6ZWb.d.ts} +3 -3
  14. package/dist/shared/{modern-text.BBDyCm63.cjs → modern-text.BAnUZM0U.cjs} +1 -1
  15. package/dist/shared/{modern-text.DNvXuVjw.mjs → modern-text.BdF52nXP.mjs} +1 -1
  16. package/dist/shared/{modern-text.K8BlyK2j.mjs → modern-text.CdKp2H-o.mjs} +13 -4
  17. package/dist/shared/{modern-text.DNXfZmiT.d.mts → modern-text.CjkLMv3V.d.cts} +3 -3
  18. package/dist/shared/{modern-text.DzBaDwbG.d.cts → modern-text.Cv-GZog_.d.mts} +3 -3
  19. package/dist/shared/{modern-text.DG27jpKj.d.ts → modern-text.DENkEKJN.d.cts} +38 -38
  20. package/dist/shared/{modern-text.DG27jpKj.d.cts → modern-text.DENkEKJN.d.mts} +38 -38
  21. package/dist/shared/{modern-text.DG27jpKj.d.mts → modern-text.DENkEKJN.d.ts} +38 -38
  22. package/dist/shared/{modern-text.DQWdaYoZ.cjs → modern-text._10DVHum.cjs} +13 -4
  23. package/dist/web-components/index.cjs +2 -2
  24. package/dist/web-components/index.d.cts +2 -2
  25. package/dist/web-components/index.d.mts +2 -2
  26. package/dist/web-components/index.d.ts +2 -2
  27. package/dist/web-components/index.mjs +2 -2
  28. package/package.json +9 -9
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { T as Text } from './shared/modern-text.DNvXuVjw.mjs';
2
- export { C as Canvas2DRenderer, a as Character, F as Fragment, M as Measurer, P as Paragraph, b as backgroundPlugin, c as createSvgLoader, d as createSvgParser, g as getEffectTransform2D, e as getHighlightStyle, h as highlightPlugin, i as isEqualObject, f as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColormap, j as parseTransformOrigin, k as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, m as textDefaultStyle } from './shared/modern-text.DNvXuVjw.mjs';
3
- export { d as defineDeformation, a as definePlugin, b as deformationPlugin, g as getDeformationNames, r as removeDeformation } from './shared/modern-text.K8BlyK2j.mjs';
1
+ import { T as Text } from './shared/modern-text.BdF52nXP.mjs';
2
+ export { C as Canvas2DRenderer, a as Character, F as Fragment, M as Measurer, P as Paragraph, b as backgroundPlugin, c as createSvgLoader, d as createSvgParser, g as getEffectTransform2D, e as getHighlightStyle, h as highlightPlugin, i as isEqualObject, f as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColormap, j as parseTransformOrigin, k as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, m as textDefaultStyle } from './shared/modern-text.BdF52nXP.mjs';
3
+ export { d as defineDeformation, a as definePlugin, b as deformationPlugin, g as getDeformationNames, r as removeDeformation } from './shared/modern-text.CdKp2H-o.mjs';
4
4
  export { C as CircleCurve, E as EllipseCurve, H as HeartCurve, P as PolygonCurve, R as RectangularCurve } from './shared/modern-text.fT17R5HY.mjs';
5
5
  import 'modern-font';
6
6
  import 'modern-idoc';
@@ -1,5 +1,5 @@
1
- import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.DG27jpKj.js';
1
+ import { Vector2, Vector2Like, BoundingBox } from 'modern-path2d';
2
+ import { C as Character } from './modern-text.DENkEKJN.js';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -97,4 +97,4 @@ interface OffsetPreset extends PresetBase {
97
97
  }
98
98
  type DeformationPreset = FfdPreset | BendPreset | CurvePreset | OffsetPreset;
99
99
 
100
- export type { BendContext as B, CurvePreset as C, DeformationCharInfo as D, FfdContext as F, OffsetPreset as O, VerbatimContext as V, BendPreset as a, DeformationCurve as b, DeformationPreset as c, FfdPreset as d };
100
+ export type { BendContext as B, CurvePreset as C, DeformationPreset as D, FfdContext as F, OffsetPreset as O, VerbatimContext as V, BendPreset as a, DeformationCharInfo as b, DeformationCurve as c, FfdPreset as d };
@@ -3,7 +3,7 @@
3
3
  const modernFont = require('modern-font');
4
4
  const modernIdoc = require('modern-idoc');
5
5
  const modernPath2d = require('modern-path2d');
6
- const deformation = require('./modern-text.DQWdaYoZ.cjs');
6
+ const deformation = require('./modern-text._10DVHum.cjs');
7
7
 
8
8
  function createSvgLoader() {
9
9
  const loaded = /* @__PURE__ */ new Map();
@@ -1,7 +1,7 @@
1
1
  import { fonts } from 'modern-font';
2
2
  import { isNone, isGradient, normalizeGradient, clearUndef, Reactivable, normalizeText, getDefaultStyle, property } from 'modern-idoc';
3
3
  import { svgToDom, svgToPath2DSet, Path2DSet, Transform2D, setCanvasContext, Path2D, BoundingBox, Vector2 } from 'modern-path2d';
4
- import { a as definePlugin, b as deformationPlugin } from './modern-text.K8BlyK2j.mjs';
4
+ import { a as definePlugin, b as deformationPlugin } from './modern-text.CdKp2H-o.mjs';
5
5
 
6
6
  function createSvgLoader() {
7
7
  const loaded = /* @__PURE__ */ new Map();
@@ -96,10 +96,19 @@ class Deformer {
96
96
  get characters() {
97
97
  return this.paragraphs.flatMap((p) => p.fragments.flatMap((f) => f.characters));
98
98
  }
99
- constructor({ text, intensities = [], maxFontSize = 100 }) {
99
+ constructor({ text, intensities = [], maxFontSize }) {
100
100
  this.text = text;
101
101
  this.intensities = intensities.map((val) => val / 100);
102
- this.lineHeight = maxFontSize;
102
+ this.lineHeight = this._maxFontSize() || maxFontSize || 100;
103
+ }
104
+ _maxFontSize() {
105
+ let max = 0;
106
+ this.characters.forEach((character) => {
107
+ if (character.glyphBox) {
108
+ max = Math.max(max, character.fontSize);
109
+ }
110
+ });
111
+ return max;
103
112
  }
104
113
  _breakLine() {
105
114
  const isVertical = !this.isHorizontal;
@@ -138,7 +147,7 @@ class Deformer {
138
147
  }
139
148
  character.path.curves.forEach((subPath) => {
140
149
  subPath.curves = subPath.curves.map((curve) => {
141
- if (curve instanceof LineCurve && curve.getLength() > 5) {
150
+ if (curve instanceof LineCurve && curve.getLength() > this.lineHeight * 0.05) {
142
151
  const { p1, p2 } = curve;
143
152
  const res = new QuadraticBezierCurve(
144
153
  p1.clone(),
@@ -274,7 +283,7 @@ class FfdDeformer extends Deformer {
274
283
  if (preset.lineToQuad) {
275
284
  this._lineToQuadraticBezier();
276
285
  }
277
- const [a, b] = this.intensities;
286
+ const [a = 0, b = 0] = this.intensities;
278
287
  const points = this._createFFDControlPoints(preset.hBlocks, preset.vBlocks);
279
288
  preset.build(points, {
280
289
  a,
@@ -1,5 +1,5 @@
1
- import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.DG27jpKj.mjs';
1
+ import { Vector2, Vector2Like, BoundingBox } from 'modern-path2d';
2
+ import { C as Character } from './modern-text.DENkEKJN.cjs';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -97,4 +97,4 @@ interface OffsetPreset extends PresetBase {
97
97
  }
98
98
  type DeformationPreset = FfdPreset | BendPreset | CurvePreset | OffsetPreset;
99
99
 
100
- export type { BendContext as B, CurvePreset as C, DeformationCharInfo as D, FfdContext as F, OffsetPreset as O, VerbatimContext as V, BendPreset as a, DeformationCurve as b, DeformationPreset as c, FfdPreset as d };
100
+ export type { BendContext as B, CurvePreset as C, DeformationPreset as D, FfdContext as F, OffsetPreset as O, VerbatimContext as V, BendPreset as a, DeformationCharInfo as b, DeformationCurve as c, FfdPreset as d };
@@ -1,5 +1,5 @@
1
- import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.DG27jpKj.cjs';
1
+ import { Vector2, Vector2Like, BoundingBox } from 'modern-path2d';
2
+ import { C as Character } from './modern-text.DENkEKJN.mjs';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -97,4 +97,4 @@ interface OffsetPreset extends PresetBase {
97
97
  }
98
98
  type DeformationPreset = FfdPreset | BendPreset | CurvePreset | OffsetPreset;
99
99
 
100
- export type { BendContext as B, CurvePreset as C, DeformationCharInfo as D, FfdContext as F, OffsetPreset as O, VerbatimContext as V, BendPreset as a, DeformationCurve as b, DeformationPreset as c, FfdPreset as d };
100
+ export type { BendContext as B, CurvePreset as C, DeformationPreset as D, FfdContext as F, OffsetPreset as O, VerbatimContext as V, BendPreset as a, DeformationCharInfo as b, DeformationCurve as c, FfdPreset as d };
@@ -1,6 +1,6 @@
1
- import { NormalizedStyle, NormalizedFill, NormalizedOutline, FullStyle, TextObject, ReactivableEvents, Reactivable, NormalizedText, NormalizedEffect, LinearGradientWithType, RadialGradientWithType, NormalizedShadow } from 'modern-idoc';
2
- import { BoundingBox, Path2D, Vector2, Vector2Like, Path2DSet, Path2DStyle } from 'modern-path2d';
1
+ import { NormalizedStyle, NormalizedFill, NormalizedOutline, FullStyle, LinearGradientWithType, RadialGradientWithType, NormalizedEffect, NormalizedShadow, TextObject, ReactivableEvents, Reactivable, NormalizedText } from 'modern-idoc';
3
2
  import { SFNT, Fonts } from 'modern-font';
3
+ import { BoundingBox, Path2D, Vector2, Vector2Like, Path2DStyle, Path2DSet } from 'modern-path2d';
4
4
 
5
5
  declare class Fragment {
6
6
  readonly content: string;
@@ -114,6 +114,40 @@ declare class Character {
114
114
  getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
115
115
  }
116
116
 
117
+ interface DrawShapePathsOptions extends Partial<Path2DStyle> {
118
+ clipRect?: BoundingBox;
119
+ }
120
+ declare class Canvas2DRenderer {
121
+ text: Text;
122
+ context: CanvasRenderingContext2D;
123
+ pixelRatio: number;
124
+ region?: {
125
+ x: number;
126
+ y: number;
127
+ width: number;
128
+ height: number;
129
+ };
130
+ constructor(text: Text, context: CanvasRenderingContext2D);
131
+ protected _setupView: () => void;
132
+ protected _setupColors: () => void;
133
+ setup: () => this;
134
+ protected _parseColor: (source: string | CanvasGradient | CanvasPattern | LinearGradientWithType | RadialGradientWithType, box: BoundingBox) => string | CanvasGradient | CanvasPattern;
135
+ protected _uploadedStyles: string[];
136
+ uploadColor: (box: BoundingBox, ctx: {
137
+ style?: NormalizedStyle;
138
+ fill?: NormalizedFill;
139
+ outline?: NormalizedOutline;
140
+ }) => void;
141
+ protected _mergePathStyle(path: Path2D, style: Partial<Path2DStyle>): Partial<Path2DStyle>;
142
+ drawPath: (path: Path2D, options?: DrawShapePathsOptions) => void;
143
+ effectToPathStyle(effect: NormalizedEffect): Partial<Path2DStyle>;
144
+ transformEffect(effect: NormalizedEffect): void;
145
+ protected _shadowCanvas?: HTMLCanvasElement;
146
+ protected _shadowCtx?: CanvasRenderingContext2D | null;
147
+ drawWithShadow: (shadow: NormalizedShadow, drawFn: () => void) => void;
148
+ drawCharacter: (character: Character, effect?: NormalizedEffect) => void;
149
+ }
150
+
117
151
  /**
118
152
  * A measurer's output: the paragraphs with their four-level boxes filled in place,
119
153
  * plus the overall bounding box. (Formerly `MeasureDomResult`; layout is now
@@ -311,39 +345,5 @@ declare class Paragraph {
311
345
  update(): this;
312
346
  }
313
347
 
314
- interface DrawShapePathsOptions extends Partial<Path2DStyle> {
315
- clipRect?: BoundingBox;
316
- }
317
- declare class Canvas2DRenderer {
318
- text: Text;
319
- context: CanvasRenderingContext2D;
320
- pixelRatio: number;
321
- region?: {
322
- x: number;
323
- y: number;
324
- width: number;
325
- height: number;
326
- };
327
- constructor(text: Text, context: CanvasRenderingContext2D);
328
- protected _setupView: () => void;
329
- protected _setupColors: () => void;
330
- setup: () => this;
331
- protected _parseColor: (source: string | CanvasGradient | CanvasPattern | LinearGradientWithType | RadialGradientWithType, box: BoundingBox) => string | CanvasGradient | CanvasPattern;
332
- protected _uploadedStyles: string[];
333
- uploadColor: (box: BoundingBox, ctx: {
334
- style?: NormalizedStyle;
335
- fill?: NormalizedFill;
336
- outline?: NormalizedOutline;
337
- }) => void;
338
- protected _mergePathStyle(path: Path2D, style: Partial<Path2DStyle>): Partial<Path2DStyle>;
339
- drawPath: (path: Path2D, options?: DrawShapePathsOptions) => void;
340
- effectToPathStyle(effect: NormalizedEffect): Partial<Path2DStyle>;
341
- transformEffect(effect: NormalizedEffect): void;
342
- protected _shadowCanvas?: HTMLCanvasElement;
343
- protected _shadowCtx?: CanvasRenderingContext2D | null;
344
- drawWithShadow: (shadow: NormalizedShadow, drawFn: () => void) => void;
345
- drawCharacter: (character: Character, effect?: NormalizedEffect) => void;
346
- }
347
-
348
- export { Canvas2DRenderer as C, Fragment as F, Paragraph as P, Text as T, Character as a, textDefaultStyle as t };
349
- export type { DrawShapePathsOptions as D, MeasureResult as M, Options as O, RenderOptions as R, MeasurerResult as b, Plugin as c, TextEvents as d, TextMeasurer as e };
348
+ export { Character as C, Fragment as F, Paragraph as a, Text as c, Canvas2DRenderer as d, textDefaultStyle as t };
349
+ export type { DrawShapePathsOptions as D, MeasurerResult as M, Options as O, Plugin as P, RenderOptions as R, TextMeasurer as T, MeasureResult as b, TextEvents as e };
@@ -1,6 +1,6 @@
1
- import { NormalizedStyle, NormalizedFill, NormalizedOutline, FullStyle, TextObject, ReactivableEvents, Reactivable, NormalizedText, NormalizedEffect, LinearGradientWithType, RadialGradientWithType, NormalizedShadow } from 'modern-idoc';
2
- import { BoundingBox, Path2D, Vector2, Vector2Like, Path2DSet, Path2DStyle } from 'modern-path2d';
1
+ import { NormalizedStyle, NormalizedFill, NormalizedOutline, FullStyle, LinearGradientWithType, RadialGradientWithType, NormalizedEffect, NormalizedShadow, TextObject, ReactivableEvents, Reactivable, NormalizedText } from 'modern-idoc';
3
2
  import { SFNT, Fonts } from 'modern-font';
3
+ import { BoundingBox, Path2D, Vector2, Vector2Like, Path2DStyle, Path2DSet } from 'modern-path2d';
4
4
 
5
5
  declare class Fragment {
6
6
  readonly content: string;
@@ -114,6 +114,40 @@ declare class Character {
114
114
  getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
115
115
  }
116
116
 
117
+ interface DrawShapePathsOptions extends Partial<Path2DStyle> {
118
+ clipRect?: BoundingBox;
119
+ }
120
+ declare class Canvas2DRenderer {
121
+ text: Text;
122
+ context: CanvasRenderingContext2D;
123
+ pixelRatio: number;
124
+ region?: {
125
+ x: number;
126
+ y: number;
127
+ width: number;
128
+ height: number;
129
+ };
130
+ constructor(text: Text, context: CanvasRenderingContext2D);
131
+ protected _setupView: () => void;
132
+ protected _setupColors: () => void;
133
+ setup: () => this;
134
+ protected _parseColor: (source: string | CanvasGradient | CanvasPattern | LinearGradientWithType | RadialGradientWithType, box: BoundingBox) => string | CanvasGradient | CanvasPattern;
135
+ protected _uploadedStyles: string[];
136
+ uploadColor: (box: BoundingBox, ctx: {
137
+ style?: NormalizedStyle;
138
+ fill?: NormalizedFill;
139
+ outline?: NormalizedOutline;
140
+ }) => void;
141
+ protected _mergePathStyle(path: Path2D, style: Partial<Path2DStyle>): Partial<Path2DStyle>;
142
+ drawPath: (path: Path2D, options?: DrawShapePathsOptions) => void;
143
+ effectToPathStyle(effect: NormalizedEffect): Partial<Path2DStyle>;
144
+ transformEffect(effect: NormalizedEffect): void;
145
+ protected _shadowCanvas?: HTMLCanvasElement;
146
+ protected _shadowCtx?: CanvasRenderingContext2D | null;
147
+ drawWithShadow: (shadow: NormalizedShadow, drawFn: () => void) => void;
148
+ drawCharacter: (character: Character, effect?: NormalizedEffect) => void;
149
+ }
150
+
117
151
  /**
118
152
  * A measurer's output: the paragraphs with their four-level boxes filled in place,
119
153
  * plus the overall bounding box. (Formerly `MeasureDomResult`; layout is now
@@ -311,39 +345,5 @@ declare class Paragraph {
311
345
  update(): this;
312
346
  }
313
347
 
314
- interface DrawShapePathsOptions extends Partial<Path2DStyle> {
315
- clipRect?: BoundingBox;
316
- }
317
- declare class Canvas2DRenderer {
318
- text: Text;
319
- context: CanvasRenderingContext2D;
320
- pixelRatio: number;
321
- region?: {
322
- x: number;
323
- y: number;
324
- width: number;
325
- height: number;
326
- };
327
- constructor(text: Text, context: CanvasRenderingContext2D);
328
- protected _setupView: () => void;
329
- protected _setupColors: () => void;
330
- setup: () => this;
331
- protected _parseColor: (source: string | CanvasGradient | CanvasPattern | LinearGradientWithType | RadialGradientWithType, box: BoundingBox) => string | CanvasGradient | CanvasPattern;
332
- protected _uploadedStyles: string[];
333
- uploadColor: (box: BoundingBox, ctx: {
334
- style?: NormalizedStyle;
335
- fill?: NormalizedFill;
336
- outline?: NormalizedOutline;
337
- }) => void;
338
- protected _mergePathStyle(path: Path2D, style: Partial<Path2DStyle>): Partial<Path2DStyle>;
339
- drawPath: (path: Path2D, options?: DrawShapePathsOptions) => void;
340
- effectToPathStyle(effect: NormalizedEffect): Partial<Path2DStyle>;
341
- transformEffect(effect: NormalizedEffect): void;
342
- protected _shadowCanvas?: HTMLCanvasElement;
343
- protected _shadowCtx?: CanvasRenderingContext2D | null;
344
- drawWithShadow: (shadow: NormalizedShadow, drawFn: () => void) => void;
345
- drawCharacter: (character: Character, effect?: NormalizedEffect) => void;
346
- }
347
-
348
- export { Canvas2DRenderer as C, Fragment as F, Paragraph as P, Text as T, Character as a, textDefaultStyle as t };
349
- export type { DrawShapePathsOptions as D, MeasureResult as M, Options as O, RenderOptions as R, MeasurerResult as b, Plugin as c, TextEvents as d, TextMeasurer as e };
348
+ export { Character as C, Fragment as F, Paragraph as a, Text as c, Canvas2DRenderer as d, textDefaultStyle as t };
349
+ export type { DrawShapePathsOptions as D, MeasurerResult as M, Options as O, Plugin as P, RenderOptions as R, TextMeasurer as T, MeasureResult as b, TextEvents as e };
@@ -1,6 +1,6 @@
1
- import { NormalizedStyle, NormalizedFill, NormalizedOutline, FullStyle, TextObject, ReactivableEvents, Reactivable, NormalizedText, NormalizedEffect, LinearGradientWithType, RadialGradientWithType, NormalizedShadow } from 'modern-idoc';
2
- import { BoundingBox, Path2D, Vector2, Vector2Like, Path2DSet, Path2DStyle } from 'modern-path2d';
1
+ import { NormalizedStyle, NormalizedFill, NormalizedOutline, FullStyle, LinearGradientWithType, RadialGradientWithType, NormalizedEffect, NormalizedShadow, TextObject, ReactivableEvents, Reactivable, NormalizedText } from 'modern-idoc';
3
2
  import { SFNT, Fonts } from 'modern-font';
3
+ import { BoundingBox, Path2D, Vector2, Vector2Like, Path2DStyle, Path2DSet } from 'modern-path2d';
4
4
 
5
5
  declare class Fragment {
6
6
  readonly content: string;
@@ -114,6 +114,40 @@ declare class Character {
114
114
  getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
115
115
  }
116
116
 
117
+ interface DrawShapePathsOptions extends Partial<Path2DStyle> {
118
+ clipRect?: BoundingBox;
119
+ }
120
+ declare class Canvas2DRenderer {
121
+ text: Text;
122
+ context: CanvasRenderingContext2D;
123
+ pixelRatio: number;
124
+ region?: {
125
+ x: number;
126
+ y: number;
127
+ width: number;
128
+ height: number;
129
+ };
130
+ constructor(text: Text, context: CanvasRenderingContext2D);
131
+ protected _setupView: () => void;
132
+ protected _setupColors: () => void;
133
+ setup: () => this;
134
+ protected _parseColor: (source: string | CanvasGradient | CanvasPattern | LinearGradientWithType | RadialGradientWithType, box: BoundingBox) => string | CanvasGradient | CanvasPattern;
135
+ protected _uploadedStyles: string[];
136
+ uploadColor: (box: BoundingBox, ctx: {
137
+ style?: NormalizedStyle;
138
+ fill?: NormalizedFill;
139
+ outline?: NormalizedOutline;
140
+ }) => void;
141
+ protected _mergePathStyle(path: Path2D, style: Partial<Path2DStyle>): Partial<Path2DStyle>;
142
+ drawPath: (path: Path2D, options?: DrawShapePathsOptions) => void;
143
+ effectToPathStyle(effect: NormalizedEffect): Partial<Path2DStyle>;
144
+ transformEffect(effect: NormalizedEffect): void;
145
+ protected _shadowCanvas?: HTMLCanvasElement;
146
+ protected _shadowCtx?: CanvasRenderingContext2D | null;
147
+ drawWithShadow: (shadow: NormalizedShadow, drawFn: () => void) => void;
148
+ drawCharacter: (character: Character, effect?: NormalizedEffect) => void;
149
+ }
150
+
117
151
  /**
118
152
  * A measurer's output: the paragraphs with their four-level boxes filled in place,
119
153
  * plus the overall bounding box. (Formerly `MeasureDomResult`; layout is now
@@ -311,39 +345,5 @@ declare class Paragraph {
311
345
  update(): this;
312
346
  }
313
347
 
314
- interface DrawShapePathsOptions extends Partial<Path2DStyle> {
315
- clipRect?: BoundingBox;
316
- }
317
- declare class Canvas2DRenderer {
318
- text: Text;
319
- context: CanvasRenderingContext2D;
320
- pixelRatio: number;
321
- region?: {
322
- x: number;
323
- y: number;
324
- width: number;
325
- height: number;
326
- };
327
- constructor(text: Text, context: CanvasRenderingContext2D);
328
- protected _setupView: () => void;
329
- protected _setupColors: () => void;
330
- setup: () => this;
331
- protected _parseColor: (source: string | CanvasGradient | CanvasPattern | LinearGradientWithType | RadialGradientWithType, box: BoundingBox) => string | CanvasGradient | CanvasPattern;
332
- protected _uploadedStyles: string[];
333
- uploadColor: (box: BoundingBox, ctx: {
334
- style?: NormalizedStyle;
335
- fill?: NormalizedFill;
336
- outline?: NormalizedOutline;
337
- }) => void;
338
- protected _mergePathStyle(path: Path2D, style: Partial<Path2DStyle>): Partial<Path2DStyle>;
339
- drawPath: (path: Path2D, options?: DrawShapePathsOptions) => void;
340
- effectToPathStyle(effect: NormalizedEffect): Partial<Path2DStyle>;
341
- transformEffect(effect: NormalizedEffect): void;
342
- protected _shadowCanvas?: HTMLCanvasElement;
343
- protected _shadowCtx?: CanvasRenderingContext2D | null;
344
- drawWithShadow: (shadow: NormalizedShadow, drawFn: () => void) => void;
345
- drawCharacter: (character: Character, effect?: NormalizedEffect) => void;
346
- }
347
-
348
- export { Canvas2DRenderer as C, Fragment as F, Paragraph as P, Text as T, Character as a, textDefaultStyle as t };
349
- export type { DrawShapePathsOptions as D, MeasureResult as M, Options as O, RenderOptions as R, MeasurerResult as b, Plugin as c, TextEvents as d, TextMeasurer as e };
348
+ export { Character as C, Fragment as F, Paragraph as a, Text as c, Canvas2DRenderer as d, textDefaultStyle as t };
349
+ export type { DrawShapePathsOptions as D, MeasurerResult as M, Options as O, Plugin as P, RenderOptions as R, TextMeasurer as T, MeasureResult as b, TextEvents as e };
@@ -98,10 +98,19 @@ class Deformer {
98
98
  get characters() {
99
99
  return this.paragraphs.flatMap((p) => p.fragments.flatMap((f) => f.characters));
100
100
  }
101
- constructor({ text, intensities = [], maxFontSize = 100 }) {
101
+ constructor({ text, intensities = [], maxFontSize }) {
102
102
  this.text = text;
103
103
  this.intensities = intensities.map((val) => val / 100);
104
- this.lineHeight = maxFontSize;
104
+ this.lineHeight = this._maxFontSize() || maxFontSize || 100;
105
+ }
106
+ _maxFontSize() {
107
+ let max = 0;
108
+ this.characters.forEach((character) => {
109
+ if (character.glyphBox) {
110
+ max = Math.max(max, character.fontSize);
111
+ }
112
+ });
113
+ return max;
105
114
  }
106
115
  _breakLine() {
107
116
  const isVertical = !this.isHorizontal;
@@ -140,7 +149,7 @@ class Deformer {
140
149
  }
141
150
  character.path.curves.forEach((subPath) => {
142
151
  subPath.curves = subPath.curves.map((curve) => {
143
- if (curve instanceof modernPath2d.LineCurve && curve.getLength() > 5) {
152
+ if (curve instanceof modernPath2d.LineCurve && curve.getLength() > this.lineHeight * 0.05) {
144
153
  const { p1, p2 } = curve;
145
154
  const res = new modernPath2d.QuadraticBezierCurve(
146
155
  p1.clone(),
@@ -276,7 +285,7 @@ class FfdDeformer extends Deformer {
276
285
  if (preset.lineToQuad) {
277
286
  this._lineToQuadraticBezier();
278
287
  }
279
- const [a, b] = this.intensities;
288
+ const [a = 0, b = 0] = this.intensities;
280
289
  const points = this._createFFDControlPoints(preset.hBlocks, preset.vBlocks);
281
290
  preset.build(points, {
282
291
  a,
@@ -2,10 +2,10 @@
2
2
 
3
3
  const diff = require('diff');
4
4
  const modernIdoc = require('modern-idoc');
5
- const Text = require('../shared/modern-text.BBDyCm63.cjs');
5
+ const Text = require('../shared/modern-text.BAnUZM0U.cjs');
6
6
  require('modern-font');
7
7
  require('modern-path2d');
8
- require('../shared/modern-text.DQWdaYoZ.cjs');
8
+ require('../shared/modern-text._10DVHum.cjs');
9
9
 
10
10
  var __defProp = Object.defineProperty;
11
11
  var __decorateClass = (decorators, target, key, kind) => {
@@ -1,7 +1,7 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.DG27jpKj.cjs';
3
- import 'modern-path2d';
2
+ import { c as Text } from '../shared/modern-text.DENkEKJN.cjs';
4
3
  import 'modern-font';
4
+ import 'modern-path2d';
5
5
 
6
6
  interface IndexCharacter {
7
7
  paragraphIndex: number;
@@ -1,7 +1,7 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.DG27jpKj.mjs';
3
- import 'modern-path2d';
2
+ import { c as Text } from '../shared/modern-text.DENkEKJN.mjs';
4
3
  import 'modern-font';
4
+ import 'modern-path2d';
5
5
 
6
6
  interface IndexCharacter {
7
7
  paragraphIndex: number;
@@ -1,7 +1,7 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.DG27jpKj.js';
3
- import 'modern-path2d';
2
+ import { c as Text } from '../shared/modern-text.DENkEKJN.js';
4
3
  import 'modern-font';
4
+ import 'modern-path2d';
5
5
 
6
6
  interface IndexCharacter {
7
7
  paragraphIndex: number;
@@ -1,9 +1,9 @@
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.DNvXuVjw.mjs';
3
+ import { T as Text } from '../shared/modern-text.BdF52nXP.mjs';
4
4
  import 'modern-font';
5
5
  import 'modern-path2d';
6
- import '../shared/modern-text.K8BlyK2j.mjs';
6
+ import '../shared/modern-text.CdKp2H-o.mjs';
7
7
 
8
8
  var __defProp = Object.defineProperty;
9
9
  var __decorateClass = (decorators, target, key, kind) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-text",
3
3
  "type": "module",
4
- "version": "2.1.0",
4
+ "version": "2.1.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,19 +60,19 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "diff": "^9.0.0",
63
- "modern-font": "^0.6.0",
64
- "modern-idoc": "^0.12.1",
65
- "modern-path2d": "^1.7.0"
63
+ "modern-font": "^0.6.2",
64
+ "modern-idoc": "^0.12.3",
65
+ "modern-path2d": "^1.8.6"
66
66
  },
67
67
  "devDependencies": {
68
- "@antfu/eslint-config": "^9.0.0",
69
- "@types/node": "^25.9.1",
68
+ "@antfu/eslint-config": "^9.1.0",
69
+ "@types/node": "^26.0.1",
70
70
  "bumpp": "^11.1.0",
71
71
  "conventional-changelog-cli": "^5.0.0",
72
- "eslint": "^10.4.0",
72
+ "eslint": "^10.6.0",
73
73
  "typescript": "^6.0.3",
74
74
  "unbuild": "^3.6.1",
75
- "vite": "^8.0.14",
76
- "vitest": "^4.1.7"
75
+ "vite": "^8.1.2",
76
+ "vitest": "^4.1.9"
77
77
  }
78
78
  }