media-chrome
Advanced tools
Comparing version 0.6.9-canary.4-59f4ed4 to 0.6.9-canary.5-97d20f7
@@ -1,2 +0,2 @@ | ||
var z=Object.create;var m=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var k=a=>m(a,"__esModule",{value:!0});var at=(a,e)=>{for(var t in e)m(a,t,{get:e[t],enumerable:!0})},y=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Z(e))!et.call(a,r)&&(t||r!=="default")&&m(a,r,{get:()=>e[r],enumerable:!(i=J(e,r))||i.enumerable});return a},it=(a,e)=>y(k(m(a!=null?z(tt(a)):{},"default",!e&&a&&a.__esModule?{get:()=>a.default,enumerable:!0}:{value:a,enumerable:!0})),a),st=(a=>(e,t)=>a&&a.get(e)||(t=y(k({}),e,1),a&&a.set(e,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var At={};at(At,{default:()=>_t,delay:()=>C,getTestMediaEl:()=>v,hasPipSupport:()=>q,hasVolumeSupportAsync:()=>Y});var j=it(require("./media-container.js"),1),K=require("./utils/defineCustomElement.js"),E=require("./utils/server-safe-globals.js"),S=require("./utils/fullscreenApi.js"),U=require("./utils/stringUtils.js"),b=require("./utils/element-utils.js"),s=require("./constants.js"),o=require("./utils/captions.js");const{MEDIA_PLAY_REQUEST:ht,MEDIA_PAUSE_REQUEST:It,MEDIA_MUTE_REQUEST:mt,MEDIA_UNMUTE_REQUEST:Tt,MEDIA_VOLUME_REQUEST:Mt,MEDIA_ENTER_FULLSCREEN_REQUEST:ft,MEDIA_EXIT_FULLSCREEN_REQUEST:Ut,MEDIA_SEEK_REQUEST:bt,MEDIA_PREVIEW_REQUEST:Dt,MEDIA_ENTER_PIP_REQUEST:gt,MEDIA_EXIT_PIP_REQUEST:Rt,MEDIA_PLAYBACK_RATE_REQUEST:Pt}=s.MediaUIEvents;class N extends j.default{constructor(){super();ut||(this._airplayUnavailable=s.AvailabilityStates.UNSUPPORTED),lt||(this._castUnavailable=s.AvailabilityStates.UNSUPPORTED),ct||(this._pipUnavailable=s.AvailabilityStates.UNSUPPORTED),I!==void 0?I||(this._volumeUnavailable=s.AvailabilityStates.UNSUPPORTED):dt.then(()=>{I||(this._volumeUnavailable=s.AvailabilityStates.UNSUPPORTED,this.propagateMediaState(s.MediaUIAttributes.MEDIA_VOLUME_UNAVAILABLE,this._volumeUnavailable))}),this.mediaStateReceivers=[],this.associatedElementSubscriptions=new Map,this.associatedElements=[],this.associateElement(this);const e={MEDIA_PLAY_REQUEST:()=>this.media.play(),MEDIA_PAUSE_REQUEST:()=>this.media.pause(),MEDIA_MUTE_REQUEST:()=>this.media.muted=!0,MEDIA_UNMUTE_REQUEST:()=>{const t=this.media;t.muted=!1,t.volume===0&&(t.volume=.25)},MEDIA_VOLUME_REQUEST:t=>{const i=this.media,r=t.detail;i.volume=r,r>0&&i.muted&&(i.muted=!1);try{E.Window.localStorage.setItem("media-chrome-pref-volume",r.toString())}catch{}},MEDIA_ENTER_FULLSCREEN_REQUEST:()=>{const t=this.media;E.Document.pictureInPictureElement&&E.Document.exitPictureInPicture(),super[S.fullscreenApi.enter]?super[S.fullscreenApi.enter]():t.webkitEnterFullscreen?t.webkitEnterFullscreen():t.requestFullscreen?t.requestFullscreen():console.warn("MediaChrome: Fullscreen not supported")},MEDIA_EXIT_FULLSCREEN_REQUEST:()=>{E.Document[S.fullscreenApi.exit]()},MEDIA_ENTER_PIP_REQUEST:()=>{const t=this.media;!E.Document.pictureInPictureEnabled||(E.Document[S.fullscreenApi.element]&&E.Document[S.fullscreenApi.exit](),t.requestPictureInPicture())},MEDIA_EXIT_PIP_REQUEST:()=>{E.Document.pictureInPictureElement&&E.Document.exitPictureInPicture()},MEDIA_ENTER_CAST_REQUEST:()=>{var i;const t=this.media;!((i=globalThis.CastableVideoElement)==null?void 0:i.castEnabled)||(E.Document[S.fullscreenApi.element]&&E.Document[S.fullscreenApi.exit](),t.requestCast())},MEDIA_EXIT_CAST_REQUEST:async()=>{var t;((t=globalThis.CastableVideoElement)==null?void 0:t.castElement)&&globalThis.CastableVideoElement.exitCast()},MEDIA_SEEK_REQUEST:t=>{const i=this.media,r=t.detail;(i.readyState>0||i.readyState===void 0)&&(i.currentTime=r)},MEDIA_PLAYBACK_RATE_REQUEST:t=>{this.media.playbackRate=t.detail},MEDIA_PREVIEW_REQUEST:t=>{var l;const i=this.media;if(!i)return;const[r]=(0,o.getTextTracksList)(i,{kind:s.TextTrackKinds.METADATA,label:"thumbnails"});if(!(r&&r.cues))return;const n=t.detail;if(n===null){this.propagateMediaState(s.MediaUIAttributes.MEDIA_PREVIEW_IMAGE,void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_PREVIEW_COORDS,void 0);return}const d=Array.prototype.find.call(r.cues,p=>p.startTime>=n);if(!d)return;const A=/'^(?:[a-z]+:)?\/\//i.test(d.text)||(l=i.querySelector('track[label="thumbnails"]'))==null?void 0:l.src,u=new URL(d.text,A),_=new URLSearchParams(u.hash).get("#xywh");this.propagateMediaState(s.MediaUIAttributes.MEDIA_PREVIEW_IMAGE,u.href),this.propagateMediaState(s.MediaUIAttributes.MEDIA_PREVIEW_COORDS,_.split(",").join(" "))},MEDIA_SHOW_CAPTIONS_REQUEST:t=>{const i=M(this),{detail:r=[]}=t;(0,o.updateTracksModeTo)(s.TextTrackModes.SHOWING,i,r)},MEDIA_DISABLE_CAPTIONS_REQUEST:t=>{const i=M(this),{detail:r=[]}=t;(0,o.updateTracksModeTo)(s.TextTrackModes.DISABLED,i,r)},MEDIA_SHOW_SUBTITLES_REQUEST:t=>{const i=T(this),{detail:r=[]}=t;(0,o.updateTracksModeTo)(s.TextTrackModes.SHOWING,i,r)},MEDIA_DISABLE_SUBTITLES_REQUEST:t=>{const i=T(this),{detail:r=[]}=t;(0,o.updateTracksModeTo)(s.TextTrackModes.DISABLED,i,r)},MEDIA_AIRPLAY_REQUEST:t=>{const{media:i}=this;if(!!i){if(!(i.webkitShowPlaybackTargetPicker&&E.Window.WebKitPlaybackTargetAvailabilityEvent)){console.warn("received a request to select AirPlay but AirPlay is not supported in this environment");return}i.webkitShowPlaybackTargetPicker()}}};if(Object.keys(e).forEach(t=>{const i=`_handle${(0,U.constToCamel)(t,!0)}`;this[i]=r=>{if(r.stopPropagation(),!this.media){console.warn("MediaController: No media available.");return}e[t](r,this.media)},this.addEventListener(s.MediaUIEvents[t],this[i])}),this._mediaStatePropagators={"play,pause,emptied":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_PAUSED,x(this))},"playing,emptied":()=>{var t;this.propagateMediaState(s.MediaUIAttributes.MEDIA_HAS_PLAYED,!((t=this.media)==null?void 0:t.paused))},volumechange:()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_MUTED,V(this)),this.propagateMediaState(s.MediaUIAttributes.MEDIA_VOLUME,B(this)),this.propagateMediaState(s.MediaUIAttributes.MEDIA_VOLUME_LEVEL,w(this))},[S.fullscreenApi.event]:t=>{const r=!!E.Document[S.fullscreenApi.element]&&(t==null?void 0:t.target),n=(0,b.containsComposedNode)(this,r);this.propagateMediaState(s.MediaUIAttributes.MEDIA_IS_FULLSCREEN,n)},"enterpictureinpicture,leavepictureinpicture":t=>{var r;let i;if(t)i=t.type=="enterpictureinpicture";else{const n=(r=this.getRootNode().pictureInPictureElement)!=null?r:E.Document.pictureInPictureElement;i=this.media&&(0,b.containsComposedNode)(this.media,n)}this.propagateMediaState(s.MediaUIAttributes.MEDIA_IS_PIP,i)},"entercast,leavecast,castchange":t=>{var n;const i=(n=globalThis.CastableVideoElement)==null?void 0:n.castElement;let r=this.media&&(0,b.containsComposedNode)(this.media,i);(t==null?void 0:t.type)==="castchange"&&(t==null?void 0:t.detail)==="CONNECTING"&&(r="connecting"),this.propagateMediaState(s.MediaUIAttributes.MEDIA_IS_CASTING,r)},"timeupdate,loadedmetadata":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_CURRENT_TIME,Q(this))},"durationchange,loadedmetadata,emptied":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_DURATION,F(this))},"loadedmetadata,emptied,progress":()=>{var t;this.propagateMediaState(s.MediaUIAttributes.MEDIA_SEEKABLE,(t=G(this))==null?void 0:t.join(":"))},"progress,emptied":()=>{var t;this.propagateMediaState(s.MediaUIAttributes.MEDIA_BUFFERED,St((t=this.media)==null?void 0:t.buffered))},"ratechange,loadstart":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_PLAYBACK_RATE,W(this))},"waiting,playing,emptied":()=>{var i;const t=((i=this.media)==null?void 0:i.readyState)<3;this.propagateMediaState(s.MediaUIAttributes.MEDIA_LOADING,t)}},this._airplayUnavailable!==s.AvailabilityStates.UNSUPPORTED){const t=i=>{(i==null?void 0:i.availability)==="available"?this._airplayUnavailable=void 0:(i==null?void 0:i.availability)==="not-available"&&(this._airplayUnavailable=s.AvailabilityStates.UNAVAILABLE),this.propagateMediaState(s.MediaUIAttributes.MEDIA_AIRPLAY_UNAVAILABLE,this._airplayUnavailable)};this._mediaStatePropagators.webkitplaybacktargetavailabilitychanged=t}if(this._castUnavailable!==s.AvailabilityStates.UNSUPPORTED){const t=i=>{(i==null?void 0:i.detail.includes("CONNECT"))?this._castUnavailable=void 0:this._castUnavailable=s.AvailabilityStates.UNAVAILABLE,this.propagateMediaState(s.MediaUIAttributes.MEDIA_CAST_UNAVAILABLE,this._castUnavailable)};this._mediaStatePropagators.castchange=t}this._textTrackMediaStatePropagators={"addtrack,removetrack,loadstart":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_CAPTIONS_LIST,(0,o.stringifyTextTrackList)(M(this))||void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_SUBTITLES_LIST,(0,o.stringifyTextTrackList)(T(this))||void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_CAPTIONS_SHOWING,(0,o.stringifyTextTrackList)(P(this))||void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING,(0,o.stringifyTextTrackList)(R(this))||void 0)},change:()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_CAPTIONS_SHOWING,(0,o.stringifyTextTrackList)(P(this))||void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING,(0,o.stringifyTextTrackList)(R(this))||void 0)}}}mediaSetCallback(e){super.mediaSetCallback(e),Object.keys(this._mediaStatePropagators).forEach(t=>{const i=t.split(","),r=this._mediaStatePropagators[t];i.forEach(n=>{(n==S.fullscreenApi.event?this.getRootNode():e).addEventListener(n,r)}),r()}),Object.entries(this._textTrackMediaStatePropagators).forEach(([t,i])=>{t.split(",").forEach(n=>{e.textTracks&&e.textTracks.addEventListener(n,i)}),i()});try{const t=E.Window.localStorage.getItem("media-chrome-pref-volume");t!==null&&(e.volume=t)}catch(t){console.debug("Error getting volume pref",t)}}mediaUnsetCallback(e){super.mediaUnsetCallback(e),Object.keys(this._mediaStatePropagators).forEach(t=>{const i=t.split(","),r=this._mediaStatePropagators[t];i.forEach(n=>{(n==S.fullscreenApi.event?this.getRootNode():e).removeEventListener(n,r)})}),Object.entries(this._textTrackMediaStatePropagators).forEach(([t,i])=>{t.split(",").forEach(n=>{e.textTracks&&e.textTracks.removeEventListener(n,i)}),i()}),this.propagateMediaState(s.MediaUIAttributes.MEDIA_PAUSED,!0)}propagateMediaState(e,t){c(this.mediaStateReceivers,e,t);const i=new E.Window.CustomEvent(s.AttributeToStateChangeEventMap[e],{composed:!0,bubbles:!0,detail:t});this.dispatchEvent(i)}associateElement(e){if(!e)return;const{associatedElementSubscriptions:t}=this;if(t.has(e))return;const i=this.registerMediaStateReceiver.bind(this),r=this.unregisterMediaStateReceiver.bind(this),n=ot(e,i,r);Object.keys(s.MediaUIEvents).forEach(d=>{e.addEventListener(s.MediaUIEvents[d],this[`_handle${(0,U.constToCamel)(d,!0)}`])}),t.set(e,n)}unassociateElement(e){if(!e)return;const{associatedElementSubscriptions:t}=this;if(!t.has(e))return;t.get(e)(),t.delete(e),Object.keys(s.MediaUIEvents).forEach(r=>{e.removeEventListener(s.MediaUIEvents[r],this[`_handle${(0,U.constToCamel)(r,!0)}`])})}registerMediaStateReceiver(e){var r;if(!e)return;const t=this.mediaStateReceivers;t.indexOf(e)>-1||(t.push(e),c([e],s.MediaUIAttributes.MEDIA_VOLUME_UNAVAILABLE,this._volumeUnavailable),c([e],s.MediaUIAttributes.MEDIA_AIRPLAY_UNAVAILABLE,this._airplayUnavailable),c([e],s.MediaUIAttributes.MEDIA_CAST_UNAVAILABLE,this._castUnavailable),c([e],s.MediaUIAttributes.MEDIA_PIP_UNAVAILABLE,this._pipUnavailable),this.media&&(c([e],s.MediaUIAttributes.MEDIA_CAPTIONS_LIST,(0,o.stringifyTextTrackList)(M(this))||void 0),c([e],s.MediaUIAttributes.MEDIA_SUBTITLES_LIST,(0,o.stringifyTextTrackList)(T(this))||void 0),c([e],s.MediaUIAttributes.MEDIA_CAPTIONS_SHOWING,(0,o.stringifyTextTrackList)(P(this))||void 0),c([e],s.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING,(0,o.stringifyTextTrackList)(R(this))||void 0),c([e],s.MediaUIAttributes.MEDIA_PAUSED,x(this)),c([e],s.MediaUIAttributes.MEDIA_MUTED,V(this)),c([e],s.MediaUIAttributes.MEDIA_VOLUME,B(this)),c([e],s.MediaUIAttributes.MEDIA_VOLUME_LEVEL,w(this)),c([e],s.MediaUIAttributes.MEDIA_IS_FULLSCREEN,this.hasAttribute(s.MediaUIAttributes.MEDIA_IS_FULLSCREEN)),c([e],s.MediaUIAttributes.MEDIA_IS_CASTING,this.hasAttribute(s.MediaUIAttributes.MEDIA_IS_CASTING)),c([e],s.MediaUIAttributes.MEDIA_CURRENT_TIME,Q(this)),c([e],s.MediaUIAttributes.MEDIA_DURATION,F(this)),c([e],s.MediaUIAttributes.MEDIA_SEEKABLE,(r=G(this))==null?void 0:r.join(":")),c([e],s.MediaUIAttributes.MEDIA_PLAYBACK_RATE,W(this))))}unregisterMediaStateReceiver(e){const t=this.mediaStateReceivers,i=t.indexOf(e);i<0||t.splice(i,1)}}const x=a=>a.media?a.media.paused:!0,V=a=>!!(a.media&&a.media.muted),B=a=>{const e=a.media;return e?e.volume:1},w=a=>{let e="high";if(!a.media)return e;const{muted:t,volume:i}=a.media;return i===0||t?e="off":i<.5?e="low":i<.75&&(e="medium"),e},Q=a=>{const e=a.media;return e?e.currentTime:0},F=a=>{const e=a==null?void 0:a.media;return Number.isFinite(e==null?void 0:e.duration)?e.duration:NaN},G=a=>{var r;const e=a==null?void 0:a.media;if(!((r=e==null?void 0:e.seekable)==null?void 0:r.length))return;const t=e.seekable.start(0),i=e.seekable.end(e.seekable.length-1);if(!(!t&&!i))return[Number(t.toFixed(3)),Number(i.toFixed(3))]},W=a=>{const e=a.media;return e?e.playbackRate:1},T=a=>(0,o.getTextTracksList)(a.media,{kind:s.TextTrackKinds.SUBTITLES}),M=a=>(0,o.getTextTracksList)(a.media,{kind:s.TextTrackKinds.CAPTIONS}),R=a=>(0,o.getTextTracksList)(a.media,{kind:s.TextTrackKinds.SUBTITLES,mode:s.TextTrackModes.SHOWING}),P=a=>(0,o.getTextTracksList)(a.media,{kind:s.TextTrackKinds.CAPTIONS,mode:s.TextTrackModes.SHOWING}),rt=Object.values(s.MediaUIAttributes),H=a=>{var i,r,n,d;let{observedAttributes:e}=a.constructor;!e&&((i=a.nodeName)==null?void 0:i.includes("-"))&&(E.Window.customElements.upgrade(a),{observedAttributes:e}=a.constructor);const t=(d=(n=(r=a==null?void 0:a.getAttribute)==null?void 0:r.call(a,s.MediaUIAttributes.MEDIA_CHROME_ATTRIBUTES))==null?void 0:n.split)==null?void 0:d.call(n,/\s+/);return Array.isArray(e||t)?(e||t).filter(A=>rt.includes(A)):[]},L=a=>!!H(a).length,nt=async(a,e,t)=>(a.isConnected||await C(0),t==null?a.removeAttribute(e):typeof t=="boolean"?t?a.setAttribute(e,""):a.removeAttribute(e):Number.isNaN(t)?a.removeAttribute(e):a.setAttribute(e,t)),Et=a=>{var e;return!!((e=a.closest)==null?void 0:e.call(a,'*[slot="media"]'))},h=(a,e)=>{if(Et(a))return;const t=(r,n)=>{var _,l;L(r)&&n(r);const{children:d=[]}=r!=null?r:{},A=(l=(_=r==null?void 0:r.shadowRoot)==null?void 0:_.children)!=null?l:[];[...d,...A].forEach(p=>h(p,n))},i=a==null?void 0:a.nodeName.toLowerCase();if(i.includes("-")&&!L(a)){E.Window.customElements.whenDefined(i).then(()=>{t(a,e)});return}t(a,e)},c=(a,e,t)=>{a.forEach(i=>{!H(i).includes(e)||nt(i,e,t)})},ot=(a,e,t)=>{h(a,e);const i=u=>{var l;const _=(l=u==null?void 0:u.composedPath()[0])!=null?l:u.target;e(_)},r=u=>{var l;const _=(l=u==null?void 0:u.composedPath()[0])!=null?l:u.target;t(_)};a.addEventListener(s.MediaUIEvents.REGISTER_MEDIA_STATE_RECEIVER,i),a.addEventListener(s.MediaUIEvents.UNREGISTER_MEDIA_STATE_RECEIVER,r);const n=(u,_)=>{u.forEach(l=>{const{addedNodes:p=[],removedNodes:X=[],type:O,target:D,attributeName:$}=l;O==="childList"?(Array.prototype.forEach.call(p,g=>h(g,e)),Array.prototype.forEach.call(X,g=>h(g,t))):O==="attributes"&&$===s.MediaUIAttributes.MEDIA_CHROME_ATTRIBUTES&&(L(D)?e(D):t(D))})},d=new MutationObserver(n);return d.observe(a,{childList:!0,attributes:!0,subtree:!0}),()=>{h(a,t),d.disconnect(),a.removeEventListener(s.MediaUIEvents.REGISTER_MEDIA_STATE_RECEIVER,i),a.removeEventListener(s.MediaUIEvents.UNREGISTER_MEDIA_STATE_RECEIVER,r)}};let f;const v=()=>{var a,e;return f||(f=(e=(a=E.Document)==null?void 0:a.createElement)==null?void 0:e.call(a,"video"),f)},Y=async(a=v())=>{if(!a)return!1;const e=a.volume;return a.volume=e/2+.1,await C(0),a.volume!==e},C=a=>new Promise((e,t)=>setTimeout(e,a)),q=(a=v())=>typeof(a==null?void 0:a.requestPictureInPicture)=="function",ct=q();let I;const dt=Y().then(a=>(I=a,I)),ut=!!E.Window.WebKitPlaybackTargetAvailabilityEvent,lt=!!E.Window.chrome;function St(a=[]){return Array.from(a).map((e,t)=>[Number(a.start(t).toFixed(3)),Number(a.end(t).toFixed(3))].join(":")).join(" ")}(0,K.defineCustomElement)("media-controller",N);var _t=N;module.exports=st(At); | ||
var z=Object.create;var m=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var k=a=>m(a,"__esModule",{value:!0});var at=(a,e)=>{for(var t in e)m(a,t,{get:e[t],enumerable:!0})},y=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Z(e))!et.call(a,r)&&(t||r!=="default")&&m(a,r,{get:()=>e[r],enumerable:!(i=J(e,r))||i.enumerable});return a},it=(a,e)=>y(k(m(a!=null?z(tt(a)):{},"default",!e&&a&&a.__esModule?{get:()=>a.default,enumerable:!0}:{value:a,enumerable:!0})),a),st=(a=>(e,t)=>a&&a.get(e)||(t=y(k({}),e,1),a&&a.set(e,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var At={};at(At,{default:()=>_t,delay:()=>C,getTestMediaEl:()=>v,hasPipSupport:()=>q,hasVolumeSupportAsync:()=>Y});var j=it(require("./media-container.js"),1),K=require("./utils/defineCustomElement.js"),E=require("./utils/server-safe-globals.js"),S=require("./utils/fullscreenApi.js"),U=require("./utils/stringUtils.js"),b=require("./utils/element-utils.js"),s=require("./constants.js"),o=require("./utils/captions.js");const{MEDIA_PLAY_REQUEST:ht,MEDIA_PAUSE_REQUEST:It,MEDIA_MUTE_REQUEST:mt,MEDIA_UNMUTE_REQUEST:Tt,MEDIA_VOLUME_REQUEST:Mt,MEDIA_ENTER_FULLSCREEN_REQUEST:ft,MEDIA_EXIT_FULLSCREEN_REQUEST:Ut,MEDIA_SEEK_REQUEST:bt,MEDIA_PREVIEW_REQUEST:Dt,MEDIA_ENTER_PIP_REQUEST:gt,MEDIA_EXIT_PIP_REQUEST:Rt,MEDIA_PLAYBACK_RATE_REQUEST:Pt}=s.MediaUIEvents;class N extends j.default{constructor(){super();ut||(this._airplayUnavailable=s.AvailabilityStates.UNSUPPORTED),lt||(this._castUnavailable=s.AvailabilityStates.UNSUPPORTED),ct||(this._pipUnavailable=s.AvailabilityStates.UNSUPPORTED),I!==void 0?I||(this._volumeUnavailable=s.AvailabilityStates.UNSUPPORTED):dt.then(()=>{I||(this._volumeUnavailable=s.AvailabilityStates.UNSUPPORTED,this.propagateMediaState(s.MediaUIAttributes.MEDIA_VOLUME_UNAVAILABLE,this._volumeUnavailable))}),this.mediaStateReceivers=[],this.associatedElementSubscriptions=new Map,this.associatedElements=[],this.associateElement(this);const e={MEDIA_PLAY_REQUEST:()=>this.media.play(),MEDIA_PAUSE_REQUEST:()=>this.media.pause(),MEDIA_MUTE_REQUEST:()=>this.media.muted=!0,MEDIA_UNMUTE_REQUEST:()=>{const t=this.media;t.muted=!1,t.volume===0&&(t.volume=.25)},MEDIA_VOLUME_REQUEST:t=>{const i=this.media,r=t.detail;i.volume=r,r>0&&i.muted&&(i.muted=!1);try{E.Window.localStorage.setItem("media-chrome-pref-volume",r.toString())}catch{}},MEDIA_ENTER_FULLSCREEN_REQUEST:()=>{const t=this.media;E.Document.pictureInPictureElement&&E.Document.exitPictureInPicture(),super[S.fullscreenApi.enter]?super[S.fullscreenApi.enter]():t.webkitEnterFullscreen?t.webkitEnterFullscreen():t.requestFullscreen?t.requestFullscreen():console.warn("MediaChrome: Fullscreen not supported")},MEDIA_EXIT_FULLSCREEN_REQUEST:()=>{E.Document[S.fullscreenApi.exit]()},MEDIA_ENTER_PIP_REQUEST:()=>{const t=this.media;!E.Document.pictureInPictureEnabled||(E.Document[S.fullscreenApi.element]&&E.Document[S.fullscreenApi.exit](),t.requestPictureInPicture())},MEDIA_EXIT_PIP_REQUEST:()=>{E.Document.pictureInPictureElement&&E.Document.exitPictureInPicture()},MEDIA_ENTER_CAST_REQUEST:()=>{var i;const t=this.media;!((i=globalThis.CastableVideoElement)==null?void 0:i.castEnabled)||(E.Document[S.fullscreenApi.element]&&E.Document[S.fullscreenApi.exit](),t.requestCast())},MEDIA_EXIT_CAST_REQUEST:async()=>{var t;((t=globalThis.CastableVideoElement)==null?void 0:t.castElement)&&globalThis.CastableVideoElement.exitCast()},MEDIA_SEEK_REQUEST:t=>{const i=this.media,r=t.detail;(i.readyState>0||i.readyState===void 0)&&(i.currentTime=r)},MEDIA_PLAYBACK_RATE_REQUEST:t=>{this.media.playbackRate=t.detail},MEDIA_PREVIEW_REQUEST:t=>{var l;const i=this.media;if(!i)return;const[r]=(0,o.getTextTracksList)(i,{kind:s.TextTrackKinds.METADATA,label:"thumbnails"});if(!(r&&r.cues))return;const n=t.detail;if(n===null){this.propagateMediaState(s.MediaUIAttributes.MEDIA_PREVIEW_IMAGE,void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_PREVIEW_COORDS,void 0);return}const d=Array.prototype.find.call(r.cues,p=>p.startTime>=n);if(!d)return;const A=/'^(?:[a-z]+:)?\/\//i.test(d.text)||(l=i.querySelector('track[label="thumbnails"]'))==null?void 0:l.src,u=new URL(d.text,A),_=new URLSearchParams(u.hash).get("#xywh");this.propagateMediaState(s.MediaUIAttributes.MEDIA_PREVIEW_IMAGE,u.href),this.propagateMediaState(s.MediaUIAttributes.MEDIA_PREVIEW_COORDS,_.split(",").join(" "))},MEDIA_SHOW_CAPTIONS_REQUEST:t=>{const i=M(this),{detail:r=[]}=t;(0,o.updateTracksModeTo)(s.TextTrackModes.SHOWING,i,r)},MEDIA_DISABLE_CAPTIONS_REQUEST:t=>{const i=M(this),{detail:r=[]}=t;(0,o.updateTracksModeTo)(s.TextTrackModes.DISABLED,i,r)},MEDIA_SHOW_SUBTITLES_REQUEST:t=>{const i=T(this),{detail:r=[]}=t;(0,o.updateTracksModeTo)(s.TextTrackModes.SHOWING,i,r)},MEDIA_DISABLE_SUBTITLES_REQUEST:t=>{const i=T(this),{detail:r=[]}=t;(0,o.updateTracksModeTo)(s.TextTrackModes.DISABLED,i,r)},MEDIA_AIRPLAY_REQUEST:t=>{const{media:i}=this;if(!!i){if(!(i.webkitShowPlaybackTargetPicker&&E.Window.WebKitPlaybackTargetAvailabilityEvent)){console.warn("received a request to select AirPlay but AirPlay is not supported in this environment");return}i.webkitShowPlaybackTargetPicker()}}};if(Object.keys(e).forEach(t=>{const i=`_handle${(0,U.constToCamel)(t,!0)}`;this[i]=r=>{if(r.stopPropagation(),!this.media){console.warn("MediaController: No media available.");return}e[t](r,this.media)},this.addEventListener(s.MediaUIEvents[t],this[i])}),this._mediaStatePropagators={"play,pause,emptied":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_PAUSED,x(this))},"playing,emptied":()=>{var t;this.propagateMediaState(s.MediaUIAttributes.MEDIA_HAS_PLAYED,!((t=this.media)==null?void 0:t.paused))},volumechange:()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_MUTED,V(this)),this.propagateMediaState(s.MediaUIAttributes.MEDIA_VOLUME,B(this)),this.propagateMediaState(s.MediaUIAttributes.MEDIA_VOLUME_LEVEL,w(this))},[S.fullscreenApi.event]:t=>{const r=!!E.Document[S.fullscreenApi.element]&&(t==null?void 0:t.target),n=(0,b.containsComposedNode)(this,r);this.propagateMediaState(s.MediaUIAttributes.MEDIA_IS_FULLSCREEN,n)},"enterpictureinpicture,leavepictureinpicture":t=>{var r;let i;if(t)i=t.type=="enterpictureinpicture";else{const n=(r=this.getRootNode().pictureInPictureElement)!=null?r:E.Document.pictureInPictureElement;i=this.media&&(0,b.containsComposedNode)(this.media,n)}this.propagateMediaState(s.MediaUIAttributes.MEDIA_IS_PIP,i)},"entercast,leavecast,castchange":t=>{var n;const i=(n=globalThis.CastableVideoElement)==null?void 0:n.castElement;let r=this.media&&(0,b.containsComposedNode)(this.media,i);(t==null?void 0:t.type)==="castchange"&&(t==null?void 0:t.detail)==="CONNECTING"&&(r="connecting"),this.propagateMediaState(s.MediaUIAttributes.MEDIA_IS_CASTING,r)},"timeupdate,loadedmetadata":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_CURRENT_TIME,Q(this))},"durationchange,loadedmetadata,emptied":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_DURATION,F(this))},"loadedmetadata,emptied,progress":()=>{var t;this.propagateMediaState(s.MediaUIAttributes.MEDIA_SEEKABLE,(t=G(this))==null?void 0:t.join(":"))},"progress,emptied":()=>{var t;this.propagateMediaState(s.MediaUIAttributes.MEDIA_BUFFERED,St((t=this.media)==null?void 0:t.buffered))},"ratechange,loadstart":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_PLAYBACK_RATE,W(this))},"waiting,playing,emptied":()=>{var i;const t=((i=this.media)==null?void 0:i.readyState)<3;this.propagateMediaState(s.MediaUIAttributes.MEDIA_LOADING,t)}},this._airplayUnavailable!==s.AvailabilityStates.UNSUPPORTED){const t=i=>{(i==null?void 0:i.availability)==="available"?this._airplayUnavailable=void 0:(i==null?void 0:i.availability)==="not-available"&&(this._airplayUnavailable=s.AvailabilityStates.UNAVAILABLE),this.propagateMediaState(s.MediaUIAttributes.MEDIA_AIRPLAY_UNAVAILABLE,this._airplayUnavailable)};this._mediaStatePropagators.webkitplaybacktargetavailabilitychanged=t}if(this._castUnavailable!==s.AvailabilityStates.UNSUPPORTED){const t=()=>{var r;const i=(r=globalThis.CastableVideoElement)==null?void 0:r.castState;(i==null?void 0:i.includes("CONNECT"))?this._castUnavailable=void 0:this._castUnavailable=s.AvailabilityStates.UNAVAILABLE,this.propagateMediaState(s.MediaUIAttributes.MEDIA_CAST_UNAVAILABLE,this._castUnavailable)};this._mediaStatePropagators.castchange=t}this._textTrackMediaStatePropagators={"addtrack,removetrack,loadstart":()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_CAPTIONS_LIST,(0,o.stringifyTextTrackList)(M(this))||void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_SUBTITLES_LIST,(0,o.stringifyTextTrackList)(T(this))||void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_CAPTIONS_SHOWING,(0,o.stringifyTextTrackList)(P(this))||void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING,(0,o.stringifyTextTrackList)(R(this))||void 0)},change:()=>{this.propagateMediaState(s.MediaUIAttributes.MEDIA_CAPTIONS_SHOWING,(0,o.stringifyTextTrackList)(P(this))||void 0),this.propagateMediaState(s.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING,(0,o.stringifyTextTrackList)(R(this))||void 0)}}}mediaSetCallback(e){super.mediaSetCallback(e),Object.keys(this._mediaStatePropagators).forEach(t=>{const i=t.split(","),r=this._mediaStatePropagators[t];i.forEach(n=>{(n==S.fullscreenApi.event?this.getRootNode():e).addEventListener(n,r)}),r()}),Object.entries(this._textTrackMediaStatePropagators).forEach(([t,i])=>{t.split(",").forEach(n=>{e.textTracks&&e.textTracks.addEventListener(n,i)}),i()});try{const t=E.Window.localStorage.getItem("media-chrome-pref-volume");t!==null&&(e.volume=t)}catch(t){console.debug("Error getting volume pref",t)}}mediaUnsetCallback(e){super.mediaUnsetCallback(e),Object.keys(this._mediaStatePropagators).forEach(t=>{const i=t.split(","),r=this._mediaStatePropagators[t];i.forEach(n=>{(n==S.fullscreenApi.event?this.getRootNode():e).removeEventListener(n,r)})}),Object.entries(this._textTrackMediaStatePropagators).forEach(([t,i])=>{t.split(",").forEach(n=>{e.textTracks&&e.textTracks.removeEventListener(n,i)}),i()}),this.propagateMediaState(s.MediaUIAttributes.MEDIA_PAUSED,!0)}propagateMediaState(e,t){c(this.mediaStateReceivers,e,t);const i=new E.Window.CustomEvent(s.AttributeToStateChangeEventMap[e],{composed:!0,bubbles:!0,detail:t});this.dispatchEvent(i)}associateElement(e){if(!e)return;const{associatedElementSubscriptions:t}=this;if(t.has(e))return;const i=this.registerMediaStateReceiver.bind(this),r=this.unregisterMediaStateReceiver.bind(this),n=ot(e,i,r);Object.keys(s.MediaUIEvents).forEach(d=>{e.addEventListener(s.MediaUIEvents[d],this[`_handle${(0,U.constToCamel)(d,!0)}`])}),t.set(e,n)}unassociateElement(e){if(!e)return;const{associatedElementSubscriptions:t}=this;if(!t.has(e))return;t.get(e)(),t.delete(e),Object.keys(s.MediaUIEvents).forEach(r=>{e.removeEventListener(s.MediaUIEvents[r],this[`_handle${(0,U.constToCamel)(r,!0)}`])})}registerMediaStateReceiver(e){var r;if(!e)return;const t=this.mediaStateReceivers;t.indexOf(e)>-1||(t.push(e),c([e],s.MediaUIAttributes.MEDIA_VOLUME_UNAVAILABLE,this._volumeUnavailable),c([e],s.MediaUIAttributes.MEDIA_AIRPLAY_UNAVAILABLE,this._airplayUnavailable),c([e],s.MediaUIAttributes.MEDIA_CAST_UNAVAILABLE,this._castUnavailable),c([e],s.MediaUIAttributes.MEDIA_PIP_UNAVAILABLE,this._pipUnavailable),this.media&&(c([e],s.MediaUIAttributes.MEDIA_CAPTIONS_LIST,(0,o.stringifyTextTrackList)(M(this))||void 0),c([e],s.MediaUIAttributes.MEDIA_SUBTITLES_LIST,(0,o.stringifyTextTrackList)(T(this))||void 0),c([e],s.MediaUIAttributes.MEDIA_CAPTIONS_SHOWING,(0,o.stringifyTextTrackList)(P(this))||void 0),c([e],s.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING,(0,o.stringifyTextTrackList)(R(this))||void 0),c([e],s.MediaUIAttributes.MEDIA_PAUSED,x(this)),c([e],s.MediaUIAttributes.MEDIA_MUTED,V(this)),c([e],s.MediaUIAttributes.MEDIA_VOLUME,B(this)),c([e],s.MediaUIAttributes.MEDIA_VOLUME_LEVEL,w(this)),c([e],s.MediaUIAttributes.MEDIA_IS_FULLSCREEN,this.hasAttribute(s.MediaUIAttributes.MEDIA_IS_FULLSCREEN)),c([e],s.MediaUIAttributes.MEDIA_IS_CASTING,this.hasAttribute(s.MediaUIAttributes.MEDIA_IS_CASTING)),c([e],s.MediaUIAttributes.MEDIA_CURRENT_TIME,Q(this)),c([e],s.MediaUIAttributes.MEDIA_DURATION,F(this)),c([e],s.MediaUIAttributes.MEDIA_SEEKABLE,(r=G(this))==null?void 0:r.join(":")),c([e],s.MediaUIAttributes.MEDIA_PLAYBACK_RATE,W(this))))}unregisterMediaStateReceiver(e){const t=this.mediaStateReceivers,i=t.indexOf(e);i<0||t.splice(i,1)}}const x=a=>a.media?a.media.paused:!0,V=a=>!!(a.media&&a.media.muted),B=a=>{const e=a.media;return e?e.volume:1},w=a=>{let e="high";if(!a.media)return e;const{muted:t,volume:i}=a.media;return i===0||t?e="off":i<.5?e="low":i<.75&&(e="medium"),e},Q=a=>{const e=a.media;return e?e.currentTime:0},F=a=>{const e=a==null?void 0:a.media;return Number.isFinite(e==null?void 0:e.duration)?e.duration:NaN},G=a=>{var r;const e=a==null?void 0:a.media;if(!((r=e==null?void 0:e.seekable)==null?void 0:r.length))return;const t=e.seekable.start(0),i=e.seekable.end(e.seekable.length-1);if(!(!t&&!i))return[Number(t.toFixed(3)),Number(i.toFixed(3))]},W=a=>{const e=a.media;return e?e.playbackRate:1},T=a=>(0,o.getTextTracksList)(a.media,{kind:s.TextTrackKinds.SUBTITLES}),M=a=>(0,o.getTextTracksList)(a.media,{kind:s.TextTrackKinds.CAPTIONS}),R=a=>(0,o.getTextTracksList)(a.media,{kind:s.TextTrackKinds.SUBTITLES,mode:s.TextTrackModes.SHOWING}),P=a=>(0,o.getTextTracksList)(a.media,{kind:s.TextTrackKinds.CAPTIONS,mode:s.TextTrackModes.SHOWING}),rt=Object.values(s.MediaUIAttributes),H=a=>{var i,r,n,d;let{observedAttributes:e}=a.constructor;!e&&((i=a.nodeName)==null?void 0:i.includes("-"))&&(E.Window.customElements.upgrade(a),{observedAttributes:e}=a.constructor);const t=(d=(n=(r=a==null?void 0:a.getAttribute)==null?void 0:r.call(a,s.MediaUIAttributes.MEDIA_CHROME_ATTRIBUTES))==null?void 0:n.split)==null?void 0:d.call(n,/\s+/);return Array.isArray(e||t)?(e||t).filter(A=>rt.includes(A)):[]},L=a=>!!H(a).length,nt=async(a,e,t)=>(a.isConnected||await C(0),t==null?a.removeAttribute(e):typeof t=="boolean"?t?a.setAttribute(e,""):a.removeAttribute(e):Number.isNaN(t)?a.removeAttribute(e):a.setAttribute(e,t)),Et=a=>{var e;return!!((e=a.closest)==null?void 0:e.call(a,'*[slot="media"]'))},h=(a,e)=>{if(Et(a))return;const t=(r,n)=>{var _,l;L(r)&&n(r);const{children:d=[]}=r!=null?r:{},A=(l=(_=r==null?void 0:r.shadowRoot)==null?void 0:_.children)!=null?l:[];[...d,...A].forEach(p=>h(p,n))},i=a==null?void 0:a.nodeName.toLowerCase();if(i.includes("-")&&!L(a)){E.Window.customElements.whenDefined(i).then(()=>{t(a,e)});return}t(a,e)},c=(a,e,t)=>{a.forEach(i=>{!H(i).includes(e)||nt(i,e,t)})},ot=(a,e,t)=>{h(a,e);const i=u=>{var l;const _=(l=u==null?void 0:u.composedPath()[0])!=null?l:u.target;e(_)},r=u=>{var l;const _=(l=u==null?void 0:u.composedPath()[0])!=null?l:u.target;t(_)};a.addEventListener(s.MediaUIEvents.REGISTER_MEDIA_STATE_RECEIVER,i),a.addEventListener(s.MediaUIEvents.UNREGISTER_MEDIA_STATE_RECEIVER,r);const n=(u,_)=>{u.forEach(l=>{const{addedNodes:p=[],removedNodes:X=[],type:O,target:D,attributeName:$}=l;O==="childList"?(Array.prototype.forEach.call(p,g=>h(g,e)),Array.prototype.forEach.call(X,g=>h(g,t))):O==="attributes"&&$===s.MediaUIAttributes.MEDIA_CHROME_ATTRIBUTES&&(L(D)?e(D):t(D))})},d=new MutationObserver(n);return d.observe(a,{childList:!0,attributes:!0,subtree:!0}),()=>{h(a,t),d.disconnect(),a.removeEventListener(s.MediaUIEvents.REGISTER_MEDIA_STATE_RECEIVER,i),a.removeEventListener(s.MediaUIEvents.UNREGISTER_MEDIA_STATE_RECEIVER,r)}};let f;const v=()=>{var a,e;return f||(f=(e=(a=E.Document)==null?void 0:a.createElement)==null?void 0:e.call(a,"video"),f)},Y=async(a=v())=>{if(!a)return!1;const e=a.volume;return a.volume=e/2+.1,await C(0),a.volume!==e},C=a=>new Promise((e,t)=>setTimeout(e,a)),q=(a=v())=>typeof(a==null?void 0:a.requestPictureInPicture)=="function",ct=q();let I;const dt=Y().then(a=>(I=a,I)),ut=!!E.Window.WebKitPlaybackTargetAvailabilityEvent,lt=!!E.Window.chrome;function St(a=[]){return Array.from(a).map((e,t)=>[Number(a.start(t).toFixed(3)),Number(a.end(t).toFixed(3))].join(":")).join(" ")}(0,K.defineCustomElement)("media-controller",N);var _t=N;module.exports=st(At); | ||
//# sourceMappingURL=media-controller.js.map |
@@ -1,2 +0,2 @@ | ||
import z from"./media-container.js";import{defineCustomElement as J}from"./utils/defineCustomElement.js";import{Window as h,Document as u}from"./utils/server-safe-globals.js";import{fullscreenApi as l}from"./utils/fullscreenApi.js";import{constToCamel as C}from"./utils/stringUtils.js";import{containsComposedNode as O}from"./utils/element-utils.js";import{MediaUIEvents as S,MediaUIAttributes as r,TextTrackKinds as M,TextTrackModes as m,AvailabilityStates as p,AttributeToStateChangeEventMap as Z}from"./constants.js";import{stringifyTextTrackList as _,getTextTracksList as f,updateTracksModeTo as D}from"./utils/captions.js";const{MEDIA_PLAY_REQUEST:mt,MEDIA_PAUSE_REQUEST:Tt,MEDIA_MUTE_REQUEST:Mt,MEDIA_UNMUTE_REQUEST:ft,MEDIA_VOLUME_REQUEST:Ut,MEDIA_ENTER_FULLSCREEN_REQUEST:bt,MEDIA_EXIT_FULLSCREEN_REQUEST:Dt,MEDIA_SEEK_REQUEST:gt,MEDIA_PREVIEW_REQUEST:Rt,MEDIA_ENTER_PIP_REQUEST:Pt,MEDIA_EXIT_PIP_REQUEST:Lt,MEDIA_PLAYBACK_RATE_REQUEST:vt}=S;class V extends z{constructor(){super();ot||(this._airplayUnavailable=p.UNSUPPORTED),ct||(this._castUnavailable=p.UNSUPPORTED),nt||(this._pipUnavailable=p.UNSUPPORTED),b!==void 0?b||(this._volumeUnavailable=p.UNSUPPORTED):Et.then(()=>{b||(this._volumeUnavailable=p.UNSUPPORTED,this.propagateMediaState(r.MEDIA_VOLUME_UNAVAILABLE,this._volumeUnavailable))}),this.mediaStateReceivers=[],this.associatedElementSubscriptions=new Map,this.associatedElements=[],this.associateElement(this);const e={MEDIA_PLAY_REQUEST:()=>this.media.play(),MEDIA_PAUSE_REQUEST:()=>this.media.pause(),MEDIA_MUTE_REQUEST:()=>this.media.muted=!0,MEDIA_UNMUTE_REQUEST:()=>{const t=this.media;t.muted=!1,t.volume===0&&(t.volume=.25)},MEDIA_VOLUME_REQUEST:t=>{const i=this.media,s=t.detail;i.volume=s,s>0&&i.muted&&(i.muted=!1);try{h.localStorage.setItem("media-chrome-pref-volume",s.toString())}catch{}},MEDIA_ENTER_FULLSCREEN_REQUEST:()=>{const t=this.media;u.pictureInPictureElement&&u.exitPictureInPicture(),super[l.enter]?super[l.enter]():t.webkitEnterFullscreen?t.webkitEnterFullscreen():t.requestFullscreen?t.requestFullscreen():console.warn("MediaChrome: Fullscreen not supported")},MEDIA_EXIT_FULLSCREEN_REQUEST:()=>{u[l.exit]()},MEDIA_ENTER_PIP_REQUEST:()=>{const t=this.media;!u.pictureInPictureEnabled||(u[l.element]&&u[l.exit](),t.requestPictureInPicture())},MEDIA_EXIT_PIP_REQUEST:()=>{u.pictureInPictureElement&&u.exitPictureInPicture()},MEDIA_ENTER_CAST_REQUEST:()=>{var i;const t=this.media;!((i=globalThis.CastableVideoElement)==null?void 0:i.castEnabled)||(u[l.element]&&u[l.exit](),t.requestCast())},MEDIA_EXIT_CAST_REQUEST:async()=>{var t;((t=globalThis.CastableVideoElement)==null?void 0:t.castElement)&&globalThis.CastableVideoElement.exitCast()},MEDIA_SEEK_REQUEST:t=>{const i=this.media,s=t.detail;(i.readyState>0||i.readyState===void 0)&&(i.currentTime=s)},MEDIA_PLAYBACK_RATE_REQUEST:t=>{this.media.playbackRate=t.detail},MEDIA_PREVIEW_REQUEST:t=>{var d;const i=this.media;if(!i)return;const[s]=f(i,{kind:M.METADATA,label:"thumbnails"});if(!(s&&s.cues))return;const n=t.detail;if(n===null){this.propagateMediaState(r.MEDIA_PREVIEW_IMAGE,void 0),this.propagateMediaState(r.MEDIA_PREVIEW_COORDS,void 0);return}const o=Array.prototype.find.call(s.cues,T=>T.startTime>=n);if(!o)return;const I=/'^(?:[a-z]+:)?\/\//i.test(o.text)||(d=i.querySelector('track[label="thumbnails"]'))==null?void 0:d.src,c=new URL(o.text,I),A=new URLSearchParams(c.hash).get("#xywh");this.propagateMediaState(r.MEDIA_PREVIEW_IMAGE,c.href),this.propagateMediaState(r.MEDIA_PREVIEW_COORDS,A.split(",").join(" "))},MEDIA_SHOW_CAPTIONS_REQUEST:t=>{const i=R(this),{detail:s=[]}=t;D(m.SHOWING,i,s)},MEDIA_DISABLE_CAPTIONS_REQUEST:t=>{const i=R(this),{detail:s=[]}=t;D(m.DISABLED,i,s)},MEDIA_SHOW_SUBTITLES_REQUEST:t=>{const i=g(this),{detail:s=[]}=t;D(m.SHOWING,i,s)},MEDIA_DISABLE_SUBTITLES_REQUEST:t=>{const i=g(this),{detail:s=[]}=t;D(m.DISABLED,i,s)},MEDIA_AIRPLAY_REQUEST:t=>{const{media:i}=this;if(!!i){if(!(i.webkitShowPlaybackTargetPicker&&h.WebKitPlaybackTargetAvailabilityEvent)){console.warn("received a request to select AirPlay but AirPlay is not supported in this environment");return}i.webkitShowPlaybackTargetPicker()}}};if(Object.keys(e).forEach(t=>{const i=`_handle${C(t,!0)}`;this[i]=s=>{if(s.stopPropagation(),!this.media){console.warn("MediaController: No media available.");return}e[t](s,this.media)},this.addEventListener(S[t],this[i])}),this._mediaStatePropagators={"play,pause,emptied":()=>{this.propagateMediaState(r.MEDIA_PAUSED,B(this))},"playing,emptied":()=>{var t;this.propagateMediaState(r.MEDIA_HAS_PLAYED,!((t=this.media)==null?void 0:t.paused))},volumechange:()=>{this.propagateMediaState(r.MEDIA_MUTED,w(this)),this.propagateMediaState(r.MEDIA_VOLUME,Q(this)),this.propagateMediaState(r.MEDIA_VOLUME_LEVEL,F(this))},[l.event]:t=>{const s=!!u[l.element]&&(t==null?void 0:t.target),n=O(this,s);this.propagateMediaState(r.MEDIA_IS_FULLSCREEN,n)},"enterpictureinpicture,leavepictureinpicture":t=>{var s;let i;if(t)i=t.type=="enterpictureinpicture";else{const n=(s=this.getRootNode().pictureInPictureElement)!=null?s:u.pictureInPictureElement;i=this.media&&O(this.media,n)}this.propagateMediaState(r.MEDIA_IS_PIP,i)},"entercast,leavecast,castchange":t=>{var n;const i=(n=globalThis.CastableVideoElement)==null?void 0:n.castElement;let s=this.media&&O(this.media,i);(t==null?void 0:t.type)==="castchange"&&(t==null?void 0:t.detail)==="CONNECTING"&&(s="connecting"),this.propagateMediaState(r.MEDIA_IS_CASTING,s)},"timeupdate,loadedmetadata":()=>{this.propagateMediaState(r.MEDIA_CURRENT_TIME,G(this))},"durationchange,loadedmetadata,emptied":()=>{this.propagateMediaState(r.MEDIA_DURATION,W(this))},"loadedmetadata,emptied,progress":()=>{var t;this.propagateMediaState(r.MEDIA_SEEKABLE,(t=H(this))==null?void 0:t.join(":"))},"progress,emptied":()=>{var t;this.propagateMediaState(r.MEDIA_BUFFERED,dt((t=this.media)==null?void 0:t.buffered))},"ratechange,loadstart":()=>{this.propagateMediaState(r.MEDIA_PLAYBACK_RATE,j(this))},"waiting,playing,emptied":()=>{var i;const t=((i=this.media)==null?void 0:i.readyState)<3;this.propagateMediaState(r.MEDIA_LOADING,t)}},this._airplayUnavailable!==p.UNSUPPORTED){const t=i=>{(i==null?void 0:i.availability)==="available"?this._airplayUnavailable=void 0:(i==null?void 0:i.availability)==="not-available"&&(this._airplayUnavailable=p.UNAVAILABLE),this.propagateMediaState(r.MEDIA_AIRPLAY_UNAVAILABLE,this._airplayUnavailable)};this._mediaStatePropagators.webkitplaybacktargetavailabilitychanged=t}if(this._castUnavailable!==p.UNSUPPORTED){const t=i=>{(i==null?void 0:i.detail.includes("CONNECT"))?this._castUnavailable=void 0:this._castUnavailable=p.UNAVAILABLE,this.propagateMediaState(r.MEDIA_CAST_UNAVAILABLE,this._castUnavailable)};this._mediaStatePropagators.castchange=t}this._textTrackMediaStatePropagators={"addtrack,removetrack,loadstart":()=>{this.propagateMediaState(r.MEDIA_CAPTIONS_LIST,_(R(this))||void 0),this.propagateMediaState(r.MEDIA_SUBTITLES_LIST,_(g(this))||void 0),this.propagateMediaState(r.MEDIA_CAPTIONS_SHOWING,_(y(this))||void 0),this.propagateMediaState(r.MEDIA_SUBTITLES_SHOWING,_(k(this))||void 0)},change:()=>{this.propagateMediaState(r.MEDIA_CAPTIONS_SHOWING,_(y(this))||void 0),this.propagateMediaState(r.MEDIA_SUBTITLES_SHOWING,_(k(this))||void 0)}}}mediaSetCallback(e){super.mediaSetCallback(e),Object.keys(this._mediaStatePropagators).forEach(t=>{const i=t.split(","),s=this._mediaStatePropagators[t];i.forEach(n=>{(n==l.event?this.getRootNode():e).addEventListener(n,s)}),s()}),Object.entries(this._textTrackMediaStatePropagators).forEach(([t,i])=>{t.split(",").forEach(n=>{e.textTracks&&e.textTracks.addEventListener(n,i)}),i()});try{const t=h.localStorage.getItem("media-chrome-pref-volume");t!==null&&(e.volume=t)}catch(t){console.debug("Error getting volume pref",t)}}mediaUnsetCallback(e){super.mediaUnsetCallback(e),Object.keys(this._mediaStatePropagators).forEach(t=>{const i=t.split(","),s=this._mediaStatePropagators[t];i.forEach(n=>{(n==l.event?this.getRootNode():e).removeEventListener(n,s)})}),Object.entries(this._textTrackMediaStatePropagators).forEach(([t,i])=>{t.split(",").forEach(n=>{e.textTracks&&e.textTracks.removeEventListener(n,i)}),i()}),this.propagateMediaState(r.MEDIA_PAUSED,!0)}propagateMediaState(e,t){E(this.mediaStateReceivers,e,t);const i=new h.CustomEvent(Z[e],{composed:!0,bubbles:!0,detail:t});this.dispatchEvent(i)}associateElement(e){if(!e)return;const{associatedElementSubscriptions:t}=this;if(t.has(e))return;const i=this.registerMediaStateReceiver.bind(this),s=this.unregisterMediaStateReceiver.bind(this),n=it(e,i,s);Object.keys(S).forEach(o=>{e.addEventListener(S[o],this[`_handle${C(o,!0)}`])}),t.set(e,n)}unassociateElement(e){if(!e)return;const{associatedElementSubscriptions:t}=this;if(!t.has(e))return;t.get(e)(),t.delete(e),Object.keys(S).forEach(s=>{e.removeEventListener(S[s],this[`_handle${C(s,!0)}`])})}registerMediaStateReceiver(e){var s;if(!e)return;const t=this.mediaStateReceivers;t.indexOf(e)>-1||(t.push(e),E([e],r.MEDIA_VOLUME_UNAVAILABLE,this._volumeUnavailable),E([e],r.MEDIA_AIRPLAY_UNAVAILABLE,this._airplayUnavailable),E([e],r.MEDIA_CAST_UNAVAILABLE,this._castUnavailable),E([e],r.MEDIA_PIP_UNAVAILABLE,this._pipUnavailable),this.media&&(E([e],r.MEDIA_CAPTIONS_LIST,_(R(this))||void 0),E([e],r.MEDIA_SUBTITLES_LIST,_(g(this))||void 0),E([e],r.MEDIA_CAPTIONS_SHOWING,_(y(this))||void 0),E([e],r.MEDIA_SUBTITLES_SHOWING,_(k(this))||void 0),E([e],r.MEDIA_PAUSED,B(this)),E([e],r.MEDIA_MUTED,w(this)),E([e],r.MEDIA_VOLUME,Q(this)),E([e],r.MEDIA_VOLUME_LEVEL,F(this)),E([e],r.MEDIA_IS_FULLSCREEN,this.hasAttribute(r.MEDIA_IS_FULLSCREEN)),E([e],r.MEDIA_IS_CASTING,this.hasAttribute(r.MEDIA_IS_CASTING)),E([e],r.MEDIA_CURRENT_TIME,G(this)),E([e],r.MEDIA_DURATION,W(this)),E([e],r.MEDIA_SEEKABLE,(s=H(this))==null?void 0:s.join(":")),E([e],r.MEDIA_PLAYBACK_RATE,j(this))))}unregisterMediaStateReceiver(e){const t=this.mediaStateReceivers,i=t.indexOf(e);i<0||t.splice(i,1)}}const B=a=>a.media?a.media.paused:!0,w=a=>!!(a.media&&a.media.muted),Q=a=>{const e=a.media;return e?e.volume:1},F=a=>{let e="high";if(!a.media)return e;const{muted:t,volume:i}=a.media;return i===0||t?e="off":i<.5?e="low":i<.75&&(e="medium"),e},G=a=>{const e=a.media;return e?e.currentTime:0},W=a=>{const e=a==null?void 0:a.media;return Number.isFinite(e==null?void 0:e.duration)?e.duration:NaN},H=a=>{var s;const e=a==null?void 0:a.media;if(!((s=e==null?void 0:e.seekable)==null?void 0:s.length))return;const t=e.seekable.start(0),i=e.seekable.end(e.seekable.length-1);if(!(!t&&!i))return[Number(t.toFixed(3)),Number(i.toFixed(3))]},j=a=>{const e=a.media;return e?e.playbackRate:1},g=a=>f(a.media,{kind:M.SUBTITLES}),R=a=>f(a.media,{kind:M.CAPTIONS}),k=a=>f(a.media,{kind:M.SUBTITLES,mode:m.SHOWING}),y=a=>f(a.media,{kind:M.CAPTIONS,mode:m.SHOWING}),tt=Object.values(r),K=a=>{var i,s,n,o;let{observedAttributes:e}=a.constructor;!e&&((i=a.nodeName)==null?void 0:i.includes("-"))&&(h.customElements.upgrade(a),{observedAttributes:e}=a.constructor);const t=(o=(n=(s=a==null?void 0:a.getAttribute)==null?void 0:s.call(a,r.MEDIA_CHROME_ATTRIBUTES))==null?void 0:n.split)==null?void 0:o.call(n,/\s+/);return Array.isArray(e||t)?(e||t).filter(I=>tt.includes(I)):[]},N=a=>!!K(a).length,et=async(a,e,t)=>(a.isConnected||await q(0),t==null?a.removeAttribute(e):typeof t=="boolean"?t?a.setAttribute(e,""):a.removeAttribute(e):Number.isNaN(t)?a.removeAttribute(e):a.setAttribute(e,t)),at=a=>{var e;return!!((e=a.closest)==null?void 0:e.call(a,'*[slot="media"]'))},U=(a,e)=>{if(at(a))return;const t=(s,n)=>{var A,d;N(s)&&n(s);const{children:o=[]}=s!=null?s:{},I=(d=(A=s==null?void 0:s.shadowRoot)==null?void 0:A.children)!=null?d:[];[...o,...I].forEach(T=>U(T,n))},i=a==null?void 0:a.nodeName.toLowerCase();if(i.includes("-")&&!N(a)){h.customElements.whenDefined(i).then(()=>{t(a,e)});return}t(a,e)},E=(a,e,t)=>{a.forEach(i=>{!K(i).includes(e)||et(i,e,t)})},it=(a,e,t)=>{U(a,e);const i=c=>{var d;const A=(d=c==null?void 0:c.composedPath()[0])!=null?d:c.target;e(A)},s=c=>{var d;const A=(d=c==null?void 0:c.composedPath()[0])!=null?d:c.target;t(A)};a.addEventListener(S.REGISTER_MEDIA_STATE_RECEIVER,i),a.addEventListener(S.UNREGISTER_MEDIA_STATE_RECEIVER,s);const n=(c,A)=>{c.forEach(d=>{const{addedNodes:T=[],removedNodes:X=[],type:x,target:L,attributeName:$}=d;x==="childList"?(Array.prototype.forEach.call(T,v=>U(v,e)),Array.prototype.forEach.call(X,v=>U(v,t))):x==="attributes"&&$===r.MEDIA_CHROME_ATTRIBUTES&&(N(L)?e(L):t(L))})},o=new MutationObserver(n);return o.observe(a,{childList:!0,attributes:!0,subtree:!0}),()=>{U(a,t),o.disconnect(),a.removeEventListener(S.REGISTER_MEDIA_STATE_RECEIVER,i),a.removeEventListener(S.UNREGISTER_MEDIA_STATE_RECEIVER,s)}};let P;const Y=()=>{var a,e;return P||(P=(e=(a=u)==null?void 0:a.createElement)==null?void 0:e.call(a,"video"),P)},st=async(a=Y())=>{if(!a)return!1;const e=a.volume;return a.volume=e/2+.1,await q(0),a.volume!==e},q=a=>new Promise((e,t)=>setTimeout(e,a)),rt=(a=Y())=>typeof(a==null?void 0:a.requestPictureInPicture)=="function",nt=rt();let b;const Et=st().then(a=>(b=a,b)),ot=!!h.WebKitPlaybackTargetAvailabilityEvent,ct=!!h.chrome;function dt(a=[]){return Array.from(a).map((e,t)=>[Number(a.start(t).toFixed(3)),Number(a.end(t).toFixed(3))].join(":")).join(" ")}J("media-controller",V);var Ct=V;export{Ct as default,q as delay,Y as getTestMediaEl,rt as hasPipSupport,st as hasVolumeSupportAsync}; | ||
import z from"./media-container.js";import{defineCustomElement as J}from"./utils/defineCustomElement.js";import{Window as h,Document as u}from"./utils/server-safe-globals.js";import{fullscreenApi as l}from"./utils/fullscreenApi.js";import{constToCamel as C}from"./utils/stringUtils.js";import{containsComposedNode as O}from"./utils/element-utils.js";import{MediaUIEvents as S,MediaUIAttributes as r,TextTrackKinds as M,TextTrackModes as m,AvailabilityStates as p,AttributeToStateChangeEventMap as Z}from"./constants.js";import{stringifyTextTrackList as _,getTextTracksList as f,updateTracksModeTo as D}from"./utils/captions.js";const{MEDIA_PLAY_REQUEST:mt,MEDIA_PAUSE_REQUEST:Tt,MEDIA_MUTE_REQUEST:Mt,MEDIA_UNMUTE_REQUEST:ft,MEDIA_VOLUME_REQUEST:Ut,MEDIA_ENTER_FULLSCREEN_REQUEST:bt,MEDIA_EXIT_FULLSCREEN_REQUEST:Dt,MEDIA_SEEK_REQUEST:gt,MEDIA_PREVIEW_REQUEST:Rt,MEDIA_ENTER_PIP_REQUEST:Pt,MEDIA_EXIT_PIP_REQUEST:Lt,MEDIA_PLAYBACK_RATE_REQUEST:vt}=S;class V extends z{constructor(){super();ot||(this._airplayUnavailable=p.UNSUPPORTED),ct||(this._castUnavailable=p.UNSUPPORTED),nt||(this._pipUnavailable=p.UNSUPPORTED),b!==void 0?b||(this._volumeUnavailable=p.UNSUPPORTED):Et.then(()=>{b||(this._volumeUnavailable=p.UNSUPPORTED,this.propagateMediaState(r.MEDIA_VOLUME_UNAVAILABLE,this._volumeUnavailable))}),this.mediaStateReceivers=[],this.associatedElementSubscriptions=new Map,this.associatedElements=[],this.associateElement(this);const e={MEDIA_PLAY_REQUEST:()=>this.media.play(),MEDIA_PAUSE_REQUEST:()=>this.media.pause(),MEDIA_MUTE_REQUEST:()=>this.media.muted=!0,MEDIA_UNMUTE_REQUEST:()=>{const t=this.media;t.muted=!1,t.volume===0&&(t.volume=.25)},MEDIA_VOLUME_REQUEST:t=>{const i=this.media,s=t.detail;i.volume=s,s>0&&i.muted&&(i.muted=!1);try{h.localStorage.setItem("media-chrome-pref-volume",s.toString())}catch{}},MEDIA_ENTER_FULLSCREEN_REQUEST:()=>{const t=this.media;u.pictureInPictureElement&&u.exitPictureInPicture(),super[l.enter]?super[l.enter]():t.webkitEnterFullscreen?t.webkitEnterFullscreen():t.requestFullscreen?t.requestFullscreen():console.warn("MediaChrome: Fullscreen not supported")},MEDIA_EXIT_FULLSCREEN_REQUEST:()=>{u[l.exit]()},MEDIA_ENTER_PIP_REQUEST:()=>{const t=this.media;!u.pictureInPictureEnabled||(u[l.element]&&u[l.exit](),t.requestPictureInPicture())},MEDIA_EXIT_PIP_REQUEST:()=>{u.pictureInPictureElement&&u.exitPictureInPicture()},MEDIA_ENTER_CAST_REQUEST:()=>{var i;const t=this.media;!((i=globalThis.CastableVideoElement)==null?void 0:i.castEnabled)||(u[l.element]&&u[l.exit](),t.requestCast())},MEDIA_EXIT_CAST_REQUEST:async()=>{var t;((t=globalThis.CastableVideoElement)==null?void 0:t.castElement)&&globalThis.CastableVideoElement.exitCast()},MEDIA_SEEK_REQUEST:t=>{const i=this.media,s=t.detail;(i.readyState>0||i.readyState===void 0)&&(i.currentTime=s)},MEDIA_PLAYBACK_RATE_REQUEST:t=>{this.media.playbackRate=t.detail},MEDIA_PREVIEW_REQUEST:t=>{var d;const i=this.media;if(!i)return;const[s]=f(i,{kind:M.METADATA,label:"thumbnails"});if(!(s&&s.cues))return;const n=t.detail;if(n===null){this.propagateMediaState(r.MEDIA_PREVIEW_IMAGE,void 0),this.propagateMediaState(r.MEDIA_PREVIEW_COORDS,void 0);return}const o=Array.prototype.find.call(s.cues,T=>T.startTime>=n);if(!o)return;const I=/'^(?:[a-z]+:)?\/\//i.test(o.text)||(d=i.querySelector('track[label="thumbnails"]'))==null?void 0:d.src,c=new URL(o.text,I),A=new URLSearchParams(c.hash).get("#xywh");this.propagateMediaState(r.MEDIA_PREVIEW_IMAGE,c.href),this.propagateMediaState(r.MEDIA_PREVIEW_COORDS,A.split(",").join(" "))},MEDIA_SHOW_CAPTIONS_REQUEST:t=>{const i=R(this),{detail:s=[]}=t;D(m.SHOWING,i,s)},MEDIA_DISABLE_CAPTIONS_REQUEST:t=>{const i=R(this),{detail:s=[]}=t;D(m.DISABLED,i,s)},MEDIA_SHOW_SUBTITLES_REQUEST:t=>{const i=g(this),{detail:s=[]}=t;D(m.SHOWING,i,s)},MEDIA_DISABLE_SUBTITLES_REQUEST:t=>{const i=g(this),{detail:s=[]}=t;D(m.DISABLED,i,s)},MEDIA_AIRPLAY_REQUEST:t=>{const{media:i}=this;if(!!i){if(!(i.webkitShowPlaybackTargetPicker&&h.WebKitPlaybackTargetAvailabilityEvent)){console.warn("received a request to select AirPlay but AirPlay is not supported in this environment");return}i.webkitShowPlaybackTargetPicker()}}};if(Object.keys(e).forEach(t=>{const i=`_handle${C(t,!0)}`;this[i]=s=>{if(s.stopPropagation(),!this.media){console.warn("MediaController: No media available.");return}e[t](s,this.media)},this.addEventListener(S[t],this[i])}),this._mediaStatePropagators={"play,pause,emptied":()=>{this.propagateMediaState(r.MEDIA_PAUSED,B(this))},"playing,emptied":()=>{var t;this.propagateMediaState(r.MEDIA_HAS_PLAYED,!((t=this.media)==null?void 0:t.paused))},volumechange:()=>{this.propagateMediaState(r.MEDIA_MUTED,w(this)),this.propagateMediaState(r.MEDIA_VOLUME,Q(this)),this.propagateMediaState(r.MEDIA_VOLUME_LEVEL,F(this))},[l.event]:t=>{const s=!!u[l.element]&&(t==null?void 0:t.target),n=O(this,s);this.propagateMediaState(r.MEDIA_IS_FULLSCREEN,n)},"enterpictureinpicture,leavepictureinpicture":t=>{var s;let i;if(t)i=t.type=="enterpictureinpicture";else{const n=(s=this.getRootNode().pictureInPictureElement)!=null?s:u.pictureInPictureElement;i=this.media&&O(this.media,n)}this.propagateMediaState(r.MEDIA_IS_PIP,i)},"entercast,leavecast,castchange":t=>{var n;const i=(n=globalThis.CastableVideoElement)==null?void 0:n.castElement;let s=this.media&&O(this.media,i);(t==null?void 0:t.type)==="castchange"&&(t==null?void 0:t.detail)==="CONNECTING"&&(s="connecting"),this.propagateMediaState(r.MEDIA_IS_CASTING,s)},"timeupdate,loadedmetadata":()=>{this.propagateMediaState(r.MEDIA_CURRENT_TIME,G(this))},"durationchange,loadedmetadata,emptied":()=>{this.propagateMediaState(r.MEDIA_DURATION,W(this))},"loadedmetadata,emptied,progress":()=>{var t;this.propagateMediaState(r.MEDIA_SEEKABLE,(t=H(this))==null?void 0:t.join(":"))},"progress,emptied":()=>{var t;this.propagateMediaState(r.MEDIA_BUFFERED,dt((t=this.media)==null?void 0:t.buffered))},"ratechange,loadstart":()=>{this.propagateMediaState(r.MEDIA_PLAYBACK_RATE,j(this))},"waiting,playing,emptied":()=>{var i;const t=((i=this.media)==null?void 0:i.readyState)<3;this.propagateMediaState(r.MEDIA_LOADING,t)}},this._airplayUnavailable!==p.UNSUPPORTED){const t=i=>{(i==null?void 0:i.availability)==="available"?this._airplayUnavailable=void 0:(i==null?void 0:i.availability)==="not-available"&&(this._airplayUnavailable=p.UNAVAILABLE),this.propagateMediaState(r.MEDIA_AIRPLAY_UNAVAILABLE,this._airplayUnavailable)};this._mediaStatePropagators.webkitplaybacktargetavailabilitychanged=t}if(this._castUnavailable!==p.UNSUPPORTED){const t=()=>{var s;const i=(s=globalThis.CastableVideoElement)==null?void 0:s.castState;(i==null?void 0:i.includes("CONNECT"))?this._castUnavailable=void 0:this._castUnavailable=p.UNAVAILABLE,this.propagateMediaState(r.MEDIA_CAST_UNAVAILABLE,this._castUnavailable)};this._mediaStatePropagators.castchange=t}this._textTrackMediaStatePropagators={"addtrack,removetrack,loadstart":()=>{this.propagateMediaState(r.MEDIA_CAPTIONS_LIST,_(R(this))||void 0),this.propagateMediaState(r.MEDIA_SUBTITLES_LIST,_(g(this))||void 0),this.propagateMediaState(r.MEDIA_CAPTIONS_SHOWING,_(y(this))||void 0),this.propagateMediaState(r.MEDIA_SUBTITLES_SHOWING,_(k(this))||void 0)},change:()=>{this.propagateMediaState(r.MEDIA_CAPTIONS_SHOWING,_(y(this))||void 0),this.propagateMediaState(r.MEDIA_SUBTITLES_SHOWING,_(k(this))||void 0)}}}mediaSetCallback(e){super.mediaSetCallback(e),Object.keys(this._mediaStatePropagators).forEach(t=>{const i=t.split(","),s=this._mediaStatePropagators[t];i.forEach(n=>{(n==l.event?this.getRootNode():e).addEventListener(n,s)}),s()}),Object.entries(this._textTrackMediaStatePropagators).forEach(([t,i])=>{t.split(",").forEach(n=>{e.textTracks&&e.textTracks.addEventListener(n,i)}),i()});try{const t=h.localStorage.getItem("media-chrome-pref-volume");t!==null&&(e.volume=t)}catch(t){console.debug("Error getting volume pref",t)}}mediaUnsetCallback(e){super.mediaUnsetCallback(e),Object.keys(this._mediaStatePropagators).forEach(t=>{const i=t.split(","),s=this._mediaStatePropagators[t];i.forEach(n=>{(n==l.event?this.getRootNode():e).removeEventListener(n,s)})}),Object.entries(this._textTrackMediaStatePropagators).forEach(([t,i])=>{t.split(",").forEach(n=>{e.textTracks&&e.textTracks.removeEventListener(n,i)}),i()}),this.propagateMediaState(r.MEDIA_PAUSED,!0)}propagateMediaState(e,t){E(this.mediaStateReceivers,e,t);const i=new h.CustomEvent(Z[e],{composed:!0,bubbles:!0,detail:t});this.dispatchEvent(i)}associateElement(e){if(!e)return;const{associatedElementSubscriptions:t}=this;if(t.has(e))return;const i=this.registerMediaStateReceiver.bind(this),s=this.unregisterMediaStateReceiver.bind(this),n=it(e,i,s);Object.keys(S).forEach(o=>{e.addEventListener(S[o],this[`_handle${C(o,!0)}`])}),t.set(e,n)}unassociateElement(e){if(!e)return;const{associatedElementSubscriptions:t}=this;if(!t.has(e))return;t.get(e)(),t.delete(e),Object.keys(S).forEach(s=>{e.removeEventListener(S[s],this[`_handle${C(s,!0)}`])})}registerMediaStateReceiver(e){var s;if(!e)return;const t=this.mediaStateReceivers;t.indexOf(e)>-1||(t.push(e),E([e],r.MEDIA_VOLUME_UNAVAILABLE,this._volumeUnavailable),E([e],r.MEDIA_AIRPLAY_UNAVAILABLE,this._airplayUnavailable),E([e],r.MEDIA_CAST_UNAVAILABLE,this._castUnavailable),E([e],r.MEDIA_PIP_UNAVAILABLE,this._pipUnavailable),this.media&&(E([e],r.MEDIA_CAPTIONS_LIST,_(R(this))||void 0),E([e],r.MEDIA_SUBTITLES_LIST,_(g(this))||void 0),E([e],r.MEDIA_CAPTIONS_SHOWING,_(y(this))||void 0),E([e],r.MEDIA_SUBTITLES_SHOWING,_(k(this))||void 0),E([e],r.MEDIA_PAUSED,B(this)),E([e],r.MEDIA_MUTED,w(this)),E([e],r.MEDIA_VOLUME,Q(this)),E([e],r.MEDIA_VOLUME_LEVEL,F(this)),E([e],r.MEDIA_IS_FULLSCREEN,this.hasAttribute(r.MEDIA_IS_FULLSCREEN)),E([e],r.MEDIA_IS_CASTING,this.hasAttribute(r.MEDIA_IS_CASTING)),E([e],r.MEDIA_CURRENT_TIME,G(this)),E([e],r.MEDIA_DURATION,W(this)),E([e],r.MEDIA_SEEKABLE,(s=H(this))==null?void 0:s.join(":")),E([e],r.MEDIA_PLAYBACK_RATE,j(this))))}unregisterMediaStateReceiver(e){const t=this.mediaStateReceivers,i=t.indexOf(e);i<0||t.splice(i,1)}}const B=a=>a.media?a.media.paused:!0,w=a=>!!(a.media&&a.media.muted),Q=a=>{const e=a.media;return e?e.volume:1},F=a=>{let e="high";if(!a.media)return e;const{muted:t,volume:i}=a.media;return i===0||t?e="off":i<.5?e="low":i<.75&&(e="medium"),e},G=a=>{const e=a.media;return e?e.currentTime:0},W=a=>{const e=a==null?void 0:a.media;return Number.isFinite(e==null?void 0:e.duration)?e.duration:NaN},H=a=>{var s;const e=a==null?void 0:a.media;if(!((s=e==null?void 0:e.seekable)==null?void 0:s.length))return;const t=e.seekable.start(0),i=e.seekable.end(e.seekable.length-1);if(!(!t&&!i))return[Number(t.toFixed(3)),Number(i.toFixed(3))]},j=a=>{const e=a.media;return e?e.playbackRate:1},g=a=>f(a.media,{kind:M.SUBTITLES}),R=a=>f(a.media,{kind:M.CAPTIONS}),k=a=>f(a.media,{kind:M.SUBTITLES,mode:m.SHOWING}),y=a=>f(a.media,{kind:M.CAPTIONS,mode:m.SHOWING}),tt=Object.values(r),K=a=>{var i,s,n,o;let{observedAttributes:e}=a.constructor;!e&&((i=a.nodeName)==null?void 0:i.includes("-"))&&(h.customElements.upgrade(a),{observedAttributes:e}=a.constructor);const t=(o=(n=(s=a==null?void 0:a.getAttribute)==null?void 0:s.call(a,r.MEDIA_CHROME_ATTRIBUTES))==null?void 0:n.split)==null?void 0:o.call(n,/\s+/);return Array.isArray(e||t)?(e||t).filter(I=>tt.includes(I)):[]},N=a=>!!K(a).length,et=async(a,e,t)=>(a.isConnected||await q(0),t==null?a.removeAttribute(e):typeof t=="boolean"?t?a.setAttribute(e,""):a.removeAttribute(e):Number.isNaN(t)?a.removeAttribute(e):a.setAttribute(e,t)),at=a=>{var e;return!!((e=a.closest)==null?void 0:e.call(a,'*[slot="media"]'))},U=(a,e)=>{if(at(a))return;const t=(s,n)=>{var A,d;N(s)&&n(s);const{children:o=[]}=s!=null?s:{},I=(d=(A=s==null?void 0:s.shadowRoot)==null?void 0:A.children)!=null?d:[];[...o,...I].forEach(T=>U(T,n))},i=a==null?void 0:a.nodeName.toLowerCase();if(i.includes("-")&&!N(a)){h.customElements.whenDefined(i).then(()=>{t(a,e)});return}t(a,e)},E=(a,e,t)=>{a.forEach(i=>{!K(i).includes(e)||et(i,e,t)})},it=(a,e,t)=>{U(a,e);const i=c=>{var d;const A=(d=c==null?void 0:c.composedPath()[0])!=null?d:c.target;e(A)},s=c=>{var d;const A=(d=c==null?void 0:c.composedPath()[0])!=null?d:c.target;t(A)};a.addEventListener(S.REGISTER_MEDIA_STATE_RECEIVER,i),a.addEventListener(S.UNREGISTER_MEDIA_STATE_RECEIVER,s);const n=(c,A)=>{c.forEach(d=>{const{addedNodes:T=[],removedNodes:X=[],type:x,target:L,attributeName:$}=d;x==="childList"?(Array.prototype.forEach.call(T,v=>U(v,e)),Array.prototype.forEach.call(X,v=>U(v,t))):x==="attributes"&&$===r.MEDIA_CHROME_ATTRIBUTES&&(N(L)?e(L):t(L))})},o=new MutationObserver(n);return o.observe(a,{childList:!0,attributes:!0,subtree:!0}),()=>{U(a,t),o.disconnect(),a.removeEventListener(S.REGISTER_MEDIA_STATE_RECEIVER,i),a.removeEventListener(S.UNREGISTER_MEDIA_STATE_RECEIVER,s)}};let P;const Y=()=>{var a,e;return P||(P=(e=(a=u)==null?void 0:a.createElement)==null?void 0:e.call(a,"video"),P)},st=async(a=Y())=>{if(!a)return!1;const e=a.volume;return a.volume=e/2+.1,await q(0),a.volume!==e},q=a=>new Promise((e,t)=>setTimeout(e,a)),rt=(a=Y())=>typeof(a==null?void 0:a.requestPictureInPicture)=="function",nt=rt();let b;const Et=st().then(a=>(b=a,b)),ot=!!h.WebKitPlaybackTargetAvailabilityEvent,ct=!!h.chrome;function dt(a=[]){return Array.from(a).map((e,t)=>[Number(a.start(t).toFixed(3)),Number(a.end(t).toFixed(3))].join(":")).join(" ")}J("media-controller",V);var Ct=V;export{Ct as default,q as delay,Y as getTestMediaEl,rt as hasPipSupport,st as hasVolumeSupportAsync}; | ||
//# sourceMappingURL=media-controller.js.map |
{ | ||
"name": "media-chrome", | ||
"version": "0.6.9-canary.4-59f4ed4", | ||
"version": "0.6.9-canary.5-97d20f7", | ||
"description": "Custom elements (web components) for making audio and video player controls that look great in your website or app.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1321598