@fldr/ui 0.1.0 → 0.3.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 (56) hide show
  1. package/dist/.build-complete +1 -1
  2. package/dist/chunks/{code-nj2nu6qzxhz6qnkk.js → code-hp2x28uiufmk3elz.js} +2 -4
  3. package/dist/chunks/highlighter-mouttug0tu8xg1i8.js +1364 -0
  4. package/dist/code/server.d.ts +4 -89
  5. package/dist/code/server.js +3 -136
  6. package/dist/code.d.ts +53 -70
  7. package/dist/code.js +186 -327
  8. package/dist/command-line/cli.js +0 -0
  9. package/dist/command-line/commands/add.js +0 -0
  10. package/dist/command-line/commands/ai.js +0 -0
  11. package/dist/command-line/commands/blocks.js +0 -0
  12. package/dist/command-line/commands/doc.js +0 -0
  13. package/dist/command-line/commands/init.js +0 -0
  14. package/dist/command-line/commands/ls.js +0 -0
  15. package/dist/components/code.d.ts +1 -1
  16. package/dist/components/code.js +1 -1
  17. package/dist/highlighter-BT3TakhJ.d.ts +13 -0
  18. package/dist/{index-B9niVl3r.d.ts → index-CNL6VDYZ.d.ts} +2 -4
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/styles/kumo-binding.css +1 -0
  22. package/dist/styles/kumo-standalone.css +1 -1
  23. package/dist/styles/kumo.css +20 -38
  24. package/dist/styles/theme-code.css +142 -0
  25. package/dist/styles/theme-fldr.css +429 -15
  26. package/dist/theming.d.ts +71 -32
  27. package/dist/theming.js +162 -17
  28. package/package.json +2 -4
  29. package/scripts/css-build.ts +1 -0
  30. package/scripts/publish-fldr.ts +50 -8
  31. package/scripts/theme-generator/index.ts +15 -5
  32. package/dist/chunks/bash-jpzh6zbf5237424t.js +0 -3
  33. package/dist/chunks/core-n0de50o00ej2ecfe.js +0 -7177
  34. package/dist/chunks/css-j501gxq1am2gnikh.js +0 -4
  35. package/dist/chunks/diff-g2re0kj6fh27rgg5.js +0 -4
  36. package/dist/chunks/engine-javascript-e9xj8hhz9xfqhpnu.js +0 -3118
  37. package/dist/chunks/engine-oniguruma-ias56ildu01gf939.js +0 -389
  38. package/dist/chunks/github-light-hir7yctc38258pwt.js +0 -5
  39. package/dist/chunks/graphql-n9vlzkvcp2j19p7a.js +0 -16
  40. package/dist/chunks/hcl-ohpfnrffs96hzyj5.js +0 -4
  41. package/dist/chunks/html-nimj6ljkkifnc9ni.js +0 -12
  42. package/dist/chunks/javascript-b6fq9bl50fdj6813.js +0 -4
  43. package/dist/chunks/json-h2g0z143t3cs13d7.js +0 -4
  44. package/dist/chunks/jsonc-jxlzvingck161eej.js +0 -4
  45. package/dist/chunks/jsx-jp7a33937sef92sn.js +0 -4
  46. package/dist/chunks/markdown-eybeqjr58vfygtz1.js +0 -4
  47. package/dist/chunks/python-nrpnmxq4r6yp6fcd.js +0 -4
  48. package/dist/chunks/shellscript-i4m7lo8wi0f5bl8b.js +0 -4
  49. package/dist/chunks/sql-hqp2eekl7qhmxe92.js +0 -4
  50. package/dist/chunks/toml-oyqrgosuct25x413.js +0 -4
  51. package/dist/chunks/tsx-pem8x69upvmibv6l.js +0 -4
  52. package/dist/chunks/typescript-pe5y016phdwbgws7.js +0 -4
  53. package/dist/chunks/vesper-g839e590k3dxnwh3.js +0 -5
  54. package/dist/chunks/wasm-cpasy0o9lsjrm39j.js +0 -8
  55. package/dist/chunks/yaml-kzk5ddyekbyha04v.js +0 -4
  56. package/dist/types-C6in2C8V.d.ts +0 -135
