targetj 1.0.260 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,12 +2,19 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  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
3
  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
4
  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); }); }; }
5
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
+ 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."); }
7
+ 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; } }
8
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return 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 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,77 +42,153 @@ 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;
52
+ this.loopQueue = [];
53
+ this.queuedLoops = new WeakMap();
54
+ this.runningLoops = new WeakMap();
55
+ this.imperativeCompletionFrame = undefined;
56
+ this.visibilityPaused = false;
57
+ this.restorePending = false;
58
+ this.propertyOwners = new WeakMap();
59
+ this.imperativeSequenceCount = 0;
37
60
  }
38
61
  return _createClass(ParticleRuntime, [{
39
62
  key: "registerChild",
40
- 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,
63
- ownerTargetName: targetName,
64
- programIndex: 0,
63
+ value: function registerChild(index, originalTargetName, compiled) {
64
+ var hasRuntime = compiled.runtimeTargets.some(function (target) {
65
+ return target.requiresRuntime !== false;
66
+ });
67
+ this.tmodel.childRuntimePrograms[index] = compiled.runtimeTargets;
68
+ this.tmodel.childRuntimeStates[index] = {
69
+ originalTargetName: originalTargetName,
70
+ nextTargetIndex: 0,
65
71
  activationCount: 0,
66
- layoutFunctions: layoutFunctions,
67
- layoutFunctionsResolved: layoutFunctions.length === 0,
68
72
  executions: {},
69
73
  startRequested: false,
74
+ startQueued: false,
70
75
  renderReady: false,
71
76
  started: false,
72
77
  done: !hasRuntime,
73
- pendingCompletion: hasRuntime
78
+ targetCycles: {},
79
+ loopTargets: {},
80
+ mainFinished: false
74
81
  };
75
82
  if (hasRuntime) {
76
- tmodel.pendingGpuChildRuntimeCounts[targetName] = (tmodel.pendingGpuChildRuntimeCounts[targetName] || 0) + 1;
83
+ this.tmodel.pendingGpuChildRuntimeCounts[originalTargetName] = (this.tmodel.pendingGpuChildRuntimeCounts[originalTargetName] || 0) + 1;
77
84
  }
78
85
  return hasRuntime;
79
86
  }
87
+ }, {
88
+ key: "removeChild",
89
+ value: function removeChild(index) {
90
+ var state = this.tmodel.childRuntimeStates[index];
91
+ if (state) {
92
+ state.cancelled = true;
93
+ state.loopTargets = {};
94
+ if (!state.done) {
95
+ this.complete(index);
96
+ }
97
+ }
98
+ for (var _i = 0, _arr = _toConsumableArray(this.activeRenderExecutions); _i < _arr.length; _i++) {
99
+ var execution = _arr[_i];
100
+ if (execution.index === index) {
101
+ this.activeRenderExecutions.delete(execution);
102
+ execution.cancelled = true;
103
+ var resolve = execution.resolve;
104
+ execution.resolve = undefined;
105
+ resolve === null || resolve === void 0 || resolve();
106
+ continue;
107
+ }
108
+ if (execution.index > index) {
109
+ execution.index--;
110
+ }
111
+ }
112
+ this.tmodel.childRuntimePrograms.splice(index, 1);
113
+ this.tmodel.childRuntimeStates.splice(index, 1);
114
+ this.activeTargets.splice(index, 1);
115
+ this.startQueue = this.startQueue.slice(this.startQueueIndex).filter(function (childIndex) {
116
+ return childIndex !== index;
117
+ }).map(function (childIndex) {
118
+ return childIndex > index ? childIndex - 1 : childIndex;
119
+ });
120
+ this.startQueueIndex = 0;
121
+ this.restoredMainIndexes = this.restoredMainIndexes.filter(function (childIndex) {
122
+ return childIndex !== index;
123
+ }).map(function (childIndex) {
124
+ return childIndex > index ? childIndex - 1 : childIndex;
125
+ });
126
+ this.restoredActivationSequences = this.restoredActivationSequences.filter(function (item) {
127
+ return item.index !== index;
128
+ }).map(function (item) {
129
+ return item.index > index ? _objectSpread(_objectSpread({}, item), {}, {
130
+ index: item.index - 1
131
+ }) : item;
132
+ });
133
+ this.restoredImperativeExecutions = this.restoredImperativeExecutions.filter(function (item) {
134
+ return item.index !== index;
135
+ }).map(function (item) {
136
+ return item.index > index ? _objectSpread(_objectSpread({}, item), {}, {
137
+ index: item.index - 1
138
+ }) : item;
139
+ });
140
+ }
80
141
  }, {
81
142
  key: "hasPending",
82
143
  value: function hasPending(key) {
83
- var targetName = TargetUtil.getTargetName(key);
84
- return (this.tmodel.pendingGpuChildRuntimeCounts[targetName] || 0) > 0;
144
+ var _this = this;
145
+ var completionScope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "all";
146
+ if (completionScope === "none") {
147
+ return false;
148
+ }
149
+ return this.tmodel.childRuntimeStates.some(function (state, index) {
150
+ if (!state || key !== undefined && state.originalTargetName !== key) {
151
+ return false;
152
+ }
153
+ if (completionScope === "visible" && TargetUtil.shouldIgnoreChildForCompletion(_this.tmodel.childHandles[index], "visible")) {
154
+ return false;
155
+ }
156
+ return !state.renderReady || !state.done || Object.keys(_this.activeTargets[index] || {}).length > 0;
157
+ });
158
+ }
159
+ }, {
160
+ key: "hasPendingAny",
161
+ value: function hasPendingAny() {
162
+ var completionScope = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "all";
163
+ return this.hasPending(undefined, completionScope);
164
+ }
165
+ }, {
166
+ key: "isIntervalTarget",
167
+ value: function isIntervalTarget(runtimeTarget) {
168
+ return TargetParser.isIntervalTarget(runtimeTarget.target);
85
169
  }
86
170
  }, {
87
171
  key: "prepareRestore",
88
172
  value: function prepareRestore() {
173
+ this.restorePending = true;
89
174
  this.restoredMainIndexes = [];
90
175
  this.restoredActivationSequences = [];
176
+ this.restoredImperativeExecutions = [];
91
177
  for (var index = 0; index < this.tmodel.childRuntimeStates.length; index++) {
92
- var _state$executions, _state$activationCoun;
178
+ var _state$executions, _state$activationCoun, _state$targetCycles, _state$loopTargets, _state$mainFinished;
93
179
  var state = this.tmodel.childRuntimeStates[index];
94
180
  if (!state) {
95
181
  continue;
96
182
  }
97
183
  (_state$executions = state.executions) !== null && _state$executions !== void 0 ? _state$executions : state.executions = {};
98
184
  (_state$activationCoun = state.activationCount) !== null && _state$activationCoun !== void 0 ? _state$activationCoun : state.activationCount = 0;
185
+ (_state$targetCycles = state.targetCycles) !== null && _state$targetCycles !== void 0 ? _state$targetCycles : state.targetCycles = {};
186
+ (_state$loopTargets = state.loopTargets) !== null && _state$loopTargets !== void 0 ? _state$loopTargets : state.loopTargets = {};
187
+ (_state$mainFinished = state.mainFinished) !== null && _state$mainFinished !== void 0 ? _state$mainFinished : state.mainFinished = false;
99
188
  var executions = Object.values(state.executions);
100
189
  var mainExecutions = executions.filter(function (execution) {
101
190
  return execution.sequenceId === "main";
102
191
  });
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
192
  if (!state.done && (state.started || mainExecutions.length)) {
109
193
  this.restoredMainIndexes.push(index);
110
194
  }
@@ -113,24 +197,35 @@ var ParticleRuntime = /*#__PURE__*/function () {
113
197
  }).filter(function (sequenceId) {
114
198
  return sequenceId === null || sequenceId === void 0 ? void 0 : sequenceId.startsWith("activation:");
115
199
  })));
116
- var _iterator2 = _createForOfIteratorHelper(activationSequenceIds),
117
- _step2;
200
+ var _iterator = _createForOfIteratorHelper(activationSequenceIds),
201
+ _step;
118
202
  try {
119
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
120
- var sequenceId = _step2.value;
203
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
204
+ var sequenceId = _step.value;
121
205
  this.restoredActivationSequences.push({
122
206
  index: index,
123
207
  sequenceId: sequenceId
124
208
  });
125
209
  }
126
-
127
- /*
128
- * Promise/timer state belonged to the old ParticleRuntime.
129
- */
130
210
  } catch (err) {
131
- _iterator2.e(err);
211
+ _iterator.e(err);
132
212
  } finally {
133
- _iterator2.f();
213
+ _iterator.f();
214
+ }
215
+ for (var _i2 = 0, _executions = executions; _i2 < _executions.length; _i2++) {
216
+ var _execution$sequenceId;
217
+ var execution = _executions[_i2];
218
+ if ((_execution$sequenceId = execution.sequenceId) !== null && _execution$sequenceId !== void 0 && _execution$sequenceId.startsWith("imperative:")) {
219
+ var lastPart = execution.sequenceId.split(":").pop();
220
+ var count = Number(lastPart);
221
+ if (Number.isFinite(count)) {
222
+ this.imperativeSequenceCount = Math.max(this.imperativeSequenceCount, count);
223
+ }
224
+ this.restoredImperativeExecutions.push({
225
+ index: index,
226
+ execution: execution
227
+ });
228
+ }
134
229
  }
135
230
  state.started = false;
136
231
  state.renderReady = false;
@@ -140,41 +235,86 @@ var ParticleRuntime = /*#__PURE__*/function () {
140
235
  }, {
141
236
  key: "resumeRestored",
142
237
  value: function resumeRestored() {
238
+ if (this.disposed || !this.restorePending || !this.tmodel.isVisible()) {
239
+ return false;
240
+ }
241
+ this.restorePending = false;
143
242
  var mainIndexes = this.restoredMainIndexes.splice(0);
144
243
  var activationSequences = this.restoredActivationSequences.splice(0);
145
- var _iterator3 = _createForOfIteratorHelper(mainIndexes),
244
+ var imperativeExecutions = this.restoredImperativeExecutions.splice(0);
245
+ var _iterator2 = _createForOfIteratorHelper(mainIndexes),
246
+ _step2;
247
+ try {
248
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
249
+ var _index = _step2.value;
250
+ this.resumeMainProgram(_index);
251
+ }
252
+ } catch (err) {
253
+ _iterator2.e(err);
254
+ } finally {
255
+ _iterator2.f();
256
+ }
257
+ var _iterator3 = _createForOfIteratorHelper(activationSequences),
146
258
  _step3;
147
259
  try {
148
260
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
149
- var index = _step3.value;
150
- this.resumeMainProgram(index);
261
+ var _step3$value = _step3.value,
262
+ _index2 = _step3$value.index,
263
+ _sequenceId = _step3$value.sequenceId;
264
+ this.resumeActivationSequence(_index2, _sequenceId);
151
265
  }
152
266
  } catch (err) {
153
267
  _iterator3.e(err);
154
268
  } finally {
155
269
  _iterator3.f();
156
270
  }
157
- var _iterator4 = _createForOfIteratorHelper(activationSequences),
271
+ var _iterator4 = _createForOfIteratorHelper(imperativeExecutions),
158
272
  _step4;
159
273
  try {
160
274
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
161
275
  var _step4$value = _step4.value,
162
- _index = _step4$value.index,
163
- sequenceId = _step4$value.sequenceId;
164
- this.resumeActivationSequence(_index, sequenceId);
276
+ _index3 = _step4$value.index,
277
+ _execution = _step4$value.execution;
278
+ this.resumeImperativeExecution(_index3, _execution);
165
279
  }
166
280
  } catch (err) {
167
281
  _iterator4.e(err);
168
282
  } finally {
169
283
  _iterator4.f();
170
284
  }
