@fuzdev/mdz 0.1.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 (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/dist/Mdz.svelte +39 -0
  4. package/dist/Mdz.svelte.d.ts +17 -0
  5. package/dist/Mdz.svelte.d.ts.map +1 -0
  6. package/dist/MdzNodeView.svelte +140 -0
  7. package/dist/MdzNodeView.svelte.d.ts +9 -0
  8. package/dist/MdzNodeView.svelte.d.ts.map +1 -0
  9. package/dist/MdzPrecompiled.svelte +33 -0
  10. package/dist/MdzPrecompiled.svelte.d.ts +17 -0
  11. package/dist/MdzPrecompiled.svelte.d.ts.map +1 -0
  12. package/dist/MdzRoot.svelte +40 -0
  13. package/dist/MdzRoot.svelte.d.ts +14 -0
  14. package/dist/MdzRoot.svelte.d.ts.map +1 -0
  15. package/dist/MdzStream.svelte +37 -0
  16. package/dist/MdzStream.svelte.d.ts +18 -0
  17. package/dist/MdzStream.svelte.d.ts.map +1 -0
  18. package/dist/MdzStreamNodeView.svelte +150 -0
  19. package/dist/MdzStreamNodeView.svelte.d.ts +9 -0
  20. package/dist/MdzStreamNodeView.svelte.d.ts.map +1 -0
  21. package/dist/context_helpers.d.ts +23 -0
  22. package/dist/context_helpers.d.ts.map +1 -0
  23. package/dist/context_helpers.js +19 -0
  24. package/dist/mdz.d.ts +152 -0
  25. package/dist/mdz.d.ts.map +1 -0
  26. package/dist/mdz.js +61 -0
  27. package/dist/mdz_contexts.d.ts +106 -0
  28. package/dist/mdz_contexts.d.ts.map +1 -0
  29. package/dist/mdz_contexts.js +42 -0
  30. package/dist/mdz_helpers.d.ts +321 -0
  31. package/dist/mdz_helpers.d.ts.map +1 -0
  32. package/dist/mdz_helpers.js +668 -0
  33. package/dist/mdz_lexer.d.ts +123 -0
  34. package/dist/mdz_lexer.d.ts.map +1 -0
  35. package/dist/mdz_lexer.js +1405 -0
  36. package/dist/mdz_opcodes.d.ts +193 -0
  37. package/dist/mdz_opcodes.d.ts.map +1 -0
  38. package/dist/mdz_opcodes.js +14 -0
  39. package/dist/mdz_opcodes_to_nodes.d.ts +26 -0
  40. package/dist/mdz_opcodes_to_nodes.d.ts.map +1 -0
  41. package/dist/mdz_opcodes_to_nodes.js +410 -0
  42. package/dist/mdz_stream_parser.d.ts +109 -0
  43. package/dist/mdz_stream_parser.d.ts.map +1 -0
  44. package/dist/mdz_stream_parser.js +699 -0
  45. package/dist/mdz_stream_parser_block.d.ts +99 -0
  46. package/dist/mdz_stream_parser_block.d.ts.map +1 -0
  47. package/dist/mdz_stream_parser_block.js +437 -0
  48. package/dist/mdz_stream_parser_inline.d.ts +98 -0
  49. package/dist/mdz_stream_parser_inline.d.ts.map +1 -0
  50. package/dist/mdz_stream_parser_inline.js +481 -0
  51. package/dist/mdz_stream_parser_link.d.ts +29 -0
  52. package/dist/mdz_stream_parser_link.d.ts.map +1 -0
  53. package/dist/mdz_stream_parser_link.js +227 -0
  54. package/dist/mdz_stream_parser_list.d.ts +106 -0
  55. package/dist/mdz_stream_parser_list.d.ts.map +1 -0
  56. package/dist/mdz_stream_parser_list.js +438 -0
  57. package/dist/mdz_stream_parser_state.d.ts +476 -0
  58. package/dist/mdz_stream_parser_state.d.ts.map +1 -0
  59. package/dist/mdz_stream_parser_state.js +651 -0
  60. package/dist/mdz_stream_parser_text.d.ts +25 -0
  61. package/dist/mdz_stream_parser_text.d.ts.map +1 -0
  62. package/dist/mdz_stream_parser_text.js +67 -0
  63. package/dist/mdz_stream_parser_url.d.ts +76 -0
  64. package/dist/mdz_stream_parser_url.d.ts.map +1 -0
  65. package/dist/mdz_stream_parser_url.js +328 -0
  66. package/dist/mdz_stream_state.svelte.d.ts +53 -0
  67. package/dist/mdz_stream_state.svelte.d.ts.map +1 -0
  68. package/dist/mdz_stream_state.svelte.js +360 -0
  69. package/dist/mdz_to_svelte.d.ts +71 -0
  70. package/dist/mdz_to_svelte.d.ts.map +1 -0
  71. package/dist/mdz_to_svelte.js +127 -0
  72. package/dist/mdz_token_parser.d.ts +20 -0
  73. package/dist/mdz_token_parser.d.ts.map +1 -0
  74. package/dist/mdz_token_parser.js +449 -0
  75. package/dist/svelte_preprocess_mdz.d.ts +80 -0
  76. package/dist/svelte_preprocess_mdz.d.ts.map +1 -0
  77. package/dist/svelte_preprocess_mdz.js +543 -0
  78. package/dist/tsdoc_mdz.d.ts +45 -0
  79. package/dist/tsdoc_mdz.d.ts.map +1 -0
  80. package/dist/tsdoc_mdz.js +88 -0
  81. package/package.json +131 -0
  82. package/src/lib/context_helpers.ts +52 -0
  83. package/src/lib/mdz.ts +190 -0
  84. package/src/lib/mdz_contexts.ts +99 -0
  85. package/src/lib/mdz_helpers.ts +727 -0
  86. package/src/lib/mdz_lexer.ts +1761 -0
  87. package/src/lib/mdz_opcodes.ts +227 -0
  88. package/src/lib/mdz_opcodes_to_nodes.ts +470 -0
  89. package/src/lib/mdz_stream_parser.ts +766 -0
  90. package/src/lib/mdz_stream_parser_block.ts +490 -0
  91. package/src/lib/mdz_stream_parser_inline.ts +527 -0
  92. package/src/lib/mdz_stream_parser_link.ts +283 -0
  93. package/src/lib/mdz_stream_parser_list.ts +525 -0
  94. package/src/lib/mdz_stream_parser_state.ts +957 -0
  95. package/src/lib/mdz_stream_parser_text.ts +95 -0
  96. package/src/lib/mdz_stream_parser_url.ts +386 -0
  97. package/src/lib/mdz_stream_state.svelte.ts +383 -0
  98. package/src/lib/mdz_to_svelte.ts +213 -0
  99. package/src/lib/mdz_token_parser.ts +544 -0
  100. package/src/lib/svelte_preprocess_mdz.ts +777 -0
  101. package/src/lib/tsdoc_mdz.ts +97 -0
package/dist/mdz.d.ts ADDED
@@ -0,0 +1,152 @@
1
+ /**
2
+ * mdz — strict markdown dialect built for streaming, Svelte authoring, docs
3
+ * sites, and untrusted content.
4
+ *
5
+ * Created for two motivating use cases: rendering TSDoc/JSDoc comments on
6
+ * docs websites (with domain-specific behavior like linkifying backticked
7
+ * identifiers) and authoring content with Svelte components. It also has a
8
+ * streaming parser that extends the same grammar to LLM output.
9
+ *
10
+ * This module is the synchronous entry: `mdz_parse` parses a complete string
11
+ * to an `MdzNode` tree. It is the canonical reference parser — the streaming
12
+ * pipeline (`mdz_stream_parser.ts`) emits opcodes that converge on the same
13
+ * tree, asserted by parity tests.
14
+ *
15
+ * The dialect supports:
16
+ * - inline formatting: `code`, **bold**, _italic_, ~~strikethrough~~
17
+ * - auto-detected links: external URLs (`https://...`) and internal paths (`/path`)
18
+ * - markdown links: `[text](url)` with custom display text
19
+ * - inline code in backticks (creates `Code` nodes; auto-linking to identifiers/modules
20
+ * is handled by the rendering layer via `MdzNodeView.svelte`)
21
+ * - paragraph breaks (blank lines)
22
+ * - block elements: headings, horizontal rules, lists, blockquotes, code blocks
23
+ * - HTML elements and Svelte components (opt-in via context)
24
+ *
25
+ * Whitespace: the parser preserves whitespace in text node content (single
26
+ * newlines stay literal `\n`, no `<br>` nodes), while structural whitespace is
27
+ * interpreted — blank lines separate paragraphs, extra blank lines collapse,
28
+ * and a line of only whitespace (spaces, tabs, `\r`) counts as blank, so an
29
+ * invisible trailing space never changes document structure.
30
+ * Presentation is the renderer's choice: by default whitespace collapses like
31
+ * standard markdown (single newlines are soft breaks), and the `whitespace`
32
+ * prop on `Mdz`/`MdzStream` opts into `pre-line` or `pre-wrap` rendering.
33
+ *
34
+ * ## Design philosophy
35
+ *
36
+ * - **False negatives over false positives**: When in doubt, treat as plain text.
37
+ * Block elements can interrupt paragraphs without blank lines; inline formatting is strict.
38
+ * - **One way to do things**: Single unambiguous syntax per feature. No alternatives.
39
+ * - **Explicit over implicit**: Clear delimiters and column-0 requirements avoid ambiguity.
40
+ * - **Simple over complete**: Prefer simple parsing rules over complex edge case handling.
41
+ * - **No implicit retroactivity**: the grammar admits no construct where later input changes
42
+ * the rendering of unboundedly-earlier output, so the streaming pipeline corrects only via
43
+ * bounded, explicit opcodes and never re-parses.
44
+ *
45
+ * ## Status
46
+ *
47
+ * Pre-stable — breaking changes are expected as the dialect matures.
48
+ * Next: attributes, editing.
49
+ *
50
+ * @module
51
+ */
52
+ /**
53
+ * Parses text to an array of `MdzNode`.
54
+ *
55
+ * Two phases: `MdzLexer` tokenizes the input into a flat `MdzToken[]` stream,
56
+ * then `MdzTokenParser` builds the `MdzNode[]` tree from the tokens.
57
+ */
58
+ export declare const mdz_parse: (text: string) => Array<MdzNode>;
59
+ export type MdzNode = MdzNodeText | MdzNodeCode | MdzNodeCodeblock | MdzNodeBold | MdzNodeItalic | MdzNodeStrikethrough | MdzNodeLink | MdzNodeParagraph | MdzNodeHr | MdzNodeHeading | MdzNodeList | MdzNodeListItem | MdzNodeBlockquote | MdzNodeElement | MdzNodeComponent;
60
+ export interface MdzNodeBase {
61
+ type: string;
62
+ start: number;
63
+ end: number;
64
+ }
65
+ export interface MdzNodeText extends MdzNodeBase {
66
+ type: 'Text';
67
+ content: string;
68
+ }
69
+ export interface MdzNodeCode extends MdzNodeBase {
70
+ type: 'Code';
71
+ /** The code content (identifier/module name). */
72
+ content: string;
73
+ }
74
+ export interface MdzNodeCodeblock extends MdzNodeBase {
75
+ type: 'Codeblock';
76
+ /** Language hint, if provided. */
77
+ lang: string | null;
78
+ /** Raw code content. */
79
+ content: string;
80
+ }
81
+ export interface MdzNodeBold extends MdzNodeBase {
82
+ type: 'Bold';
83
+ children: Array<MdzNode>;
84
+ }
85
+ export interface MdzNodeItalic extends MdzNodeBase {
86
+ type: 'Italic';
87
+ children: Array<MdzNode>;
88
+ }
89
+ export interface MdzNodeStrikethrough extends MdzNodeBase {
90
+ type: 'Strikethrough';
91
+ children: Array<MdzNode>;
92
+ }
93
+ export interface MdzNodeLink extends MdzNodeBase {
94
+ type: 'Link';
95
+ /** URL or path. */
96
+ reference: string;
97
+ /** Display content (can include inline formatting). */
98
+ children: Array<MdzNode>;
99
+ /** `external` is `https`/`http`; `internal` is `/path`, `./path`, or `../path`. */
100
+ link_type: 'external' | 'internal';
101
+ }
102
+ export interface MdzNodeParagraph extends MdzNodeBase {
103
+ type: 'Paragraph';
104
+ children: Array<MdzNode>;
105
+ }
106
+ export interface MdzNodeHr extends MdzNodeBase {
107
+ type: 'Hr';
108
+ }
109
+ export interface MdzNodeHeading extends MdzNodeBase {
110
+ type: 'Heading';
111
+ level: 1 | 2 | 3 | 4 | 5 | 6;
112
+ /** Slugified heading text for fragment links. */
113
+ id: string;
114
+ /** Inline formatting allowed. */
115
+ children: Array<MdzNode>;
116
+ }
117
+ export interface MdzNodeList extends MdzNodeBase {
118
+ type: 'List';
119
+ ordered: boolean;
120
+ /** First item's authored number (ordered only) — the `<ol start>` attribute. */
121
+ start_number?: number;
122
+ children: Array<MdzNodeListItem>;
123
+ }
124
+ export interface MdzNodeListItem extends MdzNodeBase {
125
+ type: 'ListItem';
126
+ /** Authored number (ordered only); the renderer ignores it, tooling and the future formatter use it. */
127
+ number?: number;
128
+ /** Inline run first, then block children (`Paragraph` | `List` | `Codeblock` | `Blockquote`). */
129
+ children: Array<MdzNode>;
130
+ }
131
+ export interface MdzNodeBlockquote extends MdzNodeBase {
132
+ type: 'Blockquote';
133
+ /**
134
+ * Block children — a quote's content is a mini-document, so anything that
135
+ * can appear at the top level can appear here (`Paragraph` | `Heading` |
136
+ * `Hr` | `List` | `Codeblock` | `Blockquote`).
137
+ */
138
+ children: Array<MdzNode>;
139
+ }
140
+ export interface MdzNodeElement extends MdzNodeBase {
141
+ type: 'Element';
142
+ /** HTML element name (e.g. `div`, `span`, `aside`). */
143
+ name: string;
144
+ children: Array<MdzNode>;
145
+ }
146
+ export interface MdzNodeComponent extends MdzNodeBase {
147
+ type: 'Component';
148
+ /** Svelte component name (e.g. `Alert`, `Card`). */
149
+ name: string;
150
+ children: Array<MdzNode>;
151
+ }
152
+ //# sourceMappingURL=mdz.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mdz.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/mdz.ts"],"names":[],"mappings":"AAAA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AO,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,cAAe,SAAQ,WAAW;IAClD,IAAI,EAAE,SAAS,CAAC;IAChB,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACpD,IAAI,EAAE,WAAW,CAAC;IAClB,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CACzB"}
package/dist/mdz.js ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * mdz — strict markdown dialect built for streaming, Svelte authoring, docs
3
+ * sites, and untrusted content.
4
+ *
5
+ * Created for two motivating use cases: rendering TSDoc/JSDoc comments on
6
+ * docs websites (with domain-specific behavior like linkifying backticked
7
+ * identifiers) and authoring content with Svelte components. It also has a
8
+ * streaming parser that extends the same grammar to LLM output.
9
+ *
10
+ * This module is the synchronous entry: `mdz_parse` parses a complete string
11
+ * to an `MdzNode` tree. It is the canonical reference parser — the streaming
12
+ * pipeline (`mdz_stream_parser.ts`) emits opcodes that converge on the same
13
+ * tree, asserted by parity tests.
14
+ *
15
+ * The dialect supports:
16
+ * - inline formatting: `code`, **bold**, _italic_, ~~strikethrough~~
17
+ * - auto-detected links: external URLs (`https://...`) and internal paths (`/path`)
18
+ * - markdown links: `[text](url)` with custom display text
19
+ * - inline code in backticks (creates `Code` nodes; auto-linking to identifiers/modules
20
+ * is handled by the rendering layer via `MdzNodeView.svelte`)
21
+ * - paragraph breaks (blank lines)
22
+ * - block elements: headings, horizontal rules, lists, blockquotes, code blocks
23
+ * - HTML elements and Svelte components (opt-in via context)
24
+ *
25
+ * Whitespace: the parser preserves whitespace in text node content (single
26
+ * newlines stay literal `\n`, no `<br>` nodes), while structural whitespace is
27
+ * interpreted — blank lines separate paragraphs, extra blank lines collapse,
28
+ * and a line of only whitespace (spaces, tabs, `\r`) counts as blank, so an
29
+ * invisible trailing space never changes document structure.
30
+ * Presentation is the renderer's choice: by default whitespace collapses like
31
+ * standard markdown (single newlines are soft breaks), and the `whitespace`
32
+ * prop on `Mdz`/`MdzStream` opts into `pre-line` or `pre-wrap` rendering.
33
+ *
34
+ * ## Design philosophy
35
+ *
36
+ * - **False negatives over false positives**: When in doubt, treat as plain text.
37
+ * Block elements can interrupt paragraphs without blank lines; inline formatting is strict.
38
+ * - **One way to do things**: Single unambiguous syntax per feature. No alternatives.
39
+ * - **Explicit over implicit**: Clear delimiters and column-0 requirements avoid ambiguity.
40
+ * - **Simple over complete**: Prefer simple parsing rules over complex edge case handling.
41
+ * - **No implicit retroactivity**: the grammar admits no construct where later input changes
42
+ * the rendering of unboundedly-earlier output, so the streaming pipeline corrects only via
43
+ * bounded, explicit opcodes and never re-parses.
44
+ *
45
+ * ## Status
46
+ *
47
+ * Pre-stable — breaking changes are expected as the dialect matures.
48
+ * Next: attributes, editing.
49
+ *
50
+ * @module
51
+ */
52
+ import { MdzLexer } from './mdz_lexer.js';
53
+ import { MdzTokenParser } from './mdz_token_parser.js';
54
+ // TODO design incremental parsing or some system that preserves Svelte components across re-renders when possible
55
+ /**
56
+ * Parses text to an array of `MdzNode`.
57
+ *
58
+ * Two phases: `MdzLexer` tokenizes the input into a flat `MdzToken[]` stream,
59
+ * then `MdzTokenParser` builds the `MdzNode[]` tree from the tokens.
60
+ */
61
+ export const mdz_parse = (text) => new MdzTokenParser(new MdzLexer(text).tokenize()).parse();
@@ -0,0 +1,106 @@
1
+ import type { Component } from 'svelte';
2
+ /**
3
+ * Component registry for custom Svelte components that can be used in mdz content.
4
+ *
5
+ * For example, registering 'Alert' allows using `<Alert>...</Alert>` in mdz content.
6
+ *
7
+ * The Map values are Svelte components.
8
+ */
9
+ export type MdzComponents = Map<string, Component<any, any>>;
10
+ /**
11
+ * Element registry for HTML elements that can be used in mdz content.
12
+ *
13
+ * For example, registering 'div' allows using `<div>...</div>` in mdz content.
14
+ *
15
+ * The Map values are boolean placeholders for future configuration options.
16
+ */
17
+ export type MdzElements = Map<string, boolean>;
18
+ /**
19
+ * CSS `white-space` values for the `whitespace` prop on `Mdz`, `MdzStream`,
20
+ * and `MdzPrecompiled`. By default no style is applied, so whitespace
21
+ * collapses like standard markdown — single newlines are soft breaks.
22
+ * `pre-line` renders every newline as a line break (chat-style input);
23
+ * `pre-wrap` additionally preserves spaces and tabs.
24
+ */
25
+ export type MdzWhitespace = 'normal' | 'nowrap' | 'pre' | 'pre-wrap' | 'pre-line' | 'break-spaces';
26
+ /**
27
+ * Context for providing custom mdz components via a getter function.
28
+ * Set to a getter (e.g., `() => components`) so changes are reflected reactively.
29
+ */
30
+ export declare const mdz_components_context: {
31
+ get: (error_message?: string) => () => MdzComponents | undefined;
32
+ get_maybe: () => (() => MdzComponents | undefined) | undefined;
33
+ set: (value: () => MdzComponents | undefined) => () => MdzComponents | undefined;
34
+ };
35
+ /**
36
+ * Context for providing allowed HTML elements via a getter function.
37
+ * Set to a getter (e.g., `() => elements`) so changes are reflected reactively.
38
+ * By default, no HTML elements are allowed.
39
+ */
40
+ export declare const mdz_elements_context: {
41
+ get: (error_message?: string) => () => MdzElements | undefined;
42
+ get_maybe: () => (() => MdzElements | undefined) | undefined;
43
+ set: (value: () => MdzElements | undefined) => () => MdzElements | undefined;
44
+ };
45
+ /**
46
+ * Context for providing a base path getter for resolving relative links in mdz content.
47
+ * Set to a getter (e.g., `() => base`) so changes to the base prop are reflected
48
+ * without needing an effect. When the getter returns a path like `'/docs/usage/'`,
49
+ * relative paths like `./grammar` resolve to `/docs/usage/grammar` before rendering.
50
+ * When not set, relative paths use raw hrefs (browser resolves them).
51
+ */
52
+ export declare const mdz_base_context: {
53
+ get: (error_message?: string) => () => string | undefined;
54
+ get_maybe: () => (() => string | undefined) | undefined;
55
+ set: (value: () => string | undefined) => () => string | undefined;
56
+ };
57
+ /**
58
+ * Component that renders an inline `` `code` `` span. Receives the raw span
59
+ * content as `reference` — the prop name matches `fuz_ui`'s `DocsLink`, so it
60
+ * can be injected directly to auto-link backticked API identifiers.
61
+ */
62
+ export type MdzCodeComponent = Component<{
63
+ reference: string;
64
+ }>;
65
+ /**
66
+ * Context for overriding how inline `` `code` `` spans render, via a getter
67
+ * function. When not set, inline code renders as a plain `<code>` element.
68
+ */
69
+ export declare const mdz_code_context: {
70
+ get: (error_message?: string) => () => MdzCodeComponent | undefined;
71
+ get_maybe: () => (() => MdzCodeComponent | undefined) | undefined;
72
+ set: (value: () => MdzCodeComponent | undefined) => () => MdzCodeComponent | undefined;
73
+ };
74
+ /**
75
+ * Component that renders a fenced code block. Receives `lang` and `content`,
76
+ * matching `@fuzdev/fuz_code`'s `Code`, so it can be injected directly for
77
+ * syntax highlighting.
78
+ */
79
+ export type MdzCodeblockComponent = Component<{
80
+ lang: string | null;
81
+ content: string;
82
+ }>;
83
+ /**
84
+ * Context for overriding how fenced code blocks render, via a getter function.
85
+ * When not set, code blocks render as a plain `<pre><code>` element.
86
+ */
87
+ export declare const mdz_codeblock_context: {
88
+ get: (error_message?: string) => () => MdzCodeblockComponent | undefined;
89
+ get_maybe: () => (() => MdzCodeblockComponent | undefined) | undefined;
90
+ set: (value: () => MdzCodeblockComponent | undefined) => () => MdzCodeblockComponent | undefined;
91
+ };
92
+ interface MdzGetterContext<T> {
93
+ get_maybe(): (() => T | undefined) | undefined;
94
+ set(value: () => T | undefined): unknown;
95
+ }
96
+ /**
97
+ * Set an mdz context to a getter that prefers the local `value_fn` and falls
98
+ * back to the ancestor's value when `value_fn()` returns `undefined`.
99
+ *
100
+ * Pass `value_fn` as a getter (not a snapshot) so prop changes remain reactive.
101
+ * The ancestor lookup happens once at component init — that's intentional, it
102
+ * captures the surrounding scope's context at mount time.
103
+ */
104
+ export declare const mdz_set_context_with_fallback: <T>(context: MdzGetterContext<T>, value_fn: () => T | undefined) => void;
105
+ export {};
106
+ //# sourceMappingURL=mdz_contexts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,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;AACH,MAAM,MAAM,qBAAqB,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,CAAC,CAAC;AAEtF;;;GAGG;AACH,eAAO,MAAM,qBAAqB;2CAAwB,qBAAqB,GAAG,SAAS;4BAAjC,qBAAqB,GAAG,SAAS;uBAAjC,qBAAqB,GAAG,SAAS,WAAjC,qBAAqB,GAAG,SAAS;CAAG,CAAC;AAE/F,UAAU,gBAAgB,CAAC,CAAC;IAC3B,SAAS,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IAC/C,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC;CACzC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,GAAI,CAAC,EAC9C,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAC5B,UAAU,MAAM,CAAC,GAAG,SAAS,KAC3B,IAGF,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { create_context } from './context_helpers.js';
2
+ /**
3
+ * Context for providing custom mdz components via a getter function.
4
+ * Set to a getter (e.g., `() => components`) so changes are reflected reactively.
5
+ */
6
+ export const mdz_components_context = create_context();
7
+ /**
8
+ * Context for providing allowed HTML elements via a getter function.
9
+ * Set to a getter (e.g., `() => elements`) so changes are reflected reactively.
10
+ * By default, no HTML elements are allowed.
11
+ */
12
+ export const mdz_elements_context = create_context();
13
+ /**
14
+ * Context for providing a base path getter for resolving relative links in mdz content.
15
+ * Set to a getter (e.g., `() => base`) so changes to the base prop are reflected
16
+ * without needing an effect. When the getter returns a path like `'/docs/usage/'`,
17
+ * relative paths like `./grammar` resolve to `/docs/usage/grammar` before rendering.
18
+ * When not set, relative paths use raw hrefs (browser resolves them).
19
+ */
20
+ export const mdz_base_context = create_context();
21
+ /**
22
+ * Context for overriding how inline `` `code` `` spans render, via a getter
23
+ * function. When not set, inline code renders as a plain `<code>` element.
24
+ */
25
+ export const mdz_code_context = create_context();
26
+ /**
27
+ * Context for overriding how fenced code blocks render, via a getter function.
28
+ * When not set, code blocks render as a plain `<pre><code>` element.
29
+ */
30
+ export const mdz_codeblock_context = create_context();
31
+ /**
32
+ * Set an mdz context to a getter that prefers the local `value_fn` and falls
33
+ * back to the ancestor's value when `value_fn()` returns `undefined`.
34
+ *
35
+ * Pass `value_fn` as a getter (not a snapshot) so prop changes remain reactive.
36
+ * The ancestor lookup happens once at component init — that's intentional, it
37
+ * captures the surrounding scope's context at mount time.
38
+ */
39
+ export const mdz_set_context_with_fallback = (context, value_fn) => {
40
+ const ancestor = context.get_maybe();
41
+ context.set(() => value_fn() ?? ancestor?.());
42
+ };