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.

63 lines (62 loc) 3.39 kB
import { jsx as _jsx } from "@zsnout/ithkuil-jsx/jsx-runtime"; import { deepFreeze } from "../../generate/index.js"; import { Anchor, AnchorX, Diacritic, getBBox, Row, } from "../index.js"; import { HANDWRITTEN_TERTIARY_SEGMENTS, TERTIARY_SEGMENTS, } from "./segment.js"; import { ValenceSegment } from "./valence.js"; /** An object mapping levels to their corresponding diacritics. */ export const LEVEL_TO_DIACRITIC_MAP = /* @__PURE__ */ deepFreeze({ MIN: "DOT", SBE: "HORIZ_WITH_TOP_LINE", IFR: "VERT_WITH_LEFT_LINE", DFC: "CURVE_TO_TOP", EQU: "DIAG_BAR", SUR: "CURVE_TO_BOTTOM", SPL: "VERT_WITH_RIGHT_LINE", SPQ: "HORIZ_WITH_BOTTOM_LINE", MAX: "HORIZ_BAR", }); /** * Renders a tertiary character as a group of SVG paths. * * @param tertiary Information about the tertiary character. * @returns An `SVGGElement` containing the tertiary character's elements. */ export function Tertiary(tertiary) { let g = (_jsx("g", {})); if (tertiary.top) { g.appendChild(_jsx(AnchorX, { at: "c", y: -15, x: tertiary.handwritten ? 0 : 5, children: _jsx("path", { d: (tertiary.handwritten ? HANDWRITTEN_TERTIARY_SEGMENTS : TERTIARY_SEGMENTS)[tertiary.top] }) })); } g.appendChild(_jsx(AnchorX, { at: "c", children: _jsx(ValenceSegment, { handwritten: tertiary.handwritten, valence: tertiary.valence || "MNO" }) })); if (tertiary.bottom) { g.appendChild(_jsx(Anchor, { at: "tc", y: 15, x: tertiary.handwritten ? 0 : -5, children: _jsx("path", { d: (tertiary.handwritten ? HANDWRITTEN_TERTIARY_SEGMENTS : TERTIARY_SEGMENTS)[tertiary.bottom] }) })); } if (tertiary.absoluteLevel) { if (!tertiary.top) { g.appendChild(_jsx(Anchor, { at: "bc", y: -35, children: _jsx(Diacritic, { handwritten: tertiary.handwritten, name: LEVEL_TO_DIACRITIC_MAP[tertiary.absoluteLevel] }) })); } else if (tertiary.compact) { g = (_jsx(Row, { compact: tertiary.compact, intro: [...g.children], vertical: true, reverse: true, children: _jsx(AnchorX, { at: "c", x: -2, children: _jsx(Diacritic, { handwritten: tertiary.handwritten, name: LEVEL_TO_DIACRITIC_MAP[tertiary.absoluteLevel] }) }) })); } else { const box = getBBox(g); g.appendChild(_jsx(Anchor, { at: "bc", y: box.y - 10, children: _jsx(Diacritic, { handwritten: tertiary.handwritten, name: LEVEL_TO_DIACRITIC_MAP[tertiary.absoluteLevel] }) })); } } if (tertiary.relativeLevel) { if (!tertiary.bottom) { g.appendChild(_jsx(Anchor, { at: "tc", y: 35, children: _jsx(Diacritic, { handwritten: tertiary.handwritten, name: LEVEL_TO_DIACRITIC_MAP[tertiary.relativeLevel] }) })); } else if (tertiary.compact) { g = (_jsx(Row, { compact: tertiary.compact, intro: [...g.children], vertical: true, children: _jsx(AnchorX, { at: "c", x: -2, children: _jsx(Diacritic, { handwritten: tertiary.handwritten, name: LEVEL_TO_DIACRITIC_MAP[tertiary.relativeLevel] }) }) })); } else { const box = getBBox(g); g.appendChild(_jsx(Anchor, { at: "tc", y: box.y + box.height + 10, children: _jsx(Diacritic, { handwritten: tertiary.handwritten, name: LEVEL_TO_DIACRITIC_MAP[tertiary.relativeLevel] }) })); } } return g; }