circuitjson-toolkit 1.0.16 → 1.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.
Files changed (155) hide show
  1. package/AGENTS.md +15 -0
  2. package/NOTICE.md +31 -0
  3. package/README.md +267 -107
  4. package/docs/api.md +501 -96
  5. package/docs/capabilities.md +70 -0
  6. package/docs/migration/behaviors.md +45 -0
  7. package/docs/migration/parser.md +60 -0
  8. package/docs/migration/renderers.md +515 -0
  9. package/docs/migration/root.md +740 -0
  10. package/docs/migration.md +120 -0
  11. package/docs/model-format.md +175 -57
  12. package/docs/provenance.md +206 -0
  13. package/docs/release-notes-v1.1.0.md +154 -0
  14. package/docs/testing.md +117 -7
  15. package/package.json +31 -5
  16. package/spec/api-baseline-v1.0.17.json +1 -0
  17. package/spec/baseline-provenance-v1.0.17.json +7 -0
  18. package/spec/circuitjson-schema-snapshot.json +321 -0
  19. package/spec/circuitjson-schema-source.json +28 -0
  20. package/spec/feature-preservation.json +1 -0
  21. package/spec/library-scope.md +27 -20
  22. package/src/capabilities.mjs +1 -0
  23. package/src/core/ArchiveEntryPath.mjs +93 -0
  24. package/src/core/ArchiveLimits.mjs +31 -0
  25. package/src/core/ArchiveLimitsValidator.mjs +107 -0
  26. package/src/core/AsyncInputOwnership.mjs +56 -0
  27. package/src/core/AttachedValueLimits.mjs +67 -0
  28. package/src/core/CircuitJsonDiagnosticIndexer.mjs +184 -0
  29. package/src/core/CircuitJsonDocument.mjs +19 -61
  30. package/src/core/CircuitJsonElementTypes.mjs +10 -0
  31. package/src/core/CircuitJsonElementValidator.mjs +98 -847
  32. package/src/core/CircuitJsonIndexer.mjs +274 -194
  33. package/src/core/CircuitJsonManufacturingBuilder.mjs +167 -164
  34. package/src/core/CircuitJsonParser.mjs +75 -13
  35. package/src/core/CircuitJsonPcbClearanceDiagnostics.mjs +12 -6
  36. package/src/core/CircuitJsonPcbHolePrimitiveModel.mjs +108 -10
  37. package/src/core/CircuitJsonPcbPadPrimitiveModel.mjs +1 -1
  38. package/src/core/CircuitJsonPcbPrimitiveArtwork.mjs +44 -38
  39. package/src/core/CircuitJsonPcbPrimitiveBuilder.mjs +146 -28
  40. package/src/core/CircuitJsonPcbPrimitiveFields.mjs +70 -4
  41. package/src/core/CircuitJsonPcbPrimitiveIndex.mjs +18 -2
  42. package/src/core/CircuitJsonPcbPrimitiveOverlays.mjs +26 -9
  43. package/src/core/CircuitJsonPcbZonePrimitiveBuilder.mjs +7 -6
  44. package/src/core/CircuitJsonSerializedInputAudit.mjs +87 -0
  45. package/src/core/CircuitJsonSourceMetadata.mjs +5 -1
  46. package/src/core/CircuitJsonSupportMatrixBuilder.mjs +3 -1
  47. package/src/core/CircuitJsonToolkitElementSchema.mjs +218 -0
  48. package/src/core/CircuitJsonUnitParsers.mjs +101 -0
  49. package/src/core/CircuitJsonUnits.mjs +13 -87
  50. package/src/core/CircuitJsonUpstreamSchema.mjs +9 -0
  51. package/src/core/CircuitJsonUpstreamValidator.mjs +418 -0
  52. package/src/core/CircuitJsonValidationUnits.mjs +6 -0
  53. package/src/core/ManufacturingService.mjs +323 -0
  54. package/src/core/Parser.mjs +343 -0
  55. package/src/core/ParserOptions.mjs +333 -0
  56. package/src/core/PcbBoundsSelectionModel.mjs +55 -19
  57. package/src/core/PcbDiagnosticFocusModel.mjs +42 -11
  58. package/src/core/PcbInteractionIndex.mjs +368 -0
  59. package/src/core/PcbInteractionPrimitiveModel.mjs +393 -62
  60. package/src/core/ProjectAsyncInputOwner.mjs +70 -0
  61. package/src/core/ProjectLoader.mjs +975 -0
  62. package/src/core/SimulationService.mjs +790 -0
  63. package/src/core/ToolkitCapabilities.mjs +130 -0
  64. package/src/core/ZipArchiveInspector.mjs +649 -0
  65. package/src/core/context/BinaryDataSnapshot.mjs +217 -0
  66. package/src/core/context/CircuitJsonContextIndexes.mjs +96 -0
  67. package/src/core/context/CircuitJsonDerivedCache.mjs +114 -0
  68. package/src/core/context/CircuitJsonDocumentContext.mjs +353 -0
  69. package/src/core/context/CircuitJsonLegacyModel.mjs +147 -0
  70. package/src/core/context/CircuitJsonLegacyNormalizer.mjs +847 -0
  71. package/src/core/context/CircuitJsonMetadataBoundary.mjs +76 -0
  72. package/src/core/context/CircuitJsonModelFreezeTraversal.mjs +179 -0
  73. package/src/core/context/CircuitJsonReadOnlyDocument.mjs +920 -0
  74. package/src/core/context/CircuitJsonSchematicTableNormalizer.mjs +314 -0
  75. package/src/core/context/CircuitJsonValidationAuthority.mjs +39 -0
  76. package/src/core/context/CircuitJsonValidationProof.mjs +217 -0
  77. package/src/core/context/PcbPrimitivePreparation.mjs +198 -0
  78. package/src/core/context/PcbSpatialIndex.mjs +701 -0
  79. package/src/core/context/ProtectedExtensionBinaryBoundary.mjs +128 -0
  80. package/src/core/context/StructuredDataSnapshot.mjs +683 -0
  81. package/src/core/contracts/DocumentResult.mjs +198 -0
  82. package/src/core/contracts/ProjectResult.mjs +96 -0
  83. package/src/core/contracts/RuntimeProxyBoundary.mjs +48 -0
  84. package/src/core/contracts/ToolkitAsset.mjs +493 -0
  85. package/src/core/contracts/ToolkitDiagnostic.mjs +38 -0
  86. package/src/core/contracts/ToolkitError.mjs +176 -0
  87. package/src/core/contracts/ToolkitProgress.mjs +89 -0
  88. package/src/core/interaction/CanonicalInteractionOptions.mjs +246 -0
  89. package/src/core/interaction/PcbInteractionBounds.mjs +167 -0
  90. package/src/core/query/CircuitTraversal.mjs +343 -0
  91. package/src/core/query/ComponentGrouping.mjs +275 -0
  92. package/src/core/query/QueryNetlistBuilder.mjs +306 -0
  93. package/src/core/query/QueryService.mjs +435 -0
  94. package/src/core/query/RegexPattern.mjs +75 -0
  95. package/src/core/rendering/CanonicalBomOrder.mjs +81 -0
  96. package/src/core/rendering/CanonicalBomRows.mjs +92 -0
  97. package/src/core/rendering/CanonicalRenderOptions.mjs +498 -0
  98. package/src/core/rendering/CanonicalSvgDocument.mjs +102 -0
  99. package/src/core/rendering/PcbRenderPlan.mjs +429 -0
  100. package/src/core/rendering/SchematicSheetSelector.mjs +335 -0
  101. package/src/core/scene3d/PcbScene3dBuilder.mjs +906 -0
  102. package/src/core/scene3d/PcbScene3dPreparator.mjs +47 -0
  103. package/src/core/scene3d/Scene3dAssetIndex.mjs +284 -0
  104. package/src/core/scene3d/Scene3dBoardModel.mjs +596 -0
  105. package/src/core/scene3d/Scene3dDocumentMetadata.mjs +167 -0
  106. package/src/core/scene3d/Scene3dFreeze.mjs +37 -0
  107. package/src/core/scene3d/Scene3dIdRegistry.mjs +34 -0
  108. package/src/core/scene3d/Scene3dInputPreflight.mjs +193 -0
  109. package/src/core/scene3d/Scene3dMaterials.mjs +58 -0
  110. package/src/core/scene3d/Scene3dModelReference.mjs +134 -0
  111. package/src/core/scene3d/Scene3dOptions.mjs +363 -0
  112. package/src/core/scene3d/SceneAssetResolver.mjs +441 -0
  113. package/src/core/simulation/SimulationParameterCloner.mjs +543 -0
  114. package/src/core/worker/ParserWorkerClient.mjs +997 -0
  115. package/src/core/worker/ToolkitWorkerProtocol.mjs +412 -0
  116. package/src/core/worker/WorkerRequestData.mjs +623 -0
  117. package/src/core/worker/WorkerResponseData.mjs +905 -0
  118. package/src/extensions.mjs +37 -0
  119. package/src/index.mjs +14 -9
  120. package/src/interaction.mjs +2 -0
  121. package/src/manufacturing.mjs +1 -0
  122. package/src/parser.mjs +12 -2
  123. package/src/project.mjs +5 -0
  124. package/src/query.mjs +1 -0
  125. package/src/renderers.mjs +3 -29
  126. package/src/scene3d.mjs +3 -0
  127. package/src/simulation.mjs +1 -0
  128. package/src/styles/renderers.css +24 -0
  129. package/src/testing/ToolkitContractFixtures.mjs +124 -0
  130. package/src/testing/ToolkitLoopbackWorker.mjs +174 -0
  131. package/src/testing/runToolkitContract.mjs +705 -0
  132. package/src/testing.mjs +3 -0
  133. package/src/ui/BomTableRenderer.mjs +304 -0
  134. package/src/ui/CircuitJsonPcbBoardSvgRenderer.mjs +80 -0
  135. package/src/ui/CircuitJsonPcbPrimitiveAttributeRenderer.mjs +3 -5
  136. package/src/ui/CircuitJsonPcbSvgRenderer.mjs +63 -43
  137. package/src/ui/CircuitJsonPcbViaSvgRenderer.mjs +3 -5
  138. package/src/ui/CircuitJsonSchematicDebugRenderer.mjs +164 -0
  139. package/src/ui/CircuitJsonSchematicImageSvgRenderer.mjs +210 -0
  140. package/src/ui/CircuitJsonSchematicLineRenderer.mjs +86 -0
  141. package/src/ui/CircuitJsonSchematicSheetSymbolSvgRenderer.mjs +98 -0
  142. package/src/ui/CircuitJsonSchematicSvgArcPath.mjs +117 -17
  143. package/src/ui/CircuitJsonSchematicSvgPortMetadata.mjs +67 -20
  144. package/src/ui/CircuitJsonSchematicSvgPrimitiveAttributes.mjs +45 -9
  145. package/src/ui/CircuitJsonSchematicSvgRenderer.mjs +151 -148
  146. package/src/ui/CircuitJsonSchematicTableSvgRenderer.mjs +4 -292
  147. package/src/ui/PcbSvgRenderer.mjs +41 -0
  148. package/src/ui/SafeSvgPaint.mjs +26 -0
  149. package/src/ui/SafeXmlText.mjs +60 -0
  150. package/src/ui/SchematicGeometryBounds.mjs +540 -0
  151. package/src/ui/SchematicSvgRenderer.mjs +110 -0
  152. package/src/ui/SchematicTableGeometry.mjs +319 -0
  153. package/src/ui/SchematicTextAnchor.mjs +55 -0
  154. package/src/ui/SchematicTextBounds.mjs +98 -0
  155. package/src/workers/parser.worker.mjs +59 -0
