* MIT License (http://www.opensource.org/licenses/mit-license.html)
*/
!function(a){functionb(a,b,c){"use strict";functiond(){t=q.font.match(/\d+(px|em|%)/g)?+q.font.match(/\d+(px|em|%)/g)[0].match(/\d+/g):18,u=0,v=[],w=[],x={x:0,y:0},f(t),g(),o(),e()}functione(){if(q.sizeToFill){vara=b.trim().split(/\s+/).length,c=0;dof(++c),y=c,h();while(C>u&&v.join(" ").split(/\s+/).length==a);f(--c),y=c}elseh();q.justifyLines&&"auto"===q.lineBreak&&k(),n(),l()}functionf(a){varb=q.sizeToFill?s.font.split(/\b\d+px\b/i):q.font.split(/\b\d+px\b/i);s.font=b[0]+a+"px"+b[1]}functiong(){isNaN(q.lineHeight)?-1!==q.lineHeight.toString().indexOf("px")?y=parseInt(q.lineHeight):-1!==q.lineHeight.toString().indexOf("%")&&(y=parseInt(q.lineHeight)/100*t):y=t*q.lineHeight}functionh(){if(q.allowNewLine)for(vara=b.trim().split("\n"),c=0,d=0;c<a.length-1;c++)d+=a[c].trim().split(/\s+/).length,w.push(d);vare=b.trim().split(/\s+/);i(e),j(e),u=v.length*y}functioni(a){for(varb,c,d,e,f=0;f<a.length;f++)if(b="",c=s.measureText(a[f]).width,c>B){for(varg=0;s.measureText(b+a[f][g]).width<=B&&g<a[f].length;g++)b+=a[f][g];d=a[f].slice(0,g),e=a[f].slice(g),a.splice(f,1,d,e)}}functionj(a){for(varb=0,c=0;b<a.length;c++)if(v[c]="","auto"===q.lineBreak){for(;s.measureText(v[c]+a[b]).width<=B&&b<a.length;)if(v[c]+=a[b]+" ",b++,q.allowNewLine)for(vard=0;d<w.length;d++)if(w[d]===b){c++,v[c]="";break}v[c]=v[c].trim()}elsev[c]=a[b],b++}functionk(){for(vara,b,c,d=0;d<v.length;d++)c=s.measureText(v[d]).width,(!a||c>a)&&(a=c,b=d);vare,f,g,h,i,j="";for(d=0;d<v.length;d++)if(d!==b&&(e=v[d].trim().split(/\s+/).length,!(1>=e))){v[d]=v[d].trim().split(/\s+/).join(j),f=s.measureText(j).width,g=(a-s.measureText(v[d]).width)/f,h=g/(e-1),i="";for(vark=0;h>k;k++)i+=j;v[d]=v[d].trim().split(j).join(i)}}functionl(){for(vara=0;a<v.length;a++)m(v[a]),x.y=parseInt(x.y)+y,s.fillText(v[a],x.x,x.y),q.strokeText&&s.strokeText(v[a],x.x,x.y)}functionm(a){"center"==q.textAlign?x.x=(z-s.measureText(a).width)/2:"right"==q.textAlign?x.x=z-s.measureText(a).width-q.paddingX:x.x=q.paddingX}functionn(){"middle"==q.verticalAlign?x.y=(A-u)/2:"bottom"==q.verticalAlign?x.y=A-u-q.paddingY:x.y=q.paddingY}functiono(){if(!(ainstanceofHTMLCanvasElement))thrownewTypeError("The first parameter must be an instance of HTMLCanvasElement.");if("string"!=typeofb)thrownewTypeError("The second parameter must be a string.");if(isNaN(t))thrownewTypeError('Cannot parse "font".');if(isNaN(y))thrownewTypeError('Cannot parse "lineHeight".');if("left"!==q.textAlign.toLocaleLowerCase()&&"center"!==q.textAlign.toLocaleLowerCase()&&"right"!==q.textAlign.toLocaleLowerCase())thrownewTypeError('Property "textAlign" must be set to either "left", "center", or "right".');if("top"!==q.verticalAlign.toLocaleLowerCase()&&"middle"!==q.verticalAlign.toLocaleLowerCase()&&"bottom"!==q.verticalAlign.toLocaleLowerCase())thrownewTypeError('Property "verticalAlign" must be set to either "top", "middle", or "bottom".');if("boolean"!=typeofq.justifyLines)thrownewTypeError('Property "justifyLines" must be set to a Boolean.');if(isNaN(q.paddingX))thrownewTypeError('Property "paddingX" must be set to a Number.');if(isNaN(q.paddingY))thrownewTypeError('Property "paddingY" must be set to a Number.');if("boolean"!=typeofq.fitParent)thrownewTypeError('Property "fitParent" must be set to a Boolean.');if("auto"!==q.lineBreak.toLocaleLowerCase()&&"word"!==q.lineBreak.toLocaleLowerCase())thrownewTypeError('Property "lineBreak" must be set to either "auto" or "word".');if("boolean"!=typeofq.sizeToFill)thrownewTypeError('Property "sizeToFill" must be set to a Boolean.');if("boolean"!=typeofq.strokeText)thrownewTypeError('Property "strokeText" must be set to a Boolean.')}varp={font:"18px Arial, sans-serif",sizeToFill:!1,lineHeight:1,allowNewLine:!0,lineBreak:"auto",textAlign:"left",verticalAlign:"top",justifyLines:!1,paddingX:0,paddingY:0,fitParent:!1,strokeText:!1},q={};for(varrinp)p.hasOwnProperty(r)&&(q[r]=c&&c[r]?c[r]:p[r]);vars=a.getContext("2d");s.font=q.font,s.textBaseline="bottom";vart,u,v,w,x,y,z=q.fitParent===!1?a.width:a.parentNode.clientWidth,A=q.fitParent===!1?a.height:a.parentNode.clientHeight,B=z-2*q.paddingX,C=A-2*q.paddingY;d()}"module"ina&&"exports"inmodule?module.exports=b:a.CanvasTextWrapper=b}(this);
!function(a){functionb(a,b,c){"use strict";functiond(){t=q.font.match(/\d+(px|em|%)/g)?+q.font.match(/\d+(px|em|%)/g)[0].match(/\d+/g):18,u=0,v=[],w=[],x={x:0,y:0},f(t),g(),o(),e()}functione(){if(q.sizeToFill){vara=b.trim().split(/\s+/).length,c=0;dof(++c),y=c,h();while(C>u&&v.join(" ").split(/\s+/).length==a);f(--c),y=c,h()}elseh();q.justifyLines&&"auto"===q.lineBreak&&k(),n(),l()}functionf(a){varb=q.sizeToFill?s.font.split(/\b\d+px\b/i):q.font.split(/\b\d+px\b/i);s.font=b[0]+a+"px"+b[1]}functiong(){isNaN(q.lineHeight)?-1!==q.lineHeight.toString().indexOf("px")?y=parseInt(q.lineHeight):-1!==q.lineHeight.toString().indexOf("%")&&(y=parseInt(q.lineHeight)/100*t):y=t*q.lineHeight}functionh(){if(q.allowNewLine)for(vara=b.trim().split("\n"),c=0,d=0;c<a.length-1;c++)d+=a[c].trim().split(/\s+/).length,w.push(d);vare=b.trim().split(/\s+/);i(e),j(e),u=v.length*y}functioni(a){for(varb,c,d,e,f=0;f<a.length;f++)if(b="",c=s.measureText(a[f]).width,c>B){for(varg=0;s.measureText(b+a[f][g]).width<=B&&g<a[f].length;g++)b+=a[f][g];d=a[f].slice(0,g),e=a[f].slice(g),a.splice(f,1,d,e)}}functionj(a){for(varb=0,c=0;b<a.length;c++)if(v[c]="","auto"===q.lineBreak){for(;s.measureText(v[c]+a[b]).width<=B&&b<a.length;)if(v[c]+=a[b]+" ",b++,q.allowNewLine)for(vard=0;d<w.length;d++)if(w[d]===b){c++,v[c]="";break}v[c]=v[c].trim()}elsev[c]=a[b],b++}functionk(){for(vara,b,c,d=0;d<v.length;d++)c=s.measureText(v[d]).width,(!a||c>a)&&(a=c,b=d);vare,f,g,h,i,j="";for(d=0;d<v.length;d++)if(d!==b&&(e=v[d].trim().split(/\s+/).length,!(1>=e))){v[d]=v[d].trim().split(/\s+/).join(j),f=s.measureText(j).width,g=(a-s.measureText(v[d]).width)/f,h=g/(e-1),i="";for(vark=0;h>k;k++)i+=j;v[d]=v[d].trim().split(j).join(i)}}functionl(){for(vara=0;a<v.length;a++)m(v[a]),x.y=parseInt(x.y)+y,s.fillText(v[a],x.x,x.y),q.strokeText&&s.strokeText(v[a],x.x,x.y)}functionm(a){"center"==q.textAlign?x.x=(z-s.measureText(a).width)/2:"right"==q.textAlign?x.x=z-s.measureText(a).width-q.paddingX:x.x=q.paddingX}functionn(){"middle"==q.verticalAlign?x.y=(A-u)/2:"bottom"==q.verticalAlign?x.y=A-u-q.paddingY:x.y=q.paddingY}functiono(){if(!(ainstanceofHTMLCanvasElement))thrownewTypeError("The first parameter must be an instance of HTMLCanvasElement.");if("string"!=typeofb)thrownewTypeError("The second parameter must be a string.");if(isNaN(t))thrownewTypeError('Cannot parse "font".');if(isNaN(y))thrownewTypeError('Cannot parse "lineHeight".');if("left"!==q.textAlign.toLocaleLowerCase()&&"center"!==q.textAlign.toLocaleLowerCase()&&"right"!==q.textAlign.toLocaleLowerCase())thrownewTypeError('Property "textAlign" must be set to either "left", "center", or "right".');if("top"!==q.verticalAlign.toLocaleLowerCase()&&"middle"!==q.verticalAlign.toLocaleLowerCase()&&"bottom"!==q.verticalAlign.toLocaleLowerCase())thrownewTypeError('Property "verticalAlign" must be set to either "top", "middle", or "bottom".');if("boolean"!=typeofq.justifyLines)thrownewTypeError('Property "justifyLines" must be set to a Boolean.');if(isNaN(q.paddingX))thrownewTypeError('Property "paddingX" must be set to a Number.');if(isNaN(q.paddingY))thrownewTypeError('Property "paddingY" must be set to a Number.');if("boolean"!=typeofq.fitParent)thrownewTypeError('Property "fitParent" must be set to a Boolean.');if("auto"!==q.lineBreak.toLocaleLowerCase()&&"word"!==q.lineBreak.toLocaleLowerCase())thrownewTypeError('Property "lineBreak" must be set to either "auto" or "word".');if("boolean"!=typeofq.sizeToFill)thrownewTypeError('Property "sizeToFill" must be set to a Boolean.');if("boolean"!=typeofq.strokeText)thrownewTypeError('Property "strokeText" must be set to a Boolean.')}varp={font:"18px Arial, sans-serif",sizeToFill:!1,lineHeight:1,allowNewLine:!0,lineBreak:"auto",textAlign:"left",verticalAlign:"top",justifyLines:!1,paddingX:0,paddingY:0,fitParent:!1,strokeText:!1},q={};for(varrinp)p.hasOwnProperty(r)&&(q[r]=c&&c[r]?c[r]:p[r]);vars=a.getContext("2d");s.font=q.font,s.textBaseline="bottom";vart,u,v,w,x,y,z=q.fitParent===!1?a.width:a.parentNode.clientWidth,A=q.fitParent===!1?a.height:a.parentNode.clientHeight,B=z-2*q.paddingX,C=A-2*q.paddingY;d()}"module"ina&&"exports"inmodule?module.exports=b:a.CanvasTextWrapper=b}(this);
CanvasTextWrapper(canvas,'What an awesome library!',opts);
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.