Bilibili-Evolved/registry/dist/components/video/player/intersection-actions.js
github-actions[bot] 85a0e37bf0 CI build
2023-07-13 01:07:58 +00:00

1 line
2.3 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["video/player/intersection-actions"]=t():e["video/player/intersection-actions"]=t()}(globalThis,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{component:()=>d});const o=coreApis.componentApis.define,n=coreApis.componentApis.video.playerAgent,i=coreApis.componentApis.video.playerLight,a=coreApis.observer,s=coreApis.settings,r=coreApis.utils.urls;var p;!function(e){e.Top="视频顶部",e.Medium="视频中间",e.Bottom="视频底部"}(p||(p={}));const d=(0,o.defineComponentMetadata)({name:"playerIntersectionActions",author:{name:"FoundTheWOUT",link:"https://github.com/FoundTheWOUT"},tags:[componentsTags.video],urlInclude:r.allVideoUrls,entry:async e=>{let{settings:{options:t},metadata:o}=e;const r=t;Promise.resolve().then((async()=>{const{query:{video:e}}=n.playerAgent,t=await e.element(),d=document.getElementById("video-player")??(dq(".player-wrap")||dq(".player-module"));let c,l=!0;function u(e){switch(e){case p.Top:return 1;case p.Medium:return.5;case p.Bottom:return 0;default:return.5}}function m(){c.observe(d)}function y(){c.unobserve(d)}const g=e=>new IntersectionObserver((e=>{let[o]=e;o.isIntersecting?l||(l=!0,r.pause&&t.paused&&t.play(),r.light&&(0,s.getComponentSettings)("playerAutoLight").enabled&&!r.pause&&!t.paused&&(0,i.lightOff)()):(t.paused||(l=!1),r.pause&&!t.paused&&t.pause(),r.light&&(0,s.getComponentSettings)("playerAutoLight").enabled&&!r.pause&&(0,i.lightOn)())}),{threshold:u(e||r.triggerLocation)});(0,s.addComponentListener)(`${o.name}.triggerLocation`,(e=>{y(),c=g(e),m()})),c=g(),(0,a.videoChange)((async()=>{n.playerAgent.isAutoPlay()&&m(),t.addEventListener("play",m),t.addEventListener("ended",y)}))}))},displayName:"播放器位置动作",description:{"zh-CN":"设置当播放器移出视图的位置变化时执行的动作."},options:{triggerLocation:{defaultValue:p.Medium,displayName:"触发位置",dropdownEnum:p},pause:{defaultValue:!1,displayName:"自动暂停"},light:{defaultValue:!0,displayName:"自动开灯"}},commitHash:"cd5e421d84b8e446ac214166757f99b5ae8cdbfc",coreVersion:"2.7.3"});return t=t.component})()));