UNPKG

2.77 kBJavaScriptView Raw
1/* Sutton SignWriting Core Module v1.2.0 (https://github.com/sutton-signwriting/core), author: Steve Slevinski (https://SteveSlevinski.me), license: MIT */
2let 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.sortable=`${e.prefix}${e.signbox}`;let 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}`;const t=e=>({"𝠀":"A","𝠁":"B","𝠂":"L","𝠃":"M","𝠄":"R"})[e],r=e=>({A:"𝠀",B:"𝠁",L:"𝠂",M:"𝠃",R:"𝠄"})[e],n=e=>parseInt(e.codePointAt(0))-120844+250,c=e=>String.fromCodePoint(120844+parseInt(e)-250),s=e=>[n(e.slice(0,2)),n(e.slice(2,4))],i=e=>e.map(e=>c(e)).join(""),a=e=>e.split("x").map(e=>parseInt(e)),p=e=>e.join("x"),l=e=>parseInt(e.codePointAt(0)),f=e=>String.fromCodePoint(e),g=e=>l(e)-262144,d=e=>f(e+262144),x=e=>1+96*(parseInt(e.slice(1,4),16)-256)+16*parseInt(e.slice(4,5),16)+parseInt(e.slice(5,6),16),u=e=>{const o=e-1,t=parseInt(o/96),r=parseInt((o-96*t)/16),n=parseInt(o-96*t-16*r);return"S"+(t+256).toString(16)+r.toString(16)+n.toString(16)},$=e=>{const o=l(e)-262145,t=parseInt(o/96),r=parseInt((o-96*t)/16),n=parseInt(o-96*t-16*r);return"S"+(t+256).toString(16)+r.toString(16)+n.toString(16)},b=e=>f(262145+96*(parseInt(e.slice(1,4),16)-256)+16*parseInt(e.slice(4,5),16)+parseInt(e.slice(5,6),16)),m=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(o.symbol,"g"));r&&r.forEach((function(e){t=t.replace(e,$(e))}));const n=t.match(new RegExp(o.coord,"g"));return n&&n.forEach((function(e){t=t.replace(e,s(e).join("x"))})),t},I=o=>{if(!o)return"";const t=o.match(new RegExp(e.prefix,"g"));t&&t.forEach((function(e){o=o.replace(e,"𝠀"+e.slice(1).match(/.{6}/g).map(e=>b(e)).join(""))}));const n=o.match(new RegExp(e.box+e.coord,"g"));n&&n.forEach((function(e){o=o.replace(e,r(e.slice(0,1))+i(a(e.slice(1,8))))}));const c=o.match(new RegExp(e.spatial,"g"));return c&&c.forEach((function(e){o=o.replace(e,b(e.slice(0,6))+i(a(e.slice(6,13))))})),o};export{f as code2swu,p as coord2fsw,i as coord2swu,a as fsw2coord,I as fsw2swu,u as id2key,d as id2swu,x as key2id,b as key2swu,r as mark2swu,c as num2swu,l as swu2code,s as swu2coord,m as swu2fsw,g as swu2id,$ as swu2key,t as swu2mark,n as swu2num};