eligius 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -212,10 +212,10 @@ function isExternalProperty(value) {
212
212
  *
213
213
  * At the start of the loop, the associated {@link endForEach} operation is determined and when
214
214
  * the last iteration is completed the flow control is set to the index of that operation.
215
- *
216
- * The {@link continueForEach|continue} and {@link breakForEach|break} operations can be used to control the
215
+ *
216
+ * The {@link continueForEach|continue} and {@link breakForEach|break} operations can be used to control the
217
217
  * loop iterations.
218
- *
218
+ *
219
219
  */
220
220
  const forEach = function(operationData) {
221
221
  const { collection } = operationData;
@@ -250,6 +250,43 @@ function findEndForEachIndex(scope) {
250
250
  const forEachSystemName = "forEach";
251
251
  const endForEachSystemName = "endForEach";
252
252
 
253
+ //#endregion
254
+ //#region src/operation/helper/remove-operation-properties.ts
255
+ /**
256
+ * Removes specified properties from an operation data object.
257
+ * This is a helper function to eliminate repetitive property deletion code across operations.
258
+ *
259
+ * @template T - The type of the operation data object
260
+ * @template K - The keys to remove from the object (must be keys of T)
261
+ * @param operationData - The operation data object to mutate
262
+ * @param keys - The property keys to delete from the object
263
+ * @returns The mutated operation data object with specified properties removed (typed as Omit<T, K>)
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * interface IMyOperationData {
268
+ * selectedElement: JQuery;
269
+ * animationDuration: number;
270
+ * animationEasing: string;
271
+ * }
272
+ *
273
+ * const data: IMyOperationData = {
274
+ * selectedElement: $element,
275
+ * animationDuration: 500,
276
+ * animationEasing: 'ease-in'
277
+ * };
278
+ *
279
+ * // Remove multiple properties at once
280
+ * const result = removeProperties(data, 'animationDuration', 'animationEasing');
281
+ * // result is typed as Omit<IMyOperationData, 'animationDuration' | 'animationEasing'>
282
+ * // result = { selectedElement: $element }
283
+ * ```
284
+ */
285
+ function removeProperties(operationData, ...keys) {
286
+ for (const key of keys) delete operationData[key];
287
+ return operationData;
288
+ }
289
+
253
290
  //#endregion
254
291
  //#region src/operation/when.ts
255
292
  /**
@@ -257,17 +294,17 @@ const endForEachSystemName = "endForEach";
257
294
  * until an {@link endWhen} or {@link otherwise} operation is encountered.
258
295
  *
259
296
  * Practically, this means an `if` or `if`/`else` statement control flow implementation in a list of operations.
260
- *
297
+ *
261
298
  * The expression is passed in as a formatted string.
262
299
  * The left and right values of the expression can be defined like this:
263
- *
300
+ *
264
301
  * 'constant': for a constant string
265
302
  * 100: for a constant number
266
303
  * $operationData.foo: for an operation data value
267
304
  * $globaldata.foo: for a global data value
268
305
  * $scope.loopIndex: for a scope value
269
306
  * @foo: for a variable value
270
- *
307
+ *
271
308
  * @example
272
309
  * $scope.variables.foo=='bar'
273
310
  * @example
@@ -280,10 +317,9 @@ const endForEachSystemName = "endForEach";
280
317
  */
281
318
  const when = function(operationData) {
282
319
  const [left, operator, right] = parseExpression(operationData.expression, operationData, this);
283
- delete operationData.expression;
320
+ removeProperties(operationData, "expression");
284
321
  this.whenEvaluation = evaluations[operator](left, right);
285
322
  if (!this.whenEvaluation) this.newIndex = findNextFlowControlIndex(this);
286
- delete operationData.expression;
287
323
  return operationData;
288
324
  };
289
325
  function parseExpression(expression, operationData, operationScope) {
@@ -671,7 +707,7 @@ const addGlobalsToOperation = (operationData) => {
671
707
  prev[current] = getGlobals(current);
672
708
  return prev;
673
709
  }, {});
674
- delete operationData.globalProperties;
710
+ removeProperties(operationData, "globalProperties");
675
711
  return Object.assign(operationData, globalValues);
676
712
  };
677
713
 
@@ -686,9 +722,7 @@ const addGlobalsToOperation = (operationData) => {
686
722
  */
687
723
  const animate = (operationData) => {
688
724
  const { selectedElement, animationEasing, animationProperties, animationDuration } = operationData;
689
- delete operationData.animationEasing;
690
- delete operationData.animationProperties;
691
- delete operationData.animationDuration;
725
+ removeProperties(operationData, "animationEasing", "animationProperties", "animationDuration");
692
726
  return new Promise((resolve, reject) => {
693
727
  try {
694
728
  if (animationEasing) selectedElement.animate(animationProperties, animationDuration, animationEasing, () => {
@@ -730,10 +764,10 @@ const animateWithClass = (operationData) => {
730
764
  //#endregion
731
765
  //#region src/operation/break-for-each.ts
732
766
  /**
733
- *
767
+ *
734
768
  * This operation should only be used within a loop, so between a {@link forEach} and {@link endForEach}
735
769
  * operation. This operation immediately moves to the loop end index, effectively stopping the loop.
736
- *
770
+ *
737
771
  */
738
772
  const breakForEach = function(operationData) {
739
773
  if (this.loopIndex !== void 0 && this.loopLength !== void 0) {
@@ -763,9 +797,7 @@ function resolveEventArguments(operationData, operationScope, eventArgs) {
763
797
  */
764
798
  const broadcastEvent = function(operationData) {
765
799
  const { eventArgs, eventTopic, eventName } = operationData;
766
- delete operationData.eventArgs;
767
- delete operationData.eventTopic;
768
- delete operationData.eventName;
800
+ removeProperties(operationData, "eventArgs", "eventTopic", "eventName");
769
801
  const eventArguments = resolveEventArguments(operationData, this, eventArgs);
770
802
  if (eventTopic) this.eventbus.broadcastForTopic(eventName, eventTopic, eventArguments);
771
803
  else this.eventbus.broadcast(eventName, eventArguments);
@@ -822,9 +854,7 @@ const calcFunctions = {
822
854
  const calc = function(operationData) {
823
855
  operationData = resolvePropertyValues(operationData, this, operationData);
824
856
  const { left, right, operator } = operationData;
825
- delete operationData.left;
826
- delete operationData.right;
827
- delete operationData.operator;
857
+ removeProperties(operationData, "left", "right", "operator");
828
858
  operationData.calculationResult = calcFunctions[operator](+left, +right);
829
859
  return operationData;
830
860
  };
@@ -854,7 +884,7 @@ const clearOperationData = (operationData) => {
854
884
  properties.forEach((name) => {
855
885
  delete operationData[name];
856
886
  });
857
- delete operationData.properties;
887
+ removeProperties(operationData, "properties");
858
888
  return operationData;
859
889
  }
860
890
  return {};
@@ -863,11 +893,11 @@ const clearOperationData = (operationData) => {
863
893
  //#endregion
864
894
  //#region src/operation/continue-for-each.ts
865
895
  /**
866
- *
896
+ *
867
897
  * This operation should only be used within a loop, so between a {@link forEach} and {@link endForEach}
868
- * operation. This operation immediately moves to the next loop index, effectively canceling the rest
898
+ * operation. This operation immediately moves to the next loop index, effectively canceling the rest
869
899
  * of the operations in the current iteration.
870
- *
900
+ *
871
901
  */
872
902
  const continueForEach = function(operationData) {
873
903
  if (this.loopIndex !== void 0 && this.loopLength !== void 0) {
@@ -889,9 +919,7 @@ const continueForEach = function(operationData) {
889
919
  const createElement = function(operationData) {
890
920
  operationData = resolvePropertyValues(operationData, this, operationData);
891
921
  const { elementName, attributes, text } = operationData;
892
- delete operationData.elementName;
893
- delete operationData.attributes;
894
- delete operationData.text;
922
+ removeProperties(operationData, "elementName", "attributes", "text");
895
923
  const serializedAttrs = attributes ? ` ${Object.entries(attributes).filter(([_, value]) => Boolean(value)).map(([key, value]) => `${key}="${value}"`).join(" ")}` : "";
896
924
  operationData.template = text ? $(`<${elementName}${serializedAttrs}>${text}</${elementName}>`) : $(`<${elementName}${serializedAttrs}/>`);
897
925
  return operationData;
@@ -992,7 +1020,7 @@ var TimelineEventNames = class {
992
1020
  */
993
1021
  const customFunction = function(operationData) {
994
1022
  const { systemName } = operationData;
995
- delete operationData.systemName;
1023
+ removeProperties(operationData, "systemName");
996
1024
  return new Promise((resolve, reject) => {
997
1025
  const resultCallback = (func) => {
998
1026
  const promise = func.apply(this, [operationData]);
@@ -1058,7 +1086,7 @@ const endWhen = function(operationData) {
1058
1086
  */
1059
1087
  const extendController = (operationData) => {
1060
1088
  const { controllerInstance, controllerExtension } = operationData;
1061
- delete operationData.controllerExtension;
1089
+ removeProperties(operationData, "controllerExtension");
1062
1090
  operationData.controllerInstance = Object.assign(controllerInstance, controllerExtension);
1063
1091
  return operationData;
1064
1092
  };
@@ -1070,7 +1098,7 @@ const extendController = (operationData) => {
1070
1098
  */
1071
1099
  const getAttributesFromElement = (operationData) => {
1072
1100
  const { selectedElement, attributeNames } = operationData;
1073
- delete operationData.attributeNames;
1101
+ removeProperties(operationData, "attributeNames");
1074
1102
  operationData.attributeValues = attributeNames.reduce((acc, attrName) => {
1075
1103
  if (attrName !== "value") acc[attrName] = selectedElement.attr(attrName);
1076
1104
  else acc[attrName] = selectedElement.val();
@@ -1089,7 +1117,7 @@ const getAttributesFromElement = (operationData) => {
1089
1117
  */
1090
1118
  const getControllerFromElement = (operationData) => {
1091
1119
  const { selectedElement, controllerName } = operationData;
1092
- delete operationData.controllerName;
1120
+ removeProperties(operationData, "controllerName");
1093
1121
  const controller = getElementControllers(selectedElement)?.find((ctrl) => ctrl.name === controllerName);
1094
1122
  if (!controller) console.warn(`controller for name '${controllerName}' was not found on the given element`);
1095
1123
  operationData.controllerInstance = controller;
@@ -1104,7 +1132,7 @@ const getControllerFromElement = (operationData) => {
1104
1132
  */
1105
1133
  const getControllerInstance = function(operationData) {
1106
1134
  const { systemName } = operationData;
1107
- delete operationData.systemName;
1135
+ removeProperties(operationData, "systemName");
1108
1136
  operationData.controllerInstance = void 0;
1109
1137
  const resultCallback = (instance) => {
1110
1138
  operationData.controllerInstance = instance;
@@ -1251,7 +1279,7 @@ function modifyDimensions(dimensions, modifier) {
1251
1279
  */
1252
1280
  const getElementDimensions = (operationData) => {
1253
1281
  const { selectedElement, modifier } = operationData;
1254
- delete operationData.modifier;
1282
+ removeProperties(operationData, "modifier");
1255
1283
  let dimensions = {
1256
1284
  width: selectedElement.innerWidth() ?? 0,
1257
1285
  height: selectedElement.innerHeight() ?? 0
@@ -1292,8 +1320,7 @@ const getQueryParams = (operationData) => {
1292
1320
  const searchParams = new URLSearchParams(window.location.search);
1293
1321
  const queryParams = Object.fromEntries(searchParams.entries());
1294
1322
  const { defaultValues = {} } = operationData;
1295
- delete operationData.defaultValues;
1296
- delete operationData.defaultValues;
1323
+ removeProperties(operationData, "defaultValues");
1297
1324
  operationData.queryParams = {
1298
1325
  ...defaultValues,
1299
1326
  ...queryParams
@@ -1335,8 +1362,7 @@ const addToCache = (key, value) => {
1335
1362
  */
1336
1363
  const loadJson = async (operationData) => {
1337
1364
  const { url, cache: cache$2 } = operationData;
1338
- delete operationData.url;
1339
- delete operationData.cache;
1365
+ removeProperties(operationData, "url", "cache");
1340
1366
  if (cache$2 && jsonCache[url]) {
1341
1367
  operationData.json = jsonCache[url];
1342
1368
  return operationData;
@@ -1355,8 +1381,7 @@ const loadJson = async (operationData) => {
1355
1381
  const log = function(operationData) {
1356
1382
  if ("logValue" in operationData) {
1357
1383
  console.log(operationData.logName ?? "logValue", operationData.logValue);
1358
- delete operationData.logValue;
1359
- delete operationData.logName;
1384
+ removeProperties(operationData, "logValue", "logName");
1360
1385
  } else {
1361
1386
  const globalData = getGlobals();
1362
1387
  console.group("Operation info");
@@ -1441,7 +1466,7 @@ const removeClass = (operationData) => {
1441
1466
  */
1442
1467
  const removeControllerFromElement = function(operationData) {
1443
1468
  const { selectedElement, controllerName } = operationData;
1444
- delete controllerName.controllerName;
1469
+ delete operationData.controllerName;
1445
1470
  const controllers$1 = getElementControllers(selectedElement);
1446
1471
  const controller = controllers$1?.find((ctrl) => ctrl.name === controllerName);
1447
1472
  if (controller && controllers$1) {
@@ -1486,7 +1511,7 @@ const removePropertiesFromOperationData = (operationData) => {
1486
1511
  */
1487
1512
  const reparentElement = (operationData) => {
1488
1513
  const { selectedElement, newParentSelector } = operationData;
1489
- delete operationData.newParentSelector;
1514
+ removeProperties(operationData, "newParentSelector");
1490
1515
  selectedElement.remove().appendTo(newParentSelector);
1491
1516
  return operationData;
1492
1517
  };
@@ -1499,7 +1524,7 @@ const reparentElement = (operationData) => {
1499
1524
  */
1500
1525
  const requestAction = function(operationData) {
1501
1526
  const { systemName } = operationData;
1502
- delete operationData.systemName;
1527
+ removeProperties(operationData, "systemName");
1503
1528
  const resultCallback = (action) => {
1504
1529
  operationData.actionInstance = action;
1505
1530
  };
@@ -1524,8 +1549,7 @@ function findElementBySelector(root, selector) {
1524
1549
  const selectElement = function(operationData) {
1525
1550
  operationData.selector = resolveExternalPropertyChain(operationData, this, operationData.selector);
1526
1551
  const { selector, useSelectedElementAsRoot = false } = operationData;
1527
- delete operationData.selector;
1528
- delete operationData.useSelectedElementAsRoot;
1552
+ removeProperties(operationData, "selector", "useSelectedElementAsRoot");
1529
1553
  if (!selector) throw new Error("selectElement: selector is either empty or not defined.");
1530
1554
  if (useSelectedElementAsRoot && operationData.selectedElement) {
1531
1555
  const currentRoot = operationData.selectedElement;
@@ -1555,7 +1579,7 @@ const selectElement = function(operationData) {
1555
1579
  */
1556
1580
  const setData = function(operationData) {
1557
1581
  const { properties } = operationData;
1558
- delete operationData.properties;
1582
+ removeProperties(operationData, "properties");
1559
1583
  resolveTargets(properties, operationData, this);
1560
1584
  return operationData;
1561
1585
  };
@@ -1590,7 +1614,7 @@ function isDataTarget(value) {
1590
1614
  */
1591
1615
  const setElementAttributes = (operationData) => {
1592
1616
  const { attributes, selectedElement } = operationData;
1593
- delete operationData.attributes;
1617
+ removeProperties(operationData, "attributes");
1594
1618
  selectedElement.attr(attributes);
1595
1619
  return operationData;
1596
1620
  };
@@ -1619,8 +1643,7 @@ const setElementContent = (operationData) => {
1619
1643
  selectedElement.prepend(template);
1620
1644
  break;
1621
1645
  }
1622
- delete operationData.insertionType;
1623
- delete operationData.template;
1646
+ removeProperties(operationData, "insertionType", "template");
1624
1647
  return operationData;
1625
1648
  };
1626
1649
 
@@ -1660,7 +1683,7 @@ const setOperationData = function(operationData) {
1660
1683
  const setStyle = function(operationData) {
1661
1684
  const properties = resolvePropertyValues(operationData, this, operationData.properties);
1662
1685
  operationData.selectedElement.css(properties);
1663
- delete operationData.properties;
1686
+ removeProperties(operationData, "properties");
1664
1687
  return operationData;
1665
1688
  };
1666
1689
 
@@ -1673,8 +1696,7 @@ const setVariable = function(operationData) {
1673
1696
  const { name, value } = operationData;
1674
1697
  if (!this.variables) this.variables = {};
1675
1698
  this.variables[name] = value;
1676
- delete operationData.name;
1677
- delete operationData.value;
1699
+ removeProperties(operationData, "name", "value");
1678
1700
  return operationData;
1679
1701
  };
1680
1702
 
@@ -3309,18 +3331,18 @@ var ConfigurationFactory = class ConfigurationFactory {
3309
3331
  };
3310
3332
 
3311
3333
  //#endregion
3312
- //#region src/controllers/event-listener-controller.ts
3334
+ //#region src/controllers/dom-event-listener-controller.ts
3313
3335
  /**
3314
- * This controller attaches to the given selected element and adds an event listener for the specified event name that
3336
+ * This controller attaches to the given selected element and adds a DOM event listener for the specified event name that
3315
3337
  * executes the given actions with the given operation data.
3316
3338
  *
3317
3339
  * By default the `start` operations of the specified actions are executed. To execute the `end` operations instead,
3318
3340
  * prefix the action name with `end:`.
3319
3341
  */
3320
- var EventListenerController = class {
3342
+ var DOMEventListenerController = class {
3321
3343
  operationData;
3322
3344
  actionInstanceInfos;
3323
- name = "EventListenerController";
3345
+ name = "DOMEventListenerController";
3324
3346
  constructor() {}
3325
3347
  init(operationData) {
3326
3348
  this.operationData = {
@@ -3371,6 +3393,75 @@ var EventListenerController = class {
3371
3393
  }
3372
3394
  };
3373
3395
 
3396
+ //#endregion
3397
+ //#region src/controllers/base-controller.ts
3398
+ /**
3399
+ * Abstract base class for controllers providing standardized event listener management
3400
+ *
3401
+ * Benefits:
3402
+ * - Eliminates boilerplate event listener tracking code
3403
+ * - Automatic binding of event handlers to controller instance
3404
+ * - Centralized cleanup preventing memory leaks
3405
+ * - Consistent event management pattern across all controllers
3406
+ *
3407
+ * @example
3408
+ * ```typescript
3409
+ * class MyController extends BaseController<IMyOperationData> {
3410
+ * name = 'MyController';
3411
+ *
3412
+ * init(operationData: IMyOperationData): void {
3413
+ * this.operationData = operationData;
3414
+ * }
3415
+ *
3416
+ * attach(eventbus: IEventbus): void {
3417
+ * this.addListener(eventbus, 'my-event', this.handleMyEvent);
3418
+ * // Handler automatically bound, cleanup tracked
3419
+ * }
3420
+ *
3421
+ * private handleMyEvent(): void {
3422
+ * // 'this' context preserved
3423
+ * }
3424
+ * }
3425
+ * ```
3426
+ */
3427
+ var BaseController = class {
3428
+ operationData = null;
3429
+ eventListeners = [];
3430
+ /**
3431
+ * Register event listener with automatic binding and cleanup tracking
3432
+ *
3433
+ * @param eventbus - The eventbus to register with
3434
+ * @param eventName - Name of the event to listen for
3435
+ * @param handler - Event handler function (will be bound to this controller)
3436
+ */
3437
+ addListener(eventbus$1, eventName, handler) {
3438
+ const boundHandler = handler.bind(this);
3439
+ const remover = eventbus$1.on(eventName, boundHandler);
3440
+ this.eventListeners.push(remover);
3441
+ }
3442
+ /**
3443
+ * Register multiple event listeners at once
3444
+ *
3445
+ * @param eventbus - The eventbus to register with
3446
+ * @param listeners - Array of {eventName, handler} pairs
3447
+ */
3448
+ attachMultiple(eventbus$1, listeners) {
3449
+ listeners.forEach(({ eventName, handler }) => {
3450
+ this.addListener(eventbus$1, eventName, handler);
3451
+ });
3452
+ }
3453
+ /**
3454
+ * Clean up all tracked event listeners
3455
+ * Prevents memory leaks by removing all registered handlers
3456
+ *
3457
+ * @param _eventbus - The eventbus (ignored, included for IController compatibility)
3458
+ */
3459
+ detach(_eventbus) {
3460
+ this.eventListeners.forEach((remover) => remover());
3461
+ this.eventListeners = [];
3462
+ }
3463
+ };
3464
+
3374
3465
  //#endregion
3375
3466
  //#region src/controllers/label-controller.ts
3376
3467
  /**
@@ -3379,10 +3470,8 @@ var EventListenerController = class {
3379
3470
  * The controller also listen for the `LANGUAGE_CHANGE` event and re-renders the text with the new language after such an event.
3380
3471
  *
3381
3472
  */
3382
- var LabelController = class {
3383
- listeners = [];
3473
+ var LabelController = class extends BaseController {
3384
3474
  currentLanguage = null;
3385
- operationData = null;
3386
3475
  labelData = {};
3387
3476
  name = "LabelController";
3388
3477
  requestLabelDataBound;
@@ -3403,7 +3492,7 @@ var LabelController = class {
3403
3492
  this.requestLabelDataBound = this._requestLabelData.bind(this, eventbus$1);
3404
3493
  this.requestLabelDataBound(this.operationData.labelId);
3405
3494
  this._setLabel();
3406
- this.listeners.push(eventbus$1.on(TimelineEventNames.LANGUAGE_CHANGE, this._handleLanguageChange.bind(this)));
3495
+ this.addListener(eventbus$1, TimelineEventNames.LANGUAGE_CHANGE, this._handleLanguageChange);
3407
3496
  }
3408
3497
  _requestLabelData(eventbus$1, labelId) {
3409
3498
  eventbus$1.broadcast(TimelineEventNames.REQUEST_LABEL_COLLECTION, [labelId, (labelCollection) => {
@@ -3418,8 +3507,8 @@ var LabelController = class {
3418
3507
  else this.operationData?.selectedElement.attr(this.operationData?.attributeName, text);
3419
3508
  }
3420
3509
  }
3421
- detach(_eventbus) {
3422
- this.listeners.forEach((func) => func());
3510
+ detach(eventbus$1) {
3511
+ super.detach(eventbus$1);
3423
3512
  this.requestLabelDataBound = void 0;
3424
3513
  }
3425
3514
  _handleLanguageChange(code) {
@@ -3442,18 +3531,15 @@ const lottie = lt.default ?? lt;
3442
3531
  * The url may encode freeze and end positions like this: my-url/filename[freeze=10,end=21].json
3443
3532
  *
3444
3533
  */
3445
- var LottieController = class {
3534
+ var LottieController = class extends BaseController {
3446
3535
  name = "LottieController";
3447
3536
  currentLanguage = "nl-NL";
3448
3537
  labelData = {};
3449
- eventbusRemovers = [];
3450
3538
  animationItem = null;
3451
- operationData = null;
3452
3539
  serializedData = null;
3453
3540
  serializedIEData = null;
3454
3541
  freezePosition = -1;
3455
3542
  endPosition = -1;
3456
- constructor() {}
3457
3543
  init(operationData) {
3458
3544
  this.operationData = { ...operationData };
3459
3545
  if (operationData.url.indexOf("[") > -1) this._parseFilename(operationData.url);
@@ -3461,7 +3547,9 @@ var LottieController = class {
3461
3547
  if (this.operationData.iefallback) this.serializedIEData = JSON.stringify(this.operationData.iefallback);
3462
3548
  }
3463
3549
  _parseFilename(name) {
3464
- name.substring(name.indexOf("[") + 1, name.indexOf("]") - name.indexOf("[") - 1).split(",").forEach((setting) => {
3550
+ const startIndex = name.indexOf("[") + 1;
3551
+ const endIndex = name.indexOf("]");
3552
+ name.substring(startIndex, endIndex).split(",").forEach((setting) => {
3465
3553
  const values = setting.split("=");
3466
3554
  if (values[0] === "freeze") this.freezePosition = +values[1];
3467
3555
  else if (values[0] === "end") this.endPosition = +values[1];
@@ -3474,16 +3562,14 @@ var LottieController = class {
3474
3562
  const resultHolder = {};
3475
3563
  eventbus$1.broadcast(TimelineEventNames.REQUEST_CURRENT_LANGUAGE, [resultHolder]);
3476
3564
  this.currentLanguage = resultHolder.language;
3477
- this.eventbusRemovers.push(eventbus$1.on(TimelineEventNames.LANGUAGE_CHANGE, this._handleLanguageChange.bind(this)));
3565
+ this.addListener(eventbus$1, TimelineEventNames.LANGUAGE_CHANGE, this._handleLanguageChange);
3478
3566
  eventbus$1.broadcast(TimelineEventNames.REQUEST_LABEL_COLLECTIONS, [this.operationData.labelIds, resultHolder]);
3479
3567
  this._createTextDataLookup(resultHolder.labelCollections);
3480
3568
  }
3481
3569
  this._createAnimation();
3482
3570
  }
3483
- detach(_eventbus) {
3484
- this.eventbusRemovers.forEach((func) => {
3485
- func();
3486
- });
3571
+ detach(eventbus$1) {
3572
+ super.detach(eventbus$1);
3487
3573
  if (this.animationItem) if (this.endPosition > -1) {
3488
3574
  this.animationItem.addEventListener("complete", this._destroy.bind(this));
3489
3575
  this.animationItem.playSegments([this.freezePosition, this.endPosition], true);
@@ -3500,8 +3586,8 @@ var LottieController = class {
3500
3586
  this.animationItem?.destroy();
3501
3587
  let serialized = this._isIE() && this.serializedIEData ? this.serializedIEData : this.serializedData;
3502
3588
  const { labelIds } = this.operationData;
3503
- if (labelIds && labelIds.length) labelIds.forEach((id) => {
3504
- serialized = serialized.split(`!!${id}!!`).join(this.labelData[id][this.currentLanguage]);
3589
+ if (labelIds && labelIds.length) serialized = serialized.replace(/!!([^!]+)!!/g, (match, labelId) => {
3590
+ return this.labelData[labelId]?.[this.currentLanguage] ?? match;
3505
3591
  });
3506
3592
  const animationData = JSON.parse(serialized);
3507
3593
  const animationSettings = {
@@ -3535,7 +3621,7 @@ var LottieController = class {
3535
3621
 
3536
3622
  //#endregion
3537
3623
  //#region src/controllers/navigation-controller.ts
3538
- var NavigationController = class {
3624
+ var NavigationController = class extends BaseController {
3539
3625
  name = "NavigationController";
3540
3626
  navigation = [];
3541
3627
  navLookup = {};
@@ -3543,10 +3629,8 @@ var NavigationController = class {
3543
3629
  ctrlLookup = {};
3544
3630
  activeNavigationPoint = null;
3545
3631
  labelControllers = [];
3546
- eventhandlers = [];
3547
3632
  eventbus = null;
3548
3633
  container = null;
3549
- constructor() {}
3550
3634
  init(operationData) {
3551
3635
  this.container = operationData.selectedElement;
3552
3636
  this.navigation = this._buildNavigationData(operationData.json);
@@ -3554,10 +3638,10 @@ var NavigationController = class {
3554
3638
  attach(eventbus$1) {
3555
3639
  if (!this.container) return;
3556
3640
  this.eventbus = eventbus$1;
3557
- this.eventhandlers.push(eventbus$1.on("navigate-to-video-url", this._handleNavigateVideoUrl.bind(this)));
3558
- this.eventhandlers.push(eventbus$1.on("highlight-navigation", this._highlightMenu.bind(this)));
3559
- this.eventhandlers.push(eventbus$1.on("request-current-navigation", this._handleRequestCurrentNavigation.bind(this)));
3560
- this.eventhandlers.push(eventbus$1.on("video-complete", this._handleVideoComplete.bind(this)));
3641
+ this.addListener(eventbus$1, "navigate-to-video-url", this._handleNavigateVideoUrl);
3642
+ this.addListener(eventbus$1, "highlight-navigation", this._highlightMenu);
3643
+ this.addListener(eventbus$1, "request-current-navigation", this._handleRequestCurrentNavigation);
3644
+ this.addListener(eventbus$1, "video-complete", this._handleVideoComplete);
3561
3645
  this._buildHtml(this.container, this.navigation);
3562
3646
  this._initHistory.bind(this);
3563
3647
  }
@@ -3587,9 +3671,7 @@ var NavigationController = class {
3587
3671
  } else resultCallback(null);
3588
3672
  }
3589
3673
  detach(eventbus$1) {
3590
- this.eventhandlers.forEach((handler) => {
3591
- handler();
3592
- });
3674
+ super.detach(eventbus$1);
3593
3675
  this.labelControllers.forEach((ctrl) => {
3594
3676
  ctrl.detach(eventbus$1);
3595
3677
  });
@@ -3702,31 +3784,28 @@ var NavigationController = class {
3702
3784
  *
3703
3785
  * The current progress as a percentage is rendered in the given text element.
3704
3786
  */
3705
- var ProgressbarController = class {
3787
+ var ProgressbarController = class extends BaseController {
3706
3788
  name = "ProgressbarController";
3707
3789
  selectedElement = null;
3708
3790
  textElement = null;
3709
- eventbusRemovers = [];
3710
3791
  duration = 0;
3711
3792
  init(operationData) {
3712
3793
  this.selectedElement = operationData.selectedElement;
3713
3794
  this.textElement = operationData.textElement;
3714
3795
  }
3715
3796
  attach(eventbus$1) {
3716
- this.eventbusRemovers.push(eventbus$1.on(TimelineEventNames.TIME, this._positionUpdateHandler.bind(this)));
3797
+ this.addListener(eventbus$1, TimelineEventNames.TIME, this._positionUpdateHandler);
3717
3798
  eventbus$1.broadcast(TimelineEventNames.DURATION_REQUEST, [(duration) => this.duration = duration]);
3718
3799
  this.selectedElement?.css({ "pointer-events": "none" });
3719
3800
  const container = this.selectedElement?.parent();
3720
3801
  if (container) {
3721
3802
  const clickHandler = this._clickHandler.bind(this, eventbus$1);
3722
3803
  container.on("click", clickHandler);
3723
- this.eventbusRemovers.push(() => container.off("click", clickHandler));
3804
+ this.eventListeners.push(() => container.off("click", clickHandler));
3724
3805
  }
3725
3806
  }
3726
- detach(_eventbus) {
3727
- this.eventbusRemovers.forEach((func) => {
3728
- func();
3729
- });
3807
+ detach(eventbus$1) {
3808
+ super.detach(eventbus$1);
3730
3809
  }
3731
3810
  _positionUpdateHandler(position) {
3732
3811
  const percentage = 100 / this.duration * position;
@@ -3746,20 +3825,18 @@ var ProgressbarController = class {
3746
3825
  /**
3747
3826
  * This is a work in progress, do not use this yet please....
3748
3827
  */
3749
- var RoutingController = class {
3828
+ var RoutingController = class extends BaseController {
3750
3829
  name = "RoutingController";
3751
3830
  navLookup = {};
3752
3831
  navVidIdLookup = {};
3753
3832
  navigation = null;
3754
- eventhandlers = [];
3755
3833
  eventbus = null;
3756
- constructor() {}
3757
3834
  init(operationData) {
3758
3835
  this.navigation = this._buildNavigationData(operationData.json);
3759
3836
  }
3760
3837
  attach(eventbus$1) {
3761
- this.eventhandlers.push(eventbus$1.on("before-request-video-url", this._handleBeforeRequestVideoUrl.bind(this)));
3762
- this.eventhandlers.push(eventbus$1.on("push-history-state", this._handlePushHistoryState.bind(this)));
3838
+ this.addListener(eventbus$1, "before-request-video-url", this._handleBeforeRequestVideoUrl);
3839
+ this.addListener(eventbus$1, "push-history-state", this._handlePushHistoryState);
3763
3840
  this.eventbus = eventbus$1;
3764
3841
  window.onpopstate = this._handlePopstate.bind(this);
3765
3842
  const navId = this._getQueryVariable(0);
@@ -3784,10 +3861,9 @@ var RoutingController = class {
3784
3861
  true
3785
3862
  ]);
3786
3863
  }
3787
- detach(_eventbus) {
3788
- if (this.eventhandlers) this.eventhandlers.forEach((handler) => {
3789
- handler();
3790
- });
3864
+ detach(eventbus$1) {
3865
+ super.detach(eventbus$1);
3866
+ window.onpopstate = null;
3791
3867
  this.eventbus = null;
3792
3868
  }
3793
3869
  _handleBeforeRequestVideoUrl(_index, _requestedVideoPosition = 0, isHistoryRequest = false) {
@@ -3862,29 +3938,19 @@ var RoutingController = class {
3862
3938
 
3863
3939
  //#endregion
3864
3940
  //#region src/controllers/subtitles-controller.ts
3865
- var SubtitlesController = class {
3941
+ var SubtitlesController = class extends BaseController {
3866
3942
  actionLookup = {};
3867
3943
  currentLanguage = null;
3868
3944
  lastFunc = null;
3869
3945
  name = "SubtitlesController";
3870
3946
  subtitleDurations = null;
3871
3947
  attach(eventbus$1) {
3872
- const detachTime = eventbus$1.on(TimelineEventNames.TIME, this.onTimeHandler.bind(this));
3873
- const detachSeek = eventbus$1.on(TimelineEventNames.SEEKED, this.onSeekedHandler.bind(this));
3874
- const detachLangChange = eventbus$1.on(TimelineEventNames.LANGUAGE_CHANGE, this.languageChangeHandler.bind(this));
3875
- this.internalDetach = this.internalDetach.bind(this, [
3876
- detachTime,
3877
- detachLangChange,
3878
- detachSeek
3879
- ]);
3880
- }
3881
- detach(_eventbus) {
3882
- this.internalDetach();
3948
+ this.addListener(eventbus$1, TimelineEventNames.TIME, this.onTimeHandler);
3949
+ this.addListener(eventbus$1, TimelineEventNames.SEEKED, this.onSeekedHandler);
3950
+ this.addListener(eventbus$1, TimelineEventNames.LANGUAGE_CHANGE, this.languageChangeHandler);
3883
3951
  }
3884
- internalDetach(detachMethods) {
3885
- if (detachMethods) detachMethods.forEach((f) => {
3886
- f();
3887
- });
3952
+ detach(eventbus$1) {
3953
+ super.detach(eventbus$1);
3888
3954
  }
3889
3955
  languageChangeHandler(newLanguage) {
3890
3956
  this.currentLanguage = newLanguage;
@@ -3903,7 +3969,7 @@ var SubtitlesController = class {
3903
3969
  }
3904
3970
  onSeekedHandler(args) {
3905
3971
  const position = args[0];
3906
- const duration = this.subtitleDurations?.find((x) => x.start <= position || x.end >= position);
3972
+ const duration = this.subtitleDurations?.find((x) => x.start <= position && x.end >= position);
3907
3973
  const func = duration ? this.actionLookup[duration.start ?? -1] : void 0;
3908
3974
  if (func && this.lastFunc !== func) {
3909
3975
  this.lastFunc = func;
@@ -3940,7 +4006,7 @@ var SubtitlesController = class {
3940
4006
  //#endregion
3941
4007
  //#region src/controllers/index.ts
3942
4008
  var controllers_exports = /* @__PURE__ */ __export({
3943
- EventListenerController: () => EventListenerController,
4009
+ DOMEventListenerController: () => DOMEventListenerController,
3944
4010
  LabelController: () => LabelController,
3945
4011
  LottieController: () => LottieController,
3946
4012
  NavigationController: () => NavigationController,
@@ -4125,7 +4191,7 @@ Or, if the \`properties\` property is set only removes the properties defined by
4125
4191
  function continueForEach$1() {
4126
4192
  return { description: `
4127
4193
  This operation should only be used within a loop, so between a {@link forEach} and {@link endForEach}
4128
- operation. This operation immediately moves to the next loop index, effectively canceling the rest
4194
+ operation. This operation immediately moves to the next loop index, effectively canceling the rest
4129
4195
  of the operations in the current iteration.` };
4130
4196
  }
4131
4197
 
@@ -4224,7 +4290,7 @@ assigned to the {@link IOperationScope.currentItem |currentItem} property on the
4224
4290
  At the start of the loop, the associated {@link endForEach} operation is determined and when
4225
4291
  the last iteration is completed the flow control is set to the index of that operation.
4226
4292
 
4227
- The {@link continueForEach |continue} and {@link breakForEach |break} operations can be used to control the
4293
+ The {@link continueForEach |continue} and {@link breakForEach |break} operations can be used to control the
4228
4294
  loop iterations.`,
4229
4295
  properties: { collection: {
4230
4296
  type: "ParameterType:array|ParameterType:string",
@@ -4272,7 +4338,7 @@ function getControllerInstance$1() {
4272
4338
  It assigns this instance to the \`controllerInstance\` property on the current operation data`,
4273
4339
  properties: { systemName: {
4274
4340
  type: [
4275
- { value: "EventListenerController" },
4341
+ { value: "DOMEventListenerController" },
4276
4342
  { value: "LabelController" },
4277
4343
  { value: "LottieController" },
4278
4344
  { value: "NavigationController" },
@@ -5133,6 +5199,7 @@ function resolvePlaceholder(key, configFragment, rootConfig, importer) {
5133
5199
  */
5134
5200
  var EligiusEngine = class EligiusEngine {
5135
5201
  _timeLineActionsLookup = {};
5202
+ _timelineLookupCache = /* @__PURE__ */ new Map();
5136
5203
  _eventbusRemovers = [];
5137
5204
  _currentTimelineUri = "";
5138
5205
  _activeTimelineProvider = void 0;
@@ -5273,16 +5340,20 @@ var EligiusEngine = class EligiusEngine {
5273
5340
  _createTimelineLookup() {
5274
5341
  if (!this.configuration.timelines) return;
5275
5342
  this.configuration.timelines.forEach((timelineInfo) => {
5276
- timelineInfo.timelineActions.forEach(this._addTimelineActionStart.bind(this, timelineInfo.uri));
5277
- });
5278
- this.configuration.timelines.forEach((timelineInfo) => {
5279
- timelineInfo.timelineActions.forEach(this._addTimelineActionEnd.bind(this, timelineInfo.uri));
5343
+ this._timelineLookupCache.set(timelineInfo.uri, timelineInfo);
5344
+ timelineInfo.timelineActions.forEach((timelineAction) => {
5345
+ this._addTimelineActionStart(timelineInfo.uri, timelineAction);
5346
+ this._addTimelineActionEnd(timelineInfo.uri, timelineAction);
5347
+ });
5280
5348
  });
5281
5349
  EligiusEngine.sortTimelines(Object.values(this._timeLineActionsLookup));
5282
5350
  }
5283
5351
  static sortTimelines(timelines) {
5284
5352
  timelines.forEach((timelineActions) => {
5285
- Object.keys(timelineActions).forEach((key) => timelineActions[key] = EligiusEngine.sortActionsPerPosition(timelineActions[key]));
5353
+ Object.keys(timelineActions).forEach((key) => {
5354
+ const numericKey = Number(key);
5355
+ timelineActions[numericKey] = EligiusEngine.sortActionsPerPosition(timelineActions[numericKey]);
5356
+ });
5286
5357
  });
5287
5358
  }
5288
5359
  static sortActionsPerPosition(actions) {
@@ -5323,12 +5394,9 @@ var EligiusEngine = class EligiusEngine {
5323
5394
  if (!lookup[position]) lookup[position] = [];
5324
5395
  return lookup[position];
5325
5396
  }
5326
- async _executeActions(actions, methodName, idx = 0) {
5327
- if (actions && idx < actions.length) {
5328
- await actions[idx][methodName]();
5329
- return this._executeActions(actions, methodName, ++idx);
5330
- }
5331
- return Promise.resolve();
5397
+ async _executeActions(actions, methodName) {
5398
+ if (actions.length === 0) return;
5399
+ for (const action of actions) await action[methodName]();
5332
5400
  }
5333
5401
  _handleRequestEngineRoot(engineRootSelector, resultCallback) {
5334
5402
  resultCallback($(engineRootSelector));
@@ -5337,7 +5405,7 @@ var EligiusEngine = class EligiusEngine {
5337
5405
  if (!this._activeTimelineProvider) return;
5338
5406
  this._activeTimelineProvider.stop();
5339
5407
  await this._cleanUpTimeline();
5340
- const timelineConfig = this.configuration.timelines.find((timeline) => timeline.uri === uri);
5408
+ const timelineConfig = this._timelineLookupCache.get(uri);
5341
5409
  if (!timelineConfig || !this._activeTimelineProvider || this._currentTimelineUri === timelineConfig.uri) return;
5342
5410
  this._currentTimelineUri = timelineConfig.uri;
5343
5411
  this.eventbus.broadcast(TimelineEventNames.CURRENT_TIMELINE_CHANGE, [this._currentTimelineUri]);
@@ -5379,7 +5447,7 @@ var EligiusEngine = class EligiusEngine {
5379
5447
  _executeRelevantActions(filter, executionType) {
5380
5448
  const timelineActions = this._getTimelineActionsForCurrentTimeline();
5381
5449
  const currentActions = filter.apply(this, [timelineActions]);
5382
- return this._executeActions(currentActions, executionType, 0);
5450
+ return this._executeActions(currentActions, executionType);
5383
5451
  }
5384
5452
  _handleRequestTimelinePosition(floor, resultCallback) {
5385
5453
  resultCallback(floor(this._activeTimelineProvider?.getPosition() || -1));
@@ -5394,9 +5462,7 @@ var EligiusEngine = class EligiusEngine {
5394
5462
  resultCallback(this._currentTimelineUri);
5395
5463
  }
5396
5464
  _getTimelineActionsForUri(uri) {
5397
- return this.configuration.timelines.find((timelineInfo) => {
5398
- return timelineInfo.uri === uri;
5399
- })?.timelineActions ?? [];
5465
+ return this._timelineLookupCache.get(uri)?.timelineActions ?? [];
5400
5466
  }
5401
5467
  _onTimeHandler(floor, position) {
5402
5468
  if (!isNaN(position)) {
@@ -5417,8 +5483,8 @@ var EligiusEngine = class EligiusEngine {
5417
5483
  if (!timelineActions) return Promise.resolve();
5418
5484
  const currentActions = this._getActiveActions(timelineActions).filter((action) => !(action.duration.start <= position && action.duration.end >= position));
5419
5485
  const newActions = this._getActionsForPosition(position, timelineActions);
5420
- await this._executeActions(currentActions, "end", 0);
5421
- return this._executeActions(newActions, "start", 0);
5486
+ await this._executeActions(currentActions, "end");
5487
+ return this._executeActions(newActions, "start");
5422
5488
  }
5423
5489
  };
5424
5490
  const sortActionsHighestStartPositionFirst = (a, b) => {
@@ -5802,5 +5868,5 @@ var EligiusResourceImporter = class {
5802
5868
  };
5803
5869
 
5804
5870
  //#endregion
5805
- export { Action, ActionCreator, ActionCreatorFactory, ActionEditor, ActionRegistryEventbusListener, ConfigurationFactory, ConfigurationResolver, ControllerNamesProvider, DEV_TOOLS_KEY, DevToolEventListener, Diagnostics, EligiusEngine, EligiusResourceImporter, EndableAction, EndableActionCreator, EndableActionEditor, EngineFactory, EventListenerController, Eventbus, LabelController, LanguageManager, LottieController, NavigationController, OperationEditor, OperationMetadataProvider, OperationNamesProvider, ProgressbarController, RequestAnimationFrameTimelineProvider, RequestVideoUriInterceptor, RoutingController, SubtitleEditor, SubtitleImporter, SubtitlesController, TimeLineEventNamesProvider, TimelineAction, TimelineActionCreator, TimelineActionEditor, TimelineEventNames, TimelineProviderSettingsEditor, TimelineProvidersSettingsEditor, VideoJsTimelineProvider, addClass, addControllerToElement, addGlobalsToOperation, animate, animateWithClass, breakForEach, broadcastEvent, calc, clearElement, clearOperationData, continueForEach, createElement, customFunction, endAction, endForEach, endWhen, extendController, forEach, generateImporterSourceCode, getAttributesFromElement, getControllerFromElement, getControllerInstance, getElementDimensions, getImport, getQueryParams, invokeObjectMethod, loadJson, log, math, metadata_exports as metadata, otherwise, removeClass, removeControllerFromElement, removeElement, removePropertiesFromOperationData, reparentElement, requestAction, selectElement, setData, setElementAttributes, setElementContent, setGlobalData, setOperationData, setStyle, setVariable, startAction, toggleClass, toggleElement, wait, when };
5871
+ export { Action, ActionCreator, ActionCreatorFactory, ActionEditor, ActionRegistryEventbusListener, ConfigurationFactory, ConfigurationResolver, ControllerNamesProvider, DEV_TOOLS_KEY, DOMEventListenerController, DevToolEventListener, Diagnostics, EligiusEngine, EligiusResourceImporter, EndableAction, EndableActionCreator, EndableActionEditor, EngineFactory, Eventbus, LabelController, LanguageManager, LottieController, NavigationController, OperationEditor, OperationMetadataProvider, OperationNamesProvider, ProgressbarController, RequestAnimationFrameTimelineProvider, RequestVideoUriInterceptor, RoutingController, SubtitleEditor, SubtitleImporter, SubtitlesController, TimeLineEventNamesProvider, TimelineAction, TimelineActionCreator, TimelineActionEditor, TimelineEventNames, TimelineProviderSettingsEditor, TimelineProvidersSettingsEditor, VideoJsTimelineProvider, addClass, addControllerToElement, addGlobalsToOperation, animate, animateWithClass, breakForEach, broadcastEvent, calc, clearElement, clearOperationData, continueForEach, createElement, customFunction, endAction, endForEach, endWhen, extendController, forEach, generateImporterSourceCode, getAttributesFromElement, getControllerFromElement, getControllerInstance, getElementDimensions, getImport, getQueryParams, invokeObjectMethod, loadJson, log, math, metadata_exports as metadata, otherwise, removeClass, removeControllerFromElement, removeElement, removePropertiesFromOperationData, reparentElement, requestAction, selectElement, setData, setElementAttributes, setElementContent, setGlobalData, setOperationData, setStyle, setVariable, startAction, toggleClass, toggleElement, wait, when };
5806
5872
  //# sourceMappingURL=index.js.map