UNPKG

21.4 kBJavaScriptView Raw
1/* Sutton SignWriting Core Module v1.1.0, author: Steve Slevinski, license: MIT */
2let e={symbol:"S[123][0-9a-f]{2}[0-5][0-9a-f]",coord:"[0-9]{3}x[0-9]{3}",sort:"A",box:"[BLMR]"};e.prefix=`(?:${e.sort}(?:${e.symbol})+)`,e.spatial=`${e.symbol}${e.coord}`,e.signbox=`${e.box}${e.coord}(?:${e.spatial})*`,e.sign=`${e.prefix}?${e.signbox}`,e.term=`${e.prefix}${e.signbox}`;let r={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}"};r.colorbase=`(?:${r.colorhex}|${r.colorname})`,r.color=`_${r.colorbase}_`,r.colors=`_${r.colorbase}(?:,${r.colorbase})?_`,r.background=`G${r.color}`,r.detail=`D${r.colors}`,r.detailsym=`D[0-9]{2}${r.colors}`,r.classes=`${r.classbase}(?: ${r.classbase})*`,r.full=`-(${r.colorize})?(${r.padding})?(${r.background})?(${r.detail})?(${r.zoom})?(?:-((?:${r.detailsym})*)((?:${r.zoomsym})*))?(?:-(${r.classes})?!(?:(${r.id})!)?)?`;const s=e=>{return(new RegExp(`^${r.colorhex}$`).test(e)?"#":"")+e};var t=Object.freeze({__proto__:null,re:r,parse:e=>{const t=`^${r.full}`,a="string"==typeof e?e.match(new RegExp(t)):[];return{colorize:a[1]?!!a[1]:void 0,padding:a[2]?parseInt(a[2].slice(1)):void 0,background:a[3]?s(a[3].slice(2,-1)):void 0,detail:a[4]?a[4].slice(2,-1).split(",").map(s):void 0,zoom:a[5]?"Zx"===a[5]?"x":parseFloat(a[5].slice(1)):void 0,detailsym:a[6]?a[6].match(new RegExp(r.detailsym,"g")).map(e=>{const r=e.split("_"),t=r[1].split(",").map(s);return{index:parseInt(r[0].slice(1)),detail:t}}):void 0,zoomsym:a[7]?a[7].match(new RegExp(r.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 s="-";s+=e.colorize?"C":"";const t=parseInt(e.padding);s+=!t||t<=0||t>99?"":"P"+(t>9?t:"0"+t);const a=e.background&&"string"==typeof e.background?e.background.match(r.colorbase)[0]:void 0;s+=a?"G_"+a+"_":"";const o=e.detail&&e.detail[0]&&"string"==typeof e.detail[0]?e.detail[0].match(r.colorbase)[0]:void 0,n=e.detail&&e.detail[1]&&"string"==typeof e.detail[1]?e.detail[1].match(r.colorbase)[0]:void 0;o&&(s+="D_"+o,n&&(s+=","+n),s+="_");const i="x"===e.zoom?"x":parseFloat(e.zoom);s+=!i||i<=0?"":"Z"+i;let c="";c+=(e.detailsym&&Array.isArray(e.detailsym)?e.detailsym.map(e=>{const s=parseInt(e.index);if(!s||s<=0||s>99)return"";let t="D"+(s>9?s:"0"+s);const a=e.detail&&e.detail[0]?e.detail[0].match(r.colorbase)[0]:void 0,o=e.detail&&e.detail[1]?e.detail[1].match(r.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(r.classes)[0]:void 0;l+=u||"";const p=e.id&&"string"==typeof e.id?e.id.match(r.id)[0]:void 0;return l+=u||p?"!":"",l+=p?p+"!":"",s+(c||l?"-"+c:"")+(l?"-"+l:"")}});let a={symbol:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:\ud836[\udc0c-\uddff]){2}",sort:"𝠀",box:"\ud836[\udc01-\udc04]"};a.prefix=`(?:${a.sort}(?:${a.symbol})+)`,a.spatial=`${a.symbol}${a.coord}`,a.signbox=`${a.box}${a.coord}(?:${a.spatial})*`,a.sign=`${a.prefix}?${a.signbox}`,a.term=`${a.prefix}${a.signbox}`;const o=e=>({A:"𝠀",B:"𝠁",L:"𝠂",M:"𝠃",R:"𝠄"})[e],n=e=>parseInt(e.codePointAt(0))-120844+250,i=e=>String.fromCodePoint(120844+parseInt(e)-250),c=e=>[n(e.slice(0,2)),n(e.slice(2,4))],l=e=>e.map(e=>i(e)).join(""),u=e=>e.split("x").map(e=>parseInt(e)),p=e=>parseInt(e.codePointAt(0)),f=e=>String.fromCodePoint(e),d=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)},g=e=>f(262145+96*(parseInt(e.slice(1,4),16)-256)+16*parseInt(e.slice(4,5),16)+parseInt(e.slice(5,6),16));var m=Object.freeze({__proto__:null,swu2mark:e=>({"𝠀":"A","𝠁":"B","𝠂":"L","𝠃":"M","𝠄":"R"})[e],mark2swu:o,swu2num:n,num2swu:i,swu2coord:c,coord2swu:l,fsw2coord:u,coord2fsw:e=>e.join("x"),swu2code:p,code2swu:f,swu2id:e=>p(e)-262144,id2swu:e=>f(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:d,key2swu:g,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(a.symbol,"g"));s&&s.forEach((function(e){r=r.replace(e,d(e))}));const t=r.match(new RegExp(a.coord,"g"));return t&&t.forEach((function(e){r=r.replace(e,c(e).join("x"))})),r},fsw2swu:r=>{if(!r)return"";const s=r.match(new RegExp(e.prefix,"g"));s&&s.forEach((function(e){r=r.replace(e,"𝠀"+e.slice(1).match(/.{6}/g).map(e=>g(e)).join(""))}));const t=r.match(new RegExp(e.box+e.coord,"g"));t&&t.forEach((function(e){r=r.replace(e,o(e.slice(0,1))+l(u(e.slice(1,8))))}));const a=r.match(new RegExp(e.spatial,"g"));return a&&a.forEach((function(e){r=r.replace(e,g(e.slice(0,6))+l(u(e.slice(6,13))))})),r}});const b={symbol:s=>{const t=`^(${e.symbol})(${e.coord})?(${r.full})?`,a="string"==typeof s?s.match(new RegExp(t)):void 0;return{symbol:a?a[1]:void 0,coord:a&&a[2]?u(a[2]):void 0,style:a?a[3]:void 0}},sign:s=>{const t=`^(${e.prefix})?(${e.signbox})(${r.full})?`,a="string"==typeof s?s.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:u(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]}:{}}},h=[256,517,759,767,877,895,903],x={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]},y=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];var $=Object.freeze({__proto__:null,re:e,parse:b,kind:[256,895,903],category:h,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:x,isType:(e,r)=>{const s=b.symbol(e);if(s.symbol){const e=parseInt(s.symbol.slice(1,4),16),t=x[r];if(t)return t[0]<=e&&t[1]>=e}return!1},colors:y,colorize:e=>{const r=b.symbol(e);let s="#000000";if(r.symbol){const e=parseInt(r.symbol.slice(1,4),16),t=h.findIndex(r=>r>e);s=y[t<0?6:t-1]}return s}});let w={base:"[123][0-9a-f]{2}",coord:"(?:[0-9]{3}x[0-9]{3})?",var:"V[0-9]+"};w.symbol=`S${w.base}[0-5u][0-9a-fu]`,w.range=`R${w.base}t${w.base}`,w.prefix=`(?:A(?:${w.symbol}|${w.range})+)?T`,w.signbox=`(?:${w.symbol}${w.coord}|${w.range}${w.coord})*`,w.full=`Q(${w.prefix})?(${w.signbox})?(${w.var})?(-?)`;const v=e=>({required:!0,parts:"T"==e?void 0:e.match(new RegExp(`(${w.symbol}|${w.range})`,"g")).map(e=>"S"==e[0]?e:e.slice(1).split("t"))}),I=e=>e.match(new RegExp(`(${w.symbol}${w.coord}|${w.range}${w.coord})`,"g")).map(e=>{let r,s;return e.includes("x")?(r=u(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}}),k=(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(")|("))+"))"},R=e=>{if(!(e=e.match(new RegExp(`^${w.full}`))[0]))return"";var s,t,a,o,n,i,c,l,u,p,f,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]",v="("+r.full+")?";if("Q"==e)return[x+"?"+h];if("Q-"==e)return[x+"?"+h+v];if("QT"==e)return[x+h];if("QT-"==e)return[x+h+v];var I=[],R=e.indexOf("T")+1;if(R){d="(A";var A=e.slice(0,R);if(e=e.replace(A,""),"QT"==A)d+="("+m+")+)";else if(s=A.match(new RegExp("("+$+"|"+y+")","g"))){var E;for(t=0;t<s.length;t+=1)(E=s[t].match(new RegExp($)))?(c=E[0].slice(0,4),c+="u"==(p=E[0].slice(4,5))?"[0-5]":p,d+=c+="u"==(f=E[0].slice(5,6))?"[0-9a-f]":f):(n=s[t].slice(1,4),i=s[t].slice(5,8),d+=c="S"+k(n,i,"hex")+"[0-5][0-9a-f]");d+="("+m+")*)"}}if((s=e.match(new RegExp("(V[0-9]+)","g")))&&(g=1*s.toString().slice(1)),a=$+"([0-9]{3}x[0-9]{3})?",s=e.match(new RegExp(a,"g")))for(t=0;t<s.length;t+=1)c="S"+(o=s[t].toString()).slice(1,4),c+="u"==(p=o.slice(4,5))?"[0-5]":p,c+="u"==(f=o.slice(5,6))?"[0-9a-f]":f,o.length>6?(l=1*o.slice(6,9),u=1*o.slice(10,13),c+=k(l-g,l+g),c+="x",c+=k(u-g,u+g)):c+=b,c=h+c+"("+m+b+")*",c=R?d+c:x+"?"+c,e.indexOf("-")>0&&(c+=v),I.push(c);if(a=y+"([0-9]{3}x[0-9]{3})?",s=e.match(new RegExp(a,"g")))for(t=0;t<s.length;t+=1)n=(o=s[t].toString()).slice(1,4),i=o.slice(5,8),c="S"+k(n,i,"hex")+"[0-5][0-9a-f]",o.length>8?(l=1*o.slice(8,11),u=1*o.slice(12,15),c+=k(l-g,l+g),c+="x",c+=k(u-g,u+g)):c+=b,c=h+c+"("+m+b+")*",c=R?d+c:x+"?"+c,e.indexOf("-")>0&&(c+=v),I.push(c);return I.length||(e.indexOf("-")>0&&(c+=v),I.push(d+h)),I};var A=Object.freeze({__proto__:null,re:w,parse:e=>{const r="string"==typeof e?e.match(new RegExp(`^${w.full}`)):void 0;return{query:!!r||void 0,prefix:r&&r[1]?v(r[1]):void 0,signbox:r&&r[2]?I(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(`^${w.full}`))[0]},fsw2query:(e,r)=>{let s="";const t=b.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:k,regex:R,results:(e,r)=>{if(!r)return[];let s,t,a,o,n,i=R(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=R(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 E={symbol:e=>{const s=`^(${a.symbol})(${a.coord})?(${r.full})?`,t="string"==typeof e?e.match(new RegExp(s)):void 0;return{symbol:t?t[1]:void 0,coord:t&&t[2]?c(t[2]):void 0,style:t?t[3]:void 0}},sign:e=>{const s=`^(${a.prefix})?(${a.signbox})(${r.full})?`,t="string"==typeof e?e.match(new RegExp(s)):void 0;return t?{sequence:t[1]?t[1].slice(2).match(/.{2}/g):void 0,box:t[2].slice(0,2),max:c(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:c(e.slice(2))})),style:t[3]}:{}}},S=e=>e.replace(/\\u([0-9A-F]{4})/g,(function(e,r){return String.fromCharCode(parseInt(r,16))})),_=e=>[e.charCodeAt(0).toString(16).toUpperCase(),e.charCodeAt(1).toString(16).toUpperCase()],F=[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]},j=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];var C=Object.freeze({__proto__:null,re:a,parse:E,encode:e=>e.replace(/[\u007F-\uFFFF]/g,(function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4).toUpperCase()})),decode:S,pair:_,kind:[262145,323489,324257],category:F,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=E.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:j,colorize:e=>{const r=E.symbol(e);let s="#000000";if(r.symbol){const e=p(r.symbol),t=F.findIndex(r=>r>e);s=j[t<0?6:t-1]}return s}});let O={base:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:(?:\ud836[\udc0c-\uddff]){2})?",var:"V[0-9]+"};O.symbol=`${O.base}f?r?`,O.range=`R${O.base}${O.base}`,O.prefix=`(?:A(?:${O.symbol}|${O.range})+)?T`,O.signbox=`(?:${O.symbol}${O.coord}|${O.range}${O.coord})*`,O.full=`Q(${O.prefix})?(${O.signbox})?(${O.var})?(-?)`;const q=e=>({required:!0,parts:"T"==e?void 0:e.match(new RegExp(`(${O.symbol}|${O.range})`,"g")).map(e=>"R"!=e[0]?e:[e.slice(1,3),e.slice(3,5)])}),T=e=>e.match(new RegExp(`(${O.symbol}${O.coord}|${O.range}${O.coord})`,"g")).map(e=>{let r,s;return e.length>5?(r=c(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}}),Q=(e,r)=>{if(e>r)return"";let s,t="",a=[];if(e=_(e),r=_(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(")|("))+"))",S(t)},D=e=>{let r=e.match(new RegExp(O.symbol));if(r){let e,s,t=r[0].slice(0,2),a=d(t),o=a.slice(0,4);if("fr"==r[0].slice(-2))return e=g(o+"00"),s=g(o+"5f"),Q(e,s);if("r"==r[0].slice(-1))return e=g(a.slice(0,5)+"0"),s=g(a.slice(0,5)+"f"),Q(e,s);if("f"==r[0].slice(-1)){return"("+[0,1,2,3,4,5].map((function(e){return g(o+e+a.slice(-1))})).join("|")+")"}return t}return""},Z=e=>{if(!(e=e.match(new RegExp(`^${O.full}`))[0]))return"";let s,t,o,n,i,u,p,f,m,b,h=20,x=a.symbol,y=a.coord,$=a.box+y+"("+x+y+")*",w="("+a.sort+"("+x+")+)",v="R"+x+x,I=x+"f?r?",k="("+y+")?",R="("+r.full+")?";if("Q"==e)return[a.sign];if("Q-"==e)return[a.sign+"("+r.full+")?"];if("QT"==e)return[a.term];if("QT-"==e)return[a.term+"("+r.full+")?"];let A,E=[],S=e.indexOf("T")+1;if(S){b="("+a.sort;let r=e.slice(0,S);if(e=e.replace(r,""),"QT"==r)b+="("+x+")+)";else if(s=r.match(new RegExp("("+I+"|"+v+")","g"))){let e;for(t=0;t<s.length;t+=1)(e=s[t].match(new RegExp("^"+I)))?b+=D(e[0]):(n=d(s[t].slice(1,3)),i=d(s[t].slice(-2)),n=g(n.slice(0,4)+"00"),i=g(i.slice(0,4)+"5f"),b+=Q(n,i));b+="("+x+")*)"}}if((s=e.match(new RegExp("(V[0-9]+)","g")))&&(h=1*s.toString().slice(1)),s=e.match(new RegExp("("+v+k+"|"+I+k+")","g")))for(t=0;t<s.length;t+=1)"R"!=(o=s[t].toString())[0]?(A=o.match(new RegExp(I))[0],p=D(A),A.length>o.length?(f=(u=c(o.slice(-4)))[0],m=u[1],p+=Q(l([f-h,f+h])),p+=Q(l([m-h,m+h]))):p+=y,p=$+p+"("+x+y+")*",p=S?b+p:w+"?"+p,e.indexOf("-")>0&&(p+=R),E.push(p)):(o=s[t].toString(),n=d(o.slice(1,3)),i=d(o.slice(3,5)),n=g(n.slice(0,4)+"00"),i=g(i.slice(0,4)+"5f"),p=Q(n,i),o.length>5?(f=(u=c(o.slice(5,9)))[0],m=u[1],p+=Q(l([f-h,f+h])),p+=Q(l([m-h,m+h]))):p+=y,p=$+p+"("+x+y+")*",p=S?b+p:w+"?"+p,e.indexOf("-")>0&&(p+=R),E.push(p));return E.length||(e.indexOf("-")>0&&(p+=R),E.push(b+$)),E};var L=Object.freeze({__proto__:null,re:O,parse:e=>{const r="string"==typeof e?e.match(new RegExp(`^${O.full}`)):void 0;return{query:!!r||void 0,prefix:r&&r[1]?q(r[1]):void 0,signbox:r&&r[2]?T(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?l(e.coord):"")}).join("")),r=(r+=e.style?"-":"").match(new RegExp(`^${O.full}`))[0]},swu2query:(e,r)=>{let s="";const t=E.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?l(e.coord):"")).join(""))),s?"Q"+s:void 0}},range:Q,symbolRanges:D,regex:Z,results:(e,r)=>{if(!r)return[];let s,t,a,o,n,i=Z(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=Z(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)}),{}):[]}});export{m as convert,$ as fsw,A as fswquery,t as style,C as swu,L as swuquery};