circuitscript 0.1.0 → 0.1.3

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 (61) hide show
  1. package/dist/cjs/BaseVisitor.js +13 -8
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  3. package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
  4. package/dist/cjs/builtinMethods.js +27 -8
  5. package/dist/cjs/draw_symbols.js +320 -197
  6. package/dist/cjs/execute.js +114 -116
  7. package/dist/cjs/export.js +2 -4
  8. package/dist/cjs/geometry.js +52 -19
  9. package/dist/cjs/globals.js +17 -12
  10. package/dist/cjs/helpers.js +16 -3
  11. package/dist/cjs/layout.js +473 -354
  12. package/dist/cjs/logger.js +8 -1
  13. package/dist/cjs/objects/ClassComponent.js +22 -22
  14. package/dist/cjs/objects/ExecutionScope.js +10 -4
  15. package/dist/cjs/objects/Frame.js +11 -2
  16. package/dist/cjs/objects/ParamDefinition.js +123 -4
  17. package/dist/cjs/objects/PinDefinition.js +1 -4
  18. package/dist/cjs/render.js +76 -138
  19. package/dist/cjs/sizing.js +33 -7
  20. package/dist/cjs/utils.js +86 -2
  21. package/dist/cjs/visitor.js +224 -255
  22. package/dist/esm/BaseVisitor.mjs +15 -10
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
  25. package/dist/esm/builtinMethods.mjs +24 -8
  26. package/dist/esm/draw_symbols.mjs +322 -200
  27. package/dist/esm/execute.mjs +116 -118
  28. package/dist/esm/export.mjs +2 -4
  29. package/dist/esm/geometry.mjs +52 -19
  30. package/dist/esm/globals.mjs +17 -12
  31. package/dist/esm/helpers.mjs +17 -4
  32. package/dist/esm/layout.mjs +479 -360
  33. package/dist/esm/logger.mjs +8 -1
  34. package/dist/esm/objects/ClassComponent.mjs +21 -26
  35. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  36. package/dist/esm/objects/Frame.mjs +10 -1
  37. package/dist/esm/objects/ParamDefinition.mjs +122 -3
  38. package/dist/esm/objects/PinDefinition.mjs +0 -2
  39. package/dist/esm/render.mjs +79 -141
  40. package/dist/esm/sizing.mjs +34 -8
  41. package/dist/esm/utils.mjs +80 -1
  42. package/dist/esm/visitor.mjs +226 -257
  43. package/dist/types/BaseVisitor.d.ts +1 -1
  44. package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
  45. package/dist/types/draw_symbols.d.ts +72 -45
  46. package/dist/types/execute.d.ts +15 -10
  47. package/dist/types/geometry.d.ts +31 -19
  48. package/dist/types/globals.d.ts +15 -11
  49. package/dist/types/helpers.d.ts +2 -1
  50. package/dist/types/layout.d.ts +35 -54
  51. package/dist/types/logger.d.ts +1 -1
  52. package/dist/types/objects/ClassComponent.d.ts +19 -16
  53. package/dist/types/objects/ExecutionScope.d.ts +3 -2
  54. package/dist/types/objects/Frame.d.ts +9 -2
  55. package/dist/types/objects/ParamDefinition.d.ts +32 -2
  56. package/dist/types/objects/PinDefinition.d.ts +0 -2
  57. package/dist/types/render.d.ts +2 -1
  58. package/dist/types/utils.d.ts +14 -1
  59. package/dist/types/visitor.d.ts +4 -5
  60. package/libs/lib.cst +25 -8
  61. package/package.json +7 -3
@@ -1,10 +1,10 @@
1
1
  import { SVG, registerWindow } from '@svgdotjs/svg.js';
2
2
  import { ExtractDrawingRects, RenderFrameType, getBounds } from "./layout.mjs";
3
3
  import { applyFontsToSVG, getCreateSVGWindow } from './sizing.mjs';
