@unlk/keymaster 1.6.9 → 1.7.1

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Unlock Keymaster v1.6.9 (https://keymaster.unlock.com)
2
+ * Unlock Keymaster v1.7.1 (https://keymaster.unlock.com)
3
3
  * Copyright 2022-2026 Unlk Developers
4
4
  */
5
5
  (function (global, factory) {
@@ -7682,34 +7682,88 @@
7682
7682
  const SELECTOR_MODAL = '.modal';
7683
7683
  const SELECTOR_DIALOG = '.modal-dialog-media';
7684
7684
  const SELECTOR_RATIO = '.ratio';
7685
- const youTubeAPIInitPromise = new Promise(resolve => {
7685
+ let youTubeAPIInitPromise = null;
7686
+ let vimeoAPIInitPromise = null;
7687
+
7688
+ /**
7689
+ * Load the YouTube iframe API only when a YouTube video is opened.
7690
+ */
7691
+ function loadYouTubeAPI() {
7686
7692
  if (globalThis.YT?.Player) {
7687
- resolve();
7688
- } else {
7689
- const prev = globalThis.onYouTubeIframeAPIReady;
7693
+ return Promise.resolve();
7694
+ }
7695
+ if (youTubeAPIInitPromise) {
7696
+ return youTubeAPIInitPromise;
7697
+ }
7698
+ youTubeAPIInitPromise = new Promise((resolve, reject) => {
7699
+ const existingScript = document.querySelector('script[src="https://www.youtube.com/iframe_api"]');
7700
+ const previousReady = globalThis.onYouTubeIframeAPIReady;
7690
7701
  globalThis.onYouTubeIframeAPIReady = () => {
7691
7702
  try {
7692
- if (typeof prev === 'function') prev();
7703
+ if (typeof previousReady === 'function') {
7704
+ previousReady();
7705
+ }
7693
7706
  } catch {}
7694
7707
  resolve();
7695
7708
  };
7709
+ if (existingScript) {
7710
+ if (globalThis.YT?.Player) {
7711
+ resolve();
7712
+ }
7713
+ return;
7714
+ }
7696
7715
  const script = document.createElement('script');
7697
7716
  script.src = 'https://www.youtube.com/iframe_api';
7717
+ script.async = true;
7718
+ script.addEventListener('error', () => {
7719
+ youTubeAPIInitPromise = null;
7720
+ reject(new Error('Failed to load YouTube iframe API'));
7721
+ });
7698
7722
  document.head.append(script);
7699
- }
7700
- });
7701
- const vimeoAPIInitPromise = new Promise(resolve => {
7723
+ });
7724
+ return youTubeAPIInitPromise;
7725
+ }
7726
+
7727
+ /**
7728
+ * Load the Vimeo Player API only when a Vimeo video is opened.
7729
+ */
7730
+ function loadVimeoAPI() {
7702
7731
  if (globalThis.Vimeo?.Player) {
7703
- resolve();
7704
- } else {
7732
+ return Promise.resolve();
7733
+ }
7734
+ if (vimeoAPIInitPromise) {
7735
+ return vimeoAPIInitPromise;
7736
+ }
7737
+ vimeoAPIInitPromise = new Promise((resolve, reject) => {
7738
+ const existingScript = document.querySelector('script[src="https://player.vimeo.com/api/player.js"]');
7739
+ if (existingScript) {
7740
+ existingScript.addEventListener('load', () => resolve(), {
7741
+ once: true
7742
+ });
7743
+ existingScript.addEventListener('error', () => {
7744
+ vimeoAPIInitPromise = null;
7745
+ reject(new Error('Failed to load Vimeo Player API'));
7746
+ }, {
7747
+ once: true
7748
+ });
7749
+ return;
7750
+ }
7705
7751
  const script = document.createElement('script');
7706
7752
  script.src = 'https://player.vimeo.com/api/player.js';
7707
- script.addEventListener('load', () => {
7708
- resolve();
7753
+ script.async = true;
7754
+ script.addEventListener('load', () => resolve(), {
7755
+ once: true
7756
+ });
7757
+ script.addEventListener('error', () => {
7758
+ vimeoAPIInitPromise = null;
7759
+ reject(new Error('Failed to load Vimeo Player API'));
7760
+ }, {
7761
+ once: true
7709
7762
  });
7710
7763
  document.head.append(script);
7711
- }
7712
- });
7764
+ });
7765
+ return vimeoAPIInitPromise;
7766
+ }
7713
7767
  class VideoModal extends BaseComponent {
7714
7768
  constructor(element) {
7715
7769
  super(element);
@@ -7729,46 +7783,60 @@
7729
7783
  id
7730
7784
  } = this._element;
7731
7785
  const playerID = `video-${id}-youtube-player`;
7732
- if (this._vimeoUrl) {
7733
- await vimeoAPIInitPromise;
7734
- const vimeoId = this._getVimeoId(this._vimeoUrl);
7735
- this._vimeoPlayer = new globalThis.Vimeo.Player(this._container, {
7736
- id: vimeoId,
7737
- autoplay: true
7738
- });
7739
- this._element.dataset.vimeoId = String(vimeoId);
7740
- this._element.__unlkVimeoPlayer = this._vimeoPlayer;
7741
- this._element.dispatchEvent(new CustomEvent('videomodal.ready', {
7742
- bubbles: true,
7743
- detail: {
7744
- provider: 'vimeo',
7745
- player: this._vimeoPlayer,
7746
- videoId: vimeoId
7786
+ try {
7787
+ if (this._vimeoUrl) {
7788
+ await loadVimeoAPI();
7789
+ const vimeoId = this._getVimeoId(this._vimeoUrl);
7790
+ if (!vimeoId) {
7791
+ return;
7747
7792
  }
7748
- }));
7749
- return;
7750
- }
7751
- if (this._youtubeSrc) {
7752
- await youTubeAPIInitPromise;
7753
- const youtubeId = this._getYouTubeId(this._youtubeSrc);
7754
- const playerDiv = this._container.querySelector(`#${playerID}`);
7755
- this._youtubePlayer = new globalThis.YT.Player(playerDiv, {
7756
- videoId: youtubeId,
7757
- playerVars: {
7758
- autoplay: 1,
7759
- rel: 0
7793
+ this._vimeoPlayer = new globalThis.Vimeo.Player(this._container, {
7794
+ id: vimeoId,
7795
+ autoplay: true
7796
+ });
7797
+ this._element.dataset.vimeoId = String(vimeoId);
7798
+ this._element.__unlkVimeoPlayer = this._vimeoPlayer;
7799
+ this._element.dispatchEvent(new CustomEvent('videomodal.ready', {
7800
+ bubbles: true,
7801
+ detail: {
7802
+ provider: 'vimeo',
7803
+ player: this._vimeoPlayer,
7804
+ videoId: vimeoId
7805
+ }
7806
+ }));
7807
+ return;
7808
+ }
7809
+ if (this._youtubeSrc) {
7810
+ await loadYouTubeAPI();
7811
+ const youtubeId = this._getYouTubeId(this._youtubeSrc);
7812
+ if (!youtubeId) {
7813
+ return;
7760
7814
  }
7761
- });
7762
- this._element.dataset.ytId = youtubeId;
7763
- this._element.__unlkYtPlayer = this._youtubePlayer;
7764
- this._element.dispatchEvent(new CustomEvent('videomodal.ready', {
7765
- bubbles: true,
7766
- detail: {
7767
- provider: 'youtube',
7768
- player: this._youtubePlayer,
7769
- videoId: youtubeId
7815
+ const playerDiv = this._container.querySelector(`#${playerID}`);
7816
+ if (!playerDiv) {
7817
+ return;
7770
7818
  }
7771
- }));
7819
+ this._youtubePlayer = new globalThis.YT.Player(playerDiv, {
7820
+ videoId: youtubeId,
7821
+ playerVars: {
7822
+ autoplay: 1,
7823
+ rel: 0
7824
+ }
7825
+ });
7826
+ this._element.dataset.ytId = youtubeId;
7827
+ this._element.__unlkYtPlayer = this._youtubePlayer;
7828
+ this._element.dispatchEvent(new CustomEvent('videomodal.ready', {
7829
+ bubbles: true,
7830
+ detail: {
7831
+ provider: 'youtube',
7832
+ player: this._youtubePlayer,
7833
+ videoId: youtubeId
7834
+ }
7835
+ }));
7836
+ }
7837
+ } catch (error) {
7838
+ // eslint-disable-next-line no-console
7839
+ console.error('[VideoModal] Failed to initialize video player:', error);
7772
7840
  }
7773
7841
  }
7774
7842
  _onHide() {
@@ -7803,11 +7871,15 @@
7803
7871
  }
7804
7872
  }
7805
7873
  EventHandler.on(document, EVENT_SHOW, SELECTOR_MODAL, function () {
7806
- if (!SelectorEngine.findOne(SELECTOR_DIALOG, this)) return;
7874
+ if (!SelectorEngine.findOne(SELECTOR_DIALOG, this)) {
7875
+ return;
7876
+ }
7807
7877
  VideoModal.getOrCreateInstance(this)._onShow();
7808
7878
  });
7809
7879
  EventHandler.on(document, EVENT_HIDDEN, SELECTOR_MODAL, function () {
7810
- if (!SelectorEngine.findOne(SELECTOR_DIALOG, this)) return;
7880
+ if (!SelectorEngine.findOne(SELECTOR_DIALOG, this)) {
7881
+ return;
7882
+ }
7811
7883
  VideoModal.getOrCreateInstance(this)._onHide();
7812
7884
  });
7813
7885
  defineJQueryPlugin(VideoModal);