circuitscript 0.0.21 → 0.0.24

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 (163) hide show
  1. package/dist/cjs/antlr/CircuitScriptLexer.js +288 -0
  2. package/dist/cjs/antlr/CircuitScriptParser.js +4905 -0
  3. package/dist/cjs/antlr/CircuitScriptVisitor.js +6 -0
  4. package/{src/draw_symbols.ts → dist/cjs/draw_symbols.js} +303 -614
  5. package/dist/cjs/execute.js +780 -0
  6. package/{src/export.ts → dist/cjs/export.js} +34 -56
  7. package/dist/cjs/fonts.js +4 -0
  8. package/dist/cjs/geometry.js +430 -0
  9. package/dist/cjs/globals.js +60 -0
  10. package/dist/cjs/helpers.js +99 -0
  11. package/dist/cjs/index.js +29 -0
  12. package/{src/layout.ts → dist/cjs/layout.js} +413 -1002
  13. package/dist/cjs/lexer.js +114 -0
  14. package/dist/cjs/logger.js +17 -0
  15. package/dist/cjs/main.js +87 -0
  16. package/dist/cjs/objects/ClassComponent.js +142 -0
  17. package/dist/cjs/objects/ExecutionScope.js +134 -0
  18. package/dist/cjs/objects/Frame.js +22 -0
  19. package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
  20. package/dist/cjs/objects/ParamDefinition.js +42 -0
  21. package/dist/cjs/objects/PinDefinition.js +31 -0
  22. package/dist/cjs/objects/PinTypes.js +11 -0
  23. package/dist/cjs/objects/Wire.js +9 -0
  24. package/dist/cjs/objects/types.js +9 -0
  25. package/dist/cjs/parser.js +299 -0
  26. package/dist/cjs/regenerate-tests.js +23 -0
  27. package/dist/cjs/render.js +155 -0
  28. package/{src/server.ts → dist/cjs/server.js} +15 -21
  29. package/dist/cjs/sizing.js +105 -0
  30. package/{src/utils.ts → dist/cjs/utils.js} +25 -35
  31. package/{src/visitor.ts → dist/cjs/visitor.js} +392 -948
  32. package/{build/src/antlr/CircuitScriptLexer.js → dist/esm/antlr/CircuitScriptLexer.mjs} +90 -91
  33. package/{build/src/antlr/CircuitScriptParser.js → dist/esm/antlr/CircuitScriptParser.mjs} +138 -136
  34. package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +11 -11
  35. package/{build/src/execute.js → dist/esm/execute.mjs} +9 -8
  36. package/{build/src/export.js → dist/esm/export.mjs} +2 -2
  37. package/{build/src/geometry.js → dist/esm/geometry.mjs} +3 -7
  38. package/{build/src/helpers.js → dist/esm/helpers.mjs} +27 -7
  39. package/dist/esm/index.mjs +13 -0
  40. package/{build/src/layout.js → dist/esm/layout.mjs} +11 -11
  41. package/{build/src/lexer.js → dist/esm/lexer.mjs} +2 -2
  42. package/{build/src/main.js → dist/esm/main.mjs} +5 -5
  43. package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +3 -3
  44. package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
  45. package/dist/esm/parser.mjs +269 -0
  46. package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
  47. package/{build/src/render.js → dist/esm/render.mjs} +7 -24
  48. package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
  49. package/{build/src/visitor.js → dist/esm/visitor.mjs} +10 -29
  50. package/dist/types/antlr/CircuitScriptLexer.d.ts +71 -0
  51. package/dist/types/antlr/CircuitScriptParser.d.ts +675 -0
  52. package/dist/types/antlr/CircuitScriptVisitor.d.ts +115 -0
  53. package/dist/types/draw_symbols.d.ts +162 -0
  54. package/dist/types/execute.d.ts +85 -0
  55. package/dist/types/export.d.ts +2 -0
  56. package/dist/types/fonts.d.ts +1 -0
  57. package/dist/types/geometry.d.ts +84 -0
  58. package/dist/types/globals.d.ts +50 -0
  59. package/dist/types/helpers.d.ts +9 -0
  60. package/dist/types/index.d.ts +13 -0
  61. package/dist/types/layout.d.ts +147 -0
  62. package/dist/types/lexer.d.ts +19 -0
  63. package/dist/types/logger.d.ts +6 -0
  64. package/dist/types/main.d.ts +2 -0
  65. package/dist/types/objects/ClassComponent.d.ts +40 -0
  66. package/dist/types/objects/ExecutionScope.d.ts +64 -0
  67. package/dist/types/objects/Frame.d.ts +15 -0
  68. package/dist/types/objects/Net.d.ts +10 -0
  69. package/dist/types/objects/ParamDefinition.d.ts +20 -0
  70. package/dist/types/objects/PinDefinition.d.ts +24 -0
  71. package/dist/types/objects/PinTypes.d.ts +7 -0
  72. package/dist/types/objects/Wire.d.ts +11 -0
  73. package/dist/types/objects/types.d.ts +49 -0
  74. package/dist/types/parser.d.ts +38 -0
  75. package/dist/types/regenerate-tests.d.ts +1 -0
  76. package/dist/types/render.d.ts +10 -0
  77. package/dist/types/server.d.ts +1 -0
  78. package/dist/types/sizing.d.ts +15 -0
  79. package/dist/types/utils.d.ts +19 -0
  80. package/dist/types/visitor.d.ts +135 -0
  81. package/package.json +30 -12
  82. package/.editorconfig +0 -15
  83. package/.eslintignore +0 -1
  84. package/.eslintrc.json +0 -27
  85. package/.gitlab-ci.yml +0 -81
  86. package/.prettierignore +0 -8
  87. package/.prettierrc +0 -16
  88. package/__tests__/expectedResults.ts +0 -657
  89. package/__tests__/helpers.ts +0 -82
  90. package/__tests__/parseScripts.ts +0 -593
  91. package/__tests__/renderData/script1.cst +0 -58
  92. package/__tests__/renderData/script1.cst.svg +0 -1
  93. package/__tests__/renderData/script2.cst +0 -16
  94. package/__tests__/renderData/script2.cst.svg +0 -1
  95. package/__tests__/renderData/script3.cst +0 -30
  96. package/__tests__/renderData/script3.cst.svg +0 -1
  97. package/__tests__/renderData/script4.cst +0 -54
  98. package/__tests__/renderData/script4.cst.svg +0 -1
  99. package/__tests__/renderData/script5.cst +0 -23
  100. package/__tests__/renderData/script5.cst.svg +0 -1
  101. package/__tests__/renderData/script6.cst +0 -28
  102. package/__tests__/renderData/script6.cst.svg +0 -1
  103. package/__tests__/renderData/script7.cst +0 -26
  104. package/__tests__/renderData/script7.cst.svg +0 -1
  105. package/__tests__/renderData/script8.cst +0 -37
  106. package/__tests__/renderData/script8.cst.svg +0 -1
  107. package/__tests__/testCLI.ts +0 -68
  108. package/__tests__/testMathOps.ts +0 -36
  109. package/__tests__/testMergeWires.ts +0 -141
  110. package/__tests__/testParse.ts +0 -263
  111. package/__tests__/testRender.ts +0 -38
  112. package/build/src/parser.js +0 -69
  113. package/documentation.md +0 -238
  114. package/examples/example_arduino_uno.cst +0 -1146
  115. package/examples/example_garden_pump.cst +0 -567
  116. package/examples/lib.cst +0 -185
  117. package/fonts/Inter-Bold.ttf +0 -0
  118. package/fonts/Inter-Regular.ttf +0 -0
  119. package/fonts/OpenSans-Regular.ttf +0 -0
  120. package/fonts/Roboto-Regular.ttf +0 -0
  121. package/jest.config.js +0 -23
  122. package/libs/lib.cst +0 -185
  123. package/refresh.html +0 -42
  124. package/server.cjs +0 -50
  125. package/src/antlr/CircuitScript.g4 +0 -209
  126. package/src/antlr/CircuitScriptLexer.ts +0 -317
  127. package/src/antlr/CircuitScriptParser.ts +0 -4979
  128. package/src/antlr/CircuitScriptVisitor.ts +0 -420
  129. package/src/execute.ts +0 -1227
  130. package/src/fonts.ts +0 -1
  131. package/src/geometry.ts +0 -638
  132. package/src/globals.ts +0 -67
  133. package/src/helpers.ts +0 -114
  134. package/src/lexer.ts +0 -151
  135. package/src/logger.ts +0 -17
  136. package/src/main.ts +0 -105
  137. package/src/objects/ClassComponent.ts +0 -223
  138. package/src/objects/ExecutionScope.ts +0 -201
  139. package/src/objects/Frame.ts +0 -20
  140. package/src/objects/ParamDefinition.ts +0 -49
  141. package/src/objects/PinDefinition.ts +0 -49
  142. package/src/objects/PinTypes.ts +0 -7
  143. package/src/objects/Wire.ts +0 -19
  144. package/src/objects/types.ts +0 -66
  145. package/src/parser.ts +0 -106
  146. package/src/regenerate-tests.ts +0 -25
  147. package/src/render.ts +0 -260
  148. package/src/sizing.ts +0 -96
  149. package/tsconfig.json +0 -26
  150. package/tsconfig.release.json +0 -8
  151. /package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +0 -0
  152. /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
  153. /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
  154. /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
  155. /package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +0 -0
  156. /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
  157. /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
  158. /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
  159. /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
  160. /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
  161. /package/{build/src/objects/types.js → dist/esm/objects/types.mjs} +0 -0
  162. /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
  163. /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
