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:
Harvey Zhao committed 2026-02-10 23:02:31 +08:00
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,a,s,o,i){var c="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:{},u="function"==typeof c[n]&&c[n],l=u.i||{},p=u.cache||{},f="u">typeof module&&"function"==typeof module.require&&module.require.bind(module);function d(t,r){if(!p[t]){if(!e[t]){if(a[t])return a[t];var s="function"==typeof c[n]&&c[n];if(!r&&s)return s(t,!0);if(u)return u(t,!0);if(f&&"string"==typeof t)return f(t);var o=Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}l.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},l.cache={};var i=p[t]=new d.Module(t);e[t][0].call(i.exports,l,i,i.exports,c)}return p[t].exports;function l(e){var t=l.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],s=d(n);"*"===t?Object.keys(s).forEach(function(e){"default"===e||"__esModule"===e||Object.prototype.hasOwnProperty.call(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:function(){return s[e]}})}):"*"===a?Object.defineProperty(r,t,{enumerable:!0,value:s}):Object.defineProperty(r,t,{enumerable:!0,get:function(){return"default"===a?s.__esModule?s.default:s:s[a]}})}),r}return d(t)}}d.isParcelRequire=!0,d.Module=function(e){this.id=e,this.bundle=d,this.require=f,this.exports={}},d.modules=e,d.cache=p,d.parent=u,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 h=0;h<t.length;h++)d(t[h]);if(r){var m=d(r);"object"==typeof exports&&"u">typeof module?module.exports=m:"function"==typeof define&&define.amd&&define(function(){return m})}}({"1FGEJ":[function(e,t,r,n){var a=e("@parcel/transformer-js/src/esmodule-helpers.js");a.defineInteropFlag(r),a.export(r,"default",function(){return u});var s=e("@swc/helpers/cjs/_async_to_generator.cjs"),o=e("@swc/helpers/cjs/_ts_generator.cjs"),i=e("@tensorflow-models/body-segmentation"),c=e("@tensorflow/tfjs-core");function u(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){var r=t.template,n=r.$video,a=r.$danmuku,u=null,l=null,p=null,f=null,d=!1,h={solutionPath:e.solutionPath||"https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation",modelSelection:e.modelSelection||1,smoothSegmentation:void 0===e.smoothSegmentation||e.smoothSegmentation,minDetectionConfidence:e.minDetectionConfidence||.5,minTrackingConfidence:e.minTrackingConfidence||.5,selfieMode:e.selfieMode||!1,drawContour:e.drawContour||!1,foregroundThreshold:e.foregroundThreshold||.5,opacity:e.opacity||1,maskBlurAmount:e.maskBlurAmount||3};function m(){return(0,s._)(function(){return(0,o._)(this,function(e){switch(e.label){case 0:if(d)return[3,2];return[4,(0,s._)(function(){var e,t;return(0,o._)(this,function(r){switch(r.label){case 0:return[4,(0,s._)(function(){return(0,o._)(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,4]),[4,c.setBackend("webgl")];case 1:case 3:return e.sent(),[3,4];case 2:return console.warn("WebGL backend not available, falling back to CPU",e.sent().message),[4,c.setBackend("cpu")];case 4:return[2]}})})()];case 1:r.sent(),e=i.SupportedModels.MediaPipeSelfieSegmentation,t={runtime:"mediapipe",modelType:"general",solutionPath:h.solutionPath,modelSelection:h.modelSelection,smoothSegmentation:h.smoothSegmentation,minDetectionConfidence:h.minDetectionConfidence,minTrackingConfidence:h.minTrackingConfidence,selfieMode:h.selfieMode},r.label=2;case 2:return r.trys.push([2,4,,5]),[4,i.createSegmenter(e,t)];case 3:return u=r.sent(),d=!0,[3,5];case 4:return console.error("Error initializing segmenter:",r.sent()),d=!1,[3,5];case 5:return[2]}})})()];case 1:e.sent(),e.label=2;case 2:return l||(p=(l=document.createElement("canvas")).getContext("2d")),Object.assign(a.style,{maskMode:"alpha",maskSize:"contain",maskRepeat:"no-repeat",backgroundSize:"contain",backgroundRepeat:"no-repeat"}),!function e(){return(0,s._)(function(){var t,r,s,c,m;return(0,o._)(this,function(o){switch(o.label){case 0:if(!d||n.paused||n.ended)return f=requestAnimationFrame(e),[2];o.label=1;case 1:return o.trys.push([1,5,,6]),l.width=n.videoWidth,l.height=n.videoHeight,[4,u.segmentPeople(n)];case 2:if(!(t=o.sent())||0===t.length)return f=requestAnimationFrame(e),[2];return r={r:255,g:255,b:255,a:255},s={r:0,g:0,b:0,a:255},[4,i.toBinaryMask(t,r,s,h.drawContour,h.foregroundThreshold)];case 3:return c=o.sent(),[4,i.drawMask(l,n,c,h.opacity,h.maskBlurAmount)];case 4:return o.sent(),m=p.getImageData(0,0,l.width,l.height),p.putImageData(function(e){for(var t=e.data,r=0;r<t.length;r+=4)t[r]>250&&t[r+1]>250&&t[r+2]>250&&(t[r+3]=0);return e}(m),0,0),a.style.maskImage="url(".concat(l.toDataURL(),")"),[3,6];case 5:return console.error("Error in segmentBody:",o.sent()),[3,6];case 6:return f=requestAnimationFrame(e),[2]}})})()}(),[2]}})})()}function g(){a.style.maskImage="none",f&&(cancelAnimationFrame(f),f=null)}return t.on(Line truncated
!function(e,t,r,n,a){var s="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:{},o="function"==typeof s[n]&&s[n],i=o.i||{},c=o.cache||{},u="u">typeof module&&"function"==typeof module.require&&module.require.bind(module);function l(t,r){if(!c[t]){if(!e[t]){if(a[t])return a[t];var i="function"==typeof s[n]&&s[n];if(!r&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var p=Error("Cannot find module '"+t+"'");throw p.code="MODULE_NOT_FOUND",p}d.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},d.cache={};var f=c[t]=new l.Module(t);e[t][0].call(f.exports,d,f,f.exports,s)}return c[t].exports;function d(e){var t=d.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],s=l(n);"*"===t?Object.keys(s).forEach(function(e){"default"===e||"__esModule"===e||Object.prototype.hasOwnProperty.call(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:function(){return s[e]}})}):"*"===a?Object.defineProperty(r,t,{enumerable:!0,value:s}):Object.defineProperty(r,t,{enumerable:!0,get:function(){return"default"===a?s.__esModule?s.default:s:s[a]}})}),r}return l(t)}}l.isParcelRequire=!0,l.Module=function(e){this.id=e,this.bundle=l,this.require=u,this.exports={}},l.modules=e,l.cache=c,l.parent=o,l.distDir=void 0,l.publicUrl=void 0,l.devServer=void 0,l.i=i,l.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(l,"root",{get:function(){return s[n]}}),s[n]=l;for(var p=0;p<t.length;p++)l(t[p]);if(r){var f=l(r);"object"==typeof exports&&"u">typeof module?module.exports=f:"function"==typeof define&&define.amd&&define(function(){return f})}}({"1FGEJ":[function(e,t,r,n){var a=e("@parcel/transformer-js/src/esmodule-helpers.js");a.defineInteropFlag(r),a.export(r,"default",function(){return u});var s=e("@swc/helpers/cjs/_async_to_generator.cjs"),o=e("@swc/helpers/cjs/_ts_generator.cjs"),i=e("@tensorflow-models/body-segmentation"),c=e("@tensorflow/tfjs-core");function u(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){var r=t.template,n=r.$video,a=r.$danmuku,u=null,l=null,p=null,f=null,d=!1,h={solutionPath:e.solutionPath||"https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation",modelSelection:e.modelSelection||1,smoothSegmentation:void 0===e.smoothSegmentation||e.smoothSegmentation,minDetectionConfidence:e.minDetectionConfidence||.5,minTrackingConfidence:e.minTrackingConfidence||.5,selfieMode:e.selfieMode||!1,drawContour:e.drawContour||!1,foregroundThreshold:e.foregroundThreshold||.5,opacity:e.opacity||1,maskBlurAmount:e.maskBlurAmount||3};function m(){return(0,s._)(function(){return(0,o._)(this,function(e){switch(e.label){case 0:if(d)return[3,2];return[4,(0,s._)(function(){var e,t;return(0,o._)(this,function(r){switch(r.label){case 0:return[4,(0,s._)(function(){return(0,o._)(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,4]),[4,c.setBackend("webgl")];case 1:case 3:return e.sent(),[3,4];case 2:return console.warn("WebGL backend not available, falling back to CPU",e.sent().message),[4,c.setBackend("cpu")];case 4:return[2]}})})()];case 1:r.sent(),e=i.SupportedModels.MediaPipeSelfieSegmentation,t={runtime:"mediapipe",modelType:"general",solutionPath:h.solutionPath,modelSelection:h.modelSelection,smoothSegmentation:h.smoothSegmentation,minDetectionConfidence:h.minDetectionConfidence,minTrackingConfidence:h.minTrackingConfidence,selfieMode:h.selfieMode},r.label=2;case 2:return r.trys.push([2,4,,5]),[4,i.createSegmenter(e,t)];case 3:return u=r.sent(),d=!0,[3,5];case 4:return console.error("Error initializing segmenter:",r.sent()),d=!1,[3,5];case 5:return[2]}})})()];case 1:e.sent(),e.label=2;case 2:return l||(p=(l=document.createElement("canvas")).getContext("2d")),Object.assign(a.style,{maskMode:"alpha",maskSize:"contain",maskRepeat:"no-repeat",backgroundSize:"contain",backgroundRepeat:"no-repeat"}),!function e(){return(0,s._)(function(){var t,r,s,c,m;return(0,o._)(this,function(o){switch(o.label){case 0:if(!d||n.paused||n.ended)return f=requestAnimationFrame(e),[2];o.label=1;case 1:return o.trys.push([1,5,,6]),l.width=n.videoWidth,l.height=n.videoHeight,[4,u.segmentPeople(n)];case 2:if(!(t=o.sent())||0===t.length)return f=requestAnimationFrame(e),[2];return r={r:255,g:255,b:255,a:255},s={r:0,g:0,b:0,a:255},[4,i.toBinaryMask(t,r,s,h.drawContour,h.foregroundThreshold)];case 3:return c=o.sent(),[4,i.drawMask(l,n,c,h.opacity,h.maskBlurAmount)];case 4:return o.sent(),m=p.getImageData(0,0,l.width,l.height),p.putImageData(function(e){for(var t=e.data,r=0;r<t.length;r+=4)t[r]>250&&t[r+1]>250&&t[r+2]>250&&(t[r+3]=0);return e}(m),0,0),a.style.maskImage="url(".concat(l.toDataURL(),")"),[3,6];case 5:return console.error("Error in segmentBody:",o.sent()),[3,6];case 6:return f=requestAnimationFrame(e),[2]}})})()}(),[2]}})})()}function g(){a.style.maskImage="none",f&&(cancelAnimationFrame(f),f=null)}return t.on("readyLine truncated