{"version":3,"file":"index.cjs","names":[],"sources":["../../../package/systeme/provides.ts","../../../package/systeme/libs/parser.ts","../../../package/systeme/libs/print-raw.ts","../../../package/systeme/libs/systeme.ts"],"sourcesContent":["import {\n    MacroInfoRecord,\n    EnvInfoRecord,\n} from \"@unified-latex/unified-latex-types\";\n\nexport const macros: MacroInfoRecord = {\n    systeme: {\n        signature: \"s o o m\",\n        renderInfo: { inMathMode: true },\n    },\n    sysdelim: {\n        signature: \"m m\",\n    },\n    syseqsep: { signature: \"m\" },\n    sysalign: { signature: \"m\" },\n    syssignspace: { signature: \"m\" },\n    syseqspace: { signature: \"m\" },\n    syslineskipcoeff: { signature: \"m\" },\n    syseqivsign: { signature: \"m\" },\n    sysaddeqsign: { signature: \"m\" },\n    sysremoveeqsign: { signature: \"m\" },\n    sysextracolonsign: { signature: \"m\" },\n    syscodeextracol: { signature: \"m\" },\n    sysautonum: { signature: \"m\" },\n    syssubstitute: { signature: \"m\" },\n};\n\nexport const environments: EnvInfoRecord = {};\n","import * as Ast from \"@unified-latex/unified-latex-types\";\nimport * as SystemeSpec from \"./types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { decorateArrayForPegjs } from \"@unified-latex/unified-latex-util-pegjs\";\nimport { SystemePegParser } from \"@unified-latex/unified-latex-util-pegjs\";\n\ntype SystemeMatchers = {\n    at?: string;\n    equals?: string;\n    equationSeparator?: string;\n    mathOperations?: string[];\n    whitelistedVariables?: (string | Ast.String | Ast.Macro)[];\n};\n\nfunction createMatchers({\n    at = \"@\",\n    equals = \"=\",\n    equationSeparator = \",\",\n    mathOperations = [\"+\", \"-\"],\n    whitelistedVariables,\n}: SystemeMatchers = {}) {\n    let isVar: (node: Ast.Node) => boolean = (node: Ast.Node) =>\n        match.anyString(node) && !!node.content.match(/[a-zA-Z]/);\n    if (whitelistedVariables) {\n        // Unwrap all strings\n        whitelistedVariables = whitelistedVariables.map((v) =>\n            match.anyString(v) ? v.content : v\n        );\n        const macros = whitelistedVariables.filter((v) =>\n            match.anyMacro(v)\n        ) as Ast.Macro[];\n        const strings = whitelistedVariables.filter(\n            (v) => typeof v === \"string\"\n        ) as string[];\n        const macroHash = Object.fromEntries(macros.map((v) => [v.content, v]));\n        const stringHash = Object.fromEntries(strings.map((s) => [s, s]));\n        const macroMatcher = match.createMacroMatcher(macroHash);\n        isVar = (node: Ast.Node) =>\n            macroMatcher(node) ||\n            (match.anyString(node) && !!stringHash[node.content]);\n    }\n    return {\n        isSep: (node: Ast.Node) => match.string(node, equationSeparator),\n        isVar,\n        isOperation: (node: Ast.Node) =>\n            mathOperations.some((op) => match.string(node, op)),\n        isEquals: (node: Ast.Node) => match.string(node, equals),\n        isAt: (node: Ast.Node) => match.string(node, at),\n        isSubscript: (node: Ast.Node) =>\n            match.macro(node, \"_\") && node.escapeToken === \"\",\n        isWhitespace: match.whitespace,\n        isSameLineComment: (node: Ast.Node) =>\n            match.comment(node) && node.sameline,\n        isOwnLineComment: (node: Ast.Node) =>\n            match.comment(node) && !node.sameline,\n    };\n}\n\n/**\n * Parse the contents of the `\\systeme{...}` macro\n */\nexport function parse(\n    ast: Ast.Node[],\n    options?: SystemeMatchers\n): SystemeSpec.Line[] {\n    if (!Array.isArray(ast)) {\n        throw new Error(\"You must pass an array of nodes\");\n    }\n    // We need to at functions to `nodes` so that it imitates\n    // a Javascript string. Because we're mutating, make a copy first\n    ast = decorateArrayForPegjs([...ast]);\n    // matchers are passed in via the second argument (the `options` argument)\n    // so they are available from within the Pegjs grammar.\n    return SystemePegParser.parse(\n        ast,\n        createMatchers(options || {})\n    ) as SystemeSpec.Line[];\n}\n","import { printRaw as latexPrintRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport * as SystemeSpec from \"./types\";\n\n/**\n * Print an `systeme` argument specification AST to a string.\n */\nexport function printRaw(node: SystemeSpec.Ast, root = false): string {\n    if (typeof node === \"string\") {\n        return node;\n    }\n\n    if (Array.isArray(node)) {\n        const sepToken = root ? \" \" : \"\";\n        return node.map((tok) => printRaw(tok)).join(sepToken);\n    }\n\n    switch (node.type) {\n        case \"annotation\":\n            return `${latexPrintRaw(node.marker)}${latexPrintRaw(\n                node.content\n            )}`;\n        case \"item\":\n            return `${node.op ? latexPrintRaw(node.op) : \"\"}${latexPrintRaw(\n                node.content\n            )}`;\n        case \"equation\":\n            const left = node.left.map((n) => printRaw(n)).join(\"\");\n            const right = latexPrintRaw(node.right);\n            const equals = node.equals ? latexPrintRaw(node.equals) : \"\";\n            return `${left}${equals}${right}`;\n        case \"line\":\n            const equation = node.equation ? printRaw(node.equation) : \"\";\n            const annotation = node.annotation ? printRaw(node.annotation) : \"\";\n            const sep = node.sep ? latexPrintRaw(node.sep) : \"\";\n\n            const body = `${equation}${annotation}${sep}`;\n            if (node.trailingComment) {\n                return latexPrintRaw([body, node.trailingComment]);\n            }\n\n            return body;\n\n        default:\n            console.warn(\n                `Unknown node type \"${(node as any).type}\" for node`,\n                node\n            );\n            return \"\";\n    }\n}\n","import * as SystemeSpec from \"./types\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { arrayJoin } from \"@unified-latex/unified-latex-util-split\";\nimport { parse } from \"./parser\";\nimport { structuredClone } from \"@unified-latex/structured-clone\";\nimport { deleteComments } from \"@unified-latex/unified-latex-util-comments\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { getArgsContent } from \"@unified-latex/unified-latex-util-arguments\";\n\nconst AMP: Ast.String = { type: \"string\", content: \"&\" };\nconst SEP: Ast.Macro = { type: \"macro\", content: \"\\\\\" };\nconst QUAD: Ast.Macro = { type: \"macro\", content: \"quad\" };\nconst PLUS: Ast.String = { type: \"string\", content: \"+\" };\nconst COLUMN_KERN_ADJUSTMENT: Ast.Node[] = [\n    { type: \"string\", content: \"@\" },\n    {\n        type: \"group\",\n        content: [\n            { type: \"macro\", content: \"mkern\" },\n            { type: \"string\", content: \"5mu\" },\n        ],\n    },\n];\n\n/**\n * Return a map giving the sorted index of each variable in `vars`. There\n * may be duplicated variables in `vars`. The map will send duplicates to the same index.\n *\n * @param {Ast.Node[][]} vars\n * @returns\n */\nfunction sortVariables(\n    vars: Ast.Node[][],\n    whitelistedVariables?: Ast.Node[] | null\n) {\n    const varMap = new Map(vars.map((v) => [v, printRaw(v)]));\n    const varNames = Array.from(new Set(varMap.values()));\n    varNames.sort();\n    const nameToPos = whitelistedVariables\n        ? new Map(whitelistedVariables.map((v, i) => [printRaw(v), i]))\n        : new Map(varNames.map((name, i) => [name, i]));\n\n    return new Map(\n        Array.from(varMap.entries()).map(([variable, name]) => {\n            return [variable, nameToPos.get(name) ?? -1];\n        })\n    );\n}\n\n/**\n * Make an array of arrays representing the operation/content of each item in an equation\n * + the annotation. The return value is suitable to be joined with `&` for the body of an array.\n */\nfunction processLine(\n    line: SystemeSpec.Line,\n    numVars: number,\n    varOrder: Map<Ast.Node[], number>,\n    hasEquals: boolean,\n    hasAnnotation: boolean\n) {\n    const ret: Ast.Node[][] = [];\n    if (line.equation) {\n        // We need to combine all non-var items into a single expression\n        const nonVarItems = line.equation.left.filter(\n            (item) => item.variable == null\n        );\n        const varItems = line.equation.left.filter(\n            (item) => item.variable != null\n        );\n        let nonVarTerm: SystemeSpec.Item | null = null;\n        if (nonVarItems.length === 1) {\n            nonVarTerm = nonVarItems[0];\n        } else if (nonVarItems.length > 1) {\n            // We need to combine all the items. We do so by constructing a new item with the rest of the item's contents\n            // added on the back\n            nonVarTerm = {\n                ...nonVarItems[0],\n                content: nonVarItems[0].content.concat(\n                    nonVarItems.slice(1).flatMap((item) => {\n                        if (item.op) {\n                            return [item.op, ...item.content];\n                        }\n                        return [PLUS, ...item.content];\n                    })\n                ),\n            };\n        }\n\n        const allItems = nonVarTerm ? varItems.concat(nonVarTerm) : varItems;\n\n        const indexToItem = new Map(\n            allItems.map((item) => {\n                if (item.variable == null) {\n                    return [numVars - 1, item];\n                }\n                return [varOrder.get(item.variable), item];\n            })\n        );\n\n        let isFirstItem = true;\n        for (let i = 0; i < numVars; i++) {\n            const item = indexToItem.get(i);\n            if (item) {\n                if (\n                    isFirstItem &&\n                    (match.string(item.op, \"+\") || item.op == null)\n                ) {\n                    // If the first item starts with a plus or doesn't have a starting operation,\n                    // we don't use a starting symbol.\n                    ret.push([]);\n                    ret.push(item.content);\n                } else {\n                    // If we are not the first item, we always push an operation\n                    ret.push([item.op || PLUS]);\n                    ret.push(item.content);\n                }\n                isFirstItem = false;\n            } else {\n                // If there is no item for this position, we push a blank operation and content\n                ret.push([]);\n                ret.push([]);\n            }\n        }\n        // If we have an equals, we need to push its contents\n        if (hasEquals) {\n            const equalsPart = (\n                line.equation.equals ? [line.equation.equals] : []\n            ).concat(line.equation.right);\n            ret.push(equalsPart);\n        }\n    }\n    // If we have an annotation, we need to push it or a blank\n    if (hasAnnotation) {\n        ret.push(line.annotation ? line.annotation.content : []);\n    }\n\n    return ret;\n}\n\n/**\n * Add kerning information to the array specification. E.g. `crl` becomes `c@{\\mkern5mu}r@{\\mkern5mu}l`.\n * This is so the operations when typesetting a system of equations are properly spaced.\n */\nfunction arraySpecToSpacedArraySpec(spec: string, hasAnnotation?: boolean) {\n    const annotationSpec = hasAnnotation ? spec.charAt(spec.length - 1) : \"\";\n    const bodySpec = hasAnnotation ? spec.slice(0, spec.length - 1) : spec;\n\n    const bodyStrings: Ast.Node[][] = Array.from(bodySpec).map((x) => [\n        { type: \"string\", content: x },\n    ]);\n    const body = arrayJoin(bodyStrings, COLUMN_KERN_ADJUSTMENT);\n    return annotationSpec\n        ? body.concat({ type: \"string\", content: annotationSpec })\n        : body;\n}\n\n/**\n * Extract the variables from a systeme system of equations.\n */\nexport function extractVariables(nodes: SystemeSpec.Node[]): Ast.Node[][] {\n    return nodes.flatMap((node) => {\n        if (node.type === \"line\" && node.equation) {\n            return extractVariables(node.equation.left);\n        }\n        if (node.type === \"equation\") {\n            return node.left.flatMap((item) =>\n                item.variable ? [item.variable] : []\n            );\n        }\n        if (node.type === \"item\") {\n            return node.variable ? [node.variable] : [];\n        }\n        return [];\n    });\n}\n\n/**\n * Remove any whitespace from the variable list (including an explicit \" \" string).\n * As well, filter out any non-macro/non-string items.\n */\nfunction normalizeVariableWhitelist(\n    vars: (string | Ast.Node)[] | null | undefined\n) {\n    if (!vars) {\n        return null;\n    }\n    const normalized: Ast.Node[] = vars.map((v) =>\n        typeof v === \"string\" ? { type: \"string\", content: v } : v\n    );\n    const ret = normalized.filter(\n        (v) =>\n            (match.anyMacro(v) || match.anyString(v)) &&\n            !match.string(v, \" \") &&\n            !match.whitespace(v)\n    ) as (Ast.Macro | Ast.String)[];\n    return ret;\n}\n\n/**\n * Lays out the contents of a \\systeme{...} macro as an array. This function sorts the variables\n * in alphabetical order and lays out any annotations. An `\\begin{array}...\\end{array}` environment\n * is returned.\n *\n * If `properSpacing=true` then kerning information will be included in the array specification to space\n * the operators correctly. This kerning information will make the specification long (and may make it incompatible\n * with KaTeX).\n *\n * An optional whitelist of variables may be supplied. If supplied, only listed items will count as variables and\n * the order of variable appearance will be the same as the order of the whitelisted variables.\n */\nexport function systemeContentsToArray(\n    nodes: Ast.Node[],\n    options?: {\n        properSpacing?: boolean;\n        whitelistedVariables?: (string | Ast.String | Ast.Macro)[];\n    }\n) {\n    nodes = structuredClone(nodes);\n    deleteComments(nodes);\n    const { properSpacing = true, whitelistedVariables } = options || {};\n    const coercedWhitelistedVariables =\n        normalizeVariableWhitelist(whitelistedVariables);\n    const systemeAst = parse(nodes, { whitelistedVariables });\n    const vars = extractVariables(systemeAst);\n    const varOrder = sortVariables(vars, coercedWhitelistedVariables);\n    let numVars = coercedWhitelistedVariables\n        ? coercedWhitelistedVariables.length\n        : Math.max(...Array.from(varOrder.values())) + 1;\n    // If there are terms with no variable, we need a spot for them\n    if (\n        systemeAst.some((line) => {\n            if (line.equation) {\n                return line.equation.left.some((item) => item.variable == null);\n            }\n        })\n    ) {\n        numVars += 1;\n    }\n    const hasEquals = systemeAst.some(\n        (line) => line.equation && line.equation.equals\n    );\n    const hasAnnotation = systemeAst.some((line) => line.annotation);\n\n    let rows = systemeAst.map((line) =>\n        processLine(line, numVars, varOrder, hasEquals, hasAnnotation)\n    );\n    // If we have no leading `-` signs (e.g., only leading `+` or bank signs)\n    // We don't need space for the first operation to be stored\n    const noLeadingOperation = rows.every((row) => row[0].length === 0);\n\n    // Every item in an equation has a centered operation and a right-aligned variable part.\n    let arraySignature = Array.from({ length: numVars }, () => \"cr\").join(\"\");\n    if (noLeadingOperation) {\n        // We might not have a leading operation on the first item(s)\n        arraySignature = arraySignature.slice(1);\n        rows = rows.map((row) => row.slice(1));\n    }\n    if (hasEquals) {\n        // The part after the equals is left-aligned\n        arraySignature += \"l\";\n    }\n    if (hasAnnotation) {\n        // The annotation is left-aligned\n        arraySignature += \"l\";\n        // We also manually insert space in front of any annotation\n        rows = rows.map((row) => {\n            if (row[row.length - 1].length === 0) {\n                return row;\n            }\n            return [\n                ...row.slice(0, row.length - 1),\n                [QUAD, { type: \"whitespace\" }, ...row[row.length - 1]],\n            ];\n        });\n    }\n\n    // By default, the array signature will put lots of space between items.\n    // We can correct for that manually.\n    const arraySignatureWithSpacing: Ast.Node[] = properSpacing\n        ? arraySpecToSpacedArraySpec(arraySignature, hasAnnotation)\n        : [{ type: \"string\", content: arraySignature }];\n\n    const bodyRows = rows.map((row) => arrayJoin(row, AMP));\n    const body = arrayJoin(bodyRows, SEP);\n\n    const ret: Ast.Environment = {\n        type: \"environment\",\n        env: \"array\",\n        args: [\n            {\n                type: \"argument\",\n                openMark: \"{\",\n                closeMark: \"}\",\n                content: arraySignatureWithSpacing,\n            },\n        ],\n        content: body,\n    };\n\n    return ret;\n}\n\n/**\n * Find any systeme definitions, e.g. `\\sysdelim{.}{.}`, and attach their information\n * to the renderInfo of of the systeme macros.\n *\n */\nexport function attachSystemeSettingsAsRenderInfo(ast: Ast.Ast) {\n    const systemeMatcher = match.createMacroMatcher([\"systeme\", \"sysdelim\"]);\n\n    visit(\n        ast,\n        (nodes, info) => {\n            if (!info.context.inMathMode || !nodes.some(systemeMatcher)) {\n                return;\n            }\n            // Find the positions of the systeme and sysdelim macros\n            const systemeLocations = nodes.flatMap((node, i) =>\n                match.macro(node, \"systeme\") ? i : []\n            );\n            const sysdelimLocations = nodes.flatMap((node, i) =>\n                match.macro(node, \"sysdelim\") ? i : []\n            );\n\n            if (\n                systemeLocations.length === 0 ||\n                sysdelimLocations.length === 0\n            ) {\n                return;\n            }\n\n            for (const i of systemeLocations) {\n                // Find any sysdelim macros that occur before\n                const lastSysdelim = Math.max(\n                    ...sysdelimLocations.filter((loc) => loc < i)\n                );\n                if (lastSysdelim >= 0) {\n                    const node = nodes[i];\n                    const sysdelimMacro = nodes[lastSysdelim];\n                    if (!match.anyMacro(sysdelimMacro)) {\n                        throw new Error(\n                            `Expecting sysdelim macro but found \"${printRaw(\n                                sysdelimMacro\n                            )}\"`\n                        );\n                    }\n                    const args = getArgsContent(sysdelimMacro);\n                    updateRenderInfo(node, { sysdelims: args });\n                }\n            }\n        },\n        {\n            test: Array.isArray,\n            includeArrays: true,\n        }\n    );\n}\n"],"mappings":";;;;;;;;;;;;AAKA,IAAa,SAA0B;CACnC,SAAS;EACL,WAAW;EACX,YAAY,EAAE,YAAY,MAAM;EACnC;CACD,UAAU,EACN,WAAW,OACd;CACD,UAAU,EAAE,WAAW,KAAK;CAC5B,UAAU,EAAE,WAAW,KAAK;CAC5B,cAAc,EAAE,WAAW,KAAK;CAChC,YAAY,EAAE,WAAW,KAAK;CAC9B,kBAAkB,EAAE,WAAW,KAAK;CACpC,aAAa,EAAE,WAAW,KAAK;CAC/B,cAAc,EAAE,WAAW,KAAK;CAChC,iBAAiB,EAAE,WAAW,KAAK;CACnC,mBAAmB,EAAE,WAAW,KAAK;CACrC,iBAAiB,EAAE,WAAW,KAAK;CACnC,YAAY,EAAE,WAAW,KAAK;CA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