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.cjs CHANGED
@@ -63,6 +63,8 @@ function drawPath(options) {
63
63
  fill: options.color ?? pathStyle.fill,
64
64
  stroke: options.textStrokeColor ?? pathStyle.stroke,
65
65
  strokeWidth: options.textStrokeWidth ? options.textStrokeWidth * fontSize : pathStyle.strokeWidth,
66
+ strokeLinecap: "round",
67
+ strokeLinejoin: "round",
66
68
  shadowOffsetX: (options.shadowOffsetX ?? 0) * fontSize,
67
69
  shadowOffsetY: (options.shadowOffsetY ?? 0) * fontSize,
68
70
  shadowBlur: (options.shadowBlur ?? 0) * fontSize,
@@ -253,7 +255,7 @@ class Character {
253
255
  if (Math.abs(advanceWidth - advanceHeight) > 0.1) {
254
256
  y -= (ascender - typoAscender) / (ascender + Math.abs(descender)) * advanceHeight;
255
257
  }
256
- glyphIndex = undefined;
258
+ glyphIndex = void 0;
257
259
  }
258
260
  if (isVertical && !set1.has(content) && (content.codePointAt(0) <= 256 || set2.has(content))) {
259
261
  path.addCommands(
@@ -274,12 +276,12 @@ class Character {
274
276
  isVertical ? {
275
277
  x: point.x,
276
278
  y: top - (advanceHeight - advanceWidth) / 2 + baseline
277
- } : undefined
279
+ } : void 0
278
280
  );
279
281
  }
280
282
  path.rotate(90, point);
281
283
  } else {
282
- if (glyphIndex !== undefined) {
284
+ if (glyphIndex !== void 0) {
283
285
  path.addCommands(
284
286
  sfnt.glyphs.get(glyphIndex).getPathCommands(x, y, style.fontSize)
285
287
  );
@@ -289,7 +291,7 @@ class Character {
289
291
  isVertical ? {
290
292
  x: x + advanceWidth / 2,
291
293
  y: top + typoAscender / (ascender + Math.abs(descender)) * advanceHeight
292
- } : undefined
294
+ } : void 0
293
295
  );
294
296
  }
295
297
  } else {
@@ -297,7 +299,7 @@ class Character {
297
299
  if (needsItalic) {
298
300
  this._italic(
299
301
  path,
300
- isVertical ? { x: x + advanceHeight / 2, y } : undefined
302
+ isVertical ? { x: x + advanceHeight / 2, y } : void 0
301
303
  );
302
304
  }
303
305
  }
@@ -325,13 +327,13 @@ class Character {
325
327
  if (this.path.curves[0]?.curves.length) {
326
328
  return this.path.getMinMax(min, max, withStyle);
327
329
  } else {
328
- return undefined;
330
+ return void 0;
329
331
  }
330
332
  }
331
333
  getGlyphBoundingBox(withStyle) {
332
- const minMax = this.getGlyphMinMax(undefined, undefined, withStyle);
334
+ const minMax = this.getGlyphMinMax(void 0, void 0, withStyle);
333
335
  if (!minMax) {
334
- return undefined;
336
+ return void 0;
335
337
  }
336
338
  const { min, max } = minMax;
337
339
  return new modernPath2d.BoundingBox(min.x, min.y, max.x - min.x, max.y - min.y);
@@ -445,7 +447,7 @@ function filterEmpty(val) {
445
447
  return val;
446
448
  const res = {};
447
449
  for (const key in val) {
448
- if (val[key] !== "" && val[key] !== undefined) {
450
+ if (val[key] !== "" && val[key] !== void 0) {
449
451
  res[key] = val[key];
450
452
  }
451
453
  }
@@ -589,7 +591,7 @@ class Measurer {
589
591
  const isFlex = Boolean(style.justifyContent || style.alignItems);
590
592
  Object.assign(dom.style, {
591
593
  boxSizing: "border-box",
592
- display: isFlex ? "inline-flex" : undefined,
594
+ display: isFlex ? "inline-flex" : void 0,
593
595
  width: "max-content",
594
596
  height: "max-content",
595
597
  whiteSpace: "pre-wrap",
@@ -604,8 +606,8 @@ class Measurer {
604
606
  listStyleType: "inherit",
605
607
  padding: "0",
606
608
  margin: "0",
607
- width: isFlex && isHorizontal ? "100%" : undefined,
608
- height: isFlex && !isHorizontal ? "100%" : undefined
609
+ width: isFlex && isHorizontal ? "100%" : void 0,
610
+ height: isFlex && !isHorizontal ? "100%" : void 0
609
611
  });
610
612
  paragraphs.forEach((paragraph) => {
611
613
  const li = document.createElement("li");
@@ -658,7 +660,7 @@ class Measurer {
658
660
  width: rect.width
659
661
  };
660
662
  }
661
- return undefined;
663
+ return void 0;
662
664
  }).filter(Boolean);
663
665
  }
664
666
  measureDom(dom) {
@@ -871,6 +873,13 @@ class EventEmitter {
871
873
  }
872
874
  }
873
875
 
876
+ function background() {
877
+ return {
878
+ name: "background"
879
+ // TODO
880
+ };
881
+ }
882
+
874
883
  function getHighlightStyle(style) {
875
884
  const {
876
885
  highlight: highlight2,
@@ -1242,6 +1251,13 @@ function listStyle() {
1242
1251
  });
1243
1252
  }
1244
1253
 
1254
+ function outline() {
1255
+ return {
1256
+ name: "outline"
1257
+ // TODO
1258
+ };
1259
+ }
1260
+
1245
1261
  const tempV1 = new modernPath2d.Vector2();
1246
1262
  const tempM1 = new modernPath2d.Matrix3();
1247
1263
  const tempM2 = new modernPath2d.Matrix3();
@@ -1276,7 +1292,7 @@ function render() {
1276
1292
  boxes.push(aabb);
1277
1293
  });
1278
1294
  });
1279
- return boxes.length ? modernPath2d.BoundingBox.from(...boxes) : undefined;
1295
+ return boxes.length ? modernPath2d.BoundingBox.from(...boxes) : void 0;
1280
1296
  },
