eligius 1.5.3 → 2.0.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.
package/dist/index.mjs CHANGED
@@ -1,90 +1,11 @@
1
1
  import { t as __export } from "./chunk-C6wwvPpM.mjs";
2
- import $ from "jquery";
3
2
  import { isDefined } from "ts-is-present";
3
+ import hk from "hotkeys-js";
4
+ import $ from "jquery";
4
5
  import { v4 } from "uuid";
5
- import vjs from "video.js";
6
6
  import lt from "lottie-web";
7
- import hk from "hotkeys-js";
8
-
9
- //#region src/util/guards/is-function.ts
10
- function isFunction(value) {
11
- return typeof value === "function";
12
- }
13
-
14
- //#endregion
15
- //#region src/util/guards/is-object.ts
16
- function isObject(value) {
17
- return !!value && typeof value === "object" && !Array.isArray(value);
18
- }
19
-
20
- //#endregion
21
- //#region src/util/prepare-value-for-serialization.ts
22
- function prepareValueForSerialization(value) {
23
- if (Array.isArray(value)) return value.map(prepareValueForSerialization);
24
- else if (value instanceof $) return "[jQuery object]";
25
- else if (isObject(value)) {
26
- if (value.constructor.toString().substring(0, 5) === "class" || !value.constructor.toString().startsWith("function Object()")) {
27
- const funcString = value.constructor.toString();
28
- return funcString.substring(0, funcString.indexOf("{") + 1);
29
- }
30
- return Object.fromEntries(Object.entries(value).map(([propName, propValue]) => [propName, prepareValueForSerialization(propValue)]));
31
- } else if (isFunction(value)) {
32
- const funcString = value.toString();
33
- if (funcString.indexOf("{") > -1) return funcString.substring(0, funcString.indexOf("{") + 1);
34
- return funcString;
35
- }
36
- return value;
37
- }
38
-
39
- //#endregion
40
- //#region src/diagnostics/devtool-event-listener.ts
41
- var DevToolEventListener = class {
42
- constructor(agent) {
43
- this.agent = agent;
44
- }
45
- handleEvent(eventName, eventTopic, args) {
46
- const message = {
47
- eventName,
48
- eventTopic,
49
- args: prepareValueForSerialization(args)
50
- };
51
- try {
52
- this.agent.postMessage("eligius-diagnostics-event", message);
53
- } catch (e) {
54
- console.error("postmessage failed");
55
- console.error(e);
56
- console.info("message", message);
57
- }
58
- }
59
- };
60
-
61
- //#endregion
62
- //#region src/diagnostics/diagnostics.ts
63
- let active;
64
- function send(_name, _data) {
65
- console.log(_name, _data);
66
- }
67
- function setActive(value) {
68
- active = value;
69
- }
70
- function isActive() {
71
- return active;
72
- }
73
- const Diagnostics = {
74
- send,
75
- get active() {
76
- return active;
77
- },
78
- set active(value) {
79
- active = value;
80
- }
81
- };
82
-
83
- //#endregion
84
- //#region src/diagnostics/types.ts
85
- const DEV_TOOLS_KEY = "__ELIGIUS_DEV_TOOLS__";
7
+ import vjs from "video.js";
86
8
 
87
- //#endregion
88
9
  //#region src/operation/helper/find-matching-operation-index.ts
89
10
  /**
90
11
  * This function can be used to find the index of a matching closing operation within a list of operations.
@@ -392,23 +313,14 @@ var Action = class {
392
313
  this.eventbus = eventbus$1;
393
314
  }
394
315
  start(initOperationData) {
395
- Diagnostics.active && Diagnostics.send("eligius-diagnostics-action", `${this.name ?? "Action"} begins executing start operations`);
396
316
  this._initializeScopeStack();
397
- const result = new Promise((resolve, reject) => {
317
+ return new Promise((resolve, reject) => {
398
318
  this.executeOperation(this.startOperations, 0, resolve, reject, initOperationData);
399
319
  }).catch((e) => {
400
- Diagnostics.active && Diagnostics.send("eligius-diagnostics-action-error", {
401
- name: this.name,
402
- error: e
403
- });
404
320
  console.error(`Error in action start '${this.name}'`);
405
321
  console.error(e);
406
322
  throw e;
407
323
  });
408
- return !Diagnostics.active ? result : result.then((operationsResult) => {
409
- Diagnostics.send("eligius-diagnostics-action", `${this.name ?? "Action"} finished executing start operations`);
410
- return operationsResult;
411
- });
412
324
  }
413
325
  _initializeScopeStack() {
414
326
  this._scopeStack = [{
@@ -455,14 +367,6 @@ var Action = class {
455
367
  scope = this._pushScope(scope);
456
368
  scope.owner = operationInfo;
457
369
  }
458
- Diagnostics.active && Diagnostics.send("eligius-diagnostics-operation", {
459
- systemName: operationInfo.systemName,
460
- operationData: mergedOperationData,
461
- scope: {
462
- ...scope,
463
- eventbus: void 0
464
- }
465
- });
466
370
  const operationResult = operationInfo.instance.call(scope, mergedOperationData);
467
371
  if (operationInfo.systemName === endWhenSystemName || operationInfo.systemName === endForEachSystemName && scope.newIndex === void 0) this._popScope();
468
372
  if (isPromise(operationResult)) operationResult.then((promisedOperationResult) => this.executeOperation(operations$1, ++operationIndex, resolve, reject, promisedOperationResult)).catch((error) => {
@@ -481,23 +385,14 @@ var EndableAction = class extends Action {
481
385
  this.endOperations = endOperations;
482
386
  }
483
387
  end(initOperationData) {
484
- Diagnostics.active && Diagnostics.send("eligius-diagnostics-action", `${this.name ?? "Action"} begins executing end operations`);
485
388
  if (!this.endOperations.length) return Promise.resolve(initOperationData ?? {});
486
389
  this._initializeScopeStack();
487
- const result = new Promise((resolve, reject) => {
390
+ return new Promise((resolve, reject) => {
488
391
  this.executeOperation(this.endOperations, 0, resolve, reject, initOperationData);
489
392
  }).catch((e) => {
490
- Diagnostics.active && Diagnostics.send("eligius-diagnostics-action-error", {
491
- name: this.name,
492
- error: e
493
- });
494
393
  console.error(`Error in action end '${this.name}'`);
495
394
  throw e;
496
395
  });
497
- return !Diagnostics.active ? result : result.then((operationsResult) => {
498
- Diagnostics.send("eligius-diagnostics-action", `${this.name ?? "Action"} finished executing start operations`);
499
- return operationsResult;
500
- });
501
396
  }
502
397
  };
503
398
 
@@ -527,6 +422,273 @@ var TimelineAction = class extends EndableAction {
527
422
  }
528
423
  };
529
424
 
425
+ //#endregion
426
+ //#region src/adapters/engine-eventbus-adapter.ts
427
+ /**
428
+ * Bridges EligiusEngine to/from the eventbus.
429
+ *
430
+ * This adapter:
431
+ * - Forwards engine events to eventbus broadcasts
432
+ * - Forwards eventbus commands to engine methods
433
+ * - Handles eventbus state queries by reading engine properties
434
+ */
435
+ var EngineEventbusAdapter = class {
436
+ _engineEventRemovers = [];
437
+ _eventbusRemovers = [];
438
+ constructor(_engine, _eventbus) {
439
+ this._engine = _engine;
440
+ this._eventbus = _eventbus;
441
+ }
442
+ /**
443
+ * Connect adapter - start listening and forwarding
444
+ */
445
+ connect() {
446
+ this._subscribeToEngineEvents();
447
+ this._subscribeToEventbusEvents();
448
+ }
449
+ /**
450
+ * Disconnect adapter - stop all listeners
451
+ */
452
+ disconnect() {
453
+ this._engineEventRemovers.forEach((remove) => remove());
454
+ this._engineEventRemovers = [];
455
+ this._eventbusRemovers.forEach((remove) => remove());
456
+ this._eventbusRemovers = [];
457
+ }
458
+ _subscribeToEngineEvents() {
459
+ this._onEngineEvent("start", () => {
460
+ this._eventbus.broadcast("timeline-play", []);
461
+ });
462
+ this._onEngineEvent("pause", () => {
463
+ this._eventbus.broadcast("timeline-pause", []);
464
+ });
465
+ this._onEngineEvent("stop", () => {
466
+ this._eventbus.broadcast("timeline-stop", []);
467
+ });
468
+ this._onEngineEvent("time", (position) => {
469
+ this._eventbus.broadcast("timeline-time", [position]);
470
+ });
471
+ this._onEngineEvent("duration", (duration) => {
472
+ this._eventbus.broadcast("timeline-duration", [() => duration]);
473
+ });
474
+ this._onEngineEvent("seekStart", (target, current, duration) => {
475
+ this._eventbus.broadcast("timeline-seek", [
476
+ target,
477
+ current,
478
+ duration
479
+ ]);
480
+ });
481
+ this._onEngineEvent("seekComplete", (position, duration) => {
482
+ this._eventbus.broadcast("timeline-seeked", [position, duration]);
483
+ });
484
+ this._onEngineEvent("timelineChange", (uri) => {
485
+ this._eventbus.broadcast("timeline-current-timeline-change", [uri]);
486
+ });
487
+ this._onEngineEvent("timelineComplete", () => {
488
+ this._eventbus.broadcast("timeline-complete", []);
489
+ });
490
+ this._onEngineEvent("timelineFirstFrame", () => {
491
+ this._eventbus.broadcast("timeline-firstframe", []);
492
+ });
493
+ this._onEngineEvent("timelineRestart", () => {
494
+ this._eventbus.broadcast("timeline-restart", []);
495
+ });
496
+ }
497
+ _onEngineEvent(event, handler) {
498
+ const remover = this._engine.on(event, handler);
499
+ this._engineEventRemovers.push(remover);
500
+ }
501
+ _subscribeToEventbusEvents() {
502
+ this._onEventbusEvent("timeline-play-request", () => {
503
+ this._engine.start();
504
+ });
505
+ this._onEventbusEvent("timeline-pause-request", () => {
506
+ this._engine.pause();
507
+ });
508
+ this._onEventbusEvent("timeline-stop-request", () => {
509
+ this._engine.stop();
510
+ });
511
+ this._onEventbusEvent("timeline-seek-request", (position) => {
512
+ this._engine.seek(position);
513
+ });
514
+ this._onEventbusEvent("timeline-play-toggle-request", () => {
515
+ if (this._engine.playState === "playing") this._engine.pause();
516
+ else this._engine.start();
517
+ });
518
+ this._onEventbusEvent("request-timeline-uri", (uri, position = 0) => {
519
+ this._engine.switchTimeline(uri, position);
520
+ });
521
+ this._registerRequest("request-current-timeline-position", () => {
522
+ return this._engine.position;
523
+ });
524
+ this._registerRequest("timeline-duration-request", () => {
525
+ return this._engine.duration;
526
+ });
527
+ this._registerRequest("timeline-container-request", () => {
528
+ return this._engine.container;
529
+ });
530
+ this._registerRequest("request-engine-root", () => {
531
+ return this._engine.engineRoot;
532
+ });
533
+ this._registerRequest("timeline-request-current-timeline", () => {
534
+ return this._engine.currentTimelineUri;
535
+ });
536
+ }
537
+ _onEventbusEvent(eventName, handler) {
538
+ const remover = this._eventbus.on(eventName, handler);
539
+ this._eventbusRemovers.push(remover);
540
+ }
541
+ _registerRequest(eventName, responder) {
542
+ const remover = this._eventbus.onRequest(eventName, responder);
543
+ this._eventbusRemovers.push(remover);
544
+ }
545
+ };
546
+
547
+ //#endregion
548
+ //#region src/adapters/engine-input-adapter.ts
549
+ const hotkeys = hk.default || hk;
550
+ /**
551
+ * Handles external input sources (hotkeys, resize).
552
+ *
553
+ * This adapter:
554
+ * - Registers keyboard hotkeys (space for play/pause toggle)
555
+ * - Handles window resize events with debouncing
556
+ */
557
+ var EngineInputAdapter = class {
558
+ _removers = [];
559
+ _resizeTimeout;
560
+ _resizeHandler;
561
+ constructor(_engine, _eventbus, _windowRef) {
562
+ this._engine = _engine;
563
+ this._eventbus = _eventbus;
564
+ this._windowRef = _windowRef;
565
+ }
566
+ /**
567
+ * Connect adapter - start listening to inputs
568
+ */
569
+ connect() {
570
+ this._registerHotkeys();
571
+ this._registerResizeHandler();
572
+ }
573
+ /**
574
+ * Disconnect adapter - stop all listeners
575
+ */
576
+ disconnect() {
577
+ if (this._resizeTimeout) {
578
+ clearTimeout(this._resizeTimeout);
579
+ this._resizeTimeout = void 0;
580
+ }
581
+ this._removers.forEach((remove) => remove());
582
+ this._removers = [];
583
+ }
584
+ _registerHotkeys() {
585
+ const handleSpaceBound = this._handleSpacePress.bind(this);
586
+ hotkeys("space", handleSpaceBound);
587
+ this._removers.push(() => hotkeys.unbind("space", handleSpaceBound));
588
+ }
589
+ _handleSpacePress(keyboardEvent, _hotkeysEvent) {
590
+ keyboardEvent.preventDefault();
591
+ if (this._engine.playState === "playing") this._engine.pause();
592
+ else this._engine.start();
593
+ return false;
594
+ }
595
+ _registerResizeHandler() {
596
+ this._resizeHandler = this._handleResize.bind(this);
597
+ this._windowRef.addEventListener("resize", this._resizeHandler);
598
+ this._removers.push(() => {
599
+ if (this._resizeHandler) this._windowRef.removeEventListener("resize", this._resizeHandler);
600
+ });
601
+ }
602
+ _handleResize() {
603
+ if (this._resizeTimeout) {
604
+ clearTimeout(this._resizeTimeout);
605
+ this._resizeTimeout = void 0;
606
+ }
607
+ this._resizeTimeout = setTimeout(() => {
608
+ this._eventbus.broadcast("timeline-resize", []);
609
+ }, 200);
610
+ }
611
+ };
612
+
613
+ //#endregion
614
+ //#region src/adapters/language-eventbus-adapter.ts
615
+ /**
616
+ * Bridges LanguageManager to/from the eventbus.
617
+ *
618
+ * This adapter:
619
+ * - Forwards language manager events to eventbus broadcasts
620
+ * - Forwards eventbus language commands to language manager methods
621
+ * - Handles eventbus state queries by reading language manager properties
622
+ * - Updates DOM lang attribute when language changes
623
+ *
624
+ * Note: Requires engine reference to update DOM lang attribute on language change
625
+ */
626
+ var LanguageEventbusAdapter = class {
627
+ _languageEventRemovers = [];
628
+ _eventbusRemovers = [];
629
+ constructor(_languageManager, _eventbus, _engine) {
630
+ this._languageManager = _languageManager;
631
+ this._eventbus = _eventbus;
632
+ this._engine = _engine;
633
+ }
634
+ /**
635
+ * Connect adapter - start listening and forwarding
636
+ */
637
+ connect() {
638
+ this._subscribeToLanguageManagerEvents();
639
+ this._subscribeToEventbusEvents();
640
+ }
641
+ /**
642
+ * Disconnect adapter - stop all listeners
643
+ */
644
+ disconnect() {
645
+ this._languageEventRemovers.forEach((remove) => remove());
646
+ this._languageEventRemovers = [];
647
+ this._eventbusRemovers.forEach((remove) => remove());
648
+ this._eventbusRemovers = [];
649
+ }
650
+ _subscribeToLanguageManagerEvents() {
651
+ this._onLanguageEvent("change", (language, _previousLanguage) => {
652
+ this._setRootElementLang(language);
653
+ this._eventbus.broadcast("language-change", [language]);
654
+ });
655
+ }
656
+ _onLanguageEvent(event, handler) {
657
+ const remover = this._languageManager.on(event, handler);
658
+ this._languageEventRemovers.push(remover);
659
+ }
660
+ _subscribeToEventbusEvents() {
661
+ this._onEventbusEvent("language-change", (language) => {
662
+ this._languageManager.setLanguage(language);
663
+ this._setRootElementLang(language);
664
+ });
665
+ this._registerRequest("request-current-language", () => {
666
+ return this._languageManager.language;
667
+ });
668
+ this._registerRequest("request-label-collection", (labelId) => {
669
+ return this._languageManager.getLabelCollection(labelId);
670
+ });
671
+ this._registerRequest("request-label-collections", (labelIds) => {
672
+ return this._languageManager.getLabelCollections(labelIds);
673
+ });
674
+ }
675
+ _onEventbusEvent(eventName, handler) {
676
+ const remover = this._eventbus.on(eventName, handler);
677
+ this._eventbusRemovers.push(remover);
678
+ }
679
+ _registerRequest(eventName, responder) {
680
+ const remover = this._eventbus.onRequest(eventName, responder);
681
+ this._eventbusRemovers.push(remover);
682
+ }
683
+ _setRootElementLang(language) {
684
+ const lang = this._extractPrimaryLanguage(language);
685
+ this._engine.engineRoot.attr("lang", lang);
686
+ }
687
+ _extractPrimaryLanguage(culture) {
688
+ return culture.split("-").shift();
689
+ }
690
+ };
691
+
530
692
  //#endregion
