seemingly working hangul 2-set

This commit is contained in:
minjaesong
2021-10-23 15:15:39 +09:00
parent 5ef8f3cea4
commit 1141638fc3
4 changed files with 470 additions and 36 deletions

View File

@@ -141,26 +141,26 @@ let states = {"keylayouts":[[""],[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
["0"],
["1"],
["2"],
["3"],
["4"],
["5"],
["6"],
["7"],
["8"],
["9"],
["/"],
["*"],
["-"],
["+"],
["."],
["."],
["\n"],
["="],
["("],
[")"],
[undefined],
[undefined],
[undefined],
@@ -266,7 +266,6 @@ let isChoseong = (s) => (s === undefined) ? false : inRange(s.charCodeAt(0), 0x
let isJungseong = (s) => (s === undefined) ? false : inRange(s.charCodeAt(0), 0x1161, 0x1175)
let isJongseong = (s) => (s === undefined) ? false : inRange(s.charCodeAt(0), 0x11A8, 0x11C2)
let isChoseongDigraph = (s) => (s === undefined) ? false : ([0x1100, 0x1103, 0x1107, 0x1109, 0x110C].includes(s.charCodeAt(0)))
let isJungseongDigraph1 = (s) => (s === undefined) ? false : ([0x1169, 0x116E].includes(s.charCodeAt(0)))
let isJungseongDigraphO = (s) => (s === undefined) ? false : ([0x1161, 0x1162, 0x1175].includes(s.charCodeAt(0)))
let isJungseongDigraphU = (s) => (s === undefined) ? false : ([0x1165, 0x1166, 0x1175].includes(s.charCodeAt(0)))
let isJungseongDigraphEU = (s) => (s === undefined) ? false : ([0x1175].includes(s.charCodeAt(0)))
@@ -307,17 +306,14 @@ let bufAssemble = (isPreview) => {
// nothing on the buffer
if (states.buf[0] === undefined && states.buf[1] === undefined && states.buf[2] === undefined)
return ''
// Normalise unterminated hangul assembly
else if (!isPreview)
return states.buf.map(it => normaliseBuf(it)).join('')
// Hangul: I x F
else if (states.buf[1] === undefined && isHangul(states.buf[0]))
else if (isPreview && states.buf[1] === undefined && isHangul(states.buf[0]))
return [states.buf[0], "\u1160", states.buf[2]].join('')
// Hangul: x P F
else if (states.buf[0] === undefined && isHangul(states.buf[1]))
else if (isPreview && states.buf[0] === undefined && isHangul(states.buf[1]))
return ["\u115F", states.buf[1], states.buf[2]].join('')
// Hangul: x x F
else if (isHangul(states.buf[2]) && states.buf[0] === undefined && states.buf[1] === undefined )
else if (isPreview && isHangul(states.buf[2]) && states.buf[0] === undefined && states.buf[1] === undefined )
return ["\u115F", "\u1160", states.buf[2]].join('')
// Hangul: I P F
else if (isChoseong(states.buf[0]) && isJungseong(states.buf[1]) && isJongseong(states.buf[2])) {
@@ -326,16 +322,20 @@ let bufAssemble = (isPreview) => {
let f = states.buf[2].charCodeAt(0) - 0x11A7
return String.fromCodePoint(0xAC00 + (i * 588) + (p * 28) + f)
}
// Hangul: I P x
// Hangul: I P
else if (isChoseong(states.buf[0]) && isJungseong(states.buf[1]) && undefined == states.buf[2]) {
let i = states.buf[0].charCodeAt(0) - 0x1100
let p = states.buf[1].charCodeAt(0) - 0x1161
return String.fromCodePoint(0xAC00 + (i * 588) + (p * 28))
}
// Normalise unterminated hangul assembly
else if (!isPreview)
return states.buf.map(it => normaliseBuf(it)).join('')
else
return states.buf.join('')
}
Object.freeze({"n":"세벌식 3-90","states":states,
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
return Object.freeze({"n":"세벌식 3-90","states":states,
// return: [displayed output, composed output]
"accept":(headkey,shiftin,altgrin)=>{
let layer = 1*shiftin// + 2*altgrin
@@ -388,26 +388,29 @@ Object.freeze({"n":"세벌식 3-90","states":states,
}
// key inputs that bufIndex collides (end compose and accept incoming char as a new char state)
else if (states.buf[bufIndex] !== undefined) {
let oldbufstr = bufDebugStringify(states.buf)
let sendout = bufAssemble(); reset()
states.buf[bufIndex] = s
console.log(`sending out: ${sendout}`)
let newbufstr = bufDebugStringify(states.buf)
// console.log(`sending out: ${oldbufstr} -> ${sendout} ; ${newbufstr}`)
return [bufAssemble(1), sendout]
}
else {
states.buf[bufIndex] = s
console.log(`assembling: ${bufAssemble()}`)
// console.log(`assembling: ${bufDebugStringify(states.buf)} -> ${bufAssemble()}`)
}
return [bufAssemble(1), ""]
}
else {
let sendout = bufAssemble() + s; reset()
console.log(`sending out: ${sendout}`)
let oldbufstr = bufDebugStringify(states.buf)
let sendout = bufAssemble() + (s || ''); reset()
// console.log(`sending out: ${oldbufstr} -> ${sendout}`)
return [bufAssemble(1), sendout]
}
},
"end":()=>{
console.log(`end composing`)
// console.log(`end composing`)
let ret = bufAssemble()
reset()
return ret