brep-io-kernel 1.0.0-ci.10

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 (271) hide show
  1. package/LICENSE.md +32 -0
  2. package/README.md +157 -0
  3. package/dist-kernel/brep-kernel.js +74699 -0
  4. package/package.json +58 -0
  5. package/src/BREP/AssemblyComponent.js +42 -0
  6. package/src/BREP/BREP.js +43 -0
  7. package/src/BREP/BetterSolid.js +805 -0
  8. package/src/BREP/Edge.js +103 -0
  9. package/src/BREP/Extrude.js +403 -0
  10. package/src/BREP/Face.js +187 -0
  11. package/src/BREP/MeshRepairer.js +634 -0
  12. package/src/BREP/OffsetShellSolid.js +614 -0
  13. package/src/BREP/PointCloudWrap.js +302 -0
  14. package/src/BREP/Revolve.js +345 -0
  15. package/src/BREP/SolidMethods/authoring.js +112 -0
  16. package/src/BREP/SolidMethods/booleanOps.js +230 -0
  17. package/src/BREP/SolidMethods/chamfer.js +122 -0
  18. package/src/BREP/SolidMethods/edgeResolution.js +25 -0
  19. package/src/BREP/SolidMethods/fillet.js +792 -0
  20. package/src/BREP/SolidMethods/index.js +72 -0
  21. package/src/BREP/SolidMethods/io.js +105 -0
  22. package/src/BREP/SolidMethods/lifecycle.js +103 -0
  23. package/src/BREP/SolidMethods/manifoldOps.js +375 -0
  24. package/src/BREP/SolidMethods/meshCleanup.js +2512 -0
  25. package/src/BREP/SolidMethods/meshQueries.js +264 -0
  26. package/src/BREP/SolidMethods/metadata.js +106 -0
  27. package/src/BREP/SolidMethods/metrics.js +51 -0
  28. package/src/BREP/SolidMethods/transforms.js +361 -0
  29. package/src/BREP/SolidMethods/visualize.js +508 -0
  30. package/src/BREP/SolidShared.js +26 -0
  31. package/src/BREP/Sweep.js +1596 -0
  32. package/src/BREP/Tube.js +857 -0
  33. package/src/BREP/Vertex.js +43 -0
  34. package/src/BREP/applyBooleanOperation.js +704 -0
  35. package/src/BREP/boundsUtils.js +48 -0
  36. package/src/BREP/chamfer.js +551 -0
  37. package/src/BREP/edgePolylineUtils.js +85 -0
  38. package/src/BREP/fillets/common.js +388 -0
  39. package/src/BREP/fillets/fillet.js +1422 -0
  40. package/src/BREP/fillets/filletGeometry.js +15 -0
  41. package/src/BREP/fillets/inset.js +389 -0
  42. package/src/BREP/fillets/offsetHelper.js +143 -0
  43. package/src/BREP/fillets/outset.js +88 -0
  44. package/src/BREP/helix.js +193 -0
  45. package/src/BREP/meshToBrep.js +234 -0
  46. package/src/BREP/primitives.js +279 -0
  47. package/src/BREP/setupManifold.js +71 -0
  48. package/src/BREP/threadGeometry.js +1120 -0
  49. package/src/BREP/triangleUtils.js +8 -0
  50. package/src/BREP/triangulate.js +608 -0
  51. package/src/FeatureRegistry.js +183 -0
  52. package/src/PartHistory.js +1132 -0
  53. package/src/UI/AccordionWidget.js +292 -0
  54. package/src/UI/CADmaterials.js +850 -0
  55. package/src/UI/EnvMonacoEditor.js +522 -0
  56. package/src/UI/FloatingWindow.js +396 -0
  57. package/src/UI/HistoryWidget.js +457 -0
  58. package/src/UI/MainToolbar.js +131 -0
  59. package/src/UI/ModelLibraryView.js +194 -0
  60. package/src/UI/OrthoCameraIdle.js +206 -0
  61. package/src/UI/PluginsWidget.js +280 -0
  62. package/src/UI/SceneListing.js +606 -0
  63. package/src/UI/SelectionFilter.js +629 -0
  64. package/src/UI/ViewCube.js +389 -0
  65. package/src/UI/assembly/AssemblyConstraintCollectionWidget.js +329 -0
  66. package/src/UI/assembly/AssemblyConstraintControlsWidget.js +282 -0
  67. package/src/UI/assembly/AssemblyConstraintsWidget.css +292 -0
  68. package/src/UI/assembly/AssemblyConstraintsWidget.js +1373 -0
  69. package/src/UI/assembly/constraintFaceUtils.js +115 -0
  70. package/src/UI/assembly/constraintHighlightUtils.js +70 -0
  71. package/src/UI/assembly/constraintLabelUtils.js +31 -0
  72. package/src/UI/assembly/constraintPointUtils.js +64 -0
  73. package/src/UI/assembly/constraintSelectionUtils.js +185 -0
  74. package/src/UI/assembly/constraintStatusUtils.js +142 -0
  75. package/src/UI/componentSelectorModal.js +240 -0
  76. package/src/UI/controls/CombinedTransformControls.js +386 -0
  77. package/src/UI/dialogs.js +351 -0
  78. package/src/UI/expressionsManager.js +100 -0
  79. package/src/UI/featureDialogWidgets/booleanField.js +25 -0
  80. package/src/UI/featureDialogWidgets/booleanOperationField.js +97 -0
  81. package/src/UI/featureDialogWidgets/buttonField.js +45 -0
  82. package/src/UI/featureDialogWidgets/componentSelectorField.js +102 -0
  83. package/src/UI/featureDialogWidgets/defaultField.js +23 -0
  84. package/src/UI/featureDialogWidgets/fileField.js +66 -0
  85. package/src/UI/featureDialogWidgets/index.js +34 -0
  86. package/src/UI/featureDialogWidgets/numberField.js +165 -0
  87. package/src/UI/featureDialogWidgets/optionsField.js +33 -0
  88. package/src/UI/featureDialogWidgets/referenceSelectionField.js +208 -0
  89. package/src/UI/featureDialogWidgets/stringField.js +24 -0
  90. package/src/UI/featureDialogWidgets/textareaField.js +28 -0
  91. package/src/UI/featureDialogWidgets/threadDesignationField.js +160 -0
  92. package/src/UI/featureDialogWidgets/transformField.js +252 -0
  93. package/src/UI/featureDialogWidgets/utils.js +43 -0
  94. package/src/UI/featureDialogWidgets/vec3Field.js +133 -0
  95. package/src/UI/featureDialogs.js +1414 -0
  96. package/src/UI/fileManagerWidget.js +615 -0
  97. package/src/UI/history/HistoryCollectionWidget.js +1294 -0
  98. package/src/UI/history/historyCollectionWidget.css.js +257 -0
  99. package/src/UI/history/historyDisplayInfo.js +133 -0
  100. package/src/UI/mobile.js +28 -0
  101. package/src/UI/objectDump.js +442 -0
  102. package/src/UI/pmi/AnnotationCollectionWidget.js +120 -0
  103. package/src/UI/pmi/AnnotationHistory.js +353 -0
  104. package/src/UI/pmi/AnnotationRegistry.js +90 -0
  105. package/src/UI/pmi/BaseAnnotation.js +269 -0
  106. package/src/UI/pmi/LabelOverlay.css +102 -0
  107. package/src/UI/pmi/LabelOverlay.js +191 -0
  108. package/src/UI/pmi/PMIMode.js +1550 -0
  109. package/src/UI/pmi/PMIViewsWidget.js +1098 -0
  110. package/src/UI/pmi/annUtils.js +729 -0
  111. package/src/UI/pmi/dimensions/AngleDimensionAnnotation.js +647 -0
  112. package/src/UI/pmi/dimensions/ExplodeBodyAnnotation.js +507 -0
  113. package/src/UI/pmi/dimensions/HoleCalloutAnnotation.js +462 -0
  114. package/src/UI/pmi/dimensions/LeaderAnnotation.js +403 -0
  115. package/src/UI/pmi/dimensions/LinearDimensionAnnotation.js +532 -0
  116. package/src/UI/pmi/dimensions/NoteAnnotation.js +110 -0
  117. package/src/UI/pmi/dimensions/RadialDimensionAnnotation.js +659 -0
  118. package/src/UI/pmi/pmiStyle.js +44 -0
  119. package/src/UI/sketcher/SketchMode3D.js +4095 -0
  120. package/src/UI/sketcher/dimensions.js +674 -0
  121. package/src/UI/sketcher/glyphs.js +236 -0
  122. package/src/UI/sketcher/highlights.js +60 -0
  123. package/src/UI/toolbarButtons/aboutButton.js +5 -0
  124. package/src/UI/toolbarButtons/exportButton.js +609 -0
  125. package/src/UI/toolbarButtons/flatPatternButton.js +307 -0
  126. package/src/UI/toolbarButtons/importButton.js +160 -0
  127. package/src/UI/toolbarButtons/inspectorToggleButton.js +12 -0
  128. package/src/UI/toolbarButtons/metadataButton.js +1063 -0
  129. package/src/UI/toolbarButtons/orientToFaceButton.js +114 -0
  130. package/src/UI/toolbarButtons/registerDefaultButtons.js +46 -0
  131. package/src/UI/toolbarButtons/saveButton.js +99 -0
  132. package/src/UI/toolbarButtons/scriptRunnerButton.js +302 -0
  133. package/src/UI/toolbarButtons/testsButton.js +26 -0
  134. package/src/UI/toolbarButtons/undoRedoButtons.js +25 -0
  135. package/src/UI/toolbarButtons/wireframeToggleButton.js +5 -0
  136. package/src/UI/toolbarButtons/zoomToFitButton.js +5 -0
  137. package/src/UI/triangleDebuggerWindow.js +945 -0
  138. package/src/UI/viewer.js +4228 -0
  139. package/src/assemblyConstraints/AssemblyConstraintHistory.js +1576 -0
  140. package/src/assemblyConstraints/AssemblyConstraintRegistry.js +120 -0
  141. package/src/assemblyConstraints/BaseAssemblyConstraint.js +66 -0
  142. package/src/assemblyConstraints/constraintExpressionUtils.js +35 -0
  143. package/src/assemblyConstraints/constraintUtils/parallelAlignment.js +676 -0
  144. package/src/assemblyConstraints/constraints/AngleConstraint.js +485 -0
  145. package/src/assemblyConstraints/constraints/CoincidentConstraint.js +194 -0
  146. package/src/assemblyConstraints/constraints/DistanceConstraint.js +616 -0
  147. package/src/assemblyConstraints/constraints/FixedConstraint.js +78 -0
  148. package/src/assemblyConstraints/constraints/ParallelConstraint.js +252 -0
  149. package/src/assemblyConstraints/constraints/TouchAlignConstraint.js +961 -0
  150. package/src/core/entities/HistoryCollectionBase.js +72 -0
  151. package/src/core/entities/ListEntityBase.js +109 -0
  152. package/src/core/entities/schemaProcesser.js +121 -0
  153. package/src/exporters/sheetMetalFlatPattern.js +659 -0
  154. package/src/exporters/sheetMetalUnfold.js +862 -0
  155. package/src/exporters/step.js +1135 -0
  156. package/src/exporters/threeMF.js +575 -0
  157. package/src/features/assemblyComponent/AssemblyComponentFeature.js +780 -0
  158. package/src/features/boolean/BooleanFeature.js +94 -0
  159. package/src/features/chamfer/ChamferFeature.js +116 -0
  160. package/src/features/datium/DatiumFeature.js +80 -0
  161. package/src/features/edgeFeatureUtils.js +41 -0
  162. package/src/features/extrude/ExtrudeFeature.js +143 -0
  163. package/src/features/fillet/FilletFeature.js +197 -0
  164. package/src/features/helix/HelixFeature.js +405 -0
  165. package/src/features/hole/HoleFeature.js +1050 -0
  166. package/src/features/hole/screwClearance.js +86 -0
  167. package/src/features/hole/threadDesignationCatalog.js +149 -0
  168. package/src/features/imageHeightSolid/ImageHeightmapSolidFeature.js +463 -0
  169. package/src/features/imageToFace/ImageToFaceFeature.js +727 -0
  170. package/src/features/imageToFace/imageEditor.js +1270 -0
  171. package/src/features/imageToFace/traceUtils.js +971 -0
  172. package/src/features/import3dModel/Import3dModelFeature.js +151 -0
  173. package/src/features/loft/LoftFeature.js +605 -0
  174. package/src/features/mirror/MirrorFeature.js +151 -0
  175. package/src/features/offsetFace/OffsetFaceFeature.js +370 -0
  176. package/src/features/offsetShell/OffsetShellFeature.js +89 -0
  177. package/src/features/overlapCleanup/OverlapCleanupFeature.js +85 -0
  178. package/src/features/pattern/PatternFeature.js +275 -0
  179. package/src/features/patternLinear/PatternLinearFeature.js +120 -0
  180. package/src/features/patternRadial/PatternRadialFeature.js +186 -0
  181. package/src/features/plane/PlaneFeature.js +154 -0
  182. package/src/features/primitiveCone/primitiveConeFeature.js +99 -0
  183. package/src/features/primitiveCube/primitiveCubeFeature.js +70 -0
  184. package/src/features/primitiveCylinder/primitiveCylinderFeature.js +91 -0
  185. package/src/features/primitivePyramid/primitivePyramidFeature.js +72 -0
  186. package/src/features/primitiveSphere/primitiveSphereFeature.js +62 -0
  187. package/src/features/primitiveTorus/primitiveTorusFeature.js +109 -0
  188. package/src/features/remesh/RemeshFeature.js +97 -0
  189. package/src/features/revolve/RevolveFeature.js +111 -0
  190. package/src/features/selectionUtils.js +118 -0
  191. package/src/features/sheetMetal/SheetMetalContourFlangeFeature.js +1656 -0
  192. package/src/features/sheetMetal/SheetMetalCutoutFeature.js +1056 -0
  193. package/src/features/sheetMetal/SheetMetalFlangeFeature.js +1568 -0
  194. package/src/features/sheetMetal/SheetMetalHemFeature.js +43 -0
  195. package/src/features/sheetMetal/SheetMetalObject.js +141 -0
  196. package/src/features/sheetMetal/SheetMetalTabFeature.js +176 -0
  197. package/src/features/sheetMetal/UNFOLD_NEUTRAL_REQUIREMENTS.md +153 -0
  198. package/src/features/sheetMetal/contour-flange-rebuild-spec.md +261 -0
  199. package/src/features/sheetMetal/profileUtils.js +25 -0
  200. package/src/features/sheetMetal/sheetMetalCleanup.js +9 -0
  201. package/src/features/sheetMetal/sheetMetalFaceTypes.js +146 -0
  202. package/src/features/sheetMetal/sheetMetalMetadata.js +165 -0
  203. package/src/features/sheetMetal/sheetMetalPipeline.js +169 -0
  204. package/src/features/sheetMetal/sheetMetalProfileUtils.js +216 -0
  205. package/src/features/sheetMetal/sheetMetalTabUtils.js +29 -0
  206. package/src/features/sheetMetal/sheetMetalTree.js +210 -0
  207. package/src/features/sketch/SketchFeature.js +955 -0
  208. package/src/features/sketch/sketchSolver2D/ConstraintEngine.js +800 -0
  209. package/src/features/sketch/sketchSolver2D/constraintDefinitions.js +704 -0
  210. package/src/features/sketch/sketchSolver2D/mathHelpersMod.js +307 -0
  211. package/src/features/spline/SplineEditorSession.js +988 -0
  212. package/src/features/spline/SplineFeature.js +1388 -0
  213. package/src/features/spline/splineUtils.js +218 -0
  214. package/src/features/sweep/SweepFeature.js +110 -0
  215. package/src/features/transform/TransformFeature.js +152 -0
  216. package/src/features/tube/TubeFeature.js +635 -0
  217. package/src/fs.proxy.js +625 -0
  218. package/src/idbStorage.js +254 -0
  219. package/src/index.js +12 -0
  220. package/src/main.js +15 -0
  221. package/src/metadataManager.js +64 -0
  222. package/src/path.proxy.js +277 -0
  223. package/src/plugins/ghLoader.worker.js +151 -0
  224. package/src/plugins/pluginManager.js +286 -0
  225. package/src/pmi/PMIViewsManager.js +134 -0
  226. package/src/services/componentLibrary.js +198 -0
  227. package/src/tests/ConsoleCapture.js +189 -0
  228. package/src/tests/S7-diagnostics-2025-12-23T18-37-23-570Z.json +630 -0
  229. package/src/tests/browserTests.js +597 -0
  230. package/src/tests/debugBoolean.js +225 -0
  231. package/src/tests/partFiles/badBoolean.json +957 -0
  232. package/src/tests/partFiles/extrudeTest.json +88 -0
  233. package/src/tests/partFiles/filletFail.json +58 -0
  234. package/src/tests/partFiles/import_TEst.part.part.json +646 -0
  235. package/src/tests/partFiles/sheetMetalHem.BREP.json +734 -0
  236. package/src/tests/test_boolean_subtract.js +27 -0
  237. package/src/tests/test_chamfer.js +17 -0
  238. package/src/tests/test_extrudeFace.js +24 -0
  239. package/src/tests/test_fillet.js +17 -0
  240. package/src/tests/test_fillet_nonClosed.js +45 -0
  241. package/src/tests/test_filletsMoreDifficult.js +46 -0
  242. package/src/tests/test_history_features_basic.js +149 -0
  243. package/src/tests/test_hole.js +282 -0
  244. package/src/tests/test_mirror.js +16 -0
  245. package/src/tests/test_offsetShellGrouping.js +85 -0
  246. package/src/tests/test_plane.js +4 -0
  247. package/src/tests/test_primitiveCone.js +11 -0
  248. package/src/tests/test_primitiveCube.js +7 -0
  249. package/src/tests/test_primitiveCylinder.js +8 -0
  250. package/src/tests/test_primitivePyramid.js +9 -0
  251. package/src/tests/test_primitiveSphere.js +17 -0
  252. package/src/tests/test_primitiveTorus.js +21 -0
  253. package/src/tests/test_pushFace.js +126 -0
  254. package/src/tests/test_sheetMetalContourFlange.js +125 -0
  255. package/src/tests/test_sheetMetal_features.js +80 -0
  256. package/src/tests/test_sketch_openLoop.js +45 -0
  257. package/src/tests/test_solidMetrics.js +58 -0
  258. package/src/tests/test_stlLoader.js +1889 -0
  259. package/src/tests/test_sweepFace.js +55 -0
  260. package/src/tests/test_tube.js +45 -0
  261. package/src/tests/test_tube_closedLoop.js +67 -0
  262. package/src/tests/tests.js +493 -0
  263. package/src/tools/assemblyConstraintDialogCapturePage.js +56 -0
  264. package/src/tools/dialogCapturePageFactory.js +227 -0
  265. package/src/tools/featureDialogCapturePage.js +47 -0
  266. package/src/tools/pmiAnnotationDialogCapturePage.js +60 -0
  267. package/src/utils/axisHelpers.js +99 -0
  268. package/src/utils/deepClone.js +69 -0
  269. package/src/utils/geometryTolerance.js +37 -0
  270. package/src/utils/normalizeTypeString.js +8 -0
  271. package/src/utils/xformMath.js +51 -0
