@threekit-tools/treble 0.0.90-next-09 → 0.0.91

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