4
- import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, ParamKeys, RenderFlags, defaultFont, defaultGridSizeUnits, defaultPageSpacingMM, defaultWireLineWidth, fontDisplayScale, junctionSize } from './globals.mjs';
5
- import { NumericValue } from './objects/ParamDefinition.mjs';
4
+ import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, defaultWireLineWidth, fontDisplayScale, junctionSize } from './globals.mjs';
5
+ import { numeric, NumericValue } from './objects/ParamDefinition.mjs';
6
6
  import { combineMaps, getBoundsSize } from './utils.mjs';
7
- import { getPaperSize, milsToMM, PaperGridReferences } from './helpers.mjs';
7
+ import { getPaperSize, milsToMM } from './helpers.mjs';
8
8
  import SVGtoPDF from 'svg-to-pdfkit';
9
9
  import { FrameParamKeys } from './objects/Frame.mjs';
10
10
  import { SymbolPlaceholder } from './draw_symbols.mjs';
@@ -16,19 +16,21 @@ function createSvgCanvas() {
16
16
  applyFontsToSVG(canvas);
17
17
  return canvas;
18
18
  }
19
- export function renderSheetsToSVG(sheetFrames) {
19
+ export function renderSheetsToSVG(sheetFrames, logger) {
20
20
  const canvas = createSvgCanvas();
21
21
  sheetFrames.forEach((sheet, index) => {
22
22
  const sheetGroup = canvas.group();
23
- sheetGroup.id('sheet-' + index);
23
+ sheetGroup.id('sheet-' + index).addClass('sheet');
24
+ logger.add('rendering sheet: sheet-' + index);
24
25
  const { components, wires, junctions, mergedWires, frames, textObjects } = sheet;
25
26
  const allFrames = [sheet.frame, ...frames];
26
27
  let gridBounds = null;
27
28
  let extendGrid = true;
28
29
  let xOffset = 0;
29
30
  let yOffset = 0;
30
- let sheetYOffset = 0;
31
+ let sheetYOffset = numeric(0);
31
32
  if (sheet.frame.frame) {
33
+ logger.add('drawing frame');
32
34
  const frameComponent = sheet.frame.frame.parameters
33
35
  .get(FrameParamKeys.SheetType);
34
36
  if (frameComponent) {
@@ -36,34 +38,43 @@ export function renderSheetsToSVG(sheetFrames) {
36
38
  throw 'Invalid graphic object for sheet frame';
37
39
  }
38
40
  const frameRects = ExtractDrawingRects(frameComponent.displayProp) ?? [];
39
- let originalWidthMM = 0;
40
- let originalHeightMM = 0;
41
- let widthMM = 0;
42
- let heightMM = 0;
43
- if (frameRects[0]) {
44
- originalWidthMM = milsToMM(frameRects[0].width);
45
- originalHeightMM = milsToMM(frameRects[0].height);
41
+ let originalWidthMM = numeric(0);
42
+ let originalHeightMM = numeric(0);
43
+ let widthMM = numeric(0);
44
+ let heightMM = numeric(0);
45
+ const paperRect = frameRects.find(item => item.className === 'paper-area');
46
+ const plotRect = frameRects.find(item => item.className === 'plot-area');
47
+ if (paperRect) {
48
+ originalWidthMM = milsToMM(paperRect.width);
49
+ originalHeightMM = milsToMM(paperRect.height);
50
+ logger.add('first frame size: ' + originalWidthMM.toNumber()
51
+ + ' ' + originalHeightMM.toNumber());
46
52
  }
47
- if (frameRects[1]) {
48
- widthMM = milsToMM(frameRects[1].width);
49
- heightMM = milsToMM(frameRects[1].height);
53
+ if (plotRect) {
54
+ widthMM = milsToMM(plotRect.width);
55
+ heightMM = milsToMM(plotRect.height);
56
+ logger.add('second frame size: ' + widthMM.toNumber()
57
+ + ' ' + heightMM.toNumber());
50
58
  }
51
- xOffset = (originalWidthMM - widthMM) / 2;
52
- yOffset = (originalHeightMM - heightMM) / 2;
53
- sheetYOffset = index * (originalHeightMM + defaultPageSpacingMM);
59
+ xOffset = (originalWidthMM.sub(widthMM)).half().toNumber();
60
+ yOffset = (originalHeightMM.sub(heightMM)).half().toNumber();
61
+ logger.add('offset', xOffset, yOffset);
62
+ sheetYOffset = originalHeightMM.add(defaultPageSpacingMM).mul(index);
54
63
  gridBounds = {
55
64
  xmin: 0,
56
65
  ymin: 0,
57
- xmax: widthMM,
58
- ymax: heightMM
66
+ xmax: widthMM.toNumber(),
67
+ ymax: heightMM.toNumber()
59
68
  };
60
69
  extendGrid = false;
61
70
  }
62
71
  }
63
- const sheetElements = sheetGroup.group();
64
- generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridBounds, extendGrid);
72
+ logger.add('sheet contents offset: ' + xOffset + ' ' + yOffset);
73
+ logger.add('generating svg children in sheet');
74
+ const sheetElements = sheetGroup.group().addClass('sheet-elements');
75
+ generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridBounds, extendGrid, logger);
65
76
  sheetElements.translate(xOffset, yOffset);
66
- sheetGroup.translate(0, sheetYOffset);
77
+ sheetGroup.translate(0, sheetYOffset.toNumber());
67
78
  });
68
79
  return canvas;
69
80
  }
@@ -105,16 +116,18 @@ export function generatePdfOutput(doc, canvas, sheetSize, sheetSizeDefined, zoom
105
116
  }
106
117
  });
