UNPKG

2.76 kBJavaScriptView Raw
1/* Sutton SignWriting Core Module v1.1.0, author: Steve Slevinski, 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.fsw={}))}(this,(function(o){"use strict";let e={symbol:"S[123][0-9a-f]{2}[0-5][0-9a-f]",coord:"[0-9]{3}x[0-9]{3}",sort:"A",box:"[BLMR]"};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.term=`${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 l=o=>o.split("x").map(o=>parseInt(o)),t={symbol:o=>{const t=`^(${e.symbol})(${e.coord})?(${s.full})?`,i="string"==typeof o?o.match(new RegExp(t)):void 0;return{symbol:i?i[1]:void 0,coord:i&&i[2]?l(i[2]):void 0,style:i?i[3]:void 0}},sign:o=>{const t=`^(${e.prefix})?(${e.signbox})(${s.full})?`,i="string"==typeof o?o.match(new RegExp(t)):void 0;return i?{sequence:i[1]?i[1].slice(1).match(/.{6}/g):void 0,box:i[2][0],max:l(i[2].slice(1,8)),spatials:i[2].length<9?void 0:i[2].slice(8).match(/(.{13})/g).map(o=>({symbol:o.slice(0,6),coord:[parseInt(o.slice(6,9)),parseInt(o.slice(10,13))]})),style:i[3]}:{}}},i=[256,517,759,767,877,895,903],r={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]},c=["#0000CC","#CC0000","#FF0099","#006600","#000000","#884411","#FF9900"];o.category=i,o.colorize=o=>{const e=t.symbol(o);let s="#000000";if(e.symbol){const o=parseInt(e.symbol.slice(1,4),16),l=i.findIndex(e=>e>o);s=c[l<0?6:l-1]}return s},o.colors=c,o.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],o.isType=(o,e)=>{const s=t.symbol(o);if(s.symbol){const o=parseInt(s.symbol.slice(1,4),16),l=r[e];if(l)return l[0]<=o&&l[1]>=o}return!1},o.kind=[256,895,903],o.parse=t,o.ranges=r,o.re=e,Object.defineProperty(o,"__esModule",{value:!0})}));