Refactor code structure for improved readability and maintainability

This commit is contained in:
Harvey Zack committed 2025-05-23 09:58:16 +08:00
1 parent 4bdad1675b
commit 1ece90c582
14 files changed
+17 -18

No files matched your search

+1 -1
View File
@@ -5,4 +5,4 @@
* (c) 2017-2025 Harvey Zack
* Released under the MIT License.
*/
!function(e,t,r,n,o,i,u,a){var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s="function"==typeof c[n]&&c[n],f=s.i||{},l=s.cache||{},p="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function d(t,r){if(!l[t]){if(!e[t]){if(o[t])return o[t];var i="function"==typeof c[n]&&c[n];if(!r&&i)return i(t,!0);if(s)return s(t,!0);if(p&&"string"==typeof t)return p(t);var u=Error("Cannot find module '"+t+"'");throw u.code="MODULE_NOT_FOUND",u}f.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},f.cache={};var a=l[t]=new d.Module(t);e[t][0].call(a.exports,f,a,a.exports,c)}return l[t].exports;function f(e){var t=f.resolve(e);return!1===t?{}:d(t)}}d.isParcelRequire=!0,d.Module=function(e){this.id=e,this.bundle=d,this.require=p,this.exports={}},d.modules=e,d.cache=l,d.parent=s,d.distDir=void 0,d.publicUrl=void 0,d.devServer=void 0,d.i=f,d.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(d,"root",{get:function(){return c[n]}}),c[n]=d;for(var y=0;y<t.length;y++)d(t[y]);if(r){var _=d(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=_:"function"==typeof define&&define.amd&&define(function(){return _})}}({"98QZN":[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",function(){return a});var i=e("@swc/helpers/cjs/_async_to_generator.cjs"),u=e("@swc/helpers/cjs/_ts_generator.cjs");function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.interval,r=void 0===t?5e3:t,n=e.sampleRate,o=void 0===n?16e3:n,a=e.callback,c=void 0===a?function(){return null}:a;return function(e){var t=!1,n=null,a=null,s=null,f=[],l=null,p=function(){var e=new Blob(["\n class RecorderProcessor extends AudioWorkletProcessor {\n process(inputs) {\n const input = inputs[0];\n if (input && input[0]) {\n this.port.postMessage(input[0]);\n }\n return true;\n }\n }\n registerProcessor('recorder-processor', RecorderProcessor);\n "],{type:"application/javascript"});return URL.createObjectURL(e)};function d(){return(d=(0,i._)(function(){var d;return(0,u._)(this,function(y){switch(y.label){case 0:if(t)return[2];if(t=!0,"suspended"!==(n=new(window.AudioContext||window.webkitAudioContext)({sampleRate:o})).state)return[3,2];return[4,n.resume()];case 1:y.sent(),y.label=2;case 2:return a||(a=n.createMediaElementSource(e.video)).connect(n.destination),d=p(),[4,n.audioWorklet.addModule(d)];case 3:return y.sent(),URL.revokeObjectURL(d),(s=new AudioWorkletNode(n,"recorder-processor")).port.onmessage=function(e){f.push(new Float32Array(e.data))},a.connect(s).connect(n.destination),l=setInterval((0,i._)(function(){return(0,u._)(this,function(e){switch(e.label){case 0:if(0===f.length)return[2];return[4,(function(e,t){var r,n,o=(r=new Float32Array(e.reduce(function(e,t){return e+t.length},0)),n=0,e.forEach(function(e){r.set(e,n),n+=e.length}),r),i=2*o.length,u=new ArrayBuffer(44+i),a=new DataView(u);function c(e,t){for(var r=0;r<t.length;r++)a.setUint8(e+r,t.charCodeAt(r))}c(0,"RIFF"),a.setUint32(4,36+i,!0),c(8,"WAVE"),c(12,"fmt "),a.setUint32(16,16,!0),a.setUint16(20,1,!0),a.setUint16(22,1,!0),a.setUint32(24,t,!0),a.setUint32(28,2*t,!0),a.setUint16(32,2,!0),a.setUint16(34,16,!0),c(36,"data"),a.setUint32(40,i,!0);var s=function(e){for(var t=e.length,r=new ArrayBuffer(2*t),n=new DataView(r),o=0;o<t;o++){var i=Math.max(-1,Math.min(1,e[o]));n.setInt16(2*o,i<0?32768*i:32767*i,!0)}return r}(o);return new Uint8Array(u).set(new Uint8Array(s),44),new Blob([a],{type:"audio/wav"})})(f,n.sampleRate).arrayBuffer()];case 1:return[4,c(e.sent())];case 2:return e.sent(),f=[],[2]}})}),r),[2]}})})).apply(this,arguments)}function y(){t&&(t=!1,l&&clearInterval(l),s&&s.disconnect(),s=null,f=[])}return e.on("play",function(){return d.apply(this,arguments)}),e.on("pause",y),e.on("destroy",y),{name:"artplayerPluginAsr",destroy:y}}}"undefined"!=typeof window&&(window.artplayerPluginAsr=a)},{"@swc/helpers/cjs/_async_to_generator.cjs":"cZn0e","@swc/helpers/cjs/_ts_generator.cjs":"eltGh","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],cZn0e:[function(e,t,r,n){"use strict";function o(e,t,r,n,o,i,u){try{var a=e[i](u),c=a.value}catch(e){r(e);return}a.done?t(c):Promise.resolve(c).then(n,o)}r._=function(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var u=e.apply(t,r);function a(e){o(u,n,i,a,c,"next",e)}function c(e){o(u,n,i,a,c,"throw",e)}a(void 0)})}}},{}],eltGh:[function(e,t,r,n){"use strict";r._=e("eb260df52bffddd").__generator},{eb260df52bffddd:"6yrAu"}],"6yrAu":[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"__extends",function(){return a}),o.export(r,"__assign",function(){return c}),o.export(r,"__rest",function(){return s}),o.export(r,"__decorate",function(){return f}),o.export(r,"__param",function(){return l}),o.exLine truncated
!function(e,t,r,n,o,i,a,u){var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s="function"==typeof c[n]&&c[n],l=s.i||{},f=s.cache||{},p="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function d(t,r){if(!f[t]){if(!e[t]){if(o[t])return o[t];var i="function"==typeof c[n]&&c[n];if(!r&&i)return i(t,!0);if(s)return s(t,!0);if(p&&"string"==typeof t)return p(t);var a=Error("Cannot find module '"+t+"'");throw a.code="MODULE_NOT_FOUND",a}l.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},l.cache={};var u=f[t]=new d.Module(t);e[t][0].call(u.exports,l,u,u.exports,c)}return f[t].exports;function l(e){var t=l.resolve(e);return!1===t?{}:d(t)}}d.isParcelRequire=!0,d.Module=function(e){this.id=e,this.bundle=d,this.require=p,this.exports={}},d.modules=e,d.cache=f,d.parent=s,d.distDir=void 0,d.publicUrl=void 0,d.devServer=void 0,d.i=l,d.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(d,"root",{get:function(){return c[n]}}),c[n]=d;for(var y=0;y<t.length;y++)d(t[y]);if(r){var h=d(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=h:"function"==typeof define&&define.amd&&define(function(){return h})}}({"98QZN":[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",function(){return s});var i=e("@swc/helpers/cjs/_async_to_generator.cjs"),a=e("@swc/helpers/cjs/_ts_generator.cjs"),u=e("bundle-text:./style.less"),c=o.interopDefault(u);function s(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.hideTimeout,r=void 0===t?1e4:t,n=e.length,o=void 0===n?3:n,u=e.interval,c=void 0===u?100:u,s=e.sampleRate,l=void 0===s?16e3:s,f=e.onAudioChunk,p=void 0===f?function(){return null}:f;return function(e){var t=!1,n=null,u=null,s=null,f=null,d=[],y=null,h=!1,_=null,v=null,b=null,m=e.layers.add({name:"asr",html:""});function w(){m.style.display="none"}function g(e){"string"==typeof e&&(clearTimeout(_),_=setTimeout(w,r),m.style.display="",m.innerHTML=e.split(RegExp("(?<=[、。!?!?\\.])\\s*","u")).map(function(e){return e.trim()}).filter(Boolean).slice(-o).map(function(e){return'<div class="art-asr-line">'.concat(e,"</div>")}).join(""))}var x=function(){var e=new Blob(["\n class RecorderProcessor extends AudioWorkletProcessor {\n process(inputs) {\n const input = inputs[0];\n if (input && input[0]) {\n this.port.postMessage(input[0]);\n }\n return true;\n }\n }\n registerProcessor('recorder-processor', RecorderProcessor);\n "],{type:"application/javascript"});return URL.createObjectURL(e)};function j(){return(j=(0,i._)(function(){return(0,a._)(this,function(e){switch(e.label){case 0:if(n)return[2,n];if("suspended"!==(n=new(window.AudioContext||window.webkitAudioContext)({sampleRate:l})).state)return[3,2];return[4,n.resume()];case 1:e.sent(),e.label=2;case 2:return[2,n]}})})).apply(this,arguments)}function O(){return(O=(0,i._)(function(){return(0,a._)(this,function(t){switch(t.label){case 0:if(!u&&e.video)try{return u=n.createMediaElementSource(e.video),[2,u]}catch(e){console.warn("[artplayerPluginAsr] Direct connection failed, trying fallback...",e)}t.label=1;case 1:if(t.trys.push([1,4,,5]),v)return[3,3];return[4,function(e){return P.apply(this,arguments)}(e.video)];case 2:v=t.sent(),t.label=3;case 3:if(v)return[2,b=n.createMediaStreamSource(v)];return[3,5];case 4:return console.warn("[artplayerPluginAsr] MediaStream fallback failed:",t.sent()),[3,5];case 5:return[2,null]}})})).apply(this,arguments)}function P(){return(P=(0,i._)(function(e){return(0,a._)(this,function(t){try{if(e.captureStream)return[2,e.captureStream()];if(e.mozCaptureStream)return[2,e.mozCaptureStream()];return console.warn("[artplayerPluginAsr] captureStream not supported"),[2,null]}catch(e){return console.warn("[artplayerPluginAsr] Error capturing stream:",e),[2,null]}})})).apply(this,arguments)}function S(){return(S=(0,i._)(function(){var e,r,o;return(0,a._)(this,function(u){switch(u.label){case 0:if(t)return[2];u.label=1;case 1:return u.trys.push([1,6,,8]),[4,function(){return j.apply(this,arguments)}()];case 2:return u.sent(),[4,function(){return O.apply(this,arguments)}()];case 3:if(!(e=u.sent()))throw Error("Could not establish audio source");if(h)return[3,5];return r=x(),[4,n.audioWorklet.addModule(r)];case 4:u.sent(),URL.revokeObjectURL(r),h=!0,u.label=5;case 5:return(f=n.createGain()).gain.value=1,(s=new AudioWorkletNode(n,"recorder-processor")).port.onmessage=function(e){d.push(new Float32Array(e.data))},e.connect(s),e.connect(f),f.connect(n.destination),o=c/1e3*l,y=setInterval((0,i._)(function(){var e,t,r;return(0,a._)(this,function(n){switch(n.label){case 0:if(0===d.length)return[2];for(e=new Float32Array(0);e.length<o&&d.length;)t=d.shift(),(r=new Float32Array(e.length+t.length)).set(e,0),r.set(t,e.length),e=r;if(e.length<o)return[2];return[4,p(function(e){for(var t=e.length,Line truncated