kitchen-simulator 5.10.14-react.18 → 6.0.1-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/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";
@@ -6,9 +5,6 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConst
6
5
  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
- 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
8
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
13
9
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
10
  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; } } }; }
@@ -21,82 +17,30 @@ import LiteRenderer from "./LiteRenderer";
21
17
  import { createRoot } from 'react-dom/client';
22
18
  var ROOT_KEY = '__kitchenSimulatorRoot__';
23
19
  var API_KEY = '__kitchenSimulatorApi__';
24
- function makeLogger(getEnabled) {
25
- var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '[kitchen-simulator]';
26
- var now = function now() {
27
- return (typeof performance !== 'undefined' && performance.now ? performance.now() : Date.now()).toFixed(1);
28
- };
29
- var safe = function safe(v) {
30
- try {
31
- if (v == null) return v;
32
- if (typeof v === 'string') return v;
33
- if (typeof v === 'number' || typeof v === 'boolean') return v;
34
- return JSON.stringify(v, function (k, val) {
35
- if (k === 'children' || k === 'parent') return '[omitted]';
36
- if (typeof val === 'function') return '[fn]';
37
- return val;
38
- });
39
- } catch (_unused) {
40
- return '[unserializable]';
41
- }
42
- };
43
- var log = function log() {
44
- var _console;
45
- if (!getEnabled()) return;
46
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
47
- args[_key] = arguments[_key];
48
- }
49
- (_console = console).log.apply(_console, ["".concat(prefix, " ").concat(now(), "ms")].concat(_toConsumableArray(args.map(safe))));
50
- };
51
- var warn = function warn() {
52
- var _console2;
53
- if (!getEnabled()) return;
54
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
55
- args[_key2] = arguments[_key2];
56
- }
57
- (_console2 = console).warn.apply(_console2, ["".concat(prefix, " ").concat(now(), "ms")].concat(_toConsumableArray(args.map(safe))));
58
- };
59
- var error = function error() {
60
- var _console3;
61
- if (!getEnabled()) return;
62
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
63
- args[_key3] = arguments[_key3];
64
- }
65
- (_console3 = console).error.apply(_console3, ["".concat(prefix, " ").concat(now(), "ms")].concat(_toConsumableArray(args.map(safe))));
66
- };
67
- return {
68
- log: log,
69
- warn: warn,
70
- error: error
71
- };
72
- }
73
20
 
74
- // DIY-714 [Temp Fix] Rewrite API URLs
21
+ // ---------------- URL rewrite (keep if needed) ----------------
75
22
  var API_HOST_REGEX = /(https?:\/\/)?(api\.diydesignspace\.com|api\.addovisuals\.com|127\.0\.0\.1:4002)/;
76
23
  var API_HOST_REPLACEMENT = 'https://api-old.diydesignspace.com';
77
24
  function rewriteApiUrl(url) {
78
25
  return typeof url === 'string' ? url.replace(API_HOST_REGEX, API_HOST_REPLACEMENT) : url;
79
26
  }
27
+
28
+ // texture rewrite
80
29
  var originalTextureLoad = Three.TextureLoader.prototype.load;
81
30
  Three.TextureLoader.prototype.load = function (url, onLoad, onProgress, onError) {
82
- var newUrl = rewriteApiUrl(url);
83
- return originalTextureLoad.call(this, newUrl, onLoad, onProgress, onError);
31
+ return originalTextureLoad.call(this, rewriteApiUrl(url), onLoad, onProgress, onError);
84
32
  };
85
33
 
