mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-09 03:46:16 -08:00
8 lines
6.5 KiB
JavaScript
8 lines
6.5 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})}}({"9rqDr":[function(e,t,r){var a=e("@parcel/transformer-js/src/esmodule-helpers.js");a.defineInteropFlag(r),a.export(r,"default",function(){return i});var n=e("bundle-text:./style.less"),o=a.interopDefault(n);function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){var r=t.template.$player,a=t.constructor.utils,n=a.setStyle,o=a.append,i=a.clamp,l=a.query,d=a.isMobile,p=a.addClass,s=a.removeClass,u=null,c=[],f=t.query(".art-control-progress"),h=t.query(".art-control-progress-inner"),g=o(h,'<div class="art-chapters"></div>'),y=o(h,'<div class="art-chapter-title"></div>');function v(e){var t=e.$chapter,r=e.width,a=t.dataset.title.trim();if(a){n(y,"display","flex"),y.innerText=a;var o=y.clientWidth;r<=o/2?n(y,"left",0):r>h.clientWidth-o/2?n(y,"left","".concat(h.clientWidth-o,"px")):n(y,"left","".concat(r-o/2,"px"))}else n(y,"display","none")}function m(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(c=[],g.innerText="",s(r,"artplayer-plugin-chapter"),Array.isArray(e)&&e.length&&t.duration){e=e.sort(function(e,t){return e.start-t.start});for(var a=0;a<e.length;a++){var n=e[a],d=e[a+1];if(n.end===1/0&&(n.end=t.duration),"number"!=typeof n.start||"number"!=typeof n.end||"string"!=typeof n.title)throw Error("Illegal chapter data type");if(n.start<0||n.end>t.duration||n.start>=n.end||d&&n.end>d.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(var u=0;u<e.length-1;u++)e[u].end!==e[u+1].start&&e.splice(u+1,0,{start:e[u].end,end:e[u+1].start,title:""});c=e.map(function(e){var r=o(g,'\n <div class="art-chapter">\n<div class="art-chapter-inner">\n<div class="art-progress-hover"></div>\n<div class="art-progress-loaded"></div>\n<div class="art-progress-played"></div>\n</div>\n</div>\n '),a=i(e.start,0,t.duration),n=i(e.end,0,t.duration),d=n-a,p=d/t.duration;return r.dataset.start=a,r.dataset.end=n,r.dataset.duration=d,r.dataset.title=e.title.trim(),r.style.width="".concat(100*p,"%"),{$chapter:r,$hover:l(".art-progress-hover",r),$loaded:l(".art-progress-loaded",r),$played:l(".art-progress-played",r)}}),p(r,"artplayer-plugin-chapter"),t.emit("setBar","loaded",t.loaded||0)}}return t.on("setBar",function(e,r,a){if(c.length)for(var o=0;o<c.length;o++){var i=c[o],l=i.$chapter,p=i.$loaded,s=i.$played,f={hover:i.$hover,loaded:p,played:s}[e];if(!f)return;var h=g.clientWidth*r,m=t.duration*r,b=parseFloat(l.dataset.duration),x=parseFloat(l.dataset.start),w=parseFloat(l.dataset.end);if(m<x&&n(f,"width",0),m>w&&n(f,"width","100%"),m>=x&&m<=w){var j=(m-x)/b;n(f,"width","".concat(100*j,"%")),d?"played"===e&&a&&(v({$chapter:l,width:h}),clearTimeout(u),u=setTimeout(function(){n(y,"display","none")},500)):"hover"===e&&v({$chapter:l,width:h})}}}),d||t.proxy(f,"mouseleave",function(){c.length&&n(y,"display","none")}),t.once("video:loadedmetadata",function(){return m(e.chapters)}),{name:"artplayerPluginChapter",update:function(e){return m(e.chapters)}}}}if("undefined"!=typeof document){var l="artplayer-plugin-chapter",d=document.getElementById(l);if(d)d.textContent=o.default;else{var p=document.createElement("style");p.id=l,p.textContent=o.default,document.head.appendChild(p)}}"undefined"!=typeof window&&(window.artplayerPluginChapter=i)},{"bundle-text:./style.less":"4jhrf","@parcel/transformer-js/src/esmodule-helpers.js":"iWrD0"}],"4jhrf":[function(e,t,r){t.exports=".artplayer-plugin-chapter .art-control-progress-inner{background-color:transparent!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;top:0;bottom:0;left:0;right: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}"},{}],iWrD0:[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})}},{}]},["9rqDr"],"9rqDr","parcelRequire4dc0"); |