/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/canvas-txt@4.0.3/dist/canvas-txt.umd.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
(function(p,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(p=typeof globalThis<"u"?globalThis:p||self,y(p.canvasTxt={}))})(this,function(p){"use strict";function y({ctx:e,line:b,spaceWidth:d,spaceChar:n,width:g}){const i=b.trim(),s=i.split(/\s+/),o=s.length-1;if(o===0)return i;const m=e.measureText(s.join("")).width,T=(g-m)/d,c=Math.floor(T/o);if(T<1)return i;console.log("noOfSpacesToInsert",T,o);const r=n.repeat(c);return s.join(r)}const v=" ";function W({ctx:e,text:b,justify:d,width:n}){const g=new Map,i=r=>{let f=g.get(r);return f!==void 0||(f=e.measureText(r).width,g.set(r,f)),f};let s=[],o=b.split(`
`);const m=d?i(v):0;let T=0,c=0;for(const r of o){let f=i(r);const S=r.length;if(f<=n){s.push(r);continue}let u=r,t,a,l="";for(;f>n;){if(T++,t=c,a=t===0?0:i(r.substring(0,t)),a<n)for(;a<n&&t<S&&(t++,a=i(u.substring(0,t)),t!==S););else if(a>n)for(;a>n&&(t=Math.max(1,t-1),a=i(u.substring(0,t)),!(t===0||t===1)););if(c=Math.round(c+(t-c)/T),t--,t>0){let h=t;if(u.substring(h,h+1)!=" "){for(;u.substring(h,h+1)!=" "&&h>=0;)h--;h>0&&(t=h)}}t===0&&(t=1),l=u.substring(0,t),l=d?y({ctx:e,line:l,spaceWidth:m,spaceChar:v,width:n}):l,s.push(l),u=u.substring(t),f=i(u)}f>0&&(l=d?y({ctx:e,line:u,spaceWidth:m,spaceChar:v,width:n}):u,s.push(l))}return s}function B({ctx:e,text:b,style:d}){const n=e.textBaseline,g=e.font;e.textBaseline="bottom",e.font=d;const{actualBoundingBoxAscent:i}=e.measureText(b);return e.textBaseline=n,e.font=g,i}const C={debug:!1,align:"center",vAlign:"middle",fontSize:14,fontWeight:"",fontStyle:"",fontVariant:"",font:"Arial",lineHeight:null,justify:!1};function j(e,b,d){const{width:n,height:g,x:i,y:s}=d,o={...C,...d};if(n<=0||g<=0||o.fontSize<=0)return{height:0};const m=i+n,T=s+g,{fontStyle:c,fontVariant:r,fontWeight:f,fontSize:S,font:u}=o,t=`${c} ${r} ${f} ${S}px ${u}`;e.font=t;let a=s+g/2+o.fontSize/2,l;o.align==="right"?(l=m,e.textAlign="right"):o.align==="left"?(l=i,e.textAlign="left"):(l=i+n/2,e.textAlign="center");const h=W({ctx:e,text:b,justify:o.justify,width:n}),E=o.lineHeight?o.lineHeight:B({ctx:e,text:"M",style:t}),H=E*(h.length-1),k=H/2;let A=s;return o.vAlign==="top"?(e.textBaseline="top",a=s):o.vAlign==="bottom"?(e.textBaseline="bottom",a=T-H,A=T):(e.textBaseline="bottom",A=s+g/2,a-=k),h.forEach(P=>{P=P.trim(),e.fillText(P,l,a),a+=E}),o.debug&&(e.lineWidth=1,e.strokeStyle="#0C8CE9",e.strokeRect(i,s,n,g),e.lineWidth=1,e.strokeStyle="#0C8CE9",e.beginPath(),e.moveTo(l,s),e.lineTo(l,T),e.stroke(),e.strokeStyle="#0C8CE9",e.beginPath(),e.moveTo(i,A),e.lineTo(m,A),e.stroke()),{height:H+E}}p.drawText=j,p.getTextHeight=B,p.splitText=W,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});