UNPKG

24.7 kBJavaScriptView Raw
1/* Sutton SignWriting Core Module v1.3.1 (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="undefined"!=typeof globalThis?globalThis: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=>(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 i=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;i&&(r+="D_"+i,n&&(r+=","+n),r+="_");const a="x"===e.zoom?"x":parseFloat(e.zoom);r+=!a||a<=0?"":"Z"+a;let c="";const l=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,i=e.detail&&e.detail[1]?e.detail[1].match(t.colorbase)[0]:void 0;return o&&(s+="_"+o,i&&(s+=","+i),s+="_"),s})):[];c+=l.join("");const p=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})):[];c+=p.join("");let f="";const u=e.classes&&"string"==typeof e.classes?e.classes.match(t.classes)[0]:void 0;f+=u||"";const d=e.id&&"string"==typeof e.id?e.id.match(t.id)[0]:void 0;return f+=u||d?"!":"",f+=d?d+"!":"",r+(c||f?"-"+c:"")+(f?"-"+f:"")}});let i={symbol:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:\ud836[\udc0c-\uddff]){2}",sort:"𝠀",box:"\ud836[\udc01-\udc04]"};i.prefix=`(?:${i.sort}(?:${i.symbol})+)`,i.spatial=`${i.symbol}${i.coord}`,i.signbox=`${i.box}${i.coord}(?:${i.spatial})*`,i.sign=`${i.prefix}?${i.signbox}`,i.sortable=`${i.prefix}${i.signbox}`;const n=e=>({A:"𝠀",B:"𝠁",L:"𝠂",M:"𝠃",R:"𝠄"}[e]),a=e=>parseInt(e.codePointAt(0))-120844+250,c=e=>String.fromCodePoint(120844+parseInt(e)-250),l=e=>[a(e.slice(0,2)),a(e.slice(2,4))],p=e=>e.map((e=>c(e))).join(""),f=e=>e.split("x").map((e=>parseInt(e))),u=e=>parseInt(e.codePointAt(0)),d=e=>String.fromCodePoint(e),g=e=>{const r=u(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:a,num2swu:c,swu2coord:l,coord2swu:p,fsw2coord:f,coord2fsw:e=>e.join("x"),swu2code:u,code2swu:d,swu2id:e=>u(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(i.symbol,"g"));t&&t.forEach((function(e){r=r.replace(e,g(e))}));const s=r.match(new RegExp(i.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))+p(f(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))+p(f(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]?f(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:f(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 i="";e.sequence&&Array.isArray(e.sequence)&&(i=e.sequence.map((e=>(e.match(r.symbol)||[""])[0])).join(""),i=i?"A"+i:"");let n="";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(""));return i+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 A={base:"[123][0-9a-f]{2}",coord:"(?:[0-9]{3}x[0-9]{3})?",var:"V[0-9]+"};A.symbol=`S${A.base}[0-5u][0-9a-fu]`,A.range=`R${A.base}t${A.base}`,A.item=`(?:${A.symbol}|${A.range})`,A.list=`${A.item}(?:o${A.item})*`,A.prefix=`(?:A(?:${A.list})+)?T`,A.signbox=`(?:${A.list}${A.coord})*`,A.full=`Q(${A.prefix})?(${A.signbox})?(${A.var})?(-?)`;const I=e=>e.match(new RegExp(`(${A.list}${A.coord})`,"g")).map((e=>{let r,t;return e.includes("x")?(r=f(e.slice(-7)),t=e.slice(0,-7)):t=e,t.includes("o")?{or:t.split("o").map((e=>e.includes("S")?e:e.slice(1).split("t"))),coord:r,coord:r}:t.includes("S")?{symbol:t,coord:r}:{range:t.slice(1).split("t"),coord:r}})),R=(e,r,t)=>{let s,o,i,n,a,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]"}}i=15-parseInt(e[2],16)+1,e=""+(parseInt(e,16)+i).toString(16),o.push(s)}else{switch(e[2]){case"9":s+="9";break;case"8":s+="[89]";break;default:s+="["+e[2]+"-9]"}i=9-e[2]+1,e=""+(1*e+i),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]",i=15-parseInt(e[1],16)+1,e=""+(parseInt(e,16)+16*i).toString(16),o.push(s)}else{switch(s=e[0],i=9-e[1]+1,e[1]){case"9":s+="9";break;case"8":s+="[89]";break;default:s+="["+e[1]+"-9]"}s+="[0-9]",i=9-e[1]+1,e=""+(1*e+10*i),o.push(s)}if(s="",e[0]!=r[0])if(t){switch(i=parseInt(r[0],16)-parseInt(e[0],16),n=(parseInt(e[0],16)+i-1).toString(16),i){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",c+l){case"dd":case"hh":s+="["+e[0]+"-"+n+"]";break;case"dh":switch(i=9-e[0],i){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+"]"}}}s+="[0-9a-f][0-9a-f]",i=parseInt(r[0],16)-parseInt(e[0],16),e=""+(parseInt(e,16)+256*i).toString(16),o.push(s)}else{switch(i=r[0]-e[0],n=1*e[0]+i-1,i){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*i),o.push(s)}if(s="",e[1]!=r[1])if(t){switch(i=parseInt(r[1],16)-parseInt(e[1],16),n=(parseInt(e[1],16)+i-1).toString(16),s=e[0],i){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",c+l){case"dd":s+="["+e[1],i>1&&(s+="-"),s+=n+"]";break;case"dh":switch(i=9-e[1],i){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],i>1&&(s+="-"),s+=(parseInt(r[1],16)-1).toString(16)+"]"}}s+="[0-9a-f]",i=parseInt(r[1],16)-parseInt(e[1],16),e=""+(parseInt(e,16)+16*i).toString(16),o.push(s)}else{switch(i=r[1]-e[1],n=1*e[1]+i-1,s=e[0],i){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*i),o.push(s)}if(s="",e[2]!=r[2])if(t){switch(s=e[0]+e[1],i=parseInt(r[2],16)-parseInt(e[2],16),c=parseInt(e[2],16)>9?"h":"d",l=parseInt(r[2],16)>9?"h":"d",c+l){case"dd":case"hh":s+="["+e[2],i>1&&(s+="-"),s+=r[2]+"]";break;case"dh":switch(i=9-e[2],i){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]+"]"}}i=parseInt(r[2],16)-parseInt(e[2],16),e=""+(parseInt(e,16)+i).toString(16),o.push(s)}else{switch(i=r[2]-e[2],s=e[0]+e[1],i){case 0:s+=e[2];break;case 1:s+="["+e[2]+r[2]+"]";break;default:s+="["+e[2]+"-"+r[2]+"]"}e=""+(1*e+i),o.push(s)}return s="","0"==e[2]&&"0"==r[2]&&(s=r,o.push(s)),s="",a=o.length,1==a?s=o[0]:(s=o.join(")|("),s="(("+s+"))"),s},k=e=>{let r=e.slice(0,4),t=e.slice(4,5);r+="u"==t?"[0-5]":t;let s=e.slice(5,6);return r+="u"==s?"[0-9a-f]":s,r},E=e=>{let r=e.slice(1,4),t=e.slice(5,8);return"S"+R(r,t,"hex")+"[0-5][0-9a-f]"},j=e=>{if(!(e=e.match(new RegExp(`^${A.full}`))[0]))return"";var s,o,i,n,a,c,l,p,u,d,g,m=20,b="("+t.full+")?";if("Q"==e)return[r.prefix+"?"+r.signbox];if("Q-"==e)return[r.prefix+"?"+r.signbox+b];if("QT"==e)return[r.prefix+r.signbox];if("QT-"==e)return[r.prefix+r.signbox+b];var y=[],h=e.indexOf("T")+1;if(h){g="(A";var x=e.slice(0,h);if(e=e.replace(x,""),"QT"==x)g+="("+r.symbol+")+)";else if(s=x.match(new RegExp("("+A.list+")","g"))){for(a=0;a<s.length;a+=1)if(n=[],o=s[a].match(new RegExp("("+A.symbol+"|"+A.range+")","g"))){for(c=0;c<o.length;c+=1)(i=o[c].match(new RegExp(A.symbol)))?n.push(k(i[0])):n.push(E(o[c]));1==n.length?g+=n[0]:g+="("+n.join("|")+")"}g+="("+r.symbol+")*)"}}if((s=e.match(new RegExp(A.var,"g")))&&(m=1*s.toString().slice(1)),s=e.match(new RegExp(A.list+A.coord,"g")))for(a=0;a<s.length;a+=1){if(n=[],o=s[a].match(new RegExp("("+A.symbol+"|"+A.range+")","g"))){for(c=0;c<o.length;c+=1)(i=o[c].match(new RegExp(A.symbol)))?n.push(k(i[0])):n.push(E(o[c]));l=1==n.length?n[0]:"("+n.join("|")+")"}s[a].includes("x")?(u=(p=f(s[a].slice(-7)))[0],d=p[1],l+=R(u-m,u+m),l+="x",l+=R(d-m,d+m)):l+=r.coord,l=r.signbox+l+"("+r.symbol+r.coord+")*",l=h?g+l:r.prefix+"?"+l,e.indexOf("-")>0&&(l+=b),y.push(l)}return y.length||(e.indexOf("-")>0&&(l+=b),y.push(g+r.signbox)),y};var S=Object.freeze({__proto__:null,re:A,parse:e=>{const r="string"==typeof e?e.match(new RegExp(`^${A.full}`)):void 0;return{query:!!r||void 0,prefix:r&&r[1]?(t=r[1],{required:!0,parts:"T"==t?void 0:t.match(new RegExp(`${A.list}`,"g")).map((e=>e.includes("o")?["or"].concat(e.match(new RegExp(`(${A.item})`,"g")).map((e=>"S"==e[0]?e:e.slice(1).split("t")))):"S"==e[0]?e:e.slice(1).split("t")))}):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};var t},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]}`:Array.isArray(e)&&e.length>2&&"or"==e[0]?(e.shift(),e.map((e=>"string"==typeof e?e:Array.isArray(e)&&2==e.length?`R${e[0]}t${e[1]}`:void 0)).join("o")):void 0)).join("")),r+="T"),Array.isArray(e.signbox)&&(r+=e.signbox.map((e=>{let r;return e.or?r=e.or.map((e=>"string"==typeof e?e:Array.isArray(e)&&2==e.length?`R${e[0]}t${e[1]}`:void 0)).join("o"):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+=e.style?"-":"",r=r.match(new RegExp(`^${A.full}`))[0],r},fsw2query:(e,r)=>{let t="";const s=y.sign(e);if(s.box){const e=r.indexOf("A")>-1,o=r.indexOf("a")>-1,i=r.indexOf("S")>-1,n=r.indexOf("s")>-1,a=r.indexOf("L")>-1;return(e||o||i||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"),(i||n)&&s.spatials&&(t+=s.spatials.map((e=>e.symbol.slice(0,4)+(n?"uu":e.symbol.slice(4,6))+(a?e.coord.join("x"):""))).join(""))),t?"Q"+t:void 0}},range:R,regex:j,results:(e,r)=>{if(!r)return[];let t,s,o,i,n,a=j(e);if(!a)return[];for(n=0;n<a.length;n+=1)t=a[n],s=r.match(new RegExp(t,"g")),r=s?s.join(" "):"";return r?(o=r.split(" "),i=o.filter((function(e){return!(e in o)&&(o[e]=!0)}),{})):i=[],i},lines:(e,r)=>{if(!r)return[];let t,s,o,i,n,a=j(e);if(!a)return[];for(n=0;n<a.length;n+=1)t=a[n],t="^"+t+".*",s=r.match(new RegExp(t,"mg")),r=s?s.join("\n"):"";return r?(o=r.split("\n"),i=o.filter((function(e){return!(e in o)&&(o[e]=!0)}),{})):i=[],i}});const _={symbol:e=>{const r=`^(${i.symbol})(${i.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=`^(${i.prefix})?(${i.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]}:{}}},F=e=>e.replace(/\\u([0-9A-F]{4})/g,(function(e,r){return String.fromCharCode(parseInt(r,16))})),z=e=>[e.charCodeAt(0).toString(16).toUpperCase(),e.charCodeAt(1).toString(16).toUpperCase()],C={symbol:e=>{if("object"==typeof e&&null!==e&&"string"==typeof e.symbol){const r=(e.symbol.match(i.symbol)||[""])[0];if(r){const s=e.coord&&e.coord[0]||"",o=e.coord&&e.coord[1]||"";return r+(s&&o?p([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(i.box);const s=e.max&&e.max[0]||"",o=e.max&&e.max[1]||"",n=s&&o?p([s,o]):void 0;if(!n)return;let a="";e.sequence&&Array.isArray(e.sequence)&&(a=e.sequence.map((e=>(e.match(i.symbol)||[""])[0])).join(""),a=a?"𝠀"+a:"");let c="";e.spatials&&Array.isArray(e.spatials)&&(c=e.spatials.map((e=>{if("string"==typeof e.symbol){const r=(e.symbol.match(i.symbol)||[""])[0];if(r){const t=e.coord&&e.coord[0]||"",s=e.coord&&e.coord[1]||"",o=t&&s?p([t,s]):"";if(o)return r+o}}return""})).join(""));return a+r+n+c+("string"==typeof e.style&&(e.style.match(t.full)||[""])[0]||"")}},q=[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]},T=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];var Q=Object.freeze({__proto__:null,re:i,parse:_,encode:e=>e.replace(/[\u007F-\uFFFF]/g,(function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4).toUpperCase()})),decode:F,pair:z,compose:C,kind:[262145,323489,324257],category:q,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=u(t.symbol),s=O[r];if(s)return s[0]<=e&&s[1]>=e}return!1},colors:T,colorize:e=>{const r=_.symbol(e);let t="#000000";if(r.symbol){const e=u(r.symbol),s=q.findIndex((r=>r>e));t=T[s<0?6:s-1]}return t}});let D={base:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:(?:\ud836[\udc0c-\uddff]){2})?",var:"V[0-9]+"};D.symbol=`${D.base}f?r?`,D.range=`R${D.base}${D.base}`,D.item=`(?:${D.symbol}|${D.range})`,D.list=`${D.item}(?:o${D.item})*`,D.prefix=`(?:A(?:${D.list})+)?T`,D.signbox=`(?:${D.list}${D.coord})*`,D.full=`Q(${D.prefix})?(${D.signbox})?(${D.var})?(-?)`;const Z=e=>e.match(new RegExp(`(${D.list}${D.coord})`,"g")).map((e=>{let r,t;return r=e.match(new RegExp(`${i.coord}`)),r?(r=l(r[0]),t=e.slice(0,-4)):(r=void 0,t=e),t.includes("o")?{or:t.split("o").map((e=>e.includes("R")?[e.slice(1,3),e.slice(3,5)]:e)),coord:r,coord:r}: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=z(e),r=z(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 t=o.length,1==t?s=o[0]:(s=o.join(")|("),s="(("+s+"))"),F(s)},P=e=>{let r=e.match(new RegExp(D.symbol));if(r){let e,t,s=r[0].slice(0,2),o=g(s),i=o.slice(0,4);if("fr"==r[0].slice(-2))return e=m(i+"00"),t=m(i+"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(i+e+o.slice(-1))})).join("|")+")"}return s}return""},L=e=>(from=g(e.slice(1,3)),to=g(e.slice(-2)),from=m(from.slice(0,4)+"00"),to=m(to.slice(0,4)+"5f"),M(from,to)),U=e=>{if(!(e=e.match(new RegExp(`^${D.full}`))[0]))return"";let r,s,o,n,a,p,f,u,d,g,m,b=20,y=i.symbol,h=i.coord,x=i.box+h+"("+y+h+")*",$="("+i.sort+"("+y+")+)",w="("+t.full+")?";if("Q"==e)return[i.sign];if("Q-"==e)return[i.sign+"("+t.full+")?"];if("QT"==e)return[i.sortable];if("QT-"==e)return[i.sortable+"("+t.full+")?"];let v=[],A=e.indexOf("T")+1;if(A){m="("+i.sort;let t=e.slice(0,A);if(e=e.replace(t,""),"QT"==t)m+="("+y+")+)";else if(r=t.match(new RegExp("("+D.list+")","g")),r){for(a=0;a<r.length;a+=1)if(n=[],s=r[a].match(new RegExp("("+D.symbol+"|"+D.range+")","g")),s){for(p=0;p<s.length;p+=1)o=s[p].match(new RegExp(D.symbol)),o?n.push(P(o[0])):n.push(L(s[p]));1==n.length?m+=n[0]:m+="("+n.join("|")+")"}m+="("+i.symbol+")*)"}}if(r=e.match(new RegExp("(V[0-9]+)","g")),r&&(b=1*r.toString().slice(1)),r=e.match(new RegExp(D.list+D.coord,"g")),r)for(a=0;a<r.length;a+=1){if(n=[],s=r[a].match(new RegExp("("+D.symbol+"|"+D.range+")","g")),s){for(p=0;p<s.length;p+=1)o=s[p].match(new RegExp(D.symbol)),o?n.push(P(o[0])):n.push(L(s[p]));u=1==n.length?n[0]:"("+n.join("|")+")"}f=r[a].match(new RegExp(`${i.coord}`)),f?(f=l(f[0]),d=f[0],g=f[1],u+=M(c(d-b),c(d+b)),u+=M(c(g-b),c(g+b))):u+=i.coord,u=x+u+"("+y+h+")*",u=A?m+u:$+"?"+u,e.indexOf("-")>0&&(u+=w),v.push(u)}return v.length||(e.indexOf("-")>0&&(u+=w),v.push(m+x)),v};var B=Object.freeze({__proto__:null,re:D,parse:e=>{const r="string"==typeof e?e.match(new RegExp(`^${D.full}`)):void 0;return{query:!!r||void 0,prefix:r&&r[1]?(t=r[1],{required:!0,parts:"T"==t?void 0:t.match(new RegExp(`(${D.list})`,"g")).map((e=>e.includes("o")?["or"].concat(e.match(new RegExp(`(${D.item})`,"g")).map((e=>"R"!=e[0]?e:[e.slice(1,3),e.slice(3,5)]))):"R"!=e[0]?e:[e.slice(1,3),e.slice(3,5)]))}):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};var t},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]}`:Array.isArray(e)&&e.length>2&&"or"==e[0]?(e.shift(),e.map((e=>"string"==typeof e?e:Array.isArray(e)&&2==e.length?`R${e[0]}${e[1]}`:void 0)).join("o")):void 0)).join("")),r+="T"),Array.isArray(e.signbox)&&(r+=e.signbox.map((e=>{let r;return e.or?r=e.or.map((e=>"string"==typeof e?e:Array.isArray(e)&&2==e.length?`R${e[0]}${e[1]}`:void 0)).join("o"):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?p(e.coord):"")})).join("")),r+=e.style?"-":"",r=r.match(new RegExp(`^${D.full}`))[0],r},swu2query:(e,r)=>{let t="";const s=_.sign(e);if(s.box){const e=r.indexOf("A")>-1,o=r.indexOf("a")>-1,i=r.indexOf("S")>-1,n=r.indexOf("s")>-1,a=r.indexOf("L")>-1;return(e||o||i||n)&&((e||o)&&s.sequence&&(t+="A",t+=s.sequence.map((e=>e+(o?"fr":""))).join(""),t+="T"),(i||n)&&s.spatials&&(t+=s.spatials.map((e=>e.symbol+(n?"fr":"")+(a?p(e.coord):""))).join(""))),t?"Q"+t:void 0}},range:M,symbolRanges:P,regex:U,results:(e,r)=>{if(!r)return[];let t,s,o,i,n,a=U(e);if(!a)return[];for(n=0;n<a.length;n+=1)t=a[n],s=r.match(new RegExp(t,"g")),r=s?s.join(" "):"";return r?(o=r.split(" "),i=o.filter((function(e){return!(e in o)&&(o[e]=!0)}),{})):i=[],i},lines:(e,r)=>{if(!r)return[];let t,s,o,i,n,a=U(e);if(!a)return[];for(n=0;n<a.length;n+=1)t=a[n],t="^"+t+".*",s=r.match(new RegExp(t,"mg")),r=s?s.join("\n"):"";return r?(o=r.split("\n"),i=o.filter((function(e){return!(e in o)&&(o[e]=!0)}),{})):i=[],i}});e.convert=b,e.fsw=v,e.fswquery=S,e.style=o,e.swu=Q,e.swuquery=B,Object.defineProperty(e,"__esModule",{value:!0})}));