components-svelte 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.
- package/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/components/Search.svelte +320 -0
- package/dist/components/Search.svelte.d.ts +31 -0
- package/dist/components/SearchButton.svelte +82 -0
- package/dist/components/SearchButton.svelte.d.ts +13 -0
- package/dist/components/SearchProvider.svelte +87 -0
- package/dist/components/SearchProvider.svelte.d.ts +17 -0
- package/dist/components/accordion/Accordion.svelte +150 -0
- package/dist/components/accordion/Accordion.svelte.d.ts +25 -0
- package/dist/components/accordion/AccordionCover.svelte +68 -0
- package/dist/components/accordion/AccordionCover.svelte.d.ts +13 -0
- package/dist/components/accordion/AccordionGroup.svelte +23 -0
- package/dist/components/accordion/AccordionGroup.svelte.d.ts +8 -0
- package/dist/components/accordion/accordion-url-utils.d.ts +4 -0
- package/dist/components/accordion/accordion-url-utils.js +48 -0
- package/dist/components/accordion/index.d.ts +29 -0
- package/dist/components/accordion/index.js +6 -0
- package/dist/components/badge/Badge.svelte +152 -0
- package/dist/components/badge/Badge.svelte.d.ts +23 -0
- package/dist/components/badge/index.d.ts +1 -0
- package/dist/components/badge/index.js +2 -0
- package/dist/components/callout/Callout.svelte +317 -0
- package/dist/components/callout/Callout.svelte.d.ts +17 -0
- package/dist/components/callout/Check.svelte +9 -0
- package/dist/components/callout/Check.svelte.d.ts +4 -0
- package/dist/components/callout/Danger.svelte +9 -0
- package/dist/components/callout/Danger.svelte.d.ts +4 -0
- package/dist/components/callout/Info.svelte +9 -0
- package/dist/components/callout/Info.svelte.d.ts +4 -0
- package/dist/components/callout/Note.svelte +9 -0
- package/dist/components/callout/Note.svelte.d.ts +4 -0
- package/dist/components/callout/Tip.svelte +9 -0
- package/dist/components/callout/Tip.svelte.d.ts +4 -0
- package/dist/components/callout/Warning.svelte +9 -0
- package/dist/components/callout/Warning.svelte.d.ts +4 -0
- package/dist/components/callout/index.d.ts +8 -0
- package/dist/components/callout/index.js +8 -0
- package/dist/components/card/Card.svelte +172 -0
- package/dist/components/card/Card.svelte.d.ts +21 -0
- package/dist/components/card/index.d.ts +3 -0
- package/dist/components/card/index.js +2 -0
- package/dist/components/code-block/BaseCodeBlock.svelte +249 -0
- package/dist/components/code-block/BaseCodeBlock.svelte.d.ts +10 -0
- package/dist/components/code-block/CodeBlock.svelte +185 -0
- package/dist/components/code-block/CodeBlock.svelte.d.ts +5 -0
- package/dist/components/code-block/CodeFooter.svelte +34 -0
- package/dist/components/code-block/CodeFooter.svelte.d.ts +8 -0
- package/dist/components/code-block/CodeHeader.svelte +52 -0
- package/dist/components/code-block/CodeHeader.svelte.d.ts +11 -0
- package/dist/components/code-block/CopyToClipboardButton.svelte +124 -0
- package/dist/components/code-block/CopyToClipboardButton.svelte.d.ts +4 -0
- package/dist/components/code-block/index.d.ts +10 -0
- package/dist/components/code-block/index.js +5 -0
- package/dist/components/code-block/types.d.ts +85 -0
- package/dist/components/code-block/types.js +1 -0
- package/dist/components/code-group/CodeGroup.svelte +327 -0
- package/dist/components/code-group/CodeGroup.svelte.d.ts +24 -0
- package/dist/components/code-group/CodeGroupSelect.svelte +170 -0
- package/dist/components/code-group/CodeGroupSelect.svelte.d.ts +25 -0
- package/dist/components/code-group/CodeSelectDropdown.svelte +74 -0
- package/dist/components/code-group/CodeSelectDropdown.svelte.d.ts +9 -0
- package/dist/components/code-group/LanguageDropdown.svelte +134 -0
- package/dist/components/code-group/LanguageDropdown.svelte.d.ts +11 -0
- package/dist/components/code-group/LanguageIcon.svelte +24 -0
- package/dist/components/code-group/LanguageIcon.svelte.d.ts +8 -0
- package/dist/components/code-group/context.d.ts +14 -0
- package/dist/components/code-group/context.js +2 -0
- package/dist/components/code-group/index.d.ts +8 -0
- package/dist/components/code-group/index.js +4 -0
- package/dist/components/color/Color.svelte +34 -0
- package/dist/components/color/Color.svelte.d.ts +10 -0
- package/dist/components/color/ColorItem.svelte +140 -0
- package/dist/components/color/ColorItem.svelte.d.ts +10 -0
- package/dist/components/color/ColorRow.svelte +27 -0
- package/dist/components/color/ColorRow.svelte.d.ts +8 -0
- package/dist/components/color/index.d.ts +1 -0
- package/dist/components/color/index.js +8 -0
- package/dist/components/columns/Box.svelte +15 -0
- package/dist/components/columns/Box.svelte.d.ts +7 -0
- package/dist/components/columns/Columns.svelte +31 -0
- package/dist/components/columns/Columns.svelte.d.ts +10 -0
- package/dist/components/columns/constants.d.ts +5 -0
- package/dist/components/columns/constants.js +3 -0
- package/dist/components/columns/index.d.ts +5 -0
- package/dist/components/columns/index.js +3 -0
- package/dist/components/expandable/Expandable.svelte +182 -0
- package/dist/components/expandable/Expandable.svelte.d.ts +22 -0
- package/dist/components/expandable/index.d.ts +3 -0
- package/dist/components/expandable/index.js +2 -0
- package/dist/components/frame/Frame.svelte +118 -0
- package/dist/components/frame/Frame.svelte.d.ts +15 -0
- package/dist/components/frame/index.d.ts +3 -0
- package/dist/components/frame/index.js +2 -0
- package/dist/components/icon/Icon.svelte +129 -0
- package/dist/components/icon/Icon.svelte.d.ts +18 -0
- package/dist/components/icon/index.d.ts +2 -0
- package/dist/components/icon/index.js +1 -0
- package/dist/components/index.d.ts +22 -0
- package/dist/components/index.js +22 -0
- package/dist/components/mermaid/Mermaid.svelte +181 -0
- package/dist/components/mermaid/Mermaid.svelte.d.ts +11 -0
- package/dist/components/mermaid/ZoomControls.svelte +74 -0
- package/dist/components/mermaid/ZoomControls.svelte.d.ts +12 -0
- package/dist/components/mermaid/index.d.ts +7 -0
- package/dist/components/mermaid/index.js +4 -0
- package/dist/components/mermaid/use-pan-zoom.svelte.d.ts +11 -0
- package/dist/components/mermaid/use-pan-zoom.svelte.js +41 -0
- package/dist/components/panel/Panel.svelte +27 -0
- package/dist/components/panel/Panel.svelte.d.ts +9 -0
- package/dist/components/panel/index.d.ts +3 -0
- package/dist/components/panel/index.js +2 -0
- package/dist/components/property/DeprecatedPill.svelte +16 -0
- package/dist/components/property/DeprecatedPill.svelte.d.ts +6 -0
- package/dist/components/property/InfoPill.svelte +32 -0
- package/dist/components/property/InfoPill.svelte.d.ts +10 -0
- package/dist/components/property/ParamHead.svelte +188 -0
- package/dist/components/property/ParamHead.svelte.d.ts +22 -0
- package/dist/components/property/Property.svelte +123 -0
- package/dist/components/property/Property.svelte.d.ts +24 -0
- package/dist/components/property/RequiredPill.svelte +16 -0
- package/dist/components/property/RequiredPill.svelte.d.ts +6 -0
- package/dist/components/property/index.d.ts +11 -0
- package/dist/components/property/index.js +6 -0
- package/dist/components/search/index.d.ts +7 -0
- package/dist/components/search/index.js +4 -0
- package/dist/components/search/use-search.d.ts +9 -0
- package/dist/components/search/use-search.js +6 -0
- package/dist/components/steps/Step.svelte +314 -0
- package/dist/components/steps/Step.svelte.d.ts +26 -0
- package/dist/components/steps/Steps.svelte +51 -0
- package/dist/components/steps/Steps.svelte.d.ts +11 -0
- package/dist/components/steps/constants.d.ts +4 -0
- package/dist/components/steps/constants.js +2 -0
- package/dist/components/steps/context.d.ts +10 -0
- package/dist/components/steps/context.js +2 -0
- package/dist/components/steps/index.d.ts +32 -0
- package/dist/components/steps/index.js +6 -0
- package/dist/components/tabs/Tabs.svelte +254 -0
- package/dist/components/tabs/Tabs.svelte.d.ts +16 -0
- package/dist/components/tabs/TabsItem.svelte +56 -0
- package/dist/components/tabs/TabsItem.svelte.d.ts +15 -0
- package/dist/components/tabs/context.d.ts +20 -0
- package/dist/components/tabs/context.js +2 -0
- package/dist/components/tabs/index.d.ts +27 -0
- package/dist/components/tabs/index.js +5 -0
- package/dist/components/tile/Tile.svelte +124 -0
- package/dist/components/tile/Tile.svelte.d.ts +12 -0
- package/dist/components/tile/index.d.ts +2 -0
- package/dist/components/tile/index.js +1 -0
- package/dist/components/tooltip/Tooltip.svelte +170 -0
- package/dist/components/tooltip/Tooltip.svelte.d.ts +23 -0
- package/dist/components/tooltip/index.d.ts +2 -0
- package/dist/components/tooltip/index.js +1 -0
- package/dist/components/tree/Tree.svelte +226 -0
- package/dist/components/tree/Tree.svelte.d.ts +9 -0
- package/dist/components/tree/TreeFile.svelte +44 -0
- package/dist/components/tree/TreeFile.svelte.d.ts +6 -0
- package/dist/components/tree/TreeFolder.svelte +107 -0
- package/dist/components/tree/TreeFolder.svelte.d.ts +10 -0
- package/dist/components/tree/context.d.ts +3 -0
- package/dist/components/tree/context.js +7 -0
- package/dist/components/tree/index.d.ts +10 -0
- package/dist/components/tree/index.js +9 -0
- package/dist/components/tree/tree-level-context.d.ts +8 -0
- package/dist/components/tree/tree-level-context.js +7 -0
- package/dist/components/tree/use-tree-level.d.ts +3 -0
- package/dist/components/tree/use-tree-level.js +5 -0
- package/dist/components/tree/utils.d.ts +9 -0
- package/dist/components/tree/utils.js +86 -0
- package/dist/components/update/Update.svelte +210 -0
- package/dist/components/update/Update.svelte.d.ts +34 -0
- package/dist/components/update/index.d.ts +4 -0
- package/dist/components/update/index.js +3 -0
- package/dist/components/view/View.svelte +52 -0
- package/dist/components/view/View.svelte.d.ts +14 -0
- package/dist/components/view/index.d.ts +3 -0
- package/dist/components/view/index.js +2 -0
- package/dist/constants/brands.d.ts +2 -0
- package/dist/constants/brands.js +4 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.js +6 -0
- package/dist/constants/selectors.d.ts +125 -0
- package/dist/constants/selectors.js +125 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.js +6 -0
- package/dist/hooks/use-expandable-memory.svelte.d.ts +6 -0
- package/dist/hooks/use-expandable-memory.svelte.js +89 -0
- package/dist/hooks/use-expandable.svelte.d.ts +15 -0
- package/dist/hooks/use-expandable.svelte.js +53 -0
- package/dist/hooks/use-get-shiki-highlighted-html.svelte.d.ts +8 -0
- package/dist/hooks/use-get-shiki-highlighted-html.svelte.js +36 -0
- package/dist/hooks/use-has-hover.d.ts +2 -0
- package/dist/hooks/use-has-hover.js +10 -0
- package/dist/hooks/use-is-dark-theme.svelte.d.ts +3 -0
- package/dist/hooks/use-is-dark-theme.svelte.js +25 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts +3 -0
- package/dist/hooks/use-isomorphic-layout-effect.js +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/styles.css +2 -0
- package/dist/utils/cn.d.ts +3 -0
- package/dist/utils/cn.js +7 -0
- package/dist/utils/copy-to-clipboard.d.ts +4 -0
- package/dist/utils/copy-to-clipboard.js +50 -0
- package/dist/utils/dedent.d.ts +1 -0
- package/dist/utils/dedent.js +125 -0
- package/dist/utils/enhance-video-props.d.ts +4 -0
- package/dist/utils/enhance-video-props.js +25 -0
- package/dist/utils/get-node-text.d.ts +2 -0
- package/dist/utils/get-node-text.js +26 -0
- package/dist/utils/icon-utils.d.ts +18 -0
- package/dist/utils/icon-utils.js +30 -0
- package/dist/utils/is-absolute-url.d.ts +4 -0
- package/dist/utils/is-absolute-url.js +11 -0
- package/dist/utils/is-remote-url.d.ts +2 -0
- package/dist/utils/is-remote-url.js +12 -0
- package/dist/utils/make-marker-ids-unique.d.ts +2 -0
- package/dist/utils/make-marker-ids-unique.js +36 -0
- package/dist/utils/shiki/code-styling.d.ts +13 -0
- package/dist/utils/shiki/code-styling.js +1 -0
- package/dist/utils/shiki/constants.d.ts +21 -0
- package/dist/utils/shiki/constants.js +116 -0
- package/dist/utils/shiki/get-code-styling.d.ts +9 -0
- package/dist/utils/shiki/get-code-styling.js +38 -0
- package/dist/utils/shiki/get-shiki-background-colors.d.ts +20 -0
- package/dist/utils/shiki/get-shiki-background-colors.js +56 -0
- package/dist/utils/shiki/index.d.ts +30 -0
- package/dist/utils/shiki/index.js +209 -0
- package/dist/utils/shiki/lib.d.ts +4 -0
- package/dist/utils/shiki/lib.js +49 -0
- package/dist/utils/shiki/shiki-themes.d.ts +2 -0
- package/dist/utils/shiki/shiki-themes.js +64 -0
- package/dist/utils/shiki/snippet-presets.d.ts +27 -0
- package/dist/utils/shiki/snippet-presets.js +44 -0
- package/dist/utils/shiki/worker-client.d.ts +9 -0
- package/dist/utils/shiki/worker-client.js +22 -0
- package/dist/utils/shiki/worker.d.ts +1 -0
- package/dist/utils/shiki/worker.js +134 -0
- package/dist/utils/slugify.d.ts +2 -0
- package/dist/utils/slugify.js +9 -0
- package/package.json +100 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const SHIKI_THEMES = [
|
|
2
|
+
"andromeeda",
|
|
3
|
+
"aurora-x",
|
|
4
|
+
"ayu-dark",
|
|
5
|
+
"catppuccin-frappe",
|
|
6
|
+
"catppuccin-latte",
|
|
7
|
+
"catppuccin-macchiato",
|
|
8
|
+
"catppuccin-mocha",
|
|
9
|
+
"dark-plus",
|
|
10
|
+
"dracula",
|
|
11
|
+
"dracula-soft",
|
|
12
|
+
"everforest-dark",
|
|
13
|
+
"everforest-light",
|
|
14
|
+
"github-dark",
|
|
15
|
+
"github-dark-default",
|
|
16
|
+
"github-dark-dimmed",
|
|
17
|
+
"github-dark-high-contrast",
|
|
18
|
+
"github-light",
|
|
19
|
+
"github-light-default",
|
|
20
|
+
"github-light-high-contrast",
|
|
21
|
+
"gruvbox-dark-hard",
|
|
22
|
+
"gruvbox-dark-medium",
|
|
23
|
+
"gruvbox-dark-soft",
|
|
24
|
+
"gruvbox-light-hard",
|
|
25
|
+
"gruvbox-light-medium",
|
|
26
|
+
"gruvbox-light-soft",
|
|
27
|
+
"houston",
|
|
28
|
+
"kanagawa-dragon",
|
|
29
|
+
"kanagawa-lotus",
|
|
30
|
+
"kanagawa-wave",
|
|
31
|
+
"laserwave",
|
|
32
|
+
"light-plus",
|
|
33
|
+
"material-theme",
|
|
34
|
+
"material-theme-darker",
|
|
35
|
+
"material-theme-lighter",
|
|
36
|
+
"material-theme-ocean",
|
|
37
|
+
"material-theme-palenight",
|
|
38
|
+
"min-dark",
|
|
39
|
+
"min-light",
|
|
40
|
+
"monokai",
|
|
41
|
+
"night-owl",
|
|
42
|
+
"nord",
|
|
43
|
+
"one-dark-pro",
|
|
44
|
+
"one-light",
|
|
45
|
+
"plastic",
|
|
46
|
+
"poimandres",
|
|
47
|
+
"red",
|
|
48
|
+
"rose-pine",
|
|
49
|
+
"rose-pine-dawn",
|
|
50
|
+
"rose-pine-moon",
|
|
51
|
+
"slack-dark",
|
|
52
|
+
"slack-ochin",
|
|
53
|
+
"snazzy-light",
|
|
54
|
+
"solarized-dark",
|
|
55
|
+
"solarized-light",
|
|
56
|
+
"synthwave-84",
|
|
57
|
+
"tokyo-night",
|
|
58
|
+
"vesper",
|
|
59
|
+
"vitesse-black",
|
|
60
|
+
"vitesse-dark",
|
|
61
|
+
"vitesse-light",
|
|
62
|
+
"css-variables",
|
|
63
|
+
];
|
|
64
|
+
export { SHIKI_THEMES };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type SnippetPreset = {
|
|
2
|
+
/** Canonical identifier (e.g., 'python', 'bash') */
|
|
3
|
+
key: string;
|
|
4
|
+
/** Alternative names that map to this preset (e.g., ['py'] for python) */
|
|
5
|
+
aliases?: string[];
|
|
6
|
+
/** Human-readable name (e.g., "Python", "cURL") */
|
|
7
|
+
displayName: string;
|
|
8
|
+
/** Devicon SVG name if different from key (e.g., 'dot-net' for '.NET') */
|
|
9
|
+
iconKey?: string;
|
|
10
|
+
/** Shiki language for syntax highlighting */
|
|
11
|
+
shikiLanguage: string;
|
|
12
|
+
/** httpsnippet config for code generation */
|
|
13
|
+
httpSnippet?: {
|
|
14
|
+
target: string;
|
|
15
|
+
client?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Central config for API playground language options.
|
|
20
|
+
* Each preset defines: display info, icon, syntax highlighting, and code generation.
|
|
21
|
+
*/
|
|
22
|
+
declare const SNIPPET_PRESETS: SnippetPreset[];
|
|
23
|
+
declare const getPreset: (lang: string) => SnippetPreset | undefined;
|
|
24
|
+
declare const getDisplayName: (lang: string) => string;
|
|
25
|
+
declare const getIconKey: (lang: string) => string | undefined;
|
|
26
|
+
declare const getShikiLanguageFromPreset: (lang: string) => string;
|
|
27
|
+
export { type SnippetPreset, SNIPPET_PRESETS, getPreset, getDisplayName, getIconKey, getShikiLanguageFromPreset };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central config for API playground language options.
|
|
3
|
+
* Each preset defines: display info, icon, syntax highlighting, and code generation.
|
|
4
|
+
*/
|
|
5
|
+
const SNIPPET_PRESETS = [
|
|
6
|
+
{ key: "bash", aliases: ["curl", "sh", "shell"], displayName: "cURL", shikiLanguage: "bash", httpSnippet: { target: "shell" } },
|
|
7
|
+
{ key: "python", aliases: ["py"], displayName: "Python", shikiLanguage: "python", httpSnippet: { target: "python", client: "requests" } },
|
|
8
|
+
{ key: "javascript", aliases: ["js"], displayName: "JavaScript", shikiLanguage: "javascript", httpSnippet: { target: "javascript", client: "fetch" } },
|
|
9
|
+
{ key: "node", aliases: ["nodejs", "node.js"], displayName: "Node.js", iconKey: "node", shikiLanguage: "javascript", httpSnippet: { target: "node", client: "fetch" } },
|
|
10
|
+
{ key: "php", displayName: "PHP", shikiLanguage: "php", httpSnippet: { target: "php", client: "curl" } },
|
|
11
|
+
{ key: "go", aliases: ["golang"], displayName: "Go", shikiLanguage: "go", httpSnippet: { target: "go" } },
|
|
12
|
+
{ key: "java", displayName: "Java", shikiLanguage: "java", httpSnippet: { target: "java" } },
|
|
13
|
+
{ key: "ruby", aliases: ["rb"], displayName: "Ruby", shikiLanguage: "ruby", httpSnippet: { target: "ruby" } },
|
|
14
|
+
{
|
|
15
|
+
key: "powershell",
|
|
16
|
+
displayName: "PowerShell",
|
|
17
|
+
shikiLanguage: "bash", // shiki doesn't have powershell in our LANGS
|
|
18
|
+
httpSnippet: { target: "powershell" },
|
|
19
|
+
},
|
|
20
|
+
{ key: "swift", displayName: "Swift", shikiLanguage: "swift", httpSnippet: { target: "swift" } },
|
|
21
|
+
{ key: "csharp", aliases: ["c#"], displayName: "C#", shikiLanguage: "csharp", httpSnippet: { target: "csharp", client: "restsharp" } },
|
|
22
|
+
{ key: "dotnet", aliases: [".net", ".NET", "dotnet", "dot-net"], displayName: ".NET", iconKey: "dot-net", shikiLanguage: "csharp", httpSnippet: { target: "csharp", client: "restsharp" } },
|
|
23
|
+
{ key: "typescript", aliases: ["ts"], displayName: "TypeScript", shikiLanguage: "typescript", httpSnippet: { target: "javascript", client: "fetch" } },
|
|
24
|
+
{ key: "c", displayName: "C", shikiLanguage: "c", httpSnippet: { target: "c" } },
|
|
25
|
+
{ key: "c++", aliases: ["cpp"], displayName: "C++", shikiLanguage: "c++", iconKey: "cplusplus", httpSnippet: { target: "c" } },
|
|
26
|
+
{ key: "kotlin", aliases: ["kt"], displayName: "Kotlin", shikiLanguage: "kotlin", httpSnippet: { target: "kotlin" } },
|
|
27
|
+
{ key: "rust", aliases: ["rs"], displayName: "Rust", shikiLanguage: "rust", httpSnippet: { target: "rust" } },
|
|
28
|
+
{ key: "dart", aliases: ["flutter"], displayName: "Dart", shikiLanguage: "dart", httpSnippet: { target: "dart" } },
|
|
29
|
+
{ key: "toml", displayName: "TOML", shikiLanguage: "yaml" },
|
|
30
|
+
];
|
|
31
|
+
const presetLookup = new Map();
|
|
32
|
+
for (const preset of SNIPPET_PRESETS) {
|
|
33
|
+
presetLookup.set(preset.key.toLowerCase(), preset);
|
|
34
|
+
for (const alias of preset.aliases ?? [])
|
|
35
|
+
presetLookup.set(alias.toLowerCase(), preset);
|
|
36
|
+
}
|
|
37
|
+
const getPreset = (lang) => presetLookup.get(lang.toLowerCase());
|
|
38
|
+
const getDisplayName = (lang) => getPreset(lang)?.displayName ?? lang;
|
|
39
|
+
const getIconKey = (lang) => {
|
|
40
|
+
const preset = getPreset(lang);
|
|
41
|
+
return preset ? (preset.iconKey ?? preset.key) : undefined;
|
|
42
|
+
};
|
|
43
|
+
const getShikiLanguageFromPreset = (lang) => getPreset(lang)?.shikiLanguage ?? lang;
|
|
44
|
+
export { SNIPPET_PRESETS, getPreset, getDisplayName, getIconKey, getShikiLanguageFromPreset };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Remote } from "comlink";
|
|
2
|
+
import type { ShikiHighlightedHtmlArgs } from "./index";
|
|
3
|
+
type HighlightFn = (props: ShikiHighlightedHtmlArgs) => string | undefined | Promise<string | undefined>;
|
|
4
|
+
type ShikiWorkerInstance = Remote<{
|
|
5
|
+
highlight: HighlightFn;
|
|
6
|
+
ready: () => Promise<void>;
|
|
7
|
+
}> | undefined;
|
|
8
|
+
declare function getShikiWorker(): ShikiWorkerInstance;
|
|
9
|
+
export { getShikiWorker };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { wrap } from "comlink";
|
|
2
|
+
let instance;
|
|
3
|
+
function getShikiWorker() {
|
|
4
|
+
if (typeof Worker === "undefined") {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
if (instance) {
|
|
8
|
+
return instance;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const worker = new Worker(new URL("./worker.ts", import.meta.url), {
|
|
12
|
+
type: "module",
|
|
13
|
+
});
|
|
14
|
+
instance = wrap(worker);
|
|
15
|
+
return instance;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.warn("@mintlify/components: Shiki worker unavailable, using synchronous highlighting", error);
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export { getShikiWorker };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { expose } from "comlink";
|
|
2
|
+
import { transformerMetaHighlight, transformerNotationDiff, transformerNotationFocus, transformerNotationHighlight, } from "@shikijs/transformers";
|
|
3
|
+
import { createHighlighter, hastToHtml } from "shiki";
|
|
4
|
+
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
5
|
+
import { codeStylingToThemeOrThemes } from "./get-code-styling";
|
|
6
|
+
import { getShikiLanguageFromPreset } from "./snippet-presets";
|
|
7
|
+
import { LANGS, LINE_DIFF_ADD_CLASS_NAME, LINE_DIFF_REMOVE_CLASS_NAME, LINE_FOCUS_CLASS_NAME, LINE_HIGHLIGHT_CLASS_NAME, SHIKI_COLOR_REPLACEMENTS, SHIKI_LANG_MAP, THEMES, } from "./constants";
|
|
8
|
+
const matchAlgorithm = {
|
|
9
|
+
matchAlgorithm: "v3",
|
|
10
|
+
};
|
|
11
|
+
const transformers = [
|
|
12
|
+
transformerMetaHighlight({
|
|
13
|
+
className: LINE_HIGHLIGHT_CLASS_NAME,
|
|
14
|
+
}),
|
|
15
|
+
transformerNotationHighlight({
|
|
16
|
+
...matchAlgorithm,
|
|
17
|
+
classActiveLine: LINE_HIGHLIGHT_CLASS_NAME,
|
|
18
|
+
}),
|
|
19
|
+
transformerNotationFocus({
|
|
20
|
+
...matchAlgorithm,
|
|
21
|
+
classActiveLine: LINE_FOCUS_CLASS_NAME,
|
|
22
|
+
}),
|
|
23
|
+
transformerNotationDiff({
|
|
24
|
+
...matchAlgorithm,
|
|
25
|
+
classLineAdd: LINE_DIFF_ADD_CLASS_NAME,
|
|
26
|
+
classLineRemove: LINE_DIFF_REMOVE_CLASS_NAME,
|
|
27
|
+
}),
|
|
28
|
+
];
|
|
29
|
+
let highlighter;
|
|
30
|
+
const engine = createJavaScriptRegexEngine({
|
|
31
|
+
forgiving: true,
|
|
32
|
+
cache: new Map(),
|
|
33
|
+
});
|
|
34
|
+
const ready = createHighlighter({
|
|
35
|
+
themes: [...THEMES],
|
|
36
|
+
langs: [...LANGS],
|
|
37
|
+
engine,
|
|
38
|
+
}).then((resolvedHighlighter) => {
|
|
39
|
+
highlighter = resolvedHighlighter;
|
|
40
|
+
});
|
|
41
|
+
function getShikiLanguage(lang) {
|
|
42
|
+
if (!lang) {
|
|
43
|
+
return "text";
|
|
44
|
+
}
|
|
45
|
+
const possibleStatusCode = Number(lang);
|
|
46
|
+
if (!Number.isNaN(possibleStatusCode) &&
|
|
47
|
+
Number.isFinite(possibleStatusCode) &&
|
|
48
|
+
possibleStatusCode > 99 &&
|
|
49
|
+
possibleStatusCode < 600) {
|
|
50
|
+
return "json";
|
|
51
|
+
}
|
|
52
|
+
const lower = lang.toLowerCase();
|
|
53
|
+
const presetLang = getShikiLanguageFromPreset(lower);
|
|
54
|
+
return SHIKI_LANG_MAP[presetLang] ?? SHIKI_LANG_MAP[lower] ?? "text";
|
|
55
|
+
}
|
|
56
|
+
function getLanguageFromClassName(className, fallback) {
|
|
57
|
+
// biome-ignore lint/performance/useTopLevelRegex: TODO
|
|
58
|
+
const match = /language-(\w+)/.exec(className ?? "");
|
|
59
|
+
return match ? (match[1] ?? "text") : (fallback ?? "text");
|
|
60
|
+
}
|
|
61
|
+
function highlightSync(props) {
|
|
62
|
+
if (!highlighter || !props.codeString) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
let lang;
|
|
66
|
+
if ("language" in props) {
|
|
67
|
+
lang = props.language;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
lang = getLanguageFromClassName(props.className, props.fileName);
|
|
71
|
+
}
|
|
72
|
+
if (!lang || lang === "text") {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const serializer = props.opts?.highlightedLines?.length || props.opts?.focusedLines?.length
|
|
77
|
+
? "codeToHast"
|
|
78
|
+
: "codeToHtml";
|
|
79
|
+
const code = props.codeString.trim();
|
|
80
|
+
const themeOrThemes = codeStylingToThemeOrThemes(props.codeBlockTheme);
|
|
81
|
+
const html = highlighter[serializer](code, {
|
|
82
|
+
lang: getShikiLanguage(lang),
|
|
83
|
+
...themeOrThemes,
|
|
84
|
+
colorReplacements: { ...SHIKI_COLOR_REPLACEMENTS },
|
|
85
|
+
transformers,
|
|
86
|
+
tabindex: false,
|
|
87
|
+
...props.opts,
|
|
88
|
+
});
|
|
89
|
+
if (typeof html !== "object") {
|
|
90
|
+
return html;
|
|
91
|
+
}
|
|
92
|
+
const firstChild = html.children[0];
|
|
93
|
+
if (firstChild?.type === "element" &&
|
|
94
|
+
firstChild.tagName === "pre") {
|
|
95
|
+
const codeElement = firstChild.children[0];
|
|
96
|
+
if (!codeElement?.children) {
|
|
97
|
+
return hastToHtml(html);
|
|
98
|
+
}
|
|
99
|
+
const spanElements = codeElement.children.filter((child) => child.type === "element" && child.tagName === "span");
|
|
100
|
+
spanElements.forEach((child, index) => {
|
|
101
|
+
const actualIndex = index + 1;
|
|
102
|
+
if (typeof child.properties.class === "string") {
|
|
103
|
+
if (props.opts?.highlightedLines?.includes(actualIndex)) {
|
|
104
|
+
child.properties.class += " " + LINE_HIGHLIGHT_CLASS_NAME;
|
|
105
|
+
}
|
|
106
|
+
if (props.opts?.focusedLines?.includes(actualIndex)) {
|
|
107
|
+
child.properties.class += " " + LINE_FOCUS_CLASS_NAME;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (Array.isArray(child.properties.class)) {
|
|
111
|
+
if (props.opts?.highlightedLines?.includes(actualIndex)) {
|
|
112
|
+
child.properties.class.push(LINE_HIGHLIGHT_CLASS_NAME);
|
|
113
|
+
}
|
|
114
|
+
if (props.opts?.focusedLines?.includes(actualIndex)) {
|
|
115
|
+
child.properties.class.push(LINE_FOCUS_CLASS_NAME);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return hastToHtml(html);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error("error getting shiki highlighted html", error);
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function highlight(props) {
|
|
128
|
+
await ready;
|
|
129
|
+
return highlightSync(props);
|
|
130
|
+
}
|
|
131
|
+
async function workerReady() {
|
|
132
|
+
await ready;
|
|
133
|
+
}
|
|
134
|
+
expose({ highlight, ready: workerReady });
|
package/package.json
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "components-svelte",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Svelte 5 components for documentation sites",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Kimenzo",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Kimenzo/components-svelte.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Kimenzo/components-svelte/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/Kimenzo/components-svelte#readme",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"svelte",
|
|
18
|
+
"svelte5",
|
|
19
|
+
"components",
|
|
20
|
+
"documentation",
|
|
21
|
+
"ui",
|
|
22
|
+
"tailwindcss"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20.0.0"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": [
|
|
33
|
+
"**/*.css"
|
|
34
|
+
],
|
|
35
|
+
"svelte": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"svelte": "./dist/index.js",
|
|
41
|
+
"import": "./dist/index.js",
|
|
42
|
+
"default": "./dist/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./styles.css": "./dist/styles.css"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"dev": "vite",
|
|
48
|
+
"build": "vite build",
|
|
49
|
+
"package": "svelte-package",
|
|
50
|
+
"clean:package": "node ./scripts/clean-package-artifacts.mjs",
|
|
51
|
+
"build:css": "tailwindcss -i ./src/app.css -o ./dist/styles.css --minify",
|
|
52
|
+
"build:package": "bun run package && bun run clean:package && bun run build:css",
|
|
53
|
+
"prepublishOnly": "bun run build:package && publint",
|
|
54
|
+
"preview": "vite preview",
|
|
55
|
+
"check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json",
|
|
56
|
+
"storybook": "storybook dev -p 6007 --no-open",
|
|
57
|
+
"build-storybook": "storybook build"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@storybook/addon-docs": "10.2.10",
|
|
61
|
+
"@storybook/addon-svelte-csf": "5.0.8",
|
|
62
|
+
"@storybook/svelte-vite": "10.2.10",
|
|
63
|
+
"@sveltejs/package": "2.5.8",
|
|
64
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
65
|
+
"@tailwindcss/cli": "4.1.18",
|
|
66
|
+
"@tailwindcss/typography": "^0.5.20",
|
|
67
|
+
"@tailwindcss/vite": "^4.1.18",
|
|
68
|
+
"@tsconfig/svelte": "^5.0.8",
|
|
69
|
+
"@types/hast": "3.0.4",
|
|
70
|
+
"@types/lodash": "^4.17.25",
|
|
71
|
+
"@types/node": "^24.13.3",
|
|
72
|
+
"playwright": "^1.62.1",
|
|
73
|
+
"publint": "0.3.24",
|
|
74
|
+
"storybook": "10.2.10",
|
|
75
|
+
"svelte": "5.57.0",
|
|
76
|
+
"svelte-check": "^4.7.6",
|
|
77
|
+
"typescript": "~6.0.2",
|
|
78
|
+
"tailwindcss": "^4.1.18",
|
|
79
|
+
"vite": "^8.2.2"
|
|
80
|
+
},
|
|
81
|
+
"dependencies": {
|
|
82
|
+
"@lucide/svelte": "^0.563.0",
|
|
83
|
+
"@shikijs/types": "3.21.0",
|
|
84
|
+
"@shikijs/transformers": "3.21.0",
|
|
85
|
+
"@sindresorhus/slugify": "^3.0.0",
|
|
86
|
+
"bits-ui": "^2.19.0",
|
|
87
|
+
"clsx": "^2.1.1",
|
|
88
|
+
"color": "^5.0.3",
|
|
89
|
+
"comlink": "4.4.2",
|
|
90
|
+
"hast": "1.0.0",
|
|
91
|
+
"lodash": "^4.18.1",
|
|
92
|
+
"mermaid": "11.16.1",
|
|
93
|
+
"mini-svg-data-uri": "^1.4.4",
|
|
94
|
+
"shiki": "3.21.0",
|
|
95
|
+
"tailwind-merge": "^2.6.0"
|
|
96
|
+
},
|
|
97
|
+
"peerDependencies": {
|
|
98
|
+
"svelte": "^5.57.0"
|
|
99
|
+
}
|
|
100
|
+
}
|