circuitscript 0.0.38 → 0.1.2

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 (66) hide show
  1. package/dist/cjs/BaseVisitor.js +69 -46
  2. package/dist/cjs/SymbolValidatorVisitor.js +1 -1
  3. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  4. package/dist/cjs/antlr/CircuitScriptParser.js +580 -613
  5. package/dist/cjs/builtinMethods.js +32 -10
  6. package/dist/cjs/draw_symbols.js +375 -233
  7. package/dist/cjs/execute.js +142 -131
  8. package/dist/cjs/export.js +2 -4
  9. package/dist/cjs/geometry.js +52 -19
  10. package/dist/cjs/globals.js +14 -9
  11. package/dist/cjs/helpers.js +16 -3
  12. package/dist/cjs/layout.js +143 -151
  13. package/dist/cjs/logger.js +8 -1
  14. package/dist/cjs/objects/ClassComponent.js +22 -22
  15. package/dist/cjs/objects/ExecutionScope.js +10 -4
  16. package/dist/cjs/objects/Frame.js +4 -1
  17. package/dist/cjs/objects/ParamDefinition.js +120 -4
  18. package/dist/cjs/objects/PinDefinition.js +1 -4
  19. package/dist/cjs/objects/types.js +41 -0
  20. package/dist/cjs/render.js +41 -110
  21. package/dist/cjs/sizing.js +33 -7
  22. package/dist/cjs/utils.js +92 -2
  23. package/dist/cjs/visitor.js +279 -284
  24. package/dist/esm/BaseVisitor.mjs +70 -47
  25. package/dist/esm/SymbolValidatorVisitor.mjs +1 -1
  26. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  27. package/dist/esm/antlr/CircuitScriptParser.mjs +580 -613
  28. package/dist/esm/builtinMethods.mjs +29 -10
  29. package/dist/esm/draw_symbols.mjs +381 -238
  30. package/dist/esm/execute.mjs +144 -133
  31. package/dist/esm/export.mjs +2 -4
  32. package/dist/esm/geometry.mjs +52 -19
  33. package/dist/esm/globals.mjs +13 -8
  34. package/dist/esm/helpers.mjs +17 -4
  35. package/dist/esm/layout.mjs +144 -153
  36. package/dist/esm/logger.mjs +8 -1
  37. package/dist/esm/objects/ClassComponent.mjs +21 -26
  38. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  39. package/dist/esm/objects/Frame.mjs +4 -1
  40. package/dist/esm/objects/ParamDefinition.mjs +119 -3
  41. package/dist/esm/objects/PinDefinition.mjs +0 -2
  42. package/dist/esm/objects/types.mjs +42 -0
  43. package/dist/esm/render.mjs +44 -113
  44. package/dist/esm/sizing.mjs +34 -8
  45. package/dist/esm/utils.mjs +86 -1
  46. package/dist/esm/visitor.mjs +281 -286
  47. package/dist/types/BaseVisitor.d.ts +3 -2
  48. package/dist/types/antlr/CircuitScriptParser.d.ts +5 -3
  49. package/dist/types/draw_symbols.d.ts +81 -49
  50. package/dist/types/execute.d.ts +16 -11
  51. package/dist/types/geometry.d.ts +31 -19
  52. package/dist/types/globals.d.ts +15 -10
  53. package/dist/types/helpers.d.ts +2 -1
  54. package/dist/types/layout.d.ts +22 -21
  55. package/dist/types/logger.d.ts +1 -1
  56. package/dist/types/objects/ClassComponent.d.ts +19 -16
  57. package/dist/types/objects/ExecutionScope.d.ts +2 -1
  58. package/dist/types/objects/Frame.d.ts +5 -3
  59. package/dist/types/objects/ParamDefinition.d.ts +31 -2
  60. package/dist/types/objects/PinDefinition.d.ts +0 -2
  61. package/dist/types/objects/types.d.ts +7 -2
  62. package/dist/types/render.d.ts +2 -1
  63. package/dist/types/utils.d.ts +9 -1
  64. package/dist/types/visitor.d.ts +5 -5
  65. package/libs/lib.cst +102 -32
  66. package/package.json +7 -3
