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 * This file contains information about the options that the Parser carries3 * around with it while parsing. Data is held in an `Options` object, and when4 * recursing, a new `Options` object can be created with the `.with*` and5 * `.reset` functions.6 */7 8import {getGlobalMetrics} from "./fontMetrics";9import type {StyleInterface} from "./Style";10import type {FontMetrics, MathFont, TextFont, FontWeight, FontShape} from "./types/fonts";11 12const sizeStyleMap = [13 // Each element contains [textsize, scriptsize, scriptscriptsize].14 // The size mappings are taken from TeX with \normalsize=10pt.15 [1, 1, 1], // size1: [5, 5, 5] \tiny16 [2, 1, 1], // size2: [6, 5, 5]17 [3, 1, 1], // size3: [7, 5, 5] \scriptsize18 [4, 2, 1], // size4: [8, 6, 5] \footnotesize19 [5, 2, 1], // size5: [9, 6, 5] \small20 [6, 3, 1], // size6: [10, 7, 5] \normalsize21 [7, 4, 2], // size7: [12, 8, 6] \large22 [8, 6, 3], // size8: [14.4, 10, 7] \Large23 [9, 7, 6], // size9: [17.28, 12, 10] \LARGE24 [10, 8, 7], // size10: [20.74, 14.4, 12] \huge25 [11, 10, 9], // size11: [24.88, 20.74, 17.28] \HUGE26];27 28const sizeMultipliers = [29 // fontMetrics.js:getGlobalMetrics also uses size indexes, so if30 // you change size indexes, change that function.31 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.44, 1.728, 2.074, 2.488,32];33 34const sizeAtStyle = function(size: number, style: StyleInterface): number {35 return style.size < 2 ? size : sizeStyleMap[size - 1][style.size - 1];36};37 38export type OptionsData = {39 style: StyleInterface;40 color?: string | undefined;41 size?: number;42 textSize?: number;43 phantom?: boolean;44 font?: MathFont;45 fontFamily?: TextFont;46 fontWeight?: FontWeight;47 fontShape?: FontShape;48 sizeMultiplier?: number;49 maxSize: number;50 minRuleThickness: number;51};52 53/**54 * This is the main options class. It contains the current style, size, color,55 * and font.56 *57 * Options objects should not be modified. To create a new Options with58 * different properties, call a `.having*` method.59 */60class Options {61 style: StyleInterface;62 color: string | undefined;63 size: number;64 textSize: number;65 phantom: boolean;66 // A font family applies to a group of fonts (i.e. SansSerif), while a font67 // represents a specific font (i.e. SansSerif Bold).68 // See: https://tex.stackexchange.com/questions/22350/difference-between-textrm-and-mathrm69 font: MathFont;70 fontFamily: TextFont;71 fontWeight: FontWeight;72 fontShape: FontShape;73 sizeMultiplier: number;74 maxSize: number;75 minRuleThickness: number;76 _fontMetrics: FontMetrics | undefined;77 78 /**79 * The base size index.80 */81 static BASESIZE: number = 6;82 83 constructor(data: OptionsData) {84 this.style = data.style;85 this.color = data.color;86 this.size = data.size || Options.BASESIZE;87 this.textSize = data.textSize || this.size;88 this.phantom = !!data.phantom;89 this.font = data.font || "";90 this.fontFamily = data.fontFamily || "";91 this.fontWeight = data.fontWeight || "";92 this.fontShape = data.fontShape || "";93 this.sizeMultiplier = sizeMultipliers[this.size - 1];94 this.maxSize = data.maxSize;95 this.minRuleThickness = data.minRuleThickness;96 this._fontMetrics = undefined;97 }98 99 /**100 * Returns a new options object with the same properties as "this". Properties101 * from "extension" will be copied to the new options object.102 */103 extend(extension: Partial<OptionsData>): Options {104 const data: OptionsData = {105 style: this.style,106 size: this.size,107 textSize: this.textSize,108 color: this.color,109 phantom: this.phantom,110 font: this.font,111 fontFamily: this.fontFamily,112 fontWeight: this.fontWeight,113 fontShape: this.fontShape,114 maxSize: this.maxSize,115 minRuleThickness: this.minRuleThickness,116 };117 118 Object.assign(data, extension);119 120 return new Options(data);121 }122 123 /**124 * Return an options object with the given style. If `this.style === style`,125 * returns `this`.126 */127 havingStyle(style: StyleInterface): Options {128 if (this.style === style) {129 return this;130 } else {131 return this.extend({132 style: style,133 size: sizeAtStyle(this.textSize, style),134 });135 }136 }137 138 /**139 * Return an options object with a cramped version of the current style. If140 * the current style is cramped, returns `this`.141 */142 havingCrampedStyle(): Options {143 return this.havingStyle(this.style.cramp());144 }145 146 /**147 * Return an options object with the given size and in at least `\textstyle`.148 * Returns `this` if appropriate.149 */150 havingSize(size: number): Options {151 if (this.size === size && this.textSize === size) {152 return this;153 } else {154 return this.extend({155 style: this.style.text(),156 size: size,157 textSize: size,158 sizeMultiplier: sizeMultipliers[size - 1],159 });160 }161 }162 163 /**164 * Like `this.havingSize(BASESIZE).havingStyle(style)`. If `style` is omitted,165 * changes to at least `\textstyle`.166 */167 havingBaseStyle(style: StyleInterface): Options {168 style = style || this.style.text();169 const wantSize = sizeAtStyle(Options.BASESIZE, style);170 if (171 this.size === wantSize &&172 this.textSize === Options.BASESIZE &&173 this.style === style174 ) {175 return this;176 } else {177 return this.extend({178 style: style,179 size: wantSize,180 });181 }182 }183 184 /**185 * Remove the effect of sizing changes such as \Huge.186 * Keep the effect of the current style, such as \scriptstyle.187 */188 havingBaseSizing(): Options {189 let size;190 switch (this.style.id) {191 case 4:192 case 5:193 size = 3; // normalsize in scriptstyle194 break;195 case 6:196 case 7:197 size = 1; // normalsize in scriptscriptstyle198 break;199 default:200 size = 6; // normalsize in textstyle or displaystyle201 }202 return this.extend({203 style: this.style.text(),204 size: size,205 });206 }207 208 /**209 * Create a new options object with the given color.210 */211 withColor(color: string): Options {212 return this.extend({213 color: color,214 });215 }216 217 /**218 * Create a new options object with "phantom" set to true.219 */220 withPhantom(): Options {221 return this.extend({222 phantom: true,223 });224 }225 226 /**227 * Creates a new options object with the given math font or old text font.228 * @type {[type]}229 */230 withFont(font: MathFont): Options {231 return this.extend({font});232 }233 234 /**235 * Create a new options objects with the given fontFamily.236 */237 withTextFontFamily(fontFamily: TextFont): Options {238 return this.extend({fontFamily, font: ""});239 }240 241 /**242 * Creates a new options object with the given font weight243 */244 withTextFontWeight(fontWeight: FontWeight): Options {245 return this.extend({246 fontWeight,247 font: "",248 });249 }250 251 /**252 * Creates a new options object with the given font weight253 */254 withTextFontShape(fontShape: FontShape): Options {255 return this.extend({256 fontShape,257 font: "",258 });259 }260 261 /**262 * Return the CSS sizing classes required to switch from enclosing options263 * `oldOptions` to `this`. Returns an array of classes.264 */265 sizingClasses(oldOptions: Options): Array<string> {266 if (oldOptions.size !== this.size) {267 return [268 "sizing",269 "reset-size" + oldOptions.size,270 "size" + this.size,271 ];272 } else {273 return [];274 }275 }276 277 /**278 * Return the CSS sizing classes required to switch to the base size. Like279 * `this.havingSize(BASESIZE).sizingClasses(this)`.280 */281 baseSizingClasses(): Array<string> {282 if (this.size !== Options.BASESIZE) {283 return [284 "sizing",285 "reset-size" + this.size,286 "size" + Options.BASESIZE,287 ];288 } else {289 return [];290 }291 }292 293 /**294 * Return the font metrics for this size.295 */296 fontMetrics(): FontMetrics {297 if (!this._fontMetrics) {298 this._fontMetrics = getGlobalMetrics(this.size);299 }300 return this._fontMetrics;301 }302 303 /**304 * Gets the CSS color of the current options object305 */306 getColor(): string | undefined {307 if (this.phantom) {308 return "transparent";309 } else {310 return this.color;311 }312 }313}314 315export default Options;316 