@threekit-tools/treble 0.0.91 → 0.0.92

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 (165) hide show
  1. package/dist/Treble/Treble.d.ts +1 -1
  2. package/dist/Treble/snapshot.d.ts +22 -0
  3. package/dist/Treble/snapshot.js +247 -0
  4. package/dist/Treble/snapshots.d.ts +1 -1
  5. package/dist/components/ThreekitProvider/index.js +3 -2
  6. package/dist/connection.d.ts +4 -1
  7. package/dist/connection.js +16 -53
  8. package/dist/hooks/useAttribute/index.js +1 -5
  9. package/dist/hooks/useSnapshot/index.d.ts +1 -1
  10. package/dist/hooks/useSpaces/SpacesLayout.d.ts +11 -0
  11. package/dist/hooks/useSpaces/SpacesLayout.js +74 -0
  12. package/dist/hooks/useSpaces/SpacesState.d.ts +164 -0
  13. package/dist/hooks/useSpaces/SpacesState.js +1751 -0
  14. package/dist/hooks/useSpaces/constants.d.ts +64 -0
  15. package/dist/hooks/useSpaces/constants.js +109 -0
  16. package/dist/hooks/useSpaces/dataHandlers.d.ts +20 -0
  17. package/dist/hooks/useSpaces/dataHandlers.js +254 -0
  18. package/dist/hooks/useSpaces/draw/clearCanvas.d.ts +2 -0
  19. package/dist/hooks/useSpaces/draw/clearCanvas.js +9 -0
  20. package/dist/hooks/useSpaces/draw/drawBackground.d.ts +2 -0
  21. package/dist/hooks/useSpaces/draw/drawBackground.js +12 -0
  22. package/dist/hooks/useSpaces/draw/drawDimensions.d.ts +3 -0
  23. package/dist/hooks/useSpaces/draw/drawDimensions.js +53 -0
  24. package/dist/hooks/useSpaces/draw/drawDoors.d.ts +9 -0
  25. package/dist/hooks/useSpaces/draw/drawDoors.js +99 -0
  26. package/dist/hooks/useSpaces/draw/drawFloor.d.ts +3 -0
  27. package/dist/hooks/useSpaces/draw/drawFloor.js +36 -0
  28. package/dist/hooks/useSpaces/draw/drawGrid.d.ts +3 -0
  29. package/dist/hooks/useSpaces/draw/drawGrid.js +33 -0
  30. package/dist/hooks/useSpaces/draw/drawGuides.d.ts +3 -0
  31. package/dist/hooks/useSpaces/draw/drawGuides.js +23 -0
  32. package/dist/hooks/useSpaces/draw/drawOpenings.d.ts +9 -0
  33. package/dist/hooks/useSpaces/draw/drawOpenings.js +72 -0
  34. package/dist/hooks/useSpaces/draw/drawVertices.d.ts +8 -0
  35. package/dist/hooks/useSpaces/draw/drawVertices.js +61 -0
  36. package/dist/hooks/useSpaces/draw/drawWalls.d.ts +10 -0
  37. package/dist/hooks/useSpaces/draw/drawWalls.js +88 -0
  38. package/dist/hooks/useSpaces/draw/drawWindows.d.ts +9 -0
  39. package/dist/hooks/useSpaces/draw/drawWindows.js +82 -0
  40. package/dist/hooks/useSpaces/draw/index.d.ts +11 -0
  41. package/dist/hooks/useSpaces/draw/index.js +129 -0
  42. package/dist/hooks/useSpaces/geometry/addThicknessToLine.d.ts +3 -0
  43. package/dist/hooks/useSpaces/geometry/addThicknessToLine.js +13 -0
  44. package/dist/hooks/useSpaces/geometry/areLinesEqual.d.ts +3 -0
  45. package/dist/hooks/useSpaces/geometry/areLinesEqual.js +17 -0
  46. package/dist/hooks/useSpaces/geometry/arePointsEqual.d.ts +3 -0
  47. package/dist/hooks/useSpaces/geometry/arePointsEqual.js +8 -0
  48. package/dist/hooks/useSpaces/geometry/arePointsWithinProximity.d.ts +3 -0
  49. package/dist/hooks/useSpaces/geometry/arePointsWithinProximity.js +11 -0
  50. package/dist/hooks/useSpaces/geometry/closestPointOnLine.d.ts +3 -0
  51. package/dist/hooks/useSpaces/geometry/closestPointOnLine.js +13 -0
  52. package/dist/hooks/useSpaces/geometry/doLinesOverlap.d.ts +2 -0
  53. package/dist/hooks/useSpaces/geometry/doLinesOverlap.js +16 -0
  54. package/dist/hooks/useSpaces/geometry/euclideanMod.d.ts +2 -0
  55. package/dist/hooks/useSpaces/geometry/euclideanMod.js +6 -0
  56. package/dist/hooks/useSpaces/geometry/findLoops.d.ts +6 -0
  57. package/dist/hooks/useSpaces/geometry/findLoops.js +117 -0
  58. package/dist/hooks/useSpaces/geometry/getAllLineIntersections.d.ts +6 -0
  59. package/dist/hooks/useSpaces/geometry/getAllLineIntersections.js +23 -0
  60. package/dist/hooks/useSpaces/geometry/getAngleOfLineSegment.d.ts +3 -0
  61. package/dist/hooks/useSpaces/geometry/getAngleOfLineSegment.js +7 -0
  62. package/dist/hooks/useSpaces/geometry/getClosestPointOnLineSegment.d.ts +3 -0
  63. package/dist/hooks/useSpaces/geometry/getClosestPointOnLineSegment.js +17 -0
  64. package/dist/hooks/useSpaces/geometry/getDistanceToLine.d.ts +3 -0
  65. package/dist/hooks/useSpaces/geometry/getDistanceToLine.js +10 -0
  66. package/dist/hooks/useSpaces/geometry/getLengthOfLineSegment.d.ts +3 -0
  67. package/dist/hooks/useSpaces/geometry/getLengthOfLineSegment.js +7 -0
  68. package/dist/hooks/useSpaces/geometry/getLineAtOffsetOnLineSegment.d.ts +3 -0
  69. package/dist/hooks/useSpaces/geometry/getLineAtOffsetOnLineSegment.js +17 -0
  70. package/dist/hooks/useSpaces/geometry/getLineOtherPoint.d.ts +3 -0
  71. package/dist/hooks/useSpaces/geometry/getLineOtherPoint.js +11 -0
  72. package/dist/hooks/useSpaces/geometry/getLineSegmentsIntersection.d.ts +3 -0
  73. package/dist/hooks/useSpaces/geometry/getLineSegmentsIntersection.js +43 -0
  74. package/dist/hooks/useSpaces/geometry/getMidpointOfLineSegment.d.ts +3 -0
  75. package/dist/hooks/useSpaces/geometry/getMidpointOfLineSegment.js +9 -0
  76. package/dist/hooks/useSpaces/geometry/getParallelLineSegmentAtDistance.d.ts +3 -0
  77. package/dist/hooks/useSpaces/geometry/getParallelLineSegmentAtDistance.js +20 -0
  78. package/dist/hooks/useSpaces/geometry/getPointAtOffsetOnLineSegment.d.ts +3 -0
  79. package/dist/hooks/useSpaces/geometry/getPointAtOffsetOnLineSegment.js +11 -0
  80. package/dist/hooks/useSpaces/geometry/getPolygonArea.d.ts +3 -0
  81. package/dist/hooks/useSpaces/geometry/getPolygonArea.js +15 -0
  82. package/dist/hooks/useSpaces/geometry/getQuadrilateralArea.d.ts +3 -0
  83. package/dist/hooks/useSpaces/geometry/getQuadrilateralArea.js +16 -0
  84. package/dist/hooks/useSpaces/geometry/getTangetIntersectionAndOffset.d.ts +6 -0
  85. package/dist/hooks/useSpaces/geometry/getTangetIntersectionAndOffset.js +17 -0
  86. package/dist/hooks/useSpaces/geometry/getTriangleArea.d.ts +3 -0
  87. package/dist/hooks/useSpaces/geometry/getTriangleArea.js +9 -0
  88. package/dist/hooks/useSpaces/geometry/getUnitVectorOfLineSegment.d.ts +3 -0
  89. package/dist/hooks/useSpaces/geometry/getUnitVectorOfLineSegment.js +12 -0
  90. package/dist/hooks/useSpaces/geometry/index.d.ts +30 -0
  91. package/dist/hooks/useSpaces/geometry/index.js +64 -0
  92. package/dist/hooks/useSpaces/geometry/isPointInPolygon.d.ts +3 -0
  93. package/dist/hooks/useSpaces/geometry/isPointInPolygon.js +21 -0
  94. package/dist/hooks/useSpaces/geometry/isPointInQuadrilateral.d.ts +3 -0
  95. package/dist/hooks/useSpaces/geometry/isPointInQuadrilateral.js +25 -0
  96. package/dist/hooks/useSpaces/geometry/orderCoordinatesOnLineSegment.d.ts +3 -0
  97. package/dist/hooks/useSpaces/geometry/orderCoordinatesOnLineSegment.js +11 -0
  98. package/dist/hooks/useSpaces/geometry/splitLineAtOffset.d.ts +3 -0
  99. package/dist/hooks/useSpaces/geometry/splitLineAtOffset.js +12 -0
  100. package/dist/hooks/useSpaces/geometry/splitLineAtPoint.d.ts +3 -0
  101. package/dist/hooks/useSpaces/geometry/splitLineAtPoint.js +9 -0
  102. package/dist/hooks/useSpaces/geometry/splitLineAtPoints.d.ts +3 -0
  103. package/dist/hooks/useSpaces/geometry/splitLineAtPoints.js +28 -0
  104. package/dist/hooks/useSpaces/index.d.ts +82 -0
  105. package/dist/hooks/useSpaces/index.js +482 -0
  106. package/dist/hooks/useSpaces/themes/blueprint.d.ts +3 -0
  107. package/dist/hooks/useSpaces/themes/blueprint.js +96 -0
  108. package/dist/hooks/useSpaces/themes/default.d.ts +3 -0
  109. package/dist/hooks/useSpaces/themes/default.js +96 -0
  110. package/dist/hooks/useSpaces/themes/index.d.ts +11 -0
  111. package/dist/hooks/useSpaces/themes/index.js +21 -0
  112. package/dist/hooks/useSpaces/themes/light.d.ts +3 -0
  113. package/dist/hooks/useSpaces/themes/light.js +96 -0
  114. package/dist/hooks/useSpaces/types.d.ts +339 -0
  115. package/dist/hooks/useSpaces/types.js +54 -0
  116. package/dist/hooks/useSpaces/validators/areWallsDuplicated.d.ts +3 -0
  117. package/dist/hooks/useSpaces/validators/areWallsDuplicated.js +61 -0
  118. package/dist/hooks/useSpaces/validators/areWallsIntersecting.d.ts +3 -0
  119. package/dist/hooks/useSpaces/validators/areWallsIntersecting.js +42 -0
  120. package/dist/hooks/useSpaces/validators/areWallsOrphaningFeatures.d.ts +3 -0
  121. package/dist/hooks/useSpaces/validators/areWallsOrphaningFeatures.js +52 -0
  122. package/dist/hooks/useSpaces/validators/areWallsTooShort.d.ts +3 -0
  123. package/dist/hooks/useSpaces/validators/areWallsTooShort.js +37 -0
  124. package/dist/hooks/useSpaces/validators/index.d.ts +15 -0
  125. package/dist/hooks/useSpaces/validators/index.js +40 -0
  126. package/dist/hooks/useSpaces/validators/isFeatureCollidingWithExistingFeature.d.ts +3 -0
  127. package/dist/hooks/useSpaces/validators/isFeatureCollidingWithExistingFeature.js +31 -0
  128. package/dist/hooks/useSpaces/validators/isFeatureOutsideWallBounds.d.ts +3 -0
  129. package/dist/hooks/useSpaces/validators/isFeatureOutsideWallBounds.js +19 -0
  130. package/dist/hooks/useSpaces/validators/isLineTooShort.d.ts +3 -0
  131. package/dist/hooks/useSpaces/validators/isLineTooShort.js +26 -0
  132. package/dist/hooks/useSpaces/validators/isVertexLandingOnFeature.d.ts +4 -0
  133. package/dist/hooks/useSpaces/validators/isVertexLandingOnFeature.js +19 -0
  134. package/dist/hooks/useSpaces/validators/isWallEndingOnFeature.d.ts +3 -0
  135. package/dist/hooks/useSpaces/validators/isWallEndingOnFeature.js +19 -0
  136. package/dist/hooks/useSpaces/validators/isWallIntersectingFeature.d.ts +3 -0
  137. package/dist/hooks/useSpaces/validators/isWallIntersectingFeature.js +41 -0
  138. package/dist/hooks/useSpaces/validators/isWallOverlappingExisitingWalls.d.ts +3 -0
  139. package/dist/hooks/useSpaces/validators/isWallOverlappingExisitingWalls.js +54 -0
  140. package/dist/hooks/useSpaces/validators/isWallTooShort.d.ts +3 -0
  141. package/dist/hooks/useSpaces/validators/isWallTooShort.js +10 -0
  142. package/dist/hooks/useSpaces/validators/messaging.d.ts +8 -0
  143. package/dist/hooks/useSpaces/validators/messaging.js +18 -0
  144. package/dist/icons/Player3D.d.ts +3 -0
  145. package/dist/icons/Player3D.js +21 -0
  146. package/dist/icons/Ruler copy.d.ts +3 -0
  147. package/dist/icons/Ruler copy.js +22 -0
  148. package/dist/icons/RulerBlank.d.ts +3 -0
  149. package/dist/icons/RulerBlank.js +25 -0
  150. package/dist/icons/RulerDetailed copy.d.ts +3 -0
  151. package/dist/icons/RulerDetailed copy.js +27 -0
  152. package/dist/icons/RulerDetailed.d.ts +3 -0
  153. package/dist/icons/RulerDetailed.js +27 -0
  154. package/dist/icons/types.d.ts +1 -1
  155. package/dist/store/attributes.d.ts +1 -1
  156. package/dist/store/index.d.ts +10 -31
  157. package/dist/store/spaces.d.ts +47 -0
  158. package/dist/store/spaces.js +197 -0
  159. package/dist/store/treble.d.ts +3 -1
  160. package/dist/store/treble.js +45 -30
  161. package/dist/store/wishlist.d.ts +20 -2
  162. package/dist/types.d.ts +12 -3
  163. package/package.json +2 -1
  164. package/dist/hooks/useSpaces/Canvas.d.ts +0 -37
  165. package/dist/hooks/useSpaces/Canvas.js +0 -199
