brep-io-kernel 1.0.177 → 1.0.178

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.
Files changed (51) hide show
  1. package/dist/about.html +3 -66
  2. package/dist/apiExamples/BREP_Booleans.html +2 -2
  3. package/dist/apiExamples/BREP_Export.html +2 -2
  4. package/dist/apiExamples/BREP_Primitives.html +2 -2
  5. package/dist/apiExamples/BREP_Transforms.html +2 -2
  6. package/dist/apiExamples/Embeded_2D_Sketcher.html +2 -2
  7. package/dist/apiExamples/Embeded_CAD.html +2 -2
  8. package/dist/apiExamples/Embeded_CAD_Integration_Test.html +2 -2
  9. package/dist/assembly-constraint-capture.html +5 -5
  10. package/dist/assets/{AnnotationRegistry-CyI5mmDu.js → AnnotationRegistry-QZj3o2R6.js} +1 -1
  11. package/dist/assets/{AssemblyConstraintRegistry-3P1cpGjG.js → AssemblyConstraintRegistry-DJV0rHvz.js} +1 -1
  12. package/dist/assets/{FeatureRegistry-Cd-GX-Bm.js → FeatureRegistry-C7MrfKHF.js} +3 -3
  13. package/dist/assets/{PartHistory-DxsRIXx4.js → PartHistory-CyUoWFuO.js} +1 -1
  14. package/dist/assets/{Tube-bO80ROeR.js → Tube-TKgrLSLm.js} +1 -1
  15. package/dist/assets/{annUtils-D9TT7tgs.js → annUtils-Cv2fgMTB.js} +1 -1
  16. package/dist/assets/{apiExample_BREP_Booleans-p7pplM2w.js → apiExample_BREP_Booleans-CVUu-3pI.js} +1 -1
  17. package/dist/assets/{apiExample_BREP_Export-DcEboCzN.js → apiExample_BREP_Export-D3YICePi.js} +1 -1
  18. package/dist/assets/{apiExample_BREP_Primitives-mwn27Zyf.js → apiExample_BREP_Primitives-CB9GlLIq.js} +1 -1
  19. package/dist/assets/{apiExample_BREP_Transforms-DoxqJ6cS.js → apiExample_BREP_Transforms-BTbdOuJd.js} +1 -1
  20. package/dist/assets/{apiExample_Embeded_2D_Sketcher-D0UY5aPj.js → apiExample_Embeded_2D_Sketcher-jli62c46.js} +1 -1
  21. package/dist/assets/{apiExample_Embeded_CAD-CGA1Zguy.js → apiExample_Embeded_CAD-BBzOAW8d.js} +1 -1
  22. package/dist/assets/{apiExample_Embeded_CAD_Integration_Test-CdZX2cCy.js → apiExample_Embeded_CAD_Integration_Test-Dla62MVj.js} +1 -1
  23. package/dist/assets/{assemblyConstraintDialogs-Qq5KEM_o.js → assemblyConstraintDialogs-7PwUshmv.js} +1 -1
  24. package/dist/assets/{brep-kernel-DRr4NDNQ.js → brep-kernel-B2gzJr_I.js} +3 -10
  25. package/dist/assets/{browserTests-DI1pWDf6.js → browserTests-Rma8zWcv.js} +1 -1
  26. package/dist/assets/{chamfer-DdXNz6lz.js → chamfer-jmLT1RTy.js} +1 -1
  27. package/dist/assets/{dialogCapturePageFactory-DGBZ6PkY.js → dialogCapturePageFactory-l1BkjONQ.js} +1 -1
  28. package/dist/assets/{featureDialogs-CUWi02Qp.js → featureDialogs-Bas0NDXF.js} +3 -3
  29. package/dist/assets/{featureDialogs-CJ9OA-vL.js → featureDialogs-zsfh_u_t.js} +1 -1
  30. package/dist/assets/{fillet-CJey7GJP.js → fillet-Bzd1Xae9.js} +1 -1
  31. package/dist/assets/{index.es-X1ZhwpCY.js → index.es-tZ6V_7py.js} +1 -1
  32. package/dist/assets/{javascript-CHFzcwro.js → javascript-DU8Xgp6c.js} +1 -1
  33. package/dist/assets/{main-cad-bbPyIDxb.js → main-cad-J2VK-edE.js} +6 -6
  34. package/dist/assets/{pmiDialogs-BFqEnCKw.js → pmiDialogs-DtSa0QaG.js} +1 -1
  35. package/dist/assets/{test-XEjDO9UE.js → test-D-0BGqtx.js} +3 -3
  36. package/dist/cad.html +10 -10
  37. package/dist/feature-dialog-capture.html +7 -7
  38. package/dist/help/index.html +3 -66
  39. package/dist/help/search-index.json +1 -1
  40. package/dist/pmi-dialog-capture.html +5 -5
  41. package/dist/test.html +1 -1
  42. package/dist/viewer.html +10 -10
  43. package/dist-kernel/brep-kernel.js +3 -10
  44. package/dist-kernel/help/index.html +3 -66
  45. package/dist-kernel/help/search-index.json +1 -1
  46. package/package.json +2 -3
  47. package/src/BREP/setupManifold.js +2 -7
  48. package/src/generated/licenseBundle.js +1 -1
  49. package/src/generated/manifoldSource.js +0 -1
  50. package/dist/assets/manifold-B8h_vZ5O.js +0 -16
  51. package/dist/assets/manifold-D9yvTBHx.wasm +0 -0
