wx-canvas-2d
Version:
微信小程序 canvas-2d 绘图工具,支持按需引用,支持内容配置,支持功能扩展,适配各种机型,超轻量,超易用,无需学习,直接上手。
1 lines • 1.03 kB
JavaScript
;module.exports={name:"Text",handler:function(){var p=this,u=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return new Promise(function(t,i){var e=u.x,o=void 0===e?0:e,e=u.y,n=void 0===e?0:e,e=u.color,e=void 0===e?"#000":e,c=u.fontSize,l=void 0===c?12:c,c=u.fontWeight,c=void 0===c?"":c,r=u.width,a=void 0===r?1/0:r,r=u.baseline,r=void 0===r?"top":r,x=u.align,d=void 0===x?"left":x,x=u.text,x=void 0===x?"":x,f=u.ellipsis,f=void 0===f?0:f,v=u.lineHeight,s=void 0===v?u.fontSize||12:v,h=0,g=[];p.ctx.textAlign=d,p.ctx.textBaseline=r,p.ctx.fillStyle=e,p.ctx.font="".concat(c," ").concat(p.xDpr(l),"px ").concat(p.fontFamily),[].concat(x).forEach(function(o,t){var n=0;String(o).split("").forEach(function(t,i){var e=String(o).slice(n,i+1);p.ctx.measureText(e).width<p.xDpr(a)?g[h]=e:(g[h+1]=t,n=i,h++)}),h++}),f&&g.length>f&&((g=g.slice(0,f))[f-1]=g[f-1].slice(0,-1)+"..."),g.forEach(function(t,i){p.ctx.fillText(t,p.xDpr({left:o,start:o,right:o+a,end:o+a,center:o+a/2}[d]||o),p.xDpr(n+s*i+(s-l)/2))}),t()})}};