@linkiez/dxf-renew 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +17 -0
- package/.eslintrc.json +61 -0
- package/.gitattributes +4 -0
- package/.github/instructions/project-en_US.instructions.md +352 -0
- package/.github/workflows/release.yml +110 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +1 -0
- package/.prettierrc.json +6 -0
- package/.releaserc.json +76 -0
- package/.travis.yml +6 -0
- package/.yarn/install-state.gz +0 -0
- package/.yarnrc.yml +1 -0
- package/CHANGELOG.md +134 -0
- package/CONTRIBUTING.md +271 -0
- package/LICENSE +21 -0
- package/PLAN.md +517 -0
- package/README.md +306 -0
- package/build.mjs +66 -0
- package/commitlint.config.js +25 -0
- package/dist/dxf.js +7234 -0
- package/docs/CODE_PATTERNS.md +182 -0
- package/docs/DIMENSION_SUMMARY.md +248 -0
- package/docs/DIMENSION_SUMMARY.pt-BR.md +248 -0
- package/docs/IMPLEMENTED-2D-ENTITIES.md +54 -0
- package/docs/IMPLEMENTED-2D-ENTITIES.pt-BR.md +54 -0
- package/docs/TEXT-MTEXT-DIMENSION-SUPPORT.md +241 -0
- package/docs/TEXT-MTEXT-DIMENSION-SUPPORT.pt-BR.md +169 -0
- package/docs/autocad_2012_pdf_dxf-reference_enu.md +8272 -0
- package/examples/dxf.html +36 -0
- package/examples/example.es5.js +30 -0
- package/examples/example.es6.js +30 -0
- package/examples/text-dimension-viewer.html +133 -0
- package/lib/Helper.cjs +89 -0
- package/lib/Helper.cjs.map +7 -0
- package/lib/Helper.js +59 -0
- package/lib/Helper.js.map +7 -0
- package/lib/applyTransforms.cjs +59 -0
- package/lib/applyTransforms.cjs.map +7 -0
- package/lib/applyTransforms.js +39 -0
- package/lib/applyTransforms.js.map +7 -0
- package/lib/cli.cjs +53 -0
- package/lib/cli.cjs.map +7 -0
- package/lib/cli.js +29 -0
- package/lib/cli.js.map +7 -0
- package/lib/config.cjs +30 -0
- package/lib/config.cjs.map +7 -0
- package/lib/config.js +10 -0
- package/lib/config.js.map +7 -0
- package/lib/constants.cjs +39 -0
- package/lib/constants.cjs.map +7 -0
- package/lib/constants.js +15 -0
- package/lib/constants.js.map +7 -0
- package/lib/denormalise.cjs +148 -0
- package/lib/denormalise.cjs.map +7 -0
- package/lib/denormalise.js +118 -0
- package/lib/denormalise.js.map +7 -0
- package/lib/dimensionToSVG.cjs +307 -0
- package/lib/dimensionToSVG.cjs.map +7 -0
- package/lib/dimensionToSVG.js +273 -0
- package/lib/dimensionToSVG.js.map +7 -0
- package/lib/entityToPolyline.cjs +248 -0
- package/lib/entityToPolyline.cjs.map +7 -0
- package/lib/entityToPolyline.js +213 -0
- package/lib/entityToPolyline.js.map +7 -0
- package/lib/getRGBForEntity.cjs +53 -0
- package/lib/getRGBForEntity.cjs.map +7 -0
- package/lib/getRGBForEntity.js +23 -0
- package/lib/getRGBForEntity.js.map +7 -0
- package/lib/groupEntitiesByLayer.cjs +34 -0
- package/lib/groupEntitiesByLayer.cjs.map +7 -0
- package/lib/groupEntitiesByLayer.js +14 -0
- package/lib/groupEntitiesByLayer.js.map +7 -0
- package/lib/handlers/blocks.cjs +93 -0
- package/lib/handlers/blocks.cjs.map +7 -0
- package/lib/handlers/blocks.js +63 -0
- package/lib/handlers/blocks.js.map +7 -0
- package/lib/handlers/entities.cjs +118 -0
- package/lib/handlers/entities.cjs.map +7 -0
- package/lib/handlers/entities.js +88 -0
- package/lib/handlers/entities.js.map +7 -0
- package/lib/handlers/entity/arc.cjs +82 -0
- package/lib/handlers/entity/arc.cjs.map +7 -0
- package/lib/handlers/entity/arc.js +47 -0
- package/lib/handlers/entity/arc.js.map +7 -0
- package/lib/handlers/entity/attdef.cjs +318 -0
- package/lib/handlers/entity/attdef.cjs.map +7 -0
- package/lib/handlers/entity/attdef.js +282 -0
- package/lib/handlers/entity/attdef.js.map +7 -0
- package/lib/handlers/entity/attrib.cjs +52 -0
- package/lib/handlers/entity/attrib.cjs.map +7 -0
- package/lib/handlers/entity/attrib.js +27 -0
- package/lib/handlers/entity/attrib.js.map +7 -0
- package/lib/handlers/entity/circle.cjs +73 -0
- package/lib/handlers/entity/circle.cjs.map +7 -0
- package/lib/handlers/entity/circle.js +38 -0
- package/lib/handlers/entity/circle.js.map +7 -0
- package/lib/handlers/entity/common.cjs +83 -0
- package/lib/handlers/entity/common.cjs.map +7 -0
- package/lib/handlers/entity/common.js +63 -0
- package/lib/handlers/entity/common.js.map +7 -0
- package/lib/handlers/entity/dimension.cjs +203 -0
- package/lib/handlers/entity/dimension.cjs.map +7 -0
- package/lib/handlers/entity/dimension.js +168 -0
- package/lib/handlers/entity/dimension.js.map +7 -0
- package/lib/handlers/entity/ellipse.cjs +88 -0
- package/lib/handlers/entity/ellipse.cjs.map +7 -0
- package/lib/handlers/entity/ellipse.js +53 -0
- package/lib/handlers/entity/ellipse.js.map +7 -0
- package/lib/handlers/entity/hatch.cjs +470 -0
- package/lib/handlers/entity/hatch.cjs.map +7 -0
- package/lib/handlers/entity/hatch.js +435 -0
- package/lib/handlers/entity/hatch.js.map +7 -0
- package/lib/handlers/entity/insert.cjs +106 -0
- package/lib/handlers/entity/insert.cjs.map +7 -0
- package/lib/handlers/entity/insert.js +71 -0
- package/lib/handlers/entity/insert.js.map +7 -0
- package/lib/handlers/entity/line.cjs +84 -0
- package/lib/handlers/entity/line.cjs.map +7 -0
- package/lib/handlers/entity/line.js +49 -0
- package/lib/handlers/entity/line.js.map +7 -0
- package/lib/handlers/entity/lwpolyline.cjs +82 -0
- package/lib/handlers/entity/lwpolyline.cjs.map +7 -0
- package/lib/handlers/entity/lwpolyline.js +47 -0
- package/lib/handlers/entity/lwpolyline.js.map +7 -0
- package/lib/handlers/entity/mtext.cjs +121 -0
- package/lib/handlers/entity/mtext.cjs.map +7 -0
- package/lib/handlers/entity/mtext.js +85 -0
- package/lib/handlers/entity/mtext.js.map +7 -0
- package/lib/handlers/entity/ole2Frame.cjs +98 -0
- package/lib/handlers/entity/ole2Frame.cjs.map +7 -0
- package/lib/handlers/entity/ole2Frame.js +63 -0
- package/lib/handlers/entity/ole2Frame.js.map +7 -0
- package/lib/handlers/entity/point.cjs +73 -0
- package/lib/handlers/entity/point.cjs.map +7 -0
- package/lib/handlers/entity/point.js +38 -0
- package/lib/handlers/entity/point.js.map +7 -0
- package/lib/handlers/entity/polyline.cjs +70 -0
- package/lib/handlers/entity/polyline.cjs.map +7 -0
- package/lib/handlers/entity/polyline.js +35 -0
- package/lib/handlers/entity/polyline.js.map +7 -0
- package/lib/handlers/entity/solid.cjs +101 -0
- package/lib/handlers/entity/solid.cjs.map +7 -0
- package/lib/handlers/entity/solid.js +66 -0
- package/lib/handlers/entity/solid.js.map +7 -0
- package/lib/handlers/entity/spline.cjs +109 -0
- package/lib/handlers/entity/spline.cjs.map +7 -0
- package/lib/handlers/entity/spline.js +74 -0
- package/lib/handlers/entity/spline.js.map +7 -0
- package/lib/handlers/entity/text.cjs +85 -0
- package/lib/handlers/entity/text.cjs.map +7 -0
- package/lib/handlers/entity/text.js +49 -0
- package/lib/handlers/entity/text.js.map +7 -0
- package/lib/handlers/entity/threeDFace.cjs +98 -0
- package/lib/handlers/entity/threeDFace.cjs.map +7 -0
- package/lib/handlers/entity/threeDFace.js +63 -0
- package/lib/handlers/entity/threeDFace.js.map +7 -0
- package/lib/handlers/entity/vertex.cjs +78 -0
- package/lib/handlers/entity/vertex.cjs.map +7 -0
- package/lib/handlers/entity/vertex.js +53 -0
- package/lib/handlers/entity/vertex.js.map +7 -0
- package/lib/handlers/entity/viewport.cjs +153 -0
- package/lib/handlers/entity/viewport.cjs.map +7 -0
- package/lib/handlers/entity/viewport.js +118 -0
- package/lib/handlers/entity/viewport.js.map +7 -0
- package/lib/handlers/header.cjs +92 -0
- package/lib/handlers/header.cjs.map +7 -0
- package/lib/handlers/header.js +72 -0
- package/lib/handlers/header.js.map +7 -0
- package/lib/handlers/objects.cjs +170 -0
- package/lib/handlers/objects.cjs.map +7 -0
- package/lib/handlers/objects.js +150 -0
- package/lib/handlers/objects.js.map +7 -0
- package/lib/handlers/tables.cjs +587 -0
- package/lib/handlers/tables.cjs.map +7 -0
- package/lib/handlers/tables.js +557 -0
- package/lib/handlers/tables.js.map +7 -0
- package/lib/index.cjs +60 -0
- package/lib/index.cjs.map +7 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +7 -0
- package/lib/parseString.cjs +118 -0
- package/lib/parseString.cjs.map +7 -0
- package/lib/parseString.js +88 -0
- package/lib/parseString.js.map +7 -0
- package/lib/toPolylines.cjs +69 -0
- package/lib/toPolylines.cjs.map +7 -0
- package/lib/toPolylines.js +39 -0
- package/lib/toPolylines.js.map +7 -0
- package/lib/toSVG.cjs +395 -0
- package/lib/toSVG.cjs.map +7 -0
- package/lib/toSVG.js +361 -0
- package/lib/toSVG.js.map +7 -0
- package/lib/types/arc-entity.cjs +17 -0
- package/lib/types/arc-entity.cjs.map +7 -0
- package/lib/types/arc-entity.js +1 -0
- package/lib/types/arc-entity.js.map +7 -0
- package/lib/types/base-entity.cjs +17 -0
- package/lib/types/base-entity.cjs.map +7 -0
- package/lib/types/base-entity.js +1 -0
- package/lib/types/base-entity.js.map +7 -0
- package/lib/types/circle-entity.cjs +17 -0
- package/lib/types/circle-entity.cjs.map +7 -0
- package/lib/types/circle-entity.js +1 -0
- package/lib/types/circle-entity.js.map +7 -0
- package/lib/types/common.cjs +17 -0
- package/lib/types/common.cjs.map +7 -0
- package/lib/types/common.js +1 -0
- package/lib/types/common.js.map +7 -0
- package/lib/types/dimension-entity.cjs +17 -0
- package/lib/types/dimension-entity.cjs.map +7 -0
- package/lib/types/dimension-entity.js +1 -0
- package/lib/types/dimension-entity.js.map +7 -0
- package/lib/types/dxf.cjs +17 -0
- package/lib/types/dxf.cjs.map +7 -0
- package/lib/types/dxf.js +1 -0
- package/lib/types/dxf.js.map +7 -0
- package/lib/types/ellipse-entity.cjs +17 -0
- package/lib/types/ellipse-entity.cjs.map +7 -0
- package/lib/types/ellipse-entity.js +1 -0
- package/lib/types/ellipse-entity.js.map +7 -0
- package/lib/types/entity.cjs +17 -0
- package/lib/types/entity.cjs.map +7 -0
- package/lib/types/entity.js +1 -0
- package/lib/types/entity.js.map +7 -0
- package/lib/types/handler-internal.cjs +17 -0
- package/lib/types/handler-internal.cjs.map +7 -0
- package/lib/types/handler-internal.js +1 -0
- package/lib/types/handler-internal.js.map +7 -0
- package/lib/types/handler.cjs +17 -0
- package/lib/types/handler.cjs.map +7 -0
- package/lib/types/handler.js +1 -0
- package/lib/types/handler.js.map +7 -0
- package/lib/types/hatch-entity.cjs +17 -0
- package/lib/types/hatch-entity.cjs.map +7 -0
- package/lib/types/hatch-entity.js +1 -0
- package/lib/types/hatch-entity.js.map +7 -0
- package/lib/types/helper.cjs +17 -0
- package/lib/types/helper.cjs.map +7 -0
- package/lib/types/helper.js +1 -0
- package/lib/types/helper.js.map +7 -0
- package/lib/types/index.cjs +77 -0
- package/lib/types/index.cjs.map +7 -0
- package/lib/types/index.js +29 -0
- package/lib/types/index.js.map +7 -0
- package/lib/types/insert-entity.cjs +17 -0
- package/lib/types/insert-entity.cjs.map +7 -0
- package/lib/types/insert-entity.js +1 -0
- package/lib/types/insert-entity.js.map +7 -0
- package/lib/types/layer-groups.cjs +17 -0
- package/lib/types/layer-groups.cjs.map +7 -0
- package/lib/types/layer-groups.js +1 -0
- package/lib/types/layer-groups.js.map +7 -0
- package/lib/types/line-entity.cjs +17 -0
- package/lib/types/line-entity.cjs.map +7 -0
- package/lib/types/line-entity.js +1 -0
- package/lib/types/line-entity.js.map +7 -0
- package/lib/types/mtext-entity.cjs +17 -0
- package/lib/types/mtext-entity.cjs.map +7 -0
- package/lib/types/mtext-entity.js +1 -0
- package/lib/types/mtext-entity.js.map +7 -0
- package/lib/types/ole2frame-entity.cjs +17 -0
- package/lib/types/ole2frame-entity.cjs.map +7 -0
- package/lib/types/ole2frame-entity.js +1 -0
- package/lib/types/ole2frame-entity.js.map +7 -0
- package/lib/types/options.cjs +17 -0
- package/lib/types/options.cjs.map +7 -0
- package/lib/types/options.js +1 -0
- package/lib/types/options.js.map +7 -0
- package/lib/types/point-entity.cjs +17 -0
- package/lib/types/point-entity.cjs.map +7 -0
- package/lib/types/point-entity.js +1 -0
- package/lib/types/point-entity.js.map +7 -0
- package/lib/types/polyline-entity.cjs +17 -0
- package/lib/types/polyline-entity.cjs.map +7 -0
- package/lib/types/polyline-entity.js +1 -0
- package/lib/types/polyline-entity.js.map +7 -0
- package/lib/types/polylines.cjs +17 -0
- package/lib/types/polylines.cjs.map +7 -0
- package/lib/types/polylines.js +1 -0
- package/lib/types/polylines.js.map +7 -0
- package/lib/types/solid-entity.cjs +17 -0
- package/lib/types/solid-entity.cjs.map +7 -0
- package/lib/types/solid-entity.js +1 -0
- package/lib/types/solid-entity.js.map +7 -0
- package/lib/types/spline-entity.cjs +17 -0
- package/lib/types/spline-entity.cjs.map +7 -0
- package/lib/types/spline-entity.js +1 -0
- package/lib/types/spline-entity.js.map +7 -0
- package/lib/types/svg.cjs +17 -0
- package/lib/types/svg.cjs.map +7 -0
- package/lib/types/svg.js +1 -0
- package/lib/types/svg.js.map +7 -0
- package/lib/types/tables.cjs +17 -0
- package/lib/types/tables.cjs.map +7 -0
- package/lib/types/tables.js +1 -0
- package/lib/types/tables.js.map +7 -0
- package/lib/types/text-entity.cjs +17 -0
- package/lib/types/text-entity.cjs.map +7 -0
- package/lib/types/text-entity.js +1 -0
- package/lib/types/text-entity.js.map +7 -0
- package/lib/types/util-types.cjs +17 -0
- package/lib/types/util-types.cjs.map +7 -0
- package/lib/types/util-types.js +1 -0
- package/lib/types/util-types.js.map +7 -0
- package/lib/types/vecks.d.cjs +2 -0
- package/lib/types/vecks.d.cjs.map +7 -0
- package/lib/types/vecks.d.js +1 -0
- package/lib/types/vecks.d.js.map +7 -0
- package/lib/types/viewport-entity.cjs +17 -0
- package/lib/types/viewport-entity.cjs.map +7 -0
- package/lib/types/viewport-entity.js +1 -0
- package/lib/types/viewport-entity.js.map +7 -0
- package/lib/types.cjs +23 -0
- package/lib/types.cjs.map +7 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +7 -0
- package/lib/util/bSpline.cjs +95 -0
- package/lib/util/bSpline.cjs.map +7 -0
- package/lib/util/bSpline.js +65 -0
- package/lib/util/bSpline.js.map +7 -0
- package/lib/util/colors.cjs +283 -0
- package/lib/util/colors.cjs.map +7 -0
- package/lib/util/colors.js +263 -0
- package/lib/util/colors.js.map +7 -0
- package/lib/util/createArcForLWPolyline.cjs +84 -0
- package/lib/util/createArcForLWPolyline.cjs.map +7 -0
- package/lib/util/createArcForLWPolyline.js +64 -0
- package/lib/util/createArcForLWPolyline.js.map +7 -0
- package/lib/util/dxfColorToRGB.cjs +115 -0
- package/lib/util/dxfColorToRGB.cjs.map +7 -0
- package/lib/util/dxfColorToRGB.js +90 -0
- package/lib/util/dxfColorToRGB.js.map +7 -0
- package/lib/util/insertKnot.cjs +77 -0
- package/lib/util/insertKnot.cjs.map +7 -0
- package/lib/util/insertKnot.js +57 -0
- package/lib/util/insertKnot.js.map +7 -0
- package/lib/util/logger.cjs +53 -0
- package/lib/util/logger.cjs.map +7 -0
- package/lib/util/logger.js +23 -0
- package/lib/util/logger.js.map +7 -0
- package/lib/util/rgbToColorAttribute.cjs +32 -0
- package/lib/util/rgbToColorAttribute.cjs.map +7 -0
- package/lib/util/rgbToColorAttribute.js +12 -0
- package/lib/util/rgbToColorAttribute.js.map +7 -0
- package/lib/util/rotate.cjs +30 -0
- package/lib/util/rotate.cjs.map +7 -0
- package/lib/util/rotate.js +10 -0
- package/lib/util/rotate.js.map +7 -0
- package/lib/util/round10.cjs +38 -0
- package/lib/util/round10.cjs.map +7 -0
- package/lib/util/round10.js +18 -0
- package/lib/util/round10.js.map +7 -0
- package/lib/util/toPiecewiseBezier.cjs +90 -0
- package/lib/util/toPiecewiseBezier.cjs.map +7 -0
- package/lib/util/toPiecewiseBezier.js +54 -0
- package/lib/util/toPiecewiseBezier.js.map +7 -0
- package/lib/util/transformBoundingBoxAndElement.cjs +80 -0
- package/lib/util/transformBoundingBoxAndElement.cjs.map +7 -0
- package/lib/util/transformBoundingBoxAndElement.js +60 -0
- package/lib/util/transformBoundingBoxAndElement.js.map +7 -0
- package/package.json +127 -0
- package/src/Helper.ts +71 -0
- package/src/applyTransforms.ts +54 -0
- package/src/cli.ts +41 -0
- package/src/config.ts +10 -0
- package/src/constants.ts +14 -0
- package/src/denormalise.ts +153 -0
- package/src/dimensionToSVG.ts +427 -0
- package/src/entityToPolyline.ts +338 -0
- package/src/getRGBForEntity.ts +28 -0
- package/src/groupEntitiesByLayer.ts +14 -0
- package/src/handlers/blocks.ts +65 -0
- package/src/handlers/entities.ts +111 -0
- package/src/handlers/entity/arc.ts +61 -0
- package/src/handlers/entity/attdef.ts +284 -0
- package/src/handlers/entity/attrib.ts +29 -0
- package/src/handlers/entity/circle.ts +47 -0
- package/src/handlers/entity/common.ts +79 -0
- package/src/handlers/entity/dimension.ts +217 -0
- package/src/handlers/entity/ellipse.ts +55 -0
- package/src/handlers/entity/hatch.ts +471 -0
- package/src/handlers/entity/insert.ts +73 -0
- package/src/handlers/entity/line.ts +56 -0
- package/src/handlers/entity/lwpolyline.ts +54 -0
- package/src/handlers/entity/mtext.ts +150 -0
- package/src/handlers/entity/ole2Frame.ts +64 -0
- package/src/handlers/entity/point.ts +47 -0
- package/src/handlers/entity/polyline.ts +49 -0
- package/src/handlers/entity/solid.ts +73 -0
- package/src/handlers/entity/spline.ts +103 -0
- package/src/handlers/entity/text.ts +83 -0
- package/src/handlers/entity/threeDFace.ts +69 -0
- package/src/handlers/entity/vertex.ts +55 -0
- package/src/handlers/entity/viewport.ts +119 -0
- package/src/handlers/header.ts +73 -0
- package/src/handlers/objects.ts +152 -0
- package/src/handlers/tables.ts +581 -0
- package/src/index.ts +19 -0
- package/src/parseString.ts +97 -0
- package/src/toPolylines.ts +47 -0
- package/src/toSVG.ts +518 -0
- package/src/types/README.md +91 -0
- package/src/types/arc-entity.ts +10 -0
- package/src/types/base-entity.ts +25 -0
- package/src/types/circle-entity.ts +8 -0
- package/src/types/common.ts +37 -0
- package/src/types/dimension-entity.ts +23 -0
- package/src/types/dxf.ts +64 -0
- package/src/types/ellipse-entity.ts +13 -0
- package/src/types/entity.ts +32 -0
- package/src/types/handler-internal.ts +51 -0
- package/src/types/handler.ts +10 -0
- package/src/types/hatch-entity.ts +127 -0
- package/src/types/helper.ts +12 -0
- package/src/types/index.ts +53 -0
- package/src/types/insert-entity.ts +19 -0
- package/src/types/layer-groups.ts +8 -0
- package/src/types/line-entity.ts +10 -0
- package/src/types/mtext-entity.ts +35 -0
- package/src/types/ole2frame-entity.ts +35 -0
- package/src/types/options.ts +17 -0
- package/src/types/point-entity.ts +7 -0
- package/src/types/polyline-entity.ts +20 -0
- package/src/types/polylines.ts +22 -0
- package/src/types/solid-entity.ts +9 -0
- package/src/types/spline-entity.ts +12 -0
- package/src/types/svg.ts +31 -0
- package/src/types/tables.ts +414 -0
- package/src/types/text-entity.ts +23 -0
- package/src/types/util-types.ts +27 -0
- package/src/types/vecks.d.ts +29 -0
- package/src/types/viewport-entity.ts +81 -0
- package/src/types.ts +5 -0
- package/src/util/bSpline.ts +97 -0
- package/src/util/colors.ts +266 -0
- package/src/util/createArcForLWPolyline.ts +93 -0
- package/src/util/diagram.png +0 -0
- package/src/util/dxfColorToRGB.ts +106 -0
- package/src/util/insertKnot.ts +69 -0
- package/src/util/logger.ts +23 -0
- package/src/util/rgbToColorAttribute.ts +14 -0
- package/src/util/rotate.ts +14 -0
- package/src/util/round10.ts +24 -0
- package/src/util/toPiecewiseBezier.ts +70 -0
- package/src/util/transformBoundingBoxAndElement.ts +74 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var dimensionToSVG_exports = {};
|
|
30
|
+
__export(dimensionToSVG_exports, {
|
|
31
|
+
createArrowMarker: () => createArrowMarker,
|
|
32
|
+
default: () => dimensionToSVG
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(dimensionToSVG_exports);
|
|
35
|
+
var import_vecks = require("vecks");
|
|
36
|
+
var import_colors = __toESM(require("./util/colors"), 1);
|
|
37
|
+
function colorNumberToSVG(colorNumber) {
|
|
38
|
+
if (colorNumber === void 0 || colorNumber < 0) {
|
|
39
|
+
return "currentColor";
|
|
40
|
+
}
|
|
41
|
+
if (colorNumber === 0 || colorNumber === 256) {
|
|
42
|
+
return "currentColor";
|
|
43
|
+
}
|
|
44
|
+
const rgb = import_colors.default[colorNumber];
|
|
45
|
+
if (!rgb) {
|
|
46
|
+
return "currentColor";
|
|
47
|
+
}
|
|
48
|
+
return `rgb(${rgb[0]},${rgb[1]},${rgb[2]})`;
|
|
49
|
+
}
|
|
50
|
+
function getDimensionColors(dimStyle) {
|
|
51
|
+
return {
|
|
52
|
+
dimLineColor: colorNumberToSVG(dimStyle?.dimClrd),
|
|
53
|
+
extLineColor: colorNumberToSVG(dimStyle?.dimClre),
|
|
54
|
+
textColor: colorNumberToSVG(dimStyle?.dimClrt),
|
|
55
|
+
dimLineWeight: dimStyle?.dimLwd ?? 0.5,
|
|
56
|
+
extLineWeight: dimStyle?.dimLwe ?? 0.5
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function dimensionToSVG(entity, dimStyle) {
|
|
60
|
+
switch (entity.dimensionType) {
|
|
61
|
+
case 0:
|
|
62
|
+
// Rotated, horizontal, or vertical
|
|
63
|
+
case 1:
|
|
64
|
+
return renderLinearDimension(entity, dimStyle);
|
|
65
|
+
case 2:
|
|
66
|
+
return renderAngularDimension(entity, dimStyle);
|
|
67
|
+
case 3:
|
|
68
|
+
return renderDiameterDimension(entity, dimStyle);
|
|
69
|
+
case 4:
|
|
70
|
+
return renderRadialDimension(entity, dimStyle);
|
|
71
|
+
case 6:
|
|
72
|
+
return renderOrdinateDimension(entity, dimStyle);
|
|
73
|
+
default:
|
|
74
|
+
return renderFallbackDimension(entity);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function createArrowMarker(id, size, color) {
|
|
78
|
+
const arrowPath = `M 0 0 L ${size} ${size / 2} L 0 ${size} z`;
|
|
79
|
+
return `<marker id="${id}" markerWidth="${size}" markerHeight="${size}" refX="${size}" refY="${size / 2}" orient="auto" markerUnits="strokeWidth">
|
|
80
|
+
<path d="${arrowPath}" fill="${color}" />
|
|
81
|
+
</marker>`;
|
|
82
|
+
}
|
|
83
|
+
function renderLinearDimension(entity, dimStyle) {
|
|
84
|
+
const bbox = new import_vecks.Box2();
|
|
85
|
+
const elements = [];
|
|
86
|
+
const markers = [];
|
|
87
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5;
|
|
88
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
89
|
+
const extLineOffset = dimStyle?.dimExo ?? 0.625;
|
|
90
|
+
const extLineExtension = dimStyle?.dimExe ?? 1.25;
|
|
91
|
+
const { dimLineColor, extLineColor, textColor, dimLineWeight, extLineWeight } = getDimensionColors(dimStyle);
|
|
92
|
+
const defPoint1X = entity.measureStart?.x ?? 0;
|
|
93
|
+
const defPoint1Y = entity.measureStart?.y ?? 0;
|
|
94
|
+
const defPoint2X = entity.measureEnd?.x ?? 0;
|
|
95
|
+
const defPoint2Y = entity.measureEnd?.y ?? 0;
|
|
96
|
+
const dimLineY = entity.start?.y ?? 0;
|
|
97
|
+
const textX = entity.textMidpoint?.x ?? (defPoint1X + defPoint2X) / 2;
|
|
98
|
+
const textY = entity.textMidpoint?.y ?? (defPoint1Y + defPoint2Y) / 2;
|
|
99
|
+
const angle = Math.atan2(defPoint2Y - defPoint1Y, defPoint2X - defPoint1X);
|
|
100
|
+
const perpAngle = angle + Math.PI / 2;
|
|
101
|
+
const dimLine1X = defPoint1X + Math.cos(perpAngle) * (dimLineY - defPoint1Y);
|
|
102
|
+
const dimLine1Y = defPoint1Y + Math.sin(perpAngle) * (dimLineY - defPoint1Y);
|
|
103
|
+
const dimLine2X = defPoint2X + Math.cos(perpAngle) * (dimLineY - defPoint2Y);
|
|
104
|
+
const dimLine2Y = defPoint2Y + Math.sin(perpAngle) * (dimLineY - defPoint2Y);
|
|
105
|
+
bbox.expandByPoint({ x: defPoint1X, y: defPoint1Y });
|
|
106
|
+
bbox.expandByPoint({ x: defPoint2X, y: defPoint2Y });
|
|
107
|
+
bbox.expandByPoint({ x: dimLine1X, y: dimLine1Y });
|
|
108
|
+
bbox.expandByPoint({ x: dimLine2X, y: dimLine2Y });
|
|
109
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
110
|
+
const markerId1 = `dim-arrow-start-${Date.now()}`;
|
|
111
|
+
const markerId2 = `dim-arrow-end-${Date.now()}`;
|
|
112
|
+
markers.push(
|
|
113
|
+
createArrowMarker(markerId1, arrowSize, dimLineColor),
|
|
114
|
+
createArrowMarker(markerId2, arrowSize, dimLineColor)
|
|
115
|
+
);
|
|
116
|
+
const extLine1StartX = defPoint1X + Math.cos(perpAngle) * extLineOffset;
|
|
117
|
+
const extLine1StartY = defPoint1Y + Math.sin(perpAngle) * extLineOffset;
|
|
118
|
+
const extLine1EndX = dimLine1X + Math.cos(perpAngle) * extLineExtension;
|
|
119
|
+
const extLine1EndY = dimLine1Y + Math.sin(perpAngle) * extLineExtension;
|
|
120
|
+
const extLine2StartX = defPoint2X + Math.cos(perpAngle) * extLineOffset;
|
|
121
|
+
const extLine2StartY = defPoint2Y + Math.sin(perpAngle) * extLineOffset;
|
|
122
|
+
const extLine2EndX = dimLine2X + Math.cos(perpAngle) * extLineExtension;
|
|
123
|
+
const extLine2EndY = dimLine2Y + Math.sin(perpAngle) * extLineExtension;
|
|
124
|
+
elements.push(
|
|
125
|
+
`<line x1="${extLine1StartX}" y1="${extLine1StartY}" x2="${extLine1EndX}" y2="${extLine1EndY}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
126
|
+
`<line x1="${extLine2StartX}" y1="${extLine2StartY}" x2="${extLine2EndX}" y2="${extLine2EndY}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
127
|
+
`<line x1="${dimLine1X}" y1="${dimLine1Y}" x2="${dimLine2X}" y2="${dimLine2Y}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-start="url(#${markerId1})" marker-end="url(#${markerId2})" />`
|
|
128
|
+
);
|
|
129
|
+
if (entity.text) {
|
|
130
|
+
const textRotation = angle * 180 / Math.PI;
|
|
131
|
+
elements.push(
|
|
132
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
bbox,
|
|
137
|
+
element: `<defs>${markers.join("")}</defs><g>${elements.join("")}</g>`
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function renderAngularDimension(entity, dimStyle) {
|
|
141
|
+
const bbox = new import_vecks.Box2();
|
|
142
|
+
const elements = [];
|
|
143
|
+
const markers = [];
|
|
144
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5;
|
|
145
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
146
|
+
const { dimLineColor, extLineColor, textColor, dimLineWeight, extLineWeight } = getDimensionColors(dimStyle);
|
|
147
|
+
const centerX = entity.start?.x ?? 0;
|
|
148
|
+
const centerY = entity.start?.y ?? 0;
|
|
149
|
+
const x1 = entity.measureStart?.x ?? 0;
|
|
150
|
+
const y1 = entity.measureStart?.y ?? 0;
|
|
151
|
+
const x2 = entity.measureEnd?.x ?? 0;
|
|
152
|
+
const y2 = entity.measureEnd?.y ?? 0;
|
|
153
|
+
const textX = entity.textMidpoint?.x ?? centerX;
|
|
154
|
+
const textY = entity.textMidpoint?.y ?? centerY;
|
|
155
|
+
bbox.expandByPoint({ x: centerX, y: centerY });
|
|
156
|
+
bbox.expandByPoint({ x: x1, y: y1 });
|
|
157
|
+
bbox.expandByPoint({ x: x2, y: y2 });
|
|
158
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
159
|
+
const markerId1 = `dim-angular-arrow-start-${Date.now()}`;
|
|
160
|
+
const markerId2 = `dim-angular-arrow-end-${Date.now()}`;
|
|
161
|
+
markers.push(
|
|
162
|
+
createArrowMarker(markerId1, arrowSize, dimLineColor),
|
|
163
|
+
createArrowMarker(markerId2, arrowSize, dimLineColor)
|
|
164
|
+
);
|
|
165
|
+
elements.push(
|
|
166
|
+
`<line x1="${centerX}" y1="${centerY}" x2="${x1}" y2="${y1}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
167
|
+
`<line x1="${centerX}" y1="${centerY}" x2="${x2}" y2="${y2}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`
|
|
168
|
+
);
|
|
169
|
+
const radius = Math.hypot(textX - centerX, textY - centerY);
|
|
170
|
+
const startAngle = Math.atan2(y1 - centerY, x1 - centerX);
|
|
171
|
+
const endAngle = Math.atan2(y2 - centerY, x2 - centerX);
|
|
172
|
+
const largeArcFlag = Math.abs(endAngle - startAngle) > Math.PI ? 1 : 0;
|
|
173
|
+
const arcStartX = centerX + radius * Math.cos(startAngle);
|
|
174
|
+
const arcStartY = centerY + radius * Math.sin(startAngle);
|
|
175
|
+
const arcEndX = centerX + radius * Math.cos(endAngle);
|
|
176
|
+
const arcEndY = centerY + radius * Math.sin(endAngle);
|
|
177
|
+
elements.push(
|
|
178
|
+
`<path d="M ${arcStartX} ${arcStartY} A ${radius} ${radius} 0 ${largeArcFlag} 1 ${arcEndX} ${arcEndY}" fill="none" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-start="url(#${markerId1})" marker-end="url(#${markerId2})" />`
|
|
179
|
+
);
|
|
180
|
+
if (entity.text) {
|
|
181
|
+
const midAngle = (startAngle + endAngle) / 2;
|
|
182
|
+
const textRotation = midAngle * 180 / Math.PI;
|
|
183
|
+
elements.push(
|
|
184
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
bbox,
|
|
189
|
+
element: `<defs>${markers.join("")}</defs><g>${elements.join("")}</g>`
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function renderDiameterDimension(entity, dimStyle) {
|
|
193
|
+
const bbox = new import_vecks.Box2();
|
|
194
|
+
const elements = [];
|
|
195
|
+
const markers = [];
|
|
196
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5;
|
|
197
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
198
|
+
const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle);
|
|
199
|
+
const x1 = entity.measureStart?.x ?? 0;
|
|
200
|
+
const y1 = entity.measureStart?.y ?? 0;
|
|
201
|
+
const x2 = entity.measureEnd?.x ?? 0;
|
|
202
|
+
const y2 = entity.measureEnd?.y ?? 0;
|
|
203
|
+
const textX = entity.textMidpoint?.x ?? (x1 + x2) / 2;
|
|
204
|
+
const textY = entity.textMidpoint?.y ?? (y1 + y2) / 2;
|
|
205
|
+
bbox.expandByPoint({ x: x1, y: y1 });
|
|
206
|
+
bbox.expandByPoint({ x: x2, y: y2 });
|
|
207
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
208
|
+
const markerId = `dim-diameter-arrow-${Date.now()}`;
|
|
209
|
+
markers.push(createArrowMarker(markerId, arrowSize, dimLineColor));
|
|
210
|
+
elements.push(
|
|
211
|
+
`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-end="url(#${markerId})" />`
|
|
212
|
+
);
|
|
213
|
+
const diameterText = entity.text ? `\u2300${entity.text}` : "\u2300";
|
|
214
|
+
const angle = Math.atan2(y2 - y1, x2 - x1);
|
|
215
|
+
const textRotation = angle * 180 / Math.PI;
|
|
216
|
+
elements.push(
|
|
217
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${diameterText}</text>`
|
|
218
|
+
);
|
|
219
|
+
return {
|
|
220
|
+
bbox,
|
|
221
|
+
element: `<defs>${markers.join("")}</defs><g>${elements.join("")}</g>`
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function renderRadialDimension(entity, dimStyle) {
|
|
225
|
+
const bbox = new import_vecks.Box2();
|
|
226
|
+
const elements = [];
|
|
227
|
+
const markers = [];
|
|
228
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5;
|
|
229
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
230
|
+
const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle);
|
|
231
|
+
const x1 = entity.measureStart?.x ?? 0;
|
|
232
|
+
const y1 = entity.measureStart?.y ?? 0;
|
|
233
|
+
const x2 = entity.measureEnd?.x ?? 0;
|
|
234
|
+
const y2 = entity.measureEnd?.y ?? 0;
|
|
235
|
+
const textX = entity.textMidpoint?.x ?? (x1 + x2) / 2;
|
|
236
|
+
const textY = entity.textMidpoint?.y ?? (y1 + y2) / 2;
|
|
237
|
+
bbox.expandByPoint({ x: x1, y: y1 });
|
|
238
|
+
bbox.expandByPoint({ x: x2, y: y2 });
|
|
239
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
240
|
+
const markerId = `dim-radius-arrow-${Date.now()}`;
|
|
241
|
+
markers.push(createArrowMarker(markerId, arrowSize, dimLineColor));
|
|
242
|
+
elements.push(
|
|
243
|
+
`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-end="url(#${markerId})" />`
|
|
244
|
+
);
|
|
245
|
+
const radiusText = entity.text ? `R${entity.text}` : "R";
|
|
246
|
+
const angle = Math.atan2(y2 - y1, x2 - x1);
|
|
247
|
+
const textRotation = angle * 180 / Math.PI;
|
|
248
|
+
elements.push(
|
|
249
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${radiusText}</text>`
|
|
250
|
+
);
|
|
251
|
+
return {
|
|
252
|
+
bbox,
|
|
253
|
+
element: `<defs>${markers.join("")}</defs><g>${elements.join("")}</g>`
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function renderOrdinateDimension(entity, dimStyle) {
|
|
257
|
+
const bbox = new import_vecks.Box2();
|
|
258
|
+
const elements = [];
|
|
259
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
260
|
+
const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle);
|
|
261
|
+
const x1 = entity.measureStart?.x ?? 0;
|
|
262
|
+
const y1 = entity.measureStart?.y ?? 0;
|
|
263
|
+
const x2 = entity.start?.x ?? 0;
|
|
264
|
+
const y2 = entity.start?.y ?? 0;
|
|
265
|
+
const textX = entity.textMidpoint?.x ?? x2;
|
|
266
|
+
const textY = entity.textMidpoint?.y ?? y2;
|
|
267
|
+
bbox.expandByPoint({ x: x1, y: y1 });
|
|
268
|
+
bbox.expandByPoint({ x: x2, y: y2 });
|
|
269
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
270
|
+
elements.push(
|
|
271
|
+
`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" />`
|
|
272
|
+
);
|
|
273
|
+
if (entity.text) {
|
|
274
|
+
const angle = Math.atan2(y2 - y1, x2 - x1);
|
|
275
|
+
const textRotation = angle * 180 / Math.PI;
|
|
276
|
+
elements.push(
|
|
277
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
bbox,
|
|
282
|
+
element: `<g>${elements.join("")}</g>`
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function renderFallbackDimension(entity) {
|
|
286
|
+
const bbox = new import_vecks.Box2();
|
|
287
|
+
const elements = [];
|
|
288
|
+
if (entity.textMidpoint) {
|
|
289
|
+
const textX = entity.textMidpoint.x ?? 0;
|
|
290
|
+
const textY = entity.textMidpoint.y ?? 0;
|
|
291
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
292
|
+
if (entity.text) {
|
|
293
|
+
elements.push(
|
|
294
|
+
`<text x="${textX}" y="${textY}" font-size="2.5" text-anchor="middle" transform="scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
bbox,
|
|
300
|
+
element: `<g>${elements.join("")}</g>`
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
304
|
+
0 && (module.exports = {
|
|
305
|
+
createArrowMarker
|
|
306
|
+
});
|
|
307
|
+
//# sourceMappingURL=dimensionToSVG.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/dimensionToSVG.ts"],
|
|
4
|
+
"sourcesContent": ["import { Box2 } from 'vecks'\n\nimport colors from './util/colors'\n\nimport type { DimensionEntity } from './types'\nimport type { DimStyleTable } from './types/dxf'\nimport type { BoundsAndElement } from './types/svg'\n\n/**\n * Convert DXF color number to SVG color string\n */\nfunction colorNumberToSVG(colorNumber?: number): string {\n if (colorNumber === undefined || colorNumber < 0) {\n return 'currentColor'\n }\n\n // DXF color 0 is ByBlock, 256 is ByLayer, 7 is white/black (depends on bg)\n if (colorNumber === 0 || colorNumber === 256) {\n return 'currentColor'\n }\n\n // Get RGB from color table\n const rgb = colors[colorNumber]\n if (!rgb) {\n return 'currentColor'\n }\n\n return `rgb(${rgb[0]},${rgb[1]},${rgb[2]})`\n}\n\n/**\n * Get dimension colors and weights from DIMSTYLE with defaults\n */\nfunction getDimensionColors(dimStyle?: DimStyleTable): {\n dimLineColor: string\n extLineColor: string\n textColor: string\n dimLineWeight: number\n extLineWeight: number\n} {\n return {\n dimLineColor: colorNumberToSVG(dimStyle?.dimClrd),\n extLineColor: colorNumberToSVG(dimStyle?.dimClre),\n textColor: colorNumberToSVG(dimStyle?.dimClrt),\n dimLineWeight: dimStyle?.dimLwd ?? 0.5,\n extLineWeight: dimStyle?.dimLwe ?? 0.5,\n }\n}\n\n/**\n * Render DIMENSION entity to SVG with proper DIMSTYLE support\n */\nexport default function dimensionToSVG(\n entity: DimensionEntity,\n dimStyle?: DimStyleTable,\n): BoundsAndElement {\n // Dispatch to appropriate renderer based on dimension type\n switch (entity.dimensionType) {\n case 0: // Rotated, horizontal, or vertical\n case 1: // Aligned\n return renderLinearDimension(entity, dimStyle)\n case 2: // Angular\n return renderAngularDimension(entity, dimStyle)\n case 3: // Diameter\n return renderDiameterDimension(entity, dimStyle)\n case 4: // Radius\n return renderRadialDimension(entity, dimStyle)\n case 6: // Ordinate\n return renderOrdinateDimension(entity, dimStyle)\n default:\n // Fallback to simple line rendering\n return renderFallbackDimension(entity)\n }\n}\n\n/**\n * Create SVG marker definition for dimension arrows\n */\nexport function createArrowMarker(\n id: string,\n size: number,\n color: string,\n): string {\n const arrowPath = `M 0 0 L ${size} ${size / 2} L 0 ${size} z`\n return `<marker id=\"${id}\" markerWidth=\"${size}\" markerHeight=\"${size}\" refX=\"${size}\" refY=\"${size / 2}\" orient=\"auto\" markerUnits=\"strokeWidth\">\n <path d=\"${arrowPath}\" fill=\"${color}\" />\n </marker>`\n}\n\n/**\n * Render linear dimension (rotated, horizontal, vertical, or aligned)\n */\nfunction renderLinearDimension(\n entity: DimensionEntity,\n dimStyle?: DimStyleTable,\n): BoundsAndElement {\n const bbox = new Box2()\n const elements: string[] = []\n const markers: string[] = []\n\n // Get dimension style properties with defaults\n const arrowSize = dimStyle?.dimAsz ?? 2.5\n const textHeight = dimStyle?.dimTxt ?? 2.5\n const extLineOffset = dimStyle?.dimExo ?? 0.625\n const extLineExtension = dimStyle?.dimExe ?? 1.25\n const { dimLineColor, extLineColor, textColor, dimLineWeight, extLineWeight } = getDimensionColors(dimStyle)\n\n // Extract dimension geometry\n const defPoint1X = entity.measureStart?.x ?? 0\n const defPoint1Y = entity.measureStart?.y ?? 0\n const defPoint2X = entity.measureEnd?.x ?? 0\n const defPoint2Y = entity.measureEnd?.y ?? 0\n const dimLineY = entity.start?.y ?? 0\n const textX = entity.textMidpoint?.x ?? (defPoint1X + defPoint2X) / 2\n const textY = entity.textMidpoint?.y ?? (defPoint1Y + defPoint2Y) / 2\n\n // Calculate dimension line angle\n const angle = Math.atan2(defPoint2Y - defPoint1Y, defPoint2X - defPoint1X)\n const perpAngle = angle + Math.PI / 2\n\n // Calculate dimension line endpoints\n const dimLine1X = defPoint1X + Math.cos(perpAngle) * (dimLineY - defPoint1Y)\n const dimLine1Y = defPoint1Y + Math.sin(perpAngle) * (dimLineY - defPoint1Y)\n const dimLine2X = defPoint2X + Math.cos(perpAngle) * (dimLineY - defPoint2Y)\n const dimLine2Y = defPoint2Y + Math.sin(perpAngle) * (dimLineY - defPoint2Y)\n\n // Expand bounding box\n bbox.expandByPoint({ x: defPoint1X, y: defPoint1Y })\n bbox.expandByPoint({ x: defPoint2X, y: defPoint2Y })\n bbox.expandByPoint({ x: dimLine1X, y: dimLine1Y })\n bbox.expandByPoint({ x: dimLine2X, y: dimLine2Y })\n bbox.expandByPoint({ x: textX, y: textY })\n\n // Create unique marker IDs for arrows\n const markerId1 = `dim-arrow-start-${Date.now()}`\n const markerId2 = `dim-arrow-end-${Date.now()}`\n\n // Create arrow markers with dimension line color\n markers.push(\n createArrowMarker(markerId1, arrowSize, dimLineColor),\n createArrowMarker(markerId2, arrowSize, dimLineColor),\n )\n\n // Draw extension lines\n const extLine1StartX = defPoint1X + Math.cos(perpAngle) * extLineOffset\n const extLine1StartY = defPoint1Y + Math.sin(perpAngle) * extLineOffset\n const extLine1EndX = dimLine1X + Math.cos(perpAngle) * extLineExtension\n const extLine1EndY = dimLine1Y + Math.sin(perpAngle) * extLineExtension\n\n const extLine2StartX = defPoint2X + Math.cos(perpAngle) * extLineOffset\n const extLine2StartY = defPoint2Y + Math.sin(perpAngle) * extLineOffset\n const extLine2EndX = dimLine2X + Math.cos(perpAngle) * extLineExtension\n const extLine2EndY = dimLine2Y + Math.sin(perpAngle) * extLineExtension\n\n elements.push(\n `<line x1=\"${extLine1StartX}\" y1=\"${extLine1StartY}\" x2=\"${extLine1EndX}\" y2=\"${extLine1EndY}\" stroke=\"${extLineColor}\" stroke-width=\"${extLineWeight}\" />`,\n `<line x1=\"${extLine2StartX}\" y1=\"${extLine2StartY}\" x2=\"${extLine2EndX}\" y2=\"${extLine2EndY}\" stroke=\"${extLineColor}\" stroke-width=\"${extLineWeight}\" />`,\n `<line x1=\"${dimLine1X}\" y1=\"${dimLine1Y}\" x2=\"${dimLine2X}\" y2=\"${dimLine2Y}\" stroke=\"${dimLineColor}\" stroke-width=\"${dimLineWeight}\" marker-start=\"url(#${markerId1})\" marker-end=\"url(#${markerId2})\" />`,\n )\n\n // Add dimension text\n if (entity.text) {\n const textRotation = (angle * 180) / Math.PI\n elements.push(\n `<text x=\"${textX}\" y=\"${textY}\" font-size=\"${textHeight}\" fill=\"${textColor}\" text-anchor=\"middle\" transform=\"rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})\">${entity.text}</text>`,\n )\n }\n\n return {\n bbox,\n element: `<defs>${markers.join('')}</defs><g>${elements.join('')}</g>`,\n }\n}\n\n/**\n * Render angular dimension\n */\nfunction renderAngularDimension(\n entity: DimensionEntity,\n dimStyle?: DimStyleTable,\n): BoundsAndElement {\n const bbox = new Box2()\n const elements: string[] = []\n const markers: string[] = []\n\n // Get dimension style properties\n const arrowSize = dimStyle?.dimAsz ?? 2.5\n const textHeight = dimStyle?.dimTxt ?? 2.5\n const { dimLineColor, extLineColor, textColor, dimLineWeight, extLineWeight } = getDimensionColors(dimStyle)\n\n // Extract points\n const centerX = entity.start?.x ?? 0\n const centerY = entity.start?.y ?? 0\n const x1 = entity.measureStart?.x ?? 0\n const y1 = entity.measureStart?.y ?? 0\n const x2 = entity.measureEnd?.x ?? 0\n const y2 = entity.measureEnd?.y ?? 0\n const textX = entity.textMidpoint?.x ?? centerX\n const textY = entity.textMidpoint?.y ?? centerY\n\n bbox.expandByPoint({ x: centerX, y: centerY })\n bbox.expandByPoint({ x: x1, y: y1 })\n bbox.expandByPoint({ x: x2, y: y2 })\n bbox.expandByPoint({ x: textX, y: textY })\n\n // Create arrow markers\n const markerId1 = `dim-angular-arrow-start-${Date.now()}`\n const markerId2 = `dim-angular-arrow-end-${Date.now()}`\n markers.push(\n createArrowMarker(markerId1, arrowSize, dimLineColor),\n createArrowMarker(markerId2, arrowSize, dimLineColor),\n )\n\n // Draw extension lines from center to definition points\n elements.push(\n `<line x1=\"${centerX}\" y1=\"${centerY}\" x2=\"${x1}\" y2=\"${y1}\" stroke=\"${extLineColor}\" stroke-width=\"${extLineWeight}\" />`,\n `<line x1=\"${centerX}\" y1=\"${centerY}\" x2=\"${x2}\" y2=\"${y2}\" stroke=\"${extLineColor}\" stroke-width=\"${extLineWeight}\" />`,\n )\n\n // Calculate arc radius (distance from center to text midpoint)\n const radius = Math.hypot(textX - centerX, textY - centerY)\n const startAngle = Math.atan2(y1 - centerY, x1 - centerX)\n const endAngle = Math.atan2(y2 - centerY, x2 - centerX)\n\n // Draw arc for angular dimension\n const largeArcFlag = Math.abs(endAngle - startAngle) > Math.PI ? 1 : 0\n const arcStartX = centerX + radius * Math.cos(startAngle)\n const arcStartY = centerY + radius * Math.sin(startAngle)\n const arcEndX = centerX + radius * Math.cos(endAngle)\n const arcEndY = centerY + radius * Math.sin(endAngle)\n\n elements.push(\n `<path d=\"M ${arcStartX} ${arcStartY} A ${radius} ${radius} 0 ${largeArcFlag} 1 ${arcEndX} ${arcEndY}\" fill=\"none\" stroke=\"${dimLineColor}\" stroke-width=\"${dimLineWeight}\" marker-start=\"url(#${markerId1})\" marker-end=\"url(#${markerId2})\" />`,\n )\n\n // Add dimension text\n if (entity.text) {\n const midAngle = (startAngle + endAngle) / 2\n const textRotation = (midAngle * 180) / Math.PI\n\n elements.push(\n `<text x=\"${textX}\" y=\"${textY}\" font-size=\"${textHeight}\" fill=\"${textColor}\" text-anchor=\"middle\" transform=\"rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})\">${entity.text}</text>`,\n )\n }\n\n return {\n bbox,\n element: `<defs>${markers.join('')}</defs><g>${elements.join('')}</g>`,\n }\n}\n\n/**\n * Render diameter dimension\n */\nfunction renderDiameterDimension(\n entity: DimensionEntity,\n dimStyle?: DimStyleTable,\n): BoundsAndElement {\n const bbox = new Box2()\n const elements: string[] = []\n const markers: string[] = []\n\n // Get dimension style properties\n const arrowSize = dimStyle?.dimAsz ?? 2.5\n const textHeight = dimStyle?.dimTxt ?? 2.5\n const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle)\n\n // Extract geometry\n const x1 = entity.measureStart?.x ?? 0\n const y1 = entity.measureStart?.y ?? 0\n const x2 = entity.measureEnd?.x ?? 0\n const y2 = entity.measureEnd?.y ?? 0\n const textX = entity.textMidpoint?.x ?? (x1 + x2) / 2\n const textY = entity.textMidpoint?.y ?? (y1 + y2) / 2\n\n bbox.expandByPoint({ x: x1, y: y1 })\n bbox.expandByPoint({ x: x2, y: y2 })\n bbox.expandByPoint({ x: textX, y: textY })\n\n // Create arrow markers\n const markerId = `dim-diameter-arrow-${Date.now()}`\n markers.push(createArrowMarker(markerId, arrowSize, dimLineColor))\n\n // Create diameter line with arrow at the end\n elements.push(\n `<line x1=\"${x1}\" y1=\"${y1}\" x2=\"${x2}\" y2=\"${y2}\" stroke=\"${dimLineColor}\" stroke-width=\"${dimLineWeight}\" marker-end=\"url(#${markerId})\" />`,\n )\n\n // Add dimension text with diameter symbol\n const diameterText = entity.text ? `\u2300${entity.text}` : '\u2300'\n const angle = Math.atan2(y2 - y1, x2 - x1)\n const textRotation = (angle * 180) / Math.PI\n\n elements.push(\n `<text x=\"${textX}\" y=\"${textY}\" font-size=\"${textHeight}\" fill=\"${textColor}\" text-anchor=\"middle\" transform=\"rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})\">${diameterText}</text>`,\n )\n\n return {\n bbox,\n element: `<defs>${markers.join('')}</defs><g>${elements.join('')}</g>`,\n }\n}\n\n/**\n * Render radial dimension\n */\nfunction renderRadialDimension(\n entity: DimensionEntity,\n dimStyle?: DimStyleTable,\n): BoundsAndElement {\n const bbox = new Box2()\n const elements: string[] = []\n const markers: string[] = []\n\n // Get dimension style properties\n const arrowSize = dimStyle?.dimAsz ?? 2.5\n const textHeight = dimStyle?.dimTxt ?? 2.5\n const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle)\n\n // Extract geometry\n const x1 = entity.measureStart?.x ?? 0\n const y1 = entity.measureStart?.y ?? 0\n const x2 = entity.measureEnd?.x ?? 0\n const y2 = entity.measureEnd?.y ?? 0\n const textX = entity.textMidpoint?.x ?? (x1 + x2) / 2\n const textY = entity.textMidpoint?.y ?? (y1 + y2) / 2\n\n bbox.expandByPoint({ x: x1, y: y1 })\n bbox.expandByPoint({ x: x2, y: y2 })\n bbox.expandByPoint({ x: textX, y: textY })\n\n // Create arrow markers\n const markerId = `dim-radius-arrow-${Date.now()}`\n markers.push(createArrowMarker(markerId, arrowSize, dimLineColor))\n\n // Create radius line with arrow at the end\n elements.push(\n `<line x1=\"${x1}\" y1=\"${y1}\" x2=\"${x2}\" y2=\"${y2}\" stroke=\"${dimLineColor}\" stroke-width=\"${dimLineWeight}\" marker-end=\"url(#${markerId})\" />`,\n )\n\n // Add dimension text with radius symbol\n const radiusText = entity.text ? `R${entity.text}` : 'R'\n const angle = Math.atan2(y2 - y1, x2 - x1)\n const textRotation = (angle * 180) / Math.PI\n\n elements.push(\n `<text x=\"${textX}\" y=\"${textY}\" font-size=\"${textHeight}\" fill=\"${textColor}\" text-anchor=\"middle\" transform=\"rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})\">${radiusText}</text>`,\n )\n\n return {\n bbox,\n element: `<defs>${markers.join('')}</defs><g>${elements.join('')}</g>`,\n }\n}\n\n/**\n * Render ordinate dimension\n */\nfunction renderOrdinateDimension(\n entity: DimensionEntity,\n dimStyle?: DimStyleTable,\n): BoundsAndElement {\n const bbox = new Box2()\n const elements: string[] = []\n\n // Get dimension style properties\n const textHeight = dimStyle?.dimTxt ?? 2.5\n const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle)\n\n // Extract geometry\n const x1 = entity.measureStart?.x ?? 0\n const y1 = entity.measureStart?.y ?? 0\n const x2 = entity.start?.x ?? 0\n const y2 = entity.start?.y ?? 0\n const textX = entity.textMidpoint?.x ?? x2\n const textY = entity.textMidpoint?.y ?? y2\n\n bbox.expandByPoint({ x: x1, y: y1 })\n bbox.expandByPoint({ x: x2, y: y2 })\n bbox.expandByPoint({ x: textX, y: textY })\n\n // Create leader line (no arrow for ordinate dimensions)\n elements.push(\n `<line x1=\"${x1}\" y1=\"${y1}\" x2=\"${x2}\" y2=\"${y2}\" stroke=\"${dimLineColor}\" stroke-width=\"${dimLineWeight}\" />`,\n )\n\n // Add dimension text\n if (entity.text) {\n const angle = Math.atan2(y2 - y1, x2 - x1)\n const textRotation = (angle * 180) / Math.PI\n\n elements.push(\n `<text x=\"${textX}\" y=\"${textY}\" font-size=\"${textHeight}\" fill=\"${textColor}\" text-anchor=\"middle\" transform=\"rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})\">${entity.text}</text>`,\n )\n }\n\n return {\n bbox,\n element: `<g>${elements.join('')}</g>`,\n }\n}\n\n/**\n * Fallback renderer for unsupported dimension types\n */\nfunction renderFallbackDimension(entity: DimensionEntity): BoundsAndElement {\n const bbox = new Box2()\n const elements: string[] = []\n\n // Just render text at midpoint\n if (entity.textMidpoint) {\n const textX = entity.textMidpoint.x ?? 0\n const textY = entity.textMidpoint.y ?? 0\n bbox.expandByPoint({ x: textX, y: textY })\n\n if (entity.text) {\n elements.push(\n `<text x=\"${textX}\" y=\"${textY}\" font-size=\"2.5\" text-anchor=\"middle\" transform=\"scale(1,-1) translate(0 ${-2 * textY})\">${entity.text}</text>`,\n )\n }\n }\n\n return {\n bbox,\n element: `<g>${elements.join('')}</g>`,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqB;AAErB,oBAAmB;AASnB,SAAS,iBAAiB,aAA8B;AACtD,MAAI,gBAAgB,UAAa,cAAc,GAAG;AAChD,WAAO;AAAA,EACT;AAGA,MAAI,gBAAgB,KAAK,gBAAgB,KAAK;AAC5C,WAAO;AAAA,EACT;AAGA,QAAM,MAAM,cAAAA,QAAO,WAAW;AAC9B,MAAI,CAAC,KAAK;AACR,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;AAC1C;AAKA,SAAS,mBAAmB,UAM1B;AACA,SAAO;AAAA,IACL,cAAc,iBAAiB,UAAU,OAAO;AAAA,IAChD,cAAc,iBAAiB,UAAU,OAAO;AAAA,IAChD,WAAW,iBAAiB,UAAU,OAAO;AAAA,IAC7C,eAAe,UAAU,UAAU;AAAA,IACnC,eAAe,UAAU,UAAU;AAAA,EACrC;AACF;AAKe,SAAR,eACL,QACA,UACkB;AAElB,UAAQ,OAAO,eAAe;AAAA,IAC5B,KAAK;AAAA;AAAA,IACL,KAAK;AACH,aAAO,sBAAsB,QAAQ,QAAQ;AAAA,IAC/C,KAAK;AACH,aAAO,uBAAuB,QAAQ,QAAQ;AAAA,IAChD,KAAK;AACH,aAAO,wBA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AClC;AACF;AAKA,SAAS,wBAAwB,QAA2C;AAC1E,QAAM,OAAO,IAAI,kBAAK;AACtB,QAAM,WAAqB,CAAC;AAG5B,MAAI,OAAO,cAAc;AACvB,UAAM,QAAQ,OAAO,aAAa,KAAK;AACvC,UAAM,QAAQ,OAAO,aAAa,KAAK;AACvC,SAAK,cAAc,EAAE,GAAG,OAAO,GAAG,MAAM,CAAC;AAEzC,QAAI,OAAO,MAAM;AACf,eAAS;AAAA,QACP,YAAY,KAAK,QAAQ,KAAK,6EAA6E,KAAK,KAAK,MAAM,OAAO,IAAI;AAAA,MACxI;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,SAAS,MAAM,SAAS,KAAK,EAAE,CAAC;AAAA,EAClC;AACF;",
|
|
6
|
+
"names": ["colors"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { Box2 } from "vecks";
|
|
2
|
+
import colors from "./util/colors";
|
|
3
|
+
function colorNumberToSVG(colorNumber) {
|
|
4
|
+
if (colorNumber === void 0 || colorNumber < 0) {
|
|
5
|
+
return "currentColor";
|
|
6
|
+
}
|
|
7
|
+
if (colorNumber === 0 || colorNumber === 256) {
|
|
8
|
+
return "currentColor";
|
|
9
|
+
}
|
|
10
|
+
const rgb = colors[colorNumber];
|
|
11
|
+
if (!rgb) {
|
|
12
|
+
return "currentColor";
|
|
13
|
+
}
|
|
14
|
+
return `rgb(${rgb[0]},${rgb[1]},${rgb[2]})`;
|
|
15
|
+
}
|
|
16
|
+
function getDimensionColors(dimStyle) {
|
|
17
|
+
return {
|
|
18
|
+
dimLineColor: colorNumberToSVG(dimStyle?.dimClrd),
|
|
19
|
+
extLineColor: colorNumberToSVG(dimStyle?.dimClre),
|
|
20
|
+
textColor: colorNumberToSVG(dimStyle?.dimClrt),
|
|
21
|
+
dimLineWeight: dimStyle?.dimLwd ?? 0.5,
|
|
22
|
+
extLineWeight: dimStyle?.dimLwe ?? 0.5
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function dimensionToSVG(entity, dimStyle) {
|
|
26
|
+
switch (entity.dimensionType) {
|
|
27
|
+
case 0:
|
|
28
|
+
// Rotated, horizontal, or vertical
|
|
29
|
+
case 1:
|
|
30
|
+
return renderLinearDimension(entity, dimStyle);
|
|
31
|
+
case 2:
|
|
32
|
+
return renderAngularDimension(entity, dimStyle);
|
|
33
|
+
case 3:
|
|
34
|
+
return renderDiameterDimension(entity, dimStyle);
|
|
35
|
+
case 4:
|
|
36
|
+
return renderRadialDimension(entity, dimStyle);
|
|
37
|
+
case 6:
|
|
38
|
+
return renderOrdinateDimension(entity, dimStyle);
|
|
39
|
+
default:
|
|
40
|
+
return renderFallbackDimension(entity);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function createArrowMarker(id, size, color) {
|
|
44
|
+
const arrowPath = `M 0 0 L ${size} ${size / 2} L 0 ${size} z`;
|
|
45
|
+
return `<marker id="${id}" markerWidth="${size}" markerHeight="${size}" refX="${size}" refY="${size / 2}" orient="auto" markerUnits="strokeWidth">
|
|
46
|
+
<path d="${arrowPath}" fill="${color}" />
|
|
47
|
+
</marker>`;
|
|
48
|
+
}
|
|
49
|
+
function renderLinearDimension(entity, dimStyle) {
|
|
50
|
+
const bbox = new Box2();
|
|
51
|
+
const elements = [];
|
|
52
|
+
const markers = [];
|
|
53
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5;
|
|
54
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
55
|
+
const extLineOffset = dimStyle?.dimExo ?? 0.625;
|
|
56
|
+
const extLineExtension = dimStyle?.dimExe ?? 1.25;
|
|
57
|
+
const { dimLineColor, extLineColor, textColor, dimLineWeight, extLineWeight } = getDimensionColors(dimStyle);
|
|
58
|
+
const defPoint1X = entity.measureStart?.x ?? 0;
|
|
59
|
+
const defPoint1Y = entity.measureStart?.y ?? 0;
|
|
60
|
+
const defPoint2X = entity.measureEnd?.x ?? 0;
|
|
61
|
+
const defPoint2Y = entity.measureEnd?.y ?? 0;
|
|
62
|
+
const dimLineY = entity.start?.y ?? 0;
|
|
63
|
+
const textX = entity.textMidpoint?.x ?? (defPoint1X + defPoint2X) / 2;
|
|
64
|
+
const textY = entity.textMidpoint?.y ?? (defPoint1Y + defPoint2Y) / 2;
|
|
65
|
+
const angle = Math.atan2(defPoint2Y - defPoint1Y, defPoint2X - defPoint1X);
|
|
66
|
+
const perpAngle = angle + Math.PI / 2;
|
|
67
|
+
const dimLine1X = defPoint1X + Math.cos(perpAngle) * (dimLineY - defPoint1Y);
|
|
68
|
+
const dimLine1Y = defPoint1Y + Math.sin(perpAngle) * (dimLineY - defPoint1Y);
|
|
69
|
+
const dimLine2X = defPoint2X + Math.cos(perpAngle) * (dimLineY - defPoint2Y);
|
|
70
|
+
const dimLine2Y = defPoint2Y + Math.sin(perpAngle) * (dimLineY - defPoint2Y);
|
|
71
|
+
bbox.expandByPoint({ x: defPoint1X, y: defPoint1Y });
|
|
72
|
+
bbox.expandByPoint({ x: defPoint2X, y: defPoint2Y });
|
|
73
|
+
bbox.expandByPoint({ x: dimLine1X, y: dimLine1Y });
|
|
74
|
+
bbox.expandByPoint({ x: dimLine2X, y: dimLine2Y });
|
|
75
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
76
|
+
const markerId1 = `dim-arrow-start-${Date.now()}`;
|
|
77
|
+
const markerId2 = `dim-arrow-end-${Date.now()}`;
|
|
78
|
+
markers.push(
|
|
79
|
+
createArrowMarker(markerId1, arrowSize, dimLineColor),
|
|
80
|
+
createArrowMarker(markerId2, arrowSize, dimLineColor)
|
|
81
|
+
);
|
|
82
|
+
const extLine1StartX = defPoint1X + Math.cos(perpAngle) * extLineOffset;
|
|
83
|
+
const extLine1StartY = defPoint1Y + Math.sin(perpAngle) * extLineOffset;
|
|
84
|
+
const extLine1EndX = dimLine1X + Math.cos(perpAngle) * extLineExtension;
|
|
85
|
+
const extLine1EndY = dimLine1Y + Math.sin(perpAngle) * extLineExtension;
|
|
86
|
+
const extLine2StartX = defPoint2X + Math.cos(perpAngle) * extLineOffset;
|
|
87
|
+
const extLine2StartY = defPoint2Y + Math.sin(perpAngle) * extLineOffset;
|
|
88
|
+
const extLine2EndX = dimLine2X + Math.cos(perpAngle) * extLineExtension;
|
|
89
|
+
const extLine2EndY = dimLine2Y + Math.sin(perpAngle) * extLineExtension;
|
|
90
|
+
elements.push(
|
|
91
|
+
`<line x1="${extLine1StartX}" y1="${extLine1StartY}" x2="${extLine1EndX}" y2="${extLine1EndY}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
92
|
+
`<line x1="${extLine2StartX}" y1="${extLine2StartY}" x2="${extLine2EndX}" y2="${extLine2EndY}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
93
|
+
`<line x1="${dimLine1X}" y1="${dimLine1Y}" x2="${dimLine2X}" y2="${dimLine2Y}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-start="url(#${markerId1})" marker-end="url(#${markerId2})" />`
|
|
94
|
+
);
|
|
95
|
+
if (entity.text) {
|
|
96
|
+
const textRotation = angle * 180 / Math.PI;
|
|
97
|
+
elements.push(
|
|
98
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
bbox,
|
|
103
|
+
element: `<defs>${markers.join("")}</defs><g>${elements.join("")}</g>`
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function renderAngularDimension(entity, dimStyle) {
|
|
107
|
+
const bbox = new Box2();
|
|
108
|
+
const elements = [];
|
|
109
|
+
const markers = [];
|
|
110
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5;
|
|
111
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
112
|
+
const { dimLineColor, extLineColor, textColor, dimLineWeight, extLineWeight } = getDimensionColors(dimStyle);
|
|
113
|
+
const centerX = entity.start?.x ?? 0;
|
|
114
|
+
const centerY = entity.start?.y ?? 0;
|
|
115
|
+
const x1 = entity.measureStart?.x ?? 0;
|
|
116
|
+
const y1 = entity.measureStart?.y ?? 0;
|
|
117
|
+
const x2 = entity.measureEnd?.x ?? 0;
|
|
118
|
+
const y2 = entity.measureEnd?.y ?? 0;
|
|
119
|
+
const textX = entity.textMidpoint?.x ?? centerX;
|
|
120
|
+
const textY = entity.textMidpoint?.y ?? centerY;
|
|
121
|
+
bbox.expandByPoint({ x: centerX, y: centerY });
|
|
122
|
+
bbox.expandByPoint({ x: x1, y: y1 });
|
|
123
|
+
bbox.expandByPoint({ x: x2, y: y2 });
|
|
124
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
125
|
+
const markerId1 = `dim-angular-arrow-start-${Date.now()}`;
|
|
126
|
+
const markerId2 = `dim-angular-arrow-end-${Date.now()}`;
|
|
127
|
+
markers.push(
|
|
128
|
+
createArrowMarker(markerId1, arrowSize, dimLineColor),
|
|
129
|
+
createArrowMarker(markerId2, arrowSize, dimLineColor)
|
|
130
|
+
);
|
|
131
|
+
elements.push(
|
|
132
|
+
`<line x1="${centerX}" y1="${centerY}" x2="${x1}" y2="${y1}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
133
|
+
`<line x1="${centerX}" y1="${centerY}" x2="${x2}" y2="${y2}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`
|
|
134
|
+
);
|
|
135
|
+
const radius = Math.hypot(textX - centerX, textY - centerY);
|
|
136
|
+
const startAngle = Math.atan2(y1 - centerY, x1 - centerX);
|
|
137
|
+
const endAngle = Math.atan2(y2 - centerY, x2 - centerX);
|
|
138
|
+
const largeArcFlag = Math.abs(endAngle - startAngle) > Math.PI ? 1 : 0;
|
|
139
|
+
const arcStartX = centerX + radius * Math.cos(startAngle);
|
|
140
|
+
const arcStartY = centerY + radius * Math.sin(startAngle);
|
|
141
|
+
const arcEndX = centerX + radius * Math.cos(endAngle);
|
|
142
|
+
const arcEndY = centerY + radius * Math.sin(endAngle);
|
|
143
|
+
elements.push(
|
|
144
|
+
`<path d="M ${arcStartX} ${arcStartY} A ${radius} ${radius} 0 ${largeArcFlag} 1 ${arcEndX} ${arcEndY}" fill="none" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-start="url(#${markerId1})" marker-end="url(#${markerId2})" />`
|
|
145
|
+
);
|
|
146
|
+
if (entity.text) {
|
|
147
|
+
const midAngle = (startAngle + endAngle) / 2;
|
|
148
|
+
const textRotation = midAngle * 180 / Math.PI;
|
|
149
|
+
elements.push(
|
|
150
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
bbox,
|
|
155
|
+
element: `<defs>${markers.join("")}</defs><g>${elements.join("")}</g>`
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function renderDiameterDimension(entity, dimStyle) {
|
|
159
|
+
const bbox = new Box2();
|
|
160
|
+
const elements = [];
|
|
161
|
+
const markers = [];
|
|
162
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5;
|
|
163
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
164
|
+
const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle);
|
|
165
|
+
const x1 = entity.measureStart?.x ?? 0;
|
|
166
|
+
const y1 = entity.measureStart?.y ?? 0;
|
|
167
|
+
const x2 = entity.measureEnd?.x ?? 0;
|
|
168
|
+
const y2 = entity.measureEnd?.y ?? 0;
|
|
169
|
+
const textX = entity.textMidpoint?.x ?? (x1 + x2) / 2;
|
|
170
|
+
const textY = entity.textMidpoint?.y ?? (y1 + y2) / 2;
|
|
171
|
+
bbox.expandByPoint({ x: x1, y: y1 });
|
|
172
|
+
bbox.expandByPoint({ x: x2, y: y2 });
|
|
173
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
174
|
+
const markerId = `dim-diameter-arrow-${Date.now()}`;
|
|
175
|
+
markers.push(createArrowMarker(markerId, arrowSize, dimLineColor));
|
|
176
|
+
elements.push(
|
|
177
|
+
`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-end="url(#${markerId})" />`
|
|
178
|
+
);
|
|
179
|
+
const diameterText = entity.text ? `\u2300${entity.text}` : "\u2300";
|
|
180
|
+
const angle = Math.atan2(y2 - y1, x2 - x1);
|
|
181
|
+
const textRotation = angle * 180 / Math.PI;
|
|
182
|
+
elements.push(
|
|
183
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${diameterText}</text>`
|
|
184
|
+
);
|
|
185
|
+
return {
|
|
186
|
+
bbox,
|
|
187
|
+
element: `<defs>${markers.join("")}</defs><g>${elements.join("")}</g>`
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function renderRadialDimension(entity, dimStyle) {
|
|
191
|
+
const bbox = new Box2();
|
|
192
|
+
const elements = [];
|
|
193
|
+
const markers = [];
|
|
194
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5;
|
|
195
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
196
|
+
const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle);
|
|
197
|
+
const x1 = entity.measureStart?.x ?? 0;
|
|
198
|
+
const y1 = entity.measureStart?.y ?? 0;
|
|
199
|
+
const x2 = entity.measureEnd?.x ?? 0;
|
|
200
|
+
const y2 = entity.measureEnd?.y ?? 0;
|
|
201
|
+
const textX = entity.textMidpoint?.x ?? (x1 + x2) / 2;
|
|
202
|
+
const textY = entity.textMidpoint?.y ?? (y1 + y2) / 2;
|
|
203
|
+
bbox.expandByPoint({ x: x1, y: y1 });
|
|
204
|
+
bbox.expandByPoint({ x: x2, y: y2 });
|
|
205
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
206
|
+
const markerId = `dim-radius-arrow-${Date.now()}`;
|
|
207
|
+
markers.push(createArrowMarker(markerId, arrowSize, dimLineColor));
|
|
208
|
+
elements.push(
|
|
209
|
+
`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-end="url(#${markerId})" />`
|
|
210
|
+
);
|
|
211
|
+
const radiusText = entity.text ? `R${entity.text}` : "R";
|
|
212
|
+
const angle = Math.atan2(y2 - y1, x2 - x1);
|
|
213
|
+
const textRotation = angle * 180 / Math.PI;
|
|
214
|
+
elements.push(
|
|
215
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${radiusText}</text>`
|
|
216
|
+
);
|
|
217
|
+
return {
|
|
218
|
+
bbox,
|
|
219
|
+
element: `<defs>${markers.join("")}</defs><g>${elements.join("")}</g>`
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function renderOrdinateDimension(entity, dimStyle) {
|
|
223
|
+
const bbox = new Box2();
|
|
224
|
+
const elements = [];
|
|
225
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5;
|
|
226
|
+
const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle);
|
|
227
|
+
const x1 = entity.measureStart?.x ?? 0;
|
|
228
|
+
const y1 = entity.measureStart?.y ?? 0;
|
|
229
|
+
const x2 = entity.start?.x ?? 0;
|
|
230
|
+
const y2 = entity.start?.y ?? 0;
|
|
231
|
+
const textX = entity.textMidpoint?.x ?? x2;
|
|
232
|
+
const textY = entity.textMidpoint?.y ?? y2;
|
|
233
|
+
bbox.expandByPoint({ x: x1, y: y1 });
|
|
234
|
+
bbox.expandByPoint({ x: x2, y: y2 });
|
|
235
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
236
|
+
elements.push(
|
|
237
|
+
`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" />`
|
|
238
|
+
);
|
|
239
|
+
if (entity.text) {
|
|
240
|
+
const angle = Math.atan2(y2 - y1, x2 - x1);
|
|
241
|
+
const textRotation = angle * 180 / Math.PI;
|
|
242
|
+
elements.push(
|
|
243
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
bbox,
|
|
248
|
+
element: `<g>${elements.join("")}</g>`
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function renderFallbackDimension(entity) {
|
|
252
|
+
const bbox = new Box2();
|
|
253
|
+
const elements = [];
|
|
254
|
+
if (entity.textMidpoint) {
|
|
255
|
+
const textX = entity.textMidpoint.x ?? 0;
|
|
256
|
+
const textY = entity.textMidpoint.y ?? 0;
|
|
257
|
+
bbox.expandByPoint({ x: textX, y: textY });
|
|
258
|
+
if (entity.text) {
|
|
259
|
+
elements.push(
|
|
260
|
+
`<text x="${textX}" y="${textY}" font-size="2.5" text-anchor="middle" transform="scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
bbox,
|
|
266
|
+
element: `<g>${elements.join("")}</g>`
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
export {
|
|
270
|
+
createArrowMarker,
|
|
271
|
+
dimensionToSVG as default
|
|
272
|
+
};
|
|
273
|
+
//# sourceMappingURL=dimensionToSVG.js.map
|