UNPKG

21.7 kBJavaScriptView Raw
1/* Sutton SignWriting TrueType Font Module v1.1.0 (https://github.com/sutton-signwriting/font-ttf), author: Steve Slevinski (https://SteveSlevinski.me), license: MIT */
2let t={};const o=document.createElement("canvas");o.width=152,o.height=152;const e=o.getContext("2d"),l=function(o){if(o in t)return[...t[o]];e.clearRect(0,0,152,152),e.font="60px 'SuttonSignWritingLine'",e.fillText(String.fromCodePoint(o+983040),0,0);const l=e.getImageData(0,0,152,152).data;let i,s,n,a;t:for(i=151;i>=0;i--)for(s=0;s<152;s+=1)for(a=0;a<4;a+=1)if(l[n=4*i+4*s*152+a])break t;var r=i;t:for(s=151;s>=0;s--)for(i=0;i<r;i+=1)for(a=0;a<4;a+=1)if(l[n=4*i+4*s*152+a])break t;var d=s+1;if(r=Math.ceil(r/2),d=Math.ceil(d/2),14394==o&&(r=19),[10468,10480,10496,10512,10500,10532,10548,10862,10878,10894,11058,11074,11476,11488,11492,11504,11508,11520,10516,10910,10926,11042,11082,10942].includes(o)&&(r=20),31921==o&&(r=22),38460==o&&(r=23),[20164,20212].includes(o)&&(r=25),31894==o&&(r=28),46698==o&&(r=29),29606==o&&(r=30),44855==o&&(r=40),32667==o&&(r=50),[11088,11474,11490,11506].includes(o)&&(d=20),6285==o&&(d=21),40804==o&&(d=31),41475==o&&(d=36),0==r&&0==d){const t={9:[15,30],10:[21,30],11:[30,15],12:[30,21],13:[15,30],14:[21,30]};o in t&&(r=t[o][0],d=t[o][1])}return 0!=r||0!=d?(t[o]=[r,d],[r,d]):void 0},i=function(t){return String.fromCodePoint(t+983040)},s=function(t){return String.fromCodePoint(t+1048576)},n=function(t){return` <text class="sym-fill" fill="white" style="pointer-events:none;font-family:'SuttonSignWritingFill';font-size:30px;">${s(t)}</text>\n <text class="sym-line" fill="black" style="pointer-events:none;font-family:'SuttonSignWritingLine';font-size:30px;">${i(t)}</text>`},a=function(t){if(l(1))t();else{const o=setInterval((function(){l(1)&&(clearInterval(o),t())}),100)}},r=function(t){const o=function(){const t=document.createElement("canvas");t.width=15,t.height=30;const o=t.getContext("2d");return o.font="30px 'SuttonSignWritingFill'",o.fillText(s(1),0,0),!o.getImageData(0,0,15,30).data.every(t=>0===t)};if(o())t();else{const e=setInterval((function(){o()&&(clearInterval(e),t())}),100)}};var d=Object.freeze({__proto__:null,cssAppend:function(t=""){if(!document.getElementById("SgnwFontCss")){const o=document.createElement("style");o.setAttribute("id","SgnwFontCss"),o.appendChild(document.createTextNode(`\n @font-face {\n font-family: "SuttonSignWritingLine";\n src: \n local('SuttonSignWritingLine'),\n ${t?`url('${t}SuttonSignWritingLine.ttf') format('truetype'),`:""}\n url('https://unpkg.com/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingLine.ttf') format('truetype');\n }\n @font-face {\n font-family: "SuttonSignWritingFill";\n src: \n local('SuttonSignWritingFill'),\n ${t?`url('${t}SuttonSignWritingFill.ttf') format('truetype'),`:""}\n url('https://unpkg.com/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingFill.ttf') format('truetype');\n }\n @font-face {\n font-family: "SuttonSignWritingOneD";\n src: \n local('SuttonSignWritingOneD'),\n ${t?`url('${t}SuttonSignWritingOneD.ttf') format('truetype'),`:""}\n url('https://unpkg.com/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingOneD.ttf') format('truetype');\n }\n `)),document.head.appendChild(o)}},cssLoaded:function(t){let o=!1,e=!1;a(()=>{o=!0}),r(()=>{e=!0});const l=setInterval((function(){o&&e&&(clearInterval(l),t())}),100)},cssLoadedLine:a,cssLoadedFill:r,symbolSize:l,symbolLine:i,symbolFill:s,symbolText:n});const c=t=>t.map(t=>(t=>String.fromCodePoint(120844+parseInt(t)-250))(t)).join(""),m=t=>(t=>parseInt(t.codePointAt(0)))(t)-262144,f=t=>1+96*(parseInt(t.slice(1,4),16)-256)+16*parseInt(t.slice(4,5),16)+parseInt(t.slice(5,6),16),g=function(t){return l(f(t))},p=function(t){return i(f(t))},y=function(t){return s(f(t))},$=function(t){return n(f(t))};let x={colorize:"C",colorhex:"(?:[0-9a-fA-F]{3}){1,2}",colorname:"[a-zA-Z]+",padding:"P[0-9]{2}",zoom:"Z(?:[0-9]+(?:\\.[0-9]+)?|x)",zoomsym:"Z[0-9]{2},[0-9]+(?:\\.[0-9]+)?(?:,[0-9]{3}x[0-9]{3})?",classbase:"-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}",id:"[a-zA-Z][_a-zA-Z0-9-]{0,100}"};x.colorbase=`(?:${x.colorhex}|${x.colorname})`,x.color=`_${x.colorbase}_`,x.colors=`_${x.colorbase}(?:,${x.colorbase})?_`,x.background=`G${x.color}`,x.detail=`D${x.colors}`,x.detailsym=`D[0-9]{2}${x.colors}`,x.classes=`${x.classbase}(?: ${x.classbase})*`,x.full=`-(${x.colorize})?(${x.padding})?(${x.background})?(${x.detail})?(${x.zoom})?(?:-((?:${x.detailsym})*)((?:${x.zoomsym})*))?(?:-(${x.classes})?!(?:(${x.id})!)?)?`;const u=t=>{return(new RegExp(`^${x.colorhex}$`).test(t)?"#":"")+t},b=t=>{const o=`^${x.full}`,e="string"==typeof t?t.match(new RegExp(o)):[];return{colorize:e[1]?!!e[1]:void 0,padding:e[2]?parseInt(e[2].slice(1)):void 0,background:e[3]?u(e[3].slice(2,-1)):void 0,detail:e[4]?e[4].slice(2,-1).split(",").map(u):void 0,zoom:e[5]?"Zx"===e[5]?"x":parseFloat(e[5].slice(1)):void 0,detailsym:e[6]?e[6].match(new RegExp(x.detailsym,"g")).map(t=>{const o=t.split("_"),e=o[1].split(",").map(u);return{index:parseInt(o[0].slice(1)),detail:e}}):void 0,zoomsym:e[7]?e[7].match(new RegExp(x.zoomsym,"g")).map(t=>{const o=t.split(",");return{index:parseInt(o[0].slice(1)),zoom:parseFloat(o[1]),offset:o[2]?o[2].split("x").map(t=>parseInt(t)-500):void 0}}):void 0,classes:e[8]?e[8]:void 0,id:e[9]?e[9]:void 0}};let h={symbol:"S[123][0-9a-f]{2}[0-5][0-9a-f]",coord:"[0-9]{3}x[0-9]{3}",sort:"A",box:"[BLMR]"};h.prefix=`(?:${h.sort}(?:${h.symbol})+)`,h.spatial=`${h.symbol}${h.coord}`,h.signbox=`${h.box}${h.coord}(?:${h.spatial})*`,h.sign=`${h.prefix}?${h.signbox}`,h.term=`${h.prefix}${h.signbox}`;let z={colorize:"C",colorhex:"(?:[0-9a-fA-F]{3}){1,2}",colorname:"[a-zA-Z]+",padding:"P[0-9]{2}",zoom:"Z(?:[0-9]+(?:\\.[0-9]+)?|x)",zoomsym:"Z[0-9]{2},[0-9]+(?:\\.[0-9]+)?(?:,[0-9]{3}x[0-9]{3})?",classbase:"-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}",id:"[a-zA-Z][_a-zA-Z0-9-]{0,100}"};z.colorbase=`(?:${z.colorhex}|${z.colorname})`,z.color=`_${z.colorbase}_`,z.colors=`_${z.colorbase}(?:,${z.colorbase})?_`,z.background=`G${z.color}`,z.detail=`D${z.colors}`,z.detailsym=`D[0-9]{2}${z.colors}`,z.classes=`${z.classbase}(?: ${z.classbase})*`,z.full=`-(${z.colorize})?(${z.padding})?(${z.background})?(${z.detail})?(${z.zoom})?(?:-((?:${z.detailsym})*)((?:${z.zoomsym})*))?(?:-(${z.classes})?!(?:(${z.id})!)?)?`;const v=t=>t.split("x").map(t=>parseInt(t)),w=t=>{const o=`^(${h.symbol})(${h.coord})?(${z.full})?`,e="string"==typeof t?t.match(new RegExp(o)):void 0;return{symbol:e?e[1]:void 0,coord:e&&e[2]?v(e[2]):void 0,style:e?e[3]:void 0}},S=t=>{const o=`^(${h.prefix})?(${h.signbox})(${z.full})?`,e="string"==typeof t?t.match(new RegExp(o)):void 0;return e?{sequence:e[1]?e[1].slice(1).match(/.{6}/g):void 0,box:e[2][0],max:v(e[2].slice(1,8)),spatials:e[2].length<9?void 0:e[2].slice(8).match(/(.{13})/g).map(t=>({symbol:t.slice(0,6),coord:[parseInt(t.slice(6,9)),parseInt(t.slice(10,13))]})),style:e[3]}:{}},I=[256,517,759,767,877,895,903],k=[767,876],_=[767,885],F=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"],M=t=>{const o=w(t);let e="#000000";if(o.symbol){const t=parseInt(o.symbol.slice(1,4),16),l=I.findIndex(o=>o>t);e=F[l<0?6:l-1]}return e};var E=Object.freeze({__proto__:null,symbolSize:g,symbolLine:p,symbolFill:y,symbolText:$,symbolSvg:t=>{const o=w(t);if(o.symbol){let e=g(o.symbol);if(e){let l,i=b(o.style),s=$(o.symbol);s=` <g transform="translate(500,500)">\n${s}\n </g>`,i.colorize?l=M(o.symbol):i.detail&&(l=i.detail[0]),l&&(s=s.replace(/class="sym-line" fill="black"/,`class="sym-line" fill="${l}"`));let n=i.detail&&i.detail[1];n&&(s=s.replace(/class="sym-fill" fill="white"/,`class="sym-fill" fill="${n}"`));let a=500,r=500,d="";i.padding&&(a-=i.padding,r-=i.padding,e[0]+=2*i.padding,e[1]+=2*i.padding),i.background&&(d=`\n <rect x="${a}" y="${r}" width="${e[0]}" height="${e[1]}" style="fill:${i.background};" />`);let c="";"x"!=i.zoom&&(c=` width="${e[0]*(i.zoom?i.zoom:1)}" height="${e[1]*(i.zoom?i.zoom:1)}"`);let m="";i.classes&&(m=` class="${i.classes}"`);let f="";return i.id&&(f=` id="${i.id}"`),`<svg${m}${f} version="1.1" xmlns="http://www.w3.org/2000/svg"${c} viewBox="${a} ${r} ${e[0]} ${e[1]}">\n <text font-size="0">${t}</text>${d}\n${s}\n</svg>`}}return'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>'},symbolPng:t=>{const o=function(t){const o=w(t);if(o.symbol){let t=g(o.symbol);if(t){const e=document.createElement("canvas"),l=e.getContext("2d");let i=b(o.style),s="black";i.colorize?s=M(o.symbol):i.detail&&(s=i.detail[0]);let n=i.detail&&i.detail[1]||"white",a=500,r=a+t[0],d=500,c=d+t[1];i.padding&&(a-=i.padding,d-=i.padding,r+=i.padding,c+=i.padding);let m=1;"x"!=i.zoom&&(m=i.zoom);let f=(r-a)*m,g=(c-d)*m;return e.width=f||1,e.height=g||1,i.background&&(l.rect(0,0,f,g),l.fillStyle=i.background,l.fill()),l.font=30*m+"px 'SuttonSignWritingFill'",l.fillStyle=n,l.fillText(y(o.symbol),(500-a)*m,(500-d)*m),l.font=30*m+"px 'SuttonSignWritingLine'",l.fillStyle=s,l.fillText(p(o.symbol),(500-a)*m,(500-d)*m),e}}}(t),e=o.toDataURL("image/png");return o.remove(),e},symbolNormalize:t=>{const o=w(t);if(!o.symbol)return null;{let t=g(o.symbol);if(t)return`${o.symbol}${500-parseInt(t[0]/2)}x${500-parseInt(t[1]/2)}${o.style||""}`}},signSvg:t=>{let o=S(t);if(o.spatials){let e=b(o.style);e.detailsym&&e.detailsym.forEach(t=>{o.spatials[t.index-1]&&(o.spatials[t.index-1].detail=t.detail)});let l=Math.min(...o.spatials.map(t=>t.coord[0])),i=Math.min(...o.spatials.map(t=>t.coord[1])),s=o.max[0],n=o.max[1];e.zoomsym&&e.zoomsym.forEach(t=>{if(o.spatials[t.index-1]){o.spatials[t.index-1].zoom=t.zoom,t.offset&&(o.spatials[t.index-1].coord[0]+=t.offset[0],o.spatials[t.index-1].coord[1]+=t.offset[1]);let e=g(o.spatials[t.index-1].symbol);s=Math.max(s,o.spatials[t.index-1].coord[0]+e[0]*t.zoom),n=Math.max(n,o.spatials[t.index-1].coord[1]+e[1]*t.zoom)}});let a="";e.classes&&(a=` class="${e.classes}"`);let r="";e.id&&(r=` id="${e.id}"`);let d="";e.padding&&(l-=e.padding,i-=e.padding,s+=e.padding,n+=e.padding),e.background&&(d=`\n <rect x="${l}" y="${i}" width="${s-l}" height="${n-i}" style="fill:${e.background};" />`);let c="";"x"!=e.zoom&&(c=` width="${(s-l)*(e.zoom?e.zoom:1)}" height="${(n-i)*(e.zoom?e.zoom:1)}"`);let m=`<svg${a}${r} version="1.1" xmlns="http://www.w3.org/2000/svg"${c} viewBox="${l} ${i} ${s-l} ${n-i}">\n <text font-size="0">${t}</text>${d}`;const f=e.detail&&e.detail[0],p=e.detail&&e.detail[1];return m+="\n"+o.spatials.map(t=>{let o=$(t.symbol),l=f;t.detail?l=t.detail[0]:e.colorize&&(l=M(t.symbol)),l&&(o=o.replace(/class="sym-line" fill="black"/,`class="sym-line" fill="${l}"`));let i=p;return t.detail&&t.detail[1]&&(i=t.detail[1]),i&&(o=o.replace(/class="sym-fill" fill="white"/,`class="sym-fill" fill="${i}"`)),t.zoom&&(o=`<g transform="scale(${t.zoom})">${o}</g>`),` <g transform="translate(${t.coord[0]},${t.coord[1]})">\n${o}\n </g>`}).join("\n"),m+="\n</svg>"}return'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>'},signPng:t=>{const o=function(t){const o=S(t);if(o.spatials){const t=document.createElement("canvas"),e=t.getContext("2d");let l=b(o.style);l.detailsym&&l.detailsym.forEach(t=>{o.spatials[t.index-1]&&(o.spatials[t.index-1].detail=t.detail)});let i=Math.min(...o.spatials.map(t=>t.coord[0])),s=Math.min(...o.spatials.map(t=>t.coord[1])),n=o.max[0],a=o.max[1];l.zoomsym&&l.zoomsym.forEach(t=>{if(o.spatials[t.index-1]){o.spatials[t.index-1].zoom=t.zoom,t.offset&&(o.spatials[t.index-1].coord[0]+=t.offset[0],o.spatials[t.index-1].coord[1]+=t.offset[1]);let e=g(o.spatials[t.index-1].symbol);n=Math.max(n,o.spatials[t.index-1].coord[0]+e[0]*t.zoom),a=Math.max(a,o.spatials[t.index-1].coord[1]+e[1]*t.zoom)}}),l.padding&&(i-=l.padding,s-=l.padding,n+=l.padding,a+=l.padding);let r=1;"x"!=l.zoom&&(r=l.zoom);let d=(n-i)*r,c=(a-s)*r;t.width=d||1,t.height=c||1,l.background&&(e.rect(0,0,d,c),e.fillStyle=l.background,e.fill());const m=l.detail&&l.detail[0]||"black",f=l.detail&&l.detail[1]||"white";return o.spatials.forEach(t=>{let o=m;t.detail?o=t.detail[0]:l.colorize&&(o=M(t.symbol));let n=f;t.detail&&t.detail[1]&&(n=t.detail[1]);let a=t.zoom||1;e.font=30*r*a+"px 'SuttonSignWritingFill'",e.fillStyle=n,e.fillText(y(t.symbol),(t.coord[0]-i)*r,(t.coord[1]-s)*r),e.font=30*r*a+"px 'SuttonSignWritingLine'",e.fillStyle=o,e.fillText(p(t.symbol),(t.coord[0]-i)*r,(t.coord[1]-s)*r)}),t}}(t),e=o.toDataURL("image/png");return o.remove(),e},signNormalize:t=>{const o=S(t);if(o.spatials){const t=o.spatials.reduce((t,o)=>{const e=g(o.symbol);return t[o.symbol]={width:e[0],height:e[1]},t},{}),e=o=>{return{x1:Math.min(...o.map(t=>t.coord[0])),y1:Math.min(...o.map(t=>t.coord[1])),x2:Math.max(...o.map(o=>o.coord[0]+parseInt(t[o.symbol].width))),y2:Math.max(...o.map(o=>o.coord[1]+parseInt(t[o.symbol].height)))}},l=k,i=o.spatials.filter(t=>{const o=parseInt(t.symbol.slice(1,4),16);return l[0]<=o&&l[1]>=o}),s=_,n=o.spatials.filter(t=>{const o=parseInt(t.symbol.slice(1,4),16);return s[0]<=o&&s[1]>=o});let a=e(o.spatials),r=[a.x2,a.y2];if(i.length){const t=e(i);a.x1=t.x1,a.x2=t.x2}if(n.length){const t=e(n);a.y1=t.y1,a.y2=t.y2}const d=[parseInt((a.x2+a.x1)/2)-500,parseInt((a.y2+a.y1)/2)-500];return(o.sequence?"A"+o.sequence.join(""):"")+o.box+(r[0]-d[0])+"x"+(r[1]-d[1])+o.spatials.map(t=>t.symbol+(t.coord[0]-d[0])+"x"+(t.coord[1]-d[1])).join("")+(o.style||"")}}});const A=function(t){return l(m(t))},C=function(t){return i(m(t))},W=function(t){return s(m(t))},L=function(t){return n(m(t))};let Z={symbol:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:\ud836[\udc0c-\uddff]){2}",sort:"𝠀",box:"\ud836[\udc01-\udc04]"};Z.prefix=`(?:${Z.sort}(?:${Z.symbol})+)`,Z.spatial=`${Z.symbol}${Z.coord}`,Z.signbox=`${Z.box}${Z.coord}(?:${Z.spatial})*`,Z.sign=`${Z.prefix}?${Z.signbox}`,Z.term=`${Z.prefix}${Z.signbox}`;let D={colorize:"C",colorhex:"(?:[0-9a-fA-F]{3}){1,2}",colorname:"[a-zA-Z]+",padding:"P[0-9]{2}",zoom:"Z(?:[0-9]+(?:\\.[0-9]+)?|x)",zoomsym:"Z[0-9]{2},[0-9]+(?:\\.[0-9]+)?(?:,[0-9]{3}x[0-9]{3})?",classbase:"-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}",id:"[a-zA-Z][_a-zA-Z0-9-]{0,100}"};D.colorbase=`(?:${D.colorhex}|${D.colorname})`,D.color=`_${D.colorbase}_`,D.colors=`_${D.colorbase}(?:,${D.colorbase})?_`,D.background=`G${D.color}`,D.detail=`D${D.colors}`,D.detailsym=`D[0-9]{2}${D.colors}`,D.classes=`${D.classbase}(?: ${D.classbase})*`,D.full=`-(${D.colorize})?(${D.padding})?(${D.background})?(${D.detail})?(${D.zoom})?(?:-((?:${D.detailsym})*)((?:${D.zoomsym})*))?(?:-(${D.classes})?!(?:(${D.id})!)?)?`;const P=t=>parseInt(t.codePointAt(0))-120844+250,R=t=>[P(t.slice(0,2)),P(t.slice(2,4))],T=t=>{const o=`^(${Z.symbol})(${Z.coord})?(${D.full})?`,e="string"==typeof t?t.match(new RegExp(o)):void 0;return{symbol:e?e[1]:void 0,coord:e&&e[2]?R(e[2]):void 0,style:e?e[3]:void 0}},j=t=>{const o=`^(${Z.prefix})?(${Z.signbox})(${D.full})?`,e="string"==typeof t?t.match(new RegExp(o)):void 0;return e?{sequence:e[1]?e[1].slice(2).match(/.{2}/g):void 0,box:e[2].slice(0,2),max:R(e[2].slice(2,6)),spatials:e[2].length<7?void 0:e[2].slice(6).match(/(.{6})/g).map(t=>({symbol:t.slice(0,2),coord:R(t.slice(2))})),style:e[3]}:{}},O=[262145,287201,310433,311201,321761,323489,324257],q=[311201,321760],B=[311201,322624],N=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"],U=t=>{const o=T(t);let e="#000000";if(o.symbol){const t=(t=>parseInt(t.codePointAt(0)))(o.symbol),l=O.findIndex(o=>o>t);e=N[l<0?6:l-1]}return e};var G=Object.freeze({__proto__:null,symbolSize:A,symbolLine:C,symbolFill:W,symbolText:L,symbolSvg:t=>{const o=T(t);if(o.symbol){let e=A(o.symbol);if(e){let l,i=b(o.style),s=L(o.symbol);s=` <g transform="translate(500,500)">\n${s}\n </g>`,i.colorize?l=U(o.symbol):i.detail&&(l=i.detail[0]),l&&(s=s.replace(/class="sym-line" fill="black"/,`class="sym-line" fill="${l}"`));let n=i.detail&&i.detail[1];n&&(s=s.replace(/class="sym-fill" fill="white"/,`class="sym-fill" fill="${n}"`));let a=500,r=500,d="";i.padding&&(a-=i.padding,r-=i.padding,e[0]+=2*i.padding,e[1]+=2*i.padding),i.background&&(d=`\n <rect x="${a}" y="${r}" width="${e[0]}" height="${e[1]}" style="fill:${i.background};" />`);let c="";"x"!=i.zoom&&(c=` width="${e[0]*(i.zoom?i.zoom:1)}" height="${e[1]*(i.zoom?i.zoom:1)}"`);let m="";i.classes&&(m=` class="${i.classes}"`);let f="";return i.id&&(f=` id="${i.id}"`),`<svg${m}${f} version="1.1" xmlns="http://www.w3.org/2000/svg"${c} viewBox="${a} ${r} ${e[0]} ${e[1]}">\n <text font-size="0">${t}</text>${d}\n${s}\n</svg>`}}return'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>'},symbolPng:t=>{const o=function(t){const o=T(t);if(o.symbol){let t=A(o.symbol);if(t){const e=document.createElement("canvas"),l=e.getContext("2d");let i=b(o.style),s="black";i.colorize?s=U(o.symbol):i.detail&&(s=i.detail[0]);let n=i.detail&&i.detail[1]||"white",a=500,r=a+t[0],d=500,c=d+t[1];i.padding&&(a-=i.padding,d-=i.padding,r+=i.padding,c+=i.padding);let m=1;"x"!=i.zoom&&(m=i.zoom);let f=(r-a)*m,g=(c-d)*m;return e.width=f||1,e.height=g||1,i.background&&(l.rect(0,0,f,g),l.fillStyle=i.background,l.fill()),l.font=30*m+"px 'SuttonSignWritingFill'",l.fillStyle=n,l.fillText(W(o.symbol),(500-a)*m,(500-d)*m),l.font=30*m+"px 'SuttonSignWritingLine'",l.fillStyle=s,l.fillText(C(o.symbol),(500-a)*m,(500-d)*m),e}}}(t),e=o.toDataURL("image/png");return o.remove(),e},symbolNormalize:t=>{const o=T(t);if(!o.symbol)return null;{let t=A(o.symbol);if(t)return`${o.symbol}${c([500-parseInt(t[0]/2),500-parseInt(t[1]/2)])}${o.style||""}`}},signSvg:t=>{let o=j(t);if(o.spatials){let e=b(o.style);e.detailsym&&e.detailsym.forEach(t=>{o.spatials[t.index-1]&&(o.spatials[t.index-1].detail=t.detail)});let l=Math.min(...o.spatials.map(t=>t.coord[0])),i=Math.min(...o.spatials.map(t=>t.coord[1])),s=o.max[0],n=o.max[1];e.zoomsym&&e.zoomsym.forEach(t=>{if(o.spatials[t.index-1]){o.spatials[t.index-1].zoom=t.zoom,t.offset&&(o.spatials[t.index-1].coord[0]+=t.offset[0],o.spatials[t.index-1].coord[1]+=t.offset[1]);let e=A(o.spatials[t.index-1].symbol);s=Math.max(s,o.spatials[t.index-1].coord[0]+e[0]*t.zoom),n=Math.max(n,o.spatials[t.index-1].coord[1]+e[1]*t.zoom)}});let a="";e.classes&&(a=` class="${e.classes}"`);let r="";e.id&&(r=` id="${e.id}"`);let d="";e.padding&&(l-=e.padding,i-=e.padding,s+=e.padding,n+=e.padding),e.background&&(d=`\n <rect x="${l}" y="${i}" width="${s-l}" height="${n-i}" style="fill:${e.background};" />`);let c="";"x"!=e.zoom&&(c=` width="${(s-l)*(e.zoom?e.zoom:1)}" height="${(n-i)*(e.zoom?e.zoom:1)}"`);let m=`<svg${a}${r} version="1.1" xmlns="http://www.w3.org/2000/svg"${c} viewBox="${l} ${i} ${s-l} ${n-i}">\n <text font-size="0">${t}</text>${d}`;const f=e.detail&&e.detail[0],g=e.detail&&e.detail[1];return m+="\n"+o.spatials.map(t=>{let o=L(t.symbol,t.coord),l=f;t.detail?l=t.detail[0]:e.colorize&&(l=U(t.symbol)),l&&(o=o.replace(/class="sym-line" fill="black"/,`class="sym-line" fill="${l}"`));let i=g;return t.detail&&t.detail[1]&&(i=t.detail[1]),i&&(o=o.replace(/class="sym-fill" fill="white"/,`class="sym-fill" fill="${i}"`)),t.zoom&&(o=`<g transform="scale(${t.zoom})">${o}</g>`),` <g transform="translate(${t.coord[0]},${t.coord[1]})">\n${o}\n </g>`}).join("\n"),m+="\n</svg>"}return'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>'},signPng:t=>{const o=function(t){const o=j(t);if(o.spatials){const t=document.createElement("canvas"),e=t.getContext("2d");let l=b(o.style);l.detailsym&&l.detailsym.forEach(t=>{o.spatials[t.index-1]&&(o.spatials[t.index-1].detail=t.detail)});let i=Math.min(...o.spatials.map(t=>t.coord[0])),s=Math.min(...o.spatials.map(t=>t.coord[1])),n=o.max[0],a=o.max[1];l.zoomsym&&l.zoomsym.forEach(t=>{if(o.spatials[t.index-1]){o.spatials[t.index-1].zoom=t.zoom,t.offset&&(o.spatials[t.index-1].coord[0]+=t.offset[0],o.spatials[t.index-1].coord[1]+=t.offset[1]);let e=A(o.spatials[t.index-1].symbol);n=Math.max(n,o.spatials[t.index-1].coord[0]+e[0]*t.zoom),a=Math.max(a,o.spatials[t.index-1].coord[1]+e[1]*t.zoom)}}),l.padding&&(i-=l.padding,s-=l.padding,n+=l.padding,a+=l.padding);let r=1;"x"!=l.zoom&&(r=l.zoom);let d=(n-i)*r,c=(a-s)*r;t.width=d||1,t.height=c||1,l.background&&(e.rect(0,0,d,c),e.fillStyle=l.background,e.fill());const m=l.detail&&l.detail[0]||"black",f=l.detail&&l.detail[1]||"white";return o.spatials.forEach(t=>{let o=m;t.detail?o=t.detail[0]:l.colorize&&(o=U(t.symbol));let n=f;t.detail&&t.detail[1]&&(n=t.detail[1]);let a=t.zoom||1;e.font=30*r*a+"px 'SuttonSignWritingFill'",e.fillStyle=n,e.fillText(W(t.symbol),(t.coord[0]-i)*r,(t.coord[1]-s)*r),e.font=30*r*a+"px 'SuttonSignWritingLine'",e.fillStyle=o,e.fillText(C(t.symbol),(t.coord[0]-i)*r,(t.coord[1]-s)*r)}),t}}(t),e=o.toDataURL("image/png");return o.remove(),e},signNormalize:t=>{const o=j(t);if(o.spatials){const t=o.spatials.reduce((t,o)=>{const e=A(o.symbol);return t[o.symbol]={width:e[0],height:e[1]},t},{}),e=o=>{return{x1:Math.min(...o.map(t=>t.coord[0])),y1:Math.min(...o.map(t=>t.coord[1])),x2:Math.max(...o.map(o=>o.coord[0]+parseInt(t[o.symbol].width))),y2:Math.max(...o.map(o=>o.coord[1]+parseInt(t[o.symbol].height)))}},l=q,i=o.spatials.filter(t=>{const o=parseInt(t.symbol.slice(1,4),16);return l[0]<=o&&l[1]>=o}),s=B,n=o.spatials.filter(t=>{const o=parseInt(t.symbol.slice(1,4),16);return s[0]<=o&&s[1]>=o});let a=e(o.spatials),r=[a.x2,a.y2];if(i.length){const t=e(i);a.x1=t.x1,a.x2=t.x2}if(n.length){const t=e(n);a.y1=t.y1,a.y2=t.y2}const d=[parseInt((a.x2+a.x1)/2)-500,parseInt((a.y2+a.y1)/2)-500];return(o.sequence?"𝠀"+o.sequence.join(""):"")+o.box+c([r[0]-d[0],r[1]-d[1]])+o.spatials.map(t=>t.symbol+c([t.coord[0]-d[0],t.coord[1]-d[1]])).join("")+(o.style||"")}}});export{d as font,E as fsw,G as swu};