107
118
  }
108
- function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridBounds, extendGrid) {
119
+ function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridBounds, extendGrid, logger) {
109
120
  const displayWireId = false;
110
121
  if (gridBounds === null) {
122
+ logger.add('get grid bounds');
111
123
  gridBounds = getBounds(components, wires, junctions, frameObjects);
112
124
  }
113
- drawGrid(canvas.group().translate(0, 0), gridBounds, extendGrid);
125
+ logger.add('grid bounds', gridBounds.xmin, gridBounds.ymin, gridBounds.xmax, gridBounds.ymax);
126
+ drawGrid(canvas.group().translate(0, 0), gridBounds, extendGrid, logger);
114
127
  components.forEach(item => {
115
128
  const { x, y, width, height } = item;
116
129
  const symbolGroup = canvas.group();
117
- symbolGroup.translate(x, y);
130
+ symbolGroup.translate(x.toNumber(), y.toNumber());
118
131
  const { symbol = null } = item;
119
132
  if (symbol !== null && symbol) {
120
133
  const extra = {};
@@ -151,7 +164,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
151
164
  family: 'Arial',
152
165
  size: 50 * fontDisplayScale,
153
166
  })
154
- .translate(wire.x + 5, wire.y + 5);
167
+ .translate(wire.x.add(5).toNumber(), wire.y.add(5).toNumber());
155
168
  });
156
169
  }
157
170
  const mergedWireGroup = canvas.group();
@@ -168,10 +181,13 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
168
181
  })
169
182
  .fill('none');
170
183
  });
184
+ const halfJunctionSize = junctionSize.half();
171
185
  intersectPoints.forEach(point => {
172
- const [x, y, count] = point;
173
- mergedWireGroup.circle(junctionSize)
174
- .translate(x - junctionSize / 2, y - junctionSize / 2)
186
+ const [x, y,] = point;
187
+ const translateX = numeric(x).sub(halfJunctionSize);
188
+ const translateY = numeric(y).sub(halfJunctionSize);
189
+ mergedWireGroup.circle(junctionSize.toNumber())
190
+ .translate(translateX.toNumber(), translateY.toNumber())
175
191
  .fill(ColorScheme.JunctionColor)
176
192
  .stroke('none');
177
193
  });
@@ -185,11 +201,11 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
185
201
  drawSheetFrameBorder(frameGroup, item);
186
202
  }
