@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,625 +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 __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- var react_1 = require("react");
54
- var types_1 = require("./types");
55
- var types_2 = require("./types");
56
- var useConfigurator_1 = __importDefault(require("../useConfigurator"));
57
- var constants_1 = require("./constants");
58
- var themes_1 = require("./themes");
59
- var SpacesLayout_1 = __importDefault(require("./SpacesLayout"));
60
- var store_1 = require("../../store");
61
- var spaces_1 = require("../../store/spaces");
62
- var useThreekitInitStatus_1 = __importDefault(require("../useThreekitInitStatus"));
63
- var getLocalTouchPoint = function (touch, rect) {
64
- if (touch.clientY < rect.top ||
65
- rect.bottom < touch.clientY ||
66
- touch.clientX < rect.left ||
67
- rect.right < touch.clientX)
68
- return undefined;
69
- return [touch.clientX - rect.left, touch.clientY - rect.top];
70
- };
71
- var useSpaces = function (props) {
72
- var _a, _b, _c, _d, _e;
73
- var attributesState = (0, useConfigurator_1.default)()[0];
74
- var hasLoaded = (0, useThreekitInitStatus_1.default)();
75
- var dispatch = (0, store_1.useThreekitDispatch)();
76
- var layouts = (0, store_1.useThreekitSelector)(spaces_1.getLayouts);
77
- var hasInitialized = (0, store_1.useThreekitSelector)(spaces_1.getInitialized);
78
- var zoom = (0, store_1.useThreekitSelector)(spaces_1.getZoom);
79
- var unit = (0, store_1.useThreekitSelector)(spaces_1.getUnit);
80
- var translation = (0, store_1.useThreekitSelector)(spaces_1.getTranslation);
81
- var modeValue = (0, store_1.useThreekitSelector)(spaces_1.getMode);
82
- var showDimensions = (0, store_1.useThreekitSelector)(spaces_1.getShowDimensions);
83
- var angleSnappingEnabled = (0, store_1.useThreekitSelector)(spaces_1.getAngleSnappingEnabled);
84
- var guideSnappingEnabled = (0, store_1.useThreekitSelector)(spaces_1.getGuideSnappingEnabled);
85
- var gridSnappingEnabled = (0, store_1.useThreekitSelector)(spaces_1.getGridSnappingEnabled);
86
- var wallMode = (0, store_1.useThreekitSelector)(spaces_1.getWallMode);
87
- var _f = (0, react_1.useState)(null), selectedElement = _f[0], setSelectedElement = _f[1];
88
- var _g = (0, react_1.useState)(false), pendingStatus = _g[0], setPendingStatus = _g[1];
89
- var canvasRef = (0, react_1.useRef)(null);
90
- var selectElementPending = (0, react_1.useRef)(null);
91
- var translationAnchorRef = (0, react_1.useRef)(null);
92
- var prevStateRef = (0, react_1.useRef)('');
93
- var attributeNames = Object.assign(constants_1.ATTRIBUTE_NAME_DEFAULTS, props.attributes);
94
- var spacesRef = (0, react_1.useRef)(null);
95
- var drawSpaces = function () { var _a; return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.drawSpaces(canvasRef.current); };
96
- (0, react_1.useEffect)(function () {
97
- if (!hasLoaded)
98
- return;
99
- (function () { return __awaiter(void 0, void 0, void 0, function () {
100
- var parameters, _a;
101
- var _b;
102
- return __generator(this, function (_c) {
103
- switch (_c.label) {
104
- case 0:
105
- parameters = props.config
106
- ? Object.assign({}, props.config.unit ? { unit: props.config.unit } : undefined, props.config.showDimensions
107
- ? { showDimensions: props.config.showDimensions }
108
- : undefined, 'zoomDefault' in props.config
109
- ? { zoomDefault: props.config.zoomDefault }
110
- : undefined, props.config.translateDefault
111
- ? { translateDefault: props.config.translateDefault }
112
- : undefined, 'enableAngleSnapping' in props.config
113
- ? { enableAngleSnapping: props.config.enableAngleSnapping }
114
- : undefined, 'enableGridSnapping' in props.config
115
- ? { enableGridSnapping: props.config.enableGridSnapping }
116
- : undefined, 'enableGuideSnapping' in props.config
117
- ? { enableGridSnapping: props.config.enableGuideSnapping }
118
- : undefined)
119
- : {};
120
- _a = spacesRef;
121
- return [4, dispatch((0, spaces_1.initSpaces)({
122
- parameters: __assign(__assign({}, parameters), { theme: (_b = props.config) === null || _b === void 0 ? void 0 : _b.theme }),
123
- layoutIds: props.layouts || [],
124
- attributeNames: attributeNames,
125
- canvasDimensions: canvasRef.current
126
- ? [canvasRef.current.width, canvasRef.current.height]
127
- : undefined,
128
- setPendingStatus: setPendingStatus,
129
- }))];
130
- case 1:
131
- _a.current = _c.sent();
132
- drawSpaces();
133
- return [2];
134
- }
135
- });
136
- }); })();
137
- }, [hasLoaded]);
138
- if (spacesRef.current) {
139
- var attributesDelinked = void 0;
140
- if (JSON.stringify(attributesState) !== prevStateRef.current) {
141
- prevStateRef.current = JSON.stringify(attributesState);
142
- attributesDelinked = JSON.parse(JSON.stringify(attributesState));
143
- }
144
- (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.sync({
145
- attributesState: attributesDelinked,
146
- canvasDimensions: canvasRef.current
147
- ? [canvasRef.current.width, canvasRef.current.height]
148
- : undefined,
149
- angleSnappingEnabled: angleSnappingEnabled,
150
- gridSnappingEnabled: gridSnappingEnabled,
151
- guideSnappingEnabled: guideSnappingEnabled,
152
- showDimensions: showDimensions,
153
- unit: unit,
154
- zoom: spacesRef.current.zoom !== zoom ? zoom : undefined,
155
- translate: translation,
156
- wallMode: {
157
- value: wallMode.value,
158
- assetId: wallMode.assetId,
159
- },
160
- selectedElement: selectedElement
161
- ? {
162
- type: selectedElement.path[0],
163
- index: selectedElement.path[1],
164
- }
165
- : null,
166
- });
167
- }
168
- (0, react_1.useEffect)(function () {
169
- if (!canvasRef.current)
170
- return;
171
- if (pendingStatus)
172
- canvasRef.current.style.cursor = 'progress';
173
- else
174
- canvasRef.current.style.cursor = 'default';
175
- }, [pendingStatus, canvasRef.current]);
176
- (0, react_1.useEffect)(function () {
177
- var _a, _b;
178
- if (pendingStatus)
179
- return;
180
- if (canvasRef.current) {
181
- canvasRef.current.addEventListener('mousedown', handleDrawWallStart);
182
- canvasRef.current.addEventListener('touchstart', handleDrawWallStart);
183
- canvasRef.current.addEventListener('mousemove', handleDrawWallMouseMove);
184
- canvasRef.current.addEventListener('touchmove', handleDrawWallMouseMove);
185
- document.addEventListener('mouseup', handleDrawWallFinish);
186
- document.addEventListener('touchend', handleDrawWallFinish);
187
- canvasRef.current.addEventListener('mousemove', handleHover);
188
- canvasRef.current.addEventListener('mousedown', handleSelectElement);
189
- canvasRef.current.addEventListener('touchstart', handleSelectElement);
190
- canvasRef.current.addEventListener('mousemove', handleMoveSelectedElement);
191
- canvasRef.current.addEventListener('touchmove', handleMoveSelectedElement);
192
- if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled)) {
193
- canvasRef.current.addEventListener('mousemove', handleMoveCanvas);
194
- canvasRef.current.addEventListener('touchmove', handleMoveCanvas);
195
- }
196
- document.addEventListener('mouseup', handleFinishMove);
197
- document.addEventListener('touchend', handleFinishMove);
198
- if (!((_b = props.config) === null || _b === void 0 ? void 0 : _b.zoomDisabled))
199
- canvasRef.current.addEventListener('wheel', handleScrollToZoom);
200
- }
201
- return function () {
202
- var _a, _b;
203
- if (canvasRef.current) {
204
- canvasRef.current.removeEventListener('mousedown', handleDrawWallStart);
205
- canvasRef.current.removeEventListener('touchstart', handleDrawWallStart);
206
- canvasRef.current.removeEventListener('mousemove', handleDrawWallMouseMove);
207
- canvasRef.current.removeEventListener('touchmove', handleDrawWallMouseMove);
208
- document.removeEventListener('mouseup', handleDrawWallFinish);
209
- document.removeEventListener('touchend', handleDrawWallFinish);
210
- canvasRef.current.removeEventListener('mousemove', handleHover);
211
- canvasRef.current.removeEventListener('mousedown', handleSelectElement);
212
- canvasRef.current.removeEventListener('touchstart', handleSelectElement);
213
- canvasRef.current.removeEventListener('mousemove', handleMoveSelectedElement);
214
- canvasRef.current.removeEventListener('touchmove', handleMoveSelectedElement);
215
- if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled)) {
216
- canvasRef.current.removeEventListener('mousemove', handleMoveCanvas);
217
- canvasRef.current.removeEventListener('touchmove', handleMoveCanvas);
218
- }
219
- document.removeEventListener('mouseup', handleFinishMove);
220
- document.removeEventListener('touchend', handleFinishMove);
221
- if (!((_b = props.config) === null || _b === void 0 ? void 0 : _b.zoomDisabled))
222
- canvasRef.current.removeEventListener('wheel', handleScrollToZoom);
223
- }
224
- };
225
- });
226
- (0, react_1.useEffect)(function () {
227
- if (hasInitialized)
228
- drawSpaces();
229
- });
230
- var updateZoom = function (value) {
231
- if (!spacesRef.current)
232
- return;
233
- var prevZoom = spacesRef.current.zoom;
234
- spacesRef.current.zoom = value;
235
- if (prevZoom === spacesRef.current.zoom)
236
- return;
237
- dispatch((0, spaces_1.setZoom)(spacesRef.current.zoom));
238
- drawSpaces();
239
- };
240
- var updateUnit = function (unit) {
241
- if (!spacesRef.current)
242
- return;
243
- spacesRef.current.unit = unit;
244
- dispatch((0, spaces_1.setUnit)(spacesRef.current.unit));
245
- };
246
- var handleRecenter = function (zoomToFit) {
247
- if (!spacesRef.current)
248
- return;
249
- spacesRef.current.centerSpace(canvasRef.current, zoomToFit);
250
- dispatch((0, spaces_1.setZoom)(spacesRef.current.zoom));
251
- dispatch((0, spaces_1.setTranslation)(spacesRef.current.translate));
252
- };
253
- var handleSelectModeHover = function (canvas, cursorPoint) {
254
- if (!spacesRef.current)
255
- return;
256
- if (spacesRef.current.activeElement !== null)
257
- return;
258
- if (translationAnchorRef.current)
259
- return;
260
- spacesRef.current.highlightElementIfInProximity(canvas, cursorPoint);
261
- };
262
- var handleSelectElement = function (e) {
263
- var _a;
264
- if (!spacesRef.current)
265
- return;
266
- if (!canvasRef.current)
267
- return;
268
- if (modeValue !== types_2.IModes.SELECT)
269
- return;
270
- var cursorPoint;
271
- if ('offsetX' in e && 'offsetY' in e)
272
- cursorPoint = [e.offsetX, e.offsetY];
273
- else {
274
- var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
275
- if (!localTouchPoint)
276
- return;
277
- cursorPoint = localTouchPoint;
278
- }
279
- spacesRef.current.selectElementIfInProximity(canvasRef.current, cursorPoint);
280
- var element = spacesRef.current.getElementUiAtPoint(cursorPoint);
281
- if (!element) {
282
- if (selectedElement !== null)
283
- setSelectedElement(null);
284
- if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled) && !spacesRef.current.activeElement)
285
- translationAnchorRef.current = cursorPoint;
286
- return;
287
- }
288
- if (spacesRef.current.activeElement ||
289
- (selectedElement &&
290
- JSON.stringify(element.path) !== JSON.stringify(selectedElement.path)))
291
- setSelectedElement(null);
292
- selectElementPending.current = element;
293
- };
294
- var handleMoveSelectedElement = function (e) {
295
- if (!spacesRef.current)
296
- return;
297
- if (modeValue !== types_2.IModes.SELECT)
298
- return;
299
- if (!canvasRef.current)
300
- return;
301
- var point;
302
- if ('offsetX' in e && 'offsetY' in e)
303
- point = [e.offsetX, e.offsetY];
304
- else {
305
- var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
306
- if (!localTouchPoint)
307
- return;
308
- point = localTouchPoint;
309
- }
310
- spacesRef.current.moveActiveElement(canvasRef.current, point);
311
- selectElementPending.current = null;
312
- };
313
- var handleMoveCanvas = function (e) {
314
- if (!spacesRef.current)
315
- return;
316
- if (modeValue !== types_2.IModes.SELECT)
317
- return;
318
- if (!canvasRef.current)
319
- return;
320
- if (spacesRef.current.selectedElement || !translationAnchorRef.current)
321
- return;
322
- var point;
323
- if ('offsetX' in e && 'offsetY' in e)
324
- point = [e.offsetX, e.offsetY];
325
- else {
326
- var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
327
- if (!localTouchPoint)
328
- return;
329
- point = localTouchPoint;
330
- }
331
- spacesRef.current.translate = [
332
- spacesRef.current.translate[0] +
333
- point[0] -
334
- translationAnchorRef.current[0],
335
- spacesRef.current.translate[1] +
336
- point[1] -
337
- translationAnchorRef.current[1],
338
- ];
339
- translationAnchorRef.current = point;
340
- drawSpaces();
341
- };
342
- var handleFinishMove = function (e) {
343
- var _a;
344
- if (!spacesRef.current)
345
- return;
346
- if (modeValue !== types_2.IModes.SELECT)
347
- return;
348
- if (!canvasRef.current)
349
- return;
350
- if (!((_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
351
- spacesRef.current.cancelMoveActiveElement(canvasRef.current);
352
- return;
353
- }
354
- spacesRef.current.finishMoveActiveElement(canvasRef.current);
355
- if (selectElementPending.current) {
356
- setSelectedElement(selectElementPending.current);
357
- selectElementPending.current = null;
358
- return;
359
- }
360
- if (translationAnchorRef.current) {
361
- translationAnchorRef.current = null;
362
- dispatch((0, spaces_1.setTranslation)(spacesRef.current.translate));
363
- }
364
- };
365
- var handleDrawModeHover = function (canvas, cursorPoint) {
366
- if (!spacesRef.current)
367
- return;
368
- if (spacesRef.current.isDrawWallActive)
369
- return;
370
- spacesRef.current.showGuideAtPoint(canvas, cursorPoint);
371
- };
372
- var handleDrawWallStart = function (e) {
373
- if (!spacesRef.current || !canvasRef.current)
374
- return;
375
- if (modeValue !== types_2.IModes.DRAW)
376
- return;
377
- var startPoint;
378
- if ('offsetX' in e && 'offsetY' in e)
379
- startPoint = [e.offsetX, e.offsetY];
380
- else {
381
- var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
382
- if (!localTouchPoint)
383
- return;
384
- startPoint = localTouchPoint;
385
- }
386
- spacesRef.current.startDrawNewWall(startPoint);
387
- };
388
- var handleDrawWallMouseMove = function (e) {
389
- if (!spacesRef.current || !canvasRef.current)
390
- return;
391
- if (modeValue !== types_2.IModes.DRAW)
392
- return;
393
- if (!spacesRef.current.isDrawWallActive)
394
- return;
395
- var point;
396
- if ('offsetX' in e && 'offsetY' in e)
397
- point = [e.offsetX, e.offsetY];
398
- else {
399
- var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
400
- if (!localTouchPoint)
401
- return;
402
- point = localTouchPoint;
403
- }
404
- spacesRef.current.drawNewWall(canvasRef.current, point);
405
- };
406
- var handleDrawWallFinish = function (e) {
407
- var _a;
408
- if (!spacesRef.current || !canvasRef.current)
409
- return;
410
- if (modeValue !== types_2.IModes.DRAW)
411
- return;
412
- if (!((_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
413
- spacesRef.current.cancelDrawNewWall(canvasRef.current);
414
- return;
415
- }
416
- spacesRef.current.finishDrawNewWall(canvasRef.current);
417
- };
418
- var handleScrollToZoom = function (e) {
419
- var _a;
420
- if (!canvasRef.current)
421
- return;
422
- var zoomSensitivity = ((_a = props.config) === null || _a === void 0 ? void 0 : _a.zoomSensitivity) || constants_1.ZOOM_SENSITIVITY;
423
- updateZoom(-1 * e.deltaY * zoomSensitivity);
424
- e.preventDefault();
425
- };
426
- var handleHover = function (e) {
427
- if (!canvasRef.current)
428
- return;
429
- var cursorPoint = [e.offsetX, e.offsetY];
430
- if (modeValue === types_2.IModes.DRAW)
431
- handleDrawModeHover(canvasRef.current, cursorPoint);
432
- else if (modeValue === types_2.IModes.SELECT)
433
- handleSelectModeHover(canvasRef.current, cursorPoint);
434
- };
435
- var prepFeatureAttributeForOutput = function (type, attribute) {
436
- if (!attribute)
437
- return undefined;
438
- var values = attribute.values.map(function (val) { return (__assign(__assign({}, val), { add: function (addToWallIndex, feature) {
439
- var _a;
440
- return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.addFeature(type, addToWallIndex, __assign({ assetId: val.assetId }, (feature || {})));
441
- } })); });
442
- var value = attribute.value.map(function (val, i) { return (__assign(__assign({}, val), { delete: function () { var _a; return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.deleteFeature(type, i); } })); });
443
- return __assign(__assign({}, attribute), { values: values, value: value });
444
- };
445
- var prepWallAttributeForOutput = function (attribute) {
446
- if (!attribute)
447
- return undefined;
448
- var values = attribute.values.map(function (val) { return (__assign({}, val)); });
449
- var value = attribute.value.map(function (val, i) { return (__assign(__assign({}, val), { delete: function () { var _a; return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.deleteWall(i); }, splitWall: function (offset) { var _a; return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.splitWallAtOffset(i, offset); } })); });
450
- return __assign(__assign({}, attribute), { values: values, value: value });
451
- };
452
- var getElementFromAttributeName = function (attributeName) {
453
- var elementAttr = Object.entries(attributeNames).find(function (_a) {
454
- var _ = _a[0], attrName = _a[1];
455
- return attrName === attributeName;
456
- });
457
- if (!elementAttr)
458
- return;
459
- return elementAttr[0];
460
- };
461
- var handleSetMode = function (mode) {
462
- if (mode === modeValue)
463
- return;
464
- dispatch((0, spaces_1.setMode)(mode));
465
- setSelectedElement(null);
466
- };
467
- var handleReset = function () {
468
- var _a;
469
- (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.deleteAll();
470
- setSelectedElement(null);
471
- };
472
- var handleDeleteElement = function (type, index) {
473
- var _a;
474
- var elementType = type;
475
- if (Object.values(attributeNames).includes(type)) {
476
- var updatedType = getElementFromAttributeName(type);
477
- if (!updatedType)
478
- return;
479
- elementType = updatedType;
480
- }
481
- (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.deleteElement(elementType, index);
482
- setSelectedElement(null);
483
- };
484
- var handleSetShowDimensions = function (val) {
485
- dispatch((0, spaces_1.setShowDimensions)(val));
486
- };
487
- var handleToggleAngleSnapping = function (val) {
488
- if (val === undefined)
489
- dispatch((0, spaces_1.setAngleSnappingEnabled)(!angleSnappingEnabled));
490
- else
491
- dispatch((0, spaces_1.setAngleSnappingEnabled)(val));
492
- setSelectedElement(null);
493
- };
494
- var handleToggleGuideSnapping = function (val) {
495
- if (val === undefined)
496
- dispatch((0, spaces_1.setGuideSnappingEnabled)(!guideSnappingEnabled));
497
- else
498
- dispatch((0, spaces_1.setGuideSnappingEnabled)(val));
499
- setSelectedElement(null);
500
- };
501
- var handleToggleGridSnapping = function (val) {
502
- if (val === undefined)
503
- dispatch((0, spaces_1.setGridSnappingEnabled)(!gridSnappingEnabled));
504
- else
505
- dispatch((0, spaces_1.setGridSnappingEnabled)(val));
506
- setSelectedElement(null);
507
- };
508
- var handleChangeTranslate = function (delta) {
509
- if (!spacesRef.current)
510
- return;
511
- spacesRef.current.translate = [
512
- spacesRef.current.translate[0] + delta[0],
513
- spacesRef.current.translate[1] + delta[1],
514
- ];
515
- dispatch((0, spaces_1.setTranslation)(spacesRef.current.translate));
516
- };
517
- return {
518
- hasLoaded: hasInitialized,
519
- draw: drawSpaces,
520
- canvasRef: canvasRef,
521
- selectedElement: selectedElement === null
522
- ? selectedElement
523
- : __assign(__assign({}, selectedElement), { path: [
524
- attributeNames[selectedElement.path[0]],
525
- selectedElement.path[1],
526
- ], type: selectedElement.path[0], deleteElement: function () { return handleDeleteElement.apply(void 0, selectedElement.path); }, splitWall: selectedElement.path[0] !== types_2.IElements.WALL
527
- ? undefined
528
- : function (offset) {
529
- var _a;
530
- return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.splitWallAtOffset(selectedElement.path[1], offset);
531
- }, addFeature: selectedElement.path[0] !== types_2.IElements.WALL
532
- ? undefined
533
- : function (type, feature) {
534
- var _a;
535
- return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.addFeature(type, selectedElement.path[1], feature);
536
- } }),
537
- mode: {
538
- value: modeValue,
539
- options: [types_2.IModes.SELECT, types_2.IModes.DRAW].map(function (el) { return ({
540
- value: el,
541
- label: el,
542
- selected: modeValue === el,
543
- handleSelect: function () { return handleSetMode(el); },
544
- }); }),
545
- handleChange: handleSetMode,
546
- },
547
- dimensions: {
548
- value: showDimensions,
549
- options: [
550
- types_1.IDimensionOptions.NONE,
551
- types_1.IDimensionOptions.DEFAULT,
552
- types_1.IDimensionOptions.DETAILED,
553
- ].map(function (el) { return ({
554
- value: el,
555
- label: el,
556
- selected: showDimensions === el,
557
- handleSelect: function () { return handleSetShowDimensions(el); },
558
- }); }),
559
- handleChange: handleSetShowDimensions,
560
- },
561
- angleSnapping: {
562
- enabled: angleSnappingEnabled,
563
- handleToggle: handleToggleAngleSnapping,
564
- },
565
- guideSnapping: {
566
- enabled: guideSnappingEnabled,
567
- handleToggle: handleToggleGuideSnapping,
568
- },
569
- gridSnapping: {
570
- enabled: gridSnappingEnabled,
571
- handleToggle: handleToggleGridSnapping,
572
- },
573
- zoom: {
574
- min: (_c = (_b = spacesRef.current) === null || _b === void 0 ? void 0 : _b.zoomMin) !== null && _c !== void 0 ? _c : constants_1.ZOOM_MIN,
575
- max: (_e = (_d = spacesRef.current) === null || _d === void 0 ? void 0 : _d.zoomMax) !== null && _e !== void 0 ? _e : constants_1.ZOOM_MAX,
576
- value: zoom,
577
- handleChange: updateZoom,
578
- },
579
- unit: {
580
- value: unit,
581
- options: [types_2.IUnits.FEET, types_2.IUnits.METER, types_2.IUnits.INCH, types_2.IUnits.CM].map(function (el) { return ({
582
- value: el,
583
- label: el,
584
- selected: unit === el,
585
- handleSelect: function () { return updateUnit(el); },
586
- }); }),
587
- handleChange: updateUnit,
588
- },
589
- wallMode: {
590
- value: wallMode.value,
591
- options: wallMode.options.map(function (mode) { return ({
592
- value: mode,
593
- label: constants_1.wallModeLabels[mode],
594
- selected: mode === wallMode.value,
595
- handleSelect: function () { return dispatch((0, spaces_1.setWallModeValue)(mode)); },
596
- }); }),
597
- handleChange: function (wallMode) {
598
- return dispatch((0, spaces_1.setWallModeValue)(wallMode));
599
- },
600
- },
601
- translate: {
602
- handleChange: handleChangeTranslate,
603
- },
604
- reset: handleReset,
605
- recenter: handleRecenter,
606
- deleteElement: handleDeleteElement,
607
- layouts: layouts.map(function (layout) { return ({
608
- label: layout.label,
609
- loops: layout.loop,
610
- handleSelect: function () {
611
- return window.threekit.configurator.setFullConfiguration(layout.configuration);
612
- },
613
- }); }),
614
- walls: prepWallAttributeForOutput(attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_2.IElements.WALL]]),
615
- windows: prepFeatureAttributeForOutput(types_2.IElements.WINDOW, attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_2.IElements.WINDOW]]),
616
- doors: prepFeatureAttributeForOutput(types_2.IElements.DOOR, attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_2.IElements.DOOR]]),
617
- openings: prepFeatureAttributeForOutput(types_2.IElements.OPENING, attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_2.IElements.OPENING]]),
618
- };
619
- };
620
- useSpaces.themes = themes_1.IThemes;
621
- useSpaces.units = types_2.IUnits;
622
- useSpaces.modes = types_2.IModes;
623
- useSpaces.wallModes = constants_1.WallModes;
624
- useSpaces.LayoutIcon = SpacesLayout_1.default;
625
- exports.default = useSpaces;
@@ -1,3 +0,0 @@
1
- import type { ISpacesStyles } from '../types';
2
- declare const theme: ISpacesStyles;
3
- export default theme;