mirror of
https://github.com/borbann-platform/srs-document.git
synced 2025-12-20 04:54:06 +01:00
1 line
7.0 KiB
Plaintext
1 line
7.0 KiB
Plaintext
{"version":3,"file":"index.cjs","sources":["../../../package/tikz/libs/print-raw.ts"],"sourcesContent":["import { printRaw as latexPrintRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { trim } from \"@unified-latex/unified-latex-util-trim\";\nimport * as TikzSpec from \"./types\";\n\n/**\n * Print an `systeme` argument specification AST to a string.\n */\nexport function printRaw(node: TikzSpec.Ast, root = false): string {\n if (typeof node === \"string\") {\n return node;\n }\n\n if (Array.isArray(node)) {\n const sepToken = root ? \" \" : \"\";\n const printed: string[] = [];\n for (let i = 0; i < node.length; i++) {\n const tok = node[i];\n const prevTok = node[i - 1];\n if (!prevTok) {\n printed.push(printRaw(tok));\n continue;\n }\n if (prevTok.type === \"comment\") {\n printed.push(printRaw(tok));\n continue;\n }\n if (tok.type !== \"comment\") {\n printed.push(sepToken);\n }\n printed.push(printRaw(tok));\n }\n return printed.join(\"\");\n }\n const type = node.type;\n\n switch (type) {\n case \"path_spec\":\n return printRaw(node.content, (root = true));\n case \"coordinate\":\n return `${latexPrintRaw(node.prefix)}(${latexPrintRaw(\n node.content\n )})`;\n case \"operation\":\n return latexPrintRaw(node.content);\n case \"comment\":\n return latexPrintRaw(node);\n case \"line_to\":\n return node.command;\n case \"curve_to\": {\n const comments = node.comments\n .map((c) => latexPrintRaw({ ...c, leadingWhitespace: false }))\n .join(\"\");\n if (node.controls.length === 1) {\n return `${comments}.. controls ${printRaw(\n node.controls[0]\n )} ..`;\n } else {\n return `${comments}.. controls ${printRaw(\n node.controls[0]\n )} and ${printRaw(node.controls[1])} ..`;\n }\n }\n case \"unknown\":\n return latexPrintRaw(node.content);\n case \"square_brace_group\":\n return `[${latexPrintRaw(node.content)}]`;\n case \"foreach\": {\n const comments = node.comments\n .map((c) => latexPrintRaw({ ...c, leadingWhitespace: false }))\n .join(\"\");\n let options = \"\";\n if (node.options) {\n options = ` [${latexPrintRaw(node.options)}]`;\n }\n const start = latexPrintRaw(node.start);\n const variables = [...node.variables];\n trim(variables);\n let printedVariables = latexPrintRaw(variables);\n // It is possible that the variables are specified as `[var=\\p]`, in the optional argument, instead of as `\\p`\n // In this case, `node.variables` will be empty and we don't want an extra space showing up.\n if (printedVariables.length > 0) {\n printedVariables = \" \" + printedVariables;\n }\n\n const command =\n node.command.type === \"foreach\"\n ? printRaw(node.command)\n : latexPrintRaw(node.command);\n\n return `${comments}${start}${printedVariables}${options} in ${latexPrintRaw(\n node.list\n )} ${command}`;\n }\n case \"svg_operation\": {\n const comments = node.comments\n .map((c) => latexPrintRaw({ ...c, leadingWhitespace: false }))\n .join(\"\");\n let options = \"\";\n if (node.options) {\n options = `[${latexPrintRaw(node.options)}]`;\n }\n\n return `${comments}svg${options} ${latexPrintRaw(node.content)}`;\n }\n case \"animation\": {\n const comments = node.comments\n .map((c) => latexPrintRaw({ ...c, leadingWhitespace: false }))\n .join(\"\");\n\n return `${comments}:${node.attribute} = {${latexPrintRaw(\n node.content\n )}}`;\n }\n\n default:\n const unprintedType: void = type;\n console.warn(`Unknown node type \"${unprintedType}\" for node`, node);\n return \"\";\n }\n}\n"],"names":["latexPrintRaw","trim"],"mappings":";;;;;AAOgB,SAAA,SAAS,MAAoB,OAAO,OAAe;AAC3D,MAAA,OAAO,SAAS,UAAU;AACnB,WAAA;AAAA,EAAA;AAGP,MAAA,MAAM,QAAQ,IAAI,GAAG;AACf,UAAA,WAAW,OAAO,MAAM;AAC9B,UAAM,UAAoB,CAAC;AAC3B,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AAC5B,YAAA,MAAM,KAAK,CAAC;AACZ,YAAA,UAAU,KAAK,IAAI,CAAC;AAC1B,UAAI,CAAC,SAAS;AACF,gBAAA,KAAK,SAAS,GAAG,CAAC;AAC1B;AAAA,MAAA;AAEA,UAAA,QAAQ,SAAS,WAAW;AACpB,gBAAA,KAAK,SAAS,GAAG,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