86
- /**
87
- * Track 3D asset network activity (gltf/glb/bin/textures/hdr/etc)
88
- * Ref-counted global install so multiple instances don't clobber each other.
89
- */
34
+ // ---------------- minimal gltf tracker (same idea, but smaller) ----------------
90
35
  function installGltfTracker() {
91
- var debug = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
92
36
  if (typeof window === 'undefined') {
93
- var _subscribe = function _subscribe() {
94
- return function () {};
95
- };
96
37
  return {
97
38
  getInFlight: function getInFlight() {
98
39
  return 0;
99
40
  },
41
+ subscribe: function subscribe() {
42
+ return function () {};
43
+ },
100
44
  waitForIdle: function () {
101
45
  var _waitForIdle = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
102
46
  return _regeneratorRuntime.wrap(function (_context) {
@@ -114,40 +58,25 @@ function installGltfTracker() {
114
58
  }
115
59
  return waitForIdle;
116
60
  }(),
117
- uninstall: function uninstall() {},
118
- subscribe: _subscribe
61
+ uninstall: function uninstall() {}
119
62
  };
120
63
  }
121
- var GLOBAL_KEY = '__kitchenSimulatorGltfTracker__';
122
- var TRACKER_DEBUG_KEY = '__kitchenSimulatorDebug__';
123
- if (!window[GLOBAL_KEY]) {
124
- window[GLOBAL_KEY] = {
64
+ var KEY = '__kitchenSimulatorGltfTracker__';
65
+ if (!window[KEY]) {
66
+ window[KEY] = {
125
67
  refCount: 0,
126
68
  inFlight: 0,
127
69
  listeners: new Set(),
128
70
  installed: false,
129
- originalFetch: null,
130
- originalOpen: null,
131
- originalSend: null
71
+ originalFetch: null
132
72
  };
133
73
  }
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;
74
+ var g = window[KEY];
142
75
  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
- }
76
+ var _ref, _url$url, _url$toString;
77
+ var s = typeof url === 'string' ? url : (_ref = (_url$url = url === null || url === void 0 ? void 0 : url.url) !== null && _url$url !== void 0 ? _url$url : url === null || url === void 0 || (_url$toString = url.toString) === null || _url$toString === void 0 ? void 0 : _url$toString.call(url)) !== null && _ref !== void 0 ? _ref : '';
78
+ var u = String(s).toLowerCase().split('?')[0];
79
+ 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');
151
80
  };
152
81
  var notify = function notify() {
153
82
  var _iterator = _createForOfIteratorHelper(g.listeners),
@@ -170,670 +99,249 @@ function installGltfTracker() {
170
99
  return g.listeners["delete"](fn);
171
100
  };
172
101
  };
173
- var installIfNeeded = function installIfNeeded() {
174
- var _XHR$prototype, _XHR$prototype2;
175
- if (g.installed) return;
176
- log('Installing GLTF tracker hooks');
177
-
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;
102
+ var nextFrame = function nextFrame() {
103
+ return new Promise(function (r) {
104
+ return requestAnimationFrame(r);
105
+ });
304
106
  };
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
107
  function waitStableIdle2Frames() {
325
108
  return _waitStableIdle2Frames.apply(this, arguments);
326
109
  }
327
110
  function _waitStableIdle2Frames() {
328
- _waitStableIdle2Frames = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
329
- return _regeneratorRuntime.wrap(function (_context6) {
330
- while (1) switch (_context6.prev = _context6.next) {
111
+ _waitStableIdle2Frames = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
112
+ return _regeneratorRuntime.wrap(function (_context5) {
113
+ while (1) switch (_context5.prev = _context5.next) {
331
114
  case 0:
332
- _context6.next = 1;
115
+ _context5.next = 1;
333
116
  return nextFrame();
334
117
  case 1:
335
118
  if (!(g.inFlight !== 0)) {
336
- _context6.next = 2;
119
+ _context5.next = 2;
337
120
  break;
338
121
  }
339
- return _context6.abrupt("return", false);
122
+ return _context5.abrupt("return", false);
340
123
  case 2:
341
- _context6.next = 3;
124
+ _context5.next = 3;
342
125
  return nextFrame();
343
126
  case 3:
344
- return _context6.abrupt("return", g.inFlight === 0);
127
+ return _context5.abrupt("return", g.inFlight === 0);
345
128
  case 4:
346
129
  case "end":
347
- return _context6.stop();
130
+ return _context5.stop();
348
131
  }
349
- }, _callee6);
132
+ }, _callee5);
350
133
  }));
351
134
  return _waitStableIdle2Frames.apply(this, arguments);
352
135
  }
353
136
  var waitForIdle = /*#__PURE__*/function () {
354
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
137
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
355
138
  var _ref3,
356
139
  _ref3$timeoutMs,
357
140
  timeoutMs,
358
- _args4 = arguments;
359
- return _regeneratorRuntime.wrap(function (_context4) {
360
- while (1) switch (_context4.prev = _context4.next) {
141
+ _args3 = arguments;
142
+ return _regeneratorRuntime.wrap(function (_context3) {
143
+ while (1) switch (_context3.prev = _context3.next) {
361
144
  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;
145
+ _ref3 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, _ref3$timeoutMs = _ref3.timeoutMs, timeoutMs = _ref3$timeoutMs === void 0 ? 30000 : _ref3$timeoutMs;
146
+ _context3.next = 1;
368
147
  return waitStableIdle2Frames();
369
148
  case 1:
370
- if (!_context4.sent) {
371
- _context4.next = 2;
149
+ if (!_context3.sent) {
150
+ _context3.next = 2;
372
151
  break;
373
152
  }
374
- log('waitForIdle fast-path resolved');
375
- return _context4.abrupt("return", true);
153
+ return _context3.abrupt("return", true);
376
154
  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
- };
155
+ return _context3.abrupt("return", new Promise(function (resolve, reject) {
156
+ var done = false;
397
157
  var timer = setTimeout(function () {
398
- finishErr(new Error('3D assets did not become idle within timeout'));
158
+ if (done) return;
159
+ done = true;
160
+ unsub === null || unsub === void 0 || unsub();
161
+ reject(new Error('3D assets did not become idle within timeout'));
399
162
  }, timeoutMs);
400
- var onChange = /*#__PURE__*/function () {
401
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(count) {
163
+ var unsub = subscribe(/*#__PURE__*/function () {
164
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(count) {
402
165
  var stable;
403
- return _regeneratorRuntime.wrap(function (_context3) {
404
- while (1) switch (_context3.prev = _context3.next) {
166
+ return _regeneratorRuntime.wrap(function (_context2) {
167
+ while (1) switch (_context2.prev = _context2.next) {
405
168
  case 0:
406
- if (!finished) {
407
- _context3.next = 1;
169
+ if (!done) {
170
+ _context2.next = 1;
408
171
  break;
409
172
  }
410
- return _context3.abrupt("return");
173
+ return _context2.abrupt("return");
411
174
  case 1:
412
- log('waitForIdle inFlight change', count);
413
175
  if (!(count !== 0)) {
414
- _context3.next = 2;
176
+ _context2.next = 2;
415
177
  break;
416
178
  }
417
- return _context3.abrupt("return");
179
+ return _context2.abrupt("return");
418
180
  case 2:
419
- _context3.next = 3;
181
+ _context2.next = 3;
420
182
  return waitStableIdle2Frames();
421
183
  case 3:
422
- stable = _context3.sent;
423
- log('waitForIdle stable check', stable);
424
- if (stable) finishOk();
184
+ stable = _context2.sent;
185
+ if (stable) {
186
+ done = true;
187
+ clearTimeout(timer);
188
+ unsub();
189
+ resolve(true);
190
+ }
425
191
  case 4:
426
192
  case "end":
427
- return _context3.stop();
193
+ return _context2.stop();
428
194
  }
429
- }, _callee3);
195
+ }, _callee2);
430
196
  }));
431
- return function onChange(_x) {
197
+ return function (_x) {
432
198
  return _ref4.apply(this, arguments);
433
199
  };
434
- }();
435
- unsub = subscribe(onChange);
200
+ }());
436
201
  }));
437
202
  case 3:
438
203
  case "end":
439
- return _context4.stop();
204
+ return _context3.stop();
440
205
  }
441
- }, _callee4);
206
+ }, _callee3);
442
207
  }));
443
208
  return function waitForIdle() {
444
209
  return _ref2.apply(this, arguments);
445
210
  };
446
211
  }();
212
+ var installIfNeeded = function installIfNeeded() {
213
+ if (g.installed) return;
214
+ g.originalFetch = window.fetch;
215
+ if (typeof g.originalFetch === 'function') {
216
+ window.fetch = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
217
+ var _len,
218
+ args,
219
+ _key,
220
+ input,
221
+ init,
222
+ track,
223
+ _args4 = arguments;
224
+ return _regeneratorRuntime.wrap(function (_context4) {
225
+ while (1) switch (_context4.prev = _context4.next) {
226
+ case 0:
227
+ for (_len = _args4.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
228
+ args[_key] = _args4[_key];
229
+ }
230
+ input = args[0], init = args[1]; // rewrite
231
+ if (typeof input === 'string') input = rewriteApiUrl(input);else if (input instanceof Request) input = new Request(rewriteApiUrl(input.url), input);
232
+ track = is3dAssetUrl(input);
233
+ if (track) {
234
+ _context4.next = 1;
235
+ break;
236
+ }
237
+ return _context4.abrupt("return", g.originalFetch.call(this, input, init));
238
+ case 1:
239
+ g.inFlight += 1;
240
+ notify();
241
+ _context4.prev = 2;
242
+ _context4.next = 3;
243
+ return g.originalFetch.call(this, input, init);
244
+ case 3:
245
+ return _context4.abrupt("return", _context4.sent);
246
+ case 4:
247
+ _context4.prev = 4;
248
+ g.inFlight -= 1;
249
+ if (g.inFlight < 0) g.inFlight = 0;
250
+ notify();
251
+ return _context4.finish(4);
252
+ case 5:
253
+ case "end":
254
+ return _context4.stop();
255
+ }
256
+ }, _callee4, this, [[2,, 4, 5]]);
257
+ }));
258
+ }
259
+ g.installed = true;
260
+ };
447
261
  var uninstall = function uninstall() {
448
- var _XHR$prototype3, _XHR$prototype4;
449
262
  g.refCount -= 1;
450
- log('uninstall tracker refCount--', g.refCount);
451
263
  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
264
  if (typeof g.originalFetch === 'function') window.fetch = g.originalFetch;
457
265
  g.listeners.clear();
458
266
  g.inFlight = 0;
459
267
  g.installed = false;
460
268
  g.originalFetch = null;
461
- g.originalOpen = null;
462
- g.originalSend = null;
463
269
  };