@@ -1,13 +1,15 @@
1
1
  import Flatten from '@flatten-js/core';
2
2
  import { measureTextSize2 } from './sizing.mjs';
3
3
  import { defaultFont, fontDisplayScale, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical } from './globals.mjs';
4
- import { NumericValue } from './objects/ParamDefinition.mjs';
4
+ import { numeric, NumericValue } from './objects/ParamDefinition.mjs';
5
5
  import { AllPinTypes, PinTypes } from './objects/PinTypes.mjs';
6
6
  import { roundValue } from './utils.mjs';
7
7
  export class Textbox extends Flatten.Polygon {
8
8
  id;
9
9
  text;
10
- anchorPoint = [0, 0];
10
+ anchorPoint = [
11
+ numeric(0), numeric(0)
12
+ ];
11
13
  boundingBox = { width: -1, height: -1 };
12
14
  polygon;
13
15
  font = 'default';
@@ -43,8 +45,8 @@ export class Textbox extends Flatten.Polygon {
43
45
  else {
44
46
  throw 'Invalid string passed into textbox';
45
47
  }
46
- const { fontSize = 10, anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', portType = null, } = style ?? {};
47
- const { width, height, box } = measureTextSize2(useText, defaultFont, fontSize * fontDisplayScale, fontWeight, anchor, vanchor);
48
+ const { fontSize = numeric(50), anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', portType = null, } = style ?? {};
49
+ const { box } = measureTextSize2(useText, defaultFont, fontSize.mul(fontDisplayScale).toNumber(), fontWeight, anchor, vanchor);
48
50
  let polygonCoords = [];
49
51
  let anchorOffsetX = 0;
50
52
  let anchorOffsetY = 0;
@@ -103,20 +105,31 @@ export class Textbox extends Flatten.Polygon {
103
105
  anchorOffsetY += paddingVert / 2;
104
106
  }
105
107
  const polygon = new Flatten.Polygon(polygonCoords);
106
- return new Textbox(id, useText, [x + anchorOffsetX, y + anchorOffsetY], polygon, style, box, label);
108
+ return new Textbox(id, useText, [x.add(anchorOffsetX), y.add(anchorOffsetY)], polygon, style, box, label);
107
109
  }
108
110
  rotate(angle, origin) {
109
111
  const feature = super.rotate(angle, origin);
110
112
  const newAnchorPoint = this.transformAnchorPoint(segment => segment.rotate(angle, origin));
111
- return new Textbox(this.id, this.text, newAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
113
+ const tmpAnchorPoint = [
114
+ numeric(newAnchorPoint[0]),
115
+ numeric(newAnchorPoint[1])
116
+ ];
117
+ return new Textbox(this.id, this.text, tmpAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
112
118
  }
113
119
  transform(matrix) {
114
120
  const feature = super.transform(matrix);
115
121
  const newAnchorPoint = this.transformAnchorPoint(segment => segment.transform(matrix));
116
- return new Textbox(this.id, this.text, newAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
122
+ const tmpAnchorPoint = [
123
+ numeric(newAnchorPoint[0]),
124
+ numeric(newAnchorPoint[1])
125
+ ];
126
+ return new Textbox(this.id, this.text, tmpAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
117
127
  }
118
128
  transformAnchorPoint(callback) {
119
- const anchorPointSegment = new Flatten.Segment(new Flatten.Point(0, 0), new Flatten.Point(this.anchorPoint));
129
+ const anchorPointSegment = new Flatten.Segment(new Flatten.Point(0, 0), new Flatten.Point([
130
+ this.anchorPoint[0].toNumber(),
131
+ this.anchorPoint[1].toNumber(),
132
+ ]));
120
133
  const newSegment = callback(anchorPointSegment);
121
134
  const lastPoint = newSegment.vertices[newSegment.vertices.length - 1];
122
135
  return [
@@ -137,7 +150,7 @@ export class GeometryProp {
137
150
  }
138
151
  export class Geometry {
139
152
  static point(x, y) {
140
- return new Flatten.Point(x, y);
153
+ return new Flatten.Point(x.toNumber(), y.toNumber());
141
154
  }
142
155
  static line(x1, y1, x2, y2) {
143
156
  return new Flatten.Line(Geometry.point(x1, y1), Geometry.point(x2, y2));
@@ -152,7 +165,12 @@ export class Geometry {
152
165
  return new Flatten.Segment(Geometry.point(start[0], start[1]), Geometry.point(end[0], end[1]));
153
166
  }
154
167
  static polygon(coords) {
155
- return new Flatten.Polygon(coords);
168
+ return new Flatten.Polygon(coords.map(item => {
169
+ return [
170
+ item[0].toNumber(),
171
+ item[1].toNumber(),
172
+ ];
173
+ }));
156
174
  }
157
175
  static multiline(coords) {
158
176
  const segments = [];
@@ -162,11 +180,13 @@ export class Geometry {
162
180
  return new Flatten.Multiline(segments);
163
181
  }
164
182
  static arc(center, radius, startAngle, endAngle, sweepDirection) {
165
- return new Flatten.Arc(Geometry.point(center[0], center[1]), radius, startAngle, endAngle, sweepDirection);
183
+ return new Flatten.Arc(Geometry.point(center[0], center[1]), radius.toNumber(), startAngle.toNumber(), endAngle.toNumber(), sweepDirection);
166
184
  }
167
185
  static getCoords(item) {
168
186
  const points = item.vertices.map(vertex => {
169
- return [vertex.x, vertex.y];
187
+ return [
188
+ numeric(vertex.x), numeric(vertex.y)
189
+ ];
170
190
  });
171
191
  return points;
172
192
  }
@@ -213,10 +233,10 @@ export class Geometry {
213
233
  if (feature instanceof Textbox) {
214
234
  const [x, y] = feature.anchorPoint;
215
235
  box = {
216
- xmin: box.xmin + x,
217
- ymin: box.ymin + y,
218
- xmax: box.xmax + x,
219
- ymax: box.ymax + y
236
+ xmin: box.xmin + x.toNumber(),
237
+ ymin: box.ymin + y.toNumber(),
238
+ xmax: box.xmax + x.toNumber(),
239
+ ymax: box.ymax + y.toNumber()
220
240
  };
221
241
  }
222
242
  if (box.xmin === undefined) {
@@ -274,7 +294,7 @@ export class Geometry {
274
294
  for (let i = 0; i < coords.length; i++) {
275
295
  const [x, y] = coords[i];
276
296
  const command = (i === 0) ? 'M' : 'L';
277
- path.push(`${command}`, x, y);
297
+ path.push(`${command}`, x.toNumber(), y.toNumber());
278
298
  }
279
299
  if (isClosedPolygon) {
280
300
  path.push('Z');
@@ -307,8 +327,8 @@ export class Geometry {
307
327
  const existingSegments = [];
308
328
  wirePoints.forEach(points => {
309
329
  const tmpPoints = points.map(pt => {
310
- const roundedX = roundValue(pt.x);
311
- const roundedY = roundValue(pt.y);
330
+ const roundedX = roundValue(pt.x).toNumber();
331
+ const roundedY = roundValue(pt.y).toNumber();
312
332
  return new Flatten.Point(roundedX, roundedY);
313
333
  });
314
334
  for (let i = 0; i < tmpPoints.length - 1; i++) {
@@ -519,6 +539,19 @@ export var VerticalAlign;
519
539
  VerticalAlign["Middle"] = "middle";
520
540
  VerticalAlign["Bottom"] = "bottom";
521
541
  })(VerticalAlign || (VerticalAlign = {}));
542
+ export var HorizontalAlignProp;
543
+ (function (HorizontalAlignProp) {
544
+ HorizontalAlignProp["Start"] = "start";
545
+ HorizontalAlignProp["Middle"] = "middle";
546
+ HorizontalAlignProp["End"] = "end";
547
+ })(HorizontalAlignProp || (HorizontalAlignProp = {}));
548
+ export var VerticalAlignProp;
549
+ (function (VerticalAlignProp) {
550
+ VerticalAlignProp["Hanging"] = "hanging";
551
+ VerticalAlignProp["Middle"] = "middle";
552
+ VerticalAlignProp["Central"] = "central";
553
+ VerticalAlignProp["TextTop"] = "text-top";
554
+ })(VerticalAlignProp || (VerticalAlignProp = {}));
522
555
  function getArcPointRadians(centerX, centerY, radius, angleRads) {
523
556
  const dx = Math.cos(angleRads);
524
557
  const dy = Math.sin(angleRads);
@@ -1,10 +1,6 @@
1
1
  export var GlobalNames;
2
2
  (function (GlobalNames) {
3
3
  GlobalNames["__root"] = "__root";
4
- GlobalNames["gnd"] = "gnd";
5
- GlobalNames["DefaultResistor"] = "res";
6
- GlobalNames["DefaultCapacitor"] = "cap";
7
- GlobalNames["DefaultInductor"] = "ind";
8
4
  GlobalNames["symbol"] = "symbol";
9
5
  })(GlobalNames || (GlobalNames = {}));
10
6
  export const NoNetText = 'NO_NET';
@@ -12,6 +8,10 @@ export var ParamKeys;
12
8
  (function (ParamKeys) {
13
9
  ParamKeys["priority"] = "priority";
14
10
  ParamKeys["net_name"] = "net_name";
11
+ ParamKeys["flip"] = "flip";
12
+ ParamKeys["flipX"] = "flipX";
13
+ ParamKeys["flipY"] = "flipY";
14
+ ParamKeys["angle"] = "angle";
15
15
  })(ParamKeys || (ParamKeys = {}));
16
16
  export var LayoutDirection;
17
17
  (function (LayoutDirection) {
@@ -22,6 +22,8 @@ export var SymbolPinSide;
22
22
  (function (SymbolPinSide) {
23
23
  SymbolPinSide["Left"] = "left";
24
24
  SymbolPinSide["Right"] = "right";
25
+ SymbolPinSide["Top"] = "top";
26
+ SymbolPinSide["Bottom"] = "bottom";
25
27
  })(SymbolPinSide || (SymbolPinSide = {}));
26
28
  export var LengthUnit;
27
29
  (function (LengthUnit) {
@@ -71,11 +73,10 @@ export const ColorScheme = {
71
73
  };
72
74
  export var ComponentTypes;
73
75
  (function (ComponentTypes) {
74
- ComponentTypes["gnd"] = "gnd";
75
76
  ComponentTypes["net"] = "net";
76
- ComponentTypes["label"] = "label";
77
- ComponentTypes["point"] = "point";
78
- ComponentTypes["frame"] = "frame";
77
+ ComponentTypes["graphic"] = "graphic";
78
+ ComponentTypes["port"] = "port";
79
+ ComponentTypes["module"] = "module";
79
80
  })(ComponentTypes || (ComponentTypes = {}));
80
81
  export var ReferenceTypes;
81
82
  (function (ReferenceTypes) {
@@ -97,8 +98,12 @@ export var FrameType;
97
98
  FrameType[FrameType["Frame"] = 1] = "Frame";
98
99
  FrameType[FrameType["Sheet"] = 2] = "Sheet";
99
100
  })(FrameType || (FrameType = {}));
101
+ export const ModuleContainsKeyword = 'contains';
100
102
  export const GlobalDocumentName = 'document';
101
103
  export const RenderFlags = {
102
104
  ShowElementFrames: false,
103
105
  ShowOrigin: false,
106
+ ShowGridOrigin: false,
107
+ ShowLabelBoxBounds: false,
108
+ ShowLabelOrigin: false,
104
109
  };
@@ -6,7 +6,7 @@ import { LayoutEngine } from "./layout.mjs";
6
6
  import { SequenceAction } from "./objects/ExecutionScope.mjs";
7
7
  import { parseFileWithVisitor } from "./parser.mjs";
8
8
  import { generatePdfOutput, generateSvgOutput, renderSheetsToSVG } from "./render.mjs";
9
- import { SimpleStopwatch } from "./utils.mjs";
9
+ import { resolveToNumericValue, SimpleStopwatch } from "./utils.mjs";
10
10
  import { ParserVisitor, VisitorExecutionException } from "./visitor.mjs";
11
11
  import { createContext } from "this-file";
12
12
  import { SymbolValidatorResolveVisitor, SymbolValidatorVisitor } from "./SymbolValidatorVisitor.mjs";
@@ -16,6 +16,8 @@ import { CircuitScriptParser } from "./antlr/CircuitScriptParser.mjs";
16
16
  import { prepareTokens, SemanticTokensVisitor } from "./SemanticTokenVisitor.mjs";
17
17
  import { defaultPageMarginMM, defaultZoomScale, LengthUnit, MilsToMM, PxToMM } from "./globals.mjs";
18
18
  import { FrameParamKeys } from "./objects/Frame.mjs";
19
+ import Big from "big.js";
20
+ import { Logger } from "./logger.mjs";
19
21
  export var JSModuleType;
20
22
  (function (JSModuleType) {
21
23
  JSModuleType["CommonJs"] = "cjs";
@@ -189,7 +191,13 @@ export function renderScript(scriptData, outputPath, options) {
189
191
  const action = tmp[0];
190
192
  if (action === SequenceAction.Wire) {
191
193
  tmp[2] = tmp[2].map(item2 => {
192
- return [item2.direction, item2.value].join(",");
194
+ const lengthValue = item2.value;
195
+ const useValue = [item2.direction];
196
+ if (lengthValue !== null) {
197
+ useValue.push(lengthValue.value);
198
+ useValue.push(lengthValue.type);
199
+ }
200
+ return useValue.join(",");
193
201
  }).join(" ");
194
202
  }
195
203
  else if (action === SequenceAction.Frame) {
@@ -227,8 +235,10 @@ export function renderScript(scriptData, outputPath, options) {
227
235
  showStats && console.log('Layout took:', layoutTimer.lap());
228
236
  dumpData && writeFileSync('dump/raw-layout.txt', layoutEngine.logger.dump());
229
237
  const generateSvgTimer = new SimpleStopwatch();
230
- const svgCanvas = renderSheetsToSVG(sheetFrames);
238
+ const renderLogger = new Logger();
239
+ const svgCanvas = renderSheetsToSVG(sheetFrames, renderLogger);
231
240
  showStats && console.log('Render took:', generateSvgTimer.lap());
241
+ dumpData && writeFileSync('dump/raw-render.txt', renderLogger.dump());
232
242
  svgOutput = generateSvgOutput(svgCanvas, outputDefaultZoom);
233
243
  if (outputPath) {
234
244
  if (fileExtension === 'svg') {
@@ -320,7 +330,10 @@ export class UnitDimension {
320
330
  }
321
331
  }
322
332
  export function milsToMM(value) {
323
- return value * MilsToMM;
333
+ if (typeof value === 'number') {
334
+ value = resolveToNumericValue(new Big(value));
335
+ }
336
+ return resolveToNumericValue(value.toBigNumber().mul(new Big(MilsToMM)));
324
337
  }
325
338
  export function pxToMM(value) {
326
339
  return value * PxToMM;