@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.
104 lines (103 loc) • 4.08 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "@zsnout/ithkuil-jsx/jsx-runtime";
import { deepFreeze, deepFreezeAndNullPrototype, } from "../../generate/index.js";
import { EXTENSIONS, rotate180AndRotateStartingPoint, } from "../index.js";
import { getBBox } from "../utilities/get-bbox.js";
import { Translate } from "../utilities/translate.js";
import { PrimaryBottomLeft } from "./bottom-left.js";
import { HANDWRITTEN_CORE_EXTENSIONS, PrimaryCore } from "./core.js";
import { PrimarySuperPosed } from "./super-posed.js";
import { PrimaryTopRight } from "./top-right.js";
import { PrimaryUnderPosed } from "./under-posed.js";
const DIACRITIC_OFFSET = /* @__PURE__ */ deepFreezeAndNullPrototype({
BSC: 0,
CTE: 12.5,
CSV: -2.5,
OBJ: 5,
});
const HANDWRITTEN_DIACRITIC_OFFSET = /* @__PURE__ */ deepFreezeAndNullPrototype({
BSC: 0,
CTE: 5,
CSV: 0,
OBJ: 0,
});
/** An object mapping from perspective and extension into secondary extensions. */
export const PRIMARY_TOP_LEFT = /* @__PURE__ */ deepFreeze({
M: {
DEL: undefined,
PRX: "s",
ICP: "t",
ATV: "d",
GRA: "m",
DPL: "n",
},
G: {
DEL: "p",
PRX: "g",
ICP: "ž",
ATV: "ḑ",
GRA: "v",
DPL: "x",
},
N: {
DEL: "š",
PRX: "EXTENSION_GEMINATE",
ICP: "w",
ATV: "h",
GRA: "f",
DPL: "ř",
},
A: {
DEL: "b",
PRX: "k",
ICP: "c",
ATV: "č",
GRA: "ż",
DPL: "j",
},
});
/**
* An object mapping from function, version, M/D, and stem into secondary
* extensions.
*/
export const PRIMARY_BOTTOM_RIGHT = /* @__PURE__ */ deepFreeze({
STA: {
PRC: {
M: ["b", undefined, "p", "š"],
D: ["c", "z", "p_WITH_LINE", "w"],
},
CPT: {
M: ["k", "l", "g", "EXTENSION_GEMINATE"],
D: ["č", "r_FLIPPED", "g_WITH_LINE", "h"],
},
},
DYN: {
PRC: {
M: ["d", "m", "CORE_GEMINATE", "t"],
D: ["d_WITH_LINE", "n", "ň", "ž"],
},
CPT: {
M: ["ţ", "s", "x", "f"],
D: ["ḑ", "r", "ř", "v"],
},
},
});
/**
* Assembles a primary character as an group of SVG paths.
*
* @param props Properties that modify the character.
* @returns An `SVGGElement` containing the character.
*/
export function Primary(primary) {
const specification = primary.specification || "BSC";
const handwritten = !!primary.handwritten;
const core = PrimaryCore({ handwritten, specification });
const coreBox = getBBox(core);
const topLeft = PRIMARY_TOP_LEFT[primary.perspective || "M"][primary.extension || "DEL"];
const bottomRight = PRIMARY_BOTTOM_RIGHT[primary.function || "STA"][primary.version || "PRC"][primary.configuration?.startsWith("D") ? "D" : "M"][primary.stem ?? 1];
const topLeftDirection = handwritten ? HANDWRITTEN_CORE_EXTENSIONS[specification][0] : "diag";
const bottomRightDirection = handwritten ? HANDWRITTEN_CORE_EXTENSIONS[specification][1] : "diag";
return (_jsxs("g", { children: [core, topLeft && (_jsx(Translate, { x: coreBox.x + (handwritten ? 0 : 7.5), y: -35, children: _jsx("path", { d: EXTENSIONS[topLeft][topLeftDirection] }) })), bottomRight && (_jsx(Translate, { x: coreBox.x + coreBox.width - (handwritten ? 0 : 7.5), y: 35, children: _jsx("path", { d: rotate180AndRotateStartingPoint(EXTENSIONS[bottomRight][bottomRightDirection]) }) })), _jsx(Translate, { x: coreBox.x -
(handwritten ? HANDWRITTEN_DIACRITIC_OFFSET : DIACRITIC_OFFSET)[specification], y: 35, children: PrimaryBottomLeft(primary) }), _jsx(Translate, { x: coreBox.x +
coreBox.width +
(handwritten ? HANDWRITTEN_DIACRITIC_OFFSET : DIACRITIC_OFFSET)[specification], y: -35, children: PrimaryTopRight(primary) }), _jsx(Translate, { y: -45, children: PrimarySuperPosed(primary) }), _jsx(Translate, { x: -7.5, y: 45, children: PrimaryUnderPosed(primary) })] }));
}