kitchen-simulator 5.10.14-react.18 → 6.0.2-react.18
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 +59 -124
- package/es/LiteRenderer.js +1 -0
- package/es/actions/viewer2d-actions.js +1 -7
- package/es/constants.js +0 -1
- package/es/index.js +151 -695
- package/es/reducers/viewer2d-reducer.js +1 -9
- package/package.json +1 -1
package/es/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
3
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
@@ -7,18 +6,17 @@ import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
|
7
6
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
8
7
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
9
8
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
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; }
|
|
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 _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
13
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
14
9
|
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; } } }; }
|
|
15
10
|
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; } }
|
|
16
11
|
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; }
|
|
17
12
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
13
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
14
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
15
|
+
// kitchen-simulator/index.js (or wherever renderKitchenSimulator lives)
|
|
18
16
|
import React from 'react';
|
|
19
|
-
import * as Three from 'three';
|
|
20
|
-
import LiteRenderer from "./LiteRenderer";
|
|
21
17
|
import { createRoot } from 'react-dom/client';
|
|
18
|
+
import LiteRenderer from "./LiteRenderer";
|
|
19
|
+
import * as Three from 'three';
|
|
22
20
|
var ROOT_KEY = '__kitchenSimulatorRoot__';
|
|
23
21
|
var API_KEY = '__kitchenSimulatorApi__';
|
|
24
22
|
function makeLogger(getEnabled) {
|
|
@@ -71,7 +69,7 @@ function makeLogger(getEnabled) {
|
|
|
71
69
|
};
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
//
|
|
72
|
+
// ---- Your URL rewrite + TextureLoader patch stays as you had it ----
|
|
75
73
|
var API_HOST_REGEX = /(https?:\/\/)?(api\.diydesignspace\.com|api\.addovisuals\.com|127\.0\.0\.1:4002)/;
|
|
76
74
|
var API_HOST_REPLACEMENT = 'https://api-old.diydesignspace.com';
|
|
77
75
|
function rewriteApiUrl(url) {
|
|
@@ -83,441 +81,22 @@ Three.TextureLoader.prototype.load = function (url, onLoad, onProgress, onError)
|
|
|
83
81
|
return originalTextureLoad.call(this, newUrl, onLoad, onProgress, onError);
|
|
84
82
|
};
|
|
85
83
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*/
|
|
90
|
-
function installGltfTracker() {
|
|
91
|
-
var debug = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
92
|
-
if (typeof window === 'undefined') {
|
|
93
|
-
var _subscribe = function _subscribe() {
|
|
94
|
-
return function () {};
|
|
95
|
-
};
|
|
96
|
-
return {
|
|
97
|
-
getInFlight: function getInFlight() {
|
|
98
|
-
return 0;
|
|
99
|
-
},
|
|
100
|
-
waitForIdle: function () {
|
|
101
|
-
var _waitForIdle = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
102
|
-
return _regeneratorRuntime.wrap(function (_context) {
|
|
103
|
-
while (1) switch (_context.prev = _context.next) {
|
|
104
|
-
case 0:
|
|
105
|
-
return _context.abrupt("return", true);
|
|
106
|
-
case 1:
|
|
107
|
-
case "end":
|
|
108
|
-
return _context.stop();
|
|
109
|
-
}
|
|
110
|
-
}, _callee);
|
|
111
|
-
}));
|
|
112
|
-
function waitForIdle() {
|
|
113
|
-
return _waitForIdle.apply(this, arguments);
|
|
114
|
-
}
|
|
115
|
-
return waitForIdle;
|
|
116
|
-
}(),
|
|
117
|
-
uninstall: function uninstall() {},
|
|
118
|
-
subscribe: _subscribe
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
var GLOBAL_KEY = '__kitchenSimulatorGltfTracker__';
|
|
122
|
-
var TRACKER_DEBUG_KEY = '__kitchenSimulatorDebug__';
|
|
123
|
-
if (!window[GLOBAL_KEY]) {
|
|
124
|
-
window[GLOBAL_KEY] = {
|
|
125
|
-
refCount: 0,
|
|
126
|
-
inFlight: 0,
|
|
127
|
-
listeners: new Set(),
|
|
128
|
-
installed: false,
|
|
129
|
-
originalFetch: null,
|
|
130
|
-
originalOpen: null,
|
|
131
|
-
originalSend: null
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
var g = window[GLOBAL_KEY];
|
|
135
|
-
var isDebug = function isDebug() {
|
|
136
|
-
return !!debug || !!window[TRACKER_DEBUG_KEY];
|
|
137
|
-
};
|
|
138
|
-
var _makeLogger = makeLogger(isDebug, '[kitchen-simulator:gltf]'),
|
|
139
|
-
log = _makeLogger.log,
|
|
140
|
-
warn = _makeLogger.warn,
|
|
141
|
-
error = _makeLogger.error;
|
|
142
|
-
var is3dAssetUrl = function is3dAssetUrl(url) {
|
|
143
|
-
try {
|
|
144
|
-
var _url$toString, _url$toString2;
|
|
145
|
-
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 : '';
|
|
146
|
-
var u = s.toLowerCase().split('?')[0];
|
|
147
|
-
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');
|
|
148
|
-
} catch (_unused2) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
var notify = function notify() {
|
|
153
|
-
var _iterator = _createForOfIteratorHelper(g.listeners),
|
|
154
|
-
_step;
|
|
155
|
-
try {
|
|
156
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
157
|
-
var fn = _step.value;
|
|
158
|
-
fn(g.inFlight);
|
|
159
|
-
}
|
|
160
|
-
} catch (err) {
|
|
161
|
-
_iterator.e(err);
|
|
162
|
-
} finally {
|
|
163
|
-
_iterator.f();
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
var subscribe = function subscribe(fn) {
|
|
167
|
-
g.listeners.add(fn);
|
|
168
|
-
fn(g.inFlight);
|
|
169
|
-
return function () {
|
|
170
|
-
return g.listeners["delete"](fn);
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
var installIfNeeded = function installIfNeeded() {
|
|
174
|
-
var _XHR$prototype, _XHR$prototype2;
|
|
175
|
-
if (g.installed) return;
|
|
176
|
-
log('Installing GLTF tracker hooks');
|
|
84
|
+
// ---- keep your installGltfTracker exactly as you have it ----
|
|
85
|
+
// import / paste your installGltfTracker(debug) here
|
|
86
|
+
// (omitted in this snippet for brevity)
|
|
177
87
|
|
|
178
|
-
// XHR hook
|
|
179
|
-
var XHR = window.XMLHttpRequest;
|
|
180
|
-
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) {
|
|
181
|
-
g.originalOpen = XHR.prototype.open;
|
|
182
|
-
g.originalSend = XHR.prototype.send;
|
|
183
|
-
XHR.prototype.open = function (method, url) {
|
|
184
|
-
var _g$originalOpen;
|
|
185
|
-
this.__is3dAssetRequest = is3dAssetUrl(url);
|
|
186
|
-
if (this.__is3dAssetRequest) log('XHR open (3D asset)', {
|
|
187
|
-
method: method,
|
|
188
|
-
url: url
|
|
189
|
-
});
|
|
190
|
-
for (var _len4 = arguments.length, rest = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
|
|
191
|
-
rest[_key4 - 2] = arguments[_key4];
|
|
192
|
-
}
|
|
193
|
-
return (_g$originalOpen = g.originalOpen).call.apply(_g$originalOpen, [this, method, url].concat(rest));
|
|
194
|
-
};
|
|
195
|
-
XHR.prototype.send = function () {
|
|
196
|
-
var _this = this;
|
|
197
|
-
if (this.__is3dAssetRequest) {
|
|
198
|
-
g.inFlight += 1;
|
|
199
|
-
log('XHR send -> inFlight++', g.inFlight);
|
|
200
|
-
notify();
|
|
201
|
-
var _done = function done() {
|
|
202
|
-
g.inFlight -= 1;
|
|
203
|
-
if (g.inFlight < 0) g.inFlight = 0;
|
|
204
|
-
log('XHR done -> inFlight--', g.inFlight);
|
|
205
|
-
notify();
|
|
206
|
-
_this.removeEventListener('loadend', _done);
|
|
207
|
-
_this.removeEventListener('error', _done);
|
|
208
|
-
_this.removeEventListener('abort', _done);
|
|
209
|
-
_this.removeEventListener('timeout', _done);
|
|
210
|
-
};
|
|
211
|
-
this.addEventListener('loadend', _done);
|
|
212
|
-
this.addEventListener('error', _done);
|
|
213
|
-
this.addEventListener('abort', _done);
|
|
214
|
-
this.addEventListener('timeout', _done);
|
|
215
|
-
}
|
|
216
|
-
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
217
|
-
args[_key5] = arguments[_key5];
|
|
218
|
-
}
|
|
219
|
-
return g.originalSend.apply(this, args);
|
|
220
|
-
};
|
|
221
|
-
} else {
|
|
222
|
-
warn('XHR hooks not installed (missing open/send)');
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// fetch hook
|
|
226
|
-
g.originalFetch = window.fetch;
|
|
227
|
-
if (typeof g.originalFetch === 'function') {
|
|
228
|
-
window.fetch = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
229
|
-
var _input;
|
|
230
|
-
var _len6,
|
|
231
|
-
args,
|
|
232
|
-
_key6,
|
|
233
|
-
input,
|
|
234
|
-
init,
|
|
235
|
-
newUrl,
|
|
236
|
-
track,
|
|
237
|
-
_input2,
|
|
238
|
-
res,
|
|
239
|
-
_input3,
|
|
240
|
-
_e$message,
|
|
241
|
-
_args2 = arguments,
|
|
242
|
-
_t;
|
|
243
|
-
return _regeneratorRuntime.wrap(function (_context2) {
|
|
244
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
245
|
-
case 0:
|
|
246
|
-
for (_len6 = _args2.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
247
|
-
args[_key6] = _args2[_key6];
|
|
248
|
-
}
|
|
249
|
-
input = args[0], init = args[1];
|
|
250
|
-
if (typeof input === 'string') {
|
|
251
|
-
input = rewriteApiUrl(input);
|
|
252
|
-
} else if (input instanceof Request) {
|
|
253
|
-
newUrl = rewriteApiUrl(input.url);
|
|
254
|
-
input = new Request(newUrl, input);
|
|
255
|
-
}
|
|
256
|
-
track = is3dAssetUrl(input);
|
|
257
|
-
if (track) {
|
|
258
|
-
_context2.next = 1;
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
return _context2.abrupt("return", g.originalFetch.call(this, input, init));
|
|
262
|
-
case 1:
|
|
263
|
-
g.inFlight += 1;
|
|
264
|
-
log('fetch (3D asset) -> inFlight++', g.inFlight, {
|
|
265
|
-
url: typeof input === 'string' ? input : (_input = input) === null || _input === void 0 ? void 0 : _input.url
|
|
266
|
-
});
|
|
267
|
-
notify();
|
|
268
|
-
_context2.prev = 2;
|
|
269
|
-
_context2.next = 3;
|
|
270
|
-
return g.originalFetch.call(this, input, init);
|
|
271
|
-
case 3:
|
|
272
|
-
res = _context2.sent;
|
|
273
|
-
log('fetch response (3D asset)', {
|
|
274
|
-
url: typeof input === 'string' ? input : (_input2 = input) === null || _input2 === void 0 ? void 0 : _input2.url,
|
|
275
|
-
ok: res === null || res === void 0 ? void 0 : res.ok,
|
|
276
|
-
status: res === null || res === void 0 ? void 0 : res.status
|
|
277
|
-
});
|
|
278
|
-
return _context2.abrupt("return", res);
|
|
279
|
-
case 4:
|
|
280
|
-
_context2.prev = 4;
|
|
281
|
-
_t = _context2["catch"](2);
|
|
282
|
-
error('fetch error (3D asset)', {
|
|
283
|
-
url: typeof input === 'string' ? input : (_input3 = input) === null || _input3 === void 0 ? void 0 : _input3.url,
|
|
284
|
-
error: (_e$message = _t === null || _t === void 0 ? void 0 : _t.message) !== null && _e$message !== void 0 ? _e$message : _t
|
|
285
|
-
});
|
|
286
|
-
throw _t;
|
|
287
|
-
case 5:
|
|
288
|
-
_context2.prev = 5;
|
|
289
|
-
g.inFlight -= 1;
|
|
290
|
-
if (g.inFlight < 0) g.inFlight = 0;
|
|
291
|
-
log('fetch finally -> inFlight--', g.inFlight);
|
|
292
|
-
notify();
|
|
293
|
-
return _context2.finish(5);
|
|
294
|
-
case 6:
|
|
295
|
-
case "end":
|
|
296
|
-
return _context2.stop();
|
|
297
|
-
}
|
|
298
|
-
}, _callee2, this, [[2, 4, 5, 6]]);
|
|
299
|
-
}));
|
|
300
|
-
} else {
|
|
301
|
-
warn('fetch hook not installed (window.fetch not a function)');
|
|
302
|
-
}
|
|
303
|
-
g.installed = true;
|
|
304
|
-
};
|
|
305
|
-
function nextFrame() {
|
|
306
|
-
return _nextFrame.apply(this, arguments);
|
|
307
|
-
}
|
|
308
|
-
function _nextFrame() {
|
|
309
|
-
_nextFrame = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
310
|
-
return _regeneratorRuntime.wrap(function (_context5) {
|
|
311
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
312
|
-
case 0:
|
|
313
|
-
return _context5.abrupt("return", new Promise(function (resolve) {
|
|
314
|
-
return requestAnimationFrame(resolve);
|
|
315
|
-
}));
|
|
316
|
-
case 1:
|
|
317
|
-
case "end":
|
|
318
|
-
return _context5.stop();
|
|
319
|
-
}
|
|
320
|
-
}, _callee5);
|
|
321
|
-
}));
|
|
322
|
-
return _nextFrame.apply(this, arguments);
|
|
323
|
-
}
|
|
324
|
-
function waitStableIdle2Frames() {
|
|
325
|
-
return _waitStableIdle2Frames.apply(this, arguments);
|
|
326
|
-
}
|
|
327
|
-
function _waitStableIdle2Frames() {
|
|
328
|
-
_waitStableIdle2Frames = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
329
|
-
return _regeneratorRuntime.wrap(function (_context6) {
|
|
330
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
331
|
-
case 0:
|
|
332
|
-
_context6.next = 1;
|
|
333
|
-
return nextFrame();
|
|
334
|
-
case 1:
|
|
335
|
-
if (!(g.inFlight !== 0)) {
|
|
336
|
-
_context6.next = 2;
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
return _context6.abrupt("return", false);
|
|
340
|
-
case 2:
|
|
341
|
-
_context6.next = 3;
|
|
342
|
-
return nextFrame();
|
|
343
|
-
case 3:
|
|
344
|
-
return _context6.abrupt("return", g.inFlight === 0);
|
|
345
|
-
case 4:
|
|
346
|
-
case "end":
|
|
347
|
-
return _context6.stop();
|
|
348
|
-
}
|
|
349
|
-
}, _callee6);
|
|
350
|
-
}));
|
|
351
|
-
return _waitStableIdle2Frames.apply(this, arguments);
|
|
352
|
-
}
|
|
353
|
-
var waitForIdle = /*#__PURE__*/function () {
|
|
354
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
355
|
-
var _ref3,
|
|
356
|
-
_ref3$timeoutMs,
|
|
357
|
-
timeoutMs,
|
|
358
|
-
_args4 = arguments;
|
|
359
|
-
return _regeneratorRuntime.wrap(function (_context4) {
|
|
360
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
361
|
-
case 0:
|
|
362
|
-
_ref3 = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, _ref3$timeoutMs = _ref3.timeoutMs, timeoutMs = _ref3$timeoutMs === void 0 ? 30000 : _ref3$timeoutMs;
|
|
363
|
-
log('waitForIdle start', {
|
|
364
|
-
timeoutMs: timeoutMs,
|
|
365
|
-
inFlight: g.inFlight
|
|
366
|
-
});
|
|
367
|
-
_context4.next = 1;
|
|
368
|
-
return waitStableIdle2Frames();
|
|
369
|
-
case 1:
|
|
370
|
-
if (!_context4.sent) {
|
|
371
|
-
_context4.next = 2;
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
log('waitForIdle fast-path resolved');
|
|
375
|
-
return _context4.abrupt("return", true);
|
|
376
|
-
case 2:
|
|
377
|
-
return _context4.abrupt("return", new Promise(function (resolve, reject) {
|
|
378
|
-
var unsub = null;
|
|
379
|
-
var finished = false;
|
|
380
|
-
var finishOk = function finishOk() {
|
|
381
|
-
if (finished) return;
|
|
382
|
-
finished = true;
|
|
383
|
-
if (unsub) unsub();
|
|
384
|
-
clearTimeout(timer);
|
|
385
|
-
log('waitForIdle resolved');
|
|
386
|
-
resolve(true);
|
|
387
|
-
};
|
|
388
|
-
var finishErr = function finishErr(err) {
|
|
389
|
-
var _err$message;
|
|
390
|
-
if (finished) return;
|
|
391
|
-
finished = true;
|
|
392
|
-
if (unsub) unsub();
|
|
393
|
-
clearTimeout(timer);
|
|
394
|
-
error('waitForIdle timeout/reject', (_err$message = err === null || err === void 0 ? void 0 : err.message) !== null && _err$message !== void 0 ? _err$message : err);
|
|
395
|
-
reject(err);
|
|
396
|
-
};
|
|
397
|
-
var timer = setTimeout(function () {
|
|
398
|
-
finishErr(new Error('3D assets did not become idle within timeout'));
|
|
399
|
-
}, timeoutMs);
|
|
400
|
-
var onChange = /*#__PURE__*/function () {
|
|
401
|
-
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(count) {
|
|
402
|
-
var stable;
|
|
403
|
-
return _regeneratorRuntime.wrap(function (_context3) {
|
|
404
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
405
|
-
case 0:
|
|
406
|
-
if (!finished) {
|
|
407
|
-
_context3.next = 1;
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
return _context3.abrupt("return");
|
|
411
|
-
case 1:
|
|
412
|
-
log('waitForIdle inFlight change', count);
|
|
413
|
-
if (!(count !== 0)) {
|
|
414
|
-
_context3.next = 2;
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
return _context3.abrupt("return");
|
|
418
|
-
case 2:
|
|
419
|
-
_context3.next = 3;
|
|
420
|
-
return waitStableIdle2Frames();
|
|
421
|
-
case 3:
|
|
422
|
-
stable = _context3.sent;
|
|
423
|
-
log('waitForIdle stable check', stable);
|
|
424
|
-
if (stable) finishOk();
|
|
425
|
-
case 4:
|
|
426
|
-
case "end":
|
|
427
|
-
return _context3.stop();
|
|
428
|
-
}
|
|
429
|
-
}, _callee3);
|
|
430
|
-
}));
|
|
431
|
-
return function onChange(_x) {
|
|
432
|
-
return _ref4.apply(this, arguments);
|
|
433
|
-
};
|
|
434
|
-
}();
|
|
435
|
-
unsub = subscribe(onChange);
|
|
436
|
-
}));
|
|
437
|
-
case 3:
|
|
438
|
-
case "end":
|
|
439
|
-
return _context4.stop();
|
|
440
|
-
}
|
|
441
|
-
}, _callee4);
|
|
442
|
-
}));
|
|
443
|
-
return function waitForIdle() {
|
|
444
|
-
return _ref2.apply(this, arguments);
|
|
445
|
-
};
|
|
446
|
-
}();
|
|
447
|
-
var uninstall = function uninstall() {
|
|
448
|
-
var _XHR$prototype3, _XHR$prototype4;
|
|
449
|
-
g.refCount -= 1;
|
|
450
|
-
log('uninstall tracker refCount--', g.refCount);
|
|
451
|
-
if (g.refCount > 0) return;
|
|
452
|
-
log('uninstall tracker (final) restoring hooks');
|
|
453
|
-
var XHR = window.XMLHttpRequest;
|
|
454
|
-
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;
|
|
455
|
-
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;
|
|
456
|
-
if (typeof g.originalFetch === 'function') window.fetch = g.originalFetch;
|
|
457
|
-
g.listeners.clear();
|
|
458
|
-
g.inFlight = 0;
|
|
459
|
-
g.installed = false;
|
|
460
|
-
g.originalFetch = null;
|
|
461
|
-
g.originalOpen = null;
|
|
462
|
-
g.originalSend = null;
|
|
463
|
-
};
|
|
464
|
-
g.refCount += 1;
|
|
465
|
-
log('install tracker refCount++', g.refCount);
|
|
466
|
-
installIfNeeded();
|
|
467
|
-
return {
|
|
468
|
-
getInFlight: function getInFlight() {
|
|
469
|
-
return g.inFlight;
|
|
470
|
-
},
|
|
471
|
-
waitForIdle: waitForIdle,
|
|
472
|
-
uninstall: uninstall,
|
|
473
|
-
subscribe: subscribe
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
88
|
export function renderKitchenSimulator(container) {
|
|
477
89
|
var _props$framesPerEvent, _props$waitForGltfIdl, _props$gltfTimeoutMs;
|
|
478
90
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
479
91
|
if (!container) throw new Error('renderKitchenSimulator: container is required');
|
|
480
92
|
var DEBUG_KEY = '__kitchenSimulatorDebug__';
|
|
481
93
|
var debugEnabled = !!props.debug || typeof window !== 'undefined' && !!window[DEBUG_KEY];
|
|
482
|
-
var
|
|
94
|
+
var _makeLogger = makeLogger(function () {
|
|
483
95
|
return debugEnabled;
|
|
484
96
|
}),
|
|
485
|
-
log =
|
|
486
|
-
warn =
|
|
487
|
-
error =
|
|
488
|
-
|
|
489
|
-
// ---- Long-task observer (find main-thread blocks) ----
|
|
490
|
-
var longTaskObserver = null;
|
|
491
|
-
if (typeof window !== 'undefined' && 'PerformanceObserver' in window) {
|
|
492
|
-
try {
|
|
493
|
-
longTaskObserver = new PerformanceObserver(function (list) {
|
|
494
|
-
var _iterator2 = _createForOfIteratorHelper(list.getEntries()),
|
|
495
|
-
_step2;
|
|
496
|
-
try {
|
|
497
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
498
|
-
var entry = _step2.value;
|
|
499
|
-
// entry.duration is the smoking gun when UI freezes
|
|
500
|
-
warn('Long task detected', {
|
|
501
|
-
name: entry.name,
|
|
502
|
-
duration: entry.duration,
|
|
503
|
-
startTime: entry.startTime
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
} catch (err) {
|
|
507
|
-
_iterator2.e(err);
|
|
508
|
-
} finally {
|
|
509
|
-
_iterator2.f();
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
// may throw in some browsers
|
|
513
|
-
longTaskObserver.observe({
|
|
514
|
-
entryTypes: ['longtask']
|
|
515
|
-
});
|
|
516
|
-
log('Long-task observer installed');
|
|
517
|
-
} catch (_unused3) {
|
|
518
|
-
// ignore
|
|
519
|
-
}
|
|
520
|
-
}
|
|
97
|
+
log = _makeLogger.log,
|
|
98
|
+
warn = _makeLogger.warn,
|
|
99
|
+
error = _makeLogger.error;
|
|
521
100
|
|
|
522
101
|
// ✅ Reuse existing API
|
|
523
102
|
if (container[API_KEY]) {
|
|
@@ -539,13 +118,15 @@ export function renderKitchenSimulator(container) {
|
|
|
539
118
|
var queue = [];
|
|
540
119
|
var pendingMarkers = new Set();
|
|
541
120
|
var MARKER = Symbol('marker');
|
|
121
|
+
|
|
122
|
+
// ✅ keep your tracker
|
|
542
123
|
var gltfTracker = installGltfTracker(debugEnabled);
|
|
543
124
|
var defaultFramesPerEvent = (_props$framesPerEvent = props.framesPerEvent) !== null && _props$framesPerEvent !== void 0 ? _props$framesPerEvent : 1;
|
|
544
125
|
var waitForAssets = (_props$waitForGltfIdl = props.waitForGltfIdleAfterEachEvent) !== null && _props$waitForGltfIdl !== void 0 ? _props$waitForGltfIdl : true;
|
|
545
126
|
var defaultTimeout = (_props$gltfTimeoutMs = props.gltfTimeoutMs) !== null && _props$gltfTimeoutMs !== void 0 ? _props$gltfTimeoutMs : 30000;
|
|
546
127
|
var draining = false;
|
|
547
128
|
|
|
548
|
-
// ---- Ready gate
|
|
129
|
+
// ---- Ready gate: mounted & setExternalEventFn installed ----
|
|
549
130
|
var readyResolve = null;
|
|
550
131
|
var readyReject = null;
|
|
551
132
|
var readyPromise = new Promise(function (res, rej) {
|
|
@@ -553,122 +134,59 @@ export function renderKitchenSimulator(container) {
|
|
|
553
134
|
readyReject = rej;
|
|
554
135
|
});
|
|
555
136
|
|
|
556
|
-
// ----
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
137
|
+
// ---- Catalog-ready gate (NEW) ----
|
|
138
|
+
var catalogReadyResolve = null;
|
|
139
|
+
var catalogReadyPromise = new Promise(function (res) {
|
|
140
|
+
catalogReadyResolve = res;
|
|
141
|
+
});
|
|
142
|
+
var catalogReady = false;
|
|
143
|
+
function nextFrame() {
|
|
561
144
|
return new Promise(function (resolve) {
|
|
562
|
-
|
|
563
|
-
var start = performance.now();
|
|
564
|
-
var t = setTimeout(function () {
|
|
565
|
-
var _document, _document2;
|
|
566
|
-
if (done) return;
|
|
567
|
-
|
|
568
|
-
// If this fires, RAF is not arriving (hidden tab / throttling) or main thread blocked
|
|
569
|
-
warn('RAF not fired within threshold', {
|
|
570
|
-
label: label,
|
|
571
|
-
warnAfterMs: warnAfterMs,
|
|
572
|
-
elapsedMs: performance.now() - start,
|
|
573
|
-
visibilityState: (_document = document) === null || _document === void 0 ? void 0 : _document.visibilityState,
|
|
574
|
-
hidden: (_document2 = document) === null || _document2 === void 0 ? void 0 : _document2.hidden,
|
|
575
|
-
gltfInFlight: gltfTracker.getInFlight(),
|
|
576
|
-
queueLength: queue.length,
|
|
577
|
-
draining: draining,
|
|
578
|
-
destroyed: destroyed
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
// Optional fail-open so you don't hang forever:
|
|
582
|
-
// If you want STRICT behavior, comment the next 2 lines and only keep logging.
|
|
583
|
-
done = true;
|
|
584
|
-
resolve();
|
|
585
|
-
}, warnAfterMs);
|
|
586
|
-
requestAnimationFrame(function () {
|
|
587
|
-
if (done) return;
|
|
588
|
-
done = true;
|
|
589
|
-
clearTimeout(t);
|
|
590
|
-
resolve();
|
|
591
|
-
});
|
|
145
|
+
return requestAnimationFrame(resolve);
|
|
592
146
|
});
|
|
593
147
|
}
|
|
594
|
-
function
|
|
595
|
-
var _ev$payload;
|
|
596
|
-
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;
|
|
597
|
-
}
|
|
598
|
-
function settle(_x2, _x3) {
|
|
148
|
+
function settle(_x) {
|
|
599
149
|
return _settle.apply(this, arguments);
|
|
600
150
|
}
|
|
601
151
|
function _settle() {
|
|
602
|
-
_settle = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
603
|
-
var _ev$framesPerEvent, _ev$waitForGltfIdleAf, _ev$gltfTimeoutMs
|
|
604
|
-
var frames, shouldWait, timeoutMs, i
|
|
605
|
-
return _regeneratorRuntime.wrap(function (
|
|
606
|
-
while (1) switch (
|
|
152
|
+
_settle = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(ev) {
|
|
153
|
+
var _ev$framesPerEvent, _ev$waitForGltfIdleAf, _ev$gltfTimeoutMs;
|
|
154
|
+
var frames, shouldWait, timeoutMs, i;
|
|
155
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
156
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
607
157
|
case 0:
|
|
608
158
|
frames = (_ev$framesPerEvent = ev === null || ev === void 0 ? void 0 : ev.framesPerEvent) !== null && _ev$framesPerEvent !== void 0 ? _ev$framesPerEvent : defaultFramesPerEvent;
|
|
609
159
|
shouldWait = (_ev$waitForGltfIdleAf = ev === null || ev === void 0 ? void 0 : ev.waitForGltfIdleAfterEachEvent) !== null && _ev$waitForGltfIdleAf !== void 0 ? _ev$waitForGltfIdleAf : waitForAssets;
|
|
610
|
-
timeoutMs = (_ev$gltfTimeoutMs = ev === null || ev === void 0 ? void 0 : ev.gltfTimeoutMs) !== null && _ev$gltfTimeoutMs !== void 0 ? _ev$gltfTimeoutMs : defaultTimeout;
|
|
611
|
-
log('settle:start', _objectSpread(_objectSpread({}, meta), {}, {
|
|
612
|
-
frames: frames,
|
|
613
|
-
shouldWait: shouldWait,
|
|
614
|
-
timeoutMs: timeoutMs,
|
|
615
|
-
visibilityState: (_document7 = document) === null || _document7 === void 0 ? void 0 : _document7.visibilityState,
|
|
616
|
-
hidden: (_document8 = document) === null || _document8 === void 0 ? void 0 : _document8.hidden
|
|
617
|
-
}));
|
|
618
|
-
|
|
619
|
-
// (1) RAF frames (diagnostic)
|
|
160
|
+
timeoutMs = (_ev$gltfTimeoutMs = ev === null || ev === void 0 ? void 0 : ev.gltfTimeoutMs) !== null && _ev$gltfTimeoutMs !== void 0 ? _ev$gltfTimeoutMs : defaultTimeout; // RAF frames
|
|
620
161
|
i = 0;
|
|
621
162
|
case 1:
|
|
622
163
|
if (!(i < frames)) {
|
|
623
|
-
|
|
164
|
+
_context3.next = 3;
|
|
624
165
|
break;
|
|
625
166
|
}
|
|
626
|
-
|
|
627
|
-
return
|
|
167
|
+
_context3.next = 2;
|
|
168
|
+
return nextFrame();
|
|
628
169
|
case 2:
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
}));
|
|
632
|
-
case 3:
|
|
633
|
-
i += 1;
|
|
634
|
-
_context8.next = 1;
|
|
170
|
+
i++;
|
|
171
|
+
_context3.next = 1;
|
|
635
172
|
break;
|
|
636
|
-
case
|
|
173
|
+
case 3:
|
|
637
174
|
if (!shouldWait) {
|
|
638
|
-
|
|
175
|
+
_context3.next = 4;
|
|
639
176
|
break;
|
|
640
177
|
}
|
|
641
|
-
|
|
642
|
-
log('settle:waitForIdle start', _objectSpread(_objectSpread({}, meta), {}, {
|
|
643
|
-
timeoutMs: timeoutMs,
|
|
644
|
-
gltfInFlight: gltfTracker.getInFlight()
|
|
645
|
-
}));
|
|
646
|
-
_context8.next = 5;
|
|
178
|
+
_context3.next = 4;
|
|
647
179
|
return gltfTracker.waitForIdle({
|
|
648
180
|
timeoutMs: timeoutMs
|
|
649
181
|
});
|
|
182
|
+
case 4:
|
|
183
|
+
_context3.next = 5;
|
|
184
|
+
return nextFrame();
|
|
650
185
|
case 5:
|
|
651
|
-
log('settle:waitForIdle done', _objectSpread(_objectSpread({}, meta), {}, {
|
|
652
|
-
waitedMs: Date.now() - start,
|
|
653
|
-
gltfInFlight: gltfTracker.getInFlight()
|
|
654
|
-
}));
|
|
655
|
-
case 6:
|
|
656
|
-
_context8.next = 7;
|
|
657
|
-
return nextFrameDiag('settle:final commit frame', 500);
|
|
658
|
-
case 7:
|
|
659
|
-
if (!isSyncScene(ev)) {
|
|
660
|
-
_context8.next = 8;
|
|
661
|
-
break;
|
|
662
|
-
}
|
|
663
|
-
_context8.next = 8;
|
|
664
|
-
return nextFrameDiag('settle:sync-scene extra frame', 500);
|
|
665
|
-
case 8:
|
|
666
|
-
log('settle:done', meta);
|
|
667
|
-
case 9:
|
|
668
186
|
case "end":
|
|
669
|
-
return
|
|
187
|
+
return _context3.stop();
|
|
670
188
|
}
|
|
671
|
-
},
|
|
189
|
+
}, _callee3);
|
|
672
190
|
}));
|
|
673
191
|
return _settle.apply(this, arguments);
|
|
674
192
|
}
|
|
@@ -676,140 +194,96 @@ export function renderKitchenSimulator(container) {
|
|
|
676
194
|
return _drain.apply(this, arguments);
|
|
677
195
|
}
|
|
678
196
|
function _drain() {
|
|
679
|
-
_drain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
680
|
-
var
|
|
681
|
-
return _regeneratorRuntime.wrap(function (
|
|
682
|
-
while (1) switch (
|
|
197
|
+
_drain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
198
|
+
var item, _err$message, _t;
|
|
199
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
200
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
683
201
|
case 0:
|
|
684
202
|
if (!(draining || destroyed)) {
|
|
685
|
-
|
|
203
|
+
_context4.next = 1;
|
|
686
204
|
break;
|
|
687
205
|
}
|
|
688
|
-
|
|
689
|
-
draining: draining,
|
|
690
|
-
destroyed: destroyed,
|
|
691
|
-
queueLength: queue.length
|
|
692
|
-
});
|
|
693
|
-
return _context9.abrupt("return");
|
|
206
|
+
return _context4.abrupt("return");
|
|
694
207
|
case 1:
|
|
695
208
|
draining = true;
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
watchdog = setInterval(function () {
|
|
699
|
-
var _document9, _document0;
|
|
700
|
-
warn('drain watchdog', {
|
|
701
|
-
destroyed: destroyed,
|
|
702
|
-
draining: draining,
|
|
703
|
-
queueLength: queue.length,
|
|
704
|
-
pendingMarkers: pendingMarkers.size,
|
|
705
|
-
gltfInFlight: gltfTracker.getInFlight(),
|
|
706
|
-
visibilityState: (_document9 = document) === null || _document9 === void 0 ? void 0 : _document9.visibilityState,
|
|
707
|
-
hidden: (_document0 = document) === null || _document0 === void 0 ? void 0 : _document0.hidden
|
|
708
|
-
});
|
|
709
|
-
}, 4000);
|
|
710
|
-
_context9.prev = 2;
|
|
711
|
-
_context9.next = 3;
|
|
209
|
+
_context4.prev = 2;
|
|
210
|
+
_context4.next = 3;
|
|
712
211
|
return readyPromise;
|
|
713
212
|
case 3:
|
|
714
213
|
if (!(!destroyed && queue.length)) {
|
|
715
|
-
|
|
214
|
+
_context4.next = 10;
|
|
716
215
|
break;
|
|
717
216
|
}
|
|
718
217
|
if (setExternalEventFn) {
|
|
719
|
-
|
|
218
|
+
_context4.next = 5;
|
|
720
219
|
break;
|
|
721
220
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
return nextFrameDiag('drain:waiting for setExternalEventFn', 500);
|
|
221
|
+
_context4.next = 4;
|
|
222
|
+
return nextFrame();
|
|
725
223
|
case 4:
|
|
726
|
-
return
|
|
224
|
+
return _context4.abrupt("continue", 3);
|
|
727
225
|
case 5:
|
|
728
226
|
item = queue.shift();
|
|
729
227
|
if (!(item && item.__marker === MARKER)) {
|
|
730
|
-
|
|
228
|
+
_context4.next = 6;
|
|
731
229
|
break;
|
|
732
230
|
}
|
|
733
231
|
pendingMarkers["delete"](item.token);
|
|
734
|
-
|
|
735
|
-
pendingMarkers: pendingMarkers.size,
|
|
736
|
-
queueLength: queue.length
|
|
737
|
-
});
|
|
738
|
-
return _context9.abrupt("continue", 3);
|
|
232
|
+
return _context4.abrupt("continue", 3);
|
|
739
233
|
case 6:
|
|
740
|
-
|
|
741
|
-
eventType: item === null || item === void 0 ? void 0 : item.type,
|
|
742
|
-
queueLengthAfterShift: queue.length,
|
|
743
|
-
pendingMarkers: pendingMarkers.size,
|
|
744
|
-
gltfInFlight: gltfTracker.getInFlight()
|
|
745
|
-
};
|
|
746
|
-
log('drain:event begin', meta);
|
|
747
|
-
_context9.prev = 7;
|
|
234
|
+
_context4.prev = 6;
|
|
748
235
|
setExternalEventFn(item);
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
log('drain:event done', meta);
|
|
754
|
-
_context9.next = 10;
|
|
236
|
+
_context4.next = 7;
|
|
237
|
+
return settle(item);
|
|
238
|
+
case 7:
|
|
239
|
+
_context4.next = 9;
|
|
755
240
|
break;
|
|
241
|
+
case 8:
|
|
242
|
+
_context4.prev = 8;
|
|
243
|
+
_t = _context4["catch"](6);
|
|
244
|
+
error('drain:event failed', {
|
|
245
|
+
err: (_err$message = _t === null || _t === void 0 ? void 0 : _t.message) !== null && _err$message !== void 0 ? _err$message : _t,
|
|
246
|
+
type: item === null || item === void 0 ? void 0 : item.type
|
|
247
|
+
});
|
|
756
248
|
case 9:
|
|
757
|
-
|
|
758
|
-
_t2 = _context9["catch"](7);
|
|
759
|
-
error('drain:event failed', _objectSpread(_objectSpread({}, meta), {}, {
|
|
760
|
-
err: (_err$message2 = _t2 === null || _t2 === void 0 ? void 0 : _t2.message) !== null && _err$message2 !== void 0 ? _err$message2 : _t2
|
|
761
|
-
}));
|
|
762
|
-
case 10:
|
|
763
|
-
_context9.next = 3;
|
|
249
|
+
_context4.next = 3;
|
|
764
250
|
break;
|
|
765
|
-
case
|
|
766
|
-
|
|
767
|
-
clearInterval(watchdog);
|
|
251
|
+
case 10:
|
|
252
|
+
_context4.prev = 10;
|
|
768
253
|
draining = false;
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
queueLength: queue.length,
|
|
772
|
-
pendingMarkers: pendingMarkers.size,
|
|
773
|
-
gltfInFlight: gltfTracker.getInFlight()
|
|
774
|
-
});
|
|
775
|
-
return _context9.finish(11);
|
|
776
|
-
case 12:
|
|
254
|
+
return _context4.finish(10);
|
|
255
|
+
case 11:
|
|
777
256
|
case "end":
|
|
778
|
-
return
|
|
257
|
+
return _context4.stop();
|
|
779
258
|
}
|
|
780
|
-
},
|
|
259
|
+
}, _callee4, null, [[2,, 10, 11], [6, 8]]);
|
|
781
260
|
}));
|
|
782
261
|
return _drain.apply(this, arguments);
|
|
783
262
|
}
|
|
784
263
|
var Wrapper = /*#__PURE__*/function (_React$Component) {
|
|
785
264
|
function Wrapper(p) {
|
|
786
|
-
var
|
|
265
|
+
var _this;
|
|
787
266
|
_classCallCheck(this, Wrapper);
|
|
788
|
-
|
|
789
|
-
|
|
267
|
+
_this = _callSuper(this, Wrapper, [p]);
|
|
268
|
+
_this.state = {
|
|
790
269
|
externalEvent: p.externalEvent || null
|
|
791
270
|
};
|
|
792
|
-
|
|
793
|
-
return
|
|
271
|
+
_this._mounted = false;
|
|
272
|
+
return _this;
|
|
794
273
|
}
|
|
795
274
|
_inherits(Wrapper, _React$Component);
|
|
796
275
|
return _createClass(Wrapper, [{
|
|
797
276
|
key: "componentDidMount",
|
|
798
277
|
value: function componentDidMount() {
|
|
799
|
-
var
|
|
278
|
+
var _this2 = this;
|
|
800
279
|
this._mounted = true;
|
|
801
280
|
log('Wrapper mounted -> ready');
|
|
802
281
|
setExternalEventFn = function setExternalEventFn(newEvent) {
|
|
803
|
-
if (!
|
|
804
|
-
|
|
805
|
-
type: newEvent === null || newEvent === void 0 ? void 0 : newEvent.type
|
|
806
|
-
});
|
|
807
|
-
_this3.setState({
|
|
282
|
+
if (!_this2._mounted) return;
|
|
283
|
+
_this2.setState({
|
|
808
284
|
externalEvent: newEvent
|
|
809
285
|
});
|
|
810
286
|
};
|
|
811
|
-
|
|
812
|
-
// ✅ resolve readiness here (first time)
|
|
813
287
|
if (readyResolve) {
|
|
814
288
|
readyResolve(true);
|
|
815
289
|
readyResolve = null;
|
|
@@ -818,11 +292,8 @@ export function renderKitchenSimulator(container) {
|
|
|
818
292
|
}, {
|
|
819
293
|
key: "componentWillUnmount",
|
|
820
294
|
value: function componentWillUnmount() {
|
|
821
|
-
log('Wrapper will unmount');
|
|
822
295
|
this._mounted = false;
|
|
823
296
|
setExternalEventFn = null;
|
|
824
|
-
|
|
825
|
-
// If unmount happens before ready, reject so drain can stop cleanly
|
|
826
297
|
if (readyReject) {
|
|
827
298
|
readyReject(new Error('Wrapper unmounted before ready'));
|
|
828
299
|
readyReject = null;
|
|
@@ -831,10 +302,37 @@ export function renderKitchenSimulator(container) {
|
|
|
831
302
|
}, {
|
|
832
303
|
key: "render",
|
|
833
304
|
value: function render() {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
305
|
+
var userOnInternalEvent = this.props.onInternalEvent;
|
|
306
|
+
|
|
307
|
+
// ✅ Wrap internal event to detect catalog readiness
|
|
308
|
+
var onInternalEventWrapped = /*#__PURE__*/function () {
|
|
309
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(evt, callback) {
|
|
310
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
311
|
+
while (1) switch (_context.prev = _context.next) {
|
|
312
|
+
case 0:
|
|
313
|
+
// IMPORTANT: first time we see INTERNAL_EVENT_ITEMS_CATALOG,
|
|
314
|
+
// it means catalog init path ran and tool is requesting items.
|
|
315
|
+
if (!catalogReady && (evt === null || evt === void 0 ? void 0 : evt.type) === 'INTERNAL_EVENT_ITEMS_CATALOG') {
|
|
316
|
+
catalogReady = true;
|
|
317
|
+
if (catalogReadyResolve) {
|
|
318
|
+
catalogReadyResolve(true);
|
|
319
|
+
catalogReadyResolve = null;
|
|
320
|
+
}
|
|
321
|
+
log('Catalog is ready (observed INTERNAL_EVENT_ITEMS_CATALOG)');
|
|
322
|
+
}
|
|
323
|
+
return _context.abrupt("return", userOnInternalEvent === null || userOnInternalEvent === void 0 ? void 0 : userOnInternalEvent(evt, callback));
|
|
324
|
+
case 1:
|
|
325
|
+
case "end":
|
|
326
|
+
return _context.stop();
|
|
327
|
+
}
|
|
328
|
+
}, _callee);
|
|
329
|
+
}));
|
|
330
|
+
return function onInternalEventWrapped(_x2, _x3) {
|
|
331
|
+
return _ref.apply(this, arguments);
|
|
332
|
+
};
|
|
333
|
+
}();
|
|
837
334
|
return /*#__PURE__*/React.createElement(LiteRenderer, _extends({}, this.props, {
|
|
335
|
+
onInternalEvent: onInternalEventWrapped,
|
|
838
336
|
externalEvent: this.state.externalEvent
|
|
839
337
|
}));
|
|
840
338
|
}
|
|
@@ -842,14 +340,16 @@ export function renderKitchenSimulator(container) {
|
|
|
842
340
|
}(React.Component);
|
|
843
341
|
var api = {
|
|
844
342
|
__render: function __render(nextProps) {
|
|
845
|
-
log('__render called', {
|
|
846
|
-
debug: !!(nextProps !== null && nextProps !== void 0 && nextProps.debug)
|
|
847
|
-
});
|
|
848
343
|
root.render(/*#__PURE__*/React.createElement(Wrapper, nextProps));
|
|
849
344
|
},
|
|
345
|
+
// ✅ Host can await mount
|
|
850
346
|
whenReady: function whenReady() {
|
|
851
347
|
return readyPromise;
|
|
852
348
|
},
|
|
349
|
+
// ✅ Host can await catalog init (NEW)
|
|
350
|
+
whenCatalogReady: function whenCatalogReady() {
|
|
351
|
+
return catalogReadyPromise;
|
|
352
|
+
},
|
|
853
353
|
getGltfInFlight: function getGltfInFlight() {
|
|
854
354
|
return gltfTracker.getInFlight();
|
|
855
355
|
},
|
|
@@ -857,130 +357,86 @@ export function renderKitchenSimulator(container) {
|
|
|
857
357
|
return gltfTracker.subscribe(cb);
|
|
858
358
|
},
|
|
859
359
|
sendExternalEvents: function sendExternalEvents(eventOrEvents) {
|
|
860
|
-
var
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
timeoutMs = _ref5$timeoutMs === void 0 ? 60000 : _ref5$timeoutMs;
|
|
360
|
+
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
361
|
+
_ref2$timeoutMs = _ref2.timeoutMs,
|
|
362
|
+
timeoutMs = _ref2$timeoutMs === void 0 ? 60000 : _ref2$timeoutMs;
|
|
864
363
|
var events = Array.isArray(eventOrEvents) ? eventOrEvents : [eventOrEvents];
|
|
865
|
-
var
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
count: events.length,
|
|
869
|
-
timeoutMs: timeoutMs,
|
|
870
|
-
visibilityState: (_document3 = document) === null || _document3 === void 0 ? void 0 : _document3.visibilityState,
|
|
871
|
-
hidden: (_document4 = document) === null || _document4 === void 0 ? void 0 : _document4.hidden,
|
|
872
|
-
gltfInFlight: gltfTracker.getInFlight()
|
|
873
|
-
});
|
|
874
|
-
var _iterator3 = _createForOfIteratorHelper(events),
|
|
875
|
-
_step3;
|
|
364
|
+
var token = Symbol('batch');
|
|
365
|
+
var _iterator = _createForOfIteratorHelper(events),
|
|
366
|
+
_step;
|
|
876
367
|
try {
|
|
877
|
-
for (
|
|
878
|
-
var e =
|
|
368
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
369
|
+
var e = _step.value;
|
|
879
370
|
queue.push(e);
|
|
880
371
|
}
|
|
881
372
|
} catch (err) {
|
|
882
|
-
|
|
373
|
+
_iterator.e(err);
|
|
883
374
|
} finally {
|
|
884
|
-
|
|
375
|
+
_iterator.f();
|
|
885
376
|
}
|
|
886
|
-
var token = Symbol('batch');
|
|
887
377
|
pendingMarkers.add(token);
|
|
888
378
|
queue.push({
|
|
889
379
|
__marker: MARKER,
|
|
890
380
|
token: token
|
|
891
381
|
});
|
|
892
|
-
log('sendExternalEvents:marker added', {
|
|
893
|
-
batchId: batchId,
|
|
894
|
-
queueLength: queue.length,
|
|
895
|
-
pendingMarkers: pendingMarkers.size
|
|
896
|
-
});
|
|
897
382
|
drain();
|
|
898
383
|
return new Promise(function (resolve) {
|
|
899
384
|
var start = Date.now();
|
|
900
385
|
var check = /*#__PURE__*/function () {
|
|
901
|
-
var
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
386
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
387
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
388
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
905
389
|
case 0:
|
|
906
390
|
if (destroyed) {
|
|
907
|
-
|
|
391
|
+
_context2.next = 4;
|
|
908
392
|
break;
|
|
909
393
|
}
|
|
910
394
|
if (pendingMarkers.has(token)) {
|
|
911
|
-
|
|
395
|
+
_context2.next = 1;
|
|
912
396
|
break;
|
|
913
397
|
}
|
|
914
|
-
log('sendExternalEvents:resolved', {
|
|
915
|
-
batchId: batchId,
|
|
916
|
-
ms: Date.now() - start
|
|
917
|
-
});
|
|
918
398
|
resolve(true);
|
|
919
|
-
return
|
|
399
|
+
return _context2.abrupt("return");
|
|
920
400
|
case 1:
|
|
921
401
|
if (!(Date.now() - start > timeoutMs)) {
|
|
922
|
-
|
|
402
|
+
_context2.next = 2;
|
|
923
403
|
break;
|
|
924
404
|
}
|
|
925
405
|
error('sendExternalEvents timed out', {
|
|
926
|
-
|
|
927
|
-
timeoutMs: timeoutMs,
|
|
928
|
-
ms: Date.now() - start,
|
|
929
|
-
queueLength: queue.length,
|
|
930
|
-
pendingMarkers: pendingMarkers.size,
|
|
931
|
-
gltfInFlight: gltfTracker.getInFlight(),
|
|
932
|
-
visibilityState: (_document5 = document) === null || _document5 === void 0 ? void 0 : _document5.visibilityState,
|
|
933
|
-
hidden: (_document6 = document) === null || _document6 === void 0 ? void 0 : _document6.hidden
|
|
406
|
+
timeoutMs: timeoutMs
|
|
934
407
|
});
|
|
935
408
|
pendingMarkers["delete"](token); // fail-open
|
|
936
409
|
resolve(false);
|
|
937
|
-
return
|
|
410
|
+
return _context2.abrupt("return");
|
|
938
411
|
case 2:
|
|
939
|
-
|
|
940
|
-
return
|
|
412
|
+
_context2.next = 3;
|
|
413
|
+
return nextFrame();
|
|
941
414
|
case 3:
|
|
942
|
-
|
|
415
|
+
_context2.next = 0;
|
|
943
416
|
break;
|
|
944
417
|
case 4:
|
|
945
418
|
resolve(false);
|
|
946
419
|
case 5:
|
|
947
420
|
case "end":
|
|
948
|
-
return
|
|
421
|
+
return _context2.stop();
|
|
949
422
|
}
|
|
950
|
-
},
|
|
423
|
+
}, _callee2);
|
|
951
424
|
}));
|
|
952
425
|
return function check() {
|
|
953
|
-
return
|
|
426
|
+
return _ref3.apply(this, arguments);
|
|
954
427
|
};
|
|
955
428
|
}();
|
|
956
429
|
check();
|
|
957
430
|
});
|
|
958
431
|
},
|
|
959
|
-
updateExternalEvent: function updateExternalEvent(e) {
|
|
960
|
-
return api.sendExternalEvents(e);
|
|
961
|
-
},
|
|
962
|
-
clearQueue: function clearQueue() {
|
|
963
|
-
queue.length = 0;
|
|
964
|
-
pendingMarkers.clear();
|
|
965
|
-
},
|
|
966
432
|
unmount: function unmount() {
|
|
967
433
|
destroyed = true;
|
|
968
|
-
|
|
434
|
+
queue.length = 0;
|
|
435
|
+
pendingMarkers.clear();
|
|
969
436
|
gltfTracker.uninstall();
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
// ignore
|
|
974
|
-
}
|
|
975
|
-
var doUnmount = function doUnmount() {
|
|
976
|
-
try {
|
|
977
|
-
root.unmount();
|
|
978
|
-
} finally {
|
|
979
|
-
container[ROOT_KEY] = null;
|
|
980
|
-
container[API_KEY] = null;
|
|
981
|
-
}
|
|
982
|
-
};
|
|
983
|
-
if (typeof queueMicrotask === 'function') queueMicrotask(doUnmount);else setTimeout(doUnmount, 0);
|
|
437
|
+
root.unmount();
|
|
438
|
+
container[ROOT_KEY] = null;
|
|
439
|
+
container[API_KEY] = null;
|
|
984
440
|
}
|
|
985
441
|
};
|
|
986
442
|
api.__render(props);
|