464
270
  g.refCount += 1;
465
- log('install tracker refCount++', g.refCount);
466
271
  installIfNeeded();
467
272
  return {
468
273
  getInFlight: function getInFlight() {
469
274
  return g.inFlight;
470
275
  },
276
+ subscribe: subscribe,
471
277
  waitForIdle: waitForIdle,
472
- uninstall: uninstall,
473
- subscribe: subscribe
278
+ uninstall: uninstall
474
279
  };
475
280
  }
281
+
282
+ // ---------------- simple render + simple API ----------------
476
283
  export function renderKitchenSimulator(container) {
477
- var _props$framesPerEvent, _props$waitForGltfIdl, _props$gltfTimeoutMs;
478
284
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
479
285
  if (!container) throw new Error('renderKitchenSimulator: container is required');
480
- var DEBUG_KEY = '__kitchenSimulatorDebug__';
481
- var debugEnabled = !!props.debug || typeof window !== 'undefined' && !!window[DEBUG_KEY];
482
- var _makeLogger2 = makeLogger(function () {
483
- return debugEnabled;
484
- }),
485
- log = _makeLogger2.log,
486
- warn = _makeLogger2.warn,
487
- error = _makeLogger2.error;
488
286
 
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
- }
521
-
522
- // ✅ Reuse existing API
287
+ // reuse API if already mounted
523
288
  if (container[API_KEY]) {
524
- var _container$API_KEY$__, _container$API_KEY;
525
- log('Reusing existing API; calling __render with new props');
526
- (_container$API_KEY$__ = (_container$API_KEY = container[API_KEY]).__render) === null || _container$API_KEY$__ === void 0 || _container$API_KEY$__.call(_container$API_KEY, props);
289
+ container[API_KEY].__render(props);
527
290
  return container[API_KEY];
528
291
  }
