Built@main artplayer-plugin-danmuku-mask

This commit is contained in:
Harvey Zack committed 2024-10-08 11:57:45 +08:00
1 parent 7a1240b889
commit e9d544f416
5 files changed
+33 -1

No files matched your search

@@ -0,0 +1,8 @@
/*!
* artplayer-plugin-danmuku-mask.js v1.0.0
* Github: https://github.com/zhw2590582/ArtPlayer
* (c) 2017-2024 Harvey Zack
* Released under the MIT License.
*/
!function(e,t,r,n,s){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},o="function"==typeof a[n]&&a[n],l=o.cache||{},i="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function u(t,r){if(!l[t]){if(!e[t]){var s="function"==typeof a[n]&&a[n];if(!r&&s)return s(t,!0);if(o)return o(t,!0);if(i&&"string"==typeof t)return i(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 c=l[t]=new u.Module(t);e[t][0].call(c.exports,d,c,c.exports,this)}return l[t].exports;function d(e){var t=d.resolve(e);return!1===t?{}:u(t)}}u.isParcelRequire=!0,u.Module=function(e){this.id=e,this.bundle=u,this.exports={}},u.modules=e,u.cache=l,u.parent=o,u.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(u,"root",{get:function(){return a[n]}}),a[n]=u;for(var p=0;p<t.length;p++)u(t[p]);if(r){var c=u(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=c:"function"==typeof define&&define.amd&&define(function(){return c})}}({"3nz8g":[function(e,t,r){var n=e("@parcel/transformer-js/src/esmodule-helpers.js");n.defineInteropFlag(r),n.export(r,"default",()=>o);var s=e("@tensorflow/tfjs-core");e("@tensorflow/tfjs-backend-webgl"),e("@tensorflow/tfjs-backend-cpu");var a=e("@tensorflow-models/body-segmentation");function o(e={}){return t=>{let{template:{$player:r,$video:n,$danmuku:o}}=t,l=null,i=null,u=null,p=null,c=!1,d={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};async function f(){try{await s.setBackend("webgl"),console.log("Using WebGL backend")}catch(e){console.warn("WebGL backend not available, falling back to CPU"),await s.setBackend("cpu")}}async function h(){await f();let e=a.SupportedModels.MediaPipeSelfieSegmentation,t={runtime:"mediapipe",modelType:"general",solutionPath:d.solutionPath,modelSelection:d.modelSelection,smoothSegmentation:d.smoothSegmentation,minDetectionConfidence:d.minDetectionConfidence,minTrackingConfidence:d.minTrackingConfidence,selfieMode:d.selfieMode};try{l=await a.createSegmenter(e,t),c=!0,console.log("Segmenter initialized successfully")}catch(e){console.error("Error initializing segmenter:",e),c=!1}}async function m(){if(!c||n.paused||n.ended){p=requestAnimationFrame(m);return}try{i.width=n.videoWidth,i.height=n.videoHeight;let e=await l.segmentPeople(n);if(!e||0===e.length){p=requestAnimationFrame(m);return}let t=await a.toBinaryMask(e,{r:255,g:255,b:255,a:255},{r:0,g:0,b:0,a:255},d.drawContour,d.foregroundThreshold);await a.drawMask(i,n,t,d.opacity,d.maskBlurAmount);let r=u.getImageData(0,0,i.width,i.height);u.putImageData(function(e){let t=e.data;for(let e=0;e<t.length;e+=4)t[e]>250&&t[e+1]>250&&t[e+2]>250&&(t[e+3]=0);return e}(r),0,0),o.style.maskImage=`url(${i.toDataURL()})`}catch(e){console.error("Error in segmentBody:",e)}p=requestAnimationFrame(m)}async function g(){c||await h(),i||(u=(i=document.createElement("canvas")).getContext("2d"),Object.assign(i.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",opacity:"0"}),r.appendChild(i)),Object.assign(o.style,{maskMode:"alpha",maskSize:"contain",maskRepeat:"no-repeat",backgroundSize:"contain",backgroundRepeat:"no-repeat"}),m()}function x(){o.style.maskImage="none",p&&(cancelAnimationFrame(p),p=null)}return t.on("ready",g),t.on("destroy",x),{name:"artplayerPluginDanmukuMask",start:g,stop:x}}}"undefined"!=typeof window&&(window.artplayerPluginDanmukuMask=o)},{"@tensorflow/tfjs-core":"2nuhV","@tensorflow/tfjs-backend-webgl":"2cOos","@tensorflow/tfjs-backend-cpu":"61SaF","@tensorflow-models/body-segmentation":"79Ppz","@parcel/transformer-js/src/esmodule-helpers.js":"9pCYc"}],"2nuhV":[function(e,t,r){/** * @license * Copyright 2017 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */var n=e("@parcel/transformer-js/src/esmodule-helpers.js"Line truncated