targetj 1.0.260 → 1.1.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.
@@ -1,13 +1,20 @@
1
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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
3
+ 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."); }
4
+ 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; } }
5
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
2
6
  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; }
3
7
  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); }
4
8
  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); }); }; }
9
+ 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; } } }; }
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ 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; }
5
13
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
6
14
  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."); }
15
+ 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; } }
7
16
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
8
17
  function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
9
- 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; } } }; }
10
- 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; } }
11
18
  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; }
12
19
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
13
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); } }
@@ -20,6 +27,7 @@ import { TargetUtil } from "./TargetUtil.js";
20
27
  import { TModelUtil } from "./TModelUtil.js";
21
28
  import { TUtil } from "./TUtil.js";
22
29
  import { getRunScheduler } from "./App.js";
30
+ import { TargetParser } from "./TargetParser.js";
23
31
 
24
32
  /**
25
33
  * Executes lightweight GPU-child TargetJS runtime behavior.
@@ -34,60 +42,120 @@ var ParticleRuntime = /*#__PURE__*/function () {
34
42
  this.activeTargets = [];
35
43
  this.restoredMainIndexes = [];
36
44
  this.restoredActivationSequences = [];
45
+ this.restoredImperativeExecutions = [];
46
+ this.activeRenderExecutions = new Set();
47
+ this.animationFrameRequested = false;
48
+ this.startQueue = [];
49
+ this.startQueueIndex = 0;
50
+ this.disposed = false;
51
+ this.animationFrameId = undefined;
37
52
  }
