UNPKG

23.8 kBJavaScriptView Raw
1/* Sutton SignWriting Core Module v1.2.0 (https://github.com/sutton-signwriting/core), author: Steve Slevinski (https://SteveSlevinski.me), 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.sortable=`${r.prefix}${r.signbox}`;let t={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}"};t.colorbase=`(?:${t.colorhex}|${t.colorname})`,t.color=`_${t.colorbase}_`,t.colors=`_${t.colorbase}(?:,${t.colorbase})?_`,t.background=`G${t.color}`,t.detail=`D${t.colors}`,t.detailsym=`D[0-9]{2}${t.colors}`,t.classes=`${t.classbase}(?: ${t.classbase})*`,t.full=`-(${t.colorize})?(${t.padding})?(${t.background})?(${t.detail})?(${t.zoom})?(?:-((?:${t.detailsym})*)((?:${t.zoomsym})*))?(?:-(${t.classes})?!(?:(${t.id})!)?)?`;const s=e=>{return(new RegExp(`^${t.colorhex}$`).test(e)?"#":"")+e};var o=Object.freeze({__proto__:null,re:t,parse:e=>{const r=`^${t.full}`,o=("string"==typeof e?e.match(new RegExp(r)):[])||[];return{colorize:o[1]?!!o[1]:void 0,padding:o[2]?parseInt(o[2].slice(1)):void 0,background:o[3]?s(o[3].slice(2,-1)):void 0,detail:o[4]?o[4].slice(2,-1).split(",").map(s):void 0,zoom:o[5]?"Zx"===o[5]?"x":parseFloat(o[5].slice(1)):void 0,detailsym:o[6]?o[6].match(new RegExp(t.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:o[7]?o[7].match(new RegExp(t.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:o[8]?o[8]:void 0,id:o[9]?o[9]:void 0}},compose:e=>{if("object"!=typeof e||null===e)return;let r="-";r+=e.colorize?"C":"";const s=parseInt(e.padding);r+=!s||s<=0||s>99?"":"P"+(s>9?s:"0"+s);const o=e.background&&"string"==typeof e.background?e.background.match(t.colorbase)[0]:void 0;r+=o?"G_"+o+"_":"";const a=e.detail&&e.detail[0]&&"string"==typeof e.detail[0]?e.detail[0].match(t.colorbase)[0]:void 0,n=e.detail&&e.detail[1]&&"string"==typeof e.detail[1]?e.detail[1].match(t.colorbase)[0]:void 0;a&&(r+="D_"+a,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 s="D"+(r>9?r:"0"+r);const o=e.detail&&e.detail[0]?e.detail[0].match(t.colorbase)[0]:void 0,a=e.detail&&e.detail[1]?e.detail[1].match(t.colorbase)[0]:void 0;return o&&(s+="_"+o,a&&(s+=","+a),s+="_"),s}):[]).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 t="Z"+(r>9?r:"0"+r);const s=parseFloat(e.zoom);if(t+=!s||s<=0?"":","+s,e.offset&&0 in e.offset&&1 in e.offset){const r=parseInt(e.offset[0])+500,s=parseInt(e.offset[1])+500;r>=250&&r<750&&s>=250&&s<750&&(t+=","+r+"x"+s)}return t}):[]).join("");let l="";const f=e.classes&&"string"==typeof e.classes?e.classes.match(t.classes)[0]:void 0;l+=f||"";const u=e.id&&"string"==typeof e.id?e.id.match(t.id)[0]:void 0;return l+=f||u?"!":"",l+=u?u+"!":"",r+(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.sortable=`${a.prefix}${a.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))],f=e=>e.map(e=>c(e)).join(""),u=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,t=parseInt(r/96),s=parseInt((r-96*t)/16),o=parseInt(r-96*t-16*s);return"S"+(t+256).toString(16)+s.toString(16)+o.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:f,fsw2coord:u,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,t=parseInt(r/96),s=parseInt((r-96*t)/16),o=parseInt(r-96*t-16*s);return"S"+(t+256).toString(16)+s.toString(16)+o.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 t=r.match(new RegExp(a.symbol,"g"));t&&t.forEach((function(e){r=r.replace(e,g(e))}));const s=r.match(new RegExp(a.coord,"g"));return s&&s.forEach((function(e){r=r.replace(e,l(e).join("x"))})),r},fsw2swu:e=>{if(!e)return"";const t=e.match(new RegExp(r.prefix,"g"));t&&t.forEach((function(r){e=e.replace(r,"𝠀"+r.slice(1).match(/.{6}/g).map(e=>m(e)).join(""))}));const s=e.match(new RegExp(r.box+r.coord,"g"));s&&s.forEach((function(r){e=e.replace(r,n(r.slice(0,1))+f(u(r.slice(1,8))))}));const o=e.match(new RegExp(r.spatial,"g"));return o&&o.forEach((function(r){e=e.replace(r,m(r.slice(0,6))+f(u(r.slice(6,13))))})),e}});const y={symbol:e=>{const s=`^(${r.symbol})(${r.coord})?(${t.full})?`,o="string"==typeof e?e.match(new RegExp(s)):void 0;return{symbol:o?o[1]:void 0,coord:o&&o[2]?u(o[2]):void 0,style:o?o[3]:void 0}},sign:e=>{const s=`^(${r.prefix})?(${r.signbox})(${t.full})?`,o="string"==typeof e?e.match(new RegExp(s)):void 0;return o?{sequence:o[1]?o[1].slice(1).match(/.{6}/g):void 0,box:o[2][0],max:u(o[2].slice(1,8)),spatials:o[2].length<9?void 0:o[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:o[3]}:{}}},h={symbol:e=>{if("string"==typeof e.symbol){const s=(e.symbol.match(r.symbol)||[""])[0];if(s){return s+((((e.coord&&e.coord[0]||"").toString()+"x"+(e.coord&&e.coord[1]||"").toString()).match(r.coord)||[""])[0]||"")+("string"==typeof e.style&&(e.style.match(t.full)||[""])[0]||"")}}},sign:e=>{let s="string"!=typeof e.box?"M":(e.box+"M").match(r.box);const o=(((e.max&&e.max[0]||"").toString()+"x"+(e.max&&e.max[1]||"").toString()).match(r.coord)||[""])[0]||"";if(!o)return;let a="";e.sequence&&Array.isArray(e.sequence)&&(a=(a=e.sequence.map(e=>(e.match(r.symbol)||[""])[0]).join(""))?"A"+a:"");let n="";return e.spatials&&Array.isArray(e.spatials)&&(n=e.spatials.map(e=>{if("string"==typeof e.symbol){const t=(e.symbol.match(r.symbol)||[""])[0];if(t){const s=(((e.coord&&e.coord[0]||"").toString()+"x"+(e.coord&&e.coord[1]||"").toString()).match(r.coord)||[""])[0]||"";if(s)return t+s}}return""}).join("")),a+s+o+n+("string"==typeof e.style&&(e.style.match(t.full)||[""])[0]||"")}},x=[256,517,759,767,877,895,903],$={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]},w=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];var v=Object.freeze({__proto__:null,re:r,parse:y,compose: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:$,isType:(e,r)=>{const t=y.symbol(e);if(t.symbol){const e=parseInt(t.symbol.slice(1,4),16),s=$[r];if(s)return s[0]<=e&&s[1]>=e}return!1},colors:w,colorize:e=>{const r=y.symbol(e);let t="#000000";if(r.symbol){const e=parseInt(r.symbol.slice(1,4),16),s=x.findIndex(r=>r>e);t=w[s<0?6:s-1]}return t}});let I={base:"[123][0-9a-f]{2}",coord:"(?:[0-9]{3}x[0-9]{3})?",var:"V[0-9]+"};I.symbol=`S${I.base}[0-5u][0-9a-fu]`,I.range=`R${I.base}t${I.base}`,I.prefix=`(?:A(?:${I.symbol}|${I.range})+)?T`,I.signbox=`(?:${I.symbol}${I.coord}|${I.range}${I.coord})*`,I.full=`Q(${I.prefix})?(${I.signbox})?(${I.var})?(-?)`;const A=e=>({required:!0,parts:"T"==e?void 0:e.match(new RegExp(`(${I.symbol}|${I.range})`,"g")).map(e=>"S"==e[0]?e:e.slice(1).split("t"))}),k=e=>e.match(new RegExp(`(${I.symbol}${I.coord}|${I.range}${I.coord})`,"g")).map(e=>{let r,t;return e.includes("x")?(r=u(e.slice(-7)),t=e.slice(0,-7)):t=e,t.includes("S")?{symbol:t,coord:r}:{range:t.slice(1).split("t"),coord:r}}),R=(e,r,t)=>{let s,o,a,n,i,c,l;if(t||(t=""),s="",(e=("000"+e).slice(-3))===(r=""+r))return e;if(o=[],(e[0]!=r[0]||e[1]!=r[1])&&"0"!=e[2])if(s=e[0]+e[1],t){switch(e[2]){case"f":s+="f";break;case"e":s+="[ef]";break;case"d":case"c":case"b":case"a":s+="["+e[2]+"-f]";break;default:switch(e[2]){case"9":s+="[9a-f]";break;case"8":s+="[89a-f]";break;default:s+="["+e[2]+"-9a-f]"}}a=15-parseInt(e[2],16)+1,e=""+(parseInt(e,16)+a).toString(16),o.push(s)}else{switch(e[2]){case"9":s+="9";break;case"8":s+="[89]";break;default:s+="["+e[2]+"-9]"}e=""+(1*e+(a=9-e[2]+1)),o.push(s)}if(s="",e[0]!=r[0]&&"0"!=e[1])if(t){switch(s=e[0],e[1]){case"f":s+="f";break;case"e":s+="[ef]";break;case"d":case"c":case"b":case"a":s+="["+e[1]+"-f]";break;case"9":s+="[9a-f]";break;case"8":s+="[89a-f]";break;default:s+="["+e[1]+"-9a-f]"}s+="[0-9a-f]",a=15-parseInt(e[1],16)+1,e=""+(parseInt(e,16)+16*a).toString(16),o.push(s)}else{switch(s=e[0],a=9-e[1]+1,e[1]){case"9":s+="9";break;case"8":s+="[89]";break;default:s+="["+e[1]+"-9]"}s+="[0-9]",e=""+(1*e+10*(a=9-e[1]+1)),o.push(s)}if(s="",e[0]!=r[0])if(t){switch(a=parseInt(r[0],16)-parseInt(e[0],16),n=(parseInt(e[0],16)+a-1).toString(16),a){case 1:s=e[0];break;case 2:s="["+e[0]+n+"]";break;default:switch((c=parseInt(e[0],16)>9?"h":"d")+(l=parseInt(n,16)>9?"h":"d")){case"dd":s+="["+e[0]+"-"+n+"]";break;case"dh":switch(a=9-e[0]){case 0:s+="[9";break;case 1:s+="[89";break;default:s+="["+e[0]+"-9"}switch(n[0]){case"a":s+="a]";break;case"b":s+="ab]";break;default:s+="a-"+n+"]"}break;case"hh":s+="["+e[0]+"-"+n+"]"}}s+="[0-9a-f][0-9a-f]",a=parseInt(r[0],16)-parseInt(e[0],16),e=""+(parseInt(e,16)+256*a).toString(16),o.push(s)}else{switch(a=r[0]-e[0],n=1*e[0]+a-1,a){case 1:s=e[0];break;case 2:s="["+e[0]+n+"]";break;default:s="["+e[0]+"-"+n+"]"}s+="[0-9][0-9]",e=""+(1*e+100*a),o.push(s)}if(s="",e[1]!=r[1])if(t){switch(a=parseInt(r[1],16)-parseInt(e[1],16),n=(parseInt(e[1],16)+a-1).toString(16),s=e[0],a){case 1:s+=e[1];break;case 2:s+="["+e[1]+n+"]";break;default:switch((c=parseInt(e[1],16)>9?"h":"d")+(l=parseInt(n,16)>9?"h":"d")){case"dd":s+="["+e[1],a>1&&(s+="-"),s+=n+"]";break;case"dh":switch(a=9-e[1]){case 0:s+="[9";break;case 1:s+="[89";break;default:s+="["+e[1]+"-9"}switch(r[1]){case"a":s+="]";break;case"b":s+="a]";break;default:s+="a-"+(parseInt(r[1],16)-1).toString(16)+"]"}break;case"hh":s+="["+e[1],a>1&&(s+="-"),s+=(parseInt(r[1],16)-1).toString(16)+"]"}}s+="[0-9a-f]",a=parseInt(r[1],16)-parseInt(e[1],16),e=""+(parseInt(e,16)+16*a).toString(16),o.push(s)}else{switch(a=r[1]-e[1],n=1*e[1]+a-1,s=e[0],a){case 1:s+=e[1];break;case 2:s+="["+e[1]+n+"]";break;default:s+="["+e[1]+"-"+n+"]"}s+="[0-9]",e=""+(1*e+10*a),o.push(s)}if(s="",e[2]!=r[2])if(t){switch(s=e[0]+e[1],a=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":s+="["+e[2],a>1&&(s+="-"),s+=r[2]+"]";break;case"dh":switch(a=9-e[2]){case 0:s+="[9";break;case 1:s+="[89";break;default:s+="["+e[2]+"-9"}switch(r[2]){case"a":s+="a]";break;case"b":s+="ab]";break;default:s+="a-"+r[2]+"]"}break;case"hh":s+="["+e[2],a>1&&(s+="-"),s+=r[2]+"]"}a=parseInt(r[2],16)-parseInt(e[2],16),e=""+(parseInt(e,16)+a).toString(16),o.push(s)}else{switch(a=r[2]-e[2],s=e[0]+e[1],a){case 0:s+=e[2];break;case 1:s+="["+e[2]+r[2]+"]";break;default:s+="["+e[2]+"-"+r[2]+"]"}e=""+(1*e+a),o.push(s)}return s="","0"==e[2]&&"0"==r[2]&&(s=r,o.push(s)),s="",s=1==(i=o.length)?o[0]:"(("+(s=o.join(")|("))+"))"},S=e=>{if(!(e=e.match(new RegExp(`^${I.full}`))[0]))return"";var r,s,o,a,n,i,c,l,f,u,p,d,g=20,m="S[123][0-9a-f]{2}[0-5][0-9a-f]",b="[0-9]{3}x[0-9]{3}",y="[BLMR]("+b+")("+m+b+")*",h="(A("+m+")+)",x="R[123][0-9a-f]{2}t[123][0-9a-f]{2}",$="S[123][0-9a-f]{2}[0-5u][0-9a-fu]",w="("+t.full+")?";if("Q"==e)return[h+"?"+y];if("Q-"==e)return[h+"?"+y+w];if("QT"==e)return[h+y];if("QT-"==e)return[h+y+w];var v=[],A=e.indexOf("T")+1;if(A){d="(A";var k=e.slice(0,A);if(e=e.replace(k,""),"QT"==k)d+="("+m+")+)";else if(r=k.match(new RegExp("("+$+"|"+x+")","g"))){var S;for(s=0;s<r.length;s+=1)(S=r[s].match(new RegExp($)))?(c=S[0].slice(0,4),c+="u"==(u=S[0].slice(4,5))?"[0-5]":u,d+=c+="u"==(p=S[0].slice(5,6))?"[0-9a-f]":p):(n=r[s].slice(1,4),i=r[s].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)),o=$+"([0-9]{3}x[0-9]{3})?",r=e.match(new RegExp(o,"g")))for(s=0;s<r.length;s+=1)c="S"+(a=r[s].toString()).slice(1,4),c+="u"==(u=a.slice(4,5))?"[0-5]":u,c+="u"==(p=a.slice(5,6))?"[0-9a-f]":p,a.length>6?(l=1*a.slice(6,9),f=1*a.slice(10,13),c+=R(l-g,l+g),c+="x",c+=R(f-g,f+g)):c+=b,c=y+c+"("+m+b+")*",c=A?d+c:h+"?"+c,e.indexOf("-")>0&&(c+=w),v.push(c);if(o=x+"([0-9]{3}x[0-9]{3})?",r=e.match(new RegExp(o,"g")))for(s=0;s<r.length;s+=1)n=(a=r[s].toString()).slice(1,4),i=a.slice(5,8),c="S"+R(n,i,"hex")+"[0-5][0-9a-f]",a.length>8?(l=1*a.slice(8,11),f=1*a.slice(12,15),c+=R(l-g,l+g),c+="x",c+=R(f-g,f+g)):c+=b,c=y+c+"("+m+b+")*",c=A?d+c:h+"?"+c,e.indexOf("-")>0&&(c+=w),v.push(c);return v.length||(e.indexOf("-")>0&&(c+=w),v.push(d+y)),v};var E=Object.freeze({__proto__:null,re:I,parse:e=>{const r="string"==typeof e?e.match(new RegExp(`^${I.full}`)):void 0;return{query:!!r||void 0,prefix:r&&r[1]?A(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(`^${I.full}`))[0]},fsw2query:(e,r)=>{let t="";const s=y.sign(e);if(s.box){const e=r.indexOf("A")>-1,o=r.indexOf("a")>-1,a=r.indexOf("S")>-1,n=r.indexOf("s")>-1,i=r.indexOf("L")>-1;return(e||o||a||n)&&((e||o)&&s.sequence&&(t+="A",t+=s.sequence.map(e=>e.slice(0,4)+(o?"uu":e.slice(4,6))).join(""),t+="T"),(a||n)&&s.spatials&&(t+=s.spatials.map(e=>e.symbol.slice(0,4)+(n?"uu":e.symbol.slice(4,6))+(i?e.coord.join("x"):"")).join(""))),t?"Q"+t:void 0}},range:R,regex:S,results:(e,r)=>{if(!r)return[];let t,s,o,a,n,i=S(e);if(!i)return[];for(n=0;n<i.length;n+=1)t=i[n],s=r.match(new RegExp(t,"g")),r=s?s.join(" "):"";return a=r?(o=r.split(" ")).filter((function(e){return!(e in o)&&(o[e]=!0)}),{}):[]},lines:(e,r)=>{if(!r)return[];let t,s,o,a,n,i=S(e);if(!i)return[];for(n=0;n<i.length;n+=1)t="^"+(t=i[n])+".*",s=r.match(new RegExp(t,"mg")),r=s?s.join("\n"):"";return a=r?(o=r.split("\n")).filter((function(e){return!(e in o)&&(o[e]=!0)}),{}):[]}});const _={symbol:e=>{const r=`^(${a.symbol})(${a.coord})?(${t.full})?`,s="string"==typeof e?e.match(new RegExp(r)):void 0;return{symbol:s?s[1]:void 0,coord:s&&s[2]?l(s[2]):void 0,style:s?s[3]:void 0}},sign:e=>{const r=`^(${a.prefix})?(${a.signbox})(${t.full})?`,s="string"==typeof e?e.match(new RegExp(r)):void 0;return s?{sequence:s[1]?s[1].slice(2).match(/.{2}/g):void 0,box:s[2].slice(0,2),max:l(s[2].slice(2,6)),spatials:s[2].length<7?void 0:s[2].slice(6).match(/(.{6})/g).map(e=>({symbol:e.slice(0,2),coord:l(e.slice(2))})),style:s[3]}:{}}},j=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()],z={symbol:e=>{if("object"==typeof e&&null!==e&&"string"==typeof e.symbol){const r=(e.symbol.match(a.symbol)||[""])[0];if(r){const s=e.coord&&e.coord[0]||"",o=e.coord&&e.coord[1]||"";return r+(s&&o?f([s,o]):"")+("string"==typeof e.style&&(e.style.match(t.full)||[""])[0]||"")}}},sign:e=>{if("object"!=typeof e||null===e)return;let r="string"!=typeof e.box?"𝠃":(e.box+"𝠃").match(a.box);const s=e.max&&e.max[0]||"",o=e.max&&e.max[1]||"",n=s&&o?f([s,o]):void 0;if(!n)return;let i="";e.sequence&&Array.isArray(e.sequence)&&(i=(i=e.sequence.map(e=>(e.match(a.symbol)||[""])[0]).join(""))?"𝠀"+i:"");let c="";return e.spatials&&Array.isArray(e.spatials)&&(c=e.spatials.map(e=>{if("string"==typeof e.symbol){const r=(e.symbol.match(a.symbol)||[""])[0];if(r){const t=e.coord&&e.coord[0]||"",s=e.coord&&e.coord[1]||"",o=t&&s?f([t,s]):"";if(o)return r+o}}return""}).join("")),i+r+n+c+("string"==typeof e.style&&(e.style.match(t.full)||[""])[0]||"")}},C=[262145,287201,310433,311201,321761,323489,324257],O={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]},q=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];var T=Object.freeze({__proto__:null,re:a,parse:_,encode:e=>e.replace(/[\u007F-\uFFFF]/g,(function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4).toUpperCase()})),decode:j,pair:F,compose:z,kind:[262145,323489,324257],category:C,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:O,isType:(e,r)=>{const t=_.symbol(e);if(t.symbol){const e=p(t.symbol),s=O[r];if(s)return s[0]<=e&&s[1]>=e}return!1},colors:q,colorize:e=>{const r=_.symbol(e);let t="#000000";if(r.symbol){const e=p(r.symbol),s=C.findIndex(r=>r>e);t=q[s<0?6:s-1]}return t}});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 D=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)])}),Z=e=>e.match(new RegExp(`(${Q.symbol}${Q.coord}|${Q.range}${Q.coord})`,"g")).map(e=>{let r,t;return e.length>5?(r=l(e.slice(-4)),t=e.slice(0,-4)):t=e,t.includes("R")?{range:[t.slice(1,3),t.slice(3,5)],coord:r}:{symbol:t,coord:r}}),M=(e,r)=>{if(e>r)return"";let t,s="",o=[];if(e=F(e),r=F(r),2!=e.length&&2!=r.length)return"";if(e[0]==r[0])e[1]==r[1]?(s="\\u"+e[0]+"\\u"+e[1],o.push(s)):(s="\\u"+e[0]+"[\\u"+e[1]+"-\\u"+r[1]+"]",o.push(s));else{s="DFFF"==e[1]?"\\u"+e[0]+"\\uDFFF":"\\u"+e[0]+"[\\u"+e[1]+"-\\uDFFF]",o.push(s);let t=parseInt(r[0],16)-parseInt(e[0],16);2==t&&(s="\\u"+(parseInt(e[0],16)+1).toString(16).toUpperCase(),s+="[\\uDC00-\\uDFFF]",o.push(s)),t>2&&(s="[",s+="\\u"+(parseInt(e[0],16)+1).toString(16).toUpperCase(),s+="-\\u"+(parseInt(r[0],16)-1).toString(16).toUpperCase(),s+="][\\uDC00-\\uDFFF]",o.push(s)),s="DC00"==r[1]?"\\u"+r[0]+"\\uDC00":"\\u"+r[0]+"[\\uDC00-\\u"+r[1]+"]",o.push(s)}return s=1==(t=o.length)?o[0]:"(("+(s=o.join(")|("))+"))",j(s)},L=e=>{let r=e.match(new RegExp(Q.symbol));if(r){let e,t,s=r[0].slice(0,2),o=g(s),a=o.slice(0,4);if("fr"==r[0].slice(-2))return e=m(a+"00"),t=m(a+"5f"),M(e,t);if("r"==r[0].slice(-1))return e=m(o.slice(0,5)+"0"),t=m(o.slice(0,5)+"f"),M(e,t);if("f"==r[0].slice(-1)){return"("+[0,1,2,3,4,5].map((function(e){return m(a+e+o.slice(-1))})).join("|")+")"}return s}return""},P=e=>{if(!(e=e.match(new RegExp(`^${Q.full}`))[0]))return"";let r,s,o,n,i,c,u,p,d,b,y=20,h=a.symbol,x=a.coord,$=a.box+x+"("+h+x+")*",w="("+a.sort+"("+h+")+)",v="R"+h+h,I=h+"f?r?",A="("+x+")?",k="("+t.full+")?";if("Q"==e)return[a.sign];if("Q-"==e)return[a.sign+"("+t.full+")?"];if("QT"==e)return[a.sortable];if("QT-"==e)return[a.sortable+"("+t.full+")?"];let R,S=[],E=e.indexOf("T")+1;if(E){b="("+a.sort;let t=e.slice(0,E);if(e=e.replace(t,""),"QT"==t)b+="("+h+")+)";else if(r=t.match(new RegExp("("+I+"|"+v+")","g"))){let e;for(s=0;s<r.length;s+=1)(e=r[s].match(new RegExp("^"+I)))?b+=L(e[0]):(n=g(r[s].slice(1,3)),i=g(r[s].slice(-2)),n=m(n.slice(0,4)+"00"),i=m(i.slice(0,4)+"5f"),b+=M(n,i));b+="("+h+")*)"}}if((r=e.match(new RegExp("(V[0-9]+)","g")))&&(y=1*r.toString().slice(1)),r=e.match(new RegExp("("+v+A+"|"+I+A+")","g")))for(s=0;s<r.length;s+=1)"R"!=(o=r[s].toString())[0]?(R=o.match(new RegExp(I))[0],u=L(R),R.length>o.length?(p=(c=l(o.slice(-4)))[0],d=c[1],u+=M(f([p-y,p+y])),u+=M(f([d-y,d+y]))):u+=x,u=$+u+"("+h+x+")*",u=E?b+u:w+"?"+u,e.indexOf("-")>0&&(u+=k),S.push(u)):(o=r[s].toString(),n=g(o.slice(1,3)),i=g(o.slice(3,5)),n=m(n.slice(0,4)+"00"),i=m(i.slice(0,4)+"5f"),u=M(n,i),o.length>5?(p=(c=l(o.slice(5,9)))[0],d=c[1],u+=M(f([p-y,p+y])),u+=M(f([d-y,d+y]))):u+=x,u=$+u+"("+h+x+")*",u=E?b+u:w+"?"+u,e.indexOf("-")>0&&(u+=k),S.push(u));return S.length||(e.indexOf("-")>0&&(u+=k),S.push(b+$)),S};var U=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]?D(r[1]):void 0,signbox:r&&r[2]?Z(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?f(e.coord):"")}).join("")),r=(r+=e.style?"-":"").match(new RegExp(`^${Q.full}`))[0]},swu2query:(e,r)=>{let t="";const s=_.sign(e);if(s.box){const e=r.indexOf("A")>-1,o=r.indexOf("a")>-1,a=r.indexOf("S")>-1,n=r.indexOf("s")>-1,i=r.indexOf("L")>-1;return(e||o||a||n)&&((e||o)&&s.sequence&&(t+="A",t+=s.sequence.map(e=>e+(o?"fr":"")).join(""),t+="T"),(a||n)&&s.spatials&&(t+=s.spatials.map(e=>e.symbol+(n?"fr":"")+(i?f(e.coord):"")).join(""))),t?"Q"+t:void 0}},range:M,symbolRanges:L,regex:P,results:(e,r)=>{if(!r)return[];let t,s,o,a,n,i=P(e);if(!i)return[];for(n=0;n<i.length;n+=1)t=i[n],s=r.match(new RegExp(t,"g")),r=s?s.join(" "):"";return a=r?(o=r.split(" ")).filter((function(e){return!(e in o)&&(o[e]=!0)}),{}):[]},lines:(e,r)=>{if(!r)return[];let t,s,o,a,n,i=P(e);if(!i)return[];for(n=0;n<i.length;n+=1)t="^"+(t=i[n])+".*",s=r.match(new RegExp(t,"mg")),r=s?s.join("\n"):"";return a=r?(o=r.split("\n")).filter((function(e){return!(e in o)&&(o[e]=!0)}),{}):[]}});e.convert=b,e.fsw=v,e.fswquery=E,e.style=o,e.swu=T,e.swuquery=U,Object.defineProperty(e,"__esModule",{value:!0})}));