@@ -1,96 +1,11 @@
1
- import { l as SupportedLanguage, s as ShikiEngine } from "../types-C6in2C8V.js";
1
+ import { n as highlightCode, r as normalizeLanguage, t as HighlightCodeOptions } from "../highlighter-BT3TakhJ.js";
2
2
  import { ReactNode } from "react";
3
3
  //#region src/code/server.d.ts
4
- export interface HighlightCodeOptions {
5
- /** Highlighting engine (default: "javascript") */
6
- engine?: ShikiEngine;
7
- }
8
- export interface CreateHighlighterOptions {
9
- /** Highlighting engine (default: "javascript") */
10
- engine?: ShikiEngine;
11
- /** Languages to support */
12
- languages: SupportedLanguage[];
13
- }
14
- export interface ServerHighlighter {
15
- /** Highlight code and return HTML string */
16
- highlight: (code: string, lang: SupportedLanguage) => string;
17
- /** Dispose the highlighter when done */
18
- dispose: () => void;
19
- }
20
- /**
21
- * One-off highlighting for a single code snippet.
22
- *
23
- * Creates a highlighter, highlights the code, and disposes.
24
- * For multiple highlights, use `createServerHighlighter` instead.
25
- *
26
- * Uses hardcoded themes: `github-light` for light mode, `vesper` for dark mode.
27
- *
28
- * @example
29
- * ```tsx
30
- * const html = await highlightCode(code, "tsx");
31
- * ```
32
- */
33
- export declare function highlightCode(code: string, lang: SupportedLanguage, options?: HighlightCodeOptions): Promise<string>;
34
- /**
35
- * Create a reusable highlighter for multiple code snippets.
36
- *
37
- * More efficient than `highlightCode` when highlighting multiple snippets.
38
- * Remember to call `dispose()` when done.
39
- *
40
- * Uses hardcoded themes: `github-light` for light mode, `vesper` for dark mode.
41
- *
42
- * @example
43
- * ```tsx
44
- * const highlighter = await createServerHighlighter({
45
- * languages: ["tsx", "bash", "json"],
46
- * });
47
- *
48
- * const html1 = highlighter.highlight(code1, "tsx");
49
- * const html2 = highlighter.highlight(code2, "bash");
50
- *
51
- * highlighter.dispose();
52
- * ```
53
- */
54
- export declare function createServerHighlighter(options: CreateHighlighterOptions): Promise<ServerHighlighter>;
55
- /**
56
- * Props for the CodeBlock component.
57
- */
58
4
  export interface CodeBlockProps {
59
- /** Pre-rendered HTML from highlightCode() or createServerHighlighter().highlight() */
5
+ /** HTML from `highlightCode`. */
60
6
  html: string;
61
- /** Additional CSS classes for the container */
62
7
  className?: string;
63
8
  }
64
- /**
65
- * Server component that wraps highlighted code HTML with proper styling.
66
- *
67
- * Use this with `highlightCode()` or `createServerHighlighter().highlight()`
68
- * to render syntax-highlighted code blocks with consistent Kumo styling.
69
- *
70
- * @example
71
- * ```tsx
72
- * import { highlightCode, CodeBlock } from "@fldr/ui/code/server";
73
- *
74
- * export default async function Page() {
75
- * const html = await highlightCode(`const x = 1;`, "tsx");
76
- * return <CodeBlock html={html} />;
77
- * }
78
- * ```
79
- *
80
- * @example
81
- * ```tsx
82
- * // With createServerHighlighter for multiple blocks
83
- * const highlighter = await createServerHighlighter({ languages: ["tsx", "bash"] });
84
- *
85
- * return (
86
- * <>
87
- * <CodeBlock html={highlighter.highlight(code1, "tsx")} />
88
- * <CodeBlock html={highlighter.highlight(code2, "bash")} />
89
- * </>
90
- * );
91
- *
92
- * highlighter.dispose();
93
- * ```
94
- */
95
9
  export declare function CodeBlock({ html, className }: CodeBlockProps): ReactNode;
