targetj 1.0.259 → 1.1.0

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