285
+ for (var index = 0; index < this.tmodel.childRuntimeStates.length; index++) {
286
+ var state = this.tmodel.childRuntimeStates[index];
287
+ if (!state || state.done) {
288
+ continue;
289
+ }
290
+ for (var _i3 = 0, _Object$entries = Object.entries(state.loopTargets || {}); _i3 < _Object$entries.length; _i3++) {
291
+ var _state$executions2;
292
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i3], 2),
293
+ key = _Object$entries$_i[0],
294
+ active = _Object$entries$_i[1];
295
+ if (!active) {
296
+ continue;
297
+ }
298
+ var targetIndex = Number(key);
299
+ var sequenceId = "loop:".concat(targetIndex);
300
+ var execution = (_state$executions2 = state.executions) === null || _state$executions2 === void 0 ? void 0 : _state$executions2[this.getExecutionId(sequenceId, targetIndex)];
301
+ if (execution !== null && execution !== void 0 && execution.segmentReady && execution.interval > 0) {
302
+ execution.segmentStartTime = TUtil.now() - execution.step * execution.interval;
303
+ execution.pausedAt = undefined;
304
+ }
305
+ this.queueLoop(index, targetIndex);
306
+ }
307
+ }
308
+ if (this.tmodel.pendingImperativeCompletions.size) {
309
+ this.queueImperativeCompletion();
310
+ }
171
311
  }
