kitchen-simulator 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.js +59 -29
- package/lib/index.js +59 -29
- package/package.json +1 -1
package/es/index.js
CHANGED
|
@@ -14,6 +14,8 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
14
14
|
import React from 'react';
|
|
15
15
|
import LiteRenderer from "./LiteRenderer";
|
|
16
16
|
import { createRoot } from 'react-dom/client';
|
|
17
|
+
var ROOT_KEY = '__kitchenSimulatorRoot__';
|
|
18
|
+
var API_KEY = '__kitchenSimulatorApi__';
|
|
17
19
|
function nextFrame() {
|
|
18
20
|
return new Promise(function (resolve) {
|
|
19
21
|
return requestAnimationFrame(resolve);
|
|
@@ -187,7 +189,7 @@ function installGltfTracker() {
|
|
|
187
189
|
while (1) switch (_context3.prev = _context3.next) {
|
|
188
190
|
case 0:
|
|
189
191
|
_ref3 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, _ref3$timeoutMs = _ref3.timeoutMs, timeoutMs = _ref3$timeoutMs === void 0 ? 30000 : _ref3$timeoutMs, _ref3$graceMs = _ref3.graceMs, graceMs = _ref3$graceMs === void 0 ? 50 : _ref3$graceMs;
|
|
190
|
-
start = Date.now();
|
|
192
|
+
start = Date.now();
|
|
191
193
|
if (!(graceMs > 0)) {
|
|
192
194
|
_context3.next = 1;
|
|
193
195
|
break;
|
|
@@ -196,17 +198,19 @@ function installGltfTracker() {
|
|
|
196
198
|
return sleep(graceMs);
|
|
197
199
|
case 1:
|
|
198
200
|
return _context3.abrupt("return", new Promise(function (resolve, reject) {
|
|
199
|
-
var unsub =
|
|
201
|
+
var unsub = null;
|
|
202
|
+
var onChange = function onChange(count) {
|
|
200
203
|
if (count === 0) {
|
|
201
|
-
unsub();
|
|
204
|
+
if (unsub) unsub(); // ✅ safe
|
|
202
205
|
resolve(true);
|
|
203
206
|
return;
|
|
204
207
|
}
|
|
205
208
|
if (Date.now() - start > timeoutMs) {
|
|
206
|
-
unsub();
|
|
209
|
+
if (unsub) unsub();
|
|
207
210
|
reject(new Error('GLTF did not become idle within timeout'));
|
|
208
211
|
}
|
|
209
|
-
}
|
|
212
|
+
};
|
|
213
|
+
unsub = subscribe(onChange);
|
|
210
214
|
}));
|
|
211
215
|
case 2:
|
|
212
216
|
case "end":
|
|
@@ -237,7 +241,11 @@ function installGltfTracker() {
|
|
|
237
241
|
export function renderKitchenSimulator(container) {
|
|
238
242
|
var _props$framesPerEvent, _props$waitForGltfIdl, _props$gltfTimeoutMs, _props$gltfGraceMs;
|
|
239
243
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
240
|
-
var root =
|
|
244
|
+
var root = container[ROOT_KEY];
|
|
245
|
+
if (!root) {
|
|
246
|
+
root = createRoot(container);
|
|
247
|
+
container[ROOT_KEY] = root;
|
|
248
|
+
}
|
|
241
249
|
var setExternalEventFn = null;
|
|
242
250
|
var queue = [];
|
|
243
251
|
var pendingMarkers = new Set();
|
|
@@ -269,7 +277,7 @@ export function renderKitchenSimulator(container) {
|
|
|
269
277
|
_context5.prev = 2;
|
|
270
278
|
case 3:
|
|
271
279
|
if (!(queue.length && !destroyed)) {
|
|
272
|
-
_context5.next =
|
|
280
|
+
_context5.next = 12;
|
|
273
281
|
break;
|
|
274
282
|
}
|
|
275
283
|
ev = queue.shift(); // skip internal markers
|
|
@@ -280,46 +288,55 @@ export function renderKitchenSimulator(container) {
|
|
|
280
288
|
pendingMarkers["delete"](ev.__batchMarker);
|
|
281
289
|
return _context5.abrupt("continue", 3);
|
|
282
290
|
case 4:
|
|
291
|
+
if (setExternalEventFn) {
|
|
292
|
+
_context5.next = 6;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
_context5.next = 5;
|
|
296
|
+
return nextFrame();
|
|
297
|
+
case 5:
|
|
298
|
+
return _context5.abrupt("continue", 3);
|
|
299
|
+
case 6:
|
|
283
300
|
(_setExternalEventFn = setExternalEventFn) === null || _setExternalEventFn === void 0 || _setExternalEventFn(ev);
|
|
284
301
|
|
|
285
302
|
// baseline spacing for react + legacy lifecycle
|
|
286
303
|
i = 0;
|
|
287
|
-
case
|
|
304
|
+
case 7:
|
|
288
305
|
if (!(i < FRAMES_PER_EVENT)) {
|
|
289
|
-
_context5.next =
|
|
306
|
+
_context5.next = 9;
|
|
290
307
|
break;
|
|
291
308
|
}
|
|
292
|
-
_context5.next =
|
|
309
|
+
_context5.next = 8;
|
|
293
310
|
return nextFrame();
|
|
294
|
-
case
|
|
311
|
+
case 8:
|
|
295
312
|
i += 1;
|
|
296
|
-
_context5.next =
|
|
313
|
+
_context5.next = 7;
|
|
297
314
|
break;
|
|
298
|
-
case
|
|
315
|
+
case 9:
|
|
299
316
|
if (!WAIT_FOR_GLTF_IDLE_AFTER_EACH_EVENT) {
|
|
300
|
-
_context5.next =
|
|
317
|
+
_context5.next = 11;
|
|
301
318
|
break;
|
|
302
319
|
}
|
|
303
|
-
_context5.next =
|
|
320
|
+
_context5.next = 10;
|
|
304
321
|
return gltfTracker.waitForIdle({
|
|
305
322
|
timeoutMs: (_ev$gltfTimeoutMs = ev === null || ev === void 0 ? void 0 : ev.gltfTimeoutMs) !== null && _ev$gltfTimeoutMs !== void 0 ? _ev$gltfTimeoutMs : GLTF_TIMEOUT_MS,
|
|
306
323
|
graceMs: (_ev$gltfGraceMs = ev === null || ev === void 0 ? void 0 : ev.gltfGraceMs) !== null && _ev$gltfGraceMs !== void 0 ? _ev$gltfGraceMs : GLTF_GRACE_MS
|
|
307
324
|
});
|
|
308
|
-
case
|
|
309
|
-
_context5.next =
|
|
325
|
+
case 10:
|
|
326
|
+
_context5.next = 11;
|
|
310
327
|
return nextFrame();
|
|
311
|
-
case
|
|
328
|
+
case 11:
|
|
312
329
|
_context5.next = 3;
|
|
313
330
|
break;
|
|
314
|
-
case
|
|
315
|
-
_context5.prev =
|
|
331
|
+
case 12:
|
|
332
|
+
_context5.prev = 12;
|
|
316
333
|
draining = false;
|
|
317
|
-
return _context5.finish(
|
|
318
|
-
case
|
|
334
|
+
return _context5.finish(12);
|
|
335
|
+
case 13:
|
|
319
336
|
case "end":
|
|
320
337
|
return _context5.stop();
|
|
321
338
|
}
|
|
322
|
-
}, _callee5, null, [[2,,
|
|
339
|
+
}, _callee5, null, [[2,, 12, 13]]);
|
|
323
340
|
}));
|
|
324
341
|
return _drain.apply(this, arguments);
|
|
325
342
|
}
|
|
@@ -331,16 +348,28 @@ export function renderKitchenSimulator(container) {
|
|
|
331
348
|
_this2.state = {
|
|
332
349
|
externalEvent: p.externalEvent || null
|
|
333
350
|
};
|
|
334
|
-
|
|
351
|
+
_this2._mounted = false;
|
|
335
352
|
return _this2;
|
|
336
353
|
}
|
|
337
354
|
_inherits(Wrapper, _React$Component);
|
|
338
355
|
return _createClass(Wrapper, [{
|
|
339
|
-
key: "
|
|
340
|
-
value: function
|
|
341
|
-
this
|
|
342
|
-
|
|
343
|
-
|
|
356
|
+
key: "componentDidMount",
|
|
357
|
+
value: function componentDidMount() {
|
|
358
|
+
var _this3 = this;
|
|
359
|
+
this._mounted = true;
|
|
360
|
+
setExternalEventFn = function setExternalEventFn(newEvent) {
|
|
361
|
+
// ✅ ensure we never setState during render
|
|
362
|
+
if (!_this3._mounted) return;
|
|
363
|
+
_this3.setState({
|
|
364
|
+
externalEvent: newEvent
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}, {
|
|
369
|
+
key: "componentWillUnmount",
|
|
370
|
+
value: function componentWillUnmount() {
|
|
371
|
+
this._mounted = false;
|
|
372
|
+
setExternalEventFn = null;
|
|
344
373
|
}
|
|
345
374
|
}, {
|
|
346
375
|
key: "render",
|
|
@@ -424,6 +453,7 @@ export function renderKitchenSimulator(container) {
|
|
|
424
453
|
(_this$clearQueue = this.clearQueue) === null || _this$clearQueue === void 0 || _this$clearQueue.call(this);
|
|
425
454
|
gltfTracker.uninstall();
|
|
426
455
|
root.unmount();
|
|
456
|
+
container[ROOT_KEY] = null;
|
|
427
457
|
}
|
|
428
458
|
};
|
|
429
459
|
}
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,8 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
22
22
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
23
23
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
24
24
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
25
|
+
var ROOT_KEY = '__kitchenSimulatorRoot__';
|
|
26
|
+
var API_KEY = '__kitchenSimulatorApi__';
|
|
25
27
|
function nextFrame() {
|
|
26
28
|
return new Promise(function (resolve) {
|
|
27
29
|
return requestAnimationFrame(resolve);
|
|
@@ -195,7 +197,7 @@ function installGltfTracker() {
|
|
|
195
197
|
while (1) switch (_context3.prev = _context3.next) {
|
|
196
198
|
case 0:
|
|
197
199
|
_ref3 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, _ref3$timeoutMs = _ref3.timeoutMs, timeoutMs = _ref3$timeoutMs === void 0 ? 30000 : _ref3$timeoutMs, _ref3$graceMs = _ref3.graceMs, graceMs = _ref3$graceMs === void 0 ? 50 : _ref3$graceMs;
|
|
198
|
-
start = Date.now();
|
|
200
|
+
start = Date.now();
|
|
199
201
|
if (!(graceMs > 0)) {
|
|
200
202
|
_context3.next = 1;
|
|
201
203
|
break;
|
|
@@ -204,17 +206,19 @@ function installGltfTracker() {
|
|
|
204
206
|
return sleep(graceMs);
|
|
205
207
|
case 1:
|
|
206
208
|
return _context3.abrupt("return", new Promise(function (resolve, reject) {
|
|
207
|
-
var unsub =
|
|
209
|
+
var unsub = null;
|
|
210
|
+
var onChange = function onChange(count) {
|
|
208
211
|
if (count === 0) {
|
|
209
|
-
unsub();
|
|
212
|
+
if (unsub) unsub(); // ✅ safe
|
|
210
213
|
resolve(true);
|
|
211
214
|
return;
|
|
212
215
|
}
|
|
213
216
|
if (Date.now() - start > timeoutMs) {
|
|
214
|
-
unsub();
|
|
217
|
+
if (unsub) unsub();
|
|
215
218
|
reject(new Error('GLTF did not become idle within timeout'));
|
|
216
219
|
}
|
|
217
|
-
}
|
|
220
|
+
};
|
|
221
|
+
unsub = subscribe(onChange);
|
|
218
222
|
}));
|
|
219
223
|
case 2:
|
|
220
224
|
case "end":
|
|
@@ -245,7 +249,11 @@ function installGltfTracker() {
|
|
|
245
249
|
function renderKitchenSimulator(container) {
|
|
246
250
|
var _props$framesPerEvent, _props$waitForGltfIdl, _props$gltfTimeoutMs, _props$gltfGraceMs;
|
|
247
251
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
248
|
-
var root =
|
|
252
|
+
var root = container[ROOT_KEY];
|
|
253
|
+
if (!root) {
|
|
254
|
+
root = (0, _client.createRoot)(container);
|
|
255
|
+
container[ROOT_KEY] = root;
|
|
256
|
+
}
|
|
249
257
|
var setExternalEventFn = null;
|
|
250
258
|
var queue = [];
|
|
251
259
|
var pendingMarkers = new Set();
|
|
@@ -277,7 +285,7 @@ function renderKitchenSimulator(container) {
|
|
|
277
285
|
_context5.prev = 2;
|
|
278
286
|
case 3:
|
|
279
287
|
if (!(queue.length && !destroyed)) {
|
|
280
|
-
_context5.next =
|
|
288
|
+
_context5.next = 12;
|
|
281
289
|
break;
|
|
282
290
|
}
|
|
283
291
|
ev = queue.shift(); // skip internal markers
|
|
@@ -288,46 +296,55 @@ function renderKitchenSimulator(container) {
|
|
|
288
296
|
pendingMarkers["delete"](ev.__batchMarker);
|
|
289
297
|
return _context5.abrupt("continue", 3);
|
|
290
298
|
case 4:
|
|
299
|
+
if (setExternalEventFn) {
|
|
300
|
+
_context5.next = 6;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
_context5.next = 5;
|
|
304
|
+
return nextFrame();
|
|
305
|
+
case 5:
|
|
306
|
+
return _context5.abrupt("continue", 3);
|
|
307
|
+
case 6:
|
|
291
308
|
(_setExternalEventFn = setExternalEventFn) === null || _setExternalEventFn === void 0 || _setExternalEventFn(ev);
|
|
292
309
|
|
|
293
310
|
// baseline spacing for react + legacy lifecycle
|
|
294
311
|
i = 0;
|
|
295
|
-
case
|
|
312
|
+
case 7:
|
|
296
313
|
if (!(i < FRAMES_PER_EVENT)) {
|
|
297
|
-
_context5.next =
|
|
314
|
+
_context5.next = 9;
|
|
298
315
|
break;
|
|
299
316
|
}
|
|
300
|
-
_context5.next =
|
|
317
|
+
_context5.next = 8;
|
|
301
318
|
return nextFrame();
|
|
302
|
-
case
|
|
319
|
+
case 8:
|
|
303
320
|
i += 1;
|
|
304
|
-
_context5.next =
|
|
321
|
+
_context5.next = 7;
|
|
305
322
|
break;
|
|
306
|
-
case
|
|
323
|
+
case 9:
|
|
307
324
|
if (!WAIT_FOR_GLTF_IDLE_AFTER_EACH_EVENT) {
|
|
308
|
-
_context5.next =
|
|
325
|
+
_context5.next = 11;
|
|
309
326
|
break;
|
|
310
327
|
}
|
|
311
|
-
_context5.next =
|
|
328
|
+
_context5.next = 10;
|
|
312
329
|
return gltfTracker.waitForIdle({
|
|
313
330
|
timeoutMs: (_ev$gltfTimeoutMs = ev === null || ev === void 0 ? void 0 : ev.gltfTimeoutMs) !== null && _ev$gltfTimeoutMs !== void 0 ? _ev$gltfTimeoutMs : GLTF_TIMEOUT_MS,
|
|
314
331
|
graceMs: (_ev$gltfGraceMs = ev === null || ev === void 0 ? void 0 : ev.gltfGraceMs) !== null && _ev$gltfGraceMs !== void 0 ? _ev$gltfGraceMs : GLTF_GRACE_MS
|
|
315
332
|
});
|
|
316
|
-
case
|
|
317
|
-
_context5.next =
|
|
333
|
+
case 10:
|
|
334
|
+
_context5.next = 11;
|
|
318
335
|
return nextFrame();
|
|
319
|
-
case
|
|
336
|
+
case 11:
|
|
320
337
|
_context5.next = 3;
|
|
321
338
|
break;
|
|
322
|
-
case
|
|
323
|
-
_context5.prev =
|
|
339
|
+
case 12:
|
|
340
|
+
_context5.prev = 12;
|
|
324
341
|
draining = false;
|
|
325
|
-
return _context5.finish(
|
|
326
|
-
case
|
|
342
|
+
return _context5.finish(12);
|
|
343
|
+
case 13:
|
|
327
344
|
case "end":
|
|
328
345
|
return _context5.stop();
|
|
329
346
|
}
|
|
330
|
-
}, _callee5, null, [[2,,
|
|
347
|
+
}, _callee5, null, [[2,, 12, 13]]);
|
|
331
348
|
}));
|
|
332
349
|
return _drain.apply(this, arguments);
|
|
333
350
|
}
|
|
@@ -339,16 +356,28 @@ function renderKitchenSimulator(container) {
|
|
|
339
356
|
_this2.state = {
|
|
340
357
|
externalEvent: p.externalEvent || null
|
|
341
358
|
};
|
|
342
|
-
|
|
359
|
+
_this2._mounted = false;
|
|
343
360
|
return _this2;
|
|
344
361
|
}
|
|
345
362
|
(0, _inherits2["default"])(Wrapper, _React$Component);
|
|
346
363
|
return (0, _createClass2["default"])(Wrapper, [{
|
|
347
|
-
key: "
|
|
348
|
-
value: function
|
|
349
|
-
this
|
|
350
|
-
|
|
351
|
-
|
|
364
|
+
key: "componentDidMount",
|
|
365
|
+
value: function componentDidMount() {
|
|
366
|
+
var _this3 = this;
|
|
367
|
+
this._mounted = true;
|
|
368
|
+
setExternalEventFn = function setExternalEventFn(newEvent) {
|
|
369
|
+
// ✅ ensure we never setState during render
|
|
370
|
+
if (!_this3._mounted) return;
|
|
371
|
+
_this3.setState({
|
|
372
|
+
externalEvent: newEvent
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
key: "componentWillUnmount",
|
|
378
|
+
value: function componentWillUnmount() {
|
|
379
|
+
this._mounted = false;
|
|
380
|
+
setExternalEventFn = null;
|
|
352
381
|
}
|
|
353
382
|
}, {
|
|
354
383
|
key: "render",
|
|
@@ -432,6 +461,7 @@ function renderKitchenSimulator(container) {
|
|
|
432
461
|
(_this$clearQueue = this.clearQueue) === null || _this$clearQueue === void 0 || _this$clearQueue.call(this);
|
|
433
462
|
gltfTracker.uninstall();
|
|
434
463
|
root.unmount();
|
|
464
|
+
container[ROOT_KEY] = null;
|
|
435
465
|
}
|
|
436
466
|
};
|
|
437
467
|
}
|