@biggive/components 202609171513.0.0 → 202609210628.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/hydrate/index.mjs CHANGED
@@ -8398,12 +8398,20 @@ class VideoService {
8398
8398
  }
8399
8399
  else if (url.match(/player\.vimeo\.com/g)) {
8400
8400
  const titlePart = title !== null && title.length > 0 ? ` title="${title}"` : '';
8401
- return `<div style="padding:56.25% 0 0 0;position:relative;"><iframe src="${url}?badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479&amp;dnt=1" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" style="position:absolute;top:0;left:0;width:100%;height:100%;"${titlePart}></iframe></div><script src="https://player.vimeo.com/api/player.js"></script>`;
8401
+ return `<div style="padding:56.25% 0 0 0;position:relative;"><iframe src="${url}?badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479&amp;dnt=1" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" style="position:absolute;top:0;left:0;width:100%;height:100%;"${titlePart}></iframe></div>`;
8402
8402
  }
8403
8403
  else {
8404
8404
  return `<video controls src="${url}"></video>`;
8405
8405
  }
8406
8406
  }
8407
+ static async initializeVimeoPlayer(container) {
8408
+ const iframe = container.querySelector('iframe[src*="player.vimeo.com"]');
8409
+ if (iframe !== null && iframe.dataset.vimeoPlayerInitialized !== 'true') {
8410
+ const { default: VimeoPlayer } = await Promise.resolve().then(function () { return player_es; });
8411
+ new VimeoPlayer(iframe);
8412
+ iframe.dataset.vimeoPlayerInitialized = 'true';
8413
+ }
8414
+ }
8407
8415
  /**
8408
8416
  * If the user supplied a URL to view a page video in a page on youtube or vimeo,
8409
8417
  * we replace it with the URL to the related embedabble iframe.
@@ -8440,8 +8448,12 @@ class BiggiveVideo {
8440
8448
  this.videoUrl = '';
8441
8449
  }
8442
8450
  render() {
8443
- return (hAsync("div", { key: 'f80df68393fcbb5bf4ad5e28edb4cf8fc5f9f7a4', class: 'container space-above-' + this.spaceAbove + ' space-below-' + this.spaceBelow }, hAsync("div", { key: '61564ab412a3fbe7a6e0a86c498b5f88a6fc8b93', class: "video-wrap", innerHTML: VideoService.getEmbedHtml(this.videoUrl, null) })));
8451
+ return (hAsync("div", { key: '19016f17a21455d8a3b48415f76ead3bdc65b0b4', class: 'container space-above-' + this.spaceAbove + ' space-below-' + this.spaceBelow }, hAsync("div", { key: 'a66e437f1316b47704283e01dbe1023992651bfb', class: "video-wrap", innerHTML: VideoService.getEmbedHtml(this.videoUrl, null) })));
8452
+ }
8453
+ componentDidRender() {
8454
+ void VideoService.initializeVimeoPlayer(this.host);
8444
8455
  }
8456
+ get host() { return getElement(this); }
8445
8457
  static get style() { return biggiveVideoCss(); }
8446
8458
  static get cmpMeta() { return {
8447
8459
  "$flags$": 9,
@@ -8497,8 +8509,12 @@ class BiggiveVideoFeature {
8497
8509
  }
8498
8510
  render() {
8499
8511
  const youtubeClass = this.videoUrl.includes('youtube.com') ? ' youtube' : '';
8500
- return (hAsync("div", { key: '9728b2ad86188ca8186ea51ef22d41e230321f3a', class: 'container text-colour-' + this.defaultTextColour + ' space-above-' + this.spaceAbove + ' space-below-' + this.spaceBelow }, hAsync("div", { key: '89b4cb27f12bd79a21feb0fd0e296fb88076e51b', class: "sleeve" }, hAsync("div", { key: '572da0a8b8ebdea61ea04408d31f19744e803ad3', class: "content-wrap" }, hAsync("div", { key: 'c4446b7165c47ac6562771608140774fe1451dea', class: 'slug text-colour-' + this.slugColour }, this.slug), hAsync("h2", { key: '06765a3aba7296b1a1c289cb2c33d9754f909771', class: 'title text-colour-' + this.mainTitleColour }, this.mainTitle), hAsync("div", { key: '11b2801d03d26bfc20805aa65fe9e054f82bdc1f', class: 'teaser text-colour-' + this.teaserColour }, this.teaser), this.buttonLabel != null && this.buttonUrl != null ? (hAsync("biggive-button", { "colour-scheme": this.buttonColourScheme, url: this.buttonUrl, label: this.buttonLabel })) : null), hAsync("div", { key: 'fcc96dbb3fbebde2a1db504de77bf6b509fafc3b', class: "graphic-wrap" }, this.videoUrl !== null && this.videoUrl !== undefined ? (hAsync("div", { class: 'video-wrap' + youtubeClass, innerHTML: VideoService.getEmbedHtml(this.videoUrl, this.mainTitle) })) : null))));
8512
+ return (hAsync("div", { key: '9fc267609031ded8342a70bdec2c257d305bfe14', class: 'container text-colour-' + this.defaultTextColour + ' space-above-' + this.spaceAbove + ' space-below-' + this.spaceBelow }, hAsync("div", { key: 'd566c77b874ee03424462fe2292361629d136235', class: "sleeve" }, hAsync("div", { key: 'e6405b33a58e680d7f87fc91d97718b1a6482ce1', class: "content-wrap" }, hAsync("div", { key: '676d5e83650364637a3a8dfe723cc01681091dff', class: 'slug text-colour-' + this.slugColour }, this.slug), hAsync("h2", { key: 'd8b1f143ce429e5cf2640b65c5937ece054df9a8', class: 'title text-colour-' + this.mainTitleColour }, this.mainTitle), hAsync("div", { key: '23b52399945a63a5c2bad94747715bd026990cf8', class: 'teaser text-colour-' + this.teaserColour }, this.teaser), this.buttonLabel != null && this.buttonUrl != null ? (hAsync("biggive-button", { "colour-scheme": this.buttonColourScheme, url: this.buttonUrl, label: this.buttonLabel })) : null), hAsync("div", { key: 'b3342d10bf71273aa79ea9bcd2b78bd1ce274580', class: "graphic-wrap" }, this.videoUrl !== null && this.videoUrl !== undefined ? (hAsync("div", { class: 'video-wrap' + youtubeClass, innerHTML: VideoService.getEmbedHtml(this.videoUrl, this.mainTitle) })) : null))));
8513
+ }
8514
+ componentDidRender() {
8515
+ void VideoService.initializeVimeoPlayer(this.host);
8501
8516
  }
8517
+ get host() { return getElement(this); }
8502
8518
  static get style() { return biggiveVideoFeatureCss(); }
8503
8519
  static get cmpMeta() { return {
8504
8520
  "$flags$": 9,
@@ -8651,6 +8667,2835 @@ registerComponents([
8651
8667
  PhilcoMainMenu,
8652
8668
  ]);
8653
8669
 
8670
+ /*! @vimeo/player v2.30.4 | (c) 2026 Vimeo | MIT License | https://github.com/vimeo/player.js */
8671
+ /**
8672
+ * @module lib/functions
8673
+ */
8674
+
8675
+ /**
8676
+ * Check to see this is a Node environment.
8677
+ * @type {boolean}
8678
+ */
8679
+ /* global global */
8680
+ const isNode = typeof global !== 'undefined' && {}.toString.call(global) === '[object global]';
8681
+
8682
+ /**
8683
+ * Check to see if this is a Bun environment.
8684
+ * @see https://bun.sh/guides/util/detect-bun
8685
+ * @type {boolean}
8686
+ */
8687
+ const isBun = typeof Bun !== 'undefined';
8688
+
8689
+ /**
8690
+ * Check to see if this is a Deno environment.
8691
+ * @see https://docs.deno.com/api/deno/~/Deno
8692
+ * @type {boolean}
8693
+ */
8694
+ const isDeno = typeof Deno !== 'undefined';
8695
+
8696
+ /**
8697
+ * Check to see if this is a Cloudflare Worker environment.
8698
+ * @see https://community.cloudflare.com/t/how-to-detect-the-cloudflare-worker-runtime/293715
8699
+ * @type {boolean}
8700
+ */
8701
+ const isCloudflareWorker = typeof WebSocketPair === 'function' && typeof caches?.default !== 'undefined';
8702
+
8703
+ /**
8704
+ * Check if this is a server runtime
8705
+ * @type {boolean}
8706
+ */
8707
+ const isServerRuntime = isNode || isBun || isDeno || isCloudflareWorker;
8708
+
8709
+ /**
8710
+ * Get the name of the method for a given getter or setter.
8711
+ *
8712
+ * @param {string} prop The name of the property.
8713
+ * @param {string} type Either “get” or “set”.
8714
+ * @return {string}
8715
+ */
8716
+ function getMethodName(prop, type) {
8717
+ if (prop.indexOf(type.toLowerCase()) === 0) {
8718
+ return prop;
8719
+ }
8720
+ return `${type.toLowerCase()}${prop.substr(0, 1).toUpperCase()}${prop.substr(1)}`;
8721
+ }
8722
+
8723
+ /**
8724
+ * Check to see if the object is a DOM Element.
8725
+ *
8726
+ * @param {*} element The object to check.
8727
+ * @return {boolean}
8728
+ */
8729
+ function isDomElement(element) {
8730
+ return Boolean(element && element.nodeType === 1 && 'nodeName' in element && element.ownerDocument && element.ownerDocument.defaultView);
8731
+ }
8732
+
8733
+ /**
8734
+ * Check to see whether the value is a number.
8735
+ *
8736
+ * @see http://dl.dropboxusercontent.com/u/35146/js/tests/isNumber.html
8737
+ * @param {*} value The value to check.
8738
+ * @param {boolean} integer Check if the value is an integer.
8739
+ * @return {boolean}
8740
+ */
8741
+ function isInteger(value) {
8742
+ // eslint-disable-next-line eqeqeq
8743
+ return !isNaN(parseFloat(value)) && isFinite(value) && Math.floor(value) == value;
8744
+ }
8745
+
8746
+ /**
8747
+ * Check to see if the URL is a Vimeo url.
8748
+ *
8749
+ * @param {string} url The url string.
8750
+ * @return {boolean}
8751
+ */
8752
+ function isVimeoUrl(url) {
8753
+ return /^(https?:)?\/\/((((player|www)\.)?vimeo\.com)|((player\.)?[a-zA-Z0-9-]+\.(videoji\.(hk|cn)|vimeo\.work)))(?=$|\/)/.test(url);
8754
+ }
8755
+
8756
+ /**
8757
+ * Check to see if the URL is for a Vimeo embed.
8758
+ *
8759
+ * @param {string} url The url string.
8760
+ * @return {boolean}
8761
+ */
8762
+ function isVimeoEmbed(url) {
8763
+ const expr = /^https:\/\/player\.((vimeo\.com)|([a-zA-Z0-9-]+\.(videoji\.(hk|cn)|vimeo\.work)))\/video\/\d+/;
8764
+ return expr.test(url);
8765
+ }
8766
+ function getOembedDomain(url) {
8767
+ const match = (url || '').match(/^(?:https?:)?(?:\/\/)?([^/?]+)/);
8768
+ const domain = (match && match[1] || '').replace('player.', '');
8769
+ const customDomains = ['.videoji.hk', '.vimeo.work', '.videoji.cn'];
8770
+ for (const customDomain of customDomains) {
8771
+ if (domain.endsWith(customDomain)) {
8772
+ return domain;
8773
+ }
8774
+ }
8775
+ return 'vimeo.com';
8776
+ }
8777
+
8778
+ /**
8779
+ * Get the Vimeo URL from an element.
8780
+ * The element must have either a data-vimeo-id or data-vimeo-url attribute.
8781
+ *
8782
+ * @param {object} oEmbedParameters The oEmbed parameters.
8783
+ * @return {string}
8784
+ */
8785
+ function getVimeoUrl() {
8786
+ let oEmbedParameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8787
+ const id = oEmbedParameters.id;
8788
+ const url = oEmbedParameters.url;
8789
+ const idOrUrl = id || url;
8790
+ if (!idOrUrl) {
8791
+ throw new Error('An id or url must be passed, either in an options object or as a data-vimeo-id or data-vimeo-url attribute.');
8792
+ }
8793
+ if (isInteger(idOrUrl)) {
8794
+ return `https://vimeo.com/${idOrUrl}`;
8795
+ }
8796
+ if (isVimeoUrl(idOrUrl)) {
8797
+ return idOrUrl.replace('http:', 'https:');
8798
+ }
8799
+ if (id) {
8800
+ throw new TypeError(`“${id}” is not a valid video id.`);
8801
+ }
8802
+ throw new TypeError(`“${idOrUrl}” is not a vimeo.com url.`);
8803
+ }
8804
+
8805
+ /* eslint-disable max-params */
8806
+ /**
8807
+ * A utility method for attaching and detaching event handlers
8808
+ *
8809
+ * @param {EventTarget} target
8810
+ * @param {string | string[]} eventName
8811
+ * @param {function} callback
8812
+ * @param {'addEventListener' | 'on'} onName
8813
+ * @param {'removeEventListener' | 'off'} offName
8814
+ * @return {{cancel: (function(): void)}}
8815
+ */
8816
+ const subscribe = function (target, eventName, callback) {
8817
+ let onName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'addEventListener';
8818
+ let offName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'removeEventListener';
8819
+ const eventNames = typeof eventName === 'string' ? [eventName] : eventName;
8820
+ eventNames.forEach(evName => {
8821
+ target[onName](evName, callback);
8822
+ });
8823
+ return {
8824
+ cancel: () => eventNames.forEach(evName => target[offName](evName, callback))
8825
+ };
8826
+ };
8827
+
8828
+ /**
8829
+ * Find the iframe element that contains a specific source window
8830
+ *
8831
+ * @param {Window} sourceWindow The source window to find the iframe for
8832
+ * @param {Document} [doc=document] The document to search within
8833
+ * @return {HTMLIFrameElement|null} The iframe element if found, otherwise null
8834
+ */
8835
+ function findIframeBySourceWindow(sourceWindow) {
8836
+ let doc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
8837
+ if (!sourceWindow || !doc || typeof doc.querySelectorAll !== 'function') {
8838
+ return null;
8839
+ }
8840
+ const iframes = doc.querySelectorAll('iframe');
8841
+ for (let i = 0; i < iframes.length; i++) {
8842
+ if (iframes[i] && iframes[i].contentWindow === sourceWindow) {
8843
+ return iframes[i];
8844
+ }
8845
+ }
8846
+ return null;
8847
+ }
8848
+
8849
+ const arrayIndexOfSupport = typeof Array.prototype.indexOf !== 'undefined';
8850
+ const postMessageSupport = typeof window !== 'undefined' && typeof window.postMessage !== 'undefined';
8851
+ if (!isServerRuntime && (!arrayIndexOfSupport || !postMessageSupport)) {
8852
+ throw new Error('Sorry, the Vimeo Player API is not available in this browser.');
8853
+ }
8854
+
8855
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8856
+
8857
+ function createCommonjsModule(fn, module) {
8858
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
8859
+ }
8860
+
8861
+ /*!
8862
+ * weakmap-polyfill v2.0.4 - ECMAScript6 WeakMap polyfill
8863
+ * https://github.com/polygonplanet/weakmap-polyfill
8864
+ * Copyright (c) 2015-2021 polygonplanet <polygon.planet.aqua@gmail.com>
8865
+ * @license MIT
8866
+ */
8867
+
8868
+ (function (self) {
8869
+
8870
+ if (self.WeakMap) {
8871
+ return;
8872
+ }
8873
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
8874
+ var hasDefine = Object.defineProperty && function () {
8875
+ try {
8876
+ // Avoid IE8's broken Object.defineProperty
8877
+ return Object.defineProperty({}, 'x', {
8878
+ value: 1
8879
+ }).x === 1;
8880
+ } catch (e) {}
8881
+ }();
8882
+ var defineProperty = function (object, name, value) {
8883
+ if (hasDefine) {
8884
+ Object.defineProperty(object, name, {
8885
+ configurable: true,
8886
+ writable: true,
8887
+ value: value
8888
+ });
8889
+ } else {
8890
+ object[name] = value;
8891
+ }
8892
+ };
8893
+ self.WeakMap = function () {
8894
+ // ECMA-262 23.3 WeakMap Objects
8895
+ function WeakMap() {
8896
+ if (this === void 0) {
8897
+ throw new TypeError("Constructor WeakMap requires 'new'");
8898
+ }
8899
+ defineProperty(this, '_id', genId('_WeakMap'));
8900
+
8901
+ // ECMA-262 23.3.1.1 WeakMap([iterable])
8902
+ if (arguments.length > 0) {
8903
+ // Currently, WeakMap `iterable` argument is not supported
8904
+ throw new TypeError('WeakMap iterable is not supported');
8905
+ }
8906
+ }
8907
+
8908
+ // ECMA-262 23.3.3.2 WeakMap.prototype.delete(key)
8909
+ defineProperty(WeakMap.prototype, 'delete', function (key) {
8910
+ checkInstance(this, 'delete');
8911
+ if (!isObject(key)) {
8912
+ return false;
8913
+ }
8914
+ var entry = key[this._id];
8915
+ if (entry && entry[0] === key) {
8916
+ delete key[this._id];
8917
+ return true;
8918
+ }
8919
+ return false;
8920
+ });
8921
+
8922
+ // ECMA-262 23.3.3.3 WeakMap.prototype.get(key)
8923
+ defineProperty(WeakMap.prototype, 'get', function (key) {
8924
+ checkInstance(this, 'get');
8925
+ if (!isObject(key)) {
8926
+ return void 0;
8927
+ }
8928
+ var entry = key[this._id];
8929
+ if (entry && entry[0] === key) {
8930
+ return entry[1];
8931
+ }
8932
+ return void 0;
8933
+ });
8934
+
8935
+ // ECMA-262 23.3.3.4 WeakMap.prototype.has(key)
8936
+ defineProperty(WeakMap.prototype, 'has', function (key) {
8937
+ checkInstance(this, 'has');
8938
+ if (!isObject(key)) {
8939
+ return false;
8940
+ }
8941
+ var entry = key[this._id];
8942
+ if (entry && entry[0] === key) {
8943
+ return true;
8944
+ }
8945
+ return false;
8946
+ });
8947
+
8948
+ // ECMA-262 23.3.3.5 WeakMap.prototype.set(key, value)
8949
+ defineProperty(WeakMap.prototype, 'set', function (key, value) {
8950
+ checkInstance(this, 'set');
8951
+ if (!isObject(key)) {
8952
+ throw new TypeError('Invalid value used as weak map key');
8953
+ }
8954
+ var entry = key[this._id];
8955
+ if (entry && entry[0] === key) {
8956
+ entry[1] = value;
8957
+ return this;
8958
+ }
8959
+ defineProperty(key, this._id, [key, value]);
8960
+ return this;
8961
+ });
8962
+ function checkInstance(x, methodName) {
8963
+ if (!isObject(x) || !hasOwnProperty.call(x, '_id')) {
8964
+ throw new TypeError(methodName + ' method called on incompatible receiver ' + typeof x);
8965
+ }
8966
+ }
8967
+ function genId(prefix) {
8968
+ return prefix + '_' + rand() + '.' + rand();
8969
+ }
8970
+ function rand() {
8971
+ return Math.random().toString().substring(2);
8972
+ }
8973
+ defineProperty(WeakMap, '_polyfill', true);
8974
+ return WeakMap;
8975
+ }();
8976
+ function isObject(x) {
8977
+ return Object(x) === x;
8978
+ }
8979
+ })(typeof globalThis !== 'undefined' ? globalThis : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : typeof commonjsGlobal !== 'undefined' ? commonjsGlobal : commonjsGlobal);
8980
+
8981
+ var npo_src = createCommonjsModule(function (module) {
8982
+ /*! Native Promise Only
8983
+ v0.8.1 (c) Kyle Simpson
8984
+ MIT License: http://getify.mit-license.org
8985
+ */
8986
+
8987
+ (function UMD(name, context, definition) {
8988
+ // special form of UMD for polyfilling across evironments
8989
+ context[name] = context[name] || definition();
8990
+ if (module.exports) {
8991
+ module.exports = context[name];
8992
+ }
8993
+ })("Promise", typeof commonjsGlobal != "undefined" ? commonjsGlobal : commonjsGlobal, function DEF() {
8994
+
8995
+ var builtInProp,
8996
+ cycle,
8997
+ scheduling_queue,
8998
+ ToString = Object.prototype.toString,
8999
+ timer = typeof setImmediate != "undefined" ? function timer(fn) {
9000
+ return setImmediate(fn);
9001
+ } : setTimeout;
9002
+
9003
+ // dammit, IE8.
9004
+ try {
9005
+ builtInProp = function builtInProp(obj, name, val, config) {
9006
+ return Object.defineProperty(obj, name, {
9007
+ value: val,
9008
+ writable: true,
9009
+ configurable: config !== false
9010
+ });
9011
+ };
9012
+ } catch (err) {
9013
+ builtInProp = function builtInProp(obj, name, val) {
9014
+ obj[name] = val;
9015
+ return obj;
9016
+ };
9017
+ }
9018
+
9019
+ // Note: using a queue instead of array for efficiency
9020
+ scheduling_queue = function Queue() {
9021
+ var first, last, item;
9022
+ function Item(fn, self) {
9023
+ this.fn = fn;
9024
+ this.self = self;
9025
+ this.next = void 0;
9026
+ }
9027
+ return {
9028
+ add: function add(fn, self) {
9029
+ item = new Item(fn, self);
9030
+ if (last) {
9031
+ last.next = item;
9032
+ } else {
9033
+ first = item;
9034
+ }
9035
+ last = item;
9036
+ item = void 0;
9037
+ },
9038
+ drain: function drain() {
9039
+ var f = first;
9040
+ first = last = cycle = void 0;
9041
+ while (f) {
9042
+ f.fn.call(f.self);
9043
+ f = f.next;
9044
+ }
9045
+ }
9046
+ };
9047
+ }();
9048
+ function schedule(fn, self) {
9049
+ scheduling_queue.add(fn, self);
9050
+ if (!cycle) {
9051
+ cycle = timer(scheduling_queue.drain);
9052
+ }
9053
+ }
9054
+
9055
+ // promise duck typing
9056
+ function isThenable(o) {
9057
+ var _then,
9058
+ o_type = typeof o;
9059
+ if (o != null && (o_type == "object" || o_type == "function")) {
9060
+ _then = o.then;
9061
+ }
9062
+ return typeof _then == "function" ? _then : false;
9063
+ }
9064
+ function notify() {
9065
+ for (var i = 0; i < this.chain.length; i++) {
9066
+ notifyIsolated(this, this.state === 1 ? this.chain[i].success : this.chain[i].failure, this.chain[i]);
9067
+ }
9068
+ this.chain.length = 0;
9069
+ }
9070
+
9071
+ // NOTE: This is a separate function to isolate
9072
+ // the `try..catch` so that other code can be
9073
+ // optimized better
9074
+ function notifyIsolated(self, cb, chain) {
9075
+ var ret, _then;
9076
+ try {
9077
+ if (cb === false) {
9078
+ chain.reject(self.msg);
9079
+ } else {
9080
+ if (cb === true) {
9081
+ ret = self.msg;
9082
+ } else {
9083
+ ret = cb.call(void 0, self.msg);
9084
+ }
9085
+ if (ret === chain.promise) {
9086
+ chain.reject(TypeError("Promise-chain cycle"));
9087
+ } else if (_then = isThenable(ret)) {
9088
+ _then.call(ret, chain.resolve, chain.reject);
9089
+ } else {
9090
+ chain.resolve(ret);
9091
+ }
9092
+ }
9093
+ } catch (err) {
9094
+ chain.reject(err);
9095
+ }
9096
+ }
9097
+ function resolve(msg) {
9098
+ var _then,
9099
+ self = this;
9100
+
9101
+ // already triggered?
9102
+ if (self.triggered) {
9103
+ return;
9104
+ }
9105
+ self.triggered = true;
9106
+
9107
+ // unwrap
9108
+ if (self.def) {
9109
+ self = self.def;
9110
+ }
9111
+ try {
9112
+ if (_then = isThenable(msg)) {
9113
+ schedule(function () {
9114
+ var def_wrapper = new MakeDefWrapper(self);
9115
+ try {
9116
+ _then.call(msg, function $resolve$() {
9117
+ resolve.apply(def_wrapper, arguments);
9118
+ }, function $reject$() {
9119
+ reject.apply(def_wrapper, arguments);
9120
+ });
9121
+ } catch (err) {
9122
+ reject.call(def_wrapper, err);
9123
+ }
9124
+ });
9125
+ } else {
9126
+ self.msg = msg;
9127
+ self.state = 1;
9128
+ if (self.chain.length > 0) {
9129
+ schedule(notify, self);
9130
+ }
9131
+ }
9132
+ } catch (err) {
9133
+ reject.call(new MakeDefWrapper(self), err);
9134
+ }
9135
+ }
9136
+ function reject(msg) {
9137
+ var self = this;
9138
+
9139
+ // already triggered?
9140
+ if (self.triggered) {
9141
+ return;
9142
+ }
9143
+ self.triggered = true;
9144
+
9145
+ // unwrap
9146
+ if (self.def) {
9147
+ self = self.def;
9148
+ }
9149
+ self.msg = msg;
9150
+ self.state = 2;
9151
+ if (self.chain.length > 0) {
9152
+ schedule(notify, self);
9153
+ }
9154
+ }
9155
+ function iteratePromises(Constructor, arr, resolver, rejecter) {
9156
+ for (var idx = 0; idx < arr.length; idx++) {
9157
+ (function IIFE(idx) {
9158
+ Constructor.resolve(arr[idx]).then(function $resolver$(msg) {
9159
+ resolver(idx, msg);
9160
+ }, rejecter);
9161
+ })(idx);
9162
+ }
9163
+ }
9164
+ function MakeDefWrapper(self) {
9165
+ this.def = self;
9166
+ this.triggered = false;
9167
+ }
9168
+ function MakeDef(self) {
9169
+ this.promise = self;
9170
+ this.state = 0;
9171
+ this.triggered = false;
9172
+ this.chain = [];
9173
+ this.msg = void 0;
9174
+ }
9175
+ function Promise(executor) {
9176
+ if (typeof executor != "function") {
9177
+ throw TypeError("Not a function");
9178
+ }
9179
+ if (this.__NPO__ !== 0) {
9180
+ throw TypeError("Not a promise");
9181
+ }
9182
+
9183
+ // instance shadowing the inherited "brand"
9184
+ // to signal an already "initialized" promise
9185
+ this.__NPO__ = 1;
9186
+ var def = new MakeDef(this);
9187
+ this["then"] = function then(success, failure) {
9188
+ var o = {
9189
+ success: typeof success == "function" ? success : true,
9190
+ failure: typeof failure == "function" ? failure : false
9191
+ };
9192
+ // Note: `then(..)` itself can be borrowed to be used against
9193
+ // a different promise constructor for making the chained promise,
9194
+ // by substituting a different `this` binding.
9195
+ o.promise = new this.constructor(function extractChain(resolve, reject) {
9196
+ if (typeof resolve != "function" || typeof reject != "function") {
9197
+ throw TypeError("Not a function");
9198
+ }
9199
+ o.resolve = resolve;
9200
+ o.reject = reject;
9201
+ });
9202
+ def.chain.push(o);
9203
+ if (def.state !== 0) {
9204
+ schedule(notify, def);
9205
+ }
9206
+ return o.promise;
9207
+ };
9208
+ this["catch"] = function $catch$(failure) {
9209
+ return this.then(void 0, failure);
9210
+ };
9211
+ try {
9212
+ executor.call(void 0, function publicResolve(msg) {
9213
+ resolve.call(def, msg);
9214
+ }, function publicReject(msg) {
9215
+ reject.call(def, msg);
9216
+ });
9217
+ } catch (err) {
9218
+ reject.call(def, err);
9219
+ }
9220
+ }
9221
+ var PromisePrototype = builtInProp({}, "constructor", Promise, /*configurable=*/false);
9222
+
9223
+ // Note: Android 4 cannot use `Object.defineProperty(..)` here
9224
+ Promise.prototype = PromisePrototype;
9225
+
9226
+ // built-in "brand" to signal an "uninitialized" promise
9227
+ builtInProp(PromisePrototype, "__NPO__", 0, /*configurable=*/false);
9228
+ builtInProp(Promise, "resolve", function Promise$resolve(msg) {
9229
+ var Constructor = this;
9230
+
9231
+ // spec mandated checks
9232
+ // note: best "isPromise" check that's practical for now
9233
+ if (msg && typeof msg == "object" && msg.__NPO__ === 1) {
9234
+ return msg;
9235
+ }
9236
+ return new Constructor(function executor(resolve, reject) {
9237
+ if (typeof resolve != "function" || typeof reject != "function") {
9238
+ throw TypeError("Not a function");
9239
+ }
9240
+ resolve(msg);
9241
+ });
9242
+ });
9243
+ builtInProp(Promise, "reject", function Promise$reject(msg) {
9244
+ return new this(function executor(resolve, reject) {
9245
+ if (typeof resolve != "function" || typeof reject != "function") {
9246
+ throw TypeError("Not a function");
9247
+ }
9248
+ reject(msg);
9249
+ });
9250
+ });
9251
+ builtInProp(Promise, "all", function Promise$all(arr) {
9252
+ var Constructor = this;
9253
+
9254
+ // spec mandated checks
9255
+ if (ToString.call(arr) != "[object Array]") {
9256
+ return Constructor.reject(TypeError("Not an array"));
9257
+ }
9258
+ if (arr.length === 0) {
9259
+ return Constructor.resolve([]);
9260
+ }
9261
+ return new Constructor(function executor(resolve, reject) {
9262
+ if (typeof resolve != "function" || typeof reject != "function") {
9263
+ throw TypeError("Not a function");
9264
+ }
9265
+ var len = arr.length,
9266
+ msgs = Array(len),
9267
+ count = 0;
9268
+ iteratePromises(Constructor, arr, function resolver(idx, msg) {
9269
+ msgs[idx] = msg;
9270
+ if (++count === len) {
9271
+ resolve(msgs);
9272
+ }
9273
+ }, reject);
9274
+ });
9275
+ });
9276
+ builtInProp(Promise, "race", function Promise$race(arr) {
9277
+ var Constructor = this;
9278
+
9279
+ // spec mandated checks
9280
+ if (ToString.call(arr) != "[object Array]") {
9281
+ return Constructor.reject(TypeError("Not an array"));
9282
+ }
9283
+ return new Constructor(function executor(resolve, reject) {
9284
+ if (typeof resolve != "function" || typeof reject != "function") {
9285
+ throw TypeError("Not a function");
9286
+ }
9287
+ iteratePromises(Constructor, arr, function resolver(idx, msg) {
9288
+ resolve(msg);
9289
+ }, reject);
9290
+ });
9291
+ });
9292
+ return Promise;
9293
+ });
9294
+ });
9295
+
9296
+ /**
9297
+ * @module lib/callbacks
9298
+ */
9299
+
9300
+ const callbackMap = new WeakMap();
9301
+
9302
+ /**
9303
+ * Store a callback for a method or event for a player.
9304
+ *
9305
+ * @param {Player} player The player object.
9306
+ * @param {string} name The method or event name.
9307
+ * @param {(function(this:Player, *): void|{resolve: function, reject: function})} callback
9308
+ * The callback to call or an object with resolve and reject functions for a promise.
9309
+ * @return {void}
9310
+ */
9311
+ function storeCallback(player, name, callback) {
9312
+ const playerCallbacks = callbackMap.get(player.element) || {};
9313
+ if (!(name in playerCallbacks)) {
9314
+ playerCallbacks[name] = [];
9315
+ }
9316
+ playerCallbacks[name].push(callback);
9317
+ callbackMap.set(player.element, playerCallbacks);
9318
+ }
9319
+
9320
+ /**
9321
+ * Get the callbacks for a player and event or method.
9322
+ *
9323
+ * @param {Player} player The player object.
9324
+ * @param {string} name The method or event name
9325
+ * @return {function[]}
9326
+ */
9327
+ function getCallbacks(player, name) {
9328
+ const playerCallbacks = callbackMap.get(player.element) || {};
9329
+ return playerCallbacks[name] || [];
9330
+ }
9331
+
9332
+ /**
9333
+ * Remove a stored callback for a method or event for a player.
9334
+ *
9335
+ * @param {Player} player The player object.
9336
+ * @param {string} name The method or event name
9337
+ * @param {function} [callback] The specific callback to remove.
9338
+ * @return {boolean} Was this the last callback?
9339
+ */
9340
+ function removeCallback(player, name, callback) {
9341
+ const playerCallbacks = callbackMap.get(player.element) || {};
9342
+ if (!playerCallbacks[name]) {
9343
+ return true;
9344
+ }
9345
+
9346
+ // If no callback is passed, remove all callbacks for the event
9347
+ if (!callback) {
9348
+ playerCallbacks[name] = [];
9349
+ callbackMap.set(player.element, playerCallbacks);
9350
+ return true;
9351
+ }
9352
+ const index = playerCallbacks[name].indexOf(callback);
9353
+ if (index !== -1) {
9354
+ playerCallbacks[name].splice(index, 1);
9355
+ }
9356
+ callbackMap.set(player.element, playerCallbacks);
9357
+ return playerCallbacks[name] && playerCallbacks[name].length === 0;
9358
+ }
9359
+
9360
+ /**
9361
+ * Return the first stored callback for a player and event or method.
9362
+ *
9363
+ * @param {Player} player The player object.
9364
+ * @param {string} name The method or event name.
9365
+ * @return {function} The callback, or false if there were none
9366
+ */
9367
+ function shiftCallbacks(player, name) {
9368
+ const playerCallbacks = getCallbacks(player, name);
9369
+ if (playerCallbacks.length < 1) {
9370
+ return false;
9371
+ }
9372
+ const callback = playerCallbacks.shift();
9373
+ removeCallback(player, name, callback);
9374
+ return callback;
9375
+ }
9376
+
9377
+ /**
9378
+ * Move callbacks associated with an element to another element.
9379
+ *
9380
+ * @param {HTMLElement} oldElement The old element.
9381
+ * @param {HTMLElement} newElement The new element.
9382
+ * @return {void}
9383
+ */
9384
+ function swapCallbacks(oldElement, newElement) {
9385
+ const playerCallbacks = callbackMap.get(oldElement);
9386
+ callbackMap.set(newElement, playerCallbacks);
9387
+ callbackMap.delete(oldElement);
9388
+ }
9389
+
9390
+ /**
9391
+ * @module lib/postmessage
9392
+ */
9393
+
9394
+ /**
9395
+ * Parse a message received from postMessage.
9396
+ *
9397
+ * @param {*} data The data received from postMessage.
9398
+ * @return {object}
9399
+ */
9400
+ function parseMessageData(data) {
9401
+ if (typeof data === 'string') {
9402
+ try {
9403
+ data = JSON.parse(data);
9404
+ } catch (error) {
9405
+ // If the message cannot be parsed, throw the error as a warning
9406
+ console.warn(error);
9407
+ return {};
9408
+ }
9409
+ }
9410
+ return data;
9411
+ }
9412
+
9413
+ /**
9414
+ * Post a message to the specified target.
9415
+ *
9416
+ * @param {Player} player The player object to use.
9417
+ * @param {string} method The API method to call.
9418
+ * @param {string|number|object|Array|undefined} params The parameters to send to the player.
9419
+ * @return {void}
9420
+ */
9421
+ function postMessage(player, method, params) {
9422
+ if (!player.element.contentWindow || !player.element.contentWindow.postMessage) {
9423
+ return;
9424
+ }
9425
+ let message = {
9426
+ method
9427
+ };
9428
+ if (params !== undefined) {
9429
+ message.value = params;
9430
+ }
9431
+
9432
+ // IE 8 and 9 do not support passing messages, so stringify them
9433
+ const ieVersion = parseFloat(navigator.userAgent.toLowerCase().replace(/^.*msie (\d+).*$/, '$1'));
9434
+ if (ieVersion >= 8 && ieVersion < 10) {
9435
+ message = JSON.stringify(message);
9436
+ }
9437
+ player.element.contentWindow.postMessage(message, player.origin);
9438
+ }
9439
+
9440
+ /**
9441
+ * Parse the data received from a message event.
9442
+ *
9443
+ * @param {Player} player The player that received the message.
9444
+ * @param {(Object|string)} data The message data. Strings will be parsed into JSON.
9445
+ * @return {void}
9446
+ */
9447
+ function processData(player, data) {
9448
+ data = parseMessageData(data);
9449
+ let callbacks = [];
9450
+ let param;
9451
+ if (data.event) {
9452
+ if (data.event === 'error') {
9453
+ const promises = getCallbacks(player, data.data.method);
9454
+ promises.forEach(promise => {
9455
+ const error = new Error(data.data.message);
9456
+ error.name = data.data.name;
9457
+ promise.reject(error);
9458
+ removeCallback(player, data.data.method, promise);
9459
+ });
9460
+ }
9461
+ callbacks = getCallbacks(player, `event:${data.event}`);
9462
+ param = data.data;
9463
+ } else if (data.method) {
9464
+ const callback = shiftCallbacks(player, data.method);
9465
+ if (callback) {
9466
+ callbacks.push(callback);
9467
+ param = data.value;
9468
+ }
9469
+ }
9470
+ callbacks.forEach(callback => {
9471
+ try {
9472
+ if (typeof callback === 'function') {
9473
+ callback.call(player, param);
9474
+ return;
9475
+ }
9476
+ callback.resolve(param);
9477
+ } catch (e) {
9478
+ // empty
9479
+ }
9480
+ });
9481
+ }
9482
+
9483
+ /**
9484
+ * @module lib/embed
9485
+ */
9486
+ const oEmbedParameters = ['airplay', 'audio_tracks', 'audiotrack', 'autopause', 'autoplay', 'background', 'byline', 'cc', 'chapter_id', 'chapters', 'chromecast', 'color', 'colors', 'controls', 'disable_context_menu', 'dnt', 'end_time', 'fullscreen', 'height', 'id', 'initial_quality', 'interactive_params', 'keyboard', 'loop', 'maxheight', 'max_quality', 'maxwidth', 'min_quality', 'muted', 'play_button_position', 'playsinline', 'portrait', 'preload', 'progress_bar', 'quality', 'quality_selector', 'responsive', 'skipping_forward', 'speed', 'start_time', 'texttrack', 'thumbnail_id', 'title', 'transcript', 'transparent', 'unmute_button', 'url', 'vimeo_logo', 'volume', 'watch_full_video', 'width'];
9487
+
9488
+ /**
9489
+ * Get the 'data-vimeo'-prefixed attributes from an element as an object.
9490
+ *
9491
+ * @param {HTMLElement} element The element.
9492
+ * @param {Object} [defaults={}] The default values to use.
9493
+ * @return {Object<string, string>}
9494
+ */
9495
+ function getOEmbedParameters(element) {
9496
+ let defaults = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9497
+ return oEmbedParameters.reduce((params, param) => {
9498
+ const value = element.getAttribute(`data-vimeo-${param}`);
9499
+ if (value || value === '') {
9500
+ params[param] = value === '' ? 1 : value;
9501
+ }
9502
+ return params;
9503
+ }, defaults);
9504
+ }
9505
+
9506
+ /**
9507
+ * Create an embed from oEmbed data inside an element.
9508
+ *
9509
+ * @param {object} data The oEmbed data.
9510
+ * @param {HTMLElement} element The element to put the iframe in.
9511
+ * @return {HTMLIFrameElement} The iframe embed.
9512
+ */
9513
+ function createEmbed(_ref, element) {
9514
+ let {
9515
+ html
9516
+ } = _ref;
9517
+ if (!element) {
9518
+ throw new TypeError('An element must be provided');
9519
+ }
9520
+ if (element.getAttribute('data-vimeo-initialized') !== null) {
9521
+ return element.querySelector('iframe');
9522
+ }
9523
+ const div = document.createElement('div');
9524
+ div.innerHTML = html;
9525
+ element.appendChild(div.firstChild);
9526
+ element.setAttribute('data-vimeo-initialized', 'true');
9527
+ return element.querySelector('iframe');
9528
+ }
9529
+
9530
+ /**
9531
+ * Make an oEmbed call for the specified URL.
9532
+ *
9533
+ * @param {string} videoUrl The vimeo.com url for the video.
9534
+ * @param {Object} [params] Parameters to pass to oEmbed.
9535
+ * @param {HTMLElement} element The element.
9536
+ * @return {Promise}
9537
+ */
9538
+ function getOEmbedData(videoUrl) {
9539
+ let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9540
+ let element = arguments.length > 2 ? arguments[2] : undefined;
9541
+ return new Promise((resolve, reject) => {
9542
+ if (!isVimeoUrl(videoUrl)) {
9543
+ throw new TypeError(`“${videoUrl}” is not a vimeo.com url.`);
9544
+ }
9545
+ const domain = getOembedDomain(videoUrl);
9546
+ let url = `https://${domain}/api/oembed.json?url=${encodeURIComponent(videoUrl)}`;
9547
+ for (const param in params) {
9548
+ if (params.hasOwnProperty(param)) {
9549
+ url += `&${param}=${encodeURIComponent(params[param])}`;
9550
+ }
9551
+ }
9552
+ const xhr = 'XDomainRequest' in window ? new XDomainRequest() : new XMLHttpRequest();
9553
+ xhr.open('GET', url, true);
9554
+ xhr.onload = function () {
9555
+ if (xhr.status === 404) {
9556
+ reject(new Error(`“${videoUrl}” was not found.`));
9557
+ return;
9558
+ }
9559
+ if (xhr.status === 403) {
9560
+ reject(new Error(`“${videoUrl}” is not embeddable.`));
9561
+ return;
9562
+ }
9563
+ try {
9564
+ const json = JSON.parse(xhr.responseText);
9565
+ // Check api response for 403 on oembed
9566
+ if (json.domain_status_code === 403) {
9567
+ // We still want to create the embed to give users visual feedback
9568
+ createEmbed(json, element);
9569
+ reject(new Error(`“${videoUrl}” is not embeddable.`));
9570
+ return;
9571
+ }
9572
+ resolve(json);
9573
+ } catch (error) {
9574
+ reject(error);
9575
+ }
9576
+ };
9577
+ xhr.onerror = function () {
9578
+ const status = xhr.status ? ` (${xhr.status})` : '';
9579
+ reject(new Error(`There was an error fetching the embed code from Vimeo${status}.`));
9580
+ };
9581
+ xhr.send();
9582
+ });
9583
+ }
9584
+
9585
+ /**
9586
+ * Initialize all embeds within a specific element
9587
+ *
9588
+ * @param {HTMLElement} [parent=document] The parent element.
9589
+ * @return {void}
9590
+ */
9591
+ function initializeEmbeds() {
9592
+ let parent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
9593
+ const elements = [].slice.call(parent.querySelectorAll('[data-vimeo-id], [data-vimeo-url]'));
9594
+ const handleError = error => {
9595
+ if ('console' in window && console.error) {
9596
+ console.error(`There was an error creating an embed: ${error}`);
9597
+ }
9598
+ };
9599
+ elements.forEach(element => {
9600
+ try {
9601
+ // Skip any that have data-vimeo-defer
9602
+ if (element.getAttribute('data-vimeo-defer') !== null) {
9603
+ return;
9604
+ }
9605
+ const params = getOEmbedParameters(element);
9606
+ const url = getVimeoUrl(params);
9607
+ getOEmbedData(url, params, element).then(data => {
9608
+ return createEmbed(data, element);
9609
+ }).catch(handleError);
9610
+ } catch (error) {
9611
+ handleError(error);
9612
+ }
9613
+ });
9614
+ }
9615
+
9616
+ /**
9617
+ * Resize embeds when messaged by the player.
9618
+ *
9619
+ * @param {HTMLElement} [parent=document] The parent element.
9620
+ * @return {void}
9621
+ */
9622
+ function resizeEmbeds() {
9623
+ let parent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
9624
+ // Prevent execution if users include the player.js script multiple times.
9625
+ if (window.VimeoPlayerResizeEmbeds_) {
9626
+ return;
9627
+ }
9628
+ window.VimeoPlayerResizeEmbeds_ = true;
9629
+ const onMessage = event => {
9630
+ if (!isVimeoUrl(event.origin)) {
9631
+ return;
9632
+ }
9633
+
9634
+ // 'spacechange' is fired only on embeds with cards
9635
+ if (!event.data || event.data.event !== 'spacechange') {
9636
+ return;
9637
+ }
9638
+ const senderIFrame = event.source ? findIframeBySourceWindow(event.source, parent) : null;
9639
+ if (senderIFrame) {
9640
+ // Change padding-bottom of the enclosing div to accommodate
9641
+ // card carousel without distorting aspect ratio
9642
+ const space = senderIFrame.parentElement;
9643
+ space.style.paddingBottom = `${event.data.data[0].bottom}px`;
9644
+ }
9645
+ };
9646
+ window.addEventListener('message', onMessage);
9647
+ }
9648
+
9649
+ /**
9650
+ * Add chapters to existing metadata for Google SEO
9651
+ *
9652
+ * @param {HTMLElement} [parent=document] The parent element.
9653
+ * @return {void}
9654
+ */
9655
+ function initAppendVideoMetadata() {
9656
+ let parent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
9657
+ // Prevent execution if users include the player.js script multiple times.
9658
+ if (window.VimeoSeoMetadataAppended) {
9659
+ return;
9660
+ }
9661
+ window.VimeoSeoMetadataAppended = true;
9662
+ const onMessage = event => {
9663
+ if (!isVimeoUrl(event.origin)) {
9664
+ return;
9665
+ }
9666
+ const data = parseMessageData(event.data);
9667
+ if (!data || data.event !== 'ready') {
9668
+ return;
9669
+ }
9670
+ const senderIFrame = event.source ? findIframeBySourceWindow(event.source, parent) : null;
9671
+
9672
+ // Initiate appendVideoMetadata if iframe is a Vimeo embed
9673
+ if (senderIFrame && isVimeoEmbed(senderIFrame.src)) {
9674
+ const player = new Player(senderIFrame);
9675
+ player.callMethod('appendVideoMetadata', window.location.href);
9676
+ }
9677
+ };
9678
+ window.addEventListener('message', onMessage);
9679
+ }
9680
+
9681
+ /**
9682
+ * Seek to time indicated by vimeo_t query parameter if present in URL
9683
+ *
9684
+ * @param {HTMLElement} [parent=document] The parent element.
9685
+ * @return {void}
9686
+ */
9687
+ function checkUrlTimeParam() {
9688
+ let parent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
9689
+ // Prevent execution if users include the player.js script multiple times.
9690
+ if (window.VimeoCheckedUrlTimeParam) {
9691
+ return;
9692
+ }
9693
+ window.VimeoCheckedUrlTimeParam = true;
9694
+ const handleError = error => {
9695
+ if ('console' in window && console.error) {
9696
+ console.error(`There was an error getting video Id: ${error}`);
9697
+ }
9698
+ };
9699
+ const onMessage = event => {
9700
+ if (!isVimeoUrl(event.origin)) {
9701
+ return;
9702
+ }
9703
+ const data = parseMessageData(event.data);
9704
+ if (!data || data.event !== 'ready') {
9705
+ return;
9706
+ }
9707
+ const senderIFrame = event.source ? findIframeBySourceWindow(event.source, parent) : null;
9708
+ if (senderIFrame && isVimeoEmbed(senderIFrame.src)) {
9709
+ const player = new Player(senderIFrame);
9710
+ player.getVideoId().then(videoId => {
9711
+ const matches = new RegExp(`[?&]vimeo_t_${videoId}=([^&#]*)`).exec(window.location.href);
9712
+ if (matches && matches[1]) {
9713
+ const sec = decodeURI(matches[1]);
9714
+ player.setCurrentTime(sec);
9715
+ }
9716
+ return;
9717
+ }).catch(handleError);
9718
+ }
9719
+ };
9720
+ window.addEventListener('message', onMessage);
9721
+ }
9722
+
9723
+ /**
9724
+ * Updates iframe embeds to support DRM content playback by adding the 'encrypted-media' permission
9725
+ * to the iframe's allow attribute when DRM initialization fails. This function acts as a fallback
9726
+ * mechanism to enable playback of DRM-protected content in embeds that weren't properly configured.
9727
+ *
9728
+ * @return {void}
9729
+ */
9730
+ function updateDRMEmbeds() {
9731
+ if (window.VimeoDRMEmbedsUpdated) {
9732
+ return;
9733
+ }
9734
+ window.VimeoDRMEmbedsUpdated = true;
9735
+
9736
+ /**
9737
+ * Handle message events for DRM initialization failures
9738
+ * @param {MessageEvent} event - The message event from the iframe
9739
+ */
9740
+ const onMessage = event => {
9741
+ if (!isVimeoUrl(event.origin)) {
9742
+ return;
9743
+ }
9744
+ const data = parseMessageData(event.data);
9745
+ if (!data || data.event !== 'drminitfailed') {
9746
+ return;
9747
+ }
9748
+ const senderIFrame = event.source ? findIframeBySourceWindow(event.source) : null;
9749
+ if (!senderIFrame) {
9750
+ return;
9751
+ }
9752
+ const currentAllow = senderIFrame.getAttribute('allow') || '';
9753
+ const allowSupportsDRM = currentAllow.includes('encrypted-media');
9754
+ if (!allowSupportsDRM) {
9755
+ // For DRM playback to successfully occur, the iframe `allow` attribute must include 'encrypted-media'.
9756
+ // If the video requires DRM but doesn't have the attribute, we try to add on behalf of the embed owner
9757
+ // as a temporary measure to enable playback until they're able to update their embeds.
9758
+ senderIFrame.setAttribute('allow', `${currentAllow}; encrypted-media`);
9759
+ const currentUrl = new URL(senderIFrame.getAttribute('src'));
9760
+
9761
+ // Adding this forces the embed to reload once `allow` has been updated with `encrypted-media`.
9762
+ currentUrl.searchParams.set('forcereload', 'drm');
9763
+ senderIFrame.setAttribute('src', currentUrl.toString());
9764
+ return;
9765
+ }
9766
+ };
9767
+ window.addEventListener('message', onMessage);
9768
+ }
9769
+
9770
+ /* MIT License
9771
+
9772
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
9773
+
9774
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9775
+
9776
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9777
+
9778
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9779
+ Terms */
9780
+
9781
+ function initializeScreenfull() {
9782
+ const fn = function () {
9783
+ let val;
9784
+ const fnMap = [['requestFullscreen', 'exitFullscreen', 'fullscreenElement', 'fullscreenEnabled', 'fullscreenchange', 'fullscreenerror'],
9785
+ // New WebKit
9786
+ ['webkitRequestFullscreen', 'webkitExitFullscreen', 'webkitFullscreenElement', 'webkitFullscreenEnabled', 'webkitfullscreenchange', 'webkitfullscreenerror'],
9787
+ // Old WebKit
9788
+ ['webkitRequestFullScreen', 'webkitCancelFullScreen', 'webkitCurrentFullScreenElement', 'webkitCancelFullScreen', 'webkitfullscreenchange', 'webkitfullscreenerror'], ['mozRequestFullScreen', 'mozCancelFullScreen', 'mozFullScreenElement', 'mozFullScreenEnabled', 'mozfullscreenchange', 'mozfullscreenerror'], ['msRequestFullscreen', 'msExitFullscreen', 'msFullscreenElement', 'msFullscreenEnabled', 'MSFullscreenChange', 'MSFullscreenError']];
9789
+ let i = 0;
9790
+ const l = fnMap.length;
9791
+ const ret = {};
9792
+ for (; i < l; i++) {
9793
+ val = fnMap[i];
9794
+ if (val && val[1] in document) {
9795
+ for (i = 0; i < val.length; i++) {
9796
+ ret[fnMap[0][i]] = val[i];
9797
+ }
9798
+ return ret;
9799
+ }
9800
+ }
9801
+ return false;
9802
+ }();
9803
+ const eventNameMap = {
9804
+ fullscreenchange: fn.fullscreenchange,
9805
+ fullscreenerror: fn.fullscreenerror
9806
+ };
9807
+ const screenfull = {
9808
+ request(element) {
9809
+ return new Promise((resolve, reject) => {
9810
+ const onFullScreenEntered = function () {
9811
+ screenfull.off('fullscreenchange', onFullScreenEntered);
9812
+ resolve();
9813
+ };
9814
+ screenfull.on('fullscreenchange', onFullScreenEntered);
9815
+ element = element || document.documentElement;
9816
+ const returnPromise = element[fn.requestFullscreen]();
9817
+ if (returnPromise instanceof Promise) {
9818
+ returnPromise.then(onFullScreenEntered).catch(reject);
9819
+ }
9820
+ });
9821
+ },
9822
+ exit() {
9823
+ return new Promise((resolve, reject) => {
9824
+ if (!screenfull.isFullscreen) {
9825
+ resolve();
9826
+ return;
9827
+ }
9828
+ const onFullScreenExit = function () {
9829
+ screenfull.off('fullscreenchange', onFullScreenExit);
9830
+ resolve();
9831
+ };
9832
+ screenfull.on('fullscreenchange', onFullScreenExit);
9833
+ const returnPromise = document[fn.exitFullscreen]();
9834
+ if (returnPromise instanceof Promise) {
9835
+ returnPromise.then(onFullScreenExit).catch(reject);
9836
+ }
9837
+ });
9838
+ },
9839
+ on(event, callback) {
9840
+ const eventName = eventNameMap[event];
9841
+ if (eventName) {
9842
+ document.addEventListener(eventName, callback);
9843
+ }
9844
+ },
9845
+ off(event, callback) {
9846
+ const eventName = eventNameMap[event];
9847
+ if (eventName) {
9848
+ document.removeEventListener(eventName, callback);
9849
+ }
9850
+ }
9851
+ };
9852
+ Object.defineProperties(screenfull, {
9853
+ isFullscreen: {
9854
+ get() {
9855
+ return Boolean(document[fn.fullscreenElement]);
9856
+ }
9857
+ },
9858
+ element: {
9859
+ enumerable: true,
9860
+ get() {
9861
+ return document[fn.fullscreenElement];
9862
+ }
9863
+ },
9864
+ isEnabled: {
9865
+ enumerable: true,
9866
+ get() {
9867
+ // Coerce to boolean in case of old WebKit
9868
+ return Boolean(document[fn.fullscreenEnabled]);
9869
+ }
9870
+ }
9871
+ });
9872
+ return screenfull;
9873
+ }
9874
+
9875
+ /** @typedef {import('./timing-src-connector.types').PlayerControls} PlayerControls */
9876
+ /** @typedef {import('timing-object').ITimingObject} TimingObject */
9877
+ /** @typedef {import('./timing-src-connector.types').TimingSrcConnectorOptions} TimingSrcConnectorOptions */
9878
+ /** @typedef {(msg: string) => any} Logger */
9879
+ /** @typedef {import('timing-object').TConnectionState} TConnectionState */
9880
+
9881
+ /**
9882
+ * @type {TimingSrcConnectorOptions}
9883
+ *
9884
+ * For details on these properties and their effects, see the typescript definition referenced above.
9885
+ */
9886
+ const defaultOptions = {
9887
+ role: 'viewer',
9888
+ autoPlayMuted: true,
9889
+ allowedDrift: 0.3,
9890
+ maxAllowedDrift: 1,
9891
+ minCheckInterval: 0.1,
9892
+ maxRateAdjustment: 0.2,
9893
+ maxTimeToCatchUp: 1
9894
+ };
9895
+
9896
+ /**
9897
+ * There's a proposed W3C spec for the Timing Object which would introduce a new set of APIs that would simplify time-synchronization tasks for browser applications.
9898
+ *
9899
+ * Proposed spec: https://webtiming.github.io/timingobject/
9900
+ * V3 Spec: https://timingsrc.readthedocs.io/en/latest/
9901
+ * Demuxed talk: https://www.youtube.com/watch?v=cZSjDaGDmX8
9902
+ *
9903
+ * This class makes it easy to connect Vimeo.Player to a provided TimingObject via Vimeo.Player.setTimingSrc(myTimingObject, options) and the synchronization will be handled automatically.
9904
+ *
9905
+ * There are 5 general responsibilities in TimingSrcConnector:
9906
+ *
9907
+ * 1. `updatePlayer()` which sets the player's currentTime, playbackRate and pause/play state based on current state of the TimingObject.
9908
+ * 2. `updateTimingObject()` which sets the TimingObject's position and velocity from the player's state.
9909
+ * 3. `playerUpdater` which listens for change events on the TimingObject and will respond by calling updatePlayer.
9910
+ * 4. `timingObjectUpdater` which listens to the player events of seeked, play and pause and will respond by calling `updateTimingObject()`.
9911
+ * 5. `maintainPlaybackPosition` this is code that constantly monitors the player to make sure it's always in sync with the TimingObject. This is needed because videos will generally not play with precise time accuracy and there will be some drift which becomes more noticeable over longer periods (as noted in the timing-object spec). More details on this method below.
9912
+ */
9913
+ class TimingSrcConnector extends EventTarget {
9914
+ logger;
9915
+
9916
+ /**
9917
+ * @param {PlayerControls} player
9918
+ * @param {TimingObject} timingObject
9919
+ * @param {TimingSrcConnectorOptions} options
9920
+ * @param {Logger} logger
9921
+ */
9922
+ constructor(player, timingObject) {
9923
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
9924
+ let logger = arguments.length > 3 ? arguments[3] : undefined;
9925
+ super();
9926
+ this.logger = logger;
9927
+ this.init(timingObject, player, {
9928
+ ...defaultOptions,
9929
+ ...options
9930
+ });
9931
+ }
9932
+ disconnect() {
9933
+ this.dispatchEvent(new Event('disconnect'));
9934
+ }
9935
+
9936
+ /**
9937
+ * @param {TimingObject} timingObject
9938
+ * @param {PlayerControls} player
9939
+ * @param {TimingSrcConnectorOptions} options
9940
+ * @return {Promise<void>}
9941
+ */
9942
+ async init(timingObject, player, options) {
9943
+ await this.waitForTOReadyState(timingObject, 'open');
9944
+ if (options.role === 'viewer') {
9945
+ await this.updatePlayer(timingObject, player, options);
9946
+ const playerUpdater = subscribe(timingObject, 'change', () => this.updatePlayer(timingObject, player, options));
9947
+ const positionSync = this.maintainPlaybackPosition(timingObject, player, options);
9948
+ this.addEventListener('disconnect', () => {
9949
+ positionSync.cancel();
9950
+ playerUpdater.cancel();
9951
+ });
9952
+ } else {
9953
+ await this.updateTimingObject(timingObject, player);
9954
+ const timingObjectUpdater = subscribe(player, ['seeked', 'play', 'pause', 'ratechange'], () => this.updateTimingObject(timingObject, player), 'on', 'off');
9955
+ this.addEventListener('disconnect', () => timingObjectUpdater.cancel());
9956
+ }
9957
+ }
9958
+
9959
+ /**
9960
+ * Sets the TimingObject's state to reflect that of the player
9961
+ *
9962
+ * @param {TimingObject} timingObject
9963
+ * @param {PlayerControls} player
9964
+ * @return {Promise<void>}
9965
+ */
9966
+ async updateTimingObject(timingObject, player) {
9967
+ const [position, isPaused, playbackRate] = await Promise.all([player.getCurrentTime(), player.getPaused(), player.getPlaybackRate()]);
9968
+ timingObject.update({
9969
+ position,
9970
+ velocity: isPaused ? 0 : playbackRate
9971
+ });
9972
+ }
9973
+
9974
+ /**
9975
+ * Sets the player's timing state to reflect that of the TimingObject
9976
+ *
9977
+ * @param {TimingObject} timingObject
9978
+ * @param {PlayerControls} player
9979
+ * @param {TimingSrcConnectorOptions} options
9980
+ * @return {Promise<void>}
9981
+ */
9982
+ async updatePlayer(timingObject, player, options) {
9983
+ const {
9984
+ position,
9985
+ velocity
9986
+ } = timingObject.query();
9987
+ if (typeof position === 'number') {
9988
+ player.setCurrentTime(position);
9989
+ }
9990
+ if (typeof velocity === 'number') {
9991
+ if (velocity === 0) {
9992
+ if ((await player.getPaused()) === false) {
9993
+ player.pause();
9994
+ }
9995
+ } else if (velocity > 0) {
9996
+ if ((await player.getPaused()) === true) {
9997
+ await player.play().catch(async err => {
9998
+ if (err.name === 'NotAllowedError' && options.autoPlayMuted) {
9999
+ await player.setMuted(true);
10000
+ await player.play().catch(err2 => console.error('Couldn\'t play the video from TimingSrcConnector. Error:', err2));
10001
+ }
10002
+ });
10003
+ this.updatePlayer(timingObject, player, options);
10004
+ }
10005
+ if ((await player.getPlaybackRate()) !== velocity) {
10006
+ player.setPlaybackRate(velocity);
10007
+ }
10008
+ }
10009
+ }
10010
+ }
10011
+
10012
+ /**
10013
+ * Since video players do not play with 100% time precision, we need to closely monitor
10014
+ * our player to be sure it remains in sync with the TimingObject.
10015
+ *
10016
+ * If out of sync, we use the current conditions and the options provided to determine
10017
+ * whether to re-sync via setting currentTime or adjusting the playbackRate
10018
+ *
10019
+ * @param {TimingObject} timingObject
10020
+ * @param {PlayerControls} player
10021
+ * @param {TimingSrcConnectorOptions} options
10022
+ * @return {{cancel: (function(): void)}}
10023
+ */
10024
+ maintainPlaybackPosition(timingObject, player, options) {
10025
+ const {
10026
+ allowedDrift,
10027
+ maxAllowedDrift,
10028
+ minCheckInterval,
10029
+ maxRateAdjustment,
10030
+ maxTimeToCatchUp
10031
+ } = options;
10032
+ const syncInterval = Math.min(maxTimeToCatchUp, Math.max(minCheckInterval, maxAllowedDrift)) * 1000;
10033
+ const check = async () => {
10034
+ if (timingObject.query().velocity === 0 || (await player.getPaused()) === true) {
10035
+ return;
10036
+ }
10037
+ const diff = timingObject.query().position - (await player.getCurrentTime());
10038
+ const diffAbs = Math.abs(diff);
10039
+ this.log(`Drift: ${diff}`);
10040
+ if (diffAbs > maxAllowedDrift) {
10041
+ await this.adjustSpeed(player, 0);
10042
+ player.setCurrentTime(timingObject.query().position);
10043
+ this.log('Resync by currentTime');
10044
+ } else if (diffAbs > allowedDrift) {
10045
+ const min = diffAbs / maxTimeToCatchUp;
10046
+ const max = maxRateAdjustment;
10047
+ const adjustment = min < max ? (max - min) / 2 : max;
10048
+ await this.adjustSpeed(player, adjustment * Math.sign(diff));
10049
+ this.log('Resync by playbackRate');
10050
+ }
10051
+ };
10052
+ const interval = setInterval(() => check(), syncInterval);
10053
+ return {
10054
+ cancel: () => clearInterval(interval)
10055
+ };
10056
+ }
10057
+
10058
+ /**
10059
+ * @param {string} msg
10060
+ */
10061
+ log(msg) {
10062
+ this.logger?.(`TimingSrcConnector: ${msg}`);
10063
+ }
10064
+ speedAdjustment = 0;
10065
+
10066
+ /**
10067
+ * @param {PlayerControls} player
10068
+ * @param {number} newAdjustment
10069
+ * @return {Promise<void>}
10070
+ */
10071
+ adjustSpeed = async (player, newAdjustment) => {
10072
+ if (this.speedAdjustment === newAdjustment) {
10073
+ return;
10074
+ }
10075
+ const newPlaybackRate = (await player.getPlaybackRate()) - this.speedAdjustment + newAdjustment;
10076
+ this.log(`New playbackRate: ${newPlaybackRate}`);
10077
+ await player.setPlaybackRate(newPlaybackRate);
10078
+ this.speedAdjustment = newAdjustment;
10079
+ };
10080
+
10081
+ /**
10082
+ * @param {TimingObject} timingObject
10083
+ * @param {TConnectionState} state
10084
+ * @return {Promise<void>}
10085
+ */
10086
+ waitForTOReadyState(timingObject, state) {
10087
+ return new Promise(resolve => {
10088
+ const check = () => {
10089
+ if (timingObject.readyState === state) {
10090
+ resolve();
10091
+ } else {
10092
+ timingObject.addEventListener('readystatechange', check, {
10093
+ once: true
10094
+ });
10095
+ }
10096
+ };
10097
+ check();
10098
+ });
10099
+ }
10100
+ }
10101
+
10102
+ const playerMap = new WeakMap();
10103
+ const readyMap = new WeakMap();
10104
+ let screenfull = {};
10105
+ class Player {
10106
+ /**
10107
+ * Create a Player.
10108
+ *
10109
+ * @param {(HTMLIFrameElement|HTMLElement|string|jQuery)} element A reference to the Vimeo
10110
+ * player iframe, and id, or a jQuery object.
10111
+ * @param {object} [options] oEmbed parameters to use when creating an embed in the element.
10112
+ * @return {Player}
10113
+ */
10114
+ constructor(element) {
10115
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10116
+ /* global jQuery */
10117
+ if (window.jQuery && element instanceof jQuery) {
10118
+ if (element.length > 1 && window.console && console.warn) {
10119
+ console.warn('A jQuery object with multiple elements was passed, using the first element.');
10120
+ }
10121
+ element = element[0];
10122
+ }
10123
+
10124
+ // Find an element by ID
10125
+ if (typeof document !== 'undefined' && typeof element === 'string') {
10126
+ element = document.getElementById(element);
10127
+ }
10128
+
10129
+ // Not an element!
10130
+ if (!isDomElement(element)) {
10131
+ throw new TypeError('You must pass either a valid element or a valid id.');
10132
+ }
10133
+
10134
+ // Already initialized an embed in this div, so grab the iframe
10135
+ if (element.nodeName !== 'IFRAME') {
10136
+ const iframe = element.querySelector('iframe');
10137
+ if (iframe) {
10138
+ element = iframe;
10139
+ }
10140
+ }
10141
+
10142
+ // iframe url is not a Vimeo url
10143
+ if (element.nodeName === 'IFRAME' && !isVimeoUrl(element.getAttribute('src') || '')) {
10144
+ throw new Error('The player element passed isn’t a Vimeo embed.');
10145
+ }
10146
+
10147
+ // If there is already a player object in the map, return that
10148
+ if (playerMap.has(element)) {
10149
+ return playerMap.get(element);
10150
+ }
10151
+ this._window = element.ownerDocument.defaultView;
10152
+ this.element = element;
10153
+ this.origin = '*';
10154
+ const readyPromise = new npo_src((resolve, reject) => {
10155
+ this._onMessage = event => {
10156
+ if (!isVimeoUrl(event.origin) || this.element.contentWindow !== event.source) {
10157
+ return;
10158
+ }
10159
+ if (this.origin === '*') {
10160
+ this.origin = event.origin;
10161
+ }
10162
+ const data = parseMessageData(event.data);
10163
+ const isError = data && data.event === 'error';
10164
+ const isReadyError = isError && data.data && data.data.method === 'ready';
10165
+ if (isReadyError) {
10166
+ const error = new Error(data.data.message);
10167
+ error.name = data.data.name;
10168
+ reject(error);
10169
+ return;
10170
+ }
10171
+ const isReadyEvent = data && data.event === 'ready';
10172
+ const isPingResponse = data && data.method === 'ping';
10173
+ if (isReadyEvent || isPingResponse) {
10174
+ this.element.setAttribute('data-ready', 'true');
10175
+ resolve();
10176
+ return;
10177
+ }
10178
+ processData(this, data);
10179
+ };
10180
+ this._window.addEventListener('message', this._onMessage);
10181
+ if (this.element.nodeName !== 'IFRAME') {
10182
+ const params = getOEmbedParameters(element, options);
10183
+ const url = getVimeoUrl(params);
10184
+ getOEmbedData(url, params, element).then(data => {
10185
+ const iframe = createEmbed(data, element);
10186
+ // Overwrite element with the new iframe,
10187
+ // but store reference to the original element
10188
+ this.element = iframe;
10189
+ this._originalElement = element;
10190
+ swapCallbacks(element, iframe);
10191
+ playerMap.set(this.element, this);
10192
+ return data;
10193
+ }).catch(reject);
10194
+ }
10195
+ });
10196
+
10197
+ // Store a copy of this Player in the map
10198
+ readyMap.set(this, readyPromise);
10199
+ playerMap.set(this.element, this);
10200
+
10201
+ // Send a ping to the iframe so the ready promise will be resolved if
10202
+ // the player is already ready.
10203
+ if (this.element.nodeName === 'IFRAME') {
10204
+ postMessage(this, 'ping');
10205
+ }
10206
+ if (screenfull.isEnabled) {
10207
+ const exitFullscreen = () => screenfull.exit();
10208
+ this.fullscreenchangeHandler = () => {
10209
+ if (screenfull.isFullscreen) {
10210
+ storeCallback(this, 'event:exitFullscreen', exitFullscreen);
10211
+ } else {
10212
+ removeCallback(this, 'event:exitFullscreen', exitFullscreen);
10213
+ }
10214
+ // eslint-disable-next-line
10215
+ this.ready().then(() => {
10216
+ postMessage(this, 'fullscreenchange', screenfull.isFullscreen);
10217
+ });
10218
+ };
10219
+ screenfull.on('fullscreenchange', this.fullscreenchangeHandler);
10220
+ }
10221
+ return this;
10222
+ }
10223
+
10224
+ /**
10225
+ * Check to see if the URL is a Vimeo URL.
10226
+ *
10227
+ * @param {string} url The URL string.
10228
+ * @return {boolean}
10229
+ */
10230
+ static isVimeoUrl(url) {
10231
+ return isVimeoUrl(url);
10232
+ }
10233
+
10234
+ /**
10235
+ * Get a promise for a method.
10236
+ *
10237
+ * @param {string} name The API method to call.
10238
+ * @param {...(string|number|object|Array)} args Arguments to send via postMessage.
10239
+ * @return {Promise}
10240
+ */
10241
+ callMethod(name) {
10242
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
10243
+ args[_key - 1] = arguments[_key];
10244
+ }
10245
+ if (name === undefined || name === null) {
10246
+ throw new TypeError('You must pass a method name.');
10247
+ }
10248
+ return new npo_src((resolve, reject) => {
10249
+ // We are storing the resolve/reject handlers to call later, so we
10250
+ // can’t return here.
10251
+ return this.ready().then(() => {
10252
+ storeCallback(this, name, {
10253
+ resolve,
10254
+ reject
10255
+ });
10256
+ if (args.length === 0) {
10257
+ args = {};
10258
+ } else if (args.length === 1) {
10259
+ args = args[0];
10260
+ }
10261
+ postMessage(this, name, args);
10262
+ }).catch(reject);
10263
+ });
10264
+ }
10265
+ /**
10266
+ * Get a promise for the value of a player property.
10267
+ *
10268
+ * @param {string} name The property name
10269
+ * @return {Promise}
10270
+ */
10271
+ get(name) {
10272
+ return new npo_src((resolve, reject) => {
10273
+ name = getMethodName(name, 'get');
10274
+
10275
+ // We are storing the resolve/reject handlers to call later, so we
10276
+ // can’t return here.
10277
+ return this.ready().then(() => {
10278
+ storeCallback(this, name, {
10279
+ resolve,
10280
+ reject
10281
+ });
10282
+ postMessage(this, name);
10283
+ }).catch(reject);
10284
+ });
10285
+ }
10286
+
10287
+ /**
10288
+ * Get a promise for setting the value of a player property.
10289
+ *
10290
+ * @param {string} name The API method to call.
10291
+ * @param {mixed} value The value to set.
10292
+ * @return {Promise}
10293
+ */
10294
+ set(name, value) {
10295
+ return new npo_src((resolve, reject) => {
10296
+ name = getMethodName(name, 'set');
10297
+ if (value === undefined || value === null) {
10298
+ throw new TypeError('There must be a value to set.');
10299
+ }
10300
+
10301
+ // We are storing the resolve/reject handlers to call later, so we
10302
+ // can’t return here.
10303
+ return this.ready().then(() => {
10304
+ storeCallback(this, name, {
10305
+ resolve,
10306
+ reject
10307
+ });
10308
+ postMessage(this, name, value);
10309
+ }).catch(reject);
10310
+ });
10311
+ }
10312
+
10313
+ /**
10314
+ * Add an event listener for the specified event. Will call the
10315
+ * callback with a single parameter, `data`, that contains the data for
10316
+ * that event.
10317
+ *
10318
+ * @param {string} eventName The name of the event.
10319
+ * @param {function(*)} callback The function to call when the event fires.
10320
+ * @return {void}
10321
+ */
10322
+ on(eventName, callback) {
10323
+ if (!eventName) {
10324
+ throw new TypeError('You must pass an event name.');
10325
+ }
10326
+ if (!callback) {
10327
+ throw new TypeError('You must pass a callback function.');
10328
+ }
10329
+ if (typeof callback !== 'function') {
10330
+ throw new TypeError('The callback must be a function.');
10331
+ }
10332
+ const callbacks = getCallbacks(this, `event:${eventName}`);
10333
+ if (callbacks.length === 0) {
10334
+ this.callMethod('addEventListener', eventName).catch(() => {
10335
+ // Ignore the error. There will be an error event fired that
10336
+ // will trigger the error callback if they are listening.
10337
+ });
10338
+ }
10339
+ storeCallback(this, `event:${eventName}`, callback);
10340
+ }
10341
+
10342
+ /**
10343
+ * Remove an event listener for the specified event. Will remove all
10344
+ * listeners for that event if a `callback` isn’t passed, or only that
10345
+ * specific callback if it is passed.
10346
+ *
10347
+ * @param {string} eventName The name of the event.
10348
+ * @param {function} [callback] The specific callback to remove.
10349
+ * @return {void}
10350
+ */
10351
+ off(eventName, callback) {
10352
+ if (!eventName) {
10353
+ throw new TypeError('You must pass an event name.');
10354
+ }
10355
+ if (callback && typeof callback !== 'function') {
10356
+ throw new TypeError('The callback must be a function.');
10357
+ }
10358
+ const lastCallback = removeCallback(this, `event:${eventName}`, callback);
10359
+
10360
+ // If there are no callbacks left, remove the listener
10361
+ if (lastCallback) {
10362
+ this.callMethod('removeEventListener', eventName).catch(e => {
10363
+ // Ignore the error. There will be an error event fired that
10364
+ // will trigger the error callback if they are listening.
10365
+ });
10366
+ }
10367
+ }
10368
+
10369
+ /**
10370
+ * A promise to load a new video.
10371
+ *
10372
+ * @promise LoadVideoPromise
10373
+ * @fulfill {number} The video with this id or url successfully loaded.
10374
+ * @reject {TypeError} The id was not a number.
10375
+ */
10376
+ /**
10377
+ * Load a new video into this embed. The promise will be resolved if
10378
+ * the video is successfully loaded, or it will be rejected if it could
10379
+ * not be loaded.
10380
+ *
10381
+ * @param {number|string|object} options The id of the video, the url of the video, or an object with embed options.
10382
+ * @return {LoadVideoPromise}
10383
+ */
10384
+ loadVideo(options) {
10385
+ return this.callMethod('loadVideo', options);
10386
+ }
10387
+
10388
+ /**
10389
+ * A promise to perform an action when the Player is ready.
10390
+ *
10391
+ * @todo document errors
10392
+ * @promise LoadVideoPromise
10393
+ * @fulfill {void}
10394
+ */
10395
+ /**
10396
+ * Trigger a function when the player iframe has initialized. You do not
10397
+ * need to wait for `ready` to trigger to begin adding event listeners
10398
+ * or calling other methods.
10399
+ *
10400
+ * @return {ReadyPromise}
10401
+ */
10402
+ ready() {
10403
+ const readyPromise = readyMap.get(this) || new npo_src((resolve, reject) => {
10404
+ reject(new Error('Unknown player. Probably unloaded.'));
10405
+ });
10406
+ return npo_src.resolve(readyPromise);
10407
+ }
10408
+
10409
+ /**
10410
+ * A promise to add a cue point to the player.
10411
+ *
10412
+ * @promise AddCuePointPromise
10413
+ * @fulfill {string} The id of the cue point to use for removeCuePoint.
10414
+ * @reject {RangeError} the time was less than 0 or greater than the
10415
+ * video’s duration.
10416
+ * @reject {UnsupportedError} Cue points are not supported with the current
10417
+ * player or browser.
10418
+ */
10419
+ /**
10420
+ * Add a cue point to the player.
10421
+ *
10422
+ * @param {number} time The time for the cue point.
10423
+ * @param {object} [data] Arbitrary data to be returned with the cue point.
10424
+ * @return {AddCuePointPromise}
10425
+ */
10426
+ addCuePoint(time) {
10427
+ let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10428
+ return this.callMethod('addCuePoint', {
10429
+ time,
10430
+ data
10431
+ });
10432
+ }
10433
+
10434
+ /**
10435
+ * A promise to remove a cue point from the player.
10436
+ *
10437
+ * @promise AddCuePointPromise
10438
+ * @fulfill {string} The id of the cue point that was removed.
10439
+ * @reject {InvalidCuePoint} The cue point with the specified id was not
10440
+ * found.
10441
+ * @reject {UnsupportedError} Cue points are not supported with the current
10442
+ * player or browser.
10443
+ */
10444
+ /**
10445
+ * Remove a cue point from the video.
10446
+ *
10447
+ * @param {string} id The id of the cue point to remove.
10448
+ * @return {RemoveCuePointPromise}
10449
+ */
10450
+ removeCuePoint(id) {
10451
+ return this.callMethod('removeCuePoint', id);
10452
+ }
10453
+
10454
+ /**
10455
+ * A representation of a text track on a video.
10456
+ *
10457
+ * @typedef {Object} VimeoTextTrack
10458
+ * @property {string} language The ISO language code.
10459
+ * @property {string} kind The kind of track it is (captions or subtitles).
10460
+ * @property {string} label The human‐readable label for the track.
10461
+ */
10462
+ /**
10463
+ * A promise to enable a text track.
10464
+ *
10465
+ * @promise EnableTextTrackPromise
10466
+ * @fulfill {VimeoTextTrack} The text track that was enabled.
10467
+ * @reject {InvalidTrackLanguageError} No track was available with the
10468
+ * specified language.
10469
+ * @reject {InvalidTrackError} No track was available with the specified
10470
+ * language and kind.
10471
+ */
10472
+ /**
10473
+ * Enable the text track with the specified language, and optionally the
10474
+ * specified kind (captions or subtitles).
10475
+ *
10476
+ * When set via the API, the track language will not change the viewer’s
10477
+ * stored preference.
10478
+ *
10479
+ * @param {string} language The two‐letter language code.
10480
+ * @param {string} [kind] The kind of track to enable (captions or subtitles).
10481
+ * @param {boolean} [showing] Whether to enable display of closed captions for enabled text track within the player.
10482
+ * @return {EnableTextTrackPromise}
10483
+ */
10484
+ enableTextTrack(language) {
10485
+ let kind = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
10486
+ let showing = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
10487
+ if (!language) {
10488
+ throw new TypeError('You must pass a language.');
10489
+ }
10490
+ return this.callMethod('enableTextTrack', {
10491
+ language,
10492
+ kind,
10493
+ showing
10494
+ });
10495
+ }
10496
+
10497
+ /**
10498
+ * A promise to disable the active text track.
10499
+ *
10500
+ * @promise DisableTextTrackPromise
10501
+ * @fulfill {void} The track was disabled.
10502
+ */
10503
+ /**
10504
+ * Disable the currently-active text track.
10505
+ *
10506
+ * @return {DisableTextTrackPromise}
10507
+ */
10508
+ disableTextTrack() {
10509
+ return this.callMethod('disableTextTrack');
10510
+ }
10511
+
10512
+ /** @typedef {import('../types/formats.js').VimeoAudioTrack} VimeoAudioTrack */
10513
+ /** @typedef {import('../types/formats.js').AudioLanguage} AudioLanguage */
10514
+ /** @typedef {import('../types/formats.js').AudioKind} AudioKind */
10515
+ /**
10516
+ * A promise to enable an audio track.
10517
+ *
10518
+ * @promise SelectAudioTrackPromise
10519
+ * @fulfill {VimeoAudioTrack} The audio track that was enabled.
10520
+ * @reject {NoAudioTracksError} No audio exists for the video.
10521
+ * @reject {NoAlternateAudioTracksError} No alternate audio tracks exist for the video.
10522
+ * @reject {NoMatchingAudioTrackError} No track was available with the specified
10523
+ * language and kind.
10524
+ */
10525
+ /**
10526
+ * Enable the audio track with the specified language, and optionally the
10527
+ * specified kind (main, translation, descriptions, or commentary).
10528
+ *
10529
+ * When set via the API, the track language will not change the viewer’s
10530
+ * stored preference.
10531
+ *
10532
+ * @param {AudioLanguage} language The two‐letter language code.
10533
+ * @param {AudioKind} [kind] The kind of track to enable (main, translation, descriptions, commentary).
10534
+ * @return {SelectAudioTrackPromise}
10535
+ */
10536
+ selectAudioTrack(language, kind) {
10537
+ if (!language) {
10538
+ throw new TypeError('You must pass a language.');
10539
+ }
10540
+ return this.callMethod('selectAudioTrack', {
10541
+ language,
10542
+ kind
10543
+ });
10544
+ }
10545
+
10546
+ /**
10547
+ * Enable the main audio track for the video.
10548
+ *
10549
+ * @return {SelectAudioTrackPromise}
10550
+ */
10551
+ selectDefaultAudioTrack() {
10552
+ return this.callMethod('selectDefaultAudioTrack');
10553
+ }
10554
+
10555
+ /**
10556
+ * A promise to pause the video.
10557
+ *
10558
+ * @promise PausePromise
10559
+ * @fulfill {void} The video was paused.
10560
+ */
10561
+ /**
10562
+ * Pause the video if it’s playing.
10563
+ *
10564
+ * @return {PausePromise}
10565
+ */
10566
+ pause() {
10567
+ return this.callMethod('pause');
10568
+ }
10569
+
10570
+ /**
10571
+ * A promise to play the video.
10572
+ *
10573
+ * @promise PlayPromise
10574
+ * @fulfill {void} The video was played.
10575
+ */
10576
+ /**
10577
+ * Play the video if it’s paused. **Note:** on iOS and some other
10578
+ * mobile devices, you cannot programmatically trigger play. Once the
10579
+ * viewer has tapped on the play button in the player, however, you
10580
+ * will be able to use this function.
10581
+ *
10582
+ * @return {PlayPromise}
10583
+ */
10584
+ play() {
10585
+ return this.callMethod('play');
10586
+ }
10587
+
10588
+ /**
10589
+ * Request that the player enters fullscreen.
10590
+ * @return {Promise}
10591
+ */
10592
+ requestFullscreen() {
10593
+ if (screenfull.isEnabled) {
10594
+ return screenfull.request(this.element);
10595
+ }
10596
+ return this.callMethod('requestFullscreen');
10597
+ }
10598
+
10599
+ /**
10600
+ * Request that the player exits fullscreen.
10601
+ * @return {Promise}
10602
+ */
10603
+ exitFullscreen() {
10604
+ if (screenfull.isEnabled) {
10605
+ return screenfull.exit();
10606
+ }
10607
+ return this.callMethod('exitFullscreen');
10608
+ }
10609
+
10610
+ /**
10611
+ * Returns true if the player is currently fullscreen.
10612
+ * @return {Promise}
10613
+ */
10614
+ getFullscreen() {
10615
+ if (screenfull.isEnabled) {
10616
+ return npo_src.resolve(screenfull.isFullscreen);
10617
+ }
10618
+ return this.get('fullscreen');
10619
+ }
10620
+
10621
+ /**
10622
+ * Request that the player enters picture-in-picture.
10623
+ * @return {Promise}
10624
+ */
10625
+ requestPictureInPicture() {
10626
+ return this.callMethod('requestPictureInPicture');
10627
+ }
10628
+
10629
+ /**
10630
+ * Request that the player exits picture-in-picture.
10631
+ * @return {Promise}
10632
+ */
10633
+ exitPictureInPicture() {
10634
+ return this.callMethod('exitPictureInPicture');
10635
+ }
10636
+
10637
+ /**
10638
+ * Returns true if the player is currently picture-in-picture.
10639
+ * @return {Promise}
10640
+ */
10641
+ getPictureInPicture() {
10642
+ return this.get('pictureInPicture');
10643
+ }
10644
+
10645
+ /**
10646
+ * A promise to prompt the viewer to initiate remote playback.
10647
+ *
10648
+ * @promise RemotePlaybackPromptPromise
10649
+ * @fulfill {void}
10650
+ * @reject {NotFoundError} No remote playback device is available.
10651
+ */
10652
+ /**
10653
+ * Request to prompt the user to initiate remote playback.
10654
+ *
10655
+ * @return {RemotePlaybackPromptPromise}
10656
+ */
10657
+ remotePlaybackPrompt() {
10658
+ return this.callMethod('remotePlaybackPrompt');
10659
+ }
10660
+
10661
+ /**
10662
+ * A promise to unload the video.
10663
+ *
10664
+ * @promise UnloadPromise
10665
+ * @fulfill {void} The video was unloaded.
10666
+ */
10667
+ /**
10668
+ * Return the player to its initial state.
10669
+ *
10670
+ * @return {UnloadPromise}
10671
+ */
10672
+ unload() {
10673
+ return this.callMethod('unload');
10674
+ }
10675
+
10676
+ /**
10677
+ * Cleanup the player and remove it from the DOM
10678
+ *
10679
+ * It won't be usable and a new one should be constructed
10680
+ * in order to do any operations.
10681
+ *
10682
+ * @return {Promise}
10683
+ */
10684
+ destroy() {
10685
+ return new npo_src(resolve => {
10686
+ readyMap.delete(this);
10687
+ playerMap.delete(this.element);
10688
+ if (this._originalElement) {
10689
+ playerMap.delete(this._originalElement);
10690
+ this._originalElement.removeAttribute('data-vimeo-initialized');
10691
+ }
10692
+ if (this.element && this.element.nodeName === 'IFRAME' && this.element.parentNode) {
10693
+ // If we've added an additional wrapper div, remove that from the DOM.
10694
+ // If not, just remove the iframe element.
10695
+ if (this.element.parentNode.parentNode && this._originalElement && this._originalElement !== this.element.parentNode) {
10696
+ this.element.parentNode.parentNode.removeChild(this.element.parentNode);
10697
+ } else {
10698
+ this.element.parentNode.removeChild(this.element);
10699
+ }
10700
+ }
10701
+
10702
+ // If the clip is private there is a case where the element stays the
10703
+ // div element. Destroy should reset the div and remove the iframe child.
10704
+ if (this.element && this.element.nodeName === 'DIV' && this.element.parentNode) {
10705
+ this.element.removeAttribute('data-vimeo-initialized');
10706
+ const iframe = this.element.querySelector('iframe');
10707
+ if (iframe && iframe.parentNode) {
10708
+ // If we've added an additional wrapper div, remove that from the DOM.
10709
+ // If not, just remove the iframe element.
10710
+ if (iframe.parentNode.parentNode && this._originalElement && this._originalElement !== iframe.parentNode) {
10711
+ iframe.parentNode.parentNode.removeChild(iframe.parentNode);
10712
+ } else {
10713
+ iframe.parentNode.removeChild(iframe);
10714
+ }
10715
+ }
10716
+ }
10717
+ this._window.removeEventListener('message', this._onMessage);
10718
+ if (screenfull.isEnabled) {
10719
+ screenfull.off('fullscreenchange', this.fullscreenchangeHandler);
10720
+ }
10721
+ resolve();
10722
+ });
10723
+ }
10724
+
10725
+ /**
10726
+ * A promise to get the autopause behavior of the video.
10727
+ *
10728
+ * @promise GetAutopausePromise
10729
+ * @fulfill {boolean} Whether autopause is turned on or off.
10730
+ * @reject {UnsupportedError} Autopause is not supported with the current
10731
+ * player or browser.
10732
+ */
10733
+ /**
10734
+ * Get the autopause behavior for this player.
10735
+ *
10736
+ * @return {GetAutopausePromise}
10737
+ */
10738
+ getAutopause() {
10739
+ return this.get('autopause');
10740
+ }
10741
+
10742
+ /**
10743
+ * A promise to set the autopause behavior of the video.
10744
+ *
10745
+ * @promise SetAutopausePromise
10746
+ * @fulfill {boolean} Whether autopause is turned on or off.
10747
+ * @reject {UnsupportedError} Autopause is not supported with the current
10748
+ * player or browser.
10749
+ */
10750
+ /**
10751
+ * Enable or disable the autopause behavior of this player.
10752
+ *
10753
+ * By default, when another video is played in the same browser, this
10754
+ * player will automatically pause. Unless you have a specific reason
10755
+ * for doing so, we recommend that you leave autopause set to the
10756
+ * default (`true`).
10757
+ *
10758
+ * @param {boolean} autopause
10759
+ * @return {SetAutopausePromise}
10760
+ */
10761
+ setAutopause(autopause) {
10762
+ return this.set('autopause', autopause);
10763
+ }
10764
+
10765
+ /**
10766
+ * A promise to get the buffered property of the video.
10767
+ *
10768
+ * @promise GetBufferedPromise
10769
+ * @fulfill {Array} Buffered Timeranges converted to an Array.
10770
+ */
10771
+ /**
10772
+ * Get the buffered property of the video.
10773
+ *
10774
+ * @return {GetBufferedPromise}
10775
+ */
10776
+ getBuffered() {
10777
+ return this.get('buffered');
10778
+ }
10779
+
10780
+ /**
10781
+ * @typedef {Object} CameraProperties
10782
+ * @prop {number} props.yaw - Number between 0 and 360.
10783
+ * @prop {number} props.pitch - Number between -90 and 90.
10784
+ * @prop {number} props.roll - Number between -180 and 180.
10785
+ * @prop {number} props.fov - The field of view in degrees.
10786
+ */
10787
+ /**
10788
+ * A promise to get the camera properties of the player.
10789
+ *
10790
+ * @promise GetCameraPromise
10791
+ * @fulfill {CameraProperties} The camera properties.
10792
+ */
10793
+ /**
10794
+ * For 360° videos get the camera properties for this player.
10795
+ *
10796
+ * @return {GetCameraPromise}
10797
+ */
10798
+ getCameraProps() {
10799
+ return this.get('cameraProps');
10800
+ }
10801
+
10802
+ /**
10803
+ * A promise to set the camera properties of the player.
10804
+ *
10805
+ * @promise SetCameraPromise
10806
+ * @fulfill {Object} The camera was successfully set.
10807
+ * @reject {RangeError} The range was out of bounds.
10808
+ */
10809
+ /**
10810
+ * For 360° videos set the camera properties for this player.
10811
+ *
10812
+ * @param {CameraProperties} camera The camera properties
10813
+ * @return {SetCameraPromise}
10814
+ */
10815
+ setCameraProps(camera) {
10816
+ return this.set('cameraProps', camera);
10817
+ }
10818
+
10819
+ /**
10820
+ * A representation of a chapter.
10821
+ *
10822
+ * @typedef {Object} VimeoChapter
10823
+ * @property {number} startTime The start time of the chapter.
10824
+ * @property {object} title The title of the chapter.
10825
+ * @property {number} index The place in the order of Chapters. Starts at 1.
10826
+ */
10827
+ /**
10828
+ * A promise to get chapters for the video.
10829
+ *
10830
+ * @promise GetChaptersPromise
10831
+ * @fulfill {VimeoChapter[]} The chapters for the video.
10832
+ */
10833
+ /**
10834
+ * Get an array of all the chapters for the video.
10835
+ *
10836
+ * @return {GetChaptersPromise}
10837
+ */
10838
+ getChapters() {
10839
+ return this.get('chapters');
10840
+ }
10841
+
10842
+ /**
10843
+ * A promise to get the currently active chapter.
10844
+ *
10845
+ * @promise GetCurrentChaptersPromise
10846
+ * @fulfill {VimeoChapter|undefined} The current chapter for the video.
10847
+ */
10848
+ /**
10849
+ * Get the currently active chapter for the video.
10850
+ *
10851
+ * @return {GetCurrentChaptersPromise}
10852
+ */
10853
+ getCurrentChapter() {
10854
+ return this.get('currentChapter');
10855
+ }
10856
+
10857
+ /**
10858
+ * A promise to get the accent color of the player.
10859
+ *
10860
+ * @promise GetColorPromise
10861
+ * @fulfill {string} The hex color of the player.
10862
+ */
10863
+ /**
10864
+ * Get the accent color for this player. Note this is deprecated in place of `getColorTwo`.
10865
+ *
10866
+ * @return {GetColorPromise}
10867
+ */
10868
+ getColor() {
10869
+ return this.get('color');
10870
+ }
10871
+
10872
+ /**
10873
+ * A promise to get all colors for the player in an array.
10874
+ *
10875
+ * @promise GetColorsPromise
10876
+ * @fulfill {string[]} The hex colors of the player.
10877
+ */
10878
+ /**
10879
+ * Get all the colors for this player in an array: [colorOne, colorTwo, colorThree, colorFour]
10880
+ *
10881
+ * @return {GetColorPromise}
10882
+ */
10883
+ getColors() {
10884
+ return npo_src.all([this.get('colorOne'), this.get('colorTwo'), this.get('colorThree'), this.get('colorFour')]);
10885
+ }
10886
+
10887
+ /**
10888
+ * A promise to set the accent color of the player.
10889
+ *
10890
+ * @promise SetColorPromise
10891
+ * @fulfill {string} The color was successfully set.
10892
+ * @reject {TypeError} The string was not a valid hex or rgb color.
10893
+ * @reject {ContrastError} The color was set, but the contrast is
10894
+ * outside of the acceptable range.
10895
+ * @reject {EmbedSettingsError} The owner of the player has chosen to
10896
+ * use a specific color.
10897
+ */
10898
+ /**
10899
+ * Set the accent color of this player to a hex or rgb string. Setting the
10900
+ * color may fail if the owner of the video has set their embed
10901
+ * preferences to force a specific color.
10902
+ * Note this is deprecated in place of `setColorTwo`.
10903
+ *
10904
+ * @param {string} color The hex or rgb color string to set.
10905
+ * @return {SetColorPromise}
10906
+ */
10907
+ setColor(color) {
10908
+ return this.set('color', color);
10909
+ }
10910
+
10911
+ /**
10912
+ * A promise to set all colors for the player.
10913
+ *
10914
+ * @promise SetColorsPromise
10915
+ * @fulfill {string[]} The colors were successfully set.
10916
+ * @reject {TypeError} The string was not a valid hex or rgb color.
10917
+ * @reject {ContrastError} The color was set, but the contrast is
10918
+ * outside of the acceptable range.
10919
+ * @reject {EmbedSettingsError} The owner of the player has chosen to
10920
+ * use a specific color.
10921
+ */
10922
+ /**
10923
+ * Set the colors of this player to a hex or rgb string. Setting the
10924
+ * color may fail if the owner of the video has set their embed
10925
+ * preferences to force a specific color.
10926
+ * The colors should be passed in as an array: [colorOne, colorTwo, colorThree, colorFour].
10927
+ * If a color should not be set, the index in the array can be left as null.
10928
+ *
10929
+ * @param {string[]} colors Array of the hex or rgb color strings to set.
10930
+ * @return {SetColorsPromise}
10931
+ */
10932
+ setColors(colors) {
10933
+ if (!Array.isArray(colors)) {
10934
+ return new npo_src((resolve, reject) => reject(new TypeError('Argument must be an array.')));
10935
+ }
10936
+ const nullPromise = new npo_src(resolve => resolve(null));
10937
+ const colorPromises = [colors[0] ? this.set('colorOne', colors[0]) : nullPromise, colors[1] ? this.set('colorTwo', colors[1]) : nullPromise, colors[2] ? this.set('colorThree', colors[2]) : nullPromise, colors[3] ? this.set('colorFour', colors[3]) : nullPromise];
10938
+ return npo_src.all(colorPromises);
10939
+ }
10940
+
10941
+ /**
10942
+ * A representation of a cue point.
10943
+ *
10944
+ * @typedef {Object} VimeoCuePoint
10945
+ * @property {number} time The time of the cue point.
10946
+ * @property {object} data The data passed when adding the cue point.
10947
+ * @property {string} id The unique id for use with removeCuePoint.
10948
+ */
10949
+ /**
10950
+ * A promise to get the cue points of a video.
10951
+ *
10952
+ * @promise GetCuePointsPromise
10953
+ * @fulfill {VimeoCuePoint[]} The cue points added to the video.
10954
+ * @reject {UnsupportedError} Cue points are not supported with the current
10955
+ * player or browser.
10956
+ */
10957
+ /**
10958
+ * Get an array of the cue points added to the video.
10959
+ *
10960
+ * @return {GetCuePointsPromise}
10961
+ */
10962
+ getCuePoints() {
10963
+ return this.get('cuePoints');
10964
+ }
10965
+
10966
+ /**
10967
+ * A promise to get the current time of the video.
10968
+ *
10969
+ * @promise GetCurrentTimePromise
10970
+ * @fulfill {number} The current time in seconds.
10971
+ */
10972
+ /**
10973
+ * Get the current playback position in seconds.
10974
+ *
10975
+ * @return {GetCurrentTimePromise}
10976
+ */
10977
+ getCurrentTime() {
10978
+ return this.get('currentTime');
10979
+ }
10980
+
10981
+ /**
10982
+ * A promise to set the current time of the video.
10983
+ *
10984
+ * @promise SetCurrentTimePromise
10985
+ * @fulfill {number} The actual current time that was set.
10986
+ * @reject {RangeError} the time was less than 0 or greater than the
10987
+ * video’s duration.
10988
+ */
10989
+ /**
10990
+ * Set the current playback position in seconds. If the player was
10991
+ * paused, it will remain paused. Likewise, if the player was playing,
10992
+ * it will resume playing once the video has buffered.
10993
+ *
10994
+ * You can provide an accurate time and the player will attempt to seek
10995
+ * to as close to that time as possible. The exact time will be the
10996
+ * fulfilled value of the promise.
10997
+ *
10998
+ * @param {number} currentTime
10999
+ * @return {SetCurrentTimePromise}
11000
+ */
11001
+ setCurrentTime(currentTime) {
11002
+ return this.set('currentTime', currentTime);
11003
+ }
11004
+
11005
+ /**
11006
+ * A promise to get the duration of the video.
11007
+ *
11008
+ * @promise GetDurationPromise
11009
+ * @fulfill {number} The duration in seconds.
11010
+ */
11011
+ /**
11012
+ * Get the duration of the video in seconds. It will be rounded to the
11013
+ * nearest second before playback begins, and to the nearest thousandth
11014
+ * of a second after playback begins.
11015
+ *
11016
+ * @return {GetDurationPromise}
11017
+ */
11018
+ getDuration() {
11019
+ return this.get('duration');
11020
+ }
11021
+
11022
+ /**
11023
+ * A promise to get the ended state of the video.
11024
+ *
11025
+ * @promise GetEndedPromise
11026
+ * @fulfill {boolean} Whether or not the video has ended.
11027
+ */
11028
+ /**
11029
+ * Get the ended state of the video. The video has ended if
11030
+ * `currentTime === duration`.
11031
+ *
11032
+ * @return {GetEndedPromise}
11033
+ */
11034
+ getEnded() {
11035
+ return this.get('ended');
11036
+ }
11037
+
11038
+ /**
11039
+ * A promise to get the loop state of the player.
11040
+ *
11041
+ * @promise GetLoopPromise
11042
+ * @fulfill {boolean} Whether or not the player is set to loop.
11043
+ */
11044
+ /**
11045
+ * Get the loop state of the player.
11046
+ *
11047
+ * @return {GetLoopPromise}
11048
+ */
11049
+ getLoop() {
11050
+ return this.get('loop');
11051
+ }
11052
+
11053
+ /**
11054
+ * A promise to set the loop state of the player.
11055
+ *
11056
+ * @promise SetLoopPromise
11057
+ * @fulfill {boolean} The loop state that was set.
11058
+ */
11059
+ /**
11060
+ * Set the loop state of the player. When set to `true`, the player
11061
+ * will start over immediately once playback ends.
11062
+ *
11063
+ * @param {boolean} loop
11064
+ * @return {SetLoopPromise}
11065
+ */
11066
+ setLoop(loop) {
11067
+ return this.set('loop', loop);
11068
+ }
11069
+
11070
+ /**
11071
+ * A promise to set the muted state of the player.
11072
+ *
11073
+ * @promise SetMutedPromise
11074
+ * @fulfill {boolean} The muted state that was set.
11075
+ */
11076
+ /**
11077
+ * Set the muted state of the player. When set to `true`, the player
11078
+ * volume will be muted.
11079
+ *
11080
+ * @param {boolean} muted
11081
+ * @return {SetMutedPromise}
11082
+ */
11083
+ setMuted(muted) {
11084
+ return this.set('muted', muted);
11085
+ }
11086
+
11087
+ /**
11088
+ * A promise to get the muted state of the player.
11089
+ *
11090
+ * @promise GetMutedPromise
11091
+ * @fulfill {boolean} Whether or not the player is muted.
11092
+ */
11093
+ /**
11094
+ * Get the muted state of the player.
11095
+ *
11096
+ * @return {GetMutedPromise}
11097
+ */
11098
+ getMuted() {
11099
+ return this.get('muted');
11100
+ }
11101
+
11102
+ /**
11103
+ * A promise to get the paused state of the player.
11104
+ *
11105
+ * @promise GetLoopPromise
11106
+ * @fulfill {boolean} Whether or not the video is paused.
11107
+ */
11108
+ /**
11109
+ * Get the paused state of the player.
11110
+ *
11111
+ * @return {GetLoopPromise}
11112
+ */
11113
+ getPaused() {
11114
+ return this.get('paused');
11115
+ }
11116
+
11117
+ /**
11118
+ * A promise to get the playback rate of the player.
11119
+ *
11120
+ * @promise GetPlaybackRatePromise
11121
+ * @fulfill {number} The playback rate of the player on a scale from 0 to 2.
11122
+ */
11123
+ /**
11124
+ * Get the playback rate of the player on a scale from `0` to `2`.
11125
+ *
11126
+ * @return {GetPlaybackRatePromise}
11127
+ */
11128
+ getPlaybackRate() {
11129
+ return this.get('playbackRate');
11130
+ }
11131
+
11132
+ /**
11133
+ * A promise to set the playbackrate of the player.
11134
+ *
11135
+ * @promise SetPlaybackRatePromise
11136
+ * @fulfill {number} The playback rate was set.
11137
+ * @reject {RangeError} The playback rate was less than 0 or greater than 2.
11138
+ */
11139
+ /**
11140
+ * Set the playback rate of the player on a scale from `0` to `2`. When set
11141
+ * via the API, the playback rate will not be synchronized to other
11142
+ * players or stored as the viewer's preference.
11143
+ *
11144
+ * @param {number} playbackRate
11145
+ * @return {SetPlaybackRatePromise}
11146
+ */
11147
+ setPlaybackRate(playbackRate) {
11148
+ return this.set('playbackRate', playbackRate);
11149
+ }
11150
+
11151
+ /**
11152
+ * A promise to get the played property of the video.
11153
+ *
11154
+ * @promise GetPlayedPromise
11155
+ * @fulfill {Array} Played Timeranges converted to an Array.
11156
+ */
11157
+ /**
11158
+ * Get the played property of the video.
11159
+ *
11160
+ * @return {GetPlayedPromise}
11161
+ */
11162
+ getPlayed() {
11163
+ return this.get('played');
11164
+ }
11165
+
11166
+ /**
11167
+ * A promise to get the qualities available of the current video.
11168
+ *
11169
+ * @promise GetQualitiesPromise
11170
+ * @fulfill {Array} The qualities of the video.
11171
+ */
11172
+ /**
11173
+ * Get the qualities of the current video.
11174
+ *
11175
+ * @return {GetQualitiesPromise}
11176
+ */
11177
+ getQualities() {
11178
+ return this.get('qualities');
11179
+ }
11180
+
11181
+ /**
11182
+ * A promise to get the current set quality of the video.
11183
+ *
11184
+ * @promise GetQualityPromise
11185
+ * @fulfill {string} The current set quality.
11186
+ */
11187
+ /**
11188
+ * Get the current set quality of the video.
11189
+ *
11190
+ * @return {GetQualityPromise}
11191
+ */
11192
+ getQuality() {
11193
+ return this.get('quality');
11194
+ }
11195
+
11196
+ /**
11197
+ * A promise to set the video quality.
11198
+ *
11199
+ * @promise SetQualityPromise
11200
+ * @fulfill {number} The quality was set.
11201
+ * @reject {RangeError} The quality is not available.
11202
+ */
11203
+ /**
11204
+ * Set a video quality.
11205
+ *
11206
+ * @param {string} quality
11207
+ * @return {SetQualityPromise}
11208
+ */
11209
+ setQuality(quality) {
11210
+ return this.set('quality', quality);
11211
+ }
11212
+
11213
+ /**
11214
+ * A promise to get the remote playback availability.
11215
+ *
11216
+ * @promise RemotePlaybackAvailabilityPromise
11217
+ * @fulfill {boolean} Whether remote playback is available.
11218
+ */
11219
+ /**
11220
+ * Get the availability of remote playback.
11221
+ *
11222
+ * @return {RemotePlaybackAvailabilityPromise}
11223
+ */
11224
+ getRemotePlaybackAvailability() {
11225
+ return this.get('remotePlaybackAvailability');
11226
+ }
11227
+
11228
+ /**
11229
+ * A promise to get the current remote playback state.
11230
+ *
11231
+ * @promise RemotePlaybackStatePromise
11232
+ * @fulfill {string} The state of the remote playback: connecting, connected, or disconnected.
11233
+ */
11234
+ /**
11235
+ * Get the current remote playback state.
11236
+ *
11237
+ * @return {RemotePlaybackStatePromise}
11238
+ */
11239
+ getRemotePlaybackState() {
11240
+ return this.get('remotePlaybackState');
11241
+ }
11242
+
11243
+ /**
11244
+ * A promise to get the seekable property of the video.
11245
+ *
11246
+ * @promise GetSeekablePromise
11247
+ * @fulfill {Array} Seekable Timeranges converted to an Array.
11248
+ */
11249
+ /**
11250
+ * Get the seekable property of the video.
11251
+ *
11252
+ * @return {GetSeekablePromise}
11253
+ */
11254
+ getSeekable() {
11255
+ return this.get('seekable');
11256
+ }
11257
+
11258
+ /**
11259
+ * A promise to get the seeking property of the player.
11260
+ *
11261
+ * @promise GetSeekingPromise
11262
+ * @fulfill {boolean} Whether or not the player is currently seeking.
11263
+ */
11264
+ /**
11265
+ * Get if the player is currently seeking.
11266
+ *
11267
+ * @return {GetSeekingPromise}
11268
+ */
11269
+ getSeeking() {
11270
+ return this.get('seeking');
11271
+ }
11272
+
11273
+ /**
11274
+ * A promise to get the text tracks of a video.
11275
+ *
11276
+ * @promise GetTextTracksPromise
11277
+ * @fulfill {VimeoTextTrack[]} The text tracks associated with the video.
11278
+ */
11279
+ /**
11280
+ * Get an array of the text tracks that exist for the video.
11281
+ *
11282
+ * @return {GetTextTracksPromise}
11283
+ */
11284
+ getTextTracks() {
11285
+ return this.get('textTracks');
11286
+ }
11287
+
11288
+ /**
11289
+ * A promise to get the audio tracks of a video.
11290
+ *
11291
+ * @promise GetAudioTracksPromise
11292
+ * @fulfill {VimeoAudioTrack[]} The audio tracks associated with the video.
11293
+ */
11294
+ /**
11295
+ * Get an array of the audio tracks that exist for the video.
11296
+ *
11297
+ * @return {GetAudioTracksPromise}
11298
+ */
11299
+ getAudioTracks() {
11300
+ return this.get('audioTracks');
11301
+ }
11302
+
11303
+ /**
11304
+ * A promise to get the enabled audio track of a video.
11305
+ *
11306
+ * @promise GetAudioTrackPromise
11307
+ * @fulfill {VimeoAudioTrack} The enabled audio track.
11308
+ */
11309
+ /**
11310
+ * Get the enabled audio track for a video.
11311
+ *
11312
+ * @return {GetAudioTrackPromise}
11313
+ */
11314
+ getEnabledAudioTrack() {
11315
+ return this.get('enabledAudioTrack');
11316
+ }
11317
+
11318
+ /**
11319
+ * Get the main audio track for a video.
11320
+ *
11321
+ * @return {GetAudioTrackPromise}
11322
+ */
11323
+ getDefaultAudioTrack() {
11324
+ return this.get('defaultAudioTrack');
11325
+ }
11326
+
11327
+ /**
11328
+ * A promise to get the embed code for the video.
11329
+ *
11330
+ * @promise GetVideoEmbedCodePromise
11331
+ * @fulfill {string} The `<iframe>` embed code for the video.
11332
+ */
11333
+ /**
11334
+ * Get the `<iframe>` embed code for the video.
11335
+ *
11336
+ * @return {GetVideoEmbedCodePromise}
11337
+ */
11338
+ getVideoEmbedCode() {
11339
+ return this.get('videoEmbedCode');
11340
+ }
11341
+
11342
+ /**
11343
+ * A promise to get the id of the video.
11344
+ *
11345
+ * @promise GetVideoIdPromise
11346
+ * @fulfill {number} The id of the video.
11347
+ */
11348
+ /**
11349
+ * Get the id of the video.
11350
+ *
11351
+ * @return {GetVideoIdPromise}
11352
+ */
11353
+ getVideoId() {
11354
+ return this.get('videoId');
11355
+ }
11356
+
11357
+ /**
11358
+ * A promise to get the title of the video.
11359
+ *
11360
+ * @promise GetVideoTitlePromise
11361
+ * @fulfill {number} The title of the video.
11362
+ */
11363
+ /**
11364
+ * Get the title of the video.
11365
+ *
11366
+ * @return {GetVideoTitlePromise}
11367
+ */
11368
+ getVideoTitle() {
11369
+ return this.get('videoTitle');
11370
+ }
11371
+
11372
+ /**
11373
+ * A promise to get the native width of the video.
11374
+ *
11375
+ * @promise GetVideoWidthPromise
11376
+ * @fulfill {number} The native width of the video.
11377
+ */
11378
+ /**
11379
+ * Get the native width of the currently‐playing video. The width of
11380
+ * the highest‐resolution available will be used before playback begins.
11381
+ *
11382
+ * @return {GetVideoWidthPromise}
11383
+ */
11384
+ getVideoWidth() {
11385
+ return this.get('videoWidth');
11386
+ }
11387
+
11388
+ /**
11389
+ * A promise to get the native height of the video.
11390
+ *
11391
+ * @promise GetVideoHeightPromise
11392
+ * @fulfill {number} The native height of the video.
11393
+ */
11394
+ /**
11395
+ * Get the native height of the currently‐playing video. The height of
11396
+ * the highest‐resolution available will be used before playback begins.
11397
+ *
11398
+ * @return {GetVideoHeightPromise}
11399
+ */
11400
+ getVideoHeight() {
11401
+ return this.get('videoHeight');
11402
+ }
11403
+
11404
+ /**
11405
+ * A promise to get the vimeo.com url for the video.
11406
+ *
11407
+ * @promise GetVideoUrlPromise
11408
+ * @fulfill {number} The vimeo.com url for the video.
11409
+ * @reject {PrivacyError} The url isn’t available because of the video’s privacy setting.
11410
+ */
11411
+ /**
11412
+ * Get the vimeo.com url for the video.
11413
+ *
11414
+ * @return {GetVideoUrlPromise}
11415
+ */
11416
+ getVideoUrl() {
11417
+ return this.get('videoUrl');
11418
+ }
11419
+
11420
+ /**
11421
+ * A promise to get the volume level of the player.
11422
+ *
11423
+ * @promise GetVolumePromise
11424
+ * @fulfill {number} The volume level of the player on a scale from 0 to 1.
11425
+ */
11426
+ /**
11427
+ * Get the current volume level of the player on a scale from `0` to `1`.
11428
+ *
11429
+ * Most mobile devices do not support an independent volume from the
11430
+ * system volume. In those cases, this method will always return `1`.
11431
+ *
11432
+ * @return {GetVolumePromise}
11433
+ */
11434
+ getVolume() {
11435
+ return this.get('volume');
11436
+ }
11437
+
11438
+ /**
11439
+ * A promise to set the volume level of the player.
11440
+ *
11441
+ * @promise SetVolumePromise
11442
+ * @fulfill {number} The volume was set.
11443
+ * @reject {RangeError} The volume was less than 0 or greater than 1.
11444
+ */
11445
+ /**
11446
+ * Set the volume of the player on a scale from `0` to `1`. When set
11447
+ * via the API, the volume level will not be synchronized to other
11448
+ * players or stored as the viewer’s preference.
11449
+ *
11450
+ * Most mobile devices do not support setting the volume. An error will
11451
+ * *not* be triggered in that situation.
11452
+ *
11453
+ * @param {number} volume
11454
+ * @return {SetVolumePromise}
11455
+ */
11456
+ setVolume(volume) {
11457
+ return this.set('volume', volume);
11458
+ }
11459
+
11460
+ /** @typedef {import('timing-object').ITimingObject} TimingObject */
11461
+ /** @typedef {import('./lib/timing-src-connector.types').TimingSrcConnectorOptions} TimingSrcConnectorOptions */
11462
+ /** @typedef {import('./lib/timing-src-connector').TimingSrcConnector} TimingSrcConnector */
11463
+
11464
+ /**
11465
+ * Connects a TimingObject to the video player (https://webtiming.github.io/timingobject/)
11466
+ *
11467
+ * @param {TimingObject} timingObject
11468
+ * @param {TimingSrcConnectorOptions} options
11469
+ *
11470
+ * @return {Promise<TimingSrcConnector>}
11471
+ */
11472
+ async setTimingSrc(timingObject, options) {
11473
+ if (!timingObject) {
11474
+ throw new TypeError('A Timing Object must be provided.');
11475
+ }
11476
+ await this.ready();
11477
+ const connector = new TimingSrcConnector(this, timingObject, options);
11478
+ postMessage(this, 'notifyTimingObjectConnect');
11479
+ connector.addEventListener('disconnect', () => postMessage(this, 'notifyTimingObjectDisconnect'));
11480
+ return connector;
11481
+ }
11482
+ }
11483
+
11484
+ // Setup embed only if this is not a server runtime
11485
+ if (!isServerRuntime) {
11486
+ screenfull = initializeScreenfull();
11487
+ initializeEmbeds();
11488
+ resizeEmbeds();
11489
+ initAppendVideoMetadata();
11490
+ checkUrlTimeParam();
11491
+ updateDRMEmbeds();
11492
+ }
11493
+
11494
+ var player_es = /*#__PURE__*/Object.freeze({
11495
+ __proto__: null,
11496
+ default: Player
11497
+ });
11498
+
8654
11499
  exports.hydrateApp = hydrateApp;
8655
11500
 
8656
11501