UNPKG

28.1 kBJavaScriptView Raw
1/* Sutton SignWriting Core Module v1.4.2 (https://github.com/sutton-signwriting/core), author: Steve Slevinski (https://SteveSlevinski.me), license: MIT */
2!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).ssw=e.ssw||{},e.ssw.core={}))}(this,(function(e){"use strict";let t={symbol:"S[123][0-9a-f]{2}[0-5][0-9a-f]",coord:"[0-9]{3}x[0-9]{3}",sort:"A",box:"[BLMR]"};t.prefix=`(?:${t.sort}(?:${t.symbol})+)`,t.spatial=`${t.symbol}${t.coord}`,t.signbox=`${t.box}${t.coord}(?:${t.spatial})*`,t.sign=`${t.prefix}?${t.signbox}`,t.sortable=`${t.prefix}${t.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)",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.classes})?!(?:(${r.id})!)?)?`;const s=e=>(new RegExp(`^${r.colorhex}$`).test(e)?"#":"")+e,o=e=>{const t=`^${r.full}`,o=("string"==typeof e?e.match(new RegExp(t)):[])||[];return n={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(r.detailsym,"g")).map((e=>{const t=e.split("_"),r=t[1].split(",").map(s);return{index:parseInt(t[0].slice(1)),detail:r}})):void 0,classes:o[7]?o[7]:void 0,id:o[8]?o[8]:void 0},Object.fromEntries(Object.entries(n).filter((([e,t])=>void 0!==t)));var n};var n=Object.freeze({__proto__:null,re:r,parse:o,compose:e=>{if("object"!=typeof e||null===e)return;let t="-";t+=e.colorize?"C":"";const s=parseInt(e.padding);t+=!s||s<=0||s>99?"":"P"+(s>9?s:"0"+s);const o=e.background&&"string"==typeof e.background?e.background.match(r.colorbase)[0]:void 0;t+=o?"G_"+o+"_":"";const n=e.detail&&e.detail[0]&&"string"==typeof e.detail[0]?e.detail[0].match(r.colorbase)[0]:void 0,i=e.detail&&e.detail[1]&&"string"==typeof e.detail[1]?e.detail[1].match(r.colorbase)[0]:void 0;n&&(t+="D_"+n,i&&(t+=","+i),t+="_");const a="x"===e.zoom?"x":parseFloat(e.zoom);t+=!a||a<=0?"":"Z"+a;let l="";const c=e.detailsym&&Array.isArray(e.detailsym)?e.detailsym.map((e=>{const t=parseInt(e.index);if(!t||t<=0||t>99)return"";let s="D"+(t>9?t:"0"+t);const o=e.detail&&e.detail[0]?e.detail[0].match(r.colorbase)[0]:void 0,n=e.detail&&e.detail[1]?e.detail[1].match(r.colorbase)[0]:void 0;return o&&(s+="_"+o,n&&(s+=","+n),s+="_"),s})):[];l+=c.join("");let p="";const u=e.classes&&"string"==typeof e.classes?e.classes.match(r.classes)[0]:void 0;p+=u||"";const f=e.id&&"string"==typeof e.id?e.id.match(r.id)[0]:void 0;return p+=u||f?"!":"",p+=f?f+"!":"",t+(l||p?"-"+l:"")+(p?"-"+p:"")}});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 a=e=>({A:"𝠀",B:"𝠁",L:"𝠂",M:"𝠃",R:"𝠄"}[e]),l=e=>parseInt(e.codePointAt(0))-120844+250,c=e=>String.fromCodePoint(120844+parseInt(e)-250),p=e=>[l(e.slice(0,2)),l(e.slice(2,4))],u=e=>e.map((e=>c(e))).join(""),f=e=>e.split("x").map((e=>parseInt(e))),d=e=>parseInt(e.codePointAt(0)),g=e=>String.fromCodePoint(e),m=e=>{const t=d(e)-262145,r=parseInt(t/96),s=parseInt((t-96*r)/16),o=parseInt(t-96*r-16*s);return"S"+(r+256).toString(16)+s.toString(16)+o.toString(16)},h=e=>g(262145+96*(parseInt(e.slice(1,4),16)-256)+16*parseInt(e.slice(4,5),16)+parseInt(e.slice(5,6),16));var y=Object.freeze({__proto__:null,swu2mark:e=>({"𝠀":"A","𝠁":"B","𝠂":"L","𝠃":"M","𝠄":"R"}[e]),mark2swu:a,swu2num:l,num2swu:c,swu2coord:p,coord2swu:u,fsw2coord:f,coord2fsw:e=>e.join("x"),swu2code:d,code2swu:g,swu2id:e=>d(e)-262144,id2swu:e=>g(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 t=e-1,r=parseInt(t/96),s=parseInt((t-96*r)/16),o=parseInt(t-96*r-16*s);return"S"+(r+256).toString(16)+s.toString(16)+o.toString(16)},swu2key:m,key2swu:h,swu2fsw:e=>{if(!e)return"";let t=e.replace(/𝠀/g,"A").replace(/𝠁/g,"B").replace(/𝠂/g,"L").replace(/𝠃/g,"M").replace(/𝠄/g,"R");const r=t.match(new RegExp(i.symbol,"g"));r&&r.forEach((function(e){t=t.replace(e,m(e))}));const s=t.match(new RegExp(i.coord,"g"));return s&&s.forEach((function(e){t=t.replace(e,p(e).join("x"))})),t},fsw2swu:e=>{if(!e)return"";const r=e.match(new RegExp(t.prefix,"g"));r&&r.forEach((function(t){e=e.replace(t,"𝠀"+t.slice(1).match(/.{6}/g).map((e=>h(e))).join(""))}));const s=e.match(new RegExp(t.box+t.coord,"g"));s&&s.forEach((function(t){e=e.replace(t,a(t.slice(0,1))+u(f(t.slice(1,8))))}));const o=e.match(new RegExp(t.spatial,"g"));return o&&o.forEach((function(t){e=e.replace(t,h(t.slice(0,6))+u(f(t.slice(6,13))))})),e}});const b={symbol:e=>{const s=`^(${t.symbol})(${t.coord})?(${r.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=`^(${t.prefix})?(${t.signbox})(${r.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]}:{}},text:e=>{if("string"!=typeof e)return[];const s=`(${t.sign}(${r.full})?|${t.spatial}(${r.full})?)`,o=e.match(new RegExp(s,"g"));return o?[...o]:[]}},x={symbol:e=>{if("string"==typeof e.symbol){const s=(e.symbol.match(t.symbol)||[""])[0];if(s){return s+((((e.coord&&e.coord[0]||"").toString()+"x"+(e.coord&&e.coord[1]||"").toString()).match(t.coord)||[""])[0]||"")+("string"==typeof e.style&&(e.style.match(r.full)||[""])[0]||"")}}},sign:e=>{let s="string"!=typeof e.box?"M":(e.box+"M").match(t.box);const o=(((e.max&&e.max[0]||"").toString()+"x"+(e.max&&e.max[1]||"").toString()).match(t.coord)||[""])[0]||"";if(!o)return;let n="";e.sequence&&Array.isArray(e.sequence)&&(n=e.sequence.map((e=>(e.match(t.symbol)||[""])[0])).join(""),n=n?"A"+n:"");let i="";e.spatials&&Array.isArray(e.spatials)&&(i=e.spatials.map((e=>{if("string"==typeof e.symbol){const r=(e.symbol.match(t.symbol)||[""])[0];if(r){const s=(((e.coord&&e.coord[0]||"").toString()+"x"+(e.coord&&e.coord[1]||"").toString()).match(t.coord)||[""])[0]||"";if(s)return r+s}}return""})).join(""));return n+s+o+i+("string"==typeof e.style&&(e.style.match(r.full)||[""])[0]||"")}},$=e=>{let t,r,s,n,i,a,l,c,p=b.sign(e);p.spatials?(n=Math.min(...p.spatials.map((e=>e.coord[0]))),i=p.max[0],t=i-n,a=Math.min(...p.spatials.map((e=>e.coord[1]))),l=p.max[1],r=l-a,s="sign",c=p.box):(p=b.symbol(e),c="M",p.coord?(n=p.coord[0],t=2*(500-n),a=p.coord[1],r=2*(500-a),s="symbol"):(n=490,t=20,a=490,r=20,s="none"));let u=o(p.style),f=u.zoom||1,d=u.padding||0;return{minX:n,minY:a,width:t,height:r,segment:s,lane:{B:0,L:-1,M:0,R:1}[c],padding:d,zoom:f}},w={height:500,width:150,offset:50,pad:20,margin:5,dynamic:!1,background:void 0,punctuation:{spacing:!0,pad:30,pull:!0},style:{detail:["black","white"],zoom:1}},v=e=>("object"!=typeof e&&(e={}),{...w,...e,punctuation:{...w.punctuation,...e.punctuation},style:{...w.style,...e.style}}),I=[256,517,759,767,877,895,903],A={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]},R=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];var k=Object.freeze({__proto__:null,re:t,parse:b,compose:x,info:$,columnDefaults:w,columnDefaultsMerge:v,columns:(e,t)=>{if("string"!=typeof e)return{};const r=v(t);let s=b.text(e),o=0,n=[],i=[],a=0,l=parseInt(r.width/2),c=r.height-r.margin,p=!0,u=!1;for(let e of s){let t=$(e);o+=a,r.punctuation.spacing?o+="sign"==t.segment?r.pad:0:o+=r.pad,u=o+t.height>c,u&&"symbol"==t.segment&&r.punctuation.pull&&p&&(u=!1,p=!1),0==i.length&&(u=!1),u&&(o=r.pad,n.push(i),i=[],p=!0),i.push(Object.assign(t,{x:l+r.offset*t.lane-(500-t.minX)*t.zoom*r.style.zoom,y:o,text:e})),o+=t.height*t.zoom*r.style.zoom,a=r.punctuation.spacing?"sign"==t.segment?r.pad:r.punctuation.pad:r.pad}if(i.length&&n.push(i),r.punctuation.pull)for(let e of n){let t=e[e.length-1],s=t.y+t.height-(r.height-r.margin);if(s>0){let t=parseInt(s/e.length)+1;for(let r in e)e[r].y-=t*r+t}}let f=[];for(let e of n){let t=[l-r.offset-r.pad],s=[l+r.offset+r.pad];for(let o of e)t.push(o.x-r.pad),s.push(o.x+o.width+r.pad);t=Math.min(...t),s=Math.max(...s);let o=r.width,n=0;r.dynamic?(o=s-t,n=-t):n=l-parseInt((t+s)/2);for(let t of e)t.x+=n;f.push(o)}return{options:r,widths:f,columns:n}},kind:[256,895,903],category:I,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:A,isType:(e,t)=>{const r=b.symbol(e);if(r.symbol){const e=parseInt(r.symbol.slice(1,4),16),s=A[t];if(s)return s[0]<=e&&s[1]>=e}return!1},colors:R,colorize:e=>{const t=b.symbol(e);let r="#000000";if(t.symbol){const e=parseInt(t.symbol.slice(1,4),16),s=I.findIndex((t=>t>e));r=R[s<0?6:s-1]}return r}});let E={base:"[123][0-9a-f]{2}",coord:"(?:[0-9]{3}x[0-9]{3})?",var:"V[0-9]+"};E.symbol=`S${E.base}[0-5u][0-9a-fu]`,E.range=`R${E.base}t${E.base}`,E.item=`(?:${E.symbol}|${E.range})`,E.list=`${E.item}(?:o${E.item})*`,E.prefix=`(?:A(?:${E.list})+)?T`,E.signbox=`(?:${E.list}${E.coord})*`,E.full=`Q(${E.prefix})?(${E.signbox})?(${E.var})?(-?)`;const j=e=>e.match(new RegExp(`(${E.list}${E.coord})`,"g")).map((e=>{let t,r;return e.includes("x")?(t=f(e.slice(-7)),r=e.slice(0,-7)):r=e,r.includes("o")?{or:r.split("o").map((e=>e.includes("S")?e:e.slice(1).split("t"))),coord:t,coord:t}:r.includes("S")?{symbol:r,coord:t}:{range:r.slice(1).split("t"),coord:t}})),S=(e,t,r)=>{let s,o,n,i,a,l,c;if(r||(r=""),s="",(e=("000"+e).slice(-3))===(t=""+t))return e;if(o=[],(e[0]!=t[0]||e[1]!=t[1])&&"0"!=e[2])if(s=e[0]+e[1],r){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]"}}n=15-parseInt(e[2],16)+1,e=""+(parseInt(e,16)+n).toString(16),o.push(s)}else{switch(e[2]){case"9":s+="9";break;case"8":s+="[89]";break;default:s+="["+e[2]+"-9]"}n=9-e[2]+1,e=""+(1*e+n),o.push(s)}if(s="",e[0]!=t[0]&&"0"!=e[1])if(r){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]",n=15-parseInt(e[1],16)+1,e=""+(parseInt(e,16)+16*n).toString(16),o.push(s)}else{switch(s=e[0],n=9-e[1]+1,e[1]){case"9":s+="9";break;case"8":s+="[89]";break;default:s+="["+e[1]+"-9]"}s+="[0-9]",n=9-e[1]+1,e=""+(1*e+10*n),o.push(s)}if(s="",e[0]!=t[0])if(r){switch(n=parseInt(t[0],16)-parseInt(e[0],16),i=(parseInt(e[0],16)+n-1).toString(16),n){case 1:s=e[0];break;case 2:s="["+e[0]+i+"]";break;default:switch(l=parseInt(e[0],16)>9?"h":"d",c=parseInt(i,16)>9?"h":"d",l+c){case"dd":case"hh":s+="["+e[0]+"-"+i+"]";break;case"dh":switch(n=9-e[0],n){case 0:s+="[9";break;case 1:s+="[89";break;default:s+="["+e[0]+"-9"}switch(i[0]){case"a":s+="a]";break;case"b":s+="ab]";break;default:s+="a-"+i+"]"}}}s+="[0-9a-f][0-9a-f]",n=parseInt(t[0],16)-parseInt(e[0],16),e=""+(parseInt(e,16)+256*n).toString(16),o.push(s)}else{switch(n=t[0]-e[0],i=1*e[0]+n-1,n){case 1:s=e[0];break;case 2:s="["+e[0]+i+"]";break;default:s="["+e[0]+"-"+i+"]"}s+="[0-9][0-9]",e=""+(1*e+100*n),o.push(s)}if(s="",e[1]!=t[1])if(r){switch(n=parseInt(t[1],16)-parseInt(e[1],16),i=(parseInt(e[1],16)+n-1).toString(16),s=e[0],n){case 1:s+=e[1];break;case 2:s+="["+e[1]+i+"]";break;default:switch(l=parseInt(e[1],16)>9?"h":"d",c=parseInt(i,16)>9?"h":"d",l+c){case"dd":s+="["+e[1],n>1&&(s+="-"),s+=i+"]";break;case"dh":switch(n=9-e[1],n){case 0:s+="[9";break;case 1:s+="[89";break;default:s+="["+e[1]+"-9"}switch(t[1]){case"a":s+="]";break;case"b":s+="a]";break;default:s+="a-"+(parseInt(t[1],16)-1).toString(16)+"]"}break;case"hh":s+="["+e[1],n>1&&(s+="-"),s+=(parseInt(t[1],16)-1).toString(16)+"]"}}s+="[0-9a-f]",n=parseInt(t[1],16)-parseInt(e[1],16),e=""+(parseInt(e,16)+16*n).toString(16),o.push(s)}else{switch(n=t[1]-e[1],i=1*e[1]+n-1,s=e[0],n){case 1:s+=e[1];break;case 2:s+="["+e[1]+i+"]";break;default:s+="["+e[1]+"-"+i+"]"}s+="[0-9]",e=""+(1*e+10*n),o.push(s)}if(s="",e[2]!=t[2])if(r){switch(s=e[0]+e[1],n=parseInt(t[2],16)-parseInt(e[2],16),l=parseInt(e[2],16)>9?"h":"d",c=parseInt(t[2],16)>9?"h":"d",l+c){case"dd":case"hh":s+="["+e[2],n>1&&(s+="-"),s+=t[2]+"]";break;case"dh":switch(n=9-e[2],n){case 0:s+="[9";break;case 1:s+="[89";break;default:s+="["+e[2]+"-9"}switch(t[2]){case"a":s+="a]";break;case"b":s+="ab]";break;default:s+="a-"+t[2]+"]"}}n=parseInt(t[2],16)-parseInt(e[2],16),e=""+(parseInt(e,16)+n).toString(16),o.push(s)}else{switch(n=t[2]-e[2],s=e[0]+e[1],n){case 0:s+=e[2];break;case 1:s+="["+e[2]+t[2]+"]";break;default:s+="["+e[2]+"-"+t[2]+"]"}e=""+(1*e+n),o.push(s)}return s="","0"==e[2]&&"0"==t[2]&&(s=t,o.push(s)),s="",a=o.length,1==a?s=o[0]:(s=o.join(")|("),s="(("+s+"))"),s},_=e=>{let t=e.slice(0,4),r=e.slice(4,5);t+="u"==r?"[0-5]":r;let s=e.slice(5,6);return t+="u"==s?"[0-9a-f]":s,t},z=e=>{let t=e.slice(1,4),r=e.slice(5,8);return"S"+S(t,r,"hex")+"[0-5][0-9a-f]"},F=e=>{if(!(e=e.match(new RegExp(`^${E.full}`))[0]))return"";var s,o,n,i,a,l,c,p,u,d,g,m=20,h="("+r.full+")?";if("Q"==e)return[t.prefix+"?"+t.signbox];if("Q-"==e)return[t.prefix+"?"+t.signbox+h];if("QT"==e)return[t.prefix+t.signbox];if("QT-"==e)return[t.prefix+t.signbox+h];var y=[],b=e.indexOf("T")+1;if(b){g="(A";var x=e.slice(0,b);if(e=e.replace(x,""),"QT"==x)g+="("+t.symbol+")+)";else if(s=x.match(new RegExp("("+E.list+")","g"))){for(a=0;a<s.length;a+=1)if(i=[],o=s[a].match(new RegExp("("+E.symbol+"|"+E.range+")","g"))){for(l=0;l<o.length;l+=1)(n=o[l].match(new RegExp(E.symbol)))?i.push(_(n[0])):i.push(z(o[l]));1==i.length?g+=i[0]:g+="("+i.join("|")+")"}g+="("+t.symbol+")*)"}}if((s=e.match(new RegExp(E.var,"g")))&&(m=1*s.toString().slice(1)),s=e.match(new RegExp(E.list+E.coord,"g")))for(a=0;a<s.length;a+=1){if(i=[],o=s[a].match(new RegExp("("+E.symbol+"|"+E.range+")","g"))){for(l=0;l<o.length;l+=1)(n=o[l].match(new RegExp(E.symbol)))?i.push(_(n[0])):i.push(z(o[l]));c=1==i.length?i[0]:"("+i.join("|")+")"}s[a].includes("x")?(u=(p=f(s[a].slice(-7)))[0],d=p[1],c+=S(u-m,u+m),c+="x",c+=S(d-m,d+m)):c+=t.coord,c=t.signbox+c+"("+t.symbol+t.coord+")*",c=b?g+c:t.prefix+"?"+c,e.indexOf("-")>0&&(c+=h),y.push(c)}return y.length||(e.indexOf("-")>0&&(c+=h),y.push(g+t.signbox)),y};var C=Object.freeze({__proto__:null,re:E,parse:e=>{const t="string"==typeof e?e.match(new RegExp(`^${E.full}`)):void 0;return{query:!!t||void 0,prefix:t&&t[1]?(r=t[1],{required:!0,parts:"T"==r?void 0:r.match(new RegExp(`${E.list}`,"g")).map((e=>e.includes("o")?["or"].concat(e.match(new RegExp(`(${E.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:t&&t[2]?j(t[2]):void 0,variance:t&&t[3]?parseInt(t[3].slice(1)):void 0,style:!(!t||!t[4])||void 0};var r},compose:e=>{if(!e||!e.query)return;let t="Q";return e.prefix&&e.prefix.required&&(Array.isArray(e.prefix.parts)&&(t+="A",t+=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("")),t+="T"),Array.isArray(e.signbox)&&(t+=e.signbox.map((e=>{let t;return e.or?t=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?t=e.symbol:e.range&&Array.isArray(e.range)&&2==e.range.length&&(t=`R${e.range[0]}t${e.range[1]}`),t+(Array.isArray(e.coord)&&2==e.coord.length?e.coord.join("x"):"")})).join("")),t+=e.style?"-":"",t=t.match(new RegExp(`^${E.full}`))[0],t},fsw2query:(e,t)=>{let r="";const s=b.sign(e);if(s.box){const e=t.indexOf("A")>-1,o=t.indexOf("a")>-1,n=t.indexOf("S")>-1,i=t.indexOf("s")>-1,a=t.indexOf("L")>-1;return(e||o||n||i)&&((e||o)&&s.sequence&&(r+="A",r+=s.sequence.map((e=>e.slice(0,4)+(o?"uu":e.slice(4,6)))).join(""),r+="T"),(n||i)&&s.spatials&&(r+=s.spatials.map((e=>e.symbol.slice(0,4)+(i?"uu":e.symbol.slice(4,6))+(a?e.coord.join("x"):""))).join(""))),r?"Q"+r:void 0}},range:S,regex:F,results:(e,t)=>{if(!t)return[];let r,s,o,n,i,a=F(e);if(!a)return[];for(i=0;i<a.length;i+=1)r=a[i],s=t.match(new RegExp(r,"g")),t=s?s.join(" "):"";return t?(o=t.split(" "),n=o.filter((function(e){return!(e in o)&&(o[e]=!0)}),{})):n=[],n},lines:(e,t)=>{if(!t)return[];let r,s,o,n,i,a=F(e);if(!a)return[];for(i=0;i<a.length;i+=1)r=a[i],r="^"+r+".*",s=t.match(new RegExp(r,"mg")),t=s?s.join("\n"):"";return t?(o=t.split("\n"),n=o.filter((function(e){return!(e in o)&&(o[e]=!0)}),{})):n=[],n}});const O={symbol:e=>{const t=`^(${i.symbol})(${i.coord})?(${r.full})?`,s="string"==typeof e?e.match(new RegExp(t)):void 0;return{symbol:s?s[1]:void 0,coord:s&&s[2]?p(s[2]):void 0,style:s?s[3]:void 0}},sign:e=>{const t=`^(${i.prefix})?(${i.signbox})(${r.full})?`,s="string"==typeof e?e.match(new RegExp(t)):void 0;return s?{sequence:s[1]?s[1].slice(2).match(/.{2}/g):void 0,box:s[2].slice(0,2),max:p(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:p(e.slice(2))}))),style:s[3]}:{}},text:e=>{if("string"!=typeof e)return[];const t=`(${i.sign}(${r.full})?|${i.spatial}(${r.full})?)`,s=e.match(new RegExp(t,"g"));return s?[...s]:[]}},q=e=>e.replace(/\\u([0-9A-F]{4})/g,(function(e,t){return String.fromCharCode(parseInt(t,16))})),T=e=>[e.charCodeAt(0).toString(16).toUpperCase(),e.charCodeAt(1).toString(16).toUpperCase()],M={symbol:e=>{if("object"==typeof e&&null!==e&&"string"==typeof e.symbol){const t=(e.symbol.match(i.symbol)||[""])[0];if(t){const s=e.coord&&e.coord[0]||"",o=e.coord&&e.coord[1]||"";return t+(s&&o?u([s,o]):"")+("string"==typeof e.style&&(e.style.match(r.full)||[""])[0]||"")}}},sign:e=>{if("object"!=typeof e||null===e)return;let t="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?u([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 l="";e.spatials&&Array.isArray(e.spatials)&&(l=e.spatials.map((e=>{if("string"==typeof e.symbol){const t=(e.symbol.match(i.symbol)||[""])[0];if(t){const r=e.coord&&e.coord[0]||"",s=e.coord&&e.coord[1]||"",o=r&&s?u([r,s]):"";if(o)return t+o}}return""})).join(""));return a+t+n+l+("string"==typeof e.style&&(e.style.match(r.full)||[""])[0]||"")}},D=e=>{let t,r,s,n,i,a,l,c,p=O.sign(e);p.spatials?(n=Math.min(...p.spatials.map((e=>e.coord[0]))),i=p.max[0],t=i-n,a=Math.min(...p.spatials.map((e=>e.coord[1]))),l=p.max[1],r=l-a,s="sign",c=p.box):(p=O.symbol(e),c="𝠃",p.coord?(n=p.coord[0],t=2*(500-n),a=p.coord[1],r=2*(500-a),s="symbol"):(n=490,t=20,a=490,r=20,s="none"));let u=o(p.style),f=u.zoom||1,d=u.padding||0;return{minX:n,minY:a,width:t,height:r,segment:s,lane:{"𝠁":0,"𝠂":-1,"𝠃":0,"𝠄":1}[c],padding:d,zoom:f}},Q={height:500,width:150,offset:50,pad:20,margin:5,dynamic:!1,background:void 0,punctuation:{spacing:!0,pad:30,pull:!0},style:{detail:["black","white"],zoom:1}},Z=e=>("object"!=typeof e&&(e={}),{...Q,...e,punctuation:{...Q.punctuation,...e.punctuation},style:{...Q.style,...e.style}}),L=[262145,287201,310433,311201,321761,323489,324257],P={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]},U=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];var B=Object.freeze({__proto__:null,re:i,parse:O,encode:e=>e.replace(/[\u007F-\uFFFF]/g,(function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4).toUpperCase()})),decode:q,pair:T,compose:M,info:D,columnDefaults:Q,columnDefaultsMerge:Z,columns:(e,t)=>{if("string"!=typeof e)return{};const r=Z(t);let s=O.text(e),o=0,n=[],i=[],a=0,l=parseInt(r.width/2),c=r.height-r.margin,p=!0,u=!1;for(let e of s){let t=D(e);o+=a,r.punctuation.spacing?o+="sign"==t.segment?r.pad:0:o+=r.pad,u=o+t.height>c,u&&"symbol"==t.segment&&r.punctuation.pull&&p&&(u=!1,p=!1),0==i.length&&(u=!1),u&&(o=r.pad,n.push(i),i=[],p=!0),i.push(Object.assign(t,{x:l+r.offset*t.lane-(500-t.minX)*t.zoom*r.style.zoom,y:o,text:e})),o+=t.height*t.zoom*r.style.zoom,a=r.punctuation.spacing?"sign"==t.segment?r.pad:r.punctuation.pad:r.pad}if(i.length&&n.push(i),r.punctuation.pull)for(let e of n){let t=e[e.length-1],s=t.y+t.height-(r.height-r.margin);if(s>0){let t=parseInt(s/e.length)+1;for(let r in e)e[r].y-=t*r+t}}let f=[];for(let e of n){let t=[l-r.offset-r.pad],s=[l+r.offset+r.pad];for(let o of e)t.push(o.x-r.pad),s.push(o.x+o.width+r.pad);t=Math.min(...t),s=Math.max(...s);let o=r.width,n=0;r.dynamic?(o=s-t,n=-t):n=l-parseInt((t+s)/2);for(let t of e)t.x+=n;f.push(o)}return{options:r,widths:f,columns:n}},kind:[262145,323489,324257],category:L,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:P,isType:(e,t)=>{const r=O.symbol(e);if(r.symbol){const e=d(r.symbol),s=P[t];if(s)return s[0]<=e&&s[1]>=e}return!1},colors:U,colorize:e=>{const t=O.symbol(e);let r="#000000";if(t.symbol){const e=d(t.symbol),s=L.findIndex((t=>t>e));r=U[s<0?6:s-1]}return r}});let X={base:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:(?:\ud836[\udc0c-\uddff]){2})?",var:"V[0-9]+"};X.symbol=`${X.base}f?r?`,X.range=`R${X.base}${X.base}`,X.item=`(?:${X.symbol}|${X.range})`,X.list=`${X.item}(?:o${X.item})*`,X.prefix=`(?:A(?:${X.list})+)?T`,X.signbox=`(?:${X.list}${X.coord})*`,X.full=`Q(${X.prefix})?(${X.signbox})?(${X.var})?(-?)`;const V=e=>e.match(new RegExp(`(${X.list}${X.coord})`,"g")).map((e=>{let t,r;return t=e.match(new RegExp(`${i.coord}`)),t?(t=p(t[0]),r=e.slice(0,-4)):(t=void 0,r=e),r.includes("o")?{or:r.split("o").map((e=>e.includes("R")?[e.slice(1,3),e.slice(3,5)]:e)),coord:t,coord:t}:r.includes("R")?{range:[r.slice(1,3),r.slice(3,5)],coord:t}:{symbol:r,coord:t}})),G=(e,t)=>{if(e>t)return"";let r,s="",o=[];if(e=T(e),t=T(t),2!=e.length&&2!=t.length)return"";if(e[0]==t[0])e[1]==t[1]?(s="\\u"+e[0]+"\\u"+e[1],o.push(s)):(s="\\u"+e[0]+"[\\u"+e[1]+"-\\u"+t[1]+"]",o.push(s));else{s="DFFF"==e[1]?"\\u"+e[0]+"\\uDFFF":"\\u"+e[0]+"[\\u"+e[1]+"-\\uDFFF]",o.push(s);let r=parseInt(t[0],16)-parseInt(e[0],16);2==r&&(s="\\u"+(parseInt(e[0],16)+1).toString(16).toUpperCase(),s+="[\\uDC00-\\uDFFF]",o.push(s)),r>2&&(s="[",s+="\\u"+(parseInt(e[0],16)+1).toString(16).toUpperCase(),s+="-\\u"+(parseInt(t[0],16)-1).toString(16).toUpperCase(),s+="][\\uDC00-\\uDFFF]",o.push(s)),s="DC00"==t[1]?"\\u"+t[0]+"\\uDC00":"\\u"+t[0]+"[\\uDC00-\\u"+t[1]+"]",o.push(s)}return r=o.length,1==r?s=o[0]:(s=o.join(")|("),s="(("+s+"))"),q(s)},Y=e=>{let t=e.match(new RegExp(X.symbol));if(t){let e,r,s=t[0].slice(0,2),o=m(s),n=o.slice(0,4);if("fr"==t[0].slice(-2))return e=h(n+"00"),r=h(n+"5f"),G(e,r);if("r"==t[0].slice(-1))return e=h(o.slice(0,5)+"0"),r=h(o.slice(0,5)+"f"),G(e,r);if("f"==t[0].slice(-1)){return"("+[0,1,2,3,4,5].map((function(e){return h(n+e+o.slice(-1))})).join("|")+")"}return s}return""},H=e=>(from=m(e.slice(1,3)),to=m(e.slice(-2)),from=h(from.slice(0,4)+"00"),to=h(to.slice(0,4)+"5f"),G(from,to)),J=e=>{if(!(e=e.match(new RegExp(`^${X.full}`))[0]))return"";let t,s,o,n,a,l,u,f,d,g,m,h=20,y=i.symbol,b=i.coord,x=i.box+b+"("+y+b+")*",$="("+i.sort+"("+y+")+)",w="("+r.full+")?";if("Q"==e)return[i.sign];if("Q-"==e)return[i.sign+"("+r.full+")?"];if("QT"==e)return[i.sortable];if("QT-"==e)return[i.sortable+"("+r.full+")?"];let v=[],I=e.indexOf("T")+1;if(I){m="("+i.sort;let r=e.slice(0,I);if(e=e.replace(r,""),"QT"==r)m+="("+y+")+)";else if(t=r.match(new RegExp("("+X.list+")","g")),t){for(a=0;a<t.length;a+=1)if(n=[],s=t[a].match(new RegExp("("+X.symbol+"|"+X.range+")","g")),s){for(l=0;l<s.length;l+=1)o=s[l].match(new RegExp(X.symbol)),o?n.push(Y(o[0])):n.push(H(s[l]));1==n.length?m+=n[0]:m+="("+n.join("|")+")"}m+="("+i.symbol+")*)"}}if(t=e.match(new RegExp("(V[0-9]+)","g")),t&&(h=1*t.toString().slice(1)),t=e.match(new RegExp(X.list+X.coord,"g")),t)for(a=0;a<t.length;a+=1){if(n=[],s=t[a].match(new RegExp("("+X.symbol+"|"+X.range+")","g")),s){for(l=0;l<s.length;l+=1)o=s[l].match(new RegExp(X.symbol)),o?n.push(Y(o[0])):n.push(H(s[l]));f=1==n.length?n[0]:"("+n.join("|")+")"}u=t[a].match(new RegExp(`${i.coord}`)),u?(u=p(u[0]),d=u[0],g=u[1],f+=G(c(d-h),c(d+h)),f+=G(c(g-h),c(g+h))):f+=i.coord,f=x+f+"("+y+b+")*",f=I?m+f:$+"?"+f,e.indexOf("-")>0&&(f+=w),v.push(f)}return v.length||(e.indexOf("-")>0&&(f+=w),v.push(m+x)),v};var K=Object.freeze({__proto__:null,re:X,parse:e=>{const t="string"==typeof e?e.match(new RegExp(`^${X.full}`)):void 0;return{query:!!t||void 0,prefix:t&&t[1]?(r=t[1],{required:!0,parts:"T"==r?void 0:r.match(new RegExp(`(${X.list})`,"g")).map((e=>e.includes("o")?["or"].concat(e.match(new RegExp(`(${X.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:t&&t[2]?V(t[2]):void 0,variance:t&&t[3]?parseInt(t[3].slice(1)):void 0,style:!(!t||!t[4])||void 0};var r},compose:e=>{if(!e||!e.query)return;let t="Q";return e.prefix&&e.prefix.required&&(Array.isArray(e.prefix.parts)&&(t+="A",t+=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("")),t+="T"),Array.isArray(e.signbox)&&(t+=e.signbox.map((e=>{let t;return e.or?t=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?t=e.symbol:e.range&&Array.isArray(e.range)&&2==e.range.length&&(t=`R${e.range[0]}${e.range[1]}`),t+(Array.isArray(e.coord)&&2==e.coord.length?u(e.coord):"")})).join("")),t+=e.style?"-":"",t=t.match(new RegExp(`^${X.full}`))[0],t},swu2query:(e,t)=>{let r="";const s=O.sign(e);if(s.box){const e=t.indexOf("A")>-1,o=t.indexOf("a")>-1,n=t.indexOf("S")>-1,i=t.indexOf("s")>-1,a=t.indexOf("L")>-1;return(e||o||n||i)&&((e||o)&&s.sequence&&(r+="A",r+=s.sequence.map((e=>e+(o?"fr":""))).join(""),r+="T"),(n||i)&&s.spatials&&(r+=s.spatials.map((e=>e.symbol+(i?"fr":"")+(a?u(e.coord):""))).join(""))),r?"Q"+r:void 0}},range:G,symbolRanges:Y,regex:J,results:(e,t)=>{if(!t)return[];let r,s,o,n,i,a=J(e);if(!a)return[];for(i=0;i<a.length;i+=1)r=a[i],s=t.match(new RegExp(r,"g")),t=s?s.join(" "):"";return t?(o=t.split(" "),n=o.filter((function(e){return!(e in o)&&(o[e]=!0)}),{})):n=[],n},lines:(e,t)=>{if(!t)return[];let r,s,o,n,i,a=J(e);if(!a)return[];for(i=0;i<a.length;i+=1)r=a[i],r="^"+r+".*",s=t.match(new RegExp(r,"mg")),t=s?s.join("\n"):"";return t?(o=t.split("\n"),n=o.filter((function(e){return!(e in o)&&(o[e]=!0)}),{})):n=[],n}});e.convert=y,e.fsw=k,e.fswquery=C,e.style=n,e.swu=B,e.swuquery=K,Object.defineProperty(e,"__esModule",{value:!0})}));