mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-14 00:06:17 -08:00
Refactor code structure for improved readability and maintainability
Remove debugging border from the websr plugin's styling Enhance canvas sizing logic in artplayer-plugin-websr - Updated canvas positioning to center it within the player. - Introduced a new function to calculate canvas size based on the video aspect ratio. - Adjusted canvas dimensions during initialization and on resize events to maintain aspect ratio. - Ensured canvas styles are updated to reflect the calculated dimensions. feat: add comparison mode to artplayer-plugin-websr - Updated README.md to reflect new comparison feature and simplified content. - Modified package.json to remove unnecessary keywords. - Enhanced index.js to implement comparison functionality, allowing users to compare original and upscaled video. - Added new methods for enabling, disabling, and toggling comparison mode, as well as setting and getting the comparison position. - Updated TypeScript definitions to include new comparison options and methods.
This commit is contained in:
1 parent
07a5b0c0f0
commit
7dffd99cfd
308 files changed
+3175
-852
No files matched your search
@@ -5,4 +5,4 @@
|
||||
* (c) 2017-2026 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,r,n,o,a,i,l){var u="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:{},s="function"==typeof u[n]&&u[n],c=s.i||{},d=s.cache||{},p="u">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 i=Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}c.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},c.cache={};var l=d[t]=new f.Module(t);e[t][0].call(l.exports,c,l,l.exports,u)}return d[t].exports;function c(e){var t=c.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],o=e[2]||e[0],a=f(n);"*"===t?Object.keys(a).forEach(function(e){"default"===e||"__esModule"===e||Object.prototype.hasOwnProperty.call(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:function(){return a[e]}})}):"*"===o?Object.defineProperty(r,t,{enumerable:!0,value:a}):Object.defineProperty(r,t,{enumerable:!0,get:function(){return"default"===o?a.__esModule?a.default:a:a[o]}})}),r}return 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 b=f(r);"object"==typeof exports&&"u">typeof module?module.exports=b:"function"==typeof define&&define.amd&&define(function(){return b})}}({"1gnQM":[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",()=>l);var a=e("bundle-text:./style.less"),i=o.interopDefault(a);function l(e={}){let{length:t=3,interval:r=100,sampleRate:n=16e3,autoHideTimeout:o=1e4,onAudioChunk:a=()=>null}=e;return e=>{let i=!1,l=null,u=null,s=null,c=null,d=[],p=null,f=!1,y=null,b=null,m=null,g=e.layers.add({name:"asr",html:""});function v(){g.style.display="none"}function h(e){"string"==typeof e&&(clearTimeout(y),y=setTimeout(v,o),g.style.display="",g.innerHTML=e.split(/(?<=[、。!?!?.])\s*/u).map(e=>e.trim()).filter(Boolean).slice(-t).map(e=>`<div class="art-asr-line">${e}</div>`).join(""))}let w=` 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); `;async function x(){return l||"suspended"===(l=new(window.AudioContext||window.webkitAudioContext)({sampleRate:n})).state&&await l.resume(),l}async function A(){if(!u&&e.video)try{return u=l.createMediaElementSource(e.video)}catch(e){console.warn("[artplayerPluginAsr] Direct connection failed:",e)}try{if(b||(b=await j(e.video)),b)return m=l.createMediaStreamSource(b)}catch(e){console.warn("[artplayerPluginAsr] MediaStream fallback failed:",e)}return null}async function j(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 P(){if(!i)try{await x();let e=await A();if(!e)throw Error("Could not establish audio source");if(!f){let e,t=(e=new Blob([w],{type:"application/javascript"}),URL.createObjectURL(e));await l.audioWorklet.addModule(t),URL.revokeObjectURL(t),f=!0}(c=l.createGain()).gain.value=1,(s=new AudioWorkletNode(l,"recorder-processor")).port.onmessage=e=>{d.push(new Float32Array(e.data))},e.connect(s),e.connect(c),c.connect(l.destination);let t=r/1e3*n;p=setInterval(async()=>{let e,r,o,i;if(0===d.length)return;let l=new Float32Array(0);for(;l.length<t&&d.length;){let e=d.shift(),t=new Float32Array(l.length+e.length);t.set(l,0),t.set(e,l.length),l=t}if(l.length<t)return;let u=l.slice(0,t),s=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}(u),c=(e=s.byteLength,r=new ArrayBuffer(44+e),o=new DataView(r),(i=(e,t)=>{for(let r=0;r<t.length;r++)o.setUint8(e+r,t.charCodeAt(r))})(0,"RIFF"),o.setUint32(4,36+e,!0),i(8,"WAVE"),i(12,"fmt "),o.setUint32(16,16,!0),o.setUint16(20,1,!0),o.setUint16(22,1,!0),o.setUint32(24,n,!0),o.setUint32(28,2*n,!0),o.setUint16(32,2,!0),o.setUint16(34,16,!0),i(36,"data"),o.setUint32(40,e,!0),new Uint8Array(r).set(new Uint8Array(s),44),r),p=await a({pcm:s,wav:c});h(p)},r),i=!0}catch(e){console.error("[artplayerPluginAsr] Initialization failed:",e),await M()}}async function M(){i&&(i=!1,clearInterval(p),p=null,s&&(s.disconnect(),s.port.onmessage=null,s=null),c&&(c.disconnect(),c=null),d=[])}async function U(){awaLine truncated
|
||||
!function(e,t,r,n,o){var a="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:{},i="function"==typeof a[n]&&a[n],l=i.i||{},u=i.cache||{},s="u">typeof module&&"function"==typeof module.require&&module.require.bind(module);function c(t,r){if(!u[t]){if(!e[t]){if(o[t])return o[t];var l="function"==typeof a[n]&&a[n];if(!r&&l)return l(t,!0);if(i)return i(t,!0);if(s&&"string"==typeof t)return s(t);var d=Error("Cannot find module '"+t+"'");throw d.code="MODULE_NOT_FOUND",d}f.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},f.cache={};var p=u[t]=new c.Module(t);e[t][0].call(p.exports,f,p,p.exports,a)}return u[t].exports;function f(e){var t=f.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],o=e[2]||e[0],a=c(n);"*"===t?Object.keys(a).forEach(function(e){"default"===e||"__esModule"===e||Object.prototype.hasOwnProperty.call(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:function(){return a[e]}})}):"*"===o?Object.defineProperty(r,t,{enumerable:!0,value:a}):Object.defineProperty(r,t,{enumerable:!0,get:function(){return"default"===o?a.__esModule?a.default:a:a[o]}})}),r}return c(t)}}c.isParcelRequire=!0,c.Module=function(e){this.id=e,this.bundle=c,this.require=s,this.exports={}},c.modules=e,c.cache=u,c.parent=i,c.distDir=void 0,c.publicUrl=void 0,c.devServer=void 0,c.i=l,c.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(c,"root",{get:function(){return a[n]}}),a[n]=c;for(var d=0;d<t.length;d++)c(t[d]);if(r){var p=c(r);"object"==typeof exports&&"u">typeof module?module.exports=p:"function"==typeof define&&define.amd&&define(function(){return p})}}({"1gnQM":[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",()=>l);var a=e("bundle-text:./style.less"),i=o.interopDefault(a);function l(e={}){let{length:t=3,interval:r=100,sampleRate:n=16e3,autoHideTimeout:o=1e4,onAudioChunk:a=()=>null}=e;return e=>{let i=!1,l=null,u=null,s=null,c=null,d=[],p=null,f=!1,y=null,b=null,m=null,g=e.layers.add({name:"asr",html:""});function v(){g.style.display="none"}function h(e){"string"==typeof e&&(clearTimeout(y),y=setTimeout(v,o),g.style.display="",g.innerHTML=e.split(/(?<=[、。!?!?.])\s*/u).map(e=>e.trim()).filter(Boolean).slice(-t).map(e=>`<div class="art-asr-line">${e}</div>`).join(""))}let w=` 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); `;async function x(){return l||"suspended"===(l=new(window.AudioContext||window.webkitAudioContext)({sampleRate:n})).state&&await l.resume(),l}async function A(){if(!u&&e.video)try{return u=l.createMediaElementSource(e.video)}catch(e){console.warn("[artplayerPluginAsr] Direct connection failed:",e)}try{if(b||(b=await j(e.video)),b)return m=l.createMediaStreamSource(b)}catch(e){console.warn("[artplayerPluginAsr] MediaStream fallback failed:",e)}return null}async function j(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 P(){if(!i)try{await x();let e=await A();if(!e)throw Error("Could not establish audio source");if(!f){let e,t=(e=new Blob([w],{type:"application/javascript"}),URL.createObjectURL(e));await l.audioWorklet.addModule(t),URL.revokeObjectURL(t),f=!0}(c=l.createGain()).gain.value=1,(s=new AudioWorkletNode(l,"recorder-processor")).port.onmessage=e=>{d.push(new Float32Array(e.data))},e.connect(s),e.connect(c),c.connect(l.destination);let t=r/1e3*n;p=setInterval(async()=>{let e,r,o,i;if(0===d.length)return;let l=new Float32Array(0);for(;l.length<t&&d.length;){let e=d.shift(),t=new Float32Array(l.length+e.length);t.set(l,0),t.set(e,l.length),l=t}if(l.length<t)return;let u=l.slice(0,t),s=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}(u),c=(e=s.byteLength,r=new ArrayBuffer(44+e),o=new DataView(r),(i=(e,t)=>{for(let r=0;r<t.length;r++)o.setUint8(e+r,t.charCodeAt(r))})(0,"RIFF"),o.setUint32(4,36+e,!0),i(8,"WAVE"),i(12,"fmt "),o.setUint32(16,16,!0),o.setUint16(20,1,!0),o.setUint16(22,1,!0),o.setUint32(24,n,!0),o.setUint32(28,2*n,!0),o.setUint16(32,2,!0),o.setUint16(34,16,!0),i(36,"data"),o.setUint32(40,e,!0),new Uint8Array(r).set(new Uint8Array(s),44),r),p=await a({pcm:s,wav:c});h(p)},r),i=!0}catch(e){console.error("[artplayerPluginAsr] Initialization failed:",e),await M()}}async function M(){i&&(i=!1,clearInterval(p),p=null,s&&(s.disconnect(),s.port.onmessage=null,s=null),c&&(c.disconnect(),c=null),d=[])}async function U(){await M()Line truncated
|
||||
Reference in new issue
Block a user