UNPKG

4.49 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(o,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((o=o||self).ssw=o.ssw||{},o.ssw.swu={}))}(this,(function(o){"use strict";let e={symbol:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:\ud836[\udc0c-\uddff]){2}",sort:"𝠀",box:"\ud836[\udc01-\udc04]"};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.sortable=`${e.prefix}${e.signbox}`;let s={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}"};s.colorbase=`(?:${s.colorhex}|${s.colorname})`,s.color=`_${s.colorbase}_`,s.colors=`_${s.colorbase}(?:,${s.colorbase})?_`,s.background=`G${s.color}`,s.detail=`D${s.colors}`,s.detailsym=`D[0-9]{2}${s.colors}`,s.classes=`${s.classbase}(?: ${s.classbase})*`,s.full=`-(${s.colorize})?(${s.padding})?(${s.background})?(${s.detail})?(${s.zoom})?(?:-((?:${s.detailsym})*)((?:${s.zoomsym})*))?(?:-(${s.classes})?!(?:(${s.id})!)?)?`;const t=o=>parseInt(o.codePointAt(0))-120844+250,r=o=>[t(o.slice(0,2)),t(o.slice(2,4))],c=o=>o.map(o=>(o=>String.fromCodePoint(120844+parseInt(o)-250))(o)).join(""),n=o=>parseInt(o.codePointAt(0)),l={symbol:o=>{const t=`^(${e.symbol})(${e.coord})?(${s.full})?`,c="string"==typeof o?o.match(new RegExp(t)):void 0;return{symbol:c?c[1]:void 0,coord:c&&c[2]?r(c[2]):void 0,style:c?c[3]:void 0}},sign:o=>{const t=`^(${e.prefix})?(${e.signbox})(${s.full})?`,c="string"==typeof o?o.match(new RegExp(t)):void 0;return c?{sequence:c[1]?c[1].slice(2).match(/.{2}/g):void 0,box:c[2].slice(0,2),max:r(c[2].slice(2,6)),spatials:c[2].length<7?void 0:c[2].slice(6).match(/(.{6})/g).map(o=>({symbol:o.slice(0,2),coord:r(o.slice(2))})),style:c[3]}:{}}},i={symbol:o=>{if("object"==typeof o&&null!==o&&"string"==typeof o.symbol){const t=(o.symbol.match(e.symbol)||[""])[0];if(t){const e=o.coord&&o.coord[0]||"",r=o.coord&&o.coord[1]||"";return t+(e&&r?c([e,r]):"")+("string"==typeof o.style&&(o.style.match(s.full)||[""])[0]||"")}}},sign:o=>{if("object"!=typeof o||null===o)return;let t="string"!=typeof o.box?"𝠃":(o.box+"𝠃").match(e.box);const r=o.max&&o.max[0]||"",n=o.max&&o.max[1]||"",l=r&&n?c([r,n]):void 0;if(!l)return;let i="";o.sequence&&Array.isArray(o.sequence)&&(i=(i=o.sequence.map(o=>(o.match(e.symbol)||[""])[0]).join(""))?"𝠀"+i:"");let a="";return o.spatials&&Array.isArray(o.spatials)&&(a=o.spatials.map(o=>{if("string"==typeof o.symbol){const s=(o.symbol.match(e.symbol)||[""])[0];if(s){const e=o.coord&&o.coord[0]||"",t=o.coord&&o.coord[1]||"",r=e&&t?c([e,t]):"";if(r)return s+r}}return""}).join("")),i+t+l+a+("string"==typeof o.style&&(o.style.match(s.full)||[""])[0]||"")}},a=[262145,287201,310433,311201,321761,323489,324257],d={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"];o.category=a,o.colorize=o=>{const e=l.symbol(o);let s="#000000";if(e.symbol){const o=n(e.symbol),t=a.findIndex(e=>e>o);s=u[t<0?6:t-1]}return s},o.colors=u,o.compose=i,o.decode=o=>o.replace(/\\u([0-9A-F]{4})/g,(function(o,e){return String.fromCharCode(parseInt(e,16))})),o.encode=o=>o.replace(/[\u007F-\uFFFF]/g,(function(o){return"\\u"+("0000"+o.charCodeAt(0).toString(16)).substr(-4).toUpperCase()})),o.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],o.isType=(o,e)=>{const s=l.symbol(o);if(s.symbol){const o=n(s.symbol),t=d[e];if(t)return t[0]<=o&&t[1]>=o}return!1},o.kind=[262145,323489,324257],o.pair=o=>[o.charCodeAt(0).toString(16).toUpperCase(),o.charCodeAt(1).toString(16).toUpperCase()],o.parse=l,o.ranges=d,o.re=e,Object.defineProperty(o,"__esModule",{value:!0})}));