mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 13:51:20 -08:00
Refactor code structure for improved readability and maintainability
This commit is contained in:
1 parent
4bdad1675b
commit
1ece90c582
14 files changed
+17
-18
No files matched your search
@@ -5,5 +5,5 @@
|
||||
* (c) 2017-2025 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,n,r,o,i,u,l){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s="function"==typeof a[r]&&a[r],d=s.i||{},f=s.cache||{},c="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(t,n){if(!f[t]){if(!e[t]){if(o[t])return o[t];var i="function"==typeof a[r]&&a[r];if(!n&&i)return i(t,!0);if(s)return s(t,!0);if(c&&"string"==typeof t)return c(t);var u=Error("Cannot find module '"+t+"'");throw u.code="MODULE_NOT_FOUND",u}d.resolve=function(n){var r=e[t][1][n];return null!=r?r:n},d.cache={};var l=f[t]=new p.Module(t);e[t][0].call(l.exports,d,l,l.exports,a)}return f[t].exports;function d(e){var t=d.resolve(e);return!1===t?{}:p(t)}}p.isParcelRequire=!0,p.Module=function(e){this.id=e,this.bundle=p,this.require=c,this.exports={}},p.modules=e,p.cache=f,p.parent=s,p.distDir=void 0,p.publicUrl=void 0,p.devServer=void 0,p.i=d,p.register=function(t,n){e[t]=[function(e,t){t.exports=n},{}]},Object.defineProperty(p,"root",{get:function(){return a[r]}}),a[r]=p;for(var y=0;y<t.length;y++)p(t[y]);if(n){var w=p(n);"object"==typeof exports&&"undefined"!=typeof module?module.exports=w:"function"==typeof define&&define.amd&&define(function(){return w})}}({"40eeC":[function(e,t,n,r){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");function i(e={}){let{interval:t=5e3,sampleRate:n=16e3,callback:r=()=>null}=e;return e=>{let o=!1,i=null,u=null,l=null,a=[],s=null,d=` class RecorderProcessor extends AudioWorkletProcessor { process(inputs) { const input = inputs[0]; if (input && input[0]) { this.port.postMessage(input[0]); } return true; } } registerProcessor('recorder-processor', RecorderProcessor); `,f=()=>{let e=new Blob([d],{type:"application/javascript"});return URL.createObjectURL(e)};async function c(){if(o)return;o=!0,"suspended"===(i=new(window.AudioContext||window.webkitAudioContext)({sampleRate:n})).state&&await i.resume(),u||(u=i.createMediaElementSource(e.video)).connect(i.destination);let d=f();await i.audioWorklet.addModule(d),URL.revokeObjectURL(d),(l=new AudioWorkletNode(i,"recorder-processor")).port.onmessage=e=>{a.push(new Float32Array(e.data))},u.connect(l).connect(i.destination),s=setInterval(async()=>{if(0===a.length)return;let e=function(e,t){let n=function(e){let t=new Float32Array(e.reduce((e,t)=>e+t.length,0)),n=0;return e.forEach(e=>{t.set(e,n),n+=e.length}),t}(e),r=2*n.length,o=new ArrayBuffer(44+r),i=new DataView(o);function u(e,t){for(let n=0;n<t.length;n++)i.setUint8(e+n,t.charCodeAt(n))}u(0,"RIFF"),i.setUint32(4,36+r,!0),u(8,"WAVE"),u(12,"fmt "),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,1,!0),i.setUint32(24,t,!0),i.setUint32(28,2*t,!0),i.setUint16(32,2,!0),i.setUint16(34,16,!0),u(36,"data"),i.setUint32(40,r,!0);let l=function(e){let t=e.length,n=new ArrayBuffer(2*t),r=new DataView(n);for(let n=0;n<t;n++){let t=Math.max(-1,Math.min(1,e[n]));r.setInt16(2*n,t<0?32768*t:32767*t,!0)}return n}(n);return new Uint8Array(o).set(new Uint8Array(l),44),new Blob([i],{type:"audio/wav"})}(a,i.sampleRate),t=await e.arrayBuffer();await r(t),a=[]},t)}function p(){o&&(o=!1,s&&clearInterval(s),l&&l.disconnect(),l=null,a=[])}return e.on("play",c),e.on("pause",p),e.on("destroy",p),{name:"artplayerPluginAsr",destroy:p}}}o.defineInteropFlag(n),o.export(n,"default",()=>i),"undefined"!=typeof window&&(window.artplayerPluginAsr=i)},{"@parcel/transformer-js/src/esmodule-helpers.js":"5lQoW"}],"5lQoW":[function(e,t,n,r){n.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},n.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.exportAll=function(e,t){return Object.keys(e).forEach(function(n){"default"===n||"__esModule"===n||Object.prototype.hasOwnProperty.call(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})}),t},n.export=function(e,t,n){Object.defineProperty(e,t,{enumerable:!0,get:n})}},{}]},["40eeC"],"40eeC","parcelRequire4dc0",{});let{default:e}=parcelRequire4dc0("40eeC");export{e as default};
|
||||
!function(e,t,r,n,o,a,l,i){var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s="function"==typeof u[n]&&u[n],c=s.i||{},d=s.cache||{},p="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(t,r){if(!d[t]){if(!e[t]){if(o[t])return o[t];var a="function"==typeof u[n]&&u[n];if(!r&&a)return a(t,!0);if(s)return s(t,!0);if(p&&"string"==typeof t)return p(t);var l=Error("Cannot find module '"+t+"'");throw l.code="MODULE_NOT_FOUND",l}c.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},c.cache={};var i=d[t]=new f.Module(t);e[t][0].call(i.exports,c,i,i.exports,u)}return d[t].exports;function c(e){var t=c.resolve(e);return!1===t?{}:f(t)}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.require=p,this.exports={}},f.modules=e,f.cache=d,f.parent=s,f.distDir=void 0,f.publicUrl=void 0,f.devServer=void 0,f.i=c,f.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return u[n]}}),u[n]=f;for(var y=0;y<t.length;y++)f(t[y]);if(r){var m=f(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=m:"function"==typeof define&&define.amd&&define(function(){return m})}}({"40eeC":[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",()=>i);var a=e("bundle-text:./style.less"),l=o.interopDefault(a);function i(e={}){let{hideTimeout:t=1e4,length:r=3,interval:n=100,sampleRate:o=16e3,onAudioChunk:a=()=>null}=e;return e=>{let l=!1,i=null,u=null,s=null,c=null,d=[],p=null,f=!1,y=null,m=null,b=null,g=e.layers.add({name:"asr",html:""});function v(){g.style.display="none"}function x(e){"string"==typeof e&&(clearTimeout(y),y=setTimeout(v,t),g.style.display="",g.innerHTML=e.split(/(?<=[、。!?!?\.])\s*/u).map(e=>e.trim()).filter(Boolean).slice(-r).map(e=>`<div class="art-asr-line">${e}</div>`).join(""))}let h=` class RecorderProcessor extends AudioWorkletProcessor { process(inputs) { const input = inputs[0]; if (input && input[0]) { this.port.postMessage(input[0]); } return true; } } registerProcessor('recorder-processor', RecorderProcessor); `,w=()=>{let e=new Blob([h],{type:"application/javascript"});return URL.createObjectURL(e)};async function P(){return i||"suspended"===(i=new(window.AudioContext||window.webkitAudioContext)({sampleRate:o})).state&&await i.resume(),i}async function j(){if(!u&&e.video)try{return u=i.createMediaElementSource(e.video)}catch(e){console.warn("[artplayerPluginAsr] Direct connection failed, trying fallback...",e)}try{if(m||(m=await A(e.video)),m)return b=i.createMediaStreamSource(m)}catch(e){console.warn("[artplayerPluginAsr] MediaStream fallback failed:",e)}return null}async function A(e){try{if(e.captureStream)return e.captureStream();if(e.mozCaptureStream)return e.mozCaptureStream();return console.warn("[artplayerPluginAsr] captureStream not supported"),null}catch(e){return console.warn("[artplayerPluginAsr] Error capturing stream:",e),null}}async function M(){if(!l)try{await P();let e=await j();if(!e)throw Error("Could not establish audio source");if(!f){let e=w();await i.audioWorklet.addModule(e),URL.revokeObjectURL(e),f=!0}(c=i.createGain()).gain.value=1,(s=new AudioWorkletNode(i,"recorder-processor")).port.onmessage=e=>{d.push(new Float32Array(e.data))},e.connect(s),e.connect(c),c.connect(i.destination);let t=n/1e3*o;p=setInterval(async()=>{if(0===d.length)return;let e=new Float32Array(0);for(;e.length<t&&d.length;){let t=d.shift(),r=new Float32Array(e.length+t.length);r.set(e,0),r.set(t,e.length),e=r}if(e.length<t)return;let r=e.slice(0,t),n=function(e){let t=e.length,r=new ArrayBuffer(2*t),n=new DataView(r);for(let r=0;r<t;r++){let t=Math.max(-1,Math.min(1,e[r]));n.setInt16(2*r,t<0?32768*t:32767*t,!0)}return r}(r),o=await a(n);x(o)},n),l=!0}catch(e){console.error("[artplayerPluginAsr] Initialization failed:",e),await C()}}async function C(){l&&(l=!1,clearInterval(p),p=null,s&&(s.disconnect(),s.port.onmessage=null,s=null),c&&(c.disconnect(),c=null),d=[])}async function O(){await C(),b&&(b.disconnect(),b=null),u&&(u.disconnect(),u=null),m&&(m.getTracks().forEach(e=>e.stop()),m=null),i&&(await i.close(),i=null),f=!1}return e.on("play",M),e.on("pause",C),e.on("destroy",O),{name:"artplayerPluginAsr",stop:O,hide:v,append:x}}}if("undefined"!=typeof document&&!document.getElementById("artplayer-plugin-asr")){let e=document.createElement("style");e.id="artplayer-plugin-asr",e.textContent=l.default,document.head.appendChild(e)}"undefined"!=typeof window&&(window.artplayerPluginAsr=i)},{"bundle-text:./style.less":"dKHY3","@parcel/transformer-js/src/esmodule-helpers.js":"5lQoW"}],dKHY3:[function(e,t,r,n){t.exports=".art-video-player .art-layer-asr{z-index:150;justify-content:end;gap:var(--art-subtitle-gap);padding:0 2%;padding-bottom:var(--art-subtitle-bottom);transition:padding-bottom var(--art-transition-duratLine truncated
|
||||
//# sourceMappingURL=artplayer-plugin-asr.esm.js.map
|
||||
Reference in new issue
Block a user