@threekit-tools/treble 0.0.88 → 0.0.89-next-001

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