@mlightcad/libredwg-converter 3.10.0 → 3.10.2

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(D,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(D=typeof globalThis<"u"?globalThis:D||self,r(D["libredwg-converter"]={},D.dataModel))})(this,function(D,r){"use strict";class x{convert(e){const t=this.createEntity(e);return t&&this.processCommonAttrs(e,t),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=="SHAPE"?this.convertShape(e):e.type=="SOLID"?this.convertSolid(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):null}convertProxyEntity(e){const t=new r.AcDbProxyEntity;if(t.proxyEntityClassId=e.proxyEntityClassId,e.originalDxfName&&(t.originalDxfName=e.originalDxfName),e.objectDrawingFormat!=null&&(t.graphicsMetafileType=e.objectDrawingFormat),e.applicationEntityClassId!=null&&(t.originalClassName=String(e.applicationEntityClassId)),e.graphicsData){const o=r.hexStringsToBytes([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.transformOcsPointToWcs(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.transformOcsPointToWcs(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.transformOcsPointToWcs(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){const t=new r.AcDbTrace;return t.setPointAt(0,{...e.corner1,z:0}),t.setPointAt(1,{...e.corner2,z:0}),t.setPointAt(2,{...e.corner3,z:0}),t.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),t.thickness=e.thickness,t}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)}),t}convertPolyline2d(e){const t=!!(e.flag&1),o=!!(e.flag&16),n=!!(e.flag&64),i=!!(e.flag&32),s=[],d=[],c=[];if(e.vertices.map(a=>{if(!(a.flag&16))if(n&&a.flag&128)if(a.flag&64)s.push({x:a.x,y:a.y,z:a.z}),d.push(a.bulge??0);else{const u=[];a.polyfaceIndex0!=null&&a.polyfaceIndex0!=0&&u.push(Math.abs(a.polyfaceIndex0)-1),a.polyfaceIndex1!=null&&a.polyfaceIndex1!=0&&u.push(Math.abs(a.polyfaceIndex1)-1),a.polyfaceIndex2!=null&&a.polyfaceIndex2!=0&&u.push(Math.abs(a.polyfaceIndex2)-1),a.polyfaceIndex3!=null&&a.polyfaceIndex3!=0&&u.push(Math.abs(a.polyfaceIndex3)-1),u.length>=3&&c.push(u)}else s.push({x:a.x,y:a.y,z:a.z}),d.push(a.bulge??0)}),o){const a=e.meshMVertexCount??2,u=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(a,u,s,t,i)}else{if(n)return new r.AcDbPolyFaceMesh(s,c);{let a=r.AcDbPoly2dType.SimplePoly;return e.flag&2?a=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?a=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(a=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(a,s,0,t,e.startWidth,e.endWidth,d)}}}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.isSolidFill=e.solidFill==1,t.hatchStyle=e.hatchStyle,t.patternName=e.patternName,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 d=i,c=new r.AcGePolyline2d;c.closed=d.isClosed,d.vertices.forEach((a,u)=>{c.addVertexAt(u,{x:a.x,y:a.y,bulge:a.bulge})}),t.add(c)}else{const d=i,c=[];d.edges.forEach(u=>{if(u!=null){if(u.type==1){const l=u;c.push(new r.AcGeLine2d(l.start,l.end))}else if(u.type==2){const l=u;c.push(new r.AcGeCircArc2d(l.center,l.radius,l.startAngle,l.endAngle,!l.isCCW))}else if(u.type==3){const l=u;new r.AcGeVector2d().subVectors(l.end,l.center);const h=Math.sqrt(Math.pow(l.end.x,2)+Math.pow(l.end.y,2)),f=h*l.lengthOfMinorAxis;let A=l.startAngle,g=l.endAngle;const L=Math.atan2(l.end.y,l.end.x);l.isCCW||(A=Math.PI*2-A,g=Math.PI*2-g),c.push(new r.AcGeEllipseArc2d({...l.center,z:0},h,f,A,g,!l.isCCW,L))}else if(u.type==4){const l=r.AcGeSpline3d.fromDwgSplineEdge(u);l&&c.push(l)}}});const a=r.AcGeLoop2d.buildFromEdges(c);a.length==0&&c.length>0?t.add(new r.AcGeLoop2d(c)):a.forEach(u=>t.add(u))}}),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 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;return e.endPoint&&!o?t.alignmentPoint.copy(e.endPoint):t.alignmentPoint.copy(e.startPoint),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,t}convertMText(e){const t=new r.AcDbMText;return 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,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.isSplined=e.isSpline,t.dimensionStyle=e.styleName,t.annoType=e.leaderCreationFlag,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 C,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(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=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,d=e.contentType??(s?r.AcDbMLeaderContentType.MTextContent:e.blockContent?r.AcDbMLeaderContentType.BlockContent:r.AcDbMLeaderContentType.NoneContent);t.contentType=d;const c=this.readPoint(o,["normal","extrusionDirection"]);c&&(t.normal=c);const a=this.readString(i??{},["styleName","textStyleName","textStyle"])??this.readString(o,["textStyleName","textStyle","styleName"]);a&&(t.textStyleName=a);const u=this.readPositiveNumber(i??{},["textHeight","height"])??this.readPositiveNumber(o,["textHeight","mtextHeight","textContentHeight"])??this.readPositiveNumber(o,["arrowheadSize","contentScale"]);u!=null&&(t.textHeight=u);const l=this.readPositiveNumber(i??{},["textWidth","width"])??this.readPositiveNumber(o,["textWidth","mtextWidth","textContentWidth"]);l!=null&&(t.textWidth=l),t.textLineSpacingFactor=this.readNumber(i??{},["lineSpacingFactor","textLineSpacingFactor"])??this.readNumber(o,["textLineSpacingFactor"])??t.textLineSpacingFactor;const b=this.readNumber(i??{},["textRotation","rotation"])??this.readNumber(o,["textRotation","mtextRotation","textContentRotation"]);b!=null&&(t.textRotation=b);const h=this.readPoint(o,["textDirection","mtextDirection","textDirectionVector"]);h&&(t.textDirection=h);const f=this.readNumber(o,["textAttachmentPoint","attachmentPoint"]);f!=null&&f!==0&&(t.textAttachmentPoint=f);const A=e.textAttachmentDirection;A!=null&&(t.textAttachmentDirection=A);const g=this.readNumber(o,["textDrawingDirection","drawingDirection"]);g!=null&&(t.textDrawingDirection=g);const L=typeof n=="string"?n:this.readString(i??{},["text","contents"])??this.readString(o,["text","contents","mtext"]),y=this.readPoint(i??{},["anchorPoint","textAnchor","textLocation","textPosition","textAnchorPoint"])??this.readPoint(o,["textAnchor","textLocation","textPosition","textAnchorPoint","contentBasePosition"]);if(L!=null&&y&&(t.mtextContent={text:L,anchorPoint:y}),e.blockContent){const p=e.blockContent,S=e.blockContent.blockContentId;if(this.isValidHandleId(S)){const m=this.readMLeaderEntityColor(p,["color"]);t.blockContent={blockContentId:S,normal:this.readPoint(p,["normal"]),position:e.blockContent.position,scale:this.readPoint(p,["scale"]),rotation:this.readNumber(p,["rotation"]),color:m,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(C=this.readMLeaderLeaders(o))==null||C.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(o))==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,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,d=t.subDefinitionPoint2??n??o;if(!o||!t.name)return null;const c=new r.AcDb3PointAngularDimension(i,s,d,o);return this.processDimensionCommonAttrs(e,c),c}else if(e.subclassMarker=="AcDbOrdinateDimension"){const t=e,o=new r.AcDbOrdinateDimension(t.subDefinitionPoint1,t.subDefinitionPoint2);return 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}convertViewport(e){const t=new r.AcDbViewport;return 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,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.alignmentPoint.copy(o.startPoint),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,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.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}processCommonAttrs(e,t){if(t.layer=e.layer||"0",t.objectId=e.handle,e.ownerBlockRecordSoftId!=null&&(t.ownerId=e.ownerBlockRecordSoftId),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 o=new r.AcCmColor;e.color!=null&&o.setRGBValue(e.color),e.colorIndex!=null&&(e.color==null||e.colorIndex===7)&&(o.colorIndex=e.colorIndex),e.colorName&&(o.colorName=e.colorName),t.color=o}if(e.isVisible!=null&&(t.visibility=e.isVisible),e.transparency!=null){const o=new r.AcCmTransparency;o.method=e.transparencyType,(o.isByBlock||o.isByBlock)&&(o.alpha=e.transparency),t.transparency=o}}convertMLeaderEntityColor(e){return r.decodeMLeaderStyleRawColor(e)}readMLeaderEntityColor(e,t){for(const o of t){const n=e[o];if(typeof n=="number"&&Number.isFinite(n))return r.decodeMLeaderStyleRawColor(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,d=Array.isArray(s)?s.reduce((f,A)=>{const g=this.readMLeaderLine(A);return g&&f.push(g),f},[]):void 0,c={},a=this.readPoint(i,["lastLeaderLinePoint"]),u=this.readPoint(i,["doglegVector"]),l=this.readNumber(i,["doglegLength"]),b=this.readMLeaderBreaks(i.breaks),h=this.readNumber(i,["leaderBranchIndex"]);a&&(c.lastLeaderLinePoint=a),i.lastLeaderLinePointSet!=null&&(c.lastLeaderLinePointSet=this.readBoolean(i,["lastLeaderLinePointSet"])),u&&(c.doglegVector=u),i.doglegVectorSet!=null&&(c.doglegVectorSet=this.readBoolean(i,["doglegVectorSet"])),l!=null&&(c.doglegLength=l),b&&(c.breaks=b),h!=null&&(c.leaderBranchIndex=h),d&&(c.leaderLines=d),o.push(c)}),o}readMLeaderLine(e){if(!e||typeof e!="object")return;const t=e,o=t.vertices,n=Array.isArray(o)?o.filter(c=>this.isPointLike(c)):[],i=this.readMLeaderBreaks(t.breaks),s=Array.isArray(t.breakPointIndexes)?t.breakPointIndexes.filter(c=>typeof c=="number"):void 0,d=this.readNumber(t,["leaderLineIndex"]);return n.length>0||i&&i.length>0?{vertices:n,breakPointIndexes:s,leaderLineIndex:d,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"]),d=this.readNumber(n,["index"]);if(!i||!s)return;const c={start:i,end:s};return d!=null&&(c.index=d),c}).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 I{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.decodeMLeaderStyleRawColor(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.decodeMLeaderStyleRawColor(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.decodeMLeaderStyleRawColor(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}processCommonAttrs(e,t){t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}}const E="*MODEL_SPACE";class w 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.createWorkerApi({workerUrl:o.parserWorkerUrl,timeout:n,maxConcurrentWorkers:1}),s=await i.execute(e);if(i.destroy(),s.success)return s.data;throw new Error(`Failed to parse drawing due to error: '${s.error}'`)}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){var o;const t=new Map;return e.tables.BLOCK_RECORD.entries.forEach(n=>{t.set(n.name,n)}),new r.AcDbFontNameCollector({styles:e.tables.STYLE.entries.map(n=>({name:n.name,font:n.font,bigFont:n.bigFont,extendedFont:n.extendedFont,standardFlag:n.standardFlag})),textStyleVar:((o=e.header)==null?void 0:o.TEXTSTYLE)??r.DEFAULT_TEXT_STYLE}).collect(e.entities,{getEntityFontInfo:n=>{if(n.type=="MTEXT"){const i=n;return{styleName:i.styleName,formattedText:i.text,resolveStyle:!0}}if(n.type=="TEXT"||n.type=="ATTRIB")return{styleName:n.styleName,resolveStyle:!0};if(n.type=="SHAPE")return{styleName:n.styleName,resolveStyle:!0};if(n.type=="MULTILEADER"||n.type=="MLEADER"){const i=n,s=typeof i.textContent=="string"?i.textContent:"";return{styleName:typeof i.textStyleName=="string"?i.textStyleName:typeof i.styleName=="string"?i.styleName:void 0,formattedText:s,resolveStyle:!0}}return n.type=="INSERT"?{blockName:n.name}:null},getBlockEntities:n=>{var i;return(i=t.get(n))==null?void 0:i.entities}})}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(n=>{const i={name:n.name,ownerId:n.ownerHandle,dimpost:n.DIMPOST||"",dimapost:n.DIMAPOST||"",dimscale:n.DIMSCALE,dimasz:n.DIMASZ,dimexo:n.DIMEXO,dimdli:n.DIMDLI,dimexe:n.DIMEXE,dimrnd:n.DIMRND,dimdle:n.DIMDLE,dimtp:n.DIMTP,dimtm:n.DIMTM,dimtxt:n.DIMTXT,dimcen:n.DIMCEN,dimtsz:n.DIMTSZ,dimaltf:n.DIMALTF,dimlfac:n.DIMLFAC,dimtvp:n.DIMTVP,dimtfac:n.DIMTFAC,dimgap:n.DIMGAP,dimaltrnd:n.DIMALTRND,dimtol:n.DIMTOL==null||n.DIMTOL==0?0:1,dimlim:n.DIMLIM==null||n.DIMLIM==0?0:1,dimtih:n.DIMTIH==null||n.DIMTIH==0?0:1,dimtoh:n.DIMTOH==null||n.DIMTOH==0?0:1,dimse1:n.DIMSE1==null||n.DIMSE1==0?0:1,dimse2:n.DIMSE2==null||n.DIMSE2==0?0:1,dimtad:n.DIMTAD,dimzin:n.DIMZIN,dimazin:n.DIMAZIN,dimalt:n.DIMALT,dimaltd:n.DIMALTD,dimtofl:n.DIMTOFL,dimsah:n.DIMSAH,dimtix:n.DIMTIX,dimsoxd:n.DIMSOXD,dimclrd:n.DIMCLRD,dimclre:n.DIMCLRE,dimclrt:n.DIMCLRT,dimadec:n.DIMADEC||0,dimunit:n.DIMUNIT||2,dimdec:n.DIMDEC,dimtdec:n.DIMTDEC,dimaltu:n.DIMALTU,dimalttd:n.DIMALTTD,dimaunit:n.DIMAUNIT,dimfrac:n.DIMFRAC,dimlunit:n.DIMLUNIT,dimdsep:n.DIMDSEP||".",dimtmove:n.DIMTMOVE||0,dimjust:n.DIMJUST,dimsd1:n.DIMSD1,dimsd2:n.DIMSD2,dimtolj:n.DIMTOLJ,dimtzin:n.DIMTZIN,dimaltz:n.DIMALTZ,dimalttz:n.DIMALTTZ,dimfit:n.DIMFIT||0,dimupt:n.DIMUPT,dimatfit:n.DIMATFIT,dimtxsty:r.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:n.DIMBLK||"",dimblk1:n.DIMBLK1||"",dimblk2:n.DIMBLK2||"",dimlwd:n.DIMLWD,dimlwe:n.DIMLWE},s=new r.AcDbDimStyleTableRecord(i);this.processCommonTableEntryAttrs(n,s),t.tables.dimStyleTable.add(s)})}processLayers(e,t){e.tables.LAYER.entries.forEach(n=>{const i=new r.AcCmColor;i.colorIndex=n.colorIndex;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)})}processViewports(e,t){e.tables.VPORT.entries.forEach(n=>{const i=new r.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(n,i),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),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.objectId=n.handle,i.name=n.name,i.ownerId=n.ownerHandle,i.layoutId=n.layout,i.blockInsertUnits=n.insertionUnits,i.explodability=n.explodability,i.blockScaling=n.scalability,n.bmpPreview&&(i.bmpPreview=n.bmpPreview),t.tables.blockTable.add(i)),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 x,n=e.length,i=[];for(let s=0;s<n;s++){const d=e[s],c=o.convert(d);c&&i.push(c)}t.appendEntity(i)}async processEntities(e,t,o,n,i){const s=new x;let d=[];e.tables.BLOCK_RECORD.entries.forEach(l=>{this.isModelSpace(l.name)&&(d=l.entities)});const c=d.length,a=new r.AcDbBatchProcessing(c,100-n.value,o);this.config.convertByEntityType&&(d=this.groupAndFlattenByType(d));const u=t.tables.blockTable.modelSpace;await a.processChunk(async(l,b)=>{const h=[];for(let f=l;f<b;f++){const A=d[f],g=s.convert(A);g&&h.push(g)}if(u.appendEntity(h),i){let f=n.value+b/c*(100-n.value);f>100&&(f=100),await i(f,"ENTITY","IN-PROGRESS")}})}processHeader(e,t){const o=e.header;o.CECOLOR&&(o.CECOLOR.index>=0&&o.CECOLOR.index<=256?t.cecolor.colorIndex=o.CECOLOR.index:t.cecolor.setRGBValue(o.CECOLOR.rgb)),t.angbase=o.ANGBASE??0,t.angdir=o.ANGDIR??0,t.aunits=o.AUNITS??0,o.AUPREC!=null&&(t.auprec=o.AUPREC),o.LUNITS!=null&&(t.lunits=o.LUNITS),o.LUPREC!=null&&(t.luprec=o.LUPREC),o.UNITMODE!=null&&(t.unitmode=o.UNITMODE),o.MEASUREMENT!=null&&(t.measurement=o.MEASUREMENT),t.celtype=o.CELTYPE??r.ByLayer,t.celtscale=o.CELTSCALE??1,t.ltscale=o.LTSCALE??1,o.EXTMAX&&(t.extmax=o.EXTMAX),o.EXTMIN&&(t.extmin=o.EXTMIN),t.insunits=o.INSUNITS??1,t.pdmode=o.PDMODE??0,t.pdsize=o.PDSIZE??0,t.textstyle=o.TEXTSTYLE??r.DEFAULT_TEXT_STYLE;const n=this.normalizeHeaderStringValue(o.CMLEADERSTYLE)??r.DEFAULT_MLEADER_STYLE;t.cmleaderstyle=n}processCommonTableEntryAttrs(e,t){t.name=e.name,t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}processObjects(e,t){this.processLayouts(e,t),this.processImageDefs(e,t),this.processMLeaderStyles(e,t)}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 d=t.tables.blockTable.newIterator();s.objectId=i.handle;for(const c of d)if(c.layoutId===s.objectId){s.blockTableRecordId=c.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)})}processMLeaderStyles(e,t){const o=e.objects.MLEADERSTYLE;if(!(o!=null&&o.length))return;const n=t.objects.mleaderStyle,i=new I;o.forEach(s=>{const d=i.convertMLeaderStyle(s);n.setAt(d.objectId,d)})}processCommonObjectAttrs(e,t){t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}groupAndFlattenByType(e){const t={},o=[];for(const n of e)t[n.type]||(t[n.type]=[],o.push(n.type)),t[n.type].push(n);return o.flatMap(n=>t[n])}isModelSpace(e){return e&&e.toUpperCase()==E}normalizeHeaderStringValue(e){if(typeof e!="string")return;const t=e.trim();return t.length>0?t:void 0}}D.AcDbLibreDwgConverter=w,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
1
+ (function(D,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(D=typeof globalThis<"u"?globalThis:D||self,r(D["libredwg-converter"]={},D.dataModel))})(this,function(D,r){"use strict";class L{convert(e){const t=this.createEntity(e);return t&&this.processCommonAttrs(e,t),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=="SHAPE"?this.convertShape(e):e.type=="SOLID"?this.convertSolid(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):null}convertProxyEntity(e){const t=new r.AcDbProxyEntity;if(t.proxyEntityClassId=e.proxyEntityClassId,e.originalDxfName&&(t.originalDxfName=e.originalDxfName),e.objectDrawingFormat!=null&&(t.graphicsMetafileType=e.objectDrawingFormat),e.applicationEntityClassId!=null&&(t.originalClassName=String(e.applicationEntityClassId)),e.graphicsData){const o=r.hexStringsToBytes([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.transformOcsPointToWcs(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.transformOcsPointToWcs(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.transformOcsPointToWcs(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){const t=new r.AcDbTrace;return t.setPointAt(0,{...e.corner1,z:0}),t.setPointAt(1,{...e.corner2,z:0}),t.setPointAt(2,{...e.corner3,z:0}),t.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),t.thickness=e.thickness,t}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)}),t}convertPolyline2d(e){const t=!!(e.flag&1),o=!!(e.flag&16),n=!!(e.flag&64),i=!!(e.flag&32),s=[],f=[],c=[];if(e.vertices.map(a=>{if(!(a.flag&16))if(n&&a.flag&128)if(a.flag&64)s.push({x:a.x,y:a.y,z:a.z}),f.push(a.bulge??0);else{const u=[];a.polyfaceIndex0!=null&&a.polyfaceIndex0!=0&&u.push(Math.abs(a.polyfaceIndex0)-1),a.polyfaceIndex1!=null&&a.polyfaceIndex1!=0&&u.push(Math.abs(a.polyfaceIndex1)-1),a.polyfaceIndex2!=null&&a.polyfaceIndex2!=0&&u.push(Math.abs(a.polyfaceIndex2)-1),a.polyfaceIndex3!=null&&a.polyfaceIndex3!=0&&u.push(Math.abs(a.polyfaceIndex3)-1),u.length>=3&&c.push(u)}else s.push({x:a.x,y:a.y,z:a.z}),f.push(a.bulge??0)}),o){const a=e.meshMVertexCount??2,u=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(a,u,s,t,i)}else{if(n)return new r.AcDbPolyFaceMesh(s,c);{let a=r.AcDbPoly2dType.SimplePoly;return e.flag&2?a=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?a=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(a=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(a,s,0,t,e.startWidth,e.endWidth,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.isSolidFill=e.solidFill==1,t.hatchStyle=e.hatchStyle,t.patternName=e.patternName,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 f=i,c=new r.AcGePolyline2d;c.closed=f.isClosed,f.vertices.forEach((a,u)=>{c.addVertexAt(u,{x:a.x,y:a.y,bulge:a.bulge})}),t.add(c)}else{const f=i,c=[];f.edges.forEach(u=>{if(u!=null){if(u.type==1){const l=u;c.push(new r.AcGeLine2d(l.start,l.end))}else if(u.type==2){const l=u;c.push(new r.AcGeCircArc2d(l.center,l.radius,l.startAngle,l.endAngle,!l.isCCW))}else if(u.type==3){const l=u;new r.AcGeVector2d().subVectors(l.end,l.center);const h=Math.sqrt(Math.pow(l.end.x,2)+Math.pow(l.end.y,2)),p=h*l.lengthOfMinorAxis;let A=l.startAngle,g=l.endAngle;const x=Math.atan2(l.end.y,l.end.x);l.isCCW||(A=Math.PI*2-A,g=Math.PI*2-g),c.push(new r.AcGeEllipseArc2d({...l.center,z:0},h,p,A,g,!l.isCCW,x))}else if(u.type==4){const l=r.AcGeSpline3d.fromDwgSplineEdge(u);l&&c.push(l)}}});const a=r.AcGeLoop2d.buildFromEdges(c);a.length==0&&c.length>0?t.add(new r.AcGeLoop2d(c)):a.forEach(u=>t.add(u))}}),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 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;return e.endPoint&&!o?t.alignmentPoint.copy(e.endPoint):t.alignmentPoint.copy(e.startPoint),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,t}convertMText(e){const t=new r.AcDbMText;return 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.extentsWidth!=null&&e.extentsWidth>0&&(t.extentsWidth=e.extentsWidth),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 C,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(d=>({...d})):[],t.blockAttributes=e.blockAttributes?e.blockAttributes.map(d=>({...d})):[],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,f=e.contentType??(s?r.AcDbMLeaderContentType.MTextContent:e.blockContent?r.AcDbMLeaderContentType.BlockContent:r.AcDbMLeaderContentType.NoneContent);t.contentType=f;const c=this.readPoint(o,["normal","extrusionDirection"]);c&&(t.normal=c);const a=this.readString(i??{},["styleName","textStyleName","textStyle"])??this.readString(o,["textStyleName","textStyle","styleName"]);a&&(t.textStyleName=a);const u=this.readPositiveNumber(i??{},["textHeight","height"])??this.readPositiveNumber(o,["textHeight","mtextHeight","textContentHeight"])??this.readPositiveNumber(o,["arrowheadSize","contentScale"]);u!=null&&(t.textHeight=u);const l=this.readPositiveNumber(i??{},["textWidth","width"])??this.readPositiveNumber(o,["textWidth","mtextWidth","textContentWidth"]);l!=null&&(t.textWidth=l),t.textLineSpacingFactor=this.readNumber(i??{},["lineSpacingFactor","textLineSpacingFactor"])??this.readNumber(o,["textLineSpacingFactor"])??t.textLineSpacingFactor;const b=this.readNumber(i??{},["textRotation","rotation"])??this.readNumber(o,["textRotation","mtextRotation","textContentRotation"]);b!=null&&(t.textRotation=b);const h=this.readPoint(o,["textDirection","mtextDirection","textDirectionVector"]);h&&(t.textDirection=h);const p=this.readNumber(o,["textAttachmentPoint","attachmentPoint"]);p!=null&&p!==0&&(t.textAttachmentPoint=p);const A=e.textAttachmentDirection;A!=null&&(t.textAttachmentDirection=A);const g=this.readNumber(o,["textDrawingDirection","drawingDirection"]);g!=null&&(t.textDrawingDirection=g);const x=typeof n=="string"?n:this.readString(i??{},["text","contents"])??this.readString(o,["text","contents","mtext"]),T=this.readPoint(i??{},["anchorPoint","textAnchor","textLocation","textPosition","textAnchorPoint"])??this.readPoint(o,["textAnchor","textLocation","textPosition","textAnchorPoint","contentBasePosition"]);if(x!=null&&T&&(t.mtextContent={text:x,anchorPoint:T}),e.blockContent){const d=e.blockContent,S=e.blockContent.blockContentId;if(this.isValidHandleId(S)){const m=this.readMLeaderEntityColor(d,["color"]);t.blockContent={blockContentId:S,normal:this.readPoint(d,["normal"]),position:e.blockContent.position,scale:this.readPoint(d,["scale"]),rotation:this.readNumber(d,["rotation"]),color:m,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(C=this.readMLeaderLeaders(o))==null||C.forEach(d=>{t.addLeader({lastLeaderLinePoint:d.lastLeaderLinePoint,lastLeaderLinePointSet:d.lastLeaderLinePointSet,doglegVector:d.doglegVector,doglegVectorSet:d.doglegVectorSet,doglegLength:d.doglegLength??e.doglegLength,breaks:d.breaks,leaderBranchIndex:d.leaderBranchIndex,leaderLines:d.leaderLines})}),t.numberOfLeaders===0&&((P=this.readLeaderLineArray(o))==null||P.forEach(d=>{t.addLeader({doglegLength:e.doglegLength}),t.addLeaderLine(t.numberOfLeaders-1,d)})),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,f=t.subDefinitionPoint2??n??o;if(!o||!t.name)return null;const c=new r.AcDb3PointAngularDimension(i,s,f,o);return this.processDimensionCommonAttrs(e,c),c}else if(e.subclassMarker=="AcDbOrdinateDimension"){const t=e,o=new r.AcDbOrdinateDimension(t.subDefinitionPoint1,t.subDefinitionPoint2);return 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}convertViewport(e){const t=new r.AcDbViewport;return 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,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.alignmentPoint.copy(o.startPoint),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,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.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}processCommonAttrs(e,t){if(t.layer=e.layer||"0",t.objectId=e.handle,e.ownerBlockRecordSoftId!=null&&(t.ownerId=e.ownerBlockRecordSoftId),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 o=new r.AcCmColor;e.color!=null&&o.setRGBValue(e.color),e.colorIndex!=null&&(e.color==null||e.colorIndex===7)&&(o.colorIndex=e.colorIndex),e.colorName&&(o.colorName=e.colorName),t.color=o}if(e.isVisible!=null&&(t.visibility=e.isVisible),e.transparency!=null){const o=new r.AcCmTransparency;o.method=e.transparencyType,(o.isByBlock||o.isByBlock)&&(o.alpha=e.transparency),t.transparency=o}}convertMLeaderEntityColor(e){return r.decodeMLeaderStyleRawColor(e)}readMLeaderEntityColor(e,t){for(const o of t){const n=e[o];if(typeof n=="number"&&Number.isFinite(n))return r.decodeMLeaderStyleRawColor(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,f=Array.isArray(s)?s.reduce((p,A)=>{const g=this.readMLeaderLine(A);return g&&p.push(g),p},[]):void 0,c={},a=this.readPoint(i,["lastLeaderLinePoint"]),u=this.readPoint(i,["doglegVector"]),l=this.readNumber(i,["doglegLength"]),b=this.readMLeaderBreaks(i.breaks),h=this.readNumber(i,["leaderBranchIndex"]);a&&(c.lastLeaderLinePoint=a),i.lastLeaderLinePointSet!=null&&(c.lastLeaderLinePointSet=this.readBoolean(i,["lastLeaderLinePointSet"])),u&&(c.doglegVector=u),i.doglegVectorSet!=null&&(c.doglegVectorSet=this.readBoolean(i,["doglegVectorSet"])),l!=null&&(c.doglegLength=l),b&&(c.breaks=b),h!=null&&(c.leaderBranchIndex=h),f&&(c.leaderLines=f),o.push(c)}),o}readMLeaderLine(e){if(!e||typeof e!="object")return;const t=e,o=t.vertices,n=Array.isArray(o)?o.filter(c=>this.isPointLike(c)):[],i=this.readMLeaderBreaks(t.breaks),s=Array.isArray(t.breakPointIndexes)?t.breakPointIndexes.filter(c=>typeof c=="number"):void 0,f=this.readNumber(t,["leaderLineIndex"]);return n.length>0||i&&i.length>0?{vertices:n,breakPointIndexes:s,leaderLineIndex:f,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"]),f=this.readNumber(n,["index"]);if(!i||!s)return;const c={start:i,end:s};return f!=null&&(c.index=f),c}).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 I{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.decodeMLeaderStyleRawColor(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.decodeMLeaderStyleRawColor(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.decodeMLeaderStyleRawColor(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}processCommonAttrs(e,t){t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}}const E="*MODEL_SPACE";class w 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.createWorkerApi({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!")}getFonts(e){var o;const t=new Map;return e.tables.BLOCK_RECORD.entries.forEach(n=>{t.set(n.name,n)}),new r.AcDbFontNameCollector({styles:e.tables.STYLE.entries.map(n=>({name:n.name,font:n.font,bigFont:n.bigFont,extendedFont:n.extendedFont,standardFlag:n.standardFlag})),textStyleVar:((o=e.header)==null?void 0:o.TEXTSTYLE)??r.DEFAULT_TEXT_STYLE}).collect(e.entities,{getEntityFontInfo:n=>{if(n.type=="MTEXT"){const i=n;return{styleName:i.styleName,formattedText:i.text,resolveStyle:!0}}if(n.type=="TEXT"||n.type=="ATTRIB")return{styleName:n.styleName,resolveStyle:!0};if(n.type=="SHAPE")return{styleName:n.styleName,resolveStyle:!0};if(n.type=="MULTILEADER"||n.type=="MLEADER"){const i=n,s=typeof i.textContent=="string"?i.textContent:"";return{styleName:typeof i.textStyleName=="string"?i.textStyleName:typeof i.styleName=="string"?i.styleName:void 0,formattedText:s,resolveStyle:!0}}return n.type=="INSERT"?{blockName:n.name}:null},getBlockEntities:n=>{var i;return(i=t.get(n))==null?void 0:i.entities}})}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(n=>{const i={name:n.name,ownerId:n.ownerHandle,dimpost:n.DIMPOST||"",dimapost:n.DIMAPOST||"",dimscale:n.DIMSCALE,dimasz:n.DIMASZ,dimexo:n.DIMEXO,dimdli:n.DIMDLI,dimexe:n.DIMEXE,dimrnd:n.DIMRND,dimdle:n.DIMDLE,dimtp:n.DIMTP,dimtm:n.DIMTM,dimtxt:n.DIMTXT,dimcen:n.DIMCEN,dimtsz:n.DIMTSZ,dimaltf:n.DIMALTF,dimlfac:n.DIMLFAC,dimtvp:n.DIMTVP,dimtfac:n.DIMTFAC,dimgap:n.DIMGAP,dimaltrnd:n.DIMALTRND,dimtol:n.DIMTOL==null||n.DIMTOL==0?0:1,dimlim:n.DIMLIM==null||n.DIMLIM==0?0:1,dimtih:n.DIMTIH==null||n.DIMTIH==0?0:1,dimtoh:n.DIMTOH==null||n.DIMTOH==0?0:1,dimse1:n.DIMSE1==null||n.DIMSE1==0?0:1,dimse2:n.DIMSE2==null||n.DIMSE2==0?0:1,dimtad:n.DIMTAD,dimzin:n.DIMZIN,dimazin:n.DIMAZIN,dimalt:n.DIMALT,dimaltd:n.DIMALTD,dimtofl:n.DIMTOFL,dimsah:n.DIMSAH,dimtix:n.DIMTIX,dimsoxd:n.DIMSOXD,dimclrd:n.DIMCLRD,dimclre:n.DIMCLRE,dimclrt:n.DIMCLRT,dimadec:n.DIMADEC||0,dimunit:n.DIMUNIT||2,dimdec:n.DIMDEC,dimtdec:n.DIMTDEC,dimaltu:n.DIMALTU,dimalttd:n.DIMALTTD,dimaunit:n.DIMAUNIT,dimfrac:n.DIMFRAC,dimlunit:n.DIMLUNIT,dimdsep:n.DIMDSEP||".",dimtmove:n.DIMTMOVE||0,dimjust:n.DIMJUST,dimsd1:n.DIMSD1,dimsd2:n.DIMSD2,dimtolj:n.DIMTOLJ,dimtzin:n.DIMTZIN,dimaltz:n.DIMALTZ,dimalttz:n.DIMALTTZ,dimfit:n.DIMFIT||0,dimupt:n.DIMUPT,dimatfit:n.DIMATFIT,dimtxsty:r.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:n.DIMBLK||"",dimblk1:n.DIMBLK1||"",dimblk2:n.DIMBLK2||"",dimlwd:n.DIMLWD,dimlwe:n.DIMLWE},s=new r.AcDbDimStyleTableRecord(i);this.processCommonTableEntryAttrs(n,s),t.tables.dimStyleTable.add(s)})}processLayers(e,t){e.tables.LAYER.entries.forEach(n=>{const i=new r.AcCmColor;i.colorIndex=n.colorIndex;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)})}processViewports(e,t){e.tables.VPORT.entries.forEach(n=>{const i=new r.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(n,i),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),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.objectId=n.handle,i.name=n.name,i.ownerId=n.ownerHandle,i.layoutId=n.layout,i.blockInsertUnits=n.insertionUnits,i.explodability=n.explodability,i.blockScaling=n.scalability,n.bmpPreview&&(i.bmpPreview=n.bmpPreview),t.tables.blockTable.add(i)),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 L,n=e.length,i=[];for(let s=0;s<n;s++){const f=e[s],c=o.convert(f);c&&i.push(c)}t.appendEntity(i)}async processEntities(e,t,o,n,i){const s=new L;let f=[];e.tables.BLOCK_RECORD.entries.forEach(l=>{this.isModelSpace(l.name)&&(f=l.entities)});const c=f.length,a=new r.AcDbBatchProcessing(c,100-n.value,o);this.config.convertByEntityType&&(f=this.groupAndFlattenByType(f));const u=t.tables.blockTable.modelSpace;await a.processChunk(async(l,b)=>{const h=[];for(let p=l;p<b;p++){const A=f[p],g=s.convert(A);g&&h.push(g)}if(u.appendEntity(h),i){let p=n.value+b/c*(100-n.value);p>100&&(p=100),await i(p,"ENTITY","IN-PROGRESS")}})}processHeader(e,t){const o=e.header;o.CECOLOR&&(o.CECOLOR.index>=0&&o.CECOLOR.index<=256?t.cecolor.colorIndex=o.CECOLOR.index:t.cecolor.setRGBValue(o.CECOLOR.rgb)),t.angbase=o.ANGBASE??0,t.angdir=o.ANGDIR??0,t.aunits=o.AUNITS??0,o.AUPREC!=null&&(t.auprec=o.AUPREC),o.LUNITS!=null&&(t.lunits=o.LUNITS),o.LUPREC!=null&&(t.luprec=o.LUPREC),o.UNITMODE!=null&&(t.unitmode=o.UNITMODE),o.MEASUREMENT!=null&&(t.measurement=o.MEASUREMENT),t.celtype=o.CELTYPE??r.ByLayer,t.celtscale=o.CELTSCALE??1,t.ltscale=o.LTSCALE??1,o.EXTMAX&&(t.extmax=o.EXTMAX),o.EXTMIN&&(t.extmin=o.EXTMIN),t.insunits=o.INSUNITS??1,t.pdmode=o.PDMODE??0,t.pdsize=o.PDSIZE??0,t.textstyle=o.TEXTSTYLE??r.DEFAULT_TEXT_STYLE;const n=this.normalizeHeaderStringValue(o.CMLEADERSTYLE)??r.DEFAULT_MLEADER_STYLE;t.cmleaderstyle=n}processCommonTableEntryAttrs(e,t){t.name=e.name,t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}processObjects(e,t){this.processLayouts(e,t),this.processImageDefs(e,t),this.processMLeaderStyles(e,t)}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 f=t.tables.blockTable.newIterator();s.objectId=i.handle;for(const c of f)if(c.layoutId===s.objectId){s.blockTableRecordId=c.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)})}processMLeaderStyles(e,t){const o=e.objects.MLEADERSTYLE;if(!(o!=null&&o.length))return;const n=t.objects.mleaderStyle,i=new I;o.forEach(s=>{const f=i.convertMLeaderStyle(s);n.setAt(f.objectId,f)})}processCommonObjectAttrs(e,t){t.objectId=e.handle,e.ownerHandle!=null&&(t.ownerId=e.ownerHandle)}groupAndFlattenByType(e){const t={},o=[];for(const n of e)t[n.type]||(t[n.type]=[],o.push(n.type)),t[n.type].push(n);return o.flatMap(n=>t[n])}isModelSpace(e){return e&&e.toUpperCase()==E}normalizeHeaderStringValue(e){if(typeof e!="string")return;const t=e.trim();return t.length>0?t:void 0}}D.AcDbLibreDwgConverter=w,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});