chili3d 0.6.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.
Files changed (472) hide show
  1. package/.github/workflows/main.yml +26 -0
  2. package/.vscode/c_cpp_properties.json +30 -0
  3. package/.vscode/launch.json +21 -0
  4. package/.vscode/settings.json +8 -0
  5. package/Dockerfile +7 -0
  6. package/LICENSE +661 -0
  7. package/README.md +184 -0
  8. package/biome.json +67 -0
  9. package/compose.yml +7 -0
  10. package/cpp/CMakeLists.txt +96 -0
  11. package/cpp/CMakePresets.json +43 -0
  12. package/cpp/README.md +21 -0
  13. package/cpp/src/converter.cpp +413 -0
  14. package/cpp/src/factory.cpp +612 -0
  15. package/cpp/src/geometry.cpp +204 -0
  16. package/cpp/src/mesher.cpp +330 -0
  17. package/cpp/src/opencascade.cpp +414 -0
  18. package/cpp/src/shape.cpp +447 -0
  19. package/cpp/src/shared.cpp +83 -0
  20. package/cpp/src/shared.hpp +211 -0
  21. package/cpp/src/transient.cpp +29 -0
  22. package/cpp/src/utils.cpp +114 -0
  23. package/cpp/src/utils.hpp +25 -0
  24. package/cpp/test/index.html +146 -0
  25. package/package.json +49 -0
  26. package/packages/chili/package.json +11 -0
  27. package/packages/chili/src/application.ts +200 -0
  28. package/packages/chili/src/bodys/arc.ts +61 -0
  29. package/packages/chili/src/bodys/boolean.ts +32 -0
  30. package/packages/chili/src/bodys/box.ts +73 -0
  31. package/packages/chili/src/bodys/circle.ts +57 -0
  32. package/packages/chili/src/bodys/cone.ts +64 -0
  33. package/packages/chili/src/bodys/cylinder.ts +69 -0
  34. package/packages/chili/src/bodys/ellipse.ts +85 -0
  35. package/packages/chili/src/bodys/face.ts +72 -0
  36. package/packages/chili/src/bodys/fuse.ts +44 -0
  37. package/packages/chili/src/bodys/index.ts +16 -0
  38. package/packages/chili/src/bodys/line.ts +48 -0
  39. package/packages/chili/src/bodys/polygon.ts +40 -0
  40. package/packages/chili/src/bodys/prism.ts +49 -0
  41. package/packages/chili/src/bodys/pyramid.ts +64 -0
  42. package/packages/chili/src/bodys/rect.ts +69 -0
  43. package/packages/chili/src/bodys/revolve.ts +54 -0
  44. package/packages/chili/src/bodys/sphere.ts +48 -0
  45. package/packages/chili/src/bodys/sweep.ts +67 -0
  46. package/packages/chili/src/bodys/wire.ts +36 -0
  47. package/packages/chili/src/commands/application/index.ts +10 -0
  48. package/packages/chili/src/commands/application/newDocument.ts +17 -0
  49. package/packages/chili/src/commands/application/openDocument.ts +35 -0
  50. package/packages/chili/src/commands/application/performanceTest.ts +64 -0
  51. package/packages/chili/src/commands/application/saveDocument.ts +24 -0
  52. package/packages/chili/src/commands/application/toFile.ts +35 -0
  53. package/packages/chili/src/commands/application/toggleDynamicWorkplane.ts +15 -0
  54. package/packages/chili/src/commands/application/wechatGroup.ts +42 -0
  55. package/packages/chili/src/commands/boolean.ts +109 -0
  56. package/packages/chili/src/commands/create/arc.ts +110 -0
  57. package/packages/chili/src/commands/create/bezier.ts +116 -0
  58. package/packages/chili/src/commands/create/box.ts +59 -0
  59. package/packages/chili/src/commands/create/circle.ts +54 -0
  60. package/packages/chili/src/commands/create/cone.ts +104 -0
  61. package/packages/chili/src/commands/create/converter.ts +159 -0
  62. package/packages/chili/src/commands/create/copySubShape.ts +37 -0
  63. package/packages/chili/src/commands/create/curveProjection.ts +61 -0
  64. package/packages/chili/src/commands/create/cylinder.ts +96 -0
  65. package/packages/chili/src/commands/create/ellipse.ts +95 -0
  66. package/packages/chili/src/commands/create/group.ts +205 -0
  67. package/packages/chili/src/commands/create/index.ts +26 -0
  68. package/packages/chili/src/commands/create/line.ts +61 -0
  69. package/packages/chili/src/commands/create/loft.ts +149 -0
  70. package/packages/chili/src/commands/create/offset.ts +131 -0
  71. package/packages/chili/src/commands/create/polygon.ts +104 -0
  72. package/packages/chili/src/commands/create/prism.ts +52 -0
  73. package/packages/chili/src/commands/create/pyramid.ts +56 -0
  74. package/packages/chili/src/commands/create/rect.ts +105 -0
  75. package/packages/chili/src/commands/create/revolve.ts +62 -0
  76. package/packages/chili/src/commands/create/section.ts +31 -0
  77. package/packages/chili/src/commands/create/sphere.ts +48 -0
  78. package/packages/chili/src/commands/create/sweep.ts +39 -0
  79. package/packages/chili/src/commands/create/thickSolid.ts +50 -0
  80. package/packages/chili/src/commands/createActCommand.ts +26 -0
  81. package/packages/chili/src/commands/createCommand.ts +41 -0
  82. package/packages/chili/src/commands/delete.ts +38 -0
  83. package/packages/chili/src/commands/folder.ts +18 -0
  84. package/packages/chili/src/commands/importExport.ts +97 -0
  85. package/packages/chili/src/commands/index.ts +17 -0
  86. package/packages/chili/src/commands/measure/angle.ts +130 -0
  87. package/packages/chili/src/commands/measure/index.ts +6 -0
  88. package/packages/chili/src/commands/measure/length.ts +57 -0
  89. package/packages/chili/src/commands/measure/select.module.css +68 -0
  90. package/packages/chili/src/commands/measure/select.ts +228 -0
  91. package/packages/chili/src/commands/modify/array.ts +447 -0
  92. package/packages/chili/src/commands/modify/break.ts +78 -0
  93. package/packages/chili/src/commands/modify/brush.ts +100 -0
  94. package/packages/chili/src/commands/modify/chamfer.ts +70 -0
  95. package/packages/chili/src/commands/modify/explode.ts +91 -0
  96. package/packages/chili/src/commands/modify/fillet.ts +69 -0
  97. package/packages/chili/src/commands/modify/index.ts +16 -0
  98. package/packages/chili/src/commands/modify/mirror.ts +49 -0
  99. package/packages/chili/src/commands/modify/move.ts +39 -0
  100. package/packages/chili/src/commands/modify/removeFeature.ts +56 -0
  101. package/packages/chili/src/commands/modify/removeSubShapes.ts +44 -0
  102. package/packages/chili/src/commands/modify/rotate.ts +112 -0
  103. package/packages/chili/src/commands/modify/split.ts +81 -0
  104. package/packages/chili/src/commands/modify/transformedCommand.ts +100 -0
  105. package/packages/chili/src/commands/modify/trim.ts +254 -0
  106. package/packages/chili/src/commands/multistepCommand.ts +125 -0
  107. package/packages/chili/src/commands/redo.ts +16 -0
  108. package/packages/chili/src/commands/undo.ts +16 -0
  109. package/packages/chili/src/commands/workingPlane.ts +150 -0
  110. package/packages/chili/src/comparers/NumberEqualityComparer.ts +12 -0
  111. package/packages/chili/src/comparers/XYZEqualityComparer.ts +12 -0
  112. package/packages/chili/src/comparers/index.ts +5 -0
  113. package/packages/chili/src/document.ts +145 -0
  114. package/packages/chili/src/editEventHandler.ts +20 -0
  115. package/packages/chili/src/index.ts +12 -0
  116. package/packages/chili/src/selection.ts +178 -0
  117. package/packages/chili/src/services/commandService.ts +105 -0
  118. package/packages/chili/src/services/editorService.ts +46 -0
  119. package/packages/chili/src/services/hotkeyService.ts +102 -0
  120. package/packages/chili/src/services/index.ts +6 -0
  121. package/packages/chili/src/snap/dimension.ts +33 -0
  122. package/packages/chili/src/snap/handlers/angleSnapEventHandler.ts +60 -0
  123. package/packages/chili/src/snap/handlers/index.ts +7 -0
  124. package/packages/chili/src/snap/handlers/lengthSnapEventHandler.ts +117 -0
  125. package/packages/chili/src/snap/handlers/pointSnapEventHandler.ts +176 -0
  126. package/packages/chili/src/snap/handlers/snapEventHandler.ts +288 -0
  127. package/packages/chili/src/snap/index.ts +6 -0
  128. package/packages/chili/src/snap/snap.ts +50 -0
  129. package/packages/chili/src/snap/snaps/axisSnap.ts +57 -0
  130. package/packages/chili/src/snap/snaps/baseSnap.ts +69 -0
  131. package/packages/chili/src/snap/snaps/featurePointStrategy.ts +64 -0
  132. package/packages/chili/src/snap/snaps/index.ts +7 -0
  133. package/packages/chili/src/snap/snaps/objectSnap.ts +264 -0
  134. package/packages/chili/src/snap/snaps/planeSnap.ts +55 -0
  135. package/packages/chili/src/snap/snaps/pointOnCurveSnap.ts +24 -0
  136. package/packages/chili/src/snap/tracking/axis.ts +32 -0
  137. package/packages/chili/src/snap/tracking/axisTracking.ts +46 -0
  138. package/packages/chili/src/snap/tracking/index.ts +6 -0
  139. package/packages/chili/src/snap/tracking/objectTracking.ts +90 -0
  140. package/packages/chili/src/snap/tracking/trackingBase.ts +40 -0
  141. package/packages/chili/src/snap/tracking/trackingSnap.ts +201 -0
  142. package/packages/chili/src/step/angleStep.ts +32 -0
  143. package/packages/chili/src/step/index.ts +8 -0
  144. package/packages/chili/src/step/lengthStep.ts +32 -0
  145. package/packages/chili/src/step/pointStep.ts +87 -0
  146. package/packages/chili/src/step/selectStep.ts +130 -0
  147. package/packages/chili/src/step/step.ts +55 -0
  148. package/packages/chili/src/utils.ts +19 -0
  149. package/packages/chili/test/command.test.ts +4 -0
  150. package/packages/chili-builder/package.json +13 -0
  151. package/packages/chili-builder/src/additionalModule.ts +15 -0
  152. package/packages/chili-builder/src/appBuilder.ts +176 -0
  153. package/packages/chili-builder/src/defaultDataExchange.ts +152 -0
  154. package/packages/chili-builder/src/index.ts +5 -0
  155. package/packages/chili-builder/src/ribbon.ts +129 -0
  156. package/packages/chili-controls/package.json +9 -0
  157. package/packages/chili-controls/src/collection.ts +96 -0
  158. package/packages/chili-controls/src/controls.ts +83 -0
  159. package/packages/chili-controls/src/converters/colorConverter.ts +39 -0
  160. package/packages/chili-controls/src/converters/index.ts +8 -0
  161. package/packages/chili-controls/src/converters/numberConverter.ts +15 -0
  162. package/packages/chili-controls/src/converters/stringConverter.ts +13 -0
  163. package/packages/chili-controls/src/converters/urlConverter.ts +10 -0
  164. package/packages/chili-controls/src/converters/xyzConverter.ts +28 -0
  165. package/packages/chili-controls/src/expander/expander.module.css +38 -0
  166. package/packages/chili-controls/src/expander/expander.ts +59 -0
  167. package/packages/chili-controls/src/expander/index.ts +4 -0
  168. package/packages/chili-controls/src/htmlProps.ts +10 -0
  169. package/packages/chili-controls/src/index.ts +10 -0
  170. package/packages/chili-controls/src/radioGroup.module.css +20 -0
  171. package/packages/chili-controls/src/radioGroup.ts +54 -0
  172. package/packages/chili-controls/src/utils.ts +20 -0
  173. package/packages/chili-controls/test/converter.test.ts +70 -0
  174. package/packages/chili-controls/test/styleMock.js +4 -0
  175. package/packages/chili-core/package.json +7 -0
  176. package/packages/chili-core/src/application.ts +38 -0
  177. package/packages/chili-core/src/command/command.ts +154 -0
  178. package/packages/chili-core/src/command/commandKeys.ts +8 -0
  179. package/packages/chili-core/src/command/decarator.ts +43 -0
  180. package/packages/chili-core/src/command/index.ts +6 -0
  181. package/packages/chili-core/src/config.ts +145 -0
  182. package/packages/chili-core/src/constants.ts +8 -0
  183. package/packages/chili-core/src/dataExchange.ts +12 -0
  184. package/packages/chili-core/src/document.ts +25 -0
  185. package/packages/chili-core/src/editor.ts +12 -0
  186. package/packages/chili-core/src/foundation/asyncController.ts +55 -0
  187. package/packages/chili-core/src/foundation/binding.ts +132 -0
  188. package/packages/chili-core/src/foundation/collection.ts +208 -0
  189. package/packages/chili-core/src/foundation/converter.ts +9 -0
  190. package/packages/chili-core/src/foundation/deepObserver.ts +154 -0
  191. package/packages/chili-core/src/foundation/disposable.ts +18 -0
  192. package/packages/chili-core/src/foundation/dto/index.ts +9 -0
  193. package/packages/chili-core/src/foundation/equalityComparer.ts +6 -0
  194. package/packages/chili-core/src/foundation/gc.ts +36 -0
  195. package/packages/chili-core/src/foundation/history.ts +237 -0
  196. package/packages/chili-core/src/foundation/id.ts +25 -0
  197. package/packages/chili-core/src/foundation/index.ts +26 -0
  198. package/packages/chili-core/src/foundation/lazy.ts +18 -0
  199. package/packages/chili-core/src/foundation/linkedList.ts +141 -0
  200. package/packages/chili-core/src/foundation/logger.ts +45 -0
  201. package/packages/chili-core/src/foundation/messageType.ts +8 -0
  202. package/packages/chili-core/src/foundation/objectStorage.ts +50 -0
  203. package/packages/chili-core/src/foundation/observer.ts +147 -0
  204. package/packages/chili-core/src/foundation/precision.ts +8 -0
  205. package/packages/chili-core/src/foundation/pubsub.ts +74 -0
  206. package/packages/chili-core/src/foundation/result.ts +69 -0
  207. package/packages/chili-core/src/foundation/storage.ts +10 -0
  208. package/packages/chili-core/src/foundation/transaction.ts +77 -0
  209. package/packages/chili-core/src/foundation/utils/debounce.ts +15 -0
  210. package/packages/chili-core/src/foundation/utils/download.ts +16 -0
  211. package/packages/chili-core/src/foundation/utils/index.ts +6 -0
  212. package/packages/chili-core/src/foundation/utils/readFileAsync.ts +84 -0
  213. package/packages/chili-core/src/i18n/i18n.ts +107 -0
  214. package/packages/chili-core/src/i18n/index.ts +5 -0
  215. package/packages/chili-core/src/i18n/keys.ts +265 -0
  216. package/packages/chili-core/src/index.ts +26 -0
  217. package/packages/chili-core/src/material.ts +269 -0
  218. package/packages/chili-core/src/math/boundingBox.ts +226 -0
  219. package/packages/chili-core/src/math/index.ts +14 -0
  220. package/packages/chili-core/src/math/line.ts +55 -0
  221. package/packages/chili-core/src/math/lineSegment.ts +166 -0
  222. package/packages/chili-core/src/math/mathUtils.ts +45 -0
  223. package/packages/chili-core/src/math/matrix4.ts +414 -0
  224. package/packages/chili-core/src/math/plane.ts +96 -0
  225. package/packages/chili-core/src/math/planeAngle.ts +53 -0
  226. package/packages/chili-core/src/math/quaternion.ts +131 -0
  227. package/packages/chili-core/src/math/ray.ts +30 -0
  228. package/packages/chili-core/src/math/xy.ts +104 -0
  229. package/packages/chili-core/src/math/xyz.ts +181 -0
  230. package/packages/chili-core/src/model/component.ts +305 -0
  231. package/packages/chili-core/src/model/facebaseNode.ts +17 -0
  232. package/packages/chili-core/src/model/folderNode.ts +289 -0
  233. package/packages/chili-core/src/model/geometryNode.ts +185 -0
  234. package/packages/chili-core/src/model/groupNode.ts +19 -0
  235. package/packages/chili-core/src/model/index.ts +12 -0
  236. package/packages/chili-core/src/model/meshNode.ts +53 -0
  237. package/packages/chili-core/src/model/node.ts +315 -0
  238. package/packages/chili-core/src/model/shapeNode.ts +195 -0
  239. package/packages/chili-core/src/model/visualNode.ts +39 -0
  240. package/packages/chili-core/src/modelManager.ts +147 -0
  241. package/packages/chili-core/src/navigation.ts +58 -0
  242. package/packages/chili-core/src/property.ts +60 -0
  243. package/packages/chili-core/src/selection.ts +33 -0
  244. package/packages/chili-core/src/selectionFilter.ts +28 -0
  245. package/packages/chili-core/src/serialize/index.ts +4 -0
  246. package/packages/chili-core/src/serialize/serializer.ts +231 -0
  247. package/packages/chili-core/src/service.ts +10 -0
  248. package/packages/chili-core/src/shape/curve.ts +174 -0
  249. package/packages/chili-core/src/shape/geometry.ts +17 -0
  250. package/packages/chili-core/src/shape/index.ts +12 -0
  251. package/packages/chili-core/src/shape/lineType.ts +7 -0
  252. package/packages/chili-core/src/shape/meshData.ts +347 -0
  253. package/packages/chili-core/src/shape/shape.ts +104 -0
  254. package/packages/chili-core/src/shape/shapeConverter.ts +17 -0
  255. package/packages/chili-core/src/shape/shapeFactory.ts +58 -0
  256. package/packages/chili-core/src/shape/shapeType.ts +75 -0
  257. package/packages/chili-core/src/shape/surface.ts +154 -0
  258. package/packages/chili-core/src/snapType.ts +32 -0
  259. package/packages/chili-core/src/ui/button.ts +16 -0
  260. package/packages/chili-core/src/ui/combobox.ts +27 -0
  261. package/packages/chili-core/src/ui/dialog.ts +7 -0
  262. package/packages/chili-core/src/ui/index.ts +8 -0
  263. package/packages/chili-core/src/ui/ribbon.ts +15 -0
  264. package/packages/chili-core/src/ui/window.ts +13 -0
  265. package/packages/chili-core/src/visual/act.ts +59 -0
  266. package/packages/chili-core/src/visual/cameraController.ts +22 -0
  267. package/packages/chili-core/src/visual/cursorType.ts +4 -0
  268. package/packages/chili-core/src/visual/detectedData.ts +14 -0
  269. package/packages/chili-core/src/visual/eventHandler.ts +15 -0
  270. package/packages/chili-core/src/visual/highlighter.ts +16 -0
  271. package/packages/chili-core/src/visual/index.ts +20 -0
  272. package/packages/chili-core/src/visual/meshExporter.ts +11 -0
  273. package/packages/chili-core/src/visual/meshUtils.ts +276 -0
  274. package/packages/chili-core/src/visual/textGenerator.ts +8 -0
  275. package/packages/chili-core/src/visual/view.ts +80 -0
  276. package/packages/chili-core/src/visual/viewGizmo.ts +8 -0
  277. package/packages/chili-core/src/visual/viewport.ts +10 -0
  278. package/packages/chili-core/src/visual/visual.ts +24 -0
  279. package/packages/chili-core/src/visual/visualContext.ts +29 -0
  280. package/packages/chili-core/src/visual/visualFactory.ts +10 -0
  281. package/packages/chili-core/src/visual/visualObject.ts +25 -0
  282. package/packages/chili-core/src/visual/visualShape.ts +30 -0
  283. package/packages/chili-core/test/binding.test.ts +95 -0
  284. package/packages/chili-core/test/boundingBox.test.ts +60 -0
  285. package/packages/chili-core/test/collection.test.ts +53 -0
  286. package/packages/chili-core/test/history.test.ts +42 -0
  287. package/packages/chili-core/test/line.test.ts +75 -0
  288. package/packages/chili-core/test/linesegment.test.ts +98 -0
  289. package/packages/chili-core/test/linkedList.test.ts +82 -0
  290. package/packages/chili-core/test/math.test.ts +34 -0
  291. package/packages/chili-core/test/matrix.test.ts +129 -0
  292. package/packages/chili-core/test/node.test.ts +122 -0
  293. package/packages/chili-core/test/nodeList.test.ts +247 -0
  294. package/packages/chili-core/test/observer.test.ts +91 -0
  295. package/packages/chili-core/test/plane.test.ts +31 -0
  296. package/packages/chili-core/test/quaternion.test.ts +14 -0
  297. package/packages/chili-core/test/result.test.ts +24 -0
  298. package/packages/chili-core/test/serializer.test.ts +58 -0
  299. package/packages/chili-core/test/snapType.test.ts +10 -0
  300. package/packages/chili-core/test/task.test.ts +41 -0
  301. package/packages/chili-core/test/testDocument.ts +70 -0
  302. package/packages/chili-core/test/transaction.test.ts +42 -0
  303. package/packages/chili-core/test/visual.test.ts +42 -0
  304. package/packages/chili-core/test/xyz.test.ts +260 -0
  305. package/packages/chili-geo/package.json +9 -0
  306. package/packages/chili-geo/src/index.ts +4 -0
  307. package/packages/chili-geo/src/utils.ts +113 -0
  308. package/packages/chili-i18n/package.json +9 -0
  309. package/packages/chili-i18n/src/en.ts +270 -0
  310. package/packages/chili-i18n/src/index.ts +8 -0
  311. package/packages/chili-i18n/src/pt-br.ts +67 -0
  312. package/packages/chili-i18n/src/zh-cn.ts +269 -0
  313. package/packages/chili-storage/package.json +9 -0
  314. package/packages/chili-storage/src/index.ts +4 -0
  315. package/packages/chili-storage/src/indexedDBStorage.ts +150 -0
  316. package/packages/chili-three/package.json +13 -0
  317. package/packages/chili-three/src/cameraController.ts +335 -0
  318. package/packages/chili-three/src/common.ts +65 -0
  319. package/packages/chili-three/src/constants.ts +12 -0
  320. package/packages/chili-three/src/highlightable.ts +13 -0
  321. package/packages/chili-three/src/index.ts +4 -0
  322. package/packages/chili-three/src/meshExporter.ts +69 -0
  323. package/packages/chili-three/src/outlinePass.js +340 -0
  324. package/packages/chili-three/src/texture_points.jpg +0 -0
  325. package/packages/chili-three/src/threeGeometry.ts +207 -0
  326. package/packages/chili-three/src/threeGeometryFactory.ts +120 -0
  327. package/packages/chili-three/src/threeHelper.ts +174 -0
  328. package/packages/chili-three/src/threeHighlighter.ts +257 -0
  329. package/packages/chili-three/src/threeView.module.css +39 -0
  330. package/packages/chili-three/src/threeView.ts +669 -0
  331. package/packages/chili-three/src/threeViewEventHandler.ts +193 -0
  332. package/packages/chili-three/src/threeVisual.ts +92 -0
  333. package/packages/chili-three/src/threeVisualContext.ts +435 -0
  334. package/packages/chili-three/src/threeVisualFactory.ts +12 -0
  335. package/packages/chili-three/src/threeVisualObject.ts +442 -0
  336. package/packages/chili-three/src/viewGizmo.ts +305 -0
  337. package/packages/chili-three/test/cameraControls.ts +10 -0
  338. package/packages/chili-three/test/testDocument.ts +68 -0
  339. package/packages/chili-three/test/testEdge.ts +171 -0
  340. package/packages/chili-three/test/testView.ts +78 -0
  341. package/packages/chili-three/test/three.test.ts +44 -0
  342. package/packages/chili-three/test/viewGizmo.ts +12 -0
  343. package/packages/chili-ui/package.json +12 -0
  344. package/packages/chili-ui/src/cursor/draw.cur +0 -0
  345. package/packages/chili-ui/src/cursor/index.ts +17 -0
  346. package/packages/chili-ui/src/dialog.module.css +63 -0
  347. package/packages/chili-ui/src/dialog.ts +42 -0
  348. package/packages/chili-ui/src/editor.module.css +83 -0
  349. package/packages/chili-ui/src/editor.ts +142 -0
  350. package/packages/chili-ui/src/home/home.module.css +301 -0
  351. package/packages/chili-ui/src/home/home.ts +243 -0
  352. package/packages/chili-ui/src/home/index.ts +4 -0
  353. package/packages/chili-ui/src/home/languageSelector.ts +27 -0
  354. package/packages/chili-ui/src/home/navigation3DSelector.ts +27 -0
  355. package/packages/chili-ui/src/home/themeSelector.ts +34 -0
  356. package/packages/chili-ui/src/index.ts +5 -0
  357. package/packages/chili-ui/src/mainWindow.module.css +144 -0
  358. package/packages/chili-ui/src/mainWindow.ts +154 -0
  359. package/packages/chili-ui/src/okCancel.module.css +54 -0
  360. package/packages/chili-ui/src/okCancel.ts +58 -0
  361. package/packages/chili-ui/src/permanent.module.css +44 -0
  362. package/packages/chili-ui/src/permanent.ts +31 -0
  363. package/packages/chili-ui/src/project/index.ts +4 -0
  364. package/packages/chili-ui/src/project/projectView.module.css +37 -0
  365. package/packages/chili-ui/src/project/projectView.ts +77 -0
  366. package/packages/chili-ui/src/project/toolBar.module.css +16 -0
  367. package/packages/chili-ui/src/project/toolBar.ts +73 -0
  368. package/packages/chili-ui/src/project/tree/index.ts +5 -0
  369. package/packages/chili-ui/src/project/tree/tree.module.css +16 -0
  370. package/packages/chili-ui/src/project/tree/tree.ts +265 -0
  371. package/packages/chili-ui/src/project/tree/treeItem.module.css +21 -0
  372. package/packages/chili-ui/src/project/tree/treeItem.ts +89 -0
  373. package/packages/chili-ui/src/project/tree/treeItemGroup.module.css +33 -0
  374. package/packages/chili-ui/src/project/tree/treeItemGroup.ts +85 -0
  375. package/packages/chili-ui/src/project/tree/treeModel.module.css +11 -0
  376. package/packages/chili-ui/src/project/tree/treeModel.ts +20 -0
  377. package/packages/chili-ui/src/property/check.ts +39 -0
  378. package/packages/chili-ui/src/property/colorPorperty.module.css +6 -0
  379. package/packages/chili-ui/src/property/colorProperty.ts +63 -0
  380. package/packages/chili-ui/src/property/common.module.css +14 -0
  381. package/packages/chili-ui/src/property/index.ts +4 -0
  382. package/packages/chili-ui/src/property/input.module.css +19 -0
  383. package/packages/chili-ui/src/property/input.ts +140 -0
  384. package/packages/chili-ui/src/property/material/index.ts +5 -0
  385. package/packages/chili-ui/src/property/material/materialDataContent.ts +44 -0
  386. package/packages/chili-ui/src/property/material/materialEditor.module.css +98 -0
  387. package/packages/chili-ui/src/property/material/materialEditor.ts +147 -0
  388. package/packages/chili-ui/src/property/material/textureEditor.module.css +46 -0
  389. package/packages/chili-ui/src/property/material/textureEditor.ts +61 -0
  390. package/packages/chili-ui/src/property/materialProperty.module.css +30 -0
  391. package/packages/chili-ui/src/property/materialProperty.ts +86 -0
  392. package/packages/chili-ui/src/property/matrixProperty.ts +147 -0
  393. package/packages/chili-ui/src/property/propertyBase.module.css +3 -0
  394. package/packages/chili-ui/src/property/propertyBase.ts +14 -0
  395. package/packages/chili-ui/src/property/propertyView.module.css +36 -0
  396. package/packages/chili-ui/src/property/propertyView.ts +115 -0
  397. package/packages/chili-ui/src/property/utils.ts +48 -0
  398. package/packages/chili-ui/src/ribbon/commandContext.module.css +73 -0
  399. package/packages/chili-ui/src/ribbon/commandContext.ts +239 -0
  400. package/packages/chili-ui/src/ribbon/index.ts +4 -0
  401. package/packages/chili-ui/src/ribbon/ribbon.module.css +286 -0
  402. package/packages/chili-ui/src/ribbon/ribbon.ts +288 -0
  403. package/packages/chili-ui/src/ribbon/ribbonButton.module.css +75 -0
  404. package/packages/chili-ui/src/ribbon/ribbonButton.ts +88 -0
  405. package/packages/chili-ui/src/ribbon/ribbonData.ts +66 -0
  406. package/packages/chili-ui/src/ribbon/ribbonStack.module.css +6 -0
  407. package/packages/chili-ui/src/ribbon/ribbonStack.ts +13 -0
  408. package/packages/chili-ui/src/ribbon/ribbonToggleButton.module.css +3 -0
  409. package/packages/chili-ui/src/ribbon/ribbonToggleButton.ts +6 -0
  410. package/packages/chili-ui/src/statusbar/index.ts +4 -0
  411. package/packages/chili-ui/src/statusbar/snapConfig.module.css +25 -0
  412. package/packages/chili-ui/src/statusbar/snapConfig.ts +92 -0
  413. package/packages/chili-ui/src/statusbar/statusbar.module.css +28 -0
  414. package/packages/chili-ui/src/statusbar/statusbar.ts +54 -0
  415. package/packages/chili-ui/src/toast/index.ts +4 -0
  416. package/packages/chili-ui/src/toast/toast.module.css +27 -0
  417. package/packages/chili-ui/src/toast/toast.ts +39 -0
  418. package/packages/chili-ui/src/viewport/flyout/flyout.module.css +9 -0
  419. package/packages/chili-ui/src/viewport/flyout/flyout.ts +77 -0
  420. package/packages/chili-ui/src/viewport/flyout/index.ts +6 -0
  421. package/packages/chili-ui/src/viewport/flyout/input.module.css +21 -0
  422. package/packages/chili-ui/src/viewport/flyout/input.ts +89 -0
  423. package/packages/chili-ui/src/viewport/flyout/tip.module.css +21 -0
  424. package/packages/chili-ui/src/viewport/flyout/tip.ts +45 -0
  425. package/packages/chili-ui/src/viewport/index.ts +4 -0
  426. package/packages/chili-ui/src/viewport/layoutViewport.module.css +21 -0
  427. package/packages/chili-ui/src/viewport/layoutViewport.ts +76 -0
  428. package/packages/chili-ui/src/viewport/viewport.module.css +179 -0
  429. package/packages/chili-ui/src/viewport/viewport.ts +296 -0
  430. package/packages/chili-vis/package.json +9 -0
  431. package/packages/chili-vis/src/index.ts +7 -0
  432. package/packages/chili-vis/src/nodeSelectionEventHandler.ts +122 -0
  433. package/packages/chili-vis/src/selectionEventHandler.ts +145 -0
  434. package/packages/chili-vis/src/shapeSelectionEventHandler.ts +176 -0
  435. package/packages/chili-vis/src/viewUtils.ts +64 -0
  436. package/packages/chili-wasm/lib/chili-wasm.d.ts +827 -0
  437. package/packages/chili-wasm/lib/chili-wasm.js +5275 -0
  438. package/packages/chili-wasm/lib/chili-wasm.wasm +0 -0
  439. package/packages/chili-wasm/package.json +10 -0
  440. package/packages/chili-wasm/src/converter.ts +124 -0
  441. package/packages/chili-wasm/src/curve.ts +589 -0
  442. package/packages/chili-wasm/src/factory.ts +331 -0
  443. package/packages/chili-wasm/src/geometry.ts +51 -0
  444. package/packages/chili-wasm/src/helper.ts +435 -0
  445. package/packages/chili-wasm/src/index.ts +5 -0
  446. package/packages/chili-wasm/src/mesher.ts +114 -0
  447. package/packages/chili-wasm/src/shape.ts +481 -0
  448. package/packages/chili-wasm/src/surface.ts +510 -0
  449. package/packages/chili-wasm/src/wasm.ts +13 -0
  450. package/packages/chili-web/package.json +9 -0
  451. package/packages/chili-web/src/index.ts +33 -0
  452. package/packages/chili-web/src/loading.ts +67 -0
  453. package/packages/global.d.ts +31 -0
  454. package/public/favicon.svg +10 -0
  455. package/public/fonts/fzhei.json +46120 -0
  456. package/public/iconfont.js +1 -0
  457. package/public/images/wechat.jpg +0 -0
  458. package/public/index.css +13 -0
  459. package/public/index.html +24 -0
  460. package/rspack.config.ts +93 -0
  461. package/rstest.config.ts +27 -0
  462. package/screenshots/screenshot.png +0 -0
  463. package/scripts/add_copyright.mjs +59 -0
  464. package/scripts/build-npm.mjs +105 -0
  465. package/scripts/common.mjs +24 -0
  466. package/scripts/release.mjs +92 -0
  467. package/scripts/restore-package-json.mjs +27 -0
  468. package/scripts/setup_wasm_deps.mjs +97 -0
  469. package/scripts/update-package-json.mjs +27 -0
  470. package/tsconfig.build.json +14 -0
  471. package/tsconfig.build.tsbuildinfo +1 -0
  472. package/tsconfig.json +19 -0