96
- //#endregion
10
+ //#endregion
11
+ export { type HighlightCodeOptions, highlightCode, normalizeLanguage };
@@ -1,139 +1,6 @@
1
+ import { n as normalizeLanguage, t as highlightCode } from "../chunks/highlighter-mouttug0tu8xg1i8.js";
1
2
  import { jsx } from "react/jsx-runtime";
2
3
  //#region src/code/server.tsx
3
- /**
4
- * Pre-bundled languages - only these languages are included in the Kumo bundle.
5
- * Using fine-grained imports from @shikijs/langs to minimize bundle size.
6
- */
7
- const BUNDLED_LANGS = {
8
- javascript: () => import("../chunks/javascript-b6fq9bl50fdj6813.js"),
9
- typescript: () => import("../chunks/typescript-pe5y016phdwbgws7.js"),
10
- jsx: () => import("../chunks/jsx-jp7a33937sef92sn.js"),
11
- tsx: () => import("../chunks/tsx-pem8x69upvmibv6l.js"),
12
- json: () => import("../chunks/json-h2g0z143t3cs13d7.js"),
13
- jsonc: () => import("../chunks/jsonc-jxlzvingck161eej.js"),
14
- html: () => import("../chunks/html-nimj6ljkkifnc9ni.js"),
15
- css: () => import("../chunks/css-j501gxq1am2gnikh.js"),
16
- python: () => import("../chunks/python-nrpnmxq4r6yp6fcd.js"),
17
- yaml: () => import("../chunks/yaml-kzk5ddyekbyha04v.js"),
18
- markdown: () => import("../chunks/markdown-eybeqjr58vfygtz1.js"),
19
- graphql: () => import("../chunks/graphql-n9vlzkvcp2j19p7a.js"),
20
- sql: () => import("../chunks/sql-hqp2eekl7qhmxe92.js"),
21
- bash: () => import("../chunks/bash-jpzh6zbf5237424t.js"),
22
- shell: () => import("../chunks/shellscript-i4m7lo8wi0f5bl8b.js"),
23
- diff: () => import("../chunks/diff-g2re0kj6fh27rgg5.js"),
24
- hcl: () => import("../chunks/hcl-ohpfnrffs96hzyj5.js"),
25
- toml: () => import("../chunks/toml-oyqrgosuct25x413.js")
26
- };
27
- /**
28
- * One-off highlighting for a single code snippet.
29
- *
30
- * Creates a highlighter, highlights the code, and disposes.
31
- * For multiple highlights, use `createServerHighlighter` instead.
32
- *
33
- * Uses hardcoded themes: `github-light` for light mode, `vesper` for dark mode.
34
- *
35
- * @example
36
- * ```tsx
37
- * const html = await highlightCode(code, "tsx");
38
- * ```
39
- */
40
- async function highlightCode(code, lang, options = {}) {
41
- const { createHighlighterCore } = await import("shiki/core");
42
- const engineInstance = (options.engine ?? "javascript") === "wasm" ? await import("shiki/engine/oniguruma").then((m) => m.createOnigurumaEngine(import("shiki/wasm"))) : await import("shiki/engine/javascript").then((m) => m.createJavaScriptRegexEngine());
43
- const [githubLight, vesper] = await Promise.all([import("../chunks/github-light-hir7yctc38258pwt.js"), import("../chunks/vesper-g839e590k3dxnwh3.js")]);
44
- const langModule = await BUNDLED_LANGS[lang]();
45
- const highlighter = await createHighlighterCore({
46
- themes: [githubLight.default, vesper.default],
47
- langs: [langModule.default],
48
- engine: engineInstance
49
- });
50
- const html = highlighter.codeToHtml(code, {
51
- lang,
52
- themes: {
53
- light: "github-light",
54
- dark: "vesper"
55
- }
56
- });
57
- highlighter.dispose();
58
- return html;
59
- }
60
- /**
61
- * Create a reusable highlighter for multiple code snippets.
62
- *
63
- * More efficient than `highlightCode` when highlighting multiple snippets.
64
- * Remember to call `dispose()` when done.
65
- *
66
- * Uses hardcoded themes: `github-light` for light mode, `vesper` for dark mode.
67
- *
68
- * @example
69
- * ```tsx
70
- * const highlighter = await createServerHighlighter({
71
- * languages: ["tsx", "bash", "json"],
72
- * });
73
- *
74
- * const html1 = highlighter.highlight(code1, "tsx");
75
- * const html2 = highlighter.highlight(code2, "bash");
76
- *
77
- * highlighter.dispose();
78
- * ```
79
- */
80
- async function createServerHighlighter(options) {
81
- const { createHighlighterCore } = await import("shiki/core");
82
- const engineInstance = (options.engine ?? "javascript") === "wasm" ? await import("shiki/engine/oniguruma").then((m) => m.createOnigurumaEngine(import("shiki/wasm"))) : await import("shiki/engine/javascript").then((m) => m.createJavaScriptRegexEngine());
83
- const [githubLight, vesper] = await Promise.all([import("../chunks/github-light-hir7yctc38258pwt.js"), import("../chunks/vesper-g839e590k3dxnwh3.js")]);
84
- const validLanguages = options.languages.filter((lang) => lang in BUNDLED_LANGS);
85
- const langModules = await Promise.all(validLanguages.map((lang) => BUNDLED_LANGS[lang]()));
86
- const highlighter = await createHighlighterCore({
87
- themes: [githubLight.default, vesper.default],
88
- langs: langModules.map((m) => m.default),
89
- engine: engineInstance
90
- });
91
- return {
92
- highlight: (code, lang) => {
93
- return highlighter.codeToHtml(code, {
94
- lang,
95
- themes: {
96
- light: "github-light",
97
- dark: "vesper"
98
- }
99
- });
100
- },
101
- dispose: () => {
102
- highlighter.dispose();
103
- }
104
- };
105
- }
106
- /**
107
- * Server component that wraps highlighted code HTML with proper styling.
108
- *
109
- * Use this with `highlightCode()` or `createServerHighlighter().highlight()`
110
- * to render syntax-highlighted code blocks with consistent Kumo styling.
111
- *
112
- * @example
113
- * ```tsx
114
- * import { highlightCode, CodeBlock } from "@fldr/ui/code/server";
115
- *
116
- * export default async function Page() {
117
- * const html = await highlightCode(`const x = 1;`, "tsx");
118
- * return <CodeBlock html={html} />;
119
- * }
120
- * ```
121
- *
122
- * @example
123
- * ```tsx
124
- * // With createServerHighlighter for multiple blocks
125
- * const highlighter = await createServerHighlighter({ languages: ["tsx", "bash"] });
126
- *
127
- * return (
128
- * <>
129
- * <CodeBlock html={highlighter.highlight(code1, "tsx")} />
130
- * <CodeBlock html={highlighter.highlight(code2, "bash")} />
131
- * </>
132
- * );
133
- *
134
- * highlighter.dispose();
135
- * ```
136
- */
137
4
  function CodeBlock({ html, className }) {
138
5
  const containerClass = className ? `group relative w-full min-w-0 rounded-md border border-kumo-fill bg-kumo-base ${className}` : "group relative w-full min-w-0 rounded-md border border-kumo-fill bg-kumo-base";
139
6
  return /* @__PURE__ */ jsx("div", {
@@ -141,11 +8,11 @@ function CodeBlock({ html, className }) {
141
8
  children: /* @__PURE__ */ jsx("div", {
142
9
  className: "overflow-x-auto",
143
10
  children: /* @__PURE__ */ jsx("div", {
144
- className: "kumo-shiki [&>pre]:p-4 [&>pre]:font-mono [&>pre]:text-sm [&>pre]:leading-relaxed",
11
+ className: "kumo-code [&>pre]:p-4",
145
12
  dangerouslySetInnerHTML: { __html: html }
146
13
  })
147
14
  })
148
15
  });
149
16
  }
150
17
  //#endregion
151
- export { CodeBlock, createServerHighlighter, highlightCode };
18
+ export { CodeBlock, highlightCode, normalizeLanguage };
package/dist/code.d.ts CHANGED
@@ -1,82 +1,65 @@
1
- import { a as LanguageAlias, c as ShikiProviderProps, i as LANGUAGE_ALIASES, l as SupportedLanguage, n as CodeHighlightedProps, o as LanguageInput, r as CodeHighlightedVariant, s as ShikiEngine, t as BundledLanguage, u as UseShikiHighlighterResult } from "./types-C6in2C8V.js";
1
+ import { n as highlightCode, r as normalizeLanguage, t as HighlightCodeOptions } from "./highlighter-BT3TakhJ.js";
2
2
  import React from "react";
3
- //#region src/code/provider.d.ts
4
- /**
5
- * Normalize a language identifier to its canonical SupportedLanguage name.
6
- * Returns the canonical name if the input is a known alias or already canonical,
7
- * otherwise returns null.
8
- */
9
- export declare function normalizeLanguage(lang: string): SupportedLanguage | null;
10
- export declare function ShikiProvider({ engine, languages, labels, children }: ShikiProviderProps): React.JSX.Element;
11
- export declare namespace ShikiProvider {
12
- var displayName: string;
3
+ import { HighlightTheme } from "@tanstack/highlight/theme";
4
+ //#region src/code/types.d.ts
5
+ /** Languages Kumo registers with the highlighter. Anything else renders as plain text. */
6
+ type SupportedLanguage = "javascript" | "typescript" | "jsx" | "tsx" | "json" | "jsonc" | "html" | "css" | "python" | "yaml" | "markdown" | "graphql" | "sql" | "bash" | "shell" | "diff" | "toml";
7
+ /** Short names accepted for `lang`. */
8
+ export declare const LANGUAGE_ALIASES: {
9
+ readonly js: "javascript";
10
+ readonly cjs: "javascript";
11
+ readonly mjs: "javascript";
12
+ readonly ts: "typescript";
13
+ readonly cts: "typescript";
14
+ readonly mts: "typescript";
15
+ readonly sh: "bash";
16
+ readonly zsh: "bash";
17
+ readonly yml: "yaml";
18
+ readonly py: "python";
19
+ readonly md: "markdown";
20
+ readonly gql: "graphql";
21
+ };
22
+ type LanguageAlias = keyof typeof LANGUAGE_ALIASES;
23
+ type LanguageInput = SupportedLanguage | LanguageAlias;
24
+ /** @deprecated Use `SupportedLanguage`. */
25
+ type BundledLanguage = SupportedLanguage;
26
+ interface CodeHighlightedLabels {
27
+ /** Copy button label. Default "Copy". */
28
+ copy?: string;
29
+ /** Label shown after copying. Default "Copied!". */
30
+ copied?: string;
31
+ }
32
+ type CodeHighlightedVariant = "default" | "plain";
33
+ interface CodeHighlightedProps {
34
+ /** The source to highlight. */
35
+ code: string;
36
+ /** Language name or alias. Unknown languages render as plain text. */
37
+ lang: LanguageInput | (string & {});
38
+ /** Show line numbers (multi-line code only). */
39
+ showLineNumbers?: boolean;
40
+ /** One-based line numbers to highlight. */
41
+ highlightLines?: number[];
42
+ labels?: CodeHighlightedLabels;
43
+ className?: string;
44
+ /** `default` draws a bordered frame; `plain` has no frame or padding. */
45
+ variant?: CodeHighlightedVariant;
46
+ showCopyButton?: boolean;
13
47
  }
14
48
  //#endregion
15
49
  //#region src/code/code-highlighted.d.ts
16
- /**
17
- * Syntax-highlighted code block powered by Shiki.
18
- *
19
- * Must be used within a ShikiProvider. While Shiki is loading,
20
- * displays code as plain text (no layout shift, immediately readable).
21
- *
22
- * Uses hardcoded themes: `github-light` for light mode, `vesper` for dark mode.
23
- *
24
- * @example
25
- * ```tsx
26
- * import { ShikiProvider, CodeHighlighted } from "@fldr/ui/code";
27
- *
28
- * <ShikiProvider
29
- * engine="javascript"
30
- * languages={['tsx', 'bash']}
31
- * >
32
- * <CodeHighlighted
33
- * code={`const greeting = "Hello!";`}
34
- * lang="tsx"
35
- * showLineNumbers
36
- * showCopyButton
37
- * />
38
- * </ShikiProvider>
39
- * ```
40
- */
41
50
  export declare function CodeHighlighted({ code, lang, variant, showLineNumbers, highlightLines, showCopyButton, labels: labelOverrides, className }: CodeHighlightedProps): React.JSX.Element;
42
51
  export declare namespace CodeHighlighted {
43
52
  var displayName: string;
44
53
  }
45
54
  //#endregion
46
- //#region src/code/use-shiki-highlighter.d.ts
55
+ //#region src/code/theme.d.ts
47
56
  /**
48
- * Hook for accessing Shiki highlighting in custom implementations.
49
- *
50
- * Must be used within a ShikiProvider.
51
- *
52
- * Uses hardcoded themes: `github-light` for light mode, `vesper` for dark mode.
53
- *
54
- * @example
55
- * ```tsx
56
- * import { useShikiHighlighter } from "@fldr/ui/code";
57
- *
58
- * function CustomCodeBlock({ code, lang }) {
59
- * const { highlight, isLoading, isReady, error } = useShikiHighlighter();
60
- *
61
- * if (error) {
62
- * return <div>Failed to load highlighter</div>;
63
- * }
64
- *
65
- * if (isLoading) {
66
- * return <pre><code>{code}</code></pre>;
67
- * }
68
- *
69
- * const html = highlight(code, lang);
70
- *
71
- * // null means highlighting failed — render plain text
72
- * if (html === null) {
73
- * return <pre><code>{code}</code></pre>;
74
- * }
75
- *
76
- * return <pre dangerouslySetInnerHTML={{ __html: html }} />;
77
- * }
78
- * ```
57
+ * CSS for code token colors, switched by Kumo's `data-mode`. Pass other
58
+ * TanStack Highlight themes to restyle code without touching components.
79
59
  */
80
- export declare function useShikiHighlighter(): UseShikiHighlighterResult;
60
+ export declare function generateCodeThemeCSS({ light, dark }?: {
61
+ light?: HighlightTheme;
62
+ dark?: HighlightTheme;
63
+ }): string;
81
64
  //#endregion
82
- export { type BundledLanguage, type CodeHighlightedProps, type CodeHighlightedVariant, LANGUAGE_ALIASES, type LanguageAlias, type LanguageInput, type ShikiEngine, type ShikiProviderProps, type UseShikiHighlighterResult };
65
+ export { type BundledLanguage, type CodeHighlightedLabels, type CodeHighlightedProps, type CodeHighlightedVariant, type HighlightCodeOptions, type LanguageAlias, type LanguageInput, type SupportedLanguage, highlightCode, normalizeLanguage };