@@ -1 +1 @@
1
- var Je=Object.defineProperty;var je=i=>{throw TypeError(i)};var Rt=(i,s,t)=>s in i?Je(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t;var f=(i,s)=>Je(i,"name",{value:s,configurable:!0});var k=(i,s,t)=>Rt(i,typeof s!="symbol"?s+"":s,t),Wt=(i,s,t)=>s.has(i)||je("Cannot "+t);var le=(i,s,t)=>s.has(i)?je("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(i):s.set(i,t);var N=(i,s,t)=>(Wt(i,s,"access private method"),t);import{V as b,b as R,Q as me,v as Ke}from"./featureDialogs-CUWi02Qp.js";import{o as te,g as he}from"./annUtils-D9TT7tgs.js";const re=class re{constructor(s=null){this.partHistory=s,this.inputParams={},this.persistentData={}}getWorldPoint(s){if(!s)return null;try{const t=new b;if(typeof s.getWorldPosition=="function")return s.getWorldPosition(t),t;if(s.isVector3)return s.clone();if(s.position)return t.copy(s.position),s.parent&&s.parent.isObject3D&&(s.parent.updateMatrixWorld?.(!0),t.applyMatrix4(s.parent.matrixWorld)),t}catch{return null}return null}async run(s){return console.warn(`[${this.constructor.name}] run() not implemented.`),null}};f(re,"BaseAssemblyConstraint"),k(re,"shortName","ACON"),k(re,"longName","Assembly Constraint"),k(re,"constraintType","assembly_constraint"),k(re,"inputParamsSchema",{id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."}});let ne=re;const Pe=R.degToRad(.001),ct=R.degToRad(10),qt=256,It=1e-12;function $t(i){if(!i)return null;if(i.updateMatrixWorld?.(!0),typeof i.getAverageNormal=="function")try{const s=i.getAverageNormal();if(s&&s.lengthSq()>1e-10)return s.clone().normalize()}catch{}return Ye(i)}f($t,"getWorldNormal");function Lt(i,s){let t=null;if(i)try{t=te(null,i)}catch{}if(!t&&s){try{t=te(null,s)}catch{}!t&&typeof s.getWorldPosition=="function"&&(t=s.getWorldPosition(new b))}return t||null}f(Lt,"resolveOrigin");function Ye(i,s=0){if(!i||s>3)return null;const t=i.geometry;if(t&&t.isBufferGeometry){const e=Gt(i,t);if(e)return e}if(Array.isArray(i.children))for(const e of i.children){const r=Ye(e,s+1);if(r&&r.lengthSq()>0)return r}return null}f(Ye,"computeNormalFromObject");function Gt(i,s){if(!s?.isBufferGeometry)return null;const t=s.getAttribute?.("position");if(!t||t.itemSize!==3||t.count<3)return null;const e=s.getIndex?.(),r=Math.floor(e?e.count/3:t.count/3);if(r<=0)return null;i.updateMatrixWorld?.(!0);const o=new b,n=new b,a=new b,l=new b,c=new b,u=new b,d=new b,p=Math.min(r,60);let g=0;for(let m=0;m<p;m+=1){let h,S,y;if(e){const M=m*3;if(M+2>=e.count)break;h=e.getX(M),S=e.getX(M+1),y=e.getX(M+2)}else if(h=m*3,S=h+1,y=h+2,y>=t.count)break;o.set(t.getX(h),t.getY(h),t.getZ(h)).applyMatrix4(i.matrixWorld),n.set(t.getX(S),t.getY(S),t.getZ(S)).applyMatrix4(i.matrixWorld),a.set(t.getX(y),t.getY(y),t.getZ(y)).applyMatrix4(i.matrixWorld),l.subVectors(n,o),c.subVectors(a,o),u.crossVectors(l,c),u.lengthSq()>1e-10&&(d.add(u),g+=1)}return g===0||(d.divideScalar(g),d.lengthSq()<=1e-10)?null:d.normalize()}f(Gt,"computeNormalFromGeometry");function Ae(i){if(!i)return null;const s=i instanceof b?i.clone():new b(i.x??0,i.y??0,i.z??0);return s.lengthSq()<=1e-12?null:s.normalize()}f(Ae,"normalizeOrNull$2");function Ut(i,s){return!i||typeof i.getX!="function"||s<0||s>=i.count?null:new b(i.getX(s),i.getY(s),i.getZ(s))}f(Ut,"readAttributeVector");function et(i){if(!i)return null;try{const s=he(null,i);if(s&&s.lengthSq()>1e-12)return s.clone?s.clone():new b(s.x,s.y,s.z)}catch{}return null}f(et,"elementDirectionFrom");function Vt(i,s=qt){if(!i)return null;const t=i.userData?.polylineLocal,e=!!i.userData?.closedLoop,r=[];i.updateMatrixWorld?.(!0);const o=i.matrixWorld,n=f((d,p,g)=>{if(!Number.isFinite(d)||!Number.isFinite(p)||!Number.isFinite(g))return;const m=new b(d,p,g);m.applyMatrix4(o),r.push(m)},"pushPoint");if(Array.isArray(t)&&t.length>=2){for(const d of t)if(d){if(Array.isArray(d)&&d.length>=3){n(d[0],d[1],d[2]);continue}typeof d=="object"&&n(d.x??d[0]??0,d.y??d[1]??0,d.z??d[2]??0)}return r.length>=2?{points:r,closedLoop:e}:null}const a=i.geometry;if(!a)return null;const l=f((d,p)=>{if(d<=0)return;const g=d,m=Math.min(Math.max(g,1),Math.max(2,Math.min(g,s))),h=m>1?m-1:1;let S=-1;for(let y=0;y<m;y+=1){const M=h===0?0:y/h,F=Math.min(g-1,Math.round(M*(g-1)));if(F===S)continue;S=F;const v=p(F);v&&n(v.x,v.y,v.z)}if(S!==g-1){const y=p(g-1);y&&n(y.x,y.y,y.z)}},"sampleAttribute"),c=a.getAttribute?.("position");if(c&&c.itemSize===3&&c.count>=1)return l(c.count,d=>Ut(c,d)),r.length>=2?{points:r,closedLoop:e}:null;const u=a.attributes?.position?.array;if(u&&(Array.isArray(u)||ArrayBuffer.isView(u))){const d=Math.floor(u.length/3);return d<=0?null:(l(d,p=>{const g=p*3;return new b(u[g],u[g+1],u[g+2])}),r.length>=2?{points:r,closedLoop:e}:null)}return null}f(Vt,"collectEdgeSamplePoints");function Ct(i){if(!Array.isArray(i)||i.length<2)return null;const s=new b;for(const c of i)s.add(c);s.multiplyScalar(1/i.length);let t=0,e=0,r=0,o=0,n=0,a=0;for(const c of i){const u=c.x-s.x,d=c.y-s.y,p=c.z-s.z;t+=u*u,e+=u*d,r+=u*p,o+=d*d,n+=d*p,a+=p*p}const l=new b(1,0,0);o>t&&o>=a?l.set(0,1,0):a>t&&a>o&&l.set(0,0,1);for(let c=0;c<10;c+=1){const u=t*l.x+e*l.y+r*l.z,d=e*l.x+o*l.y+n*l.z,p=r*l.x+n*l.y+a*l.z,g=Math.hypot(u,d,p);if(g<=1e-9)return null;l.set(u/g,d/g,p/g)}return l.normalize()}f(Ct,"principalAxisFromPoints");function _t(i){if(!i)return null;const s=Vt(i);if(!s)return null;const{points:t,closedLoop:e}=s;if(!t||t.length<2)return null;if(e){const h=new Error("ParallelConstraint: Selected edge is a closed loop and has no unique tangent direction.");throw h.details={objectName:i?.name||null,reason:"edge-closed-loop"},h}const r=t[0].clone(),o=t[t.length-1].clone(),n=[r.clone(),o.clone()],a=t.reduce((h,S)=>h.add(S),new b).multiplyScalar(1/t.length),l=r.distanceToSquared(o)>1e-14?r.clone().add(o).multiplyScalar(.5):a.clone(),c=new b;let u=0;for(let h=1;h<t.length;h+=1){const S=t[h].clone().sub(t[h-1]),y=S.length();y>1e-9&&(c.add(S),u+=y)}const d=o.clone().sub(r),p=d.length();let g=Ct(t),m=g?"edge-principal-axis":null;return!g&&u>1e-9&&(g=c.clone().normalize(),m="edge-segment-average"),!g&&p>1e-9&&(g=d.clone().normalize(),m="edge-chord"),!g||g.lengthSq()<=1e-12?{endpoints:n,midpoint:l,sampleCount:t.length,chord:p>1e-9?d.clone():null,segmentAccum:u>1e-9?c.clone():null,direction:null,directionSource:"edge-direction-unresolved",totalSegmentLength:u,chordLength:p}:(p>1e-9&&g.dot(d)<0&&g.negate(),{endpoints:n,midpoint:l,sampleCount:t.length,chord:p>1e-9?d.clone():null,segmentAccum:u>1e-9?c.clone():null,direction:g?g.clone():null,directionSource:m,totalSegmentLength:u,chordLength:p,closedLoop:!!e})}f(_t,"resolveEdgeData");function Xt(i,s,t,e){const r=t==="EDGE",o=r?null:Ae(et(i)||et(s));if(r){const l=Ae(e?.direction);return l?{direction:l,source:e?.directionSource||"edge-data"}:{direction:null,source:e?.directionSource||"edge-direction-unresolved"}}const n=Ae($t(i));if(n)return{direction:n,source:"surface-normal"};if(o)return{direction:o,source:r?"edge-element-direction":"element-direction"};const a=Ae(Ye(i));return a?{direction:a,source:"geometry-normal"}:{direction:null,source:r?"edge-direction-unresolved":"unresolved"}}f(Xt,"resolveDirection");function Ht(i,s){const t=[];s&&typeof s.kind=="string"&&t.push(s.kind);const e=i?.userData;e?.type&&t.push(e.type),e?.brepType&&t.push(e.brepType),i?.type&&t.push(i.type);for(const r of t){const o=String(r||"").toUpperCase();if(o){if(o.includes("FACE"))return"FACE";if(o.includes("EDGE"))return"EDGE";if(o.includes("VERTEX")||o.includes("POINT"))return"POINT";if(o.includes("COMPONENT"))return"COMPONENT"}}return"UNKNOWN"}f(Ht,"selectionKindFrom$3");function Te(i,s,t,e){const r=s.resolveObject?.(t)||null,o=s.resolveComponent?.(t)||null,n=Ht(r,t),l=n==="EDGE"?_t(r):null;if(s.scene?.updateMatrixWorld)try{s.scene.updateMatrixWorld(!0)}catch{}o?.updateMatrixWorld?.(!0),r?.updateMatrixWorld?.(!0);let c=Lt(r,o);l?.midpoint&&(c=l.midpoint.clone());const u=Xt(r,o,n,l),d=u.direction;if(!d||d.lengthSq()===0){const p={selectionLabel:e,selection:t,objectName:r?.name||null,componentName:o?.name||null,kind:n,edgeData:l?{endpoints:l.endpoints?.map?.(m=>m.toArray())||null,directionSource:l.directionSource||null,sampleCount:l.sampleCount??null,chordLength:l.chordLength??null,totalSegmentLength:l.totalSegmentLength??null,closedLoop:l.closedLoop??null}:null,reason:u.source},g=new Error("ParallelConstraint: Unable to resolve a surface normal for the provided selection.");throw g.details=p,console.error("[ParallelConstraint] Failed to resolve normal for selection.",p,g),g}return{direction:d.clone().normalize(),origin:c,object:r,component:o||null,directionSource:u.source,kind:n,edgeData:l}}f(Te,"selectionDirection");function tt(i){if(!i)return"selection";const s=/^elements\[(\d+)\]$/i.exec(String(i));if(s){const e=Number(s[1]);if(Number.isFinite(e))return`Element ${e+1}`}const t=String(i).trim();return t?t.replace(/_/g," ").replace(/\s+/g," ").replace(/\b([a-z])/gi,(e,r)=>r.toUpperCase()):"selection"}f(tt,"describeSelectionLabel");function Kt(i){if(!i)return null;const s=i instanceof me?i.clone():new me(i.x??0,i.y??0,i.z??0,i.w??1);return!Number.isFinite(s.x)||!Number.isFinite(s.y)||!Number.isFinite(s.z)||!Number.isFinite(s.w)?null:(Math.abs(1-s.lengthSq())>1e-6&&s.normalize(),s)}f(Kt,"normalizeQuaternion");function Yt(i,s,t=1){if(!i||!s)return null;const e=i.clone().normalize(),r=s.clone().normalize(),o=R.clamp(e.dot(r),-1,1);let n=Math.acos(o);if(!Number.isFinite(n)||n<=1e-6)return null;const a=new b().crossVectors(e,r);a.lengthSq()<=1e-12&&(a.set(1,0,0).cross(e),a.lengthSq()<=1e-12&&a.set(0,1,0).cross(e)),a.normalize();const l=Math.max(0,Math.min(1,t)),c=n*l,u=Math.min(c,ct,n);return u<=1e-6?null:new me().setFromAxisAngle(a,u)}f(Yt,"computeRotation");function be(i,s,t,e,r){if(!s)return!1;const o=Yt(t,e,r);if(!o)return!1;const n=Kt(o);return n&&i.applyRotation?.(s,n)?{component:s,quaternion:n}:!1}f(be,"attemptRotation");function ve({constraint:i,context:s={},selectionA:t,selectionB:e,opposeNormals:r=!1,selectionLabelA:o="elements[0]",selectionLabelB:n="elements[1]"}){if(!i)throw new Error("solveParallelAlignment requires a constraint instance.");const a=tt(o),l=tt(n);let c,u;try{c=Te(i,s,t,o)}catch(q){return{ok:!1,status:"normal-resolution-failed",satisfied:!1,applied:!1,message:`Failed to resolve a normal for ${a}.`,exception:q,infoA:null,infoB:null}}try{u=Te(i,s,e,n)}catch(q){return{ok:!1,status:"normal-resolution-failed",satisfied:!1,applied:!1,message:`Failed to resolve a normal for ${l}.`,exception:q,infoA:c,infoB:null}}if(!c.component||!u.component)return{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:"Both selections must belong to assembly components.",infoA:c,infoB:u};if(c.component===u.component)return{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:"Select references from two different components.",infoA:c,infoB:u};const d=c.direction,p=u.direction;if(!d||!p)return{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:"Unable to resolve directions for one or both selections.",infoA:c,infoB:u};const g=r?d.clone().negate():d.clone(),m=r?p.clone().negate():p.clone(),h=R.clamp(p.dot(g),-1,1),S=Math.acos(h),y=R.radToDeg(S),M=Math.abs(s.tolerance??It),F=Math.max(Pe,M*10),v=s.isComponentFixed?.(c.component),D=s.isComponentFixed?.(u.component),E=s.rotationGain??1;if(S<=F)return{ok:!0,status:"satisfied",satisfied:!0,applied:!1,angle:S,angleDeg:y,error:S,infoA:c,infoB:u,message:"Reference directions are parallel within tolerance."};if(v&&D)return{ok:!1,status:"blocked",satisfied:!1,applied:!1,angle:S,angleDeg:y,error:S,infoA:c,infoB:u,message:"Both components are fixed; unable to rotate to satisfy constraint."};const P=[];let w=!1;const A=f(q=>{if(!q)return!1;const{component:B,quaternion:V}=q;return P.push({component:B.name||B.uuid,quaternion:V.toArray()}),B.updateMatrixWorld?.(!0),!0},"pushRotation");return!v&&!D?(w=A(be(s,c.component,d,m,E*.5))||w,w=A(be(s,u.component,p,g,E*.5))||w):v&&!D?w=A(be(s,u.component,p,g,E))||w:!v&&D&&(w=A(be(s,c.component,d,m,E))||w),{ok:!0,status:w?"adjusted":"pending",satisfied:!1,applied:w,angle:S,angleDeg:y,error:S,infoA:c,infoB:u,message:w?"Applied rotation to improve parallelism.":"Waiting for a movable component to rotate.",rotations:P,diagnostics:{angle:S,angleDeg:y,rotations:P}}}f(ve,"solveParallelAlignment");function ee(i,s,t,e){return Te(i,s,t,e)}f(ee,"resolveParallelSelection");const Zt=1e-12,Qt={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two faces or edges.",selectionFilter:["FACE","EDGE"],multiple:!0,minSelections:2,maxSelections:2},angle:{type:"number",label:"Angle (deg)",default_value:90,hint:"Desired signed angle between Element A and Element B in degrees. Exterior uses supplementary angle (180 - interior)."},exteriorAngle:{type:"boolean",label:"Exterior Angle",default_value:!1,hint:"Measure and solve using the exterior (supplementary) angle."}};var I,ut,Fe,dt,ft,pt,Oe;const H=class H extends ne{constructor(t){super(t);le(this,I)}async solve(t={}){const e=this.persistentData=this.persistentData||{},[r,o]=Jt(this.inputParams),n=N(this,I,ut).call(this),a=en(this.inputParams.angle,n);let l=a.modeDeg,c=a.signPreference,u=R.degToRad(l);if(!r||!o)return e.status="incomplete",e.message="Select two references to define the constraint.",e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:e.message};let d,p;try{d=N(this,I,Fe).call(this,t,r,"elements[0]"),p=N(this,I,Fe).call(this,t,o,"elements[1]")}catch(T){const ae=T?.message||"Unable to resolve selection references.";return e.status="invalid-selection",e.message=ae,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],e.exception=T,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:ae,exception:T}}if(!d||!p||!d.direction||!p.direction){const T="Unable to resolve directions for the selected references.";return e.status="invalid-selection",e.message=T,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:T}}if(!d.component||!p.component){const T="Both selections must belong to assembly components.";return e.status="invalid-selection",e.message=T,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:T}}if(d.component===p.component){const T="Select references from two different components.";return e.status="invalid-selection",e.message=T,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:T}}const g=N(this,I,pt).call(this,d,p);if(!g){const T="Unable to measure angle between selections.";return e.status="invalid-selection",e.message=T,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:T}}const m=g.angle,h=g.angleDeg,S=g.signedAngle,y=g.signedAngleDeg,M=y<-1e-9?-1:y>1e-9?1:0,F=Math.max(0,Math.PI-m),v=Math.max(0,180-h),D=n?F:m,E=n?v:h;let P=!1;e.isNewConstraint===!0&&(l=E,c=M||c,u=R.degToRad(l),P=!0,e.initializedAngle=l,e.isNewConstraint=!1);const w=tn(S,u,c),A=Me(S-w),x=t.isComponentFixed?.(d.component),z=t.isComponentFixed?.(p.component),q=Math.abs(t.tolerance??Zt),B=Number.isFinite(t.angleTolerance)?Math.abs(t.angleTolerance):null,V=B&&B>0?Math.max(Pe,B):Math.max(Pe,q*10);if(e.error=Math.abs(A),e.errorDeg=Math.abs(R.radToDeg(A)),Math.abs(A)<=V){const T=P?`Initialized ${n?"exterior":"interior"} angle from current orientation.`:"Angle satisfied within tolerance.";return e.status="satisfied",e.message=T,e.satisfied=!0,e.lastAppliedRotations=[],e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!0,status:"satisfied",satisfied:!0,applied:!1,angle:m,angleDeg:h,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,error:A,message:T,infoA:d,infoB:p,diagnostics:{angle:m,angleDeg:h,exteriorAngle:F,exteriorAngleDeg:v,measuredModeAngle:D,measuredModeAngleDeg:E,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,targetAngleDeg:l,useExteriorAngle:n,error:A,initializedFromMeasuredAngle:P},persistInputParams:P?{angle:l}:null}}if(x&&z){const T="Both components are fixed; unable to adjust angle.";return e.status="blocked",e.message=T,e.satisfied=!1,e.lastAppliedRotations=[],e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!1,status:"blocked",satisfied:!1,applied:!1,angle:m,angleDeg:h,targetAngle:u,targetSignedAngle:w,error:A,message:T,infoA:d,infoB:p,diagnostics:{angle:m,angleDeg:h,exteriorAngle:F,exteriorAngleDeg:v,measuredModeAngle:D,measuredModeAngleDeg:E,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,targetAngleDeg:l,useExteriorAngle:n,error:A,initializedFromMeasuredAngle:P}}}const W=S-w,G=0,C=S;let _,se;if(!x&&!z){const T=W/2;_=G+T,se=C-T}else!x&&z?(se=C,_=se-w):(_=G,se=_+w);const De=Math.max(0,Math.min(1,t.rotationGain??1)),de=[];let U=!1;const we=f((T,ae,ye,Ne)=>{if(!T?.component||!ae||!ye)return!1;const oe=sn(ae,ye,De*Ne);return!oe||!t.applyRotation?.(T.component,oe)?!1:(de.push({component:T.component.name||T.component.uuid,quaternion:oe.toArray()}),T.component.updateMatrixWorld?.(!0),!0)},"applyRotation"),X=!x&&!z?.5:x?0:1,Y=!x&&!z?.5:z?0:1;if(X>0){const T=N(this,I,Oe).call(this,g,_);U=we(d,g.dirA,T,X)||U}if(Y>0){const T=N(this,I,Oe).call(this,g,se);U=we(p,g.dirB,T,Y)||U}const fe=U?"adjusted":"pending",pe=U?"Applied rotation to move toward target angle.":"Waiting for a movable component to rotate.";return e.status=fe,e.message=pe,e.satisfied=!1,e.lastAppliedRotations=de,e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!0,status:fe,satisfied:!1,applied:U,angle:m,angleDeg:h,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,error:A,message:pe,infoA:d,infoB:p,rotations:de,diagnostics:{angle:m,angleDeg:h,exteriorAngle:F,exteriorAngleDeg:v,measuredModeAngle:D,measuredModeAngleDeg:E,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,targetAngleDeg:l,useExteriorAngle:n,error:A,shareA:X,shareB:Y,desiredSignedAngle:w,initializedFromMeasuredAngle:P}}}async run(t={}){return this.solve(t)}};I=new WeakSet,ut=f(function(){return this.inputParams?.exteriorAngle===!0},"#useExteriorAngle"),Fe=f(function(t,e,r){const o=t.resolveObject?.(e)||null,n=t.resolveComponent?.(e)||null,a=jt(o,e);if(a==="FACE")return ee(this,t,e,r);if(a!=="EDGE")throw new Error(`AngleConstraint: Unsupported selection for ${r}.`);const l=N(this,I,dt).call(this,o,n)||new b,c=N(this,I,ft).call(this,o,n);if(!c)throw new Error("AngleConstraint: Unable to resolve edge direction.");return{selection:e,object:o,component:n||null,origin:l,direction:c,kind:a}},"#resolveSelectionInfo"),dt=f(function(t,e){if(t){try{const r=te(null,t);if(r&&typeof r.clone=="function")return r.clone()}catch{}if(typeof t.getWorldPosition=="function")return t.getWorldPosition(new b);if(t.isVector3)return t.clone()}if(e){if(e.updateMatrixWorld?.(!0),typeof e.getWorldPosition=="function")return e.getWorldPosition(new b);if(e.position){const r=e.position.clone();return e.parent?.updateMatrixWorld?.(!0),e.parent?.matrixWorld?r.applyMatrix4(e.parent.matrixWorld.clone()):r}}return null},"#resolveOrigin"),ft=f(function(t,e){const r=he(null,t);if(r&&r.lengthSq()>0)return r.clone().normalize();if(e){const n=he(null,e);if(n&&n.lengthSq()>0)return n.clone().normalize()}const o=t?.geometry;if(o?.getAttribute){const n=o.getAttribute("position");if(n&&n.count>=2){const a=new b(n.getX(0),n.getY(0),n.getZ(0)),l=new b(n.getX(1),n.getY(1),n.getZ(1));return t.updateMatrixWorld?.(!0),a.applyMatrix4(t.matrixWorld),l.applyMatrix4(t.matrixWorld),l.sub(a).normalize()}}return null},"#resolveEdgeDirection"),pt=f(function(t,e){const r=nt(t?.direction),o=nt(e?.direction);if(!r||!o)return null;let n=new b().crossVectors(r,o);if(n.lengthSq()<=1e-12&&(n=Be(r)),n.lengthSq()<=1e-12)return null;n.normalize();let a=new b().crossVectors(n,r);if(a.lengthSq()<=1e-12&&(a=Be(r)),a.lengthSq()<=1e-12)return null;a.normalize();const l=R.clamp(r.dot(o),-1,1),c=R.clamp(a.dot(o),-1,1),u=Math.atan2(c,l),d=Math.acos(l);return{angle:d,angleDeg:R.radToDeg(d),signedAngle:u,signedAngleDeg:R.radToDeg(u),axis:n,basisU:a,dirA:r,dirB:o}},"#measureAngle"),Oe=f(function(t,e){if(!t)return null;const{dirA:r,basisU:o}=t;if(!r||!o)return null;const n=Math.cos(e),a=Math.sin(e),l=r.clone().multiplyScalar(n).add(o.clone().multiplyScalar(a));return l.lengthSq()===0?null:l.normalize()},"#directionFromAngle"),f(H,"AngleConstraint"),k(H,"shortName","∠"),k(H,"longName","∠ Angle Constraint"),k(H,"constraintType","angle"),k(H,"focusField","angle"),k(H,"aliases",["angle","angle_between","angular","ANGL"]),k(H,"inputParamsSchema",Qt);let ke=H;function Jt(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(Jt,"selectionPair$4");function jt(i,s){const t=s&&typeof s.kind=="string"?s.kind:null,e=(i?.userData?.type||i?.userData?.brepType||i?.type||t||"").toString().toUpperCase();return e?e.includes("FACE")?"FACE":e.includes("EDGE")?"EDGE":e.includes("VERTEX")||e.includes("POINT")?"POINT":e.includes("COMPONENT")?"COMPONENT":e:"UNKNOWN"}f(jt,"selectionKindFrom$2");function nt(i){return!i||i.lengthSq()===0?null:i.clone().normalize()}f(nt,"normalizeOrNull$1");function Be(i){if(!i||i.lengthSq()===0)return new b(0,0,1);const s=Math.abs(i.dot(new b(0,0,1)))<.9?new b(0,0,1):new b(0,1,0),t=new b().crossVectors(i,s);return t.lengthSq()===0&&t.crossVectors(i,new b(1,0,0)),t.lengthSq()===0?new b(1,0,0):t.normalize()}f(Be,"arbitraryPerpendicular$1");function en(i,s=!1){const t=Number(i),e=Number.isFinite(t)?R.clamp(t,-360,360):0,r=e<-1e-9?-1:e>1e-9?1:0,o=nn(Math.abs(e)),n=o>180?360-o:o,a=n>=180-1e-9?0:180-n;return{modeDeg:s?a:n,signPreference:r}}f(en,"resolveTargetAngleMode");function tn(i,s,t=0){const e=gt(s),r=Me(e),o=Math.abs(r);if(o<=1e-9||Math.abs(o-Math.PI)<=1e-9)return r;const n=[r,-r];if(t>0)return n.find(u=>u>0)??n[0];if(t<0)return n.find(u=>u<0)??n[0];const a=Number.isFinite(i)?Me(i):0;let l=n[0],c=st(a,l);for(let u=1;u<n.length;u+=1){const d=st(a,n[u]);d<c&&(c=d,l=n[u])}return l}f(tn,"chooseSignedTargetAngle");function nn(i){if(!Number.isFinite(i))return 0;const s=(i%360+360)%360;return s<=1e-9||Math.abs(s-360)<=1e-9?0:s}f(nn,"normalizePositiveAngleDeg");function gt(i){if(!Number.isFinite(i))return 0;const s=Math.PI*2,t=(i%s+s)%s;return t<=1e-9||Math.abs(t-s)<=1e-9?0:t}f(gt,"normalizePositiveAngleRad");function Me(i){const s=gt(i);return s>Math.PI?s-Math.PI*2:s}f(Me,"normalizeSignedAngleRad");function st(i,s){return Math.abs(Me(i-s))}f(st,"angularDistanceSignedRad");function sn(i,s,t=1){if(!i||!s)return null;const e=i.clone().normalize(),r=s.clone().normalize(),o=R.clamp(e.dot(r),-1,1);let n=Math.acos(o);if(!Number.isFinite(n)||n<=1e-6)return null;let a=new b().crossVectors(e,r);if(a.lengthSq()<=1e-12&&(a=Be(e)),a.lengthSq()<=1e-12)return null;a.normalize();const l=Math.max(0,Math.min(1,t)),c=n*l,u=Math.min(c,ct,n);return u<=1e-6?null:new me().setFromAxisAngle(a,u)}f(sn,"computeRotationTowards");const on=1e-6,rn={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two references (vertex, edge, face, or component).",selectionFilter:["VERTEX","EDGE","FACE","COMPONENT"],multiple:!0,minSelections:2,maxSelections:2},applyImmediately:{type:"boolean",label:"Apply Immediately",default_value:!1,hint:"Maintained for compatibility; runtime solver applies adjustments iteratively."},faceNormalOpposed:{type:"boolean",label:"Oppose Face Normals",default_value:!1,hint:"Preserved for future expansion."}},Z=class Z extends ne{async solve(s={}){const t=this.persistentData=this.persistentData||{},e=Math.max(Math.abs(s.tolerance??on),1e-8),[r,o]=an(this.inputParams);if(!r||!o)return t.status="incomplete",t.message="Select two references to define the constraint.",t.satisfied=!1,{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:t.message};const n=ot(this,s,r),a=ot(this,s,o);if(!n.component||!a.component)return t.status="invalid-selection",t.message="Both selections must belong to assembly components.",t.satisfied=!1,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:t.message};if(n.component===a.component)return t.status="invalid-selection",t.message="Select references from two different components.",t.satisfied=!1,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:t.message};if(!n.point||!a.point)return t.status="invalid-selection",t.message="Unable to resolve world-space positions for one or both selections.",t.satisfied=!1,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:t.message};const l=new b().subVectors(n.point,a.point),c=l.length(),u=s.isComponentFixed?.(n.component),d=s.isComponentFixed?.(a.component),p=s.translationGain??1;if(c<=e)return t.status="satisfied",t.message="Selections are coincident within tolerance.",t.error=c,t.satisfied=!0,t.lastAppliedMoves=[],{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:c,message:t.message};if(u&&d)return t.status="blocked",t.message="Both components are fixed; unable to adjust positions.",t.error=c,t.satisfied=!1,t.lastAppliedMoves=[],{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:c,message:t.message};const g=[];let m=!1;const h=f((M,F)=>{if(!M||!F||F.lengthSq()===0)return!1;const v=s.applyTranslation?.(M,F);return v&&g.push({component:M.name||M.uuid,move:cn(F)}),v},"applyMove");if(!u&&!d){const M=l.clone().multiplyScalar(.5*p);M.lengthSq()>0&&(m=h(n.component,M.clone().multiplyScalar(-1))||m,m=h(a.component,M)||m)}else if(u&&!d){const M=l.clone().multiplyScalar(p);M.lengthSq()>0&&(m=h(a.component,M)||m)}else if(!u&&d){const M=l.clone().multiplyScalar(p);M.lengthSq()>0&&(m=h(n.component,M.clone().multiplyScalar(-1))||m)}const S=m?"adjusted":"pending",y=m?"Applied translation to reduce separation.":"Waiting for a movable component to adjust.";return t.status=S,t.message=y,t.error=c,t.satisfied=!1,g.length&&(t.lastAppliedMoves=g),{ok:!0,status:S,satisfied:!1,applied:m,error:c,message:y,diagnostics:{distance:c,moves:g}}}async run(s={}){return this.solve(s)}};f(Z,"CoincidentConstraint"),k(Z,"shortName","COIN"),k(Z,"longName","Coincident Constraint"),k(Z,"constraintType","coincident"),k(Z,"aliases",["mate","coincident","coincident constraint"]),k(Z,"inputParamsSchema",rn);let ze=Z;function an(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(an,"selectionPair$3");function ln(i,s,t){if(s){try{const r=te(null,s);if(r&&typeof r.clone=="function")return r.clone()}catch{}const e=i.getWorldPoint(s);if(e)return e}if(t){t.updateMatrixWorld?.(!0);const e=i.getWorldPoint(t);if(e)return e}return null}f(ln,"resolvePoint");function ot(i,s,t){const e=s.resolveObject?.(t)||null,r=s.resolveComponent?.(t)||null,o=ln(i,e,r);return{object:e,component:r,point:o}}f(ot,"selectionInfo");function cn(i){return i?[i.x,i.y,i.z]:[0,0,0]}f(cn,"vectorToArray$2");const un=1e-6,dn={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two references (point, edge, face, or component).",selectionFilter:["FACE","VERTEX","EDGE"],multiple:!0,minSelections:2,maxSelections:2},distance:{type:"number",label:"Distance",default_value:0,hint:"Desired separation between references."},opposeNormals:{type:"boolean",label:"Oppose Normals",default_value:!1,hint:"For face-to-face mode, flip Element B normal before alignment."}};var O,mt,ht,yt,We,At,bt,St,vt,qe,Mt,xt,Ie,Dt,wt,Nt;const K=class K extends ne{constructor(t){super(t);le(this,O);this._debugHelpers=[]}async solve(t={}){const e=this.persistentData=this.persistentData||{},[r,o]=fn(this.inputParams),n=Number(this.inputParams.distance??0),a=Number.isFinite(n)?Math.max(0,n):0;if((t.iteration??0)===0&&N(this,O,wt).call(this,t.scene||null),!r||!o)return e.status="incomplete",e.message="Select two references to define the constraint.",e.satisfied=!1,e.error=null,e.lastAppliedMoves=[],e.lastAppliedRotations=[],{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:e.message};const l=Math.max(Math.abs(t.tolerance??un),1e-8),c=Math.max(0,Math.min(1,t.translationGain??1)),u=N(this,O,yt).call(this,t,r,o);let d,p,g=null;if(u){const B=N(this,O,mt).call(this,t,r,o);if(g=ve({constraint:this,context:t,selectionA:r,selectionB:o,opposeNormals:B,selectionLabelA:"elements[0]",selectionLabelB:"elements[1]"}),d=g.infoA||null,p=g.infoB||null,e.lastAppliedRotations=Array.isArray(g.rotations)?g.rotations:[],t.debugMode&&d&&p&&N(this,O,Dt).call(this,t,d,p),!g.ok)return e.status=g.status,e.message=g.message||"",e.satisfied=!1,e.error=g.error??null,e.errorDeg=g.angleDeg??null,e.exception=g.exception||null,e.lastAppliedMoves=[],{...g,stage:"orientation"};if(!g.satisfied)return e.status=g.status,e.message=g.message||"Aligning surfaces…",e.satisfied=!1,e.error=g.angle??null,e.errorDeg=g.angleDeg??null,e.lastAppliedMoves=[],e.exception&&delete e.exception,{...g,stage:"orientation"}}else d=N(this,O,We).call(this,t,r,"elements[0]"),p=N(this,O,We).call(this,t,o,"elements[1]");if(!d||!p||!d.origin||!p.origin){const B="Unable to resolve world-space references for the selection.";return e.status="invalid-selection",e.message=B,e.satisfied=!1,e.error=null,e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:B}}const m=N(this,O,St).call(this,d,p,a,l);if(!m||!Number.isFinite(m.distance)){const B="Unable to measure distance between selections.";return e.status="invalid-selection",e.message=B,e.satisfied=!1,e.error=null,e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:B}}const h=m.distance;let S=a,y=!1;u&&e.isNewConstraint===!0&&(S=Math.max(0,h),y=!0,e.initializedDistance=S,e.isNewConstraint=!1);const M=h-S,F=t.isComponentFixed?.(d.component),v=t.isComponentFixed?.(p.component);if(e.error=Math.abs(M),e.errorDeg=null,Math.abs(M)<=l){const B=y?"Initialized distance from current face separation.":"Distance satisfied within tolerance.";return e.status="satisfied",e.message=B,e.satisfied=!0,e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:Math.abs(M),message:B,infoA:d,infoB:p,diagnostics:{distance:h,targetDistance:S,error:M,stage:u?"offset":"general",initializedFromFaceDistance:y},persistInputParams:y?{distance:S}:null}}if(F&&v){const B="Both components are fixed; unable to adjust distance.";return e.status="blocked",e.message=B,e.satisfied=!1,e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:Math.abs(M),message:B,infoA:d,infoB:p,diagnostics:{distance:h,targetDistance:S,error:M,stage:u?"offset":"general",initializedFromFaceDistance:y}}}const D=m.directions,E=[];let P=!1;const w=f((B,V,W)=>{if(!B?.component||!V||V.lengthSq()===0||W===0)return!1;const G=V.clone().normalize().multiplyScalar(W*c*(S-h));if(G.lengthSq()===0)return!1;const C=t.applyTranslation?.(B.component,G);return C&&E.push({component:B.component.name||B.component.uuid,move:pn(G)}),C},"applyCorrection"),A=!F&&d.component,x=!v&&p.component;A&&x?(P=w(d,D.increaseA,.5)||P,P=w(p,D.increaseB,.5)||P):A&&!x?P=w(d,D.increaseA,1)||P:!A&&x&&(P=w(p,D.increaseB,1)||P);const z=P?"adjusted":"pending",q=P?"Applied translation to move toward target distance.":"Waiting for a movable component to translate.";return e.status=z,e.message=q,e.satisfied=!1,e.lastAppliedMoves=E,e.exception&&delete e.exception,{ok:!0,status:z,satisfied:!1,applied:P,error:Math.abs(M),message:q,infoA:d,infoB:p,diagnostics:{distance:h,targetDistance:S,error:M,moves:E,stage:u?"offset":"general",initializedFromFaceDistance:y}}}async run(t={}){return this.solve(t)}};O=new WeakSet,mt=f(function(t,e,r){const o=N(this,O,ht).call(this,t,e,r);return!!this.inputParams.opposeNormals?!o:o},"#effectiveOppose"),ht=f(function(t,e,r){const o=this.persistentData=this.persistentData||{},n=gn(t,e,r),a=!!n;if(typeof o.preferredOppose!="boolean"||a&&o.preferredOpposeSignature!==n)try{const c=ee(this,t,e,"elements[0]"),u=ee(this,t,r,"elements[1]"),d=c?.direction?.clone()?.normalize(),p=u?.direction?.clone()?.normalize();if(!d||!p||d.lengthSq()===0||p.lengthSq()===0)throw new Error("DistanceConstraint: Unable to resolve directions for orientation preference.");const g=R.clamp(d.dot(p),-1,1);o.preferredOppose=g<0,o.lastOrientationDot=g,a?o.preferredOpposeSignature=n:o.preferredOpposeSignature&&delete o.preferredOpposeSignature}catch(c){typeof o.preferredOppose!="boolean"&&(o.preferredOppose=!1),t?.debugMode&&console.warn("[DistanceConstraint] Failed to capture orientation preference.",{id:this.inputParams?.id??this.inputParams?.constraintID??null,error:c})}return!!o.preferredOppose},"#preferredOppose"),yt=f(function(t,e,r){const o=t.resolveObject?.(e)||null,n=t.resolveObject?.(r)||null,a=ie(o,e),l=ie(n,r);return a==="FACE"&&l==="FACE"},"#isFaceFace"),We=f(function(t,e,r){const o=t.resolveObject?.(e)||null,n=t.resolveComponent?.(e)||null,a=ie(o,e);if(a==="FACE")return ee(this,t,e,r);const l=N(this,O,At).call(this,o,n)||new b;let c=null;return a==="EDGE"&&(c=N(this,O,bt).call(this,o,n)),{selection:e,object:o,component:n||null,origin:l,direction:c,kind:a}},"#resolveSelectionInfo"),At=f(function(t,e){if(t){try{const r=te(null,t);if(r&&typeof r.clone=="function")return r.clone()}catch{}if(typeof t.getWorldPosition=="function")return t.getWorldPosition(new b);if(t.isVector3)return t.clone()}if(e){if(e.updateMatrixWorld?.(!0),typeof e.getWorldPosition=="function")return e.getWorldPosition(new b);if(e.position){const r=e.position.clone();return e.parent?.updateMatrixWorld?.(!0),e.parent?.matrixWorld?r.applyMatrix4(e.parent.matrixWorld.clone()):r}}return null},"#resolveOrigin"),bt=f(function(t,e){const r=he(null,t);if(r&&r.lengthSq()>0)return r.clone().normalize();if(e){const n=he(null,e);if(n&&n.lengthSq()>0)return n.clone().normalize()}const o=t?.geometry;if(o?.getAttribute){const n=o.getAttribute("position");if(n&&n.count>=2){const a=new b(n.getX(0),n.getY(0),n.getZ(0)),l=new b(n.getX(1),n.getY(1),n.getZ(1));return t.updateMatrixWorld?.(!0),a.applyMatrix4(t.matrixWorld),l.applyMatrix4(t.matrixWorld),l.sub(a).normalize()}}return null},"#resolveEdgeDirection"),St=f(function(t,e,r,o){const n=(t.kind||ie(t.object,t.selection)).toUpperCase?.()||ie(t.object,t.selection),a=(e.kind||ie(e.object,e.selection)).toUpperCase?.()||ie(e.object,e.selection);if(n==="FACE"&&a==="FACE")return N(this,O,xt).call(this,t,e);if(n==="FACE"&&a!=="FACE")return N(this,O,Ie).call(this,t,e);if(a==="FACE"&&n!=="FACE"){const l=N(this,O,Ie).call(this,e,t);return l?{distance:l.distance,directions:{increaseA:l.directions.increaseB,increaseB:l.directions.increaseA}}:null}return n==="EDGE"&&a==="POINT"?N(this,O,qe).call(this,e,t,!0):n==="POINT"&&a==="EDGE"?N(this,O,qe).call(this,t,e,!1):n==="EDGE"&&a==="EDGE"?N(this,O,Mt).call(this,t,e):N(this,O,vt).call(this,t,e)},"#measureDistance"),vt=f(function(t,e){const r=new b().subVectors(e.origin,t.origin),o=r.length(),n=o>1e-9?r.clone().divideScalar(o):new b(1,0,0);return{distance:o,directions:{increaseA:n.clone().negate(),increaseB:n}}},"#pointPointDistance"),qe=f(function(t,e,r){const o=ge(e.direction)||new b(1,0,0),n=e.origin.clone(),a=t.origin.clone(),c=a.clone().sub(n).dot(o),u=n.clone().add(o.clone().multiplyScalar(c)),d=a.clone().sub(u);let p=d.length(),g=p>1e-9?d.clone().divideScalar(p):it(o);return p=Math.abs(p),r?{distance:p,directions:{increaseA:g.clone().negate(),increaseB:g.clone()}}:{distance:p,directions:{increaseA:g.clone(),increaseB:g.clone().negate()}}},"#pointEdgeDistance"),Mt=f(function(t,e){const r=ge(t.direction),o=ge(e.direction);if(!r||!o)return null;const n=t.origin.clone(),a=e.origin.clone(),l=r.clone(),c=o.clone(),u=n.clone().sub(a),d=l.dot(l),p=l.dot(c),g=c.dot(c),m=l.dot(u),h=c.dot(u),S=d*g-p*p;let y,M;Math.abs(S)<1e-8?(y=0,M=p>g?m/p:h/g):(y=(p*h-g*m)/S,M=(d*h-p*m)/S);const F=n.clone().add(l.clone().multiplyScalar(y)),D=a.clone().add(c.clone().multiplyScalar(M)).clone().sub(F),E=D.length(),P=E>1e-9?D.clone().divideScalar(E):it(l);return{distance:E,directions:{increaseA:P.clone().negate(),increaseB:P}}},"#edgeEdgeDistance"),xt=f(function(t,e){const r=ge(t.direction),o=t.origin.clone(),n=e.origin.clone();if(!r)return null;let l=n.clone().sub(o).dot(r);Number.isFinite(l)||(l=0);const c=l>=0?r.clone():r.clone().negate();return{distance:Math.abs(l),directions:{increaseA:c.clone().negate(),increaseB:c}}},"#faceFaceDistance"),Ie=f(function(t,e){const r=ge(t.direction);if(!r)return null;const o=t.origin.clone(),l=e.origin.clone().clone().sub(o).dot(r),c=Math.abs(l),u=l>=0?r.clone():r.clone().negate();return{distance:c,directions:{increaseA:u.clone().negate(),increaseB:u}}},"#facePointLikeDistance"),Dt=f(function(t,e,r){if(!t?.debugMode)return;const o=t.scene||null;if(!o)return;const n=t.iteration??0,a=[{info:e,color:16754253,label:"A"},{info:r,color:5096447,label:"B"}];for(const{info:l,color:c,label:u}of a){if(!l?.direction||!l.origin)continue;const d=l.direction.clone().normalize();if(d.lengthSq()===0)continue;const p=l.origin.clone(),g=Math.max(N(this,O,Nt).call(this,l),10),m=new Ke(d,p,g,c,g*.25,g*.15),h=this.inputParams?.id??this.inputParams?.constraintID??"unknown";m.name=`distance-constraint-normal-${h}-${u}-iter${n}`,o.add(m),this._debugHelpers.push(m)}},"#updateNormalDebug"),wt=f(function(t){if(this._debugHelpers){for(const e of this._debugHelpers)e&&(t&&e.parent===t?t.remove(e):e.parent&&e.parent.remove(e));this._debugHelpers.length=0}},"#clearDebug"),Nt=f(function(t){const e=[],r=f(n=>{if(!n)return;if(n.geometry?.computeBoundingSphere&&!n.geometry.boundingSphere)try{n.geometry.computeBoundingSphere()}catch{}const a=n.geometry?.boundingSphere;if(a?.radius&&e.push(Math.abs(a.radius)),n.geometry?.computeBoundingBox&&!n.geometry.boundingBox)try{n.geometry.computeBoundingBox()}catch{}const l=n.geometry?.boundingBox;if(l&&e.push(l.getSize(new b).length()/2),typeof n.getWorldScale=="function"){const c=n.getWorldScale(new b);e.push(c.length()*5)}},"pushBound");if(r(t.object),Array.isArray(t.component?.children))for(const n of t.component.children)r(n);e.push(t.component?.userData?.boundingRadius||0);const o=e.reduce((n,a)=>Number.isFinite(a)?Math.max(n,a):n,0);return Number.isFinite(o)&&o>0?o:0},"#estimateHelperLength"),f(K,"DistanceConstraint"),k(K,"shortName","⟺"),k(K,"longName","⟺ Distance Constraint"),k(K,"constraintType","distance"),k(K,"focusField","distance"),k(K,"aliases",["distance","offset","gap","DIST"]),k(K,"inputParamsSchema",dn);let Re=K;function fn(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(fn,"selectionPair$2");function pn(i){return i?[i.x,i.y,i.z]:[0,0,0]}f(pn,"vectorToArray$1");function ge(i){return!i||i.lengthSq()===0?null:i.normalize()}f(ge,"normalizeOrNull");function it(i){if(!i||i.lengthSq()===0)return new b(0,0,1);const s=Math.abs(i.dot(new b(0,0,1)))<.9?new b(0,0,1):new b(0,1,0),t=new b().crossVectors(i,s);return t.lengthSq()===0&&t.crossVectors(i,new b(1,0,0)),t.lengthSq()===0?new b(1,0,0):t.normalize()}f(it,"arbitraryPerpendicular");function ie(i,s){const t=s&&typeof s.kind=="string"?s.kind:null,e=(i?.userData?.type||i?.userData?.brepType||i?.type||t||"").toString().toUpperCase();return e?e.includes("FACE")?"FACE":e.includes("EDGE")?"EDGE":e.includes("VERTEX")||e.includes("POINT")?"POINT":e.includes("COMPONENT")?"COMPONENT":e:"UNKNOWN"}f(ie,"selectionKindFrom$1");function gn(i,s,t){const e=$e(i,s),r=$e(i,t);return!e||!r?null:[e,r].sort().join("|")}f(gn,"constraintSelectionPairSignature$1");function $e(i,s,t=0,e=new Set){if(s==null||t>5)return null;const r=typeof s;if(r==="string"||r==="number"||r==="boolean")return`${r}:${String(s)}`;if(Array.isArray(s)){const o=[],n=Math.min(s.length,4);for(let a=0;a<n;a+=1){const l=$e(i,s[a],t+1,e);l&&o.push(l)}return o.length?`arr:[${o.join(",")}]`:null}if(r!=="object"||e.has(s))return null;e.add(s);try{const o=["kind","type","name","selectionName","objectName","path","uuid","id","featureID"],n=[];for(const l of o){const c=s[l];if(c==null)continue;const u=typeof c;(u==="string"||u==="number"||u==="boolean")&&n.push(`${l}:${String(c)}`)}const a=mn(i,s);return a&&n.push(a),n.length?`obj:{${n.join(",")}}`:null}finally{e.delete(s)}}f($e,"constraintSelectionToken$1");function mn(i,s){if(!i||s==null)return null;const t=i.resolveObject?.(s)||null,e=i.resolveComponent?.(s)||null,r=[];if(t){const o=t.uuid||t.name||t.id||null;o!=null&&r.push(`object:${String(o)}`)}if(e){const o=e.uuid||e.name||e.id||null;o!=null&&r.push(`component:${String(o)}`)}return r.length?r.join(","):null}f(mn,"resolvedSelectionToken$1");const hn={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},component:{type:"reference_selection",label:"Component",hint:"Select the component that should remain fixed in the assembly.",selectionFilter:["COMPONENT"]}},Q=class Q extends ne{async solve(s={}){const t=this.persistentData=this.persistentData||{},e=yn(this.inputParams.component),r=s.resolveComponent?.(e)||s.resolveObject?.(e);if(!r||!r.isAssemblyComponent)return t.status="incomplete",t.message="Select an assembly component to fix in place.",t.satisfied=!1,{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:t.message};const o=s.isComponentFixed?s.isComponentFixed(r):!!r.fixed;r.fixed=!0,r.userData=r.userData||{},r.userData.fixedByConstraint=!0;const n=s.getFeatureForComponent?.(r);n&&(n.inputParams=n.inputParams||{},n.inputParams.isFixed=!0);const a=o?"Component already marked as fixed.":"Component locked in place by constraint.";return t.status="satisfied",t.message=a,t.satisfied=!0,t.error=0,t.componentName=r.name||r.owningFeatureID||null,{ok:!0,status:"satisfied",satisfied:!0,applied:!o,error:0,message:a}}async run(s={}){return this.solve(s)}};f(Q,"FixedConstraint"),k(Q,"shortName","⏚"),k(Q,"longName","⏚ Fixed Constraint"),k(Q,"constraintType","fixed"),k(Q,"aliases",["fix","fixed constraint","fixed","FIXD"]),k(Q,"inputParamsSchema",hn);let Le=Q;function yn(i){return i?Array.isArray(i)?i.find(s=>s!=null)??null:i:null}f(yn,"firstSelection");const An={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two faces, edges, or components.",selectionFilter:["FACE","EDGE","COMPONENT"],multiple:!0,minSelections:2,maxSelections:2},applyImmediately:{type:"boolean",label:"Apply Immediately",default_value:!1,hint:"Maintained for compatibility; solver applies adjustments iteratively."},reverse:{type:"boolean",label:"Reverse",default_value:!1,hint:"Flip the stored orientation preference."}};var L,Et,Pt,Tt,Ue,kt;const J=class J extends ne{constructor(t){super(t);le(this,L);this._debugHelpers=[]}clearDebugArrows(t={}){const e=t.scene||null;e&&N(this,L,Ue).call(this,e)}async solve(t={}){const e=this.persistentData=this.persistentData||{},[r,o]=bn(this.inputParams);if((t.iteration??0)===0&&N(this,L,Ue).call(this,t.scene||null),!r||!o)return e.status="incomplete",e.message="Select two references to define the constraint.",e.satisfied=!1,{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:e.message};const n=N(this,L,Et).call(this,t,r,o),a=ve({constraint:this,context:t,selectionA:r,selectionB:o,opposeNormals:n,selectionLabelA:"elements[0]",selectionLabelB:"elements[1]"}),l=a.infoA||null,c=a.infoB||null;if(t.debugMode&&l&&c&&N(this,L,Tt).call(this,t,l,c),t.debugMode&&l&&c){const u=l.direction,d=c.direction,p=typeof a.angle=="number"?a.angle:null,g=typeof a.angleDeg=="number"?a.angleDeg:typeof p=="number"?R.radToDeg(p):null;console.log("[ParallelConstraint] directions",{id:this.inputParams?.id??this.inputParams?.constraintID??null,selectionA:{normal:u?.toArray?.()||null,point:l.origin?.toArray?.()||null,source:l.directionSource,kind:l.kind||null},selectionB:{normal:d?.toArray?.()||null,point:c.origin?.toArray?.()||null,source:c.directionSource,kind:c.kind||null},angleRad:p,angleDeg:g})}return e.status=a.status,e.message=a.message||"",e.satisfied=!!a.satisfied,typeof a.angle=="number"?(e.error=a.angle,e.errorDeg=typeof a.angleDeg=="number"?a.angleDeg:R.radToDeg(a.angle)):(e.error=null,e.errorDeg=null),Array.isArray(a.rotations)&&a.rotations.length?e.lastAppliedRotations=a.rotations:e.lastAppliedRotations&&(!a.rotations||a.rotations.length===0)&&(e.lastAppliedRotations=[]),a.exception?e.exception=a.exception:e.exception&&delete e.exception,a}async run(t={}){return this.solve(t)}};L=new WeakSet,Et=f(function(t,e,r){const o=N(this,L,Pt).call(this,t,e,r);return!!this.inputParams.reverse?!o:o},"#effectiveOppose"),Pt=f(function(t,e,r){const o=this.persistentData=this.persistentData||{},n=Sn(t,e,r),a=!!n;if(typeof o.preferredOppose!="boolean"||a&&o.preferredOpposeSignature!==n)try{const c=ee(this,t,e,"elements[0]"),u=ee(this,t,r,"elements[1]"),d=c?.direction?.clone()?.normalize(),p=u?.direction?.clone()?.normalize();if(!d||!p||d.lengthSq()===0||p.lengthSq()===0)throw new Error("ParallelConstraint: Unable to resolve directions for orientation preference.");const g=R.clamp(d.dot(p),-1,1);o.preferredOppose=g<0,o.lastOrientationDot=g,a?o.preferredOpposeSignature=n:o.preferredOpposeSignature&&delete o.preferredOpposeSignature}catch(c){typeof o.preferredOppose!="boolean"&&(o.preferredOppose=!1),t?.debugMode&&console.warn("[ParallelConstraint] Failed to capture orientation preference.",{id:this.inputParams?.id??this.inputParams?.constraintID??null,error:c})}return!!o.preferredOppose},"#preferredOppose"),Tt=f(function(t,e,r){if(!t?.debugMode)return;const o=t.scene||null;if(!o)return;const n=t.iteration??0,a=[{info:e,color:16731469,label:"A"},{info:r,color:5111697,label:"B"}],l=this.inputParams?.id??this.inputParams?.constraintID??"unknown";for(const{info:c,color:u,label:d}of a){if(!c?.direction||!c.origin)continue;const p=c.direction.clone().normalize();if(p.lengthSq()===0)continue;const g=c.origin.clone(),m=Math.max(N(this,L,kt).call(this,c),10),h=new Ke(p,g,m,u,m*.25,m*.15);h.name=`parallel-constraint-normal-${l}-${d}-iter${n}`,o.add(h),this._debugHelpers.push(h)}},"#updateNormalDebug"),Ue=f(function(t){if(this._debugHelpers){for(const e of this._debugHelpers)e&&(t&&e.parent===t?t.remove(e):e.parent&&e.parent.remove(e));this._debugHelpers.length=0}},"#clearNormalDebug"),kt=f(function(t){const e=[],r=f(n=>{if(!n)return;if(n.geometry?.computeBoundingSphere&&!n.geometry.boundingSphere)try{n.geometry.computeBoundingSphere()}catch{}const a=n.geometry?.boundingSphere;if(a?.radius&&e.push(Math.abs(a.radius)),n.geometry?.computeBoundingBox&&!n.geometry.boundingBox)try{n.geometry.computeBoundingBox()}catch{}const l=n.geometry?.boundingBox;if(l&&e.push(l.getSize(new b).length()/2),typeof n.getWorldScale=="function"){const c=n.getWorldScale(new b);e.push(c.length()*5)}},"pushBound");if(r(t.object),Array.isArray(t.component?.children))for(const n of t.component.children)r(n);e.push(t.component?.userData?.boundingRadius||0);const o=e.reduce((n,a)=>Number.isFinite(a)?Math.max(n,a):n,0);return Number.isFinite(o)&&o>0?o:0},"#estimateHelperLength"),f(J,"ParallelConstraint"),k(J,"shortName","∥"),k(J,"longName","∥ Parallel Constraint"),k(J,"constraintType","parallel"),k(J,"aliases",["parallel","parallel_faces","face_parallel","PARA"]),k(J,"inputParamsSchema",An);let Ge=J;function bn(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(bn,"selectionPair$1");function Sn(i,s,t){const e=Ve(i,s),r=Ve(i,t);return!e||!r?null:[e,r].sort().join("|")}f(Sn,"constraintSelectionPairSignature");function Ve(i,s,t=0,e=new Set){if(s==null||t>5)return null;const r=typeof s;if(r==="string"||r==="number"||r==="boolean")return`${r}:${String(s)}`;if(Array.isArray(s)){const o=[],n=Math.min(s.length,4);for(let a=0;a<n;a+=1){const l=Ve(i,s[a],t+1,e);l&&o.push(l)}return o.length?`arr:[${o.join(",")}]`:null}if(r!=="object"||e.has(s))return null;e.add(s);try{const o=["kind","type","name","selectionName","objectName","path","uuid","id","featureID"],n=[];for(const l of o){const c=s[l];if(c==null)continue;const u=typeof c;(u==="string"||u==="number"||u==="boolean")&&n.push(`${l}:${String(c)}`)}const a=vn(i,s);return a&&n.push(a),n.length?`obj:{${n.join(",")}}`:null}finally{e.delete(s)}}f(Ve,"constraintSelectionToken");function vn(i,s){if(!i||s==null)return null;const t=i.resolveObject?.(s)||null,e=i.resolveComponent?.(s)||null,r=[];if(t){const o=t.uuid||t.name||t.id||null;o!=null&&r.push(`object:${String(o)}`)}if(e){const o=e.uuid||e.name||e.id||null;o!=null&&r.push(`component:${String(o)}`)}return r.length?r.join(","):null}f(vn,"resolvedSelectionToken");const Ee=1e-6,Mn=R.degToRad(5),xn={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two faces, edges, or vertices.",selectionFilter:["FACE","EDGE","VERTEX"],multiple:!0,minSelections:2,maxSelections:2},reverse:{type:"boolean",label:"Reverse",default_value:!1,hint:"Flip the stored orientation preference."}};var $,_e,Ft,Xe,He,Ot;const j=class j extends ne{constructor(t){super(t);le(this,$);this._debugHelpers=[]}clearDebugArrows(t={}){const e=t.scene||null;e&&N(this,$,He).call(this,e)}async run(t={}){const e=this.persistentData=this.persistentData||{},[r,o]=Dn(this.inputParams);if((t.iteration??0)===0&&N(this,$,He).call(this,t.scene||null),!r||!o)return e.status="incomplete",e.message="Select two references to define the constraint.",e.satisfied=!1,e.lastAppliedMoves=[],e.lastAppliedRotations=[],{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:e.message};const n=t.resolveObject?.(r)||null,a=t.resolveObject?.(o)||null,l=at(rt(n,r)),c=at(rt(a,o));if(l==="FACE"&&c==="FACE")return this.faceToFace(t,r,o);if(l==="EDGE"&&c==="EDGE")return this.edgeToEdge(t,r,o);if(l==="POINT"&&c==="POINT")return this.pointToPoint(t,r,o);const u="Touch Align requires two selections of the same type. Face-to-face alignment is currently supported.";return e.status="unsupported-selection",e.message=u,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedMoves=[],e.lastAppliedRotations=[],e.exception&&delete e.exception,{ok:!1,status:"unsupported-selection",satisfied:!1,applied:!1,message:u}}async solve(t={}){return this.run(t)}async faceToFace(t,e,r){const o=this.persistentData=this.persistentData||{},n=N(this,$,_e).call(this,t,e,r),a=ve({constraint:this,context:t,selectionA:e,selectionB:r,opposeNormals:n,selectionLabelA:"elements[0]",selectionLabelB:"elements[1]"}),l=a.infoA||null,c=a.infoB||null;if(t.debugMode&&l&&c&&N(this,$,Xe).call(this,t,l,c),o.lastAppliedRotations=Array.isArray(a.rotations)?a.rotations:[],!a.ok)return o.status=a.status,o.message=a.message||"",o.satisfied=!1,o.error=a.error??null,o.errorDeg=a.angleDeg??null,o.exception=a.exception||null,a;if(!a.satisfied)return o.status=a.status,o.message=a.message||"Aligning surface orientations…",o.satisfied=!1,o.error=a.angle??null,o.errorDeg=a.angleDeg??null,o.lastAppliedMoves=[],o.exception&&delete o.exception,{...a,stage:"orientation"};if(!l||!c||!l.origin||!c.origin||!l.direction){const A="Unable to resolve contact data after alignment.";return o.status="invalid-selection",o.message=A,o.satisfied=!1,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:A}}const u=t.isComponentFixed?.(l.component),d=t.isComponentFixed?.(c.component),p=t.translationGain??1,g=Math.max(Math.abs(t.tolerance??Ee),1e-8),m=l.direction.clone().normalize(),h=new b().subVectors(c.origin,l.origin),S=[];let y=!1;const M=f((A,x)=>{if(!A||!x||x.lengthSq()===0)return!1;const z=t.applyTranslation?.(A,x);return z&&S.push({component:A.name||A.uuid,move:ce(x)}),z},"applyMove"),F=h.dot(m),v=Math.abs(F);if(v<=g){const A="Faces are touching within tolerance.";return o.status="satisfied",o.message=A,o.satisfied=!0,o.error=v,o.errorDeg=0,o.lastAppliedMoves=[],{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:v,message:A,infoA:l,infoB:c,diagnostics:{separation:F,moves:[]}}}if(u&&d){const A="Both components are fixed; unable to translate to touch.";return o.status="blocked",o.message=A,o.satisfied=!1,o.error=v,o.errorDeg=0,{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:v,message:A,infoA:l,infoB:c,diagnostics:{separation:F,moves:[]}}}const D=-F*Math.max(0,Math.min(1,p)),E=D*.5;if(!u&&!d){const A=m.clone().multiplyScalar(-E),x=m.clone().multiplyScalar(E);y=M(l.component,A)||y,y=M(c.component,x)||y}else if(u&&!d){const A=m.clone().multiplyScalar(D);y=M(c.component,A)||y}else if(!u&&d){const A=m.clone().multiplyScalar(-D);y=M(l.component,A)||y}const P=y?"adjusted":"pending",w=y?"Applied translation to bring faces into contact.":"Waiting for a movable component to translate.";return o.status=P,o.message=w,o.satisfied=!1,o.error=v,o.errorDeg=0,o.lastAppliedMoves=S,o.exception&&delete o.exception,{ok:!0,status:P,satisfied:!1,applied:y,error:v,message:w,infoA:l,infoB:c,diagnostics:{separation:F,moves:S}}}async edgeToEdge(t,e,r){const o=t||{},n=this.persistentData=this.persistentData||{},a=N(this,$,_e).call(this,o,e,r),l=ve({constraint:this,context:o,selectionA:e,selectionB:r,opposeNormals:a,selectionLabelA:"elements[0]",selectionLabelB:"elements[1]"}),c=l.infoA||null,u=l.infoB||null;if(o.debugMode&&c&&u&&N(this,$,Xe).call(this,o,c,u),n.lastAppliedRotations=Array.isArray(l.rotations)?l.rotations:[],!l.ok)return n.status=l.status,n.message=l.message||"",n.satisfied=!1,n.error=l.error??null,n.errorDeg=l.angleDeg??null,n.lastAppliedMoves=[],n.exception=l.exception||null,l;if(!l.satisfied)return n.status=l.status,n.message=l.message||"Aligning edge directions…",n.satisfied=!1,n.error=l.angle??null,n.errorDeg=l.angleDeg??null,n.lastAppliedMoves=[],n.exception&&delete n.exception,{...l,stage:"orientation"};if(!c||!u||!c.origin||!u.origin||!c.direction){const x="Unable to resolve edge data after alignment.";return n.status="invalid-selection",n.message=x,n.satisfied=!1,n.lastAppliedMoves=[],n.error=null,n.errorDeg=null,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:x}}const d=o.isComponentFixed?.(c.component),p=o.isComponentFixed?.(u.component),g=Math.max(0,Math.min(1,o.translationGain??1)),m=Math.max(Math.abs(o.tolerance??Ee),1e-8),h=c.direction.clone().normalize(),S=new b().subVectors(u.origin,c.origin),y=h.clone().multiplyScalar(S.dot(h)),M=S.clone().sub(y),F=M.length();if(n.error=F,n.errorDeg=null,F<=m){const x="Edges are colinear within tolerance.";return n.status="satisfied",n.message=x,n.satisfied=!0,n.lastAppliedMoves=[],n.exception&&delete n.exception,{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:F,message:x,infoA:c,infoB:u,diagnostics:{separationVector:M.toArray(),parallelComponent:y.toArray()}}}if(d&&p){const x="Both components are fixed; unable to translate to make edges colinear.";return n.status="blocked",n.message=x,n.satisfied=!1,n.lastAppliedMoves=[],n.exception&&delete n.exception,{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:F,message:x,infoA:c,infoB:u,diagnostics:{separationVector:M.toArray(),parallelComponent:y.toArray()}}}const v=M.clone().multiplyScalar(g),D=[];let E=!1;const P=f((x,z)=>{if(!x||!z||z.lengthSq()===0)return!1;const q=o.applyTranslation?.(x,z);return q&&D.push({component:x.name||x.uuid,move:ce(z)}),q},"applyMove");if(!d&&!p){const x=v.clone().multiplyScalar(.5),z=v.clone().multiplyScalar(-.5);E=P(c.component,x)||E,E=P(u.component,z)||E}else if(d&&!p){const x=v.clone().negate();E=P(u.component,x)||E}else if(!d&&p){const x=v.clone();E=P(c.component,x)||E}const w=E?"adjusted":"pending",A=E?"Applied translation to bring edges onto the same line.":"Waiting for a movable component to translate.";return n.status=w,n.message=A,n.satisfied=!1,n.lastAppliedMoves=D,n.exception&&delete n.exception,{ok:!0,status:w,satisfied:!1,applied:E,error:F,message:A,infoA:c,infoB:u,diagnostics:{separationVector:M.toArray(),parallelComponent:y.toArray(),moves:D},stage:"translation"}}async pointToPoint(t,e,r){const o=t||{},n=this.persistentData=this.persistentData||{};let a=Se(this,o,e),l=Se(this,o,r);if(n.pointToPointNextMode=n.pointToPointNextMode==="rotate"?"rotate":"translate",!a?.component||!l?.component){const v="Point selections must belong to assembly components.";return n.status="invalid-selection",n.message=v,n.satisfied=!1,n.error=null,n.errorDeg=null,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:v}}if(a.component===l.component){const v="Select points from different components for touch alignment.";return n.status="invalid-selection",n.message=v,n.satisfied=!1,n.error=null,n.errorDeg=null,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:v}}if(!a.point||!l.point){const v="Unable to resolve world-space positions for the selected points.";return n.status="invalid-selection",n.message=v,n.satisfied=!1,n.error=null,n.errorDeg=null,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:v}}const c=Math.max(Math.abs(o.tolerance??Ee),1e-8),u=Math.max(0,Math.min(1,o.translationGain??1)),d=Math.max(0,Math.min(1,o.rotationGain??1)),p=o.isComponentFixed?.(a.component),g=o.isComponentFixed?.(l.component);let m=new b().subVectors(a.point,l.point),h=m.length();const S=f(()=>{const v=Se(this,o,e),D=Se(this,o,r);v?.point&&D?.point&&(a=v,l=D,m=new b().subVectors(a.point,l.point),h=m.length())},"refreshInfo");if(n.error=h,n.errorDeg=null,h<=c){const v="Points are coincident within tolerance.";return n.status="satisfied",n.message=v,n.satisfied=!0,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:h,message:v,infoA:a,infoB:l,diagnostics:{distance:h,delta:m.toArray(),moves:[],rotations:[],stage:"satisfied"}}}const y=f(()=>{const v=[],D=[];let E=!1;const P=f((q,B,V)=>{const W=q?.component;if(!W||V<=0||o.isComponentFixed?.(W))return!1;const G=Nn(this,W);if(!G)return!1;const C=q.point.clone().sub(G),_=B.clone().sub(G);if(C.lengthSq()<=1e-12||_.lengthSq()<=1e-12)return!1;const se=C.clone().normalize(),De=_.clone().normalize(),de=R.clamp(se.dot(De),-1,1),U=Math.acos(de);if(!Number.isFinite(U)||U<=1e-6)return!1;const X=Math.min(U,Mn)*d*V;if(!Number.isFinite(X)||X<=1e-6)return!1;const Y=C.clone().cross(_);if(Y.lengthSq()<=1e-12)return!1;Y.normalize();const fe=new me().setFromAxisAngle(Y,X);W.updateMatrixWorld?.(!0);const pe=G.clone();let T=null;if(typeof W.worldToLocal=="function"&&typeof W.localToWorld=="function"&&(T=W.worldToLocal(G.clone())),!o.applyRotation?.(W,fe))return!1;E=!0;const ye={component:W.name||W.uuid,quaternion:fe.toArray(),axis:ce(Y),angleRad:X,angleDeg:R.radToDeg(X),pivot:ce(pe)};if(v.push(ye),T){W.updateMatrixWorld?.(!0);const Ne=W.localToWorld(T.clone()),oe=pe.clone().sub(Ne);oe.lengthSq()>1e-12&&o.applyTranslation?.(W,oe)&&D.push({component:W.name||W.uuid,move:ce(oe)})}return!0},"applyRotationTowards"),w=!p&&a.component,A=!g&&l.component;if(!w&&!A)return{handled:!1};const x=w&&A?.5:w?1:0,z=w&&A?.5:A?1:0;return x>0&&P(a,l.point,x),z>0&&P(l,a.point,z),E?(S(),n.error=h,n.status="adjusted",n.message="Applied rotation to bring points closer.",n.satisfied=!1,n.lastAppliedMoves=D,n.lastAppliedRotations=v,n.pointToPointNextMode="translate",n.exception&&delete n.exception,{handled:!0,applied:!0,result:{ok:!0,status:"adjusted",satisfied:!1,applied:!0,error:h,message:n.message,infoA:a,infoB:l,diagnostics:{distance:h,delta:m.toArray(),rotations:v,moves:D,stage:"rotation"}}}):{handled:!1}},"performRotation"),M=f(()=>{const v=[];let D=!1;const E=f((A,x)=>{if(!A||!x||x.lengthSq()===0)return!1;const z=o.applyTranslation?.(A,x);return z&&v.push({component:A.name||A.uuid,move:ce(x)}),z},"applyMove");if(p&&g){const A="Both components are fixed; unable to translate points into contact.";return n.status="blocked",n.message=A,n.satisfied=!1,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{result:{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:h,message:A,infoA:a,infoB:l,diagnostics:{distance:h,delta:m.toArray(),moves:[],rotations:[],stage:"translation"}},applied:!1}}if(!p&&!g){const A=m.clone().multiplyScalar(.5*u);A.lengthSq()>0&&(D=E(a.component,A.clone().negate())||D,D=E(l.component,A)||D)}else if(p&&!g){const A=m.clone().multiplyScalar(u);A.lengthSq()>0&&(D=E(l.component,A)||D)}else if(!p&&g){const A=m.clone().multiplyScalar(u);A.lengthSq()>0&&(D=E(a.component,A.clone().negate())||D)}D&&(S(),n.error=h);const P=D?"adjusted":"pending",w=D?"Applied translation to align points.":"Waiting for a movable component to translate.";return n.status=P,n.message=w,n.satisfied=!1,n.lastAppliedMoves=v,n.lastAppliedRotations=[],n.pointToPointNextMode="rotate",n.exception&&delete n.exception,{result:{ok:!0,status:P,satisfied:!1,applied:D,error:h,message:w,infoA:a,infoB:l,diagnostics:{distance:h,delta:m.toArray(),moves:v,rotations:[],stage:"translation"}},applied:D}},"performTranslation");let F=null;if(n.pointToPointNextMode==="rotate"){const v=y();if(v?.handled)return v.result}return F=M(),F.result}};$=new WeakSet,_e=f(function(t,e,r){const o=N(this,$,Ft).call(this,t,e,r);return!!this.inputParams.reverse?!o:o},"#effectiveOppose"),Ft=f(function(t,e,r){const o=this.persistentData=this.persistentData||{};if(typeof o.preferredOppose!="boolean"){const n=ee(this,t,e,"elements[0]"),a=ee(this,t,r,"elements[1]"),l=n?.direction?.clone()?.normalize(),c=a?.direction?.clone()?.normalize();if(!l||!c||l.lengthSq()===0||c.lengthSq()===0)throw new Error("TouchAlignConstraint: Unable to resolve directions for orientation preference.");const u=R.clamp(l.dot(c),-1,1);o.preferredOppose=u<0,o.lastOrientationDot=u}return!!o.preferredOppose},"#preferredOppose"),Xe=f(function(t,e,r){if(!t?.debugMode)return;const o=t.scene||null;if(!o)return;const n=t.iteration??0,a=[{info:e,color:16731469,label:"A"},{info:r,color:5111697,label:"B"}],l=this.inputParams?.id??this.inputParams?.constraintID??"unknown";for(const{info:c,color:u,label:d}of a){if(!c?.direction||!c.origin)continue;const p=c.direction.clone().normalize();if(p.lengthSq()===0)continue;const g=c.origin.clone(),m=Math.max(N(this,$,Ot).call(this,c),10),h=new Ke(p,g,m,u,m*.25,m*.15);h.name=`touch-align-normal-${l}-${d}-iter${n}`,o.add(h),this._debugHelpers.push(h)}},"#updateNormalDebug"),He=f(function(t){if(this._debugHelpers){for(const e of this._debugHelpers)e&&(t&&e.parent===t?t.remove(e):e.parent&&e.parent.remove(e));this._debugHelpers.length=0}},"#clearNormalDebug"),Ot=f(function(t){const e=[],r=f(n=>{if(!n)return;if(n.geometry?.computeBoundingSphere&&!n.geometry.boundingSphere)try{n.geometry.computeBoundingSphere()}catch{}const a=n.geometry?.boundingSphere;if(a?.radius&&e.push(Math.abs(a.radius)),n.geometry?.computeBoundingBox&&!n.geometry.boundingBox)try{n.geometry.computeBoundingBox()}catch{}const l=n.geometry?.boundingBox;if(l&&e.push(l.getSize(new b).length()/2),typeof n.getWorldScale=="function"){const c=n.getWorldScale(new b);e.push(c.length()*5)}},"pushBound");if(r(t.object),Array.isArray(t.component?.children))for(const n of t.component.children)r(n);e.push(t.component?.userData?.boundingRadius||0);const o=e.reduce((n,a)=>Number.isFinite(a)?Math.max(n,a):n,0);return Number.isFinite(o)&&o>0?o:0},"#estimateHelperLength"),f(j,"TouchAlignConstraint"),k(j,"shortName","⪥"),k(j,"longName","⪥ Touch Align Constraint"),k(j,"constraintType","touch_align"),k(j,"aliases",["touch","touch_align","touch-align","TALN"]),k(j,"inputParamsSchema",xn);let Ce=j;function Dn(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(Dn,"selectionPair");function ce(i){return i?[i.x,i.y,i.z]:[0,0,0]}f(ce,"vectorToArray");function Se(i,s,t){if(!t)return null;const e=s.resolveObject?.(t)||null,r=s.resolveComponent?.(t)||null,o=wn(i,e,r);return{selection:t,object:e,component:r||null,point:o}}f(Se,"resolvePointSelection");function wn(i,s,t){if(s){try{const r=te(null,s);if(r&&typeof r.clone=="function")return r.clone()}catch{}const e=i.getWorldPoint(s);if(e)return e}if(t){try{const r=te(null,t);if(r&&typeof r.clone=="function")return r.clone()}catch{}t.updateMatrixWorld?.(!0);const e=i.getWorldPoint(t);if(e)return e}return null}f(wn,"resolveSelectionPoint");function Nn(i,s){if(!s)return null;s.updateMatrixWorld?.(!0);try{const e=te(null,s);if(e&&typeof e.clone=="function")return e.clone()}catch{}const t=i.getWorldPoint(s);if(t)return t;if(typeof s.getWorldPosition=="function")return s.getWorldPosition(new b);if(s.position){const e=s.position.clone();return s.parent?.matrixWorld?e.applyMatrix4(s.parent.matrixWorld):e}return null}f(Nn,"resolveComponentMidpoint");function rt(i,s){const t=(s?.kind||i?.userData?.type||i?.userData?.brepType||i?.type||"").toString().toUpperCase();return t?t.includes("FACE")?"FACE":t.includes("EDGE")?"EDGE":t.includes("VERTEX")||t.includes("POINT")?"POINT":t.includes("COMPONENT")?"COMPONENT":t:"UNKNOWN"}f(rt,"selectionKindFrom");function at(i){return i==="COMPONENT"?"FACE":i}f(at,"normalizeSelectionKind");const Ze=f(i=>{if(i==null&&i!==0)return"";try{return String(i).trim()}catch{return""}},"normalizeName"),ue=f(i=>Ze(i).toLowerCase(),"normalizeKey"),En=f(i=>Ze(i?.shortName??i?.constraintShortName??i?.name),"getShortName"),Pn=f(i=>Ze(i?.longName??i?.constraintName??i?.name),"getLongName");var xe,Bt;const Qe=class Qe{constructor(){le(this,xe);this._map=new Map,this._aliases=new Map,this.register(ze),this.register(ke),this.register(Re),this.register(Le),this.register(Ge),this.register(Ce)}register(s){if(!s)return;s.shortName||(s.shortName=s.constraintShortName||s.name||"CONST"),s.longName||(s.longName=s.constraintName||s.name||s.shortName||"Constraint"),typeof s.showContexButton!="function"&&(s.showContexButton=()=>!1);const t=N(this,xe,Bt).call(this,s);if(t.typeKey){this._map.set(t.typeKey,s);for(const e of t.aliases){const r=ue(e);r&&this._aliases.set(r,s)}}}get(s){const t=ue(s);if(!t)throw new Error("Constraint type must be a non-empty string");const e=this._map.get(t)||this._aliases.get(t);if(!e)throw new Error(`Constraint type "${s}" is not registered.`);return e}getSafe(s){try{return this.get(s)}catch{return null}}has(s){return!!this.getSafe(s)}list(){return Array.from(new Set(this._map.values()))}listAvailable(){return this.list()}};xe=new WeakSet,Bt=f(function(s){const t=new Set,e=ue(s.constraintType||s.type||null);e&&t.add(e);const r=ue(En(s));r&&r!==e&&t.add(r);const o=ue(Pn(s));o&&o!==e&&t.add(o);const n=ue(s.name);n&&t.add(n);const a=Array.isArray(s.aliases)?s.aliases.filter(Boolean):[],[l,...c]=t;return{typeKey:l||null,aliases:c.concat(a)}},"#collectKeys"),f(Qe,"AssemblyConstraintRegistry");let lt=Qe;export{lt as A};
1
+ var Je=Object.defineProperty;var je=i=>{throw TypeError(i)};var Rt=(i,s,t)=>s in i?Je(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t;var f=(i,s)=>Je(i,"name",{value:s,configurable:!0});var k=(i,s,t)=>Rt(i,typeof s!="symbol"?s+"":s,t),Wt=(i,s,t)=>s.has(i)||je("Cannot "+t);var le=(i,s,t)=>s.has(i)?je("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(i):s.set(i,t);var N=(i,s,t)=>(Wt(i,s,"access private method"),t);import{V as b,b as R,Q as me,v as Ke}from"./featureDialogs-Bas0NDXF.js";import{o as te,g as he}from"./annUtils-Cv2fgMTB.js";const re=class re{constructor(s=null){this.partHistory=s,this.inputParams={},this.persistentData={}}getWorldPoint(s){if(!s)return null;try{const t=new b;if(typeof s.getWorldPosition=="function")return s.getWorldPosition(t),t;if(s.isVector3)return s.clone();if(s.position)return t.copy(s.position),s.parent&&s.parent.isObject3D&&(s.parent.updateMatrixWorld?.(!0),t.applyMatrix4(s.parent.matrixWorld)),t}catch{return null}return null}async run(s){return console.warn(`[${this.constructor.name}] run() not implemented.`),null}};f(re,"BaseAssemblyConstraint"),k(re,"shortName","ACON"),k(re,"longName","Assembly Constraint"),k(re,"constraintType","assembly_constraint"),k(re,"inputParamsSchema",{id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."}});let ne=re;const Pe=R.degToRad(.001),ct=R.degToRad(10),qt=256,It=1e-12;function $t(i){if(!i)return null;if(i.updateMatrixWorld?.(!0),typeof i.getAverageNormal=="function")try{const s=i.getAverageNormal();if(s&&s.lengthSq()>1e-10)return s.clone().normalize()}catch{}return Ye(i)}f($t,"getWorldNormal");function Lt(i,s){let t=null;if(i)try{t=te(null,i)}catch{}if(!t&&s){try{t=te(null,s)}catch{}!t&&typeof s.getWorldPosition=="function"&&(t=s.getWorldPosition(new b))}return t||null}f(Lt,"resolveOrigin");function Ye(i,s=0){if(!i||s>3)return null;const t=i.geometry;if(t&&t.isBufferGeometry){const e=Gt(i,t);if(e)return e}if(Array.isArray(i.children))for(const e of i.children){const r=Ye(e,s+1);if(r&&r.lengthSq()>0)return r}return null}f(Ye,"computeNormalFromObject");function Gt(i,s){if(!s?.isBufferGeometry)return null;const t=s.getAttribute?.("position");if(!t||t.itemSize!==3||t.count<3)return null;const e=s.getIndex?.(),r=Math.floor(e?e.count/3:t.count/3);if(r<=0)return null;i.updateMatrixWorld?.(!0);const o=new b,n=new b,a=new b,l=new b,c=new b,u=new b,d=new b,p=Math.min(r,60);let g=0;for(let m=0;m<p;m+=1){let h,S,y;if(e){const M=m*3;if(M+2>=e.count)break;h=e.getX(M),S=e.getX(M+1),y=e.getX(M+2)}else if(h=m*3,S=h+1,y=h+2,y>=t.count)break;o.set(t.getX(h),t.getY(h),t.getZ(h)).applyMatrix4(i.matrixWorld),n.set(t.getX(S),t.getY(S),t.getZ(S)).applyMatrix4(i.matrixWorld),a.set(t.getX(y),t.getY(y),t.getZ(y)).applyMatrix4(i.matrixWorld),l.subVectors(n,o),c.subVectors(a,o),u.crossVectors(l,c),u.lengthSq()>1e-10&&(d.add(u),g+=1)}return g===0||(d.divideScalar(g),d.lengthSq()<=1e-10)?null:d.normalize()}f(Gt,"computeNormalFromGeometry");function Ae(i){if(!i)return null;const s=i instanceof b?i.clone():new b(i.x??0,i.y??0,i.z??0);return s.lengthSq()<=1e-12?null:s.normalize()}f(Ae,"normalizeOrNull$2");function Ut(i,s){return!i||typeof i.getX!="function"||s<0||s>=i.count?null:new b(i.getX(s),i.getY(s),i.getZ(s))}f(Ut,"readAttributeVector");function et(i){if(!i)return null;try{const s=he(null,i);if(s&&s.lengthSq()>1e-12)return s.clone?s.clone():new b(s.x,s.y,s.z)}catch{}return null}f(et,"elementDirectionFrom");function Vt(i,s=qt){if(!i)return null;const t=i.userData?.polylineLocal,e=!!i.userData?.closedLoop,r=[];i.updateMatrixWorld?.(!0);const o=i.matrixWorld,n=f((d,p,g)=>{if(!Number.isFinite(d)||!Number.isFinite(p)||!Number.isFinite(g))return;const m=new b(d,p,g);m.applyMatrix4(o),r.push(m)},"pushPoint");if(Array.isArray(t)&&t.length>=2){for(const d of t)if(d){if(Array.isArray(d)&&d.length>=3){n(d[0],d[1],d[2]);continue}typeof d=="object"&&n(d.x??d[0]??0,d.y??d[1]??0,d.z??d[2]??0)}return r.length>=2?{points:r,closedLoop:e}:null}const a=i.geometry;if(!a)return null;const l=f((d,p)=>{if(d<=0)return;const g=d,m=Math.min(Math.max(g,1),Math.max(2,Math.min(g,s))),h=m>1?m-1:1;let S=-1;for(let y=0;y<m;y+=1){const M=h===0?0:y/h,F=Math.min(g-1,Math.round(M*(g-1)));if(F===S)continue;S=F;const v=p(F);v&&n(v.x,v.y,v.z)}if(S!==g-1){const y=p(g-1);y&&n(y.x,y.y,y.z)}},"sampleAttribute"),c=a.getAttribute?.("position");if(c&&c.itemSize===3&&c.count>=1)return l(c.count,d=>Ut(c,d)),r.length>=2?{points:r,closedLoop:e}:null;const u=a.attributes?.position?.array;if(u&&(Array.isArray(u)||ArrayBuffer.isView(u))){const d=Math.floor(u.length/3);return d<=0?null:(l(d,p=>{const g=p*3;return new b(u[g],u[g+1],u[g+2])}),r.length>=2?{points:r,closedLoop:e}:null)}return null}f(Vt,"collectEdgeSamplePoints");function Ct(i){if(!Array.isArray(i)||i.length<2)return null;const s=new b;for(const c of i)s.add(c);s.multiplyScalar(1/i.length);let t=0,e=0,r=0,o=0,n=0,a=0;for(const c of i){const u=c.x-s.x,d=c.y-s.y,p=c.z-s.z;t+=u*u,e+=u*d,r+=u*p,o+=d*d,n+=d*p,a+=p*p}const l=new b(1,0,0);o>t&&o>=a?l.set(0,1,0):a>t&&a>o&&l.set(0,0,1);for(let c=0;c<10;c+=1){const u=t*l.x+e*l.y+r*l.z,d=e*l.x+o*l.y+n*l.z,p=r*l.x+n*l.y+a*l.z,g=Math.hypot(u,d,p);if(g<=1e-9)return null;l.set(u/g,d/g,p/g)}return l.normalize()}f(Ct,"principalAxisFromPoints");function _t(i){if(!i)return null;const s=Vt(i);if(!s)return null;const{points:t,closedLoop:e}=s;if(!t||t.length<2)return null;if(e){const h=new Error("ParallelConstraint: Selected edge is a closed loop and has no unique tangent direction.");throw h.details={objectName:i?.name||null,reason:"edge-closed-loop"},h}const r=t[0].clone(),o=t[t.length-1].clone(),n=[r.clone(),o.clone()],a=t.reduce((h,S)=>h.add(S),new b).multiplyScalar(1/t.length),l=r.distanceToSquared(o)>1e-14?r.clone().add(o).multiplyScalar(.5):a.clone(),c=new b;let u=0;for(let h=1;h<t.length;h+=1){const S=t[h].clone().sub(t[h-1]),y=S.length();y>1e-9&&(c.add(S),u+=y)}const d=o.clone().sub(r),p=d.length();let g=Ct(t),m=g?"edge-principal-axis":null;return!g&&u>1e-9&&(g=c.clone().normalize(),m="edge-segment-average"),!g&&p>1e-9&&(g=d.clone().normalize(),m="edge-chord"),!g||g.lengthSq()<=1e-12?{endpoints:n,midpoint:l,sampleCount:t.length,chord:p>1e-9?d.clone():null,segmentAccum:u>1e-9?c.clone():null,direction:null,directionSource:"edge-direction-unresolved",totalSegmentLength:u,chordLength:p}:(p>1e-9&&g.dot(d)<0&&g.negate(),{endpoints:n,midpoint:l,sampleCount:t.length,chord:p>1e-9?d.clone():null,segmentAccum:u>1e-9?c.clone():null,direction:g?g.clone():null,directionSource:m,totalSegmentLength:u,chordLength:p,closedLoop:!!e})}f(_t,"resolveEdgeData");function Xt(i,s,t,e){const r=t==="EDGE",o=r?null:Ae(et(i)||et(s));if(r){const l=Ae(e?.direction);return l?{direction:l,source:e?.directionSource||"edge-data"}:{direction:null,source:e?.directionSource||"edge-direction-unresolved"}}const n=Ae($t(i));if(n)return{direction:n,source:"surface-normal"};if(o)return{direction:o,source:r?"edge-element-direction":"element-direction"};const a=Ae(Ye(i));return a?{direction:a,source:"geometry-normal"}:{direction:null,source:r?"edge-direction-unresolved":"unresolved"}}f(Xt,"resolveDirection");function Ht(i,s){const t=[];s&&typeof s.kind=="string"&&t.push(s.kind);const e=i?.userData;e?.type&&t.push(e.type),e?.brepType&&t.push(e.brepType),i?.type&&t.push(i.type);for(const r of t){const o=String(r||"").toUpperCase();if(o){if(o.includes("FACE"))return"FACE";if(o.includes("EDGE"))return"EDGE";if(o.includes("VERTEX")||o.includes("POINT"))return"POINT";if(o.includes("COMPONENT"))return"COMPONENT"}}return"UNKNOWN"}f(Ht,"selectionKindFrom$3");function Te(i,s,t,e){const r=s.resolveObject?.(t)||null,o=s.resolveComponent?.(t)||null,n=Ht(r,t),l=n==="EDGE"?_t(r):null;if(s.scene?.updateMatrixWorld)try{s.scene.updateMatrixWorld(!0)}catch{}o?.updateMatrixWorld?.(!0),r?.updateMatrixWorld?.(!0);let c=Lt(r,o);l?.midpoint&&(c=l.midpoint.clone());const u=Xt(r,o,n,l),d=u.direction;if(!d||d.lengthSq()===0){const p={selectionLabel:e,selection:t,objectName:r?.name||null,componentName:o?.name||null,kind:n,edgeData:l?{endpoints:l.endpoints?.map?.(m=>m.toArray())||null,directionSource:l.directionSource||null,sampleCount:l.sampleCount??null,chordLength:l.chordLength??null,totalSegmentLength:l.totalSegmentLength??null,closedLoop:l.closedLoop??null}:null,reason:u.source},g=new Error("ParallelConstraint: Unable to resolve a surface normal for the provided selection.");throw g.details=p,console.error("[ParallelConstraint] Failed to resolve normal for selection.",p,g),g}return{direction:d.clone().normalize(),origin:c,object:r,component:o||null,directionSource:u.source,kind:n,edgeData:l}}f(Te,"selectionDirection");function tt(i){if(!i)return"selection";const s=/^elements\[(\d+)\]$/i.exec(String(i));if(s){const e=Number(s[1]);if(Number.isFinite(e))return`Element ${e+1}`}const t=String(i).trim();return t?t.replace(/_/g," ").replace(/\s+/g," ").replace(/\b([a-z])/gi,(e,r)=>r.toUpperCase()):"selection"}f(tt,"describeSelectionLabel");function Kt(i){if(!i)return null;const s=i instanceof me?i.clone():new me(i.x??0,i.y??0,i.z??0,i.w??1);return!Number.isFinite(s.x)||!Number.isFinite(s.y)||!Number.isFinite(s.z)||!Number.isFinite(s.w)?null:(Math.abs(1-s.lengthSq())>1e-6&&s.normalize(),s)}f(Kt,"normalizeQuaternion");function Yt(i,s,t=1){if(!i||!s)return null;const e=i.clone().normalize(),r=s.clone().normalize(),o=R.clamp(e.dot(r),-1,1);let n=Math.acos(o);if(!Number.isFinite(n)||n<=1e-6)return null;const a=new b().crossVectors(e,r);a.lengthSq()<=1e-12&&(a.set(1,0,0).cross(e),a.lengthSq()<=1e-12&&a.set(0,1,0).cross(e)),a.normalize();const l=Math.max(0,Math.min(1,t)),c=n*l,u=Math.min(c,ct,n);return u<=1e-6?null:new me().setFromAxisAngle(a,u)}f(Yt,"computeRotation");function be(i,s,t,e,r){if(!s)return!1;const o=Yt(t,e,r);if(!o)return!1;const n=Kt(o);return n&&i.applyRotation?.(s,n)?{component:s,quaternion:n}:!1}f(be,"attemptRotation");function ve({constraint:i,context:s={},selectionA:t,selectionB:e,opposeNormals:r=!1,selectionLabelA:o="elements[0]",selectionLabelB:n="elements[1]"}){if(!i)throw new Error("solveParallelAlignment requires a constraint instance.");const a=tt(o),l=tt(n);let c,u;try{c=Te(i,s,t,o)}catch(q){return{ok:!1,status:"normal-resolution-failed",satisfied:!1,applied:!1,message:`Failed to resolve a normal for ${a}.`,exception:q,infoA:null,infoB:null}}try{u=Te(i,s,e,n)}catch(q){return{ok:!1,status:"normal-resolution-failed",satisfied:!1,applied:!1,message:`Failed to resolve a normal for ${l}.`,exception:q,infoA:c,infoB:null}}if(!c.component||!u.component)return{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:"Both selections must belong to assembly components.",infoA:c,infoB:u};if(c.component===u.component)return{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:"Select references from two different components.",infoA:c,infoB:u};const d=c.direction,p=u.direction;if(!d||!p)return{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:"Unable to resolve directions for one or both selections.",infoA:c,infoB:u};const g=r?d.clone().negate():d.clone(),m=r?p.clone().negate():p.clone(),h=R.clamp(p.dot(g),-1,1),S=Math.acos(h),y=R.radToDeg(S),M=Math.abs(s.tolerance??It),F=Math.max(Pe,M*10),v=s.isComponentFixed?.(c.component),D=s.isComponentFixed?.(u.component),E=s.rotationGain??1;if(S<=F)return{ok:!0,status:"satisfied",satisfied:!0,applied:!1,angle:S,angleDeg:y,error:S,infoA:c,infoB:u,message:"Reference directions are parallel within tolerance."};if(v&&D)return{ok:!1,status:"blocked",satisfied:!1,applied:!1,angle:S,angleDeg:y,error:S,infoA:c,infoB:u,message:"Both components are fixed; unable to rotate to satisfy constraint."};const P=[];let w=!1;const A=f(q=>{if(!q)return!1;const{component:B,quaternion:V}=q;return P.push({component:B.name||B.uuid,quaternion:V.toArray()}),B.updateMatrixWorld?.(!0),!0},"pushRotation");return!v&&!D?(w=A(be(s,c.component,d,m,E*.5))||w,w=A(be(s,u.component,p,g,E*.5))||w):v&&!D?w=A(be(s,u.component,p,g,E))||w:!v&&D&&(w=A(be(s,c.component,d,m,E))||w),{ok:!0,status:w?"adjusted":"pending",satisfied:!1,applied:w,angle:S,angleDeg:y,error:S,infoA:c,infoB:u,message:w?"Applied rotation to improve parallelism.":"Waiting for a movable component to rotate.",rotations:P,diagnostics:{angle:S,angleDeg:y,rotations:P}}}f(ve,"solveParallelAlignment");function ee(i,s,t,e){return Te(i,s,t,e)}f(ee,"resolveParallelSelection");const Zt=1e-12,Qt={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two faces or edges.",selectionFilter:["FACE","EDGE"],multiple:!0,minSelections:2,maxSelections:2},angle:{type:"number",label:"Angle (deg)",default_value:90,hint:"Desired signed angle between Element A and Element B in degrees. Exterior uses supplementary angle (180 - interior)."},exteriorAngle:{type:"boolean",label:"Exterior Angle",default_value:!1,hint:"Measure and solve using the exterior (supplementary) angle."}};var I,ut,Fe,dt,ft,pt,Oe;const H=class H extends ne{constructor(t){super(t);le(this,I)}async solve(t={}){const e=this.persistentData=this.persistentData||{},[r,o]=Jt(this.inputParams),n=N(this,I,ut).call(this),a=en(this.inputParams.angle,n);let l=a.modeDeg,c=a.signPreference,u=R.degToRad(l);if(!r||!o)return e.status="incomplete",e.message="Select two references to define the constraint.",e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:e.message};let d,p;try{d=N(this,I,Fe).call(this,t,r,"elements[0]"),p=N(this,I,Fe).call(this,t,o,"elements[1]")}catch(T){const ae=T?.message||"Unable to resolve selection references.";return e.status="invalid-selection",e.message=ae,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],e.exception=T,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:ae,exception:T}}if(!d||!p||!d.direction||!p.direction){const T="Unable to resolve directions for the selected references.";return e.status="invalid-selection",e.message=T,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:T}}if(!d.component||!p.component){const T="Both selections must belong to assembly components.";return e.status="invalid-selection",e.message=T,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:T}}if(d.component===p.component){const T="Select references from two different components.";return e.status="invalid-selection",e.message=T,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:T}}const g=N(this,I,pt).call(this,d,p);if(!g){const T="Unable to measure angle between selections.";return e.status="invalid-selection",e.message=T,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedRotations=[],e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:T}}const m=g.angle,h=g.angleDeg,S=g.signedAngle,y=g.signedAngleDeg,M=y<-1e-9?-1:y>1e-9?1:0,F=Math.max(0,Math.PI-m),v=Math.max(0,180-h),D=n?F:m,E=n?v:h;let P=!1;e.isNewConstraint===!0&&(l=E,c=M||c,u=R.degToRad(l),P=!0,e.initializedAngle=l,e.isNewConstraint=!1);const w=tn(S,u,c),A=Me(S-w),x=t.isComponentFixed?.(d.component),z=t.isComponentFixed?.(p.component),q=Math.abs(t.tolerance??Zt),B=Number.isFinite(t.angleTolerance)?Math.abs(t.angleTolerance):null,V=B&&B>0?Math.max(Pe,B):Math.max(Pe,q*10);if(e.error=Math.abs(A),e.errorDeg=Math.abs(R.radToDeg(A)),Math.abs(A)<=V){const T=P?`Initialized ${n?"exterior":"interior"} angle from current orientation.`:"Angle satisfied within tolerance.";return e.status="satisfied",e.message=T,e.satisfied=!0,e.lastAppliedRotations=[],e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!0,status:"satisfied",satisfied:!0,applied:!1,angle:m,angleDeg:h,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,error:A,message:T,infoA:d,infoB:p,diagnostics:{angle:m,angleDeg:h,exteriorAngle:F,exteriorAngleDeg:v,measuredModeAngle:D,measuredModeAngleDeg:E,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,targetAngleDeg:l,useExteriorAngle:n,error:A,initializedFromMeasuredAngle:P},persistInputParams:P?{angle:l}:null}}if(x&&z){const T="Both components are fixed; unable to adjust angle.";return e.status="blocked",e.message=T,e.satisfied=!1,e.lastAppliedRotations=[],e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!1,status:"blocked",satisfied:!1,applied:!1,angle:m,angleDeg:h,targetAngle:u,targetSignedAngle:w,error:A,message:T,infoA:d,infoB:p,diagnostics:{angle:m,angleDeg:h,exteriorAngle:F,exteriorAngleDeg:v,measuredModeAngle:D,measuredModeAngleDeg:E,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,targetAngleDeg:l,useExteriorAngle:n,error:A,initializedFromMeasuredAngle:P}}}const W=S-w,G=0,C=S;let _,se;if(!x&&!z){const T=W/2;_=G+T,se=C-T}else!x&&z?(se=C,_=se-w):(_=G,se=_+w);const De=Math.max(0,Math.min(1,t.rotationGain??1)),de=[];let U=!1;const we=f((T,ae,ye,Ne)=>{if(!T?.component||!ae||!ye)return!1;const oe=sn(ae,ye,De*Ne);return!oe||!t.applyRotation?.(T.component,oe)?!1:(de.push({component:T.component.name||T.component.uuid,quaternion:oe.toArray()}),T.component.updateMatrixWorld?.(!0),!0)},"applyRotation"),X=!x&&!z?.5:x?0:1,Y=!x&&!z?.5:z?0:1;if(X>0){const T=N(this,I,Oe).call(this,g,_);U=we(d,g.dirA,T,X)||U}if(Y>0){const T=N(this,I,Oe).call(this,g,se);U=we(p,g.dirB,T,Y)||U}const fe=U?"adjusted":"pending",pe=U?"Applied rotation to move toward target angle.":"Waiting for a movable component to rotate.";return e.status=fe,e.message=pe,e.satisfied=!1,e.lastAppliedRotations=de,e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!0,status:fe,satisfied:!1,applied:U,angle:m,angleDeg:h,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,error:A,message:pe,infoA:d,infoB:p,rotations:de,diagnostics:{angle:m,angleDeg:h,exteriorAngle:F,exteriorAngleDeg:v,measuredModeAngle:D,measuredModeAngleDeg:E,signedAngle:S,signedAngleDeg:y,targetAngle:u,targetSignedAngle:w,targetAngleDeg:l,useExteriorAngle:n,error:A,shareA:X,shareB:Y,desiredSignedAngle:w,initializedFromMeasuredAngle:P}}}async run(t={}){return this.solve(t)}};I=new WeakSet,ut=f(function(){return this.inputParams?.exteriorAngle===!0},"#useExteriorAngle"),Fe=f(function(t,e,r){const o=t.resolveObject?.(e)||null,n=t.resolveComponent?.(e)||null,a=jt(o,e);if(a==="FACE")return ee(this,t,e,r);if(a!=="EDGE")throw new Error(`AngleConstraint: Unsupported selection for ${r}.`);const l=N(this,I,dt).call(this,o,n)||new b,c=N(this,I,ft).call(this,o,n);if(!c)throw new Error("AngleConstraint: Unable to resolve edge direction.");return{selection:e,object:o,component:n||null,origin:l,direction:c,kind:a}},"#resolveSelectionInfo"),dt=f(function(t,e){if(t){try{const r=te(null,t);if(r&&typeof r.clone=="function")return r.clone()}catch{}if(typeof t.getWorldPosition=="function")return t.getWorldPosition(new b);if(t.isVector3)return t.clone()}if(e){if(e.updateMatrixWorld?.(!0),typeof e.getWorldPosition=="function")return e.getWorldPosition(new b);if(e.position){const r=e.position.clone();return e.parent?.updateMatrixWorld?.(!0),e.parent?.matrixWorld?r.applyMatrix4(e.parent.matrixWorld.clone()):r}}return null},"#resolveOrigin"),ft=f(function(t,e){const r=he(null,t);if(r&&r.lengthSq()>0)return r.clone().normalize();if(e){const n=he(null,e);if(n&&n.lengthSq()>0)return n.clone().normalize()}const o=t?.geometry;if(o?.getAttribute){const n=o.getAttribute("position");if(n&&n.count>=2){const a=new b(n.getX(0),n.getY(0),n.getZ(0)),l=new b(n.getX(1),n.getY(1),n.getZ(1));return t.updateMatrixWorld?.(!0),a.applyMatrix4(t.matrixWorld),l.applyMatrix4(t.matrixWorld),l.sub(a).normalize()}}return null},"#resolveEdgeDirection"),pt=f(function(t,e){const r=nt(t?.direction),o=nt(e?.direction);if(!r||!o)return null;let n=new b().crossVectors(r,o);if(n.lengthSq()<=1e-12&&(n=Be(r)),n.lengthSq()<=1e-12)return null;n.normalize();let a=new b().crossVectors(n,r);if(a.lengthSq()<=1e-12&&(a=Be(r)),a.lengthSq()<=1e-12)return null;a.normalize();const l=R.clamp(r.dot(o),-1,1),c=R.clamp(a.dot(o),-1,1),u=Math.atan2(c,l),d=Math.acos(l);return{angle:d,angleDeg:R.radToDeg(d),signedAngle:u,signedAngleDeg:R.radToDeg(u),axis:n,basisU:a,dirA:r,dirB:o}},"#measureAngle"),Oe=f(function(t,e){if(!t)return null;const{dirA:r,basisU:o}=t;if(!r||!o)return null;const n=Math.cos(e),a=Math.sin(e),l=r.clone().multiplyScalar(n).add(o.clone().multiplyScalar(a));return l.lengthSq()===0?null:l.normalize()},"#directionFromAngle"),f(H,"AngleConstraint"),k(H,"shortName","∠"),k(H,"longName","∠ Angle Constraint"),k(H,"constraintType","angle"),k(H,"focusField","angle"),k(H,"aliases",["angle","angle_between","angular","ANGL"]),k(H,"inputParamsSchema",Qt);let ke=H;function Jt(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(Jt,"selectionPair$4");function jt(i,s){const t=s&&typeof s.kind=="string"?s.kind:null,e=(i?.userData?.type||i?.userData?.brepType||i?.type||t||"").toString().toUpperCase();return e?e.includes("FACE")?"FACE":e.includes("EDGE")?"EDGE":e.includes("VERTEX")||e.includes("POINT")?"POINT":e.includes("COMPONENT")?"COMPONENT":e:"UNKNOWN"}f(jt,"selectionKindFrom$2");function nt(i){return!i||i.lengthSq()===0?null:i.clone().normalize()}f(nt,"normalizeOrNull$1");function Be(i){if(!i||i.lengthSq()===0)return new b(0,0,1);const s=Math.abs(i.dot(new b(0,0,1)))<.9?new b(0,0,1):new b(0,1,0),t=new b().crossVectors(i,s);return t.lengthSq()===0&&t.crossVectors(i,new b(1,0,0)),t.lengthSq()===0?new b(1,0,0):t.normalize()}f(Be,"arbitraryPerpendicular$1");function en(i,s=!1){const t=Number(i),e=Number.isFinite(t)?R.clamp(t,-360,360):0,r=e<-1e-9?-1:e>1e-9?1:0,o=nn(Math.abs(e)),n=o>180?360-o:o,a=n>=180-1e-9?0:180-n;return{modeDeg:s?a:n,signPreference:r}}f(en,"resolveTargetAngleMode");function tn(i,s,t=0){const e=gt(s),r=Me(e),o=Math.abs(r);if(o<=1e-9||Math.abs(o-Math.PI)<=1e-9)return r;const n=[r,-r];if(t>0)return n.find(u=>u>0)??n[0];if(t<0)return n.find(u=>u<0)??n[0];const a=Number.isFinite(i)?Me(i):0;let l=n[0],c=st(a,l);for(let u=1;u<n.length;u+=1){const d=st(a,n[u]);d<c&&(c=d,l=n[u])}return l}f(tn,"chooseSignedTargetAngle");function nn(i){if(!Number.isFinite(i))return 0;const s=(i%360+360)%360;return s<=1e-9||Math.abs(s-360)<=1e-9?0:s}f(nn,"normalizePositiveAngleDeg");function gt(i){if(!Number.isFinite(i))return 0;const s=Math.PI*2,t=(i%s+s)%s;return t<=1e-9||Math.abs(t-s)<=1e-9?0:t}f(gt,"normalizePositiveAngleRad");function Me(i){const s=gt(i);return s>Math.PI?s-Math.PI*2:s}f(Me,"normalizeSignedAngleRad");function st(i,s){return Math.abs(Me(i-s))}f(st,"angularDistanceSignedRad");function sn(i,s,t=1){if(!i||!s)return null;const e=i.clone().normalize(),r=s.clone().normalize(),o=R.clamp(e.dot(r),-1,1);let n=Math.acos(o);if(!Number.isFinite(n)||n<=1e-6)return null;let a=new b().crossVectors(e,r);if(a.lengthSq()<=1e-12&&(a=Be(e)),a.lengthSq()<=1e-12)return null;a.normalize();const l=Math.max(0,Math.min(1,t)),c=n*l,u=Math.min(c,ct,n);return u<=1e-6?null:new me().setFromAxisAngle(a,u)}f(sn,"computeRotationTowards");const on=1e-6,rn={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two references (vertex, edge, face, or component).",selectionFilter:["VERTEX","EDGE","FACE","COMPONENT"],multiple:!0,minSelections:2,maxSelections:2},applyImmediately:{type:"boolean",label:"Apply Immediately",default_value:!1,hint:"Maintained for compatibility; runtime solver applies adjustments iteratively."},faceNormalOpposed:{type:"boolean",label:"Oppose Face Normals",default_value:!1,hint:"Preserved for future expansion."}},Z=class Z extends ne{async solve(s={}){const t=this.persistentData=this.persistentData||{},e=Math.max(Math.abs(s.tolerance??on),1e-8),[r,o]=an(this.inputParams);if(!r||!o)return t.status="incomplete",t.message="Select two references to define the constraint.",t.satisfied=!1,{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:t.message};const n=ot(this,s,r),a=ot(this,s,o);if(!n.component||!a.component)return t.status="invalid-selection",t.message="Both selections must belong to assembly components.",t.satisfied=!1,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:t.message};if(n.component===a.component)return t.status="invalid-selection",t.message="Select references from two different components.",t.satisfied=!1,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:t.message};if(!n.point||!a.point)return t.status="invalid-selection",t.message="Unable to resolve world-space positions for one or both selections.",t.satisfied=!1,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:t.message};const l=new b().subVectors(n.point,a.point),c=l.length(),u=s.isComponentFixed?.(n.component),d=s.isComponentFixed?.(a.component),p=s.translationGain??1;if(c<=e)return t.status="satisfied",t.message="Selections are coincident within tolerance.",t.error=c,t.satisfied=!0,t.lastAppliedMoves=[],{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:c,message:t.message};if(u&&d)return t.status="blocked",t.message="Both components are fixed; unable to adjust positions.",t.error=c,t.satisfied=!1,t.lastAppliedMoves=[],{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:c,message:t.message};const g=[];let m=!1;const h=f((M,F)=>{if(!M||!F||F.lengthSq()===0)return!1;const v=s.applyTranslation?.(M,F);return v&&g.push({component:M.name||M.uuid,move:cn(F)}),v},"applyMove");if(!u&&!d){const M=l.clone().multiplyScalar(.5*p);M.lengthSq()>0&&(m=h(n.component,M.clone().multiplyScalar(-1))||m,m=h(a.component,M)||m)}else if(u&&!d){const M=l.clone().multiplyScalar(p);M.lengthSq()>0&&(m=h(a.component,M)||m)}else if(!u&&d){const M=l.clone().multiplyScalar(p);M.lengthSq()>0&&(m=h(n.component,M.clone().multiplyScalar(-1))||m)}const S=m?"adjusted":"pending",y=m?"Applied translation to reduce separation.":"Waiting for a movable component to adjust.";return t.status=S,t.message=y,t.error=c,t.satisfied=!1,g.length&&(t.lastAppliedMoves=g),{ok:!0,status:S,satisfied:!1,applied:m,error:c,message:y,diagnostics:{distance:c,moves:g}}}async run(s={}){return this.solve(s)}};f(Z,"CoincidentConstraint"),k(Z,"shortName","COIN"),k(Z,"longName","Coincident Constraint"),k(Z,"constraintType","coincident"),k(Z,"aliases",["mate","coincident","coincident constraint"]),k(Z,"inputParamsSchema",rn);let ze=Z;function an(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(an,"selectionPair$3");function ln(i,s,t){if(s){try{const r=te(null,s);if(r&&typeof r.clone=="function")return r.clone()}catch{}const e=i.getWorldPoint(s);if(e)return e}if(t){t.updateMatrixWorld?.(!0);const e=i.getWorldPoint(t);if(e)return e}return null}f(ln,"resolvePoint");function ot(i,s,t){const e=s.resolveObject?.(t)||null,r=s.resolveComponent?.(t)||null,o=ln(i,e,r);return{object:e,component:r,point:o}}f(ot,"selectionInfo");function cn(i){return i?[i.x,i.y,i.z]:[0,0,0]}f(cn,"vectorToArray$2");const un=1e-6,dn={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two references (point, edge, face, or component).",selectionFilter:["FACE","VERTEX","EDGE"],multiple:!0,minSelections:2,maxSelections:2},distance:{type:"number",label:"Distance",default_value:0,hint:"Desired separation between references."},opposeNormals:{type:"boolean",label:"Oppose Normals",default_value:!1,hint:"For face-to-face mode, flip Element B normal before alignment."}};var O,mt,ht,yt,We,At,bt,St,vt,qe,Mt,xt,Ie,Dt,wt,Nt;const K=class K extends ne{constructor(t){super(t);le(this,O);this._debugHelpers=[]}async solve(t={}){const e=this.persistentData=this.persistentData||{},[r,o]=fn(this.inputParams),n=Number(this.inputParams.distance??0),a=Number.isFinite(n)?Math.max(0,n):0;if((t.iteration??0)===0&&N(this,O,wt).call(this,t.scene||null),!r||!o)return e.status="incomplete",e.message="Select two references to define the constraint.",e.satisfied=!1,e.error=null,e.lastAppliedMoves=[],e.lastAppliedRotations=[],{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:e.message};const l=Math.max(Math.abs(t.tolerance??un),1e-8),c=Math.max(0,Math.min(1,t.translationGain??1)),u=N(this,O,yt).call(this,t,r,o);let d,p,g=null;if(u){const B=N(this,O,mt).call(this,t,r,o);if(g=ve({constraint:this,context:t,selectionA:r,selectionB:o,opposeNormals:B,selectionLabelA:"elements[0]",selectionLabelB:"elements[1]"}),d=g.infoA||null,p=g.infoB||null,e.lastAppliedRotations=Array.isArray(g.rotations)?g.rotations:[],t.debugMode&&d&&p&&N(this,O,Dt).call(this,t,d,p),!g.ok)return e.status=g.status,e.message=g.message||"",e.satisfied=!1,e.error=g.error??null,e.errorDeg=g.angleDeg??null,e.exception=g.exception||null,e.lastAppliedMoves=[],{...g,stage:"orientation"};if(!g.satisfied)return e.status=g.status,e.message=g.message||"Aligning surfaces…",e.satisfied=!1,e.error=g.angle??null,e.errorDeg=g.angleDeg??null,e.lastAppliedMoves=[],e.exception&&delete e.exception,{...g,stage:"orientation"}}else d=N(this,O,We).call(this,t,r,"elements[0]"),p=N(this,O,We).call(this,t,o,"elements[1]");if(!d||!p||!d.origin||!p.origin){const B="Unable to resolve world-space references for the selection.";return e.status="invalid-selection",e.message=B,e.satisfied=!1,e.error=null,e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:B}}const m=N(this,O,St).call(this,d,p,a,l);if(!m||!Number.isFinite(m.distance)){const B="Unable to measure distance between selections.";return e.status="invalid-selection",e.message=B,e.satisfied=!1,e.error=null,e.lastAppliedMoves=[],{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:B}}const h=m.distance;let S=a,y=!1;u&&e.isNewConstraint===!0&&(S=Math.max(0,h),y=!0,e.initializedDistance=S,e.isNewConstraint=!1);const M=h-S,F=t.isComponentFixed?.(d.component),v=t.isComponentFixed?.(p.component);if(e.error=Math.abs(M),e.errorDeg=null,Math.abs(M)<=l){const B=y?"Initialized distance from current face separation.":"Distance satisfied within tolerance.";return e.status="satisfied",e.message=B,e.satisfied=!0,e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:Math.abs(M),message:B,infoA:d,infoB:p,diagnostics:{distance:h,targetDistance:S,error:M,stage:u?"offset":"general",initializedFromFaceDistance:y},persistInputParams:y?{distance:S}:null}}if(F&&v){const B="Both components are fixed; unable to adjust distance.";return e.status="blocked",e.message=B,e.satisfied=!1,e.lastAppliedMoves=[],e.exception&&delete e.exception,{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:Math.abs(M),message:B,infoA:d,infoB:p,diagnostics:{distance:h,targetDistance:S,error:M,stage:u?"offset":"general",initializedFromFaceDistance:y}}}const D=m.directions,E=[];let P=!1;const w=f((B,V,W)=>{if(!B?.component||!V||V.lengthSq()===0||W===0)return!1;const G=V.clone().normalize().multiplyScalar(W*c*(S-h));if(G.lengthSq()===0)return!1;const C=t.applyTranslation?.(B.component,G);return C&&E.push({component:B.component.name||B.component.uuid,move:pn(G)}),C},"applyCorrection"),A=!F&&d.component,x=!v&&p.component;A&&x?(P=w(d,D.increaseA,.5)||P,P=w(p,D.increaseB,.5)||P):A&&!x?P=w(d,D.increaseA,1)||P:!A&&x&&(P=w(p,D.increaseB,1)||P);const z=P?"adjusted":"pending",q=P?"Applied translation to move toward target distance.":"Waiting for a movable component to translate.";return e.status=z,e.message=q,e.satisfied=!1,e.lastAppliedMoves=E,e.exception&&delete e.exception,{ok:!0,status:z,satisfied:!1,applied:P,error:Math.abs(M),message:q,infoA:d,infoB:p,diagnostics:{distance:h,targetDistance:S,error:M,moves:E,stage:u?"offset":"general",initializedFromFaceDistance:y}}}async run(t={}){return this.solve(t)}};O=new WeakSet,mt=f(function(t,e,r){const o=N(this,O,ht).call(this,t,e,r);return!!this.inputParams.opposeNormals?!o:o},"#effectiveOppose"),ht=f(function(t,e,r){const o=this.persistentData=this.persistentData||{},n=gn(t,e,r),a=!!n;if(typeof o.preferredOppose!="boolean"||a&&o.preferredOpposeSignature!==n)try{const c=ee(this,t,e,"elements[0]"),u=ee(this,t,r,"elements[1]"),d=c?.direction?.clone()?.normalize(),p=u?.direction?.clone()?.normalize();if(!d||!p||d.lengthSq()===0||p.lengthSq()===0)throw new Error("DistanceConstraint: Unable to resolve directions for orientation preference.");const g=R.clamp(d.dot(p),-1,1);o.preferredOppose=g<0,o.lastOrientationDot=g,a?o.preferredOpposeSignature=n:o.preferredOpposeSignature&&delete o.preferredOpposeSignature}catch(c){typeof o.preferredOppose!="boolean"&&(o.preferredOppose=!1),t?.debugMode&&console.warn("[DistanceConstraint] Failed to capture orientation preference.",{id:this.inputParams?.id??this.inputParams?.constraintID??null,error:c})}return!!o.preferredOppose},"#preferredOppose"),yt=f(function(t,e,r){const o=t.resolveObject?.(e)||null,n=t.resolveObject?.(r)||null,a=ie(o,e),l=ie(n,r);return a==="FACE"&&l==="FACE"},"#isFaceFace"),We=f(function(t,e,r){const o=t.resolveObject?.(e)||null,n=t.resolveComponent?.(e)||null,a=ie(o,e);if(a==="FACE")return ee(this,t,e,r);const l=N(this,O,At).call(this,o,n)||new b;let c=null;return a==="EDGE"&&(c=N(this,O,bt).call(this,o,n)),{selection:e,object:o,component:n||null,origin:l,direction:c,kind:a}},"#resolveSelectionInfo"),At=f(function(t,e){if(t){try{const r=te(null,t);if(r&&typeof r.clone=="function")return r.clone()}catch{}if(typeof t.getWorldPosition=="function")return t.getWorldPosition(new b);if(t.isVector3)return t.clone()}if(e){if(e.updateMatrixWorld?.(!0),typeof e.getWorldPosition=="function")return e.getWorldPosition(new b);if(e.position){const r=e.position.clone();return e.parent?.updateMatrixWorld?.(!0),e.parent?.matrixWorld?r.applyMatrix4(e.parent.matrixWorld.clone()):r}}return null},"#resolveOrigin"),bt=f(function(t,e){const r=he(null,t);if(r&&r.lengthSq()>0)return r.clone().normalize();if(e){const n=he(null,e);if(n&&n.lengthSq()>0)return n.clone().normalize()}const o=t?.geometry;if(o?.getAttribute){const n=o.getAttribute("position");if(n&&n.count>=2){const a=new b(n.getX(0),n.getY(0),n.getZ(0)),l=new b(n.getX(1),n.getY(1),n.getZ(1));return t.updateMatrixWorld?.(!0),a.applyMatrix4(t.matrixWorld),l.applyMatrix4(t.matrixWorld),l.sub(a).normalize()}}return null},"#resolveEdgeDirection"),St=f(function(t,e,r,o){const n=(t.kind||ie(t.object,t.selection)).toUpperCase?.()||ie(t.object,t.selection),a=(e.kind||ie(e.object,e.selection)).toUpperCase?.()||ie(e.object,e.selection);if(n==="FACE"&&a==="FACE")return N(this,O,xt).call(this,t,e);if(n==="FACE"&&a!=="FACE")return N(this,O,Ie).call(this,t,e);if(a==="FACE"&&n!=="FACE"){const l=N(this,O,Ie).call(this,e,t);return l?{distance:l.distance,directions:{increaseA:l.directions.increaseB,increaseB:l.directions.increaseA}}:null}return n==="EDGE"&&a==="POINT"?N(this,O,qe).call(this,e,t,!0):n==="POINT"&&a==="EDGE"?N(this,O,qe).call(this,t,e,!1):n==="EDGE"&&a==="EDGE"?N(this,O,Mt).call(this,t,e):N(this,O,vt).call(this,t,e)},"#measureDistance"),vt=f(function(t,e){const r=new b().subVectors(e.origin,t.origin),o=r.length(),n=o>1e-9?r.clone().divideScalar(o):new b(1,0,0);return{distance:o,directions:{increaseA:n.clone().negate(),increaseB:n}}},"#pointPointDistance"),qe=f(function(t,e,r){const o=ge(e.direction)||new b(1,0,0),n=e.origin.clone(),a=t.origin.clone(),c=a.clone().sub(n).dot(o),u=n.clone().add(o.clone().multiplyScalar(c)),d=a.clone().sub(u);let p=d.length(),g=p>1e-9?d.clone().divideScalar(p):it(o);return p=Math.abs(p),r?{distance:p,directions:{increaseA:g.clone().negate(),increaseB:g.clone()}}:{distance:p,directions:{increaseA:g.clone(),increaseB:g.clone().negate()}}},"#pointEdgeDistance"),Mt=f(function(t,e){const r=ge(t.direction),o=ge(e.direction);if(!r||!o)return null;const n=t.origin.clone(),a=e.origin.clone(),l=r.clone(),c=o.clone(),u=n.clone().sub(a),d=l.dot(l),p=l.dot(c),g=c.dot(c),m=l.dot(u),h=c.dot(u),S=d*g-p*p;let y,M;Math.abs(S)<1e-8?(y=0,M=p>g?m/p:h/g):(y=(p*h-g*m)/S,M=(d*h-p*m)/S);const F=n.clone().add(l.clone().multiplyScalar(y)),D=a.clone().add(c.clone().multiplyScalar(M)).clone().sub(F),E=D.length(),P=E>1e-9?D.clone().divideScalar(E):it(l);return{distance:E,directions:{increaseA:P.clone().negate(),increaseB:P}}},"#edgeEdgeDistance"),xt=f(function(t,e){const r=ge(t.direction),o=t.origin.clone(),n=e.origin.clone();if(!r)return null;let l=n.clone().sub(o).dot(r);Number.isFinite(l)||(l=0);const c=l>=0?r.clone():r.clone().negate();return{distance:Math.abs(l),directions:{increaseA:c.clone().negate(),increaseB:c}}},"#faceFaceDistance"),Ie=f(function(t,e){const r=ge(t.direction);if(!r)return null;const o=t.origin.clone(),l=e.origin.clone().clone().sub(o).dot(r),c=Math.abs(l),u=l>=0?r.clone():r.clone().negate();return{distance:c,directions:{increaseA:u.clone().negate(),increaseB:u}}},"#facePointLikeDistance"),Dt=f(function(t,e,r){if(!t?.debugMode)return;const o=t.scene||null;if(!o)return;const n=t.iteration??0,a=[{info:e,color:16754253,label:"A"},{info:r,color:5096447,label:"B"}];for(const{info:l,color:c,label:u}of a){if(!l?.direction||!l.origin)continue;const d=l.direction.clone().normalize();if(d.lengthSq()===0)continue;const p=l.origin.clone(),g=Math.max(N(this,O,Nt).call(this,l),10),m=new Ke(d,p,g,c,g*.25,g*.15),h=this.inputParams?.id??this.inputParams?.constraintID??"unknown";m.name=`distance-constraint-normal-${h}-${u}-iter${n}`,o.add(m),this._debugHelpers.push(m)}},"#updateNormalDebug"),wt=f(function(t){if(this._debugHelpers){for(const e of this._debugHelpers)e&&(t&&e.parent===t?t.remove(e):e.parent&&e.parent.remove(e));this._debugHelpers.length=0}},"#clearDebug"),Nt=f(function(t){const e=[],r=f(n=>{if(!n)return;if(n.geometry?.computeBoundingSphere&&!n.geometry.boundingSphere)try{n.geometry.computeBoundingSphere()}catch{}const a=n.geometry?.boundingSphere;if(a?.radius&&e.push(Math.abs(a.radius)),n.geometry?.computeBoundingBox&&!n.geometry.boundingBox)try{n.geometry.computeBoundingBox()}catch{}const l=n.geometry?.boundingBox;if(l&&e.push(l.getSize(new b).length()/2),typeof n.getWorldScale=="function"){const c=n.getWorldScale(new b);e.push(c.length()*5)}},"pushBound");if(r(t.object),Array.isArray(t.component?.children))for(const n of t.component.children)r(n);e.push(t.component?.userData?.boundingRadius||0);const o=e.reduce((n,a)=>Number.isFinite(a)?Math.max(n,a):n,0);return Number.isFinite(o)&&o>0?o:0},"#estimateHelperLength"),f(K,"DistanceConstraint"),k(K,"shortName","⟺"),k(K,"longName","⟺ Distance Constraint"),k(K,"constraintType","distance"),k(K,"focusField","distance"),k(K,"aliases",["distance","offset","gap","DIST"]),k(K,"inputParamsSchema",dn);let Re=K;function fn(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(fn,"selectionPair$2");function pn(i){return i?[i.x,i.y,i.z]:[0,0,0]}f(pn,"vectorToArray$1");function ge(i){return!i||i.lengthSq()===0?null:i.normalize()}f(ge,"normalizeOrNull");function it(i){if(!i||i.lengthSq()===0)return new b(0,0,1);const s=Math.abs(i.dot(new b(0,0,1)))<.9?new b(0,0,1):new b(0,1,0),t=new b().crossVectors(i,s);return t.lengthSq()===0&&t.crossVectors(i,new b(1,0,0)),t.lengthSq()===0?new b(1,0,0):t.normalize()}f(it,"arbitraryPerpendicular");function ie(i,s){const t=s&&typeof s.kind=="string"?s.kind:null,e=(i?.userData?.type||i?.userData?.brepType||i?.type||t||"").toString().toUpperCase();return e?e.includes("FACE")?"FACE":e.includes("EDGE")?"EDGE":e.includes("VERTEX")||e.includes("POINT")?"POINT":e.includes("COMPONENT")?"COMPONENT":e:"UNKNOWN"}f(ie,"selectionKindFrom$1");function gn(i,s,t){const e=$e(i,s),r=$e(i,t);return!e||!r?null:[e,r].sort().join("|")}f(gn,"constraintSelectionPairSignature$1");function $e(i,s,t=0,e=new Set){if(s==null||t>5)return null;const r=typeof s;if(r==="string"||r==="number"||r==="boolean")return`${r}:${String(s)}`;if(Array.isArray(s)){const o=[],n=Math.min(s.length,4);for(let a=0;a<n;a+=1){const l=$e(i,s[a],t+1,e);l&&o.push(l)}return o.length?`arr:[${o.join(",")}]`:null}if(r!=="object"||e.has(s))return null;e.add(s);try{const o=["kind","type","name","selectionName","objectName","path","uuid","id","featureID"],n=[];for(const l of o){const c=s[l];if(c==null)continue;const u=typeof c;(u==="string"||u==="number"||u==="boolean")&&n.push(`${l}:${String(c)}`)}const a=mn(i,s);return a&&n.push(a),n.length?`obj:{${n.join(",")}}`:null}finally{e.delete(s)}}f($e,"constraintSelectionToken$1");function mn(i,s){if(!i||s==null)return null;const t=i.resolveObject?.(s)||null,e=i.resolveComponent?.(s)||null,r=[];if(t){const o=t.uuid||t.name||t.id||null;o!=null&&r.push(`object:${String(o)}`)}if(e){const o=e.uuid||e.name||e.id||null;o!=null&&r.push(`component:${String(o)}`)}return r.length?r.join(","):null}f(mn,"resolvedSelectionToken$1");const hn={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},component:{type:"reference_selection",label:"Component",hint:"Select the component that should remain fixed in the assembly.",selectionFilter:["COMPONENT"]}},Q=class Q extends ne{async solve(s={}){const t=this.persistentData=this.persistentData||{},e=yn(this.inputParams.component),r=s.resolveComponent?.(e)||s.resolveObject?.(e);if(!r||!r.isAssemblyComponent)return t.status="incomplete",t.message="Select an assembly component to fix in place.",t.satisfied=!1,{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:t.message};const o=s.isComponentFixed?s.isComponentFixed(r):!!r.fixed;r.fixed=!0,r.userData=r.userData||{},r.userData.fixedByConstraint=!0;const n=s.getFeatureForComponent?.(r);n&&(n.inputParams=n.inputParams||{},n.inputParams.isFixed=!0);const a=o?"Component already marked as fixed.":"Component locked in place by constraint.";return t.status="satisfied",t.message=a,t.satisfied=!0,t.error=0,t.componentName=r.name||r.owningFeatureID||null,{ok:!0,status:"satisfied",satisfied:!0,applied:!o,error:0,message:a}}async run(s={}){return this.solve(s)}};f(Q,"FixedConstraint"),k(Q,"shortName","⏚"),k(Q,"longName","⏚ Fixed Constraint"),k(Q,"constraintType","fixed"),k(Q,"aliases",["fix","fixed constraint","fixed","FIXD"]),k(Q,"inputParamsSchema",hn);let Le=Q;function yn(i){return i?Array.isArray(i)?i.find(s=>s!=null)??null:i:null}f(yn,"firstSelection");const An={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two faces, edges, or components.",selectionFilter:["FACE","EDGE","COMPONENT"],multiple:!0,minSelections:2,maxSelections:2},applyImmediately:{type:"boolean",label:"Apply Immediately",default_value:!1,hint:"Maintained for compatibility; solver applies adjustments iteratively."},reverse:{type:"boolean",label:"Reverse",default_value:!1,hint:"Flip the stored orientation preference."}};var L,Et,Pt,Tt,Ue,kt;const J=class J extends ne{constructor(t){super(t);le(this,L);this._debugHelpers=[]}clearDebugArrows(t={}){const e=t.scene||null;e&&N(this,L,Ue).call(this,e)}async solve(t={}){const e=this.persistentData=this.persistentData||{},[r,o]=bn(this.inputParams);if((t.iteration??0)===0&&N(this,L,Ue).call(this,t.scene||null),!r||!o)return e.status="incomplete",e.message="Select two references to define the constraint.",e.satisfied=!1,{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:e.message};const n=N(this,L,Et).call(this,t,r,o),a=ve({constraint:this,context:t,selectionA:r,selectionB:o,opposeNormals:n,selectionLabelA:"elements[0]",selectionLabelB:"elements[1]"}),l=a.infoA||null,c=a.infoB||null;if(t.debugMode&&l&&c&&N(this,L,Tt).call(this,t,l,c),t.debugMode&&l&&c){const u=l.direction,d=c.direction,p=typeof a.angle=="number"?a.angle:null,g=typeof a.angleDeg=="number"?a.angleDeg:typeof p=="number"?R.radToDeg(p):null;console.log("[ParallelConstraint] directions",{id:this.inputParams?.id??this.inputParams?.constraintID??null,selectionA:{normal:u?.toArray?.()||null,point:l.origin?.toArray?.()||null,source:l.directionSource,kind:l.kind||null},selectionB:{normal:d?.toArray?.()||null,point:c.origin?.toArray?.()||null,source:c.directionSource,kind:c.kind||null},angleRad:p,angleDeg:g})}return e.status=a.status,e.message=a.message||"",e.satisfied=!!a.satisfied,typeof a.angle=="number"?(e.error=a.angle,e.errorDeg=typeof a.angleDeg=="number"?a.angleDeg:R.radToDeg(a.angle)):(e.error=null,e.errorDeg=null),Array.isArray(a.rotations)&&a.rotations.length?e.lastAppliedRotations=a.rotations:e.lastAppliedRotations&&(!a.rotations||a.rotations.length===0)&&(e.lastAppliedRotations=[]),a.exception?e.exception=a.exception:e.exception&&delete e.exception,a}async run(t={}){return this.solve(t)}};L=new WeakSet,Et=f(function(t,e,r){const o=N(this,L,Pt).call(this,t,e,r);return!!this.inputParams.reverse?!o:o},"#effectiveOppose"),Pt=f(function(t,e,r){const o=this.persistentData=this.persistentData||{},n=Sn(t,e,r),a=!!n;if(typeof o.preferredOppose!="boolean"||a&&o.preferredOpposeSignature!==n)try{const c=ee(this,t,e,"elements[0]"),u=ee(this,t,r,"elements[1]"),d=c?.direction?.clone()?.normalize(),p=u?.direction?.clone()?.normalize();if(!d||!p||d.lengthSq()===0||p.lengthSq()===0)throw new Error("ParallelConstraint: Unable to resolve directions for orientation preference.");const g=R.clamp(d.dot(p),-1,1);o.preferredOppose=g<0,o.lastOrientationDot=g,a?o.preferredOpposeSignature=n:o.preferredOpposeSignature&&delete o.preferredOpposeSignature}catch(c){typeof o.preferredOppose!="boolean"&&(o.preferredOppose=!1),t?.debugMode&&console.warn("[ParallelConstraint] Failed to capture orientation preference.",{id:this.inputParams?.id??this.inputParams?.constraintID??null,error:c})}return!!o.preferredOppose},"#preferredOppose"),Tt=f(function(t,e,r){if(!t?.debugMode)return;const o=t.scene||null;if(!o)return;const n=t.iteration??0,a=[{info:e,color:16731469,label:"A"},{info:r,color:5111697,label:"B"}],l=this.inputParams?.id??this.inputParams?.constraintID??"unknown";for(const{info:c,color:u,label:d}of a){if(!c?.direction||!c.origin)continue;const p=c.direction.clone().normalize();if(p.lengthSq()===0)continue;const g=c.origin.clone(),m=Math.max(N(this,L,kt).call(this,c),10),h=new Ke(p,g,m,u,m*.25,m*.15);h.name=`parallel-constraint-normal-${l}-${d}-iter${n}`,o.add(h),this._debugHelpers.push(h)}},"#updateNormalDebug"),Ue=f(function(t){if(this._debugHelpers){for(const e of this._debugHelpers)e&&(t&&e.parent===t?t.remove(e):e.parent&&e.parent.remove(e));this._debugHelpers.length=0}},"#clearNormalDebug"),kt=f(function(t){const e=[],r=f(n=>{if(!n)return;if(n.geometry?.computeBoundingSphere&&!n.geometry.boundingSphere)try{n.geometry.computeBoundingSphere()}catch{}const a=n.geometry?.boundingSphere;if(a?.radius&&e.push(Math.abs(a.radius)),n.geometry?.computeBoundingBox&&!n.geometry.boundingBox)try{n.geometry.computeBoundingBox()}catch{}const l=n.geometry?.boundingBox;if(l&&e.push(l.getSize(new b).length()/2),typeof n.getWorldScale=="function"){const c=n.getWorldScale(new b);e.push(c.length()*5)}},"pushBound");if(r(t.object),Array.isArray(t.component?.children))for(const n of t.component.children)r(n);e.push(t.component?.userData?.boundingRadius||0);const o=e.reduce((n,a)=>Number.isFinite(a)?Math.max(n,a):n,0);return Number.isFinite(o)&&o>0?o:0},"#estimateHelperLength"),f(J,"ParallelConstraint"),k(J,"shortName","∥"),k(J,"longName","∥ Parallel Constraint"),k(J,"constraintType","parallel"),k(J,"aliases",["parallel","parallel_faces","face_parallel","PARA"]),k(J,"inputParamsSchema",An);let Ge=J;function bn(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(bn,"selectionPair$1");function Sn(i,s,t){const e=Ve(i,s),r=Ve(i,t);return!e||!r?null:[e,r].sort().join("|")}f(Sn,"constraintSelectionPairSignature");function Ve(i,s,t=0,e=new Set){if(s==null||t>5)return null;const r=typeof s;if(r==="string"||r==="number"||r==="boolean")return`${r}:${String(s)}`;if(Array.isArray(s)){const o=[],n=Math.min(s.length,4);for(let a=0;a<n;a+=1){const l=Ve(i,s[a],t+1,e);l&&o.push(l)}return o.length?`arr:[${o.join(",")}]`:null}if(r!=="object"||e.has(s))return null;e.add(s);try{const o=["kind","type","name","selectionName","objectName","path","uuid","id","featureID"],n=[];for(const l of o){const c=s[l];if(c==null)continue;const u=typeof c;(u==="string"||u==="number"||u==="boolean")&&n.push(`${l}:${String(c)}`)}const a=vn(i,s);return a&&n.push(a),n.length?`obj:{${n.join(",")}}`:null}finally{e.delete(s)}}f(Ve,"constraintSelectionToken");function vn(i,s){if(!i||s==null)return null;const t=i.resolveObject?.(s)||null,e=i.resolveComponent?.(s)||null,r=[];if(t){const o=t.uuid||t.name||t.id||null;o!=null&&r.push(`object:${String(o)}`)}if(e){const o=e.uuid||e.name||e.id||null;o!=null&&r.push(`component:${String(o)}`)}return r.length?r.join(","):null}f(vn,"resolvedSelectionToken");const Ee=1e-6,Mn=R.degToRad(5),xn={id:{type:"string",default_value:null,hint:"Unique identifier for the constraint."},elements:{type:"reference_selection",label:"Elements",hint:"Select two faces, edges, or vertices.",selectionFilter:["FACE","EDGE","VERTEX"],multiple:!0,minSelections:2,maxSelections:2},reverse:{type:"boolean",label:"Reverse",default_value:!1,hint:"Flip the stored orientation preference."}};var $,_e,Ft,Xe,He,Ot;const j=class j extends ne{constructor(t){super(t);le(this,$);this._debugHelpers=[]}clearDebugArrows(t={}){const e=t.scene||null;e&&N(this,$,He).call(this,e)}async run(t={}){const e=this.persistentData=this.persistentData||{},[r,o]=Dn(this.inputParams);if((t.iteration??0)===0&&N(this,$,He).call(this,t.scene||null),!r||!o)return e.status="incomplete",e.message="Select two references to define the constraint.",e.satisfied=!1,e.lastAppliedMoves=[],e.lastAppliedRotations=[],{ok:!1,status:"incomplete",satisfied:!1,applied:!1,message:e.message};const n=t.resolveObject?.(r)||null,a=t.resolveObject?.(o)||null,l=at(rt(n,r)),c=at(rt(a,o));if(l==="FACE"&&c==="FACE")return this.faceToFace(t,r,o);if(l==="EDGE"&&c==="EDGE")return this.edgeToEdge(t,r,o);if(l==="POINT"&&c==="POINT")return this.pointToPoint(t,r,o);const u="Touch Align requires two selections of the same type. Face-to-face alignment is currently supported.";return e.status="unsupported-selection",e.message=u,e.satisfied=!1,e.error=null,e.errorDeg=null,e.lastAppliedMoves=[],e.lastAppliedRotations=[],e.exception&&delete e.exception,{ok:!1,status:"unsupported-selection",satisfied:!1,applied:!1,message:u}}async solve(t={}){return this.run(t)}async faceToFace(t,e,r){const o=this.persistentData=this.persistentData||{},n=N(this,$,_e).call(this,t,e,r),a=ve({constraint:this,context:t,selectionA:e,selectionB:r,opposeNormals:n,selectionLabelA:"elements[0]",selectionLabelB:"elements[1]"}),l=a.infoA||null,c=a.infoB||null;if(t.debugMode&&l&&c&&N(this,$,Xe).call(this,t,l,c),o.lastAppliedRotations=Array.isArray(a.rotations)?a.rotations:[],!a.ok)return o.status=a.status,o.message=a.message||"",o.satisfied=!1,o.error=a.error??null,o.errorDeg=a.angleDeg??null,o.exception=a.exception||null,a;if(!a.satisfied)return o.status=a.status,o.message=a.message||"Aligning surface orientations…",o.satisfied=!1,o.error=a.angle??null,o.errorDeg=a.angleDeg??null,o.lastAppliedMoves=[],o.exception&&delete o.exception,{...a,stage:"orientation"};if(!l||!c||!l.origin||!c.origin||!l.direction){const A="Unable to resolve contact data after alignment.";return o.status="invalid-selection",o.message=A,o.satisfied=!1,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:A}}const u=t.isComponentFixed?.(l.component),d=t.isComponentFixed?.(c.component),p=t.translationGain??1,g=Math.max(Math.abs(t.tolerance??Ee),1e-8),m=l.direction.clone().normalize(),h=new b().subVectors(c.origin,l.origin),S=[];let y=!1;const M=f((A,x)=>{if(!A||!x||x.lengthSq()===0)return!1;const z=t.applyTranslation?.(A,x);return z&&S.push({component:A.name||A.uuid,move:ce(x)}),z},"applyMove"),F=h.dot(m),v=Math.abs(F);if(v<=g){const A="Faces are touching within tolerance.";return o.status="satisfied",o.message=A,o.satisfied=!0,o.error=v,o.errorDeg=0,o.lastAppliedMoves=[],{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:v,message:A,infoA:l,infoB:c,diagnostics:{separation:F,moves:[]}}}if(u&&d){const A="Both components are fixed; unable to translate to touch.";return o.status="blocked",o.message=A,o.satisfied=!1,o.error=v,o.errorDeg=0,{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:v,message:A,infoA:l,infoB:c,diagnostics:{separation:F,moves:[]}}}const D=-F*Math.max(0,Math.min(1,p)),E=D*.5;if(!u&&!d){const A=m.clone().multiplyScalar(-E),x=m.clone().multiplyScalar(E);y=M(l.component,A)||y,y=M(c.component,x)||y}else if(u&&!d){const A=m.clone().multiplyScalar(D);y=M(c.component,A)||y}else if(!u&&d){const A=m.clone().multiplyScalar(-D);y=M(l.component,A)||y}const P=y?"adjusted":"pending",w=y?"Applied translation to bring faces into contact.":"Waiting for a movable component to translate.";return o.status=P,o.message=w,o.satisfied=!1,o.error=v,o.errorDeg=0,o.lastAppliedMoves=S,o.exception&&delete o.exception,{ok:!0,status:P,satisfied:!1,applied:y,error:v,message:w,infoA:l,infoB:c,diagnostics:{separation:F,moves:S}}}async edgeToEdge(t,e,r){const o=t||{},n=this.persistentData=this.persistentData||{},a=N(this,$,_e).call(this,o,e,r),l=ve({constraint:this,context:o,selectionA:e,selectionB:r,opposeNormals:a,selectionLabelA:"elements[0]",selectionLabelB:"elements[1]"}),c=l.infoA||null,u=l.infoB||null;if(o.debugMode&&c&&u&&N(this,$,Xe).call(this,o,c,u),n.lastAppliedRotations=Array.isArray(l.rotations)?l.rotations:[],!l.ok)return n.status=l.status,n.message=l.message||"",n.satisfied=!1,n.error=l.error??null,n.errorDeg=l.angleDeg??null,n.lastAppliedMoves=[],n.exception=l.exception||null,l;if(!l.satisfied)return n.status=l.status,n.message=l.message||"Aligning edge directions…",n.satisfied=!1,n.error=l.angle??null,n.errorDeg=l.angleDeg??null,n.lastAppliedMoves=[],n.exception&&delete n.exception,{...l,stage:"orientation"};if(!c||!u||!c.origin||!u.origin||!c.direction){const x="Unable to resolve edge data after alignment.";return n.status="invalid-selection",n.message=x,n.satisfied=!1,n.lastAppliedMoves=[],n.error=null,n.errorDeg=null,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:x}}const d=o.isComponentFixed?.(c.component),p=o.isComponentFixed?.(u.component),g=Math.max(0,Math.min(1,o.translationGain??1)),m=Math.max(Math.abs(o.tolerance??Ee),1e-8),h=c.direction.clone().normalize(),S=new b().subVectors(u.origin,c.origin),y=h.clone().multiplyScalar(S.dot(h)),M=S.clone().sub(y),F=M.length();if(n.error=F,n.errorDeg=null,F<=m){const x="Edges are colinear within tolerance.";return n.status="satisfied",n.message=x,n.satisfied=!0,n.lastAppliedMoves=[],n.exception&&delete n.exception,{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:F,message:x,infoA:c,infoB:u,diagnostics:{separationVector:M.toArray(),parallelComponent:y.toArray()}}}if(d&&p){const x="Both components are fixed; unable to translate to make edges colinear.";return n.status="blocked",n.message=x,n.satisfied=!1,n.lastAppliedMoves=[],n.exception&&delete n.exception,{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:F,message:x,infoA:c,infoB:u,diagnostics:{separationVector:M.toArray(),parallelComponent:y.toArray()}}}const v=M.clone().multiplyScalar(g),D=[];let E=!1;const P=f((x,z)=>{if(!x||!z||z.lengthSq()===0)return!1;const q=o.applyTranslation?.(x,z);return q&&D.push({component:x.name||x.uuid,move:ce(z)}),q},"applyMove");if(!d&&!p){const x=v.clone().multiplyScalar(.5),z=v.clone().multiplyScalar(-.5);E=P(c.component,x)||E,E=P(u.component,z)||E}else if(d&&!p){const x=v.clone().negate();E=P(u.component,x)||E}else if(!d&&p){const x=v.clone();E=P(c.component,x)||E}const w=E?"adjusted":"pending",A=E?"Applied translation to bring edges onto the same line.":"Waiting for a movable component to translate.";return n.status=w,n.message=A,n.satisfied=!1,n.lastAppliedMoves=D,n.exception&&delete n.exception,{ok:!0,status:w,satisfied:!1,applied:E,error:F,message:A,infoA:c,infoB:u,diagnostics:{separationVector:M.toArray(),parallelComponent:y.toArray(),moves:D},stage:"translation"}}async pointToPoint(t,e,r){const o=t||{},n=this.persistentData=this.persistentData||{};let a=Se(this,o,e),l=Se(this,o,r);if(n.pointToPointNextMode=n.pointToPointNextMode==="rotate"?"rotate":"translate",!a?.component||!l?.component){const v="Point selections must belong to assembly components.";return n.status="invalid-selection",n.message=v,n.satisfied=!1,n.error=null,n.errorDeg=null,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:v}}if(a.component===l.component){const v="Select points from different components for touch alignment.";return n.status="invalid-selection",n.message=v,n.satisfied=!1,n.error=null,n.errorDeg=null,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:v}}if(!a.point||!l.point){const v="Unable to resolve world-space positions for the selected points.";return n.status="invalid-selection",n.message=v,n.satisfied=!1,n.error=null,n.errorDeg=null,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{ok:!1,status:"invalid-selection",satisfied:!1,applied:!1,message:v}}const c=Math.max(Math.abs(o.tolerance??Ee),1e-8),u=Math.max(0,Math.min(1,o.translationGain??1)),d=Math.max(0,Math.min(1,o.rotationGain??1)),p=o.isComponentFixed?.(a.component),g=o.isComponentFixed?.(l.component);let m=new b().subVectors(a.point,l.point),h=m.length();const S=f(()=>{const v=Se(this,o,e),D=Se(this,o,r);v?.point&&D?.point&&(a=v,l=D,m=new b().subVectors(a.point,l.point),h=m.length())},"refreshInfo");if(n.error=h,n.errorDeg=null,h<=c){const v="Points are coincident within tolerance.";return n.status="satisfied",n.message=v,n.satisfied=!0,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{ok:!0,status:"satisfied",satisfied:!0,applied:!1,error:h,message:v,infoA:a,infoB:l,diagnostics:{distance:h,delta:m.toArray(),moves:[],rotations:[],stage:"satisfied"}}}const y=f(()=>{const v=[],D=[];let E=!1;const P=f((q,B,V)=>{const W=q?.component;if(!W||V<=0||o.isComponentFixed?.(W))return!1;const G=Nn(this,W);if(!G)return!1;const C=q.point.clone().sub(G),_=B.clone().sub(G);if(C.lengthSq()<=1e-12||_.lengthSq()<=1e-12)return!1;const se=C.clone().normalize(),De=_.clone().normalize(),de=R.clamp(se.dot(De),-1,1),U=Math.acos(de);if(!Number.isFinite(U)||U<=1e-6)return!1;const X=Math.min(U,Mn)*d*V;if(!Number.isFinite(X)||X<=1e-6)return!1;const Y=C.clone().cross(_);if(Y.lengthSq()<=1e-12)return!1;Y.normalize();const fe=new me().setFromAxisAngle(Y,X);W.updateMatrixWorld?.(!0);const pe=G.clone();let T=null;if(typeof W.worldToLocal=="function"&&typeof W.localToWorld=="function"&&(T=W.worldToLocal(G.clone())),!o.applyRotation?.(W,fe))return!1;E=!0;const ye={component:W.name||W.uuid,quaternion:fe.toArray(),axis:ce(Y),angleRad:X,angleDeg:R.radToDeg(X),pivot:ce(pe)};if(v.push(ye),T){W.updateMatrixWorld?.(!0);const Ne=W.localToWorld(T.clone()),oe=pe.clone().sub(Ne);oe.lengthSq()>1e-12&&o.applyTranslation?.(W,oe)&&D.push({component:W.name||W.uuid,move:ce(oe)})}return!0},"applyRotationTowards"),w=!p&&a.component,A=!g&&l.component;if(!w&&!A)return{handled:!1};const x=w&&A?.5:w?1:0,z=w&&A?.5:A?1:0;return x>0&&P(a,l.point,x),z>0&&P(l,a.point,z),E?(S(),n.error=h,n.status="adjusted",n.message="Applied rotation to bring points closer.",n.satisfied=!1,n.lastAppliedMoves=D,n.lastAppliedRotations=v,n.pointToPointNextMode="translate",n.exception&&delete n.exception,{handled:!0,applied:!0,result:{ok:!0,status:"adjusted",satisfied:!1,applied:!0,error:h,message:n.message,infoA:a,infoB:l,diagnostics:{distance:h,delta:m.toArray(),rotations:v,moves:D,stage:"rotation"}}}):{handled:!1}},"performRotation"),M=f(()=>{const v=[];let D=!1;const E=f((A,x)=>{if(!A||!x||x.lengthSq()===0)return!1;const z=o.applyTranslation?.(A,x);return z&&v.push({component:A.name||A.uuid,move:ce(x)}),z},"applyMove");if(p&&g){const A="Both components are fixed; unable to translate points into contact.";return n.status="blocked",n.message=A,n.satisfied=!1,n.lastAppliedMoves=[],n.lastAppliedRotations=[],n.pointToPointNextMode="translate",n.exception&&delete n.exception,{result:{ok:!1,status:"blocked",satisfied:!1,applied:!1,error:h,message:A,infoA:a,infoB:l,diagnostics:{distance:h,delta:m.toArray(),moves:[],rotations:[],stage:"translation"}},applied:!1}}if(!p&&!g){const A=m.clone().multiplyScalar(.5*u);A.lengthSq()>0&&(D=E(a.component,A.clone().negate())||D,D=E(l.component,A)||D)}else if(p&&!g){const A=m.clone().multiplyScalar(u);A.lengthSq()>0&&(D=E(l.component,A)||D)}else if(!p&&g){const A=m.clone().multiplyScalar(u);A.lengthSq()>0&&(D=E(a.component,A.clone().negate())||D)}D&&(S(),n.error=h);const P=D?"adjusted":"pending",w=D?"Applied translation to align points.":"Waiting for a movable component to translate.";return n.status=P,n.message=w,n.satisfied=!1,n.lastAppliedMoves=v,n.lastAppliedRotations=[],n.pointToPointNextMode="rotate",n.exception&&delete n.exception,{result:{ok:!0,status:P,satisfied:!1,applied:D,error:h,message:w,infoA:a,infoB:l,diagnostics:{distance:h,delta:m.toArray(),moves:v,rotations:[],stage:"translation"}},applied:D}},"performTranslation");let F=null;if(n.pointToPointNextMode==="rotate"){const v=y();if(v?.handled)return v.result}return F=M(),F.result}};$=new WeakSet,_e=f(function(t,e,r){const o=N(this,$,Ft).call(this,t,e,r);return!!this.inputParams.reverse?!o:o},"#effectiveOppose"),Ft=f(function(t,e,r){const o=this.persistentData=this.persistentData||{};if(typeof o.preferredOppose!="boolean"){const n=ee(this,t,e,"elements[0]"),a=ee(this,t,r,"elements[1]"),l=n?.direction?.clone()?.normalize(),c=a?.direction?.clone()?.normalize();if(!l||!c||l.lengthSq()===0||c.lengthSq()===0)throw new Error("TouchAlignConstraint: Unable to resolve directions for orientation preference.");const u=R.clamp(l.dot(c),-1,1);o.preferredOppose=u<0,o.lastOrientationDot=u}return!!o.preferredOppose},"#preferredOppose"),Xe=f(function(t,e,r){if(!t?.debugMode)return;const o=t.scene||null;if(!o)return;const n=t.iteration??0,a=[{info:e,color:16731469,label:"A"},{info:r,color:5111697,label:"B"}],l=this.inputParams?.id??this.inputParams?.constraintID??"unknown";for(const{info:c,color:u,label:d}of a){if(!c?.direction||!c.origin)continue;const p=c.direction.clone().normalize();if(p.lengthSq()===0)continue;const g=c.origin.clone(),m=Math.max(N(this,$,Ot).call(this,c),10),h=new Ke(p,g,m,u,m*.25,m*.15);h.name=`touch-align-normal-${l}-${d}-iter${n}`,o.add(h),this._debugHelpers.push(h)}},"#updateNormalDebug"),He=f(function(t){if(this._debugHelpers){for(const e of this._debugHelpers)e&&(t&&e.parent===t?t.remove(e):e.parent&&e.parent.remove(e));this._debugHelpers.length=0}},"#clearNormalDebug"),Ot=f(function(t){const e=[],r=f(n=>{if(!n)return;if(n.geometry?.computeBoundingSphere&&!n.geometry.boundingSphere)try{n.geometry.computeBoundingSphere()}catch{}const a=n.geometry?.boundingSphere;if(a?.radius&&e.push(Math.abs(a.radius)),n.geometry?.computeBoundingBox&&!n.geometry.boundingBox)try{n.geometry.computeBoundingBox()}catch{}const l=n.geometry?.boundingBox;if(l&&e.push(l.getSize(new b).length()/2),typeof n.getWorldScale=="function"){const c=n.getWorldScale(new b);e.push(c.length()*5)}},"pushBound");if(r(t.object),Array.isArray(t.component?.children))for(const n of t.component.children)r(n);e.push(t.component?.userData?.boundingRadius||0);const o=e.reduce((n,a)=>Number.isFinite(a)?Math.max(n,a):n,0);return Number.isFinite(o)&&o>0?o:0},"#estimateHelperLength"),f(j,"TouchAlignConstraint"),k(j,"shortName","⪥"),k(j,"longName","⪥ Touch Align Constraint"),k(j,"constraintType","touch_align"),k(j,"aliases",["touch","touch_align","touch-align","TALN"]),k(j,"inputParamsSchema",xn);let Ce=j;function Dn(i){if(!i||typeof i!="object")return[null,null];const t=(Array.isArray(i.elements)?i.elements:[]).filter(e=>e!=null).slice(0,2);return i.elements=t,t.length===2?t:t.length===1?[t[0],null]:[null,null]}f(Dn,"selectionPair");function ce(i){return i?[i.x,i.y,i.z]:[0,0,0]}f(ce,"vectorToArray");function Se(i,s,t){if(!t)return null;const e=s.resolveObject?.(t)||null,r=s.resolveComponent?.(t)||null,o=wn(i,e,r);return{selection:t,object:e,component:r||null,point:o}}f(Se,"resolvePointSelection");function wn(i,s,t){if(s){try{const r=te(null,s);if(r&&typeof r.clone=="function")return r.clone()}catch{}const e=i.getWorldPoint(s);if(e)return e}if(t){try{const r=te(null,t);if(r&&typeof r.clone=="function")return r.clone()}catch{}t.updateMatrixWorld?.(!0);const e=i.getWorldPoint(t);if(e)return e}return null}f(wn,"resolveSelectionPoint");function Nn(i,s){if(!s)return null;s.updateMatrixWorld?.(!0);try{const e=te(null,s);if(e&&typeof e.clone=="function")return e.clone()}catch{}const t=i.getWorldPoint(s);if(t)return t;if(typeof s.getWorldPosition=="function")return s.getWorldPosition(new b);if(s.position){const e=s.position.clone();return s.parent?.matrixWorld?e.applyMatrix4(s.parent.matrixWorld):e}return null}f(Nn,"resolveComponentMidpoint");function rt(i,s){const t=(s?.kind||i?.userData?.type||i?.userData?.brepType||i?.type||"").toString().toUpperCase();return t?t.includes("FACE")?"FACE":t.includes("EDGE")?"EDGE":t.includes("VERTEX")||t.includes("POINT")?"POINT":t.includes("COMPONENT")?"COMPONENT":t:"UNKNOWN"}f(rt,"selectionKindFrom");function at(i){return i==="COMPONENT"?"FACE":i}f(at,"normalizeSelectionKind");const Ze=f(i=>{if(i==null&&i!==0)return"";try{return String(i).trim()}catch{return""}},"normalizeName"),ue=f(i=>Ze(i).toLowerCase(),"normalizeKey"),En=f(i=>Ze(i?.shortName??i?.constraintShortName??i?.name),"getShortName"),Pn=f(i=>Ze(i?.longName??i?.constraintName??i?.name),"getLongName");var xe,Bt;const Qe=class Qe{constructor(){le(this,xe);this._map=new Map,this._aliases=new Map,this.register(ze),this.register(ke),this.register(Re),this.register(Le),this.register(Ge),this.register(Ce)}register(s){if(!s)return;s.shortName||(s.shortName=s.constraintShortName||s.name||"CONST"),s.longName||(s.longName=s.constraintName||s.name||s.shortName||"Constraint"),typeof s.showContexButton!="function"&&(s.showContexButton=()=>!1);const t=N(this,xe,Bt).call(this,s);if(t.typeKey){this._map.set(t.typeKey,s);for(const e of t.aliases){const r=ue(e);r&&this._aliases.set(r,s)}}}get(s){const t=ue(s);if(!t)throw new Error("Constraint type must be a non-empty string");const e=this._map.get(t)||this._aliases.get(t);if(!e)throw new Error(`Constraint type "${s}" is not registered.`);return e}getSafe(s){try{return this.get(s)}catch{return null}}has(s){return!!this.getSafe(s)}list(){return Array.from(new Set(this._map.values()))}listAvailable(){return this.list()}};xe=new WeakSet,Bt=f(function(s){const t=new Set,e=ue(s.constraintType||s.type||null);e&&t.add(e);const r=ue(En(s));r&&r!==e&&t.add(r);const o=ue(Pn(s));o&&o!==e&&t.add(o);const n=ue(s.name);n&&t.add(n);const a=Array.isArray(s.aliases)?s.aliases.filter(Boolean):[],[l,...c]=t;return{typeKey:l||null,aliases:c.concat(a)}},"#collectKeys"),f(Qe,"AssemblyConstraintRegistry");let lt=Qe;export{lt as A};