targetj 1.1.0 → 1.1.1

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.
@@ -256,10 +256,10 @@ var ParticleUtil = /*#__PURE__*/function () {
256
256
  }
257
257
  }]);
258
258
  }();
259
- _defineProperty(ParticleUtil, "gpuRenderTargets", new Set(["x", "y", "width", "height", "borderRadius", "backgroundColor", "rotate", "opacity", "scale"]));
259
+ _defineProperty(ParticleUtil, "gpuRenderTargets", new Set(["x", "y", "width", "height", "borderRadius", "backgroundColor", "rotate", "opacity", "scale", "image"]));
260
260
  _defineProperty(ParticleUtil, "gpuRenderAliases", {
261
261
  background: "backgroundColor"
262
262
  });
263
263
  _defineProperty(ParticleUtil, "childrenTargets", new Set(["addChildren", "children"]));
264
- _defineProperty(ParticleUtil, "transientRuntimeFields", new Set(["particleRenderer", "childHandles", "particleValuesDirty", "particleRenderRequested", "pendingGpuChildren", "layoutEpoch", "completeLayoutEpoch", "completeChildrenLayoutState", "layoutCompleteWaiters", "particleSyncPromise", "restoringParticleRuntime"]));
264
+ _defineProperty(ParticleUtil, "transientRuntimeFields", new Set(["particleRenderer", "childHandles", "particleValuesDirty", "particleRenderRequested", "pendingGpuChildren", "explodeCapturePromise", "layoutEpoch", "completeLayoutEpoch", "completeLayoutState", "layoutCompleteWaiters", "particleSyncPromise", "restoringParticleRuntime"]));
265
265
  export { ParticleUtil };
