UNPKG

@zsnout/ithkuil

Version:

A set of tools which can generate and parse romanized Ithkuil text and which can generate Ithkuil script from text and JSON data.

79 lines (78 loc) 4.16 kB
import { jsx as _jsx, jsxs as _jsxs } from "@zsnout/ithkuil-jsx/jsx-runtime"; import { EXTENSIONS, HANDWRITTEN_CORES, CORES, } from "../index.js"; import { Diacritic } from "../other/diacritic.js"; import { Row } from "../other/row.js"; import { Anchor } from "../utilities/anchor.js"; import { getBBox } from "../utilities/get-bbox.js"; import { rotate180AndRotateStartingPoint } from "../utilities/rotate-180.js"; import { Translate } from "../utilities/translate.js"; function noop(x) { return x; } function Extension({ handwritten, name, direction, reversed, }) { const top = EXTENSIONS[name]; const check = reversed ? rotate180AndRotateStartingPoint : noop; if (direction == "horiz") { return _jsx("path", { d: check(handwritten ? top.horiz2 : top.horiz) }); } if (direction == "vert") { return _jsx("path", { d: check(handwritten ? top.vert2 : top.vert) }); } if (direction == "diag") { return _jsx("path", { d: check(top.diag) }); } throw new Error("Invalid direction: " + direction + "."); } function TopExtension({ core, coreShape, handwritten, name, }) { return (_jsx("g", { children: _jsx(Translate, { x: core.top[1] + (handwritten ? 0 : core.top[2] ? -10 : 0), y: getBBox(coreShape).y + (handwritten ? 0 : core.top[2] ? 10 : 0), children: _jsx(Extension, { name: name, handwritten: handwritten, direction: core.top[0], reversed: handwritten ? (core.top[0] == "horiz") == !core.top[2] : !!core.top[2] }) }) })); } function BottomExtension({ core, coreShape, handwritten, name, }) { const reversed = !core.bottom[2]; return (_jsx("g", { children: _jsx(Translate, { x: core.bottom[1] + (handwritten ? 0 : reversed ? 0 : 10), y: getBBox(coreShape).y + getBBox(coreShape).height + (handwritten ? 0 : reversed ? 0 : -10), children: _jsx(Extension, { name: name, direction: core.bottom[0], handwritten: handwritten, reversed: reversed }) }) })); } /** * Assembles an advanced alphabetic character as an group of SVG paths. * * @param alphabetic Properties that modify the character. * @returns An `SVGGElement` containing the character. */ export function AdvancedAlphabetic(alphabetic) { const handwritten = !!alphabetic.handwritten; const core = (handwritten ? HANDWRITTEN_CORES : CORES).TONAL_PLACEHOLDER; const coreShape = (_jsx("path", { d: core.shape })); let main = (_jsxs("g", { children: [coreShape, alphabetic.top ? _jsx(TopExtension, { core: core, coreShape: coreShape, handwritten: handwritten, name: alphabetic.top }) : undefined, alphabetic.bottom ? _jsx(BottomExtension, { core: core, coreShape: coreShape, handwritten: handwritten, name: alphabetic.bottom }) : undefined] })); if (alphabetic.superposed) { const diacritic = (_jsx(Anchor, { at: "bc", x: alphabetic.handwritten ? 7.5 : 10, y: -45, children: _jsx(Diacritic, { handwritten: handwritten, name: alphabetic.superposed }) })); main.appendChild(diacritic); } if (alphabetic.underposed) { const diacritic = (_jsx(Anchor, { at: "tc", x: alphabetic.handwritten ? -7.5 : -10, y: 45, children: _jsx(Diacritic, { handwritten: handwritten, name: alphabetic.underposed }) })); main.appendChild(diacritic); } if (alphabetic.right) { main = (_jsx(Row, { compact: true, space: handwritten ? 15 : 10, intro: [...main.querySelectorAll("path")], children: _jsx(Anchor, { at: "cl", children: _jsx(Diacritic, { handwritten: handwritten, name: alphabetic.right }) }) })); } if (alphabetic.left) { main = (_jsx(Row, { compact: true, space: handwritten ? 15 : 10, reverse: true, intro: [...main.querySelectorAll("path")], children: _jsx(Anchor, { at: "cr", children: _jsx(Diacritic, { handwritten: handwritten, name: alphabetic.left }) }) })); } return main; }