mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-09 03:39:41 -08:00
8 lines
6.2 KiB
JavaScript
8 lines
6.2 KiB
JavaScript
|
|
/*!
|
|
* artplayer-plugin-chapter.js v1.0.0
|
|
* Github: https://github.com/zhw2590582/ArtPlayer
|
|
* (c) 2017-2024 Harvey Zack
|
|
* Released under the MIT License.
|
|
*/
|
|
!function(e,t,r,a,n){var o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},i="function"==typeof o[a]&&o[a],l=i.cache||{},d="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(t,r){if(!l[t]){if(!e[t]){var n="function"==typeof o[a]&&o[a];if(!r&&n)return n(t,!0);if(i)return i(t,!0);if(d&&"string"==typeof t)return d(t);var s=Error("Cannot find module '"+t+"'");throw s.code="MODULE_NOT_FOUND",s}c.resolve=function(r){var a=e[t][1][r];return null!=a?a:r},c.cache={};var u=l[t]=new p.Module(t);e[t][0].call(u.exports,c,u,u.exports,this)}return l[t].exports;function c(e){var t=c.resolve(e);return!1===t?{}:p(t)}}p.isParcelRequire=!0,p.Module=function(e){this.id=e,this.bundle=p,this.exports={}},p.modules=e,p.cache=l,p.parent=i,p.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(p,"root",{get:function(){return o[a]}}),o[a]=p;for(var s=0;s<t.length;s++)p(t[s]);if(r){var u=p(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=u:"function"==typeof define&&define.amd&&define(function(){return u})}}({eSFsM:[function(e,t,r){var a=e("@parcel/transformer-js/src/esmodule-helpers.js");a.defineInteropFlag(r),a.export(r,"default",()=>i);var n=e("bundle-text:./style.less"),o=a.interopDefault(n);function i(e={}){return t=>{let{$player:r}=t.template,{setStyle:a,append:n,clamp:o,query:i,isMobile:l,addClass:d,removeClass:p}=t.constructor.utils,s=`<div class="art-chapter"><div class="art-chapter-inner"><div class="art-progress-hover"></div><div class="art-progress-loaded"></div><div class="art-progress-played"></div></div></div>`,u=null,c=[],f=t.query(".art-control-progress"),h=t.query(".art-control-progress-inner"),g=n(h,'<div class="art-chapters"></div>'),y=n(h,'<div class="art-chapter-title"></div>');function m({$chapter:e,width:t}){let r=e.dataset.title.trim();if(r){a(y,"display","flex"),y.innerText=r;let e=y.clientWidth;t<=e/2?a(y,"left",0):t>h.clientWidth-e/2?a(y,"left",`${h.clientWidth-e}px`):a(y,"left",`${t-e/2}px`)}else a(y,"display","none")}function v(e=[]){if(c=[],g.innerText="",p(r,"artplayer-plugin-chapter"),Array.isArray(e)&&e.length&&t.duration){e=e.sort((e,t)=>e.start-t.start);for(let r=0;r<e.length;r++){let a=e[r],n=e[r+1];if(a.end===1/0&&(a.end=t.duration),"number"!=typeof a.start||"number"!=typeof a.end||"string"!=typeof a.title)throw Error("Illegal chapter data type");if(a.start<0||a.end>t.duration||a.start>=a.end||n&&a.end>n.start)throw Error("Illegal chapter time point")}e[0].start>0&&e.unshift({start:0,end:e[0].start,title:""}),e[e.length-1].end<t.duration&&e.push({start:e[e.length-1].end,end:t.duration,title:""});for(let t=0;t<e.length-1;t++)e[t].end!==e[t+1].start&&e.splice(t+1,0,{start:e[t].end,end:e[t+1].start,title:""});c=e.map(e=>{let r=n(g,s),a=o(e.start,0,t.duration),l=o(e.end,0,t.duration),d=l-a,p=d/t.duration;return r.dataset.start=a,r.dataset.end=l,r.dataset.duration=d,r.dataset.title=e.title.trim(),r.style.width=`${100*p}%`,{$chapter:r,$hover:i(".art-progress-hover",r),$loaded:i(".art-progress-loaded",r),$played:i(".art-progress-played",r)}}),d(r,"artplayer-plugin-chapter"),t.emit("setBar","loaded",t.loaded||0)}}return t.on("setBar",(e,r,n)=>{if(c.length)for(let o=0;o<c.length;o++){let{$chapter:i,$loaded:d,$played:p,$hover:s}=c[o],f={hover:s,loaded:d,played:p}[e];if(!f)return;let h=g.clientWidth*r,v=t.duration*r,x=parseFloat(i.dataset.duration),b=parseFloat(i.dataset.start),w=parseFloat(i.dataset.end);if(v<b&&a(f,"width",0),v>w&&a(f,"width","100%"),v>=b&&v<=w){let t=(v-b)/x;a(f,"width",`${100*t}%`),l?"played"===e&&n&&(m({$chapter:i,width:h}),clearTimeout(u),u=setTimeout(()=>{a(y,"display","none")},500)):"hover"===e&&m({$chapter:i,width:h})}}}),l||t.proxy(f,"mouseleave",()=>{c.length&&a(y,"display","none")}),t.once("video:loadedmetadata",()=>v(e.chapters)),{name:"artplayerPluginChapter",update:({chapters:e})=>v(e)}}}if("undefined"!=typeof document){let e="artplayer-plugin-chapter",t=document.getElementById(e);if(t)t.textContent=o.default;else{let t=document.createElement("style");t.id=e,t.textContent=o.default,document.head.appendChild(t)}}"undefined"!=typeof window&&(window.artplayerPluginChapter=i)},{"bundle-text:./style.less":"9CXLk","@parcel/transformer-js/src/esmodule-helpers.js":"9pCYc"}],"9CXLk":[function(e,t,r){t.exports=".artplayer-plugin-chapter .art-control-progress-inner{background-color:#0000!important;height:100%!important}.artplayer-plugin-chapter .art-control-progress-inner>.art-progress-hover,.artplayer-plugin-chapter .art-control-progress-inner>.art-progress-loaded,.artplayer-plugin-chapter .art-control-progress-inner>.art-progress-played{display:none!important}.artplayer-plugin-chapter .art-control-thumbnails{bottom:calc(var(--art-bottom-gap) + 64px)!important}.artplayer-plugin-chapter .art-chapters{z-index:0;align-items:center;gap:4px;height:100%;display:flex;position:absolute;inset:0;transform:scaleY(1.25)}.artplayer-plugin-chapter .art-chapters .art-chapter{align-items:center;height:100%;display:flex}.artplayer-plugin-chapter .art-chapters .art-chapter .art-chapter-inner{cursor:pointer;transition:height var(--art-transition-duration)ease;background-color:var(--art-progress-color);border-radius:10px;width:100%;height:50%;position:relative;overflow:hidden}.artplayer-plugin-chapter .art-chapters .art-chapter:hover .art-chapter-inner{height:100%}.artplayer-plugin-chapter .art-chapter-title{z-index:70;border-radius:var(--art-border-radius);white-space:nowrap;background-color:var(--art-tip-background);padding:3px 5px;font-size:14px;line-height:1;display:none;position:absolute;top:-50px;left:0}"},{}],"9pCYc":[function(e,t,r){r.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},r.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.exportAll=function(e,t){return Object.keys(e).forEach(function(r){"default"===r||"__esModule"===r||Object.prototype.hasOwnProperty.call(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[r]}})}),t},r.export=function(e,t,r){Object.defineProperty(e,t,{enumerable:!0,get:r})}},{}]},["eSFsM"],"eSFsM","parcelRequire4dc0"); |