/*! * artplayer-plugin-danmuku-mask.js v1.0.0 * Github: https://github.com/zhw2590582/ArtPlayer * (c) 2017-2026 Harvey Zack * Released under the MIT License. */ !function(e,t,r,n,s){var a="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:{},o="function"==typeof a[n]&&a[n],l=o.i||{},i=o.cache||{},u="u">typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(t,r){if(!i[t]){if(!e[t]){if(s[t])return s[t];var l="function"==typeof a[n]&&a[n];if(!r&&l)return l(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}f.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},f.cache={};var d=i[t]=new p.Module(t);e[t][0].call(d.exports,f,d,d.exports,a)}return i[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],s=e[2]||e[0],a=p(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 p(t)}}p.isParcelRequire=!0,p.Module=function(e){this.id=e,this.bundle=p,this.require=u,this.exports={}},p.modules=e,p.cache=i,p.parent=o,p.distDir=void 0,p.publicUrl=void 0,p.devServer=void 0,p.i=l,p.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(p,"root",{get:function(){return a[n]}}),a[n]=p;for(var c=0;ctypeof module?module.exports=d:"function"==typeof define&&define.amd&&define(function(){return d})}}({"1AHlH":[function(e,t,r,n){var s=e("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"default",()=>l);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,u=null,p=!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),p=!0}catch(e){console.error("Error initializing segmenter:",e),p=!1}}async function h(){if(!p||r.paused||r.ended){u=requestAnimationFrame(h);return}try{l.width=r.videoWidth,l.height=r.videoHeight;let e=await s.segmentPeople(r);if(!e||0===e.length){u=requestAnimationFrame(h);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)}u=requestAnimationFrame(h)}async function m(){p||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"}),h()}function g(){n.style.maskImage="none",u&&(cancelAnimationFrame(u),u=null)}return t.on("ready",m),t.on("destroy",g),{name:"artplayerPluginDanmukuMask",start:m,stop:g}}}e("@tensorflow/tfjs-backend-webgl"),e("@tensorflow/tfjs-backend-cpu"),"u">typeof window&&(window.artplayerPluginDanmukuMask=l)},{"@tensorflow-models/body-segmentation":"9d7iE","@tensorflow/tfjs-core":"hADTC","@tensorflow/tfjs-backend-webgl":"3qRAd","@tensorflow/tfjs-backend-cpu":"ilpJu","@parcel/transformer-js/src/esmodule-helpers.js":"loqXi"}],"9d7iE":[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",()=>eQ),a.export(r,"bodyPixMaskValueToRainbowColor",()=>_),a.export(r,"createSegmenter",()=>eP),a.export(r,"drawBokehEffect",()=>eZ),a.export(r,"drawMask",()=>eJ),a.export(r,"drawPixelatedMask",()=>eY),a.export(r,"toBinaryMask",()=>eH),a.export(r,"toColoredMask",()=>eK);var o=e("@tensorflow/tfjs-core"),l=e("@tensorflow/tfjs-converter"),i=e("@mediapipe/selfie_segmentation"),u=function(e,t){return(u=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 p(e,t){function r(){this.constructor=e}u(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 y=[[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 _(e){if(v(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[k]);T"+p+") {\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($,[e,_,R])}function P(){return"webgl"===(0,o.getBackend)()}function $(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[C[t],C[r]]});var M=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($(e),e);)this.exchange(e,$(e)),e=$(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 V(e,t,r,n,s,a,o,l){void 0===l&&(l=2);for(var i,u,p=n.shape,c=p[0],d=p[1],f=(i=L(t.position,a,c,d),u=o.shape[2]/2,{y:o.get(i.y,i.x,e),x:o.get(i.y,i.x,u+e)}),h=A(t.position,f),m=0;mt){i=!1;break}if(!i)break}return i}(u,p,l,i,t)&&o.enqueue({score:p,part:{heatmapY:l,heatmapX:i,id:u}})}return o}(o,e),p=l*l;i.length=0;--d){var f=B[d],h=q[d];i[f]&&!i[h]&&(i[h]=V(d,i[f],h,t,r,n,a))}for(d=0;dtypeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"u">typeof OffscreenCanvas&&e instanceof OffscreenCanvas||"u">typeof HTMLImageElement&&e instanceof HTMLImageElement){if("offsetHeight"in e&&0!==e.offsetHeight&&"offsetWidth"in e&&0!==e.offsetWidth)return[e.offsetHeight,e.offsetWidth];if(null!=e.height&&null!=e.width)return[e.height,e.width];throw Error("HTMLImageElement must have height and width attributes set.")}if("u">typeof ImageData&&e instanceof ImageData)return[e.height,e.width];if("u">typeof HTMLVideoElement&&e instanceof HTMLVideoElement)return e.hasAttribute("height")&&e.hasAttribute("width")?[e.height,e.width]:[e.videoHeight,e.videoWidth];if(e instanceof o.Tensor)return[e.shape[0],e.shape[1]];throw Error("error: Unknown input type: "+e+".")}function Y(e,t){return(e-1)%t==0?e:Math.floor(e/t)*t+1}var Z={low:"low",medium:"medium",high:"high",full:"full"},Q=((U={})[Z.low]=.25,U[Z.medium]=.5,U[Z.high]=.75,U[Z.full]=1,U);function ee(e,t,r){var n=r[0],s=r[1],a=function(e){if("string"==typeof e){var t=Q[e];return o.util.assert("number"==typeof t,function(){return"string value of inputResolution must be one of "+Object.values(Z).join(",")+" but was "+e+"."}),t}return o.util.assert("number"==typeof e&&e<=2&&e>=.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],u=r[1],p=n[0],c=p[0],d=p[1],f=n[1],h=f[0],m=f[1];return void 0===s&&(s=!1),(0,o.tidy)(function(){var t,r,n,p,f,g,x,v,y,_,b,k=o.image.resizeBilinear(e,[i,u],!0);return s&&(k=(0,o.sigmoid)(k)),t=k,r=[a,l],n=[[c,d],[h,m]],p=r[0],f=r[1],x=(g=n[0])[0],v=g[1],_=(y=n[1])[0],b=y[1],(0,o.tidy)(function(){var e=(0,o.expandDims)(t);return(0,o.squeeze)(o.image.cropAndResize(e,[[x/(p+x+v-1),_/(f+_+b-1),(x+p-1)/(p+x+v-1),(_+f-1)/(f+_+b-1)]],[0],[p,f]),[0])})})}function er(e,t){var r=t[0],n=t[1],s=J(e),a=s[0],l=s[1],i=n/r,u=0,p=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 eh=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=J(e),a=s[0],l=s[1],i=ee(t,this.baseModel.outputStride,[a,l]),u=er(e,i),p=u.resized,c=u.padding,d=(0,o.tidy)(function(){var e=n.predictForPersonSegmentation(p),t=e.segmentLogits,s=e.heatmapScores,i=e.offsets,u=e.displacementFwd,d=e.displacementBwd,f=p.shape,h=et(t,[a,l],[f[0],f[1]],[[c.top,c.bottom],[c.left,c.right]],!0);return{segmentation:k((0,o.squeeze)(h),r),heatmapScores:s,offsets:i,displacementFwd:u,displacementBwd:d}}),f=d.segmentation,h=d.heatmapScores,m=d.offsets,g=d.displacementFwd,x=d.displacementBwd;return p.dispose(),{segmentation:f,heatmapScores:h,offsets:m,displacementFwd:g,displacementBwd:x,padding:c,internalResolutionHeightAndWidth:i}},e.prototype.segmentPerson=function(e,t){return void 0===t&&(t=ep),d(this,void 0,void 0,function(){var r,n,s,a,o,l,i,u,p,d,h,m,g,x,v,y;return f(this,function(f){switch(f.label){case 0:return ed(t=c(c({},ep),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,u=r.internalResolutionHeightAndWidth,d=(p=n.shape)[0],h=p[1],[4,n.data()];case 1:return m=f.sent(),n.dispose(),[4,en([s,a,o,l])];case 2:return x=(g=f.sent())[0],v=g[1],y=es(y=z(x,v,g[2],g[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[d,h],u,i,!1),s.dispose(),a.dispose(),o.dispose(),l.dispose(),[2,{height:d,width:h,data:m,allPoses:y}]}})})},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,u,p,h,m,g,x,v,y,_,b,T,w,I,j=this;return f(this,function(C){switch(C.label){case 0:return ef(t=c(c({},ec),t)),n=(r=J(e))[0],s=r[1],i=(l=er(e,a=ee(t.internalResolution,this.baseModel.outputStride,[n,s]))).resized,u=l.padding,h=(p=(0,o.tidy)(function(){var e=j.predictForMultiPersonInstanceSegmentationAndPart(i),r=e.segmentLogits,l=e.longOffsets,p=e.heatmapScores,c=e.offsets,d=e.displacementFwd,f=e.displacementBwd,h=et(r,[n,s],a,[[u.top,u.bottom],[u.left,u.right]],!0);return{segmentation:k((0,o.squeeze)(h),t.segmentationThreshold),longOffsets:l,heatmapScoresRaw:p,offsetsRaw:c,displacementFwdRaw:d,displacementBwdRaw:f}})).segmentation,m=p.longOffsets,g=p.heatmapScoresRaw,x=p.offsetsRaw,v=p.displacementFwdRaw,y=p.displacementBwdRaw,[4,en([g,x,v,y])];case 1:return b=(_=C.sent())[0],T=_[1],w=es(w=z(b,T,_[2],_[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[n,s],a,u,!1),[4,function(e,t,r,n,s,a,l,i,u,p,c,h){var m=l[0],g=l[1];return void 0===u&&(u=.2),void 0===p&&(p=8),void 0===c&&(c=.3),void 0===h&&(h=10),d(this,void 0,void 0,function(){var l,d,x,v,y;return f(this,function(f){switch(f.label){case 0:return l=r.filter(function(e){return e.score>=u}),P()?[4,Promise.all((x=(0,o.tidy)(function(){var r=D(e,t,l,n,s,a,[m,g],i,p,c,h),u=(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)(u,(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 v=f.sent(),[4,t.data()];case 4:y=f.sent(),d=function(e,t,r,n,s,a,o,l,i,u){var p=o[0],c=o[1];void 0===u&&(u=5);for(var d=r.map(function(e){return new Uint8Array(n*s).fill(0)}),f=l.top,h=l.left,m=N([n,s],[p,c],l),g=m[0],x=m[1],v=R([p,c],a)[0],y=0;y=0&&(d[k][b]=1)}}return d}(v,y,l,n,s,a,[m,g],i,p),f.label=5;case 5:return[2,d.map(function(e,t){return{data:e,pose:l[t],width:s,height:n}})]}})})}(h,m,w,n,s,this.baseModel.outputStride,a,u,t.scoreThreshold,t.refineSteps,t.minKeypointScore,t.maxDetections)];case 2:return I=C.sent(),i.dispose(),h.dispose(),m.dispose(),g.dispose(),x.dispose(),v.dispose(),y.dispose(),[2,I]}})})},e.prototype.segmentPersonPartsActivation=function(e,t,r){var n=this;void 0===r&&(r=.5);var s=J(e),a=s[0],l=s[1],i=ee(t,this.baseModel.outputStride,[a,l]),u=er(e,i),p=u.resized,c=u.padding,d=(0,o.tidy)(function(){var e,t,s,i,u,d=n.predictForPersonSegmentationAndPart(p),f=d.segmentLogits,h=d.partHeatmapLogits,m=d.heatmapScores,g=d.offsets,x=d.displacementFwd,v=d.displacementBwd,y=p.shape,_=y[0],T=y[1],w=et(f,[a,l],[_,T],[[c.top,c.bottom],[c.left,c.right]],!0),I=et(h,[a,l],[_,T],[[c.top,c.bottom],[c.left,c.right]],!0);return{partSegmentation:(e=k((0,o.squeeze)(w),r),s=(t=I.shape)[0],i=t[1],u=t[2],(0,o.tidy)(function(){var t=b(I),r=(0,o.expandDims)((0,o.range)(0,u,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:m,offsets:g,displacementFwd:x,displacementBwd:v}}),f=d.partSegmentation,h=d.heatmapScores,m=d.offsets,g=d.displacementFwd,x=d.displacementBwd;return p.dispose(),{partSegmentation:f,heatmapScores:h,offsets:m,displacementFwd:g,displacementBwd:x,padding:c,internalResolutionHeightAndWidth:i}},e.prototype.segmentPersonParts=function(e,t){return void 0===t&&(t=ep),d(this,void 0,void 0,function(){var r,n,s,a,o,l,i,u,p,d,h,m,g,x,v,y;return f(this,function(f){switch(f.label){case 0:return ed(t=c(c({},ep),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,u=r.internalResolutionHeightAndWidth,d=(p=n.shape)[0],h=p[1],[4,n.data()];case 1:return m=f.sent(),n.dispose(),[4,en([s,a,o,l])];case 2:return x=(g=f.sent())[0],v=g[1],y=es(y=z(x,v,g[2],g[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[d,h],u,i,!1),s.dispose(),a.dispose(),o.dispose(),l.dispose(),[2,{height:d,width:h,data:m,allPoses:y}]}})})},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,u,p,h,m,g,x,v,y,_,T,w,I,j,C,S=this;return f(this,function(E){switch(E.label){case 0:return ef(t=c(c({},ec),t)),n=(r=J(e))[0],s=r[1],i=(l=er(e,a=ee(t.internalResolution,this.baseModel.outputStride,[n,s]))).resized,u=l.padding,h=(p=(0,o.tidy)(function(){var e,r,l,p,c=S.predictForMultiPersonInstanceSegmentationAndPart(i),d=c.segmentLogits,f=c.longOffsets,h=c.heatmapScores,m=c.offsets,g=c.displacementFwd,x=c.displacementBwd,v=c.partHeatmaps,y=et(d,[n,s],a,[[u.top,u.bottom],[u.left,u.right]],!0),_=et(v,[n,s],a,[[u.top,u.bottom],[u.left,u.right]],!0);return{segmentation:k((0,o.squeeze)(y),t.segmentationThreshold),longOffsets:f,heatmapScoresRaw:h,offsetsRaw:m,displacementFwdRaw:g,displacementBwdRaw:x,partSegmentation:(r=(e=_.shape)[0],l=e[1],p=e[2],(0,o.tidy)(function(){var e=b(_),t=(0,o.expandDims)((0,o.range)(0,p,1,"int32"),1),n=(0,o.cast)((0,o.matMul)(e,t),"int32");return(0,o.reshape)(n,[r,l])}))}})).segmentation,m=p.longOffsets,g=p.heatmapScoresRaw,x=p.offsetsRaw,v=p.displacementFwdRaw,y=p.displacementBwdRaw,_=p.partSegmentation,[4,en([g,x,v,y])];case 1:return w=(T=E.sent())[0],I=T[1],j=es(j=z(w,I,T[2],T[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[n,s],a,u,!1),[4,function(e,t,r,n,s,a,l,i,u,p,c,h,m){var g=i[0],x=i[1];return void 0===p&&(p=.2),void 0===c&&(c=8),void 0===h&&(h=.3),void 0===m&&(m=10),d(this,void 0,void 0,function(){var i,d,v,y,_,b;return f(this,function(f){switch(f.label){case 0:return i=n.filter(function(e){return e.score>=p}),P()?[4,Promise.all((v=(0,o.tidy)(function(){var n=D(e,t,i,s,a,l,[g,x],u,c,h,m),p=(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)(p,(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(),v.forEach(function(e){return e.dispose()}),[3,6];case 2:return[4,e.data()];case 3:return y=f.sent(),[4,t.data()];case 4:return _=f.sent(),[4,r.data()];case 5:b=f.sent(),d=function(e,t,r,n,s,a,o,l,i,u,p){var c=l[0],d=l[1];void 0===p&&(p=5);for(var f=n.map(function(e){return new Int32Array(s*a).fill(-1)}),h=i.top,m=i.left,g=N([s,a],[c,d],i),x=g[0],v=g[1],y=R([c,d],o)[0],_=0;_=0&&(f[T][k]=r[k])}}return f}(y,_,b,i,s,a,l,[g,x],u,c),f.label=6;case 6:return[2,d.map(function(e,t){return{pose:i[t],data:e,height:s,width:a}})]}})})}(h,m,_,j,n,s,this.baseModel.outputStride,a,u,t.scoreThreshold,t.refineSteps,t.minKeypointScore,t.maxDetections)];case 2:return C=E.sent(),i.dispose(),h.dispose(),m.dispose(),g.dispose(),x.dispose(),v.dispose(),y.dispose(),_.dispose(),[2,C]}})})},e.prototype.dispose=function(){this.baseModel.dispose()},e}(),em=["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,m(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(v(e),255!==e)throw Error("Foreground id must be 255 but got "+e);return"person"}function ev(e){if(v(e),e>=em.length)throw Error("Invalid body part value "+e);return em[e]}var ey=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]=em.length,s[4*t+3]=0):(s[4*t]=e,s[4*t+3]=255)}),{maskValueToLabel:ev,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}(),e_={runtime:"mediapipe",modelType:"general"},eb=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 ek(e){return v(e),"person"}var eT=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:ek,mask:new eb(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 ew(e){return e instanceof o.Tensor?{height:e.shape[0],width:e.shape[1]}:{height:e.height,width:e.width}}function eI(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 ej={runtime:"tfjs",modelType:"general",modelUrl:"https://tfhub.dev/mediapipe/tfjs-model/selfie_segmentation/general/1"},eC={flipHorizontal:!1},eN={outputTensorSize:{width:256,height:256},keepAspectRatio:!1,borderMode:"zero",outputTensorFloatRange:[0,1]},eS={outputTensorSize:{width:256,height:144},keepAspectRatio:!1,borderMode:"zero",outputTensorFloatRange:[0,1]},eE={activation:"none"},eA=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,m(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 eF(e){return v(e),"person"}var eR,eD=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({},eC);var t=c({},e);return null==t.flipHorizontal&&(t.flipHorizontal=eC.flipHorizontal),t}(t),null==e?(this.reset(),[2,[]]):[2,[{maskValueToLabel:eF,mask:new eA((0,o.tidy)(function(){var t,n,s,a,l,i,u,p,c,d,f,h,m,g,x,v,y,_,b,k,T,w,I=(x=(t="general"===r.modelType?eN:eS).outputTensorSize,v=t.keepAspectRatio,y=t.borderMode,_=t.outputTensorFloatRange,T=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;eI(t,"targetSize"),eI(e,"roi");var a,o,l=n/s,i=e.height/e.width,u=0,p=0;return l>i?(a=e.width,o=e.width*l,p=(1-i/l)/2):(a=e.height/l,o=e.height,u=(1-l/i)/2),e.width=a,e.height=o,{top:p,left:u,right:u,bottom:p}}((n=b=ew(e),k={xCenter:.5*n.width,yCenter:.5*n.height,width:n.width,height:n.height,rotation:0}),x,v),s=b.width,a=b.height,l=k.width,i=k.height,u=1,p=Math.cos(k.rotation),c=Math.sin(k.rotation),d=k.xCenter,f=k.yCenter,h=1/s,m=1/a,(g=Array(16))[0]=l*p*u*h,g[1]=-i*c*h,g[2]=0,g[3]=(-.5*l*p*u+.5*i*c+d)*h,g[4]=l*c*u*m,g[5]=i*p*m,g[6]=0,g[7]=(-.5*i*p-.5*l*c*u+f)*m,g[8]=0,g[9]=0,g[10]=l*h,g[11]=0,g[12]=0,g[13]=0,g[14]=0,g[15]=1,w=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)((eI(x,"inputResolution"),[1/x.width*w[0][0]*b.width,1/x.height*w[0][1]*b.width,w[0][3]*b.width,1/x.width*w[1][0]*b.height,1/x.height*w[1][1]*b.height,w[1][3]*b.height,0,0]),[1,8]),s=o.image.transform((0,o.expandDims)((0,o.cast)(r,"float32")),n,"bilinear","zero"===y?"constant":"nearest",0,[x.height,x.width]);return null!=_?(t=function(e,t){!1;var r=(t-e)/255;return{scale:r,offset:e-0*r}}(_[0],_[1]),(0,o.tidy)(function(){return(0,o.add)((0,o.mul)(s,t.scale),t.offset)})):s}),padding:T,transformationMatrix:w}).imageTensor,j=(0,o.slice)(r.model.predict(I),[0,0,0,1],-1),C=ew(e),N=(0,o.tidy)(function(){var e=(0,o.squeeze)(j,[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=C?o.image.resizeBilinear(r,[C.height,C.width]):r;return(0,o.squeeze)(n,[2])}throw Error("Unsupported number of tensor channels "+t)}),S=(0,o.expandDims)(N,2),E=(0,o.pad)(S,[[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 eP(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({},ej);var t=c({},e);if(t.runtime="tfjs",null==t.modelType&&(t.modelType=ej.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 eD(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 eT(function(e){if(null==e)return c({},e_);var t=c({},e);return t.runtime="mediapipe",null==t.modelType&&(t.modelType=e_.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>eu.indexOf(e.quantBytes))throw Error("Invalid quantBytes "+e.quantBytes+". Should be one of "+eu+" 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