altium-toolkit 0.1.0
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/AGENTS.md +67 -0
- package/COMMERCIAL-LICENSE.md +20 -0
- package/CONTRIBUTING.md +19 -0
- package/LICENSE +22 -0
- package/LICENSES/CC-BY-SA-4.0.txt +170 -0
- package/LICENSES/GPL-3.0-or-later.txt +232 -0
- package/NOTICE.md +32 -0
- package/README.md +116 -0
- package/docs/api.md +73 -0
- package/docs/model-format.md +36 -0
- package/docs/testing.md +25 -0
- package/examples/README.md +47 -0
- package/examples/arduino-uno/PcbThreeSceneRenderer.mjs +635 -0
- package/examples/arduino-uno/SvgViewportController.mjs +306 -0
- package/examples/arduino-uno/example.mjs +480 -0
- package/examples/arduino-uno/index.html +163 -0
- package/examples/arduino-uno/styles.css +552 -0
- package/examples/server.mjs +212 -0
- package/package.json +53 -0
- package/spec/library-scope.md +32 -0
- package/src/core/BinaryReader.mjs +127 -0
- package/src/core/altium/AltiumLayoutParser.mjs +485 -0
- package/src/core/altium/AltiumParser.mjs +1007 -0
- package/src/core/altium/AsciiRecordParser.mjs +151 -0
- package/src/core/altium/ParserUtils.mjs +173 -0
- package/src/core/altium/PcbBinaryPrimitiveParser.mjs +424 -0
- package/src/core/altium/PcbEmbeddedModelExtractor.mjs +505 -0
- package/src/core/altium/PcbModelParser.mjs +336 -0
- package/src/core/altium/PcbOutlineRasterizer.mjs +852 -0
- package/src/core/altium/PcbOutlineRecovery.mjs +957 -0
- package/src/core/altium/PcbStreamExtractor.mjs +210 -0
- package/src/core/altium/PrintableTextDecoder.mjs +156 -0
- package/src/core/altium/SchematicAnnotationParser.mjs +220 -0
- package/src/core/altium/SchematicBusEntryParser.mjs +48 -0
- package/src/core/altium/SchematicDirectiveParser.mjs +47 -0
- package/src/core/altium/SchematicImageParser.mjs +173 -0
- package/src/core/altium/SchematicJunctionParser.mjs +43 -0
- package/src/core/altium/SchematicMultipartOwnerMatcher.mjs +564 -0
- package/src/core/altium/SchematicNetlistBuilder.mjs +351 -0
- package/src/core/altium/SchematicPinParser.mjs +767 -0
- package/src/core/altium/SchematicPrimitiveParser.mjs +716 -0
- package/src/core/altium/SchematicSheetParser.mjs +241 -0
- package/src/core/altium/SchematicSheetStyleResolver.mjs +46 -0
- package/src/core/altium/SchematicStandaloneCalloutNormalizer.mjs +592 -0
- package/src/core/altium/SchematicTextParser.mjs +708 -0
- package/src/core/altium/SchematicTextPostProcessor.mjs +801 -0
- package/src/core/ole/OleCompoundDocument.mjs +439 -0
- package/src/core/ole/OleConstants.mjs +64 -0
- package/src/core/ole/OleDirectoryEntry.mjs +95 -0
- package/src/index.mjs +7 -0
- package/src/parser.mjs +21 -0
- package/src/renderers.mjs +15 -0
- package/src/scene3d.mjs +9 -0
- package/src/styles/altium-renderers.css +358 -0
- package/src/ui/BomTableRenderer.mjs +46 -0
- package/src/ui/PcbArcUtils.mjs +189 -0
- package/src/ui/PcbEdgeFacingGlyphNormalizer.mjs +808 -0
- package/src/ui/PcbFootprintPrimitiveSelector.mjs +128 -0
- package/src/ui/PcbScene3dBuilder.mjs +742 -0
- package/src/ui/PcbScene3dModelRegistry.mjs +309 -0
- package/src/ui/PcbScene3dPackages.mjs +137 -0
- package/src/ui/PcbScene3dScenePreparator.mjs +36 -0
- package/src/ui/PcbScene3dSummaryRenderer.mjs +65 -0
- package/src/ui/PcbSvgRenderer.mjs +906 -0
- package/src/ui/SchematicColorResolver.mjs +132 -0
- package/src/ui/SchematicContentLayout.mjs +661 -0
- package/src/ui/SchematicDirectiveRenderer.mjs +184 -0
- package/src/ui/SchematicImageRenderer.mjs +135 -0
- package/src/ui/SchematicJunctionRenderer.mjs +381 -0
- package/src/ui/SchematicNoteRenderer.mjs +427 -0
- package/src/ui/SchematicOwnerPinLabelLayout.mjs +173 -0
- package/src/ui/SchematicPinSvgRenderer.mjs +495 -0
- package/src/ui/SchematicPortRenderer.mjs +558 -0
- package/src/ui/SchematicPowerPortRenderer.mjs +574 -0
- package/src/ui/SchematicRegionRenderer.mjs +94 -0
- package/src/ui/SchematicShapeRenderer.mjs +398 -0
- package/src/ui/SchematicSheetChromeRenderer.mjs +1025 -0
- package/src/ui/SchematicSheetSymbolRenderer.mjs +228 -0
- package/src/ui/SchematicSvgRenderer.mjs +756 -0
- package/src/ui/SchematicSvgUtils.mjs +182 -0
- package/src/ui/SchematicTypography.mjs +204 -0
- package/src/workers/altium-parser.worker.mjs +29 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 André Fiedler
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
4
|
+
|
|
5
|
+
const COLOR_TOKEN_BY_VALUE = new Map([
|
|
6
|
+
['#000080', '--schematic-default-ink-color'],
|
|
7
|
+
['#0000ff', '--schematic-accent-ink-color'],
|
|
8
|
+
['#000000', '--schematic-text-color'],
|
|
9
|
+
['#111111', '--schematic-text-color'],
|
|
10
|
+
['#1f1f1f', '--schematic-text-color'],
|
|
11
|
+
['#2c3134', '--schematic-text-color'],
|
|
12
|
+
['#4f4f4f', '--schematic-sheet-label-color'],
|
|
13
|
+
['#800000', '--schematic-power-color'],
|
|
14
|
+
['#8d2b2b', '--schematic-port-color'],
|
|
15
|
+
['#a44a1b', '--schematic-port-color'],
|
|
16
|
+
['#ff0000', '--schematic-alert-color'],
|
|
17
|
+
['#ffe16f', '--schematic-fill-color'],
|
|
18
|
+
['#ffff80', '--schematic-fill-color'],
|
|
19
|
+
['#ffffb0', '--schematic-fill-color'],
|
|
20
|
+
['#eceb94', '--schematic-note-fill-color'],
|
|
21
|
+
['#ffffff', '--schematic-fill-light-color'],
|
|
22
|
+
['#c0c0c0', '--schematic-note-border-color'],
|
|
23
|
+
['#7b7753', '--schematic-note-border-color']
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Maps recovered schematic source colors onto theme variables.
|
|
28
|
+
*/
|
|
29
|
+
export class SchematicColorResolver {
|
|
30
|
+
/**
|
|
31
|
+
* Resolves one SVG color value to a schematic theme variable.
|
|
32
|
+
* @param {string | undefined} color
|
|
33
|
+
* @param {string} fallbackVariable
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
static resolveColor(color, fallbackVariable, preserveUnknown = false) {
|
|
37
|
+
const normalized = SchematicColorResolver.#normalizeColor(color)
|
|
38
|
+
|
|
39
|
+
if (!normalized) {
|
|
40
|
+
return SchematicColorResolver.#toVariable(fallbackVariable)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
normalized === 'none' ||
|
|
45
|
+
normalized === 'transparent' ||
|
|
46
|
+
normalized.startsWith('var(')
|
|
47
|
+
) {
|
|
48
|
+
return normalized
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const token = COLOR_TOKEN_BY_VALUE.get(normalized)
|
|
52
|
+
|
|
53
|
+
if (token) {
|
|
54
|
+
return SchematicColorResolver.#toVariable(token)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return preserveUnknown
|
|
58
|
+
? normalized
|
|
59
|
+
: SchematicColorResolver.#toVariable(fallbackVariable)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Resolves one SVG fill value to a schematic theme variable.
|
|
64
|
+
* @param {string | undefined} fill
|
|
65
|
+
* @param {string} fallbackVariable
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
static resolveFill(fill, fallbackVariable, preserveUnknown = false) {
|
|
69
|
+
const normalized = SchematicColorResolver.#normalizeColor(fill)
|
|
70
|
+
|
|
71
|
+
if (!normalized) {
|
|
72
|
+
return SchematicColorResolver.#toVariable(fallbackVariable)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
normalized === 'none' ||
|
|
77
|
+
normalized === 'transparent' ||
|
|
78
|
+
normalized.startsWith('var(')
|
|
79
|
+
) {
|
|
80
|
+
return normalized
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const token = COLOR_TOKEN_BY_VALUE.get(normalized)
|
|
84
|
+
|
|
85
|
+
// Border colors such as neutral note gray should stay literal when they
|
|
86
|
+
// appear as area fills so symbol bodies do not collapse to the darker
|
|
87
|
+
// border theme token.
|
|
88
|
+
if (token === '--schematic-note-border-color') {
|
|
89
|
+
return preserveUnknown
|
|
90
|
+
? normalized
|
|
91
|
+
: SchematicColorResolver.#toVariable(fallbackVariable)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (token) {
|
|
95
|
+
return SchematicColorResolver.#toVariable(token)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return preserveUnknown
|
|
99
|
+
? normalized
|
|
100
|
+
: SchematicColorResolver.#toVariable(fallbackVariable)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Normalizes one raw color string for token lookup.
|
|
105
|
+
* @param {string | undefined} color
|
|
106
|
+
* @returns {string}
|
|
107
|
+
*/
|
|
108
|
+
static #normalizeColor(color) {
|
|
109
|
+
return String(color || '')
|
|
110
|
+
.trim()
|
|
111
|
+
.toLowerCase()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Wraps one CSS custom property name in `var(...)` markup.
|
|
116
|
+
* @param {string} variableName
|
|
117
|
+
* @returns {string}
|
|
118
|
+
*/
|
|
119
|
+
static #toVariable(variableName) {
|
|
120
|
+
const normalized = String(variableName || '').trim()
|
|
121
|
+
|
|
122
|
+
if (!normalized) {
|
|
123
|
+
return 'transparent'
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (normalized.startsWith('var(')) {
|
|
127
|
+
return normalized
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return 'var(' + normalized + ')'
|
|
131
|
+
}
|
|
132
|
+
}
|