@threekit-tools/treble 0.0.95-next-01 → 0.0.96

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