UNPKG

22 kBJavaScriptView Raw
1/* Sutton SignWriting TrueType Font Module v1.2.0 (https://github.com/sutton-signwriting/font-ttf), author: Steve Slevinski (https://SteveSlevinski.me), license: MIT */
2!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o(((t=t||self).ssw=t.ssw||{},t.ssw.ttf={}))}(this,(function(t){"use strict";let o={};const e=document.createElement("canvas");e.width=152,e.height=152;const l=e.getContext("2d"),i=function(t){if(t in o)return[...o[t]];l.clearRect(0,0,152,152),l.font="60px 'SuttonSignWritingLine'",l.fillText(String.fromCodePoint(t+983040),0,0);const e=l.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(n=4*i+4*s*152+a,e[n])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(n=4*i+4*s*152+a,e[n])break t;var d=s+1;if(r=Math.ceil(r/2),d=Math.ceil(d/2),14394==t&&(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(t)&&(r=20),31921==t&&(r=22),38460==t&&(r=23),[20164,20212].includes(t)&&(r=25),31894==t&&(r=28),46698==t&&(r=29),29606==t&&(r=30),44855==t&&(r=40),32667==t&&(r=50),[11088,11474,11490,11506].includes(t)&&(d=20),6285==t&&(d=21),40804==t&&(d=31),41475==t&&(d=36),0==r&&0==d){const o={9:[15,30],10:[21,30],11:[30,15],12:[30,21],13:[15,30],14:[21,30]};t in o&&(r=o[t][0],d=o[t][1])}return 0!=r||0!=d?(o[t]=[r,d],[r,d]):void 0},s=function(t){return String.fromCodePoint(t+983040)},n=function(t){return String.fromCodePoint(t+1048576)},a=function(t){return` <text class="sym-fill" fill="white" style="pointer-events:none;font-family:'SuttonSignWritingFill';font-size:30px;">${n(t)}</text>\n <text class="sym-line" fill="black" style="pointer-events:none;font-family:'SuttonSignWritingLine';font-size:30px;">${s(t)}</text>`},r=function(t){if(i(1))t();else{const o=setInterval((function(){i(1)&&(clearInterval(o),t())}),100)}},d=function(t){const o=function(){const t=document.createElement("canvas");t.width=15,t.height=30;const o=t.getContext("2d");o.font="30px 'SuttonSignWritingFill'",o.fillText(n(1),0,0);return!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 c=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://cdn.jsdelivr.net/npm/@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://cdn.jsdelivr.net/npm/@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://cdn.jsdelivr.net/npm/@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;r(()=>{o=!0}),d(()=>{e=!0});const l=setInterval((function(){o&&e&&(clearInterval(l),t())}),100)},cssLoadedLine:r,cssLoadedFill:d,symbolSize:i,symbolLine:s,symbolFill:n,symbolText:a});const m=t=>t.map(t=>(t=>String.fromCodePoint(120844+parseInt(t)-250))(t)).join(""),f=t=>(t=>parseInt(t.codePointAt(0)))(t)-262144,p=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 i(p(t))},y=function(t){return s(p(t))},x=function(t){return n(p(t))},u=function(t){return a(p(t))};let $={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}"};$.colorbase=`(?:${$.colorhex}|${$.colorname})`,$.color=`_${$.colorbase}_`,$.colors=`_${$.colorbase}(?:,${$.colorbase})?_`,$.background="G"+$.color,$.detail="D"+$.colors,$.detailsym="D[0-9]{2}"+$.colors,$.classes=`${$.classbase}(?: ${$.classbase})*`,$.full=`-(${$.colorize})?(${$.padding})?(${$.background})?(${$.detail})?(${$.zoom})?(?:-((?:${$.detailsym})*)((?:${$.zoomsym})*))?(?:-(${$.classes})?!(?:(${$.id})!)?)?`;const b=t=>(new RegExp(`^${$.colorhex}$`).test(t)?"#":"")+t,h=t=>{const o="^"+$.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]?b(e[3].slice(2,-1)):void 0,detail:e[4]?e[4].slice(2,-1).split(",").map(b):void 0,zoom:e[5]?"Zx"===e[5]?"x":parseFloat(e[5].slice(1)):void 0,detailsym:e[6]?e[6].match(new RegExp($.detailsym,"g")).map(t=>{const o=t.split("_"),e=o[1].split(",").map(b);return{index:parseInt(o[0].slice(1)),detail:e}}):void 0,zoomsym:e[7]?e[7].match(new RegExp($.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 z={symbol:"S[123][0-9a-f]{2}[0-5][0-9a-f]",coord:"[0-9]{3}x[0-9]{3}",sort:"A",box:"[BLMR]"};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.sortable=`${z.prefix}${z.signbox}`;let v={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}"};v.colorbase=`(?:${v.colorhex}|${v.colorname})`,v.color=`_${v.colorbase}_`,v.colors=`_${v.colorbase}(?:,${v.colorbase})?_`,v.background="G"+v.color,v.detail="D"+v.colors,v.detailsym="D[0-9]{2}"+v.colors,v.classes=`${v.classbase}(?: ${v.classbase})*`,v.full=`-(${v.colorize})?(${v.padding})?(${v.background})?(${v.detail})?(${v.zoom})?(?:-((?:${v.detailsym})*)((?:${v.zoomsym})*))?(?:-(${v.classes})?!(?:(${v.id})!)?)?`;const w=t=>t.split("x").map(t=>parseInt(t)),S=t=>{const o=`^(${z.symbol})(${z.coord})?(${v.full})?`,e="string"==typeof t?t.match(new RegExp(o)):void 0;return{symbol:e?e[1]:void 0,coord:e&&e[2]?w(e[2]):void 0,style:e?e[3]:void 0}},I=t=>{const o=`^(${z.prefix})?(${z.signbox})(${v.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:w(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]}:{}},_=[256,517,759,767,877,895,903],k=[767,876],F=[767,885],M=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"],E=t=>{const o=S(t);let e="#000000";if(o.symbol){const t=parseInt(o.symbol.slice(1,4),16),l=_.findIndex(o=>o>t);e=M[l<0?6:l-1]}return e};var A=Object.freeze({__proto__:null,symbolSize:g,symbolLine:y,symbolFill:x,symbolText:u,symbolSvg:t=>{const o=S(t);if(o.symbol){let e=g(o.symbol);if(e){let l,i=h(o.style),s=u(o.symbol);s=` <g transform="translate(500,500)">\n${s}\n </g>`,i.colorize?l=E(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=S(t);if(o.symbol){let t=g(o.symbol);if(t){const e=document.createElement("canvas"),l=e.getContext("2d");let i=h(o.style),s="black";i.colorize?s=E(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,p=(c-d)*m;return e.width=f||1,e.height=p||1,i.background&&(l.rect(0,0,f,p),l.fillStyle=i.background,l.fill()),l.font=30*m+"px 'SuttonSignWritingFill'",l.fillStyle=n,l.fillText(x(o.symbol),(500-a)*m,(500-d)*m),l.font=30*m+"px 'SuttonSignWritingLine'",l.fillStyle=s,l.fillText(y(o.symbol),(500-a)*m,(500-d)*m),e}}}(t),e=o.toDataURL("image/png");return o.remove(),e},symbolNormalize:t=>{const o=S(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=I(t);if(o.spatials){let e=h(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=u(t.symbol),l=f;t.detail?l=t.detail[0]:e.colorize&&(l=E(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>",m}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=I(t);if(o.spatials){const t=document.createElement("canvas"),e=t.getContext("2d");let l=h(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=E(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(x(t.symbol),(t.coord[0]-i)*r,(t.coord[1]-s)*r),e.font=30*r*a+"px 'SuttonSignWritingLine'",e.fillStyle=o,e.fillText(y(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=I(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=>({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=F,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 C=function(t){return i(f(t))},W=function(t){return s(f(t))},L=function(t){return n(f(t))},Z=function(t){return a(f(t))};let D={symbol:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:\ud836[\udc0c-\uddff]){2}",sort:"𝠀",box:"\ud836[\udc01-\udc04]"};D.prefix=`(?:${D.sort}(?:${D.symbol})+)`,D.spatial=`${D.symbol}${D.coord}`,D.signbox=`${D.box}${D.coord}(?:${D.spatial})*`,D.sign=`${D.prefix}?${D.signbox}`,D.sortable=`${D.prefix}${D.signbox}`;let j={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}"};j.colorbase=`(?:${j.colorhex}|${j.colorname})`,j.color=`_${j.colorbase}_`,j.colors=`_${j.colorbase}(?:,${j.colorbase})?_`,j.background="G"+j.color,j.detail="D"+j.colors,j.detailsym="D[0-9]{2}"+j.colors,j.classes=`${j.classbase}(?: ${j.classbase})*`,j.full=`-(${j.colorize})?(${j.padding})?(${j.background})?(${j.detail})?(${j.zoom})?(?:-((?:${j.detailsym})*)((?:${j.zoomsym})*))?(?:-(${j.classes})?!(?:(${j.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=`^(${D.symbol})(${D.coord})?(${j.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}},O=t=>{const o=`^(${D.prefix})?(${D.signbox})(${j.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]}:{}},q=[262145,287201,310433,311201,321761,323489,324257],B=[311201,321760],N=[311201,322624],U=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"],G=t=>{const o=T(t);let e="#000000";if(o.symbol){const t=(t=>parseInt(t.codePointAt(0)))(o.symbol),l=q.findIndex(o=>o>t);e=U[l<0?6:l-1]}return e};var H=Object.freeze({__proto__:null,symbolSize:C,symbolLine:W,symbolFill:L,symbolText:Z,symbolSvg:t=>{const o=T(t);if(o.symbol){let e=C(o.symbol);if(e){let l,i=h(o.style),s=Z(o.symbol);s=` <g transform="translate(500,500)">\n${s}\n </g>`,i.colorize?l=G(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=C(o.symbol);if(t){const e=document.createElement("canvas"),l=e.getContext("2d");let i=h(o.style),s="black";i.colorize?s=G(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,p=(c-d)*m;return e.width=f||1,e.height=p||1,i.background&&(l.rect(0,0,f,p),l.fillStyle=i.background,l.fill()),l.font=30*m+"px 'SuttonSignWritingFill'",l.fillStyle=n,l.fillText(L(o.symbol),(500-a)*m,(500-d)*m),l.font=30*m+"px 'SuttonSignWritingLine'",l.fillStyle=s,l.fillText(W(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=C(o.symbol);if(t)return`${o.symbol}${m([500-parseInt(t[0]/2),500-parseInt(t[1]/2)])}${o.style||""}`}},signSvg:t=>{let o=O(t);if(o.spatials){let e=h(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=C(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=Z(t.symbol,t.coord),l=f;t.detail?l=t.detail[0]:e.colorize&&(l=G(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>",m}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=O(t);if(o.spatials){const t=document.createElement("canvas"),e=t.getContext("2d");let l=h(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=C(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=G(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(L(t.symbol),(t.coord[0]-i)*r,(t.coord[1]-s)*r),e.font=30*r*a+"px 'SuttonSignWritingLine'",e.fillStyle=o,e.fillText(W(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=O(t);if(o.spatials){const t=o.spatials.reduce((t,o)=>{const e=C(o.symbol);return t[o.symbol]={width:e[0],height:e[1]},t},{}),e=o=>({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=B,i=o.spatials.filter(t=>{const o=parseInt(t.symbol.slice(1,4),16);return l[0]<=o&&l[1]>=o}),s=N,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+m([r[0]-d[0],r[1]-d[1]])+o.spatials.map(t=>t.symbol+m([t.coord[0]-d[0],t.coord[1]-d[1]])).join("")+(o.style||"")}}});t.font=c,t.fsw=A,t.swu=H,Object.defineProperty(t,"__esModule",{value:!0})}));