kitchen-simulator 4.0.0-queuedEvents → 4.0.0
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.
- package/es/LiteKitchenConfigurator.js +141 -288
- package/es/LiteRenderer.js +159 -398
- package/es/actions/items-actions.js +10 -6
- package/es/actions/lines-actions.js +3 -1
- package/es/actions/project-actions.js +15 -5
- package/es/assets/img/svg/bottombar/elevation.svg +12 -5
- package/es/catalog/areas/area/planner-element.js +10 -5
- package/es/catalog/catalog.js +1 -4
- package/es/catalog/factories/area-factory-3d.js +2 -1
- package/es/catalog/factories/wall-factory-3d.js +2 -2
- package/es/catalog/factories/wall-factory.js +8 -8
- package/es/catalog/lines/wall/planner-element.js +18 -9
- package/es/catalog/utils/exporter.js +7 -3
- package/es/catalog/utils/item-loader.js +24 -14
- package/es/catalog/utils/mtl-loader.js +2 -2
- package/es/catalog/utils/obj-loader.js +2 -2
- package/es/class/hole.js +0 -2
- package/es/class/item.js +183 -184
- package/es/class/line.js +11 -3
- package/es/class/project.js +165 -48
- package/es/components/content.js +19 -6
- package/es/components/viewer2d/grids/grid-streak.js +1 -1
- package/es/components/viewer2d/item.js +84 -51
- package/es/components/viewer2d/line.js +315 -243
- package/es/components/viewer2d/ruler.js +20 -38
- package/es/components/viewer2d/rulerDist.js +48 -78
- package/es/components/viewer2d/utils.js +6 -0
- package/es/components/viewer2d/viewer2d.js +298 -220
- package/es/components/viewer3d/front3D.js +3 -2
- package/es/components/viewer3d/libs/mtl-loader.js +2 -2
- package/es/components/viewer3d/libs/obj-loader.js +2 -2
- package/es/components/viewer3d/libs/orbit-controls.js +3 -4
- package/es/components/viewer3d/libs/pointer-lock-controls.js +6 -7
- package/es/components/viewer3d/scene-creator.js +51 -15
- package/es/components/viewer3d/viewer3d.js +121 -82
- package/es/constants.js +111 -3
- package/es/devLiteRenderer.js +688 -31
- package/es/index.js +567 -87
- package/es/models.js +9 -5
- package/es/plugins/SVGLoader.js +7 -5
- package/es/plugins/console-debugger.js +0 -2
- package/es/plugins/keyboard.js +15 -6
- package/es/reducers/items-reducer.js +5 -5
- package/es/reducers/lines-reducer.js +1 -1
- package/es/reducers/project-reducer.js +5 -3
- package/es/shared-style.js +4 -4
- package/es/utils/geometry.js +163 -2
- package/es/utils/get-edges-of-subgraphs.js +1 -1
- package/es/utils/graph-cycles.js +1 -1
- package/es/utils/graph.js +1 -1
- package/es/utils/helper.js +105 -3
- package/es/utils/isolate-event-handler.js +1542 -164
- package/es/utils/molding.js +461 -11
- package/lib/LiteKitchenConfigurator.js +141 -289
- package/lib/LiteRenderer.js +159 -399
- package/lib/actions/items-actions.js +10 -6
- package/lib/actions/lines-actions.js +3 -1
- package/lib/actions/project-actions.js +15 -4
- package/lib/assets/img/svg/bottombar/elevation.svg +12 -5
- package/lib/catalog/areas/area/planner-element.js +11 -5
- package/lib/catalog/catalog.js +1 -4
- package/lib/catalog/factories/area-factory-3d.js +2 -1
- package/lib/catalog/factories/wall-factory-3d.js +2 -2
- package/lib/catalog/factories/wall-factory.js +8 -8
- package/lib/catalog/lines/wall/planner-element.js +19 -9
- package/lib/catalog/utils/exporter.js +7 -3
- package/lib/catalog/utils/item-loader.js +24 -14
- package/lib/catalog/utils/mtl-loader.js +9 -2
- package/lib/catalog/utils/obj-loader.js +10 -2
- package/lib/class/hole.js +0 -2
- package/lib/class/item.js +180 -181
- package/lib/class/line.js +9 -1
- package/lib/class/project.js +164 -47
- package/lib/components/content.js +19 -6
- package/lib/components/viewer2d/grids/grid-streak.js +1 -1
- package/lib/components/viewer2d/item.js +83 -50
- package/lib/components/viewer2d/line.js +315 -242
- package/lib/components/viewer2d/ruler.js +19 -37
- package/lib/components/viewer2d/rulerDist.js +48 -78
- package/lib/components/viewer2d/utils.js +7 -0
- package/lib/components/viewer2d/viewer2d.js +296 -219
- package/lib/components/viewer3d/front3D.js +3 -2
- package/lib/components/viewer3d/libs/mtl-loader.js +9 -2
- package/lib/components/viewer3d/libs/obj-loader.js +9 -2
- package/lib/components/viewer3d/libs/orbit-controls.js +11 -5
- package/lib/components/viewer3d/libs/pointer-lock-controls.js +13 -7
- package/lib/components/viewer3d/scene-creator.js +49 -13
- package/lib/components/viewer3d/viewer3d.js +119 -80
- package/lib/constants.js +116 -7
- package/lib/devLiteRenderer.js +687 -30
- package/lib/index.js +567 -87
- package/lib/models.js +9 -5
- package/lib/plugins/SVGLoader.js +7 -5
- package/lib/plugins/console-debugger.js +0 -2
- package/lib/plugins/keyboard.js +15 -6
- package/lib/reducers/items-reducer.js +5 -5
- package/lib/reducers/lines-reducer.js +1 -1
- package/lib/reducers/project-reducer.js +4 -2
- package/lib/shared-style.js +4 -4
- package/lib/utils/geometry.js +164 -2
- package/lib/utils/get-edges-of-subgraphs.js +6 -1
- package/lib/utils/graph-cycles.js +7 -8
- package/lib/utils/graph.js +6 -1
- package/lib/utils/helper.js +108 -2
- package/lib/utils/isolate-event-handler.js +1538 -159
- package/lib/utils/molding.js +463 -9
- package/package.json +1 -1
- package/es/assets/Window.hdr +0 -2100
- package/es/assets/img/1.jpg +0 -0
- package/lib/assets/Window.hdr +0 -2100
- package/lib/assets/img/1.jpg +0 -0
package/lib/index.js
CHANGED
|
@@ -6,129 +6,609 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
exports.renderKitchenSimulator = renderKitchenSimulator;
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
11
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
12
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
13
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
14
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
15
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
var
|
|
16
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
16
17
|
var _react = _interopRequireDefault(require("react"));
|
|
17
|
-
var _client = require("react-dom/client");
|
|
18
18
|
var _LiteRenderer = _interopRequireDefault(require("./LiteRenderer"));
|
|
19
|
-
|
|
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; }
|
|
19
|
+
var _client = require("react-dom/client");
|
|
21
20
|
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)); }
|
|
22
21
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
22
|
+
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; } } }; }
|
|
23
|
+
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; } }
|
|
24
|
+
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; }
|
|
23
25
|
var ROOT_KEY = '__kitchenSimulatorRoot__';
|
|
26
|
+
var API_KEY = '__kitchenSimulatorApi__';
|
|
27
|
+
function nextFrame() {
|
|
28
|
+
return new Promise(function (resolve) {
|
|
29
|
+
return requestAnimationFrame(resolve);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Track 3D asset network activity (gltf/glb/bin/textures/hdr/etc)
|
|
35
|
+
* Ref-counted global install so multiple instances don't clobber each other.
|
|
36
|
+
*/
|
|
37
|
+
function installGltfTracker() {
|
|
38
|
+
if (typeof window === 'undefined') {
|
|
39
|
+
var _subscribe = function _subscribe() {
|
|
40
|
+
return function () {};
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
getInFlight: function getInFlight() {
|
|
44
|
+
return 0;
|
|
45
|
+
},
|
|
46
|
+
waitForIdle: function () {
|
|
47
|
+
var _waitForIdle = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
48
|
+
return _regenerator["default"].wrap(function (_context) {
|
|
49
|
+
while (1) switch (_context.prev = _context.next) {
|
|
50
|
+
case 0:
|
|
51
|
+
return _context.abrupt("return", true);
|
|
52
|
+
case 1:
|
|
53
|
+
case "end":
|
|
54
|
+
return _context.stop();
|
|
55
|
+
}
|
|
56
|
+
}, _callee);
|
|
57
|
+
}));
|
|
58
|
+
function waitForIdle() {
|
|
59
|
+
return _waitForIdle.apply(this, arguments);
|
|
60
|
+
}
|
|
61
|
+
return waitForIdle;
|
|
62
|
+
}(),
|
|
63
|
+
uninstall: function uninstall() {},
|
|
64
|
+
subscribe: _subscribe
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
var GLOBAL_KEY = '__kitchenSimulatorGltfTracker__';
|
|
68
|
+
if (!window[GLOBAL_KEY]) {
|
|
69
|
+
window[GLOBAL_KEY] = {
|
|
70
|
+
refCount: 0,
|
|
71
|
+
inFlight: 0,
|
|
72
|
+
listeners: new Set(),
|
|
73
|
+
installed: false,
|
|
74
|
+
originalFetch: null,
|
|
75
|
+
originalOpen: null,
|
|
76
|
+
originalSend: null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
var g = window[GLOBAL_KEY];
|
|
80
|
+
var is3dAssetUrl = function is3dAssetUrl(url) {
|
|
81
|
+
try {
|
|
82
|
+
var _url$toString, _url$toString2;
|
|
83
|
+
var s = typeof url === 'string' ? url : (_url$toString = url === null || url === void 0 || (_url$toString2 = url.toString) === null || _url$toString2 === void 0 ? void 0 : _url$toString2.call(url)) !== null && _url$toString !== void 0 ? _url$toString : '';
|
|
84
|
+
var u = s.toLowerCase().split('?')[0]; // ignore cache params
|
|
85
|
+
return u.endsWith('.gltf') || u.endsWith('.glb') || u.endsWith('.bin') || u.endsWith('.ktx2') || u.endsWith('.hdr') || u.endsWith('.exr') || u.endsWith('.png') || u.endsWith('.jpg') || u.endsWith('.jpeg') || u.endsWith('.webp');
|
|
86
|
+
} catch (_unused) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var notify = function notify() {
|
|
91
|
+
var _iterator = _createForOfIteratorHelper(g.listeners),
|
|
92
|
+
_step;
|
|
93
|
+
try {
|
|
94
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
95
|
+
var fn = _step.value;
|
|
96
|
+
fn(g.inFlight);
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
_iterator.e(err);
|
|
100
|
+
} finally {
|
|
101
|
+
_iterator.f();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var subscribe = function subscribe(fn) {
|
|
105
|
+
g.listeners.add(fn);
|
|
106
|
+
fn(g.inFlight); // sync emit on subscribe
|
|
107
|
+
return function () {
|
|
108
|
+
return g.listeners["delete"](fn);
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
var installIfNeeded = function installIfNeeded() {
|
|
112
|
+
var _XHR$prototype, _XHR$prototype2;
|
|
113
|
+
if (g.installed) return;
|
|
114
|
+
|
|
115
|
+
// ---- XHR hook ----
|
|
116
|
+
var XHR = window.XMLHttpRequest;
|
|
117
|
+
if (XHR !== null && XHR !== void 0 && (_XHR$prototype = XHR.prototype) !== null && _XHR$prototype !== void 0 && _XHR$prototype.open && XHR !== null && XHR !== void 0 && (_XHR$prototype2 = XHR.prototype) !== null && _XHR$prototype2 !== void 0 && _XHR$prototype2.send) {
|
|
118
|
+
g.originalOpen = XHR.prototype.open;
|
|
119
|
+
g.originalSend = XHR.prototype.send;
|
|
120
|
+
XHR.prototype.open = function (method, url) {
|
|
121
|
+
var _g$originalOpen;
|
|
122
|
+
this.__is3dAssetRequest = is3dAssetUrl(url);
|
|
123
|
+
for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
124
|
+
rest[_key - 2] = arguments[_key];
|
|
125
|
+
}
|
|
126
|
+
return (_g$originalOpen = g.originalOpen).call.apply(_g$originalOpen, [this, method, url].concat(rest));
|
|
127
|
+
};
|
|
128
|
+
XHR.prototype.send = function () {
|
|
129
|
+
var _this = this;
|
|
130
|
+
if (this.__is3dAssetRequest) {
|
|
131
|
+
g.inFlight += 1;
|
|
132
|
+
notify();
|
|
133
|
+
var _done = function done() {
|
|
134
|
+
g.inFlight -= 1;
|
|
135
|
+
if (g.inFlight < 0) g.inFlight = 0;
|
|
136
|
+
notify();
|
|
137
|
+
_this.removeEventListener('loadend', _done);
|
|
138
|
+
};
|
|
139
|
+
this.addEventListener('loadend', _done);
|
|
140
|
+
}
|
|
141
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
142
|
+
args[_key2] = arguments[_key2];
|
|
143
|
+
}
|
|
144
|
+
return g.originalSend.apply(this, args);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ---- fetch hook ----
|
|
149
|
+
g.originalFetch = window.fetch;
|
|
150
|
+
if (typeof g.originalFetch === 'function') {
|
|
151
|
+
window.fetch = /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
152
|
+
var _len3,
|
|
153
|
+
args,
|
|
154
|
+
_key3,
|
|
155
|
+
url,
|
|
156
|
+
track,
|
|
157
|
+
_args2 = arguments;
|
|
158
|
+
return _regenerator["default"].wrap(function (_context2) {
|
|
159
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
160
|
+
case 0:
|
|
161
|
+
for (_len3 = _args2.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
162
|
+
args[_key3] = _args2[_key3];
|
|
163
|
+
}
|
|
164
|
+
url = args === null || args === void 0 ? void 0 : args[0];
|
|
165
|
+
track = is3dAssetUrl(url);
|
|
166
|
+
if (track) {
|
|
167
|
+
_context2.next = 1;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
return _context2.abrupt("return", g.originalFetch.apply(this, args));
|
|
171
|
+
case 1:
|
|
172
|
+
g.inFlight += 1;
|
|
173
|
+
notify();
|
|
174
|
+
_context2.prev = 2;
|
|
175
|
+
_context2.next = 3;
|
|
176
|
+
return g.originalFetch.apply(this, args);
|
|
177
|
+
case 3:
|
|
178
|
+
return _context2.abrupt("return", _context2.sent);
|
|
179
|
+
case 4:
|
|
180
|
+
_context2.prev = 4;
|
|
181
|
+
g.inFlight -= 1;
|
|
182
|
+
if (g.inFlight < 0) g.inFlight = 0;
|
|
183
|
+
notify();
|
|
184
|
+
return _context2.finish(4);
|
|
185
|
+
case 5:
|
|
186
|
+
case "end":
|
|
187
|
+
return _context2.stop();
|
|
188
|
+
}
|
|
189
|
+
}, _callee2, this, [[2,, 4, 5]]);
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
g.installed = true;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// “No grace” but stable: idle must remain idle for 2 RAF frames
|
|
196
|
+
function waitStableIdle2Frames() {
|
|
197
|
+
return _waitStableIdle2Frames.apply(this, arguments);
|
|
198
|
+
}
|
|
199
|
+
function _waitStableIdle2Frames() {
|
|
200
|
+
_waitStableIdle2Frames = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5() {
|
|
201
|
+
return _regenerator["default"].wrap(function (_context5) {
|
|
202
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
203
|
+
case 0:
|
|
204
|
+
_context5.next = 1;
|
|
205
|
+
return nextFrame();
|
|
206
|
+
case 1:
|
|
207
|
+
if (!(g.inFlight !== 0)) {
|
|
208
|
+
_context5.next = 2;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
return _context5.abrupt("return", false);
|
|
212
|
+
case 2:
|
|
213
|
+
_context5.next = 3;
|
|
214
|
+
return nextFrame();
|
|
215
|
+
case 3:
|
|
216
|
+
return _context5.abrupt("return", g.inFlight === 0);
|
|
217
|
+
case 4:
|
|
218
|
+
case "end":
|
|
219
|
+
return _context5.stop();
|
|
220
|
+
}
|
|
221
|
+
}, _callee5);
|
|
222
|
+
}));
|
|
223
|
+
return _waitStableIdle2Frames.apply(this, arguments);
|
|
224
|
+
}
|
|
225
|
+
var waitForIdle = /*#__PURE__*/function () {
|
|
226
|
+
var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
227
|
+
var _ref3,
|
|
228
|
+
_ref3$timeoutMs,
|
|
229
|
+
timeoutMs,
|
|
230
|
+
start,
|
|
231
|
+
_args4 = arguments;
|
|
232
|
+
return _regenerator["default"].wrap(function (_context4) {
|
|
233
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
234
|
+
case 0:
|
|
235
|
+
_ref3 = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, _ref3$timeoutMs = _ref3.timeoutMs, timeoutMs = _ref3$timeoutMs === void 0 ? 30000 : _ref3$timeoutMs;
|
|
236
|
+
start = Date.now();
|
|
237
|
+
_context4.next = 1;
|
|
238
|
+
return waitStableIdle2Frames();
|
|
239
|
+
case 1:
|
|
240
|
+
if (!_context4.sent) {
|
|
241
|
+
_context4.next = 2;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
return _context4.abrupt("return", true);
|
|
245
|
+
case 2:
|
|
246
|
+
return _context4.abrupt("return", new Promise(function (resolve, reject) {
|
|
247
|
+
var unsub = null;
|
|
248
|
+
var onChange = /*#__PURE__*/function () {
|
|
249
|
+
var _ref4 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(count) {
|
|
250
|
+
var stable;
|
|
251
|
+
return _regenerator["default"].wrap(function (_context3) {
|
|
252
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
253
|
+
case 0:
|
|
254
|
+
if (!(count !== 0)) {
|
|
255
|
+
_context3.next = 1;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
if (Date.now() - start > timeoutMs) {
|
|
259
|
+
if (unsub) unsub();
|
|
260
|
+
reject(new Error('3D assets did not become idle within timeout'));
|
|
261
|
+
}
|
|
262
|
+
return _context3.abrupt("return");
|
|
263
|
+
case 1:
|
|
264
|
+
_context3.next = 2;
|
|
265
|
+
return waitStableIdle2Frames();
|
|
266
|
+
case 2:
|
|
267
|
+
stable = _context3.sent;
|
|
268
|
+
if (!stable) {
|
|
269
|
+
_context3.next = 3;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
if (unsub) unsub();
|
|
273
|
+
resolve(true);
|
|
274
|
+
return _context3.abrupt("return");
|
|
275
|
+
case 3:
|
|
276
|
+
if (Date.now() - start > timeoutMs) {
|
|
277
|
+
if (unsub) unsub();
|
|
278
|
+
reject(new Error('3D assets did not become idle within timeout'));
|
|
279
|
+
}
|
|
280
|
+
case 4:
|
|
281
|
+
case "end":
|
|
282
|
+
return _context3.stop();
|
|
283
|
+
}
|
|
284
|
+
}, _callee3);
|
|
285
|
+
}));
|
|
286
|
+
return function onChange(_x) {
|
|
287
|
+
return _ref4.apply(this, arguments);
|
|
288
|
+
};
|
|
289
|
+
}();
|
|
290
|
+
unsub = subscribe(onChange);
|
|
291
|
+
}));
|
|
292
|
+
case 3:
|
|
293
|
+
case "end":
|
|
294
|
+
return _context4.stop();
|
|
295
|
+
}
|
|
296
|
+
}, _callee4);
|
|
297
|
+
}));
|
|
298
|
+
return function waitForIdle() {
|
|
299
|
+
return _ref2.apply(this, arguments);
|
|
300
|
+
};
|
|
301
|
+
}();
|
|
302
|
+
var uninstall = function uninstall() {
|
|
303
|
+
var _XHR$prototype3, _XHR$prototype4;
|
|
304
|
+
g.refCount -= 1;
|
|
305
|
+
if (g.refCount > 0) return;
|
|
306
|
+
var XHR = window.XMLHttpRequest;
|
|
307
|
+
if (XHR !== null && XHR !== void 0 && (_XHR$prototype3 = XHR.prototype) !== null && _XHR$prototype3 !== void 0 && _XHR$prototype3.open && g.originalOpen) XHR.prototype.open = g.originalOpen;
|
|
308
|
+
if (XHR !== null && XHR !== void 0 && (_XHR$prototype4 = XHR.prototype) !== null && _XHR$prototype4 !== void 0 && _XHR$prototype4.send && g.originalSend) XHR.prototype.send = g.originalSend;
|
|
309
|
+
if (typeof g.originalFetch === 'function') window.fetch = g.originalFetch;
|
|
310
|
+
g.listeners.clear();
|
|
311
|
+
g.inFlight = 0;
|
|
312
|
+
g.installed = false;
|
|
313
|
+
g.originalFetch = null;
|
|
314
|
+
g.originalOpen = null;
|
|
315
|
+
g.originalSend = null;
|
|
316
|
+
};
|
|
317
|
+
g.refCount += 1;
|
|
318
|
+
installIfNeeded();
|
|
319
|
+
return {
|
|
320
|
+
getInFlight: function getInFlight() {
|
|
321
|
+
return g.inFlight;
|
|
322
|
+
},
|
|
323
|
+
waitForIdle: waitForIdle,
|
|
324
|
+
uninstall: uninstall,
|
|
325
|
+
subscribe: subscribe
|
|
326
|
+
};
|
|
327
|
+
}
|
|
24
328
|
function renderKitchenSimulator(container) {
|
|
329
|
+
var _props$framesPerEvent, _props$waitForGltfIdl, _props$gltfTimeoutMs;
|
|
25
330
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
26
|
-
|
|
27
|
-
|
|
331
|
+
if (!container) throw new Error('renderKitchenSimulator: container is required');
|
|
332
|
+
|
|
333
|
+
// ✅ Reuse existing API
|
|
334
|
+
if (container[API_KEY]) {
|
|
335
|
+
var _container$API_KEY$__, _container$API_KEY;
|
|
336
|
+
(_container$API_KEY$__ = (_container$API_KEY = container[API_KEY]).__render) === null || _container$API_KEY$__ === void 0 || _container$API_KEY$__.call(_container$API_KEY, props);
|
|
337
|
+
return container[API_KEY];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ✅ Reuse root
|
|
341
|
+
var root = container[ROOT_KEY];
|
|
342
|
+
if (!root) {
|
|
343
|
+
root = (0, _client.createRoot)(container);
|
|
344
|
+
container[ROOT_KEY] = root;
|
|
345
|
+
}
|
|
346
|
+
var setExternalEventFn = null;
|
|
347
|
+
var destroyed = false;
|
|
348
|
+
var queue = [];
|
|
349
|
+
var pendingMarkers = new Set();
|
|
350
|
+
var MARKER = Symbol('marker');
|
|
351
|
+
var gltfTracker = installGltfTracker();
|
|
352
|
+
|
|
353
|
+
// FAST defaults (safe)
|
|
354
|
+
var defaultFramesPerEvent = (_props$framesPerEvent = props.framesPerEvent) !== null && _props$framesPerEvent !== void 0 ? _props$framesPerEvent : 1;
|
|
355
|
+
var waitForAssets = (_props$waitForGltfIdl = props.waitForGltfIdleAfterEachEvent) !== null && _props$waitForGltfIdl !== void 0 ? _props$waitForGltfIdl : true;
|
|
356
|
+
var defaultTimeout = (_props$gltfTimeoutMs = props.gltfTimeoutMs) !== null && _props$gltfTimeoutMs !== void 0 ? _props$gltfTimeoutMs : 30000;
|
|
357
|
+
|
|
358
|
+
// If you want ultra-fast UI responsiveness, you can disable waiting per-event
|
|
359
|
+
// and only wait on “important” events, see comment in settle() below.
|
|
360
|
+
|
|
361
|
+
var draining = false;
|
|
362
|
+
function isSyncScene(ev) {
|
|
363
|
+
var _ev$payload;
|
|
364
|
+
return (ev === null || ev === void 0 ? void 0 : ev.type) === 'EXTERNAL_EVENT_SYNC_SCENE' || (ev === null || ev === void 0 || (_ev$payload = ev.payload) === null || _ev$payload === void 0 ? void 0 : _ev$payload.mode) === 'sync-scene' || (ev === null || ev === void 0 ? void 0 : ev.__sync) === true;
|
|
365
|
+
}
|
|
366
|
+
function settle(_x2) {
|
|
367
|
+
return _settle.apply(this, arguments);
|
|
368
|
+
}
|
|
369
|
+
function _settle() {
|
|
370
|
+
_settle = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(ev) {
|
|
371
|
+
var _ev$framesPerEvent, _ev$waitForGltfIdleAf;
|
|
372
|
+
var frames, i, shouldWait, _ev$gltfTimeoutMs, timeoutMs;
|
|
373
|
+
return _regenerator["default"].wrap(function (_context7) {
|
|
374
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
375
|
+
case 0:
|
|
376
|
+
frames = (_ev$framesPerEvent = ev === null || ev === void 0 ? void 0 : ev.framesPerEvent) !== null && _ev$framesPerEvent !== void 0 ? _ev$framesPerEvent : defaultFramesPerEvent; // (1) allow react/reducers to run (fixes “must zoom to see updates”)
|
|
377
|
+
i = 0;
|
|
378
|
+
case 1:
|
|
379
|
+
if (!(i < frames)) {
|
|
380
|
+
_context7.next = 3;
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
_context7.next = 2;
|
|
384
|
+
return nextFrame();
|
|
385
|
+
case 2:
|
|
386
|
+
i += 1;
|
|
387
|
+
_context7.next = 1;
|
|
388
|
+
break;
|
|
389
|
+
case 3:
|
|
390
|
+
// (2) optionally wait for assets
|
|
391
|
+
// fastest safe approach: keep ON for events that add/replace/load models
|
|
392
|
+
// You can override per-event via ev.waitForGltfIdleAfterEachEvent = false
|
|
393
|
+
shouldWait = (_ev$waitForGltfIdleAf = ev === null || ev === void 0 ? void 0 : ev.waitForGltfIdleAfterEachEvent) !== null && _ev$waitForGltfIdleAf !== void 0 ? _ev$waitForGltfIdleAf : waitForAssets;
|
|
394
|
+
if (!shouldWait) {
|
|
395
|
+
_context7.next = 4;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
timeoutMs = (_ev$gltfTimeoutMs = ev === null || ev === void 0 ? void 0 : ev.gltfTimeoutMs) !== null && _ev$gltfTimeoutMs !== void 0 ? _ev$gltfTimeoutMs : defaultTimeout;
|
|
399
|
+
_context7.next = 4;
|
|
400
|
+
return gltfTracker.waitForIdle({
|
|
401
|
+
timeoutMs: timeoutMs
|
|
402
|
+
});
|
|
403
|
+
case 4:
|
|
404
|
+
_context7.next = 5;
|
|
405
|
+
return nextFrame();
|
|
406
|
+
case 5:
|
|
407
|
+
if (!isSyncScene(ev)) {
|
|
408
|
+
_context7.next = 6;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
_context7.next = 6;
|
|
412
|
+
return nextFrame();
|
|
413
|
+
case 6:
|
|
414
|
+
case "end":
|
|
415
|
+
return _context7.stop();
|
|
416
|
+
}
|
|
417
|
+
}, _callee7);
|
|
418
|
+
}));
|
|
419
|
+
return _settle.apply(this, arguments);
|
|
420
|
+
}
|
|
421
|
+
function drain() {
|
|
422
|
+
return _drain.apply(this, arguments);
|
|
423
|
+
}
|
|
424
|
+
function _drain() {
|
|
425
|
+
_drain = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8() {
|
|
426
|
+
var item;
|
|
427
|
+
return _regenerator["default"].wrap(function (_context8) {
|
|
428
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
429
|
+
case 0:
|
|
430
|
+
if (!(draining || destroyed)) {
|
|
431
|
+
_context8.next = 1;
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
return _context8.abrupt("return");
|
|
435
|
+
case 1:
|
|
436
|
+
draining = true;
|
|
437
|
+
_context8.prev = 2;
|
|
438
|
+
case 3:
|
|
439
|
+
if (!(!destroyed && queue.length)) {
|
|
440
|
+
_context8.next = 8;
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
if (setExternalEventFn) {
|
|
444
|
+
_context8.next = 5;
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
_context8.next = 4;
|
|
448
|
+
return nextFrame();
|
|
449
|
+
case 4:
|
|
450
|
+
return _context8.abrupt("continue", 3);
|
|
451
|
+
case 5:
|
|
452
|
+
item = queue.shift();
|
|
453
|
+
if (!(item && item.__marker === MARKER)) {
|
|
454
|
+
_context8.next = 6;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
pendingMarkers["delete"](item.token);
|
|
458
|
+
return _context8.abrupt("continue", 3);
|
|
459
|
+
case 6:
|
|
460
|
+
setExternalEventFn(item);
|
|
461
|
+
_context8.next = 7;
|
|
462
|
+
return settle(item);
|
|
463
|
+
case 7:
|
|
464
|
+
_context8.next = 3;
|
|
465
|
+
break;
|
|
466
|
+
case 8:
|
|
467
|
+
_context8.prev = 8;
|
|
468
|
+
draining = false;
|
|
469
|
+
return _context8.finish(8);
|
|
470
|
+
case 9:
|
|
471
|
+
case "end":
|
|
472
|
+
return _context8.stop();
|
|
473
|
+
}
|
|
474
|
+
}, _callee8, null, [[2,, 8, 9]]);
|
|
475
|
+
}));
|
|
476
|
+
return _drain.apply(this, arguments);
|
|
477
|
+
}
|
|
28
478
|
var Wrapper = /*#__PURE__*/function (_React$Component) {
|
|
29
479
|
function Wrapper(p) {
|
|
30
|
-
var
|
|
480
|
+
var _this2;
|
|
31
481
|
(0, _classCallCheck2["default"])(this, Wrapper);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (eventId === _this._currentId) {
|
|
36
|
-
var _this$_currentResolve, _this2;
|
|
37
|
-
(_this$_currentResolve = (_this2 = _this)._currentResolve) === null || _this$_currentResolve === void 0 || _this$_currentResolve.call(_this2);
|
|
38
|
-
_this._currentResolve = null;
|
|
39
|
-
_this._currentId = null;
|
|
40
|
-
_this.processing = false;
|
|
41
|
-
_this.processNext();
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
_this.state = {
|
|
45
|
-
externalEvent: null
|
|
46
|
-
};
|
|
47
|
-
_this.queue = [];
|
|
48
|
-
_this.processing = false;
|
|
49
|
-
apiRef = {
|
|
50
|
-
enqueueExternalEvent: function enqueueExternalEvent(ev) {
|
|
51
|
-
return _this.enqueue(ev);
|
|
52
|
-
}
|
|
482
|
+
_this2 = _callSuper(this, Wrapper, [p]);
|
|
483
|
+
_this2.state = {
|
|
484
|
+
externalEvent: p.externalEvent || null
|
|
53
485
|
};
|
|
54
|
-
|
|
486
|
+
_this2._mounted = false;
|
|
487
|
+
return _this2;
|
|
55
488
|
}
|
|
56
489
|
(0, _inherits2["default"])(Wrapper, _React$Component);
|
|
57
490
|
return (0, _createClass2["default"])(Wrapper, [{
|
|
58
|
-
key: "
|
|
59
|
-
value: function
|
|
60
|
-
if (!ev) return Promise.resolve();
|
|
61
|
-
var id = ++idSeq;
|
|
62
|
-
var resolve;
|
|
63
|
-
var promise = new Promise(function (res) {
|
|
64
|
-
return resolve = res;
|
|
65
|
-
});
|
|
66
|
-
this.queue.push({
|
|
67
|
-
id: id,
|
|
68
|
-
ev: ev,
|
|
69
|
-
resolve: resolve
|
|
70
|
-
});
|
|
71
|
-
if (!this.processing) this.processNext();
|
|
72
|
-
return promise;
|
|
73
|
-
}
|
|
74
|
-
}, {
|
|
75
|
-
key: "processNext",
|
|
76
|
-
value: function processNext() {
|
|
491
|
+
key: "componentDidMount",
|
|
492
|
+
value: function componentDidMount() {
|
|
77
493
|
var _this3 = this;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
this.processing = true;
|
|
84
|
-
|
|
85
|
-
// IMPORTANT: set an ID so LiteRenderer can ack it
|
|
86
|
-
var payload = _objectSpread(_objectSpread({}, next.ev), {}, {
|
|
87
|
-
__eventId: next.id
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Clear then set (edge trigger), but no timers needed.
|
|
91
|
-
this.setState({
|
|
92
|
-
externalEvent: null
|
|
93
|
-
}, function () {
|
|
94
|
-
_this3._currentResolve = next.resolve;
|
|
95
|
-
_this3._currentId = next.id;
|
|
494
|
+
this._mounted = true;
|
|
495
|
+
setExternalEventFn = function setExternalEventFn(newEvent) {
|
|
496
|
+
if (!_this3._mounted) return;
|
|
96
497
|
_this3.setState({
|
|
97
|
-
externalEvent:
|
|
498
|
+
externalEvent: newEvent
|
|
98
499
|
});
|
|
99
|
-
}
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
}, {
|
|
503
|
+
key: "componentWillUnmount",
|
|
504
|
+
value: function componentWillUnmount() {
|
|
505
|
+
this._mounted = false;
|
|
506
|
+
setExternalEventFn = null;
|
|
100
507
|
}
|
|
101
508
|
}, {
|
|
102
509
|
key: "render",
|
|
103
510
|
value: function render() {
|
|
104
511
|
return /*#__PURE__*/_react["default"].createElement(_LiteRenderer["default"], (0, _extends2["default"])({}, this.props, {
|
|
105
|
-
externalEvent: this.state.externalEvent
|
|
106
|
-
onExternalEventProcessed: this.onExternalEventProcessed
|
|
512
|
+
externalEvent: this.state.externalEvent
|
|
107
513
|
}));
|
|
108
514
|
}
|
|
109
515
|
}]);
|
|
110
516
|
}(_react["default"].Component);
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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();
|
|
517
|
+
var api = {
|
|
518
|
+
__render: function __render(nextProps) {
|
|
519
|
+
root.render(/*#__PURE__*/_react["default"].createElement(Wrapper, nextProps));
|
|
520
|
+
},
|
|
521
|
+
// ✅ host can query current inFlight
|
|
522
|
+
getGltfInFlight: function getGltfInFlight() {
|
|
523
|
+
return gltfTracker.getInFlight();
|
|
121
524
|
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
525
|
+
// ✅ host can subscribe to inFlight changes (loader)
|
|
526
|
+
subscribeGltfInFlight: function subscribeGltfInFlight(cb) {
|
|
527
|
+
return gltfTracker.subscribe(cb);
|
|
528
|
+
},
|
|
529
|
+
sendExternalEvents: function sendExternalEvents(eventOrEvents) {
|
|
530
|
+
var events = Array.isArray(eventOrEvents) ? eventOrEvents : [eventOrEvents];
|
|
531
|
+
var _iterator2 = _createForOfIteratorHelper(events),
|
|
532
|
+
_step2;
|
|
533
|
+
try {
|
|
534
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
535
|
+
var e = _step2.value;
|
|
536
|
+
queue.push(e);
|
|
537
|
+
}
|
|
538
|
+
} catch (err) {
|
|
539
|
+
_iterator2.e(err);
|
|
540
|
+
} finally {
|
|
541
|
+
_iterator2.f();
|
|
542
|
+
}
|
|
543
|
+
var token = Symbol('batch');
|
|
544
|
+
pendingMarkers.add(token);
|
|
545
|
+
queue.push({
|
|
546
|
+
__marker: MARKER,
|
|
547
|
+
token: token
|
|
548
|
+
});
|
|
549
|
+
drain();
|
|
550
|
+
|
|
551
|
+
// resolve when marker cleared
|
|
552
|
+
return new Promise(function (resolve) {
|
|
553
|
+
var check = /*#__PURE__*/function () {
|
|
554
|
+
var _ref5 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
|
|
555
|
+
return _regenerator["default"].wrap(function (_context6) {
|
|
556
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
557
|
+
case 0:
|
|
558
|
+
if (destroyed) {
|
|
559
|
+
_context6.next = 3;
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
if (!pendingMarkers.has(token)) {
|
|
563
|
+
_context6.next = 2;
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
_context6.next = 1;
|
|
567
|
+
return nextFrame();
|
|
568
|
+
case 1:
|
|
569
|
+
return _context6.abrupt("continue", 0);
|
|
570
|
+
case 2:
|
|
571
|
+
resolve(true);
|
|
572
|
+
return _context6.abrupt("return");
|
|
573
|
+
case 3:
|
|
574
|
+
resolve(false);
|
|
575
|
+
case 4:
|
|
576
|
+
case "end":
|
|
577
|
+
return _context6.stop();
|
|
578
|
+
}
|
|
579
|
+
}, _callee6);
|
|
580
|
+
}));
|
|
581
|
+
return function check() {
|
|
582
|
+
return _ref5.apply(this, arguments);
|
|
583
|
+
};
|
|
584
|
+
}();
|
|
585
|
+
check();
|
|
586
|
+
});
|
|
587
|
+
},
|
|
588
|
+
updateExternalEvent: function updateExternalEvent(e) {
|
|
589
|
+
return api.sendExternalEvents(e);
|
|
590
|
+
},
|
|
591
|
+
clearQueue: function clearQueue() {
|
|
592
|
+
queue.length = 0;
|
|
593
|
+
pendingMarkers.clear();
|
|
125
594
|
},
|
|
126
595
|
unmount: function unmount() {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
596
|
+
destroyed = true;
|
|
597
|
+
api.clearQueue();
|
|
598
|
+
gltfTracker.uninstall();
|
|
599
|
+
var doUnmount = function doUnmount() {
|
|
600
|
+
try {
|
|
601
|
+
root.unmount();
|
|
602
|
+
} finally {
|
|
603
|
+
container[ROOT_KEY] = null;
|
|
604
|
+
container[API_KEY] = null;
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
if (typeof queueMicrotask === 'function') queueMicrotask(doUnmount);else setTimeout(doUnmount, 0);
|
|
131
608
|
}
|
|
132
609
|
};
|
|
610
|
+
api.__render(props);
|
|
611
|
+
container[API_KEY] = api;
|
|
612
|
+
return api;
|
|
133
613
|
}
|
|
134
614
|
var _default = exports["default"] = renderKitchenSimulator;
|