import{a as e,n as t,t as n}from"./index-DtqT604u.js";function r(e){if(typeof e==`number`)return e>=600;if(typeof e==`string`){let t=Number(e);return Number.isNaN(t)?e===`bold`||e===`bolder`:t>=600}return!1}function i(e,t,n){let i=e.getValueOfPropertyAt(t,n,`fill`);return{fontFamily:String(e.getValueOfPropertyAt(t,n,`fontFamily`)??``),fontSizePt:Number(e.getValueOfPropertyAt(t,n,`fontSize`)??0),bold:r(e.getValueOfPropertyAt(t,n,`fontWeight`)),italic:e.getValueOfPropertyAt(t,n,`fontStyle`)===`italic`,underline:e.getValueOfPropertyAt(t,n,`underline`)===!0,color:typeof i==`string`?i:`#000000`}}function a(e,t){return e.fontFamily===t.fontFamily&&e.fontSizePt===t.fontSizePt&&e.bold===t.bold&&e.italic===t.italic&&e.underline===t.underline&&e.color===t.color}async function o(r){let o=t(r),s=new e(void 0,{width:Math.max(1,Math.ceil(r.width)),height:Math.max(1,Math.ceil(r.height)),renderOnAddRemove:!1});try{let e=new n(o.text,{...o.options,shadow:void 0});s.add(e);let t=e;t.initDimensions();let r=t.textAlign.includes(`justify`),c=typeof t._fontSizeFraction==`number`?t._fontSizeFraction:.222,l=typeof t.charSpacing==`number`?t.charSpacing:0,u=l===0?void 0:l/1e3*(t.fontSize||0),d=[],f=0;for(let e=0;e<t._textLines.length;e++){let n=t.getHeightOfLine(e),o=typeof t.getHeightOfLineImpl==`function`?t.getHeightOfLineImpl(e):n/t.lineHeight,s=f+o*(1-c);f+=n;let l=t._textLines[e],p=t.__charBounds[e]??[],m=t._getLineLeftOffset(e),h=[],g=-1,_=null,v=``,y=e=>{if(_===null||g<0||v.length===0)return;let t=p[g],n=p[e-1],r=t?t.left:0,i=n?n.left+n.width:r;h.push({text:v,x:m+r,width:i-r,fontFamily:_.fontFamily,fontSizePt:_.fontSizePt,bold:_.bold,italic:_.italic,underline:_.underline,color:_.color,...u===void 0?{}:{letterSpacingPt:u}}),g=-1,_=null,v=``};for(let n=0;n<l.length;n++){let o=i(t,e,n);_!==null&&!a(_,o)&&y(n),_===null&&(g=n,_=o),v+=l[n],r&&l[n]===` `&&y(n+1)}y(l.length);let b=t._styleMap?.[e]?.line;d.push({baselineY:s,runs:h,lineHeightPt:n,...typeof b==`number`?{paragraphIndex:b}:{}})}return d}finally{try{await s.dispose()}catch{}}}var s=Object.assign(o,{capabilities:{paragraphDepthApplied:!0}});export{s as fabricLayoutText};