kitchen-simulator 3.0.1 → 3.1.0-alpha.12

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 (43) hide show
  1. package/es/LiteKitchenConfigurator.js +42 -9
  2. package/es/LiteRenderer.js +5 -8
  3. package/es/actions/lines-actions.js +3 -1
  4. package/es/assets/img/png/helper/video_preview_start.png +0 -0
  5. package/es/catalog/factories/area-factory-3d.js +17 -17
  6. package/es/catalog/holes/window-clear/planner-element.js +2 -2
  7. package/es/catalog/utils/item-loader.js +198 -197
  8. package/es/class/item.js +11 -0
  9. package/es/class/line.js +14 -2
  10. package/es/components/viewer2d/item.js +41 -14
  11. package/es/components/viewer2d/rulerDist.js +1 -1
  12. package/es/components/viewer2d/utils.js +2 -2
  13. package/es/components/viewer2d/viewer2d.js +13 -11
  14. package/es/components/viewer3d/viewer3d.js +98 -96
  15. package/es/constants.js +6 -2
  16. package/es/devLiteRenderer.js +192 -98
  17. package/es/index.js +82 -13
  18. package/es/reducers/lines-reducer.js +1 -1
  19. package/es/utils/geometry.js +161 -0
  20. package/es/utils/isolate-event-handler.js +273 -116
  21. package/es/utils/molding.js +234 -2
  22. package/lib/LiteKitchenConfigurator.js +42 -9
  23. package/lib/LiteRenderer.js +5 -8
  24. package/lib/actions/lines-actions.js +3 -1
  25. package/lib/assets/img/png/helper/video_preview_start.png +0 -0
  26. package/lib/catalog/factories/area-factory-3d.js +14 -14
  27. package/lib/catalog/holes/window-clear/planner-element.js +2 -2
  28. package/lib/catalog/utils/item-loader.js +195 -194
  29. package/lib/class/item.js +11 -0
  30. package/lib/class/line.js +13 -1
  31. package/lib/components/viewer2d/item.js +40 -13
  32. package/lib/components/viewer2d/rulerDist.js +1 -1
  33. package/lib/components/viewer2d/utils.js +2 -2
  34. package/lib/components/viewer2d/viewer2d.js +13 -11
  35. package/lib/components/viewer3d/viewer3d.js +98 -96
  36. package/lib/constants.js +11 -7
  37. package/lib/devLiteRenderer.js +186 -92
  38. package/lib/index.js +82 -13
  39. package/lib/reducers/lines-reducer.js +1 -1
  40. package/lib/utils/geometry.js +162 -0
  41. package/lib/utils/isolate-event-handler.js +272 -115
  42. package/lib/utils/molding.js +233 -0
  43. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -12,52 +12,121 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
12
12
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
13
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
14
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
16
  var _react = _interopRequireDefault(require("react"));
16
17
  var _reactDom = _interopRequireDefault(require("react-dom"));
17
18
  var _LiteRenderer = _interopRequireDefault(require("./LiteRenderer"));
