kitchen-simulator 3.14.0 → 3.16.0-test-renderer-fix

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.
@@ -1,5 +1,4 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
4
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
@@ -7,79 +6,57 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
7
6
  import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
8
7
  import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
9
8
  import _inherits from "@babel/runtime/helpers/esm/inherits";
10
- var _excluded = ["width", "height", "configData", "options", "user", "auth", "featureFlags", "sentry", "analytics", "externalEvent", "onInternalEvent", "onError"];
11
- import _regeneratorRuntime from "@babel/runtime/regenerator";
9
+ var _excluded = ["width", "height", "configData", "externalEvent", "onInternalEvent", "onError"];
12
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
11
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
13
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
14
15
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
15
16
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
16
- import React, { useCallback, useEffect, useRef } from 'react';
17
+ // LiteRenderer.jsx
18
+ import React, { useCallback, useEffect, useMemo, useRef } from 'react';
17
19
  import PropTypes from 'prop-types';
18
20
  import { Provider } from 'react-redux';
19
21
  import { createStore } from 'redux';
22
+ import { Map } from 'immutable';
23
+ import * as Sentry from '@sentry/react';
24
+ import * as THREE from 'three';
20
25
  import * as Models from "./models";
21
26
  import { State } from "./models";
22
27
  import PlannerReducer from "./reducers/reducer";
23
28
  import AppContext from "./AppContext";
24
29
  import Catalog from "./catalog/catalog";
25
- import { SVGLoader } from 'three/addons/loaders/SVGLoader';
26
- import { TOE_KICK_MOLDING } from "./constants";
27
30
  import * as Areas from "./catalog/areas/area/planner-element";
28
31
  import * as Lines from "./catalog/lines/wall/planner-element";
29
32
  import * as Holes from "./catalog/holes/export";
30
33
  import { ConsoleDebugger, Keyboard } from "./plugins/export";
31
- import { Map } from 'immutable';
32
- import * as Sentry from '@sentry/react';
33
- import * as THREE from 'three';
34
34
  import LiteKitchenConfigurator from "./LiteKitchenConfigurator";
35
- if (typeof window !== 'undefined') window.THREE = THREE;
35
+ var isBrowser = typeof window !== 'undefined';
36
+ if (isBrowser) window.THREE = THREE;
36
37
 
37
- /* ============================== component ============================= */
38
- var MyCatalog = new Catalog();
39
- var AppState = Map({
40
- KitchenConfigurator: new State()
41
- });
42
- console.log('Version: 378.45-202509_DIY-364-mbox-crash');
43
- isProduction && Sentry.init({
44
- dsn: process.env.SENTRY_DSN,
45
- environment: process.env.SENTRY_ENVIRONMENT
46
- });
47
-
48
- //define reducer
49
- var reducer = function reducer(state, action) {
50
- state = state || AppState;
51
- state = state.update('KitchenConfigurator', function (plannerState) {
52
- return PlannerReducer(plannerState, action);
38
+ // ---- Sentry init: keep behavior but avoid re-init on multiple mounts ----
39
+ var __sentryInited = false;
40
+ function ensureSentryInit() {
41
+ // assumes isProduction is defined in your build env like before
42
+ if (!isBrowser) return;
43
+ if (!isProduction) return;
44
+ if (__sentryInited) return;
45
+ __sentryInited = true;
46
+ Sentry.init({
47
+ dsn: process.env.SENTRY_DSN,
48
+ environment: process.env.SENTRY_ENVIRONMENT
53
49
  });
54
- return state;
55
- };
56
- var store = createStore(reducer, null, !isProduction && window.devToolsExtension ? window.devToolsExtension({
57
- features: {
58
- pause: true,
59
- // start/pause recording of dispatched actions
60
- lock: true,
61
- // lock/unlock dispatching actions and side effects
62
- persist: true,
63
- // persist states on page reloading
64
- "export": true,
65
- // export history of actions in a file
66
- "import": 'custom',
67
- // import history of actions from a file
68
- jump: true,
69
- // jump back and forth (time travelling)
70
- skip: true,
71
- // skip (cancel) actions
72
- reorder: true,
73
- // drag and drop actions in the history list
74
- dispatch: true,
75
- // dispatch custom actions or action creators
76
- test: true // generate tests for the selected actions
77
- },
78
- maxAge: 999999
79
- }) : function (f) {
80
- return f;
81
- });
82
- var plugins = [Keyboard(), ConsoleDebugger()];
50
+ }
51
+
52
+ // ---------------- error helpers ----------------
53
+ function safeJson(v) {
54
+ try {
55
+ return JSON.parse(JSON.stringify(v));
56
+ } catch (_unused) {
57
+ return undefined;
58
+ }
59
+ }
83
60
  function serializeError(err) {
84
61
  try {
85
62
  if (!err) return {
@@ -96,19 +73,12 @@ function serializeError(err) {
96
73
  message: String(err),
97
74
  raw: safeJson(err)
98
75
  };
99
- } catch (_unused) {
76
+ } catch (_unused2) {
100
77
  return {
101
78
  message: 'Error serializing error'
102
79
  };
103
80
  }
104
81
  }
105
- function safeJson(v) {
106
- try {
107
- return JSON.parse(JSON.stringify(v));
108
- } catch (_unused2) {
109
- return undefined;
110
- }
111
- }
112
82
 
113
83
  /* ---------- Error Boundary that pushes into buffer ---------- */
114
84
  var ToolErrorBoundary = /*#__PURE__*/function (_React$Component) {
@@ -136,35 +106,144 @@ var ToolErrorBoundary = /*#__PURE__*/function (_React$Component) {
136
106
  }
137
107
  }]);
138
108
  }(React.Component);
