@threekit-tools/treble 0.0.89 → 0.0.90-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 (159) hide show
  1. package/dist/Treble/Treble.d.ts +1 -1
  2. package/dist/Treble/Treble.js +3 -3
  3. package/dist/components/AttributeValue/index.js +2 -0
  4. package/dist/components/BreatheAnimation/index.js +2 -2
  5. package/dist/components/TurntableAnimation/index.js +2 -2
  6. package/dist/components/Wishlist/index.d.ts +1 -1
  7. package/dist/components/Zoom/index.d.ts +1 -1
  8. package/dist/components/containers/formInputContainer.d.ts +1 -1
  9. package/dist/components/containers/formInputContainer.js +3 -3
  10. package/dist/hooks/useConfigurationChangeStatus/index.d.ts +2 -0
  11. package/dist/hooks/{usePlayerLoadingStatus → useConfigurationChangeStatus}/index.js +2 -2
  12. package/dist/hooks/useNestedConfigurator/index.js +1 -2
  13. package/dist/hooks/usePlayerReady/index.d.ts +2 -0
  14. package/dist/hooks/{useAnimationStart → usePlayerReady}/index.js +2 -2
  15. package/dist/hooks/useRoomBuilder/RoomBuilderLayout.d.ts +8 -0
  16. package/dist/hooks/useRoomBuilder/RoomBuilderLayout.js +22 -0
  17. package/dist/hooks/useRoomBuilder/RoomBuilderState.d.ts +132 -0
  18. package/dist/hooks/useRoomBuilder/RoomBuilderState.js +1431 -0
  19. package/dist/hooks/useRoomBuilder/constants.d.ts +56 -0
  20. package/dist/hooks/useRoomBuilder/constants.js +63 -0
  21. package/dist/hooks/useRoomBuilder/dataHandlers.d.ts +18 -0
  22. package/dist/hooks/useRoomBuilder/dataHandlers.js +187 -0
  23. package/dist/hooks/useRoomBuilder/draw.d.ts +55 -0
  24. package/dist/hooks/useRoomBuilder/draw.js +573 -0
  25. package/dist/hooks/useRoomBuilder/findLoops.d.ts +5 -0
  26. package/dist/hooks/useRoomBuilder/findLoops.js +99 -0
  27. package/dist/hooks/useRoomBuilder/geometry.d.ts +33 -0
  28. package/dist/hooks/useRoomBuilder/geometry.js +325 -0
  29. package/dist/hooks/useRoomBuilder/index.d.ts +57 -0
  30. package/dist/hooks/useRoomBuilder/index.js +411 -0
  31. package/dist/hooks/useRoomBuilder/messaging.d.ts +8 -0
  32. package/dist/hooks/useRoomBuilder/messaging.js +18 -0
  33. package/dist/hooks/useRoomBuilder/themes.d.ts +12 -0
  34. package/dist/hooks/useRoomBuilder/themes.js +273 -0
  35. package/dist/hooks/useRoomBuilder/types.d.ts +247 -0
  36. package/dist/hooks/useRoomBuilder/types.js +40 -0
  37. package/dist/hooks/useRoomBuilder/validators.d.ts +36 -0
  38. package/dist/hooks/useRoomBuilder/validators.js +362 -0
  39. package/dist/icons/Add.d.ts +1 -1
  40. package/dist/icons/Add.js +3 -3
  41. package/dist/icons/Angle.d.ts +3 -0
  42. package/dist/icons/Angle.js +21 -0
  43. package/dist/icons/ArrowLeft.d.ts +1 -1
  44. package/dist/icons/ArrowLeft.js +3 -3
  45. package/dist/icons/ArrowRight.d.ts +1 -1
  46. package/dist/icons/ArrowRight.js +3 -3
  47. package/dist/icons/Camera.d.ts +1 -1
  48. package/dist/icons/Camera.js +3 -3
  49. package/dist/icons/CaretDown.d.ts +1 -1
  50. package/dist/icons/CaretDown.js +3 -3
  51. package/dist/icons/CaretLeft.d.ts +1 -1
  52. package/dist/icons/CaretLeft.js +3 -3
  53. package/dist/icons/CaretRight.d.ts +1 -1
  54. package/dist/icons/CaretRight.js +3 -3
  55. package/dist/icons/CaretUp.d.ts +1 -1
  56. package/dist/icons/CaretUp.js +3 -3
  57. package/dist/icons/Cart.d.ts +1 -1
  58. package/dist/icons/Cart.js +3 -3
  59. package/dist/icons/Checkmate.d.ts +1 -1
  60. package/dist/icons/Checkmate.js +3 -3
  61. package/dist/icons/Clipboard.d.ts +1 -1
  62. package/dist/icons/Clipboard.js +3 -3
  63. package/dist/icons/ColorPicker.d.ts +1 -1
  64. package/dist/icons/ColorPicker.js +3 -3
  65. package/dist/icons/Copy.d.ts +1 -1
  66. package/dist/icons/Copy.js +3 -3
  67. package/dist/icons/Cursor.d.ts +3 -0
  68. package/dist/icons/Cursor.js +21 -0
  69. package/dist/icons/Delete.d.ts +1 -1
  70. package/dist/icons/Delete.js +3 -3
  71. package/dist/icons/Door.d.ts +3 -0
  72. package/dist/icons/Door.js +22 -0
  73. package/dist/icons/DoubleCaretLeft.d.ts +1 -1
  74. package/dist/icons/DoubleCaretLeft.js +3 -3
  75. package/dist/icons/DoubleCaretRight.d.ts +1 -1
  76. package/dist/icons/DoubleCaretRight.js +3 -3
  77. package/dist/icons/Download.d.ts +1 -1
  78. package/dist/icons/Download.js +3 -3
  79. package/dist/icons/Drag.d.ts +1 -1
  80. package/dist/icons/Drag.js +3 -3
  81. package/dist/icons/Draggable.d.ts +1 -1
  82. package/dist/icons/Draggable.js +3 -3
  83. package/dist/icons/Draw.d.ts +3 -0
  84. package/dist/icons/Draw.js +21 -0
  85. package/dist/icons/Edit.d.ts +1 -1
  86. package/dist/icons/Edit.js +3 -3
  87. package/dist/icons/Heart.d.ts +1 -1
  88. package/dist/icons/Heart.js +3 -3
  89. package/dist/icons/Image.d.ts +1 -1
  90. package/dist/icons/Image.js +3 -3
  91. package/dist/icons/Info.d.ts +1 -1
  92. package/dist/icons/Info.js +3 -3
  93. package/dist/icons/Layout.d.ts +3 -0
  94. package/dist/icons/Layout.js +21 -0
  95. package/dist/icons/Mail.d.ts +1 -1
  96. package/dist/icons/Mail.js +3 -3
  97. package/dist/icons/Menu.d.ts +1 -1
  98. package/dist/icons/Menu.js +3 -3
  99. package/dist/icons/More.d.ts +1 -1
  100. package/dist/icons/More.js +3 -3
  101. package/dist/icons/NewWindow.d.ts +1 -1
  102. package/dist/icons/NewWindow.js +3 -3
  103. package/dist/icons/Opening.d.ts +3 -0
  104. package/dist/icons/Opening.js +21 -0
  105. package/dist/icons/Pause.d.ts +1 -1
  106. package/dist/icons/Pause.js +3 -3
  107. package/dist/icons/Play.d.ts +1 -1
  108. package/dist/icons/Play.js +3 -3
  109. package/dist/icons/Player3D.d.ts +3 -0
  110. package/dist/icons/Player3D.js +21 -0
  111. package/dist/icons/Redo.d.ts +1 -1
  112. package/dist/icons/Redo.js +3 -3
  113. package/dist/icons/Remove.d.ts +1 -1
  114. package/dist/icons/Remove.js +3 -3
  115. package/dist/icons/Ruler.d.ts +1 -1
  116. package/dist/icons/Ruler.js +3 -3
  117. package/dist/icons/Search.d.ts +1 -1
  118. package/dist/icons/Search.js +3 -3
  119. package/dist/icons/Settings.d.ts +1 -1
  120. package/dist/icons/Settings.js +3 -3
  121. package/dist/icons/Share.d.ts +1 -1
  122. package/dist/icons/Share.js +3 -3
  123. package/dist/icons/Switch.d.ts +1 -1
  124. package/dist/icons/Switch.js +3 -3
  125. package/dist/icons/Tag.d.ts +1 -1
  126. package/dist/icons/Tag.js +3 -3
  127. package/dist/icons/TrashCan.d.ts +3 -0
  128. package/dist/icons/TrashCan.js +21 -0
  129. package/dist/icons/TrashCanAlt.d.ts +3 -0
  130. package/dist/icons/TrashCanAlt.js +21 -0
  131. package/dist/icons/Undo.d.ts +1 -1
  132. package/dist/icons/Undo.js +3 -3
  133. package/dist/icons/Wall.d.ts +3 -0
  134. package/dist/icons/Wall.js +21 -0
  135. package/dist/icons/Window.d.ts +3 -0
  136. package/dist/icons/Window.js +22 -0
  137. package/dist/icons/Wishlist.d.ts +1 -1
  138. package/dist/icons/Wishlist.js +3 -3
  139. package/dist/icons/ZoomIn.d.ts +1 -1
  140. package/dist/icons/ZoomIn.js +3 -3
  141. package/dist/icons/ZoomOut.d.ts +1 -1
  142. package/dist/icons/ZoomOut.js +3 -3
  143. package/dist/icons/index.d.ts +2 -6
  144. package/dist/icons/index.js +22 -0
  145. package/dist/icons/types.d.ts +7 -0
  146. package/dist/icons/types.js +2 -0
  147. package/dist/index.d.ts +17 -2
  148. package/dist/index.js +35 -4
  149. package/dist/store/attributes.d.ts +1 -0
  150. package/dist/store/index.d.ts +39 -8
  151. package/dist/store/index.js +3 -1
  152. package/dist/store/roomBuilder.d.ts +38 -0
  153. package/dist/store/roomBuilder.js +174 -0
  154. package/dist/store/treble.js +12 -6
  155. package/dist/types.d.ts +46 -7
  156. package/dist/types.js +1 -0
  157. package/package.json +1 -1
  158. package/dist/hooks/useAnimationStart/index.d.ts +0 -2
  159. package/dist/hooks/usePlayerLoadingStatus/index.d.ts +0 -2
