@threekit-tools/treble 0.0.93 → 0.0.94-next-01

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 (297) hide show
  1. package/dist/Treble/Treble.d.ts +2 -2
  2. package/dist/Treble/Treble.js +5 -6
  3. package/dist/Treble/index.d.ts +1 -1
  4. package/dist/Treble/index.js +1 -1
  5. package/dist/Treble/{snapshots.d.ts → snapshot.d.ts} +1 -1
  6. package/dist/Treble/{snapshots.js → snapshot.js} +1 -1
  7. package/dist/Treble/wishlist.d.ts +1 -1
  8. package/dist/Treble/wishlist.js +1 -1
  9. package/dist/api/catalog.js +1 -1
  10. package/dist/api/configurations.d.ts +0 -1
  11. package/dist/api/configurations.js +3 -10
  12. package/dist/api/datatables.js +1 -1
  13. package/dist/api/index.d.ts +2 -2
  14. package/dist/api/index.js +2 -2
  15. package/dist/api/orders.js +1 -1
  16. package/dist/api/price.js +1 -1
  17. package/dist/api/products.d.ts +4 -0
  18. package/dist/api/{assets.js → products.js} +33 -12
  19. package/dist/components/AttributeTitle/index.d.ts +2 -2
  20. package/dist/components/AttributeValue/index.d.ts +2 -2
  21. package/dist/components/BreatheAnimation/index.js +1 -1
  22. package/dist/components/Button/index.d.ts +3 -3
  23. package/dist/components/Cards/index.d.ts +3 -3
  24. package/dist/components/DevTools/index.d.ts +2 -2
  25. package/dist/components/DraggableHint/draggableIndicator.styles.d.ts +1 -1
  26. package/dist/components/DraggableHint/index.d.ts +2 -2
  27. package/dist/components/Dropdown/index.d.ts +3 -3
  28. package/dist/components/FlatForm/index.d.ts +2 -2
  29. package/dist/components/FormComponentDescription/index.d.ts +1 -1
  30. package/dist/components/FormComponentTitle/index.d.ts +1 -1
  31. package/dist/components/Player/index.d.ts +9 -9
  32. package/dist/components/PlayerLoadingCircular/index.d.ts +2 -2
  33. package/dist/components/PlayerLoadingSpinner/index.d.ts +2 -2
  34. package/dist/components/PlayerLoadingSpinner/playerLoadingSpinner.styles.d.ts +1 -1
  35. package/dist/components/ProductDescription/index.d.ts +3 -3
  36. package/dist/components/ProductName/index.d.ts +3 -3
  37. package/dist/components/Share/index.d.ts +2 -2
  38. package/dist/components/Share/index.js +1 -1
  39. package/dist/components/Share/share.styles.d.ts +1 -1
  40. package/dist/components/Snapshots/index.d.ts +2 -2
  41. package/dist/components/Strips/index.d.ts +3 -3
  42. package/dist/components/Swatch/index.d.ts +3 -3
  43. package/dist/components/Switch/index.d.ts +3 -3
  44. package/dist/components/TextInput/index.d.ts +3 -3
  45. package/dist/components/ThreekitProvider/index.d.ts +3 -6
  46. package/dist/components/ThreekitProvider/index.js +2 -27
  47. package/dist/components/Tiles/index.d.ts +3 -3
  48. package/dist/components/TilesGroup/index.d.ts +3 -3
  49. package/dist/components/TotalPrice/index.d.ts +3 -3
  50. package/dist/components/TrebleApp/index.d.ts +3 -3
  51. package/dist/components/TurntableAnimation/index.js +1 -1
  52. package/dist/components/Upload/index.d.ts +3 -3
  53. package/dist/components/Upload/index.js +1 -1
  54. package/dist/components/UploadArea/index.d.ts +3 -3
  55. package/dist/components/UploadArea/index.js +1 -1
  56. package/dist/components/Wishlist/WishlistItem.d.ts +2 -2
  57. package/dist/components/Wishlist/index.d.ts +4 -4
  58. package/dist/components/Wishlist/index.js +1 -1
  59. package/dist/components/Zoom/index.d.ts +6 -6
  60. package/dist/components/containers/formInputContainer.d.ts +2 -2
  61. package/dist/components/formComponents.d.ts +6 -6
  62. package/dist/components/message/index.d.ts +1 -1
  63. package/dist/constants.d.ts +6 -6
  64. package/dist/hooks/useAttribute/index.d.ts +4 -4
  65. package/dist/hooks/useAttribute/index.js +3 -3
  66. package/dist/hooks/useConfigurationLoader/index.js +1 -1
  67. package/dist/hooks/useConfigurator/index.d.ts +3 -3
  68. package/dist/hooks/useConfigurator/index.js +5 -3
  69. package/dist/hooks/useDevTools/index.d.ts +1 -1
  70. package/dist/hooks/useNestedConfigurator/index.d.ts +2 -2
  71. package/dist/hooks/useNestedConfigurator/index.js +4 -5
  72. package/dist/hooks/usePlayer/index.d.ts +1 -1
  73. package/dist/hooks/usePlayerPortal/index.d.ts +1 -1
  74. package/dist/hooks/useProductCache/index.js +1 -1
  75. package/dist/hooks/useResetProduct/index.d.ts +1 -1
  76. package/dist/hooks/useResetProduct/index.js +1 -1
  77. package/dist/hooks/useShare/index.d.ts +1 -1
  78. package/dist/hooks/useShare/index.js +2 -4
  79. package/dist/hooks/useSingleAnimation/index.js +1 -1
  80. package/dist/hooks/useSpaces/SpacesLayout.d.ts +11 -0
  81. package/dist/hooks/useSpaces/SpacesLayout.js +74 -0
  82. package/dist/hooks/useSpaces/SpacesState.d.ts +177 -0
  83. package/dist/hooks/useSpaces/SpacesState.js +1814 -0
  84. package/dist/hooks/useSpaces/constants.d.ts +79 -0
  85. package/dist/hooks/useSpaces/constants.js +130 -0
  86. package/dist/hooks/useSpaces/dataHandlers.d.ts +38 -0
  87. package/dist/hooks/useSpaces/dataHandlers.js +411 -0
  88. package/dist/hooks/useSpaces/draw/clearCanvas.d.ts +2 -0
  89. package/dist/hooks/useSpaces/draw/clearCanvas.js +9 -0
  90. package/dist/hooks/useSpaces/draw/drawBackground.d.ts +2 -0
  91. package/dist/hooks/useSpaces/draw/drawBackground.js +12 -0
  92. package/dist/hooks/useSpaces/draw/drawDimensions.d.ts +3 -0
  93. package/dist/hooks/useSpaces/draw/drawDimensions.js +53 -0
  94. package/dist/hooks/useSpaces/draw/drawDoors.d.ts +9 -0
  95. package/dist/hooks/useSpaces/draw/drawDoors.js +99 -0
  96. package/dist/hooks/useSpaces/draw/drawFloor.d.ts +3 -0
  97. package/dist/hooks/useSpaces/draw/drawFloor.js +36 -0
  98. package/dist/hooks/useSpaces/draw/drawGrid.d.ts +3 -0
  99. package/dist/hooks/useSpaces/draw/drawGrid.js +36 -0
  100. package/dist/hooks/useSpaces/draw/drawGuides.d.ts +3 -0
  101. package/dist/hooks/useSpaces/draw/drawGuides.js +23 -0
  102. package/dist/hooks/useSpaces/draw/drawOpenings.d.ts +9 -0
  103. package/dist/hooks/useSpaces/draw/drawOpenings.js +72 -0
  104. package/dist/hooks/useSpaces/draw/drawVertices.d.ts +8 -0
  105. package/dist/hooks/useSpaces/draw/drawVertices.js +61 -0
  106. package/dist/hooks/useSpaces/draw/drawWalls.d.ts +11 -0
  107. package/dist/hooks/useSpaces/draw/drawWalls.js +90 -0
  108. package/dist/hooks/useSpaces/draw/drawWindows.d.ts +9 -0
  109. package/dist/hooks/useSpaces/draw/drawWindows.js +82 -0
  110. package/dist/hooks/useSpaces/draw/index.d.ts +11 -0
  111. package/dist/hooks/useSpaces/draw/index.js +129 -0
  112. package/dist/hooks/useSpaces/geometry/addThicknessToLine.d.ts +3 -0
  113. package/dist/hooks/useSpaces/geometry/addThicknessToLine.js +13 -0
  114. package/dist/hooks/useSpaces/geometry/areLinesEqual.d.ts +3 -0
  115. package/dist/hooks/useSpaces/geometry/areLinesEqual.js +17 -0
  116. package/dist/hooks/useSpaces/geometry/arePointsEqual.d.ts +3 -0
  117. package/dist/hooks/useSpaces/geometry/arePointsEqual.js +8 -0
  118. package/dist/hooks/useSpaces/geometry/arePointsWithinProximity.d.ts +3 -0
  119. package/dist/hooks/useSpaces/geometry/arePointsWithinProximity.js +11 -0
  120. package/dist/hooks/useSpaces/geometry/closestPointOnLine.d.ts +3 -0
  121. package/dist/hooks/useSpaces/geometry/closestPointOnLine.js +13 -0
  122. package/dist/hooks/useSpaces/geometry/doLinesOverlap.d.ts +2 -0
  123. package/dist/hooks/useSpaces/geometry/doLinesOverlap.js +16 -0
  124. package/dist/hooks/useSpaces/geometry/euclideanMod.d.ts +2 -0
  125. package/dist/hooks/useSpaces/geometry/euclideanMod.js +6 -0
  126. package/dist/hooks/useSpaces/geometry/findLoops.d.ts +6 -0
  127. package/dist/hooks/{useRoomBuilder → useSpaces/geometry}/findLoops.js +31 -13
  128. package/dist/hooks/useSpaces/geometry/getAllLineIntersections.d.ts +6 -0
  129. package/dist/hooks/useSpaces/geometry/getAllLineIntersections.js +23 -0
  130. package/dist/hooks/useSpaces/geometry/getAngleOfLineSegment.d.ts +3 -0
  131. package/dist/hooks/useSpaces/geometry/getAngleOfLineSegment.js +7 -0
  132. package/dist/hooks/useSpaces/geometry/getClosestPointOnLineSegment.d.ts +3 -0
  133. package/dist/hooks/useSpaces/geometry/getClosestPointOnLineSegment.js +17 -0
  134. package/dist/hooks/useSpaces/geometry/getDistanceToLine.d.ts +3 -0
  135. package/dist/hooks/useSpaces/geometry/getDistanceToLine.js +10 -0
  136. package/dist/hooks/useSpaces/geometry/getLengthOfLineSegment.d.ts +3 -0
  137. package/dist/hooks/useSpaces/geometry/getLengthOfLineSegment.js +7 -0
  138. package/dist/hooks/useSpaces/geometry/getLineAtOffsetOnLineSegment.d.ts +3 -0
  139. package/dist/hooks/useSpaces/geometry/getLineAtOffsetOnLineSegment.js +17 -0
  140. package/dist/hooks/useSpaces/geometry/getLineOtherPoint.d.ts +3 -0
  141. package/dist/hooks/useSpaces/geometry/getLineOtherPoint.js +11 -0
  142. package/dist/hooks/useSpaces/geometry/getLineSegmentsIntersection.d.ts +3 -0
  143. package/dist/hooks/useSpaces/geometry/getLineSegmentsIntersection.js +43 -0
  144. package/dist/hooks/useSpaces/geometry/getMidpointOfLineSegment.d.ts +3 -0
  145. package/dist/hooks/useSpaces/geometry/getMidpointOfLineSegment.js +9 -0
  146. package/dist/hooks/useSpaces/geometry/getParallelLineSegmentAtDistance.d.ts +3 -0
  147. package/dist/hooks/useSpaces/geometry/getParallelLineSegmentAtDistance.js +20 -0
  148. package/dist/hooks/useSpaces/geometry/getPointAtOffsetOnLineSegment.d.ts +3 -0
  149. package/dist/hooks/useSpaces/geometry/getPointAtOffsetOnLineSegment.js +11 -0
  150. package/dist/hooks/useSpaces/geometry/getPolygonArea.d.ts +3 -0
  151. package/dist/hooks/useSpaces/geometry/getPolygonArea.js +15 -0
  152. package/dist/hooks/useSpaces/geometry/getQuadrilateralArea.d.ts +3 -0
  153. package/dist/hooks/useSpaces/geometry/getQuadrilateralArea.js +16 -0
  154. package/dist/hooks/useSpaces/geometry/getTangetIntersectionAndOffset.d.ts +6 -0
  155. package/dist/hooks/useSpaces/geometry/getTangetIntersectionAndOffset.js +17 -0
  156. package/dist/hooks/useSpaces/geometry/getTriangleArea.d.ts +3 -0
  157. package/dist/hooks/useSpaces/geometry/getTriangleArea.js +9 -0
  158. package/dist/hooks/useSpaces/geometry/getUnitVectorOfLineSegment.d.ts +3 -0
  159. package/dist/hooks/useSpaces/geometry/getUnitVectorOfLineSegment.js +12 -0
  160. package/dist/hooks/useSpaces/geometry/index.d.ts +30 -0
  161. package/dist/hooks/useSpaces/geometry/index.js +64 -0
  162. package/dist/hooks/useSpaces/geometry/isPointInPolygon.d.ts +3 -0
  163. package/dist/hooks/useSpaces/geometry/isPointInPolygon.js +21 -0
  164. package/dist/hooks/useSpaces/geometry/isPointInQuadrilateral.d.ts +3 -0
  165. package/dist/hooks/useSpaces/geometry/isPointInQuadrilateral.js +25 -0
  166. package/dist/hooks/useSpaces/geometry/orderCoordinatesOnLineSegment.d.ts +3 -0
  167. package/dist/hooks/useSpaces/geometry/orderCoordinatesOnLineSegment.js +11 -0
  168. package/dist/hooks/useSpaces/geometry/splitLineAtOffset.d.ts +3 -0
  169. package/dist/hooks/useSpaces/geometry/splitLineAtOffset.js +12 -0
  170. package/dist/hooks/useSpaces/geometry/splitLineAtPoint.d.ts +3 -0
  171. package/dist/hooks/useSpaces/geometry/splitLineAtPoint.js +9 -0
  172. package/dist/hooks/useSpaces/geometry/splitLineAtPoints.d.ts +3 -0
  173. package/dist/hooks/useSpaces/geometry/splitLineAtPoints.js +28 -0
  174. package/dist/hooks/useSpaces/index.d.ts +95 -0
  175. package/dist/hooks/useSpaces/index.js +625 -0
  176. package/dist/hooks/useSpaces/themes/blueprint.d.ts +3 -0
  177. package/dist/hooks/useSpaces/themes/blueprint.js +96 -0
  178. package/dist/hooks/useSpaces/themes/default.d.ts +3 -0
  179. package/dist/hooks/useSpaces/themes/default.js +96 -0
  180. package/dist/hooks/{useRoomBuilder/themes.d.ts → useSpaces/themes/index.d.ts} +3 -4
  181. package/dist/hooks/useSpaces/themes/index.js +21 -0
  182. package/dist/hooks/useSpaces/themes/light.d.ts +3 -0
  183. package/dist/hooks/useSpaces/themes/light.js +96 -0
  184. package/dist/hooks/useSpaces/types.d.ts +378 -0
  185. package/dist/hooks/useSpaces/types.js +54 -0
  186. package/dist/hooks/useSpaces/validators/areWallsDuplicated.d.ts +3 -0
  187. package/dist/hooks/useSpaces/validators/areWallsDuplicated.js +61 -0
  188. package/dist/hooks/useSpaces/validators/areWallsIntersecting.d.ts +3 -0
  189. package/dist/hooks/useSpaces/validators/areWallsIntersecting.js +42 -0
  190. package/dist/hooks/useSpaces/validators/areWallsOrphaningFeatures.d.ts +3 -0
  191. package/dist/hooks/useSpaces/validators/areWallsOrphaningFeatures.js +52 -0
  192. package/dist/hooks/useSpaces/validators/areWallsTooShort.d.ts +3 -0
  193. package/dist/hooks/useSpaces/validators/areWallsTooShort.js +37 -0
  194. package/dist/hooks/useSpaces/validators/index.d.ts +15 -0
  195. package/dist/hooks/useSpaces/validators/index.js +40 -0
  196. package/dist/hooks/useSpaces/validators/isFeatureCollidingWithExistingFeature.d.ts +3 -0
  197. package/dist/hooks/useSpaces/validators/isFeatureCollidingWithExistingFeature.js +31 -0
  198. package/dist/hooks/useSpaces/validators/isFeatureOutsideWallBounds.d.ts +3 -0
  199. package/dist/hooks/useSpaces/validators/isFeatureOutsideWallBounds.js +19 -0
  200. package/dist/hooks/useSpaces/validators/isLineTooShort.d.ts +3 -0
  201. package/dist/hooks/useSpaces/validators/isLineTooShort.js +26 -0
  202. package/dist/hooks/useSpaces/validators/isVertexLandingOnFeature.d.ts +4 -0
  203. package/dist/hooks/useSpaces/validators/isVertexLandingOnFeature.js +19 -0
  204. package/dist/hooks/useSpaces/validators/isWallEndingOnFeature.d.ts +3 -0
  205. package/dist/hooks/useSpaces/validators/isWallEndingOnFeature.js +19 -0
  206. package/dist/hooks/useSpaces/validators/isWallIntersectingFeature.d.ts +3 -0
  207. package/dist/hooks/useSpaces/validators/isWallIntersectingFeature.js +41 -0
  208. package/dist/hooks/useSpaces/validators/isWallOverlappingExisitingWalls.d.ts +3 -0
  209. package/dist/hooks/useSpaces/validators/isWallOverlappingExisitingWalls.js +54 -0
  210. package/dist/hooks/useSpaces/validators/isWallTooShort.d.ts +3 -0
  211. package/dist/hooks/useSpaces/validators/isWallTooShort.js +10 -0
  212. package/dist/hooks/{useRoomBuilder → useSpaces/validators}/messaging.js +1 -1
  213. package/dist/hooks/useWishlist/index.d.ts +1 -1
  214. package/dist/hooks/useZoom/index.d.ts +1 -1
  215. package/dist/http/index.d.ts +2 -2
  216. package/dist/http/index.js +2 -2
  217. package/dist/http/orders.d.ts +1 -1
  218. package/dist/http/products.d.ts +1 -0
  219. package/dist/http/products.js +12 -0
  220. package/dist/icons/AngleSnapping.d.ts +3 -0
  221. package/dist/icons/AngleSnapping.js +28 -0
  222. package/dist/icons/Boundary.d.ts +3 -0
  223. package/dist/icons/Boundary.js +21 -0
  224. package/dist/icons/Center.d.ts +3 -0
  225. package/dist/icons/Center.js +24 -0
  226. package/dist/icons/Draw.js +3 -3
  227. package/dist/icons/GridSnapping.d.ts +3 -0
  228. package/dist/icons/GridSnapping.js +28 -0
  229. package/dist/icons/LayoutAlt.d.ts +3 -0
  230. package/dist/icons/LayoutAlt.js +21 -0
  231. package/dist/icons/Magnet.d.ts +3 -0
  232. package/dist/icons/Magnet.js +27 -0
  233. package/dist/icons/Player3D.d.ts +3 -0
  234. package/dist/icons/Player3D.js +21 -0
  235. package/dist/icons/RulerBlank.d.ts +3 -0
  236. package/dist/icons/RulerBlank.js +25 -0
  237. package/dist/icons/RulerDetailed.d.ts +3 -0
  238. package/dist/icons/RulerDetailed.js +27 -0
  239. package/dist/icons/Save.d.ts +3 -0
  240. package/dist/icons/Save.js +21 -0
  241. package/dist/icons/Spinner.d.ts +2 -2
  242. package/dist/icons/UnitCm.d.ts +3 -0
  243. package/dist/icons/UnitCm.js +22 -0
  244. package/dist/icons/UnitFeet.d.ts +3 -0
  245. package/dist/icons/UnitFeet.js +22 -0
  246. package/dist/icons/UnitInch.d.ts +3 -0
  247. package/dist/icons/UnitInch.js +22 -0
  248. package/dist/icons/UnitMeter.d.ts +3 -0
  249. package/dist/icons/UnitMeter.js +21 -0
  250. package/dist/icons/Window.js +4 -4
  251. package/dist/icons/index.js +28 -0
  252. package/dist/icons/types.d.ts +1 -1
  253. package/dist/index.d.ts +17 -2
  254. package/dist/index.js +35 -5
  255. package/dist/store/attributes.d.ts +5 -4
  256. package/dist/store/attributes.js +4 -2
  257. package/dist/store/index.d.ts +43 -12
  258. package/dist/store/index.js +3 -1
  259. package/dist/store/price.d.ts +1 -1
  260. package/dist/store/price.js +1 -1
  261. package/dist/store/product.d.ts +2 -2
  262. package/dist/store/product.js +5 -8
  263. package/dist/store/spaces.d.ts +74 -0
  264. package/dist/store/spaces.js +354 -0
  265. package/dist/store/translations.d.ts +8 -10
  266. package/dist/store/translations.js +19 -39
  267. package/dist/store/treble.d.ts +2 -2
  268. package/dist/store/treble.js +15 -22
  269. package/dist/store/wishlist.d.ts +4 -22
  270. package/dist/store/wishlist.js +1 -1
  271. package/dist/types.d.ts +20 -19
  272. package/dist/types.js +9 -9
  273. package/dist/utils.d.ts +6 -2
  274. package/dist/utils.js +12 -5
  275. package/package.json +1 -1
  276. package/dist/api/assets.d.ts +0 -1
  277. package/dist/hooks/useRoomBuilder/RoomBuilderState.d.ts +0 -95
  278. package/dist/hooks/useRoomBuilder/RoomBuilderState.js +0 -1237
  279. package/dist/hooks/useRoomBuilder/constants.d.ts +0 -41
  280. package/dist/hooks/useRoomBuilder/constants.js +0 -48
  281. package/dist/hooks/useRoomBuilder/dataHandlers.d.ts +0 -18
  282. package/dist/hooks/useRoomBuilder/dataHandlers.js +0 -187
  283. package/dist/hooks/useRoomBuilder/draw.d.ts +0 -55
  284. package/dist/hooks/useRoomBuilder/draw.js +0 -573
  285. package/dist/hooks/useRoomBuilder/findLoops.d.ts +0 -5
  286. package/dist/hooks/useRoomBuilder/geometry.d.ts +0 -33
  287. package/dist/hooks/useRoomBuilder/geometry.js +0 -325
  288. package/dist/hooks/useRoomBuilder/index.d.ts +0 -40
  289. package/dist/hooks/useRoomBuilder/index.js +0 -303
  290. package/dist/hooks/useRoomBuilder/themes.js +0 -273
  291. package/dist/hooks/useRoomBuilder/types.d.ts +0 -238
  292. package/dist/hooks/useRoomBuilder/types.js +0 -36
  293. package/dist/hooks/useRoomBuilder/validators.d.ts +0 -36
  294. package/dist/hooks/useRoomBuilder/validators.js +0 -362
  295. package/dist/http/assets.d.ts +0 -2
  296. package/dist/http/assets.js +0 -16
  297. /package/dist/hooks/{useRoomBuilder → useSpaces/validators}/messaging.d.ts +0 -0
