@lobehub/ui 6.5.1 → 6.6.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 (78) hide show
  1. package/README.md +87 -125
  2. package/es/Accordion/style.d.mts +2 -2
  3. package/es/AutoComplete/style.d.mts +1 -1
  4. package/es/Carousel/Carousel.mjs +7 -8
  5. package/es/Carousel/Carousel.mjs.map +1 -1
  6. package/es/Drawer/atoms.mjs +5 -5
  7. package/es/Drawer/atoms.mjs.map +1 -1
  8. package/es/EditorSlashMenu/EditorSlashMenu.mjs +7 -9
  9. package/es/EditorSlashMenu/EditorSlashMenu.mjs.map +1 -1
  10. package/es/FormKit/List.mjs +24 -24
  11. package/es/FormKit/List.mjs.map +1 -1
  12. package/es/Highlighter/Highlighter.mjs +1 -3
  13. package/es/Highlighter/Highlighter.mjs.map +1 -1
  14. package/es/Highlighter/LangSelect.mjs +2 -2
  15. package/es/Highlighter/LangSelect.mjs.map +1 -1
  16. package/es/Highlighter/SyntaxHighlighter/StaticRenderer.mjs +2 -3
  17. package/es/Highlighter/SyntaxHighlighter/StaticRenderer.mjs.map +1 -1
  18. package/es/Highlighter/SyntaxHighlighter/StreamRenderer.mjs +4 -20
  19. package/es/Highlighter/SyntaxHighlighter/StreamRenderer.mjs.map +1 -1
  20. package/es/Highlighter/SyntaxHighlighter/index.mjs +2 -3
  21. package/es/Highlighter/SyntaxHighlighter/index.mjs.map +1 -1
  22. package/es/Highlighter/SyntaxHighlighter/tokenFade.mjs.map +1 -1
  23. package/es/Highlighter/const.d.mts +2 -0
  24. package/es/Highlighter/const.mjs +95 -12
  25. package/es/Highlighter/const.mjs.map +1 -1
  26. package/es/Highlighter/engine.mjs +75 -0
  27. package/es/Highlighter/engine.mjs.map +1 -0
  28. package/es/Highlighter/languages.mjs +501 -0
  29. package/es/Highlighter/languages.mjs.map +1 -0
  30. package/es/Highlighter/theme/lobe-highlights-theme.mjs +73 -0
  31. package/es/Highlighter/theme/lobe-highlights-theme.mjs.map +1 -0
  32. package/es/Highlighter/tokens.mjs +50 -0
  33. package/es/Highlighter/tokens.mjs.map +1 -0
  34. package/es/Highlighter/type.d.mts +5 -2
  35. package/es/Image/viewer/ActualSizeIcon.mjs +3 -4
  36. package/es/Image/viewer/ActualSizeIcon.mjs.map +1 -1
  37. package/es/ImageSelect/ImageSelect.mjs +22 -22
  38. package/es/ImageSelect/ImageSelect.mjs.map +1 -1
  39. package/es/Markdown/SyntaxMarkdown/MarkdownRender.mjs.map +1 -1
  40. package/es/Markdown/SyntaxMarkdown/StreamdownRender.mjs.map +1 -1
  41. package/es/Markdown/components/Footnotes.mjs +26 -26
  42. package/es/Markdown/components/Footnotes.mjs.map +1 -1
  43. package/es/Modal/Modal.mjs.map +1 -1
  44. package/es/Modal/atoms.mjs +5 -5
  45. package/es/Modal/atoms.mjs.map +1 -1
  46. package/es/Pagination/Pagination.mjs +5 -5
  47. package/es/Pagination/Pagination.mjs.map +1 -1
  48. package/es/Popover/PopoverInGroup.mjs.map +1 -1
  49. package/es/Rate/Rate.mjs +3 -4
  50. package/es/Rate/Rate.mjs.map +1 -1
  51. package/es/SearchBar/SearchBar.mjs +3 -1
  52. package/es/SearchBar/SearchBar.mjs.map +1 -1
  53. package/es/Select/parts.mjs +20 -20
  54. package/es/Select/parts.mjs.map +1 -1
  55. package/es/Spin/NetworkGlyph.mjs +5 -7
  56. package/es/Spin/NetworkGlyph.mjs.map +1 -1
  57. package/es/Table/render/Header.mjs +15 -16
  58. package/es/Table/render/Header.mjs.map +1 -1
  59. package/es/color/ColorScales/ScaleRow.mjs +7 -7
  60. package/es/color/ColorScales/ScaleRow.mjs.map +1 -1
  61. package/es/color/ColorScales/index.mjs +20 -21
  62. package/es/color/ColorScales/index.mjs.map +1 -1
  63. package/es/color/CssVar/ScaleRow.mjs +7 -7
  64. package/es/color/CssVar/ScaleRow.mjs.map +1 -1
  65. package/es/color/CssVar/VarRow.mjs +7 -7
  66. package/es/color/CssVar/VarRow.mjs.map +1 -1
  67. package/es/color/CssVar/index.mjs +20 -21
  68. package/es/color/CssVar/index.mjs.map +1 -1
  69. package/es/dashboard/PageSkeleton/PageSkeleton.mjs +30 -25
  70. package/es/dashboard/PageSkeleton/PageSkeleton.mjs.map +1 -1
  71. package/es/eslint/index.d.mts +1 -1
  72. package/es/hooks/useHighlight.mjs +35 -107
  73. package/es/hooks/useHighlight.mjs.map +1 -1
  74. package/es/hooks/useStreamHighlight.mjs +90 -194
  75. package/es/hooks/useStreamHighlight.mjs.map +1 -1
  76. package/es/node_modules/.pnpm/{eslint@10.13.0_jiti@2.6.1_supports-color@10.2.2 → eslint@10.13.0_jiti@2.7.0_supports-color@10.2.2}/node_modules/eslint/lib/types/index.d.mts +1 -1
  77. package/es/style.css +2 -46
  78. package/package.json +3 -6
