1 line
747 KiB
Plaintext
1 line
747 KiB
Plaintext
|
|
{"version":3,"file":"temml-BQUKR1fw.js","sources":["../../node_modules/temml/dist/temml.mjs"],"sourcesContent":["/**\n * This is the ParseError class, which is the main error thrown by Temml\n * functions when something has gone wrong. This is used to distinguish internal\n * errors from errors in the expression that the user provided.\n *\n * If possible, a caller should provide a Token or ParseNode with information\n * about where in the source string the problem occurred.\n */\nclass ParseError {\n constructor(\n message, // The error message\n token // An object providing position information\n ) {\n let error = \" \" + message;\n let start;\n\n const loc = token && token.loc;\n if (loc && loc.start <= loc.end) {\n // If we have the input and a position, make the error a bit fancier\n\n // Get the input\n const input = loc.lexer.input;\n\n // Prepend some information\n start = loc.start;\n const end = loc.end;\n if (start === input.length) {\n error += \" at end of input: \";\n } else {\n error += \" at position \" + (start + 1) + \": \\n\";\n }\n\n // Underline token in question using combining underscores\n const underlined = input.slice(start, end).replace(/[^]/g, \"$&\\u0332\");\n\n // Extract some context from the input and add it to the error\n let left;\n if (start > 15) {\n left = \"…\" + input.slice(start - 15, start);\n } else {\n left = input.slice(0, start);\n }\n let right;\n if (end + 15 < input.length) {\n right = input.slice(end, end + 15) + \"…\";\n } else {\n right = input.slice(end);\n }\n error += left + underlined + right;\n }\n\n // Some hackery to make ParseError a prototype of Error\n // See http://stackoverflow.com/a/8460753\n const self = new Error(error);\n self.name = \"ParseError\";\n self.__proto__ = ParseError.prototype;\n self.position = start;\n return self;\n }\n}\n\nParseError.prototype.__proto__ = Error.prototype;\n\n//\n/**\n * This file contains a list of utility functions which are useful in other\n * files.\n */\n\n/**\n * Provide a default value if a setting is undefined\n */\nconst deflt = function(setting, defaultIfUndefined) {\n return setting === undefined ? defaultIfUndefined : setting;\n};\n\n// hyphenate and escape adapted from Facebook's React under Apache 2 license\n\nconst uppercase = /([A-Z])/g;\nconst hyphenate = function(str) {\n return str.replace(uppercase, \"-$1\").toLowerCase();\n};\n\nconst ESCAPE_LOOKUP = {\n \"&\": \"&\",\n \">\": \">\",\n \"<\": \"<\",\n '\"': \""\",\n \"'\": \"'\"\n};\n\nconst ESCAPE_REGEX = /[&><\"']/g;\n\n/**\n * Escapes text to prevent scripting attacks.\n */\nfunction escape(text) {\n return String(text).replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);\n}\n\n/**\n * Sometimes we want to pull out the innermost element of a group. In most\n * cases, this will just be the group itself, but when ordgroups and colors have\n * a single element, we want to pull that out.\n */\nconst getBaseElem = function(group) {\n if (group.type === \"ordgroup\") {\n if (group.body.length === 1) {\n return getBaseElem(group.body[0]);\n } else {\n return group;\n }\n } else if (group.type === \"color\") {\n if (group.body.length === 1) {\n return getBaseElem(group.body[0]);\n } else {\n return group;\n }\n } else if (group.type === \"font\") {\n return getBaseElem(group.body);\n } else {\n return group;\n }\n};\n\n/**\n * TeXbook algorithms often reference \"character boxes\", which are simply groups\n * with a single character in them. To decide if something is a character box,\n * we find its innermost group, and see if it is a single character.\n */\nconst isCharacterBox = function(group) {\n const baseElem = getBaseElem(group);\n\n // These are all the types of groups which hold single characters\n return baseElem.type === \"mathord\" || baseElem.type === \"textord\" || base
|