@@ -0,0 +1,1814 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.SpacesState = void 0;
60
+ var types_1 = require("./types");
61
+ var validators_1 = require("./validators");
62
+ var geometry_1 = require("./geometry");
63
+ var draw_1 = require("./draw");
64
+ var dataHandlers_1 = require("./dataHandlers");
65
+ var __1 = require("../..");
66
+ var constants_1 = require("./constants");
67
+ var SpacesState = (function () {
68
+ function SpacesState(config) {
69
+ var _a;
70
+ var _this = this;
71
+ var _b;
72
+ this.moveActiveVertex = function (canvas, point) {
73
+ var _a, _b, _c, _d;
74
+ if (!canvas)
75
+ return;
76
+ if (((_a = _this._activeElement) === null || _a === void 0 ? void 0 : _a.type) !== types_1.IElements.VERTEX)
77
+ return;
78
+ var snapPoint = _this.getSnapPointToElementInProximity(point);
79
+ snapPoint = _this.getSnapActiveVertexToGuideInProximity(snapPoint);
80
+ snapPoint = _this.getSnapPointToGridInProximity(snapPoint);
81
+ if (snapPoint.type === types_1.SNAPPING_TYPES.GUIDE ||
82
+ snapPoint.type === types_1.SNAPPING_TYPES.GRID)
83
+ _this.guides = snapPoint;
84
+ else if (_this.guides)
85
+ _this.guides = null;
86
+ var vertex = _this.getVertex(_this._activeElement.index);
87
+ if (!vertex)
88
+ return;
89
+ var validationData = {
90
+ vertex: vertex,
91
+ updatedPosition: snapPoint,
92
+ };
93
+ _this._errorElement = _this.runValidators([
94
+ validators_1.isVertexLandingOnFeature,
95
+ validators_1.areWallsTooShort,
96
+ validators_1.areWallsIntersecting,
97
+ validators_1.areWallsOrphaningFeatures,
98
+ validators_1.areWallsDuplicated,
99
+ ], validationData);
100
+ var errorType = ((_b = _this._errorElement) === null || _b === void 0 ? void 0 : _b[0].type) || null;
101
+ switch (errorType) {
102
+ case types_1.IErrorTypes.HARD:
103
+ return;
104
+ case types_1.IErrorTypes.SOFT:
105
+ case types_1.IErrorTypes.WARN:
106
+ case null:
107
+ default:
108
+ _this._activeElement.snapPoint = snapPoint;
109
+ _this.repositionVertex(_this._activeElement.index, (_c = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _c !== void 0 ? _c : point);
110
+ _this.drawSpaces(canvas);
111
+ (0, draw_1.drawVertex)(canvas, _this.transformPointToCanvas((_d = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _d !== void 0 ? _d : point), _this.styles.vertex, types_1.IElementStyleModes.HIGHLIGHT);
112
+ break;
113
+ }
114
+ };
115
+ this.finishMoveActiveVertex = function () {
116
+ var _a, _b;
117
+ if (((_a = _this._activeElement) === null || _a === void 0 ? void 0 : _a.type) !== types_1.IElements.VERTEX)
118
+ return;
119
+ if (((_b = _this._activeElement.snapPoint) === null || _b === void 0 ? void 0 : _b.type) === types_1.IElements.WALL)
120
+ _this.splitWallAtPoint(_this._activeElement.snapPoint.index, _this._activeElement.snapPoint.point);
121
+ _this.guides = null;
122
+ _this.pushStateToConfigurator();
123
+ };
124
+ this.moveActiveFeature = function (canvas, moveToPoint) {
125
+ var _a, _b;
126
+ if (_this._activeElement === null)
127
+ return;
128
+ var _c = _this._activeElement, type = _c.type, index = _c.index;
129
+ if (type !== types_1.IElements.WINDOW &&
130
+ type !== types_1.IElements.DOOR &&
131
+ type !== types_1.IElements.OPENING)
132
+ return;
133
+ var feature = _this.getFeature(type, index);
134
+ if (!feature)
135
+ return;
136
+ var wallIndex = (_a = _this.getWallIndexInProximity(moveToPoint)) !== null && _a !== void 0 ? _a : feature.connectedTo[1];
137
+ var wall = _this.getWall(wallIndex);
138
+ if (!wall)
139
+ return;
140
+ var intersection = (0, geometry_1.getTangetIntersectionAndOffset)(wall.line, moveToPoint);
141
+ if (!intersection)
142
+ return;
143
+ var padding = _this.validationConfig.padding;
144
+ var minOffset = padding;
145
+ var maxOffset = (0, geometry_1.getLengthOfLineSegment)(wall.line) - (padding + feature.length);
146
+ var newOffset = intersection.offset - feature.length / 2;
147
+ if (newOffset < minOffset)
148
+ newOffset = minOffset;
149
+ else if (newOffset > maxOffset)
150
+ newOffset = maxOffset;
151
+ var validationData = {
152
+ wall: wall,
153
+ updatedFeature: {
154
+ length: feature.length,
155
+ offset: newOffset,
156
+ address: { type: type, index: index },
157
+ },
158
+ };
159
+ _this._errorElement = _this.runValidators([validators_1.isFeatureCollidingWithExistingFeature], validationData);
160
+ var errorType = ((_b = _this._errorElement) === null || _b === void 0 ? void 0 : _b[0].type) || null;
161
+ switch (errorType) {
162
+ case types_1.IErrorTypes.HARD:
163
+ return;
164
+ case types_1.IErrorTypes.SOFT:
165
+ _this.drawSpaces(canvas);
166
+ break;
167
+ case types_1.IErrorTypes.WARN:
168
+ case null:
169
+ default:
170
+ _this.repositionFeature([type, index], newOffset, wallIndex);
171
+ _this.drawSpaces(canvas);
172
+ break;
173
+ }
174
+ };
175
+ this.finishMoveActiveFeature = function () {
176
+ var _a;
177
+ var type = (_a = _this._activeElement) === null || _a === void 0 ? void 0 : _a.type;
178
+ if (!type)
179
+ return;
180
+ if (type !== types_1.IElements.WINDOW &&
181
+ type !== types_1.IElements.DOOR &&
182
+ type !== types_1.IElements.OPENING)
183
+ return;
184
+ _this.pushStateToConfigurator();
185
+ };
186
+ this._config = config;
187
+ this._newWall = null;
188
+ this._activeElement = null;
189
+ this._selectedElement = null;
190
+ this._highlightedElement = null;
191
+ this._errorElement = null;
192
+ this._attributeDefaults = config.attributeDefaults;
193
+ this._state = (_a = {},
194
+ _a[types_1.IElements.WALL] = [],
195
+ _a[types_1.IElements.VERTEX] = {},
196
+ _a[types_1.IElements.FEATURE] = {},
197
+ _a);
198
+ this._unit = config.config.unit;
199
+ this._showDimensions = config.config.showDimensions;
200
+ this._angleSnappingEnabled = config.config.enableAngleSnapping;
201
+ this._guideSnappingEnabled = config.config.enableGuideSnapping;
202
+ this._gridSnappingEnabled = config.config.enableGridSnapping;
203
+ this._guides = null;
204
+ this._attributesState = null;
205
+ this._canvasDimensions = (_b = config.canvasDimensions) !== null && _b !== void 0 ? _b : [0, 0];
206
+ this._zoom = config.config.zoomDefault;
207
+ this._zoomLimits = [constants_1.ZOOM_MIN, constants_1.ZOOM_MAX];
208
+ this._translate = config.config.translateDefault;
209
+ this._translateLimits = [constants_1.TRANSLATE_MIN, constants_1.TRANSLATE_MAX];
210
+ this._activeWallMode = config.wallMode.value;
211
+ this._activeWallModeAssetId = config.wallMode.assetId;
212
+ this._setPendingStatus = config.setPendingStatus;
213
+ if (config.attributesState)
214
+ this.setAttributesToState(config.attributesState);
215
+ }
216
+ Object.defineProperty(SpacesState.prototype, "styles", {
217
+ get: function () {
218
+ return this._config.config.styles;
219
+ },
220
+ enumerable: false,
221
+ configurable: true
222
+ });
223
+ Object.defineProperty(SpacesState.prototype, "attributeDefaults", {
224
+ get: function () {
225
+ return this._attributeDefaults;
226
+ },
227
+ set: function (val) {
228
+ this._attributeDefaults = val;
229
+ },
230
+ enumerable: false,
231
+ configurable: true
232
+ });
233
+ Object.defineProperty(SpacesState.prototype, "scale", {
234
+ get: function () {
235
+ return this._config.config.scale;
236
+ },
237
+ enumerable: false,
238
+ configurable: true
239
+ });
240
+ Object.defineProperty(SpacesState.prototype, "snapProximity", {
241
+ get: function () {
242
+ return this.transformLengthFromCanvas(this._config.config.snapProximity);
243
+ },
244
+ enumerable: false,
245
+ configurable: true
246
+ });
247
+ Object.defineProperty(SpacesState.prototype, "gridUnitLength", {
248
+ get: function () {
249
+ var length = [types_1.IUnits.FEET, types_1.IUnits.INCH].includes(this.unit)
250
+ ? (0, dataHandlers_1.convertLengthUnit)(1, types_1.IUnits.FEET, types_1.IUnits.METER)
251
+ : 1;
252
+ return length / this.scale;
253
+ },
254
+ enumerable: false,
255
+ configurable: true
256
+ });
257
+ Object.defineProperty(SpacesState.prototype, "gridUnitLengthToDraw", {
258
+ get: function () {
259
+ return this.transformLengthToCanvas(this.gridUnitLength);
260
+ },
261
+ enumerable: false,
262
+ configurable: true
263
+ });
264
+ Object.defineProperty(SpacesState.prototype, "gridOffset", {
265
+ get: function () {
266
+ var gridLength = this.gridUnitLengthToDraw;
267
+ var translate = this.transformPointToCanvas([0, 0]);
268
+ return [
269
+ ((translate[0] % gridLength) + gridLength) % gridLength,
270
+ ((translate[1] % gridLength) + gridLength) % gridLength,
271
+ ];
272
+ },
273
+ enumerable: false,
274
+ configurable: true
275
+ });
276
+ Object.defineProperty(SpacesState.prototype, "gridToDraw", {
277
+ get: function () {
278
+ var unitLength = this.gridUnitLengthToDraw;
279
+ var subdivisions = [types_1.IUnits.FEET, types_1.IUnits.INCH].includes(this.unit) ? 4 : 5;
280
+ return {
281
+ unitLength: unitLength,
282
+ offset: this.gridOffset,
283
+ subdivisions: subdivisions,
284
+ showSubdivisions: this.styles.grid.showSubdivisions &&
285
+ unitLength / subdivisions > this.styles.grid.subdivisionThreshold,
286
+ };
287
+ },
288
+ enumerable: false,
289
+ configurable: true
290
+ });
291
+ Object.defineProperty(SpacesState.prototype, "walls", {
292
+ get: function () {
293
+ return this._state[types_1.IElements.WALL];
294
+ },
295
+ set: function (walls) {
296
+ this._state[types_1.IElements.WALL] = walls;
297
+ },
298
+ enumerable: false,
299
+ configurable: true
300
+ });
301
+ Object.defineProperty(SpacesState.prototype, "wallsToDraw", {
302
+ get: function () {
303
+ var _this = this;
304
+ return this._state[types_1.IElements.WALL].map(function (wall) { return (__assign(__assign({}, wall), { line: _this.transformLineToCanvas(wall.line), path: undefined })); });
305
+ },
306
+ enumerable: false,
307
+ configurable: true
308
+ });
309
+ Object.defineProperty(SpacesState.prototype, "wallCount", {
310
+ get: function () {
311
+ return this.walls.length;
312
+ },
313
+ enumerable: false,
314
+ configurable: true
315
+ });
316
+ Object.defineProperty(SpacesState.prototype, "wallLines", {
317
+ get: function () {
318
+ return this.walls.map(function (_a) {
319
+ var line = _a.line;
320
+ return line;
321
+ });
322
+ },
323
+ enumerable: false,
324
+ configurable: true
325
+ });
326
+ Object.defineProperty(SpacesState.prototype, "vertices", {
327
+ get: function () {
328
+ return this._state[types_1.IElements.VERTEX];
329
+ },
330
+ set: function (vertices) {
331
+ this._state[types_1.IElements.VERTEX] = vertices;
332
+ },
333
+ enumerable: false,
334
+ configurable: true
335
+ });
336
+ Object.defineProperty(SpacesState.prototype, "verticesToDraw", {
337
+ get: function () {
338
+ return this._state[types_1.IElements.VERTEX];
339
+ },
340
+ enumerable: false,
341
+ configurable: true
342
+ });
343
+ Object.defineProperty(SpacesState.prototype, "verticesList", {
344
+ get: function () {
345
+ return Object.entries(this.vertices).map(function (_a) {
346
+ var pointStr = _a[0], connections = _a[1];
347
+ return ({
348
+ point: JSON.parse(pointStr),
349
+ connections: connections,
350
+ });
351
+ });
352
+ },
353
+ enumerable: false,
354
+ configurable: true
355
+ });
356
+ Object.defineProperty(SpacesState.prototype, "verticesListToDraw", {
357
+ get: function () {
358
+ var _this = this;
359
+ return this.verticesList.map(function (vertex) { return (__assign(__assign({}, vertex), { point: _this.transformPointToCanvas(vertex.point) })); });
360
+ },
361
+ enumerable: false,
362
+ configurable: true
363
+ });
364
+ Object.defineProperty(SpacesState.prototype, "features", {
365
+ get: function () {
366
+ return this._state[types_1.IElements.FEATURE];
367
+ },
368
+ set: function (features) {
369
+ this._state[types_1.IElements.FEATURE] = features;
370
+ },
371
+ enumerable: false,
372
+ configurable: true
373
+ });
374
+ Object.defineProperty(SpacesState.prototype, "featuresToDraw", {
375
+ get: function () {
376
+ var _this = this;
377
+ return Object.entries(this.features).reduce(function (output, _a) {
378
+ var _b;
379
+ var type = _a[0], featureArr = _a[1];
380
+ return Object.assign(output, (_b = {},
381
+ _b[type] = featureArr.map(function (feature) { return (__assign(__assign({}, feature), { path: undefined, offset: _this.transformLengthToCanvas(feature.offset), length: _this.transformLengthToCanvas(feature.length) })); }),
382
+ _b));
383
+ }, {});
384
+ },
385
+ enumerable: false,
386
+ configurable: true
387
+ });
388
+ Object.defineProperty(SpacesState.prototype, "getHydratedFeatures", {
389
+ get: function () {
390
+ var _this = this;
391
+ return Object.entries(this.features).reduce(function (output, _a) {
392
+ var _b;
393
+ var type = _a[0], featureArr = _a[1];
394
+ return Object.assign(output, (_b = {},
395
+ _b[type] = featureArr.map(function (feature) {
396
+ var wall = _this.getWall(feature.connectedTo[1]);
397
+ if (!wall)
398
+ return;
399
+ var line = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, feature.offset, feature.length);
400
+ return __assign(__assign({}, feature), { line: line });
401
+ }),
402
+ _b));
403
+ }, {});
404
+ },
405
+ enumerable: false,
406
+ configurable: true
407
+ });
408
+ Object.defineProperty(SpacesState.prototype, "featureCount", {
409
+ get: function () {
410
+ return Object.values(this.features).flat().length;
411
+ },
412
+ enumerable: false,
413
+ configurable: true
414
+ });
415
+ Object.defineProperty(SpacesState.prototype, "activeElement", {
416
+ get: function () {
417
+ return this._activeElement;
418
+ },
419
+ enumerable: false,
420
+ configurable: true
421
+ });
422
+ Object.defineProperty(SpacesState.prototype, "selectedElement", {
423
+ get: function () {
424
+ return this._selectedElement;
425
+ },
426
+ set: function (element) {
427
+ this._selectedElement = element;
428
+ },
429
+ enumerable: false,
430
+ configurable: true
431
+ });
432
+ Object.defineProperty(SpacesState.prototype, "showDimensions", {
433
+ get: function () {
434
+ return this._showDimensions;
435
+ },
436
+ set: function (val) {
437
+ this._showDimensions = val;
438
+ },
439
+ enumerable: false,
440
+ configurable: true
441
+ });
442
+ Object.defineProperty(SpacesState.prototype, "angleSnappingEnabled", {
443
+ get: function () {
444
+ return this._angleSnappingEnabled;
445
+ },
446
+ set: function (val) {
447
+ this._angleSnappingEnabled = val;
448
+ },
449
+ enumerable: false,
450
+ configurable: true
451
+ });
452
+ Object.defineProperty(SpacesState.prototype, "guideSnappingEnabled", {
453
+ get: function () {
454
+ return this._guideSnappingEnabled;
455
+ },
456
+ set: function (val) {
457
+ this._guideSnappingEnabled = val;
458
+ },
459
+ enumerable: false,
460
+ configurable: true
461
+ });
462
+ Object.defineProperty(SpacesState.prototype, "gridSnappingEnabled", {
463
+ get: function () {
464
+ return this._gridSnappingEnabled;
465
+ },
466
+ set: function (val) {
467
+ this._gridSnappingEnabled = val;
468
+ },
469
+ enumerable: false,
470
+ configurable: true
471
+ });
472
+ Object.defineProperty(SpacesState.prototype, "guides", {
473
+ get: function () {
474
+ return this._guides;
475
+ },
476
+ set: function (val) {
477
+ this._guides = val;
478
+ },
479
+ enumerable: false,
480
+ configurable: true
481
+ });
482
+ Object.defineProperty(SpacesState.prototype, "enclosedSpacesToDraw", {
483
+ get: function () {
484
+ var _this = this;
485
+ var loops = (0, geometry_1.findLoops)(this.wallLines).inner;
486
+ return loops.reduce(function (output, loop) {
487
+ var screenSpaceArea = Math.round((0, geometry_1.getPolygonArea)(loop));
488
+ var area = screenSpaceArea * Math.pow(_this.scale, 2);
489
+ var convertedArea = (0, dataHandlers_1.convertAreaUnit)(area, types_1.IUnits.METER, _this.unit);
490
+ var enclosedSpace = {
491
+ loop: loop.map(function (point) { return _this.transformPointToCanvas(point); }),
492
+ area: (0, dataHandlers_1.prepAreaForUser)(convertedArea, _this.unit),
493
+ center: loop.reduce(function (centerPoint, point) {
494
+ centerPoint[0] += point[0] / loop.length;
495
+ centerPoint[1] += point[1] / loop.length;
496
+ return centerPoint;
497
+ }, [0, 0]),
498
+ };
499
+ enclosedSpace.center = _this.transformPointToCanvas(enclosedSpace.center);
500
+ output.push(enclosedSpace);
501
+ return output;
502
+ }, []);
503
+ },
504
+ enumerable: false,
505
+ configurable: true
506
+ });
507
+ Object.defineProperty(SpacesState.prototype, "canvasDimensions", {
508
+ get: function () {
509
+ return this._canvasDimensions;
510
+ },
511
+ set: function (dimensions) {
512
+ this._canvasDimensions = dimensions;
513
+ },
514
+ enumerable: false,
515
+ configurable: true
516
+ });
517
+ Object.defineProperty(SpacesState.prototype, "canvasWidth", {
518
+ get: function () {
519
+ return this.canvasDimensions[0];
520
+ },
521
+ enumerable: false,
522
+ configurable: true
523
+ });
524
+ Object.defineProperty(SpacesState.prototype, "canvasHeight", {
525
+ get: function () {
526
+ return this.canvasDimensions[1];
527
+ },
528
+ enumerable: false,
529
+ configurable: true
530
+ });
531
+ Object.defineProperty(SpacesState.prototype, "zoom", {
532
+ get: function () {
533
+ return this._zoom;
534
+ },
535
+ set: function (delta) {
536
+ var newZoom = this.zoom + delta;
537
+ var preppedZoom = newZoom < this.zoomMin
538
+ ? this.zoomMin
539
+ : newZoom > this.zoomMax
540
+ ? this.zoomMax
541
+ : newZoom;
542
+ if (preppedZoom === this.zoom)
543
+ return;
544
+ this._zoom = preppedZoom;
545
+ },
546
+ enumerable: false,
547
+ configurable: true
548
+ });
549
+ Object.defineProperty(SpacesState.prototype, "zoomFactor", {
550
+ get: function () {
551
+ return this._zoom / this.zoomMin;
552
+ },
553
+ set: function (val) {
554
+ var newZoom = val * this.zoomMin;
555
+ var validatedZoom = newZoom < this.zoomMin
556
+ ? this.zoomMin
557
+ : newZoom > this.zoomMax
558
+ ? this.zoomMax
559
+ : newZoom;
560
+ this._zoom = validatedZoom;
561
+ },
562
+ enumerable: false,
563
+ configurable: true
564
+ });
565
+ Object.defineProperty(SpacesState.prototype, "zoomMin", {
566
+ get: function () {
567
+ return this._zoomLimits[0];
568
+ },
569
+ enumerable: false,
570
+ configurable: true
571
+ });
572
+ Object.defineProperty(SpacesState.prototype, "zoomMax", {
573
+ get: function () {
574
+ return this._zoomLimits[1];
575
+ },
576
+ enumerable: false,
577
+ configurable: true
578
+ });
579
+ Object.defineProperty(SpacesState.prototype, "unit", {
580
+ get: function () {
581
+ return this._unit;
582
+ },
583
+ set: function (unit) {
584
+ this._unit = unit;
585
+ },
586
+ enumerable: false,
587
+ configurable: true
588
+ });
589
+ Object.defineProperty(SpacesState.prototype, "translate", {
590
+ get: function () {
591
+ return this._translate;
592
+ },
593
+ set: function (position) {
594
+ var zoomFactor = this._zoom / this.zoomMin;
595
+ var delta = [
596
+ (position[0] - this._translate[0]) / zoomFactor,
597
+ (position[1] - this._translate[1]) / zoomFactor,
598
+ ];
599
+ this._translate = [
600
+ this._translate[0] + delta[0],
601
+ this._translate[1] + delta[1],
602
+ ];
603
+ },
604
+ enumerable: false,
605
+ configurable: true
606
+ });
607
+ Object.defineProperty(SpacesState.prototype, "translateMin", {
608
+ get: function () {
609
+ return this._translateLimits[0];
610
+ },
611
+ enumerable: false,
612
+ configurable: true
613
+ });
614
+ Object.defineProperty(SpacesState.prototype, "translateMax", {
615
+ get: function () {
616
+ return this._translateLimits[1];
617
+ },
618
+ enumerable: false,
619
+ configurable: true
620
+ });
621
+ Object.defineProperty(SpacesState.prototype, "isDrawWallActive", {
622
+ get: function () {
623
+ return !!this._newWall;
624
+ },
625
+ enumerable: false,
626
+ configurable: true
627
+ });
628
+ Object.defineProperty(SpacesState.prototype, "validationConfig", {
629
+ get: function () {
630
+ return this._validationConfig;
631
+ },
632
+ set: function (config) {
633
+ this._validationConfig = config;
634
+ },
635
+ enumerable: false,
636
+ configurable: true
637
+ });
638
+ Object.defineProperty(SpacesState.prototype, "wallMode", {
639
+ get: function () {
640
+ return {
641
+ value: this._activeWallMode,
642
+ assetId: this._activeWallModeAssetId,
643
+ };
644
+ },
645
+ set: function (mode) {
646
+ this._activeWallMode = mode.value;
647
+ this._activeWallModeAssetId = mode.assetId;
648
+ },
649
+ enumerable: false,
650
+ configurable: true
651
+ });
652
+ SpacesState.prototype.sync = function (state) {
653
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
654
+ this._canvasDimensions = (_a = state.canvasDimensions) !== null && _a !== void 0 ? _a : this._canvasDimensions;
655
+ this.angleSnappingEnabled =
656
+ (_b = state.angleSnappingEnabled) !== null && _b !== void 0 ? _b : this.angleSnappingEnabled;
657
+ this.guideSnappingEnabled =
658
+ (_c = state.guideSnappingEnabled) !== null && _c !== void 0 ? _c : this.guideSnappingEnabled;
659
+ this.gridSnappingEnabled =
660
+ (_d = state.gridSnappingEnabled) !== null && _d !== void 0 ? _d : this.gridSnappingEnabled;
661
+ this.showDimensions = (_e = state.showDimensions) !== null && _e !== void 0 ? _e : this.showDimensions;
662
+ this._zoom = (_f = state.zoom) !== null && _f !== void 0 ? _f : this._zoom;
663
+ this.translate = (_g = state.translate) !== null && _g !== void 0 ? _g : this.translate;
664
+ this.unit = (_h = state.unit) !== null && _h !== void 0 ? _h : this.unit;
665
+ this.wallMode = (_j = state.wallMode) !== null && _j !== void 0 ? _j : this.wallMode;
666
+ if (state.selectedElement !== undefined)
667
+ this.selectedElement = state.selectedElement;
668
+ if (state.attributesState)
669
+ this.setAttributesToState(state.attributesState);
670
+ };
671
+ SpacesState.prototype.transformLengthFromCanvas = function (length) {
672
+ return length / this.zoomFactor;
673
+ };
674
+ SpacesState.prototype.transformLengthToCanvas = function (length) {
675
+ return length * this.zoomFactor;
676
+ };
677
+ SpacesState.prototype.transformPointToCanvas = function (point) {
678
+ var widthOffset = this.canvasWidth / 2;
679
+ var heightOffset = this.canvasHeight / 2;
680
+ return [
681
+ this.transformLengthToCanvas(point[0] + this.translate[0]) -
682
+ widthOffset * (this.zoomFactor - 1),
683
+ this.transformLengthToCanvas(point[1] + this.translate[1]) -
684
+ heightOffset * (this.zoomFactor - 1),
685
+ ];
686
+ };
687
+ SpacesState.prototype.transformPointFromCanvas = function (point) {
688
+ var widthOffset = this.canvasWidth / 2;
689
+ var heightOffset = this.canvasHeight / 2;
690
+ return [
691
+ this.transformLengthFromCanvas(point[0] + widthOffset * (this.zoomFactor - 1)) - this.translate[0],
692
+ this.transformLengthFromCanvas(point[1] + heightOffset * (this.zoomFactor - 1)) - this.translate[1],
693
+ ];
694
+ };
695
+ SpacesState.prototype.transformLineToCanvas = function (line) {
696
+ return [
697
+ this.transformPointToCanvas(line[0]),
698
+ this.transformPointToCanvas(line[1]),
699
+ ];
700
+ };
701
+ SpacesState.prototype.prepLineLength = function (line) {
702
+ var lineLength = (0, geometry_1.getLengthOfLineSegment)(line) * this.scale;
703
+ var convertedVal = (0, dataHandlers_1.convertLengthUnit)(lineLength, types_1.IUnits.METER, this.unit);
704
+ return convertedVal;
705
+ };
706
+ SpacesState.prototype.getWall = function (index) {
707
+ return this.walls[index];
708
+ };
709
+ SpacesState.prototype.addWall = function (wall) {
710
+ if (!wall)
711
+ return;
712
+ var updatedWalls = this.walls;
713
+ updatedWalls.push(wall);
714
+ this.walls = updatedWalls;
715
+ };
716
+ SpacesState.prototype.addWalls = function (walls) {
717
+ var _this = this;
718
+ if (!(walls === null || walls === void 0 ? void 0 : walls.length))
719
+ return;
720
+ walls.forEach(function (wall) { return _this.addWall(wall); });
721
+ };
722
+ SpacesState.prototype.updateWall = function (index, wall) {
723
+ var currentWall = this.walls[index];
724
+ if (!currentWall)
725
+ return;
726
+ this._state[types_1.IElements.WALL][index] = Object.assign({}, currentWall, wall);
727
+ };
728
+ SpacesState.prototype.getWallConnectionCount = function (index) {
729
+ var wall = this.getWall(index);
730
+ return (wall === null || wall === void 0 ? void 0 : wall.connections.length) || 0;
731
+ };
732
+ SpacesState.prototype.getWallConnectionsHydrated = function (index) {
733
+ var _this = this;
734
+ var _a;
735
+ var connections = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.connections;
736
+ if (!connections)
737
+ return undefined;
738
+ return connections.reduce(function (output, connection) {
739
+ var feature = _this.getFeature.apply(_this, connection);
740
+ if (feature)
741
+ output.push(feature);
742
+ return output;
743
+ }, []);
744
+ };
745
+ SpacesState.prototype.getWallDimensions = function (line) {
746
+ var lineLength = this.prepLineLength(line);
747
+ return {
748
+ line: line,
749
+ label: (0, dataHandlers_1.prepLengthForUser)(lineLength, this.unit),
750
+ };
751
+ };
752
+ SpacesState.prototype.getWallDimensionsByIndex = function (index) {
753
+ var _a;
754
+ var line = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.line;
755
+ if (!line)
756
+ return undefined;
757
+ return this.getWallDimensions(line);
758
+ };
759
+ SpacesState.prototype.getWallDetailedDimensionsByIndex = function (index) {
760
+ var _this = this;
761
+ var _a;
762
+ var line = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.line;
763
+ var features = this.getWallConnectionsHydrated(index);
764
+ if (!line || !features)
765
+ return undefined;
766
+ var prepLength = function (val) { return val.toFixed(2); };
767
+ var lines = features
768
+ .sort(function (a, b) { return a.offset - b.offset; })
769
+ .reduce(function (output, _a, i) {
770
+ var offset = _a.offset, length = _a.length;
771
+ var featureLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(line, offset, length);
772
+ var featureLength = _this.prepLineLength(featureLine);
773
+ var unit = constants_1.UNIT_LABELS[_this.unit];
774
+ if (!i) {
775
+ var startLine = [line[0], featureLine[0]];
776
+ var startLineLength = _this.prepLineLength(startLine);
777
+ output.push({
778
+ line: startLine,
779
+ label: "".concat(prepLength(startLineLength), " ").concat(unit),
780
+ });
781
+ }
782
+ else {
783
+ var previousLine = [
784
+ output[output.length - 1].line[1],
785
+ featureLine[0],
786
+ ];
787
+ var previousLineLength = _this.prepLineLength(previousLine);
788
+ output.push({
789
+ line: previousLine,
790
+ label: "".concat(prepLength(previousLineLength), " ").concat(unit),
791
+ });
792
+ }
793
+ output.push({
794
+ line: featureLine,
795
+ label: "".concat(prepLength(featureLength), " ").concat(unit),
796
+ });
797
+ if (i === features.length - 1) {
798
+ var endLine = [featureLine[1], line[1]];
799
+ var endLineLength = _this.prepLineLength(endLine);
800
+ output.push({
801
+ line: endLine,
802
+ label: "".concat(prepLength(endLineLength), " ").concat(unit),
803
+ });
804
+ }
805
+ return output;
806
+ }, []);
807
+ return lines;
808
+ };
809
+ SpacesState.prototype.getDimensionToDraw = function (detailedWallsIndexes) {
810
+ var _this = this;
811
+ if (detailedWallsIndexes === void 0) { detailedWallsIndexes = []; }
812
+ if (this.showDimensions === types_1.IDimensionOptions.NONE)
813
+ return undefined;
814
+ var indexes = new Set([detailedWallsIndexes].flat());
815
+ var dimensionsList = this.walls.reduce(function (output, _, i) {
816
+ var dimensions = _this.showDimensions === types_1.IDimensionOptions.DETAILED || indexes.has(i)
817
+ ? _this.getWallDetailedDimensionsByIndex(i)
818
+ : _this.getWallDimensionsByIndex(i);
819
+ if (!dimensions)
820
+ return output;
821
+ if (Array.isArray(dimensions))
822
+ output.push.apply(output, dimensions);
823
+ else
824
+ output.push(dimensions);
825
+ return output;
826
+ }, []);
827
+ return dimensionsList.map(function (dimension) { return (__assign(__assign({}, dimension), { line: _this.transformLineToCanvas(dimension.line) })); });
828
+ };
829
+ SpacesState.prototype.shiftAllFeaturesOnWall = function (index, shift) {
830
+ var _this = this;
831
+ var _a;
832
+ var connections = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.connections;
833
+ if (!connections)
834
+ return;
835
+ connections.forEach(function (_a) {
836
+ var type = _a[0], featureIndex = _a[1];
837
+ var feature = _this.getFeature(type, featureIndex);
838
+ if (!feature)
839
+ return;
840
+ _this.updateFeature(type, featureIndex, {
841
+ offset: feature.offset + shift,
842
+ });
843
+ });
844
+ };
845
+ SpacesState.prototype.addFeatureToWall = function (index, featurePath) {
846
+ var _a;
847
+ var updatedWalls = this.walls;
848
+ (_a = updatedWalls[index]) === null || _a === void 0 ? void 0 : _a.connections.push(featurePath);
849
+ this.walls = updatedWalls;
850
+ };
851
+ SpacesState.prototype.removeFeatureFromWall = function (index, featurePath) {
852
+ var updatedWalls = this.walls;
853
+ if (!updatedWalls[index])
854
+ return;
855
+ updatedWalls[index].connections = updatedWalls[index].connections.filter(function (connection) {
856
+ return connection[0] !== featurePath[0] || connection[1] !== featurePath[1];
857
+ });
858
+ this.walls = updatedWalls;
859
+ };
860
+ SpacesState.prototype.splitWallAtOffset = function (wallIndex, offset) {
861
+ var wall = this.getWall(wallIndex);
862
+ if (!wall)
863
+ return;
864
+ var point = offset
865
+ ? (0, geometry_1.getPointAtOffsetOnLineSegment)(wall.line, offset)
866
+ : (0, geometry_1.getMidpointOfLineSegment)(wall.line);
867
+ this.splitWallAtPoint(wallIndex, point);
868
+ this.pushStateToConfigurator();
869
+ };
870
+ SpacesState.prototype.splitWallAtPoint = function (wallIndex, point) {
871
+ var _this = this;
872
+ var originalWall = this.getWall(wallIndex);
873
+ if (!originalWall)
874
+ return;
875
+ var offset = (0, geometry_1.getLengthOfLineSegment)([originalWall.line[0], point]);
876
+ var _a = (0, geometry_1.splitLineAtPoint)(originalWall.line, point), line1 = _a[0], line2 = _a[1];
877
+ var newWallIndex = this.wallCount;
878
+ var splitWallsShared = {
879
+ assetId: originalWall.assetId,
880
+ restConfiguration: originalWall.restConfiguration,
881
+ mode: originalWall.mode,
882
+ };
883
+ var wall1 = __assign(__assign({}, splitWallsShared), { line: line1, connections: originalWall.connections });
884
+ var wall2 = __assign(__assign({}, splitWallsShared), { line: line2, connections: [] });
885
+ this.updateWall(wallIndex, wall1);
886
+ this.addWall(wall2);
887
+ originalWall.connections.forEach(function (connection) {
888
+ var feature = _this.getFeature.apply(_this, connection);
889
+ if (!feature)
890
+ return;
891
+ var updatedOffset = feature.offset - offset;
892
+ if (updatedOffset > 0)
893
+ _this.repositionFeature(connection, updatedOffset, newWallIndex);
894
+ });
895
+ };
896
+ SpacesState.prototype.deleteWall = function (index) {
897
+ var wall = this.getWall(index);
898
+ if (!wall)
899
+ return;
900
+ if (wall.connections.length) {
901
+ var currentFeatures_1 = this.features;
902
+ var deleteMap = wall.connections.reduce(function (output, _a) {
903
+ var type = _a[0], index = _a[1];
904
+ if (output[type])
905
+ output[type].push(index);
906
+ else
907
+ output[type] = [index];
908
+ return output;
909
+ }, {});
910
+ var updatedFeatures = Object.entries(deleteMap).reduce(function (output, _a) {
911
+ var _b;
912
+ var type = _a[0], deletionIndexes = _a[1];
913
+ output[type] = (_b = currentFeatures_1[type]) === null || _b === void 0 ? void 0 : _b.filter(function (_, i) { return !deletionIndexes.includes(i); });
914
+ return output;
915
+ }, __assign({}, currentFeatures_1));
916
+ this.features = updatedFeatures;
917
+ }
918
+ var updatedWalls = this.walls;
919
+ updatedWalls.splice(index, 1);
920
+ this.walls = updatedWalls;
921
+ var reevaluatedFeatures = Object.entries(this.features).reduce(function (output, _a) {
922
+ var type = _a[0], featuresArr = _a[1];
923
+ output[type] = featuresArr.map(function (feature) {
924
+ return feature.connectedTo[1] > index
925
+ ? Object.assign({}, feature, {
926
+ connectedTo: [
927
+ feature.connectedTo[0],
928
+ feature.connectedTo[1] - 1,
929
+ ],
930
+ })
931
+ : feature;
932
+ });
933
+ return output;
934
+ }, {});
935
+ this.features = reevaluatedFeatures;
936
+ this.reevaluateFeatureConnections();
937
+ this.pushStateToConfigurator();
938
+ };
939
+ SpacesState.prototype.getFirstVacantLocationOnWallIndex = function (length, wallIndex) {
940
+ var _a, _b;
941
+ var _c = this, walls = _c.walls, validationConfig = _c.validationConfig;
942
+ var padding = validationConfig.padding;
943
+ var wallLength = (0, geometry_1.getLengthOfLineSegment)(walls[wallIndex].line);
944
+ var features = (_b = (_a = this.getWallConnectionsHydrated(wallIndex)) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.offset - b.offset; })) !== null && _b !== void 0 ? _b : [];
945
+ for (var j = 0; j <= features.length; j++) {
946
+ var prev = features[j - 1];
947
+ var next = features[j];
948
+ var slotStart = prev ? prev.offset + prev.length : padding;
949
+ var slotEnd = next ? next.offset : wallLength - padding;
950
+ if (slotEnd - slotStart > length) {
951
+ return (slotStart + slotEnd) / 2 - length / 2;
952
+ }
953
+ }
954
+ return undefined;
955
+ };
956
+ SpacesState.prototype.getFirstVacantLocation = function (length, wallIndex) {
957
+ if (wallIndex !== undefined) {
958
+ var offset = this.getFirstVacantLocationOnWallIndex(length, wallIndex);
959
+ if (offset != null)
960
+ return {
961
+ wallIndex: wallIndex,
962
+ offset: offset,
963
+ };
964
+ }
965
+ for (var i = 0; i < this.walls.length; i++) {
966
+ var offset = this.getFirstVacantLocationOnWallIndex(length, i);
967
+ if (offset != null)
968
+ return {
969
+ wallIndex: i,
970
+ offset: offset,
971
+ };
972
+ }
973
+ return false;
974
+ };
975
+ SpacesState.prototype.getWallUiAnchorPoint = function (index) {
976
+ var wall = this.getWall(index);
977
+ if (!wall)
978
+ return undefined;
979
+ var line = (0, geometry_1.getParallelLineSegmentAtDistance)(wall.line, constants_1.UI_ANCHOR_DISTANCE);
980
+ var point = (0, geometry_1.getMidpointOfLineSegment)(line);
981
+ return this.transformPointToCanvas(point);
982
+ };
983
+ SpacesState.prototype.getVertex = function (index) {
984
+ return this.verticesList[index];
985
+ };
986
+ SpacesState.prototype.getWallsConnectedToVertex = function (index) {
987
+ if (index === undefined)
988
+ return [];
989
+ var vertex = this.getVertex(index);
990
+ if (!vertex)
991
+ return [];
992
+ return vertex.connections.map(function (_a) {
993
+ var index = _a[0];
994
+ return index;
995
+ });
996
+ };
997
+ SpacesState.prototype.repositionVertex = function (index, newCoordinates) {
998
+ var _this = this;
999
+ var _a;
1000
+ var connections = (_a = this.getVertex(index)) === null || _a === void 0 ? void 0 : _a.connections;
1001
+ if (!connections)
1002
+ return;
1003
+ connections.forEach(function (_a) {
1004
+ var wallIdx = _a[0], vertexIdx = _a[1];
1005
+ var updatedLine = JSON.parse(JSON.stringify(_this.walls[wallIdx].line));
1006
+ var currentLine = JSON.parse(JSON.stringify(_this.walls[wallIdx].line));
1007
+ updatedLine[vertexIdx] = newCoordinates;
1008
+ if (_this.getWallConnectionCount(wallIdx) && vertexIdx === 0) {
1009
+ var delta = (0, geometry_1.getLengthOfLineSegment)(updatedLine) -
1010
+ (0, geometry_1.getLengthOfLineSegment)(currentLine);
1011
+ _this.shiftAllFeaturesOnWall(wallIdx, delta);
1012
+ }
1013
+ _this.updateWall(wallIdx, {
1014
+ line: updatedLine,
1015
+ path: undefined,
1016
+ });
1017
+ });
1018
+ };
1019
+ SpacesState.prototype.getFeatureType = function (type) {
1020
+ return this.features[type];
1021
+ };
1022
+ SpacesState.prototype.setFeatureType = function (type, features) {
1023
+ var updatedFeatures = this.features;
1024
+ updatedFeatures[type] = features;
1025
+ this.features = updatedFeatures;
1026
+ this.reevaluateFeatureConnections();
1027
+ };
1028
+ SpacesState.prototype.getFeature = function (type, index) {
1029
+ var _a;
1030
+ return (_a = this.features[type]) === null || _a === void 0 ? void 0 : _a[index];
1031
+ };
1032
+ SpacesState.prototype.updateFeature = function (type, index, feature) {
1033
+ var currentFeature = this._state[types_1.IElements.FEATURE][type][index];
1034
+ if (!currentFeature)
1035
+ return;
1036
+ this._state[types_1.IElements.FEATURE][type][index] = Object.assign({}, currentFeature, feature);
1037
+ };
1038
+ SpacesState.prototype.repositionFeature = function (featurePath, offset, moveToWallIndex) {
1039
+ var type = featurePath[0], index = featurePath[1];
1040
+ var feature = this.getFeature(type, index);
1041
+ if (!feature)
1042
+ return;
1043
+ this.updateFeature(type, index, { offset: offset, path: undefined });
1044
+ if (moveToWallIndex === feature.connectedTo[1])
1045
+ return;
1046
+ this.removeFeatureFromWall(index, featurePath);
1047
+ this.addFeatureToWall(moveToWallIndex, featurePath);
1048
+ this.updateFeature(type, index, {
1049
+ connectedTo: [types_1.IElements.WALL, moveToWallIndex],
1050
+ });
1051
+ };
1052
+ SpacesState.prototype.addFeature = function (type, addToWallIndex, feature) {
1053
+ var _a;
1054
+ var assetId = (feature === null || feature === void 0 ? void 0 : feature.assetId) || this.attributeDefaults[type];
1055
+ if (!assetId)
1056
+ return;
1057
+ var offset = undefined;
1058
+ var index = undefined;
1059
+ var length = ((feature === null || feature === void 0 ? void 0 : feature.length) || constants_1.FEATURE_LENGTH) / this.scale;
1060
+ if (addToWallIndex !== undefined && (feature === null || feature === void 0 ? void 0 : feature.offset) !== undefined) {
1061
+ var wall = this.getWall(addToWallIndex);
1062
+ if (wall) {
1063
+ var isColliding = (0, validators_1.isFeatureCollidingWithExistingFeature)({
1064
+ wall: wall,
1065
+ updatedFeature: {
1066
+ length: length,
1067
+ offset: feature.offset,
1068
+ address: { type: types_1.IElements.WALL, index: addToWallIndex },
1069
+ },
1070
+ }, {
1071
+ walls: this.walls,
1072
+ features: this.features,
1073
+ });
1074
+ if (!isColliding) {
1075
+ offset = feature.offset;
1076
+ index = addToWallIndex;
1077
+ }
1078
+ }
1079
+ }
1080
+ if (offset === undefined) {
1081
+ var availableSlot = this.getFirstVacantLocation(length, addToWallIndex);
1082
+ if (!availableSlot)
1083
+ return;
1084
+ offset = availableSlot.offset;
1085
+ index = availableSlot.wallIndex;
1086
+ }
1087
+ if (index === undefined || offset === undefined)
1088
+ return;
1089
+ var newFeature = __assign(__assign({}, feature), { assetId: assetId, offset: offset, length: length, height: (feature === null || feature === void 0 ? void 0 : feature.height) ? feature.height / this.scale : 0, altitude: (feature === null || feature === void 0 ? void 0 : feature.altitude) ? feature.altitude / this.scale : 0, connectedTo: [types_1.IElements.WALL, index], restConfiguration: '{}' });
1090
+ if (type === types_1.IElements.DOOR) {
1091
+ newFeature.orientation =
1092
+ this.attributeDefaults.doorOrientation;
1093
+ newFeature.openingDirection =
1094
+ this.attributeDefaults.doorOpeningDirection;
1095
+ newFeature.showSwing =
1096
+ this.attributeDefaults.doorShowSwing;
1097
+ }
1098
+ var newFeatureIndex;
1099
+ if ((_a = this._state[types_1.IElements.FEATURE][type]) === null || _a === void 0 ? void 0 : _a.length)
1100
+ newFeatureIndex = this._state[types_1.IElements.FEATURE][type].length;
1101
+ else {
1102
+ this._state[types_1.IElements.FEATURE][type] = [];
1103
+ newFeatureIndex = 0;
1104
+ }
1105
+ this._state[types_1.IElements.FEATURE][type].push(newFeature);
1106
+ this.addFeatureToWall(index, [type, newFeatureIndex]);
1107
+ this.pushStateToConfigurator();
1108
+ };
1109
+ SpacesState.prototype.deleteFeature = function (type, index) {
1110
+ var features = this.getFeatureType(type);
1111
+ if (!(features === null || features === void 0 ? void 0 : features[index]))
1112
+ return;
1113
+ var deletedFeature = features.splice(index, 1)[0];
1114
+ this.setFeatureType(type, features);
1115
+ var wallToUpdate = this.getWall(deletedFeature.connectedTo[1]);
1116
+ if (!wallToUpdate)
1117
+ return;
1118
+ this.updateWall(deletedFeature.connectedTo[1], {
1119
+ connections: wallToUpdate.connections.filter(function (connection) { return connection[0] === type && connection[1] !== index; }),
1120
+ });
1121
+ this.pushStateToConfigurator();
1122
+ };
1123
+ SpacesState.prototype.getHydratedFeature = function (type, index) {
1124
+ var feature = this.getFeature(type, index);
1125
+ if (!feature)
1126
+ return;
1127
+ var wall = this.getWall(feature.connectedTo[1]);
1128
+ if (!wall)
1129
+ return;
1130
+ var line = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, feature.offset, feature.length);
1131
+ return __assign(__assign({}, feature), { line: line });
1132
+ };
1133
+ SpacesState.prototype.getFeatureUiAnchorPoint = function (type, index) {
1134
+ var feature = this.getHydratedFeature(type, index);
1135
+ if (!feature)
1136
+ return;
1137
+ var line = (0, geometry_1.getParallelLineSegmentAtDistance)(feature.line, constants_1.UI_ANCHOR_DISTANCE);
1138
+ var point = (0, geometry_1.getMidpointOfLineSegment)(line);
1139
+ return this.transformPointToCanvas(point);
1140
+ };
1141
+ SpacesState.prototype.deleteElement = function (type, index) {
1142
+ if (type === types_1.IElements.VERTEX)
1143
+ return;
1144
+ if (type === types_1.IElements.WALL)
1145
+ this.deleteWall(index);
1146
+ else
1147
+ this.deleteFeature(type, index);
1148
+ };
1149
+ SpacesState.prototype.getVertexIndexInProximity = function (point) {
1150
+ if (!point)
1151
+ return undefined;
1152
+ var snapProximity = this.snapProximity;
1153
+ var index = this.verticesList.findIndex(function (vertex) {
1154
+ return (0, geometry_1.arePointsWithinProximity)(vertex.point, point, snapProximity);
1155
+ });
1156
+ if (index === -1)
1157
+ return undefined;
1158
+ return index;
1159
+ };
1160
+ SpacesState.prototype.getWallIndexInProximity = function (point) {
1161
+ var _this = this;
1162
+ var index = this.walls.findIndex(function (wall) {
1163
+ var path = (0, geometry_1.addThicknessToLine)(wall.line, _this.styles.wall.thickness + constants_1.WALL_SNAP_DISTANCE);
1164
+ return (0, geometry_1.isPointInQuadrilateral)(path, point);
1165
+ });
1166
+ if (index === -1)
1167
+ return undefined;
1168
+ return index;
1169
+ };
1170
+ SpacesState.prototype.getSnapPointToVertexInProximity = function (point) {
1171
+ var _a, _b;
1172
+ if (!point)
1173
+ return undefined;
1174
+ var index = this.getVertexIndexInProximity(point);
1175
+ if (index === undefined)
1176
+ return undefined;
1177
+ if (((_a = this._activeElement) === null || _a === void 0 ? void 0 : _a.type) === types_1.IElements.VERTEX &&
1178
+ ((_b = this._activeElement) === null || _b === void 0 ? void 0 : _b.index) === index)
1179
+ return undefined;
1180
+ var vertex = this.getVertex(index);
1181
+ if (!vertex)
1182
+ return undefined;
1183
+ return {
1184
+ type: types_1.IElements.VERTEX,
1185
+ index: index,
1186
+ point: vertex.point,
1187
+ locked: [true, true],
1188
+ };
1189
+ };
1190
+ SpacesState.prototype.getSnapPointToWallInProximity = function (point) {
1191
+ var index = this.getWallIndexInProximity(point);
1192
+ if (index === undefined)
1193
+ return undefined;
1194
+ if (this._activeElement) {
1195
+ if (this._activeElement.type === types_1.IElements.WALL &&
1196
+ this._activeElement.index === index)
1197
+ return undefined;
1198
+ if (this._activeElement.type === types_1.IElements.VERTEX) {
1199
+ var vertex = this.getVertex(this._activeElement.index);
1200
+ if (vertex)
1201
+ for (var i = 0; i < vertex.connections.length; i++) {
1202
+ if (vertex.connections[i][0] === index)
1203
+ return undefined;
1204
+ }
1205
+ }
1206
+ }
1207
+ var intersection = (0, geometry_1.getTangetIntersectionAndOffset)(this.getWall(index).line, point);
1208
+ if (!intersection)
1209
+ return undefined;
1210
+ return __assign(__assign({ type: types_1.IElements.WALL, index: index }, intersection), { locked: [true, true] });
1211
+ };
1212
+ SpacesState.prototype.getSnapPointToAngleInProximity = function (snapPoint, anchorPoint, angle) {
1213
+ var _a;
1214
+ if (anchorPoint === void 0) { anchorPoint = ((_a = this._newWall) === null || _a === void 0 ? void 0 : _a.start.point) ||
1215
+ undefined; }
1216
+ if (angle === void 0) { angle = 30; }
1217
+ if (!this.angleSnappingEnabled)
1218
+ return snapPoint;
1219
+ var point = snapPoint.point, locked = snapPoint.locked;
1220
+ if (locked[0] || locked[1])
1221
+ return snapPoint;
1222
+ if (!anchorPoint)
1223
+ return snapPoint;
1224
+ if (Math.abs(point[0] - anchorPoint[0]) < this.snapProximity) {
1225
+ return {
1226
+ type: types_1.SNAPPING_TYPES.ANGLE,
1227
+ point: [anchorPoint[0], point[1]],
1228
+ orientations: [types_1.GUIDE_ORIENTATIONS.VERTICAL],
1229
+ locked: [true, true],
1230
+ };
1231
+ }
1232
+ else if (Math.abs(point[1] - anchorPoint[1]) < this.snapProximity) {
1233
+ return {
1234
+ type: types_1.SNAPPING_TYPES.ANGLE,
1235
+ point: [point[0], anchorPoint[1]],
1236
+ orientations: [types_1.GUIDE_ORIENTATIONS.HORIZONTAL],
1237
+ locked: [true, true],
1238
+ };
1239
+ }
1240
+ for (var degrees = 0; degrees < 360; degrees += angle) {
1241
+ if (degrees === 0 || degrees % 90 === 0)
1242
+ continue;
1243
+ var radians = degrees * (Math.PI / 180);
1244
+ if ((0, geometry_1.getDistanceToLine)(anchorPoint, radians, point) < this.snapProximity)
1245
+ return {
1246
+ type: types_1.SNAPPING_TYPES.ANGLE,
1247
+ point: (0, geometry_1.closestPointOnLine)(anchorPoint, radians, point),
1248
+ orientations: [],
1249
+ locked: [true, true],
1250
+ };
1251
+ }
1252
+ return snapPoint;
1253
+ };
1254
+ SpacesState.prototype.getSnapVertexToGuideInProximity = function (snapPoint, vertexIndex) {
1255
+ if (!this.guideSnappingEnabled)
1256
+ return snapPoint;
1257
+ var locked = snapPoint.locked, point = snapPoint.point;
1258
+ if (locked[0] && locked[1])
1259
+ return snapPoint;
1260
+ var x = point[0], y = point[1];
1261
+ var outputSnapPoint;
1262
+ var anchorPoints = [];
1263
+ var orientations = new Set();
1264
+ var vertices = __spreadArray([], this.verticesList.map(function (_a) {
1265
+ var point = _a.point;
1266
+ return point;
1267
+ }), true);
1268
+ if (this._newWall)
1269
+ vertices.push(this._newWall.start.point);
1270
+ for (var i = 0; i < vertices.length &&
1271
+ (!orientations.has(types_1.GUIDE_ORIENTATIONS.VERTICAL) ||
1272
+ !orientations.has(types_1.GUIDE_ORIENTATIONS.HORIZONTAL)); i++) {
1273
+ if (vertexIndex === i)
1274
+ continue;
1275
+ var _a = vertices[i], xAnchor = _a[0], yAnchor = _a[1];
1276
+ if (!orientations.has(types_1.GUIDE_ORIENTATIONS.VERTICAL) &&
1277
+ Math.abs(x - xAnchor) < this.snapProximity) {
1278
+ outputSnapPoint = orientations.has(types_1.GUIDE_ORIENTATIONS.HORIZONTAL)
1279
+ ? [xAnchor, outputSnapPoint[1]]
1280
+ : [xAnchor, y];
1281
+ anchorPoints.push(vertices[i]);
1282
+ orientations.add(types_1.GUIDE_ORIENTATIONS.VERTICAL);
1283
+ locked[0] = true;
1284
+ }
1285
+ else if (!orientations.has(types_1.GUIDE_ORIENTATIONS.HORIZONTAL) &&
1286
+ Math.abs(y - yAnchor) < this.snapProximity) {
1287
+ outputSnapPoint = orientations.has(types_1.GUIDE_ORIENTATIONS.VERTICAL)
1288
+ ? [outputSnapPoint[0], yAnchor]
1289
+ : [x, yAnchor];
1290
+ anchorPoints.push(vertices[i]);
1291
+ orientations.add(types_1.GUIDE_ORIENTATIONS.HORIZONTAL);
1292
+ locked[1] = true;
1293
+ }
1294
+ }
1295
+ if (!outputSnapPoint)
1296
+ return snapPoint;
1297
+ return {
1298
+ type: types_1.SNAPPING_TYPES.GUIDE,
1299
+ point: outputSnapPoint,
1300
+ orientations: Array.from(orientations),
1301
+ locked: locked,
1302
+ };
1303
+ };
1304
+ SpacesState.prototype.getSnapActiveVertexToGuideInProximity = function (snapPoint) {
1305
+ if (!this._activeElement)
1306
+ return snapPoint;
1307
+ return this.getSnapVertexToGuideInProximity(snapPoint, this._activeElement.index);
1308
+ };
1309
+ SpacesState.prototype.getSnapPointToGridInProximity = function (snapPoint) {
1310
+ if (!this.gridSnappingEnabled)
1311
+ return snapPoint;
1312
+ var locked = snapPoint.locked, point = snapPoint.point;
1313
+ if (locked[0] && locked[1])
1314
+ return snapPoint;
1315
+ var _a = this.gridToDraw, showSubdivisions = _a.showSubdivisions, subdivisions = _a.subdivisions;
1316
+ var gridUnitLength = showSubdivisions
1317
+ ? this.gridUnitLength / subdivisions
1318
+ : this.gridUnitLength;
1319
+ var gridPoint = point.map(function (axis) { return Math.round(axis / gridUnitLength) * gridUnitLength; });
1320
+ if ((0, geometry_1.getLengthOfLineSegment)([point, gridPoint]) > this.snapProximity)
1321
+ return snapPoint;
1322
+ if ((!locked[0] && !locked[1]) ||
1323
+ (locked[0] && gridPoint[0] === point[0]) ||
1324
+ (locked[1] && gridPoint[1] === point[1]))
1325
+ return {
1326
+ type: types_1.SNAPPING_TYPES.GRID,
1327
+ point: gridPoint,
1328
+ locked: [true, true],
1329
+ orientations: types_1.SNAPPING_TYPES.ANGLE === snapPoint.type ||
1330
+ types_1.SNAPPING_TYPES.GUIDE === snapPoint.type
1331
+ ? snapPoint.orientations
1332
+ : [],
1333
+ };
1334
+ return snapPoint;
1335
+ };
1336
+ SpacesState.prototype.getFeatureAtPoint = function (point) {
1337
+ var _this = this;
1338
+ if (!point)
1339
+ return undefined;
1340
+ if (!this.featureCount)
1341
+ return undefined;
1342
+ var featuresMap = Object.entries(this.features);
1343
+ for (var i = 0; i < featuresMap.length; i++) {
1344
+ var _a = featuresMap[i], name_1 = _a[0], feature = _a[1];
1345
+ var index = feature.findIndex(function (feature) {
1346
+ var path = feature.path;
1347
+ if (!path) {
1348
+ var wallIndex = feature.connectedTo[1];
1349
+ var featureLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(_this.getWall(wallIndex).line, feature.offset, feature.length);
1350
+ path = (0, geometry_1.addThicknessToLine)(featureLine, _this.styles.feature.thickness);
1351
+ }
1352
+ return (0, geometry_1.isPointInQuadrilateral)(path, point);
1353
+ });
1354
+ if (index !== -1)
1355
+ return {
1356
+ type: name_1,
1357
+ index: index,
1358
+ };
1359
+ }
1360
+ return undefined;
1361
+ };
1362
+ SpacesState.prototype.getElementAddressAtPoint = function (point) {
1363
+ if (!point)
1364
+ return undefined;
1365
+ var snapToVertex = this.getSnapPointToVertexInProximity(point);
1366
+ if (snapToVertex !== undefined)
1367
+ return snapToVertex;
1368
+ if (this.featureCount) {
1369
+ var featureInProximity = this.getFeatureAtPoint(point);
1370
+ if (featureInProximity)
1371
+ return featureInProximity;
1372
+ }
1373
+ var wallInProximity = this.getWallIndexInProximity(point);
1374
+ if (wallInProximity !== undefined)
1375
+ return { type: types_1.IElements.WALL, index: wallInProximity };
1376
+ return undefined;
1377
+ };
1378
+ SpacesState.prototype.getElementUiAtPoint = function (cursorPoint) {
1379
+ var point = this.transformPointFromCanvas(cursorPoint);
1380
+ var element = this.getElementAddressAtPoint(point);
1381
+ if (!element)
1382
+ return;
1383
+ var uiAnchor;
1384
+ if (element.type === types_1.IElements.VERTEX)
1385
+ return;
1386
+ if (element.type === types_1.IElements.WALL)
1387
+ uiAnchor = this.getWallUiAnchorPoint(element.index);
1388
+ else
1389
+ uiAnchor = this.getFeatureUiAnchorPoint(element.type, element.index);
1390
+ if (!uiAnchor)
1391
+ return undefined;
1392
+ return {
1393
+ path: [element.type, element.index],
1394
+ uiAnchor: uiAnchor,
1395
+ };
1396
+ };
1397
+ SpacesState.prototype.getSnapPointToElementInProximity = function (point) {
1398
+ var feature = this.getFeatureAtPoint(point);
1399
+ if (feature)
1400
+ return __assign(__assign({}, feature), { point: point, locked: [true, true] });
1401
+ var snapToVertex = this.getSnapPointToVertexInProximity(point);
1402
+ if (snapToVertex)
1403
+ return snapToVertex;
1404
+ var snapToWall = this.getSnapPointToWallInProximity(point);
1405
+ if (snapToWall)
1406
+ return snapToWall;
1407
+ return {
1408
+ type: types_1.SNAPPING_TYPES.NONE,
1409
+ point: point,
1410
+ locked: [false, false],
1411
+ };
1412
+ };
1413
+ SpacesState.prototype.runValidators = function (validators, input) {
1414
+ return (0, validators_1.runValidators)(validators, input, { walls: this.walls, features: this.features }, this.validationConfig);
1415
+ };
1416
+ SpacesState.prototype.reevaluateFeatureConnections = function () {
1417
+ var _this = this;
1418
+ this.walls.forEach(function (_, i) { return _this.updateWall(i, { connections: [] }); });
1419
+ Object.entries(this.features).forEach(function (_a) {
1420
+ var type = _a[0], featuresArr = _a[1];
1421
+ return featuresArr.forEach(function (feature, i) {
1422
+ return _this.addFeatureToWall(feature.connectedTo[1], [type, i]);
1423
+ });
1424
+ });
1425
+ };
1426
+ SpacesState.prototype.pushStateToConfigurator = function () {
1427
+ return __awaiter(this, void 0, void 0, function () {
1428
+ var configuration;
1429
+ return __generator(this, function (_a) {
1430
+ switch (_a.label) {
1431
+ case 0:
1432
+ configuration = (0, dataHandlers_1.prepAttributesOutgoing)(this.walls, this.features, this._config);
1433
+ this._setPendingStatus(true);
1434
+ return [4, window.threekit.configurator.setConfiguration(configuration)];
1435
+ case 1:
1436
+ _a.sent();
1437
+ this._setPendingStatus(false);
1438
+ return [2];
1439
+ }
1440
+ });
1441
+ });
1442
+ };
1443
+ SpacesState.prototype.setAttributesToState = function (attributes) {
1444
+ if (!attributes)
1445
+ return;
1446
+ this._attributesState = attributes;
1447
+ var data = (0, dataHandlers_1.prepAttributesIncoming)(attributes, this._config, __assign(__assign({}, this.attributeDefaults), { wallMode: this.wallMode.value }));
1448
+ this.validationConfig = data.validationConfig;
1449
+ this.walls = data[types_1.IElements.WALL];
1450
+ this.vertices = data[types_1.IElements.VERTEX];
1451
+ this.features = data[types_1.IElements.FEATURE];
1452
+ this.reevaluateFeatureConnections();
1453
+ };
1454
+ SpacesState.prototype.deleteAll = function () {
1455
+ this.walls = [];
1456
+ this.vertices = {};
1457
+ this.features = Object.keys(this.features).reduce(function (output, type) {
1458
+ var _a;
1459
+ return Object.assign(output, (_a = {}, _a[type] = [], _a));
1460
+ }, {});
1461
+ this.pushStateToConfigurator();
1462
+ };
1463
+ SpacesState.prototype.resetInternalState = function () {
1464
+ if (this._attributesState)
1465
+ this.setAttributesToState(this._attributesState);
1466
+ };
1467
+ SpacesState.prototype.highlightElementIfInProximity = function (canvas, cursorPoint) {
1468
+ var _a, _b;
1469
+ var point = this.transformPointFromCanvas(cursorPoint);
1470
+ var elementAtPoint = this.getElementAddressAtPoint(point);
1471
+ if ((!elementAtPoint && !this._highlightedElement) ||
1472
+ Array.isArray(this._highlightedElement))
1473
+ return;
1474
+ if (elementAtPoint) {
1475
+ var type = elementAtPoint.type, index = elementAtPoint.index;
1476
+ if (((_a = this._highlightedElement) === null || _a === void 0 ? void 0 : _a.type) === type &&
1477
+ ((_b = this._highlightedElement) === null || _b === void 0 ? void 0 : _b.index) === index)
1478
+ return;
1479
+ }
1480
+ this._highlightedElement = elementAtPoint !== null && elementAtPoint !== void 0 ? elementAtPoint : null;
1481
+ this.drawSpaces(canvas);
1482
+ };
1483
+ SpacesState.prototype.centerSpace = function (canvas, zoomToFit) {
1484
+ if (zoomToFit === void 0) { zoomToFit = true; }
1485
+ if (!canvas)
1486
+ return;
1487
+ if (!this.verticesList.length)
1488
+ return;
1489
+ var _a = this.verticesList.reduce(function (output, _a, i) {
1490
+ var point = _a.point;
1491
+ if (!i)
1492
+ return {
1493
+ xMin: point[0],
1494
+ yMin: point[1],
1495
+ xMax: point[0],
1496
+ yMax: point[1],
1497
+ };
1498
+ if (point[0] < output.xMin)
1499
+ output.xMin = point[0];
1500
+ if (point[1] < output.yMin)
1501
+ output.yMin = point[1];
1502
+ if (point[0] > output.xMax)
1503
+ output.xMax = point[0];
1504
+ if (point[1] > output.yMax)
1505
+ output.yMax = point[1];
1506
+ return output;
1507
+ }, { xMin: 0, yMin: 0, xMax: 0, yMax: 0 }), xMin = _a.xMin, yMin = _a.yMin, xMax = _a.xMax, yMax = _a.yMax;
1508
+ var centerPoint = [(xMin + xMax) / 2, (yMin + yMax) / 2];
1509
+ this._translate = [
1510
+ canvas.width / 2 - centerPoint[0],
1511
+ canvas.height / 2 - centerPoint[1],
1512
+ ];
1513
+ if (zoomToFit)
1514
+ this.zoomFactor = Math.min((canvas.width - 80) / (xMax - xMin), (canvas.height - 80) / (yMax - yMin));
1515
+ this.drawSpaces(canvas);
1516
+ };
1517
+ SpacesState.prototype.showGuideAtPoint = function (canvas, cursorPoint) {
1518
+ var _this = this;
1519
+ if (!this.guideSnappingEnabled)
1520
+ return;
1521
+ var clearGuides = function () {
1522
+ if (!_this.guides)
1523
+ return;
1524
+ _this.guides = null;
1525
+ _this.drawSpaces(canvas);
1526
+ };
1527
+ var point = this.transformPointFromCanvas(cursorPoint);
1528
+ var elementAtPoint = this.getElementAddressAtPoint(point);
1529
+ if (elementAtPoint) {
1530
+ clearGuides();
1531
+ if (elementAtPoint.type === types_1.IElements.WALL ||
1532
+ elementAtPoint.type === types_1.IElements.VERTEX) {
1533
+ this._highlightedElement = elementAtPoint;
1534
+ this.drawSpaces(canvas);
1535
+ }
1536
+ return;
1537
+ }
1538
+ else if (this._highlightedElement) {
1539
+ this._highlightedElement = null;
1540
+ this.drawSpaces(canvas);
1541
+ }
1542
+ var snapPoint = this.getSnapVertexToGuideInProximity({
1543
+ type: types_1.SNAPPING_TYPES.NONE,
1544
+ point: point,
1545
+ locked: [false, false],
1546
+ }) || null;
1547
+ if (snapPoint.type === types_1.SNAPPING_TYPES.NONE) {
1548
+ clearGuides();
1549
+ return;
1550
+ }
1551
+ else if (snapPoint.type === types_1.SNAPPING_TYPES.GUIDE) {
1552
+ this.guides = snapPoint;
1553
+ this.drawSpaces(canvas);
1554
+ }
1555
+ };
1556
+ SpacesState.prototype.startDrawNewWall = function (startPoint) {
1557
+ if (this.guides) {
1558
+ this._newWall = {
1559
+ start: __assign(__assign({ type: types_1.SNAPPING_TYPES.GUIDE }, this.guides), { locked: [true, true] }),
1560
+ };
1561
+ return;
1562
+ }
1563
+ var point = this.transformPointFromCanvas(startPoint);
1564
+ var snapPoint = this.getSnapPointToElementInProximity(point);
1565
+ snapPoint = this.getSnapPointToGridInProximity(snapPoint);
1566
+ if (snapPoint.type === types_1.IElements.WINDOW ||
1567
+ snapPoint.type === types_1.IElements.DOOR ||
1568
+ snapPoint.type === types_1.IElements.OPENING)
1569
+ return;
1570
+ this._newWall = {
1571
+ start: snapPoint,
1572
+ };
1573
+ };
1574
+ SpacesState.prototype.drawNewWall = function (canvas, endPoint) {
1575
+ var _a;
1576
+ if (!this._newWall)
1577
+ return;
1578
+ var point = this.transformPointFromCanvas(endPoint);
1579
+ var snapPoint = this.getSnapPointToElementInProximity(point);
1580
+ snapPoint = this.getSnapVertexToGuideInProximity(snapPoint);
1581
+ snapPoint = this.getSnapPointToAngleInProximity(snapPoint);
1582
+ snapPoint = this.getSnapPointToGridInProximity(snapPoint);
1583
+ if (this.guideSnappingEnabled) {
1584
+ if (snapPoint.type === types_1.SNAPPING_TYPES.GUIDE ||
1585
+ snapPoint.type === types_1.SNAPPING_TYPES.ANGLE ||
1586
+ snapPoint.type === types_1.SNAPPING_TYPES.GRID)
1587
+ this.guides = snapPoint;
1588
+ else if (this.guides)
1589
+ this.guides = null;
1590
+ }
1591
+ var wallLine = [
1592
+ this._newWall.start.point,
1593
+ snapPoint.point,
1594
+ ];
1595
+ var validationData = {
1596
+ newWall: __assign({ line: wallLine }, this._newWall),
1597
+ };
1598
+ this._errorElement = this.runValidators([
1599
+ validators_1.isWallEndingOnFeature,
1600
+ validators_1.isWallTooShort,
1601
+ validators_1.isWallOverlappingExisitingWalls,
1602
+ validators_1.isWallIntersectingFeature,
1603
+ ], validationData);
1604
+ var errorType = ((_a = this._errorElement) === null || _a === void 0 ? void 0 : _a[0].type) || null;
1605
+ switch (errorType) {
1606
+ case types_1.IErrorTypes.HARD:
1607
+ return;
1608
+ case types_1.IErrorTypes.SOFT:
1609
+ case types_1.IErrorTypes.WARN:
1610
+ case null:
1611
+ default:
1612
+ this._newWall.end = snapPoint || { type: types_1.SNAPPING_TYPES.NONE, point: point };
1613
+ this.drawSpaces(canvas);
1614
+ break;
1615
+ }
1616
+ };
1617
+ SpacesState.prototype.cancelDrawNewWall = function (canvas) {
1618
+ this._newWall = null;
1619
+ this._errorElement = null;
1620
+ this._highlightedElement = null;
1621
+ this.guides = null;
1622
+ this.drawSpaces(canvas);
1623
+ };
1624
+ SpacesState.prototype.finishDrawNewWall = function (canvas, assetId) {
1625
+ return __awaiter(this, void 0, void 0, function () {
1626
+ var newWallAssetId, _a, start, end, wallsToExclude, filteredWalls, intersections, newWallLines;
1627
+ var _this = this;
1628
+ return __generator(this, function (_b) {
1629
+ if (this._errorElement) {
1630
+ if ([this._errorElement].flat()[0].message)
1631
+ __1.message.info([this._errorElement].flat()[0].message);
1632
+ this._newWall = null;
1633
+ this._errorElement = null;
1634
+ this._highlightedElement = null;
1635
+ this.drawSpaces(canvas);
1636
+ return [2];
1637
+ }
1638
+ newWallAssetId = assetId || this.attributeDefaults[types_1.IElements.WALL];
1639
+ if (!newWallAssetId)
1640
+ return [2];
1641
+ _a = this._newWall || {}, start = _a.start, end = _a.end;
1642
+ if (!start || !end) {
1643
+ this._newWall = null;
1644
+ this._errorElement = null;
1645
+ this._highlightedElement = null;
1646
+ return [2];
1647
+ }
1648
+ wallsToExclude = new Set([]);
1649
+ if (start.type === types_1.IElements.WALL) {
1650
+ this.splitWallAtPoint(start.index, start.point);
1651
+ wallsToExclude.add(start.index);
1652
+ }
1653
+ if (end.type === types_1.IElements.WALL) {
1654
+ this.splitWallAtPoint(end.index, end.point);
1655
+ wallsToExclude.add(end.index);
1656
+ }
1657
+ if (wallsToExclude.size === 1)
1658
+ wallsToExclude.add(this.wallCount - 1);
1659
+ else if (wallsToExclude.size === 2)
1660
+ wallsToExclude.add(this.wallCount - 1).add(this.wallCount - 2);
1661
+ filteredWalls = this.walls.map(function (wall, i) {
1662
+ return wallsToExclude.has(i) ? null : wall.line;
1663
+ });
1664
+ intersections = (0, geometry_1.getAllLineIntersections)([start.point, end.point], filteredWalls);
1665
+ intersections.forEach(function (_a) {
1666
+ var index = _a.index, point = _a.point;
1667
+ return _this.splitWallAtPoint(index, point);
1668
+ });
1669
+ newWallLines = (0, geometry_1.splitLineAtPoints)([start.point, end.point], intersections.map(function (_a) {
1670
+ var point = _a.point;
1671
+ return point;
1672
+ }));
1673
+ this.addWalls(newWallLines.map(function (line) {
1674
+ var _a;
1675
+ return ({
1676
+ assetId: newWallAssetId,
1677
+ line: line,
1678
+ connections: [],
1679
+ restConfiguration: JSON.stringify((_a = {},
1680
+ _a[_this._config.attributes.wallMode] = {
1681
+ assetId: _this.wallMode.assetId,
1682
+ },
1683
+ _a)),
1684
+ mode: _this.wallMode.value,
1685
+ });
1686
+ }));
1687
+ this._newWall = null;
1688
+ this._errorElement = null;
1689
+ this._highlightedElement = null;
1690
+ this.guides = null;
1691
+ this.pushStateToConfigurator();
1692
+ return [2];
1693
+ });
1694
+ });
1695
+ };
1696
+ SpacesState.prototype.selectElementIfInProximity = function (canvas, cursorPoint) {
1697
+ var point = this.transformPointFromCanvas(cursorPoint);
1698
+ var elementAtPoint = this.getElementAddressAtPoint(point);
1699
+ if (!elementAtPoint || elementAtPoint.type === types_1.IElements.WALL)
1700
+ return;
1701
+ this._activeElement = elementAtPoint;
1702
+ if (elementAtPoint.type === types_1.IElements.VERTEX) {
1703
+ var wallIndexes = this.getWallsConnectedToVertex(elementAtPoint.index);
1704
+ this._highlightedElement = wallIndexes.map(function (index) { return ({
1705
+ type: types_1.IElements.WALL,
1706
+ index: index,
1707
+ }); });
1708
+ }
1709
+ this.drawSpaces(canvas);
1710
+ };
1711
+ SpacesState.prototype.moveActiveElement = function (canvas, moveToPoint) {
1712
+ if (!canvas)
1713
+ return;
1714
+ if (!this._activeElement)
1715
+ return;
1716
+ var point = this.transformPointFromCanvas(moveToPoint);
1717
+ var type = this._activeElement.type;
1718
+ if (type === types_1.IElements.VERTEX)
1719
+ this.moveActiveVertex(canvas, point);
1720
+ else if (type === types_1.IElements.WINDOW ||
1721
+ type === types_1.IElements.DOOR ||
1722
+ type === types_1.IElements.OPENING)
1723
+ this.moveActiveFeature(canvas, point);
1724
+ };
1725
+ SpacesState.prototype.finishMoveActiveElement = function (canvas) {
1726
+ if (!this._activeElement)
1727
+ return;
1728
+ if (this._errorElement) {
1729
+ if ([this._errorElement].flat()[0].message)
1730
+ __1.message.info([this._errorElement].flat()[0].message);
1731
+ this._activeElement = null;
1732
+ this._errorElement = null;
1733
+ this._highlightedElement = null;
1734
+ this.resetInternalState();
1735
+ this.drawSpaces(canvas);
1736
+ return;
1737
+ }
1738
+ var type = this._activeElement.type;
1739
+ if (type === types_1.IElements.VERTEX)
1740
+ this.finishMoveActiveVertex();
1741
+ else if (type === types_1.IElements.WINDOW ||
1742
+ type === types_1.IElements.DOOR ||
1743
+ type === types_1.IElements.OPENING)
1744
+ this.finishMoveActiveFeature();
1745
+ this._activeElement = null;
1746
+ this._errorElement = null;
1747
+ this._highlightedElement = null;
1748
+ this.drawSpaces(canvas);
1749
+ };
1750
+ SpacesState.prototype.cancelMoveActiveElement = function (canvas) {
1751
+ this._activeElement = null;
1752
+ this._errorElement = null;
1753
+ this._highlightedElement = null;
1754
+ this.resetInternalState();
1755
+ this.drawSpaces(canvas);
1756
+ };
1757
+ SpacesState.prototype.drawSpaces = function (canvas) {
1758
+ var _a, _b, _c, _d, _e, _f, _g;
1759
+ if (!canvas)
1760
+ return;
1761
+ var highlighted = this._highlightedElement
1762
+ ? [this._highlightedElement].flat()
1763
+ : [];
1764
+ var active = this._activeElement && this._activeElement.type !== types_1.IElements.VERTEX
1765
+ ? [this._activeElement]
1766
+ : [];
1767
+ var error = this._errorElement
1768
+ ? [this._errorElement]
1769
+ .flat()
1770
+ .reduce(function (output, _a) {
1771
+ var address = _a.address;
1772
+ return (address ? __spreadArray(__spreadArray([], output, true), [address], false) : output);
1773
+ }, [])
1774
+ : [];
1775
+ var hidden = ((_a = this._activeElement) === null || _a === void 0 ? void 0 : _a.type) === types_1.IElements.VERTEX
1776
+ ? [this._activeElement]
1777
+ : [];
1778
+ if (this.selectedElement)
1779
+ highlighted.push(this.selectedElement);
1780
+ var selection = {
1781
+ highlighted: highlighted,
1782
+ active: active,
1783
+ error: error,
1784
+ hidden: hidden,
1785
+ };
1786
+ var activeWallIndex;
1787
+ if (this._showDimensions &&
1788
+ (((_b = this._activeElement) === null || _b === void 0 ? void 0 : _b.type) === types_1.IElements.WINDOW ||
1789
+ ((_c = this._activeElement) === null || _c === void 0 ? void 0 : _c.type) === types_1.IElements.DOOR ||
1790
+ ((_d = this._activeElement) === null || _d === void 0 ? void 0 : _d.type) === types_1.IElements.OPENING))
1791
+ activeWallIndex = (_e = this.getFeature(this._activeElement.type, this._activeElement.index)) === null || _e === void 0 ? void 0 : _e.connectedTo[1];
1792
+ var guides = this.guides
1793
+ ? __assign(__assign({}, this.guides), { point: this.transformPointToCanvas(this.guides.point) }) : this.guides;
1794
+ (0, draw_1.drawSpaces)(canvas, this.gridToDraw, this.enclosedSpacesToDraw, this.wallsToDraw, this.verticesListToDraw, this.featuresToDraw, this.getDimensionToDraw(activeWallIndex), guides, selection, this._config.config);
1795
+ if (((_f = this._newWall) === null || _f === void 0 ? void 0 : _f.start) && ((_g = this._newWall) === null || _g === void 0 ? void 0 : _g.end)) {
1796
+ var newWallLine = [
1797
+ this._newWall.start.point,
1798
+ this._newWall.end.point,
1799
+ ];
1800
+ (0, draw_1.drawNewWall)(canvas, this.transformLineToCanvas(newWallLine), this.wallMode.value, this.styles, this._errorElement ? types_1.IElementStyleModes.ERROR : undefined);
1801
+ if (this._showDimensions) {
1802
+ (0, draw_1.drawDimensions)(canvas, [
1803
+ {
1804
+ label: this.getWallDimensions(newWallLine).label,
1805
+ line: this.transformLineToCanvas(newWallLine),
1806
+ },
1807
+ ], this._config.config);
1808
+ }
1809
+ }
1810
+ };
1811
+ return SpacesState;
1812
+ }());
1813
+ exports.SpacesState = SpacesState;
1814
+ exports.default = SpacesState;