@mlightcad/cad-simple-viewer-cli 1.8.0-preview.2 → 1.8.0-preview.3

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,4 +1,4 @@
1
- import{U as at,G as rt,v as ot,a as N,A as Q,j as ht,d as lt,p as ct,b as L,c as tt,e as ut,f as mt,g as et,h as xt,i as gt,k as ft,l as pt,m as H,n as dt,o as O,q as W,r as yt,M as bt,s as vt,t as B,u as w,w as p,x as E,T,X as wt,y as St}from"./index-ugurFpJq.js";import{z as Me,B as Ce}from"./index-ugurFpJq.js";const k=1e10;function _t(r){return Math.max(r.maxX-r.minX,r.maxY-r.minY)>=k?!0:Math.abs(r.minX)>=k||Math.abs(r.minY)>=k||Math.abs(r.maxX)>=k||Math.abs(r.maxY)>=k}function it(r){return r.isEmpty()?!1:Number.isFinite(r.min.x)&&Number.isFinite(r.min.y)&&Number.isFinite(r.max.x)&&Number.isFinite(r.max.y)}function Tt(r){const t=[];for(const l of r)it(l)&&t.push({minX:l.min.x,minY:l.min.y,maxX:l.max.x,maxY:l.max.y});if(t.length===0)return new L;const e=t.filter(l=>!_t(l));if(e.length===0)return new L;const i=e.map(l=>Math.max(l.maxX-l.minX,l.maxY-l.minY,1e-9));i.sort((l,c)=>l-c);const s=i[Math.floor(i.length/2)]||1,n=Math.max(s*50,k),a=[];for(const l of e)Math.max(l.maxX-l.minX,l.maxY-l.minY)<n&&a.push(l);if(a.length===0)return new L;const o=Lt(a),h=Mt(o.length>0?o:a);return h?new L({x:h.minX,y:h.minY},{x:h.maxX,y:h.maxY}):new L}function Lt(r){if(r.length<2)return r;const t=r.map(c=>({x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2,box:c})),e=t.map(c=>c.x).sort((c,m)=>c-m),i=t.map(c=>c.y).sort((c,m)=>c-m),s=e[Math.floor(e.length/2)],n=i[Math.floor(i.length/2)],a=r.map(c=>Math.max(c.maxX-c.minX,c.maxY-c.minY,1e-9));a.sort((c,m)=>c-m);const o=a[Math.floor(a.length/2)]||1,h=Math.max(o*50,k),l=t.filter(c=>Math.hypot(c.x-s,c.y-n)<=h);return l.length>0?l.map(c=>c.box):r}function D(r,t){if(r.length<8)return r;const e=r.map(u=>({value:t==="x"?(u.minX+u.maxX)/2:(u.minY+u.maxY)/2,box:u})).sort((u,d)=>u.value-d.value),i=e[e.length-1].value-e[0].value;if(!(i>0))return r;let s=0,n=0;for(let u=1;u<e.length;u++){const d=e[u].value-e[u-1].value;d>s&&(s=d,n=u)}if(s<i*.2)return r;const a=e.slice(0,n),o=e.slice(n),h=a.length>=o.length?a:o,l=r.map(u=>Math.max(u.maxX-u.minX,u.maxY-u.minY,1e-9));l.sort((u,d)=>u-d);const c=l[Math.floor(l.length/2)]||1,m=[];for(let u=1;u<h.length;u++)m.push(h[u].value-h[u-1].value);m.sort((u,d)=>u-d);const f=m.length>0&&m[Math.floor(m.length/2)]||c,x=Math.max(f*10,c*20);return s<x?r:h.map(u=>u.box)}function G(r){if(r.length===0)return null;let t=1/0,e=1/0,i=-1/0,s=-1/0;for(const n of r)t=Math.min(t,n.minX),e=Math.min(e,n.minY),i=Math.max(i,n.maxX),s=Math.max(s,n.maxY);return{minX:t,minY:e,maxX:i,maxY:s}}function Mt(r){if(r.length===0)return null;const t=G(r);if(r.length<8)return t;let e=r.slice(),i=-1;for(;e.length!==i;)i=e.length,e=D(e,"x"),e=D(e,"y");return G(e)??t}class V{static toSvgTransform(t){const e=t.elements;return`matrix(${e[0]},${e[1]},${e[4]},${e[5]},${e[12]},${e[13]})`}static transformPoint(t,e){const i=t.elements,s=e.x,n=e.y,a=e.z??0,o=i[3]*s+i[7]*n+i[11]*a+i[15],h=o===0?1:1/o;return{x:(i[0]*s+i[4]*n+i[8]*a+i[12])*h,y:(i[1]*s+i[5]*n+i[9]*a+i[13])*h}}static transformBox(t,e){if(t.isEmpty())return;const i=t.min,s=t.max;if(!Number.isFinite(i.x)||!Number.isFinite(i.y)||!Number.isFinite(s.x)||!Number.isFinite(s.y)){t.makeEmpty();return}const n=[{x:i.x,y:i.y,z:0},{x:s.x,y:i.y,z:0},{x:s.x,y:s.y,z:0},{x:i.x,y:s.y,z:0}];let a=1/0,o=1/0,h=-1/0,l=-1/0;for(const c of n){const m=this.transformPoint(e,c);if(!Number.isFinite(m.x)||!Number.isFinite(m.y)){t.makeEmpty();return}a=Math.min(a,m.x),o=Math.min(o,m.y),h=Math.max(h,m.x),l=Math.max(l,m.y)}t.min.set(a,o),t.max.set(h,l)}}class y{constructor(){this._objectId="",this._ownerId="",this._layerName="",this._visible=!0,this._userData={},this._box=new L,this._localSvg="",this._children=[]}get box(){return this._box}set box(t){this._box.copy(t)}get basePoint(){return this._basePoint}set basePoint(t){t==null?this._basePoint=t:this._basePoint=this._basePoint?this._basePoint.copy(t):new yt(t)}get svg(){return this.renderSvg()}set svg(t){this._localSvg=t}getLocalSvg(){return this._localSvg}get childCount(){return this._children.length}renderSvg(){const t=[];this._localSvg&&t.push(this._localSvg);for(const i of this._children){const s=i.renderSvg();s&&t.push(s)}const e=t.join(`
1
+ import{U as at,G as rt,v as ot,a as N,A as Q,j as ht,d as lt,p as ct,b as L,c as tt,e as ut,f as mt,g as et,h as xt,i as gt,k as ft,l as pt,m as H,n as dt,o as O,q as W,r as yt,M as bt,s as vt,t as B,u as w,w as p,x as E,T,X as wt,y as St}from"./index-C50ZUySK.js";import{z as Me,B as Ce}from"./index-C50ZUySK.js";const k=1e10;function _t(r){return Math.max(r.maxX-r.minX,r.maxY-r.minY)>=k?!0:Math.abs(r.minX)>=k||Math.abs(r.minY)>=k||Math.abs(r.maxX)>=k||Math.abs(r.maxY)>=k}function it(r){return r.isEmpty()?!1:Number.isFinite(r.min.x)&&Number.isFinite(r.min.y)&&Number.isFinite(r.max.x)&&Number.isFinite(r.max.y)}function Tt(r){const t=[];for(const l of r)it(l)&&t.push({minX:l.min.x,minY:l.min.y,maxX:l.max.x,maxY:l.max.y});if(t.length===0)return new L;const e=t.filter(l=>!_t(l));if(e.length===0)return new L;const i=e.map(l=>Math.max(l.maxX-l.minX,l.maxY-l.minY,1e-9));i.sort((l,c)=>l-c);const s=i[Math.floor(i.length/2)]||1,n=Math.max(s*50,k),a=[];for(const l of e)Math.max(l.maxX-l.minX,l.maxY-l.minY)<n&&a.push(l);if(a.length===0)return new L;const o=Lt(a),h=Mt(o.length>0?o:a);return h?new L({x:h.minX,y:h.minY},{x:h.maxX,y:h.maxY}):new L}function Lt(r){if(r.length<2)return r;const t=r.map(c=>({x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2,box:c})),e=t.map(c=>c.x).sort((c,m)=>c-m),i=t.map(c=>c.y).sort((c,m)=>c-m),s=e[Math.floor(e.length/2)],n=i[Math.floor(i.length/2)],a=r.map(c=>Math.max(c.maxX-c.minX,c.maxY-c.minY,1e-9));a.sort((c,m)=>c-m);const o=a[Math.floor(a.length/2)]||1,h=Math.max(o*50,k),l=t.filter(c=>Math.hypot(c.x-s,c.y-n)<=h);return l.length>0?l.map(c=>c.box):r}function D(r,t){if(r.length<8)return r;const e=r.map(u=>({value:t==="x"?(u.minX+u.maxX)/2:(u.minY+u.maxY)/2,box:u})).sort((u,d)=>u.value-d.value),i=e[e.length-1].value-e[0].value;if(!(i>0))return r;let s=0,n=0;for(let u=1;u<e.length;u++){const d=e[u].value-e[u-1].value;d>s&&(s=d,n=u)}if(s<i*.2)return r;const a=e.slice(0,n),o=e.slice(n),h=a.length>=o.length?a:o,l=r.map(u=>Math.max(u.maxX-u.minX,u.maxY-u.minY,1e-9));l.sort((u,d)=>u-d);const c=l[Math.floor(l.length/2)]||1,m=[];for(let u=1;u<h.length;u++)m.push(h[u].value-h[u-1].value);m.sort((u,d)=>u-d);const f=m.length>0&&m[Math.floor(m.length/2)]||c,x=Math.max(f*10,c*20);return s<x?r:h.map(u=>u.box)}function G(r){if(r.length===0)return null;let t=1/0,e=1/0,i=-1/0,s=-1/0;for(const n of r)t=Math.min(t,n.minX),e=Math.min(e,n.minY),i=Math.max(i,n.maxX),s=Math.max(s,n.maxY);return{minX:t,minY:e,maxX:i,maxY:s}}function Mt(r){if(r.length===0)return null;const t=G(r);if(r.length<8)return t;let e=r.slice(),i=-1;for(;e.length!==i;)i=e.length,e=D(e,"x"),e=D(e,"y");return G(e)??t}class V{static toSvgTransform(t){const e=t.elements;return`matrix(${e[0]},${e[1]},${e[4]},${e[5]},${e[12]},${e[13]})`}static transformPoint(t,e){const i=t.elements,s=e.x,n=e.y,a=e.z??0,o=i[3]*s+i[7]*n+i[11]*a+i[15],h=o===0?1:1/o;return{x:(i[0]*s+i[4]*n+i[8]*a+i[12])*h,y:(i[1]*s+i[5]*n+i[9]*a+i[13])*h}}static transformBox(t,e){if(t.isEmpty())return;const i=t.min,s=t.max;if(!Number.isFinite(i.x)||!Number.isFinite(i.y)||!Number.isFinite(s.x)||!Number.isFinite(s.y)){t.makeEmpty();return}const n=[{x:i.x,y:i.y,z:0},{x:s.x,y:i.y,z:0},{x:s.x,y:s.y,z:0},{x:i.x,y:s.y,z:0}];let a=1/0,o=1/0,h=-1/0,l=-1/0;for(const c of n){const m=this.transformPoint(e,c);if(!Number.isFinite(m.x)||!Number.isFinite(m.y)){t.makeEmpty();return}a=Math.min(a,m.x),o=Math.min(o,m.y),h=Math.max(h,m.x),l=Math.max(l,m.y)}t.min.set(a,o),t.max.set(h,l)}}class y{constructor(){this._objectId="",this._ownerId="",this._layerName="",this._visible=!0,this._userData={},this._box=new L,this._localSvg="",this._children=[]}get box(){return this._box}set box(t){this._box.copy(t)}get basePoint(){return this._basePoint}set basePoint(t){t==null?this._basePoint=t:this._basePoint=this._basePoint?this._basePoint.copy(t):new yt(t)}get svg(){return this.renderSvg()}set svg(t){this._localSvg=t}getLocalSvg(){return this._localSvg}get childCount(){return this._children.length}renderSvg(){const t=[];this._localSvg&&t.push(this._localSvg);for(const i of this._children){const s=i.renderSvg();s&&t.push(s)}const e=t.join(`
2
2
  `);return e?this._matrix?`<g transform="${V.toSvgTransform(this._matrix)}">
3
3
  ${e}
4
4
  </g>`:e:""}get objectId(){return this._objectId}set objectId(t){this._objectId=t}get ownerId(){return this._ownerId}set ownerId(t){this._ownerId=t}get layerName(){return this._layerName}set layerName(t){this._layerName=t}get visible(){return this._visible}set visible(t){this._visible=t}get userData(){return this._userData}set userData(t){this._userData=t}applyMatrix(t){this._matrix?this._matrix=t.clone().multiply(this._matrix):this._matrix=t.clone(),this.transformBoxesRecursive(t)}transformBoxesRecursive(t){V.transformBox(this._box,t);for(const e of this._children)e.transformBoxesRecursive(t)}recomputeBoundingBox(){}highlight(){}unhighlight(){}fastDeepClone(){const t=new y;t._objectId=this._objectId,t._ownerId=this._ownerId,t._layerName=this._layerName,t._visible=this._visible,t._userData=this._userData,t._localSvg=this._localSvg,t._box.copy(this._box),this._matrix&&(t._matrix=this._matrix.clone()),this._basePoint&&(t._basePoint=this._basePoint.clone());for(const e of this._children)t._children.push(e.fastDeepClone());return t}addChild(t){t instanceof y&&(this._children.push(t),it(t.box)&&this._box.union(t.box))}}class g{static rgbToHex(t){const e=t>>16&255,i=t>>8&255,s=t&255;return`#${e.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}static resolveRgb(t,e,i){return t.isBackgroundFill||i==="fill"&&t.color.isForeground&&this.isSolidBackgroundHatch(t)?e.backgroundColor:tt.fromBackgroundColor(e.backgroundColor).resolveSubEntityTraitsRgb(t)}static strokeAttributes(t,e){const i={stroke:this.rgbToHex(this.resolveRgb(t,e,"line")),fill:"none"};if(!e.showLineWeight)i["stroke-width"]="1",i["vector-effect"]="non-scaling-stroke";else{const a=this.resolveStrokeWidth(t.lineWeight);a!=null&&(i["stroke-width"]=String(a))}const s=this.resolveOpacity(t);s!=null&&s<1&&(i["stroke-opacity"]=String(s));const n=this.strokeDasharray(t,e);return n&&(i["stroke-dasharray"]=n),i}static fillAttributes(t,e){const i={fill:this.rgbToHex(this.resolveRgb(t,e,"fill")),stroke:"none"},s=this.resolveOpacity(t);return s!=null&&s<1&&(i["fill-opacity"]=String(s)),i}static textAttributes(t,e){const i={fill:this.rgbToHex(this.resolveRgb(t,e,"text")),stroke:"none"},s=this.resolveOpacity(t);return s!=null&&s<1&&(i["fill-opacity"]=String(s)),i}static pointAttributes(t,e){return this.textAttributes(t,e)}static formatAttributes(t){return Object.entries(t).map(([e,i])=>`${e}="${Ct(i)}"`).join(" ")}static tag(t,e,i){const s=this.formatAttributes(e);return i==null?`<${t} ${s}/>`:`<${t} ${s}>${i}</${t}>`}static isSolidBackgroundHatch(t){if((t.drawOrder??0)>=0)return!1;const e=t.fillType;return e.gradient?!1:!e.definitionLines||e.definitionLines.length===0}static resolveStrokeWidth(t){return t<0?null:Math.max(.01,t/100)}static resolveOpacity(t){const e=t.transparency;if(!(e!=null&&e.isByAlpha))return null;const i=e.alpha;return i==null||Number.isNaN(i)||i<=0?null:Math.min(1,Math.max(0,i/255))}static strokeDasharray(t,e){const i=t.lineType.pattern;if(!i||i.length===0)return;const s=e.ltscale*e.celtscale*t.lineTypeScale,n=this.patternToDashSegments(i,s);if(n.length!==0)return n.join(" ")}static patternToDashSegments(t,e){const i=[];for(const s of t){let n=s.elementLength;n<0&&s.elementTypeFlag!==0&&(n=Math.abs(n)),n*=e,n===0&&(n=.5*e),i.push(Math.abs(n))}return i}}function Ct(r){return r.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}class At extends y{constructor(t,e,i,s){super();const n=t.tessellate(s);let a="";for(const o of n){if(o.length===0)continue;const[h,...l]=o;a+=`M${h.x},${h.y}`;for(const c of l)a+=` L${c.x},${c.y}`;a+=" Z";for(const c of o)this._box.expandByPoint(c)}if(a){const o={d:a,"fill-rule":"evenodd",...g.fillAttributes(e,i)};this.svg=g.tag("path",o)}}}class kt extends y{constructor(t,e,i,s){super();const n=t.tessellate(s),a=n.reduce((o,h,l)=>(o+=l===0?"M":"L",o+=`${h.x},${h.y}`,o),"");if(a){const o={d:a,...g.strokeAttributes(e,i)};this.svg=g.tag("path",o)}for(const o of n)this._box.expandByPoint(o)}}class Ft extends y{constructor(t,e,i,s){super();const n=t.tessellate(s),a=n.reduce((o,h,l)=>(o+=l===0?"M":"L",o+=`${h.x},${h.y}`,o),"");if(a){const o={d:a,...g.strokeAttributes(e,i)};this.svg=g.tag("path",o)}for(const o of n)this._box.expandByPoint(o)}}class F{static isSafeEmbeddedUrl(t){const e=t.trim();return e.startsWith("data:")||e.startsWith("#")}static sanitizeExternalReferences(t){return t.replace(/<(?:image|use)\b[^>]*\s(?:xlink:)?href="(?!data:|#)[^"]*"[^>]*\/?>\s*/gi,"")}static stripInvalidXmlChars(t){return t.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g,"")}static escapeXml(t){return F.stripInvalidXmlChars(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}static async rasterizeSvgDataUrl(t){return typeof document>"u"?t:new Promise((e,i)=>{const s=new Image;s.onload=()=>{const n=Math.max(1,s.naturalWidth||1),a=Math.max(1,s.naturalHeight||1),o=document.createElement("canvas");o.width=n,o.height=a;const h=o.getContext("2d");if(!h){i(new Error("Canvas 2D context unavailable"));return}h.drawImage(s,0,0,n,a),e(o.toDataURL("image/png"))},s.onerror=()=>i(new Error("Failed to rasterize embedded SVG image")),s.src=t})}}class Pt extends y{constructor(t){super();for(const e of t)this.addChild(e)}}class X extends y{constructor(t,e,i,s){super();const{boundary:n}=e;if(n.length<2||!F.isSafeEmbeddedUrl(t))return;let a=1/0,o=1/0,h=-1/0,l=-1/0;for(const x of n)x.x<a&&(a=x.x),x.y<o&&(o=x.y),x.x>h&&(h=x.x),x.y>l&&(l=x.y),this._box.expandByPoint(x);const c=h-a,m=l-o,f=Yt(t);this._localSvg=`<image x="${a}" y="${o}" width="${c}" height="${m}" href="${f}" xlink:href="${f}" transform="scale(1,-1) translate(0,${-(o*2+m)})"/>`}static async fromBlob(t,e,i,s){let n=await Rt(t);if(t.type==="image/svg+xml"||n.startsWith("data:image/svg+xml"))try{n=await F.rasterizeSvgDataUrl(n)}catch{return new X("",e,i,s)}return new X(n,e,i,s)}}function Rt(r){return new Promise((t,e)=>{const i=new FileReader;i.onload=()=>t(i.result),i.onerror=e,i.readAsDataURL(r)})}function Yt(r){return r.replace(/&/g,"&amp;").replace(/"/g,"&quot;")}class Bt extends y{constructor(t,e,i){super();const s=t.reduce((n,a,o)=>(n+=o===0?"M":"L",n+=a.x+","+a.y,this.box.expandByPoint(a),n),"");if(s){const n={d:s,...g.strokeAttributes(e,i)};this.svg=g.tag("path",n)}}}class Et extends y{constructor(t,e,i,s,n){super();const a=g.strokeAttributes(s,n),o=[];for(let h=0;h+1<i.length;h+=2){const l=i[h]*e,c=i[h+1]*e,m=t[l],f=t[l+1],x=t[c],u=t[c+1];o.push(g.tag("line",{x1:String(m),y1:String(f),x2:String(x),y2:String(u),...a})),this._box.expandByPoint({x:m,y:f}),this._box.expandByPoint({x,y:u})}this.svg=o.join(`
@@ -13,4 +13,4 @@ ${o}
13
13
  <g transform="matrix(1,0,0,-1,0,0)">
14
14
  ${e}
15
15
  </g>
16
- </svg>`);return F.stripInvalidXmlChars(h)}buildBackgroundRect(t){const e=g.rgbToHex(this._currentBackgroundColor),i=Math.max(t.width,1),s=Math.max(t.height,1);return` <rect x="${t.x}" y="${t.y}" width="${i}" height="${s}" fill="${e}"/>`}}const ge=new y;function fe(r,t){const e=Z(r),i=Z(t);if(e!==i||e<2)return null;const s=new Array(e+1);for(let a=0;a<e;a++){const o=r[a],h=t[a];s[a]={x:(o.x+h.x)*.5,y:(o.y+h.y)*.5,z:((o.z??0)+(h.z??0))*.5}}const n=s[0];return s[e]={x:n.x,y:n.y,z:n.z},s}function Z(r){const t=r.length;return t>1&&r[0].x===r[t-1].x&&r[0].y===r[t-1].y?t-1:t}const pe=200;class de{async convert(t){await ot.instance.withBusyIndicator(async()=>{await N(),J.prepareExport();const e=t.doc.database.tables.blockTable.modelSpace.newIterator(),i=new J;this.configureRenderer(i,t);const s=new Q(pe),n=()=>new Promise(l=>setTimeout(l,0)),a=[];for(const l of e){const c=l.worldDraw(i);c instanceof y&&a.push(c),await s.maybeYield(n)}await N();const o=await i.exportAsync(a);await N();const h=ht(t.doc.fileName||t.doc.docTitle,"svg");this.createFileAndDownloadIt(o,h)},lt.t("main.message.exportingSvg"))}configureRenderer(t,e){const i=e.doc.database;t.ltscale=i.ltscale,t.celtscale=i.celtscale,t.showLineWeight=!!i.lwdisplay,t.setFontMapping(ct.instance.fontMapping);const s=e.view,n=(s==null?void 0:s.backgroundColor)??16777215;t.currentBackgroundColor=n,t.changeForeground(n===0?16777215:0)}createFileAndDownloadIt(t,e){const i=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(i),n=document.createElement("a");n.href=s,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),window.setTimeout(()=>URL.revokeObjectURL(s),6e4)}}class ye extends rt{async execute(t){await new de().convert(t)}}const be="1.8.0-preview.2",ve={version:be};class we{constructor(){this.name="SvgPlugin",this.version=ve.version,this.description="SVG export (csvg) command",this.registeredCommands=[]}onLoad(t,e){const i=at.SYSTEMT_COMMAND_GROUP_NAME;e.addCommand(i,"csvg","csvg",new ye),this.registeredCommands.push({group:i,name:"csvg"})}onUnload(t,e){for(const i of this.registeredCommands)e.removeCmd(i.group,i.name);this.registeredCommands=[]}}async function _e(){return new we}export{ye as AcApConvertToSvgCmd,de as AcApSvgConvertor,J as AcSvgRenderer,Me as SVG_PLUGIN_NAME,Ce as SVG_PLUGIN_TRIGGERS,_e as createSvgPlugin};
16
+ </svg>`);return F.stripInvalidXmlChars(h)}buildBackgroundRect(t){const e=g.rgbToHex(this._currentBackgroundColor),i=Math.max(t.width,1),s=Math.max(t.height,1);return` <rect x="${t.x}" y="${t.y}" width="${i}" height="${s}" fill="${e}"/>`}}const ge=new y;function fe(r,t){const e=Z(r),i=Z(t);if(e!==i||e<2)return null;const s=new Array(e+1);for(let a=0;a<e;a++){const o=r[a],h=t[a];s[a]={x:(o.x+h.x)*.5,y:(o.y+h.y)*.5,z:((o.z??0)+(h.z??0))*.5}}const n=s[0];return s[e]={x:n.x,y:n.y,z:n.z},s}function Z(r){const t=r.length;return t>1&&r[0].x===r[t-1].x&&r[0].y===r[t-1].y?t-1:t}const pe=200;class de{async convert(t){await ot.instance.withBusyIndicator(async()=>{await N(),J.prepareExport();const e=t.doc.database.tables.blockTable.modelSpace.newIterator(),i=new J;this.configureRenderer(i,t);const s=new Q(pe),n=()=>new Promise(l=>setTimeout(l,0)),a=[];for(const l of e){const c=l.worldDraw(i);c instanceof y&&a.push(c),await s.maybeYield(n)}await N();const o=await i.exportAsync(a);await N();const h=ht(t.doc.fileName||t.doc.docTitle,"svg");this.createFileAndDownloadIt(o,h)},lt.t("main.message.exportingSvg"))}configureRenderer(t,e){const i=e.doc.database;t.ltscale=i.ltscale,t.celtscale=i.celtscale,t.showLineWeight=!!i.lwdisplay,t.setFontMapping(ct.instance.fontMapping);const s=e.view,n=(s==null?void 0:s.backgroundColor)??16777215;t.currentBackgroundColor=n,t.changeForeground(n===0?16777215:0)}createFileAndDownloadIt(t,e){const i=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(i),n=document.createElement("a");n.href=s,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),window.setTimeout(()=>URL.revokeObjectURL(s),6e4)}}class ye extends rt{async execute(t){await new de().convert(t)}}const be="1.8.0-preview.3",ve={version:be};class we{constructor(){this.name="SvgPlugin",this.version=ve.version,this.description="SVG export (csvg) command",this.registeredCommands=[]}onLoad(t,e){const i=at.SYSTEMT_COMMAND_GROUP_NAME;e.addCommand(i,"csvg","csvg",new ye),this.registeredCommands.push({group:i,name:"csvg"})}onUnload(t,e){for(const i of this.registeredCommands)e.removeCmd(i.group,i.name);this.registeredCommands=[]}}async function _e(){return new we}export{ye as AcApConvertToSvgCmd,de as AcApSvgConvertor,J as AcSvgRenderer,Me as SVG_PLUGIN_NAME,Ce as SVG_PLUGIN_TRIGGERS,_e as createSvgPlugin};