187
203
  else {
188
- if (borderWidth > 0) {
189
- if (item.type === RenderFrameType.Container) {
204
+ if (borderWidth.toNumber() > 0) {
205
+ if (item.renderType === RenderFrameType.Container) {
190
206
  strokeColor = '#111';
191
207
  }
192
- else if (item.type === RenderFrameType.Elements) {
208
+ else if (item.renderType === RenderFrameType.Elements) {
193
209
  strokeColor = '#aaa';
194
210
  if (!RenderFlags.ShowElementFrames) {
195
211
  return;
@@ -197,52 +213,61 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
197
213
  }
198
214
  const tmpRect = frameGroup.rect(width, height)
199
215
  .fill('none')
200
- .stroke({ width: milsToMM(borderWidth), color: strokeColor });
201
- tmpRect.translate(item.x, item.y);
216
+ .stroke({
217
+ width: milsToMM(borderWidth).toNumber(),
218
+ color: strokeColor
219
+ });
220
+ tmpRect.translate(item.x.toNumber(), item.y.toNumber());
202
221
  }
203
222
  }
204
223
  });
205
224
  textObjects.forEach(item => {
206
225
  const { x, y, symbol } = item;
207
226
  const innerGroup = canvas.group();
208
- innerGroup.translate(x, y);
227
+ innerGroup.translate(x.toNumber(), y.toNumber());
209
228
  symbol.draw(innerGroup);
210
229
  });
211
- const originSize = milsToMM(10);
230
+ const originSize = milsToMM(10).toNumber();
212
231
  RenderFlags.ShowOrigin && canvas.group().translate(0, 0)
213
232
  .circle(originSize)
214
233
  .translate(-originSize / 2, -originSize / 2)
215
234
  .stroke('none').fill('red');
216
235
  }
217
- function drawGrid(group, canvasSize, extendGrid) {
236
+ function drawGrid(group, canvasSize, extendGrid, logger) {
218
237
  const gridSize = defaultGridSizeUnits;
219
238
  const { xmin, ymin, xmax, ymax } = canvasSize;
220
239
  const extraValue = extendGrid ? 1 : 0;
221
- const gridStartX = (Math.floor(xmin / gridSize) - extraValue) * gridSize;
222
- const gridStartY = (Math.floor(ymin / gridSize) - extraValue) * gridSize;
240
+ const gridStartX = (numeric(Math.floor(xmin / gridSize)).sub(extraValue)).mul(gridSize);
241
+ const gridStartY = (numeric(Math.floor(ymin / gridSize)).sub(extraValue)).mul(gridSize);
223
242
  const gridEndX = extendGrid
224
- ? (Math.ceil(xmax / gridSize) + extraValue) * gridSize
225
- : (xmax - xmin);
243
+ ? (numeric(Math.ceil(xmax / gridSize)).add(extraValue)).mul(gridSize)
244
+ : (numeric(xmax).sub(xmin));
226
245
  const gridEndY = extendGrid
227
- ? (Math.ceil(ymax / gridSize) + extraValue) * gridSize
228
- : (ymax - ymin);
229
- const numCols = Math.floor((gridEndX - gridStartX) / gridSize)
246
+ ? (numeric(Math.ceil(ymax / gridSize)).add(extraValue)).mul(gridSize)
247
+ : (numeric(ymax).sub(ymin));
248
+ const numCols = Math.floor(gridEndX.sub(gridStartX).div(gridSize).toNumber())
230
249
  + (extendGrid ? 1 : 0);
250
+ const originSize = milsToMM(10).toNumber();
251
+ RenderFlags.ShowGridOrigin && group.circle(originSize)
252
+ .translate(-originSize / 2, -originSize / 2)
253
+ .stroke('none').fill('blue');
231
254
  const lines = [];
232
255
  const smallOffset = milsToMM(3);
233
- const startY = gridStartY - smallOffset / 2;
234
- const endY = gridEndY + smallOffset;
256
+ const startY = gridStartY.sub(smallOffset.half());
257
+ const endY = gridEndY.add(smallOffset);
258
+ const numericGridSize = numeric(gridSize);
235
259
  for (let i = 0; i < numCols; i++) {
236
- const startX = gridStartX + i * gridSize;
237
- lines.push(`M ${startX} ${startY} L ${startX} ${endY}`);
260
+ const startX = gridStartX.add(numericGridSize.mul(i)).toNumber();
261
+ lines.push(`M ${startX} ${startY.toNumber()} L ${startX} ${endY.toNumber()}`);
238
262
  }
239
263
  const strokeSize = milsToMM(3);
240
- group.path(lines.join(" "))
264
+ group.addClass('grid')
265
+ .path(lines.join(" "))
241
266
  .attr({
242
- 'stroke-dasharray': `${strokeSize},${gridSize - strokeSize}`,
267
+ 'stroke-dasharray': `${strokeSize.toNumber()},${numericGridSize.sub(strokeSize).toNumber()}`,
243
268
  })
244
269
  .stroke({
245
- width: strokeSize,
270
+ width: strokeSize.toNumber(),
246
271
  color: '#000'
247
272
  });
248
273
  }
@@ -259,94 +284,7 @@ function drawSheetFrameBorder(frameGroup, frame) {
259
284
  symbol.draw(sheetFrameGroup);
260
285
  const offsetX = milsToMM(frameComponent.getParam('offset_x'));
261
286
  const offsetY = milsToMM(frameComponent.getParam('offset_y'));
262
- sheetFrameGroup.translate(-offsetX, -offsetY);
263
- }
264
- }
265
- }
266
- function drawSheetFrameBorderDirect(frameGroup, frame, borderWidth, strokeColor, width, height) {
267
- const commonStroke = {
268
- width: milsToMM(borderWidth),
269
- color: strokeColor
270
- };
271
- const commonFont = {
272
- family: defaultFont,
273
- size: 50 * fontDisplayScale,
274
- 'dominant-baseline': 'middle',
275
- 'text-anchor': 'middle',
276
- };
277
- let rows = 1;
278
- let columns = 1;
279
- let showGridReference = true;
280
- if (PaperGridReferences[frame.size]) {
281
- [rows, columns] = PaperGridReferences[frame.size];
282
- }
283
- else {
284
- showGridReference = false;
285
- }
286
- if (!showGridReference) {
287
- return;
288
- }
289
- const outerMargin = 2;
290
- const outerWidth = width + outerMargin * 2;
291
- const outerHeight = height + outerMargin * 2;
292
- const outerRect = frameGroup.rect(outerWidth, outerHeight)
293
- .fill('none')
294
- .stroke(commonStroke);
295
- outerRect.translate(frame.x - outerMargin, frame.y - outerMargin);
296
- const gridWidth = outerWidth / columns;
297
- const gridHeight = outerHeight / rows;
298
- const pathPoints = [];
299
- for (let i = 1; i < rows + 1; i++) {
300
- const lineStartX = frame.x - outerMargin;
301
- const lineStartX2 = frame.x - outerMargin + outerWidth - outerMargin;
302
- const lineY = frame.y - outerMargin + (gridHeight * i);
303
- if (i < rows) {
304
- pathPoints.push(...[
305
- "M", lineStartX, lineY, "L", lineStartX + outerMargin, lineY,
306
- "M", lineStartX2, lineY, "L", lineStartX2 + outerMargin, lineY
307
- ]);
287
+ sheetFrameGroup.translate(-offsetX.toNumber(), -offsetY.toNumber());
308
288
  }
309
- const displayValue = String.fromCharCode(i + 64);
310
- frameGroup.text(displayValue)
311
- .font(commonFont)
312
- .translate(lineStartX + outerMargin / 2, lineY - gridHeight / 2);
313
- frameGroup.text(displayValue)
314
- .font(commonFont)
315
- .translate(lineStartX2 + outerMargin / 2, lineY - gridHeight / 2);
316
- }
317
- for (let i = 1; i < columns + 1; i++) {
318
- const lineStartY = frame.y - outerMargin;
319
- const lineStartY2 = frame.y - outerMargin + outerHeight - outerMargin;
320
- const lineX = frame.x - outerMargin + (gridWidth * i);
321
- if (i < columns) {
322
- pathPoints.push(...[
323
- "M", lineX, lineStartY, "L", lineX, lineStartY + outerMargin,
324
- "M", lineX, lineStartY2, "L", lineX, lineStartY2 + outerMargin
325
- ]);
326
- }
327
- frameGroup.text(i.toString())
328
- .font(commonFont)
329
- .translate(lineX - gridWidth / 2, lineStartY + outerMargin / 2 + milsToMM(10));
330
- frameGroup.text(i.toString())
331
- .font(commonFont)
332
- .translate(lineX - gridWidth / 2, lineStartY2 + outerMargin / 2 + milsToMM(10));
333
- }
334
- frameGroup.path(pathPoints).stroke(commonStroke);
335
- const titleWidth = milsToMM(3000);
336
- const titleHeight = milsToMM(1000);
337
- const rowHeight = milsToMM(200);
338
- const points = [
339
- "M", width - titleWidth, height,
340
- "L", width - titleWidth, height - titleHeight,
341
- "L", width, height - titleHeight,
342
- "M", width - titleWidth, height - rowHeight,
343
- "L", width, height - rowHeight,
344
- "M", width - titleWidth, height - rowHeight * 2,
345
- "L", width, height - rowHeight * 2,
346
- "M", width - titleWidth, height - rowHeight * 3,
347
- "L", width, height - rowHeight * 3
348
- ];
349
- frameGroup.path(points).stroke(commonStroke).fill('none');
350
- if (frame.containsTitle) {
351
289
  }
352
290
  }