@@ -77,10 +77,15 @@ var RunScheduler = /*#__PURE__*/function () {
77
77
  }, {
78
78
  key: "scheduleOnlyIfEarlier",
79
79
  value: function scheduleOnlyIfEarlier(delay, runId) {
80
- var _this$runStartTime;
81
- var base = this.runningFlag ? (_this$runStartTime = this.runStartTime) !== null && _this$runStartTime !== void 0 ? _this$runStartTime : TUtil.now() : TUtil.now();
82
- var runTime = base + (delay !== null && delay !== void 0 ? delay : 0);
83
- if (this.delayProcess && runTime >= this.delayProcess.runTime) {
80
+ var _this$delayProcess$ru, _this$delayProcess;
81
+ if (!tApp.isRunning() || this.resetting) {
82
+ return;
83
+ }
84
+ var effectiveDelay = tApp.throttle === 0 ? Math.max(0, delay !== null && delay !== void 0 ? delay : 0) : tApp.throttle;
85
+ var requestedTime = TUtil.now() + effectiveDelay;
86
+ var activeTime = (_this$delayProcess$ru = (_this$delayProcess = this.delayProcess) === null || _this$delayProcess === void 0 ? void 0 : _this$delayProcess.runTime) !== null && _this$delayProcess$ru !== void 0 ? _this$delayProcess$ru : Infinity;
87
+ var queuedTime = this.nextRuns.length ? this.nextRuns[0].insertTime + this.nextRuns[0].delay : Infinity;
88
+ if (Math.min(activeTime, queuedTime) <= requestedTime) {
84
89
  return;
85
90
  }
86
91
  this.schedule(delay, runId);
@@ -99,7 +104,7 @@ var RunScheduler = /*#__PURE__*/function () {
99
104
  key: "run",
100
105
  value: function () {
101
106
  var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(delay, runId) {
102
- var handedOff, _this$delayProcess, capturedEvent, type, activatedStep;
107
+ var handedOff, _this$delayProcess2, capturedEvent, type, activatedStep;
103
108
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
104
109
  while (1) switch (_context2.prev = _context2.next) {
105
110
  case 0:
@@ -124,7 +129,7 @@ var RunScheduler = /*#__PURE__*/function () {
124
129
  this.runStartTime = TUtil.now();
125
130
  handedOff = false;
126
131
  if (tApp.debugLevel === 1) {
127
- TUtil.log(true)("Request from: ".concat(runId, " delay: ").concat(delay, " runningStep:").concat(this.runningStep, " dom:").concat(this.domProcessing, " runs:").concat(this.nextRuns.length, " D:").concat((_this$delayProcess = this.delayProcess) === null || _this$delayProcess === void 0 ? void 0 : _this$delayProcess.delay, " events:").concat(getEvents().eventQueue.length));
132
+ TUtil.log(true)("Request from: ".concat(runId, " delay: ").concat(delay, " runningStep:").concat(this.runningStep, " dom:").concat(this.domProcessing, " runs:").concat(this.nextRuns.length, " D:").concat((_this$delayProcess2 = this.delayProcess) === null || _this$delayProcess2 === void 0 ? void 0 : _this$delayProcess2.delay, " events:").concat(getEvents().eventQueue.length));
128
133
  }
129
134
  _context2.prev = 11;
130
135
  if (!(this.phase === 0)) {
@@ -321,8 +326,8 @@ var RunScheduler = /*#__PURE__*/function () {
321
326
  }, {
322
327
  key: "clearDelayProcess",
323
328
  value: function clearDelayProcess() {
324
- var _this$delayProcess2;
325
- if ((_this$delayProcess2 = this.delayProcess) !== null && _this$delayProcess2 !== void 0 && _this$delayProcess2.timeoutId) {
329
+ var _this$delayProcess3;
330
+ if ((_this$delayProcess3 = this.delayProcess) !== null && _this$delayProcess3 !== void 0 && _this$delayProcess3.timeoutId) {
326
331
  clearTimeout(this.delayProcess.timeoutId);
327
332
  this.delayProcess.timeoutId = undefined;
328
333
  }
@@ -29,6 +29,7 @@ import { $Dom } from "./$Dom.js";
29
29
  import { TargetUtil } from "./TargetUtil.js";
30
30
  import { TModelUtil } from "./TModelUtil.js";
31
31
  import { TModel } from "./TModel.js";
32
+ import { ParticleTModel } from "./ParticleTModel.js";
32
33
  import { StateUtil } from "./StateUtil.js";
33
34
  /**
34
35
  * It enables storing and restoring state.
@@ -37,6 +38,7 @@ var StateManager = /*#__PURE__*/function () {
37
38
  function StateManager() {
38
39
  _classCallCheck(this, StateManager);
39
40
  this.stateCheckpoints = {};
41
+ this.restoreQueue = Promise.resolve();
40
42
  }
41
43
  return _createClass(StateManager, [{
42
44
  key: "store",
@@ -46,6 +48,7 @@ var StateManager = /*#__PURE__*/function () {
46
48
  runSnapshot,
47
49
  $pageDom,
48
50
  checkpoint,
51
+ template,
49
52
  _args = arguments;
50
53
  return _regeneratorRuntime().wrap(function _callee$(_context) {
51
54
  while (1) switch (_context.prev = _context.next) {
@@ -69,6 +72,10 @@ var StateManager = /*#__PURE__*/function () {
69
72
  return this.captureGpuVisuals();
70
73
  case 17:
71
74
  _context.t11 = _context.sent;
75
+ _context.next = 20;
76
+ return this.captureExplodeSources();
77
+ case 20:
78
+ _context.t12 = _context.sent;
72
79
  checkpoint = {
73
80
  key: _context.t0,
74
81
  capturedAt: _context.t1,
@@ -81,12 +88,16 @@ var StateManager = /*#__PURE__*/function () {
81
88
  scrollLeft: _context.t8,
82
89
  scrollTop: _context.t9,
83
90
  runSnapshot: _context.t10,
84
- gpuVisuals: _context.t11
91
+ gpuVisuals: _context.t11,
92
+ explodeSources: _context.t12
85
93
  };
86
- this.releaseGpuVisuals(this.stateCheckpoints[key]);
94
+ template = document.createElement("template");
95
+ template.innerHTML = checkpoint.html;
96
+ checkpoint.domTemplate = template;
97
+ this.releaseGpuResources(this.stateCheckpoints[key]);
87
98
  this.stateCheckpoints[key] = checkpoint;
88
99
  return _context.abrupt("return", checkpoint);
89
- case 22:
100
+ case 28:
90
101
  case "end":
91
102
  return _context.stop();
92
103
  }
@@ -99,8 +110,21 @@ var StateManager = /*#__PURE__*/function () {
99
110
  }()
100
111
  }, {
101
112
  key: "restore",
113
+ value: function restore() {
114
+ var _this = this;
115
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
116
+ var promise = this.restoreQueue.then(function () {
117
+ return _this.restoreCheckpoint(key);
118
+ });
119
+ this.restoreQueue = promise.catch(function (error) {
120
+ console.error("State restoration failed:", error);
121
+ });
122
+ return promise;
123
+ }
124
+ }, {
125
+ key: "restoreCheckpoint",
102
126
  value: function () {
103
- var _restore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
127
+ var _restoreCheckpoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
104
128
  var key,
105
129
  checkpoint,
106
130
  timeOffset,
@@ -109,9 +133,12 @@ var StateManager = /*#__PURE__*/function () {
109
133
  tmodelIdMap,
110
134
  models,
111
135
  $pageDom,
136
+ fragment,
112
137
  visibleModels,
113
138
  restoredWithDom,
114
139
  $restoredPageDom,
140
+ gpuModels,
141
+ index,
115
142
  _args2 = arguments;
116
143
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
117
144
  while (1) switch (_context2.prev = _context2.next) {
@@ -128,11 +155,16 @@ var StateManager = /*#__PURE__*/function () {
128
155
  case 6:
129
156
  getLoader().clear();
130
157
  _context2.next = 9;
131
- return tApp.stop();
158
+ return tApp.stop({
159
+ discardState: true
160
+ });
132
161
  case 9:
133
162
  getLocationManager().cancelCurrentCalculation();
134
163
  _context2.next = 12;
135
- return tApp.reset();
164
+ return tApp.reset({
165
+ discardState: true,
166
+ skipSchedulerReset: true
167
+ });
136
168
  case 12:
137
169
  App.oids = {};
138
170
  App.tmodelIdMap = {};
@@ -145,7 +177,8 @@ var StateManager = /*#__PURE__*/function () {
145
177
  App.tmodelIdMap = tmodelIdMap;
146
178
  getLoader().restoreRuntimeSnapshot(checkpoint.loaderSnapshot, tmodelIdMap);
147
179
  $pageDom = TModelUtil.getPageDom();
148
- $pageDom.innerHTML(checkpoint.html);
180
+ fragment = checkpoint.domTemplate.content.cloneNode(true);
181
+ $pageDom.getElement().replaceChildren(fragment);
149
182
  TModelUtil.restoreMountedDom($pageDom, checkpoint.domState);
150
183
  this.showGpuRestoreVisuals(checkpoint.gpuVisuals);
151
184
  tApp.tRoot.$dom = TModelUtil.getRootDom();
@@ -157,36 +190,43 @@ var StateManager = /*#__PURE__*/function () {
157
190
  restoredDoneTargets: true
158
191
  });
159
192
  tApp.tRoot.markLayoutDirty("checkpointRestore");
160
- _context2.next = 31;
161
- return tApp.start();
162
- case 31:
193
+ _context2.next = 32;
194
+ return tApp.start({
195
+ skipSchedulerReset: true
196
+ });
197
+ case 32:
163
198
  $restoredPageDom = TModelUtil.getPageDom();
164
199
  TModelUtil.restoreMountedDom($restoredPageDom, checkpoint.domState);
165
- _context2.next = 35;
200
+ _context2.next = 36;
166
201
  return TModelUtil.restoreScroll(checkpoint);
167
- case 35:
168
- _context2.next = 37;
202
+ case 36:
203
+ _context2.next = 38;
169
204
  return TModelUtil.restoreDomInteractionState($restoredPageDom, checkpoint.domState);
170
- case 37:
171
- _context2.next = 39;
172
- return Promise.all(models.map(function (tmodel) {
173
- var _tmodel$restoreRuntim;
174
- return (_tmodel$restoreRuntim = tmodel.restoreRuntimeDomDerivedState) === null || _tmodel$restoreRuntim === void 0 ? void 0 : _tmodel$restoreRuntim.call(tmodel);
205
+ case 38:
206
+ gpuModels = models.filter(function (tmodel) {
207
+ return tmodel instanceof ParticleTModel;
208
+ });
209
+ _context2.next = 41;
210
+ return Promise.all(gpuModels.map(function (tmodel) {
211
+ return tmodel.restoreRuntimeDomDerivedState(checkpoint.explodeSources[tmodel.oid]);
175
212
  }));
176
- case 39:
213
+ case 41:
214
+ for (index = 0; index < gpuModels.length; index++) {
215
+ gpuModels[index].particleRuntime.resumeRestored();
216
+ }
177
217
  this.hideGpuRestoreVisuals();
178
218
  getRunScheduler().restoreSnapshot(checkpoint.runSnapshot);
179
219
  return _context2.abrupt("return", true);
180
- case 42:
220
+ case 45:
181
221
  case "end":
182
222
  return _context2.stop();
183
223
  }
184
224
  }, _callee2, this);
185
225
  }));
186
- function restore() {
187
- return _restore.apply(this, arguments);
226
+ function restoreCheckpoint() {
227
+ return _restoreCheckpoint.apply(this, arguments);
188
228
  }
189
- return restore;
229
+ return restoreCheckpoint;
190
230
  }()
191
231
  }, {
192
232
  key: "syncAnimationsForCheckpoint",
@@ -388,6 +428,53 @@ var StateManager = /*#__PURE__*/function () {
388
428
  }
389
429
  return captureGpuVisuals;
390
430
  }()
431
+ }, {
432
+ key: "captureExplodeSources",
433
+ value: function () {
434
+ var _captureExplodeSources = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
435
+ var sources, _i2, _Object$values2, _renderer$captureExpl, tmodel, renderer, source;
436
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
437
+ while (1) switch (_context4.prev = _context4.next) {
438
+ case 0:
439
+ sources = {};
440
+ _i2 = 0, _Object$values2 = Object.values(App.tmodelIdMap);
441
+ case 2:
442
+ if (!(_i2 < _Object$values2.length)) {
443
+ _context4.next = 14;
444
+ break;
445
+ }
446
+ tmodel = _Object$values2[_i2];
447
+ renderer = tmodel.particleRenderer;
448
+ if (!(!renderer || !tmodel.explodeChildrenState)) {
449
+ _context4.next = 7;
450
+ break;
451
+ }
452
+ return _context4.abrupt("continue", 11);
453
+ case 7:
454
+ _context4.next = 9;
455
+ return (_renderer$captureExpl = renderer.captureExplodeSourceBitmap) === null || _renderer$captureExpl === void 0 ? void 0 : _renderer$captureExpl.call(renderer);
456
+ case 9:
457
+ source = _context4.sent;
458
+ if (source) {
459
+ sources[tmodel.oid] = source;
460
+ }
461
+ case 11:
462
+ _i2++;
463
+ _context4.next = 2;
464
+ break;
465
+ case 14:
466
+ return _context4.abrupt("return", sources);
467
+ case 15:
468
+ case "end":
469
+ return _context4.stop();
470
+ }
471
+ }, _callee4);
472
+ }));
473
+ function captureExplodeSources() {
474
+ return _captureExplodeSources.apply(this, arguments);
475
+ }
476
+ return captureExplodeSources;
477
+ }()
391
478
  }, {
392
479
  key: "showGpuRestoreVisuals",
393
480
  value: function showGpuRestoreVisuals(visuals) {
@@ -406,8 +493,8 @@ var StateManager = /*#__PURE__*/function () {
406
493
  pointerEvents: "none",
407
494
  zIndex: "2147483647"
408
495
  });
409
- for (var _i2 = 0, _Object$values2 = Object.values(visuals); _i2 < _Object$values2.length; _i2++) {
410
- var visual = _Object$values2[_i2];
496
+ for (var _i3 = 0, _Object$values3 = Object.values(visuals); _i3 < _Object$values3.length; _i3++) {
497
+ var visual = _Object$values3[_i3];
411
498
  if (!(visual !== null && visual !== void 0 && visual.bitmap) || visual.clipWidth <= 0 || visual.clipHeight <= 0) {
412
499
  continue;
413
500
  }
@@ -445,13 +532,18 @@ var StateManager = /*#__PURE__*/function () {
445
532
  (_document$querySelect = document.querySelector('[data-targetjs-gpu-restore-overlay="true"]')) === null || _document$querySelect === void 0 || _document$querySelect.remove();
446
533
  }
447
534
  }, {
448
- key: "releaseGpuVisuals",
449
- value: function releaseGpuVisuals(checkpoint) {
450
- for (var _i3 = 0, _Object$values3 = Object.values((checkpoint === null || checkpoint === void 0 ? void 0 : checkpoint.gpuVisuals) || {}); _i3 < _Object$values3.length; _i3++) {
535
+ key: "releaseGpuResources",
536
+ value: function releaseGpuResources(checkpoint) {
537
+ for (var _i4 = 0, _Object$values4 = Object.values((checkpoint === null || checkpoint === void 0 ? void 0 : checkpoint.gpuVisuals) || {}); _i4 < _Object$values4.length; _i4++) {
451
538
  var _visual$bitmap, _visual$bitmap$close, _visual$bitmap2;
452
- var visual = _Object$values3[_i3];
539
+ var visual = _Object$values4[_i4];
453
540
  visual === null || visual === void 0 || (_visual$bitmap = visual.bitmap) === null || _visual$bitmap === void 0 || (_visual$bitmap$close = (_visual$bitmap2 = _visual$bitmap).close) === null || _visual$bitmap$close === void 0 || _visual$bitmap$close.call(_visual$bitmap2);
454
541
  }
542
+ for (var _i5 = 0, _Object$values5 = Object.values((checkpoint === null || checkpoint === void 0 ? void 0 : checkpoint.explodeSources) || {}); _i5 < _Object$values5.length; _i5++) {
543
+ var _source$close;
544
+ var source = _Object$values5[_i5];
545
+ source === null || source === void 0 || (_source$close = source.close) === null || _source$close === void 0 || _source$close.call(source);
546
+ }
455
547
  }
456
548
  }, {
457
549
  key: "has",
@@ -479,16 +571,16 @@ var StateManager = /*#__PURE__*/function () {
479
571
  if (!checkpoint) {
480
572
  return false;
481
573
  }
482
- this.releaseGpuVisuals(checkpoint);
574
+ this.releaseGpuResources(checkpoint);
483
575
  delete this.stateCheckpoints[key];
484
576
  return true;
485
577
  }
486
578
  }, {
487
579
  key: "clearAll",
488
580
  value: function clearAll() {
489
- for (var _i4 = 0, _Object$values4 = Object.values(this.stateCheckpoints); _i4 < _Object$values4.length; _i4++) {
490
- var checkpoint = _Object$values4[_i4];
491
- this.releaseGpuVisuals(checkpoint);
581
+ for (var _i6 = 0, _Object$values6 = Object.values(this.stateCheckpoints); _i6 < _Object$values6.length; _i6++) {
582
+ var checkpoint = _Object$values6[_i6];
583
+ this.releaseGpuResources(checkpoint);
492
584
  }
493
585
  this.stateCheckpoints = {};
494
586
  }