targetj 1.0.237 → 1.0.239

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.
@@ -10,7 +10,7 @@ var _TUtil = require("./TUtil.js");
10
10
  var _TargetUtil = require("./TargetUtil.js");
11
11
  var _TModelUtil = require("./TModelUtil.js");
12
12
  var _SearchUtil = require("./SearchUtil.js");
13
- var _TargetData = require("./TargetData.js");
13
+ var _ScheduleUtil = require("./ScheduleUtil.js");
14
14
  var _AnimationUtil = require("./AnimationUtil.js");
15
15
  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); }
16
16
  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; } } }; }
@@ -56,6 +56,9 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
56
56
  tmodel.removeFromActiveTargets(key);
57
57
  return;
58
58
  }
59
+ if (_ScheduleUtil.ScheduleUtil.shouldPauseTarget(tmodel, key)) {
60
+ return;
61
+ }
59
62
  if (tmodel.isExecuted(key) && tmodel.hasUpdatingImperativeTargets(key)) {
60
63
  return;
61
64
  }
@@ -63,7 +66,7 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
63
66
  if (tmodel.isScheduledPending(key)) {
64
67
  return;
65
68
  }
66
- var schedulePeriod = _TUtil.TUtil.scheduleExecution(tmodel, key);
69
+ var schedulePeriod = _ScheduleUtil.ScheduleUtil.scheduleExecution(tmodel, key);
67
70
  if (schedulePeriod > 0) {
68
71
  (0, _App.getRunScheduler)().schedule(schedulePeriod, "targetSchedule__".concat(tmodel.oid));
69
72
  return;
@@ -95,7 +98,10 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
95
98
  try {
96
99
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
97
100
  var key = _step2.value;
98
- schedulePeriod = _TUtil.TUtil.scheduleExecution(tmodel, key);
101
+ if (_ScheduleUtil.ScheduleUtil.shouldPauseTarget(tmodel, key)) {
102
+ continue;
103
+ }
104
+ schedulePeriod = _ScheduleUtil.ScheduleUtil.scheduleExecution(tmodel, key);
99
105
  if (schedulePeriod > 0) {
100
106
  (0, _App.getRunScheduler)().schedule(schedulePeriod, "setActualValues-".concat(tmodel.oid));
101
107
  } else {
@@ -184,7 +190,7 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
184
190
  originalTModel = this.findOriginalTModel(tmodel, originalTargetName);
185
191
  originalTarget = originalTModel ? originalTModel.targets[originalTargetName] : null;
186
192
  }
187
- var newStatus = this.calculateTargetStatus(tmodel, targetValue, key);
193
+ var newStatus = this.calculateTargetStatus(tmodel, key);
188
194
  tmodel.setTargetStatus(key, newStatus);
189
195
  if (tmodel.isTargetImperative(key)) {
190
196
  var capKey = _TargetUtil.TargetUtil.getTargetName(_TUtil.TUtil.capitalizeFirstLetter(key));
@@ -199,6 +205,7 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
199
205
  tmodel.incrementTargetCycle(key);
200
206
  tmodel.resetTargetStep(key);
201
207
  tmodel.resetTargetInitialValue(key);
208
+ delete targetValue.valuePointer;
202
209
  }
203
210
  } else {
204
211
  var _tmodel$targets$key;
@@ -207,6 +214,7 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
207
214
  tmodel.resetTargetStep(key);
208
215
  tmodel.resetTargetInitialValue(key);
209
216
  tmodel.resetTargetExecutionFlag(key);
217
+ delete targetValue.valuePointer;
210
218
  _TargetExecutor.TargetExecutor.executeDeclarativeTarget(tmodel, key);
211
219
  }
212
220
  if (typeof ((_tmodel$targets$key = tmodel.targets[key]) === null || _tmodel$targets$key === void 0 ? void 0 : _tmodel$targets$key.onStepsEnd) === "function") {
@@ -218,7 +226,11 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
218
226
  }
219
227
  }, {
220
228
  key: "calculateTargetStatus",
221
- value: function calculateTargetStatus(tmodel, targetValue, key) {
229
+ value: function calculateTargetStatus(tmodel, key) {
230
+ var targetValue = tmodel.targetValues[key];
231
+ if (!targetValue) {
232
+ return;
233
+ }
222
234
  var valuePointer = tmodel.getValueListPointer(key);
223
235
  var cycle = tmodel.getTargetCycle(key);
224
236
  var cycles = tmodel.getTargetCycles(key);
@@ -233,166 +245,182 @@ var TargetManager = exports.TargetManager = /*#__PURE__*/function () {
233
245
  }
234
246
  }
235
247
  }, {
236
- key: "handleWebAnimationAPI",
237
- value: function handleWebAnimationAPI(tmodel, cleanKey, key, targetValue, from, to, steps, interval, timeShift) {
238
- var _batch$keyMap;
239
- var skipStartFrame = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : false;
240
- var batch = tmodel.waapiBatch || (tmodel.waapiBatch = {
241
- frames: [],
242
- easing: undefined,
243
- keyMap: {},
244
- totalDuration: 0
245
- });
246
- var isTransform = _TargetData.TargetData.isTransformKey(cleanKey);
247
- var getFrameAtTime = function getFrameAtTime(t) {
248
- var shifted = Math.max(0, t + timeShift);
249
- for (var i = 0; i < batch.frames.length; i++) {
250
- var _frame = batch.frames[i];
251
- if (Math.abs(_frame.keyTime - shifted) < 0.0001) {
252
- return _frame;
253
- }
248
+ key: "catchupTargetByElapsed",
249
+ value: function catchupTargetByElapsed(tmodel, key) {
250
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
251
+ _ref$fireEnd = _ref.fireEnd,
252
+ fireEnd = _ref$fireEnd === void 0 ? false : _ref$fireEnd;
253
+ var targetValue = tmodel.targetValues[key];
254
+ if (!targetValue) {
255
+ return {
256
+ done: false
257
+ };
258
+ }
259
+ var progress = _TUtil.TUtil.advanceTargetByElapsed(tmodel, key);
260
+ var step = progress.step;
261
+ var valuePointer = progress.valuePointer;
262
+ var cycle = progress.cycle;
263
+ var theValue = tmodel.getTargetValue(key);
264
+ var steps = tmodel.getTargetSteps(key);
265
+ var cycles = tmodel.getTargetCycles(key);
266
+ if (progress.done) {
267
+ var _targetValue$valueLis, _targetValue$valueLis2, _targetValue$valueLis3;
268
+ var finalValue = (_targetValue$valueLis = targetValue.valueList) !== null && _targetValue$valueLis !== void 0 && _targetValue$valueLis.length ? targetValue.valueList[targetValue.valueList.length - 1] : theValue;
269
+ tmodel.val(key, finalValue);
270
+ tmodel.setActual(key, finalValue);
271
+ tmodel.addToStyleTargetList(key);
272
+ targetValue.step = steps;
273
+ targetValue.valuePointer = (_targetValue$valueLis2 = (_targetValue$valueLis3 = targetValue.valueList) === null || _targetValue$valueLis3 === void 0 ? void 0 : _targetValue$valueLis3.length) !== null && _targetValue$valueLis2 !== void 0 ? _targetValue$valueLis2 : valuePointer;
274
+ targetValue.value = finalValue;
275
+ targetValue.cycle = cycles;
276
+ delete targetValue.catchupAt;
277
+ if (fireEnd) {
278
+ this.fireOnEnd(tmodel, key);
254
279
  }
255
- var frame = {
256
- keyTime: shifted,
257
- tfMap: {},
258
- styleMap: {},
259
- keyMeta: new Map()
280
+ return {
281
+ done: true,
282
+ step: steps,
283
+ cycle: cycles,
284
+ valuePointer: targetValue.valuePointer
260
285
  };
261
- batch.frames.push(frame);
262
- return frame;
286
+ }
287
+ var initialValue = tmodel.getTargetInitialValue(key);
288
+ if (!_TUtil.TUtil.isDefined(initialValue)) {
289
+ initialValue = this.resolveInitialValue(tmodel, key, theValue);
290
+ tmodel.setTargetInitialValue(key, initialValue);
291
+ }
292
+ var value = step > 0 ? _TModelUtil.TModelUtil.easingMorph(tmodel, key, initialValue, theValue, step, steps) : initialValue;
293
+ tmodel.val(key, value);
294
+ tmodel.setActual(key, value);
295
+ tmodel.addToStyleTargetList(key);
296
+ targetValue.step = step;
297
+ targetValue.valuePointer = valuePointer;
298
+ targetValue.cycle = cycle;
299
+ return {
300
+ done: false,
301
+ step: step,
302
+ cycle: cycle,
303
+ valuePointer: valuePointer
263
304
  };
264
- var keyDuration = 0;
265
- if (targetValue.valueList && targetValue.valueList.length) {
266
- var valueList = targetValue.valueList;
267
- var stepList = targetValue.stepList || [1];
268
- var intervalList = targetValue.intervalList;
269
- var step = targetValue.step;
270
- if (!skipStartFrame) {
271
- var frame = getFrameAtTime(0);
272
- if (isTransform) {
273
- frame.tfMap[cleanKey] = step > 0 && _TUtil.TUtil.isDefined(tmodel.val(key)) ? tmodel.val(key) : valueList[0];
274
- tmodel.val(key, frame.tfMap[cleanKey]);
275
- } else {
276
- frame.styleMap[cleanKey] = valueList[0];
277
- tmodel.val(key, frame.styleMap[cleanKey]);
278
- }
279
- }
280
- for (var i = 1; i < valueList.length; i++) {
281
- var stepValue = stepList[(i - 1) % stepList.length];
282
- var intervalValue = intervalList[(i - 1) % intervalList.length];
283
- var duration = stepValue * intervalValue;
284
- keyDuration += duration;
285
- var _frame2 = getFrameAtTime(keyDuration);
286
- if (isTransform) {
287
- _frame2.tfMap[cleanKey] = valueList[i];
288
- } else {
289
- _frame2.styleMap[cleanKey] = valueList[i];
290
- }
291
- _frame2.keyMeta.set(cleanKey, {
292
- steps: stepValue,
293
- interval: intervalValue
294
- });
295
- }
296
- targetValue.valuePointer = valueList.length;
297
- } else {
298
- interval = interval || 8;
299
- keyDuration = steps * interval;
300
- if (!skipStartFrame) {
301
- var frame0 = getFrameAtTime(0);
302
- if (isTransform) {
303
- frame0.tfMap[cleanKey] = from;
304
- } else {
305
- frame0.styleMap[cleanKey] = from;
306
- }
307
- }
308
- var frame1 = getFrameAtTime(keyDuration);
309
- if (isTransform) {
310
- frame1.tfMap[cleanKey] = to;
311
- } else {
312
- frame1.styleMap[cleanKey] = to;
313
- }
314
- tmodel.val(key, from);
315
- frame1.keyMeta.set(cleanKey, {
316
- steps: steps,
317
- interval: interval
318
- });
319
- }
320
- if (tmodel.getTargetEasing(key)) {
321
- batch.easing = tmodel.getTargetEasing(key);
322
- }
323
- batch.totalDuration = Math.max(0, batch.totalDuration, timeShift + keyDuration);
324
- ((_batch$keyMap = batch.keyMap)[cleanKey] || (_batch$keyMap[cleanKey] = new Set())).add(key);
325
- tmodel.removeFromUpdatingTargets(key);
326
- return keyDuration;
327
305
  }
328
306
  }, {
329
307
  key: "setActualValue",
330
308
  value: function setActualValue(tmodel, key) {
309
+ var _catchup$step, _catchup$valuePointer;
331
310
  var targetValue = tmodel.targetValues[key];
332
311
  if (!targetValue) {
333
312
  return;
334
313
  }
335
- if (!tmodel.isTargetImperative(key) && !tmodel.isTargetEnabled(key)) {
336
- (0, _App.getRunScheduler)().schedule(15, "setActualValue-postpone-".concat(tmodel.oid, "}"));
314
+ if (!this.canUpdateTarget(tmodel, key)) {
337
315
  return;
338
316
  }
339
- var theValue = tmodel.getTargetValue(key);
340
- var cleanKey = _TargetUtil.TargetUtil.getTargetName(key);
341
- var step = tmodel.getTargetStep(key);
342
- var steps = tmodel.getTargetSteps(key);
343
- var cycle = tmodel.getTargetCycle(key);
344
- var valuePointer = tmodel.getValueListPointer(key);
345
- var interval = tmodel.getTargetInterval(key);
346
- var initialValue = tmodel.getTargetInitialValue(key);
347
- var lastUpdateTime = tmodel.getLastUpdate(key);
348
- var now = _TUtil.TUtil.now();
349
- if (!_TUtil.TUtil.isDefined(initialValue)) {
350
- initialValue = _TUtil.TUtil.isDefined(tmodel.val(key)) ? tmodel.val(key) : typeof theValue === 'number' ? 0 : undefined;
351
- tmodel.setTargetInitialValue(key, initialValue);
317
+ var state = this.getTargetUpdateState(tmodel, key);
318
+ if (!_TUtil.TUtil.isDefined(state.initialValue)) {
319
+ state.initialValue = this.resolveInitialValue(tmodel, key, state.theValue);
320
+ tmodel.setTargetInitialValue(key, state.initialValue);
352
321
  }
353
- if (tmodel.canBeAnimated(cleanKey)) {
354
- if (tmodel.hasDom()) {
355
- var cycles = tmodel.isTargetImperative(key) ? tmodel.getTargetCycles(key) : 0;
356
- var cycleDuration = this.handleWebAnimationAPI(tmodel, cleanKey, key, targetValue, initialValue, theValue, steps, interval, 0);
357
- for (var c = 1; c < cycles; c++) {
358
- this.handleWebAnimationAPI(tmodel, cleanKey, key, targetValue, initialValue, theValue, steps, interval, c * cycleDuration, true);
359
- }
360
- }
322
+ var catchup = this.catchupTargetByElapsed(tmodel, key, {
323
+ fireEnd: true
324
+ });
325
+ if (catchup.done) {
326
+ (0, _App.getRunScheduler)().scheduleOnlyIfEarlier(1, "".concat(tmodel.oid, "---").concat(key, "-catchup-finished"));
361
327
  return;
362
328
  }
363
- if (step <= steps) {
364
- tmodel.incrementTargetStep(key, now, lastUpdateTime, interval, steps);
365
- var newValue = _TModelUtil.TModelUtil.easingMorph(tmodel, key, initialValue, theValue, step, steps);
329
+ var step = (_catchup$step = catchup.step) !== null && _catchup$step !== void 0 ? _catchup$step : 0;
330
+ var valuePointer = (_catchup$valuePointer = catchup.valuePointer) !== null && _catchup$valuePointer !== void 0 ? _catchup$valuePointer : tmodel.getValueListPointer(key);
331
+ if (tmodel.canBeAnimated(state.cleanKey)) {
332
+ this.animateActualValue(tmodel, key, targetValue, state, step, valuePointer);
333
+ } else {
334
+ this.updateActualValue(tmodel, key, targetValue, state, step, valuePointer);
335
+ }
336
+ }
337
+ }, {
338
+ key: "canUpdateTarget",
339
+ value: function canUpdateTarget(tmodel, key) {
340
+ if (!tmodel.isTargetImperative(key) && !tmodel.isTargetEnabled(key)) {
341
+ (0, _App.getRunScheduler)().schedule(15, "setActualValue-postpone-".concat(tmodel.oid));
342
+ return false;
343
+ }
344
+ return true;
345
+ }
346
+ }, {
347
+ key: "getTargetUpdateState",
348
+ value: function getTargetUpdateState(tmodel, key) {
349
+ return {
350
+ theValue: tmodel.getTargetValue(key),
351
+ cleanKey: _TargetUtil.TargetUtil.getTargetName(key),
352
+ steps: tmodel.getTargetSteps(key),
353
+ cycle: tmodel.getTargetCycle(key),
354
+ interval: tmodel.getTargetInterval(key),
355
+ initialValue: tmodel.getTargetInitialValue(key),
356
+ lastUpdateTime: tmodel.getLastUpdate(key),
357
+ now: _TUtil.TUtil.now()
358
+ };
359
+ }
360
+ }, {
361
+ key: "resolveInitialValue",
362
+ value: function resolveInitialValue(tmodel, key, theValue) {
363
+ if (_TUtil.TUtil.isDefined(tmodel.val(key))) {
364
+ return tmodel.val(key);
365
+ }
366
+ if (typeof theValue === 'number') {
367
+ return 0;
368
+ }
369
+ return undefined;
370
+ }
371
+ }, {
372
+ key: "animateActualValue",
373
+ value: function animateActualValue(tmodel, key, targetValue, state, step, valuePointer) {
374
+ if (!tmodel.hasDom()) {
375
+ return;
376
+ }
377
+ var newValue = step > 0 ? _TModelUtil.TModelUtil.easingMorph(tmodel, key, state.initialValue, state.theValue, step, state.steps) : state.initialValue;
378
+ var cycles = tmodel.isTargetImperative(key) ? tmodel.getTargetCycles(key) : 0;
379
+ var cycleDuration = _AnimationUtil.AnimationUtil.handleWebAnimationAPI(tmodel, state.cleanKey, key, targetValue, newValue, state.theValue, valuePointer, step, state.steps, state.interval, 0, false, true);
380
+ for (var c = 1; c < cycles; c++) {
381
+ _AnimationUtil.AnimationUtil.handleWebAnimationAPI(tmodel, state.cleanKey, key, targetValue, newValue, state.theValue, valuePointer, step, state.steps, state.interval, c * cycleDuration, true, false);
382
+ }
383
+ }
384
+ }, {
385
+ key: "updateActualValue",
386
+ value: function updateActualValue(tmodel, key, targetValue, state, step, valuePointer) {
387
+ if (step <= state.steps) {
388
+ tmodel.incrementTargetStep(key, state.now, state.lastUpdateTime, state.interval, state.steps);
389
+ var newValue = _TModelUtil.TModelUtil.easingMorph(tmodel, key, state.initialValue, state.theValue, step, state.steps);
366
390
  tmodel.val(key, newValue);
367
391
  tmodel.setActual(key, newValue);
368
392
  tmodel.addToStyleTargetList(key);
369
393
  this.fireOnStep(tmodel, key, step);
370
- if (tmodel.getTargetStep(key) < steps) {
371
- (0, _App.getRunScheduler)().scheduleOnlyIfEarlier(interval, "".concat(tmodel.oid, "---").concat(key, "-").concat(step, "/").concat(steps, "-").concat(cycle, "-").concat(interval));
394
+ if (tmodel.getTargetStep(key) < state.steps) {
395
+ (0, _App.getRunScheduler)().scheduleOnlyIfEarlier(state.interval, "".concat(tmodel.oid, "---").concat(key, "-").concat(step, "/").concat(state.steps, "-").concat(state.cycle, "-").concat(state.interval));
372
396
  return;
373
397
  }
374
398
  }
375
- tmodel.val(key, theValue);
376
- tmodel.setActual(key, theValue);
399
+ this.finishCurrentSegment(tmodel, key, targetValue, state, valuePointer);
400
+ }
401
+ }, {
402
+ key: "finishCurrentSegment",
403
+ value: function finishCurrentSegment(tmodel, key, targetValue, state, valuePointer) {
404
+ tmodel.val(key, state.theValue);
405
+ tmodel.setActual(key, state.theValue);
377
406
  tmodel.addToStyleTargetList(key);
378
- targetValue.step = steps;
407
+ targetValue.step = state.steps;
379
408
  tmodel.setLastUpdate(key);
380
- step = steps;
381
409
  var scheduleTime = 1;
382
410
  if (targetValue.valueList && valuePointer < targetValue.valueList.length) {
383
411
  tmodel.incrementValueListPointer(key);
384
- valuePointer = tmodel.getValueListPointer(key);
412
+ var nextPointer = tmodel.getValueListPointer(key);
385
413
  tmodel.resetTargetStep(key);
386
414
  targetValue.initialValue = targetValue.value;
387
- targetValue.value = targetValue.valueList[valuePointer];
388
- targetValue.steps = targetValue.stepList[(valuePointer - 1) % targetValue.stepList.length];
389
- targetValue.interval = Array.isArray(targetValue.intervalList) ? targetValue.intervalList[(valuePointer - 1) % targetValue.intervalList.length] : 0;
390
- targetValue.easing = targetValue.easingList[(valuePointer - 1) % targetValue.easingList.length];
391
- scheduleTime = interval;
415
+ targetValue.value = targetValue.valueList[nextPointer];
416
+ targetValue.steps = targetValue.stepList[(nextPointer - 1) % targetValue.stepList.length];
417
+ targetValue.interval = Array.isArray(targetValue.intervalList) ? targetValue.intervalList[(nextPointer - 1) % targetValue.intervalList.length] : 0;
418
+ targetValue.easing = targetValue.easingList[(nextPointer - 1) % targetValue.easingList.length];
419
+ scheduleTime = state.interval;
392
420
  } else {
393
421
  this.fireOnEnd(tmodel, key);
394
422
  }
395
- (0, _App.getRunScheduler)().scheduleOnlyIfEarlier(scheduleTime, "".concat(tmodel.oid, "---").concat(key, "-").concat(step, "/").concat(steps, "-").concat(cycle, "-").concat(scheduleTime));
423
+ (0, _App.getRunScheduler)().scheduleOnlyIfEarlier(scheduleTime, "".concat(tmodel.oid, "---").concat(key, "-").concat(state.steps, "/").concat(state.steps, "-").concat(state.cycle, "-").concat(scheduleTime));
396
424
  }
397
425
  }]);
398
426
  }();