531
693
  //#region src/operation/add-class.ts
532
694
  /**
@@ -738,6 +900,12 @@ const broadcastEvent = function(operationData) {
738
900
  return operationData;
739
901
  };
740
902
 
903
+ //#endregion
904
+ //#region src/util/guards/is-object.ts
905
+ function isObject(value) {
906
+ return !!value && typeof value === "object" && !Array.isArray(value);
907
+ }
908
+
741
909
  //#endregion
742
910
  //#region src/operation/helper/resolve-property-values.ts
743
911
  const cache = [];
@@ -948,7 +1116,8 @@ const createElement = function(operationData) {
948
1116
  const { elementName, attributes, text } = operationData;
949
1117
  removeProperties(operationData, "elementName", "attributes", "text");
950
1118
  const serializedAttrs = attributes ? ` ${Object.entries(attributes).filter(([_, value]) => Boolean(value)).map(([key, value]) => `${key}="${value}"`).join(" ")}` : "";
951
- operationData.template = text ? $(`<${elementName}${serializedAttrs}>${text}</${elementName}>`) : $(`<${elementName}${serializedAttrs}/>`);
1119
+ const template = text ? $(`<${elementName}${serializedAttrs}>${text}</${elementName}>`) : $(`<${elementName}${serializedAttrs}/>`);
1120
+ operationData.template = template;
952
1121
  return operationData;
953
1122
  };
954
1123
 
@@ -965,16 +1134,15 @@ const createElement = function(operationData) {
965
1134
  const customFunction = function(operationData) {
966
1135
  const { systemName } = operationData;
967
1136
  removeProperties(operationData, "systemName");
968
- return new Promise((resolve, reject) => {
969
- const resultCallback = (func) => {
970
- const promise = func.apply(this, [operationData]);
971
- if (promise) promise.then(() => {
972
- internalResolve(resolve, {}, operationData);
973
- }, reject);
974
- else internalResolve(resolve, {}, operationData);
975
- };
976
- this.eventbus.broadcast("request-function", [systemName, resultCallback]);
1137
+ const func = this.eventbus.request("request-function", systemName);
1138
+ if (!func) return operationData;
1139
+ const promise = func.apply(this, [operationData]);
1140
+ if (promise) return new Promise((resolve, reject) => {
1141
+ promise.then(() => {
1142
+ internalResolve(resolve, {}, operationData);
1143
+ }, reject);
977
1144
  });
1145
+ return operationData;
978
1146
  };
979
1147
 
980
1148
  //#endregion
@@ -1297,11 +1465,7 @@ const getControllerFromElement = (operationData) => {
1297
1465
  const getControllerInstance = function(operationData) {
1298
1466
  const { systemName } = operationData;
1299
1467
  removeProperties(operationData, "systemName");
1300
- operationData.controllerInstance = void 0;
1301
- const resultCallback = (instance) => {
1302
- operationData.controllerInstance = instance;
1303
- };
1304
- this.eventbus.broadcast("request-instance", [systemName, resultCallback]);
1468
+ operationData.controllerInstance = this.eventbus.request("request-instance", systemName);
1305
1469
  return operationData;
1306
1470
  };
1307
1471
 
@@ -1529,11 +1693,7 @@ const getFormData = (operationData) => {
1529
1693
  const getImport = function(operationData) {
1530
1694
  const { systemName } = operationData;
1531
1695
  delete operationData.systemName;
1532
- const callBack = (instance) => {
1533
- operationData.importedInstance = instance;
1534
- };
1535
- this.eventbus.broadcast("request-function", [systemName, callBack]);
1536
- delete operationData.systemName;
1696
+ operationData.importedInstance = this.eventbus.request("request-function", systemName);
1537
1697
  return operationData;
1538
1698
  };
1539
1699
 
@@ -1928,6 +2088,12 @@ const mapArray = (operationData) => {
1928
2088
  return operationData;
1929
2089
  };
1930
2090
 
2091
+ //#endregion
2092
+ //#region src/util/guards/is-function.ts
2093
+ function isFunction(value) {
2094
+ return typeof value === "function";
2095
+ }
2096
+
1931
2097
  //#endregion
1932
2098
  //#region src/util/guards/is-string.ts
1933
2099
  function isString(value) {
@@ -2159,10 +2325,7 @@ const replaceText = (operationData) => {
2159
2325
  const requestAction = function(operationData) {
2160
2326
  const { systemName } = operationData;
2161
2327
  removeProperties(operationData, "systemName");
2162
- const resultCallback = (action) => {
2163
- operationData.actionInstance = action;
2164
- };
2165
- this.eventbus.broadcast("request-action", [systemName, resultCallback]);
2328
+ operationData.actionInstance = this.eventbus.request("request-action", systemName);
2166
2329
  return operationData;
2167
2330
  };
2168
2331
 
@@ -2318,10 +2481,8 @@ const selectElement = function(operationData) {
2318
2481
  operationData.selectedElement = findElementBySelector(currentRoot, selector);
2319
2482
  return operationData;
2320
2483
  }
2321
- const rootCallback = (root) => {
2322
- operationData.selectedElement = findElementBySelector(root, selector);
2323
- };
2324
- this.eventbus.broadcast("request-engine-root", [rootCallback]);
2484
+ const root = this.eventbus.request("request-engine-root");
2485
+ if (root) operationData.selectedElement = findElementBySelector(root, selector);
2325
2486
  return operationData;
2326
2487
  };
2327
2488
 
@@ -3585,323 +3746,154 @@ var LabelEditor = class {
3585
3746
  };
3586
3747
 
3587
3748
  //#endregion
3588
- //#region src/util/animation-interval.ts
3589
- function animationInterval(ms, signal, callback) {
3590
- const currentTime = document?.timeline?.currentTime;
3591
- const start = currentTime ? Number(currentTime) : performance.now();
3592
- const frame = (time) => {
3593
- if (signal.aborted) return;
3594
- callback(time);
3595
- scheduleFrame(time);
3596
- };
3597
- const { round } = Math;
3598
- const scheduleFrame = (time) => {
3599
- const delay = start + round((time - start) / ms) * ms + ms - performance.now();
3600
- setTimeout(() => requestAnimationFrame(frame), delay);
3601
- };
3602
- scheduleFrame(start);
3603
- }
3604
-
3605
- //#endregion
3606
- //#region src/timelineproviders/request-animation-frame-timeline-provider.ts
3607
- var RequestAnimationFrameTimelineProvider = class {
3608
- _currentPosition = 0;
3609
- _updateBound = this._update.bind(this);
3610
- _firstFramePending = true;
3611
- _currentPlaylistItem;
3612
- _tickInterval = 1e3;
3613
- _playlist;
3614
- _containerElement;
3615
- _abortController;
3616
- _onTime;
3617
- _onComplete;
3618
- _onRestart;
3619
- _onFirstFrame;
3620
- loop = false;
3621
- _playState = "stopped";
3622
- get playState() {
3623
- return this._playState;
3749
+ //#region src/configuration/api/timeline-provider-settings-editor.ts
3750
+ /**
3751
+ * Default position source system names for convenience methods.
3752
+ */
3753
+ const DEFAULT_POSITION_SOURCES = {
3754
+ raf: "RafPositionSource",
3755
+ scroll: "ScrollPositionSource",
3756
+ video: "VideoPositionSource"
3757
+ };
3758
+ /**
3759
+ * Default container provider system name.
3760
+ */
3761
+ const DEFAULT_CONTAINER_PROVIDER = "DomContainerProvider";
3762
+ /**
3763
+ * Default playlist system name.
3764
+ */
3765
+ const DEFAULT_PLAYLIST = "SimplePlaylist";
3766
+ var TimelineProvidersSettingsEditor = class {
3767
+ constructor(providersSettings, configurationFactory) {
3768
+ this.providersSettings = providersSettings;
3769
+ this.configurationFactory = configurationFactory;
3624
3770
  }
3625
- constructor(config) {
3626
- this._playlist = this._extractPlaylist(config);
3627
- this._currentPlaylistItem = this._playlist[0];
3771
+ /**
3772
+ * Adds a new provider for the specified timeline type.
3773
+ *
3774
+ * @param timelineType - The timeline type (e.g., 'animation', 'mediaplayer')
3775
+ * @param positionSourceSystemName - System name of the position source class (default: 'RafPositionSource')
3776
+ * @returns A TimelineProviderSettingsEditor for further configuration
3777
+ */
3778
+ addProvider(timelineType, positionSourceSystemName = "RafPositionSource") {
3779
+ if (this.providersSettings[timelineType]) throw new Error(`Settings for a '${timelineType}' provider already exist`);
3780
+ const settings = { positionSource: { systemName: positionSourceSystemName } };
3781
+ this.providersSettings[timelineType] = settings;
3782
+ return new TimelineProviderSettingsEditor(settings, this, this.configurationFactory);
3628
3783
  }
3629
- _extractPlaylist(configuration) {
3630
- return configuration.timelines.filter((timeline) => timeline.type === "animation");
3784
+ editProvider(timelineType) {
3785
+ if (!this.providersSettings[timelineType]) throw new Error(`No settings for a '${timelineType}' provider exist yet`);
3786
+ return new TimelineProviderSettingsEditor(this.providersSettings[timelineType], this, this.configurationFactory);
3631
3787
  }
3632
- onTime(callback) {
3633
- this._onTime = callback;
3788
+ next() {
3789
+ return this.configurationFactory;
3634
3790
  }
3635
- onComplete(callback) {
3636
- this._onComplete = callback;
3791
+ };
3792
+ var TimelineProviderSettingsEditor = class {
3793
+ constructor(providerSettings, providersSettingsEditor, configurationFactory) {
3794
+ this.providerSettings = providerSettings;
3795
+ this.providersSettingsEditor = providersSettingsEditor;
3796
+ this.configurationFactory = configurationFactory;
3637
3797
  }
3638
- onRestart(callback) {
3639
- this._onRestart = callback;
3798
+ /**
3799
+ * Sets the position source configuration with full config object.
3800
+ * @param config - Position source configuration with systemName and options
3801
+ */
3802
+ setPositionSource(config) {
3803
+ this.providerSettings.positionSource = config;
3804
+ return this;
3640
3805
  }
3641
- onFirstFrame(callback) {
3642
- this._onFirstFrame = callback;
3806
+ /**
3807
+ * Sets the position source by system name with optional configuration.
3808
+ * @param systemName - The position source class name (e.g., 'RafPositionSource')
3809
+ * @param options - Additional options passed to the position source constructor
3810
+ */
3811
+ setPositionSourceByName(systemName, options) {
3812
+ this.providerSettings.positionSource = {
3813
+ systemName,
3814
+ ...options
3815
+ };
3816
+ return this;
3643
3817
  }
3644
- playlistItem(uri) {
3645
- if (uri === null || !uri.length || this._playlist.length === 0) return;
3646
- const item = this._playlist.find((item$1) => {
3647
- return item$1.uri === uri;
3648
- });
3649
- if (!item) throw new Error(`Unknown playlist uri: ${uri}`);
3650
- this._currentPlaylistItem = item;
3651
- }
3652
- _update(_now) {
3653
- if (this.playState !== "running") return;
3654
- this._currentPosition++;
3655
- if (this._currentPosition > this._currentPlaylistItem.duration) if (this.loop) {
3656
- this._resetToStartPosition();
3657
- this._onRestart?.();
3658
- this._callbackPosition();
3659
- } else {
3660
- this.stop();
3661
- this._onComplete?.();
3662
- return;
3663
- }
3664
- this._callbackPosition();
3818
+ /**
3819
+ * Convenience method to set position source using shorthand type names.
3820
+ * @param type - Shorthand type ('raf', 'scroll', 'video')
3821
+ * @param options - Type-specific options
3822
+ * @deprecated Use setPositionSourceByName for explicit control
3823
+ */
3824
+ setPositionSourceType(type, options) {
3825
+ const systemName = DEFAULT_POSITION_SOURCES[type];
3826
+ if (!systemName) throw new Error(`Unknown position source type: ${type}`);
3827
+ this.providerSettings.positionSource = {
3828
+ systemName,
3829
+ ...options
3830
+ };
3831
+ return this;
3665
3832
  }
3666
- _callbackPosition() {
3667
- this._onTime?.(this._currentPosition);
3833
+ /**
3834
+ * Sets the container provider configuration by selector.
3835
+ * Uses DomContainerProvider by default.
3836
+ * @param selector - CSS selector for the container element
3837
+ */
3838
+ setContainer(selector) {
3839
+ this.providerSettings.container = {
3840
+ systemName: DEFAULT_CONTAINER_PROVIDER,
3841
+ selector
3842
+ };
3843
+ return this;
3668
3844
  }
3669
- start() {
3670
- if (this.playState === "running") {
3671
- if (this._currentPosition === 0) this._callbackPosition();
3672
- return;
3673
- }
3674
- this._playState = "running";
3675
- this._abortController?.abort();
3676
- this._abortController = new AbortController();
3677
- if (this._firstFramePending) {
3678
- this._firstFramePending = false;
3679
- this._onFirstFrame?.();
3680
- }
3681
- if (this._currentPosition === 0) this._callbackPosition();
3682
- animationInterval(this._tickInterval, this._abortController.signal, this._updateBound);
3845
+ /**
3846
+ * Sets the container provider configuration with full config object.
3847
+ * @param config - Container provider configuration with systemName
3848
+ */
3849
+ setContainerConfig(config) {
3850
+ this.providerSettings.container = config;
3851
+ return this;
3683
3852
  }
3684
- _resetToStartPosition() {
3685
- this._currentPosition = 0;
3686
- }
3687
- getContainer() {
3688
- return this._containerElement;
3689
- }
3690
- _stopAnimationInterval(resetPosition = true) {
3691
- this._abortController?.abort();
3692
- this._abortController = void 0;
3693
- if (resetPosition) this._resetToStartPosition();
3694
- }
3695
- init() {
3696
- this._currentPlaylistItem = this._playlist[0];
3697
- this._containerElement = $(this._currentPlaylistItem.selector);
3698
- if (!this._containerElement.length) throw new Error(`timeline selector '${this._currentPlaylistItem.selector}' not found`);
3699
- return Promise.resolve();
3700
- }
3701
- destroy() {
3702
- this.stop();
3703
- this._containerElement = void 0;
3704
- }
3705
- stop() {
3706
- this._stopAnimationInterval();
3707
- this._playState = "stopped";
3708
- }
3709
- pause() {
3710
- this._stopAnimationInterval(false);
3711
- this._playState = "stopped";
3712
- }
3713
- seek(position) {
3714
- if (position < 0 || position > this._currentPlaylistItem.duration) return Promise.resolve(this._currentPosition);
3715
- this._currentPosition = position;
3716
- return Promise.resolve(position);
3717
- }
3718
- getPosition() {
3719
- return this._currentPosition;
3720
- }
3721
- getDuration() {
3722
- return this._currentPlaylistItem.duration;
3723
- }
3724
- };
3725
-
3726
- //#endregion
3727
- //#region src/timelineproviders/video-js-timeline-provider.ts
3728
- const videojs = vjs.default ?? vjs;
3729
- var VideoJsTimelineProvider = class {
3730
- _videoElementId = v4();
3731
- _eventHandlers = [];
3732
- _playState = "stopped";
3733
- get playState() {
3734
- return this._playState;
3735
- }
3736
- loop = false;
3737
- _urls = [];
3738
- _onTime;
3739
- _onComplete;
3740
- _onRestart;
3741
- _onFirstFrame;
3742
- _player;
3743
- constructor(config) {
3744
- this.config = config;
3745
- }
3746
- init() {
3747
- videojs.log.level("all");
3748
- const selector = this.config.timelineProviderSettings.mediaplayer?.selector ?? "";
3749
- this._urls = this._extractUrls(this.config);
3750
- this._addVideoElements(selector, this._urls);
3751
- const self = this;
3752
- return new Promise((resolve) => {
3753
- setTimeout(() => {
3754
- this._player = videojs(this._videoElementId, {
3755
- controls: false,
3756
- controlBar: false,
3757
- liveui: false,
3758
- autoplay: false,
3759
- preload: "auto",
3760
- loop: this.loop,
3761
- src: this._urls[0]
3762
- }, function onPlayerReady() {
3763
- this.one("firstplay", () => self._onFirstFrame?.());
3764
- this.one("canplay", () => resolve());
3765
- self._addPlayerListener(this, "ended", self._handleEnded.bind(self));
3766
- self._addPlayerListener(this, "timeupdate", self._handleTimeUpdate.bind(self));
3767
- this.load();
3768
- });
3769
- }, 0);
3770
- });
3771
- }
3772
- _addPlayerListener(instance, type, eventHandler) {
3773
- instance.on(type, eventHandler);
3774
- this._eventHandlers.push(() => instance.off(type, eventHandler));
3775
- }
3776
- _handleEnded() {
3777
- if (!this._player?.loop) this._onComplete?.();
3778
- else this._onRestart?.();
3779
- }
3780
- _handleTimeUpdate() {
3781
- if (this._player) {
3782
- const time = this._player.currentTime();
3783
- if (time !== void 0) this._onTime?.(time);
3784
- }
3785
- }
3786
- start() {
3787
- this._player?.play();
3788
- this._playState = "running";
3789
- }
3790
- stop() {
3791
- this._player?.pause();
3792
- this._player?.currentTime(0);
3793
- this._playState = "stopped";
3794
- }
3795
- pause() {
3796
- this._player?.pause();
3797
- this._playState = "stopped";
3798
- }
3799
- seek(position) {
3800
- return new Promise((resolve) => {
3801
- this._player.one("seeked", () => {
3802
- resolve(this._player?.currentTime() ?? 0);
3803
- });
3804
- this._player?.currentTime(position);
3805
- });
3806
- }
3807
- playlistItem(uri) {
3808
- if (uri === null || !uri.length || this._urls.length === 0) return;
3809
- if (!this._urls.includes(uri)) throw new Error(`Unknown playlist uri: ${uri}`);
3810
- this._player?.selectSource([uri]);
3811
- }
3812
- getPosition() {
3813
- return this._player?.currentTime() ?? 0;
3814
- }
3815
- getDuration() {
3816
- return this._player?.duration() ?? 0;
3817
- }
3818
- getContainer() {
3819
- return $(this.config.timelineProviderSettings.mediaplayer?.selector ?? "");
3820
- }
3821
- destroy() {
3822
- this._eventHandlers.forEach((remover) => remover());
3823
- this._eventHandlers.length = 0;
3824
- }
3825
- onTime(callback) {
3826
- this._onTime = callback;
3827
- }
3828
- onComplete(callback) {
3829
- this._onComplete = callback;
3830
- }
3831
- onRestart(callback) {
3832
- this._onRestart = callback;
3833
- }
3834
- onFirstFrame(callback) {
3835
- this._onFirstFrame = callback;
3836
- }
3837
- _extractUrls(configuration) {
3838
- return configuration.timelines.filter((timeline) => timeline.type === "mediaplayer").map((timeline) => timeline.uri);
3839
- }
3840
- _addVideoElements(selector, urls) {
3841
- const videoElm = [`<video id=${this._videoElementId}>`];
3842
- urls.forEach((url) => {
3843
- videoElm.push(`<source src='${url}' type='${this._extractFileType(url)}'/>`);
3844
- });
3845
- videoElm.push("</video>");
3846
- $(selector).append(videoElm.join(""));
3847
- }
3848
- _extractFileType(url) {
3849
- const lastIdx = url.lastIndexOf(".");
3850
- return `video/${url.substring(lastIdx + 1)}`;
3851
- }
3852
- };
3853
-
3854
- //#endregion
3855
- //#region src/timelineproviders/index.ts
3856
- var timelineproviders_exports = /* @__PURE__ */ __export({
3857
- RequestAnimationFrameTimelineProvider: () => RequestAnimationFrameTimelineProvider,
3858
- VideoJsTimelineProvider: () => VideoJsTimelineProvider
3859
- });
3860
-
3861
- //#endregion
3862
- //#region src/configuration/api/timeline-provider-settings-editor.ts
3863
- var TimelineProvidersSettingsEditor = class {
3864
- constructor(providersSettings, configurationFactory) {
3865
- this.providersSettings = providersSettings;
3866
- this.configurationFactory = configurationFactory;
3867
- }
3868
- addProvider(timelineType) {
3869
- if (this.providersSettings[timelineType]) throw new Error(`Settings for a '${timelineType}' provider already exist`);
3870
- const settings = {
3871
- id: v4(),
3872
- poster: void 0,
3873
- selector: void 0,
3874
- systemName: "",
3875
- vendor: ""
3853
+ /**
3854
+ * Sets the container provider by system name with options.
3855
+ * @param systemName - The container provider class name
3856
+ * @param options - Additional options passed to the container provider constructor
3857
+ */
3858
+ setContainerByName(systemName, options) {
3859
+ this.providerSettings.container = {
3860
+ systemName,
3861
+ ...options
3876
3862
  };
3877
- this.providersSettings[timelineType] = settings;
3878
- return new TimelineProviderSettingsEditor(settings, this, this.configurationFactory);
3879
- }
3880
- editProvider(timelineType) {
3881
- if (!this.providersSettings[timelineType]) throw new Error(`No settings for a '${timelineType}' provider exist yet`);
3882
- return new TimelineProviderSettingsEditor(this.providersSettings[timelineType], this, this.configurationFactory);
3883
- }
3884
- next() {
3885
- return this.configurationFactory;
3886
- }
3887
- };
3888
- var TimelineProviderSettingsEditor = class {
3889
- constructor(providerSettings, providersSettingsEditor, configurationFactory) {
3890
- this.providerSettings = providerSettings;
3891
- this.providersSettingsEditor = providersSettingsEditor;
3892
- this.configurationFactory = configurationFactory;
3863
+ return this;
3893
3864
  }
3894
- setVendor(vendor) {
3895
- this.providerSettings.vendor = vendor;
3865
+ /**
3866
+ * Sets the playlist configuration.
3867
+ * Uses SimplePlaylist by default.
3868
+ * @param items - Array of playlist items
3869
+ * @param identifierKey - Key used to identify items (default: 'uri')
3870
+ */
3871
+ setPlaylist(items, identifierKey = "uri") {
3872
+ this.providerSettings.playlist = {
3873
+ systemName: DEFAULT_PLAYLIST,
3874
+ items,
3875
+ identifierKey
3876
+ };
3896
3877
  return this;
3897
3878
  }
3898
- setSelector(selector) {
3899
- this.providerSettings.selector = selector;
3879
+ /**
3880
+ * Sets the playlist configuration with full config object.
3881
+ * @param config - Playlist configuration with systemName
3882
+ */
3883
+ setPlaylistConfig(config) {
3884
+ this.providerSettings.playlist = config;
3900
3885
  return this;
3901
3886
  }
3902
- setSystemName(systemName) {
3903
- if (!timelineproviders_exports[systemName]) throw new Error(`Unknown timeline provider system name: ${systemName}`);
3904
- this.providerSettings.systemName = systemName;
3887
+ /**
3888
+ * Sets the playlist by system name with options.
3889
+ * @param systemName - The playlist class name
3890
+ * @param options - Additional options including items and identifierKey
3891
+ */
3892
+ setPlaylistByName(systemName, options) {
3893
+ this.providerSettings.playlist = {
3894
+ systemName,
3895
+ ...options
3896
+ };
3905
3897
  return this;
3906
3898
  }
3907
3899
  next() {
@@ -4459,15 +4451,13 @@ var DOMEventListenerController = class {
4459
4451
  const { selectedElement, actions, eventName } = this.operationData;
4460
4452
  if (!this.actionInstanceInfos) {
4461
4453
  this.actionInstanceInfos = [];
4462
- const resultCallback = (isStart) => (actionInstance) => {
4463
- this.actionInstanceInfos?.push({
4454
+ actions.forEach((actionName) => {
4455
+ const [isStart, name] = this._isStartAction(actionName);
4456
+ const actionInstance = eventbus$1.request("request-action", name);
4457
+ if (actionInstance) this.actionInstanceInfos?.push({
4464
4458
  start: isStart,
4465
4459
  action: actionInstance
4466
4460
  });
4467
- };
4468
- actions.forEach((actionName) => {
4469
- const [isStart, name] = this._isStartAction(actionName);
4470
- eventbus$1.broadcast("request-action", [name, resultCallback(isStart)]);
4471
4461
  });
4472
4462
  selectedElement.on(eventName, this._eventHandler.bind(this));
4473
4463
  }
@@ -4588,19 +4578,16 @@ var LabelController = class extends BaseController {
4588
4578
  }
4589
4579
  attach(eventbus$1) {
4590
4580
  if (!this.operationData) return;
4591
- eventbus$1.broadcast("request-current-language", [(language) => {
4592
- this.currentLanguage = language;
4593
- }]);
4581
+ this.currentLanguage = eventbus$1.request("request-current-language") ?? null;
4594
4582
  this.requestLabelDataBound = this._requestLabelData.bind(this, eventbus$1);
4595
4583
  this.requestLabelDataBound(this.operationData.labelId);
4596
4584
  this._setLabel();
4597
4585
  this.addListener(eventbus$1, "language-change", this._handleLanguageChange);
4598
4586
  }
4599
4587
  _requestLabelData(eventbus$1, labelId) {
4600
- eventbus$1.broadcast("request-label-collection", [labelId, (labelCollection) => {
4601
- if (labelCollection) this._createTextDataLookup(labelCollection);
4602
- else throw new Error(`Label id '${labelId}' does not exist!`);
4603
- }]);
4588
+ const labelCollection = eventbus$1.request("request-label-collection", labelId);
4589
+ if (labelCollection) this._createTextDataLookup(labelCollection);
4590
+ else throw new Error(`Label id '${labelId}' does not exist!`);
4604
4591
  }
4605
4592
  _setLabel() {
4606
4593
  if (this.currentLanguage) {
@@ -4661,16 +4648,9 @@ var LottieController = class extends BaseController {
4661
4648
  if (!this.operationData) return;
4662
4649
  const { labelIds } = this.operationData;
4663
4650
  if (labelIds?.length) {
4664
- let currentLanguage = "en-US";
4665
- let labelCollections = [];
4666
- eventbus$1.broadcast("request-current-language", [(language) => {
4667
- currentLanguage = language;
4668
- }]);
4669
- this.currentLanguage = currentLanguage;
4651
+ this.currentLanguage = eventbus$1.request("request-current-language") ?? "en-US";
4670
4652
  this.addListener(eventbus$1, "language-change", this._handleLanguageChange);
4671
- eventbus$1.broadcast("request-label-collections", [this.operationData.labelIds, (collections) => {
4672
- labelCollections = collections;
4673
- }]);
4653
+ const labelCollections = eventbus$1.request("request-label-collections", this.operationData.labelIds) ?? [];
4674
4654
  this._createTextDataLookup(labelCollections);
4675
4655
  }
4676
4656
  this._createAnimation();
@@ -4963,13 +4943,13 @@ var NavigationController = class extends BaseController {
4963
4943
  selectedElement: parentElm,
4964
4944
  labelId
4965
4945
  };
4966
- const resultCallback = (instance) => {
4946
+ const instance = this.eventbus?.request("request-instance", "LabelController");
4947
+ if (instance) {
4967
4948
  instance.init(data);
4968
4949
  instance.attach(this.eventbus);
4969
4950
  this.labelControllers.push(instance);
4970
4951
  this.ctrlLookup[labelId] = instance;
4971
- };
4972
- this.eventbus?.broadcast("request-instance", ["LabelController", resultCallback]);
4952
+ }
4973
4953
  }
4974
4954
  _buildNavigationData(data) {
4975
4955
  const result = [];
@@ -5013,7 +4993,7 @@ var ProgressbarController = class extends BaseController {
5013
4993
  }
5014
4994
  attach(eventbus$1) {
5015
4995
  this.addListener(eventbus$1, "timeline-time", this._positionUpdateHandler);
5016
- eventbus$1.broadcast("timeline-duration-request", [(duration) => this.duration = duration]);
4996
+ this.duration = eventbus$1.request("timeline-duration-request") ?? 0;
5017
4997
  this.selectedElement?.css({ "pointer-events": "none" });
5018
4998
  const container = this.selectedElement?.parent();
5019
4999
  if (container) {
@@ -7597,7 +7577,10 @@ function requestCurrentTimelinePosition() {
7597
7577
  return {
7598
7578
  description: `Event: request-current-timeline-position`,
7599
7579
  category: `Engine Request`,
7600
- args: []
7580
+ args: [{
7581
+ name: "callback",
7582
+ type: "TResultCallback<number>"
7583
+ }]
7601
7584
  };
7602
7585
  }
7603
7586
 
@@ -7707,7 +7690,13 @@ function requestTimelineUri() {
7707
7690
  return {
7708
7691
  description: `Event: request-timeline-uri`,
7709
7692
  category: `Engine Request`,
7710
- args: []
7693
+ args: [{
7694
+ name: "uri",
7695
+ type: "string"
7696
+ }, {
7697
+ name: "position",
7698
+ type: "number"
7699
+ }]
7711
7700
  };
7712
7701
  }
7713
7702
 
@@ -7872,7 +7861,10 @@ function timelineRequestCurrentTimeline() {
7872
7861
  return {
7873
7862
  description: `Event: timeline-request-current-timeline`,
7874
7863
  category: `Engine Request`,
7875
- args: []
7864
+ args: [{
7865
+ name: "callback",
7866
+ type: "TResultCallback<string>"
7867
+ }]
7876
7868
  };
7877
7869
  }
7878
7870
 
@@ -8079,17 +8071,44 @@ var ActionRegistryEventbusListener = class {
8079
8071
 
8080
8072
  //#endregion
8081
8073
  //#region src/eventbus/eventbus.ts
8074
+ /**
8075
+ * Central event bus for pub/sub communication and synchronous request/response queries.
8076
+ *
8077
+ * The eventbus supports:
8078
+ * - **Pub/Sub**: `on()`, `once()`, `off()`, `broadcast()`, `broadcastForTopic()`
8079
+ * - **Request/Response**: `onRequest()`, `request()`, `requestForTopic()` for synchronous queries
8080
+ * - **Interceptors**: Transform event arguments before handlers receive them
8081
+ * - **Listeners**: Global event observers for logging/debugging
8082
+ *
8083
+ * @example Pub/Sub pattern
8084
+ * ```ts
8085
+ * const remover = eventbus.on('timeline-play', () => console.log('Playing'));
8086
+ * eventbus.broadcast('timeline-play', []);
8087
+ * remover(); // Unsubscribe
8088
+ * ```
8089
+ *
8090
+ * @example Request/Response pattern
8091
+ * ```ts
8092
+ * eventbus.onRequest('request-instance', (name) => new MyClass(name));
8093
+ * const instance = eventbus.request<MyClass>('request-instance', 'test');
8094
+ * ```
8095
+ */
8082
8096
  var Eventbus = class {
8083
8097
  eventHandlers = /* @__PURE__ */ new Map();
8084
8098
  eventInterceptors = /* @__PURE__ */ new Map();
8085
8099
  eventListeners = [];
8100
+ requestResponders = /* @__PURE__ */ new Map();
8086
8101
  constructor() {
8087
8102
  this.clear();
8088
8103
  }
8104
+ /**
8105
+ * Clears all handlers, listeners, interceptors, and request responders.
8106
+ */
8089
8107
  clear() {
8090
8108
  this.eventHandlers = /* @__PURE__ */ new Map();
8091
8109
  this.eventListeners = [];
8092
8110
  this.eventInterceptors = /* @__PURE__ */ new Map();
8111
+ this.requestResponders = /* @__PURE__ */ new Map();
8093
8112
  }
8094
8113
  _getEventInterceptors(eventName, eventTopic) {
8095
8114
  if (eventTopic) eventName = `${eventName}:${eventTopic}`;
@@ -8145,6 +8164,30 @@ var Eventbus = class {
8145
8164
  if (index > -1) interceptors.splice(index, 1);
8146
8165
  };
8147
8166
  }
8167
+ onRequest(eventName, responder, eventTopic) {
8168
+ const responders = this._getRequestResponders(eventName, eventTopic);
8169
+ responders.push(responder);
8170
+ return () => {
8171
+ const index = responders.indexOf(responder);
8172
+ if (index > -1) responders.splice(index, 1);
8173
+ };
8174
+ }
8175
+ request(eventName, ...args) {
8176
+ return this._callResponder(eventName, void 0, args);
8177
+ }
8178
+ requestForTopic(eventName, eventTopic, ...args) {
8179
+ return this._callResponder(eventName, eventTopic, args);
8180
+ }
8181
+ _getRequestResponders(eventName, eventTopic) {
8182
+ if (eventTopic) eventName = `${eventName}:${eventTopic}`;
8183
+ if (!this.requestResponders.has(eventName)) this.requestResponders.set(eventName, []);
8184
+ return this.requestResponders.get(eventName);
8185
+ }
8186
+ _callResponder(eventName, eventTopic, args) {
8187
+ const responders = this._getRequestResponders(eventName, eventTopic);
8188
+ if (responders.length === 0) return;
8189
+ return responders[0](...args);
8190
+ }
8148
8191
  _callHandlers(eventName, eventTopic, args = []) {
8149
8192
  const handlers = this._getEventHandlers(eventName, eventTopic);
8150
8193
  if (handlers) {
@@ -8181,150 +8224,1171 @@ var eventbus_exports = /* @__PURE__ */ __export({
8181
8224
  });
8182
8225
 
8183
8226
  //#endregion
8184
- //#region src/eligius-engine.ts
8227
+ //#region src/timelineproviders/types.ts
8185
8228
  /**
8186
- * This is where the magic happens. The engine is responsible for starting and stopping
8187
- * the given timeline provider and triggering the actions associated with the positions along the timeline.
8229
+ * Type guard to check if a position source is seekable.
8230
+ *
8231
+ * @param source - Position source to check
8232
+ * @returns `true` if source implements ISeekable
8188
8233
  */
8189
- var EligiusEngine = class EligiusEngine {
8190
- _timeLineActionsLookup = {};
8191
- _timelineLookupCache = /* @__PURE__ */ new Map();
8192
- _eventbusRemovers = [];
8193
- _currentTimelineUri = "";
8194
- _activeTimelineProvider = void 0;
8195
- _lastPosition = -1;
8196
- constructor(configuration, eventbus$1, timelineProviders, languageManager) {
8197
- this.configuration = configuration;
8198
- this.eventbus = eventbus$1;
8199
- this.timelineProviders = timelineProviders;
8200
- this.languageManager = languageManager;
8201
- }
8234
+ function isSeekable(source) {
8235
+ return "seek" in source && typeof source.seek === "function";
8236
+ }
8237
+
8238
+ //#endregion
8239
+ //#region src/timelineproviders/position-sources/base-position-source.ts
8240
+ /**
8241
+ * Abstract base class for position sources.
8242
+ *
8243
+ * Provides shared state management, lifecycle handling, and callback
8244
+ * registration for concrete position source implementations.
8245
+ *
8246
+ * Subclasses must implement:
8247
+ * - `doInit()` - Source-specific initialization
8248
+ * - `doDestroy()` - Source-specific cleanup
8249
+ * - `startTicking()` - Start emitting position updates
8250
+ * - `stopTicking()` - Stop emitting position updates
8251
+ *
8252
+ * @example
8253
+ * ```typescript
8254
+ * class MyPositionSource extends BasePositionSource {
8255
+ * protected doInit(): Promise<void> {
8256
+ * // Initialize resources
8257
+ * return Promise.resolve();
8258
+ * }
8259
+ *
8260
+ * protected doDestroy(): void {
8261
+ * // Clean up resources
8262
+ * }
8263
+ *
8264
+ * protected startTicking(): void {
8265
+ * // Start position updates
8266
+ * }
8267
+ *
8268
+ * protected stopTicking(): void {
8269
+ * // Stop position updates
8270
+ * }
8271
+ * }
8272
+ * ```
8273
+ */
8274
+ var BasePositionSource = class {
8275
+ _state = "inactive";
8276
+ _position = 0;
8277
+ _duration;
8278
+ _loop = false;
8279
+ _positionCallbacks = [];
8280
+ _boundaryCallbacks = [];
8281
+ _activatedCallbacks = [];
8202
8282
  /**
8203
- * Initializes the engine by creating the HTML layout and the first time line
8204
- * by executing its initActions.
8283
+ * Create a new position source.
8284
+ *
8285
+ * @param duration - Total duration in seconds (or `Infinity` for unbounded)
8205
8286
  */
8206
- init() {
8207
- this._createLayoutTemplate();
8208
- this._addEventbusListeners();
8209
- const { timelines } = this.configuration;
8210
- this._currentTimelineUri = timelines?.[0].uri ?? "";
8211
- this._createTimelineLookup();
8212
- return this._initializeTimelineProvider();
8287
+ constructor(duration) {
8288
+ this._duration = duration;
8213
8289
  }
8214
- _createLayoutTemplate() {
8215
- const { containerSelector } = this.configuration;
8216
- const container = $(containerSelector);
8217
- if (!container || !container.length) throw new Error(`Container selector not found: ${containerSelector}`);
8218
- const { layoutTemplate } = this.configuration;
8219
- if (layoutTemplate?.length) container.html(layoutTemplate);
8220
- else console.warn("layoutTemplate is empty, unable to create layout");
8290
+ get state() {
8291
+ return this._state;
8221
8292
  }
8222
- async _initializeTimelineProvider() {
8223
- if (!this.configuration.timelines?.length) throw new Error("No timelines present");
8224
- const firstTimeline = this.configuration.timelines[0];
8225
- const providerSettings = this.timelineProviders[firstTimeline.type];
8226
- if (!providerSettings) throw new Error(`No timeline provider configured for type ${firstTimeline.type}`);
8227
- this._activeTimelineProvider?.destroy();
8228
- this._activeTimelineProvider = providerSettings.provider;
8229
- if (!this._activeTimelineProvider) throw new Error("NO ACTIVE TIMELINE PROVIDER");
8230
- this._activeTimelineProvider.onTime(this._onTimeHandler.bind(this, Math.floor));
8231
- this._activeTimelineProvider.onComplete(this._onCompleteCallback.bind(this));
8232
- this._activeTimelineProvider.onFirstFrame(this._onFirstFrameCallback.bind(this));
8233
- this._activeTimelineProvider.onRestart(this._onRestartCallback.bind(this));
8234
- await this._activeTimelineProvider.init();
8235
- await this._executeActions(this.configuration.initActions, "start");
8236
- return this._activeTimelineProvider;
8293
+ get loop() {
8294
+ return this._loop;
8237
8295
  }
8238
- _onCompleteCallback() {
8239
- this.eventbus.broadcast("timeline-complete", []);
8296
+ set loop(value) {
8297
+ this._loop = value;
8240
8298
  }
8241
- _onFirstFrameCallback() {
8242
- this.eventbus.broadcast("timeline-firstframe", []);
8243
- this.eventbus.broadcast("timeline-duration", [this._activeTimelineProvider?.getDuration]);
8299
+ async init() {
8300
+ await this.doInit();
8244
8301
  }
8245
- _onRestartCallback() {
8246
- this.eventbus.broadcast("timeline-restart", []);
8302
+ destroy() {
8303
+ if (this._state === "active") this.stopTicking();
8304
+ this._state = "inactive";
8305
+ this._position = 0;
8306
+ this.doDestroy();
8307
+ }
8308
+ async activate() {
8309
+ if (this._state === "active") return;
8310
+ this._state = "active";
8311
+ this.startTicking();
8312
+ for (const callback of this._activatedCallbacks) callback();
8313
+ }
8314
+ suspend() {
8315
+ if (this._state !== "active") return;
8316
+ this._state = "suspended";
8317
+ this.stopTicking();
8318
+ }
8319
+ deactivate() {
8320
+ if (this._state === "inactive") return;
8321
+ if (this._state === "active") this.stopTicking();
8322
+ this._state = "inactive";
8323
+ this._position = 0;
8247
8324
  }
8248
- async _cleanUp() {
8249
- await this._cleanUpTimeline();
8250
- await this._executeActions([...this.configuration.initActions].reverse(), "end");
8325
+ getPosition() {
8326
+ return this._position;
8327
+ }
8328
+ getDuration() {
8329
+ return this._duration;
8330
+ }
8331
+ onPosition(callback) {
8332
+ this._positionCallbacks.push(callback);
8333
+ }
8334
+ onBoundaryReached(callback) {
8335
+ this._boundaryCallbacks.push(callback);
8336
+ }
8337
+ onActivated(callback) {
8338
+ this._activatedCallbacks.push(callback);
8251
8339
  }
8252
8340
  /**
8253
- * Cleans up all the necessary parts that the engine initialized.
8254
- * - It ends the currently active operations and the init actions.
8255
- * - It removes all its eventbus listeners, handlers and interceptors.
8256
- * - It destroys all of its timeline providers
8257
- * - It empties the HTML element indicated by the containerSelector configuration property.
8341
+ * Set the current position and emit to callbacks.
8342
+ *
8343
+ * Only emits if the source is active.
8258
8344
  *
8345
+ * @param position - New position value
8259
8346
  */
8260
- async destroy() {
8261
- await this._cleanUp();
8262
- this.languageManager.destroy();
8263
- this._activeTimelineProvider = void 0;
8264
- this._eventbusRemovers.forEach((remover) => remover());
8265
- if (this.timelineProviders) Object.values(this.timelineProviders).forEach((providerInfo) => providerInfo.provider.destroy());
8266
- const { containerSelector } = this.configuration;
8267
- $(containerSelector).empty();
8347
+ setPosition(position) {
8348
+ this._position = position;
8349
+ if (this._state === "active") for (const callback of this._positionCallbacks) callback(position);
8268
8350
  }
8269
- _addEventListener(eventName, eventHandler, eventTopic) {
8270
- this._eventbusRemovers.push(this.eventbus.on(eventName, eventHandler, eventTopic));
8271
- }
8272
- _addEventbusListeners() {
8351
+ /**
8352
+ * Emit a boundary event to all registered callbacks.
8353
+ *
8354
+ * @param boundary - The boundary type ('start' or 'end')
8355
+ */
8356
+ emitBoundary(boundary) {
8357
+ for (const callback of this._boundaryCallbacks) callback(boundary);
8358
+ }
8359
+ };
8360
+
8361
+ //#endregion
8362
+ //#region src/util/animation-interval.ts
8363
+ function animationInterval(ms, signal, callback) {
8364
+ const currentTime = document?.timeline?.currentTime;
8365
+ const start = currentTime ? Number(currentTime) : performance.now();
8366
+ const frame = (time) => {
8367
+ if (signal.aborted) return;
8368
+ callback(time);
8369
+ scheduleFrame(time);
8370
+ };
8371
+ const { round } = Math;
8372
+ const scheduleFrame = (time) => {
8373
+ const delay = start + round((time - start) / ms) * ms + ms - performance.now();
8374
+ setTimeout(() => requestAnimationFrame(frame), delay);
8375
+ };
8376
+ scheduleFrame(start);
8377
+ }
8378
+
8379
+ //#endregion
8380
+ //#region src/timelineproviders/position-sources/raf-position-source.ts
8381
+ /**
8382
+ * RequestAnimationFrame-based position source.
8383
+ *
8384
+ * Uses the `animationInterval` utility to emit position updates at a regular
8385
+ * interval (default: 1 second). Position increments by 1 per second, making
8386
+ * position values equivalent to elapsed seconds.
8387
+ *
8388
+ * Implements both `IPositionSource` (via `BasePositionSource`) and `ISeekable`.
8389
+ *
8390
+ * @example
8391
+ * ```typescript
8392
+ * const source = new RafPositionSource({ duration: 60 });
8393
+ * await source.init();
8394
+ *
8395
+ * source.onPosition((position) => {
8396
+ * console.log(`Position: ${position}s`);
8397
+ * });
8398
+ *
8399
+ * source.onBoundaryReached((boundary) => {
8400
+ * if (boundary === 'end') {
8401
+ * console.log('Timeline complete');
8402
+ * }
8403
+ * });
8404
+ *
8405
+ * await source.activate();
8406
+ *
8407
+ * // Seek to 30 seconds
8408
+ * await source.seek(30);
8409
+ * ```
8410
+ */
8411
+ var RafPositionSource = class extends BasePositionSource {
8412
+ _tickInterval;
8413
+ _abortController = null;
8414
+ _startTimeOffset = 0;
8415
+ /**
8416
+ * Create a new RAF-based position source.
8417
+ *
8418
+ * @param config - Configuration options
8419
+ */
8420
+ constructor(config) {
8421
+ super(config.duration);
8422
+ this._tickInterval = config.tickInterval ?? 1e3;
8423
+ }
8424
+ doInit() {
8425
+ return Promise.resolve();
8426
+ }
8427
+ doDestroy() {
8428
+ this._abortTicking();
8429
+ }
8430
+ startTicking() {
8431
+ this.setPosition(this.getPosition());
8432
+ this._abortController = new AbortController();
8433
+ animationInterval(this._tickInterval, this._abortController.signal, this._onTick.bind(this));
8434
+ }
8435
+ stopTicking() {
8436
+ this._abortTicking();
8437
+ }
8438
+ /**
8439
+ * Seek to a specific position.
8440
+ *
8441
+ * Position is clamped to the valid range [0, duration].
8442
+ *
8443
+ * @param position - Target position in seconds
8444
+ * @returns Actual position after seek (may be clamped)
8445
+ */
8446
+ async seek(position) {
8447
+ const clampedPosition = Math.max(0, Math.min(position, this.getDuration()));
8448
+ this.setPosition(clampedPosition);
8449
+ return clampedPosition;
8450
+ }
8451
+ /**
8452
+ * Handle a tick from animationInterval.
8453
+ *
8454
+ * The time parameter represents elapsed milliseconds since the animation
8455
+ * interval started. Position is calculated in seconds, rounded to the
8456
+ * precision determined by tickInterval.
8457
+ *
8458
+ * @param time - Elapsed time in milliseconds from animationInterval
8459
+ */
8460
+ _onTick(time) {
8461
+ if (this.state !== "active") return;
8462
+ const elapsedSinceStart = time - this._startTimeOffset;
8463
+ const newPosition = Math.floor(elapsedSinceStart / this._tickInterval) * this._tickInterval / 1e3;
8464
+ const duration = this.getDuration();
8465
+ if (newPosition >= duration) {
8466
+ this.emitBoundary("end");
8467
+ if (this.loop) {
8468
+ this._startTimeOffset = time;
8469
+ this.setPosition(0);
8470
+ this.emitBoundary("start");
8471
+ } else {
8472
+ this.setPosition(duration);
8473
+ this.deactivate();
8474
+ }
8475
+ } else this.setPosition(newPosition);
8476
+ }
8477
+ /**
8478
+ * Abort the current ticking session.
8479
+ */
8480
+ _abortTicking() {
8481
+ if (this._abortController) {
8482
+ this._abortController.abort();
8483
+ this._abortController = null;
8484
+ }
8485
+ }
8486
+ };
8487
+
8488
+ //#endregion
8489
+ //#region src/timelineproviders/position-sources/scroll-position-source.ts
8490
+ /**
8491
+ * Scroll-based position source.
8492
+ *
8493
+ * Maps scroll position to a timeline position. The position is calculated
8494
+ * as a percentage of the scroll progress multiplied by the configured duration.
8495
+ *
8496
+ * Implements `IPositionSource` and `ISeekable`.
8497
+ *
8498
+ * @example
8499
+ * ```typescript
8500
+ * const source = new ScrollPositionSource({
8501
+ * selector: '#scroll-container',
8502
+ * duration: 100, // 100 seconds timeline
8503
+ * });
8504
+ *
8505
+ * await source.init();
8506
+ *
8507
+ * source.onPosition((position) => {
8508
+ * console.log(`Scroll at ${position}s of 100s`);
8509
+ * });
8510
+ *
8511
+ * source.onBoundaryReached((boundary) => {
8512
+ * if (boundary === 'end') {
8513
+ * console.log('Scrolled to bottom');
8514
+ * }
8515
+ * });
8516
+ *
8517
+ * await source.activate();
8518
+ * ```
8519
+ */
8520
+ var ScrollPositionSource = class extends BasePositionSource {
8521
+ _config;
8522
+ _element = null;
8523
+ _boundScrollHandler = null;
8524
+ _lastPosition = 0;
8525
+ _wasAtStart = true;
8526
+ /**
8527
+ * Create a new scroll-based position source.
8528
+ *
8529
+ * @param config - Configuration options
8530
+ */
8531
+ constructor(config) {
8532
+ super(config.duration);
8533
+ this._config = config;
8534
+ }
8535
+ doInit() {
8536
+ return new Promise((resolve, reject) => {
8537
+ const $element = $(this._config.selector);
8538
+ if ($element.length === 0) {
8539
+ reject(/* @__PURE__ */ new Error(`Element not found: ${this._config.selector}`));
8540
+ return;
8541
+ }
8542
+ this._element = $element.get(0);
8543
+ resolve();
8544
+ });
8545
+ }
8546
+ doDestroy() {
8547
+ if (this._element && this._boundScrollHandler) {
8548
+ this._element.removeEventListener("scroll", this._boundScrollHandler, { passive: true });
8549
+ this._boundScrollHandler = null;
8550
+ }
8551
+ this._element = null;
8552
+ }
8553
+ startTicking() {
8554
+ if (!this._element) return;
8555
+ this._boundScrollHandler = this._handleScroll.bind(this);
8556
+ this._element.addEventListener("scroll", this._boundScrollHandler, { passive: true });
8557
+ }
8558
+ stopTicking() {
8559
+ if (this._element && this._boundScrollHandler) {
8560
+ this._element.removeEventListener("scroll", this._boundScrollHandler, { passive: true });
8561
+ this._boundScrollHandler = null;
8562
+ }
8563
+ }
8564
+ /**
8565
+ * Seek to a specific position by programmatically scrolling.
8566
+ *
8567
+ * @param position - Target position in seconds (0 to duration)
8568
+ * @returns Actual position after scroll
8569
+ */
8570
+ async seek(position) {
8571
+ if (!this._element || this.state === "inactive") return this.getPosition();
8572
+ const scrollableHeight = this._getScrollableHeight();
8573
+ const targetScrollTop = position / this._config.duration * scrollableHeight;
8574
+ this._element.scrollTo({
8575
+ top: targetScrollTop,
8576
+ behavior: "smooth"
8577
+ });
8578
+ return position;
8579
+ }
8580
+ /**
8581
+ * Handle scroll events and update position.
8582
+ */
8583
+ _handleScroll(_event) {
8584
+ if (this.state !== "active" || !this._element) return;
8585
+ const position = this._calculatePosition();
8586
+ const duration = this._config.duration;
8587
+ const previousPosition = this._lastPosition;
8588
+ this._lastPosition = position;
8589
+ this.setPosition(position);
8590
+ if (position >= duration && previousPosition < duration) {
8591
+ this.emitBoundary("end");
8592
+ if (this.loop) this._element.scrollTo({
8593
+ top: 0,
8594
+ behavior: "smooth"
8595
+ });
8596
+ }
8597
+ if (position === 0 && previousPosition > 0 && !this._wasAtStart) this.emitBoundary("start");
8598
+ this._wasAtStart = position === 0;
8599
+ }
8600
+ /**
8601
+ * Calculate position from scroll percentage.
8602
+ */
8603
+ _calculatePosition() {
8604
+ if (!this._element) return 0;
8605
+ const scrollTop = this._element.scrollTop;
8606
+ const scrollableHeight = this._getScrollableHeight();
8607
+ if (scrollableHeight <= 0) return 0;
8608
+ return scrollTop / scrollableHeight * this._config.duration;
8609
+ }
8610
+ /**
8611
+ * Get the scrollable height (total scroll distance).
8612
+ */
8613
+ _getScrollableHeight() {
8614
+ if (!this._element) return 0;
8615
+ return this._element.scrollHeight - this._element.clientHeight;
8616
+ }
8617
+ };
8618
+
8619
+ //#endregion
8620
+ //#region src/timelineproviders/position-sources/video-position-source.ts
8621
+ const videojs = vjs.default ?? vjs;
8622
+ /**
8623
+ * Video.js-based position source.
8624
+ *
8625
+ * Wraps a video.js player to provide position updates based on video playback.
8626
+ * Implements `IPositionSource`, `ISeekable`, and `IContainerProvider`.
8627
+ *
8628
+ * @example
8629
+ * ```typescript
8630
+ * const source = new VideoPositionSource({
8631
+ * selector: '#video-container',
8632
+ * sources: [
8633
+ * { src: 'video.mp4', type: 'video/mp4' },
8634
+ * { src: 'video.webm', type: 'video/webm' },
8635
+ * ],
8636
+ * });
8637
+ *
8638
+ * await source.init();
8639
+ *
8640
+ * source.onPosition((position) => {
8641
+ * console.log(`Video at ${position}s`);
8642
+ * });
8643
+ *
8644
+ * source.onContainerReady(() => {
8645
+ * console.log('Video ready for display');
8646
+ * });
8647
+ *
8648
+ * await source.activate();
8649
+ * ```
8650
+ */
8651
+ var VideoPositionSource = class extends BasePositionSource {
8652
+ _config;
8653
+ _player = null;
8654
+ _videoElementId;
8655
+ _containerReadyCallbacks = [];
8656
+ _eventHandlers = [];
8657
+ /**
8658
+ * Create a new video.js-based position source.
8659
+ *
8660
+ * @param config - Configuration options
8661
+ */
8662
+ constructor(config) {
8663
+ super(0);
8664
+ this._config = config;
8665
+ this._videoElementId = `video-${crypto.randomUUID?.() ?? Math.random().toString(36).slice(2)}`;
8666
+ }
8667
+ doInit() {
8668
+ return new Promise((resolve) => {
8669
+ this._createVideoElement();
8670
+ setTimeout(() => {
8671
+ this._player = videojs(this._videoElementId, {
8672
+ controls: false,
8673
+ controlBar: false,
8674
+ liveui: false,
8675
+ autoplay: false,
8676
+ preload: "auto",
8677
+ loop: this.loop,
8678
+ sources: this._config.sources,
8679
+ ...this._config.options
8680
+ }, () => {
8681
+ if (this._player) {
8682
+ this._addPlayerListener("timeupdate", this._handleTimeUpdate.bind(this));
8683
+ this._addPlayerListener("ended", this._handleEnded.bind(this));
8684
+ this._player.one("firstplay", () => {
8685
+ this._notifyContainerReady();
8686
+ });
8687
+ this._player.one("canplay", () => {
8688
+ resolve();
8689
+ });
8690
+ this._player.load();
8691
+ }
8692
+ });
8693
+ }, 0);
8694
+ });
8695
+ }
8696
+ doDestroy() {
8697
+ for (const removeHandler of this._eventHandlers) removeHandler();
8698
+ this._eventHandlers.length = 0;
8699
+ if (this._player) {
8700
+ this._player.dispose?.();
8701
+ this._player = null;
8702
+ }
8703
+ $(`#${this._videoElementId}`).remove();
8704
+ }
8705
+ startTicking() {
8706
+ this._player?.play();
8707
+ }
8708
+ stopTicking() {
8709
+ this._player?.pause();
8710
+ }
8711
+ /**
8712
+ * Seek to a specific position in the video.
8713
+ *
8714
+ * @param position - Target position in seconds
8715
+ * @returns Actual position after seek
8716
+ */
8717
+ async seek(position) {
8718
+ if (!this._player) return this.getPosition();
8719
+ return new Promise((resolve) => {
8720
+ this._player.one("seeked", () => {
8721
+ const actualPosition = this._player?.currentTime() ?? 0;
8722
+ this.setPosition(actualPosition);
8723
+ resolve(actualPosition);
8724
+ });
8725
+ this._player.currentTime(position);
8726
+ });
8727
+ }
8728
+ /**
8729
+ * Get the container element.
8730
+ *
8731
+ * @returns jQuery-wrapped container element
8732
+ */
8733
+ getContainer() {
8734
+ return $(this._config.selector);
8735
+ }
8736
+ /**
8737
+ * Register a callback for when the container is ready.
8738
+ *
8739
+ * @param callback - Function called when container is ready
8740
+ */
8741
+ onContainerReady(callback) {
8742
+ this._containerReadyCallbacks.push(callback);
8743
+ }
8744
+ /**
8745
+ * Get the video duration.
8746
+ *
8747
+ * @returns Duration in seconds from video.js player
8748
+ */
8749
+ getDuration() {
8750
+ return this._player?.duration() ?? 0;
8751
+ }
8752
+ /**
8753
+ * Deactivate the source and reset position.
8754
+ *
8755
+ * Overrides base to also reset video currentTime.
8756
+ */
8757
+ deactivate() {
8758
+ if (this.state === "inactive") return;
8759
+ if (this.state === "active") this.stopTicking();
8760
+ this._player?.currentTime(0);
8761
+ super.deactivate();
8762
+ }
8763
+ /**
8764
+ * Create the video element in the container.
8765
+ */
8766
+ _createVideoElement() {
8767
+ const $container = $(this._config.selector);
8768
+ const videoHtml = `<video id="${this._videoElementId}" class="video-js"></video>`;
8769
+ $container.append(videoHtml);
8770
+ }
8771
+ /**
8772
+ * Add an event listener to the player and track for cleanup.
8773
+ *
8774
+ * @param event - Event name
8775
+ * @param handler - Event handler
8776
+ */
8777
+ _addPlayerListener(event, handler) {
8778
+ if (this._player) {
8779
+ this._player.on(event, handler);
8780
+ this._eventHandlers.push(() => {
8781
+ this._player?.off(event, handler);
8782
+ });
8783
+ }
8784
+ }
8785
+ /**
8786
+ * Handle timeupdate event from video.js.
8787
+ */
8788
+ _handleTimeUpdate() {
8789
+ if (this.state !== "active" || !this._player) return;
8790
+ const currentTime = this._player.currentTime();
8791
+ if (currentTime !== void 0) this.setPosition(currentTime);
8792
+ }
8793
+ /**
8794
+ * Handle ended event from video.js.
8795
+ */
8796
+ _handleEnded() {
8797
+ if (this.state !== "active") return;
8798
+ this.emitBoundary("end");
8799
+ if (this.loop) {
8800
+ this._player?.currentTime(0);
8801
+ this.setPosition(0);
8802
+ this.emitBoundary("start");
8803
+ this._player?.play();
8804
+ } else this.deactivate();
8805
+ }
8806
+ /**
8807
+ * Notify all container ready callbacks.
8808
+ */
8809
+ _notifyContainerReady() {
8810
+ for (const callback of this._containerReadyCallbacks) callback();
8811
+ }
8812
+ };
8813
+
8814
+ //#endregion
8815
+ //#region src/timelineproviders/container-providers/dom-container-provider.ts
8816
+ /**
8817
+ * DOM selector-based container provider.
8818
+ *
8819
+ * Provides access to a DOM container element via a CSS selector.
8820
+ * Implements `IContainerProvider` for use with position sources that
8821
+ * don't have an intrinsic container (e.g., RAF-based sources, WebSocket sources).
8822
+ *
8823
+ * @example
8824
+ * ```typescript
8825
+ * const containerProvider = new DomContainerProvider({
8826
+ * selector: '#timeline-container',
8827
+ * });
8828
+ *
8829
+ * containerProvider.onContainerReady(() => {
8830
+ * const $container = containerProvider.getContainer();
8831
+ * $container?.append('<div class="content">Ready!</div>');
8832
+ * });
8833
+ *
8834
+ * await containerProvider.init();
8835
+ * ```
8836
+ */
8837
+ var DomContainerProvider = class {
8838
+ _config;
8839
+ _container;
8840
+ _isReady = false;
8841
+ _isDestroyed = false;
8842
+ _readyCallbacks = [];
8843
+ /**
8844
+ * Create a new DOM container provider.
8845
+ *
8846
+ * @param config - Configuration options
8847
+ */
8848
+ constructor(config) {
8849
+ this._config = config;
8850
+ }
8851
+ /**
8852
+ * Initialize the container provider.
8853
+ *
8854
+ * Looks up the container element using the configured selector.
8855
+ *
8856
+ * @throws Error if the element is not found
8857
+ */
8858
+ async init() {
8859
+ if (this._isReady) return;
8860
+ const $element = $(this._config.selector);
8861
+ if ($element.length === 0) throw new Error(`Container element not found: ${this._config.selector}`);
8862
+ this._container = $element;
8863
+ this._isReady = true;
8864
+ this._notifyReady();
8865
+ }
8866
+ /**
8867
+ * Destroy the container provider and release resources.
8868
+ */
8869
+ destroy() {
8870
+ this._container = void 0;
8871
+ this._isReady = false;
8872
+ this._isDestroyed = true;
8873
+ this._readyCallbacks.length = 0;
8874
+ }
8875
+ /**
8876
+ * Get the container element.
8877
+ *
8878
+ * @returns jQuery-wrapped container element, or `undefined` if not initialized
8879
+ */
8880
+ getContainer() {
8881
+ return this._container;
8882
+ }
8883
+ /**
8884
+ * Register a callback for when the container is ready.
8885
+ *
8886
+ * If the container is already ready, the callback is invoked immediately.
8887
+ *
8888
+ * @param callback - Function called when container is ready
8889
+ */
8890
+ onContainerReady(callback) {
8891
+ if (this._isDestroyed) return;
8892
+ if (this._isReady) callback();
8893
+ else this._readyCallbacks.push(callback);
8894
+ }
8895
+ /**
8896
+ * Notify all registered ready callbacks.
8897
+ */
8898
+ _notifyReady() {
8899
+ for (const callback of this._readyCallbacks) callback();
8900
+ }
8901
+ };
8902
+
8903
+ //#endregion
8904
+ //#region src/timelineproviders/playlist/simple-playlist.ts
8905
+ /**
8906
+ * Simple playlist implementation.
8907
+ *
8908
+ * Manages a collection of timeline items and allows switching between them.
8909
+ * Implements `IPlaylist<TItem>` for use with timeline providers that
8910
+ * support multiple content sources.
8911
+ *
8912
+ * @typeParam TItem - Type of playlist items
8913
+ *
8914
+ * @example
8915
+ * ```typescript
8916
+ * interface VideoItem {
8917
+ * id: string;
8918
+ * uri: string;
8919
+ * title: string;
8920
+ * }
8921
+ *
8922
+ * const playlist = new SimplePlaylist<VideoItem>({
8923
+ * items: [
8924
+ * { id: 'intro', uri: '/videos/intro.mp4', title: 'Introduction' },
8925
+ * { id: 'ch1', uri: '/videos/chapter-1.mp4', title: 'Chapter 1' },
8926
+ * ],
8927
+ * identifierKey: 'id',
8928
+ * });
8929
+ *
8930
+ * playlist.onItemChange((item) => {
8931
+ * console.log(`Now playing: ${item.title}`);
8932
+ * });
8933
+ *
8934
+ * playlist.selectItem('ch1');
8935
+ * ```
8936
+ */
8937
+ var SimplePlaylist = class {
8938
+ _items;
8939
+ _identifierKey;
8940
+ _currentIndex = 0;
8941
+ _changeCallbacks = [];
8942
+ /**
8943
+ * Create a new simple playlist.
8944
+ *
8945
+ * @param config - Configuration options
8946
+ * @throws Error if items array is empty
8947
+ */
8948
+ constructor(config) {
8949
+ if (!config.items || config.items.length === 0) throw new Error("Playlist must have at least one item");
8950
+ this._items = Object.freeze([...config.items]);
8951
+ this._identifierKey = config.identifierKey;
8952
+ }
8953
+ /**
8954
+ * Get the currently active item.
8955
+ */
8956
+ get currentItem() {
8957
+ return this._items[this._currentIndex];
8958
+ }
8959
+ /**
8960
+ * Get all items in the playlist.
8961
+ *
8962
+ * Returns a readonly array to prevent external modification.
8963
+ */
8964
+ get items() {
8965
+ return this._items;
8966
+ }
8967
+ /**
8968
+ * Select an item by identifier.
8969
+ *
8970
+ * Looks up the item using the configured identifier key and switches
8971
+ * to it if found. Triggers item change callbacks if the selection changes.
8972
+ *
8973
+ * @param identifier - Unique identifier for the item
8974
+ * @throws Error if no item matches the identifier
8975
+ */
8976
+ selectItem(identifier) {
8977
+ const index = this._items.findIndex((item) => String(item[this._identifierKey]) === identifier);
8978
+ if (index === -1) throw new Error(`Playlist item not found: ${identifier}`);
8979
+ if (index !== this._currentIndex) {
8980
+ this._currentIndex = index;
8981
+ this._notifyChange();
8982
+ }
8983
+ }
8984
+ /**
8985
+ * Register a callback for item changes.
8986
+ *
8987
+ * Called whenever the current item changes via `selectItem()`.
8988
+ *
8989
+ * @param callback - Function receiving the new current item
8990
+ */
8991
+ onItemChange(callback) {
8992
+ this._changeCallbacks.push(callback);
8993
+ }
8994
+ /**
8995
+ * Notify all registered change callbacks.
8996
+ */
8997
+ _notifyChange() {
8998
+ const currentItem = this.currentItem;
8999
+ for (const callback of this._changeCallbacks) callback(currentItem);
9000
+ }
9001
+ };
9002
+
9003
+ //#endregion
9004
+ //#region src/timelineproviders/index.ts
9005
+ var timelineproviders_exports = /* @__PURE__ */ __export({
9006
+ BasePositionSource: () => BasePositionSource,
9007
+ DomContainerProvider: () => DomContainerProvider,
9008
+ RafPositionSource: () => RafPositionSource,
9009
+ ScrollPositionSource: () => ScrollPositionSource,
9010
+ SimplePlaylist: () => SimplePlaylist,
9011
+ VideoPositionSource: () => VideoPositionSource,
9012
+ isSeekable: () => isSeekable
9013
+ });
9014
+
9015
+ //#endregion
9016
+ //#region src/util/typed-event-emitter.ts
9017
+ /**
9018
+ * Type-safe event emitter implementation
9019
+ *
9020
+ * Features:
9021
+ * - Generic type parameter for event map
9022
+ * - Handler execution order preserved (registration order)
9023
+ * - Errors in handlers caught and logged (don't break other handlers)
9024
+ * - Copy handlers array during emit (safe removal during iteration)
9025
+ *
9026
+ * @example
9027
+ * ```typescript
9028
+ * interface MyEvents {
9029
+ * start: [];
9030
+ * data: [value: string];
9031
+ * progress: [current: number, total: number];
9032
+ * }
9033
+ *
9034
+ * const emitter = new TypedEventEmitter<MyEvents>();
9035
+ *
9036
+ * const unsubscribe = emitter.on('data', (value) => {
9037
+ * console.log('Received:', value);
9038
+ * });
9039
+ *
9040
+ * emitter.emit('data', 'hello');
9041
+ * unsubscribe();
9042
+ * ```
9043
+ */
9044
+ var TypedEventEmitter = class {
9045
+ handlers = /* @__PURE__ */ new Map();
9046
+ /**
9047
+ * Subscribe to an event
9048
+ * @param event - Event name
9049
+ * @param handler - Event handler
9050
+ * @returns Unsubscribe function
9051
+ */
9052
+ on(event, handler) {
9053
+ if (!this.handlers.has(event)) this.handlers.set(event, []);
9054
+ this.handlers.get(event).push(handler);
9055
+ return () => this.off(event, handler);
9056
+ }
9057
+ /**
9058
+ * Subscribe to an event for one-time execution
9059
+ * @param event - Event name
9060
+ * @param handler - Event handler
9061
+ * @returns Unsubscribe function
9062
+ */
9063
+ once(event, handler) {
9064
+ const onceHandler = (...args) => {
9065
+ this.off(event, onceHandler);
9066
+ handler(...args);
9067
+ };
9068
+ return this.on(event, onceHandler);
9069
+ }
9070
+ /**
9071
+ * Unsubscribe from an event
9072
+ * @param event - Event name
9073
+ * @param handler - Event handler to remove
9074
+ */
9075
+ off(event, handler) {
9076
+ const eventHandlers = this.handlers.get(event);
9077
+ if (!eventHandlers) return;
9078
+ const index = eventHandlers.indexOf(handler);
9079
+ if (index !== -1) eventHandlers.splice(index, 1);
9080
+ }
9081
+ /**
9082
+ * Emit an event to all subscribers
9083
+ *
9084
+ * Features:
9085
+ * - Copies handlers array to allow safe removal during iteration
9086
+ * - Isolates errors - one failing handler doesn't break others
9087
+ * - Logs errors to console for debugging
9088
+ *
9089
+ * @param event - Event name
9090
+ * @param args - Event arguments
9091
+ */
9092
+ emit(event, ...args) {
9093
+ const eventHandlers = this.handlers.get(event);
9094
+ if (!eventHandlers || eventHandlers.length === 0) return;
9095
+ const handlersCopy = [...eventHandlers];
9096
+ for (const handler of handlersCopy) try {
9097
+ handler(...args);
9098
+ } catch (error) {
9099
+ console.error(`Error in event handler for "${String(event)}":`, error);
9100
+ }
9101
+ }
9102
+ /**
9103
+ * Remove all listeners for a specific event or all events
9104
+ * @param event - Optional event name. If not provided, removes all listeners.
9105
+ */
9106
+ removeAllListeners(event) {
9107
+ if (event !== void 0) this.handlers.delete(event);
9108
+ else this.handlers.clear();
9109
+ }
9110
+ };
9111
+
9112
+ //#endregion
9113
+ //#region src/eligius-engine.ts
9114
+ /**
9115
+ * Type guard to check if a position source supports seeking.
9116
+ */
9117
+ function isSeekable$1(source) {
9118
+ return "seek" in source && typeof source.seek === "function";
9119
+ }
9120
+ /**
9121
+ * Maps position source state to engine play state.
9122
+ */
9123
+ function mapSourceStateToPlayState(sourceState) {
9124
+ switch (sourceState) {
9125
+ case "active": return "playing";
9126
+ case "suspended": return "paused";
9127
+ case "inactive": return "stopped";
9128
+ }
9129
+ }
9130
+ /**
9131
+ * The Eligius timeline engine with explicit, testable API.
9132
+ *
9133
+ * This engine is responsible for starting and stopping the given timeline provider
9134
+ * and triggering the actions associated with positions along the timeline.
9135
+ */
9136
+ var EligiusEngine = class EligiusEngine {
9137
+ _timeLineActionsLookup = {};
9138
+ _timelineLookupCache = /* @__PURE__ */ new Map();
9139
+ _eventbusRemovers = [];
9140
+ _currentTimelineUri = "";
9141
+ _activePositionSource = void 0;
9142
+ _activeContainerProvider = void 0;
9143
+ _activePlaylist = void 0;
9144
+ _lastPosition = -1;
9145
+ _emitter = new TypedEventEmitter();
9146
+ /** Current timeline position in seconds (supports fractional values) */
9147
+ get position() {
9148
+ return this._activePositionSource?.getPosition() ?? 0;
9149
+ }
9150
+ /** Timeline duration in seconds, undefined if not yet available */
9151
+ get duration() {
9152
+ return this._activePositionSource?.getDuration();
9153
+ }
9154
+ /** Current playback state (derived from position source state) */
9155
+ get playState() {
9156
+ if (!this._activePositionSource) return "stopped";
9157
+ return mapSourceStateToPlayState(this._activePositionSource.state);
9158
+ }
9159
+ /** URI of the currently active timeline */
9160
+ get currentTimelineUri() {
9161
+ return this._currentTimelineUri;
9162
+ }
9163
+ /** Container element for the active timeline provider */
9164
+ get container() {
9165
+ return this._activeContainerProvider?.getContainer();
9166
+ }
9167
+ /** Root element of the engine (container selector) */
9168
+ get engineRoot() {
9169
+ return $(this.configuration.containerSelector);
9170
+ }
9171
+ constructor(configuration, eventbus$1, timelineProviders, languageManager) {
9172
+ this.configuration = configuration;
9173
+ this.eventbus = eventbus$1;
9174
+ this.timelineProviders = timelineProviders;
9175
+ this.languageManager = languageManager;
9176
+ }
9177
+ /**
9178
+ * Subscribe to engine events
9179
+ * @param event - Event name
9180
+ * @param handler - Event handler
9181
+ * @returns Unsubscribe function
9182
+ */
9183
+ on(event, handler) {
9184
+ return this._emitter.on(event, handler);
9185
+ }
9186
+ /**
9187
+ * Start playback
9188
+ * @throws If autoplay is blocked (video provider)
9189
+ */
9190
+ async start() {
9191
+ if (!this._activePositionSource) return;
9192
+ await this._activePositionSource.activate();
9193
+ this._emitter.emit("start");
9194
+ this.eventbus.broadcast("timeline-play", []);
9195
+ }
9196
+ /**
9197
+ * Pause playback
9198
+ */
9199
+ pause() {
9200
+ if (!this._activePositionSource) return;
9201
+ this._activePositionSource.suspend();
9202
+ this._emitter.emit("pause");
9203
+ this.eventbus.broadcast("timeline-pause", []);
9204
+ }
9205
+ /**
9206
+ * Stop playback and reset to beginning
9207
+ */
9208
+ stop() {
9209
+ if (!this._activePositionSource) return;
9210
+ this._activePositionSource.deactivate();
9211
+ this._emitter.emit("stop");
9212
+ this.eventbus.broadcast("timeline-stop", []);
9213
+ }
9214
+ /**
9215
+ * Seek to a specific position
9216
+ * @param position - Target position in seconds
9217
+ * @returns Actual position after seek
9218
+ */
9219
+ async seek(position) {
9220
+ if (!this._activePositionSource) return 0;
9221
+ const seekPosition = position;
9222
+ const duration = this._activePositionSource.getDuration();
9223
+ const currentPosition = this._activePositionSource.getPosition();
9224
+ if (seekPosition < 0 || seekPosition > duration) return currentPosition;
9225
+ this._emitter.emit("seekStart", seekPosition, currentPosition, duration);
9226
+ this.eventbus.broadcast("timeline-seek", [
9227
+ seekPosition,
9228
+ currentPosition,
9229
+ duration
9230
+ ]);
9231
+ if (isSeekable$1(this._activePositionSource)) await this._activePositionSource.seek(seekPosition);
9232
+ await this._executeSeekActions(seekPosition);
9233
+ const finalPosition = this._activePositionSource.getPosition();
9234
+ this._emitter.emit("seekComplete", finalPosition, duration);
9235
+ this.eventbus.broadcast("timeline-seeked", [finalPosition, duration]);
9236
+ this._emitter.emit("time", finalPosition);
9237
+ this.eventbus.broadcast("timeline-time", [finalPosition]);
9238
+ if (this._activePositionSource.state === "active") await this._activePositionSource.activate();
9239
+ return finalPosition;
9240
+ }
9241
+ /**
9242
+ * Switch to a different timeline
9243
+ * @param uri - Timeline URI to switch to
9244
+ * @param position - Optional starting position
9245
+ */
9246
+ async switchTimeline(uri, position = 0) {
9247
+ if (!this._activePositionSource) return;
9248
+ const timelineConfig = this._timelineLookupCache.get(uri);
9249
+ if (!timelineConfig || this._currentTimelineUri === timelineConfig.uri) return;
9250
+ this._activePositionSource.deactivate();
9251
+ await this._cleanUpTimeline();
9252
+ this._currentTimelineUri = timelineConfig.uri;
9253
+ this._emitter.emit("timelineChange", this._currentTimelineUri);
9254
+ this.eventbus.broadcast("timeline-current-timeline-change", [this._currentTimelineUri]);
9255
+ const newProviderSettings = this.timelineProviders[timelineConfig.type];
9256
+ if (this._activePositionSource !== newProviderSettings.positionSource) {
9257
+ this._activePositionSource.destroy();
9258
+ this._activePositionSource = newProviderSettings.positionSource;
9259
+ this._activeContainerProvider = newProviderSettings.containerProvider;
9260
+ this._activePlaylist = newProviderSettings.playlist;
9261
+ }
9262
+ this._activePositionSource.loop = timelineConfig.loop;
9263
+ if (!this._activePositionSource.loop && position > 0) this.eventbus.once("timeline-firstframe", async () => {
9264
+ if (!this._activePositionSource) return;
9265
+ this._activePositionSource.suspend();
9266
+ this.eventbus.broadcast("timeline-duration", [this._activePositionSource.getDuration]);
9267
+ await this._executeStartActions();
9268
+ if (isSeekable$1(this._activePositionSource)) await this._activePositionSource.seek(position);
9269
+ await this._executeSeekActions(position);
9270
+ });
9271
+ if (this._activePlaylist) this._activePlaylist.selectItem(uri);
9272
+ }
9273
+ /**
9274
+ * Initializes the engine by creating the HTML layout and the first time line
9275
+ * by executing its initActions.
9276
+ */
9277
+ init() {
9278
+ this._createLayoutTemplate();
9279
+ this._addEventbusListeners();
9280
+ const { timelines } = this.configuration;
9281
+ this._currentTimelineUri = timelines?.[0].uri ?? "";
9282
+ this._createTimelineLookup();
9283
+ return this._initializeTimelineProvider();
9284
+ }
9285
+ _createLayoutTemplate() {
9286
+ const { containerSelector } = this.configuration;
9287
+ const container = $(containerSelector);
9288
+ if (!container || !container.length) throw new Error(`Container selector not found: ${containerSelector}`);
9289
+ const { layoutTemplate } = this.configuration;
9290
+ if (layoutTemplate?.length) container.html(layoutTemplate);
9291
+ else console.warn("layoutTemplate is empty, unable to create layout");
9292
+ }
9293
+ async _initializeTimelineProvider() {
9294
+ if (!this.configuration.timelines?.length) throw new Error("No timelines present");
9295
+ const firstTimeline = this.configuration.timelines[0];
9296
+ const providerSettings = this.timelineProviders[firstTimeline.type];
9297
+ if (!providerSettings) throw new Error(`No timeline provider configured for type ${firstTimeline.type}`);
9298
+ this._activePositionSource?.destroy();
9299
+ this._activePositionSource = providerSettings.positionSource;
9300
+ this._activeContainerProvider = providerSettings.containerProvider;
9301
+ this._activePlaylist = providerSettings.playlist;
9302
+ if (!this._activePositionSource) throw new Error("NO ACTIVE POSITION SOURCE");
9303
+ this._activePositionSource.onPosition(this._onTimeHandler.bind(this, (x) => x));
9304
+ this._activePositionSource.onBoundaryReached((boundary) => {
9305
+ if (boundary === "end") this._onCompleteCallback();
9306
+ else if (boundary === "start") this._onRestartCallback();
9307
+ });
9308
+ this._activePositionSource.onActivated(this._onFirstFrameCallback.bind(this));
9309
+ await this._activePositionSource.init();
9310
+ await this._executeActions(this.configuration.initActions, "start");
9311
+ this._emitter.emit("initialized");
9312
+ return this._activePositionSource;
9313
+ }
9314
+ _onCompleteCallback() {
9315
+ this._emitter.emit("timelineComplete");
9316
+ this.eventbus.broadcast("timeline-complete", []);
9317
+ }
9318
+ _onFirstFrameCallback() {
9319
+ this._emitter.emit("timelineFirstFrame");
9320
+ this.eventbus.broadcast("timeline-firstframe", []);
9321
+ const duration = this._activePositionSource?.getDuration();
9322
+ if (duration !== void 0) this._emitter.emit("duration", duration);
9323
+ this.eventbus.broadcast("timeline-duration", [this._activePositionSource?.getDuration]);
9324
+ }
9325
+ _onRestartCallback() {
9326
+ this._emitter.emit("timelineRestart");
9327
+ this.eventbus.broadcast("timeline-restart", []);
9328
+ }
9329
+ async _cleanUp() {
9330
+ await this._cleanUpTimeline();
9331
+ await this._executeActions([...this.configuration.initActions].reverse(), "end");
9332
+ }
9333
+ /**
9334
+ * Cleans up all the necessary parts that the engine initialized.
9335
+ * - It ends the currently active operations and the init actions.
9336
+ * - It removes all its eventbus listeners, handlers and interceptors.
9337
+ * - It destroys all of its timeline providers
9338
+ * - It empties the HTML element indicated by the containerSelector configuration property.
9339
+ *
9340
+ */
9341
+ async destroy() {
9342
+ await this._cleanUp();
9343
+ this.languageManager.destroy();
9344
+ this._activePositionSource = void 0;
9345
+ this._activeContainerProvider = void 0;
9346
+ this._activePlaylist = void 0;
9347
+ this._eventbusRemovers.forEach((remover) => remover());
9348
+ if (this.timelineProviders) Object.values(this.timelineProviders).forEach((providerInfo) => providerInfo.positionSource.destroy());
9349
+ const { containerSelector } = this.configuration;
9350
+ $(containerSelector).empty();
9351
+ this._emitter.emit("destroyed");
9352
+ this._emitter.removeAllListeners();
9353
+ }
9354
+ _addEventListener(eventName, eventHandler, eventTopic) {
9355
+ this._eventbusRemovers.push(this.eventbus.on(eventName, eventHandler, eventTopic));
9356
+ }
9357
+ _addEventbusListeners() {
8273
9358
  this._addEventListener("request-engine-root", this._handleRequestEngineRoot.bind(this, this.configuration.containerSelector));
8274
9359
  this._addEventListener("request-timeline-uri", this._handleRequestTimelineUri.bind(this));
8275
- this._addEventListener("request-current-timeline-position", this._handleRequestTimelinePosition.bind(this, Math.floor));
9360
+ this._addEventListener("request-current-timeline-position", this._handleRequestTimelinePosition.bind(this, (x) => x));
8276
9361
  this._addEventListener("request-timeline-cleanup", this._handleTimelineComplete.bind(this));
8277
9362
  this._addEventListener("timeline-request-current-timeline", this._requestCurrentTimeline.bind(this));
8278
9363
  this._addEventListener("timeline-play-toggle-request", this._toggleplay.bind(this));
8279
9364
  this._addEventListener("timeline-play-request", this._playRequest.bind(this));
8280
9365
  this._addEventListener("timeline-stop-request", this._stopRequest.bind(this));
8281
9366
  this._addEventListener("timeline-pause-request", this._pauseRequest.bind(this));
8282
- this._addEventListener("timeline-container-request", this.containerRequest.bind(this));
8283
- this._addEventListener("timeline-duration-request", this.durationRequest.bind(this));
8284
- this._addEventListener("timeline-seek-request", this.seekRequest.bind(this));
8285
- }
8286
- async seekRequest(position) {
8287
- if (!this._activeTimelineProvider) return;
8288
- const seekPosition = Math.floor(position);
8289
- const duration = this._activeTimelineProvider.getDuration();
8290
- const currentPosition = this._activeTimelineProvider.getPosition();
8291
- if (seekPosition < 0 || seekPosition > duration) return;
8292
- this.eventbus.broadcast("timeline-seek", [
8293
- seekPosition,
8294
- currentPosition,
8295
- duration
8296
- ]);
8297
- await this._activeTimelineProvider.seek(seekPosition);
8298
- await this._executeSeekActions(seekPosition);
8299
- this.eventbus.broadcast("timeline-seeked", [this._activeTimelineProvider.getPosition(), duration]);
8300
- this.eventbus.broadcast("timeline-time", [this._activeTimelineProvider.getPosition()]);
8301
- if (this._activeTimelineProvider?.playState === "running") this._activeTimelineProvider?.start();
9367
+ this._addEventListener("timeline-container-request", this._containerRequest.bind(this));
9368
+ this._addEventListener("timeline-duration-request", this._durationRequest.bind(this));
9369
+ this._addEventListener("timeline-seek-request", this._seekRequest.bind(this));
9370
+ }
9371
+ async _seekRequest(position) {
9372
+ await this.seek(position);
8302
9373
  }
8303
- durationRequest(callBack) {
8304
- callBack(this._activeTimelineProvider?.getDuration());
9374
+ _durationRequest(callBack) {
9375
+ callBack(this.duration);
8305
9376
  }
8306
- containerRequest(callBack) {
8307
- callBack(this._activeTimelineProvider?.getContainer());
9377
+ _containerRequest(callBack) {
9378
+ callBack(this.container);
8308
9379
  }
8309
9380
  _pauseRequest() {
8310
- if (!this._activeTimelineProvider) return;
8311
- this._activeTimelineProvider.pause();
8312
- this.eventbus.broadcast("timeline-pause", []);
9381
+ this.pause();
8313
9382
  }
8314
9383
  _stopRequest() {
8315
- if (!this._activeTimelineProvider) return;
8316
- this._activeTimelineProvider.stop();
8317
- this.eventbus.broadcast("timeline-stop", []);
9384
+ this.stop();
8318
9385
  }
8319
- _playRequest() {
8320
- if (!this._activeTimelineProvider) return;
8321
- this._activeTimelineProvider.start();
8322
- this.eventbus.broadcast("timeline-play", []);
9386
+ async _playRequest() {
9387
+ await this.start();
8323
9388
  }
8324
- _toggleplay() {
8325
- if (!this._activeTimelineProvider) return;
8326
- if (this._activeTimelineProvider.playState === "running") this._activeTimelineProvider.pause();
8327
- else this._activeTimelineProvider.start();
9389
+ async _toggleplay() {
9390
+ if (this._activePositionSource?.state === "active") this.pause();
9391
+ else await this.start();
8328
9392
  }
8329
9393
  _createTimelineLookup() {
8330
9394
  if (!this.configuration.timelines) return;
@@ -8391,28 +9455,7 @@ var EligiusEngine = class EligiusEngine {
8391
9455
  resultCallback($(engineRootSelector));
8392
9456
  }
8393
9457
  async _handleRequestTimelineUri(uri, position = 0) {
8394
- if (!this._activeTimelineProvider) return;
8395
- this._activeTimelineProvider.stop();
8396
- await this._cleanUpTimeline();
8397
- const timelineConfig = this._timelineLookupCache.get(uri);
8398
- if (!timelineConfig || !this._activeTimelineProvider || this._currentTimelineUri === timelineConfig.uri) return;
8399
- this._currentTimelineUri = timelineConfig.uri;
8400
- this.eventbus.broadcast("timeline-current-timeline-change", [this._currentTimelineUri]);
8401
- const newProviderSettings = this.timelineProviders[timelineConfig.type];
8402
- if (this._activeTimelineProvider !== newProviderSettings.provider) {
8403
- this._activeTimelineProvider.destroy();
8404
- this._activeTimelineProvider = newProviderSettings.provider;
8405
- }
8406
- this._activeTimelineProvider.loop = timelineConfig.loop;
8407
- if (!this._activeTimelineProvider.loop && position > 0) this.eventbus.once("timeline-firstframe", async () => {
8408
- if (!this._activeTimelineProvider) return;
8409
- this._activeTimelineProvider.pause();
8410
- this.eventbus.broadcast("timeline-duration", [this._activeTimelineProvider.getDuration]);
8411
- await this._executeStartActions();
8412
- const seekPosition = await this._activeTimelineProvider.seek(position);
8413
- this.seekRequest(seekPosition);
8414
- });
8415
- this._activeTimelineProvider.playlistItem(uri);
9458
+ await this.switchTimeline(uri, position);
8416
9459
  }
8417
9460
  _cleanUpTimeline() {
8418
9461
  return this._executeRelevantActions(this._getActiveActions, "end");
@@ -8439,7 +9482,7 @@ var EligiusEngine = class EligiusEngine {
8439
9482
  return this._executeActions(currentActions, executionType);
8440
9483
  }
8441
9484
  _handleRequestTimelinePosition(floor, resultCallback) {
8442
- resultCallback(floor(this._activeTimelineProvider?.getPosition() || -1));
9485
+ resultCallback(floor(this._activePositionSource?.getPosition() || -1));
8443
9486
  }
8444
9487
  _handleTimelineComplete() {
8445
9488
  this._cleanUpTimeline();
@@ -8458,6 +9501,7 @@ var EligiusEngine = class EligiusEngine {
8458
9501
  const pos = floor(position);
8459
9502
  if (this._lastPosition !== pos) {
8460
9503
  this._executeActionsForPosition(pos);
9504
+ this._emitter.emit("time", pos);
8461
9505
  this.eventbus.broadcast("timeline-time", [pos]);
8462
9506
  }
8463
9507
  }
@@ -8469,23 +9513,16 @@ var EligiusEngine = class EligiusEngine {
8469
9513
  }
8470
9514
  async _executeSeekActions(position) {
8471
9515
  const timelineActions = this._getTimelineActionsForCurrentTimeline();
8472
- if (!timelineActions) return Promise.resolve();
8473
9516
  const currentActions = this._getActiveActions(timelineActions).filter((action) => !(action.duration.start <= position && action.duration.end >= position));
8474
9517
  const newActions = this._getActionsForPosition(position, timelineActions);
8475
9518
  await this._executeActions(currentActions, "end");
8476
- return this._executeActions(newActions, "start");
9519
+ await this._executeActions(newActions, "start");
8477
9520
  }
8478
9521
  };
8479
- const sortActionsHighestStartPositionFirst = (a, b) => {
8480
- if (b.duration.start < a.duration.start) return -1;
8481
- else if (b.duration.start > a.duration.start) return 1;
8482
- else return 0;
8483
- };
9522
+ const sortActionsHighestStartPositionFirst = (a, b) => b.duration.start - a.duration.start;
8484
9523
  const sortActionMethodsHighestStartPositionFirst = (a, b) => {
8485
- if (b.startPosition === void 0 || a.startPosition === void 0) return 0;
8486
- if (b.startPosition < a.startPosition) return -1;
8487
- else if (b.startPosition > a.startPosition) return 1;
8488
- else return 0;
9524
+ if (a.startPosition === void 0 || b.startPosition === void 0) return 0;
9525
+ return b.startPosition - a.startPosition;
8489
9526
  };
8490
9527
 
8491
9528
  //#endregion
@@ -8524,56 +9561,73 @@ function setGlobal(name, value) {
8524
9561
  //#endregion
8525
9562
  //#region src/language-manager.ts
8526
9563
  /**
8527
- * This class manages the labels for an {@link IEligiusEngine} instance.
9564
+ * Manages multi-language labels with explicit, testable API.
8528
9565
  *
8529
- * It handles the request-label-collection, request-label-collections, request-current-language and language-change events.
9566
+ * This class manages the labels for an {@link IEligiusEngine} instance.
9567
+ * It provides a pure API for language management and emits events for language changes.
8530
9568
  *
9569
+ * Eventbus integration is handled by LanguageEventbusAdapter.
8531
9570
  */
8532
9571
  var LanguageManager = class {
8533
9572
  _labelLookup;
8534
- _eventbusRemovers = [];
8535
- constructor(_currentLanguage, labels, _eventbus) {
9573
+ _emitter = new TypedEventEmitter();
9574
+ _availableLanguages = [];
9575
+ /** Current language code (e.g., 'en-US', 'nl-NL') */
9576
+ get language() {
9577
+ return this._currentLanguage;
9578
+ }
9579
+ /** List of available language codes, derived from unique languages in label collections */
9580
+ get availableLanguages() {
9581
+ return this._availableLanguages;
9582
+ }
9583
+ constructor(_currentLanguage, labels) {
8536
9584
  this._currentLanguage = _currentLanguage;
8537
- this._eventbus = _eventbus;
8538
9585
  if (!_currentLanguage) throw new Error("language ctor arg cannot have zero length");
8539
9586
  setGlobal("defaultLanguage", _currentLanguage);
8540
- this._setRootElementLang(_currentLanguage);
8541
9587
  this._labelLookup = this._createLabelLookup(labels);
8542
- this._addEventbusListeners(_eventbus);
8543
- }
8544
- destroy() {
8545
- this._eventbusRemovers.forEach((x) => x());
8546
- }
8547
- _addEventbusListeners(eventbus$1) {
8548
- this._eventbusRemovers.push(eventbus$1.on("request-label-collection", this._handleRequestLabelCollection.bind(this)));
8549
- this._eventbusRemovers.push(eventbus$1.on("request-label-collections", this._handleRequestLabelCollections.bind(this)));
8550
- this._eventbusRemovers.push(eventbus$1.on("request-current-language", this._handleRequestCurrentLanguage.bind(this)));
8551
- this._eventbusRemovers.push(eventbus$1.on("language-change", this._handleLanguageChange.bind(this)));
8552
- }
8553
- _handleRequestCurrentLanguage(resultCallback) {
8554
- resultCallback(this._currentLanguage);
8555
- }
8556
- _handleRequestLabelCollection(labelId, resultCallback) {
8557
- resultCallback(this._labelLookup[labelId]);
9588
+ this._availableLanguages = this._extractAvailableLanguages(labels);
8558
9589
  }
8559
- _handleRequestLabelCollections(labelIds, resultCallback) {
8560
- resultCallback(labelIds.map((labelId) => {
8561
- return this._labelLookup[labelId];
8562
- }));
9590
+ /**
9591
+ * Subscribe to language manager events
9592
+ * @param event - Event name
9593
+ * @param handler - Event handler
9594
+ * @returns Unsubscribe function
9595
+ */
9596
+ on(event, handler) {
9597
+ return this._emitter.on(event, handler);
8563
9598
  }
8564
- _handleLanguageChange(language) {
9599
+ /**
9600
+ * Change the current language
9601
+ * @param language - New language code
9602
+ * @throws If language code is empty or null
9603
+ */
9604
+ setLanguage(language) {
9605
+ if (!language || language.length === 0) throw new Error("Language cannot be empty");
9606
+ const previousLanguage = this._currentLanguage;
8565
9607
  this._currentLanguage = language;
8566
- this._setRootElementLang(this._currentLanguage);
9608
+ this._emitter.emit("change", language, previousLanguage);
8567
9609
  }
8568
- _setRootElementLang(language) {
8569
- const callBack = (rootSelector) => {
8570
- const lang = this._extractPrimaryLanguage(language);
8571
- $(rootSelector).attr("lang", lang);
8572
- };
8573
- this._eventbus.broadcast("request-engine-root", [callBack]);
9610
+ /**
9611
+ * Get a label collection by ID
9612
+ * @param collectionId - Label collection ID
9613
+ * @returns Label array or undefined if not found
9614
+ */
9615
+ getLabelCollection(collectionId) {
9616
+ return this._labelLookup[collectionId];
8574
9617
  }
8575
- _extractPrimaryLanguage(culture) {
8576
- return culture.split("-").shift();
9618
+ /**
9619
+ * Get multiple label collections by IDs
9620
+ * @param collectionIds - Array of label collection IDs
9621
+ * @returns Array of label arrays (undefined for not found collections)
9622
+ */
9623
+ getLabelCollections(collectionIds) {
9624
+ return collectionIds.map((id) => this._labelLookup[id]);
9625
+ }
9626
+ /**
9627
+ * Clean up resources
9628
+ */
9629
+ destroy() {
9630
+ this._emitter.removeAllListeners();
8577
9631
  }
8578
9632
  _createLabelLookup(labels) {
8579
9633
  return labels.reduce((acc, label) => {
@@ -8581,11 +9635,15 @@ var LanguageManager = class {
8581
9635
  return acc;
8582
9636
  }, {});
8583
9637
  }
9638
+ _extractAvailableLanguages(labels) {
9639
+ const languages = /* @__PURE__ */ new Set();
9640
+ for (const labelCollection of labels) for (const label of labelCollection.labels) languages.add(label.languageCode);
9641
+ return Array.from(languages);
9642
+ }
8584
9643
  };
8585
9644
 
8586
9645
  //#endregion
8587
9646
  //#region src/engine-factory.ts
8588
- const hotkeys = hk.default || hk;
8589
9647
  /**
8590
9648
  * The EngineFactory is used to create and initialize an {@link IEligiusEngine} instance.
8591
9649
  *
@@ -8593,12 +9651,12 @@ const hotkeys = hk.default || hk;
8593
9651
  *
8594
9652
  * @example Loading a configuration and creating an IEligiusEngine instance
8595
9653
  * ```ts
8596
- * import { IEngineConfiguration, EngineFactory, WebpackResourceImporter } from 'eligius';
9654
+ * import { IEngineConfiguration, EngineFactory, EligiusResourceImporter } from 'eligius';
8597
9655
  * import * as engineConfig from './my-eligius-config.json';
8598
9656
  *
8599
- * const factory = new EngineFactory(new WebpackResourceImporter(), window);
9657
+ * const factory = new EngineFactory(new EligiusResourceImporter(), window);
8600
9658
  *
8601
- * const engine = factory.createEngine((engineConfig as unknown) as IEngineConfiguration);
9659
+ * const { engine } = factory.createEngine((engineConfig as unknown) as IEngineConfiguration);
8602
9660
  *
8603
9661
  * engine.init().then(()=> {console.log('Eligius engine ready for business');});
8604
9662
  * ```
@@ -8608,94 +9666,58 @@ var EngineFactory = class {
8608
9666
  _eventbus;
8609
9667
  _eventRemovers = [];
8610
9668
  _importer;
8611
- _resizeTimeout = -1;
9669
+ _windowRef;
8612
9670
  constructor(importer, windowRef, options) {
8613
9671
  this._importer = importer;
9672
+ this._windowRef = windowRef;
8614
9673
  this._eventbus = options?.eventbus ?? new Eventbus();
8615
- Diagnostics.active = options?.devtools ?? false;
8616
- if (Diagnostics.active) this._initializeDevtools(this._eventbus);
8617
- this._eventRemovers.push(this._eventbus.on("request-instance", this._requestInstanceHandler.bind(this)));
8618
- this._eventRemovers.push(this._eventbus.on("request-action", this._requestActionHandler.bind(this)));
8619
- this._eventRemovers.push(this._eventbus.on("request-function", this._requestFunctionHandler.bind(this)));
8620
- const handleSpaceBound = this._handleSpacePress.bind(this);
8621
- hotkeys("space", handleSpaceBound);
8622
- this._eventRemovers.push(() => hotkeys.unbind("space", handleSpaceBound));
8623
- const resizeBound = this._resizeHandler.bind(this);
8624
- const jqWin = $(windowRef);
8625
- jqWin.on("resize", resizeBound);
8626
- this._eventRemovers.push(() => jqWin.off("resize", resizeBound));
8627
- }
8628
- _handleSpacePress(keyboardEvent, _hotkeysEvent) {
8629
- keyboardEvent.preventDefault();
8630
- this._eventbus.broadcast("timeline-play-toggle-request", []);
8631
- return false;
8632
- }
8633
- _initializeDevtools(eventbus$1) {
8634
- const diagnosticInfo = window[DEV_TOOLS_KEY];
8635
- if (diagnosticInfo) {
8636
- const { agent } = diagnosticInfo;
8637
- this._eventRemovers.push(eventbus$1.registerEventlistener(new DevToolEventListener(agent)));
8638
- this._eventRemovers.push(agent.subscribe((message) => {
8639
- if (message.type === "playcontrol") switch (message.data.kind) {
8640
- case "play":
8641
- this._eventbus.broadcast("timeline-play-request", []);
8642
- break;
8643
- case "stop":
8644
- this._eventbus.broadcast("timeline-stop-request", []);
8645
- break;
8646
- case "pause":
8647
- this._eventbus.broadcast("timeline-pause-request", []);
8648
- break;
8649
- case "seek":
8650
- this._eventbus.broadcast("timeline-seek-request", [message.data.args ?? 0]);
8651
- break;
8652
- }
8653
- }));
8654
- Diagnostics.send = (name, messageData) => {
8655
- const message = prepareValueForSerialization(messageData);
8656
- try {
8657
- agent.postMessage(name, message);
8658
- } catch (e) {
8659
- console.error("postmessage failed");
8660
- console.error(e);
8661
- console.log("message", message);
8662
- }
8663
- };
8664
- Diagnostics.send("eligius-diagnostics-factory", "Diagnostics initialized");
8665
- } else console.warn(`${DEV_TOOLS_KEY} property not found on window, please install the Eligius Devtools extension.`);
9674
+ this._eventRemovers.push(this._eventbus.onRequest("request-instance", this._requestInstanceHandler.bind(this)));
9675
+ this._eventRemovers.push(this._eventbus.onRequest("request-action", this._requestActionHandler.bind(this)));
9676
+ this._eventRemovers.push(this._eventbus.onRequest("request-function", this._requestFunctionHandler.bind(this)));
8666
9677
  }
9678
+ /**
9679
+ * Destroys the factory and cleans up all registered request handlers.
9680
+ */
8667
9681
  destroy() {
8668
9682
  this._eventRemovers.forEach((x) => x());
8669
- }
8670
- _resizeHandler() {
8671
- if (this._resizeTimeout) {
8672
- clearTimeout(this._resizeTimeout);
8673
- this._resizeTimeout = -1;
8674
- }
8675
- this._resizeTimeout = setTimeout(() => {
8676
- this._eventbus.broadcast("timeline-resize", []);
8677
- }, 200);
9683
+ this._eventRemovers = [];
9684
+ this._actionsLookup = {};
8678
9685
  }
8679
9686
  _importSystemEntryWithEventbusDependency(systemName) {
8680
9687
  return new (this._importSystemEntry(systemName))(this._eventbus);
8681
9688
  }
8682
9689
  _importSystemEntry(systemName) {
8683
- return this._importer.import(systemName)[systemName];
9690
+ const entry = this._importer.import(systemName)?.[systemName];
9691
+ if (!entry) throw new Error(`Failed to import '${systemName}': module does not export '${systemName}'`);
9692
+ return entry;
8684
9693
  }
8685
- _requestInstanceHandler(systemName, resultCallback) {
8686
- resultCallback(this._importSystemEntryWithEventbusDependency(systemName));
9694
+ _requestInstanceHandler(systemName) {
9695
+ return this._importSystemEntryWithEventbusDependency(systemName);
8687
9696
  }
8688
- _requestFunctionHandler(systemName, resultCallback) {
8689
- resultCallback(this._importSystemEntry(systemName));
9697
+ _requestFunctionHandler(systemName) {
9698
+ return this._importSystemEntry(systemName);
8690
9699
  }
8691
- _requestActionHandler(systemName, resultCallback) {
9700
+ _requestActionHandler(systemName) {
8692
9701
  const action = this._actionsLookup[systemName];
8693
- if (action) resultCallback(action);
9702
+ if (action) return action;
8694
9703
  else {
8695
9704
  console.error(`Unknown action: ${systemName}`);
8696
- resultCallback(null);
9705
+ return null;
8697
9706
  }
8698
9707
  }
9708
+ /**
9709
+ * Creates a fully wired engine with adapters and event handlers.
9710
+ *
9711
+ * This method:
9712
+ * - Resolves the configuration
9713
+ * - Creates timeline providers
9714
+ * - Instantiates the engine and language manager
9715
+ * - Creates and connects adapters for eventbus integration
9716
+ *
9717
+ * @param configuration - The engine configuration
9718
+ * @param resolver - Optional custom configuration resolver
9719
+ * @returns Engine result with engine, language manager, eventbus, and destroy function
9720
+ */
8699
9721
  createEngine(configuration, resolver) {
8700
9722
  const { systemName } = configuration.engine;
8701
9723
  const EngineClass = this._importSystemEntry(systemName);
@@ -8710,24 +9732,120 @@ var EngineFactory = class {
8710
9732
  this._actionsLookup = actionLookup;
8711
9733
  const timelineProviders = this._createTimelineProviders(resolvedConfiguration);
8712
9734
  const { language, labels } = configuration;
8713
- const languageManager = new LanguageManager(language, labels, this._eventbus);
8714
- return new EngineClass(resolvedConfiguration, this._eventbus, timelineProviders, languageManager);
9735
+ const languageManager = new LanguageManager(language, labels);
9736
+ const engineInstance = new EngineClass(resolvedConfiguration, this._eventbus, timelineProviders, languageManager);
9737
+ const engineEventbusAdapter = new EngineEventbusAdapter(engineInstance, this._eventbus);
9738
+ const languageEventbusAdapter = new LanguageEventbusAdapter(languageManager, this._eventbus, engineInstance);
9739
+ const engineInputAdapter = new EngineInputAdapter(engineInstance, this._eventbus, this._windowRef);
9740
+ engineEventbusAdapter.connect();
9741
+ languageEventbusAdapter.connect();
9742
+ engineInputAdapter.connect();
9743
+ return {
9744
+ engine: engineInstance,
9745
+ languageManager,
9746
+ eventbus: this._eventbus,
9747
+ destroy: async () => {
9748
+ engineInputAdapter.disconnect();
9749
+ languageEventbusAdapter.disconnect();
9750
+ engineEventbusAdapter.disconnect();
9751
+ await engineInstance.destroy();
9752
+ }
9753
+ };
8715
9754
  }
8716
9755
  _createTimelineProviders(configuration) {
8717
- const { timelineProviderSettings } = configuration;
9756
+ return this.createTimelineProvidersForConfig(configuration);
9757
+ }
9758
+ /**
9759
+ * Creates a position source for a specific timeline based on configuration.
9760
+ *
9761
+ * The position source class is resolved dynamically via the resource importer
9762
+ * using the `systemName` property from the configuration.
9763
+ *
9764
+ * @param timeline - The resolved timeline configuration
9765
+ * @param settings - The timeline provider settings containing position source config
9766
+ * @returns A configured position source
9767
+ * @throws Error if the position source class cannot be resolved
9768
+ */
9769
+ createPositionSourceForTimeline(timeline, settings) {
9770
+ const { systemName, ...options } = settings.positionSource;
9771
+ return new (this._importSystemEntry(systemName))({
9772
+ ...options,
9773
+ duration: timeline.duration
9774
+ });
9775
+ }
9776
+ /**
9777
+ * Creates a container provider based on timeline provider settings.
9778
+ *
9779
+ * The container provider class is resolved dynamically via the resource importer
9780
+ * using the `systemName` property from the configuration.
9781
+ *
9782
+ * @param settings - The timeline provider settings
9783
+ * @returns A container provider, or undefined if not configured
9784
+ * @throws Error if the container provider class cannot be resolved
9785
+ */
9786
+ createContainerProviderForTimeline(settings) {
9787
+ if (!settings.container) return;
9788
+ const { systemName, ...options } = settings.container;
9789
+ return new (this._importSystemEntry(systemName))(options);
9790
+ }
9791
+ /**
9792
+ * Creates a playlist based on timeline provider settings.
9793
+ *
9794
+ * The playlist class is resolved dynamically via the resource importer
9795
+ * using the `systemName` property from the configuration.
9796
+ *
9797
+ * @param settings - The timeline provider settings
9798
+ * @returns A playlist, or undefined if not configured
9799
+ * @throws Error if the playlist class cannot be resolved
9800
+ */
9801
+ createPlaylistForTimeline(settings) {
9802
+ if (!settings.playlist) return;
9803
+ const { systemName, ...options } = settings.playlist;
9804
+ return new (this._importSystemEntry(systemName))(options);
9805
+ }
9806
+ /**
9807
+ * Assembles a complete ITimelineProviderInfo from timeline and settings.
9808
+ *
9809
+ * This is the main entry point for creating provider info with the new
9810
+ * configuration-driven architecture.
9811
+ *
9812
+ * @param timeline - The resolved timeline configuration
9813
+ * @param settings - The timeline provider settings
9814
+ * @returns A complete timeline provider info with all components
9815
+ */
9816
+ createTimelineProviderInfo(timeline, settings) {
9817
+ return {
9818
+ positionSource: this.createPositionSourceForTimeline(timeline, settings),
9819
+ containerProvider: this.createContainerProviderForTimeline(settings),
9820
+ playlist: this.createPlaylistForTimeline(settings)
9821
+ };
9822
+ }
9823
+ /**
9824
+ * Creates timeline providers for all configured timeline types using the new
9825
+ * configuration-driven architecture.
9826
+ *
9827
+ * This method iterates over timelineProviderSettings and creates a
9828
+ * ITimelineProviderInfo for each configured timeline type by:
9829
+ * 1. Finding the first timeline that matches the type
9830
+ * 2. Using the timeline's duration for the position source
9831
+ * 3. Assembling components from the settings
9832
+ *
9833
+ * @param configuration - The resolved engine configuration
9834
+ * @returns A record of timeline types to their provider info
9835
+ * @throws Error if a provider setting has no matching timeline in config
9836
+ */
9837
+ createTimelineProvidersForConfig(configuration) {
9838
+ const { timelineProviderSettings, timelines } = configuration;
8718
9839
  return Object.entries(timelineProviderSettings).reduce((acc, [timelineType, settings]) => {
8719
9840
  if (!settings) return acc;
8720
- const TimelineProviderClass = this._importSystemEntry(settings.systemName);
8721
- acc[timelineType] = {
8722
- id: settings.id,
8723
- vendor: settings.vendor,
8724
- provider: new TimelineProviderClass(configuration)
8725
- };
9841
+ const matchingTimeline = timelines.find((t) => t.type === timelineType);
9842
+ if (!matchingTimeline) throw new Error(`Timeline provider settings for '${timelineType}' has no matching timeline in configuration`);
9843
+ acc[timelineType] = this.createTimelineProviderInfo(matchingTimeline, settings);
8726
9844
  return acc;
8727
9845
  }, {});
8728
9846
  }
8729
9847
  };
8730
9848
 
8731
9849
  //#endregion
8732
- export { Action, ActionCreator, ActionCreatorFactory, ActionEditor, ActionRegistryEventbusListener, ConfigurationFactory, ConfigurationResolver, ControllerNamesProvider, DEV_TOOLS_KEY, DOMEventListenerController, DevToolEventListener, Diagnostics, EligiusEngine, EligiusResourceImporter, EndableAction, EndableActionCreator, EndableActionEditor, EngineFactory, Eventbus, LabelController, LanguageManager, LottieController, MutationObserverController, NavigationController, OperationEditor, OperationMetadataProvider, OperationNamesProvider, ProgressbarController, RequestAnimationFrameTimelineProvider, RequestVideoUriInterceptor, RoutingController, SubtitleEditor, SubtitleImporter, SubtitlesController, TimeLineEventNamesProvider, TimelineAction, TimelineActionCreator, TimelineActionEditor, TimelineProviderSettingsEditor, TimelineProvidersSettingsEditor, VideoJsTimelineProvider, addClass, addControllerToElement, addGlobalsToOperation, animate, animateWithClass, announceToScreenReader, breakForEach, broadcastEvent, calc, clearElement, clearOperationData, clearStorage, compareDate, concatenateStrings, continueForEach, createElement, metadata_exports as ctrlmetadata, customFunction, endAction, endForEach, endWhen, metadata_exports$1 as eventmetadata, extendController, filterArray, findInArray, forEach, formatDate, formatText, getAttributesFromElement, getControllerFromElement, getControllerInstance, getCurrentTime, getElementDimensions, getFocusedElement, getFormData, getImport, getQueryParams, getScrollPosition, getTextContent, httpDelete, httpPost, httpPut, invokeObjectMethod, isActive, isElementInViewport, loadFromStorage, loadJson, log, mapArray, math, metadata_exports$2 as metadata, otherwise, removeClass, removeControllerFromElement, removeElement, removePropertiesFromOperationData, reparentElement, replaceString, replaceText, requestAction, saveToStorage, scrollToElement, scrollToPosition, selectElement, send, setActive, setData, setElementAttributes, setElementContent, setFocus, setFormValue, setGlobalData, setOperationData, setStyle, setVariable, sortArray, splitString, startAction, substringText, toggleClass, toggleElement, toggleFormElement, validateForm, wait, when };
9850
+ export { Action, ActionCreator, ActionCreatorFactory, ActionEditor, ActionRegistryEventbusListener, BasePositionSource, ConfigurationFactory, ConfigurationResolver, ControllerNamesProvider, DOMEventListenerController, DomContainerProvider, EligiusEngine, EligiusResourceImporter, EndableAction, EndableActionCreator, EndableActionEditor, EngineEventbusAdapter, EngineFactory, EngineInputAdapter, Eventbus, LabelController, LanguageEventbusAdapter, LanguageManager, LottieController, MutationObserverController, NavigationController, OperationEditor, OperationMetadataProvider, OperationNamesProvider, ProgressbarController, RafPositionSource, RequestVideoUriInterceptor, RoutingController, ScrollPositionSource, SimplePlaylist, SubtitleEditor, SubtitleImporter, SubtitlesController, TimeLineEventNamesProvider, TimelineAction, TimelineActionCreator, TimelineActionEditor, TimelineProviderSettingsEditor, TimelineProvidersSettingsEditor, TypedEventEmitter, VideoPositionSource, addClass, addControllerToElement, addGlobalsToOperation, animate, animateWithClass, announceToScreenReader, breakForEach, broadcastEvent, calc, clearElement, clearOperationData, clearStorage, compareDate, concatenateStrings, continueForEach, createElement, metadata_exports as ctrlmetadata, customFunction, endAction, endForEach, endWhen, metadata_exports$1 as eventmetadata, extendController, filterArray, findInArray, forEach, formatDate, formatText, getAttributesFromElement, getControllerFromElement, getControllerInstance, getCurrentTime, getElementDimensions, getFocusedElement, getFormData, getImport, getQueryParams, getScrollPosition, getTextContent, httpDelete, httpPost, httpPut, invokeObjectMethod, isElementInViewport, isSeekable, loadFromStorage, loadJson, log, mapArray, math, metadata_exports$2 as metadata, otherwise, removeClass, removeControllerFromElement, removeElement, removePropertiesFromOperationData, reparentElement, replaceString, replaceText, requestAction, saveToStorage, scrollToElement, scrollToPosition, selectElement, setData, setElementAttributes, setElementContent, setFocus, setFormValue, setGlobalData, setOperationData, setStyle, setVariable, sortArray, splitString, startAction, substringText, toggleClass, toggleElement, toggleFormElement, validateForm, wait, when };
8733
9851
  //# sourceMappingURL=index.mjs.map