@@ -0,0 +1,329 @@
1
+ import { HistoryCollectionWidget } from '../history/HistoryCollectionWidget.js';
2
+ import { resolveEntryId } from '../history/historyDisplayInfo.js';
3
+ import { SelectionFilter } from '../SelectionFilter.js';
4
+ import { constraintLabelText } from './constraintLabelUtils.js';
5
+
6
+ const COLLECTION_EXTRA_CSS = `
7
+ .constraint-enable-toggle {
8
+ display: inline-flex;
9
+ align-items: center;
10
+ padding-left: 8px;
11
+ padding-right: 4px;
12
+ }
13
+ .constraint-enable-toggle .hc-entry-toggle-checkbox {
14
+ width: 16px;
15
+ height: 16px;
16
+ cursor: pointer;
17
+ accent-color: var(--accent);
18
+ }
19
+ .hc-item.constraint-disabled .hc-title {
20
+ opacity: 0.7;
21
+ }
22
+ .hc-item.constraint-disabled .hc-meta {
23
+ opacity: 0.7;
24
+ }
25
+ .hc-item.has-error .hc-meta {
26
+ color: var(--danger);
27
+ font-weight: 600;
28
+ }
29
+ .constraint-dialog-actions {
30
+ display: flex;
31
+ flex-wrap: wrap;
32
+ gap: 8px;
33
+ margin-top: 12px;
34
+ }
35
+ .constraint-dialog-actions .btn {
36
+ appearance: none;
37
+ border: 1px solid var(--border);
38
+ background: rgba(255,255,255,.03);
39
+ color: var(--text);
40
+ border-radius: 8px;
41
+ padding: 6px 12px;
42
+ font-size: 12px;
43
+ cursor: pointer;
44
+ transition: border-color .15s ease, background-color .15s ease, transform .05s ease;
45
+ }
46
+ .constraint-dialog-actions .btn:hover {
47
+ border-color: var(--focus);
48
+ }
49
+ .constraint-dialog-actions .btn:active {
50
+ transform: translateY(1px);
51
+ }
52
+ .constraint-dialog-actions .highlight-btn {
53
+ border-color: var(--accent);
54
+ color: var(--accent);
55
+ }
56
+ .constraint-dialog-actions .highlight-btn:hover {
57
+ background: rgba(110,168,254,.15);
58
+ }
59
+ `;
60
+
61
+ export class AssemblyConstraintCollectionWidget extends HistoryCollectionWidget {
62
+ constructor({
63
+ history = null,
64
+ viewer = null,
65
+ partHistory = null,
66
+ onEntryChange = null,
67
+ onCollectionChange = null,
68
+ onEntryToggle = null,
69
+ onHighlightRequest = null,
70
+ onClearHighlight = null,
71
+ onBeforeConstraintChange = null,
72
+ } = {}) {
73
+ const historyRef = history;
74
+ const viewerRef = viewer;
75
+ const beforeChangeHook = typeof onBeforeConstraintChange === 'function' ? onBeforeConstraintChange : null;
76
+ const callBeforeChange = (payload = {}) => {
77
+ if (!beforeChangeHook) return Promise.resolve();
78
+ try {
79
+ const result = beforeChangeHook(payload);
80
+ if (result && typeof result.then === 'function') {
81
+ return result.catch((error) => {
82
+ console.warn('[AssemblyConstraintCollectionWidget] before change hook rejected:', error);
83
+ });
84
+ }
85
+ return Promise.resolve(result);
86
+ } catch (error) {
87
+ console.warn('[AssemblyConstraintCollectionWidget] before change hook failed:', error);
88
+ return Promise.resolve();
89
+ }
90
+ };
91
+ const formOptionsProvider = (context = {}) => {
92
+ const entry = context.entry || null;
93
+ const constraintId = resolveEntryId(entry);
94
+ return {
95
+ excludeKeys: ['id', 'constraintID', 'applyImmediately'],
96
+ onReferenceChipRemove: (name) => {
97
+ try { SelectionFilter.deselectItem?.(viewerRef?.scene, name); }
98
+ catch { /* ignore */ }
99
+ },
100
+ onChange: async (_entryId, details) => {
101
+ if (!constraintId) return;
102
+ const key = details?.key;
103
+ if (!key || !Object.prototype.hasOwnProperty.call(details, 'value')) return;
104
+ await callBeforeChange({ entry, reason: 'params', key, value: details.value });
105
+ historyRef?.updateConstraintParams?.(constraintId, (params) => {
106
+ if (!params || typeof params !== 'object') return;
107
+ params[key] = details.value;
108
+ });
109
+ },
110
+ };
111
+ };
112
+
113
+ const externalEntryChange = typeof onEntryChange === 'function' ? onEntryChange : null;
114
+ const externalCollectionChange = typeof onCollectionChange === 'function' ? onCollectionChange : null;
115
+ const externalToggle = typeof onEntryToggle === 'function' ? onEntryToggle : null;
116
+
117
+ super({
118
+ history,
119
+ viewer,
120
+ autoSyncOpenState: true,
121
+ formOptions: formOptionsProvider,
122
+ createEntry: async (typeStr) => {
123
+ if (!typeStr) return null;
124
+ if (typeof historyRef?.addConstraint !== 'function') return null;
125
+ return historyRef.addConstraint(typeStr);
126
+ },
127
+ entryToggle: {
128
+ className: 'constraint-enable-toggle',
129
+ getTitle: () => 'Enable or disable this constraint',
130
+ isEnabled: ({ entry }) => entry?.enabled !== false,
131
+ setEnabled: async ({ entry }, value) => {
132
+ const entryId = resolveEntryId(entry);
133
+ if (!entryId) return;
134
+ await callBeforeChange({ entry, reason: value ? 'enable' : 'disable' });
135
+ historyRef?.setConstraintEnabled?.(entryId, value);
136
+ },
137
+ },
138
+ onEntryChange: (payload) => {
139
+ if (payload?.entry?.inputParams) {
140
+ payload.entry.inputParams.applyImmediately = true;
141
+ }
142
+ if (externalEntryChange) {
143
+ try { externalEntryChange(payload); } catch { /* ignore */ }
144
+ }
145
+ },
146
+ onCollectionChange: (payload) => {
147
+ if (externalCollectionChange) {
148
+ try { externalCollectionChange(payload); } catch { /* ignore */ }
149
+ }
150
+ },
151
+ onEntryToggle: (entry, isOpen) => {
152
+ const entryId = resolveEntryId(entry);
153
+ if (entryId && typeof historyRef?.setOpenState === 'function') {
154
+ historyRef.setOpenState(entryId, isOpen);
155
+ }
156
+ if (externalToggle) {
157
+ try { externalToggle(entry, isOpen); } catch { /* ignore */ }
158
+ }
159
+ },
160
+ decorateEntryHeader: (context) => { this.#decorateEntry(context); },
161
+ buildEntryControls: (context) => this.#buildControls(context),
162
+ onFormReady: (payload) => { this.#handleFormReady(payload); },
163
+ });
164
+
165
+ this.partHistory = partHistory || null;
166
+ this.viewer = viewer || null;
167
+ this._highlightCallback = typeof onHighlightRequest === 'function' ? onHighlightRequest : null;
168
+ this._clearHighlightCallback = typeof onClearHighlight === 'function' ? onClearHighlight : null;
169
+ this._beforeConstraintChangeHandler = callBeforeChange;
170
+ this.#injectAdditionalStyles();
171
+ }
172
+
173
+ setPartHistory(partHistory) {
174
+ this.partHistory = partHistory || null;
175
+ }
176
+
177
+ focusEntryById(targetId, { behavior = 'smooth' } = {}) {
178
+ if (targetId == null) return;
179
+ const id = String(targetId);
180
+ if (!id) return;
181
+ this._expandedId = id;
182
+ this.render();
183
+ const root = this._shadow || null;
184
+ if (!root) return;
185
+ const selector = `.hc-item[data-entry-id="${CSS?.escape ? CSS.escape(id) : id}"]`;
186
+ const el = root.querySelector(selector);
187
+ if (el && typeof el.scrollIntoView === 'function') {
188
+ el.scrollIntoView({ behavior, block: 'center' });
189
+ }
190
+ }
191
+
192
+ #decorateEntry(context = {}) {
193
+ const { entry = null, elements = {}, index = 0 } = context;
194
+ if (!elements || !elements.item) return;
195
+ const info = this._applyDisplayInfo(entry, index, resolveEntryId(entry, index), {
196
+ titleEl: elements.titleEl,
197
+ metaEl: elements.metaEl,
198
+ item: elements.item,
199
+ });
200
+ const constraintClass = entry?.constraintClass || null;
201
+ elements.item.classList.toggle('constraint-disabled', entry?.enabled === false);
202
+ elements.item.dataset.constraintId = resolveEntryId(entry) || '';
203
+
204
+ if (info && info.name && elements.titleEl) {
205
+ elements.titleEl.textContent = info.name;
206
+ } else if (elements.titleEl) {
207
+ elements.titleEl.textContent =
208
+ constraintLabelText(entry, constraintClass, this.partHistory) || `Constraint ${index + 1}`;
209
+ }
210
+ }
211
+
212
+ #buildControls(context = {}) {
213
+ const entryId = resolveEntryId(context.entry);
214
+ const total = context.totalCount || 0;
215
+ const index = context.index || 0;
216
+ const controls = [];
217
+ controls.push({
218
+ key: 'move-up',
219
+ label: '△',
220
+ title: 'Move up',
221
+ disabled: index <= 0,
222
+ onClick: async () => {
223
+ await this.#notifyBeforeChange({ entry: context.entry, reason: 'move-up' });
224
+ if (entryId) this.history?.moveConstraint?.(entryId, -1);
225
+ },
226
+ });
227
+ controls.push({
228
+ key: 'move-down',
229
+ label: '▽',
230
+ title: 'Move down',
231
+ disabled: index >= total - 1,
232
+ onClick: async () => {
233
+ await this.#notifyBeforeChange({ entry: context.entry, reason: 'move-down' });
234
+ if (entryId) this.history?.moveConstraint?.(entryId, 1);
235
+ },
236
+ });
237
+ controls.push({
238
+ key: 'delete',
239
+ label: '✕',
240
+ className: 'hc-btn danger',
241
+ title: 'Delete',
242
+ onClick: async () => {
243
+ await this.#notifyBeforeChange({ entry: context.entry, reason: 'delete' });
244
+ if (entryId) this.history?.removeConstraint?.(entryId);
245
+ },
246
+ });
247
+ return controls;
248
+ }
249
+
250
+ #notifyBeforeChange(payload = {}) {
251
+ const handler = this._beforeConstraintChangeHandler;
252
+ if (!handler) return Promise.resolve();
253
+ try {
254
+ const result = handler(payload);
255
+ if (result && typeof result.then === 'function') {
256
+ return result.catch((error) => {
257
+ console.warn('[AssemblyConstraintCollectionWidget] before change hook rejected:', error);
258
+ });
259
+ }
260
+ return Promise.resolve(result);
261
+ } catch (error) {
262
+ console.warn('[AssemblyConstraintCollectionWidget] before change hook threw:', error);
263
+ return Promise.resolve();
264
+ }
265
+ }
266
+
267
+ _resolveSchema(entry) {
268
+ const constraintClass = entry?.constraintClass || null;
269
+ if (constraintClass?.inputParamsSchema) return constraintClass.inputParamsSchema;
270
+ const registry = this.history?.registry || null;
271
+ const type = entry?.type || entry?.inputParams?.type;
272
+ if (registry && type) {
273
+ const resolved =
274
+ (typeof registry.getSafe === 'function' && registry.getSafe(type))
275
+ || (typeof registry.get === 'function' && registry.get(type));
276
+ if (resolved?.inputParamsSchema) return resolved.inputParamsSchema;
277
+ }
278
+ return super._resolveSchema(entry);
279
+ }
280
+
281
+ #handleFormReady({ entry, form }) {
282
+ if (!form?.uiElement) return;
283
+ if (entry?.inputParams) entry.inputParams.applyImmediately = true;
284
+ const host = form.uiElement.parentElement;
285
+ if (!host) return;
286
+ let actions = host.querySelector(':scope > .constraint-dialog-actions');
287
+ if (!actions) {
288
+ actions = document.createElement('div');
289
+ actions.className = 'constraint-dialog-actions';
290
+ host.appendChild(actions);
291
+ } else {
292
+ actions.textContent = '';
293
+ }
294
+
295
+ const highlightBtn = document.createElement('button');
296
+ highlightBtn.type = 'button';
297
+ highlightBtn.className = 'btn highlight-btn';
298
+ highlightBtn.textContent = 'Highlight Selection';
299
+ highlightBtn.addEventListener('click', (ev) => {
300
+ ev.preventDefault();
301
+ ev.stopPropagation();
302
+ if (this._highlightCallback) {
303
+ try { this._highlightCallback(entry); } catch { /* ignore */ }
304
+ }
305
+ });
306
+ actions.appendChild(highlightBtn);
307
+
308
+ const clearBtn = document.createElement('button');
309
+ clearBtn.type = 'button';
310
+ clearBtn.className = 'btn';
311
+ clearBtn.textContent = 'Clear Highlight';
312
+ clearBtn.addEventListener('click', (ev) => {
313
+ ev.preventDefault();
314
+ ev.stopPropagation();
315
+ if (this._clearHighlightCallback) {
316
+ try { this._clearHighlightCallback(); } catch { /* ignore */ }
317
+ }
318
+ });
319
+ actions.appendChild(clearBtn);
320
+ }
321
+
322
+ #injectAdditionalStyles() {
323
+ if (!this._shadow) return;
324
+ const style = document.createElement('style');
325
+ style.textContent = COLLECTION_EXTRA_CSS;
326
+ this._shadow.appendChild(style);
327
+ }
328
+
329
+ }
@@ -0,0 +1,282 @@
1
+ export class AssemblyConstraintControlsWidget {
2
+ constructor(host) {
3
+ this.host = host || null;
4
+ this.element = this.#buildControlsPanel();
5
+ }
6
+
7
+ #buildControlsPanel() {
8
+ const wrap = document.createElement('div');
9
+ wrap.className = 'constraints-control-panel';
10
+
11
+ wrap.appendChild(this.#buildSolverControls());
12
+ wrap.appendChild(this.#buildVisualizationControls());
13
+ wrap.appendChild(this.#buildDebugControls());
14
+
15
+ return wrap;
16
+ }
17
+
18
+ #buildSolverControls() {
19
+ const host = this.host;
20
+ const wrap = document.createElement('div');
21
+ wrap.className = 'control-panel-section solver-controls';
22
+
23
+ const mainRow = document.createElement('div');
24
+ mainRow.className = 'solver-row solver-row-main';
25
+
26
+ const label = document.createElement('label');
27
+ label.className = 'solver-iterations';
28
+
29
+ const labelText = document.createElement('span');
30
+ labelText.className = 'solver-iterations-label';
31
+ labelText.textContent = 'Iterations';
32
+
33
+ const input = document.createElement('input');
34
+ input.type = 'number';
35
+ input.min = '1';
36
+ input.step = '1';
37
+ input.inputMode = 'numeric';
38
+ input.value = String(host?._defaultIterations ?? 1);
39
+ input.style.width = '5em';
40
+ input.addEventListener('change', () => {
41
+ const value = Number(input.value);
42
+ if (!Number.isFinite(value) || value < 1) {
43
+ input.value = String(host?._defaultIterations ?? 1);
44
+ }
45
+ });
46
+
47
+ label.appendChild(labelText);
48
+ label.appendChild(input);
49
+
50
+ const buttonGroup = document.createElement('div');
51
+ buttonGroup.className = 'solver-button-group';
52
+
53
+ const startBtn = document.createElement('button');
54
+ startBtn.type = 'button';
55
+ startBtn.className = 'btn solver-start-btn';
56
+ startBtn.textContent = 'Start';
57
+ startBtn.addEventListener('click', (ev) => {
58
+ ev.preventDefault();
59
+ ev.stopPropagation();
60
+ const promise = host?._handleStartClick?.call(host);
61
+ if (promise?.catch) {
62
+ try { promise.catch(() => { }); } catch { /* ignore */ }
63
+ }
64
+ });
65
+
66
+ const stopBtn = document.createElement('button');
67
+ stopBtn.type = 'button';
68
+ stopBtn.className = 'btn solver-stop-btn';
69
+ stopBtn.textContent = 'Stop';
70
+ stopBtn.disabled = true;
71
+ stopBtn.addEventListener('click', (ev) => {
72
+ ev.preventDefault();
73
+ ev.stopPropagation();
74
+ const stopPromise = host?._stopSolver?.call(host, { wait: false });
75
+ if (stopPromise?.catch) {
76
+ try { stopPromise.catch(() => { }); } catch { /* ignore */ }
77
+ }
78
+ });
79
+
80
+ buttonGroup.appendChild(startBtn);
81
+ buttonGroup.appendChild(stopBtn);
82
+
83
+ mainRow.appendChild(label);
84
+ mainRow.appendChild(buttonGroup);
85
+
86
+ const statusRow = document.createElement('div');
87
+ statusRow.className = 'solver-row solver-row-status';
88
+
89
+ const statusLabel = document.createElement('span');
90
+ statusLabel.className = 'solver-status-label';
91
+ statusLabel.textContent = 'Status: Idle';
92
+
93
+ const loopLabel = document.createElement('span');
94
+ loopLabel.className = 'solver-loop-label';
95
+ loopLabel.textContent = 'Loop: -';
96
+
97
+ const constraintLabel = document.createElement('span');
98
+ constraintLabel.className = 'solver-constraint-label';
99
+ constraintLabel.textContent = 'Constraint: -';
100
+
101
+ statusRow.appendChild(statusLabel);
102
+ statusRow.appendChild(loopLabel);
103
+ statusRow.appendChild(constraintLabel);
104
+
105
+ const autoSolveRow = document.createElement('div');
106
+ autoSolveRow.className = 'solver-row solver-row-autosolve';
107
+
108
+ const autoSolveLabel = document.createElement('label');
109
+ autoSolveLabel.className = 'toggle-control solver-autosolve-toggle';
110
+
111
+ const autoSolveCheckbox = document.createElement('input');
112
+ autoSolveCheckbox.type = 'checkbox';
113
+ autoSolveCheckbox.checked = !!host?._fullSolveOnChange;
114
+ autoSolveCheckbox.addEventListener('change', () => {
115
+ host?._handleFullSolveToggleChange?.call(host, autoSolveCheckbox.checked);
116
+ });
117
+
118
+ const autoSolveText = document.createElement('span');
119
+ autoSolveText.textContent = 'Full solve on change';
120
+
121
+ autoSolveLabel.appendChild(autoSolveCheckbox);
122
+ autoSolveLabel.appendChild(autoSolveText);
123
+ autoSolveRow.appendChild(autoSolveLabel);
124
+
125
+ const animateRow = document.createElement('div');
126
+ animateRow.className = 'solver-row solver-row-animate';
127
+
128
+ const animateLabel = document.createElement('label');
129
+ animateLabel.className = 'toggle-control solver-animate-toggle';
130
+
131
+ const animateCheckbox = document.createElement('input');
132
+ animateCheckbox.type = 'checkbox';
133
+ animateCheckbox.checked = host?._animateEnabled !== false;
134
+ animateCheckbox.addEventListener('change', () => {
135
+ host?._handleAnimateCheckboxChange?.call(host);
136
+ });
137
+
138
+ const animateText = document.createElement('span');
139
+ animateText.textContent = 'Animate solve';
140
+
141
+ animateLabel.appendChild(animateCheckbox);
142
+ animateLabel.appendChild(animateText);
143
+
144
+ const delayContainer = document.createElement('div');
145
+ delayContainer.className = 'solver-animate-delay';
146
+
147
+ const delayLabel = document.createElement('span');
148
+ delayLabel.textContent = 'Step speed (ms)';
149
+
150
+ const delayInput = document.createElement('input');
151
+ delayInput.type = 'number';
152
+ delayInput.min = '0';
153
+ delayInput.step = '1';
154
+ delayInput.inputMode = 'numeric';
155
+ delayInput.value = String(host?._animateDelayMs ?? 0);
156
+ delayInput.addEventListener('change', () => {
157
+ host?._handleAnimateDelayChange?.call(host);
158
+ });
159
+
160
+ delayContainer.appendChild(delayLabel);
161
+ delayContainer.appendChild(delayInput);
162
+
163
+ animateRow.appendChild(animateLabel);
164
+ animateRow.appendChild(delayContainer);
165
+
166
+ const pauseRow = document.createElement('div');
167
+ pauseRow.className = 'solver-row solver-row-pause';
168
+
169
+ const pauseLabel = document.createElement('label');
170
+ pauseLabel.className = 'toggle-control solver-pause-toggle';
171
+
172
+ const pauseCheckbox = document.createElement('input');
173
+ pauseCheckbox.type = 'checkbox';
174
+ pauseCheckbox.addEventListener('change', () => {
175
+ host?._handlePauseCheckboxChange?.call(host);
176
+ });
177
+
178
+ const pauseText = document.createElement('span');
179
+ pauseText.textContent = 'Pause between loops';
180
+
181
+ pauseLabel.appendChild(pauseCheckbox);
182
+ pauseLabel.appendChild(pauseText);
183
+
184
+ const continueBtn = document.createElement('button');
185
+ continueBtn.type = 'button';
186
+ continueBtn.className = 'btn solver-continue-btn';
187
+ continueBtn.textContent = 'Continue';
188
+ continueBtn.disabled = true;
189
+ continueBtn.style.display = 'none';
190
+ continueBtn.addEventListener('click', (ev) => {
191
+ ev.preventDefault();
192
+ ev.stopPropagation();
193
+ host?._handleContinueClick?.call(host);
194
+ });
195
+
196
+ pauseRow.appendChild(pauseLabel);
197
+ pauseRow.appendChild(continueBtn);
198
+
199
+ wrap.appendChild(mainRow);
200
+ wrap.appendChild(statusRow);
201
+ wrap.appendChild(autoSolveRow);
202
+ wrap.appendChild(animateRow);
203
+ wrap.appendChild(pauseRow);
204
+
205
+ if (host) {
206
+ host._iterationInput = input;
207
+ host._startButton = startBtn;
208
+ host._stopButton = stopBtn;
209
+ host._solverStatusLabel = statusLabel;
210
+ host._solverLoopLabel = loopLabel;
211
+ host._solverConstraintLabel = constraintLabel;
212
+ host._pauseCheckbox = pauseCheckbox;
213
+ host._solverContinueButton = continueBtn;
214
+ host._animateCheckbox = animateCheckbox;
215
+ host._animateDelayInput = delayInput;
216
+ host._animateDelayContainer = delayContainer;
217
+ host._fullSolveCheckbox = autoSolveCheckbox;
218
+ host._animateEnabled = animateCheckbox.checked !== false;
219
+ host._updateSolverUI?.();
220
+ }
221
+
222
+ return wrap;
223
+ }
224
+
225
+ #buildVisualizationControls() {
226
+ const host = this.host;
227
+ const wrap = document.createElement('div');
228
+ wrap.className = 'control-panel-section visualization-controls';
229
+
230
+ const label = document.createElement('label');
231
+ label.className = 'toggle-control';
232
+
233
+ const checkbox = document.createElement('input');
234
+ checkbox.type = 'checkbox';
235
+ checkbox.checked = host?._constraintGraphicsEnabled ?? false;
236
+ checkbox.addEventListener('change', () => {
237
+ host?._setConstraintGraphicsEnabled?.call(host, checkbox.checked);
238
+ });
239
+
240
+ const span = document.createElement('span');
241
+ span.textContent = 'Show Constraint Graphics';
242
+
243
+ label.appendChild(checkbox);
244
+ label.appendChild(span);
245
+ wrap.appendChild(label);
246
+
247
+ if (host) {
248
+ host._constraintGraphicsCheckbox = checkbox;
249
+ }
250
+
251
+ return wrap;
252
+ }
253
+
254
+ #buildDebugControls() {
255
+ const host = this.host;
256
+ const wrap = document.createElement('div');
257
+ wrap.className = 'control-panel-section debug-controls';
258
+
259
+ const label = document.createElement('label');
260
+ label.className = 'toggle-control';
261
+
262
+ const checkbox = document.createElement('input');
263
+ checkbox.type = 'checkbox';
264
+ checkbox.addEventListener('change', () => {
265
+ host?._handleDebugCheckboxChange?.call(host, checkbox.checked);
266
+ });
267
+
268
+ const span = document.createElement('span');
269
+ span.textContent = 'Debug Normals';
270
+
271
+ label.appendChild(checkbox);
272
+ label.appendChild(span);
273
+ wrap.appendChild(label);
274
+
275
+ return wrap;
276
+ }
277
+
278
+ dispose() {
279
+ this.host = null;
280
+ this.element = null;
281
+ }
282
+ }