@@ -1,31 +1,6 @@
1
+ import * as UnitParsers from './CircuitJsonUnitParsers.mjs'
2
+
1
3
  const MILS_PER_MM = 39.37007874015748
2
- const LENGTH_FACTORS_TO_MM = new Map([
3
- ['mm', 1],
4
- ['millimeter', 1],
5
- ['millimeters', 1],
6
- ['cm', 10],
7
- ['centimeter', 10],
8
- ['centimeters', 10],
9
- ['m', 1000],
10
- ['meter', 1000],
11
- ['meters', 1000],
12
- ['in', 25.4],
13
- ['inch', 25.4],
14
- ['inches', 25.4],
15
- ['mil', 0.0254],
16
- ['mils', 0.0254],
17
- ['um', 0.001],
18
- ['micrometer', 0.001],
19
- ['micrometers', 0.001]
20
- ])
21
- const ANGLE_FACTORS_TO_DEG = new Map([
22
- ['deg', 1],
23
- ['degree', 1],
24
- ['degrees', 1],
25
- ['rad', 180 / Math.PI],
26
- ['radian', 180 / Math.PI],
27
- ['radians', 180 / Math.PI]
28
- ])
29
4
 
30
5
  /**
31
6
  * Unit helpers for CircuitJSON's millimeter-based PCB dimensions.
@@ -38,10 +13,7 @@ export class CircuitJsonUnits {
38
13
  * @returns {number}
39
14
  */
