UNPKG

21.7 kBJavaScriptView Raw
1/* Sutton SignWriting Core Module v1.1.0, author: Steve Slevinski, license: MIT */
2!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(((e=e||self).ssw=e.ssw||{},e.ssw.core={}))}(this,(function(e){"use strict";let r={symbol:"S[123][0-9a-f]{2}[0-5][0-9a-f]",coord:"[0-9]{3}x[0-9]{3}",sort:"A",box:"[BLMR]"};r.prefix=`(?:${r.sort}(?:${r.symbol})+)`,r.spatial=`${r.symbol}${r.coord}`,r.signbox=`${r.box}${r.coord}(?:${r.spatial})*`,r.sign=`${r.prefix}?${r.signbox}`,r.term=`${r.prefix}${r.signbox}`;let s={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}"};s.colorbase=`(?:${s.colorhex}|${s.colorname})`,s.color=`_${s.colorbase}_`,s.colors=`_${s.colorbase}(?:,${s.colorbase})?_`,s.background=`G${s.color}`,s.detail=`D${s.colors}`,s.detailsym=`D[0-9]{2}${s.colors}`,s.classes=`${s.classbase}(?: ${s.classbase})*`,s.full=`-(${s.colorize})?(${s.padding})?(${s.background})?(${s.detail})?(${s.zoom})?(?:-((?:${s.detailsym})*)((?:${s.zoomsym})*))?(?:-(${s.classes})?!(?:(${s.id})!)?)?`;const t=e=>{return(new RegExp(`^${s.colorhex}$`).test(e)?"#":"")+e};var a=Object.freeze({__proto__:null,re:s,parse:e=>{const r=`^${s.full}`,a="string"==typeof e?e.match(new RegExp(r)):[];return{colorize:a[1]?!!a[1]:void 0,padding:a[2]?parseInt(a[2].slice(1)):void 0,background:a[3]?t(a[3].slice(2,-1)):void 0,detail:a[4]?a[4].slice(2,-1).split(",").map(t):void 0,zoom:a[5]?"Zx"===a[5]?"x":parseFloat(a[5].slice(1)):void 0,detailsym:a[6]?a[6].match(new RegExp(s.detailsym,"g")).map(e=>{const r=e.split("_"),s=r[1].split(",").map(t);return{index:parseInt(r[0].slice(1)),detail:s}}):void 0,zoomsym:a[7]?a[7].match(new RegExp(s.zoomsym,"g")).map(e=>{const r=e.split(",");return{index:parseInt(r[0].slice(1)),zoom:parseFloat(r[1]),offset:r[2]?r[2].split("x").map(e=>parseInt(e)-500):void 0}}):void 0,classes:a[8]?a[8]:void 0,id:a[9]?a[9]:void 0}},compose:e=>{let r="-";r+=e.colorize?"C":"";const t=parseInt(e.padding);r+=!t||t<=0||t>99?"":"P"+(t>9?t:"0"+t);const a=e.background&&"string"==typeof e.background?e.background.match(s.colorbase)[0]:void 0;r+=a?"G_"+a+"_":"";const o=e.detail&&e.detail[0]&&"string"==typeof e.detail[0]?e.detail[0].match(s.colorbase)[0]:void 0,n=e.detail&&e.detail[1]&&"string"==typeof e.detail[1]?e.detail[1].match(s.colorbase)[0]:void 0;o&&(r+="D_"+o,n&&(r+=","+n),r+="_");const i="x"===e.zoom?"x":parseFloat(e.zoom);r+=!i||i<=0?"":"Z"+i;let c="";c+=(e.detailsym&&Array.isArray(e.detailsym)?e.detailsym.map(e=>{const r=parseInt(e.index);if(!r||r<=0||r>99)return"";let t="D"+(r>9?r:"0"+r);const a=e.detail&&e.detail[0]?e.detail[0].match(s.colorbase)[0]:void 0,o=e.detail&&e.detail[1]?e.detail[1].match(s.colorbase)[0]:void 0;return a&&(t+="_"+a,o&&(t+=","+o),t+="_"),t}):[]).join(""),c+=(e.zoomsym&&Array.isArray(e.zoomsym)?e.zoomsym.map(e=>{const r=parseInt(e.index);if(!r||r<=0||r>99)return"";let s="Z"+(r>9?r:"0"+r);const t=parseFloat(e.zoom);if(s+=!t||t<=0?"":","+t,e.offset&&0 in e.offset&&1 in e.offset){const r=parseInt(e.offset[0])+500,t=parseInt(e.offset[1])+500;r>=250&&r<750&&t>=250&&t<750&&(s+=","+r+"x"+t)}return s}):[]).join("");let l="";const u=e.classes&&"string"==typeof e.classes?e.classes.match(s.classes)[0]:void 0;l+=u||"";const f=e.id&&"string"==typeof e.id?e.id.match(s.id)[0]:void 0;return l+=u||f?"!":"",l+=f?f+"!":"",r+(c||l?"-"+c:"")+(l?"-"+l:"")}});let o={symbol:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:\ud836[\udc0c-\uddff]){2}",sort:"𝠀",box:"\ud836[\udc01-\udc04]"};o.prefix=`(?:${o.sort}(?:${o.symbol})+)`,o.spatial=`${o.symbol}${o.coord}`,o.signbox=`${o.box}${o.coord}(?:${o.spatial})*`,o.sign=`${o.prefix}?${o.signbox}`,o.term=`${o.prefix}${o.signbox}`;const n=e=>({A:"𝠀",B:"𝠁",L:"𝠂",M:"𝠃",R:"𝠄"})[e],i=e=>parseInt(e.codePointAt(0))-120844+250,c=e=>String.fromCodePoint(120844+parseInt(e)-250),l=e=>[i(e.slice(0,2)),i(e.slice(2,4))],u=e=>e.map(e=>c(e)).join(""),f=e=>e.split("x").map(e=>parseInt(e)),p=e=>parseInt(e.codePointAt(0)),d=e=>String.fromCodePoint(e),g=e=>{const r=p(e)-262145,s=parseInt(r/96),t=parseInt((r-96*s)/16),a=parseInt(r-96*s-16*t);return"S"+(s+256).toString(16)+t.toString(16)+a.toString(16)},m=e=>d(262145+96*(parseInt(e.slice(1,4),16)-256)+16*parseInt(e.slice(4,5),16)+parseInt(e.slice(5,6),16));var b=Object.freeze({__proto__:null,swu2mark:e=>({"𝠀":"A","𝠁":"B","𝠂":"L","𝠃":"M","𝠄":"R"})[e],mark2swu:n,swu2num:i,num2swu:c,swu2coord:l,coord2swu:u,fsw2coord:f,coord2fsw:e=>e.join("x"),swu2code:p,code2swu:d,swu2id:e=>p(e)-262144,id2swu:e=>d(e+262144),key2id:e=>1+96*(parseInt(e.slice(1,4),16)-256)+16*parseInt(e.slice(4,5),16)+parseInt(e.slice(5,6),16),id2key:e=>{const r=e-1,s=parseInt(r/96),t=parseInt((r-96*s)/16),a=parseInt(r-96*s-16*t);return"S"+(s+256).toString(16)+t.toString(16)+a.toString(16)},swu2key:g,key2swu:m,swu2fsw:e=>{if(!e)return"";let r=e.replace(/𝠀/g,"A").replace(/𝠁/g,"B").replace(/𝠂/g,"L").replace(/𝠃/g,"M").replace(/𝠄/g,"R");const s=r.match(new RegExp(o.symbol,"g"));s&&s.forEach((function(e){r=r.replace(e,g(e))}));const t=r.match(new RegExp(o.coord,"g"));return t&&t.forEach((function(e){r=r.replace(e,l(e).join("x"))})),r},fsw2swu:e=>{if(!e)return"";const s=e.match(new RegExp(r.prefix,"g"));s&&s.forEach((function(r){e=e.replace(r,"𝠀"+r.slice(1).match(/.{6}/g).map(e=>m(e)).join(""))}));const t=e.match(new RegExp(r.box+r.coord,"g"));t&&t.forEach((function(r){e=e.replace(r,n(r.slice(0,1))+u(f(r.slice(1,8))))}));const a=e.match(new RegExp(r.spatial,"g"));return a&&a.forEach((function(r){e=e.replace(r,m(r.slice(0,6))+u(f(r.slice(6,13))))})),e}});const h={symbol:e=>{const t=`^(${r.symbol})(${r.coord})?(${s.full})?`,a="string"==typeof e?e.match(new RegExp(t)):void 0;return{symbol:a?a[1]:void 0,coord:a&&a[2]?f(a[2]):void 0,style:a?a[3]:void 0}},sign:e=>{const t=`^(${r.prefix})?(${r.signbox})(${s.full})?`,a="string"==typeof e?e.match(new RegExp(t)):void 0;return a?{sequence:a[1]?a[1].slice(1).match(/.{6}/g):void 0,box:a[2][0],max:f(a[2].slice(1,8)),spatials:a[2].length<9?void 0:a[2].slice(8).match(/(.{13})/g).map(e=>({symbol:e.slice(0,6),coord:[parseInt(e.slice(6,9)),parseInt(e.slice(10,13))]})),style:a[3]}:{}}},x=[256,517,759,767,877,895,903],y={all:[256,907],writing:[256,894],hand:[256,516],movement:[517,758],dynamic:[759,766],head:[767,876],hcenter:[767,876],vcenter:[767,885],trunk:[877,885],limb:[886,894],location:[895,902],punctuation:[903,907]},$=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];var w=Object.freeze({__proto__:null,re:r,parse:h,kind:[256,895,903],category:x,group:[256,270,286,324,332,390,420,442,461,501,517,534,554,597,613,648,678,695,725,739,759,767,778,810,827,857,877,886,895,903],ranges:y,isType:(e,r)=>{const s=h.symbol(e);if(s.symbol){const e=parseInt(s.symbol.slice(1,4),16),t=y[r];if(t)return t[0]<=e&&t[1]>=e}return!1},colors:$,colorize:e=>{const r=h.symbol(e);let s="#000000";if(r.symbol){const e=parseInt(r.symbol.slice(1,4),16),t=x.findIndex(r=>r>e);s=$[t<0?6:t-1]}return s}});let v={base:"[123][0-9a-f]{2}",coord:"(?:[0-9]{3}x[0-9]{3})?",var:"V[0-9]+"};v.symbol=`S${v.base}[0-5u][0-9a-fu]`,v.range=`R${v.base}t${v.base}`,v.prefix=`(?:A(?:${v.symbol}|${v.range})+)?T`,v.signbox=`(?:${v.symbol}${v.coord}|${v.range}${v.coord})*`,v.full=`Q(${v.prefix})?(${v.signbox})?(${v.var})?(-?)`;const I=e=>({required:!0,parts:"T"==e?void 0:e.match(new RegExp(`(${v.symbol}|${v.range})`,"g")).map(e=>"S"==e[0]?e:e.slice(1).split("t"))}),k=e=>e.match(new RegExp(`(${v.symbol}${v.coord}|${v.range}${v.coord})`,"g")).map(e=>{let r,s;return e.includes("x")?(r=f(e.slice(-7)),s=e.slice(0,-7)):s=e,s.includes("S")?{symbol:s,coord:r}:{range:s.slice(1).split("t"),coord:r}}),R=(e,r,s)=>{let t,a,o,n,i,c,l;if(s||(s=""),t="",(e=("000"+e).slice(-3))===(r=""+r))return e;if(a=[],(e[0]!=r[0]||e[1]!=r[1])&&"0"!=e[2])if(t=e[0]+e[1],s){switch(e[2]){case"f":t+="f";break;case"e":t+="[ef]";break;case"d":case"c":case"b":case"a":t+="["+e[2]+"-f]";break;default:switch(e[2]){case"9":t+="[9a-f]";break;case"8":t+="[89a-f]";break;default:t+="["+e[2]+"-9a-f]"}}o=15-parseInt(e[2],16)+1,e=""+(parseInt(e,16)+o).toString(16),a.push(t)}else{switch(e[2]){case"9":t+="9";break;case"8":t+="[89]";break;default:t+="["+e[2]+"-9]"}e=""+(1*e+(o=9-e[2]+1)),a.push(t)}if(t="",e[0]!=r[0]&&"0"!=e[1])if(s){switch(t=e[0],e[1]){case"f":t+="f";break;case"e":t+="[ef]";break;case"d":case"c":case"b":case"a":t+="["+e[1]+"-f]";break;case"9":t+="[9a-f]";break;case"8":t+="[89a-f]";break;default:t+="["+e[1]+"-9a-f]"}t+="[0-9a-f]",o=15-parseInt(e[1],16)+1,e=""+(parseInt(e,16)+16*o).toString(16),a.push(t)}else{switch(t=e[0],o=9-e[1]+1,e[1]){case"9":t+="9";break;case"8":t+="[89]";break;default:t+="["+e[1]+"-9]"}t+="[0-9]",e=""+(1*e+10*(o=9-e[1]+1)),a.push(t)}if(t="",e[0]!=r[0])if(s){switch(o=parseInt(r[0],16)-parseInt(e[0],16),n=(parseInt(e[0],16)+o-1).toString(16),o){case 1:t=e[0];break;case 2:t="["+e[0]+n+"]";break;default:switch((c=parseInt(e[0],16)>9?"h":"d")+(l=parseInt(n,16)>9?"h":"d")){case"dd":t+="["+e[0]+"-"+n+"]";break;case"dh":switch(o=9-e[0]){case 0:t+="[9";break;case 1:t+="[89";break;default:t+="["+e[0]+"-9"}switch(n[0]){case"a":t+="a]";break;case"b":t+="ab]";break;default:t+="a-"+n+"]"}break;case"hh":t+="["+e[0]+"-"+n+"]"}}t+="[0-9a-f][0-9a-f]",o=parseInt(r[0],16)-parseInt(e[0],16),e=""+(parseInt(e,16)+256*o).toString(16),a.push(t)}else{switch(o=r[0]-e[0],n=1*e[0]+o-1,o){case 1:t=e[0];break;case 2:t="["+e[0]+n+"]";break;default:t="["+e[0]+"-"+n+"]"}t+="[0-9][0-9]",e=""+(1*e+100*o),a.push(t)}if(t="",e[1]!=r[1])if(s){switch(o=parseInt(r[1],16)-parseInt(e[1],16),n=(parseInt(e[1],16)+o-1).toString(16),t=e[0],o){case 1:t+=e[1];break;case 2:t+="["+e[1]+n+"]";break;default:switch((c=parseInt(e[1],16)>9?"h":"d")+(l=parseInt(n,16)>9?"h":"d")){case"dd":t+="["+e[1],o>1&&(t+="-"),t+=n+"]";break;case"dh":switch(o=9-e[1]){case 0:t+="[9";break;case 1:t+="[89";break;default:t+="["+e[1]+"-9"}switch(r[1]){case"a":t+="]";break;case"b":t+="a]";break;default:t+="a-"+(parseInt(r[1],16)-1).toString(16)+"]"}break;case"hh":t+="["+e[1],o>1&&(t+="-"),t+=(parseInt(r[1],16)-1).toString(16)+"]"}}t+="[0-9a-f]",o=parseInt(r[1],16)-parseInt(e[1],16),e=""+(parseInt(e,16)+16*o).toString(16),a.push(t)}else{switch(o=r[1]-e[1],n=1*e[1]+o-1,t=e[0],o){case 1:t+=e[1];break;case 2:t+="["+e[1]+n+"]";break;default:t+="["+e[1]+"-"+n+"]"}t+="[0-9]",e=""+(1*e+10*o),a.push(t)}if(t="",e[2]!=r[2])if(s){switch(t=e[0]+e[1],o=parseInt(r[2],16)-parseInt(e[2],16),(c=parseInt(e[2],16)>9?"h":"d")+(l=parseInt(r[2],16)>9?"h":"d")){case"dd":t+="["+e[2],o>1&&(t+="-"),t+=r[2]+"]";break;case"dh":switch(o=9-e[2]){case 0:t+="[9";break;case 1:t+="[89";break;default:t+="["+e[2]+"-9"}switch(r[2]){case"a":t+="a]";break;case"b":t+="ab]";break;default:t+="a-"+r[2]+"]"}break;case"hh":t+="["+e[2],o>1&&(t+="-"),t+=r[2]+"]"}o=parseInt(r[2],16)-parseInt(e[2],16),e=""+(parseInt(e,16)+o).toString(16),a.push(t)}else{switch(o=r[2]-e[2],t=e[0]+e[1],o){case 0:t+=e[2];break;case 1:t+="["+e[2]+r[2]+"]";break;default:t+="["+e[2]+"-"+r[2]+"]"}e=""+(1*e+o),a.push(t)}return t="","0"==e[2]&&"0"==r[2]&&(t=r,a.push(t)),t="",t=1==(i=a.length)?a[0]:"(("+(t=a.join(")|("))+"))"},A=e=>{if(!(e=e.match(new RegExp(`^${v.full}`))[0]))return"";var r,t,a,o,n,i,c,l,u,f,p,d,g=20,m="S[123][0-9a-f]{2}[0-5][0-9a-f]",b="[0-9]{3}x[0-9]{3}",h="[BLMR]("+b+")("+m+b+")*",x="(A("+m+")+)",y="R[123][0-9a-f]{2}t[123][0-9a-f]{2}",$="S[123][0-9a-f]{2}[0-5u][0-9a-fu]",w="("+s.full+")?";if("Q"==e)return[x+"?"+h];if("Q-"==e)return[x+"?"+h+w];if("QT"==e)return[x+h];if("QT-"==e)return[x+h+w];var I=[],k=e.indexOf("T")+1;if(k){d="(A";var A=e.slice(0,k);if(e=e.replace(A,""),"QT"==A)d+="("+m+")+)";else if(r=A.match(new RegExp("("+$+"|"+y+")","g"))){var E;for(t=0;t<r.length;t+=1)(E=r[t].match(new RegExp($)))?(c=E[0].slice(0,4),c+="u"==(f=E[0].slice(4,5))?"[0-5]":f,d+=c+="u"==(p=E[0].slice(5,6))?"[0-9a-f]":p):(n=r[t].slice(1,4),i=r[t].slice(5,8),d+=c="S"+R(n,i,"hex")+"[0-5][0-9a-f]");d+="("+m+")*)"}}if((r=e.match(new RegExp("(V[0-9]+)","g")))&&(g=1*r.toString().slice(1)),a=$+"([0-9]{3}x[0-9]{3})?",r=e.match(new RegExp(a,"g")))for(t=0;t<r.length;t+=1)c="S"+(o=r[t].toString()).slice(1,4),c+="u"==(f=o.slice(4,5))?"[0-5]":f,c+="u"==(p=o.slice(5,6))?"[0-9a-f]":p,o.length>6?(l=1*o.slice(6,9),u=1*o.slice(10,13),c+=R(l-g,l+g),c+="x",c+=R(u-g,u+g)):c+=b,c=h+c+"("+m+b+")*",c=k?d+c:x+"?"+c,e.indexOf("-")>0&&(c+=w),I.push(c);if(a=y+"([0-9]{3}x[0-9]{3})?",r=e.match(new RegExp(a,"g")))for(t=0;t<r.length;t+=1)n=(o=r[t].toString()).slice(1,4),i=o.slice(5,8),c="S"+R(n,i,"hex")+"[0-5][0-9a-f]",o.length>8?(l=1*o.slice(8,11),u=1*o.slice(12,15),c+=R(l-g,l+g),c+="x",c+=R(u-g,u+g)):c+=b,c=h+c+"("+m+b+")*",c=k?d+c:x+"?"+c,e.indexOf("-")>0&&(c+=w),I.push(c);return I.length||(e.indexOf("-")>0&&(c+=w),I.push(d+h)),I};var E=Object.freeze({__proto__:null,re:v,parse:e=>{const r="string"==typeof e?e.match(new RegExp(`^${v.full}`)):void 0;return{query:!!r||void 0,prefix:r&&r[1]?I(r[1]):void 0,signbox:r&&r[2]?k(r[2]):void 0,variance:r&&r[3]?parseInt(r[3].slice(1)):void 0,style:!(!r||!r[4])||void 0}},compose:e=>{if(!e||!e.query)return;let r="Q";return e.prefix&&e.prefix.required&&(Array.isArray(e.prefix.parts)&&(r+="A",r+=e.prefix.parts.map(e=>"string"==typeof e?e:Array.isArray(e)&&2==e.length?`R${e[0]}t${e[1]}`:void 0).join("")),r+="T"),Array.isArray(e.signbox)&&(r+=e.signbox.map(e=>{let r;return e.symbol?r=e.symbol:e.range&&Array.isArray(e.range)&&2==e.range.length&&(r=`R${e.range[0]}t${e.range[1]}`),r+(Array.isArray(e.coord)&&2==e.coord.length?e.coord.join("x"):"")}).join("")),r=(r+=e.style?"-":"").match(new RegExp(`^${v.full}`))[0]},fsw2query:(e,r)=>{let s="";const t=h.sign(e);if(t.box){const e=r.indexOf("A")>-1,a=r.indexOf("a")>-1,o=r.indexOf("S")>-1,n=r.indexOf("s")>-1,i=r.indexOf("L")>-1;return(e||a||o||n)&&((e||a)&&t.sequence&&(s+="A",s+=t.sequence.map(e=>e.slice(0,4)+(a?"uu":e.slice(4,6))).join(""),s+="T"),(o||n)&&t.spatials&&(s+=t.spatials.map(e=>e.symbol.slice(0,4)+(n?"uu":e.symbol.slice(4,6))+(i?e.coord.join("x"):"")).join(""))),s?"Q"+s:void 0}},range:R,regex:A,results:(e,r)=>{if(!r)return[];let s,t,a,o,n,i=A(e);if(!i)return[];for(n=0;n<i.length;n+=1)s=i[n],t=r.match(new RegExp(s,"g")),r=t?t.join(" "):"";return o=r?(a=r.split(" ")).filter((function(e){return!(e in a)&&(a[e]=!0)}),{}):[]},lines:(e,r)=>{if(!r)return[];let s,t,a,o,n,i=A(e);if(!i)return[];for(n=0;n<i.length;n+=1)s="^"+(s=i[n])+".*",t=r.match(new RegExp(s,"mg")),r=t?t.join("\n"):"";return o=r?(a=r.split("\n")).filter((function(e){return!(e in a)&&(a[e]=!0)}),{}):[]}});const S={symbol:e=>{const r=`^(${o.symbol})(${o.coord})?(${s.full})?`,t="string"==typeof e?e.match(new RegExp(r)):void 0;return{symbol:t?t[1]:void 0,coord:t&&t[2]?l(t[2]):void 0,style:t?t[3]:void 0}},sign:e=>{const r=`^(${o.prefix})?(${o.signbox})(${s.full})?`,t="string"==typeof e?e.match(new RegExp(r)):void 0;return t?{sequence:t[1]?t[1].slice(2).match(/.{2}/g):void 0,box:t[2].slice(0,2),max:l(t[2].slice(2,6)),spatials:t[2].length<7?void 0:t[2].slice(6).match(/(.{6})/g).map(e=>({symbol:e.slice(0,2),coord:l(e.slice(2))})),style:t[3]}:{}}},_=e=>e.replace(/\\u([0-9A-F]{4})/g,(function(e,r){return String.fromCharCode(parseInt(r,16))})),F=e=>[e.charCodeAt(0).toString(16).toUpperCase(),e.charCodeAt(1).toString(16).toUpperCase()],j=[262145,287201,310433,311201,321761,323489,324257],z={all:[262145,324736],writing:[262145,323488],hand:[262145,287200],movement:[287201,310432],dynamic:[310433,311200],head:[311201,321760],hcenter:[311201,321760],vcenter:[311201,322624],trunk:[321761,322624],limb:[322625,323488],location:[323489,324256],punctuation:[324257,324736]},C=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];var O=Object.freeze({__proto__:null,re:o,parse:S,encode:e=>e.replace(/[\u007F-\uFFFF]/g,(function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4).toUpperCase()})),decode:_,pair:F,kind:[262145,323489,324257],category:j,group:[262145,263489,265025,268673,269441,275009,277889,280001,281825,285665,287201,288833,290753,294881,296417,299777,302657,304289,307169,308513,310433,311201,312257,315329,316961,319841,321761,322625,323489,324257],ranges:z,isType:(e,r)=>{const s=S.symbol(e);if(s.symbol){const e=p(s.symbol),t=z[r];if(t)return t[0]<=e&&t[1]>=e}return!1},colors:C,colorize:e=>{const r=S.symbol(e);let s="#000000";if(r.symbol){const e=p(r.symbol),t=j.findIndex(r=>r>e);s=C[t<0?6:t-1]}return s}});let q={base:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:(?:\ud836[\udc0c-\uddff]){2})?",var:"V[0-9]+"};q.symbol=`${q.base}f?r?`,q.range=`R${q.base}${q.base}`,q.prefix=`(?:A(?:${q.symbol}|${q.range})+)?T`,q.signbox=`(?:${q.symbol}${q.coord}|${q.range}${q.coord})*`,q.full=`Q(${q.prefix})?(${q.signbox})?(${q.var})?(-?)`;const T=e=>({required:!0,parts:"T"==e?void 0:e.match(new RegExp(`(${q.symbol}|${q.range})`,"g")).map(e=>"R"!=e[0]?e:[e.slice(1,3),e.slice(3,5)])}),Q=e=>e.match(new RegExp(`(${q.symbol}${q.coord}|${q.range}${q.coord})`,"g")).map(e=>{let r,s;return e.length>5?(r=l(e.slice(-4)),s=e.slice(0,-4)):s=e,s.includes("R")?{range:[s.slice(1,3),s.slice(3,5)],coord:r}:{symbol:s,coord:r}}),D=(e,r)=>{if(e>r)return"";let s,t="",a=[];if(e=F(e),r=F(r),2!=e.length&&2!=r.length)return"";if(e[0]==r[0])e[1]==r[1]?(t="\\u"+e[0]+"\\u"+e[1],a.push(t)):(t="\\u"+e[0]+"[\\u"+e[1]+"-\\u"+r[1]+"]",a.push(t));else{t="DFFF"==e[1]?"\\u"+e[0]+"\\uDFFF":"\\u"+e[0]+"[\\u"+e[1]+"-\\uDFFF]",a.push(t);let s=parseInt(r[0],16)-parseInt(e[0],16);2==s&&(t="\\u"+(parseInt(e[0],16)+1).toString(16).toUpperCase(),t+="[\\uDC00-\\uDFFF]",a.push(t)),s>2&&(t="[",t+="\\u"+(parseInt(e[0],16)+1).toString(16).toUpperCase(),t+="-\\u"+(parseInt(r[0],16)-1).toString(16).toUpperCase(),t+="][\\uDC00-\\uDFFF]",a.push(t)),t="DC00"==r[1]?"\\u"+r[0]+"\\uDC00":"\\u"+r[0]+"[\\uDC00-\\u"+r[1]+"]",a.push(t)}return t=1==(s=a.length)?a[0]:"(("+(t=a.join(")|("))+"))",_(t)},Z=e=>{let r=e.match(new RegExp(q.symbol));if(r){let e,s,t=r[0].slice(0,2),a=g(t),o=a.slice(0,4);if("fr"==r[0].slice(-2))return e=m(o+"00"),s=m(o+"5f"),D(e,s);if("r"==r[0].slice(-1))return e=m(a.slice(0,5)+"0"),s=m(a.slice(0,5)+"f"),D(e,s);if("f"==r[0].slice(-1)){return"("+[0,1,2,3,4,5].map((function(e){return m(o+e+a.slice(-1))})).join("|")+")"}return t}return""},L=e=>{if(!(e=e.match(new RegExp(`^${q.full}`))[0]))return"";let r,t,a,n,i,c,f,p,d,b,h=20,x=o.symbol,y=o.coord,$=o.box+y+"("+x+y+")*",w="("+o.sort+"("+x+")+)",v="R"+x+x,I=x+"f?r?",k="("+y+")?",R="("+s.full+")?";if("Q"==e)return[o.sign];if("Q-"==e)return[o.sign+"("+s.full+")?"];if("QT"==e)return[o.term];if("QT-"==e)return[o.term+"("+s.full+")?"];let A,E=[],S=e.indexOf("T")+1;if(S){b="("+o.sort;let s=e.slice(0,S);if(e=e.replace(s,""),"QT"==s)b+="("+x+")+)";else if(r=s.match(new RegExp("("+I+"|"+v+")","g"))){let e;for(t=0;t<r.length;t+=1)(e=r[t].match(new RegExp("^"+I)))?b+=Z(e[0]):(n=g(r[t].slice(1,3)),i=g(r[t].slice(-2)),n=m(n.slice(0,4)+"00"),i=m(i.slice(0,4)+"5f"),b+=D(n,i));b+="("+x+")*)"}}if((r=e.match(new RegExp("(V[0-9]+)","g")))&&(h=1*r.toString().slice(1)),r=e.match(new RegExp("("+v+k+"|"+I+k+")","g")))for(t=0;t<r.length;t+=1)"R"!=(a=r[t].toString())[0]?(A=a.match(new RegExp(I))[0],f=Z(A),A.length>a.length?(p=(c=l(a.slice(-4)))[0],d=c[1],f+=D(u([p-h,p+h])),f+=D(u([d-h,d+h]))):f+=y,f=$+f+"("+x+y+")*",f=S?b+f:w+"?"+f,e.indexOf("-")>0&&(f+=R),E.push(f)):(a=r[t].toString(),n=g(a.slice(1,3)),i=g(a.slice(3,5)),n=m(n.slice(0,4)+"00"),i=m(i.slice(0,4)+"5f"),f=D(n,i),a.length>5?(p=(c=l(a.slice(5,9)))[0],d=c[1],f+=D(u([p-h,p+h])),f+=D(u([d-h,d+h]))):f+=y,f=$+f+"("+x+y+")*",f=S?b+f:w+"?"+f,e.indexOf("-")>0&&(f+=R),E.push(f));return E.length||(e.indexOf("-")>0&&(f+=R),E.push(b+$)),E};var P=Object.freeze({__proto__:null,re:q,parse:e=>{const r="string"==typeof e?e.match(new RegExp(`^${q.full}`)):void 0;return{query:!!r||void 0,prefix:r&&r[1]?T(r[1]):void 0,signbox:r&&r[2]?Q(r[2]):void 0,variance:r&&r[3]?parseInt(r[3].slice(1)):void 0,style:!(!r||!r[4])||void 0}},compose:e=>{if(!e||!e.query)return;let r="Q";return e.prefix&&e.prefix.required&&(Array.isArray(e.prefix.parts)&&(r+="A",r+=e.prefix.parts.map(e=>"string"==typeof e?e:Array.isArray(e)&&2==e.length?`R${e[0]}${e[1]}`:void 0).join("")),r+="T"),Array.isArray(e.signbox)&&(r+=e.signbox.map(e=>{let r;return e.symbol?r=e.symbol:e.range&&Array.isArray(e.range)&&2==e.range.length&&(r=`R${e.range[0]}${e.range[1]}`),r+(Array.isArray(e.coord)&&2==e.coord.length?u(e.coord):"")}).join("")),r=(r+=e.style?"-":"").match(new RegExp(`^${q.full}`))[0]},swu2query:(e,r)=>{let s="";const t=S.sign(e);if(t.box){const e=r.indexOf("A")>-1,a=r.indexOf("a")>-1,o=r.indexOf("S")>-1,n=r.indexOf("s")>-1,i=r.indexOf("L")>-1;return(e||a||o||n)&&((e||a)&&t.sequence&&(s+="A",s+=t.sequence.map(e=>e+(a?"fr":"")).join(""),s+="T"),(o||n)&&t.spatials&&(s+=t.spatials.map(e=>e.symbol+(n?"fr":"")+(i?u(e.coord):"")).join(""))),s?"Q"+s:void 0}},range:D,symbolRanges:Z,regex:L,results:(e,r)=>{if(!r)return[];let s,t,a,o,n,i=L(e);if(!i)return[];for(n=0;n<i.length;n+=1)s=i[n],t=r.match(new RegExp(s,"g")),r=t?t.join(" "):"";return o=r?(a=r.split(" ")).filter((function(e){return!(e in a)&&(a[e]=!0)}),{}):[]},lines:(e,r)=>{if(!r)return[];let s,t,a,o,n,i=L(e);if(!i)return[];for(n=0;n<i.length;n+=1)s="^"+(s=i[n])+".*",t=r.match(new RegExp(s,"mg")),r=t?t.join("\n"):"";return o=r?(a=r.split("\n")).filter((function(e){return!(e in a)&&(a[e]=!0)}),{}):[]}});e.convert=b,e.fsw=w,e.fswquery=E,e.style=a,e.swu=O,e.swuquery=P,Object.defineProperty(e,"__esModule",{value:!0})}));