@mlightcad/libredwg-converter 3.15.23 → 3.15.25

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.
@@ -1 +1 @@
1
- (function(T,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(T=typeof globalThis<"u"?globalThis:T||self,r(T["libredwg-converter"]={},T.dataModel))})(this,(function(T,r){"use strict";function y(C){return!!C&&Math.hypot(C.x||0,C.y||0,C.z||0)>1e-9}function x(C){const e=C.elevation;return Number.isFinite(e)?e:void 0}class S{convert(e){const t=this.createEntity(e);if(t&&(this.processCommonAttrs(e,t),e.type==="ARCALIGNEDTEXT")){const i=e.rawTextColor;t.applyRawTextColor(i)}return t}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="ATTDEF"?this.convertAttributeDefinition(e):e.type=="ATTRIB"?this.convertAttribute(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MLINE"?this.convertMLine(e):e.type=="MTEXT"?this.convertMText(e):e.type=="MULTILEADER"||e.type=="MLEADER"?this.convertMLeader(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE2D"?this.convertPolyline2d(e):e.type=="POLYLINE3D"?this.convertPolyline3d(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="TOLERANCE"?this.convertTolerance(e):e.type=="SHAPE"?this.convertShape(e):e.type=="SOLID"?this.convertSolid(e):e.type=="TRACE"?this.convertTrace(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):e.type=="ACAD_PROXY_ENTITY"?this.convertProxyEntity(e):e.type=="OLE2FRAME"?this.convertOle2Frame(e):e.type=="OLEFRAME"?this.convertOleFrame(e):e.type=="ARCALIGNEDTEXT"?this.convertArcAlignedText(e):null}convertProxyEntity(e){const t=new r.AcDbProxyEntity;if(t.proxyEntityClassId=e.proxyEntityClassId,e.originalDxfName&&(t.originalDxfName=e.originalDxfName),e.applicationEntityClassId!=null&&(t.applicationEntityClassId=e.applicationEntityClassId),e.objectDrawingFormat!=null&&(t.objectDrawingFormat=e.objectDrawingFormat),e.originalDataFormat!=null&&(t.originalDataFormat=e.originalDataFormat),e.graphicsData){const i=r.acdbHexStringsToBytes([e.graphicsData]),n=e.graphicsDataSize??i.length;t.setProxyGraphic(i.subarray(0,n))}return t}convertFace(e){const t=new r.AcDbFace;return e.corner1&&t.setVertexAt(0,e.corner1),e.corner2&&t.setVertexAt(1,e.corner2),e.corner3&&t.setVertexAt(2,e.corner3),e.corner4&&t.setVertexAt(3,e.corner4),t.setEdgeInvisibilities(e.flag),t}convertArc(e){const t=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbArc(r.acgeTransformOcsPointToWcs(e.center,t),e.radius,e.startAngle,e.endAngle,t)}convertCirle(e){const t=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbCircle(r.acgeTransformOcsPointToWcs(e.center,t),e.radius,t)}convertEllipse(e){const t=new r.AcGeVector3d(e.majorAxisEndPoint),i=t.length();return new r.AcDbEllipse(e.center,e.extrusionDirection??r.AcGeVector3d.Z_AXIS,t,i,i*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const t=e.startPoint,i=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(t.x,t.y,t.z),new r.AcGePoint3d(i.x,i.y,i.z))}convertSpline(e){return r.AcDbSpline.fromDwgSpline(e)}convertPoint(e){const t=new r.AcDbPoint;return t.position=e.position,t}convertShape(e){const t=e.extrusionDirection??r.AcGeVector3d.Z_AXIS,i=new r.AcDbShape;return i.position=r.acgeTransformOcsPointToWcs(e.insertionPoint,t),i.size=e.size,i.shapeNumber=e.shapeNumber,e.styleName&&(i.styleName=e.styleName),i.rotation=e.rotation??0,i.widthFactor=e.xScale??1,i.oblique=e.obliqueAngle??0,i.thickness=e.thickness??0,i.normal.copy(t),i}convertSolid(e){return this.convertTraceLike(new r.AcDbSolid,e)}convertTrace(e){return this.convertTraceLike(new r.AcDbTrace,e)}convertTraceLike(e,t){const i=t.extrusionDirection??r.AcGeVector3d.Z_AXIS,n=s=>r.acgeTransformOcsPointToWcs({x:s.x,y:s.y,z:s.z??0},i),o=t.corner4??t.corner3;return e.setPointAt(0,n(t.corner1)),e.setPointAt(1,n(t.corner2)),e.setPointAt(2,n(t.corner3)),e.setPointAt(3,n(o)),e.thickness=t.thickness??0,e.normal.copy(i),e.elevation=e.getPointAt(0).z,e}convertLWPolyline(e){const t=new r.AcDbPolyline;t.closed=!!(e.flag&512);const i=e.constantWidth??-1;return e.vertices.forEach((n,o)=>{t.addVertexAt(o,new r.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth??i,n.endWidth??i)}),Number.isFinite(e.elevation)&&(t.elevation=e.elevation),Number.isFinite(e.thickness)&&(t.thickness=e.thickness),y(e.extrusionDirection)&&(t.normal=e.extrusionDirection),t}convertPolyline2d(e){var f;const t=!!(e.flag&1),i=!!(e.flag&16),n=!!(e.flag&64),o=!!(e.flag&32),s=[],c=[],a=[];if(e.vertices.map(l=>{if(!(l.flag&16))if(n&&l.flag&128)if(l.flag&64)s.push({x:l.x,y:l.y,z:l.z}),c.push(l.bulge??0);else{const u=[];l.polyfaceIndex0!=null&&l.polyfaceIndex0!=0&&u.push(Math.abs(l.polyfaceIndex0)-1),l.polyfaceIndex1!=null&&l.polyfaceIndex1!=0&&u.push(Math.abs(l.polyfaceIndex1)-1),l.polyfaceIndex2!=null&&l.polyfaceIndex2!=0&&u.push(Math.abs(l.polyfaceIndex2)-1),l.polyfaceIndex3!=null&&l.polyfaceIndex3!=0&&u.push(Math.abs(l.polyfaceIndex3)-1),u.length>=3&&a.push(u)}else s.push({x:l.x,y:l.y,z:l.z}),c.push(l.bulge??0)}),i){const l=e.meshMVertexCount??2,u=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(l,u,s,t,o)}else{if(n)return new r.AcDbPolyFaceMesh(s,a);{let l=r.AcDbPoly2dType.SimplePoly;e.flag&2?l=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?l=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(l=r.AcDbPoly2dType.QuadSplinePoly));const u=new r.AcDb2dPolyline(l,s,((f=s[0])==null?void 0:f.z)??0,t,e.startWidth,e.endWidth,c);return y(e.extrusionDirection)&&(u.normal=e.extrusionDirection),u}}}convertPolyline3d(e){const t=!!(e.flag&1),i=[];e.vertices.map(o=>{o.flag&16||i.push({x:o.x,y:o.y,z:o.z})});let n=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?n=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(n=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(n,i,t)}convertHatch(e){var n;const t=new r.AcDbHatch;if((n=e.definitionLines)==null||n.forEach(o=>{t.definitionLines.push({angle:o.angle,base:o.base,offset:o.offset,dashLengths:o.numberOfDashLengths>0?o.dashLengths:[]})}),t.hatchStyle=e.hatchStyle,t.patternName=e.patternName,e.solidFill==1&&(t.isSolidFill=!0),t.patternType=e.patternType,t.patternAngle=e.patternAngle==null?0:e.patternAngle,t.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(o=>{if(o.boundaryPathTypeFlag&2){const c=o,a=new r.AcGePolyline2d;a.closed=c.isClosed,c.vertices.forEach((f,l)=>{a.addVertexAt(l,{x:f.x,y:f.y,bulge:f.bulge})}),t.add(a)}else{const c=o,a=[];c.edges.forEach(l=>{if(l!=null){if(l.type==1){const u=l;a.push(new r.AcGeLine2d(u.start,u.end))}else if(l.type==2){const u=l;a.push(new r.AcGeCircArc2d(u.center,u.radius,u.startAngle,u.endAngle,!u.isCCW))}else if(l.type==3){const u=l;new r.AcGeVector2d().subVectors(u.end,u.center);const h=Math.sqrt(Math.pow(u.end.x,2)+Math.pow(u.end.y,2)),A=h*u.lengthOfMinorAxis;let d=u.startAngle,b=u.endAngle;const L=Math.atan2(u.end.y,u.end.x);u.isCCW||(d=Math.PI*2-d,b=Math.PI*2-b),a.push(new r.AcGeEllipseArc2d({...u.center,z:0},h,A,d,b,!u.isCCW,L))}else if(l.type==4){const u=r.AcGeSpline3d.fromDwgSplineEdge(l);u&&a.push(u)}}});const f=r.AcGeLoop2d.buildFromEdges(a);f.length===1?t.add(f[0]):a.length>0&&t.add(new r.AcGeLoop2d(a))}}),e.gradientFlag){const o=e;if(t.hatchObjectType=r.AcDbHatchObjectType.GradientObject,t.gradientName=o.gradientName,t.gradientAngle=o.gradientRotation??0,t.gradientShift=o.gradientDefinition??0,t.gradientOneColorMode=o.gradientColorFlag==1,t.shadeTintValue=o.colorTint??0,o.gradientColors){const s=o.gradientColors.length;s>1?(t.gradientStartColor=o.gradientColors[0].rgb,t.gradientEndColor=o.gradientColors[1].rgb):s>0&&(t.gradientStartColor=o.gradientColors[0].rgb)}}return e.extrusionDirection&&(t.normal=e.extrusionDirection),t}convertTable(e){const t=new r.AcDbTable(e.name??"",e.rowCount,e.columnCount);return t.tableStyleId=e.tableStyleId,t.owningBlockRecordId=e.blockRecordHandle,e.directionVector&&(t.horizontalDirection=new r.AcGeVector3d(e.directionVector)),t.attachmentPoint=e.attachmentPoint,t.position.copy(e.startPoint),t.tableValueFlag=e.tableValue,t.tableOverrideFlag=e.overrideFlag,t.borderColorOverrideFlag=e.borderColorOverrideFlag,t.borderLineweightOverrideFlag=e.borderLineWeightOverrideFlag,t.borderVisibilityOverrideFlag=e.borderVisibilityOverrideFlag,e.columnWidthArr.forEach((i,n)=>t.setColumnWidth(n,i)),e.rowHeightArr.forEach((i,n)=>t.setRowHeight(n,i)),e.cells.forEach((i,n)=>{t.setCell(n,i)}),t}convertText(e){const t=new r.AcDbText;t.textString=e.text,t.styleName=e.styleName,t.height=e.textHeight,t.position.copy(e.startPoint);const i=!e.endPoint||e.endPoint.x===0&&e.endPoint.y===0&&(e.endPoint.z??0)===0;e.endPoint&&!i?(t.alignmentPoint.copy(e.endPoint),t.hasAlignmentPoint=!0):(t.alignmentPoint.copy(e.startPoint),t.hasAlignmentPoint=!1),t.rotation=e.rotation,t.oblique=e.obliqueAngle??0,t.thickness=e.thickness,t.horizontalMode=e.halign,t.verticalMode=e.valign,t.widthFactor=e.xScale??1,y(e.extrusionDirection)&&(t.normal=e.extrusionDirection);const n=x(e);return n!=null&&(t.position.z=n,t.alignmentPoint.z=n),t}convertArcAlignedText(e){const t=new r.AcDbArcAlignedText;return t.textString=e.text,t.textSize=e.textSize,t.xScale=e.xScale>0?e.xScale:1,t.characterSpacing=e.characterSpacing,e.styleName&&(t.styleName=e.styleName),t.fontName=e.fontName,t.bigFontName=e.bigFontName,t.offsetFromArc=e.offsetFromArc,t.rightOffset=e.rightOffset,t.leftOffset=e.leftOffset,t.center=new r.AcGePoint3d(e.center.x,e.center.y,e.center.z),t.radius=e.radius,t.startAngle=e.startAngle,t.endAngle=e.endAngle,t.normal=new r.AcGeVector3d(e.extrusionDirection.x,e.extrusionDirection.y,e.extrusionDirection.z||1),t.characterSet=e.characterSet,t.pitchAndFamily=e.pitchAndFamily,t.isShx=e.isShx,t.isBold=e.isBold,t.isItalic=e.isItalic,t.isUnderlined=e.isUnderlined,t.alignment=e.alignment,t.isReverse=e.isReverse,t.wizardFlag=e.wizardFlag,t.textPosition=e.textPosition,t.textDirection=e.textDirection,e.arcHandle&&(t.arcId=e.arcHandle),t}convertTolerance(e){const t=new r.AcDbFcf;return t.location.copy(e.insertionPoint),t.text=e.text,t.dimensionStyle=e.styleName??"",e.extrusionDirection&&t.normal.copy(e.extrusionDirection),e.xAxisDirection&&t.direction.copy(e.xAxisDirection),t}convertMText(e){const t=new r.AcDbMText;t.contents=e.text,e.styleName!=null&&(t.styleName=e.styleName),t.height=e.textHeight,t.width=e.rectWidth,t.rotation=e.rotation||0,t.location=e.insertionPoint,t.attachmentPoint=e.attachmentPoint,e.direction&&(t.direction=new r.AcGeVector3d(e.direction)),t.drawingDirection=e.drawingDirection,e.lineSpacing!=null&&e.lineSpacing>0&&(t.lineSpacingFactor=e.lineSpacing),e.lineSpacingStyle!=null&&(t.lineSpacingStyle=e.lineSpacingStyle),e.extentsWidth!=null&&e.extentsWidth>0&&(t.extentsWidth=e.extentsWidth);const i=e.backgroundFill??0;if(i!==0){if(t.backgroundFill=!0,t.useBackgroundColor=(i&2)!==0,!t.useBackgroundColor&&e.backgroundFillColor!=null){const n=e.backgroundFillColor>>>0,o=n>>>24&255;if(o>=192&&o<=200){const s=n&255;if(o===197||o===195&&s>=1&&s<=255)t.backgroundFillColor=o===197?7:s;else if(o===194){const c=n&16777215;c!==0&&(t.backgroundFillColor=c)}}else t.backgroundFillColor=n}e.fillBoxScale!=null&&e.fillBoxScale>0&&(t.backgroundScaleFactor=e.fillBoxScale),e.backgroundFillTransparency!=null&&(t.backgroundFillTransparency=e.backgroundFillTransparency)}return t}convertLeader(e){const t=new r.AcDbLeader;return e.vertices.forEach(i=>{t.appendVertex(i)}),t.hasArrowHead=e.isArrowheadEnabled,t.hasHookLine=e.isHooklineExists,t.isHookLineSameDirection=e.isHooklineSameDirection,t.isSplined=e.isSpline,t.dimensionStyle=e.styleName??"",t.annoType=e.leaderCreationFlag,e.textHeight!=null&&(t.textHeight=e.textHeight),e.textWidth!=null&&(t.textWidth=e.textWidth),e.byBlockColor!=null&&(t.byBlockColor=e.byBlockColor),e.associatedAnnotation&&(t.associatedAnnotation=e.associatedAnnotation),e.normal&&(t.normal=e.normal),e.horizontalDirection&&(t.horizontalDirection=e.horizontalDirection),e.offsetFromBlock&&(t.offsetFromBlock=e.offsetFromBlock),e.offsetFromAnnotation&&(t.offsetFromAnnotation=e.offsetFromAnnotation),t}convertMLine(e){const t=new r.AcDbMLine;return t.styleName=e.mlineStyle||"STANDARD",t.scale=e.scale,t.flags=e.flags,t.justification=e.justification,t.startPosition=e.startPoint,t.normal=e.extrusionDirection??r.AcGeVector3d.Z_AXIS,t.styleCount=e.numberOfLines??0,t.segments=(e.vertices??[]).map(i=>({position:i.vertex,direction:i.vertexDirection,miterDirection:i.miterDirection,elements:(i.lines??[]).map(n=>({parameterCount:n.numberOfSegmentParams,parameters:n.segmentParams??[],fillCount:n.numberOfAreaFillParams,fillParameters:n.areaFillParams??[]}))})),t}convertMLeader(e){var E,P;const t=new r.AcDbMLeader,i=e;t.version=e.version,t.leaderStyleId=e.leaderStyleId,e.leaderStyleId&&(t.mleaderStyleId=e.leaderStyleId),t.propertyOverrideFlag=e.propertyOverrideFlag,t.leaderLineType=e.leaderLineType??r.AcDbMLeaderLineType.StraightLeader,e.leaderLineColor!=null&&(t.leaderLineColor=this.convertMLeaderEntityColor(e.leaderLineColor)),t.leaderLineTypeId=e.leaderLineTypeId,t.leaderLineWeight=e.leaderLineWeight,t.landingEnabled=e.landingEnabled,t.doglegEnabled=e.doglegEnabled??!1,t.doglegLength=e.doglegLength??0,t.arrowheadId=e.arrowheadId,t.arrowheadSize=e.arrowheadSize,t.textStyleId=e.textStyleId,t.textLeftAttachmentType=e.textLeftAttachmentType,t.textRightAttachmentType=e.textRightAttachmentType,t.textAngleType=e.textAngleType,t.textAlignmentType=e.textAlignmentType,e.textColor!=null&&(t.textColor=this.convertMLeaderEntityColor(e.textColor)),t.textFrameEnabled=e.textFrameEnabled,t.landingGap=e.landingGap,t.textAttachment=e.textAttachment,t.textFlowDirection=e.textFlowDirection,this.isValidHandleId(e.blockContentId)&&(t.blockContentId=e.blockContentId),e.blockContentColor!=null&&(t.blockContentColor=this.convertMLeaderEntityColor(e.blockContentColor)),t.blockContentRotation=e.blockContentRotation,t.blockContentConnectionType=e.blockContentConnectionType,t.annotativeScaleEnabled=e.annotativeScaleEnabled,t.arrowheadOverrides=e.arrowheadOverrides?e.arrowheadOverrides.map(p=>({...p})):[],t.blockAttributes=e.blockAttributes?e.blockAttributes.map(p=>({...p})):[],t.textDirectionNegative=e.textDirectionNegative,t.textAlignInIPE=e.textAlignInIPE,t.bottomTextAttachmentDirection=e.bottomTextAttachmentDirection,t.topTextAttachmentDirection=e.topTextAttachmentDirection,t.contentScale=e.contentScale,t.textLineSpacingStyle=e.textLineSpacingStyle,e.textBackgroundColor!=null&&(t.textBackgroundColor=this.convertMLeaderEntityColor(e.textBackgroundColor)),t.textBackgroundScaleFactor=e.textBackgroundScaleFactor,t.textBackgroundTransparency=e.textBackgroundTransparency,t.textBackgroundColorOn=e.textBackgroundColorOn,t.textFillOn=e.textFillOn,t.textColumnType=e.textColumnType,t.textUseAutoHeight=e.textUseAutoHeight,t.textColumnWidth=e.textColumnWidth,t.textColumnGutterWidth=e.textColumnGutterWidth,t.textColumnFlowReversed=e.textColumnFlowReversed,t.textColumnHeight=e.textColumnHeight,t.textUseWordBreak=e.textUseWordBreak,t.hasMText=e.hasMText,t.hasBlock=e.hasBlock,t.planeNormalReversed=e.planeNormalReversed,e.blockContentScale&&(t.blockContentScale=new r.AcGeVector3d(e.blockContentScale)),e.contentBasePosition&&(t.contentBasePosition=new r.AcGePoint3d().copy(e.contentBasePosition)),e.textAnchor&&(t.textAnchor=new r.AcGePoint3d().copy(e.textAnchor)),e.planeOrigin&&(t.planeOrigin=new r.AcGePoint3d().copy(e.planeOrigin)),e.planeXAxisDirection&&(t.planeXAxisDirection=new r.AcGeVector3d(e.planeXAxisDirection)),e.planeYAxisDirection&&(t.planeYAxisDirection=new r.AcGeVector3d(e.planeYAxisDirection));const n=i.textContent,o=n&&typeof n=="object"?n:void 0,s=typeof n=="string"&&n.length>0||this.readString(o??{},["text","contents"])!=null||this.readString(i,["text","contents","mtext"])!=null,c=e.contentType??(s?r.AcDbMLeaderContentType.MTextContent:e.blockContent?r.AcDbMLeaderContentType.BlockContent:r.AcDbMLeaderContentType.NoneContent);t.contentType=c;const a=this.readPoint(i,["normal","extrusionDirection"]);a&&(t.normal=a);const f=this.readString(o??{},["styleName","textStyleName","textStyle"])??this.readString(i,["textStyleName","textStyle","styleName"]);f&&(t.textStyleName=f);const l=this.readPositiveNumber(o??{},["textHeight","height"])??this.readPositiveNumber(i,["textHeight","mtextHeight","textContentHeight"])??this.readPositiveNumber(i,["arrowheadSize","contentScale"]);l!=null&&(t.textHeight=l);const u=this.readPositiveNumber(o??{},["textWidth","width"])??this.readPositiveNumber(i,["textWidth","mtextWidth","textContentWidth"]);u!=null&&(t.textWidth=u),t.textLineSpacingFactor=this.readNumber(o??{},["lineSpacingFactor","textLineSpacingFactor"])??this.readNumber(i,["textLineSpacingFactor"])??t.textLineSpacingFactor;const D=this.readNumber(o??{},["lineSpacingStyle","textLineSpacingStyle"])??this.readNumber(i,["textLineSpacingStyle"]);D!=null&&(t.textLineSpacingStyle=D);const h=this.readNumber(o??{},["textRotation","rotation"])??this.readNumber(i,["textRotation","mtextRotation","textContentRotation"]);h!=null&&(t.textRotation=h);const A=this.readPoint(i,["textDirection","mtextDirection","textDirectionVector"]);A&&(t.textDirection=A);const d=this.readNumber(i,["textAttachmentPoint","attachmentPoint"]);d!=null&&d!==0&&(t.textAttachmentPoint=d);const b=e.textAttachmentDirection;b!=null&&(t.textAttachmentDirection=b);const L=this.readNumber(i,["textDrawingDirection","drawingDirection"]);L!=null&&(t.textDrawingDirection=L);const I=typeof n=="string"?n:this.readString(o??{},["text","contents"])??this.readString(i,["text","contents","mtext"]),m=this.readPoint(o??{},["anchorPoint","textAnchor","textLocation","textPosition","textAnchorPoint"])??this.readPoint(i,["textAnchor","textLocation","textPosition","textAnchorPoint","contentBasePosition"]);if(I!=null&&m&&(t.mtextContent={text:I,anchorPoint:m}),e.blockContent){const p=e.blockContent,w=e.blockContent.blockContentId;if(this.isValidHandleId(w)){const N=this.readMLeaderEntityColor(p,["color"]);t.blockContent={blockContentId:w,normal:this.readPoint(p,["normal"]),position:e.blockContent.position,scale:this.readPoint(p,["scale"]),rotation:this.readNumber(p,["rotation"]),color:N,transformationMatrix:Array.isArray(e.blockContent.transformationMatrix)?e.blockContent.transformationMatrix:[]}}}else this.isValidHandleId(e.blockContentId)&&(t.blockContent={blockContentId:e.blockContentId,scale:e.blockContentScale,rotation:e.blockContentRotation,color:t.blockContentColor,transformationMatrix:[]});return(E=this.readMLeaderLeaders(i))==null||E.forEach(p=>{t.addLeader({lastLeaderLinePoint:p.lastLeaderLinePoint,lastLeaderLinePointSet:p.lastLeaderLinePointSet,doglegVector:p.doglegVector,doglegVectorSet:p.doglegVectorSet,doglegLength:p.doglegLength??e.doglegLength,breaks:p.breaks,leaderBranchIndex:p.leaderBranchIndex,leaderLines:p.leaderLines})}),t.numberOfLeaders===0&&((P=this.readLeaderLineArray(i))==null||P.forEach(p=>{t.addLeader({doglegLength:e.doglegLength}),t.addLeaderLine(t.numberOfLeaders-1,p)})),t.numberOfLeaders===0&&e.contentBasePosition&&t.addLeader({lastLeaderLinePoint:e.contentBasePosition,lastLeaderLinePointSet:!0,doglegLength:e.doglegLength}),t}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"){const t=e,i=new r.AcDbAlignedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return t.insertionPoint&&(i.dimBlockPosition={x:t.insertionPoint.x,y:t.insertionPoint.y,z:0}),i.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,i),i}else if(e.subclassMarker=="AcDbRotatedDimension"){const t=e,i=new r.AcDbRotatedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return t.insertionPoint&&(i.dimBlockPosition={x:t.insertionPoint.x,y:t.insertionPoint.y,z:0}),i.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,i),i}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const t=e,i=new r.AcDb3PointAngularDimension(t.centerPoint,t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return this.processDimensionCommonAttrs(e,i),i}else if(e.subclassMarker=="AcDb2LineAngularDimension"){const t=e,i=t.definitionPoint??t.arcPoint??t.subDefinitionPoint2,n=t.centerPoint??t.subDefinitionPoint2??t.subDefinitionPoint1,o=n??i,s=t.subDefinitionPoint1??n??i,c=t.subDefinitionPoint2??n??i;if(!i||!t.name)return null;const a=new r.AcDb3PointAngularDimension(o,s,c,i);return this.processDimensionCommonAttrs(e,a),a}else if(e.subclassMarker=="AcDbOrdinateDimension"){const t=e,i=new r.AcDbOrdinateDimension(t.subDefinitionPoint1,t.subDefinitionPoint2);return t.definitionPoint&&(i.origin=new r.AcGePoint3d(t.definitionPoint.x,t.definitionPoint.y,t.definitionPoint.z)),this.processDimensionCommonAttrs(e,i),i}else if(e.subclassMarker=="AcDbRadialDimension"){const t=e,i=new r.AcDbRadialDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,i),i}else if(e.subclassMarker=="AcDbDiametricDimension"){const t=e,i=new r.AcDbDiametricDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,i),i}return null}processImage(e,t){t.position.copy(e.position),t.brightness=e.brightness,t.contrast=e.contrast,t.fade=e.fade,t.imageSize.copy(e.imageSize),t.imageDefId=e.imageDefHandle,t.isClipped=e.clipping>0,t.isShownClipped=(e.flags&4)!==0,t.isImageShown=(e.flags&3)!==0,t.isImageTransparent=(e.flags&8)!==0,e.clippingBoundaryPath.forEach(i=>{t.clipBoundary.push(new r.AcGePoint2d(i))}),t.clipBoundaryType=e.clippingBoundaryType,t.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,t.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,t.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const t=new r.AcDbRasterImage;return this.processImage(e,t),t}convertWipeout(e){const t=new r.AcDbWipeout;return this.processImage(e,t),t}convertOleFrame(e){const t=new r.AcDbOleFrame;if(t.oleVersion=e.flag??0,e.binaryData){const i=r.acdbHexStringsToBytes([e.binaryData]);t.loadOleObjectFromDxf(e.dataSize,i)}return t}convertOle2Frame(e){const t=new r.AcDbOle2Frame;if(t.oleVersion=e.oleVersion??0,t.userType=e.oleClient??"",e.leftUpPoint&&t.upperLeftCorner.copy(e.leftUpPoint),e.rightDownPoint&&t.lowerRightCorner.copy(e.rightDownPoint),t.setLockAspect(e.lockAspect??0),t.oleObjectType=e.oleObjectType??r.AcDbOleObjectType.Embedded,t.tileMode=e.tileModeDescriptor??r.AcDbOleTileMode.ModelSpace,e.binaryData){const i=r.acdbHexStringsToBytes([e.binaryData]);t.loadOleObjectFromDxf(e.dataSize,i)}return t}convertViewport(e){const t=new r.AcDbViewport;t.number=e.viewportId,t.centerPoint.copy(e.viewportCenter),t.height=e.height,t.width=e.width,t.viewCenter.copy(e.displayCenter),t.viewHeight=e.viewHeight,e.targetPoint&&t.viewTarget.copy(e.targetPoint),e.viewTwistAngle!=null&&(t.viewTwistAngle=e.viewTwistAngle);const i=1e-6,n=Math.abs(t.centerPoint.x)<i&&Math.abs(t.centerPoint.y)<i,o=t.viewTarget,s=Math.abs(o.x)<i&&Math.abs(o.y)<i,c=Number.isFinite(t.height)&&Number.isFinite(t.viewHeight)&&Math.abs(t.viewHeight-t.height)<i;return n&&s&&c&&t.centerPoint.copy(t.viewCenter),t}convertRay(e){const t=new r.AcDbRay;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertXline(e){const t=new r.AcDbXline;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertAttributeCommon(e,t){const i=e.text;t.textString=i.text,t.styleName=i.styleName,t.height=i.textHeight,t.position.copy(i.startPoint);const n=e.alignmentPoint??i.endPoint,o=!n||n.x===0&&n.y===0&&(n.z??0)===0;n&&!o?(t.alignmentPoint.copy(n),t.hasAlignmentPoint=!0):(t.alignmentPoint.copy(i.startPoint),t.hasAlignmentPoint=!1),t.rotation=i.rotation,t.oblique=i.obliqueAngle??0,t.thickness=i.thickness,t.horizontalMode=i.halign,t.verticalMode=i.valign,t.widthFactor=i.xScale??1,y(i.extrusionDirection)&&(t.normal=i.extrusionDirection);const s=x(i);s!=null&&(t.position.z=s,t.alignmentPoint.z=s),t.tag=e.tag,t.fieldLength=e.fieldLength,t.isInvisible=(e.flags&r.AcDbAttributeFlags.Invisible)!==0,t.isConst=(e.flags&r.AcDbAttributeFlags.Const)!==0,t.isVerifiable=(e.flags&r.AcDbAttributeFlags.Verifiable)!==0,t.isPreset=(e.flags&r.AcDbAttributeFlags.Preset)!==0,t.lockPositionInBlock=e.lockPositionFlag,t.isReallyLocked=e.isReallyLocked,t.isMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.MultiLine)!==0,t.isConstMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.ConstMultiLine)!==0}convertAttribute(e){const t=new r.AcDbAttribute;return this.convertAttributeCommon(e,t),t}convertAttributeDefinition(e){const t=new r.AcDbAttributeDefinition;return this.convertAttributeCommon(e,t),t.prompt=e.prompt,t}convertBlockReference(e){const t=new r.AcDbBlockReference(e.name);return e.insertionPoint&&t.position.copy(e.insertionPoint),t.scaleFactors.x=e.xScale,t.scaleFactors.y=e.yScale,t.scaleFactors.z=e.zScale,t.rotation=e.rotation,t.normal.copy(e.extrusionDirection),e.columnCount!=null&&(t.columnCount=e.columnCount),e.rowCount!=null&&(t.rowCount=e.rowCount),e.columnSpacing!=null&&(t.columnSpacing=e.columnSpacing),e.rowSpacing!=null&&(t.rowSpacing=e.rowSpacing),e.handle!=null&&(t.objectId=e.handle),e.attribs&&e.attribs.forEach(i=>{const n=this.convert(i);n instanceof r.AcDbAttribute&&t.appendAttributes(n)}),t}processDimensionCommonAttrs(e,t){t.dimBlockId=e.name,t.textPosition.copy(e.textPoint),t.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(t.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(t.textLineSpacingStyle=e.textLineSpacingStyle),t.dimensionStyleName=e.styleName,t.dimensionText=e.text||"",t.measurement=e.measurement,e.dimensionType!=null&&(t.dimensionType=e.dimensionType)}processCommonAttrs(e,t){t.layer=e.layer||"0",t.objectId=e.handle,e.ownerBlockRecordSoftId!=null&&(t.ownerId=e.ownerBlockRecordSoftId);const i=r.acdbNormalizeExtensionDictionaryId(e.extensionDictionary??e.ownerDictionaryHardId??e.ownerDictionarySoftId);if(i&&(t.extensionDictionary=i),this.applyExtendedData(e,t),e.lineType!=null&&(t.lineType=e.lineType),e.lineweight!=null&&(t.lineWeight=e.lineweight),e.lineTypeScale!=null&&(t.linetypeScale=e.lineTypeScale),e.color!=null||e.colorIndex!=null||e.colorName){const n=new r.AcCmColor;e.color!=null&&n.setRGBValue(e.color),e.colorIndex!=null&&(e.color==null||e.colorIndex===7)&&(n.colorIndex=e.colorIndex),e.colorName&&(n.colorName=e.colorName),t.color=n}if(e.isVisible!=null&&(t.visibility=e.isVisible),e.transparency!=null){const n=new r.AcCmTransparency;n.method=e.transparencyType,(n.isByBlock||n.isByBlock)&&(n.alpha=e.transparency),t.transparency=n}}applyExtendedData(e,t){const i=e.xdata;if(!i)return;const n=Array.isArray(i)?i:[i];for(const o of n){if(!(o!=null&&o.appName))continue;const s=[{code:r.AcDbDxfCode.ExtendedDataRegAppName,value:o.appName}];for(const c of o.value??[])if(c!=null&&typeof c=="object"&&"code"in c&&"value"in c){const a=Number(c.code),f=c.value;if(a===r.AcDbDxfCode.ExtendedDataHandle||a>=1e3&&a<=1071){const l=this.normalizeXDataValue(a,f);l!==void 0&&s.push({code:a,value:l})}}t.setImportedXData(s)}}normalizeXDataValue(e,t){if(e>=1010&&e<=1013){if(this.isPointLike(t))return{x:t.x,y:t.y,z:typeof t.z=="number"?t.z:0};if(Array.isArray(t)&&typeof t[0]=="number"&&typeof t[1]=="number")return{x:t[0],y:t[1],z:typeof t[2]=="number"?t[2]:0};if(typeof t=="number"&&Number.isFinite(t))return t}if(e===r.AcDbDxfCode.ExtendedDataBinaryChunk)return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):typeof t=="string"?t:Array.isArray(t)&&t.every(i=>typeof i=="number"&&Number.isFinite(i)&&i>=0&&i<=255)?Uint8Array.from(t):void 0;if(typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t instanceof Uint8Array)return t;if(this.isPointLike(t))return{x:t.x,y:t.y,z:typeof t.z=="number"?t.z:0}}convertMLeaderEntityColor(e){return r.acdbDecodeMLeaderStyleRawColor(e)}readMLeaderEntityColor(e,t){for(const i of t){const n=e[i];if(typeof n=="number"&&Number.isFinite(n))return r.acdbDecodeMLeaderStyleRawColor(n)}}isValidHandleId(e){return e!=null&&e!==""&&e!=="0"}readNumber(e,t){for(const i of t){const n=e[i];if(typeof n=="number"&&Number.isFinite(n))return n}}readPositiveNumber(e,t){const i=this.readNumber(e,t);return i!=null&&i>0?i:void 0}readString(e,t){for(const i of t){const n=e[i];if(typeof n=="string")return n}}readBoolean(e,t){for(const i of t){const n=e[i];if(typeof n=="boolean")return n;if(typeof n=="number")return n!==0}}readPoint(e,t){for(const i of t){const n=e[i];if(this.isPointLike(n))return n;if(Array.isArray(n)&&typeof n[0]=="number"&&typeof n[1]=="number")return{x:n[0],y:n[1],z:n[2]??0}}}readLeaderLineArray(e){const t=e.leaderLines;if(Array.isArray(t))return t.map(n=>{if(!n||typeof n!="object")return;const o=n.vertices;return Array.isArray(o)?o.filter(s=>this.isPointLike(s)):void 0}).filter(n=>!!n&&n.length>0);const i=e.vertices;if(Array.isArray(i)){const n=i.filter(o=>this.isPointLike(o));return n.length>0?[n]:void 0}}readMLeaderLeaders(e){const t=e.leaderSections;if(!Array.isArray(t))return;const i=[];return t.forEach(n=>{if(!n||typeof n!="object")return;const o=n,s=o.leaderLines,c=Array.isArray(s)?s.reduce((A,d)=>{const b=this.readMLeaderLine(d);return b&&A.push(b),A},[]):void 0,a={},f=this.readPoint(o,["lastLeaderLinePoint"]),l=this.readPoint(o,["doglegVector"]),u=this.readNumber(o,["doglegLength"]),D=this.readMLeaderBreaks(o.breaks),h=this.readNumber(o,["leaderBranchIndex"]);f&&(a.lastLeaderLinePoint=f),o.lastLeaderLinePointSet!=null&&(a.lastLeaderLinePointSet=this.readBoolean(o,["lastLeaderLinePointSet"])),l&&(a.doglegVector=l),o.doglegVectorSet!=null&&(a.doglegVectorSet=this.readBoolean(o,["doglegVectorSet"])),u!=null&&(a.doglegLength=u),D&&(a.breaks=D),h!=null&&(a.leaderBranchIndex=h),c&&(a.leaderLines=c),i.push(a)}),i}readMLeaderLine(e){if(!e||typeof e!="object")return;const t=e,i=t.vertices,n=Array.isArray(i)?i.filter(a=>this.isPointLike(a)):[],o=this.readMLeaderBreaks(t.breaks),s=Array.isArray(t.breakPointIndexes)?t.breakPointIndexes.filter(a=>typeof a=="number"):void 0,c=this.readNumber(t,["leaderLineIndex"]);return n.length>0||o&&o.length>0?{vertices:n,breakPointIndexes:s,leaderLineIndex:c,breaks:o}:void 0}readMLeaderBreaks(e){if(!Array.isArray(e))return;const t=e.map(i=>{if(!i||typeof i!="object")return;const n=i,o=this.readPoint(n,["start"]),s=this.readPoint(n,["end"]),c=this.readNumber(n,["index"]);if(!o||!s)return;const a={start:o,end:s};return c!=null&&(a.index=c),a}).filter(i=>!!i);return t.length>0?t:void 0}isPointLike(e){return!!e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}}class g{convertMLeaderStyle(e){const t=new r.AcDbMLeaderStyle;return t.unknown1=e.unknown1,e.contentType!=null&&(t.contentType=e.contentType),e.drawMLeaderOrderType!=null&&(t.drawMLeaderOrderType=e.drawMLeaderOrderType),e.drawLeaderOrderType!=null&&(t.drawLeaderOrderType=e.drawLeaderOrderType),e.maxLeaderSegmentPoints!=null&&(t.maxLeaderSegmentPoints=e.maxLeaderSegmentPoints),e.firstSegmentAngleConstraint!=null&&(t.firstSegmentAngleConstraint=e.firstSegmentAngleConstraint),e.secondSegmentAngleConstraint!=null&&(t.secondSegmentAngleConstraint=e.secondSegmentAngleConstraint),e.leaderLineType!=null&&(t.leaderLineType=e.leaderLineType),e.leaderLineColor!=null&&(t.leaderLineColor=r.acdbDecodeMLeaderStyleRawColor(e.leaderLineColor)),t.leaderLineTypeId=e.leaderLineTypeId,e.leaderLineWeight!=null&&(t.leaderLineWeight=e.leaderLineWeight),e.landingEnabled!=null&&(t.landingEnabled=e.landingEnabled),e.landingGap!=null&&(t.landingGap=e.landingGap),e.doglegEnabled!=null&&(t.doglegEnabled=e.doglegEnabled),e.doglegLength!=null&&(t.doglegLength=e.doglegLength),e.description!=null&&(t.description=e.description),t.arrowheadId=e.arrowheadId,e.arrowheadSize!=null&&(t.arrowheadSize=e.arrowheadSize),e.defaultMTextContents!=null&&(t.defaultMTextContents=e.defaultMTextContents),t.textStyleId=e.textStyleId,e.textLeftAttachmentType!=null&&(t.textLeftAttachmentType=e.textLeftAttachmentType),e.textAngleType!=null&&(t.textAngleType=e.textAngleType),e.textAlignmentType!=null&&(t.textAlignmentType=e.textAlignmentType),e.textRightAttachmentType!=null&&(t.textRightAttachmentType=e.textRightAttachmentType),e.textColor!=null&&(t.textColor=r.acdbDecodeMLeaderStyleRawColor(e.textColor)),e.textHeight!=null&&(t.textHeight=e.textHeight),e.textFrameEnabled!=null&&(t.textFrameEnabled=e.textFrameEnabled),e.textAlignAlwaysLeft!=null&&(t.textAlignAlwaysLeft=e.textAlignAlwaysLeft),e.alignSpace!=null&&(t.alignSpace=e.alignSpace),t.blockContentId=e.blockContentId,e.blockContentColor!=null&&(t.blockContentColor=r.acdbDecodeMLeaderStyleRawColor(e.blockContentColor)),e.blockContentScale&&(t.blockContentScale={x:e.blockContentScale.x,y:e.blockContentScale.y,z:e.blockContentScale.z??1}),e.blockContentScaleEnabled!=null&&(t.blockContentScaleEnabled=e.blockContentScaleEnabled),e.blockContentRotation!=null&&(t.blockContentRotation=e.blockContentRotation),e.blockContentRotationEnabled!=null&&(t.blockContentRotationEnabled=e.blockContentRotationEnabled),e.blockContentConnectionType!=null&&(t.blockContentConnectionType=e.blockContentConnectionType),e.scale!=null&&(t.scale=e.scale),e.overwritePropertyValue!=null&&(t.overwritePropertyValue=e.overwritePropertyValue),e.annotative!=null&&(t.annotative=e.annotative),e.breakGapSize!=null&&(t.breakGapSize=e.breakGapSize),e.textAttachmentDirection!=null&&(t.textAttachmentDirection=e.textAttachmentDirection),e.bottomTextAttachmentDirection!=null&&(t.bottomTextAttachmentDirection=e.bottomTextAttachmentDirection),e.topTextAttachmentDirection!=null&&(t.topTextAttachmentDirection=e.topTextAttachmentDirection),t.unknown2=e.unknown2,this.processCommonAttrs(e,t),t}convertLayerFilter(e){var i;const t=new r.AcDbLayerFilter;return(i=e.layerNames)!=null&&i.length&&(t.layerNames=e.layerNames),this.processCommonAttrs(e,t),t}convertLayerIndex(e){var i,n,o;const t=new r.AcDbLayerIndex;return e.timeStamp!=null&&(t.lastUpdatedAt=e.timeStamp,t.lastUpdatedAtU=e.timeStamp),(i=e.layerNames)!=null&&i.length&&(t.layerNames=e.layerNames),(n=e.idBufferIds)!=null&&n.length&&(t.idBufferIds=e.idBufferIds),(o=e.idBufferEntryCounts)!=null&&o.length&&(t.idBufferEntryCounts=e.idBufferEntryCounts),t.isUptoDate=!0,this.processCommonAttrs(e,t),t}convertScale(e){const t=new r.AcDbScale;return e.flag!=null&&(t.classVersion=e.flag),t.scaleName=e.name??"",t.paperUnits=e.paperUnits??1,t.drawingUnits=e.drawingUnits??1,t.isUnitScale=!!e.isUnitScale,this.processCommonAttrs(e,t),t}convertDictionaryVar(e){const t=new r.AcDbDictionaryVar;return e.schema!=null&&(t.schema=e.schema),t.value=e.value??e.strvalue??"",this.processCommonAttrs(e,t),t}convertMTextObjectContextData(e){const t=new r.AcDbMTextObjectContextData;return e.classVersion!=null&&(t.classVersion=e.classVersion),t.isDefault=!!e.isDefault,t.scaleId=e.scaleId??e.scaleHandle??"",e.attachment!=null&&(t.attachmentPoint=e.attachment),e.xAxisDir&&(t.direction=new r.AcGeVector3d(e.xAxisDir.x,e.xAxisDir.y,e.xAxisDir.z??0)),e.insertionPoint&&(t.insertionPoint=new r.AcGePoint3d(e.insertionPoint.x,e.insertionPoint.y,e.insertionPoint.z??0)),e.definedWidth!=null&&(t.definedWidth=e.definedWidth),e.definedHeight!=null&&(t.definedHeight=e.definedHeight),e.extentsWidth!=null&&(t.extentsWidth=e.extentsWidth),e.extentsHeight!=null&&(t.extentsHeight=e.extentsHeight),e.columnType!=null&&(t.columnType=e.columnType),this.processCommonAttrs(e,t),t}convertDimensionObjectContextData(e){const t=new r.AcDbDimensionObjectContextData;e.classVersion!=null&&(t.classVersion=e.classVersion),t.isDefault=!!e.isDefault,t.scaleId=e.scaleId??e.scaleHandle??"",t.blockName=e.blockName??e.name??"";const i=e.definitionPoint??e.defPt;i&&(t.definitionPoint=new r.AcGePoint3d(i.x,i.y,i.z??0));const n=e.dimLinePoint??e._11pt;return n&&(t.dimLinePoint=new r.AcGePoint3d(n.x,n.y,n.z??0)),this.processCommonAttrs(e,t),t}convertTextObjectContextData(e){const t=new r.AcDbTextObjectContextData;return this.applyAnnotScaleContextBase(e,t),e.horizontalMode!=null&&(t.horizontalMode=e.horizontalMode),e.rotation!=null&&(t.rotation=e.rotation),e.alignmentPoint&&(t.alignmentPoint=new r.AcGePoint3d(e.alignmentPoint.x,e.alignmentPoint.y,e.alignmentPoint.z??0)),e.position&&(t.position=new r.AcGePoint3d(e.position.x,e.position.y,e.position.z??0)),this.processCommonAttrs(e,t),t}convertHatchScaleContextData(e){const t=new r.AcDbHatchScaleContextData;this.applyAnnotScaleContextBase(e,t);const i=e.patternScale??e.scale;return i!=null&&i>0&&(t.patternScale=i),this.processCommonAttrs(e,t),t}convertBlkRefObjectContextData(e){const t=new r.AcDbBlkRefObjectContextData;this.applyAnnotScaleContextBase(e,t);const i=e.position??e.insertionPoint;i&&(t.position=new r.AcGePoint3d(i.x,i.y,i.z??0)),e.rotation!=null&&(t.rotation=e.rotation);const n=e.scaleX??e.xScale,o=e.scaleY??e.yScale,s=e.scaleZ??e.zScale;return n!=null&&(t.scaleX=n),o!=null&&(t.scaleY=o),s!=null&&(t.scaleZ=s),this.processCommonAttrs(e,t),t}convertLeaderObjectContextData(e){const t=new r.AcDbLeaderObjectContextData;return this.applyAnnotScaleContextBase(e,t),this.processCommonAttrs(e,t),t}convertMLeaderObjectContextData(e){const t=new r.AcDbMLeaderObjectContextData;this.applyAnnotScaleContextBase(e,t),e.contentScale!=null&&e.contentScale>0&&(t.contentScale=e.contentScale),e.textHeight!=null&&e.textHeight>0&&(t.textHeight=e.textHeight);const i=e.arrowheadSize??e.arrowSize;i!=null&&i>0&&(t.arrowheadSize=i);const n=e.textAnchor??e.landingPoint;return n&&(t.textAnchor=new r.AcGePoint3d(n.x,n.y,n.z??0)),this.processCommonAttrs(e,t),t}convertMTextAttributeObjectContextData(e){const t=new r.AcDbMTextAttributeObjectContextData;return e.classVersion!=null&&(t.classVersion=e.classVersion),t.isDefault=!!e.isDefault,t.scaleId=e.scaleId??e.scaleHandle??"",e.attachment!=null&&(t.attachmentPoint=e.attachment),e.xAxisDir&&(t.direction=new r.AcGeVector3d(e.xAxisDir.x,e.xAxisDir.y,e.xAxisDir.z??0)),e.insertionPoint&&(t.insertionPoint=new r.AcGePoint3d(e.insertionPoint.x,e.insertionPoint.y,e.insertionPoint.z??0)),e.definedWidth!=null&&(t.definedWidth=e.definedWidth),e.definedHeight!=null&&(t.definedHeight=e.definedHeight),e.extentsWidth!=null&&(t.extentsWidth=e.extentsWidth),e.extentsHeight!=null&&(t.extentsHeight=e.extentsHeight),e.columnType!=null&&(t.columnType=e.columnType),this.processCommonAttrs(e,t),t}convertXRecord(e){const t=new r.AcDbXrecord;return this.processCommonAttrs(e,t),e.extensionDictionary&&(t.extensionDictionary=e.extensionDictionary),t.data=new r.AcDbResultBuffer((e.data??[]).map(i=>({code:Number(i.code),value:i.value}))),t}applyAnnotScaleContextBase(e,t){e.classVersion!=null&&(t.classVersion=e.classVersion),t.isDefault=!!e.isDefault,t.scaleId=e.scaleId??e.scaleHandle??""}processCommonAttrs(e,t){t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}}const O="*MODEL_SPACE";class v extends r.AcDbDatabaseConverter{constructor(e={}){super(e),this.config.useWorker=!0,this.config.parserWorkerUrl||(this.config.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,t){const i=this.config,n=this.getParserWorkerTimeout(e,t);if(i.useWorker&&i.parserWorkerUrl){const o=r.acdbCreateWorkerApi({workerUrl:i.parserWorkerUrl,timeout:n,maxConcurrentWorkers:1}),s=await o.execute(e);return o.destroy(),r.AcDbOpenDatabaseError.throwOnWorkerParseFailure(s),s.data}else throw new Error("dwg converter can run in web worker only!")}processLineTypes(e,t){e.tables.LTYPE.entries.forEach(n=>{const o={name:n.name,description:n.description,standardFlag:n.standardFlag,totalPatternLength:n.totalPatternLength,pattern:n.pattern},s=new r.AcDbLinetypeTableRecord(o);this.processCommonTableEntryAttrs(n,s),t.tables.linetypeTable.add(s)})}processTextStyles(e,t){e.tables.STYLE.entries.forEach(n=>{const o={name:n.name,standardFlag:n.standardFlag,fixedTextHeight:n.fixedTextHeight,widthFactor:n.widthFactor,obliqueAngle:n.obliqueAngle,textGenerationFlag:n.textGenerationFlag,lastHeight:n.lastHeight,font:n.font,bigFont:n.bigFont,extendedFont:n.extendedFont},s=new r.AcDbTextStyleTableRecord(o);this.processCommonTableEntryAttrs(n,s),t.tables.textStyleTable.add(s)}),t.ensureTextStyleDefaults()}processDimStyles(e,t){e.tables.DIMSTYLE.entries.forEach(o=>{const s={name:o.name,ownerId:o.ownerHandle,dimpost:o.DIMPOST||"",dimapost:o.DIMAPOST||"",dimscale:o.DIMSCALE,dimasz:o.DIMASZ,dimexo:o.DIMEXO,dimdli:o.DIMDLI,dimexe:o.DIMEXE,dimrnd:o.DIMRND,dimdle:o.DIMDLE,dimtp:o.DIMTP,dimtm:o.DIMTM,dimtxt:o.DIMTXT,dimcen:o.DIMCEN,dimtsz:o.DIMTSZ,dimaltf:o.DIMALTF,dimlfac:o.DIMLFAC,dimtvp:o.DIMTVP,dimtfac:o.DIMTFAC,dimgap:o.DIMGAP,dimtfill:o.DIMTFILL===1||o.DIMTFILL===2?o.DIMTFILL:0,dimtfillclr:r.acdbNormalizeDimStyleColorNumber(o.DIMTFILLCLR),dimtxtdirection:o.DIMTXTDIRECTION===1?1:0,dimaltrnd:o.DIMALTRND,dimtol:o.DIMTOL==null||o.DIMTOL==0?0:1,dimlim:o.DIMLIM==null||o.DIMLIM==0?0:1,dimtih:o.DIMTIH==null||o.DIMTIH==0?0:1,dimtoh:o.DIMTOH==null||o.DIMTOH==0?0:1,dimse1:o.DIMSE1==null||o.DIMSE1==0?0:1,dimse2:o.DIMSE2==null||o.DIMSE2==0?0:1,dimtad:o.DIMTAD,dimzin:o.DIMZIN,dimazin:o.DIMAZIN,dimalt:o.DIMALT,dimaltd:o.DIMALTD,dimtofl:o.DIMTOFL,dimsah:o.DIMSAH,dimtix:o.DIMTIX,dimsoxd:o.DIMSOXD,dimclrd:r.acdbNormalizeDimStyleColorNumber(o.DIMCLRD),dimclre:r.acdbNormalizeDimStyleColorNumber(o.DIMCLRE),dimclrt:r.acdbNormalizeDimStyleColorNumber(o.DIMCLRT),dimadec:o.DIMADEC||0,dimunit:o.DIMUNIT||2,dimdec:o.DIMDEC,dimtdec:o.DIMTDEC,dimaltu:o.DIMALTU,dimalttd:o.DIMALTTD,dimaunit:o.DIMAUNIT,dimfrac:o.DIMFRAC,dimlunit:o.DIMLUNIT,dimdsep:o.DIMDSEP||".",dimtmove:o.DIMTMOVE||0,dimjust:o.DIMJUST,dimsd1:o.DIMSD1,dimsd2:o.DIMSD2,dimtolj:o.DIMTOLJ,dimtzin:o.DIMTZIN,dimaltz:o.DIMALTZ,dimalttz:o.DIMALTTZ,dimfit:o.DIMFIT||0,dimupt:o.DIMUPT,dimatfit:o.DIMATFIT,dimtxsty:this.resolveDimTextStyleName(e,o.DIMTXSTY),dimldrblk:this.resolveDimBlockName(e,o.DIMLDRBLK),dimblk:this.resolveDimBlockName(e,o.DIMBLK),dimblk1:this.resolveDimBlockName(e,o.DIMBLK1),dimblk2:this.resolveDimBlockName(e,o.DIMBLK2),dimlwd:o.DIMLWD,dimlwe:o.DIMLWE},c=new r.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(o,c),t.tables.dimStyleTable.add(c)});const n=e.dimStyleAnnotationScales;if(n)for(const[o,s]of Object.entries(n))t.setDimStyleAnnotationScale(o,s)}resolveDimTextStyleName(e,t){if(typeof t=="string"){const n=t.trim();if(n&&!/^[0-9]+$/.test(n)&&!/^[0-9A-F]+$/i.test(n))return n;if(n&&/[A-Z]/i.test(n)){const o=e.tables.STYLE.entries.find(s=>String(s.handle).toUpperCase()===n.toUpperCase());if(o!=null&&o.name)return o.name}}const i=typeof t=="number"?t:Number(t);if(Number.isFinite(i)&&i>0){const n=Math.trunc(i).toString(16).toUpperCase(),o=e.tables.STYLE.entries.find(s=>String(s.handle).toUpperCase()===n);if(o!=null&&o.name)return o.name}return r.DEFAULT_TEXT_STYLE}resolveDimBlockName(e,t){var s;const i=((s=e.tables.BLOCK_RECORD)==null?void 0:s.entries)??[],n=c=>{var a;return(a=i.find(f=>String(f.handle).toUpperCase()===c.toUpperCase()))==null?void 0:a.name};if(typeof t=="string"){const c=t.trim();if(!c||c===".")return"";if(!/^[0-9A-F]+$/i.test(c))return c;const a=i.find(f=>f.name.toUpperCase()===c.toUpperCase());if(a!=null&&a.name)return a.name;if(/[A-Z]/i.test(c))return n(c)??c}const o=typeof t=="number"?t:Number(t);return!Number.isFinite(o)||o<=0?"":n(Math.trunc(o).toString(16).toUpperCase())??""}processLayers(e,t){e.tables.LAYER.entries.forEach(n=>{const o=new r.AcCmColor;this.applyLibreLayerColor(o,n);const s=new r.AcDbLayerTableRecord({name:n.name,standardFlags:n.standardFlag,linetype:n.lineType,lineWeight:n.lineweight,isOff:n.off,color:o,isPlottable:n.plotFlag!=0});this.processCommonTableEntryAttrs(n,s),t.tables.layerTable.add(s)})}applyLibreLayerColor(e,t){const i=t.colorIndex,n=t.color;i!=null&&i>=1&&i<=255?e.colorIndex=i:i===0?e.colorIndex=0:n!=null&&Number.isFinite(n)?e.setRGBValue(n&16777215):e.colorIndex=256,t.colorName&&(e.colorName=t.colorName)}processViewports(e,t){e.tables.VPORT.entries.forEach(n=>{const o=new r.AcDbViewportTableRecord;n.circleSides&&(o.circleSides=n.circleSides),o.standardFlag=n.standardFlag,o.center.copy(n.center??r.VPORT_FALLBACK_CENTER_2D),o.lowerLeftCorner.copy(n.lowerLeftCorner??r.VPORT_FALLBACK_LLC),o.upperRightCorner.copy(n.upperRightCorner??r.VPORT_FALLBACK_URC),n.snapBasePoint&&o.snapBase.copy(n.snapBasePoint),n.snapRotationAngle&&(o.snapAngle=n.snapRotationAngle),n.snapSpacing&&o.snapIncrements.copy(n.snapSpacing),n.majorGridLines&&(o.gridMajor=n.majorGridLines),n.gridSpacing&&o.gridIncrements.copy(n.gridSpacing),n.backgroundObjectId&&(o.backgroundObjectId=n.backgroundObjectId),o.gsView.center.copy(n.center??r.VPORT_FALLBACK_CENTER_2D),o.gsView.viewDirectionFromTarget.copy(n.viewDirectionFromTarget??r.VPORT_FALLBACK_VIEW_DIR),o.gsView.viewTarget.copy(n.viewTarget??r.VPORT_FALLBACK_VIEW_TARGET),n.lensLength&&(o.gsView.lensLength=n.lensLength),n.frontClippingPlane&&(o.gsView.frontClippingPlane=n.frontClippingPlane),n.backClippingPlane&&(o.gsView.backClippingPlane=n.backClippingPlane),n.viewHeight&&(o.gsView.viewHeight=n.viewHeight);const s=n.aspectRatio;s!=null&&Number.isFinite(s)&&s>0&&(o.gsView.aspectRatio=s),n.viewTwistAngle&&(o.gsView.viewTwistAngle=n.viewTwistAngle),n.frozenLayers&&(o.gsView.frozenLayers=n.frozenLayers),n.styleSheet&&(o.gsView.styleSheet=n.styleSheet),n.renderMode&&(o.gsView.renderMode=n.renderMode),n.viewMode&&(o.gsView.viewMode=n.viewMode),n.ucsIconSetting&&(o.gsView.ucsIconSetting=n.ucsIconSetting),n.ucsOrigin&&o.gsView.ucsOrigin.copy(n.ucsOrigin),n.ucsXAxis&&o.gsView.ucsXAxis.copy(n.ucsXAxis),n.ucsYAxis&&o.gsView.ucsYAxis.copy(n.ucsYAxis),n.orthographicType&&(o.gsView.orthographicType=n.orthographicType),n.shadePlotSetting&&(o.gsView.shadePlotSetting=n.shadePlotSetting),n.shadePlotObjectId&&(o.gsView.shadePlotObjectId=n.shadePlotObjectId),n.visualStyleObjectId&&(o.gsView.visualStyleObjectId=n.visualStyleObjectId),n.isDefaultLightingOn&&(o.gsView.isDefaultLightingOn=n.isDefaultLightingOn),n.defaultLightingType&&(o.gsView.defaultLightingType=n.defaultLightingType),n.brightness&&(o.gsView.brightness=n.brightness),n.contrast&&(o.gsView.contrast=n.contrast),n.ambientColor&&(o.gsView.ambientColor=n.ambientColor),this.processCommonTableEntryAttrs(n,o),t.tables.viewportTable.add(o)})}processBlockTables(e,t){e.tables.BLOCK_RECORD.entries.forEach(n=>{let o=t.tables.blockTable.getAt(n.name);o||(o=new r.AcDbBlockTableRecord,o.name=n.name,o.ownerId=n.ownerHandle,o.layoutId=n.layout,o.flags=r.AcDbBlockTableRecord.sanitizeImportedFlags(n.flags??0),o.blockInsertUnits=n.insertionUnits,o.explodability=n.explodability,o.blockScaling=n.scalability,o.objectId=n.handle,t.tables.blockTable.add(o)),n.bmpPreview&&(o.previewIcon=r.acdbHexStringsToBytes([n.bmpPreview])),o.origin.copy(n.basePoint),!o.isModelSapce&&n.entities&&n.entities.length>0&&this.processEntitiesInBlock(n.entities,o)})}processBlocks(e,t){}async processEntitiesInBlock(e,t){const i=new S,n=e.length,o=[];for(let s=0;s<n;s++){const c=e[s],a=i.convert(c);a&&o.push(a)}t.appendEntity(o)}async processEntities(e,t,i,n,o){const s=new S;let c=[];e.tables.BLOCK_RECORD.entries.forEach(u=>{this.isModelSpace(u.name)&&(c=u.entities)});const a=c.length,f=new r.AcDbBatchProcessing(a,100-n.value,i);this.config.convertByEntityType&&(c=this.groupAndFlattenByType(c));const l=t.tables.blockTable.modelSpace;await f.processChunk(async(u,D)=>{const h=[];for(let A=u;A<D;A++){const d=c[A],b=s.convert(d);b&&h.push(b)}if(l.appendEntity(h),o){let A=n.value+D/a*(100-n.value);A>100&&(A=100),await o(A,"ENTITY","IN-PROGRESS")}})}processClasses(e,t){var i;(i=e.classes)!=null&&i.length&&(t.classes=e.classes.map(n=>({name:n.dxfName,cppClassName:n.cppName,appName:n.appName,proxyFlag:n.capabilitiesFlag,instanceCount:n.instanceCount,wasProxy:n.wasAProxyFlag,isEntity:n.isAnEntityFlag})))}processHeader(e,t){const i=e.thumbnailImage;i!=null&&i.length&&(t.thumbnailImage=i);const n=e.header;n.CECOLOR&&(n.CECOLOR.index>=0&&n.CECOLOR.index<=256?t.cecolor.colorIndex=n.CECOLOR.index:t.cecolor.setRGBValue(n.CECOLOR.rgb)),t.angbase=n.ANGBASE??0,t.angdir=n.ANGDIR??0,t.aunits=n.AUNITS??0,n.AUPREC!=null&&(t.auprec=n.AUPREC),n.LUNITS!=null&&(t.lunits=n.LUNITS),n.LUPREC!=null&&(t.luprec=n.LUPREC),n.UNITMODE!=null&&(t.unitmode=n.UNITMODE),n.MEASUREMENT!=null&&(t.measurement=n.MEASUREMENT),t.celtype=n.CELTYPE??r.ByLayer,t.celtscale=n.CELTSCALE??1,t.ltscale=n.LTSCALE??1,t.tilemode=n.TILEMODE??1,n.EXTMAX&&(t.extmax=n.EXTMAX),n.EXTMIN&&(t.extmin=n.EXTMIN),t.insunits=n.INSUNITS??1,t.pdmode=n.PDMODE??0,t.pdsize=n.PDSIZE??0,t.textstyle=n.TEXTSTYLE??r.DEFAULT_TEXT_STYLE,t.dimstyle=this.normalizeHeaderStringValue(n.DIMSTYLE)??r.DEFAULT_TEXT_STYLE;const o=this.normalizeHeaderStringValue(n.CMLEADERSTYLE)??r.DEFAULT_MLEADER_STYLE;t.cmleaderstyle=o}processCommonTableEntryAttrs(e,t){t.name=e.name,t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}processObjects(e,t){this.processScales(e,t),this.processDictionaryVars(e,t),this.processMTextObjectContextData(e,t),this.processTextObjectContextData(e,t),this.processDimensionObjectContextData(e,t),this.processHatchScaleContextData(e,t),this.processBlkRefObjectContextData(e,t),this.processLeaderObjectContextData(e,t),this.processMLeaderObjectContextData(e,t),this.processMTextAttributeObjectContextData(e,t),this.processXRecords(e,t),this.processLayouts(e,t),this.processImageDefs(e,t),this.processLayerFilters(e,t),this.processLayerIndexes(e,t),this.processLayerFilterTree(e,t),this.processMLeaderStyles(e,t),this.processDynBlockMetadata(e,t),this.finishCannoscale(e,t),this.finishAnnoallvisible(e,t)}processDynBlockMetadata(e,t){const i=s=>s==null||s===""||s===0?"":String(s).trim().toUpperCase();for(const s of e.tables.BLOCK_RECORD.entries){const c=t.tables.blockTable.getAt(s.name);if(!c)continue;const a=s,f=r.acdbNormalizeExtensionDictionaryId(a.extensionDictionary??a.ownerDictionaryHardId??a.ownerDictionarySoftId);f&&(c.extensionDictionary=f)}const n=e.objects.DICTIONARY;if(!(n!=null&&n.length))return;const o=n.map(s=>{const c=[],a=s.entries??{};for(const f in a){const l=a[f];f&&l&&c.push({name:f,handle:i(String(l))})}return{handle:i(s.handle),ownerHandle:i(s.ownerHandle)||void 0,entries:c}});r.acdbImportDynBlockMetadata(t,{dictionaries:o,representationData:[]})}processLayerFilterTree(e,t){const i=e.objects.DICTIONARY,n=e.objects.XRECORD;if(!(i!=null&&i.length)||!(n!=null&&n.length))return;const o=f=>f?String(f).trim().toUpperCase():"",s=new Map;i.forEach(f=>{const l={},u=f.entries??{};for(const D in u){const h=u[D];D&&h&&(l[D]=o(String(h)))}s.set(o(f.handle),{handle:o(f.handle),ownerObjectId:o(f.ownerHandle),entries:l})});const c=new Map;n.forEach(f=>{c.set(o(f.handle),{handle:o(f.handle),ownerObjectId:o(f.ownerHandle),extensionDictionaryId:o(f.extensionDictionary),data:(f.data??[]).map(l=>({code:Number(l.code),value:l.value}))})});const a=r.acdbReadLayerFilterTree({dictionaries:s,xrecords:c});a.root.getNestedFilters().length>0&&(t.layerFilters=a)}processLayouts(e,t){const i=t.objects.layout;e.objects.LAYOUT.forEach(o=>{const s=new r.AcDbLayout;s.layoutName=o.layoutName,s.tabOrder=o.tabOrder;const c=t.tables.blockTable.newIterator();s.objectId=o.handle;for(const a of c)if(a.layoutId===s.objectId){s.blockTableRecordId=a.objectId;break}s.blockTableRecordId||o.layoutName==="Model"&&(s.blockTableRecordId=t.tables.blockTable.modelSpace.objectId),s.limits.min.copy(o.minLimit),s.limits.max.copy(o.maxLimit),s.extents.min.copy(o.minExtent),s.extents.max.copy(o.maxExtent),o.viewportId&&s.viewportArray.push(o.viewportId),this.processCommonObjectAttrs(o,s),i.setAt(s.layoutName,s)})}processImageDefs(e,t){const i=t.objects.imageDefinition;e.objects.IMAGEDEF.forEach(o=>{const s=new r.AcDbRasterImageDef;s.sourceFileName=o.fileName,this.processCommonObjectAttrs(o,s),i.setAt(s.objectId,s)})}processLayerFilters(e,t){const i=e.objects.LAYER_FILTER;if(!(i!=null&&i.length))return;const n=t.objects.layerFilter,o=new g;i.forEach(s=>{const c=o.convertLayerFilter(s);n.setAt(c.objectId,c)})}processLayerIndexes(e,t){const i=e.objects.LAYER_INDEX;if(!(i!=null&&i.length))return;const n=t.objects.layerIndex,o=new g;i.forEach(s=>{const c=o.convertLayerIndex(s);n.setAt(c.objectId,c)})}processMLeaderStyles(e,t){const i=e.objects.MLEADERSTYLE;if(!(i!=null&&i.length))return;const n=t.objects.mleaderStyle,o=new g;i.forEach(s=>{const c=o.convertMLeaderStyle(s);n.setAt(c.objectId,c)})}processScales(e,t){const i=this.optionalObjectArray(e,"SCALE");if(!(i!=null&&i.length))return;const n=t.objects.scale,o=new g;for(const s of i){const c=o.convertScale(s),a=c.scaleName||c.objectId;a&&n.setAt(a,c)}}processDictionaryVars(e,t){const i=this.optionalObjectArray(e,"DICTIONARYVAR");if(!(i!=null&&i.length))return;const n=t.objects.dictionaryVar,o=new g;for(const s of i){const c=o.convertDictionaryVar(s);c.objectId&&n.setAt(c.objectId,c)}}processMTextObjectContextData(e,t){const i=this.optionalObjectArray(e,"MTEXTOBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_MTEXTOBJECTCONTEXTDATA_CLASS");if(!(i!=null&&i.length))return;const n=t.objects.objectContextData,o=new g;for(const s of i){const c=o.convertMTextObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processDimensionObjectContextData(e,t){const i=["ALDIMOBJECTCONTEXTDATA","ACDB_ALDIMOBJECTCONTEXTDATA_CLASS","ANGDIMOBJECTCONTEXTDATA","ACDB_ANGDIMOBJECTCONTEXTDATA_CLASS","ARCDIMOBJECTCONTEXTDATA","ACDB_ARCDIMOBJECTCONTEXTDATA_CLASS","DMDIMOBJECTCONTEXTDATA","ACDB_DMDIMOBJECTCONTEXTDATA_CLASS","ORDDIMOBJECTCONTEXTDATA","ACDB_ORDDIMOBJECTCONTEXTDATA_CLASS","RADDIMOBJECTCONTEXTDATA","ACDB_RADDIMOBJECTCONTEXTDATA_CLASS","RADIMOBJECTCONTEXTDATA","ACDB_RADIMOBJECTCONTEXTDATA_CLASS","RADDIMLGCOBJECTCONTEXTDATA","ACDB_RADDIMLGCOBJECTCONTEXTDATA_CLASS"],n=new g,o=t.objects.objectContextData;for(const s of i){const c=this.optionalObjectArray(e,s);if(c!=null&&c.length)for(const a of c){const f=n.convertDimensionObjectContextData(a);f.objectId&&o.setAt(f.objectId,f)}}}processTextObjectContextData(e,t){const i=this.optionalObjectArray(e,"TEXTOBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_TEXTOBJECTCONTEXTDATA_CLASS");if(!(i!=null&&i.length))return;const n=t.objects.objectContextData,o=new g;for(const s of i){const c=o.convertTextObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processHatchScaleContextData(e,t){const i=this.optionalObjectArray(e,"HATCHSCALECONTEXTDATA")??this.optionalObjectArray(e,"ACDB_HATCHSCALECONTEXTDATA_CLASS");if(!(i!=null&&i.length))return;const n=t.objects.objectContextData,o=new g;for(const s of i){const c=o.convertHatchScaleContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processBlkRefObjectContextData(e,t){const i=this.optionalObjectArray(e,"BLKREFOBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_BLKREFOBJECTCONTEXTDATA_CLASS");if(!(i!=null&&i.length))return;const n=t.objects.objectContextData,o=new g;for(const s of i){const c=o.convertBlkRefObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processLeaderObjectContextData(e,t){const i=this.optionalObjectArray(e,"LEADEROBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_LEADEROBJECTCONTEXTDATA_CLASS");if(!(i!=null&&i.length))return;const n=t.objects.objectContextData,o=new g;for(const s of i){const c=o.convertLeaderObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processMLeaderObjectContextData(e,t){const i=this.optionalObjectArray(e,"MLEADEROBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_MLEADEROBJECTCONTEXTDATA_CLASS");if(!(i!=null&&i.length))return;const n=t.objects.objectContextData,o=new g;for(const s of i){const c=o.convertMLeaderObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processMTextAttributeObjectContextData(e,t){const i=this.optionalObjectArray(e,"MTEXTATTRIBUTEOBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_MTEXTATTRIBUTEOBJECTCONTEXTDATA_CLASS");if(!(i!=null&&i.length))return;const n=t.objects.objectContextData,o=new g;for(const s of i){const c=o.convertMTextAttributeObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processXRecords(e,t){const i=e.objects.XRECORD;if(!(i!=null&&i.length))return;const n=t.objects.xrecord,o=new g;for(const s of i){const c=o.convertXRecord(s);c.objectId&&n.setAt(c.objectId,c)}}finishCannoscale(e,t){const i=s=>{const c=s.getAt("CANNOSCALE");return c instanceof r.AcDbDictionaryVar&&c.value?(t.cannoscale=c.value,!0):!1},n=t.objects.dictionary.getAt("AcDbVariableDictionary");if(n instanceof r.AcDbDictionary&&i(n))return;const o=s=>s==null||s===""||s===0?"":String(s).trim().toUpperCase();for(const s of e.objects.DICTIONARY??[]){const a=(s.entries??{}).AcDbVariableDictionary;if(!a)continue;const f=t.getObjectById(o(a));if(f instanceof r.AcDbDictionary&&i(f)){try{t.objects.dictionary.getAt("AcDbVariableDictionary")||t.objects.dictionary.setAt("AcDbVariableDictionary",f)}catch{}return}}}finishAnnoallvisible(e,t){const i=s=>{const c=s.getAt("ANNOALLVISIBLE");if(!(c instanceof r.AcDbDictionaryVar)||c.value==null)return!1;const a=String(c.value).trim();return t.annoallvisible=a!=="0"&&a.toLowerCase()!=="false",!0},n=t.objects.dictionary.getAt("AcDbVariableDictionary");if(n instanceof r.AcDbDictionary&&i(n))return;const o=s=>s==null||s===""||s===0?"":String(s).trim().toUpperCase();for(const s of e.objects.DICTIONARY??[]){const a=(s.entries??{}).AcDbVariableDictionary;if(!a)continue;const f=t.getObjectById(o(a));if(f instanceof r.AcDbDictionary&&i(f))return}}optionalObjectArray(e,t){const n=e.objects[t];return Array.isArray(n)?n:void 0}processCommonObjectAttrs(e,t){t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}groupAndFlattenByType(e){const t={},i=[];for(const o of e)t[o.type]||(t[o.type]=[],i.push(o.type)),t[o.type].push(o);const n=[];for(const o of i){const s=t[o];for(let c=0;c<s.length;c++)n.push(s[c])}return n}isModelSpace(e){return e&&e.toUpperCase()==O}normalizeHeaderStringValue(e){if(typeof e!="string")return;const t=e.trim();return t.length>0?t:void 0}}T.AcDbLibreDwgConverter=v,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(T,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(T=typeof globalThis<"u"?globalThis:T||self,r(T["libredwg-converter"]={},T.dataModel))})(this,(function(T,r){"use strict";function L(C){return!!C&&Math.hypot(C.x||0,C.y||0,C.z||0)>1e-9}function x(C){const e=C.elevation;return Number.isFinite(e)?e:void 0}class S{convert(e){const t=this.createEntity(e);if(t&&(this.processCommonAttrs(e,t),e.type==="ARCALIGNEDTEXT")){const o=e.rawTextColor;t.applyRawTextColor(o)}return t}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="ATTDEF"?this.convertAttributeDefinition(e):e.type=="ATTRIB"?this.convertAttribute(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MLINE"?this.convertMLine(e):e.type=="MTEXT"?this.convertMText(e):e.type=="MULTILEADER"||e.type=="MLEADER"?this.convertMLeader(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE2D"?this.convertPolyline2d(e):e.type=="POLYLINE3D"?this.convertPolyline3d(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="TOLERANCE"?this.convertTolerance(e):e.type=="SHAPE"?this.convertShape(e):e.type=="SOLID"?this.convertSolid(e):e.type=="TRACE"?this.convertTrace(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):e.type=="ACAD_PROXY_ENTITY"?this.convertProxyEntity(e):e.type=="OLE2FRAME"?this.convertOle2Frame(e):e.type=="OLEFRAME"?this.convertOleFrame(e):e.type=="ARCALIGNEDTEXT"?this.convertArcAlignedText(e):null}convertProxyEntity(e){const t=new r.AcDbProxyEntity;if(t.proxyEntityClassId=e.proxyEntityClassId,e.originalDxfName&&(t.originalDxfName=e.originalDxfName),e.applicationEntityClassId!=null&&(t.applicationEntityClassId=e.applicationEntityClassId),e.objectDrawingFormat!=null&&(t.objectDrawingFormat=e.objectDrawingFormat),e.originalDataFormat!=null&&(t.originalDataFormat=e.originalDataFormat),e.graphicsData){const o=r.acdbHexStringsToBytes([e.graphicsData]),n=e.graphicsDataSize??o.length;t.setProxyGraphic(o.subarray(0,n))}return t}convertFace(e){const t=new r.AcDbFace;return e.corner1&&t.setVertexAt(0,e.corner1),e.corner2&&t.setVertexAt(1,e.corner2),e.corner3&&t.setVertexAt(2,e.corner3),e.corner4&&t.setVertexAt(3,e.corner4),t.setEdgeInvisibilities(e.flag),t}convertArc(e){const t=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbArc(r.acgeTransformOcsPointToWcs(e.center,t),e.radius,e.startAngle,e.endAngle,t)}convertCirle(e){const t=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbCircle(r.acgeTransformOcsPointToWcs(e.center,t),e.radius,t)}convertEllipse(e){const t=new r.AcGeVector3d(e.majorAxisEndPoint),o=t.length();return new r.AcDbEllipse(e.center,e.extrusionDirection??r.AcGeVector3d.Z_AXIS,t,o,o*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const t=e.startPoint,o=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(t.x,t.y,t.z),new r.AcGePoint3d(o.x,o.y,o.z))}convertSpline(e){return r.AcDbSpline.fromDwgSpline(e)}convertPoint(e){const t=new r.AcDbPoint;return t.position=e.position,t}convertShape(e){const t=e.extrusionDirection??r.AcGeVector3d.Z_AXIS,o=new r.AcDbShape;return o.position=r.acgeTransformOcsPointToWcs(e.insertionPoint,t),o.size=e.size,o.shapeNumber=e.shapeNumber,e.styleName&&(o.styleName=e.styleName),o.rotation=e.rotation??0,o.widthFactor=e.xScale??1,o.oblique=e.obliqueAngle??0,o.thickness=e.thickness??0,o.normal.copy(t),o}convertSolid(e){return this.convertTraceLike(new r.AcDbSolid,e)}convertTrace(e){return this.convertTraceLike(new r.AcDbTrace,e)}convertTraceLike(e,t){const o=t.extrusionDirection??r.AcGeVector3d.Z_AXIS,n=s=>r.acgeTransformOcsPointToWcs({x:s.x,y:s.y,z:s.z??0},o),i=t.corner4??t.corner3;return e.setPointAt(0,n(t.corner1)),e.setPointAt(1,n(t.corner2)),e.setPointAt(2,n(t.corner3)),e.setPointAt(3,n(i)),e.thickness=t.thickness??0,e.normal.copy(o),e.elevation=e.getPointAt(0).z,e}convertLWPolyline(e){const t=new r.AcDbPolyline;t.closed=!!(e.flag&512);const o=e.constantWidth??-1;return e.vertices.forEach((n,i)=>{t.addVertexAt(i,new r.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth??o,n.endWidth??o)}),Number.isFinite(e.elevation)&&(t.elevation=e.elevation),Number.isFinite(e.thickness)&&(t.thickness=e.thickness),L(e.extrusionDirection)&&(t.normal=e.extrusionDirection),t}convertPolyline2d(e){var u;const t=!!(e.flag&1),o=!!(e.flag&16),n=!!(e.flag&64),i=!!(e.flag&32),s=[],c=[],a=[];if(e.vertices.map(l=>{if(!(l.flag&16))if(n&&l.flag&128)if(l.flag&64)s.push({x:l.x,y:l.y,z:l.z}),c.push(l.bulge??0);else{const f=[];l.polyfaceIndex0!=null&&l.polyfaceIndex0!=0&&f.push(Math.abs(l.polyfaceIndex0)-1),l.polyfaceIndex1!=null&&l.polyfaceIndex1!=0&&f.push(Math.abs(l.polyfaceIndex1)-1),l.polyfaceIndex2!=null&&l.polyfaceIndex2!=0&&f.push(Math.abs(l.polyfaceIndex2)-1),l.polyfaceIndex3!=null&&l.polyfaceIndex3!=0&&f.push(Math.abs(l.polyfaceIndex3)-1),f.length>=3&&a.push(f)}else s.push({x:l.x,y:l.y,z:l.z}),c.push(l.bulge??0)}),o){const l=e.meshMVertexCount??2,f=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(l,f,s,t,i)}else{if(n)return new r.AcDbPolyFaceMesh(s,a);{let l=r.AcDbPoly2dType.SimplePoly;e.flag&2?l=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?l=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(l=r.AcDbPoly2dType.QuadSplinePoly));const f=new r.AcDb2dPolyline(l,s,((u=s[0])==null?void 0:u.z)??0,t,e.startWidth,e.endWidth,c);return L(e.extrusionDirection)&&(f.normal=e.extrusionDirection),f}}}convertPolyline3d(e){const t=!!(e.flag&1),o=[];e.vertices.map(i=>{i.flag&16||o.push({x:i.x,y:i.y,z:i.z})});let n=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?n=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(n=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(n,o,t)}convertHatch(e){var n;const t=new r.AcDbHatch;if((n=e.definitionLines)==null||n.forEach(i=>{t.definitionLines.push({angle:i.angle,base:i.base,offset:i.offset,dashLengths:i.numberOfDashLengths>0?i.dashLengths:[]})}),t.hatchStyle=e.hatchStyle,t.patternName=e.patternName,e.solidFill==1&&(t.isSolidFill=!0),t.patternType=e.patternType,t.patternAngle=e.patternAngle==null?0:e.patternAngle,t.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(i=>{if(i.boundaryPathTypeFlag&2){const c=i,a=new r.AcGePolyline2d;a.closed=c.isClosed,c.vertices.forEach((u,l)=>{a.addVertexAt(l,{x:u.x,y:u.y,bulge:u.bulge})}),t.add(a)}else{const c=i,a=[];c.edges.forEach(l=>{if(l!=null){if(l.type==1){const f=l;a.push(new r.AcGeLine2d(f.start,f.end))}else if(l.type==2){const f=l;a.push(new r.AcGeCircArc2d(f.center,f.radius,f.startAngle,f.endAngle,!f.isCCW))}else if(l.type==3){const f=l;new r.AcGeVector2d().subVectors(f.end,f.center);const p=Math.sqrt(Math.pow(f.end.x,2)+Math.pow(f.end.y,2)),A=p*f.lengthOfMinorAxis;let b=f.startAngle,d=f.endAngle;const y=Math.atan2(f.end.y,f.end.x);f.isCCW||(b=Math.PI*2-b,d=Math.PI*2-d),a.push(new r.AcGeEllipseArc2d({...f.center,z:0},p,A,b,d,!f.isCCW,y))}else if(l.type==4){const f=r.AcGeSpline3d.fromDwgSplineEdge(l);f&&a.push(f)}}});const u=r.AcGeLoop2d.buildFromEdges(a);u.length===1?t.add(u[0]):a.length>0&&t.add(new r.AcGeLoop2d(a))}}),e.gradientFlag){const i=e;if(t.hatchObjectType=r.AcDbHatchObjectType.GradientObject,t.gradientName=i.gradientName,t.gradientAngle=i.gradientRotation??0,t.gradientShift=i.gradientDefinition??0,t.gradientOneColorMode=i.gradientColorFlag==1,t.shadeTintValue=i.colorTint??0,i.gradientColors){const s=i.gradientColors.length;s>1?(t.gradientStartColor=i.gradientColors[0].rgb,t.gradientEndColor=i.gradientColors[1].rgb):s>0&&(t.gradientStartColor=i.gradientColors[0].rgb)}}return e.extrusionDirection&&(t.normal=e.extrusionDirection),t}convertTable(e){const t=new r.AcDbTable(e.name??"",e.rowCount,e.columnCount);return t.tableStyleId=e.tableStyleId,t.owningBlockRecordId=e.blockRecordHandle,e.directionVector&&(t.horizontalDirection=new r.AcGeVector3d(e.directionVector)),t.attachmentPoint=e.attachmentPoint,t.position.copy(e.startPoint),t.tableValueFlag=e.tableValue,t.tableOverrideFlag=e.overrideFlag,t.borderColorOverrideFlag=e.borderColorOverrideFlag,t.borderLineweightOverrideFlag=e.borderLineWeightOverrideFlag,t.borderVisibilityOverrideFlag=e.borderVisibilityOverrideFlag,e.columnWidthArr.forEach((o,n)=>t.setColumnWidth(n,o)),e.rowHeightArr.forEach((o,n)=>t.setRowHeight(n,o)),e.cells.forEach((o,n)=>{t.setCell(n,o)}),t}convertText(e){const t=new r.AcDbText;t.textString=e.text,t.styleName=e.styleName,t.height=e.textHeight,t.position.copy(e.startPoint);const o=!e.endPoint||e.endPoint.x===0&&e.endPoint.y===0&&(e.endPoint.z??0)===0;e.endPoint&&!o?(t.alignmentPoint.copy(e.endPoint),t.hasAlignmentPoint=!0):(t.alignmentPoint.copy(e.startPoint),t.hasAlignmentPoint=!1),t.rotation=e.rotation,t.oblique=e.obliqueAngle??0,t.thickness=e.thickness,t.horizontalMode=e.halign,t.verticalMode=e.valign,t.widthFactor=e.xScale??1,L(e.extrusionDirection)&&(t.normal=e.extrusionDirection);const n=x(e);return n!=null&&(t.position.z=n,t.alignmentPoint.z=n),t}convertArcAlignedText(e){const t=new r.AcDbArcAlignedText;return t.textString=e.text,t.textSize=e.textSize,t.xScale=e.xScale>0?e.xScale:1,t.characterSpacing=e.characterSpacing,e.styleName&&(t.styleName=e.styleName),t.fontName=e.fontName,t.bigFontName=e.bigFontName,t.offsetFromArc=e.offsetFromArc,t.rightOffset=e.rightOffset,t.leftOffset=e.leftOffset,t.center=new r.AcGePoint3d(e.center.x,e.center.y,e.center.z),t.radius=e.radius,t.startAngle=e.startAngle,t.endAngle=e.endAngle,t.normal=new r.AcGeVector3d(e.extrusionDirection.x,e.extrusionDirection.y,e.extrusionDirection.z||1),t.characterSet=e.characterSet,t.pitchAndFamily=e.pitchAndFamily,t.isShx=e.isShx,t.isBold=e.isBold,t.isItalic=e.isItalic,t.isUnderlined=e.isUnderlined,t.alignment=e.alignment,t.isReverse=e.isReverse,t.wizardFlag=e.wizardFlag,t.textPosition=e.textPosition,t.textDirection=e.textDirection,e.arcHandle&&(t.arcId=e.arcHandle),t}convertTolerance(e){const t=new r.AcDbFcf;return t.location.copy(e.insertionPoint),t.text=e.text,t.dimensionStyle=e.styleName??"",e.extrusionDirection&&t.normal.copy(e.extrusionDirection),e.xAxisDirection&&t.direction.copy(e.xAxisDirection),t}convertMText(e){const t=new r.AcDbMText;t.contents=e.text,e.styleName!=null&&(t.styleName=e.styleName),t.height=e.textHeight,t.width=e.rectWidth,t.rotation=e.rotation||0,t.location=e.insertionPoint,t.attachmentPoint=e.attachmentPoint,e.direction&&(t.direction=new r.AcGeVector3d(e.direction)),t.drawingDirection=e.drawingDirection,e.lineSpacing!=null&&e.lineSpacing>0&&(t.lineSpacingFactor=e.lineSpacing),e.lineSpacingStyle!=null&&(t.lineSpacingStyle=e.lineSpacingStyle),e.extentsWidth!=null&&e.extentsWidth>0&&(t.extentsWidth=e.extentsWidth);const o=e.backgroundFill??0;if(o!==0){if(t.backgroundFill=!0,t.useBackgroundColor=(o&2)!==0,!t.useBackgroundColor&&e.backgroundFillColor!=null){const n=e.backgroundFillColor>>>0,i=n>>>24&255;if(i>=192&&i<=200){const s=n&255;if(i===197||i===195&&s>=1&&s<=255)t.backgroundFillColor=i===197?7:s;else if(i===194){const c=n&16777215;c!==0&&(t.backgroundFillColor=c)}}else t.backgroundFillColor=n}e.fillBoxScale!=null&&e.fillBoxScale>0&&(t.backgroundScaleFactor=e.fillBoxScale),e.backgroundFillTransparency!=null&&(t.backgroundFillTransparency=e.backgroundFillTransparency)}return t}convertLeader(e){const t=new r.AcDbLeader;return e.vertices.forEach(o=>{t.appendVertex(o)}),t.hasArrowHead=e.isArrowheadEnabled,t.hasHookLine=e.isHooklineExists,t.isHookLineSameDirection=e.isHooklineSameDirection,t.isSplined=e.isSpline,t.dimensionStyle=e.styleName??"",t.annoType=e.leaderCreationFlag,e.textHeight!=null&&(t.textHeight=e.textHeight),e.textWidth!=null&&(t.textWidth=e.textWidth),e.byBlockColor!=null&&(t.byBlockColor=e.byBlockColor),e.associatedAnnotation&&(t.associatedAnnotation=e.associatedAnnotation),e.normal&&(t.normal=e.normal),e.horizontalDirection&&(t.horizontalDirection=e.horizontalDirection),e.offsetFromBlock&&(t.offsetFromBlock=e.offsetFromBlock),e.offsetFromAnnotation&&(t.offsetFromAnnotation=e.offsetFromAnnotation),t}convertMLine(e){const t=new r.AcDbMLine;return t.styleName=e.mlineStyle||"STANDARD",t.scale=e.scale,t.flags=e.flags,t.justification=e.justification,t.startPosition=e.startPoint,t.normal=e.extrusionDirection??r.AcGeVector3d.Z_AXIS,t.styleCount=e.numberOfLines??0,t.segments=(e.vertices??[]).map(o=>({position:o.vertex,direction:o.vertexDirection,miterDirection:o.miterDirection,elements:(o.lines??[]).map(n=>({parameterCount:n.numberOfSegmentParams,parameters:n.segmentParams??[],fillCount:n.numberOfAreaFillParams,fillParameters:n.areaFillParams??[]}))})),t}convertMLeader(e){var E,P;const t=new r.AcDbMLeader,o=e;t.version=e.version,t.leaderStyleId=e.leaderStyleId,e.leaderStyleId&&(t.mleaderStyleId=e.leaderStyleId),t.propertyOverrideFlag=e.propertyOverrideFlag,t.leaderLineType=e.leaderLineType??r.AcDbMLeaderLineType.StraightLeader,e.leaderLineColor!=null&&(t.leaderLineColor=this.convertMLeaderEntityColor(e.leaderLineColor)),t.leaderLineTypeId=e.leaderLineTypeId,t.leaderLineWeight=e.leaderLineWeight,t.landingEnabled=e.landingEnabled,t.doglegEnabled=e.doglegEnabled??!1,t.doglegLength=e.doglegLength??0,t.arrowheadId=e.arrowheadId,t.arrowheadSize=e.arrowheadSize,t.textStyleId=e.textStyleId,t.textLeftAttachmentType=e.textLeftAttachmentType,t.textRightAttachmentType=e.textRightAttachmentType,t.textAngleType=e.textAngleType,t.textAlignmentType=e.textAlignmentType,e.textColor!=null&&(t.textColor=this.convertMLeaderEntityColor(e.textColor)),t.textFrameEnabled=e.textFrameEnabled,t.landingGap=e.landingGap,t.textAttachment=e.textAttachment,t.textFlowDirection=e.textFlowDirection,this.isValidHandleId(e.blockContentId)&&(t.blockContentId=e.blockContentId),e.blockContentColor!=null&&(t.blockContentColor=this.convertMLeaderEntityColor(e.blockContentColor)),t.blockContentRotation=e.blockContentRotation,t.blockContentConnectionType=e.blockContentConnectionType,t.annotativeScaleEnabled=e.annotativeScaleEnabled,t.arrowheadOverrides=e.arrowheadOverrides?e.arrowheadOverrides.map(g=>({...g})):[],t.blockAttributes=e.blockAttributes?e.blockAttributes.map(g=>({...g})):[],t.textDirectionNegative=e.textDirectionNegative,t.textAlignInIPE=e.textAlignInIPE,t.bottomTextAttachmentDirection=e.bottomTextAttachmentDirection,t.topTextAttachmentDirection=e.topTextAttachmentDirection,t.contentScale=e.contentScale,t.textLineSpacingStyle=e.textLineSpacingStyle,e.textBackgroundColor!=null&&(t.textBackgroundColor=this.convertMLeaderEntityColor(e.textBackgroundColor)),t.textBackgroundScaleFactor=e.textBackgroundScaleFactor,t.textBackgroundTransparency=e.textBackgroundTransparency,t.textBackgroundColorOn=e.textBackgroundColorOn,t.textFillOn=e.textFillOn,t.textColumnType=e.textColumnType,t.textUseAutoHeight=e.textUseAutoHeight,t.textColumnWidth=e.textColumnWidth,t.textColumnGutterWidth=e.textColumnGutterWidth,t.textColumnFlowReversed=e.textColumnFlowReversed,t.textColumnHeight=e.textColumnHeight,t.textUseWordBreak=e.textUseWordBreak,t.hasMText=e.hasMText,t.hasBlock=e.hasBlock,t.planeNormalReversed=e.planeNormalReversed,e.blockContentScale&&(t.blockContentScale=new r.AcGeVector3d(e.blockContentScale)),e.contentBasePosition&&(t.contentBasePosition=new r.AcGePoint3d().copy(e.contentBasePosition)),e.textAnchor&&(t.textAnchor=new r.AcGePoint3d().copy(e.textAnchor)),e.planeOrigin&&(t.planeOrigin=new r.AcGePoint3d().copy(e.planeOrigin)),e.planeXAxisDirection&&(t.planeXAxisDirection=new r.AcGeVector3d(e.planeXAxisDirection)),e.planeYAxisDirection&&(t.planeYAxisDirection=new r.AcGeVector3d(e.planeYAxisDirection));const n=o.textContent,i=n&&typeof n=="object"?n:void 0,s=typeof n=="string"&&n.length>0||this.readString(i??{},["text","contents"])!=null||this.readString(o,["text","contents","mtext"])!=null,c=e.contentType??(s?r.AcDbMLeaderContentType.MTextContent:e.blockContent?r.AcDbMLeaderContentType.BlockContent:r.AcDbMLeaderContentType.NoneContent);t.contentType=c;const a=this.readPoint(o,["normal","extrusionDirection"]);a&&(t.normal=a);const u=this.readString(i??{},["styleName","textStyleName","textStyle"])??this.readString(o,["textStyleName","textStyle","styleName"]);u&&(t.textStyleName=u);const l=this.readPositiveNumber(i??{},["textHeight","height"])??this.readPositiveNumber(o,["textHeight","mtextHeight","textContentHeight"])??this.readPositiveNumber(o,["arrowheadSize","contentScale"]);l!=null&&(t.textHeight=l);const f=this.readPositiveNumber(i??{},["textWidth","width"])??this.readPositiveNumber(o,["textWidth","mtextWidth","textContentWidth"]);f!=null&&(t.textWidth=f),t.textLineSpacingFactor=this.readNumber(i??{},["lineSpacingFactor","textLineSpacingFactor"])??this.readNumber(o,["textLineSpacingFactor"])??t.textLineSpacingFactor;const h=this.readNumber(i??{},["lineSpacingStyle","textLineSpacingStyle"])??this.readNumber(o,["textLineSpacingStyle"]);h!=null&&(t.textLineSpacingStyle=h);const p=this.readNumber(i??{},["textRotation","rotation"])??this.readNumber(o,["textRotation","mtextRotation","textContentRotation"]);p!=null&&(t.textRotation=p);const A=this.readPoint(o,["textDirection","mtextDirection","textDirectionVector"]);A&&(t.textDirection=A);const b=this.readNumber(o,["textAttachmentPoint","attachmentPoint"]);b!=null&&b!==0&&(t.textAttachmentPoint=b);const d=e.textAttachmentDirection;d!=null&&(t.textAttachmentDirection=d);const y=this.readNumber(o,["textDrawingDirection","drawingDirection"]);y!=null&&(t.textDrawingDirection=y);const I=typeof n=="string"?n:this.readString(i??{},["text","contents"])??this.readString(o,["text","contents","mtext"]),m=this.readPoint(i??{},["anchorPoint","textAnchor","textLocation","textPosition","textAnchorPoint"])??this.readPoint(o,["textAnchor","textLocation","textPosition","textAnchorPoint","contentBasePosition"]);if(I!=null&&m&&(t.mtextContent={text:I,anchorPoint:m}),e.blockContent){const g=e.blockContent,w=e.blockContent.blockContentId;if(this.isValidHandleId(w)){const N=this.readMLeaderEntityColor(g,["color"]);t.blockContent={blockContentId:w,normal:this.readPoint(g,["normal"]),position:e.blockContent.position,scale:this.readPoint(g,["scale"]),rotation:this.readNumber(g,["rotation"]),color:N,transformationMatrix:Array.isArray(e.blockContent.transformationMatrix)?e.blockContent.transformationMatrix:[]}}}else this.isValidHandleId(e.blockContentId)&&(t.blockContent={blockContentId:e.blockContentId,scale:e.blockContentScale,rotation:e.blockContentRotation,color:t.blockContentColor,transformationMatrix:[]});return(E=this.readMLeaderLeaders(o))==null||E.forEach(g=>{t.addLeader({lastLeaderLinePoint:g.lastLeaderLinePoint,lastLeaderLinePointSet:g.lastLeaderLinePointSet,doglegVector:g.doglegVector,doglegVectorSet:g.doglegVectorSet,doglegLength:g.doglegLength??e.doglegLength,breaks:g.breaks,leaderBranchIndex:g.leaderBranchIndex,leaderLines:g.leaderLines})}),t.numberOfLeaders===0&&((P=this.readLeaderLineArray(o))==null||P.forEach(g=>{t.addLeader({doglegLength:e.doglegLength}),t.addLeaderLine(t.numberOfLeaders-1,g)})),t.numberOfLeaders===0&&e.contentBasePosition&&t.addLeader({lastLeaderLinePoint:e.contentBasePosition,lastLeaderLinePointSet:!0,doglegLength:e.doglegLength}),t}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"){const t=e,o=new r.AcDbAlignedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return t.insertionPoint&&(o.dimBlockPosition={x:t.insertionPoint.x,y:t.insertionPoint.y,z:0}),o.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRotatedDimension"){const t=e,o=new r.AcDbRotatedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return t.insertionPoint&&(o.dimBlockPosition={x:t.insertionPoint.x,y:t.insertionPoint.y,z:0}),o.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const t=e,o=new r.AcDb3PointAngularDimension(t.centerPoint,t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDb2LineAngularDimension"){const t=e,o=t.definitionPoint??t.arcPoint??t.subDefinitionPoint2,n=t.centerPoint??t.subDefinitionPoint2??t.subDefinitionPoint1,i=n??o,s=t.subDefinitionPoint1??n??o,c=t.subDefinitionPoint2??n??o;if(!o||!t.name)return null;const a=new r.AcDb3PointAngularDimension(i,s,c,o);return this.processDimensionCommonAttrs(e,a),a}else if(e.subclassMarker=="AcDbOrdinateDimension"){const t=e,o=new r.AcDbOrdinateDimension(t.subDefinitionPoint1,t.subDefinitionPoint2);return t.definitionPoint&&(o.origin=new r.AcGePoint3d(t.definitionPoint.x,t.definitionPoint.y,t.definitionPoint.z)),this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRadialDimension"){const t=e,o=new r.AcDbRadialDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbDiametricDimension"){const t=e,o=new r.AcDbDiametricDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,o),o}return null}processImage(e,t){t.position.copy(e.position),t.brightness=e.brightness,t.contrast=e.contrast,t.fade=e.fade,t.imageSize.copy(e.imageSize),t.imageDefId=e.imageDefHandle,t.isClipped=e.clipping>0,t.isShownClipped=(e.flags&4)!==0,t.isImageShown=(e.flags&3)!==0,t.isImageTransparent=(e.flags&8)!==0,e.clippingBoundaryPath.forEach(o=>{t.clipBoundary.push(new r.AcGePoint2d(o))}),t.clipBoundaryType=e.clippingBoundaryType,t.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,t.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,t.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const t=new r.AcDbRasterImage;return this.processImage(e,t),t}convertWipeout(e){const t=new r.AcDbWipeout;return this.processImage(e,t),t}convertOleFrame(e){const t=new r.AcDbOleFrame;if(t.oleVersion=e.flag??0,e.binaryData){const o=r.acdbHexStringsToBytes([e.binaryData]);t.loadOleObjectFromDxf(e.dataSize,o)}return t}convertOle2Frame(e){const t=new r.AcDbOle2Frame;if(t.oleVersion=e.oleVersion??0,t.userType=e.oleClient??"",e.leftUpPoint&&t.upperLeftCorner.copy(e.leftUpPoint),e.rightDownPoint&&t.lowerRightCorner.copy(e.rightDownPoint),t.setLockAspect(e.lockAspect??0),t.oleObjectType=e.oleObjectType??r.AcDbOleObjectType.Embedded,t.tileMode=e.tileModeDescriptor??r.AcDbOleTileMode.ModelSpace,e.binaryData){const o=r.acdbHexStringsToBytes([e.binaryData]);t.loadOleObjectFromDxf(e.dataSize,o)}return t}convertViewport(e){const t=new r.AcDbViewport;t.number=e.viewportId,t.centerPoint.copy(e.viewportCenter),t.height=e.height,t.width=e.width,t.viewCenter.copy(e.displayCenter),t.viewHeight=e.viewHeight,e.targetPoint&&t.viewTarget.copy(e.targetPoint),e.viewTwistAngle!=null&&(t.viewTwistAngle=e.viewTwistAngle);const o=1e-6,n=Math.abs(t.centerPoint.x)<o&&Math.abs(t.centerPoint.y)<o,i=t.viewTarget,s=Math.abs(i.x)<o&&Math.abs(i.y)<o,c=Number.isFinite(t.height)&&Number.isFinite(t.viewHeight)&&Math.abs(t.viewHeight-t.height)<o;return n&&s&&c&&t.centerPoint.copy(t.viewCenter),t}convertRay(e){const t=new r.AcDbRay;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertXline(e){const t=new r.AcDbXline;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertAttributeCommon(e,t){const o=e.text;t.textString=o.text,t.styleName=o.styleName,t.height=o.textHeight,t.position.copy(o.startPoint);const n=e.alignmentPoint??o.endPoint,i=!n||n.x===0&&n.y===0&&(n.z??0)===0;n&&!i?(t.alignmentPoint.copy(n),t.hasAlignmentPoint=!0):(t.alignmentPoint.copy(o.startPoint),t.hasAlignmentPoint=!1),t.rotation=o.rotation,t.oblique=o.obliqueAngle??0,t.thickness=o.thickness,t.horizontalMode=o.halign,t.verticalMode=o.valign,t.widthFactor=o.xScale??1,L(o.extrusionDirection)&&(t.normal=o.extrusionDirection);const s=x(o);s!=null&&(t.position.z=s,t.alignmentPoint.z=s),t.tag=e.tag,t.fieldLength=e.fieldLength,t.isInvisible=(e.flags&r.AcDbAttributeFlags.Invisible)!==0,t.isConst=(e.flags&r.AcDbAttributeFlags.Const)!==0,t.isVerifiable=(e.flags&r.AcDbAttributeFlags.Verifiable)!==0,t.isPreset=(e.flags&r.AcDbAttributeFlags.Preset)!==0,t.lockPositionInBlock=e.lockPositionFlag,t.isReallyLocked=e.isReallyLocked,t.isMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.MultiLine)!==0,t.isConstMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.ConstMultiLine)!==0}convertAttribute(e){const t=new r.AcDbAttribute;return this.convertAttributeCommon(e,t),t}convertAttributeDefinition(e){const t=new r.AcDbAttributeDefinition;return this.convertAttributeCommon(e,t),t.prompt=e.prompt,t}convertBlockReference(e){const t=new r.AcDbBlockReference(e.name);return e.insertionPoint&&t.position.copy(e.insertionPoint),t.scaleFactors.x=e.xScale,t.scaleFactors.y=e.yScale,t.scaleFactors.z=e.zScale,t.rotation=e.rotation,t.normal.copy(e.extrusionDirection),e.columnCount!=null&&(t.columnCount=e.columnCount),e.rowCount!=null&&(t.rowCount=e.rowCount),e.columnSpacing!=null&&(t.columnSpacing=e.columnSpacing),e.rowSpacing!=null&&(t.rowSpacing=e.rowSpacing),e.handle!=null&&(t.objectId=e.handle),e.attribs&&e.attribs.forEach(o=>{const n=this.convert(o);n instanceof r.AcDbAttribute&&t.appendAttributes(n)}),t}processDimensionCommonAttrs(e,t){t.dimBlockId=e.name,t.textPosition.copy(e.textPoint),t.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(t.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(t.textLineSpacingStyle=e.textLineSpacingStyle),t.dimensionStyleName=e.styleName,t.dimensionText=e.text||"",t.measurement=e.measurement,e.dimensionType!=null&&(t.dimensionType=e.dimensionType)}processCommonAttrs(e,t){t.layer=e.layer||"0",t.objectId=e.handle,e.ownerBlockRecordSoftId!=null&&(t.ownerId=e.ownerBlockRecordSoftId);const o=r.acdbNormalizeExtensionDictionaryId(e.extensionDictionary??e.ownerDictionaryHardId??e.ownerDictionarySoftId);if(o&&(t.extensionDictionary=o),this.applyExtendedData(e,t),e.lineType!=null&&(t.lineType=e.lineType),e.lineweight!=null&&(t.lineWeight=e.lineweight),e.lineTypeScale!=null&&(t.linetypeScale=e.lineTypeScale),e.color!=null||e.colorIndex!=null||e.colorName){const n=new r.AcCmColor;e.color!=null&&n.setRGBValue(e.color),e.colorIndex!=null&&(e.color==null||e.colorIndex===7)&&(n.colorIndex=e.colorIndex),e.colorName&&(n.colorName=e.colorName),t.color=n}if(e.isVisible!=null&&(t.visibility=e.isVisible),e.transparency!=null){const n=new r.AcCmTransparency;n.method=e.transparencyType,(n.isByBlock||n.isByBlock)&&(n.alpha=e.transparency),t.transparency=n}}applyExtendedData(e,t){const o=e.xdata;if(!o)return;const n=Array.isArray(o)?o:[o];for(const i of n){if(!(i!=null&&i.appName))continue;const s=[{code:r.AcDbDxfCode.ExtendedDataRegAppName,value:i.appName}];for(const c of i.value??[])if(c!=null&&typeof c=="object"&&"code"in c&&"value"in c){const a=Number(c.code),u=c.value;if(a===r.AcDbDxfCode.ExtendedDataHandle||a>=1e3&&a<=1071){const l=this.normalizeXDataValue(a,u);l!==void 0&&s.push({code:a,value:l})}}t.setImportedXData(s)}}normalizeXDataValue(e,t){if(e>=1010&&e<=1013){if(this.isPointLike(t))return{x:t.x,y:t.y,z:typeof t.z=="number"?t.z:0};if(Array.isArray(t)&&typeof t[0]=="number"&&typeof t[1]=="number")return{x:t[0],y:t[1],z:typeof t[2]=="number"?t[2]:0};if(typeof t=="number"&&Number.isFinite(t))return t}if(e===r.AcDbDxfCode.ExtendedDataBinaryChunk)return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):typeof t=="string"?t:Array.isArray(t)&&t.every(o=>typeof o=="number"&&Number.isFinite(o)&&o>=0&&o<=255)?Uint8Array.from(t):void 0;if(typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t instanceof Uint8Array)return t;if(this.isPointLike(t))return{x:t.x,y:t.y,z:typeof t.z=="number"?t.z:0}}convertMLeaderEntityColor(e){return r.acdbDecodeMLeaderStyleRawColor(e)}readMLeaderEntityColor(e,t){for(const o of t){const n=e[o];if(typeof n=="number"&&Number.isFinite(n))return r.acdbDecodeMLeaderStyleRawColor(n)}}isValidHandleId(e){return e!=null&&e!==""&&e!=="0"}readNumber(e,t){for(const o of t){const n=e[o];if(typeof n=="number"&&Number.isFinite(n))return n}}readPositiveNumber(e,t){const o=this.readNumber(e,t);return o!=null&&o>0?o:void 0}readString(e,t){for(const o of t){const n=e[o];if(typeof n=="string")return n}}readBoolean(e,t){for(const o of t){const n=e[o];if(typeof n=="boolean")return n;if(typeof n=="number")return n!==0}}readPoint(e,t){for(const o of t){const n=e[o];if(this.isPointLike(n))return n;if(Array.isArray(n)&&typeof n[0]=="number"&&typeof n[1]=="number")return{x:n[0],y:n[1],z:n[2]??0}}}readLeaderLineArray(e){const t=e.leaderLines;if(Array.isArray(t))return t.map(n=>{if(!n||typeof n!="object")return;const i=n.vertices;return Array.isArray(i)?i.filter(s=>this.isPointLike(s)):void 0}).filter(n=>!!n&&n.length>0);const o=e.vertices;if(Array.isArray(o)){const n=o.filter(i=>this.isPointLike(i));return n.length>0?[n]:void 0}}readMLeaderLeaders(e){const t=e.leaderSections;if(!Array.isArray(t))return;const o=[];return t.forEach(n=>{if(!n||typeof n!="object")return;const i=n,s=i.leaderLines,c=Array.isArray(s)?s.reduce((A,b)=>{const d=this.readMLeaderLine(b);return d&&A.push(d),A},[]):void 0,a={},u=this.readPoint(i,["lastLeaderLinePoint"]),l=this.readPoint(i,["doglegVector"]),f=this.readNumber(i,["doglegLength"]),h=this.readMLeaderBreaks(i.breaks),p=this.readNumber(i,["leaderBranchIndex"]);u&&(a.lastLeaderLinePoint=u),i.lastLeaderLinePointSet!=null&&(a.lastLeaderLinePointSet=this.readBoolean(i,["lastLeaderLinePointSet"])),l&&(a.doglegVector=l),i.doglegVectorSet!=null&&(a.doglegVectorSet=this.readBoolean(i,["doglegVectorSet"])),f!=null&&(a.doglegLength=f),h&&(a.breaks=h),p!=null&&(a.leaderBranchIndex=p),c&&(a.leaderLines=c),o.push(a)}),o}readMLeaderLine(e){if(!e||typeof e!="object")return;const t=e,o=t.vertices,n=Array.isArray(o)?o.filter(a=>this.isPointLike(a)):[],i=this.readMLeaderBreaks(t.breaks),s=Array.isArray(t.breakPointIndexes)?t.breakPointIndexes.filter(a=>typeof a=="number"):void 0,c=this.readNumber(t,["leaderLineIndex"]);return n.length>0||i&&i.length>0?{vertices:n,breakPointIndexes:s,leaderLineIndex:c,breaks:i}:void 0}readMLeaderBreaks(e){if(!Array.isArray(e))return;const t=e.map(o=>{if(!o||typeof o!="object")return;const n=o,i=this.readPoint(n,["start"]),s=this.readPoint(n,["end"]),c=this.readNumber(n,["index"]);if(!i||!s)return;const a={start:i,end:s};return c!=null&&(a.index=c),a}).filter(o=>!!o);return t.length>0?t:void 0}isPointLike(e){return!!e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}}class D{convertMLeaderStyle(e){const t=new r.AcDbMLeaderStyle;return t.unknown1=e.unknown1,e.contentType!=null&&(t.contentType=e.contentType),e.drawMLeaderOrderType!=null&&(t.drawMLeaderOrderType=e.drawMLeaderOrderType),e.drawLeaderOrderType!=null&&(t.drawLeaderOrderType=e.drawLeaderOrderType),e.maxLeaderSegmentPoints!=null&&(t.maxLeaderSegmentPoints=e.maxLeaderSegmentPoints),e.firstSegmentAngleConstraint!=null&&(t.firstSegmentAngleConstraint=e.firstSegmentAngleConstraint),e.secondSegmentAngleConstraint!=null&&(t.secondSegmentAngleConstraint=e.secondSegmentAngleConstraint),e.leaderLineType!=null&&(t.leaderLineType=e.leaderLineType),e.leaderLineColor!=null&&(t.leaderLineColor=r.acdbDecodeMLeaderStyleRawColor(e.leaderLineColor)),t.leaderLineTypeId=e.leaderLineTypeId,e.leaderLineWeight!=null&&(t.leaderLineWeight=e.leaderLineWeight),e.landingEnabled!=null&&(t.landingEnabled=e.landingEnabled),e.landingGap!=null&&(t.landingGap=e.landingGap),e.doglegEnabled!=null&&(t.doglegEnabled=e.doglegEnabled),e.doglegLength!=null&&(t.doglegLength=e.doglegLength),e.description!=null&&(t.description=e.description),t.arrowheadId=e.arrowheadId,e.arrowheadSize!=null&&(t.arrowheadSize=e.arrowheadSize),e.defaultMTextContents!=null&&(t.defaultMTextContents=e.defaultMTextContents),t.textStyleId=e.textStyleId,e.textLeftAttachmentType!=null&&(t.textLeftAttachmentType=e.textLeftAttachmentType),e.textAngleType!=null&&(t.textAngleType=e.textAngleType),e.textAlignmentType!=null&&(t.textAlignmentType=e.textAlignmentType),e.textRightAttachmentType!=null&&(t.textRightAttachmentType=e.textRightAttachmentType),e.textColor!=null&&(t.textColor=r.acdbDecodeMLeaderStyleRawColor(e.textColor)),e.textHeight!=null&&(t.textHeight=e.textHeight),e.textFrameEnabled!=null&&(t.textFrameEnabled=e.textFrameEnabled),e.textAlignAlwaysLeft!=null&&(t.textAlignAlwaysLeft=e.textAlignAlwaysLeft),e.alignSpace!=null&&(t.alignSpace=e.alignSpace),t.blockContentId=e.blockContentId,e.blockContentColor!=null&&(t.blockContentColor=r.acdbDecodeMLeaderStyleRawColor(e.blockContentColor)),e.blockContentScale&&(t.blockContentScale={x:e.blockContentScale.x,y:e.blockContentScale.y,z:e.blockContentScale.z??1}),e.blockContentScaleEnabled!=null&&(t.blockContentScaleEnabled=e.blockContentScaleEnabled),e.blockContentRotation!=null&&(t.blockContentRotation=e.blockContentRotation),e.blockContentRotationEnabled!=null&&(t.blockContentRotationEnabled=e.blockContentRotationEnabled),e.blockContentConnectionType!=null&&(t.blockContentConnectionType=e.blockContentConnectionType),e.scale!=null&&(t.scale=e.scale),e.overwritePropertyValue!=null&&(t.overwritePropertyValue=e.overwritePropertyValue),e.annotative!=null&&(t.annotative=e.annotative),e.breakGapSize!=null&&(t.breakGapSize=e.breakGapSize),e.textAttachmentDirection!=null&&(t.textAttachmentDirection=e.textAttachmentDirection),e.bottomTextAttachmentDirection!=null&&(t.bottomTextAttachmentDirection=e.bottomTextAttachmentDirection),e.topTextAttachmentDirection!=null&&(t.topTextAttachmentDirection=e.topTextAttachmentDirection),t.unknown2=e.unknown2,this.processCommonAttrs(e,t),t}convertLayerFilter(e){var o;const t=new r.AcDbLayerFilter;return(o=e.layerNames)!=null&&o.length&&(t.layerNames=e.layerNames),this.processCommonAttrs(e,t),t}convertLayerIndex(e){var o,n,i;const t=new r.AcDbLayerIndex;return e.timeStamp!=null&&(t.lastUpdatedAt=e.timeStamp,t.lastUpdatedAtU=e.timeStamp),(o=e.layerNames)!=null&&o.length&&(t.layerNames=e.layerNames),(n=e.idBufferIds)!=null&&n.length&&(t.idBufferIds=e.idBufferIds),(i=e.idBufferEntryCounts)!=null&&i.length&&(t.idBufferEntryCounts=e.idBufferEntryCounts),t.isUptoDate=!0,this.processCommonAttrs(e,t),t}convertScale(e){const t=new r.AcDbScale;return e.flag!=null&&(t.classVersion=e.flag),t.scaleName=e.name??"",t.paperUnits=e.paperUnits??1,t.drawingUnits=e.drawingUnits??1,t.isUnitScale=!!e.isUnitScale,this.processCommonAttrs(e,t),t}convertDictionaryVar(e){const t=new r.AcDbDictionaryVar;return e.schema!=null&&(t.schema=e.schema),t.value=e.value??e.strvalue??"",this.processCommonAttrs(e,t),t}convertMTextObjectContextData(e){const t=new r.AcDbMTextObjectContextData;return e.classVersion!=null&&(t.classVersion=e.classVersion),t.isDefault=!!e.isDefault,t.scaleId=e.scaleId??e.scaleHandle??"",e.attachment!=null&&(t.attachmentPoint=e.attachment),e.xAxisDir&&(t.direction=new r.AcGeVector3d(e.xAxisDir.x,e.xAxisDir.y,e.xAxisDir.z??0)),e.insertionPoint&&(t.insertionPoint=new r.AcGePoint3d(e.insertionPoint.x,e.insertionPoint.y,e.insertionPoint.z??0)),e.definedWidth!=null&&(t.definedWidth=e.definedWidth),e.definedHeight!=null&&(t.definedHeight=e.definedHeight),e.extentsWidth!=null&&(t.extentsWidth=e.extentsWidth),e.extentsHeight!=null&&(t.extentsHeight=e.extentsHeight),e.columnType!=null&&(t.columnType=e.columnType),this.processCommonAttrs(e,t),t}convertDimensionObjectContextData(e){const t=new r.AcDbDimensionObjectContextData;e.classVersion!=null&&(t.classVersion=e.classVersion),t.isDefault=!!e.isDefault,t.scaleId=e.scaleId??e.scaleHandle??"",t.blockName=e.blockName??e.name??"";const o=e.definitionPoint??e.defPt;o&&(t.definitionPoint=new r.AcGePoint3d(o.x,o.y,o.z??0));const n=e.dimLinePoint??e._11pt;return n&&(t.dimLinePoint=new r.AcGePoint3d(n.x,n.y,n.z??0)),this.processCommonAttrs(e,t),t}convertTextObjectContextData(e){const t=new r.AcDbTextObjectContextData;return this.applyAnnotScaleContextBase(e,t),e.horizontalMode!=null&&(t.horizontalMode=e.horizontalMode),e.rotation!=null&&(t.rotation=e.rotation),e.alignmentPoint&&(t.alignmentPoint=new r.AcGePoint3d(e.alignmentPoint.x,e.alignmentPoint.y,e.alignmentPoint.z??0)),e.position&&(t.position=new r.AcGePoint3d(e.position.x,e.position.y,e.position.z??0)),this.processCommonAttrs(e,t),t}convertHatchScaleContextData(e){const t=new r.AcDbHatchScaleContextData;this.applyAnnotScaleContextBase(e,t);const o=e.patternScale??e.scale;return o!=null&&o>0&&(t.patternScale=o),this.processCommonAttrs(e,t),t}convertBlkRefObjectContextData(e){const t=new r.AcDbBlkRefObjectContextData;this.applyAnnotScaleContextBase(e,t);const o=e.position??e.insertionPoint;o&&(t.position=new r.AcGePoint3d(o.x,o.y,o.z??0)),e.rotation!=null&&(t.rotation=e.rotation);const n=e.scaleX??e.xScale,i=e.scaleY??e.yScale,s=e.scaleZ??e.zScale;return n!=null&&(t.scaleX=n),i!=null&&(t.scaleY=i),s!=null&&(t.scaleZ=s),this.processCommonAttrs(e,t),t}convertLeaderObjectContextData(e){const t=new r.AcDbLeaderObjectContextData;return this.applyAnnotScaleContextBase(e,t),this.processCommonAttrs(e,t),t}convertMLeaderObjectContextData(e){const t=new r.AcDbMLeaderObjectContextData;this.applyAnnotScaleContextBase(e,t),e.contentScale!=null&&e.contentScale>0&&(t.contentScale=e.contentScale),e.textHeight!=null&&e.textHeight>0&&(t.textHeight=e.textHeight);const o=e.arrowheadSize??e.arrowSize;o!=null&&o>0&&(t.arrowheadSize=o);const n=e.textAnchor??e.landingPoint;return n&&(t.textAnchor=new r.AcGePoint3d(n.x,n.y,n.z??0)),this.processCommonAttrs(e,t),t}convertMTextAttributeObjectContextData(e){const t=new r.AcDbMTextAttributeObjectContextData;return e.classVersion!=null&&(t.classVersion=e.classVersion),t.isDefault=!!e.isDefault,t.scaleId=e.scaleId??e.scaleHandle??"",e.attachment!=null&&(t.attachmentPoint=e.attachment),e.xAxisDir&&(t.direction=new r.AcGeVector3d(e.xAxisDir.x,e.xAxisDir.y,e.xAxisDir.z??0)),e.insertionPoint&&(t.insertionPoint=new r.AcGePoint3d(e.insertionPoint.x,e.insertionPoint.y,e.insertionPoint.z??0)),e.definedWidth!=null&&(t.definedWidth=e.definedWidth),e.definedHeight!=null&&(t.definedHeight=e.definedHeight),e.extentsWidth!=null&&(t.extentsWidth=e.extentsWidth),e.extentsHeight!=null&&(t.extentsHeight=e.extentsHeight),e.columnType!=null&&(t.columnType=e.columnType),this.processCommonAttrs(e,t),t}convertXRecord(e){const t=new r.AcDbXrecord;return this.processCommonAttrs(e,t),e.extensionDictionary&&(t.extensionDictionary=e.extensionDictionary),t.data=new r.AcDbResultBuffer((e.data??[]).map(o=>({code:Number(o.code),value:o.value}))),t}convertGroup(e){const t=new r.AcDbGroup;this.processCommonAttrs(e,t),t.description=e.description??"",t.anonymous=!!e.unnamed,t.selectable=e.selectable!==!1;for(const o of e.objectHandles??[])o&&t.append(String(o));return t}applyAnnotScaleContextBase(e,t){e.classVersion!=null&&(t.classVersion=e.classVersion),t.isDefault=!!e.isDefault,t.scaleId=e.scaleId??e.scaleHandle??""}processCommonAttrs(e,t){t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}}const O="*MODEL_SPACE";class v extends r.AcDbDatabaseConverter{constructor(e={}){super(e),this.config.useWorker=!0,this.config.parserWorkerUrl||(this.config.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,t){const o=this.config,n=this.getParserWorkerTimeout(e,t);if(o.useWorker&&o.parserWorkerUrl){const i=r.acdbCreateWorkerApi({workerUrl:o.parserWorkerUrl,timeout:n,maxConcurrentWorkers:1}),s=await i.execute(e);return i.destroy(),r.AcDbOpenDatabaseError.throwOnWorkerParseFailure(s),s.data}else throw new Error("dwg converter can run in web worker only!")}processLineTypes(e,t){e.tables.LTYPE.entries.forEach(n=>{const i={name:n.name,description:n.description,standardFlag:n.standardFlag,totalPatternLength:n.totalPatternLength,pattern:n.pattern},s=new r.AcDbLinetypeTableRecord(i);this.processCommonTableEntryAttrs(n,s),t.tables.linetypeTable.add(s)})}processTextStyles(e,t){e.tables.STYLE.entries.forEach(n=>{const i={name:n.name,standardFlag:n.standardFlag,fixedTextHeight:n.fixedTextHeight,widthFactor:n.widthFactor,obliqueAngle:n.obliqueAngle,textGenerationFlag:n.textGenerationFlag,lastHeight:n.lastHeight,font:n.font,bigFont:n.bigFont,extendedFont:n.extendedFont},s=new r.AcDbTextStyleTableRecord(i);this.processCommonTableEntryAttrs(n,s),t.tables.textStyleTable.add(s)}),t.ensureTextStyleDefaults()}processDimStyles(e,t){e.tables.DIMSTYLE.entries.forEach(i=>{const s={name:i.name,ownerId:i.ownerHandle,dimpost:i.DIMPOST||"",dimapost:i.DIMAPOST||"",dimscale:i.DIMSCALE,dimasz:i.DIMASZ,dimexo:i.DIMEXO,dimdli:i.DIMDLI,dimexe:i.DIMEXE,dimrnd:i.DIMRND,dimdle:i.DIMDLE,dimtp:i.DIMTP,dimtm:i.DIMTM,dimtxt:i.DIMTXT,dimcen:i.DIMCEN,dimtsz:i.DIMTSZ,dimaltf:i.DIMALTF,dimlfac:i.DIMLFAC,dimtvp:i.DIMTVP,dimtfac:i.DIMTFAC,dimgap:i.DIMGAP,dimtfill:i.DIMTFILL===1||i.DIMTFILL===2?i.DIMTFILL:0,dimtfillclr:r.acdbNormalizeDimStyleColorNumber(i.DIMTFILLCLR),dimtxtdirection:i.DIMTXTDIRECTION===1?1:0,dimaltrnd:i.DIMALTRND,dimtol:i.DIMTOL==null||i.DIMTOL==0?0:1,dimlim:i.DIMLIM==null||i.DIMLIM==0?0:1,dimtih:i.DIMTIH==null||i.DIMTIH==0?0:1,dimtoh:i.DIMTOH==null||i.DIMTOH==0?0:1,dimse1:i.DIMSE1==null||i.DIMSE1==0?0:1,dimse2:i.DIMSE2==null||i.DIMSE2==0?0:1,dimtad:i.DIMTAD,dimzin:i.DIMZIN,dimazin:i.DIMAZIN,dimalt:i.DIMALT,dimaltd:i.DIMALTD,dimtofl:i.DIMTOFL,dimsah:i.DIMSAH,dimtix:i.DIMTIX,dimsoxd:i.DIMSOXD,dimclrd:r.acdbNormalizeDimStyleColorNumber(i.DIMCLRD),dimclre:r.acdbNormalizeDimStyleColorNumber(i.DIMCLRE),dimclrt:r.acdbNormalizeDimStyleColorNumber(i.DIMCLRT),dimadec:i.DIMADEC||0,dimunit:i.DIMUNIT||2,dimdec:i.DIMDEC,dimtdec:i.DIMTDEC,dimaltu:i.DIMALTU,dimalttd:i.DIMALTTD,dimaunit:i.DIMAUNIT,dimfrac:i.DIMFRAC,dimlunit:i.DIMLUNIT,dimdsep:i.DIMDSEP||".",dimtmove:i.DIMTMOVE||0,dimjust:i.DIMJUST,dimsd1:i.DIMSD1,dimsd2:i.DIMSD2,dimtolj:i.DIMTOLJ,dimtzin:i.DIMTZIN,dimaltz:i.DIMALTZ,dimalttz:i.DIMALTTZ,dimfit:i.DIMFIT||0,dimupt:i.DIMUPT,dimatfit:i.DIMATFIT,dimtxsty:this.resolveDimTextStyleName(e,i.DIMTXSTY),dimldrblk:this.resolveDimBlockName(e,i.DIMLDRBLK),dimblk:this.resolveDimBlockName(e,i.DIMBLK),dimblk1:this.resolveDimBlockName(e,i.DIMBLK1),dimblk2:this.resolveDimBlockName(e,i.DIMBLK2),dimlwd:i.DIMLWD,dimlwe:i.DIMLWE},c=new r.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(i,c),t.tables.dimStyleTable.add(c)});const n=e.dimStyleAnnotationScales;if(n)for(const[i,s]of Object.entries(n))t.setDimStyleAnnotationScale(i,s)}resolveDimTextStyleName(e,t){if(typeof t=="string"){const n=t.trim();if(n&&!/^[0-9]+$/.test(n)&&!/^[0-9A-F]+$/i.test(n))return n;if(n&&/[A-Z]/i.test(n)){const i=e.tables.STYLE.entries.find(s=>String(s.handle).toUpperCase()===n.toUpperCase());if(i!=null&&i.name)return i.name}}const o=typeof t=="number"?t:Number(t);if(Number.isFinite(o)&&o>0){const n=Math.trunc(o).toString(16).toUpperCase(),i=e.tables.STYLE.entries.find(s=>String(s.handle).toUpperCase()===n);if(i!=null&&i.name)return i.name}return r.DEFAULT_TEXT_STYLE}resolveDimBlockName(e,t){var s;const o=((s=e.tables.BLOCK_RECORD)==null?void 0:s.entries)??[],n=c=>{var a;return(a=o.find(u=>String(u.handle).toUpperCase()===c.toUpperCase()))==null?void 0:a.name};if(typeof t=="string"){const c=t.trim();if(!c||c===".")return"";if(!/^[0-9A-F]+$/i.test(c))return c;const a=o.find(u=>u.name.toUpperCase()===c.toUpperCase());if(a!=null&&a.name)return a.name;if(/[A-Z]/i.test(c))return n(c)??c}const i=typeof t=="number"?t:Number(t);return!Number.isFinite(i)||i<=0?"":n(Math.trunc(i).toString(16).toUpperCase())??""}processLayers(e,t){e.tables.LAYER.entries.forEach(n=>{const i=new r.AcCmColor;this.applyLibreLayerColor(i,n);const s=new r.AcDbLayerTableRecord({name:n.name,standardFlags:n.standardFlag,linetype:n.lineType,lineWeight:n.lineweight,isOff:n.off,color:i,isPlottable:n.plotFlag!=0});this.processCommonTableEntryAttrs(n,s),t.tables.layerTable.add(s)})}applyLibreLayerColor(e,t){const o=t.colorIndex,n=t.color;o!=null&&o>=1&&o<=255?e.colorIndex=o:o===0?e.colorIndex=0:n!=null&&Number.isFinite(n)?e.setRGBValue(n&16777215):e.colorIndex=256,t.colorName&&(e.colorName=t.colorName)}processViewports(e,t){e.tables.VPORT.entries.forEach(n=>{const i=new r.AcDbViewportTableRecord;n.circleSides&&(i.circleSides=n.circleSides),i.standardFlag=n.standardFlag,i.center.copy(n.center??r.VPORT_FALLBACK_CENTER_2D),i.lowerLeftCorner.copy(n.lowerLeftCorner??r.VPORT_FALLBACK_LLC),i.upperRightCorner.copy(n.upperRightCorner??r.VPORT_FALLBACK_URC),n.snapBasePoint&&i.snapBase.copy(n.snapBasePoint),n.snapRotationAngle&&(i.snapAngle=n.snapRotationAngle),n.snapSpacing&&i.snapIncrements.copy(n.snapSpacing),n.majorGridLines&&(i.gridMajor=n.majorGridLines),n.gridSpacing&&i.gridIncrements.copy(n.gridSpacing),n.backgroundObjectId&&(i.backgroundObjectId=n.backgroundObjectId),i.gsView.center.copy(n.center??r.VPORT_FALLBACK_CENTER_2D),i.gsView.viewDirectionFromTarget.copy(n.viewDirectionFromTarget??r.VPORT_FALLBACK_VIEW_DIR),i.gsView.viewTarget.copy(n.viewTarget??r.VPORT_FALLBACK_VIEW_TARGET),n.lensLength&&(i.gsView.lensLength=n.lensLength),n.frontClippingPlane&&(i.gsView.frontClippingPlane=n.frontClippingPlane),n.backClippingPlane&&(i.gsView.backClippingPlane=n.backClippingPlane),n.viewHeight&&(i.gsView.viewHeight=n.viewHeight);const s=n.aspectRatio;s!=null&&Number.isFinite(s)&&s>0&&(i.gsView.aspectRatio=s),n.viewTwistAngle&&(i.gsView.viewTwistAngle=n.viewTwistAngle),n.frozenLayers&&(i.gsView.frozenLayers=n.frozenLayers),n.styleSheet&&(i.gsView.styleSheet=n.styleSheet),n.renderMode&&(i.gsView.renderMode=n.renderMode),n.viewMode&&(i.gsView.viewMode=n.viewMode),n.ucsIconSetting&&(i.gsView.ucsIconSetting=n.ucsIconSetting),n.ucsOrigin&&i.gsView.ucsOrigin.copy(n.ucsOrigin),n.ucsXAxis&&i.gsView.ucsXAxis.copy(n.ucsXAxis),n.ucsYAxis&&i.gsView.ucsYAxis.copy(n.ucsYAxis),n.orthographicType&&(i.gsView.orthographicType=n.orthographicType),n.shadePlotSetting&&(i.gsView.shadePlotSetting=n.shadePlotSetting),n.shadePlotObjectId&&(i.gsView.shadePlotObjectId=n.shadePlotObjectId),n.visualStyleObjectId&&(i.gsView.visualStyleObjectId=n.visualStyleObjectId),n.isDefaultLightingOn&&(i.gsView.isDefaultLightingOn=n.isDefaultLightingOn),n.defaultLightingType&&(i.gsView.defaultLightingType=n.defaultLightingType),n.brightness&&(i.gsView.brightness=n.brightness),n.contrast&&(i.gsView.contrast=n.contrast),n.ambientColor&&(i.gsView.ambientColor=n.ambientColor),this.processCommonTableEntryAttrs(n,i),t.tables.viewportTable.add(i)})}processBlockTables(e,t){e.tables.BLOCK_RECORD.entries.forEach(n=>{let i=t.tables.blockTable.getAt(n.name);i||(i=new r.AcDbBlockTableRecord,i.name=n.name,i.ownerId=n.ownerHandle,i.layoutId=n.layout,i.flags=r.AcDbBlockTableRecord.sanitizeImportedFlags(n.flags??0),i.blockInsertUnits=n.insertionUnits,i.explodability=n.explodability,i.blockScaling=n.scalability,i.objectId=n.handle,t.tables.blockTable.add(i)),n.bmpPreview&&(i.previewIcon=r.acdbHexStringsToBytes([n.bmpPreview])),i.origin.copy(n.basePoint),!i.isModelSapce&&n.entities&&n.entities.length>0&&this.processEntitiesInBlock(n.entities,i)})}processBlocks(e,t){}async processEntitiesInBlock(e,t){const o=new S,n=e.length,i=[];for(let s=0;s<n;s++){const c=e[s],a=o.convert(c);a&&i.push(a)}t.appendEntity(i)}async processEntities(e,t,o,n,i){const s=new S;let c=[];e.tables.BLOCK_RECORD.entries.forEach(f=>{this.isModelSpace(f.name)&&(c=f.entities)});const a=c.length,u=new r.AcDbBatchProcessing(a,100-n.value,o);this.config.convertByEntityType&&(c=this.groupAndFlattenByType(c));const l=t.tables.blockTable.modelSpace;await u.processChunk(async(f,h)=>{const p=[];for(let A=f;A<h;A++){const b=c[A],d=s.convert(b);d&&p.push(d)}if(l.appendEntity(p),i){let A=n.value+h/a*(100-n.value);A>100&&(A=100),await i(A,"ENTITY","IN-PROGRESS")}})}processClasses(e,t){var o;(o=e.classes)!=null&&o.length&&(t.classes=e.classes.map(n=>({name:n.dxfName,cppClassName:n.cppName,appName:n.appName,proxyFlag:n.capabilitiesFlag,instanceCount:n.instanceCount,wasProxy:n.wasAProxyFlag,isEntity:n.isAnEntityFlag})))}processHeader(e,t){const o=e.thumbnailImage;o!=null&&o.length&&(t.thumbnailImage=o);const n=e.header;n.CECOLOR&&(n.CECOLOR.index>=0&&n.CECOLOR.index<=256?t.cecolor.colorIndex=n.CECOLOR.index:t.cecolor.setRGBValue(n.CECOLOR.rgb)),t.angbase=n.ANGBASE??0,t.angdir=n.ANGDIR??0,t.aunits=n.AUNITS??0,n.AUPREC!=null&&(t.auprec=n.AUPREC),n.LUNITS!=null&&(t.lunits=n.LUNITS),n.LUPREC!=null&&(t.luprec=n.LUPREC),n.UNITMODE!=null&&(t.unitmode=n.UNITMODE),n.MEASUREMENT!=null&&(t.measurement=n.MEASUREMENT),t.celtype=n.CELTYPE??r.ByLayer,t.celtscale=n.CELTSCALE??1,t.ltscale=n.LTSCALE??1,t.tilemode=n.TILEMODE??1,n.EXTMAX&&(t.extmax=n.EXTMAX),n.EXTMIN&&(t.extmin=n.EXTMIN),t.insunits=n.INSUNITS??1,t.pdmode=n.PDMODE??0,t.pdsize=n.PDSIZE??0,t.textstyle=n.TEXTSTYLE??r.DEFAULT_TEXT_STYLE,t.dimstyle=this.normalizeHeaderStringValue(n.DIMSTYLE)??r.DEFAULT_TEXT_STYLE;const i=this.normalizeHeaderStringValue(n.CMLEADERSTYLE)??r.DEFAULT_MLEADER_STYLE;t.cmleaderstyle=i}processCommonTableEntryAttrs(e,t){t.name=e.name,t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}processObjects(e,t){this.processScales(e,t),this.processDictionaryVars(e,t),this.processMTextObjectContextData(e,t),this.processTextObjectContextData(e,t),this.processDimensionObjectContextData(e,t),this.processHatchScaleContextData(e,t),this.processBlkRefObjectContextData(e,t),this.processLeaderObjectContextData(e,t),this.processMLeaderObjectContextData(e,t),this.processMTextAttributeObjectContextData(e,t),this.processXRecords(e,t),this.processGroups(e,t),this.processLayouts(e,t),this.processImageDefs(e,t),this.processLayerFilters(e,t),this.processLayerIndexes(e,t),this.processLayerFilterTree(e,t),this.processMLeaderStyles(e,t),this.processDynBlockMetadata(e,t),this.finishCannoscale(e,t),this.finishAnnoallvisible(e,t)}processDynBlockMetadata(e,t){const o=s=>s==null||s===""||s===0?"":String(s).trim().toUpperCase();for(const s of e.tables.BLOCK_RECORD.entries){const c=t.tables.blockTable.getAt(s.name);if(!c)continue;const a=s,u=r.acdbNormalizeExtensionDictionaryId(a.extensionDictionary??a.ownerDictionaryHardId??a.ownerDictionarySoftId);u&&(c.extensionDictionary=u)}const n=e.objects.DICTIONARY;if(!(n!=null&&n.length))return;const i=n.map(s=>{const c=[],a=s.entries??{};for(const u in a){const l=a[u];u&&l&&c.push({name:u,handle:o(String(l))})}return{handle:o(s.handle),ownerHandle:o(s.ownerHandle)||void 0,entries:c}});r.acdbImportDynBlockMetadata(t,{dictionaries:i,representationData:[]})}processLayerFilterTree(e,t){const o=e.objects.DICTIONARY,n=e.objects.XRECORD;if(!(o!=null&&o.length)||!(n!=null&&n.length))return;const i=u=>u?String(u).trim().toUpperCase():"",s=new Map;o.forEach(u=>{const l={},f=u.entries??{};for(const h in f){const p=f[h];h&&p&&(l[h]=i(String(p)))}s.set(i(u.handle),{handle:i(u.handle),ownerObjectId:i(u.ownerHandle),entries:l})});const c=new Map;n.forEach(u=>{c.set(i(u.handle),{handle:i(u.handle),ownerObjectId:i(u.ownerHandle),extensionDictionaryId:i(u.extensionDictionary),data:(u.data??[]).map(l=>({code:Number(l.code),value:l.value}))})});const a=r.acdbReadLayerFilterTree({dictionaries:s,xrecords:c});a.root.getNestedFilters().length>0&&(t.layerFilters=a)}processLayouts(e,t){const o=t.objects.layout;e.objects.LAYOUT.forEach(i=>{const s=new r.AcDbLayout;s.layoutName=i.layoutName,s.tabOrder=i.tabOrder;const c=t.tables.blockTable.newIterator();s.objectId=i.handle;for(const a of c)if(a.layoutId===s.objectId){s.blockTableRecordId=a.objectId;break}s.blockTableRecordId||i.layoutName==="Model"&&(s.blockTableRecordId=t.tables.blockTable.modelSpace.objectId),s.limits.min.copy(i.minLimit),s.limits.max.copy(i.maxLimit),s.extents.min.copy(i.minExtent),s.extents.max.copy(i.maxExtent),i.viewportId&&s.viewportArray.push(i.viewportId),this.processCommonObjectAttrs(i,s),o.setAt(s.layoutName,s)})}processImageDefs(e,t){const o=t.objects.imageDefinition;e.objects.IMAGEDEF.forEach(i=>{const s=new r.AcDbRasterImageDef;s.sourceFileName=i.fileName,this.processCommonObjectAttrs(i,s),o.setAt(s.objectId,s)})}processLayerFilters(e,t){const o=e.objects.LAYER_FILTER;if(!(o!=null&&o.length))return;const n=t.objects.layerFilter,i=new D;o.forEach(s=>{const c=i.convertLayerFilter(s);n.setAt(c.objectId,c)})}processLayerIndexes(e,t){const o=e.objects.LAYER_INDEX;if(!(o!=null&&o.length))return;const n=t.objects.layerIndex,i=new D;o.forEach(s=>{const c=i.convertLayerIndex(s);n.setAt(c.objectId,c)})}processMLeaderStyles(e,t){const o=e.objects.MLEADERSTYLE;if(!(o!=null&&o.length))return;const n=t.objects.mleaderStyle,i=new D;o.forEach(s=>{const c=i.convertMLeaderStyle(s);n.setAt(c.objectId,c)})}processScales(e,t){const o=this.optionalObjectArray(e,"SCALE");if(!(o!=null&&o.length))return;const n=t.objects.scale,i=new D;for(const s of o){const c=i.convertScale(s),a=c.scaleName||c.objectId;a&&n.setAt(a,c)}}processDictionaryVars(e,t){const o=this.optionalObjectArray(e,"DICTIONARYVAR");if(!(o!=null&&o.length))return;const n=t.objects.dictionaryVar,i=new D;for(const s of o){const c=i.convertDictionaryVar(s);c.objectId&&n.setAt(c.objectId,c)}}processMTextObjectContextData(e,t){const o=this.optionalObjectArray(e,"MTEXTOBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_MTEXTOBJECTCONTEXTDATA_CLASS");if(!(o!=null&&o.length))return;const n=t.objects.objectContextData,i=new D;for(const s of o){const c=i.convertMTextObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processDimensionObjectContextData(e,t){const o=["ALDIMOBJECTCONTEXTDATA","ACDB_ALDIMOBJECTCONTEXTDATA_CLASS","ANGDIMOBJECTCONTEXTDATA","ACDB_ANGDIMOBJECTCONTEXTDATA_CLASS","ARCDIMOBJECTCONTEXTDATA","ACDB_ARCDIMOBJECTCONTEXTDATA_CLASS","DMDIMOBJECTCONTEXTDATA","ACDB_DMDIMOBJECTCONTEXTDATA_CLASS","ORDDIMOBJECTCONTEXTDATA","ACDB_ORDDIMOBJECTCONTEXTDATA_CLASS","RADDIMOBJECTCONTEXTDATA","ACDB_RADDIMOBJECTCONTEXTDATA_CLASS","RADIMOBJECTCONTEXTDATA","ACDB_RADIMOBJECTCONTEXTDATA_CLASS","RADDIMLGCOBJECTCONTEXTDATA","ACDB_RADDIMLGCOBJECTCONTEXTDATA_CLASS"],n=new D,i=t.objects.objectContextData;for(const s of o){const c=this.optionalObjectArray(e,s);if(c!=null&&c.length)for(const a of c){const u=n.convertDimensionObjectContextData(a);u.objectId&&i.setAt(u.objectId,u)}}}processTextObjectContextData(e,t){const o=this.optionalObjectArray(e,"TEXTOBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_TEXTOBJECTCONTEXTDATA_CLASS");if(!(o!=null&&o.length))return;const n=t.objects.objectContextData,i=new D;for(const s of o){const c=i.convertTextObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processHatchScaleContextData(e,t){const o=this.optionalObjectArray(e,"HATCHSCALECONTEXTDATA")??this.optionalObjectArray(e,"ACDB_HATCHSCALECONTEXTDATA_CLASS");if(!(o!=null&&o.length))return;const n=t.objects.objectContextData,i=new D;for(const s of o){const c=i.convertHatchScaleContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processBlkRefObjectContextData(e,t){const o=this.optionalObjectArray(e,"BLKREFOBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_BLKREFOBJECTCONTEXTDATA_CLASS");if(!(o!=null&&o.length))return;const n=t.objects.objectContextData,i=new D;for(const s of o){const c=i.convertBlkRefObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processLeaderObjectContextData(e,t){const o=this.optionalObjectArray(e,"LEADEROBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_LEADEROBJECTCONTEXTDATA_CLASS");if(!(o!=null&&o.length))return;const n=t.objects.objectContextData,i=new D;for(const s of o){const c=i.convertLeaderObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processMLeaderObjectContextData(e,t){const o=this.optionalObjectArray(e,"MLEADEROBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_MLEADEROBJECTCONTEXTDATA_CLASS");if(!(o!=null&&o.length))return;const n=t.objects.objectContextData,i=new D;for(const s of o){const c=i.convertMLeaderObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processMTextAttributeObjectContextData(e,t){const o=this.optionalObjectArray(e,"MTEXTATTRIBUTEOBJECTCONTEXTDATA")??this.optionalObjectArray(e,"ACDB_MTEXTATTRIBUTEOBJECTCONTEXTDATA_CLASS");if(!(o!=null&&o.length))return;const n=t.objects.objectContextData,i=new D;for(const s of o){const c=i.convertMTextAttributeObjectContextData(s);c.objectId&&n.setAt(c.objectId,c)}}processXRecords(e,t){const o=e.objects.XRECORD;if(!(o!=null&&o.length))return;const n=t.objects.xrecord,i=new D;for(const s of o){const c=i.convertXRecord(s);c.objectId&&n.setAt(c.objectId,c)}}processGroups(e,t){const o=e.objects.GROUP??this.optionalObjectArray(e,"GROUP");if(!(o!=null&&o.length))return;const n=t.objects.group,i=new D,s=new Map,c=l=>l==null||l===""||l===0?"":String(l).trim().toUpperCase();for(const l of o){const f=i.convertGroup(l);f.objectId&&(n.setAt(f.objectId,f),s.set(c(f.objectId),f))}let a="";for(const l of e.objects.DICTIONARY??[]){const f=l.entries??{};if(f.ACAD_GROUP){a=c(f.ACAD_GROUP);break}}if(!a)return;const u=(e.objects.DICTIONARY??[]).find(l=>c(l.handle)===a);if(u!=null&&u.entries)for(const[l,f]of Object.entries(u.entries)){const h=c(f),p=s.get(h);if(!p||!l)continue;let A;for(const[d,y]of n.entries())if(c(y.objectId)===h){A=d;break}const b=n.getAt(l);b&&b!==p||(A!=null&&A!==l?(n.remove(A),n.setAt(l,p)):b||n.setAt(l,p),p.name=l)}}finishCannoscale(e,t){const o=s=>{const c=s.getAt("CANNOSCALE");return c instanceof r.AcDbDictionaryVar&&c.value?(t.cannoscale=c.value,!0):!1},n=t.objects.dictionary.getAt("AcDbVariableDictionary");if(n instanceof r.AcDbDictionary&&o(n))return;const i=s=>s==null||s===""||s===0?"":String(s).trim().toUpperCase();for(const s of e.objects.DICTIONARY??[]){const a=(s.entries??{}).AcDbVariableDictionary;if(!a)continue;const u=t.getObjectById(i(a));if(u instanceof r.AcDbDictionary&&o(u)){try{t.objects.dictionary.getAt("AcDbVariableDictionary")||t.objects.dictionary.setAt("AcDbVariableDictionary",u)}catch{}return}}}finishAnnoallvisible(e,t){const o=s=>{const c=s.getAt("ANNOALLVISIBLE");if(!(c instanceof r.AcDbDictionaryVar)||c.value==null)return!1;const a=String(c.value).trim();return t.annoallvisible=a!=="0"&&a.toLowerCase()!=="false",!0},n=t.objects.dictionary.getAt("AcDbVariableDictionary");if(n instanceof r.AcDbDictionary&&o(n))return;const i=s=>s==null||s===""||s===0?"":String(s).trim().toUpperCase();for(const s of e.objects.DICTIONARY??[]){const a=(s.entries??{}).AcDbVariableDictionary;if(!a)continue;const u=t.getObjectById(i(a));if(u instanceof r.AcDbDictionary&&o(u))return}}optionalObjectArray(e,t){const n=e.objects[t];return Array.isArray(n)?n:void 0}processCommonObjectAttrs(e,t){t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}groupAndFlattenByType(e){const t={},o=[];for(const i of e)t[i.type]||(t[i.type]=[],o.push(i.type)),t[i.type].push(i);const n=[];for(const i of o){const s=t[i];for(let c=0;c<s.length;c++)n.push(s[c])}return n}isModelSpace(e){return e&&e.toUpperCase()==O}normalizeHeaderStringValue(e){if(typeof e!="string")return;const t=e.trim();return t.length>0?t:void 0}}T.AcDbLibreDwgConverter=v,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));