modern-text 0.2.2 → 0.2.4

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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { Sfnt } from 'modern-font';
1
+ import { BoundingBox, Path2D, Point2D } from 'modern-path2d';
2
+ import { GlyphPathCommand, Sfnt } from 'modern-font';
2
3
  export * from 'modern-font';
3
- import { BoundingBox, Path2D } from 'modern-path2d';
4
4
 
5
5
  type WritingMode = 'horizontal-tb' | 'vertical-lr' | 'vertical-rl';
6
6
  type TextOrientation = 'mixed' | 'upright' | 'sideways-right' | 'sideways';
@@ -52,14 +52,32 @@ type TextEffect = Partial<TextDrawStyle & {
52
52
  offsetX: number;
53
53
  offsetY: number;
54
54
  }>;
55
- interface TextDeformation {
56
- type: string;
57
- intensities?: number[];
58
- }
55
+ type TextDeformation = () => void;
59
56
  interface FragmentHighlight {
60
57
  url: string;
61
58
  }
62
59
 
60
+ declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
61
+ declare function uploadColor(style: Partial<TextDrawStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
62
+ interface LinearGradient {
63
+ x0: number;
64
+ y0: number;
65
+ x1: number;
66
+ y1: number;
67
+ stops: {
68
+ offset: number;
69
+ color: string;
70
+ }[];
71
+ }
72
+
73
+ interface DrawShapePathsOptions extends Partial<TextEffect> {
74
+ ctx: CanvasRenderingContext2D;
75
+ paths: Path2D[];
76
+ fontSize: number;
77
+ fill?: boolean;
78
+ }
79
+ declare function drawPaths(options: DrawShapePathsOptions): void;
80
+
63
81
  declare class Fragment {
64
82
  content: string;
65
83
  style: Partial<TextStyle>;
@@ -82,7 +100,7 @@ declare class Character {
82
100
  path: Path2D<any>;
83
101
  textWidth: number;
84
102
  textHeight: number;
85
- font: Sfnt;
103
+ commands: GlyphPathCommand[];
86
104
  glyphHeight: number;
87
105
  glyphWidth: number;
88
106
  underlinePosition: number;
@@ -100,10 +118,24 @@ declare class Character {
100
118
  get isVertical(): boolean;
101
119
  get fontSize(): number;
102
120
  constructor(content: string, index: number, parent: Fragment);
103
- protected _updateFont(): this;
121
+ protected _font(): Sfnt | undefined;
104
122
  protected _updateGlyph(font: Sfnt): this;
123
+ protected _decoration(): GlyphPathCommand[];
124
+ protected _transform(commands: GlyphPathCommand[], cb: (x: number, y: number) => number[]): GlyphPathCommand[];
125
+ protected _italic(commands: GlyphPathCommand[], startPoint?: {
126
+ x: number;
127
+ y: number;
128
+ }): GlyphPathCommand[];
129
+ protected _rotation90(commands: GlyphPathCommand[], point: {
130
+ x: number;
131
+ y: number;
132
+ }): GlyphPathCommand[];
105
133
  updatePath(): this;
106
134
  update(): this;
135
+ getMinMax(min?: Point2D, max?: Point2D): {
136
+ min: Point2D;
137
+ max: Point2D;
138
+ };
107
139
  drawTo(ctx: CanvasRenderingContext2D, config?: Partial<TextEffect>): void;
108
140
  }
109
141
 
@@ -118,6 +150,66 @@ declare class Paragraph {
118
150
  addFragment(content: string, style?: Partial<TextStyle>): Fragment;
119
151
  }
120
152
 
153
+ interface TextRenderOptions {
154
+ view: HTMLCanvasElement;
155
+ pixelRatio?: number;
156
+ }
157
+ interface TextOptions {
158
+ content?: TextContent;
159
+ style?: Partial<TextStyle>;
160
+ effects?: TextEffect[];
161
+ deformation?: TextDeformation;
162
+ measureDom?: HTMLElement;
163
+ }
164
+ declare const defaultTextStyles: TextStyle;
165
+ declare class Text {
166
+ content: TextContent;
167
+ style: Partial<TextStyle>;
168
+ effects?: TextEffect[];
169
+ deformation?: TextDeformation;
170
+ measureDom?: HTMLElement;
171
+ needsUpdate: boolean;
172
+ computedStyle: {
173
+ writingMode: WritingMode;
174
+ textOrientation: TextOrientation;
175
+ fontSize: number;
176
+ fontWeight: FontWeight;
177
+ fontFamily: string;
178
+ fontStyle: FontStyle;
179
+ fontKerning: FontKerning;
180
+ textWrap: TextWrap;
181
+ textAlign: TextAlign;
182
+ verticalAlign: VerticalAlign;
183
+ textTransform: TextTransform;
184
+ lineHeight: number;
185
+ letterSpacing: number;
186
+ color: string | CanvasGradient | CanvasPattern;
187
+ backgroundColor: string | CanvasGradient | CanvasPattern;
188
+ textStrokeWidth: number;
189
+ textStrokeColor: string | CanvasGradient | CanvasPattern;
190
+ textDecoration: TextDecoration;
191
+ shadowColor: string;
192
+ shadowOffsetX: number;
193
+ shadowOffsetY: number;
194
+ shadowBlur: number;
195
+ };
196
+ paragraphs: Paragraph[];
197
+ boundingBox: BoundingBox;
198
+ renderBoundingBox: BoundingBox;
199
+ protected _parser: Parser;
200
+ protected _measurer: Measurer;
201
+ protected _deformer: Deformer;
202
+ protected _effector: Effector;
203
+ protected _highlighter: Highlighter;
204
+ protected _renderer2D: Renderer2D;
205
+ get characters(): Character[];
206
+ constructor(options?: TextOptions);
207
+ measure(dom?: HTMLElement | undefined): MeasuredResult;
208
+ requestUpdate(): this;
209
+ update(): this;
210
+ render(options: TextRenderOptions): this;
211
+ }
212
+
121
213
  declare class Feature {
122
214
  _text: Text;
123
215
  constructor(_text: Text);
@@ -190,16 +282,14 @@ interface MeasuredResult {
190
282
  declare class Measurer extends Feature {
191
283
  protected _styleToDomStyle(style: Partial<TextStyle>): Record<string, any>;
192
284
  /**
193
- * <div style="...">
285
+ * <section style="...">
194
286
  * <ul>
195
287
  * <li style="...">
196
- * <div>
197
- * <span style="...">...</span>
198
- * <span>...</span>
199
- * </div>
288
+ * <span style="...">...</span>
289
+ * <span>...</span>
200
290
  * </li>
201
291
  * </ul>
202
- * </div>
292
+ * </section>
203
293
  */
204
294
  createDom(): {
205
295
  dom: HTMLElement;
@@ -218,6 +308,9 @@ declare class Parser extends Feature {
218
308
  parse(): Paragraph[];
219
309
  }
220
310
 
311
+ declare class Reflector extends Feature {
312
+ }
313
+
221
314
  interface Render2dOptions {
222
315
  pixelRatio: number;
223
316
  ctx: CanvasRenderingContext2D;
@@ -229,62 +322,28 @@ declare class Renderer2D extends Feature {
229
322
  draw(options: Pick<Render2dOptions, 'ctx'>): this;
230
323
  }
231
324
 
232
- interface TextRenderOptions {
233
- view: HTMLCanvasElement;
234
- pixelRatio?: number;
235
- }
236
- interface TextOptions {
237
- content?: TextContent;
238
- style?: Partial<TextStyle>;
239
- effects?: TextEffect[];
240
- deformation?: TextDeformation;
241
- }
242
- declare const defaultTextStyles: TextStyle;
243
- declare class Text {
244
- content: TextContent;
245
- style: Partial<TextStyle>;
246
- effects?: TextEffect[];
247
- deformation?: TextDeformation;
248
- needsUpdate: boolean;
249
- computedStyle: {
250
- writingMode: WritingMode;
251
- textOrientation: TextOrientation;
252
- fontSize: number;
253
- fontWeight: FontWeight;
254
- fontFamily: string;
255
- fontStyle: FontStyle;
256
- fontKerning: FontKerning;
257
- textWrap: TextWrap;
258
- textAlign: TextAlign;
259
- verticalAlign: VerticalAlign;
260
- textTransform: TextTransform;
261
- lineHeight: number;
262
- letterSpacing: number;
263
- color: string | CanvasGradient | CanvasPattern;
264
- backgroundColor: string | CanvasGradient | CanvasPattern;
265
- textStrokeWidth: number;
266
- textStrokeColor: string | CanvasGradient | CanvasPattern;
267
- textDecoration: TextDecoration;
268
- shadowColor: string;
269
- shadowOffsetX: number;
270
- shadowOffsetY: number;
271
- shadowBlur: number;
272
- };
273
- paragraphs: Paragraph[];
274
- boundingBox: BoundingBox;
275
- renderBoundingBox: BoundingBox;
276
- protected _parser: Parser;
277
- protected _measurer: Measurer;
278
- protected _deformer: Deformer;
279
- protected _effector: Effector;
280
- protected _highlighter: Highlighter;
281
- protected _renderer2D: Renderer2D;
282
- get characters(): Character[];
283
- constructor(options?: TextOptions);
284
- measure(dom?: HTMLElement): MeasuredResult;
285
- requestUpdate(): this;
286
- update(): this;
287
- render(options: TextRenderOptions): this;
288
- }
325
+ declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
326
+ declare function getRotationPoint(point: any, rotation: number): {
327
+ x: number;
328
+ y: number;
329
+ };
330
+ declare function getSkewPoint(point: any, startPoint: any, skewX: number, skewY: number): {
331
+ x: number;
332
+ y: number;
333
+ };
334
+ declare function getScalePoint(point: any, startPoint: any, scaleX: number, scaleY: number): {
335
+ x: number;
336
+ y: number;
337
+ };
338
+ declare function getPointPosition(point: {
339
+ x: number;
340
+ y: number;
341
+ }, startPoint: {
342
+ x: number;
343
+ y: number;
344
+ }, rotation?: number, skewX?: number, skewY?: number, scaleX?: number, scaleY?: number): {
345
+ x: number;
346
+ y: number;
347
+ };
289
348
 
290
- export { Text, type TextOptions, type TextRenderOptions, defaultTextStyles };
349
+ export { Character, Deformer, type DrawShapePathsOptions, type EffectOptions, Effector, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type FragmentHighlight, Highlighter, type LinearGradient, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, type MeasuredResult, Measurer, Paragraph, type ParagraphContent, Parser, Reflector, type Render2dOptions, Renderer2D, Text, type TextAlign, type TextContent, type TextDecoration, type TextDeformation, type TextDrawStyle, type TextEffect, type TextLayoutStyle, type TextOptions, type TextOrientation, type TextRenderOptions, type TextStyle, type TextTransform, type TextWrap, type VerticalAlign, type WritingMode, defaultTextStyles, drawPaths, filterEmpty, getPointPosition, getRotationPoint, getScalePoint, getSkewPoint, parseColor, uploadColor };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { Sfnt } from 'modern-font';
1
+ import { BoundingBox, Path2D, Point2D } from 'modern-path2d';
2
+ import { GlyphPathCommand, Sfnt } from 'modern-font';
2
3
  export * from 'modern-font';
3
- import { BoundingBox, Path2D } from 'modern-path2d';
4
4
 
5
5
  type WritingMode = 'horizontal-tb' | 'vertical-lr' | 'vertical-rl';
6
6
  type TextOrientation = 'mixed' | 'upright' | 'sideways-right' | 'sideways';
@@ -52,14 +52,32 @@ type TextEffect = Partial<TextDrawStyle & {
52
52
  offsetX: number;
53
53
  offsetY: number;
54
54
  }>;
55
- interface TextDeformation {
56
- type: string;
57
- intensities?: number[];
58
- }
55
+ type TextDeformation = () => void;
59
56
  interface FragmentHighlight {
60
57
  url: string;
61
58
  }
62
59
 
60
+ declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
61
+ declare function uploadColor(style: Partial<TextDrawStyle>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
62
+ interface LinearGradient {
63
+ x0: number;
64
+ y0: number;
65
+ x1: number;
66
+ y1: number;
67
+ stops: {
68
+ offset: number;
69
+ color: string;
70
+ }[];
71
+ }
72
+
73
+ interface DrawShapePathsOptions extends Partial<TextEffect> {
74
+ ctx: CanvasRenderingContext2D;
75
+ paths: Path2D[];
76
+ fontSize: number;
77
+ fill?: boolean;
78
+ }
79
+ declare function drawPaths(options: DrawShapePathsOptions): void;
80
+
63
81
  declare class Fragment {
64
82
  content: string;
65
83
  style: Partial<TextStyle>;
@@ -82,7 +100,7 @@ declare class Character {
82
100
  path: Path2D<any>;
83
101
  textWidth: number;
84
102
  textHeight: number;
85
- font: Sfnt;
103
+ commands: GlyphPathCommand[];
86
104
  glyphHeight: number;
87
105
  glyphWidth: number;
88
106
  underlinePosition: number;
@@ -100,10 +118,24 @@ declare class Character {
100
118
  get isVertical(): boolean;
101
119
  get fontSize(): number;
102
120
  constructor(content: string, index: number, parent: Fragment);
103
- protected _updateFont(): this;
121
+ protected _font(): Sfnt | undefined;
104
122
  protected _updateGlyph(font: Sfnt): this;
123
+ protected _decoration(): GlyphPathCommand[];
124
+ protected _transform(commands: GlyphPathCommand[], cb: (x: number, y: number) => number[]): GlyphPathCommand[];
125
+ protected _italic(commands: GlyphPathCommand[], startPoint?: {
126
+ x: number;
127
+ y: number;
128
+ }): GlyphPathCommand[];
129
+ protected _rotation90(commands: GlyphPathCommand[], point: {
130
+ x: number;
131
+ y: number;
132
+ }): GlyphPathCommand[];
105
133
  updatePath(): this;
106
134
  update(): this;
135
+ getMinMax(min?: Point2D, max?: Point2D): {
136
+ min: Point2D;
137
+ max: Point2D;
138
+ };
107
139
  drawTo(ctx: CanvasRenderingContext2D, config?: Partial<TextEffect>): void;
108
140
  }
109
141
 
@@ -118,6 +150,66 @@ declare class Paragraph {
118
150
  addFragment(content: string, style?: Partial<TextStyle>): Fragment;
119
151
  }
120
152
 
153
+ interface TextRenderOptions {
154
+ view: HTMLCanvasElement;
155
+ pixelRatio?: number;
156
+ }
157
+ interface TextOptions {
158
+ content?: TextContent;
159
+ style?: Partial<TextStyle>;
160
+ effects?: TextEffect[];
161
+ deformation?: TextDeformation;
162
+ measureDom?: HTMLElement;
163
+ }
164
+ declare const defaultTextStyles: TextStyle;
165
+ declare class Text {
166
+ content: TextContent;
167
+ style: Partial<TextStyle>;
168
+ effects?: TextEffect[];
169
+ deformation?: TextDeformation;
170
+ measureDom?: HTMLElement;
171
+ needsUpdate: boolean;
172
+ computedStyle: {
173
+ writingMode: WritingMode;
174
+ textOrientation: TextOrientation;
175
+ fontSize: number;
176
+ fontWeight: FontWeight;
177
+ fontFamily: string;
178
+ fontStyle: FontStyle;
179
+ fontKerning: FontKerning;
180
+ textWrap: TextWrap;
181
+ textAlign: TextAlign;
182
+ verticalAlign: VerticalAlign;
183
+ textTransform: TextTransform;
184
+ lineHeight: number;
185
+ letterSpacing: number;
186
+ color: string | CanvasGradient | CanvasPattern;
187
+ backgroundColor: string | CanvasGradient | CanvasPattern;
188
+ textStrokeWidth: number;
189
+ textStrokeColor: string | CanvasGradient | CanvasPattern;
190
+ textDecoration: TextDecoration;
191
+ shadowColor: string;
192
+ shadowOffsetX: number;
193
+ shadowOffsetY: number;
194
+ shadowBlur: number;
195
+ };
196
+ paragraphs: Paragraph[];
197
+ boundingBox: BoundingBox;
198
+ renderBoundingBox: BoundingBox;
199
+ protected _parser: Parser;
200
+ protected _measurer: Measurer;
201
+ protected _deformer: Deformer;
202
+ protected _effector: Effector;
203
+ protected _highlighter: Highlighter;
204
+ protected _renderer2D: Renderer2D;
205
+ get characters(): Character[];
206
+ constructor(options?: TextOptions);
207
+ measure(dom?: HTMLElement | undefined): MeasuredResult;
208
+ requestUpdate(): this;
209
+ update(): this;
210
+ render(options: TextRenderOptions): this;
211
+ }
212
+
121
213
  declare class Feature {
122
214
  _text: Text;
123
215
  constructor(_text: Text);
@@ -190,16 +282,14 @@ interface MeasuredResult {
190
282
  declare class Measurer extends Feature {
191
283
  protected _styleToDomStyle(style: Partial<TextStyle>): Record<string, any>;
192
284
  /**
193
- * <div style="...">
285
+ * <section style="...">
194
286
  * <ul>
195
287
  * <li style="...">
196
- * <div>
197
- * <span style="...">...</span>
198
- * <span>...</span>
199
- * </div>
288
+ * <span style="...">...</span>
289
+ * <span>...</span>
200
290
  * </li>
201
291
  * </ul>
202
- * </div>
292
+ * </section>
203
293
  */
204
294
  createDom(): {
205
295
  dom: HTMLElement;
@@ -218,6 +308,9 @@ declare class Parser extends Feature {
218
308
  parse(): Paragraph[];
219
309
  }
220
310
 
311
+ declare class Reflector extends Feature {
312
+ }
313
+
221
314
  interface Render2dOptions {
222
315
  pixelRatio: number;
223
316
  ctx: CanvasRenderingContext2D;
@@ -229,62 +322,28 @@ declare class Renderer2D extends Feature {
229
322
  draw(options: Pick<Render2dOptions, 'ctx'>): this;
230
323
  }
231
324
 
232
- interface TextRenderOptions {
233
- view: HTMLCanvasElement;
234
- pixelRatio?: number;
235
- }
236
- interface TextOptions {
237
- content?: TextContent;
238
- style?: Partial<TextStyle>;
239
- effects?: TextEffect[];
240
- deformation?: TextDeformation;
241
- }
242
- declare const defaultTextStyles: TextStyle;
243
- declare class Text {
244
- content: TextContent;
245
- style: Partial<TextStyle>;
246
- effects?: TextEffect[];
247
- deformation?: TextDeformation;
248
- needsUpdate: boolean;
249
- computedStyle: {
250
- writingMode: WritingMode;
251
- textOrientation: TextOrientation;
252
- fontSize: number;
253
- fontWeight: FontWeight;
254
- fontFamily: string;
255
- fontStyle: FontStyle;
256
- fontKerning: FontKerning;
257
- textWrap: TextWrap;
258
- textAlign: TextAlign;
259
- verticalAlign: VerticalAlign;
260
- textTransform: TextTransform;
261
- lineHeight: number;
262
- letterSpacing: number;
263
- color: string | CanvasGradient | CanvasPattern;
264
- backgroundColor: string | CanvasGradient | CanvasPattern;
265
- textStrokeWidth: number;
266
- textStrokeColor: string | CanvasGradient | CanvasPattern;
267
- textDecoration: TextDecoration;
268
- shadowColor: string;
269
- shadowOffsetX: number;
270
- shadowOffsetY: number;
271
- shadowBlur: number;
272
- };
273
- paragraphs: Paragraph[];
274
- boundingBox: BoundingBox;
275
- renderBoundingBox: BoundingBox;
276
- protected _parser: Parser;
277
- protected _measurer: Measurer;
278
- protected _deformer: Deformer;
279
- protected _effector: Effector;
280
- protected _highlighter: Highlighter;
281
- protected _renderer2D: Renderer2D;
282
- get characters(): Character[];
283
- constructor(options?: TextOptions);
284
- measure(dom?: HTMLElement): MeasuredResult;
285
- requestUpdate(): this;
286
- update(): this;
287
- render(options: TextRenderOptions): this;
288
- }
325
+ declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
326
+ declare function getRotationPoint(point: any, rotation: number): {
327
+ x: number;
328
+ y: number;
329
+ };
330
+ declare function getSkewPoint(point: any, startPoint: any, skewX: number, skewY: number): {
331
+ x: number;
332
+ y: number;
333
+ };
334
+ declare function getScalePoint(point: any, startPoint: any, scaleX: number, scaleY: number): {
335
+ x: number;
336
+ y: number;
337
+ };
338
+ declare function getPointPosition(point: {
339
+ x: number;
340
+ y: number;
341
+ }, startPoint: {
342
+ x: number;
343
+ y: number;
344
+ }, rotation?: number, skewX?: number, skewY?: number, scaleX?: number, scaleY?: number): {
345
+ x: number;
346
+ y: number;
347
+ };
289
348
 
290
- export { Text, type TextOptions, type TextRenderOptions, defaultTextStyles };
349
+ export { Character, Deformer, type DrawShapePathsOptions, type EffectOptions, Effector, type FontKerning, type FontStyle, type FontWeight, Fragment, type FragmentContent, type FragmentHighlight, Highlighter, type LinearGradient, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, type MeasuredResult, Measurer, Paragraph, type ParagraphContent, Parser, Reflector, type Render2dOptions, Renderer2D, Text, type TextAlign, type TextContent, type TextDecoration, type TextDeformation, type TextDrawStyle, type TextEffect, type TextLayoutStyle, type TextOptions, type TextOrientation, type TextRenderOptions, type TextStyle, type TextTransform, type TextWrap, type VerticalAlign, type WritingMode, defaultTextStyles, drawPaths, filterEmpty, getPointPosition, getRotationPoint, getScalePoint, getSkewPoint, parseColor, uploadColor };