eligius 1.0.5 → 1.0.6

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,63 @@ 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 prepareValueForSerialization(value) {
10
+ if (Array.isArray(value)) {
11
+ return value.map(prepareValueForSerialization);
12
+ } else if (typeof value === 'object') {
13
+ return Object.fromEntries(Object.entries(value).map(function (_ref) {
14
+ var name = _ref[0],
15
+ value = _ref[1];
16
+ return [name, prepareValueForSerialization(value)];
17
+ }));
18
+ } else if (typeof value === 'function') {
19
+ return value.toString();
20
+ }
21
+
22
+ return value;
23
+ }
24
+
25
+ var DevToolEventListener = /*#__PURE__*/function () {
26
+ function DevToolEventListener(agent) {
27
+ this.agent = void 0;
28
+ this.agent = agent;
29
+ }
30
+
31
+ var _proto = DevToolEventListener.prototype;
32
+
33
+ _proto.handleEvent = function handleEvent(eventName, eventTopic, args) {
34
+ this.agent.postMessage('eligius-diagnostics-event', {
35
+ eventName: eventName,
36
+ eventTopic: eventTopic,
37
+ args: prepareValueForSerialization(args)
38
+ });
39
+ };
40
+
41
+ return DevToolEventListener;
42
+ }();
43
+
44
+ var Diagnostics = /*#__PURE__*/function () {
45
+ function Diagnostics() {}
46
+
47
+ Diagnostics.send = function send(_name, _data) {
48
+ console.log(_name, _data);
49
+ };
50
+
51
+ return Diagnostics;
52
+ }();
53
+ Diagnostics.active = void 0;
54
+
55
+ var DEV_TOOLS_KEY = '__ELIGIUS_DEV_TOOLS__';
56
+
57
+ var copyFunction = typeof structuredClone !== 'undefined' ? structuredClone : function (original) {
58
+ return JSON.parse(JSON.stringify(original));
59
+ };
9
60
  function deepCopy(original) {
10
61
  if (isDefined(original)) {
11
- if (typeof structuredClone !== 'undefined') {
12
- return structuredClone(original);
13
- }
14
-
15
- return JSON.parse(JSON.stringify(original));
62
+ return copyFunction(original);
16
63
  }
17
64
 
18
65
  return original;
@@ -36,8 +83,10 @@ var Action = /*#__PURE__*/function () {
36
83
  var _proto = Action.prototype;
37
84
 
38
85
  _proto.start = function start(initOperationData) {
39
- var _this = this;
86
+ var _this$name,
87
+ _this = this;
40
88
 
89
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing start operations");
41
90
  var context = {
42
91
  currentIndex: -1,
43
92
  eventbus: this.eventbus
@@ -45,11 +94,20 @@ var Action = /*#__PURE__*/function () {
45
94
  var result = new Promise(function (resolve, reject) {
46
95
  _this.executeOperation(_this.startOperations, 0, resolve, reject, initOperationData, context);
47
96
  })["catch"](function (e) {
97
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action-error', {
98
+ name: name,
99
+ error: e
100
+ });
48
101
  console.error("Error in action start '" + _this.name + "'");
49
102
  console.error(e);
50
103
  throw e;
51
104
  });
52
- return result;
105
+ return !Diagnostics.active ? result : result.then(function (operationsResult) {
106
+ var _this$name2;
107
+
108
+ Diagnostics.send('eligius-diagnostics-action', ((_this$name2 = _this.name) != null ? _this$name2 : 'Action') + " finished executing start operations");
109
+ return operationsResult;
110
+ });
53
111
  };
54
112
 
55
113
  _proto.executeOperation = function executeOperation(operations, idx, resolve, reject, previousOperationData, context) {
@@ -78,6 +136,11 @@ var Action = /*#__PURE__*/function () {
78
136
  var operationInfo = operations[idx];
79
137
  var copy = operationInfo.operationData ? deepCopy(operationInfo.operationData) : {};
80
138
  var mergedOperationData = Object.assign(previousOperationData, copy);
139
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-operation', {
140
+ systemName: operationInfo.systemName,
141
+ operationData: operationInfo.operationData,
142
+ context: context
143
+ });
81
144
  var operationResult = operationInfo.instance.call(context, mergedOperationData);
82
145
 
83
146
  if (isPromise(operationResult)) {
@@ -525,24 +588,30 @@ var EndableAction = /*#__PURE__*/function (_Action) {
525
588
  var _proto = EndableAction.prototype;
526
589
 
527
590
  _proto.end = function end(initOperationData) {
528
- var _this2 = this;
591
+ var _this$name,
592
+ _this2 = this;
529
593
 
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;
594
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing end operations");
595
+
596
+ if (!this.endOperations.length) {
597
+ return Promise.resolve(initOperationData);
542
598
  }
543
599
 
544
- return new Promise(function (resolve) {
545
- resolve(initOperationData);
600
+ var context = {
601
+ currentIndex: -1,
602
+ eventbus: this.eventbus
603
+ };
604
+ var result = new Promise(function (resolve, reject) {
605
+ _this2.executeOperation(_this2.endOperations, 0, resolve, reject, initOperationData, context);
606
+ })["catch"](function (e) {
607
+ console.error("Error in action end '" + _this2.name + "'");
608
+ throw e;
609
+ });
610
+ return !Diagnostics.active ? result : result.then(function (operationsResult) {
611
+ var _this2$name;
612
+
613
+ Diagnostics.send('eligius-diagnostics-action', ((_this2$name = _this2.name) != null ? _this2$name : 'Action') + " finished executing start operations");
614
+ return operationsResult;
546
615
  });
547
616
  };
548
617
 
@@ -994,6 +1063,7 @@ TimelineEventNames.DURATION = 'timeline-duration';
994
1063
  TimelineEventNames.TIME = 'timeline-time';
995
1064
  TimelineEventNames.SEEKED = 'timeline-seeked';
996
1065
  TimelineEventNames.COMPLETE = 'timeline-complete';
1066
+ TimelineEventNames.RESTART = 'timeline-restart';
997
1067
  TimelineEventNames.PLAY = 'timeline-play';
998
1068
  TimelineEventNames.STOP = 'timeline-stop';
999
1069
  TimelineEventNames.PAUSE = 'timeline-pause';
@@ -1952,34 +2022,6 @@ var ctrls = {
1952
2022
  SubtitlesController: SubtitlesController
1953
2023
  };
1954
2024
 
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
2025
  /**
1984
2026
  * EligiusEngine, this is where the magic happens. The engine is responsible for starting and stopping
1985
2027
  * the given timeline provider and triggering the actions associated with it.
@@ -2829,24 +2871,38 @@ var LanguageManager = /*#__PURE__*/function () {
2829
2871
  }();
2830
2872
 
2831
2873
  var EngineFactory = /*#__PURE__*/function () {
2832
- function EngineFactory(importer, windowRef, eventbus) {
2874
+ function EngineFactory(importer, windowRef, options) {
2875
+ var _options$devtools;
2876
+
2833
2877
  this.resizeTimeout = -1;
2834
2878
  this.actionsLookup = {};
2835
2879
  this.importer = void 0;
2836
2880
  this.eventbus = void 0;
2881
+ this._handleSpaceBound = void 0;
2837
2882
  this.importer = importer;
2838
- this.eventbus = eventbus || new Eventbus();
2883
+ this.eventbus = (options == null ? void 0 : options.eventbus) || new Eventbus();
2884
+ Diagnostics.active = (_options$devtools = options == null ? void 0 : options.devtools) != null ? _options$devtools : false;
2839
2885
 
2840
- this._initializeDevtools(this.eventbus);
2886
+ if (Diagnostics.active) {
2887
+ this._initializeDevtools(this.eventbus);
2888
+ }
2841
2889
 
2842
2890
  this.eventbus.on(TimelineEventNames.REQUEST_INSTANCE, this._requestInstanceHandler.bind(this));
2843
2891
  this.eventbus.on(TimelineEventNames.REQUEST_ACTION, this._requestActionHandler.bind(this));
2844
2892
  this.eventbus.on(TimelineEventNames.REQUEST_FUNCTION, this._requestFunctionHandler.bind(this));
2893
+ this._handleSpaceBound = this._handleSpacePress.bind(this);
2894
+ hotkeys('space', this._handleSpaceBound);
2845
2895
  $(windowRef).resize(this._resizeHandler.bind(this));
2846
2896
  }
2847
2897
 
2848
2898
  var _proto = EngineFactory.prototype;
2849
2899
 
2900
+ _proto._handleSpacePress = function _handleSpacePress(keyboardEvent, _hotkeysEvent) {
2901
+ keyboardEvent.preventDefault();
2902
+ this.eventbus.broadcast(TimelineEventNames.PLAY_TOGGLE_REQUEST);
2903
+ return false;
2904
+ };
2905
+
2850
2906
  _proto._initializeDevtools = function _initializeDevtools(eventbus) {
2851
2907
  var diagnosticInfo = window[DEV_TOOLS_KEY];
2852
2908
 
@@ -2858,11 +2914,16 @@ var EngineFactory = /*#__PURE__*/function () {
2858
2914
  Diagnostics.send = function (name, data) {
2859
2915
  agent.postMessage(name, data);
2860
2916
  };
2917
+
2918
+ Diagnostics.send('eligius-diagnostics-factory', 'Diagnostics initialized');
2919
+ } else {
2920
+ console.warn(DEV_TOOLS_KEY + " property not found on window, please install the extension.");
2861
2921
  }
2862
2922
  };
2863
2923
 
2864
2924
  _proto.destroy = function destroy() {
2865
2925
  this.eventbus.clear();
2926
+ hotkeys.unbind('space', this._handleSpaceBound);
2866
2927
  };
2867
2928
 
2868
2929
  _proto._resizeHandler = function _resizeHandler() {
@@ -2907,8 +2968,7 @@ var EngineFactory = /*#__PURE__*/function () {
2907
2968
  };
2908
2969
 
2909
2970
  _proto.createEngine = function createEngine(configuration, resolver) {
2910
- var _configuration$eventA,
2911
- _this2 = this;
2971
+ var _configuration$eventA;
2912
2972
 
2913
2973
  var systemName = configuration.engine.systemName;
2914
2974
 
@@ -2936,18 +2996,11 @@ var EngineFactory = /*#__PURE__*/function () {
2936
2996
  labels = configuration.labels;
2937
2997
  var languageManager = new LanguageManager(language, labels, this.eventbus);
2938
2998
  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
2999
  return engineInstance;
2947
3000
  };
2948
3001
 
2949
3002
  _proto._createTimelineProviders = function _createTimelineProviders(configuration, eventbus) {
2950
- var _this3 = this;
3003
+ var _this2 = this;
2951
3004
 
2952
3005
  var timelineProviderSettings = configuration.timelineProviderSettings;
2953
3006
  var result = Object.entries(timelineProviderSettings).reduce(function (acc, _ref) {
@@ -2958,7 +3011,7 @@ var EngineFactory = /*#__PURE__*/function () {
2958
3011
  return acc;
2959
3012
  }
2960
3013
 
2961
- var timelineProviderClass = _this3._importSystemEntry(settings.systemName);
3014
+ var timelineProviderClass = _this2._importSystemEntry(settings.systemName);
2962
3015
 
2963
3016
  acc[timelineType] = {
2964
3017
  id: settings.id,
@@ -4455,20 +4508,46 @@ var JwPlayerTimelineProvider = /*#__PURE__*/function () {
4455
4508
  return JwPlayerTimelineProvider;
4456
4509
  }();
4457
4510
 
4511
+ // https://gist.github.com/jakearchibald/cb03f15670817001b1157e62a076fe95
4512
+ function animationInterval(ms, signal, callback) {
4513
+ var _document$timeline$cu, _document, _document$timeline;
4514
+
4515
+ // Prefer currentTime, as it'll better sync animations queued in the
4516
+ // same frame, but if it isn't supported, performance.now() is fine.
4517
+ 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();
4518
+
4519
+ function frame(time) {
4520
+ if (signal.aborted) return;
4521
+ callback(time);
4522
+ scheduleFrame(time);
4523
+ }
4524
+
4525
+ function scheduleFrame(time) {
4526
+ var elapsed = time - start;
4527
+ var roundedElapsed = Math.round(elapsed / ms) * ms;
4528
+ var targetNext = start + roundedElapsed + ms;
4529
+ var delay = targetNext - performance.now();
4530
+ setTimeout(function () {
4531
+ return requestAnimationFrame(frame);
4532
+ }, delay);
4533
+ }
4534
+
4535
+ scheduleFrame(start);
4536
+ }
4537
+
4458
4538
  var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4459
4539
  function RequestAnimationFrameTimelineProvider(eventbus, config) {
4460
4540
  this.eventbus = void 0;
4461
4541
  this.config = void 0;
4462
- this._requestID = -1;
4463
- this._last = 0;
4464
4542
  this._currentPosition = 0;
4465
4543
  this._updateBound = this._update.bind(this);
4466
4544
  this._eventbusListeners = [];
4467
4545
  this._firstFrame = true;
4468
4546
  this._currentPlaylistItem = void 0;
4469
- this._granularity = 1000;
4547
+ this._tickInterval = 1000;
4470
4548
  this._playlist = void 0;
4471
4549
  this._containerElement = void 0;
4550
+ this._abortController = void 0;
4472
4551
  this.playState = 'stopped';
4473
4552
  this.loop = false;
4474
4553
  this.eventbus = eventbus;
@@ -4523,55 +4602,53 @@ var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4523
4602
  this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.DURATION_REQUEST, this.requestDurationHandler.bind(this)));
4524
4603
  };
4525
4604
 
4526
- _proto._update = function _update(now) {
4605
+ _proto._update = function _update(_now) {
4527
4606
  if (this.playState !== 'running') {
4528
4607
  return;
4529
4608
  }
4530
4609
 
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
- }
4610
+ if (this._firstFrame) {
4611
+ this._firstFrame = false;
4612
+ this.eventbus.broadcast(TimelineEventNames.FIRST_FRAME);
4613
+ }
4536
4614
 
4537
- this._last = now;
4538
- this._currentPosition++;
4615
+ this._currentPosition++;
4539
4616
 
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
- }
4617
+ if (this._currentPosition > this._currentPlaylistItem.duration) {
4618
+ if (this.loop) {
4619
+ this._resetToStartPosition();
4549
4620
 
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
- }]);
4621
+ this.eventbus.broadcast(TimelineEventNames.RESTART);
4622
+ } else {
4623
+ this.stop();
4624
+ this.eventbus.broadcast(TimelineEventNames.COMPLETE);
4625
+ return;
4626
+ }
4557
4627
  }
4558
4628
 
4559
- this._requestID = requestAnimationFrame(this._updateBound);
4629
+ this.eventbus.broadcast(TimelineEventNames.TIME, [{
4630
+ position: this._currentPosition
4631
+ }]);
4632
+ this.eventbus.broadcast(TimelineEventNames.POSITION_UPDATE, [{
4633
+ position: this._currentPosition,
4634
+ duration: this._currentPlaylistItem.duration
4635
+ }]);
4560
4636
  };
4561
4637
 
4562
4638
  _proto._start = function _start() {
4563
- if (this._requestID && this.playState === 'running') {
4639
+ var _this$_abortControlle;
4640
+
4641
+ if (this.playState === 'running') {
4564
4642
  return;
4565
4643
  }
4566
4644
 
4567
4645
  this.playState = 'running';
4568
- this._requestID = requestAnimationFrame(this._updateBound);
4646
+ (_this$_abortControlle = this._abortController) == null ? void 0 : _this$_abortControlle.abort();
4647
+ this._abortController = new AbortController();
4648
+ animationInterval(this._tickInterval, this._abortController.signal, this._updateBound);
4569
4649
  };
4570
4650
 
4571
- _proto._reset = function _reset() {
4572
- this._cancelAnimationFrame();
4573
-
4574
- this._last = 0;
4651
+ _proto._resetToStartPosition = function _resetToStartPosition() {
4575
4652
  this._currentPosition = 0;
4576
4653
  };
4577
4654
 
@@ -4583,12 +4660,18 @@ var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4583
4660
  callBack(this._containerElement);
4584
4661
  };
4585
4662
 
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;
4663
+ _proto._stopAnimationInterval = function _stopAnimationInterval(resetPosition) {
4664
+ var _this$_abortControlle2;
4665
+
4666
+ if (resetPosition === void 0) {
4667
+ resetPosition = true;
4668
+ }
4669
+
4670
+ (_this$_abortControlle2 = this._abortController) == null ? void 0 : _this$_abortControlle2.abort();
4671
+ this._abortController = undefined;
4672
+
4673
+ if (resetPosition) {
4674
+ this._resetToStartPosition();
4592
4675
  }
4593
4676
  };
4594
4677
 
@@ -4633,13 +4716,15 @@ var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4633
4716
  };
4634
4717
 
4635
4718
  _proto.stop = function stop() {
4636
- this._cancelAnimationFrame();
4719
+ this._stopAnimationInterval();
4637
4720
 
4638
4721
  this.playState = 'stopped';
4639
4722
  this.eventbus.broadcast(TimelineEventNames.STOP);
4640
4723
  };
4641
4724
 
4642
4725
  _proto.pause = function pause() {
4726
+ this._stopAnimationInterval(false);
4727
+
4643
4728
  this.playState = 'paused';
4644
4729
  this.eventbus.broadcast(TimelineEventNames.PAUSE);
4645
4730
  };