targetj 1.0.255 → 1.0.257

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.
@@ -33,6 +33,7 @@ var RunScheduler = /*#__PURE__*/function () {
33
33
  this.phase = 0;
34
34
  this.runningStep = -1;
35
35
  this.sliceQueued = false;
36
+ this.eventSettlePending = false;
36
37
  }
37
38
  return _createClass(RunScheduler, [{
38
39
  key: "resetRuns",
@@ -61,7 +62,8 @@ var RunScheduler = /*#__PURE__*/function () {
61
62
  this.phase = 0;
62
63
  this.runningStep = -1;
63
64
  this.sliceQueued = false;
64
- case 17:
65
+ this.eventSettlePending = false;
66
+ case 18:
65
67
  case "end":
66
68
  return _context.stop();
67
69
  }
@@ -97,7 +99,7 @@ var RunScheduler = /*#__PURE__*/function () {
97
99
  key: "run",
98
100
  value: function () {
99
101
  var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(delay, runId) {
100
- var handedOff, _this$delayProcess;
102
+ var handedOff, _this$delayProcess, capturedEvent, type, activatedStep;
101
103
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
102
104
  while (1) switch (_context2.prev = _context2.next) {
103
105
  case 0:
@@ -126,49 +128,57 @@ var RunScheduler = /*#__PURE__*/function () {
126
128
  }
127
129
  _context2.prev = 11;
128
130
  if (!(this.phase === 0)) {
129
- _context2.next = 18;
131
+ _context2.next = 19;
130
132
  break;
131
133
  }
132
- getEvents().captureEvents();
134
+ capturedEvent = getEvents().captureEvents();
135
+ if (capturedEvent) {
136
+ type = capturedEvent.eventType;
137
+ this.eventSettlePending = type === 'start' || type === 'end' || type === 'click';
138
+ }
133
139
  tApp.targetManager.applyTargetValues(tRoot());
134
- _context2.next = 17;
140
+ _context2.next = 18;
135
141
  return getLocationManager().calculateAll();
136
- case 17:
137
- this.phase = 1;
138
142
  case 18:
143
+ this.phase = 1;
144
+ case 19:
139
145
  if (!(TUtil.now() - this.runStartTime > FRAME_BUDGET_MS)) {
140
- _context2.next = 22;
146
+ _context2.next = 23;
141
147
  break;
142
148
  }
143
149
  handedOff = true;
144
150
  this.requestNextSlice(runId);
145
151
  return _context2.abrupt("return");
146
- case 22:
152
+ case 23:
147
153
  if (this.phase === 1) {
148
154
  this.runningStep = tApp.manager.analyze();
149
155
  this.phase = 2;
150
156
  }
151
157
  if (!(TUtil.now() - this.runStartTime > FRAME_BUDGET_MS)) {
152
- _context2.next = 27;
158
+ _context2.next = 28;
153
159
  break;
154
160
  }
155
161
  handedOff = true;
156
162
  this.requestNextSlice(runId);
157
163
  return _context2.abrupt("return");
158
- case 27:
164
+ case 28:
159
165
  if (this.phase === 2) {
160
166
  getLocationManager().calculateActivated();
161
167
  tApp.events.resetEventsOnTimeout();
168
+ activatedStep = tApp.manager.analyze();
169
+ if (activatedStep >= 0) {
170
+ this.runningStep = this.runningStep < 0 ? activatedStep : Math.min(this.runningStep, activatedStep);
171
+ }
162
172
  this.phase = 3;
163
173
  }
164
174
  if (!(TUtil.now() - this.runStartTime > FRAME_BUDGET_MS)) {
165
- _context2.next = 32;
175
+ _context2.next = 33;
166
176
  break;
167
177
  }
168
178
  handedOff = true;
169
179
  this.requestNextSlice(runId);
170
180
  return _context2.abrupt("return");
171
- case 32:
181
+ case 33:
172
182
  if (this.phase === 3) {
173
183
  if (this.runningStep >= 0) {
174
184
  if (this.domProcessing === 0) {
@@ -184,24 +194,24 @@ var RunScheduler = /*#__PURE__*/function () {
184
194
  if (this.domProcessing === 0) {
185
195
  this.needsRerun();
186
196
  }
187
- _context2.next = 41;
197
+ _context2.next = 42;
188
198
  break;
189
- case 37:
190
- _context2.prev = 37;
199
+ case 38:
200
+ _context2.prev = 38;
191
201
  _context2.t0 = _context2["catch"](11);
192
202
  this.phase = 0;
193
203
  throw _context2.t0;
194
- case 41:
195
- _context2.prev = 41;
204
+ case 42:
205
+ _context2.prev = 42;
196
206
  if (!handedOff && this.domProcessing === 0) {
197
207
  this.runningFlag = false;
198
208
  }
199
- return _context2.finish(41);
200
- case 44:
209
+ return _context2.finish(42);
210
+ case 45:
201
211
  case "end":
202
212
  return _context2.stop();
203
213
  }
204
- }, _callee2, this, [[11, 37, 41, 44]]);
214
+ }, _callee2, this, [[11, 38, 42, 45]]);
205
215
  }));
206
216
  function run(_x, _x2) {
207
217
  return _run.apply(this, arguments);
@@ -227,19 +237,23 @@ var RunScheduler = /*#__PURE__*/function () {
227
237
  value: function needsRerun() {
228
238
  this.phase = 0;
229
239
  this.runningFlag = false;
240
+ var eventSettlePending = this.eventSettlePending;
241
+ this.eventSettlePending = false;
230
242
  if (this.rerunId) {
231
243
  var id = this.rerunId;
232
244
  this.rerunId = '';
233
245
  this.schedule(0, "rerun-".concat(id));
234
- } else if (getEvents().eventQueue.length > 0) {
246
+ } else if (getEvents().eventQueue.length > 0 || eventSettlePending) {
235
247
  this.schedule(0, "events-".concat(getEvents().eventQueue.length));
236
248
  } else {
237
249
  var newDelay = this.nextRuns.length > 0 ? this.nextRuns[0].delay - (TUtil.now() - this.nextRuns[0].insertTime) : undefined;
238
- if (newDelay === undefined || getManager().lists.activeTModels.length > 0 || getManager().lists.updatingTModels.length > 0 || getManager().lists.restyle.length > 0 || getManager().lists.reasyncStyle.length > 0 || getEvents().eventQueue.length > 0 || getLocationManager().activatedList.length > 0) {
239
- if (getManager().lists.updatingTModels.length > 0) {
250
+ var manager = getManager();
251
+ var hasImmediateWork = manager.lists.restyle.length > 0 || manager.lists.reasyncStyle.length > 0 || getLocationManager().activatedList.length > 0;
252
+ if (newDelay === undefined || manager.lists.activeTModels.length > 0 || manager.lists.updatingTModels.length > 0 || hasImmediateWork) {
253
+ if (manager.lists.updatingTModels.length > 0) {
240
254
  this.schedule(1, "getManager-needsRerun-updatingTModels");
241
- } else if (getManager().lists.activeTModels.length > 0) {
242
- var activeTModel = getManager().lists.activeTModels.find(function (tmodel) {
255
+ } else if (manager.lists.activeTModels.length > 0) {
256
+ var activeTModel = manager.lists.activeTModels.find(function (tmodel) {
243
257
  return tmodel.targetExecutionCount === 0 || tmodel.activeTargetList.filter(function (target) {
244
258
  return !tmodel.isScheduledPending(target);
245
259
  }).some(function (target) {
@@ -251,6 +265,8 @@ var RunScheduler = /*#__PURE__*/function () {
251
265
  this.activeStartTime = TUtil.now();
252
266
  this.schedule(delay, "getManager-needsRerun-".concat(activeTModel.oid, "-").concat(activeTModel.activeTargetList));
253
267
  }
268
+ } else if (hasImmediateWork) {
269
+ this.schedule(1, 'needsRerun-dom-work');
254
270
  }
255
271
  }
256
272
  }
@@ -90,6 +90,16 @@ var SearchUtil = /*#__PURE__*/function () {
90
90
  value: function findFirstLeaveHandler(tmodel) {
91
91
  return this.findFirstHandler(tmodel, 'onLeave');
92
92
  }
93
+ }, {
94
+ key: "findFirstStartHandler",
95
+ value: function findFirstStartHandler(tmodel) {
96
+ return this.findFirstHandler(tmodel, 'onStart');
97
+ }
98
+ }, {
99
+ key: "findFirstEndHandler",
100
+ value: function findFirstEndHandler(tmodel) {
101
+ return this.findFirstHandler(tmodel, 'onEnd');
102
+ }
93
103
  }, {
94
104
  key: "findFirstClickHandler",
95
105
  value: function findFirstClickHandler(tmodel) {
@@ -0,0 +1,293 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
5
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
6
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
9
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
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
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
14
+ 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; }
15
+ 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; }
16
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
17
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
18
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
19
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
20
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
21
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
22
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
23
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
24
+ import { TUtil } from "./TUtil.js";
25
+ import { tApp, App, getRunScheduler, getLocationManager, getAnimationManager, getLoader } from "./App.js";
26
+ import { AnimationUtil } from "./AnimationUtil.js";
27
+ import { DomInit } from "./DomInit.js";
28
+ import { $Dom } from "./$Dom.js";
29
+ import { TModel } from "./TModel.js";
30
+ import { TargetUtil } from "./TargetUtil.js";
31
+ import { TModelUtil } from "./TModelUtil.js";
32
+ import { StateUtil } from "./StateUtil.js";
33
+ /**
34
+ * It enables storing and restoring state.
35
+ */
36
+ var StateManager = /*#__PURE__*/function () {
37
+ function StateManager() {
38
+ _classCallCheck(this, StateManager);
39
+ this.stateCheckpoints = {};
40
+ }
41
+ return _createClass(StateManager, [{
42
+ key: "store",
43
+ value: function () {
44
+ var _store = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
45
+ var key,
46
+ runSnapshot,
47
+ $pageDom,
48
+ checkpoint,
49
+ _args = arguments;
50
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
51
+ while (1) switch (_context.prev = _context.next) {
52
+ case 0:
53
+ key = _args.length > 0 && _args[0] !== undefined ? _args[0] : "default";
54
+ this.syncAnimationsForCheckpoint();
55
+ runSnapshot = getRunScheduler().getSnapshot();
56
+ $pageDom = TModelUtil.getPageDom();
57
+ checkpoint = {
58
+ key: key,
59
+ capturedAt: TUtil.now(),
60
+ html: $pageDom.innerHTML(),
61
+ domState: TModelUtil.captureDomState($pageDom),
62
+ oids: _objectSpread({}, App.oids),
63
+ rootSnapshot: tApp.tRoot.createRuntimeSnapshot(),
64
+ loaderSnapshot: getLoader().createRuntimeSnapshot(),
65
+ visibleOids: Object.keys(tApp.manager.visibleOidMap),
66
+ scrollLeft: $Dom.getWindowScrollLeft() || 0,
67
+ scrollTop: $Dom.getWindowScrollTop() || 0,
68
+ runSnapshot: runSnapshot
69
+ };
70
+ this.stateCheckpoints[key] = checkpoint;
71
+ return _context.abrupt("return", checkpoint);
72
+ case 7:
73
+ case "end":
74
+ return _context.stop();
75
+ }
76
+ }, _callee, this);
77
+ }));
78
+ function store() {
79
+ return _store.apply(this, arguments);
80
+ }
81
+ return store;
82
+ }()
83
+ }, {
84
+ key: "restore",
85
+ value: function () {
86
+ var _restore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
87
+ var key,
88
+ checkpoint,
89
+ timeOffset,
90
+ _StateUtil$fromRuntim,
91
+ root,
92
+ tmodelIdMap,
93
+ models,
94
+ $pageDom,
95
+ visibleModels,
96
+ $restoredPageDom,
97
+ _args2 = arguments;
98
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
99
+ while (1) switch (_context2.prev = _context2.next) {
100
+ case 0:
101
+ key = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : "default";
102
+ TargetUtil.currentTargetName = undefined;
103
+ TargetUtil.currentTModel = undefined;
104
+ checkpoint = this.stateCheckpoints[key];
105
+ if (checkpoint) {
106
+ _context2.next = 6;
107
+ break;
108
+ }
109
+ return _context2.abrupt("return", false);
110
+ case 6:
111
+ getLoader().clear();
112
+ _context2.next = 9;
113
+ return tApp.stop();
114
+ case 9:
115
+ getLocationManager().cancelCurrentCalculation();
116
+ _context2.next = 12;
117
+ return tApp.reset();
118
+ case 12:
119
+ App.oids = {};
120
+ App.tmodelIdMap = {};
121
+ timeOffset = TUtil.now() - checkpoint.capturedAt;
122
+ _StateUtil$fromRuntim = StateUtil.fromRuntimeSnapshot(checkpoint.rootSnapshot, TModel, {
123
+ timeOffset: timeOffset
124
+ }), root = _StateUtil$fromRuntim.root, tmodelIdMap = _StateUtil$fromRuntim.tmodelIdMap, models = _StateUtil$fromRuntim.models;
125
+ tApp.tRoot = root;
126
+ App.oids = _objectSpread({}, checkpoint.oids);
127
+ App.tmodelIdMap = tmodelIdMap;
128
+ getLoader().restoreRuntimeSnapshot(checkpoint.loaderSnapshot, tmodelIdMap);
129
+ $pageDom = TModelUtil.getPageDom();
130
+ $pageDom.innerHTML(checkpoint.html);
131
+ TModelUtil.restoreDomState($pageDom, checkpoint.domState);
132
+ tApp.tRoot.$dom = TModelUtil.getRootDom();
133
+ visibleModels = checkpoint.visibleOids.map(function (oid) {
134
+ return tmodelIdMap[oid];
135
+ }).filter(Boolean);
136
+ this.connectRestoredDoms(visibleModels, models);
137
+ tApp.tRoot.markLayoutDirty("checkpointRestore");
138
+ _context2.next = 29;
139
+ return tApp.start();
140
+ case 29:
141
+ getRunScheduler().restoreSnapshot(checkpoint.runSnapshot);
142
+ $restoredPageDom = TModelUtil.getPageDom();
143
+ TModelUtil.restoreDomState($restoredPageDom, checkpoint.domState);
144
+ _context2.next = 34;
145
+ return TModelUtil.restoreScroll(checkpoint);
146
+ case 34:
147
+ _context2.next = 36;
148
+ return TModelUtil.restoreDomInteractionState($restoredPageDom, checkpoint.domState);
149
+ case 36:
150
+ return _context2.abrupt("return", true);
151
+ case 37:
152
+ case "end":
153
+ return _context2.stop();
154
+ }
155
+ }, _callee2, this);
156
+ }));
157
+ function restore() {
158
+ return _restore.apply(this, arguments);
159
+ }
160
+ return restore;
161
+ }()
162
+ }, {
163
+ key: "syncAnimationsForCheckpoint",
164
+ value: function syncAnimationsForCheckpoint() {
165
+ var keysByTModel = new Map();
166
+ var _iterator = _createForOfIteratorHelper(getAnimationManager().recordMap.values()),
167
+ _step;
168
+ try {
169
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
170
+ var record = _step.value;
171
+ if (record.status === "canceled" || record.status === "detached") {
172
+ continue;
173
+ }
174
+ AnimationUtil.updateTModelFromRecord(record);
175
+ var keys = keysByTModel.get(record.tmodel);
176
+ if (!keys) {
177
+ keys = new Set();
178
+ keysByTModel.set(record.tmodel, keys);
179
+ }
180
+ keys.add(record.originalKey);
181
+ }
182
+ } catch (err) {
183
+ _iterator.e(err);
184
+ } finally {
185
+ _iterator.f();
186
+ }
187
+ var _iterator2 = _createForOfIteratorHelper(keysByTModel),
188
+ _step2;
189
+ try {
190
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
191
+ var _step2$value = _slicedToArray(_step2.value, 2),
192
+ tmodel = _step2$value[0],
193
+ _keys = _step2$value[1];
194
+ TModelUtil.commitAnimatedStyles(tmodel, _keys);
195
+ }
196
+ } catch (err) {
197
+ _iterator2.e(err);
198
+ } finally {
199
+ _iterator2.f();
200
+ }
201
+ }
202
+ }, {
203
+ key: "normalizeRestoredModels",
204
+ value: function normalizeRestoredModels(tmodels) {
205
+ var uniqueModels = TUtil.uniqueTModels(tmodels);
206
+ var _iterator3 = _createForOfIteratorHelper(uniqueModels),
207
+ _step3;
208
+ try {
209
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
210
+ var tmodel = _step3.value;
211
+ var animatingKeys = new Set(tmodel.getAnimatingTargets());
212
+ if (animatingKeys.size && tmodel.hasDom()) {
213
+ TModelUtil.commitAnimatedStyles(tmodel, animatingKeys);
214
+ }
215
+ tmodel.viewport = undefined;
216
+ tmodel.visibilityStatus = undefined;
217
+ tmodel.currentStatus = "new";
218
+ tmodel.originWindowEpoch = -1;
219
+ tmodel.domHeightTimestamp = 0;
220
+ tmodel.domWidthTimestamp = 0;
221
+ tmodel.dirtyLayout = false;
222
+ tmodel.markLayoutDirty("stateRestore");
223
+ }
224
+ } catch (err) {
225
+ _iterator3.e(err);
226
+ } finally {
227
+ _iterator3.f();
228
+ }
229
+ TargetUtil.convertAnimatingTargetsToUpdating(uniqueModels);
230
+ return uniqueModels;
231
+ }
232
+ }, {
233
+ key: "connectRestoredDoms",
234
+ value: function connectRestoredDoms(visibleModels, allModels) {
235
+ var newVisibles = DomInit.initCacheDoms(visibleModels);
236
+ var restoredWithDom = TUtil.uniqueTModels([].concat(_toConsumableArray(visibleModels), _toConsumableArray(newVisibles)));
237
+ this.normalizeRestoredModels(allModels);
238
+ tApp.manager.visibleOidMap = {};
239
+ var _iterator4 = _createForOfIteratorHelper(restoredWithDom),
240
+ _step4;
241
+ try {
242
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
243
+ var tmodel = _step4.value;
244
+ if (tmodel.isIncluded()) {
245
+ tApp.manager.visibleOidMap[tmodel.oid] = tmodel;
246
+ }
247
+ }
248
+ } catch (err) {
249
+ _iterator4.e(err);
250
+ } finally {
251
+ _iterator4.f();
252
+ }
253
+ tApp.manager.activatePendingTargetsAfterDom(restoredWithDom, {
254
+ restoredDoneTargets: true
255
+ });
256
+ return restoredWithDom;
257
+ }
258
+ }, {
259
+ key: "has",
260
+ value: function has() {
261
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
262
+ return Boolean(this.stateCheckpoints[key]);
263
+ }
264
+ }, {
265
+ key: "get",
266
+ value: function get() {
267
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
268
+ return this.stateCheckpoints[key];
269
+ }
270
+ }, {
271
+ key: "toggle",
272
+ value: function toggle() {
273
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
274
+ return this.has(key) ? this.restore(key) : this.store(key);
275
+ }
276
+ }, {
277
+ key: "clear",
278
+ value: function clear() {
279
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
280
+ if (!this.stateCheckpoints[key]) {
281
+ return false;
282
+ }
283
+ delete this.stateCheckpoints[key];
284
+ return true;
285
+ }
286
+ }, {
287
+ key: "clearAll",
288
+ value: function clearAll() {
289
+ this.stateCheckpoints = {};
290
+ }
291
+ }]);
292
+ }();
293
+ export { StateManager };