@@ -1,5 +1,5 @@
1
1
  import { SVG, registerWindow } from '@svgdotjs/svg.js';
2
- import { HorizontalAlign, VerticalAlign } from './geometry.mjs';
2
+ import { HorizontalAlign, HorizontalAlignProp, VerticalAlign, VerticalAlignProp } from './geometry.mjs';
3
3
  import { defaultFont } from './globals.mjs';
4
4
  import { JSModuleType, detectJSModuleType } from './helpers.mjs';
5
5
  let MainCanvas = null;
@@ -38,27 +38,53 @@ export function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regul
38
38
  }
39
39
  const key = `${text}-${fontFamily}-${fontSize}-${fontWeight}-${anchor}-${vanchor}`;
40
40
  if (measureTextSizeCache[key] === undefined) {
41
- let dominantBaseline = 'hanging';
41
+ let dominantBaseline = VerticalAlignProp.Hanging;
42
42
  switch (vanchor) {
43
43
  case VerticalAlign.Top:
44
- dominantBaseline = 'hanging';
44
+ dominantBaseline = VerticalAlignProp.Hanging;
45
45
  break;
46
46
  case VerticalAlign.Middle:
47
- dominantBaseline = 'middle';
47
+ dominantBaseline = VerticalAlignProp.Central;
48
48
  break;
49
49
  case VerticalAlign.Bottom:
50
- dominantBaseline = 'text-top';
50
+ dominantBaseline = VerticalAlignProp.TextTop;
51
+ break;
52
+ }
53
+ let useAnchor = HorizontalAlignProp.Start;
54
+ switch (anchor) {
55
+ case HorizontalAlign.Left:
56
+ useAnchor = HorizontalAlignProp.Start;
57
+ break;
58
+ case HorizontalAlign.Middle:
59
+ useAnchor = HorizontalAlignProp.Middle;
60
+ break;
61
+ case HorizontalAlign.Right:
62
+ useAnchor = HorizontalAlignProp.End;
51
63
  break;
52
64
  }
53
65
  fontFamily = defaultFont;
54
66
  const tmpTextElement = MainCanvas.text(text).font({
55
67
  family: fontFamily,
56
68
  size: fontSize,
57
- anchor: anchor,
69
+ anchor: useAnchor,
58
70
  'dominant-baseline': dominantBaseline,
59
71
  weight: fontWeight,
60
- }).fill('#333');
61
- const textbox = tmpTextElement.bbox();
72
+ })
73
+ .attr("xml:space", "preserve")
74
+ .fill('#333');
75
+ let textbox = tmpTextElement.bbox();
76
+ const tmpTextBox = { ...textbox };
77
+ if (dominantBaseline === VerticalAlignProp.Hanging) {
78
+ tmpTextBox.y = textbox.cy - textbox.height;
79
+ tmpTextBox.y2 = tmpTextBox.y + textbox.height;
80
+ textbox = tmpTextBox;
81
+ }
82
+ else if (dominantBaseline === VerticalAlignProp.Central) {
83
+ tmpTextBox.y -= textbox.cy;
84
+ tmpTextBox.y2 -= textbox.cy;
85
+ tmpTextBox.cy = 0;
86
+ textbox = tmpTextBox;
87
+ }
62
88
  const { width, height } = textbox;
