@fuzdev/fuz_ui 0.181.0 → 0.182.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/dist/DeclarationDetail.svelte +2 -2
- package/dist/LibraryDetail.svelte +1 -1
- package/dist/Mdz.svelte +1 -1
- package/dist/MdzPrecompiled.svelte +30 -0
- package/dist/MdzPrecompiled.svelte.d.ts +11 -0
- package/dist/MdzPrecompiled.svelte.d.ts.map +1 -0
- package/dist/Spiders.svelte +1 -1
- package/dist/declaration.svelte.d.ts +1 -1
- package/dist/library.svelte.d.ts +1 -1
- package/dist/mdz_to_svelte.d.ts +38 -0
- package/dist/mdz_to_svelte.d.ts.map +1 -0
- package/dist/mdz_to_svelte.js +89 -0
- package/dist/svelte_preprocess_mdz.d.ts +65 -0
- package/dist/svelte_preprocess_mdz.d.ts.map +1 -0
- package/dist/svelte_preprocess_mdz.js +513 -0
- package/dist/tsdoc_mdz.d.ts +1 -1
- package/dist/tsdoc_mdz.js +1 -1
- package/package.json +26 -9
- package/src/lib/mdz_to_svelte.ts +127 -0
- package/src/lib/svelte_preprocess_mdz.ts +726 -0
- package/src/lib/tsdoc_mdz.ts +1 -1
|
@@ -323,13 +323,13 @@
|
|
|
323
323
|
<Mdz content={prop.doc_comment} />
|
|
324
324
|
{/if}
|
|
325
325
|
{#if prop.type_signature}
|
|
326
|
-
<div class="row gap_md">
|
|
326
|
+
<div class="row gap_md mt_lg">
|
|
327
327
|
<strong>type</strong>
|
|
328
328
|
<TypeLink type={prop.type_signature} />
|
|
329
329
|
</div>
|
|
330
330
|
{/if}
|
|
331
331
|
{#if prop.modifiers?.length}
|
|
332
|
-
<div class="row gap_md">
|
|
332
|
+
<div class="row gap_md mt_lg">
|
|
333
333
|
{#each prop.modifiers as modifier (modifier)}
|
|
334
334
|
<span class="chip">{modifier}</span>
|
|
335
335
|
{/each}
|
package/dist/Mdz.svelte
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type {Snippet} from 'svelte';
|
|
3
|
+
import type {SvelteHTMLElements} from 'svelte/elements';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper for precompiled mdz content. Used by `svelte_preprocess_mdz`.
|
|
7
|
+
* Not intended for direct use.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
inline = false,
|
|
14
|
+
nowrap = false,
|
|
15
|
+
children,
|
|
16
|
+
...rest
|
|
17
|
+
}: (SvelteHTMLElements['div'] | SvelteHTMLElements['span']) & {
|
|
18
|
+
inline?: boolean;
|
|
19
|
+
nowrap?: boolean;
|
|
20
|
+
children: Snippet;
|
|
21
|
+
} = $props();
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<svelte:element
|
|
25
|
+
this={inline ? 'span' : 'div'}
|
|
26
|
+
{...rest}
|
|
27
|
+
style:white-space={nowrap ? 'pre' : 'pre-wrap'}
|
|
28
|
+
>
|
|
29
|
+
{@render children()}
|
|
30
|
+
</svelte:element>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { SvelteHTMLElements } from 'svelte/elements';
|
|
3
|
+
type $$ComponentProps = (SvelteHTMLElements['div'] | SvelteHTMLElements['span']) & {
|
|
4
|
+
inline?: boolean;
|
|
5
|
+
nowrap?: boolean;
|
|
6
|
+
children: Snippet;
|
|
7
|
+
};
|
|
8
|
+
declare const MdzPrecompiled: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type MdzPrecompiled = ReturnType<typeof MdzPrecompiled>;
|
|
10
|
+
export default MdzPrecompiled;
|
|
11
|
+
//# sourceMappingURL=MdzPrecompiled.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MdzPrecompiled.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/MdzPrecompiled.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAEvD,KAAK,gBAAgB,GAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAG;IACnF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CAClB,CAAC;AA0BH,QAAA,MAAM,cAAc,sDAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
|
package/dist/Spiders.svelte
CHANGED
|
@@ -12,7 +12,7 @@ export declare class Declaration {
|
|
|
12
12
|
*/
|
|
13
13
|
module_path: string;
|
|
14
14
|
name: string;
|
|
15
|
-
kind: "function" | "class" | "type" | "
|
|
15
|
+
kind: "function" | "class" | "type" | "json" | "variable" | "constructor" | "component" | "css";
|
|
16
16
|
/**
|
|
17
17
|
* GitHub source URL with line number.
|
|
18
18
|
*/
|
package/dist/library.svelte.d.ts
CHANGED
|
@@ -86,7 +86,7 @@ export declare class Library {
|
|
|
86
86
|
declarations?: {
|
|
87
87
|
[x: string]: unknown;
|
|
88
88
|
name: string;
|
|
89
|
-
kind: "function" | "class" | "type" | "
|
|
89
|
+
kind: "function" | "class" | "type" | "json" | "variable" | "constructor" | "component" | "css";
|
|
90
90
|
doc_comment?: string | undefined;
|
|
91
91
|
type_signature?: string | undefined;
|
|
92
92
|
modifiers?: string[] | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts parsed `MdzNode` arrays to Svelte markup strings.
|
|
3
|
+
*
|
|
4
|
+
* Used by the `svelte_preprocess_mdz` preprocessor to expand static `<Mdz content="...">` usages
|
|
5
|
+
* into pre-rendered Svelte markup at build time. The output for each node type matches what
|
|
6
|
+
* `MdzNodeView.svelte` renders at runtime, so precompiled and runtime rendering are identical.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { MdzNode } from './mdz.js';
|
|
11
|
+
/**
|
|
12
|
+
* Result of converting `MdzNode` arrays to Svelte markup.
|
|
13
|
+
*/
|
|
14
|
+
export interface MdzToSvelteResult {
|
|
15
|
+
/** Generated Svelte markup string. */
|
|
16
|
+
markup: string;
|
|
17
|
+
/** Required imports: `Map<local_name, {path, kind}>`. */
|
|
18
|
+
imports: Map<string, {
|
|
19
|
+
path: string;
|
|
20
|
+
kind: 'default' | 'named';
|
|
21
|
+
}>;
|
|
22
|
+
/** Whether content references unconfigured Component or Element tags. */
|
|
23
|
+
has_unconfigured_tags: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converts an array of `MdzNode` to a Svelte markup string.
|
|
27
|
+
*
|
|
28
|
+
* Each node type produces output matching what `MdzNodeView.svelte` renders at runtime.
|
|
29
|
+
* Collects required imports and flags unconfigured component/element references.
|
|
30
|
+
*
|
|
31
|
+
* @param nodes Parsed mdz nodes to render.
|
|
32
|
+
* @param components Component name to import path mapping (e.g., `{Alert: '$lib/Alert.svelte'}`).
|
|
33
|
+
* If content references a component not in this map, `has_unconfigured_tags` is set.
|
|
34
|
+
* @param elements Allowed HTML element names (e.g., `new Set(['aside', 'details'])`).
|
|
35
|
+
* If content references an element not in this set, `has_unconfigured_tags` is set.
|
|
36
|
+
*/
|
|
37
|
+
export declare const mdz_to_svelte: (nodes: Array<MdzNode>, components: Record<string, string>, elements: ReadonlySet<string>) => MdzToSvelteResult;
|
|
38
|
+
//# sourceMappingURL=mdz_to_svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdz_to_svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/mdz_to_svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IAEf,yDAAyD;IACzD,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAA;KAAC,CAAC,CAAC;IAEhE,yEAAyE;IACzE,qBAAqB,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACzB,OAAO,KAAK,CAAC,OAAO,CAAC,EACrB,YAAY,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,UAAU,WAAW,CAAC,MAAM,CAAC,KAC3B,iBAgFF,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts parsed `MdzNode` arrays to Svelte markup strings.
|
|
3
|
+
*
|
|
4
|
+
* Used by the `svelte_preprocess_mdz` preprocessor to expand static `<Mdz content="...">` usages
|
|
5
|
+
* into pre-rendered Svelte markup at build time. The output for each node type matches what
|
|
6
|
+
* `MdzNodeView.svelte` renders at runtime, so precompiled and runtime rendering are identical.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { UnreachableError } from '@fuzdev/fuz_util/error.js';
|
|
11
|
+
import { escape_svelte_text } from '@fuzdev/fuz_util/svelte_preprocess_helpers.js';
|
|
12
|
+
import { escape_js_string } from '@fuzdev/fuz_util/string.js';
|
|
13
|
+
/**
|
|
14
|
+
* Converts an array of `MdzNode` to a Svelte markup string.
|
|
15
|
+
*
|
|
16
|
+
* Each node type produces output matching what `MdzNodeView.svelte` renders at runtime.
|
|
17
|
+
* Collects required imports and flags unconfigured component/element references.
|
|
18
|
+
*
|
|
19
|
+
* @param nodes Parsed mdz nodes to render.
|
|
20
|
+
* @param components Component name to import path mapping (e.g., `{Alert: '$lib/Alert.svelte'}`).
|
|
21
|
+
* If content references a component not in this map, `has_unconfigured_tags` is set.
|
|
22
|
+
* @param elements Allowed HTML element names (e.g., `new Set(['aside', 'details'])`).
|
|
23
|
+
* If content references an element not in this set, `has_unconfigured_tags` is set.
|
|
24
|
+
*/
|
|
25
|
+
export const mdz_to_svelte = (nodes, components, elements) => {
|
|
26
|
+
const imports = new Map();
|
|
27
|
+
let has_unconfigured_tags = false;
|
|
28
|
+
const render_nodes = (children) => {
|
|
29
|
+
return children.map((child) => render_node(child)).join('');
|
|
30
|
+
};
|
|
31
|
+
const render_node = (node) => {
|
|
32
|
+
switch (node.type) {
|
|
33
|
+
case 'Text':
|
|
34
|
+
return escape_svelte_text(node.content);
|
|
35
|
+
case 'Code':
|
|
36
|
+
imports.set('DocsLink', { path: '@fuzdev/fuz_ui/DocsLink.svelte', kind: 'default' });
|
|
37
|
+
return `<DocsLink reference={'${escape_js_string(node.content)}'} />`;
|
|
38
|
+
case 'Codeblock': {
|
|
39
|
+
imports.set('Code', { path: '@fuzdev/fuz_code/Code.svelte', kind: 'default' });
|
|
40
|
+
const lang_attr = node.lang === null ? 'lang={null}' : `lang={'${escape_js_string(node.lang)}'}`;
|
|
41
|
+
return `<Code ${lang_attr} content={'${escape_js_string(node.content)}'} />`;
|
|
42
|
+
}
|
|
43
|
+
case 'Bold':
|
|
44
|
+
return `<strong>${render_nodes(node.children)}</strong>`;
|
|
45
|
+
case 'Italic':
|
|
46
|
+
return `<em>${render_nodes(node.children)}</em>`;
|
|
47
|
+
case 'Strikethrough':
|
|
48
|
+
return `<s>${render_nodes(node.children)}</s>`;
|
|
49
|
+
case 'Link': {
|
|
50
|
+
const children_markup = render_nodes(node.children);
|
|
51
|
+
if (node.link_type === 'internal') {
|
|
52
|
+
if (node.reference.startsWith('#') || node.reference.startsWith('?')) {
|
|
53
|
+
return `<a href={'${escape_js_string(node.reference)}'}>${children_markup}</a>`;
|
|
54
|
+
}
|
|
55
|
+
imports.set('resolve', { path: '$app/paths', kind: 'named' });
|
|
56
|
+
return `<a href={resolve('${escape_js_string(node.reference)}')}>${children_markup}</a>`;
|
|
57
|
+
}
|
|
58
|
+
// External link — matches MdzNodeView: target="_blank" rel="noopener"
|
|
59
|
+
return `<a href={'${escape_js_string(node.reference)}'} target="_blank" rel="noopener">${children_markup}</a>`;
|
|
60
|
+
}
|
|
61
|
+
case 'Paragraph':
|
|
62
|
+
return `<p>${render_nodes(node.children)}</p>`;
|
|
63
|
+
case 'Hr':
|
|
64
|
+
return '<hr />';
|
|
65
|
+
case 'Heading':
|
|
66
|
+
return `<h${node.level}>${render_nodes(node.children)}</h${node.level}>`;
|
|
67
|
+
case 'Element': {
|
|
68
|
+
if (!elements.has(node.name)) {
|
|
69
|
+
has_unconfigured_tags = true;
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
return `<${node.name}>${render_nodes(node.children)}</${node.name}>`;
|
|
73
|
+
}
|
|
74
|
+
case 'Component': {
|
|
75
|
+
const import_path = components[node.name];
|
|
76
|
+
if (!import_path) {
|
|
77
|
+
has_unconfigured_tags = true;
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
imports.set(node.name, { path: import_path, kind: 'default' });
|
|
81
|
+
return `<${node.name}>${render_nodes(node.children)}</${node.name}>`;
|
|
82
|
+
}
|
|
83
|
+
default:
|
|
84
|
+
throw new UnreachableError(node);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const markup = render_nodes(nodes);
|
|
88
|
+
return { markup, imports, has_unconfigured_tags };
|
|
89
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte preprocessor that compiles static `Mdz` content to Svelte markup at build time.
|
|
3
|
+
*
|
|
4
|
+
* Detects `Mdz` components with static string `content` props, parses the mdz content,
|
|
5
|
+
* renders each `MdzNode` to equivalent Svelte markup via `mdz_to_svelte`, and replaces
|
|
6
|
+
* the `Mdz` with `MdzPrecompiled` containing pre-rendered children.
|
|
7
|
+
*
|
|
8
|
+
* Also handles ternary chains (`content={a ? 'x' : b ? 'y' : 'z'}`) where all leaf
|
|
9
|
+
* values are statically resolvable strings, emitting `{#if a}markup_x{:else if b}markup_y{:else}markup_z{/if}`
|
|
10
|
+
* as children of a single `MdzPrecompiled`.
|
|
11
|
+
*
|
|
12
|
+
* Truly dynamic `content` props are left untouched.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
import { type PreprocessorGroup } from 'svelte/compiler';
|
|
17
|
+
/**
|
|
18
|
+
* Options for `svelte_preprocess_mdz`.
|
|
19
|
+
*/
|
|
20
|
+
export interface SveltePreprocessMdzOptions {
|
|
21
|
+
/** File patterns to exclude. */
|
|
22
|
+
exclude?: Array<string | RegExp>;
|
|
23
|
+
/**
|
|
24
|
+
* Component import mapping for mdz content.
|
|
25
|
+
* Key: component name as used in mdz (e.g., 'Alert').
|
|
26
|
+
* Value: import path (e.g., '$lib/Alert.svelte').
|
|
27
|
+
*
|
|
28
|
+
* If mdz content references a component not in this map,
|
|
29
|
+
* that Mdz usage is skipped (left as runtime).
|
|
30
|
+
*/
|
|
31
|
+
components?: Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Allowed HTML elements in mdz content.
|
|
34
|
+
* If mdz content references an element not in this list,
|
|
35
|
+
* that Mdz usage is skipped (left as runtime).
|
|
36
|
+
*/
|
|
37
|
+
elements?: Array<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Import sources that resolve to the Mdz component.
|
|
40
|
+
* Used to verify that `Mdz` in templates refers to fuz_ui's Mdz.svelte.
|
|
41
|
+
*
|
|
42
|
+
* @default ['@fuzdev/fuz_ui/Mdz.svelte']
|
|
43
|
+
*/
|
|
44
|
+
component_imports?: Array<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Import path for the precompiled wrapper component.
|
|
47
|
+
*
|
|
48
|
+
* @default '@fuzdev/fuz_ui/MdzPrecompiled.svelte'
|
|
49
|
+
*/
|
|
50
|
+
compiled_component_import?: string;
|
|
51
|
+
/**
|
|
52
|
+
* How to handle errors during mdz parsing or rendering.
|
|
53
|
+
*
|
|
54
|
+
* @default 'throw' in CI, 'log' otherwise
|
|
55
|
+
*/
|
|
56
|
+
on_error?: 'log' | 'throw';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a Svelte preprocessor that compiles static `Mdz` content at build time.
|
|
60
|
+
*
|
|
61
|
+
* @param options Configuration for component/element resolution and file filtering.
|
|
62
|
+
* @returns A Svelte `PreprocessorGroup` for use in `svelte.config.js`.
|
|
63
|
+
*/
|
|
64
|
+
export declare const svelte_preprocess_mdz: (options?: SveltePreprocessMdzOptions) => PreprocessorGroup;
|
|
65
|
+
//# sourceMappingURL=svelte_preprocess_mdz.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte_preprocess_mdz.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte_preprocess_mdz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAQ,KAAK,iBAAiB,EAAW,MAAM,iBAAiB,CAAC;AA+BxE;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C,gCAAgC;IAChC,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAEjC;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEpC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAElC;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IAEnC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;CAC3B;AAID;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GACjC,UAAS,0BAA+B,KACtC,iBAsFF,CAAC"}
|