ray-template/js/canvas@2.11.2-CVRTzJty.js

2 lines
1.7 KiB
JavaScript

var i={};const u="bold|bolder|lighter|[1-9]00",g="italic|oblique",d="small-caps",p="ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded",h="px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q",m=`'([^']+)'|"([^"]+)"|[\\w\\s-]+`,w=new RegExp(`(${u}) +`,"i"),x=new RegExp(`(${g}) +`,"i"),b=new RegExp(`(${d}) +`,"i"),f=new RegExp(`(${p}) +`,"i"),z=new RegExp(`([\\d\\.]+)(${h}) *((?:${m})( *, *(?:${m}))*)`),o={},R=16;var v=n=>{if(o[n])return o[n];const t=z.exec(n);if(!t)return;const e={weight:"normal",style:"normal",stretch:"normal",variant:"normal",size:parseFloat(t[1]),unit:t[2],family:t[3].replace(/["']/g,"").replace(/ *, */g,",")};let c,a,s,l;const r=n.substring(0,t.index);switch((c=w.exec(r))&&(e.weight=c[1]),(a=x.exec(r))&&(e.style=a[1]),(s=b.exec(r))&&(e.variant=s[1]),(l=f.exec(r))&&(e.stretch=l[1]),e.unit){case"pt":e.size/=.75;break;case"pc":e.size*=16;break;case"in":e.size*=96;break;case"cm":e.size*=96/2.54;break;case"mm":e.size*=96/25.4;break;case"%":break;case"em":case"rem":e.size*=R/.75;break;case"q":e.size*=96/25.4/4;break}return o[n]=e};const k=v;i.parseFont=k;i.createCanvas=function(n,t){return Object.assign(document.createElement("canvas"),{width:n,height:t})};i.createImageData=function(n,t,e){switch(arguments.length){case 0:return new ImageData;case 1:return new ImageData(n);case 2:return new ImageData(n,t);default:return new ImageData(n,t,e)}};i.loadImage=function(n,t){return new Promise(function(e,c){const a=Object.assign(document.createElement("img"),t);function s(){a.onload=null,a.onerror=null}a.onload=function(){s(),e(a)},a.onerror=function(){s(),c(new Error('Failed to load the image "'+n+'"'))},a.src=n})};export{i as b};