@xibosignage/xibo-layout-renderer 1.0.27 → 1.0.28

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.
@@ -19,30 +19,6 @@ var XiboLayoutRenderer = (function (exports) {
19
19
  return !!t;
20
20
  })();
21
21
  }
22
- function _iterableToArrayLimit(r, l) {
23
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
24
- if (null != t) {
25
- var e,
26
- n,
27
- i,
28
- u,
29
- a = [],
30
- f = !0,
31
- o = !1;
32
- try {
33
- if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
34
- } catch (r) {
35
- o = !0, n = r;
36
- } finally {
37
- try {
38
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
39
- } finally {
40
- if (o) throw n;
41
- }
42
- }
43
- return a;
44
- }
45
- }
46
22
  function ownKeys(e, r) {
47
23
  var t = Object.keys(e);
48
24
  if (Object.getOwnPropertySymbols) {
@@ -521,18 +497,12 @@ var XiboLayoutRenderer = (function (exports) {
521
497
  }
522
498
  return _assertThisInitialized(self);
523
499
  }
524
- function _slicedToArray(arr, i) {
525
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
526
- }
527
500
  function _toConsumableArray(arr) {
528
501
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
529
502
  }
530
503
  function _arrayWithoutHoles(arr) {
531
504
  if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
532
505
  }
533
- function _arrayWithHoles(arr) {
534
- if (Array.isArray(arr)) return arr;
535
- }
536
506
  function _iterableToArray(iter) {
537
507
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
538
508
  }
@@ -552,9 +522,6 @@ var XiboLayoutRenderer = (function (exports) {
552
522
  function _nonIterableSpread() {
553
523
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
554
524
  }
555
- function _nonIterableRest() {
556
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
557
- }
558
525
  function _createForOfIteratorHelper(o, allowArrayLike) {
559
526
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
560
527
  if (!it) {
@@ -1061,6 +1028,13 @@ var XiboLayoutRenderer = (function (exports) {
1061
1028
  },
1062
1029
  gotoNextLayout: function gotoNextLayout() {},
1063
1030
  gotoPrevLayout: function gotoPrevLayout() {},
1031
+ gotoLayoutByCode: function gotoLayoutByCode(_layoutCode) {
1032
+ return Promise.resolve();
1033
+ },
1034
+ playInterruptLayout: function playInterruptLayout(_inputLayout) {
1035
+ return Promise.resolve();
1036
+ },
1037
+ triggerAction: function triggerAction(_triggerCode, _widgetId) {},
1064
1038
  init: function init() {
1065
1039
  return Promise.resolve({});
1066
1040
  },
@@ -1099,7 +1073,7 @@ var XiboLayoutRenderer = (function (exports) {
1099
1073
  renderOverlayLayouts: function renderOverlayLayouts() {
1100
1074
  return Promise.resolve();
1101
1075
  },
1102
- uniqueLayouts: {},
1076
+ uniqueLayouts: new Map(),
1103
1077
  updateInputLayout: function updateInputLayout(layoutIndex, layout) {},
1104
1078
  updateLayouts: function updateLayouts(inputLayouts) {},
1105
1079
  updateLoop: function updateLoop(inputLayouts) {
@@ -14019,11 +13993,11 @@ var XiboLayoutRenderer = (function (exports) {
14019
13993
  * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
14020
13994
  * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization
14021
13995
  */
14022
- function DOMParser$1(options){
13996
+ function DOMParser$2(options){
14023
13997
  this.options = options ||{locator:{}};
14024
13998
  }
14025
13999
 
14026
- DOMParser$1.prototype.parseFromString = function(source,mimeType){
14000
+ DOMParser$2.prototype.parseFromString = function(source,mimeType){
14027
14001
  var options = this.options;
14028
14002
  var sax = new XMLReader();
14029
14003
  var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
@@ -14270,9 +14244,9 @@ var XiboLayoutRenderer = (function (exports) {
14270
14244
 
14271
14245
  domParser.__DOMHandler = DOMHandler;
14272
14246
  domParser.normalizeLineEndings = normalizeLineEndings;
14273
- domParser.DOMParser = DOMParser$1;
14247
+ domParser.DOMParser = DOMParser$2;
14274
14248
 
14275
- var DOMParser = domParser.DOMParser;
14249
+ var DOMParser$1 = domParser.DOMParser;
14276
14250
 
14277
14251
  /*! @name mpd-parser @version 1.3.1 @license Apache-2.0 */
14278
14252
 
@@ -16896,7 +16870,7 @@ var XiboLayoutRenderer = (function (exports) {
16896
16870
  throw new Error(errors.DASH_EMPTY_MANIFEST);
16897
16871
  }
16898
16872
 
16899
- const parser = new DOMParser();
16873
+ const parser = new DOMParser$1();
16900
16874
  let xml;
16901
16875
  let mpd;
16902
16876
 
@@ -74025,14 +73999,13 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74025
73999
  _this.startMediaTimer(media);
74026
74000
  }
74027
74001
  } else if (media.mediaType === 'shellcommand') {
74028
- if (_this.hasCommandExecuted && !_this.loop) {
74029
- return;
74030
- }
74031
- _this.hasCommandExecuted = true;
74032
- _this.emitCommand(media);
74033
- if (media.duration > 0) {
74034
- _this.startMediaTimer(media);
74002
+ // Fire once per cycle unless loop is enabled, in which case re-fire every play.
74003
+ if (!_this.hasCommandExecuted || _this.loop) {
74004
+ _this.hasCommandExecuted = true;
74005
+ _this.emitCommand(media);
74035
74006
  }
74007
+ // Always run the timer so the layout advances and stats are recorded correctly.
74008
+ _this.startMediaTimer(media);
74036
74009
  } else {
74037
74010
  _this.startMediaTimer(media);
74038
74011
  }
@@ -74108,7 +74081,12 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74108
74081
  var _this$sspImpressionUr2, _this$sspErrorUrls2;
74109
74082
  _this.xlr.emitter.emit('sspWidgetEnd', (_this$sspImpressionUr2 = _this.sspImpressionUrls) !== null && _this$sspImpressionUr2 !== void 0 ? _this$sspImpressionUr2 : [], (_this$sspErrorUrls2 = _this.sspErrorUrls) !== null && _this$sspErrorUrls2 !== void 0 ? _this$sspErrorUrls2 : [], _this.sspImpressionUrls ? _this.duration : 0);
74110
74083
  }
74111
- media.region.playNextMedia();
74084
+ // Only advance the region if this media is still the active one.
74085
+ // A user-triggered next/prev action may have already moved currMedia
74086
+ // on, in which case the timer firing here would cause a double-advance.
74087
+ if (media === media.region.currMedia) {
74088
+ media.region.playNextMedia();
74089
+ }
74112
74090
  });
74113
74091
  // Initialize Media object
74114
74092
  this.init();
@@ -74341,11 +74319,11 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74341
74319
  };
74342
74320
  var getNewMedia = function getNewMedia() {
74343
74321
  var $region = _this3.region.html;
74344
- // This function is for checking whether
74345
- // the region still has to show a media item
74346
- // when another region is not finished yet
74347
- if (_this3.region.complete && !_this3.region.layout.allEnded) {
74348
- // Add currentMedia to the region
74322
+ // Re-insert the element whenever it is missing from the DOM. This covers:
74323
+ // 1. Region completed early but the layout is still running (freeze last frame).
74324
+ // 2. Backward navigation the previous media's element was removed by the
74325
+ // removeOldMedia setTimeout in transitionNodes.
74326
+ if (_this3.html) {
74349
74327
  $region.insertBefore(_this3.html, $region.lastElementChild);
74350
74328
  return _this3.html;
74351
74329
  }
@@ -74611,15 +74589,21 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74611
74589
  });
74612
74590
  // Add media to region for targeted actions
74613
74591
  (_this$layout$actionCo = this.layout.actionController) === null || _this$layout$actionCo === void 0 || _this$layout$actionCo.actions.forEach(function (action) {
74592
+ var _ref2, _attributes$actionTyp, _ref3, _attributes$targetId, _ref4, _attributes$widgetId, _attributes$target;
74614
74593
  var attributes = getAllAttributes(action.xml);
74615
- if (attributes.target.value === 'region' && attributes.actionType.value === 'navWidget' && attributes.targetId.value == _this.id) {
74594
+ // getAllAttributes preserves the XML attribute case. Xibo CMS may export
74595
+ // attributes in camelCase (actionType, targetId, widgetId) or lowercase.
74596
+ // Read both variants so we work with either XLF format.
74597
+ var actionType = (_ref2 = (_attributes$actionTyp = attributes['actionType']) !== null && _attributes$actionTyp !== void 0 ? _attributes$actionTyp : attributes['actiontype']) === null || _ref2 === void 0 ? void 0 : _ref2.value;
74598
+ var targetId = (_ref3 = (_attributes$targetId = attributes['targetId']) !== null && _attributes$targetId !== void 0 ? _attributes$targetId : attributes['targetid']) === null || _ref3 === void 0 ? void 0 : _ref3.value;
74599
+ var widgetId = (_ref4 = (_attributes$widgetId = attributes['widgetId']) !== null && _attributes$widgetId !== void 0 ? _attributes$widgetId : attributes['widgetid']) === null || _ref4 === void 0 ? void 0 : _ref4.value;
74600
+ if (((_attributes$target = attributes['target']) === null || _attributes$target === void 0 ? void 0 : _attributes$target.value) === 'region' && actionType === 'navWidget' && targetId == _this.id) {
74616
74601
  var _this$layout$drawer;
74617
74602
  var drawerMediaItems = Array.from(((_this$layout$drawer = _this.layout.drawer) === null || _this$layout$drawer === void 0 ? void 0 : _this$layout$drawer.getElementsByTagName('media')) || []);
74618
74603
  drawerMediaItems.forEach(function (drawerMedia) {
74619
- var _attributes$widgetId;
74620
- if (drawerMedia.id === ((_attributes$widgetId = attributes.widgetId) === null || _attributes$widgetId === void 0 ? void 0 : _attributes$widgetId.value)) {
74604
+ if (drawerMedia.getAttribute('id') === widgetId) {
74621
74605
  // Add drawer media to the region
74622
- _this.mediaObjectsActions.push(new Media(_this, (drawerMedia === null || drawerMedia === void 0 ? void 0 : drawerMedia.getAttribute('id')) || '', drawerMedia, _this.options, _this.xlr));
74606
+ _this.mediaObjectsActions.push(new Media(_this, drawerMedia.getAttribute('id') || '', drawerMedia, _this.options, _this.xlr));
74623
74607
  }
74624
74608
  });
74625
74609
  }
@@ -74651,6 +74635,11 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74651
74635
  prepareAudioMedia(media, this);
74652
74636
  } else if ((media.render === 'html' || media.mediaType === 'webpage') && media.iframe && media.checkIframeStatus) {
74653
74637
  prepareHtmlMedia(media, this);
74638
+ } else if (media.mediaType === 'shellcommand') {
74639
+ // Shell command widgets are invisible but must be in the DOM to trigger playback.
74640
+ if (media.html) {
74641
+ this.html.appendChild(media.html);
74642
+ }
74654
74643
  }
74655
74644
  }
74656
74645
  }, {
@@ -74874,7 +74863,17 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74874
74863
  }, {
74875
74864
  key: "playNextMedia",
74876
74865
  value: function playNextMedia() {
74877
- var _this$oldMedia3, _this$currMedia2, _this$nxtMedia, _this$currMedia3, _this$currMedia4, _this$currMedia5, _this$currMedia6, _this$oldMedia4, _this$currMedia7, _this$nxtMedia2;
74866
+ var _this$oldMedia3,
74867
+ _this$currMedia2,
74868
+ _this$nxtMedia,
74869
+ _this$currMedia3,
74870
+ _this$currMedia4,
74871
+ _this$currMedia5,
74872
+ _this$currMedia6,
74873
+ _this3 = this,
74874
+ _this$oldMedia4,
74875
+ _this$currMedia7,
74876
+ _this$nxtMedia2;
74878
74877
  console.debug('??? XLR.debug Region playing next media', {
74879
74878
  regionId: this.id,
74880
74879
  currentMediaIndex: this.currentMediaIndex,
@@ -74894,8 +74893,10 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74894
74893
  // cycle completion after the skip loop runs.
74895
74894
  var origIndex = this.currentMediaIndex;
74896
74895
  // When the region has completed and when currentMedia is html
74897
- // Then, preserve the currentMedia state
74898
- if (this.complete && ((_this$currMedia3 = this.currMedia) === null || _this$currMedia3 === void 0 ? void 0 : _this$currMedia3.render) === 'html') {
74896
+ // and there is only one media object, preserve the currentMedia state.
74897
+ // Guard is limited to single-media regions so navWidget injections
74898
+ // (which splice a second media in) are not blocked.
74899
+ if (this.complete && ((_this$currMedia3 = this.currMedia) === null || _this$currMedia3 === void 0 ? void 0 : _this$currMedia3.render) === 'html' && this.totalMediaObjects === 1) {
74899
74900
  return;
74900
74901
  }
74901
74902
  // When the region has completed and mediaObjects.length = 1
@@ -74941,6 +74942,25 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74941
74942
  }
74942
74943
  });
74943
74944
  }
74945
+ // Remove single-play media injected via navWidget actions at the end of each cycle
74946
+ if (crossedEnd && this.mediaObjects.some(function (m) {
74947
+ return m.singlePlay;
74948
+ })) {
74949
+ this.mediaObjects = this.mediaObjects.filter(function (m) {
74950
+ return !m.singlePlay;
74951
+ });
74952
+ this.totalMediaObjects = this.mediaObjects.length;
74953
+ if (this.totalMediaObjects === 0) {
74954
+ this.finished();
74955
+ return;
74956
+ }
74957
+ var newIndex = this.mediaObjects.findIndex(function (m) {
74958
+ return m === _this3.currMedia;
74959
+ });
74960
+ this.currentMediaIndex = newIndex >= 0 ? newIndex : 0;
74961
+ this.currMedia = this.mediaObjects[this.currentMediaIndex];
74962
+ this.nxtMedia = this.mediaObjects[(this.currentMediaIndex + 1) % this.totalMediaObjects];
74963
+ }
74944
74964
  console.debug('??? XLR.debug >> End Region::playNextMedia > execute transitionNodes', {
74945
74965
  regionId: this.id,
74946
74966
  currentMediaIndex: this.currentMediaIndex,
@@ -74961,14 +74981,15 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74961
74981
  }, {
74962
74982
  key: "playPreviousMedia",
74963
74983
  value: function playPreviousMedia() {
74964
- this.currentMediaIndex = this.currentMediaIndex - 1;
74965
- if (this.currentMediaIndex < 0 || this.ended) {
74966
- this.currentMediaIndex = 0;
74984
+ if (this.currentMediaIndex <= 0 || this.ended) {
74967
74985
  return;
74968
74986
  }
74969
- this.prepareMediaObjects();
74987
+ this.oldMedia = this.currMedia;
74988
+ this.currentMediaIndex -= 1;
74989
+ this.currMedia = this.mediaObjects[this.currentMediaIndex];
74990
+ this.nxtMedia = this.mediaObjects[(this.currentMediaIndex + 1) % this.totalMediaObjects];
74991
+ this.complete = false;
74970
74992
  console.debug('region::playPreviousMedia', this);
74971
- /* Do the transition */
74972
74993
  this.transitionNodes(this.oldMedia, this.currMedia);
74973
74994
  }
74974
74995
  }, {
@@ -75167,6 +75188,10 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75167
75188
  key: "openLayoutInNewTab",
75168
75189
  value: function openLayoutInNewTab(layoutCode, options) {
75169
75190
  var url = options.layoutPreviewUrl.replace('[layoutCode]', layoutCode) + '?findByCode=1';
75191
+ console.debug('[ActionController::openLayoutInNewTab] Navigating to layout in new tab with code', {
75192
+ layoutCode: layoutCode,
75193
+ url: url
75194
+ });
75170
75195
  // Send a postMessage to the parent frame so the CMS can handle the confirmation
75171
75196
  // and navigation (confirm() is blocked in sandboxed iframes without allow-modals).
75172
75197
  window.parent.postMessage({
@@ -75179,26 +75204,40 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75179
75204
  }
75180
75205
  }, {
75181
75206
  key: "openLayoutInPlayer",
75182
- value: function openLayoutInPlayer(layoutCode, options) {
75183
- // this.parent.xlr.updateLoop([]);
75207
+ value: function openLayoutInPlayer(layoutCode, _options) {
75208
+ console.debug('[ActionController::openLayoutInPlayer] Navigating to layout in player with code', {
75209
+ layoutCode: layoutCode,
75210
+ options: _options
75211
+ });
75212
+ this.parent.xlr.emitter.emit('navLayout', layoutCode, '');
75184
75213
  }
75185
75214
  }, {
75186
75215
  key: "prevOrNextLayout",
75187
75216
  value: function prevOrNextLayout(targetId, actionType) {
75188
75217
  var _this$parent$xlr$curr;
75189
- // Check if currentLayout is the targetId
75190
- if (((_this$parent$xlr$curr = this.parent.xlr.currentLayout) === null || _this$parent$xlr$curr === void 0 ? void 0 : _this$parent$xlr$curr.layoutId) === parseInt(targetId)) {
75191
- if (actionType === 'next') {
75192
- this.parent.xlr.gotoNextLayout();
75193
- } else if (actionType === 'previous') {
75194
- this.parent.xlr.gotoPrevLayout();
75195
- }
75218
+ console.debug('[ActionController::prevOrNextLayout] Changing layout with data', {
75219
+ targetId: targetId,
75220
+ actionType: actionType
75221
+ });
75222
+ // For screen-level actions targetId may be "0" (the screen has no numeric ID).
75223
+ // Guard using this.parent.layoutId instead so the check always works.
75224
+ if (((_this$parent$xlr$curr = this.parent.xlr.currentLayout) === null || _this$parent$xlr$curr === void 0 ? void 0 : _this$parent$xlr$curr.layoutId) !== this.parent.layoutId) {
75225
+ return;
75226
+ }
75227
+ if (actionType === 'next') {
75228
+ this.parent.xlr.gotoNextLayout();
75229
+ } else if (actionType === 'previous') {
75230
+ this.parent.xlr.gotoPrevLayout();
75196
75231
  }
75197
75232
  }
75198
75233
  /** Change media in region (next/previous) */
75199
75234
  }, {
75200
- key: "nextMediaInRegion",
75201
- value: function nextMediaInRegion(regionId, actionType) {
75235
+ key: "gotoMediaInRegion",
75236
+ value: function gotoMediaInRegion(regionId, actionType) {
75237
+ console.debug('[ActionController::gotoMediaInRegion] Changing media in region with data', {
75238
+ regionId: regionId,
75239
+ actionType: actionType
75240
+ });
75202
75241
  // Find target region
75203
75242
  this.parent.regions.forEach(function (regionObj) {
75204
75243
  if (regionObj.id === regionId) {
@@ -75213,7 +75252,11 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75213
75252
  }, {
75214
75253
  key: "loadMediaInRegion",
75215
75254
  value: function loadMediaInRegion(regionId, widgetId) {
75216
- var _targetRegion, _targetRegion2, _targetRegion3;
75255
+ var _targetRegion, _targetRegion2, _targetRegion3, _targetRegion4;
75256
+ console.debug('[ActionController::loadMediaInRegion] Loading media in region with data', {
75257
+ regionId: regionId,
75258
+ widgetId: widgetId
75259
+ });
75217
75260
  var self = this;
75218
75261
  // Find target region
75219
75262
  var targetRegion;
@@ -75236,27 +75279,70 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75236
75279
  targetMedia.singlePlay = true;
75237
75280
  }
75238
75281
  // If region is empty, remove the background color and empty message
75239
- if (((_targetRegion = targetRegion) === null || _targetRegion === void 0 ? void 0 : _targetRegion.mediaObjects.length) === 0) {
75282
+ if (((_targetRegion = targetRegion) === null || _targetRegion === void 0 ? void 0 : _targetRegion.totalMediaObjects) === 0) {
75283
+ targetRegion.complete = false;
75284
+ }
75285
+ // Bail out early when the target widget was not found in the drawer
75286
+ if (!targetMedia) {
75287
+ console.debug('[ActionController::loadMediaInRegion] Target media not found in mediaObjectsActions', {
75288
+ regionId: regionId,
75289
+ widgetId: widgetId
75290
+ });
75291
+ return;
75292
+ }
75293
+ // Guard against duplicate insertion if the action fires multiple times before the widget plays
75294
+ if (targetRegion && targetRegion.mediaObjects.some(function (m) {
75295
+ return m.id === targetMedia.id;
75296
+ })) {
75297
+ console.debug('[ActionController::loadMediaInRegion] Target media already queued, skipping duplicate insertion');
75298
+ return;
75299
+ }
75300
+ // Cancel the current media's duration timer so it doesn't fire and interrupt
75301
+ // the target widget mid-playback (e.g. an Interactive Zone timer still ticking).
75302
+ if ((_targetRegion2 = targetRegion) !== null && _targetRegion2 !== void 0 && (_targetRegion2 = _targetRegion2.currMedia) !== null && _targetRegion2 !== void 0 && _targetRegion2.mediaTimer) {
75303
+ clearInterval(targetRegion.currMedia.mediaTimer);
75304
+ targetRegion.currMedia.mediaTimer = undefined;
75305
+ }
75306
+ // Reset complete so the HTML-media guard in playNextMedia() doesn't block
75307
+ // the transition (that guard is for single-media loops, not navWidget injections).
75308
+ if (targetRegion) {
75240
75309
  targetRegion.complete = false;
75241
75310
  }
75242
75311
  // Create media in region and play it next
75243
- (_targetRegion2 = targetRegion) === null || _targetRegion2 === void 0 || _targetRegion2.mediaObjects.splice(targetRegion.currentMediaIndex + 1, 0, targetMedia);
75244
- (_targetRegion3 = targetRegion) === null || _targetRegion3 === void 0 || _targetRegion3.playNextMedia();
75312
+ (_targetRegion3 = targetRegion) === null || _targetRegion3 === void 0 || _targetRegion3.mediaObjects.splice(targetRegion.currentMediaIndex + 1, 0, targetMedia);
75313
+ // Keep totalMediaObjects in sync with the actual array length
75314
+ if (targetRegion) {
75315
+ targetRegion.totalMediaObjects = targetRegion.mediaObjects.length;
75316
+ }
75317
+ // Drawer media items are never run through the normal prepareMedia pipeline,
75318
+ // so their DOM element has no background-image / src set and is not yet in the
75319
+ // region DOM. Prepare it now so Media.run() finds a ready element to show.
75320
+ if (targetRegion) {
75321
+ targetRegion.prepareMedia(targetMedia);
75322
+ }
75323
+ console.debug('[ActionController::loadMediaInRegion] Target media loaded, playing next', {
75324
+ regionId: regionId,
75325
+ widgetId: widgetId
75326
+ });
75327
+ (_targetRegion4 = targetRegion) === null || _targetRegion4 === void 0 || _targetRegion4.playNextMedia();
75245
75328
  }
75246
75329
  /** Run action based on action data */
75247
75330
  }, {
75248
75331
  key: "runAction",
75249
75332
  value: function runAction(actionData, options) {
75333
+ console.debug('[ActionController::runAction] Triggering action', {
75334
+ actionData: actionData
75335
+ });
75250
75336
  if (actionData.actiontype == 'navLayout') {
75251
75337
  if (this.parent.xlr.config.platform === exports.ConsumerPlatform.CMS) {
75252
- // Open layout preview in a new tab
75338
+ // Open layout preview in a new tab (CMS preview only)
75253
75339
  this.openLayoutInNewTab(actionData.layoutcode, options);
75254
- } else if (this.parent.xlr.config.platform === exports.ConsumerPlatform.CHROMEOS) {
75255
- // Set target layout as active layout
75340
+ } else {
75341
+ // All player platforms (Electron, ChromeOS, Android, etc.)
75256
75342
  this.openLayoutInPlayer(actionData.layoutcode, options);
75257
75343
  }
75258
75344
  } else if ((actionData.actiontype == 'previous' || actionData.actiontype == 'next') && actionData.target == 'region') {
75259
- this.nextMediaInRegion(actionData.targetid, actionData.actiontype);
75345
+ this.gotoMediaInRegion(actionData.targetid, actionData.actiontype);
75260
75346
  } else if (actionData.actiontype == 'navWidget' && actionData.target == 'region') {
75261
75347
  this.loadMediaInRegion(actionData.targetid, actionData.widgetid);
75262
75348
  } else if (actionData.target === 'screen') {
@@ -75315,6 +75401,18 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75315
75401
  }
75316
75402
  });
75317
75403
  }
75404
+ /** Dispatch an incoming webhook trigger to any matching actions on this layout. */
75405
+ }, {
75406
+ key: "handleWebhookTrigger",
75407
+ value: function handleWebhookTrigger(triggerCode, widgetId) {
75408
+ var _this3 = this;
75409
+ this.$actionController.querySelectorAll('.action[triggertype="webhook"]').forEach(function ($el) {
75410
+ var ds = $el.dataset;
75411
+ if (ds.triggercode !== triggerCode) return;
75412
+ if (widgetId && ds.sourceid !== widgetId) return;
75413
+ _this3.runAction(ds, _this3.options);
75414
+ });
75415
+ }
75318
75416
  }, {
75319
75417
  key: "initKeyboardActions",
75320
75418
  value: function initKeyboardActions() {
@@ -76364,6 +76462,13 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76364
76462
  return _ref4.apply(this, arguments);
76365
76463
  };
76366
76464
  }());
76465
+ xlrObject.on('navLayout', function (layoutCode) {
76466
+ // Non-CMS platforms handle navLayout in their renderer via playInterruptLayout.
76467
+ // CMS navLayout is handled by ActionController (opens layout in a new tab).
76468
+ console.debug('[navLayout] XLR::on("navLayout") - received', {
76469
+ layoutCode: layoutCode
76470
+ });
76471
+ });
76367
76472
  xlrObject.emitSync = /*#__PURE__*/function () {
76368
76473
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(eventName) {
76369
76474
  var _xlrObject$emitter$ev;
@@ -76543,35 +76648,28 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76543
76648
  }));
76544
76649
  xlrObject.updateScheduleLayouts = /*#__PURE__*/function () {
76545
76650
  var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(scheduleLayouts) {
76546
- var inputLayoutIds, _iterator, _step, _step$value, layoutIndex, _layout, uniqueLayout, _i, _Object$keys, layoutId;
76651
+ var next;
76547
76652
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
76548
76653
  while (1) switch (_context9.prev = _context9.next) {
76549
76654
  case 0:
76550
- console.debug('XLR::updateScheduleLayouts > Updating schedule layouts . . .');
76551
- inputLayoutIds = [];
76552
- _iterator = _createForOfIteratorHelper(scheduleLayouts.entries());
76553
- try {
76554
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
76555
- _step$value = _slicedToArray(_step.value, 2), layoutIndex = _step$value[0], _layout = _step$value[1];
76556
- uniqueLayout = _layout;
76557
- uniqueLayout.index = layoutIndex;
76558
- uniqueLayout.id = _layout.layoutId;
76559
- this.uniqueLayouts[_layout.layoutId] = uniqueLayout;
76560
- inputLayoutIds.push(_layout.layoutId);
76561
- }
76562
- // Cross-check if we need to remove non-existing layouts based on inputLayouts
76563
- } catch (err) {
76564
- _iterator.e(err);
76565
- } finally {
76566
- _iterator.f();
76567
- }
76568
- for (_i = 0, _Object$keys = Object.keys(this.uniqueLayouts); _i < _Object$keys.length; _i++) {
76569
- layoutId = _Object$keys[_i];
76570
- if (!inputLayoutIds.includes(parseInt(layoutId))) {
76571
- delete this.uniqueLayouts[layoutId];
76572
- }
76655
+ console.debug('XLR::updateScheduleLayouts > Updating schedule layouts . . .', scheduleLayouts);
76656
+ next = new Map();
76657
+ if (!(scheduleLayouts.length === 0)) {
76658
+ _context9.next = 5;
76659
+ break;
76573
76660
  }
76661
+ this.uniqueLayouts = next;
76662
+ return _context9.abrupt("return");
76574
76663
  case 5:
76664
+ scheduleLayouts.forEach(function (_layout, layoutIndex) {
76665
+ next.set(String(_layout.layoutId), _objectSpread2(_objectSpread2({}, _layout), {}, {
76666
+ index: layoutIndex,
76667
+ id: _layout.layoutId
76668
+ }));
76669
+ });
76670
+ console.debug('XLR::updateScheduleLayouts > next unique layouts', Array.from(next).values());
76671
+ this.uniqueLayouts = next;
76672
+ case 8:
76575
76673
  case "end":
76576
76674
  return _context9.stop();
76577
76675
  }
@@ -76620,6 +76718,36 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76620
76718
  case 0:
76621
76719
  console.debug('>>>> XLR.debug XLR::updateLoop > Updating schedule loop . . .');
76622
76720
  this.inputLayouts = inputLayouts;
76721
+ // Guard against a splash-only update: uniqueLayouts has no entry for layoutId 0,
76722
+ // so parseLayouts() would return undefined current/next and prepareLayoutXlf()
76723
+ // would be called with undefined. Clean up any playing layouts and show splash directly.
76724
+ if (!(inputLayouts.length === 1 && inputLayouts[0].layoutId === 0)) {
76725
+ _context11.next = 14;
76726
+ break;
76727
+ }
76728
+ if (!(this.currentLayout && this.isLayoutInDOM(this.currentLayout.containerName, this.currentLayout.index))) {
76729
+ _context11.next = 8;
76730
+ break;
76731
+ }
76732
+ // Force all regions to complete immediately
76733
+ this.currentLayout.inLoop = false;
76734
+ _context11.next = 7;
76735
+ return this.currentLayout.finishAllRegions();
76736
+ case 7:
76737
+ this.currentLayout.removeLayout();
76738
+ case 8:
76739
+ if (this.nextLayout) {
76740
+ // Discard regardless of DOM presence: nextLayout may be preloaded with
76741
+ // DOM elements and video.js players but not yet attached to the screen container.
76742
+ this.nextLayout.discardLayout(exports.LayoutPlaybackType.NEXT);
76743
+ }
76744
+ this.currentLayout = undefined;
76745
+ this.nextLayout = undefined;
76746
+ _context11.next = 13;
76747
+ return this.playSchedules(this);
76748
+ case 13:
76749
+ return _context11.abrupt("return");
76750
+ case 14:
76623
76751
  playback = this.parseLayouts(true);
76624
76752
  isCurrentLayoutValid = isLayoutValid(this.inputLayouts, (_this$currentLayout = this.currentLayout) === null || _this$currentLayout === void 0 ? void 0 : _this$currentLayout.layoutId);
76625
76753
  if (this.isSspEnabled && this.currentLayoutId === -1) {
@@ -76628,7 +76756,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76628
76756
  if (!isCurrentLayoutValid && this.currentLayout) {
76629
76757
  this.currentLayout.emitter.emit('cancelled', this.currentLayout);
76630
76758
  }
76631
- console.debug('>>>>> XLR.debug XLR::updateLoop > uniqueLayouts', this.uniqueLayouts);
76759
+ console.debug('>>>>> XLR.debug XLR::updateLoop > uniqueLayouts', Array.from(this.uniqueLayouts.values()));
76632
76760
  console.debug('>>>>> XLR.debug XLR::updateLoop > inputLayouts', this.inputLayouts);
76633
76761
  console.debug('>>>>> XLR.debug XLR::updateLoop > isCurrentLayoutValid', isCurrentLayoutValid);
76634
76762
  console.debug('>>>>> XLR.debug XLR::updateLoop > currentLayout', this.currentLayout);
@@ -76656,86 +76784,86 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76656
76784
  };
76657
76785
  }();
76658
76786
  if (isCurrentLayoutValid) {
76659
- _context11.next = 55;
76787
+ _context11.next = 67;
76660
76788
  break;
76661
76789
  }
76662
76790
  if (!playback.hasDefaultOnly) {
76663
- _context11.next = 34;
76791
+ _context11.next = 46;
76664
76792
  break;
76665
76793
  }
76666
76794
  if (!(this.currentLayout && playback.currentLayout && this.currentLayout.layoutId !== playback.currentLayout.layoutId)) {
76667
- _context11.next = 20;
76795
+ _context11.next = 32;
76668
76796
  break;
76669
76797
  }
76670
76798
  this.currentLayout.inLoop = false;
76671
- _context11.next = 19;
76799
+ _context11.next = 31;
76672
76800
  return this.currentLayout.finishAllRegions();
76673
- case 19:
76801
+ case 31:
76674
76802
  this.currentLayout.removeLayout();
76675
- case 20:
76803
+ case 32:
76676
76804
  // Discard old nextLayout before replacing it — same as the
76677
76805
  // other two branches do, otherwise the prepared DOM element
76678
76806
  // and any video.js players are orphaned.
76679
76807
  if (this.nextLayout && this.isLayoutInDOM(this.nextLayout.containerName, this.nextLayout.index)) {
76680
76808
  this.nextLayout.discardLayout(exports.LayoutPlaybackType.NEXT);
76681
76809
  }
76682
- _context11.next = 23;
76810
+ _context11.next = 35;
76683
76811
  return this.prepareLayoutXlf(playback.currentLayout);
76684
- case 23:
76812
+ case 35:
76685
76813
  this.currentLayout = _context11.sent;
76686
76814
  this.currentLayoutId = this.currentLayout.layoutId;
76687
76815
  _context11.t0 = this;
76688
- _context11.next = 28;
76816
+ _context11.next = 40;
76689
76817
  return this.prepareLayoutXlf(playback.nextLayout);
76690
- case 28:
76818
+ case 40:
76691
76819
  _context11.t1 = _context11.sent;
76692
- _context11.next = 31;
76820
+ _context11.next = 43;
76693
76821
  return _context11.t0.prepareForSsp.call(_context11.t0, _context11.t1);
76694
- case 31:
76822
+ case 43:
76695
76823
  this.nextLayout = _context11.sent;
76696
- _context11.next = 51;
76824
+ _context11.next = 63;
76697
76825
  break;
76698
- case 34:
76826
+ case 46:
76699
76827
  if (!(this.currentLayout && this.isLayoutInDOM(this.currentLayout.containerName, this.currentLayout.index))) {
76700
- _context11.next = 39;
76828
+ _context11.next = 51;
76701
76829
  break;
76702
76830
  }
76703
76831
  this.currentLayout.inLoop = false;
76704
- _context11.next = 38;
76832
+ _context11.next = 50;
76705
76833
  return this.currentLayout.finishAllRegions();
76706
- case 38:
76834
+ case 50:
76707
76835
  this.currentLayout.removeLayout();
76708
- case 39:
76836
+ case 51:
76709
76837
  if (this.nextLayout && this.isLayoutInDOM(this.nextLayout.containerName, this.nextLayout.index)) {
76710
76838
  this.nextLayout.discardLayout(exports.LayoutPlaybackType.NEXT);
76711
76839
  }
76712
76840
  if (!playback.currentLayout) {
76713
- _context11.next = 43;
76841
+ _context11.next = 55;
76714
76842
  break;
76715
76843
  }
76716
- _context11.next = 43;
76844
+ _context11.next = 55;
76717
76845
  return prepareNewCurrentLayout();
76718
- case 43:
76846
+ case 55:
76719
76847
  if (!playback.nextLayout) {
76720
- _context11.next = 51;
76848
+ _context11.next = 63;
76721
76849
  break;
76722
76850
  }
76723
76851
  _context11.t2 = this;
76724
- _context11.next = 47;
76852
+ _context11.next = 59;
76725
76853
  return this.prepareLayoutXlf(playback.nextLayout);
76726
- case 47:
76854
+ case 59:
76727
76855
  _context11.t3 = _context11.sent;
76728
- _context11.next = 50;
76856
+ _context11.next = 62;
76729
76857
  return _context11.t2.prepareForSsp.call(_context11.t2, _context11.t3);
76730
- case 50:
76858
+ case 62:
76731
76859
  this.nextLayout = _context11.sent;
76732
- case 51:
76733
- _context11.next = 53;
76860
+ case 63:
76861
+ _context11.next = 65;
76734
76862
  return this.playSchedules(this);
76735
- case 53:
76736
- _context11.next = 67;
76863
+ case 65:
76864
+ _context11.next = 79;
76737
76865
  break;
76738
- case 55:
76866
+ case 67:
76739
76867
  // Remove next layout if it is in the DOM
76740
76868
  if (this.nextLayout && this.isLayoutInDOM(this.nextLayout.containerName, this.nextLayout.index)) {
76741
76869
  this.nextLayout.discardLayout(exports.LayoutPlaybackType.NEXT);
@@ -76762,22 +76890,22 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76762
76890
  // nextLayout keeps the cycle in order; the slot after that will be
76763
76891
  // prepared by the normal prepareLayouts() call at transition time.
76764
76892
  if (!playback.currentLayout) {
76765
- _context11.next = 66;
76893
+ _context11.next = 78;
76766
76894
  break;
76767
76895
  }
76768
76896
  this.currentLayoutIndex = playback.currentLayoutIndex;
76769
76897
  _context11.t4 = this;
76770
- _context11.next = 62;
76898
+ _context11.next = 74;
76771
76899
  return this.prepareLayoutXlf(playback.currentLayout);
76772
- case 62:
76900
+ case 74:
76773
76901
  _context11.t5 = _context11.sent;
76774
- _context11.next = 65;
76902
+ _context11.next = 77;
76775
76903
  return _context11.t4.prepareForSsp.call(_context11.t4, _context11.t5);
76776
- case 65:
76904
+ case 77:
76777
76905
  this.nextLayout = _context11.sent;
76778
- case 66:
76906
+ case 78:
76779
76907
  console.debug('>>>> XLR.debug XLR::updateLoop > updated nextLayout', this.nextLayout);
76780
- case 67:
76908
+ case 79:
76781
76909
  case "end":
76782
76910
  return _context11.stop();
76783
76911
  }
@@ -76807,7 +76935,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76807
76935
  };
76808
76936
  }();
76809
76937
  xlrObject.parseLayouts = function (hasChanged) {
76810
- var _this$currentLayout2, _this$currentLayout3;
76938
+ var _this$currentLayout2, _this$currentLayout3, _this$currentLayout4, _this$nextLayout, _currentLayout2, _nextLayout2;
76811
76939
  var _currentLayout;
76812
76940
  var _nextLayout;
76813
76941
  var _hasDefaultOnly = hasDefaultOnly(this.inputLayouts);
@@ -76820,17 +76948,28 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76820
76948
  if (this.isSspEnabled && ((_this$currentLayout3 = this.currentLayout) === null || _this$currentLayout3 === void 0 ? void 0 : _this$currentLayout3.layoutId) === -1) {
76821
76949
  isCurrentLayoutValid = true;
76822
76950
  }
76951
+ console.debug('XLR::parseLayouts', {
76952
+ currentLayoutId: (_this$currentLayout4 = this.currentLayout) === null || _this$currentLayout4 === void 0 ? void 0 : _this$currentLayout4.layoutId,
76953
+ currentLayoutIndex: this.currentLayoutIndex,
76954
+ nextLayoutId: (_this$nextLayout = this.nextLayout) === null || _this$nextLayout === void 0 ? void 0 : _this$nextLayout.layoutId,
76955
+ isCurrentLayoutValid: isCurrentLayoutValid,
76956
+ hasChanged: !!hasChanged,
76957
+ inputLayoutsCount: this.inputLayouts.length,
76958
+ inputLayoutIds: this.inputLayouts.map(function (l) {
76959
+ return l.layoutId;
76960
+ }).join(', ')
76961
+ });
76823
76962
  _currentLayout = this.currentLayout;
76824
76963
  if (this.currentLayout && this.nextLayout) {
76825
76964
  // Both currentLayout and nextLayout has values
76826
76965
  if (hasLayout) {
76827
76966
  if (!isCurrentLayoutValid) {
76828
- var _this$nextLayout;
76967
+ var _this$nextLayout2;
76829
76968
  // Check if currentLayout.state is PLAYED,
76830
76969
  // then, validate nextLayout and if valid,
76831
76970
  // proceed to nextLayout as new currentLayout
76832
76971
  // Else, go back to first layout in the loop
76833
- if (this.currentLayout.state === exports.ELayoutState.PLAYED && isLayoutValid(this.inputLayouts, (_this$nextLayout = this.nextLayout) === null || _this$nextLayout === void 0 ? void 0 : _this$nextLayout.layoutId)) {
76972
+ if (this.currentLayout.state === exports.ELayoutState.PLAYED && isLayoutValid(this.inputLayouts, (_this$nextLayout2 = this.nextLayout) === null || _this$nextLayout2 === void 0 ? void 0 : _this$nextLayout2.layoutId)) {
76834
76973
  // Get nextLayout from updated loop
76835
76974
  var tempNextLayoutIndex = getLayoutIndexByLayoutId(this.inputLayouts, this.nextLayout.layoutId);
76836
76975
  _currentLayoutIndex = tempNextLayoutIndex !== null && tempNextLayoutIndex !== void 0 ? tempNextLayoutIndex : 0;
@@ -76874,7 +77013,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76874
77013
  _nextLayout = setLayoutIndex(_nextLayout, _nextLayoutIndex);
76875
77014
  }
76876
77015
  } else {
76877
- var _this$currentLayout4, _this$currentLayout5;
77016
+ var _this$currentLayout5, _this$currentLayout6;
76878
77017
  _currentLayout = this.nextLayout;
76879
77018
  _currentLayoutIndex = _currentLayout.index;
76880
77019
  // updateLoop can re-queue the same index that is currently
@@ -76884,7 +77023,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76884
77023
  // whether the queued next-to-current is at the same index as the
76885
77024
  // layout that just finished, and advance past it so the following
76886
77025
  // slot (e.g. an SSP that now has an ad) becomes current instead.
76887
- if (this.inputLayouts.length > 1 && (_this$currentLayout4 = this.currentLayout) !== null && _this$currentLayout4 !== void 0 && _this$currentLayout4.done && _currentLayoutIndex === ((_this$currentLayout5 = this.currentLayout) === null || _this$currentLayout5 === void 0 ? void 0 : _this$currentLayout5.index)) {
77026
+ if (this.inputLayouts.length > 1 && (_this$currentLayout5 = this.currentLayout) !== null && _this$currentLayout5 !== void 0 && _this$currentLayout5.done && _currentLayoutIndex === ((_this$currentLayout6 = this.currentLayout) === null || _this$currentLayout6 === void 0 ? void 0 : _this$currentLayout6.index)) {
76888
77027
  _currentLayoutIndex = (_currentLayoutIndex + 1) % this.inputLayouts.length;
76889
77028
  _currentLayout = this.getLayout(this.inputLayouts[_currentLayoutIndex]);
76890
77029
  _currentLayout = setLayoutIndex(_currentLayout, _currentLayoutIndex);
@@ -76921,6 +77060,12 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76921
77060
  _currentLayout.xlr = this;
76922
77061
  _nextLayout.xlr = this;
76923
77062
  }
77063
+ console.debug('XLR::parseLayouts result', {
77064
+ currentLayoutId: (_currentLayout2 = _currentLayout) === null || _currentLayout2 === void 0 ? void 0 : _currentLayout2.layoutId,
77065
+ currentLayoutIndex: _currentLayoutIndex,
77066
+ nextLayoutId: (_nextLayout2 = _nextLayout) === null || _nextLayout2 === void 0 ? void 0 : _nextLayout2.layoutId,
77067
+ nextLayoutIndex: _nextLayoutIndex
77068
+ });
76924
77069
  return {
76925
77070
  currentLayout: _currentLayout,
76926
77071
  nextLayout: _nextLayout,
@@ -76932,7 +77077,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76932
77077
  };
76933
77078
  xlrObject.getLayout = function (inputLayout) {
76934
77079
  var isCMS = this.config.platform === exports.ConsumerPlatform.CMS;
76935
- if (!isCMS && Object.keys(this.uniqueLayouts).length === 0) {
77080
+ if (!isCMS && this.uniqueLayouts.size === 0) {
76936
77081
  return;
76937
77082
  }
76938
77083
  var _layout = {};
@@ -76949,7 +77094,13 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76949
77094
  activeLayout.id = activeLayout.layoutId;
76950
77095
  }
76951
77096
  } else {
76952
- activeLayout = _objectSpread2({}, this.uniqueLayouts[inputLayout.layoutId]);
77097
+ var layoutFromUniqueLayouts = this.uniqueLayouts.get(String(inputLayout.layoutId));
77098
+ console.debug('XLR::getLayout > layoutFromUniqueLayouts', {
77099
+ layoutFromUniqueLayouts: layoutFromUniqueLayouts,
77100
+ inputLayout: inputLayout,
77101
+ uniqueLayouts: this.uniqueLayouts
77102
+ });
77103
+ activeLayout = layoutFromUniqueLayouts ? _objectSpread2({}, layoutFromUniqueLayouts) : _objectSpread2({}, inputLayout);
76953
77104
  }
76954
77105
  _layout = _objectSpread2(_objectSpread2({}, _layout), activeLayout);
76955
77106
  console.debug('XLR::getLayout > activeLayout from uniqueLayouts', {
@@ -76966,10 +77117,10 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76966
77117
  return iLayout;
76967
77118
  };
76968
77119
  xlrObject.getLayoutById = function (layoutId, layoutIndex) {
76969
- if (!layoutId || Object.keys(this.uniqueLayouts).length === 0) {
77120
+ if (!layoutId || this.uniqueLayouts.size === 0 || !this.uniqueLayouts.has(String(layoutId))) {
76970
77121
  return undefined;
76971
77122
  }
76972
- var _layout = _objectSpread2(_objectSpread2({}, initialLayout), this.uniqueLayouts[layoutId]);
77123
+ var _layout = _objectSpread2(_objectSpread2({}, initialLayout), this.uniqueLayouts.get(String(layoutId)));
76973
77124
  // Set layout index if available
76974
77125
  if (layoutIndex) {
76975
77126
  _layout.index = layoutIndex;
@@ -76977,71 +77128,79 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76977
77128
  return _layout;
76978
77129
  };
76979
77130
  xlrObject.prepareLayouts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
76980
- var _layoutPlayback$curre, _layoutPlayback$curre2;
77131
+ var _layoutPlayback$curre, _layoutPlayback$nextL, _layoutPlayback$curre2, _layoutPlayback$curre3, _layouts$, _layouts$2, _layouts$3, _layouts$4;
76981
77132
  var self, layoutPlayback, currentLayoutXlf, wasCurrentReused, nextLayoutXlf, layouts;
76982
77133
  return _regeneratorRuntime().wrap(function _callee14$(_context14) {
76983
77134
  while (1) switch (_context14.prev = _context14.next) {
76984
77135
  case 0:
76985
77136
  self = xlrObject;
76986
77137
  if (!this.isUpdatingLoop) {
76987
- _context14.next = 3;
77138
+ _context14.next = 4;
76988
77139
  break;
76989
77140
  }
77141
+ console.debug('XLR::prepareLayouts - skipped (isUpdatingLoop)');
76990
77142
  return _context14.abrupt("return", Promise.resolve(self));
76991
- case 3:
77143
+ case 4:
76992
77144
  layoutPlayback = self.parseLayouts(); // Don't prepare layout if it's just the splash screen
76993
77145
  if (!(self.inputLayouts.length === 1 && self.inputLayouts[0].layoutId === 0)) {
76994
- _context14.next = 6;
77146
+ _context14.next = 8;
76995
77147
  break;
76996
77148
  }
77149
+ console.debug('XLR::prepareLayouts - skipped (splash screen only)');
76997
77150
  return _context14.abrupt("return", Promise.resolve(self));
76998
- case 6:
76999
- console.debug('??? XLR.debug prepareLayouts::playback', {
77000
- layoutPlayback: layoutPlayback,
77001
- shouldParse: false
77151
+ case 8:
77152
+ console.debug('XLR::prepareLayouts', {
77153
+ currentLayoutId: (_layoutPlayback$curre = layoutPlayback.currentLayout) === null || _layoutPlayback$curre === void 0 ? void 0 : _layoutPlayback$curre.layoutId,
77154
+ currentLayoutIndex: layoutPlayback.currentLayoutIndex,
77155
+ nextLayoutId: (_layoutPlayback$nextL = layoutPlayback.nextLayout) === null || _layoutPlayback$nextL === void 0 ? void 0 : _layoutPlayback$nextL.layoutId,
77156
+ nextLayoutIndex: layoutPlayback.nextLayoutIndex
77002
77157
  });
77003
- self.currentLayoutId = (_layoutPlayback$curre = layoutPlayback.currentLayout) === null || _layoutPlayback$curre === void 0 ? void 0 : _layoutPlayback$curre.layoutId;
77158
+ self.currentLayoutId = (_layoutPlayback$curre2 = layoutPlayback.currentLayout) === null || _layoutPlayback$curre2 === void 0 ? void 0 : _layoutPlayback$curre2.layoutId;
77004
77159
  // Only reuse the existing Layout instance if it is fully healthy —
77005
77160
  // a done=true instance was removed from the DOM (e.g. an SSP slot that
77006
77161
  // had no ad), and an empty-XLF instance has no regions so it can never
77007
77162
  // advance the cycle. In either case re-prepare from scratch so we get
77008
77163
  // a fresh request (which may now have a valid ad / XLF).
77009
- if (!((_layoutPlayback$curre2 = layoutPlayback.currentLayout) !== null && _layoutPlayback$curre2 !== void 0 && _layoutPlayback$curre2.layoutNode && !layoutPlayback.currentLayout.done && layoutPlayback.currentLayout.xlfString !== '')) {
77010
- _context14.next = 12;
77164
+ if (!((_layoutPlayback$curre3 = layoutPlayback.currentLayout) !== null && _layoutPlayback$curre3 !== void 0 && _layoutPlayback$curre3.layoutNode && !layoutPlayback.currentLayout.done && layoutPlayback.currentLayout.xlfString !== '')) {
77165
+ _context14.next = 14;
77011
77166
  break;
77012
77167
  }
77013
77168
  _context14.t0 = layoutPlayback.currentLayout;
77014
- _context14.next = 15;
77169
+ _context14.next = 17;
77015
77170
  break;
77016
- case 12:
77017
- _context14.next = 14;
77018
- return self.prepareLayoutXlf(layoutPlayback.currentLayout);
77019
77171
  case 14:
77172
+ _context14.next = 16;
77173
+ return self.prepareLayoutXlf(layoutPlayback.currentLayout);
77174
+ case 16:
77020
77175
  _context14.t0 = _context14.sent;
77021
- case 15:
77176
+ case 17:
77022
77177
  currentLayoutXlf = _context14.t0;
77023
77178
  // True when the same object was returned (reused); false when a fresh
77024
77179
  // Layout was constructed by prepareLayoutXlf above.
77025
77180
  wasCurrentReused = currentLayoutXlf === layoutPlayback.currentLayout;
77026
- _context14.next = 19;
77181
+ _context14.next = 21;
77027
77182
  return self.prepareLayoutXlf(layoutPlayback.nextLayout);
77028
- case 19:
77183
+ case 21:
77029
77184
  nextLayoutXlf = _context14.sent;
77030
77185
  _context14.t1 = Promise;
77031
77186
  _context14.t2 = currentLayoutXlf;
77032
- _context14.next = 24;
77187
+ _context14.next = 26;
77033
77188
  return self.prepareForSsp(nextLayoutXlf);
77034
- case 24:
77189
+ case 26:
77035
77190
  _context14.t3 = _context14.sent;
77036
77191
  _context14.t4 = [_context14.t2, _context14.t3];
77037
- _context14.next = 28;
77192
+ _context14.next = 30;
77038
77193
  return _context14.t1.all.call(_context14.t1, _context14.t4);
77039
- case 28:
77194
+ case 30:
77040
77195
  layouts = _context14.sent;
77041
77196
  if (!(self.isUpdatingLoop || layouts[0].done)) {
77042
- _context14.next = 33;
77197
+ _context14.next = 36;
77043
77198
  break;
77044
77199
  }
77200
+ console.debug('XLR::prepareLayouts - aborted (concurrent updateLoop)', {
77201
+ isUpdatingLoop: self.isUpdatingLoop,
77202
+ currentLayoutDone: layouts[0].done
77203
+ });
77045
77204
  // If currentLayout was freshly prepared (not reused from nextLayout),
77046
77205
  // its DOM element was just appended — discard it now so it does not
77047
77206
  // accumulate in screen_container. Also disposes any video.js players
@@ -77053,8 +77212,14 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
77053
77212
  nextLayoutXlf.discardLayout(exports.LayoutPlaybackType.NEXT);
77054
77213
  }
77055
77214
  return _context14.abrupt("return", Promise.resolve(self));
77056
- case 33:
77057
- console.debug('>>>>> XLR.debug prepared layout XLF', layouts);
77215
+ case 36:
77216
+ console.debug('XLR::prepareLayouts - layouts prepared', {
77217
+ currentLayoutId: (_layouts$ = layouts[0]) === null || _layouts$ === void 0 ? void 0 : _layouts$.layoutId,
77218
+ currentLayoutIndex: (_layouts$2 = layouts[0]) === null || _layouts$2 === void 0 ? void 0 : _layouts$2.index,
77219
+ nextLayoutId: (_layouts$3 = layouts[1]) === null || _layouts$3 === void 0 ? void 0 : _layouts$3.layoutId,
77220
+ nextLayoutIndex: (_layouts$4 = layouts[1]) === null || _layouts$4 === void 0 ? void 0 : _layouts$4.index,
77221
+ currentReused: wasCurrentReused
77222
+ });
77058
77223
  return _context14.abrupt("return", new Promise( /*#__PURE__*/function () {
77059
77224
  var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(resolve) {
77060
77225
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
@@ -77088,7 +77253,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
77088
77253
  return _ref14.apply(this, arguments);
77089
77254
  };
77090
77255
  }()));
77091
- case 35:
77256
+ case 38:
77092
77257
  case "end":
77093
77258
  return _context14.stop();
77094
77259
  }
@@ -77251,33 +77416,48 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
77251
77416
  return _ref16.apply(this, arguments);
77252
77417
  };
77253
77418
  }();
77419
+ // Shared re-entry guard for all layout navigation methods.
77420
+ // Prevents a double-tap from advancing two layouts at once.
77421
+ var isNavigatingLayout = false;
77254
77422
  xlrObject.gotoPrevLayout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
77255
77423
  var _this4 = this;
77256
- var _currentLayoutIndex, _assumedPrevIndex, _this$currentLayout6;
77424
+ var _currentLayoutIndex, _assumedPrevIndex, _this$currentLayout7;
77257
77425
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
77258
77426
  while (1) switch (_context18.prev = _context18.next) {
77259
77427
  case 0:
77428
+ if (!isNavigatingLayout) {
77429
+ _context18.next = 2;
77430
+ break;
77431
+ }
77432
+ return _context18.abrupt("return");
77433
+ case 2:
77434
+ isNavigatingLayout = true;
77435
+ _context18.prev = 3;
77260
77436
  _currentLayoutIndex = this.currentLayoutIndex;
77261
77437
  _assumedPrevIndex = _currentLayoutIndex - 1; // If previous layout is same as current layout or
77262
77438
  // if there's only one layout, do nothing
77263
77439
  if (!(_assumedPrevIndex < 0)) {
77264
- _context18.next = 4;
77440
+ _context18.next = 8;
77265
77441
  break;
77266
77442
  }
77267
77443
  return _context18.abrupt("return");
77268
- case 4:
77444
+ case 8:
77269
77445
  console.debug('XLR::gotoPrevLayout', {
77270
- previousLayoutIndex: _assumedPrevIndex,
77271
- method: 'XLR::gotoPrevLayout',
77272
- shouldParse: false
77446
+ previousLayoutIndex: _assumedPrevIndex
77273
77447
  });
77274
77448
  if (!Boolean(this.inputLayouts[_assumedPrevIndex])) {
77275
- _context18.next = 10;
77449
+ _context18.next = 15;
77276
77450
  break;
77277
77451
  }
77278
- _context18.next = 8;
77279
- return (_this$currentLayout6 = this.currentLayout) === null || _this$currentLayout6 === void 0 ? void 0 : _this$currentLayout6.finishAllRegions();
77280
- case 8:
77452
+ // Prevent the natural layout-end handler from also calling
77453
+ // prepareLayouts() when finishAllRegions() causes the layout
77454
+ // 'end' event to fire.
77455
+ if (this.currentLayout) {
77456
+ this.currentLayout.inLoop = false;
77457
+ }
77458
+ _context18.next = 13;
77459
+ return (_this$currentLayout7 = this.currentLayout) === null || _this$currentLayout7 === void 0 ? void 0 : _this$currentLayout7.finishAllRegions();
77460
+ case 13:
77281
77461
  // and set the previous layout as current layout
77282
77462
  this.currentLayoutIndex = _assumedPrevIndex;
77283
77463
  this.prepareLayouts().then( /*#__PURE__*/function () {
@@ -77297,30 +77477,366 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
77297
77477
  return _ref18.apply(this, arguments);
77298
77478
  };
77299
77479
  }());
77300
- case 10:
77480
+ case 15:
77481
+ _context18.prev = 15;
77482
+ isNavigatingLayout = false;
77483
+ return _context18.finish(15);
77484
+ case 18:
77301
77485
  case "end":
77302
77486
  return _context18.stop();
77303
77487
  }
77304
- }, _callee18, this);
77488
+ }, _callee18, this, [[3,, 15, 18]]);
77305
77489
  }));
77306
- xlrObject.gotoNextLayout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
77307
- var _xlrObject$currentLay2;
77308
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
77309
- while (1) switch (_context19.prev = _context19.next) {
77490
+ xlrObject.gotoNextLayout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
77491
+ var _this5 = this;
77492
+ var _this$currentLayout8, nextIndex;
77493
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
77494
+ while (1) switch (_context20.prev = _context20.next) {
77310
77495
  case 0:
77496
+ if (!isNavigatingLayout) {
77497
+ _context20.next = 2;
77498
+ break;
77499
+ }
77500
+ return _context20.abrupt("return");
77501
+ case 2:
77502
+ isNavigatingLayout = true;
77503
+ _context20.prev = 3;
77504
+ nextIndex = this.currentLayoutIndex + 1;
77505
+ if (Boolean(this.inputLayouts[nextIndex])) {
77506
+ _context20.next = 7;
77507
+ break;
77508
+ }
77509
+ return _context20.abrupt("return");
77510
+ case 7:
77311
77511
  console.debug('XLR::gotoNextLayout', {
77312
- nextLayoutIndex: this.currentLayoutIndex + 1,
77313
- method: 'XLR::gotoNextLayout',
77314
- shouldParse: false
77512
+ nextLayoutIndex: nextIndex
77315
77513
  });
77316
- _context19.next = 3;
77317
- return (_xlrObject$currentLay2 = xlrObject.currentLayout) === null || _xlrObject$currentLay2 === void 0 ? void 0 : _xlrObject$currentLay2.finishAllRegions();
77318
- case 3:
77514
+ if (this.currentLayout) {
77515
+ this.currentLayout.inLoop = false;
77516
+ }
77517
+ _context20.next = 11;
77518
+ return (_this$currentLayout8 = this.currentLayout) === null || _this$currentLayout8 === void 0 ? void 0 : _this$currentLayout8.finishAllRegions();
77519
+ case 11:
77520
+ this.currentLayoutIndex = nextIndex;
77521
+ this.prepareLayouts().then( /*#__PURE__*/function () {
77522
+ var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(xlr) {
77523
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
77524
+ while (1) switch (_context19.prev = _context19.next) {
77525
+ case 0:
77526
+ _context19.next = 2;
77527
+ return _this5.playSchedules(xlr);
77528
+ case 2:
77529
+ case "end":
77530
+ return _context19.stop();
77531
+ }
77532
+ }, _callee19);
77533
+ }));
77534
+ return function (_x14) {
77535
+ return _ref20.apply(this, arguments);
77536
+ };
77537
+ }());
77538
+ case 13:
77539
+ _context20.prev = 13;
77540
+ isNavigatingLayout = false;
77541
+ return _context20.finish(13);
77542
+ case 16:
77319
77543
  case "end":
77320
- return _context19.stop();
77544
+ return _context20.stop();
77321
77545
  }
77322
- }, _callee19, this);
77546
+ }, _callee20, this, [[3,, 13, 16]]);
77323
77547
  }));
77548
+ xlrObject.gotoLayoutByCode = /*#__PURE__*/function () {
77549
+ var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(layoutCode) {
77550
+ var _this6 = this;
77551
+ var _this$currentLayout9, targetIndex, parsedLayouts, _loop, _ret, _i, _parsedLayouts, parser, i, _inputLayout$getXlf, _doc$documentElement, inputLayout, xlfString, url, res, doc, foundCode;
77552
+ return _regeneratorRuntime().wrap(function _callee22$(_context23) {
77553
+ while (1) switch (_context23.prev = _context23.next) {
77554
+ case 0:
77555
+ if (!isNavigatingLayout) {
77556
+ _context23.next = 2;
77557
+ break;
77558
+ }
77559
+ return _context23.abrupt("return");
77560
+ case 2:
77561
+ isNavigatingLayout = true;
77562
+ _context23.prev = 3;
77563
+ targetIndex = -1; // 1. Check the two already-parsed layouts first (zero fetch cost)
77564
+ parsedLayouts = [this.layouts['current'], this.layouts['next']];
77565
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
77566
+ var _layout$layoutNode;
77567
+ var layout, code;
77568
+ return _regeneratorRuntime().wrap(function _loop$(_context21) {
77569
+ while (1) switch (_context21.prev = _context21.next) {
77570
+ case 0:
77571
+ layout = _parsedLayouts[_i];
77572
+ if (layout) {
77573
+ _context21.next = 3;
77574
+ break;
77575
+ }
77576
+ return _context21.abrupt("return", 0);
77577
+ case 3:
77578
+ code = (_layout$layoutNode = layout.layoutNode) === null || _layout$layoutNode === void 0 || (_layout$layoutNode = _layout$layoutNode.documentElement) === null || _layout$layoutNode === void 0 ? void 0 : _layout$layoutNode.getAttribute('code');
77579
+ if (!(code === layoutCode)) {
77580
+ _context21.next = 7;
77581
+ break;
77582
+ }
77583
+ targetIndex = _this6.inputLayouts.findIndex(function (i) {
77584
+ return i.layoutId === layout.layoutId;
77585
+ });
77586
+ return _context21.abrupt("return", 1);
77587
+ case 7:
77588
+ case "end":
77589
+ return _context21.stop();
77590
+ }
77591
+ }, _loop);
77592
+ });
77593
+ _i = 0, _parsedLayouts = parsedLayouts;
77594
+ case 8:
77595
+ if (!(_i < _parsedLayouts.length)) {
77596
+ _context23.next = 18;
77597
+ break;
77598
+ }
77599
+ return _context23.delegateYield(_loop(), "t0", 10);
77600
+ case 10:
77601
+ _ret = _context23.t0;
77602
+ if (!(_ret === 0)) {
77603
+ _context23.next = 13;
77604
+ break;
77605
+ }
77606
+ return _context23.abrupt("continue", 15);
77607
+ case 13:
77608
+ if (!(_ret === 1)) {
77609
+ _context23.next = 15;
77610
+ break;
77611
+ }
77612
+ return _context23.abrupt("break", 18);
77613
+ case 15:
77614
+ _i++;
77615
+ _context23.next = 8;
77616
+ break;
77617
+ case 18:
77618
+ if (!(targetIndex === -1)) {
77619
+ _context23.next = 60;
77620
+ break;
77621
+ }
77622
+ parser = new DOMParser();
77623
+ i = 0;
77624
+ case 21:
77625
+ if (!(i < this.inputLayouts.length)) {
77626
+ _context23.next = 60;
77627
+ break;
77628
+ }
77629
+ inputLayout = this.inputLayouts[i]; // Fast check: code pre-populated by the player (no fetch needed)
77630
+ if (!(inputLayout.code !== undefined)) {
77631
+ _context23.next = 28;
77632
+ break;
77633
+ }
77634
+ if (!(inputLayout.code === layoutCode)) {
77635
+ _context23.next = 27;
77636
+ break;
77637
+ }
77638
+ targetIndex = i;
77639
+ return _context23.abrupt("break", 60);
77640
+ case 27:
77641
+ return _context23.abrupt("continue", 57);
77642
+ case 28:
77643
+ xlfString = void 0; // Prefer getXlf() when available (e.g. CMS platform)
77644
+ xlfString = (_inputLayout$getXlf = inputLayout.getXlf) === null || _inputLayout$getXlf === void 0 ? void 0 : _inputLayout$getXlf.call(inputLayout);
77645
+ // Otherwise fetch from the local file server (Electron / ChromeOS)
77646
+ if (!(!xlfString && this.config.appHost && inputLayout.path)) {
77647
+ _context23.next = 49;
77648
+ break;
77649
+ }
77650
+ url = this.config.appHost + inputLayout.path;
77651
+ console.debug('[gotoLayoutByCode] Fetching XLF for layoutId', inputLayout.layoutId, url);
77652
+ _context23.prev = 33;
77653
+ _context23.next = 36;
77654
+ return fetch(url);
77655
+ case 36:
77656
+ res = _context23.sent;
77657
+ if (res.ok) {
77658
+ _context23.next = 40;
77659
+ break;
77660
+ }
77661
+ console.debug('[gotoLayoutByCode] Fetch non-OK', res.status, url);
77662
+ return _context23.abrupt("continue", 57);
77663
+ case 40:
77664
+ _context23.next = 42;
77665
+ return res.text();
77666
+ case 42:
77667
+ xlfString = _context23.sent;
77668
+ _context23.next = 49;
77669
+ break;
77670
+ case 45:
77671
+ _context23.prev = 45;
77672
+ _context23.t1 = _context23["catch"](33);
77673
+ console.debug('[gotoLayoutByCode] Fetch error for', url, _context23.t1);
77674
+ return _context23.abrupt("continue", 57);
77675
+ case 49:
77676
+ if (xlfString) {
77677
+ _context23.next = 52;
77678
+ break;
77679
+ }
77680
+ console.debug('[gotoLayoutByCode] No XLF for layoutId', inputLayout.layoutId, 'path:', inputLayout.path);
77681
+ return _context23.abrupt("continue", 57);
77682
+ case 52:
77683
+ doc = parser.parseFromString(xlfString, 'text/xml');
77684
+ foundCode = (_doc$documentElement = doc.documentElement) === null || _doc$documentElement === void 0 ? void 0 : _doc$documentElement.getAttribute('code');
77685
+ if (!(foundCode === layoutCode)) {
77686
+ _context23.next = 57;
77687
+ break;
77688
+ }
77689
+ targetIndex = i;
77690
+ return _context23.abrupt("break", 60);
77691
+ case 57:
77692
+ i++;
77693
+ _context23.next = 21;
77694
+ break;
77695
+ case 60:
77696
+ if (!(targetIndex === -1)) {
77697
+ _context23.next = 63;
77698
+ break;
77699
+ }
77700
+ console.warn('XLR::gotoLayoutByCode - layout not found for code:', layoutCode);
77701
+ return _context23.abrupt("return");
77702
+ case 63:
77703
+ console.debug('XLR::gotoLayoutByCode', {
77704
+ layoutCode: layoutCode,
77705
+ targetIndex: targetIndex
77706
+ });
77707
+ // Prevent the natural layout-end handler from racing with our own
77708
+ // prepareLayouts() call (same pattern as gotoPrevLayout/gotoNextLayout).
77709
+ if (this.currentLayout) {
77710
+ this.currentLayout.inLoop = false;
77711
+ }
77712
+ _context23.next = 67;
77713
+ return (_this$currentLayout9 = this.currentLayout) === null || _this$currentLayout9 === void 0 ? void 0 : _this$currentLayout9.finishAllRegions();
77714
+ case 67:
77715
+ this.currentLayoutIndex = targetIndex;
77716
+ this.prepareLayouts().then( /*#__PURE__*/function () {
77717
+ var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(xlr) {
77718
+ return _regeneratorRuntime().wrap(function _callee21$(_context22) {
77719
+ while (1) switch (_context22.prev = _context22.next) {
77720
+ case 0:
77721
+ _context22.next = 2;
77722
+ return _this6.playSchedules(xlr);
77723
+ case 2:
77724
+ case "end":
77725
+ return _context22.stop();
77726
+ }
77727
+ }, _callee21);
77728
+ }));
77729
+ return function (_x16) {
77730
+ return _ref22.apply(this, arguments);
77731
+ };
77732
+ }());
77733
+ case 69:
77734
+ _context23.prev = 69;
77735
+ isNavigatingLayout = false;
77736
+ return _context23.finish(69);
77737
+ case 72:
77738
+ case "end":
77739
+ return _context23.stop();
77740
+ }
77741
+ }, _callee22, this, [[3,, 69, 72], [33, 45]]);
77742
+ }));
77743
+ return function (_x15) {
77744
+ return _ref21.apply(this, arguments);
77745
+ };
77746
+ }();
77747
+ xlrObject.playInterruptLayout = /*#__PURE__*/function () {
77748
+ var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(inputLayout) {
77749
+ var _this7 = this;
77750
+ var _this$currentLayout10, _this$currentLayout11, resumeIndex, savedNextLayout, interruptKey, wasInUniqueLayouts, interruptILayout, cleanup;
77751
+ return _regeneratorRuntime().wrap(function _callee23$(_context24) {
77752
+ while (1) switch (_context24.prev = _context24.next) {
77753
+ case 0:
77754
+ if (!isNavigatingLayout) {
77755
+ _context24.next = 2;
77756
+ break;
77757
+ }
77758
+ return _context24.abrupt("return");
77759
+ case 2:
77760
+ isNavigatingLayout = true;
77761
+ _context24.prev = 3;
77762
+ resumeIndex = this.currentLayoutIndex; // Save B (the layout that was queued to play after A) before stopping A.
77763
+ // After the interrupt ends, parseLayouts() will use this to resume the loop.
77764
+ savedNextLayout = this.nextLayout;
77765
+ console.debug('[navLayout] XLR::playInterruptLayout - Starting interrupt', {
77766
+ interruptLayoutId: inputLayout.layoutId,
77767
+ resumeIndex: resumeIndex,
77768
+ currentLayoutId: (_this$currentLayout10 = this.currentLayout) === null || _this$currentLayout10 === void 0 ? void 0 : _this$currentLayout10.layoutId,
77769
+ resumeNextLayoutId: savedNextLayout === null || savedNextLayout === void 0 ? void 0 : savedNextLayout.layoutId
77770
+ });
77771
+ // Prevent A's end handler from calling prepareLayouts (we take over).
77772
+ if (this.currentLayout) {
77773
+ this.currentLayout.inLoop = false;
77774
+ }
77775
+ _context24.next = 10;
77776
+ return (_this$currentLayout11 = this.currentLayout) === null || _this$currentLayout11 === void 0 ? void 0 : _this$currentLayout11.finishAllRegions();
77777
+ case 10:
77778
+ // Register interrupt in uniqueLayouts so getLayout()/prepareLayoutXlf() resolve it.
77779
+ // Do NOT splice into inputLayouts — keeping the original loop intact means
77780
+ // parseLayouts() will see the interrupt as "not in loop" (isCurrentLayoutValid=false)
77781
+ // after it ends, and will correctly advance to savedNextLayout (B).
77782
+ interruptKey = String(inputLayout.layoutId);
77783
+ wasInUniqueLayouts = this.uniqueLayouts.has(interruptKey);
77784
+ if (!wasInUniqueLayouts) {
77785
+ this.uniqueLayouts.set(interruptKey, _objectSpread2(_objectSpread2({}, inputLayout), {}, {
77786
+ index: resumeIndex,
77787
+ id: inputLayout.layoutId
77788
+ }));
77789
+ }
77790
+ // Prepare the interrupt ILayout (fetches XLF, builds regions).
77791
+ _context24.next = 15;
77792
+ return this.prepareLayoutXlf(this.getLayout(inputLayout));
77793
+ case 15:
77794
+ interruptILayout = _context24.sent;
77795
+ // Wire into XLR so playLayouts picks up the interrupt as current.
77796
+ // inLoop=true lets the interrupt's own end handler call prepareLayouts normally.
77797
+ interruptILayout.inLoop = true;
77798
+ this.layouts.current = interruptILayout;
77799
+ this.currentLayout = interruptILayout;
77800
+ this.currentLayoutId = interruptILayout.layoutId;
77801
+ // Restore nextLayout to B so after the interrupt ends, parseLayouts() resumes
77802
+ // the original loop from B (since interrupt.layoutId is not in inputLayouts,
77803
+ // parseLayouts sees it as invalid and advances to nextLayout).
77804
+ if (savedNextLayout) {
77805
+ this.layouts.next = savedNextLayout;
77806
+ this.nextLayout = savedNextLayout;
77807
+ }
77808
+ // Remove interrupt from uniqueLayouts once it ends.
77809
+ cleanup = this.emitter.on('layoutEnd', function (endedLayout) {
77810
+ if (endedLayout !== interruptILayout) return;
77811
+ cleanup();
77812
+ if (!wasInUniqueLayouts) {
77813
+ _this7.uniqueLayouts["delete"](interruptKey);
77814
+ }
77815
+ console.debug('[navLayout] XLR::playInterruptLayout - Interrupt ended, resuming loop', {
77816
+ interruptLayoutId: inputLayout.layoutId,
77817
+ resumeNextLayoutId: savedNextLayout === null || savedNextLayout === void 0 ? void 0 : savedNextLayout.layoutId
77818
+ });
77819
+ });
77820
+ _context24.next = 24;
77821
+ return this.playSchedules(xlrObject);
77822
+ case 24:
77823
+ _context24.prev = 24;
77824
+ isNavigatingLayout = false;
77825
+ return _context24.finish(24);
77826
+ case 27:
77827
+ case "end":
77828
+ return _context24.stop();
77829
+ }
77830
+ }, _callee23, this, [[3,, 24, 27]]);
77831
+ }));
77832
+ return function (_x17) {
77833
+ return _ref23.apply(this, arguments);
77834
+ };
77835
+ }();
77836
+ xlrObject.triggerAction = function (triggerCode, widgetId) {
77837
+ var _this$currentLayout12;
77838
+ (_this$currentLayout12 = this.currentLayout) === null || _this$currentLayout12 === void 0 || (_this$currentLayout12 = _this$currentLayout12.actionController) === null || _this$currentLayout12 === void 0 || _this$currentLayout12.handleWebhookTrigger(triggerCode, widgetId);
77839
+ };
77324
77840
  xlrObject.updateInputLayout = function (layoutIndex, layout) {
77325
77841
  var xlrInputLayout = this.inputLayouts[layoutIndex];
77326
77842
  if (layout !== null) {