eligius 1.0.5 → 1.0.7

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.
@@ -3,16 +3,74 @@ import fs from 'fs';
3
3
  import path from 'path';
4
4
  import lottie from 'lottie-web';
5
5
  import $ from 'jquery';
6
- import Mousetrap from 'mousetrap';
6
+ import hotkeys from 'hotkeys-js';
7
7
  import { v4 } from 'uuid';
8
8
 
9
- function deepCopy(original) {
10
- if (isDefined(original)) {
11
- if (typeof structuredClone !== 'undefined') {
12
- return structuredClone(original);
9
+ function prepareValueForSerialization(value) {
10
+ if (Array.isArray(value)) {
11
+ return value.map(prepareValueForSerialization);
12
+ } else if (value instanceof jQuery) {
13
+ return 'jQuery object';
14
+ } else if (typeof value === 'object') {
15
+ return Object.fromEntries(Object.entries(value).map(function (_ref) {
16
+ var name = _ref[0],
17
+ value = _ref[1];
18
+ return [name, prepareValueForSerialization(value)];
19
+ }));
20
+ } else if (typeof value === 'function') {
21
+ var funcString = value.toString();
22
+ return funcString.substring(0, funcString.indexOf('{') + 1);
23
+ }
24
+
25
+ return value;
26
+ }
27
+
28
+ var DevToolEventListener = /*#__PURE__*/function () {
29
+ function DevToolEventListener(agent) {
30
+ this.agent = void 0;
31
+ this.agent = agent;
32
+ }
33
+
34
+ var _proto = DevToolEventListener.prototype;
35
+
36
+ _proto.handleEvent = function handleEvent(eventName, eventTopic, args) {
37
+ var message = {
38
+ eventName: eventName,
39
+ eventTopic: eventTopic,
40
+ args: prepareValueForSerialization(args)
41
+ };
42
+
43
+ try {
44
+ this.agent.postMessage('eligius-diagnostics-event', message);
45
+ } catch (e) {
46
+ console.error('postmessage failed');
47
+ console.error(e);
48
+ console.log('message', message);
13
49
  }
50
+ };
51
+
52
+ return DevToolEventListener;
53
+ }();
54
+
55
+ var Diagnostics = /*#__PURE__*/function () {
56
+ function Diagnostics() {}
57
+
58
+ Diagnostics.send = function send(_name, _data) {
59
+ console.log(_name, _data);
60
+ };
61
+
62
+ return Diagnostics;
63
+ }();
64
+ Diagnostics.active = void 0;
14
65
 
15
- return JSON.parse(JSON.stringify(original));
66
+ var DEV_TOOLS_KEY = '__ELIGIUS_DEV_TOOLS__';
67
+
68
+ var copyFunction = typeof structuredClone !== 'undefined' ? structuredClone : function (original) {
69
+ return JSON.parse(JSON.stringify(original));
70
+ };
71
+ function deepCopy(original) {
72
+ if (isDefined(original)) {
73
+ return copyFunction(original);
16
74
  }
17
75
 
18
76
  return original;
@@ -36,8 +94,10 @@ var Action = /*#__PURE__*/function () {
36
94
  var _proto = Action.prototype;
37
95
 
38
96
  _proto.start = function start(initOperationData) {
39
- var _this = this;
97
+ var _this$name,
98
+ _this = this;
40
99
 
100
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing start operations");
41
101
  var context = {
42
102
  currentIndex: -1,
43
103
  eventbus: this.eventbus
@@ -45,11 +105,20 @@ var Action = /*#__PURE__*/function () {
45
105
  var result = new Promise(function (resolve, reject) {
46
106
  _this.executeOperation(_this.startOperations, 0, resolve, reject, initOperationData, context);
47
107
  })["catch"](function (e) {
108
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action-error', {
109
+ name: name,
110
+ error: e
111
+ });
48
112
  console.error("Error in action start '" + _this.name + "'");
49
113
  console.error(e);
50
114
  throw e;
51
115
  });
52
- return result;
116
+ return !Diagnostics.active ? result : result.then(function (operationsResult) {
117
+ var _this$name2;
118
+
119
+ Diagnostics.send('eligius-diagnostics-action', ((_this$name2 = _this.name) != null ? _this$name2 : 'Action') + " finished executing start operations");
120
+ return operationsResult;
121
+ });
53
122
  };
54
123
 
55
124
  _proto.executeOperation = function executeOperation(operations, idx, resolve, reject, previousOperationData, context) {
@@ -78,6 +147,11 @@ var Action = /*#__PURE__*/function () {
78
147
  var operationInfo = operations[idx];
79
148
  var copy = operationInfo.operationData ? deepCopy(operationInfo.operationData) : {};
80
149
  var mergedOperationData = Object.assign(previousOperationData, copy);
150
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-operation', {
151
+ systemName: operationInfo.systemName,
152
+ operationData: operationInfo.operationData,
153
+ context: context
154
+ });
81
155
  var operationResult = operationInfo.instance.call(context, mergedOperationData);
82
156
 
83
157
  if (isPromise(operationResult)) {
@@ -525,24 +599,30 @@ var EndableAction = /*#__PURE__*/function (_Action) {
525
599
  var _proto = EndableAction.prototype;
526
600
 
527
601
  _proto.end = function end(initOperationData) {
528
- var _this2 = this;
602
+ var _this$name,
603
+ _this2 = this;
529
604
 
530
- if (this.endOperations.length) {
531
- var context = {
532
- currentIndex: -1,
533
- eventbus: this.eventbus
534
- };
535
- var result = new Promise(function (resolve, reject) {
536
- _this2.executeOperation(_this2.endOperations, 0, resolve, reject, initOperationData, context);
537
- })["catch"](function (e) {
538
- console.error("Error in action end '" + _this2.name + "'");
539
- throw e;
540
- });
541
- return result;
605
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing end operations");
606
+
607
+ if (!this.endOperations.length) {
608
+ return Promise.resolve(initOperationData);
542
609
  }
543
610
 
544
- return new Promise(function (resolve) {
545
- resolve(initOperationData);
611
+ var context = {
612
+ currentIndex: -1,
613
+ eventbus: this.eventbus
614
+ };
615
+ var result = new Promise(function (resolve, reject) {
616
+ _this2.executeOperation(_this2.endOperations, 0, resolve, reject, initOperationData, context);
617
+ })["catch"](function (e) {
618
+ console.error("Error in action end '" + _this2.name + "'");
619
+ throw e;
620
+ });
621
+ return !Diagnostics.active ? result : result.then(function (operationsResult) {
622
+ var _this2$name;
623
+
624
+ Diagnostics.send('eligius-diagnostics-action', ((_this2$name = _this2.name) != null ? _this2$name : 'Action') + " finished executing start operations");
625
+ return operationsResult;
546
626
  });
547
627
  };
548
628
 
@@ -994,6 +1074,7 @@ TimelineEventNames.DURATION = 'timeline-duration';
994
1074
  TimelineEventNames.TIME = 'timeline-time';
995
1075
  TimelineEventNames.SEEKED = 'timeline-seeked';
996
1076
  TimelineEventNames.COMPLETE = 'timeline-complete';
1077
+ TimelineEventNames.RESTART = 'timeline-restart';
997
1078
  TimelineEventNames.PLAY = 'timeline-play';
998
1079
  TimelineEventNames.STOP = 'timeline-stop';
999
1080
  TimelineEventNames.PAUSE = 'timeline-pause';
@@ -1952,34 +2033,6 @@ var ctrls = {
1952
2033
  SubtitlesController: SubtitlesController
1953
2034
  };
1954
2035
 
1955
- var DevToolEventListener = /*#__PURE__*/function () {
1956
- function DevToolEventListener(agent) {
1957
- this.agent = void 0;
1958
- this.agent = agent;
1959
- }
1960
-
1961
- var _proto = DevToolEventListener.prototype;
1962
-
1963
- _proto.handleEvent = function handleEvent(eventName, eventTopic, args) {
1964
- this.agent.postMessage('eligius-diagnostics-event', {
1965
- eventName: eventName,
1966
- eventTopic: eventTopic
1967
- });
1968
- };
1969
-
1970
- return DevToolEventListener;
1971
- }();
1972
-
1973
- var Diagnostics = /*#__PURE__*/function () {
1974
- function Diagnostics() {}
1975
-
1976
- Diagnostics.send = function send(_name, _data) {};
1977
-
1978
- return Diagnostics;
1979
- }();
1980
-
1981
- var DEV_TOOLS_KEY = '__ELIGIUS_DEV_TOOLS__';
1982
-
1983
2036
  /**
1984
2037
  * EligiusEngine, this is where the magic happens. The engine is responsible for starting and stopping
1985
2038
  * the given timeline provider and triggering the actions associated with it.
@@ -2829,24 +2882,38 @@ var LanguageManager = /*#__PURE__*/function () {
2829
2882
  }();
2830
2883
 
2831
2884
  var EngineFactory = /*#__PURE__*/function () {
2832
- function EngineFactory(importer, windowRef, eventbus) {
2885
+ function EngineFactory(importer, windowRef, options) {
2886
+ var _options$devtools;
2887
+
2833
2888
  this.resizeTimeout = -1;
2834
2889
  this.actionsLookup = {};
2835
2890
  this.importer = void 0;
2836
2891
  this.eventbus = void 0;
2892
+ this._handleSpaceBound = void 0;
2837
2893
  this.importer = importer;
2838
- this.eventbus = eventbus || new Eventbus();
2894
+ this.eventbus = (options == null ? void 0 : options.eventbus) || new Eventbus();
2895
+ Diagnostics.active = (_options$devtools = options == null ? void 0 : options.devtools) != null ? _options$devtools : false;
2839
2896
 
2840
- this._initializeDevtools(this.eventbus);
2897
+ if (Diagnostics.active) {
2898
+ this._initializeDevtools(this.eventbus);
2899
+ }
2841
2900
 
2842
2901
  this.eventbus.on(TimelineEventNames.REQUEST_INSTANCE, this._requestInstanceHandler.bind(this));
2843
2902
  this.eventbus.on(TimelineEventNames.REQUEST_ACTION, this._requestActionHandler.bind(this));
2844
2903
  this.eventbus.on(TimelineEventNames.REQUEST_FUNCTION, this._requestFunctionHandler.bind(this));
2904
+ this._handleSpaceBound = this._handleSpacePress.bind(this);
2905
+ hotkeys('space', this._handleSpaceBound);
2845
2906
  $(windowRef).resize(this._resizeHandler.bind(this));
2846
2907
  }
2847
2908
 
2848
2909
  var _proto = EngineFactory.prototype;
2849
2910
 
2911
+ _proto._handleSpacePress = function _handleSpacePress(keyboardEvent, _hotkeysEvent) {
2912
+ keyboardEvent.preventDefault();
2913
+ this.eventbus.broadcast(TimelineEventNames.PLAY_TOGGLE_REQUEST);
2914
+ return false;
2915
+ };
2916
+
2850
2917
  _proto._initializeDevtools = function _initializeDevtools(eventbus) {
2851
2918
  var diagnosticInfo = window[DEV_TOOLS_KEY];
2852
2919
 
@@ -2856,13 +2923,26 @@ var EngineFactory = /*#__PURE__*/function () {
2856
2923
  eventbus.registerEventlistener(eventbusListener);
2857
2924
 
2858
2925
  Diagnostics.send = function (name, data) {
2859
- agent.postMessage(name, data);
2926
+ var message = prepareValueForSerialization(data);
2927
+
2928
+ try {
2929
+ agent.postMessage(name, message);
2930
+ } catch (e) {
2931
+ console.error('postmessage failed');
2932
+ console.error(e);
2933
+ console.log('message', message);
2934
+ }
2860
2935
  };
2936
+
2937
+ Diagnostics.send('eligius-diagnostics-factory', 'Diagnostics initialized');
2938
+ } else {
2939
+ console.warn(DEV_TOOLS_KEY + " property not found on window, please install the extension.");
2861
2940
  }
2862
2941
  };
2863
2942
 
2864
2943
  _proto.destroy = function destroy() {
2865
2944
  this.eventbus.clear();
2945
+ hotkeys.unbind('space', this._handleSpaceBound);
2866
2946
  };
2867
2947
 
2868
2948
  _proto._resizeHandler = function _resizeHandler() {
@@ -2907,8 +2987,7 @@ var EngineFactory = /*#__PURE__*/function () {
2907
2987
  };
2908
2988
 
2909
2989
  _proto.createEngine = function createEngine(configuration, resolver) {
2910
- var _configuration$eventA,
2911
- _this2 = this;
2990
+ var _configuration$eventA;
2912
2991
 
2913
2992
  var systemName = configuration.engine.systemName;
2914
2993
 
@@ -2936,18 +3015,11 @@ var EngineFactory = /*#__PURE__*/function () {
2936
3015
  labels = configuration.labels;
2937
3016
  var languageManager = new LanguageManager(language, labels, this.eventbus);
2938
3017
  var engineInstance = new EngineClass(resolvedConfiguration, this.eventbus, timelineProviders, languageManager);
2939
- Mousetrap.bind('space', function (event) {
2940
- event.preventDefault();
2941
-
2942
- _this2.eventbus.broadcast(TimelineEventNames.PLAY_TOGGLE_REQUEST);
2943
-
2944
- return false;
2945
- });
2946
3018
  return engineInstance;
2947
3019
  };
2948
3020
 
2949
3021
  _proto._createTimelineProviders = function _createTimelineProviders(configuration, eventbus) {
2950
- var _this3 = this;
3022
+ var _this2 = this;
2951
3023
 
2952
3024
  var timelineProviderSettings = configuration.timelineProviderSettings;
2953
3025
  var result = Object.entries(timelineProviderSettings).reduce(function (acc, _ref) {
@@ -2958,7 +3030,7 @@ var EngineFactory = /*#__PURE__*/function () {
2958
3030
  return acc;
2959
3031
  }
2960
3032
 
2961
- var timelineProviderClass = _this3._importSystemEntry(settings.systemName);
3033
+ var timelineProviderClass = _this2._importSystemEntry(settings.systemName);
2962
3034
 
2963
3035
  acc[timelineType] = {
2964
3036
  id: settings.id,
@@ -4455,20 +4527,46 @@ var JwPlayerTimelineProvider = /*#__PURE__*/function () {
4455
4527
  return JwPlayerTimelineProvider;
4456
4528
  }();
4457
4529
 
4530
+ // https://gist.github.com/jakearchibald/cb03f15670817001b1157e62a076fe95
4531
+ function animationInterval(ms, signal, callback) {
4532
+ var _document$timeline$cu, _document, _document$timeline;
4533
+
4534
+ // Prefer currentTime, as it'll better sync animations queued in the
4535
+ // same frame, but if it isn't supported, performance.now() is fine.
4536
+ var start = (_document$timeline$cu = (_document = document) == null ? void 0 : (_document$timeline = _document.timeline) == null ? void 0 : _document$timeline.currentTime) != null ? _document$timeline$cu : performance.now();
4537
+
4538
+ function frame(time) {
4539
+ if (signal.aborted) return;
4540
+ callback(time);
4541
+ scheduleFrame(time);
4542
+ }
4543
+
4544
+ function scheduleFrame(time) {
4545
+ var elapsed = time - start;
4546
+ var roundedElapsed = Math.round(elapsed / ms) * ms;
4547
+ var targetNext = start + roundedElapsed + ms;
4548
+ var delay = targetNext - performance.now();
4549
+ setTimeout(function () {
4550
+ return requestAnimationFrame(frame);
4551
+ }, delay);
4552
+ }
4553
+
4554
+ scheduleFrame(start);
4555
+ }
4556
+
4458
4557
  var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4459
4558
  function RequestAnimationFrameTimelineProvider(eventbus, config) {
4460
4559
  this.eventbus = void 0;
4461
4560
  this.config = void 0;
4462
- this._requestID = -1;
4463
- this._last = 0;
4464
4561
  this._currentPosition = 0;
4465
4562
  this._updateBound = this._update.bind(this);
4466
4563
  this._eventbusListeners = [];
4467
4564
  this._firstFrame = true;
4468
4565
  this._currentPlaylistItem = void 0;
4469
- this._granularity = 1000;
4566
+ this._tickInterval = 1000;
4470
4567
  this._playlist = void 0;
4471
4568
  this._containerElement = void 0;
4569
+ this._abortController = void 0;
4472
4570
  this.playState = 'stopped';
4473
4571
  this.loop = false;
4474
4572
  this.eventbus = eventbus;
@@ -4523,55 +4621,53 @@ var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4523
4621
  this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.DURATION_REQUEST, this.requestDurationHandler.bind(this)));
4524
4622
  };
4525
4623
 
4526
- _proto._update = function _update(now) {
4624
+ _proto._update = function _update(_now) {
4527
4625
  if (this.playState !== 'running') {
4528
4626
  return;
4529
4627
  }
4530
4628
 
4531
- if (!this._last || now - this._last >= this._granularity) {
4532
- if (!this._last && this._firstFrame) {
4533
- this._firstFrame = false;
4534
- this.eventbus.broadcast(TimelineEventNames.FIRST_FRAME);
4535
- }
4629
+ if (this._firstFrame) {
4630
+ this._firstFrame = false;
4631
+ this.eventbus.broadcast(TimelineEventNames.FIRST_FRAME);
4632
+ }
4536
4633
 
4537
- this._last = now;
4538
- this._currentPosition++;
4634
+ this._currentPosition++;
4539
4635
 
4540
- if (this._currentPosition > this._currentPlaylistItem.duration) {
4541
- if (this.loop) {
4542
- this._reset();
4543
- } else {
4544
- this.stop();
4545
- this.eventbus.broadcast(TimelineEventNames.COMPLETE);
4546
- return;
4547
- }
4548
- }
4636
+ if (this._currentPosition > this._currentPlaylistItem.duration) {
4637
+ if (this.loop) {
4638
+ this._resetToStartPosition();
4549
4639
 
4550
- this.eventbus.broadcast(TimelineEventNames.TIME, [{
4551
- position: this._currentPosition
4552
- }]);
4553
- this.eventbus.broadcast(TimelineEventNames.POSITION_UPDATE, [{
4554
- position: this._currentPosition,
4555
- duration: this._currentPlaylistItem.duration
4556
- }]);
4640
+ this.eventbus.broadcast(TimelineEventNames.RESTART);
4641
+ } else {
4642
+ this.stop();
4643
+ this.eventbus.broadcast(TimelineEventNames.COMPLETE);
4644
+ return;
4645
+ }
4557
4646
  }
4558
4647
 
4559
- this._requestID = requestAnimationFrame(this._updateBound);
4648
+ this.eventbus.broadcast(TimelineEventNames.TIME, [{
4649
+ position: this._currentPosition
4650
+ }]);
4651
+ this.eventbus.broadcast(TimelineEventNames.POSITION_UPDATE, [{
4652
+ position: this._currentPosition,
4653
+ duration: this._currentPlaylistItem.duration
4654
+ }]);
4560
4655
  };
4561
4656
 
4562
4657
  _proto._start = function _start() {
4563
- if (this._requestID && this.playState === 'running') {
4658
+ var _this$_abortControlle;
4659
+
4660
+ if (this.playState === 'running') {
4564
4661
  return;
4565
4662
  }
4566
4663
 
4567
4664
  this.playState = 'running';
4568
- this._requestID = requestAnimationFrame(this._updateBound);
4665
+ (_this$_abortControlle = this._abortController) == null ? void 0 : _this$_abortControlle.abort();
4666
+ this._abortController = new AbortController();
4667
+ animationInterval(this._tickInterval, this._abortController.signal, this._updateBound);
4569
4668
  };
4570
4669
 
4571
- _proto._reset = function _reset() {
4572
- this._cancelAnimationFrame();
4573
-
4574
- this._last = 0;
4670
+ _proto._resetToStartPosition = function _resetToStartPosition() {
4575
4671
  this._currentPosition = 0;
4576
4672
  };
4577
4673
 
@@ -4583,12 +4679,18 @@ var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4583
4679
  callBack(this._containerElement);
4584
4680
  };
4585
4681
 
4586
- _proto._cancelAnimationFrame = function _cancelAnimationFrame() {
4587
- if (this._requestID) {
4588
- cancelAnimationFrame(this._requestID);
4589
- this._requestID = -1;
4590
- this._last = 0;
4591
- this._currentPosition = 0;
4682
+ _proto._stopAnimationInterval = function _stopAnimationInterval(resetPosition) {
4683
+ var _this$_abortControlle2;
4684
+
4685
+ if (resetPosition === void 0) {
4686
+ resetPosition = true;
4687
+ }
4688
+
4689
+ (_this$_abortControlle2 = this._abortController) == null ? void 0 : _this$_abortControlle2.abort();
4690
+ this._abortController = undefined;
4691
+
4692
+ if (resetPosition) {
4693
+ this._resetToStartPosition();
4592
4694
  }
4593
4695
  };
4594
4696
 
@@ -4633,13 +4735,15 @@ var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4633
4735
  };
4634
4736
 
4635
4737
  _proto.stop = function stop() {
4636
- this._cancelAnimationFrame();
4738
+ this._stopAnimationInterval();
4637
4739
 
4638
4740
  this.playState = 'stopped';
4639
4741
  this.eventbus.broadcast(TimelineEventNames.STOP);
4640
4742
  };
4641
4743
 
4642
4744
  _proto.pause = function pause() {
4745
+ this._stopAnimationInterval(false);
4746
+
4643
4747
  this.playState = 'paused';
4644
4748
  this.eventbus.broadcast(TimelineEventNames.PAUSE);
4645
4749
  };