109
+ ToolErrorBoundary.propTypes = {
110
+ pushError: PropTypes.func.isRequired,
111
+ children: PropTypes.any
112
+ };
113
+
114
+ // ----------------- catalog init -----------------
115
+ function initCatalogOnce(catalog) {
116
+ if (!catalog) return;
117
+ if (catalog.__ksInitialized) return;
118
+ for (var x in Areas) catalog.registerElement(Areas[x]);
119
+ for (var _x in Lines) catalog.registerElement(Lines[_x]);
120
+ for (var _x2 in Holes) catalog.registerElement(Holes[_x2]);
121
+ catalog.registerCategory('Windows', 'Windows', [Holes.windowClear, Holes.windowCross, Holes.windowDoubleHung, Holes.windowVertical]);
122
+ catalog.registerCategory('Doors', 'Doors', [Holes.doorInterior, Holes.doorExterior, Holes.doorCloset, Holes.doorSliding, Holes.doorwayFramed, Holes.doorwayFrameless]);
123
+ catalog.__ksInitialized = true;
124
+ }
125
+
126
+ // ----------------- store factory -----------------
127
+ function createInstanceStore() {
128
+ // keep your initial state semantics identical
129
+ var AppState = Map({
130
+ KitchenConfigurator: new State()
131
+ });
132
+ var reducer = function reducer(state, action) {
133
+ state = state || AppState;
134
+ return state.update('KitchenConfigurator', function (plannerState) {
135
+ return PlannerReducer(plannerState, action);
136
+ });
137
+ };
138
+
139
+ // keep devtools behavior identical; guard against missing window
140
+ var enhancer = !isProduction && isBrowser && window.devToolsExtension ? window.devToolsExtension({
141
+ features: {
142
+ pause: true,
143
+ lock: true,
144
+ persist: true,
145
+ "export": true,
146
+ "import": 'custom',
147
+ jump: true,
148
+ skip: true,
149
+ reorder: true,
150
+ dispatch: true,
151
+ test: true
152
+ },
153
+ maxAge: 999999
154
+ }) : function (f) {
155
+ return f;
156
+ };
157
+ return createStore(reducer, null, enhancer);
158
+ }
159
+
160
+ // ----------------- plugins -----------------
161
+ function createPlugins() {
162
+ return [Keyboard(), ConsoleDebugger()];
163
+ }
139
164
  export default function LiteRenderer(props) {
165
+ ensureSentryInit();
140
166
  var width = props.width,
141
167
  height = props.height,
142
168
  configData = props.configData,
143
- options = props.options,
144
- user = props.user,
145
- auth = props.auth,
146
- featureFlags = props.featureFlags,
147
- sentry = props.sentry,
148
- analytics = props.analytics,
149
169
  externalEvent = props.externalEvent,
150
170
  onInternalEvent = props.onInternalEvent,
151
171
  onError = props.onError,
152
172
  passThrough = _objectWithoutProperties(props, _excluded);
153
173
 
174
+ // ---- instance-scoped store + catalog (no module-level globals) ----
175
+ var storeRef = useRef(null);
176
+ if (!storeRef.current) storeRef.current = createInstanceStore();
177
+ var catalogRef = useRef(null);
178
+ if (!catalogRef.current) {
179
+ catalogRef.current = new Catalog();
180
+ initCatalogOnce(catalogRef.current);
181
+ }
182
+
183
+ // ---- plugins init once per instance + cleanup support ----
184
+ var pluginCleanupsRef = useRef([]);
185
+ var plugins = useMemo(function () {
186
+ return createPlugins();
187
+ }, []); // stable
188
+
189
+ useEffect(function () {
190
+ var store = storeRef.current;
191
+ var stateExtractor = function stateExtractor(state) {
192
+ return state.get('KitchenConfigurator');
193
+ };
194
+
195
+ // plugins may or may not return cleanup; support both
196
+ var cleanups = [];
197
+ var _iterator = _createForOfIteratorHelper(plugins),
198
+ _step;
199
+ try {
200
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
201
+ var p = _step.value;
202
+ try {
203
+ var maybeCleanup = p === null || p === void 0 ? void 0 : p(store, stateExtractor);
204
+ if (typeof maybeCleanup === 'function') cleanups.push(maybeCleanup);
205
+ } catch (e) {
206
+ // keep behavior: don't crash; send to onError buffer
207
+ // (actual emitting is handled below)
208
+ }
209
+ }
210
+ } catch (err) {
211
+ _iterator.e(err);
212
+ } finally {
213
+ _iterator.f();
214
+ }
215
+ pluginCleanupsRef.current = cleanups;
216
+ return function () {
217
+ var _iterator2 = _createForOfIteratorHelper(pluginCleanupsRef.current),
218
+ _step2;
219
+ try {
220
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
221
+ var fn = _step2.value;
222
+ try {
223
+ fn();
224
+ } catch (_unused3) {}
225
+ }
226
+ } catch (err) {
227
+ _iterator2.e(err);
228
+ } finally {
229
+ _iterator2.f();
230
+ }
231
+ pluginCleanupsRef.current = [];
232
+ };
233
+ }, [plugins]);
234
+
154
235
  /* ---------- track last external event ---------- */