172
312
  }, {
173
313
  key: "resumeActivationSequence",
174
314
  value: function resumeActivationSequence(index, sequenceId) {
175
315
  var _this$activeTargets,
176
316
  _this$activeTargets$i,
177
- _this = this;
317
+ _this2 = this;
178
318
  var state = this.tmodel.childRuntimeStates[index];
179
319
  if (!state) {
180
320
  return false;
@@ -191,9 +331,11 @@ var ParticleRuntime = /*#__PURE__*/function () {
191
331
  var activationId = sequenceId.startsWith("activation:") ? sequenceId.slice("activation:".length) : sequenceId;
192
332
  var activeTargets = (_this$activeTargets$i = (_this$activeTargets = this.activeTargets)[index]) !== null && _this$activeTargets$i !== void 0 ? _this$activeTargets$i : _this$activeTargets[index] = {};
193
333
  var promise = Promise.all(executions.map(function (execution) {
194
- return _this.resumeExecution(index, execution);
195
- })).then(function () {
196
- return _this.continueActivatedSequence(index, currentTargetIndex + 1, sequenceId);
334
+ return _this2.resumeExecution(index, execution);
335
+ })).then(function (results) {
336
+ if (results.every(Boolean)) {
337
+ return _this2.continueActivatedSequence(index, currentTargetIndex + 1, sequenceId);
338
+ }
197
339
  }).catch(function (error) {
198
340
  console.error(error);
199
341
  }).finally(function () {
@@ -202,39 +344,102 @@ var ParticleRuntime = /*#__PURE__*/function () {
202
344
  activeTargets[activationId] = promise;
203
345
  return true;
204
346
  }
347
+ }, {
348
+ key: "resumeImperativeExecution",
349
+ value: function resumeImperativeExecution(index, execution) {
350
+ var _runtimeTarget$target,
351
+ _this3 = this;
352
+ var child = this.tmodel.childHandles[index];
353
+ var state = this.tmodel.childRuntimeStates[index];
354
+ var runtimeTarget = execution === null || execution === void 0 ? void 0 : execution.imperativeTarget;
355
+ if (!child || !state || !runtimeTarget) {
356
+ return false;
357
+ }
358
+ if (execution.kind !== "render" && execution.kind !== "runtime") {
359
+ return false;
360
+ }
361
+ var imperativeKey = execution.imperativeKey || runtimeTarget.imperativeKey || "".concat(execution.targetName, "+");
362
+
363
+ // Resume from the saved animation step rather than from the old absolute clock time.
364
+ if (execution.segmentReady && execution.interval > 0) {
365
+ execution.segmentStartTime = TUtil.now() - execution.step * execution.interval;
366
+ execution.pausedAt = undefined;
367
+ }
368
+ var targetValue = {
369
+ isImperative: true,
370
+ originalTargetName: runtimeTarget.originalTargetName,
371
+ originalTModel: runtimeTarget.originalTargetIsParent ? this.tmodel : undefined,
372
+ status: "updating",
373
+ value: runtimeTarget.target.value,
374
+ steps: runtimeTarget.target.steps || 0,
375
+ interval: runtimeTarget.target.interval || 0,
376
+ easing: runtimeTarget.target.easing,
377
+ cycles: (_runtimeTarget$target = runtimeTarget.target.cycles) !== null && _runtimeTarget$target !== void 0 ? _runtimeTarget$target : 1
378
+ };
379
+ child.targetValues[imperativeKey] = targetValue;
380
+ child.addToUpdatingTargets(imperativeKey);
381
+ var promise = this.runTarget(index, runtimeTarget, execution.targetIndex, execution.sequenceId, targetValue);
382
+ Promise.resolve(promise).catch(function (error) {
383
+ console.error(error);
384
+ return false;
385
+ }).then(function (completed) {
386
+ if (_this3.disposed || child.targetValues[imperativeKey] !== targetValue) {
387
+ return;
388
+ }
389
+ targetValue.status = completed ? "done" : "cancelled";
390
+ child.removeFromUpdatingTargets(imperativeKey);
391
+ if (completed) {
392
+ _this3.queueImperativeCompletion(runtimeTarget.originalTargetIsParent ? _this3.tmodel : undefined, runtimeTarget.originalTargetName);
393
+ }
394
+ });
395
+ return true;
396
+ }
205
397
  }, {
206
398
  key: "continueActivatedSequence",
207
399
  value: function () {
208
- var _continueActivatedSequence = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(index, programIndex, sequenceId) {
209
- var program, runtimeTarget;
400
+ var _continueActivatedSequence = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(index, nextTargetIndex, sequenceId) {
401
+ var program, runtimeTarget, completed;
210
402
  return _regeneratorRuntime().wrap(function _callee$(_context) {
211
403
  while (1) switch (_context.prev = _context.next) {
212
404
  case 0:
405
+ if (!this.disposed) {
406
+ _context.next = 2;
407
+ break;
408
+ }
409
+ return _context.abrupt("return");
410
+ case 2:
213
411
  program = this.tmodel.childRuntimePrograms[index];
214
412
  if (program) {
215
- _context.next = 3;
413
+ _context.next = 5;
216
414
  break;
217
415
  }
218
416
  return _context.abrupt("return");
219
- case 3:
220
- if (!(programIndex < program.length)) {
221
- _context.next = 12;
417
+ case 5:
418
+ if (!(!this.disposed && nextTargetIndex < program.length)) {
419
+ _context.next = 17;
222
420
  break;
223
421
  }
224
- runtimeTarget = program[programIndex];
422
+ runtimeTarget = program[nextTargetIndex];
225
423
  if (!(runtimeTarget.mode !== "deferred")) {
226
- _context.next = 7;
424
+ _context.next = 9;
227
425
  break;
228
426
  }
229
- return _context.abrupt("break", 12);
230
- case 7:
231
- _context.next = 9;
232
- return this.runTarget(index, runtimeTarget, programIndex, sequenceId);
427
+ return _context.abrupt("break", 17);
233
428
  case 9:
234
- programIndex++;
235
- _context.next = 3;
429
+ _context.next = 11;
430
+ return this.runTarget(index, runtimeTarget, nextTargetIndex, sequenceId);
431
+ case 11:
432
+ completed = _context.sent;
433
+ if (completed) {
434
+ _context.next = 14;
435
+ break;
436
+ }
437
+ return _context.abrupt("return");
438
+ case 14:
439
+ nextTargetIndex++;
440
+ _context.next = 5;
236
441
  break;
237
- case 12:
442
+ case 17:
238
443
  case "end":
239
444
  return _context.stop();
240
445
  }
@@ -248,9 +453,9 @@ var ParticleRuntime = /*#__PURE__*/function () {
248
453
  }, {
249
454
  key: "resumeMainProgram",
250
455
  value: function resumeMainProgram(index) {
251
- var _this2 = this;
456
+ var _this4 = this;
252
457
  var state = this.tmodel.childRuntimeStates[index];
253
- if (!state || state.done || state.started) {
458
+ if (this.disposed || !state || state.done || state.started) {
254
459
  return;
255
460
  }
256
461
  state.started = true;
@@ -258,13 +463,13 @@ var ParticleRuntime = /*#__PURE__*/function () {
258
463
  return execution.sequenceId === "main";
259
464
  });
260
465
  Promise.all(runningExecutions.map(function (execution) {
261
- return _this2.resumeExecution(index, execution);
466
+ return _this4.resumeExecution(index, execution);
262
467
  })).then(function () {
263
- return _this2.runProgram(index);
468
+ return _this4.runProgram(index);
264
469
  }).catch(function (error) {
265
470
  console.error(error);
266
471
  }).finally(function () {
267
- _this2.complete(index);
472
+ _this4.finishMainProgram(index, state);
268
473
  });
269
474
  }
270
475
  }, {
@@ -275,28 +480,14 @@ var ParticleRuntime = /*#__PURE__*/function () {
275
480
  if (!runtimeTarget) {
276
481
  return Promise.resolve();
277
482
  }
278
- if (execution.kind === "interval") {
279
- return this.runIntervalTarget(index, runtimeTarget, execution.targetIndex, execution.sequenceId);
280
- }
281
- if (execution.kind === "render") {
282
- return this.runRenderTarget(index, runtimeTarget, execution.targetIndex, execution.sequenceId);
283
- }
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;
293
- }
294
- var targetName = ParticleUtil.getGpuRenderTargetName(key);
295
- return ((_state$controlledTarg = state.controlledTargets) === null || _state$controlledTarg === void 0 ? void 0 : _state$controlledTarg[targetName]) === true;
483
+ return this.runTarget(index, runtimeTarget, execution.targetIndex, execution.sequenceId);
296
484
  }
297
485
  }, {
298
486
  key: "complete",
299
487
  value: function complete(index) {
488
+ if (this.disposed) {
489
+ return;
490
+ }
300
491
  var tmodel = this.tmodel;
301
492
  var state = tmodel.childRuntimeStates[index];
302
493
  if (!state || state.done) {
@@ -304,56 +495,27 @@ var ParticleRuntime = /*#__PURE__*/function () {
304
495
  }
305
496
  state.done = true;
306
497
  state.started = false;
307
- if (!state.pendingCompletion) {
308
- return;
309
- }
310
- state.pendingCompletion = false;
311
- var targetName = state.ownerTargetName;
312
- var count = Math.max(0, (tmodel.pendingGpuChildRuntimeCounts[targetName] || 0) - 1);
498
+ var originalTargetName = state.originalTargetName;
499
+ var count = Math.max(0, (tmodel.pendingGpuChildRuntimeCounts[originalTargetName] || 0) - 1);
313
500
  if (count > 0) {
314
- tmodel.pendingGpuChildRuntimeCounts[targetName] = count;
315
- return;
501
+ tmodel.pendingGpuChildRuntimeCounts[originalTargetName] = count;
502
+ } else {
503
+ delete tmodel.pendingGpuChildRuntimeCounts[originalTargetName];
504
+ getRunScheduler().schedule(1, "gpuChildRuntimeComplete-".concat(tmodel.oid));
316
505
  }
317
- delete tmodel.pendingGpuChildRuntimeCounts[targetName];
318
- getRunScheduler().schedule(1, "gpuChildRuntimeComplete-".concat(tmodel.oid));
506
+ TargetUtil.cleanupVisibleComplete(tmodel, originalTargetName);
507
+ this.completeOriginalTarget(originalTargetName);
319
508
  }
320
509
  }, {
321
- key: "resolveLayoutFunctions",
322
- value: function resolveLayoutFunctions() {
510
+ key: "completeOriginalTarget",
511
+ value: function completeOriginalTarget(originalTargetName) {
323
512
  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
- }
513
+ if (!tmodel.isTargetDone(originalTargetName) || !tmodel.isTargetTreeComplete(originalTargetName)) {
514
+ return false;
355
515
  }
356
- return changed;
516
+ TargetUtil.cleanupTarget(tmodel, originalTargetName);
517
+ TargetUtil.shouldActivateNextTarget(tmodel, originalTargetName);
518
+ return true;
357
519
  }
358
520
  }, {
359
521
  key: "queueStart",
@@ -363,81 +525,125 @@ var ParticleRuntime = /*#__PURE__*/function () {
363
525
  return;
364
526
  }
365
527
  state.startRequested = true;
366
- this.startReady();
367
528
  }
368
529
  }, {
369
530
  key: "markRenderReady",
370
531
  value: function markRenderReady(indexes) {
371
- var _iterator6 = _createForOfIteratorHelper(indexes),
372
- _step6;
532
+ var originalTargetNames = new Set();
533
+ var _iterator5 = _createForOfIteratorHelper(indexes),
534
+ _step5;
373
535
  try {
374
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
375
- var index = _step6.value;
536
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
537
+ var index = _step5.value;
376
538
  var state = this.tmodel.childRuntimeStates[index];
377
- if (state) {
378
- state.renderReady = true;
539
+ if (!state) {
540
+ continue;
379
541
  }
542
+ state.renderReady = true;
543
+ originalTargetNames.add(state.originalTargetName);
544
+ }
545
+ } catch (err) {
546
+ _iterator5.e(err);
547
+ } finally {
548
+ _iterator5.f();
549
+ }
550
+ this.startReady();
551
+ var tmodel = this.tmodel;
552
+ var _iterator6 = _createForOfIteratorHelper(originalTargetNames),
553
+ _step6;
554
+ try {
555
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
556
+ var originalTargetName = _step6.value;
557
+ this.completeOriginalTarget(originalTargetName);
380
558
  }
381
559
  } catch (err) {
382
560
  _iterator6.e(err);
383
561
  } finally {
384
562
  _iterator6.f();
385
563
  }
386
- this.startReady();
564
+ if (originalTargetNames.size > 0) {
565
+ getRunScheduler().schedule(1, "gpuChildrenRenderReady-".concat(tmodel.oid));
566
+ }
387
567
  }
388
568
  }, {
389
569
  key: "markPendingRenderReady",
390
570
  value: function markPendingRenderReady() {
391
- var _iterator7 = _createForOfIteratorHelper(this.tmodel.childRuntimeStates),
392
- _step7;
393
- try {
394
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
395
- var state = _step7.value;
396
- if (state !== null && state !== void 0 && state.startRequested && !state.started && !state.done) {
397
- state.renderReady = true;
398
- }
571
+ var indexes = [];
572
+ for (var i = 0; i < this.tmodel.childRuntimeStates.length; i++) {
573
+ var state = this.tmodel.childRuntimeStates[i];
574
+ if (state && !state.renderReady) {
575
+ indexes.push(i);
399
576
  }
400
- } catch (err) {
401
- _iterator7.e(err);
402
- } finally {
403
- _iterator7.f();
404
577
  }
405
- this.startReady();
578
+ this.markRenderReady(indexes);
406
579
  }
407
580
  }, {
408
581
  key: "startReady",
409
582
  value: function startReady() {
583
+ if (this.disposed) {
584
+ return;
585
+ }
410
586
  var tmodel = this.tmodel;
411
- if (!tmodel.hasDom() || tmodel.completeLayoutEpoch !== tmodel.layoutEpoch) {
587
+ if (!tmodel.isVisible() || !tmodel.hasDom() || tmodel.completeLayoutEpoch !== tmodel.layoutEpoch) {
412
588
  return false;
413
589
  }
414
- var started = false;
590
+ var queued = false;
415
591
  for (var index = 0; index < tmodel.childRuntimeStates.length; index++) {
416
592
  var state = tmodel.childRuntimeStates[index];
417
- if (!state || !state.startRequested || !state.renderReady || state.started || state.done) {
593
+ if (!state || !state.startRequested || !state.renderReady || state.startQueued || state.started || state.done) {
594
+ continue;
595
+ }
596
+ state.startQueued = true;
597
+ this.startQueue.push(index);
598
+ queued = true;
599
+ }
600
+ if (queued) {
601
+ this.requestAnimationFrame();
602
+ }
603
+ return queued;
604
+ }
605
+ }, {
606
+ key: "startQueuedPrograms",
607
+ value: function startQueuedPrograms() {
608
+ var frameStart = TUtil.now();
609
+ var count = 0;
610
+ while (this.startQueueIndex < this.startQueue.length && count < 5000 && TUtil.now() - frameStart < 4) {
611
+ var index = this.startQueue[this.startQueueIndex++];
612
+ var state = this.tmodel.childRuntimeStates[index];
613
+ if (!state) {
614
+ continue;
615
+ }
616
+ state.startQueued = false;
617
+ if (!state.startRequested || !state.renderReady || state.started || state.done) {
418
618
  continue;
419
619
  }
420
620
  state.startRequested = false;
421
621
  this.start(index);
422
- started = true;
622
+ count++;
623
+ }
624
+ if (this.startQueueIndex >= this.startQueue.length) {
625
+ this.startQueue.length = 0;
626
+ this.startQueueIndex = 0;
423
627
  }
424
- return started;
425
628
  }
426
629
  }, {
427
630
  key: "start",
428
631
  value: function start(index) {
429
- var _this3 = this;
632
+ var _this5 = this;
633
+ if (this.disposed) {
634
+ return;
635
+ }
430
636
  var state = this.tmodel.childRuntimeStates[index];
431
637
  var program = this.tmodel.childRuntimePrograms[index];
432
638
  if (!state || !(program !== null && program !== void 0 && program.length) || state.started || state.done) {
433
639
  return;
434
640
  }
435
641
  state.started = true;
436
- state.programIndex = 0;
642
+ state.nextTargetIndex = 0;
437
643
  Promise.resolve(this.runProgram(index)).catch(function (error) {
438
644
  console.error(error);
439
645
  }).finally(function () {
440
- _this3.complete(index);
646
+ _this5.finishMainProgram(index, state);
441
647
  });
442
648
  }
443
649
  }, {
@@ -448,37 +654,49 @@ var ParticleRuntime = /*#__PURE__*/function () {
448
654
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
449
655
  while (1) switch (_context2.prev = _context2.next) {
450
656
  case 0:
657
+ if (!this.disposed) {
658
+ _context2.next = 2;
659
+ break;
660
+ }
661
+ return _context2.abrupt("return");
662
+ case 2:
451
663
  state = this.tmodel.childRuntimeStates[index];
452
664
  program = this.tmodel.childRuntimePrograms[index];
453
665
  if (!(!state || !program)) {
454
- _context2.next = 4;
666
+ _context2.next = 6;
455
667
  break;
456
668
  }
457
669
  return _context2.abrupt("return");
458
- case 4:
670
+ case 6:
459
671
  immediate = [];
460
- while (state.programIndex < program.length && program[state.programIndex].mode === "immediate") {
461
- targetIndex = state.programIndex++;
672
+ while (!state.cancelled && state.nextTargetIndex < program.length && program[state.nextTargetIndex].mode === "immediate") {
673
+ targetIndex = state.nextTargetIndex++;
462
674
  immediate.push(this.runTarget(index, program[targetIndex], targetIndex, "main"));
463
675
  }
464
676
  if (!immediate.length) {
465
- _context2.next = 9;
677
+ _context2.next = 11;
466
678
  break;
467
679
  }
468
- _context2.next = 9;
680
+ _context2.next = 11;
469
681
  return Promise.all(immediate);
470
- case 9:
471
- if (!(state.programIndex < program.length)) {
472
- _context2.next = 15;
682
+ case 11:
683
+ if (!state.cancelled) {
684
+ _context2.next = 13;
473
685
  break;
474
686
  }
475
- _targetIndex = state.programIndex++;
476
- _context2.next = 13;
477
- return this.runTarget(index, program[_targetIndex], _targetIndex, "main");
687
+ return _context2.abrupt("return");
478
688
  case 13:
479
- _context2.next = 9;
689
+ if (!(!state.cancelled && state.nextTargetIndex < program.length)) {
690
+ _context2.next = 19;
691
+ break;
692
+ }
693
+ _targetIndex = state.nextTargetIndex++;
694
+ _context2.next = 17;
695
+ return this.runTarget(index, program[_targetIndex], _targetIndex, "main");
696
+ case 17:
697
+ _context2.next = 13;
480
698
  break;
481
- case 15:
699
+ case 19:
482
700
  case "end":
483
701
  return _context2.stop();
484
702
  }
@@ -493,57 +711,139 @@ var ParticleRuntime = /*#__PURE__*/function () {
493
711
  key: "runTarget",
494
712
  value: function () {
495
713
  var _runTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(index, runtimeTarget, targetIndex) {
714
+ var _state$targetCycles2,
715
+ _this6 = this;
496
716
  var sequenceId,
717
+ owner,
718
+ state,
497
719
  child,
498
- value,
499
- result,
720
+ targetName,
721
+ automaticLoop,
722
+ owners,
723
+ ownership,
724
+ cycleKey,
725
+ isCancelled,
726
+ completedCycles,
727
+ cycles,
500
728
  _args3 = arguments;
501
729
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
502
730
  while (1) switch (_context3.prev = _context3.next) {
503
731
  case 0:
504
732
  sequenceId = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : "main";
505
- child = this.tmodel.childHandles[index];
506
- if (child) {
733
+ owner = _args3.length > 4 ? _args3[4] : undefined;
734
+ if (!(this.disposed || runtimeTarget.requiresRuntime === false)) {
507
735
  _context3.next = 4;
508
736
  break;
509
737
  }
510
- return _context3.abrupt("return");
738
+ return _context3.abrupt("return", false);
511
739
  case 4:
512
- if (!(runtimeTarget.kind === "interval")) {
740
+ state = this.tmodel.childRuntimeStates[index];
741
+ child = this.tmodel.childHandles[index];
742
+ if (!(!state || !child || state.cancelled)) {
513
743
  _context3.next = 8;
514
744
  break;
515
745
  }
516
- _context3.next = 7;
517
- return this.runIntervalTarget(index, runtimeTarget, targetIndex, sequenceId);
518
- case 7:
519
- return _context3.abrupt("return");
746
+ return _context3.abrupt("return", false);
520
747
  case 8:
521
- if (!(runtimeTarget.kind === "render")) {
522
- _context3.next = 12;
748
+ targetName = ParticleUtil.getTargetName(runtimeTarget.targetName);
749
+ automaticLoop = sequenceId.startsWith("loop:");
750
+ if (!(automaticLoop && this.isTargetUpdating(index, targetName, sequenceId, targetIndex))) {
751
+ _context3.next = 13;
523
752
  break;
524
753
  }
525
- _context3.next = 11;
526
- return this.runRenderTarget(index, runtimeTarget, targetIndex, sequenceId);
527
- case 11:
528
- return _context3.abrupt("return");
529
- case 12:
530
- value = runtimeTarget.target.value;
531
- if (!(typeof value === "function")) {
532
- _context3.next = 18;
754
+ this.blockLoop(index, targetIndex);
755
+ return _context3.abrupt("return", false);
756
+ case 13:
757
+ // Any newly activated target replaces the previous property owner.
758
+ this.cancelPropertyExecutions(index, targetName, sequenceId, targetIndex);
759
+ owners = this.propertyOwners.get(state);
760
+ if (!owners) {
761
+ owners = new Map();
762
+ this.propertyOwners.set(state, owners);
763
+ }
764
+ ownership = {
765
+ sequenceId: sequenceId,
766
+ targetIndex: targetIndex
767
+ };
768
+ owners.set(targetName, ownership);
769
+ cycleKey = this.getExecutionId(sequenceId, targetIndex);
770
+ (_state$targetCycles2 = state.targetCycles) !== null && _state$targetCycles2 !== void 0 ? _state$targetCycles2 : state.targetCycles = {};
771
+ isCancelled = function isCancelled() {
772
+ return _this6.disposed || state.cancelled || _this6.tmodel.childHandles[index] !== child || owners.get(targetName) !== ownership || owner && child.targetValues[runtimeTarget.imperativeKey] !== owner;
773
+ };
774
+ _context3.prev = 21;
775
+ case 22:
776
+ if (isCancelled()) {
777
+ _context3.next = 44;
533
778
  break;
534
779
  }
535
- result = value.call(child);
536
- if (!(result !== null && result !== void 0 && result.then)) {
537
- _context3.next = 18;
780
+ if (!this.isIntervalTarget(runtimeTarget)) {
781
+ _context3.next = 28;
538
782
  break;
539
783
  }
540
- _context3.next = 18;
541
- return result;
542
- case 18:
784
+ _context3.next = 26;
785
+ return this.runIntervalTarget(index, runtimeTarget, targetIndex, sequenceId, isCancelled);
786
+ case 26:
787
+ _context3.next = 35;
788
+ break;
789
+ case 28:
790
+ if (!runtimeTarget.renderable) {
791
+ _context3.next = 33;
792
+ break;
793
+ }
794
+ _context3.next = 31;
795
+ return this.runRenderTarget(index, runtimeTarget, targetIndex, sequenceId, isCancelled);
796
+ case 31:
797
+ _context3.next = 35;
798
+ break;
799
+ case 33:
800
+ _context3.next = 35;
801
+ return this.runRuntimeTarget(index, runtimeTarget, targetIndex, sequenceId, isCancelled);
802
+ case 35:
803
+ if (!isCancelled()) {
804
+ _context3.next = 37;
805
+ break;
806
+ }
807
+ return _context3.abrupt("return", false);
808
+ case 37:
809
+ completedCycles = (state.targetCycles[cycleKey] || 0) + 1;
810
+ cycles = this.getTargetCycles(runtimeTarget, child, completedCycles - 1);
811
+ if (!(completedCycles >= cycles)) {
812
+ _context3.next = 41;
813
+ break;
814
+ }
815
+ return _context3.abrupt("break", 44);
816
+ case 41:
817
+ state.targetCycles[cycleKey] = completedCycles;
818
+ _context3.next = 22;
819
+ break;
820
+ case 44:
821
+ if (!isCancelled()) {
822
+ _context3.next = 46;
823
+ break;
824
+ }
825
+ return _context3.abrupt("return", false);
826
+ case 46:
827
+ if (!sequenceId.startsWith("imperative:") && this.isTargetInLoop(runtimeTarget, child)) {
828
+ this.queueLoop(index, targetIndex);
829
+ } else if (automaticLoop) {
830
+ delete state.loopTargets[targetIndex];
831
+ this.completeIfReady(index);
832
+ }
833
+ return _context3.abrupt("return", true);
834
+ case 48:
835
+ _context3.prev = 48;
836
+ if (owners.get(targetName) === ownership) {
837
+ owners.delete(targetName);
838
+ this.queueBlockedLoops(index, targetName);
839
+ }
840
+ delete state.targetCycles[cycleKey];
841
+ return _context3.finish(48);
842
+ case 52:
543
843
  case "end":
544
844
  return _context3.stop();
545
845
  }
546
- }, _callee3, this);
846
+ }, _callee3, this, [[21,, 48, 52]]);
547
847
  }));
548
848
  function runTarget(_x5, _x6, _x7) {
549
849
  return _runTarget.apply(this, arguments);
@@ -551,80 +851,434 @@ var ParticleRuntime = /*#__PURE__*/function () {
551
851
  return runTarget;
552
852
  }()
553
853
  }, {
554
- key: "getExecutionId",
555
- value: function getExecutionId(sequenceId, targetIndex) {
556
- return "".concat(sequenceId, ":").concat(targetIndex);
557
- }
558
- }, {
559
- key: "getExecution",
560
- value: function getExecution(index, sequenceId, targetIndex) {
561
- var _state$executions2;
854
+ key: "isTargetUpdating",
855
+ value: function isTargetUpdating(index, key, sequenceId, targetIndex) {
856
+ var _this$propertyOwners$;
562
857
  var state = this.tmodel.childRuntimeStates[index];
563
- return state === null || state === void 0 || (_state$executions2 = state.executions) === null || _state$executions2 === void 0 ? void 0 : _state$executions2[this.getExecutionId(sequenceId, targetIndex)];
858
+ var property = ParticleUtil.getTargetName(key);
859
+ var owner = (_this$propertyOwners$ = this.propertyOwners.get(state)) === null || _this$propertyOwners$ === void 0 ? void 0 : _this$propertyOwners$.get(property);
860
+ if (owner && !(owner.sequenceId === sequenceId && owner.targetIndex === targetIndex)) {
861
+ return true;
862
+ }
863
+ return Object.values((state === null || state === void 0 ? void 0 : state.executions) || {}).some(function (execution) {
864
+ return !execution.cancelled && execution.targetName === property && !(execution.sequenceId === sequenceId && execution.targetIndex === targetIndex);
865
+ });
564
866
  }
565
867
  }, {
566
- key: "setExecution",
567
- value: function setExecution(index, sequenceId, targetIndex, execution) {
568
- var _state$executions3;
868
+ key: "blockLoop",
869
+ value: function blockLoop(index, targetIndex) {
870
+ var _state$blockedLoops;
569
871
  var state = this.tmodel.childRuntimeStates[index];
570
872
  if (!state) {
571
873
  return;
572
874
  }
573
- (_state$executions3 = state.executions) !== null && _state$executions3 !== void 0 ? _state$executions3 : state.executions = {};
574
- state.executions[this.getExecutionId(sequenceId, targetIndex)] = execution;
875
+ ((_state$blockedLoops = state.blockedLoops) !== null && _state$blockedLoops !== void 0 ? _state$blockedLoops : state.blockedLoops = {})[targetIndex] = true;
575
876
  }
576
877
  }, {
577
- key: "clearExecution",
578
- value: function clearExecution(index, sequenceId, targetIndex) {
878
+ key: "queueBlockedLoops",
879
+ value: function queueBlockedLoops(index, key) {
579
880
  var state = this.tmodel.childRuntimeStates[index];
580
- if (!(state !== null && state !== void 0 && state.executions)) {
881
+ var program = this.tmodel.childRuntimePrograms[index];
882
+ if (!state || !program || state.cancelled || this.disposed || this.isTargetUpdating(index, key)) {
581
883
  return;
582
884
  }
583
- delete state.executions[this.getExecutionId(sequenceId, targetIndex)];
885
+ var running = this.runningLoops.get(state);
886
+ for (var _i4 = 0, _Object$keys = Object.keys(state.blockedLoops || {}); _i4 < _Object$keys.length; _i4++) {
887
+ var _program$targetIndex, _state$loopTargets2;
888
+ var id = _Object$keys[_i4];
889
+ var targetIndex = Number(id);
890
+ if (((_program$targetIndex = program[targetIndex]) === null || _program$targetIndex === void 0 ? void 0 : _program$targetIndex.targetName) !== key || !((_state$loopTargets2 = state.loopTargets) !== null && _state$loopTargets2 !== void 0 && _state$loopTargets2[targetIndex]) || running !== null && running !== void 0 && running.has(targetIndex)) {
891
+ continue;
892
+ }
893
+ delete state.blockedLoops[id];
894
+ this.queueLoop(index, targetIndex);
895
+ }
584
896
  }
585
897
  }, {
586
- key: "runIntervalTarget",
587
- value: function () {
588
- var _runIntervalTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(index, runtimeTarget, targetIndex, sequenceId) {
589
- var child, execution;
590
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
591
- while (1) switch (_context4.prev = _context4.next) {
592
- case 0:
593
- child = this.tmodel.childHandles[index];
594
- execution = this.getExecution(index, sequenceId, targetIndex);
595
- if (!execution) {
596
- execution = {
597
- sequenceId: sequenceId,
598
- targetIndex: targetIndex,
599
- kind: "interval",
600
- interval: Math.max(0, Number(this.resolveOption(runtimeTarget.target.interval, child)) || 0),
601
- waiting: false,
602
- startTime: 0
603
- };
604
- this.setExecution(index, sequenceId, targetIndex, execution);
605
- }
606
- _context4.next = 5;
607
- return this.waitForExecution(execution);
608
- case 5:
609
- this.clearExecution(index, sequenceId, targetIndex);
610
- case 6:
611
- case "end":
612
- return _context4.stop();
613
- }
614
- }, _callee4, this);
615
- }));
616
- function runIntervalTarget(_x8, _x9, _x10, _x11) {
617
- return _runIntervalTarget.apply(this, arguments);
898
+ key: "cancelPropertyExecutions",
899
+ value: function cancelPropertyExecutions(index, key, sequenceId, targetIndex) {
900
+ var _this7 = this;
901
+ var state = this.tmodel.childRuntimeStates[index];
902
+ var child = this.tmodel.childHandles[index];
903
+ var program = this.tmodel.childRuntimePrograms[index];
904
+ if (!state || !child) {
905
+ return;
618
906
  }
619
- return runIntervalTarget;
620
- }()
621
- }, {
622
- key: "waitForExecution",
623
- value: function () {
624
- var _waitForExecution = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(execution) {
625
- var delay;
907
+ var property = ParticleUtil.getTargetName(key);
908
+ var owners = this.propertyOwners.get(state);
909
+ var previous = owners === null || owners === void 0 ? void 0 : owners.get(property);
910
+ var rememberLoop = function rememberLoop(previousSequence, previousIndex) {
911
+ if (previousSequence !== null && previousSequence !== void 0 && previousSequence.startsWith("imperative:")) {
912
+ return;
913
+ }
914
+ var target = program === null || program === void 0 ? void 0 : program[previousIndex];
915
+ if ((target === null || target === void 0 ? void 0 : target.targetName) === property && _this7.isTargetInLoop(target, child)) {
916
+ var _state$loopTargets3;
917
+ (_state$loopTargets3 = state.loopTargets) !== null && _state$loopTargets3 !== void 0 ? _state$loopTargets3 : state.loopTargets = {};
918
+ state.loopTargets[previousIndex] = true;
919
+ _this7.blockLoop(index, previousIndex);
920
+ }
921
+ };
922
+ if (previous && !(previous.sequenceId === sequenceId && previous.targetIndex === targetIndex)) {
923
+ rememberLoop(previous.sequenceId, previous.targetIndex);
924
+ owners.delete(property);
925
+ }
926
+
927
+ // Preserve previously queued loops.
928
+ for (var _i5 = 0, _Object$entries2 = Object.entries(state.loopTargets || {}); _i5 < _Object$entries2.length; _i5++) {
929
+ var _program$Number;
930
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i5], 2),
931
+ id = _Object$entries2$_i[0],
932
+ pending = _Object$entries2$_i[1];
933
+ if (pending && (program === null || program === void 0 || (_program$Number = program[Number(id)]) === null || _program$Number === void 0 ? void 0 : _program$Number.targetName) === property) {
934
+ this.blockLoop(index, Number(id));
935
+ }
936
+ }
937
+
938
+ // Cancel every previous execution of the same property.
939
+ for (var _i6 = 0, _Object$entries3 = Object.entries(state.executions || {}); _i6 < _Object$entries3.length; _i6++) {
940
+ var _execution$cancelWait;
941
+ var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i6], 2),
942
+ _id = _Object$entries3$_i[0],
943
+ execution = _Object$entries3$_i[1];
944
+ if (execution.cancelled || execution.targetName !== property || execution.sequenceId === sequenceId && execution.targetIndex === targetIndex) {
945
+ continue;
946
+ }
947
+ rememberLoop(execution.sequenceId, execution.targetIndex);
948
+ execution.cancelled = true;
949
+ (_execution$cancelWait = execution.cancelWait) === null || _execution$cancelWait === void 0 || _execution$cancelWait.call(execution);
950
+ execution.cancelWait = undefined;
951
+ this.activeRenderExecutions.delete(execution);
952
+ delete state.executions[_id];
953
+ var resolve = execution.resolve;
954
+ execution.resolve = undefined;
955
+ resolve === null || resolve === void 0 || resolve();
956
+ }
957
+ }
958
+ }, {
959
+ key: "queueLoop",
960
+ value: function queueLoop(index, targetIndex) {
961
+ var _state$loopTargets4, _this$tmodel$childRun;
962
+ var state = this.tmodel.childRuntimeStates[index];
963
+ if (this.disposed || !state || state.cancelled) {
964
+ return;
965
+ }
966
+ (_state$loopTargets4 = state.loopTargets) !== null && _state$loopTargets4 !== void 0 ? _state$loopTargets4 : state.loopTargets = {};
967
+ state.loopTargets[targetIndex] = true;
968
+ var targetName = (_this$tmodel$childRun = this.tmodel.childRuntimePrograms[index]) === null || _this$tmodel$childRun === void 0 || (_this$tmodel$childRun = _this$tmodel$childRun[targetIndex]) === null || _this$tmodel$childRun === void 0 ? void 0 : _this$tmodel$childRun.targetName;
969
+ if (targetName && this.isTargetUpdating(index, targetName)) {
970
+ this.blockLoop(index, targetIndex);
971
+ return;
972
+ }
973
+ var queued = this.queuedLoops.get(state);
974
+ if (!queued) {
975
+ queued = new Set();
976
+ this.queuedLoops.set(state, queued);
977
+ }
978
+ if (queued.has(targetIndex)) {
979
+ return;
980
+ }
981
+ queued.add(targetIndex);
982
+ this.loopQueue.push({
983
+ state: state,
984
+ targetIndex: targetIndex
985
+ });
986
+ this.requestAnimationFrame();
987
+ }
988
+ }, {
989
+ key: "startQueuedLoops",
990
+ value: function startQueuedLoops() {
991
+ var _this8 = this;
992
+ var queue = this.loopQueue.splice(0);
993
+ var _iterator7 = _createForOfIteratorHelper(queue),
994
+ _step7;
995
+ try {
996
+ var _loop = function _loop() {
997
+ var _this8$queuedLoops$ge, _state$loopTargets5, _this8$tmodel$childRu;
998
+ var _step7$value = _step7.value,
999
+ state = _step7$value.state,
1000
+ targetIndex = _step7$value.targetIndex;
1001
+ (_this8$queuedLoops$ge = _this8.queuedLoops.get(state)) === null || _this8$queuedLoops$ge === void 0 || _this8$queuedLoops$ge.delete(targetIndex);
1002
+ var index = _this8.tmodel.childRuntimeStates.indexOf(state);
1003
+ if (_this8.disposed || index < 0 || state.cancelled || !((_state$loopTargets5 = state.loopTargets) !== null && _state$loopTargets5 !== void 0 && _state$loopTargets5[targetIndex])) {
1004
+ return 0; // continue
1005
+ }
1006
+ var runtimeTarget = (_this8$tmodel$childRu = _this8.tmodel.childRuntimePrograms[index]) === null || _this8$tmodel$childRu === void 0 ? void 0 : _this8$tmodel$childRu[targetIndex];
1007
+ if (!runtimeTarget) {
1008
+ delete state.loopTargets[targetIndex];
1009
+ _this8.completeIfReady(index);
1010
+ return 0; // continue
1011
+ }
1012
+ var running = _this8.runningLoops.get(state);
1013
+ if (!running) {
1014
+ running = new Set();
1015
+ _this8.runningLoops.set(state, running);
1016
+ }
1017
+ if (running.has(targetIndex) || _this8.isTargetUpdating(index, runtimeTarget.targetName)) {
1018
+ _this8.blockLoop(index, targetIndex);
1019
+ return 0; // continue
1020
+ }
1021
+ running.add(targetIndex);
1022
+ _this8.runTarget(index, runtimeTarget, targetIndex, "loop:".concat(targetIndex)).catch(function (error) {
1023
+ console.error(error);
1024
+ delete state.loopTargets[targetIndex];
1025
+ var currentIndex = _this8.tmodel.childRuntimeStates.indexOf(state);
1026
+ if (currentIndex >= 0) {
1027
+ _this8.completeIfReady(currentIndex);
1028
+ }
1029
+ }).finally(function () {
1030
+ running.delete(targetIndex);
1031
+ var currentIndex = _this8.tmodel.childRuntimeStates.indexOf(state);
1032
+ if (currentIndex >= 0) {
1033
+ _this8.queueBlockedLoops(currentIndex, runtimeTarget.targetName);
1034
+ }
1035
+ });
1036
+ },
1037
+ _ret;
1038
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1039
+ _ret = _loop();
1040
+ if (_ret === 0) continue;
1041
+ }
1042
+ } catch (err) {
1043
+ _iterator7.e(err);
1044
+ } finally {
1045
+ _iterator7.f();
1046
+ }
1047
+ }
1048
+ }, {
1049
+ key: "runRuntimeTarget",
1050
+ value: function () {
1051
+ var _runRuntimeTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(index, runtimeTarget, targetIndex) {
1052
+ var sequenceId,
1053
+ isCancelled,
1054
+ child,
1055
+ target,
1056
+ targetName,
1057
+ execution,
1058
+ value,
1059
+ _value,
1060
+ isValueList,
1061
+ currentValue,
1062
+ values,
1063
+ _args4 = arguments;
1064
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1065
+ while (1) switch (_context4.prev = _context4.next) {
1066
+ case 0:
1067
+ sequenceId = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : "main";
1068
+ isCancelled = _args4.length > 4 ? _args4[4] : undefined;
1069
+ if (!isCancelled()) {
1070
+ _context4.next = 4;
1071
+ break;
1072
+ }
1073
+ return _context4.abrupt("return");
1074
+ case 4:
1075
+ child = this.tmodel.childHandles[index];
1076
+ target = runtimeTarget.target;
1077
+ targetName = runtimeTarget.targetName;
1078
+ execution = this.getExecution(index, sequenceId, targetIndex);
1079
+ if (execution) {
1080
+ _context4.next = 28;
1081
+ break;
1082
+ }
1083
+ value = target.value;
1084
+ if (!(typeof value === "function")) {
1085
+ _context4.next = 18;
1086
+ break;
1087
+ }
1088
+ value = value.call(child);
1089
+ if (!((_value = value) !== null && _value !== void 0 && _value.then)) {
1090
+ _context4.next = 16;
1091
+ break;
1092
+ }
1093
+ _context4.next = 15;
1094
+ return value;
1095
+ case 15:
1096
+ value = _context4.sent;
1097
+ case 16:
1098
+ if (!isCancelled()) {
1099
+ _context4.next = 18;
1100
+ break;
1101
+ }
1102
+ return _context4.abrupt("return");
1103
+ case 18:
1104
+ if (!(isCancelled() || !TUtil.isDefined(value))) {
1105
+ _context4.next = 20;
1106
+ break;
1107
+ }
1108
+ return _context4.abrupt("return");
1109
+ case 20:
1110
+ isValueList = Array.isArray(value);
1111
+ currentValue = child.actualValues[targetName];
1112
+ values = isValueList ? value : [TUtil.isDefined(currentValue) ? currentValue : value, value];
1113
+ if (!(values.length < 2)) {
1114
+ _context4.next = 26;
1115
+ break;
1116
+ }
1117
+ if (values.length) {
1118
+ child.actualValues[targetName] = values[0];
1119
+ }
1120
+ return _context4.abrupt("return");
1121
+ case 26:
1122
+ execution = {
1123
+ sequenceId: sequenceId,
1124
+ targetIndex: targetIndex,
1125
+ kind: "runtime",
1126
+ targetName: targetName,
1127
+ imperativeKey: runtimeTarget.imperativeKey,
1128
+ values: values,
1129
+ isValueList: isValueList,
1130
+ pauseOn: target.pauseOn,
1131
+ segmentIndex: 0,
1132
+ segmentReady: false,
1133
+ step: 0,
1134
+ segmentStartTime: 0,
1135
+ waiting: false,
1136
+ startTime: 0,
1137
+ imperativeTarget: sequenceId.startsWith("imperative:") ? {
1138
+ targetName: runtimeTarget.targetName,
1139
+ imperativeKey: runtimeTarget.imperativeKey,
1140
+ renderable: runtimeTarget.renderable,
1141
+ originalTargetName: runtimeTarget.originalTargetName,
1142
+ originalTargetIsParent: runtimeTarget.originalTargetIsParent,
1143
+ target: _objectSpread({}, runtimeTarget.target)
1144
+ } : undefined
1145
+ };
1146
+ this.setExecution(index, sequenceId, targetIndex, execution);
1147
+ case 28:
1148
+ if (!(execution.segmentIndex < execution.values.length - 1)) {
1149
+ _context4.next = 46;
1150
+ break;
1151
+ }
1152
+ if (!(execution.cancelled || isCancelled())) {
1153
+ _context4.next = 31;
1154
+ break;
1155
+ }
1156
+ return _context4.abrupt("return");
1157
+ case 31:
1158
+ if (!execution.segmentReady) {
1159
+ this.prepareRenderSegment(execution, runtimeTarget, child);
1160
+ }
1161
+ if (!(execution.cancelled || isCancelled())) {
1162
+ _context4.next = 34;
1163
+ break;
1164
+ }
1165
+ return _context4.abrupt("return");
1166
+ case 34:
1167
+ _context4.next = 36;
1168
+ return this.animateExecution(index, execution);
1169
+ case 36:
1170
+ if (!(execution.cancelled || isCancelled())) {
1171
+ _context4.next = 38;
1172
+ break;
1173
+ }
1174
+ return _context4.abrupt("return");
1175
+ case 38:
1176
+ execution.segmentIndex++;
1177
+ execution.segmentReady = false;
1178
+ execution.step = 0;
1179
+ execution.segmentStartTime = 0;
1180
+ execution.waiting = false;
1181
+ execution.startTime = 0;
1182
+ _context4.next = 28;
1183
+ break;
1184
+ case 46:
1185
+ this.clearExecution(index, sequenceId, targetIndex);
1186
+ case 47:
1187
+ case "end":
1188
+ return _context4.stop();
1189
+ }
1190
+ }, _callee4, this);
1191
+ }));
1192
+ function runRuntimeTarget(_x8, _x9, _x10) {
1193
+ return _runRuntimeTarget.apply(this, arguments);
1194
+ }
1195
+ return runRuntimeTarget;
1196
+ }()
1197
+ }, {
1198
+ key: "getExecutionId",
1199
+ value: function getExecutionId(sequenceId, targetIndex) {
1200
+ return "".concat(sequenceId, ":").concat(targetIndex);
1201
+ }
1202
+ }, {
1203
+ key: "getExecution",
1204
+ value: function getExecution(index, sequenceId, targetIndex) {
1205
+ var _state$executions3;
1206
+ var state = this.tmodel.childRuntimeStates[index];
1207
+ return state === null || state === void 0 || (_state$executions3 = state.executions) === null || _state$executions3 === void 0 ? void 0 : _state$executions3[this.getExecutionId(sequenceId, targetIndex)];
1208
+ }
1209
+ }, {
1210
+ key: "setExecution",
1211
+ value: function setExecution(index, sequenceId, targetIndex, execution) {
1212
+ var _state$executions4;
1213
+ var state = this.tmodel.childRuntimeStates[index];
1214
+ if (!state) {
1215
+ return;
1216
+ }
1217
+ (_state$executions4 = state.executions) !== null && _state$executions4 !== void 0 ? _state$executions4 : state.executions = {};
1218
+ state.executions[this.getExecutionId(sequenceId, targetIndex)] = execution;
1219
+ }
1220
+ }, {
1221
+ key: "clearExecution",
1222
+ value: function clearExecution(index, sequenceId, targetIndex) {
1223
+ var state = this.tmodel.childRuntimeStates[index];
1224
+ if (!(state !== null && state !== void 0 && state.executions)) {
1225
+ return;
1226
+ }
1227
+ delete state.executions[this.getExecutionId(sequenceId, targetIndex)];
1228
+ }
1229
+ }, {
1230
+ key: "runIntervalTarget",
1231
+ value: function () {
1232
+ var _runIntervalTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(index, runtimeTarget, targetIndex, sequenceId, isCancelled) {
1233
+ var child, execution;
626
1234
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
627
1235
  while (1) switch (_context5.prev = _context5.next) {
1236
+ case 0:
1237
+ child = this.tmodel.childHandles[index];
1238
+ execution = this.getExecution(index, sequenceId, targetIndex);
1239
+ if (!execution) {
1240
+ execution = {
1241
+ sequenceId: sequenceId,
1242
+ targetIndex: targetIndex,
1243
+ kind: "interval",
1244
+ targetName: runtimeTarget.targetName,
1245
+ interval: Math.max(0, Number(this.resolveOption(runtimeTarget.target.interval, child)) || 0),
1246
+ waiting: false,
1247
+ startTime: 0
1248
+ };
1249
+ this.setExecution(index, sequenceId, targetIndex, execution);
1250
+ }
1251
+ _context5.next = 5;
1252
+ return Promise.race([this.waitForExecution(execution), new Promise(function (resolve) {
1253
+ execution.cancelWait = resolve;
1254
+ })]);
1255
+ case 5:
1256
+ execution.cancelWait = undefined;
1257
+ if (!(isCancelled() || execution.cancelled)) {
1258
+ _context5.next = 8;
1259
+ break;
1260
+ }
1261
+ return _context5.abrupt("return");
1262
+ case 8:
1263
+ this.clearExecution(index, sequenceId, targetIndex);
1264
+ case 9:
1265
+ case "end":
1266
+ return _context5.stop();
1267
+ }
1268
+ }, _callee5, this);
1269
+ }));
1270
+ function runIntervalTarget(_x11, _x12, _x13, _x14, _x15) {
1271
+ return _runIntervalTarget.apply(this, arguments);
1272
+ }
1273
+ return runIntervalTarget;
1274
+ }()
1275
+ }, {
1276
+ key: "waitForExecution",
1277
+ value: function () {
1278
+ var _waitForExecution = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(execution) {
1279
+ var delay;
1280
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1281
+ while (1) switch (_context6.prev = _context6.next) {
628
1282
  case 0:
629
1283
  delay = execution.interval;
630
1284
  if (execution.waiting && execution.startTime > 0) {
@@ -634,97 +1288,186 @@ var ParticleRuntime = /*#__PURE__*/function () {
634
1288
  execution.startTime = TUtil.now();
635
1289
  }
636
1290
  if (!(delay > 0)) {
637
- _context5.next = 5;
1291
+ _context6.next = 5;
638
1292
  break;
639
1293
  }
640
- _context5.next = 5;
1294
+ _context6.next = 5;
641
1295
  return this.wait(delay);
642
1296
  case 5:
643
1297
  execution.waiting = false;
644
1298
  execution.startTime = 0;
645
1299
  case 7:
646
1300
  case "end":
647
- return _context5.stop();
1301
+ return _context6.stop();
648
1302
  }
649
- }, _callee5, this);
1303
+ }, _callee6, this);
650
1304
  }));
651
- function waitForExecution(_x12) {
1305
+ function waitForExecution(_x16) {
652
1306
  return _waitForExecution.apply(this, arguments);
653
1307
  }
654
1308
  return waitForExecution;
655
1309
  }()
1310
+ }, {
1311
+ key: "resolveInitialTargets",
1312
+ value: function resolveInitialTargets() {
1313
+ var tmodel = this.tmodel;
1314
+ var changed = false;
1315
+ var flowLayoutChanged = false;
1316
+ for (var index = 0; index < tmodel.childRuntimePrograms.length; index++) {
1317
+ var program = tmodel.childRuntimePrograms[index];
1318
+ var _child = tmodel.childHandles[index];
1319
+ if (!program || !_child) {
1320
+ continue;
1321
+ }
1322
+ var _iterator8 = _createForOfIteratorHelper(program),
1323
+ _step8;
1324
+ try {
1325
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1326
+ var runtimeTarget = _step8.value;
1327
+ var isLayoutTarget = runtimeTarget.requiresRuntime === false && ParticleUtil.affectsChildLayout(runtimeTarget.targetName);
1328
+ if (!isLayoutTarget && !runtimeTarget.requiresInitialResolution) {
1329
+ continue;
1330
+ }
1331
+ var resolved = ParticleUtil.resolveValue(runtimeTarget.target, _child);
1332
+ var value = TargetParser.isTargetSpecObject(resolved) ? resolved.value : resolved;
1333
+ var initialValue = Array.isArray(value) ? value[0] : value;
1334
+ if (runtimeTarget.requiresInitialResolution) {
1335
+ runtimeTarget.requiresInitialResolution = false;
1336
+ runtimeTarget.initialResolvedValue = value;
1337
+ }
1338
+ if (tmodel.getChildValue(index, runtimeTarget.targetName) === initialValue) {
1339
+ continue;
1340
+ }
1341
+ if (!tmodel.setChildValue(index, runtimeTarget.targetName, initialValue, false)) {
1342
+ continue;
1343
+ }
1344
+ if (ParticleUtil.affectsChildFlowLayout(runtimeTarget.targetName)) {
1345
+ flowLayoutChanged = true;
1346
+ }
1347
+ changed = true;
1348
+ }
1349
+ } catch (err) {
1350
+ _iterator8.e(err);
1351
+ } finally {
1352
+ _iterator8.f();
1353
+ }
1354
+ }
1355
+ if (flowLayoutChanged) {
1356
+ tmodel.invalidateLayout();
1357
+ }
1358
+ return changed;
1359
+ }
656
1360
  }, {
657
1361
  key: "runRenderTarget",
658
1362
  value: function () {
659
- var _runRenderTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(index, runtimeTarget, targetIndex) {
660
- var sequenceId,
661
- tmodel,
662
- child,
663
- target,
664
- targetName,
665
- execution,
666
- value,
667
- isValueList,
668
- values,
669
- _args6 = arguments;
670
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
671
- while (1) switch (_context6.prev = _context6.next) {
1363
+ var _runRenderTarget = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(index, runtimeTarget, targetIndex, sequenceId, isCancelled) {
1364
+ var tmodel, child, target, targetName, execution, value, isValueList, values;
1365
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1366
+ while (1) switch (_context7.prev = _context7.next) {
672
1367
  case 0:
673
- sequenceId = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : "main";
1368
+ if (!isCancelled()) {
1369
+ _context7.next = 2;
1370
+ break;
1371
+ }
1372
+ return _context7.abrupt("return");
1373
+ case 2:
674
1374
  tmodel = this.tmodel;
675
1375
  child = tmodel.childHandles[index];
676
1376
  target = runtimeTarget.target;
677
1377
  targetName = runtimeTarget.targetName;
678
1378
  execution = this.getExecution(index, sequenceId, targetIndex);
679
- if (!execution) {
1379
+ if (execution) {
1380
+ _context7.next = 15;
1381
+ break;
1382
+ }
1383
+ if (sequenceId === "main" && TUtil.hasProperty(runtimeTarget, "initialResolvedValue")) {
1384
+ value = runtimeTarget.initialResolvedValue;
1385
+ delete runtimeTarget.initialResolvedValue;
1386
+ } else {
680
1387
  value = target.value;
681
1388
  if (typeof value === "function") {
682
1389
  value = value.call(child);
683
1390
  }
684
- isValueList = Array.isArray(value);
685
- values = isValueList ? value : [tmodel.getChildValue(index, targetName), value];
686
- execution = {
687
- sequenceId: sequenceId,
688
- targetIndex: targetIndex,
689
- kind: "render",
690
- targetName: targetName,
691
- values: values,
692
- isValueList: isValueList,
693
- segmentIndex: 0,
694
- segmentReady: false,
695
- step: 0,
696
- waiting: false,
697
- startTime: 0
698
- };
699
- this.setExecution(index, sequenceId, targetIndex, execution);
700
1391
  }
701
- case 7:
1392
+ isValueList = Array.isArray(value);
1393
+ if (!isCancelled()) {
1394
+ _context7.next = 12;
1395
+ break;
1396
+ }
1397
+ return _context7.abrupt("return");
1398
+ case 12:
1399
+ values = isValueList ? value : [tmodel.getChildValue(index, targetName), value];
1400
+ execution = {
1401
+ sequenceId: sequenceId,
1402
+ targetIndex: targetIndex,
1403
+ kind: "render",
1404
+ targetName: targetName,
1405
+ imperativeKey: runtimeTarget.imperativeKey,
1406
+ values: values,
1407
+ isValueList: isValueList,
1408
+ pauseOn: target.pauseOn,
1409
+ segmentIndex: 0,
1410
+ segmentReady: false,
1411
+ step: 0,
1412
+ segmentStartTime: 0,
1413
+ waiting: false,
1414
+ startTime: 0,
1415
+ imperativeTarget: sequenceId.startsWith("imperative:") ? {
1416
+ targetName: runtimeTarget.targetName,
1417
+ imperativeKey: runtimeTarget.imperativeKey,
1418
+ renderable: runtimeTarget.renderable,
1419
+ originalTargetName: runtimeTarget.originalTargetName,
1420
+ originalTargetIsParent: runtimeTarget.originalTargetIsParent,
1421
+ target: _objectSpread({}, runtimeTarget.target)
1422
+ } : undefined
1423
+ };
1424
+ this.setExecution(index, sequenceId, targetIndex, execution);
1425
+ case 15:
702
1426
  if (!(execution.segmentIndex < execution.values.length - 1)) {
703
- _context6.next = 18;
1427
+ _context7.next = 33;
704
1428
  break;
705
1429
  }
1430
+ if (!(isCancelled() || execution.cancelled)) {
1431
+ _context7.next = 18;
1432
+ break;
1433
+ }
1434
+ return _context7.abrupt("return");
1435
+ case 18:
706
1436
  if (!execution.segmentReady) {
707
1437
  this.prepareRenderSegment(execution, runtimeTarget, child);
708
1438
  }
709
- _context6.next = 11;
1439
+ if (!(isCancelled() || execution.cancelled)) {
1440
+ _context7.next = 21;
1441
+ break;
1442
+ }
1443
+ return _context7.abrupt("return");
1444
+ case 21:
1445
+ _context7.next = 23;
710
1446
  return this.animateExecution(index, execution);
711
- case 11:
1447
+ case 23:
1448
+ if (!(isCancelled() || execution.cancelled)) {
1449
+ _context7.next = 25;
1450
+ break;
1451
+ }
1452
+ return _context7.abrupt("return");
1453
+ case 25:
712
1454
  execution.segmentIndex++;
713
1455
  execution.segmentReady = false;
714
1456
  execution.step = 0;
1457
+ execution.segmentStartTime = 0;
715
1458
  execution.waiting = false;
716
1459
  execution.startTime = 0;
717
- _context6.next = 7;
1460
+ _context7.next = 15;
718
1461
  break;
719
- case 18:
1462
+ case 33:
720
1463
  this.clearExecution(index, sequenceId, targetIndex);
721
- case 19:
1464
+ case 34:
722
1465
  case "end":
723
- return _context6.stop();
1466
+ return _context7.stop();
724
1467
  }
725
- }, _callee6, this);
1468
+ }, _callee7, this);
726
1469
  }));
727
- function runRenderTarget(_x13, _x14, _x15) {
1470
+ function runRenderTarget(_x17, _x18, _x19, _x20, _x21) {
728
1471
  return _runRenderTarget.apply(this, arguments);
729
1472
  }
730
1473
  return runRenderTarget;
@@ -737,10 +1480,38 @@ var ParticleRuntime = /*#__PURE__*/function () {
737
1480
  execution.from = execution.values[segmentIndex];
738
1481
  execution.to = execution.values[segmentIndex + 1];
739
1482
  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;
1483
+ execution.interval = Math.max(0, Number(this.resolveOption(target.interval, child, segmentIndex)) || 0);
1484
+ if (execution.steps > 0 && !execution.interval) {
1485
+ execution.interval = 8;
1486
+ }
741
1487
  execution.easingName = this.resolveOption(target.easing, child, segmentIndex);
742
1488
  execution.segmentReady = true;
743
1489
  }
1490
+ }, {
1491
+ key: "isTargetInLoop",
1492
+ value: function isTargetInLoop(runtimeTarget, child) {
1493
+ var loop = runtimeTarget.target.loop;
1494
+ return (typeof loop === "function" ? loop.call(child, runtimeTarget.key) : loop) === true;
1495
+ }
1496
+ }, {
1497
+ key: "getTargetCycles",
1498
+ value: function getTargetCycles(runtimeTarget, child, cycle) {
1499
+ var option = runtimeTarget.target.cycles;
1500
+ var cycles = typeof option === "function" ? option.call(child, cycle) : option;
1501
+ return Math.max(1, Math.floor(Number(cycles) || 1));
1502
+ }
1503
+ }, {
1504
+ key: "completeIfReady",
1505
+ value: function completeIfReady(index) {
1506
+ var state = this.tmodel.childRuntimeStates[index];
1507
+ if (!state || state.done || !state.mainFinished) {
1508
+ return;
1509
+ }
1510
+ if (Object.values(state.loopTargets || {}).some(Boolean) || Object.keys(this.activeTargets[index] || {}).length > 0) {
1511
+ return;
1512
+ }
1513
+ this.complete(index);
1514
+ }
744
1515
  }, {
745
1516
  key: "resolveOption",
746
1517
  value: function resolveOption(value, child) {
@@ -755,62 +1526,171 @@ var ParticleRuntime = /*#__PURE__*/function () {
755
1526
  }
756
1527
  }, {
757
1528
  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();
1529
+ value: function animateExecution(index, execution) {
1530
+ var _this9 = this;
1531
+ if (execution.steps <= 0) {
1532
+ var changed = this.setExecutionValue(index, execution, execution.to);
1533
+ if (changed && execution.kind === "render") {
1534
+ this.tmodel.requestParticleRender();
1535
+ }
1536
+ return Promise.resolve();
1537
+ }
1538
+ return new Promise(function (resolve) {
1539
+ execution.index = index;
1540
+ execution.resolve = resolve;
1541
+ _this9.activeRenderExecutions.add(execution);
1542
+ _this9.requestAnimationFrame();
1543
+ });
1544
+ }
1545
+ }, {
1546
+ key: "setExecutionValue",
1547
+ value: function setExecutionValue(index, execution, value) {
1548
+ if (execution.kind === "render") {
1549
+ return this.tmodel.setChildValue(index, execution.targetName, value, false);
1550
+ }
1551
+ var child = this.tmodel.childHandles[index];
1552
+ if (!child || child.actualValues[execution.targetName] === value) {
1553
+ return false;
1554
+ }
1555
+ child.actualValues[execution.targetName] = value;
1556
+ return true;
1557
+ }
1558
+ }, {
1559
+ key: "requestAnimationFrame",
1560
+ value: function (_requestAnimationFrame) {
1561
+ function requestAnimationFrame() {
1562
+ return _requestAnimationFrame.apply(this, arguments);
1563
+ }
1564
+ requestAnimationFrame.toString = function () {
1565
+ return _requestAnimationFrame.toString();
1566
+ };
1567
+ return requestAnimationFrame;
1568
+ }(function () {
1569
+ var _this10 = this;
1570
+ if (this.disposed || this.visibilityPaused || !this.tmodel.isVisible() || this.animationFrameRequested) {
1571
+ return;
1572
+ }
1573
+ this.animationFrameRequested = true;
1574
+ this.animationFrameId = requestAnimationFrame(function () {
1575
+ _this10.animationFrameId = undefined;
1576
+ _this10.animationFrameRequested = false;
1577
+ if (!_this10.disposed) {
1578
+ _this10.updateRenderExecutions();
1579
+ }
1580
+ });
1581
+ })
1582
+ }, {
1583
+ key: "finishMainProgram",
1584
+ value: function finishMainProgram(index, state) {
1585
+ if (this.disposed || this.tmodel.childRuntimeStates[index] !== state || state.cancelled) {
1586
+ return;
1587
+ }
1588
+ state.started = false;
1589
+ state.mainFinished = true;
1590
+ this.completeIfReady(index);
1591
+ }
1592
+ }, {
1593
+ key: "updateRenderExecutions",
1594
+ value: function updateRenderExecutions() {
1595
+ if (this.disposed) {
1596
+ return;
1597
+ }
1598
+ if (!this.tmodel.isVisible()) {
1599
+ this.pauseForVisibility();
1600
+ return;
1601
+ }
1602
+ this.startQueuedPrograms();
1603
+ this.startQueuedLoops();
1604
+ var now = TUtil.now();
1605
+ var renderChanged = false;
1606
+ var layoutChanged = false;
1607
+ var _iterator9 = _createForOfIteratorHelper(this.activeRenderExecutions),
1608
+ _step9;
1609
+ try {
1610
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1611
+ var execution = _step9.value;
1612
+ var _child2 = this.tmodel.childHandles[execution.index];
1613
+ var paused = typeof execution.pauseOn === "function" ? execution.pauseOn.call(_child2) : execution.pauseOn === true;
1614
+ if (paused) {
1615
+ if (execution.segmentStartTime) {
1616
+ var _execution$pausedAt;
1617
+ (_execution$pausedAt = execution.pausedAt) !== null && _execution$pausedAt !== void 0 ? _execution$pausedAt : execution.pausedAt = now;
1618
+ }
1619
+ continue;
800
1620
  }
801
- }, _callee7, this);
802
- }));
803
- function animateExecution(_x16, _x17) {
804
- return _animateExecution.apply(this, arguments);
1621
+ if (!execution.segmentStartTime) {
1622
+ execution.segmentStartTime = now - execution.step * execution.interval;
1623
+ execution.pausedAt = undefined;
1624
+ } else if (execution.pausedAt !== undefined) {
1625
+ execution.segmentStartTime += now - execution.pausedAt;
1626
+ execution.pausedAt = undefined;
1627
+ }
1628
+ var elapsed = now - execution.segmentStartTime;
1629
+ var step = execution.interval > 0 ? Math.min(Math.floor(elapsed / execution.interval), execution.steps) : execution.steps;
1630
+ if (step <= execution.step) {
1631
+ continue;
1632
+ }
1633
+ var easing = execution.easingName ? Easing.easingFunction(execution.easingName) : undefined;
1634
+ var progress = step / execution.steps;
1635
+ var easedProgress = easing ? easing(progress) : progress;
1636
+ var value = TModelUtil.morph(execution.targetName, execution.from, execution.to, easedProgress);
1637
+ var valueChanged = this.setExecutionValue(execution.index, execution, value);
1638
+ if (execution.kind === "render" && valueChanged && ParticleUtil.affectsChildFlowLayout(execution.targetName)) {
1639
+ layoutChanged = true;
1640
+ }
1641
+ if (execution.kind === "render") {
1642
+ renderChanged || (renderChanged = valueChanged);
1643
+ }
1644
+ execution.step = step;
1645
+ if (step >= execution.steps) {
1646
+ this.activeRenderExecutions.delete(execution);
1647
+ var resolve = execution.resolve;
1648
+ execution.resolve = undefined;
1649
+ resolve();
1650
+ }
1651
+ }
1652
+ } catch (err) {
1653
+ _iterator9.e(err);
1654
+ } finally {
1655
+ _iterator9.f();
805
1656
  }
