kitchen-simulator 4.0.0-queuedEvents → 4.0.0

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