529
292
 
530
- // Root
293
+ // reuse root
531
294
  var root = container[ROOT_KEY];
532
295
  if (!root) {
533
296
  root = createRoot(container);
534
297
  container[ROOT_KEY] = root;
535
- log('Created new React root');
536
298
  }
537
- var setExternalEventFn = null;
299
+ var gltfTracker = installGltfTracker();
538
300
  var destroyed = false;
539
- var queue = [];
540
- var pendingMarkers = new Set();
541
- var MARKER = Symbol('marker');
542
- var gltfTracker = installGltfTracker(debugEnabled);
543
- var defaultFramesPerEvent = (_props$framesPerEvent = props.framesPerEvent) !== null && _props$framesPerEvent !== void 0 ? _props$framesPerEvent : 1;
544
- var waitForAssets = (_props$waitForGltfIdl = props.waitForGltfIdleAfterEachEvent) !== null && _props$waitForGltfIdl !== void 0 ? _props$waitForGltfIdl : true;
545
- var defaultTimeout = (_props$gltfTimeoutMs = props.gltfTimeoutMs) !== null && _props$gltfTimeoutMs !== void 0 ? _props$gltfTimeoutMs : 30000;
546
- var draining = false;
301
+ var setExternalEvent = null;
547
302
 
548
- // ---- Ready gate (super important for first event) ----
549
- var readyResolve = null;
550
- var readyReject = null;
551
- var readyPromise = new Promise(function (res, rej) {
552
- readyResolve = res;
553
- readyReject = rej;
303
+ // mounted gate (first-event safety)
304
+ var mountedResolve;
305
+ var mounted = new Promise(function (res) {
306
+ return mountedResolve = res;
554
307
  });
555
-
556
- // ---- RAF diagnostic wrapper ----
557
- function nextFrameDiag() {
558
- var label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'raf';
559
- var warnAfterMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
560
- if (typeof window === 'undefined') return Promise.resolve();
561
- return new Promise(function (resolve) {
562
- var done = false;
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
- });
308
+ var nextFrame = function nextFrame() {
309
+ return new Promise(function (r) {
310
+ return requestAnimationFrame(r);
592
311
  });
593
- }
594
- function isSyncScene(ev) {
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) {
599
- return _settle.apply(this, arguments);
600
- }
601
- function _settle() {
602
- _settle = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(ev, meta) {
603
- var _ev$framesPerEvent, _ev$waitForGltfIdleAf, _ev$gltfTimeoutMs, _document7, _document8;
604
- var frames, shouldWait, timeoutMs, i, start;
605
- return _regeneratorRuntime.wrap(function (_context8) {
606
- while (1) switch (_context8.prev = _context8.next) {
607
- case 0:
608
- frames = (_ev$framesPerEvent = ev === null || ev === void 0 ? void 0 : ev.framesPerEvent) !== null && _ev$framesPerEvent !== void 0 ? _ev$framesPerEvent : defaultFramesPerEvent;
609
- 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)
620
- i = 0;
621
- case 1:
622
- if (!(i < frames)) {
623
- _context8.next = 4;
624
- break;
625
- }
626
- _context8.next = 2;
627
- return nextFrameDiag("settle:frame ".concat(i + 1, "/").concat(frames), 500);
628
- case 2:
629
- if (debugEnabled) log('settle:after frame', _objectSpread(_objectSpread({}, meta), {}, {
630
- i: i + 1
631
- }));
632
- case 3:
633
- i += 1;
634
- _context8.next = 1;
635
- break;
636
- case 4:
637
- if (!shouldWait) {
638
- _context8.next = 6;
639
- break;
640
- }
641
- start = Date.now();
642
- log('settle:waitForIdle start', _objectSpread(_objectSpread({}, meta), {}, {
643
- timeoutMs: timeoutMs,
644
- gltfInFlight: gltfTracker.getInFlight()
645
- }));
646
- _context8.next = 5;
647
- return gltfTracker.waitForIdle({
648
- timeoutMs: timeoutMs
649
- });
650
- 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
- case "end":
669
- return _context8.stop();
670
- }
671
- }, _callee8);
672
- }));
673
- return _settle.apply(this, arguments);
674
- }
675
- function drain() {
676
- return _drain.apply(this, arguments);
677
- }
678
- function _drain() {
679
- _drain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
680
- var watchdog, item, meta, _err$message2, _t2;
681
- return _regeneratorRuntime.wrap(function (_context9) {
682
- while (1) switch (_context9.prev = _context9.next) {
683
- case 0:
684
- if (!(draining || destroyed)) {
685
- _context9.next = 1;
686
- break;
687
- }
688
- if (debugEnabled) log('drain:skip', {
689
- draining: draining,
690
- destroyed: destroyed,
691
- queueLength: queue.length
692
- });
693
- return _context9.abrupt("return");
694
- case 1:
695
- draining = true;
696
-
697
- // Watchdog: if we’re “stuck” in draining, dump state periodically
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;
712
- return readyPromise;
713
- case 3:
714
- if (!(!destroyed && queue.length)) {
715
- _context9.next = 11;
716
- break;
717
- }
718
- if (setExternalEventFn) {
719
- _context9.next = 5;
720
- break;
721
- }
722
- warn('drain: no setExternalEventFn even after ready (unexpected)');
723
- _context9.next = 4;
724
- return nextFrameDiag('drain:waiting for setExternalEventFn', 500);
725
- case 4:
726
- return _context9.abrupt("continue", 3);
727
- case 5:
728
- item = queue.shift();
729
- if (!(item && item.__marker === MARKER)) {
730
- _context9.next = 6;
731
- break;
732
- }
733
- pendingMarkers["delete"](item.token);
734
- log('drain:marker consumed', {
735
- pendingMarkers: pendingMarkers.size,
736
- queueLength: queue.length
737
- });
738
- return _context9.abrupt("continue", 3);
739
- case 6:
740
- meta = {
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;
748
- setExternalEventFn(item);
749
- log('drain:setExternalEventFn called', meta);
750
- _context9.next = 8;
751
- return settle(item, meta);
752
- case 8:
753
- log('drain:event done', meta);
754
- _context9.next = 10;
755
- break;
756
- case 9:
757
- _context9.prev = 9;
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;
764
- break;
765
- case 11:
766
- _context9.prev = 11;
767
- clearInterval(watchdog);
768
- draining = false;
769
- log('drain:done', {
770
- destroyed: destroyed,
771
- queueLength: queue.length,
772
- pendingMarkers: pendingMarkers.size,
773
- gltfInFlight: gltfTracker.getInFlight()
774
- });
775
- return _context9.finish(11);
776
- case 12:
777
- case "end":
778
- return _context9.stop();
779
- }
780
- }, _callee9, null, [[2,, 11, 12], [7, 9]]);
781
- }));
782
- return _drain.apply(this, arguments);
783
- }
312
+ };
784
313
  var Wrapper = /*#__PURE__*/function (_React$Component) {
785
314
  function Wrapper(p) {
786
- var _this2;
315
+ var _this;
787
316
  _classCallCheck(this, Wrapper);
788
- _this2 = _callSuper(this, Wrapper, [p]);
789
- _this2.state = {
790
- externalEvent: p.externalEvent || null
317
+ _this = _callSuper(this, Wrapper, [p]);
318
+ _this.state = {
319
+ externalEvent: null
791
320
  };
792
- _this2._mounted = false;
793
- return _this2;
321
+ return _this;
794
322
  }
795
323
  _inherits(Wrapper, _React$Component);
796
324
  return _createClass(Wrapper, [{
797
325
  key: "componentDidMount",
798
326
  value: function componentDidMount() {
799
- var _this3 = this;
800
- this._mounted = true;
801
- log('Wrapper mounted -> ready');
802
- setExternalEventFn = function setExternalEventFn(newEvent) {
803
- if (!_this3._mounted) return;
804
- log('Wrapper setState(externalEvent)', {
805
- type: newEvent === null || newEvent === void 0 ? void 0 : newEvent.type
806
- });
807
- _this3.setState({
808
- externalEvent: newEvent
327
+ var _this2 = this,
328
+ _mountedResolve;
329
+ setExternalEvent = function setExternalEvent(ev) {
330
+ return _this2.setState({
331
+ externalEvent: ev
809
332
  });
810
333
  };
811
-
812
- // resolve readiness here (first time)
813
- if (readyResolve) {
814
- readyResolve(true);
815
- readyResolve = null;
816
- }
334
+ (_mountedResolve = mountedResolve) === null || _mountedResolve === void 0 || _mountedResolve();
335
+ mountedResolve = null;
817
336
  }
818
337
  }, {
819
338
  key: "componentWillUnmount",
820
339
  value: function componentWillUnmount() {
821
- log('Wrapper will unmount');
822
- this._mounted = false;
823
- setExternalEventFn = null;
824
-
825
- // If unmount happens before ready, reject so drain can stop cleanly
826
- if (readyReject) {
827
- readyReject(new Error('Wrapper unmounted before ready'));
828
- readyReject = null;
829
- }
340
+ setExternalEvent = null;
830
341
  }
831
342
  }, {
832
343
  key: "render",
833
344
  value: function render() {
834
- if (debugEnabled) log('Wrapper render', {
835
- hasExternalEvent: !!this.state.externalEvent
836
- });
837
345
  return /*#__PURE__*/React.createElement(LiteRenderer, _extends({}, this.props, {
838
346
  externalEvent: this.state.externalEvent
839
347
  }));
@@ -842,145 +350,112 @@ export function renderKitchenSimulator(container) {
842
350
  }(React.Component);
843
351
  var api = {
844
352
  __render: function __render(nextProps) {
845
- log('__render called', {
846
- debug: !!(nextProps !== null && nextProps !== void 0 && nextProps.debug)
847
- });
848
353
  root.render(/*#__PURE__*/React.createElement(Wrapper, nextProps));
849
354
  },
850
- whenReady: function whenReady() {
851
- return readyPromise;
355
+ // subscribe to gltf inFlight
356
+ subscribeGltfInFlight: function subscribeGltfInFlight(cb) {
357
+ return gltfTracker.subscribe(cb);
852
358
  },
853
359
  getGltfInFlight: function getGltfInFlight() {
854
360
  return gltfTracker.getInFlight();
855
361
  },
856
- subscribeGltfInFlight: function subscribeGltfInFlight(cb) {
857
- return gltfTracker.subscribe(cb);
858
- },
859
- sendExternalEvents: function sendExternalEvents(eventOrEvents) {
860
- var _document3, _document4;
861
- var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
862
- _ref5$timeoutMs = _ref5.timeoutMs,
863
- timeoutMs = _ref5$timeoutMs === void 0 ? 60000 : _ref5$timeoutMs;
864
- var events = Array.isArray(eventOrEvents) ? eventOrEvents : [eventOrEvents];
865
- var batchId = Math.random().toString(16).slice(2);
866
- log('sendExternalEvents:enqueue', {
867
- batchId: batchId,
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;
876
- try {
877
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
878
- var e = _step3.value;
879
- queue.push(e);
880
- }
881
- } catch (err) {
882
- _iterator3.e(err);
883
- } finally {
884
- _iterator3.f();
885
- }
886
- var token = Symbol('batch');
887
- pendingMarkers.add(token);
888
- queue.push({
889
- __marker: MARKER,
890
- token: token
891
- });
892
- log('sendExternalEvents:marker added', {
893
- batchId: batchId,
894
- queueLength: queue.length,
895
- pendingMarkers: pendingMarkers.size
896
- });
897
- drain();
898
- return new Promise(function (resolve) {
899
- var start = Date.now();
900
- var check = /*#__PURE__*/function () {
901
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
902
- var _document5, _document6;
903
- return _regeneratorRuntime.wrap(function (_context7) {
904
- while (1) switch (_context7.prev = _context7.next) {
905
- case 0:
906
- if (destroyed) {
907
- _context7.next = 4;
908
- break;
909
- }
910
- if (pendingMarkers.has(token)) {
911
- _context7.next = 1;
912
- break;
913
- }
914
- log('sendExternalEvents:resolved', {
915
- batchId: batchId,
916
- ms: Date.now() - start
917
- });
918
- resolve(true);
919
- return _context7.abrupt("return");
920
- case 1:
921
- if (!(Date.now() - start > timeoutMs)) {
922
- _context7.next = 2;
923
- break;
924
- }
925
- error('sendExternalEvents timed out', {
926
- batchId: batchId,
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
934
- });
935
- pendingMarkers["delete"](token); // fail-open
936
- resolve(false);
937
- return _context7.abrupt("return");
938
- case 2:
939
- _context7.next = 3;
940
- return nextFrameDiag("sendExternalEvents:waiting batch=".concat(batchId), 1000);
941
- case 3:
942
- _context7.next = 0;
943
- break;
944
- case 4:
945
- resolve(false);
946
- case 5:
947
- case "end":
948
- return _context7.stop();
362
+ // VERY SIMPLE batch sender
363
+ sendExternalEvents: function sendExternalEvents(events) {
364
+ var _arguments = arguments;
365
+ return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
366
+ var opts, _opts$framesPerEvent, framesPerEvent, _opts$heavyPredicate, heavyPredicate, _opts$gltfTimeoutMs, gltfTimeoutMs, list, _iterator2, _step2, ev, i, isHeavy, _t;
367
+ return _regeneratorRuntime.wrap(function (_context6) {
368
+ while (1) switch (_context6.prev = _context6.next) {
369
+ case 0:
370
+ opts = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : {};
371
+ _opts$framesPerEvent = opts.framesPerEvent, framesPerEvent = _opts$framesPerEvent === void 0 ? 2 : _opts$framesPerEvent, _opts$heavyPredicate = opts.heavyPredicate, heavyPredicate = _opts$heavyPredicate === void 0 ? function (ev) {
372
+ var _ev$type;
373
+ return /ADD_ITEM|LOAD_PROJECT|REPLACE|CHANGE_DOORSTYLE|SET_FINISHING|SET_MOLDING|ADD_ROOM_SHAPE/.test((_ev$type = ev === null || ev === void 0 ? void 0 : ev.type) !== null && _ev$type !== void 0 ? _ev$type : '');
374
+ } : _opts$heavyPredicate, _opts$gltfTimeoutMs = opts.gltfTimeoutMs, gltfTimeoutMs = _opts$gltfTimeoutMs === void 0 ? 30000 : _opts$gltfTimeoutMs;
375
+ list = Array.isArray(events) ? events : [events]; // ensure mounted before first event
376
+ _context6.next = 1;
377
+ return mounted;
378
+ case 1:
379
+ if (!(destroyed || !setExternalEvent)) {
380
+ _context6.next = 2;
381
+ break;
949
382
  }
950
- }, _callee7);
951
- }));
952
- return function check() {
953
- return _ref6.apply(this, arguments);
954
- };
955
- }();
956
- check();
957
- });
958
- },
959
- updateExternalEvent: function updateExternalEvent(e) {
960
- return api.sendExternalEvents(e);
961
- },
962
- clearQueue: function clearQueue() {
963
- queue.length = 0;
964
- pendingMarkers.clear();
383
+ return _context6.abrupt("return", false);
384
+ case 2:
385
+ _iterator2 = _createForOfIteratorHelper(list);
386
+ _context6.prev = 3;
387
+ _iterator2.s();
388
+ case 4:
389
+ if ((_step2 = _iterator2.n()).done) {
390
+ _context6.next = 11;
391
+ break;
392
+ }
393
+ ev = _step2.value;
394
+ if (!destroyed) {
395
+ _context6.next = 5;
396
+ break;
397
+ }
398
+ return _context6.abrupt("return", false);
399
+ case 5:
400
+ // push event
401
+ setExternalEvent(ev);
402
+
403
+ // allow react/redux to process
404
+ i = 0;
405
+ case 6:
406
+ if (!(i < framesPerEvent)) {
407
+ _context6.next = 8;
408
+ break;
409
+ }
410
+ _context6.next = 7;
411
+ return nextFrame();
412
+ case 7:
413
+ i++;
414
+ _context6.next = 6;
415
+ break;
416
+ case 8:
417
+ // optional gltf wait only for heavy events
418
+ isHeavy = !!heavyPredicate(ev);
419
+ if (!isHeavy) {
420
+ _context6.next = 9;
421
+ break;
422
+ }
423
+ _context6.next = 9;
424
+ return gltfTracker.waitForIdle({
425
+ timeoutMs: gltfTimeoutMs
426
+ });
427
+ case 9:
428
+ _context6.next = 10;
429
+ return nextFrame();
430
+ case 10:
431
+ _context6.next = 4;
432
+ break;
433
+ case 11:
434
+ _context6.next = 13;
435
+ break;
436
+ case 12:
437
+ _context6.prev = 12;
438
+ _t = _context6["catch"](3);
439
+ _iterator2.e(_t);
440
+ case 13:
441
+ _context6.prev = 13;
442
+ _iterator2.f();
443
+ return _context6.finish(13);
444
+ case 14:
445
+ return _context6.abrupt("return", true);
446
+ case 15:
447
+ case "end":
448
+ return _context6.stop();
449
+ }
450
+ }, _callee6, null, [[3, 12, 13, 14]]);
451
+ }))();
965
452
  },
966
453
  unmount: function unmount() {
967
454
  destroyed = true;
968
- api.clearQueue();
969
455
  gltfTracker.uninstall();
970
- try {
971
- if (longTaskObserver) longTaskObserver.disconnect();
972
- } catch (_unused4) {
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);
456
+ root.unmount();
457
+ container[ROOT_KEY] = null;
458
+ container[API_KEY] = null;
984
459
  }
985
460
  };
986
461
  api.__render(props);