40
15
  static length(value, fallback = 0) {
41
- return (
42
- CircuitJsonUnits.optionalLength(value) ??
43
- CircuitJsonUnits.#round(fallback)
44
- )
16
+ return UnitParsers.optionalLength(value) ?? UnitParsers.round(fallback)
45
17
  }
46
18
 
47
19
  /**
@@ -50,7 +22,7 @@ export class CircuitJsonUnits {
50
22
  * @returns {number | null}
51
23
  */
52
24
  static optionalLength(value) {
53
- return CircuitJsonUnits.#parseUnitValue(value, LENGTH_FACTORS_TO_MM)
25
+ return UnitParsers.optionalLength(value)
54
26
  }
55
27
 
56
28
  /**
@@ -60,10 +32,7 @@ export class CircuitJsonUnits {
60
32
  * @returns {number}
61
33
  */
62
34
  static angle(value, fallback = 0) {
63
- return (
64
- CircuitJsonUnits.optionalAngle(value) ??
65
- CircuitJsonUnits.#round(fallback)
66
- )
35
+ return UnitParsers.optionalAngle(value) ?? UnitParsers.round(fallback)
67
36
  }
68
37
 
69
38
  /**
@@ -72,7 +41,7 @@ export class CircuitJsonUnits {
72
41
  * @returns {number | null}
73
42
  */