63
89
  tmpTextElement.remove();
64
90
  measureTextSizeCache[key] = {
@@ -1,3 +1,5 @@
1
+ import { Big } from 'big.js';
2
+ import { NumericValue } from "./objects/ParamDefinition";
1
3
  export class SimpleStopwatch {
2
4
  startTime;
3
5
  constructor() {
@@ -64,7 +66,7 @@ export function getPortType(component) {
64
66
  return foundPinType;
65
67
  }
66
68
  export function roundValue(value) {
67
- return +value.toFixed(7);
69
+ return resolveToNumericValue(new Big(value.toBigNumber().toFixed(7)));
68
70
  }
69
71
  export function throwWithContext(context, message) {
70
72
  const startLine = context.start?.line;
@@ -88,3 +90,80 @@ export function combineMaps(map1, map2) {
88
90
  });
89
91
  return newMap;
90
92
  }
93
+ export function getNumberExponential(value) {
94
+ value = value.trim();
95
+ switch (value) {
96
+ case 'G':
97
+ return 9;
98
+ case 'M':
99
+ return 6;
100
+ case 'k':
101
+ case 'K':
102
+ return 3;
103
+ case 'm':
104
+ return -3;
105
+ case 'u':
106
+ return -6;
107
+ case 'n':
108
+ return -9;
109
+ case 'p':
110
+ return -12;
111
+ case 'f':
112
+ return -15;
113
+ default:
114
+ return 0;
115
+ }
116
+ }
117
+ export function getNumberExponentialText(value) {
118
+ switch (value) {
119
+ case -15:
120
+ return 'f';
121
+ case -12:
122
+ return 'p';
123
+ case -9:
124
+ return 'n';
125
+ case -6:
126
+ return 'u';
127
+ case -3:
128
+ return 'm';
129
+ case 3:
130
+ return 'k';
131
+ case 6:
132
+ return 'M';
133
+ case 9:
134
+ return 'G';
135
+ case 0:
136
+ default:
137
+ return '';
138
+ }
139
+ }
140
+ export function resolveToNumericValue(value) {
141
+ if (value.toNumber() === 0) {
142
+ return new NumericValue(0);
143
+ }
144
+ const isNeg = value.lt(0);
145
+ const positiveValue = isNeg ? value.neg() : value;
146
+ const prefixPart = Math.floor(Math.log10(positiveValue.toNumber()) / 3);
147
+ let useValue = value;
148
+ if (prefixPart !== 0) {
149
+ const tmpValue1 = positiveValue.div(Math.pow(10, prefixPart * 3));
150
+ useValue = isNeg ? tmpValue1.neg() : tmpValue1;
151
+ }
152
+ return new NumericValue(useValue, prefixPart * 3);
153
+ }
154
+ export function isPointWithinArea(point, bounds) {
155
+ const [xPt, yPt] = point;
156
+ const [xmin, ymin, xmax, ymax] = bounds;
157
+ return (xPt > xmin && xPt < xmax && yPt > ymin && yPt < ymax);
158
+ }
159
+ export function areasOverlap(area1, area2) {
160
+ const [xmin, ymin, xmax, ymax] = area1;
161
+ const pt1 = [xmin, ymin];
162
+ const pt2 = [xmin, ymax];
163
+ const pt3 = [xmax, ymin];
164
+ const pt4 = [xmax, ymax];
165
+ return isPointWithinArea(pt1, area2)
166
+ || isPointWithinArea(pt2, area2)
167
+ || isPointWithinArea(pt3, area2)
168
+ || isPointWithinArea(pt4, area2);
169
+ }