@ssafy-mhk/e-ver 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/WebcamPlaneBackground.d.ts +2 -3
- package/dist/garment/fitMotion.d.ts +3 -0
- package/dist/garment/trackedModelTransform.d.ts +1 -0
- package/dist/hooks/useWebcam.d.ts +2 -2
- package/dist/index.d.ts +0 -8
- package/dist/index.es.js +1101 -1131
- package/dist/index.umd.js +1 -1
- package/dist/pose/coordinateTransform.d.ts +2 -0
- package/dist/pose/yawFreezeController.d.ts +1 -1
- package/package.json +4 -4
- package/dist/components/AvatarModel.d.ts +0 -11
- package/dist/components/CameraView.d.ts +0 -15
- package/dist/components/EverProvider.d.ts +0 -9
- package/dist/components/GarmentModel.d.ts +0 -10
- package/dist/components/ever-context.d.ts +0 -9
- package/dist/hooks/useBodyMeasurer.d.ts +0 -20
- package/dist/hooks/useBodyMeasurer.test.d.ts +0 -1
- package/dist/hooks/usePoseMapper.d.ts +0 -8
- package/dist/hooks/usePoseMapper.test.d.ts +0 -1
- package/dist/store/useEverStore.d.ts +0 -22
- package/dist/store/useEverStore.test.d.ts +0 -1
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`zustand`),require(`react`),require(`three`),require(`react/jsx-runtime`),require(`@react-three/fiber`),require(`@react-three/drei`),require(`@mediapipe/tasks-vision`),require(`three/examples/jsm/utils/SkeletonUtils.js`),require(`@pixiv/three-vrm`)):typeof define==`function`&&define.amd?define([`exports`,`zustand`,`react`,`three`,`react/jsx-runtime`,`@react-three/fiber`,`@react-three/drei`,`@mediapipe/tasks-vision`,`three/examples/jsm/utils/SkeletonUtils.js`,`@pixiv/three-vrm`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`e-ver`]={},e.Zustand,e.React,e.THREE,e.react_jsx_runtime,e.ReactThreeFiber,e.ReactThreeDrei,e.MediaPipeVision,e.three_examples_jsm_utils_SkeletonUtils_js,e.PixivThreeVRM))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=Object.create,d=Object.defineProperty,f=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,m=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,g=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=p(t),a=0,o=i.length,s;a<o;a++)s=i[a],!h.call(e,s)&&s!==n&&d(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=f(t,s))||r.enumerable});return e},_=(e,t,n)=>(n=e==null?{}:u(m(e)),g(t||!e||!e.__esModule?d(n,`default`,{value:e,enumerable:!0}):n,e));n=_(n),r=_(r);var v=(0,t.create)(e=>({isWebcamActive:!1,activeGarmentUrl:null,landmarks:null,worldLandmarks:null,fitResult:null,setWebcamActive:t=>e({isWebcamActive:t}),setActiveGarmentUrl:t=>e({activeGarmentUrl:t}),setLandmarks:(t,n)=>e({landmarks:t,worldLandmarks:n}),setFitResult:t=>e({fitResult:t})})),y=(0,n.createContext)(void 0);function b(){let e=(0,n.useContext)(y);if(!e)throw Error(`useEver must be used within an EverProvider`);return e}var x=({children:e})=>{let t=(0,n.useRef)(null),[r,a]=(0,n.useState)(null),o={videoRef:t,avatarBones:r,setAvatarBones:(0,n.useCallback)(e=>{a(e)},[]),isProviderReady:!0};return(0,i.jsx)(y.Provider,{value:o,children:e})},S=({children:e,showEnvironment:t=!0,useDefaultLights:r=!0,enableOrbitControls:s=!0})=>(0,i.jsx)(x,{children:(0,i.jsx)(a.Canvas,{camera:{position:[0,1.5,3],fov:45},style:{width:`100%`,height:`100%`,position:`absolute`,top:0,left:0},gl:{alpha:!0,antialias:!0,preserveDrawingBuffer:!0},children:(0,i.jsxs)(n.Suspense,{fallback:null,children:[r?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`ambientLight`,{intensity:.7}),(0,i.jsx)(`directionalLight`,{position:[2,5,2],intensity:1.5,castShadow:!0}),(0,i.jsx)(`directionalLight`,{position:[-2,5,-2],intensity:.5})]}):null,t&&(0,i.jsx)(o.Environment,{preset:`city`}),e,s?(0,i.jsx)(o.OrbitControls,{enablePan:!1,minPolarAngle:Math.PI/4,maxPolarAngle:Math.PI/1.5,minDistance:1,maxDistance:5}):null]})})}),C={refShoulderWidthCm:44,refHeightCm:170,refArmLengthCm:58,refChestCircumferenceCm:96,refWaistCircumferenceCm:84,refHipWidthCm:36,refTorsoLengthCm:52,shoulderEaseCm:4.5,chestEaseCm:10,waistEaseCm:8,hipEaseCm:5,torsoEaseCm:2.5,armEaseCm:2,fitEaseScale:1.03};function w(e,t,n){return!e||t<=0?1:(e+n)/t}function T(e,t,n){return Math.max(t,Math.min(n,e))}function E(e,t=C){let n=w(e.shoulderWidthCm,t.refShoulderWidthCm,t.shoulderEaseCm),r=w(e.chestCircumferenceCm,t.refChestCircumferenceCm,t.chestEaseCm),i=w(e.waistCircumferenceCm,t.refWaistCircumferenceCm,t.waistEaseCm),a=w(e.hipWidthCm,t.refHipWidthCm,t.hipEaseCm),o=w(e.torsoLengthCm,t.refTorsoLengthCm,t.torsoEaseCm),s=t.refHeightCm>0?e.heightCm/t.refHeightCm:1,c=w(e.armLengthCm,t.refArmLengthCm,t.armEaseCm),l=Math.max(n,r,a),u=Math.max(r,i,a*.98),d=Math.max(s,o,l*.94);return{scaleX:T(l,.82,1.85),scaleY:T(d,.85,1.55),scaleZ:T(u,.84,1.9),sleeveScale:T(c,.8,1.55),fitEaseScale:T(t.fitEaseScale,1,1.2)}}var D=.82,O=2.1,k=.85,A=1.8,j=.84,M=2.1,ee=.8,N=1.7,P=1,F=1.25,te={scaleX:1,scaleY:1,scaleZ:1,sleeveScale:1,fitEaseScale:1.02},ne={scaleX:1,scaleY:1,scaleZ:1,sleeveScale:1,fitEaseScale:1},re={slim:{x:.95,y:.95,z:1,ease:.99},regular:{x:1,y:1,z:1,ease:1},oversize:{x:1.08,y:1.08,z:1.02,ease:1.03}},ie={narrow:{width:.97,shoulder:.97},balanced:{width:1,shoulder:1},broad:{width:1.03,shoulder:1.04}},ae={tapered:{depth:.98,vertical:.995,hip:.99},balanced:{depth:1,vertical:1,hip:1},full:{depth:1.04,vertical:1.015,hip:1.03}};function I(e,t,n){return Math.max(t,Math.min(n,e))}function L(e,t,n,r){return!e||!t||t<=0?1:I(e/t,n,r)}function R(e,t,n,r,i){return!e||t<=0?1:I((e+n)/t,r,i)}function oe(e){return ie[e?.taxonomy.upperBodySilhouette??`balanced`]??ie.balanced}function se(e){return ae[e?.taxonomy.torsoOrPelvisProfile??`balanced`]??ae.balanced}function ce(e){if(!e)return!1;let{metrics:t}=e;return!!(t.heightCm||t.chestCm||t.waistCm||t.shoulderWidthCm||t.armLengthCm||t.torsoLengthCm||t.neckToHipCm)}function le(e,t){let{metrics:n}=e,r=oe(e),i=se(e),a=Math.max(R(n.shoulderWidthCm,t.refShoulderWidthCm,t.shoulderEaseCm*.55,.88,1.3),R(n.chestCm,t.refChestCircumferenceCm,t.chestEaseCm*.35,.9,1.34),R(n.waistCm,t.refWaistCircumferenceCm,t.waistEaseCm*.3,.9,1.3))*r.width,o=Math.max(L(n.heightCm,t.refHeightCm,.9,1.18),R(n.torsoLengthCm??n.neckToHipCm,t.refTorsoLengthCm,t.torsoEaseCm*.2,.9,1.16))*i.vertical,s=Math.max(R(n.chestCm,t.refChestCircumferenceCm,t.chestEaseCm*.15,.9,1.34),R(n.waistCm,t.refWaistCircumferenceCm,t.waistEaseCm*.1,.9,1.28))*i.depth;return{scaleX:I(a,D,O),scaleY:I(o,k,A),scaleZ:I(s,j,M),sleeveScale:I(L(n.armLengthCm,t.refArmLengthCm,.9,1.16),ee,N),fitEaseScale:I(t.fitEaseScale*(r.width*.5+i.depth*.5),P,F)}}function ue(e,t){let{metrics:n}=t,r=oe(t),i=se(t),a=L(e.shoulderWidthCm,n.shoulderWidthCm,.9,1.14)*r.shoulder,o=L(e.chestCircumferenceCm,n.chestCm,.9,1.15),s=L(e.waistCircumferenceCm,n.waistCm,.9,1.15);return{torsoScale:L(e.torsoLengthCm,n.torsoLengthCm??n.neckToHipCm,.9,1.14),chestScale:o,waistScale:s,hipScale:I(s*.6+i.hip*.4,.92,1.14),shoulderAdjust:I(a-1,-.12,.12),postureAdjust:`neutral`}}function de(e,t,n){let r=se(t),i=I(1+n.shoulderAdjust,.92,1.14)*.3+n.chestScale*.45+n.waistScale*.25,a=n.chestScale*.45+n.waistScale*.25+n.hipScale*.3,o=L(e.armLengthCm,t.metrics.armLengthCm,.9,1.16),s=Math.max(n.chestScale,n.waistScale,n.hipScale);return{scaleX:I(i,.92,1.16),scaleY:I(n.torsoScale*r.vertical,.92,1.14),scaleZ:I(a*r.depth,.92,1.18),sleeveScale:I(o,ee,N),fitEaseScale:I(1+(s-1)*.22,.99,1.08)}}function fe(e,t){if(!t||!Number.isFinite(t)||t<=0)return e;let n=I(t,.88,1.2),r=1+(n-1)*.35;return{scaleX:I(e.scaleX*n,D,O),scaleY:I(e.scaleY*r,k,A),scaleZ:I(e.scaleZ*n,j,M),sleeveScale:I(e.sleeveScale*r,ee,N),fitEaseScale:I(e.fitEaseScale*n,P,F)}}function pe(e,t){let n=re[t];return{scaleX:I(e.scaleX*n.x,D,O),scaleY:I(e.scaleY*n.y,k,A),scaleZ:I(e.scaleZ*n.z,j,M),sleeveScale:e.sleeveScale,fitEaseScale:I(e.fitEaseScale*n.ease,P,F)}}function me(e,t){return{scaleX:I(e.scaleX*t.scaleX,D,O),scaleY:I(e.scaleY*t.scaleY,k,A),scaleZ:I(e.scaleZ*t.scaleZ,j,M),sleeveScale:I(e.sleeveScale*t.sleeveScale,ee,N),fitEaseScale:I(e.fitEaseScale*t.fitEaseScale,P,F)}}function he({measurements:e,measurementScale:t,presetSelection:n,fitType:r=`regular`,garmentScaleHint:i=null,spec:a=C}){let o=ce(n),s=o&&n?le(n,a):t??te,c=o&&n&&e?ue(e,n):null;return{scale:pe(fe(me(s,e&&n&&c?de(e,n,c):ne),i),r),morph:c}}var ge=`http://localhost:8000/api/v1`;function _e(e){return e.replace(/\/+$/,``)}function ve(e){try{return new URL(e).origin}catch{return``}}var ye=class{baseUrl;apiOrigin;apiKey;constructor(e){let t=typeof e==`string`?{baseUrl:e}:e??{},n=_e(t.baseUrl??`http://localhost:8000/api/v1`);this.baseUrl=n,this.apiOrigin=ve(n),this.apiKey=t.apiKey}resolveAssetUrl(e){return e?e.startsWith(`http://`)||e.startsWith(`https://`)?e:e.startsWith(`/`)?this.apiOrigin?`${this.apiOrigin}${e}`:e:this.apiOrigin?`${this.apiOrigin}/${e}`:`/${e}`:null}async listBodyPresets(e){return(await this.request(`body-presets/`,{params:e?{gender:e}:void 0})).map(e=>this.normalizeBodyPreset(e))}async matchBodyPreset(e){let t=await this.request(`body-presets/match`,{method:`POST`,body:e});return this.normalizeBodyPreset(t)}async listGarments(e){let t=await this.request(`garment/`,{params:e});return{...t,items:t.items.map(e=>this.normalizeGarmentSummary(e))}}async getGarment(e){let t=await this.request(`garment/${e}`);return this.normalizeGarmentDetail(t)}async getPipelineStatus(e){return this.request(`pipeline/${e}`)}async createGarment(e){let t=await this.request(`garment/`,{method:`POST`,body:e});return this.normalizeGarmentSummary(t)}async uploadGarmentImage(e,t,n){let r=new FormData;return r.append(`files`,t,`${n}_image.png`),r.append(`image_type`,n),(await this.request(`garment/${e}/images`,{method:`POST`,body:r})).map(e=>({...e,image_url:this.resolveAssetUrl(e.image_url)??e.image_url}))}async generateGarment3D(e,t){return this.request(`garment/${e}/generate-3d`,{method:`POST`,body:{include_measurements:t?.include_measurements??!1,target_fit_types:t?.target_fit_types??[`regular`]}})}async waitForGarmentModel(e,t){let n=t?.intervalMs??2e3,r=t?.timeoutMs??12e4,i=Date.now();for(;Date.now()-i<=r;){let t=await this.getGarment(e);if(this.pickGarmentModelUrl(t))return t;if(t.asset_status===`rigging_failed`)throw Error(`Garment 3D generation failed on backend.`);await new Promise(e=>globalThis.setTimeout(e,n))}throw Error(`Timed out while waiting for garment 3D model.`)}pickGarmentModelUrl(e){if(e.model_url)return e.model_url;let t=e.variants.find(e=>e.is_default&&e.model_url);return t?.model_url?t.model_url:e.variants.find(e=>e.model_url)?.model_url??null}normalizeBodyPreset(e){return{...e,model_url:this.resolveAssetUrl(e.model_url)}}normalizeGarmentSummary(e){return{...e,thumbnail_url:this.resolveAssetUrl(e.thumbnail_url),model_url:this.resolveAssetUrl(e.model_url)}}normalizeGarmentDetail(e){return{...this.normalizeGarmentSummary(e),brand:e.brand?{...e.brand,logo_url:this.resolveAssetUrl(e.brand.logo_url)}:null,images:e.images.map(e=>({...e,image_url:this.resolveAssetUrl(e.image_url)??e.image_url})),sizes:e.sizes,variants:e.variants.map(e=>({...e,model_url:this.resolveAssetUrl(e.model_url)}))}}async request(e,t){let n=this.apiKey?`sdk/public/${e}`:e,r=this.buildUrl(n,t?.params),i=new Headers,a;this.apiKey&&i.set(`X-API-Key`,this.apiKey),t?.body instanceof FormData?a=t.body:t?.body!==void 0&&(i.set(`Content-Type`,`application/json`),a=JSON.stringify(t.body));let o=await fetch(r.toString(),{method:t?.method??`GET`,body:a,headers:i,credentials:this.apiKey?`omit`:`include`});if(!o.ok)throw Error(await this.getResponseErrorMessage(o));if(o.status!==204)return await o.json()}buildUrl(e,t){let n=this.baseUrl.startsWith(`http://`)||this.baseUrl.startsWith(`https://`)?`${this.baseUrl}/`:typeof window<`u`?new URL(`${this.baseUrl}/`,window.location.origin).toString():`http://localhost${this.baseUrl}/`,r=new URL(e.replace(/^\/+/,``),n);return t&&Object.entries(t).forEach(([e,t])=>{t!==void 0&&r.searchParams.set(e,String(t))}),r}async getResponseErrorMessage(e){try{let t=await e.json();return t.detail||t.message||t.error||`Request failed with status ${e.status}`}catch{return`Request failed with status ${e.status}`}}},be=`M`,xe=`male-m-balanced-balanced`,Se=`female-m-balanced-balanced`,Ce=`rigged_avatar`;function we(e,t){if(!t)return``;if(/^https?:\/\//.test(t))return t;let n=t.startsWith(`/`)?t:`/${t}`;return n.startsWith(`/assets/`)||n.startsWith(`/static/`)?n:e.resolveAssetUrl(n)??n}function Te(e){return e===`female`?`female`:`male`}function Ee(e,t={}){let n=t.renderMode??`rigged_avatar`,r=t.legacyPresetId??`rigged_avatar`,i=`/assets/body-presets/${r}.glb`;return e===r||n!==`preset-native`?i:`/assets/body-presets/archive/${e}.glb`}function De(e){return e===`female`?Se:xe}function Oe(e,t){return{id:e.id,presetId:e.preset_id,baseGender:Te(e.base_gender),sizeBand:e.size_band,upperBodySilhouette:e.upper_body_silhouette,torsoOrPelvisProfile:e.torso_or_pelvis_profile,modelUrl:we(t,e.model_url),heightCm:e.height_cm??null,chestCm:e.chest_cm??null,waistCm:e.waist_cm??null,hipCm:e.hip_cm??null,shoulderWidthCm:e.shoulder_width_cm??null,armLengthCm:e.arm_length_cm??null,inseamCm:e.inseam_cm??null,torsoLengthCm:e.torso_length_cm??null,neckToHipCm:e.neck_to_hip_cm??null}}function ke(e,t={}){return{...e,modelUrl:e.modelUrl||Ee(e.presetId,t)}}function Ae(e,t={}){return e.length===0?null:ke(e.find(e=>e.sizeBand===be)||e[Math.floor(e.length/2)],t)}function je(e,t={}){let n=De(e);return{id:null,presetId:n,label:`${e===`female`?`여성`:`남성`} 기본 ${be}`,modelUrl:Ee(n,t),gender:e,source:`fallback`,taxonomy:{sizeBand:be,upperBodySilhouette:`balanced`,torsoOrPelvisProfile:`balanced`},metrics:{heightCm:null,chestCm:null,waistCm:null,hipCm:null,shoulderWidthCm:null,armLengthCm:null,inseamCm:null,torsoLengthCm:null,neckToHipCm:null}}}function Me(e,t,n={}){let r=ke(e,n);return{id:r.id,presetId:r.presetId,label:`${r.baseGender===`female`?`여성`:`남성`} ${r.sizeBand}`,modelUrl:r.modelUrl,gender:r.baseGender,source:t,taxonomy:{sizeBand:r.sizeBand,upperBodySilhouette:r.upperBodySilhouette,torsoOrPelvisProfile:r.torsoOrPelvisProfile},metrics:{heightCm:r.heightCm,chestCm:r.chestCm,waistCm:r.waistCm,hipCm:r.hipCm,shoulderWidthCm:r.shoulderWidthCm,armLengthCm:r.armLengthCm,inseamCm:r.inseamCm,torsoLengthCm:r.torsoLengthCm,neckToHipCm:r.neckToHipCm}}}function Ne(e,t){let n={gender:t};return Number.isFinite(e.heightCm)&&(n.height_cm=e.heightCm),e.chestCircumferenceCm!==null&&(n.chest_cm=e.chestCircumferenceCm),e.waistCircumferenceCm!==null&&(n.waist_cm=e.waistCircumferenceCm),e.shoulderWidthCm!==null&&(n.shoulder_width_cm=e.shoulderWidthCm),n}var Pe=new ye;function Fe(e,t){return{selection:je(e,t),loading:!0,error:null}}function Ie(e,t={}){let r=Te(t.gender),i=t.renderMode,a=t.legacyPresetId,o={gender:r,renderMode:i,legacyPresetId:a},[s,c]=(0,n.useState)(()=>Fe(r,o));return(0,n.useEffect)(()=>{let t=new AbortController;async function n(){c(e=>({...e,loading:!0,error:null}));try{if(e){let n=Me(Oe(await Pe.matchBodyPreset(Ne(e,r)),Pe),`match`,o);if(t.signal.aborted)return;c({selection:n,loading:!1,error:null});return}let n=(await Pe.listBodyPresets(r)).map(e=>Oe(e,Pe));if(t.signal.aborted)return;let i=Ae(n,o);if(i){c({selection:Me(i,`default`,o),loading:!1,error:null});return}c({selection:je(r,o),loading:!1,error:`바디 프리셋 응답이 비어 있어 기본 프리셋으로 대체했습니다.`})}catch(e){if(t.signal.aborted)return;c({selection:je(r,o),loading:!1,error:e instanceof Error?e.message:`바디 프리셋을 불러오지 못해 기본 프리셋으로 대체했습니다.`})}}return n(),()=>{t.abort()}},[r,a,e,i]),s}var z={NOSE:0,LEFT_EYE_INNER:1,LEFT_EYE:2,LEFT_EYE_OUTER:3,RIGHT_EYE_INNER:4,RIGHT_EYE:5,RIGHT_EYE_OUTER:6,LEFT_EAR:7,RIGHT_EAR:8,MOUTH_LEFT:9,MOUTH_RIGHT:10,LEFT_SHOULDER:11,RIGHT_SHOULDER:12,LEFT_ELBOW:13,RIGHT_ELBOW:14,LEFT_WRIST:15,RIGHT_WRIST:16,LEFT_PINKY:17,RIGHT_PINKY:18,LEFT_INDEX:19,RIGHT_INDEX:20,LEFT_THUMB:21,RIGHT_THUMB:22,LEFT_HIP:23,RIGHT_HIP:24,LEFT_KNEE:25,RIGHT_KNEE:26,LEFT_ANKLE:27,RIGHT_ANKLE:28,LEFT_HEEL:29,RIGHT_HEEL:30,LEFT_FOOT_INDEX:31,RIGHT_FOOT_INDEX:32},Le={positionAlpha:.7,rotationAlpha:.6,visibilityThreshold:.5},Re=.5;function B(e){return e?(e.visibility??1)>=Re:!1}function ze(e,t){let n=e[z.NOSE],r=e[z.LEFT_EYE],i=e[z.LEFT_ANKLE],a=e[z.RIGHT_ANKLE];if(!B(n)||!B(r)||!B(i)||!B(a))return 0;let o=n.y-(r.y-n.y)*2,s=(Math.max(i.y,a.y)-o)*t;return Number.isFinite(s)&&s>0?s:0}function Be(e,t,n=720){let r=ze(e,n);return r<=0||t<=0?0:t/r}function Ve(e){let t=[[15,.8],[18.5,.84],[22,.88],[25,.91],[30,.94],[40,.96]];if(e<=t[0][0])return t[0][1];if(e>=t[t.length-1][0])return t[t.length-1][1];for(let n=0;n<t.length-1;n+=1){let[r,i]=t[n],[a,o]=t[n+1];if(e>=r&&e<=a)return i+(e-r)/(a-r)*(o-i)}return .88}function V(e,t,n,r){if(!B(e)||!B(t))return null;let i=(e.x-t.x)*n,a=(e.y-t.y)*r,o=Math.hypot(i,a);return Number.isFinite(o)&&o>0?o:null}function He(e){return Math.round(e*10)/10}function H(e){return e===null||!Number.isFinite(e)||e<=0?null:He(e)}function Ue(e){let t=e.filter(e=>e!==null);return t.length===0?null:t.reduce((e,t)=>e+t,0)/t.length}function We(e,t){return e&&t!==null&&t>0?`silhouette_bmi`:`keypoint`}function Ge(e,t,n){return n&&t>0&&e/t>=.85?`standard`:`estimate`}function Ke(e,t,n,r){if(t<=0||e<=0)return 0;let i=e/t*.8,a=n?.15:0,o=r!==null&&r>0?.05:0;return Math.min(.99,He((i+a+o)*10)/10)}function qe(e,t){if(e<=0||t<=0)return 0;let n=(e-t)**2/(e+t)**2;return Math.PI*(e+t)*(1+3*n/(10+Math.sqrt(4-3*n)))}function Je(e,t,n=null,r=null,i=1280,a=720){let o=Be(e,t,a),s=We(r,n);if(o<=0)return{heightCm:t,shoulderWidthCm:null,chestCircumferenceCm:null,waistCircumferenceCm:null,hipWidthCm:null,armLengthCm:null,legLengthCm:null,torsoLengthCm:null,accuracyGrade:`estimate`,confidenceScore:0,measurementMethod:s,measuredAt:null};let c=V(e[z.LEFT_SHOULDER],e[z.RIGHT_SHOULDER],i,a),l=V(e[z.LEFT_HIP],e[z.RIGHT_HIP],i,a),u=V(e[z.LEFT_SHOULDER],e[z.LEFT_ELBOW],i,a),d=V(e[z.LEFT_ELBOW],e[z.LEFT_WRIST],i,a),f=V(e[z.RIGHT_SHOULDER],e[z.RIGHT_ELBOW],i,a),p=V(e[z.RIGHT_ELBOW],e[z.RIGHT_WRIST],i,a),m=u!==null&&d!==null?u+d:null,h=f!==null&&p!==null?f+p:null,g=V(e[z.LEFT_HIP],e[z.LEFT_KNEE],i,a),_=V(e[z.LEFT_KNEE],e[z.LEFT_ANKLE],i,a),v=V(e[z.RIGHT_HIP],e[z.RIGHT_KNEE],i,a),y=V(e[z.RIGHT_KNEE],e[z.RIGHT_ANKLE],i,a),b=g!==null&&_!==null?g+_:null,x=v!==null&&y!==null?v+y:null,S=Ue([V(e[z.LEFT_SHOULDER],e[z.LEFT_HIP],i,a),V(e[z.RIGHT_SHOULDER],e[z.RIGHT_HIP],i,a)]),C=H(c===null?null:c*o),w=H(l===null?null:l*o),T=H(Ue([m===null?null:m*o,h===null?null:h*o])),E=H(Ue([b===null?null:b*o,x===null?null:x*o])),D=H(S===null?null:S*o),O=C===null?null:C*2.2,k=w===null?null:w*2.1;if(r){let e=r.shoulderWidthPx*o;if(O=H(qe(Math.max(r.chestWidthPx*o/2,0),Math.max(e*.28/2,0))),k=H(qe(Math.max(r.waistWidthPx*o/2,0),Math.max(r.hipWidthPx*o*.26/2,0))),n!==null&&n>0){let e=Ve(n/(t/100)**2);O=H(O===null?null:O/e),k=H(k===null?null:k/e)}}else O=H(O),k=H(k);let A=[C,O,k,w,T,E,D].filter(e=>e!==null).length;return{heightCm:He(t),shoulderWidthCm:C,chestCircumferenceCm:O,waistCircumferenceCm:k,hipWidthCm:w,armLengthCm:T,legLengthCm:E,torsoLengthCm:D,accuracyGrade:Ge(A,7,r),confidenceScore:Ke(A,7,r,n),measurementMethod:s,measuredAt:null}}var Ye={S:{shoulder:[40,42],chest:[86,92],waist:[72,78]},M:{shoulder:[42,44],chest:[92,98],waist:[78,84]},L:{shoulder:[44,46],chest:[98,104],waist:[84,90]},XL:{shoulder:[46,48],chest:[104,110],waist:[90,96]},"2XL":{shoulder:[48,50],chest:[110,118],waist:[96,104]}};function Xe(e){let t=[`S`,`M`,`L`,`XL`,`2XL`],n=`M`,r=-1/0,i=!1;for(let a of t){let t=Ye[a],o=0,s=0;if(e.shoulderWidthCm!==null){let n=(t.shoulder[0]+t.shoulder[1])/2;o-=Math.abs(e.shoulderWidthCm-n),s+=1,i=!0}if(e.chestCircumferenceCm!==null){let n=(t.chest[0]+t.chest[1])/2;o-=Math.abs(e.chestCircumferenceCm-n),s+=1,i=!0}if(e.waistCircumferenceCm!==null){let n=(t.waist[0]+t.waist[1])/2;o-=Math.abs(e.waistCircumferenceCm-n),s+=1,i=!0}s>0&&(o/=s),o>r&&(r=o,n=a)}if(!i)return null;let a=Ye[n],o=`true-to-size`;if(e.chestCircumferenceCm!==null){let t=(a.chest[0]+a.chest[1])/2;e.chestCircumferenceCm>t+3?o=`slim`:e.chestCircumferenceCm<t-3&&(o=`relaxed`)}return{size:n,confidence:Math.min(1,Math.max(0,1+r/10)),fitDescription:o}}var Ze={referenceHeightCm:170,weightKg:null,stableFrameCount:15,motionThreshold:.015};function Qe(e){return e.map(e=>({...e}))}function $e(e,t){let n=0;for(let r=0;r<33;r+=1){let i=e[r],a=t[r];n+=Math.abs(a.x-i.x)+Math.abs(a.y-i.y)}return n/33}function et(){let[e,t]=(0,n.useState)(Ze),[r,i]=(0,n.useState)(null),[a,o]=(0,n.useState)(null),[s,c]=(0,n.useState)(null),[l,u]=(0,n.useState)(!1),d=(0,n.useRef)(0),f=(0,n.useRef)(null),p=(0,n.useCallback)(()=>{d.current=0,f.current=null},[]),m=(0,n.useCallback)(()=>{i(null),o(null),c(null)},[]),h=(0,n.useCallback)(()=>{p(),m(),u(!0)},[m,p]);return{measure:(0,n.useCallback)((t,n={})=>{if(!l||t.length<33)return;let r=Qe(t);if(!f.current){f.current=r,d.current=1;return}if(d.current=$e(f.current,r)<e.motionThreshold?d.current+1:1,f.current=r,d.current<e.stableFrameCount)return;let a=Je(t,e.referenceHeightCm,e.weightKg,n.silhouetteWidths??null,n.imageWidth??1280,n.imageHeight??720),s=new Date().toISOString(),m=Xe(a),h=E(a);i({...a,measuredAt:s}),o(m),c(h),u(!1),p()},[e,l,p]),startMeasurement:h,measurements:r,sizeRecommendation:a,garmentScale:s,isMeasuring:l,updateConfig:(0,n.useCallback)(e=>{t(t=>({...t,...e})),p(),m(),u(!1)},[m,p]),config:e}}function tt(e,t,n,r){if(e<=0||t<=0||n<=0||r<=0)return{x:0,y:0,width:Math.max(0,e),height:Math.max(0,t)};let i=e/t,a=n/r;if(i>a){let n=e,r=n/a;return{x:0,y:(t-r)*.5,width:n,height:r}}let o=t,s=o*a;return{x:(e-s)*.5,y:0,width:s,height:o}}function nt(e,t,n,r){if(e<=0||t<=0||n<=0||r<=0)return{xMin:0,xMax:1,yMin:0,yMax:1};let i=e/t,a=n/r;if(i>a){let e=(1-a/i)/2;return{xMin:0,xMax:1,yMin:e,yMax:1-e}}let o=(1-i/a)/2;return{xMin:o,xMax:1-o,yMin:0,yMax:1}}var rt=5,it=.5;function at(e,t,n,r,i=rt,a=it){if(t<=0||n<=0||e.length!==t*n)return null;let o=Math.round(r),s=Math.floor(i/2),c=Math.max(0,o-s),l=Math.min(n-1,o+s),u=0,d=0,f=0;for(let n=c;n<=l;n+=1){let r=-1,i=-1,o=n*t;for(let n=0;n<t;n+=1)e[o+n]>=a&&(r<0&&(r=n),i=n);r>=0&&i>r&&(u+=r,d+=i,f+=1)}if(f===0)return null;let p=u/f;return d/f-p}function ot(e,t,n,r){if(r.length<33)return null;let i=r[z.LEFT_SHOULDER],a=r[z.RIGHT_SHOULDER],o=r[z.LEFT_HIP],s=r[z.RIGHT_HIP],c=r[z.LEFT_KNEE],l=r[z.RIGHT_KNEE];if(!i||!a||!o||!s)return null;let u=(i.y+a.y)/2*n,d=(o.y+s.y)/2*n,f=u+(d-u)*.4,p=c&&l?d+((c.y+l.y)/2*n-d)*.2:d,m=at(e,t,n,u),h=at(e,t,n,f),g=at(e,t,n,d),_=at(e,t,n,p);return m===null||h===null||g===null||_===null?null:{shoulderWidthPx:m,chestWidthPx:h,waistWidthPx:g,hipWidthPx:_}}function U(e,t,n){return e+(t-e)*n}function st(e,t,n){return t?!e||e.length!==t.length?t:e.map((e,r)=>{let i=t[r];return{x:U(e.x,i.x,n),y:U(e.y,i.y,n),z:U(e.z??0,i.z??0,n),visibility:U(e.visibility??0,i.visibility??0,n)}}):null}function W(e,t,n){return{x:U(e.x,t.x,n),y:U(e.y,t.y,n),z:U(e.z,t.z,n)}}function ct(e,t,n){return!e||!t?t??e:W(e,t,n)}function lt(e,t,n){return t?e?{hips:{position:{x:U(e.hips.position.x,t.hips.position.x,n),y:U(e.hips.position.y,t.hips.position.y,n),z:U(e.hips.position.z,t.hips.position.z,n)},rotation:W(e.hips.rotation,t.hips.rotation,n)},spine:W(e.spine,t.spine,n),chest:W(e.chest,t.chest,n),leftUpperArm:W(e.leftUpperArm,t.leftUpperArm,n),leftLowerArm:W(e.leftLowerArm,t.leftLowerArm,n),rightUpperArm:W(e.rightUpperArm,t.rightUpperArm,n),rightLowerArm:W(e.rightLowerArm,t.rightLowerArm,n),leftUpperLeg:ct(e.leftUpperLeg,t.leftUpperLeg,n),leftLowerLeg:ct(e.leftLowerLeg,t.leftLowerLeg,n),rightUpperLeg:ct(e.rightUpperLeg,t.rightUpperLeg,n),rightLowerLeg:ct(e.rightLowerLeg,t.rightLowerLeg,n)}:t:null}function ut(e,t,n){return t?e?{shoulderWidthPx:U(e.shoulderWidthPx,t.shoulderWidthPx,n),chestWidthPx:U(e.chestWidthPx,t.chestWidthPx,n),waistWidthPx:U(e.waistWidthPx,t.waistWidthPx,n),hipWidthPx:U(e.hipWidthPx,t.hipWidthPx,n)}:t:null}function dt(){return{landmarks:null,worldLandmarks:null,poseRig:null,confidence:0,isTracking:!1,silhouetteWidths:null}}function ft(e,t,n){return!e||!e.isTracking||!t.isTracking||!t.landmarks?t:{landmarks:st(e.landmarks,t.landmarks,n),worldLandmarks:st(e.worldLandmarks,t.worldLandmarks,n),poseRig:lt(e.poseRig,t.poseRig,n),confidence:U(e.confidence,t.confidence,n),isTracking:t.isTracking,silhouetteWidths:ut(e.silhouetteWidths,t.silhouetteWidths,n)}}var pt=`0.10.32`,mt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${pt}/wasm`,ht=2,gt=3,_t=.5,vt={lite:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/latest/pose_landmarker_lite.task`,full:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_full/float16/latest/pose_landmarker_full.task`,heavy:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_heavy/float16/latest/pose_landmarker_heavy.task`};async function yt(e,t,n,r,i=3){let a=await s.FilesetResolver.forVisionTasks(mt),o={baseOptions:{modelAssetPath:e},runningMode:`VIDEO`,numPoses:i,outputSegmentationMasks:r,minPoseDetectionConfidence:t,minPosePresenceConfidence:n,minTrackingConfidence:n};try{return await s.PoseLandmarker.createFromOptions(a,{...o,baseOptions:{...o.baseOptions,delegate:`GPU`}})}catch{return s.PoseLandmarker.createFromOptions(a,{...o,baseOptions:{...o.baseOptions,delegate:`CPU`}})}}var bt=new r.Vector3,xt=new r.Vector3,St=new r.Vector3,Ct=new r.Quaternion,wt=new r.Vector3,Tt=new r.Vector3,Et=new r.Vector3(0,-1,0),Dt=new r.Vector3(1,0,0),Ot=new r.Vector3(-1,0,0),kt=new r.Vector3(0,1,0),At=[z.LEFT_SHOULDER,z.RIGHT_SHOULDER],jt=[z.LEFT_HIP,z.RIGHT_HIP],Mt=[z.LEFT_EAR,z.RIGHT_EAR],Nt=[z.LEFT_INDEX,z.LEFT_PINKY],Pt=[z.RIGHT_INDEX,z.RIGHT_PINKY],Ft={Hips:{from:jt,to:At,restDir:kt,influence:.35},Spine:{from:jt,to:At,restDir:kt,influence:.55},Chest:{from:At,to:Mt,restDir:kt,influence:.7},LeftShoulder:{from:At,to:z.LEFT_SHOULDER,restDir:Dt,influence:.45},LeftUpperArm:{from:z.LEFT_SHOULDER,to:z.LEFT_ELBOW,restDir:Dt},LeftLowerArm:{from:z.LEFT_ELBOW,to:z.LEFT_WRIST,restDir:Dt},LeftHand:{from:z.LEFT_WRIST,to:Nt,restDir:Dt,influence:.65},RightShoulder:{from:At,to:z.RIGHT_SHOULDER,restDir:Ot,influence:.45},RightUpperArm:{from:z.RIGHT_SHOULDER,to:z.RIGHT_ELBOW,restDir:Ot},RightLowerArm:{from:z.RIGHT_ELBOW,to:z.RIGHT_WRIST,restDir:Ot},RightHand:{from:z.RIGHT_WRIST,to:Pt,restDir:Ot,influence:.65},LeftUpperLeg:{from:z.LEFT_HIP,to:z.LEFT_KNEE,restDir:Et},LeftLowerLeg:{from:z.LEFT_KNEE,to:z.LEFT_ANKLE,restDir:Et},LeftFoot:{from:z.LEFT_ANKLE,to:z.LEFT_FOOT_INDEX,restDir:new r.Vector3(0,0,1)},RightUpperLeg:{from:z.RIGHT_HIP,to:z.RIGHT_KNEE,restDir:Et},RightLowerLeg:{from:z.RIGHT_KNEE,to:z.RIGHT_ANKLE,restDir:Et},RightFoot:{from:z.RIGHT_ANKLE,to:z.RIGHT_FOOT_INDEX,restDir:new r.Vector3(0,0,1)}};function It(e,t,n){return n===`world`?(t.set(-e.x,-e.y,-(e.z??0)),t):(t.set(-(e.x-.5),-(e.y-.5),-(e.z??0)*.5),t)}function Lt(e,t,n,r){if(typeof e==`number`){let i=t[e];return!i||(i.visibility??0)<.4?!1:(It(i,n,r),!0)}let i=t[e[0]],a=t[e[1]];return!i||!a||(i.visibility??0)<.4||(a.visibility??0)<.4?!1:(It(i,wt,r),It(a,Tt,r),n.copy(wt).add(Tt).multiplyScalar(.5),!0)}function Rt(e,t,n,r,i=`normalized`){if(!Lt(e,n,bt,i)||!Lt(t,n,xt,i))return!1;r.subVectors(xt,bt);let a=r.length();return a<.001?!1:(r.divideScalar(a),!0)}function zt(e,t,n,r=`normalized`){let i=Ft[e];return i?Rt(i.from,i.to,t,n,r):!1}function Bt(e){return Ft[e]?.influence}function Vt(e,t,n,r=`normalized`){let i=Ft[e];return!i||!zt(e,t,St,r)?!1:(n.setFromUnitVectors(i.restDir,St),i.influence!==void 0&&n.slerp(Ct.identity(),1-i.influence),!0)}function Ht(e){return e in Ft}var Ut=new r.Quaternion,Wt=new r.Euler;function Gt(){return{x:0,y:0,z:0}}function Kt(e){return Wt.setFromQuaternion(e,`XYZ`),{x:Wt.x,y:Wt.y,z:Wt.z}}function G(e,t,n){return Vt(e,t,Ut,n)?Kt(Ut):Gt()}function qt(e,t,n){if(Vt(e,t,Ut,n))return Kt(Ut)}function Jt(e){let t=e[z.LEFT_HIP],n=e[z.RIGHT_HIP];return{x:((t?.x??0)+(n?.x??0))*.5,y:((t?.y??0)+(n?.y??0))*.5,z:((t?.z??0)+(n?.z??0))*.5}}function Yt(e,t){if(e.length<33)return null;let n=t&&t.length>=33?t:e,r=t&&t.length>=33?`world`:`normalized`;return{hips:{position:Jt(e),rotation:G(`Hips`,n,r)},spine:G(`Spine`,n,r),chest:G(`Chest`,n,r),leftUpperArm:G(`LeftUpperArm`,n,r),leftLowerArm:G(`LeftLowerArm`,n,r),rightUpperArm:G(`RightUpperArm`,n,r),rightLowerArm:G(`RightLowerArm`,n,r),leftUpperLeg:qt(`LeftUpperLeg`,n,r),leftLowerLeg:qt(`LeftLowerLeg`,n,r),rightUpperLeg:qt(`RightUpperLeg`,n,r),rightLowerLeg:qt(`RightLowerLeg`,n,r)}}function Xt(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.width!=`number`||typeof t.height!=`number`||typeof t.getAsFloat32Array!=`function`?null:t}function Zt(e){if(e)for(let t of e)t&&typeof t==`object`&&`close`in t&&typeof t.close==`function`&&t.close()}function Qt(e,t,n){let r=t/n;return{shoulderWidthPx:e.shoulderWidthPx*r,chestWidthPx:e.chestWidthPx*r,waistWidthPx:e.waistWidthPx*r,hipWidthPx:e.hipWidthPx*r}}var $t=`pose-0`;function en(e){return typeof e==`number`?e:0}function tn(e){return{x:e.x,y:e.y,z:e.z,visibility:en(e.visibility)}}function nn(e){return e.map(tn)}function rn(e){return tn(e)}function an(e){let t=Math.PI*2,n=(e+Math.PI)%t;return n<0&&(n+=t),n-Math.PI}function on(e,t,n){return an(e+an(t-e)*n)}var sn=class{prev=null;config;constructor(e=Le){this.config=e}smooth(e){if(e.length===0)return this.prev=null,[];let t=nn(e);if(!this.prev||this.prev.length!==t.length)return this.prev=t.map(rn),t.map(rn);let n=this.config.positionAlpha,r=t.map((e,t)=>{let r=this.prev[t];return(e.visibility??0)<this.config.visibilityThreshold?{...rn(r),visibility:e.visibility}:{x:r.x+n*(e.x-r.x),y:r.y+n*(e.y-r.y),z:r.z+n*(e.z-r.z),visibility:e.visibility}});return this.prev=r.map(rn),r}reset(){this.prev=null}};function K(e,t,n){return{x:on(e.x,t.x,n),y:on(e.y,t.y,n),z:on(e.z,t.z,n)}}function cn(e,t,n){return t?e?K(e,t,n):t:e}function ln(e,t,n=Le.rotationAlpha){return e?{hips:{position:{x:e.hips.position.x+n*(t.hips.position.x-e.hips.position.x),y:e.hips.position.y+n*(t.hips.position.y-e.hips.position.y),z:e.hips.position.z+n*(t.hips.position.z-e.hips.position.z)},rotation:K(e.hips.rotation,t.hips.rotation,n)},spine:K(e.spine,t.spine,n),chest:K(e.chest,t.chest,n),leftUpperArm:K(e.leftUpperArm,t.leftUpperArm,n),leftLowerArm:K(e.leftLowerArm,t.leftLowerArm,n),rightUpperArm:K(e.rightUpperArm,t.rightUpperArm,n),rightLowerArm:K(e.rightLowerArm,t.rightLowerArm,n),leftUpperLeg:cn(e.leftUpperLeg,t.leftUpperLeg,n),leftLowerLeg:cn(e.leftLowerLeg,t.leftLowerLeg,n),rightUpperLeg:cn(e.rightUpperLeg,t.rightUpperLeg,n),rightLowerLeg:cn(e.rightLowerLeg,t.rightLowerLeg,n)}:t}var un=.12,dn=.35,fn=.05,pn=[11,12,23,24],mn=2,hn=.3;function gn(e){if(!e)return null;let t=Math.max(0,Math.min(1,e.x)),n=Math.max(0,Math.min(1,e.y));return{x:t,y:n,w:Math.max(.01,Math.min(1-t,e.w)),h:Math.max(.01,Math.min(1-n,e.h))}}function _n(e){if(!Array.isArray(e)||e.length===0)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0,a=0;return e.forEach(e=>{!e||typeof e.x!=`number`||typeof e.y!=`number`||(e.visibility??0)<dn||(t=Math.min(t,e.x),n=Math.min(n,e.y),r=Math.max(r,e.x),i=Math.max(i,e.y),a+=1)}),a<4||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)?null:gn({x:t,y:n,w:Math.max(.01,r-t),h:Math.max(.01,i-n)})}function vn(e,t=un){if(!e)return null;let n=e.w*t,r=e.h*t;return gn({x:e.x-n/2,y:e.y-r/2,w:e.w+n,h:e.h+r})}function yn(e,t){if(!e||!t)return 0;let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.w,t.x+t.w),a=Math.min(e.y+e.h,t.y+t.h),o=Math.max(0,i-n)*Math.max(0,a-r);if(o<=0)return 0;let s=e.w*e.h+t.w*t.h-o;return s<=0?0:o/s}function bn(e){return e.length===0?0:e.reduce((e,t)=>e+(t.visibility??0),0)/e.length}function xn(e,t=[]){return e.flatMap((e,n)=>{let r=_n(e),i=vn(r);return!r||!i?[]:[{poseIndex:n,personId:`pose-${n}`,landmarks:e,worldLandmarks:t[n]??null,bounds:r,expandedBounds:i,meanVisibility:bn(e),area:i.w*i.h}]})}function Sn(e,t){let n=yn(e.expandedBounds,t.expandedBounds);return{iou:n,score:n*.75+e.area*.25}}function Cn(e,{previousCandidate:t,allowRelock:n=!1,minIouToKeep:r=fn}){if(e.length===0)return null;let i=[...e].sort((e,t)=>t.area*t.meanVisibility-e.area*e.meanVisibility);if(!t)return i[0];let a=null,o=-1/0,s=0;return e.forEach(e=>{let{iou:n,score:r}=Sn(e,t);r>o&&(a=e,o=r,s=n)}),a&&s>=r?a:n?i[0]:null}function wn(e,t){if(!t)return!0;let n=0,r=0,i=0;for(let t of pn){let a=e.landmarks[t];a&&(a.visibility??0)>hn&&(n+=a.x,r+=a.y,i+=1)}if(i<mn)return!0;let a=n/i,o=r/i;return a>=t.xMin&&a<=t.xMax&&o>=t.yMin&&o<=t.yMax}function Tn(e,t){return t?e.filter(e=>wn(e,t)):e}function En(e){return e?{poseIndex:e.poseIndex,personId:e.personId,bounds:e.bounds,expandedBounds:e.expandedBounds}:null}var Dn=.55,On=640,kn=360;function An(e=null){return{level:`idle`,reasons:[`no_person_detected`],updatedAt:e}}function jn({detectedPersonCount:e,isTracking:t,lockedPersonId:n=null,meanVisibility:r=null,frameWidth:i=0,frameHeight:a=0,updatedAt:o=Date.now()}){if(e<1)return An(o);let s=[];return e>1&&s.push(`multi_person_detected`),i>0&&a>0&&(i<On||a<kn)&&s.push(`resolution_too_low`),r!==null&&r<Dn&&s.push(`low_visibility`),(!n||!t)&&s.push(`pose_not_locked`),s.length===0?{level:`good`,reasons:[],updatedAt:o}:{level:s.includes(`resolution_too_low`)?`blocked`:`degraded`,reasons:s,updatedAt:o}}function Mn(){return{detectedPersonCount:0,lockedPersonId:null,trackingQuality:An()}}function Nn({detectedPersonCount:e,isTracking:t,lockedPersonId:n,meanVisibility:r,frameWidth:i,frameHeight:a,updatedAt:o}){let s=n??(t&&e>0?`pose-0`:null);return{detectedPersonCount:e,lockedPersonId:s,trackingQuality:jn({detectedPersonCount:e,isTracking:t,lockedPersonId:s,meanVisibility:r,frameWidth:i,frameHeight:a,updatedAt:o})}}var Pn=180;function Fn(e,t,n=180){return e===null?!1:t-e<=n}function In(e){return!e||!e.isTracking||!e.landmarks||!e.poseRig?null:{...e,isTracking:!0}}function Ln(e,t,n=$t){return{detectedPersonCount:e,lockedPersonId:n,trackingQuality:{level:`degraded`,reasons:[`tracking_lost`],updatedAt:t}}}function Rn(){return{landmarks:null,worldLandmarks:null,poseRig:null,confidence:0,fps:0,isTracking:!1}}var zn=(e,t={})=>{let{enabled:r=!0,modelComplexity:i=`lite`,numPoses:a=3,minDetectionConfidence:o=.5,minTrackingConfidence:c=.5,outputSegmentationMasks:l=!1,viewportWidth:u=0,viewportHeight:d=0}=t,f=(0,n.useRef)(null),p=(0,n.useRef)(new sn(Le)),m=(0,n.useRef)(null),h=(0,n.useRef)(null),g=(0,n.useRef)(null),_=(0,n.useRef)(-1),v=(0,n.useRef)({width:0,height:0}),y=(0,n.useRef)(0),b=(0,n.useRef)(null),x=(0,n.useRef)(null),S=(0,n.useRef)(null),C=(0,n.useRef)(null),w=(0,n.useRef)(null),T=(0,n.useRef)(Mn()),E=(0,n.useRef)({frames:0,lastMeasuredAt:0}),D=(0,n.useRef)(null),O=(0,n.useRef)({width:0,height:0}),[k,A]=(0,n.useState)(!1),[j,M]=(0,n.useState)(Rn),[ee,N]=(0,n.useState)(null),[P,F]=(0,n.useState)({width:0,height:0}),[te,ne]=(0,n.useState)(Mn()),re=(0,n.useCallback)((e,t=T.current)=>{h.current=e.landmarks,T.current=t,M(t=>({...t,landmarks:e.landmarks,worldLandmarks:e.worldLandmarks,poseRig:e.poseRig,confidence:e.confidence,isTracking:e.isTracking})),N(e.silhouetteWidths),ne(t)},[]),ie=(0,n.useCallback)(()=>{p.current.reset(),m.current=null,h.current=null,_.current=-1,v.current={width:0,height:0},y.current=0,b.current=null,x.current=null,S.current=null,C.current=null,w.current=null,T.current=Mn(),E.current={frames:0,lastMeasuredAt:0},M(Rn()),N(null),F({width:0,height:0}),ne(Mn())},[]);(0,n.useEffect)(()=>{if(!r){A(!1),ie();return}let e=!1;async function t(){try{let t=await yt(vt[i],o,c,l,a);if(e){t.close();return}f.current=t,E.current.lastMeasuredAt=performance.now(),A(!0)}catch(e){console.error(`Failed to initialize MediaPipe Pose Landmarker:`,e)}}return t(),()=>{e=!0,A(!1),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),f.current?.close(),f.current=null,ie()}},[r,o,c,i,a,l,ie]),O.current={width:u,height:d},(0,n.useEffect)(()=>{if(!r||!k)return;let t=()=>{let n=e.current,r=f.current;if(!n||!r||n.readyState<HTMLMediaElement.HAVE_CURRENT_DATA){g.current=requestAnimationFrame(t);return}if(n.currentTime===_.current){g.current=requestAnimationFrame(t);return}_.current=n.currentTime;let i=n.videoWidth||n.clientWidth||1280,a=n.videoHeight||n.clientHeight||720;(i!==v.current.width||a!==v.current.height)&&(v.current={width:i,height:a},F({width:i,height:a}));let o=O.current;D.current=o.width>0&&o.height>0?nt(o.width,o.height,i,a):null;let s=performance.now();try{let e=b.current===null||y.current===0;if(y.current=(y.current+1)%2,e){let e=r.detectForVideo(n,s);try{let t=Tn(xn(e.landmarks,e.worldLandmarks),D.current),n=t.length,r=!Fn(C.current,s),o=Cn(t,{previousCandidate:w.current,allowRelock:r}),u=o?.landmarks??null,d=o?.worldLandmarks??null,f=o||w.current?$t:null,h=dt(),g=Nn({detectedPersonCount:n,isTracking:!1,lockedPersonId:f,frameWidth:i,frameHeight:a,updatedAt:s}),_=Fn(C.current,s)?In(S.current):null;if(!u)_?(h=_,g=Ln(n,s,f)):(p.current.reset(),m.current=null,S.current=null,C.current=null,w.current=null,g=Nn({detectedPersonCount:n,isTracking:!1,lockedPersonId:null,frameWidth:i,frameHeight:a,updatedAt:s}));else{r&&o&&(p.current.reset(),m.current=null);let t=p.current.smooth(nn(u)),v=d?nn(d):null,y=Yt(t,v),b=t.reduce((e,t)=>e+(t.visibility??0),0)/t.length,x=b>=c?y?ln(m.current,y,Le.rotationAlpha):m.current:null,T=x!==null,E=null;if(w.current=o?En(o):w.current,l){let n=Xt(o?e.segmentationMasks?.[o.poseIndex]:void 0);if(n){let e=ot(new Float32Array(n.getAsFloat32Array()),n.width,n.height,t);e&&(E=Qt(e,i,n.width))}}T&&x?(m.current=x,h={landmarks:t,worldLandmarks:v,poseRig:x,confidence:b,isTracking:T,silhouetteWidths:E},S.current=h,C.current=s,g=Nn({detectedPersonCount:n,isTracking:T,lockedPersonId:$t,meanVisibility:o?.meanVisibility??b,frameWidth:i,frameHeight:a,updatedAt:s})):_?(h=_,g=Ln(n,s,f)):(m.current=null,S.current=null,C.current=null,h={landmarks:t,worldLandmarks:v,poseRig:null,confidence:b,isTracking:!1,silhouetteWidths:E},g=Nn({detectedPersonCount:n,isTracking:!1,lockedPersonId:o?$t:null,meanVisibility:o?.meanVisibility??b,frameWidth:i,frameHeight:a,updatedAt:s}))}let v=b.current;b.current=h,T.current=g;let y=ft(v,h,_t);x.current=y,re(y,g)}finally{Zt(e.segmentationMasks)}}else x.current&&re(x.current,T.current)}catch{}let u=E.current;if(u.frames+=1,u.lastMeasuredAt===0&&(u.lastMeasuredAt=s),s-u.lastMeasuredAt>=1e3){let e=u.frames;u.frames=0,u.lastMeasuredAt=s,M(t=>({...t,fps:e}))}g.current=requestAnimationFrame(t)};return g.current=requestAnimationFrame(t),()=>{g.current!==null&&(cancelAnimationFrame(g.current),g.current=null)}},[r,k,c,l,re,e]);let ae=(0,n.useCallback)(t=>{let n=e.current,r=t.getContext(`2d`);if(!n||!r)return;t.width=n.videoWidth||t.clientWidth||1280,t.height=n.videoHeight||t.clientHeight||720,r.clearRect(0,0,t.width,t.height);let i=h.current;if(!i)return;let a=nn(i),o=new s.DrawingUtils(r);o.drawLandmarks(a,{radius:3,color:`#00FF88`,fillColor:`#00FF88`}),o.drawConnectors(a,s.PoseLandmarker.POSE_CONNECTIONS,{color:`#00C8FF`,lineWidth:2})},[e]);return{...j,isTrackerReady:k,drawLandmarks:ae,silhouetteWidths:ee,poseFrameWidth:P.width,poseFrameHeight:P.height,detectedPersonCount:te.detectedPersonCount,lockedPersonId:te.lockedPersonId,trackingQuality:te.trackingQuality}};function Bn(e){if(!(e instanceof DOMException))return`Failed to start the camera.`;switch(e.name){case`NotAllowedError`:return`Camera permission was denied.`;case`NotFoundError`:return`No available camera was found.`;case`NotReadableError`:return`The camera is already in use by another app.`;case`OverconstrainedError`:return`The requested camera settings are not supported.`;default:return`Failed to start the camera.`}}function Vn(e={}){let{width:t=1280,height:r=720,facingMode:i=`user`,enabled:a=!0,mockMode:o=!1,videoRef:s,onReadyChange:c,onErrorChange:l}=e,u=(0,n.useRef)(null),d=s??u,f=(0,n.useRef)(null),p=(0,n.useRef)(!1),m=(0,n.useRef)(0),[h,g]=(0,n.useState)(!1),[_,v]=(0,n.useState)(null),y=(0,n.useCallback)(e=>{g(e),c?.(e)},[c]),b=(0,n.useCallback)(e=>{v(e),l?.(e)},[l]),x=(0,n.useCallback)(()=>{f.current&&=(f.current.getTracks().forEach(e=>e.stop()),null),d.current&&(d.current.pause(),d.current.srcObject=null),y(!1)},[y,d]),S=(0,n.useCallback)(()=>{m.current+=1,x()},[x]),C=(0,n.useCallback)(()=>{if(d.current)return d.current;let e=document.createElement(`video`);return e.playsInline=!0,e.autoplay=!0,e.muted=!0,e.setAttribute(`playsinline`,`true`),d.current=e,e},[d]),w=(0,n.useCallback)(async()=>{let e=m.current+1;if(m.current=e,x(),b(null),o){C(),y(!0);return}if(!navigator.mediaDevices?.getUserMedia){b(`This browser does not support camera access.`);return}try{let n=C(),a=await navigator.mediaDevices.getUserMedia({video:{width:t,height:r,facingMode:i},audio:!1});if(!p.current||m.current!==e){a.getTracks().forEach(e=>e.stop());return}if(f.current=a,n.srcObject=a,await n.play(),!p.current||m.current!==e){a.getTracks().forEach(e=>e.stop());return}y(!0)}catch(t){if(m.current!==e)return;x(),b(Bn(t))}},[C,i,r,o,b,y,x,t]);return(0,n.useEffect)(()=>(p.current=!0,()=>{p.current=!1,S()}),[S]),(0,n.useEffect)(()=>{if(p.current){if(!a){S();return}w()}},[a,w,S]),{videoRef:d,isReady:h,error:_,start:w,stop:S}}function Hn(e={}){let{width:t=1280,height:r=720,facingMode:i=`user`,enabled:a=!0,mockMode:o=!1,modelComplexity:s=`lite`,numPoses:c,minDetectionConfidence:l,minTrackingConfidence:u,outputSegmentationMasks:d=!0,viewportWidth:f=0,viewportHeight:p=0,measurementEnabled:m=!0,autoStartMeasurement:h=!1,measurementConfig:g,bodyPresetOptions:_,fitType:v=`regular`,garmentScaleHint:y=null}=e,b=Vn({width:t,height:r,facingMode:i,enabled:a,mockMode:o}),x=zn(b.videoRef,{enabled:a,modelComplexity:s,numPoses:c,minDetectionConfidence:l,minTrackingConfidence:u,outputSegmentationMasks:d,viewportWidth:f,viewportHeight:p}),{config:S,measurements:C,sizeRecommendation:w,garmentScale:T,isMeasuring:E,measure:D,startMeasurement:O,updateConfig:k}=et(),A=a&&b.isReady&&x.isTracking,j=Ie(C,_),M=(0,n.useMemo)(()=>he({measurements:C,measurementScale:T,presetSelection:j.selection,fitType:v,garmentScaleHint:y}),[j.selection,v,T,y,C]);return(0,n.useEffect)(()=>{g&&k(g)},[g,k]),(0,n.useEffect)(()=>{!m||!h||!A||C||E||O()},[h,A,m,C,E,O]),(0,n.useEffect)(()=>{!m||!E||!x.landmarks||D(x.landmarks,{silhouetteWidths:x.silhouetteWidths,imageWidth:x.poseFrameWidth||t,imageHeight:x.poseFrameHeight||r})},[r,m,E,D,x.landmarks,x.poseFrameHeight,x.poseFrameWidth,x.silhouetteWidths,t]),{videoRef:b.videoRef,webcamReady:b.isReady,webcamError:b.error,startWebcam:b.start,stopWebcam:b.stop,isTrackerReady:x.isTrackerReady,landmarks:x.landmarks,worldLandmarks:x.worldLandmarks,poseRig:x.poseRig,confidence:x.confidence,fps:x.fps,isTracking:x.isTracking,drawLandmarks:x.drawLandmarks,silhouetteWidths:x.silhouetteWidths,poseFrameWidth:x.poseFrameWidth,poseFrameHeight:x.poseFrameHeight,detectedPersonCount:x.detectedPersonCount,lockedPersonId:x.lockedPersonId,trackingQuality:x.trackingQuality,config:S,measurements:C,sizeRecommendation:w,garmentScale:T,finalGarmentScale:M.scale,bodyMorphResult:M.morph,isMeasuring:E,canMeasure:A,startMeasurement:O,updateConfig:k,bodyPresetSelection:j.selection,bodyPresetLoading:j.loading,bodyPresetError:j.error}}function Un(e){let t=new r.Vector3,n=new r.Quaternion,i=new r.Quaternion;return e.updateWorldMatrix(!0,!1),e.getWorldPosition(t),e.getWorldQuaternion(n),e.parent?e.parent.getWorldQuaternion(i):i.identity(),{bone:e,restQuaternion:e.quaternion.clone(),restScale:e.scale.clone(),restWorldPosition:t,restWorldQuaternion:n,restParentWorldQuaternion:i}}function Wn(e){let t=new r.Box3,n={current:!1},i=new r.Vector3,a=new r.Box3;return e.updateMatrixWorld(!0),e.traverse(e=>{if(!(e instanceof r.Mesh)||e.name.startsWith(`Collision`)||!e.visible)return;let o=e.geometry.getAttribute(`skinIndex`)&&e.geometry.getAttribute(`skinWeight`);if(e instanceof r.SkinnedMesh&&o){if(e.computeBoundingBox(),!e.boundingBox)return;a.copy(e.boundingBox)}else{if(e.geometry.computeBoundingBox(),!e.geometry.boundingBox)return;a.copy(e.geometry.boundingBox)}let{min:s,max:c}=a;[[s.x,s.y,s.z],[s.x,s.y,c.z],[s.x,c.y,s.z],[s.x,c.y,c.z],[c.x,s.y,s.z],[c.x,s.y,c.z],[c.x,c.y,s.z],[c.x,c.y,c.z]].forEach(([r,a,o])=>{if(i.set(r,a,o).applyMatrix4(e.matrixWorld),!n.current){t.min.copy(i),t.max.copy(i),n.current=!0;return}t.expandByPoint(i)})}),n.current||t.makeEmpty(),t}function Gn(e){if(!e||e.length===0)return null;let t=new r.Vector3,n=new r.Vector3;return e.forEach(({bone:e})=>{e.getWorldPosition(n),t.add(n)}),t.multiplyScalar(1/e.length)}function Kn(e,t){for(let n=0;n<t.length;n+=1){let r=Gn(e.get(t[n]));if(r)return r}return null}function qn(e,t,n=1){e.updateMatrixWorld(!0);let i=Wn(e),a=i.getCenter(new r.Vector3),o=i.getSize(new r.Vector3),s=new r.Vector3(a.x,i.min.y+o.y*.74,a.z),c=new r.Vector3(a.x,i.min.y+o.y*.42,a.z),l=Kn(t,[`LeftUpperArm`,`LeftShoulder`]),u=Kn(t,[`RightUpperArm`,`RightShoulder`]),d=Kn(t,[`Hips`]),f=Kn(t,[`LeftUpperLeg`]),p=Kn(t,[`RightUpperLeg`]),m=l??s.clone().setX(a.x+o.x*.18),h=u??s.clone().setX(a.x-o.x*.18),g=d??c,_=m.clone().add(h).multiplyScalar(.5),v=f&&p?f.clone().add(p).multiplyScalar(.5):g.clone(),y=!!(l&&u),b=y&&!!(d||f&&p),x=m.distanceTo(h),S=_.distanceTo(v),C=y?Math.max(x,1e-4):Math.max(x,o.x*.3,n),w=b?Math.max(S,1e-4):Math.max(S,o.y*.28,1e-4),T=b?_.clone().add(v).multiplyScalar(.5):a.clone(),E=i.clone();if(b){let e=Math.min(_.y,v.y),t=Math.max(_.y,v.y);E.min.y=Math.max(E.min.y,e),E.max.y=Math.min(E.max.y,t),E.max.y<=E.min.y&&E.copy(i)}let D=E.getCenter(new r.Vector3),O=E.getSize(new r.Vector3);return{anchor:T,shoulderCenter:_,hipCenter:v,referenceWidth:C,referenceTorsoHeight:w,trackingHeight:Math.max(o.y,w,1e-4),boundsCenter:D,boundsSize:O,hasBoneAnchors:b}}function Jn(e){for(let t of e.values())t.forEach(({bone:e,restQuaternion:t,restScale:n})=>{e.quaternion.copy(t),e.scale.copy(n)})}var Yn=`__nativeVRMPrepared`;function Xn(e){try{return new URL(e,`https://avatar.local`).pathname}catch{return e}}function Zn(e){return Xn(e).toLowerCase().endsWith(`.vrm`)}function Qn(e){return Zn(e)?`vrm`:`gltf`}function $n(e,t){Zn(t)&&e.register(e=>new l.VRMLoaderPlugin(e))}function er(e){if(Zn(e))return t=>{$n(t,e)}}function tr(e){e.traverse(e=>{e.frustumCulled=!1})}function nr(e){let t=e.scene.userData;t[Yn]||(l.VRMUtils.rotateVRM0(e),t[Yn]=!0),tr(e.scene)}var rr={Hips:[`hips`],Spine:[`spine`],Chest:[`chest`,`upperChest`],Neck:[`neck`],Head:[`head`],LeftShoulder:[`leftShoulder`],LeftUpperArm:[`leftUpperArm`],LeftLowerArm:[`leftLowerArm`],LeftHand:[`leftHand`],RightShoulder:[`rightShoulder`],RightUpperArm:[`rightUpperArm`],RightLowerArm:[`rightLowerArm`],RightHand:[`rightHand`],LeftUpperLeg:[`leftUpperLeg`],LeftLowerLeg:[`leftLowerLeg`],LeftFoot:[`leftFoot`],RightUpperLeg:[`rightUpperLeg`],RightLowerLeg:[`rightLowerLeg`],RightFoot:[`rightFoot`]};function ir(e){let t=new Map;return Object.entries(rr).forEach(([n,r])=>{for(let i=0;i<r.length;i+=1){let a=e.getNormalizedBoneNode(r[i]);if(a){t.set(n,[Un(a)]);break}}}),t}var ar={root:`hips`,c_spine0:`spine`,c_spine1:`spine`,c_spine2:`chest`,c_spine3:`upperChest`,c_neck:`neck`,c_head:`head`,l_clavicle:`leftShoulder`,l_uparm:`leftUpperArm`,l_lowarm:`leftLowerArm`,l_wrist:`leftHand`,r_clavicle:`rightShoulder`,r_uparm:`rightUpperArm`,r_lowarm:`rightLowerArm`,r_wrist:`rightHand`,l_upleg:`leftUpperLeg`,l_lowleg:`leftLowerLeg`,l_foot:`leftFoot`,r_upleg:`rightUpperLeg`,r_lowleg:`rightLowerLeg`,r_foot:`rightFoot`},or={bone_0:`hips`,bone_1:`spine`,bone_2:`chest`,bone_3:`upperChest`,bone_4:`neck`,bone_5:`head`,bone_6:`leftShoulder`,bone_7:`leftUpperArm`,bone_8:`leftLowerArm`,bone_9:`leftHand`,bone_25:`rightShoulder`,bone_26:`rightUpperArm`,bone_27:`rightLowerArm`,bone_28:`rightHand`,bone_44:`leftUpperLeg`,bone_45:`leftLowerLeg`,bone_46:`leftFoot`,bone_48:`rightUpperLeg`,bone_49:`rightLowerLeg`,bone_50:`rightFoot`},sr={Root:`hips`,Hips:`hips`,Spine:`spine`,Chest:`chest`,Neck:`neck`,Head:`head`,LeftShoulder:`leftShoulder`,LeftUpperArm:`leftUpperArm`,LeftLowerArm:`leftLowerArm`,LeftHand:`leftHand`,RightShoulder:`rightShoulder`,RightUpperArm:`rightUpperArm`,RightLowerArm:`rightLowerArm`,RightHand:`rightHand`,LeftUpperLeg:`leftUpperLeg`,LeftLowerLeg:`leftLowerLeg`,LeftFoot:`leftFoot`,RightUpperLeg:`rightUpperLeg`,RightLowerLeg:`rightLowerLeg`,RightFoot:`rightFoot`};function cr(e,t){if(t?.humanoid)return{getNormalizedBoneNode:e=>t.humanoid.getNormalizedBoneNode(e)??null,update:e=>t.update(e),vrm:t};let n=new Map;return e.traverse(e=>{if(!(e instanceof r.Bone))return;let t=e.name,i=ar[t];i&&!n.has(i)&&n.set(i,e);let a=sr[t];a&&!n.has(a)&&n.set(a,e);let o=or[t];o&&!n.has(o)&&n.set(o,e)}),{getNormalizedBoneNode:e=>n.get(e)??null,update:()=>{},vrm:null}}function lr(e){let t=(0,c.clone)(e);return tr(t),t.traverse(e=>{if(e instanceof r.Mesh){if(Array.isArray(e.material)){e.material=e.material.map(e=>e.clone());return}e.material=e.material.clone()}}),t}function ur({url:e}){let t=(0,o.useGLTF)(e,`/draco/`,!0,(0,n.useMemo)(()=>er(e),[e])),r=t.userData?.vrm??null,i=(0,n.useMemo)(()=>r?(nr(r),r.scene):lr(t.scene),[t.scene,r]),a=(0,n.useMemo)(()=>cr(i,r),[i,r]);return{scene:i,humanoid:a,bones:(0,n.useMemo)(()=>ir(a),[a])}}var q=Math.PI/180,dr={min:-70*q,max:70*q},fr={min:-45*q,max:45*q},pr={min:-150*q,max:150*q},mr={min:-90*q,max:90*q},hr={min:0,max:150*q},gr={Hips:{rigKey:`hips`,rotationScale:{x:.7,y:.3,z:.7}},Spine:{rigKey:`spine`,rotationScale:{x:.85,y:.4,z:.85}},Chest:{rigKey:`chest`,rotationScale:{x:.75,y:.35,z:.75}},Neck:{rigKey:null},Head:{rigKey:null},LeftShoulder:{rigKey:`leftUpperArm`,rotationScale:.45,rotationLimits:{x:dr,z:fr}},LeftUpperArm:{rigKey:`leftUpperArm`,rotationScale:1,rotationLimits:{x:pr,z:mr}},LeftLowerArm:{rigKey:`leftLowerArm`,rotationScale:1,rotationLimits:{x:hr}},LeftHand:{rigKey:`leftLowerArm`,rotationScale:.5},RightShoulder:{rigKey:`rightUpperArm`,rotationScale:.45,rotationLimits:{x:dr,z:fr}},RightUpperArm:{rigKey:`rightUpperArm`,rotationScale:1,rotationLimits:{x:pr,z:mr}},RightLowerArm:{rigKey:`rightLowerArm`,rotationScale:1,rotationLimits:{x:hr}},RightHand:{rigKey:`rightLowerArm`,rotationScale:.5},LeftUpperLeg:{rigKey:`leftUpperLeg`,rotationScale:.9},LeftLowerLeg:{rigKey:`leftLowerLeg`,rotationScale:.9},LeftFoot:{rigKey:null},RightUpperLeg:{rigKey:`rightUpperLeg`,rotationScale:.9},RightLowerLeg:{rigKey:`rightLowerLeg`,rotationScale:.9},RightFoot:{rigKey:null}},_r={Root:`Hips`,root:`Hips`,c_spine0:`Spine`,c_spine1:`Spine`,c_spine2:`Chest`,c_spine3:`Chest`,c_neck:`Neck`,c_head:`Head`,l_clavicle:`LeftShoulder`,l_uparm:`LeftUpperArm`,l_lowarm:`LeftLowerArm`,l_wrist:`LeftHand`,r_clavicle:`RightShoulder`,r_uparm:`RightUpperArm`,r_lowarm:`RightLowerArm`,r_wrist:`RightHand`,l_upleg:`LeftUpperLeg`,l_lowleg:`LeftLowerLeg`,l_foot:`LeftFoot`,r_upleg:`RightUpperLeg`,r_lowleg:`RightLowerLeg`,r_foot:`RightFoot`,mixamorig_Hips:`Hips`,mixamorig_Spine:`Spine`,mixamorig_Spine1:`Chest`,mixamorig_Neck:`Neck`,mixamorig_Head:`Head`,mixamorig_LeftShoulder:`LeftShoulder`,mixamorig_LeftArm:`LeftUpperArm`,mixamorig_LeftForeArm:`LeftLowerArm`,mixamorig_LeftHand:`LeftHand`,mixamorig_RightShoulder:`RightShoulder`,mixamorig_RightArm:`RightUpperArm`,mixamorig_RightForeArm:`RightLowerArm`,mixamorig_RightHand:`RightHand`,mixamorig_LeftUpLeg:`LeftUpperLeg`,mixamorig_LeftLeg:`LeftLowerLeg`,mixamorig_LeftFoot:`LeftFoot`,mixamorig_RightUpLeg:`RightUpperLeg`,mixamorig_RightLeg:`RightLowerLeg`,mixamorig_RightFoot:`RightFoot`};function vr(e){return gr[e]?e:_r[e]??e}function yr(e,t){let n=gr[vr(e)];if(!n||!n.rigKey)return null;let r=t[n.rigKey];if(!r)return null;let i=br(n.rigKey===`hips`&&`rotation`in r?r.rotation:r,n.rotationScale);return{x:xr(i.x,n.rotationLimits?.x),y:xr(i.y,n.rotationLimits?.y),z:xr(i.z,n.rotationLimits?.z)}}function br(e,t=1){return typeof t==`number`?{x:e.x*t,y:e.y*t,z:e.z*t}:{x:e.x*(t.x??1),y:e.y*(t.y??1),z:e.z*(t.z??1)}}function xr(e,t){return t?Math.min(t.max,Math.max(t.min,e)):e}var Sr=12,Cr=new r.Quaternion,J=new r.Quaternion,wr=new r.Quaternion,Tr=new r.Vector3,Er=new r.Vector3,Y=new r.Vector3,Dr=new r.Vector3,Or=new r.Vector3,kr=new r.Vector3,Ar=new r.Vector3,jr=new r.Vector3,Mr=new r.Vector3,Nr=new r.Quaternion,Pr=new r.Quaternion,Fr=new r.Quaternion,Ir=new r.Quaternion,Lr={Hips:[`Spine`,`Chest`,`Neck`],Spine:[`Chest`,`Neck`],Chest:[`Neck`,`Head`],Neck:[`Head`],LeftShoulder:[`LeftUpperArm`],LeftUpperArm:[`LeftLowerArm`],LeftLowerArm:[`LeftHand`],RightShoulder:[`RightUpperArm`],RightUpperArm:[`RightLowerArm`],RightLowerArm:[`RightHand`],LeftUpperLeg:[`LeftLowerLeg`],LeftLowerLeg:[`LeftFoot`],RightUpperLeg:[`RightLowerLeg`],RightLowerLeg:[`RightFoot`]},Rr={Hips:[[`LeftUpperLeg`,`RightUpperLeg`],[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`]],Spine:[[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`],[`LeftUpperLeg`,`RightUpperLeg`]],Chest:[[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`],[`LeftUpperLeg`,`RightUpperLeg`]]},zr={Hips:[z.RIGHT_HIP,z.LEFT_HIP],Spine:[z.RIGHT_SHOULDER,z.LEFT_SHOULDER],Chest:[z.RIGHT_SHOULDER,z.LEFT_SHOULDER]};function Br(e){return e.startsWith(`Left`)?`Right${e.slice(4)}`:e.startsWith(`Right`)?`Left${e.slice(5)}`:e}function Vr(e,t,n,r){let i=Lr[e];if(!i)return!1;for(let e=0;e<i.length;e+=1){let a=n.get(i[e])?.[0];if(!(!a||a.bone===t.bone||!t.restWorldPosition||!t.restParentWorldQuaternion||!a.restWorldPosition)&&(r.copy(a.restWorldPosition).sub(t.restWorldPosition),!(r.lengthSq()<1e-6)))return r.applyQuaternion(Nr.copy(t.restParentWorldQuaternion).invert()).normalize(),!0}return!1}function Hr(e){return e in Rr}function Ur(e,t,n,r){let i=Rr[e];if(!i||!t.restParentWorldQuaternion)return!1;for(let e=0;e<i.length;e+=1){let[a,o]=i[e],s=n.get(a)?.[0],c=n.get(o)?.[0];if(!(!s?.restWorldPosition||!c?.restWorldPosition)&&(r.copy(c.restWorldPosition).sub(s.restWorldPosition).applyQuaternion(Nr.copy(t.restParentWorldQuaternion).invert()),!(r.lengthSq()<1e-6)))return r.normalize(),!0}return!1}function Wr(e,t,n,r,i){let a=zr[e];return!a||!Rt(a[0],a[1],t,i,n)?!1:(i.applyQuaternion(Fr.copy(r).invert()).normalize(),i.lengthSq()>=1e-6)}function Gr(e,t,n,r,i,a,o,s){if(!Ur(e,t,n,Dr)||!Wr(e,r,i,a,Or)||(kr.copy(Dr).applyQuaternion(J),Ar.copy(kr).projectOnPlane(Y).normalize(),jr.copy(Or).projectOnPlane(Y).normalize(),Ar.lengthSq()<1e-6||jr.lengthSq()<1e-6))return s.copy(J),!1;Mr.crossVectors(Ar,jr);let c=Math.atan2(Y.dot(Mr),Ar.dot(jr));return Ir.setFromAxisAngle(Y,c),s.copy(Ir).multiply(J),o!==void 0&&s.slerp(wr,1-o),!0}function Kr(){let e=(0,n.useRef)(new r.Timer),t=(0,n.useRef)(new Map);return(0,n.useMemo)(()=>({clockRef:e,prevRotationsRef:t}),[])}function qr(e,t,n,r={}){if(t.size===0)return;let{coordinateSpace:i=`normalized`,excludeBones:a}=r;n.clockRef.current.update();let o=n.clockRef.current.getDelta(),s=Math.min(1,o*Sr);for(let[n,r]of t){let o=vr(n);if(a?.has(o))continue;let c=Br(o);if(o!==n&&t.has(o))continue;let l=Ht(c);if(!l)continue;let u=l&&zt(c,e,Tr,i);if(!u)continue;let d=!1,f=Bt(c);for(let n of r){let{bone:r,restQuaternion:a}=n;if(u&&Vr(o,n,t,Er))r.parent?(r.parent.updateWorldMatrix(!0,!1),r.parent.getWorldQuaternion(Pr)):(r.updateWorldMatrix(!0,!1),Pr.identity()),Y.copy(Tr).applyQuaternion(Fr.copy(Pr).invert()).normalize(),J.setFromUnitVectors(Er,Y),Hr(o)&&Gr(o,n,t,e,i,Pr,f,J)||f!==void 0&&J.slerp(wr,1-f),Cr.copy(J).multiply(a);else{if(d||=Vt(c,e,J,i),!d)continue;Cr.copy(a).multiply(J)}r.quaternion.slerp(Cr,s),r.updateWorldMatrix(!1,!0)}}}function Jr(e,t){Jn(e),t.prevRotationsRef.current.clear()}function Yr(e,t,n,r){let i=Math.min(1,n*Sr);for(let[n,a]of e){let e=vr(n);if(!(r&&!r.has(e)))for(let{bone:e,restQuaternion:n}of a)e.quaternion.slerp(n,t*i)}}var Xr=50*Math.PI/180,Zr=30*Math.PI/180,Qr=3;function $r(e){return Math.abs(e)<Xr?`unknown`:e>=0?`positive`:`negative`}function ei(e){return e===`positive`?1:e===`negative`?-1:0}var ti=class{_committedYawDirection=`unknown`;_pendingYawDirection=`unknown`;_pendingCount=0;update(e,t){let n=Math.abs(t),r=$r(t);return e===`back`||n<Zr?(this.reset(),this._buildState(r,`unknown`,t)):this._committedYawDirection===`unknown`?r===`unknown`?(this._clearPending(),this._buildState(r,`unknown`,t)):(this._pendingYawDirection===r?this._pendingCount+=1:(this._pendingYawDirection=r,this._pendingCount=1),this._pendingCount>=Qr?(this._committedYawDirection=this._pendingYawDirection,this._clearPending(),this._buildState(r,this._committedYawDirection,n*ei(this._committedYawDirection))):this._buildState(r,r,t)):this._buildState(r,this._committedYawDirection,n*ei(this._committedYawDirection))}reset(){this._committedYawDirection=`unknown`,this._clearPending()}_buildState(e,t,n){return{rawYawDirection:e,yawDirection:t,committedYawDirection:this._committedYawDirection,pendingYawDirection:this._pendingYawDirection,pendingCount:this._pendingCount,stableYaw:n}}_clearPending(){this._pendingYawDirection=`unknown`,this._pendingCount=0}},ni=80*Math.PI/180,ri=100*Math.PI/180,ii=25*Math.PI/180,ai=8,oi=5,si=5,ci=5,li=.5,ui=.3,di=.2,fi=5,pi=8;function mi(e){return e?.visibility??0}function hi(e){if(!e||e.length<33)return{shoulderOrder:!1,noseVisible:!1,earSymmetry:!1};let t=e[z.LEFT_SHOULDER],n=e[z.RIGHT_SHOULDER],r=e[z.NOSE],i=e[z.LEFT_EAR],a=e[z.RIGHT_EAR],o=t.x<n.x,s=mi(r)>li,c=mi(i),l=mi(a);return{shoulderOrder:o,noseVisible:s,earSymmetry:Math.abs(c-l)<ui&&Math.max(c,l)>di}}function gi(e){let t=0;return e.shoulderOrder&&(t+=1),e.noseVisible&&(t+=1),e.earSymmetry&&(t+=1),t>=2}function _i(e){return e<ni?`front`:e<ri?`side`:`back`}var vi=class{_zone=`front`;_consecutiveCount=0;_lastRawZone=`front`;_2dFrontCount=0;_2dBackCount=0;_2dIsFront=!0;_yawDirectionStabilizer=new ti;update(e,t,n){let r=t??0,i=n??0,a=Math.abs(i)>ii,o;t===void 0?o=this._resolve2dFallback(e):(o=_i(Math.abs(t)),o===`front`&&this._zone!==`front`&&(gi(hi(e))||(o=`back`))),this._applyHysteresis(o);let s=t===void 0?null:this._yawDirectionStabilizer.update(this._zone,r);return t===void 0&&this._yawDirectionStabilizer.reset(),{zone:this._zone,rawZone:o,isFrontFacing:this._zone===`front`,pitchClamped:a,bodyYaw:s?.stableYaw??r,bodyPitch:i,rawYawDirection:s?.rawYawDirection??`unknown`,yawDirection:s?.yawDirection??`unknown`,committedYawDirection:s?.committedYawDirection??`unknown`}}reset(){this._zone=`front`,this._consecutiveCount=0,this._lastRawZone=`front`,this._2dFrontCount=0,this._2dBackCount=0,this._2dIsFront=!0,this._yawDirectionStabilizer.reset()}_resolve2dFallback(e){return gi(hi(e))?(this._2dFrontCount+=1,this._2dBackCount=0):(this._2dBackCount+=1,this._2dFrontCount=0),this._2dIsFront?this._2dBackCount>=fi&&(this._2dIsFront=!1):this._2dFrontCount>=pi&&(this._2dIsFront=!0),this._2dIsFront?`front`:`back`}_applyHysteresis(e){e===this._lastRawZone?this._consecutiveCount+=1:(this._lastRawZone=e,this._consecutiveCount=1);let t=this._getTransitionThreshold(this._zone,e);t!==null&&this._consecutiveCount>=t&&(this._zone=e)}_getTransitionThreshold(e,t){return e===t?null:e===`front`&&t===`side`||e===`front`&&t===`back`?ai:e===`side`&&t===`back`?oi:e===`back`&&t===`side`?si:e===`side`&&t===`front`?ci:e===`back`&&t===`front`?si:ai}},yi=Math.PI/2;function bi(e){return e>=0?yi:-yi}var xi=class{_isFrozen=!1;_frozenYaw=null;update(e,t,n){let r=Math.abs(t);return this._isFrozen?e!==`back`&&r<yi&&this.reset():e!==`front`&&r>=yi&&(this._isFrozen=!0,this._frozenYaw=bi(t)),{isFrozen:this._isFrozen,frozenYaw:this._frozenYaw}}reset(){this._isFrozen=!1,this._frozenYaw=null}};function Si(e,t){return typeof e==`boolean`?{mirrorX:e,sourceWidth:0,sourceHeight:0,target:t??new r.Vector3}:{mirrorX:e.mirrorX??!1,sourceWidth:e.sourceWidth??0,sourceHeight:e.sourceHeight??0,target:e.target??t??new r.Vector3}}function X(e,t,n,r=!1,i){let a=Si(r,i),o=tt(t,n,a.sourceWidth||t,a.sourceHeight||n),s=a.mirrorX?1-e.x:e.x,c=o.x+s*o.width,l=o.y+e.y*o.height,u=c-t*.5,d=n*.5-l,f=-(e.z??0)*o.width*.5;return a.target.set(u,d,f)}var Ci=.45,wi=.72,Ti=1.02,Ei=1.1,Di=1e-4,Oi=Di*Di,ki=.35,Ai=.6,ji=new r.Vector3,Mi=new r.Vector3,Z=new r.Vector3,Q=new r.Vector3,Ni=new r.Vector3,Pi=new r.Vector3,Fi=new r.Matrix4;function Ii(e,t,n){let r=Math.min(Math.abs(n),Ei),i=1/Math.max(Math.cos(r),Ci)*e,a=t*wi;return Math.max(i,a,e)}function Li({projectedShoulderWidth:e,projectedTorsoHeight:t,bodyYaw:n,worldLandmarks:r}){let i=Ii(e,t,n),a=zi(t,r);if(!a)return i;let o=Hi((Math.abs(n)-ki)/Ai,0,1);return i+(Math.max(i,a)-i)*o}function Ri({leftShoulder:e,rightShoulder:t,leftHip:n,rightHip:i},a=new r.Quaternion){return ji.copy(e).add(t).multiplyScalar(.5),Mi.copy(n).add(i).multiplyScalar(.5),Z.copy(t).sub(e),Z.lengthSq()<=Oi||(Z.normalize(),Q.copy(ji).sub(Mi),Ni.copy(Z).multiplyScalar(Q.dot(Z)),Q.sub(Ni),Q.lengthSq()<=Oi)||(Q.normalize(),Pi.crossVectors(Z,Q),Pi.lengthSq()<=Oi)?null:(Pi.normalize(),Q.crossVectors(Pi,Z).normalize(),Fi.makeBasis(Z,Q,Pi),a.setFromRotationMatrix(Fi))}function zi(e,t){if(!t||t.length<=z.RIGHT_HIP||e<=Di)return null;let n=t[z.LEFT_SHOULDER],r=t[z.RIGHT_SHOULDER],i=t[z.LEFT_HIP],a=t[z.RIGHT_HIP];if(!n||!r||!i||!a)return null;let o=Vi(n,r),s=Vi(Bi(n,r),Bi(i,a));return o<=Di||s<=Di?null:e*Hi(o/s,wi,Ti)}function Bi(e,t){return{x:(e.x+t.x)*.5,y:(e.y+t.y)*.5,z:((e.z??0)+(t.z??0))*.5}}function Vi(e,t){let n=e.x-t.x,r=e.y-t.y,i=(e.z??0)-(t.z??0);return Math.sqrt(n*n+r*r+i*i)}function Hi(e,t,n){return Math.max(t,Math.min(n,e))}var $=1e-4,Ui=.15,Wi=8,Gi=1e-4,Ki=1.45,qi=.35,Ji=10,Yi=.18,Xi=.55,Zi=6,Qi=.3,$i=.08,ea=.05,ta=1.35,na=.7,ra=new r.Quaternion,ia=new r.Vector3,aa=[[z.LEFT_EAR,z.RIGHT_EAR],z.NOSE,[z.LEFT_SHOULDER,z.RIGHT_SHOULDER]],oa=[[z.LEFT_ANKLE,z.RIGHT_ANKLE],[z.LEFT_HEEL,z.RIGHT_HEEL],[z.LEFT_FOOT_INDEX,z.RIGHT_FOOT_INDEX]];function sa(e,t,n){return Math.max(t,Math.min(n,e))}function ca(){return{leftShoulder:new r.Vector3,rightShoulder:new r.Vector3,leftHip:new r.Vector3,rightHip:new r.Vector3,shoulderCenter:new r.Vector3,hipCenter:new r.Vector3,bodyTop:new r.Vector3,bodyBottom:new r.Vector3,anchor:new r.Vector3,scaledAnchor:new r.Vector3,position:new r.Vector3,scale:new r.Vector3(1,1,1),stabilizedBodyHeightScale:null,missingBodyHeightFrames:0,smoothedGlobalScale:1,hasSmoothedGlobalScale:!1,effectiveYaw:0,previousDepthProxy:0,scaleVelocity:0,smoothedXDeviation:1,smoothedAnchor:new r.Vector3,hasSmoothedAnchor:!1}}function la(e,t,n,i,a,o={}){if(t.length<33)return!1;X(t[z.LEFT_SHOULDER],n,i,{mirrorX:!0,sourceWidth:o.sourceWidth,sourceHeight:o.sourceHeight,target:a.leftShoulder}),X(t[z.RIGHT_SHOULDER],n,i,{mirrorX:!0,sourceWidth:o.sourceWidth,sourceHeight:o.sourceHeight,target:a.rightShoulder}),X(t[z.LEFT_HIP],n,i,{mirrorX:!0,sourceWidth:o.sourceWidth,sourceHeight:o.sourceHeight,target:a.leftHip}),X(t[z.RIGHT_HIP],n,i,{mirrorX:!0,sourceWidth:o.sourceWidth,sourceHeight:o.sourceHeight,target:a.rightHip}),a.shoulderCenter.copy(a.leftShoulder).add(a.rightShoulder).multiplyScalar(.5),a.hipCenter.copy(a.leftHip).add(a.rightHip).multiplyScalar(.5);let s=Ri({leftShoulder:a.rightShoulder,rightShoulder:a.leftShoulder,leftHip:a.rightHip,rightHip:a.leftHip},ra),c=s?ua(s):0,l=pa(o.bodyYaw,c);a.effectiveYaw=l;let u=ha(a.leftShoulder,a.rightShoulder),d=ha(a.shoulderCenter,a.hipCenter),f=Li({projectedShoulderWidth:u,projectedTorsoHeight:d,bodyYaw:l,worldLandmarks:o.worldLandmarks}),p=d/Math.max(e.referenceTorsoHeight,$),m=ma(t,n,i,d,a,o),h=da(m===null?null:m/Math.max(e.trackingHeight,$),a),g=h!==null&&p>$?sa(h,p*na,p*ta):h,_=fa(sa(g===null?p:p*.55+g*.45,Ui,Wi)*(o.scaleMultiplier??1),a,d),v=.1,y=e.referenceWidth/Math.max(e.referenceTorsoHeight,$),b=d>$?f/d:y,x=sa(y>$?b/y:1,1-v,1+v);return a.smoothedXDeviation=r.MathUtils.lerp(a.smoothedXDeviation,x,.35),a.scale.set(_*a.smoothedXDeviation*(o.scaleX??1),_*(o.scaleY??1),_*(o.scaleZ??1)),a.anchor.copy(a.shoulderCenter).add(a.hipCenter).multiplyScalar(.5),a.hasSmoothedAnchor?a.smoothedAnchor.lerp(a.anchor,.4):(a.smoothedAnchor.copy(a.anchor),a.hasSmoothedAnchor=!0),a.scaledAnchor.set(e.anchor.x*_,e.anchor.y*_,e.anchor.z*_),a.position.copy(a.smoothedAnchor).sub(a.scaledAnchor),a.position.z+=o.depthOffset??0,!0}function ua(e){return ia.set(0,0,1).applyQuaternion(e),ia.y=0,ia.lengthSq()<=Gi?0:(ia.normalize(),Math.atan2(ia.x,ia.z))}function da(e,t){return e===null?t.stabilizedBodyHeightScale===null?(t.missingBodyHeightFrames=0,null):(t.missingBodyHeightFrames+=1,t.missingBodyHeightFrames>Ji?(t.stabilizedBodyHeightScale=null,null):t.stabilizedBodyHeightScale):(t.missingBodyHeightFrames=0,t.stabilizedBodyHeightScale=t.stabilizedBodyHeightScale===null?e:r.MathUtils.lerp(t.stabilizedBodyHeightScale,e,qi),t.stabilizedBodyHeightScale)}function fa(e,t,n){if(!t.hasSmoothedGlobalScale)return t.smoothedGlobalScale=e,t.previousDepthProxy=n,t.scaleVelocity=0,t.hasSmoothedGlobalScale=!0,e;let i=t.previousDepthProxy,a=1;i>ea&&n>ea&&(a=sa(n/i,1-$i,1+$i)),t.previousDepthProxy=n;let o=t.smoothedGlobalScale*a,s=o>0?Math.abs(e-o)/o:0;t.scaleVelocity=r.MathUtils.lerp(t.scaleVelocity,s,Qi);let c=sa(Yi+t.scaleVelocity*Zi,Yi,Xi);return t.smoothedGlobalScale=r.MathUtils.lerp(o,e,c),t.smoothedGlobalScale}function pa(e,t){let n=e??0;return Math.abs(n)>=Math.abs(t)?n:t}function ma(e,t,n,r,i,a){let o=ga(aa,e,t,n,i.bodyTop,a),s=ga(oa,e,t,n,i.bodyBottom,a);if(!o||!s)return null;let c=ha(i.bodyTop,i.bodyBottom);return c<=r*Ki?null:c}function ha(e,t){let n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function ga(e,t,n,r,i,a){for(let o=0;o<e.length;o+=1)if(_a(e[o],t,n,r,i,a))return!0;return!1}function _a(e,t,n,r,i,a){if(typeof e==`number`){let o=t[e];return!o||(o.visibility??0)<.4?!1:(X(o,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i}),!0)}let o=t[e[0]],s=t[e[1]];if(!o||!s||(o.visibility??0)<.4||(s.visibility??0)<.4)return!1;X(o,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i});let c=X(s,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight});return i.add(c).multiplyScalar(.5),!0}var va=new r.Vector3(0,1,0),ya=new Set([`LeftHand`,`RightHand`]),ba=new Set([`Hips`,`Spine`,`Chest`]),xa=20,Sa=.436,Ca=.175,wa=1.396,Ta=.349,Ea=.35;function Da(e,t,n){return Math.max(t,Math.min(n,e))}function Oa(e){let t=e;for(;t<=-Math.PI;)t+=Math.PI*2;for(;t>Math.PI;)t-=Math.PI*2;return t}function ka(e,t,n){let r=Oa(t-e);return Oa(Math.abs(r)<=n?t:e+Math.sign(r)*n)}function Aa(){return{transformScratch:ca(),facingDetector:new vi,yawFreezeController:new xi,displayYaw:null,lastFacingState:null,hasInitialPosition:!1}}function ja(e){e.transformScratch=ca(),e.facingDetector.reset(),e.yawFreezeController.reset(),e.displayYaw=null,e.lastFacingState=null,e.hasInitialPosition=!1}function Ma({fitProfile:e,garmentRoot:t,boneBindingMap:n,poseRefs:r,motionState:i,landmarks:a,worldLandmarks:o=null,viewportWidth:s,viewportHeight:c,poseFrameWidth:l,poseFrameHeight:u,delta:d}){if(!a||a.length<33)return null;let f=i.transformScratch;la(e,a,s,c,f,{sourceWidth:l,sourceHeight:u,worldLandmarks:o});let p=f.shoulderCenter.y-f.hipCenter.y,m=f.shoulderCenter.distanceTo(f.hipCenter),h=Math.acos(Da(Math.abs(p)/Math.max(m,.001),0,1)),g=f.effectiveYaw,_=g>0?g-Math.PI:g+Math.PI,v=i.facingDetector.update(a,_,h),y=v.bodyYaw,b=i.displayYaw===null?y:ka(i.displayYaw,y,xa*d),x=i.yawFreezeController.update(v.zone,y,b),S=x.isFrozen,C=S?x.frozenYaw??b:b;return i.displayYaw=C,i.lastFacingState=v,v.zone!==`back`&&(S||(t.scale.copy(f.scale),i.hasInitialPosition?t.position.lerp(f.position,Ea):(t.position.copy(f.position),i.hasInitialPosition=!0)),t.quaternion.setFromAxisAngle(va,C)),v.zone===`front`&&!S?(qr(a,n,r,{coordinateSpace:`normalized`,excludeBones:ya}),v.pitchClamped&&Yr(n,Da((Math.abs(h)-Sa)/Ca,0,1),d,ba)):v.zone===`side`&&!S&&(qr(a,n,r,{coordinateSpace:`normalized`,excludeBones:ya}),Yr(n,Da((Math.abs(y)-wa)/Ta,0,1),d)),v}function Na({garmentRootRef:e,boneBindingMap:t,fitProfile:r,landmarks:i,worldLandmarks:o,poseFrameWidth:s,poseFrameHeight:c}){let{viewport:l}=(0,a.useThree)(),u=Kr(),d=(0,n.useRef)(Aa());return(0,n.useEffect)(()=>{let n=e.current,r=d.current;return n&&(n.position.set(0,0,0),n.scale.set(1,1,1),n.quaternion.identity()),Jr(t,u),ja(r),()=>{Jr(t,u),ja(r)}},[t,r,e,u]),(0,a.useFrame)((n,a)=>{let f=e.current;!f||!r||Ma({fitProfile:r,garmentRoot:f,boneBindingMap:t,poseRefs:u,motionState:d.current,landmarks:i,worldLandmarks:o,viewportWidth:l.width,viewportHeight:l.height,poseFrameWidth:s,poseFrameHeight:c,delta:a})}),null}function Pa(e){return e?e.map(e=>({x:e.x,y:e.y,z:e.z,visibility:typeof e.visibility==`number`?e.visibility:0})):null}function Fa({url:e,landmarks:t,worldLandmarks:a,poseFrameWidth:o,poseFrameHeight:s,debugMaterials:c=!1,onLoadStateChange:l}){let u=(0,n.useRef)(null),{scene:d,bones:f}=ur({url:e}),p=(0,n.useMemo)(()=>Pa(t),[t]),m=(0,n.useMemo)(()=>Pa(a),[a]),h=(0,n.useMemo)(()=>(d.updateMatrixWorld(!0),qn(d,f,1)),[f,d]);return(0,n.useEffect)(()=>{d.traverse(e=>{if(e instanceof r.Mesh){if(e.name.startsWith(`Collision`)){e.visible=!1;return}e.visible=!0,(Array.isArray(e.material)?e.material:[e.material]).forEach(e=>{`opacity`in e&&(c?(e.transparent=!0,e.opacity=.34,e.depthWrite=!1,e.side=r.DoubleSide):(e.transparent=!1,e.opacity=1,e.depthWrite=!0,e.side=r.FrontSide),e.needsUpdate=!0)})}})},[d,c]),(0,n.useEffect)(()=>(l?.({loaded:!0,error:null}),()=>{l?.({loaded:!1,error:null})}),[l,e]),(0,i.jsxs)(`group`,{ref:u,children:[(0,i.jsx)(`primitive`,{object:d}),(0,i.jsx)(Na,{garmentRootRef:u,boneBindingMap:f,fitProfile:h,landmarks:p,worldLandmarks:m,poseFrameWidth:o,poseFrameHeight:s})]})}var Ia=1;function La(e){let t=new r.VideoTexture(e);return t.minFilter=r.NearestFilter,t.magFilter=r.NearestFilter,t.generateMipmaps=!1,t.colorSpace=r.SRGBColorSpace,t.needsUpdate=!0,t}function Ra(e,t,n){if(!n||n.width===0||n.height===0)return[e,t];let r=e/t,i=n.width/n.height;return r>i?[e,e/i]:[t*i,t]}function za({videoRef:e,webcamReady:t}){let{viewport:r}=(0,a.useThree)(),[o,s]=(0,n.useState)(null),[c,l]=(0,n.useState)(null),u=(0,n.useRef)(null),d=(0,n.useRef)(null),f=(0,n.useRef)(0);(0,n.useEffect)(()=>{let n=e.current;if(!t||!n){d.current!==null&&(clearTimeout(d.current),d.current=null),f.current=0;return}let r=!1,i=()=>{if(r||u.current)return;if(n.videoWidth===0||n.videoHeight===0){d.current=setTimeout(i,100);return}let e=La(n);u.current=e,f.current=0,l({width:n.videoWidth,height:n.videoHeight}),s(e)};return n.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&n.videoWidth>0&&n.videoHeight>0?i():(n.addEventListener(`loadeddata`,i),n.addEventListener(`loadedmetadata`,i),n.addEventListener(`playing`,i),d.current=setTimeout(i,200)),()=>{r=!0,d.current!==null&&(clearTimeout(d.current),d.current=null),n.removeEventListener(`loadeddata`,i),n.removeEventListener(`loadedmetadata`,i),n.removeEventListener(`playing`,i),u.current&&=(u.current.dispose(),null),f.current=0,s(null),l(null)}},[e,t]),(0,a.useFrame)(()=>{!u.current||!u.current.image||(f.current=(f.current+1)%Ia,f.current===0&&(u.current.needsUpdate=!0))});let[p,m]=(0,n.useMemo)(()=>Ra(r.width,r.height,c),[c,r.height,r.width]);return!t||!o?null:(0,i.jsxs)(`mesh`,{position:[0,0,-20],renderOrder:-1,scale:[-1,1,1],children:[(0,i.jsx)(`planeGeometry`,{args:[p,m]}),(0,i.jsx)(`meshBasicMaterial`,{map:o,depthTest:!1,depthWrite:!1,toneMapped:!1})]})}function Ba({onReady:e}){return(0,n.useEffect)(()=>(e?.(!0),()=>{e?.(!1)}),[e]),null}function Va(){return(0,i.jsx)(`color`,{attach:`background`,args:[`#000000`]})}function Ha({garmentUrl:e,enabled:t=!0,width:r=1280,height:a=720,facingMode:s=`user`,mockMode:c=!1,viewportWidth:l=0,viewportHeight:u=0,measurementEnabled:d=!0,autoStartMeasurement:f=!1,measurementConfig:p,fitType:m=`regular`,garmentScaleHint:h=null,bodyPresetOptions:g,className:_,style:v,debugMaterials:y=!1,showEnvironment:b=!1,showStats:x=!1,showWebcamBackground:C=!0,onCanvasReadyChange:w,onRuntimeStateChange:T,onGarmentLoadStateChange:E}){let D=Hn({enabled:t,width:r,height:a,facingMode:s,mockMode:c,viewportWidth:l,viewportHeight:u,measurementEnabled:d,autoStartMeasurement:f,measurementConfig:p,bodyPresetOptions:g,fitType:m,garmentScaleHint:h});return(0,n.useEffect)(()=>{T?.(D)},[D,T]),(0,i.jsxs)(`div`,{className:_,style:{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,...v},children:[(0,i.jsx)(`video`,{ref:D.videoRef,autoPlay:!0,playsInline:!0,muted:!0,style:{display:`none`}}),(0,i.jsxs)(S,{showEnvironment:b,useDefaultLights:!1,enableOrbitControls:!1,children:[(0,i.jsx)(Ba,{onReady:w}),(0,i.jsx)(Va,{}),(0,i.jsx)(o.OrthographicCamera,{makeDefault:!0,position:[0,0,100],zoom:180,near:.1,far:1e3}),(0,i.jsx)(`ambientLight`,{intensity:.95}),(0,i.jsx)(`directionalLight`,{position:[4,6,8],intensity:1.15}),(0,i.jsx)(`directionalLight`,{position:[-5,4,6],intensity:.45}),(0,i.jsx)(`hemisphereLight`,{args:[`#ffffff`,`#7d8aa6`,.35]}),C?(0,i.jsx)(za,{videoRef:D.videoRef,webcamReady:D.webcamReady}):null,t&&e?(0,i.jsx)(Fa,{url:e,landmarks:D.landmarks,worldLandmarks:D.worldLandmarks,poseFrameWidth:D.poseFrameWidth,poseFrameHeight:D.poseFrameHeight,debugMaterials:y,onLoadStateChange:E}):null,x?(0,i.jsx)(o.Stats,{}):null]})]})}var Ua=({className:e,style:t,width:r=1280,height:a=720,facingMode:o=`user`,enabled:s=!0,mockMode:c=!1})=>{let{videoRef:l}=b(),{isWebcamActive:u,setWebcamActive:d}=v(),{isReady:f}=Vn({width:r,height:a,facingMode:o,enabled:s,mockMode:c,videoRef:l,onReadyChange:d});return(0,n.useEffect)(()=>{!s&&u&&d(!1)},[s,u,d]),(0,i.jsx)(`div`,{className:`camera-view-container ${e||``}`,style:{position:`absolute`,inset:0,zIndex:0,...t},children:(0,i.jsx)(`video`,{ref:l,autoPlay:!0,playsInline:!0,muted:!0,className:`w-full h-full object-cover`,style:{display:s&&(f||u)?`block`:`none`}})})},Wa=({url:e,onBonesReady:t})=>e?(0,i.jsx)(Ka,{url:e,onBonesReady:t}):null;function Ga(e){return`isBone`in e&&e.isBone===!0}var Ka=({url:e,onBonesReady:t})=>{let{scene:r}=(0,o.useGLTF)(e),a=(0,n.useRef)(null),{setAvatarBones:s}=b();return(0,n.useEffect)(()=>{if(!r)return;let e={};return r.traverse(t=>{Ga(t)&&(e[t.name]=t)}),s(e),t&&t(e),()=>s(null)},[r,t,s]),(0,i.jsx)(`group`,{ref:a,dispose:null,children:(0,i.jsx)(`primitive`,{object:r})})},qa=({url:e,targetAvatarBones:t})=>e?(0,i.jsx)(Ya,{url:e,targetAvatarBones:t}):null;function Ja(e){return`isSkinnedMesh`in e&&e.isSkinnedMesh===!0}var Ya=({url:e,targetAvatarBones:t})=>{let{scene:a}=(0,o.useGLTF)(e),s=(0,n.useRef)(null),{avatarBones:c}=b(),l=t||c;return(0,n.useEffect)(()=>{!a||!l||a.traverse(e=>{if(Ja(e)){let t=e,n=[];t.skeleton.bones.forEach(e=>{l[e.name]?n.push(l[e.name]):n.push(e)}),t.bind(new r.Skeleton(n),t.bindMatrix)}})},[a,l]),(0,i.jsx)(`group`,{ref:s,dispose:null,children:(0,i.jsx)(`primitive`,{object:a})})},Xa=()=>({mapPoseToBones:(0,n.useCallback)((e,t)=>{if(!e||e.length===0||!t)return;for(let n of[`Hips`,`Spine`,`Chest`,`LeftUpperArm`,`LeftLowerArm`,`RightUpperArm`,`RightLowerArm`,`LeftUpperLeg`,`LeftLowerLeg`,`RightUpperLeg`,`RightLowerLeg`]){let r=t[n];r&&Vt(n,e,r.quaternion)&&r.quaternion.normalize()}let n=e[z.LEFT_HIP],r=e[z.RIGHT_HIP],i=t.Hips;i&&n&&r&&i.position.set((n.x+r.x)*.5,-((n.y+r.y)*.5)+1,((n.z??0)+(r.z??0))*.5)},[])}),Za=e=>{let[t,r]=(0,n.useState)(null),{landmarks:i,setFitResult:a}=v();return(0,n.useEffect)(()=>{let t=e?.referenceHeightCm??170,n=e?.weightKg??null,o=e?.measurementIntervalMs??1e3,s=setInterval(()=>{if(!i||i.length<33)return;let e=Je(i,t,n),o=Xe(e);if(E(e),r({shoulder:e.shoulderWidthCm,chest:e.chestCircumferenceCm,waist:e.waistCircumferenceCm}),!o){a(null);return}a({type:o.fitDescription===`slim`?`slim`:o.fitDescription===`relaxed`?`oversize`:`regular`,suitability:Math.round(o.confidence*100)})},o);return()=>clearInterval(s)},[i,a,e]),{dimensions:t}},Qa={gender:`female`};function $a(e,t){return e instanceof Error&&e.message?e.message:t}function eo(e){let t=(0,n.useMemo)(()=>new ye(e),[e]),[r,i]=(0,n.useState)(`idle`),[a,o]=(0,n.useState)(null),[s,c]=(0,n.useState)(null);return{status:r,resultUrl:a,error:s,generateAvatar:(0,n.useCallback)(async(e=Qa)=>{i(`processing`),c(null);try{let n=e instanceof Blob?Qa:e,r=await t.matchBodyPreset(n);if(!r.model_url)throw Error(`Matched body preset does not have a 3D model URL.`);return o(r.model_url),i(`ready`),r.model_url}catch(e){throw c($a(e,`Failed to load avatar model`)),i(`error`),e}},[t]),createGarment:(0,n.useCallback)(async(e,n,r,a)=>{i(`uploading`),c(null);try{let s=await t.createGarment(e);await t.uploadGarmentImage(s.id,n,`front`),r&&await t.uploadGarmentImage(s.id,r,`back`),i(`processing`),await t.generateGarment3D(s.id,{include_measurements:!!a,target_fit_types:[`regular`]});let c=await t.waitForGarmentModel(s.id),l=t.pickGarmentModelUrl(c);if(!l)throw Error(`Backend did not return a garment 3D model URL.`);return o(l),i(`ready`),l}catch(e){throw c($a(e,`Failed to generate garment`)),i(`error`),e}},[t]),reset:()=>{i(`idle`),o(null),c(null)}}}var to={Hips:[z.LEFT_HIP,z.RIGHT_HIP],Spine:[z.LEFT_SHOULDER,z.RIGHT_SHOULDER,z.LEFT_HIP,z.RIGHT_HIP],Chest:[z.LEFT_SHOULDER,z.RIGHT_SHOULDER],LeftShoulder:[z.LEFT_SHOULDER,z.LEFT_ELBOW],LeftUpperArm:[z.LEFT_SHOULDER,z.LEFT_ELBOW],LeftLowerArm:[z.LEFT_ELBOW,z.LEFT_WRIST],RightShoulder:[z.RIGHT_SHOULDER,z.RIGHT_ELBOW],RightUpperArm:[z.RIGHT_SHOULDER,z.RIGHT_ELBOW],RightLowerArm:[z.RIGHT_ELBOW,z.RIGHT_WRIST],LeftUpperLeg:[z.LEFT_HIP,z.LEFT_KNEE],LeftLowerLeg:[z.LEFT_KNEE,z.LEFT_ANKLE],RightUpperLeg:[z.RIGHT_HIP,z.RIGHT_KNEE],RightLowerLeg:[z.RIGHT_KNEE,z.RIGHT_ANKLE]};e.AvatarModel=Wa,e.BONE_MAPPING=gr,e.BONE_VISIBILITY_MAP=to,e.CameraView=Ua,e.DEFAULT_EVER_API_BASE_URL=ge,e.DEFAULT_FEMALE_BODY_PRESET_ID=Se,e.DEFAULT_GARMENT_SPEC=C,e.DEFAULT_LOCKED_PERSON_ID=$t,e.DEFAULT_MALE_BODY_PRESET_ID=xe,e.DEFAULT_MEASUREMENT_CONFIG=Ze,e.DEFAULT_NUM_POSES=gt,e.DEFAULT_SMOOTHING=Le,e.EverCanvas=S,e.EverClient=ye,e.EverContext=y,e.EverFittingScene=Ha,e.EverProvider=x,e.EverTrackedGarment=Fa,e.FacingDetector=vi,e.GarmentModel=qa,e.INTERPOLATION_ALPHA=_t,e.LANDMARK=z,e.LEGACY_RIGGED_BODY_PRESET_ID=Ce,e.LandmarkSmoother=sn,e.MEDIAPIPE_TASKS_VISION_VERSION=pt,e.MODEL_ASSET_PATHS=vt,e.POSE_DETECTION_INTERVAL=ht,e.TRACKING_SNAPSHOT_HOLD_MS=Pn,e.TrackedGarmentPoseDriver=Na,e.WASM_FILES_URL=mt,e.WebcamPlaneBackground=za,e.YawDirectionStabilizer=ti,e.YawFreezeController=xi,e.applyLandmarkPoseToGarment=qr,e.blendBonesToRest=Yr,e.buildBodyPresetAssetUrl=Ee,e.buildBodyPresetMatchRequest=Ne,e.calcRectIoU=yn,e.captureBoneBinding=Un,e.clampNormalizedRect=gn,e.closeSegmentationMasks=Zt,e.computeBmiCorrectionFactor=Ve,e.computeBodyFirstFitting=he,e.computeBoneDirectionFromLandmarks=zt,e.computeBoneRotationFromLandmarks=Vt,e.computeCoverRect=tt,e.computeFacingAwareShoulderWidth=Ii,e.computeGarmentFitProfile=qn,e.computeGarmentRootQuaternion=Ri,e.computeGarmentScale=E,e.computeLandmarkBoundsNormalized=_n,e.computeLandmarkSegmentDirection=Rt,e.computeScale=Be,e.computeStableShoulderWidth=Li,e.computeVisibleNormalizedRegion=nt,e.configureAvatarLoader=$n,e.createAvatarLoaderExtension=er,e.createFallbackBodyPresetSelection=je,e.createHeldTrackingSnapshot=In,e.createHumanoidBoneBindings=ir,e.createIdleTrackingQuality=An,e.createInitialPoseSnapshot=dt,e.createInitialTrackingRuntimeState=Mn,e.createPoseCandidates=xn,e.createPoseLandmarker=yt,e.createTrackedGarmentMotionState=Aa,e.createTrackedModelTransformScratch=ca,e.createTrackingLostRuntimeState=Ln,e.createTrackingQuality=jn,e.createTrackingRuntimeState=Nn,e.createVRMCompat=cr,e.deriveBodyMorphResult=ue,e.ensureBodyPresetModelUrl=ke,e.expandNormalizedRect=vn,e.extractFacingSignals=hi,e.extractSilhouetteWidths=ot,e.filterCandidatesByVisibleRegion=Tn,e.getAvatarAssetKind=Qn,e.getBoneLandmarkInfluence=Bt,e.getBoneRotation=yr,e.getDefaultBodyPresetId=De,e.getSegmentationMaskData=Xt,e.hasLandmarkMapping=Ht,e.interpolateLandmarks=st,e.interpolatePoseRig=lt,e.interpolatePoseSnapshot=ft,e.interpolateSilhouetteWidths=ut,e.isCandidateInVisibleRegion=wn,e.isRawFrontFacing=gi,e.isVRMAssetUrl=Zn,e.landmarkToThreePosition=X,e.lerpRotation=K,e.lerpValue=U,e.measureBody=Je,e.normalizeBodyPresetGender=Te,e.normalizeBoneName=vr,e.normalizeLandmark=tn,e.normalizeLandmarks=nn,e.pickDefaultBodyPreset=Ae,e.prepareAvatarScene=tr,e.prepareNativeVRM=nr,e.recommendSize=Xe,e.resetBoneRotations=Jn,e.resetPoseState=Jr,e.resetTrackedGarmentMotionState=ja,e.scaleSilhouetteWidths=Qt,e.selectLockedPoseCandidate=Cn,e.shouldHoldTrackingSnapshot=Fn,e.smoothPoseRig=ln,e.solvePose=Yt,e.toBodyPresetSelection=Me,e.toBodyPresetSummary=Oe,e.toLockedPoseCandidate=En,e.updateTrackedGarmentMotion=Ma,e.updateTrackedModelTransform=la,e.useAvatarVariant=ur,e.useBodyMeasurer=Za,e.useBodyPresetSelection=Ie,e.useEver=b,e.useEverFitting=Hn,e.useEverGeneration=eo,e.useEverStore=v,e.useMeasurement=et,e.usePoseApplicationRefs=Kr,e.usePoseMapper=Xa,e.usePoseTracker=zn,e.useWebcam=Vn});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`@react-three/fiber`),require(`@react-three/drei`),require(`react/jsx-runtime`),require(`@mediapipe/tasks-vision`),require(`three`),require(`three/examples/jsm/utils/SkeletonUtils.js`),require(`@pixiv/three-vrm`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@react-three/fiber`,`@react-three/drei`,`react/jsx-runtime`,`@mediapipe/tasks-vision`,`three`,`three/examples/jsm/utils/SkeletonUtils.js`,`@pixiv/three-vrm`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`e-ver`]={},e.React,e.ReactThreeFiber,e.ReactThreeDrei,e.react_jsx_runtime,e.MediaPipeVision,e.THREE,e.three_examples_jsm_utils_SkeletonUtils_js,e.PixivThreeVRM))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e},g=(e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e));t=g(t),o=g(o);var _=({children:e,showEnvironment:a=!0,useDefaultLights:o=!0,enableOrbitControls:s=!0})=>(0,i.jsx)(n.Canvas,{camera:{position:[0,1.5,3],fov:45},style:{width:`100%`,height:`100%`,position:`absolute`,top:0,left:0},gl:{alpha:!0,antialias:!0,preserveDrawingBuffer:!0},children:(0,i.jsxs)(t.Suspense,{fallback:null,children:[o?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`ambientLight`,{intensity:.7}),(0,i.jsx)(`directionalLight`,{position:[2,5,2],intensity:1.5,castShadow:!0}),(0,i.jsx)(`directionalLight`,{position:[-2,5,-2],intensity:.5})]}):null,a&&(0,i.jsx)(r.Environment,{preset:`city`}),e,s?(0,i.jsx)(r.OrbitControls,{enablePan:!1,minPolarAngle:Math.PI/4,maxPolarAngle:Math.PI/1.5,minDistance:1,maxDistance:5}):null]})}),v={refShoulderWidthCm:44,refHeightCm:170,refArmLengthCm:58,refChestCircumferenceCm:96,refWaistCircumferenceCm:84,refHipWidthCm:36,refTorsoLengthCm:52,shoulderEaseCm:4.5,chestEaseCm:10,waistEaseCm:8,hipEaseCm:5,torsoEaseCm:2.5,armEaseCm:2,fitEaseScale:1.03};function y(e,t,n){return!e||t<=0?1:(e+n)/t}function b(e,t,n){return Math.max(t,Math.min(n,e))}function x(e,t=v){let n=y(e.shoulderWidthCm,t.refShoulderWidthCm,t.shoulderEaseCm),r=y(e.chestCircumferenceCm,t.refChestCircumferenceCm,t.chestEaseCm),i=y(e.waistCircumferenceCm,t.refWaistCircumferenceCm,t.waistEaseCm),a=y(e.hipWidthCm,t.refHipWidthCm,t.hipEaseCm),o=y(e.torsoLengthCm,t.refTorsoLengthCm,t.torsoEaseCm),s=t.refHeightCm>0?e.heightCm/t.refHeightCm:1,c=y(e.armLengthCm,t.refArmLengthCm,t.armEaseCm),l=Math.max(n,r,a),u=Math.max(r,i,a*.98),d=Math.max(s,o,l*.94);return{scaleX:b(l,.82,1.85),scaleY:b(d,.85,1.55),scaleZ:b(u,.84,1.9),sleeveScale:b(c,.8,1.55),fitEaseScale:b(t.fitEaseScale,1,1.2)}}var S=.82,C=2.1,w=.85,T=1.8,E=.84,D=2.1,O=.8,k=1.7,A=1,j=1.25,M={scaleX:1,scaleY:1,scaleZ:1,sleeveScale:1,fitEaseScale:1.02},ee={scaleX:1,scaleY:1,scaleZ:1,sleeveScale:1,fitEaseScale:1},N={slim:{x:.95,y:.95,z:1,ease:.99},regular:{x:1,y:1,z:1,ease:1},oversize:{x:1.08,y:1.08,z:1.02,ease:1.03}},P={narrow:{width:.97,shoulder:.97},balanced:{width:1,shoulder:1},broad:{width:1.03,shoulder:1.04}},F={tapered:{depth:.98,vertical:.995,hip:.99},balanced:{depth:1,vertical:1,hip:1},full:{depth:1.04,vertical:1.015,hip:1.03}};function I(e,t,n){return Math.max(t,Math.min(n,e))}function L(e,t,n,r){return!e||!t||t<=0?1:I(e/t,n,r)}function R(e,t,n,r,i){return!e||t<=0?1:I((e+n)/t,r,i)}function z(e){return P[e?.taxonomy.upperBodySilhouette??`balanced`]??P.balanced}function B(e){return F[e?.taxonomy.torsoOrPelvisProfile??`balanced`]??F.balanced}function te(e){if(!e)return!1;let{metrics:t}=e;return!!(t.heightCm||t.chestCm||t.waistCm||t.shoulderWidthCm||t.armLengthCm||t.torsoLengthCm||t.neckToHipCm)}function ne(e,t){let{metrics:n}=e,r=z(e),i=B(e),a=Math.max(R(n.shoulderWidthCm,t.refShoulderWidthCm,t.shoulderEaseCm*.55,.88,1.3),R(n.chestCm,t.refChestCircumferenceCm,t.chestEaseCm*.35,.9,1.34),R(n.waistCm,t.refWaistCircumferenceCm,t.waistEaseCm*.3,.9,1.3))*r.width,o=Math.max(L(n.heightCm,t.refHeightCm,.9,1.18),R(n.torsoLengthCm??n.neckToHipCm,t.refTorsoLengthCm,t.torsoEaseCm*.2,.9,1.16))*i.vertical,s=Math.max(R(n.chestCm,t.refChestCircumferenceCm,t.chestEaseCm*.15,.9,1.34),R(n.waistCm,t.refWaistCircumferenceCm,t.waistEaseCm*.1,.9,1.28))*i.depth;return{scaleX:I(a,S,C),scaleY:I(o,w,T),scaleZ:I(s,E,D),sleeveScale:I(L(n.armLengthCm,t.refArmLengthCm,.9,1.16),O,k),fitEaseScale:I(t.fitEaseScale*(r.width*.5+i.depth*.5),A,j)}}function re(e,t){let{metrics:n}=t,r=z(t),i=B(t),a=L(e.shoulderWidthCm,n.shoulderWidthCm,.9,1.14)*r.shoulder,o=L(e.chestCircumferenceCm,n.chestCm,.9,1.15),s=L(e.waistCircumferenceCm,n.waistCm,.9,1.15);return{torsoScale:L(e.torsoLengthCm,n.torsoLengthCm??n.neckToHipCm,.9,1.14),chestScale:o,waistScale:s,hipScale:I(s*.6+i.hip*.4,.92,1.14),shoulderAdjust:I(a-1,-.12,.12),postureAdjust:`neutral`}}function ie(e,t,n){let r=B(t),i=I(1+n.shoulderAdjust,.92,1.14)*.3+n.chestScale*.45+n.waistScale*.25,a=n.chestScale*.45+n.waistScale*.25+n.hipScale*.3,o=L(e.armLengthCm,t.metrics.armLengthCm,.9,1.16),s=Math.max(n.chestScale,n.waistScale,n.hipScale);return{scaleX:I(i,.92,1.16),scaleY:I(n.torsoScale*r.vertical,.92,1.14),scaleZ:I(a*r.depth,.92,1.18),sleeveScale:I(o,O,k),fitEaseScale:I(1+(s-1)*.22,.99,1.08)}}function ae(e,t){if(!t||!Number.isFinite(t)||t<=0)return e;let n=I(t,.88,1.2),r=1+(n-1)*.35;return{scaleX:I(e.scaleX*n,S,C),scaleY:I(e.scaleY*r,w,T),scaleZ:I(e.scaleZ*n,E,D),sleeveScale:I(e.sleeveScale*r,O,k),fitEaseScale:I(e.fitEaseScale*n,A,j)}}function oe(e,t){let n=N[t];return{scaleX:I(e.scaleX*n.x,S,C),scaleY:I(e.scaleY*n.y,w,T),scaleZ:I(e.scaleZ*n.z,E,D),sleeveScale:e.sleeveScale,fitEaseScale:I(e.fitEaseScale*n.ease,A,j)}}function se(e,t){return{scaleX:I(e.scaleX*t.scaleX,S,C),scaleY:I(e.scaleY*t.scaleY,w,T),scaleZ:I(e.scaleZ*t.scaleZ,E,D),sleeveScale:I(e.sleeveScale*t.sleeveScale,O,k),fitEaseScale:I(e.fitEaseScale*t.fitEaseScale,A,j)}}function ce({measurements:e,measurementScale:t,presetSelection:n,fitType:r=`regular`,garmentScaleHint:i=null,spec:a=v}){let o=te(n),s=o&&n?ne(n,a):t??M,c=o&&n&&e?re(e,n):null;return{scale:oe(ae(se(s,e&&n&&c?ie(e,n,c):ee),i),r),morph:c}}var le=`http://localhost:8000/api/v1`;function ue(e){return e.replace(/\/+$/,``)}function de(e){try{return new URL(e).origin}catch{return``}}var fe=class{baseUrl;apiOrigin;apiKey;constructor(e){let t=typeof e==`string`?{baseUrl:e}:e??{},n=ue(t.baseUrl??`http://localhost:8000/api/v1`);this.baseUrl=n,this.apiOrigin=de(n),this.apiKey=t.apiKey}resolveAssetUrl(e){return e?e.startsWith(`http://`)||e.startsWith(`https://`)?e:e.startsWith(`/`)?this.apiOrigin?`${this.apiOrigin}${e}`:e:this.apiOrigin?`${this.apiOrigin}/${e}`:`/${e}`:null}async listBodyPresets(e){return(await this.request(`body-presets/`,{params:e?{gender:e}:void 0})).map(e=>this.normalizeBodyPreset(e))}async matchBodyPreset(e){let t=await this.request(`body-presets/match`,{method:`POST`,body:e});return this.normalizeBodyPreset(t)}async listGarments(e){let t=await this.request(`garment/`,{params:e});return{...t,items:t.items.map(e=>this.normalizeGarmentSummary(e))}}async getGarment(e){let t=await this.request(`garment/${e}`);return this.normalizeGarmentDetail(t)}async getPipelineStatus(e){return this.request(`pipeline/${e}`)}async createGarment(e){let t=await this.request(`garment/`,{method:`POST`,body:e});return this.normalizeGarmentSummary(t)}async uploadGarmentImage(e,t,n){let r=new FormData;return r.append(`files`,t,`${n}_image.png`),r.append(`image_type`,n),(await this.request(`garment/${e}/images`,{method:`POST`,body:r})).map(e=>({...e,image_url:this.resolveAssetUrl(e.image_url)??e.image_url}))}async generateGarment3D(e,t){return this.request(`garment/${e}/generate-3d`,{method:`POST`,body:{include_measurements:t?.include_measurements??!1,target_fit_types:t?.target_fit_types??[`regular`]}})}async waitForGarmentModel(e,t){let n=t?.intervalMs??2e3,r=t?.timeoutMs??12e4,i=Date.now();for(;Date.now()-i<=r;){let t=await this.getGarment(e);if(this.pickGarmentModelUrl(t))return t;if(t.asset_status===`rigging_failed`)throw Error(`Garment 3D generation failed on backend.`);await new Promise(e=>globalThis.setTimeout(e,n))}throw Error(`Timed out while waiting for garment 3D model.`)}pickGarmentModelUrl(e){if(e.model_url)return e.model_url;let t=e.variants.find(e=>e.is_default&&e.model_url);return t?.model_url?t.model_url:e.variants.find(e=>e.model_url)?.model_url??null}normalizeBodyPreset(e){return{...e,model_url:this.resolveAssetUrl(e.model_url)}}normalizeGarmentSummary(e){return{...e,thumbnail_url:this.resolveAssetUrl(e.thumbnail_url),model_url:this.resolveAssetUrl(e.model_url)}}normalizeGarmentDetail(e){return{...this.normalizeGarmentSummary(e),brand:e.brand?{...e.brand,logo_url:this.resolveAssetUrl(e.brand.logo_url)}:null,images:e.images.map(e=>({...e,image_url:this.resolveAssetUrl(e.image_url)??e.image_url})),sizes:e.sizes,variants:e.variants.map(e=>({...e,model_url:this.resolveAssetUrl(e.model_url)}))}}async request(e,t){let n=this.apiKey?`sdk/public/${e}`:e,r=this.buildUrl(n,t?.params),i=new Headers,a;this.apiKey&&i.set(`X-API-Key`,this.apiKey),t?.body instanceof FormData?a=t.body:t?.body!==void 0&&(i.set(`Content-Type`,`application/json`),a=JSON.stringify(t.body));let o=await fetch(r.toString(),{method:t?.method??`GET`,body:a,headers:i,credentials:this.apiKey?`omit`:`include`});if(!o.ok)throw Error(await this.getResponseErrorMessage(o));if(o.status!==204)return await o.json()}buildUrl(e,t){let n=this.baseUrl.startsWith(`http://`)||this.baseUrl.startsWith(`https://`)?`${this.baseUrl}/`:typeof window<`u`?new URL(`${this.baseUrl}/`,window.location.origin).toString():`http://localhost${this.baseUrl}/`,r=new URL(e.replace(/^\/+/,``),n);return t&&Object.entries(t).forEach(([e,t])=>{t!==void 0&&r.searchParams.set(e,String(t))}),r}async getResponseErrorMessage(e){try{let t=await e.json();return t.detail||t.message||t.error||`Request failed with status ${e.status}`}catch{return`Request failed with status ${e.status}`}}},pe=`M`,me=`male-m-balanced-balanced`,he=`female-m-balanced-balanced`,ge=`rigged_avatar`;function _e(e,t){if(!t)return``;if(/^https?:\/\//.test(t))return t;let n=t.startsWith(`/`)?t:`/${t}`;return n.startsWith(`/assets/`)||n.startsWith(`/static/`)?n:e.resolveAssetUrl(n)??n}function ve(e){return e===`female`?`female`:`male`}function ye(e,t={}){let n=t.renderMode??`rigged_avatar`,r=t.legacyPresetId??`rigged_avatar`,i=`/assets/body-presets/${r}.glb`;return e===r||n!==`preset-native`?i:`/assets/body-presets/archive/${e}.glb`}function be(e){return e===`female`?he:me}function xe(e,t){return{id:e.id,presetId:e.preset_id,baseGender:ve(e.base_gender),sizeBand:e.size_band,upperBodySilhouette:e.upper_body_silhouette,torsoOrPelvisProfile:e.torso_or_pelvis_profile,modelUrl:_e(t,e.model_url),heightCm:e.height_cm??null,chestCm:e.chest_cm??null,waistCm:e.waist_cm??null,hipCm:e.hip_cm??null,shoulderWidthCm:e.shoulder_width_cm??null,armLengthCm:e.arm_length_cm??null,inseamCm:e.inseam_cm??null,torsoLengthCm:e.torso_length_cm??null,neckToHipCm:e.neck_to_hip_cm??null}}function Se(e,t={}){return{...e,modelUrl:e.modelUrl||ye(e.presetId,t)}}function Ce(e,t={}){return e.length===0?null:Se(e.find(e=>e.sizeBand===pe)||e[Math.floor(e.length/2)],t)}function we(e,t={}){let n=be(e);return{id:null,presetId:n,label:`${e===`female`?`여성`:`남성`} 기본 ${pe}`,modelUrl:ye(n,t),gender:e,source:`fallback`,taxonomy:{sizeBand:pe,upperBodySilhouette:`balanced`,torsoOrPelvisProfile:`balanced`},metrics:{heightCm:null,chestCm:null,waistCm:null,hipCm:null,shoulderWidthCm:null,armLengthCm:null,inseamCm:null,torsoLengthCm:null,neckToHipCm:null}}}function Te(e,t,n={}){let r=Se(e,n);return{id:r.id,presetId:r.presetId,label:`${r.baseGender===`female`?`여성`:`남성`} ${r.sizeBand}`,modelUrl:r.modelUrl,gender:r.baseGender,source:t,taxonomy:{sizeBand:r.sizeBand,upperBodySilhouette:r.upperBodySilhouette,torsoOrPelvisProfile:r.torsoOrPelvisProfile},metrics:{heightCm:r.heightCm,chestCm:r.chestCm,waistCm:r.waistCm,hipCm:r.hipCm,shoulderWidthCm:r.shoulderWidthCm,armLengthCm:r.armLengthCm,inseamCm:r.inseamCm,torsoLengthCm:r.torsoLengthCm,neckToHipCm:r.neckToHipCm}}}function Ee(e,t){let n={gender:t};return Number.isFinite(e.heightCm)&&(n.height_cm=e.heightCm),e.chestCircumferenceCm!==null&&(n.chest_cm=e.chestCircumferenceCm),e.waistCircumferenceCm!==null&&(n.waist_cm=e.waistCircumferenceCm),e.shoulderWidthCm!==null&&(n.shoulder_width_cm=e.shoulderWidthCm),n}var De=new fe;function Oe(e,t){return{selection:we(e,t),loading:!0,error:null}}function ke(e,n={}){let r=ve(n.gender),i=n.renderMode,a=n.legacyPresetId,o=(0,t.useMemo)(()=>({gender:r,renderMode:i,legacyPresetId:a}),[r,a,i]),[s,c]=(0,t.useState)(()=>Oe(r,o));return(0,t.useEffect)(()=>{let t=new AbortController;async function n(){c(e=>({...e,loading:!0,error:null}));try{if(e){let n=Te(xe(await De.matchBodyPreset(Ee(e,o.gender)),De),`match`,o);if(t.signal.aborted)return;c({selection:n,loading:!1,error:null});return}let n=(await De.listBodyPresets(o.gender)).map(e=>xe(e,De));if(t.signal.aborted)return;let r=Ce(n,o);if(r){c({selection:Te(r,`default`,o),loading:!1,error:null});return}c({selection:we(o.gender,o),loading:!1,error:`바디 프리셋 응답이 비어 있어 기본 프리셋으로 대체했습니다.`})}catch(e){if(t.signal.aborted)return;c({selection:we(o.gender,o),loading:!1,error:e instanceof Error?e.message:`바디 프리셋을 불러오지 못해 기본 프리셋으로 대체했습니다.`})}}return n(),()=>{t.abort()}},[e,o]),s}var V={NOSE:0,LEFT_EYE_INNER:1,LEFT_EYE:2,LEFT_EYE_OUTER:3,RIGHT_EYE_INNER:4,RIGHT_EYE:5,RIGHT_EYE_OUTER:6,LEFT_EAR:7,RIGHT_EAR:8,MOUTH_LEFT:9,MOUTH_RIGHT:10,LEFT_SHOULDER:11,RIGHT_SHOULDER:12,LEFT_ELBOW:13,RIGHT_ELBOW:14,LEFT_WRIST:15,RIGHT_WRIST:16,LEFT_PINKY:17,RIGHT_PINKY:18,LEFT_INDEX:19,RIGHT_INDEX:20,LEFT_THUMB:21,RIGHT_THUMB:22,LEFT_HIP:23,RIGHT_HIP:24,LEFT_KNEE:25,RIGHT_KNEE:26,LEFT_ANKLE:27,RIGHT_ANKLE:28,LEFT_HEEL:29,RIGHT_HEEL:30,LEFT_FOOT_INDEX:31,RIGHT_FOOT_INDEX:32},Ae={positionAlpha:.7,rotationAlpha:.6,visibilityThreshold:.5},je=.5;function Me(e){return e?(e.visibility??1)>=je:!1}function Ne(e,t){let n=e[V.NOSE],r=e[V.LEFT_EYE],i=e[V.LEFT_ANKLE],a=e[V.RIGHT_ANKLE];if(!Me(n)||!Me(r)||!Me(i)||!Me(a))return 0;let o=n.y-(r.y-n.y)*2,s=(Math.max(i.y,a.y)-o)*t;return Number.isFinite(s)&&s>0?s:0}function Pe(e,t,n=720){let r=Ne(e,n);return r<=0||t<=0?0:t/r}function Fe(e){let t=[[15,.8],[18.5,.84],[22,.88],[25,.91],[30,.94],[40,.96]];if(e<=t[0][0])return t[0][1];if(e>=t[t.length-1][0])return t[t.length-1][1];for(let n=0;n<t.length-1;n+=1){let[r,i]=t[n],[a,o]=t[n+1];if(e>=r&&e<=a)return i+(e-r)/(a-r)*(o-i)}return .88}function H(e,t,n,r){if(!Me(e)||!Me(t))return null;let i=(e.x-t.x)*n,a=(e.y-t.y)*r,o=Math.hypot(i,a);return Number.isFinite(o)&&o>0?o:null}function Ie(e){return Math.round(e*10)/10}function U(e){return e===null||!Number.isFinite(e)||e<=0?null:Ie(e)}function Le(e){let t=e.filter(e=>e!==null);return t.length===0?null:t.reduce((e,t)=>e+t,0)/t.length}function Re(e,t){return e&&t!==null&&t>0?`silhouette_bmi`:`keypoint`}function ze(e,t,n){return n&&t>0&&e/t>=.85?`standard`:`estimate`}function Be(e,t,n,r){if(t<=0||e<=0)return 0;let i=e/t*.8,a=n?.15:0,o=r!==null&&r>0?.05:0;return Math.min(.99,Ie((i+a+o)*10)/10)}function Ve(e,t){if(e<=0||t<=0)return 0;let n=(e-t)**2/(e+t)**2;return Math.PI*(e+t)*(1+3*n/(10+Math.sqrt(4-3*n)))}function He(e,t,n=null,r=null,i=1280,a=720){let o=Pe(e,t,a),s=Re(r,n);if(o<=0)return{heightCm:t,shoulderWidthCm:null,chestCircumferenceCm:null,waistCircumferenceCm:null,hipWidthCm:null,armLengthCm:null,legLengthCm:null,torsoLengthCm:null,accuracyGrade:`estimate`,confidenceScore:0,measurementMethod:s,measuredAt:null};let c=H(e[V.LEFT_SHOULDER],e[V.RIGHT_SHOULDER],i,a),l=H(e[V.LEFT_HIP],e[V.RIGHT_HIP],i,a),u=H(e[V.LEFT_SHOULDER],e[V.LEFT_ELBOW],i,a),d=H(e[V.LEFT_ELBOW],e[V.LEFT_WRIST],i,a),f=H(e[V.RIGHT_SHOULDER],e[V.RIGHT_ELBOW],i,a),p=H(e[V.RIGHT_ELBOW],e[V.RIGHT_WRIST],i,a),m=u!==null&&d!==null?u+d:null,h=f!==null&&p!==null?f+p:null,g=H(e[V.LEFT_HIP],e[V.LEFT_KNEE],i,a),_=H(e[V.LEFT_KNEE],e[V.LEFT_ANKLE],i,a),v=H(e[V.RIGHT_HIP],e[V.RIGHT_KNEE],i,a),y=H(e[V.RIGHT_KNEE],e[V.RIGHT_ANKLE],i,a),b=g!==null&&_!==null?g+_:null,x=v!==null&&y!==null?v+y:null,S=Le([H(e[V.LEFT_SHOULDER],e[V.LEFT_HIP],i,a),H(e[V.RIGHT_SHOULDER],e[V.RIGHT_HIP],i,a)]),C=U(c===null?null:c*o),w=U(l===null?null:l*o),T=U(Le([m===null?null:m*o,h===null?null:h*o])),E=U(Le([b===null?null:b*o,x===null?null:x*o])),D=U(S===null?null:S*o),O=C===null?null:C*2.2,k=w===null?null:w*2.1;if(r){let e=r.shoulderWidthPx*o;if(O=U(Ve(Math.max(r.chestWidthPx*o/2,0),Math.max(e*.28/2,0))),k=U(Ve(Math.max(r.waistWidthPx*o/2,0),Math.max(r.hipWidthPx*o*.26/2,0))),n!==null&&n>0){let e=Fe(n/(t/100)**2);O=U(O===null?null:O/e),k=U(k===null?null:k/e)}}else O=U(O),k=U(k);let A=[C,O,k,w,T,E,D].filter(e=>e!==null).length;return{heightCm:Ie(t),shoulderWidthCm:C,chestCircumferenceCm:O,waistCircumferenceCm:k,hipWidthCm:w,armLengthCm:T,legLengthCm:E,torsoLengthCm:D,accuracyGrade:ze(A,7,r),confidenceScore:Be(A,7,r,n),measurementMethod:s,measuredAt:null}}var Ue={S:{shoulder:[40,42],chest:[86,92],waist:[72,78]},M:{shoulder:[42,44],chest:[92,98],waist:[78,84]},L:{shoulder:[44,46],chest:[98,104],waist:[84,90]},XL:{shoulder:[46,48],chest:[104,110],waist:[90,96]},"2XL":{shoulder:[48,50],chest:[110,118],waist:[96,104]}};function We(e){let t=[`S`,`M`,`L`,`XL`,`2XL`],n=`M`,r=-1/0,i=!1;for(let a of t){let t=Ue[a],o=0,s=0;if(e.shoulderWidthCm!==null){let n=(t.shoulder[0]+t.shoulder[1])/2;o-=Math.abs(e.shoulderWidthCm-n),s+=1,i=!0}if(e.chestCircumferenceCm!==null){let n=(t.chest[0]+t.chest[1])/2;o-=Math.abs(e.chestCircumferenceCm-n),s+=1,i=!0}if(e.waistCircumferenceCm!==null){let n=(t.waist[0]+t.waist[1])/2;o-=Math.abs(e.waistCircumferenceCm-n),s+=1,i=!0}s>0&&(o/=s),o>r&&(r=o,n=a)}if(!i)return null;let a=Ue[n],o=`true-to-size`;if(e.chestCircumferenceCm!==null){let t=(a.chest[0]+a.chest[1])/2;e.chestCircumferenceCm>t+3?o=`slim`:e.chestCircumferenceCm<t-3&&(o=`relaxed`)}return{size:n,confidence:Math.min(1,Math.max(0,1+r/10)),fitDescription:o}}var Ge={referenceHeightCm:170,weightKg:null,stableFrameCount:15,motionThreshold:.015};function Ke(e){return e.map(e=>({...e}))}function qe(e,t){let n=0;for(let r=0;r<33;r+=1){let i=e[r],a=t[r];n+=Math.abs(a.x-i.x)+Math.abs(a.y-i.y)}return n/33}function Je(){let[e,n]=(0,t.useState)(Ge),[r,i]=(0,t.useState)(null),[a,o]=(0,t.useState)(null),[s,c]=(0,t.useState)(null),[l,u]=(0,t.useState)(!1),d=(0,t.useRef)(0),f=(0,t.useRef)(null),p=(0,t.useCallback)(()=>{d.current=0,f.current=null},[]),m=(0,t.useCallback)(()=>{i(null),o(null),c(null)},[]),h=(0,t.useCallback)(()=>{p(),m(),u(!0)},[m,p]);return{measure:(0,t.useCallback)((t,n={})=>{if(!l||t.length<33)return;let r=Ke(t);if(!f.current){f.current=r,d.current=1;return}if(d.current=qe(f.current,r)<e.motionThreshold?d.current+1:1,f.current=r,d.current<e.stableFrameCount)return;let a=He(t,e.referenceHeightCm,e.weightKg,n.silhouetteWidths??null,n.imageWidth??1280,n.imageHeight??720),s=new Date().toISOString(),m=We(a),h=x(a);i({...a,measuredAt:s}),o(m),c(h),u(!1),p()},[e,l,p]),startMeasurement:h,measurements:r,sizeRecommendation:a,garmentScale:s,isMeasuring:l,updateConfig:(0,t.useCallback)(e=>{n(t=>({...t,...e})),p(),m(),u(!1)},[m,p]),config:e}}function Ye(e,t,n,r){if(e<=0||t<=0||n<=0||r<=0)return{x:0,y:0,width:Math.max(0,e),height:Math.max(0,t)};let i=e/t,a=n/r;if(i>a){let n=e,r=n/a;return{x:0,y:(t-r)*.5,width:n,height:r}}let o=t,s=o*a;return{x:(e-s)*.5,y:0,width:s,height:o}}function Xe(e,t,n,r){if(e<=0||t<=0||n<=0||r<=0)return{xMin:0,xMax:1,yMin:0,yMax:1};let i=e/t,a=n/r;if(i>a){let e=(1-a/i)/2;return{xMin:0,xMax:1,yMin:e,yMax:1-e}}let o=(1-i/a)/2;return{xMin:o,xMax:1-o,yMin:0,yMax:1}}var Ze=5,Qe=.5;function $e(e,t,n,r,i=Ze,a=Qe){if(t<=0||n<=0||e.length!==t*n)return null;let o=Math.round(r),s=Math.floor(i/2),c=Math.max(0,o-s),l=Math.min(n-1,o+s),u=0,d=0,f=0;for(let n=c;n<=l;n+=1){let r=-1,i=-1,o=n*t;for(let n=0;n<t;n+=1)e[o+n]>=a&&(r<0&&(r=n),i=n);r>=0&&i>r&&(u+=r,d+=i,f+=1)}if(f===0)return null;let p=u/f;return d/f-p}function et(e,t,n,r){if(r.length<33)return null;let i=r[V.LEFT_SHOULDER],a=r[V.RIGHT_SHOULDER],o=r[V.LEFT_HIP],s=r[V.RIGHT_HIP],c=r[V.LEFT_KNEE],l=r[V.RIGHT_KNEE];if(!i||!a||!o||!s)return null;let u=(i.y+a.y)/2*n,d=(o.y+s.y)/2*n,f=u+(d-u)*.4,p=c&&l?d+((c.y+l.y)/2*n-d)*.2:d,m=$e(e,t,n,u),h=$e(e,t,n,f),g=$e(e,t,n,d),_=$e(e,t,n,p);return m===null||h===null||g===null||_===null?null:{shoulderWidthPx:m,chestWidthPx:h,waistWidthPx:g,hipWidthPx:_}}function W(e,t,n){return e+(t-e)*n}function tt(e,t,n){return t?!e||e.length!==t.length?t:e.map((e,r)=>{let i=t[r];return{x:W(e.x,i.x,n),y:W(e.y,i.y,n),z:W(e.z??0,i.z??0,n),visibility:W(e.visibility??0,i.visibility??0,n)}}):null}function G(e,t,n){return{x:W(e.x,t.x,n),y:W(e.y,t.y,n),z:W(e.z,t.z,n)}}function nt(e,t,n){return!e||!t?t??e:G(e,t,n)}function rt(e,t,n){return t?e?{hips:{position:{x:W(e.hips.position.x,t.hips.position.x,n),y:W(e.hips.position.y,t.hips.position.y,n),z:W(e.hips.position.z,t.hips.position.z,n)},rotation:G(e.hips.rotation,t.hips.rotation,n)},spine:G(e.spine,t.spine,n),chest:G(e.chest,t.chest,n),leftUpperArm:G(e.leftUpperArm,t.leftUpperArm,n),leftLowerArm:G(e.leftLowerArm,t.leftLowerArm,n),rightUpperArm:G(e.rightUpperArm,t.rightUpperArm,n),rightLowerArm:G(e.rightLowerArm,t.rightLowerArm,n),leftUpperLeg:nt(e.leftUpperLeg,t.leftUpperLeg,n),leftLowerLeg:nt(e.leftLowerLeg,t.leftLowerLeg,n),rightUpperLeg:nt(e.rightUpperLeg,t.rightUpperLeg,n),rightLowerLeg:nt(e.rightLowerLeg,t.rightLowerLeg,n)}:t:null}function it(e,t,n){return t?e?{shoulderWidthPx:W(e.shoulderWidthPx,t.shoulderWidthPx,n),chestWidthPx:W(e.chestWidthPx,t.chestWidthPx,n),waistWidthPx:W(e.waistWidthPx,t.waistWidthPx,n),hipWidthPx:W(e.hipWidthPx,t.hipWidthPx,n)}:t:null}function at(){return{landmarks:null,worldLandmarks:null,poseRig:null,confidence:0,isTracking:!1,silhouetteWidths:null}}function ot(e,t,n){return!e||!e.isTracking||!t.isTracking||!t.landmarks?t:{landmarks:tt(e.landmarks,t.landmarks,n),worldLandmarks:tt(e.worldLandmarks,t.worldLandmarks,n),poseRig:rt(e.poseRig,t.poseRig,n),confidence:W(e.confidence,t.confidence,n),isTracking:t.isTracking,silhouetteWidths:it(e.silhouetteWidths,t.silhouetteWidths,n)}}var st=`0.10.32`,ct=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${st}/wasm`,lt=2,ut=3,dt=.5,ft={lite:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/latest/pose_landmarker_lite.task`,full:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_full/float16/latest/pose_landmarker_full.task`,heavy:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_heavy/float16/latest/pose_landmarker_heavy.task`};async function pt(e,t,n,r,i=3){let o=await a.FilesetResolver.forVisionTasks(ct),s={baseOptions:{modelAssetPath:e},runningMode:`VIDEO`,numPoses:i,outputSegmentationMasks:r,minPoseDetectionConfidence:t,minPosePresenceConfidence:n,minTrackingConfidence:n};try{return await a.PoseLandmarker.createFromOptions(o,{...s,baseOptions:{...s.baseOptions,delegate:`GPU`}})}catch{return a.PoseLandmarker.createFromOptions(o,{...s,baseOptions:{...s.baseOptions,delegate:`CPU`}})}}var mt=new o.Vector3,ht=new o.Vector3,gt=new o.Vector3,_t=new o.Quaternion,vt=new o.Vector3,yt=new o.Vector3,bt=new o.Vector3(0,-1,0),xt=new o.Vector3(1,0,0),St=new o.Vector3(-1,0,0),Ct=new o.Vector3(0,1,0),wt=[V.LEFT_SHOULDER,V.RIGHT_SHOULDER],Tt=[V.LEFT_HIP,V.RIGHT_HIP],Et=[V.LEFT_EAR,V.RIGHT_EAR],Dt=[V.LEFT_INDEX,V.LEFT_PINKY],Ot=[V.RIGHT_INDEX,V.RIGHT_PINKY],kt={Hips:{from:Tt,to:wt,restDir:Ct,influence:.35},Spine:{from:Tt,to:wt,restDir:Ct,influence:.55},Chest:{from:wt,to:Et,restDir:Ct,influence:.7},LeftShoulder:{from:wt,to:V.LEFT_SHOULDER,restDir:xt,influence:.45},LeftUpperArm:{from:V.LEFT_SHOULDER,to:V.LEFT_ELBOW,restDir:xt},LeftLowerArm:{from:V.LEFT_ELBOW,to:V.LEFT_WRIST,restDir:xt},LeftHand:{from:V.LEFT_WRIST,to:Dt,restDir:xt,influence:.65},RightShoulder:{from:wt,to:V.RIGHT_SHOULDER,restDir:St,influence:.45},RightUpperArm:{from:V.RIGHT_SHOULDER,to:V.RIGHT_ELBOW,restDir:St},RightLowerArm:{from:V.RIGHT_ELBOW,to:V.RIGHT_WRIST,restDir:St},RightHand:{from:V.RIGHT_WRIST,to:Ot,restDir:St,influence:.65},LeftUpperLeg:{from:V.LEFT_HIP,to:V.LEFT_KNEE,restDir:bt},LeftLowerLeg:{from:V.LEFT_KNEE,to:V.LEFT_ANKLE,restDir:bt},LeftFoot:{from:V.LEFT_ANKLE,to:V.LEFT_FOOT_INDEX,restDir:new o.Vector3(0,0,1)},RightUpperLeg:{from:V.RIGHT_HIP,to:V.RIGHT_KNEE,restDir:bt},RightLowerLeg:{from:V.RIGHT_KNEE,to:V.RIGHT_ANKLE,restDir:bt},RightFoot:{from:V.RIGHT_ANKLE,to:V.RIGHT_FOOT_INDEX,restDir:new o.Vector3(0,0,1)}};function At(e,t,n){return n===`world`?(t.set(-e.x,-e.y,-(e.z??0)),t):(t.set(-(e.x-.5),-(e.y-.5),-(e.z??0)*.5),t)}function jt(e,t,n,r){if(typeof e==`number`){let i=t[e];return!i||(i.visibility??0)<.4?!1:(At(i,n,r),!0)}let i=t[e[0]],a=t[e[1]];return!i||!a||(i.visibility??0)<.4||(a.visibility??0)<.4?!1:(At(i,vt,r),At(a,yt,r),n.copy(vt).add(yt).multiplyScalar(.5),!0)}function Mt(e,t,n,r,i=`normalized`){if(!jt(e,n,mt,i)||!jt(t,n,ht,i))return!1;r.subVectors(ht,mt);let a=r.length();return a<.001?!1:(r.divideScalar(a),!0)}function Nt(e,t,n,r=`normalized`){let i=kt[e];return i?Mt(i.from,i.to,t,n,r):!1}function Pt(e){return kt[e]?.influence}function Ft(e,t,n,r=`normalized`){let i=kt[e];return!i||!Nt(e,t,gt,r)?!1:(n.setFromUnitVectors(i.restDir,gt),i.influence!==void 0&&n.slerp(_t.identity(),1-i.influence),!0)}function It(e){return e in kt}var Lt=new o.Quaternion,Rt=new o.Euler;function zt(){return{x:0,y:0,z:0}}function Bt(e){return Rt.setFromQuaternion(e,`XYZ`),{x:Rt.x,y:Rt.y,z:Rt.z}}function K(e,t,n){return Ft(e,t,Lt,n)?Bt(Lt):zt()}function Vt(e,t,n){if(Ft(e,t,Lt,n))return Bt(Lt)}function Ht(e){let t=e[V.LEFT_HIP],n=e[V.RIGHT_HIP];return{x:((t?.x??0)+(n?.x??0))*.5,y:((t?.y??0)+(n?.y??0))*.5,z:((t?.z??0)+(n?.z??0))*.5}}function Ut(e,t){if(e.length<33)return null;let n=t&&t.length>=33?t:e,r=t&&t.length>=33?`world`:`normalized`;return{hips:{position:Ht(e),rotation:K(`Hips`,n,r)},spine:K(`Spine`,n,r),chest:K(`Chest`,n,r),leftUpperArm:K(`LeftUpperArm`,n,r),leftLowerArm:K(`LeftLowerArm`,n,r),rightUpperArm:K(`RightUpperArm`,n,r),rightLowerArm:K(`RightLowerArm`,n,r),leftUpperLeg:Vt(`LeftUpperLeg`,n,r),leftLowerLeg:Vt(`LeftLowerLeg`,n,r),rightUpperLeg:Vt(`RightUpperLeg`,n,r),rightLowerLeg:Vt(`RightLowerLeg`,n,r)}}function Wt(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.width!=`number`||typeof t.height!=`number`||typeof t.getAsFloat32Array!=`function`?null:t}function Gt(e){if(e)for(let t of e)t&&typeof t==`object`&&`close`in t&&typeof t.close==`function`&&t.close()}function Kt(e,t,n){let r=t/n;return{shoulderWidthPx:e.shoulderWidthPx*r,chestWidthPx:e.chestWidthPx*r,waistWidthPx:e.waistWidthPx*r,hipWidthPx:e.hipWidthPx*r}}var qt=`pose-0`;function Jt(e){return typeof e==`number`?e:0}function Yt(e){return{x:e.x,y:e.y,z:e.z,visibility:Jt(e.visibility)}}function Xt(e){return e.map(Yt)}function Zt(e){return Yt(e)}function Qt(e){let t=Math.PI*2,n=(e+Math.PI)%t;return n<0&&(n+=t),n-Math.PI}function $t(e,t,n){return Qt(e+Qt(t-e)*n)}var en=class{prev=null;config;constructor(e=Ae){this.config=e}smooth(e){if(e.length===0)return this.prev=null,[];let t=Xt(e);if(!this.prev||this.prev.length!==t.length)return this.prev=t.map(Zt),t.map(Zt);let n=this.config.positionAlpha,r=t.map((e,t)=>{let r=this.prev[t];return(e.visibility??0)<this.config.visibilityThreshold?{...Zt(r),visibility:e.visibility}:{x:r.x+n*(e.x-r.x),y:r.y+n*(e.y-r.y),z:r.z+n*(e.z-r.z),visibility:e.visibility}});return this.prev=r.map(Zt),r}reset(){this.prev=null}};function q(e,t,n){return{x:$t(e.x,t.x,n),y:$t(e.y,t.y,n),z:$t(e.z,t.z,n)}}function tn(e,t,n){return t?e?q(e,t,n):t:e}function nn(e,t,n=Ae.rotationAlpha){return e?{hips:{position:{x:e.hips.position.x+n*(t.hips.position.x-e.hips.position.x),y:e.hips.position.y+n*(t.hips.position.y-e.hips.position.y),z:e.hips.position.z+n*(t.hips.position.z-e.hips.position.z)},rotation:q(e.hips.rotation,t.hips.rotation,n)},spine:q(e.spine,t.spine,n),chest:q(e.chest,t.chest,n),leftUpperArm:q(e.leftUpperArm,t.leftUpperArm,n),leftLowerArm:q(e.leftLowerArm,t.leftLowerArm,n),rightUpperArm:q(e.rightUpperArm,t.rightUpperArm,n),rightLowerArm:q(e.rightLowerArm,t.rightLowerArm,n),leftUpperLeg:tn(e.leftUpperLeg,t.leftUpperLeg,n),leftLowerLeg:tn(e.leftLowerLeg,t.leftLowerLeg,n),rightUpperLeg:tn(e.rightUpperLeg,t.rightUpperLeg,n),rightLowerLeg:tn(e.rightLowerLeg,t.rightLowerLeg,n)}:t}var rn=.12,an=.35,on=.05,sn=[11,12,23,24],cn=2,ln=.3;function un(e){if(!e)return null;let t=Math.max(0,Math.min(1,e.x)),n=Math.max(0,Math.min(1,e.y));return{x:t,y:n,w:Math.max(.01,Math.min(1-t,e.w)),h:Math.max(.01,Math.min(1-n,e.h))}}function dn(e){if(!Array.isArray(e)||e.length===0)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0,a=0;return e.forEach(e=>{!e||typeof e.x!=`number`||typeof e.y!=`number`||(e.visibility??0)<an||(t=Math.min(t,e.x),n=Math.min(n,e.y),r=Math.max(r,e.x),i=Math.max(i,e.y),a+=1)}),a<4||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)?null:un({x:t,y:n,w:Math.max(.01,r-t),h:Math.max(.01,i-n)})}function fn(e,t=rn){if(!e)return null;let n=e.w*t,r=e.h*t;return un({x:e.x-n/2,y:e.y-r/2,w:e.w+n,h:e.h+r})}function pn(e,t){if(!e||!t)return 0;let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.w,t.x+t.w),a=Math.min(e.y+e.h,t.y+t.h),o=Math.max(0,i-n)*Math.max(0,a-r);if(o<=0)return 0;let s=e.w*e.h+t.w*t.h-o;return s<=0?0:o/s}function mn(e){return e.length===0?0:e.reduce((e,t)=>e+(t.visibility??0),0)/e.length}function hn(e,t=[]){return e.flatMap((e,n)=>{let r=dn(e),i=fn(r);return!r||!i?[]:[{poseIndex:n,personId:`pose-${n}`,landmarks:e,worldLandmarks:t[n]??null,bounds:r,expandedBounds:i,meanVisibility:mn(e),area:i.w*i.h}]})}function gn(e,t){let n=pn(e.expandedBounds,t.expandedBounds);return{iou:n,score:n*.75+e.area*.25}}function _n(e,{previousCandidate:t,allowRelock:n=!1,minIouToKeep:r=on}){if(e.length===0)return null;let i=[...e].sort((e,t)=>t.area*t.meanVisibility-e.area*e.meanVisibility);if(!t)return i[0];let a=null,o=-1/0,s=0;return e.forEach(e=>{let{iou:n,score:r}=gn(e,t);r>o&&(a=e,o=r,s=n)}),a&&s>=r?a:n?i[0]:null}function vn(e,t){if(!t)return!0;let n=0,r=0,i=0;for(let t of sn){let a=e.landmarks[t];a&&(a.visibility??0)>ln&&(n+=a.x,r+=a.y,i+=1)}if(i<cn)return!0;let a=n/i,o=r/i;return a>=t.xMin&&a<=t.xMax&&o>=t.yMin&&o<=t.yMax}function yn(e,t){return t?e.filter(e=>vn(e,t)):e}function bn(e){return e?{poseIndex:e.poseIndex,personId:e.personId,bounds:e.bounds,expandedBounds:e.expandedBounds}:null}var xn=.55,Sn=640,Cn=360;function wn(e=null){return{level:`idle`,reasons:[`no_person_detected`],updatedAt:e}}function Tn({detectedPersonCount:e,isTracking:t,lockedPersonId:n=null,meanVisibility:r=null,frameWidth:i=0,frameHeight:a=0,updatedAt:o=Date.now()}){if(e<1)return wn(o);let s=[];return e>1&&s.push(`multi_person_detected`),i>0&&a>0&&(i<Sn||a<Cn)&&s.push(`resolution_too_low`),r!==null&&r<xn&&s.push(`low_visibility`),(!n||!t)&&s.push(`pose_not_locked`),s.length===0?{level:`good`,reasons:[],updatedAt:o}:{level:s.includes(`resolution_too_low`)?`blocked`:`degraded`,reasons:s,updatedAt:o}}function En(){return{detectedPersonCount:0,lockedPersonId:null,trackingQuality:wn()}}function Dn({detectedPersonCount:e,isTracking:t,lockedPersonId:n,meanVisibility:r,frameWidth:i,frameHeight:a,updatedAt:o}){let s=n??(t&&e>0?`pose-0`:null);return{detectedPersonCount:e,lockedPersonId:s,trackingQuality:Tn({detectedPersonCount:e,isTracking:t,lockedPersonId:s,meanVisibility:r,frameWidth:i,frameHeight:a,updatedAt:o})}}var On=180;function kn(e,t,n=180){return e===null?!1:t-e<=n}function An(e){return!e||!e.isTracking||!e.landmarks||!e.poseRig?null:{...e,isTracking:!0}}function jn(e,t,n=qt){return{detectedPersonCount:e,lockedPersonId:n,trackingQuality:{level:`degraded`,reasons:[`tracking_lost`],updatedAt:t}}}function Mn(){return{landmarks:null,worldLandmarks:null,poseRig:null,confidence:0,fps:0,isTracking:!1}}var Nn=(e,n={})=>{let{enabled:r=!0,modelComplexity:i=`lite`,numPoses:o=3,minDetectionConfidence:s=.5,minTrackingConfidence:c=.5,outputSegmentationMasks:l=!1,viewportWidth:u=0,viewportHeight:d=0}=n,f=(0,t.useRef)(null),p=(0,t.useRef)(new en(Ae)),m=(0,t.useRef)(null),h=(0,t.useRef)(null),g=(0,t.useRef)(null),_=(0,t.useRef)(-1),v=(0,t.useRef)({width:0,height:0}),y=(0,t.useRef)(0),b=(0,t.useRef)(null),x=(0,t.useRef)(null),S=(0,t.useRef)(null),C=(0,t.useRef)(null),w=(0,t.useRef)(null),T=(0,t.useRef)(En()),E=(0,t.useRef)({frames:0,lastMeasuredAt:0}),D=(0,t.useRef)(null),O=(0,t.useRef)({width:0,height:0}),[k,A]=(0,t.useState)(!1),[j,M]=(0,t.useState)(Mn),[ee,N]=(0,t.useState)(null),[P,F]=(0,t.useState)({width:0,height:0}),[I,L]=(0,t.useState)(En()),R=(0,t.useCallback)((e,t=T.current)=>{h.current=e.landmarks,T.current=t,M(t=>({...t,landmarks:e.landmarks,worldLandmarks:e.worldLandmarks,poseRig:e.poseRig,confidence:e.confidence,isTracking:e.isTracking})),N(e.silhouetteWidths),L(t)},[]),z=(0,t.useCallback)(()=>{p.current.reset(),m.current=null,h.current=null,_.current=-1,v.current={width:0,height:0},y.current=0,b.current=null,x.current=null,S.current=null,C.current=null,w.current=null,T.current=En(),E.current={frames:0,lastMeasuredAt:0},M(Mn()),N(null),F({width:0,height:0}),L(En())},[]);(0,t.useEffect)(()=>{if(!r){A(!1),z();return}let e=!1;async function t(){try{let t=await pt(ft[i],s,c,l,o);if(e){t.close();return}f.current=t,E.current.lastMeasuredAt=performance.now(),A(!0)}catch(e){console.error(`Failed to initialize MediaPipe Pose Landmarker:`,e)}}return t(),()=>{e=!0,A(!1),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),f.current?.close(),f.current=null,z()}},[r,s,c,i,o,l,z]),O.current={width:u,height:d},(0,t.useEffect)(()=>{if(!r||!k)return;let t=()=>{let n=e.current,r=f.current;if(!n||!r||n.readyState<HTMLMediaElement.HAVE_CURRENT_DATA){g.current=requestAnimationFrame(t);return}if(n.currentTime===_.current){g.current=requestAnimationFrame(t);return}_.current=n.currentTime;let i=n.videoWidth||n.clientWidth||1280,a=n.videoHeight||n.clientHeight||720;(i!==v.current.width||a!==v.current.height)&&(v.current={width:i,height:a},F({width:i,height:a}));let o=O.current;D.current=o.width>0&&o.height>0?Xe(o.width,o.height,i,a):null;let s=performance.now();try{let e=b.current===null||y.current===0;if(y.current=(y.current+1)%2,e){let e=r.detectForVideo(n,s);try{let t=yn(hn(e.landmarks,e.worldLandmarks),D.current),n=t.length,r=!kn(C.current,s),o=_n(t,{previousCandidate:w.current,allowRelock:r}),u=o?.landmarks??null,d=o?.worldLandmarks??null,f=o||w.current?qt:null,h=at(),g=Dn({detectedPersonCount:n,isTracking:!1,lockedPersonId:f,frameWidth:i,frameHeight:a,updatedAt:s}),_=kn(C.current,s)?An(S.current):null;if(!u)_?(h=_,g=jn(n,s,f)):(p.current.reset(),m.current=null,S.current=null,C.current=null,w.current=null,g=Dn({detectedPersonCount:n,isTracking:!1,lockedPersonId:null,frameWidth:i,frameHeight:a,updatedAt:s}));else{r&&o&&(p.current.reset(),m.current=null);let t=p.current.smooth(Xt(u)),v=d?Xt(d):null,y=Ut(t,v),b=t.reduce((e,t)=>e+(t.visibility??0),0)/t.length,x=b>=c?y?nn(m.current,y,Ae.rotationAlpha):m.current:null,T=x!==null,E=null;if(w.current=o?bn(o):w.current,l){let n=Wt(o?e.segmentationMasks?.[o.poseIndex]:void 0);if(n){let e=et(new Float32Array(n.getAsFloat32Array()),n.width,n.height,t);e&&(E=Kt(e,i,n.width))}}T&&x?(m.current=x,h={landmarks:t,worldLandmarks:v,poseRig:x,confidence:b,isTracking:T,silhouetteWidths:E},S.current=h,C.current=s,g=Dn({detectedPersonCount:n,isTracking:T,lockedPersonId:qt,meanVisibility:o?.meanVisibility??b,frameWidth:i,frameHeight:a,updatedAt:s})):_?(h=_,g=jn(n,s,f)):(m.current=null,S.current=null,C.current=null,h={landmarks:t,worldLandmarks:v,poseRig:null,confidence:b,isTracking:!1,silhouetteWidths:E},g=Dn({detectedPersonCount:n,isTracking:!1,lockedPersonId:o?qt:null,meanVisibility:o?.meanVisibility??b,frameWidth:i,frameHeight:a,updatedAt:s}))}let v=b.current;b.current=h,T.current=g;let y=ot(v,h,dt);x.current=y,R(y,g)}finally{Gt(e.segmentationMasks)}}else x.current&&R(x.current,T.current)}catch{}let u=E.current;if(u.frames+=1,u.lastMeasuredAt===0&&(u.lastMeasuredAt=s),s-u.lastMeasuredAt>=1e3){let e=u.frames;u.frames=0,u.lastMeasuredAt=s,M(t=>({...t,fps:e}))}g.current=requestAnimationFrame(t)};return g.current=requestAnimationFrame(t),()=>{g.current!==null&&(cancelAnimationFrame(g.current),g.current=null)}},[r,k,c,l,R,e]);let B=(0,t.useCallback)(t=>{let n=e.current,r=t.getContext(`2d`);if(!n||!r)return;t.width=n.videoWidth||t.clientWidth||1280,t.height=n.videoHeight||t.clientHeight||720,r.clearRect(0,0,t.width,t.height);let i=h.current;if(!i)return;let o=Xt(i),s=new a.DrawingUtils(r);s.drawLandmarks(o,{radius:3,color:`#00FF88`,fillColor:`#00FF88`}),s.drawConnectors(o,a.PoseLandmarker.POSE_CONNECTIONS,{color:`#00C8FF`,lineWidth:2})},[e]);return{...j,isTrackerReady:k,drawLandmarks:B,silhouetteWidths:ee,poseFrameWidth:P.width,poseFrameHeight:P.height,detectedPersonCount:I.detectedPersonCount,lockedPersonId:I.lockedPersonId,trackingQuality:I.trackingQuality}};function Pn(e){if(!(e instanceof DOMException))return`Failed to start the camera.`;switch(e.name){case`NotAllowedError`:return`Camera permission was denied.`;case`NotFoundError`:return`No available camera was found.`;case`NotReadableError`:return`The camera is already in use by another app.`;case`OverconstrainedError`:return`The requested camera settings are not supported.`;default:return`Failed to start the camera.`}}function Fn(e={}){let{width:n=1280,height:r=720,facingMode:i=`user`,enabled:a=!0,mockMode:o=!1,videoRef:s,onReadyChange:c,onErrorChange:l}=e,u=(0,t.useRef)(null),d=(0,t.useMemo)(()=>({get current(){return u.current},set current(e){u.current=e,s&&(s.current=e)}}),[s]),f=(0,t.useRef)(null),p=(0,t.useRef)(!1),m=(0,t.useRef)(0),[h,g]=(0,t.useState)(!1),[_,v]=(0,t.useState)(null),y=(0,t.useCallback)(e=>{g(e),c?.(e)},[c]),b=(0,t.useCallback)(e=>{v(e),l?.(e)},[l]),x=(0,t.useCallback)(()=>{f.current&&=(f.current.getTracks().forEach(e=>e.stop()),null),d.current&&(d.current.pause(),d.current.srcObject=null),y(!1)},[y,d]),S=(0,t.useCallback)(()=>{m.current+=1,x()},[x]),C=(0,t.useCallback)(()=>{if(d.current)return d.current;let e=document.createElement(`video`);return e.playsInline=!0,e.autoplay=!0,e.muted=!0,e.setAttribute(`playsinline`,`true`),d.current=e,e},[d]),w=(0,t.useCallback)(async()=>{let e=m.current+1;if(m.current=e,x(),b(null),o){C(),y(!0);return}if(!navigator.mediaDevices?.getUserMedia){b(`This browser does not support camera access.`);return}try{let t=C(),a=await navigator.mediaDevices.getUserMedia({video:{width:n,height:r,facingMode:i},audio:!1});if(!p.current||m.current!==e){a.getTracks().forEach(e=>e.stop());return}if(f.current=a,t.srcObject=a,await t.play(),!p.current||m.current!==e){a.getTracks().forEach(e=>e.stop());return}y(!0)}catch(t){if(m.current!==e)return;x(),b(Pn(t))}},[C,i,r,o,b,y,x,n]);return(0,t.useEffect)(()=>(p.current=!0,()=>{p.current=!1,S()}),[S]),(0,t.useEffect)(()=>{if(p.current){if(!a){S();return}w()}},[a,w,S]),{videoRef:d,isReady:h,error:_,start:w,stop:S}}function In(e={}){let{width:n=1280,height:r=720,facingMode:i=`user`,enabled:a=!0,mockMode:o=!1,modelComplexity:s=`lite`,numPoses:c,minDetectionConfidence:l,minTrackingConfidence:u,outputSegmentationMasks:d=!0,viewportWidth:f=0,viewportHeight:p=0,measurementEnabled:m=!0,autoStartMeasurement:h=!1,measurementConfig:g,bodyPresetOptions:_,fitType:v=`regular`,garmentScaleHint:y=null}=e,b=Fn({width:n,height:r,facingMode:i,enabled:a,mockMode:o}),x=Nn(b.videoRef,{enabled:a,modelComplexity:s,numPoses:c,minDetectionConfidence:l,minTrackingConfidence:u,outputSegmentationMasks:d,viewportWidth:f,viewportHeight:p}),{config:S,measurements:C,sizeRecommendation:w,garmentScale:T,isMeasuring:E,measure:D,startMeasurement:O,updateConfig:k}=Je(),A=a&&b.isReady&&x.isTracking,j=ke(C,_),M=(0,t.useMemo)(()=>ce({measurements:C,measurementScale:T,presetSelection:j.selection,fitType:v,garmentScaleHint:y}),[j.selection,v,T,y,C]);return(0,t.useEffect)(()=>{g&&k(g)},[g,k]),(0,t.useEffect)(()=>{!m||!h||!A||C||E||O()},[h,A,m,C,E,O]),(0,t.useEffect)(()=>{!m||!E||!x.landmarks||D(x.landmarks,{silhouetteWidths:x.silhouetteWidths,imageWidth:x.poseFrameWidth||n,imageHeight:x.poseFrameHeight||r})},[r,m,E,D,x.landmarks,x.poseFrameHeight,x.poseFrameWidth,x.silhouetteWidths,n]),(0,t.useMemo)(()=>({videoRef:b.videoRef,webcamReady:b.isReady,webcamError:b.error,startWebcam:b.start,stopWebcam:b.stop,isTrackerReady:x.isTrackerReady,landmarks:x.landmarks,worldLandmarks:x.worldLandmarks,poseRig:x.poseRig,confidence:x.confidence,fps:x.fps,isTracking:x.isTracking,drawLandmarks:x.drawLandmarks,silhouetteWidths:x.silhouetteWidths,poseFrameWidth:x.poseFrameWidth,poseFrameHeight:x.poseFrameHeight,detectedPersonCount:x.detectedPersonCount,lockedPersonId:x.lockedPersonId,trackingQuality:x.trackingQuality,config:S,measurements:C,sizeRecommendation:w,garmentScale:T,finalGarmentScale:M.scale,bodyMorphResult:M.morph,isMeasuring:E,canMeasure:A,startMeasurement:O,updateConfig:k,bodyPresetSelection:j.selection,bodyPresetLoading:j.loading,bodyPresetError:j.error}),[M.morph,M.scale,j.error,j.loading,j.selection,A,S,T,E,C,w,O,x.confidence,x.detectedPersonCount,x.drawLandmarks,x.fps,x.isTrackerReady,x.isTracking,x.landmarks,x.lockedPersonId,x.poseFrameHeight,x.poseFrameWidth,x.poseRig,x.silhouetteWidths,x.trackingQuality,x.worldLandmarks,k,b.error,b.isReady,b.start,b.stop,b.videoRef])}function Ln(e){let t=new o.Vector3,n=new o.Quaternion,r=new o.Quaternion;return e.updateWorldMatrix(!0,!1),e.getWorldPosition(t),e.getWorldQuaternion(n),e.parent?e.parent.getWorldQuaternion(r):r.identity(),{bone:e,restQuaternion:e.quaternion.clone(),restScale:e.scale.clone(),restWorldPosition:t,restWorldQuaternion:n,restParentWorldQuaternion:r}}function Rn(e){let t=new o.Box3,n={current:!1},r=new o.Vector3,i=new o.Box3;return e.updateMatrixWorld(!0),e.traverse(e=>{if(!(e instanceof o.Mesh)||e.name.startsWith(`Collision`)||!e.visible)return;let a=e.geometry.getAttribute(`skinIndex`)&&e.geometry.getAttribute(`skinWeight`);if(e instanceof o.SkinnedMesh&&a){if(e.computeBoundingBox(),!e.boundingBox)return;i.copy(e.boundingBox)}else{if(e.geometry.computeBoundingBox(),!e.geometry.boundingBox)return;i.copy(e.geometry.boundingBox)}let{min:s,max:c}=i;[[s.x,s.y,s.z],[s.x,s.y,c.z],[s.x,c.y,s.z],[s.x,c.y,c.z],[c.x,s.y,s.z],[c.x,s.y,c.z],[c.x,c.y,s.z],[c.x,c.y,c.z]].forEach(([i,a,o])=>{if(r.set(i,a,o).applyMatrix4(e.matrixWorld),!n.current){t.min.copy(r),t.max.copy(r),n.current=!0;return}t.expandByPoint(r)})}),n.current||t.makeEmpty(),t}function zn(e){if(!e||e.length===0)return null;let t=new o.Vector3,n=new o.Vector3;return e.forEach(({bone:e})=>{e.getWorldPosition(n),t.add(n)}),t.multiplyScalar(1/e.length)}function Bn(e,t){for(let n=0;n<t.length;n+=1){let r=zn(e.get(t[n]));if(r)return r}return null}function Vn(e,t,n=1){e.updateMatrixWorld(!0);let r=Rn(e),i=r.getCenter(new o.Vector3),a=r.getSize(new o.Vector3),s=new o.Vector3(i.x,r.min.y+a.y*.74,i.z),c=new o.Vector3(i.x,r.min.y+a.y*.42,i.z),l=Bn(t,[`LeftUpperArm`,`LeftShoulder`]),u=Bn(t,[`RightUpperArm`,`RightShoulder`]),d=Bn(t,[`Hips`]),f=Bn(t,[`LeftUpperLeg`]),p=Bn(t,[`RightUpperLeg`]),m=l??s.clone().setX(i.x+a.x*.18),h=u??s.clone().setX(i.x-a.x*.18),g=d??c,_=m.clone().add(h).multiplyScalar(.5),v=f&&p?f.clone().add(p).multiplyScalar(.5):g.clone(),y=!!(l&&u),b=y&&!!(d||f&&p),x=m.distanceTo(h),S=_.distanceTo(v),C=y?Math.max(x,1e-4):Math.max(x,a.x*.3,n),w=b?Math.max(S,1e-4):Math.max(S,a.y*.28,1e-4),T=b?_.clone().add(v).multiplyScalar(.5):i.clone(),E=r.clone();if(b){let e=Math.min(_.y,v.y),t=Math.max(_.y,v.y);E.min.y=Math.max(E.min.y,e),E.max.y=Math.min(E.max.y,t),E.max.y<=E.min.y&&E.copy(r)}let D=E.getCenter(new o.Vector3),O=E.getSize(new o.Vector3);return{anchor:T,shoulderCenter:_,hipCenter:v,referenceWidth:C,referenceTorsoHeight:w,trackingHeight:Math.max(a.y,w,1e-4),boundsCenter:D,boundsSize:O,hasBoneAnchors:b}}function Hn(e){for(let t of e.values())t.forEach(({bone:e,restQuaternion:t,restScale:n})=>{e.quaternion.copy(t),e.scale.copy(n)})}var Un=`__nativeVRMPrepared`;function Wn(e){try{return new URL(e,`https://avatar.local`).pathname}catch{return e}}function Gn(e){return Wn(e).toLowerCase().endsWith(`.vrm`)}function Kn(e){return Gn(e)?`vrm`:`gltf`}function qn(e,t){Gn(t)&&e.register(e=>new c.VRMLoaderPlugin(e))}function Jn(e){if(Gn(e))return t=>{qn(t,e)}}function Yn(e){e.traverse(e=>{e.frustumCulled=!1})}function Xn(e){let t=e.scene.userData;t[Un]||(c.VRMUtils.rotateVRM0(e),t[Un]=!0),Yn(e.scene)}var Zn={Hips:[`hips`],Spine:[`spine`],Chest:[`chest`,`upperChest`],Neck:[`neck`],Head:[`head`],LeftShoulder:[`leftShoulder`],LeftUpperArm:[`leftUpperArm`],LeftLowerArm:[`leftLowerArm`],LeftHand:[`leftHand`],RightShoulder:[`rightShoulder`],RightUpperArm:[`rightUpperArm`],RightLowerArm:[`rightLowerArm`],RightHand:[`rightHand`],LeftUpperLeg:[`leftUpperLeg`],LeftLowerLeg:[`leftLowerLeg`],LeftFoot:[`leftFoot`],RightUpperLeg:[`rightUpperLeg`],RightLowerLeg:[`rightLowerLeg`],RightFoot:[`rightFoot`]};function Qn(e){let t=new Map;return Object.entries(Zn).forEach(([n,r])=>{for(let i=0;i<r.length;i+=1){let a=e.getNormalizedBoneNode(r[i]);if(a){t.set(n,[Ln(a)]);break}}}),t}var $n={root:`hips`,c_spine0:`spine`,c_spine1:`spine`,c_spine2:`chest`,c_spine3:`upperChest`,c_neck:`neck`,c_head:`head`,l_clavicle:`leftShoulder`,l_uparm:`leftUpperArm`,l_lowarm:`leftLowerArm`,l_wrist:`leftHand`,r_clavicle:`rightShoulder`,r_uparm:`rightUpperArm`,r_lowarm:`rightLowerArm`,r_wrist:`rightHand`,l_upleg:`leftUpperLeg`,l_lowleg:`leftLowerLeg`,l_foot:`leftFoot`,r_upleg:`rightUpperLeg`,r_lowleg:`rightLowerLeg`,r_foot:`rightFoot`},er={bone_0:`hips`,bone_1:`spine`,bone_2:`chest`,bone_3:`upperChest`,bone_4:`neck`,bone_5:`head`,bone_6:`leftShoulder`,bone_7:`leftUpperArm`,bone_8:`leftLowerArm`,bone_9:`leftHand`,bone_25:`rightShoulder`,bone_26:`rightUpperArm`,bone_27:`rightLowerArm`,bone_28:`rightHand`,bone_44:`leftUpperLeg`,bone_45:`leftLowerLeg`,bone_46:`leftFoot`,bone_48:`rightUpperLeg`,bone_49:`rightLowerLeg`,bone_50:`rightFoot`},tr={Root:`hips`,Hips:`hips`,Spine:`spine`,Chest:`chest`,Neck:`neck`,Head:`head`,LeftShoulder:`leftShoulder`,LeftUpperArm:`leftUpperArm`,LeftLowerArm:`leftLowerArm`,LeftHand:`leftHand`,RightShoulder:`rightShoulder`,RightUpperArm:`rightUpperArm`,RightLowerArm:`rightLowerArm`,RightHand:`rightHand`,LeftUpperLeg:`leftUpperLeg`,LeftLowerLeg:`leftLowerLeg`,LeftFoot:`leftFoot`,RightUpperLeg:`rightUpperLeg`,RightLowerLeg:`rightLowerLeg`,RightFoot:`rightFoot`};function nr(e,t){if(t?.humanoid)return{getNormalizedBoneNode:e=>t.humanoid.getNormalizedBoneNode(e)??null,update:e=>t.update(e),vrm:t};let n=new Map;return e.traverse(e=>{if(!(e instanceof o.Bone))return;let t=e.name,r=$n[t];r&&!n.has(r)&&n.set(r,e);let i=tr[t];i&&!n.has(i)&&n.set(i,e);let a=er[t];a&&!n.has(a)&&n.set(a,e)}),{getNormalizedBoneNode:e=>n.get(e)??null,update:()=>{},vrm:null}}function rr(e){let t=(0,s.clone)(e);return Yn(t),t.traverse(e=>{if(e instanceof o.Mesh){if(Array.isArray(e.material)){e.material=e.material.map(e=>e.clone());return}e.material=e.material.clone()}}),t}function ir({url:e}){let n=(0,r.useGLTF)(e,`/draco/`,!0,(0,t.useMemo)(()=>Jn(e),[e])),i=n.userData?.vrm??null,a=(0,t.useMemo)(()=>i?(Xn(i),i.scene):rr(n.scene),[n.scene,i]),o=(0,t.useMemo)(()=>nr(a,i),[a,i]);return{scene:a,humanoid:o,bones:(0,t.useMemo)(()=>Qn(o),[o])}}var J=Math.PI/180,ar={min:-70*J,max:70*J},or={min:-45*J,max:45*J},sr={min:-150*J,max:150*J},cr={min:-90*J,max:90*J},lr={min:0,max:150*J},ur={Hips:{rigKey:`hips`,rotationScale:{x:.7,y:.3,z:.7}},Spine:{rigKey:`spine`,rotationScale:{x:.85,y:.4,z:.85}},Chest:{rigKey:`chest`,rotationScale:{x:.75,y:.35,z:.75}},Neck:{rigKey:null},Head:{rigKey:null},LeftShoulder:{rigKey:`leftUpperArm`,rotationScale:.45,rotationLimits:{x:ar,z:or}},LeftUpperArm:{rigKey:`leftUpperArm`,rotationScale:1,rotationLimits:{x:sr,z:cr}},LeftLowerArm:{rigKey:`leftLowerArm`,rotationScale:1,rotationLimits:{x:lr}},LeftHand:{rigKey:`leftLowerArm`,rotationScale:.5},RightShoulder:{rigKey:`rightUpperArm`,rotationScale:.45,rotationLimits:{x:ar,z:or}},RightUpperArm:{rigKey:`rightUpperArm`,rotationScale:1,rotationLimits:{x:sr,z:cr}},RightLowerArm:{rigKey:`rightLowerArm`,rotationScale:1,rotationLimits:{x:lr}},RightHand:{rigKey:`rightLowerArm`,rotationScale:.5},LeftUpperLeg:{rigKey:`leftUpperLeg`,rotationScale:.9},LeftLowerLeg:{rigKey:`leftLowerLeg`,rotationScale:.9},LeftFoot:{rigKey:null},RightUpperLeg:{rigKey:`rightUpperLeg`,rotationScale:.9},RightLowerLeg:{rigKey:`rightLowerLeg`,rotationScale:.9},RightFoot:{rigKey:null}},dr={Root:`Hips`,root:`Hips`,c_spine0:`Spine`,c_spine1:`Spine`,c_spine2:`Chest`,c_spine3:`Chest`,c_neck:`Neck`,c_head:`Head`,l_clavicle:`LeftShoulder`,l_uparm:`LeftUpperArm`,l_lowarm:`LeftLowerArm`,l_wrist:`LeftHand`,r_clavicle:`RightShoulder`,r_uparm:`RightUpperArm`,r_lowarm:`RightLowerArm`,r_wrist:`RightHand`,l_upleg:`LeftUpperLeg`,l_lowleg:`LeftLowerLeg`,l_foot:`LeftFoot`,r_upleg:`RightUpperLeg`,r_lowleg:`RightLowerLeg`,r_foot:`RightFoot`,mixamorig_Hips:`Hips`,mixamorig_Spine:`Spine`,mixamorig_Spine1:`Chest`,mixamorig_Neck:`Neck`,mixamorig_Head:`Head`,mixamorig_LeftShoulder:`LeftShoulder`,mixamorig_LeftArm:`LeftUpperArm`,mixamorig_LeftForeArm:`LeftLowerArm`,mixamorig_LeftHand:`LeftHand`,mixamorig_RightShoulder:`RightShoulder`,mixamorig_RightArm:`RightUpperArm`,mixamorig_RightForeArm:`RightLowerArm`,mixamorig_RightHand:`RightHand`,mixamorig_LeftUpLeg:`LeftUpperLeg`,mixamorig_LeftLeg:`LeftLowerLeg`,mixamorig_LeftFoot:`LeftFoot`,mixamorig_RightUpLeg:`RightUpperLeg`,mixamorig_RightLeg:`RightLowerLeg`,mixamorig_RightFoot:`RightFoot`};function fr(e){return ur[e]?e:dr[e]??e}function pr(e,t){let n=ur[fr(e)];if(!n||!n.rigKey)return null;let r=t[n.rigKey];if(!r)return null;let i=mr(n.rigKey===`hips`&&`rotation`in r?r.rotation:r,n.rotationScale);return{x:hr(i.x,n.rotationLimits?.x),y:hr(i.y,n.rotationLimits?.y),z:hr(i.z,n.rotationLimits?.z)}}function mr(e,t=1){return typeof t==`number`?{x:e.x*t,y:e.y*t,z:e.z*t}:{x:e.x*(t.x??1),y:e.y*(t.y??1),z:e.z*(t.z??1)}}function hr(e,t){return t?Math.min(t.max,Math.max(t.min,e)):e}var gr=12,_r=new o.Quaternion,Y=new o.Quaternion,vr=new o.Quaternion,yr=new o.Vector3,br=new o.Vector3,X=new o.Vector3,xr=new o.Vector3,Sr=new o.Vector3,Cr=new o.Vector3,wr=new o.Vector3,Tr=new o.Vector3,Er=new o.Vector3,Dr=new o.Quaternion,Or=new o.Quaternion,kr=new o.Quaternion,Ar=new o.Quaternion,jr={Hips:[`Spine`,`Chest`,`Neck`],Spine:[`Chest`,`Neck`],Chest:[`Neck`,`Head`],Neck:[`Head`],LeftShoulder:[`LeftUpperArm`],LeftUpperArm:[`LeftLowerArm`],LeftLowerArm:[`LeftHand`],RightShoulder:[`RightUpperArm`],RightUpperArm:[`RightLowerArm`],RightLowerArm:[`RightHand`],LeftUpperLeg:[`LeftLowerLeg`],LeftLowerLeg:[`LeftFoot`],RightUpperLeg:[`RightLowerLeg`],RightLowerLeg:[`RightFoot`]},Mr={Hips:[[`LeftUpperLeg`,`RightUpperLeg`],[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`]],Spine:[[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`],[`LeftUpperLeg`,`RightUpperLeg`]],Chest:[[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`],[`LeftUpperLeg`,`RightUpperLeg`]]},Nr={Hips:[V.RIGHT_HIP,V.LEFT_HIP],Spine:[V.RIGHT_SHOULDER,V.LEFT_SHOULDER],Chest:[V.RIGHT_SHOULDER,V.LEFT_SHOULDER]};function Pr(e){return e.startsWith(`Left`)?`Right${e.slice(4)}`:e.startsWith(`Right`)?`Left${e.slice(5)}`:e}function Fr(e,t,n,r){let i=jr[e];if(!i)return!1;for(let e=0;e<i.length;e+=1){let a=n.get(i[e])?.[0];if(!(!a||a.bone===t.bone||!t.restWorldPosition||!t.restParentWorldQuaternion||!a.restWorldPosition)&&(r.copy(a.restWorldPosition).sub(t.restWorldPosition),!(r.lengthSq()<1e-6)))return r.applyQuaternion(Dr.copy(t.restParentWorldQuaternion).invert()).normalize(),!0}return!1}function Ir(e){return e in Mr}function Lr(e,t,n,r){let i=Mr[e];if(!i||!t.restParentWorldQuaternion)return!1;for(let e=0;e<i.length;e+=1){let[a,o]=i[e],s=n.get(a)?.[0],c=n.get(o)?.[0];if(!(!s?.restWorldPosition||!c?.restWorldPosition)&&(r.copy(c.restWorldPosition).sub(s.restWorldPosition).applyQuaternion(Dr.copy(t.restParentWorldQuaternion).invert()),!(r.lengthSq()<1e-6)))return r.normalize(),!0}return!1}function Rr(e,t,n,r,i){let a=Nr[e];return!a||!Mt(a[0],a[1],t,i,n)?!1:(i.applyQuaternion(kr.copy(r).invert()).normalize(),i.lengthSq()>=1e-6)}function zr(e,t,n,r,i,a,o,s){if(!Lr(e,t,n,xr)||!Rr(e,r,i,a,Sr)||(Cr.copy(xr).applyQuaternion(Y),wr.copy(Cr).projectOnPlane(X).normalize(),Tr.copy(Sr).projectOnPlane(X).normalize(),wr.lengthSq()<1e-6||Tr.lengthSq()<1e-6))return s.copy(Y),!1;Er.crossVectors(wr,Tr);let c=Math.atan2(X.dot(Er),wr.dot(Tr));return Ar.setFromAxisAngle(X,c),s.copy(Ar).multiply(Y),o!==void 0&&s.slerp(vr,1-o),!0}function Br(){let e=(0,t.useRef)(new o.Timer),n=(0,t.useRef)(new Map);return(0,t.useMemo)(()=>({clockRef:e,prevRotationsRef:n}),[])}function Vr(e,t,n,r={}){if(t.size===0)return;let{coordinateSpace:i=`normalized`,excludeBones:a}=r;n.clockRef.current.update();let o=n.clockRef.current.getDelta(),s=Math.min(1,o*gr);for(let[n,r]of t){let o=fr(n);if(a?.has(o))continue;let c=Pr(o);if(o!==n&&t.has(o))continue;let l=It(c);if(!l)continue;let u=l&&Nt(c,e,yr,i);if(!u)continue;let d=!1,f=Pt(c);for(let n of r){let{bone:r,restQuaternion:a}=n;if(u&&Fr(o,n,t,br))r.parent?(r.parent.updateWorldMatrix(!0,!1),r.parent.getWorldQuaternion(Or)):(r.updateWorldMatrix(!0,!1),Or.identity()),X.copy(yr).applyQuaternion(kr.copy(Or).invert()).normalize(),Y.setFromUnitVectors(br,X),Ir(o)&&zr(o,n,t,e,i,Or,f,Y)||f!==void 0&&Y.slerp(vr,1-f),_r.copy(Y).multiply(a);else{if(d||=Ft(c,e,Y,i),!d)continue;_r.copy(a).multiply(Y)}r.quaternion.slerp(_r,s),r.updateWorldMatrix(!1,!0)}}}function Hr(e,t){Hn(e),t.prevRotationsRef.current.clear()}function Ur(e,t,n,r){let i=Math.min(1,n*gr);for(let[n,a]of e){let e=fr(n);if(!(r&&!r.has(e)))for(let{bone:e,restQuaternion:n}of a)e.quaternion.slerp(n,t*i)}}var Wr=50*Math.PI/180,Gr=30*Math.PI/180,Kr=3;function qr(e){return Math.abs(e)<Wr?`unknown`:e>=0?`positive`:`negative`}function Jr(e){return e===`positive`?1:e===`negative`?-1:0}var Yr=class{_committedYawDirection=`unknown`;_pendingYawDirection=`unknown`;_pendingCount=0;update(e,t){let n=Math.abs(t),r=qr(t);return e===`back`||n<Gr?(this.reset(),this._buildState(r,`unknown`,t)):this._committedYawDirection===`unknown`?r===`unknown`?(this._clearPending(),this._buildState(r,`unknown`,t)):(this._pendingYawDirection===r?this._pendingCount+=1:(this._pendingYawDirection=r,this._pendingCount=1),this._pendingCount>=Kr?(this._committedYawDirection=this._pendingYawDirection,this._clearPending(),this._buildState(r,this._committedYawDirection,n*Jr(this._committedYawDirection))):this._buildState(r,r,t)):this._buildState(r,this._committedYawDirection,n*Jr(this._committedYawDirection))}reset(){this._committedYawDirection=`unknown`,this._clearPending()}_buildState(e,t,n){return{rawYawDirection:e,yawDirection:t,committedYawDirection:this._committedYawDirection,pendingYawDirection:this._pendingYawDirection,pendingCount:this._pendingCount,stableYaw:n}}_clearPending(){this._pendingYawDirection=`unknown`,this._pendingCount=0}},Xr=80*Math.PI/180,Zr=100*Math.PI/180,Qr=25*Math.PI/180,$r=8,ei=5,ti=5,ni=5,ri=.5,ii=.3,ai=.2,oi=5,si=8;function ci(e){return e?.visibility??0}function li(e){if(!e||e.length<33)return{shoulderOrder:!1,noseVisible:!1,earSymmetry:!1};let t=e[V.LEFT_SHOULDER],n=e[V.RIGHT_SHOULDER],r=e[V.NOSE],i=e[V.LEFT_EAR],a=e[V.RIGHT_EAR],o=t.x<n.x,s=ci(r)>ri,c=ci(i),l=ci(a);return{shoulderOrder:o,noseVisible:s,earSymmetry:Math.abs(c-l)<ii&&Math.max(c,l)>ai}}function ui(e){let t=0;return e.shoulderOrder&&(t+=1),e.noseVisible&&(t+=1),e.earSymmetry&&(t+=1),t>=2}function di(e){return e<Xr?`front`:e<Zr?`side`:`back`}var fi=class{_zone=`front`;_consecutiveCount=0;_lastRawZone=`front`;_2dFrontCount=0;_2dBackCount=0;_2dIsFront=!0;_yawDirectionStabilizer=new Yr;update(e,t,n){let r=t??0,i=n??0,a=Math.abs(i)>Qr,o;t===void 0?o=this._resolve2dFallback(e):(o=di(Math.abs(t)),o===`front`&&this._zone!==`front`&&(ui(li(e))||(o=`back`))),this._applyHysteresis(o);let s=t===void 0?null:this._yawDirectionStabilizer.update(this._zone,r);return t===void 0&&this._yawDirectionStabilizer.reset(),{zone:this._zone,rawZone:o,isFrontFacing:this._zone===`front`,pitchClamped:a,bodyYaw:s?.stableYaw??r,bodyPitch:i,rawYawDirection:s?.rawYawDirection??`unknown`,yawDirection:s?.yawDirection??`unknown`,committedYawDirection:s?.committedYawDirection??`unknown`}}reset(){this._zone=`front`,this._consecutiveCount=0,this._lastRawZone=`front`,this._2dFrontCount=0,this._2dBackCount=0,this._2dIsFront=!0,this._yawDirectionStabilizer.reset()}_resolve2dFallback(e){return ui(li(e))?(this._2dFrontCount+=1,this._2dBackCount=0):(this._2dBackCount+=1,this._2dFrontCount=0),this._2dIsFront?this._2dBackCount>=oi&&(this._2dIsFront=!1):this._2dFrontCount>=si&&(this._2dIsFront=!0),this._2dIsFront?`front`:`back`}_applyHysteresis(e){e===this._lastRawZone?this._consecutiveCount+=1:(this._lastRawZone=e,this._consecutiveCount=1);let t=this._getTransitionThreshold(this._zone,e);t!==null&&this._consecutiveCount>=t&&(this._zone=e)}_getTransitionThreshold(e,t){return e===t?null:e===`front`&&t===`side`||e===`front`&&t===`back`?$r:e===`side`&&t===`back`?ei:e===`back`&&t===`side`?ti:e===`side`&&t===`front`?ni:e===`back`&&t===`front`?ti:$r}},pi=Math.PI/2;function mi(e){return e>=0?pi:-pi}var hi=class{_isFrozen=!1;_frozenYaw=null;update(e,t){let n=Math.abs(t);return this._isFrozen?e!==`back`&&n<pi&&this.reset():e!==`front`&&n>=pi&&(this._isFrozen=!0,this._frozenYaw=mi(t)),{isFrozen:this._isFrozen,frozenYaw:this._frozenYaw}}reset(){this._isFrozen=!1,this._frozenYaw=null}};function gi(e,t){return typeof e==`boolean`?{mirrorX:e,sourceWidth:0,sourceHeight:0,target:t??new o.Vector3}:{mirrorX:e.mirrorX??!1,sourceWidth:e.sourceWidth??0,sourceHeight:e.sourceHeight??0,target:e.target??t??new o.Vector3}}function Z(e,t,n,r=!1,i){let a=gi(r,i),o=Ye(t,n,a.sourceWidth||t,a.sourceHeight||n),s=a.mirrorX?1-e.x:e.x,c=o.x+s*o.width,l=o.y+e.y*o.height,u=c-t*.5,d=n*.5-l,f=-(e.z??0)*o.width*.5;return a.target.set(u,d,f)}function _i(e,t,n,r,i=!1,a){return Z({x:(e.x+t.x)/2,y:(e.y+t.y)/2,z:((e.z??0)+(t.z??0))/2,visibility:Math.min(e.visibility??0,t.visibility??0)},n,r,i,a)}function vi(e,t,n,r){let i=(e.x-t.x)*n,a=(e.y-t.y)*r;return Math.sqrt(i*i+a*a)}var yi=.45,bi=.72,xi=1.02,Si=1.1,Ci=Math.PI/6,wi=1e-4,Ti=wi*wi,Ei=.35,Di=.6,Oi=new o.Vector3,ki=new o.Vector3,Q=new o.Vector3,$=new o.Vector3,Ai=new o.Vector3,ji=new o.Vector3,Mi=new o.Matrix4;function Ni(e,t,n){let r=Math.min(Math.abs(n),Si),i=1/Math.max(Math.cos(r),yi)*e,a=t*bi;return Math.max(i,a,e)}function Pi({projectedShoulderWidth:e,projectedTorsoHeight:t,bodyYaw:n,worldLandmarks:r}){let i=Ni(e,t,n),a=Ri(t,r);if(!a)return i;let o=Vi((Math.abs(n)-Ei)/Di,0,1);return i+(Math.max(i,a)-i)*o}function Fi(e){return e?Vi(e.hips.rotation.y*.85+e.chest.y*.15,-Si,Si):0}function Ii(e,t,n){let r=e.x<=t.x?e:t,i=e.x<=t.x?t:e,a=i.x-r.x;if(a<=wi)return 0;let o=-(i.y-r.y);return Vi(Math.atan2(o,a)*Vi(1-Math.abs(n)/Si,0,1),-Ci,Ci)}function Li({leftShoulder:e,rightShoulder:t,leftHip:n,rightHip:r},i=new o.Quaternion){return Oi.copy(e).add(t).multiplyScalar(.5),ki.copy(n).add(r).multiplyScalar(.5),Q.copy(t).sub(e),Q.lengthSq()<=Ti||(Q.normalize(),$.copy(Oi).sub(ki),Ai.copy(Q).multiplyScalar($.dot(Q)),$.sub(Ai),$.lengthSq()<=Ti)||($.normalize(),ji.crossVectors(Q,$),ji.lengthSq()<=Ti)?null:(ji.normalize(),$.crossVectors(ji,Q).normalize(),Mi.makeBasis(Q,$,ji),i.setFromRotationMatrix(Mi))}function Ri(e,t){if(!t||t.length<=V.RIGHT_HIP||e<=wi)return null;let n=t[V.LEFT_SHOULDER],r=t[V.RIGHT_SHOULDER],i=t[V.LEFT_HIP],a=t[V.RIGHT_HIP];if(!n||!r||!i||!a)return null;let o=Bi(n,r),s=Bi(zi(n,r),zi(i,a));return o<=wi||s<=wi?null:e*Vi(o/s,bi,xi)}function zi(e,t){return{x:(e.x+t.x)*.5,y:(e.y+t.y)*.5,z:((e.z??0)+(t.z??0))*.5}}function Bi(e,t){let n=e.x-t.x,r=e.y-t.y,i=(e.z??0)-(t.z??0);return Math.sqrt(n*n+r*r+i*i)}function Vi(e,t,n){return Math.max(t,Math.min(n,e))}var Hi=1e-4,Ui=.15,Wi=8,Gi=1e-4,Ki=1.45,qi=.35,Ji=10,Yi=.18,Xi=.55,Zi=6,Qi=.3,$i=.08,ea=.05,ta=1.35,na=.7,ra=new o.Quaternion,ia=new o.Vector3,aa=[[V.LEFT_EAR,V.RIGHT_EAR],V.NOSE,[V.LEFT_SHOULDER,V.RIGHT_SHOULDER]],oa=[[V.LEFT_ANKLE,V.RIGHT_ANKLE],[V.LEFT_HEEL,V.RIGHT_HEEL],[V.LEFT_FOOT_INDEX,V.RIGHT_FOOT_INDEX]];function sa(e,t,n){return Math.max(t,Math.min(n,e))}function ca(){return{leftShoulder:new o.Vector3,rightShoulder:new o.Vector3,leftHip:new o.Vector3,rightHip:new o.Vector3,shoulderCenter:new o.Vector3,hipCenter:new o.Vector3,bodyTop:new o.Vector3,bodyBottom:new o.Vector3,anchor:new o.Vector3,scaledAnchor:new o.Vector3,position:new o.Vector3,scale:new o.Vector3(1,1,1),stabilizedBodyHeightScale:null,missingBodyHeightFrames:0,smoothedGlobalScale:1,hasSmoothedGlobalScale:!1,effectiveYaw:0,previousDepthProxy:0,scaleVelocity:0,smoothedXDeviation:1,smoothedAnchor:new o.Vector3,hasSmoothedAnchor:!1}}function la(e,t,n,r,i,a={}){if(t.length<33)return!1;Z(t[V.LEFT_SHOULDER],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.leftShoulder}),Z(t[V.RIGHT_SHOULDER],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.rightShoulder}),Z(t[V.LEFT_HIP],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.leftHip}),Z(t[V.RIGHT_HIP],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.rightHip}),i.shoulderCenter.copy(i.leftShoulder).add(i.rightShoulder).multiplyScalar(.5),i.hipCenter.copy(i.leftHip).add(i.rightHip).multiplyScalar(.5);let s=Li({leftShoulder:i.rightShoulder,rightShoulder:i.leftShoulder,leftHip:i.rightHip,rightHip:i.leftHip},ra),c=s?da(s):0,l=ma(a.bodyYaw,c);i.effectiveYaw=l;let u=ga(i.leftShoulder,i.rightShoulder),d=ga(i.shoulderCenter,i.hipCenter),f=Pi({projectedShoulderWidth:u,projectedTorsoHeight:d,bodyYaw:l,worldLandmarks:a.worldLandmarks}),p=d/Math.max(e.referenceTorsoHeight,Hi),m=ha(t,n,r,d,i,a),h=fa(m===null?null:m/Math.max(e.trackingHeight,Hi),i),g=h!==null&&p>Hi?sa(h,p*na,p*ta):h,_=pa(sa(g===null?p:p*.55+g*.45,Ui,Wi)*(a.scaleMultiplier??1),i,d),v=.1,y=e.referenceWidth/Math.max(e.referenceTorsoHeight,Hi),b=d>Hi?f/d:y,x=sa(y>Hi?b/y:1,1-v,1+v);return i.smoothedXDeviation=o.MathUtils.lerp(i.smoothedXDeviation,x,.35),i.scale.set(_*i.smoothedXDeviation*(a.scaleX??1),_*(a.scaleY??1),_*(a.scaleZ??1)),i.anchor.copy(i.shoulderCenter).add(i.hipCenter).multiplyScalar(.5),i.hasSmoothedAnchor?i.smoothedAnchor.lerp(i.anchor,.4):(i.smoothedAnchor.copy(i.anchor),i.hasSmoothedAnchor=!0),i.scaledAnchor.set(e.anchor.x*_,e.anchor.y*_,e.anchor.z*_),i.position.copy(i.smoothedAnchor).sub(i.scaledAnchor),i.position.z+=a.depthOffset??0,!0}function ua(e,t){e.position.copy(t.position),e.scale.copy(t.scale)}function da(e){return ia.set(0,0,1).applyQuaternion(e),ia.y=0,ia.lengthSq()<=Gi?0:(ia.normalize(),Math.atan2(ia.x,ia.z))}function fa(e,t){return e===null?t.stabilizedBodyHeightScale===null?(t.missingBodyHeightFrames=0,null):(t.missingBodyHeightFrames+=1,t.missingBodyHeightFrames>Ji?(t.stabilizedBodyHeightScale=null,null):t.stabilizedBodyHeightScale):(t.missingBodyHeightFrames=0,t.stabilizedBodyHeightScale=t.stabilizedBodyHeightScale===null?e:o.MathUtils.lerp(t.stabilizedBodyHeightScale,e,qi),t.stabilizedBodyHeightScale)}function pa(e,t,n){if(!t.hasSmoothedGlobalScale)return t.smoothedGlobalScale=e,t.previousDepthProxy=n,t.scaleVelocity=0,t.hasSmoothedGlobalScale=!0,e;let r=t.previousDepthProxy,i=1;r>ea&&n>ea&&(i=sa(n/r,1-$i,1+$i)),t.previousDepthProxy=n;let a=t.smoothedGlobalScale*i,s=a>0?Math.abs(e-a)/a:0;t.scaleVelocity=o.MathUtils.lerp(t.scaleVelocity,s,Qi);let c=sa(Yi+t.scaleVelocity*Zi,Yi,Xi);return t.smoothedGlobalScale=o.MathUtils.lerp(a,e,c),t.smoothedGlobalScale}function ma(e,t){let n=e??0;return Math.abs(n)>=Math.abs(t)?n:t}function ha(e,t,n,r,i,a){let o=_a(aa,e,t,n,i.bodyTop,a),s=_a(oa,e,t,n,i.bodyBottom,a);if(!o||!s)return null;let c=ga(i.bodyTop,i.bodyBottom);return c<=r*Ki?null:c}function ga(e,t){let n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function _a(e,t,n,r,i,a){for(let o=0;o<e.length;o+=1)if(va(e[o],t,n,r,i,a))return!0;return!1}function va(e,t,n,r,i,a){if(typeof e==`number`){let o=t[e];return!o||(o.visibility??0)<.4?!1:(Z(o,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i}),!0)}let o=t[e[0]],s=t[e[1]];if(!o||!s||(o.visibility??0)<.4||(s.visibility??0)<.4)return!1;Z(o,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i});let c=Z(s,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight});return i.add(c).multiplyScalar(.5),!0}var ya=new o.Vector3(0,1,0),ba=new Set([`LeftHand`,`RightHand`]),xa=new Set([`Hips`,`Spine`,`Chest`]),Sa=20,Ca=.436,wa=.175,Ta=1.396,Ea=.349,Da=.35;function Oa(e,t,n){return Math.max(t,Math.min(n,e))}function ka(e){let t=e;for(;t<=-Math.PI;)t+=Math.PI*2;for(;t>Math.PI;)t-=Math.PI*2;return t}function Aa(e,t,n){let r=ka(t-e);return ka(Math.abs(r)<=n?t:e+Math.sign(r)*n)}function ja(){return{transformScratch:ca(),facingDetector:new fi,yawFreezeController:new hi,displayYaw:null,lastFacingState:null,hasInitialPosition:!1}}function Ma(e){e.transformScratch=ca(),e.facingDetector.reset(),e.yawFreezeController.reset(),e.displayYaw=null,e.lastFacingState=null,e.hasInitialPosition=!1}function Na({fitProfile:e,garmentRoot:t,boneBindingMap:n,poseRefs:r,motionState:i,landmarks:a,worldLandmarks:o=null,viewportWidth:s,viewportHeight:c,poseFrameWidth:l,poseFrameHeight:u,delta:d}){if(!a||a.length<33)return null;let f=i.transformScratch;la(e,a,s,c,f,{sourceWidth:l,sourceHeight:u,worldLandmarks:o});let p=f.shoulderCenter.y-f.hipCenter.y,m=f.shoulderCenter.distanceTo(f.hipCenter),h=Math.acos(Oa(Math.abs(p)/Math.max(m,.001),0,1)),g=f.effectiveYaw,_=g>0?g-Math.PI:g+Math.PI,v=i.facingDetector.update(a,_,h),y=v.bodyYaw,b=i.displayYaw===null?y:Aa(i.displayYaw,y,Sa*d),x=i.yawFreezeController.update(v.zone,y),S=x.isFrozen,C=S?x.frozenYaw??b:b;return i.displayYaw=C,i.lastFacingState=v,v.zone!==`back`&&(S||(t.scale.copy(f.scale),i.hasInitialPosition?t.position.lerp(f.position,Da):(t.position.copy(f.position),i.hasInitialPosition=!0)),t.quaternion.setFromAxisAngle(ya,C)),v.zone===`front`&&!S?(Vr(a,n,r,{coordinateSpace:`normalized`,excludeBones:ba}),v.pitchClamped&&Ur(n,Oa((Math.abs(h)-Ca)/wa,0,1),d,xa)):v.zone===`side`&&!S&&(Vr(a,n,r,{coordinateSpace:`normalized`,excludeBones:ba}),Ur(n,Oa((Math.abs(y)-Ta)/Ea,0,1),d)),v}function Pa({garmentRootRef:e,boneBindingMap:r,fitProfile:i,landmarks:a,worldLandmarks:o,poseFrameWidth:s,poseFrameHeight:c}){let{viewport:l}=(0,n.useThree)(),u=Br(),d=(0,t.useRef)(ja());return(0,t.useEffect)(()=>{let t=e.current,n=d.current;return t&&(t.position.set(0,0,0),t.scale.set(1,1,1),t.quaternion.identity()),Hr(r,u),Ma(n),()=>{Hr(r,u),Ma(n)}},[r,i,e,u]),(0,n.useFrame)((t,n)=>{let f=e.current;!f||!i||Na({fitProfile:i,garmentRoot:f,boneBindingMap:r,poseRefs:u,motionState:d.current,landmarks:a,worldLandmarks:o,viewportWidth:l.width,viewportHeight:l.height,poseFrameWidth:s,poseFrameHeight:c,delta:n})}),null}function Fa(e){return e?e.map(e=>({x:e.x,y:e.y,z:e.z,visibility:typeof e.visibility==`number`?e.visibility:0})):null}function Ia({url:e,landmarks:n,worldLandmarks:r,poseFrameWidth:a,poseFrameHeight:s,debugMaterials:c=!1,onLoadStateChange:l}){let u=(0,t.useRef)(null),{scene:d,bones:f}=ir({url:e}),p=(0,t.useMemo)(()=>Fa(n),[n]),m=(0,t.useMemo)(()=>Fa(r),[r]),h=(0,t.useMemo)(()=>(d.updateMatrixWorld(!0),Vn(d,f,1)),[f,d]);return(0,t.useEffect)(()=>{d.traverse(e=>{if(e instanceof o.Mesh){if(e.name.startsWith(`Collision`)){e.visible=!1;return}e.visible=!0,(Array.isArray(e.material)?e.material:[e.material]).forEach(e=>{`opacity`in e&&(c?(e.transparent=!0,e.opacity=.34,e.depthWrite=!1,e.side=o.DoubleSide):(e.transparent=!1,e.opacity=1,e.depthWrite=!0,e.side=o.FrontSide),e.needsUpdate=!0)})}})},[d,c]),(0,t.useEffect)(()=>(l?.({loaded:!0,error:null}),()=>{l?.({loaded:!1,error:null})}),[l,e]),(0,i.jsxs)(`group`,{ref:u,children:[(0,i.jsx)(`primitive`,{object:d}),(0,i.jsx)(Pa,{garmentRootRef:u,boneBindingMap:f,fitProfile:h,landmarks:p,worldLandmarks:m,poseFrameWidth:a,poseFrameHeight:s})]})}var La=1;function Ra(e){let t=new o.VideoTexture(e);return t.minFilter=o.NearestFilter,t.magFilter=o.NearestFilter,t.generateMipmaps=!1,t.colorSpace=o.SRGBColorSpace,t.needsUpdate=!0,t}function za(e,t,n){if(!n||n.width===0||n.height===0)return[e,t];let r=e/t,i=n.width/n.height;return r>i?[e,e/i]:[t*i,t]}function Ba({videoElement:e,webcamReady:r}){let{viewport:a}=(0,n.useThree)(),[o,s]=(0,t.useState)(null),[c,l]=(0,t.useState)(null),u=(0,t.useRef)(null),d=(0,t.useRef)(null),f=(0,t.useRef)(0);(0,t.useEffect)(()=>{let t=e;if(!r||!t){d.current!==null&&(clearTimeout(d.current),d.current=null),f.current=0;return}let n=!1,i=()=>{if(n||u.current)return;if(t.videoWidth===0||t.videoHeight===0){d.current=setTimeout(i,100);return}let e=Ra(t);u.current=e,f.current=0,l({width:t.videoWidth,height:t.videoHeight}),s(e)};return t.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&t.videoWidth>0&&t.videoHeight>0?i():(t.addEventListener(`loadeddata`,i),t.addEventListener(`loadedmetadata`,i),t.addEventListener(`playing`,i),d.current=setTimeout(i,200)),()=>{n=!0,d.current!==null&&(clearTimeout(d.current),d.current=null),t.removeEventListener(`loadeddata`,i),t.removeEventListener(`loadedmetadata`,i),t.removeEventListener(`playing`,i),u.current&&=(u.current.dispose(),null),f.current=0,s(null),l(null)}},[e,r]),(0,n.useFrame)(()=>{!u.current||!u.current.image||(f.current=(f.current+1)%La,f.current===0&&(u.current.needsUpdate=!0))});let[p,m]=(0,t.useMemo)(()=>za(a.width,a.height,c),[c,a.height,a.width]);return!r||!o?null:(0,i.jsxs)(`mesh`,{position:[0,0,-20],renderOrder:-1,scale:[-1,1,1],children:[(0,i.jsx)(`planeGeometry`,{args:[p,m]}),(0,i.jsx)(`meshBasicMaterial`,{map:o,depthTest:!1,depthWrite:!1,toneMapped:!1})]})}function Va({onReady:e}){return(0,t.useEffect)(()=>(e?.(!0),()=>{e?.(!1)}),[e]),null}function Ha(){return(0,i.jsx)(`color`,{attach:`background`,args:[`#000000`]})}function Ua({garmentUrl:e,enabled:n=!0,width:a=1280,height:o=720,facingMode:s=`user`,mockMode:c=!1,viewportWidth:l=0,viewportHeight:u=0,measurementEnabled:d=!0,autoStartMeasurement:f=!1,measurementConfig:p,fitType:m=`regular`,garmentScaleHint:h=null,bodyPresetOptions:g,className:v,style:y,debugMaterials:b=!1,showEnvironment:x=!1,showStats:S=!1,showWebcamBackground:C=!0,onCanvasReadyChange:w,onRuntimeStateChange:T,onGarmentLoadStateChange:E}){let{videoRef:D,webcamReady:O,webcamError:k,startWebcam:A,stopWebcam:j,isTrackerReady:M,landmarks:ee,worldLandmarks:N,poseRig:P,confidence:F,fps:I,isTracking:L,drawLandmarks:R,silhouetteWidths:z,poseFrameWidth:B,poseFrameHeight:te,detectedPersonCount:ne,lockedPersonId:re,trackingQuality:ie,config:ae,measurements:oe,sizeRecommendation:se,garmentScale:ce,finalGarmentScale:le,bodyMorphResult:ue,isMeasuring:de,canMeasure:fe,startMeasurement:pe,updateConfig:me,bodyPresetSelection:he,bodyPresetLoading:ge,bodyPresetError:_e}=In({enabled:n,width:a,height:o,facingMode:s,mockMode:c,viewportWidth:l,viewportHeight:u,measurementEnabled:d,autoStartMeasurement:f,measurementConfig:p,bodyPresetOptions:g,fitType:m,garmentScaleHint:h}),[ve,ye]=(0,t.useState)(null),be=(0,t.useCallback)(e=>{D.current=e,ye(e)},[D]),xe=(0,t.useMemo)(()=>({videoRef:D,webcamReady:O,webcamError:k,startWebcam:A,stopWebcam:j,isTrackerReady:M,landmarks:ee,worldLandmarks:N,poseRig:P,confidence:F,fps:I,isTracking:L,drawLandmarks:R,silhouetteWidths:z,poseFrameWidth:B,poseFrameHeight:te,detectedPersonCount:ne,lockedPersonId:re,trackingQuality:ie,config:ae,measurements:oe,sizeRecommendation:se,garmentScale:ce,finalGarmentScale:le,bodyMorphResult:ue,isMeasuring:de,canMeasure:fe,startMeasurement:pe,updateConfig:me,bodyPresetSelection:he,bodyPresetLoading:ge,bodyPresetError:_e}),[D,O,k,A,j,M,ee,N,P,F,I,L,R,z,B,te,ne,re,ie,ae,oe,se,ce,le,ue,de,fe,pe,me,he,ge,_e]);return(0,t.useEffect)(()=>{T?.(xe)},[T,xe]),(0,i.jsxs)(`div`,{className:v,style:{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,...y},children:[(0,i.jsx)(`video`,{ref:be,autoPlay:!0,playsInline:!0,muted:!0,style:{display:`none`}}),(0,i.jsxs)(_,{showEnvironment:x,useDefaultLights:!1,enableOrbitControls:!1,children:[(0,i.jsx)(Va,{onReady:w}),(0,i.jsx)(Ha,{}),(0,i.jsx)(r.OrthographicCamera,{makeDefault:!0,position:[0,0,100],zoom:180,near:.1,far:1e3}),(0,i.jsx)(`ambientLight`,{intensity:.95}),(0,i.jsx)(`directionalLight`,{position:[4,6,8],intensity:1.15}),(0,i.jsx)(`directionalLight`,{position:[-5,4,6],intensity:.45}),(0,i.jsx)(`hemisphereLight`,{args:[`#ffffff`,`#7d8aa6`,.35]}),C?(0,i.jsx)(Ba,{videoElement:ve,webcamReady:O}):null,n&&e?(0,i.jsx)(Ia,{url:e,landmarks:ee,worldLandmarks:N,poseFrameWidth:B,poseFrameHeight:te,debugMaterials:b,onLoadStateChange:E}):null,S?(0,i.jsx)(r.Stats,{}):null]})]})}var Wa={gender:`female`};function Ga(e,t){return e instanceof Error&&e.message?e.message:t}function Ka(e){let n=(0,t.useMemo)(()=>new fe(e),[e]),[r,i]=(0,t.useState)(`idle`),[a,o]=(0,t.useState)(null),[s,c]=(0,t.useState)(null);return{status:r,resultUrl:a,error:s,generateAvatar:(0,t.useCallback)(async(e=Wa)=>{i(`processing`),c(null);try{let t=e instanceof Blob?Wa:e,r=await n.matchBodyPreset(t);if(!r.model_url)throw Error(`Matched body preset does not have a 3D model URL.`);return o(r.model_url),i(`ready`),r.model_url}catch(e){throw c(Ga(e,`Failed to load avatar model`)),i(`error`),e}},[n]),createGarment:(0,t.useCallback)(async(e,t,r,a)=>{i(`uploading`),c(null);try{let s=await n.createGarment(e);await n.uploadGarmentImage(s.id,t,`front`),r&&await n.uploadGarmentImage(s.id,r,`back`),i(`processing`),await n.generateGarment3D(s.id,{include_measurements:!!a,target_fit_types:[`regular`]});let c=await n.waitForGarmentModel(s.id),l=n.pickGarmentModelUrl(c);if(!l)throw Error(`Backend did not return a garment 3D model URL.`);return o(l),i(`ready`),l}catch(e){throw c(Ga(e,`Failed to generate garment`)),i(`error`),e}},[n]),reset:()=>{i(`idle`),o(null),c(null)}}}var qa={Hips:[V.LEFT_HIP,V.RIGHT_HIP],Spine:[V.LEFT_SHOULDER,V.RIGHT_SHOULDER,V.LEFT_HIP,V.RIGHT_HIP],Chest:[V.LEFT_SHOULDER,V.RIGHT_SHOULDER],LeftShoulder:[V.LEFT_SHOULDER,V.LEFT_ELBOW],LeftUpperArm:[V.LEFT_SHOULDER,V.LEFT_ELBOW],LeftLowerArm:[V.LEFT_ELBOW,V.LEFT_WRIST],RightShoulder:[V.RIGHT_SHOULDER,V.RIGHT_ELBOW],RightUpperArm:[V.RIGHT_SHOULDER,V.RIGHT_ELBOW],RightLowerArm:[V.RIGHT_ELBOW,V.RIGHT_WRIST],LeftUpperLeg:[V.LEFT_HIP,V.LEFT_KNEE],LeftLowerLeg:[V.LEFT_KNEE,V.LEFT_ANKLE],RightUpperLeg:[V.RIGHT_HIP,V.RIGHT_KNEE],RightLowerLeg:[V.RIGHT_KNEE,V.RIGHT_ANKLE]};e.BONE_MAPPING=ur,e.BONE_VISIBILITY_MAP=qa,e.DEFAULT_EVER_API_BASE_URL=le,e.DEFAULT_FEMALE_BODY_PRESET_ID=he,e.DEFAULT_GARMENT_SPEC=v,e.DEFAULT_LOCKED_PERSON_ID=qt,e.DEFAULT_MALE_BODY_PRESET_ID=me,e.DEFAULT_MEASUREMENT_CONFIG=Ge,e.DEFAULT_NUM_POSES=ut,e.DEFAULT_SMOOTHING=Ae,e.EverCanvas=_,e.EverClient=fe,e.EverFittingScene=Ua,e.EverTrackedGarment=Ia,e.FacingDetector=fi,e.INTERPOLATION_ALPHA=dt,e.LANDMARK=V,e.LEGACY_RIGGED_BODY_PRESET_ID=ge,e.LandmarkSmoother=en,e.MEDIAPIPE_TASKS_VISION_VERSION=st,e.MODEL_ASSET_PATHS=ft,e.POSE_DETECTION_INTERVAL=lt,e.TRACKING_SNAPSHOT_HOLD_MS=On,e.TrackedGarmentPoseDriver=Pa,e.WASM_FILES_URL=ct,e.WebcamPlaneBackground=Ba,e.YawDirectionStabilizer=Yr,e.YawFreezeController=hi,e.applyLandmarkPoseToGarment=Vr,e.applyTrackedModelTransform=ua,e.blendBonesToRest=Ur,e.buildBodyPresetAssetUrl=ye,e.buildBodyPresetMatchRequest=Ee,e.calcRectIoU=pn,e.captureBoneBinding=Ln,e.clampNormalizedRect=un,e.closeSegmentationMasks=Gt,e.computeBmiCorrectionFactor=Fe,e.computeBodyFirstFitting=ce,e.computeBoneDirectionFromLandmarks=Nt,e.computeBoneRotationFromLandmarks=Ft,e.computeCoverRect=Ye,e.computeFacingAwareShoulderWidth=Ni,e.computeGarmentFitProfile=Vn,e.computeGarmentGroupRoll=Ii,e.computeGarmentGroupYaw=Fi,e.computeGarmentRootQuaternion=Li,e.computeGarmentScale=x,e.computeLandmarkBoundsNormalized=dn,e.computeLandmarkSegmentDirection=Mt,e.computeScale=Pe,e.computeStableShoulderWidth=Pi,e.computeVisibleNormalizedRegion=Xe,e.configureAvatarLoader=qn,e.createAvatarLoaderExtension=Jn,e.createFallbackBodyPresetSelection=we,e.createHeldTrackingSnapshot=An,e.createHumanoidBoneBindings=Qn,e.createIdleTrackingQuality=wn,e.createInitialPoseSnapshot=at,e.createInitialTrackingRuntimeState=En,e.createPoseCandidates=hn,e.createPoseLandmarker=pt,e.createTrackedGarmentMotionState=ja,e.createTrackedModelTransformScratch=ca,e.createTrackingLostRuntimeState=jn,e.createTrackingQuality=Tn,e.createTrackingRuntimeState=Dn,e.createVRMCompat=nr,e.deriveBodyMorphResult=re,e.ensureBodyPresetModelUrl=Se,e.expandNormalizedRect=fn,e.extractFacingSignals=li,e.extractSilhouetteWidths=et,e.filterCandidatesByVisibleRegion=yn,e.getAvatarAssetKind=Kn,e.getBoneLandmarkInfluence=Pt,e.getBoneRotation=pr,e.getDefaultBodyPresetId=be,e.getSegmentationMaskData=Wt,e.hasLandmarkMapping=It,e.interpolateLandmarks=tt,e.interpolatePoseRig=rt,e.interpolatePoseSnapshot=ot,e.interpolateSilhouetteWidths=it,e.isCandidateInVisibleRegion=vn,e.isRawFrontFacing=ui,e.isVRMAssetUrl=Gn,e.landmarkDistance=vi,e.landmarkToThreePosition=Z,e.lerpRotation=q,e.lerpValue=W,e.measureBody=He,e.midpointToThree=_i,e.normalizeBodyPresetGender=ve,e.normalizeBoneName=fr,e.normalizeLandmark=Yt,e.normalizeLandmarks=Xt,e.pickDefaultBodyPreset=Ce,e.prepareAvatarScene=Yn,e.prepareNativeVRM=Xn,e.recommendSize=We,e.resetBoneRotations=Hn,e.resetPoseState=Hr,e.resetTrackedGarmentMotionState=Ma,e.scaleSilhouetteWidths=Kt,e.selectLockedPoseCandidate=_n,e.shouldHoldTrackingSnapshot=kn,e.smoothPoseRig=nn,e.solvePose=Ut,e.toBodyPresetSelection=Te,e.toBodyPresetSummary=xe,e.toLockedPoseCandidate=bn,e.updateTrackedGarmentMotion=Na,e.updateTrackedModelTransform=la,e.useAvatarVariant=ir,e.useBodyPresetSelection=ke,e.useEverFitting=In,e.useEverGeneration=Ka,e.useMeasurement=Je,e.usePoseApplicationRefs=Br,e.usePoseTracker=Nn,e.useWebcam=Fn});
|
|
@@ -7,3 +7,5 @@ export interface CoordinateTransformOptions {
|
|
|
7
7
|
target?: THREE.Vector3;
|
|
8
8
|
}
|
|
9
9
|
export declare function landmarkToThreePosition(landmark: NormalizedLandmark, viewportWidth: number, viewportHeight: number, mirrorXOrOptions?: boolean | CoordinateTransformOptions, target?: THREE.Vector3): THREE.Vector3;
|
|
10
|
+
export declare function midpointToThree(a: NormalizedLandmark, b: NormalizedLandmark, viewportWidth: number, viewportHeight: number, mirrorXOrOptions?: boolean | CoordinateTransformOptions, target?: THREE.Vector3): THREE.Vector3;
|
|
11
|
+
export declare function landmarkDistance(a: NormalizedLandmark, b: NormalizedLandmark, viewportWidth: number, viewportHeight: number): number;
|
|
@@ -6,6 +6,6 @@ export interface YawFreezeState {
|
|
|
6
6
|
export declare class YawFreezeController {
|
|
7
7
|
private _isFrozen;
|
|
8
8
|
private _frozenYaw;
|
|
9
|
-
update(zone: FacingZone, yaw: number
|
|
9
|
+
update(zone: FacingZone, yaw: number): YawFreezeState;
|
|
10
10
|
reset(): void;
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"module": "./dist/index.es.js",
|
|
42
42
|
"name": "@ssafy-mhk/e-ver",
|
|
43
43
|
"peerDependencies": {
|
|
44
|
+
"@mediapipe/tasks-vision": ">=0.10.0",
|
|
45
|
+
"@react-three/drei": ">=9.0.0",
|
|
46
|
+
"@react-three/fiber": ">=8.0.0",
|
|
44
47
|
"react": ">=16.8.0",
|
|
45
48
|
"react-dom": ">=16.8.0",
|
|
46
49
|
"three": ">=0.150.0",
|
|
47
|
-
"@react-three/fiber": ">=8.0.0",
|
|
48
|
-
"@react-three/drei": ">=9.0.0",
|
|
49
|
-
"@mediapipe/tasks-vision": ">=0.10.0",
|
|
50
50
|
"zustand": ">=4.0.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
},
|
|
60
60
|
"type": "module",
|
|
61
61
|
"types": "./dist/index.d.ts",
|
|
62
|
-
"version": "1.0.
|
|
62
|
+
"version": "1.0.6"
|
|
63
63
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import * as THREE from "three";
|
|
3
|
-
export interface AvatarModelProps {
|
|
4
|
-
url: string | null;
|
|
5
|
-
onBonesReady?: (bones: Record<string, THREE.Bone>) => void;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Loads and renders the user's 3D avatar (GLB/VRM).
|
|
9
|
-
* Automatically registers bone references to the EverProvider for the pose mapping pipeline.
|
|
10
|
-
*/
|
|
11
|
-
export declare const AvatarModel: React.FC<AvatarModelProps>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export interface CameraViewProps {
|
|
3
|
-
className?: string;
|
|
4
|
-
style?: React.CSSProperties;
|
|
5
|
-
width?: number;
|
|
6
|
-
height?: number;
|
|
7
|
-
facingMode?: "user" | "environment";
|
|
8
|
-
enabled?: boolean;
|
|
9
|
-
mockMode?: boolean;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* CameraView handles the rendering of the user's webcam feed.
|
|
13
|
-
* It automatically registers the video element to the EverProvider for tracking.
|
|
14
|
-
*/
|
|
15
|
-
export declare const CameraView: React.FC<CameraViewProps>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export interface EverProviderProps {
|
|
3
|
-
children: React.ReactNode;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* EverProvider coordinates the shared state between tracking and rendering.
|
|
7
|
-
* It manages the video reference for MediaPipe and the bone mappings for 3D models.
|
|
8
|
-
*/
|
|
9
|
-
export declare const EverProvider: React.FC<EverProviderProps>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import * as THREE from "three";
|
|
3
|
-
export interface GarmentModelProps {
|
|
4
|
-
url: string | null;
|
|
5
|
-
targetAvatarBones?: Record<string, THREE.Bone>;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Loads the clothing GLB and binds its SkinnedMeshes to the target avatar's bones.
|
|
9
|
-
*/
|
|
10
|
-
export declare const GarmentModel: React.FC<GarmentModelProps>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as THREE from "three";
|
|
2
|
-
export interface EverContextType {
|
|
3
|
-
videoRef: React.RefObject<HTMLVideoElement | null>;
|
|
4
|
-
avatarBones: Record<string, THREE.Bone> | null;
|
|
5
|
-
setAvatarBones: (bones: Record<string, THREE.Bone> | null) => void;
|
|
6
|
-
isProviderReady: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare const EverContext: import("react").Context<EverContextType | undefined>;
|
|
9
|
-
export declare function useEver(): EverContextType;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface BodyMeasurerOptions {
|
|
2
|
-
wasmUrl?: string;
|
|
3
|
-
modelUrl?: string;
|
|
4
|
-
referenceHeightCm?: number;
|
|
5
|
-
weightKg?: number | null;
|
|
6
|
-
measurementIntervalMs?: number;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Extracts silhouette, calculates body dimensions periodically (e.g. 1Hz).
|
|
10
|
-
* Evaluates clothing fit.
|
|
11
|
-
*
|
|
12
|
-
* `wasmUrl` / `modelUrl` are reserved for future segmentation model integration.
|
|
13
|
-
*/
|
|
14
|
-
export declare const useBodyMeasurer: (_options?: BodyMeasurerOptions) => {
|
|
15
|
-
dimensions: {
|
|
16
|
-
shoulder: number | null;
|
|
17
|
-
chest: number | null;
|
|
18
|
-
waist: number | null;
|
|
19
|
-
} | null;
|
|
20
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as THREE from "three";
|
|
2
|
-
import { type PoseLandmarkLike } from "../types/pose";
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook to map MediaPipe 2D/3D landmarks to 3D bones (Quaternions).
|
|
5
|
-
*/
|
|
6
|
-
export declare const usePoseMapper: () => {
|
|
7
|
-
mapPoseToBones: (landmarks: PoseLandmarkLike[], targetBones: Record<string, THREE.Bone>) => void;
|
|
8
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface PoseLandmark {
|
|
2
|
-
x: number;
|
|
3
|
-
y: number;
|
|
4
|
-
z: number;
|
|
5
|
-
visibility?: number;
|
|
6
|
-
presence?: number;
|
|
7
|
-
}
|
|
8
|
-
export interface EverState {
|
|
9
|
-
isWebcamActive: boolean;
|
|
10
|
-
activeGarmentUrl: string | null;
|
|
11
|
-
landmarks: PoseLandmark[] | null;
|
|
12
|
-
worldLandmarks: PoseLandmark[] | null;
|
|
13
|
-
fitResult: {
|
|
14
|
-
type: "slim" | "regular" | "oversize" | null;
|
|
15
|
-
suitability: number;
|
|
16
|
-
} | null;
|
|
17
|
-
setWebcamActive: (active: boolean) => void;
|
|
18
|
-
setActiveGarmentUrl: (url: string | null) => void;
|
|
19
|
-
setLandmarks: (landmarks: PoseLandmark[] | null, worldLandmarks: PoseLandmark[] | null) => void;
|
|
20
|
-
setFitResult: (result: EverState["fitResult"]) => void;
|
|
21
|
-
}
|
|
22
|
-
export declare const useEverStore: import("zustand").UseBoundStore<import("zustand").StoreApi<EverState>>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|