74
43
  static optionalAngle(value) {
75
- return CircuitJsonUnits.#parseUnitValue(value, ANGLE_FACTORS_TO_DEG)
44
+ return UnitParsers.optionalAngle(value)
76
45
  }
77
46
 
78
47
  /**
@@ -82,8 +51,8 @@ export class CircuitJsonUnits {
82
51
  */
83
52
  static point(point) {
84
53
  return {
85
- x: CircuitJsonUnits.length(point?.x, 0),
86
- y: CircuitJsonUnits.length(point?.y, 0)
54
+ x: UnitParsers.optionalLength(point?.x) ?? 0,
55
+ y: UnitParsers.optionalLength(point?.y) ?? 0
87
56
  }
88
57
  }
89
58
 
@@ -93,9 +62,7 @@ export class CircuitJsonUnits {
93
62
  * @returns {{ x: number, y: number } | null}
94
63
  */
95
64
  static optionalPoint(point) {
96
- const x = CircuitJsonUnits.optionalLength(point?.x)
97
- const y = CircuitJsonUnits.optionalLength(point?.y)
98
- return x === null || y === null ? null : { x, y }
65
+ return UnitParsers.optionalPoint(point)
99
66
  }
100
67
 
101
68
  /**
@@ -104,9 +71,7 @@ export class CircuitJsonUnits {
104
71
  * @returns {{ width: number, height: number } | null}
105
72
  */
106
73
  static optionalSize(size) {
107
- const width = CircuitJsonUnits.optionalLength(size?.width)
108
- const height = CircuitJsonUnits.optionalLength(size?.height)
109
- return width === null || height === null ? null : { width, height }
74
+ return UnitParsers.optionalSize(size)
110
75
  }
111
76
 
112
77
  /**
@@ -116,8 +81,9 @@ export class CircuitJsonUnits {
116
81
  * @returns {number}
117
82
  */
118
83
  static mmToMil(value, fallback = 0) {
119
- return CircuitJsonUnits.#round(
120
- CircuitJsonUnits.length(value, fallback) * MILS_PER_MM
84
+ return UnitParsers.round(
85
+ (UnitParsers.optionalLength(value) ?? UnitParsers.round(fallback)) *
86
+ MILS_PER_MM
121
87
  )
122
88
  }
123
89
 
@@ -132,44 +98,4 @@ export class CircuitJsonUnits {
132
98
  y: CircuitJsonUnits.mmToMil(point?.y, 0)
133
99
  }
134
100
  }
135
-
136
- /**
137
- * Parses one numeric value with an optional unit suffix.
138
- * @param {unknown} value Value candidate.
139
- * @param {Map<string, number>} unitFactors Unit factor lookup.
140
- * @returns {number | null}
141
- */
142
- static #parseUnitValue(value, unitFactors) {
143
- if (typeof value === 'number') {
144
- return Number.isFinite(value)
145
- ? CircuitJsonUnits.#round(value)
146
- : null
147
- }
148
-
149
- const text = String(value ?? '').trim()
150
- if (!text) return null
151
-
152
- const match = text.match(
153
- /^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)\s*([a-z]+)?$/iu
154
- )
155
- if (!match) return null
156
-
157
- const number = Number(match[1])
158
- if (!Number.isFinite(number)) return null
159
-
160
- const unit = String(match[2] || '').toLowerCase()
161
- const factor = unit ? unitFactors.get(unit) : 1
162
- if (!Number.isFinite(factor)) return null
163
-
164
- return CircuitJsonUnits.#round(number * factor)
165
- }
166
-
167
- /**
168
- * Rounds render-unit conversions to stable precision.
169
- * @param {number} value Numeric value.
170
- * @returns {number}
171
- */
172
- static #round(value) {
173
- return Math.round(value * 1_000_000) / 1_000_000
174
- }
175
101
  }