@@ -0,0 +1,1431 @@
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.RoomBuilderState = void 0;
60
+ var types_1 = require("./types");
61
+ var types_2 = require("./types");
62
+ var validators_1 = require("./validators");
63
+ var geometry_1 = require("./geometry");
64
+ var draw_1 = require("./draw");
65
+ var dataHandlers_1 = require("./dataHandlers");
66
+ var __1 = require("../..");
67
+ var constants_1 = require("./constants");
68
+ var findLoops_1 = require("./findLoops");
69
+ var RoomBuilderState = (function () {
70
+ function RoomBuilderState(config) {
71
+ var _a;
72
+ var _this = this;
73
+ this.moveActiveVertex = function (canvas, point) {
74
+ var _a, _b, _c, _d;
75
+ if (!canvas)
76
+ return;
77
+ if (((_a = _this._activeElement) === null || _a === void 0 ? void 0 : _a.type) !== types_2.IElements.VERTEX)
78
+ return;
79
+ var snapPoint = _this.getPointProximity(point);
80
+ if (!snapPoint && _this._angleSnappingEnabled)
81
+ snapPoint = _this.snapVertexToAbsoluteAngle(_this._activeElement.index, point);
82
+ var vertex = _this.getVertex(_this._activeElement.index);
83
+ if (!vertex)
84
+ return;
85
+ var validationData = {
86
+ vertex: vertex,
87
+ walls: _this.walls,
88
+ updatedPosition: {
89
+ point: point,
90
+ snapTo: snapPoint,
91
+ },
92
+ features: _this.features,
93
+ };
94
+ _this._errorElement = (0, validators_1.runValidators)([
95
+ validators_1.isVertexLandingOnFeature,
96
+ validators_1.areWallsTooShort,
97
+ validators_1.areWallsIntersecting,
98
+ validators_1.areWallsOrphaningFeatures,
99
+ validators_1.areWallsDuplicated,
100
+ ], validationData);
101
+ var errorType = ((_b = _this._errorElement) === null || _b === void 0 ? void 0 : _b[0].type) || null;
102
+ switch (errorType) {
103
+ case types_1.IErrorTypes.HARD:
104
+ return;
105
+ case types_1.IErrorTypes.SOFT:
106
+ case types_1.IErrorTypes.WARN:
107
+ case null:
108
+ default:
109
+ _this._activeElement.snapPoint = snapPoint;
110
+ _this.repositionVertex(_this._activeElement.index, (_c = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _c !== void 0 ? _c : point);
111
+ _this.drawRoom(canvas);
112
+ (0, draw_1.drawVertex)(canvas, _this.transformPointToCanvas((_d = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _d !== void 0 ? _d : point), _this._config.config.styles.vertex, types_1.IElementStyleModes.HIGHLIGHT);
113
+ break;
114
+ }
115
+ };
116
+ this.finishMoveActiveVertex = function () {
117
+ var _a, _b;
118
+ if (((_a = _this._activeElement) === null || _a === void 0 ? void 0 : _a.type) !== types_2.IElements.VERTEX)
119
+ return;
120
+ if (((_b = _this._activeElement.snapPoint) === null || _b === void 0 ? void 0 : _b.type) === types_2.IElements.WALL)
121
+ _this.splitWall(_this._activeElement.snapPoint.index, _this._activeElement.snapPoint.point);
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_2.IElements.WINDOW &&
130
+ type !== types_2.IElements.DOOR &&
131
+ type !== types_2.IElements.OPENING)
132
+ return;
133
+ var feature = _this.getFeature(type, index);
134
+ if (!feature)
135
+ return;
136
+ var wallIndex = (_a = _this.getWallInProximity(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 newOffset = intersection.offset - feature.length / 2;
144
+ var featureUpdatesToValidate = {
145
+ length: feature.length,
146
+ offset: newOffset,
147
+ address: { type: type, index: index },
148
+ };
149
+ _this._errorElement = (0, validators_1.runValidators)([validators_1.isFeatureOutsideWallBounds, validators_1.isFeatureCollidingWithExistingFeature], {
150
+ wall: wall,
151
+ features: _this.features,
152
+ updatedFeature: featureUpdatesToValidate,
153
+ });
154
+ var errorType = ((_b = _this._errorElement) === null || _b === void 0 ? void 0 : _b[0].type) || null;
155
+ switch (errorType) {
156
+ case types_1.IErrorTypes.HARD:
157
+ return;
158
+ case types_1.IErrorTypes.SOFT:
159
+ _this.drawRoom(canvas);
160
+ break;
161
+ case types_1.IErrorTypes.WARN:
162
+ case null:
163
+ default:
164
+ _this.repositionFeature([type, index], newOffset, wallIndex);
165
+ _this.drawRoom(canvas);
166
+ break;
167
+ }
168
+ };
169
+ this.finishMoveActiveFeature = function () {
170
+ var _a;
171
+ var type = (_a = _this._activeElement) === null || _a === void 0 ? void 0 : _a.type;
172
+ if (!type)
173
+ return;
174
+ if (type !== types_2.IElements.WINDOW &&
175
+ type !== types_2.IElements.DOOR &&
176
+ type !== types_2.IElements.OPENING)
177
+ return;
178
+ _this.pushStateToConfigurator();
179
+ };
180
+ this._config = config;
181
+ this._newWall = null;
182
+ this._activeElement = null;
183
+ this._selectedElement = null;
184
+ this._highlightedElement = null;
185
+ this._errorElement = null;
186
+ this._state = (_a = {},
187
+ _a[types_2.IElements.WALL] = [],
188
+ _a[types_2.IElements.VERTEX] = {},
189
+ _a[types_2.IElements.FEATURE] = {},
190
+ _a);
191
+ this._showDimensions = true;
192
+ this._angleSnappingEnabled = true;
193
+ this._attributesState = null;
194
+ this._canvasDimensions = [0, 0];
195
+ this._zoom = config.config.zoomDefault;
196
+ this._zoomLimits = [constants_1.ZOOM_MIN, constants_1.ZOOM_MAX];
197
+ this._translate = config.config.translateDefault;
198
+ this._translateLimits = [constants_1.TRANSLATE_MIN, constants_1.TRANSLATE_MAX];
199
+ }
200
+ Object.defineProperty(RoomBuilderState.prototype, "walls", {
201
+ get: function () {
202
+ return this._state[types_2.IElements.WALL];
203
+ },
204
+ set: function (walls) {
205
+ this._state[types_2.IElements.WALL] = walls;
206
+ },
207
+ enumerable: false,
208
+ configurable: true
209
+ });
210
+ Object.defineProperty(RoomBuilderState.prototype, "wallsToDraw", {
211
+ get: function () {
212
+ var _this = this;
213
+ return this._state[types_2.IElements.WALL].map(function (wall) { return (__assign(__assign({}, wall), { line: _this.transformLineToCanvas(wall.line), path: undefined })); });
214
+ },
215
+ enumerable: false,
216
+ configurable: true
217
+ });
218
+ Object.defineProperty(RoomBuilderState.prototype, "wallCount", {
219
+ get: function () {
220
+ return this.walls.length;
221
+ },
222
+ enumerable: false,
223
+ configurable: true
224
+ });
225
+ Object.defineProperty(RoomBuilderState.prototype, "wallLines", {
226
+ get: function () {
227
+ return this.walls.map(function (_a) {
228
+ var line = _a.line;
229
+ return line;
230
+ });
231
+ },
232
+ enumerable: false,
233
+ configurable: true
234
+ });
235
+ Object.defineProperty(RoomBuilderState.prototype, "vertices", {
236
+ get: function () {
237
+ return this._state[types_2.IElements.VERTEX];
238
+ },
239
+ set: function (vertices) {
240
+ this._state[types_2.IElements.VERTEX] = vertices;
241
+ },
242
+ enumerable: false,
243
+ configurable: true
244
+ });
245
+ Object.defineProperty(RoomBuilderState.prototype, "verticesToDraw", {
246
+ get: function () {
247
+ return this._state[types_2.IElements.VERTEX];
248
+ },
249
+ enumerable: false,
250
+ configurable: true
251
+ });
252
+ Object.defineProperty(RoomBuilderState.prototype, "verticesList", {
253
+ get: function () {
254
+ return Object.entries(this.vertices).map(function (_a) {
255
+ var pointStr = _a[0], connections = _a[1];
256
+ return ({
257
+ point: JSON.parse(pointStr),
258
+ connections: connections,
259
+ });
260
+ });
261
+ },
262
+ enumerable: false,
263
+ configurable: true
264
+ });
265
+ Object.defineProperty(RoomBuilderState.prototype, "verticesListToDraw", {
266
+ get: function () {
267
+ var _this = this;
268
+ return this.verticesList.map(function (vertex) { return (__assign(__assign({}, vertex), { point: _this.transformPointToCanvas(vertex.point) })); });
269
+ },
270
+ enumerable: false,
271
+ configurable: true
272
+ });
273
+ Object.defineProperty(RoomBuilderState.prototype, "features", {
274
+ get: function () {
275
+ return this._state[types_2.IElements.FEATURE];
276
+ },
277
+ set: function (features) {
278
+ this._state[types_2.IElements.FEATURE] = features;
279
+ },
280
+ enumerable: false,
281
+ configurable: true
282
+ });
283
+ Object.defineProperty(RoomBuilderState.prototype, "featuresToDraw", {
284
+ get: function () {
285
+ var _this = this;
286
+ return Object.entries(this.features).reduce(function (output, _a) {
287
+ var _b;
288
+ var type = _a[0], featureArr = _a[1];
289
+ return Object.assign(output, (_b = {},
290
+ _b[type] = featureArr.map(function (feature) { return (__assign(__assign({}, feature), { path: undefined, offset: _this.transformLengthToCanvas(feature.offset), length: _this.transformLengthToCanvas(feature.length) })); }),
291
+ _b));
292
+ }, {});
293
+ },
294
+ enumerable: false,
295
+ configurable: true
296
+ });
297
+ Object.defineProperty(RoomBuilderState.prototype, "getHydratedFeatures", {
298
+ get: function () {
299
+ var _this = this;
300
+ return Object.entries(this.features).reduce(function (output, _a) {
301
+ var _b;
302
+ var type = _a[0], featureArr = _a[1];
303
+ return Object.assign(output, (_b = {},
304
+ _b[type] = featureArr.map(function (feature) {
305
+ var wall = _this.getWall(feature.connectedTo[1]);
306
+ if (!wall)
307
+ return;
308
+ var line = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, feature.offset, feature.length);
309
+ return __assign(__assign({}, feature), { line: line });
310
+ }),
311
+ _b));
312
+ }, {});
313
+ },
314
+ enumerable: false,
315
+ configurable: true
316
+ });
317
+ Object.defineProperty(RoomBuilderState.prototype, "featureCount", {
318
+ get: function () {
319
+ return Object.values(this.features).flat().length;
320
+ },
321
+ enumerable: false,
322
+ configurable: true
323
+ });
324
+ Object.defineProperty(RoomBuilderState.prototype, "activeElement", {
325
+ get: function () {
326
+ return this._activeElement;
327
+ },
328
+ enumerable: false,
329
+ configurable: true
330
+ });
331
+ Object.defineProperty(RoomBuilderState.prototype, "selectedElement", {
332
+ get: function () {
333
+ return this._selectedElement;
334
+ },
335
+ set: function (element) {
336
+ this._selectedElement = element;
337
+ },
338
+ enumerable: false,
339
+ configurable: true
340
+ });
341
+ Object.defineProperty(RoomBuilderState.prototype, "showDimensions", {
342
+ get: function () {
343
+ return this._showDimensions;
344
+ },
345
+ set: function (val) {
346
+ this._showDimensions = val;
347
+ },
348
+ enumerable: false,
349
+ configurable: true
350
+ });
351
+ Object.defineProperty(RoomBuilderState.prototype, "angleSnappingEnabled", {
352
+ get: function () {
353
+ return this._angleSnappingEnabled;
354
+ },
355
+ set: function (val) {
356
+ this._angleSnappingEnabled = val;
357
+ },
358
+ enumerable: false,
359
+ configurable: true
360
+ });
361
+ Object.defineProperty(RoomBuilderState.prototype, "enclosedSpacesToDraw", {
362
+ get: function () {
363
+ var _this = this;
364
+ var loops = (0, findLoops_1.findLoops)(this.wallLines).inner;
365
+ return loops.reduce(function (output, loop) {
366
+ var screenSpaceArea = Math.round((0, geometry_1.getPolygonArea)(loop));
367
+ var area = screenSpaceArea * Math.pow(_this._config.config.scale, 2);
368
+ var convertedArea = (0, dataHandlers_1.convertAreaUnit)(area, types_1.IUnits.METER, _this._config.config.unit);
369
+ var enclosedSpace = {
370
+ loop: loop.map(function (point) { return _this.transformPointToCanvas(point); }),
371
+ area: (0, dataHandlers_1.prepAreaForUser)(convertedArea, _this._config.config.unit),
372
+ center: loop.reduce(function (centerPoint, point) {
373
+ centerPoint[0] += point[0] / loop.length;
374
+ centerPoint[1] += point[1] / loop.length;
375
+ return centerPoint;
376
+ }, [0, 0]),
377
+ };
378
+ enclosedSpace.center = _this.transformPointToCanvas(enclosedSpace.center);
379
+ output.push(enclosedSpace);
380
+ return output;
381
+ }, []);
382
+ },
383
+ enumerable: false,
384
+ configurable: true
385
+ });
386
+ Object.defineProperty(RoomBuilderState.prototype, "canvasDimensions", {
387
+ get: function () {
388
+ return this._canvasDimensions;
389
+ },
390
+ set: function (dimensions) {
391
+ this._canvasDimensions = dimensions;
392
+ },
393
+ enumerable: false,
394
+ configurable: true
395
+ });
396
+ Object.defineProperty(RoomBuilderState.prototype, "canvasWidth", {
397
+ get: function () {
398
+ return this.canvasDimensions[0];
399
+ },
400
+ enumerable: false,
401
+ configurable: true
402
+ });
403
+ Object.defineProperty(RoomBuilderState.prototype, "canvasHeight", {
404
+ get: function () {
405
+ return this.canvasDimensions[1];
406
+ },
407
+ enumerable: false,
408
+ configurable: true
409
+ });
410
+ Object.defineProperty(RoomBuilderState.prototype, "zoom", {
411
+ get: function () {
412
+ return this._zoom;
413
+ },
414
+ enumerable: false,
415
+ configurable: true
416
+ });
417
+ Object.defineProperty(RoomBuilderState.prototype, "zoomFactor", {
418
+ get: function () {
419
+ return this._zoom / this.zoomMin;
420
+ },
421
+ enumerable: false,
422
+ configurable: true
423
+ });
424
+ Object.defineProperty(RoomBuilderState.prototype, "zoomMin", {
425
+ get: function () {
426
+ return this._zoomLimits[0];
427
+ },
428
+ enumerable: false,
429
+ configurable: true
430
+ });
431
+ Object.defineProperty(RoomBuilderState.prototype, "zoomMax", {
432
+ get: function () {
433
+ return this._zoomLimits[1];
434
+ },
435
+ enumerable: false,
436
+ configurable: true
437
+ });
438
+ RoomBuilderState.prototype.setZoom = function (delta) {
439
+ var newZoom = this.zoom + delta;
440
+ var preppedZoom = newZoom < this.zoomMin
441
+ ? this.zoomMin
442
+ : newZoom > this.zoomMax
443
+ ? this.zoomMax
444
+ : newZoom;
445
+ if (preppedZoom === this.zoom)
446
+ return;
447
+ this._zoom = preppedZoom;
448
+ return this.zoom;
449
+ };
450
+ Object.defineProperty(RoomBuilderState.prototype, "translate", {
451
+ get: function () {
452
+ return this._translate;
453
+ },
454
+ set: function (position) {
455
+ var zoomFactor = this._zoom / this.zoomMin;
456
+ var delta = [
457
+ (position[0] - this._translate[0]) / zoomFactor,
458
+ (position[1] - this._translate[1]) / zoomFactor,
459
+ ];
460
+ this._translate = [
461
+ this._translate[0] + delta[0],
462
+ this._translate[1] + delta[1],
463
+ ];
464
+ },
465
+ enumerable: false,
466
+ configurable: true
467
+ });
468
+ Object.defineProperty(RoomBuilderState.prototype, "translateMin", {
469
+ get: function () {
470
+ return this._translateLimits[0];
471
+ },
472
+ enumerable: false,
473
+ configurable: true
474
+ });
475
+ Object.defineProperty(RoomBuilderState.prototype, "translateMax", {
476
+ get: function () {
477
+ return this._translateLimits[1];
478
+ },
479
+ enumerable: false,
480
+ configurable: true
481
+ });
482
+ Object.defineProperty(RoomBuilderState.prototype, "isDrawWallActive", {
483
+ get: function () {
484
+ return !!this._newWall;
485
+ },
486
+ enumerable: false,
487
+ configurable: true
488
+ });
489
+ RoomBuilderState.prototype.transformLengthFromCanvas = function (length) {
490
+ return length / this.zoomFactor;
491
+ };
492
+ RoomBuilderState.prototype.transformLengthToCanvas = function (length) {
493
+ return length * this.zoomFactor;
494
+ };
495
+ RoomBuilderState.prototype.transformPointToCanvas = function (point) {
496
+ var widthOffset = this.canvasWidth / 2;
497
+ var heightOffset = this.canvasHeight / 2;
498
+ return [
499
+ this.transformLengthToCanvas(point[0] + this.translate[0]) -
500
+ widthOffset * (this.zoomFactor - 1),
501
+ this.transformLengthToCanvas(point[1] + this.translate[1]) -
502
+ heightOffset * (this.zoomFactor - 1),
503
+ ];
504
+ };
505
+ RoomBuilderState.prototype.transformPointFromCanvas = function (point) {
506
+ var widthOffset = this.canvasWidth / 2;
507
+ var heightOffset = this.canvasHeight / 2;
508
+ return [
509
+ this.transformLengthFromCanvas(point[0] + widthOffset * (this.zoomFactor - 1)) - this.translate[0],
510
+ this.transformLengthFromCanvas(point[1] + heightOffset * (this.zoomFactor - 1)) - this.translate[1],
511
+ ];
512
+ };
513
+ RoomBuilderState.prototype.transformLineToCanvas = function (line) {
514
+ return [
515
+ this.transformPointToCanvas(line[0]),
516
+ this.transformPointToCanvas(line[1]),
517
+ ];
518
+ };
519
+ RoomBuilderState.prototype.transformLineFromCanvas = function (line) {
520
+ return [
521
+ this.transformPointFromCanvas(line[0]),
522
+ this.transformPointFromCanvas(line[1]),
523
+ ];
524
+ };
525
+ RoomBuilderState.prototype.getWall = function (index) {
526
+ return this.walls[index];
527
+ };
528
+ RoomBuilderState.prototype.addWall = function (wall) {
529
+ if (!wall)
530
+ return;
531
+ var updatedWalls = this.walls;
532
+ updatedWalls.push(wall);
533
+ this.walls = updatedWalls;
534
+ };
535
+ RoomBuilderState.prototype.addWalls = function (walls) {
536
+ var _this = this;
537
+ if (!(walls === null || walls === void 0 ? void 0 : walls.length))
538
+ return;
539
+ walls.forEach(function (wall) { return _this.addWall(wall); });
540
+ };
541
+ RoomBuilderState.prototype.updateWall = function (index, wall) {
542
+ var currentWall = this.walls[index];
543
+ if (!currentWall)
544
+ return;
545
+ this._state[types_2.IElements.WALL][index] = Object.assign({}, currentWall, wall);
546
+ };
547
+ RoomBuilderState.prototype.getWallConnectionCount = function (index) {
548
+ var wall = this.getWall(index);
549
+ return (wall === null || wall === void 0 ? void 0 : wall.connections.length) || 0;
550
+ };
551
+ RoomBuilderState.prototype.getWallConnectionsHydrated = function (index) {
552
+ var _this = this;
553
+ var _a;
554
+ var connections = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.connections;
555
+ if (!connections)
556
+ return undefined;
557
+ return connections.reduce(function (output, connection) {
558
+ var feature = _this.getFeature.apply(_this, connection);
559
+ if (feature)
560
+ output.push(feature);
561
+ return output;
562
+ }, []);
563
+ };
564
+ RoomBuilderState.prototype.getWallDimensions = function (index) {
565
+ var _a;
566
+ var line = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.line;
567
+ if (!line)
568
+ return undefined;
569
+ var lineLength = (0, geometry_1.getLengthOfLineSegment)(line) * this._config.config.scale;
570
+ var convertedVal = (0, dataHandlers_1.convertLengthUnit)(lineLength, types_1.IUnits.METER, this._config.config.unit);
571
+ return {
572
+ line: line,
573
+ label: (0, dataHandlers_1.prepLengthForUser)(convertedVal, this._config.config.unit),
574
+ };
575
+ };
576
+ RoomBuilderState.prototype.getWallDetailedDimensions = function (index) {
577
+ var _this = this;
578
+ var _a;
579
+ var line = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.line;
580
+ var features = this.getWallConnectionsHydrated(index);
581
+ if (!line || !features)
582
+ return undefined;
583
+ var prepLength = function (val) { return val.toFixed(2); };
584
+ var lines = features
585
+ .sort(function (a, b) { return a.offset - b.offset; })
586
+ .reduce(function (output, _a, i) {
587
+ var offset = _a.offset, length = _a.length;
588
+ var featureLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(line, offset, length);
589
+ var featureLength = (0, geometry_1.getLengthOfLineSegment)(featureLine);
590
+ var unit = constants_1.UNIT_LABELS[_this._config.config.unit];
591
+ var scale = _this._config.config.scale;
592
+ if (!i) {
593
+ var startLine = [line[0], featureLine[0]];
594
+ var startLineLength = (0, geometry_1.getLengthOfLineSegment)(startLine);
595
+ output.push({
596
+ line: startLine,
597
+ label: "".concat(prepLength(startLineLength * scale), " ").concat(unit),
598
+ });
599
+ }
600
+ else {
601
+ var previousLine = [
602
+ output[output.length - 1].line[1],
603
+ featureLine[0],
604
+ ];
605
+ var previousLineLength = (0, geometry_1.getLengthOfLineSegment)(previousLine);
606
+ output.push({
607
+ line: previousLine,
608
+ label: "".concat(prepLength(previousLineLength * scale), " ").concat(unit),
609
+ });
610
+ }
611
+ output.push({
612
+ line: featureLine,
613
+ label: "".concat(prepLength(featureLength * scale), " ").concat(unit),
614
+ });
615
+ if (i === features.length - 1) {
616
+ var endLine = [featureLine[1], line[1]];
617
+ var endLineLength = (0, geometry_1.getLengthOfLineSegment)(endLine);
618
+ output.push({
619
+ line: endLine,
620
+ label: "".concat(prepLength(endLineLength * scale), " ").concat(unit),
621
+ });
622
+ }
623
+ return output;
624
+ }, []);
625
+ return lines;
626
+ };
627
+ RoomBuilderState.prototype.getAllWallDimensionsToDraw = function (detailedWallsIndexes) {
628
+ var _this = this;
629
+ if (detailedWallsIndexes === void 0) { detailedWallsIndexes = []; }
630
+ var indexes = new Set([detailedWallsIndexes].flat());
631
+ var dimensionsList = this.walls.reduce(function (output, _, i) {
632
+ var dimensions = indexes.has(i)
633
+ ? _this.getWallDetailedDimensions(i)
634
+ : _this.getWallDimensions(i);
635
+ if (!dimensions)
636
+ return output;
637
+ if (Array.isArray(dimensions))
638
+ output.push.apply(output, dimensions);
639
+ else
640
+ output.push(dimensions);
641
+ return output;
642
+ }, []);
643
+ return dimensionsList.map(function (dimension) { return (__assign(__assign({}, dimension), { line: _this.transformLineToCanvas(dimension.line) })); });
644
+ };
645
+ RoomBuilderState.prototype.shiftAllFeaturesOnWall = function (index, shift) {
646
+ var _this = this;
647
+ var _a;
648
+ var connections = (_a = this.getWall(index)) === null || _a === void 0 ? void 0 : _a.connections;
649
+ if (!connections)
650
+ return;
651
+ connections.forEach(function (_a) {
652
+ var type = _a[0], featureIndex = _a[1];
653
+ var feature = _this.getFeature(type, featureIndex);
654
+ if (!feature)
655
+ return;
656
+ _this.updateFeature(type, featureIndex, {
657
+ offset: feature.offset + shift,
658
+ });
659
+ });
660
+ };
661
+ RoomBuilderState.prototype.addFeatureToWall = function (index, featurePath) {
662
+ var _a;
663
+ var updatedWalls = this.walls;
664
+ (_a = updatedWalls[index]) === null || _a === void 0 ? void 0 : _a.connections.push(featurePath);
665
+ this.walls = updatedWalls;
666
+ };
667
+ RoomBuilderState.prototype.removeFeatureFromWall = function (index, featurePath) {
668
+ var updatedWalls = this.walls;
669
+ if (!updatedWalls[index])
670
+ return;
671
+ updatedWalls[index].connections = updatedWalls[index].connections.filter(function (connection) {
672
+ return connection[0] !== featurePath[0] || connection[1] !== featurePath[1];
673
+ });
674
+ this.walls = updatedWalls;
675
+ };
676
+ RoomBuilderState.prototype.splitWall = function (wallIndex, point) {
677
+ var _this = this;
678
+ var singleWall = this.getWall(wallIndex);
679
+ if (!singleWall)
680
+ return;
681
+ var offset = (0, geometry_1.getLengthOfLineSegment)([singleWall.line[0], point]);
682
+ var _a = (0, geometry_1.splitLineAtPoint)(singleWall.line, point), line1 = _a[0], line2 = _a[1];
683
+ var newWallIndex = this.wallCount;
684
+ var wall1 = {
685
+ assetId: singleWall.assetId,
686
+ line: line1,
687
+ height: singleWall.height,
688
+ thickness: singleWall.thickness,
689
+ connections: singleWall.connections,
690
+ };
691
+ var wall2 = {
692
+ assetId: singleWall.assetId,
693
+ line: line2,
694
+ height: singleWall.height,
695
+ thickness: singleWall.thickness,
696
+ connections: [],
697
+ };
698
+ this.updateWall(wallIndex, wall1);
699
+ this.addWall(wall2);
700
+ singleWall.connections.forEach(function (connection) {
701
+ var feature = _this.getFeature.apply(_this, connection);
702
+ if (!feature)
703
+ return;
704
+ var updatedOffset = feature.offset - offset;
705
+ if (updatedOffset > 0)
706
+ _this.repositionFeature(connection, updatedOffset, newWallIndex);
707
+ });
708
+ };
709
+ RoomBuilderState.prototype.deleteWall = function (index) {
710
+ var wall = this.getWall(index);
711
+ if (!wall)
712
+ return;
713
+ if (wall.connections.length) {
714
+ var currentFeatures_1 = this.features;
715
+ var deleteMap = wall.connections.reduce(function (output, _a) {
716
+ var type = _a[0], index = _a[1];
717
+ if (output[type])
718
+ output[type].push(index);
719
+ else
720
+ output[type] = [index];
721
+ return output;
722
+ }, {});
723
+ var updatedFeatures = Object.entries(deleteMap).reduce(function (output, _a) {
724
+ var _b;
725
+ var type = _a[0], deletionIndexes = _a[1];
726
+ output[type] = (_b = currentFeatures_1[type]) === null || _b === void 0 ? void 0 : _b.filter(function (_, i) { return !deletionIndexes.includes(i); });
727
+ return output;
728
+ }, __assign({}, currentFeatures_1));
729
+ this.features = updatedFeatures;
730
+ }
731
+ var updatedWalls = this.walls;
732
+ updatedWalls.splice(index, 1);
733
+ this.walls = updatedWalls;
734
+ var reevaluatedFeatures = Object.entries(this.features).reduce(function (output, _a) {
735
+ var type = _a[0], featuresArr = _a[1];
736
+ output[type] = featuresArr.map(function (feature) {
737
+ return feature.connectedTo[1] > index
738
+ ? Object.assign({}, feature, {
739
+ connectedTo: [
740
+ feature.connectedTo[0],
741
+ feature.connectedTo[1] - 1,
742
+ ],
743
+ })
744
+ : feature;
745
+ });
746
+ return output;
747
+ }, {});
748
+ this.features = reevaluatedFeatures;
749
+ this.reevaluateFeatureConnections();
750
+ this.pushStateToConfigurator();
751
+ };
752
+ RoomBuilderState.prototype.getFirstVacantLocation = function (length) {
753
+ var _a;
754
+ var walls = this.walls;
755
+ var offset = undefined;
756
+ for (var i = 0; i < walls.length; i++) {
757
+ var wallLength = (0, geometry_1.getLengthOfLineSegment)(walls[i].line);
758
+ var features = (_a = this.getWallConnectionsHydrated(i)) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.offset - b.offset; });
759
+ if (!(features === null || features === void 0 ? void 0 : features.length)) {
760
+ if (length < wallLength - 2 * constants_1.WALL_PADDING_FOR_FEATURE)
761
+ offset = (wallLength - 2 * constants_1.WALL_PADDING_FOR_FEATURE) / 2 - length / 2;
762
+ }
763
+ else {
764
+ for (var j = 0; j < features.length && offset === undefined; j++) {
765
+ var _b = features[j], currentOffset = _b.offset, currentLength = _b.length;
766
+ if (!j) {
767
+ if (constants_1.WALL_PADDING_FOR_FEATURE + length < currentOffset) {
768
+ var slotStart = constants_1.WALL_PADDING_FOR_FEATURE;
769
+ var slotEnd = currentOffset;
770
+ offset = slotStart + (slotEnd - slotStart) / 2 - length / 2;
771
+ continue;
772
+ }
773
+ }
774
+ else {
775
+ var _c = features[j - 1], previousOffset = _c.offset, previousLength = _c.length;
776
+ if (length < currentOffset - (previousOffset + previousLength)) {
777
+ var slotStart = previousOffset + previousLength;
778
+ var slotEnd = currentOffset;
779
+ offset = slotStart + (slotEnd - slotStart) / 2 - length / 2;
780
+ continue;
781
+ }
782
+ }
783
+ if (j === features.length - 1) {
784
+ if (length <
785
+ wallLength -
786
+ constants_1.WALL_PADDING_FOR_FEATURE -
787
+ (currentOffset + currentLength)) {
788
+ var slotStart = currentOffset + currentLength;
789
+ var slotEnd = wallLength - constants_1.WALL_PADDING_FOR_FEATURE;
790
+ offset = slotStart + (slotEnd - slotStart) / 2 - length / 2;
791
+ }
792
+ }
793
+ }
794
+ }
795
+ if (offset !== undefined)
796
+ return {
797
+ wallIndex: i,
798
+ offset: offset,
799
+ };
800
+ }
801
+ return false;
802
+ };
803
+ RoomBuilderState.prototype.getWallUiAnchorPoint = function (index) {
804
+ var wall = this.getWall(index);
805
+ if (!wall)
806
+ return undefined;
807
+ var line = (0, geometry_1.getParallelLineSegmentAtDistance)(wall.line, constants_1.UI_ANCHOR_DISTANCE);
808
+ var point = (0, geometry_1.getMidpointOfLineSegment)(line);
809
+ return this.transformPointToCanvas(point);
810
+ };
811
+ RoomBuilderState.prototype.getVertex = function (index) {
812
+ return this.verticesList[index];
813
+ };
814
+ RoomBuilderState.prototype.getWallsConnectedToVertex = function (index) {
815
+ if (index === undefined)
816
+ return [];
817
+ var vertex = this.getVertex(index);
818
+ if (!vertex)
819
+ return [];
820
+ return vertex.connections.map(function (_a) {
821
+ var index = _a[0];
822
+ return index;
823
+ });
824
+ };
825
+ RoomBuilderState.prototype.repositionVertex = function (index, newCoordinates) {
826
+ var _this = this;
827
+ var _a;
828
+ var connections = (_a = this.getVertex(index)) === null || _a === void 0 ? void 0 : _a.connections;
829
+ if (!connections)
830
+ return;
831
+ connections.forEach(function (_a) {
832
+ var wallIdx = _a[0], vertexIdx = _a[1];
833
+ var updatedLine = JSON.parse(JSON.stringify(_this.walls[wallIdx].line));
834
+ var currentLine = JSON.parse(JSON.stringify(_this.walls[wallIdx].line));
835
+ updatedLine[vertexIdx] = newCoordinates;
836
+ if (_this.getWallConnectionCount(wallIdx) && vertexIdx === 0) {
837
+ var delta = (0, geometry_1.getLengthOfLineSegment)(updatedLine) -
838
+ (0, geometry_1.getLengthOfLineSegment)(currentLine);
839
+ _this.shiftAllFeaturesOnWall(wallIdx, delta);
840
+ }
841
+ _this.updateWall(wallIdx, {
842
+ line: updatedLine,
843
+ path: undefined,
844
+ });
845
+ });
846
+ };
847
+ RoomBuilderState.prototype.getFeatureType = function (type) {
848
+ return this.features[type];
849
+ };
850
+ RoomBuilderState.prototype.setFeatureType = function (type, features) {
851
+ var updatedFeatures = this.features;
852
+ updatedFeatures[type] = features;
853
+ this.features = updatedFeatures;
854
+ this.reevaluateFeatureConnections();
855
+ };
856
+ RoomBuilderState.prototype.getFeature = function (type, index) {
857
+ var _a;
858
+ return (_a = this.features[type]) === null || _a === void 0 ? void 0 : _a[index];
859
+ };
860
+ RoomBuilderState.prototype.updateFeature = function (type, index, feature) {
861
+ var currentFeature = this._state[types_2.IElements.FEATURE][type][index];
862
+ if (!currentFeature)
863
+ return;
864
+ this._state[types_2.IElements.FEATURE][type][index] = Object.assign({}, currentFeature, feature);
865
+ };
866
+ RoomBuilderState.prototype.repositionFeature = function (featurePath, offset, moveToWallIndex) {
867
+ var type = featurePath[0], index = featurePath[1];
868
+ var feature = this.getFeature(type, index);
869
+ if (!feature)
870
+ return;
871
+ this.updateFeature(type, index, { offset: offset, path: undefined });
872
+ if (moveToWallIndex === feature.connectedTo[1])
873
+ return;
874
+ this.removeFeatureFromWall(index, featurePath);
875
+ this.addFeatureToWall(moveToWallIndex, featurePath);
876
+ this.updateFeature(type, index, {
877
+ connectedTo: [types_2.IElements.WALL, moveToWallIndex],
878
+ });
879
+ };
880
+ RoomBuilderState.prototype.addFeature = function (type, feature, addToWallIndex) {
881
+ var _a;
882
+ var offset = undefined;
883
+ var index = undefined;
884
+ if (addToWallIndex !== undefined && feature.offset !== undefined) {
885
+ var wall = this.getWall(addToWallIndex);
886
+ if (wall) {
887
+ var isColliding = (0, validators_1.isFeatureCollidingWithExistingFeature)({
888
+ wall: wall,
889
+ features: this.features,
890
+ updatedFeature: __assign(__assign({}, feature), { offset: feature.offset, address: { type: types_2.IElements.WALL, index: addToWallIndex } }),
891
+ });
892
+ if (!isColliding) {
893
+ offset = feature.offset;
894
+ index = addToWallIndex;
895
+ }
896
+ }
897
+ }
898
+ if (offset === undefined) {
899
+ var availableSlot = this.getFirstVacantLocation(feature.length);
900
+ if (!availableSlot)
901
+ return;
902
+ offset = availableSlot.offset;
903
+ index = availableSlot.wallIndex;
904
+ }
905
+ if (index === undefined || offset === undefined)
906
+ return;
907
+ var newFeature = __assign(__assign({}, feature), { offset: offset, connectedTo: [types_2.IElements.WALL, index] });
908
+ var newFeatureIndex;
909
+ if ((_a = this._state[types_2.IElements.FEATURE][type]) === null || _a === void 0 ? void 0 : _a.length) {
910
+ newFeatureIndex = this._state[types_2.IElements.FEATURE][type].length;
911
+ this._state[types_2.IElements.FEATURE][type].push(newFeature);
912
+ }
913
+ else {
914
+ this._state[types_2.IElements.FEATURE][type] = [newFeature];
915
+ newFeatureIndex = 0;
916
+ }
917
+ this.addFeatureToWall(index, [type, newFeatureIndex]);
918
+ this.pushStateToConfigurator();
919
+ };
920
+ RoomBuilderState.prototype.deleteFeature = function (type, index) {
921
+ var features = this.getFeatureType(type);
922
+ if (!(features === null || features === void 0 ? void 0 : features[index]))
923
+ return;
924
+ var deletedFeature = features.splice(index, 1)[0];
925
+ this.setFeatureType(type, features);
926
+ var wallToUpdate = this.getWall(deletedFeature.connectedTo[1]);
927
+ if (!wallToUpdate)
928
+ return;
929
+ this.updateWall(deletedFeature.connectedTo[1], {
930
+ connections: wallToUpdate.connections.filter(function (connection) { return connection[0] === type && connection[1] !== index; }),
931
+ });
932
+ this.pushStateToConfigurator();
933
+ };
934
+ RoomBuilderState.prototype.getHydratedFeature = function (type, index) {
935
+ var feature = this.getFeature(type, index);
936
+ if (!feature)
937
+ return;
938
+ var wall = this.getWall(feature.connectedTo[1]);
939
+ if (!wall)
940
+ return;
941
+ var line = (0, geometry_1.getLineAtOffsetOnLineSegment)(wall.line, feature.offset, feature.length);
942
+ return __assign(__assign({}, feature), { line: line });
943
+ };
944
+ RoomBuilderState.prototype.getFeatureUiAnchorPoint = function (type, index) {
945
+ var feature = this.getHydratedFeature(type, index);
946
+ if (!feature)
947
+ return;
948
+ var line = (0, geometry_1.getParallelLineSegmentAtDistance)(feature.line, constants_1.UI_ANCHOR_DISTANCE);
949
+ var point = (0, geometry_1.getMidpointOfLineSegment)(line);
950
+ return this.transformPointToCanvas(point);
951
+ };
952
+ RoomBuilderState.prototype.deleteElement = function (type, index) {
953
+ if (type === types_2.IElements.VERTEX)
954
+ return;
955
+ if (type === types_2.IElements.WALL)
956
+ this.deleteWall(index);
957
+ else
958
+ this.deleteFeature(type, index);
959
+ };
960
+ RoomBuilderState.prototype.getVertexInProximity = function (point) {
961
+ if (!point)
962
+ return undefined;
963
+ var snapProximity = this.transformLengthFromCanvas(this._config.config.snapProximity);
964
+ var index = this.verticesList.findIndex(function (vertex) {
965
+ return (0, geometry_1.arePointsWithinProximity)(vertex.point, point, snapProximity);
966
+ });
967
+ if (index === -1)
968
+ return undefined;
969
+ return index;
970
+ };
971
+ RoomBuilderState.prototype.getWallInProximity = function (point) {
972
+ var _this = this;
973
+ var index = this.walls.findIndex(function (wall) {
974
+ var path = (0, geometry_1.addThicknessToLine)(wall.line, _this._config.config.styles.wall.thickness + constants_1.WALL_SNAP_DISTANCE);
975
+ return (0, geometry_1.isPointInQuadrilateral)(path, point);
976
+ });
977
+ if (index === -1)
978
+ return undefined;
979
+ return index;
980
+ };
981
+ RoomBuilderState.prototype.snapPointToVertex = function (point) {
982
+ var _a, _b;
983
+ if (!point)
984
+ return undefined;
985
+ var index = this.getVertexInProximity(point);
986
+ if (index === undefined)
987
+ return undefined;
988
+ if (((_a = this._activeElement) === null || _a === void 0 ? void 0 : _a.type) === types_2.IElements.VERTEX &&
989
+ ((_b = this._activeElement) === null || _b === void 0 ? void 0 : _b.index) === index)
990
+ return undefined;
991
+ var vertex = this.getVertex(index);
992
+ if (!vertex)
993
+ return undefined;
994
+ return {
995
+ type: types_2.IElements.VERTEX,
996
+ index: index,
997
+ point: vertex.point,
998
+ };
999
+ };
1000
+ RoomBuilderState.prototype.snapPointToWall = function (point) {
1001
+ var index = this.getWallInProximity(point);
1002
+ if (index === undefined)
1003
+ return undefined;
1004
+ if (this._activeElement) {
1005
+ if (this._activeElement.type === types_2.IElements.WALL &&
1006
+ this._activeElement.index === index)
1007
+ return undefined;
1008
+ if (this._activeElement.type === types_2.IElements.VERTEX) {
1009
+ var vertex = this.getVertex(this._activeElement.index);
1010
+ if (vertex)
1011
+ for (var i = 0; i < vertex.connections.length; i++) {
1012
+ if (vertex.connections[i][0] === index)
1013
+ return undefined;
1014
+ }
1015
+ }
1016
+ }
1017
+ var intersection = (0, geometry_1.getTangetIntersectionAndOffset)(this.getWall(index).line, point);
1018
+ if (!intersection)
1019
+ return undefined;
1020
+ return __assign({ type: types_2.IElements.WALL, index: index }, intersection);
1021
+ };
1022
+ RoomBuilderState.prototype.snapPointToAbsoluteAngle = function (point, anchorPoint, angle) {
1023
+ if (angle === void 0) { angle = 30; }
1024
+ var snapProximity = this.transformLengthFromCanvas(this._config.config.snapProximity);
1025
+ if (Math.abs(point[0] - anchorPoint[0]) < snapProximity) {
1026
+ return {
1027
+ type: types_1.SNAPPING_TYPES.ANGLE,
1028
+ point: [anchorPoint[0], point[1]],
1029
+ };
1030
+ }
1031
+ else if (Math.abs(point[1] - anchorPoint[1]) < snapProximity) {
1032
+ return {
1033
+ type: types_1.SNAPPING_TYPES.ANGLE,
1034
+ point: [point[0], anchorPoint[1]],
1035
+ };
1036
+ }
1037
+ for (var degrees = 0; degrees < 360; degrees += angle) {
1038
+ if (degrees === 0 || degrees % 90 === 0)
1039
+ continue;
1040
+ var radians = degrees * (Math.PI / 180);
1041
+ if ((0, geometry_1.getDistanceToLine)(anchorPoint, radians, point) < snapProximity)
1042
+ return {
1043
+ type: types_1.SNAPPING_TYPES.ANGLE,
1044
+ point: (0, geometry_1.closestPointOnLine)(anchorPoint, radians, point),
1045
+ };
1046
+ }
1047
+ return undefined;
1048
+ };
1049
+ RoomBuilderState.prototype.snapVertexToAbsoluteAngle = function (vertexIndex, updatedPoint) {
1050
+ var _this = this;
1051
+ var vertex = this.getVertex(vertexIndex);
1052
+ if (!vertex)
1053
+ return undefined;
1054
+ var snapProximity = this.transformLengthFromCanvas(this._config.config.snapProximity);
1055
+ var point = vertex.connections.reduce(function (output, connection) {
1056
+ var _a;
1057
+ var line = (_a = _this.getWall(connection[0])) === null || _a === void 0 ? void 0 : _a.line;
1058
+ if (!line)
1059
+ return output;
1060
+ var _b = output || updatedPoint, x = _b[0], y = _b[1];
1061
+ var _c = line[connection[1] === 0 ? 1 : 0], xAnchor = _c[0], yAnchor = _c[1];
1062
+ if (Math.abs(x - xAnchor) < snapProximity)
1063
+ return [xAnchor, y];
1064
+ else if (Math.abs(y - yAnchor) < snapProximity)
1065
+ return [x, yAnchor];
1066
+ return output;
1067
+ }, undefined);
1068
+ if (!point)
1069
+ return point;
1070
+ return {
1071
+ type: types_1.SNAPPING_TYPES.ANGLE,
1072
+ point: point,
1073
+ };
1074
+ };
1075
+ RoomBuilderState.prototype.getFeatureAtPoint = function (point) {
1076
+ var _this = this;
1077
+ if (!point)
1078
+ return undefined;
1079
+ if (!this.featureCount)
1080
+ return undefined;
1081
+ var featuresMap = Object.entries(this.features);
1082
+ for (var i = 0; i < featuresMap.length; i++) {
1083
+ var _a = featuresMap[i], name_1 = _a[0], feature = _a[1];
1084
+ var index = feature.findIndex(function (feature) {
1085
+ var path = feature.path;
1086
+ if (!path) {
1087
+ var wallIndex = feature.connectedTo[1];
1088
+ var featureLine = (0, geometry_1.getLineAtOffsetOnLineSegment)(_this.getWall(wallIndex).line, feature.offset, feature.length);
1089
+ path = (0, geometry_1.addThicknessToLine)(featureLine, _this._config.config.styles.feature.thickness);
1090
+ }
1091
+ return (0, geometry_1.isPointInQuadrilateral)(path, point);
1092
+ });
1093
+ if (index !== -1)
1094
+ return {
1095
+ type: name_1,
1096
+ index: index,
1097
+ };
1098
+ }
1099
+ return undefined;
1100
+ };
1101
+ RoomBuilderState.prototype.getElementAtPoint = function (point) {
1102
+ if (!point)
1103
+ return undefined;
1104
+ var snapToVertex = this.snapPointToVertex(point);
1105
+ if (snapToVertex !== undefined)
1106
+ return snapToVertex;
1107
+ if (this.featureCount) {
1108
+ var featureInProximity = this.getFeatureAtPoint(point);
1109
+ if (featureInProximity)
1110
+ return featureInProximity;
1111
+ }
1112
+ var wallInProximity = this.getWallInProximity(point);
1113
+ if (wallInProximity !== undefined)
1114
+ return { type: types_2.IElements.WALL, index: wallInProximity };
1115
+ return undefined;
1116
+ };
1117
+ RoomBuilderState.prototype.getClickedElement = function (cursorPoint) {
1118
+ var point = this.transformPointFromCanvas(cursorPoint);
1119
+ var element = this.getElementAtPoint(point);
1120
+ if (!element)
1121
+ return;
1122
+ var uiAnchor;
1123
+ if (element.type === types_2.IElements.VERTEX)
1124
+ return;
1125
+ if (element.type === types_2.IElements.WALL)
1126
+ uiAnchor = this.getWallUiAnchorPoint(element.index);
1127
+ else
1128
+ uiAnchor = this.getFeatureUiAnchorPoint(element.type, element.index);
1129
+ if (!uiAnchor)
1130
+ return undefined;
1131
+ return {
1132
+ path: [element.type, element.index],
1133
+ uiAnchor: uiAnchor,
1134
+ };
1135
+ };
1136
+ RoomBuilderState.prototype.getPointProximity = function (point) {
1137
+ var feature = this.getFeatureAtPoint(point);
1138
+ if (feature)
1139
+ return __assign(__assign({}, feature), { point: point });
1140
+ var snapToVertex = this.snapPointToVertex(point);
1141
+ if (snapToVertex)
1142
+ return snapToVertex;
1143
+ var snapToWall = this.snapPointToWall(point);
1144
+ if (snapToWall)
1145
+ return snapToWall;
1146
+ return undefined;
1147
+ };
1148
+ RoomBuilderState.prototype.reevaluateFeatureConnections = function () {
1149
+ var _this = this;
1150
+ this.walls.forEach(function (_, i) { return _this.updateWall(i, { connections: [] }); });
1151
+ Object.entries(this.features).forEach(function (_a) {
1152
+ var type = _a[0], featuresArr = _a[1];
1153
+ return featuresArr.forEach(function (feature, i) {
1154
+ return _this.addFeatureToWall(feature.connectedTo[1], [type, i]);
1155
+ });
1156
+ });
1157
+ };
1158
+ RoomBuilderState.prototype.pushStateToConfigurator = function () {
1159
+ var configuration = (0, dataHandlers_1.prepAttributesOutgoing)(this.walls, this.features, this._config);
1160
+ window.threekit.configurator.setConfiguration(configuration);
1161
+ };
1162
+ RoomBuilderState.prototype.setAttributesToState = function (attributes) {
1163
+ if (!attributes)
1164
+ return;
1165
+ this._attributesState = attributes;
1166
+ var data = (0, dataHandlers_1.prepAttributesIncoming)(attributes, this._config);
1167
+ this.walls = data[types_2.IElements.WALL];
1168
+ this.vertices = data[types_2.IElements.VERTEX];
1169
+ this.features = data[types_2.IElements.FEATURE];
1170
+ this.reevaluateFeatureConnections();
1171
+ };
1172
+ RoomBuilderState.prototype.deleteAll = function () {
1173
+ this.walls = [];
1174
+ this.vertices = {};
1175
+ this.features = Object.keys(this.features).reduce(function (output, type) {
1176
+ var _a;
1177
+ return Object.assign(output, (_a = {}, _a[type] = [], _a));
1178
+ }, {});
1179
+ this.pushStateToConfigurator();
1180
+ };
1181
+ RoomBuilderState.prototype.resetInternalState = function () {
1182
+ if (this._attributesState)
1183
+ this.setAttributesToState(this._attributesState);
1184
+ };
1185
+ RoomBuilderState.prototype.highlightElementIfInProximity = function (canvas, cursorPoint) {
1186
+ var _a, _b;
1187
+ var point = this.transformPointFromCanvas(cursorPoint);
1188
+ var elementAtPoint = this.getElementAtPoint(point);
1189
+ if ((!elementAtPoint && !this._highlightedElement) ||
1190
+ Array.isArray(this._highlightedElement))
1191
+ return;
1192
+ if (elementAtPoint) {
1193
+ var type = elementAtPoint.type, index = elementAtPoint.index;
1194
+ if (((_a = this._highlightedElement) === null || _a === void 0 ? void 0 : _a.type) === type &&
1195
+ ((_b = this._highlightedElement) === null || _b === void 0 ? void 0 : _b.index) === index)
1196
+ return;
1197
+ }
1198
+ this._highlightedElement = elementAtPoint !== null && elementAtPoint !== void 0 ? elementAtPoint : null;
1199
+ this.drawRoom(canvas);
1200
+ };
1201
+ RoomBuilderState.prototype.startDrawNewWall = function (startPoint) {
1202
+ var _a;
1203
+ var point = this.transformPointFromCanvas(startPoint);
1204
+ var snapPoint = this.getPointProximity(point);
1205
+ if ((snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.type) === types_2.IElements.WINDOW ||
1206
+ (snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.type) === types_2.IElements.OPENING ||
1207
+ (snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.type) === types_2.IElements.DOOR)
1208
+ return;
1209
+ this._newWall = {
1210
+ start: (_a = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _a !== void 0 ? _a : point,
1211
+ snapStartTo: snapPoint,
1212
+ };
1213
+ };
1214
+ RoomBuilderState.prototype.drawNewWall = function (canvas, endPoint) {
1215
+ var _a, _b, _c, _d, _e;
1216
+ if (!this._newWall)
1217
+ return;
1218
+ var point = this.transformPointFromCanvas(endPoint);
1219
+ var snapPoint = this.getPointProximity(point);
1220
+ if (!snapPoint && this._angleSnappingEnabled)
1221
+ snapPoint = this.snapPointToAbsoluteAngle(point, (_b = (_a = this._newWall.snapStartTo) === null || _a === void 0 ? void 0 : _a.point) !== null && _b !== void 0 ? _b : this._newWall.start);
1222
+ var wallLine = [
1223
+ this._newWall.start,
1224
+ (_c = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _c !== void 0 ? _c : point,
1225
+ ];
1226
+ var validationData = {
1227
+ walls: this.walls,
1228
+ features: this.features,
1229
+ newWall: {
1230
+ line: wallLine,
1231
+ snapStartTo: this._newWall.snapStartTo,
1232
+ snapEndTo: snapPoint,
1233
+ },
1234
+ };
1235
+ this._errorElement = (0, validators_1.runValidators)([
1236
+ validators_1.isWallEndingOnFeature,
1237
+ validators_1.isWallTooShort,
1238
+ validators_1.isWallOverlappingExisitingWalls,
1239
+ validators_1.isWallIntersectingFeature,
1240
+ ], validationData);
1241
+ var errorType = ((_d = this._errorElement) === null || _d === void 0 ? void 0 : _d[0].type) || null;
1242
+ switch (errorType) {
1243
+ case types_1.IErrorTypes.HARD:
1244
+ return;
1245
+ case types_1.IErrorTypes.SOFT:
1246
+ case types_1.IErrorTypes.WARN:
1247
+ case null:
1248
+ default:
1249
+ this._newWall.end = (_e = snapPoint === null || snapPoint === void 0 ? void 0 : snapPoint.point) !== null && _e !== void 0 ? _e : point;
1250
+ this._newWall.snapEndTo = snapPoint;
1251
+ this.drawRoom(canvas);
1252
+ break;
1253
+ }
1254
+ };
1255
+ RoomBuilderState.prototype.cancelDrawNewWall = function (canvas) {
1256
+ this._newWall = null;
1257
+ this._errorElement = null;
1258
+ this._highlightedElement = null;
1259
+ this.drawRoom(canvas);
1260
+ };
1261
+ RoomBuilderState.prototype.finishDrawNewWall = function (canvas, assetId) {
1262
+ return __awaiter(this, void 0, void 0, function () {
1263
+ var _a, start, end, snapStartTo, snapEndTo, wallsToExclude, filteredWalls, intersections, newWallLines;
1264
+ var _this = this;
1265
+ return __generator(this, function (_b) {
1266
+ if (this._errorElement) {
1267
+ if ([this._errorElement].flat()[0].message)
1268
+ __1.message.info([this._errorElement].flat()[0].message);
1269
+ this._newWall = null;
1270
+ this._errorElement = null;
1271
+ this._highlightedElement = null;
1272
+ this.drawRoom(canvas);
1273
+ return [2];
1274
+ }
1275
+ _a = this._newWall || {}, start = _a.start, end = _a.end, snapStartTo = _a.snapStartTo, snapEndTo = _a.snapEndTo;
1276
+ if (!start || !end) {
1277
+ this._newWall = null;
1278
+ this._errorElement = null;
1279
+ this._highlightedElement = null;
1280
+ return [2];
1281
+ }
1282
+ wallsToExclude = new Set([]);
1283
+ if ((snapStartTo === null || snapStartTo === void 0 ? void 0 : snapStartTo.type) === types_2.IElements.WALL) {
1284
+ this.splitWall(snapStartTo.index, start);
1285
+ wallsToExclude.add(snapStartTo.index);
1286
+ }
1287
+ if ((snapEndTo === null || snapEndTo === void 0 ? void 0 : snapEndTo.type) === types_2.IElements.WALL) {
1288
+ this.splitWall(snapEndTo.index, end);
1289
+ wallsToExclude.add(snapEndTo.index);
1290
+ }
1291
+ if (wallsToExclude.size === 1)
1292
+ wallsToExclude.add(this.wallCount - 1);
1293
+ else if (wallsToExclude.size === 2)
1294
+ wallsToExclude.add(this.wallCount - 1).add(this.wallCount - 2);
1295
+ filteredWalls = this.walls.map(function (wall, i) {
1296
+ return wallsToExclude.has(i) ? null : wall.line;
1297
+ });
1298
+ intersections = (0, geometry_1.getAllLineIntersections)([start, end], filteredWalls);
1299
+ intersections.forEach(function (_a) {
1300
+ var index = _a.index, point = _a.point;
1301
+ return _this.splitWall(index, point);
1302
+ });
1303
+ newWallLines = (0, geometry_1.splitLineAtPoints)([start, end], intersections.map(function (_a) {
1304
+ var point = _a.point;
1305
+ return point;
1306
+ }));
1307
+ this.addWalls(newWallLines.map(function (line) { return ({
1308
+ assetId: assetId,
1309
+ line: line,
1310
+ connections: [],
1311
+ }); }));
1312
+ this._newWall = null;
1313
+ this._errorElement = null;
1314
+ this._highlightedElement = null;
1315
+ this.pushStateToConfigurator();
1316
+ return [2];
1317
+ });
1318
+ });
1319
+ };
1320
+ RoomBuilderState.prototype.drawNewWallGuides = function (canvas, cursorPoint) {
1321
+ var point = this.transformPointFromCanvas(cursorPoint);
1322
+ if (canvas)
1323
+ console.log(point);
1324
+ };
1325
+ RoomBuilderState.prototype.selectElementIfInProximity = function (canvas, cursorPoint) {
1326
+ var point = this.transformPointFromCanvas(cursorPoint);
1327
+ var elementAtPoint = this.getElementAtPoint(point);
1328
+ if (!elementAtPoint || elementAtPoint.type === types_2.IElements.WALL)
1329
+ return;
1330
+ this._activeElement = elementAtPoint;
1331
+ if (elementAtPoint.type === types_2.IElements.VERTEX) {
1332
+ var wallIndexes = this.getWallsConnectedToVertex(elementAtPoint.index);
1333
+ this._highlightedElement = wallIndexes.map(function (index) { return ({
1334
+ type: types_2.IElements.WALL,
1335
+ index: index,
1336
+ }); });
1337
+ }
1338
+ this.drawRoom(canvas);
1339
+ };
1340
+ RoomBuilderState.prototype.moveActiveElement = function (canvas, moveToPoint) {
1341
+ if (!canvas)
1342
+ return;
1343
+ if (!this._activeElement)
1344
+ return;
1345
+ var point = this.transformPointFromCanvas(moveToPoint);
1346
+ var type = this._activeElement.type;
1347
+ if (type === types_2.IElements.VERTEX)
1348
+ this.moveActiveVertex(canvas, point);
1349
+ else if (type === types_2.IElements.WINDOW ||
1350
+ type === types_2.IElements.DOOR ||
1351
+ type === types_2.IElements.OPENING)
1352
+ this.moveActiveFeature(canvas, point);
1353
+ };
1354
+ RoomBuilderState.prototype.finishMoveActiveElement = function (canvas) {
1355
+ if (!this._activeElement)
1356
+ return;
1357
+ if (this._errorElement) {
1358
+ if ([this._errorElement].flat()[0].message)
1359
+ __1.message.info([this._errorElement].flat()[0].message);
1360
+ this._activeElement = null;
1361
+ this._errorElement = null;
1362
+ this._highlightedElement = null;
1363
+ this.resetInternalState();
1364
+ this.drawRoom(canvas);
1365
+ return;
1366
+ }
1367
+ var type = this._activeElement.type;
1368
+ if (type === types_2.IElements.VERTEX)
1369
+ this.finishMoveActiveVertex();
1370
+ else if (type === types_2.IElements.WINDOW ||
1371
+ type === types_2.IElements.DOOR ||
1372
+ type === types_2.IElements.OPENING)
1373
+ this.finishMoveActiveFeature();
1374
+ this._activeElement = null;
1375
+ this._errorElement = null;
1376
+ this._highlightedElement = null;
1377
+ this.drawRoom(canvas);
1378
+ };
1379
+ RoomBuilderState.prototype.cancelMoveActiveElement = function (canvas) {
1380
+ this._activeElement = null;
1381
+ this._errorElement = null;
1382
+ this._highlightedElement = null;
1383
+ this.resetInternalState();
1384
+ this.drawRoom(canvas);
1385
+ };
1386
+ RoomBuilderState.prototype.drawRoom = function (canvas) {
1387
+ var _a, _b, _c, _d, _e, _f, _g;
1388
+ if (!canvas)
1389
+ return;
1390
+ var highlighted = this._highlightedElement
1391
+ ? [this._highlightedElement].flat()
1392
+ : [];
1393
+ var active = this._activeElement && this._activeElement.type !== types_2.IElements.VERTEX
1394
+ ? [this._activeElement]
1395
+ : [];
1396
+ var error = this._errorElement
1397
+ ? [this._errorElement]
1398
+ .flat()
1399
+ .reduce(function (output, _a) {
1400
+ var address = _a.address;
1401
+ return (address ? __spreadArray(__spreadArray([], output, true), [address], false) : output);
1402
+ }, [])
1403
+ : [];
1404
+ var hidden = ((_a = this._activeElement) === null || _a === void 0 ? void 0 : _a.type) === types_2.IElements.VERTEX
1405
+ ? [this._activeElement]
1406
+ : [];
1407
+ if (this.selectedElement)
1408
+ highlighted.push(this.selectedElement);
1409
+ var selection = {
1410
+ highlighted: highlighted,
1411
+ active: active,
1412
+ error: error,
1413
+ hidden: hidden,
1414
+ };
1415
+ var activeWallIndex;
1416
+ if (this._showDimensions &&
1417
+ (((_b = this._activeElement) === null || _b === void 0 ? void 0 : _b.type) === types_2.IElements.WINDOW ||
1418
+ ((_c = this._activeElement) === null || _c === void 0 ? void 0 : _c.type) === types_2.IElements.DOOR ||
1419
+ ((_d = this._activeElement) === null || _d === void 0 ? void 0 : _d.type) === types_2.IElements.OPENING))
1420
+ activeWallIndex = (_e = this.getFeature(this._activeElement.type, this._activeElement.index)) === null || _e === void 0 ? void 0 : _e.connectedTo[1];
1421
+ (0, draw_1.drawRoom)(canvas, this.enclosedSpacesToDraw, this.wallsToDraw, this.verticesListToDraw, this.featuresToDraw, this._showDimensions
1422
+ ? this.getAllWallDimensionsToDraw(activeWallIndex)
1423
+ : undefined, selection, this._config.config);
1424
+ if (((_f = this._newWall) === null || _f === void 0 ? void 0 : _f.start) && ((_g = this._newWall) === null || _g === void 0 ? void 0 : _g.end)) {
1425
+ (0, draw_1.drawNewWall)(canvas, this.transformLineToCanvas([this._newWall.start, this._newWall.end]), this._config.config.styles, this._errorElement ? types_1.IElementStyleModes.ERROR : undefined);
1426
+ }
1427
+ };
1428
+ return RoomBuilderState;
1429
+ }());
1430
+ exports.RoomBuilderState = RoomBuilderState;
1431
+ exports.default = RoomBuilderState;