@threekit-tools/treble 0.0.89 → 0.0.90-next-01

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 (159) hide show
  1. package/dist/Treble/Treble.d.ts +1 -1
  2. package/dist/Treble/Treble.js +3 -3
  3. package/dist/components/AttributeValue/index.js +2 -0
  4. package/dist/components/BreatheAnimation/index.js +2 -2
  5. package/dist/components/TurntableAnimation/index.js +2 -2
  6. package/dist/components/Wishlist/index.d.ts +1 -1
  7. package/dist/components/Zoom/index.d.ts +1 -1
  8. package/dist/components/containers/formInputContainer.d.ts +1 -1
  9. package/dist/components/containers/formInputContainer.js +3 -3
  10. package/dist/hooks/useConfigurationChangeStatus/index.d.ts +2 -0
  11. package/dist/hooks/{usePlayerLoadingStatus → useConfigurationChangeStatus}/index.js +2 -2
  12. package/dist/hooks/useNestedConfigurator/index.js +1 -2
  13. package/dist/hooks/usePlayerReady/index.d.ts +2 -0
  14. package/dist/hooks/{useAnimationStart → usePlayerReady}/index.js +2 -2
  15. package/dist/hooks/useRoomBuilder/RoomBuilderLayout.d.ts +8 -0
  16. package/dist/hooks/useRoomBuilder/RoomBuilderLayout.js +22 -0
  17. package/dist/hooks/useRoomBuilder/RoomBuilderState.d.ts +132 -0
  18. package/dist/hooks/useRoomBuilder/RoomBuilderState.js +1431 -0
  19. package/dist/hooks/useRoomBuilder/constants.d.ts +56 -0
  20. package/dist/hooks/useRoomBuilder/constants.js +63 -0
  21. package/dist/hooks/useRoomBuilder/dataHandlers.d.ts +18 -0
  22. package/dist/hooks/useRoomBuilder/dataHandlers.js +187 -0
  23. package/dist/hooks/useRoomBuilder/draw.d.ts +55 -0
  24. package/dist/hooks/useRoomBuilder/draw.js +573 -0
  25. package/dist/hooks/useRoomBuilder/findLoops.d.ts +5 -0
  26. package/dist/hooks/useRoomBuilder/findLoops.js +99 -0
  27. package/dist/hooks/useRoomBuilder/geometry.d.ts +33 -0
  28. package/dist/hooks/useRoomBuilder/geometry.js +325 -0
  29. package/dist/hooks/useRoomBuilder/index.d.ts +57 -0
  30. package/dist/hooks/useRoomBuilder/index.js +411 -0
  31. package/dist/hooks/useRoomBuilder/messaging.d.ts +8 -0
  32. package/dist/hooks/useRoomBuilder/messaging.js +18 -0
  33. package/dist/hooks/useRoomBuilder/themes.d.ts +12 -0
  34. package/dist/hooks/useRoomBuilder/themes.js +273 -0
  35. package/dist/hooks/useRoomBuilder/types.d.ts +247 -0
  36. package/dist/hooks/useRoomBuilder/types.js +40 -0
  37. package/dist/hooks/useRoomBuilder/validators.d.ts +36 -0
  38. package/dist/hooks/useRoomBuilder/validators.js +362 -0
  39. package/dist/icons/Add.d.ts +1 -1
  40. package/dist/icons/Add.js +3 -3
  41. package/dist/icons/Angle.d.ts +3 -0
  42. package/dist/icons/Angle.js +21 -0
  43. package/dist/icons/ArrowLeft.d.ts +1 -1
  44. package/dist/icons/ArrowLeft.js +3 -3
  45. package/dist/icons/ArrowRight.d.ts +1 -1
  46. package/dist/icons/ArrowRight.js +3 -3
  47. package/dist/icons/Camera.d.ts +1 -1
  48. package/dist/icons/Camera.js +3 -3
  49. package/dist/icons/CaretDown.d.ts +1 -1
  50. package/dist/icons/CaretDown.js +3 -3
  51. package/dist/icons/CaretLeft.d.ts +1 -1
  52. package/dist/icons/CaretLeft.js +3 -3
  53. package/dist/icons/CaretRight.d.ts +1 -1
  54. package/dist/icons/CaretRight.js +3 -3
  55. package/dist/icons/CaretUp.d.ts +1 -1
  56. package/dist/icons/CaretUp.js +3 -3
  57. package/dist/icons/Cart.d.ts +1 -1
  58. package/dist/icons/Cart.js +3 -3
  59. package/dist/icons/Checkmate.d.ts +1 -1
  60. package/dist/icons/Checkmate.js +3 -3
  61. package/dist/icons/Clipboard.d.ts +1 -1
  62. package/dist/icons/Clipboard.js +3 -3
  63. package/dist/icons/ColorPicker.d.ts +1 -1
  64. package/dist/icons/ColorPicker.js +3 -3
  65. package/dist/icons/Copy.d.ts +1 -1
  66. package/dist/icons/Copy.js +3 -3
  67. package/dist/icons/Cursor.d.ts +3 -0
  68. package/dist/icons/Cursor.js +21 -0
  69. package/dist/icons/Delete.d.ts +1 -1
  70. package/dist/icons/Delete.js +3 -3
  71. package/dist/icons/Door.d.ts +3 -0
  72. package/dist/icons/Door.js +22 -0
  73. package/dist/icons/DoubleCaretLeft.d.ts +1 -1
  74. package/dist/icons/DoubleCaretLeft.js +3 -3
  75. package/dist/icons/DoubleCaretRight.d.ts +1 -1
  76. package/dist/icons/DoubleCaretRight.js +3 -3
  77. package/dist/icons/Download.d.ts +1 -1
  78. package/dist/icons/Download.js +3 -3
  79. package/dist/icons/Drag.d.ts +1 -1
  80. package/dist/icons/Drag.js +3 -3
  81. package/dist/icons/Draggable.d.ts +1 -1
  82. package/dist/icons/Draggable.js +3 -3
  83. package/dist/icons/Draw.d.ts +3 -0
  84. package/dist/icons/Draw.js +21 -0
  85. package/dist/icons/Edit.d.ts +1 -1
  86. package/dist/icons/Edit.js +3 -3
  87. package/dist/icons/Heart.d.ts +1 -1
  88. package/dist/icons/Heart.js +3 -3
  89. package/dist/icons/Image.d.ts +1 -1
  90. package/dist/icons/Image.js +3 -3
  91. package/dist/icons/Info.d.ts +1 -1
  92. package/dist/icons/Info.js +3 -3
  93. package/dist/icons/Layout.d.ts +3 -0
  94. package/dist/icons/Layout.js +21 -0
  95. package/dist/icons/Mail.d.ts +1 -1
  96. package/dist/icons/Mail.js +3 -3
  97. package/dist/icons/Menu.d.ts +1 -1
  98. package/dist/icons/Menu.js +3 -3
  99. package/dist/icons/More.d.ts +1 -1
  100. package/dist/icons/More.js +3 -3
  101. package/dist/icons/NewWindow.d.ts +1 -1
  102. package/dist/icons/NewWindow.js +3 -3
  103. package/dist/icons/Opening.d.ts +3 -0
  104. package/dist/icons/Opening.js +21 -0
  105. package/dist/icons/Pause.d.ts +1 -1
  106. package/dist/icons/Pause.js +3 -3
  107. package/dist/icons/Play.d.ts +1 -1
  108. package/dist/icons/Play.js +3 -3
  109. package/dist/icons/Player3D.d.ts +3 -0
  110. package/dist/icons/Player3D.js +21 -0
  111. package/dist/icons/Redo.d.ts +1 -1
  112. package/dist/icons/Redo.js +3 -3
  113. package/dist/icons/Remove.d.ts +1 -1
  114. package/dist/icons/Remove.js +3 -3
  115. package/dist/icons/Ruler.d.ts +1 -1
  116. package/dist/icons/Ruler.js +3 -3
  117. package/dist/icons/Search.d.ts +1 -1
  118. package/dist/icons/Search.js +3 -3
  119. package/dist/icons/Settings.d.ts +1 -1
  120. package/dist/icons/Settings.js +3 -3
  121. package/dist/icons/Share.d.ts +1 -1
  122. package/dist/icons/Share.js +3 -3
  123. package/dist/icons/Switch.d.ts +1 -1
  124. package/dist/icons/Switch.js +3 -3
  125. package/dist/icons/Tag.d.ts +1 -1
  126. package/dist/icons/Tag.js +3 -3
  127. package/dist/icons/TrashCan.d.ts +3 -0
  128. package/dist/icons/TrashCan.js +21 -0
  129. package/dist/icons/TrashCanAlt.d.ts +3 -0
  130. package/dist/icons/TrashCanAlt.js +21 -0
  131. package/dist/icons/Undo.d.ts +1 -1
  132. package/dist/icons/Undo.js +3 -3
  133. package/dist/icons/Wall.d.ts +3 -0
  134. package/dist/icons/Wall.js +21 -0
  135. package/dist/icons/Window.d.ts +3 -0
  136. package/dist/icons/Window.js +22 -0
  137. package/dist/icons/Wishlist.d.ts +1 -1
  138. package/dist/icons/Wishlist.js +3 -3
  139. package/dist/icons/ZoomIn.d.ts +1 -1
  140. package/dist/icons/ZoomIn.js +3 -3
  141. package/dist/icons/ZoomOut.d.ts +1 -1
  142. package/dist/icons/ZoomOut.js +3 -3
  143. package/dist/icons/index.d.ts +2 -6
  144. package/dist/icons/index.js +22 -0
  145. package/dist/icons/types.d.ts +7 -0
  146. package/dist/icons/types.js +2 -0
  147. package/dist/index.d.ts +17 -2
  148. package/dist/index.js +35 -4
  149. package/dist/store/attributes.d.ts +1 -0
  150. package/dist/store/index.d.ts +39 -8
  151. package/dist/store/index.js +3 -1
  152. package/dist/store/roomBuilder.d.ts +38 -0
  153. package/dist/store/roomBuilder.js +174 -0
  154. package/dist/store/treble.js +12 -6
  155. package/dist/types.d.ts +46 -7
  156. package/dist/types.js +1 -0
  157. package/package.json +1 -1
  158. package/dist/hooks/useAnimationStart/index.d.ts +0 -2
  159. package/dist/hooks/usePlayerLoadingStatus/index.d.ts +0 -2
