circuit-to-canvas 0.0.24 → 0.0.26

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.ts CHANGED
@@ -216,17 +216,14 @@ interface DrawArrowParams {
216
216
  */
217
217
  declare function drawArrow(params: DrawArrowParams): void;
218
218
 
219
- type AlphabetLayout = {
220
- width: number;
221
- height: number;
222
- glyphWidth: number;
223
- letterSpacing: number;
224
- spaceWidth: number;
225
- strokeWidth: number;
226
- };
227
- declare function getAlphabetLayout(text: string, fontSize: number): AlphabetLayout;
228
-
229
- declare function strokeAlphabetText(ctx: CanvasContext, text: string, layout: AlphabetLayout, startX: number, startY: number): void;
219
+ interface StrokeAlphabetTextParams {
220
+ ctx: CanvasContext;
221
+ text: string;
222
+ fontSize: number;
223
+ startX: number;
224
+ startY: number;
225
+ }
226
+ declare function strokeAlphabetText(params: StrokeAlphabetTextParams): void;
230
227
  interface DrawTextParams {
231
228
  ctx: CanvasContext;
232
229
  text: string;
@@ -240,6 +237,16 @@ interface DrawTextParams {
240
237
  }
241
238
  declare function drawText(params: DrawTextParams): void;
242
239
 
240
+ type AlphabetLayout = {
241
+ width: number;
242
+ height: number;
243
+ glyphWidth: number;
244
+ letterSpacing: number;
245
+ spaceWidth: number;
246
+ strokeWidth: number;
247
+ };
248
+ declare function getAlphabetLayout(text: string, fontSize: number): AlphabetLayout;
249
+
243
250
  type AnchorAlignment = NinePointAnchor;
244
251
  declare function getTextStartPosition(alignment: NinePointAnchor, layout: AlphabetLayout): {
245
252
  x: number;
package/dist/index.js CHANGED
@@ -708,7 +708,9 @@ function getTextStartPosition(alignment, layout) {
708
708
 
709
709
  // lib/drawer/shapes/text/text.ts
710
710
  var getGlyphLines = (char) => lineAlphabet[char] ?? lineAlphabet[char.toUpperCase()];
711
- function strokeAlphabetText(ctx, text, layout, startX, startY) {
711
+ function strokeAlphabetText(params) {
712
+ const { ctx, text, fontSize, startX, startY } = params;
713
+ const layout = getAlphabetLayout(text, fontSize);
712
714
  const { glyphWidth, letterSpacing, spaceWidth, height, strokeWidth } = layout;
713
715
  const topY = startY;
714
716
  const characters = Array.from(text);
@@ -761,7 +763,13 @@ function drawText(params) {
761
763
  ctx.lineCap = "round";
762
764
  ctx.lineJoin = "round";
763
765
  ctx.strokeStyle = color;
764
- strokeAlphabetText(ctx, text, layout, startPos.x, startPos.y);
766
+ strokeAlphabetText({
767
+ ctx,
768
+ text,
769
+ fontSize: scaledFontSize,
770
+ startX: startPos.x,
771
+ startY: startPos.y
772
+ });
765
773
  ctx.restore();
766
774
  }
767
775
 
@@ -800,7 +808,13 @@ function drawPcbSilkscreenText(params) {
800
808
  ctx.lineCap = "round";
801
809
  ctx.lineJoin = "round";
802
810
  ctx.strokeStyle = color;
803
- strokeAlphabetText(ctx, content, layout, startPos.x, startPos.y);
811
+ strokeAlphabetText({
812
+ ctx,
813
+ text: content,
814
+ fontSize,
815
+ startX: startPos.x,
816
+ startY: startPos.y
817
+ });
804
818
  ctx.restore();
805
819
  }
806
820
 
@@ -1032,7 +1046,7 @@ function drawPcbCopperText(params) {
1032
1046
  ctx.globalCompositeOperation = "destination-out";
1033
1047
  ctx.fillStyle = "rgba(0,0,0,1)";
1034
1048
  ctx.strokeStyle = "rgba(0,0,0,1)";
1035
- strokeAlphabetText(ctx, content, layout, startX, startY);
1049
+ strokeAlphabetText({ ctx, text: content, fontSize, startX, startY });
1036
1050
  if (previousCompositeOperation) {
1037
1051
  ctx.globalCompositeOperation = previousCompositeOperation;
1038
1052
  } else {
@@ -1040,7 +1054,7 @@ function drawPcbCopperText(params) {
1040
1054
  }
1041
1055
  } else {
1042
1056
  ctx.strokeStyle = textColor;
1043
- strokeAlphabetText(ctx, content, layout, startX, startY);
1057
+ strokeAlphabetText({ ctx, text: content, fontSize, startX, startY });
1044
1058
  }
1045
1059
  ctx.restore();
1046
1060
  }
@@ -88,7 +88,7 @@ export function drawPcbCopperText(params: DrawPcbCopperTextParams): void {
88
88
  ctx.globalCompositeOperation = "destination-out"
89
89
  ctx.fillStyle = "rgba(0,0,0,1)"
90
90
  ctx.strokeStyle = "rgba(0,0,0,1)"
91
- strokeAlphabetText(ctx, content, layout, startX, startY)
91
+ strokeAlphabetText({ ctx, text: content, fontSize, startX, startY })
92
92
  if (previousCompositeOperation) {
93
93
  ctx.globalCompositeOperation = previousCompositeOperation
94
94
  } else {
@@ -96,7 +96,7 @@ export function drawPcbCopperText(params: DrawPcbCopperTextParams): void {
96
96
  }
97
97
  } else {
98
98
  ctx.strokeStyle = textColor
99
- strokeAlphabetText(ctx, content, layout, startX, startY)
99
+ strokeAlphabetText({ ctx, text: content, fontSize, startX, startY })
100
100
  }
101
101
  ctx.restore()
102
102
  }
@@ -65,7 +65,13 @@ export function drawPcbSilkscreenText(
65
65
  ctx.lineJoin = "round"
66
66
  ctx.strokeStyle = color
67
67
 
68
- strokeAlphabetText(ctx, content, layout, startPos.x, startPos.y)
68
+ strokeAlphabetText({
69
+ ctx,
70
+ text: content,
71
+ fontSize,
72
+ startX: startPos.x,
73
+ startY: startPos.y,
74
+ })
69
75
 
70
76
  ctx.restore()
71
77
  }
@@ -9,13 +9,17 @@ import { getTextStartPosition } from "./getTextStartPosition"
9
9
  const getGlyphLines = (char: string) =>
10
10
  lineAlphabet[char] ?? lineAlphabet[char.toUpperCase()]
11
11
 
12
- export function strokeAlphabetText(
13
- ctx: CanvasContext,
14
- text: string,
15
- layout: AlphabetLayout,
16
- startX: number,
17
- startY: number,
18
- ): void {
12
+ export interface StrokeAlphabetTextParams {
13
+ ctx: CanvasContext
14
+ text: string
15
+ fontSize: number
16
+ startX: number
17
+ startY: number
18
+ }
19
+
20
+ export function strokeAlphabetText(params: StrokeAlphabetTextParams): void {
21
+ const { ctx, text, fontSize, startX, startY } = params
22
+ const layout = getAlphabetLayout(text, fontSize)
19
23
  const { glyphWidth, letterSpacing, spaceWidth, height, strokeWidth } = layout
20
24
  const topY = startY
21
25
  const characters = Array.from(text)
@@ -92,7 +96,13 @@ export function drawText(params: DrawTextParams): void {
92
96
  ctx.lineJoin = "round"
93
97
  ctx.strokeStyle = color
94
98
 
95
- strokeAlphabetText(ctx, text, layout, startPos.x, startPos.y)
99
+ strokeAlphabetText({
100
+ ctx,
101
+ text,
102
+ fontSize: scaledFontSize,
103
+ startX: startPos.x,
104
+ startY: startPos.y,
105
+ })
96
106
 
97
107
  ctx.restore()
98
108
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-to-canvas",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.24",
4
+ "version": "0.0.26",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup-node ./lib/index.ts --format esm --dts",