38
53
  return _createClass(ParticleRuntime, [{
39
54
  key: "registerChild",
40
55
  value: function registerChild(index, targetName, compiled) {
41
- var _compiled$layoutFunct;
42
- var tmodel = this.tmodel;
43
- var controlledTargets = {};
44
- var _iterator = _createForOfIteratorHelper(compiled.runtimeTargets),
45
- _step;
46
- try {
47
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
48
- var runtimeTarget = _step.value;
49
- if (runtimeTarget.kind === "render") {
50
- controlledTargets[runtimeTarget.targetName] = true;
51
- }
52
- }
53
- } catch (err) {
54
- _iterator.e(err);
55
- } finally {
56
- _iterator.f();
57
- }
58
- var hasRuntime = compiled.runtimeTargets.length > 0;
59
- var layoutFunctions = (_compiled$layoutFunct = compiled.layoutFunctions) !== null && _compiled$layoutFunct !== void 0 ? _compiled$layoutFunct : [];
60
- tmodel.childRuntimePrograms[index] = compiled.runtimeTargets;
61
- tmodel.childRuntimeStates[index] = {
62
- controlledTargets: controlledTargets,
56
+ var hasRuntime = compiled.runtimeTargets.some(function (target) {
57
+ return target.requiresRuntime !== false;
58
+ });
59
+ this.tmodel.childRuntimePrograms[index] = compiled.runtimeTargets;
60
+ this.tmodel.childRuntimeStates[index] = {
63
61
  ownerTargetName: targetName,
64
- programIndex: 0,
62
+ nextTargetIndex: 0,
65
63
  activationCount: 0,
66
- layoutFunctions: layoutFunctions,
67
- layoutFunctionsResolved: layoutFunctions.length === 0,
68
64
  executions: {},
69
65
  startRequested: false,
66
+ startQueued: false,
70
67
  renderReady: false,
71
68
  started: false,
72
- done: !hasRuntime,
73
- pendingCompletion: hasRuntime
69
+ done: !hasRuntime
74
70
  };
75
71
  if (hasRuntime) {
76
- tmodel.pendingGpuChildRuntimeCounts[targetName] = (tmodel.pendingGpuChildRuntimeCounts[targetName] || 0) + 1;
72
+ this.tmodel.pendingGpuChildRuntimeCounts[targetName] = (this.tmodel.pendingGpuChildRuntimeCounts[targetName] || 0) + 1;
77
73
  }
78
74
  return hasRuntime;
79
75
  }
76
+ }, {
77
+ key: "removeChild",
78
+ value: function removeChild(index) {
79
+ var state = this.tmodel.childRuntimeStates[index];
80
+ if (state) {
81
+ state.cancelled = true;
82
+ if (!state.done) {
83
+ this.complete(index);
84
+ }
85
+ }
86
+ for (var _i = 0, _arr = _toConsumableArray(this.activeRenderExecutions); _i < _arr.length; _i++) {
87
+ var execution = _arr[_i];
88
+ if (execution.index === index) {
89
+ this.activeRenderExecutions.delete(execution);
90
+ execution.cancelled = true;
91
+ var resolve = execution.resolve;
92
+ execution.resolve = undefined;
93
+ resolve === null || resolve === void 0 || resolve();
94
+ continue;
95
+ }
96
+ if (execution.index > index) {
97
+ execution.index--;
98
+ }
99
+ }
100
+ this.tmodel.childRuntimePrograms.splice(index, 1);
101
+ this.tmodel.childRuntimeStates.splice(index, 1);
102
+ this.activeTargets.splice(index, 1);
103
+ this.startQueue = this.startQueue.slice(this.startQueueIndex).filter(function (childIndex) {
104
+ return childIndex !== index;
105
+ }).map(function (childIndex) {
106
+ return childIndex > index ? childIndex - 1 : childIndex;
107
+ });
108
+ this.startQueueIndex = 0;
109
+ this.restoredMainIndexes = this.restoredMainIndexes.filter(function (childIndex) {
110
+ return childIndex !== index;
111
+ }).map(function (childIndex) {
112
+ return childIndex > index ? childIndex - 1 : childIndex;
113
+ });
114
+ this.restoredActivationSequences = this.restoredActivationSequences.filter(function (item) {
115
+ return item.index !== index;
116
+ }).map(function (item) {
117
+ return item.index > index ? _objectSpread(_objectSpread({}, item), {}, {
118
+ index: item.index - 1
119
+ }) : item;
120
+ });
121
+ this.restoredImperativeExecutions = this.restoredImperativeExecutions.filter(function (item) {
122
+ return item.index !== index;
123
+ }).map(function (item) {
124
+ return item.index > index ? _objectSpread(_objectSpread({}, item), {}, {
125
+ index: item.index - 1
126
+ }) : item;
127
+ });
128
+ }
80
129
  }, {
81
130
  key: "hasPending",
82
131
  value: function hasPending(key) {
132
+ var _this = this;
133
+ var completionScope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "all";
134
+ if (completionScope === "none") {
135
+ return false;
136
+ }
83
137
  var targetName = TargetUtil.getTargetName(key);
84
- return (this.tmodel.pendingGpuChildRuntimeCounts[targetName] || 0) > 0;
138
+ return this.tmodel.childRuntimeStates.some(function (state, index) {
139
+ if (!state || state.ownerTargetName !== targetName) {
140
+ return false;
141
+ }
142
+ if (completionScope === "visible" && TargetUtil.shouldIgnoreChildForCompletion(_this.tmodel.childHandles[index], "visible")) {
143
+ return false;
144
+ }
145
+ return !state.done || Object.keys(_this.activeTargets[index] || {}).length > 0;
146
+ });
147
+ }
148
+ }, {
149
+ key: "isIntervalTarget",
150
+ value: function isIntervalTarget(runtimeTarget) {
151
+ return TargetParser.isIntervalTarget(runtimeTarget.target);
85
152
  }
86
153
  }, {
87
154
  key: "prepareRestore",
88
155
  value: function prepareRestore() {
89
156
  this.restoredMainIndexes = [];
90
157
  this.restoredActivationSequences = [];
158
+ this.restoredImperativeExecutions = [];
91
159
  for (var index = 0; index < this.tmodel.childRuntimeStates.length; index++) {
92
160
  var _state$executions, _state$activationCoun;
93
161
  var state = this.tmodel.childRuntimeStates[index];
@@ -100,11 +168,6 @@ var ParticleRuntime = /*#__PURE__*/function () {
100
168
  var mainExecutions = executions.filter(function (execution) {
101
169
  return execution.sequenceId === "main";
102
170
  });
103
-
104
- /*
105
- * A main program may be between targets and therefore have no current
106
- * execution record, so state.started still matters for the main sequence.
107
- */
108
171
  if (!state.done && (state.started || mainExecutions.length)) {
109
172
  this.restoredMainIndexes.push(index);
110
173
  }
@@ -113,24 +176,30 @@ var ParticleRuntime = /*#__PURE__*/function () {
113
176
  }).filter(function (sequenceId) {
114
177
  return sequenceId === null || sequenceId === void 0 ? void 0 : sequenceId.startsWith("activation:");
115
178
  })));
116
- var _iterator2 = _createForOfIteratorHelper(activationSequenceIds),
117
- _step2;
179
+ var _iterator = _createForOfIteratorHelper(activationSequenceIds),
180
+ _step;
118
181
  try {
119
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
120
- var sequenceId = _step2.value;
182
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
183
+ var sequenceId = _step.value;
121
184
  this.restoredActivationSequences.push({
122
185
  index: index,
123
186
  sequenceId: sequenceId
124
187
  });
125
188
  }
126
-
127
- /*
128
- * Promise/timer state belonged to the old ParticleRuntime.
129
- */
130
189
  } catch (err) {
131
- _iterator2.e(err);
190
+ _iterator.e(err);
132
191
  } finally {
133
- _iterator2.f();
192
+ _iterator.f();
193
+ }
194
+ for (var _i2 = 0, _executions = executions; _i2 < _executions.length; _i2++) {
195
+ var _execution$sequenceId;
196
+ var execution = _executions[_i2];
197
+ if ((_execution$sequenceId = execution.sequenceId) !== null && _execution$sequenceId !== void 0 && _execution$sequenceId.startsWith("imperative:")) {
198
+ this.restoredImperativeExecutions.push({
199
+ index: index,
200
+ execution: execution
201
+ });
202
+ }
134
203
  }
135
204
  state.started = false;
136
205
  state.renderReady = false;
@@ -142,26 +211,41 @@ var ParticleRuntime = /*#__PURE__*/function () {
142
211
  value: function resumeRestored() {
143
212
  var mainIndexes = this.restoredMainIndexes.splice(0);
144
213
  var activationSequences = this.restoredActivationSequences.splice(0);
145
- var _iterator3 = _createForOfIteratorHelper(mainIndexes),
214
+ var imperativeExecutions = this.restoredImperativeExecutions.splice(0);
215
+ var _iterator2 = _createForOfIteratorHelper(mainIndexes),
216
+ _step2;
217
+ try {
218
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
219
+ var index = _step2.value;
220
+ this.resumeMainProgram(index);
221
+ }
222
+ } catch (err) {
223
+ _iterator2.e(err);
224
+ } finally {
225
+ _iterator2.f();
226
+ }
227
+ var _iterator3 = _createForOfIteratorHelper(activationSequences),
146
228
  _step3;
147
229
  try {
148
230
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
149
- var index = _step3.value;
150
- this.resumeMainProgram(index);
231
+ var _step3$value = _step3.value,
232
+ _index = _step3$value.index,
233
+ sequenceId = _step3$value.sequenceId;
234
+ this.resumeActivationSequence(_index, sequenceId);
151
235
  }
152
236
  } catch (err) {
153
237
  _iterator3.e(err);
154
238
  } finally {
155
239
  _iterator3.f();
156
240
  }
157
- var _iterator4 = _createForOfIteratorHelper(activationSequences),
241
+ var _iterator4 = _createForOfIteratorHelper(imperativeExecutions),
158
242
  _step4;
159
243
  try {
160
244
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
161
245
  var _step4$value = _step4.value,
162
- _index = _step4$value.index,
163
- sequenceId = _step4$value.sequenceId;
164
- this.resumeActivationSequence(_index, sequenceId);
246
+ _index2 = _step4$value.index,
247
+ execution = _step4$value.execution;
248
+ this.resumeImperativeExecution(_index2, execution);
165
249
  }
166
250
  } catch (err) {
167
251
  _iterator4.e(err);
@@ -174,7 +258,7 @@ var ParticleRuntime = /*#__PURE__*/function () {
174
258
  value: function resumeActivationSequence(index, sequenceId) {
175
259
  var _this$activeTargets,
176
260
  _this$activeTargets$i,
177
- _this = this;
261
+ _this2 = this;
178
262
  var state = this.tmodel.childRuntimeStates[index];
179
263
  if (!state) {
180
264
  return false;
@@ -191,9 +275,9 @@ var ParticleRuntime = /*#__PURE__*/function () {
191
275
  var activationId = sequenceId.startsWith("activation:") ? sequenceId.slice("activation:".length) : sequenceId;
192
276
  var activeTargets = (_this$activeTargets$i = (_this$activeTargets = this.activeTargets)[index]) !== null && _this$activeTargets$i !== void 0 ? _this$activeTargets$i : _this$activeTargets[index] = {};
193
277
  var promise = Promise.all(executions.map(function (execution) {
194
- return _this.resumeExecution(index, execution);
278
+ return _this2.resumeExecution(index, execution);
195
279
  })).then(function () {
196
- return _this.continueActivatedSequence(index, currentTargetIndex + 1, sequenceId);
280
+ return _this2.continueActivatedSequence(index, currentTargetIndex + 1, sequenceId);
197
281
  }).catch(function (error) {
198
282
  console.error(error);
199
283
  }).finally(function () {
@@ -202,39 +286,93 @@ var ParticleRuntime = /*#__PURE__*/function () {
202
286
  activeTargets[activationId] = promise;
203
287
  return true;
204
288
  }
289
+ }, {
290
+ key: "resumeImperativeExecution",
291
+ value: function resumeImperativeExecution(index, execution) {
292
+ var _this3 = this;
293
+ var child = this.tmodel.childHandles[index];
294
+ var state = this.tmodel.childRuntimeStates[index];
295
+ var runtimeTarget = execution === null || execution === void 0 ? void 0 : execution.imperativeTarget;
296
+ if (!child || !state || !runtimeTarget) {
297
+ return false;
298
+ }
299
+ if (execution.kind !== "render" && execution.kind !== "runtime") {
300
+ return false;
301
+ }
302
+ var imperativeKey = execution.imperativeKey || runtimeTarget.imperativeKey || "".concat(execution.targetName, "+");
303
+
304
+ // Resume from the saved animation step rather than from the old absolute clock time.
305
+ if (execution.segmentReady && execution.interval > 0) {
306
+ execution.segmentStartTime = TUtil.now() - execution.step * execution.interval;
307
+ execution.pausedAt = undefined;
308
+ }
309
+ var targetValue = {
310
+ isImperative: true,
311
+ originalTargetName: runtimeTarget.originalTargetName,
312
+ originalTModel: runtimeTarget.originalTargetIsParent ? this.tmodel : undefined,
313
+ status: "updating",
314
+ value: runtimeTarget.target.value,
315
+ steps: runtimeTarget.target.steps || 0,
316
+ interval: runtimeTarget.target.interval || 0,
317
+ easing: runtimeTarget.target.easing
318
+ };
319
+ child.targetValues[imperativeKey] = targetValue;
320
+ child.addToUpdatingTargets(imperativeKey);
321
+ var promise = execution.kind === "render" ? this.runRenderTarget(index, runtimeTarget, execution.targetIndex, execution.sequenceId) : this.runRuntimeTarget(index, runtimeTarget, execution.targetIndex, execution.sequenceId);
322
+ Promise.resolve(promise).catch(function (error) {
323
+ console.error(error);
324
+ }).finally(function () {
325
+ if (_this3.disposed || child.targetValues[imperativeKey] !== targetValue) {
326
+ return;
327
+ }
328
+ targetValue.status = "done";
329
+ child.removeFromUpdatingTargets(imperativeKey);
330
+ if (runtimeTarget.originalTargetIsParent && runtimeTarget.originalTargetName) {
331
+ TargetUtil.shouldActivateNextTarget(_this3.tmodel, runtimeTarget.originalTargetName, 1, 0, true, "complete");
332
+ }
333
+ getRunScheduler().schedule(1, "gpuImperativeComplete-".concat(child.oid, "-").concat(imperativeKey));
334
+ });
335
+ return true;
336
+ }
205
337
  }, {
206
338
  key: "continueActivatedSequence",
207
339
  value: function () {
208
- var _continueActivatedSequence = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(index, programIndex, sequenceId) {
340
+ var _continueActivatedSequence = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(index, nextTargetIndex, sequenceId) {
209
341
  var program, runtimeTarget;
210
342
  return _regeneratorRuntime().wrap(function _callee$(_context) {
211
343
  while (1) switch (_context.prev = _context.next) {
212
344
  case 0:
345
+ if (!this.disposed) {
346
+ _context.next = 2;
347
+ break;
348
+ }
349
+ return _context.abrupt("return");
350
+ case 2:
213
351
  program = this.tmodel.childRuntimePrograms[index];
214
352
  if (program) {
215
- _context.next = 3;
353
+ _context.next = 5;
216
354
  break;
217
355
  }
218
356
  return _context.abrupt("return");
219
- case 3:
220
- if (!(programIndex < program.length)) {
221
- _context.next = 12;
357
+ case 5:
358
+ if (!(!this.disposed && nextTargetIndex < program.length)) {
359
+ _context.next = 14;
222
360
  break;
223
361
  }
224
- runtimeTarget = program[programIndex];
362
+ runtimeTarget = program[nextTargetIndex];
225
363
  if (!(runtimeTarget.mode !== "deferred")) {
226
- _context.next = 7;
364
+ _context.next = 9;
227
365
  break;
228
366
  }
229
- return _context.abrupt("break", 12);
230
- case 7:
231
- _context.next = 9;
232
- return this.runTarget(index, runtimeTarget, programIndex, sequenceId);
367
+ return _context.abrupt("break", 14);
233
368
  case 9:
234
- programIndex++;
235
- _context.next = 3;
369
+ _context.next = 11;
370
+ return this.runTarget(index, runtimeTarget, nextTargetIndex, sequenceId);
371
+ case 11:
372
+ nextTargetIndex++;
373
+ _context.next = 5;
236
374
  break;
237
- case 12:
375
+ case 14:
238
376
  case "end":
239
377
  return _context.stop();
240
378
  }
@@ -248,9 +386,9 @@ var ParticleRuntime = /*#__PURE__*/function () {
248
386
  }, {
249
387
  key: "resumeMainProgram",
250
388
  value: function resumeMainProgram(index) {
251
- var _this2 = this;
389
+ var _this4 = this;
252
390
  var state = this.tmodel.childRuntimeStates[index];
253
- if (!state || state.done || state.started) {
391
+ if (this.disposed || !state || state.done || state.started) {
254
392
  return;
255
393
  }
256
394
  state.started = true;
@@ -258,13 +396,13 @@ var ParticleRuntime = /*#__PURE__*/function () {
258
396
  return execution.sequenceId === "main";
259
397
  });
260
398
  Promise.all(runningExecutions.map(function (execution) {
261
- return _this2.resumeExecution(index, execution);
399
+ return _this4.resumeExecution(index, execution);
262
400
  })).then(function () {
263
- return _this2.runProgram(index);
401
+ return _this4.runProgram(index);
264
402
  }).catch(function (error) {
265
403
  console.error(error);
266
404
  }).finally(function () {
267
- _this2.complete(index);
405
+ _this4.complete(index);
268
406
  });
269
407
  }
270
408
  }, {
@@ -281,22 +419,18 @@ var ParticleRuntime = /*#__PURE__*/function () {
281
419
  if (execution.kind === "render") {
282
420
  return this.runRenderTarget(index, runtimeTarget, execution.targetIndex, execution.sequenceId);
283
421
  }
284
- return Promise.resolve();
285
- }
286
- }, {
287
- key: "isControlled",
288
- value: function isControlled(index, key) {
289
- var _state$controlledTarg;
290
- var state = this.tmodel.childRuntimeStates[index];
291
- if (!state) {
292
- return false;
422
+ if (execution.kind === "runtime") {
423
+ return this.runRuntimeTarget(index, runtimeTarget, execution.targetIndex, execution.sequenceId);
293
424
  }
294
- var targetName = ParticleUtil.getGpuRenderTargetName(key);
295
- return ((_state$controlledTarg = state.controlledTargets) === null || _state$controlledTarg === void 0 ? void 0 : _state$controlledTarg[targetName]) === true;
425
+ return Promise.resolve();
296
426
  }
297
427
  }, {
298
428
  key: "complete",
299
429
  value: function complete(index) {
430
+ var _tmodel$pendingTarget;
431
+ if (this.disposed) {
432
+ return;
433
+ }
300
434
  var tmodel = this.tmodel;
301
435
  var state = tmodel.childRuntimeStates[index];
302
436
  if (!state || state.done) {
@@ -304,56 +438,24 @@ var ParticleRuntime = /*#__PURE__*/function () {
304
438
  }
305
439
  state.done = true;
306
440
  state.started = false;
307
- if (!state.pendingCompletion) {
308
- return;
309
- }
310
- state.pendingCompletion = false;
311
441
  var targetName = state.ownerTargetName;
312
442
  var count = Math.max(0, (tmodel.pendingGpuChildRuntimeCounts[targetName] || 0) - 1);
313
443
  if (count > 0) {
314
444
  tmodel.pendingGpuChildRuntimeCounts[targetName] = count;
315
- return;
445
+ } else {
446
+ delete tmodel.pendingGpuChildRuntimeCounts[targetName];
447
+ getRunScheduler().schedule(1, "gpuChildRuntimeComplete-".concat(tmodel.oid));
316
448
  }
317
- delete tmodel.pendingGpuChildRuntimeCounts[targetName];
318
- getRunScheduler().schedule(1, "gpuChildRuntimeComplete-".concat(tmodel.oid));
319
- }
320
- }, {
321
- key: "resolveLayoutFunctions",
322
- value: function resolveLayoutFunctions() {
323
- var tmodel = this.tmodel;
324
- var changed = false;
325
- for (var index = 0; index < tmodel.childRuntimeStates.length; index++) {
326
- var _state$layoutFunction;
327
- var state = tmodel.childRuntimeStates[index];
328
- if (!state || state.layoutFunctionsResolved || !((_state$layoutFunction = state.layoutFunctions) !== null && _state$layoutFunction !== void 0 && _state$layoutFunction.length)) {
329
- continue;
330
- }
331
- var child = tmodel.childHandles[index];
332
- var childChanged = false;
333
- var _iterator5 = _createForOfIteratorHelper(state.layoutFunctions),
334
- _step5;
335
- try {
336
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
337
- var entry = _step5.value;
338
- var resolved = ParticleUtil.resolveGpuRenderValue(entry.value, child);
339
- var value = ParticleUtil.getGpuInitialRenderValue(resolved);
340
- if (tmodel.getChildValue(index, entry.targetName) === value) {
341
- continue;
342
- }
343
- child.val(entry.targetName, value);
344
- childChanged = true;
345
- changed = true;
346
- }
347
- } catch (err) {
348
- _iterator5.e(err);
349
- } finally {
350
- _iterator5.f();
351
- }
352
- if (!childChanged) {
353
- state.layoutFunctionsResolved = true;
354
- }
449
+ TargetUtil.cleanupVisibleComplete(tmodel, targetName);
450
+
451
+ // Retry the parent pipeline when its GPU children are ready.
452
+ var pendingKey = _toConsumableArray((_tmodel$pendingTarget = tmodel.pendingTargets) !== null && _tmodel$pendingTarget !== void 0 ? _tmodel$pendingTarget : []).find(function (key) {
453
+ return TargetUtil.getTargetName(key) === targetName;
454
+ });
455
+ if (pendingKey && tmodel.isTargetDone(pendingKey) && tmodel.isTargetTreeComplete(pendingKey) === true) {
456
+ TargetUtil.cleanupTarget(tmodel, pendingKey);
457
+ TargetUtil.shouldActivateNextTarget(tmodel, pendingKey);
355
458
  }
356
- return changed;
357
459
  }
358
460
  }, {
359
461
  key: "queueStart",
@@ -363,81 +465,113 @@ var ParticleRuntime = /*#__PURE__*/function () {
363
465
  return;
364
466
  }
365
467
  state.startRequested = true;
366
- this.startReady();
367
468
  }
368
469
  }, {
369
470
  key: "markRenderReady",
370
471
  value: function markRenderReady(indexes) {
371
- var _iterator6 = _createForOfIteratorHelper(indexes),
372
- _step6;
472
+ var _iterator5 = _createForOfIteratorHelper(indexes),
473
+ _step5;
373
474
  try {
374
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
375
- var index = _step6.value;
475
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
476
+ var index = _step5.value;
376
477
  var state = this.tmodel.childRuntimeStates[index];
377
478
  if (state) {
378
479
  state.renderReady = true;
379
480
  }
380
481
  }
381
482
  } catch (err) {
382
- _iterator6.e(err);
483
+ _iterator5.e(err);
383
484
  } finally {
384
- _iterator6.f();
485
+ _iterator5.f();
385
486
  }
386
487
  this.startReady();
387
488
  }
388
489
  }, {
389
490
  key: "markPendingRenderReady",
390
491
  value: function markPendingRenderReady() {
391
- var _iterator7 = _createForOfIteratorHelper(this.tmodel.childRuntimeStates),
392
- _step7;
492
+ var _iterator6 = _createForOfIteratorHelper(this.tmodel.childRuntimeStates),
493
+ _step6;
393
494
  try {
394
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
395
- var state = _step7.value;
495
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
496
+ var state = _step6.value;
396
497
  if (state !== null && state !== void 0 && state.startRequested && !state.started && !state.done) {
397
498
  state.renderReady = true;
398
499
  }
399
500
  }
400
501
  } catch (err) {
401
- _iterator7.e(err);
502
+ _iterator6.e(err);
402
503
  } finally {
403
- _iterator7.f();
504
+ _iterator6.f();
404
505
  }
405
506
  this.startReady();
406
507
  }
407
508
  }, {
408
509
  key: "startReady",
409
510
  value: function startReady() {
511
+ if (this.disposed) {
512
+ return;
513
+ }
410
514
  var tmodel = this.tmodel;
411
515
  if (!tmodel.hasDom() || tmodel.completeLayoutEpoch !== tmodel.layoutEpoch) {
412
516
  return false;
413
517
  }
414
- var started = false;
518
+ var queued = false;
415
519
  for (var index = 0; index < tmodel.childRuntimeStates.length; index++) {
416
520
  var state = tmodel.childRuntimeStates[index];
417
- if (!state || !state.startRequested || !state.renderReady || state.started || state.done) {
521
+ if (!state || !state.startRequested || !state.renderReady || state.startQueued || state.started || state.done) {
522
+ continue;
523
+ }
524
+ state.startQueued = true;
525
+ this.startQueue.push(index);
526
+ queued = true;
527
+ }
528
+ if (queued) {
529
+ this.requestAnimationFrame();
530
+ }
531
+ return queued;
532
+ }
533
+ }, {
534
+ key: "startQueuedPrograms",
535
+ value: function startQueuedPrograms() {
536
+ var frameStart = TUtil.now();
537
+ var count = 0;
538
+ while (this.startQueueIndex < this.startQueue.length && count < 5000 && TUtil.now() - frameStart < 4) {
539
+ var index = this.startQueue[this.startQueueIndex++];
540
+ var state = this.tmodel.childRuntimeStates[index];
541
+ if (!state) {
542
+ continue;
543
+ }
544
+ state.startQueued = false;
545
+ if (!state.startRequested || !state.renderReady || state.started || state.done) {
418
546
  continue;
419
547
  }
420
548
  state.startRequested = false;
421
549
  this.start(index);
422
- started = true;
550
+ count++;
551
+ }
552
+ if (this.startQueueIndex >= this.startQueue.length) {
553
+ this.startQueue.length = 0;
554
+ this.startQueueIndex = 0;
423
555
  }
424
- return started;
425
556
  }
426
557
  }, {
427
558
  key: "start",
428
559
  value: function start(index) {
429
- var _this3 = this;
560
+ var _this5 = this;
561
+ if (this.disposed) {
562
+ return;
563
+ }
430
564
  var state = this.tmodel.childRuntimeStates[index];
431
565
  var program = this.tmodel.childRuntimePrograms[index];
432
566
  if (!state || !(program !== null && program !== void 0 && program.length) || state.started || state.done) {
433
567
  return;
434
568
  }
435
569
  state.started = true;
436
- state.programIndex = 0;
570
+ state.nextTargetIndex = 0;
437
571
  Promise.resolve(this.runProgram(index)).catch(function (error) {
438
572
  console.error(error);
439
573
  }).finally(function () {
440
- _this3.complete(index);
574
+ _this5.complete(index);
441
575
  });
442
576
  }
443
577
  }, {
@@ -448,37 +582,49 @@ var ParticleRuntime = /*#__PURE__*/function () {
448
582
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
449
583
  while (1) switch (_context2.prev = _context2.next) {
450
584
  case 0:
585
+ if (!this.disposed) {
586
+ _context2.next = 2;
587
+ break;
588
+ }
589
+ return _context2.abrupt("return");
590
+ case 2:
451
591
  state = this.tmodel.childRuntimeStates[index];
452
592
  program = this.tmodel.childRuntimePrograms[index];
453
593
  if (!(!state || !program)) {
454
- _context2.next = 4;
594
+ _context2.next = 6;
455
595
  break;
456
596
  }
457
597
  return _context2.abrupt("return");
458
- case 4:
598
+ case 6:
459
599
  immediate = [];
460
- while (state.programIndex < program.length && program[state.programIndex].mode === "immediate") {
461
- targetIndex = state.programIndex++;
600
+ while (!state.cancelled && state.nextTargetIndex < program.length && program[state.nextTargetIndex].mode === "immediate") {
601
+ targetIndex = state.nextTargetIndex++;
462
602
  immediate.push(this.runTarget(index, program[targetIndex], targetIndex, "main"));
463
603
  }
464
604
  if (!immediate.length) {
465
- _context2.next = 9;
605
+ _context2.next = 11;
466
606
  break;
467
607
  }
468
- _context2.next = 9;
608
+ _context2.next = 11;
469
609
  return Promise.all(immediate);
470
- case 9:
471
- if (!(state.programIndex < program.length)) {
472
- _context2.next = 15;
610
+ case 11:
611
+ if (!state.cancelled) {
612
+ _context2.next = 13;
473
613
  break;
474
614
  }
475
- _targetIndex = state.programIndex++;
476
- _context2.next = 13;
477
- return this.runTarget(index, program[_targetIndex], _targetIndex, "main");
615
+ return _context2.abrupt("return");
478
616
  case 13:
479
- _context2.next = 9;
617
+ if (!(!state.cancelled && state.nextTargetIndex < program.length)) {
618
+ _context2.next = 19;
619
+ break;
620
+ }
621
+ _targetIndex = state.nextTargetIndex++;
622
+ _context2.next = 17;
623
+ return this.runTarget(index, program[_targetIndex], _targetIndex, "main");
624
+ case 17:
625
+ _context2.next = 13;
480
626
  break;
481
- case 15:
627
+ case 19:
482
628
  case "end":
483
629
  return _context2.stop();
484
630
  }
@@ -495,50 +641,50 @@ var ParticleRuntime = /*#__PURE__*/function () {
495
641
  var _runTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(index, runtimeTarget, targetIndex) {
496
642
  var sequenceId,
497
643
  child,
498
- value,
499
- result,
500
644
  _args3 = arguments;
501
645
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
502
646
  while (1) switch (_context3.prev = _context3.next) {
503
647
  case 0:
504
648
  sequenceId = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : "main";
505
- child = this.tmodel.childHandles[index];
506
- if (child) {
507
- _context3.next = 4;
649
+ if (!this.disposed) {
650
+ _context3.next = 3;
651
+ break;
652
+ }
653
+ return _context3.abrupt("return");
654
+ case 3:
655
+ if (!(runtimeTarget.requiresRuntime === false)) {
656
+ _context3.next = 5;
508
657
  break;
509
658
  }
510
659
  return _context3.abrupt("return");
511
- case 4:
512
- if (!(runtimeTarget.kind === "interval")) {
660
+ case 5:
661
+ child = this.tmodel.childHandles[index];
662
+ if (child) {
513
663
  _context3.next = 8;
514
664
  break;
515
665
  }
516
- _context3.next = 7;
517
- return this.runIntervalTarget(index, runtimeTarget, targetIndex, sequenceId);
518
- case 7:
519
666
  return _context3.abrupt("return");
520
667
  case 8:
521
- if (!(runtimeTarget.kind === "render")) {
668
+ if (!this.isIntervalTarget(runtimeTarget)) {
522
669
  _context3.next = 12;
523
670
  break;
524
671
  }
525
672
  _context3.next = 11;
526
- return this.runRenderTarget(index, runtimeTarget, targetIndex, sequenceId);
673
+ return this.runIntervalTarget(index, runtimeTarget, targetIndex, sequenceId);
527
674
  case 11:
528
675
  return _context3.abrupt("return");
529
676
  case 12:
530
- value = runtimeTarget.target.value;
531
- if (!(typeof value === "function")) {
532
- _context3.next = 18;
533
- break;
534
- }
535
- result = value.call(child);
536
- if (!(result !== null && result !== void 0 && result.then)) {
537
- _context3.next = 18;
677
+ if (!runtimeTarget.renderable) {
678
+ _context3.next = 16;
538
679
  break;
539
680
  }
681
+ _context3.next = 15;
682
+ return this.runRenderTarget(index, runtimeTarget, targetIndex, sequenceId);
683
+ case 15:
684
+ return _context3.abrupt("return");
685
+ case 16:
540
686
  _context3.next = 18;
541
- return result;
687
+ return this.runRuntimeTarget(index, runtimeTarget, targetIndex, sequenceId);
542
688
  case 18:
543
689
  case "end":
544
690
  return _context3.stop();
@@ -550,6 +696,135 @@ var ParticleRuntime = /*#__PURE__*/function () {
550
696
  }
551
697
  return runTarget;
552
698
  }()
699
+ }, {
700
+ key: "runRuntimeTarget",
701
+ value: function () {
702
+ var _runRuntimeTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(index, runtimeTarget, targetIndex) {
703
+ var sequenceId,
704
+ child,
705
+ target,
706
+ targetName,
707
+ execution,
708
+ value,
709
+ _value,
710
+ isValueList,
711
+ currentValue,
712
+ values,
713
+ _args4 = arguments;
714
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
715
+ while (1) switch (_context4.prev = _context4.next) {
716
+ case 0:
717
+ sequenceId = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : "main";
718
+ child = this.tmodel.childHandles[index];
719
+ target = runtimeTarget.target;
720
+ targetName = runtimeTarget.targetName;
721
+ execution = this.getExecution(index, sequenceId, targetIndex);
722
+ if (execution) {
723
+ _context4.next = 25;
724
+ break;
725
+ }
726
+ value = target.value;
727
+ if (!(typeof value === "function")) {
728
+ _context4.next = 15;
729
+ break;
730
+ }
731
+ value = value.call(child);
732
+ if (!((_value = value) !== null && _value !== void 0 && _value.then)) {
733
+ _context4.next = 13;
734
+ break;
735
+ }
736
+ _context4.next = 12;
737
+ return value;
738
+ case 12:
739
+ value = _context4.sent;
740
+ case 13:
741
+ if (!this.disposed) {
742
+ _context4.next = 15;
743
+ break;
744
+ }
745
+ return _context4.abrupt("return");
746
+ case 15:
747
+ if (TUtil.isDefined(value)) {
748
+ _context4.next = 17;
749
+ break;
750
+ }
751
+ return _context4.abrupt("return");
752
+ case 17:
753
+ isValueList = Array.isArray(value);
754
+ currentValue = child.actualValues[targetName];
755
+ values = isValueList ? value : [TUtil.isDefined(currentValue) ? currentValue : value, value];
756
+ if (!(values.length < 2)) {
757
+ _context4.next = 23;
758
+ break;
759
+ }
760
+ if (values.length) {
761
+ child.actualValues[targetName] = values[0];
762
+ }
763
+ return _context4.abrupt("return");
764
+ case 23:
765
+ execution = {
766
+ sequenceId: sequenceId,
767
+ targetIndex: targetIndex,
768
+ kind: "runtime",
769
+ targetName: targetName,
770
+ imperativeKey: runtimeTarget.imperativeKey,
771
+ values: values,
772
+ isValueList: isValueList,
773
+ pauseOn: target.pauseOn,
774
+ segmentIndex: 0,
775
+ segmentReady: false,
776
+ step: 0,
777
+ segmentStartTime: 0,
778
+ waiting: false,
779
+ startTime: 0,
780
+ imperativeTarget: sequenceId.startsWith("imperative:") ? {
781
+ targetName: runtimeTarget.targetName,
782
+ imperativeKey: runtimeTarget.imperativeKey,
783
+ renderable: runtimeTarget.renderable,
784
+ originalTargetName: runtimeTarget.originalTargetName,
785
+ originalTargetIsParent: runtimeTarget.originalTargetIsParent,
786
+ target: _objectSpread({}, runtimeTarget.target)
787
+ } : undefined
788
+ };
789
+ this.setExecution(index, sequenceId, targetIndex, execution);
790
+ case 25:
791
+ if (!(execution.segmentIndex < execution.values.length - 1)) {
792
+ _context4.next = 39;
793
+ break;
794
+ }
795
+ if (!execution.segmentReady) {
796
+ this.prepareRenderSegment(execution, runtimeTarget, child);
797
+ }
798
+ _context4.next = 29;
799
+ return this.animateExecution(index, execution);
800
+ case 29:
801
+ if (!execution.cancelled) {
802
+ _context4.next = 31;
803
+ break;
804
+ }
805
+ return _context4.abrupt("return");
806
+ case 31:
807
+ execution.segmentIndex++;
808
+ execution.segmentReady = false;
809
+ execution.step = 0;
810
+ execution.segmentStartTime = 0;
811
+ execution.waiting = false;
812
+ execution.startTime = 0;
813
+ _context4.next = 25;
814
+ break;
815
+ case 39:
816
+ this.clearExecution(index, sequenceId, targetIndex);
817
+ case 40:
818
+ case "end":
819
+ return _context4.stop();
820
+ }
821
+ }, _callee4, this);
822
+ }));
823
+ function runRuntimeTarget(_x8, _x9, _x10) {
824
+ return _runRuntimeTarget.apply(this, arguments);
825
+ }
826
+ return runRuntimeTarget;
827
+ }()
553
828
  }, {
554
829
  key: "getExecutionId",
555
830
  value: function getExecutionId(sequenceId, targetIndex) {
@@ -585,10 +860,10 @@ var ParticleRuntime = /*#__PURE__*/function () {
585
860
  }, {
586
861
  key: "runIntervalTarget",
587
862
  value: function () {
588
- var _runIntervalTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(index, runtimeTarget, targetIndex, sequenceId) {
863
+ var _runIntervalTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(index, runtimeTarget, targetIndex, sequenceId) {
589
864
  var child, execution;
590
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
591
- while (1) switch (_context4.prev = _context4.next) {
865
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
866
+ while (1) switch (_context5.prev = _context5.next) {
592
867
  case 0:
593
868
  child = this.tmodel.childHandles[index];
594
869
  execution = this.getExecution(index, sequenceId, targetIndex);
@@ -603,17 +878,23 @@ var ParticleRuntime = /*#__PURE__*/function () {
603
878
  };
604
879
  this.setExecution(index, sequenceId, targetIndex, execution);
605
880
  }
606
- _context4.next = 5;
881
+ _context5.next = 5;
607
882
  return this.waitForExecution(execution);
608
883
  case 5:
884
+ if (!(this.disposed || execution.cancelled)) {
885
+ _context5.next = 7;
886
+ break;
887
+ }
888
+ return _context5.abrupt("return");
889
+ case 7:
609
890
  this.clearExecution(index, sequenceId, targetIndex);
610
- case 6:
891
+ case 8:
611
892
  case "end":
612
- return _context4.stop();
893
+ return _context5.stop();
613
894
  }
614
- }, _callee4, this);
895
+ }, _callee5, this);
615
896
  }));
616
- function runIntervalTarget(_x8, _x9, _x10, _x11) {
897
+ function runIntervalTarget(_x11, _x12, _x13, _x14) {
617
898
  return _runIntervalTarget.apply(this, arguments);
618
899
  }
619
900
  return runIntervalTarget;
@@ -621,10 +902,10 @@ var ParticleRuntime = /*#__PURE__*/function () {
621
902
  }, {
622
903
  key: "waitForExecution",
623
904
  value: function () {
624
- var _waitForExecution = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(execution) {
905
+ var _waitForExecution = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(execution) {
625
906
  var delay;
626
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
627
- while (1) switch (_context5.prev = _context5.next) {
907
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
908
+ while (1) switch (_context6.prev = _context6.next) {
628
909
  case 0:
629
910
  delay = execution.interval;
630
911
  if (execution.waiting && execution.startTime > 0) {
@@ -634,29 +915,79 @@ var ParticleRuntime = /*#__PURE__*/function () {
634
915
  execution.startTime = TUtil.now();
635
916
  }
636
917
  if (!(delay > 0)) {
637
- _context5.next = 5;
918
+ _context6.next = 5;
638
919
  break;
639
920
  }
640
- _context5.next = 5;
921
+ _context6.next = 5;
641
922
  return this.wait(delay);
642
923
  case 5:
643
924
  execution.waiting = false;
644
925
  execution.startTime = 0;
645
926
  case 7:
646
927
  case "end":
647
- return _context5.stop();
928
+ return _context6.stop();
648
929
  }
649
- }, _callee5, this);
930
+ }, _callee6, this);
650
931
  }));
651
- function waitForExecution(_x12) {
932
+ function waitForExecution(_x15) {
652
933
  return _waitForExecution.apply(this, arguments);
653
934
  }
654
935
  return waitForExecution;
655
936
  }()
937
+ }, {
938
+ key: "resolveInitialTargets",
939
+ value: function resolveInitialTargets() {
940
+ var tmodel = this.tmodel;
941
+ var changed = false;
942
+ var flowLayoutChanged = false;
943
+ for (var index = 0; index < tmodel.childRuntimePrograms.length; index++) {
944
+ var program = tmodel.childRuntimePrograms[index];
945
+ var child = tmodel.childHandles[index];
946
+ if (!program || !child) {
947
+ continue;
948
+ }
949
+ var _iterator7 = _createForOfIteratorHelper(program),
950
+ _step7;
951
+ try {
952
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
953
+ var runtimeTarget = _step7.value;
954
+ var isLayoutTarget = runtimeTarget.requiresRuntime === false && ParticleUtil.affectsChildLayout(runtimeTarget.targetName);
955
+ if (!isLayoutTarget && !runtimeTarget.requiresInitialResolution) {
956
+ continue;
957
+ }
958
+ var resolved = ParticleUtil.resolveValue(runtimeTarget.target, child);
959
+ var value = TargetParser.isTargetSpecObject(resolved) ? resolved.value : resolved;
960
+ var initialValue = Array.isArray(value) ? value[0] : value;
961
+ if (runtimeTarget.requiresInitialResolution) {
962
+ runtimeTarget.requiresInitialResolution = false;
963
+ runtimeTarget.initialResolvedValue = value;
964
+ }
965
+ if (tmodel.getChildValue(index, runtimeTarget.targetName) === initialValue) {
966
+ continue;
967
+ }
968
+ if (!tmodel.setChildValue(index, runtimeTarget.targetName, initialValue, false)) {
969
+ continue;
970
+ }
971
+ if (ParticleUtil.affectsChildFlowLayout(runtimeTarget.targetName)) {
972
+ flowLayoutChanged = true;
973
+ }
974
+ changed = true;
975
+ }
976
+ } catch (err) {
977
+ _iterator7.e(err);
978
+ } finally {
979
+ _iterator7.f();
980
+ }
981
+ }
982
+ if (flowLayoutChanged) {
983
+ tmodel.invalidateLayout();
984
+ }
985
+ return changed;
986
+ }
656
987
  }, {
657
988
  key: "runRenderTarget",
658
989
  value: function () {
659
- var _runRenderTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(index, runtimeTarget, targetIndex) {
990
+ var _runRenderTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(index, runtimeTarget, targetIndex) {
660
991
  var sequenceId,
661
992
  tmodel,
662
993
  child,
@@ -666,20 +997,25 @@ var ParticleRuntime = /*#__PURE__*/function () {
666
997
  value,
667
998
  isValueList,
668
999
  values,
669
- _args6 = arguments;
670
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
671
- while (1) switch (_context6.prev = _context6.next) {
1000
+ _args7 = arguments;
1001
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1002
+ while (1) switch (_context7.prev = _context7.next) {
672
1003
  case 0:
673
- sequenceId = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : "main";
1004
+ sequenceId = _args7.length > 3 && _args7[3] !== undefined ? _args7[3] : "main";
674
1005
  tmodel = this.tmodel;
675
1006
  child = tmodel.childHandles[index];
676
1007
  target = runtimeTarget.target;
677
1008
  targetName = runtimeTarget.targetName;
678
1009
  execution = this.getExecution(index, sequenceId, targetIndex);
679
1010
  if (!execution) {
680
- value = target.value;
681
- if (typeof value === "function") {
682
- value = value.call(child);
1011
+ if (sequenceId === "main" && TUtil.hasProperty(runtimeTarget, "initialResolvedValue")) {
1012
+ value = runtimeTarget.initialResolvedValue;
1013
+ delete runtimeTarget.initialResolvedValue;
1014
+ } else {
1015
+ value = target.value;
1016
+ if (typeof value === "function") {
1017
+ value = value.call(child);
1018
+ }
683
1019
  }
684
1020
  isValueList = Array.isArray(value);
685
1021
  values = isValueList ? value : [tmodel.getChildValue(index, targetName), value];
@@ -688,43 +1024,61 @@ var ParticleRuntime = /*#__PURE__*/function () {
688
1024
  targetIndex: targetIndex,
689
1025
  kind: "render",
690
1026
  targetName: targetName,
1027
+ imperativeKey: runtimeTarget.imperativeKey,
691
1028
  values: values,
692
1029
  isValueList: isValueList,
1030
+ pauseOn: target.pauseOn,
693
1031
  segmentIndex: 0,
694
1032
  segmentReady: false,
695
1033
  step: 0,
1034
+ segmentStartTime: 0,
696
1035
  waiting: false,
697
- startTime: 0
1036
+ startTime: 0,
1037
+ imperativeTarget: sequenceId.startsWith("imperative:") ? {
1038
+ targetName: runtimeTarget.targetName,
1039
+ imperativeKey: runtimeTarget.imperativeKey,
1040
+ renderable: runtimeTarget.renderable,
1041
+ originalTargetName: runtimeTarget.originalTargetName,
1042
+ originalTargetIsParent: runtimeTarget.originalTargetIsParent,
1043
+ target: _objectSpread({}, runtimeTarget.target)
1044
+ } : undefined
698
1045
  };
699
1046
  this.setExecution(index, sequenceId, targetIndex, execution);
700
1047
  }
701
1048
  case 7:
702
1049
  if (!(execution.segmentIndex < execution.values.length - 1)) {
703
- _context6.next = 18;
1050
+ _context7.next = 21;
704
1051
  break;
705
1052
  }
706
1053
  if (!execution.segmentReady) {
707
1054
  this.prepareRenderSegment(execution, runtimeTarget, child);
708
1055
  }
709
- _context6.next = 11;
1056
+ _context7.next = 11;
710
1057
  return this.animateExecution(index, execution);
711
1058
  case 11:
1059
+ if (!execution.cancelled) {
1060
+ _context7.next = 13;
1061
+ break;
1062
+ }
1063
+ return _context7.abrupt("return");
1064
+ case 13:
712
1065
  execution.segmentIndex++;
713
1066
  execution.segmentReady = false;
714
1067
  execution.step = 0;
1068
+ execution.segmentStartTime = 0;
715
1069
  execution.waiting = false;
716
1070
  execution.startTime = 0;
717
- _context6.next = 7;
1071
+ _context7.next = 7;
718
1072
  break;
719
- case 18:
1073
+ case 21:
720
1074
  this.clearExecution(index, sequenceId, targetIndex);
721
- case 19:
1075
+ case 22:
722
1076
  case "end":
723
- return _context6.stop();
1077
+ return _context7.stop();
724
1078
  }
725
- }, _callee6, this);
1079
+ }, _callee7, this);
726
1080
  }));
727
- function runRenderTarget(_x13, _x14, _x15) {
1081
+ function runRenderTarget(_x16, _x17, _x18) {
728
1082
  return _runRenderTarget.apply(this, arguments);
729
1083
  }
730
1084
  return runRenderTarget;
@@ -737,8 +1091,14 @@ var ParticleRuntime = /*#__PURE__*/function () {
737
1091
  execution.from = execution.values[segmentIndex];
738
1092
  execution.to = execution.values[segmentIndex + 1];
739
1093
  execution.steps = Math.max(0, Number(this.resolveOption(target.steps, child, segmentIndex)) || 0);
740
- execution.interval = TUtil.isDefined(target.interval) ? Math.max(0, Number(this.resolveOption(target.interval, child, segmentIndex)) || 0) : execution.isValueList && execution.steps > 0 ? 8 : 0;
1094
+ execution.interval = Math.max(0, Number(this.resolveOption(target.interval, child, segmentIndex)) || 0);
1095
+ if (execution.steps > 0 && !execution.interval) {
1096
+ execution.interval = 8;
1097
+ }
741
1098
  execution.easingName = this.resolveOption(target.easing, child, segmentIndex);
1099
+ if (!execution.segmentStartTime) {
1100
+ execution.segmentStartTime = TUtil.now() - execution.step * execution.interval;
1101
+ }
742
1102
  execution.segmentReady = true;
743
1103
  }
744
1104
  }, {
@@ -755,62 +1115,151 @@ var ParticleRuntime = /*#__PURE__*/function () {
755
1115
  }
756
1116
  }, {
757
1117
  key: "animateExecution",
758
- value: function () {
759
- var _animateExecution = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(index, execution) {
760
- var tmodel, easing, step, progress, easedProgress, value;
761
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
762
- while (1) switch (_context7.prev = _context7.next) {
763
- case 0:
764
- tmodel = this.tmodel;
765
- if (!(execution.steps <= 0)) {
766
- _context7.next = 5;
767
- break;
768
- }
769
- tmodel.setChildValue(index, execution.targetName, execution.to);
770
- tmodel.requestParticleRender();
771
- return _context7.abrupt("return");
772
- case 5:
773
- easing = execution.easingName ? Easing.easingFunction(execution.easingName) : undefined;
774
- step = execution.step + 1;
775
- case 7:
776
- if (!(step <= execution.steps)) {
777
- _context7.next = 20;
778
- break;
779
- }
780
- if (!(execution.interval > 0)) {
781
- _context7.next = 11;
782
- break;
783
- }
784
- _context7.next = 11;
785
- return this.waitForExecution(execution);
786
- case 11:
787
- progress = step / execution.steps;
788
- easedProgress = easing ? easing(progress) : progress;
789
- value = TModelUtil.morph(execution.targetName, execution.from, execution.to, easedProgress);
790
- tmodel.setChildValue(index, execution.targetName, value);
791
- execution.step = step;
792
- tmodel.requestParticleRender();
793
- case 17:
794
- step++;
795
- _context7.next = 7;
796
- break;
797
- case 20:
798
- case "end":
799
- return _context7.stop();
1118
+ value: function animateExecution(index, execution) {
1119
+ var _this6 = this;
1120
+ if (execution.steps <= 0) {
1121
+ var changed = this.setExecutionValue(index, execution, execution.to);
1122
+ if (changed && execution.kind === "render") {
1123
+ this.tmodel.requestParticleRender();
1124
+ }
1125
+ return Promise.resolve();
1126
+ }
1127
+ return new Promise(function (resolve) {
1128
+ execution.index = index;
1129
+ execution.resolve = resolve;
1130
+ _this6.activeRenderExecutions.add(execution);
1131
+ _this6.requestAnimationFrame();
1132
+ });
1133
+ }
1134
+ }, {
1135
+ key: "setExecutionValue",
1136
+ value: function setExecutionValue(index, execution, value) {
1137
+ if (execution.kind === "render") {
1138
+ return this.tmodel.setChildValue(index, execution.targetName, value, false);
1139
+ }
1140
+ var child = this.tmodel.childHandles[index];
1141
+ if (!child || child.actualValues[execution.targetName] === value) {
1142
+ return false;
1143
+ }
1144
+ child.actualValues[execution.targetName] = value;
1145
+ return true;
1146
+ }
1147
+ }, {
1148
+ key: "requestAnimationFrame",
1149
+ value: function (_requestAnimationFrame) {
1150
+ function requestAnimationFrame() {
1151
+ return _requestAnimationFrame.apply(this, arguments);
1152
+ }
1153
+ requestAnimationFrame.toString = function () {
1154
+ return _requestAnimationFrame.toString();
1155
+ };
1156
+ return requestAnimationFrame;
1157
+ }(function () {
1158
+ var _this7 = this;
1159
+ if (this.disposed || this.animationFrameRequested) {
1160
+ return;
1161
+ }
1162
+ this.animationFrameRequested = true;
1163
+ this.animationFrameId = requestAnimationFrame(function () {
1164
+ _this7.animationFrameId = undefined;
1165
+ _this7.animationFrameRequested = false;
1166
+ if (!_this7.disposed) {
1167
+ _this7.updateRenderExecutions();
1168
+ }
1169
+ });
1170
+ })
1171
+ }, {
1172
+ key: "updateRenderExecutions",
1173
+ value: function updateRenderExecutions() {
1174
+ if (this.disposed) {
1175
+ return;
1176
+ }
1177
+ this.startQueuedPrograms();
1178
+ var now = TUtil.now();
1179
+ var renderChanged = false;
1180
+ var layoutChanged = false;
1181
+ var _iterator8 = _createForOfIteratorHelper(this.activeRenderExecutions),
1182
+ _step8;
1183
+ try {
1184
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1185
+ var execution = _step8.value;
1186
+ var child = this.tmodel.childHandles[execution.index];
1187
+ var paused = typeof execution.pauseOn === "function" ? execution.pauseOn.call(child) : execution.pauseOn === true;
1188
+ if (paused) {
1189
+ var _execution$pausedAt;
1190
+ (_execution$pausedAt = execution.pausedAt) !== null && _execution$pausedAt !== void 0 ? _execution$pausedAt : execution.pausedAt = now;
1191
+ continue;
800
1192
  }
801
- }, _callee7, this);
802
- }));
803
- function animateExecution(_x16, _x17) {
804
- return _animateExecution.apply(this, arguments);
1193
+ if (execution.pausedAt !== undefined) {
1194
+ execution.segmentStartTime += now - execution.pausedAt;
1195
+ execution.pausedAt = undefined;
1196
+ }
1197
+ var elapsed = now - execution.segmentStartTime;
1198
+ var step = execution.interval > 0 ? Math.min(Math.floor(elapsed / execution.interval), execution.steps) : execution.steps;
1199
+ if (step <= execution.step) {
1200
+ continue;
1201
+ }
1202
+ var easing = execution.easingName ? Easing.easingFunction(execution.easingName) : undefined;
1203
+ var progress = step / execution.steps;
1204
+ var easedProgress = easing ? easing(progress) : progress;
1205
+ var value = TModelUtil.morph(execution.targetName, execution.from, execution.to, easedProgress);
1206
+ var valueChanged = this.setExecutionValue(execution.index, execution, value);
1207
+ if (execution.kind === "render" && valueChanged && ParticleUtil.affectsChildFlowLayout(execution.targetName)) {
1208
+ layoutChanged = true;
1209
+ }
1210
+ if (execution.kind === "render") {
1211
+ renderChanged || (renderChanged = valueChanged);
1212
+ }
1213
+ execution.step = step;
1214
+ if (step >= execution.steps) {
1215
+ this.activeRenderExecutions.delete(execution);
1216
+ var resolve = execution.resolve;
1217
+ execution.resolve = undefined;
1218
+ resolve();
1219
+ }
1220
+ }
1221
+ } catch (err) {
1222
+ _iterator8.e(err);
1223
+ } finally {
1224
+ _iterator8.f();
805
1225
  }
806
- return animateExecution;
807
- }()
1226
+ if (layoutChanged) {
1227
+ this.tmodel.invalidateLayout();
1228
+ }
1229
+ if (renderChanged) {
1230
+ this.tmodel.requestParticleRender();
1231
+ }
1232
+ if (this.startQueueIndex < this.startQueue.length || this.activeRenderExecutions.size) {
1233
+ this.requestAnimationFrame();
1234
+ }
1235
+ }
808
1236
  }, {
809
1237
  key: "wait",
810
1238
  value: function wait(interval) {
811
- return new Promise(function (resolve) {
812
- return setTimeout(resolve, Math.max(0, Number(interval) || 0));
813
- });
1239
+ var _this$waitBuckets,
1240
+ _this8 = this;
1241
+ if (this.disposed) {
1242
+ return Promise.resolve();
1243
+ }
1244
+ var delay = Math.max(0, Number(interval) || 0);
1245
+ if (delay === 0) {
1246
+ return Promise.resolve();
1247
+ }
1248
+ var deadline = Math.ceil((TUtil.now() + delay) / 4) * 4;
1249
+ (_this$waitBuckets = this.waitBuckets) !== null && _this$waitBuckets !== void 0 ? _this$waitBuckets : this.waitBuckets = new Map();
1250
+ var bucket = this.waitBuckets.get(deadline);
1251
+ if (!bucket) {
1252
+ bucket = {};
1253
+ bucket.promise = new Promise(function (resolve) {
1254
+ bucket.resolve = resolve;
1255
+ bucket.timeoutId = setTimeout(function () {
1256
+ _this8.waitBuckets.delete(deadline);
1257
+ resolve();
1258
+ }, Math.max(0, deadline - TUtil.now()));
1259
+ });
1260
+ this.waitBuckets.set(deadline, bucket);
1261
+ }
1262
+ return bucket.promise;
814
1263
  }
815
1264
  }, {
816
1265
  key: "findTargetIndex",
@@ -819,15 +1268,15 @@ var ParticleRuntime = /*#__PURE__*/function () {
819
1268
  if (!program) {
820
1269
  return -1;
821
1270
  }
822
- var cleanKey = TargetUtil.getTargetName(key);
1271
+ var cleanKey = ParticleUtil.getTargetName(key);
823
1272
  var exactIndex = program.findIndex(function (target) {
824
- return target.key === key;
1273
+ return target.requiresRuntime !== false && target.key === key;
825
1274
  });
826
1275
  if (exactIndex >= 0) {
827
1276
  return exactIndex;
828
1277
  }
829
1278
  return program.findIndex(function (target) {
830
- return target.targetName === cleanKey && target.mode === "immediate";
1279
+ return target.requiresRuntime !== false && target.targetName === cleanKey && target.mode === "immediate";
831
1280
  });
832
1281
  }
833
1282
  }, {
@@ -838,35 +1287,133 @@ var ParticleRuntime = /*#__PURE__*/function () {
838
1287
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
839
1288
  while (1) switch (_context8.prev = _context8.next) {
840
1289
  case 0:
1290
+ if (!this.disposed) {
1291
+ _context8.next = 2;
1292
+ break;
1293
+ }
1294
+ return _context8.abrupt("return");
1295
+ case 2:
841
1296
  program = this.tmodel.childRuntimePrograms[index];
842
- if (!(!program || startIndex < 0 || startIndex >= program.length)) {
843
- _context8.next = 3;
1297
+ if (!(this.disposed || !program || startIndex < 0 || startIndex >= program.length)) {
1298
+ _context8.next = 5;
844
1299
  break;
845
1300
  }
846
1301
  return _context8.abrupt("return");
847
- case 3:
848
- _context8.next = 5;
849
- return this.runTarget(index, program[startIndex], startIndex, sequenceId);
850
1302
  case 5:
851
1303
  _context8.next = 7;
852
- return this.continueActivatedSequence(index, startIndex + 1, sequenceId);
1304
+ return this.runTarget(index, program[startIndex], startIndex, sequenceId);
853
1305
  case 7:
1306
+ if (this.disposed) {
1307
+ _context8.next = 10;
1308
+ break;
1309
+ }
1310
+ _context8.next = 10;
1311
+ return this.continueActivatedSequence(index, startIndex + 1, sequenceId);
1312
+ case 10:
854
1313
  case "end":
855
1314
  return _context8.stop();
856
1315
  }
857
1316
  }, _callee8, this);
858
1317
  }));
859
- function runActivatedSequence(_x18, _x19, _x20) {
1318
+ function runActivatedSequence(_x19, _x20, _x21) {
860
1319
  return _runActivatedSequence.apply(this, arguments);
861
1320
  }
862
1321
  return runActivatedSequence;
863
1322
  }()
1323
+ }, {
1324
+ key: "cancelImperativeExecution",
1325
+ value: function cancelImperativeExecution(index, imperativeKey) {
1326
+ for (var _i3 = 0, _arr2 = _toConsumableArray(this.activeRenderExecutions); _i3 < _arr2.length; _i3++) {
1327
+ var execution = _arr2[_i3];
1328
+ if (execution.index !== index || execution.imperativeKey !== imperativeKey) {
1329
+ continue;
1330
+ }
1331
+ this.activeRenderExecutions.delete(execution);
1332
+ execution.cancelled = true;
1333
+ this.clearExecution(index, execution.sequenceId, execution.targetIndex);
1334
+ var resolve = execution.resolve;
1335
+ execution.resolve = undefined;
1336
+ resolve === null || resolve === void 0 || resolve();
1337
+ }
1338
+ }
1339
+ }, {
1340
+ key: "setImperativeTarget",
1341
+ value: function setImperativeTarget(index, key, rawTarget, steps, interval, easing, originalTargetName, originalTModel) {
1342
+ var _this9 = this;
1343
+ if (this.disposed) {
1344
+ return;
1345
+ }
1346
+ var child = this.tmodel.childHandles[index];
1347
+ if (!child) {
1348
+ return;
1349
+ }
1350
+ var imperativeKey = key.endsWith("+") ? key : "".concat(key, "+");
1351
+ this.cancelImperativeExecution(index, imperativeKey);
1352
+ var target = TargetParser.isTargetSpecObject(rawTarget) ? _objectSpread({}, rawTarget) : {
1353
+ value: rawTarget
1354
+ };
1355
+ if (target.steps === undefined) {
1356
+ target.steps = steps;
1357
+ }
1358
+ if (target.interval === undefined) {
1359
+ target.interval = interval;
1360
+ }
1361
+ if (target.easing === undefined) {
1362
+ target.easing = easing;
1363
+ }
1364
+ var _TargetParser$getValu = TargetParser.getValueStepsCycles(child, imperativeKey, target, 0),
1365
+ _TargetParser$getValu2 = _slicedToArray(_TargetParser$getValu, 4),
1366
+ value = _TargetParser$getValu2[0],
1367
+ parsedSteps = _TargetParser$getValu2[1],
1368
+ parsedInterval = _TargetParser$getValu2[2],
1369
+ parsedEasing = _TargetParser$getValu2[3];
1370
+ var targetValue = {
1371
+ isImperative: true,
1372
+ originalTargetName: originalTargetName,
1373
+ originalTModel: originalTModel,
1374
+ status: "updating",
1375
+ value: value,
1376
+ steps: parsedSteps || 0,
1377
+ interval: parsedInterval || 0,
1378
+ easing: parsedEasing
1379
+ };
1380
+ child.targetValues[imperativeKey] = targetValue;
1381
+ child.addToUpdatingTargets(imperativeKey);
1382
+ var runtimeTarget = {
1383
+ targetName: key,
1384
+ imperativeKey: imperativeKey,
1385
+ renderable: ParticleUtil.isGpuTarget(key),
1386
+ originalTargetName: originalTargetName,
1387
+ originalTargetIsParent: originalTModel === this.tmodel,
1388
+ target: {
1389
+ value: TargetParser.isListTarget(value) ? value.list : value,
1390
+ steps: parsedSteps,
1391
+ interval: parsedInterval,
1392
+ easing: parsedEasing,
1393
+ pauseOn: target.pauseOn
1394
+ }
1395
+ };
1396
+ var sequenceId = "imperative:".concat(index, ":").concat(imperativeKey, ":").concat(TUtil.now());
1397
+ var promise = runtimeTarget.renderable ? this.runRenderTarget(index, runtimeTarget, 0, sequenceId) : this.runRuntimeTarget(index, runtimeTarget, 0, sequenceId);
1398
+ promise.finally(function () {
1399
+ if (_this9.disposed || child.targetValues[imperativeKey] !== targetValue) {
1400
+ return;
1401
+ }
1402
+ targetValue.status = "done";
1403
+ child.removeFromUpdatingTargets(imperativeKey);
1404
+ if (originalTModel && originalTargetName) {
1405
+ TargetUtil.shouldActivateNextTarget(originalTModel, originalTargetName, 1, 0, true, "complete");
1406
+ }
1407
+ getRunScheduler().schedule(1, "gpuImperativeComplete-".concat(child.oid, "-").concat(imperativeKey));
1408
+ });
1409
+ return promise;
1410
+ }
864
1411
  }, {
865
1412
  key: "activateTarget",
866
1413
  value: function activateTarget(index, key) {
867
1414
  var _this$activeTargets2,
868
1415
  _this$activeTargets2$,
869
- _this4 = this;
1416
+ _this10 = this;
870
1417
  var state = this.tmodel.childRuntimeStates[index];
871
1418
  var program = this.tmodel.childRuntimePrograms[index];
872
1419
  if (!state || !program) {
@@ -877,22 +1424,90 @@ var ParticleRuntime = /*#__PURE__*/function () {
877
1424
  throw new Error("GPU child target \"".concat(key, "\" cannot be activated because it is not in the child runtime program."));
878
1425
  }
879
1426
  var runtimeTarget = program[startIndex];
880
- if (runtimeTarget.kind !== "render" && runtimeTarget.kind !== "runtime") {
1427
+ if (this.isIntervalTarget(runtimeTarget)) {
881
1428
  throw new Error("GPU child target \"".concat(key, "\" cannot be activated."));
882
1429
  }
883
1430
  var activationId = "".concat(runtimeTarget.key, "-").concat(++state.activationCount);
884
1431
  var sequenceId = "activation:".concat(activationId);
885
1432
  var activeTargets = (_this$activeTargets2$ = (_this$activeTargets2 = this.activeTargets)[index]) !== null && _this$activeTargets2$ !== void 0 ? _this$activeTargets2$ : _this$activeTargets2[index] = {};
886
1433
  var promise = Promise.resolve().then(function () {
887
- return _this4.runActivatedSequence(index, startIndex, sequenceId);
1434
+ return _this10.runActivatedSequence(index, startIndex, sequenceId);
888
1435
  }).catch(function (error) {
889
1436
  console.error(error);
890
1437
  }).finally(function () {
891
1438
  delete activeTargets[activationId];
1439
+ if (!_this10.disposed) {
1440
+ TargetUtil.cleanupVisibleComplete(_this10.tmodel, state.ownerTargetName);
1441
+ }
892
1442
  });
893
1443
  activeTargets[activationId] = promise;
894
1444
  return true;
895
1445
  }
1446
+ }, {
1447
+ key: "dispose",
1448
+ value: function dispose() {
1449
+ var _this$waitBuckets2, _this$waitBuckets$val, _this$waitBuckets3;
1450
+ if (this.disposed) {
1451
+ return;
1452
+ }
1453
+ this.disposed = true;
1454
+ if (this.animationFrameId !== undefined) {
1455
+ cancelAnimationFrame(this.animationFrameId);
1456
+ this.animationFrameId = undefined;
1457
+ }
1458
+ this.animationFrameRequested = false;
1459
+ this.startQueue.length = 0;
1460
+ this.startQueueIndex = 0;
1461
+ var _iterator9 = _createForOfIteratorHelper(this.tmodel.childRuntimeStates),
1462
+ _step9;
1463
+ try {
1464
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1465
+ var state = _step9.value;
1466
+ if (!state) {
1467
+ continue;
1468
+ }
1469
+ state.cancelled = true;
1470
+ for (var _i4 = 0, _Object$values = Object.values(state.executions || {}); _i4 < _Object$values.length; _i4++) {
1471
+ var execution = _Object$values[_i4];
1472
+ execution.cancelled = true;
1473
+ }
1474
+ }
1475
+ } catch (err) {
1476
+ _iterator9.e(err);
1477
+ } finally {
1478
+ _iterator9.f();
1479
+ }
1480
+ var _iterator10 = _createForOfIteratorHelper(this.activeRenderExecutions),
1481
+ _step10;
1482
+ try {
1483
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1484
+ var _execution = _step10.value;
1485
+ _execution.cancelled = true;
1486
+ var resolve = _execution.resolve;
1487
+ _execution.resolve = undefined;
1488
+ resolve === null || resolve === void 0 || resolve();
1489
+ }
1490
+ } catch (err) {
1491
+ _iterator10.e(err);
1492
+ } finally {
1493
+ _iterator10.f();
1494
+ }
1495
+ this.activeRenderExecutions.clear();
1496
+ var _iterator11 = _createForOfIteratorHelper((_this$waitBuckets$val = (_this$waitBuckets3 = this.waitBuckets) === null || _this$waitBuckets3 === void 0 ? void 0 : _this$waitBuckets3.values()) !== null && _this$waitBuckets$val !== void 0 ? _this$waitBuckets$val : []),
1497
+ _step11;
1498
+ try {
1499
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1500
+ var bucket = _step11.value;
1501
+ clearTimeout(bucket.timeoutId);
1502
+ bucket.resolve();
1503
+ }
1504
+ } catch (err) {
1505
+ _iterator11.e(err);
1506
+ } finally {
1507
+ _iterator11.f();
1508
+ }
1509
+ (_this$waitBuckets2 = this.waitBuckets) === null || _this$waitBuckets2 === void 0 || _this$waitBuckets2.clear();
1510
+ }
896
1511
  }]);
897
1512
  }();
898
1513
  export { ParticleRuntime };