UNPKG

6.87 kBJavaScriptView Raw
1/* Sutton SignWriting Core Module v1.4.2 (https://github.com/sutton-signwriting/core), author: Steve Slevinski (https://SteveSlevinski.me), license: MIT */
2let o={symbol:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:\ud836[\udc0c-\uddff]){2}",sort:"𝠀",box:"\ud836[\udc01-\udc04]"};o.prefix=`(?:${o.sort}(?:${o.symbol})+)`,o.spatial=`${o.symbol}${o.coord}`,o.signbox=`${o.box}${o.coord}(?:${o.spatial})*`,o.sign=`${o.prefix}?${o.signbox}`,o.sortable=`${o.prefix}${o.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)",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.classes})?!(?:(${t.id})!)?)?`;const e=o=>(new RegExp(`^${t.colorhex}$`).test(o)?"#":"")+o,s=o=>{const s=`^${t.full}`,i=("string"==typeof o?o.match(new RegExp(s)):[])||[];return n={colorize:i[1]?!!i[1]:void 0,padding:i[2]?parseInt(i[2].slice(1)):void 0,background:i[3]?e(i[3].slice(2,-1)):void 0,detail:i[4]?i[4].slice(2,-1).split(",").map(e):void 0,zoom:i[5]?"Zx"===i[5]?"x":parseFloat(i[5].slice(1)):void 0,detailsym:i[6]?i[6].match(new RegExp(t.detailsym,"g")).map((o=>{const t=o.split("_"),s=t[1].split(",").map(e);return{index:parseInt(t[0].slice(1)),detail:s}})):void 0,classes:i[7]?i[7]:void 0,id:i[8]?i[8]:void 0},Object.fromEntries(Object.entries(n).filter((([o,t])=>void 0!==t)));var n},i=o=>parseInt(o.codePointAt(0))-120844+250,n=o=>[i(o.slice(0,2)),i(o.slice(2,4))],l=o=>o.map((o=>(o=>String.fromCodePoint(120844+parseInt(o)-250))(o))).join(""),a=o=>parseInt(o.codePointAt(0)),r={symbol:e=>{const s=`^(${o.symbol})(${o.coord})?(${t.full})?`,i="string"==typeof e?e.match(new RegExp(s)):void 0;return{symbol:i?i[1]:void 0,coord:i&&i[2]?n(i[2]):void 0,style:i?i[3]:void 0}},sign:e=>{const s=`^(${o.prefix})?(${o.signbox})(${t.full})?`,i="string"==typeof e?e.match(new RegExp(s)):void 0;return i?{sequence:i[1]?i[1].slice(2).match(/.{2}/g):void 0,box:i[2].slice(0,2),max:n(i[2].slice(2,6)),spatials:i[2].length<7?void 0:i[2].slice(6).match(/(.{6})/g).map((o=>({symbol:o.slice(0,2),coord:n(o.slice(2))}))),style:i[3]}:{}},text:e=>{if("string"!=typeof e)return[];const s=`(${o.sign}(${t.full})?|${o.spatial}(${t.full})?)`,i=e.match(new RegExp(s,"g"));return i?[...i]:[]}},c=o=>o.replace(/[\u007F-\uFFFF]/g,(function(o){return"\\u"+("0000"+o.charCodeAt(0).toString(16)).substr(-4).toUpperCase()})),d=o=>o.replace(/\\u([0-9A-F]{4})/g,(function(o,t){return String.fromCharCode(parseInt(t,16))})),p=o=>[o.charCodeAt(0).toString(16).toUpperCase(),o.charCodeAt(1).toString(16).toUpperCase()],m={symbol:e=>{if("object"==typeof e&&null!==e&&"string"==typeof e.symbol){const s=(e.symbol.match(o.symbol)||[""])[0];if(s){const o=e.coord&&e.coord[0]||"",i=e.coord&&e.coord[1]||"";return s+(o&&i?l([o,i]):"")+("string"==typeof e.style&&(e.style.match(t.full)||[""])[0]||"")}}},sign:e=>{if("object"!=typeof e||null===e)return;let s="string"!=typeof e.box?"𝠃":(e.box+"𝠃").match(o.box);const i=e.max&&e.max[0]||"",n=e.max&&e.max[1]||"",a=i&&n?l([i,n]):void 0;if(!a)return;let r="";e.sequence&&Array.isArray(e.sequence)&&(r=e.sequence.map((t=>(t.match(o.symbol)||[""])[0])).join(""),r=r?"𝠀"+r:"");let c="";e.spatials&&Array.isArray(e.spatials)&&(c=e.spatials.map((t=>{if("string"==typeof t.symbol){const e=(t.symbol.match(o.symbol)||[""])[0];if(e){const o=t.coord&&t.coord[0]||"",s=t.coord&&t.coord[1]||"",i=o&&s?l([o,s]):"";if(i)return e+i}}return""})).join(""));return r+s+a+c+("string"==typeof e.style&&(e.style.match(t.full)||[""])[0]||"")}},u=o=>{let t,e,i,n,l,a,c,d,p=r.sign(o);p.spatials?(n=Math.min(...p.spatials.map((o=>o.coord[0]))),l=p.max[0],t=l-n,a=Math.min(...p.spatials.map((o=>o.coord[1]))),c=p.max[1],e=c-a,i="sign",d=p.box):(p=r.symbol(o),d="𝠃",p.coord?(n=p.coord[0],t=2*(500-n),a=p.coord[1],e=2*(500-a),i="symbol"):(n=490,t=20,a=490,e=20,i="none"));let m=s(p.style),u=m.zoom||1,f=m.padding||0;return{minX:n,minY:a,width:t,height:e,segment:i,lane:{"𝠁":0,"𝠂":-1,"𝠃":0,"𝠄":1}[d],padding:f,zoom:u}},f={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}},g=o=>("object"!=typeof o&&(o={}),{...f,...o,punctuation:{...f.punctuation,...o.punctuation},style:{...f.style,...o.style}}),y=(o,t)=>{if("string"!=typeof o)return{};const e=g(t);let s=r.text(o),i=0,n=[],l=[],a=0,c=parseInt(e.width/2),d=e.height-e.margin,p=!0,m=!1;for(let o of s){let t=u(o);i+=a,e.punctuation.spacing?i+="sign"==t.segment?e.pad:0:i+=e.pad,m=i+t.height>d,m&&"symbol"==t.segment&&e.punctuation.pull&&p&&(m=!1,p=!1),0==l.length&&(m=!1),m&&(i=e.pad,n.push(l),l=[],p=!0),l.push(Object.assign(t,{x:c+e.offset*t.lane-(500-t.minX)*t.zoom*e.style.zoom,y:i,text:o})),i+=t.height*t.zoom*e.style.zoom,a=e.punctuation.spacing?"sign"==t.segment?e.pad:e.punctuation.pad:e.pad}if(l.length&&n.push(l),e.punctuation.pull)for(let o of n){let t=o[o.length-1],s=t.y+t.height-(e.height-e.margin);if(s>0){let t=parseInt(s/o.length)+1;for(let e in o)o[e].y-=t*e+t}}let f=[];for(let o of n){let t=[c-e.offset-e.pad],s=[c+e.offset+e.pad];for(let i of o)t.push(i.x-e.pad),s.push(i.x+i.width+e.pad);t=Math.min(...t),s=Math.max(...s);let i=e.width,n=0;e.dynamic?(i=s-t,n=-t):n=c-parseInt((t+s)/2);for(let t of o)t.x+=n;f.push(i)}return{options:e,widths:f,columns:n}},h=[262145,323489,324257],b=[262145,287201,310433,311201,321761,323489,324257],x=[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],$={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]},v=(o,t)=>{const e=r.symbol(o);if(e.symbol){const o=a(e.symbol),s=$[t];if(s)return s[0]<=o&&s[1]>=o}return!1},z=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"],A=o=>{const t=r.symbol(o);let e="#000000";if(t.symbol){const o=a(t.symbol),s=b.findIndex((t=>t>o));e=z[s<0?6:s-1]}return e};export{b as category,A as colorize,z as colors,f as columnDefaults,g as columnDefaultsMerge,y as columns,m as compose,d as decode,c as encode,x as group,u as info,v as isType,h as kind,p as pair,r as parse,$ as ranges,o as re};