@@ -0,0 +1,411 @@
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 useConfigurator_1 = __importDefault(require("../useConfigurator"));
43
+ var RoomBuilderState_1 = __importDefault(require("./RoomBuilderState"));
44
+ var constants_1 = require("./constants");
45
+ var themes_1 = __importStar(require("./themes"));
46
+ var RoomBuilderLayout_1 = __importDefault(require("./RoomBuilderLayout"));
47
+ var store_1 = require("../../store");
48
+ var roomBuilder_1 = require("../../store/roomBuilder");
49
+ var useThreekitInitStatus_1 = __importDefault(require("../useThreekitInitStatus"));
50
+ var useRoomBuilder = function (props) {
51
+ var _a;
52
+ var _b;
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)(roomBuilder_1.getLayouts);
57
+ var zoom = (0, store_1.useThreekitSelector)(roomBuilder_1.getZoom);
58
+ var translation = (0, store_1.useThreekitSelector)(roomBuilder_1.getTranslation);
59
+ var modeValue = (0, store_1.useThreekitSelector)(roomBuilder_1.getMode);
60
+ var showDimensions = (0, store_1.useThreekitSelector)(roomBuilder_1.getShowDimensions);
61
+ var angleSnappingEnabled = (0, store_1.useThreekitSelector)(roomBuilder_1.getAngleSnappingEnabled);
62
+ var _c = (0, react_1.useState)(null), selectedElement = _c[0], setSelectedElement = _c[1];
63
+ var _d = (0, react_1.useState)(null), selectedWallAsset = _d[0], setSelectedWallAsset = _d[1];
64
+ var canvasRef = (0, react_1.useRef)(null);
65
+ var selectElementPending = (0, react_1.useRef)(null);
66
+ var translationAnchorRef = (0, react_1.useRef)(null);
67
+ var preppedConfig = Object.assign({
68
+ scale: constants_1.SCALE,
69
+ unit: types_1.IUnits.FEET,
70
+ snapProximity: constants_1.SNAP_PROXIMITY,
71
+ zoomDefault: zoom || constants_1.ZOOM_DEFAULT,
72
+ translateDefault: translation || constants_1.TRANSLATE_DEFAULT,
73
+ styles: ((_b = props.config) === null || _b === void 0 ? void 0 : _b.theme) && themes_1.default[props.config.theme]
74
+ ? themes_1.default[props.config.theme]
75
+ : themes_1.default[themes_1.IThemes.DEFAULT],
76
+ }, props.config);
77
+ var attributeNames = Object.assign((_a = {},
78
+ _a[types_1.IElements.WALL] = constants_1.IRoomBuilderAttributes.WALLS,
79
+ _a[types_1.IElements.WINDOW] = constants_1.IRoomBuilderAttributes.WINDOWS,
80
+ _a[types_1.IElements.OPENING] = constants_1.IRoomBuilderAttributes.OPENINGS,
81
+ _a[types_1.IElements.DOOR] = constants_1.IRoomBuilderAttributes.DOORS,
82
+ _a), props.attributes);
83
+ var roomBuilderRef = (0, react_1.useRef)(new RoomBuilderState_1.default(__assign(__assign({}, props), { config: preppedConfig, attributes: attributeNames })));
84
+ var drawRoom = function () { return roomBuilderRef.current.drawRoom(canvasRef.current); };
85
+ (0, react_1.useEffect)(function () {
86
+ var _a;
87
+ if (!selectedWallAsset && (attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_1.IElements.WALL]]))
88
+ setSelectedWallAsset(((_a = attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_1.IElements.WALL]]) === null || _a === void 0 ? void 0 : _a.values[0].assetId) || null);
89
+ var attributesDelinked = JSON.parse(JSON.stringify(attributesState));
90
+ roomBuilderRef.current.setAttributesToState(attributesDelinked);
91
+ drawRoom();
92
+ }, [attributesState]);
93
+ (0, react_1.useEffect)(function () {
94
+ var _a;
95
+ if (zoom &&
96
+ ((_a = props.config) === null || _a === void 0 ? void 0 : _a.zoomDefault) &&
97
+ props.config.zoomDefault >= roomBuilderRef.current.zoomMin &&
98
+ roomBuilderRef.current.zoomMax >= props.config.zoomDefault)
99
+ updateZoom(props.config.zoomDefault);
100
+ }, []);
101
+ (0, react_1.useEffect)(function () {
102
+ var _a, _b;
103
+ if (canvasRef === null || canvasRef === void 0 ? void 0 : canvasRef.current) {
104
+ roomBuilderRef.current.canvasDimensions = [
105
+ canvasRef.current.width,
106
+ canvasRef.current.height,
107
+ ];
108
+ canvasRef.current.addEventListener('mousedown', handleDrawWallStart);
109
+ canvasRef.current.addEventListener('mousemove', handleDrawWallMouseMove);
110
+ document.addEventListener('mouseup', handleDrawWallFinish);
111
+ canvasRef.current.addEventListener('mousemove', handleSelectModeHover);
112
+ canvasRef.current.addEventListener('mousedown', handleSelectElement);
113
+ canvasRef.current.addEventListener('mousemove', handleMoveSelectedElement);
114
+ if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled))
115
+ canvasRef.current.addEventListener('mousemove', handleMoveCanvas);
116
+ document.addEventListener('mouseup', handleSetSelectedElement);
117
+ if (!((_b = props.config) === null || _b === void 0 ? void 0 : _b.zoomDisabled))
118
+ canvasRef.current.addEventListener('wheel', handleScrollToZoom);
119
+ }
120
+ return function () {
121
+ var _a, _b;
122
+ if (canvasRef === null || canvasRef === void 0 ? void 0 : canvasRef.current) {
123
+ canvasRef.current.removeEventListener('mousedown', handleDrawWallStart);
124
+ canvasRef.current.removeEventListener('mousemove', handleDrawWallMouseMove);
125
+ document.removeEventListener('mouseup', handleDrawWallFinish);
126
+ canvasRef.current.removeEventListener('mousemove', handleSelectModeHover);
127
+ canvasRef.current.removeEventListener('mousedown', handleSelectElement);
128
+ canvasRef.current.removeEventListener('mousemove', handleMoveSelectedElement);
129
+ if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled))
130
+ canvasRef.current.removeEventListener('mousemove', handleMoveCanvas);
131
+ document.removeEventListener('mouseup', handleSetSelectedElement);
132
+ if (!((_b = props.config) === null || _b === void 0 ? void 0 : _b.zoomDisabled))
133
+ canvasRef.current.removeEventListener('wheel', handleScrollToZoom);
134
+ }
135
+ };
136
+ });
137
+ (0, react_1.useEffect)(function () {
138
+ roomBuilderRef.current.showDimensions = showDimensions;
139
+ roomBuilderRef.current.angleSnappingEnabled = angleSnappingEnabled;
140
+ roomBuilderRef.current.selectedElement = selectedElement
141
+ ? {
142
+ type: selectedElement.path[0],
143
+ index: selectedElement.path[1],
144
+ }
145
+ : null;
146
+ drawRoom();
147
+ }, [selectedElement, showDimensions, angleSnappingEnabled]);
148
+ (0, react_1.useEffect)(function () {
149
+ if (!hasLoaded)
150
+ return;
151
+ var layoutIds = props.layouts || [];
152
+ dispatch((0, roomBuilder_1.hydrateLayouts)(layoutIds, {
153
+ walls: attributeNames[types_1.IElements.WALL],
154
+ startX: constants_1.IWallAttributes.START_X,
155
+ startZ: constants_1.IWallAttributes.START_Z,
156
+ endX: constants_1.IWallAttributes.END_X,
157
+ endZ: constants_1.IWallAttributes.END_Z,
158
+ }));
159
+ }, [hasLoaded, JSON.stringify(props.layouts)]);
160
+ var updateZoom = function (value) {
161
+ var newZoom = roomBuilderRef.current.setZoom(value);
162
+ if (!newZoom)
163
+ return;
164
+ dispatch((0, roomBuilder_1.setZoom)(newZoom));
165
+ drawRoom();
166
+ };
167
+ var handleScrollToZoom = function (e) {
168
+ if (!canvasRef.current)
169
+ return;
170
+ updateZoom(e.deltaY);
171
+ };
172
+ var handleSelectModeHover = function (e) {
173
+ if (!canvasRef.current)
174
+ return;
175
+ if (modeValue !== types_1.IModes.SELECT)
176
+ return;
177
+ if (roomBuilderRef.current.activeElement !== null)
178
+ return;
179
+ if (translationAnchorRef.current)
180
+ return;
181
+ var cursorPoint = [e.offsetX, e.offsetY];
182
+ roomBuilderRef.current.highlightElementIfInProximity(canvasRef.current, cursorPoint);
183
+ };
184
+ var handleSelectElement = function (e) {
185
+ var _a;
186
+ if (!canvasRef.current)
187
+ return;
188
+ if (modeValue !== types_1.IModes.SELECT)
189
+ return;
190
+ var cursorPoint = [e.offsetX, e.offsetY];
191
+ roomBuilderRef.current.selectElementIfInProximity(canvasRef.current, cursorPoint);
192
+ if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled) &&
193
+ !roomBuilderRef.current.activeElement)
194
+ translationAnchorRef.current = cursorPoint;
195
+ var element = roomBuilderRef.current.getClickedElement(cursorPoint);
196
+ if (!element) {
197
+ if (selectedElement !== null)
198
+ setSelectedElement(null);
199
+ return;
200
+ }
201
+ if (roomBuilderRef.current.activeElement ||
202
+ (selectedElement &&
203
+ JSON.stringify(element.path) !== JSON.stringify(selectedElement.path)))
204
+ setSelectedElement(null);
205
+ selectElementPending.current = element;
206
+ };
207
+ var handleMoveSelectedElement = function (e) {
208
+ if (modeValue !== types_1.IModes.SELECT)
209
+ return;
210
+ if (!canvasRef.current)
211
+ return;
212
+ var point = [e.offsetX, e.offsetY];
213
+ roomBuilderRef.current.moveActiveElement(canvasRef.current, point);
214
+ selectElementPending.current = null;
215
+ };
216
+ var handleMoveCanvas = function (e) {
217
+ if (modeValue !== types_1.IModes.SELECT)
218
+ return;
219
+ if (!canvasRef.current)
220
+ return;
221
+ if (roomBuilderRef.current.selectedElement || !translationAnchorRef.current)
222
+ return;
223
+ var delta = [
224
+ e.offsetX - translationAnchorRef.current[0],
225
+ e.offsetY - translationAnchorRef.current[1],
226
+ ];
227
+ handleChangeTranslate(delta);
228
+ translationAnchorRef.current = [e.offsetX, e.offsetY];
229
+ };
230
+ var handleSetSelectedElement = function (e) {
231
+ var _a;
232
+ if (modeValue !== types_1.IModes.SELECT)
233
+ return;
234
+ if (!canvasRef.current)
235
+ return;
236
+ if (!((_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
237
+ roomBuilderRef.current.cancelMoveActiveElement(canvasRef.current);
238
+ return;
239
+ }
240
+ roomBuilderRef.current.finishMoveActiveElement(canvasRef.current);
241
+ if (selectElementPending.current) {
242
+ setSelectedElement(selectElementPending.current);
243
+ selectElementPending.current = null;
244
+ return;
245
+ }
246
+ if (translationAnchorRef.current)
247
+ translationAnchorRef.current = null;
248
+ };
249
+ var handleDrawWallStart = function (e) {
250
+ if (modeValue !== types_1.IModes.DRAW)
251
+ return;
252
+ var cursorPoint = [e.offsetX, e.offsetY];
253
+ roomBuilderRef.current.startDrawNewWall(cursorPoint);
254
+ };
255
+ var handleDrawWallMouseMove = function (e) {
256
+ if (modeValue !== types_1.IModes.DRAW)
257
+ return;
258
+ if (!canvasRef.current)
259
+ return;
260
+ var cursorPoint = [e.offsetX, e.offsetY];
261
+ if (roomBuilderRef.current.isDrawWallActive)
262
+ roomBuilderRef.current.drawNewWall(canvasRef.current, cursorPoint);
263
+ };
264
+ var handleDrawWallFinish = function (e) {
265
+ var _a;
266
+ if (modeValue !== types_1.IModes.DRAW)
267
+ return;
268
+ if (!canvasRef.current)
269
+ return;
270
+ if (!selectedWallAsset)
271
+ return;
272
+ if (!((_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
273
+ roomBuilderRef.current.cancelDrawNewWall(canvasRef.current);
274
+ return;
275
+ }
276
+ roomBuilderRef.current.finishDrawNewWall(canvasRef.current, selectedWallAsset);
277
+ };
278
+ var prepFeatureAttributeForOutput = function (type, attribute) {
279
+ if (!attribute)
280
+ return undefined;
281
+ var values = attribute.values.map(function (val) { return (__assign(__assign({}, val), { add: function (addToWallIndex, offset) {
282
+ return roomBuilderRef.current.addFeature(type, {
283
+ assetId: val.assetId,
284
+ length: constants_1.FEATURE_LENGTH,
285
+ offset: offset,
286
+ }, addToWallIndex);
287
+ } })); });
288
+ var value = attribute.value.map(function (val, i) { return (__assign(__assign({}, val), { delete: function () { return roomBuilderRef.current.deleteFeature(type, i); } })); });
289
+ return __assign(__assign({}, attribute), { values: values, value: value });
290
+ };
291
+ var prepWallAttributeForOutput = function (attribute) {
292
+ if (!attribute)
293
+ return undefined;
294
+ var values = attribute.values.map(function (val) { return (__assign(__assign({}, val), { selected: val.assetId === selectedWallAsset, selectToDraw: function () {
295
+ dispatch((0, roomBuilder_1.setMode)(types_1.IModes.DRAW));
296
+ setSelectedWallAsset(val.assetId);
297
+ } })); });
298
+ var value = attribute.value.map(function (val, i) { return (__assign(__assign({}, val), { delete: function () { var _a; return (_a = roomBuilderRef.current) === null || _a === void 0 ? void 0 : _a.deleteWall(i); } })); });
299
+ return __assign(__assign({}, attribute), { values: values, value: value });
300
+ };
301
+ var getElementFromAttributeName = function (attributeName) {
302
+ var elementAttr = Object.entries(attributeNames).find(function (_a) {
303
+ var _ = _a[0], attrName = _a[1];
304
+ return attrName === attributeName;
305
+ });
306
+ if (!elementAttr)
307
+ return;
308
+ return elementAttr[0];
309
+ };
310
+ var handleSetMode = function (mode) {
311
+ if (mode === modeValue)
312
+ return;
313
+ drawRoom();
314
+ dispatch((0, roomBuilder_1.setMode)(mode));
315
+ setSelectedElement(null);
316
+ };
317
+ var handleReset = function () {
318
+ var _a;
319
+ (_a = roomBuilderRef.current) === null || _a === void 0 ? void 0 : _a.deleteAll();
320
+ setSelectedElement(null);
321
+ };
322
+ var handleDeleteElement = function (type, index) {
323
+ var _a;
324
+ var elementType = type;
325
+ if (Object.values(attributeNames).includes(type)) {
326
+ var updatedType = getElementFromAttributeName(type);
327
+ if (!updatedType)
328
+ return;
329
+ elementType = updatedType;
330
+ }
331
+ (_a = roomBuilderRef.current) === null || _a === void 0 ? void 0 : _a.deleteElement(elementType, index);
332
+ setSelectedElement(null);
333
+ };
334
+ var handleToggleDimensions = function (val) {
335
+ if (val === undefined)
336
+ dispatch((0, roomBuilder_1.setShowDimensions)(!showDimensions));
337
+ else
338
+ dispatch((0, roomBuilder_1.setShowDimensions)(val));
339
+ setSelectedElement(null);
340
+ };
341
+ var handleToggleAngleSnapping = function (val) {
342
+ if (val === undefined)
343
+ dispatch((0, roomBuilder_1.setAngleSnappingEnabled)(!angleSnappingEnabled));
344
+ else
345
+ dispatch((0, roomBuilder_1.setAngleSnappingEnabled)(val));
346
+ setSelectedElement(null);
347
+ };
348
+ var handleChangeTranslate = function (delta) {
349
+ roomBuilderRef.current.translate = [
350
+ roomBuilderRef.current.translate[0] + delta[0],
351
+ roomBuilderRef.current.translate[1] + delta[1],
352
+ ];
353
+ dispatch((0, roomBuilder_1.setTranslation)(roomBuilderRef.current.translate));
354
+ drawRoom();
355
+ };
356
+ return {
357
+ drawRoom: drawRoom,
358
+ canvasRef: canvasRef,
359
+ selectedElement: selectedElement === null
360
+ ? selectedElement
361
+ : __assign(__assign({}, selectedElement), { path: [
362
+ attributeNames[selectedElement.path[0]],
363
+ selectedElement.path[1],
364
+ ], type: selectedElement.path[0] }),
365
+ mode: {
366
+ value: modeValue,
367
+ options: [types_1.IModes.SELECT, types_1.IModes.DRAW].map(function (el) { return ({
368
+ value: el,
369
+ label: el,
370
+ selected: modeValue === el,
371
+ handleSelect: function () { return handleSetMode(el); },
372
+ }); }),
373
+ handleChange: handleSetMode,
374
+ },
375
+ dimensions: {
376
+ enabled: showDimensions,
377
+ handleToggle: handleToggleDimensions,
378
+ },
379
+ angleSnapping: {
380
+ enabled: angleSnappingEnabled,
381
+ handleToggle: handleToggleAngleSnapping,
382
+ },
383
+ zoom: {
384
+ min: roomBuilderRef.current.zoomMin,
385
+ max: roomBuilderRef.current.zoomMax,
386
+ value: zoom || constants_1.ZOOM_DEFAULT,
387
+ handleChange: updateZoom,
388
+ },
389
+ translate: {
390
+ handleChange: handleChangeTranslate,
391
+ },
392
+ reset: handleReset,
393
+ deleteElement: handleDeleteElement,
394
+ layouts: layouts.map(function (layout) { return ({
395
+ label: layout.label,
396
+ loops: layout.loop,
397
+ handleSelect: function () {
398
+ return window.threekit.configurator.setFullConfiguration(layout.configuration);
399
+ },
400
+ }); }),
401
+ walls: prepWallAttributeForOutput(attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_1.IElements.WALL]]),
402
+ windows: prepFeatureAttributeForOutput(types_1.IElements.WINDOW, attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_1.IElements.WINDOW]]),
403
+ doors: prepFeatureAttributeForOutput(types_1.IElements.DOOR, attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_1.IElements.DOOR]]),
404
+ openings: prepFeatureAttributeForOutput(types_1.IElements.OPENING, attributesState === null || attributesState === void 0 ? void 0 : attributesState[attributeNames[types_1.IElements.OPENING]]),
405
+ };
406
+ };
407
+ useRoomBuilder.themes = themes_1.IThemes;
408
+ useRoomBuilder.units = types_1.IUnits;
409
+ useRoomBuilder.modes = types_1.IModes;
410
+ useRoomBuilder.LayoutIcon = RoomBuilderLayout_1.default;
411
+ exports.default = useRoomBuilder;
@@ -0,0 +1,8 @@
1
+ export declare const errorMessages: {
2
+ addWallCollidingWithWall: () => string;
3
+ addWallCollidingWithFeature: (feature: string) => string;
4
+ featuresColliding: (feature: string) => string;
5
+ featureOutsideWallBounds: () => string;
6
+ wallsNotUnique: () => string;
7
+ wallTooShort: () => string;
8
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorMessages = void 0;
4
+ var constants_1 = require("./constants");
5
+ exports.errorMessages = {
6
+ addWallCollidingWithWall: function () { return 'Wall cannot collide with another wall.'; },
7
+ addWallCollidingWithFeature: function (feature) {
8
+ return "Wall cannot collide with a ".concat(constants_1.FEATURE_LABELS[feature]);
9
+ },
10
+ featuresColliding: function (feature) {
11
+ return "There is already a ".concat(constants_1.FEATURE_LABELS[feature], " in that space.");
12
+ },
13
+ featureOutsideWallBounds: function () {
14
+ return 'Feature is too close to the end of the wall.';
15
+ },
16
+ wallsNotUnique: function () { return 'Cannot place a wall over an existing wall.'; },
17
+ wallTooShort: function () { return 'Wall is too short.'; },
18
+ };
@@ -0,0 +1,12 @@
1
+ import type { IRoomBuilderStyles } from './types';
2
+ export declare enum IThemes {
3
+ DEFAULT = "default",
4
+ BLUEPRINT = "blueprint",
5
+ LIGHT = "light"
6
+ }
7
+ declare const _default: {
8
+ default: IRoomBuilderStyles;
9
+ blueprint: IRoomBuilderStyles;
10
+ light: IRoomBuilderStyles;
11
+ };
12
+ export default _default;