155
236
  var lastExternalEventRef = useRef(null);
156
237
  useEffect(function () {
157
- if (externalEvent) {
158
- lastExternalEventRef.current = externalEvent;
159
- }
238
+ if (externalEvent) lastExternalEventRef.current = externalEvent;
160
239
  }, [externalEvent]);
161
240
 
162
241
  /* ---------- error buffer + last emitted bundle ---------- */
163
- var errorsBufferRef = useRef([]); // pending errors (not yet emitted)
242
+ var errorsBufferRef = useRef([]);
164
243
  var lastEmittedRef = useRef({
165
244
  externalEvent: null,
166
245
  errors: []
167
- }); // last bundle we sent
246
+ });
168
247
  var flushTimerRef = useRef(null);
169
248
  var emit = useCallback(function (external, errors) {
170
249
  var payload = {
@@ -173,13 +252,12 @@ export default function LiteRenderer(props) {
173
252
  };
174
253
  try {
175
254
  onError === null || onError === void 0 || onError(payload);
176
- } catch (_unused3) {}
255
+ } catch (_unused4) {}
256
+ // keep your debug
177
257
  // eslint-disable-next-line no-console
178
258
  console.debug('[LiteRenderer:onError]', payload);
179
259
  lastEmittedRef.current = payload;
180
260
  }, [onError]);