@@ -0,0 +1,154 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ import type { IApplication } from "../application";
5
+ import { type AsyncController, type IDisposable, Observable, PubSub } from "../foundation";
6
+ import { Property } from "../property";
7
+
8
+ export interface ICommand {
9
+ execute(application: IApplication): Promise<void>;
10
+ }
11
+
12
+ export interface ICanclableCommand extends ICommand, IDisposable {
13
+ cancel(): Promise<void>;
14
+ }
15
+
16
+ export namespace ICommand {
17
+ export function isCancelableCommand(command: ICommand): command is ICanclableCommand {
18
+ return "cancel" in command;
19
+ }
20
+ }
21
+
22
+ export abstract class CancelableCommand extends Observable implements ICanclableCommand {
23
+ private static readonly _propertiesCache: Map<string, any> = new Map(); // 所有命令共享
24
+ protected readonly disposeStack: Set<IDisposable> = new Set();
25
+
26
+ private _isCompleted: boolean = false;
27
+ get isCompleted() {
28
+ return this._isCompleted;
29
+ }
30
+
31
+ private _isCanceled: boolean = false;
32
+ get isCanceled() {
33
+ return this._isCanceled;
34
+ }
35
+
36
+ private _application: IApplication | undefined;
37
+ get application() {
38
+ if (!this._application) {
39
+ throw new Error("application is not set");
40
+ }
41
+ return this._application;
42
+ }
43
+
44
+ get document() {
45
+ return this.application.activeView?.document!;
46
+ }
47
+
48
+ #controller?: AsyncController;
49
+ protected get controller() {
50
+ return this.#controller;
51
+ }
52
+ protected set controller(value: AsyncController | undefined) {
53
+ if (this.#controller === value) return;
54
+ this.#controller?.dispose();
55
+ this.#controller = value;
56
+ }
57
+
58
+ @Property.define("common.cancel")
59
+ async cancel() {
60
+ this._isCanceled = true;
61
+
62
+ this.controller?.cancel();
63
+ while (!this._isCompleted) {
64
+ await new Promise((r) => setTimeout(r, 30));
65
+ }
66
+ }
67
+
68
+ @Property.define("option.command.repeat")
69
+ get repeatOperation() {
70
+ return this.getPrivateValue("repeatOperation", false);
71
+ }
72
+
73
+ set repeatOperation(value: boolean) {
74
+ this.setProperty("repeatOperation", value);
75
+ }
76
+
77
+ protected _isRestarting: boolean = false;
78
+ protected async restart() {
79
+ this._isRestarting = true;
80
+ await this.cancel();
81
+ }
82
+
83
+ protected onRestarting() {}
84
+
85
+ async execute(application: IApplication): Promise<void> {
86
+ if (!application.activeView?.document) return;
87
+ this._application = application;
88
+
89
+ await Promise.try(async () => {
90
+ this.beforeExecute();
91
+
92
+ await this.executeAsync();
93
+
94
+ while (this._isRestarting || (!this.checkCanceled() && this.repeatOperation)) {
95
+ this._isRestarting = false;
96
+
97
+ this.onRestarting();
98
+ await this.executeAsync();
99
+ }
100
+ }).finally(() => {
101
+ this.afterExecute();
102
+ });
103
+ }
104
+
105
+ protected checkCanceled() {
106
+ if (this.isCanceled) {
107
+ return true;
108
+ }
109
+
110
+ if (this.controller?.result?.status === "cancel") {
111
+ return true;
112
+ }
113
+
114
+ return false;
115
+ }
116
+
117
+ protected abstract executeAsync(): Promise<void>;
118
+
119
+ protected beforeExecute() {
120
+ this.readProperties();
121
+ PubSub.default.pub("openCommandContext", this);
122
+ }
123
+
124
+ protected afterExecute() {
125
+ this.saveProperties();
126
+ PubSub.default.pub("closeCommandContext");
127
+ this.controller?.dispose();
128
+ this.disposeStack.forEach((x) => x.dispose());
129
+ this.disposeStack.clear();
130
+ this._isCompleted = true;
131
+ }
132
+
133
+ private readProperties() {
134
+ Property.getProperties(this).forEach((x) => {
135
+ const key = this.cacheKeyOfProperty(x);
136
+ if (CancelableCommand._propertiesCache.has(key)) {
137
+ this.setPrivateValue(key as keyof this, CancelableCommand._propertiesCache.get(key));
138
+ }
139
+ });
140
+ }
141
+
142
+ private saveProperties() {
143
+ Property.getProperties(this).forEach((x) => {
144
+ const key = this.cacheKeyOfProperty(x);
145
+ const prop = (this as any)[key];
146
+ if (typeof prop === "function") return;
147
+ CancelableCommand._propertiesCache.set(key, prop);
148
+ });
149
+ }
150
+
151
+ private cacheKeyOfProperty(property: Property) {
152
+ return property.name;
153
+ }
154
+ }
@@ -0,0 +1,8 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ import type { I18nKeys } from "../i18n";
5
+
6
+ export type CommandKeys = {
7
+ [P in I18nKeys]: P extends `command.${infer K}` ? K : never;
8
+ }[I18nKeys];
@@ -0,0 +1,43 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ import type { Binding } from "../foundation";
5
+ import type { ICommand } from "./command";
6
+ import type { CommandKeys } from "./commandKeys";
7
+
8
+ const commandRegistry = new Map<string, CommandConstructor>();
9
+
10
+ export type CommandConstructor = new (...args: any[]) => ICommand;
11
+
12
+ export interface CommandData {
13
+ key: CommandKeys;
14
+ icon: string;
15
+ toggle?: Binding;
16
+ helpText?: string;
17
+ helpUrl?: string;
18
+ isApplicationCommand?: boolean;
19
+ }
20
+
21
+ export function command<T extends CommandConstructor>(metadata: CommandData) {
22
+ return (ctor: T) => {
23
+ commandRegistry.set(metadata.key, ctor);
24
+ ctor.prototype.data = metadata;
25
+ };
26
+ }
27
+
28
+ export namespace Command {
29
+ export function getData(target: string | ICommand | CommandConstructor): CommandData | undefined {
30
+ if (typeof target === "string") {
31
+ const ctor = commandRegistry.get(target);
32
+ return ctor?.prototype.data;
33
+ }
34
+
35
+ const prototype = typeof target === "function" ? target.prototype : Object.getPrototypeOf(target);
36
+
37
+ return prototype.data;
38
+ }
39
+
40
+ export function get(name: CommandKeys): CommandConstructor | undefined {
41
+ return commandRegistry.get(name);
42
+ }
43
+ }
@@ -0,0 +1,6 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ export * from "./command";
5
+ export * from "./commandKeys";
6
+ export * from "./decarator";
@@ -0,0 +1,145 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ import { ObjectStorage, Observable } from "./foundation";
5
+ import { I18n } from "./i18n";
6
+ import { type SerializedProperties, Serializer } from "./serialize";
7
+ import { ObjectSnapType } from "./snapType";
8
+
9
+ export class VisualItemConfig extends Observable {
10
+ defaultFaceColor = 0xdedede;
11
+ highlightEdgeColor = 0x33ff33;
12
+ highlightFaceColor = 0x99ff00;
13
+ selectedEdgeColor = 0x33ff33;
14
+ selectedFaceColor = 0x33ff33;
15
+ editVertexSize = 7;
16
+ editVertexColor = 0x33ff33;
17
+ hintVertexSize = 5;
18
+ hintVertexColor = 0x33ff33;
19
+ trackingVertexSize = 7;
20
+ trackingVertexColor = 0x33ff33;
21
+ temporaryVertexSize = 5;
22
+ temporaryVertexColor = 0x33ff33;
23
+ temporaryEdgeColor = 0x33ff33;
24
+
25
+ get defaultEdgeColor() {
26
+ return this.getPrivateValue("defaultEdgeColor", 0x333333);
27
+ }
28
+ set defaultEdgeColor(value: number) {
29
+ this.setProperty("defaultEdgeColor", value);
30
+ }
31
+
32
+ applyTheme(theme: "light" | "dark") {
33
+ this.defaultEdgeColor = theme === "light" ? 0x333333 : 0xeeeeee;
34
+ }
35
+ }
36
+
37
+ export const VisualConfig = new VisualItemConfig();
38
+
39
+ export class Config extends Observable {
40
+ static readonly #instance = new Config();
41
+
42
+ static get instance() {
43
+ return Config.#instance;
44
+ }
45
+
46
+ readonly SnapDistance: number = 5;
47
+
48
+ get snapType() {
49
+ return this.getPrivateValue(
50
+ "snapType",
51
+ ObjectSnapType.midPoint |
52
+ ObjectSnapType.endPoint |
53
+ ObjectSnapType.center |
54
+ ObjectSnapType.perpendicular |
55
+ ObjectSnapType.intersection |
56
+ ObjectSnapType.nearest,
57
+ );
58
+ }
59
+ set snapType(snapType: ObjectSnapType) {
60
+ this.setProperty("snapType", snapType);
61
+ }
62
+
63
+ get enableSnapTracking() {
64
+ return this.getPrivateValue("enableSnapTracking", true);
65
+ }
66
+ set enableSnapTracking(value: boolean) {
67
+ this.setProperty("enableSnapTracking", value);
68
+ }
69
+
70
+ get enableSnap() {
71
+ return this.getPrivateValue("enableSnap", true);
72
+ }
73
+ set enableSnap(value: boolean) {
74
+ this.setProperty("enableSnap", value);
75
+ }
76
+
77
+ get dynamicWorkplane() {
78
+ return this.getPrivateValue("dynamicWorkplane", true);
79
+ }
80
+ set dynamicWorkplane(value: boolean) {
81
+ this.setProperty("dynamicWorkplane", value);
82
+ }
83
+
84
+ @Serializer.serialze()
85
+ get language() {
86
+ return this.getPrivateValue("language", I18n.defaultLanguage());
87
+ }
88
+ set language(value: string) {
89
+ this.setProperty("language", value);
90
+ }
91
+
92
+ @Serializer.serialze()
93
+ get navigation3DIndex() {
94
+ return this.getPrivateValue("navigation3DIndex", 0);
95
+ }
96
+ set navigation3DIndex(value: number) {
97
+ this.setProperty("navigation3DIndex", value);
98
+ }
99
+
100
+ @Serializer.serialze()
101
+ get themeMode() {
102
+ return this.getPrivateValue("themeMode", "system");
103
+ }
104
+ set themeMode(value: "light" | "dark" | "system") {
105
+ this.setProperty("themeMode", value, () => {
106
+ if (value === "system") {
107
+ VisualConfig.applyTheme(
108
+ window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light",
109
+ );
110
+ } else {
111
+ VisualConfig.applyTheme(value);
112
+ }
113
+ });
114
+ }
115
+
116
+ #storageKey: string = "config";
117
+ get storageKey() {
118
+ return this.#storageKey;
119
+ }
120
+ private set storageKey(value: string) {
121
+ this.#storageKey = value;
122
+ }
123
+
124
+ private constructor() {
125
+ super();
126
+ }
127
+
128
+ init(storageKey: string) {
129
+ this.#storageKey = storageKey;
130
+ this.readFromStorage();
131
+ }
132
+
133
+ readFromStorage() {
134
+ const data = ObjectStorage.default.value<SerializedProperties<Config>>(this.storageKey);
135
+ for (const key in data) {
136
+ const thisKey = key as keyof Config;
137
+ this.setPrivateValue(thisKey, (data as any)[key]);
138
+ }
139
+ }
140
+
141
+ saveToStorage() {
142
+ const json = Serializer.serializeProperties(this);
143
+ ObjectStorage.default.setValue(this.storageKey, json);
144
+ }
145
+ }
@@ -0,0 +1,8 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ export class Constants {
5
+ static readonly DBName = "chili3d-db";
6
+ static readonly DocumentTable = "documents";
7
+ static readonly RecentTable = "recents";
8
+ }
@@ -0,0 +1,12 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ import type { IDocument } from "./document";
5
+ import type { VisualNode } from "./model";
6
+
7
+ export interface IDataExchange {
8
+ importFormats(): string[];
9
+ exportFormats(): string[];
10
+ import(document: IDocument, files: FileList | File[]): Promise<void>;
11
+ export(type: string, nodes: VisualNode[]): Promise<BlobPart[] | undefined>;
12
+ }
@@ -0,0 +1,25 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ import type { IApplication } from "./application";
5
+ import type { History, IDisposable, IPropertyChanged, ObservableCollection } from "./foundation";
6
+ import type { ModelManager } from "./modelManager";
7
+ import type { ISelection } from "./selection";
8
+ import type { ISerialize, Serialized } from "./serialize";
9
+ import type { Act, IVisual } from "./visual";
10
+
11
+ export const DOCUMENT_FILE_EXTENSION = ".cd";
12
+
13
+ export interface IDocument extends IPropertyChanged, IDisposable, ISerialize {
14
+ readonly selection: ISelection;
15
+ readonly id: string;
16
+ readonly history: History;
17
+ readonly visual: IVisual;
18
+ readonly application: IApplication;
19
+ readonly modelManager: ModelManager;
20
+ name: string;
21
+ acts: ObservableCollection<Act>;
22
+ save(): Promise<void>;
23
+ close(): Promise<void>;
24
+ serialize(): Serialized;
25
+ }
@@ -0,0 +1,12 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ import type { IView } from "./visual";
5
+
6
+ export interface IEditor {
7
+ active(): boolean;
8
+ deactive(): boolean;
9
+ onPointerMove(view: IView, e: PointerEvent): void;
10
+ onPointerDown(view: IView, e: PointerEvent): void;
11
+ onPointerUp(view: IView, e: PointerEvent): void;
12
+ }
@@ -0,0 +1,55 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ import type { IDisposable } from "./disposable";
5
+
6
+ export interface AsyncResult {
7
+ status: "success" | "fail" | "cancel";
8
+ message?: string;
9
+ }
10
+
11
+ export class AsyncController implements IDisposable {
12
+ private readonly _failListeners = new Set<(state: AsyncResult) => void>();
13
+ private readonly _successListeners = new Set<(state: AsyncResult) => void>();
14
+ private _result: AsyncResult | undefined;
15
+
16
+ get result() {
17
+ return this._result;
18
+ }
19
+
20
+ readonly fail = (message?: string) => {
21
+ this.notifyListeners(this._failListeners, "fail", message);
22
+ };
23
+
24
+ readonly cancel = (message?: string) => {
25
+ this.notifyListeners(this._failListeners, "cancel", message);
26
+ };
27
+
28
+ readonly success = (message?: string) => {
29
+ this.notifyListeners(this._successListeners, "success", message);
30
+ };
31
+
32
+ private notifyListeners(
33
+ listeners: Set<(result: AsyncResult) => void>,
34
+ status: AsyncResult["status"],
35
+ message?: string,
36
+ ) {
37
+ if (this._result === undefined) {
38
+ this._result = { status, message };
39
+ listeners.forEach((listener) => listener(this._result!));
40
+ }
41
+ }
42
+
43
+ onCancelled(listener: (result: AsyncResult) => void): void {
44
+ this._failListeners.add(listener);
45
+ }
46
+
47
+ onCompleted(listener: (result: AsyncResult) => void): void {
48
+ this._successListeners.add(listener);
49
+ }
50
+
51
+ dispose() {
52
+ this._failListeners.clear();
53
+ this._successListeners.clear();
54
+ }
55
+ }
@@ -0,0 +1,132 @@
1
+ // Part of the Chili3d Project, under the AGPL-3.0 License.
2
+ // See LICENSE file in the project root for full license information.
3
+
4
+ import type { IConverter } from "./converter";
5
+ import type { IPropertyChanged } from "./observer";
6
+
7
+ const registry = new FinalizationRegistry((binding: PathBinding<IPropertyChanged>) => {
8
+ binding.removeBinding();
9
+ });
10
+
11
+ /**
12
+ * Bind the property chain as a path, separated by dots
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const binding = new PathBinding(source, "a.b.c");
17
+ * binding.setBinding(element, "property");
18
+ * ```
19
+ */
20
+ export class PathBinding<T extends IPropertyChanged = IPropertyChanged> {
21
+ private _target?: { element: WeakRef<object>; property: PropertyKey };
22
+ private _oldPathObjects?: { source: IPropertyChanged; property: string }[];
23
+ private _actualSource?: { source: IPropertyChanged; property: string };
24
+
25
+ constructor(
26
+ readonly source: T,
27
+ readonly path: string,
28
+ public converter?: IConverter,
29
+ ) {}
30
+
31
+ setBinding<U extends object>(element: U, property: keyof U) {
32
+ if (this._target) throw new Error("Binding already set");
33
+ this._target = { element: new WeakRef(element), property };
34
+ registry.register(element, this);
35
+ this.addPropertyChangedHandler();
36
+ }
37
+
38
+ removeBinding() {
39
+ const element = this._target?.element.deref();
40
+ if (element) registry.unregister(element);
41
+ this._target = undefined;
42
+ this.removePropertyChangedHandler();
43
+ }
44
+
45
+ private readonly handleAllPathPropertyChanged = (property: string, source: any) => {
46
+ if (this.shouldUpdateHandler(property, source)) {
47
+ this.removePropertyChangedHandler();
48
+ this.addPropertyChangedHandler();
49
+ }
50
+ };
51
+
52
+ private readonly handlePropertyChanged = (property: string, source: any) => {
53
+ if (this.path.endsWith(property) && this._target) {
54
+ this.setValue(source, property);
55
+ }
56
+ };
57
+
58
+ private shouldUpdateHandler(property: string, source: any) {
59
+ if (this._oldPathObjects === undefined) {
60
+ return true;
61
+ }
62
+
63
+ if (
64
+ this._oldPathObjects.some((element) => element.property === property && element.source === source)
65
+ ) {
66
+ return true;
67
+ }
68
+
69
+ if (!this._actualSource) {
70
+ return this.path.includes(property);
71
+ }
72
+
73
+ return false;
74
+ }
75
+
76
+ private addPropertyChangedHandler() {
77
+ const props = this.path.split(".");
78
+ let source: any = this.source;
79
+ this._oldPathObjects = [];
80
+ for (let i = 0; i < props.length; i++) {
81
+ if (!source || !(props[i] in source)) break;
82
+
83
+ const sourceProperty = { source, property: props[i] };
84
+ if (i === props.length - 1) {
85
+ this.setValue(source, props[i]);
86
+ this._actualSource = sourceProperty;
87
+ source.onPropertyChanged(this.handlePropertyChanged);
88
+ break;
89
+ }
90
+
91
+ source.onPropertyChanged(this.handleAllPathPropertyChanged);
92
+ this._oldPathObjects.push(sourceProperty);
93
+ source = source[props[i]];
94
+ }
95
+ }
96
+
97
+ private removePropertyChangedHandler() {
98
+ if (!this._oldPathObjects) return;
99
+ this._oldPathObjects.forEach((element) =>
100
+ element.source.removePropertyChanged(this.handleAllPathPropertyChanged),
101
+ );
102
+ this._actualSource?.source.removePropertyChanged(this.handlePropertyChanged);
103
+ this._actualSource = undefined;
104
+ this._oldPathObjects = undefined;
105
+ }
106
+
107
+ private setValue(source: any, property: string) {
108
+ if (!this._target) return;
109
+ const element = this._target.element.deref();
110
+ if (!element) return;
111
+
112
+ const value = source[property];
113
+ if (this.converter) {
114
+ const converted = this.converter.convert(value);
115
+ if (converted.isOk) (element as any)[this._target.property] = converted.value;
116
+ } else {
117
+ (element as any)[this._target.property] = value;
118
+ }
119
+ }
120
+
121
+ getPropertyValue() {
122
+ return this._actualSource
123
+ ? (this._actualSource.source as any)[this._actualSource.property]
124
+ : undefined;
125
+ }
126
+ }
127
+
128
+ export class Binding<T extends IPropertyChanged = IPropertyChanged> extends PathBinding<T> {
129
+ constructor(source: T, path: keyof T, converter?: IConverter) {
130
+ super(source, path.toString(), converter);
131
+ }
132
+ }