@@ -0,0 +1,482 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ var react_1 = require("react");
41
+ var types_1 = require("./types");
42
+ var types_2 = require("./types");
43
+ var useConfigurator_1 = __importDefault(require("../useConfigurator"));
44
+ var SpacesState_1 = __importDefault(require("./SpacesState"));
45
+ var constants_1 = require("./constants");
46
+ var themes_1 = __importStar(require("./themes"));
47
+ var SpacesLayout_1 = __importDefault(require("./SpacesLayout"));
48
+ var store_1 = require("../../store");
49
+ var spaces_1 = require("../../store/spaces");
50
+ var useThreekitInitStatus_1 = __importDefault(require("../useThreekitInitStatus"));
51
+ var useSpaces = function (props) {
52
+ var _a;
53
+ var attributesState = (0, useConfigurator_1.default)()[0];
54
+ var hasLoaded = (0, useThreekitInitStatus_1.default)();
55
+ var dispatch = (0, store_1.useThreekitDispatch)();
56
+ var layouts = (0, store_1.useThreekitSelector)(spaces_1.getLayouts);
57
+ var zoom = (0, store_1.useThreekitSelector)(spaces_1.getZoom);
58
+ var unit = (0, store_1.useThreekitSelector)(spaces_1.getUnit);
59
+ var translation = (0, store_1.useThreekitSelector)(spaces_1.getTranslation);
60
+ var modeValue = (0, store_1.useThreekitSelector)(spaces_1.getMode);
61
+ var showDimensions = (0, store_1.useThreekitSelector)(spaces_1.getShowDimensions);
62
+ var angleSnappingEnabled = (0, store_1.useThreekitSelector)(spaces_1.getAngleSnappingEnabled);
63
+ var guideSnappingEnabled = (0, store_1.useThreekitSelector)(spaces_1.getGuideSnappingEnabled);
64
+ var gridSnappingEnabled = (0, store_1.useThreekitSelector)(spaces_1.getGridSnappingEnabled);
65
+ var _b = (0, react_1.useState)(null), selectedElement = _b[0], setSelectedElement = _b[1];
66
+ var canvasRef = (0, react_1.useRef)(null);
67
+ var selectElementPending = (0, react_1.useRef)(null);
68
+ var translationAnchorRef = (0, react_1.useRef)(null);
69
+ var preppedConfig = Object.assign({
70
+ scale: constants_1.SCALE,
71
+ unit: types_2.IUnits.FEET,
72
+ snapProximity: constants_1.SNAP_PROXIMITY,
73
+ zoomDefault: zoom || constants_1.ZOOM_DEFAULT,
74
+ translateDefault: translation || constants_1.TRANSLATE_DEFAULT,
75
+ disableGuides: false,
76
+ styles: ((_a = props.config) === null || _a === void 0 ? void 0 : _a.theme) && themes_1.default[props.config.theme]
77
+ ? themes_1.default[props.config.theme]
78
+ : themes_1.default[themes_1.IThemes.DEFAULT],
79
+ }, props.config);
80
+ var attributeNames = Object.assign(constants_1.ATTRIBUTE_NAME_DEFAULTS, props.attributes);
81
+ var spacesRef = (0, react_1.useRef)(new SpacesState_1.default(__assign(__assign({}, props), { config: preppedConfig, attributes: attributeNames })));
82
+ var drawSpaces = function () { return spacesRef.current.drawSpaces(canvasRef.current); };
83
+ (0, react_1.useEffect)(function () {
84
+ var attributesDelinked = JSON.parse(JSON.stringify(attributesState));
85
+ spacesRef.current.setAttributesToState(attributesDelinked);
86
+ drawSpaces();
87
+ }, [attributesState]);
88
+ (0, react_1.useEffect)(function () {
89
+ var _a;
90
+ var guidesEnabled = !(((_a = props.config) === null || _a === void 0 ? void 0 : _a.disableGuides) || false);
91
+ dispatch((0, spaces_1.setGuideSnappingEnabled)(guidesEnabled));
92
+ spacesRef.current.guideSnappingEnabled = guidesEnabled;
93
+ }, []);
94
+ (0, react_1.useEffect)(function () {
95
+ var _a;
96
+ if (zoom &&
97
+ ((_a = props.config) === null || _a === void 0 ? void 0 : _a.zoomDefault) &&
98
+ props.config.zoomDefault >= spacesRef.current.zoomMin &&
99
+ spacesRef.current.zoomMax >= props.config.zoomDefault)
100
+ updateZoom(props.config.zoomDefault);
101
+ updateUnit(preppedConfig.unit);
102
+ }, []);
103
+ (0, react_1.useEffect)(function () {
104
+ var _a, _b;
105
+ if (canvasRef === null || canvasRef === void 0 ? void 0 : canvasRef.current) {
106
+ spacesRef.current.canvasDimensions = [
107
+ canvasRef.current.width,
108
+ canvasRef.current.height,
109
+ ];
110
+ canvasRef.current.addEventListener('mousedown', handleDrawWallStart);
111
+ canvasRef.current.addEventListener('mousemove', handleDrawWallMouseMove);
112
+ document.addEventListener('mouseup', handleDrawWallFinish);
113
+ canvasRef.current.addEventListener('mousemove', handleHover);
114
+ canvasRef.current.addEventListener('mousedown', handleSelectElement);
115
+ canvasRef.current.addEventListener('mousemove', handleMoveSelectedElement);
116
+ if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled))
117
+ canvasRef.current.addEventListener('mousemove', handleMoveCanvas);
118
+ document.addEventListener('mouseup', handleSetSelectedElement);
119
+ if (!((_b = props.config) === null || _b === void 0 ? void 0 : _b.zoomDisabled))
120
+ canvasRef.current.addEventListener('wheel', handleScrollToZoom);
121
+ }
122
+ return function () {
123
+ var _a, _b;
124
+ if (canvasRef === null || canvasRef === void 0 ? void 0 : canvasRef.current) {
125
+ canvasRef.current.removeEventListener('mousedown', handleDrawWallStart);
126
+ canvasRef.current.removeEventListener('mousemove', handleDrawWallMouseMove);
127
+ document.removeEventListener('mouseup', handleDrawWallFinish);
128
+ canvasRef.current.removeEventListener('mousemove', handleHover);
129
+ canvasRef.current.removeEventListener('mousedown', handleSelectElement);
130
+ canvasRef.current.removeEventListener('mousemove', handleMoveSelectedElement);
131
+ if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled))
132
+ canvasRef.current.removeEventListener('mousemove', handleMoveCanvas);
133
+ document.removeEventListener('mouseup', handleSetSelectedElement);
134
+ if (!((_b = props.config) === null || _b === void 0 ? void 0 : _b.zoomDisabled))
135
+ canvasRef.current.removeEventListener('wheel', handleScrollToZoom);
136
+ }
137
+ };
138
+ });
139
+ (0, react_1.useEffect)(function () {
140
+ spacesRef.current.showDimensions = showDimensions;
141
+ spacesRef.current.angleSnappingEnabled = angleSnappingEnabled;
142
+ spacesRef.current.guideSnappingEnabled = guideSnappingEnabled;
143
+ spacesRef.current.gridSnappingEnabled = gridSnappingEnabled;
144
+ spacesRef.current.selectedElement = selectedElement
145
+ ? {
146
+ type: selectedElement.path[0],
147
+ index: selectedElement.path[1],
148
+ }
149
+ : null;
150
+ drawSpaces();
151
+ }, [
152
+ selectedElement,
153
+ showDimensions,
154
+ angleSnappingEnabled,
155
+ guideSnappingEnabled,
156
+ gridSnappingEnabled,
157
+ ]);
158
+ (0, react_1.useEffect)(function () {
159
+ if (!hasLoaded)
160
+ return;
161
+ var layoutIds = props.layouts || [];
162
+ dispatch((0, spaces_1.hydrateLayouts)(layoutIds, {
163
+ walls: attributeNames[types_2.IElements.WALL],
164
+ startX: attributeNames.wallStartX,
165
+ startZ: attributeNames.wallStartZ,
166
+ endX: attributeNames.wallEndX,
167
+ endZ: attributeNames.wallEndZ,
168
+ }));
169
+ }, [hasLoaded, JSON.stringify(props.layouts)]);
170
+ var updateZoom = function (value) {
171
+ spacesRef.current.zoom = value;
172
+ if (!spacesRef.current.zoom)
173
+ return;
174
+ dispatch((0, spaces_1.setZoom)(spacesRef.current.zoom));
175
+ };
176
+ var updateUnit = function (unit) {
177
+ if (!spacesRef.current)
178
+ return;
179
+ spacesRef.current.unit = unit;
180
+ if (!spacesRef.current.unit)
181
+ return;
182
+ dispatch((0, spaces_1.setUnit)(spacesRef.current.unit));
183
+ spacesRef.current.drawSpaces(canvasRef.current);
184
+ };
185
+ var handleRecenter = function (zoomToFit) {
186
+ spacesRef.current.centerSpace(canvasRef.current, zoomToFit);
187
+ dispatch((0, spaces_1.setZoom)(spacesRef.current.zoom));
188
+ };
189
+ var handleSelectModeHover = function (canvas, cursorPoint) {
190
+ if (spacesRef.current.activeElement !== null)
191
+ return;
192
+ if (translationAnchorRef.current)
193
+ return;
194
+ spacesRef.current.highlightElementIfInProximity(canvas, cursorPoint);
195
+ };
196
+ var handleSelectElement = function (e) {
197
+ var _a;
198
+ if (!canvasRef.current)
199
+ return;
200
+ if (modeValue !== types_2.IModes.SELECT)
201
+ return;
202
+ var cursorPoint = [e.offsetX, e.offsetY];
203
+ spacesRef.current.selectElementIfInProximity(canvasRef.current, cursorPoint);
204
+ var element = spacesRef.current.getElementUiAtPoint(cursorPoint);
205
+ if (!element) {
206
+ if (selectedElement !== null)
207
+ setSelectedElement(null);
208
+ if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled) && !spacesRef.current.activeElement)
209
+ translationAnchorRef.current = cursorPoint;
210
+ return;
211
+ }
212
+ if (spacesRef.current.activeElement ||
213
+ (selectedElement &&
214
+ JSON.stringify(element.path) !== JSON.stringify(selectedElement.path)))
215
+ setSelectedElement(null);
216
+ selectElementPending.current = element;
217
+ };
218
+ var handleMoveSelectedElement = function (e) {
219
+ if (modeValue !== types_2.IModes.SELECT)
220
+ return;
221
+ if (!canvasRef.current)
222
+ return;
223
+ var point = [e.offsetX, e.offsetY];
224
+ spacesRef.current.moveActiveElement(canvasRef.current, point);
225
+ selectElementPending.current = null;
226
+ };
227
+ var handleMoveCanvas = function (e) {
228
+ if (modeValue !== types_2.IModes.SELECT)
229
+ return;
230
+ if (!canvasRef.current)
231
+ return;
232
+ if (spacesRef.current.selectedElement || !translationAnchorRef.current)
233
+ return;
234
+ var delta = [
235
+ e.offsetX - translationAnchorRef.current[0],
236
+ e.offsetY - translationAnchorRef.current[1],
237
+ ];
238
+ handleChangeTranslate(delta);
239
+ translationAnchorRef.current = [e.offsetX, e.offsetY];
240
+ };
241
+ var handleSetSelectedElement = function (e) {
242
+ var _a;
243
+ if (modeValue !== types_2.IModes.SELECT)
244
+ return;
245
+ if (!canvasRef.current)
246
+ return;
247
+ if (!((_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
248
+ spacesRef.current.cancelMoveActiveElement(canvasRef.current);
249
+ return;
250
+ }
251
+ spacesRef.current.finishMoveActiveElement(canvasRef.current);
252
+ if (selectElementPending.current) {
253
+ setSelectedElement(selectElementPending.current);
254
+ selectElementPending.current = null;
255
+ return;
256
+ }
257
+ if (translationAnchorRef.current)
258
+ translationAnchorRef.current = null;
259
+ };
260
+ var handleDrawModeHover = function (canvas, cursorPoint) {
261
+ if (spacesRef.current.isDrawWallActive)
262
+ return;
263
+ spacesRef.current.showGuideAtPoint(canvas, cursorPoint);
264
+ };
265
+ var handleDrawWallStart = function (e) {
266
+ if (modeValue !== types_2.IModes.DRAW)
267
+ return;
268
+ var cursorPoint = [e.offsetX, e.offsetY];
269
+ spacesRef.current.startDrawNewWall(cursorPoint);
270
+ };
271
+ var handleDrawWallMouseMove = function (e) {
272
+ if (modeValue !== types_2.IModes.DRAW)
273
+ return;
274
+ if (!canvasRef.current)
275
+ return;
276
+ var cursorPoint = [e.offsetX, e.offsetY];
277
+ if (spacesRef.current.isDrawWallActive)
278
+ spacesRef.current.drawNewWall(canvasRef.current, cursorPoint);
279
+ };
280
+ var handleDrawWallFinish = function (e) {
281
+ var _a;
282
+ if (modeValue !== types_2.IModes.DRAW)
283
+ return;
284
+ if (!canvasRef.current)
285
+ return;
286
+ if (!((_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
287
+ spacesRef.current.cancelDrawNewWall(canvasRef.current);
288
+ return;
289
+ }
290
+ spacesRef.current.finishDrawNewWall(canvasRef.current);
291
+ };
292
+ var handleScrollToZoom = function (e) {
293
+ var _a;
294
+ if (!canvasRef.current)
295
+ return;
296
+ var zoomSensitivity = ((_a = props.config) === null || _a === void 0 ? void 0 : _a.zoomSensitivity) || constants_1.ZOOM_SENSITIVITY;
297
+ updateZoom(-1 * e.deltaY * zoomSensitivity);
298
+ e.preventDefault();
299
+ };
300
+ var handleHover = function (e) {
301
+ if (!canvasRef.current)
302
+ return;
303
+ var cursorPoint = [e.offsetX, e.offsetY];
304
+ if (modeValue === types_2.IModes.DRAW)
305
+ handleDrawModeHover(canvasRef.current, cursorPoint);
306
+ else if (modeValue === types_2.IModes.SELECT)
307
+ handleSelectModeHover(canvasRef.current, cursorPoint);
308
+ };
309
+ var prepFeatureAttributeForOutput = function (type, attribute) {
310
+ if (!attribute)
311
+ return undefined;
312
+ var values = attribute.values.map(function (val) { return (__assign(__assign({}, val), { add: function (addToWallIndex, feature) {
313
+ return spacesRef.current.addFeature(type, addToWallIndex, __assign({ assetId: val.assetId }, (feature || {})));
314
+ } })); });
315
+ var value = attribute.value.map(function (val, i) { return (__assign(__assign({}, val), { delete: function () { return spacesRef.current.deleteFeature(type, i); } })); });
316
+ return __assign(__assign({}, attribute), { values: values, value: value });
317
+ };
318
+ var prepWallAttributeForOutput = function (attribute) {
319
+ if (!attribute)
320
+ return undefined;
321
+ var values = attribute.values.map(function (val) { return (__assign({}, val)); });
322
+ 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); } })); });
323
+ return __assign(__assign({}, attribute), { values: values, value: value });
324
+ };
325
+ var getElementFromAttributeName = function (attributeName) {
326
+ var elementAttr = Object.entries(attributeNames).find(function (_a) {
327
+ var _ = _a[0], attrName = _a[1];
328
+ return attrName === attributeName;
329
+ });
330
+ if (!elementAttr)
331
+ return;
332
+ return elementAttr[0];
333
+ };
334
+ var handleSetMode = function (mode) {
335
+ if (mode === modeValue)
336
+ return;
337
+ drawSpaces();
338
+ dispatch((0, spaces_1.setMode)(mode));
339
+ setSelectedElement(null);
340
+ };
341
+ var handleReset = function () {
342
+ var _a;
343
+ (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.deleteAll();
344
+ setSelectedElement(null);
345
+ };
346
+ var handleDeleteElement = function (type, index) {
347
+ var _a;
348
+ var elementType = type;
349
+ if (Object.values(attributeNames).includes(type)) {
350
+ var updatedType = getElementFromAttributeName(type);
351
+ if (!updatedType)
352
+ return;
353
+ elementType = updatedType;
354
+ }
355
+ (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.deleteElement(elementType, index);
356
+ setSelectedElement(null);
357
+ };
358
+ var handleSetShowDimensions = function (val) {
359
+ dispatch((0, spaces_1.setShowDimensions)(val));
360
+ };
361
+ var handleToggleAngleSnapping = function (val) {
362
+ if (val === undefined)
363
+ dispatch((0, spaces_1.setAngleSnappingEnabled)(!angleSnappingEnabled));
364
+ else
365
+ dispatch((0, spaces_1.setAngleSnappingEnabled)(val));
366
+ setSelectedElement(null);
367
+ };
368
+ var handleToggleGuideSnapping = function (val) {
369
+ if (val === undefined)
370
+ dispatch((0, spaces_1.setGuideSnappingEnabled)(!guideSnappingEnabled));
371
+ else
372
+ dispatch((0, spaces_1.setGuideSnappingEnabled)(val));
373
+ setSelectedElement(null);
374
+ };
375
+ var handleToggleGridSnapping = function (val) {
376
+ if (val === undefined)
377
+ dispatch((0, spaces_1.setGridSnappingEnabled)(!gridSnappingEnabled));
378
+ else
379
+ dispatch((0, spaces_1.setGridSnappingEnabled)(val));
380
+ setSelectedElement(null);
381
+ };
382
+ var handleChangeTranslate = function (delta) {
383
+ spacesRef.current.translate = [
384
+ spacesRef.current.translate[0] + delta[0],
385
+ spacesRef.current.translate[1] + delta[1],
386
+ ];
387
+ dispatch((0, spaces_1.setTranslation)(spacesRef.current.translate));
388
+ drawSpaces();
389
+ };
390
+ return {
391
+ draw: drawSpaces,
392
+ canvasRef: canvasRef,
393
+ selectedElement: selectedElement === null
394
+ ? selectedElement
395
+ : __assign(__assign({}, selectedElement), { path: [
396
+ attributeNames[selectedElement.path[0]],
397
+ selectedElement.path[1],
398
+ ], type: selectedElement.path[0], deleteElement: function () { return handleDeleteElement.apply(void 0, selectedElement.path); }, splitWall: selectedElement.path[0] !== types_2.IElements.WALL
399
+ ? undefined
400
+ : function (offset) {
401
+ return spacesRef.current.splitWallAtOffset(selectedElement.path[1], offset);
402
+ }, addFeature: selectedElement.path[0] !== types_2.IElements.WALL
403
+ ? undefined
404
+ : function (type, feature) {
405
+ return spacesRef.current.addFeature(type, selectedElement.path[1], feature);
406
+ } }),
407
+ mode: {
408
+ value: modeValue,
409
+ options: [types_2.IModes.SELECT, types_2.IModes.DRAW].map(function (el) { return ({
410
+ value: el,
411
+ label: el,
412
+ selected: modeValue === el,
413
+ handleSelect: function () { return handleSetMode(el); },
414
+ }); }),
415
+ handleChange: handleSetMode,
416
+ },
417
+ dimensions: {
418
+ value: showDimensions,
419
+ options: [
420
+ types_1.IDimensionOptions.NONE,
421
+ types_1.IDimensionOptions.DEFAULT,
422
+ types_1.IDimensionOptions.DETAILED,
423
+ ].map(function (el) { return ({
424
+ value: el,
425
+ label: el,
426
+ selected: showDimensions === el,
427
+ handleSelect: function () { return handleSetShowDimensions(el); },
428
+ }); }),
429
+ handleChange: handleSetShowDimensions,
430
+ },
431
+ angleSnapping: {
432
+ enabled: angleSnappingEnabled,
433
+ handleToggle: handleToggleAngleSnapping,
434
+ },
435
+ guideSnapping: {
436
+ enabled: guideSnappingEnabled,
437
+ handleToggle: handleToggleGuideSnapping,
438
+ },
439
+ gridSnapping: {
440
+ enabled: gridSnappingEnabled,
441
+ handleToggle: handleToggleGridSnapping,
442
+ },
443
+ zoom: {
444
+ min: spacesRef.current.zoomMin,
445
+ max: spacesRef.current.zoomMax,
446
+ value: zoom || constants_1.ZOOM_DEFAULT,
447
+ handleChange: updateZoom,
448
+ },
449
+ unit: {
450
+ value: unit,
451
+ options: [types_2.IUnits.FEET, types_2.IUnits.METER, types_2.IUnits.INCH, types_2.IUnits.CM].map(function (el) { return ({
452
+ value: el,
453
+ label: el,
454
+ selected: unit === el,
455
+ handleSelect: function () { return updateUnit(el); },
456
+ }); }),
457
+ handleChange: updateUnit,
458
+ },
459
+ translate: {
460
+ handleChange: handleChangeTranslate,
461
+ },
462
+ reset: handleReset,
463
+ recenter: handleRecenter,
464
+ deleteElement: handleDeleteElement,
465
+ layouts: layouts.map(function (layout) { return ({
466
+ label: layout.label,
467
+ loops: layout.loop,
468
+ handleSelect: function () {
469
+ return window.threekit.configurator.setFullConfiguration(layout.configuration);
470
+ },
471
+ }); }),
472
+ walls: prepWallAttributeForOutput(attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_2.IElements.WALL]]),
473
+ windows: prepFeatureAttributeForOutput(types_2.IElements.WINDOW, attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_2.IElements.WINDOW]]),
474
+ doors: prepFeatureAttributeForOutput(types_2.IElements.DOOR, attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_2.IElements.DOOR]]),
475
+ openings: prepFeatureAttributeForOutput(types_2.IElements.OPENING, attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_2.IElements.OPENING]]),
476
+ };
477
+ };
478
+ useSpaces.themes = themes_1.IThemes;
479
+ useSpaces.units = types_2.IUnits;
480
+ useSpaces.modes = types_2.IModes;
481
+ useSpaces.LayoutIcon = SpacesLayout_1.default;
482
+ exports.default = useSpaces;
@@ -0,0 +1,3 @@
1
+ import type { ISpacesStyles } from '../types';
2
+ declare const theme: ISpacesStyles;
3
+ export default theme;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var WALL_THICKNESS = 22;
4
+ var VERTEX_RADIUS = (WALL_THICKNESS - 8) / 2;
5
+ var FEATURE_THICKNESS = WALL_THICKNESS + 6;
6
+ var HIGHLIGHT_COLOR = '#36738E';
7
+ var ACTIVE_COLOR = 'green';
8
+ var ERROR_COLOR = 'red';
9
+ var theme = {
10
+ grid: {
11
+ lineThickness: 2,
12
+ lineColor: '#fff',
13
+ showSubdivisions: true,
14
+ subdivisionLineThickness: 1,
15
+ subdivisionLineColor: '#fff',
16
+ subdivisionThreshold: 20,
17
+ backgroundColor: '#37588B',
18
+ },
19
+ guides: {
20
+ color: 'red',
21
+ thickness: 1,
22
+ },
23
+ floor: {
24
+ color: '#eee',
25
+ textColor: '#666',
26
+ },
27
+ dimensions: {
28
+ padding: WALL_THICKNESS / 2 + 12,
29
+ lineThickness: 1,
30
+ lineColor: '#fff',
31
+ fontSize: 14,
32
+ font: 'Helvetica',
33
+ textColor: '#444',
34
+ textBackgroundColor: '#fff',
35
+ },
36
+ wall: {
37
+ fill: '#848484',
38
+ stroke: '#fff',
39
+ strokeWidth: 1,
40
+ thickness: WALL_THICKNESS,
41
+ highlight: {
42
+ fill: HIGHLIGHT_COLOR,
43
+ stroke: HIGHLIGHT_COLOR,
44
+ },
45
+ active: {
46
+ fill: ACTIVE_COLOR,
47
+ stroke: ACTIVE_COLOR,
48
+ },
49
+ error: {
50
+ fill: ERROR_COLOR,
51
+ stroke: ERROR_COLOR,
52
+ },
53
+ },
54
+ vertex: {
55
+ innerFill: '#fff',
56
+ outerFill: '#fff',
57
+ stroke: '#36738E',
58
+ strokeWidth: 0,
59
+ outerRadius: VERTEX_RADIUS,
60
+ innerRadius: VERTEX_RADIUS / 2,
61
+ highlight: {
62
+ innerFill: HIGHLIGHT_COLOR,
63
+ outerFill: HIGHLIGHT_COLOR,
64
+ stroke: HIGHLIGHT_COLOR,
65
+ },
66
+ active: {
67
+ innerFill: ACTIVE_COLOR,
68
+ outerFill: ACTIVE_COLOR,
69
+ stroke: ACTIVE_COLOR,
70
+ },
71
+ error: {
72
+ innerFill: ERROR_COLOR,
73
+ outerFill: ERROR_COLOR,
74
+ stroke: ERROR_COLOR,
75
+ },
76
+ },
77
+ feature: {
78
+ fill: '#888',
79
+ stroke: '#888',
80
+ strokeWidth: 0,
81
+ thickness: FEATURE_THICKNESS,
82
+ highlight: {
83
+ fill: HIGHLIGHT_COLOR,
84
+ stroke: HIGHLIGHT_COLOR,
85
+ },
86
+ active: {
87
+ fill: ACTIVE_COLOR,
88
+ stroke: ACTIVE_COLOR,
89
+ },
90
+ error: {
91
+ fill: ERROR_COLOR,
92
+ stroke: ERROR_COLOR,
93
+ },
94
+ },
95
+ };
96
+ exports.default = theme;
@@ -0,0 +1,3 @@
1
+ import type { ISpacesStyles } from '../types';
2
+ declare const theme: ISpacesStyles;
3
+ export default theme;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var HIGHLIGHT_COLOR = '#36738E';
4
+ var ACTIVE_COLOR = 'green';
5
+ var ERROR_COLOR = 'red';
6
+ var WALL_THICKNESS = 18;
7
+ var VERTEX_RADIUS = (WALL_THICKNESS - 6) / 2;
8
+ var FEATURE_THICKNESS = WALL_THICKNESS + 6;
9
+ var theme = {
10
+ grid: {
11
+ lineThickness: 2,
12
+ lineColor: '#ddd',
13
+ showSubdivisions: true,
14
+ subdivisionLineThickness: 1,
15
+ subdivisionLineColor: '#ddd',
16
+ subdivisionThreshold: 20,
17
+ backgroundColor: '#fff',
18
+ },
19
+ guides: {
20
+ color: '#00F8FB',
21
+ thickness: 1,
22
+ },
23
+ floor: {
24
+ color: '#eee',
25
+ textColor: '#666',
26
+ },
27
+ dimensions: {
28
+ padding: WALL_THICKNESS / 2 + 12,
29
+ lineThickness: 1,
30
+ lineColor: '#444',
31
+ fontSize: 14,
32
+ font: 'Helvetica',
33
+ textColor: '#444',
34
+ textBackgroundColor: 'white',
35
+ },
36
+ wall: {
37
+ fill: '#d9d9d9',
38
+ stroke: '#d9d9d9',
39
+ strokeWidth: 0,
40
+ thickness: WALL_THICKNESS,
41
+ highlight: {
42
+ fill: HIGHLIGHT_COLOR,
43
+ stroke: HIGHLIGHT_COLOR,
44
+ },
45
+ active: {
46
+ fill: ACTIVE_COLOR,
47
+ stroke: ACTIVE_COLOR,
48
+ },
49
+ error: {
50
+ fill: ERROR_COLOR,
51
+ stroke: ERROR_COLOR,
52
+ },
53
+ },
54
+ vertex: {
55
+ innerFill: '#36738E',
56
+ outerFill: 'white',
57
+ stroke: '#36738E',
58
+ strokeWidth: 2,
59
+ outerRadius: VERTEX_RADIUS,
60
+ innerRadius: VERTEX_RADIUS / 2,
61
+ highlight: {
62
+ innerFill: HIGHLIGHT_COLOR,
63
+ outerFill: HIGHLIGHT_COLOR,
64
+ stroke: HIGHLIGHT_COLOR,
65
+ },
66
+ active: {
67
+ innerFill: ACTIVE_COLOR,
68
+ outerFill: ACTIVE_COLOR,
69
+ stroke: ACTIVE_COLOR,
70
+ },
71
+ error: {
72
+ innerFill: ERROR_COLOR,
73
+ outerFill: ERROR_COLOR,
74
+ stroke: ERROR_COLOR,
75
+ },
76
+ },
77
+ feature: {
78
+ fill: '#888',
79
+ stroke: '#888',
80
+ strokeWidth: 0,
81
+ thickness: FEATURE_THICKNESS,
82
+ highlight: {
83
+ fill: HIGHLIGHT_COLOR,
84
+ stroke: HIGHLIGHT_COLOR,
85
+ },
86
+ active: {
87
+ fill: ACTIVE_COLOR,
88
+ stroke: ACTIVE_COLOR,
89
+ },
90
+ error: {
91
+ fill: ERROR_COLOR,
92
+ stroke: ERROR_COLOR,
93
+ },
94
+ },
95
+ };
96
+ exports.default = theme;
@@ -0,0 +1,11 @@
1
+ export declare enum IThemes {
2
+ DEFAULT = "default",
3
+ BLUEPRINT = "blueprint",
4
+ LIGHT = "light"
5
+ }
6
+ declare const _default: {
7
+ default: import("../types").ISpacesStyles;
8
+ blueprint: import("../types").ISpacesStyles;
9
+ light: import("../types").ISpacesStyles;
10
+ };
11
+ export default _default;