806
- return animateExecution;
807
- }()
1657
+ if (layoutChanged) {
1658
+ this.tmodel.invalidateLayout();
1659
+ }
1660
+ if (renderChanged) {
1661
+ this.tmodel.requestParticleRender();
1662
+ }
1663
+ if (this.startQueueIndex < this.startQueue.length || this.loopQueue.length || this.activeRenderExecutions.size) {
1664
+ this.requestAnimationFrame();
1665
+ }
1666
+ }
808
1667
  }, {
809
1668
  key: "wait",
810
1669
  value: function wait(interval) {
811
- return new Promise(function (resolve) {
812
- return setTimeout(resolve, Math.max(0, Number(interval) || 0));
813
- });
1670
+ var _this$waitBuckets,
1671
+ _this11 = this;
1672
+ if (this.disposed) {
1673
+ return Promise.resolve();
1674
+ }
1675
+ var delay = Math.max(0, Number(interval) || 0);
1676
+ if (delay === 0) {
1677
+ return Promise.resolve();
1678
+ }
1679
+ var deadline = Math.ceil((TUtil.now() + delay) / 4) * 4;
1680
+ (_this$waitBuckets = this.waitBuckets) !== null && _this$waitBuckets !== void 0 ? _this$waitBuckets : this.waitBuckets = new Map();
1681
+ var bucket = this.waitBuckets.get(deadline);
1682
+ if (!bucket) {
1683
+ bucket = {};
1684
+ bucket.promise = new Promise(function (resolve) {
1685
+ bucket.resolve = resolve;
1686
+ bucket.timeoutId = setTimeout(function () {
1687
+ _this11.waitBuckets.delete(deadline);
1688
+ resolve();
1689
+ }, Math.max(0, deadline - TUtil.now()));
1690
+ });
1691
+ this.waitBuckets.set(deadline, bucket);
1692
+ }
1693
+ return bucket.promise;
814
1694
  }
815
1695
  }, {
816
1696
  key: "findTargetIndex",
@@ -819,54 +1699,198 @@ var ParticleRuntime = /*#__PURE__*/function () {
819
1699
  if (!program) {
820
1700
  return -1;
821
1701
  }
822
- var cleanKey = TargetUtil.getTargetName(key);
1702
+ var cleanKey = ParticleUtil.getTargetName(key);
823
1703
  var exactIndex = program.findIndex(function (target) {
824
- return target.key === key;
1704
+ return target.requiresRuntime !== false && target.key === key;
825
1705
  });
826
1706
  if (exactIndex >= 0) {
827
1707
  return exactIndex;
828
1708
  }
829
1709
  return program.findIndex(function (target) {
830
- return target.targetName === cleanKey && target.mode === "immediate";
1710
+ return target.requiresRuntime !== false && target.targetName === cleanKey && target.mode === "immediate";
831
1711
  });
832
1712
  }
833
1713
  }, {
834
1714
  key: "runActivatedSequence",
835
1715
  value: function () {
836
1716
  var _runActivatedSequence = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(index, startIndex, sequenceId) {
837
- var program;
1717
+ var program, completed;
838
1718
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
839
1719
  while (1) switch (_context8.prev = _context8.next) {
840
1720
  case 0:
1721
+ if (!this.disposed) {
1722
+ _context8.next = 2;
1723
+ break;
1724
+ }
1725
+ return _context8.abrupt("return");
1726
+ case 2:
841
1727
  program = this.tmodel.childRuntimePrograms[index];
842
- if (!(!program || startIndex < 0 || startIndex >= program.length)) {
843
- _context8.next = 3;
1728
+ if (!(this.disposed || !program || startIndex < 0 || startIndex >= program.length)) {
1729
+ _context8.next = 5;
844
1730
  break;
845
1731
  }
846
1732
  return _context8.abrupt("return");
847
- case 3:
848
- _context8.next = 5;
849
- return this.runTarget(index, program[startIndex], startIndex, sequenceId);
850
1733
  case 5:
851
1734
  _context8.next = 7;
852
- return this.continueActivatedSequence(index, startIndex + 1, sequenceId);
1735
+ return this.runTarget(index, program[startIndex], startIndex, sequenceId);
853
1736
  case 7:
1737
+ completed = _context8.sent;
1738
+ if (!(completed && !this.disposed)) {
1739
+ _context8.next = 11;
1740
+ break;
1741
+ }
1742
+ _context8.next = 11;
1743
+ return this.continueActivatedSequence(index, startIndex + 1, sequenceId);
1744
+ case 11:
854
1745
  case "end":
855
1746
  return _context8.stop();
856
1747
  }
857
1748
  }, _callee8, this);
858
1749
  }));
