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,4 +1,4 @@
1
- var qe=Object.defineProperty;var pe=o=>{throw TypeError(o)};var u=(o,t)=>qe(o,"name",{value:t,configurable:!0});var Ze=(o,t,e)=>t.has(o)||pe("Cannot "+e);var Mt=(o,t,e)=>t.has(o)?pe("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(o):t.set(o,e);var A=(o,t,e)=>(Ze(o,t,"access private method"),e);import{r as Je,F as Qe,A as et}from"./FeatureRegistry-Cd-GX-Bm.js";import{Q as Ut,V as T,a3 as tn,b6 as Tt,s as mt,a4 as Dt,Z as he,b7 as me,K as en,b0 as nn,b as jt}from"./featureDialogs-CUWi02Qp.js";import{A as De}from"./AssemblyConstraintRegistry-3P1cpGjG.js";import{d as z}from"./deepClone-Dj59xCHB.js";import{e as rn,o as sn}from"./browserStorage-CvgF8ovw.js";function on(o,t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;let e=null;try{o&&typeof o.evaluateExpression=="function"&&(e=o.evaluateExpression(t))}catch{e=null}if(typeof e=="number"&&Number.isFinite(e))return e;const n=Number(e);if(Number.isFinite(n))return n;const r=Number(t);return Number.isFinite(r)?r:null}u(on,"evaluateConstraintNumericValue");function W(o){return o===0?"0":o?String(o).trim():""}u(W,"normalizeTypeString");const an=new Set(["type","persistentData","__open"]);function cn(o,t){if(o===t)return!0;if(!Array.isArray(o)||!Array.isArray(t)||o.length!==t.length)return!1;for(let e=0;e<o.length;e+=1)if(o[e]!==t[e])return!1;return!0}u(cn,"shallowArrayEqual");function de(o){const t={};if(!o||typeof o!="object")return t;for(const e in o){if(!Object.prototype.hasOwnProperty.call(o,e)||an.has(e))continue;const n=o[e]?o[e].default_value:void 0;t[e]=z(n)}return t}u(de,"extractDefaults");function ye(o){return`Unknown constraint type: ${o!=null?String(o):"unknown"}`}u(ye,"formatUnknownConstraintMessage");const ln=new Map([["touch_align","touch_align"],["touch-align","touch_align"],["touchalign","touch_align"],["touch align","touch_align"],["touch align constraint","touch_align"],["touchalignconstraint","touch_align"],["touch","touch_align"],["distance","distance"],["distance constraint","distance"],["distanceconstraint","distance"],["angle","angle"],["angle constraint","angle"],["angleconstraint","angle"]]),ge={touch_align:"Touch Align",distance:"Distance",angle:"Angle"},be=1e-6,Vt=1,un=.5,fn=.5,pn=Math.max(1,Vt),ct="Constraint disabled.";function lt(o,t){const e=Number(o);return Number.isFinite(e)?e:t}u(lt,"toFiniteNumber$4");function hn(o){const t=Math.floor(lt(o,Vt));return!Number.isFinite(t)||t<1?Vt:t}u(hn,"clampIterations");function Se(o,t){const e=lt(o,t);return Number.isFinite(e)?e<0?0:e>1?1:e:t}u(Se,"clampGain");function mn(o){if(!o||typeof o.traverse!="function")return;const t=[],e=["parallel-constraint-normal-","distance-constraint-normal-","touch-align-normal-"];o.traverse(n=>{!n||typeof n.name!="string"||e.some(r=>n.name.startsWith(r))&&t.push(n)});for(const n of t)try{n.parent?.remove?.(n)}catch{}}u(mn,"removeExistingDebugArrows");function Pe(o){let t=o;for(;t;){if(t.isAssemblyComponent||t.type==="COMPONENT")return t;t=t.parent||null}return null}u(Pe,"resolveComponentFromObject");function dn(o){return Pe(o)?1:0}u(dn,"scoreObjectForComponent");function yn(o){if(!o)return null;if(o instanceof T)return o.clone();if(typeof o=="object"){const{x:t,y:e,z:n}=o,r=Number.isFinite(t)?t:0,s=Number.isFinite(e)?e:0,i=Number.isFinite(n)?n:0;return new T(r,s,i)}return null}u(yn,"vectorFrom");function wt(o,t=null){if(!o)return t;const e=o.inputParams||{},n=e.id??e.constraintID??o.id??t;return n==null?t:String(n)}u(wt,"resolveConstraintEntryId");function dt(o){return W(wt(o))}u(dt,"normalizeConstraintEntryId");var x,Fe,At,Bt,Re,Xt,ve,rt,Kt,ze,ke,gt,Yt,It,U;const oe=class oe{constructor(t=null,e=null){Mt(this,x);this.partHistory=t||null,this.registry=e||new De,this.constraints=[],this.idCounter=0,this._listeners=new Set,this._autoRunScheduled=!1,this._autoRunActive=!1,this._autoRunOptions=null}setPartHistory(t){this.partHistory=t||null,this.partHistory&&this.constraints.length&&A(this,x,rt).call(this)}setRegistry(t){this.registry=t||this.registry}addListener(t){return typeof t!="function"?()=>{}:(this._listeners.add(t),()=>{this._listeners.delete(t)})}removeListener(t){typeof t=="function"&&this._listeners.delete(t)}onChange(t){if(typeof t!="function")return()=>{};const e=u(()=>{try{t(this)}catch{}},"wrapped");return this.addListener(e)}list(){return this.entries}get entries(){return this.constraints}set entries(t){Array.isArray(t)?this.constraints=t:this.constraints=[]}get size(){return this.constraints.length}findById(t){const e=W(t);return e&&this.constraints.find(n=>dt(n)===e)||null}async addConstraint(t,e=null){const n=A(this,x,It).call(this,t);if(!n)throw new Error(`Constraint type "${t}" is not registered.`);const r=n.inputParamsSchema||{},s=de(r),i=W(n.constraintType||t||n.name),c={type:i,inputParams:{...s},persistentData:{isNewConstraint:!0},__open:!0,enabled:!0};Object.defineProperty(c,"constraintClass",{value:n,configurable:!0,writable:!0,enumerable:!1});const m=n?.shortName||n?.constraintShortName||i||"CONST",a=this.generateId(m),y=c.inputParams.id??c.inputParams.constraintID;return c.inputParams.id=y||a,A(this,x,At).call(this,c),e&&typeof e=="object"&&Object.assign(c.inputParams,z(e)),c.inputParams.applyImmediately=!0,A(this,x,Bt).call(this,c),this.constraints.push(c),A(this,x,U).call(this,"add",c),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),c}removeConstraint(t){const e=W(t);if(!e)return!1;const n=this.constraints.findIndex(s=>dt(s)===e);if(n<0)return!1;const[r]=this.constraints.splice(n,1);return A(this,x,U).call(this,"remove",r||null),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),!0}moveConstraint(t,e){const n=W(t);if(!n)return!1;const r=this.constraints.findIndex(s=>dt(s)===n);return r<0?!1:this.moveConstraintToIndex(n,r+e)}moveConstraintToIndex(t,e){const n=W(t);if(!n)return!1;const r=this.constraints.findIndex(c=>dt(c)===n);if(r<0)return!1;const s=Number.isFinite(e)?Math.max(0,Math.min(this.constraints.length-1,e)):r;if(s===r)return!1;const[i]=this.constraints.splice(r,1);return this.constraints.splice(s,0,i),A(this,x,U).call(this,"reorder",i||null),A(this,x,rt).call(this),!0}updateConstraintParams(t,e){const n=this.findById(t);return!n||typeof e!="function"?!1:(e(n.inputParams),A(this,x,At).call(this,n),A(this,x,U).call(this,"update",n),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),!0)}setConstraintEnabled(t,e){const n=this.findById(t);if(!n)return!1;const r=e!==!1;if(n.enabled!==!1===r){if(n.enabled!==r&&(n.enabled=r),!r&&n.persistentData?.status!=="disabled"){const c={...n.persistentData||{}};c.status="disabled",c.message||(c.message=ct),n.persistentData=c,A(this,x,U).call(this,"update",n)}return!1}n.enabled=r;const i={...n.persistentData||{}};return r?(i.status==="disabled"&&(i.status="pending",i.message===ct&&delete i.message,n.persistentData=i),A(this,x,U).call(this,"update",n),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),!0):(i.status="disabled",i.message||(i.message=ct),n.persistentData=i,A(this,x,U).call(this,"update",n),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),!0)}setOpenState(t,e){const n=this.findById(t);if(!n)return!1;const r=e!==!1;if(n.__open!==!1===r)return!1;const i=n.inputParams||{};if(Object.prototype.hasOwnProperty.call(i,"__open"))try{i.__open=r}catch{n.__open=r}else n.__open=r;return(!n.runtimeAttributes||typeof n.runtimeAttributes!="object")&&(n.runtimeAttributes={}),n.runtimeAttributes.__open=r,A(this,x,U).call(this,"open-state",n),!0}setExclusiveOpen(t){const e=W(t);if(!e)return!1;let n=!1;for(const r of this.constraints){if(!r)continue;const i=dt(r)===e;if(r.__open!==!1!==i){const m=r.inputParams||{};if(Object.prototype.hasOwnProperty.call(m,"__open"))try{m.__open=i}catch{r.__open=i}else r.__open=i;(!r.runtimeAttributes||typeof r.runtimeAttributes!="object")&&(r.runtimeAttributes={}),r.runtimeAttributes.__open=i,n=!0}}return n&&A(this,x,U).call(this,"open-state",this.findById(t)),n}clear(){this.constraints=[],this.idCounter=0,A(this,x,U).call(this,"clear")}snapshot(){return{idCounter:this.idCounter,constraints:this.constraints.map(t=>({type:t?.type||null,inputParams:z(t?.inputParams)||{},persistentData:z(t?.persistentData)||{},open:t?.__open!==!1,enabled:t?.enabled!==!1}))}}async replaceAll(t=[],e=0){const n=[],r=Array.isArray(t)?t:[];let s=Number.isFinite(Number(e))?Number(e):0;for(const i of r){const c=A(this,x,Fe).call(this,i);if(!c)continue;const m=c.type||c.constraintType||null,a=A(this,x,It).call(this,m);if(!a)continue;const y=de(a.inputParamsSchema),f=W(a.constraintType||m||a.name),l={type:f,inputParams:{...y,...z(c.inputParams||{})},persistentData:z(c.persistentData||{}),__open:c.open!==!1,enabled:c.enabled!==!1},h=l.inputParams.id??l.inputParams.constraintID;if(h){const d=String(h).match(/(\d+)$/);if(d){const g=Number(d[1]);Number.isFinite(g)&&(s=Math.max(s,g))}l.inputParams.id=h}else{const d=(a?.shortName||a?.constraintShortName||f||"CONST").replace(/[^a-z0-9]/gi,"").toUpperCase()||"CONST";s+=1,l.inputParams.id=`${d}${s}`}A(this,x,At).call(this,l),l.inputParams.applyImmediately=!0,Object.defineProperty(l,"constraintClass",{value:a,configurable:!0,writable:!0,enumerable:!1}),A(this,x,Bt).call(this,l),n.push(l)}this.idCounter=s,this.constraints=n,A(this,x,U).call(this,"replace"),this.constraints.length&&(this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this))}async deserialize(t){const e=t&&typeof t=="object"?t:{},n=Array.isArray(e.constraints)?e.constraints:Array.isArray(t)?t:[],r=Number.isFinite(Number(e.idCounter))?Number(e.idCounter):void 0;await this.replaceAll(n,r)}generateId(t="CONST"){const e=W(t).replace(/[^a-z0-9]/gi,"").toUpperCase()||"CONST";return this.idCounter+=1,`${e}${this.idCounter}`}checkConstraintErrors(t=this.partHistory,e={}){const n=e&&typeof e=="object"?e:{},r=n.emit!==!1,s=n.updatePersistentData!==!1,i=t||this.partHistory||null;i&&(this.partHistory=i);const c=A(this,x,Xt).call(this),m=[];let a=!1;const y=u((f,l)=>{const h=f?.persistentData&&typeof f.persistentData=="object"?f.persistentData:{},d={...h};let g=!1;const S=u((b,w)=>{const C=d[b];if(w===void 0){Object.prototype.hasOwnProperty.call(d,b)&&(delete d[b],g=!0);return}if(Array.isArray(C)&&Array.isArray(w)){if(cn(C,w))return}else if(C===w)return;d[b]=w,g=!0},"set"),p=u(b=>{Object.prototype.hasOwnProperty.call(d,b)&&(delete d[b],g=!0)},"remove");try{l({set:S,remove:p,data:d,previous:h})}catch(b){console.warn("[AssemblyConstraintHistory] Failed to update persistent data:",b)}return g&&(f.persistentData=d),g},"mutatePersistentData");for(const f of this.constraints){if(!f)continue;const l=wt(f),h=f?.type||null,d={id:l,constraintID:l,type:h,status:"ok",message:"",duplicateConstraintIDs:null,duplicateSignature:null};if(f.enabled===!1){d.status="disabled",d.message=ct,s&&(a=y(f,({set:p,remove:b,previous:w})=>{p("status","disabled"),(!w.message||w.message===ct)&&p("message",ct),p("satisfied",!1),b("duplicateConstraintIDs"),b("duplicateSignature")})||a),m.push(d);continue}const g=A(this,x,It).call(this,h),S=c.get(f);if(!g){const p=ye(h);d.status="error",d.message=p,s&&(a=y(f,({set:b,remove:w})=>{b("status","error"),b("message",p),b("satisfied",!1),w("duplicateConstraintIDs"),w("duplicateSignature")})||a),m.push(d);continue}if(S){const p=Array.isArray(S.relatedIds)?S.relatedIds.filter(Boolean):[],b=S.signature||null;d.status="duplicate",d.message=S.message||"Duplicate constraint selections.",d.duplicateConstraintIDs=p.length?p:null,d.duplicateSignature=b,s&&(a=y(f,({set:w,remove:C})=>{w("status","duplicate"),w("message",d.message),w("satisfied",!1),d.duplicateConstraintIDs?w("duplicateConstraintIDs",d.duplicateConstraintIDs):C("duplicateConstraintIDs"),b?w("duplicateSignature",b):C("duplicateSignature")})||a),m.push(d);continue}s&&(a=y(f,({set:p,remove:b,previous:w})=>{w.status==="duplicate"&&(p("status","pending"),typeof w.message=="string"&&w.message.startsWith("Duplicate constraint selections")&&b("message")),w.status==="error"&&typeof w.message=="string"&&w.message.startsWith("Unknown constraint type:")&&(p("status","pending"),b("message")),b("duplicateConstraintIDs"),b("duplicateSignature")})||a),m.push(d)}return s&&a&&r&&A(this,x,U).call(this,"update"),m}async runAll(t=this.partHistory,e={}){const n=t||this.partHistory;if(!n)return[];this.partHistory=n,this.checkConstraintErrors(n,{emit:!1});const r=Math.abs(lt(e?.tolerance,be))||be,s=hn(e?.iterations),i=Se(e?.translationGain,un),c=Se(e?.rotationGain,fn),m=e?.debugMode===!0,a=m?500:0,y=lt(e?.delayMs??e?.iterationDelayMs,a),f=Math.max(0,Number.isFinite(y)?y:a),l=e?.viewer||n.viewer||null,h=u(()=>{try{l?.render?.()}catch{}try{l?.requestRender?.()}catch{}},"renderScene"),d=e?.controller&&typeof e.controller=="object"?e.controller:null,g=d?.signal||e?.signal||null;let S=!1;const p=u(()=>g?.aborted?(S=!0,!0):!1,"shouldAbort"),b=d?.hooks||e?.hooks,w=b&&typeof b=="object"?b:{},C=u(async(I,N={})=>{const F=w?.[I];if(typeof F=="function")try{await F({controller:d,signal:g,aborted:S,...N})}catch(_){console.warn(`[AssemblyConstraintHistory] hook "${I}" failed:`,_)}},"safeCallHook"),D=n.scene||null,O=Array.isArray(n.features)?n.features.filter(Boolean):[],j=new Map;for(const I of O){const N=W(I?.inputParams?.featureID);N&&j.set(N,I)}const H=new Set,ot=u(I=>Je(D,I,{scoreFn:dn,allowJson:!1,allowUuidString:!1,allowUuidObject:!0,allowFuzzyName:!1,allowNameContains:!1,allowPath:!1,allowReference:!1,allowTarget:!1,allowSelectionName:!1,arrayMode:"first"}),"resolveObject"),ft=u(I=>{const N=ot(I);return Pe(N)},"resolveComponent"),J=u(I=>{if(!I)return null;const N=W(I.owningFeatureID);return N&&j.get(N)||null},"getFeatureForComponent"),Y=u(I=>!!(!I||I.fixed||I.userData?.fixedByConstraint||J(I)?.inputParams?.isFixed),"isComponentFixed"),G=u(I=>{I&&H.add(I)},"markUpdated"),E={partHistory:n,scene:D,tolerance:r,translationGain:i,rotationGain:c,resolveObject:ot,resolveComponent:ft,applyTranslation:u((I,N)=>{const F=yn(N);return!I||!F||F.lengthSq()===0?!1:(I.position.add(F),I.updateMatrixWorld?.(!0),G(I),!0)},"applyTranslation"),applyRotation:u((I,N)=>{if(!I||!N)return!1;let F;if(N instanceof Ut)F=N.clone();else{const _=lt(N?.x,0),at=lt(N?.y,0),v=lt(N?.z,0),L=Number.isFinite(N?.w)?N.w:1;F=new Ut(_,at,v,L)}return!Number.isFinite(F.x)||!Number.isFinite(F.y)||!Number.isFinite(F.z)||!Number.isFinite(F.w)?!1:(Math.abs(1-F.lengthSq())>1e-6&&F.normalize(),I.quaternion.premultiply(F),I.updateMatrixWorld?.(!0),G(I),!0)},"applyRotation"),isComponentFixed:Y,getFeatureForComponent:J,markUpdated:G,viewer:l,renderScene:h,debugMode:m};mn(D);const Ke=A(this,x,Xt).call(this),pt=this.constraints.map(I=>{const N=wt(I);if(I?.enabled===!1)return{entry:I,instance:null,result:{id:N,ok:!0,status:"disabled",message:ct,applied:!1,satisfied:!1,iteration:0,constraintID:N},skipReason:"disabled"};const F=Ke.get(I);if(F){const $=Array.isArray(F.relatedIds)?F.relatedIds.slice():[],X={id:N,ok:!1,status:"duplicate",message:F.message,applied:!1,satisfied:!1,iteration:0,constraintID:N,duplicateConstraintIDs:$,duplicateSignature:F.signature};return{entry:I,instance:null,result:X,skipReason:"duplicate"}}const _=A(this,x,It).call(this,I.type);if(!_){const $=ye(I.type);return I.persistentData={status:"error",message:$,lastRunAt:Date.now(),lastIteration:0},{entry:I,instance:null,result:{id:N,ok:!1,status:"error",message:$,applied:!1,satisfied:!1,iteration:0,constraintID:N},skipReason:"unregistered"}}const at=z(I.inputParams)||{},v=z(I.inputParams)||{},L=new _(n);A(this,x,Re).call(this,v,_.inputParamsSchema||{});try{L.inputParams=v}catch{L.inputParams={...v}}try{Object.assign(L.persistentData,z(I.persistentData))}catch{L.persistentData={...I.persistentData||{}}}return{entry:I,instance:L,result:null,originalInputParams:at}});for(const I of pt)I.instance?.clearDebugArrows?.({scene:D});await C("onStart",{maxIterations:s,constraintCount:pt.length});let fe=0;const Ye=pt.length;t:for(let I=0;I<s&&!(p()||(await C("onIterationStart",{iteration:I,maxIterations:s}),p()));I+=1){let N=!1;for(let F=0;F<pt.length;F+=1){if(p())break t;const _=pt[F],at=wt(_?.entry),v=_?.entry?.type||null,L={iteration:I,index:F,id:at,constraintID:at,constraintType:v,totalConstraints:Ye};if(!_.instance){await C("onConstraintSkipped",{...L,skipReason:_.skipReason||null});continue}if(await C("onConstraintStart",L),p())break t;const $={...E,iteration:I,maxIterations:s};let X;try{typeof _.instance.solve=="function"?X=await _.instance.solve($):X=await _.instance.run($)}catch(ht){console.warn("[AssemblyConstraintHistory] Constraint solve failed:",ht),X={ok:!1,status:"error",message:ht?.message||"Constraint evaluation failed.",error:ht},_.instance.persistentData=_.instance.persistentData||{},_.instance.persistentData.status="error",_.instance.persistentData.message=X.message}if(_.result=A(this,x,Yt).call(this,_.instance,X,I),_.result.applied&&(N=!0),await C("onConstraintEnd",{...L,result:_.result}),p())break t}if(typeof E.renderScene=="function")try{E.renderScene()}catch{}if(f>0&&await new Promise(F=>setTimeout(F,f)),p()||(fe=I+1,await C("onIterationComplete",{iteration:I,maxIterations:s,applied:N}),p())||!N)break}S=S||g?.aborted||!1;const Ge=Date.now(),Ot=[];for(const I of pt){const{entry:N,instance:F}=I,_=I.result||A(this,x,Yt).call(this,F,{ok:!1,status:"pending",message:"Constraint was not evaluated."},Math.max(0,s-1)),v={...F?.persistentData&&Object.keys(F.persistentData).length?F.persistentData:N.persistentData||{}};if(_.status&&(v.status=_.status),_.message!==void 0&&(_.message?v.message=_.message:v.message&&delete v.message),v.satisfied=!!_.satisfied,typeof _.error=="number"&&Number.isFinite(_.error)&&(v.error=_.error),v.lastRunAt=Ge,v.lastIteration=_.iteration,v.lastRequestedIterations=s,_.status==="duplicate"?(Array.isArray(_.duplicateConstraintIDs)&&_.duplicateConstraintIDs.length?v.duplicateConstraintIDs=_.duplicateConstraintIDs.slice():v.duplicateConstraintIDs&&delete v.duplicateConstraintIDs,_.duplicateSignature?v.duplicateSignature=_.duplicateSignature:v.duplicateSignature&&delete v.duplicateSignature):(v.duplicateConstraintIDs&&delete v.duplicateConstraintIDs,v.duplicateSignature&&delete v.duplicateSignature),N.persistentData=v,I.originalInputParams){const $=z(I.originalInputParams)||{};_.persistInputParams&&typeof _.persistInputParams=="object"&&Object.assign($,z(_.persistInputParams));const X=N.inputParams&&typeof N.inputParams=="object"?N.inputParams:{};for(const ht of Object.keys(X))Object.prototype.hasOwnProperty.call($,ht)||delete X[ht];Object.assign(X,$),N.inputParams=X}else{const $={...N.inputParams||{}};_.persistInputParams&&typeof _.persistInputParams=="object"&&Object.assign($,z(_.persistInputParams)),N.inputParams=$}const L=wt(N);Ot.push({id:L,constraintID:L,type:N?.type||null,..._})}try{n.syncAssemblyComponentTransforms?.()}catch(I){console.warn("[AssemblyConstraintHistory] Failed to sync component transforms:",I)}return A(this,x,U).call(this,"solve"),await C("onComplete",{results:Ot.slice(),aborted:S,iterationsCompleted:fe,maxIterations:s}),Ot}};x=new WeakSet,Fe=u(function(t){if(!t||typeof t!="object")return t;const e={...t},n=t.inputParams&&typeof t.inputParams=="object"?t.inputParams:null;if(n){const s={...n},i=Object.prototype.hasOwnProperty.call(s,"constraintID")?s.constraintID:void 0;(s.id==null||s.id==="")&&i!=null&&(s.id=i),Object.prototype.hasOwnProperty.call(s,"constraintID")&&delete s.constraintID,e.inputParams=s}const r=Object.prototype.hasOwnProperty.call(e,"constraintID")?e.constraintID:void 0;return(e.id==null||e.id==="")&&r!=null&&(e.id=r),Object.prototype.hasOwnProperty.call(e,"constraintID")&&delete e.constraintID,(e.id==null||e.id==="")&&e.inputParams?.id!=null&&(e.id=e.inputParams.id),e},"#runConstraintEntryMigrations"),At=u(function(t){if(!t||!t.inputParams)return;const e=t.inputParams,n=e.id??e.constraintID??t.id;if(!n)return;const r=String(n);e.id=r,t.id=r},"#syncEntryIds"),Bt=u(function(t){if(!t||typeof t!="object")return;(!t.inputParams||typeof t.inputParams!="object")&&(t.inputParams={});const e=t.inputParams,n={configurable:!0,enumerable:!1};A(this,x,At).call(this,t);const r=Object.prototype.hasOwnProperty.call(e,"constraintID")?e.constraintID:void 0;if(r!=null&&(e.id==null||e.id==="")&&(e.id=r),Object.prototype.hasOwnProperty.call(e,"constraintID"))try{delete e.constraintID}catch{}Object.getOwnPropertyDescriptor(e,"constraintID")||Object.defineProperty(e,"constraintID",{...n,get:u(()=>e.id,"get"),set:u(a=>{if(a==null){e.id=a,t.id=a;return}const y=String(a);e.id=y,t.id=y},"set")});const s=Object.prototype.hasOwnProperty.call(e,"__open")?e.__open:t.__open;if(Object.prototype.hasOwnProperty.call(e,"__open"))try{delete e.__open}catch{}const i=s!==!1;t.__open=i;const c=t.runtimeAttributes&&typeof t.runtimeAttributes=="object"?t.runtimeAttributes:{};c.__open=i;try{Object.defineProperty(t,"runtimeAttributes",{value:c,configurable:!0,writable:!0,enumerable:!1})}catch{t.runtimeAttributes=c}Object.prototype.hasOwnProperty.call(e,"__entityRef")||Object.defineProperty(e,"__entityRef",{...n,value:t});let m;if(Object.prototype.hasOwnProperty.call(e,"persistentData")){m=e.persistentData;try{delete e.persistentData}catch{}}m&&typeof m=="object"?t.persistentData=z(m):(!t.persistentData||typeof t.persistentData!="object")&&(t.persistentData={}),Object.defineProperty(e,"persistentData",{...n,get:u(()=>t.persistentData||(t.persistentData={}),"get"),set:u(a=>{const y=a&&typeof a=="object"?a:{};t.persistentData=y},"set")}),Object.defineProperty(e,"__open",{...n,get:u(()=>t.runtimeAttributes.__open!==!1,"get"),set:u(a=>{const y=a!==!1;t.runtimeAttributes.__open=y,t.__open=y},"set")}),t.type&&!e.type&&(e.type=t.type),t.entityType=t.type||e.type||t.entityType||null},"#linkEntryParams"),Re=u(function(t,e){if(!(!t||!e))for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const r=e[n];if(!r||r.type!=="number")continue;const s=on(this.partHistory,t[n]);s!=null&&(t[n]=s)}},"#applyNumericExpressions"),Xt=u(function(){const t=new Map;for(const n of this.constraints){if(!n)continue;const r=A(this,x,ve).call(this,n?.type);if(!r)continue;const s=A(this,x,ze).call(this,n?.inputParams);if(!s)continue;t.has(s)||t.set(s,[]);const i=dt(n)||null,c=ge[r]||r;t.get(s).push({entry:n,type:r,typeLabel:c,id:i})}const e=new Map;for(const[n,r]of t.entries()){if(!Array.isArray(r)||r.length<=1)continue;const s=new Map;for(const i of r)s.has(i.type)||s.set(i.type,[]),s.get(i.type).push(i);for(const i of r){const c=(s.get(i.type)||[]).filter(h=>h!==i),m=[];for(const[h,d]of s.entries())h!==i.type&&m.push({type:h,entries:d});const a=u((h,d)=>{const g=Array.from(new Set(d.map(p=>p&&p.trim()?p.trim():null).filter(Boolean)));if(g.length===0)return`${h} constraint`;const S=g.length>1?"constraints":"constraint";return`${h} ${S} ${g.join(", ")}`},"formatConstraintPhrase"),y=[];if(c.length){const h=c.map(d=>d.id);y.push(a(`shares selections with ${i.typeLabel}`,h))}for(const h of m){const d=ge[h.type]||h.type,g=h.entries.map(S=>S.id);y.push(a(`conflicts with ${d}`,g))}const f=y.length?`Duplicate constraint selections: ${y.join(". ")}.`:"Duplicate constraint selections.",l=r.filter(h=>h!==i).map(h=>h.id).filter(Boolean);e.set(i.entry,{message:f,signature:n,relatedIds:Array.from(new Set(l)),type:i.type})}}return e},"#detectDuplicateConstraints"),ve=u(function(t){const e=W(t).toLowerCase();return e&&ln.get(e)||null},"#normalizeDuplicateConstraintType"),rt=u(function(t=null){if(!this.partHistory)return;const e=t&&typeof t=="object"?{...t}:null;this._autoRunOptions=e,!this._autoRunScheduled&&(this._autoRunScheduled=!0,Promise.resolve().then(()=>{try{A(this,x,Kt).call(this)}catch(n){console.warn("[AssemblyConstraintHistory] Failed to schedule auto run:",n)}}))},"#scheduleAutoRun"),Kt=u(async function(){if(!this._autoRunScheduled||this._autoRunActive)return;const t=this._autoRunOptions?{...this._autoRunOptions}:{};this._autoRunOptions=null,this._autoRunScheduled=!1;const e=Number(t.iterations),n=Number.isFinite(e)&&e>=1?Math.floor(e):pn,r=this.partHistory;if(r){this._autoRunActive=!0;try{await this.runAll(r,{...t,iterations:n})}catch(s){console.warn("[AssemblyConstraintHistory] Auto run failed:",s)}finally{this._autoRunActive=!1,this._autoRunScheduled&&Promise.resolve().then(()=>{try{A(this,x,Kt).call(this)}catch(s){console.warn("[AssemblyConstraintHistory] Failed to re-run auto cycle:",s)}})}}},"#executeAutoRun"),ze=u(function(t){if(!t||typeof t!="object")return null;const e=A(this,x,ke).call(this,t);if(!e)return null;const n=[];for(const r of e){const s=A(this,x,gt).call(this,r,0,new Set);if(!s)return null;n.push(s)}return n.length!==2?null:(n.sort(),`${n[0]}|${n[1]}`)},"#buildSelectionSignature"),ke=u(function(t){const e=Array.isArray(t?.elements)?t.elements:[],n=[];for(const r of e)if(r!=null&&(n.push(r),n.length>=2))break;return n.length>=2?n.slice(0,2):null},"#extractSelectionPair"),gt=u(function(t,e=0,n=new Set){if(t==null||e>5)return null;if(Array.isArray(t)){for(const s of t){const i=A(this,x,gt).call(this,s,e+1,n);if(i)return i}return null}const r=typeof t;if(r==="string"||r==="number"||r==="boolean")return`${r}:${String(t)}`;if(r!=="object"||n.has(t))return null;n.add(t);try{if(t.isObject3D&&typeof t.uuid=="string"&&t.uuid)return`uuid:${t.uuid}`;const s=["selectionID","selectionId","fullName","fullPath","pathKey","pathId","pathID","id","uuid","entityUUID","brepId","brepID","objectUUID","objectId","objectID"];for(const a of s){const y=t[a];if(typeof y=="string"&&y.trim())return`${a}:${y.trim()}`}const i=["name","label","displayName","componentName","faceName","edgeName","vertexName","reference","refName"];for(const a of i){const y=t[a];if(typeof y=="string"&&y.trim())return`${a}:${y.trim()}`}if(Array.isArray(t.path)&&t.path.length){const a=t.path.map(y=>String(y)).join("/");if(a)return`path:${a}`}if(t.component&&typeof t.component=="object"){const a=A(this,x,gt).call(this,t.component,e+1,n);if(a)return`component:${a}`}if(t.object&&typeof t.object=="object"){const a=A(this,x,gt).call(this,t.object,e+1,n);if(a)return`object:${a}`}const c=Object.keys(t).filter(a=>a!=="__proto__").sort(),m=[];for(const a of c){const y=t[a];if(y==null||typeof y=="function"||typeof y=="symbol")continue;let f=null;if(typeof y=="object"){const l=A(this,x,gt).call(this,y,e+1,n);l&&(f=l)}else f=`${typeof y}:${String(y)}`;if(f&&(m.push(`${a}=${f}`),m.length>=8))break}return m.length?`obj:${m.join(",")}`:null}finally{n.delete(t)}},"#selectionKey"),Yt=u(function(t,e,n){const r=e&&typeof e=="object"?e:{},s=!!r.satisfied,i=!!r.applied,c=r.ok!==!1,m=typeof r.message=="string"?r.message:"";let a=typeof r.status=="string"&&r.status.trim()?r.status.trim():null;a||(c?s?a="satisfied":i?a="adjusted":a="pending":a="error");const y=Number.isFinite(r.error)?r.error:null,f=r.persistInputParams&&typeof r.persistInputParams=="object"?z(r.persistInputParams):null;return t&&(t.persistentData=t.persistentData||{},t.persistentData.status||(t.persistentData.status=a),m&&!t.persistentData.message&&(t.persistentData.message=m),t.persistentData.satisfied=s,y!=null&&(t.persistentData.error=y),t.persistentData.isNewConstraint===!0&&c&&i&&(t.persistentData.isNewConstraint=!1)),{ok:c,status:a,satisfied:s,applied:i,error:y,message:m,iteration:n,diagnostics:r.diagnostics||null,persistInputParams:f}},"#finalizeConstraintResult"),It=u(function(t){const e=W(t);if(!e)return null;if(this.registry&&typeof this.registry.getSafe=="function"){const n=this.registry.getSafe(e);if(n)return n}if(this.registry&&typeof this.registry.get=="function")try{return this.registry.get(e)}catch{return null}return null},"#resolveConstraint"),U=u(function(t="update",e=null,n=null){if(!(this._listeners instanceof Set)||this._listeners.size===0)return;const r={...n&&typeof n=="object"?n:{},history:this,entry:e||null,reason:t||"update"};for(const s of Array.from(this._listeners))try{s({...r})}catch{}},"#emitChange"),u(oe,"AssemblyConstraintHistory");let Wt=oe;const ae=class ae{constructor(){this.metadata={}}getMetadata(t){const e=this.metadata[t]||{};return e.inheritsFrom?{...this.getMetadata(e.inheritsFrom),...e}:e}getOwnMetadata(t){const e=this.metadata[t];return e?{...e}:{}}setMetadata(t,e,n){this.metadata[t]||(this.metadata[t]={}),this.metadata[t][e]=n}setMetadataObject(t,e){e&&Object.keys(e).length>0?this.metadata[t]={...e}:delete this.metadata[t]}deleteMetadataKey(t,e){const n=this.metadata[t];n&&(delete n[e],Object.keys(n).length===0&&delete this.metadata[t])}clearMetadata(t){delete this.metadata[t]}};u(ae,"MetadataManager");let zt=ae;const ce=class ce{constructor(t){this.partHistory=t||null,this.views=[],this._listeners=new Set}reset(){this.views=[],this._emit()}getViews(){return this._normalizeViewsArray(this.views),this.views}setViews(t){const e=Array.isArray(t)?Array.from(t):[];return this.views=e,this._normalizeViewsArray(this.views),this._emit(),this.views}addView(t){const e=this.getViews(),n=this._normalizeView(t,e.length);return e.push(n),this._emit(),n}updateView(t,e){const n=this.getViews(),r=Number(t);if(!Number.isInteger(r)||r<0||r>=n.length)return null;const s=n[r];let i=s;if(typeof e=="function")try{const c=e(s);c&&typeof c=="object"&&(i=c)}catch{}else e&&typeof e=="object"&&e!==s&&(i=Object.assign({},s,e));return i!==s&&(n[r]=i),n[r]=this._normalizeView(n[r],r),this._emit(),n[r]}removeView(t){const e=this.getViews(),n=Number(t);if(!Number.isInteger(n)||n<0||n>=e.length)return null;const[r]=e.splice(n,1);for(let s=0;s<e.length;s++)e[s]=this._normalizeView(e[s],s);return this._emit(),r||null}addListener(t){return typeof t!="function"?()=>{}:(this._listeners.add(t),()=>{try{this._listeners.delete(t)}catch{}})}removeListener(t){if(typeof t=="function")try{this._listeners.delete(t)}catch{}}notifyChanged(){this._emit()}toSerializable(){return this.getViews().map(t=>z(t))}_normalizeViewsArray(t){if(!Array.isArray(t))return this.views=[],this.views;for(let e=0;e<t.length;e++)t[e]=this._normalizeView(t[e],e);return t}_normalizeView(t,e){const n=Number.isInteger(e)?e:0,r=t&&typeof t=="object"?t:{},s=typeof r.name=="string"?r.name.trim():"",c=(typeof r.viewName=="string"?r.viewName.trim():"")||s||`View ${n+1}`;if(r.viewName=c,r.name=c,Array.isArray(r.annotations)||(r.annotations=[]),(!r.camera||typeof r.camera!="object")&&(r.camera={}),r.camera.viewport&&typeof r.camera.viewport=="object"){const y=Number(r.camera.viewport.width),f=Number(r.camera.viewport.height);y>0&&f>0?r.camera.viewport={width:y,height:f}:delete r.camera.viewport}(!r.viewSettings||typeof r.viewSettings!="object")&&(r.viewSettings={});const m=Number(r.viewSettings?.pmiTextSizePt);Number.isFinite(m)&&m>0?r.viewSettings.pmiTextSizePt=Math.max(1,Math.min(288,m)):delete r.viewSettings.pmiTextSizePt;const a=Array.isArray(r.viewSettings?.visibilityState?.hidden)?r.viewSettings.visibilityState.hidden.map(y=>({key:String(y?.key||""),count:Math.max(1,Math.round(Number(y?.count)||1))})).filter(y=>y.key):[];return a.length?r.viewSettings.visibilityState={hidden:a}:delete r.viewSettings.visibilityState,r.annotationHistory&&typeof r.annotationHistory!="object"&&delete r.annotationHistory,r}_emit(){if(!this._listeners||this._listeners.size===0)return;const t=this.getViews();for(const e of Array.from(this._listeners))try{e(t,this.partHistory||null)}catch{}}};u(ce,"PMIViewsManager");let Gt=ce;const yt=96,Oe=1;function gn(o,t=0){const e=Number(o);return Number.isFinite(e)?e:t}u(gn,"toFiniteNumber$3");function qt(o,t){return Math.max(Oe,gn(o,t))}u(qt,"clampCustomSheetSize");function we(o){const t=Math.round(qt(o,Oe)*100)/100;return String(t).replace(/(\.\d*?[1-9])0+$/u,"$1").replace(/\.0+$/u,"")}u(we,"formatSheetDimension");const Zt=Object.freeze({A:Object.freeze({key:"A",label:"A (8.5 x 11 in)",widthIn:8.5,heightIn:11}),B:Object.freeze({key:"B",label:"B (11 x 17 in)",widthIn:11,heightIn:17}),C:Object.freeze({key:"C",label:"C (17 x 22 in)",widthIn:17,heightIn:22}),D:Object.freeze({key:"D",label:"D (22 x 34 in)",widthIn:22,heightIn:34}),E:Object.freeze({key:"E",label:"E (34 x 44 in)",widthIn:34,heightIn:44}),A4:Object.freeze({key:"A4",label:"A4 (210 x 297 mm)",widthIn:8.27,heightIn:11.69}),A3:Object.freeze({key:"A3",label:"A3 (297 x 420 mm)",widthIn:11.69,heightIn:16.54}),A2:Object.freeze({key:"A2",label:"A2 (420 x 594 mm)",widthIn:16.54,heightIn:23.39}),A1:Object.freeze({key:"A1",label:"A1 (594 x 841 mm)",widthIn:23.39,heightIn:33.11}),A0:Object.freeze({key:"A0",label:"A0 (841 x 1189 mm)",widthIn:33.11,heightIn:46.81}),CUSTOM:Object.freeze({key:"CUSTOM",label:"Custom",widthIn:36,heightIn:24})}),bn=Object.freeze(["A","B","C","D","E","A4","A3","A2","A1","A0","CUSTOM"]);function Me(o){return String(o??"").trim().toLowerCase()==="portrait"?"portrait":"landscape"}u(Me,"normalizeSheetOrientation");function Te(o){const t=String(o??"").trim().toUpperCase();return Zt[t]||Zt.A}u(Te,"getSheetSizeByKey");function Wn(){return bn.map(o=>Zt[o]).filter(Boolean)}u(Wn,"listSheetSizes");function Sn(o,t="landscape",e=null){const n=Te(o),r=Me(t);if(n.key==="CUSTOM"){const m=qt(e?.customWidthIn??e?.widthIn,n.widthIn),a=qt(e?.customHeightIn??e?.heightIn,n.heightIn),y=r==="landscape",f=y?Math.max(m,a):Math.min(m,a),l=y?Math.min(m,a):Math.max(m,a);return{key:n.key,label:`Custom (${we(f)} x ${we(l)} in)`,orientation:r,units:"in",widthIn:f,heightIn:l,widthPx:f*yt,heightPx:l*yt,pxPerInch:yt,customWidthIn:f,customHeightIn:l}}const s=r==="landscape",i=s?Math.max(n.widthIn,n.heightIn):Math.min(n.widthIn,n.heightIn),c=s?Math.min(n.widthIn,n.heightIn):Math.max(n.widthIn,n.heightIn);return{key:n.key,label:n.label,orientation:r,units:"in",widthIn:i,heightIn:c,widthPx:i*yt,heightPx:c*yt,pxPerInch:yt}}u(Sn,"resolveSheetDimensions");function _t(o,t=0){const e=Number(o);return Number.isFinite(e)?e:t}u(_t,"toFiniteNumber$2");function Z(o,t,e){return Math.max(t,Math.min(e,o))}u(Z,"clamp$1");function it(o,t=""){return typeof o=="string"?o:o==null?t:String(o)}u(it,"sanitizeText$1");function wn(o,t=null){const e=String(o??"").trim();return e&&(/^#[\da-fA-F]{3,8}$/.test(e)||/^[a-zA-Z]+$/.test(e)||/^(rgb|rgba|hsl|hsla)\([^)]+\)$/i.test(e))?e:t}u(wn,"sanitizeColor$1");function M(o,t=1){return Math.max(1,Math.round(_t(o,t)))}u(M,"clampPositiveInt");function K(o,t=0){return Math.max(0,Math.round(_t(o,t)))}u(K,"clampIndex");function An(o,t=null){if(o==null)return t;const e=String(o).trim().toLowerCase();return e==="middle"||e==="center"?"center":e==="end"||e==="right"?"right":e==="left"?"left":t}u(An,"normalizeTextAlign$1");function In(o,t=null){if(o==null)return t;const e=String(o).trim().toLowerCase();return e==="center"?"middle":e==="bottom"?"bottom":e==="middle"||e==="top"?e:t}u(In,"normalizeVerticalAlign$1");function xn(o,t=null){if(o==null)return t;const e=String(o).trim();return e==="bold"?"700":e==="normal"?"400":/^\d{3}$/.test(e)?e:t}u(xn,"normalizeFontWeight");function Cn(o,t=null){return o==null?t:String(o).trim().toLowerCase()==="italic"?"italic":"normal"}u(Cn,"normalizeFontStyle");function _n(o,t=null){return o==null?t:String(o).trim().toLowerCase()==="underline"?"underline":"none"}u(_n,"normalizeTextDecoration");function ie(o){if(!o||typeof o!="object"||Array.isArray(o))return{};const t={},e=it(o.fontFamily,"").trim();e&&(t.fontFamily=e);const n=_t(o.fontSize,Number.NaN);Number.isFinite(n)&&n>0&&(t.fontSize=Z(n,.08,3));const r=xn(o.fontWeight??(o.bold?"700":null));r&&(t.fontWeight=r);const s=Cn(o.fontStyle??(o.italic?"italic":null));s&&(t.fontStyle=s);const i=_n(o.textDecoration);i&&(t.textDecoration=i);const c=An(o.textAlign??o.textAnchor);c&&(t.textAlign=c);const m=In(o.verticalAlign??o.verticalAnchor);m&&(t.verticalAlign=m);const a=wn(o.color??o.textColor,null);return a&&(t.color=a),t}u(ie,"normalizeTableCellStyle");function je(o=""){return{text:it(o,""),rowSpan:1,colSpan:1,mergedInto:null,style:{}}}u(je,"createTableCell");function ut(o,t){const e=Math.max(1,M(t,1)),n=Array.isArray(o)?o.slice(0,e):[],r=[];for(let i=0;i<e;i+=1)r.push(Math.max(1e-4,_t(n[i],1)));const s=r.reduce((i,c)=>i+c,0);return!Number.isFinite(s)||s<=0?Array.from({length:e},()=>1/e):r.map(i=>i/s)}u(ut,"normalizeTableFractions");function bt(o,t=0){return Array.isArray(o?.cells)&&o.cells.length>0?o.cells.length:Array.isArray(o?.rowFractions)&&o.rowFractions.length>0?o.rowFractions.length:Math.max(0,M(t,0))}u(bt,"getTableRowCount");function St(o,t=0){const e=Array.isArray(o?.cells)?o.cells:[];let n=0;for(const r of e)Array.isArray(r)&&(n=Math.max(n,r.length));return n>0?n:Array.isArray(o?.colFractions)&&o.colFractions.length>0?o.colFractions.length:Math.max(0,M(t,0))}u(St,"getTableColumnCount");function Ee(o=3,t=3){const e=Math.max(1,M(o,3)),n=Math.max(1,M(t,3));return{rowFractions:ut(null,e),colFractions:ut(null,n),cells:Array.from({length:e},()=>Array.from({length:n},()=>je()))}}u(Ee,"createTableData");function Nt(o,t=3,e=3){const n=Math.max(1,bt(o,t)),r=Math.max(1,St(o,e)),s=Ee(n,r);s.rowFractions=ut(o?.rowFractions,n),s.colFractions=ut(o?.colFractions,r);const i=Array.isArray(o?.cells)?o.cells:[],c=[];for(let a=0;a<n;a+=1)for(let y=0;y<r;y+=1){const f=Array.isArray(i[a])?i[a][y]:null,l=s.cells[a][y];f&&typeof f=="object"&&!Array.isArray(f)?(l.text=it(f.text,it(f.value,"")),l.style=ie(f.style&&typeof f.style=="object"?f.style:f),c.push({row:a,col:y,rowSpan:M(f.rowSpan,1),colSpan:M(f.colSpan,1)})):(l.text=it(f,""),l.style={}),l.rowSpan=1,l.colSpan=1,l.mergedInto=null}const m=Array.from({length:n},()=>Array.from({length:r},()=>!1));for(const a of c){const y=Z(a.rowSpan,1,n-a.row),f=Z(a.colSpan,1,r-a.col);if(y===1&&f===1)continue;let l=!1;for(let d=a.row;d<a.row+y&&!l;d+=1)for(let g=a.col;g<a.col+f;g+=1)if(!(d===a.row&&g===a.col)&&m[d][g]){l=!0;break}if(l)continue;const h=s.cells[a.row][a.col];h.rowSpan=y,h.colSpan=f;for(let d=a.row;d<a.row+y;d+=1)for(let g=a.col;g<a.col+f;g+=1)d===a.row&&g===a.col||(m[d][g]=!0,s.cells[d][g]={text:"",rowSpan:1,colSpan:1,mergedInto:{row:a.row,col:a.col},style:{}})}return s}u(Nt,"normalizeTableData");function Ct(o,t,e){return Array.isArray(o?.cells?.[t])&&o.cells[t][e]||null}u(Ct,"getTableCell");function He(o,t,e){const n=Ct(o,t,e);if(!n)return null;const r=n?.mergedInto;if(r&&Number.isInteger(r.row)&&Number.isInteger(r.col)){const s=Ct(o,r.row,r.col);if(s)return{row:r.row,col:r.col,cell:s}}return{row:t,col:e,cell:n}}u(He,"resolveTableCellAnchor");function Bn(o){if(!o)return null;const t=[o.anchorRow,o.focusRow].map(n=>K(n,0)),e=[o.anchorCol,o.focusCol].map(n=>K(n,0));return{minRow:Math.min(...t),maxRow:Math.max(...t),minCol:Math.min(...e),maxCol:Math.max(...e)}}u(Bn,"getTableSelectionRect");function kt(o,t=3,e=3){const n=Nt(o,t,e);return{rowFractions:n.rowFractions.slice(),colFractions:n.colFractions.slice(),cells:n.cells.map(r=>r.map(s=>({text:it(s?.text,""),rowSpan:M(s?.rowSpan,1),colSpan:M(s?.colSpan,1),mergedInto:s?.mergedInto&&Number.isInteger(s.mergedInto.row)&&Number.isInteger(s.mergedInto.col)?{row:s.mergedInto.row,col:s.mergedInto.col}:null,style:ie(s?.style)})))}}u(kt,"cloneTableData");function Nn(o,t){if(typeof t!="function")return;const e=Nt(o),n=bt(e,0),r=St(e,0);for(let s=0;s<n;s+=1)for(let i=0;i<r;i+=1){const c=Ct(e,s,i);!c||c?.mergedInto||t(c,s,i,e)}}u(Nn,"forEachTableAnchor");function Xn(o,t,e,n){const r=kt(o),s=He(r,K(t,0),K(e,0));return s?.cell&&(s.cell.text=it(n,"")),r}u(Xn,"setTableCellText");function Dn(o,t){const e=Nt(o),n=t||null;if(!n)return!1;const r=bt(e,0),s=St(e,0),i=Z(n.minRow,0,Math.max(0,r-1)),c=Z(n.maxRow,i,Math.max(0,r-1)),m=Z(n.minCol,0,Math.max(0,s-1)),a=Z(n.maxCol,m,Math.max(0,s-1));if(i===c&&m===a)return!1;for(let y=i;y<=c;y+=1)for(let f=m;f<=a;f+=1){const l=Ct(e,y,f);if(!l||l?.mergedInto||M(l.rowSpan,1)!==1||M(l.colSpan,1)!==1)return!1}return!0}u(Dn,"canMergeTableCells");function Kn(o,t){const e=kt(o),n=t||null;if(!n||!Dn(e,n))return e;const r=K(n.minRow,0),s=Math.max(r,K(n.maxRow,r)),i=K(n.minCol,0),c=Math.max(i,K(n.maxCol,i)),m=Ct(e,r,i);if(!m)return e;m.rowSpan=s-r+1,m.colSpan=c-i+1,m.mergedInto=null;for(let a=r;a<=s;a+=1)for(let y=i;y<=c;y+=1)a===r&&y===i||(e.cells[a][y]={text:"",rowSpan:1,colSpan:1,mergedInto:{row:r,col:i},style:{}});return e}u(Kn,"mergeTableCells");function Yn(o,t,e){const n=kt(o),r=He(n,K(t,0),K(e,0));if(!r?.cell)return n;const s=M(r.cell.rowSpan,1),i=M(r.cell.colSpan,1);if(s===1&&i===1)return n;r.cell.rowSpan=1,r.cell.colSpan=1,r.cell.mergedInto=null;for(let c=r.row;c<r.row+s;c+=1)for(let m=r.col;m<r.col+i;m+=1)c===r.row&&m===r.col||(n.cells[c][m]=je(""));return n}u(Yn,"unmergeTableCell");function Ae(o,t){const e=Array.isArray(o)?o.slice():[1],n=e.length;if(n<=0)return[1];const r=Z(t,0,n),s=Z(r===n?n-1:r,0,n-1),i=Math.max(1e-4,_t(e[s],1/n)),c=Math.max(1e-4,i*.5);return e[s]=Math.max(1e-4,i-c),e.splice(r,0,c),ut(e,e.length)}u(Ae,"splitFractionList");function $e(o,{rowInsertIndex:t=null,colInsertIndex:e=null}={}){const n=Nt(o),r=bt(n,1),s=St(n,1),i=t==null?r:r+1,c=e==null?s:s+1,m=t==null?-1:Z(t,0,r),a=e==null?-1:Z(e,0,s),y=Ee(i,c);return y.rowFractions=t==null?ut(n.rowFractions,r):Ae(n.rowFractions,m),y.colFractions=e==null?ut(n.colFractions,s):Ae(n.colFractions,a),Nn(n,(f,l,h)=>{const d=m>=0&&l>=m?l+1:l,g=a>=0&&h>=a?h+1:h,S=m>=0&&l<m&&l+M(f.rowSpan,1)>m?M(f.rowSpan,1)+1:M(f.rowSpan,1),p=a>=0&&h<a&&h+M(f.colSpan,1)>a?M(f.colSpan,1)+1:M(f.colSpan,1);y.cells[d][g]={text:it(f.text,""),rowSpan:S,colSpan:p,mergedInto:null,style:ie(f.style)};for(let b=d;b<d+S;b+=1)for(let w=g;w<g+p;w+=1)b===d&&w===g||(y.cells[b][w]={text:"",rowSpan:1,colSpan:1,mergedInto:{row:d,col:g},style:{}})}),y}u($e,"buildInsertedTable");function Pn(o,t){return $e(o,{rowInsertIndex:K(t,0)})}u(Pn,"insertTableRow");function Fn(o,t){return $e(o,{colInsertIndex:K(t,0)})}u(Fn,"insertTableColumn");function Gn(o,t=1,e=1){let n=kt(o,t,e);const r=Math.max(1,M(t,1)),s=Math.max(1,M(e,1));for(;bt(n,0)<r;)n=Pn(n,bt(n,0));for(;St(n,0)<s;)n=Fn(n,St(n,0));return n}u(Gn,"ensureTableSize");function R(o,t=0){const e=Number(o);return Number.isFinite(e)?e:t}u(R,"toFiniteNumber$1");function V(o,t=""){return typeof o=="string"?o:o==null?t:String(o)}u(V,"sanitizeText");function Q(o,t){const e=String(o??"").trim();return e&&(/^#[\da-fA-F]{3,8}$/.test(e)||/^[a-zA-Z]+$/.test(e)||/^(rgb|rgba|hsl|hsla)\([^)]+\)$/i.test(e))?e:t}u(Q,"sanitizeColor");function k(o,t,e){return Math.max(t,Math.min(e,o))}u(k,"clamp");function Et(o,t="left"){const e=String(o||t).trim().toLowerCase();return e==="middle"||e==="center"?"center":e==="end"||e==="right"?"right":"left"}u(Et,"normalizeTextAlign");function Ht(o,t="top"){const e=String(o||t).trim().toLowerCase();return e==="center"?"middle":e==="bottom"?"bottom":e==="middle"?"middle":"top"}u(Ht,"normalizeVerticalAlign");function Rn(o,t="c"){const e=String(o||t).trim().toLowerCase();return["nw","n","ne","w","c","e","sw","s","se"].includes(e)?e:t}u(Rn,"normalizePmiAnchor");function Ie(o,t="bottom"){const e=String(o||t).trim().toLowerCase();return["top","bottom","none"].includes(e)?e:t}u(Ie,"normalizePmiLabelPosition");function vn(o,t="shaded"){const e=String(o||t).trim().toLowerCase();return["shaded","monochrome"].includes(e)?e:t}u(vn,"normalizePmiRenderMode");function zn(o,t="solid"){const e=String(o||t).trim();return["none","solid","dotted","dashed","dashDot","longDash","dashDotDot"].includes(e)?e:t}u(zn,"normalizeLineStyle");function nt(o){return["rect","ellipse","triangle","diamond","pentagon","hexagon","parallelogram","trapezoid"].includes(String(o||""))}u(nt,"isShapeElementType");function Le(o){return["parallelogram","trapezoid"].includes(String(o||""))}u(Le,"shapeSupportsAdjustHandle");function kn(o){return Le(o)?.18:0}u(kn,"getDefaultShapeAdjust");function On(o,t){return Le(o)?k(R(t,kn(o)),0,.45):0}u(On,"clampShapeAdjust");function Mn(o){const t=String(o??"").trim().toLowerCase();return t==="rect"?"rect":t==="ellipse"?"ellipse":t==="triangle"?"triangle":t==="diamond"?"diamond":t==="pentagon"?"pentagon":t==="hexagon"?"hexagon":t==="parallelogram"?"parallelogram":t==="trapezoid"?"trapezoid":t==="table"?"table":t==="image"?"image":t==="line"?"line":t==="pmiinset"||t==="pmi_inset"||t==="pmi"||t==="pmiview"?"pmiInset":"text"}u(Mn,"normalizeElementType");const le=class le{constructor(t){this.partHistory=t||null,this.sheets=[],this._listeners=new Set}reset(){this.sheets=[],this._emit()}getSheets(){return this._normalizeSheetsArray(this.sheets),this.sheets}getSheetById(t){const e=String(t??"").trim();return e&&this.getSheets().find(n=>String(n?.id||"")===e)||null}setSheets(t){const e=Array.isArray(t)?Array.from(t):[];return this.sheets=e,this._normalizeSheetsArray(this.sheets),this._emit(),this.sheets}createSheet(t={}){const e=this.getSheets(),n=this._normalizeSheet({...t,id:t?.id||this._generateSheetId()},e.length);return e.push(n),this._emit(),n}duplicateSheet(t){const e=this._resolveSheetIndex(t);if(e<0)return null;const n=this.getSheets()[e],r=z(n)||{};r.id=this._generateSheetId(),r.name=`${V(n?.name,"Sheet")} Copy`,r.elements=Array.isArray(r.elements)?r.elements.map(i=>({...i||{},id:this._generateElementId(r.id)})):[];const s=this._normalizeSheet(r,this.sheets.length);return this.sheets.push(s),this._emit(),s}updateSheet(t,e){const n=this._resolveSheetIndex(t);if(n<0)return null;const r=this.sheets[n];let s=r;if(typeof e=="function")try{const i=e(z(r));i&&typeof i=="object"&&(s=i)}catch{s=r}else e&&typeof e=="object"&&(s={...r,...e});return this.sheets[n]=this._normalizeSheet(s,n,r?.id),this._emit(),this.sheets[n]}moveSheet(t,e){const n=this._resolveSheetIndex(t);if(n<0)return null;const r=this.getSheets(),s=k(Math.round(R(e,n)),0,Math.max(0,r.length-1));if(s===n)return r[n]||null;const[i]=r.splice(n,1);return i?(r.splice(s,0,i),this._normalizeSheetsArray(r),this._emit(),i):null}removeSheet(t){const e=this._resolveSheetIndex(t);if(e<0)return null;const[n]=this.sheets.splice(e,1);return this._normalizeSheetsArray(this.sheets),this._emit(),n||null}addListener(t){return typeof t!="function"?()=>{}:(this._listeners.add(t),()=>{try{this._listeners.delete(t)}catch{}})}removeListener(t){if(typeof t=="function")try{this._listeners.delete(t)}catch{}}notifyChanged(){this._emit()}toSerializable(){return this.getSheets().map(t=>z(t))}_resolveSheetIndex(t){if(Number.isInteger(t)){const n=Number(t);return n>=0&&n<this.getSheets().length?n:-1}const e=String(t??"").trim();return e?this.getSheets().findIndex(n=>String(n?.id||"")===e):-1}_generateSheetId(){const t=new Set(this.getSheets().map(n=>String(n?.id||"")));let e=1;for(;t.has(`sheet-${e}`);)e+=1;return`sheet-${e}`}_generateElementId(t="sheet"){return`${String(t||"sheet").replace(/[^A-Za-z0-9_-]/g,"_")}:el:${Date.now().toString(36)}:${Math.random().toString(36).slice(2,7)}`}_normalizeSheetsArray(t){if(!Array.isArray(t))return this.sheets=[],this.sheets;for(let e=0;e<t.length;e++){const n=t[e]?.id;t[e]=this._normalizeSheet(t[e],e,n)}return t}_normalizeSheet(t,e,n=null){const r=t&&typeof t=="object"?t:{},s=Te(r.sizeKey),i=Me(r.orientation),c=Math.max(1,R(r.customWidthIn??r.widthIn,s.widthIn)),m=Math.max(1,R(r.customHeightIn??r.heightIn,s.heightIn)),a=Sn(s.key,i,{customWidthIn:c,customHeightIn:m}),y=V(n||r.id||this._generateSheetId(),"").trim()||this._generateSheetId(),f=V(r.name,"").trim()||`Sheet ${e+1}`,l=Array.isArray(r.elements)?r.elements:[],h=[],d=new Set;for(let g=0;g<l.length;g++){const S=this._normalizeElement(l[g],g,y,a);S&&(d.has(S.id)&&(S.id=this._generateElementId(y)),d.add(S.id),h.push(S))}return{id:y,name:f,sizeKey:a.key,sizeLabel:a.label,orientation:a.orientation,units:a.units,widthIn:a.widthIn,heightIn:a.heightIn,customWidthIn:a.key==="CUSTOM"?a.widthIn:void 0,customHeightIn:a.key==="CUSTOM"?a.heightIn:void 0,widthPx:a.widthPx,heightPx:a.heightPx,pxPerInch:a.pxPerInch,background:Q(r.background,"#ffffff"),elements:h,metadata:{createdAt:Number.isFinite(Number(r?.metadata?.createdAt))?Number(r.metadata.createdAt):Date.now(),updatedAt:Date.now()}}}_normalizeElement(t,e,n,r){const s=t&&typeof t=="object"?t:{},i=Mn(s.type),c=Math.max(.1,R(r?.widthIn,11)),m=Math.max(.1,R(r?.heightIn,8.5)),a=-c*2,y=-m*2,f=c*3,l=m*3,h=k(R(s.x,c*.1),a,f),d=k(R(s.y,m*.1),y,l),g=V(s.id,"").trim()||this._generateElementId(n),S=Number.isInteger(s.z)?s.z:Number.isInteger(s.layer)?s.layer:e,p={id:g,type:i,groupId:V(s.groupId,"").trim()||void 0,formboard:s.formboard&&typeof s.formboard=="object"?z(s.formboard):void 0,x:h,y:d,rotationDeg:R(s.rotationDeg,0),z:Number.isFinite(Number(S))?Number(S):e,fill:Q(s.fill,i==="text"||i==="pmiInset"?"transparent":i==="table"?"#ffffff":"#dbeafe"),stroke:Q(s.stroke,i==="table"?"#0f172a":"#1d4ed8"),strokeWidth:k(R(s.strokeWidth,.02),.002,1),lineStyle:zn(s.lineStyle,"solid"),opacity:k(R(s.opacity,1),0,1)};if(i==="line"){const tt=k(R(s.x2,h+1),a,f),E=k(R(s.y2,d),y,l);return{...p,x2:tt,y2:E,strokeWidth:k(R(s.strokeWidth,.035),.002,1)}}const b=Number.isFinite(Number(s.w)),w=Number.isFinite(Number(s.h)),C=R(b?s.w:s.width??(s.radiusX!=null?R(s.radiusX,.8)*2:1.4),1.4),D=R(w?s.h:s.height??(s.radiusY!=null?R(s.radiusY,.55)*2:.9),.9),O=k(C,.05,c*8),j=k(D,.05,m*8),H=!b&&!w&&Number.isFinite(Number(s.width))&&Number.isFinite(Number(s.height)),ot=!b&&!w&&Number.isFinite(Number(s.radiusX))&&Number.isFinite(Number(s.radiusY)),ft=k(H||ot?R(s.x,c*.5)-O*.5:h,a,f),J=k(H||ot?R(s.y,m*.5)-j*.5:d,y,l);if(i==="table"){const tt=String(s.fontStyle||(s.italic?"italic":"normal")).toLowerCase()==="italic"?"italic":"normal",E=String(s.fontWeight||(s.bold?"700":"400"));return{...p,x:ft,y:J,w:k(C,.4,c*8),h:k(D,.3,m*8),tableData:Nt(s.tableData,s.rows??3,s.cols??4),fontSize:k(R(s.fontSize,.22),.08,3),fontFamily:V(s.fontFamily,"Arial, Helvetica, sans-serif"),fontWeight:/^\d{3}$/.test(E)?E:E==="bold"?"700":"400",fontStyle:tt,textDecoration:String(s.textDecoration||"none").toLowerCase()==="underline"?"underline":"none",textAlign:Et(s.textAlign||s.textAnchor,"left"),verticalAlign:Ht(s.verticalAlign||s.verticalAnchor,"middle"),color:Q(s.color,Q(s.textColor,"#111111"))}}if(nt(i)||i==="image"||i==="pmiInset"){const tt=String(s.fontStyle||(s.italic?"italic":"normal")).toLowerCase()==="italic"?"italic":"normal",E=String(s.fontWeight||(s.bold?"700":"400"));return{...p,x:ft,y:J,w:O,h:j,cornerRadius:k(R(s.cornerRadius,i==="rect"?.1:0),0,Math.min(O,j)*.5),shapeAdjust:On(i,s.shapeAdjust),src:i==="image"||i==="pmiInset"?V(s.src,""):void 0,mediaScale:i==="image"||i==="pmiInset"?k(R(s.mediaScale,1),1,10):void 0,mediaOffsetX:i==="image"||i==="pmiInset"?k(R(s.mediaOffsetX,0),-1,1):void 0,mediaOffsetY:i==="image"||i==="pmiInset"?k(R(s.mediaOffsetY,0),-1,1):void 0,pmiViewIndex:i==="pmiInset"?Number.isInteger(s.pmiViewIndex)?s.pmiViewIndex:-1:void 0,pmiViewName:i==="pmiInset"?V(s.pmiViewName,"PMI View"):void 0,pmiImageRevision:i==="pmiInset"?Number.isInteger(s.pmiImageRevision)?s.pmiImageRevision:0:void 0,pmiModelRevision:i==="pmiInset"?Number.isInteger(s.pmiModelRevision)?s.pmiModelRevision:-1:void 0,pmiImageCaptureKey:i==="pmiInset"?V(s.pmiImageCaptureKey,""):void 0,showTitle:i==="pmiInset"?Ie(s.pmiLabelPosition,s.showTitle!==!1?"bottom":"none")!=="none":void 0,pmiLabelPosition:i==="pmiInset"?Ie(s.pmiLabelPosition,s.showTitle!==!1?"bottom":"none"):void 0,pmiRenderMode:i==="pmiInset"?vn(s.pmiRenderMode,"shaded"):void 0,pmiShowCenterLines:i==="pmiInset"?s.pmiShowCenterLines===!0:void 0,pmiAnchor:i==="pmiInset"?Rn(s.pmiAnchor,"c"):void 0,text:nt(i)?V(s.text,""):void 0,fontSize:nt(i)?k(R(s.fontSize,.28),.08,3):void 0,fontFamily:nt(i)?V(s.fontFamily,"Arial, Helvetica, sans-serif"):void 0,fontWeight:nt(i)?/^\d{3}$/.test(E)?E:E==="bold"?"700":"400":void 0,fontStyle:nt(i)?tt:void 0,textAlign:nt(i)?Et(s.textAlign||s.textAnchor,"center"):void 0,verticalAlign:nt(i)?Ht(s.verticalAlign||s.verticalAnchor,"middle"):void 0,color:nt(i)?Q(s.color,Q(s.textColor,"#0f172a")):void 0}}const Y=Et(s.textAlign||s.textAnchor,"left"),G=String(s.fontStyle||(s.italic?"italic":"normal")).toLowerCase()==="italic"?"italic":"normal",q=String(s.fontWeight||(s.bold?"700":"400"));return{...p,w:k(R(b?s.w:s.width,3.2),.1,c*8),h:k(R(w?s.h:s.height,1.1),.1,m*8),text:V(s.text,`Text ${e+1}`),fontSize:k(R(s.fontSize,.32),.08,3),fontFamily:V(s.fontFamily,"Arial, Helvetica, sans-serif"),fontWeight:/^\d{3}$/.test(q)?q:q==="bold"?"700":"400",fontStyle:G,textAlign:Y,verticalAlign:Ht(s.verticalAlign||s.verticalAnchor,"top"),color:Q(s.color,Q(s.textColor,Q(s.fill,"#111111")))}}_emit(){if(!this._listeners||this._listeners.size===0)return;const t=this.getSheets();for(const e of Array.from(this._listeners))try{e(t,this.partHistory||null)}catch{}}};u(le,"Sheet2DManager");let Jt=le;function xt(o,t=0){const e=Number(o);return Number.isFinite(e)?e:t}u(xt,"toFiniteNumber");function B(o,t=""){return String(o??"").trim()||t}u(B,"normalizeText");function $t(o,t=0){const e=o&&typeof o=="object"?o:{},n=Number.isInteger(t)?t+1:1;return{id:B(e.id,`wire-${n}`),name:B(e.name,`Wire ${n}`),from:B(e.from,""),to:B(e.to,""),diameter:Math.max(.01,xt(e.diameter,1))}}u($t,"normalizeConnection");function Tn(o){return!Array.isArray(o)||o.length<3?null:[xt(o[0],0),xt(o[1],0),xt(o[2],0)]}u(Tn,"normalizePointArray");function xe(o){return Array.isArray(o)?o.map(t=>B(t,"")).filter(Boolean):[]}u(xe,"normalizeStringArray");function jn(o,t=new Map){const e=o&&typeof o=="object"?o:{},n=B(e.connectionId,""),r=t.get(n)||null,s=!!e.feasible;return{connectionId:n,connectionName:B(e.connectionName,r?.name||n||"Wire"),feasible:s,error:B(e.error,s?"":"No route found through the harness network."),distance:Number.isFinite(Number(e.distance))?Number(e.distance):null,polyline:(Array.isArray(e.polyline)?e.polyline:[]).map(i=>Tn(i)).filter(Boolean),segmentIds:xe(e.segmentIds),nodePath:xe(e.nodePath),reusesHarnessPoint:!!e.reusesHarnessPoint,diameter:Math.max(.01,xt(e.diameter,r?.diameter||1)),from:B(e.from,r?.from||""),to:B(e.to,r?.to||"")}}u(jn,"normalizeRouteResult");const ue=class ue{constructor(t){this.partHistory=t||null,this.connections=[],this.routeResults=[],this._pendingRestoredRouteResults=null,this._listeners=new Set}reset(){this.connections=[],this.routeResults=[],this._pendingRestoredRouteResults=null,this._emit()}getConnections(){return this._normalizeConnectionsArray(this.connections),this.connections}setConnections(t){const e=Array.isArray(t)?Array.from(t):[];return this.connections=e,this._normalizeConnectionsArray(this.connections),this._pendingRestoredRouteResults=null,this._emit(),this.connections}addConnection(t={}){const e=this.getConnections(),n=$t({id:t?.id||this._generateConnectionId(),...t},e.length);return e.push(n),this._emit(),n}updateConnection(t,e){const n=this.getConnections(),r=B(t,""),s=n.findIndex(m=>String(m?.id||"")===r);if(s<0)return null;const i=n[s];let c=i;if(typeof e=="function")try{const m=e(z(i));m&&typeof m=="object"&&(c=m)}catch{c=i}else e&&typeof e=="object"&&(c={...i,...e});return n[s]=$t(c,s),n[s].id||(n[s].id=i.id),this._emit(),n[s]}removeConnection(t){const e=this.getConnections(),n=B(t,""),r=e.findIndex(i=>String(i?.id||"")===n);if(r<0)return null;const[s]=e.splice(r,1);return this.routeResults=this.routeResults.filter(i=>String(i?.connectionId||"")!==n),this._normalizeConnectionsArray(e),this._emit(),s||null}getRouteResults(){return this._normalizeRouteResultsArray(this.routeResults),Array.isArray(this.routeResults)?this.routeResults:[]}setRouteResults(t,e={}){const n=!!e?.preservePendingRestore,r=!!e?.markPendingRestore;return this.routeResults=Array.isArray(t)?t.map(s=>({...s||{}})):[],this._normalizeRouteResultsArray(this.routeResults),r?this._pendingRestoredRouteResults=this.routeResults.map(s=>z(s)):n||(this._pendingRestoredRouteResults=null),this._emit(),this.routeResults}clearRouteResults(t={}){this.routeResults=[],t?.preservePendingRestore||(this._pendingRestoredRouteResults=null),this._emit()}getRouteResultMap(){const t=new Map;for(const e of this.getRouteResults()){const n=B(e?.connectionId,"");n&&t.set(n,e)}return t}addListener(t){return typeof t!="function"?()=>{}:(this._listeners.add(t),()=>{try{this._listeners.delete(t)}catch{}})}removeListener(t){if(typeof t=="function")try{this._listeners.delete(t)}catch{}}notifyChanged(){this._emit()}toSerializable(){return{connections:this.getConnections().map(t=>z(t)),routeResults:this.getRouteResults().map(t=>z(t))}}loadSerializable(t){const e=t&&typeof t=="object"&&!Array.isArray(t)?t:{connections:t,routeResults:[]};return this.connections=Array.isArray(e.connections)?Array.from(e.connections):[],this._normalizeConnectionsArray(this.connections),this.routeResults=Array.isArray(e.routeResults)?Array.from(e.routeResults):[],this._normalizeRouteResultsArray(this.routeResults),this._pendingRestoredRouteResults=this.routeResults.length?this.routeResults.map(n=>z(n)):null,this._emit(),this.toSerializable()}consumePendingRestoredRouteResults(){const t=Array.isArray(this._pendingRestoredRouteResults)?this._pendingRestoredRouteResults.map(e=>z(e)):null;return this._pendingRestoredRouteResults=null,t}_generateConnectionId(){const t=new Set(this.getConnections().map(n=>String(n?.id||"")));let e=1;for(;t.has(`wire-${e}`);)e+=1;return`wire-${e}`}_normalizeConnectionsArray(t){if(!Array.isArray(t))return this.connections=[],this.connections;for(let e=0;e<t.length;e+=1)t[e]=$t(t[e],e);return t}_normalizeRouteResultsArray(t){if(!Array.isArray(t))return this.routeResults=[],this.routeResults;const e=new Map(this.getConnections().map(n=>[String(n?.id||""),n]));for(let n=0;n<t.length;n+=1)t[n]=jn(t[n],e);return t}_emit(){if(!this._listeners||this._listeners.size===0)return;const t={connections:this.getConnections(),routeResults:this.getRouteResults(),manager:this,partHistory:this.partHistory||null};for(const e of Array.from(this._listeners))try{e(t)}catch{}}};u(ue,"WireHarnessManager");let Qt=ue;const Ce=!1,_e=new Set(["__open"]);function Lt(o,t=null){if(!o)return t;const e=o.inputParams||{},n=e.id??e.featureID??o.id??t;return n==null?t:String(n)}u(Lt,"resolveFeatureEntryId");function Ne(o){const t=o&&typeof o=="object"?o:{};try{const e=JSON.stringify(t,(n,r)=>{if(!(n&&_e.has(n)))return r});return e??""}catch{try{const e={};for(const[n,r]of Object.entries(t))_e.has(n)||(e[n]=r);return JSON.stringify(e)||""}catch{return""}}}u(Ne,"stringifyInputParamsForDirtyCheck");var P,Ue,Pt,Ve,We,ee,ne,re,Be,Ft,se,Rt,vt;const st=class st{constructor(){Mt(this,P);this.features=[],this.scene=new tn,this.idCounter=0,this.featureRegistry=new Qe,this.assemblyConstraintRegistry=new De,this.assemblyConstraintHistory=new Wt(this,this.assemblyConstraintRegistry),this.callbacks={},this._modelRevision=0,this._modelChangeListeners=new Set,this.currentHistoryStepId=null,this.runningFeatureId=null,this.expressions=`//Examples:
1
+ var qe=Object.defineProperty;var pe=o=>{throw TypeError(o)};var u=(o,t)=>qe(o,"name",{value:t,configurable:!0});var Ze=(o,t,e)=>t.has(o)||pe("Cannot "+e);var Mt=(o,t,e)=>t.has(o)?pe("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(o):t.set(o,e);var A=(o,t,e)=>(Ze(o,t,"access private method"),e);import{r as Je,F as Qe,A as et}from"./FeatureRegistry-C7MrfKHF.js";import{Q as Ut,V as T,a3 as tn,b6 as Tt,s as mt,a4 as Dt,Z as he,b7 as me,K as en,b0 as nn,b as jt}from"./featureDialogs-Bas0NDXF.js";import{A as De}from"./AssemblyConstraintRegistry-DJV0rHvz.js";import{d as z}from"./deepClone-Dj59xCHB.js";import{e as rn,o as sn}from"./browserStorage-CvgF8ovw.js";function on(o,t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;let e=null;try{o&&typeof o.evaluateExpression=="function"&&(e=o.evaluateExpression(t))}catch{e=null}if(typeof e=="number"&&Number.isFinite(e))return e;const n=Number(e);if(Number.isFinite(n))return n;const r=Number(t);return Number.isFinite(r)?r:null}u(on,"evaluateConstraintNumericValue");function W(o){return o===0?"0":o?String(o).trim():""}u(W,"normalizeTypeString");const an=new Set(["type","persistentData","__open"]);function cn(o,t){if(o===t)return!0;if(!Array.isArray(o)||!Array.isArray(t)||o.length!==t.length)return!1;for(let e=0;e<o.length;e+=1)if(o[e]!==t[e])return!1;return!0}u(cn,"shallowArrayEqual");function de(o){const t={};if(!o||typeof o!="object")return t;for(const e in o){if(!Object.prototype.hasOwnProperty.call(o,e)||an.has(e))continue;const n=o[e]?o[e].default_value:void 0;t[e]=z(n)}return t}u(de,"extractDefaults");function ye(o){return`Unknown constraint type: ${o!=null?String(o):"unknown"}`}u(ye,"formatUnknownConstraintMessage");const ln=new Map([["touch_align","touch_align"],["touch-align","touch_align"],["touchalign","touch_align"],["touch align","touch_align"],["touch align constraint","touch_align"],["touchalignconstraint","touch_align"],["touch","touch_align"],["distance","distance"],["distance constraint","distance"],["distanceconstraint","distance"],["angle","angle"],["angle constraint","angle"],["angleconstraint","angle"]]),ge={touch_align:"Touch Align",distance:"Distance",angle:"Angle"},be=1e-6,Vt=1,un=.5,fn=.5,pn=Math.max(1,Vt),ct="Constraint disabled.";function lt(o,t){const e=Number(o);return Number.isFinite(e)?e:t}u(lt,"toFiniteNumber$4");function hn(o){const t=Math.floor(lt(o,Vt));return!Number.isFinite(t)||t<1?Vt:t}u(hn,"clampIterations");function Se(o,t){const e=lt(o,t);return Number.isFinite(e)?e<0?0:e>1?1:e:t}u(Se,"clampGain");function mn(o){if(!o||typeof o.traverse!="function")return;const t=[],e=["parallel-constraint-normal-","distance-constraint-normal-","touch-align-normal-"];o.traverse(n=>{!n||typeof n.name!="string"||e.some(r=>n.name.startsWith(r))&&t.push(n)});for(const n of t)try{n.parent?.remove?.(n)}catch{}}u(mn,"removeExistingDebugArrows");function Pe(o){let t=o;for(;t;){if(t.isAssemblyComponent||t.type==="COMPONENT")return t;t=t.parent||null}return null}u(Pe,"resolveComponentFromObject");function dn(o){return Pe(o)?1:0}u(dn,"scoreObjectForComponent");function yn(o){if(!o)return null;if(o instanceof T)return o.clone();if(typeof o=="object"){const{x:t,y:e,z:n}=o,r=Number.isFinite(t)?t:0,s=Number.isFinite(e)?e:0,i=Number.isFinite(n)?n:0;return new T(r,s,i)}return null}u(yn,"vectorFrom");function wt(o,t=null){if(!o)return t;const e=o.inputParams||{},n=e.id??e.constraintID??o.id??t;return n==null?t:String(n)}u(wt,"resolveConstraintEntryId");function dt(o){return W(wt(o))}u(dt,"normalizeConstraintEntryId");var x,Fe,At,Bt,Re,Xt,ve,rt,Kt,ze,ke,gt,Yt,It,U;const oe=class oe{constructor(t=null,e=null){Mt(this,x);this.partHistory=t||null,this.registry=e||new De,this.constraints=[],this.idCounter=0,this._listeners=new Set,this._autoRunScheduled=!1,this._autoRunActive=!1,this._autoRunOptions=null}setPartHistory(t){this.partHistory=t||null,this.partHistory&&this.constraints.length&&A(this,x,rt).call(this)}setRegistry(t){this.registry=t||this.registry}addListener(t){return typeof t!="function"?()=>{}:(this._listeners.add(t),()=>{this._listeners.delete(t)})}removeListener(t){typeof t=="function"&&this._listeners.delete(t)}onChange(t){if(typeof t!="function")return()=>{};const e=u(()=>{try{t(this)}catch{}},"wrapped");return this.addListener(e)}list(){return this.entries}get entries(){return this.constraints}set entries(t){Array.isArray(t)?this.constraints=t:this.constraints=[]}get size(){return this.constraints.length}findById(t){const e=W(t);return e&&this.constraints.find(n=>dt(n)===e)||null}async addConstraint(t,e=null){const n=A(this,x,It).call(this,t);if(!n)throw new Error(`Constraint type "${t}" is not registered.`);const r=n.inputParamsSchema||{},s=de(r),i=W(n.constraintType||t||n.name),c={type:i,inputParams:{...s},persistentData:{isNewConstraint:!0},__open:!0,enabled:!0};Object.defineProperty(c,"constraintClass",{value:n,configurable:!0,writable:!0,enumerable:!1});const m=n?.shortName||n?.constraintShortName||i||"CONST",a=this.generateId(m),y=c.inputParams.id??c.inputParams.constraintID;return c.inputParams.id=y||a,A(this,x,At).call(this,c),e&&typeof e=="object"&&Object.assign(c.inputParams,z(e)),c.inputParams.applyImmediately=!0,A(this,x,Bt).call(this,c),this.constraints.push(c),A(this,x,U).call(this,"add",c),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),c}removeConstraint(t){const e=W(t);if(!e)return!1;const n=this.constraints.findIndex(s=>dt(s)===e);if(n<0)return!1;const[r]=this.constraints.splice(n,1);return A(this,x,U).call(this,"remove",r||null),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),!0}moveConstraint(t,e){const n=W(t);if(!n)return!1;const r=this.constraints.findIndex(s=>dt(s)===n);return r<0?!1:this.moveConstraintToIndex(n,r+e)}moveConstraintToIndex(t,e){const n=W(t);if(!n)return!1;const r=this.constraints.findIndex(c=>dt(c)===n);if(r<0)return!1;const s=Number.isFinite(e)?Math.max(0,Math.min(this.constraints.length-1,e)):r;if(s===r)return!1;const[i]=this.constraints.splice(r,1);return this.constraints.splice(s,0,i),A(this,x,U).call(this,"reorder",i||null),A(this,x,rt).call(this),!0}updateConstraintParams(t,e){const n=this.findById(t);return!n||typeof e!="function"?!1:(e(n.inputParams),A(this,x,At).call(this,n),A(this,x,U).call(this,"update",n),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),!0)}setConstraintEnabled(t,e){const n=this.findById(t);if(!n)return!1;const r=e!==!1;if(n.enabled!==!1===r){if(n.enabled!==r&&(n.enabled=r),!r&&n.persistentData?.status!=="disabled"){const c={...n.persistentData||{}};c.status="disabled",c.message||(c.message=ct),n.persistentData=c,A(this,x,U).call(this,"update",n)}return!1}n.enabled=r;const i={...n.persistentData||{}};return r?(i.status==="disabled"&&(i.status="pending",i.message===ct&&delete i.message,n.persistentData=i),A(this,x,U).call(this,"update",n),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),!0):(i.status="disabled",i.message||(i.message=ct),n.persistentData=i,A(this,x,U).call(this,"update",n),this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this),!0)}setOpenState(t,e){const n=this.findById(t);if(!n)return!1;const r=e!==!1;if(n.__open!==!1===r)return!1;const i=n.inputParams||{};if(Object.prototype.hasOwnProperty.call(i,"__open"))try{i.__open=r}catch{n.__open=r}else n.__open=r;return(!n.runtimeAttributes||typeof n.runtimeAttributes!="object")&&(n.runtimeAttributes={}),n.runtimeAttributes.__open=r,A(this,x,U).call(this,"open-state",n),!0}setExclusiveOpen(t){const e=W(t);if(!e)return!1;let n=!1;for(const r of this.constraints){if(!r)continue;const i=dt(r)===e;if(r.__open!==!1!==i){const m=r.inputParams||{};if(Object.prototype.hasOwnProperty.call(m,"__open"))try{m.__open=i}catch{r.__open=i}else r.__open=i;(!r.runtimeAttributes||typeof r.runtimeAttributes!="object")&&(r.runtimeAttributes={}),r.runtimeAttributes.__open=i,n=!0}}return n&&A(this,x,U).call(this,"open-state",this.findById(t)),n}clear(){this.constraints=[],this.idCounter=0,A(this,x,U).call(this,"clear")}snapshot(){return{idCounter:this.idCounter,constraints:this.constraints.map(t=>({type:t?.type||null,inputParams:z(t?.inputParams)||{},persistentData:z(t?.persistentData)||{},open:t?.__open!==!1,enabled:t?.enabled!==!1}))}}async replaceAll(t=[],e=0){const n=[],r=Array.isArray(t)?t:[];let s=Number.isFinite(Number(e))?Number(e):0;for(const i of r){const c=A(this,x,Fe).call(this,i);if(!c)continue;const m=c.type||c.constraintType||null,a=A(this,x,It).call(this,m);if(!a)continue;const y=de(a.inputParamsSchema),f=W(a.constraintType||m||a.name),l={type:f,inputParams:{...y,...z(c.inputParams||{})},persistentData:z(c.persistentData||{}),__open:c.open!==!1,enabled:c.enabled!==!1},h=l.inputParams.id??l.inputParams.constraintID;if(h){const d=String(h).match(/(\d+)$/);if(d){const g=Number(d[1]);Number.isFinite(g)&&(s=Math.max(s,g))}l.inputParams.id=h}else{const d=(a?.shortName||a?.constraintShortName||f||"CONST").replace(/[^a-z0-9]/gi,"").toUpperCase()||"CONST";s+=1,l.inputParams.id=`${d}${s}`}A(this,x,At).call(this,l),l.inputParams.applyImmediately=!0,Object.defineProperty(l,"constraintClass",{value:a,configurable:!0,writable:!0,enumerable:!1}),A(this,x,Bt).call(this,l),n.push(l)}this.idCounter=s,this.constraints=n,A(this,x,U).call(this,"replace"),this.constraints.length&&(this.checkConstraintErrors(this.partHistory),A(this,x,rt).call(this))}async deserialize(t){const e=t&&typeof t=="object"?t:{},n=Array.isArray(e.constraints)?e.constraints:Array.isArray(t)?t:[],r=Number.isFinite(Number(e.idCounter))?Number(e.idCounter):void 0;await this.replaceAll(n,r)}generateId(t="CONST"){const e=W(t).replace(/[^a-z0-9]/gi,"").toUpperCase()||"CONST";return this.idCounter+=1,`${e}${this.idCounter}`}checkConstraintErrors(t=this.partHistory,e={}){const n=e&&typeof e=="object"?e:{},r=n.emit!==!1,s=n.updatePersistentData!==!1,i=t||this.partHistory||null;i&&(this.partHistory=i);const c=A(this,x,Xt).call(this),m=[];let a=!1;const y=u((f,l)=>{const h=f?.persistentData&&typeof f.persistentData=="object"?f.persistentData:{},d={...h};let g=!1;const S=u((b,w)=>{const C=d[b];if(w===void 0){Object.prototype.hasOwnProperty.call(d,b)&&(delete d[b],g=!0);return}if(Array.isArray(C)&&Array.isArray(w)){if(cn(C,w))return}else if(C===w)return;d[b]=w,g=!0},"set"),p=u(b=>{Object.prototype.hasOwnProperty.call(d,b)&&(delete d[b],g=!0)},"remove");try{l({set:S,remove:p,data:d,previous:h})}catch(b){console.warn("[AssemblyConstraintHistory] Failed to update persistent data:",b)}return g&&(f.persistentData=d),g},"mutatePersistentData");for(const f of this.constraints){if(!f)continue;const l=wt(f),h=f?.type||null,d={id:l,constraintID:l,type:h,status:"ok",message:"",duplicateConstraintIDs:null,duplicateSignature:null};if(f.enabled===!1){d.status="disabled",d.message=ct,s&&(a=y(f,({set:p,remove:b,previous:w})=>{p("status","disabled"),(!w.message||w.message===ct)&&p("message",ct),p("satisfied",!1),b("duplicateConstraintIDs"),b("duplicateSignature")})||a),m.push(d);continue}const g=A(this,x,It).call(this,h),S=c.get(f);if(!g){const p=ye(h);d.status="error",d.message=p,s&&(a=y(f,({set:b,remove:w})=>{b("status","error"),b("message",p),b("satisfied",!1),w("duplicateConstraintIDs"),w("duplicateSignature")})||a),m.push(d);continue}if(S){const p=Array.isArray(S.relatedIds)?S.relatedIds.filter(Boolean):[],b=S.signature||null;d.status="duplicate",d.message=S.message||"Duplicate constraint selections.",d.duplicateConstraintIDs=p.length?p:null,d.duplicateSignature=b,s&&(a=y(f,({set:w,remove:C})=>{w("status","duplicate"),w("message",d.message),w("satisfied",!1),d.duplicateConstraintIDs?w("duplicateConstraintIDs",d.duplicateConstraintIDs):C("duplicateConstraintIDs"),b?w("duplicateSignature",b):C("duplicateSignature")})||a),m.push(d);continue}s&&(a=y(f,({set:p,remove:b,previous:w})=>{w.status==="duplicate"&&(p("status","pending"),typeof w.message=="string"&&w.message.startsWith("Duplicate constraint selections")&&b("message")),w.status==="error"&&typeof w.message=="string"&&w.message.startsWith("Unknown constraint type:")&&(p("status","pending"),b("message")),b("duplicateConstraintIDs"),b("duplicateSignature")})||a),m.push(d)}return s&&a&&r&&A(this,x,U).call(this,"update"),m}async runAll(t=this.partHistory,e={}){const n=t||this.partHistory;if(!n)return[];this.partHistory=n,this.checkConstraintErrors(n,{emit:!1});const r=Math.abs(lt(e?.tolerance,be))||be,s=hn(e?.iterations),i=Se(e?.translationGain,un),c=Se(e?.rotationGain,fn),m=e?.debugMode===!0,a=m?500:0,y=lt(e?.delayMs??e?.iterationDelayMs,a),f=Math.max(0,Number.isFinite(y)?y:a),l=e?.viewer||n.viewer||null,h=u(()=>{try{l?.render?.()}catch{}try{l?.requestRender?.()}catch{}},"renderScene"),d=e?.controller&&typeof e.controller=="object"?e.controller:null,g=d?.signal||e?.signal||null;let S=!1;const p=u(()=>g?.aborted?(S=!0,!0):!1,"shouldAbort"),b=d?.hooks||e?.hooks,w=b&&typeof b=="object"?b:{},C=u(async(I,N={})=>{const F=w?.[I];if(typeof F=="function")try{await F({controller:d,signal:g,aborted:S,...N})}catch(_){console.warn(`[AssemblyConstraintHistory] hook "${I}" failed:`,_)}},"safeCallHook"),D=n.scene||null,O=Array.isArray(n.features)?n.features.filter(Boolean):[],j=new Map;for(const I of O){const N=W(I?.inputParams?.featureID);N&&j.set(N,I)}const H=new Set,ot=u(I=>Je(D,I,{scoreFn:dn,allowJson:!1,allowUuidString:!1,allowUuidObject:!0,allowFuzzyName:!1,allowNameContains:!1,allowPath:!1,allowReference:!1,allowTarget:!1,allowSelectionName:!1,arrayMode:"first"}),"resolveObject"),ft=u(I=>{const N=ot(I);return Pe(N)},"resolveComponent"),J=u(I=>{if(!I)return null;const N=W(I.owningFeatureID);return N&&j.get(N)||null},"getFeatureForComponent"),Y=u(I=>!!(!I||I.fixed||I.userData?.fixedByConstraint||J(I)?.inputParams?.isFixed),"isComponentFixed"),G=u(I=>{I&&H.add(I)},"markUpdated"),E={partHistory:n,scene:D,tolerance:r,translationGain:i,rotationGain:c,resolveObject:ot,resolveComponent:ft,applyTranslation:u((I,N)=>{const F=yn(N);return!I||!F||F.lengthSq()===0?!1:(I.position.add(F),I.updateMatrixWorld?.(!0),G(I),!0)},"applyTranslation"),applyRotation:u((I,N)=>{if(!I||!N)return!1;let F;if(N instanceof Ut)F=N.clone();else{const _=lt(N?.x,0),at=lt(N?.y,0),v=lt(N?.z,0),L=Number.isFinite(N?.w)?N.w:1;F=new Ut(_,at,v,L)}return!Number.isFinite(F.x)||!Number.isFinite(F.y)||!Number.isFinite(F.z)||!Number.isFinite(F.w)?!1:(Math.abs(1-F.lengthSq())>1e-6&&F.normalize(),I.quaternion.premultiply(F),I.updateMatrixWorld?.(!0),G(I),!0)},"applyRotation"),isComponentFixed:Y,getFeatureForComponent:J,markUpdated:G,viewer:l,renderScene:h,debugMode:m};mn(D);const Ke=A(this,x,Xt).call(this),pt=this.constraints.map(I=>{const N=wt(I);if(I?.enabled===!1)return{entry:I,instance:null,result:{id:N,ok:!0,status:"disabled",message:ct,applied:!1,satisfied:!1,iteration:0,constraintID:N},skipReason:"disabled"};const F=Ke.get(I);if(F){const $=Array.isArray(F.relatedIds)?F.relatedIds.slice():[],X={id:N,ok:!1,status:"duplicate",message:F.message,applied:!1,satisfied:!1,iteration:0,constraintID:N,duplicateConstraintIDs:$,duplicateSignature:F.signature};return{entry:I,instance:null,result:X,skipReason:"duplicate"}}const _=A(this,x,It).call(this,I.type);if(!_){const $=ye(I.type);return I.persistentData={status:"error",message:$,lastRunAt:Date.now(),lastIteration:0},{entry:I,instance:null,result:{id:N,ok:!1,status:"error",message:$,applied:!1,satisfied:!1,iteration:0,constraintID:N},skipReason:"unregistered"}}const at=z(I.inputParams)||{},v=z(I.inputParams)||{},L=new _(n);A(this,x,Re).call(this,v,_.inputParamsSchema||{});try{L.inputParams=v}catch{L.inputParams={...v}}try{Object.assign(L.persistentData,z(I.persistentData))}catch{L.persistentData={...I.persistentData||{}}}return{entry:I,instance:L,result:null,originalInputParams:at}});for(const I of pt)I.instance?.clearDebugArrows?.({scene:D});await C("onStart",{maxIterations:s,constraintCount:pt.length});let fe=0;const Ye=pt.length;t:for(let I=0;I<s&&!(p()||(await C("onIterationStart",{iteration:I,maxIterations:s}),p()));I+=1){let N=!1;for(let F=0;F<pt.length;F+=1){if(p())break t;const _=pt[F],at=wt(_?.entry),v=_?.entry?.type||null,L={iteration:I,index:F,id:at,constraintID:at,constraintType:v,totalConstraints:Ye};if(!_.instance){await C("onConstraintSkipped",{...L,skipReason:_.skipReason||null});continue}if(await C("onConstraintStart",L),p())break t;const $={...E,iteration:I,maxIterations:s};let X;try{typeof _.instance.solve=="function"?X=await _.instance.solve($):X=await _.instance.run($)}catch(ht){console.warn("[AssemblyConstraintHistory] Constraint solve failed:",ht),X={ok:!1,status:"error",message:ht?.message||"Constraint evaluation failed.",error:ht},_.instance.persistentData=_.instance.persistentData||{},_.instance.persistentData.status="error",_.instance.persistentData.message=X.message}if(_.result=A(this,x,Yt).call(this,_.instance,X,I),_.result.applied&&(N=!0),await C("onConstraintEnd",{...L,result:_.result}),p())break t}if(typeof E.renderScene=="function")try{E.renderScene()}catch{}if(f>0&&await new Promise(F=>setTimeout(F,f)),p()||(fe=I+1,await C("onIterationComplete",{iteration:I,maxIterations:s,applied:N}),p())||!N)break}S=S||g?.aborted||!1;const Ge=Date.now(),Ot=[];for(const I of pt){const{entry:N,instance:F}=I,_=I.result||A(this,x,Yt).call(this,F,{ok:!1,status:"pending",message:"Constraint was not evaluated."},Math.max(0,s-1)),v={...F?.persistentData&&Object.keys(F.persistentData).length?F.persistentData:N.persistentData||{}};if(_.status&&(v.status=_.status),_.message!==void 0&&(_.message?v.message=_.message:v.message&&delete v.message),v.satisfied=!!_.satisfied,typeof _.error=="number"&&Number.isFinite(_.error)&&(v.error=_.error),v.lastRunAt=Ge,v.lastIteration=_.iteration,v.lastRequestedIterations=s,_.status==="duplicate"?(Array.isArray(_.duplicateConstraintIDs)&&_.duplicateConstraintIDs.length?v.duplicateConstraintIDs=_.duplicateConstraintIDs.slice():v.duplicateConstraintIDs&&delete v.duplicateConstraintIDs,_.duplicateSignature?v.duplicateSignature=_.duplicateSignature:v.duplicateSignature&&delete v.duplicateSignature):(v.duplicateConstraintIDs&&delete v.duplicateConstraintIDs,v.duplicateSignature&&delete v.duplicateSignature),N.persistentData=v,I.originalInputParams){const $=z(I.originalInputParams)||{};_.persistInputParams&&typeof _.persistInputParams=="object"&&Object.assign($,z(_.persistInputParams));const X=N.inputParams&&typeof N.inputParams=="object"?N.inputParams:{};for(const ht of Object.keys(X))Object.prototype.hasOwnProperty.call($,ht)||delete X[ht];Object.assign(X,$),N.inputParams=X}else{const $={...N.inputParams||{}};_.persistInputParams&&typeof _.persistInputParams=="object"&&Object.assign($,z(_.persistInputParams)),N.inputParams=$}const L=wt(N);Ot.push({id:L,constraintID:L,type:N?.type||null,..._})}try{n.syncAssemblyComponentTransforms?.()}catch(I){console.warn("[AssemblyConstraintHistory] Failed to sync component transforms:",I)}return A(this,x,U).call(this,"solve"),await C("onComplete",{results:Ot.slice(),aborted:S,iterationsCompleted:fe,maxIterations:s}),Ot}};x=new WeakSet,Fe=u(function(t){if(!t||typeof t!="object")return t;const e={...t},n=t.inputParams&&typeof t.inputParams=="object"?t.inputParams:null;if(n){const s={...n},i=Object.prototype.hasOwnProperty.call(s,"constraintID")?s.constraintID:void 0;(s.id==null||s.id==="")&&i!=null&&(s.id=i),Object.prototype.hasOwnProperty.call(s,"constraintID")&&delete s.constraintID,e.inputParams=s}const r=Object.prototype.hasOwnProperty.call(e,"constraintID")?e.constraintID:void 0;return(e.id==null||e.id==="")&&r!=null&&(e.id=r),Object.prototype.hasOwnProperty.call(e,"constraintID")&&delete e.constraintID,(e.id==null||e.id==="")&&e.inputParams?.id!=null&&(e.id=e.inputParams.id),e},"#runConstraintEntryMigrations"),At=u(function(t){if(!t||!t.inputParams)return;const e=t.inputParams,n=e.id??e.constraintID??t.id;if(!n)return;const r=String(n);e.id=r,t.id=r},"#syncEntryIds"),Bt=u(function(t){if(!t||typeof t!="object")return;(!t.inputParams||typeof t.inputParams!="object")&&(t.inputParams={});const e=t.inputParams,n={configurable:!0,enumerable:!1};A(this,x,At).call(this,t);const r=Object.prototype.hasOwnProperty.call(e,"constraintID")?e.constraintID:void 0;if(r!=null&&(e.id==null||e.id==="")&&(e.id=r),Object.prototype.hasOwnProperty.call(e,"constraintID"))try{delete e.constraintID}catch{}Object.getOwnPropertyDescriptor(e,"constraintID")||Object.defineProperty(e,"constraintID",{...n,get:u(()=>e.id,"get"),set:u(a=>{if(a==null){e.id=a,t.id=a;return}const y=String(a);e.id=y,t.id=y},"set")});const s=Object.prototype.hasOwnProperty.call(e,"__open")?e.__open:t.__open;if(Object.prototype.hasOwnProperty.call(e,"__open"))try{delete e.__open}catch{}const i=s!==!1;t.__open=i;const c=t.runtimeAttributes&&typeof t.runtimeAttributes=="object"?t.runtimeAttributes:{};c.__open=i;try{Object.defineProperty(t,"runtimeAttributes",{value:c,configurable:!0,writable:!0,enumerable:!1})}catch{t.runtimeAttributes=c}Object.prototype.hasOwnProperty.call(e,"__entityRef")||Object.defineProperty(e,"__entityRef",{...n,value:t});let m;if(Object.prototype.hasOwnProperty.call(e,"persistentData")){m=e.persistentData;try{delete e.persistentData}catch{}}m&&typeof m=="object"?t.persistentData=z(m):(!t.persistentData||typeof t.persistentData!="object")&&(t.persistentData={}),Object.defineProperty(e,"persistentData",{...n,get:u(()=>t.persistentData||(t.persistentData={}),"get"),set:u(a=>{const y=a&&typeof a=="object"?a:{};t.persistentData=y},"set")}),Object.defineProperty(e,"__open",{...n,get:u(()=>t.runtimeAttributes.__open!==!1,"get"),set:u(a=>{const y=a!==!1;t.runtimeAttributes.__open=y,t.__open=y},"set")}),t.type&&!e.type&&(e.type=t.type),t.entityType=t.type||e.type||t.entityType||null},"#linkEntryParams"),Re=u(function(t,e){if(!(!t||!e))for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const r=e[n];if(!r||r.type!=="number")continue;const s=on(this.partHistory,t[n]);s!=null&&(t[n]=s)}},"#applyNumericExpressions"),Xt=u(function(){const t=new Map;for(const n of this.constraints){if(!n)continue;const r=A(this,x,ve).call(this,n?.type);if(!r)continue;const s=A(this,x,ze).call(this,n?.inputParams);if(!s)continue;t.has(s)||t.set(s,[]);const i=dt(n)||null,c=ge[r]||r;t.get(s).push({entry:n,type:r,typeLabel:c,id:i})}const e=new Map;for(const[n,r]of t.entries()){if(!Array.isArray(r)||r.length<=1)continue;const s=new Map;for(const i of r)s.has(i.type)||s.set(i.type,[]),s.get(i.type).push(i);for(const i of r){const c=(s.get(i.type)||[]).filter(h=>h!==i),m=[];for(const[h,d]of s.entries())h!==i.type&&m.push({type:h,entries:d});const a=u((h,d)=>{const g=Array.from(new Set(d.map(p=>p&&p.trim()?p.trim():null).filter(Boolean)));if(g.length===0)return`${h} constraint`;const S=g.length>1?"constraints":"constraint";return`${h} ${S} ${g.join(", ")}`},"formatConstraintPhrase"),y=[];if(c.length){const h=c.map(d=>d.id);y.push(a(`shares selections with ${i.typeLabel}`,h))}for(const h of m){const d=ge[h.type]||h.type,g=h.entries.map(S=>S.id);y.push(a(`conflicts with ${d}`,g))}const f=y.length?`Duplicate constraint selections: ${y.join(". ")}.`:"Duplicate constraint selections.",l=r.filter(h=>h!==i).map(h=>h.id).filter(Boolean);e.set(i.entry,{message:f,signature:n,relatedIds:Array.from(new Set(l)),type:i.type})}}return e},"#detectDuplicateConstraints"),ve=u(function(t){const e=W(t).toLowerCase();return e&&ln.get(e)||null},"#normalizeDuplicateConstraintType"),rt=u(function(t=null){if(!this.partHistory)return;const e=t&&typeof t=="object"?{...t}:null;this._autoRunOptions=e,!this._autoRunScheduled&&(this._autoRunScheduled=!0,Promise.resolve().then(()=>{try{A(this,x,Kt).call(this)}catch(n){console.warn("[AssemblyConstraintHistory] Failed to schedule auto run:",n)}}))},"#scheduleAutoRun"),Kt=u(async function(){if(!this._autoRunScheduled||this._autoRunActive)return;const t=this._autoRunOptions?{...this._autoRunOptions}:{};this._autoRunOptions=null,this._autoRunScheduled=!1;const e=Number(t.iterations),n=Number.isFinite(e)&&e>=1?Math.floor(e):pn,r=this.partHistory;if(r){this._autoRunActive=!0;try{await this.runAll(r,{...t,iterations:n})}catch(s){console.warn("[AssemblyConstraintHistory] Auto run failed:",s)}finally{this._autoRunActive=!1,this._autoRunScheduled&&Promise.resolve().then(()=>{try{A(this,x,Kt).call(this)}catch(s){console.warn("[AssemblyConstraintHistory] Failed to re-run auto cycle:",s)}})}}},"#executeAutoRun"),ze=u(function(t){if(!t||typeof t!="object")return null;const e=A(this,x,ke).call(this,t);if(!e)return null;const n=[];for(const r of e){const s=A(this,x,gt).call(this,r,0,new Set);if(!s)return null;n.push(s)}return n.length!==2?null:(n.sort(),`${n[0]}|${n[1]}`)},"#buildSelectionSignature"),ke=u(function(t){const e=Array.isArray(t?.elements)?t.elements:[],n=[];for(const r of e)if(r!=null&&(n.push(r),n.length>=2))break;return n.length>=2?n.slice(0,2):null},"#extractSelectionPair"),gt=u(function(t,e=0,n=new Set){if(t==null||e>5)return null;if(Array.isArray(t)){for(const s of t){const i=A(this,x,gt).call(this,s,e+1,n);if(i)return i}return null}const r=typeof t;if(r==="string"||r==="number"||r==="boolean")return`${r}:${String(t)}`;if(r!=="object"||n.has(t))return null;n.add(t);try{if(t.isObject3D&&typeof t.uuid=="string"&&t.uuid)return`uuid:${t.uuid}`;const s=["selectionID","selectionId","fullName","fullPath","pathKey","pathId","pathID","id","uuid","entityUUID","brepId","brepID","objectUUID","objectId","objectID"];for(const a of s){const y=t[a];if(typeof y=="string"&&y.trim())return`${a}:${y.trim()}`}const i=["name","label","displayName","componentName","faceName","edgeName","vertexName","reference","refName"];for(const a of i){const y=t[a];if(typeof y=="string"&&y.trim())return`${a}:${y.trim()}`}if(Array.isArray(t.path)&&t.path.length){const a=t.path.map(y=>String(y)).join("/");if(a)return`path:${a}`}if(t.component&&typeof t.component=="object"){const a=A(this,x,gt).call(this,t.component,e+1,n);if(a)return`component:${a}`}if(t.object&&typeof t.object=="object"){const a=A(this,x,gt).call(this,t.object,e+1,n);if(a)return`object:${a}`}const c=Object.keys(t).filter(a=>a!=="__proto__").sort(),m=[];for(const a of c){const y=t[a];if(y==null||typeof y=="function"||typeof y=="symbol")continue;let f=null;if(typeof y=="object"){const l=A(this,x,gt).call(this,y,e+1,n);l&&(f=l)}else f=`${typeof y}:${String(y)}`;if(f&&(m.push(`${a}=${f}`),m.length>=8))break}return m.length?`obj:${m.join(",")}`:null}finally{n.delete(t)}},"#selectionKey"),Yt=u(function(t,e,n){const r=e&&typeof e=="object"?e:{},s=!!r.satisfied,i=!!r.applied,c=r.ok!==!1,m=typeof r.message=="string"?r.message:"";let a=typeof r.status=="string"&&r.status.trim()?r.status.trim():null;a||(c?s?a="satisfied":i?a="adjusted":a="pending":a="error");const y=Number.isFinite(r.error)?r.error:null,f=r.persistInputParams&&typeof r.persistInputParams=="object"?z(r.persistInputParams):null;return t&&(t.persistentData=t.persistentData||{},t.persistentData.status||(t.persistentData.status=a),m&&!t.persistentData.message&&(t.persistentData.message=m),t.persistentData.satisfied=s,y!=null&&(t.persistentData.error=y),t.persistentData.isNewConstraint===!0&&c&&i&&(t.persistentData.isNewConstraint=!1)),{ok:c,status:a,satisfied:s,applied:i,error:y,message:m,iteration:n,diagnostics:r.diagnostics||null,persistInputParams:f}},"#finalizeConstraintResult"),It=u(function(t){const e=W(t);if(!e)return null;if(this.registry&&typeof this.registry.getSafe=="function"){const n=this.registry.getSafe(e);if(n)return n}if(this.registry&&typeof this.registry.get=="function")try{return this.registry.get(e)}catch{return null}return null},"#resolveConstraint"),U=u(function(t="update",e=null,n=null){if(!(this._listeners instanceof Set)||this._listeners.size===0)return;const r={...n&&typeof n=="object"?n:{},history:this,entry:e||null,reason:t||"update"};for(const s of Array.from(this._listeners))try{s({...r})}catch{}},"#emitChange"),u(oe,"AssemblyConstraintHistory");let Wt=oe;const ae=class ae{constructor(){this.metadata={}}getMetadata(t){const e=this.metadata[t]||{};return e.inheritsFrom?{...this.getMetadata(e.inheritsFrom),...e}:e}getOwnMetadata(t){const e=this.metadata[t];return e?{...e}:{}}setMetadata(t,e,n){this.metadata[t]||(this.metadata[t]={}),this.metadata[t][e]=n}setMetadataObject(t,e){e&&Object.keys(e).length>0?this.metadata[t]={...e}:delete this.metadata[t]}deleteMetadataKey(t,e){const n=this.metadata[t];n&&(delete n[e],Object.keys(n).length===0&&delete this.metadata[t])}clearMetadata(t){delete this.metadata[t]}};u(ae,"MetadataManager");let zt=ae;const ce=class ce{constructor(t){this.partHistory=t||null,this.views=[],this._listeners=new Set}reset(){this.views=[],this._emit()}getViews(){return this._normalizeViewsArray(this.views),this.views}setViews(t){const e=Array.isArray(t)?Array.from(t):[];return this.views=e,this._normalizeViewsArray(this.views),this._emit(),this.views}addView(t){const e=this.getViews(),n=this._normalizeView(t,e.length);return e.push(n),this._emit(),n}updateView(t,e){const n=this.getViews(),r=Number(t);if(!Number.isInteger(r)||r<0||r>=n.length)return null;const s=n[r];let i=s;if(typeof e=="function")try{const c=e(s);c&&typeof c=="object"&&(i=c)}catch{}else e&&typeof e=="object"&&e!==s&&(i=Object.assign({},s,e));return i!==s&&(n[r]=i),n[r]=this._normalizeView(n[r],r),this._emit(),n[r]}removeView(t){const e=this.getViews(),n=Number(t);if(!Number.isInteger(n)||n<0||n>=e.length)return null;const[r]=e.splice(n,1);for(let s=0;s<e.length;s++)e[s]=this._normalizeView(e[s],s);return this._emit(),r||null}addListener(t){return typeof t!="function"?()=>{}:(this._listeners.add(t),()=>{try{this._listeners.delete(t)}catch{}})}removeListener(t){if(typeof t=="function")try{this._listeners.delete(t)}catch{}}notifyChanged(){this._emit()}toSerializable(){return this.getViews().map(t=>z(t))}_normalizeViewsArray(t){if(!Array.isArray(t))return this.views=[],this.views;for(let e=0;e<t.length;e++)t[e]=this._normalizeView(t[e],e);return t}_normalizeView(t,e){const n=Number.isInteger(e)?e:0,r=t&&typeof t=="object"?t:{},s=typeof r.name=="string"?r.name.trim():"",c=(typeof r.viewName=="string"?r.viewName.trim():"")||s||`View ${n+1}`;if(r.viewName=c,r.name=c,Array.isArray(r.annotations)||(r.annotations=[]),(!r.camera||typeof r.camera!="object")&&(r.camera={}),r.camera.viewport&&typeof r.camera.viewport=="object"){const y=Number(r.camera.viewport.width),f=Number(r.camera.viewport.height);y>0&&f>0?r.camera.viewport={width:y,height:f}:delete r.camera.viewport}(!r.viewSettings||typeof r.viewSettings!="object")&&(r.viewSettings={});const m=Number(r.viewSettings?.pmiTextSizePt);Number.isFinite(m)&&m>0?r.viewSettings.pmiTextSizePt=Math.max(1,Math.min(288,m)):delete r.viewSettings.pmiTextSizePt;const a=Array.isArray(r.viewSettings?.visibilityState?.hidden)?r.viewSettings.visibilityState.hidden.map(y=>({key:String(y?.key||""),count:Math.max(1,Math.round(Number(y?.count)||1))})).filter(y=>y.key):[];return a.length?r.viewSettings.visibilityState={hidden:a}:delete r.viewSettings.visibilityState,r.annotationHistory&&typeof r.annotationHistory!="object"&&delete r.annotationHistory,r}_emit(){if(!this._listeners||this._listeners.size===0)return;const t=this.getViews();for(const e of Array.from(this._listeners))try{e(t,this.partHistory||null)}catch{}}};u(ce,"PMIViewsManager");let Gt=ce;const yt=96,Oe=1;function gn(o,t=0){const e=Number(o);return Number.isFinite(e)?e:t}u(gn,"toFiniteNumber$3");function qt(o,t){return Math.max(Oe,gn(o,t))}u(qt,"clampCustomSheetSize");function we(o){const t=Math.round(qt(o,Oe)*100)/100;return String(t).replace(/(\.\d*?[1-9])0+$/u,"$1").replace(/\.0+$/u,"")}u(we,"formatSheetDimension");const Zt=Object.freeze({A:Object.freeze({key:"A",label:"A (8.5 x 11 in)",widthIn:8.5,heightIn:11}),B:Object.freeze({key:"B",label:"B (11 x 17 in)",widthIn:11,heightIn:17}),C:Object.freeze({key:"C",label:"C (17 x 22 in)",widthIn:17,heightIn:22}),D:Object.freeze({key:"D",label:"D (22 x 34 in)",widthIn:22,heightIn:34}),E:Object.freeze({key:"E",label:"E (34 x 44 in)",widthIn:34,heightIn:44}),A4:Object.freeze({key:"A4",label:"A4 (210 x 297 mm)",widthIn:8.27,heightIn:11.69}),A3:Object.freeze({key:"A3",label:"A3 (297 x 420 mm)",widthIn:11.69,heightIn:16.54}),A2:Object.freeze({key:"A2",label:"A2 (420 x 594 mm)",widthIn:16.54,heightIn:23.39}),A1:Object.freeze({key:"A1",label:"A1 (594 x 841 mm)",widthIn:23.39,heightIn:33.11}),A0:Object.freeze({key:"A0",label:"A0 (841 x 1189 mm)",widthIn:33.11,heightIn:46.81}),CUSTOM:Object.freeze({key:"CUSTOM",label:"Custom",widthIn:36,heightIn:24})}),bn=Object.freeze(["A","B","C","D","E","A4","A3","A2","A1","A0","CUSTOM"]);function Me(o){return String(o??"").trim().toLowerCase()==="portrait"?"portrait":"landscape"}u(Me,"normalizeSheetOrientation");function Te(o){const t=String(o??"").trim().toUpperCase();return Zt[t]||Zt.A}u(Te,"getSheetSizeByKey");function Wn(){return bn.map(o=>Zt[o]).filter(Boolean)}u(Wn,"listSheetSizes");function Sn(o,t="landscape",e=null){const n=Te(o),r=Me(t);if(n.key==="CUSTOM"){const m=qt(e?.customWidthIn??e?.widthIn,n.widthIn),a=qt(e?.customHeightIn??e?.heightIn,n.heightIn),y=r==="landscape",f=y?Math.max(m,a):Math.min(m,a),l=y?Math.min(m,a):Math.max(m,a);return{key:n.key,label:`Custom (${we(f)} x ${we(l)} in)`,orientation:r,units:"in",widthIn:f,heightIn:l,widthPx:f*yt,heightPx:l*yt,pxPerInch:yt,customWidthIn:f,customHeightIn:l}}const s=r==="landscape",i=s?Math.max(n.widthIn,n.heightIn):Math.min(n.widthIn,n.heightIn),c=s?Math.min(n.widthIn,n.heightIn):Math.max(n.widthIn,n.heightIn);return{key:n.key,label:n.label,orientation:r,units:"in",widthIn:i,heightIn:c,widthPx:i*yt,heightPx:c*yt,pxPerInch:yt}}u(Sn,"resolveSheetDimensions");function _t(o,t=0){const e=Number(o);return Number.isFinite(e)?e:t}u(_t,"toFiniteNumber$2");function Z(o,t,e){return Math.max(t,Math.min(e,o))}u(Z,"clamp$1");function it(o,t=""){return typeof o=="string"?o:o==null?t:String(o)}u(it,"sanitizeText$1");function wn(o,t=null){const e=String(o??"").trim();return e&&(/^#[\da-fA-F]{3,8}$/.test(e)||/^[a-zA-Z]+$/.test(e)||/^(rgb|rgba|hsl|hsla)\([^)]+\)$/i.test(e))?e:t}u(wn,"sanitizeColor$1");function M(o,t=1){return Math.max(1,Math.round(_t(o,t)))}u(M,"clampPositiveInt");function K(o,t=0){return Math.max(0,Math.round(_t(o,t)))}u(K,"clampIndex");function An(o,t=null){if(o==null)return t;const e=String(o).trim().toLowerCase();return e==="middle"||e==="center"?"center":e==="end"||e==="right"?"right":e==="left"?"left":t}u(An,"normalizeTextAlign$1");function In(o,t=null){if(o==null)return t;const e=String(o).trim().toLowerCase();return e==="center"?"middle":e==="bottom"?"bottom":e==="middle"||e==="top"?e:t}u(In,"normalizeVerticalAlign$1");function xn(o,t=null){if(o==null)return t;const e=String(o).trim();return e==="bold"?"700":e==="normal"?"400":/^\d{3}$/.test(e)?e:t}u(xn,"normalizeFontWeight");function Cn(o,t=null){return o==null?t:String(o).trim().toLowerCase()==="italic"?"italic":"normal"}u(Cn,"normalizeFontStyle");function _n(o,t=null){return o==null?t:String(o).trim().toLowerCase()==="underline"?"underline":"none"}u(_n,"normalizeTextDecoration");function ie(o){if(!o||typeof o!="object"||Array.isArray(o))return{};const t={},e=it(o.fontFamily,"").trim();e&&(t.fontFamily=e);const n=_t(o.fontSize,Number.NaN);Number.isFinite(n)&&n>0&&(t.fontSize=Z(n,.08,3));const r=xn(o.fontWeight??(o.bold?"700":null));r&&(t.fontWeight=r);const s=Cn(o.fontStyle??(o.italic?"italic":null));s&&(t.fontStyle=s);const i=_n(o.textDecoration);i&&(t.textDecoration=i);const c=An(o.textAlign??o.textAnchor);c&&(t.textAlign=c);const m=In(o.verticalAlign??o.verticalAnchor);m&&(t.verticalAlign=m);const a=wn(o.color??o.textColor,null);return a&&(t.color=a),t}u(ie,"normalizeTableCellStyle");function je(o=""){return{text:it(o,""),rowSpan:1,colSpan:1,mergedInto:null,style:{}}}u(je,"createTableCell");function ut(o,t){const e=Math.max(1,M(t,1)),n=Array.isArray(o)?o.slice(0,e):[],r=[];for(let i=0;i<e;i+=1)r.push(Math.max(1e-4,_t(n[i],1)));const s=r.reduce((i,c)=>i+c,0);return!Number.isFinite(s)||s<=0?Array.from({length:e},()=>1/e):r.map(i=>i/s)}u(ut,"normalizeTableFractions");function bt(o,t=0){return Array.isArray(o?.cells)&&o.cells.length>0?o.cells.length:Array.isArray(o?.rowFractions)&&o.rowFractions.length>0?o.rowFractions.length:Math.max(0,M(t,0))}u(bt,"getTableRowCount");function St(o,t=0){const e=Array.isArray(o?.cells)?o.cells:[];let n=0;for(const r of e)Array.isArray(r)&&(n=Math.max(n,r.length));return n>0?n:Array.isArray(o?.colFractions)&&o.colFractions.length>0?o.colFractions.length:Math.max(0,M(t,0))}u(St,"getTableColumnCount");function Ee(o=3,t=3){const e=Math.max(1,M(o,3)),n=Math.max(1,M(t,3));return{rowFractions:ut(null,e),colFractions:ut(null,n),cells:Array.from({length:e},()=>Array.from({length:n},()=>je()))}}u(Ee,"createTableData");function Nt(o,t=3,e=3){const n=Math.max(1,bt(o,t)),r=Math.max(1,St(o,e)),s=Ee(n,r);s.rowFractions=ut(o?.rowFractions,n),s.colFractions=ut(o?.colFractions,r);const i=Array.isArray(o?.cells)?o.cells:[],c=[];for(let a=0;a<n;a+=1)for(let y=0;y<r;y+=1){const f=Array.isArray(i[a])?i[a][y]:null,l=s.cells[a][y];f&&typeof f=="object"&&!Array.isArray(f)?(l.text=it(f.text,it(f.value,"")),l.style=ie(f.style&&typeof f.style=="object"?f.style:f),c.push({row:a,col:y,rowSpan:M(f.rowSpan,1),colSpan:M(f.colSpan,1)})):(l.text=it(f,""),l.style={}),l.rowSpan=1,l.colSpan=1,l.mergedInto=null}const m=Array.from({length:n},()=>Array.from({length:r},()=>!1));for(const a of c){const y=Z(a.rowSpan,1,n-a.row),f=Z(a.colSpan,1,r-a.col);if(y===1&&f===1)continue;let l=!1;for(let d=a.row;d<a.row+y&&!l;d+=1)for(let g=a.col;g<a.col+f;g+=1)if(!(d===a.row&&g===a.col)&&m[d][g]){l=!0;break}if(l)continue;const h=s.cells[a.row][a.col];h.rowSpan=y,h.colSpan=f;for(let d=a.row;d<a.row+y;d+=1)for(let g=a.col;g<a.col+f;g+=1)d===a.row&&g===a.col||(m[d][g]=!0,s.cells[d][g]={text:"",rowSpan:1,colSpan:1,mergedInto:{row:a.row,col:a.col},style:{}})}return s}u(Nt,"normalizeTableData");function Ct(o,t,e){return Array.isArray(o?.cells?.[t])&&o.cells[t][e]||null}u(Ct,"getTableCell");function He(o,t,e){const n=Ct(o,t,e);if(!n)return null;const r=n?.mergedInto;if(r&&Number.isInteger(r.row)&&Number.isInteger(r.col)){const s=Ct(o,r.row,r.col);if(s)return{row:r.row,col:r.col,cell:s}}return{row:t,col:e,cell:n}}u(He,"resolveTableCellAnchor");function Bn(o){if(!o)return null;const t=[o.anchorRow,o.focusRow].map(n=>K(n,0)),e=[o.anchorCol,o.focusCol].map(n=>K(n,0));return{minRow:Math.min(...t),maxRow:Math.max(...t),minCol:Math.min(...e),maxCol:Math.max(...e)}}u(Bn,"getTableSelectionRect");function kt(o,t=3,e=3){const n=Nt(o,t,e);return{rowFractions:n.rowFractions.slice(),colFractions:n.colFractions.slice(),cells:n.cells.map(r=>r.map(s=>({text:it(s?.text,""),rowSpan:M(s?.rowSpan,1),colSpan:M(s?.colSpan,1),mergedInto:s?.mergedInto&&Number.isInteger(s.mergedInto.row)&&Number.isInteger(s.mergedInto.col)?{row:s.mergedInto.row,col:s.mergedInto.col}:null,style:ie(s?.style)})))}}u(kt,"cloneTableData");function Nn(o,t){if(typeof t!="function")return;const e=Nt(o),n=bt(e,0),r=St(e,0);for(let s=0;s<n;s+=1)for(let i=0;i<r;i+=1){const c=Ct(e,s,i);!c||c?.mergedInto||t(c,s,i,e)}}u(Nn,"forEachTableAnchor");function Xn(o,t,e,n){const r=kt(o),s=He(r,K(t,0),K(e,0));return s?.cell&&(s.cell.text=it(n,"")),r}u(Xn,"setTableCellText");function Dn(o,t){const e=Nt(o),n=t||null;if(!n)return!1;const r=bt(e,0),s=St(e,0),i=Z(n.minRow,0,Math.max(0,r-1)),c=Z(n.maxRow,i,Math.max(0,r-1)),m=Z(n.minCol,0,Math.max(0,s-1)),a=Z(n.maxCol,m,Math.max(0,s-1));if(i===c&&m===a)return!1;for(let y=i;y<=c;y+=1)for(let f=m;f<=a;f+=1){const l=Ct(e,y,f);if(!l||l?.mergedInto||M(l.rowSpan,1)!==1||M(l.colSpan,1)!==1)return!1}return!0}u(Dn,"canMergeTableCells");function Kn(o,t){const e=kt(o),n=t||null;if(!n||!Dn(e,n))return e;const r=K(n.minRow,0),s=Math.max(r,K(n.maxRow,r)),i=K(n.minCol,0),c=Math.max(i,K(n.maxCol,i)),m=Ct(e,r,i);if(!m)return e;m.rowSpan=s-r+1,m.colSpan=c-i+1,m.mergedInto=null;for(let a=r;a<=s;a+=1)for(let y=i;y<=c;y+=1)a===r&&y===i||(e.cells[a][y]={text:"",rowSpan:1,colSpan:1,mergedInto:{row:r,col:i},style:{}});return e}u(Kn,"mergeTableCells");function Yn(o,t,e){const n=kt(o),r=He(n,K(t,0),K(e,0));if(!r?.cell)return n;const s=M(r.cell.rowSpan,1),i=M(r.cell.colSpan,1);if(s===1&&i===1)return n;r.cell.rowSpan=1,r.cell.colSpan=1,r.cell.mergedInto=null;for(let c=r.row;c<r.row+s;c+=1)for(let m=r.col;m<r.col+i;m+=1)c===r.row&&m===r.col||(n.cells[c][m]=je(""));return n}u(Yn,"unmergeTableCell");function Ae(o,t){const e=Array.isArray(o)?o.slice():[1],n=e.length;if(n<=0)return[1];const r=Z(t,0,n),s=Z(r===n?n-1:r,0,n-1),i=Math.max(1e-4,_t(e[s],1/n)),c=Math.max(1e-4,i*.5);return e[s]=Math.max(1e-4,i-c),e.splice(r,0,c),ut(e,e.length)}u(Ae,"splitFractionList");function $e(o,{rowInsertIndex:t=null,colInsertIndex:e=null}={}){const n=Nt(o),r=bt(n,1),s=St(n,1),i=t==null?r:r+1,c=e==null?s:s+1,m=t==null?-1:Z(t,0,r),a=e==null?-1:Z(e,0,s),y=Ee(i,c);return y.rowFractions=t==null?ut(n.rowFractions,r):Ae(n.rowFractions,m),y.colFractions=e==null?ut(n.colFractions,s):Ae(n.colFractions,a),Nn(n,(f,l,h)=>{const d=m>=0&&l>=m?l+1:l,g=a>=0&&h>=a?h+1:h,S=m>=0&&l<m&&l+M(f.rowSpan,1)>m?M(f.rowSpan,1)+1:M(f.rowSpan,1),p=a>=0&&h<a&&h+M(f.colSpan,1)>a?M(f.colSpan,1)+1:M(f.colSpan,1);y.cells[d][g]={text:it(f.text,""),rowSpan:S,colSpan:p,mergedInto:null,style:ie(f.style)};for(let b=d;b<d+S;b+=1)for(let w=g;w<g+p;w+=1)b===d&&w===g||(y.cells[b][w]={text:"",rowSpan:1,colSpan:1,mergedInto:{row:d,col:g},style:{}})}),y}u($e,"buildInsertedTable");function Pn(o,t){return $e(o,{rowInsertIndex:K(t,0)})}u(Pn,"insertTableRow");function Fn(o,t){return $e(o,{colInsertIndex:K(t,0)})}u(Fn,"insertTableColumn");function Gn(o,t=1,e=1){let n=kt(o,t,e);const r=Math.max(1,M(t,1)),s=Math.max(1,M(e,1));for(;bt(n,0)<r;)n=Pn(n,bt(n,0));for(;St(n,0)<s;)n=Fn(n,St(n,0));return n}u(Gn,"ensureTableSize");function R(o,t=0){const e=Number(o);return Number.isFinite(e)?e:t}u(R,"toFiniteNumber$1");function V(o,t=""){return typeof o=="string"?o:o==null?t:String(o)}u(V,"sanitizeText");function Q(o,t){const e=String(o??"").trim();return e&&(/^#[\da-fA-F]{3,8}$/.test(e)||/^[a-zA-Z]+$/.test(e)||/^(rgb|rgba|hsl|hsla)\([^)]+\)$/i.test(e))?e:t}u(Q,"sanitizeColor");function k(o,t,e){return Math.max(t,Math.min(e,o))}u(k,"clamp");function Et(o,t="left"){const e=String(o||t).trim().toLowerCase();return e==="middle"||e==="center"?"center":e==="end"||e==="right"?"right":"left"}u(Et,"normalizeTextAlign");function Ht(o,t="top"){const e=String(o||t).trim().toLowerCase();return e==="center"?"middle":e==="bottom"?"bottom":e==="middle"?"middle":"top"}u(Ht,"normalizeVerticalAlign");function Rn(o,t="c"){const e=String(o||t).trim().toLowerCase();return["nw","n","ne","w","c","e","sw","s","se"].includes(e)?e:t}u(Rn,"normalizePmiAnchor");function Ie(o,t="bottom"){const e=String(o||t).trim().toLowerCase();return["top","bottom","none"].includes(e)?e:t}u(Ie,"normalizePmiLabelPosition");function vn(o,t="shaded"){const e=String(o||t).trim().toLowerCase();return["shaded","monochrome"].includes(e)?e:t}u(vn,"normalizePmiRenderMode");function zn(o,t="solid"){const e=String(o||t).trim();return["none","solid","dotted","dashed","dashDot","longDash","dashDotDot"].includes(e)?e:t}u(zn,"normalizeLineStyle");function nt(o){return["rect","ellipse","triangle","diamond","pentagon","hexagon","parallelogram","trapezoid"].includes(String(o||""))}u(nt,"isShapeElementType");function Le(o){return["parallelogram","trapezoid"].includes(String(o||""))}u(Le,"shapeSupportsAdjustHandle");function kn(o){return Le(o)?.18:0}u(kn,"getDefaultShapeAdjust");function On(o,t){return Le(o)?k(R(t,kn(o)),0,.45):0}u(On,"clampShapeAdjust");function Mn(o){const t=String(o??"").trim().toLowerCase();return t==="rect"?"rect":t==="ellipse"?"ellipse":t==="triangle"?"triangle":t==="diamond"?"diamond":t==="pentagon"?"pentagon":t==="hexagon"?"hexagon":t==="parallelogram"?"parallelogram":t==="trapezoid"?"trapezoid":t==="table"?"table":t==="image"?"image":t==="line"?"line":t==="pmiinset"||t==="pmi_inset"||t==="pmi"||t==="pmiview"?"pmiInset":"text"}u(Mn,"normalizeElementType");const le=class le{constructor(t){this.partHistory=t||null,this.sheets=[],this._listeners=new Set}reset(){this.sheets=[],this._emit()}getSheets(){return this._normalizeSheetsArray(this.sheets),this.sheets}getSheetById(t){const e=String(t??"").trim();return e&&this.getSheets().find(n=>String(n?.id||"")===e)||null}setSheets(t){const e=Array.isArray(t)?Array.from(t):[];return this.sheets=e,this._normalizeSheetsArray(this.sheets),this._emit(),this.sheets}createSheet(t={}){const e=this.getSheets(),n=this._normalizeSheet({...t,id:t?.id||this._generateSheetId()},e.length);return e.push(n),this._emit(),n}duplicateSheet(t){const e=this._resolveSheetIndex(t);if(e<0)return null;const n=this.getSheets()[e],r=z(n)||{};r.id=this._generateSheetId(),r.name=`${V(n?.name,"Sheet")} Copy`,r.elements=Array.isArray(r.elements)?r.elements.map(i=>({...i||{},id:this._generateElementId(r.id)})):[];const s=this._normalizeSheet(r,this.sheets.length);return this.sheets.push(s),this._emit(),s}updateSheet(t,e){const n=this._resolveSheetIndex(t);if(n<0)return null;const r=this.sheets[n];let s=r;if(typeof e=="function")try{const i=e(z(r));i&&typeof i=="object"&&(s=i)}catch{s=r}else e&&typeof e=="object"&&(s={...r,...e});return this.sheets[n]=this._normalizeSheet(s,n,r?.id),this._emit(),this.sheets[n]}moveSheet(t,e){const n=this._resolveSheetIndex(t);if(n<0)return null;const r=this.getSheets(),s=k(Math.round(R(e,n)),0,Math.max(0,r.length-1));if(s===n)return r[n]||null;const[i]=r.splice(n,1);return i?(r.splice(s,0,i),this._normalizeSheetsArray(r),this._emit(),i):null}removeSheet(t){const e=this._resolveSheetIndex(t);if(e<0)return null;const[n]=this.sheets.splice(e,1);return this._normalizeSheetsArray(this.sheets),this._emit(),n||null}addListener(t){return typeof t!="function"?()=>{}:(this._listeners.add(t),()=>{try{this._listeners.delete(t)}catch{}})}removeListener(t){if(typeof t=="function")try{this._listeners.delete(t)}catch{}}notifyChanged(){this._emit()}toSerializable(){return this.getSheets().map(t=>z(t))}_resolveSheetIndex(t){if(Number.isInteger(t)){const n=Number(t);return n>=0&&n<this.getSheets().length?n:-1}const e=String(t??"").trim();return e?this.getSheets().findIndex(n=>String(n?.id||"")===e):-1}_generateSheetId(){const t=new Set(this.getSheets().map(n=>String(n?.id||"")));let e=1;for(;t.has(`sheet-${e}`);)e+=1;return`sheet-${e}`}_generateElementId(t="sheet"){return`${String(t||"sheet").replace(/[^A-Za-z0-9_-]/g,"_")}:el:${Date.now().toString(36)}:${Math.random().toString(36).slice(2,7)}`}_normalizeSheetsArray(t){if(!Array.isArray(t))return this.sheets=[],this.sheets;for(let e=0;e<t.length;e++){const n=t[e]?.id;t[e]=this._normalizeSheet(t[e],e,n)}return t}_normalizeSheet(t,e,n=null){const r=t&&typeof t=="object"?t:{},s=Te(r.sizeKey),i=Me(r.orientation),c=Math.max(1,R(r.customWidthIn??r.widthIn,s.widthIn)),m=Math.max(1,R(r.customHeightIn??r.heightIn,s.heightIn)),a=Sn(s.key,i,{customWidthIn:c,customHeightIn:m}),y=V(n||r.id||this._generateSheetId(),"").trim()||this._generateSheetId(),f=V(r.name,"").trim()||`Sheet ${e+1}`,l=Array.isArray(r.elements)?r.elements:[],h=[],d=new Set;for(let g=0;g<l.length;g++){const S=this._normalizeElement(l[g],g,y,a);S&&(d.has(S.id)&&(S.id=this._generateElementId(y)),d.add(S.id),h.push(S))}return{id:y,name:f,sizeKey:a.key,sizeLabel:a.label,orientation:a.orientation,units:a.units,widthIn:a.widthIn,heightIn:a.heightIn,customWidthIn:a.key==="CUSTOM"?a.widthIn:void 0,customHeightIn:a.key==="CUSTOM"?a.heightIn:void 0,widthPx:a.widthPx,heightPx:a.heightPx,pxPerInch:a.pxPerInch,background:Q(r.background,"#ffffff"),elements:h,metadata:{createdAt:Number.isFinite(Number(r?.metadata?.createdAt))?Number(r.metadata.createdAt):Date.now(),updatedAt:Date.now()}}}_normalizeElement(t,e,n,r){const s=t&&typeof t=="object"?t:{},i=Mn(s.type),c=Math.max(.1,R(r?.widthIn,11)),m=Math.max(.1,R(r?.heightIn,8.5)),a=-c*2,y=-m*2,f=c*3,l=m*3,h=k(R(s.x,c*.1),a,f),d=k(R(s.y,m*.1),y,l),g=V(s.id,"").trim()||this._generateElementId(n),S=Number.isInteger(s.z)?s.z:Number.isInteger(s.layer)?s.layer:e,p={id:g,type:i,groupId:V(s.groupId,"").trim()||void 0,formboard:s.formboard&&typeof s.formboard=="object"?z(s.formboard):void 0,x:h,y:d,rotationDeg:R(s.rotationDeg,0),z:Number.isFinite(Number(S))?Number(S):e,fill:Q(s.fill,i==="text"||i==="pmiInset"?"transparent":i==="table"?"#ffffff":"#dbeafe"),stroke:Q(s.stroke,i==="table"?"#0f172a":"#1d4ed8"),strokeWidth:k(R(s.strokeWidth,.02),.002,1),lineStyle:zn(s.lineStyle,"solid"),opacity:k(R(s.opacity,1),0,1)};if(i==="line"){const tt=k(R(s.x2,h+1),a,f),E=k(R(s.y2,d),y,l);return{...p,x2:tt,y2:E,strokeWidth:k(R(s.strokeWidth,.035),.002,1)}}const b=Number.isFinite(Number(s.w)),w=Number.isFinite(Number(s.h)),C=R(b?s.w:s.width??(s.radiusX!=null?R(s.radiusX,.8)*2:1.4),1.4),D=R(w?s.h:s.height??(s.radiusY!=null?R(s.radiusY,.55)*2:.9),.9),O=k(C,.05,c*8),j=k(D,.05,m*8),H=!b&&!w&&Number.isFinite(Number(s.width))&&Number.isFinite(Number(s.height)),ot=!b&&!w&&Number.isFinite(Number(s.radiusX))&&Number.isFinite(Number(s.radiusY)),ft=k(H||ot?R(s.x,c*.5)-O*.5:h,a,f),J=k(H||ot?R(s.y,m*.5)-j*.5:d,y,l);if(i==="table"){const tt=String(s.fontStyle||(s.italic?"italic":"normal")).toLowerCase()==="italic"?"italic":"normal",E=String(s.fontWeight||(s.bold?"700":"400"));return{...p,x:ft,y:J,w:k(C,.4,c*8),h:k(D,.3,m*8),tableData:Nt(s.tableData,s.rows??3,s.cols??4),fontSize:k(R(s.fontSize,.22),.08,3),fontFamily:V(s.fontFamily,"Arial, Helvetica, sans-serif"),fontWeight:/^\d{3}$/.test(E)?E:E==="bold"?"700":"400",fontStyle:tt,textDecoration:String(s.textDecoration||"none").toLowerCase()==="underline"?"underline":"none",textAlign:Et(s.textAlign||s.textAnchor,"left"),verticalAlign:Ht(s.verticalAlign||s.verticalAnchor,"middle"),color:Q(s.color,Q(s.textColor,"#111111"))}}if(nt(i)||i==="image"||i==="pmiInset"){const tt=String(s.fontStyle||(s.italic?"italic":"normal")).toLowerCase()==="italic"?"italic":"normal",E=String(s.fontWeight||(s.bold?"700":"400"));return{...p,x:ft,y:J,w:O,h:j,cornerRadius:k(R(s.cornerRadius,i==="rect"?.1:0),0,Math.min(O,j)*.5),shapeAdjust:On(i,s.shapeAdjust),src:i==="image"||i==="pmiInset"?V(s.src,""):void 0,mediaScale:i==="image"||i==="pmiInset"?k(R(s.mediaScale,1),1,10):void 0,mediaOffsetX:i==="image"||i==="pmiInset"?k(R(s.mediaOffsetX,0),-1,1):void 0,mediaOffsetY:i==="image"||i==="pmiInset"?k(R(s.mediaOffsetY,0),-1,1):void 0,pmiViewIndex:i==="pmiInset"?Number.isInteger(s.pmiViewIndex)?s.pmiViewIndex:-1:void 0,pmiViewName:i==="pmiInset"?V(s.pmiViewName,"PMI View"):void 0,pmiImageRevision:i==="pmiInset"?Number.isInteger(s.pmiImageRevision)?s.pmiImageRevision:0:void 0,pmiModelRevision:i==="pmiInset"?Number.isInteger(s.pmiModelRevision)?s.pmiModelRevision:-1:void 0,pmiImageCaptureKey:i==="pmiInset"?V(s.pmiImageCaptureKey,""):void 0,showTitle:i==="pmiInset"?Ie(s.pmiLabelPosition,s.showTitle!==!1?"bottom":"none")!=="none":void 0,pmiLabelPosition:i==="pmiInset"?Ie(s.pmiLabelPosition,s.showTitle!==!1?"bottom":"none"):void 0,pmiRenderMode:i==="pmiInset"?vn(s.pmiRenderMode,"shaded"):void 0,pmiShowCenterLines:i==="pmiInset"?s.pmiShowCenterLines===!0:void 0,pmiAnchor:i==="pmiInset"?Rn(s.pmiAnchor,"c"):void 0,text:nt(i)?V(s.text,""):void 0,fontSize:nt(i)?k(R(s.fontSize,.28),.08,3):void 0,fontFamily:nt(i)?V(s.fontFamily,"Arial, Helvetica, sans-serif"):void 0,fontWeight:nt(i)?/^\d{3}$/.test(E)?E:E==="bold"?"700":"400":void 0,fontStyle:nt(i)?tt:void 0,textAlign:nt(i)?Et(s.textAlign||s.textAnchor,"center"):void 0,verticalAlign:nt(i)?Ht(s.verticalAlign||s.verticalAnchor,"middle"):void 0,color:nt(i)?Q(s.color,Q(s.textColor,"#0f172a")):void 0}}const Y=Et(s.textAlign||s.textAnchor,"left"),G=String(s.fontStyle||(s.italic?"italic":"normal")).toLowerCase()==="italic"?"italic":"normal",q=String(s.fontWeight||(s.bold?"700":"400"));return{...p,w:k(R(b?s.w:s.width,3.2),.1,c*8),h:k(R(w?s.h:s.height,1.1),.1,m*8),text:V(s.text,`Text ${e+1}`),fontSize:k(R(s.fontSize,.32),.08,3),fontFamily:V(s.fontFamily,"Arial, Helvetica, sans-serif"),fontWeight:/^\d{3}$/.test(q)?q:q==="bold"?"700":"400",fontStyle:G,textAlign:Y,verticalAlign:Ht(s.verticalAlign||s.verticalAnchor,"top"),color:Q(s.color,Q(s.textColor,Q(s.fill,"#111111")))}}_emit(){if(!this._listeners||this._listeners.size===0)return;const t=this.getSheets();for(const e of Array.from(this._listeners))try{e(t,this.partHistory||null)}catch{}}};u(le,"Sheet2DManager");let Jt=le;function xt(o,t=0){const e=Number(o);return Number.isFinite(e)?e:t}u(xt,"toFiniteNumber");function B(o,t=""){return String(o??"").trim()||t}u(B,"normalizeText");function $t(o,t=0){const e=o&&typeof o=="object"?o:{},n=Number.isInteger(t)?t+1:1;return{id:B(e.id,`wire-${n}`),name:B(e.name,`Wire ${n}`),from:B(e.from,""),to:B(e.to,""),diameter:Math.max(.01,xt(e.diameter,1))}}u($t,"normalizeConnection");function Tn(o){return!Array.isArray(o)||o.length<3?null:[xt(o[0],0),xt(o[1],0),xt(o[2],0)]}u(Tn,"normalizePointArray");function xe(o){return Array.isArray(o)?o.map(t=>B(t,"")).filter(Boolean):[]}u(xe,"normalizeStringArray");function jn(o,t=new Map){const e=o&&typeof o=="object"?o:{},n=B(e.connectionId,""),r=t.get(n)||null,s=!!e.feasible;return{connectionId:n,connectionName:B(e.connectionName,r?.name||n||"Wire"),feasible:s,error:B(e.error,s?"":"No route found through the harness network."),distance:Number.isFinite(Number(e.distance))?Number(e.distance):null,polyline:(Array.isArray(e.polyline)?e.polyline:[]).map(i=>Tn(i)).filter(Boolean),segmentIds:xe(e.segmentIds),nodePath:xe(e.nodePath),reusesHarnessPoint:!!e.reusesHarnessPoint,diameter:Math.max(.01,xt(e.diameter,r?.diameter||1)),from:B(e.from,r?.from||""),to:B(e.to,r?.to||"")}}u(jn,"normalizeRouteResult");const ue=class ue{constructor(t){this.partHistory=t||null,this.connections=[],this.routeResults=[],this._pendingRestoredRouteResults=null,this._listeners=new Set}reset(){this.connections=[],this.routeResults=[],this._pendingRestoredRouteResults=null,this._emit()}getConnections(){return this._normalizeConnectionsArray(this.connections),this.connections}setConnections(t){const e=Array.isArray(t)?Array.from(t):[];return this.connections=e,this._normalizeConnectionsArray(this.connections),this._pendingRestoredRouteResults=null,this._emit(),this.connections}addConnection(t={}){const e=this.getConnections(),n=$t({id:t?.id||this._generateConnectionId(),...t},e.length);return e.push(n),this._emit(),n}updateConnection(t,e){const n=this.getConnections(),r=B(t,""),s=n.findIndex(m=>String(m?.id||"")===r);if(s<0)return null;const i=n[s];let c=i;if(typeof e=="function")try{const m=e(z(i));m&&typeof m=="object"&&(c=m)}catch{c=i}else e&&typeof e=="object"&&(c={...i,...e});return n[s]=$t(c,s),n[s].id||(n[s].id=i.id),this._emit(),n[s]}removeConnection(t){const e=this.getConnections(),n=B(t,""),r=e.findIndex(i=>String(i?.id||"")===n);if(r<0)return null;const[s]=e.splice(r,1);return this.routeResults=this.routeResults.filter(i=>String(i?.connectionId||"")!==n),this._normalizeConnectionsArray(e),this._emit(),s||null}getRouteResults(){return this._normalizeRouteResultsArray(this.routeResults),Array.isArray(this.routeResults)?this.routeResults:[]}setRouteResults(t,e={}){const n=!!e?.preservePendingRestore,r=!!e?.markPendingRestore;return this.routeResults=Array.isArray(t)?t.map(s=>({...s||{}})):[],this._normalizeRouteResultsArray(this.routeResults),r?this._pendingRestoredRouteResults=this.routeResults.map(s=>z(s)):n||(this._pendingRestoredRouteResults=null),this._emit(),this.routeResults}clearRouteResults(t={}){this.routeResults=[],t?.preservePendingRestore||(this._pendingRestoredRouteResults=null),this._emit()}getRouteResultMap(){const t=new Map;for(const e of this.getRouteResults()){const n=B(e?.connectionId,"");n&&t.set(n,e)}return t}addListener(t){return typeof t!="function"?()=>{}:(this._listeners.add(t),()=>{try{this._listeners.delete(t)}catch{}})}removeListener(t){if(typeof t=="function")try{this._listeners.delete(t)}catch{}}notifyChanged(){this._emit()}toSerializable(){return{connections:this.getConnections().map(t=>z(t)),routeResults:this.getRouteResults().map(t=>z(t))}}loadSerializable(t){const e=t&&typeof t=="object"&&!Array.isArray(t)?t:{connections:t,routeResults:[]};return this.connections=Array.isArray(e.connections)?Array.from(e.connections):[],this._normalizeConnectionsArray(this.connections),this.routeResults=Array.isArray(e.routeResults)?Array.from(e.routeResults):[],this._normalizeRouteResultsArray(this.routeResults),this._pendingRestoredRouteResults=this.routeResults.length?this.routeResults.map(n=>z(n)):null,this._emit(),this.toSerializable()}consumePendingRestoredRouteResults(){const t=Array.isArray(this._pendingRestoredRouteResults)?this._pendingRestoredRouteResults.map(e=>z(e)):null;return this._pendingRestoredRouteResults=null,t}_generateConnectionId(){const t=new Set(this.getConnections().map(n=>String(n?.id||"")));let e=1;for(;t.has(`wire-${e}`);)e+=1;return`wire-${e}`}_normalizeConnectionsArray(t){if(!Array.isArray(t))return this.connections=[],this.connections;for(let e=0;e<t.length;e+=1)t[e]=$t(t[e],e);return t}_normalizeRouteResultsArray(t){if(!Array.isArray(t))return this.routeResults=[],this.routeResults;const e=new Map(this.getConnections().map(n=>[String(n?.id||""),n]));for(let n=0;n<t.length;n+=1)t[n]=jn(t[n],e);return t}_emit(){if(!this._listeners||this._listeners.size===0)return;const t={connections:this.getConnections(),routeResults:this.getRouteResults(),manager:this,partHistory:this.partHistory||null};for(const e of Array.from(this._listeners))try{e(t)}catch{}}};u(ue,"WireHarnessManager");let Qt=ue;const Ce=!1,_e=new Set(["__open"]);function Lt(o,t=null){if(!o)return t;const e=o.inputParams||{},n=e.id??e.featureID??o.id??t;return n==null?t:String(n)}u(Lt,"resolveFeatureEntryId");function Ne(o){const t=o&&typeof o=="object"?o:{};try{const e=JSON.stringify(t,(n,r)=>{if(!(n&&_e.has(n)))return r});return e??""}catch{try{const e={};for(const[n,r]of Object.entries(t))_e.has(n)||(e[n]=r);return JSON.stringify(e)||""}catch{return""}}}u(Ne,"stringifyInputParamsForDirtyCheck");var P,Ue,Pt,Ve,We,ee,ne,re,Be,Ft,se,Rt,vt;const st=class st{constructor(){Mt(this,P);this.features=[],this.scene=new tn,this.idCounter=0,this.featureRegistry=new Qe,this.assemblyConstraintRegistry=new De,this.assemblyConstraintHistory=new Wt(this,this.assemblyConstraintRegistry),this.callbacks={},this._modelRevision=0,this._modelChangeListeners=new Set,this.currentHistoryStepId=null,this.runningFeatureId=null,this.expressions=`//Examples:
2
2
  x = 10 + 6;
3
3
  y = x * 2;`,this.activeWorkbench=Tt(),this.pmiViewsManager=new Gt(this),this.sheet2DManager=new Jt(this),this.wireHarnessManager=new Qt(this),this.metadataManager=new zt,this._historyUndo={undoStack:[],redoStack:[],max:50,debounceMs:350,pendingTimer:null,lastSignature:null,captureInFlight:!1,pendingRequest:!1,isApplying:!1},this.assemblyConstraintHistory&&(this.assemblyConstraintHistory.clear(),this.assemblyConstraintHistory.setPartHistory(this));const t=this.scene.remove;this.scene.remove=(...n)=>{n[0]?.userData?.preventRemove||t.apply(this.scene,n)};const e=this.scene.add;this.scene.add=(...n)=>{e.apply(this.scene,n)}}captureVisibilityState(){const t=A(this,P,se).call(this);return Array.from(t.entries()).map(([e,n])=>({key:e,count:Math.max(1,Number(n)||1)}))}applyVisibilityState(t){const e=new Map,n=Array.isArray(t)?t:[];for(const r of n){const s=typeof r=="string"?r:String(r?.key||"");if(!s)continue;const i=Math.max(1,Math.round(Number(typeof r=="string"?1:r?.count)||1));e.set(s,(e.get(s)||0)+i)}return this.scene&&typeof this.scene.traverse=="function"&&this.scene.traverse(r=>{if(!(!r||!A(this,P,Ft).call(this,r)))try{r.visible=!0}catch{}}),A(this,P,Rt).call(this,e),e}static evaluateExpression(t,e){const r=`${typeof t=="string"?t:""}; return ${e} ;`;try{let s=Function(r)();if(typeof s=="string"){const i=Number(s);if(!Number.isNaN(i))return i}return s}catch(s){try{console.warn("[PartHistory] evaluateExpression failed:",s?.message||s)}catch{}return null}}evaluateExpression(t){return st.evaluateExpression(this.expressions,t)}getModelRevision(){return Number.isInteger(this._modelRevision)?this._modelRevision:0}addModelChangeListener(t){return typeof t!="function"?()=>{}:(this._modelChangeListeners.add(t),()=>{try{this._modelChangeListeners.delete(t)}catch{}})}removeModelChangeListener(t){if(typeof t=="function")try{this._modelChangeListeners.delete(t)}catch{}}markModelChanged(t="update"){const e=this.getModelRevision()+1;if(this._modelRevision=e,!this._modelChangeListeners||this._modelChangeListeners.size===0)return e;const n={reason:t,partHistory:this,revision:e};for(const r of Array.from(this._modelChangeListeners))try{r(e,n)}catch{}return e}getObjectByName(t){return this.scene.getObjectByName(t)}async reset(){if(this.features=[],this.idCounter=0,this.pmiViewsManager.reset(),this.sheet2DManager.reset(),this.wireHarnessManager.reset(),this.expressions=`//Examples:
4
4
  x = 10 + 6;
@@ -1 +1 @@
1
- var ye=Object.defineProperty;var b=(e,o)=>ye(e,"name",{value:o,configurable:!0});import{aD as H,V as z,b as ge,M as pe,aC as X}from"./featureDialogs-CUWi02Qp.js";import"./browserStorage-CvgF8ovw.js";import"./preload-helper-ZNr0Qq7Q.js";const Z=32,I=1e-9,W=I*I;function oe(e){const o=[];if(!Array.isArray(e))return o;for(const t of e){if(!Array.isArray(t)||t.length<3)continue;const n=Number(t[0]),i=Number(t[1]),a=Number(t[2]);!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(a)||o.push(new z(n,i,a))}return o}b(oe,"toVector3Array");function Y(e,o=1e-7){if(!Array.isArray(e)||e.length===0)return[];const t=o*o,n=[e[0].clone()];for(let i=1;i<e.length;i++){const a=e[i];a&&a.distanceToSquared(n[n.length-1])>t&&n.push(a.clone())}return n}b(Y,"dedupeVectors");function _e(e,o){if(!Array.isArray(e)||e.length<2)return Array.isArray(e)?e.map(n=>n.clone()):[];if(e.length===2)return e.map(n=>n.clone());const t=[];t.push(e[0].clone());for(let n=1;n<e.length-1;n++){const i=e[n-1],a=e[n],s=e[n+1];if(!i||!a||!s){t.push(a.clone());continue}const r=a.clone().sub(i),c=s.clone().sub(a);if(r.lengthSq()<W||c.lengthSq()<W){t.push(a.clone());continue}r.normalize(),c.normalize();const u=ge.clamp(r.dot(c),-1,1),h=Math.acos(Math.abs(u));if(h>Math.PI/3){const l=h*.5,d=o/Math.tan(l),g=i.distanceTo(a),f=a.distanceTo(s),S=Math.min(d*.8,g*.6),V=Math.min(d*.8,f*.6);if(S>o*.1&&V>o*.1){const w=a.clone().addScaledVector(r,-S),_=a.clone().addScaledVector(c,V);t[t.length-1].distanceTo(w)>1e-6&&t.push(w),t.push(_)}else t.push(a.clone())}else t.push(a.clone())}return t.push(e[e.length-1].clone()),Y(t,1e-6)}b(_e,"calculateTubeIntersectionTrimming");function Se(e,o){try{const t=_e(e,o);return!Array.isArray(t)||t.length<2?Array.isArray(e)?e.map(n=>n.clone()):[]:Y(t,1e-9)}catch(t){return console.error("Error in smoothPath:",t),e.map(n=>n.clone())}}b(Se,"smoothPath");const J=new z,se=new z,ae=new z,ie=new z;function we(e,o=!1){const t=[],n=[],i=[];if(!Array.isArray(e)||e.length<2)return{tangents:t,normals:n,binormals:i};const a=new z;for(let s=0;s<e.length;s++){const r=new z;if(o){const c=(s-1+e.length)%e.length,u=(s+1)%e.length,h=new z().subVectors(e[u],e[s]),l=new z().subVectors(e[s],e[c]),d=h.length(),g=l.length();d>I&&g>I?(h.normalize(),l.normalize(),r.addVectors(h,l).normalize()):d>I?r.copy(h).normalize():g>I?r.copy(l).normalize():r.set(0,0,1)}else if(s===0)r.subVectors(e[1],e[0]);else if(s===e.length-1)r.subVectors(e[s],e[s-1]);else{const c=new z().subVectors(e[s+1],e[s]),u=new z().subVectors(e[s],e[s-1]),h=c.length(),l=u.length();h>I&&l>I?(c.normalize(),u.normalize(),r.addVectors(c,u).normalize()):h>I?r.copy(c).normalize():l>I?r.copy(u).normalize():r.copy(s>0?t[s-1]:new z(0,0,1))}t.push(r.normalize())}a.set(0,0,1),Math.abs(t[0].dot(a))>.99&&a.set(1,0,0),n.push(new z().crossVectors(t[0],a).cross(t[0]).normalize()),i.push(new z().crossVectors(t[0],n[0]).normalize());for(let s=1;s<e.length;s++){n.push(n[s-1].clone()),i.push(i[s-1].clone());const r=t[s-1].dot(t[s]);if(r<=1-I){const c=new z().crossVectors(t[s-1],t[s]).normalize(),u=Math.acos(ge.clamp(r,-1,1)),h=new pe().makeRotationAxis(c,u);n[s].applyMatrix4(h).normalize(),i[s].crossVectors(t[s],n[s]).normalize()}}if(o&&e.length>2){const s=n.reduce((r,c)=>r.add(c),new z).normalize();for(let r=0;r<n.length;r++){const c=n[r].clone().sub(t[r].clone().multiplyScalar(t[r].dot(n[r])));c.lengthSq()>W?(n[r].copy(c.normalize()),i[r].crossVectors(t[r],c).normalize()):(n[r].copy(s),i[r].crossVectors(t[r],s).normalize())}}return{tangents:t,normals:n,binormals:i}}b(we,"computeFrames");function be(e,o,t,n,i,a){const s=[],r=i>0?[]:null;for(let c=0;c<e.length;c++){const u=o[c],h=t[c],l=[],d=r?[]:null;for(let g=0;g<a;g++){const f=g/a*Math.PI*2,S=Math.cos(f),V=Math.sin(f),w=u.clone().multiplyScalar(S).add(h.clone().multiplyScalar(V)),_=e[c].clone().addScaledVector(w,n);if(l.push([_.x,_.y,_.z]),r&&i>0){const x=e[c].clone().addScaledVector(w,i);d.push([x.x,x.y,x.z])}}s.push(l),r&&i>0&&r.push(d)}return{outer:s,inner:r}}b(be,"buildRings");function ee(e,o,t,n,i,a){if(!a||a.lengthSq()<1e-10){e.addTriangle(o,t,n,i);return}J.set(t[0],t[1],t[2]),se.set(n[0],n[1],n[2]).sub(J),ae.set(i[0],i[1],i[2]).sub(J),ie.copy(se).cross(ae),ie.dot(a)<0?e.addTriangle(o,t,i,n):e.addTriangle(o,t,n,i)}b(ee,"addTriangleOriented");function te(e,o,t,n,i,a,s){ee(e,o,t,n,i,s),ee(e,o,t,i,a,s)}b(te,"addQuadOriented");function ce(e,o,t,n,i){for(let a=0;a<n.length;a++){const s=(a+1)%n.length;ee(e,o,t,n[a],n[s],i)}}b(ce,"addDiskCap");function le(e,o,t,n,i){const a=t.length;for(let s=0;s<a;s++){const r=(s+1)%a;te(e,o,t[s],t[r],n[r],n[s],i)}}b(le,"addRingCap");function he(e,o,{auxEdges:t}={}){e._numProp=o._numProp,e._vertProperties=o._vertProperties,e._triVerts=o._triVerts,e._triIDs=o._triIDs,e._vertKeyToIndex=new Map(o._vertKeyToIndex),e._idToFaceName=new Map(o._idToFaceName),e._faceNameToID=new Map(o._faceNameToID),e._faceMetadata=new Map(o._faceMetadata),e._edgeMetadata=new Map(o._edgeMetadata),e._auxEdges=t!==void 0?t:Array.isArray(o._auxEdges)?o._auxEdges:[],e._manifold=o._manifold,e._dirty=!1,e._faceIndex=null}b(he,"copySolidState");function xe(e,o,t){const n=Y(e,t);if(n.length<2)return{points:n,closed:!1};const i=n[0],a=n[n.length-1],s=Math.max(t*4,I),r=!!o||i.distanceToSquared(a)<=s*s;return r&&i.distanceToSquared(a)<=s*s&&n.pop(),{points:n,closed:r}}b(xe,"normalizePath");function fe(e,o,t=!1){if(!e||!o)return null;const n=new z().subVectors(o,e);return n.lengthSq()<=I?null:(t&&n.negate(),n.normalize(),{anchor:e,normalVec:n,normalArray:[n.x,n.y,n.z],offset:n.dot(e)})}b(fe,"trimPlaneFromPoints");function ue(e,o,t,n,i=!0){if(!n||!Array.isArray(e)||!Array.isArray(o)||!(t>0))return;const a=i?0:e.length-1,s=i?e.length:-1,r=i?1:-1;for(let c=a;c!==s;c+=r){const u=o[c];if(!u)continue;if(u.distanceTo(n.anchor)>t)break;const h=e[c];if(!h)continue;const l=h.trimByPlane(n.normalArray,n.offset);if(!l){e[c]=l;continue}if(l!==h){try{typeof h.delete=="function"&&h.delete()}catch{}e[c]=l}else e[c]=l}}b(ue,"applyTrimPlaneSequentially");function ze(e,o,t,n,{keepSpheres:i=!1,trimPlanes:a=null}={}){if(!Array.isArray(e)||e.length<2)return{hull:null,spheres:[]};const s=X.sphere(o,t),r=e.map(l=>s.translate([l.x,l.y,l.z]));try{typeof s.delete=="function"&&s.delete()}catch{}!n&&a&&(a.start&&ue(r,e,o,a.start,!0),a.end&&ue(r,e,o,a.end,!1));const c=[],u=n?e.length:e.length-1;for(let l=0;l<u;l++){const d=e[l],g=e[(l+1)%e.length],f=r[l],S=r[(l+1)%r.length];!d||!g||!f||!S||d.distanceToSquared(g)<I*I||c.push(X.hull([f,S]))}if(!i)for(const l of r)try{l&&typeof l.delete=="function"&&l.delete()}catch{}if(!c.length)return{hull:null,spheres:i?r:[]};if(c.length===1)return{hull:c[0],spheres:i?r:[]};let h=null;try{return h=X.union(c),{hull:h,spheres:i?r:[]}}finally{for(const l of c)if(l&&l!==h)try{typeof l.delete=="function"&&l.delete()}catch{}}}b(ze,"buildHullChain");function de(e,o,t,n,i=!1,a=null){const{hull:s,spheres:r}=ze(e,o,t,n,{keepSpheres:i,trimPlanes:a});if(!s)throw new Error("Unable to build tube hulls from the supplied path.");return{manifold:s,spheres:r}}b(de,"buildHullTube");function Me(e){if(!Array.isArray(e)||e.length<2)return[];const o=[];for(let t=0;t<e.length-1;t++){const n=e[t],i=e[t+1];if(!n||!i)continue;const a=n.x,s=n.y,r=n.z,c=i.x-a,u=i.y-s,h=i.z-r,l=c*c+u*u+h*h;o.push({ax:a,ay:s,az:r,dx:c,dy:u,dz:h,lenSq:l})}return o}b(Me,"buildPolylineSegmentCache");function Ae(e,o,t,n,i=1/0){if(!Array.isArray(n)||n.length===0)return 1/0;let a=1/0;for(let s=0;s<n.length;s++){const r=n[s];if(!r||r.lenSq<=W)continue;const c=e-r.ax,u=o-r.ay,h=t-r.az;let l=(c*r.dx+u*r.dy+h*r.dz)/r.lenSq;l<0?l=0:l>1&&(l=1);const d=r.ax+r.dx*l,g=r.ay+r.dy*l,f=r.az+r.dz*l,S=e-d,V=o-g,w=t-f,_=S*S+V*V+w*w;if(_<a&&(a=_,a<=i))break}return a}b(Ae,"minDistanceToPolylineSq");function Te(e,o,t,n,i,a,s,r){if(!e||!e._vertProperties||!e._triVerts)return e;const c=e._triVerts.length/3|0;if(!c)return e;e._faceNameToID=new Map,e._idToFaceName=new Map;const u=t?t.clone().normalize():null,h=n?n.clone().normalize():null,l=o[0],d=o[o.length-1],g=u?u.dot(l):0,f=h?h.dot(d):0,S=Math.max(i*.01,1e-5),V=(i+S)*(i+S),w=e._getOrCreateID(`${r}_Outer`),_=a>0?e._getOrCreateID(`${r}_Inner`):w,x=!s&&u?e._getOrCreateID(`${r}_CapStart`):w,M=!s&&h?e._getOrCreateID(`${r}_CapEnd`):w,O=new Array(c),A=e._vertProperties,N=e._triVerts,E=a>0?(a+i)*.5:i*.5,q=E*E,y=a>0?Me(o):null,m=u?u.x:0,p=u?u.y:0,T=u?u.z:0,$=h?h.x:0,D=h?h.y:0,F=h?h.z:0;for(let C=0;C<c;C++){const v=N[C*3+0]*3,G=N[C*3+1]*3,Q=N[C*3+2]*3,L=(A[v+0]+A[G+0]+A[Q+0])/3,k=(A[v+1]+A[G+1]+A[Q+1])/3,U=(A[v+2]+A[G+2]+A[Q+2])/3;let P=w;if(!s&&u&&Math.abs(m*L+p*k+T*U-g)<=S){const j=L-l.x,K=k-l.y,B=U-l.z;j*j+K*K+B*B<=V&&(P=x)}if(P===w&&!s&&h&&Math.abs($*L+D*k+F*U-f)<=S){const j=L-d.x,K=k-d.y,B=U-d.z;j*j+K*K+B*B<=V&&(P=M)}P===w&&a>0&&(P=Ae(L,k,U,y,q)<=q?_:w),P!==w&&P!==_&&P!==x&&P!==M&&(P=w),O[C]=P}e._triIDs=O,e._idToFaceName=new Map([[w,`${r}_Outer`],...a>0?[[_,`${r}_Inner`]]:[],...!s&&u?[[x,`${r}_CapStart`]]:[],...!s&&h?[[M,`${r}_CapEnd`]]:[]]),e._faceNameToID=new Map([...e._idToFaceName.entries()].map(([C,v])=>[v,C]));try{typeof e.free=="function"&&e.free()}catch{}e._dirty=!0,e._faceIndex=null;try{e._manifoldize()}catch{}return e}b(Te,"relabelFaces");function Ee(e){if(!Array.isArray(e)||e.length<2)return null;for(let o=1;o<e.length;o++){const t=new z().subVectors(e[o],e[o-1]);if(t.lengthSq()>I)return t.normalize()}return null}b(Ee,"firstTangent");function Ie(e){if(!Array.isArray(e)||e.length<2)return null;for(let o=e.length-1;o>=1;o--){const t=new z().subVectors(e[o],e[o-1]);if(t.lengthSq()>I)return t.normalize()}return null}b(Ie,"lastTangent");function R(e,o){const t=o||"Sphere",n=H._fromManifold(e,new Map([[0,t]])),i=n._getOrCreateID(t),a=n._triVerts.length/3|0;n._triIDs=new Array(a).fill(i),n._idToFaceName=new Map([[i,t]]),n._faceNameToID=new Map([[t,i]]),n._dirty=!0;try{n._manifoldize()}catch{}return n}b(R,"singleFaceSolidFromManifold");const ne=class ne extends H{constructor(o={}){super();const{points:t=[],radius:n=1,innerRadius:i=0,resolution:a=Z,closed:s=!1,name:r="Tube",debugSpheres:c=!1,preferFast:u=!0,selfUnion:h=!0,autoVisualize:l=!1}=o;if(this.params={points:t,radius:n,innerRadius:i,resolution:a,closed:s,name:r,debugSpheres:c,preferFast:u,selfUnion:h},this.name=r,Array.isArray(t)&&t.length>=2){const d=t[0],g=t[t.length-1];d[0]===g[0]&&d[1]===g[1]&&d[2]===g[2]&&(this.params.closed=!0)}try{const d=Array.isArray(t)&&t.length>=2,g=Number(n)>0;d&&g&&(this.generate(),l&&this.visualize())}catch{}}generate(){if(this.params?.preferFast!==!1)try{if(this.generateFast(),this._selfUnionStats?.selfIntersectionLikely){if(typeof this.free=="function")try{this.free()}catch{}return this.generateSlow()}return this}catch(t){if(console.warn("Tube fast generation failed; falling back to slow.",t),typeof this.free=="function")try{this.free()}catch{}}return this.generateSlow()}generateFast(){let{points:o,radius:t,innerRadius:n,resolution:i,closed:a,name:s}=this.params,r=!!a;if(!(t>0))throw new Error("Tube radius must be greater than zero.");const c=Number(n)||0;if(c<0)throw new Error("Inside radius cannot be negative.");if(c>0&&c>=t)throw new Error("Inside radius must be smaller than the outer radius.");const u=Math.max(8,Math.floor(Number(i)||Z)),h=Y(oe(o));if(h.length<2)throw new Error(`Tube requires at least two distinct path points. Got ${h.length} valid points from ${o.length} input points.`);const l=h.reduce((y,m)=>Math.max(y,Math.abs(m.x),Math.abs(m.y),Math.abs(m.z)),Math.max(1e-6,t)),d=Math.max(1e-7,t*1e-5,l*1e-6),g=d*d;!r&&h.length>=2&&h[0].distanceToSquared(h[h.length-1])<=g&&(r=!0);let f;try{f=Se(h,t)}catch(y){throw console.error("Error in smoothPath:",y),new Error(`Path smoothing failed: ${y.message}`)}if(f.length<2)throw new Error(`Tube path collapsed after smoothing; check input. Original: ${h.length}, Smoothed: ${f.length}`);if(f.length>1){const y=f[0],m=f[f.length-1],p=y.distanceToSquared(m);!r&&p<=g&&(r=!0),r&&p<=g&&f.length>2&&(f=f.slice(0,-1))}this.params.closed=r;const{tangents:S,normals:V,binormals:w}=we(f,r);if(S.length<2)throw new Error("Unable to compute frames for tube path.");this._numProp=3,this._vertProperties=[],this._triVerts=[],this._triIDs=[],this._vertKeyToIndex=new Map,this._idToFaceName=new Map,this._faceNameToID=new Map,this._faceMetadata=new Map,this._edgeMetadata=new Map,this._auxEdges=[],this._dirty=!0;const{outer:_,inner:x}=be(f,V,w,t,c,u),M=s||"Tube",O=r?_.length:_.length-1;for(let y=0;y<O;y++){const m=_[y],p=_[(y+1)%_.length],T=(y+1)%f.length,$=f[T].clone().sub(f[y]).normalize();for(let D=0;D<u;D++){const F=(D+1)%u;te(this,`${M}_Outer`,m[D],m[F],p[F],p[D],$)}}if(x){const y=r?x.length:x.length-1;for(let m=0;m<y;m++){const p=x[m],T=x[(m+1)%x.length],$=(m+1)%f.length,F=f[$].clone().sub(f[m]).normalize().clone().negate();for(let C=0;C<u;C++){const v=(C+1)%u;te(this,`${M}_Inner`,p[C],T[C],T[v],p[v],F)}}}if(!r){const y=[f[0].x,f[0].y,f[0].z],m=[f[f.length-1].x,f[f.length-1].y,f[f.length-1].z],p=S[0].clone().negate(),T=S[S.length-1].clone();x?(le(this,`${M}_CapStart`,_[0],x[0],p),le(this,`${M}_CapEnd`,_[_.length-1],x[x.length-1],T)):(ce(this,`${M}_CapStart`,y,_[0],p),ce(this,`${M}_CapEnd`,m,_[_.length-1],T))}try{const y=f.map(m=>[m.x,m.y,m.z]);if(r&&y.length>=2){const m=y[0],p=y[y.length-1],T=m[0]-p[0],$=m[1]-p[1],D=m[2]-p[2];T*T+$*$+D*D>0&&y.push([m[0],m[1],m[2]])}this.addAuxEdge(`${M}_PATH`,y,{polylineWorld:!0,materialKey:"OVERLAY",closedLoop:!!r,centerline:!0})}catch{}const A=(this._triVerts?.length||0)/3|0,N=this.params?.selfUnion!==!1;let E=A,q=!1;if(N){const y=Array.isArray(this._auxEdges)?this._auxEdges.map(p=>({name:p?.name,closedLoop:!!p?.closedLoop,polylineWorld:!!p?.polylineWorld,materialKey:p?.materialKey,centerline:!!p?.centerline,points:Array.isArray(p?.points)?p.points.map(T=>Array.isArray(T)?[T[0],T[1],T[2]]:T):[]})):[];let m=null;try{m=this._manifoldize()}catch{}try{const p=this.union(this);if(E=(p?._triVerts?.length||0)/3|0,he(this,p,{auxEdges:y}),m&&m!==this._manifold)try{typeof m.delete=="function"&&m.delete()}catch{}q=!0}catch(p){console.warn("Self-union failed; returning raw tube geometry.",p)}}return this._selfUnionStats={preTriangles:A,postTriangles:E,selfIntersectionLikely:N?E>A:!1,unionSucceeded:q,selfUnionSkipped:!N},this.name=s,this}generateSlow(){const{points:o,radius:t,innerRadius:n,resolution:i,closed:a,name:s,debugSpheres:r}=this.params;if(!(t>0))throw new Error("Tube radius must be greater than zero.");const c=Number(n)||0;if(c<0)throw new Error("Inside radius cannot be negative.");if(c>0&&c>=t)throw new Error("Inside radius must be smaller than the outer radius.");const u=Math.max(8,Math.floor(Number(i)||Z)),h=oe(o),l=Math.max(1e-7,t*1e-5),{points:d,closed:g}=xe(h,!!a,l);if(d.length<2)throw new Error(`Tube requires at least two distinct path points. Got ${d.length} valid points from ${o.length} input points.`);if(g&&d.length<3)throw new Error("Closed tubes require at least three unique points.");typeof this.free=="function"&&this.free();const f=s||"Tube",S=!!r,V=g?null:Ee(d),w=g?null:Ie(d),_=w?w.clone().negate():null,x=g?null:{start:fe(d[0],d[1]),end:fe(d[d.length-1],d[d.length-2])},{manifold:M,spheres:O}=de(d,t,u,g,S,x);let A;if(c>0){const{manifold:E,spheres:q}=de(d,c,u,g,S,x);let y=null;try{y=M.subtract(E)}finally{if(M&&M!==y)try{typeof M.delete=="function"&&M.delete()}catch{}if(E&&E!==y)try{typeof E.delete=="function"&&E.delete()}catch{}}A=H._fromManifold(y,new Map([[0,`${f}_Outer`]])),S&&(this.debugSphereSolids=[...this.debugSphereSolids||[],...O.map((m,p)=>R(m,`${f}_sphere_outer_${p+1}`)),...q.map((m,p)=>R(m,`${f}_sphere_inner_${p+1}`))])}else A=H._fromManifold(M,new Map([[0,`${f}_Outer`]])),S&&(this.debugSphereSolids=O.map((E,q)=>R(E,`${f}_sphere_${q+1}`)));const N=Te(A,d,V,_,t,c,g,f);he(this,N||A),this.name=s,this.params.closed=g;try{const E=d.map(q=>[q.x,q.y,q.z]);this.addAuxEdge(`${f}_PATH`,E,{polylineWorld:!0,materialKey:"OVERLAY",closedLoop:!!g,centerline:!0})}catch{}return this._selfUnionStats=null,this}};b(ne,"Tube");let me=ne;export{me as Tube};
1
+ var ye=Object.defineProperty;var b=(e,o)=>ye(e,"name",{value:o,configurable:!0});import{aD as H,V as z,b as ge,M as pe,aC as X}from"./featureDialogs-Bas0NDXF.js";import"./browserStorage-CvgF8ovw.js";import"./preload-helper-ZNr0Qq7Q.js";const Z=32,I=1e-9,W=I*I;function oe(e){const o=[];if(!Array.isArray(e))return o;for(const t of e){if(!Array.isArray(t)||t.length<3)continue;const n=Number(t[0]),i=Number(t[1]),a=Number(t[2]);!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(a)||o.push(new z(n,i,a))}return o}b(oe,"toVector3Array");function Y(e,o=1e-7){if(!Array.isArray(e)||e.length===0)return[];const t=o*o,n=[e[0].clone()];for(let i=1;i<e.length;i++){const a=e[i];a&&a.distanceToSquared(n[n.length-1])>t&&n.push(a.clone())}return n}b(Y,"dedupeVectors");function _e(e,o){if(!Array.isArray(e)||e.length<2)return Array.isArray(e)?e.map(n=>n.clone()):[];if(e.length===2)return e.map(n=>n.clone());const t=[];t.push(e[0].clone());for(let n=1;n<e.length-1;n++){const i=e[n-1],a=e[n],s=e[n+1];if(!i||!a||!s){t.push(a.clone());continue}const r=a.clone().sub(i),c=s.clone().sub(a);if(r.lengthSq()<W||c.lengthSq()<W){t.push(a.clone());continue}r.normalize(),c.normalize();const u=ge.clamp(r.dot(c),-1,1),h=Math.acos(Math.abs(u));if(h>Math.PI/3){const l=h*.5,d=o/Math.tan(l),g=i.distanceTo(a),f=a.distanceTo(s),S=Math.min(d*.8,g*.6),V=Math.min(d*.8,f*.6);if(S>o*.1&&V>o*.1){const w=a.clone().addScaledVector(r,-S),_=a.clone().addScaledVector(c,V);t[t.length-1].distanceTo(w)>1e-6&&t.push(w),t.push(_)}else t.push(a.clone())}else t.push(a.clone())}return t.push(e[e.length-1].clone()),Y(t,1e-6)}b(_e,"calculateTubeIntersectionTrimming");function Se(e,o){try{const t=_e(e,o);return!Array.isArray(t)||t.length<2?Array.isArray(e)?e.map(n=>n.clone()):[]:Y(t,1e-9)}catch(t){return console.error("Error in smoothPath:",t),e.map(n=>n.clone())}}b(Se,"smoothPath");const J=new z,se=new z,ae=new z,ie=new z;function we(e,o=!1){const t=[],n=[],i=[];if(!Array.isArray(e)||e.length<2)return{tangents:t,normals:n,binormals:i};const a=new z;for(let s=0;s<e.length;s++){const r=new z;if(o){const c=(s-1+e.length)%e.length,u=(s+1)%e.length,h=new z().subVectors(e[u],e[s]),l=new z().subVectors(e[s],e[c]),d=h.length(),g=l.length();d>I&&g>I?(h.normalize(),l.normalize(),r.addVectors(h,l).normalize()):d>I?r.copy(h).normalize():g>I?r.copy(l).normalize():r.set(0,0,1)}else if(s===0)r.subVectors(e[1],e[0]);else if(s===e.length-1)r.subVectors(e[s],e[s-1]);else{const c=new z().subVectors(e[s+1],e[s]),u=new z().subVectors(e[s],e[s-1]),h=c.length(),l=u.length();h>I&&l>I?(c.normalize(),u.normalize(),r.addVectors(c,u).normalize()):h>I?r.copy(c).normalize():l>I?r.copy(u).normalize():r.copy(s>0?t[s-1]:new z(0,0,1))}t.push(r.normalize())}a.set(0,0,1),Math.abs(t[0].dot(a))>.99&&a.set(1,0,0),n.push(new z().crossVectors(t[0],a).cross(t[0]).normalize()),i.push(new z().crossVectors(t[0],n[0]).normalize());for(let s=1;s<e.length;s++){n.push(n[s-1].clone()),i.push(i[s-1].clone());const r=t[s-1].dot(t[s]);if(r<=1-I){const c=new z().crossVectors(t[s-1],t[s]).normalize(),u=Math.acos(ge.clamp(r,-1,1)),h=new pe().makeRotationAxis(c,u);n[s].applyMatrix4(h).normalize(),i[s].crossVectors(t[s],n[s]).normalize()}}if(o&&e.length>2){const s=n.reduce((r,c)=>r.add(c),new z).normalize();for(let r=0;r<n.length;r++){const c=n[r].clone().sub(t[r].clone().multiplyScalar(t[r].dot(n[r])));c.lengthSq()>W?(n[r].copy(c.normalize()),i[r].crossVectors(t[r],c).normalize()):(n[r].copy(s),i[r].crossVectors(t[r],s).normalize())}}return{tangents:t,normals:n,binormals:i}}b(we,"computeFrames");function be(e,o,t,n,i,a){const s=[],r=i>0?[]:null;for(let c=0;c<e.length;c++){const u=o[c],h=t[c],l=[],d=r?[]:null;for(let g=0;g<a;g++){const f=g/a*Math.PI*2,S=Math.cos(f),V=Math.sin(f),w=u.clone().multiplyScalar(S).add(h.clone().multiplyScalar(V)),_=e[c].clone().addScaledVector(w,n);if(l.push([_.x,_.y,_.z]),r&&i>0){const x=e[c].clone().addScaledVector(w,i);d.push([x.x,x.y,x.z])}}s.push(l),r&&i>0&&r.push(d)}return{outer:s,inner:r}}b(be,"buildRings");function ee(e,o,t,n,i,a){if(!a||a.lengthSq()<1e-10){e.addTriangle(o,t,n,i);return}J.set(t[0],t[1],t[2]),se.set(n[0],n[1],n[2]).sub(J),ae.set(i[0],i[1],i[2]).sub(J),ie.copy(se).cross(ae),ie.dot(a)<0?e.addTriangle(o,t,i,n):e.addTriangle(o,t,n,i)}b(ee,"addTriangleOriented");function te(e,o,t,n,i,a,s){ee(e,o,t,n,i,s),ee(e,o,t,i,a,s)}b(te,"addQuadOriented");function ce(e,o,t,n,i){for(let a=0;a<n.length;a++){const s=(a+1)%n.length;ee(e,o,t,n[a],n[s],i)}}b(ce,"addDiskCap");function le(e,o,t,n,i){const a=t.length;for(let s=0;s<a;s++){const r=(s+1)%a;te(e,o,t[s],t[r],n[r],n[s],i)}}b(le,"addRingCap");function he(e,o,{auxEdges:t}={}){e._numProp=o._numProp,e._vertProperties=o._vertProperties,e._triVerts=o._triVerts,e._triIDs=o._triIDs,e._vertKeyToIndex=new Map(o._vertKeyToIndex),e._idToFaceName=new Map(o._idToFaceName),e._faceNameToID=new Map(o._faceNameToID),e._faceMetadata=new Map(o._faceMetadata),e._edgeMetadata=new Map(o._edgeMetadata),e._auxEdges=t!==void 0?t:Array.isArray(o._auxEdges)?o._auxEdges:[],e._manifold=o._manifold,e._dirty=!1,e._faceIndex=null}b(he,"copySolidState");function xe(e,o,t){const n=Y(e,t);if(n.length<2)return{points:n,closed:!1};const i=n[0],a=n[n.length-1],s=Math.max(t*4,I),r=!!o||i.distanceToSquared(a)<=s*s;return r&&i.distanceToSquared(a)<=s*s&&n.pop(),{points:n,closed:r}}b(xe,"normalizePath");function fe(e,o,t=!1){if(!e||!o)return null;const n=new z().subVectors(o,e);return n.lengthSq()<=I?null:(t&&n.negate(),n.normalize(),{anchor:e,normalVec:n,normalArray:[n.x,n.y,n.z],offset:n.dot(e)})}b(fe,"trimPlaneFromPoints");function ue(e,o,t,n,i=!0){if(!n||!Array.isArray(e)||!Array.isArray(o)||!(t>0))return;const a=i?0:e.length-1,s=i?e.length:-1,r=i?1:-1;for(let c=a;c!==s;c+=r){const u=o[c];if(!u)continue;if(u.distanceTo(n.anchor)>t)break;const h=e[c];if(!h)continue;const l=h.trimByPlane(n.normalArray,n.offset);if(!l){e[c]=l;continue}if(l!==h){try{typeof h.delete=="function"&&h.delete()}catch{}e[c]=l}else e[c]=l}}b(ue,"applyTrimPlaneSequentially");function ze(e,o,t,n,{keepSpheres:i=!1,trimPlanes:a=null}={}){if(!Array.isArray(e)||e.length<2)return{hull:null,spheres:[]};const s=X.sphere(o,t),r=e.map(l=>s.translate([l.x,l.y,l.z]));try{typeof s.delete=="function"&&s.delete()}catch{}!n&&a&&(a.start&&ue(r,e,o,a.start,!0),a.end&&ue(r,e,o,a.end,!1));const c=[],u=n?e.length:e.length-1;for(let l=0;l<u;l++){const d=e[l],g=e[(l+1)%e.length],f=r[l],S=r[(l+1)%r.length];!d||!g||!f||!S||d.distanceToSquared(g)<I*I||c.push(X.hull([f,S]))}if(!i)for(const l of r)try{l&&typeof l.delete=="function"&&l.delete()}catch{}if(!c.length)return{hull:null,spheres:i?r:[]};if(c.length===1)return{hull:c[0],spheres:i?r:[]};let h=null;try{return h=X.union(c),{hull:h,spheres:i?r:[]}}finally{for(const l of c)if(l&&l!==h)try{typeof l.delete=="function"&&l.delete()}catch{}}}b(ze,"buildHullChain");function de(e,o,t,n,i=!1,a=null){const{hull:s,spheres:r}=ze(e,o,t,n,{keepSpheres:i,trimPlanes:a});if(!s)throw new Error("Unable to build tube hulls from the supplied path.");return{manifold:s,spheres:r}}b(de,"buildHullTube");function Me(e){if(!Array.isArray(e)||e.length<2)return[];const o=[];for(let t=0;t<e.length-1;t++){const n=e[t],i=e[t+1];if(!n||!i)continue;const a=n.x,s=n.y,r=n.z,c=i.x-a,u=i.y-s,h=i.z-r,l=c*c+u*u+h*h;o.push({ax:a,ay:s,az:r,dx:c,dy:u,dz:h,lenSq:l})}return o}b(Me,"buildPolylineSegmentCache");function Ae(e,o,t,n,i=1/0){if(!Array.isArray(n)||n.length===0)return 1/0;let a=1/0;for(let s=0;s<n.length;s++){const r=n[s];if(!r||r.lenSq<=W)continue;const c=e-r.ax,u=o-r.ay,h=t-r.az;let l=(c*r.dx+u*r.dy+h*r.dz)/r.lenSq;l<0?l=0:l>1&&(l=1);const d=r.ax+r.dx*l,g=r.ay+r.dy*l,f=r.az+r.dz*l,S=e-d,V=o-g,w=t-f,_=S*S+V*V+w*w;if(_<a&&(a=_,a<=i))break}return a}b(Ae,"minDistanceToPolylineSq");function Te(e,o,t,n,i,a,s,r){if(!e||!e._vertProperties||!e._triVerts)return e;const c=e._triVerts.length/3|0;if(!c)return e;e._faceNameToID=new Map,e._idToFaceName=new Map;const u=t?t.clone().normalize():null,h=n?n.clone().normalize():null,l=o[0],d=o[o.length-1],g=u?u.dot(l):0,f=h?h.dot(d):0,S=Math.max(i*.01,1e-5),V=(i+S)*(i+S),w=e._getOrCreateID(`${r}_Outer`),_=a>0?e._getOrCreateID(`${r}_Inner`):w,x=!s&&u?e._getOrCreateID(`${r}_CapStart`):w,M=!s&&h?e._getOrCreateID(`${r}_CapEnd`):w,O=new Array(c),A=e._vertProperties,N=e._triVerts,E=a>0?(a+i)*.5:i*.5,q=E*E,y=a>0?Me(o):null,m=u?u.x:0,p=u?u.y:0,T=u?u.z:0,$=h?h.x:0,D=h?h.y:0,F=h?h.z:0;for(let C=0;C<c;C++){const v=N[C*3+0]*3,G=N[C*3+1]*3,Q=N[C*3+2]*3,L=(A[v+0]+A[G+0]+A[Q+0])/3,k=(A[v+1]+A[G+1]+A[Q+1])/3,U=(A[v+2]+A[G+2]+A[Q+2])/3;let P=w;if(!s&&u&&Math.abs(m*L+p*k+T*U-g)<=S){const j=L-l.x,K=k-l.y,B=U-l.z;j*j+K*K+B*B<=V&&(P=x)}if(P===w&&!s&&h&&Math.abs($*L+D*k+F*U-f)<=S){const j=L-d.x,K=k-d.y,B=U-d.z;j*j+K*K+B*B<=V&&(P=M)}P===w&&a>0&&(P=Ae(L,k,U,y,q)<=q?_:w),P!==w&&P!==_&&P!==x&&P!==M&&(P=w),O[C]=P}e._triIDs=O,e._idToFaceName=new Map([[w,`${r}_Outer`],...a>0?[[_,`${r}_Inner`]]:[],...!s&&u?[[x,`${r}_CapStart`]]:[],...!s&&h?[[M,`${r}_CapEnd`]]:[]]),e._faceNameToID=new Map([...e._idToFaceName.entries()].map(([C,v])=>[v,C]));try{typeof e.free=="function"&&e.free()}catch{}e._dirty=!0,e._faceIndex=null;try{e._manifoldize()}catch{}return e}b(Te,"relabelFaces");function Ee(e){if(!Array.isArray(e)||e.length<2)return null;for(let o=1;o<e.length;o++){const t=new z().subVectors(e[o],e[o-1]);if(t.lengthSq()>I)return t.normalize()}return null}b(Ee,"firstTangent");function Ie(e){if(!Array.isArray(e)||e.length<2)return null;for(let o=e.length-1;o>=1;o--){const t=new z().subVectors(e[o],e[o-1]);if(t.lengthSq()>I)return t.normalize()}return null}b(Ie,"lastTangent");function R(e,o){const t=o||"Sphere",n=H._fromManifold(e,new Map([[0,t]])),i=n._getOrCreateID(t),a=n._triVerts.length/3|0;n._triIDs=new Array(a).fill(i),n._idToFaceName=new Map([[i,t]]),n._faceNameToID=new Map([[t,i]]),n._dirty=!0;try{n._manifoldize()}catch{}return n}b(R,"singleFaceSolidFromManifold");const ne=class ne extends H{constructor(o={}){super();const{points:t=[],radius:n=1,innerRadius:i=0,resolution:a=Z,closed:s=!1,name:r="Tube",debugSpheres:c=!1,preferFast:u=!0,selfUnion:h=!0,autoVisualize:l=!1}=o;if(this.params={points:t,radius:n,innerRadius:i,resolution:a,closed:s,name:r,debugSpheres:c,preferFast:u,selfUnion:h},this.name=r,Array.isArray(t)&&t.length>=2){const d=t[0],g=t[t.length-1];d[0]===g[0]&&d[1]===g[1]&&d[2]===g[2]&&(this.params.closed=!0)}try{const d=Array.isArray(t)&&t.length>=2,g=Number(n)>0;d&&g&&(this.generate(),l&&this.visualize())}catch{}}generate(){if(this.params?.preferFast!==!1)try{if(this.generateFast(),this._selfUnionStats?.selfIntersectionLikely){if(typeof this.free=="function")try{this.free()}catch{}return this.generateSlow()}return this}catch(t){if(console.warn("Tube fast generation failed; falling back to slow.",t),typeof this.free=="function")try{this.free()}catch{}}return this.generateSlow()}generateFast(){let{points:o,radius:t,innerRadius:n,resolution:i,closed:a,name:s}=this.params,r=!!a;if(!(t>0))throw new Error("Tube radius must be greater than zero.");const c=Number(n)||0;if(c<0)throw new Error("Inside radius cannot be negative.");if(c>0&&c>=t)throw new Error("Inside radius must be smaller than the outer radius.");const u=Math.max(8,Math.floor(Number(i)||Z)),h=Y(oe(o));if(h.length<2)throw new Error(`Tube requires at least two distinct path points. Got ${h.length} valid points from ${o.length} input points.`);const l=h.reduce((y,m)=>Math.max(y,Math.abs(m.x),Math.abs(m.y),Math.abs(m.z)),Math.max(1e-6,t)),d=Math.max(1e-7,t*1e-5,l*1e-6),g=d*d;!r&&h.length>=2&&h[0].distanceToSquared(h[h.length-1])<=g&&(r=!0);let f;try{f=Se(h,t)}catch(y){throw console.error("Error in smoothPath:",y),new Error(`Path smoothing failed: ${y.message}`)}if(f.length<2)throw new Error(`Tube path collapsed after smoothing; check input. Original: ${h.length}, Smoothed: ${f.length}`);if(f.length>1){const y=f[0],m=f[f.length-1],p=y.distanceToSquared(m);!r&&p<=g&&(r=!0),r&&p<=g&&f.length>2&&(f=f.slice(0,-1))}this.params.closed=r;const{tangents:S,normals:V,binormals:w}=we(f,r);if(S.length<2)throw new Error("Unable to compute frames for tube path.");this._numProp=3,this._vertProperties=[],this._triVerts=[],this._triIDs=[],this._vertKeyToIndex=new Map,this._idToFaceName=new Map,this._faceNameToID=new Map,this._faceMetadata=new Map,this._edgeMetadata=new Map,this._auxEdges=[],this._dirty=!0;const{outer:_,inner:x}=be(f,V,w,t,c,u),M=s||"Tube",O=r?_.length:_.length-1;for(let y=0;y<O;y++){const m=_[y],p=_[(y+1)%_.length],T=(y+1)%f.length,$=f[T].clone().sub(f[y]).normalize();for(let D=0;D<u;D++){const F=(D+1)%u;te(this,`${M}_Outer`,m[D],m[F],p[F],p[D],$)}}if(x){const y=r?x.length:x.length-1;for(let m=0;m<y;m++){const p=x[m],T=x[(m+1)%x.length],$=(m+1)%f.length,F=f[$].clone().sub(f[m]).normalize().clone().negate();for(let C=0;C<u;C++){const v=(C+1)%u;te(this,`${M}_Inner`,p[C],T[C],T[v],p[v],F)}}}if(!r){const y=[f[0].x,f[0].y,f[0].z],m=[f[f.length-1].x,f[f.length-1].y,f[f.length-1].z],p=S[0].clone().negate(),T=S[S.length-1].clone();x?(le(this,`${M}_CapStart`,_[0],x[0],p),le(this,`${M}_CapEnd`,_[_.length-1],x[x.length-1],T)):(ce(this,`${M}_CapStart`,y,_[0],p),ce(this,`${M}_CapEnd`,m,_[_.length-1],T))}try{const y=f.map(m=>[m.x,m.y,m.z]);if(r&&y.length>=2){const m=y[0],p=y[y.length-1],T=m[0]-p[0],$=m[1]-p[1],D=m[2]-p[2];T*T+$*$+D*D>0&&y.push([m[0],m[1],m[2]])}this.addAuxEdge(`${M}_PATH`,y,{polylineWorld:!0,materialKey:"OVERLAY",closedLoop:!!r,centerline:!0})}catch{}const A=(this._triVerts?.length||0)/3|0,N=this.params?.selfUnion!==!1;let E=A,q=!1;if(N){const y=Array.isArray(this._auxEdges)?this._auxEdges.map(p=>({name:p?.name,closedLoop:!!p?.closedLoop,polylineWorld:!!p?.polylineWorld,materialKey:p?.materialKey,centerline:!!p?.centerline,points:Array.isArray(p?.points)?p.points.map(T=>Array.isArray(T)?[T[0],T[1],T[2]]:T):[]})):[];let m=null;try{m=this._manifoldize()}catch{}try{const p=this.union(this);if(E=(p?._triVerts?.length||0)/3|0,he(this,p,{auxEdges:y}),m&&m!==this._manifold)try{typeof m.delete=="function"&&m.delete()}catch{}q=!0}catch(p){console.warn("Self-union failed; returning raw tube geometry.",p)}}return this._selfUnionStats={preTriangles:A,postTriangles:E,selfIntersectionLikely:N?E>A:!1,unionSucceeded:q,selfUnionSkipped:!N},this.name=s,this}generateSlow(){const{points:o,radius:t,innerRadius:n,resolution:i,closed:a,name:s,debugSpheres:r}=this.params;if(!(t>0))throw new Error("Tube radius must be greater than zero.");const c=Number(n)||0;if(c<0)throw new Error("Inside radius cannot be negative.");if(c>0&&c>=t)throw new Error("Inside radius must be smaller than the outer radius.");const u=Math.max(8,Math.floor(Number(i)||Z)),h=oe(o),l=Math.max(1e-7,t*1e-5),{points:d,closed:g}=xe(h,!!a,l);if(d.length<2)throw new Error(`Tube requires at least two distinct path points. Got ${d.length} valid points from ${o.length} input points.`);if(g&&d.length<3)throw new Error("Closed tubes require at least three unique points.");typeof this.free=="function"&&this.free();const f=s||"Tube",S=!!r,V=g?null:Ee(d),w=g?null:Ie(d),_=w?w.clone().negate():null,x=g?null:{start:fe(d[0],d[1]),end:fe(d[d.length-1],d[d.length-2])},{manifold:M,spheres:O}=de(d,t,u,g,S,x);let A;if(c>0){const{manifold:E,spheres:q}=de(d,c,u,g,S,x);let y=null;try{y=M.subtract(E)}finally{if(M&&M!==y)try{typeof M.delete=="function"&&M.delete()}catch{}if(E&&E!==y)try{typeof E.delete=="function"&&E.delete()}catch{}}A=H._fromManifold(y,new Map([[0,`${f}_Outer`]])),S&&(this.debugSphereSolids=[...this.debugSphereSolids||[],...O.map((m,p)=>R(m,`${f}_sphere_outer_${p+1}`)),...q.map((m,p)=>R(m,`${f}_sphere_inner_${p+1}`))])}else A=H._fromManifold(M,new Map([[0,`${f}_Outer`]])),S&&(this.debugSphereSolids=O.map((E,q)=>R(E,`${f}_sphere_${q+1}`)));const N=Te(A,d,V,_,t,c,g,f);he(this,N||A),this.name=s,this.params.closed=g;try{const E=d.map(q=>[q.x,q.y,q.z]);this.addAuxEdge(`${f}_PATH`,E,{polylineWorld:!0,materialKey:"OVERLAY",closedLoop:!!g,centerline:!0})}catch{}return this._selfUnionStats=null,this}};b(ne,"Tube");let me=ne;export{me as Tube};
@@ -1 +1 @@
1
- var U=Object.defineProperty;var c=(t,e)=>U(t,"name",{value:e,configurable:!0});import{d as I,L as R,e as H,b8 as B,J as Y,f as k,V as b,Q as G,I as J,t as Z,m as C,M as T,b as E}from"./featureDialogs-CUWi02Qp.js";const S=Object.freeze({lineColor:9684477,dotColor:9684477,arrowColor:9684477,arrowLengthPx:12,arrowWidthPx:4,leaderDotRadiusPx:6,noteDotRadius:.08,noteDotColor:9684477});let A={...S};function D(){return A}c(D,"getPMIStyle");function st(t={}){return!t||typeof t!="object"||(A={...A,...t}),A}c(st,"setPMIStyle");function at(t={}){const e={...S},n=c((i,s)=>{const r=t[i];if(Number.isFinite(r))e[i]=r;else if(typeof r=="string"&&i.toLowerCase().includes("color")){const f=parseInt(r.replace("#",""),16);Number.isFinite(f)&&(e[i]=f)}else r!=null&&(e[i]=s)},"assign");return n("lineColor",S.lineColor),n("dotColor",S.dotColor),n("arrowColor",S.arrowColor),n("arrowLengthPx",S.arrowLengthPx),n("arrowWidthPx",S.arrowWidthPx),n("leaderDotRadiusPx",S.leaderDotRadiusPx),n("lineWidth",S.lineWidth||1),n("noteDotRadius",S.noteDotRadius),n("noteDotColor",S.noteDotColor),e}c(at,"sanitizePMIStyle");function q(t){try{return JSON.parse(JSON.stringify(t))}catch{return{}}}c(q,"safeCloneJSON");function X(t){return t?t.isPerspectiveCamera?"PerspectiveCamera":t.isOrthographicCamera?"OrthographicCamera":"Camera":"Camera"}c(X,"resolveCameraType");function W(t){if(!t)return null;if(Array.isArray(t)&&t.length===3)return[Number(t[0])||0,Number(t[1])||0,Number(t[2])||0];if(typeof t=="object"){const{x:e,y:n,z:i}=t;if([e,n,i].every(s=>Number.isFinite(s)))return[e,n,i]}return null}c(W,"extractVector3");function _(t){if(!t||typeof t!="object")return null;const e=Number(t.width),n=Number(t.height);return!(e>0)||!(n>0)?null:{width:e,height:n}}c(_,"normalizeViewportMetrics");function Q(t,e,n,i,s){if(!e)return;const r=i?.controlsState;if(r&&typeof e.setStateFromJSON=="function"){const x=Array.isArray(r.target)?r.target:n,o={arcballState:{target:Array.isArray(x)?x:[t.target?.x||0,t.target?.y||0,t.target?.z||0],cameraMatrix:{elements:Array.isArray(r.cameraMatrix)&&r.cameraMatrix.length===16?r.cameraMatrix:Array.from(t.matrix.elements)},cameraUp:r.cameraUp||{x:t.up.x,y:t.up.y,z:t.up.z},cameraNear:Number.isFinite(r.cameraNear)?r.cameraNear:t.near,cameraFar:Number.isFinite(r.cameraFar)?r.cameraFar:t.far,cameraZoom:Number.isFinite(r.cameraZoom)?r.cameraZoom:t.zoom,gizmoMatrix:{elements:Array.isArray(r.gizmoMatrix)&&r.gizmoMatrix.length===16?r.gizmoMatrix:Array.from((e._gizmos?.matrix||new T).elements)}}},l=Number.isFinite(r.cameraFov)?r.cameraFov:i?.projection?.fov;t.isPerspectiveCamera&&Number.isFinite(l)&&(o.arcballState.cameraFov=l);try{e.setStateFromJSON(JSON.stringify(o))}catch(g){console.warn("ArcballControls setStateFromJSON failed; falling back to manual sync",g),L(t,e,n,i),O(e,s);return}O(e,s);return}L(t,e,n,i),O(e,s)}c(Q,"syncArcballControls");function L(t,e,n,i){const s=Array.isArray(n)&&n.length===3?n:e.target?[e.target.x,e.target.y,e.target.z]:[0,0,0],r=new b(s[0],s[1],s[2]);try{typeof e.setTarget=="function"?e.setTarget(r.x,r.y,r.z):e.target?.set?e.target.set(r.x,r.y,r.z):e.target&&(e.target.x=r.x,e.target.y=r.y,e.target.z=r.z)}catch{}try{e._currentTarget?.copy&&e._currentTarget.copy(r),e._target0?.copy&&e._target0.copy(r)}catch{}const f=e._gizmos;if(f){try{f.position.copy(r),f.updateMatrix(),f.updateMatrixWorld(!0)}catch{}if(typeof e.calculateTbRadius=="function")try{e._tbRadius=e.calculateTbRadius(t)}catch{}if(typeof e.makeGizmos=="function")try{e.makeGizmos(r,e._tbRadius||1)}catch{}}try{e._cameraMatrixState?.copy?.(t.matrix),e._cameraMatrixState0?.copy?.(t.matrix),f?.matrix&&(e._gizmoMatrixState?.copy?.(f.matrix),e._gizmoMatrixState0?.copy?.(f.matrix)),e._cameraProjectionState?.copy?.(t.projectionMatrix),typeof e._zoomState=="number"&&(e._zoomState=t.zoom),typeof e._zoom0=="number"&&(e._zoom0=t.zoom),typeof e._fovState=="number"&&Number.isFinite(i?.projection?.fov??t.fov)&&(e._fovState=i?.projection?.fov??t.fov),typeof e._fov0=="number"&&Number.isFinite(i?.projection?.fov??t.fov)&&(e._fov0=i?.projection?.fov??t.fov),typeof e._nearPos=="number"&&(e._nearPos=Number.isFinite(i?.near)?i.near:t.near),typeof e._farPos=="number"&&(e._farPos=Number.isFinite(i?.far)?i.far:t.far),e._up0?.copy?.(t.up)}catch{}try{typeof e.updateTbState=="function"&&e.STATE?.IDLE?e.updateTbState(e.STATE.IDLE,!1):"_state"in e&&e.STATE?.IDLE&&(e._state=e.STATE.IDLE)}catch{}}c(L,"manualArcballSync");function O(t,e){try{if(typeof t._animationId=="number"&&t._animationId!==-1){const n=typeof cancelAnimationFrame=="function"?cancelAnimationFrame:typeof window<"u"&&typeof window.cancelAnimationFrame=="function"?window.cancelAnimationFrame.bind(window):null;n&&n(t._animationId)}t._animationId=-1,typeof t._timeStart=="number"&&(t._timeStart=-1)}catch{}try{t.updateMatrixState?.()}catch{}if(e)try{t.update?.()}catch{}}c(O,"finalizeArcballSync");function K(t){if(!t)return null;if(t.isPerspectiveCamera){const e=t.view&&t.view.enabled?{enabled:!0,fullWidth:t.view.fullWidth,fullHeight:t.view.fullHeight,offsetX:t.view.offsetX,offsetY:t.view.offsetY,width:t.view.width,height:t.view.height}:{enabled:!1};return{kind:"perspective",aspect:Number.isFinite(t.aspect)&&t.aspect>0?t.aspect:void 0,fov:t.fov,near:t.near,far:t.far,zoom:t.zoom??1,filmGauge:t.filmGauge??35,filmOffset:t.filmOffset??0,view:e}}if(t.isOrthographicCamera){const e=t.view&&t.view.enabled?{enabled:!0,fullWidth:t.view.fullWidth,fullHeight:t.view.fullHeight,offsetX:t.view.offsetX,offsetY:t.view.offsetY,width:t.view.width,height:t.view.height}:{enabled:!1};return{kind:"orthographic",aspect:Number.isFinite(t.top-t.bottom)&&Math.abs(t.top-t.bottom)>1e-9?(t.right-t.left)/(t.top-t.bottom):void 0,left:t.left,right:t.right,top:t.top,bottom:t.bottom,near:t.near,far:t.far,zoom:t.zoom??1,view:e}}return{kind:"generic",near:t.near??.1,far:t.far??2e3}}c(K,"captureProjection");function $(t,e=null,n=null,i=null){try{if(!t?.isPerspectiveCamera)return;const s=_(n);if(!s)return;const r=s.width/s.height;if(!(r>1e-9))return;t.aspect=r;const f=_(i),x=f?f.width/f.height:Number.isFinite(e?.aspect)&&e.aspect>1e-9?e.aspect:null;if(!(x>1e-9)||r>=x)return;const o=Number.isFinite(e?.fov)?e.fov:t.fov,l=Number.isFinite(e?.zoom)&&e.zoom>0?e.zoom:Number.isFinite(t.zoom)&&t.zoom>0?t.zoom:1;if(!(o>0)||o>=179)return;const m=Math.tan(E.degToRad(o)*.5)/l*x/r;if(!(m>0))return;const w=E.radToDeg(2*Math.atan(m*l));Number.isFinite(w)&&w>o&&(t.fov=Math.min(179,w))}catch{}}c($,"fitPerspectiveProjection");function j(t,e,n=null){if(!(!t||!e)){if(t.isPerspectiveCamera&&e.kind==="perspective"){Number.isFinite(e.fov)&&(t.fov=e.fov),Number.isFinite(e.near)&&(t.near=e.near),Number.isFinite(e.far)&&(t.far=e.far),Number.isFinite(e.zoom)&&(t.zoom=e.zoom),Number.isFinite(e.filmGauge)&&(t.filmGauge=e.filmGauge),Number.isFinite(e.filmOffset)&&(t.filmOffset=e.filmOffset),n!=null&&Number.isFinite(n)&&(t.aspect=n),e.view&&e.view.enabled&&t.setViewOffset?t.setViewOffset(e.view.fullWidth,e.view.fullHeight,e.view.offsetX,e.view.offsetY,e.view.width,e.view.height):t.clearViewOffset&&t.clearViewOffset();return}if(t.isOrthographicCamera&&e.kind==="orthographic"){const i=["left","right","top","bottom","near","far","zoom"];for(const s of i)Number.isFinite(e[s])&&(t[s]=e[s]);e.view&&e.view.enabled&&t.setViewOffset?t.setViewOffset(e.view.fullWidth,e.view.fullHeight,e.view.offsetX,e.view.offsetY,e.view.width,e.view.height):t.clearViewOffset&&t.clearViewOffset();return}Number.isFinite(e.near)&&(t.near=e.near),Number.isFinite(e.far)&&(t.far=e.far),Number.isFinite(e.zoom)&&(t.zoom=e.zoom)}}c(j,"applyProjection");function ft(t,{controls:e=null,viewport:n=null}={}){if(!t||!t.isCamera)return null;try{t.updateMatrixWorld(!0)}catch{}const i={version:3,type:X(t),worldMatrix:t.matrixWorld?.toArray?.()??null,projection:K(t),position:{x:t.position.x,y:t.position.y,z:t.position.z},quaternion:{x:t.quaternion.x,y:t.quaternion.y,z:t.quaternion.z,w:t.quaternion.w},up:{x:t.up.x,y:t.up.y,z:t.up.z},zoom:Number.isFinite(t.zoom)?t.zoom:1,near:Number.isFinite(t.near)?t.near:void 0,far:Number.isFinite(t.far)?t.far:void 0};if(t.layers?.mask!==void 0&&(i.layers=t.layers.mask),e?.target&&typeof e.target=="object"){i.target={x:e.target.x,y:e.target.y,z:e.target.z};try{const r=e._gizmos?.matrix;r&&(i.controlsState={target:[e.target.x,e.target.y,e.target.z],cameraMatrix:Array.from(t.matrix.elements),cameraUp:{x:t.up.x,y:t.up.y,z:t.up.z},cameraNear:t.near,cameraFar:t.far,cameraZoom:t.zoom,cameraFov:t.isPerspectiveCamera?t.fov:void 0,gizmoMatrix:Array.from(r.elements)})}catch{}}!i.target&&t.target&&typeof t.target=="object"&&(i.target={x:t.target.x,y:t.target.y,z:t.target.z}),t.userData&&typeof t.userData=="object"&&(i.userData=q(t.userData));const s=_(n);return s&&(i.viewport=s),i}c(ft,"captureCameraSnapshot");function ut(t,e,{controls:n=null,respectParent:i=!0,strictType:s=!1,overrideAspect:r=null,syncControls:f=!0,viewport:x=null}={}){if(!t||!t.isCamera||!e)return!1;let o=e;if(typeof o=="string")try{o=JSON.parse(o)}catch{return!1}if(!o||typeof o!="object")return!1;const l=o.type||null;if(s&&l){const p=X(t);if(l!==p)return!1}try{j(t,o.projection,r)}catch{}$(t,o?.projection,x,o?.viewport||null),tt(t,o?.projection,x),typeof o.layers=="number"&&t.layers&&(t.layers.mask=o.layers);const g=W(o.up)||W(o.upVector);g&&t.up.set(g[0],g[1],g[2]),o.userData&&typeof o.userData=="object"&&(t.userData=q(o.userData));let u=!1,m=!1;const w=Array.isArray(o.worldMatrix)&&o.worldMatrix.length===16?o.worldMatrix:null;if(w)try{const p=new T().fromArray(w),F=t.parent||null,M=new b,a=new G,d=new b;if(i&&F){F.updateMatrixWorld?.(!0);const z=new T().copy(F.matrixWorld).invert();new T().multiplyMatrices(z,p).decompose(M,a,d)}else p.decompose(M,a,d);const y=t.matrixAutoUpdate;t.matrixAutoUpdate=!1,t.position.copy(M),t.quaternion.copy(a),t.scale.copy(d),t.updateMatrix(),t.updateMatrixWorld(!0),t.matrixAutoUpdate=y,u=!0,m=!0}catch{u=!1}if(!u){const p=W(o.position);let F=!1;p&&(t.position.set(p[0],p[1],p[2]),F=!0);const M=o.quaternion;if(M&&typeof M=="object"){const{x:a,y:d,z:y,w:z}=M;[a,d,y,z].every(N=>Number.isFinite(N))&&(t.quaternion.set(a,d,y,z),F=!0)}Number.isFinite(o.zoom)&&(t.zoom=o.zoom,F=!0),Number.isFinite(o.near)&&(t.near=o.near,F=!0),Number.isFinite(o.far)&&(t.far=o.far,F=!0),F&&(t.updateMatrixWorld?.(!0),m=!0)}if(!m){try{t.updateProjectionMatrix?.()}catch{}if(n){try{n.update?.()}catch{}try{n.updateMatrixState?.()}catch{}}return!1}try{t.updateProjectionMatrix?.()}catch{}const v=o.target||o.controlsTarget,h=W(v);return n?Q(t,n,h,o,f):h&&t.target&&typeof t.target.set=="function"&&t.target.set(h[0],h[1],h[2]),!0}c(ut,"applyCameraSnapshot");function tt(t,e=null,n=null){try{if(!t?.isOrthographicCamera)return;const i=e||{},s=Number.isFinite(i.top)?i.top:t.top,r=Number.isFinite(i.bottom)?i.bottom:t.bottom,f=Number.isFinite(i.left)?i.left:t.left,x=Number.isFinite(i.right)?i.right:t.right,o=Number.isFinite(s)&&Number.isFinite(r)?s-r:t.top-t.bottom,l=Number.isFinite(f)&&Number.isFinite(x)?x-f:t.right-t.left;if(!Number.isFinite(o)||Math.abs(o)<1e-9||!Number.isFinite(l)||Math.abs(l)<1e-9)return;const g=Number.isFinite(s)&&Number.isFinite(r)?(s+r)*.5:(t.top+t.bottom)*.5,u=Number.isFinite(f)&&Number.isFinite(x)?(f+x)*.5:(t.left+t.right)*.5,m=_(n);let w=m?m.width/m.height:null;w>1e-9||(w=Number.isFinite(i.aspect)&&i.aspect>1e-9?i.aspect:l/o),(!Number.isFinite(w)||w<=1e-9)&&(w=1);const v=Math.abs(o)*.5,h=Math.abs(l)*.5,p=Math.max(h,v*w),F=Math.max(v,h/w),M=o>=0?1:-1;t.top=g+F*M,t.bottom=g-F*M,t.left=u-p,t.right=u+p,t.updateProjectionMatrix()}catch{}}c(tt,"adjustOrthographicFrustum");function V(t,e,n=void 0){const i=D(),s=n??i.lineColor??9684477,r=new I().setFromPoints([t.clone(),e.clone()]),f=new R({color:s,linewidth:i.lineWidth||1});return f.depthTest=!1,f.depthWrite=!1,f.transparent=!0,new H(r,f)}c(V,"makeOverlayLine");function lt(t,e,n=void 0,i={}){const s=D(),{viewer:r=null,dashPixels:f=10,gapPixels:x=10}=i||{},o=t.distanceTo(e);if(!(o>1e-6))return V(t,e,n??s.lineColor??9684477);const l=e.clone().sub(t).normalize(),g=t.clone().add(e).multiplyScalar(.5),u=et(r,g),m=it(u*f,o),w=nt(u*x,o),v=[];let h=0,p=t.clone();for(;h<o-1e-6;){const d=Math.min(m,o-h),y=p.clone().addScaledVector(l,d);if(v.push(p.clone(),y.clone()),h+=d,h>=o)break;const z=Math.min(w,o-h);p=y.clone().addScaledVector(l,z),h+=z}if(v.length<2)return V(t,e,n??s.lineColor??9684477);const F=new I().setFromPoints(v),M=new R({color:n??s.lineColor??9684477,linewidth:s.lineWidth||1});M.depthTest=!1,M.depthWrite=!1,M.transparent=!0;const a=new Z(F,M);return a.renderOrder=9994,a}c(lt,"makeOverlayDashedLine");function et(t,e){try{const n=t?.camera,i=t?.renderer;if(!n||!i)return .01;const s=i.domElement,r=Math.max(1,s?.clientHeight||s?.height||600);if(n.isOrthographicCamera)return(n.top-n.bottom)/Math.max(1e-6,n.zoom||1)/r;const f=n.getWorldPosition(new b),x=e?e.clone():n.getWorldDirection(new b).add(f),o=f.distanceTo(x),l=(n.fov||50)*Math.PI/180;return 2*Math.tan(l/2)*o/r}catch{return .01}}c(et,"worldUnitsPerPixelAtPoint");function it(t,e){if(!Number.isFinite(t)||t<=0)return e*.25;const n=Math.max(1e-4,e*.5);return Math.max(1e-4,Math.min(t,n))}c(it,"clampDashLength");function nt(t,e){if(!Number.isFinite(t)||t<0)return e*.25;const n=Math.max(1e-4,e*.5);return Math.max(1e-4,Math.min(t,n))}c(nt,"clampGapLength");function dt(t,e=void 0){const n=D(),i=e??n.dotColor??16777215,s=new J(t,12,8),r=new Y({color:i});return r.depthTest=!1,r.depthWrite=!1,r.transparent=!0,new k(s,r)}c(dt,"makeOverlaySphere");function pt(t,e,n,i,s,r){try{const f=D(),x=new B(s,i,8),o=new Y({color:r??f.arrowColor??9684477,depthTest:!1,depthWrite:!1,transparent:!0}),l=new k(x,o),g=e.clone().addScaledVector(n,-i*.5);l.position.copy(g);const u=new b(0,1,0),m=new G;return m.setFromUnitVectors(u,n.clone().normalize()),l.setRotationFromQuaternion(m),l.renderOrder=9996,t.add(l),l}catch{return null}}c(pt,"addArrowCone");function gt(t,e=1){try{const n=t?.renderer?.domElement?.getBoundingClientRect?.()||{width:800,height:600},i=t?.camera,s=Math.max(1,n.height||600);if(i&&i.isOrthographicCamera){const f=(i.top-i.bottom)/Math.max(1e-6,i.zoom||1)/s;return Math.max(1e-4,f*(e||1))}if(i&&i.isPerspectiveCamera){const r=(i.fov||50)*Math.PI/180,f=i.position.length(),o=2*Math.tan(r/2)*f/s;return Math.max(1e-4,o*(e||1))}return .01*(e||1)}catch{return .01*(e||1)}}c(gt,"screenSizeWorld");function ct(t,e){try{if(!e)return null;const n=e.userData||{},i=String(e.type||"").toUpperCase(),s=String(n.type||n.brepType||"").toUpperCase(),f=i==="FACE"||i==="PLANE"||!(i==="FACE"||i==="EDGE"||i==="PLANE")&&(s==="FACE"||s==="PLANE"),x=i==="EDGE"||!f&&(s==="EDGE"||e.isLine||e.isLine2||e.isLineSegments||e.isLineLoop);if(f){if(typeof e.getAverageNormal=="function"){const u=e.getAverageNormal();e.updateMatrixWorld(!0);const m=new C().getNormalMatrix(e.matrixWorld);return u.applyMatrix3(m).normalize()}const o=e.geometry;if(o){if(o.attributes&&o.attributes.normal){const u=o.attributes.normal.array;if(u.length>=3){const m=new b,w=u.length/3;for(let h=0;h<w;h++){const p=h*3;m.add(new b(u[p],u[p+1],u[p+2]))}m.divideScalar(w),e.updateMatrixWorld(!0);const v=new C().getNormalMatrix(e.matrixWorld);return m.applyMatrix3(v).normalize()}}if(o.attributes&&o.attributes.position){const u=o.attributes.position.array;if(u.length>=9){const m=new b;let w=0;const v=new b,h=new b,p=new b;e.updateMatrixWorld(!0);const F=Math.min(5,Math.floor(u.length/9));for(let M=0;M<F;M++){const a=M*9;if(a+8<u.length){v.set(u[a],u[a+1],u[a+2]).applyMatrix4(e.matrixWorld),h.set(u[a+3],u[a+4],u[a+5]).applyMatrix4(e.matrixWorld),p.set(u[a+6],u[a+7],u[a+8]).applyMatrix4(e.matrixWorld);const d=h.clone().sub(v).cross(p.clone().sub(v));d.lengthSq()>1e-10&&(d.normalize(),m.add(d),w++)}}if(w>0)return m.divideScalar(w).normalize()}}}const l=new b(0,0,1);e.updateMatrixWorld(!0);const g=new C().getNormalMatrix(e.matrixWorld);return l.applyMatrix3(g).normalize()}else if(x){const l=e.geometry;e.updateMatrixWorld(!0);const g=e.matrixWorld,u=c((a,d=!1)=>{if(!a)return null;let y=null;if(Array.isArray(a)&&a.length>=3)y=new b(a[0],a[1],a[2]);else if(typeof a=="object"){const z=Number(a.x),N=Number(a.y),P=Number(a.z);Number.isFinite(z)&&Number.isFinite(N)&&Number.isFinite(P)&&(y=new b(z,N,P))}return y?(d&&g&&y.applyMatrix4(g),y):null},"parsePoint"),m=c((a,d=!1)=>{if(!Array.isArray(a)||a.length<2)return null;let y=u(a[0],d);for(let z=1;z<a.length;z++){const N=u(a[z],d);if(!y||!N){y=N||y;continue}const P=N.clone().sub(y);if(P.lengthSq()>1e-12)return P.normalize();y=N}return null},"directionFromPointList");try{if(typeof e.points=="function"){const a=e.points(!0),d=m(a,!1);if(d)return d}}catch{}const w=Array.isArray(e?.userData?.polylineLocal)?e.userData.polylineLocal:null;if(w){const a=m(w,!0);if(a)return a}const v=l?.attributes?.instanceStart,h=l?.attributes?.instanceEnd;if(v&&h){const a=Math.min(v.count||0,h.count||0);for(let d=0;d<a;d++){const y=new b(v.getX(d),v.getY(d),v.getZ(d)),z=new b(h.getX(d),h.getY(d),h.getZ(d));g&&(y.applyMatrix4(g),z.applyMatrix4(g));const N=z.sub(y);if(N.lengthSq()>1e-12)return N.normalize()}}const p=l?.getAttribute?.("position");if(p&&p.itemSize===3&&p.count>=2){const a=new b,d=new b;a.set(p.getX(0),p.getY(0),p.getZ(0)),g&&a.applyMatrix4(g);for(let y=1;y<p.count;y++){d.set(p.getX(y),p.getY(y),p.getZ(y)),g&&d.applyMatrix4(g);const z=d.clone().sub(a);if(z.lengthSq()>1e-12)return z.normalize();a.copy(d)}}const F=new b(1,0,0),M=new C().getNormalMatrix(e.matrixWorld);return F.applyMatrix3(M).normalize()}return null}catch{return null}}c(ct,"getElementDirection");function ht(t,e){try{if(!e)return null;const n=e.geometry;if(n){if(typeof e.getWorldPosition=="function"){const s=n.attributes&&n.attributes.position?n.attributes.position.array:null;if(s&&s.length>=3){let r=0,f=0,x=0,o=0;const l=new b;e.updateMatrixWorld(!0);for(let g=0;g<s.length;g+=3)l.set(s[g],s[g+1],s[g+2]).applyMatrix4(e.matrixWorld),r+=l.x,f+=l.y,x+=l.z,o++;if(o>0)return new b(r/o,f/o,x/o)}}n.computeBoundingBox?.();const i=n.boundingBox;if(i)return i.getCenter(new b).applyMatrix4(e.matrixWorld)}return e.getWorldPosition(new b)}catch{return null}}c(ht,"objectRepresentativePoint");export{pt as a,st as b,at as c,D as d,ft as e,ut as f,ct as g,tt as h,V as i,lt as j,dt as m,ht as o,gt as s};
1
+ var U=Object.defineProperty;var c=(t,e)=>U(t,"name",{value:e,configurable:!0});import{d as I,L as R,e as H,b8 as B,J as Y,f as k,V as b,Q as G,I as J,t as Z,m as C,M as T,b as E}from"./featureDialogs-Bas0NDXF.js";const S=Object.freeze({lineColor:9684477,dotColor:9684477,arrowColor:9684477,arrowLengthPx:12,arrowWidthPx:4,leaderDotRadiusPx:6,noteDotRadius:.08,noteDotColor:9684477});let A={...S};function D(){return A}c(D,"getPMIStyle");function st(t={}){return!t||typeof t!="object"||(A={...A,...t}),A}c(st,"setPMIStyle");function at(t={}){const e={...S},n=c((i,s)=>{const r=t[i];if(Number.isFinite(r))e[i]=r;else if(typeof r=="string"&&i.toLowerCase().includes("color")){const f=parseInt(r.replace("#",""),16);Number.isFinite(f)&&(e[i]=f)}else r!=null&&(e[i]=s)},"assign");return n("lineColor",S.lineColor),n("dotColor",S.dotColor),n("arrowColor",S.arrowColor),n("arrowLengthPx",S.arrowLengthPx),n("arrowWidthPx",S.arrowWidthPx),n("leaderDotRadiusPx",S.leaderDotRadiusPx),n("lineWidth",S.lineWidth||1),n("noteDotRadius",S.noteDotRadius),n("noteDotColor",S.noteDotColor),e}c(at,"sanitizePMIStyle");function q(t){try{return JSON.parse(JSON.stringify(t))}catch{return{}}}c(q,"safeCloneJSON");function X(t){return t?t.isPerspectiveCamera?"PerspectiveCamera":t.isOrthographicCamera?"OrthographicCamera":"Camera":"Camera"}c(X,"resolveCameraType");function W(t){if(!t)return null;if(Array.isArray(t)&&t.length===3)return[Number(t[0])||0,Number(t[1])||0,Number(t[2])||0];if(typeof t=="object"){const{x:e,y:n,z:i}=t;if([e,n,i].every(s=>Number.isFinite(s)))return[e,n,i]}return null}c(W,"extractVector3");function _(t){if(!t||typeof t!="object")return null;const e=Number(t.width),n=Number(t.height);return!(e>0)||!(n>0)?null:{width:e,height:n}}c(_,"normalizeViewportMetrics");function Q(t,e,n,i,s){if(!e)return;const r=i?.controlsState;if(r&&typeof e.setStateFromJSON=="function"){const x=Array.isArray(r.target)?r.target:n,o={arcballState:{target:Array.isArray(x)?x:[t.target?.x||0,t.target?.y||0,t.target?.z||0],cameraMatrix:{elements:Array.isArray(r.cameraMatrix)&&r.cameraMatrix.length===16?r.cameraMatrix:Array.from(t.matrix.elements)},cameraUp:r.cameraUp||{x:t.up.x,y:t.up.y,z:t.up.z},cameraNear:Number.isFinite(r.cameraNear)?r.cameraNear:t.near,cameraFar:Number.isFinite(r.cameraFar)?r.cameraFar:t.far,cameraZoom:Number.isFinite(r.cameraZoom)?r.cameraZoom:t.zoom,gizmoMatrix:{elements:Array.isArray(r.gizmoMatrix)&&r.gizmoMatrix.length===16?r.gizmoMatrix:Array.from((e._gizmos?.matrix||new T).elements)}}},l=Number.isFinite(r.cameraFov)?r.cameraFov:i?.projection?.fov;t.isPerspectiveCamera&&Number.isFinite(l)&&(o.arcballState.cameraFov=l);try{e.setStateFromJSON(JSON.stringify(o))}catch(g){console.warn("ArcballControls setStateFromJSON failed; falling back to manual sync",g),L(t,e,n,i),O(e,s);return}O(e,s);return}L(t,e,n,i),O(e,s)}c(Q,"syncArcballControls");function L(t,e,n,i){const s=Array.isArray(n)&&n.length===3?n:e.target?[e.target.x,e.target.y,e.target.z]:[0,0,0],r=new b(s[0],s[1],s[2]);try{typeof e.setTarget=="function"?e.setTarget(r.x,r.y,r.z):e.target?.set?e.target.set(r.x,r.y,r.z):e.target&&(e.target.x=r.x,e.target.y=r.y,e.target.z=r.z)}catch{}try{e._currentTarget?.copy&&e._currentTarget.copy(r),e._target0?.copy&&e._target0.copy(r)}catch{}const f=e._gizmos;if(f){try{f.position.copy(r),f.updateMatrix(),f.updateMatrixWorld(!0)}catch{}if(typeof e.calculateTbRadius=="function")try{e._tbRadius=e.calculateTbRadius(t)}catch{}if(typeof e.makeGizmos=="function")try{e.makeGizmos(r,e._tbRadius||1)}catch{}}try{e._cameraMatrixState?.copy?.(t.matrix),e._cameraMatrixState0?.copy?.(t.matrix),f?.matrix&&(e._gizmoMatrixState?.copy?.(f.matrix),e._gizmoMatrixState0?.copy?.(f.matrix)),e._cameraProjectionState?.copy?.(t.projectionMatrix),typeof e._zoomState=="number"&&(e._zoomState=t.zoom),typeof e._zoom0=="number"&&(e._zoom0=t.zoom),typeof e._fovState=="number"&&Number.isFinite(i?.projection?.fov??t.fov)&&(e._fovState=i?.projection?.fov??t.fov),typeof e._fov0=="number"&&Number.isFinite(i?.projection?.fov??t.fov)&&(e._fov0=i?.projection?.fov??t.fov),typeof e._nearPos=="number"&&(e._nearPos=Number.isFinite(i?.near)?i.near:t.near),typeof e._farPos=="number"&&(e._farPos=Number.isFinite(i?.far)?i.far:t.far),e._up0?.copy?.(t.up)}catch{}try{typeof e.updateTbState=="function"&&e.STATE?.IDLE?e.updateTbState(e.STATE.IDLE,!1):"_state"in e&&e.STATE?.IDLE&&(e._state=e.STATE.IDLE)}catch{}}c(L,"manualArcballSync");function O(t,e){try{if(typeof t._animationId=="number"&&t._animationId!==-1){const n=typeof cancelAnimationFrame=="function"?cancelAnimationFrame:typeof window<"u"&&typeof window.cancelAnimationFrame=="function"?window.cancelAnimationFrame.bind(window):null;n&&n(t._animationId)}t._animationId=-1,typeof t._timeStart=="number"&&(t._timeStart=-1)}catch{}try{t.updateMatrixState?.()}catch{}if(e)try{t.update?.()}catch{}}c(O,"finalizeArcballSync");function K(t){if(!t)return null;if(t.isPerspectiveCamera){const e=t.view&&t.view.enabled?{enabled:!0,fullWidth:t.view.fullWidth,fullHeight:t.view.fullHeight,offsetX:t.view.offsetX,offsetY:t.view.offsetY,width:t.view.width,height:t.view.height}:{enabled:!1};return{kind:"perspective",aspect:Number.isFinite(t.aspect)&&t.aspect>0?t.aspect:void 0,fov:t.fov,near:t.near,far:t.far,zoom:t.zoom??1,filmGauge:t.filmGauge??35,filmOffset:t.filmOffset??0,view:e}}if(t.isOrthographicCamera){const e=t.view&&t.view.enabled?{enabled:!0,fullWidth:t.view.fullWidth,fullHeight:t.view.fullHeight,offsetX:t.view.offsetX,offsetY:t.view.offsetY,width:t.view.width,height:t.view.height}:{enabled:!1};return{kind:"orthographic",aspect:Number.isFinite(t.top-t.bottom)&&Math.abs(t.top-t.bottom)>1e-9?(t.right-t.left)/(t.top-t.bottom):void 0,left:t.left,right:t.right,top:t.top,bottom:t.bottom,near:t.near,far:t.far,zoom:t.zoom??1,view:e}}return{kind:"generic",near:t.near??.1,far:t.far??2e3}}c(K,"captureProjection");function $(t,e=null,n=null,i=null){try{if(!t?.isPerspectiveCamera)return;const s=_(n);if(!s)return;const r=s.width/s.height;if(!(r>1e-9))return;t.aspect=r;const f=_(i),x=f?f.width/f.height:Number.isFinite(e?.aspect)&&e.aspect>1e-9?e.aspect:null;if(!(x>1e-9)||r>=x)return;const o=Number.isFinite(e?.fov)?e.fov:t.fov,l=Number.isFinite(e?.zoom)&&e.zoom>0?e.zoom:Number.isFinite(t.zoom)&&t.zoom>0?t.zoom:1;if(!(o>0)||o>=179)return;const m=Math.tan(E.degToRad(o)*.5)/l*x/r;if(!(m>0))return;const w=E.radToDeg(2*Math.atan(m*l));Number.isFinite(w)&&w>o&&(t.fov=Math.min(179,w))}catch{}}c($,"fitPerspectiveProjection");function j(t,e,n=null){if(!(!t||!e)){if(t.isPerspectiveCamera&&e.kind==="perspective"){Number.isFinite(e.fov)&&(t.fov=e.fov),Number.isFinite(e.near)&&(t.near=e.near),Number.isFinite(e.far)&&(t.far=e.far),Number.isFinite(e.zoom)&&(t.zoom=e.zoom),Number.isFinite(e.filmGauge)&&(t.filmGauge=e.filmGauge),Number.isFinite(e.filmOffset)&&(t.filmOffset=e.filmOffset),n!=null&&Number.isFinite(n)&&(t.aspect=n),e.view&&e.view.enabled&&t.setViewOffset?t.setViewOffset(e.view.fullWidth,e.view.fullHeight,e.view.offsetX,e.view.offsetY,e.view.width,e.view.height):t.clearViewOffset&&t.clearViewOffset();return}if(t.isOrthographicCamera&&e.kind==="orthographic"){const i=["left","right","top","bottom","near","far","zoom"];for(const s of i)Number.isFinite(e[s])&&(t[s]=e[s]);e.view&&e.view.enabled&&t.setViewOffset?t.setViewOffset(e.view.fullWidth,e.view.fullHeight,e.view.offsetX,e.view.offsetY,e.view.width,e.view.height):t.clearViewOffset&&t.clearViewOffset();return}Number.isFinite(e.near)&&(t.near=e.near),Number.isFinite(e.far)&&(t.far=e.far),Number.isFinite(e.zoom)&&(t.zoom=e.zoom)}}c(j,"applyProjection");function ft(t,{controls:e=null,viewport:n=null}={}){if(!t||!t.isCamera)return null;try{t.updateMatrixWorld(!0)}catch{}const i={version:3,type:X(t),worldMatrix:t.matrixWorld?.toArray?.()??null,projection:K(t),position:{x:t.position.x,y:t.position.y,z:t.position.z},quaternion:{x:t.quaternion.x,y:t.quaternion.y,z:t.quaternion.z,w:t.quaternion.w},up:{x:t.up.x,y:t.up.y,z:t.up.z},zoom:Number.isFinite(t.zoom)?t.zoom:1,near:Number.isFinite(t.near)?t.near:void 0,far:Number.isFinite(t.far)?t.far:void 0};if(t.layers?.mask!==void 0&&(i.layers=t.layers.mask),e?.target&&typeof e.target=="object"){i.target={x:e.target.x,y:e.target.y,z:e.target.z};try{const r=e._gizmos?.matrix;r&&(i.controlsState={target:[e.target.x,e.target.y,e.target.z],cameraMatrix:Array.from(t.matrix.elements),cameraUp:{x:t.up.x,y:t.up.y,z:t.up.z},cameraNear:t.near,cameraFar:t.far,cameraZoom:t.zoom,cameraFov:t.isPerspectiveCamera?t.fov:void 0,gizmoMatrix:Array.from(r.elements)})}catch{}}!i.target&&t.target&&typeof t.target=="object"&&(i.target={x:t.target.x,y:t.target.y,z:t.target.z}),t.userData&&typeof t.userData=="object"&&(i.userData=q(t.userData));const s=_(n);return s&&(i.viewport=s),i}c(ft,"captureCameraSnapshot");function ut(t,e,{controls:n=null,respectParent:i=!0,strictType:s=!1,overrideAspect:r=null,syncControls:f=!0,viewport:x=null}={}){if(!t||!t.isCamera||!e)return!1;let o=e;if(typeof o=="string")try{o=JSON.parse(o)}catch{return!1}if(!o||typeof o!="object")return!1;const l=o.type||null;if(s&&l){const p=X(t);if(l!==p)return!1}try{j(t,o.projection,r)}catch{}$(t,o?.projection,x,o?.viewport||null),tt(t,o?.projection,x),typeof o.layers=="number"&&t.layers&&(t.layers.mask=o.layers);const g=W(o.up)||W(o.upVector);g&&t.up.set(g[0],g[1],g[2]),o.userData&&typeof o.userData=="object"&&(t.userData=q(o.userData));let u=!1,m=!1;const w=Array.isArray(o.worldMatrix)&&o.worldMatrix.length===16?o.worldMatrix:null;if(w)try{const p=new T().fromArray(w),F=t.parent||null,M=new b,a=new G,d=new b;if(i&&F){F.updateMatrixWorld?.(!0);const z=new T().copy(F.matrixWorld).invert();new T().multiplyMatrices(z,p).decompose(M,a,d)}else p.decompose(M,a,d);const y=t.matrixAutoUpdate;t.matrixAutoUpdate=!1,t.position.copy(M),t.quaternion.copy(a),t.scale.copy(d),t.updateMatrix(),t.updateMatrixWorld(!0),t.matrixAutoUpdate=y,u=!0,m=!0}catch{u=!1}if(!u){const p=W(o.position);let F=!1;p&&(t.position.set(p[0],p[1],p[2]),F=!0);const M=o.quaternion;if(M&&typeof M=="object"){const{x:a,y:d,z:y,w:z}=M;[a,d,y,z].every(N=>Number.isFinite(N))&&(t.quaternion.set(a,d,y,z),F=!0)}Number.isFinite(o.zoom)&&(t.zoom=o.zoom,F=!0),Number.isFinite(o.near)&&(t.near=o.near,F=!0),Number.isFinite(o.far)&&(t.far=o.far,F=!0),F&&(t.updateMatrixWorld?.(!0),m=!0)}if(!m){try{t.updateProjectionMatrix?.()}catch{}if(n){try{n.update?.()}catch{}try{n.updateMatrixState?.()}catch{}}return!1}try{t.updateProjectionMatrix?.()}catch{}const v=o.target||o.controlsTarget,h=W(v);return n?Q(t,n,h,o,f):h&&t.target&&typeof t.target.set=="function"&&t.target.set(h[0],h[1],h[2]),!0}c(ut,"applyCameraSnapshot");function tt(t,e=null,n=null){try{if(!t?.isOrthographicCamera)return;const i=e||{},s=Number.isFinite(i.top)?i.top:t.top,r=Number.isFinite(i.bottom)?i.bottom:t.bottom,f=Number.isFinite(i.left)?i.left:t.left,x=Number.isFinite(i.right)?i.right:t.right,o=Number.isFinite(s)&&Number.isFinite(r)?s-r:t.top-t.bottom,l=Number.isFinite(f)&&Number.isFinite(x)?x-f:t.right-t.left;if(!Number.isFinite(o)||Math.abs(o)<1e-9||!Number.isFinite(l)||Math.abs(l)<1e-9)return;const g=Number.isFinite(s)&&Number.isFinite(r)?(s+r)*.5:(t.top+t.bottom)*.5,u=Number.isFinite(f)&&Number.isFinite(x)?(f+x)*.5:(t.left+t.right)*.5,m=_(n);let w=m?m.width/m.height:null;w>1e-9||(w=Number.isFinite(i.aspect)&&i.aspect>1e-9?i.aspect:l/o),(!Number.isFinite(w)||w<=1e-9)&&(w=1);const v=Math.abs(o)*.5,h=Math.abs(l)*.5,p=Math.max(h,v*w),F=Math.max(v,h/w),M=o>=0?1:-1;t.top=g+F*M,t.bottom=g-F*M,t.left=u-p,t.right=u+p,t.updateProjectionMatrix()}catch{}}c(tt,"adjustOrthographicFrustum");function V(t,e,n=void 0){const i=D(),s=n??i.lineColor??9684477,r=new I().setFromPoints([t.clone(),e.clone()]),f=new R({color:s,linewidth:i.lineWidth||1});return f.depthTest=!1,f.depthWrite=!1,f.transparent=!0,new H(r,f)}c(V,"makeOverlayLine");function lt(t,e,n=void 0,i={}){const s=D(),{viewer:r=null,dashPixels:f=10,gapPixels:x=10}=i||{},o=t.distanceTo(e);if(!(o>1e-6))return V(t,e,n??s.lineColor??9684477);const l=e.clone().sub(t).normalize(),g=t.clone().add(e).multiplyScalar(.5),u=et(r,g),m=it(u*f,o),w=nt(u*x,o),v=[];let h=0,p=t.clone();for(;h<o-1e-6;){const d=Math.min(m,o-h),y=p.clone().addScaledVector(l,d);if(v.push(p.clone(),y.clone()),h+=d,h>=o)break;const z=Math.min(w,o-h);p=y.clone().addScaledVector(l,z),h+=z}if(v.length<2)return V(t,e,n??s.lineColor??9684477);const F=new I().setFromPoints(v),M=new R({color:n??s.lineColor??9684477,linewidth:s.lineWidth||1});M.depthTest=!1,M.depthWrite=!1,M.transparent=!0;const a=new Z(F,M);return a.renderOrder=9994,a}c(lt,"makeOverlayDashedLine");function et(t,e){try{const n=t?.camera,i=t?.renderer;if(!n||!i)return .01;const s=i.domElement,r=Math.max(1,s?.clientHeight||s?.height||600);if(n.isOrthographicCamera)return(n.top-n.bottom)/Math.max(1e-6,n.zoom||1)/r;const f=n.getWorldPosition(new b),x=e?e.clone():n.getWorldDirection(new b).add(f),o=f.distanceTo(x),l=(n.fov||50)*Math.PI/180;return 2*Math.tan(l/2)*o/r}catch{return .01}}c(et,"worldUnitsPerPixelAtPoint");function it(t,e){if(!Number.isFinite(t)||t<=0)return e*.25;const n=Math.max(1e-4,e*.5);return Math.max(1e-4,Math.min(t,n))}c(it,"clampDashLength");function nt(t,e){if(!Number.isFinite(t)||t<0)return e*.25;const n=Math.max(1e-4,e*.5);return Math.max(1e-4,Math.min(t,n))}c(nt,"clampGapLength");function dt(t,e=void 0){const n=D(),i=e??n.dotColor??16777215,s=new J(t,12,8),r=new Y({color:i});return r.depthTest=!1,r.depthWrite=!1,r.transparent=!0,new k(s,r)}c(dt,"makeOverlaySphere");function pt(t,e,n,i,s,r){try{const f=D(),x=new B(s,i,8),o=new Y({color:r??f.arrowColor??9684477,depthTest:!1,depthWrite:!1,transparent:!0}),l=new k(x,o),g=e.clone().addScaledVector(n,-i*.5);l.position.copy(g);const u=new b(0,1,0),m=new G;return m.setFromUnitVectors(u,n.clone().normalize()),l.setRotationFromQuaternion(m),l.renderOrder=9996,t.add(l),l}catch{return null}}c(pt,"addArrowCone");function gt(t,e=1){try{const n=t?.renderer?.domElement?.getBoundingClientRect?.()||{width:800,height:600},i=t?.camera,s=Math.max(1,n.height||600);if(i&&i.isOrthographicCamera){const f=(i.top-i.bottom)/Math.max(1e-6,i.zoom||1)/s;return Math.max(1e-4,f*(e||1))}if(i&&i.isPerspectiveCamera){const r=(i.fov||50)*Math.PI/180,f=i.position.length(),o=2*Math.tan(r/2)*f/s;return Math.max(1e-4,o*(e||1))}return .01*(e||1)}catch{return .01*(e||1)}}c(gt,"screenSizeWorld");function ct(t,e){try{if(!e)return null;const n=e.userData||{},i=String(e.type||"").toUpperCase(),s=String(n.type||n.brepType||"").toUpperCase(),f=i==="FACE"||i==="PLANE"||!(i==="FACE"||i==="EDGE"||i==="PLANE")&&(s==="FACE"||s==="PLANE"),x=i==="EDGE"||!f&&(s==="EDGE"||e.isLine||e.isLine2||e.isLineSegments||e.isLineLoop);if(f){if(typeof e.getAverageNormal=="function"){const u=e.getAverageNormal();e.updateMatrixWorld(!0);const m=new C().getNormalMatrix(e.matrixWorld);return u.applyMatrix3(m).normalize()}const o=e.geometry;if(o){if(o.attributes&&o.attributes.normal){const u=o.attributes.normal.array;if(u.length>=3){const m=new b,w=u.length/3;for(let h=0;h<w;h++){const p=h*3;m.add(new b(u[p],u[p+1],u[p+2]))}m.divideScalar(w),e.updateMatrixWorld(!0);const v=new C().getNormalMatrix(e.matrixWorld);return m.applyMatrix3(v).normalize()}}if(o.attributes&&o.attributes.position){const u=o.attributes.position.array;if(u.length>=9){const m=new b;let w=0;const v=new b,h=new b,p=new b;e.updateMatrixWorld(!0);const F=Math.min(5,Math.floor(u.length/9));for(let M=0;M<F;M++){const a=M*9;if(a+8<u.length){v.set(u[a],u[a+1],u[a+2]).applyMatrix4(e.matrixWorld),h.set(u[a+3],u[a+4],u[a+5]).applyMatrix4(e.matrixWorld),p.set(u[a+6],u[a+7],u[a+8]).applyMatrix4(e.matrixWorld);const d=h.clone().sub(v).cross(p.clone().sub(v));d.lengthSq()>1e-10&&(d.normalize(),m.add(d),w++)}}if(w>0)return m.divideScalar(w).normalize()}}}const l=new b(0,0,1);e.updateMatrixWorld(!0);const g=new C().getNormalMatrix(e.matrixWorld);return l.applyMatrix3(g).normalize()}else if(x){const l=e.geometry;e.updateMatrixWorld(!0);const g=e.matrixWorld,u=c((a,d=!1)=>{if(!a)return null;let y=null;if(Array.isArray(a)&&a.length>=3)y=new b(a[0],a[1],a[2]);else if(typeof a=="object"){const z=Number(a.x),N=Number(a.y),P=Number(a.z);Number.isFinite(z)&&Number.isFinite(N)&&Number.isFinite(P)&&(y=new b(z,N,P))}return y?(d&&g&&y.applyMatrix4(g),y):null},"parsePoint"),m=c((a,d=!1)=>{if(!Array.isArray(a)||a.length<2)return null;let y=u(a[0],d);for(let z=1;z<a.length;z++){const N=u(a[z],d);if(!y||!N){y=N||y;continue}const P=N.clone().sub(y);if(P.lengthSq()>1e-12)return P.normalize();y=N}return null},"directionFromPointList");try{if(typeof e.points=="function"){const a=e.points(!0),d=m(a,!1);if(d)return d}}catch{}const w=Array.isArray(e?.userData?.polylineLocal)?e.userData.polylineLocal:null;if(w){const a=m(w,!0);if(a)return a}const v=l?.attributes?.instanceStart,h=l?.attributes?.instanceEnd;if(v&&h){const a=Math.min(v.count||0,h.count||0);for(let d=0;d<a;d++){const y=new b(v.getX(d),v.getY(d),v.getZ(d)),z=new b(h.getX(d),h.getY(d),h.getZ(d));g&&(y.applyMatrix4(g),z.applyMatrix4(g));const N=z.sub(y);if(N.lengthSq()>1e-12)return N.normalize()}}const p=l?.getAttribute?.("position");if(p&&p.itemSize===3&&p.count>=2){const a=new b,d=new b;a.set(p.getX(0),p.getY(0),p.getZ(0)),g&&a.applyMatrix4(g);for(let y=1;y<p.count;y++){d.set(p.getX(y),p.getY(y),p.getZ(y)),g&&d.applyMatrix4(g);const z=d.clone().sub(a);if(z.lengthSq()>1e-12)return z.normalize();a.copy(d)}}const F=new b(1,0,0),M=new C().getNormalMatrix(e.matrixWorld);return F.applyMatrix3(M).normalize()}return null}catch{return null}}c(ct,"getElementDirection");function ht(t,e){try{if(!e)return null;const n=e.geometry;if(n){if(typeof e.getWorldPosition=="function"){const s=n.attributes&&n.attributes.position?n.attributes.position.array:null;if(s&&s.length>=3){let r=0,f=0,x=0,o=0;const l=new b;e.updateMatrixWorld(!0);for(let g=0;g<s.length;g+=3)l.set(s[g],s[g+1],s[g+2]).applyMatrix4(e.matrixWorld),r+=l.x,f+=l.y,x+=l.z,o++;if(o>0)return new b(r/o,f/o,x/o)}}n.computeBoundingBox?.();const i=n.boundingBox;if(i)return i.getCenter(new b).applyMatrix4(e.matrixWorld)}return e.getWorldPosition(new b)}catch{return null}}c(ht,"objectRepresentativePoint");export{pt as a,st as b,at as c,D as d,ft as e,ut as f,ct as g,tt as h,V as i,lt as j,dt as m,ht as o,gt as s};
@@ -1,2 +1,2 @@
1
- var E=Object.defineProperty;var o=(e,t)=>E(e,"name",{value:t,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{BREP as i}from"./brep-kernel-DRr4NDNQ.js";import"./preload-helper-ZNr0Qq7Q.js";const m=document.getElementById("status"),b=document.getElementById("log"),f=document.getElementById("btn-run"),c=o((e,t)=>{m.textContent=e,m.className=`status ${t}`},"setStatus"),g=o(e=>Number(e).toFixed(6),"fmt"),u=o((...e)=>{const t=e.map(r=>typeof r=="string"?r:JSON.stringify(r)).join(" ");b.textContent+=`${t}
1
+ var E=Object.defineProperty;var o=(e,t)=>E(e,"name",{value:t,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{BREP as i}from"./brep-kernel-B2gzJr_I.js";import"./preload-helper-ZNr0Qq7Q.js";const m=document.getElementById("status"),b=document.getElementById("log"),f=document.getElementById("btn-run"),c=o((e,t)=>{m.textContent=e,m.className=`status ${t}`},"setStatus"),g=o(e=>Number(e).toFixed(6),"fmt"),u=o((...e)=>{const t=e.map(r=>typeof r=="string"?r:JSON.stringify(r)).join(" ");b.textContent+=`${t}
2
2
  `,console.log(...e)},"write"),s=o(e=>({volume:e.volume(),surfaceArea:e.surfaceArea(),triangles:e.getTriangleCount()}),"summarize"),d=o(()=>{b.textContent="",c("Running...","pending");const e=new i.Cube({x:2.2,y:2.2,z:2.2,name:"Cube"}),t=new i.Sphere({r:1.35,resolution:40,name:"Sphere"}),r=e.union(t),h=e.subtract(t),p=e.intersect(t),n={cube:s(e),sphere:s(t),union:s(r),subtract:s(h),intersect:s(p)};u("--- Boolean Results ---");for(const[v,l]of Object.entries(n))u(`${v.padEnd(10)} volume=${g(l.volume)} area=${g(l.surfaceArea)} triangles=${l.triangles}`);const a=1e-6;if(n.union.volume+a<Math.max(n.cube.volume,n.sphere.volume))throw new Error("Union volume is unexpectedly smaller than both source solids.");if(n.intersect.volume-a>Math.min(n.cube.volume,n.sphere.volume))throw new Error("Intersection volume is unexpectedly larger than a source solid.");if(n.subtract.volume-a>n.cube.volume)throw new Error("Subtract volume is unexpectedly larger than the original cube.");c("Completed","ok")},"runExample");f.addEventListener("click",()=>{try{d()}catch(e){console.error(e),u("ERROR:",e?.stack||e?.message||String(e)),c("Failed","err")}});try{d()}catch(e){console.error(e),u("ERROR:",e?.stack||e?.message||String(e)),c("Failed","err")}
@@ -1,4 +1,4 @@
1
- var g=Object.defineProperty;var r=(t,n)=>g(t,"name",{value:n,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{BREP as c}from"./brep-kernel-DRr4NDNQ.js";import"./preload-helper-ZNr0Qq7Q.js";const l=document.getElementById("status"),d=document.getElementById("log"),p=document.getElementById("btn-run"),s=r((t,n)=>{l.textContent=t,l.className=`status ${n}`},"setStatus"),e=r((...t)=>{const n=t.map(o=>typeof o=="string"?o:JSON.stringify(o)).join(" ");d.textContent+=`${n}
1
+ var g=Object.defineProperty;var r=(t,n)=>g(t,"name",{value:n,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{BREP as c}from"./brep-kernel-B2gzJr_I.js";import"./preload-helper-ZNr0Qq7Q.js";const l=document.getElementById("status"),d=document.getElementById("log"),p=document.getElementById("btn-run"),s=r((t,n)=>{l.textContent=t,l.className=`status ${n}`},"setStatus"),e=r((...t)=>{const n=t.map(o=>typeof o=="string"?o:JSON.stringify(o)).join(" ");d.textContent+=`${n}
2
2
  `,console.log(...t)},"write"),u=r((t,n=8)=>t.split(`
3
3
  `).slice(0,n).join(`
4
4
  `),"firstLines"),m=r(()=>{d.textContent="",s("Running...","pending");const t=new c.Cylinder({radius:1,height:3,resolution:48,name:"Shaft"}).bakeTRS({position:[0,0,.6],rotationEuler:[90,0,0],scale:[1,1,1]}),n=new c.Cone({radius:1.55,height:1.6,resolution:48,name:"Head"}).bakeTRS({position:[0,1.65,.6],rotationEuler:[-90,0,0],scale:[1,1,1]}),o=t.union(n),i=o.toSTL("api_example_part",4),a=o.toSTEP("api_example_part",{precision:4});if(e("--- Export Summary ---"),e("Volume:",o.volume()),e("Surface area:",o.surfaceArea()),e("Triangles:",o.getTriangleCount()),e("STL characters:",i.length),e("STEP characters:",a.length),e(""),e("--- STL Preview ---"),e(u(i)),e(""),e("--- STEP Preview ---"),e(u(a)),!i.startsWith("solid"))throw new Error('STL output did not start with "solid".');if(!a.includes("ISO-10303-21"))throw new Error("STEP output did not contain expected ISO header.");s("Completed","ok")},"runExample");p.addEventListener("click",()=>{try{m()}catch(t){console.error(t),e("ERROR:",t?.stack||t?.message||String(t)),s("Failed","err")}});try{m()}catch(t){console.error(t),e("ERROR:",t?.stack||t?.message||String(t)),s("Failed","err")}
@@ -1,2 +1,2 @@
1
- var g=Object.defineProperty;var n=(e,t)=>g(e,"name",{value:t,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{BREP as o}from"./brep-kernel-DRr4NDNQ.js";import"./preload-helper-ZNr0Qq7Q.js";const m=document.getElementById("status"),u=document.getElementById("log"),y=document.getElementById("btn-run"),s=n((e,t)=>{m.textContent=e,m.className=`status ${t}`},"setStatus"),l=n(e=>Number(e).toFixed(6),"fmt"),a=n((...e)=>{const t=e.map(r=>typeof r=="string"?r:JSON.stringify(r)).join(" ");u.textContent+=`${t}
1
+ var g=Object.defineProperty;var n=(e,t)=>g(e,"name",{value:t,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{BREP as o}from"./brep-kernel-B2gzJr_I.js";import"./preload-helper-ZNr0Qq7Q.js";const m=document.getElementById("status"),u=document.getElementById("log"),y=document.getElementById("btn-run"),s=n((e,t)=>{m.textContent=e,m.className=`status ${t}`},"setStatus"),l=n(e=>Number(e).toFixed(6),"fmt"),a=n((...e)=>{const t=e.map(r=>typeof r=="string"?r:JSON.stringify(r)).join(" ");u.textContent+=`${t}
2
2
  `,console.log(...e)},"write"),C=n(e=>({volume:e.volume(),area:e.surfaceArea(),triangles:e.getTriangleCount()}),"summarize"),c=n(()=>{u.textContent="",s("Running...","pending");const e=[["Cube",()=>new o.Cube({x:2,y:3,z:4,name:"Cube"})],["Sphere",()=>new o.Sphere({r:1.2,resolution:32,name:"Sphere"})],["Cylinder",()=>new o.Cylinder({radius:1,height:2.4,resolution:48,name:"Cylinder"})],["Cone",()=>new o.Cone({radius:1.1,height:2.1,resolution:48,name:"Cone"})],["Torus",()=>new o.Torus({mR:2,tR:.55,resolution:64,name:"Torus"})],["Pyramid",()=>new o.Pyramid({bL:2,s:4,h:2.7,name:"Pyramid"})]];a("--- Primitive Summary ---");for(const[t,r]of e){const d=r(),i=C(d);a(`${t.padEnd(10)} volume=${l(i.volume)} area=${l(i.area)} triangles=${i.triangles}`)}s("Completed","ok")},"runExample");y.addEventListener("click",()=>{try{c()}catch(e){console.error(e),a("ERROR:",e?.stack||e?.message||String(e)),s("Failed","err")}});try{c()}catch(e){console.error(e),a("ERROR:",e?.stack||e?.message||String(e)),s("Failed","err")}
@@ -1,2 +1,2 @@
1
- var u=Object.defineProperty;var n=(e,t)=>u(e,"name",{value:t,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{BREP as g}from"./brep-kernel-DRr4NDNQ.js";import"./preload-helper-ZNr0Qq7Q.js";const c=document.getElementById("status"),l=document.getElementById("log"),b=document.getElementById("btn-run"),s=n((e,t)=>{c.textContent=e,c.className=`status ${t}`},"setStatus"),i=n(e=>Number(e).toFixed(6),"fmt"),m=n((...e)=>{const t=e.map(o=>typeof o=="string"?o:JSON.stringify(o)).join(" ");l.textContent+=`${t}
1
+ var u=Object.defineProperty;var n=(e,t)=>u(e,"name",{value:t,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{BREP as g}from"./brep-kernel-B2gzJr_I.js";import"./preload-helper-ZNr0Qq7Q.js";const c=document.getElementById("status"),l=document.getElementById("log"),b=document.getElementById("btn-run"),s=n((e,t)=>{c.textContent=e,c.className=`status ${t}`},"setStatus"),i=n(e=>Number(e).toFixed(6),"fmt"),m=n((...e)=>{const t=e.map(o=>typeof o=="string"?o:JSON.stringify(o)).join(" ");l.textContent+=`${t}
2
2
  `,console.log(...e)},"write"),r=n((e,t)=>{m(`${e.padEnd(16)} volume=${i(t.volume())} area=${i(t.surfaceArea())} triangles=${t.getTriangleCount()}`)},"describe"),d=n(()=>{l.textContent="",s("Running...","pending");const e=new g.Cube({x:2.2,y:1.4,z:1,name:"BaseCube"}),t=e.clone().bakeTRS({position:[2,.4,.3],rotationEuler:[0,35,20],scale:[1.1,.85,1.25]}),o=t.mirrorAcrossPlane([0,0,0],[1,0,0]),a=t.union(o);if(m("--- Transform Summary ---"),r("base",e),r("moved",t),r("mirrored",o),r("combined",a),a.volume()<=t.volume())throw new Error("Combined solid volume should be greater than a single moved solid.");s("Completed","ok")},"runExample");b.addEventListener("click",()=>{try{d()}catch(e){console.error(e),m("ERROR:",e?.stack||e?.message||String(e)),s("Failed","err")}});try{d()}catch(e){console.error(e),m("ERROR:",e?.stack||e?.message||String(e)),s("Failed","err")}
@@ -1,4 +1,4 @@
1
- var H=Object.defineProperty;var s=(e,o)=>H(e,"name",{value:o,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{Sketcher2DEmbed as J}from"./brep-kernel-DRr4NDNQ.js";import"./preload-helper-ZNr0Qq7Q.js";const k=document.getElementById("btn-create"),C=document.getElementById("btn-destroy"),I=document.getElementById("btn-apply-css"),w=document.getElementById("btn-apply-theme"),B=document.getElementById("btn-export-svg"),$=document.getElementById("btn-export-dxf"),r=document.getElementById("btn-download-dxf"),D=document.getElementById("btn-export-polylines"),F=document.getElementById("geometry-color"),L=document.getElementById("point-color"),N=document.getElementById("constraint-color"),G=document.getElementById("background-color"),T=document.getElementById("point-size-px"),A=document.getElementById("curve-thickness-px"),f=document.getElementById("sidebar-expanded"),u=document.getElementById("grid-visible"),V=document.getElementById("grid-spacing"),W=document.getElementById("curve-resolution"),R=document.getElementById("css-input"),Y=document.getElementById("sketch-status"),q=document.getElementById("sketch-host"),d=document.getElementById("event-output"),g=document.getElementById("svg-preview"),O=document.getElementById("path-output"),P=document.getElementById("dxf-output"),M=document.getElementById("polyline-output");let t=null,i=null,m=0,h=0,y=0,c=null;const K=6,n=s(e=>{Y.textContent=e},"setSketchStatus"),b=s(()=>{c&&(URL.revokeObjectURL(c),c=null)},"revokeDxfDownload"),Q=s(e=>{if(b(),typeof e!="string"||!e.length){r.disabled=!0;return}const o=new Blob([e],{type:"application/dxf"});c=URL.createObjectURL(o),r.disabled=!1},"setDxfDownload"),E=s(e=>{k.disabled=e,C.disabled=!e,I.disabled=!e,w.disabled=!e,B.disabled=!e,$.disabled=!e,D.disabled=!e,r.disabled=!e||!c},"setSketchButtons"),p=s((e,o=null)=>{const a=new Date().toLocaleTimeString(),j=o==null?`[${a}] ${e}`:`[${a}] ${e} ${JSON.stringify(o)}`,z=d.textContent==="(No sketch events yet)"?[]:d.textContent.split(`
1
+ var H=Object.defineProperty;var s=(e,o)=>H(e,"name",{value:o,configurable:!0});import"./modulepreload-polyfill-BdX5DvLD.js";/* empty css */import{Sketcher2DEmbed as J}from"./brep-kernel-B2gzJr_I.js";import"./preload-helper-ZNr0Qq7Q.js";const k=document.getElementById("btn-create"),C=document.getElementById("btn-destroy"),I=document.getElementById("btn-apply-css"),w=document.getElementById("btn-apply-theme"),B=document.getElementById("btn-export-svg"),$=document.getElementById("btn-export-dxf"),r=document.getElementById("btn-download-dxf"),D=document.getElementById("btn-export-polylines"),F=document.getElementById("geometry-color"),L=document.getElementById("point-color"),N=document.getElementById("constraint-color"),G=document.getElementById("background-color"),T=document.getElementById("point-size-px"),A=document.getElementById("curve-thickness-px"),f=document.getElementById("sidebar-expanded"),u=document.getElementById("grid-visible"),V=document.getElementById("grid-spacing"),W=document.getElementById("curve-resolution"),R=document.getElementById("css-input"),Y=document.getElementById("sketch-status"),q=document.getElementById("sketch-host"),d=document.getElementById("event-output"),g=document.getElementById("svg-preview"),O=document.getElementById("path-output"),P=document.getElementById("dxf-output"),M=document.getElementById("polyline-output");let t=null,i=null,m=0,h=0,y=0,c=null;const K=6,n=s(e=>{Y.textContent=e},"setSketchStatus"),b=s(()=>{c&&(URL.revokeObjectURL(c),c=null)},"revokeDxfDownload"),Q=s(e=>{if(b(),typeof e!="string"||!e.length){r.disabled=!0;return}const o=new Blob([e],{type:"application/dxf"});c=URL.createObjectURL(o),r.disabled=!1},"setDxfDownload"),E=s(e=>{k.disabled=e,C.disabled=!e,I.disabled=!e,w.disabled=!e,B.disabled=!e,$.disabled=!e,D.disabled=!e,r.disabled=!e||!c},"setSketchButtons"),p=s((e,o=null)=>{const a=new Date().toLocaleTimeString(),j=o==null?`[${a}] ${e}`:`[${a}] ${e} ${JSON.stringify(o)}`,z=d.textContent==="(No sketch events yet)"?[]:d.textContent.split(`
2
2
  `).filter(Boolean),S=[j,...z].slice(0,K);d.textContent=S.length?S.join(`
3
3
  `):"(No sketch events yet)"},"pushEvent"),U=s(()=>({geometryColor:F.value,pointColor:L.value,constraintColor:N.value,backgroundColor:G.value,pointSizePx:Math.max(1,Number(T.value)||10),curveThicknessPx:Math.max(.5,Number(A.value)||2)}),"currentTheme"),x=s(()=>{const e=Number(V.value);return Number.isFinite(e)&&e>0?e:1},"currentGridSpacing"),v=s(()=>{const e=Number(W.value);return Number.isFinite(e)?Math.max(3,Math.min(2048,Math.floor(e))):64},"currentCurveResolution"),Z=s(async()=>{t||(t=new J({cssText:R.value,...U(),sidebarExpanded:f.checked,gridVisible:u.checked,gridSpacing:x(),onChange:s(e=>{i=e,m+=1;const o=Array.isArray(e?.geometries)?e.geometries.length:0;n(`Sketch updated (${m}). Geometries: ${o}`),p("onChange",{geometries:o})},"onChange"),onFinished:s(e=>{i=e,h+=1;const o=Array.isArray(e?.geometries)?e.geometries.length:0;n(`Sketch finished (${h}). Geometries: ${o}`),p("onFinished",{geometries:o}),X().catch(a=>{console.error(a),n(`Failed to export SVG after Finish: ${a?.message||String(a)}`)})},"onFinished"),onCancelled:s(()=>{y+=1,n(`Sketch cancelled (${y}).`),p("onCancelled")},"onCancelled")}),await t.mount(q),i=await t.getSketch(),E(!0),n("Sketcher iframe mounted. Draw geometry and run any export action."))},"attachSketcher"),_=s(async()=>{t&&(await t.destroy(),t=null,i=null,m=0,h=0,y=0,E(!1),n("Sketcher destroyed."),d.textContent="(No sketch events yet)",g.innerHTML="",O.textContent="(No SVG exported yet)",P.textContent="(No DXF exported yet)",M.textContent="(No 3D polylines exported yet)",b())},"detachSketcher"),ee=s(async()=>{t&&(await t.setCss(R.value),n("Custom CSS applied to iframe."))},"applySketchCss"),l=s(async()=>{t&&(await t.setTheme(U()),await t.setSidebarExpanded(f.checked),typeof t.setGrid=="function"?await t.setGrid({visible:u.checked,spacing:x()}):(typeof t.setGridVisible=="function"&&await t.setGridVisible(u.checked),typeof t.setGridSpacing=="function"&&await t.setGridSpacing(x())),n("Theme + sidebar + grid state applied to iframe."))},"applySketchTheme"),X=s(async()=>{if(!t)return;const e=await t.exportSVG({flipY:!0,precision:3,stroke:"#111111",strokeWidth:1.5,fill:"none",padding:12,curveResolution:v()});i=await t.getSketch({preferCached:!0}),g.innerHTML=e.svg,O.textContent=e.paths.length?e.paths.map(o=>`id=${o.id} type=${o.type} d="${o.d}"`).join(`
4
4
  `):"(No sketch geometry to export)",n(`Exported ${e.paths.length} SVG paths.`),g.scrollIntoView({behavior:"smooth",block:"start"})},"exportSvg"),te=s(async()=>{if(!t)return;const e=await t.exportDXF({units:"mm",curveResolution:v(),includeConstruction:!1});P.textContent=e?.dxf||"(No DXF payload returned)",Q(e?.dxf||""),n(`Exported DXF with ${e?.polylines?.length||0} polylines.`)},"exportDxf"),ne=s(async()=>{if(!t)return;const e=await t.export3DPolylines({curveResolution:v(),includeConstruction:!1,origin:[0,0,0],xAxis:[1,0,0],yAxis:[0,1,0]});M.textContent=JSON.stringify(e,null,2),n(`Exported ${e?.polylines?.length||0} 3D polylines.`)},"export3DPolylines");k.addEventListener("click",()=>{Z().catch(e=>{console.error(e),n(`Failed to create sketcher: ${e?.message||String(e)}`)})});C.addEventListener("click",()=>{_().catch(e=>{console.error(e),n(`Failed to destroy sketcher: ${e?.message||String(e)}`)})});I.addEventListener("click",()=>{ee().catch(e=>{console.error(e),n(`Failed to apply CSS: ${e?.message||String(e)}`)})});w.addEventListener("click",()=>{l().catch(e=>{console.error(e),n(`Failed to apply theme: ${e?.message||String(e)}`)})});B.addEventListener("click",()=>{X().catch(e=>{console.error(e),n(`Failed to export SVG: ${e?.message||String(e)}`)})});$.addEventListener("click",()=>{te().catch(e=>{console.error(e),n(`Failed to export DXF: ${e?.message||String(e)}`)})});r.addEventListener("click",()=>{if(!c)return;const e=document.createElement("a");e.href=c,e.download="sketch-export.dxf",e.click()});D.addEventListener("click",()=>{ne().catch(e=>{console.error(e),n(`Failed to export 3D polylines: ${e?.message||String(e)}`)})});[F,L,N,G,T,A].forEach(e=>{e.addEventListener("input",()=>{t&&l().catch(o=>{console.error(o),n(`Failed to apply theme: ${o?.message||String(o)}`)})})});f.addEventListener("change",()=>{t&&l().catch(e=>{console.error(e),n(`Failed to apply sidebar state: ${e?.message||String(e)}`)})});u.addEventListener("change",()=>{t&&l().catch(e=>{console.error(e),n(`Failed to apply grid visibility: ${e?.message||String(e)}`)})});V.addEventListener("input",()=>{t&&l().catch(e=>{console.error(e),n(`Failed to apply grid spacing: ${e?.message||String(e)}`)})});window.addEventListener("beforeunload",()=>{t&&t.destroy().catch(()=>{}),b()});E(!1);i&&!Array.isArray(i?.geometries)&&console.warn("Unexpected sketch payload shape",i);