Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1/**2 * These objects store data about MathML nodes. This is the MathML equivalent3 * of the types in domTree.js. Since MathML handles its own rendering, and4 * since we're mainly using MathML to improve accessibility, we don't manage5 * any of the styling state that the plain DOM nodes do.6 *7 * The `toNode` and `toMarkup` functions work similarly to how they do in8 * domTree.js, creating namespaced DOM nodes and HTML text markup respectively.9 */10 11import {escape} from "./utils";12import {DocumentFragment} from "./tree";13import {createClass} from "./domTree";14import {makeEm} from "./units";15 16import type {VirtualNode} from "./tree";17 18/**19 * MathML node types used in KaTeX. For a complete list of MathML nodes, see20 * https://developer.mozilla.org/en-US/docs/Web/MathML/Element.21 */22export type MathNodeType =23 "math" | "annotation" | "semantics" |24 "mtext" | "mn" | "mo" | "mi" | "mspace" |25 "mover" | "munder" | "munderover" | "msup" | "msub" | "msubsup" |26 "mfrac" | "mroot" | "msqrt" |27 "mtable" | "mtr" | "mtd" | "mlabeledtr" |28 "mrow" | "menclose" |29 "mstyle" | "mpadded" | "mphantom" | "mglyph";30 31export interface MathDomNode extends VirtualNode {32 toText(): string;33}34 35export type documentFragment = DocumentFragment<MathDomNode>;36export function newDocumentFragment(37 children: ReadonlyArray<MathDomNode>38): documentFragment {39 return new DocumentFragment(children);40}41 42/**43 * This node represents a general purpose MathML node of any type. The44 * constructor requires the type of node to create (for example, `"mo"` or45 * `"mspace"`, corresponding to `<mo>` and `<mspace>` tags).46 */47export class MathNode implements MathDomNode {48 type: MathNodeType;49 attributes: Record<string, string>;50 children: MathDomNode[];51 classes: string[];52 53 constructor(54 type: MathNodeType,55 children?: MathDomNode[],56 classes?: string[]57 ) {58 this.type = type;59 this.attributes = {};60 this.children = children || [];61 this.classes = classes || [];62 }63 64 /**65 * Sets an attribute on a MathML node. MathML depends on attributes to convey a66 * semantic content, so this is used heavily.67 */68 setAttribute(name: string, value: string) {69 this.attributes[name] = value;70 }71 72 /**73 * Gets an attribute on a MathML node.74 */75 getAttribute(name: string): string {76 return this.attributes[name];77 }78 79 /**80 * Converts the math node into a MathML-namespaced DOM element.81 */82 toNode(): Node {83 const node = document.createElementNS(84 "http://www.w3.org/1998/Math/MathML", this.type);85 86 for (const attr in this.attributes) {87 if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {88 node.setAttribute(attr, this.attributes[attr]);89 }90 }91 92 if (this.classes.length > 0) {93 node.className = createClass(this.classes);94 }95 96 for (let i = 0; i < this.children.length; i++) {97 // Combine multiple TextNodes into one TextNode, to prevent98 // screen readers from reading each as a separate word [#3995]99 if (this.children[i] instanceof TextNode &&100 this.children[i + 1] instanceof TextNode) {101 let text = this.children[i].toText() + this.children[++i].toText();102 while (this.children[i + 1] instanceof TextNode) {103 text += this.children[++i].toText();104 }105 node.appendChild(new TextNode(text).toNode());106 } else {107 node.appendChild(this.children[i].toNode());108 }109 }110 111 return node;112 }113 114 /**115 * Converts the math node into an HTML markup string.116 */117 toMarkup(): string {118 let markup = "<" + this.type;119 120 // Add the attributes121 for (const attr in this.attributes) {122 if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {123 markup += " " + attr + "=\"";124 markup += escape(this.attributes[attr]);125 markup += "\"";126 }127 }128 129 if (this.classes.length > 0) {130 markup += ` class ="${escape(createClass(this.classes))}"`;131 }132 133 markup += ">";134 135 for (let i = 0; i < this.children.length; i++) {136 markup += this.children[i].toMarkup();137 }138 139 markup += "</" + this.type + ">";140 141 return markup;142 }143 144 /**145 * Converts the math node into a string, similar to innerText, but escaped.146 */147 toText(): string {148 return this.children.map(child => child.toText()).join("");149 }150}151 152/**153 * This node represents a piece of text.154 */155export class TextNode implements MathDomNode {156 text: string;157 158 constructor(text: string) {159 this.text = text;160 }161 162 /**163 * Converts the text node into a DOM text node.164 */165 toNode(): Node {166 return document.createTextNode(this.text);167 }168 169 /**170 * Converts the text node into escaped HTML markup171 * (representing the text itself).172 */173 toMarkup(): string {174 return escape(this.toText());175 }176 177 /**178 * Converts the text node into a string179 * (representing the text itself).180 */181 toText(): string {182 return this.text;183 }184}185 186/**187 * This node represents a space, but may render as <mspace.../> or as text,188 * depending on the width.189 */190export class SpaceNode implements MathDomNode {191 width: number;192 character: string | null | undefined;193 194 /**195 * Create a Space node with width given in CSS ems.196 */197 constructor(width: number) {198 this.width = width;199 // See https://www.w3.org/TR/2000/WD-MathML2-20000328/chapter6.html200 // for a table of space-like characters. We use Unicode201 // representations instead of &LongNames; as it's not clear how to202 // make the latter via document.createTextNode.203 if (width >= 0.05555 && width <= 0.05556) {204 this.character = "\u200a"; //  205 } else if (width >= 0.1666 && width <= 0.1667) {206 this.character = "\u2009"; //  207 } else if (width >= 0.2222 && width <= 0.2223) {208 this.character = "\u2005"; //  209 } else if (width >= 0.2777 && width <= 0.2778) {210 this.character = "\u2005\u200a"; //   211 } else if (width >= -0.05556 && width <= -0.05555) {212 this.character = "\u200a\u2063"; // ​213 } else if (width >= -0.1667 && width <= -0.1666) {214 this.character = "\u2009\u2063"; // ​215 } else if (width >= -0.2223 && width <= -0.2222) {216 this.character = "\u205f\u2063"; // ​217 } else if (width >= -0.2778 && width <= -0.2777) {218 this.character = "\u2005\u2063"; // ​219 } else {220 this.character = null;221 }222 }223 224 /**225 * Converts the math node into a MathML-namespaced DOM element.226 */227 toNode(): Node {228 if (this.character) {229 return document.createTextNode(this.character);230 } else {231 const node = document.createElementNS(232 "http://www.w3.org/1998/Math/MathML", "mspace");233 node.setAttribute("width", makeEm(this.width));234 return node;235 }236 }237 238 /**239 * Converts the math node into an HTML markup string.240 */241 toMarkup(): string {242 if (this.character) {243 return `<mtext>${this.character}</mtext>`;244 } else {245 return `<mspace width="${makeEm(this.width)}"/>`;246 }247 }248 249 /**250 * Converts the math node into a string, similar to innerText.251 */252 toText(): string {253 if (this.character) {254 return this.character;255 } else {256 return " ";257 }258 }259}260 