@@ -1,448 +1,327 @@
1
- import { G } from "@svgdotjs/svg.js";
2
-
3
- import { SymbolPinSide, bodyColor, defaultFontBold, defaultFont } from "./globals.js";
4
- import { Feature, Geometry, GeometryProp, HorizontalAlign, Label, LabelStyle, VerticalAlign } from "./geometry.js";
5
- import { Logger } from "./logger.js";
6
-
7
-
8
- /**
9
- * Symbols should also define where their ports
10
- */
11
-
12
- const defaultSymbolLineColor = '#333';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SymbolDrawingCommands = exports.SymbolDrawing = exports.SymbolCustom = exports.PlaceHolderCommands = exports.SymbolPlaceholder = exports.SymbolText = exports.SymbolPointHidden = exports.SymbolFactory = exports.SymbolGraphic = void 0;
4
+ const globals_js_1 = require("./globals.js");
5
+ const geometry_js_1 = require("./geometry.js");
13
6
  const defaultSymbolLineWidth = 2;
14
-
15
- export abstract class SymbolGraphic {
16
-
17
- drawPortsName = true;
18
-
19
- displayBounds = true;
20
-
21
- drawing: SymbolDrawing;
22
-
23
- _angle = 0;
24
-
25
- width: number;
26
- height: number;
27
-
28
- // Stores a reference of <labelID> to the label value
29
- labelTexts = new Map<string, string>();
30
-
31
- get angle(): number {
7
+ class SymbolGraphic {
8
+ constructor() {
9
+ this.drawPortsName = true;
10
+ this.displayBounds = true;
11
+ this._angle = 0;
12
+ this.labelTexts = new Map();
13
+ }
14
+ get angle() {
32
15
  return (this._angle % 360);
33
16
  }
34
-
35
- set angle(value: number) {
17
+ set angle(value) {
36
18
  this._angle = value;
37
19
  }
38
-
39
- refreshDrawing(calculateSize = true): void {
20
+ refreshDrawing(calculateSize = true) {
40
21
  this.generateDrawing();
41
22
  calculateSize && this.calculateSize();
42
23
  }
43
-
44
- calculateSize(): void {
24
+ calculateSize() {
45
25
  const { width, height } = this.drawing.getBoundingBox();
46
26
  this.width = width;
47
27
  this.height = height;
48
28
  }
49
-
50
- // Subclasses should implement this
51
- abstract generateDrawing(): void;
52
-
53
- size(): { width: number; height: number; } {
29
+ size() {
54
30
  return {
55
31
  width: this.width,
56
32
  height: this.height
57
- }
33
+ };
58
34
  }
59
-
60
- draw(group: G, extra?: {}): void {
61
- // Assume that the symbol is vertical
35
+ draw(group, extra) {
62
36
  const innerGroup = group.group();
63
-
64
37
  this.drawBody(innerGroup);
65
-
66
38
  this.drawPins(innerGroup);
67
-
68
39
  this.drawLabels(innerGroup);
69
-
70
40
  this.drawPlaceRemove(innerGroup, extra);
71
-
72
- // this.displayBounds && this.drawBounds(group);
73
41
  }
74
-
75
- drawPlaceRemove(group: G, extra?: { place?: boolean }): void {
42
+ drawPlaceRemove(group, extra) {
76
43
  if (extra && extra.place === false) {
77
- // Do not place this component!
78
- // Draw the x
79
44
  const { start, end } = this.drawing.getBoundingBox(true);
80
-
81
45
  group.path([
82
46
  "M", start[0], start[1], "L", end[0], end[1],
83
47
  "M", end[0], start[1], "L", start[0], end[1]
84
48
  ].join(" "))
85
49
  .stroke({
86
- width: defaultSymbolLineWidth,
87
- color: 'red'
88
- });
50
+ width: defaultSymbolLineWidth,
51
+ color: 'red'
52
+ });
89
53
  }
90
54
  }
91
-
92
- // Returns the port position, relative to the symbol origin
93
- pinPosition(id: number): { x: number; y: number; angle: number; } {
55
+ pinPosition(id) {
94
56
  const pin = this.drawing.getPinPosition(id);
95
-
96
- // Allow pin position values to be rounded to 4 d.p
97
57
  const [x, y] = pin.start;
98
58
  const useX = Math.round(x * 10000) / 10000;
99
59
  const useY = Math.round(y * 10000 / 10000);
100
-
101
- if (pin) {
102
- return {
103
- x: useX,
104
- y: useY,
105
- angle: pin.angle,
106
- }
107
- }
60
+ return {
61
+ x: useX,
62
+ y: useY,
63
+ angle: pin.angle,
64
+ };
108
65
  }
109
-
110
- protected drawBounds(group: G): void {
66
+ drawBounds(group) {
111
67
  const bbox = this.drawing.getBoundingBox();
112
-
113
68
  group.circle(3)
114
69
  .translate(-3 / 2, -3 / 2)
115
70
  .fill('red')
116
71
  .stroke('none');
117
-
118
72
  group.rect(bbox.width, bbox.height)
119
73
  .translate(bbox.start[0], bbox.start[1])
120
74
  .fill('none')
121
75
  .stroke({
122
- width: 1,
123
- color: '#ccc',
124
- })
76
+ width: 1,
77
+ color: '#ccc',
78
+ });
125
79
  }
126
-
127
- protected drawBody(group: G): void {
128
- // Draws the symbol body
129
-
80
+ drawBody(group) {
130
81
  const paths = this.drawing.getPaths();
131
82
  paths.forEach(pathInfo => {
132
- const {path, lineColor, fillColor, lineWidth} = pathInfo;
83
+ const { path, lineColor, fillColor, lineWidth } = pathInfo;
133
84
  group.path(path)
134
85
  .stroke({
135
- width: lineWidth,
136
- color: lineColor,
137
- })
138
- .fill(fillColor)
86
+ width: lineWidth,
87
+ color: lineColor,
88
+ })
89
+ .fill(fillColor);
139
90
  });
140
91
  }
141
-
142
- protected drawPins(group: G): void {
143
- // Draw pins
92
+ drawPins(group) {
144
93
  group.path(this.drawing.getPinsPath())
145
94
  .stroke({
146
- width: defaultSymbolLineWidth,
147
- color: '#333',
148
- });
95
+ width: defaultSymbolLineWidth,
96
+ color: '#333',
97
+ });
149
98
  }
150
-
151
- protected drawLabels(group: G): void {
99
+ drawLabels(group) {
152
100
  const labels = this.drawing.getLabels();
153
-
154
101
  labels.forEach(label => {
155
- const tmpLabel = label as Label;
156
-
157
- const {
158
- fontSize = 10,
159
- anchor = HorizontalAlign.Left,
160
- vanchor = VerticalAlign.Bottom,
161
- fontWeight = 'regular',
162
- angle: labelAngle = 0,
163
- } = tmpLabel.style ?? {};
164
-
102
+ const tmpLabel = label;
103
+ const { fontSize = 10, anchor = geometry_js_1.HorizontalAlign.Left, vanchor = geometry_js_1.VerticalAlign.Bottom, fontWeight = 'regular', angle: labelAngle = 0, } = tmpLabel.style ?? {};
165
104
  let anchorStyle = 'start';
166
105
  let dominantBaseline = 'auto';
167
-
168
106
  let useAnchor = anchor;
169
107
  let useDominantBaseline = vanchor;
170
108
  const isRotation180 = Math.abs(this.angle) === 180;
171
-
172
109
  if (isRotation180) {
173
- // Special case to flip the text instead of rotating
174
110
  useAnchor = this.flipTextAnchor(anchor);
175
111
  useDominantBaseline = this.flipDominantBaseline(vanchor);
176
112
  }
177
-
178
- switch(useAnchor){
179
- case HorizontalAlign.Left:
113
+ switch (useAnchor) {
114
+ case geometry_js_1.HorizontalAlign.Left:
180
115
  anchorStyle = 'start';
181
116
  break;
182
-
183
- case HorizontalAlign.Middle:
117
+ case geometry_js_1.HorizontalAlign.Middle:
184
118
  anchorStyle = 'middle';
185
119
  break;
186
-
187
- case HorizontalAlign.Right:
120
+ case geometry_js_1.HorizontalAlign.Right:
188
121
  anchorStyle = 'end';
189
122
  break;
190
123
  }
191
-
192
- switch(useDominantBaseline){
193
- case VerticalAlign.Top:
124
+ switch (useDominantBaseline) {
125
+ case geometry_js_1.VerticalAlign.Top:
194
126
  dominantBaseline = 'hanging';
195
127
  break;
196
-
197
- case VerticalAlign.Middle:
128
+ case geometry_js_1.VerticalAlign.Middle:
198
129
  dominantBaseline = 'middle';
199
130
  break;
200
-
201
- case VerticalAlign.Bottom:
131
+ case geometry_js_1.VerticalAlign.Bottom:
202
132
  dominantBaseline = 'text-top';
203
133
  break;
204
134
  }
205
-
206
135
  const position = tmpLabel.getLabelPosition();
207
- const useFont = defaultFont;
208
-
136
+ const useFont = globals_js_1.defaultFont;
209
137
  const textContainer = group.group();
210
138
  const text = textContainer.text(tmpLabel.text)
211
139
  .fill('#333')
212
140
  .font({
213
- family: useFont,
214
- size: fontSize,
215
- anchor: anchorStyle,
216
- 'dominant-baseline': dominantBaseline,
217
- weight: fontWeight,
218
- });
219
-
220
- let translateX: number, translateY: number;
141
+ family: useFont,
142
+ size: fontSize,
143
+ anchor: anchorStyle,
144
+ 'dominant-baseline': dominantBaseline,
145
+ weight: fontWeight,
146
+ });
147
+ let translateX, translateY;
221
148
  let useRotateAngle = 0;
222
-
223
- if (isRotation180){
149
+ if (isRotation180) {
224
150
  translateX = -position[0];
225
151
  translateY = -position[1];
226
152
  useRotateAngle = 0;
227
- } else {
153
+ }
154
+ else {
228
155
  translateX = position[0];
229
156
  translateY = position[1];
230
157
  useRotateAngle = this.angle;
231
158
  }
232
-
233
159
  text.rotate(labelAngle);
234
160
  textContainer.translate(translateX, translateY)
235
- .rotate(useRotateAngle, -translateX, -translateY);
236
-
237
- // For debug, show the origin of the text container
238
- // textContainer.circle(2).fill('red');
161
+ .rotate(useRotateAngle, -translateX, -translateY);
239
162
  });
240
163
  }
241
-
242
- flipTextAnchor(value: HorizontalAlign): HorizontalAlign {
243
- if (value === HorizontalAlign.Left) {
244
- return HorizontalAlign.Right
245
- } else if (value === HorizontalAlign.Right) {
246
- return HorizontalAlign.Left;
247
- } else {
248
- return HorizontalAlign.Middle;
164
+ flipTextAnchor(value) {
165
+ if (value === geometry_js_1.HorizontalAlign.Left) {
166
+ return geometry_js_1.HorizontalAlign.Right;
167
+ }
168
+ else if (value === geometry_js_1.HorizontalAlign.Right) {
169
+ return geometry_js_1.HorizontalAlign.Left;
170
+ }
171
+ else {
172
+ return geometry_js_1.HorizontalAlign.Middle;
249
173
  }
250
174
  }
251
-
252
- flipDominantBaseline(value: VerticalAlign): VerticalAlign {
253
- if (value === VerticalAlign.Top) {
254
- return VerticalAlign.Bottom;
255
- } else if (value === VerticalAlign.Bottom) {
256
- return VerticalAlign.Top;
257
- } else {
258
- return VerticalAlign.Middle;
175
+ flipDominantBaseline(value) {
176
+ if (value === geometry_js_1.VerticalAlign.Top) {
177
+ return geometry_js_1.VerticalAlign.Bottom;
178
+ }
179
+ else if (value === geometry_js_1.VerticalAlign.Bottom) {
180
+ return geometry_js_1.VerticalAlign.Top;
181
+ }
182
+ else {
183
+ return geometry_js_1.VerticalAlign.Middle;
259
184
  }
260
185
  }
261
-
262
- setLabelValue(labelId: string, labelValue: string): void {
186
+ setLabelValue(labelId, labelValue) {
263
187
  this.labelTexts.set(labelId, labelValue);
264
188
  }
265
-
266
- getLabelValue(labelId: string): string {
189
+ getLabelValue(labelId) {
267
190
  if (this.labelTexts.has(labelId)) {
268
191
  return this.labelTexts.get(labelId);
269
192
  }
193
+ return undefined;
270
194
  }
271
195
  }
272
-
273
- export function SymbolFactory(name: string): SymbolGraphic | null {
196
+ exports.SymbolGraphic = SymbolGraphic;
197
+ function SymbolFactory(name) {
274
198
  switch (name) {
275
199
  case 'point':
276
200
  return new SymbolPointHidden();
277
201
  }
202
+ return null;
278
203
  }
279
-
280
- export class SymbolPointHidden extends SymbolGraphic {
281
- generateDrawing(): void {
204
+ exports.SymbolFactory = SymbolFactory;
205
+ class SymbolPointHidden extends SymbolGraphic {
206
+ generateDrawing() {
282
207
  const drawing = new SymbolDrawing();
283
208
  drawing.addPin(1, 0, 0, 0, 0);
284
-
285
209
  this.drawing = drawing;
286
210
  }
287
211
  }
288
-
289
- export class SymbolText extends SymbolGraphic {
290
-
291
- text: string;
292
- fontSize = 10;
293
- fontWeight = 'regular';
294
-
295
- constructor(text: string){
212
+ exports.SymbolPointHidden = SymbolPointHidden;
213
+ class SymbolText extends SymbolGraphic {
214
+ constructor(text) {
296
215
  super();
216
+ this.fontSize = 10;
217
+ this.fontWeight = 'regular';
297
218
  this.text = text;
298
219
  }
299
-
300
- generateDrawing(): void {
220
+ generateDrawing() {
301
221
  const drawing = new SymbolDrawing();
302
222
  drawing.addLabel(0, 0, this.text, {
303
223
  fontSize: this.fontSize,
304
- anchor: HorizontalAlign.Middle,
224
+ anchor: geometry_js_1.HorizontalAlign.Middle,
305
225
  fontWeight: this.fontWeight,
306
226
  });
307
-
308
227
  this.drawing = drawing;
309
228
  }
310
229
  }
311
-
312
- export class SymbolPlaceholder extends SymbolGraphic {
313
- // This is used if the drawing object is defined within
314
- // circuitscript code itself.
315
- generateDrawing(): void {
316
- const drawing = this.drawing as SymbolDrawingCommands;
317
-
230
+ exports.SymbolText = SymbolText;
231
+ class SymbolPlaceholder extends SymbolGraphic {
232
+ generateDrawing() {
233
+ const drawing = this.drawing;
318
234
  drawing.log("=== start generate drawing ===");
319
-
320
235
  drawing.clear();
321
236
  drawing.angle = this._angle;
322
237
  const commands = drawing.getCommands();
323
-
324
238
  drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
325
-
326
239
  commands.forEach(([commandName, positionParams, keywordParams]) => {
327
240
  switch (commandName) {
328
241
  case PlaceHolderCommands.rect:
329
242
  drawing.log('add rect', ...positionParams);
330
243
  drawing.addRect(...positionParams);
331
244
  break;
332
-
333
245
  case PlaceHolderCommands.hline:
334
246
  drawing.log('add hline', ...positionParams);
335
247
  drawing.addHLine(...positionParams);
336
248
  break;
337
-
338
249
  case PlaceHolderCommands.vline:
339
250
  drawing.log('add vline', ...positionParams);
340
251
  drawing.addVLine(...positionParams);
341
252
  break;
342
-
343
253
  case PlaceHolderCommands.line:
344
254
  drawing.log('add line', ...positionParams);
345
255
  drawing.addLine(...positionParams);
346
256
  break;
347
-
348
257
  case PlaceHolderCommands.path:
349
258
  drawing.addPath(...positionParams);
350
259
  break;
351
-
352
260
  case PlaceHolderCommands.lineWidth:
353
261
  drawing.addSetLineWidth(...positionParams);
354
262
  break;
355
-
356
263
  case PlaceHolderCommands.fill:
357
264
  drawing.addSetFillColor(...positionParams);
358
265
  break;
359
-
360
266
  case PlaceHolderCommands.lineColor:
361
267
  drawing.addSetLineColor(...positionParams);
362
268
  break;
363
-
364
269
  case PlaceHolderCommands.arc:
365
270
  drawing.addArc(...positionParams);
366
271
  break;
367
-
368
272
  case PlaceHolderCommands.circle:
369
- // circle params: center x, center y, radius
370
273
  drawing.addArc(...positionParams, 0, 360);
371
274
  break;
372
-
373
275
  case PlaceHolderCommands.triangle:
374
276
  drawing.addTriangle(...positionParams);
375
277
  break;
376
-
377
- case PlaceHolderCommands.pin:
278
+ case PlaceHolderCommands.pin:
378
279
  case PlaceHolderCommands.hpin:
379
280
  case PlaceHolderCommands.vpin:
380
- {
381
- this.drawPinParams(drawing, commandName,
382
- keywordParams, positionParams);
383
- break;
384
- }
385
-
281
+ {
282
+ this.drawPinParams(drawing, commandName, keywordParams, positionParams);
283
+ break;
284
+ }
386
285
  case PlaceHolderCommands.label: {
387
286
  const keywords = ['fontSize', 'anchor', 'vanchor', 'angle'];
388
-
389
- // Create the style object
390
287
  const style = {};
391
288
  keywords.forEach(item => {
392
289
  if (keywordParams.has(item)) {
393
290
  style[item] = keywordParams.get(item);
394
291
  }
395
292
  });
396
-
397
293
  positionParams = [...positionParams];
398
294
  positionParams.push(style);
399
-
400
295
  const labelId = positionParams[0];
401
-
402
296
  const tmpPositionParams = [...positionParams];
403
-
404
297
  const tmpLabelValue = this.getLabelValue(labelId);
405
298
  if (tmpLabelValue !== undefined) {
406
299
  tmpPositionParams[3] = tmpLabelValue;
407
300
  }
408
-
409
301
  drawing.log('add label', JSON.stringify(tmpPositionParams));
410
302
  drawing.addLabelId(...tmpPositionParams);
411
303
  break;
412
304
  }
413
305
  }
414
306
  });
415
-
416
307
  drawing.log("=== end generate drawing ===");
417
308
  }
418
-
419
- drawPinParams(drawing: SymbolDrawingCommands,
420
- commandName: string, keywordParams: Map<string, any>,
421
- positionParams: any[]): void {
422
-
309
+ drawPinParams(drawing, commandName, keywordParams, positionParams) {
423
310
  drawing.log('add pin', ...positionParams);
424
-
425
311
  const keywordDisplayPinId = 'display_pin_id';
426
312
  let displayPinId = true;
427
-
428
313
  if (keywordParams.has(keywordDisplayPinId)) {
429
314
  if (keywordParams.get(keywordDisplayPinId) === 0) {
430
315
  displayPinId = false;
431
316
  }
432
317
  }
433
-
434
- let pinNameParam: string | null = null;
318
+ let pinNameParam = null;
435
319
  if (typeof positionParams[1] === 'string') {
436
- // If the type of the second position is a string, then
437
- // use the string value as the pin name
438
320
  pinNameParam = positionParams[1];
439
321
  positionParams = [positionParams[0], ...positionParams.slice(2)];
440
322
  }
441
-
442
- // create the next point
443
323
  const startX = positionParams[1];
444
324
  const startY = positionParams[2];
445
-
446
325
  if (commandName === PlaceHolderCommands.vpin) {
447
326
  const magnitude = positionParams[3];
448
327
  positionParams = [
@@ -452,7 +331,8 @@ export class SymbolPlaceholder extends SymbolGraphic {
452
331
  startX,
453
332
  startY + magnitude
454
333
  ];
455
- } else if (commandName === PlaceHolderCommands.hpin) {
334
+ }
335
+ else if (commandName === PlaceHolderCommands.hpin) {
456
336
  const magnitude = positionParams[3];
457
337
  positionParams = [
458
338
  positionParams[0],
@@ -462,485 +342,349 @@ export class SymbolPlaceholder extends SymbolGraphic {
462
342
  startY
463
343
  ];
464
344
  }
465
-
466
345
  drawing.addPin(...positionParams);
467
-
468
- // Add a label for the pinId and pinName
469
346
  const latestPin = this.drawing.pins[this.drawing.pins.length - 1];
470
347
  const [pinId, , angle] = latestPin;
471
348
  const [, , , endX, endY] = positionParams;
472
-
473
- let pinNameAlignment = HorizontalAlign.Left;
349
+ let pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
474
350
  let pinNameOffsetX = 4;
475
-
476
351
  let pinIdOffsetX = 0;
477
- let pinIdAlignment = HorizontalAlign.Left;
478
-
479
- let pinIdVAlignment = VerticalAlign.Bottom;
352
+ let pinIdAlignment = geometry_js_1.HorizontalAlign.Left;
353
+ let pinIdVAlignment = geometry_js_1.VerticalAlign.Bottom;
480
354
  let pinIdOffsetY = -2;
481
-
482
355
  switch (angle) {
483
356
  case 0:
484
- pinNameAlignment = HorizontalAlign.Left;
357
+ pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
485
358
  pinNameOffsetX = 4;
486
- pinIdAlignment = HorizontalAlign.Right;
359
+ pinIdAlignment = geometry_js_1.HorizontalAlign.Right;
487
360
  pinIdOffsetX = -2;
488
361
  break;
489
362
  case 90:
490
363
  case 180:
491
- pinNameAlignment = HorizontalAlign.Right;
364
+ pinNameAlignment = geometry_js_1.HorizontalAlign.Right;
492
365
  pinNameOffsetX = -4;
493
- pinIdAlignment = HorizontalAlign.Left;
366
+ pinIdAlignment = geometry_js_1.HorizontalAlign.Left;
494
367
  pinIdOffsetX = 2;
495
368
  break;
496
369
  case 270:
497
- pinNameAlignment = HorizontalAlign.Left;
370
+ pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
498
371
  pinNameOffsetX = 4;
499
- pinIdAlignment = HorizontalAlign.Left;
372
+ pinIdAlignment = geometry_js_1.HorizontalAlign.Left;
500
373
  pinIdOffsetX = 2;
501
374
  pinIdOffsetY = 2;
502
- pinIdVAlignment = VerticalAlign.Top;
375
+ pinIdVAlignment = geometry_js_1.VerticalAlign.Top;
503
376
  break;
504
377
  }
505
-
506
378
  if (angle === 0 || angle === 90 || angle === 180 || angle === 270) {
507
379
  const usePinName = pinNameParam ?? "";
508
-
509
- // Draw the pinName
510
- usePinName !== "" && drawing.addLabel(
511
- endX + pinNameOffsetX, endY, usePinName, {
380
+ usePinName !== "" && drawing.addLabel(endX + pinNameOffsetX, endY, usePinName, {
512
381
  fontSize: 10,
513
382
  anchor: pinNameAlignment,
514
- vanchor: VerticalAlign.Middle,
383
+ vanchor: geometry_js_1.VerticalAlign.Middle,
515
384
  });
516
-
517
- // Draw pin Id
518
- displayPinId && drawing.addLabel(
519
- endX + pinIdOffsetX, endY + pinIdOffsetY, pinId.toString(), {
385
+ displayPinId && drawing.addLabel(endX + pinIdOffsetX, endY + pinIdOffsetY, pinId.toString(), {
520
386
  fontSize: 8,
521
387
  anchor: pinIdAlignment,
522
388
  vanchor: pinIdVAlignment,
523
389
  });
524
390
  }
525
391
  }
526
-
527
- constructor(drawing: SymbolDrawing) {
392
+ constructor(drawing) {
528
393
  super();
529
394
  this.drawing = drawing;
530
395
  }
531
396
  }
532
-
533
- export enum PlaceHolderCommands {
534
- arc = 'arc',
535
- circle = 'circle',
536
- rect = 'rect',
537
- triangle = 'triangle',
538
- pin = 'pin',
539
- hpin = 'hpin',
540
- vpin = 'vpin',
541
- hline = 'hline',
542
- vline = 'vline',
543
- line = 'line',
544
- label = 'label',
545
- path = 'path',
546
- lineWidth = 'lineWidth',
547
- fill = 'fill',
548
- lineColor = 'lineColor'
549
- }
550
-
551
- export class SymbolCustom extends SymbolGraphic {
552
-
553
- pinDefinition: SymbolPinDefintion[] = [];
554
-
555
- bodyWidth = 100;
556
-
557
- pinLength = 20;
558
-
559
- width = 100;
560
- height = 100;
561
-
562
- pinSpacing = 20;
563
-
564
- pinTextPadding = 5;
565
-
566
- pins: SymbolPinLayout[] = [];
567
-
568
- _cacheLeftPins: SymbolPinDefintion[];
569
- _cacheRightPins: SymbolPinDefintion[];
570
-
571
- constructor(pinDefinition: SymbolPinDefintion[]) {
397
+ exports.SymbolPlaceholder = SymbolPlaceholder;
398
+ var PlaceHolderCommands;
399
+ (function (PlaceHolderCommands) {
400
+ PlaceHolderCommands["arc"] = "arc";
401
+ PlaceHolderCommands["circle"] = "circle";
402
+ PlaceHolderCommands["rect"] = "rect";
403
+ PlaceHolderCommands["triangle"] = "triangle";
404
+ PlaceHolderCommands["pin"] = "pin";
405
+ PlaceHolderCommands["hpin"] = "hpin";
406
+ PlaceHolderCommands["vpin"] = "vpin";
407
+ PlaceHolderCommands["hline"] = "hline";
408
+ PlaceHolderCommands["vline"] = "vline";
409
+ PlaceHolderCommands["line"] = "line";
410
+ PlaceHolderCommands["label"] = "label";
411
+ PlaceHolderCommands["path"] = "path";
412
+ PlaceHolderCommands["lineWidth"] = "lineWidth";
413
+ PlaceHolderCommands["fill"] = "fill";
414
+ PlaceHolderCommands["lineColor"] = "lineColor";
415
+ })(PlaceHolderCommands || (exports.PlaceHolderCommands = PlaceHolderCommands = {}));
416
+ class SymbolCustom extends SymbolGraphic {
417
+ constructor(pinDefinition) {
572
418
  super();
573
-
574
- // define the left and right pins only for now
419
+ this.pinDefinition = [];
420
+ this.bodyWidth = 100;
421
+ this.pinLength = 20;
422
+ this.width = 100;
423
+ this.height = 100;
424
+ this.pinSpacing = 20;
425
+ this.pinTextPadding = 5;
426
+ this.pins = [];
575
427
  this.pinDefinition = pinDefinition;
576
428
  }
577
-
578
- generateDrawing(): void {
579
- // Determine the size based on the definition
580
-
429
+ generateDrawing() {
581
430
  const leftPins = this.pinDefinition.filter(item => {
582
- return item.side === SymbolPinSide.Left;
431
+ return item.side === globals_js_1.SymbolPinSide.Left;
583
432
  });
584
-
585
433
  const rightPins = this.pinDefinition.filter(item => {
586
- return item.side === SymbolPinSide.Right;
434
+ return item.side === globals_js_1.SymbolPinSide.Right;
587
435
  });
588
-
589
436
  const maxLeftPins = Math.max(...leftPins.map(item => item.position)) + 1;
590
437
  const maxRightPins = Math.max(...rightPins.map(item => item.position)) + 1;
591
-
592
438
  const drawing = new SymbolDrawing();
593
439
  drawing.angle = this._angle;
594
-
595
440
  const bodyWidth = this.bodyWidth;
596
441
  const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
597
-
598
- // drawing.addSetFillColor(bodyColor);
599
-
600
442
  drawing.addRect(0, 0, bodyWidth, bodyHeight);
601
-
602
- // Setup the pins
603
443
  const leftPinStart = -bodyWidth / 2;
604
444
  const rightPinStart = bodyWidth / 2;
605
445
  const pinStartY = -bodyHeight / 2;
606
-
607
446
  leftPins.forEach(pin => {
608
447
  const position = pin.position;
609
- const pinY = pinStartY + (position + 1) * this.pinSpacing // Includes the offset too
448
+ const pinY = pinStartY + (position + 1) * this.pinSpacing;
610
449
  drawing.addPin(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY);
611
-
612
450
  drawing.addLabel(leftPinStart + 4, pinY, pin.text, {
613
451
  fontSize: 10,
614
- anchor: HorizontalAlign.Left,
615
- vanchor: VerticalAlign.Middle,
452
+ anchor: geometry_js_1.HorizontalAlign.Left,
453
+ vanchor: geometry_js_1.VerticalAlign.Middle,
616
454
  });
617
-
618
- // Add the pin number
619
- drawing.addLabel(leftPinStart - 2 , pinY - 2, pin.pinId.toString(), {
455
+ drawing.addLabel(leftPinStart - 2, pinY - 2, pin.pinId.toString(), {
620
456
  fontSize: 8,
621
- anchor: HorizontalAlign.Right,
622
- vanchor: VerticalAlign.Bottom,
457
+ anchor: geometry_js_1.HorizontalAlign.Right,
458
+ vanchor: geometry_js_1.VerticalAlign.Bottom,
623
459
  });
624
460
  });
625
-
626
461
  rightPins.forEach(pin => {
627
462
  const position = pin.position;
628
- const pinY = pinStartY + (position + 1) * this.pinSpacing // Includes the offset too
463
+ const pinY = pinStartY + (position + 1) * this.pinSpacing;
629
464
  drawing.addPin(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY);
630
-
631
465
  drawing.addLabel(rightPinStart - 4, pinY, pin.text, {
632
466
  fontSize: 10,
633
- anchor: HorizontalAlign.Right,
634
- vanchor: VerticalAlign.Middle,
467
+ anchor: geometry_js_1.HorizontalAlign.Right,
468
+ vanchor: geometry_js_1.VerticalAlign.Middle,
635
469
  });
636
-
637
- // Add the pin number
638
- drawing.addLabel(rightPinStart + 2 , pinY - 2, pin.pinId.toString(), {
470
+ drawing.addLabel(rightPinStart + 2, pinY - 2, pin.pinId.toString(), {
639
471
  fontSize: 8,
640
- anchor: HorizontalAlign.Left,
641
- vanchor: VerticalAlign.Bottom,
472
+ anchor: geometry_js_1.HorizontalAlign.Left,
473
+ vanchor: geometry_js_1.VerticalAlign.Bottom,
642
474
  });
643
475
  });
644
-
645
476
  const instanceName = this.getLabelValue("refdes");
646
- instanceName && drawing.addLabel(-bodyWidth/2, -bodyHeight/2 - 4, instanceName, {
477
+ instanceName && drawing.addLabel(-bodyWidth / 2, -bodyHeight / 2 - 4, instanceName, {
647
478
  fontSize: 10,
648
- anchor: HorizontalAlign.Left,
479
+ anchor: geometry_js_1.HorizontalAlign.Left,
649
480
  });
650
-
651
481
  const acceptedMPNKeys = ['MPN', 'mpn', 'manufacturer_pn'];
652
-
653
482
  acceptedMPNKeys.some(key => {
654
483
  const labelValue = this.getLabelValue(key);
655
- if (labelValue !== undefined){
656
- drawing.addLabel(-bodyWidth/2, bodyHeight/2 + 4, labelValue, {
484
+ if (labelValue !== undefined) {
485
+ drawing.addLabel(-bodyWidth / 2, bodyHeight / 2 + 4, labelValue, {
657
486
  fontSize: 10,
658
- anchor: HorizontalAlign.Left,
659
- vanchor: VerticalAlign.Top,
487
+ anchor: geometry_js_1.HorizontalAlign.Left,
488
+ vanchor: geometry_js_1.VerticalAlign.Top,
660
489
  });
661
490
  }
662
491
  });
663
-
664
492
  this.drawing = drawing;
665
493
  this._cacheLeftPins = leftPins;
666
494
  this._cacheRightPins = rightPins;
667
495
  }
668
-
669
- calculateSize(): void {
670
- // This width also includes the pin length
496
+ calculateSize() {
671
497
  this.width = this.bodyWidth + 2 * this.pinLength;
672
- this.height = (1 + Math.max(this._cacheLeftPins.length,
673
- this._cacheRightPins.length)) * this.pinSpacing;
498
+ this.height = (1 + Math.max(this._cacheLeftPins.length, this._cacheRightPins.length)) * this.pinSpacing;
674
499
  }
675
-
676
500
  }
677
-
678
-
679
- export class SymbolDrawing {
680
-
681
- items: (Feature | GeometryProp)[] = [];
682
-
683
- // pinId, feature, angle
684
- pins: [number, Feature, number][] = [];
685
-
686
- angle = 0;
687
-
688
- mainOrigin:[number, number] = [0, 0];
689
-
690
- logger: Logger = null;
691
-
692
- clear(): void {
501
+ exports.SymbolCustom = SymbolCustom;
502
+ class SymbolDrawing {
503
+ constructor() {
504
+ this.items = [];
505
+ this.pins = [];
506
+ this.angle = 0;
507
+ this.mainOrigin = [0, 0];
508
+ this.logger = null;
509
+ }
510
+ clear() {
693
511
  this.items = [];
694
512
  this.pins = [];
695
513
  }
696
-
697
- log(...params: any[]): void {
514
+ log(...params) {
698
515
  this.logger && this.logger.add(params.join(' '));
699
516
  }
700
-
701
- addLine(startX: number, startY: number, endX: number, endY: number): SymbolDrawing {
702
- this.items.push(
703
- Geometry.segment([startX, startY], [endX, endY])
704
- );
705
-
517
+ addLine(startX, startY, endX, endY) {
518
+ this.items.push(geometry_js_1.Geometry.segment([startX, startY], [endX, endY]));
706
519
  return this;
707
520
  }
708
-
709
- addPin(pinId: number, startX: number, startY: number,
710
- endX: number, endY: number): SymbolDrawing {
711
-
712
- // Determine the pin angle based on vector with start point
713
- // going to end point. The angle is relative to the x-axis.
714
- // 270
715
- // 180 -- start --> 0
716
- // 90
717
-
521
+ addPin(pinId, startX, startY, endX, endY) {
718
522
  let angle = 0;
719
523
  if (startX === endX) {
720
524
  if (startY > endY) {
721
525
  angle = 270;
722
- } else if (startY < endY) {
526
+ }
527
+ else if (startY < endY) {
723
528
  angle = 90;
724
529
  }
725
- } else {
530
+ }
531
+ else {
726
532
  if (startX < endX) {
727
533
  angle = 0;
728
- } else if (startX > endX) {
534
+ }
535
+ else if (startX > endX) {
729
536
  angle = 180;
730
537
  }
731
538
  }
732
-
733
539
  this.pins.push([
734
540
  pinId,
735
- Geometry.segment([startX, startY], [endX, endY]),
541
+ geometry_js_1.Geometry.segment([startX, startY], [endX, endY]),
736
542
  angle
737
543
  ]);
738
-
739
544
  return this;
740
545
  }
741
-
742
- addVLine(startX: number, startY: number, value: number): SymbolDrawing {
743
- this.items.push(
744
- Geometry.segment([startX, startY], [startX, startY + value])
745
- );
546
+ addVLine(startX, startY, value) {
547
+ this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX, startY + value]));
746
548
  return this;
747
549
  }
748
-
749
- addHLine(startX: number, startY: number, value: number): SymbolDrawing {
750
- this.items.push(
751
- Geometry.segment([startX, startY], [startX + value, startY])
752
- );
550
+ addHLine(startX, startY, value) {
551
+ this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX + value, startY]));
753
552
  return this;
754
553
  }
755
-
756
- addRect(centerX: number, centerY: number,width: number, height: number): SymbolDrawing {
757
- const width2 = width/2;
758
- const height2 = height/2;
759
-
760
- this.items.push(
761
- Geometry.polygon([
762
- [centerX - width2, centerY - height2],
763
- [centerX + width2, centerY - height2],
764
- [centerX + width2, centerY + height2],
765
- [centerX - width2, centerY + height2],
766
- [centerX - width2, centerY - height2]
767
- ])
768
- );
769
-
554
+ addRect(centerX, centerY, width, height) {
555
+ const width2 = width / 2;
556
+ const height2 = height / 2;
557
+ this.items.push(geometry_js_1.Geometry.polygon([
558
+ [centerX - width2, centerY - height2],
559
+ [centerX + width2, centerY - height2],
560
+ [centerX + width2, centerY + height2],
561
+ [centerX - width2, centerY + height2],
562
+ [centerX - width2, centerY - height2]
563
+ ]));
770
564
  return this;
771
565
  }
772
-
773
- addTriangle(startX: number, startY: number, endX: number, endY: number, width: number): SymbolDrawing {
774
- const line = Geometry.line(
775
- startX, startY,
776
- endX, endY);
777
-
566
+ addTriangle(startX, startY, endX, endY, width) {
567
+ const line = geometry_js_1.Geometry.line(startX, startY, endX, endY);
778
568
  const normLine = line.norm;
779
569
  const dx1 = normLine.x * width / 2;
780
570
  const dy1 = normLine.y * width / 2;
781
571
  const dx2 = normLine.x * -width / 2;
782
572
  const dy2 = normLine.y * -width / 2;
783
-
784
- this.items.push(
785
- Geometry.polygon([
786
- [dx1 + startX, dy1 + startY],
787
- [dx2 + startX, dy2 + startY],
788
- [endX, endY],
789
- [dx1 + startX, dy1 + startY],
790
- ])
791
- );
792
-
573
+ this.items.push(geometry_js_1.Geometry.polygon([
574
+ [dx1 + startX, dy1 + startY],
575
+ [dx2 + startX, dy2 + startY],
576
+ [endX, endY],
577
+ [dx1 + startX, dy1 + startY],
578
+ ]));
793
579
  return this;
794
580
  }
795
-
796
- addRect2(x: number, y: number, x2: number, y2: number): SymbolDrawing {
797
- this.items.push(
798
- Geometry.polygon([
799
- [x, y],
800
- [x2, y],
801
- [x2, y2],
802
- [x, y2],
803
- [x, y]
804
- ])
805
- );
806
-
581
+ addRect2(x, y, x2, y2) {
582
+ this.items.push(geometry_js_1.Geometry.polygon([
583
+ [x, y],
584
+ [x2, y],
585
+ [x2, y2],
586
+ [x, y2],
587
+ [x, y]
588
+ ]));
807
589
  return this;
808
590
  }
809
-
810
- addLabel(x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing {
811
- this.items.push(
812
- Geometry.label(null, x, y, textValue, style)
813
- )
814
-
591
+ addLabel(x, y, textValue, style) {
592
+ this.items.push(geometry_js_1.Geometry.label(null, x, y, textValue, style));
815
593
  return this;
816
594
  }
817
-
818
- addLabelId(id: string, x: number, y: number, textValue: string, style: LabelStyle,): SymbolDrawing {
819
- this.items.push(
820
- Geometry.label(id, x, y, textValue, style)
821
- )
822
-
595
+ addLabelId(id, x, y, textValue, style) {
596
+ this.items.push(geometry_js_1.Geometry.label(id, x, y, textValue, style));
823
597
  return this;
824
598
  }
825
-
826
- addPath(...pathParts:any): SymbolDrawing {
599
+ addPath(...pathParts) {
827
600
  const parts = pathParts.reduce((accum, tmp) => {
828
- if (typeof tmp === "string"){
601
+ if (typeof tmp === "string") {
829
602
  accum = accum.concat(tmp.split(" "));
830
- } else if (typeof tmp === "number"){
603
+ }
604
+ else if (typeof tmp === "number") {
831
605
  accum.push(tmp);
832
606
  }
833
607
  return accum;
834
- }, [] as (number|string)[]);
835
-
608
+ }, []);
836
609
  const geomObjects = [];
837
- let currentObj: [x: number, y: number][] = null;
838
-
610
+ let currentObj = null;
839
611
  for (let i = 0; i < parts.length; i++) {
840
612
  const command = parts[i];
841
613
  if (command === 'M') {
842
- // Start a new object
843
614
  if (currentObj !== null) {
844
615
  geomObjects.push(currentObj);
845
616
  }
846
-
847
617
  const x = Number(parts[i + 1]);
848
618
  const y = Number(parts[i + 2]);
849
-
850
619
  currentObj = [[x, y]];
851
-
852
620
  i += 2;
853
-
854
- } else if (command === 'L') {
621
+ }
622
+ else if (command === 'L') {
855
623
  const x = Number(parts[i + 1]);
856
624
  const y = Number(parts[i + 2]);
857
625
  currentObj.push([x, y]);
858
-
859
626
  i += 2;
860
-
861
- } else if (command === 'Z'){
862
- // Return back to first point in path
627
+ }
628
+ else if (command === 'Z') {
863
629
  const firstPoint = currentObj[0];
864
630
  currentObj.push(firstPoint);
865
631
  }
866
632
  }
867
-
868
- if (currentObj !== null){
633
+ if (currentObj !== null) {
869
634
  geomObjects.push(currentObj);
870
635
  currentObj = null;
871
636
  }
872
-
873
637
  geomObjects.forEach(coords => {
874
638
  const [first] = coords;
875
639
  const last = coords[coords.length - 1];
876
-
877
- if (first[0] === last[0] && first[1] === last[1]){
878
- // If both are the same, then this is a polygon
879
- this.items.push(Geometry.polygon(coords));
880
- } else {
881
- this.items.push(Geometry.multiline(coords));
640
+ if (first[0] === last[0] && first[1] === last[1]) {
641
+ this.items.push(geometry_js_1.Geometry.polygon(coords));
642
+ }
643
+ else {
644
+ this.items.push(geometry_js_1.Geometry.multiline(coords));
882
645
  }
883
- })
884
-
646
+ });
885
647
  return this;
886
648
  }
887
-
888
- addSetLineWidth(value: number): SymbolDrawing {
889
- this.items.push(new GeometryProp('lineWidth', value));
649
+ addSetLineWidth(value) {
650
+ this.items.push(new geometry_js_1.GeometryProp('lineWidth', value));
890
651
  return this;
891
652
  }
892
-
893
- addSetLineColor(value: string): SymbolDrawing {
894
- this.items.push(new GeometryProp('lineColor', value));
653
+ addSetLineColor(value) {
654
+ this.items.push(new geometry_js_1.GeometryProp('lineColor', value));
895
655
  return this;
896
656
  }
897
-
898
- addSetFillColor(value: string): SymbolDrawing {
899
- this.items.push(new GeometryProp('fillColor', value));
657
+ addSetFillColor(value) {
658
+ this.items.push(new geometry_js_1.GeometryProp('fillColor', value));
900
659
  return this;
901
660
  }
902
-
903
- addArc(x: number, y: number, radius: number,
904
- startAngle: number, endAngle: number): SymbolDrawing {
905
-
906
- // Angles in degrees, convert to radians
661
+ addArc(x, y, radius, startAngle, endAngle) {
907
662
  startAngle = startAngle * Math.PI / 180;
908
663
  endAngle = endAngle * Math.PI / 180;
909
-
910
- this.items.push(
911
- Geometry.arc([x, y], radius, startAngle, endAngle, true));
912
-
664
+ this.items.push(geometry_js_1.Geometry.arc([x, y], radius, startAngle, endAngle, true));
913
665
  return this;
914
666
  }
915
-
916
- getPaths(): {path: string,
917
- fillColor: string,
918
- lineColor: string,
919
- lineWidth: number}[] {
920
-
667
+ getPaths() {
921
668
  let currentFill = "#fff";
922
669
  let currentLineWidth = 1;
923
670
  let currentLineColor = '#333';
924
-
925
671
  const pathItems = [];
926
-
927
672
  this.items.forEach(item => {
928
- if (!(item instanceof Label)){
929
- if (item instanceof GeometryProp){
930
- if (item.name === 'lineWidth'){
931
- currentLineWidth = item.value as number;
932
- } else if (item.name === 'lineColor'){
933
- currentLineColor = item.value as string;
934
- } else if (item.name === 'fillColor'){
935
- currentFill = item.value as string;
673
+ if (!(item instanceof geometry_js_1.Label)) {
674
+ if (item instanceof geometry_js_1.GeometryProp) {
675
+ if (item.name === 'lineWidth') {
676
+ currentLineWidth = item.value;
677
+ }
678
+ else if (item.name === 'lineColor') {
679
+ currentLineColor = item.value;
680
+ }
681
+ else if (item.name === 'fillColor') {
682
+ currentFill = item.value;
936
683
  }
937
- } else {
938
- const rotatedPath = Geometry.groupRotate([item], this.angle,
939
- this.mainOrigin);
940
-
941
- const {path, isClosedPolygon} =
942
- this.featuresToPath(rotatedPath);
943
-
684
+ }
685
+ else {
686
+ const rotatedPath = geometry_js_1.Geometry.groupRotate([item], this.angle, this.mainOrigin);
687
+ const { path, isClosedPolygon } = this.featuresToPath(rotatedPath);
944
688
  pathItems.push({
945
689
  path: path,
946
690
  lineWidth: currentLineWidth,
@@ -950,136 +694,81 @@ export class SymbolDrawing {
950
694
  }
951
695
  }
952
696
  });
953
-
954
697
  return pathItems;
955
698
  }
956
-
957
- getPinsPath(): string {
699
+ getPinsPath() {
958
700
  const features = this.pins.map(item => item[1]);
959
- const withAngle = Geometry.groupRotate(features, this.angle, this.mainOrigin);
701
+ const withAngle = geometry_js_1.Geometry.groupRotate(features, this.angle, this.mainOrigin);
960
702
  const { path } = this.featuresToPath(withAngle);
961
703
  return path;
962
704
  }
963
-
964
- getLabels(): Label[] {
965
- return this.items.filter(item => item instanceof Label) as Label[];
705
+ getLabels() {
706
+ return this.items.filter(item => item instanceof geometry_js_1.Label);
966
707
  }
967
-
968
- private featuresToPath(items: Feature[]):
969
- {path: string, isClosedPolygon: boolean} {
970
- return Geometry.featuresToPath(items);
708
+ featuresToPath(items) {
709
+ return geometry_js_1.Geometry.featuresToPath(items);
971
710
  }
972
-
973
- getBoundingBox(excludeLabels = false): {
974
- width: number, height: number,
975
- start: SimplePoint, end: SimplePoint
976
- } {
977
- // If excludeLabels is true, then do not add labels to the list
978
- // of items to measure the boundaries.
979
-
711
+ getBoundingBox(excludeLabels = false) {
980
712
  const pinFeatures = this.pins.map(pin => {
981
713
  return pin[1];
982
714
  });
983
-
984
715
  const drawingFeatures = this.items.reduce((accum, item) => {
985
- if (!excludeLabels || (excludeLabels && !(item instanceof Label))){
986
- if (!(item instanceof GeometryProp)){
716
+ if (!excludeLabels || (excludeLabels && !(item instanceof geometry_js_1.Label))) {
717
+ if (!(item instanceof geometry_js_1.GeometryProp)) {
987
718
  accum.push(item);
988
719
  }
989
720
  }
990
-
991
721
  return accum;
992
-
993
- }, [] as Feature[]);
994
-
722
+ }, []);
995
723
  const measureItems = [...drawingFeatures, ...pinFeatures];
996
-
997
- const withAngle = Geometry.groupRotate(measureItems, this.angle, this.mainOrigin);
998
-
999
- return Geometry.groupBounds(withAngle);
724
+ const withAngle = geometry_js_1.Geometry.groupRotate(measureItems, this.angle, this.mainOrigin);
725
+ return geometry_js_1.Geometry.groupBounds(withAngle);
1000
726
  }
1001
-
1002
- getPinPosition(pinId: number): { start: [number, number], end: [number, number], angle: number } {
727
+ getPinPosition(pinId) {
1003
728
  const pin = this.pins.find(item => {
1004
729
  return item[0] === pinId;
1005
730
  });
1006
-
1007
731
  if (pin) {
1008
- const [pinId, feature, angle] = pin;
1009
-
1010
- // Apply angle to feature
1011
-
1012
- const withAngle = Geometry.rotateDegs(feature, this.angle, this.mainOrigin);
1013
- const coords = Geometry.getCoords(withAngle);
1014
-
732
+ const [, feature, angle] = pin;
733
+ const withAngle = geometry_js_1.Geometry.rotateDegs(feature, this.angle, this.mainOrigin);
734
+ const coords = geometry_js_1.Geometry.getCoords(withAngle);
1015
735
  return {
1016
736
  start: coords[0],
1017
737
  end: coords[1],
1018
738
  angle,
1019
- }
739
+ };
1020
740
  }
741
+ return null;
1021
742
  }
1022
743
  }
1023
-
1024
- export type SubExpressionCommand = [commandName: string,
1025
- positionParams: any[],
1026
- keywordParams: Map<string, any>];
1027
-
1028
- export class SymbolDrawingCommands extends SymbolDrawing {
1029
-
1030
- id = "";
1031
- private commands: SubExpressionCommand[];
1032
-
1033
- constructor(commands: SubExpressionCommand[]){
744
+ exports.SymbolDrawing = SymbolDrawing;
745
+ class SymbolDrawingCommands extends SymbolDrawing {
746
+ constructor(commands) {
1034
747
  super();
748
+ this.id = "";
1035
749
  this.commands = commands;
1036
750
  this.id = Math.random().toString().slice(2);
1037
751
  }
1038
-
1039
- getCommands(): SubExpressionCommand[] {
752
+ getCommands() {
1040
753
  return this.commands;
1041
754
  }
1042
-
1043
- clone(): SymbolDrawingCommands {
1044
- // Force a deep clone
1045
- const tmpCommands: SubExpressionCommand[] = this.commands.map(item => {
755
+ clone() {
756
+ const tmpCommands = this.commands.map(item => {
1046
757
  if (item[0] === PlaceHolderCommands.label) {
1047
758
  const commandName = item[0];
1048
759
  const positionParams = item[1];
1049
760
  const keywordParams = item[2];
1050
-
1051
- const newMap = new Map<string, any>();
761
+ const newMap = new Map();
1052
762
  for (const [key, value] of keywordParams) {
1053
763
  newMap.set(key, value);
1054
764
  }
1055
-
1056
765
  return [commandName, positionParams, newMap];
1057
- } else {
766
+ }
767
+ else {
1058
768
  return [...item];
1059
769
  }
1060
770
  });
1061
771
  return new SymbolDrawingCommands(tmpCommands);
1062
772
  }
1063
773
  }
1064
-
1065
- type SimplePoint = [x: number, y: number];
1066
-
1067
- type SymbolPinLayout = {
1068
- pinId: number,
1069
- angle: number,
1070
- text: string,
1071
- start: {
1072
- x: number, y: number
1073
- },
1074
- end: {
1075
- x: number, y: number
1076
- }
1077
- }
1078
-
1079
- export type SymbolPinDefintion = {
1080
- side: string,
1081
- pinId: number,
1082
- text: string, // Display value at the pin
1083
- position: number,
1084
- }
1085
-
774
+ exports.SymbolDrawingCommands = SymbolDrawingCommands;