schematic-symbols 0.0.92 → 0.0.94

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,21 +7,72 @@ import type {
7
7
  NinePointAnchor,
8
8
  } from "./types"
9
9
 
10
- const rotateAnchor = (anchor: NinePointAnchor): NinePointAnchor => {
11
- switch (anchor) {
12
- case "middle_top":
13
- return "middle_right"
14
- case "middle_bottom":
15
- return "middle_left"
10
+ // Update rotateAnchor to handle all anchor rotations based on orientation
11
+ const rotateAnchor = (
12
+ anchor: NinePointAnchor,
13
+ orientation: "up" | "down" | "left" | "right" = "right",
14
+ ): NinePointAnchor => {
15
+ switch (orientation) {
16
+ case "up":
17
+ switch (anchor) {
18
+ case "middle_top":
19
+ return "middle_left"
20
+ case "middle_bottom":
21
+ return "middle_right"
22
+ case "middle_left":
23
+ return "middle_bottom"
24
+ case "middle_right":
25
+ return "middle_top"
26
+ }
27
+ break
28
+ case "down":
29
+ switch (anchor) {
30
+ case "middle_top":
31
+ return "middle_right"
32
+ case "middle_bottom":
33
+ return "middle_left"
34
+ case "middle_left":
35
+ return "middle_top"
36
+ case "middle_right":
37
+ return "middle_bottom"
38
+ }
39
+ break
40
+ case "left":
41
+ switch (anchor) {
42
+ case "middle_top":
43
+ return "middle_left"
44
+ case "middle_bottom":
45
+ return "middle_right"
46
+ case "middle_left":
47
+ return "middle_bottom"
48
+ case "middle_right":
49
+ return "middle_top"
50
+ }
51
+ break
52
+ case "right":
53
+ return anchor // No change if orientation is "right"
16
54
  }
17
55
  return anchor
18
56
  }
19
57
 
20
58
  export const rotateSymbol = (
21
59
  symbol: SchSymbol,
60
+ orientation?: "up" | "down" | "left" | "right",
22
61
  overrides?: Partial<SchSymbol>,
23
62
  ): SchSymbol => {
24
- const transform = rotate(Math.PI / 2, symbol.center.x, symbol.center.y)
63
+ // Assuming the default orientation is "right"
64
+ const angleMap = {
65
+ up: -Math.PI / 2,
66
+ right: 0,
67
+ down: Math.PI / 2,
68
+ left: -Math.PI,
69
+ }
70
+
71
+ const transform = rotate(
72
+ orientation ? angleMap[orientation] : Math.PI / 2,
73
+ symbol.center.x,
74
+ symbol.center.y,
75
+ )
25
76
 
26
77
  const { primitives, center, size, ports } = symbol
27
78
 
@@ -41,7 +92,10 @@ export const rotateSymbol = (
41
92
  y: primitive.y,
42
93
  }) as Point
43
94
 
44
- primitive.anchor = rotateAnchor(primitive.anchor)
95
+ primitive.anchor = rotateAnchor(
96
+ primitive.anchor,
97
+ orientation ?? "right",
98
+ )
45
99
 
46
100
  return {
47
101
  ...primitive,
@@ -84,10 +138,15 @@ export const rotateSymbol = (
84
138
  primitives: rotatedPrimitives,
85
139
  center,
86
140
  ports: rotatedPorts,
87
- // TODO recompute size using overrides
88
141
  size: {
89
- width: size.height,
90
- height: size.width,
142
+ width:
143
+ orientation === "up" || orientation === "down"
144
+ ? size.width
145
+ : size.height,
146
+ height:
147
+ orientation === "up" || orientation === "down"
148
+ ? size.height
149
+ : size.width,
91
150
  },
92
151
  ...overrides,
93
152
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "schematic-symbols",
3
3
  "main": "./dist/index.js",
4
- "version": "0.0.92",
4
+ "version": "0.0.94",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -0,0 +1,4 @@
1
+ import { rotateSymbol } from "drawing/rotateSymbol"
2
+ import diode_right from "./diode_right"
3
+
4
+ export default rotateSymbol(diode_right, "down")
@@ -0,0 +1,4 @@
1
+ import { rotateSymbol } from "drawing/rotateSymbol"
2
+ import diode_right from "./diode_right"
3
+
4
+ export default rotateSymbol(diode_right, "left")
@@ -1,14 +1,16 @@
1
- import svgJson from "assets/generated/diode.json"
2
1
  import { defineSymbol } from "drawing/defineSymbol"
2
+ import svgJson from "assets/generated/diode.json"
3
+ import { Primitive } from "drawing/types"
3
4
 
4
- const { paths, texts, bounds, refblocks } = svgJson
5
+ const { paths, texts, bounds, refblocks, circles } = svgJson
5
6
 
6
7
  export default defineSymbol({
7
8
  primitives: [
8
9
  ...Object.values(paths),
10
+ ...Object.values(circles),
9
11
  { ...texts.top1, anchor: "middle_bottom" },
10
12
  { ...texts.bottom1, anchor: "middle_top" },
11
- ] as any,
13
+ ] as Primitive[],
12
14
  ports: [
13
15
  { ...refblocks.left1, labels: ["1"] }, // TODO add more "standard" labels
14
16
  { ...refblocks.right1, labels: ["2"] }, // TODO add more "standard" labels
@@ -0,0 +1,4 @@
1
+ import { rotateSymbol } from "drawing/rotateSymbol"
2
+ import diode_right from "./diode_right"
3
+
4
+ export default rotateSymbol(diode_right, "up")
@@ -1,4 +1,4 @@
1
1
  import { rotateSymbol } from "drawing/rotateSymbol"
2
2
  import varistor_horz from "./varistor_horz"
3
3
 
4
- export default rotateSymbol(varistor_horz, {})
4
+ export default rotateSymbol(varistor_horz)
@@ -1,4 +0,0 @@
1
- import { rotateSymbol } from "drawing/rotateSymbol"
2
- import diode_horz from "./diode_horz"
3
-
4
- export default rotateSymbol(diode_horz)