UNPKG

19.8 kBJavaScriptView Raw
1/* Sutton SignWriting TrueType Font Module v1.5.2 (https://github.com/sutton-signwriting/font-ttf), author: Steve Slevinski (https://SteveSlevinski.me), license: MIT */
2!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.swu={}))}(this,(function(t){"use strict";const e=t=>t.map((t=>(t=>String.fromCodePoint(120844+parseInt(t)-250))(t))).join(""),o=t=>parseInt(t.codePointAt(0)),l=t=>o(t)-262144,i=t=>{const e=o(t)-262145,l=parseInt(e/96),i=parseInt((e-96*l)/16),s=parseInt(e-96*l-16*i);return"S"+(l+256).toString(16)+i.toString(16)+s.toString(16)},s=t=>{return e=262145+96*(parseInt(t.slice(1,4),16)-256)+16*parseInt(t.slice(4,5),16)+parseInt(t.slice(5,6),16),String.fromCodePoint(e);var e};let n={symbol:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:\ud836[\udc0c-\uddff]){2}",sort:"𝠀",box:"\ud836[\udc01-\udc04]"};n.prefix=`(?:${n.sort}(?:${n.symbol})+)`,n.spatial=`${n.symbol}${n.coord}`,n.signbox=`${n.box}${n.coord}(?:${n.spatial})*`,n.sign=`${n.prefix}?${n.signbox}`,n.sortable=`${n.prefix}${n.signbox}`;let a={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}"};a.colorbase=`(?:${a.colorhex}|${a.colorname})`,a.color=`_${a.colorbase}_`,a.colors=`_${a.colorbase}(?:,${a.colorbase})?_`,a.background=`G${a.color}`,a.detail=`D${a.colors}`,a.detailsym=`D[0-9]{2}${a.colors}`,a.classes=`${a.classbase}(?: ${a.classbase})*`,a.full=`-(${a.colorize})?(${a.padding})?(${a.background})?(${a.detail})?(${a.zoom})?(?:-((?:${a.detailsym})*))?(?:-(${a.classes})?!(?:(${a.id})!)?)?`;const r=t=>(new RegExp(`^${a.colorhex}$`).test(t)?"#":"")+t,d=t=>{const e=`^${a.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]?r(o[3].slice(2,-1)):void 0,detail:o[4]?o[4].slice(2,-1).split(",").map(r):void 0,zoom:o[5]?"Zx"===o[5]?"x":parseFloat(o[5].slice(1)):void 0,detailsym:o[6]?o[6].match(new RegExp(a.detailsym,"g")).map((t=>{const e=t.split("_"),o=e[1].split(",").map(r);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},c=t=>parseInt(t.codePointAt(0))-120844+250,m=t=>[c(t.slice(0,2)),c(t.slice(2,4))],p=t=>t.map((t=>(t=>String.fromCodePoint(120844+parseInt(t)-250))(t))).join(""),g=t=>{const e=`^(${n.symbol})(${n.coord})?(${a.full})?`,o="string"==typeof t?t.match(new RegExp(e)):void 0;return{symbol:o?o[1]:void 0,coord:o&&o[2]?m(o[2]):void 0,style:o?o[3]:void 0}},f=t=>{const e=`^(${n.prefix})?(${n.signbox})(${a.full})?`,o="string"==typeof t?t.match(new RegExp(e)):void 0;return o?{sequence:o[1]?o[1].slice(2).match(/.{2}/g):void 0,box:o[2].slice(0,2),max:m(o[2].slice(2,6)),spatials:o[2].length<7?void 0:o[2].slice(6).match(/(.{6})/g).map((t=>({symbol:t.slice(0,2),coord:m(t.slice(2))}))),style:o[3]}:{}},y=t=>{if("string"!=typeof t)return[];const e=`(${n.sign}(${a.full})?|${n.spatial}(${a.full})?)`,o=t.match(new RegExp(e,"g"));return o?[...o]:[]},u=t=>{if("object"==typeof t&&null!==t&&"string"==typeof t.symbol){const e=(t.symbol.match(n.symbol)||[""])[0];if(e){const o=t.coord&&t.coord[0]||"",l=t.coord&&t.coord[1]||"";return e+(o&&l?p([o,l]):"")+("string"==typeof t.style&&(t.style.match(a.full)||[""])[0]||"")}}},b=t=>{let e,o,l,i,s,n,a,r,c=f(t);c.spatials?(i=Math.min(...c.spatials.map((t=>t.coord[0]))),s=c.max[0],e=s-i,n=Math.min(...c.spatials.map((t=>t.coord[1]))),a=c.max[1],o=a-n,l="sign",r=c.box):(c=g(t),r="𝠃",c.coord?(i=c.coord[0],e=2*(500-i),n=c.coord[1],o=2*(500-n),l="symbol"):(i=490,e=20,n=490,o=20,l="none"));let m=d(c.style),p=m.zoom||1,y=m.padding||0;return{minX:i,minY:n,width:e,height:o,segment:l,lane:{"𝠁":0,"𝠂":-1,"𝠃":0,"𝠄":1}[r],padding:y,zoom:p}},h={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}},x=(t,e)=>{if("string"!=typeof t)return{};const o=(t=>("object"!=typeof t&&(t={}),{...h,...t,punctuation:{...h.punctuation,...t.punctuation},style:{...h.style,...t.style}}))(e);let l=y(t),i=0,s=[],n=[],a=0,r=parseInt(o.width/2),d=o.height-o.margin,c=!0,m=!1;for(let t of l){let e=b(t);i+=a,o.punctuation.spacing?i+="sign"==e.segment?o.pad:0:i+=o.pad,m=i+e.height>d,m&&"symbol"==e.segment&&o.punctuation.pull&&c&&(m=!1,c=!1),0==n.length&&(m=!1),m&&(i=o.pad,s.push(n),n=[],c=!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 p=[];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;p.push(i)}return{options:o,widths:p,columns:s}},$=[262145,287201,310433,311201,321761,323489,324257],v=[311201,321760],z=[311201,322624],w=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"],S=t=>{const e=g(t);let o="#000000";if(e.symbol){const t=(t=>parseInt(t.codePointAt(0)))(e.symbol),l=$.findIndex((e=>e>t));o=w[l<0?6:l-1]}return o};let I={};const k=152;let _;const j=function(t){if(g(t).symbol)return function(t){if(t in I)return[...I[t]];if(!_){const t=document.createElement("canvas");t.width=k,t.height=k,_=t.getContext("2d",{willReadFrequently:!0})}_.clearRect(0,0,k,k),_.font="60px 'SuttonSignWritingLine'",_.fillText(String.fromCodePoint(t+983040),0,0);const e=_.getImageData(0,0,k,k).data;let o,l,i,s;t:for(o=151;o>=0;o--)for(l=0;l<k;l+=1)for(s=0;s<4;s+=1)if(i=4*o+4*l*k+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*k+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?(I[t]=[n,a],[n,a]):void 0}(l(t))},E=function(t){return String.fromCodePoint(t+983040)},M=function(t){return String.fromCodePoint(t+1048576)},A=function(t){return E(l(t))},C=function(t){return M(l(t))},P=function(t){return e=l(t),` <text class="sym-fill" fill="white" style="pointer-events:none;font-family:'SuttonSignWritingFill';font-size:30px;">${M(e)}</text>\n <text class="sym-line" fill="black" style="pointer-events:none;font-family:'SuttonSignWritingLine';font-size:30px;">${E(e)}</text>`;var e};let F={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}"};F.colorbase=`(?:${F.colorhex}|${F.colorname})`,F.color=`_${F.colorbase}_`,F.colors=`_${F.colorbase}(?:,${F.colorbase})?_`,F.background=`G${F.color}`,F.detail=`D${F.colors}`,F.detailsym=`D[0-9]{2}${F.colors}`,F.classes=`${F.classbase}(?: ${F.classbase})*`,F.full=`-(${F.colorize})?(${F.padding})?(${F.background})?(${F.detail})?(${F.zoom})?(?:-((?:${F.detailsym})*))?(?:-(${F.classes})?!(?:(${F.id})!)?)?`;const R=t=>(new RegExp(`^${F.colorhex}$`).test(t)?"#":"")+t,Z=t=>{const e=`^${F.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]?R(o[3].slice(2,-1)):void 0,detail:o[4]?o[4].slice(2,-1).split(",").map(R):void 0,zoom:o[5]?"Zx"===o[5]?"x":parseFloat(o[5].slice(1)):void 0,detailsym:o[6]?o[6].match(new RegExp(F.detailsym,"g")).map((t=>{const e=t.split("_"),o=e[1].split(",").map(R);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},D=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(F.colorbase)[0]:void 0;e+=l?"G_"+l+"_":"";const i=t.detail&&t.detail[0]&&"string"==typeof t.detail[0]?t.detail[0].match(F.colorbase)[0]:void 0,s=t.detail&&t.detail[1]&&"string"==typeof t.detail[1]?t.detail[1].match(F.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(F.colorbase)[0]:void 0,i=t.detail&&t.detail[1]?t.detail[1].match(F.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(F.classes)[0]:void 0;d+=c||"";const m=t.id&&"string"==typeof t.id?t.id.match(F.id)[0]:void 0;return d+=c||m?"!":"",d+=m?m+"!":"",e+(a||d?"-"+a:"")+(d?"-"+d:"")},O=t=>{const e=g(t);if(!e.symbol)return"";let o,l,i,s,n=Z(e.style);if(e.coord)o=e.coord[0],l=e.coord[1],i=500-o+500,s=500-l+500;else{let t=j(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 a,r=P(e.symbol);r=` <g transform="translate(${o},${l})">\n${r}\n </g>`,n.colorize?a=S(e.symbol):n.detail&&(a=n.detail[0]),a&&(r=r.replace(/class="sym-line" fill="black"/,`class="sym-line" fill="${a}"`));let d=n.detail&&n.detail[1];d&&(r=r.replace(/class="sym-fill" fill="white"/,`class="sym-fill" fill="${d}"`));let c="";return n.padding&&(o-=n.padding,l-=n.padding,i+=n.padding,s+=n.padding),n.background&&(c=`\n <rect x="${o}" y="${l}" width="${i-o}" height="${s-l}" style="fill:${n.background};" />`),` <text font-size="0">${t}</text>${c}\n${r}`},T=t=>{let e=f(t);if(e.spatials){let o=Z(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=P(t.symbol),l=d;t.detail?l=t.detail[0]:o.colorize&&(l=S(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""},L=(t,e)=>{"object"!=typeof e&&(e={});const o=Object.assign(h,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 <text font-size="0">0</text>${s}`;return n+=t.map((t=>{const e=t.text.indexOf("-");if(e>0){const l=t.text.substring(e),i={...o.style,...Z(l)};t.text=t.text.replace(l,D(i))}else t.text+=D(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?T(t.text):O(t.text))+"</g>"})).join("\n"),n+="\n</svg>",n},W=(t,e)=>{const o=function(t,e){"object"!=typeof e&&(e={});const o=Object.assign(h,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,...Z(l)};t.text=t.text.replace(l,D(i))}else t.text+=D(o.style);t.zoom=t.zoom*o.style.zoom;let l={};if("sign"==t.segment)l=f(t.text);else{let e=g(t.text);l.style=e.style,l.spatials=[e]}let s=Z(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",a=s.detail&&s.detail[1]||"white";l.spatials.forEach((e=>{let o=n;e.detail?o=e.detail[0]:s.colorize&&(o=S(e.symbol));let l=a;e.detail&&e.detail[1]&&(l=e.detail[1]),i.font=30*t.zoom+"px 'SuttonSignWritingFill'",i.fillStyle=l,i.fillText(C(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(A(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=W,t.columnSvg=L,t.columnsPng=function(t,e){"object"!=typeof e&&(e={});let o=x(t,e);return o.columns.map(((t,e)=>W(t,{...o.options,width:o.widths[e]})))},t.columnsSvg=function(t,e){"object"!=typeof e&&(e={});let o=x(t,e);return o.columns.map(((t,e)=>L(t,{...o.options,width:o.widths[e]})))},t.signNormalize=t=>{const o=f(t);if(o.spatials){const t=o.spatials.reduce(((t,e)=>{const o=j(e.symbol);return t[e.symbol]={width:o[0],height:o[1]},t}),{}),l=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))))}),i=v,s=o.spatials.filter((t=>{const e=parseInt(t.symbol.slice(1,4),16);return i[0]<=e&&i[1]>=e})),n=z,a=o.spatials.filter((t=>{const e=parseInt(t.symbol.slice(1,4),16);return n[0]<=e&&n[1]>=e}));let r=l(o.spatials),d=[r.x2,r.y2];if(s.length){const t=l(s);r.x1=t.x1,r.x2=t.x2}if(a.length){const t=l(a);r.y1=t.y1,r.y2=t.y2}const c=[parseInt((r.x2+r.x1)/2)-500,parseInt((r.y2+r.y1)/2)-500];return(o.sequence?"𝠀"+o.sequence.join(""):"")+o.box+e([d[0]-c[0],d[1]-c[1]])+o.spatials.map((t=>t.symbol+e([t.coord[0]-c[0],t.coord[1]-c[1]]))).join("")+(o.style||"")}},t.signPng=t=>{const e=function(t){const e=f(t);if(e.spatials){const t=document.createElement("canvas"),o=t.getContext("2d");let l=Z(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=S(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(C(t.symbol),(t.coord[0]-i)*r,(t.coord[1]-s)*r),o.font=30*r+"px 'SuttonSignWritingLine'",o.fillStyle=e,o.fillText(A(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=f(t);if(e.spatials){let o=Z(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+=T(t),c+="\n</svg>",c}return'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>'},t.signSvgBody=T,t.symbolFill=C,t.symbolFlop=(t,e=!0)=>{let o=g(t);if(!o.symbol)return t;if(!j(o.symbol))return t;o.symbol=i(o.symbol);const l=e?1:-1,n=o.symbol.slice(0,4);let a=parseInt(o.symbol.slice(4,5)),r=o.symbol.slice(5,6),d="";for(;!d||!j(s(d));)a+=l,a>5&&(a=0),a<0&&(a=5),d=n+a+r;return o.symbol=s(d),u(o)},t.symbolLine=A,t.symbolMirror=t=>{let e=g(t);if(!e.symbol)return t;if(!j(e.symbol))return t;e.symbol=i(e.symbol);const o=e.symbol.slice(0,4);let l=e.symbol.slice(4,5),n=parseInt(e.symbol.slice(5,6),16);const a=o+"18";var r;j(s(o+"08"))||j(s(a))?r=8:(0!==n&&4!=n||(r=0),1!=n&&5!=n||(r=6),2!=n&&6!=n||(r=4),3!=n&&7!=n||(r=2));let d="";for(;!d||!j(s(d));)n+=r,n>7&&r<8&&(n-=8),n>15&&(n-=16),d=o+l+n.toString(16);return e.symbol=s(d),u(e)},t.symbolNormalize=t=>{const o=g(t);if(!o.symbol)return null;{let t=j(o.symbol);if(t)return`${o.symbol}${e([500-parseInt((t[0]+1)/2),500-parseInt((t[1]+1)/2)])}${o.style||""}`}},t.symbolPng=t=>{const e=function(t){const e=g(t);if(e.symbol){let t=j(e.symbol);if(t){const o=document.createElement("canvas"),l=o.getContext("2d");let i=Z(e.style),s="black";i.colorize?s=S(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(C(e.symbol),(500-a)*m,(500-d)*m),l.font=30*m+"px 'SuttonSignWritingLine'",l.fillStyle=s,l.fillText(A(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=g(t);if(!o.symbol)return t;if(!j(o.symbol))return t;o.symbol=i(o.symbol);const l=e?1:-1,n=o.symbol.slice(0,4);let a=o.symbol.slice(4,5),r=parseInt(o.symbol.slice(5,6),16),d="";for(;!d||!j(s(d));)r>7?(r+=l,r>15&&(r=8),r<8&&(r=15),d=n+a+r.toString(16)):(r-=l,r>7&&(r=0),r<0&&(r=7),d=n+a+r);return o.symbol=s(d),u(o)},t.symbolScroll=(t,e=!0)=>{let o=g(t);if(!o.symbol)return t;if(!j(o.symbol))return t;o.symbol=i(o.symbol);const l=e?1:-1,n=parseInt(o.symbol.slice(1,4),16)+l,a=o.symbol.slice(4,5),r=o.symbol.slice(5,6),d="S"+n.toString(16)+a+r;return 6==d.length&&j(s(d))&&(o.symbol=d),o.symbol=s(o.symbol),u(o)},t.symbolSize=j,t.symbolSvg=t=>{const e=g(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,a=Z(e.style);if(e.coord)l=e.coord[0],i=e.coord[1],s=500-l+500,n=500-i+500;else{let t=j(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 r="";a.classes&&(r=` class="${a.classes}"`);let d="";a.id&&(d=` id="${a.id}"`),a.padding&&(l-=a.padding,i-=a.padding,s+=a.padding,n+=a.padding);let c="";return"x"!=a.zoom&&(c=` width="${(s-l)*(a.zoom?a.zoom:1)}" height="${(n-i)*(a.zoom?a.zoom:1)}"`),`<svg${r}${d} version="1.1" xmlns="http://www.w3.org/2000/svg"${c} viewBox="${l} ${i} ${s-l} ${n-i}">\n${O(t)}\n</svg>`},t.symbolSvgBody=O,t.symbolText=P,Object.defineProperty(t,"__esModule",{value:!0})}));