@temelj/mdx 0.13.0 → 0.15.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 +468 -82
- package/dist/character-entities.d.mts +4 -0
- package/dist/character-entities.d.mts.map +1 -0
- package/dist/character-entities.mjs +2132 -0
- package/dist/character-entities.mjs.map +1 -0
- package/dist/character-reference.d.mts +6 -0
- package/dist/character-reference.d.mts.map +1 -0
- package/dist/character-reference.mjs +18 -0
- package/dist/character-reference.mjs.map +1 -0
- package/dist/compile-analysis.d.mts +28 -0
- package/dist/compile-analysis.d.mts.map +1 -0
- package/dist/compile-analysis.mjs +74 -0
- package/dist/compile-analysis.mjs.map +1 -0
- package/dist/compile-emit.d.mts +9 -0
- package/dist/compile-emit.d.mts.map +1 -0
- package/dist/compile-emit.mjs +187 -0
- package/dist/compile-emit.mjs.map +1 -0
- package/dist/compile-esm.d.mts +34 -0
- package/dist/compile-esm.d.mts.map +1 -0
- package/dist/compile-esm.mjs +187 -0
- package/dist/compile-esm.mjs.map +1 -0
- package/dist/compile-names.d.mts +13 -0
- package/dist/compile-names.d.mts.map +1 -0
- package/dist/compile-names.mjs +32 -0
- package/dist/compile-names.mjs.map +1 -0
- package/dist/compiler.d.mts +69 -85
- package/dist/compiler.d.mts.map +1 -1
- package/dist/compiler.mjs +185 -418
- package/dist/compiler.mjs.map +1 -1
- package/dist/diagnostics.d.mts +37 -0
- package/dist/diagnostics.d.mts.map +1 -0
- package/dist/diagnostics.mjs +57 -0
- package/dist/diagnostics.mjs.map +1 -0
- package/dist/errors.d.mts +157 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +263 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/footnote-numbering.d.mts +27 -0
- package/dist/footnote-numbering.d.mts.map +1 -0
- package/dist/footnote-numbering.mjs +49 -0
- package/dist/footnote-numbering.mjs.map +1 -0
- package/dist/format-context.d.mts +46 -0
- package/dist/format-context.d.mts.map +1 -0
- package/dist/format-context.mjs +26 -0
- package/dist/format-context.mjs.map +1 -0
- package/dist/format-directive.d.mts +9 -0
- package/dist/format-directive.d.mts.map +1 -0
- package/dist/format-directive.mjs +99 -0
- package/dist/format-directive.mjs.map +1 -0
- package/dist/format-jsx.d.mts +8 -0
- package/dist/format-jsx.d.mts.map +1 -0
- package/dist/format-jsx.mjs +47 -0
- package/dist/format-jsx.mjs.map +1 -0
- package/dist/format-math.d.mts +9 -0
- package/dist/format-math.d.mts.map +1 -0
- package/dist/format-math.mjs +79 -0
- package/dist/format-math.mjs.map +1 -0
- package/dist/format-safe.d.mts +25 -0
- package/dist/format-safe.d.mts.map +1 -0
- package/dist/format-safe.mjs +366 -0
- package/dist/format-safe.mjs.map +1 -0
- package/dist/format-table.d.mts +8 -0
- package/dist/format-table.d.mts.map +1 -0
- package/dist/format-table.mjs +55 -0
- package/dist/format-table.mjs.map +1 -0
- package/dist/format-track.d.mts +18 -0
- package/dist/format-track.d.mts.map +1 -0
- package/dist/format-track.mjs +34 -0
- package/dist/format-track.mjs.map +1 -0
- package/dist/format.d.mts +7 -0
- package/dist/format.d.mts.map +1 -0
- package/dist/format.mjs +549 -0
- package/dist/format.mjs.map +1 -0
- package/dist/frontmatter.d.mts +15 -0
- package/dist/frontmatter.d.mts.map +1 -0
- package/dist/frontmatter.mjs +187 -0
- package/dist/frontmatter.mjs.map +1 -0
- package/dist/heading.d.mts +6 -0
- package/dist/heading.d.mts.map +1 -0
- package/dist/heading.mjs +19 -0
- package/dist/heading.mjs.map +1 -0
- package/dist/html-format.d.mts +32 -0
- package/dist/html-format.d.mts.map +1 -0
- package/dist/html-format.mjs +127 -0
- package/dist/html-format.mjs.map +1 -0
- package/dist/html-lower.d.mts +78 -0
- package/dist/html-lower.d.mts.map +1 -0
- package/dist/html-lower.mjs +583 -0
- package/dist/html-lower.mjs.map +1 -0
- package/dist/html-stream.d.mts +13 -0
- package/dist/html-stream.d.mts.map +1 -0
- package/dist/html-stream.mjs +32 -0
- package/dist/html-stream.mjs.map +1 -0
- package/dist/html.d.mts +120 -0
- package/dist/html.d.mts.map +1 -0
- package/dist/html.mjs +77 -0
- package/dist/html.mjs.map +1 -0
- package/dist/identifier.d.mts +4 -0
- package/dist/identifier.d.mts.map +1 -0
- package/dist/identifier.mjs +8 -0
- package/dist/identifier.mjs.map +1 -0
- package/dist/javascript-ast.d.mts +16 -0
- package/dist/javascript-ast.d.mts.map +1 -0
- package/dist/javascript-ast.mjs +39 -0
- package/dist/javascript-ast.mjs.map +1 -0
- package/dist/javascript-jsx.d.mts +24 -0
- package/dist/javascript-jsx.d.mts.map +1 -0
- package/dist/javascript-jsx.mjs +189 -0
- package/dist/javascript-jsx.mjs.map +1 -0
- package/dist/javascript.d.mts +9 -0
- package/dist/javascript.d.mts.map +1 -0
- package/dist/javascript.mjs +31 -0
- package/dist/javascript.mjs.map +1 -0
- package/dist/jsx-reference.d.mts +15 -0
- package/dist/jsx-reference.d.mts.map +1 -0
- package/dist/jsx-reference.mjs +31 -0
- package/dist/jsx-reference.mjs.map +1 -0
- package/dist/mod.d.mts +25 -8
- package/dist/mod.mjs +19 -7
- package/dist/model.d.mts +196 -0
- package/dist/model.d.mts.map +1 -0
- package/dist/model.mjs +113 -0
- package/dist/model.mjs.map +1 -0
- package/dist/parser/block-container-recognizers.d.mts +40 -0
- package/dist/parser/block-container-recognizers.d.mts.map +1 -0
- package/dist/parser/block-container-recognizers.mjs +90 -0
- package/dist/parser/block-container-recognizers.mjs.map +1 -0
- package/dist/parser/block-directive-recognizers.d.mts +22 -0
- package/dist/parser/block-directive-recognizers.d.mts.map +1 -0
- package/dist/parser/block-directive-recognizers.mjs +77 -0
- package/dist/parser/block-directive-recognizers.mjs.map +1 -0
- package/dist/parser/block-leaf-recognizers.d.mts +53 -0
- package/dist/parser/block-leaf-recognizers.d.mts.map +1 -0
- package/dist/parser/block-leaf-recognizers.mjs +386 -0
- package/dist/parser/block-leaf-recognizers.mjs.map +1 -0
- package/dist/parser/block-parser.d.mts +38 -0
- package/dist/parser/block-parser.d.mts.map +1 -0
- package/dist/parser/block-parser.mjs +895 -0
- package/dist/parser/block-parser.mjs.map +1 -0
- package/dist/parser/block-syntax.d.mts +240 -0
- package/dist/parser/block-syntax.d.mts.map +1 -0
- package/dist/parser/characters.d.mts +19 -0
- package/dist/parser/characters.d.mts.map +1 -0
- package/dist/parser/characters.mjs +52 -0
- package/dist/parser/characters.mjs.map +1 -0
- package/dist/parser/config.d.mts +16 -0
- package/dist/parser/config.d.mts.map +1 -0
- package/dist/parser/config.mjs +25 -0
- package/dist/parser/config.mjs.map +1 -0
- package/dist/parser/directive-attributes.d.mts +9 -0
- package/dist/parser/directive-attributes.d.mts.map +1 -0
- package/dist/parser/directive-attributes.mjs +24 -0
- package/dist/parser/directive-attributes.mjs.map +1 -0
- package/dist/parser/embedded-scanner.d.mts +18 -0
- package/dist/parser/embedded-scanner.d.mts.map +1 -0
- package/dist/parser/embedded-scanner.mjs +199 -0
- package/dist/parser/embedded-scanner.mjs.map +1 -0
- package/dist/parser/inline-autolink.d.mts +7 -0
- package/dist/parser/inline-autolink.d.mts.map +1 -0
- package/dist/parser/inline-autolink.mjs +42 -0
- package/dist/parser/inline-autolink.mjs.map +1 -0
- package/dist/parser/inline-character-reference.d.mts +7 -0
- package/dist/parser/inline-character-reference.d.mts.map +1 -0
- package/dist/parser/inline-character-reference.mjs +22 -0
- package/dist/parser/inline-character-reference.mjs.map +1 -0
- package/dist/parser/inline-code.d.mts +7 -0
- package/dist/parser/inline-code.d.mts.map +1 -0
- package/dist/parser/inline-code.mjs +29 -0
- package/dist/parser/inline-code.mjs.map +1 -0
- package/dist/parser/inline-directive.d.mts +9 -0
- package/dist/parser/inline-directive.d.mts.map +1 -0
- package/dist/parser/inline-directive.mjs +45 -0
- package/dist/parser/inline-directive.mjs.map +1 -0
- package/dist/parser/inline-embedded.d.mts +19 -0
- package/dist/parser/inline-embedded.d.mts.map +1 -0
- package/dist/parser/inline-embedded.mjs +92 -0
- package/dist/parser/inline-embedded.mjs.map +1 -0
- package/dist/parser/inline-emphasis.d.mts +11 -0
- package/dist/parser/inline-emphasis.d.mts.map +1 -0
- package/dist/parser/inline-emphasis.mjs +79 -0
- package/dist/parser/inline-emphasis.mjs.map +1 -0
- package/dist/parser/inline-input.d.mts +46 -0
- package/dist/parser/inline-input.d.mts.map +1 -0
- package/dist/parser/inline-input.mjs +137 -0
- package/dist/parser/inline-input.mjs.map +1 -0
- package/dist/parser/inline-link.d.mts +12 -0
- package/dist/parser/inline-link.d.mts.map +1 -0
- package/dist/parser/inline-link.mjs +187 -0
- package/dist/parser/inline-link.mjs.map +1 -0
- package/dist/parser/inline-math.d.mts +10 -0
- package/dist/parser/inline-math.d.mts.map +1 -0
- package/dist/parser/inline-math.mjs +46 -0
- package/dist/parser/inline-math.mjs.map +1 -0
- package/dist/parser/inline-output.d.mts +34 -0
- package/dist/parser/inline-output.d.mts.map +1 -0
- package/dist/parser/inline-output.mjs +62 -0
- package/dist/parser/inline-output.mjs.map +1 -0
- package/dist/parser/inline-parser.d.mts +14 -0
- package/dist/parser/inline-parser.d.mts.map +1 -0
- package/dist/parser/inline-parser.mjs +328 -0
- package/dist/parser/inline-parser.mjs.map +1 -0
- package/dist/parser/inline-pending.d.mts +23 -0
- package/dist/parser/inline-pending.d.mts.map +1 -0
- package/dist/parser/inline-pending.mjs +100 -0
- package/dist/parser/inline-pending.mjs.map +1 -0
- package/dist/parser/inline-syntax.d.mts +118 -0
- package/dist/parser/inline-syntax.d.mts.map +1 -0
- package/dist/parser/inline-syntax.mjs +1 -0
- package/dist/parser/javascript-boundary.d.mts +16 -0
- package/dist/parser/javascript-boundary.d.mts.map +1 -0
- package/dist/parser/javascript-boundary.mjs +42 -0
- package/dist/parser/javascript-boundary.mjs.map +1 -0
- package/dist/parser/javascript-scanner.d.mts +22 -0
- package/dist/parser/javascript-scanner.d.mts.map +1 -0
- package/dist/parser/javascript-scanner.mjs +122 -0
- package/dist/parser/javascript-scanner.mjs.map +1 -0
- package/dist/parser/materialize-cache.d.mts +34 -0
- package/dist/parser/materialize-cache.d.mts.map +1 -0
- package/dist/parser/materialize-cache.mjs +12 -0
- package/dist/parser/materialize-cache.mjs.map +1 -0
- package/dist/parser/materialize-jsx.d.mts +14 -0
- package/dist/parser/materialize-jsx.d.mts.map +1 -0
- package/dist/parser/materialize-jsx.mjs +76 -0
- package/dist/parser/materialize-jsx.mjs.map +1 -0
- package/dist/parser/materialize.d.mts +61 -0
- package/dist/parser/materialize.d.mts.map +1 -0
- package/dist/parser/materialize.mjs +736 -0
- package/dist/parser/materialize.mjs.map +1 -0
- package/dist/parser/recognizer.d.mts +20 -0
- package/dist/parser/recognizer.d.mts.map +1 -0
- package/dist/parser/recognizer.mjs +24 -0
- package/dist/parser/recognizer.mjs.map +1 -0
- package/dist/parser/session.d.mts +42 -0
- package/dist/parser/session.d.mts.map +1 -0
- package/dist/parser/session.mjs +89 -0
- package/dist/parser/session.mjs.map +1 -0
- package/dist/parser.d.mts +25 -0
- package/dist/parser.d.mts.map +1 -0
- package/dist/parser.mjs +37 -0
- package/dist/parser.mjs.map +1 -0
- package/dist/plugin-internal.d.mts +25 -0
- package/dist/plugin-internal.d.mts.map +1 -0
- package/dist/plugin-internal.mjs +99 -0
- package/dist/plugin-internal.mjs.map +1 -0
- package/dist/plugin.d.mts +37 -0
- package/dist/plugin.d.mts.map +1 -0
- package/dist/plugin.mjs +1 -0
- package/dist/plugins/code-block-metadata.d.mts +42 -0
- package/dist/plugins/code-block-metadata.d.mts.map +1 -0
- package/dist/plugins/code-block-metadata.mjs +133 -0
- package/dist/plugins/code-block-metadata.mjs.map +1 -0
- package/dist/plugins/heading-id.d.mts +15 -0
- package/dist/plugins/heading-id.d.mts.map +1 -0
- package/dist/plugins/heading-id.mjs +45 -0
- package/dist/plugins/heading-id.mjs.map +1 -0
- package/dist/plugins/lower-heading.d.mts +16 -0
- package/dist/plugins/lower-heading.d.mts.map +1 -0
- package/dist/plugins/lower-heading.mjs +28 -0
- package/dist/plugins/lower-heading.mjs.map +1 -0
- package/dist/plugins/math-render.d.mts +26 -0
- package/dist/plugins/math-render.d.mts.map +1 -0
- package/dist/plugins/math-render.mjs +51 -0
- package/dist/plugins/math-render.mjs.map +1 -0
- package/dist/plugins/mod.d.mts +9 -5
- package/dist/plugins/mod.mjs +8 -5
- package/dist/plugins/remove-esm.d.mts +10 -0
- package/dist/plugins/remove-esm.d.mts.map +1 -0
- package/dist/plugins/remove-esm.mjs +12 -0
- package/dist/plugins/remove-esm.mjs.map +1 -0
- package/dist/plugins/shiki.d.mts +21 -0
- package/dist/plugins/shiki.d.mts.map +1 -0
- package/dist/plugins/shiki.mjs +144 -0
- package/dist/plugins/shiki.mjs.map +1 -0
- package/dist/plugins/syntax-highlight.d.mts +38 -0
- package/dist/plugins/syntax-highlight.d.mts.map +1 -0
- package/dist/plugins/syntax-highlight.mjs +106 -0
- package/dist/plugins/syntax-highlight.mjs.map +1 -0
- package/dist/processor.d.mts +60 -0
- package/dist/processor.d.mts.map +1 -0
- package/dist/processor.mjs +106 -0
- package/dist/processor.mjs.map +1 -0
- package/dist/ranges.d.mts +10 -0
- package/dist/ranges.d.mts.map +1 -0
- package/dist/ranges.mjs +22 -0
- package/dist/ranges.mjs.map +1 -0
- package/dist/source-map.d.mts +28 -0
- package/dist/source-map.d.mts.map +1 -0
- package/dist/source-map.mjs +90 -0
- package/dist/source-map.mjs.map +1 -0
- package/dist/source-text.d.mts +35 -0
- package/dist/source-text.d.mts.map +1 -0
- package/dist/source-text.mjs +132 -0
- package/dist/source-text.mjs.map +1 -0
- package/dist/source.d.mts +86 -0
- package/dist/source.d.mts.map +1 -0
- package/dist/source.mjs +264 -0
- package/dist/source.mjs.map +1 -0
- package/dist/stream-events.d.mts +59 -0
- package/dist/stream-events.d.mts.map +1 -0
- package/dist/stream-events.mjs +115 -0
- package/dist/stream-events.mjs.map +1 -0
- package/dist/stream-session.d.mts +79 -0
- package/dist/stream-session.d.mts.map +1 -0
- package/dist/stream-session.mjs +904 -0
- package/dist/stream-session.mjs.map +1 -0
- package/dist/stream-tail.d.mts +84 -0
- package/dist/stream-tail.d.mts.map +1 -0
- package/dist/stream-tail.mjs +359 -0
- package/dist/stream-tail.mjs.map +1 -0
- package/dist/stream-types.d.mts +89 -0
- package/dist/stream-types.d.mts.map +1 -0
- package/dist/stream-types.mjs +1 -0
- package/dist/stream.d.mts +28 -0
- package/dist/stream.d.mts.map +1 -0
- package/dist/stream.mjs +68 -0
- package/dist/stream.mjs.map +1 -0
- package/dist/syntax-options.d.mts +21 -0
- package/dist/syntax-options.d.mts.map +1 -0
- package/dist/syntax-options.mjs +26 -0
- package/dist/syntax-options.mjs.map +1 -0
- package/dist/traversal.d.mts +25 -0
- package/dist/traversal.d.mts.map +1 -0
- package/dist/traversal.mjs +136 -0
- package/dist/traversal.mjs.map +1 -0
- package/dist/tree.d.mts +18 -0
- package/dist/tree.d.mts.map +1 -0
- package/dist/tree.mjs +43 -0
- package/dist/tree.mjs.map +1 -0
- package/dist/unified/adapter.d.mts +24 -0
- package/dist/unified/adapter.d.mts.map +1 -0
- package/dist/unified/adapter.mjs +44 -0
- package/dist/unified/adapter.mjs.map +1 -0
- package/dist/unified/mod.d.mts +2 -0
- package/dist/unified/mod.mjs +1 -0
- package/dist/unified/runtime.d.mts +10 -0
- package/dist/unified/runtime.d.mts.map +1 -0
- package/dist/unified/runtime.mjs +115 -0
- package/dist/unified/runtime.mjs.map +1 -0
- package/dist/unified/tree-bridge.d.mts +63 -0
- package/dist/unified/tree-bridge.d.mts.map +1 -0
- package/dist/unified/tree-bridge.mjs +876 -0
- package/dist/unified/tree-bridge.mjs.map +1 -0
- package/dist/uri.d.mts +5 -0
- package/dist/uri.d.mts.map +1 -0
- package/dist/uri.mjs +32 -0
- package/dist/uri.mjs.map +1 -0
- package/package.json +56 -27
- package/dist/plugins/heading-id/plugin.d.mts +0 -17
- package/dist/plugins/heading-id/plugin.d.mts.map +0 -1
- package/dist/plugins/heading-id/plugin.mjs +0 -23
- package/dist/plugins/heading-id/plugin.mjs.map +0 -1
- package/dist/plugins/remove-imports-exports.d.mts +0 -10
- package/dist/plugins/remove-imports-exports.d.mts.map +0 -1
- package/dist/plugins/remove-imports-exports.mjs +0 -15
- package/dist/plugins/remove-imports-exports.mjs.map +0 -1
- package/dist/plugins/syntax-highlight/code-meta.d.mts +0 -22
- package/dist/plugins/syntax-highlight/code-meta.d.mts.map +0 -1
- package/dist/plugins/syntax-highlight/code-meta.mjs +0 -38
- package/dist/plugins/syntax-highlight/code-meta.mjs.map +0 -1
- package/dist/plugins/syntax-highlight/plugin.d.mts +0 -57
- package/dist/plugins/syntax-highlight/plugin.d.mts.map +0 -1
- package/dist/plugins/syntax-highlight/plugin.mjs +0 -93
- package/dist/plugins/syntax-highlight/plugin.mjs.map +0 -1
- package/dist/plugins/tree-processor/plugin.d.mts +0 -19
- package/dist/plugins/tree-processor/plugin.d.mts.map +0 -1
- package/dist/plugins/tree-processor/plugin.mjs +0 -21
- package/dist/plugins/tree-processor/plugin.mjs.map +0 -1
- package/dist/types.d.mts +0 -2
- /package/dist/{types.mjs → parser/block-syntax.mjs} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { runRehypePlugin, runRemarkPlugin } from "./runtime.mjs";
|
|
2
|
+
import { isFunction } from "@temelj/value";
|
|
3
|
+
//#region src/unified/adapter.ts
|
|
4
|
+
var RemarkPluginAdapter = class {
|
|
5
|
+
name;
|
|
6
|
+
#attach;
|
|
7
|
+
constructor(plugin, ...parameters) {
|
|
8
|
+
this.#attach = createAttach(plugin, parameters);
|
|
9
|
+
this.name = `unified:remark:${pluginName(plugin)}`;
|
|
10
|
+
}
|
|
11
|
+
transform(context) {
|
|
12
|
+
return runRemarkPlugin(context, this.#attach);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var RehypePluginAdapter = class {
|
|
16
|
+
name;
|
|
17
|
+
#attach;
|
|
18
|
+
constructor(plugin, ...parameters) {
|
|
19
|
+
this.#attach = createAttach(plugin, parameters);
|
|
20
|
+
this.name = `unified:rehype:${pluginName(plugin)}`;
|
|
21
|
+
}
|
|
22
|
+
transform(context) {
|
|
23
|
+
return runRehypePlugin(context, this.#attach);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function createAttach(plugin, parameters) {
|
|
27
|
+
if (isPreset(plugin)) {
|
|
28
|
+
if (parameters.length !== 0) throw new TypeError("Unified presets do not accept plugin parameters");
|
|
29
|
+
return (processor) => processor.use(plugin);
|
|
30
|
+
}
|
|
31
|
+
return (processor) => {
|
|
32
|
+
processor.use(plugin, ...parameters);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function isPreset(value) {
|
|
36
|
+
return !isFunction(value);
|
|
37
|
+
}
|
|
38
|
+
function pluginName(plugin) {
|
|
39
|
+
return isFunction(plugin) && plugin.name.length > 0 ? plugin.name : "preset";
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { RehypePluginAdapter, RemarkPluginAdapter };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=adapter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.mjs","names":[],"sources":["../../src/unified/adapter.ts"],"sourcesContent":["import type { Preset, Plugin, Transformer } from \"unified\";\n\nimport { isFunction } from \"@temelj/value\";\n\nimport type { HtmlRootNode } from \"../html.ts\";\nimport type { DocumentNode } from \"../model.ts\";\nimport type {\n DocumentPlugin,\n DocumentPluginContext,\n HtmlPlugin,\n HtmlPluginContext,\n} from \"../plugin.ts\";\nimport type { UnifiedAttach } from \"./runtime.ts\";\n\nimport { runRehypePlugin, runRemarkPlugin } from \"./runtime.ts\";\n\ntype UnifiedNode = Parameters<Transformer>[0];\n\nexport type UnifiedAttacher<\n TParameters extends unknown[] = [],\n TInput extends UnifiedNode = UnifiedNode,\n TOutput extends UnifiedNode = TInput,\n> = Plugin<TParameters, TInput, TOutput>;\n\nexport class RemarkPluginAdapter<\n TParameters extends unknown[] = [],\n TInput extends UnifiedNode = UnifiedNode,\n TOutput extends UnifiedNode = TInput,\n> implements DocumentPlugin {\n public readonly name: string;\n readonly #attach: UnifiedAttach;\n\n public constructor(preset: Preset);\n public constructor(\n plugin: UnifiedAttacher<TParameters, TInput, TOutput>,\n ...parameters: TParameters\n );\n public constructor(\n plugin: UnifiedAttacher<TParameters, TInput, TOutput> | Preset,\n ...parameters: TParameters\n ) {\n this.#attach = createAttach(plugin, parameters);\n this.name = `unified:remark:${pluginName(plugin)}`;\n }\n\n public transform(context: DocumentPluginContext): DocumentNode | Promise<DocumentNode> {\n return runRemarkPlugin(context, this.#attach);\n }\n}\n\nexport class RehypePluginAdapter<\n TParameters extends unknown[] = [],\n TInput extends UnifiedNode = UnifiedNode,\n TOutput extends UnifiedNode = TInput,\n> implements HtmlPlugin {\n public readonly name: string;\n readonly #attach: UnifiedAttach;\n\n public constructor(preset: Preset);\n public constructor(\n plugin: UnifiedAttacher<TParameters, TInput, TOutput>,\n ...parameters: TParameters\n );\n public constructor(\n plugin: UnifiedAttacher<TParameters, TInput, TOutput> | Preset,\n ...parameters: TParameters\n ) {\n this.#attach = createAttach(plugin, parameters);\n this.name = `unified:rehype:${pluginName(plugin)}`;\n }\n\n public transform(context: HtmlPluginContext): HtmlRootNode | Promise<HtmlRootNode> {\n return runRehypePlugin(context, this.#attach);\n }\n}\n\nfunction createAttach<\n TParameters extends unknown[],\n TInput extends UnifiedNode,\n TOutput extends UnifiedNode,\n>(\n plugin: UnifiedAttacher<TParameters, TInput, TOutput> | Preset,\n parameters: TParameters,\n): UnifiedAttach {\n if (isPreset(plugin)) {\n if (parameters.length !== 0) {\n throw new TypeError(\"Unified presets do not accept plugin parameters\");\n }\n\n return (processor) => processor.use(plugin);\n }\n\n return (processor) => {\n processor.use(plugin, ...parameters);\n };\n}\n\nfunction isPreset<\n TParameters extends unknown[],\n TInput extends UnifiedNode,\n TOutput extends UnifiedNode,\n>(value: UnifiedAttacher<TParameters, TInput, TOutput> | Preset): value is Preset {\n return !isFunction(value);\n}\n\nfunction pluginName(plugin: Function | Preset): string {\n return isFunction(plugin) && plugin.name.length > 0 ? plugin.name : \"preset\";\n}\n"],"mappings":";;;AAwBA,IAAa,sBAAb,MAI4B;CAC1B;CACA;CAOA,YACE,QACA,GAAG,YACH;EACA,KAAK,UAAU,aAAa,QAAQ,UAAU;EAC9C,KAAK,OAAO,kBAAkB,WAAW,MAAM;CACjD;CAEA,UAAiB,SAAsE;EACrF,OAAO,gBAAgB,SAAS,KAAK,OAAO;CAC9C;AACF;AAEA,IAAa,sBAAb,MAIwB;CACtB;CACA;CAOA,YACE,QACA,GAAG,YACH;EACA,KAAK,UAAU,aAAa,QAAQ,UAAU;EAC9C,KAAK,OAAO,kBAAkB,WAAW,MAAM;CACjD;CAEA,UAAiB,SAAkE;EACjF,OAAO,gBAAgB,SAAS,KAAK,OAAO;CAC9C;AACF;AAEA,SAAS,aAKP,QACA,YACe;CACf,IAAI,SAAS,MAAM,GAAG;EACpB,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,UAAU,iDAAiD;EAGvE,QAAQ,cAAc,UAAU,IAAI,MAAM;CAC5C;CAEA,QAAQ,cAAc;EACpB,UAAU,IAAI,QAAQ,GAAG,UAAU;CACrC;AACF;AAEA,SAAS,SAIP,OAAgF;CAChF,OAAO,CAAC,WAAW,KAAK;AAC1B;AAEA,SAAS,WAAW,QAAmC;CACrD,OAAO,WAAW,MAAM,KAAK,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO;AACtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RehypePluginAdapter, RemarkPluginAdapter } from "./adapter.mjs";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DocumentNode } from "../model.mjs";
|
|
2
|
+
import { HtmlRootNode } from "../html.mjs";
|
|
3
|
+
import { DocumentPluginContext, HtmlPluginContext } from "../plugin.mjs";
|
|
4
|
+
import { Processor } from "unified";
|
|
5
|
+
//#region src/unified/runtime.d.ts
|
|
6
|
+
export type UnifiedAttach = (processor: Processor) => void;
|
|
7
|
+
export declare function runRemarkPlugin(context: DocumentPluginContext, attach: UnifiedAttach): DocumentNode | Promise<DocumentNode>;
|
|
8
|
+
export declare function runRehypePlugin(context: HtmlPluginContext, attach: UnifiedAttach): HtmlRootNode | Promise<HtmlRootNode>;
|
|
9
|
+
//#endregion
|
|
10
|
+
//# sourceMappingURL=runtime.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":["UnifiedProcessor"],"sources":["../../src/unified/runtime.ts"],"mappings":";;;;;YAiBY,iBAAiB,WAAWA;wBAaxB,gBACd,SAAS,uBACT,QAAQ,gBACP,eAAe,QAAQ;wBAUV,gBACd,SAAS,mBACT,QAAQ,gBACP,eAAe,QAAQ"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ConfigurationError } from "../errors.mjs";
|
|
2
|
+
import { UnifiedTreeBridge } from "./tree-bridge.mjs";
|
|
3
|
+
import { isPlainObject, isPromise, isString } from "@temelj/value";
|
|
4
|
+
import { unified } from "unified";
|
|
5
|
+
import { VFile } from "vfile";
|
|
6
|
+
//#region src/unified/runtime.ts
|
|
7
|
+
function runRemarkPlugin(context, attach) {
|
|
8
|
+
const bridge = new UnifiedTreeBridge(context.file);
|
|
9
|
+
return runUnifiedTransform(context.document, context, attach, {
|
|
10
|
+
ecosystem: "Remark",
|
|
11
|
+
decode: (tree) => bridge.fromMdast(tree),
|
|
12
|
+
encode: (document) => bridge.toMdast(document)
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function runRehypePlugin(context, attach) {
|
|
16
|
+
const bridge = new UnifiedTreeBridge(context.file);
|
|
17
|
+
return runUnifiedTransform(context.root, context, attach, {
|
|
18
|
+
ecosystem: "Rehype",
|
|
19
|
+
decode: (tree) => bridge.fromHast(tree),
|
|
20
|
+
encode: (document) => bridge.toHast(document)
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function runUnifiedTransform(original, context, attach, codec) {
|
|
24
|
+
const file = new VFile({ value: context.file.text });
|
|
25
|
+
const processor = unified();
|
|
26
|
+
attach(processor);
|
|
27
|
+
processor.freeze();
|
|
28
|
+
if (processor.parser !== void 0 || processor.compiler !== void 0) throw ConfigurationError.unsupportedUnifiedPlugin();
|
|
29
|
+
let result;
|
|
30
|
+
try {
|
|
31
|
+
result = runPossiblyAsync(processor, codec.encode(original), file, codec.ecosystem);
|
|
32
|
+
} catch (cause) {
|
|
33
|
+
recordMessages(file, context.diagnostics, context.file);
|
|
34
|
+
throw cause;
|
|
35
|
+
}
|
|
36
|
+
const accept = (tree) => recordMessages(file, context.diagnostics, context.file) ? original : codec.decode(tree);
|
|
37
|
+
return isPromise(result) ? result.then(accept, (cause) => {
|
|
38
|
+
recordMessages(file, context.diagnostics, context.file);
|
|
39
|
+
throw cause;
|
|
40
|
+
}) : accept(result);
|
|
41
|
+
}
|
|
42
|
+
function runPossiblyAsync(processor, tree, file, ecosystem) {
|
|
43
|
+
let complete = false;
|
|
44
|
+
let failure;
|
|
45
|
+
let result = stageRoot(tree, ecosystem);
|
|
46
|
+
let finish = (error, transformed) => {
|
|
47
|
+
failure = error ?? void 0;
|
|
48
|
+
if (error === void 0 || error === null) result = stageRoot(transformed, ecosystem);
|
|
49
|
+
complete = true;
|
|
50
|
+
};
|
|
51
|
+
processor.run(tree, file, (error, transformed) => {
|
|
52
|
+
finish(error, transformed);
|
|
53
|
+
});
|
|
54
|
+
if (complete) {
|
|
55
|
+
if (failure !== void 0) throw failure;
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
finish = (error, transformed) => {
|
|
60
|
+
if (error === void 0 || error === null) try {
|
|
61
|
+
resolve(stageRoot(transformed, ecosystem));
|
|
62
|
+
} catch (cause) {
|
|
63
|
+
reject(cause);
|
|
64
|
+
}
|
|
65
|
+
else reject(error);
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function stageRoot(node, ecosystem) {
|
|
70
|
+
if (isRoot(node)) return node;
|
|
71
|
+
if (!isPlainObject(node) || !("type" in node)) throw new TypeError(`${ecosystem} returned a malformed tree instead of root`);
|
|
72
|
+
const type = node.type;
|
|
73
|
+
if (!isString(type)) throw new TypeError(`${ecosystem} returned a malformed tree instead of root`);
|
|
74
|
+
throw new TypeError(`${ecosystem} returned ${JSON.stringify(type)} instead of root`);
|
|
75
|
+
}
|
|
76
|
+
function isRoot(node) {
|
|
77
|
+
return isPlainObject(node) && "type" in node && node.type === "root";
|
|
78
|
+
}
|
|
79
|
+
function recordMessages(file, diagnostics, sourceFile) {
|
|
80
|
+
let fatal = false;
|
|
81
|
+
for (const message of file.messages) {
|
|
82
|
+
fatal ||= message.fatal === true;
|
|
83
|
+
const span = messageSpan(message, sourceFile);
|
|
84
|
+
const diagnostic = {
|
|
85
|
+
severity: message.fatal === true ? "error" : message.fatal === false ? "warning" : "info",
|
|
86
|
+
code: "mdx.plugin.unified",
|
|
87
|
+
message: message.reason
|
|
88
|
+
};
|
|
89
|
+
if (span !== void 0) diagnostic.span = span;
|
|
90
|
+
const notes = [];
|
|
91
|
+
if (message.source !== void 0) notes.push(`source: ${message.source}`);
|
|
92
|
+
if (message.ruleId !== void 0) notes.push(`rule: ${message.ruleId}`);
|
|
93
|
+
if (message.note !== void 0) notes.push(message.note);
|
|
94
|
+
if (notes.length > 0) diagnostic.notes = notes;
|
|
95
|
+
diagnostics.add(diagnostic);
|
|
96
|
+
}
|
|
97
|
+
return fatal;
|
|
98
|
+
}
|
|
99
|
+
function messageSpan(message, file) {
|
|
100
|
+
const place = message.place;
|
|
101
|
+
if (place === void 0) return;
|
|
102
|
+
const startPoint = "start" in place ? place.start : place;
|
|
103
|
+
const endPoint = "end" in place ? place.end : place;
|
|
104
|
+
if (startPoint.offset === void 0 || endPoint.offset === void 0) return;
|
|
105
|
+
if (startPoint.offset < 0 || endPoint.offset < startPoint.offset || endPoint.offset > file.length) return;
|
|
106
|
+
return {
|
|
107
|
+
file,
|
|
108
|
+
start: startPoint.offset,
|
|
109
|
+
end: endPoint.offset
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
export { runRehypePlugin, runRemarkPlugin };
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../src/unified/runtime.ts"],"sourcesContent":["import type { Processor as UnifiedProcessor } from \"unified\";\n\nimport { isString, isPlainObject, isPromise } from \"@temelj/value\";\nimport { unified } from \"unified\";\nimport { VFile } from \"vfile\";\n\ntype VFileMessage = VFile[\"messages\"][number];\n\nimport type { Diagnostic, DiagnosticReporter } from \"../diagnostics.ts\";\nimport type { HtmlRootNode } from \"../html.ts\";\nimport type { DocumentNode } from \"../model.ts\";\nimport type { DocumentPluginContext, HtmlPluginContext } from \"../plugin.ts\";\nimport type { SourceFile } from \"../source.ts\";\n\nimport { ConfigurationError } from \"../errors.ts\";\nimport { UnifiedTreeBridge } from \"./tree-bridge.ts\";\n\nexport type UnifiedAttach = (processor: UnifiedProcessor) => void;\n\ninterface UnifiedTransformContext {\n readonly diagnostics: DiagnosticReporter;\n readonly file: SourceFile;\n}\n\ninterface TreeCodec<TDocument> {\n readonly ecosystem: string;\n decode(tree: unknown): TDocument;\n encode(document: TDocument): Readonly<{ type: string }>;\n}\n\nexport function runRemarkPlugin(\n context: DocumentPluginContext,\n attach: UnifiedAttach,\n): DocumentNode | Promise<DocumentNode> {\n const bridge = new UnifiedTreeBridge(context.file);\n\n return runUnifiedTransform(context.document, context, attach, {\n ecosystem: \"Remark\",\n decode: (tree) => bridge.fromMdast(tree),\n encode: (document) => bridge.toMdast(document),\n });\n}\n\nexport function runRehypePlugin(\n context: HtmlPluginContext,\n attach: UnifiedAttach,\n): HtmlRootNode | Promise<HtmlRootNode> {\n const bridge = new UnifiedTreeBridge(context.file);\n\n return runUnifiedTransform(context.root, context, attach, {\n ecosystem: \"Rehype\",\n decode: (tree) => bridge.fromHast(tree),\n encode: (document) => bridge.toHast(document),\n });\n}\n\nfunction runUnifiedTransform<TDocument>(\n original: TDocument,\n context: UnifiedTransformContext,\n attach: UnifiedAttach,\n codec: TreeCodec<TDocument>,\n): TDocument | Promise<TDocument> {\n const file = new VFile({ value: context.file.text });\n const processor = unified();\n attach(processor);\n processor.freeze();\n\n if (processor.parser !== undefined || processor.compiler !== undefined) {\n throw ConfigurationError.unsupportedUnifiedPlugin();\n }\n\n let result: Readonly<{ type: string }> | Promise<Readonly<{ type: string }>>;\n\n try {\n result = runPossiblyAsync(processor, codec.encode(original), file, codec.ecosystem);\n } catch (cause) {\n recordMessages(file, context.diagnostics, context.file);\n throw cause;\n }\n\n const accept = (tree: Readonly<{ type: string }>): TDocument =>\n recordMessages(file, context.diagnostics, context.file) ? original : codec.decode(tree);\n\n return isPromise(result)\n ? result.then(accept, (cause: unknown) => {\n recordMessages(file, context.diagnostics, context.file);\n throw cause;\n })\n : accept(result);\n}\n\nfunction runPossiblyAsync(\n processor: UnifiedProcessor,\n tree: Readonly<{ type: string }>,\n file: VFile,\n ecosystem: string,\n): Readonly<{ type: string }> | Promise<Readonly<{ type: string }>> {\n let complete = false;\n let failure: Error | undefined;\n let result = stageRoot(tree, ecosystem);\n\n let finish = (error: Error | null | undefined, transformed: unknown): void => {\n failure = error ?? undefined;\n\n if (error === undefined || error === null) {\n result = stageRoot(transformed, ecosystem);\n }\n\n complete = true;\n };\n\n processor.run(tree, file, (error, transformed) => {\n finish(error, transformed);\n });\n\n if (complete) {\n if (failure !== undefined) {\n throw failure;\n }\n\n return result;\n }\n\n return new Promise((resolve, reject) => {\n finish = (error, transformed) => {\n if (error === undefined || error === null) {\n try {\n resolve(stageRoot(transformed, ecosystem));\n } catch (cause) {\n reject(cause);\n }\n } else {\n reject(error);\n }\n };\n });\n}\n\nfunction stageRoot(node: unknown, ecosystem: string): Readonly<{ type: string }> {\n if (isRoot(node)) {\n return node;\n }\n\n if (!isPlainObject(node) || !(\"type\" in node)) {\n throw new TypeError(`${ecosystem} returned a malformed tree instead of root`);\n }\n\n const type = node.type;\n\n if (!isString(type)) {\n throw new TypeError(`${ecosystem} returned a malformed tree instead of root`);\n }\n\n throw new TypeError(`${ecosystem} returned ${JSON.stringify(type)} instead of root`);\n}\n\nfunction isRoot(node: unknown): node is Readonly<{ type: \"root\" }> {\n return isPlainObject(node) && \"type\" in node && node.type === \"root\";\n}\n\ntype UnifiedDiagnostic = { -readonly [K in keyof Diagnostic]: Diagnostic[K] };\n\nfunction recordMessages(\n file: VFile,\n diagnostics: DiagnosticReporter,\n sourceFile: SourceFile,\n): boolean {\n let fatal = false;\n\n for (const message of file.messages) {\n fatal ||= message.fatal === true;\n const span = messageSpan(message, sourceFile);\n\n const diagnostic: UnifiedDiagnostic = {\n severity: message.fatal === true ? \"error\" : message.fatal === false ? \"warning\" : \"info\",\n code: \"mdx.plugin.unified\",\n message: message.reason,\n };\n\n if (span !== undefined) {\n diagnostic.span = span;\n }\n\n const notes: string[] = [];\n\n if (message.source !== undefined) {\n notes.push(`source: ${message.source}`);\n }\n\n if (message.ruleId !== undefined) {\n notes.push(`rule: ${message.ruleId}`);\n }\n\n if (message.note !== undefined) {\n notes.push(message.note);\n }\n\n if (notes.length > 0) {\n diagnostic.notes = notes;\n }\n\n diagnostics.add(diagnostic);\n }\n\n return fatal;\n}\n\nfunction messageSpan(\n message: VFileMessage,\n file: SourceFile,\n): { file: SourceFile; start: number; end: number } | undefined {\n const place = message.place;\n\n if (place === undefined) {\n return undefined;\n }\n\n const startPoint = \"start\" in place ? place.start : place;\n const endPoint = \"end\" in place ? place.end : place;\n\n if (startPoint.offset === undefined || endPoint.offset === undefined) {\n return undefined;\n }\n\n if (\n startPoint.offset < 0 ||\n endPoint.offset < startPoint.offset ||\n endPoint.offset > file.length\n ) {\n return undefined;\n }\n\n return { file, start: startPoint.offset, end: endPoint.offset };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { SourceRange } from "../ranges.mjs";
|
|
2
|
+
import { DocumentNode, MdxNode } from "../model.mjs";
|
|
3
|
+
import { HtmlRootNode } from "../html.mjs";
|
|
4
|
+
import { SourceFile } from "../source.mjs";
|
|
5
|
+
//#region src/unified/tree-bridge.d.ts
|
|
6
|
+
interface UnistRecord {
|
|
7
|
+
readonly type: string;
|
|
8
|
+
readonly align?: unknown;
|
|
9
|
+
readonly alt?: unknown;
|
|
10
|
+
readonly attributes?: unknown;
|
|
11
|
+
readonly checked?: unknown;
|
|
12
|
+
children?: unknown;
|
|
13
|
+
data?: unknown;
|
|
14
|
+
readonly depth?: unknown;
|
|
15
|
+
readonly identifier?: unknown;
|
|
16
|
+
readonly label?: unknown;
|
|
17
|
+
readonly lang?: unknown;
|
|
18
|
+
readonly meta?: unknown;
|
|
19
|
+
readonly name?: unknown;
|
|
20
|
+
readonly ordered?: unknown;
|
|
21
|
+
readonly position?: unknown;
|
|
22
|
+
readonly properties?: unknown;
|
|
23
|
+
readonly referenceType?: unknown;
|
|
24
|
+
readonly spread?: unknown;
|
|
25
|
+
readonly start?: unknown;
|
|
26
|
+
readonly tagName?: unknown;
|
|
27
|
+
readonly title?: unknown;
|
|
28
|
+
readonly url?: unknown;
|
|
29
|
+
readonly value?: unknown;
|
|
30
|
+
}
|
|
31
|
+
interface UnistPosition {
|
|
32
|
+
readonly start: ReturnType<SourceFile["location"]>;
|
|
33
|
+
readonly end: ReturnType<SourceFile["location"]>;
|
|
34
|
+
}
|
|
35
|
+
interface UnistOrigin {
|
|
36
|
+
readonly position?: UnistPosition;
|
|
37
|
+
}
|
|
38
|
+
export declare class UnifiedBoundaryError extends Error {
|
|
39
|
+
constructor(message: string);
|
|
40
|
+
}
|
|
41
|
+
export declare class UnifiedTreeBridge {
|
|
42
|
+
#private;
|
|
43
|
+
private readonly file;
|
|
44
|
+
readonly visiting: WeakSet<object>;
|
|
45
|
+
constructor(file: SourceFile);
|
|
46
|
+
toMdast(document: DocumentNode): UnistRecord;
|
|
47
|
+
fromMdast(root: unknown): DocumentNode;
|
|
48
|
+
toHast(document: HtmlRootNode): UnistRecord;
|
|
49
|
+
fromHast(root: unknown): HtmlRootNode;
|
|
50
|
+
mdxToUnist(node: MdxNode): UnistRecord;
|
|
51
|
+
unistToMdx(value: unknown, mode?: "flow" | "phrasing"): MdxNode;
|
|
52
|
+
private htmlToUnist;
|
|
53
|
+
private unistToHtml;
|
|
54
|
+
/** Restores a semantic node whose inert fallback came back from rehype unchanged. */
|
|
55
|
+
private restoredHtmlNode;
|
|
56
|
+
nodeRecord(value: unknown): UnistRecord;
|
|
57
|
+
private nodeChildren;
|
|
58
|
+
positionBase(origin: SourceRange | undefined): UnistOrigin;
|
|
59
|
+
origin(position: unknown): SourceRange | undefined;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=tree-bridge.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-bridge.d.mts","names":[],"sources":["../../src/unified/tree-bridge.ts"],"mappings":";;;;;UAgCU;WACC;WACA;WACA;WACA;WACA;EACT;EACA;WACS;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;UAGD;WACC,OAAO,WAAW;WAClB,KAAK,WAAW;;UAGjB;WACC,WAAW;;qBAST,6BAA6B;EACxC,YAAmB;;qBAMR;;mBACM;WACD,UAAQ;EAIxB,YAAmB,MAAM;EAIlB,QAAQ,UAAU,eAAe;EAUjC,UAAU,gBAAgB;EAY1B,OAAO,UAAU,eAAe;EAUhC,SAAS,gBAAgB;EAUzB,WAAW,MAAM,UAAU;EAyK3B,WAAW,gBAAgB,6BAAqC;UA4P/D;UAoDA;;UAiDA;EAoBD,WAAW,iBAAiB;UAc3B;EAQD,aAAa,QAAQ,0BAA0B;EAW/C,OAAO,oBAAoB"}
|