@regmisatyam/retex 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +189 -37
- package/dist/index-DJEasLJc.d.ts +492 -0
- package/dist/index-DXTDYNCI.d.cts +492 -0
- package/dist/index.cjs +1198 -591
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +196 -358
- package/dist/index.d.ts +196 -358
- package/dist/index.js +1166 -592
- package/dist/index.js.map +1 -1
- package/dist/library.cjs +649 -0
- package/dist/library.cjs.map +1 -0
- package/dist/library.d.cts +2 -0
- package/dist/library.d.ts +2 -0
- package/dist/library.js +625 -0
- package/dist/library.js.map +1 -0
- package/dist/{react-v8gyKEAs.d.cts → react-B3tN1iWa.d.cts} +74 -38
- package/dist/{react-v8gyKEAs.d.ts → react-B3tN1iWa.d.ts} +74 -38
- package/dist/react.cjs +113 -74
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +113 -74
- package/dist/react.js.map +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { b as SourceRange, A as ArgumentNode, N as Node, f as CommandNode, T as Theme, R as ReactRenderFn, P as PartialTheme, V as ThemeColors, X as ThemeFonts, D as DocumentNode } from './react-B3tN1iWa.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Token kinds produced by the {@link Tokenizer}.
|
|
5
|
+
*
|
|
6
|
+
* ReTeX intentionally diverges from TeX in a few places that matter for
|
|
7
|
+
* resumes:
|
|
8
|
+
* - `%` is a *literal* percent sign (so `Reduced latency by 40%` and
|
|
9
|
+
* `\column{40%}` work as written) rather than a comment marker.
|
|
10
|
+
* - Comments use `%%` to end-of-line, which never collides with percentages.
|
|
11
|
+
*/
|
|
12
|
+
declare enum TokenType {
|
|
13
|
+
/** A command such as `\section`, `\textbf`, `\item`. The lexeme excludes the backslash. */
|
|
14
|
+
Command = "Command",
|
|
15
|
+
/** `{` — begin group / argument. */
|
|
16
|
+
LBrace = "LBrace",
|
|
17
|
+
/** `}` — end group / argument. */
|
|
18
|
+
RBrace = "RBrace",
|
|
19
|
+
/** `[` — begin optional argument. */
|
|
20
|
+
LBracket = "LBracket",
|
|
21
|
+
/** `]` — end optional argument. */
|
|
22
|
+
RBracket = "RBracket",
|
|
23
|
+
/** Run of literal text. */
|
|
24
|
+
Text = "Text",
|
|
25
|
+
/** Run of inline whitespace (spaces/tabs, single newline). */
|
|
26
|
+
Whitespace = "Whitespace",
|
|
27
|
+
/** A blank line — paragraph break. */
|
|
28
|
+
ParBreak = "ParBreak",
|
|
29
|
+
/** `\\` — explicit line break. */
|
|
30
|
+
LineBreak = "LineBreak",
|
|
31
|
+
/** `%% ...` comment (stripped from output, surfaced to editor tooling). */
|
|
32
|
+
Comment = "Comment",
|
|
33
|
+
/** End of input. */
|
|
34
|
+
EOF = "EOF"
|
|
35
|
+
}
|
|
36
|
+
/** A lexical token with full source provenance. */
|
|
37
|
+
interface Token {
|
|
38
|
+
type: TokenType;
|
|
39
|
+
/** The exact source text of the token (backslash stripped for commands). */
|
|
40
|
+
value: string;
|
|
41
|
+
range: SourceRange;
|
|
42
|
+
}
|
|
43
|
+
/** Reserved single characters that the tokenizer treats specially. */
|
|
44
|
+
declare const SPECIAL_CHARS: Set<string>;
|
|
45
|
+
|
|
46
|
+
/** Severity levels, ordered the same way LSP orders them. */
|
|
47
|
+
declare enum DiagnosticSeverity {
|
|
48
|
+
Error = "error",
|
|
49
|
+
Warning = "warning",
|
|
50
|
+
Info = "info",
|
|
51
|
+
Hint = "hint"
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Stable, machine-readable diagnostic codes. Editors can key quick-fixes and
|
|
55
|
+
* documentation links off these rather than the (localizable) message text.
|
|
56
|
+
*/
|
|
57
|
+
declare enum DiagnosticCode {
|
|
58
|
+
UnexpectedToken = "RTX1001",
|
|
59
|
+
UnterminatedGroup = "RTX1002",
|
|
60
|
+
UnterminatedArgument = "RTX1003",
|
|
61
|
+
UnexpectedEOF = "RTX1004",
|
|
62
|
+
MismatchedBrace = "RTX1005",
|
|
63
|
+
UnknownCommand = "RTX2001",
|
|
64
|
+
UnknownEnvironment = "RTX2002",
|
|
65
|
+
MissingRequiredArgument = "RTX2003",
|
|
66
|
+
TooManyArguments = "RTX2004",
|
|
67
|
+
MissingEnvironmentEnd = "RTX2005",
|
|
68
|
+
MismatchedEnvironment = "RTX2006",
|
|
69
|
+
InvalidColor = "RTX3001",
|
|
70
|
+
InvalidUrl = "RTX3002",
|
|
71
|
+
InvalidDimension = "RTX3003",
|
|
72
|
+
MissingRequiredField = "RTX3004",
|
|
73
|
+
UnknownField = "RTX3005",
|
|
74
|
+
EmptyArgument = "RTX3006",
|
|
75
|
+
CommandOutsideContext = "RTX4001",
|
|
76
|
+
UnknownIcon = "RTX4002",
|
|
77
|
+
UnknownThemeColor = "RTX4003",
|
|
78
|
+
UnknownLibrary = "RTX4004",
|
|
79
|
+
LibraryRequired = "RTX4005",
|
|
80
|
+
UnsafeUrlBlocked = "RTX5001"
|
|
81
|
+
}
|
|
82
|
+
/** Optional quick-fix an editor can apply. */
|
|
83
|
+
interface QuickFix {
|
|
84
|
+
title: string;
|
|
85
|
+
/** Replacement text for {@link Diagnostic.range}. */
|
|
86
|
+
replacement: string;
|
|
87
|
+
range?: SourceRange;
|
|
88
|
+
}
|
|
89
|
+
/** A single diagnostic emitted by any stage of the pipeline. */
|
|
90
|
+
interface Diagnostic {
|
|
91
|
+
severity: DiagnosticSeverity;
|
|
92
|
+
code: DiagnosticCode;
|
|
93
|
+
message: string;
|
|
94
|
+
range: SourceRange;
|
|
95
|
+
/** Stage that produced the diagnostic, for filtering. */
|
|
96
|
+
source: "tokenizer" | "parser" | "validator" | "security";
|
|
97
|
+
/** Optional editor quick-fixes. */
|
|
98
|
+
fixes?: QuickFix[];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* How a single argument should be consumed by the parser.
|
|
103
|
+
*
|
|
104
|
+
* - `content` — recursively parse markup (nested commands, text).
|
|
105
|
+
* - `string` — verbatim text; no command expansion (URLs, colors, sizes).
|
|
106
|
+
* - `keyval` — `key=value, key=value` map.
|
|
107
|
+
* - `list` — comma-separated list of trimmed strings.
|
|
108
|
+
*/
|
|
109
|
+
type ArgKind = "content" | "string" | "keyval" | "list";
|
|
110
|
+
interface ArgSpec {
|
|
111
|
+
kind: ArgKind;
|
|
112
|
+
/** When true the argument may be absent (no diagnostic if missing). */
|
|
113
|
+
optional?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Delimiter pair. `"brace"` (default) → `{...}`; `"bracket"` → `[...]`.
|
|
116
|
+
* An optional brace argument (e.g. an entry body) is still written with
|
|
117
|
+
* `{...}` but may be omitted.
|
|
118
|
+
*/
|
|
119
|
+
delimiter?: "brace" | "bracket";
|
|
120
|
+
/** Human-readable name surfaced in hover docs / diagnostics. */
|
|
121
|
+
name?: string;
|
|
122
|
+
/** Validation hint for `string` args (drives format checks). */
|
|
123
|
+
format?: "color" | "url" | "dimension" | "text";
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Semantic category of a command. Drives default rendering and where the
|
|
127
|
+
* command is legal.
|
|
128
|
+
*
|
|
129
|
+
* - `inline` — flows within text (`\textbf`).
|
|
130
|
+
* - `block` — starts a block (`\section`, `\job`).
|
|
131
|
+
* - `switch` — a state switch that applies to the rest of its group
|
|
132
|
+
* (`\large`, `\bfseries`-style).
|
|
133
|
+
* - `meta` — document metadata that produces no inline flow on its own.
|
|
134
|
+
*/
|
|
135
|
+
type CommandCategory = "inline" | "block" | "switch" | "meta";
|
|
136
|
+
/**
|
|
137
|
+
* A factory the parser calls once arguments are consumed, to build the AST
|
|
138
|
+
* node for a command. Returning `null` drops the command from the tree.
|
|
139
|
+
*/
|
|
140
|
+
type NodeBuilder = (ctx: BuildContext) => Node | Node[] | null;
|
|
141
|
+
interface BuildContext {
|
|
142
|
+
name: string;
|
|
143
|
+
args: ArgumentNode[];
|
|
144
|
+
/** For switches: the trailing content the switch applies to. */
|
|
145
|
+
scope: Node[];
|
|
146
|
+
/** Emit a diagnostic from within a builder. */
|
|
147
|
+
report: (d: Omit<Diagnostic, "source">) => void;
|
|
148
|
+
/** Utilities exposed to plugin authors. */
|
|
149
|
+
utils: BuilderUtils;
|
|
150
|
+
}
|
|
151
|
+
interface BuilderUtils {
|
|
152
|
+
/** Flatten an argument's children into a plain string (best-effort). */
|
|
153
|
+
textOf(arg: ArgumentNode | undefined): string;
|
|
154
|
+
/** Sanitize a URL; returns `"#"` (and reports) when unsafe. */
|
|
155
|
+
safeUrl(url: string): string;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The contract for a command. Used by the parser (argument signature, scope
|
|
159
|
+
* behavior) and the renderers (when no native node exists, renderers consult
|
|
160
|
+
* the command's per-target `render` map).
|
|
161
|
+
*/
|
|
162
|
+
interface CommandDefinition {
|
|
163
|
+
name: string;
|
|
164
|
+
category?: CommandCategory;
|
|
165
|
+
/** Argument signature, in order. */
|
|
166
|
+
args?: ArgSpec[];
|
|
167
|
+
/**
|
|
168
|
+
* `true` for switches that swallow the remainder of their enclosing group
|
|
169
|
+
* as scoped content (`\large`, `\itshape`).
|
|
170
|
+
*/
|
|
171
|
+
scoped?: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Builds the AST node. When omitted, the parser emits a generic
|
|
174
|
+
* {@link CommandNode} carrying the parsed arguments.
|
|
175
|
+
*/
|
|
176
|
+
build?: NodeBuilder;
|
|
177
|
+
/** One-line summary for hover docs / completion detail. */
|
|
178
|
+
summary?: string;
|
|
179
|
+
/** Longer documentation (markdown) for hover. */
|
|
180
|
+
documentation?: string;
|
|
181
|
+
/** Example snippet shown in completion / hover. */
|
|
182
|
+
example?: string;
|
|
183
|
+
}
|
|
184
|
+
/** Environment (`\begin{x} … \end{x}`) contract. */
|
|
185
|
+
interface EnvironmentDefinition {
|
|
186
|
+
name: string;
|
|
187
|
+
/**
|
|
188
|
+
* Command that introduces each entry inside the environment, e.g. `item`
|
|
189
|
+
* for `itemize`, `column` for `columns`. The parser uses this to slice
|
|
190
|
+
* the body into entries.
|
|
191
|
+
*/
|
|
192
|
+
itemCommand?: string;
|
|
193
|
+
/** Commands legal as direct children (for validation). `*` allows any. */
|
|
194
|
+
allowedChildren?: string[];
|
|
195
|
+
/** Build the environment node from its parsed body. */
|
|
196
|
+
build?: (ctx: EnvBuildContext) => Node | Node[] | null;
|
|
197
|
+
summary?: string;
|
|
198
|
+
documentation?: string;
|
|
199
|
+
example?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* One entry of an `itemCommand`-delimited environment. For `itemize`, the
|
|
203
|
+
* marker command is `\item`; for `columns`, it is `\column{width}`.
|
|
204
|
+
*/
|
|
205
|
+
interface EnvEntry {
|
|
206
|
+
/** The marker command that introduced the entry, with its parsed arguments. */
|
|
207
|
+
marker: CommandNode;
|
|
208
|
+
/** Content nodes belonging to this entry (up to the next marker / `\end`). */
|
|
209
|
+
content: Node[];
|
|
210
|
+
}
|
|
211
|
+
interface EnvBuildContext {
|
|
212
|
+
name: string;
|
|
213
|
+
/** Parsed body nodes of the environment (always present). */
|
|
214
|
+
body: Node[];
|
|
215
|
+
/**
|
|
216
|
+
* When the environment declares an `itemCommand`, the body sliced into
|
|
217
|
+
* entries at each marker. `undefined` for plain block environments.
|
|
218
|
+
*/
|
|
219
|
+
entries?: EnvEntry[];
|
|
220
|
+
/** Optional `[...]` arguments after `\begin{env}`. */
|
|
221
|
+
options: ArgumentNode[];
|
|
222
|
+
report: (d: Omit<Diagnostic, "source">) => void;
|
|
223
|
+
utils: BuilderUtils;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* The command/environment registry. The parser consults it for argument
|
|
228
|
+
* signatures and node builders; the plugin system mutates it. A registry can
|
|
229
|
+
* be cloned cheaply so an engine instance never mutates shared global state.
|
|
230
|
+
*/
|
|
231
|
+
declare class CommandRegistry {
|
|
232
|
+
private commands;
|
|
233
|
+
private environments;
|
|
234
|
+
registerCommand(def: CommandDefinition): this;
|
|
235
|
+
registerEnvironment(def: EnvironmentDefinition): this;
|
|
236
|
+
getCommand(name: string): CommandDefinition | undefined;
|
|
237
|
+
getEnvironment(name: string): EnvironmentDefinition | undefined;
|
|
238
|
+
hasCommand(name: string): boolean;
|
|
239
|
+
hasEnvironment(name: string): boolean;
|
|
240
|
+
commandNames(): string[];
|
|
241
|
+
environmentNames(): string[];
|
|
242
|
+
allCommands(): CommandDefinition[];
|
|
243
|
+
allEnvironments(): EnvironmentDefinition[];
|
|
244
|
+
/** Shallow-clone the registry (definitions are shared, maps are copied). */
|
|
245
|
+
clone(): CommandRegistry;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Icon registry. Icons are stored as the inner markup of a `0 0 24 24` SVG and
|
|
250
|
+
* use `currentColor` so they inherit surrounding text color. The set is
|
|
251
|
+
* intentionally small and extensible via {@link registerIcon} / plugins.
|
|
252
|
+
*
|
|
253
|
+
* Glyphs are simplified, original representations (not vendor logo artwork) so
|
|
254
|
+
* the package carries no third-party asset licensing.
|
|
255
|
+
*/
|
|
256
|
+
interface IconDefinition {
|
|
257
|
+
/** Inner SVG markup (paths/shapes) with a `0 0 24 24` viewBox. */
|
|
258
|
+
body: string;
|
|
259
|
+
/** Whether shapes are stroked (true) or filled (false). */
|
|
260
|
+
stroked?: boolean;
|
|
261
|
+
/** Aliases that resolve to this icon. */
|
|
262
|
+
aliases?: string[];
|
|
263
|
+
}
|
|
264
|
+
/** Resolve a (possibly aliased) icon name to its canonical key. */
|
|
265
|
+
declare function resolveIconName(name: string): string | undefined;
|
|
266
|
+
declare function hasIcon(name: string): boolean;
|
|
267
|
+
declare function getIcon(name: string): IconDefinition | undefined;
|
|
268
|
+
/** Register (or override) an icon at runtime. Used by plugins. */
|
|
269
|
+
declare function registerIcon(name: string, def: IconDefinition): void;
|
|
270
|
+
/** All canonical icon names, for completion / docs. */
|
|
271
|
+
declare function iconNames(): string[];
|
|
272
|
+
/**
|
|
273
|
+
* Render an icon to an inline SVG string. Returns `null` for unknown icons so
|
|
274
|
+
* callers can emit a diagnostic and a graceful fallback.
|
|
275
|
+
*/
|
|
276
|
+
declare function iconToSvg(name: string, opts?: {
|
|
277
|
+
size?: number | string;
|
|
278
|
+
className?: string;
|
|
279
|
+
}): string | null;
|
|
280
|
+
|
|
281
|
+
/** Node types that participate in block (vertical) flow. */
|
|
282
|
+
declare const BLOCK_TYPES: Set<string>;
|
|
283
|
+
declare function isBlockNode(node: Node): boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Plugin HTML renderer. Receives the node, the active context, and a callback
|
|
286
|
+
* to recursively render child nodes to HTML.
|
|
287
|
+
*/
|
|
288
|
+
type HtmlRenderFn = (node: Node, ctx: HtmlRenderContext, renderChildren: (nodes: Node[]) => string) => string;
|
|
289
|
+
interface HtmlRenderContext {
|
|
290
|
+
theme: Theme;
|
|
291
|
+
classPrefix: string;
|
|
292
|
+
/** Override renderers keyed by node `type` or `command:<name>`. */
|
|
293
|
+
overrides: Map<string, HtmlRenderFn>;
|
|
294
|
+
/** Render arbitrary inline/block nodes to an HTML string. */
|
|
295
|
+
renderNodes: (nodes: Node[]) => string;
|
|
296
|
+
cls: (name: string) => string;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* A command definition extended with optional per-target render functions.
|
|
301
|
+
* Passing `render.html` is shorthand for registering an HTML override keyed by
|
|
302
|
+
* `command:<name>` — the common case for a plugin command with no custom AST
|
|
303
|
+
* node (e.g. `\badge{...}`).
|
|
304
|
+
*/
|
|
305
|
+
interface EngineCommand extends CommandDefinition {
|
|
306
|
+
render?: {
|
|
307
|
+
html?: HtmlRenderFn;
|
|
308
|
+
react?: ReactRenderFn;
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* A ReTeX plugin. Everything is optional; a plugin may contribute commands,
|
|
313
|
+
* environments, icons, renderers, theme overrides, or run arbitrary setup
|
|
314
|
+
* against the engine. Plugins never touch global state — they mutate only the
|
|
315
|
+
* engine instance they are installed on.
|
|
316
|
+
*/
|
|
317
|
+
interface ReTeXPlugin {
|
|
318
|
+
name: string;
|
|
319
|
+
commands?: EngineCommand[];
|
|
320
|
+
environments?: EnvironmentDefinition[];
|
|
321
|
+
icons?: Record<string, IconDefinition>;
|
|
322
|
+
/** HTML overrides keyed by node `type` or `command:<name>`. */
|
|
323
|
+
htmlRenderers?: Record<string, HtmlRenderFn>;
|
|
324
|
+
/** React overrides keyed by node `type` or `command:<name>`. */
|
|
325
|
+
reactRenderers?: Record<string, ReactRenderFn>;
|
|
326
|
+
/** A theme patch applied when the plugin is installed. */
|
|
327
|
+
theme?: PartialTheme;
|
|
328
|
+
/** Imperative hook for advanced setup. */
|
|
329
|
+
setup?: (engine: PluginHost) => void;
|
|
330
|
+
}
|
|
331
|
+
/** The subset of the engine surface a plugin's `setup` hook may use. */
|
|
332
|
+
interface PluginHost {
|
|
333
|
+
registerCommand(def: EngineCommand): PluginHost;
|
|
334
|
+
registerEnvironment(def: EnvironmentDefinition): PluginHost;
|
|
335
|
+
registerHtmlRenderer(key: string, fn: HtmlRenderFn): PluginHost;
|
|
336
|
+
registerReactRenderer(key: string, fn: ReactRenderFn): PluginHost;
|
|
337
|
+
registerIcon(name: string, def: IconDefinition): PluginHost;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* A ReTeX **library** — a named, opt-in bundle of styling capability.
|
|
342
|
+
*
|
|
343
|
+
* ReTeX's core is deliberately blank: it ships document structure and basic
|
|
344
|
+
* emphasis only. Libraries add the rest. A library is just a {@link ReTeXPlugin}
|
|
345
|
+
* with a stable `name` so it can be activated two ways:
|
|
346
|
+
*
|
|
347
|
+
* - declaratively, from the document: `\usepackage{colors}`
|
|
348
|
+
* - programmatically, from code: `engine.use(colorsLibrary)`
|
|
349
|
+
*
|
|
350
|
+
* Built-in libraries: `fonts`, `shapes`, `colors`, and the theme packs `modern`,
|
|
351
|
+
* `classic`, `compact`. Custom libraries can be registered with
|
|
352
|
+
* `engine.provideLibrary(lib)` (available to `\usepackage`) or installed
|
|
353
|
+
* globally with `engine.use(lib)`.
|
|
354
|
+
*/
|
|
355
|
+
interface ReTeXLibrary extends ReTeXPlugin {
|
|
356
|
+
name: string;
|
|
357
|
+
/** One-line description, surfaced in docs and diagnostics. */
|
|
358
|
+
summary?: string;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Commands provided by the `colors` library: `\textcolor` (an explicit
|
|
363
|
+
* hex/named color) and `\themecolor` (a swatch from the active theme). Both
|
|
364
|
+
* produce core AST nodes, so the standard renderers display them once the
|
|
365
|
+
* library is active.
|
|
366
|
+
*/
|
|
367
|
+
declare const colorCommands: CommandDefinition[];
|
|
368
|
+
/**
|
|
369
|
+
* A catalog of ready-made color palettes. Apply one as a theme patch, e.g.
|
|
370
|
+
* `new ReTeXEngine({ theme: { colors: palettes.violet } })`, or reference its
|
|
371
|
+
* swatches from `\themecolor{...}` once `colors` is active.
|
|
372
|
+
*/
|
|
373
|
+
declare const palettes: Record<string, ThemeColors>;
|
|
374
|
+
/**
|
|
375
|
+
* The `colors` library — text color commands plus a palette catalog.
|
|
376
|
+
*
|
|
377
|
+
* ```ts
|
|
378
|
+
* engine.use(colorsLibrary); // or \usepackage{colors}
|
|
379
|
+
* engine.toHtml("\\textcolor{#7c3aed}{Hi}");
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
declare const colorsLibrary: ReTeXLibrary;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Commands provided by the `fonts` library: explicit family/size control
|
|
386
|
+
* (`\fontfamily`, `\fontsize`), the relative size switches (`\small`, `\large`,
|
|
387
|
+
* `\Large`, `\Huge`, `\normalsize`), and the monospace switch (`\ttfamily`).
|
|
388
|
+
*/
|
|
389
|
+
declare const fontCommands: CommandDefinition[];
|
|
390
|
+
/**
|
|
391
|
+
* A catalog of vetted font stacks. Use a key as a `\fontfamily` argument, or
|
|
392
|
+
* build a `fonts` theme patch with {@link fontTheme}.
|
|
393
|
+
*/
|
|
394
|
+
declare const fontStacks: Record<string, string>;
|
|
395
|
+
/**
|
|
396
|
+
* Build a `fonts` theme patch from named {@link fontStacks} (or raw CSS stacks).
|
|
397
|
+
*
|
|
398
|
+
* ```ts
|
|
399
|
+
* new ReTeXEngine({ theme: { fonts: fontTheme({ heading: "spaceGrotesk", body: "inter" }) } });
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
declare function fontTheme(spec: Partial<Record<keyof ThemeFonts, string>>): ThemeFonts;
|
|
403
|
+
/**
|
|
404
|
+
* The `fonts` library — font family/size control plus a stack catalog.
|
|
405
|
+
*
|
|
406
|
+
* ```ts
|
|
407
|
+
* engine.use(fontsLibrary); // or \usepackage{fonts}
|
|
408
|
+
* engine.toHtml("{\\large \\fontfamily{Georgia}{Hi}}");
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
declare const fontsLibrary: ReTeXLibrary;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Commands provided by the `shapes` library: horizontal rules / dividers in a
|
|
415
|
+
* few styles, plus explicit spacing. All produce core AST nodes.
|
|
416
|
+
*/
|
|
417
|
+
declare const shapeCommands: CommandDefinition[];
|
|
418
|
+
/**
|
|
419
|
+
* The `shapes` library — rules, dividers, and spacing.
|
|
420
|
+
*
|
|
421
|
+
* ```ts
|
|
422
|
+
* engine.use(shapesLibrary); // or \usepackage{shapes}
|
|
423
|
+
* engine.toHtml("\\hrule \\dashrule \\vspace{1em}");
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
declare const shapesLibrary: ReTeXLibrary;
|
|
427
|
+
|
|
428
|
+
/** `\usepackage{modern}` — accent-forward look with underlined headings. */
|
|
429
|
+
declare const modernLibrary: ReTeXLibrary;
|
|
430
|
+
/** `\usepackage{classic}` — restrained serif look for academic CVs. */
|
|
431
|
+
declare const classicLibrary: ReTeXLibrary;
|
|
432
|
+
/** `\usepackage{compact}` — dense, single-accent look. */
|
|
433
|
+
declare const compactLibrary: ReTeXLibrary;
|
|
434
|
+
|
|
435
|
+
/** Built-in libraries, keyed by their canonical (lowercase) name. */
|
|
436
|
+
declare const builtinLibraries: Record<string, ReTeXLibrary>;
|
|
437
|
+
/** Resolve a (possibly aliased / differently-cased) library name. */
|
|
438
|
+
declare function resolveLibraryName(name: string): string | undefined;
|
|
439
|
+
/** Look up a built-in library by name (accepts aliases). */
|
|
440
|
+
declare function getBuiltinLibrary(name: string): ReTeXLibrary | undefined;
|
|
441
|
+
/** All built-in library names, for docs / completion. */
|
|
442
|
+
declare function builtinLibraryNames(): string[];
|
|
443
|
+
/**
|
|
444
|
+
* Map of every gated command name → the library that provides it. Powers the
|
|
445
|
+
* "‹\textcolor› requires \usepackage{colors}" diagnostic. Derived from the
|
|
446
|
+
* library command lists so it can never drift out of sync.
|
|
447
|
+
*/
|
|
448
|
+
declare const GATED_COMMANDS: Record<string, string>;
|
|
449
|
+
/** A resolver from a library name to a library object. */
|
|
450
|
+
type LibraryLookup = (name: string) => ReTeXLibrary | undefined;
|
|
451
|
+
/**
|
|
452
|
+
* Scan a token stream for `\usepackage{...}` / `\use{...}` directives and return
|
|
453
|
+
* the requested library names (in source order, de-duplicated). Used to decide
|
|
454
|
+
* which libraries to activate *before* parsing, since a directive must enable
|
|
455
|
+
* the commands that follow it.
|
|
456
|
+
*/
|
|
457
|
+
declare function usedLibraryNamesFromTokens(tokens: Token[]): string[];
|
|
458
|
+
/** Collect library names from `\usepackage` nodes in a parsed document. */
|
|
459
|
+
declare function usedLibraryNamesFromAst(root: Node): string[];
|
|
460
|
+
interface AppliedLibraries {
|
|
461
|
+
/** A clone of the base registry with the resolved libraries' commands added. */
|
|
462
|
+
registry: CommandRegistry;
|
|
463
|
+
/** The libraries that resolved successfully, in order. */
|
|
464
|
+
libraries: ReTeXLibrary[];
|
|
465
|
+
/** Requested names that did not resolve to any library. */
|
|
466
|
+
missing: string[];
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Clone `base` and register the commands/environments of every requested
|
|
470
|
+
* library that resolves via `lookup` (built-ins by default). Never mutates the
|
|
471
|
+
* base registry.
|
|
472
|
+
*/
|
|
473
|
+
declare function applyLibraries(base: CommandRegistry, names: string[], lookup?: LibraryLookup): AppliedLibraries;
|
|
474
|
+
/** Fold each library's theme patch over a base theme, in order. */
|
|
475
|
+
declare function mergeLibraryTheme(base: Theme, libraries: ReTeXLibrary[]): Theme;
|
|
476
|
+
/**
|
|
477
|
+
* Refine a diagnostic list with library-awareness:
|
|
478
|
+
*
|
|
479
|
+
* 1. Replace the generic "unknown command" diagnostic for a *gated* command
|
|
480
|
+
* (one that lives in a library) with a clear "import the library" message.
|
|
481
|
+
* 2. Flag unknown library names in `\usepackage{...}` directives.
|
|
482
|
+
*
|
|
483
|
+
* Shared by the engine and the editor so both give identical guidance.
|
|
484
|
+
*/
|
|
485
|
+
declare function libraryDiagnostics(ast: DocumentNode, diagnostics: Diagnostic[], lookup?: LibraryLookup): Diagnostic[];
|
|
486
|
+
/** Collect HTML/React render overrides contributed by a set of libraries. */
|
|
487
|
+
declare function collectLibraryOverrides(libraries: ReTeXLibrary[]): {
|
|
488
|
+
html: Map<string, HtmlRenderFn>;
|
|
489
|
+
react: Map<string, ReactRenderFn>;
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
export { resolveLibraryName as $, type AppliedLibraries as A, BLOCK_TYPES as B, CommandRegistry as C, type Diagnostic as D, type EngineCommand as E, getBuiltinLibrary as F, GATED_COMMANDS as G, type HtmlRenderFn as H, type IconDefinition as I, getIcon as J, hasIcon as K, type LibraryLookup as L, iconNames as M, type NodeBuilder as N, iconToSvg as O, type PluginHost as P, type QuickFix as Q, type ReTeXPlugin as R, SPECIAL_CHARS as S, type Token as T, isBlockNode as U, libraryDiagnostics as V, mergeLibraryTheme as W, modernLibrary as X, palettes as Y, registerIcon as Z, resolveIconName as _, type ReTeXLibrary as a, shapeCommands as a0, shapesLibrary as a1, usedLibraryNamesFromAst as a2, usedLibraryNamesFromTokens as a3, type EnvironmentDefinition as b, type ArgKind as c, type ArgSpec as d, type BuildContext as e, type BuilderUtils as f, type CommandCategory as g, type CommandDefinition as h, DiagnosticCode as i, DiagnosticSeverity as j, type EnvBuildContext as k, type EnvEntry as l, type HtmlRenderContext as m, TokenType as n, applyLibraries as o, builtinLibraries as p, builtinLibraryNames as q, classicLibrary as r, collectLibraryOverrides as s, colorCommands as t, colorsLibrary as u, compactLibrary as v, fontCommands as w, fontStacks as x, fontTheme as y, fontsLibrary as z };
|