19
+ 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; }
20
+ 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) { (0, _defineProperty2["default"])(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; }
18
21
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
19
22
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
20
23
  function renderKitchenSimulator(container) {
21
24
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
22
- var setExternalEventFn = null;
23
-
24
- // Internal wrapper that exposes a state setter
25
+ var apiRef = null;
26
+ var idSeq = 0;
25
27
  var Wrapper = /*#__PURE__*/function (_React$Component) {
26
28
  function Wrapper(p) {
27
29
  var _this;
28
30
  (0, _classCallCheck2["default"])(this, Wrapper);
29
31
  _this = _callSuper(this, Wrapper, [p]);
32
+ (0, _defineProperty2["default"])(_this, "onExternalEventProcessed", function (eventId) {
33
+ // Resolve only if it matches the current event in flight
34
+ if (eventId === _this._currentId) {
35
+ try {
36
+ var _this$_currentResolve, _this2;
37
+ (_this$_currentResolve = (_this2 = _this)._currentResolve) === null || _this$_currentResolve === void 0 || _this$_currentResolve.call(_this2);
38
+ } finally {
39
+ _this._currentResolve = null;
40
+ _this._currentId = null;
41
+ _this.processing = false;
42
+ _this.processNext();
43
+ }
44
+ }
45
+ });
30
46
  _this.state = {
31
- externalEvent: p.externalEvent || null
47
+ externalEvent: null
48
+ };
49
+ _this.queue = [];
50
+ _this.processing = false;
51
+ _this._currentResolve = null;
52
+ _this._currentId = null;
53
+ apiRef = {
54
+ enqueueExternalEvent: function enqueueExternalEvent(ev) {
55
+ return _this.enqueue(ev);
56
+ }
32
57
  };
33
- setExternalEventFn = _this.setExternalEvent.bind(_this);
34
58
  return _this;
35
59
  }
36
60
  (0, _inherits2["default"])(Wrapper, _React$Component);
37
61
  return (0, _createClass2["default"])(Wrapper, [{
38
- key: "setExternalEvent",
39
- value: function setExternalEvent(newEvent) {
62
+ key: "enqueue",
63
+ value: function enqueue(ev) {
64
+ if (!ev) return Promise.resolve();
65
+ var id = ++idSeq;
66
+ var resolve;
67
+ var promise = new Promise(function (res) {
68
+ return resolve = res;
69
+ });
70
+ this.queue.push({
71
+ id: id,
72
+ ev: ev,
73
+ resolve: resolve
74
+ });
75
+ if (!this.processing) this.processNext();
76
+ return promise;
77
+ }
78
+ }, {
79
+ key: "processNext",
80
+ value: function processNext() {
81
+ var _this3 = this;
82
+ var next = this.queue.shift();
83
+ if (!next) {
84
+ this.processing = false;
85
+ return;
86
+ }
87
+ this.processing = true;
88
+
89
+ // Tool assigns __eventId (do NOT rely on host for this)
90
+ var payload = _objectSpread(_objectSpread({}, next.ev), {}, {
91
+ __eventId: next.id
92
+ });
93
+
94
+ // Edge trigger: clear then set so downstream sees prop change reliably
40
95
  this.setState({
41
- externalEvent: newEvent
96
+ externalEvent: null
97
+ }, function () {
98
+ _this3._currentResolve = next.resolve;
99
+ _this3._currentId = next.id;
100
+ _this3.setState({
101
+ externalEvent: payload
102
+ });
42
103
  });
43
104
  }
44
105
  }, {
45
106
  key: "render",
46
107
  value: function render() {
47
108
  return /*#__PURE__*/_react["default"].createElement(_LiteRenderer["default"], (0, _extends2["default"])({}, this.props, {
48
- externalEvent: this.state.externalEvent
109
+ externalEvent: this.state.externalEvent,
110
+ onExternalEventProcessed: this.onExternalEventProcessed
49
111
  }));
50
112
  }
51
113
  }]);
52
- }(_react["default"].Component); // Mount once
114
+ }(_react["default"].Component);
53
115
  _reactDom["default"].render(/*#__PURE__*/_react["default"].createElement(Wrapper, props), container);
54
116
  return {
55
- updateExternalEvent: function updateExternalEvent(newExternalEvent) {
56
- var _setExternalEventFn;
57
- (_setExternalEventFn = setExternalEventFn) === null || _setExternalEventFn === void 0 || _setExternalEventFn(newExternalEvent);
117
+ // Promise-based API (use this from host)
118
+ enqueueExternalEvent: function enqueueExternalEvent(ev) {
119
+ var _apiRef$enqueueExtern, _apiRef, _apiRef$enqueueExtern2;
120
+ return (_apiRef$enqueueExtern = (_apiRef = apiRef) === null || _apiRef === void 0 || (_apiRef$enqueueExtern2 = _apiRef.enqueueExternalEvent) === null || _apiRef$enqueueExtern2 === void 0 ? void 0 : _apiRef$enqueueExtern2.call(_apiRef, ev)) !== null && _apiRef$enqueueExtern !== void 0 ? _apiRef$enqueueExtern : Promise.resolve();
121
+ },
122
+ // old API still works, but no await possible
123
+ updateExternalEvent: function updateExternalEvent(ev) {
124
+ var _apiRef2, _apiRef2$enqueueExter;
125
+ (_apiRef2 = apiRef) === null || _apiRef2 === void 0 || (_apiRef2$enqueueExter = _apiRef2.enqueueExternalEvent) === null || _apiRef2$enqueueExter === void 0 || _apiRef2$enqueueExter.call(_apiRef2, ev);
58
126
  },
59
127
  unmount: function unmount() {
60
128
  _reactDom["default"].unmountComponentAtNode(container);
129
+ apiRef = null;
61
130
  }
62
131
  };
63
132
  }
@@ -19,7 +19,7 @@ function _default(state, action) {
19
19
  state = state.merge({
20
20
  sceneHistory: _export2.history.historyPush(state.sceneHistory, state.scene)
21
21
  });
22
- return _export.Line.beginDrawingLine(state, action.layerID, action.x, action.y).updatedState;
22
+ return _export.Line.beginDrawingLine(state, action.layerID, action.x, action.y, action.onInternalEvent).updatedState;
23
23
  case _constants.UPDATE_DRAWING_LINE:
24
24
  return _export.Line.updateDrawingLine(state, action.x, action.y, action.relatedLines).updatedState;
25
25
  case _constants.STOP_DRAWING_LINE:
@@ -14,6 +14,7 @@ exports.angleBetweenTwoPoints = angleBetweenTwoPoints;
14
14
  exports.angleBetweenTwoPointsAndOrigin = angleBetweenTwoPointsAndOrigin;
15
15
  exports.buildRectFromLines = buildRectFromLines;
16
16
  exports.calcCreateSnap = calcCreateSnap;
17
+ exports.calcDistancesFromItemToWalls = calcDistancesFromItemToWalls;
17
18
  exports.calcSnap = calcSnap;
18
19
  exports.calcSnap1 = calcSnap1;
19
20
  exports.calcSnap2 = calcSnap2;
@@ -2542,4 +2543,165 @@ function validRect(itemRect, rects) {
2542
2543
  return rects.every(function (rect) {
2543
2544
  return !intersectRect(rect.rect, updatedItemRect.rect);
2544
2545
  });
2546
+ }
2547
+ function getCalcRectFromItem2(itemInfo) {
2548
+ var x = itemInfo.pos.x;
2549
+ var y = itemInfo.pos.y;
2550
+ var w = itemInfo.size.width / 2;
2551
+ var h = itemInfo.size.height / 2;
2552
+ var rotRad = itemInfo.rotRad;
2553
+ var mh = 3 * h / 4;
2554
+ var mx = x - w * Math.cos(rotRad) - mh * Math.sin(rotRad);
2555
+ var my = y - w * Math.sin(rotRad) + mh * Math.cos(rotRad);
2556
+ var m2x = x + w * Math.cos(rotRad) - mh * Math.sin(rotRad);
2557
+ var m2y = y + w * Math.sin(rotRad) + mh * Math.cos(rotRad);
2558
+ var m3x = x - h * Math.sin(rotRad);
2559
+ var m3y = y + h * Math.cos(rotRad);
2560
+ var m1x = x + h * Math.sin(rotRad);
2561
+ var m1y = y - h * Math.cos(rotRad);
2562
+ return {
2563
+ rectCenterPoint: [[point(mx, my), 180], [point(m1x, m1y), -90], [point(m2x, m2y), 0], [point(m3x, m3y), 90]]
2564
+ };
2565
+ }
2566
+ function getAllItems2(curItem, layer) {
2567
+ var rectarray = [];
2568
+ var tempHeight = curItem.get('properties').get('depth');
2569
+ layer.items.forEach(function (item) {
2570
+ var val = {
2571
+ pos: {
2572
+ x: item.x,
2573
+ y: item.y
2574
+ },
2575
+ rotRad: item.rotation / 180 * Math.PI
2576
+ };
2577
+ var width = (0, _convertUnitsLite.convert)(item.properties.getIn(['width', '_length'])).from('in').to('cm');
2578
+ var height = (0, _convertUnitsLite.convert)(item.properties.getIn(['depth', '_length'])).from('in').to('cm');
2579
+ val.size = {
2580
+ width: width,
2581
+ height: height
2582
+ };
2583
+ if (curItem.get('id') !== item.id) {
2584
+ var detectObjectsAtSameAltitudeFlag = curItem.get('layoutpos') === 'Base' ? item.properties.getIn(['altitude', '_length']) <= curItem.get('properties').getIn(['altitude', '_length']) + tempHeight.get('_length') : item.properties.getIn(['altitude', '_length']) + item.properties.getIn(['height', '_length']) >= curItem.get('properties').getIn(['altitude', '_length']);
2585
+ if (detectObjectsAtSameAltitudeFlag) {
2586
+ var x = val.pos.x;
2587
+ var y = val.pos.y;
2588
+ var rotRad = val.rotRad;
2589
+ var w = val.size.width / 2;
2590
+ var h = val.size.height / 2;
2591
+ var mx = x - w * Math.cos(rotRad);
2592
+ var my = y - w * Math.sin(rotRad);
2593
+ var x0 = mx + h * Math.sin(rotRad);
2594
+ var y0 = my - h * Math.cos(rotRad);
2595
+ var x3 = mx * 2 - x0;
2596
+ var y3 = my * 2 - y0;
2597
+ var x1 = x * 2 - x3;
2598
+ var y1 = y * 2 - y3;
2599
+ var x2 = x * 2 - x0;
2600
+ var y2 = y * 2 - y0;
2601
+ rectarray.push({
2602
+ rect: [point(x0, y0), point(x1, y1), point(x0, y0), point(x1, y1)]
2603
+ });
2604
+ rectarray.push({
2605
+ rect: [point(x1, y1), point(x2, y2), point(x1, y1), point(x2, y2)]
2606
+ });
2607
+ rectarray.push({
2608
+ rect: [point(x2, y2), point(x3, y3), point(x2, y2), point(x3, y3)]
2609
+ });
2610
+ rectarray.push({
2611
+ rect: [point(x3, y3), point(x0, y0), point(x3, y3), point(x0, y0)]
2612
+ });
2613
+ }
2614
+ }
2615
+ });
2616
+ return {
2617
+ others: rectarray
2618
+ };
2619
+ }
2620
+ function calcDistancesFromItemToWalls(curItem, layer) {
2621
+ if ((0, _helper.isEmpty)(curItem)) return [];
2622
+ var x = curItem.get('x');
2623
+ var y = curItem.get('y');
2624
+ var rotRad = curItem.get('rotation') / 180 * Math.PI;
2625
+ var width, height;
2626
+ if (curItem.get('properties').get('width') || curItem.get('properties').get('depth')) {
2627
+ width = (0, _convertUnitsLite.convert)(curItem.get('properties').get('width').get('_length')).from(curItem.get('properties').get('width').get('_unit')).to('cm');
2628
+ height = (0, _convertUnitsLite.convert)(curItem.get('properties').get('depth').get('_length')).from(curItem.get('properties').get('depth').get('_unit')).to('cm');
2629
+ } else {
2630
+ width = (0, _convertUnitsLite.convert)(curItem.info.sizeinfo.width).from('in').to('cm');
2631
+ height = (0, _convertUnitsLite.convert)(curItem.info.sizeinfo.depth).from('in').to('cm');
2632
+ }
2633
+ var center_h = 3 * height / 8;
2634
+ var center_x = x; // middle of front line of cabinet rect
2635
+ var center_y = y;
2636
+ var center_x1 = x - center_h * Math.sin(rotRad); // center point of cabinet rect
2637
+ var center_y1 = y + center_h * Math.cos(rotRad);
2638
+ var PointArray = [];
2639
+ var itemInfo = {
2640
+ pos: {
2641
+ x: x,
2642
+ y: y
2643
+ },
2644
+ rotRad: rotRad
2645
+ };
2646
+ itemInfo.size = {
2647
+ width: width,
2648
+ height: height
2649
+ };
2650
+ var curiteminfo = getCalcRectFromItem2(itemInfo);
2651
+ var allItemRect = getAllItems2(curItem, layer);
2652
+ var allLines = getAllLines(layer);
2653
+ var allLineRects = buildRectFromLines(layer, allLines);
2654
+ var allRect = allLineRects.concat(allItemRect.others);
2655
+ var _loop = function _loop(i) {
2656
+ // [rectCenterPoint] has four middle points of cabinet rect edges
2657
+ var centerpoint = curiteminfo.rectCenterPoint[i];
2658
+ var comparelength = []; // distance array from rectCenterPoint[i] to other lines(walls, other cabinet rect edges)
2659
+ var a;
2660
+ var RectLineFuction; // normal line of cabinet rect edge
2661
+ if (centerpoint[1] === 180 || centerpoint[1] === 0) RectLineFuction = linePassingThroughTwoPoints(centerpoint[0].x, centerpoint[0].y, center_x1, center_y1);else RectLineFuction = linePassingThroughTwoPoints(centerpoint[0].x, centerpoint[0].y, center_x, center_y);
2662
+ allRect.forEach(function (linerect) {
2663
+ // calc distance to all other lines
2664
+ var p0 = clone_point(linerect.rect[2]);
2665
+ var p1 = clone_point(linerect.rect[3]);
2666
+ var lineFunction = {}; // other line function
2667
+ if (p0.x !== p1.x || p0.y !== p1.y) lineFunction = linePassingThroughTwoPoints(p0.x, p0.y, p1.x, p1.y);
2668
+ // intersection between normal line and other line
2669
+ var coordinatePoint = twoLinesIntersection(lineFunction.a, lineFunction.b, lineFunction.c, RectLineFuction.a, RectLineFuction.b, RectLineFuction.c);
2670
+ if (coordinatePoint !== undefined) {
2671
+ if (
2672
+ // intersection point is on the other line
2673
+ pointsDistance(p0.x, p0.y, p1.x, p1.y) > pointsDistance(p0.x, p0.y, coordinatePoint.x, coordinatePoint.y) && pointsDistance(p0.x, p0.y, p1.x, p1.y) > pointsDistance(p1.x, p1.y, coordinatePoint.x, coordinatePoint.y)) {
2674
+ // check the intersection point is outside direction of edge
2675
+ var isOutside = true;
2676
+ for (var j = 0; j < curiteminfo.rectCenterPoint.length; j++) {
2677
+ if (j === i) continue;
2678
+ var otherCenterPoint = curiteminfo.rectCenterPoint[j];
2679
+ if (isPointOnLineSegment(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y, otherCenterPoint[0].x, otherCenterPoint[0].y)) isOutside = false;
2680
+ }
2681
+ if (isOutside && pointsDistance(coordinatePoint.x, coordinatePoint.y, center_x, center_y) > pointsDistance(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y)) {
2682
+ comparelength.push(pointsDistance(centerpoint[0].x, centerpoint[0].y, coordinatePoint.x, coordinatePoint.y));
2683
+ a = Math.min.apply(null, comparelength);
2684
+ }
2685
+ }
2686
+ }
2687
+ });
2688
+ PointArray.push([a, centerpoint[1]]);
2689
+ };
2690
+ for (var i = 0; i < curiteminfo.rectCenterPoint.length; i++) {
2691
+ _loop(i);
2692
+ }
2693
+ PointArray.forEach(function (pointElement, index) {
2694
+ if (pointElement[0] == undefined) PointArray[index][0] = 0;
2695
+ });
2696
+ var cnt = 0;
2697
+ PointArray.forEach(function (pointElement) {
2698
+ if (pointElement[0] == 0) cnt++;
2699
+ });
2700
+ if (cnt == 4 || cnt == 3) {
2701
+ PointArray[0][0] = 100;
2702
+ PointArray[1][0] = 100;
2703
+ }
2704
+ return {
2705
+ PointArray: PointArray
2706
+ };
2545
2707
  }