mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 04:01:20 -08:00
Refactor code structure for improved readability and maintainability
This commit is contained in:
1 parent
4a0fbda3c4
commit
0bb4e1acdb
214 files changed
+462
-415
No files matched your search
@@ -1,8 +1,8 @@
|
||||
|
||||
/*!
|
||||
* artplayer-plugin-chapter.js v1.0.1
|
||||
* artplayer-plugin-chapter.js v1.0.2
|
||||
* Github: https://github.com/zhw2590582/ArtPlayer
|
||||
* (c) 2017-2025 Harvey Zack
|
||||
* (c) 2017-2026 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,r,n,a,o,i,l){var d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},p="function"==typeof d[n]&&d[n],s=p.i||{},u=p.cache||{},c="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(t,r){if(!u[t]){if(!e[t]){if(a[t])return a[t];var o="function"==typeof d[n]&&d[n];if(!r&&o)return o(t,!0);if(p)return p(t,!0);if(c&&"string"==typeof t)return c(t);var i=Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}s.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},s.cache={};var l=u[t]=new f.Module(t);e[t][0].call(l.exports,s,l,l.exports,d)}return u[t].exports;function s(e){var t=s.resolve(e);if(!1===t)return{};if(Array.isArray(t)){var r={__esModule:!0};return t.forEach(function(e){var t=e[0],n=e[1],a=e[2]||e[0],o=f(n);"*"===t?Object.keys(o).forEach(function(e){"default"===e||"__esModule"===e||Object.prototype.hasOwnProperty.call(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:function(){return o[e]}})}):"*"===a?Object.defineProperty(r,t,{enumerable:!0,value:o}):Object.defineProperty(r,t,{enumerable:!0,get:function(){return"default"===a?o.__esModule?o.default:o:o[a]}})}),r}return f(t)}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.require=c,this.exports={}},f.modules=e,f.cache=u,f.parent=p,f.distDir=void 0,f.publicUrl=void 0,f.devServer=void 0,f.i=s,f.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return d[n]}}),d[n]=f;for(var h=0;h<t.length;h++)f(t[h]);if(r){var y=f(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=y:"function"==typeof define&&define.amd&&define(function(){return y})}}({"7hySu":[function(e,t,r,n){var a=e("@parcel/transformer-js/src/esmodule-helpers.js");a.defineInteropFlag(r),a.export(r,"default",function(){return l});var o=e("bundle-text:./style.less"),i=a.interopDefault(o);function l(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){var r=t.template.$player,n=t.constructor.utils,a=n.setStyle,o=n.append,i=n.clamp,l=n.query,d=n.isMobile,p=n.addClass,s=n.removeClass,u=null,c=[],f=t.query(".art-control-progress"),h=t.query(".art-control-progress-inner"),y=o(h,'<div class="art-chapters"></div>'),g=o(h,'<div class="art-chapter-title"></div>');function v(e){var t=e.$chapter,r=e.width,n=t.dataset.title.trim();if(n){a(g,"display","flex"),g.textContent=n;var o=g.clientWidth;r<=o/2?a(g,"left",0):r>h.clientWidth-o/2?a(g,"left","".concat(h.clientWidth-o,"px")):a(g,"left","".concat(r-o/2,"px"))}else a(g,"display","none")}function m(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if((c=[],y.textContent="",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 n=0;n<e.length;n++){var a=e[n],d=e[n+1];if(a.end===1/0&&(a.end=t.duration),"number"!=typeof a.start||"number"!=typeof a.end||"string"!=typeof a.title)throw TypeError("Illegal chapter data type");if(a.start<0||a.end>t.duration||a.start>=a.end||d&&a.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(y,'\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 '),n=i(e.start,0,t.duration),a=i(e.end,0,t.duration),d=a-n,p=d/t.duration;return r.dataset.start=n,r.dataset.end=a,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,n){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=y.clientWidth*r,m=t.duration*r,b=Number.parseFloat(l.dataset.duration),x=Number.parseFloat(l.dataset.start),w=Number.parseFloat(l.dataset.end);if(m<x&&a(f,"width",0),m>w&&a(f,"width","100%"),m>=x&&m<=w){var O=(m-x)/b;a(f,"width","".concat(100*O,"%")),d?"played"===e&&n&&(v({$chapter:l,width:h}),clearTimeout(u),u=setTimeout(function(){a(g,"display","none")},500)):"hover"===e&&v({$chapter:l,width:h})}}}),d||t.proxy(f,"mouseleave",function(){c.length&&a(g,"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 d="artplayer-plugin-chapter",p=document.getElementById(d);p||((p=Line truncated
|
||||
!function(t,e,r,a,n,o,i,l){var p="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:{},d="function"==typeof p[a]&&p[a],s=d.i||{},u=d.cache||{},c="u">typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(e,r){if(!u[e]){if(!t[e]){if(n[e])return n[e];var o="function"==typeof p[a]&&p[a];if(!r&&o)return o(e,!0);if(d)return d(e,!0);if(c&&"string"==typeof e)return c(e);var i=Error("Cannot find module '"+e+"'");throw i.code="MODULE_NOT_FOUND",i}s.resolve=function(r){var a=t[e][1][r];return null!=a?a:r},s.cache={};var l=u[e]=new f.Module(e);t[e][0].call(l.exports,s,l,l.exports,p)}return u[e].exports;function s(t){var e=s.resolve(t);if(!1===e)return{};if(Array.isArray(e)){var r={__esModule:!0};return e.forEach(function(t){var e=t[0],a=t[1],n=t[2]||t[0],o=f(a);"*"===e?Object.keys(o).forEach(function(t){"default"===t||"__esModule"===t||Object.prototype.hasOwnProperty.call(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:function(){return o[t]}})}):"*"===n?Object.defineProperty(r,e,{enumerable:!0,value:o}):Object.defineProperty(r,e,{enumerable:!0,get:function(){return"default"===n?o.__esModule?o.default:o:o[n]}})}),r}return f(e)}}f.isParcelRequire=!0,f.Module=function(t){this.id=t,this.bundle=f,this.require=c,this.exports={}},f.modules=t,f.cache=u,f.parent=d,f.distDir=void 0,f.publicUrl=void 0,f.devServer=void 0,f.i=s,f.register=function(e,r){t[e]=[function(t,e){e.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return p[a]}}),p[a]=f;for(var h=0;h<e.length;h++)f(e[h]);if(r){var g=f(r);"object"==typeof exports&&"u">typeof module?module.exports=g:"function"==typeof define&&define.amd&&define(function(){return g})}}({"7hySu":[function(t,e,r,a){var n=t("@parcel/transformer-js/src/esmodule-helpers.js");n.defineInteropFlag(r),n.export(r,"default",function(){return l});var o=t("bundle-text:./style.less"),i=n.interopDefault(o);function l(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e){var r=e.template.$player,a=e.constructor.utils,n=a.setStyle,o=a.append,i=a.clamp,l=a.query,p=a.addClass,d=a.removeClass,s=[],u=e.query(".art-control-progress-inner"),c=o(u,'<div class="art-chapters"></div>'),f=o(u,'<div class="art-chapter-title"></div>');function h(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if((s=[],c.textContent="",d(r,"artplayer-plugin-chapter"),Array.isArray(t)&&t.length)&&e.duration){t=t.sort(function(t,e){return t.start-e.start});for(var a=0;a<t.length;a++){var n=t[a],u=t[a+1];if(n.end===1/0&&(n.end=e.duration),"number"!=typeof n.start||"number"!=typeof n.end||"string"!=typeof n.title)throw TypeError("Illegal chapter data type");if(n.start<0||n.end>e.duration||n.start>=n.end||u&&n.end>u.start)throw Error("Illegal chapter time point")}t[0].start>0&&t.unshift({start:0,end:t[0].start,title:""}),t[t.length-1].end<e.duration&&t.push({start:t[t.length-1].end,end:e.duration,title:""});for(var f=0;f<t.length-1;f++)t[f].end!==t[f+1].start&&t.splice(f+1,0,{start:t[f].end,end:t[f+1].start,title:""});s=t.map(function(t){var r=o(c,'\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(t.start,0,e.duration),n=i(t.end,0,e.duration),p=n-a,d=p/e.duration;return r.dataset.start=a,r.dataset.end=n,r.dataset.duration=p,r.dataset.title=t.title.trim(),r.style.width="".concat(100*d,"%"),{$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"),e.emit("setBar","loaded",e.loaded||0)}}return e.on("setBar",function(t,r){if(s.length)for(var a=0;a<s.length;a++){var o=s[a],i=o.$chapter,l=o.$loaded,p=o.$played,d={hover:o.$hover,loaded:l,played:p}[t];if(!d)return;var h=c.clientWidth*r,g=e.duration*r,y=Number.parseFloat(i.dataset.duration),v=Number.parseFloat(i.dataset.start),m=Number.parseFloat(i.dataset.end);if(g<v&&n(d,"width",0),g>m&&n(d,"width","100%"),g>=v&&g<=m){var b=(g-v)/y;n(d,"width","".concat(100*b,"%")),"hover"===t&&h>0&&function(t){var e=t.$chapter,r=t.width,a=e.dataset.title.trim();if(a){f.textContent=a;var o=f.clientWidth;r<=o/2?n(f,"left",0):r>u.clientWidth-o/2?n(f,"left","".concat(u.clientWidth-o,"px")):n(f,"left","".concat(r-o/2,"px"))}}({$chapter:i,width:h})}}}),e.once("video:loadedmetadata",function(){return h(t.chapters)}),{name:"artplayerPluginChapter",update:function(t){return h(t.chapters)}}}}if("u">typeof document){var p="artplayer-plugin-chapter",d=document.getElementById(p);d||((d=document.createElement("style")).id=p,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",function(){document.head.appendChild(d)}):(document.head||document.documentElement).appendChild(d)),d.textContent=i.default}"u">typeof window&&(window.artplayerPluginChapter=l)},{"bundle-text:./style.less":"35ZxU","@parcel/transformer-Line truncated
|
||||
Reference in new issue
Block a user