@danxbot/ui 1.0.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.
Files changed (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +126 -0
  3. package/dist/fonts/bricolage-grotesque-0.woff2 +0 -0
  4. package/dist/fonts/bricolage-grotesque-1.woff2 +0 -0
  5. package/dist/fonts/bricolage-grotesque-2.woff2 +0 -0
  6. package/dist/fonts/figtree-0.woff2 +0 -0
  7. package/dist/fonts/figtree-1.woff2 +0 -0
  8. package/dist/fonts/figtree-2.woff2 +0 -0
  9. package/dist/fonts/figtree-3.woff2 +0 -0
  10. package/dist/fonts/jetbrains-mono-0.woff2 +0 -0
  11. package/dist/fonts/jetbrains-mono-1.woff2 +0 -0
  12. package/dist/fonts/jetbrains-mono-10.woff2 +0 -0
  13. package/dist/fonts/jetbrains-mono-11.woff2 +0 -0
  14. package/dist/fonts/jetbrains-mono-2.woff2 +0 -0
  15. package/dist/fonts/jetbrains-mono-3.woff2 +0 -0
  16. package/dist/fonts/jetbrains-mono-4.woff2 +0 -0
  17. package/dist/fonts/jetbrains-mono-5.woff2 +0 -0
  18. package/dist/fonts/jetbrains-mono-6.woff2 +0 -0
  19. package/dist/fonts/jetbrains-mono-7.woff2 +0 -0
  20. package/dist/fonts/jetbrains-mono-8.woff2 +0 -0
  21. package/dist/fonts/jetbrains-mono-9.woff2 +0 -0
  22. package/dist/fonts.css +187 -0
  23. package/dist/index.js +42425 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/styles.css +190 -0
  26. package/dist/types/components/Accordion.d.ts +15 -0
  27. package/dist/types/components/AppShell.d.ts +58 -0
  28. package/dist/types/components/Avatar.d.ts +154 -0
  29. package/dist/types/components/Badge.d.ts +73 -0
  30. package/dist/types/components/Button.d.ts +103 -0
  31. package/dist/types/components/Card.d.ts +193 -0
  32. package/dist/types/components/Choice.d.ts +112 -0
  33. package/dist/types/components/CodeEditor.d.ts +86 -0
  34. package/dist/types/components/Combobox.d.ts +37 -0
  35. package/dist/types/components/CommandPalette.d.ts +33 -0
  36. package/dist/types/components/DatePicker.d.ts +20 -0
  37. package/dist/types/components/Dialog.d.ts +117 -0
  38. package/dist/types/components/DragDrop.d.ts +60 -0
  39. package/dist/types/components/ErrorBoundary.d.ts +16 -0
  40. package/dist/types/components/Field.d.ts +37 -0
  41. package/dist/types/components/FileUpload.d.ts +22 -0
  42. package/dist/types/components/Icon.d.ts +40 -0
  43. package/dist/types/components/Input.d.ts +120 -0
  44. package/dist/types/components/Loading.d.ts +83 -0
  45. package/dist/types/components/MarkdownEditor.d.ts +24 -0
  46. package/dist/types/components/Menu.d.ts +57 -0
  47. package/dist/types/components/Navigation.d.ts +46 -0
  48. package/dist/types/components/NumberInput.d.ts +88 -0
  49. package/dist/types/components/OTPInput.d.ts +11 -0
  50. package/dist/types/components/Panel.d.ts +94 -0
  51. package/dist/types/components/Popover.d.ts +64 -0
  52. package/dist/types/components/Progress.d.ts +178 -0
  53. package/dist/types/components/Select.d.ts +53 -0
  54. package/dist/types/components/Slider.d.ts +203 -0
  55. package/dist/types/components/Spinner.d.ts +29 -0
  56. package/dist/types/components/Stat.d.ts +98 -0
  57. package/dist/types/components/StatusSelect.d.ts +23 -0
  58. package/dist/types/components/Surface.d.ts +110 -0
  59. package/dist/types/components/Table.d.ts +46 -0
  60. package/dist/types/components/Tabs.d.ts +84 -0
  61. package/dist/types/components/ThemeMenu.d.ts +4 -0
  62. package/dist/types/components/Toast.d.ts +46 -0
  63. package/dist/types/components/Toggle.d.ts +65 -0
  64. package/dist/types/components/Tree.d.ts +20 -0
  65. package/dist/types/components/calendar/CalendarMonth.d.ts +33 -0
  66. package/dist/types/components/calendar/CalendarTimeGrid.d.ts +75 -0
  67. package/dist/types/components/calendar/EventActions.d.ts +17 -0
  68. package/dist/types/components/calendar/format.d.ts +43 -0
  69. package/dist/types/components/calendar/index.d.ts +9 -0
  70. package/dist/types/components/calendar/palette.d.ts +17 -0
  71. package/dist/types/components/calendar/use-calendar-drag.d.ts +54 -0
  72. package/dist/types/components/calendar/use-event-keyboard.d.ts +24 -0
  73. package/dist/types/components/calendar/use-grid-navigation.d.ts +47 -0
  74. package/dist/types/components/calendar/use-now.d.ts +20 -0
  75. package/dist/types/components/chat/Attachment.d.ts +49 -0
  76. package/dist/types/components/chat/Chat.d.ts +60 -0
  77. package/dist/types/components/chat/Composer.d.ts +29 -0
  78. package/dist/types/components/chat/ContextMeter.d.ts +55 -0
  79. package/dist/types/components/chat/EffortControl.d.ts +23 -0
  80. package/dist/types/components/chat/Markdown.d.ts +22 -0
  81. package/dist/types/components/chat/Message.d.ts +59 -0
  82. package/dist/types/components/chat/MessageScroller.d.ts +13 -0
  83. package/dist/types/components/chat/ModelSelector.d.ts +44 -0
  84. package/dist/types/components/chat/types.d.ts +155 -0
  85. package/dist/types/components/code-editor/context.d.ts +32 -0
  86. package/dist/types/components/code-editor/editing.d.ts +39 -0
  87. package/dist/types/components/code-editor/highlight.d.ts +20 -0
  88. package/dist/types/components/code-editor/recipe.d.ts +109 -0
  89. package/dist/types/components/code-editor/state.d.ts +14 -0
  90. package/dist/types/components/drag-drop/context.d.ts +45 -0
  91. package/dist/types/components/drag-drop/recipe.d.ts +121 -0
  92. package/dist/types/components/drag-drop/shift.d.ts +66 -0
  93. package/dist/types/components/markdown/Affordances.d.ts +76 -0
  94. package/dist/types/components/rbac/AccountMenu.d.ts +8 -0
  95. package/dist/types/components/rbac/DevToolsPopover.d.ts +5 -0
  96. package/dist/types/components/rbac/ProfilePage.d.ts +1 -0
  97. package/dist/types/components/rbac/RBACProvider.d.ts +64 -0
  98. package/dist/types/components/rbac/RolePermissionMatrix.d.ts +6 -0
  99. package/dist/types/components/rbac/RolesPermissionsPage.d.ts +1 -0
  100. package/dist/types/components/rbac/index.d.ts +7 -0
  101. package/dist/types/components/rbac/types.d.ts +26 -0
  102. package/dist/types/components/roadmap/PhaseManager.d.ts +19 -0
  103. package/dist/types/components/roadmap/RoadmapItemCard.d.ts +45 -0
  104. package/dist/types/components/roadmap/RoadmapPage.d.ts +9 -0
  105. package/dist/types/components/roadmap/RoadmapSwimlaneBoard.d.ts +9 -0
  106. package/dist/types/components/roadmap/UseCaseCard.d.ts +14 -0
  107. package/dist/types/components/roadmap/UseCaseLedgerPage.d.ts +21 -0
  108. package/dist/types/components/roadmap/chip-tones.d.ts +2 -0
  109. package/dist/types/components/roadmap/derive.d.ts +12 -0
  110. package/dist/types/components/roadmap/index.d.ts +9 -0
  111. package/dist/types/components/roadmap/types.d.ts +54 -0
  112. package/dist/types/icons/data.d.ts +1318 -0
  113. package/dist/types/index.d.ts +97 -0
  114. package/dist/types/lib/calendar/band-packer.d.ts +53 -0
  115. package/dist/types/lib/calendar/drag.d.ts +125 -0
  116. package/dist/types/lib/calendar/index.d.ts +4 -0
  117. package/dist/types/lib/calendar/lane-packer.d.ts +88 -0
  118. package/dist/types/lib/calendar/segments.d.ts +91 -0
  119. package/dist/types/lib/calendar/types.d.ts +166 -0
  120. package/dist/types/lib/cn.d.ts +7 -0
  121. package/dist/types/lib/dnd/announce.d.ts +132 -0
  122. package/dist/types/lib/dnd/autoscroll.d.ts +88 -0
  123. package/dist/types/lib/dnd/geometry.d.ts +78 -0
  124. package/dist/types/lib/dnd/index.d.ts +16 -0
  125. package/dist/types/lib/dnd/sensors/gesture.d.ts +37 -0
  126. package/dist/types/lib/dnd/sensors/keyboard.d.ts +50 -0
  127. package/dist/types/lib/dnd/sensors/pointer.d.ts +59 -0
  128. package/dist/types/lib/dnd/session.d.ts +99 -0
  129. package/dist/types/lib/dnd/types.d.ts +162 -0
  130. package/dist/types/lib/dnd/use-drag.d.ts +56 -0
  131. package/dist/types/lib/icons.d.ts +40 -0
  132. package/dist/types/lib/markdown/caret-map.d.ts +48 -0
  133. package/dist/types/lib/markdown/caret.d.ts +6 -0
  134. package/dist/types/lib/markdown/commands.d.ts +170 -0
  135. package/dist/types/lib/markdown/convert.d.ts +82 -0
  136. package/dist/types/lib/markdown/dom.d.ts +67 -0
  137. package/dist/types/lib/markdown/edit.d.ts +16 -0
  138. package/dist/types/lib/markdown/history.d.ts +47 -0
  139. package/dist/types/lib/markdown/hotkeys.d.ts +39 -0
  140. package/dist/types/lib/markdown/input.d.ts +15 -0
  141. package/dist/types/lib/markdown/keys.d.ts +34 -0
  142. package/dist/types/lib/markdown/paste.d.ts +9 -0
  143. package/dist/types/lib/markdown/position.d.ts +43 -0
  144. package/dist/types/lib/markdown/project.d.ts +88 -0
  145. package/dist/types/lib/markdown/reconcile.d.ts +63 -0
  146. package/dist/types/lib/markdown/surface.d.ts +177 -0
  147. package/dist/types/lib/persist.d.ts +40 -0
  148. package/dist/types/lib/preferences.d.ts +80 -0
  149. package/dist/types/lib/sim/createSimStore.d.ts +18 -0
  150. package/dist/types/lib/sim/index.d.ts +5 -0
  151. package/dist/types/lib/sim/latency.d.ts +10 -0
  152. package/dist/types/lib/sim/registry.d.ts +14 -0
  153. package/dist/types/lib/sim/settings.d.ts +11 -0
  154. package/dist/types/lib/sim/types.d.ts +3 -0
  155. package/dist/types/lib/syntax/index.d.ts +16 -0
  156. package/dist/types/lib/syntax/languages/bash.d.ts +1 -0
  157. package/dist/types/lib/syntax/languages/css.d.ts +1 -0
  158. package/dist/types/lib/syntax/languages/html.d.ts +17 -0
  159. package/dist/types/lib/syntax/languages/index.d.ts +33 -0
  160. package/dist/types/lib/syntax/languages/javascript.d.ts +22 -0
  161. package/dist/types/lib/syntax/languages/json.d.ts +1 -0
  162. package/dist/types/lib/syntax/languages/mongodb.d.ts +1 -0
  163. package/dist/types/lib/syntax/languages/plain.d.ts +9 -0
  164. package/dist/types/lib/syntax/languages/sql.d.ts +4 -0
  165. package/dist/types/lib/syntax/languages/vue.d.ts +1 -0
  166. package/dist/types/lib/syntax/languages/yaml.d.ts +1 -0
  167. package/dist/types/lib/syntax/markdown/frames.d.ts +145 -0
  168. package/dist/types/lib/syntax/markdown/grammar.d.ts +1 -0
  169. package/dist/types/lib/syntax/markdown/index.d.ts +4 -0
  170. package/dist/types/lib/syntax/markdown/inline.d.ts +21 -0
  171. package/dist/types/lib/syntax/markdown/parse.d.ts +11 -0
  172. package/dist/types/lib/syntax/markdown/render.d.ts +19 -0
  173. package/dist/types/lib/syntax/markdown/spans.d.ts +84 -0
  174. package/dist/types/lib/syntax/markdown/types.d.ts +108 -0
  175. package/dist/types/lib/syntax/registry.d.ts +37 -0
  176. package/dist/types/lib/syntax/tokenize.d.ts +17 -0
  177. package/dist/types/lib/syntax/types.d.ts +119 -0
  178. package/dist/types/lib/time/index.d.ts +3 -0
  179. package/dist/types/lib/time/plain.d.ts +61 -0
  180. package/dist/types/lib/time/types.d.ts +87 -0
  181. package/dist/types/lib/time/zone.d.ts +97 -0
  182. package/dist/types/lib/use-media-query.d.ts +29 -0
  183. package/package.json +130 -0
@@ -0,0 +1,10 @@
1
+ export declare class SimNetworkError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ /**
5
+ * Awaits a delay scaled to `recordsTouched` and the Dev popover's current
6
+ * network-speed setting. `Instant` returns immediately rather than awaiting a
7
+ * zero-length timer — the difference between "no perceptible delay" and
8
+ * "every store call pays for a microtask it gets nothing from."
9
+ */
10
+ export declare function simulateLatency(recordsTouched: number): Promise<void>;
@@ -0,0 +1,14 @@
1
+ import type { SimNamespace } from "./types";
2
+ interface RegisteredStore {
3
+ namespace: SimNamespace;
4
+ reset: () => Promise<void>;
5
+ }
6
+ /** Called once by `createSimStore` itself — not a public store-authoring API. */
7
+ export declare function registerSimStore(entry: RegisteredStore): () => void;
8
+ /**
9
+ * Resets every registered store in `namespace`, or every store at all when
10
+ * omitted. Resolves once every reset has actually written back to
11
+ * LocalStorage and notified its subscribers.
12
+ */
13
+ export declare function resetSimStores(namespace?: SimNamespace): Promise<void>;
14
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { DataSource, NetworkSpeed } from "./types";
2
+ export interface SimSettings {
3
+ networkSpeed: NetworkSpeed;
4
+ dataSource: DataSource;
5
+ }
6
+ export declare function useSimSettings(): SimSettings;
7
+ export declare function setSimSettings(patch: Partial<SimSettings>): void;
8
+ /** Read outside React — `latency.ts` needs the current speed synchronously,
9
+ inside a plain async function with no hook rules to follow. */
10
+ export declare function getNetworkSpeed(): NetworkSpeed;
11
+ export declare function getDataSource(): DataSource;
@@ -0,0 +1,3 @@
1
+ export type NetworkSpeed = "instant" | "fast" | "typical" | "flaky";
2
+ export type DataSource = "simulated" | "live";
3
+ export type SimNamespace = "demo" | "ledger";
@@ -0,0 +1,16 @@
1
+ import type { Grammar, Token } from "./types";
2
+ export declare function tokenize(source: string, language: string | null | undefined): Token[];
3
+ export declare function listLanguages(): string[];
4
+ export declare function resolveLanguage(alias: string | null | undefined): string | null;
5
+ export declare function getGrammar(name: string | null | undefined): Grammar | undefined;
6
+ /**
7
+ * Register a custom grammar.
8
+ *
9
+ * Seeds first, so a consumer registering `json` deliberately overrides the
10
+ * built-in rather than being silently overwritten by it on the next call that
11
+ * happens to seed.
12
+ */
13
+ export declare function registerGrammar(grammar: Grammar): void;
14
+ export { checkCoverage } from "./tokenize";
15
+ export { defineGrammar } from "./registry";
16
+ export type { Token, TokenType, Grammar, Rule, TokenizeContext } from "./types";
@@ -0,0 +1 @@
1
+ export declare const bash: import("..").Grammar;
@@ -0,0 +1 @@
1
+ export declare const css: import("..").Grammar;
@@ -0,0 +1,17 @@
1
+ import type { Rule } from "../types";
2
+ /** Reads one attribute out of the raw attribute run of an opening tag. */
3
+ export declare function attrValue(attrs: string, name: string): string | null;
4
+ /** The language a `<script>` block's attributes ask for. */
5
+ export declare function scriptLang(attrs: string): string;
6
+ /** The language a `<style>` block's attributes ask for. */
7
+ export declare function styleLang(attrs: string): string;
8
+ /**
9
+ * The tag-interior states, shared with the Vue grammar so a directive like
10
+ * `@click` or `:prop` is understood identically in both. Returned fresh per
11
+ * grammar — `defineGrammar` rewrites every pattern, so sharing rule OBJECTS
12
+ * between two grammars would work only by luck.
13
+ */
14
+ export declare function markupStates(): Record<string, Rule[]>;
15
+ /** The `<script>` / `<style>` embed rules, shared with Vue's own root. */
16
+ export declare function embedRules(scriptUntil: RegExp, styleUntil: RegExp): Rule[];
17
+ export declare const html: import("..").Grammar;
@@ -0,0 +1,33 @@
1
+ import type { Grammar } from "../types";
2
+ import { bash } from "./bash";
3
+ import { css } from "./css";
4
+ import { html } from "./html";
5
+ import { javascript, jsx, tsx, typescript } from "./javascript";
6
+ import { markdown } from "../markdown/grammar";
7
+ import { json } from "./json";
8
+ import { mongodb } from "./mongodb";
9
+ import { plain } from "./plain";
10
+ import { mysql, postgresql, sql } from "./sql";
11
+ import { vue } from "./vue";
12
+ import { yaml } from "./yaml";
13
+ /**
14
+ * Every grammar, as a VALUE. `src/lib/syntax/index.ts` iterates this list to
15
+ * seed the registry at module load.
16
+ *
17
+ * It is a list rather than each module registering itself on import, because
18
+ * `package.json` declares `sideEffects: ["*.css"]` — which tells every bundler
19
+ * that a bare `import "./javascript"` is safe to delete, and esbuild does. That
20
+ * is exactly how this project once shipped an empty icon registry (CAV-11).
21
+ *
22
+ * Order is not significant: an embedded language is resolved through
23
+ * `getGrammar` when the region is scanned, not when the grammar is defined, so
24
+ * `vue` may reference `css` regardless of which was registered first.
25
+ *
26
+ * Markdown is imported from its own module rather than its barrel: the barrel
27
+ * also exports the React renderer, and the tokenizer must stay usable without
28
+ * React in the graph.
29
+ *
30
+ * Adding a language: write the grammar, add it here. Nothing else.
31
+ */
32
+ export declare const LANGUAGES: Grammar[];
33
+ export { plain, json, yaml, markdown, javascript, typescript, jsx, tsx, html, css, sql, mysql, postgresql, mongodb, bash, vue };
@@ -0,0 +1,22 @@
1
+ import type { Rule } from "../types";
2
+ export interface JsFlavour {
3
+ /** TypeScript keywords and primitive type names. */
4
+ ts: boolean;
5
+ /** JSX element rules. See the JSX-IS-OPT-IN note above. */
6
+ jsx: boolean;
7
+ }
8
+ /**
9
+ * The complete state machine, rebuilt per grammar.
10
+ *
11
+ * A FUNCTION, NOT A SHARED CONSTANT: `defineGrammar` rewrites every pattern
12
+ * (sticky + hasIndices), and two grammars handing it the same rule objects
13
+ * would work only by accident. Fresh objects make that impossible to get wrong.
14
+ *
15
+ * `prefix` rules are spliced in ahead of everything else in the shared rule
16
+ * body, which is how MongoDB adds `$gte` without re-deriving JavaScript.
17
+ */
18
+ export declare function jsStates(flavour: JsFlavour, prefix?: Rule[]): Record<string, Rule[]>;
19
+ export declare const javascript: import("..").Grammar;
20
+ export declare const typescript: import("..").Grammar;
21
+ export declare const jsx: import("..").Grammar;
22
+ export declare const tsx: import("..").Grammar;
@@ -0,0 +1 @@
1
+ export declare const json: import("..").Grammar;
@@ -0,0 +1 @@
1
+ export declare const mongodb: import("..").Grammar;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The identity grammar: everything is text.
3
+ *
4
+ * It exists so "no highlighting" is a REGISTERED language rather than a missing
5
+ * one. A picker can offer it, a fence can name it, and the editor behaves
6
+ * identically — only the colours are absent. Without it, "plain" and "the
7
+ * language you asked for does not exist" would be indistinguishable states.
8
+ */
9
+ export declare const plain: import("..").Grammar;
@@ -0,0 +1,4 @@
1
+ import type { Grammar } from "../types";
2
+ export declare const sql: Grammar;
3
+ export declare const mysql: Grammar;
4
+ export declare const postgresql: Grammar;
@@ -0,0 +1 @@
1
+ export declare const vue: import("..").Grammar;
@@ -0,0 +1 @@
1
+ export declare const yaml: import("..").Grammar;
@@ -0,0 +1,145 @@
1
+ import type { MdAlign } from "./types";
2
+ /** An absolute source range. Half-open, like everything else here. */
3
+ export interface Range {
4
+ start: number;
5
+ end: number;
6
+ }
7
+ /**
8
+ * What a frame IS — everything the projector needs to build its element, and
9
+ * nothing about where it is. Position lives on the frame record, not here, so
10
+ * a frame description can be compared and tested without coordinates.
11
+ *
12
+ * These are deliberately FINER than `MdNode`. A table is one node and six frame
13
+ * kinds, because the pipes and the delimiter row have to land somewhere legal
14
+ * in a DOM table, and "somewhere legal" is a structural question the renderer's
15
+ * tree does not answer.
16
+ */
17
+ export type Frame = {
18
+ kind: "paragraph";
19
+ } | {
20
+ kind: "heading";
21
+ level: 1 | 2 | 3 | 4 | 5 | 6;
22
+ } | {
23
+ kind: "code";
24
+ language: string | null;
25
+ fenced: boolean;
26
+ open: boolean;
27
+ }
28
+ /**
29
+ * The code INSIDE a fence or an indent — the lines a reader would copy, and
30
+ * nothing else.
31
+ *
32
+ * EXISTS FOR THE SAME REASON THE QUOTE'S BAR MOVED OFF THE QUOTE. A block
33
+ * owns the newline that ends it (see `endBlock`), so the outer `code` frame
34
+ * necessarily extends one line past its last character. Anything drawn on
35
+ * that outer frame — a background, a padding box — therefore paints an empty
36
+ * fragment underneath the code, which reads as a stray tinted stub. The body
37
+ * frame stops at the last code character, so the block's decoration has
38
+ * somewhere to live that the terminator is not inside.
39
+ *
40
+ * It is also what finally makes `<pre><code>` honest here: the fence lines
41
+ * stay in the `<pre>` where they belong, and the `<code>` holds only code.
42
+ *
43
+ * It carries the LANGUAGE because it, not its parent, is the frame whose
44
+ * content is the code — so it is the one the projector hands to a syntax
45
+ * highlighter. Keying that off the outer frame was the first version, and it
46
+ * tokenized the block's terminating newline and nothing else.
47
+ */
48
+ | {
49
+ kind: "codeBody";
50
+ language: string | null;
51
+ } | {
52
+ kind: "quote";
53
+ } | {
54
+ kind: "list";
55
+ ordered: boolean;
56
+ start: number;
57
+ tight: boolean;
58
+ }
59
+ /**
60
+ * `marker` is the item's OWN marker text — `-`, `*`, `3.`, `7)`.
61
+ *
62
+ * Carried because the marker is collapsed markup, so the view has to draw
63
+ * something in its place, and a CSS counter would draw the wrong thing: a
64
+ * list that starts at 3 renumbers to 1, and a list the author numbered
65
+ * `1. 1. 1.` (which markdown allows, and which many people write) renumbers
66
+ * to 1, 2, 3. The rendered marker should be what the document says.
67
+ */
68
+ | {
69
+ kind: "listItem";
70
+ checked: boolean | null;
71
+ marker: string;
72
+ } | {
73
+ kind: "rule";
74
+ } | {
75
+ kind: "frontmatter";
76
+ language: string;
77
+ } | {
78
+ kind: "footnoteDef";
79
+ label: string;
80
+ } | {
81
+ kind: "linkDef";
82
+ } | {
83
+ kind: "table";
84
+ } | {
85
+ kind: "tableRow";
86
+ header: boolean;
87
+ } | {
88
+ kind: "tableCell";
89
+ header: boolean;
90
+ align: MdAlign | null;
91
+ }
92
+ /**
93
+ * A row's pipes and padding, and the whole delimiter row.
94
+ *
95
+ * EXISTS BECAUSE OF THE CARET CONTRACT, not for tidiness. Rule 1 says every
96
+ * source offset is a caret position, and a DOM table cannot hold text outside
97
+ * a cell — text placed directly in a `<tr>` gets an anonymous cell box the
98
+ * browser will not step into, which the arrow-key torture test caught as
99
+ * Right moving from offset 2 to offset 2. So the pipes get a cell of their
100
+ * own. It is hidden, not absent, which is the difference between a character
101
+ * the caret can reach and one it cannot.
102
+ */
103
+ | {
104
+ kind: "tableGutter";
105
+ } | {
106
+ kind: "tableDelimiter";
107
+ } | {
108
+ kind: "inline";
109
+ } | {
110
+ kind: "emphasis";
111
+ } | {
112
+ kind: "strong";
113
+ } | {
114
+ kind: "strike";
115
+ } | {
116
+ kind: "codeSpan";
117
+ } | {
118
+ kind: "link";
119
+ href: string;
120
+ title?: string;
121
+ } | {
122
+ kind: "image";
123
+ src: string;
124
+ alt: string;
125
+ title?: string;
126
+ } | {
127
+ kind: "autolink";
128
+ href: string;
129
+ } | {
130
+ kind: "footnoteRef";
131
+ label: string;
132
+ } | {
133
+ kind: "hardBreak";
134
+ };
135
+ export type FrameKind = Frame["kind"];
136
+ /** A frame as the projector receives it: what, where, and what it owns. */
137
+ export interface FrameRecord {
138
+ frame: Frame;
139
+ start: number;
140
+ end: number;
141
+ /** Absolute source ranges holding this frame's own text. Empty = opaque. */
142
+ content: readonly Range[];
143
+ /** Emission order, which breaks ties between two frames at the same offset. */
144
+ seq: number;
145
+ }
@@ -0,0 +1 @@
1
+ export declare const markdown: import("..").Grammar;
@@ -0,0 +1,4 @@
1
+ export { parseMarkdown } from "./parse";
2
+ export { markdown } from "./grammar";
3
+ export { MarkdownNodes, sanitizeHref } from "./render";
4
+ export type { MdNode, MdInline, MdListItem, MdCell, MdAlign, MdCodeRenderer } from "./types";
@@ -0,0 +1,21 @@
1
+ import type { TokenType } from "../types";
2
+ import { type Segments, type Sink } from "./spans";
3
+ import type { MdInline } from "./types";
4
+ export interface LinkRef {
5
+ href: string;
6
+ title?: string;
7
+ }
8
+ export type RefMap = ReadonlyMap<string, LinkRef>;
9
+ /**
10
+ * Parses the joined text of `seg` between `from` and `to`, reporting spans to
11
+ * `sink` and returning the tree.
12
+ *
13
+ * `ambient` is the token type unclaimed text takes — `text` in a paragraph,
14
+ * `heading` inside a heading, `quote` inside a blockquote. Constructs override
15
+ * it, so `` `code` `` in a heading still reads as code.
16
+ */
17
+ export declare function parseInline(seg: Segments, refs: RefMap, sink: Sink | undefined, ambient?: TokenType, from?: number, to?: number): MdInline[];
18
+ /** Reference labels are case-insensitive and whitespace-collapsed. */
19
+ export declare function normalizeRef(label: string): string;
20
+ /** Flattens a subtree to its text — an image's alt attribute takes no markup. */
21
+ export declare function plainText(nodes: MdInline[]): string;
@@ -0,0 +1,11 @@
1
+ import { type Sink } from "./spans";
2
+ import type { MdNode } from "./types";
3
+ /** The renderer's entry point: tree only, no token bookkeeping. */
4
+ export declare function parseMarkdown(source: string): MdNode[];
5
+ /**
6
+ * The shared entry point. `sink` is supplied only by the grammar; without it
7
+ * the span reporting compiles down to a handful of `undefined` checks.
8
+ */
9
+ export declare function parseDocument(source: string, sink?: Sink): MdNode[];
10
+ /** Heading anchors: lowercase, non-word runs to hyphens, trimmed. */
11
+ export declare function slug(text: string): string;
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from "react";
2
+ import type { MdCodeRenderer, MdNode } from "./types";
3
+ export interface MarkdownNodesProps {
4
+ nodes: MdNode[];
5
+ /** How a fenced block renders. Supplied by the consumer to avoid a cycle. */
6
+ renderCode: MdCodeRenderer;
7
+ }
8
+ export declare function MarkdownNodes({ nodes, renderCode }: MarkdownNodesProps): ReactNode;
9
+ /**
10
+ * RULE TWO, the implementation: a link's scheme is checked before it is
11
+ * rendered.
12
+ *
13
+ * `[click](javascript:fetch('/api/keys').then(…))` is a working attack against
14
+ * every renderer that passes href through untouched, and `data:text/html` is
15
+ * the same hole wearing a different scheme. Anything not on the allowed list
16
+ * returns null, and the caller renders the label as plain text rather than
17
+ * dropping it — silently swallowing it would hide the attempt.
18
+ */
19
+ export declare function sanitizeHref(href: string): string | null;
@@ -0,0 +1,84 @@
1
+ import type { TokenType } from "../types";
2
+ import type { Frame, Range } from "./frames";
3
+ /** A run of source text with the absolute offset of its first character. */
4
+ export interface Piece {
5
+ text: string;
6
+ start: number;
7
+ }
8
+ /**
9
+ * Pieces joined into one string for the inline scanner, plus the map back.
10
+ *
11
+ * The `"\n"` inserted BETWEEN pieces is synthetic — in the source those two
12
+ * lines may be separated by a newline plus a `> ` prefix, or by nothing at all.
13
+ * It is deliberately covered by no part, so a span crossing it maps to two
14
+ * source ranges and the prefix in between is left for the caller to have
15
+ * already claimed.
16
+ */
17
+ export interface Segments {
18
+ text: string;
19
+ parts: ReadonlyArray<{
20
+ ja: number;
21
+ jb: number;
22
+ sa: number;
23
+ }>;
24
+ }
25
+ export declare function makeSegments(pieces: Piece[]): Segments;
26
+ /** One line of prose is the common case; spelled out so callers do not build a
27
+ single-element array by hand at forty call sites. */
28
+ export declare function segmentOf(piece: Piece): Segments;
29
+ /**
30
+ * Maps a joined-text range to the absolute source ranges it covers.
31
+ *
32
+ * Returns several ranges when the span crosses a piece boundary, and none when
33
+ * it falls entirely on a synthetic separator.
34
+ */
35
+ export declare function mapRange(seg: Segments, a: number, b: number): Array<{
36
+ start: number;
37
+ end: number;
38
+ }>;
39
+ /**
40
+ * Where the parser reports what it consumed.
41
+ *
42
+ * `span` takes ABSOLUTE source offsets — never joined-text ones — because a
43
+ * token that is right relative to some intermediate string is a token the
44
+ * editor cannot use. `embed` is the entire nesting feature for markdown: the
45
+ * grammar forwards it to `ctx.sub`, and a fenced block gets highlighted in its
46
+ * own language with no code anywhere that knows which language that is.
47
+ */
48
+ export interface Sink {
49
+ span(start: number, end: number, type: TokenType): void;
50
+ embed(code: string, language: string | null, at: number): void;
51
+ /**
52
+ * Opens a structural frame. `content` names the absolute source ranges this
53
+ * frame holds as its own TEXT; omitting it means the frame is opaque and its
54
+ * children claim what they need. See ./frames.ts for why that default.
55
+ *
56
+ * Required rather than optional so a new consumer cannot silently receive
57
+ * spans without structure — the grammar, which genuinely wants only spans,
58
+ * says so with an explicit no-op rather than by omission.
59
+ */
60
+ open(frame: Frame, start: number, content?: readonly Range[]): void;
61
+ /**
62
+ * Closes the innermost frame. `content` adds ranges the frame could not know
63
+ * at open time — in practice its own trailing line terminator, which is not
64
+ * known until the reader has found where the block ends.
65
+ */
66
+ close(end: number, content?: readonly Range[]): void;
67
+ }
68
+ /**
69
+ * The source ranges a `Segments` covers — its parts, in absolute coordinates.
70
+ *
71
+ * This is the whole reason frames could reuse the existing bookkeeping: a
72
+ * block's content ranges are ALREADY computed, as the pieces it cut its
73
+ * prefixes off to build. Deriving them a second time is how the two would drift.
74
+ */
75
+ export declare function contentOf(seg: Segments): Range[];
76
+ /** The absolute range spanned by a joined-text range, prefixes included.
77
+ *
78
+ * Deliberately the OUTER hull rather than the list `mapRange` returns: a
79
+ * frame's interval must contain the `> ` prefixes sitting between its pieces,
80
+ * or the frames those prefixes belong to would not nest inside it. The pieces
81
+ * themselves are what `contentOf`/`mapRange` report; this is the envelope. */
82
+ export declare function hullOf(seg: Segments, a: number, b: number): Range | null;
83
+ /** Reports a joined-text range, split across pieces, at one token type. */
84
+ export declare function markRange(seg: Segments, sink: Sink | undefined, a: number, b: number, type: TokenType): void;
@@ -0,0 +1,108 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * The markdown tree.
4
+ *
5
+ * WHY MARKDOWN GETS A PARSER AND EVERY OTHER LANGUAGE GETS A RULE STACK. The
6
+ * scanner decides what a character means from the rules in force AT THAT
7
+ * POSITION. Markdown decides from block structure that is only knowable later:
8
+ * whether a line is a paragraph or a lazy continuation of the list item above
9
+ * it depends on its indentation relative to a marker several lines back, and
10
+ * whether `---` is a thematic break or the underline of a setext heading
11
+ * depends on what follows. No positional rule stack can see either.
12
+ *
13
+ * So markdown parses properly into this tree — and then emits the same flat
14
+ * `Token[]` as everything else, so the editor highlights it with no special
15
+ * case anywhere. One parse, two consumers: the renderer reads the tree, the
16
+ * highlighter reads the tokens.
17
+ */
18
+ export type MdNode = {
19
+ kind: "paragraph";
20
+ children: MdInline[];
21
+ } | {
22
+ kind: "heading";
23
+ level: 1 | 2 | 3 | 4 | 5 | 6;
24
+ id: string;
25
+ children: MdInline[];
26
+ } | {
27
+ kind: "code";
28
+ language: string | null;
29
+ code: string; /** unclosed fence, still typing */
30
+ open: boolean;
31
+ } | {
32
+ kind: "quote";
33
+ children: MdNode[];
34
+ } | {
35
+ kind: "list";
36
+ ordered: boolean;
37
+ start: number;
38
+ tight: boolean;
39
+ items: MdListItem[];
40
+ } | {
41
+ kind: "table";
42
+ head: MdCell[];
43
+ rows: MdCell[][];
44
+ align: (MdAlign | null)[];
45
+ } | {
46
+ kind: "rule";
47
+ } | {
48
+ kind: "frontmatter";
49
+ language: string;
50
+ body: string;
51
+ } | {
52
+ kind: "footnotes";
53
+ items: Array<{
54
+ label: string;
55
+ children: MdNode[];
56
+ }>;
57
+ };
58
+ export type MdAlign = "left" | "center" | "right";
59
+ export interface MdListItem {
60
+ /** null for a plain bullet; true/false for a task list checkbox. */
61
+ checked: boolean | null;
62
+ children: MdNode[];
63
+ }
64
+ export interface MdCell {
65
+ children: MdInline[];
66
+ }
67
+ export type MdInline = {
68
+ kind: "text";
69
+ value: string;
70
+ } | {
71
+ kind: "code";
72
+ value: string;
73
+ } | {
74
+ kind: "emphasis";
75
+ children: MdInline[];
76
+ } | {
77
+ kind: "strong";
78
+ children: MdInline[];
79
+ } | {
80
+ kind: "strike";
81
+ children: MdInline[];
82
+ } | {
83
+ kind: "link";
84
+ href: string;
85
+ title?: string;
86
+ children: MdInline[];
87
+ } | {
88
+ kind: "image";
89
+ src: string;
90
+ alt: string;
91
+ title?: string;
92
+ } | {
93
+ kind: "footnoteRef";
94
+ label: string;
95
+ } | {
96
+ kind: "break";
97
+ };
98
+ /**
99
+ * How a fenced block is rendered. The markdown renderer must NOT import the
100
+ * `Code` component — `Code` renders markdown, so that import is a cycle. The
101
+ * consumer supplies the renderer instead, which also means a chat message and
102
+ * a docs page can present the same fence differently.
103
+ */
104
+ export type MdCodeRenderer = (block: {
105
+ language: string | null;
106
+ code: string;
107
+ open: boolean;
108
+ }) => ReactNode;
@@ -0,0 +1,37 @@
1
+ import type { Grammar } from "./types";
2
+ /**
3
+ * Normalises and checks a grammar at definition time, so a malformed rule fails
4
+ * where it was written rather than as slightly-wrong colours in a browser.
5
+ *
6
+ * Every pattern is rebuilt with two flags forced on:
7
+ *
8
+ * `y` (sticky) — a plain regex SEARCHES FORWARD from the position, so a rule
9
+ * can match text the scanner has not reached yet and silently swallow
10
+ * everything in between. Sticky anchors it to exactly where the scanner is.
11
+ *
12
+ * `d` (hasIndices) — `groups` needs the offset of each capture, and
13
+ * `match.indices` is the only way to get it that survives optional groups.
14
+ *
15
+ * Forcing them beats throwing on their absence: a grammar author writes an
16
+ * ordinary regex and the one thing they could get subtly wrong is unreachable.
17
+ */
18
+ export declare function defineGrammar(grammar: Grammar): Grammar;
19
+ /**
20
+ * Registered explicitly from a VALUE import rather than by each language module
21
+ * importing the registry for its side effect. `package.json` declares
22
+ * `sideEffects: ["*.css"]`, which tells every bundler a bare `import "./x"` of
23
+ * a `.ts` module is safe to delete — and esbuild does. That already cost this
24
+ * project its entire icon set once (CAV-11); the registry that a table is
25
+ * pushed INTO cannot be pruned while the table is reachable.
26
+ */
27
+ export declare function registerGrammar(grammar: Grammar): void;
28
+ /**
29
+ * Looks up a language by name or alias. Returns undefined for anything
30
+ * unregistered — callers render it as plain text, because an unknown language
31
+ * on a code block must never be an error. The block still has to be readable.
32
+ */
33
+ export declare function getGrammar(language: string | null | undefined): Grammar | undefined;
34
+ /** The canonical name for an alias — `ts` becomes `typescript`. */
35
+ export declare function resolveLanguage(language: string | null | undefined): string | null;
36
+ /** Every registered language, canonical names only, sorted. Drives the picker. */
37
+ export declare function listLanguages(): string[];
@@ -0,0 +1,17 @@
1
+ import type { Token } from "./types";
2
+ /**
3
+ * Tokenizes `source` as `language`. An unknown or missing language yields one
4
+ * `text` token spanning the input — never an error, never an empty result. A
5
+ * code block labelled with a language nobody implemented still has to be
6
+ * readable, and an editor still has to be editable.
7
+ */
8
+ export declare function tokenize(source: string, language: string | null | undefined): Token[];
9
+ /**
10
+ * Asserts what the whole design rests on: the tokens reproduce the source
11
+ * exactly. Exported because it is used by every language's test rather than
12
+ * re-derived in each one, and because a consumer building a grammar at runtime
13
+ * should have the same check available.
14
+ *
15
+ * Returns a description of the first violation, or null when the list is sound.
16
+ */
17
+ export declare function checkCoverage(source: string, tokens: Token[]): string | null;