eligius 1.5.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -25
- package/dist/index.d.mts +1965 -340
- package/dist/index.mjs +2130 -777
- package/dist/index.mjs.map +1 -1
- package/jsonschema/eligius-configuration.json +101 -47
- package/jsonschema/endable-action-template.json +4 -2
- package/jsonschema/endable-action.json +3 -1
- package/jsonschema/event-action.json +3 -1
- package/jsonschema/mediaplayer-timeline-provider-settings.json +85 -30
- package/jsonschema/raf-timeline-provider-settings.json +132 -20
- package/jsonschema/timeline-action.json +4 -2
- package/jsonschema/timeline-provider-settings.json +6 -3
- package/jsonschema/timeline.json +31 -10
- package/package.json +8 -9
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
|
|
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
|
-
|
|
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
|
-
|
|
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$1 = 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$1("space", handleSpaceBound);
|
|
587
|
+
this._removers.push(() => hotkeys$1.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
|
-
|
|
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
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
},
|
|
974
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
2322
|
-
|
|
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/
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
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;
|
|
3624
|
-
}
|
|
3625
|
-
constructor(config) {
|
|
3626
|
-
this._playlist = this._extractPlaylist(config);
|
|
3627
|
-
this._currentPlaylistItem = this._playlist[0];
|
|
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;
|
|
3628
3770
|
}
|
|
3629
|
-
|
|
3630
|
-
|
|
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);
|
|
3631
3783
|
}
|
|
3632
|
-
|
|
3633
|
-
this.
|
|
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);
|
|
3634
3787
|
}
|
|
3635
|
-
|
|
3636
|
-
this.
|
|
3788
|
+
next() {
|
|
3789
|
+
return this.configurationFactory;
|
|
3637
3790
|
}
|
|
3638
|
-
|
|
3639
|
-
|
|
3791
|
+
};
|
|
3792
|
+
var TimelineProviderSettingsEditor = class {
|
|
3793
|
+
constructor(providerSettings, providersSettingsEditor, configurationFactory) {
|
|
3794
|
+
this.providerSettings = providerSettings;
|
|
3795
|
+
this.providersSettingsEditor = providersSettingsEditor;
|
|
3796
|
+
this.configurationFactory = configurationFactory;
|
|
3640
3797
|
}
|
|
3641
|
-
|
|
3642
|
-
|
|
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;
|
|
3643
3805
|
}
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
this.
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
this
|
|
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();
|
|
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;
|
|
3665
3817
|
}
|
|
3666
|
-
|
|
3667
|
-
|
|
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;
|
|
3668
3832
|
}
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
this.
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
}
|
|
3681
|
-
if (this._currentPosition === 0) this._callbackPosition();
|
|
3682
|
-
animationInterval(this._tickInterval, this._abortController.signal, this._updateBound);
|
|
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;
|
|
3683
3844
|
}
|
|
3684
|
-
|
|
3685
|
-
|
|
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;
|
|
3686
3852
|
}
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
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
|
|
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
|
-
|
|
3895
|
-
|
|
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
|
-
|
|
3899
|
-
|
|
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
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
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
|
-
|
|
4463
|
-
this.
|
|
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.
|
|
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.
|
|
4601
|
-
|
|
4602
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
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.
|
|
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) {
|
|
@@ -6963,51 +6943,6 @@ var OperationMetadataProvider = class {
|
|
|
6963
6943
|
return getMetadata();
|
|
6964
6944
|
}
|
|
6965
6945
|
};
|
|
6966
|
-
/**
|
|
6967
|
-
*
|
|
6968
|
-
* Provider for all the available event names
|
|
6969
|
-
*
|
|
6970
|
-
*/
|
|
6971
|
-
var TimeLineEventNamesProvider = class {
|
|
6972
|
-
getEventNames() {
|
|
6973
|
-
return [
|
|
6974
|
-
"timeline-play-toggle-request",
|
|
6975
|
-
"timeline-play-request",
|
|
6976
|
-
"timeline-stop-request",
|
|
6977
|
-
"timeline-pause-request",
|
|
6978
|
-
"timeline-seek-request",
|
|
6979
|
-
"timeline-resize-request",
|
|
6980
|
-
"timeline-container-request",
|
|
6981
|
-
"timeline-duration-request",
|
|
6982
|
-
"timeline-request-current-timeline",
|
|
6983
|
-
"timeline-duration",
|
|
6984
|
-
"timeline-time",
|
|
6985
|
-
"timeline-seeked",
|
|
6986
|
-
"timeline-complete",
|
|
6987
|
-
"timeline-restart",
|
|
6988
|
-
"timeline-play",
|
|
6989
|
-
"timeline-stop",
|
|
6990
|
-
"timeline-pause",
|
|
6991
|
-
"timeline-seek",
|
|
6992
|
-
"timeline-resize",
|
|
6993
|
-
"timeline-current-timeline-change",
|
|
6994
|
-
"timeline-firstframe",
|
|
6995
|
-
"request-instance",
|
|
6996
|
-
"request-action",
|
|
6997
|
-
"request-function",
|
|
6998
|
-
"request-timeline-uri",
|
|
6999
|
-
"before-request-timeline-uri",
|
|
7000
|
-
"request-engine-root",
|
|
7001
|
-
"request-current-timeline-position",
|
|
7002
|
-
"request-timeline-cleanup",
|
|
7003
|
-
"request-label-collection",
|
|
7004
|
-
"request-label-collections",
|
|
7005
|
-
"request-current-language",
|
|
7006
|
-
"language-change",
|
|
7007
|
-
"dom-mutation"
|
|
7008
|
-
];
|
|
7009
|
-
}
|
|
7010
|
-
};
|
|
7011
6946
|
|
|
7012
6947
|
//#endregion
|
|
7013
6948
|
//#region src/configuration/api/subtitle-converter.ts
|
|
@@ -7597,7 +7532,10 @@ function requestCurrentTimelinePosition() {
|
|
|
7597
7532
|
return {
|
|
7598
7533
|
description: `Event: request-current-timeline-position`,
|
|
7599
7534
|
category: `Engine Request`,
|
|
7600
|
-
args: [
|
|
7535
|
+
args: [{
|
|
7536
|
+
name: "callback",
|
|
7537
|
+
type: "TResultCallback<number>"
|
|
7538
|
+
}]
|
|
7601
7539
|
};
|
|
7602
7540
|
}
|
|
7603
7541
|
|
|
@@ -7707,7 +7645,13 @@ function requestTimelineUri() {
|
|
|
7707
7645
|
return {
|
|
7708
7646
|
description: `Event: request-timeline-uri`,
|
|
7709
7647
|
category: `Engine Request`,
|
|
7710
|
-
args: [
|
|
7648
|
+
args: [{
|
|
7649
|
+
name: "uri",
|
|
7650
|
+
type: "string"
|
|
7651
|
+
}, {
|
|
7652
|
+
name: "position",
|
|
7653
|
+
type: "number"
|
|
7654
|
+
}]
|
|
7711
7655
|
};
|
|
7712
7656
|
}
|
|
7713
7657
|
|
|
@@ -7872,7 +7816,10 @@ function timelineRequestCurrentTimeline() {
|
|
|
7872
7816
|
return {
|
|
7873
7817
|
description: `Event: timeline-request-current-timeline`,
|
|
7874
7818
|
category: `Engine Request`,
|
|
7875
|
-
args: [
|
|
7819
|
+
args: [{
|
|
7820
|
+
name: "callback",
|
|
7821
|
+
type: "TResultCallback<string>"
|
|
7822
|
+
}]
|
|
7876
7823
|
};
|
|
7877
7824
|
}
|
|
7878
7825
|
|
|
@@ -8079,17 +8026,44 @@ var ActionRegistryEventbusListener = class {
|
|
|
8079
8026
|
|
|
8080
8027
|
//#endregion
|
|
8081
8028
|
//#region src/eventbus/eventbus.ts
|
|
8029
|
+
/**
|
|
8030
|
+
* Central event bus for pub/sub communication and synchronous request/response queries.
|
|
8031
|
+
*
|
|
8032
|
+
* The eventbus supports:
|
|
8033
|
+
* - **Pub/Sub**: `on()`, `once()`, `off()`, `broadcast()`, `broadcastForTopic()`
|
|
8034
|
+
* - **Request/Response**: `onRequest()`, `request()`, `requestForTopic()` for synchronous queries
|
|
8035
|
+
* - **Interceptors**: Transform event arguments before handlers receive them
|
|
8036
|
+
* - **Listeners**: Global event observers for logging/debugging
|
|
8037
|
+
*
|
|
8038
|
+
* @example Pub/Sub pattern
|
|
8039
|
+
* ```ts
|
|
8040
|
+
* const remover = eventbus.on('timeline-play', () => console.log('Playing'));
|
|
8041
|
+
* eventbus.broadcast('timeline-play', []);
|
|
8042
|
+
* remover(); // Unsubscribe
|
|
8043
|
+
* ```
|
|
8044
|
+
*
|
|
8045
|
+
* @example Request/Response pattern
|
|
8046
|
+
* ```ts
|
|
8047
|
+
* eventbus.onRequest('request-instance', (name) => new MyClass(name));
|
|
8048
|
+
* const instance = eventbus.request<MyClass>('request-instance', 'test');
|
|
8049
|
+
* ```
|
|
8050
|
+
*/
|
|
8082
8051
|
var Eventbus = class {
|
|
8083
8052
|
eventHandlers = /* @__PURE__ */ new Map();
|
|
8084
8053
|
eventInterceptors = /* @__PURE__ */ new Map();
|
|
8085
8054
|
eventListeners = [];
|
|
8055
|
+
requestResponders = /* @__PURE__ */ new Map();
|
|
8086
8056
|
constructor() {
|
|
8087
8057
|
this.clear();
|
|
8088
8058
|
}
|
|
8059
|
+
/**
|
|
8060
|
+
* Clears all handlers, listeners, interceptors, and request responders.
|
|
8061
|
+
*/
|
|
8089
8062
|
clear() {
|
|
8090
8063
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
8091
8064
|
this.eventListeners = [];
|
|
8092
8065
|
this.eventInterceptors = /* @__PURE__ */ new Map();
|
|
8066
|
+
this.requestResponders = /* @__PURE__ */ new Map();
|
|
8093
8067
|
}
|
|
8094
8068
|
_getEventInterceptors(eventName, eventTopic) {
|
|
8095
8069
|
if (eventTopic) eventName = `${eventName}:${eventTopic}`;
|
|
@@ -8145,6 +8119,30 @@ var Eventbus = class {
|
|
|
8145
8119
|
if (index > -1) interceptors.splice(index, 1);
|
|
8146
8120
|
};
|
|
8147
8121
|
}
|
|
8122
|
+
onRequest(eventName, responder, eventTopic) {
|
|
8123
|
+
const responders = this._getRequestResponders(eventName, eventTopic);
|
|
8124
|
+
responders.push(responder);
|
|
8125
|
+
return () => {
|
|
8126
|
+
const index = responders.indexOf(responder);
|
|
8127
|
+
if (index > -1) responders.splice(index, 1);
|
|
8128
|
+
};
|
|
8129
|
+
}
|
|
8130
|
+
request(eventName, ...args) {
|
|
8131
|
+
return this._callResponder(eventName, void 0, args);
|
|
8132
|
+
}
|
|
8133
|
+
requestForTopic(eventName, eventTopic, ...args) {
|
|
8134
|
+
return this._callResponder(eventName, eventTopic, args);
|
|
8135
|
+
}
|
|
8136
|
+
_getRequestResponders(eventName, eventTopic) {
|
|
8137
|
+
if (eventTopic) eventName = `${eventName}:${eventTopic}`;
|
|
8138
|
+
if (!this.requestResponders.has(eventName)) this.requestResponders.set(eventName, []);
|
|
8139
|
+
return this.requestResponders.get(eventName);
|
|
8140
|
+
}
|
|
8141
|
+
_callResponder(eventName, eventTopic, args) {
|
|
8142
|
+
const responders = this._getRequestResponders(eventName, eventTopic);
|
|
8143
|
+
if (responders.length === 0) return;
|
|
8144
|
+
return responders[0](...args);
|
|
8145
|
+
}
|
|
8148
8146
|
_callHandlers(eventName, eventTopic, args = []) {
|
|
8149
8147
|
const handlers = this._getEventHandlers(eventName, eventTopic);
|
|
8150
8148
|
if (handlers) {
|
|
@@ -8181,150 +8179,1451 @@ var eventbus_exports = /* @__PURE__ */ __export({
|
|
|
8181
8179
|
});
|
|
8182
8180
|
|
|
8183
8181
|
//#endregion
|
|
8184
|
-
//#region src/
|
|
8182
|
+
//#region src/timelineproviders/types.ts
|
|
8185
8183
|
/**
|
|
8186
|
-
*
|
|
8187
|
-
*
|
|
8184
|
+
* Type guard to check if a position source is seekable.
|
|
8185
|
+
*
|
|
8186
|
+
* @param source - Position source to check
|
|
8187
|
+
* @returns `true` if source implements ISeekable
|
|
8188
8188
|
*/
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8189
|
+
function isSeekable(source) {
|
|
8190
|
+
return "seek" in source && typeof source.seek === "function";
|
|
8191
|
+
}
|
|
8192
|
+
|
|
8193
|
+
//#endregion
|
|
8194
|
+
//#region src/timelineproviders/position-sources/base-position-source.ts
|
|
8195
|
+
/**
|
|
8196
|
+
* Abstract base class for position sources.
|
|
8197
|
+
*
|
|
8198
|
+
* Provides shared state management, lifecycle handling, and callback
|
|
8199
|
+
* registration for concrete position source implementations.
|
|
8200
|
+
*
|
|
8201
|
+
* Subclasses must implement:
|
|
8202
|
+
* - `doInit()` - Source-specific initialization
|
|
8203
|
+
* - `doDestroy()` - Source-specific cleanup
|
|
8204
|
+
* - `startTicking()` - Start emitting position updates
|
|
8205
|
+
* - `stopTicking()` - Stop emitting position updates
|
|
8206
|
+
*
|
|
8207
|
+
* @example
|
|
8208
|
+
* ```typescript
|
|
8209
|
+
* class MyPositionSource extends BasePositionSource {
|
|
8210
|
+
* protected doInit(): Promise<void> {
|
|
8211
|
+
* // Initialize resources
|
|
8212
|
+
* return Promise.resolve();
|
|
8213
|
+
* }
|
|
8214
|
+
*
|
|
8215
|
+
* protected doDestroy(): void {
|
|
8216
|
+
* // Clean up resources
|
|
8217
|
+
* }
|
|
8218
|
+
*
|
|
8219
|
+
* protected startTicking(): void {
|
|
8220
|
+
* // Start position updates
|
|
8221
|
+
* }
|
|
8222
|
+
*
|
|
8223
|
+
* protected stopTicking(): void {
|
|
8224
|
+
* // Stop position updates
|
|
8225
|
+
* }
|
|
8226
|
+
* }
|
|
8227
|
+
* ```
|
|
8228
|
+
*/
|
|
8229
|
+
var BasePositionSource = class {
|
|
8230
|
+
_state = "inactive";
|
|
8231
|
+
_position = 0;
|
|
8232
|
+
_duration;
|
|
8233
|
+
_loop = false;
|
|
8234
|
+
_positionCallbacks = [];
|
|
8235
|
+
_boundaryCallbacks = [];
|
|
8236
|
+
_activatedCallbacks = [];
|
|
8202
8237
|
/**
|
|
8203
|
-
*
|
|
8204
|
-
*
|
|
8238
|
+
* Create a new position source.
|
|
8239
|
+
*
|
|
8240
|
+
* @param duration - Total duration in seconds (or `Infinity` for unbounded)
|
|
8205
8241
|
*/
|
|
8206
|
-
|
|
8207
|
-
this.
|
|
8208
|
-
this._addEventbusListeners();
|
|
8209
|
-
const { timelines } = this.configuration;
|
|
8210
|
-
this._currentTimelineUri = timelines?.[0].uri ?? "";
|
|
8211
|
-
this._createTimelineLookup();
|
|
8212
|
-
return this._initializeTimelineProvider();
|
|
8242
|
+
constructor(duration) {
|
|
8243
|
+
this._duration = duration;
|
|
8213
8244
|
}
|
|
8214
|
-
|
|
8215
|
-
|
|
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");
|
|
8245
|
+
get state() {
|
|
8246
|
+
return this._state;
|
|
8221
8247
|
}
|
|
8222
|
-
|
|
8223
|
-
|
|
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;
|
|
8248
|
+
get loop() {
|
|
8249
|
+
return this._loop;
|
|
8237
8250
|
}
|
|
8238
|
-
|
|
8239
|
-
this.
|
|
8251
|
+
set loop(value) {
|
|
8252
|
+
this._loop = value;
|
|
8240
8253
|
}
|
|
8241
|
-
|
|
8242
|
-
this.
|
|
8243
|
-
this.eventbus.broadcast("timeline-duration", [this._activeTimelineProvider?.getDuration]);
|
|
8254
|
+
async init() {
|
|
8255
|
+
await this.doInit();
|
|
8244
8256
|
}
|
|
8245
|
-
|
|
8246
|
-
this.
|
|
8257
|
+
destroy() {
|
|
8258
|
+
if (this._state === "active") this.stopTicking();
|
|
8259
|
+
this._state = "inactive";
|
|
8260
|
+
this._position = 0;
|
|
8261
|
+
this.doDestroy();
|
|
8262
|
+
}
|
|
8263
|
+
async activate() {
|
|
8264
|
+
if (this._state === "active") return;
|
|
8265
|
+
this._state = "active";
|
|
8266
|
+
this.startTicking();
|
|
8267
|
+
for (const callback of this._activatedCallbacks) callback();
|
|
8268
|
+
}
|
|
8269
|
+
suspend() {
|
|
8270
|
+
if (this._state !== "active") return;
|
|
8271
|
+
this._state = "suspended";
|
|
8272
|
+
this.stopTicking();
|
|
8273
|
+
}
|
|
8274
|
+
deactivate() {
|
|
8275
|
+
if (this._state === "inactive") return;
|
|
8276
|
+
if (this._state === "active") this.stopTicking();
|
|
8277
|
+
this._state = "inactive";
|
|
8278
|
+
this._position = 0;
|
|
8247
8279
|
}
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8280
|
+
getPosition() {
|
|
8281
|
+
return this._position;
|
|
8282
|
+
}
|
|
8283
|
+
getDuration() {
|
|
8284
|
+
return this._duration;
|
|
8285
|
+
}
|
|
8286
|
+
onPosition(callback) {
|
|
8287
|
+
this._positionCallbacks.push(callback);
|
|
8288
|
+
}
|
|
8289
|
+
onBoundaryReached(callback) {
|
|
8290
|
+
this._boundaryCallbacks.push(callback);
|
|
8291
|
+
}
|
|
8292
|
+
onActivated(callback) {
|
|
8293
|
+
this._activatedCallbacks.push(callback);
|
|
8251
8294
|
}
|
|
8252
8295
|
/**
|
|
8253
|
-
*
|
|
8254
|
-
*
|
|
8255
|
-
*
|
|
8256
|
-
* - It destroys all of its timeline providers
|
|
8257
|
-
* - It empties the HTML element indicated by the containerSelector configuration property.
|
|
8296
|
+
* Set the current position and emit to callbacks.
|
|
8297
|
+
*
|
|
8298
|
+
* Only emits if the source is active.
|
|
8258
8299
|
*
|
|
8300
|
+
* @param position - New position value
|
|
8259
8301
|
*/
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
this.
|
|
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();
|
|
8302
|
+
setPosition(position) {
|
|
8303
|
+
this._position = position;
|
|
8304
|
+
if (this._state === "active") for (const callback of this._positionCallbacks) callback(position);
|
|
8268
8305
|
}
|
|
8269
|
-
|
|
8270
|
-
|
|
8306
|
+
/**
|
|
8307
|
+
* Emit a boundary event to all registered callbacks.
|
|
8308
|
+
*
|
|
8309
|
+
* @param boundary - The boundary type ('start' or 'end')
|
|
8310
|
+
*/
|
|
8311
|
+
emitBoundary(boundary) {
|
|
8312
|
+
for (const callback of this._boundaryCallbacks) callback(boundary);
|
|
8313
|
+
}
|
|
8314
|
+
};
|
|
8315
|
+
|
|
8316
|
+
//#endregion
|
|
8317
|
+
//#region src/timelineproviders/position-sources/keyboard-step-source.ts
|
|
8318
|
+
const hotkeys = hk.default || hk;
|
|
8319
|
+
/**
|
|
8320
|
+
* Key bindings used by KeyboardStepSource.
|
|
8321
|
+
*/
|
|
8322
|
+
const KEY_BINDINGS = {
|
|
8323
|
+
stepForward: "right",
|
|
8324
|
+
stepBackward: "left",
|
|
8325
|
+
largeStepForward: "shift+right",
|
|
8326
|
+
largeStepBackward: "shift+left",
|
|
8327
|
+
jumpToStart: "home",
|
|
8328
|
+
jumpToEnd: "end",
|
|
8329
|
+
verticalPrev: "up",
|
|
8330
|
+
verticalNext: "down"
|
|
8331
|
+
};
|
|
8332
|
+
/**
|
|
8333
|
+
* Keyboard-based position source for stepping through a timeline.
|
|
8334
|
+
*
|
|
8335
|
+
* Supports:
|
|
8336
|
+
* - Left/Right arrows: step by `stepSize` (default 1s)
|
|
8337
|
+
* - Shift+Left/Right: large step by `largeStepSize` (default 10s)
|
|
8338
|
+
* - Home/End: jump to start/end
|
|
8339
|
+
* - Up/Down: configurable (timeline switch, chapter navigation, or disabled)
|
|
8340
|
+
*
|
|
8341
|
+
* @example
|
|
8342
|
+
* ```typescript
|
|
8343
|
+
* const source = new KeyboardStepSource({
|
|
8344
|
+
* duration: 60,
|
|
8345
|
+
* verticalMode: 'chapter-navigation',
|
|
8346
|
+
* markers: [0, 10, 20, 30, 40, 50],
|
|
8347
|
+
* });
|
|
8348
|
+
*
|
|
8349
|
+
* await source.init();
|
|
8350
|
+
*
|
|
8351
|
+
* source.onPosition((position) => {
|
|
8352
|
+
* console.log(`Position: ${position}s`);
|
|
8353
|
+
* });
|
|
8354
|
+
*
|
|
8355
|
+
* source.onMarkerJump((index, position) => {
|
|
8356
|
+
* console.log(`Jumped to marker ${index} at ${position}s`);
|
|
8357
|
+
* });
|
|
8358
|
+
*
|
|
8359
|
+
* await source.activate();
|
|
8360
|
+
* ```
|
|
8361
|
+
*/
|
|
8362
|
+
var KeyboardStepSource = class extends BasePositionSource {
|
|
8363
|
+
_stepSize;
|
|
8364
|
+
_largeStepSize;
|
|
8365
|
+
_verticalMode;
|
|
8366
|
+
_wrapNavigation;
|
|
8367
|
+
_markers;
|
|
8368
|
+
_targetElementConfig;
|
|
8369
|
+
_targetElement;
|
|
8370
|
+
_scopeId;
|
|
8371
|
+
_timelineChangeCallbacks = [];
|
|
8372
|
+
_markerJumpCallbacks = [];
|
|
8373
|
+
/**
|
|
8374
|
+
* Create a new keyboard-based position source.
|
|
8375
|
+
*
|
|
8376
|
+
* @param config - Configuration options
|
|
8377
|
+
*/
|
|
8378
|
+
constructor(config) {
|
|
8379
|
+
super(config.duration);
|
|
8380
|
+
this._stepSize = config.stepSize ?? 1;
|
|
8381
|
+
this._largeStepSize = config.largeStepSize ?? 10;
|
|
8382
|
+
this._verticalMode = config.verticalMode;
|
|
8383
|
+
this._wrapNavigation = config.wrapNavigation ?? true;
|
|
8384
|
+
this._markers = config.markers ? [...config.markers] : [];
|
|
8385
|
+
this._targetElementConfig = config.targetElement;
|
|
8386
|
+
this._scopeId = `keyboard-step-source-${v4()}`;
|
|
8387
|
+
}
|
|
8388
|
+
doInit() {
|
|
8389
|
+
this._markers.sort((a, b) => a - b);
|
|
8390
|
+
if (typeof this._targetElementConfig === "string") {
|
|
8391
|
+
const element = document.querySelector(this._targetElementConfig);
|
|
8392
|
+
if (element instanceof HTMLElement) this._targetElement = element;
|
|
8393
|
+
} else if (this._targetElementConfig instanceof HTMLElement) this._targetElement = this._targetElementConfig;
|
|
8394
|
+
return Promise.resolve();
|
|
8395
|
+
}
|
|
8396
|
+
doDestroy() {
|
|
8397
|
+
this._unbindKeys();
|
|
8398
|
+
}
|
|
8399
|
+
startTicking() {
|
|
8400
|
+
this._bindKeys();
|
|
8401
|
+
}
|
|
8402
|
+
stopTicking() {
|
|
8403
|
+
this._unbindKeys();
|
|
8404
|
+
}
|
|
8405
|
+
/**
|
|
8406
|
+
* Seek to a specific position.
|
|
8407
|
+
*
|
|
8408
|
+
* Position is clamped to the valid range [0, duration].
|
|
8409
|
+
*
|
|
8410
|
+
* @param position - Target position in seconds
|
|
8411
|
+
* @returns Actual position after seek (may be clamped)
|
|
8412
|
+
*/
|
|
8413
|
+
async seek(position) {
|
|
8414
|
+
const clampedPosition = Math.max(0, Math.min(position, this.getDuration()));
|
|
8415
|
+
this.setPosition(clampedPosition);
|
|
8416
|
+
return clampedPosition;
|
|
8417
|
+
}
|
|
8418
|
+
/**
|
|
8419
|
+
* Register callback for timeline change requests (timeline-switch mode).
|
|
8420
|
+
*
|
|
8421
|
+
* @param callback - Called with 'prev' or 'next' when Up/Down is pressed
|
|
8422
|
+
*/
|
|
8423
|
+
onTimelineChangeRequest(callback) {
|
|
8424
|
+
this._timelineChangeCallbacks.push(callback);
|
|
8425
|
+
}
|
|
8426
|
+
/**
|
|
8427
|
+
* Register callback for marker jumps (chapter-navigation mode).
|
|
8428
|
+
*
|
|
8429
|
+
* @param callback - Called with marker index and position when jumping
|
|
8430
|
+
*/
|
|
8431
|
+
onMarkerJump(callback) {
|
|
8432
|
+
this._markerJumpCallbacks.push(callback);
|
|
8433
|
+
}
|
|
8434
|
+
/**
|
|
8435
|
+
* Bind all keyboard handlers.
|
|
8436
|
+
*/
|
|
8437
|
+
_bindKeys() {
|
|
8438
|
+
const options = { scope: this._scopeId };
|
|
8439
|
+
if (this._targetElement) options.element = this._targetElement;
|
|
8440
|
+
hotkeys.setScope(this._scopeId);
|
|
8441
|
+
hotkeys(KEY_BINDINGS.stepForward, options, (event) => {
|
|
8442
|
+
event.preventDefault();
|
|
8443
|
+
this._handleStepForward();
|
|
8444
|
+
});
|
|
8445
|
+
hotkeys(KEY_BINDINGS.stepBackward, options, (event) => {
|
|
8446
|
+
event.preventDefault();
|
|
8447
|
+
this._handleStepBackward();
|
|
8448
|
+
});
|
|
8449
|
+
hotkeys(KEY_BINDINGS.largeStepForward, options, (event) => {
|
|
8450
|
+
event.preventDefault();
|
|
8451
|
+
this._handleLargeStepForward();
|
|
8452
|
+
});
|
|
8453
|
+
hotkeys(KEY_BINDINGS.largeStepBackward, options, (event) => {
|
|
8454
|
+
event.preventDefault();
|
|
8455
|
+
this._handleLargeStepBackward();
|
|
8456
|
+
});
|
|
8457
|
+
hotkeys(KEY_BINDINGS.jumpToStart, options, (event) => {
|
|
8458
|
+
event.preventDefault();
|
|
8459
|
+
this._handleJumpToStart();
|
|
8460
|
+
});
|
|
8461
|
+
hotkeys(KEY_BINDINGS.jumpToEnd, options, (event) => {
|
|
8462
|
+
event.preventDefault();
|
|
8463
|
+
this._handleJumpToEnd();
|
|
8464
|
+
});
|
|
8465
|
+
if (this._verticalMode !== "disabled") {
|
|
8466
|
+
hotkeys(KEY_BINDINGS.verticalPrev, options, (event) => {
|
|
8467
|
+
event.preventDefault();
|
|
8468
|
+
this._handleVerticalPrev();
|
|
8469
|
+
});
|
|
8470
|
+
hotkeys(KEY_BINDINGS.verticalNext, options, (event) => {
|
|
8471
|
+
event.preventDefault();
|
|
8472
|
+
this._handleVerticalNext();
|
|
8473
|
+
});
|
|
8474
|
+
}
|
|
8475
|
+
}
|
|
8476
|
+
/**
|
|
8477
|
+
* Unbind all keyboard handlers.
|
|
8478
|
+
*/
|
|
8479
|
+
_unbindKeys() {
|
|
8480
|
+
hotkeys.deleteScope(this._scopeId);
|
|
8481
|
+
}
|
|
8482
|
+
_handleStepForward() {
|
|
8483
|
+
const currentPosition = this.getPosition();
|
|
8484
|
+
const duration = this.getDuration();
|
|
8485
|
+
let newPosition = currentPosition + this._stepSize;
|
|
8486
|
+
if (newPosition > duration) {
|
|
8487
|
+
if (this._wrapNavigation) {
|
|
8488
|
+
newPosition = 0;
|
|
8489
|
+
this.setPosition(newPosition);
|
|
8490
|
+
this.emitBoundary("start");
|
|
8491
|
+
}
|
|
8492
|
+
} else this.setPosition(newPosition);
|
|
8493
|
+
}
|
|
8494
|
+
_handleStepBackward() {
|
|
8495
|
+
const currentPosition = this.getPosition();
|
|
8496
|
+
const duration = this.getDuration();
|
|
8497
|
+
let newPosition = currentPosition - this._stepSize;
|
|
8498
|
+
if (newPosition < 0) {
|
|
8499
|
+
if (this._wrapNavigation) {
|
|
8500
|
+
newPosition = duration;
|
|
8501
|
+
this.setPosition(newPosition);
|
|
8502
|
+
this.emitBoundary("end");
|
|
8503
|
+
}
|
|
8504
|
+
} else this.setPosition(newPosition);
|
|
8505
|
+
}
|
|
8506
|
+
_handleLargeStepForward() {
|
|
8507
|
+
const currentPosition = this.getPosition();
|
|
8508
|
+
const duration = this.getDuration();
|
|
8509
|
+
let newPosition = currentPosition + this._largeStepSize;
|
|
8510
|
+
if (newPosition > duration) if (this._wrapNavigation) {
|
|
8511
|
+
newPosition = 0;
|
|
8512
|
+
this.setPosition(newPosition);
|
|
8513
|
+
this.emitBoundary("start");
|
|
8514
|
+
} else {
|
|
8515
|
+
newPosition = duration;
|
|
8516
|
+
this.setPosition(newPosition);
|
|
8517
|
+
}
|
|
8518
|
+
else this.setPosition(newPosition);
|
|
8519
|
+
}
|
|
8520
|
+
_handleLargeStepBackward() {
|
|
8521
|
+
const currentPosition = this.getPosition();
|
|
8522
|
+
const duration = this.getDuration();
|
|
8523
|
+
let newPosition = currentPosition - this._largeStepSize;
|
|
8524
|
+
if (newPosition < 0) if (this._wrapNavigation) {
|
|
8525
|
+
newPosition = duration;
|
|
8526
|
+
this.setPosition(newPosition);
|
|
8527
|
+
this.emitBoundary("end");
|
|
8528
|
+
} else {
|
|
8529
|
+
newPosition = 0;
|
|
8530
|
+
this.setPosition(newPosition);
|
|
8531
|
+
}
|
|
8532
|
+
else this.setPosition(newPosition);
|
|
8533
|
+
}
|
|
8534
|
+
_handleJumpToStart() {
|
|
8535
|
+
this.setPosition(0);
|
|
8536
|
+
this.emitBoundary("start");
|
|
8537
|
+
}
|
|
8538
|
+
_handleJumpToEnd() {
|
|
8539
|
+
this.setPosition(this.getDuration());
|
|
8540
|
+
this.emitBoundary("end");
|
|
8541
|
+
}
|
|
8542
|
+
_handleVerticalPrev() {
|
|
8543
|
+
if (this._verticalMode === "timeline-switch") this._emitTimelineChange("prev");
|
|
8544
|
+
else if (this._verticalMode === "chapter-navigation") this._jumpToPreviousMarker();
|
|
8545
|
+
}
|
|
8546
|
+
_handleVerticalNext() {
|
|
8547
|
+
if (this._verticalMode === "timeline-switch") this._emitTimelineChange("next");
|
|
8548
|
+
else if (this._verticalMode === "chapter-navigation") this._jumpToNextMarker();
|
|
8549
|
+
}
|
|
8550
|
+
_emitTimelineChange(direction) {
|
|
8551
|
+
for (const callback of this._timelineChangeCallbacks) callback(direction);
|
|
8552
|
+
}
|
|
8553
|
+
_jumpToPreviousMarker() {
|
|
8554
|
+
if (this._markers.length === 0) return;
|
|
8555
|
+
const currentPosition = this.getPosition();
|
|
8556
|
+
const currentMarkerIndex = this._findCurrentMarkerIndex(currentPosition);
|
|
8557
|
+
let targetIndex;
|
|
8558
|
+
if (this._markers[currentMarkerIndex] === currentPosition) if (currentMarkerIndex <= 0) if (this._wrapNavigation) targetIndex = this._markers.length - 1;
|
|
8559
|
+
else return;
|
|
8560
|
+
else targetIndex = currentMarkerIndex - 1;
|
|
8561
|
+
else targetIndex = currentMarkerIndex;
|
|
8562
|
+
const targetPosition = this._markers[targetIndex];
|
|
8563
|
+
this.setPosition(targetPosition);
|
|
8564
|
+
this._emitMarkerJump(targetIndex, targetPosition);
|
|
8565
|
+
}
|
|
8566
|
+
_jumpToNextMarker() {
|
|
8567
|
+
if (this._markers.length === 0) return;
|
|
8568
|
+
const currentPosition = this.getPosition();
|
|
8569
|
+
const currentMarkerIndex = this._findCurrentMarkerIndex(currentPosition);
|
|
8570
|
+
let targetIndex;
|
|
8571
|
+
if (currentMarkerIndex >= this._markers.length - 1) if (this._wrapNavigation) targetIndex = 0;
|
|
8572
|
+
else return;
|
|
8573
|
+
else targetIndex = currentMarkerIndex + 1;
|
|
8574
|
+
const targetPosition = this._markers[targetIndex];
|
|
8575
|
+
this.setPosition(targetPosition);
|
|
8576
|
+
this._emitMarkerJump(targetIndex, targetPosition);
|
|
8577
|
+
}
|
|
8578
|
+
/**
|
|
8579
|
+
* Find the index of the current or previous marker.
|
|
8580
|
+
*
|
|
8581
|
+
* If position matches a marker exactly, returns that marker's index.
|
|
8582
|
+
* Otherwise, returns the index of the marker before the current position.
|
|
8583
|
+
* Returns 0 if before first marker.
|
|
8584
|
+
*/
|
|
8585
|
+
_findCurrentMarkerIndex(position) {
|
|
8586
|
+
if (this._markers.length === 0) return -1;
|
|
8587
|
+
for (let i = this._markers.length - 1; i >= 0; i--) if (position >= this._markers[i]) return i;
|
|
8588
|
+
return 0;
|
|
8589
|
+
}
|
|
8590
|
+
_emitMarkerJump(markerIndex, position) {
|
|
8591
|
+
for (const callback of this._markerJumpCallbacks) callback(markerIndex, position);
|
|
8592
|
+
}
|
|
8593
|
+
};
|
|
8594
|
+
|
|
8595
|
+
//#endregion
|
|
8596
|
+
//#region src/util/animation-interval.ts
|
|
8597
|
+
function animationInterval(ms, signal, callback) {
|
|
8598
|
+
const currentTime = document?.timeline?.currentTime;
|
|
8599
|
+
const start = currentTime ? Number(currentTime) : performance.now();
|
|
8600
|
+
const frame = (time) => {
|
|
8601
|
+
if (signal.aborted) return;
|
|
8602
|
+
callback(time);
|
|
8603
|
+
scheduleFrame(time);
|
|
8604
|
+
};
|
|
8605
|
+
const { round } = Math;
|
|
8606
|
+
const scheduleFrame = (time) => {
|
|
8607
|
+
const delay = start + round((time - start) / ms) * ms + ms - performance.now();
|
|
8608
|
+
setTimeout(() => requestAnimationFrame(frame), delay);
|
|
8609
|
+
};
|
|
8610
|
+
scheduleFrame(start);
|
|
8611
|
+
}
|
|
8612
|
+
|
|
8613
|
+
//#endregion
|
|
8614
|
+
//#region src/timelineproviders/position-sources/raf-position-source.ts
|
|
8615
|
+
/**
|
|
8616
|
+
* RequestAnimationFrame-based position source.
|
|
8617
|
+
*
|
|
8618
|
+
* Uses the `animationInterval` utility to emit position updates at a regular
|
|
8619
|
+
* interval (default: 1 second). Position increments by 1 per second, making
|
|
8620
|
+
* position values equivalent to elapsed seconds.
|
|
8621
|
+
*
|
|
8622
|
+
* Implements both `IPositionSource` (via `BasePositionSource`) and `ISeekable`.
|
|
8623
|
+
*
|
|
8624
|
+
* @example
|
|
8625
|
+
* ```typescript
|
|
8626
|
+
* const source = new RafPositionSource({ duration: 60 });
|
|
8627
|
+
* await source.init();
|
|
8628
|
+
*
|
|
8629
|
+
* source.onPosition((position) => {
|
|
8630
|
+
* console.log(`Position: ${position}s`);
|
|
8631
|
+
* });
|
|
8632
|
+
*
|
|
8633
|
+
* source.onBoundaryReached((boundary) => {
|
|
8634
|
+
* if (boundary === 'end') {
|
|
8635
|
+
* console.log('Timeline complete');
|
|
8636
|
+
* }
|
|
8637
|
+
* });
|
|
8638
|
+
*
|
|
8639
|
+
* await source.activate();
|
|
8640
|
+
*
|
|
8641
|
+
* // Seek to 30 seconds
|
|
8642
|
+
* await source.seek(30);
|
|
8643
|
+
* ```
|
|
8644
|
+
*/
|
|
8645
|
+
var RafPositionSource = class extends BasePositionSource {
|
|
8646
|
+
_tickInterval;
|
|
8647
|
+
_abortController = null;
|
|
8648
|
+
_startTimeOffset = 0;
|
|
8649
|
+
/**
|
|
8650
|
+
* Create a new RAF-based position source.
|
|
8651
|
+
*
|
|
8652
|
+
* @param config - Configuration options
|
|
8653
|
+
*/
|
|
8654
|
+
constructor(config) {
|
|
8655
|
+
super(config.duration);
|
|
8656
|
+
this._tickInterval = config.tickInterval ?? 1e3;
|
|
8657
|
+
}
|
|
8658
|
+
doInit() {
|
|
8659
|
+
return Promise.resolve();
|
|
8660
|
+
}
|
|
8661
|
+
doDestroy() {
|
|
8662
|
+
this._abortTicking();
|
|
8663
|
+
}
|
|
8664
|
+
startTicking() {
|
|
8665
|
+
this.setPosition(this.getPosition());
|
|
8666
|
+
this._abortController = new AbortController();
|
|
8667
|
+
animationInterval(this._tickInterval, this._abortController.signal, this._onTick.bind(this));
|
|
8668
|
+
}
|
|
8669
|
+
stopTicking() {
|
|
8670
|
+
this._abortTicking();
|
|
8671
|
+
}
|
|
8672
|
+
/**
|
|
8673
|
+
* Seek to a specific position.
|
|
8674
|
+
*
|
|
8675
|
+
* Position is clamped to the valid range [0, duration].
|
|
8676
|
+
*
|
|
8677
|
+
* @param position - Target position in seconds
|
|
8678
|
+
* @returns Actual position after seek (may be clamped)
|
|
8679
|
+
*/
|
|
8680
|
+
async seek(position) {
|
|
8681
|
+
const clampedPosition = Math.max(0, Math.min(position, this.getDuration()));
|
|
8682
|
+
this.setPosition(clampedPosition);
|
|
8683
|
+
return clampedPosition;
|
|
8684
|
+
}
|
|
8685
|
+
/**
|
|
8686
|
+
* Handle a tick from animationInterval.
|
|
8687
|
+
*
|
|
8688
|
+
* The time parameter represents elapsed milliseconds since the animation
|
|
8689
|
+
* interval started. Position is calculated in seconds, rounded to the
|
|
8690
|
+
* precision determined by tickInterval.
|
|
8691
|
+
*
|
|
8692
|
+
* @param time - Elapsed time in milliseconds from animationInterval
|
|
8693
|
+
*/
|
|
8694
|
+
_onTick(time) {
|
|
8695
|
+
if (this.state !== "active") return;
|
|
8696
|
+
const elapsedSinceStart = time - this._startTimeOffset;
|
|
8697
|
+
const newPosition = Math.floor(elapsedSinceStart / this._tickInterval) * this._tickInterval / 1e3;
|
|
8698
|
+
const duration = this.getDuration();
|
|
8699
|
+
if (newPosition >= duration) {
|
|
8700
|
+
this.emitBoundary("end");
|
|
8701
|
+
if (this.loop) {
|
|
8702
|
+
this._startTimeOffset = time;
|
|
8703
|
+
this.setPosition(0);
|
|
8704
|
+
this.emitBoundary("start");
|
|
8705
|
+
} else {
|
|
8706
|
+
this.setPosition(duration);
|
|
8707
|
+
this.deactivate();
|
|
8708
|
+
}
|
|
8709
|
+
} else this.setPosition(newPosition);
|
|
8710
|
+
}
|
|
8711
|
+
/**
|
|
8712
|
+
* Abort the current ticking session.
|
|
8713
|
+
*/
|
|
8714
|
+
_abortTicking() {
|
|
8715
|
+
if (this._abortController) {
|
|
8716
|
+
this._abortController.abort();
|
|
8717
|
+
this._abortController = null;
|
|
8718
|
+
}
|
|
8719
|
+
}
|
|
8720
|
+
};
|
|
8721
|
+
|
|
8722
|
+
//#endregion
|
|
8723
|
+
//#region src/timelineproviders/position-sources/scroll-position-source.ts
|
|
8724
|
+
/**
|
|
8725
|
+
* Scroll-based position source.
|
|
8726
|
+
*
|
|
8727
|
+
* Maps scroll position to a timeline position. The position is calculated
|
|
8728
|
+
* as a percentage of the scroll progress multiplied by the configured duration.
|
|
8729
|
+
*
|
|
8730
|
+
* Implements `IPositionSource` and `ISeekable`.
|
|
8731
|
+
*
|
|
8732
|
+
* @example
|
|
8733
|
+
* ```typescript
|
|
8734
|
+
* const source = new ScrollPositionSource({
|
|
8735
|
+
* selector: '#scroll-container',
|
|
8736
|
+
* duration: 100, // 100 seconds timeline
|
|
8737
|
+
* });
|
|
8738
|
+
*
|
|
8739
|
+
* await source.init();
|
|
8740
|
+
*
|
|
8741
|
+
* source.onPosition((position) => {
|
|
8742
|
+
* console.log(`Scroll at ${position}s of 100s`);
|
|
8743
|
+
* });
|
|
8744
|
+
*
|
|
8745
|
+
* source.onBoundaryReached((boundary) => {
|
|
8746
|
+
* if (boundary === 'end') {
|
|
8747
|
+
* console.log('Scrolled to bottom');
|
|
8748
|
+
* }
|
|
8749
|
+
* });
|
|
8750
|
+
*
|
|
8751
|
+
* await source.activate();
|
|
8752
|
+
* ```
|
|
8753
|
+
*/
|
|
8754
|
+
var ScrollPositionSource = class extends BasePositionSource {
|
|
8755
|
+
_config;
|
|
8756
|
+
_element = null;
|
|
8757
|
+
_boundScrollHandler = null;
|
|
8758
|
+
_lastPosition = 0;
|
|
8759
|
+
_wasAtStart = true;
|
|
8760
|
+
/**
|
|
8761
|
+
* Create a new scroll-based position source.
|
|
8762
|
+
*
|
|
8763
|
+
* @param config - Configuration options
|
|
8764
|
+
*/
|
|
8765
|
+
constructor(config) {
|
|
8766
|
+
super(config.duration);
|
|
8767
|
+
this._config = config;
|
|
8768
|
+
}
|
|
8769
|
+
doInit() {
|
|
8770
|
+
return new Promise((resolve, reject) => {
|
|
8771
|
+
const $element = $(this._config.selector);
|
|
8772
|
+
if ($element.length === 0) {
|
|
8773
|
+
reject(/* @__PURE__ */ new Error(`Element not found: ${this._config.selector}`));
|
|
8774
|
+
return;
|
|
8775
|
+
}
|
|
8776
|
+
this._element = $element.get(0);
|
|
8777
|
+
resolve();
|
|
8778
|
+
});
|
|
8779
|
+
}
|
|
8780
|
+
doDestroy() {
|
|
8781
|
+
if (this._element && this._boundScrollHandler) {
|
|
8782
|
+
this._element.removeEventListener("scroll", this._boundScrollHandler, { passive: true });
|
|
8783
|
+
this._boundScrollHandler = null;
|
|
8784
|
+
}
|
|
8785
|
+
this._element = null;
|
|
8786
|
+
}
|
|
8787
|
+
startTicking() {
|
|
8788
|
+
if (!this._element) return;
|
|
8789
|
+
this._boundScrollHandler = this._handleScroll.bind(this);
|
|
8790
|
+
this._element.addEventListener("scroll", this._boundScrollHandler, { passive: true });
|
|
8791
|
+
}
|
|
8792
|
+
stopTicking() {
|
|
8793
|
+
if (this._element && this._boundScrollHandler) {
|
|
8794
|
+
this._element.removeEventListener("scroll", this._boundScrollHandler, { passive: true });
|
|
8795
|
+
this._boundScrollHandler = null;
|
|
8796
|
+
}
|
|
8797
|
+
}
|
|
8798
|
+
/**
|
|
8799
|
+
* Seek to a specific position by programmatically scrolling.
|
|
8800
|
+
*
|
|
8801
|
+
* @param position - Target position in seconds (0 to duration)
|
|
8802
|
+
* @returns Actual position after scroll
|
|
8803
|
+
*/
|
|
8804
|
+
async seek(position) {
|
|
8805
|
+
if (!this._element || this.state === "inactive") return this.getPosition();
|
|
8806
|
+
const scrollableHeight = this._getScrollableHeight();
|
|
8807
|
+
const targetScrollTop = position / this._config.duration * scrollableHeight;
|
|
8808
|
+
this._element.scrollTo({
|
|
8809
|
+
top: targetScrollTop,
|
|
8810
|
+
behavior: "smooth"
|
|
8811
|
+
});
|
|
8812
|
+
return position;
|
|
8813
|
+
}
|
|
8814
|
+
/**
|
|
8815
|
+
* Handle scroll events and update position.
|
|
8816
|
+
*/
|
|
8817
|
+
_handleScroll(_event) {
|
|
8818
|
+
if (this.state !== "active" || !this._element) return;
|
|
8819
|
+
const position = this._calculatePosition();
|
|
8820
|
+
const duration = this._config.duration;
|
|
8821
|
+
const previousPosition = this._lastPosition;
|
|
8822
|
+
this._lastPosition = position;
|
|
8823
|
+
this.setPosition(position);
|
|
8824
|
+
if (position >= duration && previousPosition < duration) {
|
|
8825
|
+
this.emitBoundary("end");
|
|
8826
|
+
if (this.loop) this._element.scrollTo({
|
|
8827
|
+
top: 0,
|
|
8828
|
+
behavior: "smooth"
|
|
8829
|
+
});
|
|
8830
|
+
}
|
|
8831
|
+
if (position === 0 && previousPosition > 0 && !this._wasAtStart) this.emitBoundary("start");
|
|
8832
|
+
this._wasAtStart = position === 0;
|
|
8833
|
+
}
|
|
8834
|
+
/**
|
|
8835
|
+
* Calculate position from scroll percentage.
|
|
8836
|
+
*/
|
|
8837
|
+
_calculatePosition() {
|
|
8838
|
+
if (!this._element) return 0;
|
|
8839
|
+
const scrollTop = this._element.scrollTop;
|
|
8840
|
+
const scrollableHeight = this._getScrollableHeight();
|
|
8841
|
+
if (scrollableHeight <= 0) return 0;
|
|
8842
|
+
return scrollTop / scrollableHeight * this._config.duration;
|
|
8843
|
+
}
|
|
8844
|
+
/**
|
|
8845
|
+
* Get the scrollable height (total scroll distance).
|
|
8846
|
+
*/
|
|
8847
|
+
_getScrollableHeight() {
|
|
8848
|
+
if (!this._element) return 0;
|
|
8849
|
+
return this._element.scrollHeight - this._element.clientHeight;
|
|
8850
|
+
}
|
|
8851
|
+
};
|
|
8852
|
+
|
|
8853
|
+
//#endregion
|
|
8854
|
+
//#region src/timelineproviders/position-sources/video-position-source.ts
|
|
8855
|
+
const videojs = vjs.default ?? vjs;
|
|
8856
|
+
/**
|
|
8857
|
+
* Video.js-based position source.
|
|
8858
|
+
*
|
|
8859
|
+
* Wraps a video.js player to provide position updates based on video playback.
|
|
8860
|
+
* Implements `IPositionSource`, `ISeekable`, and `IContainerProvider`.
|
|
8861
|
+
*
|
|
8862
|
+
* @example
|
|
8863
|
+
* ```typescript
|
|
8864
|
+
* const source = new VideoPositionSource({
|
|
8865
|
+
* selector: '#video-container',
|
|
8866
|
+
* sources: [
|
|
8867
|
+
* { src: 'video.mp4', type: 'video/mp4' },
|
|
8868
|
+
* { src: 'video.webm', type: 'video/webm' },
|
|
8869
|
+
* ],
|
|
8870
|
+
* });
|
|
8871
|
+
*
|
|
8872
|
+
* await source.init();
|
|
8873
|
+
*
|
|
8874
|
+
* source.onPosition((position) => {
|
|
8875
|
+
* console.log(`Video at ${position}s`);
|
|
8876
|
+
* });
|
|
8877
|
+
*
|
|
8878
|
+
* source.onContainerReady(() => {
|
|
8879
|
+
* console.log('Video ready for display');
|
|
8880
|
+
* });
|
|
8881
|
+
*
|
|
8882
|
+
* await source.activate();
|
|
8883
|
+
* ```
|
|
8884
|
+
*/
|
|
8885
|
+
var VideoPositionSource = class extends BasePositionSource {
|
|
8886
|
+
_config;
|
|
8887
|
+
_player = null;
|
|
8888
|
+
_videoElementId;
|
|
8889
|
+
_containerReadyCallbacks = [];
|
|
8890
|
+
_eventHandlers = [];
|
|
8891
|
+
/**
|
|
8892
|
+
* Create a new video.js-based position source.
|
|
8893
|
+
*
|
|
8894
|
+
* @param config - Configuration options
|
|
8895
|
+
*/
|
|
8896
|
+
constructor(config) {
|
|
8897
|
+
super(0);
|
|
8898
|
+
this._config = config;
|
|
8899
|
+
this._videoElementId = `video-${crypto.randomUUID?.() ?? Math.random().toString(36).slice(2)}`;
|
|
8900
|
+
}
|
|
8901
|
+
doInit() {
|
|
8902
|
+
return new Promise((resolve) => {
|
|
8903
|
+
this._createVideoElement();
|
|
8904
|
+
setTimeout(() => {
|
|
8905
|
+
this._player = videojs(this._videoElementId, {
|
|
8906
|
+
controls: false,
|
|
8907
|
+
controlBar: false,
|
|
8908
|
+
liveui: false,
|
|
8909
|
+
autoplay: false,
|
|
8910
|
+
preload: "auto",
|
|
8911
|
+
loop: this.loop,
|
|
8912
|
+
sources: this._config.sources,
|
|
8913
|
+
...this._config.options
|
|
8914
|
+
}, () => {
|
|
8915
|
+
if (this._player) {
|
|
8916
|
+
this._addPlayerListener("timeupdate", this._handleTimeUpdate.bind(this));
|
|
8917
|
+
this._addPlayerListener("ended", this._handleEnded.bind(this));
|
|
8918
|
+
this._player.one("firstplay", () => {
|
|
8919
|
+
this._notifyContainerReady();
|
|
8920
|
+
});
|
|
8921
|
+
this._player.one("canplay", () => {
|
|
8922
|
+
resolve();
|
|
8923
|
+
});
|
|
8924
|
+
this._player.load();
|
|
8925
|
+
}
|
|
8926
|
+
});
|
|
8927
|
+
}, 0);
|
|
8928
|
+
});
|
|
8929
|
+
}
|
|
8930
|
+
doDestroy() {
|
|
8931
|
+
for (const removeHandler of this._eventHandlers) removeHandler();
|
|
8932
|
+
this._eventHandlers.length = 0;
|
|
8933
|
+
if (this._player) {
|
|
8934
|
+
this._player.dispose?.();
|
|
8935
|
+
this._player = null;
|
|
8936
|
+
}
|
|
8937
|
+
$(`#${this._videoElementId}`).remove();
|
|
8938
|
+
}
|
|
8939
|
+
startTicking() {
|
|
8940
|
+
this._player?.play();
|
|
8941
|
+
}
|
|
8942
|
+
stopTicking() {
|
|
8943
|
+
this._player?.pause();
|
|
8944
|
+
}
|
|
8945
|
+
/**
|
|
8946
|
+
* Seek to a specific position in the video.
|
|
8947
|
+
*
|
|
8948
|
+
* @param position - Target position in seconds
|
|
8949
|
+
* @returns Actual position after seek
|
|
8950
|
+
*/
|
|
8951
|
+
async seek(position) {
|
|
8952
|
+
if (!this._player) return this.getPosition();
|
|
8953
|
+
return new Promise((resolve) => {
|
|
8954
|
+
this._player.one("seeked", () => {
|
|
8955
|
+
const actualPosition = this._player?.currentTime() ?? 0;
|
|
8956
|
+
this.setPosition(actualPosition);
|
|
8957
|
+
resolve(actualPosition);
|
|
8958
|
+
});
|
|
8959
|
+
this._player.currentTime(position);
|
|
8960
|
+
});
|
|
8961
|
+
}
|
|
8962
|
+
/**
|
|
8963
|
+
* Get the container element.
|
|
8964
|
+
*
|
|
8965
|
+
* @returns jQuery-wrapped container element
|
|
8966
|
+
*/
|
|
8967
|
+
getContainer() {
|
|
8968
|
+
return $(this._config.selector);
|
|
8969
|
+
}
|
|
8970
|
+
/**
|
|
8971
|
+
* Register a callback for when the container is ready.
|
|
8972
|
+
*
|
|
8973
|
+
* @param callback - Function called when container is ready
|
|
8974
|
+
*/
|
|
8975
|
+
onContainerReady(callback) {
|
|
8976
|
+
this._containerReadyCallbacks.push(callback);
|
|
8977
|
+
}
|
|
8978
|
+
/**
|
|
8979
|
+
* Get the video duration.
|
|
8980
|
+
*
|
|
8981
|
+
* @returns Duration in seconds from video.js player
|
|
8982
|
+
*/
|
|
8983
|
+
getDuration() {
|
|
8984
|
+
return this._player?.duration() ?? 0;
|
|
8985
|
+
}
|
|
8986
|
+
/**
|
|
8987
|
+
* Deactivate the source and reset position.
|
|
8988
|
+
*
|
|
8989
|
+
* Overrides base to also reset video currentTime.
|
|
8990
|
+
*/
|
|
8991
|
+
deactivate() {
|
|
8992
|
+
if (this.state === "inactive") return;
|
|
8993
|
+
if (this.state === "active") this.stopTicking();
|
|
8994
|
+
this._player?.currentTime(0);
|
|
8995
|
+
super.deactivate();
|
|
8996
|
+
}
|
|
8997
|
+
/**
|
|
8998
|
+
* Create the video element in the container.
|
|
8999
|
+
*/
|
|
9000
|
+
_createVideoElement() {
|
|
9001
|
+
const $container = $(this._config.selector);
|
|
9002
|
+
const videoHtml = `<video id="${this._videoElementId}" class="video-js"></video>`;
|
|
9003
|
+
$container.append(videoHtml);
|
|
9004
|
+
}
|
|
9005
|
+
/**
|
|
9006
|
+
* Add an event listener to the player and track for cleanup.
|
|
9007
|
+
*
|
|
9008
|
+
* @param event - Event name
|
|
9009
|
+
* @param handler - Event handler
|
|
9010
|
+
*/
|
|
9011
|
+
_addPlayerListener(event, handler) {
|
|
9012
|
+
if (this._player) {
|
|
9013
|
+
this._player.on(event, handler);
|
|
9014
|
+
this._eventHandlers.push(() => {
|
|
9015
|
+
this._player?.off(event, handler);
|
|
9016
|
+
});
|
|
9017
|
+
}
|
|
9018
|
+
}
|
|
9019
|
+
/**
|
|
9020
|
+
* Handle timeupdate event from video.js.
|
|
9021
|
+
*/
|
|
9022
|
+
_handleTimeUpdate() {
|
|
9023
|
+
if (this.state !== "active" || !this._player) return;
|
|
9024
|
+
const currentTime = this._player.currentTime();
|
|
9025
|
+
if (currentTime !== void 0) this.setPosition(currentTime);
|
|
9026
|
+
}
|
|
9027
|
+
/**
|
|
9028
|
+
* Handle ended event from video.js.
|
|
9029
|
+
*/
|
|
9030
|
+
_handleEnded() {
|
|
9031
|
+
if (this.state !== "active") return;
|
|
9032
|
+
this.emitBoundary("end");
|
|
9033
|
+
if (this.loop) {
|
|
9034
|
+
this._player?.currentTime(0);
|
|
9035
|
+
this.setPosition(0);
|
|
9036
|
+
this.emitBoundary("start");
|
|
9037
|
+
this._player?.play();
|
|
9038
|
+
} else this.deactivate();
|
|
9039
|
+
}
|
|
9040
|
+
/**
|
|
9041
|
+
* Notify all container ready callbacks.
|
|
9042
|
+
*/
|
|
9043
|
+
_notifyContainerReady() {
|
|
9044
|
+
for (const callback of this._containerReadyCallbacks) callback();
|
|
9045
|
+
}
|
|
9046
|
+
};
|
|
9047
|
+
|
|
9048
|
+
//#endregion
|
|
9049
|
+
//#region src/timelineproviders/container-providers/dom-container-provider.ts
|
|
9050
|
+
/**
|
|
9051
|
+
* DOM selector-based container provider.
|
|
9052
|
+
*
|
|
9053
|
+
* Provides access to a DOM container element via a CSS selector.
|
|
9054
|
+
* Implements `IContainerProvider` for use with position sources that
|
|
9055
|
+
* don't have an intrinsic container (e.g., RAF-based sources, WebSocket sources).
|
|
9056
|
+
*
|
|
9057
|
+
* @example
|
|
9058
|
+
* ```typescript
|
|
9059
|
+
* const containerProvider = new DomContainerProvider({
|
|
9060
|
+
* selector: '#timeline-container',
|
|
9061
|
+
* });
|
|
9062
|
+
*
|
|
9063
|
+
* containerProvider.onContainerReady(() => {
|
|
9064
|
+
* const $container = containerProvider.getContainer();
|
|
9065
|
+
* $container?.append('<div class="content">Ready!</div>');
|
|
9066
|
+
* });
|
|
9067
|
+
*
|
|
9068
|
+
* await containerProvider.init();
|
|
9069
|
+
* ```
|
|
9070
|
+
*/
|
|
9071
|
+
var DomContainerProvider = class {
|
|
9072
|
+
_config;
|
|
9073
|
+
_container;
|
|
9074
|
+
_isReady = false;
|
|
9075
|
+
_isDestroyed = false;
|
|
9076
|
+
_readyCallbacks = [];
|
|
9077
|
+
/**
|
|
9078
|
+
* Create a new DOM container provider.
|
|
9079
|
+
*
|
|
9080
|
+
* @param config - Configuration options
|
|
9081
|
+
*/
|
|
9082
|
+
constructor(config) {
|
|
9083
|
+
this._config = config;
|
|
9084
|
+
}
|
|
9085
|
+
/**
|
|
9086
|
+
* Initialize the container provider.
|
|
9087
|
+
*
|
|
9088
|
+
* Looks up the container element using the configured selector.
|
|
9089
|
+
*
|
|
9090
|
+
* @throws Error if the element is not found
|
|
9091
|
+
*/
|
|
9092
|
+
async init() {
|
|
9093
|
+
if (this._isReady) return;
|
|
9094
|
+
const $element = $(this._config.selector);
|
|
9095
|
+
if ($element.length === 0) throw new Error(`Container element not found: ${this._config.selector}`);
|
|
9096
|
+
this._container = $element;
|
|
9097
|
+
this._isReady = true;
|
|
9098
|
+
this._notifyReady();
|
|
9099
|
+
}
|
|
9100
|
+
/**
|
|
9101
|
+
* Destroy the container provider and release resources.
|
|
9102
|
+
*/
|
|
9103
|
+
destroy() {
|
|
9104
|
+
this._container = void 0;
|
|
9105
|
+
this._isReady = false;
|
|
9106
|
+
this._isDestroyed = true;
|
|
9107
|
+
this._readyCallbacks.length = 0;
|
|
9108
|
+
}
|
|
9109
|
+
/**
|
|
9110
|
+
* Get the container element.
|
|
9111
|
+
*
|
|
9112
|
+
* @returns jQuery-wrapped container element, or `undefined` if not initialized
|
|
9113
|
+
*/
|
|
9114
|
+
getContainer() {
|
|
9115
|
+
return this._container;
|
|
9116
|
+
}
|
|
9117
|
+
/**
|
|
9118
|
+
* Register a callback for when the container is ready.
|
|
9119
|
+
*
|
|
9120
|
+
* If the container is already ready, the callback is invoked immediately.
|
|
9121
|
+
*
|
|
9122
|
+
* @param callback - Function called when container is ready
|
|
9123
|
+
*/
|
|
9124
|
+
onContainerReady(callback) {
|
|
9125
|
+
if (this._isDestroyed) return;
|
|
9126
|
+
if (this._isReady) callback();
|
|
9127
|
+
else this._readyCallbacks.push(callback);
|
|
9128
|
+
}
|
|
9129
|
+
/**
|
|
9130
|
+
* Notify all registered ready callbacks.
|
|
9131
|
+
*/
|
|
9132
|
+
_notifyReady() {
|
|
9133
|
+
for (const callback of this._readyCallbacks) callback();
|
|
9134
|
+
}
|
|
9135
|
+
};
|
|
9136
|
+
|
|
9137
|
+
//#endregion
|
|
9138
|
+
//#region src/timelineproviders/playlist/simple-playlist.ts
|
|
9139
|
+
/**
|
|
9140
|
+
* Simple playlist implementation.
|
|
9141
|
+
*
|
|
9142
|
+
* Manages a collection of timeline items and allows switching between them.
|
|
9143
|
+
* Implements `IPlaylist<TItem>` for use with timeline providers that
|
|
9144
|
+
* support multiple content sources.
|
|
9145
|
+
*
|
|
9146
|
+
* @typeParam TItem - Type of playlist items
|
|
9147
|
+
*
|
|
9148
|
+
* @example
|
|
9149
|
+
* ```typescript
|
|
9150
|
+
* interface VideoItem {
|
|
9151
|
+
* id: string;
|
|
9152
|
+
* uri: string;
|
|
9153
|
+
* title: string;
|
|
9154
|
+
* }
|
|
9155
|
+
*
|
|
9156
|
+
* const playlist = new SimplePlaylist<VideoItem>({
|
|
9157
|
+
* items: [
|
|
9158
|
+
* { id: 'intro', uri: '/videos/intro.mp4', title: 'Introduction' },
|
|
9159
|
+
* { id: 'ch1', uri: '/videos/chapter-1.mp4', title: 'Chapter 1' },
|
|
9160
|
+
* ],
|
|
9161
|
+
* identifierKey: 'id',
|
|
9162
|
+
* });
|
|
9163
|
+
*
|
|
9164
|
+
* playlist.onItemChange((item) => {
|
|
9165
|
+
* console.log(`Now playing: ${item.title}`);
|
|
9166
|
+
* });
|
|
9167
|
+
*
|
|
9168
|
+
* playlist.selectItem('ch1');
|
|
9169
|
+
* ```
|
|
9170
|
+
*/
|
|
9171
|
+
var SimplePlaylist = class {
|
|
9172
|
+
_items;
|
|
9173
|
+
_identifierKey;
|
|
9174
|
+
_currentIndex = 0;
|
|
9175
|
+
_changeCallbacks = [];
|
|
9176
|
+
/**
|
|
9177
|
+
* Create a new simple playlist.
|
|
9178
|
+
*
|
|
9179
|
+
* @param config - Configuration options
|
|
9180
|
+
* @throws Error if items array is empty
|
|
9181
|
+
*/
|
|
9182
|
+
constructor(config) {
|
|
9183
|
+
if (!config.items || config.items.length === 0) throw new Error("Playlist must have at least one item");
|
|
9184
|
+
this._items = Object.freeze([...config.items]);
|
|
9185
|
+
this._identifierKey = config.identifierKey;
|
|
9186
|
+
}
|
|
9187
|
+
/**
|
|
9188
|
+
* Get the currently active item.
|
|
9189
|
+
*/
|
|
9190
|
+
get currentItem() {
|
|
9191
|
+
return this._items[this._currentIndex];
|
|
9192
|
+
}
|
|
9193
|
+
/**
|
|
9194
|
+
* Get all items in the playlist.
|
|
9195
|
+
*
|
|
9196
|
+
* Returns a readonly array to prevent external modification.
|
|
9197
|
+
*/
|
|
9198
|
+
get items() {
|
|
9199
|
+
return this._items;
|
|
9200
|
+
}
|
|
9201
|
+
/**
|
|
9202
|
+
* Select an item by identifier.
|
|
9203
|
+
*
|
|
9204
|
+
* Looks up the item using the configured identifier key and switches
|
|
9205
|
+
* to it if found. Triggers item change callbacks if the selection changes.
|
|
9206
|
+
*
|
|
9207
|
+
* @param identifier - Unique identifier for the item
|
|
9208
|
+
* @throws Error if no item matches the identifier
|
|
9209
|
+
*/
|
|
9210
|
+
selectItem(identifier) {
|
|
9211
|
+
const index = this._items.findIndex((item) => String(item[this._identifierKey]) === identifier);
|
|
9212
|
+
if (index === -1) throw new Error(`Playlist item not found: ${identifier}`);
|
|
9213
|
+
if (index !== this._currentIndex) {
|
|
9214
|
+
this._currentIndex = index;
|
|
9215
|
+
this._notifyChange();
|
|
9216
|
+
}
|
|
9217
|
+
}
|
|
9218
|
+
/**
|
|
9219
|
+
* Register a callback for item changes.
|
|
9220
|
+
*
|
|
9221
|
+
* Called whenever the current item changes via `selectItem()`.
|
|
9222
|
+
*
|
|
9223
|
+
* @param callback - Function receiving the new current item
|
|
9224
|
+
*/
|
|
9225
|
+
onItemChange(callback) {
|
|
9226
|
+
this._changeCallbacks.push(callback);
|
|
9227
|
+
}
|
|
9228
|
+
/**
|
|
9229
|
+
* Notify all registered change callbacks.
|
|
9230
|
+
*/
|
|
9231
|
+
_notifyChange() {
|
|
9232
|
+
const currentItem = this.currentItem;
|
|
9233
|
+
for (const callback of this._changeCallbacks) callback(currentItem);
|
|
9234
|
+
}
|
|
9235
|
+
};
|
|
9236
|
+
|
|
9237
|
+
//#endregion
|
|
9238
|
+
//#region src/timelineproviders/index.ts
|
|
9239
|
+
var timelineproviders_exports = /* @__PURE__ */ __export({
|
|
9240
|
+
BasePositionSource: () => BasePositionSource,
|
|
9241
|
+
DomContainerProvider: () => DomContainerProvider,
|
|
9242
|
+
KeyboardStepSource: () => KeyboardStepSource,
|
|
9243
|
+
RafPositionSource: () => RafPositionSource,
|
|
9244
|
+
ScrollPositionSource: () => ScrollPositionSource,
|
|
9245
|
+
SimplePlaylist: () => SimplePlaylist,
|
|
9246
|
+
VideoPositionSource: () => VideoPositionSource,
|
|
9247
|
+
isSeekable: () => isSeekable
|
|
9248
|
+
});
|
|
9249
|
+
|
|
9250
|
+
//#endregion
|
|
9251
|
+
//#region src/util/typed-event-emitter.ts
|
|
9252
|
+
/**
|
|
9253
|
+
* Type-safe event emitter implementation
|
|
9254
|
+
*
|
|
9255
|
+
* Features:
|
|
9256
|
+
* - Generic type parameter for event map
|
|
9257
|
+
* - Handler execution order preserved (registration order)
|
|
9258
|
+
* - Errors in handlers caught and logged (don't break other handlers)
|
|
9259
|
+
* - Copy handlers array during emit (safe removal during iteration)
|
|
9260
|
+
*
|
|
9261
|
+
* @example
|
|
9262
|
+
* ```typescript
|
|
9263
|
+
* interface MyEvents {
|
|
9264
|
+
* start: [];
|
|
9265
|
+
* data: [value: string];
|
|
9266
|
+
* progress: [current: number, total: number];
|
|
9267
|
+
* }
|
|
9268
|
+
*
|
|
9269
|
+
* const emitter = new TypedEventEmitter<MyEvents>();
|
|
9270
|
+
*
|
|
9271
|
+
* const unsubscribe = emitter.on('data', (value) => {
|
|
9272
|
+
* console.log('Received:', value);
|
|
9273
|
+
* });
|
|
9274
|
+
*
|
|
9275
|
+
* emitter.emit('data', 'hello');
|
|
9276
|
+
* unsubscribe();
|
|
9277
|
+
* ```
|
|
9278
|
+
*/
|
|
9279
|
+
var TypedEventEmitter = class {
|
|
9280
|
+
handlers = /* @__PURE__ */ new Map();
|
|
9281
|
+
/**
|
|
9282
|
+
* Subscribe to an event
|
|
9283
|
+
* @param event - Event name
|
|
9284
|
+
* @param handler - Event handler
|
|
9285
|
+
* @returns Unsubscribe function
|
|
9286
|
+
*/
|
|
9287
|
+
on(event, handler) {
|
|
9288
|
+
if (!this.handlers.has(event)) this.handlers.set(event, []);
|
|
9289
|
+
this.handlers.get(event).push(handler);
|
|
9290
|
+
return () => this.off(event, handler);
|
|
9291
|
+
}
|
|
9292
|
+
/**
|
|
9293
|
+
* Subscribe to an event for one-time execution
|
|
9294
|
+
* @param event - Event name
|
|
9295
|
+
* @param handler - Event handler
|
|
9296
|
+
* @returns Unsubscribe function
|
|
9297
|
+
*/
|
|
9298
|
+
once(event, handler) {
|
|
9299
|
+
const onceHandler = (...args) => {
|
|
9300
|
+
this.off(event, onceHandler);
|
|
9301
|
+
handler(...args);
|
|
9302
|
+
};
|
|
9303
|
+
return this.on(event, onceHandler);
|
|
9304
|
+
}
|
|
9305
|
+
/**
|
|
9306
|
+
* Unsubscribe from an event
|
|
9307
|
+
* @param event - Event name
|
|
9308
|
+
* @param handler - Event handler to remove
|
|
9309
|
+
*/
|
|
9310
|
+
off(event, handler) {
|
|
9311
|
+
const eventHandlers = this.handlers.get(event);
|
|
9312
|
+
if (!eventHandlers) return;
|
|
9313
|
+
const index = eventHandlers.indexOf(handler);
|
|
9314
|
+
if (index !== -1) eventHandlers.splice(index, 1);
|
|
9315
|
+
}
|
|
9316
|
+
/**
|
|
9317
|
+
* Emit an event to all subscribers
|
|
9318
|
+
*
|
|
9319
|
+
* Features:
|
|
9320
|
+
* - Copies handlers array to allow safe removal during iteration
|
|
9321
|
+
* - Isolates errors - one failing handler doesn't break others
|
|
9322
|
+
* - Logs errors to console for debugging
|
|
9323
|
+
*
|
|
9324
|
+
* @param event - Event name
|
|
9325
|
+
* @param args - Event arguments
|
|
9326
|
+
*/
|
|
9327
|
+
emit(event, ...args) {
|
|
9328
|
+
const eventHandlers = this.handlers.get(event);
|
|
9329
|
+
if (!eventHandlers || eventHandlers.length === 0) return;
|
|
9330
|
+
const handlersCopy = [...eventHandlers];
|
|
9331
|
+
for (const handler of handlersCopy) try {
|
|
9332
|
+
handler(...args);
|
|
9333
|
+
} catch (error) {
|
|
9334
|
+
console.error(`Error in event handler for "${String(event)}":`, error);
|
|
9335
|
+
}
|
|
9336
|
+
}
|
|
9337
|
+
/**
|
|
9338
|
+
* Remove all listeners for a specific event or all events
|
|
9339
|
+
* @param event - Optional event name. If not provided, removes all listeners.
|
|
9340
|
+
*/
|
|
9341
|
+
removeAllListeners(event) {
|
|
9342
|
+
if (event !== void 0) this.handlers.delete(event);
|
|
9343
|
+
else this.handlers.clear();
|
|
9344
|
+
}
|
|
9345
|
+
};
|
|
9346
|
+
|
|
9347
|
+
//#endregion
|
|
9348
|
+
//#region src/eligius-engine.ts
|
|
9349
|
+
/**
|
|
9350
|
+
* Type guard to check if a position source supports seeking.
|
|
9351
|
+
*/
|
|
9352
|
+
function isSeekable$1(source) {
|
|
9353
|
+
return "seek" in source && typeof source.seek === "function";
|
|
9354
|
+
}
|
|
9355
|
+
/**
|
|
9356
|
+
* Maps position source state to engine play state.
|
|
9357
|
+
*/
|
|
9358
|
+
function mapSourceStateToPlayState(sourceState) {
|
|
9359
|
+
switch (sourceState) {
|
|
9360
|
+
case "active": return "playing";
|
|
9361
|
+
case "suspended": return "paused";
|
|
9362
|
+
case "inactive": return "stopped";
|
|
9363
|
+
}
|
|
9364
|
+
}
|
|
9365
|
+
/**
|
|
9366
|
+
* The Eligius timeline engine with explicit, testable API.
|
|
9367
|
+
*
|
|
9368
|
+
* This engine is responsible for starting and stopping the given timeline provider
|
|
9369
|
+
* and triggering the actions associated with positions along the timeline.
|
|
9370
|
+
*/
|
|
9371
|
+
var EligiusEngine = class EligiusEngine {
|
|
9372
|
+
_timeLineActionsLookup = {};
|
|
9373
|
+
_timelineLookupCache = /* @__PURE__ */ new Map();
|
|
9374
|
+
_eventbusRemovers = [];
|
|
9375
|
+
_currentTimelineUri = "";
|
|
9376
|
+
_activePositionSource = void 0;
|
|
9377
|
+
_activeContainerProvider = void 0;
|
|
9378
|
+
_activePlaylist = void 0;
|
|
9379
|
+
_lastPosition = -1;
|
|
9380
|
+
_emitter = new TypedEventEmitter();
|
|
9381
|
+
/** Current timeline position in seconds (supports fractional values) */
|
|
9382
|
+
get position() {
|
|
9383
|
+
return this._activePositionSource?.getPosition() ?? 0;
|
|
9384
|
+
}
|
|
9385
|
+
/** Timeline duration in seconds, undefined if not yet available */
|
|
9386
|
+
get duration() {
|
|
9387
|
+
return this._activePositionSource?.getDuration();
|
|
9388
|
+
}
|
|
9389
|
+
/** Current playback state (derived from position source state) */
|
|
9390
|
+
get playState() {
|
|
9391
|
+
if (!this._activePositionSource) return "stopped";
|
|
9392
|
+
return mapSourceStateToPlayState(this._activePositionSource.state);
|
|
9393
|
+
}
|
|
9394
|
+
/** URI of the currently active timeline */
|
|
9395
|
+
get currentTimelineUri() {
|
|
9396
|
+
return this._currentTimelineUri;
|
|
9397
|
+
}
|
|
9398
|
+
/** Container element for the active timeline provider */
|
|
9399
|
+
get container() {
|
|
9400
|
+
return this._activeContainerProvider?.getContainer();
|
|
9401
|
+
}
|
|
9402
|
+
/** Root element of the engine (container selector) */
|
|
9403
|
+
get engineRoot() {
|
|
9404
|
+
return $(this.configuration.containerSelector);
|
|
9405
|
+
}
|
|
9406
|
+
constructor(configuration, eventbus$1, timelineProviders, languageManager) {
|
|
9407
|
+
this.configuration = configuration;
|
|
9408
|
+
this.eventbus = eventbus$1;
|
|
9409
|
+
this.timelineProviders = timelineProviders;
|
|
9410
|
+
this.languageManager = languageManager;
|
|
9411
|
+
}
|
|
9412
|
+
/**
|
|
9413
|
+
* Subscribe to engine events
|
|
9414
|
+
* @param event - Event name
|
|
9415
|
+
* @param handler - Event handler
|
|
9416
|
+
* @returns Unsubscribe function
|
|
9417
|
+
*/
|
|
9418
|
+
on(event, handler) {
|
|
9419
|
+
return this._emitter.on(event, handler);
|
|
9420
|
+
}
|
|
9421
|
+
/**
|
|
9422
|
+
* Start playback
|
|
9423
|
+
* @throws If autoplay is blocked (video provider)
|
|
9424
|
+
*/
|
|
9425
|
+
async start() {
|
|
9426
|
+
if (!this._activePositionSource) return;
|
|
9427
|
+
await this._activePositionSource.activate();
|
|
9428
|
+
this._emitter.emit("start");
|
|
9429
|
+
this.eventbus.broadcast("timeline-play", []);
|
|
9430
|
+
}
|
|
9431
|
+
/**
|
|
9432
|
+
* Pause playback
|
|
9433
|
+
*/
|
|
9434
|
+
pause() {
|
|
9435
|
+
if (!this._activePositionSource) return;
|
|
9436
|
+
this._activePositionSource.suspend();
|
|
9437
|
+
this._emitter.emit("pause");
|
|
9438
|
+
this.eventbus.broadcast("timeline-pause", []);
|
|
9439
|
+
}
|
|
9440
|
+
/**
|
|
9441
|
+
* Stop playback and reset to beginning
|
|
9442
|
+
*/
|
|
9443
|
+
stop() {
|
|
9444
|
+
if (!this._activePositionSource) return;
|
|
9445
|
+
this._activePositionSource.deactivate();
|
|
9446
|
+
this._emitter.emit("stop");
|
|
9447
|
+
this.eventbus.broadcast("timeline-stop", []);
|
|
9448
|
+
}
|
|
9449
|
+
/**
|
|
9450
|
+
* Seek to a specific position
|
|
9451
|
+
* @param position - Target position in seconds
|
|
9452
|
+
* @returns Actual position after seek
|
|
9453
|
+
*/
|
|
9454
|
+
async seek(position) {
|
|
9455
|
+
if (!this._activePositionSource) return 0;
|
|
9456
|
+
const seekPosition = position;
|
|
9457
|
+
const duration = this._activePositionSource.getDuration();
|
|
9458
|
+
const currentPosition = this._activePositionSource.getPosition();
|
|
9459
|
+
if (seekPosition < 0 || seekPosition > duration) return currentPosition;
|
|
9460
|
+
this._emitter.emit("seekStart", seekPosition, currentPosition, duration);
|
|
9461
|
+
this.eventbus.broadcast("timeline-seek", [
|
|
9462
|
+
seekPosition,
|
|
9463
|
+
currentPosition,
|
|
9464
|
+
duration
|
|
9465
|
+
]);
|
|
9466
|
+
if (isSeekable$1(this._activePositionSource)) await this._activePositionSource.seek(seekPosition);
|
|
9467
|
+
await this._executeSeekActions(seekPosition);
|
|
9468
|
+
const finalPosition = this._activePositionSource.getPosition();
|
|
9469
|
+
this._emitter.emit("seekComplete", finalPosition, duration);
|
|
9470
|
+
this.eventbus.broadcast("timeline-seeked", [finalPosition, duration]);
|
|
9471
|
+
this._emitter.emit("time", finalPosition);
|
|
9472
|
+
this.eventbus.broadcast("timeline-time", [finalPosition]);
|
|
9473
|
+
if (this._activePositionSource.state === "active") await this._activePositionSource.activate();
|
|
9474
|
+
return finalPosition;
|
|
9475
|
+
}
|
|
9476
|
+
/**
|
|
9477
|
+
* Switch to a different timeline
|
|
9478
|
+
* @param uri - Timeline URI to switch to
|
|
9479
|
+
* @param position - Optional starting position
|
|
9480
|
+
*/
|
|
9481
|
+
async switchTimeline(uri, position = 0) {
|
|
9482
|
+
if (!this._activePositionSource) return;
|
|
9483
|
+
const timelineConfig = this._timelineLookupCache.get(uri);
|
|
9484
|
+
if (!timelineConfig || this._currentTimelineUri === timelineConfig.uri) return;
|
|
9485
|
+
this._activePositionSource.deactivate();
|
|
9486
|
+
await this._cleanUpTimeline();
|
|
9487
|
+
this._currentTimelineUri = timelineConfig.uri;
|
|
9488
|
+
this._emitter.emit("timelineChange", this._currentTimelineUri);
|
|
9489
|
+
this.eventbus.broadcast("timeline-current-timeline-change", [this._currentTimelineUri]);
|
|
9490
|
+
const newProviderSettings = this.timelineProviders[timelineConfig.type];
|
|
9491
|
+
if (this._activePositionSource !== newProviderSettings.positionSource) {
|
|
9492
|
+
this._activePositionSource.destroy();
|
|
9493
|
+
this._activePositionSource = newProviderSettings.positionSource;
|
|
9494
|
+
this._activeContainerProvider = newProviderSettings.containerProvider;
|
|
9495
|
+
this._activePlaylist = newProviderSettings.playlist;
|
|
9496
|
+
}
|
|
9497
|
+
this._activePositionSource.loop = timelineConfig.loop;
|
|
9498
|
+
if (!this._activePositionSource.loop && position > 0) this.eventbus.once("timeline-firstframe", async () => {
|
|
9499
|
+
if (!this._activePositionSource) return;
|
|
9500
|
+
this._activePositionSource.suspend();
|
|
9501
|
+
this.eventbus.broadcast("timeline-duration", [this._activePositionSource.getDuration]);
|
|
9502
|
+
await this._executeStartActions();
|
|
9503
|
+
if (isSeekable$1(this._activePositionSource)) await this._activePositionSource.seek(position);
|
|
9504
|
+
await this._executeSeekActions(position);
|
|
9505
|
+
});
|
|
9506
|
+
if (this._activePlaylist) this._activePlaylist.selectItem(uri);
|
|
9507
|
+
}
|
|
9508
|
+
/**
|
|
9509
|
+
* Initializes the engine by creating the HTML layout and the first time line
|
|
9510
|
+
* by executing its initActions.
|
|
9511
|
+
*/
|
|
9512
|
+
init() {
|
|
9513
|
+
this._createLayoutTemplate();
|
|
9514
|
+
this._addEventbusListeners();
|
|
9515
|
+
const { timelines } = this.configuration;
|
|
9516
|
+
this._currentTimelineUri = timelines?.[0].uri ?? "";
|
|
9517
|
+
this._createTimelineLookup();
|
|
9518
|
+
return this._initializeTimelineProvider();
|
|
9519
|
+
}
|
|
9520
|
+
_createLayoutTemplate() {
|
|
9521
|
+
const { containerSelector } = this.configuration;
|
|
9522
|
+
const container = $(containerSelector);
|
|
9523
|
+
if (!container || !container.length) throw new Error(`Container selector not found: ${containerSelector}`);
|
|
9524
|
+
const { layoutTemplate } = this.configuration;
|
|
9525
|
+
if (layoutTemplate?.length) container.html(layoutTemplate);
|
|
9526
|
+
else console.warn("layoutTemplate is empty, unable to create layout");
|
|
9527
|
+
}
|
|
9528
|
+
async _initializeTimelineProvider() {
|
|
9529
|
+
if (!this.configuration.timelines?.length) throw new Error("No timelines present");
|
|
9530
|
+
const firstTimeline = this.configuration.timelines[0];
|
|
9531
|
+
const providerSettings = this.timelineProviders[firstTimeline.type];
|
|
9532
|
+
if (!providerSettings) throw new Error(`No timeline provider configured for type ${firstTimeline.type}`);
|
|
9533
|
+
this._activePositionSource?.destroy();
|
|
9534
|
+
this._activePositionSource = providerSettings.positionSource;
|
|
9535
|
+
this._activeContainerProvider = providerSettings.containerProvider;
|
|
9536
|
+
this._activePlaylist = providerSettings.playlist;
|
|
9537
|
+
if (!this._activePositionSource) throw new Error("NO ACTIVE POSITION SOURCE");
|
|
9538
|
+
this._activePositionSource.onPosition(this._onTimeHandler.bind(this, (x) => x));
|
|
9539
|
+
this._activePositionSource.onBoundaryReached((boundary) => {
|
|
9540
|
+
if (boundary === "end") this._onCompleteCallback();
|
|
9541
|
+
else if (boundary === "start") this._onRestartCallback();
|
|
9542
|
+
});
|
|
9543
|
+
this._activePositionSource.onActivated(this._onFirstFrameCallback.bind(this));
|
|
9544
|
+
await this._activePositionSource.init();
|
|
9545
|
+
await this._executeActions(this.configuration.initActions, "start");
|
|
9546
|
+
this._emitter.emit("initialized");
|
|
9547
|
+
return this._activePositionSource;
|
|
9548
|
+
}
|
|
9549
|
+
_onCompleteCallback() {
|
|
9550
|
+
this._emitter.emit("timelineComplete");
|
|
9551
|
+
this.eventbus.broadcast("timeline-complete", []);
|
|
9552
|
+
}
|
|
9553
|
+
_onFirstFrameCallback() {
|
|
9554
|
+
this._emitter.emit("timelineFirstFrame");
|
|
9555
|
+
this.eventbus.broadcast("timeline-firstframe", []);
|
|
9556
|
+
const duration = this._activePositionSource?.getDuration();
|
|
9557
|
+
if (duration !== void 0) this._emitter.emit("duration", duration);
|
|
9558
|
+
this.eventbus.broadcast("timeline-duration", [this._activePositionSource?.getDuration]);
|
|
9559
|
+
}
|
|
9560
|
+
_onRestartCallback() {
|
|
9561
|
+
this._emitter.emit("timelineRestart");
|
|
9562
|
+
this.eventbus.broadcast("timeline-restart", []);
|
|
9563
|
+
}
|
|
9564
|
+
async _cleanUp() {
|
|
9565
|
+
await this._cleanUpTimeline();
|
|
9566
|
+
await this._executeActions([...this.configuration.initActions].reverse(), "end");
|
|
9567
|
+
}
|
|
9568
|
+
/**
|
|
9569
|
+
* Cleans up all the necessary parts that the engine initialized.
|
|
9570
|
+
* - It ends the currently active operations and the init actions.
|
|
9571
|
+
* - It removes all its eventbus listeners, handlers and interceptors.
|
|
9572
|
+
* - It destroys all of its timeline providers
|
|
9573
|
+
* - It empties the HTML element indicated by the containerSelector configuration property.
|
|
9574
|
+
*
|
|
9575
|
+
*/
|
|
9576
|
+
async destroy() {
|
|
9577
|
+
await this._cleanUp();
|
|
9578
|
+
this.languageManager.destroy();
|
|
9579
|
+
this._activePositionSource = void 0;
|
|
9580
|
+
this._activeContainerProvider = void 0;
|
|
9581
|
+
this._activePlaylist = void 0;
|
|
9582
|
+
this._eventbusRemovers.forEach((remover) => remover());
|
|
9583
|
+
if (this.timelineProviders) Object.values(this.timelineProviders).forEach((providerInfo) => providerInfo.positionSource.destroy());
|
|
9584
|
+
const { containerSelector } = this.configuration;
|
|
9585
|
+
$(containerSelector).empty();
|
|
9586
|
+
this._emitter.emit("destroyed");
|
|
9587
|
+
this._emitter.removeAllListeners();
|
|
9588
|
+
}
|
|
9589
|
+
_addEventListener(eventName, eventHandler, eventTopic) {
|
|
9590
|
+
this._eventbusRemovers.push(this.eventbus.on(eventName, eventHandler, eventTopic));
|
|
8271
9591
|
}
|
|
8272
9592
|
_addEventbusListeners() {
|
|
8273
9593
|
this._addEventListener("request-engine-root", this._handleRequestEngineRoot.bind(this, this.configuration.containerSelector));
|
|
8274
9594
|
this._addEventListener("request-timeline-uri", this._handleRequestTimelineUri.bind(this));
|
|
8275
|
-
this._addEventListener("request-current-timeline-position", this._handleRequestTimelinePosition.bind(this,
|
|
9595
|
+
this._addEventListener("request-current-timeline-position", this._handleRequestTimelinePosition.bind(this, (x) => x));
|
|
8276
9596
|
this._addEventListener("request-timeline-cleanup", this._handleTimelineComplete.bind(this));
|
|
8277
9597
|
this._addEventListener("timeline-request-current-timeline", this._requestCurrentTimeline.bind(this));
|
|
8278
9598
|
this._addEventListener("timeline-play-toggle-request", this._toggleplay.bind(this));
|
|
8279
9599
|
this._addEventListener("timeline-play-request", this._playRequest.bind(this));
|
|
8280
9600
|
this._addEventListener("timeline-stop-request", this._stopRequest.bind(this));
|
|
8281
9601
|
this._addEventListener("timeline-pause-request", this._pauseRequest.bind(this));
|
|
8282
|
-
this._addEventListener("timeline-container-request", this.
|
|
8283
|
-
this._addEventListener("timeline-duration-request", this.
|
|
8284
|
-
this._addEventListener("timeline-seek-request", 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();
|
|
9602
|
+
this._addEventListener("timeline-container-request", this._containerRequest.bind(this));
|
|
9603
|
+
this._addEventListener("timeline-duration-request", this._durationRequest.bind(this));
|
|
9604
|
+
this._addEventListener("timeline-seek-request", this._seekRequest.bind(this));
|
|
8302
9605
|
}
|
|
8303
|
-
|
|
8304
|
-
|
|
9606
|
+
async _seekRequest(position) {
|
|
9607
|
+
await this.seek(position);
|
|
8305
9608
|
}
|
|
8306
|
-
|
|
8307
|
-
callBack(this.
|
|
9609
|
+
_durationRequest(callBack) {
|
|
9610
|
+
callBack(this.duration);
|
|
9611
|
+
}
|
|
9612
|
+
_containerRequest(callBack) {
|
|
9613
|
+
callBack(this.container);
|
|
8308
9614
|
}
|
|
8309
9615
|
_pauseRequest() {
|
|
8310
|
-
|
|
8311
|
-
this._activeTimelineProvider.pause();
|
|
8312
|
-
this.eventbus.broadcast("timeline-pause", []);
|
|
9616
|
+
this.pause();
|
|
8313
9617
|
}
|
|
8314
9618
|
_stopRequest() {
|
|
8315
|
-
|
|
8316
|
-
this._activeTimelineProvider.stop();
|
|
8317
|
-
this.eventbus.broadcast("timeline-stop", []);
|
|
9619
|
+
this.stop();
|
|
8318
9620
|
}
|
|
8319
|
-
_playRequest() {
|
|
8320
|
-
|
|
8321
|
-
this._activeTimelineProvider.start();
|
|
8322
|
-
this.eventbus.broadcast("timeline-play", []);
|
|
9621
|
+
async _playRequest() {
|
|
9622
|
+
await this.start();
|
|
8323
9623
|
}
|
|
8324
|
-
_toggleplay() {
|
|
8325
|
-
if (
|
|
8326
|
-
|
|
8327
|
-
else this._activeTimelineProvider.start();
|
|
9624
|
+
async _toggleplay() {
|
|
9625
|
+
if (this._activePositionSource?.state === "active") this.pause();
|
|
9626
|
+
else await this.start();
|
|
8328
9627
|
}
|
|
8329
9628
|
_createTimelineLookup() {
|
|
8330
9629
|
if (!this.configuration.timelines) return;
|
|
@@ -8391,28 +9690,7 @@ var EligiusEngine = class EligiusEngine {
|
|
|
8391
9690
|
resultCallback($(engineRootSelector));
|
|
8392
9691
|
}
|
|
8393
9692
|
async _handleRequestTimelineUri(uri, position = 0) {
|
|
8394
|
-
|
|
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);
|
|
9693
|
+
await this.switchTimeline(uri, position);
|
|
8416
9694
|
}
|
|
8417
9695
|
_cleanUpTimeline() {
|
|
8418
9696
|
return this._executeRelevantActions(this._getActiveActions, "end");
|
|
@@ -8439,7 +9717,7 @@ var EligiusEngine = class EligiusEngine {
|
|
|
8439
9717
|
return this._executeActions(currentActions, executionType);
|
|
8440
9718
|
}
|
|
8441
9719
|
_handleRequestTimelinePosition(floor, resultCallback) {
|
|
8442
|
-
resultCallback(floor(this.
|
|
9720
|
+
resultCallback(floor(this._activePositionSource?.getPosition() || -1));
|
|
8443
9721
|
}
|
|
8444
9722
|
_handleTimelineComplete() {
|
|
8445
9723
|
this._cleanUpTimeline();
|
|
@@ -8458,6 +9736,7 @@ var EligiusEngine = class EligiusEngine {
|
|
|
8458
9736
|
const pos = floor(position);
|
|
8459
9737
|
if (this._lastPosition !== pos) {
|
|
8460
9738
|
this._executeActionsForPosition(pos);
|
|
9739
|
+
this._emitter.emit("time", pos);
|
|
8461
9740
|
this.eventbus.broadcast("timeline-time", [pos]);
|
|
8462
9741
|
}
|
|
8463
9742
|
}
|
|
@@ -8469,23 +9748,16 @@ var EligiusEngine = class EligiusEngine {
|
|
|
8469
9748
|
}
|
|
8470
9749
|
async _executeSeekActions(position) {
|
|
8471
9750
|
const timelineActions = this._getTimelineActionsForCurrentTimeline();
|
|
8472
|
-
if (!timelineActions) return Promise.resolve();
|
|
8473
9751
|
const currentActions = this._getActiveActions(timelineActions).filter((action) => !(action.duration.start <= position && action.duration.end >= position));
|
|
8474
9752
|
const newActions = this._getActionsForPosition(position, timelineActions);
|
|
8475
9753
|
await this._executeActions(currentActions, "end");
|
|
8476
|
-
|
|
9754
|
+
await this._executeActions(newActions, "start");
|
|
8477
9755
|
}
|
|
8478
9756
|
};
|
|
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
|
-
};
|
|
9757
|
+
const sortActionsHighestStartPositionFirst = (a, b) => b.duration.start - a.duration.start;
|
|
8484
9758
|
const sortActionMethodsHighestStartPositionFirst = (a, b) => {
|
|
8485
|
-
if (
|
|
8486
|
-
|
|
8487
|
-
else if (b.startPosition > a.startPosition) return 1;
|
|
8488
|
-
else return 0;
|
|
9759
|
+
if (a.startPosition === void 0 || b.startPosition === void 0) return 0;
|
|
9760
|
+
return b.startPosition - a.startPosition;
|
|
8489
9761
|
};
|
|
8490
9762
|
|
|
8491
9763
|
//#endregion
|
|
@@ -8524,56 +9796,73 @@ function setGlobal(name, value) {
|
|
|
8524
9796
|
//#endregion
|
|
8525
9797
|
//#region src/language-manager.ts
|
|
8526
9798
|
/**
|
|
8527
|
-
*
|
|
9799
|
+
* Manages multi-language labels with explicit, testable API.
|
|
8528
9800
|
*
|
|
8529
|
-
*
|
|
9801
|
+
* This class manages the labels for an {@link IEligiusEngine} instance.
|
|
9802
|
+
* It provides a pure API for language management and emits events for language changes.
|
|
8530
9803
|
*
|
|
9804
|
+
* Eventbus integration is handled by LanguageEventbusAdapter.
|
|
8531
9805
|
*/
|
|
8532
9806
|
var LanguageManager = class {
|
|
8533
9807
|
_labelLookup;
|
|
8534
|
-
|
|
8535
|
-
|
|
9808
|
+
_emitter = new TypedEventEmitter();
|
|
9809
|
+
_availableLanguages = [];
|
|
9810
|
+
/** Current language code (e.g., 'en-US', 'nl-NL') */
|
|
9811
|
+
get language() {
|
|
9812
|
+
return this._currentLanguage;
|
|
9813
|
+
}
|
|
9814
|
+
/** List of available language codes, derived from unique languages in label collections */
|
|
9815
|
+
get availableLanguages() {
|
|
9816
|
+
return this._availableLanguages;
|
|
9817
|
+
}
|
|
9818
|
+
constructor(_currentLanguage, labels) {
|
|
8536
9819
|
this._currentLanguage = _currentLanguage;
|
|
8537
|
-
this._eventbus = _eventbus;
|
|
8538
9820
|
if (!_currentLanguage) throw new Error("language ctor arg cannot have zero length");
|
|
8539
9821
|
setGlobal("defaultLanguage", _currentLanguage);
|
|
8540
|
-
this._setRootElementLang(_currentLanguage);
|
|
8541
9822
|
this._labelLookup = this._createLabelLookup(labels);
|
|
8542
|
-
this.
|
|
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);
|
|
9823
|
+
this._availableLanguages = this._extractAvailableLanguages(labels);
|
|
8555
9824
|
}
|
|
8556
|
-
|
|
8557
|
-
|
|
8558
|
-
|
|
8559
|
-
|
|
8560
|
-
|
|
8561
|
-
|
|
8562
|
-
|
|
9825
|
+
/**
|
|
9826
|
+
* Subscribe to language manager events
|
|
9827
|
+
* @param event - Event name
|
|
9828
|
+
* @param handler - Event handler
|
|
9829
|
+
* @returns Unsubscribe function
|
|
9830
|
+
*/
|
|
9831
|
+
on(event, handler) {
|
|
9832
|
+
return this._emitter.on(event, handler);
|
|
8563
9833
|
}
|
|
8564
|
-
|
|
9834
|
+
/**
|
|
9835
|
+
* Change the current language
|
|
9836
|
+
* @param language - New language code
|
|
9837
|
+
* @throws If language code is empty or null
|
|
9838
|
+
*/
|
|
9839
|
+
setLanguage(language) {
|
|
9840
|
+
if (!language || language.length === 0) throw new Error("Language cannot be empty");
|
|
9841
|
+
const previousLanguage = this._currentLanguage;
|
|
8565
9842
|
this._currentLanguage = language;
|
|
8566
|
-
this.
|
|
9843
|
+
this._emitter.emit("change", language, previousLanguage);
|
|
8567
9844
|
}
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
9845
|
+
/**
|
|
9846
|
+
* Get a label collection by ID
|
|
9847
|
+
* @param collectionId - Label collection ID
|
|
9848
|
+
* @returns Label array or undefined if not found
|
|
9849
|
+
*/
|
|
9850
|
+
getLabelCollection(collectionId) {
|
|
9851
|
+
return this._labelLookup[collectionId];
|
|
8574
9852
|
}
|
|
8575
|
-
|
|
8576
|
-
|
|
9853
|
+
/**
|
|
9854
|
+
* Get multiple label collections by IDs
|
|
9855
|
+
* @param collectionIds - Array of label collection IDs
|
|
9856
|
+
* @returns Array of label arrays (undefined for not found collections)
|
|
9857
|
+
*/
|
|
9858
|
+
getLabelCollections(collectionIds) {
|
|
9859
|
+
return collectionIds.map((id) => this._labelLookup[id]);
|
|
9860
|
+
}
|
|
9861
|
+
/**
|
|
9862
|
+
* Clean up resources
|
|
9863
|
+
*/
|
|
9864
|
+
destroy() {
|
|
9865
|
+
this._emitter.removeAllListeners();
|
|
8577
9866
|
}
|
|
8578
9867
|
_createLabelLookup(labels) {
|
|
8579
9868
|
return labels.reduce((acc, label) => {
|
|
@@ -8581,11 +9870,15 @@ var LanguageManager = class {
|
|
|
8581
9870
|
return acc;
|
|
8582
9871
|
}, {});
|
|
8583
9872
|
}
|
|
9873
|
+
_extractAvailableLanguages(labels) {
|
|
9874
|
+
const languages = /* @__PURE__ */ new Set();
|
|
9875
|
+
for (const labelCollection of labels) for (const label of labelCollection.labels) languages.add(label.languageCode);
|
|
9876
|
+
return Array.from(languages);
|
|
9877
|
+
}
|
|
8584
9878
|
};
|
|
8585
9879
|
|
|
8586
9880
|
//#endregion
|
|
8587
9881
|
//#region src/engine-factory.ts
|
|
8588
|
-
const hotkeys = hk.default || hk;
|
|
8589
9882
|
/**
|
|
8590
9883
|
* The EngineFactory is used to create and initialize an {@link IEligiusEngine} instance.
|
|
8591
9884
|
*
|
|
@@ -8593,12 +9886,12 @@ const hotkeys = hk.default || hk;
|
|
|
8593
9886
|
*
|
|
8594
9887
|
* @example Loading a configuration and creating an IEligiusEngine instance
|
|
8595
9888
|
* ```ts
|
|
8596
|
-
* import { IEngineConfiguration, EngineFactory,
|
|
9889
|
+
* import { IEngineConfiguration, EngineFactory, EligiusResourceImporter } from 'eligius';
|
|
8597
9890
|
* import * as engineConfig from './my-eligius-config.json';
|
|
8598
9891
|
*
|
|
8599
|
-
* const factory = new EngineFactory(new
|
|
9892
|
+
* const factory = new EngineFactory(new EligiusResourceImporter(), window);
|
|
8600
9893
|
*
|
|
8601
|
-
* const engine = factory.createEngine((engineConfig as unknown) as IEngineConfiguration);
|
|
9894
|
+
* const { engine } = factory.createEngine((engineConfig as unknown) as IEngineConfiguration);
|
|
8602
9895
|
*
|
|
8603
9896
|
* engine.init().then(()=> {console.log('Eligius engine ready for business');});
|
|
8604
9897
|
* ```
|
|
@@ -8608,94 +9901,58 @@ var EngineFactory = class {
|
|
|
8608
9901
|
_eventbus;
|
|
8609
9902
|
_eventRemovers = [];
|
|
8610
9903
|
_importer;
|
|
8611
|
-
|
|
9904
|
+
_windowRef;
|
|
8612
9905
|
constructor(importer, windowRef, options) {
|
|
8613
9906
|
this._importer = importer;
|
|
9907
|
+
this._windowRef = windowRef;
|
|
8614
9908
|
this._eventbus = options?.eventbus ?? new Eventbus();
|
|
8615
|
-
|
|
8616
|
-
|
|
8617
|
-
this._eventRemovers.push(this._eventbus.
|
|
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.`);
|
|
9909
|
+
this._eventRemovers.push(this._eventbus.onRequest("request-instance", this._requestInstanceHandler.bind(this)));
|
|
9910
|
+
this._eventRemovers.push(this._eventbus.onRequest("request-action", this._requestActionHandler.bind(this)));
|
|
9911
|
+
this._eventRemovers.push(this._eventbus.onRequest("request-function", this._requestFunctionHandler.bind(this)));
|
|
8666
9912
|
}
|
|
9913
|
+
/**
|
|
9914
|
+
* Destroys the factory and cleans up all registered request handlers.
|
|
9915
|
+
*/
|
|
8667
9916
|
destroy() {
|
|
8668
9917
|
this._eventRemovers.forEach((x) => x());
|
|
8669
|
-
|
|
8670
|
-
|
|
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);
|
|
9918
|
+
this._eventRemovers = [];
|
|
9919
|
+
this._actionsLookup = {};
|
|
8678
9920
|
}
|
|
8679
9921
|
_importSystemEntryWithEventbusDependency(systemName) {
|
|
8680
9922
|
return new (this._importSystemEntry(systemName))(this._eventbus);
|
|
8681
9923
|
}
|
|
8682
9924
|
_importSystemEntry(systemName) {
|
|
8683
|
-
|
|
9925
|
+
const entry = this._importer.import(systemName)?.[systemName];
|
|
9926
|
+
if (!entry) throw new Error(`Failed to import '${systemName}': module does not export '${systemName}'`);
|
|
9927
|
+
return entry;
|
|
8684
9928
|
}
|
|
8685
|
-
_requestInstanceHandler(systemName
|
|
8686
|
-
|
|
9929
|
+
_requestInstanceHandler(systemName) {
|
|
9930
|
+
return this._importSystemEntryWithEventbusDependency(systemName);
|
|
8687
9931
|
}
|
|
8688
|
-
_requestFunctionHandler(systemName
|
|
8689
|
-
|
|
9932
|
+
_requestFunctionHandler(systemName) {
|
|
9933
|
+
return this._importSystemEntry(systemName);
|
|
8690
9934
|
}
|
|
8691
|
-
_requestActionHandler(systemName
|
|
9935
|
+
_requestActionHandler(systemName) {
|
|
8692
9936
|
const action = this._actionsLookup[systemName];
|
|
8693
|
-
if (action)
|
|
9937
|
+
if (action) return action;
|
|
8694
9938
|
else {
|
|
8695
9939
|
console.error(`Unknown action: ${systemName}`);
|
|
8696
|
-
|
|
9940
|
+
return null;
|
|
8697
9941
|
}
|
|
8698
9942
|
}
|
|
9943
|
+
/**
|
|
9944
|
+
* Creates a fully wired engine with adapters and event handlers.
|
|
9945
|
+
*
|
|
9946
|
+
* This method:
|
|
9947
|
+
* - Resolves the configuration
|
|
9948
|
+
* - Creates timeline providers
|
|
9949
|
+
* - Instantiates the engine and language manager
|
|
9950
|
+
* - Creates and connects adapters for eventbus integration
|
|
9951
|
+
*
|
|
9952
|
+
* @param configuration - The engine configuration
|
|
9953
|
+
* @param resolver - Optional custom configuration resolver
|
|
9954
|
+
* @returns Engine result with engine, language manager, eventbus, and destroy function
|
|
9955
|
+
*/
|
|
8699
9956
|
createEngine(configuration, resolver) {
|
|
8700
9957
|
const { systemName } = configuration.engine;
|
|
8701
9958
|
const EngineClass = this._importSystemEntry(systemName);
|
|
@@ -8710,24 +9967,120 @@ var EngineFactory = class {
|
|
|
8710
9967
|
this._actionsLookup = actionLookup;
|
|
8711
9968
|
const timelineProviders = this._createTimelineProviders(resolvedConfiguration);
|
|
8712
9969
|
const { language, labels } = configuration;
|
|
8713
|
-
const languageManager = new LanguageManager(language, labels
|
|
8714
|
-
|
|
9970
|
+
const languageManager = new LanguageManager(language, labels);
|
|
9971
|
+
const engineInstance = new EngineClass(resolvedConfiguration, this._eventbus, timelineProviders, languageManager);
|
|
9972
|
+
const engineEventbusAdapter = new EngineEventbusAdapter(engineInstance, this._eventbus);
|
|
9973
|
+
const languageEventbusAdapter = new LanguageEventbusAdapter(languageManager, this._eventbus, engineInstance);
|
|
9974
|
+
const engineInputAdapter = new EngineInputAdapter(engineInstance, this._eventbus, this._windowRef);
|
|
9975
|
+
engineEventbusAdapter.connect();
|
|
9976
|
+
languageEventbusAdapter.connect();
|
|
9977
|
+
engineInputAdapter.connect();
|
|
9978
|
+
return {
|
|
9979
|
+
engine: engineInstance,
|
|
9980
|
+
languageManager,
|
|
9981
|
+
eventbus: this._eventbus,
|
|
9982
|
+
destroy: async () => {
|
|
9983
|
+
engineInputAdapter.disconnect();
|
|
9984
|
+
languageEventbusAdapter.disconnect();
|
|
9985
|
+
engineEventbusAdapter.disconnect();
|
|
9986
|
+
await engineInstance.destroy();
|
|
9987
|
+
}
|
|
9988
|
+
};
|
|
8715
9989
|
}
|
|
8716
9990
|
_createTimelineProviders(configuration) {
|
|
8717
|
-
|
|
9991
|
+
return this.createTimelineProvidersForConfig(configuration);
|
|
9992
|
+
}
|
|
9993
|
+
/**
|
|
9994
|
+
* Creates a position source for a specific timeline based on configuration.
|
|
9995
|
+
*
|
|
9996
|
+
* The position source class is resolved dynamically via the resource importer
|
|
9997
|
+
* using the `systemName` property from the configuration.
|
|
9998
|
+
*
|
|
9999
|
+
* @param timeline - The resolved timeline configuration
|
|
10000
|
+
* @param settings - The timeline provider settings containing position source config
|
|
10001
|
+
* @returns A configured position source
|
|
10002
|
+
* @throws Error if the position source class cannot be resolved
|
|
10003
|
+
*/
|
|
10004
|
+
createPositionSourceForTimeline(timeline, settings) {
|
|
10005
|
+
const { systemName, ...options } = settings.positionSource;
|
|
10006
|
+
return new (this._importSystemEntry(systemName))({
|
|
10007
|
+
...options,
|
|
10008
|
+
duration: timeline.duration
|
|
10009
|
+
});
|
|
10010
|
+
}
|
|
10011
|
+
/**
|
|
10012
|
+
* Creates a container provider based on timeline provider settings.
|
|
10013
|
+
*
|
|
10014
|
+
* The container provider class is resolved dynamically via the resource importer
|
|
10015
|
+
* using the `systemName` property from the configuration.
|
|
10016
|
+
*
|
|
10017
|
+
* @param settings - The timeline provider settings
|
|
10018
|
+
* @returns A container provider, or undefined if not configured
|
|
10019
|
+
* @throws Error if the container provider class cannot be resolved
|
|
10020
|
+
*/
|
|
10021
|
+
createContainerProviderForTimeline(settings) {
|
|
10022
|
+
if (!settings.container) return;
|
|
10023
|
+
const { systemName, ...options } = settings.container;
|
|
10024
|
+
return new (this._importSystemEntry(systemName))(options);
|
|
10025
|
+
}
|
|
10026
|
+
/**
|
|
10027
|
+
* Creates a playlist based on timeline provider settings.
|
|
10028
|
+
*
|
|
10029
|
+
* The playlist class is resolved dynamically via the resource importer
|
|
10030
|
+
* using the `systemName` property from the configuration.
|
|
10031
|
+
*
|
|
10032
|
+
* @param settings - The timeline provider settings
|
|
10033
|
+
* @returns A playlist, or undefined if not configured
|
|
10034
|
+
* @throws Error if the playlist class cannot be resolved
|
|
10035
|
+
*/
|
|
10036
|
+
createPlaylistForTimeline(settings) {
|
|
10037
|
+
if (!settings.playlist) return;
|
|
10038
|
+
const { systemName, ...options } = settings.playlist;
|
|
10039
|
+
return new (this._importSystemEntry(systemName))(options);
|
|
10040
|
+
}
|
|
10041
|
+
/**
|
|
10042
|
+
* Assembles a complete ITimelineProviderInfo from timeline and settings.
|
|
10043
|
+
*
|
|
10044
|
+
* This is the main entry point for creating provider info with the new
|
|
10045
|
+
* configuration-driven architecture.
|
|
10046
|
+
*
|
|
10047
|
+
* @param timeline - The resolved timeline configuration
|
|
10048
|
+
* @param settings - The timeline provider settings
|
|
10049
|
+
* @returns A complete timeline provider info with all components
|
|
10050
|
+
*/
|
|
10051
|
+
createTimelineProviderInfo(timeline, settings) {
|
|
10052
|
+
return {
|
|
10053
|
+
positionSource: this.createPositionSourceForTimeline(timeline, settings),
|
|
10054
|
+
containerProvider: this.createContainerProviderForTimeline(settings),
|
|
10055
|
+
playlist: this.createPlaylistForTimeline(settings)
|
|
10056
|
+
};
|
|
10057
|
+
}
|
|
10058
|
+
/**
|
|
10059
|
+
* Creates timeline providers for all configured timeline types using the new
|
|
10060
|
+
* configuration-driven architecture.
|
|
10061
|
+
*
|
|
10062
|
+
* This method iterates over timelineProviderSettings and creates a
|
|
10063
|
+
* ITimelineProviderInfo for each configured timeline type by:
|
|
10064
|
+
* 1. Finding the first timeline that matches the type
|
|
10065
|
+
* 2. Using the timeline's duration for the position source
|
|
10066
|
+
* 3. Assembling components from the settings
|
|
10067
|
+
*
|
|
10068
|
+
* @param configuration - The resolved engine configuration
|
|
10069
|
+
* @returns A record of timeline types to their provider info
|
|
10070
|
+
* @throws Error if a provider setting has no matching timeline in config
|
|
10071
|
+
*/
|
|
10072
|
+
createTimelineProvidersForConfig(configuration) {
|
|
10073
|
+
const { timelineProviderSettings, timelines } = configuration;
|
|
8718
10074
|
return Object.entries(timelineProviderSettings).reduce((acc, [timelineType, settings]) => {
|
|
8719
10075
|
if (!settings) return acc;
|
|
8720
|
-
const
|
|
8721
|
-
|
|
8722
|
-
|
|
8723
|
-
vendor: settings.vendor,
|
|
8724
|
-
provider: new TimelineProviderClass(configuration)
|
|
8725
|
-
};
|
|
10076
|
+
const matchingTimeline = timelines.find((t) => t.type === timelineType);
|
|
10077
|
+
if (!matchingTimeline) throw new Error(`Timeline provider settings for '${timelineType}' has no matching timeline in configuration`);
|
|
10078
|
+
acc[timelineType] = this.createTimelineProviderInfo(matchingTimeline, settings);
|
|
8726
10079
|
return acc;
|
|
8727
10080
|
}, {});
|
|
8728
10081
|
}
|
|
8729
10082
|
};
|
|
8730
10083
|
|
|
8731
10084
|
//#endregion
|
|
8732
|
-
export { Action, ActionCreator, ActionCreatorFactory, ActionEditor, ActionRegistryEventbusListener, ConfigurationFactory, ConfigurationResolver, ControllerNamesProvider,
|
|
10085
|
+
export { Action, ActionCreator, ActionCreatorFactory, ActionEditor, ActionRegistryEventbusListener, BasePositionSource, ConfigurationFactory, ConfigurationResolver, ControllerNamesProvider, DOMEventListenerController, DomContainerProvider, EligiusEngine, EligiusResourceImporter, EndableAction, EndableActionCreator, EndableActionEditor, EngineEventbusAdapter, EngineFactory, EngineInputAdapter, Eventbus, KeyboardStepSource, LabelController, LanguageEventbusAdapter, LanguageManager, LottieController, MutationObserverController, NavigationController, OperationEditor, OperationMetadataProvider, OperationNamesProvider, ProgressbarController, RafPositionSource, RequestVideoUriInterceptor, RoutingController, ScrollPositionSource, SimplePlaylist, SubtitleEditor, SubtitleImporter, SubtitlesController, 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
10086
|
//# sourceMappingURL=index.mjs.map
|