/*! * artplayer-plugin-danmuku-mask.js v1.0.0 * Github: https://github.com/zhw2590582/ArtPlayer * (c) 2017-2025 Harvey Zack * Released under the MIT License. */ !function(e,t,r,n,s,a,o,l){var i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},p="function"==typeof i[n]&&i[n],u=p.i||{},c=p.cache||{},d="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(t,r){if(!c[t]){if(!e[t]){if(s[t])return s[t];var a="function"==typeof i[n]&&i[n];if(!r&&a)return a(t,!0);if(p)return p(t,!0);if(d&&"string"==typeof t)return d(t);var o=Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}u.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},u.cache={};var l=c[t]=new f.Module(t);e[t][0].call(l.exports,u,l,l.exports,i)}return c[t].exports;function u(e){var t=u.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],s=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]}})}):"*"===s?Object.defineProperty(r,t,{enumerable:!0,value:a}):Object.defineProperty(r,t,{enumerable:!0,get:function(){return"default"===s?a.__esModule?a.default:a:a[s]}})}),r}return f(t)}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.require=d,this.exports={}},f.modules=e,f.cache=c,f.parent=p,f.distDir=void 0,f.publicUrl=void 0,f.devServer=void 0,f.i=u,f.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return i[n]}}),i[n]=f;for(var m=0;ml);var a=e("@tensorflow-models/body-segmentation"),o=e("@tensorflow/tfjs-core");function l(e={}){return t=>{let{template:{$video:r,$danmuku:n}}=t,s=null,l=null,i=null,p=null,u=!1,c={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 d(){try{await o.setBackend("webgl")}catch(e){console.warn("WebGL backend not available, falling back to CPU",e.message),await o.setBackend("cpu")}}async function f(){await d();let e=a.SupportedModels.MediaPipeSelfieSegmentation,t={runtime:"mediapipe",modelType:"general",solutionPath:c.solutionPath,modelSelection:c.modelSelection,smoothSegmentation:c.smoothSegmentation,minDetectionConfidence:c.minDetectionConfidence,minTrackingConfidence:c.minTrackingConfidence,selfieMode:c.selfieMode};try{s=await a.createSegmenter(e,t),u=!0}catch(e){console.error("Error initializing segmenter:",e),u=!1}}async function m(){if(!u||r.paused||r.ended){p=requestAnimationFrame(m);return}try{l.width=r.videoWidth,l.height=r.videoHeight;let e=await s.segmentPeople(r);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},c.drawContour,c.foregroundThreshold);await a.drawMask(l,r,t,c.opacity,c.maskBlurAmount);let o=i.getImageData(0,0,l.width,l.height);i.putImageData(function(e){let t=e.data;for(let e=0;e250&&t[e+1]>250&&t[e+2]>250&&(t[e+3]=0);return e}(o),0,0),n.style.maskImage=`url(${l.toDataURL()})`}catch(e){console.error("Error in segmentBody:",e)}p=requestAnimationFrame(m)}async function h(){u||await f(),l||(i=(l=document.createElement("canvas")).getContext("2d")),Object.assign(n.style,{maskMode:"alpha",maskSize:"contain",maskRepeat:"no-repeat",backgroundSize:"contain",backgroundRepeat:"no-repeat"}),m()}function g(){n.style.maskImage="none",p&&(cancelAnimationFrame(p),p=null)}return t.on("ready",h),t.on("destroy",g),{name:"artplayerPluginDanmukuMask",start:h,stop:g}}}e("@tensorflow/tfjs-backend-webgl"),e("@tensorflow/tfjs-backend-cpu"),"undefined"!=typeof window&&(window.artplayerPluginDanmukuMask=l)},{"@tensorflow-models/body-segmentation":"5Otso","@tensorflow/tfjs-core":"2Gtps","@tensorflow/tfjs-backend-webgl":"2ZcDF","@tensorflow/tfjs-backend-cpu":"b4yJT","@parcel/transformer-js/src/esmodule-helpers.js":"6ykb1"}],"5Otso":[function(e,t,r,n){var s,a=e("@parcel/transformer-js/src/esmodule-helpers.js");a.defineInteropFlag(r),a.export(r,"SupportedModels",()=>eR),a.export(r,"blurBodyPart",()=>eJ),a.export(r,"bodyPixMaskValueToRainbowColor",()=>b),a.export(r,"createSegmenter",()=>e$),a.export(r,"drawBokehEffect",()=>eQ),a.export(r,"drawMask",()=>eZ),a.export(r,"drawPixelatedMask",()=>eY),a.export(r,"toBinaryMask",()=>eK),a.export(r,"toColoredMask",()=>eX);var o=e("@tensorflow/tfjs-core"),l=e("@tensorflow/tfjs-converter"),i=e("@mediapipe/selfie_segmentation"),p=function(e,t){return(p=Object.setPrototypeOf||({__proto__:[]})instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function u(e,t){function r(){this.constructor=e}p(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var c=function(){return(c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&s[s.length-1])&&(6===i[0]||2===i[0])){o=0;continue}if(3===i[0]&&(!s||i[1]>s[0]&&i[1]=256)throw Error("Mask value must be in range [0, 255] but got "+e);if(!Number.isInteger(e))throw Error("Mask value must be an integer but got "+e)}var v=[[110,64,170],[143,61,178],[178,60,178],[210,62,167],[238,67,149],[255,78,125],[255,94,99],[255,115,75],[255,140,56],[239,167,47],[217,194,49],[194,219,64],[175,240,91],[135,245,87],[96,247,96],[64,243,115],[40,234,141],[28,219,169],[26,199,194],[33,176,213],[47,150,224],[65,125,224],[84,101,214],[99,81,195]];function b(e){if(y(e),er&&(s+=1,n+=Math.pow(e[a].x-t.keypoints[a].position.x,2)+Math.pow(e[a].y-t.keypoints[a].position.y,2));return 0===s?n=1/0:n/=s,n}(g,r[_]);I"+u+") {\n numKpt = numKpt + 1;\n curDistSum = curDistSum + dist(x, y, poseX, poseY);\n }\n }\n if (numKpt > 0 && curDistSum / float(numKpt)< minDist) {\n minDist = curDistSum / float(numKpt);\n iMin = i;\n }\n }\n return iMin;\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int nearestPose = findNearestPose(coords[0], coords[1]);\n setOutput(float(nearestPose));\n }\n "};return(0,o.backend)().compileAndRun(O,[e,b,R])}function $(){return"webgl"===(0,o.getBackend)()}function O(e){return Math.floor(e/2)}[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]].map(function(e){var t=e[0],r=e[1];return[S[t],S[r]]});var D=function(){function e(e,t){this.priorityQueue=Array(e),this.numberOfElements=-1,this.getElementValue=t}return e.prototype.enqueue=function(e){this.priorityQueue[++this.numberOfElements]=e,this.swim(this.numberOfElements)},e.prototype.dequeue=function(){var e=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,e},e.prototype.empty=function(){return -1===this.numberOfElements},e.prototype.size=function(){return this.numberOfElements+1},e.prototype.all=function(){return this.priorityQueue.slice(0,this.numberOfElements+1)},e.prototype.max=function(){return this.priorityQueue[0]},e.prototype.swim=function(e){for(;e>0&&this.less(O(e),e);)this.exchange(e,O(e)),e=O(e)},e.prototype.sink=function(e){for(;2*e<=this.numberOfElements;){var t=2*e;if(ta?a:s),x:(o=Math.round(e.x/t),l=n-1,o<0?0:o>l?l:o)}}function L(e,t,r,n,s,a,o,l){void 0===l&&(l=2);for(var i,p,u=n.shape,c=u[0],d=u[1],f=(i=V(t.position,a,c,d),p=o.shape[2]/2,{y:o.get(i.y,i.x,e),x:o.get(i.y,i.x,p+e)}),m=F(t.position,f),h=0;ht){p=!1;break}if(!p)break}return p}(u,c,i,p,1,r)&&l.enqueue({score:c,part:{heatmapY:i,heatmapX:p,id:u}})}return l}(o,0,e),u=l*l;i.length=0;--d){var f=B[d],m=G[d];i[f]&&!i[m]&&(i[m]=L(d,i[f],m,t,r,n,a))}for(d=0;d=.1,function(){return"inputResolution must be a string or number between 0.1 and 2, but was "+e}),e}(e);return[Y(n*a,t),Y(s*a,t)]}function et(e,t,r,n,s){var a=t[0],l=t[1],i=r[0],p=r[1],u=n[0],c=u[0],d=u[1],f=n[1],m=f[0],h=f[1];return void 0===s&&(s=!1),(0,o.tidy)(function(){var t,r,n,u,f,g,x,y,v,b,k,_=o.image.resizeBilinear(e,[i,p],!0);return s&&(_=(0,o.sigmoid)(_)),t=_,r=[a,l],n=[[c,d],[m,h]],u=r[0],f=r[1],x=(g=n[0])[0],y=g[1],b=(v=n[1])[0],k=v[1],(0,o.tidy)(function(){var e=(0,o.expandDims)(t);return(0,o.squeeze)(o.image.cropAndResize(e,[[x/(u+x+y-1),b/(f+b+k-1),(x+u-1)/(u+x+y-1),(b+f-1)/(f+b+k-1)]],[0],[u,f]),[0])})})}function er(e,t){var r=t[0],n=t[1],s=Z(e),a=s[0],l=s[1],i=n/r,p=0,u=0,c=0,d=0;return l/a1)throw Error("segmentationThreshold "+t+". Should be in range [0.0, 1.0]");if(r<=0)throw Error("Invalid maxDetections "+r+". Should be >0");if(n<0||n>1)throw Error("Invalid scoreThreshold "+n+". Should be in range [0.0, 1.0]");if(s<=0)throw Error("Invalid nmsRadius "+s+".")}function ef(e){var t=e.segmentationThreshold,r=e.maxDetections,n=e.scoreThreshold,s=e.nmsRadius,a=e.minKeypointScore,o=e.refineSteps;if(t<0||t>1)throw Error("segmentationThreshold "+t+". Should be in range [0.0, 1.0]");if(r<=0)throw Error("Invalid maxDetections "+r+". Should be >0");if(n<0||n>1)throw Error("Invalid scoreThreshold "+n+". Should be in range [0.0, 1.0]");if(s<=0)throw Error("Invalid nmsRadius "+s+".");if(a<0||a>1)throw Error("Invalid minKeypointScore "+a+".Should be in range [0.0, 1.0]");if(o<=0||o>20)throw Error("Invalid refineSteps "+o+".Should be in range [1, 20]")}var em=function(){function e(e){this.baseModel=e}return e.prototype.predictForPersonSegmentation=function(e){var t=this.baseModel.predict(e);return{segmentLogits:t.segmentation,heatmapScores:t.heatmapScores,offsets:t.offsets,displacementFwd:t.displacementFwd,displacementBwd:t.displacementBwd}},e.prototype.predictForPersonSegmentationAndPart=function(e){var t=this.baseModel.predict(e);return{segmentLogits:t.segmentation,partHeatmapLogits:t.partHeatmaps,heatmapScores:t.heatmapScores,offsets:t.offsets,displacementFwd:t.displacementFwd,displacementBwd:t.displacementBwd}},e.prototype.predictForMultiPersonInstanceSegmentationAndPart=function(e){var t=this.baseModel.predict(e);return{segmentLogits:t.segmentation,longOffsets:t.longOffsets,heatmapScores:t.heatmapScores,offsets:t.offsets,displacementFwd:t.displacementFwd,displacementBwd:t.displacementBwd,partHeatmaps:t.partHeatmaps}},e.prototype.segmentPersonActivation=function(e,t,r){var n=this;void 0===r&&(r=.5);var s=Z(e),a=s[0],l=s[1],i=ee(t,this.baseModel.outputStride,[a,l]),p=er(e,i),u=p.resized,c=p.padding,d=(0,o.tidy)(function(){var e=n.predictForPersonSegmentation(u),t=e.segmentLogits,s=e.heatmapScores,i=e.offsets,p=e.displacementFwd,d=e.displacementBwd,f=u.shape,m=et(t,[a,l],[f[0],f[1]],[[c.top,c.bottom],[c.left,c.right]],!0);return{segmentation:_((0,o.squeeze)(m),r),heatmapScores:s,offsets:i,displacementFwd:p,displacementBwd:d}}),f=d.segmentation,m=d.heatmapScores,h=d.offsets,g=d.displacementFwd,x=d.displacementBwd;return u.dispose(),{segmentation:f,heatmapScores:m,offsets:h,displacementFwd:g,displacementBwd:x,padding:c,internalResolutionHeightAndWidth:i}},e.prototype.segmentPerson=function(e,t){return void 0===t&&(t=eu),d(this,void 0,void 0,function(){var r,n,s,a,o,l,i,p,u,d,m,h,g,x,y,v;return f(this,function(f){switch(f.label){case 0:return ed(t=c(c({},eu),t)),n=(r=this.segmentPersonActivation(e,t.internalResolution,t.segmentationThreshold)).segmentation,s=r.heatmapScores,a=r.offsets,o=r.displacementFwd,l=r.displacementBwd,i=r.padding,p=r.internalResolutionHeightAndWidth,d=(u=n.shape)[0],m=u[1],[4,n.data()];case 1:return h=f.sent(),n.dispose(),[4,en([s,a,o,l])];case 2:return x=(g=f.sent())[0],y=g[1],v=es(v=U(x,y,g[2],g[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[d,m],p,i,!1),s.dispose(),a.dispose(),o.dispose(),l.dispose(),[2,{height:d,width:m,data:h,allPoses:v}]}})})},e.prototype.segmentMultiPerson=function(e,t){return void 0===t&&(t=ec),d(this,void 0,void 0,function(){var r,n,s,a,l,i,p,u,m,h,g,x,y,v,b,k,I,j,w,T=this;return f(this,function(S){switch(S.label){case 0:return ef(t=c(c({},ec),t)),n=(r=Z(e))[0],s=r[1],i=(l=er(e,a=ee(t.internalResolution,this.baseModel.outputStride,[n,s]))).resized,p=l.padding,m=(u=(0,o.tidy)(function(){var e=T.predictForMultiPersonInstanceSegmentationAndPart(i),r=e.segmentLogits,l=e.longOffsets,u=e.heatmapScores,c=e.offsets,d=e.displacementFwd,f=e.displacementBwd,m=et(r,[n,s],a,[[p.top,p.bottom],[p.left,p.right]],!0);return{segmentation:_((0,o.squeeze)(m),t.segmentationThreshold),longOffsets:l,heatmapScoresRaw:u,offsetsRaw:c,displacementFwdRaw:d,displacementBwdRaw:f}})).segmentation,h=u.longOffsets,g=u.heatmapScoresRaw,x=u.offsetsRaw,y=u.displacementFwdRaw,v=u.displacementBwdRaw,[4,en([g,x,y,v])];case 1:return k=(b=S.sent())[0],I=b[1],j=es(j=U(k,I,b[2],b[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[n,s],a,p,!1),[4,function(e,t,r,n,s,a,l,i,p,u,c,m){var h=l[0],g=l[1];return void 0===p&&(p=.2),void 0===u&&(u=8),void 0===c&&(c=.3),void 0===m&&(m=10),d(this,void 0,void 0,function(){var l,d,x,y,v;return f(this,function(f){switch(f.label){case 0:return l=r.filter(function(e){return e.score>=p}),$()?[4,Promise.all((x=(0,o.tidy)(function(){var r=P(e,t,l,n,s,a,[h,g],i,u,c,m),p=(0,o.engine)().makeTensorFromDataId(r.dataId,r.shape,r.dtype);return l.map(function(e,t){return(0,o.tidy)(function(){return(0,o.cast)((0,o.equal)(p,(0,o.scalar)(t)),"int32")})})})).map(function(e){return e.data()}))]:[3,2];case 1:return d=f.sent(),x.forEach(function(e){return e.dispose()}),[3,5];case 2:return[4,e.data()];case 3:return y=f.sent(),[4,t.data()];case 4:v=f.sent(),d=function(e,t,r,n,s,a,o,l,i,p){var u=o[0],c=o[1];void 0===p&&(p=5);for(var d=r.map(function(e){return new Uint8Array(n*s).fill(0)}),f=l.top,m=l.left,h=C([n,s],[u,c],l),g=h[0],x=h[1],y=R([u,c],a)[0],v=0;v=0&&(d[_][k]=1)}}return d}(y,v,l,n,s,a,[h,g],i,u),f.label=5;case 5:return[2,d.map(function(e,t){return{data:e,pose:l[t],width:s,height:n}})]}})})}(m,h,j,n,s,this.baseModel.outputStride,a,p,t.scoreThreshold,t.refineSteps,t.minKeypointScore,t.maxDetections)];case 2:return w=S.sent(),i.dispose(),m.dispose(),h.dispose(),g.dispose(),x.dispose(),y.dispose(),v.dispose(),[2,w]}})})},e.prototype.segmentPersonPartsActivation=function(e,t,r){var n=this;void 0===r&&(r=.5);var s=Z(e),a=s[0],l=s[1],i=ee(t,this.baseModel.outputStride,[a,l]),p=er(e,i),u=p.resized,c=p.padding,d=(0,o.tidy)(function(){var e,t,s,i,p,d=n.predictForPersonSegmentationAndPart(u),f=d.segmentLogits,m=d.partHeatmapLogits,h=d.heatmapScores,g=d.offsets,x=d.displacementFwd,y=d.displacementBwd,v=u.shape,b=v[0],I=v[1],j=et(f,[a,l],[b,I],[[c.top,c.bottom],[c.left,c.right]],!0),w=et(m,[a,l],[b,I],[[c.top,c.bottom],[c.left,c.right]],!0);return{partSegmentation:(e=_((0,o.squeeze)(j),r),s=(t=w.shape)[0],i=t[1],p=t[2],(0,o.tidy)(function(){var t=k(w),r=(0,o.expandDims)((0,o.range)(0,p,1,"int32"),1),n=(0,o.cast)((0,o.matMul)(t,r),"int32"),a=(0,o.reshape)(n,[s,i]),l=(0,o.add)(a,(0,o.scalar)(1,"int32"));return(0,o.sub)((0,o.mul)(l,e),(0,o.scalar)(1,"int32"))})),heatmapScores:h,offsets:g,displacementFwd:x,displacementBwd:y}}),f=d.partSegmentation,m=d.heatmapScores,h=d.offsets,g=d.displacementFwd,x=d.displacementBwd;return u.dispose(),{partSegmentation:f,heatmapScores:m,offsets:h,displacementFwd:g,displacementBwd:x,padding:c,internalResolutionHeightAndWidth:i}},e.prototype.segmentPersonParts=function(e,t){return void 0===t&&(t=eu),d(this,void 0,void 0,function(){var r,n,s,a,o,l,i,p,u,d,m,h,g,x,y,v;return f(this,function(f){switch(f.label){case 0:return ed(t=c(c({},eu),t)),n=(r=this.segmentPersonPartsActivation(e,t.internalResolution,t.segmentationThreshold)).partSegmentation,s=r.heatmapScores,a=r.offsets,o=r.displacementFwd,l=r.displacementBwd,i=r.padding,p=r.internalResolutionHeightAndWidth,d=(u=n.shape)[0],m=u[1],[4,n.data()];case 1:return h=f.sent(),n.dispose(),[4,en([s,a,o,l])];case 2:return x=(g=f.sent())[0],y=g[1],v=es(v=U(x,y,g[2],g[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[d,m],p,i,!1),s.dispose(),a.dispose(),o.dispose(),l.dispose(),[2,{height:d,width:m,data:h,allPoses:v}]}})})},e.prototype.segmentMultiPersonParts=function(e,t){return void 0===t&&(t=ec),d(this,void 0,void 0,function(){var r,n,s,a,l,i,p,u,m,h,g,x,y,v,b,I,j,w,T,S,N=this;return f(this,function(E){switch(E.label){case 0:return ef(t=c(c({},ec),t)),n=(r=Z(e))[0],s=r[1],i=(l=er(e,a=ee(t.internalResolution,this.baseModel.outputStride,[n,s]))).resized,p=l.padding,m=(u=(0,o.tidy)(function(){var e,r,l,u,c=N.predictForMultiPersonInstanceSegmentationAndPart(i),d=c.segmentLogits,f=c.longOffsets,m=c.heatmapScores,h=c.offsets,g=c.displacementFwd,x=c.displacementBwd,y=c.partHeatmaps,v=et(d,[n,s],a,[[p.top,p.bottom],[p.left,p.right]],!0),b=et(y,[n,s],a,[[p.top,p.bottom],[p.left,p.right]],!0);return{segmentation:_((0,o.squeeze)(v),t.segmentationThreshold),longOffsets:f,heatmapScoresRaw:m,offsetsRaw:h,displacementFwdRaw:g,displacementBwdRaw:x,partSegmentation:(r=(e=b.shape)[0],l=e[1],u=e[2],(0,o.tidy)(function(){var e=k(b),t=(0,o.expandDims)((0,o.range)(0,u,1,"int32"),1),n=(0,o.cast)((0,o.matMul)(e,t),"int32");return(0,o.reshape)(n,[r,l])}))}})).segmentation,h=u.longOffsets,g=u.heatmapScoresRaw,x=u.offsetsRaw,y=u.displacementFwdRaw,v=u.displacementBwdRaw,b=u.partSegmentation,[4,en([g,x,y,v])];case 1:return j=(I=E.sent())[0],w=I[1],T=es(T=U(j,w,I[2],I[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[n,s],a,p,!1),[4,function(e,t,r,n,s,a,l,i,p,u,c,m,h){var g=i[0],x=i[1];return void 0===u&&(u=.2),void 0===c&&(c=8),void 0===m&&(m=.3),void 0===h&&(h=10),d(this,void 0,void 0,function(){var i,d,y,v,b,k;return f(this,function(f){switch(f.label){case 0:return i=n.filter(function(e){return e.score>=u}),$()?[4,Promise.all((y=(0,o.tidy)(function(){var n=P(e,t,i,s,a,l,[g,x],p,c,m,h),u=(0,o.engine)().makeTensorFromDataId(n.dataId,n.shape,n.dtype);return i.map(function(e,t){return(0,o.tidy)(function(){return(0,o.sub)((0,o.mul)((0,o.cast)((0,o.equal)(u,(0,o.scalar)(t)),"int32"),(0,o.add)(r,1)),1)})})})).map(function(e){return e.data()}))]:[3,2];case 1:return d=f.sent(),y.forEach(function(e){return e.dispose()}),[3,6];case 2:return[4,e.data()];case 3:return v=f.sent(),[4,t.data()];case 4:return b=f.sent(),[4,r.data()];case 5:k=f.sent(),d=function(e,t,r,n,s,a,o,l,i,p,u){var c=l[0],d=l[1];void 0===u&&(u=5);for(var f=n.map(function(e){return new Int32Array(s*a).fill(-1)}),m=i.top,h=i.left,g=C([s,a],[c,d],i),x=g[0],y=g[1],v=R([c,d],o)[0],b=0;b=0&&(f[I][_]=r[_])}}return f}(v,b,k,i,s,a,l,[g,x],p,c),f.label=6;case 6:return[2,d.map(function(e,t){return{pose:i[t],data:e,height:s,width:a}})]}})})}(m,h,b,T,n,s,this.baseModel.outputStride,a,p,t.scoreThreshold,t.refineSteps,t.minKeypointScore,t.maxDetections)];case 2:return S=E.sent(),i.dispose(),m.dispose(),h.dispose(),g.dispose(),x.dispose(),y.dispose(),v.dispose(),b.dispose(),[2,S]}})})},e.prototype.dispose=function(){this.baseModel.dispose()},e}(),eh=["left_face","right_face","left_upper_arm_front","left_upper_arm_back","right_upper_arm_front","right_upper_arm_back","left_lower_arm_front","left_lower_arm_back","right_lower_arm_front","right_lower_arm_back","left_hand","right_hand","torso_front","torso_back","left_upper_leg_front","left_upper_leg_back","right_upper_leg_front","right_upper_leg_back","left_lower_leg_front","left_lower_leg_back","right_lower_leg_front","right_lower_leg_back","left_feet","right_feet"],eg=function(){function e(e){this.mask=e}return e.prototype.toCanvasImageSource=function(){return d(this,void 0,void 0,function(){return f(this,function(e){return[2,h(this.mask)]})})},e.prototype.toImageData=function(){return d(this,void 0,void 0,function(){return f(this,function(e){return[2,this.mask]})})},e.prototype.toTensor=function(){return d(this,void 0,void 0,function(){return f(this,function(e){return[2,x(this.mask)]})})},e.prototype.getUnderlyingType=function(){return"imagedata"},e}();function ex(e){if(y(e),255!==e)throw Error("Foreground id must be 255 but got "+e);return"person"}function ey(e){if(y(e),e>=eh.length)throw Error("Invalid body part value "+e);return eh[e]}var ev=function(){function e(e){this.bodyPixModel=e}return e.prototype.segmentPeople=function(e,t){return d(this,void 0,void 0,function(){var r,n,s,a;return f(this,function(o){switch(o.label){case 0:return e instanceof ImageBitmap&&((r=document.createElement("canvas")).getContext("2d").drawImage(e,0,0),e=r),t.segmentBodyParts?t.multiSegmentation?[4,this.bodyPixModel.segmentMultiPersonParts(e,t)]:[3,2]:[3,5];case 1:return s=o.sent(),[3,4];case 2:return[4,this.bodyPixModel.segmentPersonParts(e,t)];case 3:s=[o.sent()],o.label=4;case 4:return n=s.map(function(e){var t=e.data,r=e.width,n=e.height,s=new Uint8ClampedArray(r*n*4).fill(0);return t.forEach(function(e,t){-1===e?(s[4*t]=eh.length,s[4*t+3]=0):(s[4*t]=e,s[4*t+3]=255)}),{maskValueToLabel:ey,mask:new eg(new ImageData(s,r,n))}}),[3,10];case 5:return t.multiSegmentation?[4,this.bodyPixModel.segmentMultiPerson(e,t)]:[3,7];case 6:return a=o.sent(),[3,9];case 7:return[4,this.bodyPixModel.segmentPerson(e,t)];case 8:a=[o.sent()],o.label=9;case 9:n=a.map(function(e){var t=e.data,r=e.width,n=e.height,s=new Uint8ClampedArray(r*n*4).fill(0);return t.forEach(function(e,t){0===e?(s[4*t]=0,s[4*t+3]=0):(s[4*t]=255,s[4*t+3]=255)}),{maskValueToLabel:ex,mask:new eg(new ImageData(s,r,n))}}),o.label=10;case 10:return[2,n]}})})},e.prototype.dispose=function(){this.bodyPixModel.dispose()},e.prototype.reset=function(){},e}(),eb={runtime:"mediapipe",modelType:"general"},ek=function(){function e(e){this.mask=e}return e.prototype.toCanvasImageSource=function(){return d(this,void 0,void 0,function(){return f(this,function(e){return[2,this.mask]})})},e.prototype.toImageData=function(){return d(this,void 0,void 0,function(){return f(this,function(e){return[2,g(this.mask)]})})},e.prototype.toTensor=function(){return d(this,void 0,void 0,function(){return f(this,function(e){return[2,x(this.mask)]})})},e.prototype.getUnderlyingType=function(){return"canvasimagesource"},e}();function e_(e){return y(e),"person"}var eI=function(){function e(e){var t,r,n=this;this.selfieMode=!1,t=+(this.selfieSegmentationSolution=new(0,i.SelfieSegmentation)({locateFile:null!=(r=e.locateFile)?r:function(t,r){return e.solutionPath?e.solutionPath.replace(/\/+$/,"")+"/"+t:r+"/"+t}}),"landscape"===e.modelType),this.selfieSegmentationSolution.setOptions({modelSelection:t,selfieMode:this.selfieMode}),this.selfieSegmentationSolution.onResults(function(e){n.segmentation=[{maskValueToLabel:e_,mask:new ek(e.segmentationMask)}]})}return e.prototype.segmentPeople=function(e,t){return d(this,void 0,void 0,function(){var r,n;return f(this,function(s){switch(s.label){case 0:return t&&t.flipHorizontal&&t.flipHorizontal!==this.selfieMode&&(this.selfieMode=t.flipHorizontal,this.selfieSegmentationSolution.setOptions({selfieMode:this.selfieMode})),e instanceof o.Tensor?(n=ImageData.bind,[4,o.browser.toPixels(e)]):[3,2];case 1:return r=new(n.apply(ImageData,[void 0,s.sent(),e.shape[1],e.shape[0]])),[3,3];case 2:r=e,s.label=3;case 3:return e=r,[4,this.selfieSegmentationSolution.send({image:e})];case 4:return s.sent(),[2,this.segmentation]}})})},e.prototype.dispose=function(){this.selfieSegmentationSolution.close()},e.prototype.reset=function(){this.selfieSegmentationSolution.reset(),this.segmentation=null,this.selfieMode=!1},e.prototype.initialize=function(){return this.selfieSegmentationSolution.initialize()},e}();function ej(e){return e instanceof o.Tensor?{height:e.shape[0],width:e.shape[1]}:{height:e.height,width:e.width}}function ew(e,t){o.util.assert(0!==e.width,function(){return t+" width cannot be 0."}),o.util.assert(0!==e.height,function(){return t+" height cannot be 0."})}var eT={runtime:"tfjs",modelType:"general",modelUrl:"https://tfhub.dev/mediapipe/tfjs-model/selfie_segmentation/general/1"},eS={flipHorizontal:!1},eC={outputTensorSize:{width:256,height:256},keepAspectRatio:!1,borderMode:"zero",outputTensorFloatRange:[0,1]},eN={outputTensorSize:{width:256,height:144},keepAspectRatio:!1,borderMode:"zero",outputTensorFloatRange:[0,1]},eE={activation:"none"},eF=function(){function e(e){this.mask=e}return e.prototype.toCanvasImageSource=function(){return d(this,void 0,void 0,function(){return f(this,function(e){return[2,h(this.mask)]})})},e.prototype.toImageData=function(){return d(this,void 0,void 0,function(){return f(this,function(e){return[2,g(this.mask)]})})},e.prototype.toTensor=function(){return d(this,void 0,void 0,function(){return f(this,function(e){return[2,this.mask]})})},e.prototype.getUnderlyingType=function(){return"tensor"},e}();function eA(e){return y(e),"person"}var eR,eP=function(){function e(e,t){this.modelType=e,this.model=t}return e.prototype.segmentPeople=function(e,t){return d(this,void 0,void 0,function(){var r=this;return f(this,function(n){return t=function(e){if(null==e)return c({},eS);var t=c({},e);return null==t.flipHorizontal&&(t.flipHorizontal=eS.flipHorizontal),t}(t),null==e?(this.reset(),[2,[]]):[2,[{maskValueToLabel:eA,mask:new eF((0,o.tidy)(function(){var t,n,s,a,l,i,p,u,c,d,f,m,h,g,x,y,v,b,k,_,I,j,w=(x=(t="general"===r.modelType?eC:eN).outputTensorSize,y=t.keepAspectRatio,v=t.borderMode,b=t.outputTensorFloatRange,I=function(e,t,r){if(void 0===r&&(r=!1),!r)return{top:0,left:0,right:0,bottom:0};var n=t.height,s=t.width;ew(t,"targetSize"),ew(e,"roi");var a,o,l=n/s,i=e.height/e.width,p=0,u=0;return l>i?(a=e.width,o=e.width*l,u=(1-i/l)/2):(a=e.height/l,o=e.height,p=(1-l/i)/2),e.width=a,e.height=o,{top:u,left:p,right:p,bottom:u}}((n=k=ej(e),_={xCenter:.5*n.width,yCenter:.5*n.height,width:n.width,height:n.height,rotation:0}),x,y),s=k.width,a=k.height,l=_.width,i=_.height,p=1,u=Math.cos(_.rotation),c=Math.sin(_.rotation),d=_.xCenter,f=_.yCenter,m=1/s,h=1/a,(g=Array(16))[0]=l*u*p*m,g[1]=-i*c*m,g[2]=0,g[3]=(-.5*l*u*p+.5*i*c+d)*m,g[4]=l*c*p*h,g[5]=i*u*h,g[6]=0,g[7]=(-.5*i*u-.5*l*c*p+f)*h,g[8]=0,g[9]=0,g[10]=l*m,g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,j=function(e){if(16!==e.length)throw Error("Array length must be 16 but got "+e.length);return[[e[0],e[1],e[2],e[3]],[e[4],e[5],e[6],e[7]],[e[8],e[9],e[10],e[11]],[e[12],e[13],e[14],e[15]]]}(g),{imageTensor:(0,o.tidy)(function(){var t,r=e instanceof o.Tensor?e:o.browser.fromPixels(e),n=(0,o.tensor2d)((ew(x,"inputResolution"),[1/x.width*j[0][0]*k.width,1/x.height*j[0][1]*k.width,j[0][3]*k.width,1/x.width*j[1][0]*k.height,1/x.height*j[1][1]*k.height,j[1][3]*k.height,0,0]),[1,8]),s=o.image.transform((0,o.expandDims)((0,o.cast)(r,"float32")),n,"bilinear","zero"===v?"constant":"nearest",0,[x.height,x.width]);return null!=b?(t=function(e,t,r,n){!1;var s=(n-r)/255;return{scale:s,offset:r-0*s}}(0,0,b[0],b[1]),(0,o.tidy)(function(){return(0,o.add)((0,o.mul)(s,t.scale),t.offset)})):s}),padding:I,transformationMatrix:j}).imageTensor,T=(0,o.slice)(r.model.predict(w),[0,0,0,1],-1),S=ej(e),C=(0,o.tidy)(function(){var e=(0,o.squeeze)(T,[0]),t=e.shape[2];if(1===t){var r=e;switch(eE.activation){case"none":break;case"sigmoid":r=(0,o.sigmoid)(r);break;case"softmax":throw Error("Softmax activation requires two channels.");default:throw Error("Activation not supported ("+eE.activation+")")}var n=S?o.image.resizeBilinear(r,[S.height,S.width]):r;return(0,o.squeeze)(n,[2])}throw Error("Unsupported number of tensor channels "+t)}),N=(0,o.expandDims)(C,2),E=(0,o.pad)(N,[[0,0],[0,0],[0,1]]);return(0,o.mirrorPad)(E,[[0,0],[0,0],[0,2]],"symmetric")}))}]]})})},e.prototype.dispose=function(){this.model.dispose()},e.prototype.reset=function(){},e}();function e$(e,t){return d(this,void 0,void 0,function(){var r,n;return f(this,function(s){switch(e){case eR.MediaPipeSelfieSegmentation:if(r=void 0,null!=(n=t)){if("tfjs"===n.runtime)return[2,function(e){return d(this,void 0,void 0,function(){var t,r,n;return f(this,function(s){switch(s.label){case 0:return r="string"==typeof(t=function(e){if(null==e)return c({},eT);var t=c({},e);if(t.runtime="tfjs",null==t.modelType&&(t.modelType=eT.modelType),"general"!==t.modelType&&"landscape"!==t.modelType)throw Error("Model type must be one of general or landscape, but got "+t.modelType);return null==t.modelUrl&&("general"===t.modelType?t.modelUrl="https://tfhub.dev/mediapipe/tfjs-model/selfie_segmentation/general/1":t.modelUrl="https://tfhub.dev/mediapipe/tfjs-model/selfie_segmentation/landscape/1"),t}(e)).modelUrl&&t.modelUrl.indexOf("https://tfhub.dev")>-1,[4,(0,l.loadGraphModel)(t.modelUrl,{fromTFHub:r})];case 1:return n=s.sent(),[2,new eP(t.modelType,n)]}})})}(n)];if("mediapipe"===n.runtime)return[2,function(e){return d(this,void 0,void 0,function(){var t;return f(this,function(r){switch(r.label){case 0:return[4,(t=new eI(function(e){if(null==e)return c({},eb);var t=c({},e);return t.runtime="mediapipe",null==t.modelType&&(t.modelType=eb.modelType),t}(e))).initialize()];case 1:return r.sent(),[2,t]}})})}(n)];r=n.runtime}throw Error("Expect modelConfig.runtime to be either 'tfjs' or 'mediapipe', but got "+r);case eR.BodyPix:return[2,function(e){return d(this,void 0,void 0,function(){return f(this,function(t){return[2,(function(e){return void 0===e&&(e=ea),d(this,void 0,void 0,function(){return f(this,function(t){return"ResNet50"===(e=function(e){if(null==(e=e||ea).architecture&&(e.architecture="MobileNetV1"),0>eo.indexOf(e.architecture))throw Error("Invalid architecture "+e.architecture+". Should be one of "+eo);if(null==e.outputStride&&(e.outputStride=16),0>el[e.architecture].indexOf(e.outputStride))throw Error("Invalid outputStride "+e.outputStride+". Should be one of "+el[e.architecture]+" for architecture "+e.architecture+".");if(null==e.multiplier&&(e.multiplier=1),0>ei[e.architecture].indexOf(e.multiplier))throw Error("Invalid multiplier "+e.multiplier+". Should be one of "+ei[e.architecture]+" for architecture "+e.architecture+".");if(null==e.quantBytes&&(e.quantBytes=4),0>ep.indexOf(e.quantBytes))throw Error("Invalid quantBytes "+e.quantBytes+". Should be one of "+ep+" for architecture "+e.architecture+".");return e}(e)).architecture?[2,function(e){return d(this,void 0,void 0,function(){var t,r,n;return f(this,function(s){switch(s.label){case 0:var a;if(t=e.outputStride,r=e.quantBytes,null==o)throw Error("Cannot find TensorFlow.js. If you are using a