@fldr/ui 0.1.0 → 0.3.1
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/.build-complete +1 -1
- package/dist/ai/schemas.d.ts +18 -18
- package/dist/chunks/{code-nj2nu6qzxhz6qnkk.js → code-hp2x28uiufmk3elz.js} +2 -4
- package/dist/chunks/highlighter-mouttug0tu8xg1i8.js +1364 -0
- package/dist/code/server.d.ts +4 -89
- package/dist/code/server.js +3 -136
- package/dist/code.d.ts +53 -70
- package/dist/code.js +186 -327
- package/dist/command-line/cli.js +0 -0
- package/dist/command-line/commands/add.js +0 -0
- package/dist/command-line/commands/ai.js +0 -0
- package/dist/command-line/commands/blocks.js +0 -0
- package/dist/command-line/commands/doc.js +0 -0
- package/dist/command-line/commands/init.js +0 -0
- package/dist/command-line/commands/ls.js +0 -0
- package/dist/components/code.d.ts +1 -1
- package/dist/components/code.js +1 -1
- package/dist/highlighter-BT3TakhJ.d.ts +13 -0
- package/dist/{index-B9niVl3r.d.ts → index-CNL6VDYZ.d.ts} +2 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/styles/kumo-binding.css +1 -0
- package/dist/styles/kumo-standalone.css +1 -1
- package/dist/styles/kumo.css +20 -38
- package/dist/styles/theme-code.css +142 -0
- package/dist/styles/theme-fldr.css +429 -15
- package/dist/theming.d.ts +71 -32
- package/dist/theming.js +162 -17
- package/package.json +2 -4
- package/scripts/css-build.ts +1 -0
- package/scripts/publish-fldr.ts +62 -10
- package/scripts/theme-generator/index.ts +15 -5
- package/dist/chunks/bash-jpzh6zbf5237424t.js +0 -3
- package/dist/chunks/core-n0de50o00ej2ecfe.js +0 -7177
- package/dist/chunks/css-j501gxq1am2gnikh.js +0 -4
- package/dist/chunks/diff-g2re0kj6fh27rgg5.js +0 -4
- package/dist/chunks/engine-javascript-e9xj8hhz9xfqhpnu.js +0 -3118
- package/dist/chunks/engine-oniguruma-ias56ildu01gf939.js +0 -389
- package/dist/chunks/github-light-hir7yctc38258pwt.js +0 -5
- package/dist/chunks/graphql-n9vlzkvcp2j19p7a.js +0 -16
- package/dist/chunks/hcl-ohpfnrffs96hzyj5.js +0 -4
- package/dist/chunks/html-nimj6ljkkifnc9ni.js +0 -12
- package/dist/chunks/javascript-b6fq9bl50fdj6813.js +0 -4
- package/dist/chunks/json-h2g0z143t3cs13d7.js +0 -4
- package/dist/chunks/jsonc-jxlzvingck161eej.js +0 -4
- package/dist/chunks/jsx-jp7a33937sef92sn.js +0 -4
- package/dist/chunks/markdown-eybeqjr58vfygtz1.js +0 -4
- package/dist/chunks/python-nrpnmxq4r6yp6fcd.js +0 -4
- package/dist/chunks/shellscript-i4m7lo8wi0f5bl8b.js +0 -4
- package/dist/chunks/sql-hqp2eekl7qhmxe92.js +0 -4
- package/dist/chunks/toml-oyqrgosuct25x413.js +0 -4
- package/dist/chunks/tsx-pem8x69upvmibv6l.js +0 -4
- package/dist/chunks/typescript-pe5y016phdwbgws7.js +0 -4
- package/dist/chunks/vesper-g839e590k3dxnwh3.js +0 -5
- package/dist/chunks/wasm-cpasy0o9lsjrm39j.js +0 -8
- package/dist/chunks/yaml-kzk5ddyekbyha04v.js +0 -4
- package/dist/types-C6in2C8V.d.ts +0 -135
package/dist/code.js
CHANGED
|
@@ -2,291 +2,49 @@
|
|
|
2
2
|
import { t as cn } from "./chunks/vendor-styling-gs32v7xt5znc8kg0.js";
|
|
3
3
|
import { t as Button } from "./chunks/button-hzvowfkbathmx8yg.js";
|
|
4
4
|
import { t as useCopyFeedback } from "./chunks/use-copy-feedback-gl55ghst0csvpv4j.js";
|
|
5
|
-
import {
|
|
5
|
+
import { n as normalizeLanguage, t as highlightCode } from "./chunks/highlighter-mouttug0tu8xg1i8.js";
|
|
6
|
+
import { useCallback, useMemo } from "react";
|
|
6
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
//#region src/code/
|
|
8
|
-
const ShikiContext = createContext(null);
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/code/types.ts
|
|
11
|
-
/**
|
|
12
|
-
* Common language aliases mapped to their canonical SupportedLanguage names.
|
|
13
|
-
*
|
|
14
|
-
* Markdown code fences often use short aliases (e.g., `js`, `ts`, `sh`) that
|
|
15
|
-
* don't match the canonical grammar names but should resolve to them.
|
|
16
|
-
*
|
|
17
|
-
* Note: `mdx` is intentionally omitted because it has a distinct grammar
|
|
18
|
-
* (Markdown + JSX) that would lose JSX highlighting if mapped to `markdown`.
|
|
19
|
-
*/
|
|
20
|
-
const LANGUAGE_ALIASES = {
|
|
21
|
-
js: "javascript",
|
|
22
|
-
cjs: "javascript",
|
|
23
|
-
mjs: "javascript",
|
|
24
|
-
ts: "typescript",
|
|
25
|
-
cts: "typescript",
|
|
26
|
-
mts: "typescript",
|
|
27
|
-
sh: "bash",
|
|
28
|
-
zsh: "bash",
|
|
29
|
-
yml: "yaml",
|
|
30
|
-
py: "python",
|
|
31
|
-
md: "markdown",
|
|
32
|
-
gql: "graphql"
|
|
33
|
-
};
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/code/provider.tsx
|
|
36
|
-
/**
|
|
37
|
-
* Pre-bundled languages - only these languages are included in the Kumo bundle.
|
|
38
|
-
* Using fine-grained imports from @shikijs/langs to minimize bundle size.
|
|
39
|
-
*/
|
|
40
|
-
const BUNDLED_LANGS = {
|
|
41
|
-
javascript: () => import("./chunks/javascript-b6fq9bl50fdj6813.js"),
|
|
42
|
-
typescript: () => import("./chunks/typescript-pe5y016phdwbgws7.js"),
|
|
43
|
-
jsx: () => import("./chunks/jsx-jp7a33937sef92sn.js"),
|
|
44
|
-
tsx: () => import("./chunks/tsx-pem8x69upvmibv6l.js"),
|
|
45
|
-
json: () => import("./chunks/json-h2g0z143t3cs13d7.js"),
|
|
46
|
-
jsonc: () => import("./chunks/jsonc-jxlzvingck161eej.js"),
|
|
47
|
-
html: () => import("./chunks/html-nimj6ljkkifnc9ni.js"),
|
|
48
|
-
css: () => import("./chunks/css-j501gxq1am2gnikh.js"),
|
|
49
|
-
python: () => import("./chunks/python-nrpnmxq4r6yp6fcd.js"),
|
|
50
|
-
yaml: () => import("./chunks/yaml-kzk5ddyekbyha04v.js"),
|
|
51
|
-
markdown: () => import("./chunks/markdown-eybeqjr58vfygtz1.js"),
|
|
52
|
-
graphql: () => import("./chunks/graphql-n9vlzkvcp2j19p7a.js"),
|
|
53
|
-
sql: () => import("./chunks/sql-hqp2eekl7qhmxe92.js"),
|
|
54
|
-
bash: () => import("./chunks/bash-jpzh6zbf5237424t.js"),
|
|
55
|
-
shell: () => import("./chunks/shellscript-i4m7lo8wi0f5bl8b.js"),
|
|
56
|
-
diff: () => import("./chunks/diff-g2re0kj6fh27rgg5.js"),
|
|
57
|
-
hcl: () => import("./chunks/hcl-ohpfnrffs96hzyj5.js"),
|
|
58
|
-
toml: () => import("./chunks/toml-oyqrgosuct25x413.js")
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Normalize a language identifier to its canonical SupportedLanguage name.
|
|
62
|
-
* Returns the canonical name if the input is a known alias or already canonical,
|
|
63
|
-
* otherwise returns null.
|
|
64
|
-
*/
|
|
65
|
-
function normalizeLanguage(lang) {
|
|
66
|
-
if (lang in BUNDLED_LANGS) return lang;
|
|
67
|
-
if (lang in LANGUAGE_ALIASES) return LANGUAGE_ALIASES[lang];
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
8
|
+
//#region src/code/code-highlighted.tsx
|
|
70
9
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* Shiki is lazy-loaded on first render — no JavaScript is downloaded
|
|
74
|
-
* until this provider mounts. While loading, child components can
|
|
75
|
-
* render code as plain text.
|
|
10
|
+
* Syntax-highlighted code block, powered by TanStack Highlight.
|
|
76
11
|
*
|
|
77
|
-
*
|
|
12
|
+
* Highlighting is synchronous, so there is no provider and no loading state.
|
|
13
|
+
* Token colors come from `styles/theme-code.css` and follow `data-mode`.
|
|
78
14
|
*
|
|
79
15
|
* @example
|
|
80
16
|
* ```tsx
|
|
81
|
-
* import {
|
|
17
|
+
* import { CodeHighlighted } from "@fldr/ui/code";
|
|
82
18
|
*
|
|
83
|
-
*
|
|
84
|
-
* return (
|
|
85
|
-
* <ShikiProvider
|
|
86
|
-
* engine="javascript"
|
|
87
|
-
* languages={['tsx', 'bash', 'json']}
|
|
88
|
-
* >
|
|
89
|
-
* <CodeHighlighted code="const x = 1;" lang="tsx" />
|
|
90
|
-
* </ShikiProvider>
|
|
91
|
-
* );
|
|
92
|
-
* }
|
|
19
|
+
* <CodeHighlighted code={source} lang="tsx" showLineNumbers showCopyButton />
|
|
93
20
|
* ```
|
|
94
21
|
*/
|
|
95
22
|
const DEFAULT_LABELS = {
|
|
96
23
|
copy: "Copy",
|
|
97
24
|
copied: "Copied!"
|
|
98
25
|
};
|
|
99
|
-
function ShikiProvider({ engine, languages, labels, children }) {
|
|
100
|
-
const [state, setState] = useState({
|
|
101
|
-
highlighter: null,
|
|
102
|
-
isLoading: true,
|
|
103
|
-
error: null,
|
|
104
|
-
languages: []
|
|
105
|
-
});
|
|
106
|
-
const languageKey = [...new Set(languages.map((lang) => normalizeLanguage(lang)).filter((lang) => lang !== null))].sort().join(",");
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
let cancelled = false;
|
|
109
|
-
let ownedHighlighter = null;
|
|
110
|
-
const validLanguages = languageKey ? languageKey.split(",") : [];
|
|
111
|
-
setState((prev) => prev.highlighter || prev.error ? {
|
|
112
|
-
highlighter: null,
|
|
113
|
-
isLoading: true,
|
|
114
|
-
error: null,
|
|
115
|
-
languages: []
|
|
116
|
-
} : prev);
|
|
117
|
-
async function initializeShiki() {
|
|
118
|
-
try {
|
|
119
|
-
const { createHighlighterCore } = await import("./chunks/core-n0de50o00ej2ecfe.js");
|
|
120
|
-
const engineInstance = engine === "wasm" ? await import("./chunks/engine-oniguruma-ias56ildu01gf939.js").then((m) => m.createOnigurumaEngine(import("./chunks/wasm-cpasy0o9lsjrm39j.js"))) : await import("./chunks/engine-javascript-e9xj8hhz9xfqhpnu.js").then((m) => m.createJavaScriptRegexEngine());
|
|
121
|
-
const [githubLight, vesper] = await Promise.all([import("./chunks/github-light-hir7yctc38258pwt.js"), import("./chunks/vesper-g839e590k3dxnwh3.js")]);
|
|
122
|
-
const langModules = await Promise.all(validLanguages.map((lang) => BUNDLED_LANGS[lang]()));
|
|
123
|
-
const highlighter = await createHighlighterCore({
|
|
124
|
-
themes: [githubLight.default, vesper.default],
|
|
125
|
-
langs: langModules.map((m) => m.default),
|
|
126
|
-
engine: engineInstance
|
|
127
|
-
});
|
|
128
|
-
if (cancelled) {
|
|
129
|
-
highlighter.dispose();
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
ownedHighlighter = highlighter;
|
|
133
|
-
setState({
|
|
134
|
-
highlighter,
|
|
135
|
-
isLoading: false,
|
|
136
|
-
error: null,
|
|
137
|
-
languages: validLanguages
|
|
138
|
-
});
|
|
139
|
-
} catch (err) {
|
|
140
|
-
if (!cancelled) setState({
|
|
141
|
-
highlighter: null,
|
|
142
|
-
isLoading: false,
|
|
143
|
-
error: err instanceof Error ? err : /* @__PURE__ */ new Error("Failed to load Shiki"),
|
|
144
|
-
languages: []
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
initializeShiki();
|
|
149
|
-
return () => {
|
|
150
|
-
cancelled = true;
|
|
151
|
-
ownedHighlighter?.dispose();
|
|
152
|
-
};
|
|
153
|
-
}, [engine, languageKey]);
|
|
154
|
-
const mergedLabels = useMemo(() => ({
|
|
155
|
-
...DEFAULT_LABELS,
|
|
156
|
-
...labels
|
|
157
|
-
}), [labels]);
|
|
158
|
-
const contextValue = useMemo(() => ({
|
|
159
|
-
highlighter: state.highlighter,
|
|
160
|
-
isLoading: state.isLoading,
|
|
161
|
-
error: state.error,
|
|
162
|
-
languages: state.languages,
|
|
163
|
-
labels: mergedLabels
|
|
164
|
-
}), [
|
|
165
|
-
state.highlighter,
|
|
166
|
-
state.isLoading,
|
|
167
|
-
state.error,
|
|
168
|
-
state.languages,
|
|
169
|
-
mergedLabels
|
|
170
|
-
]);
|
|
171
|
-
return /* @__PURE__ */ jsx(ShikiContext.Provider, {
|
|
172
|
-
value: contextValue,
|
|
173
|
-
children
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
ShikiProvider.displayName = "ShikiProvider";
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/code/use-shiki-highlighter.ts
|
|
179
|
-
/**
|
|
180
|
-
* Hook for accessing Shiki highlighting in custom implementations.
|
|
181
|
-
*
|
|
182
|
-
* Must be used within a ShikiProvider.
|
|
183
|
-
*
|
|
184
|
-
* Uses hardcoded themes: `github-light` for light mode, `vesper` for dark mode.
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* ```tsx
|
|
188
|
-
* import { useShikiHighlighter } from "@fldr/ui/code";
|
|
189
|
-
*
|
|
190
|
-
* function CustomCodeBlock({ code, lang }) {
|
|
191
|
-
* const { highlight, isLoading, isReady, error } = useShikiHighlighter();
|
|
192
|
-
*
|
|
193
|
-
* if (error) {
|
|
194
|
-
* return <div>Failed to load highlighter</div>;
|
|
195
|
-
* }
|
|
196
|
-
*
|
|
197
|
-
* if (isLoading) {
|
|
198
|
-
* return <pre><code>{code}</code></pre>;
|
|
199
|
-
* }
|
|
200
|
-
*
|
|
201
|
-
* const html = highlight(code, lang);
|
|
202
|
-
*
|
|
203
|
-
* // null means highlighting failed — render plain text
|
|
204
|
-
* if (html === null) {
|
|
205
|
-
* return <pre><code>{code}</code></pre>;
|
|
206
|
-
* }
|
|
207
|
-
*
|
|
208
|
-
* return <pre dangerouslySetInnerHTML={{ __html: html }} />;
|
|
209
|
-
* }
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
function useShikiHighlighter() {
|
|
213
|
-
const context = useContext(ShikiContext);
|
|
214
|
-
if (!context) throw new Error("useShikiHighlighter must be used within a ShikiProvider. Wrap your app with <ShikiProvider> from '@fldr/ui/code'.");
|
|
215
|
-
const { highlighter, isLoading, error, languages, labels } = context;
|
|
216
|
-
return {
|
|
217
|
-
highlight: useCallback((code, lang) => {
|
|
218
|
-
if (!highlighter) return null;
|
|
219
|
-
const normalizedLang = normalizeLanguage(lang);
|
|
220
|
-
if (!normalizedLang || !languages.includes(normalizedLang)) {
|
|
221
|
-
console.warn(`[Kumo CodeHighlighted] Language "${lang}" is not in the ShikiProvider's languages list. Add it to the languages array: languages={[...existing, '${normalizedLang || lang}']}. Rendering as plain text.`);
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
try {
|
|
225
|
-
return highlighter.codeToHtml(code, {
|
|
226
|
-
lang: normalizedLang,
|
|
227
|
-
themes: {
|
|
228
|
-
light: "github-light",
|
|
229
|
-
dark: "vesper"
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
} catch (err) {
|
|
233
|
-
console.warn(`[Kumo CodeHighlighted] Failed to highlight code with language "${lang}":`, err);
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
}, [highlighter, languages]),
|
|
237
|
-
isLoading,
|
|
238
|
-
isReady: !isLoading && highlighter !== null,
|
|
239
|
-
error,
|
|
240
|
-
labels
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
//#endregion
|
|
244
|
-
//#region src/code/code-highlighted.tsx
|
|
245
|
-
/**
|
|
246
|
-
* Syntax-highlighted code block powered by Shiki.
|
|
247
|
-
*
|
|
248
|
-
* Must be used within a ShikiProvider. While Shiki is loading,
|
|
249
|
-
* displays code as plain text (no layout shift, immediately readable).
|
|
250
|
-
*
|
|
251
|
-
* Uses hardcoded themes: `github-light` for light mode, `vesper` for dark mode.
|
|
252
|
-
*
|
|
253
|
-
* @example
|
|
254
|
-
* ```tsx
|
|
255
|
-
* import { ShikiProvider, CodeHighlighted } from "@fldr/ui/code";
|
|
256
|
-
*
|
|
257
|
-
* <ShikiProvider
|
|
258
|
-
* engine="javascript"
|
|
259
|
-
* languages={['tsx', 'bash']}
|
|
260
|
-
* >
|
|
261
|
-
* <CodeHighlighted
|
|
262
|
-
* code={`const greeting = "Hello!";`}
|
|
263
|
-
* lang="tsx"
|
|
264
|
-
* showLineNumbers
|
|
265
|
-
* showCopyButton
|
|
266
|
-
* />
|
|
267
|
-
* </ShikiProvider>
|
|
268
|
-
* ```
|
|
269
|
-
*/
|
|
270
26
|
function CodeHighlighted({ code, lang, variant = "default", showLineNumbers = false, highlightLines, showCopyButton = false, labels: labelOverrides, className }) {
|
|
271
|
-
const { highlight, isLoading, error, labels: providerLabels } = useShikiHighlighter();
|
|
272
27
|
const { copied, runCopy } = useCopyFeedback();
|
|
273
28
|
const labels = useMemo(() => ({
|
|
274
|
-
...
|
|
29
|
+
...DEFAULT_LABELS,
|
|
275
30
|
...labelOverrides
|
|
276
|
-
}), [
|
|
31
|
+
}), [labelOverrides]);
|
|
277
32
|
const handleCopy = useCallback(async () => {
|
|
278
33
|
await runCopy(() => navigator.clipboard.writeText(code), (error) => console.error("[Kumo CodeHighlighted] Failed to copy to clipboard:", error));
|
|
279
34
|
}, [code, runCopy]);
|
|
280
|
-
const
|
|
281
|
-
|
|
35
|
+
const isSingleLine = useMemo(() => code.split("\n").length, [code]) === 1;
|
|
36
|
+
const html = useMemo(() => highlightCode(code, lang, {
|
|
37
|
+
lineNumbers: showLineNumbers && !isSingleLine,
|
|
38
|
+
highlightLines
|
|
39
|
+
}), [
|
|
282
40
|
code,
|
|
283
|
-
lang
|
|
41
|
+
lang,
|
|
42
|
+
showLineNumbers,
|
|
43
|
+
isSingleLine,
|
|
44
|
+
highlightLines
|
|
284
45
|
]);
|
|
285
|
-
const lineCount = useMemo(() => code.split("\n").length, [code]);
|
|
286
|
-
const isSingleLine = lineCount === 1;
|
|
287
46
|
const containerClasses = cn("group relative m-0 w-full min-w-0 p-0", variant === "plain" ? "rounded-none border-0 bg-transparent" : "rounded-md border border-kumo-fill bg-kumo-base", showCopyButton && isSingleLine && "flex items-center", className);
|
|
288
|
-
const
|
|
289
|
-
const highlightedCodeClasses = cn("kumo-shiki", "[&_code]:!m-0 [&_code]:!border-0 [&_code]:!bg-transparent [&_code]:!p-0", "[&>pre]:!m-0 [&>pre]:!rounded-none [&>pre]:!border-0 [&>pre]:!bg-transparent", "[&>pre]:font-mono [&>pre]:text-sm [&>pre]:leading-relaxed", variant === "plain" ? "[&>pre]:!p-0" : "[&>pre]:!p-4", variant === "plain" && "[&_.line-highlighted]:!m-0 [&_.line-highlighted]:!w-full [&_.line-highlighted]:!px-0");
|
|
47
|
+
const highlightedCodeClasses = cn("kumo-code", variant === "plain" ? "kumo-code--plain [&>pre]:!p-0" : "[&>pre]:!p-4");
|
|
290
48
|
const copyButton = showCopyButton ? /* @__PURE__ */ jsx("div", {
|
|
291
49
|
className: cn(isSingleLine ? "shrink-0 px-2" : variant === "plain" ? "absolute top-0 right-0" : "absolute top-2 right-2", !copied && "opacity-0 transition-opacity group-hover:opacity-100"),
|
|
292
50
|
children: /* @__PURE__ */ jsx(Button, {
|
|
@@ -297,77 +55,178 @@ function CodeHighlighted({ code, lang, variant = "default", showLineNumbers = fa
|
|
|
297
55
|
children: copied ? labels.copied : labels.copy
|
|
298
56
|
})
|
|
299
57
|
}) : null;
|
|
300
|
-
const lineNumbers = showLineNumbers && !isSingleLine ? /* @__PURE__ */ jsx("div", {
|
|
301
|
-
className: cn("kumo-line-numbers shrink-0 pr-4 text-right font-mono text-sm opacity-40 select-none", variant === "plain" ? "py-0" : "py-4"),
|
|
302
|
-
"aria-hidden": "true",
|
|
303
|
-
children: Array.from({ length: lineCount }, (_, i) => /* @__PURE__ */ jsx("div", {
|
|
304
|
-
className: "leading-relaxed",
|
|
305
|
-
children: i + 1
|
|
306
|
-
}, i + 1))
|
|
307
|
-
}) : null;
|
|
308
|
-
useEffect(() => {
|
|
309
|
-
if (error) console.error("[Kumo CodeHighlighted] Shiki initialization error:", error);
|
|
310
|
-
}, [error]);
|
|
311
|
-
if (isLoading || html === null) return /* @__PURE__ */ jsxs("div", {
|
|
312
|
-
className: containerClasses,
|
|
313
|
-
children: [
|
|
314
|
-
lineNumbers && /* @__PURE__ */ jsxs("div", {
|
|
315
|
-
className: "flex",
|
|
316
|
-
children: [lineNumbers, /* @__PURE__ */ jsx("pre", {
|
|
317
|
-
className: fallbackCodeClasses,
|
|
318
|
-
children: /* @__PURE__ */ jsx("code", {
|
|
319
|
-
className: "!m-0 !border-0 !bg-transparent !p-0",
|
|
320
|
-
children: code
|
|
321
|
-
})
|
|
322
|
-
})]
|
|
323
|
-
}),
|
|
324
|
-
!lineNumbers && /* @__PURE__ */ jsx("pre", {
|
|
325
|
-
className: fallbackCodeClasses,
|
|
326
|
-
children: /* @__PURE__ */ jsx("code", {
|
|
327
|
-
className: "!m-0 !border-0 !bg-transparent !p-0",
|
|
328
|
-
children: code
|
|
329
|
-
})
|
|
330
|
-
}),
|
|
331
|
-
copyButton
|
|
332
|
-
]
|
|
333
|
-
});
|
|
334
58
|
return /* @__PURE__ */ jsxs("div", {
|
|
335
59
|
className: containerClasses,
|
|
336
|
-
children: [
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
dangerouslySetInnerHTML: { __html: processHighlightedHtml(html, highlightLines) }
|
|
344
|
-
})
|
|
345
|
-
})]
|
|
346
|
-
}),
|
|
347
|
-
!lineNumbers && /* @__PURE__ */ jsx("div", {
|
|
348
|
-
className: "overflow-x-auto",
|
|
349
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
350
|
-
className: highlightedCodeClasses,
|
|
351
|
-
dangerouslySetInnerHTML: { __html: processHighlightedHtml(html, highlightLines) }
|
|
352
|
-
})
|
|
353
|
-
}),
|
|
354
|
-
copyButton
|
|
355
|
-
]
|
|
60
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
61
|
+
className: "min-w-0 flex-1 overflow-x-auto",
|
|
62
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
63
|
+
className: highlightedCodeClasses,
|
|
64
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
65
|
+
})
|
|
66
|
+
}), copyButton]
|
|
356
67
|
});
|
|
357
68
|
}
|
|
358
69
|
CodeHighlighted.displayName = "CodeHighlighted";
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region ../../node_modules/.pnpm/@tanstack+highlight@1.2.12/node_modules/@tanstack/highlight/dist/theme.js
|
|
72
|
+
const themeTokenClasses = [
|
|
73
|
+
"token",
|
|
74
|
+
"attr",
|
|
75
|
+
"code-inline",
|
|
76
|
+
"command",
|
|
77
|
+
"comment",
|
|
78
|
+
"deleted",
|
|
79
|
+
"function",
|
|
80
|
+
"heading",
|
|
81
|
+
"inserted",
|
|
82
|
+
"keyword",
|
|
83
|
+
"link",
|
|
84
|
+
"literal",
|
|
85
|
+
"meta",
|
|
86
|
+
"number",
|
|
87
|
+
"operator",
|
|
88
|
+
"property",
|
|
89
|
+
"selector",
|
|
90
|
+
"string",
|
|
91
|
+
"tag",
|
|
92
|
+
"type",
|
|
93
|
+
"variable"
|
|
94
|
+
];
|
|
95
|
+
function createThemeCss(options) {
|
|
96
|
+
const themeCss = (options.themes || [...options.light ? [{
|
|
97
|
+
selector: options.lightSelector || ":root",
|
|
98
|
+
theme: options.light
|
|
99
|
+
}] : [], ...options.dark ? [{
|
|
100
|
+
selector: options.darkSelector || ".dark",
|
|
101
|
+
theme: options.dark
|
|
102
|
+
}] : []]).map(({ selector, theme }) => createThemeRule(selector, theme)).join("\n\n");
|
|
103
|
+
if (options.includeBaseStyles === false) return themeCss;
|
|
104
|
+
return `${themeCss}\n\n${createThemeBaseCss(options)}`;
|
|
105
|
+
}
|
|
106
|
+
function createThemeRule(selector, theme) {
|
|
107
|
+
return `${selector} {
|
|
108
|
+
${[
|
|
109
|
+
` --th-background: ${theme.background};`,
|
|
110
|
+
` --th-token: ${theme.tokens.token || theme.foreground};`,
|
|
111
|
+
...themeTokenClasses.filter((className) => className !== "token").map((className) => ` --th-${className}: ${theme.tokens[className]};`)
|
|
112
|
+
].join("\n")}
|
|
113
|
+
}`;
|
|
114
|
+
}
|
|
115
|
+
function createThemeBaseCss(options = {}) {
|
|
116
|
+
const codeBlockSelector = options.codeBlockSelector || "pre.th-code";
|
|
117
|
+
const lineNumbersSelector = options.lineNumbersSelector || ".th-code--line-numbers";
|
|
118
|
+
return `${codeBlockSelector} {
|
|
119
|
+
overflow-x: auto;
|
|
120
|
+
padding: 1rem;
|
|
121
|
+
background: var(--th-background);
|
|
122
|
+
color: var(--th-token);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
${themeTokenClasses.map((token) => `.th-${token} { color: var(--th-${token}); }`).join("\n")}
|
|
126
|
+
.th-line { display: inline-block; min-width: 100%; width: max-content; }
|
|
127
|
+
${lineNumbersSelector} code { counter-reset: th-line; }
|
|
128
|
+
${lineNumbersSelector} .th-line::before {
|
|
129
|
+
display: inline-block;
|
|
130
|
+
width: 2.5em;
|
|
131
|
+
padding-right: 1em;
|
|
132
|
+
color: var(--th-comment);
|
|
133
|
+
content: attr(data-line);
|
|
134
|
+
text-align: right;
|
|
135
|
+
user-select: none;
|
|
136
|
+
}`;
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region ../../node_modules/.pnpm/@tanstack+highlight@1.2.12/node_modules/@tanstack/highlight/dist/themes/github-dark.js
|
|
140
|
+
const githubDarkTheme = {
|
|
141
|
+
background: "#0d1117",
|
|
142
|
+
foreground: "#c9d1d9",
|
|
143
|
+
name: "github-dark",
|
|
144
|
+
type: "dark",
|
|
145
|
+
tokens: {
|
|
146
|
+
attr: "#79c0ff",
|
|
147
|
+
"code-inline": "#ffa657",
|
|
148
|
+
command: "#d2a8ff",
|
|
149
|
+
comment: "#8b949e",
|
|
150
|
+
deleted: "#ff7b72",
|
|
151
|
+
function: "#d2a8ff",
|
|
152
|
+
heading: "#79c0ff",
|
|
153
|
+
inserted: "#7ee787",
|
|
154
|
+
keyword: "#ff7b72",
|
|
155
|
+
link: "#58a6ff",
|
|
156
|
+
literal: "#79c0ff",
|
|
157
|
+
meta: "#8b949e",
|
|
158
|
+
number: "#79c0ff",
|
|
159
|
+
operator: "#d2a8ff",
|
|
160
|
+
property: "#79c0ff",
|
|
161
|
+
selector: "#7ee787",
|
|
162
|
+
string: "#a5d6ff",
|
|
163
|
+
tag: "#7ee787",
|
|
164
|
+
token: "#c9d1d9",
|
|
165
|
+
type: "#ffa657",
|
|
166
|
+
variable: "#ffa657"
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region ../../node_modules/.pnpm/@tanstack+highlight@1.2.12/node_modules/@tanstack/highlight/dist/themes/github-light.js
|
|
171
|
+
const githubLightTheme = {
|
|
172
|
+
background: "#ffffff",
|
|
173
|
+
foreground: "#24292f",
|
|
174
|
+
name: "github-light",
|
|
175
|
+
type: "light",
|
|
176
|
+
tokens: {
|
|
177
|
+
attr: "#0550ae",
|
|
178
|
+
"code-inline": "#953800",
|
|
179
|
+
command: "#8250df",
|
|
180
|
+
comment: "#6e7781",
|
|
181
|
+
deleted: "#cf222e",
|
|
182
|
+
function: "#8250df",
|
|
183
|
+
heading: "#0550ae",
|
|
184
|
+
inserted: "#1a7f37",
|
|
185
|
+
keyword: "#cf222e",
|
|
186
|
+
link: "#0969da",
|
|
187
|
+
literal: "#0550ae",
|
|
188
|
+
meta: "#57606a",
|
|
189
|
+
number: "#0550ae",
|
|
190
|
+
operator: "#8250df",
|
|
191
|
+
property: "#0550ae",
|
|
192
|
+
selector: "#116329",
|
|
193
|
+
string: "#0a7f64",
|
|
194
|
+
tag: "#116329",
|
|
195
|
+
token: "#24292f",
|
|
196
|
+
type: "#953800",
|
|
197
|
+
variable: "#953800"
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/code/theme.ts
|
|
359
202
|
/**
|
|
360
|
-
*
|
|
361
|
-
*
|
|
203
|
+
* CSS for code token colors, switched by Kumo's `data-mode`. Pass other
|
|
204
|
+
* TanStack Highlight themes to restyle code without touching components.
|
|
362
205
|
*/
|
|
363
|
-
function
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
});
|
|
206
|
+
function generateCodeThemeCSS({ light = githubLightTheme, dark = githubDarkTheme } = {}) {
|
|
207
|
+
return `/* Code highlighting colors. Generated by generateCodeThemeCSS(). */\n@layer base {\n${createThemeCss({
|
|
208
|
+
light,
|
|
209
|
+
dark,
|
|
210
|
+
lightSelector: ":root, [data-mode=\"light\"]",
|
|
211
|
+
darkSelector: ":root[data-mode=\"dark\"], [data-mode=\"dark\"]"
|
|
212
|
+
}).trim().split("\n").map((line) => line ? ` ${line}` : line).join("\n")}\n}\n`;
|
|
371
213
|
}
|
|
372
214
|
//#endregion
|
|
373
|
-
|
|
215
|
+
//#region src/code/types.ts
|
|
216
|
+
/** Short names accepted for `lang`. */
|
|
217
|
+
const LANGUAGE_ALIASES = {
|
|
218
|
+
js: "javascript",
|
|
219
|
+
cjs: "javascript",
|
|
220
|
+
mjs: "javascript",
|
|
221
|
+
ts: "typescript",
|
|
222
|
+
cts: "typescript",
|
|
223
|
+
mts: "typescript",
|
|
224
|
+
sh: "bash",
|
|
225
|
+
zsh: "bash",
|
|
226
|
+
yml: "yaml",
|
|
227
|
+
py: "python",
|
|
228
|
+
md: "markdown",
|
|
229
|
+
gql: "graphql"
|
|
230
|
+
};
|
|
231
|
+
//#endregion
|
|
232
|
+
export { CodeHighlighted, LANGUAGE_ALIASES, generateCodeThemeCSS, highlightCode, normalizeLanguage };
|
package/dist/command-line/cli.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as CodeLang, i as CodeBlockProps, n as Code, o as CodeProps, r as CodeBlock, t as BundledLanguage } from "../index-
|
|
1
|
+
import { a as CodeLang, i as CodeBlockProps, n as Code, o as CodeProps, r as CodeBlock, t as BundledLanguage } from "../index-CNL6VDYZ.js";
|
|
2
2
|
export { type BundledLanguage, Code, CodeBlock, type CodeBlockProps, type CodeLang, type CodeProps };
|
package/dist/components/code.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/code/highlighter.d.ts
|
|
2
|
+
interface HighlightCodeOptions {
|
|
3
|
+
/** Prefix each line with its number. */
|
|
4
|
+
lineNumbers?: boolean;
|
|
5
|
+
/** One-based line numbers to mark with the `line-highlighted` class. */
|
|
6
|
+
highlightLines?: number[];
|
|
7
|
+
}
|
|
8
|
+
/** Highlight code to an HTML string (`<pre class="th-code">…</pre>`). Safe to call during SSR. */
|
|
9
|
+
declare function highlightCode(code: string, lang: string, options?: HighlightCodeOptions): string;
|
|
10
|
+
/** Resolve a language name or alias (`ts`, `bash`, `yml`) to the highlighter's canonical name. */
|
|
11
|
+
declare function normalizeLanguage(lang: string): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { highlightCode as n, normalizeLanguage as r, HighlightCodeOptions as t };
|
|
@@ -87,10 +87,8 @@ interface CodeProps extends KumoCodeVariantsProps {
|
|
|
87
87
|
* <Code code="const x = 1;" lang="ts" />
|
|
88
88
|
*
|
|
89
89
|
* // After
|
|
90
|
-
* import {
|
|
91
|
-
* <
|
|
92
|
-
* <CodeHighlighted code="const x = 1;" lang="tsx" />
|
|
93
|
-
* </ShikiProvider>
|
|
90
|
+
* import { CodeHighlighted } from "@fldr/ui/code";
|
|
91
|
+
* <CodeHighlighted code="const x = 1;" lang="tsx" />
|
|
94
92
|
* ```
|
|
95
93
|
*/
|
|
96
94
|
declare function CodeComponent({ code, lang, className, style }: CodeProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { C as TimeseriesChart, S as KumoChartOption, _ as SankeyTooltipParams, a
|
|
|
11
11
|
import { a as CheckboxLegendProps, n as CheckboxChangeEventDetails, o as CheckboxProps, t as Checkbox } from "./index-DjSGDESy.js";
|
|
12
12
|
import { t as ClipboardText } from "./index-CReGk3Dc.js";
|
|
13
13
|
import { a as CloudflareLogoSvgVariant, c as KUMO_CLOUDFLARE_LOGO_DEFAULT_VARIANTS, d as PoweredByCloudflareProps, f as generateCloudflareLogoSvg, i as CloudflareLogoSvgColor, l as KUMO_CLOUDFLARE_LOGO_VARIANTS, n as CloudflareLogoColor, o as CloudflareLogoVariant, r as CloudflareLogoProps, s as GenerateCloudflareLogoSvgOptions, t as CloudflareLogo, u as PoweredByCloudflare } from "./index-CYoiniZ4.js";
|
|
14
|
-
import { n as Code, r as CodeBlock } from "./index-
|
|
14
|
+
import { n as Code, r as CodeBlock } from "./index-CNL6VDYZ.js";
|
|
15
15
|
import { a as CollapsibleProps, i as CollapsiblePanelProps, n as CollapsibleDefaultPanelProps, o as CollapsibleRootProps, r as CollapsibleDefaultTriggerProps, s as CollapsibleTriggerProps, t as Collapsible } from "./index-CzTgKPh-.js";
|
|
16
16
|
import { n as PortalContainer, t as KumoPortalProvider } from "./portal-provider-BAqPpq_a.js";
|
|
17
17
|
import { n as Combobox } from "./index-DxOyYZaJ.js";
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import { t as InputGroup } from "./chunks/input-group-h9fepskc84e1h11n.js";
|
|
|
21
21
|
import { t as ClipboardText } from "./chunks/clipboard-text-oukrnke1s3kebk3y.js";
|
|
22
22
|
import { t as Text } from "./chunks/text-nqum95flcp07ac9s.js";
|
|
23
23
|
import { i as KUMO_INLINE_COPY_TEXT_VARIANTS, n as KUMO_INLINE_COPY_TEXT_DEFAULT_VARIANTS, r as KUMO_INLINE_COPY_TEXT_STYLING, t as InlineCopyText } from "./chunks/inline-copy-text-izxpvnrtebcqlquf.js";
|
|
24
|
-
import { n as CodeBlock, t as Code } from "./chunks/code-
|
|
24
|
+
import { n as CodeBlock, t as Code } from "./chunks/code-hp2x28uiufmk3elz.js";
|
|
25
25
|
import { t as Combobox } from "./chunks/combobox-mzvobpvalz2gnpli.js";
|
|
26
26
|
import { n as KUMO_TOOLBAR_VARIANTS, r as Toolbar, t as KUMO_TOOLBAR_DEFAULT_VARIANTS } from "./chunks/toolbar-kh6pc12ii7b6dv1x.js";
|
|
27
27
|
import { t as LayerCard } from "./chunks/layer-card-lsmeuqic9i1isv2b.js";
|