UNPKG

2.9 kBJavaScriptView Raw
1/* Sutton SignWriting Core Module v1.1.0, author: Steve Slevinski, license: MIT */
2!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o(((e=e||self).ssw=e.ssw||{},e.ssw.convert={}))}(this,(function(e){"use strict";let o={symbol:"S[123][0-9a-f]{2}[0-5][0-9a-f]",coord:"[0-9]{3}x[0-9]{3}",sort:"A",box:"[BLMR]"};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.term=`${o.prefix}${o.signbox}`;let s={symbol:"(?:(?:\ud8c0[\udc01-\udfff])|(?:[\ud8c1-\ud8fc][\udc00-\udfff])|(?:\ud8fd[\udc00-\udc80]))",coord:"(?:\ud836[\udc0c-\uddff]){2}",sort:"𝠀",box:"\ud836[\udc01-\udc04]"};s.prefix=`(?:${s.sort}(?:${s.symbol})+)`,s.spatial=`${s.symbol}${s.coord}`,s.signbox=`${s.box}${s.coord}(?:${s.spatial})*`,s.sign=`${s.prefix}?${s.signbox}`,s.term=`${s.prefix}${s.signbox}`;const t=e=>({A:"𝠀",B:"𝠁",L:"𝠂",M:"𝠃",R:"𝠄"})[e],r=e=>parseInt(e.codePointAt(0))-120844+250,n=e=>String.fromCodePoint(120844+parseInt(e)-250),c=e=>[r(e.slice(0,2)),r(e.slice(2,4))],i=e=>e.map(e=>n(e)).join(""),a=e=>e.split("x").map(e=>parseInt(e)),p=e=>parseInt(e.codePointAt(0)),u=e=>String.fromCodePoint(e),d=e=>{const o=p(e)-262145,s=parseInt(o/96),t=parseInt((o-96*s)/16),r=parseInt(o-96*s-16*t);return"S"+(s+256).toString(16)+t.toString(16)+r.toString(16)},f=e=>u(262145+96*(parseInt(e.slice(1,4),16)-256)+16*parseInt(e.slice(4,5),16)+parseInt(e.slice(5,6),16));e.code2swu=u,e.coord2fsw=e=>e.join("x"),e.coord2swu=i,e.fsw2coord=a,e.fsw2swu=e=>{if(!e)return"";const s=e.match(new RegExp(o.prefix,"g"));s&&s.forEach((function(o){e=e.replace(o,"𝠀"+o.slice(1).match(/.{6}/g).map(e=>f(e)).join(""))}));const r=e.match(new RegExp(o.box+o.coord,"g"));r&&r.forEach((function(o){e=e.replace(o,t(o.slice(0,1))+i(a(o.slice(1,8))))}));const n=e.match(new RegExp(o.spatial,"g"));return n&&n.forEach((function(o){e=e.replace(o,f(o.slice(0,6))+i(a(o.slice(6,13))))})),e},e.id2key=e=>{const o=e-1,s=parseInt(o/96),t=parseInt((o-96*s)/16),r=parseInt(o-96*s-16*t);return"S"+(s+256).toString(16)+t.toString(16)+r.toString(16)},e.id2swu=e=>u(e+262144),e.key2id=e=>1+96*(parseInt(e.slice(1,4),16)-256)+16*parseInt(e.slice(4,5),16)+parseInt(e.slice(5,6),16),e.key2swu=f,e.mark2swu=t,e.num2swu=n,e.swu2code=p,e.swu2coord=c,e.swu2fsw=e=>{if(!e)return"";let o=e.replace(/𝠀/g,"A").replace(/𝠁/g,"B").replace(/𝠂/g,"L").replace(/𝠃/g,"M").replace(/𝠄/g,"R");const t=o.match(new RegExp(s.symbol,"g"));t&&t.forEach((function(e){o=o.replace(e,d(e))}));const r=o.match(new RegExp(s.coord,"g"));return r&&r.forEach((function(e){o=o.replace(e,c(e).join("x"))})),o},e.swu2id=e=>p(e)-262144,e.swu2key=d,e.swu2mark=e=>({"𝠀":"A","𝠁":"B","𝠂":"L","𝠃":"M","𝠄":"R"})[e],e.swu2num=r,Object.defineProperty(e,"__esModule",{value:!0})}));