@@ -1,218 +1,114 @@
1
1
  "use client";
2
- import lobe_theme_default from "../Highlighter/theme/lobe-theme.mjs";
3
2
  import { getCodeLanguageByInput } from "../Highlighter/const.mjs";
4
- import { shikiModulePromise } from "./useHighlight.mjs";
5
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
6
- import { ShikiStreamTokenizer } from "@shikijs/stream";
3
+ import { useHighlighterEngine } from "../Highlighter/engine.mjs";
4
+ import { getPreStyle } from "../Highlighter/tokens.mjs";
5
+ import { useEffect, useMemo, useRef, useState } from "react";
7
6
  //#region src/hooks/useStreamHighlight.ts
8
- const tokensToLineTokens = (tokens) => {
9
- if (!tokens.length) return [[]];
10
- const lines = [];
11
- let currentLine = [];
12
- for (const token of tokens) {
13
- const content = token.content ?? "";
14
- if (content === "\n") {
15
- lines.push(currentLine);
16
- currentLine = [];
17
- continue;
18
- }
19
- if (content.indexOf("\n") === -1) currentLine.push(token);
20
- else {
21
- const segments = content.split("\n");
22
- for (const [j, segment] of segments.entries()) {
23
- if (segment) currentLine.push(j === 0 && segment === content ? token : {
24
- ...token,
25
- content: segment
26
- });
27
- if (j < segments.length - 1) {
28
- lines.push(currentLine);
29
- currentLine = [];
30
- }
31
- }
32
- }
33
- }
34
- if (currentLine.length > 0 || lines.length === 0) lines.push(currentLine);
35
- return lines.length > 0 ? lines : [[]];
7
+ const readLines = (session, from) => {
8
+ const { tokenizer } = session;
9
+ const lines = session.lines.slice(0, Math.min(from, tokenizer.lineCount));
10
+ for (let line = lines.length; line < tokenizer.lineCount; line++) lines.push(tokenizer.getLineTokens(line).tokens);
11
+ session.lines = lines;
36
12
  };
37
- const createPreStyle = (bg, fg) => {
38
- if (!bg && !fg) return void 0;
39
- return {
40
- backgroundColor: bg,
41
- color: fg
13
+ const createSession = (engine, language, text) => {
14
+ const tokenizer = new engine.highlights.LiveTokenizer({
15
+ code: text,
16
+ lang: language,
17
+ theme: engine.theme
18
+ });
19
+ const { bg, fg } = engine.highlights.codeToTokens("", {
20
+ lang: language,
21
+ theme: engine.theme
22
+ });
23
+ const session = {
24
+ engine,
25
+ language,
26
+ lines: [],
27
+ preStyle: getPreStyle({
28
+ bg,
29
+ fg
30
+ }),
31
+ text,
32
+ tokenizer
42
33
  };
34
+ readLines(session, 0);
35
+ return session;
43
36
  };
44
- const useStreamingHighlighter = (text, options) => {
45
- const { customThemes, enabled, language, theme } = options;
46
- const [result, setResult] = useState();
47
- const tokenizerRef = useRef(null);
48
- const previousTextRef = useRef("");
37
+ const updateSession = (session, text) => {
38
+ if (text === session.text) return false;
39
+ const { tokenizer } = session;
40
+ if (text.startsWith(session.text)) {
41
+ const lastLine = tokenizer.lineCount - 1;
42
+ const end = {
43
+ character: tokenizer.getLineLength(lastLine),
44
+ line: lastLine
45
+ };
46
+ const firstChanged = tokenizer.applyEdits([{
47
+ newText: text.slice(session.text.length),
48
+ range: {
49
+ end,
50
+ start: end
51
+ }
52
+ }]).lineChanges.reduce((min, change) => Math.min(min, change.newStartLine), lastLine);
53
+ session.text = text;
54
+ readLines(session, firstChanged);
55
+ } else {
56
+ tokenizer.reset(text);
57
+ session.text = text;
58
+ readLines(session, 0);
59
+ }
60
+ return true;
61
+ };
62
+ const useStreamHighlight = (text, { language, theme: themeId, streaming }) => {
49
63
  const safeText = text ?? "";
50
- const latestTextRef = useRef(safeText);
51
- const preStyleRef = useRef(void 0);
52
- const linesRef = useRef([[]]);
64
+ const lang = (language ?? "plaintext").toLowerCase();
65
+ const matchedLanguage = useMemo(() => getCodeLanguageByInput(lang), [lang]);
66
+ const engine = useHighlighterEngine(themeId);
67
+ const sessionRef = useRef(null);
68
+ const [result, setResult] = useState();
53
69
  useEffect(() => {
54
- latestTextRef.current = safeText;
55
- }, [safeText]);
56
- const setStreamingResultRef = useRef((rawLines) => {
57
- const previousLines = linesRef.current;
58
- const newLinesLength = rawLines.length;
59
- if (newLinesLength !== previousLines.length || newLinesLength === 0) {
60
- linesRef.current = rawLines;
61
- setResult({
62
- lines: rawLines,
63
- preStyle: preStyleRef.current
64
- });
70
+ if (!streaming || !engine) {
71
+ sessionRef.current?.tokenizer.dispose();
72
+ sessionRef.current = null;
73
+ setResult(void 0);
65
74
  return;
66
75
  }
67
- let hasChanges = false;
68
- const mergedLines = [];
69
- for (let i = 0; i < newLinesLength; i++) {
70
- const newLine = rawLines[i];
71
- const prevLine = previousLines[i];
72
- if (prevLine === newLine) {
73
- mergedLines[i] = prevLine;
74
- continue;
75
- }
76
- if (!prevLine || prevLine.length !== newLine.length) {
77
- mergedLines[i] = newLine;
78
- hasChanges = true;
79
- continue;
80
- }
81
- let lineChanged = false;
82
- for (const [j, newToken] of newLine.entries()) if (prevLine[j] !== newToken) {
83
- lineChanged = true;
84
- break;
85
- }
86
- if (lineChanged) {
87
- mergedLines[i] = newLine;
88
- hasChanges = true;
89
- } else mergedLines[i] = prevLine;
90
- }
91
- if (hasChanges) {
92
- linesRef.current = mergedLines;
93
- setResult({
94
- lines: mergedLines,
95
- preStyle: preStyleRef.current
96
- });
97
- }
98
- });
99
- const updateTokens = useCallback(async (nextText, forceReset = false) => {
100
- const tokenizer = tokenizerRef.current;
101
- if (!tokenizer) return;
102
- if (forceReset) {
103
- tokenizer.clear();
104
- previousTextRef.current = "";
105
- }
106
- const previousText = previousTextRef.current;
107
- let chunk = nextText;
108
- if (!forceReset && nextText.startsWith(previousText)) chunk = nextText.slice(previousText.length);
109
- else if (!forceReset) tokenizer.clear();
110
- previousTextRef.current = nextText;
111
- if (!chunk) {
112
- const stableTokens = tokenizer.tokensStable;
113
- const unstableTokens = tokenizer.tokensUnstable;
114
- if (stableTokens.length + unstableTokens.length === 0) {
115
- setStreamingResultRef.current([[]]);
76
+ let session = sessionRef.current;
77
+ let changed;
78
+ if (!session || session.engine !== engine || session.language !== matchedLanguage) {
79
+ session?.tokenizer.dispose();
80
+ try {
81
+ session = createSession(engine, matchedLanguage, safeText);
82
+ } catch (error) {
83
+ console.error("Streaming highlighter initialization failed:", error);
84
+ sessionRef.current = null;
85
+ setResult(void 0);
116
86
  return;
117
87
  }
118
- const mergedTokens = stableTokens.length === 0 ? unstableTokens : unstableTokens.length === 0 ? stableTokens : [...stableTokens, ...unstableTokens];
119
- setStreamingResultRef.current(tokensToLineTokens(mergedTokens));
120
- return;
121
- }
122
- try {
123
- await tokenizer.enqueue(chunk);
124
- const stableTokens = tokenizer.tokensStable;
125
- const unstableTokens = tokenizer.tokensUnstable;
126
- const mergedTokens = stableTokens.length === 0 ? unstableTokens : unstableTokens.length === 0 ? stableTokens : [...stableTokens, ...unstableTokens];
127
- setStreamingResultRef.current(tokensToLineTokens(mergedTokens));
88
+ sessionRef.current = session;
89
+ changed = true;
90
+ } else try {
91
+ changed = updateSession(session, safeText);
128
92
  } catch (error) {
129
93
  console.error("Streaming highlighting failed:", error);
130
- }
131
- }, []);
132
- const highlighterKeyRef = useRef("");
133
- useEffect(() => {
134
- if (!enabled) {
135
- tokenizerRef.current?.clear();
136
- tokenizerRef.current = null;
137
- previousTextRef.current = "";
138
- preStyleRef.current = void 0;
139
- linesRef.current = [[]];
140
- setResult(void 0);
141
- highlighterKeyRef.current = "";
142
94
  return;
143
95
  }
144
- const currentKey = `${language}-${theme}`;
145
- if (highlighterKeyRef.current === currentKey && tokenizerRef.current) return;
146
- let cancelled = false;
147
- (async () => {
148
- const mod = await shikiModulePromise;
149
- if (!mod || cancelled) return;
150
- try {
151
- let themesToLoad = [theme];
152
- if (customThemes && theme === "lobe-theme") {
153
- const customTheme = customThemes[theme];
154
- if (customTheme) themesToLoad = [customTheme];
155
- }
156
- const highlighter = await mod.getSingletonHighlighter({
157
- langs: language ? [language] : ["plaintext"],
158
- themes: themesToLoad
159
- });
160
- if (!highlighter || cancelled) return;
161
- if (highlighterKeyRef.current !== currentKey) {
162
- tokenizerRef.current?.clear();
163
- const tokenizer = new ShikiStreamTokenizer({
164
- highlighter,
165
- lang: language,
166
- theme
167
- });
168
- tokenizerRef.current = tokenizer;
169
- highlighterKeyRef.current = currentKey;
170
- previousTextRef.current = "";
171
- linesRef.current = [[]];
172
- const themeInfo = highlighter.getTheme(theme);
173
- preStyleRef.current = createPreStyle(themeInfo?.bg, themeInfo?.fg);
174
- }
175
- const currentText = latestTextRef.current;
176
- if (currentText) await updateTokens(currentText, true);
177
- else setStreamingResultRef.current([[]]);
178
- } catch (error) {
179
- console.error("Streaming highlighter initialization failed:", error);
180
- highlighterKeyRef.current = "";
181
- }
182
- })();
183
- return () => {
184
- cancelled = true;
185
- };
186
- }, [
187
- enabled,
188
- language,
189
- theme,
190
- updateTokens,
191
- customThemes
192
- ]);
193
- useEffect(() => {
194
- if (!enabled) return;
195
- if (!tokenizerRef.current) return;
196
- const currentText = latestTextRef.current;
197
- updateTokens(currentText);
96
+ if (changed) setResult({
97
+ lines: session.lines,
98
+ preStyle: session.preStyle
99
+ });
198
100
  }, [
199
- enabled,
101
+ engine,
102
+ matchedLanguage,
200
103
  safeText,
201
- updateTokens
104
+ streaming
202
105
  ]);
106
+ useEffect(() => () => {
107
+ sessionRef.current?.tokenizer.dispose();
108
+ sessionRef.current = null;
109
+ }, []);
203
110
  return result;
204
111
  };
205
- const useStreamHighlight = (text, { language, theme: builtinTheme, streaming }) => {
206
- const safeText = text ?? "";
207
- const lang = (language ?? "plaintext").toLowerCase();
208
- const matchedLanguage = useMemo(() => getCodeLanguageByInput(lang), [lang]);
209
- return useStreamingHighlighter(safeText, {
210
- customThemes: { "lobe-theme": lobe_theme_default },
211
- enabled: streaming,
212
- language: matchedLanguage,
213
- theme: builtinTheme || "lobe-theme"
214
- });
215
- };
216
112
  //#endregion
217
113
  export { useStreamHighlight };
218
114
 
@@ -1 +1 @@
1
- {"version":3,"file":"useStreamHighlight.mjs","names":["lobeTheme"],"sources":["../../src/hooks/useStreamHighlight.ts"],"sourcesContent":["'use client';\n\nimport { ShikiStreamTokenizer } from '@shikijs/stream';\nimport { type CSSProperties, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { type BuiltinTheme, type ThemedToken } from 'shiki';\n\nimport { getCodeLanguageByInput } from '@/Highlighter/const';\nimport lobeTheme from '@/Highlighter/theme/lobe-theme';\n\nimport { shikiModulePromise, type StreamingHighlightResult } from './useHighlight';\n\ntype StreamingOptions = {\n customThemes?: Record<string, any>;\n enabled?: boolean;\n language: string;\n theme: string;\n};\n\n// Optimized version: reduce array allocations and object spreading\nconst tokensToLineTokens = (tokens: ThemedToken[]): ThemedToken[][] => {\n if (!tokens.length) return [[]];\n\n const lines: ThemedToken[][] = [];\n let currentLine: ThemedToken[] = [];\n\n for (const token of tokens) {\n const content = token.content ?? '';\n\n if (content === '\\n') {\n lines.push(currentLine);\n currentLine = [];\n continue;\n }\n\n const newlineIndex = content.indexOf('\\n');\n if (newlineIndex === -1) {\n // No newline, add token directly\n currentLine.push(token);\n } else {\n // Split on newlines\n const segments = content.split('\\n');\n for (const [j, segment] of segments.entries()) {\n if (segment) {\n // Only create new object if we need to modify content\n currentLine.push(j === 0 && segment === content ? token : { ...token, content: segment });\n }\n if (j < segments.length - 1) {\n lines.push(currentLine);\n currentLine = [];\n }\n }\n }\n }\n\n // Don't forget the last line\n if (currentLine.length > 0 || lines.length === 0) {\n lines.push(currentLine);\n }\n\n return lines.length > 0 ? lines : [[]];\n};\n\nconst createPreStyle = (bg?: string, fg?: string): CSSProperties | undefined => {\n if (!bg && !fg) return undefined;\n return {\n backgroundColor: bg,\n color: fg,\n };\n};\n\nconst useStreamingHighlighter = (\n text: string,\n options: StreamingOptions,\n): StreamingHighlightResult | undefined => {\n const { customThemes, enabled, language, theme } = options;\n const [result, setResult] = useState<StreamingHighlightResult>();\n const tokenizerRef = useRef<ShikiStreamTokenizer | null>(null);\n const previousTextRef = useRef('');\n const safeText = text ?? '';\n const latestTextRef = useRef(safeText);\n const preStyleRef = useRef<CSSProperties | undefined>(undefined);\n const linesRef = useRef<ThemedToken[][]>([[]]);\n\n useEffect(() => {\n latestTextRef.current = safeText;\n }, [safeText]);\n\n // Use ref to store callback to avoid recreating it\n const setStreamingResultRef = useRef((rawLines: ThemedToken[][]) => {\n const previousLines = linesRef.current;\n const newLinesLength = rawLines.length;\n const prevLinesLength = previousLines.length;\n\n // Fast path: if lengths differ or it's a complete reset, use new lines directly\n if (newLinesLength !== prevLinesLength || newLinesLength === 0) {\n linesRef.current = rawLines;\n setResult({\n lines: rawLines,\n preStyle: preStyleRef.current,\n });\n return;\n }\n\n // Optimized comparison: only check changed lines\n let hasChanges = false;\n const mergedLines: ThemedToken[][] = [];\n\n for (let i = 0; i < newLinesLength; i++) {\n const newLine = rawLines[i];\n const prevLine = previousLines[i];\n\n // Quick reference equality check first\n if (prevLine === newLine) {\n mergedLines[i] = prevLine;\n continue;\n }\n\n // Length check\n if (!prevLine || prevLine.length !== newLine.length) {\n mergedLines[i] = newLine;\n hasChanges = true;\n continue;\n }\n\n // Deep comparison only for lines that might have changed\n let lineChanged = false;\n for (const [j, newToken] of newLine.entries()) {\n if (prevLine[j] !== newToken) {\n lineChanged = true;\n break;\n }\n }\n\n if (lineChanged) {\n mergedLines[i] = newLine;\n hasChanges = true;\n } else {\n mergedLines[i] = prevLine;\n }\n }\n\n // Only update state if there are actual changes\n if (hasChanges) {\n linesRef.current = mergedLines;\n setResult({\n lines: mergedLines,\n preStyle: preStyleRef.current,\n });\n }\n });\n\n const updateTokens = useCallback(async (nextText: string, forceReset = false) => {\n const tokenizer = tokenizerRef.current;\n if (!tokenizer) return;\n\n if (forceReset) {\n tokenizer.clear();\n previousTextRef.current = '';\n }\n\n const previousText = previousTextRef.current;\n let chunk = nextText;\n const canAppend = !forceReset && nextText.startsWith(previousText);\n\n if (canAppend) {\n chunk = nextText.slice(previousText.length);\n } else if (!forceReset) {\n tokenizer.clear();\n }\n\n previousTextRef.current = nextText;\n\n if (!chunk) {\n // Optimize: avoid array spread if possible\n const stableTokens = tokenizer.tokensStable;\n const unstableTokens = tokenizer.tokensUnstable;\n const totalLength = stableTokens.length + unstableTokens.length;\n\n if (totalLength === 0) {\n setStreamingResultRef.current([[]]);\n return;\n }\n\n // Only create merged array if we have both stable and unstable tokens\n const mergedTokens =\n stableTokens.length === 0\n ? unstableTokens\n : unstableTokens.length === 0\n ? stableTokens\n : [...stableTokens, ...unstableTokens];\n\n setStreamingResultRef.current(tokensToLineTokens(mergedTokens));\n return;\n }\n\n try {\n await tokenizer.enqueue(chunk);\n // Optimize: avoid array spread if possible\n const stableTokens = tokenizer.tokensStable;\n const unstableTokens = tokenizer.tokensUnstable;\n const mergedTokens =\n stableTokens.length === 0\n ? unstableTokens\n : unstableTokens.length === 0\n ? stableTokens\n : [...stableTokens, ...unstableTokens];\n setStreamingResultRef.current(tokensToLineTokens(mergedTokens));\n } catch (error) {\n console.error('Streaming highlighting failed:', error);\n }\n }, []);\n\n // Cache highlighter key to avoid unnecessary recreations\n const highlighterKeyRef = useRef<string>('');\n\n useEffect(() => {\n if (!enabled) {\n tokenizerRef.current?.clear();\n tokenizerRef.current = null;\n previousTextRef.current = '';\n preStyleRef.current = undefined;\n linesRef.current = [[]];\n setResult(undefined);\n highlighterKeyRef.current = '';\n return;\n }\n\n // Skip if language/theme combination hasn't changed\n const currentKey = `${language}-${theme}`;\n if (highlighterKeyRef.current === currentKey && tokenizerRef.current) {\n return;\n }\n\n let cancelled = false;\n\n (async () => {\n const mod = await shikiModulePromise;\n if (!mod || cancelled) return;\n\n try {\n // Load custom theme if using slack-dark or slack-ochin\n let themesToLoad: any[] = [theme];\n if (customThemes && theme === 'lobe-theme') {\n const customTheme = customThemes[theme];\n if (customTheme) {\n themesToLoad = [customTheme as any];\n }\n }\n\n // Only load the specific language and theme needed\n // getSingletonHighlighter will cache the instance internally\n const highlighter = await mod.getSingletonHighlighter({\n langs: language ? [language] : ['plaintext'],\n themes: themesToLoad,\n });\n\n if (!highlighter || cancelled) return;\n\n // Only create new tokenizer if key changed\n if (highlighterKeyRef.current !== currentKey) {\n // Clear old tokenizer\n tokenizerRef.current?.clear();\n\n const tokenizer = new ShikiStreamTokenizer({\n highlighter,\n lang: language,\n theme,\n });\n\n tokenizerRef.current = tokenizer;\n highlighterKeyRef.current = currentKey;\n previousTextRef.current = '';\n linesRef.current = [[]];\n\n const themeInfo = highlighter.getTheme(theme);\n preStyleRef.current = createPreStyle(themeInfo?.bg, themeInfo?.fg);\n }\n\n const currentText = latestTextRef.current;\n if (currentText) {\n await updateTokens(currentText, true);\n } else {\n setStreamingResultRef.current([[]]);\n }\n } catch (error) {\n console.error('Streaming highlighter initialization failed:', error);\n // Reset on error\n highlighterKeyRef.current = '';\n }\n })();\n\n return () => {\n cancelled = true;\n // Cleanup only if this effect was cancelled before completion\n // The next effect will handle cleanup if key changed\n };\n }, [enabled, language, theme, updateTokens, customThemes]);\n\n // Separate effect for text updates to avoid unnecessary tokenizer recreation\n useEffect(() => {\n if (!enabled) return;\n if (!tokenizerRef.current) return;\n // Use ref to get latest text to avoid stale closures\n const currentText = latestTextRef.current;\n updateTokens(currentText);\n }, [enabled, safeText, updateTokens]);\n\n return result;\n};\n\nexport const useStreamHighlight = (\n text: string,\n {\n language,\n theme: builtinTheme,\n streaming,\n }: { enableTransformer?: boolean; language: string; streaming?: boolean; theme?: BuiltinTheme },\n) => {\n // Safely handle language and text with boundary checks\n const safeText = text ?? '';\n const lang = (language ?? 'plaintext').toLowerCase();\n\n // Match supported languages\n const matchedLanguage = useMemo(() => getCodeLanguageByInput(lang), [lang]);\n\n const effectiveTheme = builtinTheme || 'lobe-theme';\n\n return useStreamingHighlighter(safeText, {\n customThemes: {\n 'lobe-theme': lobeTheme,\n },\n enabled: streaming,\n language: matchedLanguage,\n theme: effectiveTheme,\n });\n};\n"],"mappings":";;;;;;;AAmBA,MAAM,sBAAsB,WAA2C;CACrE,IAAI,CAAC,OAAO,QAAQ,OAAO,CAAC,CAAC,CAAC;CAE9B,MAAM,QAAyB,CAAC;CAChC,IAAI,cAA6B,CAAC;CAElC,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,UAAU,MAAM,WAAW;EAEjC,IAAI,YAAY,MAAM;GACpB,MAAM,KAAK,WAAW;GACtB,cAAc,CAAC;GACf;EACF;EAGA,IADqB,QAAQ,QAAQ,IACtB,MAAM,IAEnB,YAAY,KAAK,KAAK;OACjB;GAEL,MAAM,WAAW,QAAQ,MAAM,IAAI;GACnC,KAAK,MAAM,CAAC,GAAG,YAAY,SAAS,QAAQ,GAAG;IAC7C,IAAI,SAEF,YAAY,KAAK,MAAM,KAAK,YAAY,UAAU,QAAQ;KAAE,GAAG;KAAO,SAAS;IAAQ,CAAC;IAE1F,IAAI,IAAI,SAAS,SAAS,GAAG;KAC3B,MAAM,KAAK,WAAW;KACtB,cAAc,CAAC;IACjB;GACF;EACF;CACF;CAGA,IAAI,YAAY,SAAS,KAAK,MAAM,WAAW,GAC7C,MAAM,KAAK,WAAW;CAGxB,OAAO,MAAM,SAAS,IAAI,QAAQ,CAAC,CAAC,CAAC;AACvC;AAEA,MAAM,kBAAkB,IAAa,OAA2C;CAC9E,IAAI,CAAC,MAAM,CAAC,IAAI,OAAO,KAAA;CACvB,OAAO;EACL,iBAAiB;EACjB,OAAO;CACT;AACF;AAEA,MAAM,2BACJ,MACA,YACyC;CACzC,MAAM,EAAE,cAAc,SAAS,UAAU,UAAU;CACnD,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AAA,CAAa,YAAY;CAGnD,MAAM,kBAAkB,cAAc,uBAAuB,IAAI,GAAG,CAAC,IAAI,CAAC;CAI1E,OAAO,wBAAwB,UAAU;EACvC,cAAc,EACZ,cAAcA,mBAChB;EACA,SAAS;EACT,UAAU;EACV,OARqB,gBAAgB;CASvC,CAAC;AACH"}
1
+ {"version":3,"file":"useStreamHighlight.mjs","names":[],"sources":["../../src/hooks/useStreamHighlight.ts"],"sourcesContent":["'use client';\n\nimport type { Lang, LiveTokenizer, ThemedToken } from '@pierre/highlights';\nimport { type CSSProperties, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { getCodeLanguageByInput } from '@/Highlighter/const';\nimport { type HighlighterEngine, useHighlighterEngine } from '@/Highlighter/engine';\nimport { getPreStyle } from '@/Highlighter/tokens';\n\nexport type StreamingHighlightResult = {\n lines: ThemedToken[][];\n preStyle?: CSSProperties;\n};\n\ninterface StreamSession {\n engine: HighlighterEngine;\n language: string;\n lines: ThemedToken[][];\n preStyle?: CSSProperties;\n text: string;\n tokenizer: LiveTokenizer;\n}\n\nconst readLines = (session: StreamSession, from: number) => {\n const { tokenizer } = session;\n const lines = session.lines.slice(0, Math.min(from, tokenizer.lineCount));\n for (let line = lines.length; line < tokenizer.lineCount; line++) {\n lines.push(tokenizer.getLineTokens(line).tokens);\n }\n session.lines = lines;\n};\n\nconst createSession = (\n engine: HighlighterEngine,\n language: string,\n text: string,\n): StreamSession => {\n const tokenizer = new engine.highlights.LiveTokenizer({\n code: text,\n lang: language as Lang,\n theme: engine.theme,\n });\n const { bg, fg } = engine.highlights.codeToTokens('', {\n lang: language as Lang,\n theme: engine.theme,\n });\n const session: StreamSession = {\n engine,\n language,\n lines: [],\n preStyle: getPreStyle({ bg, fg }),\n text,\n tokenizer,\n };\n readLines(session, 0);\n return session;\n};\n\nconst updateSession = (session: StreamSession, text: string) => {\n if (text === session.text) return false;\n\n const { tokenizer } = session;\n if (text.startsWith(session.text)) {\n const lastLine = tokenizer.lineCount - 1;\n const end = { character: tokenizer.getLineLength(lastLine), line: lastLine };\n const update = tokenizer.applyEdits([\n { newText: text.slice(session.text.length), range: { end, start: end } },\n ]);\n const firstChanged = update.lineChanges.reduce(\n (min, change) => Math.min(min, change.newStartLine),\n lastLine,\n );\n session.text = text;\n readLines(session, firstChanged);\n } else {\n tokenizer.reset(text);\n session.text = text;\n readLines(session, 0);\n }\n return true;\n};\n\nexport const useStreamHighlight = (\n text: string,\n {\n language,\n theme: themeId,\n streaming,\n }: { language: string; streaming?: boolean; theme?: string },\n): StreamingHighlightResult | undefined => {\n const safeText = text ?? '';\n const lang = (language ?? 'plaintext').toLowerCase();\n const matchedLanguage = useMemo(() => getCodeLanguageByInput(lang), [lang]);\n const engine = useHighlighterEngine(themeId);\n\n const sessionRef = useRef<StreamSession | null>(null);\n const [result, setResult] = useState<StreamingHighlightResult>();\n\n useEffect(() => {\n if (!streaming || !engine) {\n sessionRef.current?.tokenizer.dispose();\n sessionRef.current = null;\n setResult(undefined);\n return;\n }\n\n let session = sessionRef.current;\n let changed: boolean;\n if (!session || session.engine !== engine || session.language !== matchedLanguage) {\n session?.tokenizer.dispose();\n try {\n session = createSession(engine, matchedLanguage, safeText);\n } catch (error) {\n console.error('Streaming highlighter initialization failed:', error);\n sessionRef.current = null;\n setResult(undefined);\n return;\n }\n sessionRef.current = session;\n changed = true;\n } else {\n try {\n changed = updateSession(session, safeText);\n } catch (error) {\n console.error('Streaming highlighting failed:', error);\n return;\n }\n }\n\n if (changed) setResult({ lines: session.lines, preStyle: session.preStyle });\n }, [engine, matchedLanguage, safeText, streaming]);\n\n useEffect(\n () => () => {\n sessionRef.current?.tokenizer.dispose();\n sessionRef.current = null;\n },\n [],\n );\n\n return result;\n};\n"],"mappings":";;;;;;AAuBA,MAAM,aAAa,SAAwB,SAAiB;CAC1D,MAAM,EAAE,cAAc;CACtB,MAAM,QAAQ,QAAQ,MAAM,MAAM,GAAG,KAAK,IAAI,MAAM,UAAU,SAAS,CAAC;CACxE,KAA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BAAuB,IAAI,GAAG,CAAC,IAAI,CAAC;CAC1E,MAAM,SAAS,qBAAqB,OAAO;CAE3C,MAAM,aAAa,OAA6B,IAAI;CACpD,MAAM,CAAC,QAAQ,aAAa,SAAmC;CAE/D,gBAAgB;EACd,IAAI,CAAC,aAAa,CAAC,QAAQ;GACzB,WAAW,SAAS,UAAU,QAAQ;GACtC,WAAW,UAAU;GACrB,UAAU,KAAA,CAAS;GACnB;EACF;EAEA,IAAI,UAAU,WAAW;EACzB,IAAI;EACJ,IAAI,CAAC,WAAW,QAAQ,WAAW,UAAU,QAAQ,aAAa,iBAAiB;GACjF,SAAS,UAAU,QAAQ;GAC3B,IAAI;IACF,UAAU,cAAc,QAAQ,iBAAiB,QAAQ;GAC3D,SAAS,OAAO;IACd,QAAQ,MAAM,gDAAgD,KAAK;IACnE,WAAW,UAAU;IACrB,UAAU,KAAA,CAAS;IACnB;GACF;GACA,WAAW,UAAU;GACrB,UAAU;EACZ,OACE,IAAI;GACF,UAAU,cAAc,SAAS,QAAQ;EAC3C,SAAS,OAAO;GACd,QAAQ,MAAM,kCAAkC,KAAK;GACrD;EACF;EAGF,IAAI,SAAS,UAAU;GAAE,OAAO,QAAQ;GAAO,UAAU,QAAQ;EAAS,CAAC;CAC7E,GAAG;EAAC;EAAQ;EAAiB;EAAU;CAAS,CAAC;CAEjD,sBACc;EACV,WAAW,SAAS,UAAU,QAAQ;EACtC,WAAW,UAAU;CACvB,GACA,CAAC,CACH;CAEA,OAAO;AACT"}
@@ -1,7 +1,7 @@
1
1
  import { ArrowFunctionExpression, AssignmentExpression, BaseNode, CatchClause, ClassDeclaration, ClassExpression, Comment, Expression, ForInStatement, ForOfStatement, FunctionDeclaration, FunctionExpression, Identifier, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, Node as Node$1, Position, Program, SourceLocation as SourceLocation$1, VariableDeclaration, VariableDeclarator } from "../../../../../@types_estree@1.0.9/node_modules/@types/estree/index.mjs";
2
2
  import { BaseConfig, ConfigObject, ConfigOverride, DeprecatedInfo, EcmaVersion as EcmaVersion$1, EnvironmentConfig, GlobalAccess, GlobalsConfig, HasRules, JavaScriptSourceType, LanguageOptions, LegacyConfigObject, LintMessage as LintMessage$1, LintSuggestion, LinterOptionsConfig, ObjectMetaProperties, Plugin as Plugin$1, Processor, ProcessorFile as ProcessorFile$1, RuleConfig, RuleContext as RuleContext$1, RuleDefinition, RuleFixer, RuleTextEdit, RuleTextEditor, RulesConfig, RulesMeta, Severity, SeverityLevel, SeverityName, SourceRange, SuggestedEdit, SuggestedEditBase, SuggestionMessage, TextSourceCode, TraversalStep, ViolationLocation, ViolationMessage, ViolationReport, ViolationReportBase } from "../../../../../@eslint_core@1.2.1/node_modules/@eslint/core/dist/esm/types.mjs";
3
3
  import { CustomRuleVisitorWithExit } from "../../../../../@eslint_plugin-kit@0.7.3/node_modules/@eslint/plugin-kit/dist/cjs/index.mjs";
4
- //#region node_modules/.pnpm/eslint@10.13.0_jiti@2.6.1_supports-color@10.2.2/node_modules/eslint/lib/types/index.d.ts
4
+ //#region node_modules/.pnpm/eslint@10.13.0_jiti@2.7.0_supports-color@10.2.2/node_modules/eslint/lib/types/index.d.ts
5
5
  //------------------------------------------------------------------------------
6
6
  // Exports
7
7
  //------------------------------------------------------------------------------
package/es/style.css CHANGED
@@ -1331,52 +1331,8 @@
1331
1331
  display: block;
1332
1332
  }
1333
1333
 
1334
- .lobe-syntax-highlighter-shiki pre.has-focused .line:not(.focused) {
1335
- opacity: .5;
1336
- }
1337
-
1338
- .lobe-syntax-highlighter-shiki pre .highlighted {
1339
- background: var(--lobe-color-fill-tertiary);
1340
- }
1341
-
1342
- .lobe-syntax-highlighter-shiki pre .highlighted.warning {
1343
- background: var(--lobe-color-warning-bg);
1344
- }
1345
-
1346
- .lobe-syntax-highlighter-shiki pre .highlighted.error {
1347
- background: var(--lobe-color-error-bg);
1348
- }
1349
-
1350
- .lobe-syntax-highlighter-shiki pre .highlighted-word {
1351
- border: 1px solid var(--lobe-color-border-secondary);
1352
- border-radius: var(--lobe-border-radius);
1353
- background: var(--lobe-color-fill-tertiary);
1354
- padding-block: .1em;
1355
- padding-inline: .2em;
1356
- }
1357
-
1358
- .lobe-syntax-highlighter-shiki pre .diff.remove {
1359
- background: var(--lobe-color-error-bg);
1360
- }
1361
-
1362
- .lobe-syntax-highlighter-shiki pre .diff.remove:before {
1363
- content: "-";
1364
- color: var(--lobe-color-error-text);
1365
- display: inline-block;
1366
- position: absolute;
1367
- inset-inline-start: 4px;
1368
- }
1369
-
1370
- .lobe-syntax-highlighter-shiki pre .diff.add {
1371
- background: var(--lobe-color-success-bg);
1372
- }
1373
-
1374
- .lobe-syntax-highlighter-shiki pre .diff.add:before {
1375
- content: "+";
1376
- color: var(--lobe-color-success-text);
1377
- display: inline-block;
1378
- position: absolute;
1379
- inset-inline-start: 4px;
1334
+ .lobe-syntax-highlighter-shiki pre code .line:empty:before {
1335
+ content: "​";
1380
1336
  }
1381
1337
 
1382
1338
  .lobe-syntax-highlighter-transparent pre {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "6.5.1",
3
+ "version": "6.6.0",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -144,7 +144,7 @@
144
144
  "test": "vitest --passWithNoTests",
145
145
  "test:coverage": "vitest run --coverage --passWithNoTests",
146
146
  "test:update": "vitest -u",
147
- "type-check": "lobedocs typegen && tsc --noEmit && tsc --noEmit -p tsconfig.site.json"
147
+ "type-check": "tsrs --noEmit"
148
148
  },
149
149
  "dependencies": {
150
150
  "@base-ui/react": "1.9.0",
@@ -160,9 +160,7 @@
160
160
  "@lobehub/streamdown": "^1.4.0",
161
161
  "@mdx-js/mdx": "^3.1.1",
162
162
  "@pierre/diffs": "1.5.2",
163
- "@shikijs/core": "^4.5.0",
164
- "@shikijs/stream": "^4.5.0",
165
- "@shikijs/transformers": "^4.5.0",
163
+ "@pierre/highlights": "^0.2.0",
166
164
  "@stylexjs/stylex": "0.19.1",
167
165
  "@tanstack/form-core": "^1.33.5",
168
166
  "@tanstack/react-table": "^9.2.8",
@@ -192,7 +190,6 @@
192
190
  "remark-cjk-friendly": "^2.3.2",
193
191
  "remark-gfm": "^4.0.1",
194
192
  "remark-math": "^6.0.0",
195
- "shiki": "^4.5.0",
196
193
  "unified": "^11.0.5",
197
194
  "unist-util-visit-parents": "^6.0.2",
198
195
  "uqr": "^0.1.3",