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