859
- function runActivatedSequence(_x18, _x19, _x20) {
1750
+ function runActivatedSequence(_x22, _x23, _x24) {
860
1751
  return _runActivatedSequence.apply(this, arguments);
861
1752
  }
862
1753
  return runActivatedSequence;
863
1754
  }()
1755
+ }, {
1756
+ key: "setImperativeTarget",
1757
+ value: function setImperativeTarget(index, key, rawTarget, steps, interval, easing, originalTargetName, originalTModel) {
1758
+ var _ref,
1759
+ _ref2,
1760
+ _target$steps,
1761
+ _ref3,
1762
+ _ref4,
1763
+ _target$interval,
1764
+ _ref5,
1765
+ _target$easing,
1766
+ _ref6,
1767
+ _target$cycles,
1768
+ _target$pauseOn,
1769
+ _this12 = this;
1770
+ if (this.disposed) {
1771
+ return;
1772
+ }
1773
+ var child = this.tmodel.childHandles[index];
1774
+ if (!child) {
1775
+ return;
1776
+ }
1777
+ var imperativeKey = key.endsWith("+") ? key : "".concat(key, "+");
1778
+
1779
+ // List targets carry their animation options beside the list, not beside a `value` property.
1780
+ // Unwrap them without calling TargetParser.getValueStepsCycles(), which requires a full TModel.
1781
+ var outerList = TargetParser.isListTarget(rawTarget) ? rawTarget : undefined;
1782
+ var target = outerList ? {
1783
+ value: outerList.list
1784
+ } : TargetParser.isTargetSpecObject(rawTarget) ? _objectSpread({}, rawTarget) : {
1785
+ value: rawTarget
1786
+ };
1787
+ var innerList = TargetParser.isListTarget(target.value) ? target.value : undefined;
1788
+ var listOptions = outerList !== null && outerList !== void 0 ? outerList : innerList;
1789
+ var value = listOptions ? listOptions.list : target.value;
1790
+ var parsedSteps = (_ref = (_ref2 = (_target$steps = target.steps) !== null && _target$steps !== void 0 ? _target$steps : listOptions === null || listOptions === void 0 ? void 0 : listOptions.steps) !== null && _ref2 !== void 0 ? _ref2 : steps) !== null && _ref !== void 0 ? _ref : 0;
1791
+ var parsedInterval = (_ref3 = (_ref4 = (_target$interval = target.interval) !== null && _target$interval !== void 0 ? _target$interval : listOptions === null || listOptions === void 0 ? void 0 : listOptions.interval) !== null && _ref4 !== void 0 ? _ref4 : interval) !== null && _ref3 !== void 0 ? _ref3 : 0;
1792
+ var parsedEasing = (_ref5 = (_target$easing = target.easing) !== null && _target$easing !== void 0 ? _target$easing : listOptions === null || listOptions === void 0 ? void 0 : listOptions.easing) !== null && _ref5 !== void 0 ? _ref5 : easing;
1793
+ var cycles = (_ref6 = (_target$cycles = target.cycles) !== null && _target$cycles !== void 0 ? _target$cycles : listOptions === null || listOptions === void 0 ? void 0 : listOptions.cycles) !== null && _ref6 !== void 0 ? _ref6 : 1;
1794
+ var pauseOn = (_target$pauseOn = target.pauseOn) !== null && _target$pauseOn !== void 0 ? _target$pauseOn : listOptions === null || listOptions === void 0 ? void 0 : listOptions.pauseOn;
1795
+ var targetValue = {
1796
+ isImperative: true,
1797
+ originalTargetName: originalTargetName,
1798
+ originalTModel: originalTModel,
1799
+ status: "updating",
1800
+ value: value,
1801
+ steps: parsedSteps || 0,
1802
+ interval: parsedInterval || 0,
1803
+ easing: parsedEasing,
1804
+ cycles: cycles
1805
+ };
1806
+ child.targetValues[imperativeKey] = targetValue;
1807
+ child.addToUpdatingTargets(imperativeKey);
1808
+ var runtimeTarget = {
1809
+ targetName: ParticleUtil.getTargetName(key),
1810
+ imperativeKey: imperativeKey,
1811
+ renderable: ParticleUtil.isGpuTarget(key),
1812
+ originalTargetName: originalTargetName,
1813
+ originalTargetIsParent: originalTModel === this.tmodel,
1814
+ target: {
1815
+ value: value,
1816
+ steps: parsedSteps,
1817
+ interval: parsedInterval,
1818
+ easing: parsedEasing,
1819
+ cycles: cycles,
1820
+ pauseOn: pauseOn
1821
+ }
1822
+ };
1823
+ var sequenceId = "imperative:".concat(index, ":").concat(imperativeKey, ":").concat(++this.imperativeSequenceCount);
1824
+ var promise = this.runTarget(index, runtimeTarget, 0, sequenceId, targetValue);
1825
+ promise.then(function (completed) {
1826
+ if (_this12.disposed || child.targetValues[imperativeKey] !== targetValue) {
1827
+ return;
1828
+ }
1829
+ targetValue.status = completed ? "done" : "cancelled";
1830
+ child.removeFromUpdatingTargets(imperativeKey);
1831
+ if (completed) {
1832
+ _this12.queueImperativeCompletion(originalTModel, originalTargetName);
1833
+ }
1834
+ });
1835
+ return promise;
1836
+ }
1837
+ }, {
1838
+ key: "queueImperativeCompletion",
1839
+ value: function queueImperativeCompletion(originalTModel, originalTargetName) {
1840
+ var _this13 = this;
1841
+ var pending = this.tmodel.pendingImperativeCompletions;
1842
+ if (originalTModel && originalTargetName) {
1843
+ var targets = pending.get(originalTModel);
1844
+ if (!targets) {
1845
+ targets = new Set();
1846
+ pending.set(originalTModel, targets);
1847
+ }
1848
+ targets.add(originalTargetName);
1849
+ }
1850
+ if (this.imperativeCompletionFrame !== undefined) {
1851
+ return;
1852
+ }
1853
+ this.imperativeCompletionFrame = requestAnimationFrame(function () {
1854
+ _this13.imperativeCompletionFrame = undefined;
1855
+ if (_this13.disposed) {
1856
+ return;
1857
+ }
1858
+ var completions = _this13.tmodel.pendingImperativeCompletions;
1859
+ _this13.tmodel.pendingImperativeCompletions = new Map();
1860
+ var _iterator10 = _createForOfIteratorHelper(completions),
1861
+ _step10;
1862
+ try {
1863
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1864
+ var _step10$value = _slicedToArray(_step10.value, 2),
1865
+ tmodel = _step10$value[0],
1866
+ _targets = _step10$value[1];
1867
+ var _iterator11 = _createForOfIteratorHelper(_targets),
1868
+ _step11;
1869
+ try {
1870
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1871
+ var key = _step11.value;
1872
+ TargetUtil.shouldActivateNextTarget(tmodel, key, 1, 0, true, "complete");
1873
+ }
1874
+ } catch (err) {
1875
+ _iterator11.e(err);
1876
+ } finally {
1877
+ _iterator11.f();
1878
+ }
1879
+ }
1880
+ } catch (err) {
1881
+ _iterator10.e(err);
1882
+ } finally {
1883
+ _iterator10.f();
1884
+ }
1885
+ getRunScheduler().schedule(1, "gpuImperativeComplete-".concat(_this13.tmodel.oid));
1886
+ });
1887
+ }
864
1888
  }, {
865
1889
  key: "activateTarget",
866
1890
  value: function activateTarget(index, key) {
867
1891
  var _this$activeTargets2,
868
1892
  _this$activeTargets2$,
869
- _this4 = this;
1893
+ _this14 = this;
870
1894
  var state = this.tmodel.childRuntimeStates[index];
871
1895
  var program = this.tmodel.childRuntimePrograms[index];
872
1896
  if (!state || !program) {
@@ -877,22 +1901,146 @@ var ParticleRuntime = /*#__PURE__*/function () {
877
1901
  throw new Error("GPU child target \"".concat(key, "\" cannot be activated because it is not in the child runtime program."));
878
1902
  }
879
1903
  var runtimeTarget = program[startIndex];
880
- if (runtimeTarget.kind !== "render" && runtimeTarget.kind !== "runtime") {
1904
+ if (this.isIntervalTarget(runtimeTarget)) {
881
1905
  throw new Error("GPU child target \"".concat(key, "\" cannot be activated."));
882
1906
  }
883
1907
  var activationId = "".concat(runtimeTarget.key, "-").concat(++state.activationCount);
884
1908
  var sequenceId = "activation:".concat(activationId);
885
1909
  var activeTargets = (_this$activeTargets2$ = (_this$activeTargets2 = this.activeTargets)[index]) !== null && _this$activeTargets2$ !== void 0 ? _this$activeTargets2$ : _this$activeTargets2[index] = {};
1910
+ if (state.done) {
1911
+ state.done = false;
1912
+ this.tmodel.pendingGpuChildRuntimeCounts[state.originalTargetName] = (this.tmodel.pendingGpuChildRuntimeCounts[state.originalTargetName] || 0) + 1;
1913
+ }
1914
+ ;
886
1915
  var promise = Promise.resolve().then(function () {
887
- return _this4.runActivatedSequence(index, startIndex, sequenceId);
1916
+ return _this14.runActivatedSequence(index, startIndex, sequenceId);
888
1917
  }).catch(function (error) {
889
1918
  console.error(error);
890
1919
  }).finally(function () {
891
1920
  delete activeTargets[activationId];
1921
+ if (!_this14.disposed) {
1922
+ _this14.completeIfReady(index);
1923
+ TargetUtil.cleanupVisibleComplete(_this14.tmodel, state.originalTargetName);
1924
+ }
892
1925
  });
893
1926
  activeTargets[activationId] = promise;
894
1927
  return true;
895
1928
  }
1929
+ }, {
1930
+ key: "pauseForVisibility",
1931
+ value: function pauseForVisibility() {
1932
+ if (this.disposed || this.visibilityPaused) {
1933
+ return;
1934
+ }
1935
+ this.visibilityPaused = true;
1936
+ var now = TUtil.now();
1937
+ var _iterator12 = _createForOfIteratorHelper(this.activeRenderExecutions),
1938
+ _step12;
1939
+ try {
1940
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1941
+ var execution = _step12.value;
1942
+ if (execution.segmentStartTime) {
1943
+ var _execution$pausedAt2;
1944
+ (_execution$pausedAt2 = execution.pausedAt) !== null && _execution$pausedAt2 !== void 0 ? _execution$pausedAt2 : execution.pausedAt = now;
1945
+ }
1946
+ }
1947
+ } catch (err) {
1948
+ _iterator12.e(err);
1949
+ } finally {
1950
+ _iterator12.f();
1951
+ }
1952
+ if (this.animationFrameId !== undefined) {
1953
+ cancelAnimationFrame(this.animationFrameId);
1954
+ this.animationFrameId = undefined;
1955
+ }
1956
+ this.animationFrameRequested = false;
1957
+ }
1958
+ }, {
1959
+ key: "resumeForVisibility",
1960
+ value: function resumeForVisibility() {
1961
+ if (this.disposed || !this.tmodel.isVisible()) {
1962
+ return;
1963
+ }
1964
+ this.visibilityPaused = false;
1965
+ this.resumeRestored();
1966
+ this.startReady();
1967
+ if (this.startQueueIndex < this.startQueue.length || this.loopQueue.length || this.activeRenderExecutions.size) {
1968
+ this.requestAnimationFrame();
1969
+ }
1970
+ if (this.tmodel.particleValuesDirty || this.tmodel.activeChildTransitionKey) {
1971
+ this.tmodel.requestParticleRender();
1972
+ }
1973
+ }
1974
+ }, {
1975
+ key: "dispose",
1976
+ value: function dispose() {
1977
+ var _this$waitBuckets2, _this$waitBuckets$val, _this$waitBuckets3;
1978
+ if (this.disposed) {
1979
+ return;
1980
+ }
1981
+ this.disposed = true;
1982
+ if (this.animationFrameId !== undefined) {
1983
+ cancelAnimationFrame(this.animationFrameId);
1984
+ this.animationFrameId = undefined;
1985
+ }
1986
+ this.animationFrameRequested = false;
1987
+ this.startQueue.length = 0;
1988
+ this.startQueueIndex = 0;
1989
+ this.loopQueue.length = 0;
1990
+ if (this.imperativeCompletionFrame !== undefined) {
1991
+ cancelAnimationFrame(this.imperativeCompletionFrame);
1992
+ this.imperativeCompletionFrame = undefined;
1993
+ }
1994
+ var _iterator13 = _createForOfIteratorHelper(this.tmodel.childRuntimeStates),
1995
+ _step13;
1996
+ try {
1997
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1998
+ var _state = _step13.value;
1999
+ if (!_state) {
2000
+ continue;
2001
+ }
2002
+ _state.cancelled = true;
2003
+ for (var _i7 = 0, _Object$values = Object.values(_state.executions || {}); _i7 < _Object$values.length; _i7++) {
2004
+ var execution = _Object$values[_i7];
2005
+ execution.cancelled = true;
2006
+ }
2007
+ }
2008
+ } catch (err) {
2009
+ _iterator13.e(err);
2010
+ } finally {
2011
+ _iterator13.f();
2012
+ }
2013
+ var _iterator14 = _createForOfIteratorHelper(this.activeRenderExecutions),
2014
+ _step14;
2015
+ try {
2016
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
2017
+ var _execution2 = _step14.value;
2018
+ _execution2.cancelled = true;
2019
+ var resolve = _execution2.resolve;
2020
+ _execution2.resolve = undefined;
2021
+ resolve === null || resolve === void 0 || resolve();
2022
+ }
2023
+ } catch (err) {
2024
+ _iterator14.e(err);
2025
+ } finally {
2026
+ _iterator14.f();
2027
+ }
2028
+ this.activeRenderExecutions.clear();
2029
+ var _iterator15 = _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 : []),
2030
+ _step15;
2031
+ try {
2032
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2033
+ var bucket = _step15.value;
2034
+ clearTimeout(bucket.timeoutId);
2035
+ bucket.resolve();
2036
+ }
2037
+ } catch (err) {
2038
+ _iterator15.e(err);
2039
+ } finally {
2040
+ _iterator15.f();
2041
+ }
2042
+ (_this$waitBuckets2 = this.waitBuckets) === null || _this$waitBuckets2 === void 0 || _this$waitBuckets2.clear();
2043
+ }
896
2044
  }]);
897
2045
  }();
898
2046
  export { ParticleRuntime };