/*! * 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,a,s,o,i){var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},u="function"==typeof c[n]&&c[n],l=u.i||{},p=u.cache||{},f="undefined"!=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);return!1===t?{}: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;h0&&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;r250&&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("ready",m),t.on("destroy",g),{name:"artplayerPluginDanmukuMask",start:m,stop:g}}}e("@tensorflow/tfjs-backend-webgl"),e("@tensorflow/tfjs-backend-cpu"),"undefined"!=typeof window&&(window.artplayerPluginDanmukuMask=u)},{"@swc/helpers/cjs/_async_to_generator.cjs":"cZn0e","@swc/helpers/cjs/_ts_generator.cjs":"eltGh","@tensorflow-models/body-segmentation":"8yK79","@tensorflow/tfjs-core":"aOH7b","@tensorflow/tfjs-backend-webgl":"8uAp9","@tensorflow/tfjs-backend-cpu":"5BQ3i","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],cZn0e:[function(e,t,r,n){"use strict";function a(e,t,r,n,a,s,o){try{var i=e[s](o),c=i.value}catch(e){r(e);return}i.done?t(c):Promise.resolve(c).then(n,a)}r._=function(e){return function(){var t=this,r=arguments;return new Promise(function(n,s){var o=e.apply(t,r);function i(e){a(o,n,s,i,c,"next",e)}function c(e){a(o,n,s,i,c,"throw",e)}i(void 0)})}}},{}],eltGh:[function(e,t,r,n){"use strict";r._=e("eb260df52bffddd").__generator},{eb260df52bffddd:"6yrAu"}],"6yrAu":[function(e,t,r,n){var a=e("@parcel/transformer-js/src/esmodule-helpers.js");a.defineInteropFlag(r),a.export(r,"__extends",function(){return i}),a.export(r,"__assign",function(){return c}),a.export(r,"__rest",function(){return u}),a.export(r,"__decorate",function(){return l}),a.export(r,"__param",function(){return p}),a.export(r,"__esDecorate",function(){return f}),a.export(r,"__runInitializers",function(){return d}),a.export(r,"__propKey",function(){return h}),a.export(r,"__setFunctionName",function(){return m}),a.export(r,"__metadata",function(){return g}),a.export(r,"__awaiter",function(){return v}),a.export(r,"__generator",function(){return _}),a.export(r,"__createBinding",function(){return x}),a.export(r,"__exportStar",function(){return y}),a.export(r,"__values",function(){return b}),a.export(r,"__read",function(){return k}),a.export(r,"__spread",function(){return j}),a.export(r,"__spreadArrays",function(){return w}),a.export(r,"__spreadArray",function(){return I}),a.export(r,"__await",function(){return T}),a.export(r,"__asyncGenerator",function(){return S}),a.export(r,"__asyncDelegator",function(){return N}),a.export(r,"__asyncValues",function(){return M}),a.export(r,"__makeTemplateObject",function(){return C}),a.export(r,"__importStar",function(){return A}),a.export(r,"__importDefault",function(){return R}),a.export(r,"__classPrivateFieldGet",function(){return P}),a.export(r,"__classPrivateFieldSet",function(){return O}),a.export(r,"__classPrivateFieldIn",function(){return D}),a.export(r,"__addDisposableResource",function(){return B}),a.export(r,"__disposeResources",function(){return G}),a.export(r,"__rewriteRelativeImportExtension",function(){return L});var s=e("@swc/helpers/cjs/_type_of.cjs"),o=function(e,t){return(o=Object.setPrototypeOf||({__proto__:[]})instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};function i(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}o(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;rt.indexOf(n)&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var a=0,n=Object.getOwnPropertySymbols(e);at.indexOf(n[a])&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]]);return r}function l(e,t,r,n){var a,o=arguments.length,i=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if(("undefined"==typeof Reflect?"undefined":(0,s._)(Reflect))==="object"&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(a=e[c])&&(i=(o<3?a(i):o>3?a(t,r,i):a(t,r))||i);return o>3&&i&&Object.defineProperty(t,r,i),i}function p(e,t){return function(r,n){t(r,n,e)}}function f(e,t,r,n,a,o){function i(e){if(void 0!==e&&"function"!=typeof e)throw TypeError("Function expected");return e}for(var c,u=n.kind,l="getter"===u?"get":"setter"===u?"set":"value",p=!t&&e?n.static?e:e.prototype:null,f=t||(p?Object.getOwnPropertyDescriptor(p,n.name):{}),d=!1,h=r.length-1;h>=0;h--){var m={};for(var g in n)m[g]="access"===g?{}:n[g];for(var g in n.access)m.access[g]=n.access[g];m.addInitializer=function(e){if(d)throw TypeError("Cannot add initializers after decoration has completed");o.push(i(e||null))};var v=(0,r[h])("accessor"===u?{get:f.get,set:f.set}:f[l],m);if("accessor"===u){if(void 0===v)continue;if(null===v||(void 0===v?"undefined":(0,s._)(v))!=="object")throw TypeError("Object expected");(c=i(v.get))&&(f.get=c),(c=i(v.set))&&(f.set=c),(c=i(v.init))&&a.unshift(c)}else(c=i(v))&&("field"===u?a.unshift(c):f[l]=c)}p&&Object.defineProperty(p,n.name,f),d=!0}function d(e,t,r){for(var n=arguments.length>2,a=0;a0&&a[a.length-1])&&(6===u[0]||2===u[0])){s=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function k(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,a,s=r.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(n=s.next()).done;)o.push(n.value)}catch(e){a={error:e}}finally{try{n&&!n.done&&(r=s.return)&&r.call(s)}finally{if(a)throw a.error}}return o}function j(){for(var e=[],t=0;t1||i(e,t)})},t&&(n[e]=t(n[e])))}function i(e,t){try{var r;(r=a[e](t)).value instanceof T?Promise.resolve(r.value.v).then(c,u):l(s[0][2],r)}catch(e){l(s[0][3],e)}}function c(e){i("next",e)}function u(e){i("throw",e)}function l(e,t){e(t),s.shift(),s.length&&i(s[0][0],s[0][1])}}function N(e){var t,r;return t={},n("next"),n("throw",function(e){throw e}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(n,a){t[n]=e[n]?function(t){return(r=!r)?{value:T(e[n](t)),done:!1}:a?a(t):t}:a}}function M(e){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=b(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise(function(n,a){var s,o,i;s=n,o=a,i=(t=e[r](t)).done,Promise.resolve(t.value).then(function(e){s({value:e,done:i})},o)})}}}function C(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var E=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t},F=function(e){return(F=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(e)};function A(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=F(e),n=0;n0&&a[a.length-1])&&(6===c[0]||2===c[0])){o=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[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 x=[[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 y(e){if(_(e),er&&(a+=1,n+=Math.pow(e[s].x-t.keypoints[s].position.x,2)+Math.pow(e[s].y-t.keypoints[s].position.y,2));return 0===a?n=1/0:n/=a,n}(g,r[k]);j"+l+") {\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,y,A])}function P(){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(ts?s:a),x:(o=Math.round(e.x/t),i=n-1,o<0?0:o>i?i:o)}}function q(e,t,r,n,a,s,o,i){void 0===i&&(i=2);for(var c,u,l=n.shape,p=l[0],f=l[1],d=(c=L(t.position,s,p,f),u=o.shape[2]/2,{y:o.get(c.y,c.x,e),x:o.get(c.y,c.x,u+e)}),h=E(t.position,d),m=0;mt){u=!1;break}if(!u)break}return u}(l,p,c,u,1,r)&&i.enqueue({score:p,part:{heatmapY:c,heatmapX:u,id:l}})}return i}(o,0,e),l=i*i;c.length=0;--f){var d=V[f],h=G[f];c[d]&&!c[h]&&(c[h]=q(f,c[d],h,t,r,n,s))}for(f=0;f=.1,function(){return"inputResolution must be a string or number between 0.1 and 2, but was "+e}),e}(e);return[J(n*s,t),J(a*s,t)]}function et(e,t,r,n,a){var s=t[0],i=t[1],c=r[0],u=r[1],l=n[0],p=l[0],f=l[1],d=n[1],h=d[0],m=d[1];return void 0===a&&(a=!1),(0,o.tidy)(function(){var t,r,n,l,d,g,v,_,x,y,b,k=o.image.resizeBilinear(e,[c,u],!0);return a&&(k=(0,o.sigmoid)(k)),t=k,r=[s,i],n=[[p,f],[h,m]],l=r[0],d=r[1],v=(g=n[0])[0],_=g[1],y=(x=n[1])[0],b=x[1],(0,o.tidy)(function(){var e=(0,o.expandDims)(t);return(0,o.squeeze)(o.image.cropAndResize(e,[[v/(l+v+_-1),y/(d+y+b-1),(v+l-1)/(l+v+_-1),(y+d-1)/(d+y+b-1)]],[0],[l,d]),[0])})})}function er(e,t){var r=t[0],n=t[1],a=Q(e),s=a[0],i=a[1],c=n/r,u=0,l=0,p=0,f=0;return i/s1)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(a<=0)throw Error("Invalid nmsRadius "+a+".")}function ed(e){var t=e.segmentationThreshold,r=e.maxDetections,n=e.scoreThreshold,a=e.nmsRadius,s=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(a<=0)throw Error("Invalid nmsRadius "+a+".");if(s<0||s>1)throw Error("Invalid minKeypointScore "+s+".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 a=Q(e),s=a[0],i=a[1],c=ee(t,this.baseModel.outputStride,[s,i]),u=er(e,c),l=u.resized,p=u.padding,f=(0,o.tidy)(function(){var e=n.predictForPersonSegmentation(l),t=e.segmentLogits,a=e.heatmapScores,c=e.offsets,u=e.displacementFwd,f=e.displacementBwd,d=l.shape,h=et(t,[s,i],[d[0],d[1]],[[p.top,p.bottom],[p.left,p.right]],!0);return{segmentation:k((0,o.squeeze)(h),r),heatmapScores:a,offsets:c,displacementFwd:u,displacementBwd:f}}),d=f.segmentation,h=f.heatmapScores,m=f.offsets,g=f.displacementFwd,v=f.displacementBwd;return l.dispose(),{segmentation:d,heatmapScores:h,offsets:m,displacementFwd:g,displacementBwd:v,padding:p,internalResolutionHeightAndWidth:c}},e.prototype.segmentPerson=function(e,t){return void 0===t&&(t=el),f(this,void 0,void 0,function(){var r,n,a,s,o,i,c,u,l,f,h,m,g,v,_,x;return d(this,function(d){switch(d.label){case 0:return ef(t=p(p({},el),t)),n=(r=this.segmentPersonActivation(e,t.internalResolution,t.segmentationThreshold)).segmentation,a=r.heatmapScores,s=r.offsets,o=r.displacementFwd,i=r.displacementBwd,c=r.padding,u=r.internalResolutionHeightAndWidth,f=(l=n.shape)[0],h=l[1],[4,n.data()];case 1:return m=d.sent(),n.dispose(),[4,en([a,s,o,i])];case 2:return v=(g=d.sent())[0],_=g[1],x=ea(x=U(v,_,g[2],g[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[f,h],u,c,!1),a.dispose(),s.dispose(),o.dispose(),i.dispose(),[2,{height:f,width:h,data:m,allPoses:x}]}})})},e.prototype.segmentMultiPerson=function(e,t){return void 0===t&&(t=ep),f(this,void 0,void 0,function(){var r,n,a,s,i,c,u,l,h,m,g,v,_,x,y,b,j,w,I,T=this;return d(this,function(S){switch(S.label){case 0:return ed(t=p(p({},ep),t)),n=(r=Q(e))[0],a=r[1],c=(i=er(e,s=ee(t.internalResolution,this.baseModel.outputStride,[n,a]))).resized,u=i.padding,h=(l=(0,o.tidy)(function(){var e=T.predictForMultiPersonInstanceSegmentationAndPart(c),r=e.segmentLogits,i=e.longOffsets,l=e.heatmapScores,p=e.offsets,f=e.displacementFwd,d=e.displacementBwd,h=et(r,[n,a],s,[[u.top,u.bottom],[u.left,u.right]],!0);return{segmentation:k((0,o.squeeze)(h),t.segmentationThreshold),longOffsets:i,heatmapScoresRaw:l,offsetsRaw:p,displacementFwdRaw:f,displacementBwdRaw:d}})).segmentation,m=l.longOffsets,g=l.heatmapScoresRaw,v=l.offsetsRaw,_=l.displacementFwdRaw,x=l.displacementBwdRaw,[4,en([g,v,_,x])];case 1:return b=(y=S.sent())[0],j=y[1],w=ea(w=U(b,j,y[2],y[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[n,a],s,u,!1),[4,function(e,t,r,n,a,s,i,c,u,l,p,h){var m=i[0],g=i[1];return void 0===u&&(u=.2),void 0===l&&(l=8),void 0===p&&(p=.3),void 0===h&&(h=10),f(this,void 0,void 0,function(){var i,f,v,_,x;return d(this,function(d){switch(d.label){case 0:return i=r.filter(function(e){return e.score>=u}),P()?[4,Promise.all((v=(0,o.tidy)(function(){var r=R(e,t,i,n,a,s,[m,g],c,l,p,h),u=(0,o.engine)().makeTensorFromDataId(r.dataId,r.shape,r.dtype);return i.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 f=d.sent(),v.forEach(function(e){return e.dispose()}),[3,5];case 2:return[4,e.data()];case 3:return _=d.sent(),[4,t.data()];case 4:x=d.sent(),f=function(e,t,r,n,a,s,o,i,c,u){var l=o[0],p=o[1];void 0===u&&(u=5);for(var f=r.map(function(e){return new Uint8Array(n*a).fill(0)}),d=i.top,h=i.left,m=N([n,a],[l,p],i),g=m[0],v=m[1],_=A([l,p],s)[0],x=0;x=0&&(f[k][b]=1)}}return f}(_,x,i,n,a,s,[m,g],c,l),d.label=5;case 5:return[2,f.map(function(e,t){return{data:e,pose:i[t],width:a,height:n}})]}})})}(h,m,w,n,a,this.baseModel.outputStride,s,u,t.scoreThreshold,t.refineSteps,t.minKeypointScore,t.maxDetections)];case 2:return I=S.sent(),c.dispose(),h.dispose(),m.dispose(),g.dispose(),v.dispose(),_.dispose(),x.dispose(),[2,I]}})})},e.prototype.segmentPersonPartsActivation=function(e,t,r){var n=this;void 0===r&&(r=.5);var a=Q(e),s=a[0],i=a[1],c=ee(t,this.baseModel.outputStride,[s,i]),u=er(e,c),l=u.resized,p=u.padding,f=(0,o.tidy)(function(){var e,t,a,c,u,f=n.predictForPersonSegmentationAndPart(l),d=f.segmentLogits,h=f.partHeatmapLogits,m=f.heatmapScores,g=f.offsets,v=f.displacementFwd,_=f.displacementBwd,x=l.shape,y=x[0],j=x[1],w=et(d,[s,i],[y,j],[[p.top,p.bottom],[p.left,p.right]],!0),I=et(h,[s,i],[y,j],[[p.top,p.bottom],[p.left,p.right]],!0);return{partSegmentation:(e=k((0,o.squeeze)(w),r),a=(t=I.shape)[0],c=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"),s=(0,o.reshape)(n,[a,c]),i=(0,o.add)(s,(0,o.scalar)(1,"int32"));return(0,o.sub)((0,o.mul)(i,e),(0,o.scalar)(1,"int32"))})),heatmapScores:m,offsets:g,displacementFwd:v,displacementBwd:_}}),d=f.partSegmentation,h=f.heatmapScores,m=f.offsets,g=f.displacementFwd,v=f.displacementBwd;return l.dispose(),{partSegmentation:d,heatmapScores:h,offsets:m,displacementFwd:g,displacementBwd:v,padding:p,internalResolutionHeightAndWidth:c}},e.prototype.segmentPersonParts=function(e,t){return void 0===t&&(t=el),f(this,void 0,void 0,function(){var r,n,a,s,o,i,c,u,l,f,h,m,g,v,_,x;return d(this,function(d){switch(d.label){case 0:return ef(t=p(p({},el),t)),n=(r=this.segmentPersonPartsActivation(e,t.internalResolution,t.segmentationThreshold)).partSegmentation,a=r.heatmapScores,s=r.offsets,o=r.displacementFwd,i=r.displacementBwd,c=r.padding,u=r.internalResolutionHeightAndWidth,f=(l=n.shape)[0],h=l[1],[4,n.data()];case 1:return m=d.sent(),n.dispose(),[4,en([a,s,o,i])];case 2:return v=(g=d.sent())[0],_=g[1],x=ea(x=U(v,_,g[2],g[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[f,h],u,c,!1),a.dispose(),s.dispose(),o.dispose(),i.dispose(),[2,{height:f,width:h,data:m,allPoses:x}]}})})},e.prototype.segmentMultiPersonParts=function(e,t){return void 0===t&&(t=ep),f(this,void 0,void 0,function(){var r,n,a,s,i,c,u,l,h,m,g,v,_,x,y,j,w,I,T,S,M=this;return d(this,function(C){switch(C.label){case 0:return ed(t=p(p({},ep),t)),n=(r=Q(e))[0],a=r[1],c=(i=er(e,s=ee(t.internalResolution,this.baseModel.outputStride,[n,a]))).resized,u=i.padding,h=(l=(0,o.tidy)(function(){var e,r,i,l,p=M.predictForMultiPersonInstanceSegmentationAndPart(c),f=p.segmentLogits,d=p.longOffsets,h=p.heatmapScores,m=p.offsets,g=p.displacementFwd,v=p.displacementBwd,_=p.partHeatmaps,x=et(f,[n,a],s,[[u.top,u.bottom],[u.left,u.right]],!0),y=et(_,[n,a],s,[[u.top,u.bottom],[u.left,u.right]],!0);return{segmentation:k((0,o.squeeze)(x),t.segmentationThreshold),longOffsets:d,heatmapScoresRaw:h,offsetsRaw:m,displacementFwdRaw:g,displacementBwdRaw:v,partSegmentation:(r=(e=y.shape)[0],i=e[1],l=e[2],(0,o.tidy)(function(){var e=b(y),t=(0,o.expandDims)((0,o.range)(0,l,1,"int32"),1),n=(0,o.cast)((0,o.matMul)(e,t),"int32");return(0,o.reshape)(n,[r,i])}))}})).segmentation,m=l.longOffsets,g=l.heatmapScoresRaw,v=l.offsetsRaw,_=l.displacementFwdRaw,x=l.displacementBwdRaw,y=l.partSegmentation,[4,en([g,v,_,x])];case 1:return w=(j=C.sent())[0],I=j[1],T=ea(T=U(w,I,j[2],j[3],this.baseModel.outputStride,t.maxDetections,t.scoreThreshold,t.nmsRadius),[n,a],s,u,!1),[4,function(e,t,r,n,a,s,i,c,u,l,p,h,m){var g=c[0],v=c[1];return void 0===l&&(l=.2),void 0===p&&(p=8),void 0===h&&(h=.3),void 0===m&&(m=10),f(this,void 0,void 0,function(){var c,f,_,x,y,b;return d(this,function(d){switch(d.label){case 0:return c=n.filter(function(e){return e.score>=l}),P()?[4,Promise.all((_=(0,o.tidy)(function(){var n=R(e,t,c,a,s,i,[g,v],u,p,h,m),l=(0,o.engine)().makeTensorFromDataId(n.dataId,n.shape,n.dtype);return c.map(function(e,t){return(0,o.tidy)(function(){return(0,o.sub)((0,o.mul)((0,o.cast)((0,o.equal)(l,(0,o.scalar)(t)),"int32"),(0,o.add)(r,1)),1)})})})).map(function(e){return e.data()}))]:[3,2];case 1:return f=d.sent(),_.forEach(function(e){return e.dispose()}),[3,6];case 2:return[4,e.data()];case 3:return x=d.sent(),[4,t.data()];case 4:return y=d.sent(),[4,r.data()];case 5:b=d.sent(),f=function(e,t,r,n,a,s,o,i,c,u,l){var p=i[0],f=i[1];void 0===l&&(l=5);for(var d=n.map(function(e){return new Int32Array(a*s).fill(-1)}),h=c.top,m=c.left,g=N([a,s],[p,f],c),v=g[0],_=g[1],x=A([p,f],o)[0],y=0;y=0&&(d[j][k]=r[k])}}return d}(x,y,b,c,a,s,i,[g,v],u,p),d.label=6;case 6:return[2,f.map(function(e,t){return{pose:c[t],data:e,height:a,width:s}})]}})})}(h,m,y,T,n,a,this.baseModel.outputStride,s,u,t.scoreThreshold,t.refineSteps,t.minKeypointScore,t.maxDetections)];case 2:return S=C.sent(),c.dispose(),h.dispose(),m.dispose(),g.dispose(),v.dispose(),_.dispose(),x.dispose(),y.dispose(),[2,S]}})})},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 f(this,void 0,void 0,function(){return d(this,function(e){return[2,m(this.mask)]})})},e.prototype.toImageData=function(){return f(this,void 0,void 0,function(){return d(this,function(e){return[2,this.mask]})})},e.prototype.toTensor=function(){return f(this,void 0,void 0,function(){return d(this,function(e){return[2,v(this.mask)]})})},e.prototype.getUnderlyingType=function(){return"imagedata"},e}();function ev(e){if(_(e),255!==e)throw Error("Foreground id must be 255 but got "+e);return"person"}function e_(e){if(_(e),e>=em.length)throw Error("Invalid body part value "+e);return em[e]}var ex=function(){function e(e){this.bodyPixModel=e}return e.prototype.segmentPeople=function(e,t){return f(this,void 0,void 0,function(){var r,n,a,s;return d(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 a=o.sent(),[3,4];case 2:return[4,this.bodyPixModel.segmentPersonParts(e,t)];case 3:a=[o.sent()],o.label=4;case 4:return n=a.map(function(e){var t=e.data,r=e.width,n=e.height,a=new Uint8ClampedArray(r*n*4).fill(0);return t.forEach(function(e,t){-1===e?(a[4*t]=em.length,a[4*t+3]=0):(a[4*t]=e,a[4*t+3]=255)}),{maskValueToLabel:e_,mask:new eg(new ImageData(a,r,n))}}),[3,10];case 5:return t.multiSegmentation?[4,this.bodyPixModel.segmentMultiPerson(e,t)]:[3,7];case 6:return s=o.sent(),[3,9];case 7:return[4,this.bodyPixModel.segmentPerson(e,t)];case 8:s=[o.sent()],o.label=9;case 9:n=s.map(function(e){var t=e.data,r=e.width,n=e.height,a=new Uint8ClampedArray(r*n*4).fill(0);return t.forEach(function(e,t){0===e?(a[4*t]=0,a[4*t+3]=0):(a[4*t]=255,a[4*t+3]=255)}),{maskValueToLabel:ev,mask:new eg(new ImageData(a,r,n))}}),o.label=10;case 10:return[2,n]}})})},e.prototype.dispose=function(){this.bodyPixModel.dispose()},e.prototype.reset=function(){},e}(),ey={runtime:"mediapipe",modelType:"general"},eb=function(){function e(e){this.mask=e}return e.prototype.toCanvasImageSource=function(){return f(this,void 0,void 0,function(){return d(this,function(e){return[2,this.mask]})})},e.prototype.toImageData=function(){return f(this,void 0,void 0,function(){return d(this,function(e){return[2,g(this.mask)]})})},e.prototype.toTensor=function(){return f(this,void 0,void 0,function(){return d(this,function(e){return[2,v(this.mask)]})})},e.prototype.getUnderlyingType=function(){return"canvasimagesource"},e}();function ek(e){return _(e),"person"}var ej=function(){function e(e){var t,r,n=this;this.selfieMode=!1,t=+(this.selfieSegmentationSolution=new(0,c.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 f(this,void 0,void 0,function(){var r,n;return d(this,function(a){switch(a.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,a.sent(),e.shape[1],e.shape[0]])),[3,3];case 2:r=e,a.label=3;case 3:return e=r,[4,this.selfieSegmentationSolution.send({image:e})];case 4:return a.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 eT={runtime:"tfjs",modelType:"general",modelUrl:"https://tfhub.dev/mediapipe/tfjs-model/selfie_segmentation/general/1"},eS={flipHorizontal:!1},eN={outputTensorSize:{width:256,height:256},keepAspectRatio:!1,borderMode:"zero",outputTensorFloatRange:[0,1]},eM={outputTensorSize:{width:256,height:144},keepAspectRatio:!1,borderMode:"zero",outputTensorFloatRange:[0,1]},eC={activation:"none"},eE=function(){function e(e){this.mask=e}return e.prototype.toCanvasImageSource=function(){return f(this,void 0,void 0,function(){return d(this,function(e){return[2,m(this.mask)]})})},e.prototype.toImageData=function(){return f(this,void 0,void 0,function(){return d(this,function(e){return[2,g(this.mask)]})})},e.prototype.toTensor=function(){return f(this,void 0,void 0,function(){return d(this,function(e){return[2,this.mask]})})},e.prototype.getUnderlyingType=function(){return"tensor"},e}();function eF(e){return _(e),"person"}var eA,eR=function(){function e(e,t){this.modelType=e,this.model=t}return e.prototype.segmentPeople=function(e,t){return f(this,void 0,void 0,function(){var r=this;return d(this,function(n){return t=function(e){if(null==e)return p({},eS);var t=p({},e);return null==t.flipHorizontal&&(t.flipHorizontal=eS.flipHorizontal),t}(t),null==e?(this.reset(),[2,[]]):[2,[{maskValueToLabel:eF,mask:new eE((0,o.tidy)(function(){var t,n,a,s,i,c,u,l,p,f,d,h,m,g,v,_,x,y,b,k,j,w,I=(v=(t="general"===r.modelType?eN:eM).outputTensorSize,_=t.keepAspectRatio,x=t.borderMode,y=t.outputTensorFloatRange,j=function(e,t,r){if(void 0===r&&(r=!1),!r)return{top:0,left:0,right:0,bottom:0};var n=t.height,a=t.width;eI(t,"targetSize"),eI(e,"roi");var s,o,i=n/a,c=e.height/e.width,u=0,l=0;return i>c?(s=e.width,o=e.width*i,l=(1-c/i)/2):(s=e.height/i,o=e.height,u=(1-i/c)/2),e.width=s,e.height=o,{top:l,left:u,right:u,bottom:l}}((n=b=ew(e),k={xCenter:.5*n.width,yCenter:.5*n.height,width:n.width,height:n.height,rotation:0}),v,_),a=b.width,s=b.height,i=k.width,c=k.height,u=1,l=Math.cos(k.rotation),p=Math.sin(k.rotation),f=k.xCenter,d=k.yCenter,h=1/a,m=1/s,(g=Array(16))[0]=i*l*u*h,g[1]=-c*p*h,g[2]=0,g[3]=(-.5*i*l*u+.5*c*p+f)*h,g[4]=i*p*u*m,g[5]=c*l*m,g[6]=0,g[7]=(-.5*c*l-.5*i*p*u+d)*m,g[8]=0,g[9]=0,g[10]=i*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(v,"inputResolution"),[1/v.width*w[0][0]*b.width,1/v.height*w[0][1]*b.width,w[0][3]*b.width,1/v.width*w[1][0]*b.height,1/v.height*w[1][1]*b.height,w[1][3]*b.height,0,0]),[1,8]),a=o.image.transform((0,o.expandDims)((0,o.cast)(r,"float32")),n,"bilinear","zero"===x?"constant":"nearest",0,[v.height,v.width]);return null!=y?(t=function(e,t,r,n){!1;var a=(n-r)/255;return{scale:a,offset:r-e*a}}(0,0,y[0],y[1]),(0,o.tidy)(function(){return(0,o.add)((0,o.mul)(a,t.scale),t.offset)})):a}),padding:j,transformationMatrix:w}).imageTensor,T=(0,o.slice)(r.model.predict(I),[0,0,0,1],-1),S=ew(e),N=(0,o.tidy)(function(){var e=(0,o.squeeze)(T,[0]),t=e.shape[2];if(1===t){var r=e;switch(eC.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 ("+eC.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)}),M=(0,o.expandDims)(N,2),C=(0,o.pad)(M,[[0,0],[0,0],[0,1]]);return(0,o.mirrorPad)(C,[[0,0],[0,0],[0,2]],"symmetric")}))}]]})})},e.prototype.dispose=function(){this.model.dispose()},e.prototype.reset=function(){},e}();function eP(e,t){return f(this,void 0,void 0,function(){var r,n;return d(this,function(a){switch(e){case eA.MediaPipeSelfieSegmentation:if(r=void 0,null!=(n=t)){if("tfjs"===n.runtime)return[2,function(e){return f(this,void 0,void 0,function(){var t,r,n;return d(this,function(a){switch(a.label){case 0:return r="string"==typeof(t=function(e){if(null==e)return p({},eT);var t=p({},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,i.loadGraphModel)(t.modelUrl,{fromTFHub:r})];case 1:return n=a.sent(),[2,new eR(t.modelType,n)]}})})}(n)];if("mediapipe"===n.runtime)return[2,function(e){return f(this,void 0,void 0,function(){var t;return d(this,function(r){switch(r.label){case 0:return[4,(t=new ej(function(e){if(null==e)return p({},ey);var t=p({},e);return t.runtime="mediapipe",null==t.modelType&&(t.modelType=ey.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 eA.BodyPix:return[2,function(e){return f(this,void 0,void 0,function(){return d(this,function(t){return[2,(function(e){return void 0===e&&(e=es),f(this,void 0,void 0,function(){return d(this,function(t){return"ResNet50"===(e=function(e){if(null==(e=e||es).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>ei[e.architecture].indexOf(e.outputStride))throw Error("Invalid outputStride "+e.outputStride+". Should be one of "+ei[e.architecture]+" for architecture "+e.architecture+".");if(null==e.multiplier&&(e.multiplier=1),0>ec[e.architecture].indexOf(e.multiplier))throw Error("Invalid multiplier "+e.multiplier+". Should be one of "+ec[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 f(this,void 0,void 0,function(){var t,r,n;return d(this,function(a){switch(a.label){case 0:var s;if(t=e.outputStride,r=e.quantBytes,null==o)throw Error("Cannot find TensorFlow.js. If you are using a