circuitscript 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseVisitor.js +394 -262
- package/dist/cjs/LexerDiagnosticListener.js +375 -0
- package/dist/cjs/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/cjs/annotate/DefaultPostAnnotationCallback.js +126 -0
- package/dist/cjs/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +8 -82
- package/dist/cjs/annotate/utils.js +70 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +279 -286
- package/dist/cjs/antlr/CircuitScriptParser.js +1954 -3535
- package/dist/cjs/antlr/CircuitScriptParserVisitor.js +7 -0
- package/dist/cjs/cache/deserializer.js +34 -0
- package/dist/cjs/cache/hash.js +8 -0
- package/dist/cjs/cache/serializer.js +122 -0
- package/dist/cjs/cache/storage.js +45 -0
- package/dist/cjs/cache/types.js +4 -0
- package/dist/cjs/{environment.js → environment/environment.js} +18 -6
- package/dist/cjs/environment/esm-environment.js +21 -0
- package/dist/cjs/environment/helpers.js +8 -0
- package/dist/cjs/execute.js +49 -15
- package/dist/cjs/globals.js +9 -1
- package/dist/cjs/helpers.js +3 -485
- package/dist/cjs/importResolver.js +102 -0
- package/dist/cjs/index.js +12 -7
- package/dist/cjs/lexer.js +48 -12
- package/dist/cjs/main.js +14 -4
- package/dist/cjs/objects/ClassComponent.js +1 -1
- package/dist/cjs/objects/ExecutionScope.js +0 -1
- package/dist/cjs/objects/types.js +17 -1
- package/dist/cjs/parser.js +18 -4
- package/dist/cjs/pipeline.js +284 -0
- package/dist/cjs/regenerate-tests.js +4 -3
- package/dist/cjs/render/KiCadNetListOutputHandler.js +30 -0
- package/dist/cjs/render/PaperSizes.js +46 -0
- package/dist/cjs/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/cjs/{export.js → render/export.js} +2 -2
- package/dist/cjs/{geometry.js → render/geometry.js} +5 -5
- package/dist/cjs/{graph.js → render/graph.js} +7 -7
- package/dist/cjs/{layout.js → render/layout.js} +8 -8
- package/dist/cjs/{render.js → render/render.js} +9 -8
- package/dist/cjs/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/cjs/rules-check/unconnected-pins.js +1 -1
- package/dist/cjs/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/cjs/semantic-tokens/getSemanticTokens.js +55 -0
- package/dist/cjs/sizing.js +2 -2
- package/dist/cjs/utils.js +2 -2
- package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +6 -0
- package/dist/cjs/validate/SymbolValidatorVisitor.js +34 -39
- package/dist/cjs/validate/validateScript.js +54 -0
- package/dist/cjs/validate.js +5 -4
- package/dist/cjs/visitor.js +140 -204
- package/dist/esm/BaseVisitor.js +396 -264
- package/dist/esm/LexerDiagnosticListener.js +371 -0
- package/dist/esm/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/esm/annotate/DefaultPostAnnotationCallback.js +122 -0
- package/dist/esm/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +8 -82
- package/dist/esm/annotate/utils.js +66 -0
- package/dist/esm/antlr/CircuitScriptLexer.js +279 -286
- package/dist/esm/antlr/CircuitScriptParser.js +1962 -3522
- package/dist/esm/antlr/{CircuitScriptVisitor.js → CircuitScriptParserVisitor.js} +14 -35
- package/dist/esm/cache/deserializer.js +30 -0
- package/dist/esm/cache/hash.js +4 -0
- package/dist/esm/cache/serializer.js +118 -0
- package/dist/esm/cache/storage.js +39 -0
- package/dist/esm/cache/types.js +1 -0
- package/dist/esm/{environment.js → environment/environment.js} +18 -6
- package/dist/esm/environment/esm-environment.js +17 -0
- package/dist/esm/environment/helpers.js +4 -0
- package/dist/esm/execute.js +49 -15
- package/dist/esm/globals.js +8 -0
- package/dist/esm/helpers.js +5 -474
- package/dist/esm/importResolver.js +96 -0
- package/dist/esm/index.js +12 -7
- package/dist/esm/lexer.js +51 -12
- package/dist/esm/main.js +13 -3
- package/dist/esm/objects/ClassComponent.js +1 -1
- package/dist/esm/objects/ExecutionScope.js +0 -1
- package/dist/esm/objects/types.js +21 -1
- package/dist/esm/parser.js +19 -5
- package/dist/esm/pipeline.js +276 -0
- package/dist/esm/regenerate-tests.js +3 -2
- package/dist/esm/render/KiCadNetListOutputHandler.js +20 -0
- package/dist/esm/render/PaperSizes.js +41 -0
- package/dist/esm/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/esm/{export.js → render/export.js} +2 -2
- package/dist/esm/{geometry.js → render/geometry.js} +5 -5
- package/dist/esm/{graph.js → render/graph.js} +7 -7
- package/dist/esm/{layout.js → render/layout.js} +8 -8
- package/dist/esm/{render.js → render/render.js} +8 -7
- package/dist/esm/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/esm/rules-check/unconnected-pins.js +1 -1
- package/dist/esm/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/esm/semantic-tokens/getSemanticTokens.js +51 -0
- package/dist/esm/sizing.js +2 -2
- package/dist/esm/utils.js +2 -2
- package/dist/esm/validate/SymbolValidatorResolveVisitor.js +3 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +36 -41
- package/dist/esm/validate/validateScript.js +50 -0
- package/dist/esm/validate.js +4 -3
- package/dist/esm/visitor.js +142 -206
- package/dist/libs/std.cst +15 -19
- package/dist/types/BaseVisitor.d.ts +25 -18
- package/dist/types/BomGeneration.d.ts +1 -1
- package/dist/types/LexerDiagnosticListener.d.ts +85 -0
- package/dist/types/{ComponentAnnotater.d.ts → annotate/ComponentAnnotater.d.ts} +1 -1
- package/dist/types/annotate/DefaultPostAnnotationCallback.d.ts +7 -0
- package/dist/types/{RefdesAnnotationVisitor.d.ts → annotate/RefdesAnnotationVisitor.d.ts} +6 -8
- package/dist/types/annotate/utils.d.ts +6 -0
- package/dist/types/antlr/CircuitScriptLexer.d.ts +71 -70
- package/dist/types/antlr/CircuitScriptParser.d.ts +357 -515
- package/dist/types/antlr/{CircuitScriptVisitor.d.ts → CircuitScriptParserVisitor.d.ts} +27 -69
- package/dist/types/cache/deserializer.d.ts +5 -0
- package/dist/types/cache/hash.d.ts +1 -0
- package/dist/types/cache/serializer.d.ts +3 -0
- package/dist/types/cache/storage.d.ts +4 -0
- package/dist/types/cache/types.d.ts +20 -0
- package/dist/types/{environment.d.ts → environment/environment.d.ts} +5 -4
- package/dist/types/environment/esm-environment.d.ts +4 -0
- package/dist/types/environment/helpers.d.ts +2 -0
- package/dist/types/execute.d.ts +3 -2
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/helpers.d.ts +31 -36
- package/dist/types/importResolver.d.ts +4 -0
- package/dist/types/index.d.ts +12 -7
- package/dist/types/lexer.d.ts +9 -5
- package/dist/types/objects/ClassComponent.d.ts +1 -1
- package/dist/types/objects/ExecutionScope.d.ts +1 -4
- package/dist/types/objects/types.d.ts +16 -2
- package/dist/types/parser.d.ts +9 -2
- package/dist/types/pipeline.d.ts +9 -0
- package/dist/types/render/KiCadNetListOutputHandler.d.ts +10 -0
- package/dist/types/render/PaperSizes.d.ts +12 -0
- package/dist/types/{draw_symbols.d.ts → render/draw_symbols.d.ts} +4 -4
- package/dist/types/{export.d.ts → render/export.d.ts} +1 -1
- package/dist/types/{geometry.d.ts → render/geometry.d.ts} +2 -2
- package/dist/types/{graph.d.ts → render/graph.d.ts} +6 -6
- package/dist/types/{layout.d.ts → render/layout.d.ts} +10 -10
- package/dist/types/{render.d.ts → render/render.d.ts} +1 -1
- package/dist/types/{SemanticTokenVisitor.d.ts → semantic-tokens/SemanticTokenVisitor.d.ts} +6 -6
- package/dist/types/semantic-tokens/getSemanticTokens.d.ts +6 -0
- package/dist/types/sizing.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +3 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +8 -8
- package/dist/types/validate/validateScript.d.ts +3 -0
- package/dist/types/visitor.d.ts +8 -14
- package/libs/std.cst +15 -19
- package/package.json +3 -6
- package/dist/cjs/antlr/CircuitScriptVisitor.js +0 -7
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CircuitScriptParserVisitor = void 0;
|
|
4
|
+
const antlr4ng_1 = require("antlr4ng");
|
|
5
|
+
class CircuitScriptParserVisitor extends antlr4ng_1.AbstractParseTreeVisitor {
|
|
6
|
+
}
|
|
7
|
+
exports.CircuitScriptParserVisitor = CircuitScriptParserVisitor;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeLibraryScope = void 0;
|
|
4
|
+
const types_js_1 = require("../objects/types.js");
|
|
5
|
+
function deserializeLibraryScope(ir, name, libraryNamespace, filePathUsed, importHandling, specificImports, importContext, parseAndVisit, enterContext, exitContext, libraryFileHash) {
|
|
6
|
+
const importedLibrary = new types_js_1.ImportedLibrary(name, libraryNamespace, filePathUsed, null, null, importContext, importHandling, specificImports, libraryFileHash);
|
|
7
|
+
ir.functions.forEach(func => {
|
|
8
|
+
const { name, uniqueId } = func;
|
|
9
|
+
const functionEntry = importContext.createFunctionLazyLoaded(importContext.namespace, name, uniqueId);
|
|
10
|
+
functionEntry.lazyLoader = () => {
|
|
11
|
+
importContext.log(`loading lazy function ${name}`);
|
|
12
|
+
enterContext();
|
|
13
|
+
const [line, column, sourceText] = func.sourceText;
|
|
14
|
+
const { tokens, tree } = parseAndVisit(sourceText, line - 1);
|
|
15
|
+
importedLibrary.referencedTokens.push([tokens, tree]);
|
|
16
|
+
exitContext();
|
|
17
|
+
functionEntry.tokens = tokens;
|
|
18
|
+
functionEntry.tree = tree;
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
enterContext();
|
|
22
|
+
for (const importStatement of ir.imports) {
|
|
23
|
+
const [line, column, statement] = importStatement;
|
|
24
|
+
parseAndVisit(statement, line - 1);
|
|
25
|
+
}
|
|
26
|
+
for (const block of (ir.topLevel ?? [])) {
|
|
27
|
+
const [line, column, sourceText] = block;
|
|
28
|
+
const { tokens, tree } = parseAndVisit(sourceText, line - 1);
|
|
29
|
+
importedLibrary.referencedTokens.push([tokens, tree]);
|
|
30
|
+
}
|
|
31
|
+
exitContext();
|
|
32
|
+
return importedLibrary;
|
|
33
|
+
}
|
|
34
|
+
exports.deserializeLibraryScope = deserializeLibraryScope;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeContentHash = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
function computeContentHash(fileContent) {
|
|
6
|
+
return (0, crypto_1.createHash)('sha256').update(fileContent, 'utf8').digest('hex');
|
|
7
|
+
}
|
|
8
|
+
exports.computeContentHash = computeContentHash;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeLibraryScope = void 0;
|
|
4
|
+
const types_js_1 = require("./types.js");
|
|
5
|
+
const CircuitScriptLexer_js_1 = require("../antlr/CircuitScriptLexer.js");
|
|
6
|
+
const utils_js_1 = require("../annotate/utils.js");
|
|
7
|
+
function serializeLibraryScope(importedLib, contentHash) {
|
|
8
|
+
const functions = [];
|
|
9
|
+
const topLevelExpressions = [];
|
|
10
|
+
const scope = importedLib.context.scope;
|
|
11
|
+
const { tokens: libraryTokens, refdesAnnotations } = importedLib;
|
|
12
|
+
const libraryInputStream = libraryTokens.tokenSource.inputStream;
|
|
13
|
+
scope.functions.forEach((entry) => {
|
|
14
|
+
let useSource = '';
|
|
15
|
+
let useTokenLine = 0;
|
|
16
|
+
let useTokenColumn = 0;
|
|
17
|
+
if (libraryTokens !== null && entry.source !== null) {
|
|
18
|
+
const source = entry.source;
|
|
19
|
+
const startIndex = source.start?.tokenIndex ?? 0;
|
|
20
|
+
const stopIndex = source.stop?.tokenIndex ?? -1;
|
|
21
|
+
const contextTokens = libraryTokens.getTokens(startIndex, stopIndex);
|
|
22
|
+
const startToken = source.start;
|
|
23
|
+
const startChar = startToken.start ?? -1;
|
|
24
|
+
const stopChar = getFunctionDefinitionEnding(source, libraryTokens);
|
|
25
|
+
const sourceText = libraryInputStream != null && startChar >= 0 && stopChar >= 0
|
|
26
|
+
? libraryInputStream.getTextFromRange(startChar, stopChar)
|
|
27
|
+
: libraryTokens.getTextFromContext(source);
|
|
28
|
+
useSource = (0, utils_js_1.generateModifiedSourceText)(refdesAnnotations, contextTokens, sourceText, startToken.start);
|
|
29
|
+
useTokenLine = startToken.line;
|
|
30
|
+
useTokenColumn = startToken.column;
|
|
31
|
+
}
|
|
32
|
+
functions.push({
|
|
33
|
+
name: entry.name,
|
|
34
|
+
namespace: entry.originalNamespace,
|
|
35
|
+
uniqueId: entry.uniqueId ?? '',
|
|
36
|
+
sourceText: [
|
|
37
|
+
useTokenLine, useTokenColumn, useSource
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
const tree = importedLib.tree;
|
|
42
|
+
if (tree != null) {
|
|
43
|
+
let groupCtx = [];
|
|
44
|
+
let groupStart = null;
|
|
45
|
+
let prevStopLine = null;
|
|
46
|
+
const flushGroup = () => {
|
|
47
|
+
let useSource = '';
|
|
48
|
+
if (groupCtx.length > 0 && groupStart !== null) {
|
|
49
|
+
const startToken = groupCtx[0].start;
|
|
50
|
+
const stopToken = groupCtx[groupCtx.length - 1].stop;
|
|
51
|
+
const startIndex = startToken.tokenIndex ?? 0;
|
|
52
|
+
const stopIndex = stopToken.tokenIndex ?? -1;
|
|
53
|
+
const contextTokens = libraryTokens.getTokens(startIndex, stopIndex);
|
|
54
|
+
const startChar = startToken.start ?? -1;
|
|
55
|
+
const stopChar = stopToken.stop ?? -1;
|
|
56
|
+
const sourceText = libraryInputStream.getTextFromRange(startChar, stopChar);
|
|
57
|
+
useSource = (0, utils_js_1.generateModifiedSourceText)(refdesAnnotations, contextTokens, sourceText, startToken.start);
|
|
58
|
+
topLevelExpressions.push([
|
|
59
|
+
...groupStart,
|
|
60
|
+
useSource
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
groupCtx = [];
|
|
64
|
+
groupStart = null;
|
|
65
|
+
prevStopLine = null;
|
|
66
|
+
};
|
|
67
|
+
for (const exprCtx of tree.expression()) {
|
|
68
|
+
if (exprCtx.function_def_expr() !== null) {
|
|
69
|
+
flushGroup();
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (exprCtx.NEWLINE() !== null) {
|
|
73
|
+
if (groupCtx.length > 0) {
|
|
74
|
+
groupCtx.push(exprCtx);
|
|
75
|
+
}
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const startToken = exprCtx.start;
|
|
79
|
+
if (startToken == null)
|
|
80
|
+
continue;
|
|
81
|
+
const currentStartLine = startToken.line;
|
|
82
|
+
if (prevStopLine !== null && currentStartLine > prevStopLine + 1) {
|
|
83
|
+
flushGroup();
|
|
84
|
+
}
|
|
85
|
+
if (groupStart == null) {
|
|
86
|
+
groupStart = [currentStartLine, startToken.column];
|
|
87
|
+
}
|
|
88
|
+
groupCtx.push(exprCtx);
|
|
89
|
+
prevStopLine = exprCtx.stop?.line ?? currentStartLine;
|
|
90
|
+
}
|
|
91
|
+
flushGroup();
|
|
92
|
+
}
|
|
93
|
+
const imports = [];
|
|
94
|
+
for (const [libName, lib] of importedLib.context.scope.libraries) {
|
|
95
|
+
imports.push(lib.importStatement);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
schemaVersion: types_js_1.CACHE_SCHEMA_VERSION,
|
|
99
|
+
contentHash,
|
|
100
|
+
libraryFilePath: importedLib.libraryFilePath,
|
|
101
|
+
imports,
|
|
102
|
+
functions,
|
|
103
|
+
topLevel: topLevelExpressions,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
exports.serializeLibraryScope = serializeLibraryScope;
|
|
107
|
+
function getFunctionDefinitionEnding(source, tokens) {
|
|
108
|
+
let stopChar = source.stop?.stop ?? -1;
|
|
109
|
+
const stopTokenIndex = source.stop?.tokenIndex ?? -1;
|
|
110
|
+
if (stopTokenIndex >= 0) {
|
|
111
|
+
for (let i = stopTokenIndex; i >= 0; i--) {
|
|
112
|
+
const tok = tokens.get(i);
|
|
113
|
+
if (tok.type !== CircuitScriptLexer_js_1.CircuitScriptLexer.NEWLINE &&
|
|
114
|
+
tok.type !== CircuitScriptLexer_js_1.CircuitScriptLexer.DEDENT &&
|
|
115
|
+
tok.type !== CircuitScriptLexer_js_1.CircuitScriptLexer.INDENT) {
|
|
116
|
+
stopChar = tok.stop ?? stopChar;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return stopChar;
|
|
122
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeCache = exports.readCache = exports.getCachePath = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const types_js_1 = require("./types.js");
|
|
7
|
+
function getCachePath(libFilePath) {
|
|
8
|
+
const dir = (0, path_1.dirname)(libFilePath);
|
|
9
|
+
const base = (0, path_1.basename)(libFilePath);
|
|
10
|
+
return (0, path_1.join)(dir, '.cst.cache', `${base}.json`);
|
|
11
|
+
}
|
|
12
|
+
exports.getCachePath = getCachePath;
|
|
13
|
+
function readCache(libFilePath, hash) {
|
|
14
|
+
try {
|
|
15
|
+
const cachePath = getCachePath(libFilePath);
|
|
16
|
+
if (!(0, fs_1.existsSync)(cachePath)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const raw = (0, fs_1.readFileSync)(cachePath, 'utf8');
|
|
20
|
+
const ir = JSON.parse(raw);
|
|
21
|
+
if (ir.schemaVersion !== types_js_1.CACHE_SCHEMA_VERSION || ir.contentHash !== hash) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return ir;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.readCache = readCache;
|
|
31
|
+
function writeCache(libFilePath, hash, ir) {
|
|
32
|
+
try {
|
|
33
|
+
const cachePath = getCachePath(libFilePath);
|
|
34
|
+
const cacheDir = (0, path_1.dirname)(cachePath);
|
|
35
|
+
if (!(0, fs_1.existsSync)(cacheDir)) {
|
|
36
|
+
(0, fs_1.mkdirSync)(cacheDir, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
const tmp = cachePath + '.tmp';
|
|
39
|
+
(0, fs_1.writeFileSync)(tmp, JSON.stringify(ir), 'utf8');
|
|
40
|
+
(0, fs_1.renameSync)(tmp, cachePath);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.writeCache = writeCache;
|
|
@@ -8,8 +8,8 @@ const svg_js_1 = require("@svgdotjs/svg.js");
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
11
|
-
const globals_js_1 = require("
|
|
12
|
-
const utils_js_1 = require("
|
|
11
|
+
const globals_js_1 = require("../globals.js");
|
|
12
|
+
const utils_js_1 = require("../utils.js");
|
|
13
13
|
class NodeScriptEnvironment {
|
|
14
14
|
constructor() {
|
|
15
15
|
this.useModuleDirectoryPath = null;
|
|
@@ -60,14 +60,15 @@ class NodeScriptEnvironment {
|
|
|
60
60
|
return this.useModuleDirectoryPath;
|
|
61
61
|
}
|
|
62
62
|
if (typeof __dirname !== 'undefined') {
|
|
63
|
-
return __dirname;
|
|
63
|
+
return path_1.default.resolve(__dirname + "/../");
|
|
64
64
|
}
|
|
65
65
|
const stackLine = new Error().stack?.split('\n')[1];
|
|
66
66
|
if (stackLine) {
|
|
67
67
|
const fileMatch = stackLine.match(/\((.+)\:[\d]+\:[\d]+\)/);
|
|
68
68
|
if (fileMatch) {
|
|
69
69
|
const filePath = fileMatch[1].replace('file://', '');
|
|
70
|
-
|
|
70
|
+
const finalPath = path_1.default.resolve(path_1.default.dirname(filePath) + "/../");
|
|
71
|
+
return finalPath;
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
throw new utils_js_1.RuntimeExecutionError("Failed to get current module directory");
|
|
@@ -134,7 +135,15 @@ class NodeScriptEnvironment {
|
|
|
134
135
|
return path_1.default.resolve(filePath);
|
|
135
136
|
}
|
|
136
137
|
getDirPath(filePath) {
|
|
137
|
-
|
|
138
|
+
const resolved = path_1.default.resolve(filePath);
|
|
139
|
+
try {
|
|
140
|
+
if (fs_1.default.statSync(resolved).isDirectory()) {
|
|
141
|
+
return resolved;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
}
|
|
146
|
+
return path_1.default.dirname(resolved);
|
|
138
147
|
}
|
|
139
148
|
setCurrentFile(filePath) {
|
|
140
149
|
this.currentFile = this.getAbsolutePath(filePath);
|
|
@@ -143,7 +152,7 @@ class NodeScriptEnvironment {
|
|
|
143
152
|
getCurrentFile() {
|
|
144
153
|
return this.currentFile;
|
|
145
154
|
}
|
|
146
|
-
|
|
155
|
+
getAbsPathRelativeToCurrentFolder(filePath) {
|
|
147
156
|
return path_1.default.join(this.getDirPath(this.currentFile), filePath);
|
|
148
157
|
}
|
|
149
158
|
async exists(path) {
|
|
@@ -176,6 +185,9 @@ class NodeScriptEnvironment {
|
|
|
176
185
|
createWriteStream(filePath) {
|
|
177
186
|
return fs_1.default.createWriteStream(filePath);
|
|
178
187
|
}
|
|
188
|
+
getCurrentDirectory() {
|
|
189
|
+
return process.cwd();
|
|
190
|
+
}
|
|
179
191
|
}
|
|
180
192
|
exports.NodeScriptEnvironment = NodeScriptEnvironment;
|
|
181
193
|
NodeScriptEnvironment._instance = null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ESMNodeScriptEnvironment = void 0;
|
|
4
|
+
const svgdom_1 = require("svgdom");
|
|
5
|
+
const environment_1 = require("./environment");
|
|
6
|
+
class ESMNodeScriptEnvironment extends environment_1.NodeScriptEnvironment {
|
|
7
|
+
async prepareSVGEnvironmentInternal(fontsPath) {
|
|
8
|
+
try {
|
|
9
|
+
this.globalCreateSVGWindow = svgdom_1.createSVGWindow;
|
|
10
|
+
if (fontsPath !== null) {
|
|
11
|
+
await svgdom_1.config.setFontDir(fontsPath)
|
|
12
|
+
.setFontFamilyMappings(this.supportedFonts)
|
|
13
|
+
.preloadFonts();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
throw new Error(`Failed to load svgdom ESM module: ${error}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.ESMNodeScriptEnvironment = ESMNodeScriptEnvironment;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNewEnvironment = void 0;
|
|
4
|
+
const esm_environment_1 = require("./esm-environment");
|
|
5
|
+
function getNewEnvironment() {
|
|
6
|
+
return new esm_environment_1.ESMNodeScriptEnvironment();
|
|
7
|
+
}
|
|
8
|
+
exports.getNewEnvironment = getNewEnvironment;
|
package/dist/cjs/execute.js
CHANGED
|
@@ -10,9 +10,9 @@ const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
|
10
10
|
const types_js_1 = require("./objects/types.js");
|
|
11
11
|
const Wire_js_1 = require("./objects/Wire.js");
|
|
12
12
|
const Frame_js_1 = require("./objects/Frame.js");
|
|
13
|
-
const layout_js_1 = require("./layout.js");
|
|
13
|
+
const layout_js_1 = require("./render/layout.js");
|
|
14
14
|
const helpers_js_1 = require("./helpers.js");
|
|
15
|
-
const draw_symbols_js_1 = require("./draw_symbols.js");
|
|
15
|
+
const draw_symbols_js_1 = require("./render/draw_symbols.js");
|
|
16
16
|
const utils_js_1 = require("./utils.js");
|
|
17
17
|
class ExecutionContext {
|
|
18
18
|
constructor(name, namespace, netNamespace, executionLevel = 0, scopeLevel = 0, silent = false, logger, warnings, parent) {
|
|
@@ -615,10 +615,36 @@ class ExecutionContext {
|
|
|
615
615
|
return this.scope.breakStack[this.scope.breakStack.length - 1];
|
|
616
616
|
}
|
|
617
617
|
createFunction(namespace, functionName, __runFunc, source, uniqueId) {
|
|
618
|
-
const
|
|
619
|
-
|
|
618
|
+
const functionEntry = new types_js_1.CFunctionEntry(namespace, functionName, __runFunc, source, uniqueId);
|
|
619
|
+
const functionPath = functionEntry.getFunctionPath();
|
|
620
|
+
if (this.scope.functions.has(functionPath)) {
|
|
621
|
+
this.log(`function: ${functionPath} already exists`);
|
|
622
|
+
const existingEntry = this.scope.functions.get(functionPath);
|
|
623
|
+
if (existingEntry.lazyLoaded) {
|
|
624
|
+
this.log(`updating lazy function: ${functionPath}`);
|
|
625
|
+
existingEntry.execute = __runFunc;
|
|
626
|
+
existingEntry.source = source;
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
this.log(`function is already defined: ${functionName}`);
|
|
630
|
+
console.log(`WARNING: function is already defined ${functionName}`);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
this.scope.functions.set(functionPath, functionEntry);
|
|
635
|
+
this.log(`defined new function: ${functionPath}`);
|
|
636
|
+
}
|
|
620
637
|
this.__functionCache.set(functionPath, __runFunc);
|
|
621
|
-
|
|
638
|
+
return functionEntry;
|
|
639
|
+
}
|
|
640
|
+
createFunctionLazyLoaded(namespace, functionName, uniqueId) {
|
|
641
|
+
const functionEntry = new types_js_1.CFunctionEntry(namespace, functionName, null, null, uniqueId);
|
|
642
|
+
const functionPath = functionEntry.getFunctionPath();
|
|
643
|
+
functionEntry.lazyLoaded = true;
|
|
644
|
+
this.scope.functions.set(functionPath, functionEntry);
|
|
645
|
+
this.__functionCache.set(functionPath, null);
|
|
646
|
+
this.log(`defined new function with lazy flag: ${functionPath}`);
|
|
647
|
+
return functionEntry;
|
|
622
648
|
}
|
|
623
649
|
hasFunction(functionName) {
|
|
624
650
|
return this.scope.functions.has(functionName);
|
|
@@ -648,11 +674,11 @@ class ExecutionContext {
|
|
|
648
674
|
&& library.specifiedImports.indexOf(idName) !== -1)) {
|
|
649
675
|
const { context: libraryContext } = library;
|
|
650
676
|
const functionPath = `${libraryContext.namespace}${idName}`;
|
|
651
|
-
if (
|
|
677
|
+
if (libraryContext.hasFunction(functionPath)) {
|
|
652
678
|
return new types_js_1.DeclaredReference({
|
|
653
679
|
found: true,
|
|
654
680
|
rootValue: library,
|
|
655
|
-
value:
|
|
681
|
+
value: libraryContext.getFunction(functionPath),
|
|
656
682
|
type: globals_js_1.ReferenceTypes.function,
|
|
657
683
|
name: idName,
|
|
658
684
|
trailerIndex: 1,
|
|
@@ -759,7 +785,14 @@ class ExecutionContext {
|
|
|
759
785
|
}
|
|
760
786
|
callFunction(functionReference, functionParams, executionStack, netNamespace) {
|
|
761
787
|
const functionEntry = functionReference.value;
|
|
762
|
-
const { name: functionName
|
|
788
|
+
const { name: functionName } = functionEntry;
|
|
789
|
+
let { execute: __runFunc } = functionEntry;
|
|
790
|
+
if (__runFunc === null && functionEntry.lazyLoaded) {
|
|
791
|
+
this.log(`load lazy function: ${functionEntry.getFunctionPath()}`);
|
|
792
|
+
functionEntry.lazyLoader !== null && functionEntry.lazyLoader();
|
|
793
|
+
this.log(`done loading lazy function: ${functionEntry.getFunctionPath()}, replacing execute method`);
|
|
794
|
+
__runFunc = functionEntry.execute;
|
|
795
|
+
}
|
|
763
796
|
if (__runFunc !== null) {
|
|
764
797
|
let functionCallIndex = -1;
|
|
765
798
|
if (!this.scope.functionCounter.has(__runFunc)) {
|
|
@@ -941,7 +974,7 @@ class ExecutionContext {
|
|
|
941
974
|
[(0, ParamDefinition_js_1.numeric)(1), (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0),
|
|
942
975
|
(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)],
|
|
943
976
|
new Map([
|
|
944
|
-
["
|
|
977
|
+
["display_id", false]
|
|
945
978
|
]),
|
|
946
979
|
null
|
|
947
980
|
]
|
|
@@ -1077,8 +1110,9 @@ class ExecutionContext {
|
|
|
1077
1110
|
if (targetAngle === null) {
|
|
1078
1111
|
return;
|
|
1079
1112
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1113
|
+
const pinAngle = connectedPinPos.angle.toNumber();
|
|
1114
|
+
this.log('set component unit angle from wire, target angle:', targetAngle, ', component unit angle:', targetUnit.angleProp, 'pin angle:', pinAngle);
|
|
1115
|
+
let useAngle = (targetAngle - pinAngle) % 360;
|
|
1082
1116
|
if (useAngle < 0) {
|
|
1083
1117
|
useAngle += 360;
|
|
1084
1118
|
}
|
|
@@ -1086,12 +1120,12 @@ class ExecutionContext {
|
|
|
1086
1120
|
targetUnit.setParam(globals_js_1.ParamKeys.angle, (0, ParamDefinition_js_1.numeric)(90));
|
|
1087
1121
|
}
|
|
1088
1122
|
else if (useAngle === 180) {
|
|
1089
|
-
if (
|
|
1090
|
-
targetUnit.setParam(globals_js_1.ParamKeys.flipX, (0, ParamDefinition_js_1.numeric)(1));
|
|
1091
|
-
}
|
|
1092
|
-
else if (targetUnit.angleProp === 90 || targetUnit.angleProp === 270) {
|
|
1123
|
+
if (pinAngle == 90 || pinAngle == 270) {
|
|
1093
1124
|
targetUnit.setParam(globals_js_1.ParamKeys.flipY, (0, ParamDefinition_js_1.numeric)(1));
|
|
1094
1125
|
}
|
|
1126
|
+
else if (pinAngle == 0 || pinAngle == 180) {
|
|
1127
|
+
targetUnit.setParam(globals_js_1.ParamKeys.flipX, (0, ParamDefinition_js_1.numeric)(1));
|
|
1128
|
+
}
|
|
1095
1129
|
}
|
|
1096
1130
|
else if (useAngle === 270) {
|
|
1097
1131
|
targetUnit.setParam(globals_js_1.ParamKeys.angle, (0, ParamDefinition_js_1.numeric)(270));
|
package/dist/cjs/globals.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RenderFlags = exports.GlobalDocumentName = exports.ModuleContainsKeyword = exports.FrameType = exports.NetGraphicsParams = exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPageSpacingMM = exports.defaultPageMarginMM = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultWireLineWidth = exports.defaultSymbolLineWidth = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPt = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.ValidPinSides = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = exports.RefdesFileSuffix = exports.BaseNamespace = exports.DoubleDelimiter1 = exports.Delimiter1 = exports.TOOL_VERSION = void 0;
|
|
4
|
-
exports.DefaultComponentUnit = exports.TrailerArrayIndex = exports.SymbolValidatorContext = void 0;
|
|
4
|
+
exports.PinTypesList = exports.DefaultComponentUnit = exports.TrailerArrayIndex = exports.SymbolValidatorContext = void 0;
|
|
5
5
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
6
|
+
const PinTypes_js_1 = require("./objects/PinTypes.js");
|
|
6
7
|
exports.TOOL_VERSION = '0.1.5';
|
|
7
8
|
exports.Delimiter1 = '-';
|
|
8
9
|
exports.DoubleDelimiter1 = `${exports.Delimiter1}${exports.Delimiter1}`;
|
|
@@ -135,3 +136,10 @@ exports.RenderFlags = {
|
|
|
135
136
|
exports.SymbolValidatorContext = '_sym';
|
|
136
137
|
exports.TrailerArrayIndex = 'index';
|
|
137
138
|
exports.DefaultComponentUnit = '__default';
|
|
139
|
+
exports.PinTypesList = [
|
|
140
|
+
PinTypes_js_1.PinTypes.Any,
|
|
141
|
+
PinTypes_js_1.PinTypes.Input,
|
|
142
|
+
PinTypes_js_1.PinTypes.Output,
|
|
143
|
+
PinTypes_js_1.PinTypes.IO,
|
|
144
|
+
PinTypes_js_1.PinTypes.Power,
|
|
145
|
+
];
|