1281
1297
  render: (ctx, text) => {
1282
1298
  const { paragraphs, glyphBox, effects, style } = text;
@@ -1398,7 +1414,7 @@ function textDecoration() {
1398
1414
  }
1399
1415
  prevStyle = style;
1400
1416
  } else {
1401
- prevStyle = undefined;
1417
+ prevStyle = void 0;
1402
1418
  }
1403
1419
  });
1404
1420
  groups.forEach((group2) => {
@@ -1522,7 +1538,7 @@ class Text extends EventEmitter {
1522
1538
  this.measureDom = options.measureDom;
1523
1539
  this.effects = options.effects;
1524
1540
  this.fonts = options.fonts;
1525
- this.use(listStyle()).use(textDecoration()).use(highlight()).use(render());
1541
+ this.use(background()).use(outline()).use(listStyle()).use(textDecoration()).use(highlight()).use(render());
1526
1542
  this.updateParagraphs();
1527
1543
  }
1528
1544
  use(plugin) {
@@ -1564,7 +1580,7 @@ class Text extends EventEmitter {
1564
1580
  paragraph.addFragment(f);
1565
1581
  } else {
1566
1582
  const { content: content2, ...fStyle } = f;
1567
- if (content2 !== undefined) {
1583
+ if (content2 !== void 0) {
1568
1584
  paragraph.addFragment(content2, fStyle);
1569
1585
  }
1570
1586
  }
@@ -1575,14 +1591,14 @@ class Text extends EventEmitter {
1575
1591
  const paragraph = new Paragraph(pStyle, style);
1576
1592
  fragments.forEach((f) => {
1577
1593
  const { content: content2, ...fStyle } = f;
1578
- if (content2 !== undefined) {
1594
+ if (content2 !== void 0) {
1579
1595
  paragraph.addFragment(content2, fStyle);
1580
1596
  }
1581
1597
  });
1582
1598
  paragraphs.push(paragraph);
1583
1599
  } else if ("content" in p) {
1584
1600
  const { content: pData, ...pStyle } = p;
1585
- if (pData !== undefined) {
1601
+ if (pData !== void 0) {
1586
1602
  const paragraph = new Paragraph(pStyle, style);
1587
1603
  paragraph.addFragment(pData);
1588
1604
  paragraphs.push(paragraph);
@@ -1731,6 +1747,7 @@ exports.Fragment = Fragment;
1731
1747
  exports.Measurer = Measurer;
1732
1748
  exports.Paragraph = Paragraph;
1733
1749
  exports.Text = Text;
1750
+ exports.background = background;
1734
1751
  exports.definePlugin = definePlugin;
1735
1752
  exports.drawPath = drawPath;
1736
1753
  exports.filterEmpty = filterEmpty;
@@ -1744,6 +1761,7 @@ exports.isNone = isNone;
1744
1761
  exports.listStyle = listStyle;
1745
1762
  exports.measureText = measureText;
1746
1763
  exports.needsFetch = needsFetch;
1764
+ exports.outline = outline;
1747
1765
  exports.parseColor = parseColor;
1748
1766
  exports.parseColormap = parseColormap;
1749
1767
  exports.parseValueNumber = parseValueNumber;
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { IDOCStyleDeclaration, IDOCTextContent, IDOCHighlightDeclaration } from 'modern-idoc';
2
- import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
1
+ import { StyleDeclaration, TextContent, HighlightDeclaration } from 'modern-idoc';
2
+ import { BoundingBox, Path2DDrawStyle, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
3
3
  import { Fonts, SFNT } from 'modern-font';
4
4
 
5
5
  declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
6
- declare function uploadColor(style: Partial<IDOCStyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
6
+ declare function uploadColor(style: Partial<StyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
7
7
  interface LinearGradient {
8
8
  x0: number;
9
9
  y0: number;
@@ -15,7 +15,7 @@ interface LinearGradient {
15
15
  }[];
16
16
  }
17
17
 
18
- interface DrawShapePathsOptions extends Partial<IDOCStyleDeclaration> {
18
+ interface DrawShapePathsOptions extends Partial<StyleDeclaration>, Partial<Path2DDrawStyle> {
19
19
  ctx: CanvasRenderingContext2D;
20
20
  path: Path2D;
21
21
  fontSize: number;
@@ -27,13 +27,13 @@ declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, bo
27
27
 
28
28
  declare class Fragment {
29
29
  content: string;
30
- style: Partial<IDOCStyleDeclaration>;
30
+ style: Partial<StyleDeclaration>;
31
31
  parent: Paragraph;
32
32
  inlineBox: BoundingBox;
33
33
  characters: Character[];
34
- computedStyle: IDOCStyleDeclaration;
34
+ computedStyle: StyleDeclaration;
35
35
  get computedContent(): string;
36
- constructor(content: string, style: Partial<IDOCStyleDeclaration> | undefined, parent: Paragraph);
36
+ constructor(content: string, style: Partial<StyleDeclaration> | undefined, parent: Paragraph);
37
37
  updateComputedStyle(): this;
38
38
  initCharacters(): this;
39
39
  }
@@ -65,7 +65,7 @@ declare class Character {
65
65
  centerDiviation: number;
66
66
  fontStyle?: 'bold' | 'italic';
67
67
  get center(): Vector2 | undefined;
68
- get computedStyle(): IDOCStyleDeclaration;
68
+ get computedStyle(): StyleDeclaration;
69
69
  get isVertical(): boolean;
70
70
  get fontSize(): number;
71
71
  get fontHeight(): number;
@@ -79,18 +79,18 @@ declare class Character {
79
79
  max: Vector2;
80
80
  } | undefined;
81
81
  getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
82
- drawTo(ctx: CanvasRenderingContext2D, config?: Partial<IDOCStyleDeclaration>): void;
82
+ drawTo(ctx: CanvasRenderingContext2D, config?: Partial<StyleDeclaration>): void;
83
83
  }
84
84
 
85
85
  declare class Paragraph {
86
- style: Partial<IDOCStyleDeclaration>;
87
- parentStyle: IDOCStyleDeclaration;
86
+ style: Partial<StyleDeclaration>;
87
+ parentStyle: StyleDeclaration;
88
88
  lineBox: BoundingBox;
89
89
  fragments: Fragment[];
90
- computedStyle: IDOCStyleDeclaration;
91
- constructor(style: Partial<IDOCStyleDeclaration>, parentStyle: IDOCStyleDeclaration);
90
+ computedStyle: StyleDeclaration;
91
+ constructor(style: Partial<StyleDeclaration>, parentStyle: StyleDeclaration);
92
92
  updateComputedStyle(): this;
93
- addFragment(content: string, style?: Partial<IDOCStyleDeclaration>): Fragment;
93
+ addFragment(content: string, style?: Partial<StyleDeclaration>): Fragment;
94
94
  }
95
95
 
96
96
  interface TextPlugin {
@@ -104,9 +104,9 @@ interface TextPlugin {
104
104
  load?: (text: Text$1) => Promise<void>;
105
105
  }
106
106
  interface TextOptions {
107
- style?: Partial<IDOCStyleDeclaration>;
108
- content?: IDOCTextContent;
109
- effects?: Partial<IDOCStyleDeclaration>[];
107
+ style?: Partial<StyleDeclaration>;
108
+ content?: TextContent;
109
+ effects?: Partial<StyleDeclaration>[];
110
110
  debug?: boolean;
111
111
  measureDom?: HTMLElement;
112
112
  fonts?: Fonts;
@@ -177,7 +177,7 @@ declare class Measurer {
177
177
  * </ul>
178
178
  * </section>
179
179
  */
180
- createParagraphDom(paragraphs: Paragraph[], rootStyle: IDOCStyleDeclaration): {
180
+ createParagraphDom(paragraphs: Paragraph[], rootStyle: StyleDeclaration): {
181
181
  dom: HTMLElement;
182
182
  destory: () => void;
183
183
  };
@@ -194,7 +194,7 @@ declare class Measurer {
194
194
  characters: MeasuredCharacter[];
195
195
  };
196
196
  measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
197
- measure(paragraphs: Paragraph[], rootStyle: IDOCStyleDeclaration, dom?: HTMLElement): MeasureDomResult;
197
+ measure(paragraphs: Paragraph[], rootStyle: StyleDeclaration, dom?: HTMLElement): MeasureDomResult;
198
198
  }
199
199
 
200
200
  interface TextRenderOptions {
@@ -209,7 +209,7 @@ interface MeasureResult {
209
209
  pathBox: BoundingBox;
210
210
  boundingBox: BoundingBox;
211
211
  }
212
- declare const textDefaultStyle: IDOCStyleDeclaration;
212
+ declare const textDefaultStyle: StyleDeclaration;
213
213
  interface TextEventMap {
214
214
  update: {
215
215
  text: Text$1;
@@ -226,12 +226,12 @@ interface TextEventMap {
226
226
  }
227
227
  declare class Text$1 extends EventEmitter<TextEventMap> {
228
228
  debug: boolean;
229
- content: IDOCTextContent;
230
- style: Partial<IDOCStyleDeclaration>;
231
- effects?: Partial<IDOCStyleDeclaration>[];
229
+ content: TextContent;
230
+ style: Partial<StyleDeclaration>;
231
+ effects?: Partial<StyleDeclaration>[];
232
232
  measureDom?: HTMLElement;
233
233
  needsUpdate: boolean;
234
- computedStyle: IDOCStyleDeclaration;
234
+ computedStyle: StyleDeclaration;
235
235
  paragraphs: Paragraph[];
236
236
  lineBox: BoundingBox;
237
237
  rawGlyphBox: BoundingBox;
@@ -273,13 +273,17 @@ type RenderTextOptions = TextOptions & TextRenderOptions;
273
273
  declare function renderText(options: RenderTextOptions, load: true): Promise<void>;
274
274
  declare function renderText(options: RenderTextOptions): void;
275
275
 
276
- declare function getHighlightStyle(style: IDOCStyleDeclaration): IDOCHighlightDeclaration;
276
+ declare function background(): TextPlugin;
277
+
278
+ declare function getHighlightStyle(style: StyleDeclaration): HighlightDeclaration;
277
279
  declare function highlight(): TextPlugin;
278
280
 
279
281
  declare function listStyle(): TextPlugin;
280
282
 
283
+ declare function outline(): TextPlugin;
284
+
281
285
  declare function render(): TextPlugin;
282
- declare function getTransform2D(text: Text$1, style: Partial<IDOCStyleDeclaration>): Matrix3;
286
+ declare function getTransform2D(text: Text$1, style: Partial<StyleDeclaration>): Matrix3;
283
287
 
284
288
  declare function textDecoration(): TextPlugin;
285
289
 
@@ -296,4 +300,4 @@ declare function hexToRgb(hex: string): string | null;
296
300
  declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
297
301
  declare function needsFetch(source: string): boolean;
298
302
 
299
- export { Character, type DrawShapePathsOptions, Fragment, type LinearGradient, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type RenderTextOptions, Text$1 as Text, type TextEventMap, type TextOptions, type TextPlugin, type TextRenderOptions, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
303
+ export { Character, type DrawShapePathsOptions, Fragment, type LinearGradient, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type RenderTextOptions, Text$1 as Text, type TextEventMap, type TextOptions, type TextPlugin, type TextRenderOptions, 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/dist/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
- import { IDOCStyleDeclaration, IDOCTextContent, IDOCHighlightDeclaration } from 'modern-idoc';
2
- import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
1
+ import { StyleDeclaration, TextContent, HighlightDeclaration } from 'modern-idoc';
2
+ import { BoundingBox, Path2DDrawStyle, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
3
3
  import { Fonts, SFNT } from 'modern-font';
4
4
 
5
5
  declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
6
- declare function uploadColor(style: Partial<IDOCStyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
6
+ declare function uploadColor(style: Partial<StyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
7
7
  interface LinearGradient {
8
8
  x0: number;
9
9
  y0: number;
@@ -15,7 +15,7 @@ interface LinearGradient {
15
15
  }[];
16
16
  }
17
17
 
18
- interface DrawShapePathsOptions extends Partial<IDOCStyleDeclaration> {
18
+ interface DrawShapePathsOptions extends Partial<StyleDeclaration>, Partial<Path2DDrawStyle> {
19
19
  ctx: CanvasRenderingContext2D;
20
20
  path: Path2D;
21
21
  fontSize: number;
@@ -27,13 +27,13 @@ declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, bo
27
27
 
28
28
  declare class Fragment {
29
29
  content: string;
30
- style: Partial<IDOCStyleDeclaration>;
30
+ style: Partial<StyleDeclaration>;
31
31
  parent: Paragraph;
32
32
  inlineBox: BoundingBox;
33
33
  characters: Character[];
34
- computedStyle: IDOCStyleDeclaration;
34
+ computedStyle: StyleDeclaration;
35
35
  get computedContent(): string;
36
- constructor(content: string, style: Partial<IDOCStyleDeclaration> | undefined, parent: Paragraph);
36
+ constructor(content: string, style: Partial<StyleDeclaration> | undefined, parent: Paragraph);
37
37
  updateComputedStyle(): this;
38
38
  initCharacters(): this;
39
39
  }
@@ -65,7 +65,7 @@ declare class Character {
65
65
  centerDiviation: number;
66
66
  fontStyle?: 'bold' | 'italic';
67
67
  get center(): Vector2 | undefined;
68
- get computedStyle(): IDOCStyleDeclaration;
68
+ get computedStyle(): StyleDeclaration;
69
69
  get isVertical(): boolean;
70
70
  get fontSize(): number;
71
71
  get fontHeight(): number;
@@ -79,18 +79,18 @@ declare class Character {
79
79
  max: Vector2;
80
80
  } | undefined;
81
81
  getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
82
- drawTo(ctx: CanvasRenderingContext2D, config?: Partial<IDOCStyleDeclaration>): void;
82
+ drawTo(ctx: CanvasRenderingContext2D, config?: Partial<StyleDeclaration>): void;
83
83
  }
84
84
 
85
85
  declare class Paragraph {
86
- style: Partial<IDOCStyleDeclaration>;
87
- parentStyle: IDOCStyleDeclaration;
86
+ style: Partial<StyleDeclaration>;
87
+ parentStyle: StyleDeclaration;
88
88
  lineBox: BoundingBox;
89
89
  fragments: Fragment[];
90
- computedStyle: IDOCStyleDeclaration;
91
- constructor(style: Partial<IDOCStyleDeclaration>, parentStyle: IDOCStyleDeclaration);
90
+ computedStyle: StyleDeclaration;
91
+ constructor(style: Partial<StyleDeclaration>, parentStyle: StyleDeclaration);
92
92
  updateComputedStyle(): this;
93
- addFragment(content: string, style?: Partial<IDOCStyleDeclaration>): Fragment;
93
+ addFragment(content: string, style?: Partial<StyleDeclaration>): Fragment;
94
94
  }
95
95
 
96
96
  interface TextPlugin {
@@ -104,9 +104,9 @@ interface TextPlugin {
104
104
  load?: (text: Text$1) => Promise<void>;
105
105
  }
106
106
  interface TextOptions {
107
- style?: Partial<IDOCStyleDeclaration>;
108
- content?: IDOCTextContent;
109
- effects?: Partial<IDOCStyleDeclaration>[];
107
+ style?: Partial<StyleDeclaration>;
108
+ content?: TextContent;
109
+ effects?: Partial<StyleDeclaration>[];
110
110
  debug?: boolean;
111
111
  measureDom?: HTMLElement;
112
112
  fonts?: Fonts;
@@ -177,7 +177,7 @@ declare class Measurer {
177
177
  * </ul>
178
178
  * </section>
179
179
  */
180
- createParagraphDom(paragraphs: Paragraph[], rootStyle: IDOCStyleDeclaration): {
180
+ createParagraphDom(paragraphs: Paragraph[], rootStyle: StyleDeclaration): {
181
181
  dom: HTMLElement;
182
182
  destory: () => void;
183
183
  };
@@ -194,7 +194,7 @@ declare class Measurer {
194
194
  characters: MeasuredCharacter[];
195
195
  };
196
196
  measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
197
- measure(paragraphs: Paragraph[], rootStyle: IDOCStyleDeclaration, dom?: HTMLElement): MeasureDomResult;
197
+ measure(paragraphs: Paragraph[], rootStyle: StyleDeclaration, dom?: HTMLElement): MeasureDomResult;
198
198
  }
199
199
 
200
200
  interface TextRenderOptions {
@@ -209,7 +209,7 @@ interface MeasureResult {
209
209
  pathBox: BoundingBox;
210
210
  boundingBox: BoundingBox;
211
211
  }
212
- declare const textDefaultStyle: IDOCStyleDeclaration;
212
+ declare const textDefaultStyle: StyleDeclaration;
213
213
  interface TextEventMap {
214
214
  update: {
215
215
  text: Text$1;
@@ -226,12 +226,12 @@ interface TextEventMap {
226
226
  }
227
227
  declare class Text$1 extends EventEmitter<TextEventMap> {
228
228
  debug: boolean;
229
- content: IDOCTextContent;
230
- style: Partial<IDOCStyleDeclaration>;
231
- effects?: Partial<IDOCStyleDeclaration>[];
229
+ content: TextContent;
230
+ style: Partial<StyleDeclaration>;
231
+ effects?: Partial<StyleDeclaration>[];
232
232
  measureDom?: HTMLElement;
233
233
  needsUpdate: boolean;
234
- computedStyle: IDOCStyleDeclaration;
234
+ computedStyle: StyleDeclaration;
235
235
  paragraphs: Paragraph[];
236
236
  lineBox: BoundingBox;
237
237
  rawGlyphBox: BoundingBox;
@@ -273,13 +273,17 @@ type RenderTextOptions = TextOptions & TextRenderOptions;
273
273
  declare function renderText(options: RenderTextOptions, load: true): Promise<void>;
274
274
  declare function renderText(options: RenderTextOptions): void;
275
275
 
276
- declare function getHighlightStyle(style: IDOCStyleDeclaration): IDOCHighlightDeclaration;
276
+ declare function background(): TextPlugin;
277
+
278
+ declare function getHighlightStyle(style: StyleDeclaration): HighlightDeclaration;
277
279
  declare function highlight(): TextPlugin;
278
280
 
279
281
  declare function listStyle(): TextPlugin;
280
282
 
283
+ declare function outline(): TextPlugin;
284
+
281
285
  declare function render(): TextPlugin;
282
- declare function getTransform2D(text: Text$1, style: Partial<IDOCStyleDeclaration>): Matrix3;
286
+ declare function getTransform2D(text: Text$1, style: Partial<StyleDeclaration>): Matrix3;
283
287
 
284
288
  declare function textDecoration(): TextPlugin;
285
289
 
@@ -296,4 +300,4 @@ declare function hexToRgb(hex: string): string | null;
296
300
  declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
297
301
  declare function needsFetch(source: string): boolean;
298
302
 
299
- export { Character, type DrawShapePathsOptions, Fragment, type LinearGradient, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type RenderTextOptions, Text$1 as Text, type TextEventMap, type TextOptions, type TextPlugin, type TextRenderOptions, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
303
+ export { Character, type DrawShapePathsOptions, Fragment, type LinearGradient, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type RenderTextOptions, Text$1 as Text, type TextEventMap, type TextOptions, type TextPlugin, type TextRenderOptions, 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/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { IDOCStyleDeclaration, IDOCTextContent, IDOCHighlightDeclaration } from 'modern-idoc';
2
- import { BoundingBox, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
1
+ import { StyleDeclaration, TextContent, HighlightDeclaration } from 'modern-idoc';
2
+ import { BoundingBox, Path2DDrawStyle, Path2D, Vector2, VectorLike, Matrix3 } from 'modern-path2d';
3
3
  import { Fonts, SFNT } from 'modern-font';
4
4
 
5
5
  declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern;
6
- declare function uploadColor(style: Partial<IDOCStyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
6
+ declare function uploadColor(style: Partial<StyleDeclaration>, box: BoundingBox, ctx: CanvasRenderingContext2D): void;
7
7
  interface LinearGradient {
8
8
  x0: number;
9
9
  y0: number;
@@ -15,7 +15,7 @@ interface LinearGradient {
15
15
  }[];
16
16
  }
17
17
 
18
- interface DrawShapePathsOptions extends Partial<IDOCStyleDeclaration> {
18
+ interface DrawShapePathsOptions extends Partial<StyleDeclaration>, Partial<Path2DDrawStyle> {
19
19
  ctx: CanvasRenderingContext2D;
20
20
  path: Path2D;
21
21
  fontSize: number;
@@ -27,13 +27,13 @@ declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, bo
27
27
 
28
28
  declare class Fragment {
29
29
  content: string;
30
- style: Partial<IDOCStyleDeclaration>;
30
+ style: Partial<StyleDeclaration>;
31
31
  parent: Paragraph;
32
32
  inlineBox: BoundingBox;
33
33
  characters: Character[];
34
- computedStyle: IDOCStyleDeclaration;
34
+ computedStyle: StyleDeclaration;
35
35
  get computedContent(): string;
36
- constructor(content: string, style: Partial<IDOCStyleDeclaration> | undefined, parent: Paragraph);
36
+ constructor(content: string, style: Partial<StyleDeclaration> | undefined, parent: Paragraph);
37
37
  updateComputedStyle(): this;
38
38
  initCharacters(): this;
39
39
  }
@@ -65,7 +65,7 @@ declare class Character {
65
65
  centerDiviation: number;
66
66
  fontStyle?: 'bold' | 'italic';
67
67
  get center(): Vector2 | undefined;
68
- get computedStyle(): IDOCStyleDeclaration;
68
+ get computedStyle(): StyleDeclaration;
69
69
  get isVertical(): boolean;
70
70
  get fontSize(): number;
71
71
  get fontHeight(): number;
@@ -79,18 +79,18 @@ declare class Character {
79
79
  max: Vector2;
80
80
  } | undefined;
81
81
  getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
82
- drawTo(ctx: CanvasRenderingContext2D, config?: Partial<IDOCStyleDeclaration>): void;
82
+ drawTo(ctx: CanvasRenderingContext2D, config?: Partial<StyleDeclaration>): void;
83
83
  }
84
84
 
85
85
  declare class Paragraph {
86
- style: Partial<IDOCStyleDeclaration>;
87
- parentStyle: IDOCStyleDeclaration;
86
+ style: Partial<StyleDeclaration>;
87
+ parentStyle: StyleDeclaration;
88
88
  lineBox: BoundingBox;
89
89
  fragments: Fragment[];
90
- computedStyle: IDOCStyleDeclaration;
91
- constructor(style: Partial<IDOCStyleDeclaration>, parentStyle: IDOCStyleDeclaration);
90
+ computedStyle: StyleDeclaration;
91
+ constructor(style: Partial<StyleDeclaration>, parentStyle: StyleDeclaration);
92
92
  updateComputedStyle(): this;
93
- addFragment(content: string, style?: Partial<IDOCStyleDeclaration>): Fragment;
93
+ addFragment(content: string, style?: Partial<StyleDeclaration>): Fragment;
94
94
  }
95
95
 
96
96
  interface TextPlugin {
@@ -104,9 +104,9 @@ interface TextPlugin {
104
104
  load?: (text: Text$1) => Promise<void>;
105
105
  }
106
106
  interface TextOptions {
107
- style?: Partial<IDOCStyleDeclaration>;
108
- content?: IDOCTextContent;
109
- effects?: Partial<IDOCStyleDeclaration>[];
107
+ style?: Partial<StyleDeclaration>;
108
+ content?: TextContent;
109
+ effects?: Partial<StyleDeclaration>[];
110
110
  debug?: boolean;
111
111
  measureDom?: HTMLElement;
112
112
  fonts?: Fonts;
@@ -177,7 +177,7 @@ declare class Measurer {
177
177
  * </ul>
178
178
  * </section>
179
179
  */
180
- createParagraphDom(paragraphs: Paragraph[], rootStyle: IDOCStyleDeclaration): {
180
+ createParagraphDom(paragraphs: Paragraph[], rootStyle: StyleDeclaration): {
181
181
  dom: HTMLElement;
182
182
  destory: () => void;
183
183
  };
@@ -194,7 +194,7 @@ declare class Measurer {
194
194
  characters: MeasuredCharacter[];
195
195
  };
196
196
  measureParagraphDom(paragraphs: Paragraph[], dom: HTMLElement): MeasureDomResult;
197
- measure(paragraphs: Paragraph[], rootStyle: IDOCStyleDeclaration, dom?: HTMLElement): MeasureDomResult;
197
+ measure(paragraphs: Paragraph[], rootStyle: StyleDeclaration, dom?: HTMLElement): MeasureDomResult;
198
198
  }
199
199
 
200
200
  interface TextRenderOptions {
@@ -209,7 +209,7 @@ interface MeasureResult {
209
209
  pathBox: BoundingBox;
210
210
  boundingBox: BoundingBox;
211
211
  }
212
- declare const textDefaultStyle: IDOCStyleDeclaration;
212
+ declare const textDefaultStyle: StyleDeclaration;
213
213
  interface TextEventMap {
214
214
  update: {
215
215
  text: Text$1;
@@ -226,12 +226,12 @@ interface TextEventMap {
226
226
  }
227
227
  declare class Text$1 extends EventEmitter<TextEventMap> {
228
228
  debug: boolean;
229
- content: IDOCTextContent;
230
- style: Partial<IDOCStyleDeclaration>;
231
- effects?: Partial<IDOCStyleDeclaration>[];
229
+ content: TextContent;
230
+ style: Partial<StyleDeclaration>;
231
+ effects?: Partial<StyleDeclaration>[];
232
232
  measureDom?: HTMLElement;
233
233
  needsUpdate: boolean;
234
- computedStyle: IDOCStyleDeclaration;
234
+ computedStyle: StyleDeclaration;
235
235
  paragraphs: Paragraph[];
236
236
  lineBox: BoundingBox;
237
237
  rawGlyphBox: BoundingBox;
@@ -273,13 +273,17 @@ type RenderTextOptions = TextOptions & TextRenderOptions;
273
273
  declare function renderText(options: RenderTextOptions, load: true): Promise<void>;
274
274
  declare function renderText(options: RenderTextOptions): void;
275
275
 
276
- declare function getHighlightStyle(style: IDOCStyleDeclaration): IDOCHighlightDeclaration;
276
+ declare function background(): TextPlugin;
277
+
278
+ declare function getHighlightStyle(style: StyleDeclaration): HighlightDeclaration;
277
279
  declare function highlight(): TextPlugin;
278
280
 
279
281
  declare function listStyle(): TextPlugin;
280
282
 
283
+ declare function outline(): TextPlugin;
284
+
281
285
  declare function render(): TextPlugin;
282
- declare function getTransform2D(text: Text$1, style: Partial<IDOCStyleDeclaration>): Matrix3;
286
+ declare function getTransform2D(text: Text$1, style: Partial<StyleDeclaration>): Matrix3;
283
287
 
284
288
  declare function textDecoration(): TextPlugin;
285
289
 
@@ -296,4 +300,4 @@ declare function hexToRgb(hex: string): string | null;
296
300
  declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined;
297
301
  declare function needsFetch(source: string): boolean;
298
302
 
299
- export { Character, type DrawShapePathsOptions, Fragment, type LinearGradient, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type RenderTextOptions, Text$1 as Text, type TextEventMap, type TextOptions, type TextPlugin, type TextRenderOptions, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlight, isEqualObject, isEqualValue, isNone, listStyle, measureText, needsFetch, parseColor, parseColormap, parseValueNumber, render, renderText, setupView, textDecoration, textDefaultStyle, uploadColor, uploadColors };
303
+ export { Character, type DrawShapePathsOptions, Fragment, type LinearGradient, type MeasureDomResult, type MeasureResult, type MeasuredCharacter, type MeasuredFragment, type MeasuredParagraph, Measurer, Paragraph, type RenderTextOptions, Text$1 as Text, type TextEventMap, type TextOptions, type TextPlugin, type TextRenderOptions, 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 };