181
-
182
- // batch short bursts (e.g., multiple async errors in same tick)
183
261
  var scheduleFlush = useCallback(function () {
184
262
  if (flushTimerRef.current) return;
185
263
  flushTimerRef.current = setTimeout(function () {
@@ -188,7 +266,7 @@ export default function LiteRenderer(props) {
188
266
  if (!errors.length) return;
189
267
  errorsBufferRef.current = [];
190
268
  emit(lastExternalEventRef.current, errors);
191
- }, 0); // micro-batch; increase (e.g. 50ms) if you want coarser batching
269
+ }, 0);
192
270
  }, [emit]);
193
271
  var pushError = useCallback(function (errPayload) {
194
272
  errorsBufferRef.current.push(_objectSpread({
@@ -199,6 +277,7 @@ export default function LiteRenderer(props) {
199
277
 
200
278
  /* ---------- global runtime + async error capture ---------- */
201
279
  useEffect(function () {
280
+ if (!isBrowser) return;
202
281
  var onWindowError = function onWindowError(event) {
203
282
  pushError({
204
283
  type: 'runtime-error',
@@ -230,64 +309,20 @@ export default function LiteRenderer(props) {
230
309
  var prev = prevExternalEventRef.current;
231
310
  if (prev === externalEvent) return;
232
311
  prevExternalEventRef.current = externalEvent;
233
-
234
- // if we already emitted something before, re-send it with the new event context
235
312
  var last = lastEmittedRef.current;
236
313
  if (last && last.errors && last.errors.length) {
237
314
  emit(lastExternalEventRef.current, last.errors);
238
315
  }
239
316
  }, [externalEvent, emit]);
240
- var id = configData.id,
241
- logoImg = configData.logoImg,
242
- companyUrl = configData.companyUrl;
243
- useEffect(function () {
244
- var initMyCatalog = /*#__PURE__*/function () {
245
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
246
- var x, _x, _x2;
247
- return _regeneratorRuntime.wrap(function (_context) {
248
- while (1) switch (_context.prev = _context.next) {
249
- case 0:
250
- for (x in Areas) MyCatalog.registerElement(Areas[x]);
251
- for (_x in Lines) MyCatalog.registerElement(Lines[_x]);
252
- for (_x2 in Holes) MyCatalog.registerElement(Holes[_x2]);
253
- MyCatalog.registerCategory('Windows', 'Windows', [Holes.windowClear, Holes.windowCross, Holes.windowDoubleHung, Holes.windowVertical]);
254
- MyCatalog.registerCategory('Doors', 'Doors', [Holes.doorInterior, Holes.doorExterior, Holes.doorCloset, Holes.doorSliding, Holes.doorwayFramed, Holes.doorwayFrameless]);
255
- case 1:
256
- case "end":
257
- return _context.stop();
258
- }
259
- }, _callee);
260
- }));
261
- return function initMyCatalog() {
262
- return _ref.apply(this, arguments);
263
- };
264
- }();
265
- var initCatalog = /*#__PURE__*/function () {
266
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
267
- return _regeneratorRuntime.wrap(function (_context2) {
268
- while (1) switch (_context2.prev = _context2.next) {
269
- case 0:
270
- _context2.next = 1;
271
- return initMyCatalog();
272
- case 1:
273
- case "end":
274
- return _context2.stop();
275
- }
276
- }, _callee2);
277
- }));
278
- return function initCatalog() {
279
- return _ref2.apply(this, arguments);
280
- };
281
- }();
282
- initCatalog();
283
- // eslint-disable-next-line react-hooks/exhaustive-deps
284
- }, [id]);
317
+ var _ref = configData || {},
318
+ logoImg = _ref.logoImg,
319
+ companyUrl = _ref.companyUrl;
285
320
  return /*#__PURE__*/React.createElement(AppContext.Provider, null, /*#__PURE__*/React.createElement(Provider, {
286
- store: store
321
+ store: storeRef.current
287
322
  }, /*#__PURE__*/React.createElement(ToolErrorBoundary, {
288
323
  pushError: pushError
289
324
  }, /*#__PURE__*/React.createElement(LiteKitchenConfigurator, _extends({
290
- catalog: MyCatalog,
325
+ catalog: catalogRef.current,
291
326
  width: width,
292
327
  height: height,
293
328
  logoImage: logoImg,
@@ -301,9 +336,6 @@ export default function LiteRenderer(props) {
301
336
  onInternalEvent: onInternalEvent
302
337
  }, passThrough)))));
303
338
  }
304
-
305
- /* ============================== prop types ============================== */
306
-
307
339
  LiteRenderer.propTypes = {
308
340
  width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
309
341
  height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
Binary file
@@ -838,85 +838,88 @@ var Project = /*#__PURE__*/function () {
838
838
  state = state.merge({
839
839
  catalog: catalog
840
840
  });
841
- var _viewer2D = state.viewer2D;
842
- var viewer = _viewer2D.toJS();
843
- width = convert(width).from(state.getIn(['scene', 'layers', 'layer-1', 'unit'])).to('cm');
844
- height = convert(height).from(state.getIn(['scene', 'layers', 'layer-1', 'unit'])).to('cm');
845
- var layerID = state.scene.selectedLayer;
846
841
  state = Item.setInitialDoorStyle(state, doorStyle).updatedState;
847
- if (isEmpty(viewer)) return {
848
- updatedState: state
849
- };
850
- var halfWidth = width / 2;
851
- var halfHeight = height / 2;
852
- var viewerWidth = viewer.SVGWidth;
853
- var viewerHeight = viewer.SVGHeight;
854
- var centerPos = {
855
- x: viewerWidth / 2,
856
- y: viewerHeight / 2
857
- };
858
- var vtLB = {
859
- x: centerPos.x - halfWidth,
860
- y: centerPos.y - halfHeight
861
- };
862
- var vtRB = {
863
- x: centerPos.x + halfWidth,
864
- y: centerPos.y - halfHeight
865
- };
866
- var vtRT = {
867
- x: centerPos.x + halfWidth,
868
- y: centerPos.y + halfHeight
869
- };
870
- var vtLT = {
871
- x: centerPos.x - halfWidth,
872
- y: centerPos.y + halfHeight
873
- };
874
- var vertices = [];
875
- switch (roomShapeType) {
876
- case 'rectangle':
877
- vertices = [vtLB, vtLT, vtRT, vtRB];
878
- break;
879
- case constants.ROOM_SHAPE_TYPE.TWO_WALLS_RIGHT_BOTTOM:
880
- vertices = [vtLB, vtRB, vtRT];
881
- break;
882
- case constants.ROOM_SHAPE_TYPE.TWO_WALLS_RIGHT_TOP:
883
- vertices = [vtRB, vtRT, vtLT];
884
- break;
885
- case constants.ROOM_SHAPE_TYPE.TWO_WALLS_LEFT_TOP:
886
- vertices = [vtRT, vtLT, vtLB];
887
- break;
888
- case constants.ROOM_SHAPE_TYPE.TWO_WALLS_LEFT_BOTTOM:
889
- vertices = [vtLT, vtLB, vtRB];
890
- break;
891
- case constants.ROOM_SHAPE_TYPE.THREE_WALLS_LEFT_TOP_RIGHT:
892
- vertices = [vtRB, vtRT, vtLT, vtLB];
893
- break;
894
- case constants.ROOM_SHAPE_TYPE.THREE_WALLS_TOP_RIGHT_BOTTOM:
895
- vertices = [vtLB, vtRB, vtRT, vtLT];
896
- break;
897
- case constants.ROOM_SHAPE_TYPE.THREE_WALLS_RIGHT_BOTTOM_LEFT:
898
- vertices = [vtLT, vtLB, vtRB, vtRT];
899
- break;
900
- case constants.ROOM_SHAPE_TYPE.THREE_WALLS_BOTTOM_LEFT_TOP:
901
- vertices = [vtRT, vtLT, vtLB, vtRB];
902
- break;
903
- }
904
- for (var i = 0; i < vertices.length - 1; i++) {
905
- state = Line.create(state, layerID, 'wall', vertices[i].x, vertices[i].y, vertices[i + 1].x, vertices[i + 1].y).updatedState;
906
- }
907
- if (roomShapeType === constants.ROOM_SHAPE_TYPE.RECTANGLE) {
908
- state = Line.create(state, layerID, 'wall', vertices[vertices.length - 1].x, vertices[vertices.length - 1].y, vertices[0].x, vertices[0].y).updatedState;
909
- }
910
- var layer = state.getIn(['scene', 'layers', layerID]);
911
- var lines = layer.getIn(['lines']).toJS();
912
- var drawingInfo = {};
913
- var lineKey = Object.keys(lines);
914
- for (var _i = 0; _i < lineKey.length; _i++) {
915
- if (!isEmpty(lineKey)) {
916
- drawingInfo.drawingLine = layer.getIn(['lines', lineKey[_i]]);
842
+ var layerID = state.scene.selectedLayer;
843
+ if (roomShapeType !== constants.ROOM_SHAPE_TYPE.CUSTOM && !isEmpty(width) && !isEmpty(height) && width !== 0 && height !== 0) {
844
+ var _viewer2D = state.viewer2D;
845
+ var viewer = _viewer2D.toJS();
846
+ if (isEmpty(viewer)) return {
847
+ updatedState: state
848
+ };
849
+ width = convert(width).from(state.getIn(['scene', 'layers', 'layer-1', 'unit'])).to('cm');
850
+ height = convert(height).from(state.getIn(['scene', 'layers', 'layer-1', 'unit'])).to('cm');
851
+ var halfWidth = width / 2;
852
+ var halfHeight = height / 2;
853
+ var viewerWidth = viewer.SVGWidth;
854
+ var viewerHeight = viewer.SVGHeight;
855
+ var centerPos = {
856
+ x: viewerWidth / 2,
857
+ y: viewerHeight / 2
858
+ };
859
+ var vtLB = {
860
+ x: centerPos.x - halfWidth,
861
+ y: centerPos.y - halfHeight
862
+ };
863
+ var vtRB = {
864
+ x: centerPos.x + halfWidth,
865
+ y: centerPos.y - halfHeight
866
+ };
867
+ var vtRT = {
868
+ x: centerPos.x + halfWidth,
869
+ y: centerPos.y + halfHeight
870
+ };
871
+ var vtLT = {
872
+ x: centerPos.x - halfWidth,
873
+ y: centerPos.y + halfHeight
874
+ };
875
+ var vertices = [];
876
+ switch (roomShapeType) {
877
+ case 'rectangle':
878
+ vertices = [vtLB, vtLT, vtRT, vtRB];
879
+ break;
880
+ case constants.ROOM_SHAPE_TYPE.TWO_WALLS_RIGHT_BOTTOM:
881
+ vertices = [vtLB, vtRB, vtRT];
882
+ break;
883
+ case constants.ROOM_SHAPE_TYPE.TWO_WALLS_RIGHT_TOP:
884
+ vertices = [vtRB, vtRT, vtLT];
885
+ break;
886
+ case constants.ROOM_SHAPE_TYPE.TWO_WALLS_LEFT_TOP:
887
+ vertices = [vtRT, vtLT, vtLB];
888
+ break;
889
+ case constants.ROOM_SHAPE_TYPE.TWO_WALLS_LEFT_BOTTOM:
890
+ vertices = [vtLT, vtLB, vtRB];
891
+ break;
892
+ case constants.ROOM_SHAPE_TYPE.THREE_WALLS_LEFT_TOP_RIGHT:
893
+ vertices = [vtRB, vtRT, vtLT, vtLB];
894
+ break;
895
+ case constants.ROOM_SHAPE_TYPE.THREE_WALLS_TOP_RIGHT_BOTTOM:
896
+ vertices = [vtLB, vtRB, vtRT, vtLT];
897
+ break;
898
+ case constants.ROOM_SHAPE_TYPE.THREE_WALLS_RIGHT_BOTTOM_LEFT:
899
+ vertices = [vtLT, vtLB, vtRB, vtRT];
900
+ break;
901
+ case constants.ROOM_SHAPE_TYPE.THREE_WALLS_BOTTOM_LEFT_TOP:
902
+ vertices = [vtRT, vtLT, vtLB, vtRB];
903
+ break;
904
+ }
905
+ for (var i = 0; i < vertices.length - 1; i++) {
906
+ state = Line.create(state, layerID, 'wall', vertices[i].x, vertices[i].y, vertices[i + 1].x, vertices[i + 1].y).updatedState;
907
+ }
908
+ if (roomShapeType === constants.ROOM_SHAPE_TYPE.RECTANGLE) {
909
+ state = Line.create(state, layerID, 'wall', vertices[vertices.length - 1].x, vertices[vertices.length - 1].y, vertices[0].x, vertices[0].y).updatedState;
910
+ }
911
+ var layer = state.getIn(['scene', 'layers', layerID]);
912
+ var lines = layer.getIn(['lines']).toJS();
913
+ var drawingInfo = {};
914
+ var lineKey = Object.keys(lines);
915
+ for (var _i = 0; _i < lineKey.length; _i++) {
916
+ if (!isEmpty(lineKey)) {
917
+ drawingInfo.drawingLine = layer.getIn(['lines', lineKey[_i]]);
918
+ }
919
+ state = Layer.detectAndUpdateAreas(state, layerID, drawingInfo).updatedState;
917
920
  }
918
- state = Layer.detectAndUpdateAreas(state, layerID, drawingInfo).updatedState;
919
921
  }
922
+
920
923
  // copy keeped measurement unit
921
924
  state = state.setIn(['scene', 'layers', layerID, 'unit'], layerUnit);
922
925
  state = state.setIn(['scene', 'layers', layerID, 'ceilHeight'], ceilHeight);
@@ -32,6 +32,7 @@ export default function Ruler(_ref) {
32
32
  transform = _ref.transform,
33
33
  style = _ref.style;
34
34
  var distanceText = convert(length).from(unit).to(rulerUnit).toFixed(0);
35
+ distanceText = (Math.round(convert(distanceText).from('in').to(layer.unit) * 100) / 100).toFixed(0);
35
36
  var textLength = (distanceText.length + layer.unit.length) * 9;
36
37
  return /*#__PURE__*/React.createElement("g", {
37
38
  transform: transform
@@ -52,7 +53,7 @@ export default function Ruler(_ref) {
52
53
  transform: "scale(1, -1)",
53
54
  style: STYLE_TEXT,
54
55
  fill: TEXT_COLOR_NEUTRAL_7
55
- }, Math.round(convert(distanceText).from('in').to(layer.unit) * 100) / 100, layer.unit === 'in' ? '"' : layer.unit)), /*#__PURE__*/React.createElement("line", {
56
+ }, distanceText, layer.unit === 'in' ? '"' : layer.unit)), /*#__PURE__*/React.createElement("line", {
56
57
  x1: style === STYLE_ROOM_SHAPE ? 0 : 4,
57
58
  y1: "0",
58
59
  x2: (length - textLength) / 2 < 0 ? 0 : (length - textLength) / 2,
@@ -266,7 +266,7 @@ export function updateScene(planData, sceneData, oldSceneData, diffArray, action
266
266
  * Every 'doorStyle' change has a 'door_style_id' change.
267
267
  * So, if door_style_id changes, it indicates 'doorStyle' change.
268
268
  */
269
- if (['id'].includes(path[path.length - 1])) isSettingDoorStyle = true;
269
+ if (path[1] === 'layers' && path[3] === 'molding' || path[path.length - 2] === 'doorStyle' && path[path.length - 1] === 'id' || ['id'].includes(path[path.length - 1])) isSettingDoorStyle = true;
270
270
 
271
271
  // If there are any molding change of layer
272
272
  if (path[1] === 'layers' && path[3] === 'molding') isUpdateMolding = true;
@@ -951,9 +951,9 @@ function getLineDistance(obj, layer, isCalcWall, index) {
951
951
  obj.geometry.attributes.position.needsUpdate = true;
952
952
  obj.geometry.computeBoundingSphere();
953
953
  obj.geometry.computeBoundingBox();
954
- var dist = formatNumber(convert(intersects[i].distance).from('cm').to('in'), DECIMAL_PLACES_2);
954
+ var dist = convert(intersects[i].distance).from('cm').to('in');
955
955
  if (dist > 3) {
956
- var _canvas = getTextCanvas(dist);
956
+ var _canvas = getDistanceCanvas(dist, layer);
957
957
  var wid = _canvas.width / window.innerWidth * 30;
958
958
  var hei = _canvas.height / window.innerHeight * 30;
959
959
  var texture = new Three.Texture(_canvas);
@@ -1075,7 +1075,7 @@ function getLineDistance(obj, layer, isCalcWall, index) {
1075
1075
  obj.geometry.attributes.position.needsUpdate = true;
1076
1076
  var _dist = formatNumber(distance, DECIMAL_PLACES_2);
1077
1077
  if (_dist > 3) {
1078
- var _canvas2 = getTextCanvas(_dist);
1078
+ var _canvas2 = getDistanceCanvas(_dist, layer);
1079
1079
  var _wid = _canvas2.width / window.innerWidth * 30;
1080
1080
  var _hei = _canvas2.height / window.innerHeight * 30;
1081
1081
  var _texture = new Three.Texture(_canvas2);
@@ -1203,12 +1203,17 @@ export function getIntersectPoint(opX, opY, pX, pY) {
1203
1203
  function gcd(a, b) {
1204
1204
  return a % b ? gcd(b, a % b) : b;
1205
1205
  }
1206
- function getTextCanvas(text) {
1207
- var parameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1206
+ function getDistanceCanvas(distance, layer) {
1207
+ var _layer$unit;
1208
+ var parameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1208
1209
  var canvas = document.createElement('canvas');
1209
1210
  var ctx = canvas.getContext('2d');
1211
+ var curUnit = (_layer$unit = layer === null || layer === void 0 ? void 0 : layer.unit) !== null && _layer$unit !== void 0 ? _layer$unit : 'in';
1212
+ var distText = String((Math.round(convert(distance).from('in').to(curUnit) * 100) / 100).toFixed(0));
1210
1213
  var fontSize = 16;
1211
- var integral = String(text) + "''";
1214
+ var integral = distText + curUnit;
1215
+ // let integral = String(distance) + "''";
1216
+
1212
1217
  parameters.fontName = parameters.fontName || ARROW_TEXT_FONTFACE;
1213
1218
 
1214
1219
  // Prepare the font to be able to measure
@@ -231,6 +231,7 @@ var Scene3DViewer = /*#__PURE__*/function (_React$Component) {
231
231
  });
232
232
  self.renderer.domElement.style.display = 'block';
233
233
  }, 1500);
234
+ self.planData = planData;
234
235
  });
235
236
  var area = scene.getIn(['layers', scene.selectedLayer, 'areas']);
236
237
  var layer = scene.getIn(['layers', scene.selectedLayer]);
package/es/constants.js CHANGED
@@ -754,6 +754,7 @@ export var INTERNAL_EVENT_START_DRAW_WALL = 'INTERNAL_EVENT_START_DRAW_WALL';
754
754
 
755
755
  // room shape type
756
756
  export var ROOM_SHAPE_TYPE = {
757
+ CUSTOM: 'custom',
757
758
  RECTANGLE: 'rectangle',
758
759
  TWO_WALLS_LEFT_TOP: '2wLeftTop',
759
760
  TWO_WALLS_RIGHT_TOP: '2wRightTop',