@sutton-signwriting/font-ttf
Version:
a javascript package for node that generates SVG and PNG images for individual symbols, complete signs, and structured text. The package covers the entire set of the International SignWritnig Alphabet 2010 (ISWA 2010).
3 lines (2 loc) • 19.6 kB
JavaScript
/* Sutton SignWriting TrueType Font Module v1.6.0 (https://github.com/sutton-signwriting/font-ttf), author: Steve Slevinski (https://SteveSlevinski.me), license: MIT */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ssw=t.ssw||{},t.ssw.ttf=t.ssw.ttf||{},t.ssw.ttf.fsw={}))}(this,(function(t){"use strict";const e=t=>"S00000"===t?0:1+96*(parseInt(t.slice(1,4),16)-256)+16*parseInt(t.slice(4,5),16)+parseInt(t.slice(5,6),16);let o={null:"S00000",symbol:"S[123][0-9a-f]{2}[0-5][0-9a-f]",coord:"[0-9]{3}x[0-9]{3}",sort:"A",box:"[BLMR]"};o.nullorsymbol=`(?:${o.null}|${o.symbol})`,o.prefix=`(?:${o.sort}${o.nullorsymbol}+)`,o.spatial=`${o.symbol}${o.coord}`,o.signbox=`${o.box}${o.coord}(?:${o.spatial})*`,o.sign=`${o.prefix}?${o.signbox}`,o.sortable=`${o.prefix}${o.signbox}`;let l={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)",classbase:"-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}",id:"[a-zA-Z][_a-zA-Z0-9-]{0,100}"};l.colorbase=`(?:${l.colorhex}|${l.colorname})`,l.color=`_${l.colorbase}_`,l.colors=`_${l.colorbase}(?:,${l.colorbase})?_`,l.background=`G${l.color}`,l.detail=`D${l.colors}`,l.detailsym=`D[0-9]{2}${l.colors}`,l.classes=`${l.classbase}(?: ${l.classbase})*`,l.full=`-(${l.colorize})?(${l.padding})?(${l.background})?(${l.detail})?(${l.zoom})?(?:-((?:${l.detailsym})*))?(?:-(${l.classes})?!(?:(${l.id})!)?)?`;const i=t=>(new RegExp(`^${l.colorhex}$`).test(t)?"#":"")+t,s=t=>{const e=`^${l.full}`,o=("string"==typeof t?t.match(new RegExp(e)):[])||[];return s={colorize:o[1]?!!o[1]:void 0,padding:o[2]?parseInt(o[2].slice(1)):void 0,background:o[3]?i(o[3].slice(2,-1)):void 0,detail:o[4]?o[4].slice(2,-1).split(",").map(i):void 0,zoom:o[5]?"Zx"===o[5]?"x":parseFloat(o[5].slice(1)):void 0,detailsym:o[6]?o[6].match(new RegExp(l.detailsym,"g")).map((t=>{const e=t.split("_"),o=e[1].split(",").map(i);return{index:parseInt(e[0].slice(1)),detail:o}})):void 0,classes:o[7]?o[7]:void 0,id:o[8]?o[8]:void 0},Object.fromEntries(Object.entries(s).filter((([t,e])=>void 0!==e)));var s},n=t=>t.split("x").map((t=>parseInt(t))),a=t=>{const e=`^(${o.symbol})(${o.coord})?(${l.full})?`,i="string"==typeof t?t.match(new RegExp(e)):void 0;return{symbol:i?i[1]:void 0,coord:i&&i[2]?n(i[2]):void 0,style:i?i[3]:void 0}},r=t=>{const e=`^(${o.prefix})?(${o.signbox})(${l.full})?`,i="string"==typeof t?t.match(new RegExp(e)):void 0;return i?{sequence:i[1]?i[1].slice(1).match(/.{6}/g):void 0,box:i[2][0],max:n(i[2].slice(1,8)),spatials:i[2].length<9?void 0:i[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:i[3]}:{}},d=t=>{if("string"!=typeof t)return[];const e=`(${o.sign}(${l.full})?|${o.spatial}(${l.full})?)`,i=t.match(new RegExp(e,"g"));return i?[...i]:[]},c=t=>{if("string"==typeof t.symbol){const e=(t.symbol.match(o.symbol)||[""])[0];if(e){return e+((((t.coord&&t.coord[0]||"").toString()+"x"+(t.coord&&t.coord[1]||"").toString()).match(o.coord)||[""])[0]||"")+("string"==typeof t.style&&(t.style.match(l.full)||[""])[0]||"")}}},m=t=>{let e,o,l,i,n,d,c,m,p=r(t);p.spatials?(i=Math.min(...p.spatials.map((t=>t.coord[0]))),n=p.max[0],e=n-i,d=Math.min(...p.spatials.map((t=>t.coord[1]))),c=p.max[1],o=c-d,l="sign",m=p.box):(p=a(t),m="M",p.coord?(i=p.coord[0],e=2*(500-i),d=p.coord[1],o=2*(500-d),l="symbol"):(i=490,e=20,d=490,o=20,l="none"));let g=s(p.style),f=g.zoom||1,y=g.padding||0;return{minX:i,minY:d,width:e,height:o,segment:l,lane:{B:0,L:-1,M:0,R:1}[m],padding:y,zoom:f}},p={height:500,width:150,offset:50,pad:20,margin:5,dynamic:!1,background:void 0,punctuation:{spacing:!0,pad:30,pull:!0},style:{detail:["black","white"],zoom:1}},g=(t,e)=>{if("string"!=typeof t)return{};const o=(t=>("object"!=typeof t&&(t={}),{...p,...t,punctuation:{...p.punctuation,...t.punctuation},style:{...p.style,...t.style}}))(e);let l=d(t),i=0,s=[],n=[],a=0,r=parseInt(o.width/2),c=o.height-o.margin,g=!0,f=!1;for(let t of l){let e=m(t);i+=a,o.punctuation.spacing?i+="sign"==e.segment?o.pad:0:i+=o.pad,f=i+e.height>c,f&&"symbol"==e.segment&&o.punctuation.pull&&g&&(f=!1,g=!1),0==n.length&&(f=!1),f&&(i=o.pad,s.push(n),n=[],g=!0),n.push(Object.assign(e,{x:r+o.offset*e.lane-(500-e.minX)*e.zoom*o.style.zoom,y:i,text:t})),i+=e.height*e.zoom*o.style.zoom,a=o.punctuation.spacing?"sign"==e.segment?o.pad:o.punctuation.pad:o.pad}if(n.length&&s.push(n),o.punctuation.pull)for(let t of s){let e=t[t.length-1],l=e.y+e.height-(o.height-o.margin);if(l>0){let e=parseInt(l/t.length)+1;for(let o in t)t[o].y-=e*o+e}}let y=[];for(let t of s){let e=[r-o.offset-o.pad],l=[r+o.offset+o.pad];for(let i of t)e.push(i.x-o.pad),l.push(i.x+i.width+o.pad);e=Math.min(...e),l=Math.max(...l);let i=o.width,s=0;o.dynamic?(i=l-e,s=-e):s=r-parseInt((e+l)/2);for(let e of t)e.x+=s;y.push(i)}return{options:o,widths:y,columns:s}},f=[256,517,759,767,877,895,903],y=[767,876],u=[767,885],b=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"],h=t=>{const e=a(t);let o="#000000";if(e.symbol){const t=parseInt(e.symbol.slice(1,4),16),l=f.findIndex((e=>e>t));o=b[l<0?6:l-1]}return o};let x={};const $=152;let v;const w=function(t){if(a(t).symbol)return function(t){if(t in x)return[...x[t]];if(!v){const t=document.createElement("canvas");t.width=$,t.height=$,v=t.getContext("2d",{willReadFrequently:!0})}v.clearRect(0,0,$,$),v.font="60px 'SuttonSignWritingLine'",v.fillText(String.fromCodePoint(t+983040),0,0);const e=v.getImageData(0,0,$,$).data;let o,l,i,s;t:for(o=151;o>=0;o--)for(l=0;l<$;l+=1)for(s=0;s<4;s+=1)if(i=4*o+4*l*$+s,e[i])break t;var n=o;t:for(l=151;l>=0;l--)for(o=0;o<n;o+=1)for(s=0;s<4;s+=1)if(i=4*o+4*l*$+s,e[i])break t;var a=l+1;if(n=Math.ceil(n/2),a=Math.ceil(a/2),14394==t&&(n=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(t)&&(n=20),31921==t&&(n=22),38460==t&&(n=23),[20164,20212].includes(t)&&(n=25),31894==t&&(n=28),46698==t&&(n=29),29606==t&&(n=30),44855==t&&(n=40),32667==t&&(n=50),[11088,11474,11490,11506].includes(t)&&(a=20),6285==t&&(a=21),40804==t&&(a=31),41475==t&&(a=36),0==n&&0==a){const e={9:[15,30],10:[21,30],11:[30,15],12:[30,21],13:[15,30],14:[21,30]};t in e&&(n=e[t][0],a=e[t][1])}return 0!=n||0!=a?(x[t]=[n,a],[n,a]):void 0}(e(t))},z=function(t){return String.fromCodePoint(t+983040)},S=function(t){return String.fromCodePoint(t+1048576)},I=function(t){return z(e(t))},k=function(t){return S(e(t))},_=function(t){return o=e(t),` <text class="sym-fill" fill="white" style="pointer-events:none;font-family:'SuttonSignWritingFill';font-size:30px;">${S(o)}</text>\n <text class="sym-line" fill="black" style="pointer-events:none;font-family:'SuttonSignWritingLine';font-size:30px;">${z(o)}</text>`;var o};let M={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)",classbase:"-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}",id:"[a-zA-Z][_a-zA-Z0-9-]{0,100}"};M.colorbase=`(?:${M.colorhex}|${M.colorname})`,M.color=`_${M.colorbase}_`,M.colors=`_${M.colorbase}(?:,${M.colorbase})?_`,M.background=`G${M.color}`,M.detail=`D${M.colors}`,M.detailsym=`D[0-9]{2}${M.colors}`,M.classes=`${M.classbase}(?: ${M.classbase})*`,M.full=`-(${M.colorize})?(${M.padding})?(${M.background})?(${M.detail})?(${M.zoom})?(?:-((?:${M.detailsym})*))?(?:-(${M.classes})?!(?:(${M.id})!)?)?`;const j=t=>(new RegExp(`^${M.colorhex}$`).test(t)?"#":"")+t,E=t=>{const e=`^${M.full}`,o=("string"==typeof t?t.match(new RegExp(e)):[])||[];return l={colorize:o[1]?!!o[1]:void 0,padding:o[2]?parseInt(o[2].slice(1)):void 0,background:o[3]?j(o[3].slice(2,-1)):void 0,detail:o[4]?o[4].slice(2,-1).split(",").map(j):void 0,zoom:o[5]?"Zx"===o[5]?"x":parseFloat(o[5].slice(1)):void 0,detailsym:o[6]?o[6].match(new RegExp(M.detailsym,"g")).map((t=>{const e=t.split("_"),o=e[1].split(",").map(j);return{index:parseInt(e[0].slice(1)),detail:o}})):void 0,classes:o[7]?o[7]:void 0,id:o[8]?o[8]:void 0},Object.fromEntries(Object.entries(l).filter((([t,e])=>void 0!==e)));var l},R=t=>{if("object"!=typeof t||null===t)return;let e="-";e+=t.colorize?"C":"";const o=parseInt(t.padding);e+=!o||o<=0||o>99?"":"P"+(o>9?o:"0"+o);const l=t.background&&"string"==typeof t.background?t.background.match(M.colorbase)[0]:void 0;e+=l?"G_"+l+"_":"";const i=t.detail&&t.detail[0]&&"string"==typeof t.detail[0]?t.detail[0].match(M.colorbase)[0]:void 0,s=t.detail&&t.detail[1]&&"string"==typeof t.detail[1]?t.detail[1].match(M.colorbase)[0]:void 0;i&&(e+="D_"+i,s&&(e+=","+s),e+="_");const n="x"===t.zoom?"x":parseFloat(t.zoom);e+=!n||n<=0?"":"Z"+n;let a="";const r=t.detailsym&&Array.isArray(t.detailsym)?t.detailsym.map((t=>{const e=parseInt(t.index);if(!e||e<=0||e>99)return"";let o="D"+(e>9?e:"0"+e);const l=t.detail&&t.detail[0]?t.detail[0].match(M.colorbase)[0]:void 0,i=t.detail&&t.detail[1]?t.detail[1].match(M.colorbase)[0]:void 0;return l&&(o+="_"+l,i&&(o+=","+i),o+="_"),o})):[];a+=r.join("");let d="";const c=t.classes&&"string"==typeof t.classes?t.classes.match(M.classes)[0]:void 0;d+=c||"";const m=t.id&&"string"==typeof t.id?t.id.match(M.id)[0]:void 0;return d+=c||m?"!":"",d+=m?m+"!":"",e+(a||d?"-"+a:"")+(d?"-"+d:"")},A=t=>{const e=a(t);if(!e.symbol)return"";let o,l,i,s,n=E(e.style);if(e.coord)o=e.coord[0],l=e.coord[1],i=500-o+500,s=500-l+500;else{let t=w(e.symbol);if(!t)return"";o=500-parseInt((t[0]+1)/2),l=500-parseInt((t[1]+1)/2),i=500-o+500,s=500-l+500}let r,d=_(e.symbol);d=` <g transform="translate(${o},${l})">\n${d}\n </g>`,n.colorize?r=h(e.symbol):n.detail&&(r=n.detail[0]),r&&(d=d.replace(/class="sym-line" fill="black"/,`class="sym-line" fill="${r}"`));let c=n.detail&&n.detail[1];c&&(d=d.replace(/class="sym-fill" fill="white"/,`class="sym-fill" fill="${c}"`));let m="";return n.padding&&(o-=n.padding,l-=n.padding,i+=n.padding,s+=n.padding),n.background&&(m=`\n <rect x="${o}" y="${l}" width="${i-o}" height="${s-l}" style="fill:${n.background};" />`),` <text font-size="0">${t}</text>${m}\n${d}`},F=t=>{let e=r(t);if(e.spatials){let o=E(e.style);o.detailsym&&o.detailsym.forEach((t=>{e.spatials[t.index-1]&&(e.spatials[t.index-1].detail=t.detail)}));let l=Math.min(...e.spatials.map((t=>t.coord[0]))),i=Math.min(...e.spatials.map((t=>t.coord[1]))),s=e.max[0],n=e.max[1],a="";o.padding&&(l-=o.padding,i-=o.padding,s+=o.padding,n+=o.padding),o.background&&(a=`\n <rect x="${l}" y="${i}" width="${s-l}" height="${n-i}" style="fill:${o.background};" />`);let r=` <text font-size="0">${t}</text>${a}`;const d=o.detail&&o.detail[0],c=o.detail&&o.detail[1];return r+="\n"+e.spatials.map((t=>{let e=_(t.symbol),l=d;t.detail?l=t.detail[0]:o.colorize&&(l=h(t.symbol)),l&&(e=e.replace(/class="sym-line" fill="black"/,`class="sym-line" fill="${l}"`));let i=c;return t.detail&&t.detail[1]&&(i=t.detail[1]),i&&(e=e.replace(/class="sym-fill" fill="white"/,`class="sym-fill" fill="${i}"`)),` <g transform="translate(${t.coord[0]},${t.coord[1]})">\n${e}\n </g>`})).join("\n"),r}return""},Z=(t,e)=>{"object"!=typeof e&&(e={});const o=Object.assign(p,e);let l=o.width,i=o.height,s="";o.background&&(s=`\n <rect x="0" y="0" width="${l-0}" height="${i-0}" style="fill:${o.background};" />`);let n=`<svg version="1.1" xmlns="http://www.w3.org/2000/svg"${` width="${o.width}" height="${o.height}"`} viewBox="0 0 ${l-0} ${i-0}">\n ${s}`;return n+=t.map((t=>{const e=t.text.indexOf("-");if(e>0){const l=t.text.substring(e),i={...o.style,...E(l)};t.text=t.text.replace(l,R(i))}else t.text+=R(o.style);return t.zoom=t.zoom*o.style.zoom,'<g transform="translate('+t.x+","+t.y+") scale("+t.zoom+") translate("+-t.minX+","+-t.minY+') ">'+("sign"==t.segment?F(t.text):A(t.text))+"</g>"})).join("\n"),n+="\n</svg>",n},C=(t,e)=>{const o=function(t,e){"object"!=typeof e&&(e={});const o=Object.assign(p,e),l=document.createElement("canvas");l.width=o.width,l.height=o.height;const i=l.getContext("2d");return o.background&&(i.rect(0,0,o.width,o.height),i.fillStyle=o.background,i.fill()),t.map((t=>{const e=t.text.indexOf("-");if(e>0){const l=t.text.substring(e),i={...o.style,...E(l)};t.text=t.text.replace(l,R(i))}else t.text+=R(o.style);t.zoom=t.zoom*o.style.zoom;let l={};if("sign"==t.segment)l=r(t.text);else{let e=a(t.text);l.style=e.style,l.spatials=[e]}let s=E(l.style);s.background&&(i.fillStyle=s.background,i.fillRect(t.x-s.padding*t.zoom,t.y-s.padding*t.zoom,(t.width+2*s.padding)*t.zoom,(t.height+2*s.padding)*t.zoom)),s.detailsym&&s.detailsym.forEach((t=>{l.spatials[t.index-1]&&(l.spatials[t.index-1].detail=t.detail)}));const n=s.detail&&s.detail[0]||"black",d=s.detail&&s.detail[1]||"white";l.spatials.forEach((e=>{let o=n;e.detail?o=e.detail[0]:s.colorize&&(o=h(e.symbol));let l=d;e.detail&&e.detail[1]&&(l=e.detail[1]),i.font=30*t.zoom+"px 'SuttonSignWritingFill'",i.fillStyle=l,i.fillText(k(e.symbol),t.x+(e.coord[0]-t.minX)*t.zoom,t.y+(e.coord[1]-t.minY)*t.zoom),i.font=30*t.zoom+"px 'SuttonSignWritingLine'",i.fillStyle=o,i.fillText(I(e.symbol),t.x+(e.coord[0]-t.minX)*t.zoom,t.y+(e.coord[1]-t.minY)*t.zoom)}))})),l}(t,e),l=o.toDataURL("image/png");return o.remove(),l};t.columnPng=C,t.columnSvg=Z,t.columnsPng=function(t,e){"object"!=typeof e&&(e={});let o=g(t,e);return o.columns.map(((t,e)=>C(t,{...o.options,width:o.widths[e]})))},t.columnsSvg=function(t,e){"object"!=typeof e&&(e={});let o=g(t,e);return o.columns.map(((t,e)=>Z(t,{...o.options,width:o.widths[e]})))},t.signNormalize=t=>{const e=r(t);if(e.spatials){const t=e.spatials.reduce(((t,e)=>{const o=w(e.symbol);return t[e.symbol]={width:o[0],height:o[1]},t}),{}),o=e=>({x1:Math.min(...e.map((t=>t.coord[0]))),y1:Math.min(...e.map((t=>t.coord[1]))),x2:Math.max(...e.map((e=>e.coord[0]+parseInt(t[e.symbol].width)))),y2:Math.max(...e.map((e=>e.coord[1]+parseInt(t[e.symbol].height))))}),l=y,i=e.spatials.filter((t=>{const e=parseInt(t.symbol.slice(1,4),16);return l[0]<=e&&l[1]>=e})),s=u,n=e.spatials.filter((t=>{const e=parseInt(t.symbol.slice(1,4),16);return s[0]<=e&&s[1]>=e}));let a=o(e.spatials),r=[a.x2,a.y2];if(i.length){const t=o(i);a.x1=t.x1,a.x2=t.x2}if(n.length){const t=o(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(e.sequence?"A"+e.sequence.join(""):"")+e.box+(r[0]-d[0])+"x"+(r[1]-d[1])+e.spatials.map((t=>t.symbol+(t.coord[0]-d[0])+"x"+(t.coord[1]-d[1]))).join("")+(e.style||"")}},t.signPng=t=>{const e=function(t){const e=r(t);if(e.spatials){const t=document.createElement("canvas"),o=t.getContext("2d");let l=E(e.style);l.detailsym&&l.detailsym.forEach((t=>{e.spatials[t.index-1]&&(e.spatials[t.index-1].detail=t.detail)}));let i=Math.min(...e.spatials.map((t=>t.coord[0]))),s=Math.min(...e.spatials.map((t=>t.coord[1]))),n=e.max[0],a=e.max[1];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&&(o.rect(0,0,d,c),o.fillStyle=l.background,o.fill());const m=l.detail&&l.detail[0]||"black",p=l.detail&&l.detail[1]||"white";return e.spatials.forEach((t=>{let e=m;t.detail?e=t.detail[0]:l.colorize&&(e=h(t.symbol));let n=p;t.detail&&t.detail[1]&&(n=t.detail[1]),o.font=30*r+"px 'SuttonSignWritingFill'",o.fillStyle=n,o.fillText(k(t.symbol),(t.coord[0]-i)*r,(t.coord[1]-s)*r),o.font=30*r+"px 'SuttonSignWritingLine'",o.fillStyle=e,o.fillText(I(t.symbol),(t.coord[0]-i)*r,(t.coord[1]-s)*r)})),t}}(t),o=e.toDataURL("image/png");return e.remove(),o},t.signSvg=t=>{let e=r(t);if(e.spatials){let o=E(e.style),l=Math.min(...e.spatials.map((t=>t.coord[0]))),i=Math.min(...e.spatials.map((t=>t.coord[1]))),s=e.max[0],n=e.max[1],a="";o.classes&&(a=` class="${o.classes}"`);let r="";o.id&&(r=` id="${o.id}"`),o.padding&&(l-=o.padding,i-=o.padding,s+=o.padding,n+=o.padding);let d="";"x"!=o.zoom&&(d=` width="${(s-l)*(o.zoom?o.zoom:1)}" height="${(n-i)*(o.zoom?o.zoom:1)}"`);let c=`<svg${a}${r} version="1.1" xmlns="http://www.w3.org/2000/svg"${d} viewBox="${l} ${i} ${s-l} ${n-i}">\n`;return c+=F(t),c+="\n</svg>",c}return'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>'},t.signSvgBody=F,t.symbolFill=k,t.symbolFlop=(t,e=!0)=>{let o=a(t);if(!o.symbol)return t;if(!w(o.symbol))return t;const l=e?1:-1,i=o.symbol.slice(0,4);let s=parseInt(o.symbol.slice(4,5)),n=o.symbol.slice(5,6),r="";for(;!r||!w(r);)s+=l,s>5&&(s=0),s<0&&(s=5),r=i+s+n;return o.symbol=r,c(o)},t.symbolInvert=t=>{let e=a(t);if(!e.symbol)return t;if(!w(e.symbol))return t;const o=e.symbol.slice(0,4);let l=e.symbol.slice(4,5),i=e.symbol.slice(5,6);const s=o+"18";let n;if(n=w(o+"08")||w(s)?{0:"c",1:"d",2:"e",3:"f",4:"8",5:"9",6:"a",7:"b",c:"0",d:"1",e:"2",f:"3",8:"4",9:"5",a:"6",b:"7"}:{0:"4",1:"3",2:"2",3:"1",4:"0",5:"7",6:"6",7:"5"},i in n){const t=o+l+n[i];w(t)&&(e.symbol=t)}return c(e)},t.symbolLine=I,t.symbolMirror=t=>{let e=a(t);if(!e.symbol)return t;if(!w(e.symbol))return t;const o=e.symbol.slice(0,4);let l=e.symbol.slice(4,5),i=parseInt(e.symbol.slice(5,6),16);const s=o+"18";var n;w(o+"08")||w(s)?n=8:(0!==i&&4!=i||(n=0),1!=i&&5!=i||(n=6),2!=i&&6!=i||(n=4),3!=i&&7!=i||(n=2));let r="";for(;!r||!w(r);)i+=n,i>7&&n<8&&(i-=8),i>15&&(i-=16),r=o+l+i.toString(16);return e.symbol=r,c(e)},t.symbolNormalize=t=>{const e=a(t);if(!e.symbol)return null;{let t=w(e.symbol);if(t)return`${e.symbol}${500-parseInt((t[0]+1)/2)}x${500-parseInt((t[1]+1)/2)}${e.style||""}`}},t.symbolPng=t=>{const e=function(t){const e=a(t);if(e.symbol){let t=w(e.symbol);if(t){const o=document.createElement("canvas"),l=o.getContext("2d");let i=E(e.style),s="black";i.colorize?s=h(e.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 p=(r-a)*m,g=(c-d)*m;return o.width=p||1,o.height=g||1,i.background&&(l.rect(0,0,p,g),l.fillStyle=i.background,l.fill()),l.font=30*m+"px 'SuttonSignWritingFill'",l.fillStyle=n,l.fillText(k(e.symbol),(500-a)*m,(500-d)*m),l.font=30*m+"px 'SuttonSignWritingLine'",l.fillStyle=s,l.fillText(I(e.symbol),(500-a)*m,(500-d)*m),o}}}(t),o=e.toDataURL("image/png");return e.remove(),o},t.symbolRotate=(t,e=!0)=>{let o=a(t);if(!o.symbol)return t;if(!w(o.symbol))return t;const l=e?1:-1,i=o.symbol.slice(0,4);let s=o.symbol.slice(4,5),n=parseInt(o.symbol.slice(5,6),16),r="";for(;!r||!w(r);)n>7?(n+=l,n>15&&(n=8),n<8&&(n=15),r=i+s+n.toString(16)):(n-=l,n>7&&(n=0),n<0&&(n=7),r=i+s+n);return o.symbol=r,c(o)},t.symbolScroll=(t,e=!0)=>{let o=a(t);if(!o.symbol)return t;if(!w(o.symbol))return t;const l=e?1:-1,i=parseInt(o.symbol.slice(1,4),16)+l,s=o.symbol.slice(4,5),n=o.symbol.slice(5,6),r="S"+i.toString(16)+s+n;return w(r)&&(o.symbol=r),c(o)},t.symbolSize=w,t.symbolSvg=t=>{const e=a(t),o='<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>';if(!e.symbol)return o;let l,i,s,n,r=E(e.style);if(e.coord)l=e.coord[0],i=e.coord[1],s=500-l+500,n=500-i+500;else{let t=w(e.symbol);if(!t)return o;l=parseInt(500-t[0]/2),i=parseInt(500-t[1]/2),s=l+t[0],n=i+t[1]}let d="";r.classes&&(d=` class="${r.classes}"`);let c="";r.id&&(c=` id="${r.id}"`),r.padding&&(l-=r.padding,i-=r.padding,s+=r.padding,n+=r.padding);let m="";return"x"!=r.zoom&&(m=` width="${(s-l)*(r.zoom?r.zoom:1)}" height="${(n-i)*(r.zoom?r.zoom:1)}"`),`<svg${d}${c} version="1.1" xmlns="http://www.w3.org/2000/svg"${m} viewBox="${l} ${i} ${s-l} ${n-i}">\n${A(t)}\n</svg>`},t.symbolSvgBody=A,t.symbolText=_,Object.defineProperty(t,"__esModule",{value:!0})}));