@lobehub/ui 5.9.3 → 5.9.5
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/es/A/index.mjs.map +1 -1
- package/es/Accordion/Accordion.mjs +2 -2
- package/es/Accordion/Accordion.mjs.map +1 -1
- package/es/Accordion/AccordionItem.mjs +2 -2
- package/es/Accordion/AccordionItem.mjs.map +1 -1
- package/es/Alert/Alert.mjs.map +1 -1
- package/es/Checkbox/Checkbox.mjs +2 -2
- package/es/Checkbox/Checkbox.mjs.map +1 -1
- package/es/Checkbox/CheckboxGroup.mjs +2 -2
- package/es/Checkbox/CheckboxGroup.mjs.map +1 -1
- package/es/CodeEditor/CodeEditor.mjs +2 -2
- package/es/CodeEditor/CodeEditor.mjs.map +1 -1
- package/es/ColorSwatches/ColorSwatches.mjs +2 -2
- package/es/ColorSwatches/ColorSwatches.mjs.map +1 -1
- package/es/ConfigProvider/index.mjs.map +1 -1
- package/es/DraggablePanel/DraggablePanel.mjs +21 -5
- package/es/DraggablePanel/DraggablePanel.mjs.map +1 -1
- package/es/DraggablePanel/components/DraggablePanelHeader.mjs +2 -2
- package/es/DraggablePanel/components/DraggablePanelHeader.mjs.map +1 -1
- package/es/DraggableSideNav/DraggableSideNav.mjs +2 -2
- package/es/DraggableSideNav/DraggableSideNav.mjs.map +1 -1
- package/es/EditableText/EditableText.mjs +2 -2
- package/es/EditableText/EditableText.mjs.map +1 -1
- package/es/EditorSlashMenu/useNormalizedItems.mjs.map +1 -1
- package/es/EmojiPicker/AvatarUploader.mjs.map +1 -1
- package/es/EmojiPicker/EmojiPicker.mjs +3 -3
- package/es/EmojiPicker/EmojiPicker.mjs.map +1 -1
- package/es/Form/components/FormFlatGroup.mjs.map +1 -1
- package/es/Grid/Grid.mjs.map +1 -1
- package/es/Highlighter/LangSelect.mjs.map +1 -1
- package/es/Highlighter/SyntaxHighlighter/StreamRenderer.mjs.map +1 -1
- package/es/Highlighter/const.mjs.map +1 -1
- package/es/Hotkey/Hotkey.mjs.map +1 -1
- package/es/HotkeyInput/HotkeyInput.mjs +2 -2
- package/es/HotkeyInput/HotkeyInput.mjs.map +1 -1
- package/es/Icon/style.mjs.map +1 -1
- package/es/Image/components/Toolbar.mjs.map +1 -1
- package/es/ImageSelect/ImageSelect.mjs +2 -2
- package/es/ImageSelect/ImageSelect.mjs.map +1 -1
- package/es/Img/index.mjs.map +1 -1
- package/es/Markdown/SyntaxMarkdown/StreamdownRender.mjs.map +1 -1
- package/es/Markdown/SyntaxMarkdown/useSmoothStreamContent.mjs.map +1 -1
- package/es/Markdown/components/CodeBlock.mjs.map +1 -1
- package/es/Markdown/markdown.style.mjs.map +1 -1
- package/es/Markdown/plugins/remarkBr.mjs.map +1 -1
- package/es/Markdown/plugins/remarkColor.mjs.map +1 -1
- package/es/Markdown/plugins/remarkGfmPlus.mjs.map +1 -1
- package/es/MaterialFileTypeIcon/MaterialFileTypeIcon.mjs.map +1 -1
- package/es/MaterialFileTypeIcon/utils.mjs.map +1 -1
- package/es/Mermaid/SyntaxMermaid/StaticMermaid.mjs.map +1 -1
- package/es/Mermaid/SyntaxMermaid/StreamMermaid.mjs.map +1 -1
- package/es/Modal/imperative.mjs.map +1 -1
- package/es/ScrollShadow/ScrollShadow.mjs.map +1 -1
- package/es/SearchBar/SearchBar.mjs +2 -2
- package/es/SearchBar/SearchBar.mjs.map +1 -1
- package/es/SortableList/SortableList.mjs.map +1 -1
- package/es/SortableList/components/SortableItem.mjs.map +1 -1
- package/es/Text/Text.mjs.map +1 -1
- package/es/ThemeProvider/ThemeProvider.mjs.map +1 -1
- package/es/Toc/TocMobile.mjs +2 -2
- package/es/Toc/TocMobile.mjs.map +1 -1
- package/es/Toc/style.mjs.map +1 -1
- package/es/Tooltip/TooltipGroup.mjs.map +1 -1
- package/es/Tooltip/TooltipInGroup.mjs.map +1 -1
- package/es/Tooltip/TooltipStandalone.mjs.map +1 -1
- package/es/Tooltip/useMergedTooltipProps.mjs.map +1 -1
- package/es/awesome/Spline/ParentSize.mjs.map +1 -1
- package/es/awesome/TypewriterEffect/TypewriterEffect.mjs.map +1 -1
- package/es/base-ui/ContextMenu/renderItems.mjs +14 -7
- package/es/base-ui/ContextMenu/renderItems.mjs.map +1 -1
- package/es/base-ui/ContextMenu/store.mjs.map +1 -1
- package/es/base-ui/DropdownMenu/atoms.mjs +14 -7
- package/es/base-ui/DropdownMenu/atoms.mjs.map +1 -1
- package/es/base-ui/DropdownMenu/renderItems.mjs.map +1 -1
- package/es/base-ui/FloatingSheet/FloatingSheet.mjs.map +1 -1
- package/es/base-ui/FloatingSheet/useSheetDrag.mjs.map +1 -1
- package/es/base-ui/FloatingSheet/useSnapPoints.mjs.map +1 -1
- package/es/base-ui/Modal/atoms.mjs.map +1 -1
- package/es/base-ui/Modal/imperative.mjs.map +1 -1
- package/es/base-ui/Modal/zIndexManager.mjs.map +1 -1
- package/es/base-ui/Popover/useMergedPopoverProps.mjs.map +1 -1
- package/es/base-ui/Select/Select.mjs.map +1 -1
- package/es/base-ui/Switch/atoms.mjs +2 -2
- package/es/base-ui/Switch/atoms.mjs.map +1 -1
- package/es/base-ui/Toast/imperative.mjs.map +1 -1
- package/es/brand/BrandLoading/index.mjs.map +1 -1
- package/es/brand/Logo3d/index.mjs.map +1 -1
- package/es/chat/ChatItem/components/Actions.mjs.map +1 -1
- package/es/chat/EditableMessage/EditableMessage.mjs +3 -3
- package/es/chat/EditableMessage/EditableMessage.mjs.map +1 -1
- package/es/chat/EditableMessageList/EditableMessageList.mjs.map +1 -1
- package/es/chat/MessageModal/MessageModal.mjs +3 -3
- package/es/chat/MessageModal/MessageModal.mjs.map +1 -1
- package/es/hooks/useHighlight.mjs.map +1 -1
- package/es/hooks/useMarkdown/latex.mjs.map +1 -1
- package/es/hooks/useMarkdown/useMarkdownComponents.mjs.map +1 -1
- package/es/hooks/useMarkdown/useMarkdownContent.mjs.map +1 -1
- package/es/hooks/useMermaid.mjs.map +1 -1
- package/es/hooks/useNativeButton.mjs.map +1 -1
- package/es/hooks/useStreamHighlight.mjs.map +1 -1
- package/es/hooks/useStreamMermaid.mjs.map +1 -1
- package/es/i18n/useTranslation.mjs.map +1 -1
- package/es/mdx/mdxComponents/CodeBlock.mjs.map +1 -1
- package/es/mobile/TabBar/TabBar.mjs +2 -2
- package/es/mobile/TabBar/TabBar.mjs.map +1 -1
- package/es/styles/customTheme.mjs.map +1 -1
- package/es/styles/theme/customStylishStatic.mjs +15 -0
- package/es/styles/theme/customStylishStatic.mjs.map +1 -1
- package/es/styles/theme/token/base.mjs.map +1 -1
- package/es/utils/blobToPng.mjs.map +1 -1
- package/es/utils/placement.mjs.map +1 -1
- package/es/utils/smoothCorners.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHighlight.mjs","names":["lobeTheme"],"sources":["../../src/hooks/useHighlight.ts"],"sourcesContent":["'use client';\n\nimport {\n transformerNotationDiff,\n transformerNotationErrorLevel,\n transformerNotationFocus,\n transformerNotationHighlight,\n transformerNotationWordHighlight,\n} from '@shikijs/transformers';\nimport { type CSSProperties, useEffect, useMemo, useState } from 'react';\nimport type { BuiltinTheme, CodeToHastOptions, ThemedToken } from 'shiki';\nimport { Md5 } from 'ts-md5';\n\nimport { getCodeLanguageByInput } from '@/Highlighter/const';\nimport lobeTheme from '@/Highlighter/theme/lobe-theme';\n\n// Application-level cache to avoid repeated calculations\nexport const MD5_LENGTH_THRESHOLD = 10_000; // Use async MD5 for text exceeding this length\n\nexport type StreamingHighlightResult = {\n lines: ThemedToken[][];\n preStyle?: CSSProperties;\n};\n\n// Application-level cache for highlighted HTML\n// Key: cacheKey string, Value: Promise<string>\nconst highlightCache = new Map<string, Promise<string>>();\n\n// Maximum cache size to prevent memory leaks\nconst MAX_CACHE_SIZE = 1000;\n\n// Clean up old cache entries when limit is reached\nconst cleanupCache = () => {\n if (highlightCache.size > MAX_CACHE_SIZE) {\n // Remove oldest 20% of entries\n const entriesToRemove = Math.floor(MAX_CACHE_SIZE * 0.2);\n const keysToRemove = Array.from(highlightCache.keys()).slice(0, entriesToRemove);\n for (const key of keysToRemove) {\n highlightCache.delete(key);\n }\n }\n};\n\nexport type ICodeToHtml = (code: string, options: CodeToHastOptions) => Promise<string>;\nexport type ShikiModule = typeof import('shiki');\n\n// Use codeToHtml shorthand for better performance\n// It automatically manages highlighter instances and loads themes/languages on-demand\nlet codeToHtmlPromise: Promise<ICodeToHtml | null> | null = null;\n\nconst loadCodeToHtml = (): Promise<ICodeToHtml | null> => {\n if (typeof window === 'undefined') return Promise.resolve(null);\n\n if (!codeToHtmlPromise) {\n codeToHtmlPromise = import('shiki').then((mod) => mod.codeToHtml ?? null);\n }\n\n return codeToHtmlPromise;\n};\n\n// Export shikiModulePromise for useStreamHighlight compatibility\nconst loadShikiModule = (): Promise<ShikiModule | null> => {\n if (typeof window === 'undefined') return Promise.resolve(null);\n return import('shiki');\n};\nexport const shikiModulePromise = loadShikiModule();\n\n// Helper function: Safe HTML escaping\nexport const escapeHtml = (str: string): string => {\n return str\n .replaceAll('&', '&')\n .replaceAll('<', '<')\n .replaceAll('>', '>')\n .replaceAll('\"', '"')\n .replaceAll(\"'\", ''');\n};\n\n// Main highlight component - optimized version without SWR\nconst customThemes = {\n 'lobe-theme': lobeTheme,\n};\n\nexport const useHighlight = (\n text: string,\n {\n language,\n enableTransformer,\n theme: builtinTheme,\n streaming,\n }: { enableTransformer?: boolean; language: string; streaming?: boolean; theme?: BuiltinTheme },\n): string => {\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 // Optimize transformer creation\n const transformers = useMemo(() => {\n if (!enableTransformer) return;\n return [\n transformerNotationDiff(),\n transformerNotationHighlight(),\n transformerNotationWordHighlight(),\n transformerNotationFocus(),\n transformerNotationErrorLevel(),\n ];\n }, [enableTransformer]);\n\n // Build cache key\n const cacheKey = useMemo((): string | null => {\n if (streaming) return null;\n // Use hash for long text\n const hash = safeText.length < MD5_LENGTH_THRESHOLD ? safeText : Md5.hashStr(safeText);\n return [matchedLanguage, builtinTheme, hash].filter(Boolean).join('-');\n }, [safeText, matchedLanguage, builtinTheme, streaming]);\n\n const [data, setData] = useState<string | undefined>();\n\n useEffect(() => {\n if (!cacheKey) {\n setData(undefined);\n return;\n }\n\n // Check cache first\n const cachedPromise = highlightCache.get(cacheKey);\n if (cachedPromise) {\n cachedPromise\n .then((html) => {\n setData(html);\n })\n .catch(() => {\n // Silently handle errors, fallback will be handled in the promise\n });\n return;\n }\n\n // Create new promise for highlighting\n // Using codeToHtml shorthand: automatically loads themes/languages on-demand\n const highlightPromise = (async (): Promise<string> => {\n try {\n // Try full rendering with transformers\n const shikiModule = await shikiModulePromise;\n if (!shikiModule) return safeText;\n\n const effectiveTheme = builtinTheme || 'lobe-theme';\n\n // Load custom theme if using slack-dark or slack-ochin\n if (!builtinTheme && effectiveTheme === 'lobe-theme') {\n const customTheme = customThemes[effectiveTheme];\n if (customTheme) {\n // Use getSingletonHighlighter to load custom theme\n const highlighter = await shikiModule.getSingletonHighlighter({\n langs: [matchedLanguage],\n themes: [customTheme as any],\n });\n\n const html = await highlighter.codeToHtml(safeText, {\n lang: matchedLanguage,\n theme: effectiveTheme,\n transformers,\n });\n\n return html;\n }\n }\n\n // Fallback to codeToHtml for builtin themes\n const codeToHtml = await loadCodeToHtml();\n if (!codeToHtml) return safeText;\n\n const html = await codeToHtml(safeText, {\n lang: matchedLanguage,\n theme: effectiveTheme,\n transformers,\n });\n\n return html;\n } catch (error_) {\n console.error('Advanced rendering failed:', error_);\n\n try {\n // Try simple rendering (without transformers)\n const codeToHtml = await loadCodeToHtml();\n if (!codeToHtml) return safeText;\n const html = await codeToHtml(safeText, {\n lang: matchedLanguage,\n theme: 'lobe-theme',\n });\n return html;\n } catch {\n // Fallback to plain text\n const fallbackHtml = `<pre class=\"fallback\"><code>${escapeHtml(safeText)}</code></pre>`;\n return fallbackHtml;\n }\n }\n })();\n\n // Cache the promise\n highlightCache.set(cacheKey, highlightPromise);\n cleanupCache();\n\n // Handle promise result\n highlightPromise\n .then((html) => {\n // Only update if this is still the current cache key\n if (highlightCache.get(cacheKey) === highlightPromise) {\n setData(html);\n }\n })\n .catch(() => {\n // Remove failed promise from cache\n if (highlightCache.get(cacheKey) === highlightPromise) {\n highlightCache.delete(cacheKey);\n }\n });\n }, [cacheKey, safeText, matchedLanguage, builtinTheme, transformers, customThemes]);\n\n return data || '';\n};\n"],"mappings":";;;;;;AA0BA,MAAM,iCAAiB,IAAI,KAA8B;AAGzD,MAAM,iBAAiB;AAGvB,MAAM,qBAAqB;AACzB,KAAI,eAAe,OAAO,gBAAgB;EAExC,MAAM,kBAAkB,KAAK,MAAM,iBAAiB,GAAI;EACxD,MAAM,eAAe,MAAM,KAAK,eAAe,MAAM,CAAC,CAAC,MAAM,GAAG,gBAAgB;AAChF,OAAK,MAAM,OAAO,aAChB,gBAAe,OAAO,IAAI;;;AAUhC,IAAI,oBAAwD;AAE5D,MAAM,uBAAoD;AACxD,KAAI,OAAO,WAAW,YAAa,QAAO,QAAQ,QAAQ,KAAK;AAE/D,KAAI,CAAC,kBACH,qBAAoB,OAAO,SAAS,MAAM,QAAQ,IAAI,cAAc,KAAK;AAG3E,QAAO;;AAIT,MAAM,wBAAqD;AACzD,KAAI,OAAO,WAAW,YAAa,QAAO,QAAQ,QAAQ,KAAK;AAC/D,QAAO,OAAO;;AAEhB,MAAa,qBAAqB,iBAAiB;AAGnD,MAAa,cAAc,QAAwB;AACjD,QAAO,IACJ,WAAW,KAAK,QAAQ,CACxB,WAAW,KAAK,OAAO,CACvB,WAAW,KAAK,OAAO,CACvB,WAAW,MAAK,SAAS,CACzB,WAAW,KAAK,SAAS;;AAI9B,MAAM,eAAe,EACnB,cAAcA,oBACf;AAED,MAAa,gBACX,MACA,EACE,UACA,mBACA,OAAO,cACP,gBAES;CAEX,MAAM,WAAW,QAAQ;CACzB,MAAM,QAAQ,YAAY,aAAa,aAAa;CAGpD,MAAM,kBAAkB,cAAc,uBAAuB,KAAK,EAAE,CAAC,KAAK,CAAC;CAG3E,MAAM,eAAe,cAAc;AACjC,MAAI,CAAC,kBAAmB;AACxB,SAAO;GACL,yBAAyB;GACzB,8BAA8B;GAC9B,kCAAkC;GAClC,0BAA0B;GAC1B,+BAA+B;GAChC;IACA,CAAC,kBAAkB,CAAC;CAGvB,MAAM,WAAW,cAA6B;AAC5C,MAAI,UAAW,QAAO;AAGtB,SAAO;GAAC;GAAiB;GADZ,SAAS,SAAA,MAAgC,WAAW,IAAI,QAAQ,SAAS;GAC1C,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;IACrE;EAAC;EAAU;EAAiB;EAAc;EAAU,CAAC;CAExD,MAAM,CAAC,MAAM,WAAW,UAA8B;AAEtD,iBAAgB;AACd,MAAI,CAAC,UAAU;AACb,WAAQ,KAAA,EAAU;AAClB;;EAIF,MAAM,gBAAgB,eAAe,IAAI,SAAS;AAClD,MAAI,eAAe;AACjB,iBACG,MAAM,SAAS;AACd,YAAQ,KAAK;KACb,CACD,YAAY,GAEX;AACJ;;EAKF,MAAM,oBAAoB,YAA6B;AACrD,OAAI;IAEF,MAAM,cAAc,MAAM;AAC1B,QAAI,CAAC,YAAa,QAAO;IAEzB,MAAM,iBAAiB,gBAAgB;AAGvC,QAAI,CAAC,gBAAgB,mBAAmB,cAAc;KACpD,MAAM,cAAc,aAAa;AACjC,SAAI,YAaF,
|
|
1
|
+
{"version":3,"file":"useHighlight.mjs","names":["lobeTheme"],"sources":["../../src/hooks/useHighlight.ts"],"sourcesContent":["'use client';\n\nimport {\n transformerNotationDiff,\n transformerNotationErrorLevel,\n transformerNotationFocus,\n transformerNotationHighlight,\n transformerNotationWordHighlight,\n} from '@shikijs/transformers';\nimport { type CSSProperties, useEffect, useMemo, useState } from 'react';\nimport type { BuiltinTheme, CodeToHastOptions, ThemedToken } from 'shiki';\nimport { Md5 } from 'ts-md5';\n\nimport { getCodeLanguageByInput } from '@/Highlighter/const';\nimport lobeTheme from '@/Highlighter/theme/lobe-theme';\n\n// Application-level cache to avoid repeated calculations\nexport const MD5_LENGTH_THRESHOLD = 10_000; // Use async MD5 for text exceeding this length\n\nexport type StreamingHighlightResult = {\n lines: ThemedToken[][];\n preStyle?: CSSProperties;\n};\n\n// Application-level cache for highlighted HTML\n// Key: cacheKey string, Value: Promise<string>\nconst highlightCache = new Map<string, Promise<string>>();\n\n// Maximum cache size to prevent memory leaks\nconst MAX_CACHE_SIZE = 1000;\n\n// Clean up old cache entries when limit is reached\nconst cleanupCache = () => {\n if (highlightCache.size > MAX_CACHE_SIZE) {\n // Remove oldest 20% of entries\n const entriesToRemove = Math.floor(MAX_CACHE_SIZE * 0.2);\n const keysToRemove = Array.from(highlightCache.keys()).slice(0, entriesToRemove);\n for (const key of keysToRemove) {\n highlightCache.delete(key);\n }\n }\n};\n\nexport type ICodeToHtml = (code: string, options: CodeToHastOptions) => Promise<string>;\nexport type ShikiModule = typeof import('shiki');\n\n// Use codeToHtml shorthand for better performance\n// It automatically manages highlighter instances and loads themes/languages on-demand\nlet codeToHtmlPromise: Promise<ICodeToHtml | null> | null = null;\n\nconst loadCodeToHtml = (): Promise<ICodeToHtml | null> => {\n if (typeof window === 'undefined') return Promise.resolve(null);\n\n if (!codeToHtmlPromise) {\n codeToHtmlPromise = import('shiki').then((mod) => mod.codeToHtml ?? null);\n }\n\n return codeToHtmlPromise;\n};\n\n// Export shikiModulePromise for useStreamHighlight compatibility\nconst loadShikiModule = (): Promise<ShikiModule | null> => {\n if (typeof window === 'undefined') return Promise.resolve(null);\n return import('shiki');\n};\nexport const shikiModulePromise = loadShikiModule();\n\n// Helper function: Safe HTML escaping\nexport const escapeHtml = (str: string): string => {\n return str\n .replaceAll('&', '&')\n .replaceAll('<', '<')\n .replaceAll('>', '>')\n .replaceAll('\"', '"')\n .replaceAll(\"'\", ''');\n};\n\n// Main highlight component - optimized version without SWR\nconst customThemes = {\n 'lobe-theme': lobeTheme,\n};\n\nexport const useHighlight = (\n text: string,\n {\n language,\n enableTransformer,\n theme: builtinTheme,\n streaming,\n }: { enableTransformer?: boolean; language: string; streaming?: boolean; theme?: BuiltinTheme },\n): string => {\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 // Optimize transformer creation\n const transformers = useMemo(() => {\n if (!enableTransformer) return;\n return [\n transformerNotationDiff(),\n transformerNotationHighlight(),\n transformerNotationWordHighlight(),\n transformerNotationFocus(),\n transformerNotationErrorLevel(),\n ];\n }, [enableTransformer]);\n\n // Build cache key\n const cacheKey = useMemo((): string | null => {\n if (streaming) return null;\n // Use hash for long text\n const hash = safeText.length < MD5_LENGTH_THRESHOLD ? safeText : Md5.hashStr(safeText);\n return [matchedLanguage, builtinTheme, hash].filter(Boolean).join('-');\n }, [safeText, matchedLanguage, builtinTheme, streaming]);\n\n const [data, setData] = useState<string | undefined>();\n\n useEffect(() => {\n if (!cacheKey) {\n setData(undefined);\n return;\n }\n\n // Check cache first\n const cachedPromise = highlightCache.get(cacheKey);\n if (cachedPromise) {\n cachedPromise\n .then((html) => {\n setData(html);\n })\n .catch(() => {\n // Silently handle errors, fallback will be handled in the promise\n });\n return;\n }\n\n // Create new promise for highlighting\n // Using codeToHtml shorthand: automatically loads themes/languages on-demand\n const highlightPromise = (async (): Promise<string> => {\n try {\n // Try full rendering with transformers\n const shikiModule = await shikiModulePromise;\n if (!shikiModule) return safeText;\n\n const effectiveTheme = builtinTheme || 'lobe-theme';\n\n // Load custom theme if using slack-dark or slack-ochin\n if (!builtinTheme && effectiveTheme === 'lobe-theme') {\n const customTheme = customThemes[effectiveTheme];\n if (customTheme) {\n // Use getSingletonHighlighter to load custom theme\n const highlighter = await shikiModule.getSingletonHighlighter({\n langs: [matchedLanguage],\n themes: [customTheme as any],\n });\n\n const html = await highlighter.codeToHtml(safeText, {\n lang: matchedLanguage,\n theme: effectiveTheme,\n transformers,\n });\n\n return html;\n }\n }\n\n // Fallback to codeToHtml for builtin themes\n const codeToHtml = await loadCodeToHtml();\n if (!codeToHtml) return safeText;\n\n const html = await codeToHtml(safeText, {\n lang: matchedLanguage,\n theme: effectiveTheme,\n transformers,\n });\n\n return html;\n } catch (error_) {\n console.error('Advanced rendering failed:', error_);\n\n try {\n // Try simple rendering (without transformers)\n const codeToHtml = await loadCodeToHtml();\n if (!codeToHtml) return safeText;\n const html = await codeToHtml(safeText, {\n lang: matchedLanguage,\n theme: 'lobe-theme',\n });\n return html;\n } catch {\n // Fallback to plain text\n const fallbackHtml = `<pre class=\"fallback\"><code>${escapeHtml(safeText)}</code></pre>`;\n return fallbackHtml;\n }\n }\n })();\n\n // Cache the promise\n highlightCache.set(cacheKey, highlightPromise);\n cleanupCache();\n\n // Handle promise result\n highlightPromise\n .then((html) => {\n // Only update if this is still the current cache key\n if (highlightCache.get(cacheKey) === highlightPromise) {\n setData(html);\n }\n })\n .catch(() => {\n // Remove failed promise from cache\n if (highlightCache.get(cacheKey) === highlightPromise) {\n highlightCache.delete(cacheKey);\n }\n });\n }, [cacheKey, safeText, matchedLanguage, builtinTheme, transformers, customThemes]);\n\n return data || '';\n};\n"],"mappings":";;;;;;AA0BA,MAAM,iCAAiB,IAAI,KAA8B;AAGzD,MAAM,iBAAiB;AAGvB,MAAM,qBAAqB;AACzB,KAAI,eAAe,OAAO,gBAAgB;EAExC,MAAM,kBAAkB,KAAK,MAAM,iBAAiB,GAAI;EACxD,MAAM,eAAe,MAAM,KAAK,eAAe,MAAM,CAAC,CAAC,MAAM,GAAG,gBAAgB;AAChF,OAAK,MAAM,OAAO,aAChB,gBAAe,OAAO,IAAI;;;AAUhC,IAAI,oBAAwD;AAE5D,MAAM,uBAAoD;AACxD,KAAI,OAAO,WAAW,YAAa,QAAO,QAAQ,QAAQ,KAAK;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,oBAAoB,YAA6B;AACrD,OAAI;IAEF,MAAM,cAAc,MAAM;AAC1B,QAAI,CAAC,YAAa,QAAO;IAEzB,MAAM,iBAAiB,gBAAgB;AAGvC,QAAI,CAAC,gBAAgB,mBAAmB,cAAc;KACpD,MAAM,cAAc,aAAa;AACjC,SAAI,YAaF,QAAO,OANY,MALO,YAAY,wBAAwB;MAC5D,OAAO,CAAC,gBAAgB;MACxB,QAAQ,CAAC,YAAmB;MAC7B,CAAC,EAE6B,WAAW,UAAU;MAClD,MAAM;MACN,OAAO;MACP;MACD,CAAC;;IAON,MAAM,aAAa,MAAM,gBAAgB;AACzC,QAAI,CAAC,WAAY,QAAO;AAQxB,WAAO,MANY,WAAW,UAAU;KACtC,MAAM;KACN,OAAO;KACP;KACD,CAAC;YAGK,QAAQ;AACf,YAAQ,MAAM,8BAA8B,OAAO;AAEnD,QAAI;KAEF,MAAM,aAAa,MAAM,gBAAgB;AACzC,SAAI,CAAC,WAAY,QAAO;AAKxB,YAAO,MAJY,WAAW,UAAU;MACtC,MAAM;MACN,OAAO;MACR,CAAC;YAEI;AAGN,YAAO,+BAD6C,WAAW,SAAS,CAAC;;;MAI3E;AAGJ,iBAAe,IAAI,UAAU,iBAAiB;AAC9C,gBAAc;AAGd,mBACG,MAAM,SAAS;AAEd,OAAI,eAAe,IAAI,SAAS,KAAK,iBACnC,SAAQ,KAAK;IAEf,CACD,YAAY;AAEX,OAAI,eAAe,IAAI,SAAS,KAAK,iBACnC,gBAAe,OAAO,SAAS;IAEjC;IACH;EAAC;EAAU;EAAU;EAAiB;EAAc;EAAc;EAAa,CAAC;AAEnF,QAAO,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"latex.mjs","names":[],"sources":["../../../src/hooks/useMarkdown/latex.ts"],"sourcesContent":["import { renderToString } from 'katex';\n\n// ============================================================================\n// Utility Classes\n// ============================================================================\n\n/**\n * PlaceholderManager - Manages temporary replacement and restoration of protected content\n * Used to protect code blocks and LaTeX expressions during preprocessing\n */\nclass PlaceholderManager {\n private placeholders: string[] = [];\n private prefix: string;\n\n constructor(prefix = 'PROTECTED') {\n this.prefix = prefix;\n }\n\n add(content: string): string {\n const index = this.placeholders.length;\n this.placeholders.push(content);\n return `<<${this.prefix}_${index}>>`;\n }\n\n restore(text: string): string {\n return text.replaceAll(new RegExp(`<<${this.prefix}_(\\\\d+)>>`, 'g'), (_, index) => {\n return this.placeholders[Number.parseInt(index)] || '';\n });\n }\n\n clear(): void {\n this.placeholders = [];\n }\n}\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n// Helper: replace unescaped pipes with \\vert within a LaTeX math fragment\nconst replaceUnescapedPipes = (formula: string): string =>\n // Use \\vert{} so the control sequence terminates before the next token\n formula.replaceAll(/(?<!\\\\)\\|/g, '\\\\vert{}');\n\n/**\n * Converts LaTeX bracket delimiters to dollar sign delimiters.\n * Converts \\[...\\] to $$...$$ and \\(...\\) to $...$\n * Preserves code blocks during the conversion.\n *\n * @param text The input string containing LaTeX expressions\n * @returns The string with LaTeX bracket delimiters converted to dollar sign delimiters\n */\nexport function convertLatexDelimiters(text: string): string {\n const pattern = /(```[\\s\\S]*?```|`.*?`)|\\\\\\[([\\s\\S]*?[^\\\\])\\\\\\]|\\\\\\((.*?)\\\\\\)/g;\n return text.replaceAll(\n pattern,\n (\n match: string,\n codeBlock: string | undefined,\n squareBracket: string | undefined,\n roundBracket: string | undefined,\n ): string => {\n if (codeBlock !== undefined) {\n return codeBlock;\n } else if (squareBracket !== undefined) {\n return `$$${squareBracket}$$`;\n } else if (roundBracket !== undefined) {\n return `$${roundBracket}$`;\n }\n return match;\n },\n );\n}\n\n/**\n * Escapes mhchem commands in LaTeX expressions to ensure proper rendering.\n *\n * @param text The input string containing LaTeX expressions with mhchem commands\n * @returns The string with escaped mhchem commands\n */\nexport function escapeMhchemCommands(text: string) {\n return text.replaceAll('$\\\\ce{', '$\\\\\\\\ce{').replaceAll('$\\\\pu{', '$\\\\\\\\pu{');\n}\n\n/**\n * Escapes pipe characters within LaTeX expressions to prevent them from being interpreted\n * as table column separators in markdown tables.\n *\n * @param text The input string containing LaTeX expressions\n * @returns The string with pipe characters escaped in LaTeX expressions\n */\nexport function escapeLatexPipes(text: string): string {\n // Replace unescaped '|' inside LaTeX math spans with '\\vert' so that\n // remark-gfm table parsing won't treat them as column separators.\n // Leave code blocks/inline code untouched.\n // Also ignore escaped dollars (\\$) which are currency symbols\n\n // Process code blocks first to protect them\n const codeBlocks: string[] = [];\n let content = text.replaceAll(/(```[\\s\\S]*?```|`[^\\n`]*`)/g, (match) => {\n codeBlocks.push(match);\n return `<<CODE_${codeBlocks.length - 1}>>`;\n });\n\n // For display math, allow multiline\n content = content.replaceAll(/\\$\\$([\\s\\S]*?)\\$\\$/g, (match, display) => {\n return `$$${replaceUnescapedPipes(display)}$$`;\n });\n\n // For inline math, use non-greedy match that DOES NOT cross newlines\n // This prevents issues in tables where $ might appear in different cells\n content = content.replaceAll(/(?<!\\\\)\\$(?!\\$)([^\\n$]*)(?<!\\\\)\\$(?!\\$)/g, (match, inline) => {\n return `$${replaceUnescapedPipes(inline)}$`;\n });\n\n // Restore code blocks\n content = content.replaceAll(/<<CODE_(\\d+)>>/g, (_, index) => {\n return codeBlocks[Number.parseInt(index)];\n });\n\n return content;\n}\n\n/**\n * Escapes underscores within \\text{...} commands in LaTeX expressions\n * that are not already escaped.\n * For example, \\text{node_domain} becomes \\text{node\\_domain},\n * but \\text{node\\_domain} remains \\text{node\\_domain}.\n *\n * @param text The input string potentially containing LaTeX expressions\n * @returns The string with unescaped underscores escaped within \\text{...} commands\n */\nexport function escapeTextUnderscores(text: string): string {\n return text.replaceAll(/\\\\text\\{([^}]*)\\}/g, (match, textContent: string) => {\n // textContent is the content within the braces, e.g., \"node_domain\" or \"already\\_escaped\"\n // Replace underscores '_' with '\\_' only if they are NOT preceded by a backslash '\\'.\n // The (?<!\\\\) is a negative lookbehind assertion that ensures the character before '_' is not a '\\'.\n const escapedTextContent = textContent.replaceAll(/(?<!\\\\)_/g, '\\\\_');\n return `\\\\text{${escapedTextContent}}`;\n });\n}\n\n/**\n * Escapes dollar signs that appear to be currency symbols to prevent them from being\n * interpreted as LaTeX math delimiters.\n *\n * This function identifies currency patterns such as:\n * - $20, $100, $1,000\n * - $20-50, $100+\n * - Patterns within markdown tables\n *\n * @param text The input string containing potential currency symbols\n * @returns The string with currency dollar signs escaped\n */\nexport function escapeCurrencyDollars(text: string): string {\n // Protect code blocks and existing LaTeX expressions from processing\n const manager = new PlaceholderManager('PROTECTED');\n\n let content = text.replaceAll(\n // Match patterns to protect (in order):\n // 1. Code blocks: ```...```\n // 2. Inline code: `...`\n // 3. Display math: $$...$$\n // 4. Inline math with LaTeX commands: $...\\...$ (must contain backslash to distinguish from currency)\n // 5. Simple number formulas: $1$, $10$, $100$ (pure digits in math mode)\n // 6. Number lists in math mode: $1,-1,0$ or $1,2,3$ (comma-separated numbers, possibly negative)\n // 7. LaTeX bracket notation: \\[...\\]\n // 8. LaTeX parenthesis notation: \\(...\\)\n /(```[\\s\\S]*?```|`[^\\n`]*`|\\$\\$[\\s\\S]*?\\$\\$|(?<!\\\\)\\$(?!\\$)(?=[\\s\\S]*?\\\\)[\\s\\S]*?(?<!\\\\)\\$(?!\\$)|\\$\\d+\\$|\\$-?\\d+(?:,-?\\d+)+\\$|\\\\\\[[\\s\\S]*?\\\\\\]|\\\\\\(.*?\\\\\\))/g,\n (match) => manager.add(match),\n );\n\n // Escape dollar signs that are clearly currency:\n // - $ followed by a digit\n // - Not preceded by another $ (to avoid breaking $$)\n // - Not followed immediately by another $ (to avoid breaking $1$ LaTeX)\n // - Followed by number patterns with optional commas, decimals, ranges, or plus signs\n // Match patterns like: $20, $1,000, $19.99, $20-50, $300+, $1,000-2,000+\n // But NOT: $1$, $2$ (these are LaTeX formulas)\n // In the replacement: \\\\ = backslash, $$ = literal $, $1 = capture group 1\n content = content.replaceAll(\n /(?<!\\$)\\$(\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?(?:-\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?)?\\+?)(?!\\$)/g,\n '\\\\$$$1',\n );\n\n // Restore protected content\n content = manager.restore(content);\n\n return content;\n}\n\n// Old simple preprocessLaTeX has been replaced by the comprehensive version below\n// The new preprocessLaTeX provides the same default behavior with optional advanced featuresgit\n\n/**\n * Extracts the LaTeX formula after the last $$ delimiter if there's an odd number of $$ delimiters.\n *\n * @param text The input string containing LaTeX formulas\n * @returns The content after the last $$ if there's an odd number of $$, otherwise an empty string\n */\nconst extractIncompleteFormula = (text: string) => {\n // Count the number of $$ delimiters\n const dollarsCount = (text.match(/\\$\\$/g) || []).length;\n\n // If odd number of $$ delimiters, extract content after the last $$\n if (dollarsCount % 2 === 1) {\n const match = text.match(/\\$\\$([\\s\\S]*)$/);\n return match ? match[1] : '';\n }\n\n // If even number of $$ delimiters, return empty string\n return '';\n};\n\n/**\n * Checks if the last LaTeX formula in the text is renderable.\n * Only validates the formula after the last $$ if there's an odd number of $$.\n *\n * @param text The input string containing LaTeX formulas\n * @returns True if the last formula is renderable or if there's no incomplete formula\n */\nexport const isLastFormulaRenderable = (text: string) => {\n const formula = extractIncompleteFormula(text);\n\n // If no incomplete formula, return true\n if (!formula) return true;\n\n // Try to render the last formula\n try {\n renderToString(formula, {\n displayMode: true,\n throwOnError: true,\n });\n return true;\n } catch (error) {\n console.error(`LaTeX formula rendering error: ${error}`);\n return false;\n }\n};\n\n// ============================================================================\n// Advanced Preprocessing Functions\n// ============================================================================\n\n/**\n * Fixes common LaTeX syntax errors automatically\n * - Balances unmatched braces\n * - Balances \\left and \\right delimiters\n *\n * @param text The input string containing LaTeX expressions\n * @returns The string with fixed LaTeX expressions\n */\nexport function fixCommonLaTeXErrors(text: string): string {\n return text.replaceAll(/(\\$\\$[\\s\\S]*?\\$\\$|\\$[\\s\\S]*?\\$)/g, (match) => {\n let fixed = match;\n\n // Fix unbalanced braces\n const openBraces = (fixed.match(/(?<!\\\\)\\{/g) || []).length;\n const closeBraces = (fixed.match(/(?<!\\\\)\\}/g) || []).length;\n if (openBraces > closeBraces) {\n const diff = openBraces - closeBraces;\n const closingBraces = '}'.repeat(diff);\n // Insert before the closing delimiter\n fixed = fixed.replace(/(\\$\\$?)$/, closingBraces + '$1');\n }\n\n // Fix unbalanced \\left and \\right\n const leftDelims = (fixed.match(/\\\\left[(.<[{|]/g) || []).length;\n const rightDelims = (fixed.match(/\\\\right[).>\\]|}]/g) || []).length;\n if (leftDelims > rightDelims) {\n const diff = leftDelims - rightDelims;\n const rightDots = '\\\\right.'.repeat(diff);\n fixed = fixed.replace(/(\\$\\$?)$/, rightDots + '$1');\n }\n\n return fixed;\n });\n}\n\n/**\n * Normalizes whitespace in LaTeX expressions\n * - Removes extra spaces around $ delimiters\n * - Normalizes multiple spaces to single space inside formulas\n *\n * @param text The input string containing LaTeX expressions\n * @returns The string with normalized whitespace\n */\nexport function normalizeLatexSpacing(text: string): string {\n let result = text;\n\n // Remove spaces inside $ delimiters (at the edges)\n result = result.replaceAll(/\\$\\s+/g, '$');\n result = result.replaceAll(/\\s+\\$/g, '$');\n result = result.replaceAll(/\\$\\$\\s+/g, '$$');\n result = result.replaceAll(/\\s+\\$\\$/g, '$$');\n\n // Normalize multiple spaces inside formulas to single space\n result = result.replaceAll(/(\\$\\$[\\s\\S]*?\\$\\$|\\$[\\s\\S]*?\\$)/g, (match) => {\n return match.replaceAll(/\\s{2,}/g, ' ');\n });\n\n return result;\n}\n\n/**\n * Validates all LaTeX expressions in the text\n * Returns detailed information about validation results\n *\n * @param text The input string containing LaTeX expressions\n * @returns Validation results with errors if any\n */\nexport function validateLatexExpressions(text: string): {\n errors: Array<{\n formula: string;\n message: string;\n position: number;\n type: 'display' | 'inline';\n }>;\n totalExpressions: number;\n valid: boolean;\n} {\n const errors: Array<{\n formula: string;\n message: string;\n position: number;\n type: 'display' | 'inline';\n }> = [];\n\n let totalExpressions = 0;\n const pattern = /\\$\\$([\\s\\S]*?)\\$\\$|(?<!\\\\)\\$(?!\\$)([\\s\\S]*?)(?<!\\\\)\\$(?!\\$)/g;\n let match;\n\n while ((match = pattern.exec(text)) !== null) {\n totalExpressions++;\n const formula = match[1] || match[2];\n const isDisplay = match[0].startsWith('$$');\n\n try {\n renderToString(formula, {\n displayMode: isDisplay,\n strict: 'warn',\n throwOnError: true,\n trust: false,\n });\n } catch (error) {\n errors.push({\n formula: formula.slice(0, 50) + (formula.length > 50 ? '...' : ''),\n message: error instanceof Error ? error.message : String(error),\n position: match.index,\n type: isDisplay ? 'display' : 'inline',\n });\n }\n }\n\n return {\n errors,\n totalExpressions,\n valid: errors.length === 0,\n };\n}\n\n/**\n * Handles CJK (Chinese, Japanese, Korean) characters mixed with LaTeX\n * Optionally adds spaces between CJK characters and LaTeX expressions for better rendering\n *\n * @param text The input string\n * @param addSpaces Whether to add spaces between CJK and LaTeX (default: false)\n * @returns The processed string\n */\nexport function handleCJKWithLatex(text: string, addSpaces = false): string {\n if (!addSpaces) return text;\n\n let result = text;\n\n // Add space between CJK character and opening $\n result = result.replaceAll(/([\\u3040-\\u30FF\\u4E00-\\u9FA5])(\\$)/g, '$1 $2');\n\n // Add space between closing $ and CJK character\n result = result.replaceAll(/(\\$)([\\u3040-\\u30FF\\u4E00-\\u9FA5])/g, '$1 $2');\n\n return result;\n}\n\n// ============================================================================\n// Advanced Preprocessing Options\n// ============================================================================\n\nexport interface AdvancedPreprocessOptions {\n /** Add spaces between CJK and LaTeX (default: false, requires handleCJK: true) */\n addCJKSpaces?: boolean;\n /** Convert bracket notation \\[...\\] to $$...$$ (default: true) */\n convertBrackets?: boolean;\n /** Enable currency escaping (default: true) */\n escapeCurrency?: boolean;\n /** Escape mhchem commands (default: true) */\n escapeMhchem?: boolean;\n /** Escape pipe symbols in LaTeX (default: true) */\n escapePipes?: boolean;\n /** Escape underscores in \\text{} (default: true) */\n escapeUnderscores?: boolean;\n /** Automatically fix common LaTeX errors (default: false) */\n fixErrors?: boolean;\n /** Handle CJK characters (default: false) */\n handleCJK?: boolean;\n /** Normalize whitespace (default: false) */\n normalizeSpacing?: boolean;\n /** Throw error on validation failure (default: false, requires validate: true) */\n throwOnValidationError?: boolean;\n /** Validate LaTeX syntax (default: false) */\n validate?: boolean;\n}\n\n/**\n * Comprehensive LaTeX preprocessing with configurable options\n *\n * This is the main preprocessing function that handles:\n * - Currency symbol escaping (e.g., $20 → \\$20)\n * - LaTeX delimiter conversion (\\[...\\] → $$...$$)\n * - Special character escaping (pipes, underscores, mhchem)\n * - Optional error fixing and validation\n * - Optional CJK character handling\n *\n * @param text The input string containing LaTeX and Markdown\n * @param options Configuration options for fine-grained control\n * @returns The preprocessed string\n *\n * @example\n * ```ts\n * // Default behavior (same as old preprocessLaTeX)\n * preprocessLaTeX('向量$90^\\\\circ$,非 $0^\\\\circ$ 和 $180^\\\\circ$')\n *\n * // With custom options\n * preprocessLaTeX(text, {\n * fixErrors: true,\n * validate: true,\n * handleCJK: true\n * })\n * ```\n */\nexport function preprocessLaTeX(text: string, options: AdvancedPreprocessOptions = {}): string {\n const {\n addCJKSpaces = false,\n convertBrackets = true,\n escapeCurrency = true,\n escapeMhchem = true,\n escapePipes = true,\n escapeUnderscores = true,\n fixErrors = false,\n handleCJK = false,\n normalizeSpacing = false,\n throwOnValidationError = false,\n validate = false,\n } = options;\n\n let content = text;\n\n // Phase 1: Currency escaping (if enabled)\n if (escapeCurrency) {\n content = escapeCurrencyDollars(content);\n }\n\n // Phase 2: Bracket conversion (if enabled)\n if (convertBrackets) {\n content = convertLatexDelimiters(content);\n }\n\n // Phase 3: LaTeX-specific escaping\n if (escapeMhchem) {\n content = escapeMhchemCommands(content);\n }\n\n if (escapePipes) {\n content = escapeLatexPipes(content);\n }\n\n if (escapeUnderscores) {\n content = escapeTextUnderscores(content);\n }\n\n // Phase 4: Error fixing (if enabled)\n if (fixErrors) {\n content = fixCommonLaTeXErrors(content);\n }\n\n // Phase 5: Whitespace normalization (if enabled)\n if (normalizeSpacing) {\n content = normalizeLatexSpacing(content);\n }\n\n // Phase 6: CJK handling (if enabled)\n if (handleCJK) {\n content = handleCJKWithLatex(content, addCJKSpaces);\n }\n\n // Phase 7: Validation (if enabled)\n if (validate) {\n const validation = validateLatexExpressions(content);\n if (!validation.valid) {\n const errorMessage = `LaTeX validation failed (${validation.errors.length}/${validation.totalExpressions} expressions have errors):\\n${validation.errors.map((e) => ` - [${e.type}] at position ${e.position}: ${e.message}\\n Formula: ${e.formula}`).join('\\n')}`;\n\n if (throwOnValidationError) {\n throw new Error(errorMessage);\n } else {\n console.warn(errorMessage);\n }\n }\n }\n\n return content;\n}\n\n/**\n * Strict preprocessing mode - enables all safety features and validations\n * Use this when you want maximum correctness and are willing to accept the performance cost\n *\n * @param text The input string\n * @returns The preprocessed string with all features enabled\n *\n * @example\n * ```ts\n * const processed = preprocessLaTeXStrict(userInput)\n * // Enables: error fixing, validation, CJK handling, space normalization\n * ```\n */\nexport function preprocessLaTeXStrict(text: string): string {\n return preprocessLaTeX(text, {\n addCJKSpaces: false, // Usually don't want extra spaces\n convertBrackets: true,\n escapeCurrency: true,\n escapeMhchem: true,\n escapePipes: true,\n escapeUnderscores: true,\n fixErrors: true,\n handleCJK: true,\n normalizeSpacing: true,\n throwOnValidationError: false, // Warn but don't throw\n validate: true,\n });\n}\n\n/**\n * Minimal preprocessing mode - only essential operations\n * Use this for better performance when you control the input\n *\n * @param text The input string\n * @returns The preprocessed string with minimal processing\n *\n * @example\n * ```ts\n * const processed = preprocessLaTeXMinimal(trustedInput)\n * // Only escapes currency and converts brackets\n * ```\n */\nexport function preprocessLaTeXMinimal(text: string): string {\n return preprocessLaTeX(text, {\n convertBrackets: true,\n escapeCurrency: true,\n escapeMhchem: false,\n escapePipes: false,\n escapeUnderscores: false,\n fixErrors: false,\n handleCJK: false,\n normalizeSpacing: false,\n validate: false,\n });\n}\n"],"mappings":";;;;;;AAUA,IAAM,qBAAN,MAAyB;CAIvB,YAAY,SAAS,aAAa;sBAHD,EAAE;AA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AQ;AAE1E,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DT,SAAgB,gBAAgB,MAAc,UAAqC,EAAE,EAAU;CAC7F,MAAM,EACJ,eAAe,OACf,kBAAkB,MAClB,iBAAiB,MACjB,eAAe,MACf,cAAc,MACd,oBAAoB,MACpB,YAAY,OACZ,YAAY,OACZ,mBAAmB,OACnB,yBAAyB,OACzB,WAAW,UACT;CAEJ,IAAI,UAAU;AAGd,KAAI,eACF,WAAU,sBAAsB,QAAQ;AAI1C,KAAI,gBACF,WAAU,uBAAuB,QAAQ;AAI3C,KAAI,aACF,WAAU,qBAAqB,QAAQ;AAGzC,KAAI,YACF,WAAU,iBAAiB,QAAQ;AAGrC,KAAI,kBACF,WAAU,sBAAsB,QAAQ;AAI1C,KAAI,UACF,WAAU,qBAAqB,QAAQ;AAIzC,KAAI,iBACF,WAAU,sBAAsB,QAAQ;AAI1C,KAAI,UACF,WAAU,mBAAmB,SAAS,aAAa;AAIrD,KAAI,UAAU;EACZ,MAAM,aAAa,yBAAyB,QAAQ;AACpD,MAAI,CAAC,WAAW,OAAO;GACrB,MAAM,eAAe,4BAA4B,WAAW,OAAO,OAAO,GAAG,WAAW,iBAAiB,8BAA8B,WAAW,OAAO,KAAK,MAAM,QAAQ,EAAE,KAAK,gBAAgB,EAAE,SAAS,IAAI,EAAE,QAAQ,iBAAiB,EAAE,UAAU,CAAC,KAAK,KAAK;AAEpQ,OAAI,uBACF,OAAM,IAAI,MAAM,aAAa;OAE7B,SAAQ,KAAK,aAAa;;;AAKhC,QAAO"}
|
|
1
|
+
{"version":3,"file":"latex.mjs","names":[],"sources":["../../../src/hooks/useMarkdown/latex.ts"],"sourcesContent":["import { renderToString } from 'katex';\n\n// ============================================================================\n// Utility Classes\n// ============================================================================\n\n/**\n * PlaceholderManager - Manages temporary replacement and restoration of protected content\n * Used to protect code blocks and LaTeX expressions during preprocessing\n */\nclass PlaceholderManager {\n private placeholders: string[] = [];\n private prefix: string;\n\n constructor(prefix = 'PROTECTED') {\n this.prefix = prefix;\n }\n\n add(content: string): string {\n const index = this.placeholders.length;\n this.placeholders.push(content);\n return `<<${this.prefix}_${index}>>`;\n }\n\n restore(text: string): string {\n return text.replaceAll(new RegExp(`<<${this.prefix}_(\\\\d+)>>`, 'g'), (_, index) => {\n return this.placeholders[Number.parseInt(index)] || '';\n });\n }\n\n clear(): void {\n this.placeholders = [];\n }\n}\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n// Helper: replace unescaped pipes with \\vert within a LaTeX math fragment\nconst replaceUnescapedPipes = (formula: string): string =>\n // Use \\vert{} so the control sequence terminates before the next token\n formula.replaceAll(/(?<!\\\\)\\|/g, '\\\\vert{}');\n\n/**\n * Converts LaTeX bracket delimiters to dollar sign delimiters.\n * Converts \\[...\\] to $$...$$ and \\(...\\) to $...$\n * Preserves code blocks during the conversion.\n *\n * @param text The input string containing LaTeX expressions\n * @returns The string with LaTeX bracket delimiters converted to dollar sign delimiters\n */\nexport function convertLatexDelimiters(text: string): string {\n const pattern = /(```[\\s\\S]*?```|`.*?`)|\\\\\\[([\\s\\S]*?[^\\\\])\\\\\\]|\\\\\\((.*?)\\\\\\)/g;\n return text.replaceAll(\n pattern,\n (\n match: string,\n codeBlock: string | undefined,\n squareBracket: string | undefined,\n roundBracket: string | undefined,\n ): string => {\n if (codeBlock !== undefined) {\n return codeBlock;\n } else if (squareBracket !== undefined) {\n return `$$${squareBracket}$$`;\n } else if (roundBracket !== undefined) {\n return `$${roundBracket}$`;\n }\n return match;\n },\n );\n}\n\n/**\n * Escapes mhchem commands in LaTeX expressions to ensure proper rendering.\n *\n * @param text The input string containing LaTeX expressions with mhchem commands\n * @returns The string with escaped mhchem commands\n */\nexport function escapeMhchemCommands(text: string) {\n return text.replaceAll('$\\\\ce{', '$\\\\\\\\ce{').replaceAll('$\\\\pu{', '$\\\\\\\\pu{');\n}\n\n/**\n * Escapes pipe characters within LaTeX expressions to prevent them from being interpreted\n * as table column separators in markdown tables.\n *\n * @param text The input string containing LaTeX expressions\n * @returns The string with pipe characters escaped in LaTeX expressions\n */\nexport function escapeLatexPipes(text: string): string {\n // Replace unescaped '|' inside LaTeX math spans with '\\vert' so that\n // remark-gfm table parsing won't treat them as column separators.\n // Leave code blocks/inline code untouched.\n // Also ignore escaped dollars (\\$) which are currency symbols\n\n // Process code blocks first to protect them\n const codeBlocks: string[] = [];\n let content = text.replaceAll(/(```[\\s\\S]*?```|`[^\\n`]*`)/g, (match) => {\n codeBlocks.push(match);\n return `<<CODE_${codeBlocks.length - 1}>>`;\n });\n\n // For display math, allow multiline\n content = content.replaceAll(/\\$\\$([\\s\\S]*?)\\$\\$/g, (match, display) => {\n return `$$${replaceUnescapedPipes(display)}$$`;\n });\n\n // For inline math, use non-greedy match that DOES NOT cross newlines\n // This prevents issues in tables where $ might appear in different cells\n content = content.replaceAll(/(?<!\\\\)\\$(?!\\$)([^\\n$]*)(?<!\\\\)\\$(?!\\$)/g, (match, inline) => {\n return `$${replaceUnescapedPipes(inline)}$`;\n });\n\n // Restore code blocks\n content = content.replaceAll(/<<CODE_(\\d+)>>/g, (_, index) => {\n return codeBlocks[Number.parseInt(index)];\n });\n\n return content;\n}\n\n/**\n * Escapes underscores within \\text{...} commands in LaTeX expressions\n * that are not already escaped.\n * For example, \\text{node_domain} becomes \\text{node\\_domain},\n * but \\text{node\\_domain} remains \\text{node\\_domain}.\n *\n * @param text The input string potentially containing LaTeX expressions\n * @returns The string with unescaped underscores escaped within \\text{...} commands\n */\nexport function escapeTextUnderscores(text: string): string {\n return text.replaceAll(/\\\\text\\{([^}]*)\\}/g, (match, textContent: string) => {\n // textContent is the content within the braces, e.g., \"node_domain\" or \"already\\_escaped\"\n // Replace underscores '_' with '\\_' only if they are NOT preceded by a backslash '\\'.\n // The (?<!\\\\) is a negative lookbehind assertion that ensures the character before '_' is not a '\\'.\n const escapedTextContent = textContent.replaceAll(/(?<!\\\\)_/g, '\\\\_');\n return `\\\\text{${escapedTextContent}}`;\n });\n}\n\n/**\n * Escapes dollar signs that appear to be currency symbols to prevent them from being\n * interpreted as LaTeX math delimiters.\n *\n * This function identifies currency patterns such as:\n * - $20, $100, $1,000\n * - $20-50, $100+\n * - Patterns within markdown tables\n *\n * @param text The input string containing potential currency symbols\n * @returns The string with currency dollar signs escaped\n */\nexport function escapeCurrencyDollars(text: string): string {\n // Protect code blocks and existing LaTeX expressions from processing\n const manager = new PlaceholderManager('PROTECTED');\n\n let content = text.replaceAll(\n // Match patterns to protect (in order):\n // 1. Code blocks: ```...```\n // 2. Inline code: `...`\n // 3. Display math: $$...$$\n // 4. Inline math with LaTeX commands: $...\\...$ (must contain backslash to distinguish from currency)\n // 5. Simple number formulas: $1$, $10$, $100$ (pure digits in math mode)\n // 6. Number lists in math mode: $1,-1,0$ or $1,2,3$ (comma-separated numbers, possibly negative)\n // 7. LaTeX bracket notation: \\[...\\]\n // 8. LaTeX parenthesis notation: \\(...\\)\n /(```[\\s\\S]*?```|`[^\\n`]*`|\\$\\$[\\s\\S]*?\\$\\$|(?<!\\\\)\\$(?!\\$)(?=[\\s\\S]*?\\\\)[\\s\\S]*?(?<!\\\\)\\$(?!\\$)|\\$\\d+\\$|\\$-?\\d+(?:,-?\\d+)+\\$|\\\\\\[[\\s\\S]*?\\\\\\]|\\\\\\(.*?\\\\\\))/g,\n (match) => manager.add(match),\n );\n\n // Escape dollar signs that are clearly currency:\n // - $ followed by a digit\n // - Not preceded by another $ (to avoid breaking $$)\n // - Not followed immediately by another $ (to avoid breaking $1$ LaTeX)\n // - Followed by number patterns with optional commas, decimals, ranges, or plus signs\n // Match patterns like: $20, $1,000, $19.99, $20-50, $300+, $1,000-2,000+\n // But NOT: $1$, $2$ (these are LaTeX formulas)\n // In the replacement: \\\\ = backslash, $$ = literal $, $1 = capture group 1\n content = content.replaceAll(\n /(?<!\\$)\\$(\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?(?:-\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?)?\\+?)(?!\\$)/g,\n '\\\\$$$1',\n );\n\n // Restore protected content\n content = manager.restore(content);\n\n return content;\n}\n\n// Old simple preprocessLaTeX has been replaced by the comprehensive version below\n// The new preprocessLaTeX provides the same default behavior with optional advanced featuresgit\n\n/**\n * Extracts the LaTeX formula after the last $$ delimiter if there's an odd number of $$ delimiters.\n *\n * @param text The input string containing LaTeX formulas\n * @returns The content after the last $$ if there's an odd number of $$, otherwise an empty string\n */\nconst extractIncompleteFormula = (text: string) => {\n // Count the number of $$ delimiters\n const dollarsCount = (text.match(/\\$\\$/g) || []).length;\n\n // If odd number of $$ delimiters, extract content after the last $$\n if (dollarsCount % 2 === 1) {\n const match = text.match(/\\$\\$([\\s\\S]*)$/);\n return match ? match[1] : '';\n }\n\n // If even number of $$ delimiters, return empty string\n return '';\n};\n\n/**\n * Checks if the last LaTeX formula in the text is renderable.\n * Only validates the formula after the last $$ if there's an odd number of $$.\n *\n * @param text The input string containing LaTeX formulas\n * @returns True if the last formula is renderable or if there's no incomplete formula\n */\nexport const isLastFormulaRenderable = (text: string) => {\n const formula = extractIncompleteFormula(text);\n\n // If no incomplete formula, return true\n if (!formula) return true;\n\n // Try to render the last formula\n try {\n renderToString(formula, {\n displayMode: true,\n throwOnError: true,\n });\n return true;\n } catch (error) {\n console.error(`LaTeX formula rendering error: ${error}`);\n return false;\n }\n};\n\n// ============================================================================\n// Advanced Preprocessing Functions\n// ============================================================================\n\n/**\n * Fixes common LaTeX syntax errors automatically\n * - Balances unmatched braces\n * - Balances \\left and \\right delimiters\n *\n * @param text The input string containing LaTeX expressions\n * @returns The string with fixed LaTeX expressions\n */\nexport function fixCommonLaTeXErrors(text: string): string {\n return text.replaceAll(/(\\$\\$[\\s\\S]*?\\$\\$|\\$[\\s\\S]*?\\$)/g, (match) => {\n let fixed = match;\n\n // Fix unbalanced braces\n const openBraces = (fixed.match(/(?<!\\\\)\\{/g) || []).length;\n const closeBraces = (fixed.match(/(?<!\\\\)\\}/g) || []).length;\n if (openBraces > closeBraces) {\n const diff = openBraces - closeBraces;\n const closingBraces = '}'.repeat(diff);\n // Insert before the closing delimiter\n fixed = fixed.replace(/(\\$\\$?)$/, closingBraces + '$1');\n }\n\n // Fix unbalanced \\left and \\right\n const leftDelims = (fixed.match(/\\\\left[(.<[{|]/g) || []).length;\n const rightDelims = (fixed.match(/\\\\right[).>\\]|}]/g) || []).length;\n if (leftDelims > rightDelims) {\n const diff = leftDelims - rightDelims;\n const rightDots = '\\\\right.'.repeat(diff);\n fixed = fixed.replace(/(\\$\\$?)$/, rightDots + '$1');\n }\n\n return fixed;\n });\n}\n\n/**\n * Normalizes whitespace in LaTeX expressions\n * - Removes extra spaces around $ delimiters\n * - Normalizes multiple spaces to single space inside formulas\n *\n * @param text The input string containing LaTeX expressions\n * @returns The string with normalized whitespace\n */\nexport function normalizeLatexSpacing(text: string): string {\n let result = text;\n\n // Remove spaces inside $ delimiters (at the edges)\n result = result.replaceAll(/\\$\\s+/g, '$');\n result = result.replaceAll(/\\s+\\$/g, '$');\n result = result.replaceAll(/\\$\\$\\s+/g, '$$');\n result = result.replaceAll(/\\s+\\$\\$/g, '$$');\n\n // Normalize multiple spaces inside formulas to single space\n result = result.replaceAll(/(\\$\\$[\\s\\S]*?\\$\\$|\\$[\\s\\S]*?\\$)/g, (match) => {\n return match.replaceAll(/\\s{2,}/g, ' ');\n });\n\n return result;\n}\n\n/**\n * Validates all LaTeX expressions in the text\n * Returns detailed information about validation results\n *\n * @param text The input string containing LaTeX expressions\n * @returns Validation results with errors if any\n */\nexport function validateLatexExpressions(text: string): {\n errors: Array<{\n formula: string;\n message: string;\n position: number;\n type: 'display' | 'inline';\n }>;\n totalExpressions: number;\n valid: boolean;\n} {\n const errors: Array<{\n formula: string;\n message: string;\n position: number;\n type: 'display' | 'inline';\n }> = [];\n\n let totalExpressions = 0;\n const pattern = /\\$\\$([\\s\\S]*?)\\$\\$|(?<!\\\\)\\$(?!\\$)([\\s\\S]*?)(?<!\\\\)\\$(?!\\$)/g;\n let match;\n\n while ((match = pattern.exec(text)) !== null) {\n totalExpressions++;\n const formula = match[1] || match[2];\n const isDisplay = match[0].startsWith('$$');\n\n try {\n renderToString(formula, {\n displayMode: isDisplay,\n strict: 'warn',\n throwOnError: true,\n trust: false,\n });\n } catch (error) {\n errors.push({\n formula: formula.slice(0, 50) + (formula.length > 50 ? '...' : ''),\n message: error instanceof Error ? error.message : String(error),\n position: match.index,\n type: isDisplay ? 'display' : 'inline',\n });\n }\n }\n\n return {\n errors,\n totalExpressions,\n valid: errors.length === 0,\n };\n}\n\n/**\n * Handles CJK (Chinese, Japanese, Korean) characters mixed with LaTeX\n * Optionally adds spaces between CJK characters and LaTeX expressions for better rendering\n *\n * @param text The input string\n * @param addSpaces Whether to add spaces between CJK and LaTeX (default: false)\n * @returns The processed string\n */\nexport function handleCJKWithLatex(text: string, addSpaces = false): string {\n if (!addSpaces) return text;\n\n let result = text;\n\n // Add space between CJK character and opening $\n result = result.replaceAll(/([\\u3040-\\u30FF\\u4E00-\\u9FA5])(\\$)/g, '$1 $2');\n\n // Add space between closing $ and CJK character\n result = result.replaceAll(/(\\$)([\\u3040-\\u30FF\\u4E00-\\u9FA5])/g, '$1 $2');\n\n return result;\n}\n\n// ============================================================================\n// Advanced Preprocessing Options\n// ============================================================================\n\nexport interface AdvancedPreprocessOptions {\n /** Add spaces between CJK and LaTeX (default: false, requires handleCJK: true) */\n addCJKSpaces?: boolean;\n /** Convert bracket notation \\[...\\] to $$...$$ (default: true) */\n convertBrackets?: boolean;\n /** Enable currency escaping (default: true) */\n escapeCurrency?: boolean;\n /** Escape mhchem commands (default: true) */\n escapeMhchem?: boolean;\n /** Escape pipe symbols in LaTeX (default: true) */\n escapePipes?: boolean;\n /** Escape underscores in \\text{} (default: true) */\n escapeUnderscores?: boolean;\n /** Automatically fix common LaTeX errors (default: false) */\n fixErrors?: boolean;\n /** Handle CJK characters (default: false) */\n handleCJK?: boolean;\n /** Normalize whitespace (default: false) */\n normalizeSpacing?: boolean;\n /** Throw error on validation failure (default: false, requires validate: true) */\n throwOnValidationError?: boolean;\n /** Validate LaTeX syntax (default: false) */\n validate?: boolean;\n}\n\n/**\n * Comprehensive LaTeX preprocessing with configurable options\n *\n * This is the main preprocessing function that handles:\n * - Currency symbol escaping (e.g., $20 → \\$20)\n * - LaTeX delimiter conversion (\\[...\\] → $$...$$)\n * - Special character escaping (pipes, underscores, mhchem)\n * - Optional error fixing and validation\n * - Optional CJK character handling\n *\n * @param text The input string containing LaTeX and Markdown\n * @param options Configuration options for fine-grained control\n * @returns The preprocessed string\n *\n * @example\n * ```ts\n * // Default behavior (same as old preprocessLaTeX)\n * preprocessLaTeX('向量$90^\\\\circ$,非 $0^\\\\circ$ 和 $180^\\\\circ$')\n *\n * // With custom options\n * preprocessLaTeX(text, {\n * fixErrors: true,\n * validate: true,\n * handleCJK: true\n * })\n * ```\n */\nexport function preprocessLaTeX(text: string, options: AdvancedPreprocessOptions = {}): string {\n const {\n addCJKSpaces = false,\n convertBrackets = true,\n escapeCurrency = true,\n escapeMhchem = true,\n escapePipes = true,\n escapeUnderscores = true,\n fixErrors = false,\n handleCJK = false,\n normalizeSpacing = false,\n throwOnValidationError = false,\n validate = false,\n } = options;\n\n let content = text;\n\n // Phase 1: Currency escaping (if enabled)\n if (escapeCurrency) {\n content = escapeCurrencyDollars(content);\n }\n\n // Phase 2: Bracket conversion (if enabled)\n if (convertBrackets) {\n content = convertLatexDelimiters(content);\n }\n\n // Phase 3: LaTeX-specific escaping\n if (escapeMhchem) {\n content = escapeMhchemCommands(content);\n }\n\n if (escapePipes) {\n content = escapeLatexPipes(content);\n }\n\n if (escapeUnderscores) {\n content = escapeTextUnderscores(content);\n }\n\n // Phase 4: Error fixing (if enabled)\n if (fixErrors) {\n content = fixCommonLaTeXErrors(content);\n }\n\n // Phase 5: Whitespace normalization (if enabled)\n if (normalizeSpacing) {\n content = normalizeLatexSpacing(content);\n }\n\n // Phase 6: CJK handling (if enabled)\n if (handleCJK) {\n content = handleCJKWithLatex(content, addCJKSpaces);\n }\n\n // Phase 7: Validation (if enabled)\n if (validate) {\n const validation = validateLatexExpressions(content);\n if (!validation.valid) {\n const errorMessage = `LaTeX validation failed (${validation.errors.length}/${validation.totalExpressions} expressions have errors):\\n${validation.errors.map((e) => ` - [${e.type}] at position ${e.position}: ${e.message}\\n Formula: ${e.formula}`).join('\\n')}`;\n\n if (throwOnValidationError) {\n throw new Error(errorMessage);\n } else {\n console.warn(errorMessage);\n }\n }\n }\n\n return content;\n}\n\n/**\n * Strict preprocessing mode - enables all safety features and validations\n * Use this when you want maximum correctness and are willing to accept the performance cost\n *\n * @param text The input string\n * @returns The preprocessed string with all features enabled\n *\n * @example\n * ```ts\n * const processed = preprocessLaTeXStrict(userInput)\n * // Enables: error fixing, validation, CJK handling, space normalization\n * ```\n */\nexport function preprocessLaTeXStrict(text: string): string {\n return preprocessLaTeX(text, {\n addCJKSpaces: false, // Usually don't want extra spaces\n convertBrackets: true,\n escapeCurrency: true,\n escapeMhchem: true,\n escapePipes: true,\n escapeUnderscores: true,\n fixErrors: true,\n handleCJK: true,\n normalizeSpacing: true,\n throwOnValidationError: false, // Warn but don't throw\n validate: true,\n });\n}\n\n/**\n * Minimal preprocessing mode - only essential operations\n * Use this for better performance when you control the input\n *\n * @param text The input string\n * @returns The preprocessed string with minimal processing\n *\n * @example\n * ```ts\n * const processed = preprocessLaTeXMinimal(trustedInput)\n * // Only escapes currency and converts brackets\n * ```\n */\nexport function preprocessLaTeXMinimal(text: string): string {\n return preprocessLaTeX(text, {\n convertBrackets: true,\n escapeCurrency: true,\n escapeMhchem: false,\n escapePipes: false,\n escapeUnderscores: false,\n fixErrors: false,\n handleCJK: false,\n normalizeSpacing: false,\n validate: false,\n });\n}\n"],"mappings":";;;;;;AAUA,IAAM,qBAAN,MAAyB;CAIvB,YAAY,SAAS,aAAa;sBAHD,EAAE;AAIjC,OAAK,SAAS;;CAGhB,IAAI,SAAyB;EAC3B,MAAM,QAAQ,KAAK,aAAa;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gB,MAAc,UAAqC,EAAE,EAAU;CAC7F,MAAM,EACJ,eAAe,OACf,kBAAkB,MAClB,iBAAiB,MACjB,eAAe,MACf,cAAc,MACd,oBAAoB,MACpB,YAAY,OACZ,YAAY,OACZ,mBAAmB,OACnB,yBAAyB,OACzB,WAAW,UACT;CAEJ,IAAI,UAAU;AAGd,KAAI,eACF,WAAU,sBAAsB,QAAQ;AAI1C,KAAI,gBACF,WAAU,uBAAuB,QAAQ;AAI3C,KAAI,aACF,WAAU,qBAAqB,QAAQ;AAGzC,KAAI,YACF,WAAU,iBAAiB,QAAQ;AAGrC,KAAI,kBACF,WAAU,sBAAsB,QAAQ;AAI1C,KAAI,UACF,WAAU,qBAAqB,QAAQ;AAIzC,KAAI,iBACF,WAAU,sBAAsB,QAAQ;AAI1C,KAAI,UACF,WAAU,mBAAmB,SAAS,aAAa;AAIrD,KAAI,UAAU;EACZ,MAAM,aAAa,yBAAyB,QAAQ;AACpD,MAAI,CAAC,WAAW,OAAO;GACrB,MAAM,eAAe,4BAA4B,WAAW,OAAO,OAAO,GAAG,WAAW,iBAAiB,8BAA8B,WAAW,OAAO,KAAK,MAAM,QAAQ,EAAE,KAAK,gBAAgB,EAAE,SAAS,IAAI,EAAE,QAAQ,iBAAiB,EAAE,UAAU,CAAC,KAAK,KAAK;AAEpQ,OAAI,uBACF,OAAM,IAAI,MAAM,aAAa;OAE7B,SAAQ,KAAK,aAAa;;;AAKhC,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMarkdownComponents.mjs","names":[],"sources":["../../../src/hooks/useMarkdown/useMarkdownComponents.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useMemo } from 'react';\nimport type { Components } from 'react-markdown';\n\nimport Hotkey from '@/Hotkey';\nimport { CodeBlock } from '@/Markdown/components/CodeBlock';\nimport { useMarkdownContext } from '@/Markdown/components/MarkdownProvider';\nimport Image from '@/mdx/mdxComponents/Image';\nimport Link from '@/mdx/mdxComponents/Link';\nimport Section from '@/mdx/mdxComponents/Section';\nimport Video from '@/mdx/mdxComponents/Video';\n\nexport const useMarkdownComponents = (): Components => {\n const {\n components,\n animated,\n citations,\n componentProps,\n enableMermaid,\n fullFeaturedCodeBlock,\n showFootnotes,\n } = useMarkdownContext();\n\n const memoA = useCallback(\n ({ node, ...props }: any) => <Link citations={citations} {...props} {...componentProps?.a} />,\n [citations, componentProps?.a],\n );\n\n const memoImg = useCallback(\n ({ node, ...props }: any) => <Image {...props} {...componentProps?.img} />,\n [componentProps?.img],\n );\n\n const memoVideo = useCallback(\n ({ node, ...props }: any) => <Video {...props} {...componentProps?.video} />,\n [componentProps?.video],\n );\n\n const memoSection = useCallback(\n ({ node, ...props }: any) => <Section showFootnotes={showFootnotes} {...props} />,\n [showFootnotes],\n );\n\n const memoKbd = useCallback(\n ({ children }: any) => <Hotkey keys={children} style={{ display: 'inline-flex' }} />,\n [],\n );\n\n const memoBr = useCallback(() => <br />, []);\n\n const memeP = useCallback(({ style, children, className }: any) => {\n const skipWrapperTags = ['img', 'video'];\n if (typeof children === 'object' && skipWrapperTags.includes(children?.props?.node?.tagName)) {\n return children;\n }\n return (\n <p className={className} style={style}>\n {children}\n </p>\n );\n }, []);\n\n // Stable references for theme objects to prevent unnecessary re-renders\n const highlightTheme = useMemo(\n () => componentProps?.highlight?.theme,\n [JSON.stringify(componentProps?.highlight?.theme)],\n );\n\n const mermaidTheme = useMemo(\n () => componentProps?.mermaid?.theme,\n [JSON.stringify(componentProps?.mermaid?.theme)],\n );\n\n // Create stable component props reference\n const stableComponentProps = useMemo(() => {\n if (!componentProps) return;\n\n return {\n highlight: componentProps.highlight\n ? { ...componentProps.highlight, theme: highlightTheme }\n : undefined,\n mermaid: componentProps.mermaid\n ? { ...componentProps.mermaid, theme: mermaidTheme }\n : undefined,\n };\n }, [highlightTheme, mermaidTheme]);\n\n const memoPre = useCallback(\n ({ node, ...props }: any) => (\n <CodeBlock\n animated={animated}\n enableMermaid={enableMermaid}\n fullFeatured={fullFeaturedCodeBlock}\n {...stableComponentProps}\n {...componentProps?.pre}\n {...props}\n />\n ),\n [animated, enableMermaid, fullFeaturedCodeBlock, stableComponentProps, componentProps?.pre],\n );\n\n const memoColorPreview = useCallback(({ node, ...props }: any) => <code {...props} />, []);\n\n const memoComponents = useMemo(\n () => ({\n a: memoA,\n br: memoBr,\n colorPreview: memoColorPreview,\n img: memoImg,\n kbd: memoKbd,\n p: memeP,\n pre: memoPre,\n section: memoSection,\n video: memoVideo,\n }),\n [memoA, memoBr, memoImg, memoVideo, memoPre, memoSection, memeP, memoColorPreview, memoKbd],\n );\n\n return useMemo(\n () => ({\n ...memoComponents,\n ...components,\n }),\n [memoComponents, components],\n );\n};\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,8BAA0C;CACrD,MAAM,EACJ,YACA,UACA,WACA,gBACA,eACA,uBACA,kBACE,oBAAoB;CAExB,MAAM,QAAQ,aACX,EAAE,MAAM,GAAG,YAAiB,oBAAC,MAAD;EAAiB;EAAW,GAAI;EAAO,GAAI,gBAAgB;EAAK,CAAA,EAC7F,CAAC,WAAW,gBAAgB,EAAE,CAC/B;CAED,MAAM,UAAU,aACb,EAAE,MAAM,GAAG,YAAiB,oBAAC,OAAD;EAAO,GAAI;EAAO,GAAI,gBAAgB;EAAO,CAAA,EAC1E,CAAC,gBAAgB,IAAI,CACtB;CAED,MAAM,YAAY,aACf,EAAE,MAAM,GAAG,YAAiB,oBAAC,OAAD;EAAO,GAAI;EAAO,GAAI,gBAAgB;EAAS,CAAA,EAC5E,CAAC,gBAAgB,MAAM,CACxB;CAED,MAAM,cAAc,aACjB,EAAE,MAAM,GAAG,YAAiB,oBAAC,SAAD;EAAwB;EAAe,GAAI;EAAS,CAAA,EACjF,CAAC,cAAc,CAChB;CAED,MAAM,UAAU,aACb,EAAE,eAAoB,oBAAC,QAAD;EAAQ,MAAM;EAAU,OAAO,EAAE,SAAS,eAAe;EAAI,CAAA,EACpF,EAAE,CACH;CAED,MAAM,SAAS,kBAAkB,oBAAC,MAAD,EAAM,CAAA,EAAE,EAAE,CAAC;CAE5C,MAAM,QAAQ,aAAa,EAAE,OAAO,UAAU,gBAAqB;AAEjE,MAAI,OAAO,aAAa,
|
|
1
|
+
{"version":3,"file":"useMarkdownComponents.mjs","names":[],"sources":["../../../src/hooks/useMarkdown/useMarkdownComponents.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useMemo } from 'react';\nimport type { Components } from 'react-markdown';\n\nimport Hotkey from '@/Hotkey';\nimport { CodeBlock } from '@/Markdown/components/CodeBlock';\nimport { useMarkdownContext } from '@/Markdown/components/MarkdownProvider';\nimport Image from '@/mdx/mdxComponents/Image';\nimport Link from '@/mdx/mdxComponents/Link';\nimport Section from '@/mdx/mdxComponents/Section';\nimport Video from '@/mdx/mdxComponents/Video';\n\nexport const useMarkdownComponents = (): Components => {\n const {\n components,\n animated,\n citations,\n componentProps,\n enableMermaid,\n fullFeaturedCodeBlock,\n showFootnotes,\n } = useMarkdownContext();\n\n const memoA = useCallback(\n ({ node, ...props }: any) => <Link citations={citations} {...props} {...componentProps?.a} />,\n [citations, componentProps?.a],\n );\n\n const memoImg = useCallback(\n ({ node, ...props }: any) => <Image {...props} {...componentProps?.img} />,\n [componentProps?.img],\n );\n\n const memoVideo = useCallback(\n ({ node, ...props }: any) => <Video {...props} {...componentProps?.video} />,\n [componentProps?.video],\n );\n\n const memoSection = useCallback(\n ({ node, ...props }: any) => <Section showFootnotes={showFootnotes} {...props} />,\n [showFootnotes],\n );\n\n const memoKbd = useCallback(\n ({ children }: any) => <Hotkey keys={children} style={{ display: 'inline-flex' }} />,\n [],\n );\n\n const memoBr = useCallback(() => <br />, []);\n\n const memeP = useCallback(({ style, children, className }: any) => {\n const skipWrapperTags = ['img', 'video'];\n if (typeof children === 'object' && skipWrapperTags.includes(children?.props?.node?.tagName)) {\n return children;\n }\n return (\n <p className={className} style={style}>\n {children}\n </p>\n );\n }, []);\n\n // Stable references for theme objects to prevent unnecessary re-renders\n const highlightTheme = useMemo(\n () => componentProps?.highlight?.theme,\n [JSON.stringify(componentProps?.highlight?.theme)],\n );\n\n const mermaidTheme = useMemo(\n () => componentProps?.mermaid?.theme,\n [JSON.stringify(componentProps?.mermaid?.theme)],\n );\n\n // Create stable component props reference\n const stableComponentProps = useMemo(() => {\n if (!componentProps) return;\n\n return {\n highlight: componentProps.highlight\n ? { ...componentProps.highlight, theme: highlightTheme }\n : undefined,\n mermaid: componentProps.mermaid\n ? { ...componentProps.mermaid, theme: mermaidTheme }\n : undefined,\n };\n }, [highlightTheme, mermaidTheme]);\n\n const memoPre = useCallback(\n ({ node, ...props }: any) => (\n <CodeBlock\n animated={animated}\n enableMermaid={enableMermaid}\n fullFeatured={fullFeaturedCodeBlock}\n {...stableComponentProps}\n {...componentProps?.pre}\n {...props}\n />\n ),\n [animated, enableMermaid, fullFeaturedCodeBlock, stableComponentProps, componentProps?.pre],\n );\n\n const memoColorPreview = useCallback(({ node, ...props }: any) => <code {...props} />, []);\n\n const memoComponents = useMemo(\n () => ({\n a: memoA,\n br: memoBr,\n colorPreview: memoColorPreview,\n img: memoImg,\n kbd: memoKbd,\n p: memeP,\n pre: memoPre,\n section: memoSection,\n video: memoVideo,\n }),\n [memoA, memoBr, memoImg, memoVideo, memoPre, memoSection, memeP, memoColorPreview, memoKbd],\n );\n\n return useMemo(\n () => ({\n ...memoComponents,\n ...components,\n }),\n [memoComponents, components],\n );\n};\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,8BAA0C;CACrD,MAAM,EACJ,YACA,UACA,WACA,gBACA,eACA,uBACA,kBACE,oBAAoB;CAExB,MAAM,QAAQ,aACX,EAAE,MAAM,GAAG,YAAiB,oBAAC,MAAD;EAAiB;EAAW,GAAI;EAAO,GAAI,gBAAgB;EAAK,CAAA,EAC7F,CAAC,WAAW,gBAAgB,EAAE,CAC/B;CAED,MAAM,UAAU,aACb,EAAE,MAAM,GAAG,YAAiB,oBAAC,OAAD;EAAO,GAAI;EAAO,GA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,cAAc;EACd,GAAI;EACJ,GAAI,gBAAgB;EACpB,GAAI;EACJ,CAAA,EAEJ;EAAC;EAAU;EAAe;EAAuB;EAAsB,gBAAgB;EAAI,CAC5F;CAED,MAAM,mBAAmB,aAAa,EAAE,MAAM,GAAG,YAAiB,oBAAC,QAAD,EAAM,GAAI,OAAS,CAAA,EAAE,EAAE,CAAC;CAE1F,MAAM,iBAAiB,eACd;EACL,GAAG;EACH,IAAI;EACJ,cAAc;EACd,KAAK;EACL,KAAK;EACL,GAAG;EACH,KAAK;EACL,SAAS;EACT,OAAO;EACR,GACD;EAAC;EAAO;EAAQ;EAAS;EAAW;EAAS;EAAa;EAAO;EAAkB;EAAQ,CAC5F;AAED,QAAO,eACE;EACL,GAAG;EACH,GAAG;EACJ,GACD,CAAC,gBAAgB,WAAW,CAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMarkdownContent.mjs","names":[],"sources":["../../../src/hooks/useMarkdown/useMarkdownContent.ts"],"sourcesContent":["'use client';\n\nimport { useMemo, useRef, useState } from 'react';\n\nimport { useMarkdownContext } from '@/Markdown/components/MarkdownProvider';\n\nimport { isLastFormulaRenderable } from './latex';\nimport { addToCache, contentCache, preprocessMarkdownContent } from './utils';\n\nexport const useMarkdownContent = (children: string): string | undefined => {\n const { animated, enableLatex = true, enableCustomFootnotes, citations } = useMarkdownContext();\n const [validContent, setValidContent] = useState<string>('');\n const prevProcessedContent = useRef<string>('');\n\n const citationsLength = citations?.length || 0;\n\n // Calculate cache key with fewer string concatenations and better performance\n const cacheKey = useMemo(\n () => `${children}|${enableLatex ? 1 : 0}|${enableCustomFootnotes ? 1 : 0}|${citationsLength}`,\n [children, enableLatex, enableCustomFootnotes, citationsLength],\n );\n\n // Process content and use cache to avoid repeated calculations\n return useMemo(() => {\n // Try to get from cache first for best performance\n if (contentCache.has(cacheKey)) {\n return contentCache.get(cacheKey);\n }\n\n // Process new content only if needed\n let processedContent = preprocessMarkdownContent(children, {\n citationsLength,\n enableCustomFootnotes,\n enableLatex,\n });\n\n // Special handling for LaTeX content when animated\n if (animated && enableLatex) {\n const isRenderable = isLastFormulaRenderable(processedContent);\n if (!isRenderable && validContent) {\n processedContent = validContent;\n }\n }\n\n // Only update state if content changed (prevents unnecessary re-renders)\n if (processedContent !== prevProcessedContent.current) {\n setValidContent(processedContent);\n prevProcessedContent.current = processedContent;\n }\n\n // Cache the processed result\n addToCache(cacheKey, processedContent);\n return processedContent;\n }, [\n cacheKey,\n children,\n enableLatex,\n enableCustomFootnotes,\n citationsLength,\n animated,\n validContent,\n ]);\n};\n"],"mappings":";;;;;;AASA,MAAa,sBAAsB,aAAyC;CAC1E,MAAM,EAAE,UAAU,cAAc,MAAM,uBAAuB,cAAc,oBAAoB;CAC/F,MAAM,CAAC,cAAc,mBAAmB,SAAiB,GAAG;CAC5D,MAAM,uBAAuB,OAAe,GAAG;CAE/C,MAAM,kBAAkB,WAAW,UAAU;CAG7C,MAAM,WAAW,cACT,GAAG,SAAS,GAAG,cAAc,IAAI,EAAE,GAAG,wBAAwB,IAAI,EAAE,GAAG,mBAC7E;EAAC;EAAU;EAAa;EAAuB;EAAgB,CAChE;AAGD,QAAO,cAAc;AAEnB,MAAI,aAAa,IAAI,SAAS,CAC5B,QAAO,aAAa,IAAI,SAAS;EAInC,IAAI,mBAAmB,0BAA0B,UAAU;GACzD;GACA;GACA;GACD,CAAC;AAGF,MAAI,YAAY;OAEV,CADiB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"useMarkdownContent.mjs","names":[],"sources":["../../../src/hooks/useMarkdown/useMarkdownContent.ts"],"sourcesContent":["'use client';\n\nimport { useMemo, useRef, useState } from 'react';\n\nimport { useMarkdownContext } from '@/Markdown/components/MarkdownProvider';\n\nimport { isLastFormulaRenderable } from './latex';\nimport { addToCache, contentCache, preprocessMarkdownContent } from './utils';\n\nexport const useMarkdownContent = (children: string): string | undefined => {\n const { animated, enableLatex = true, enableCustomFootnotes, citations } = useMarkdownContext();\n const [validContent, setValidContent] = useState<string>('');\n const prevProcessedContent = useRef<string>('');\n\n const citationsLength = citations?.length || 0;\n\n // Calculate cache key with fewer string concatenations and better performance\n const cacheKey = useMemo(\n () => `${children}|${enableLatex ? 1 : 0}|${enableCustomFootnotes ? 1 : 0}|${citationsLength}`,\n [children, enableLatex, enableCustomFootnotes, citationsLength],\n );\n\n // Process content and use cache to avoid repeated calculations\n return useMemo(() => {\n // Try to get from cache first for best performance\n if (contentCache.has(cacheKey)) {\n return contentCache.get(cacheKey);\n }\n\n // Process new content only if needed\n let processedContent = preprocessMarkdownContent(children, {\n citationsLength,\n enableCustomFootnotes,\n enableLatex,\n });\n\n // Special handling for LaTeX content when animated\n if (animated && enableLatex) {\n const isRenderable = isLastFormulaRenderable(processedContent);\n if (!isRenderable && validContent) {\n processedContent = validContent;\n }\n }\n\n // Only update state if content changed (prevents unnecessary re-renders)\n if (processedContent !== prevProcessedContent.current) {\n setValidContent(processedContent);\n prevProcessedContent.current = processedContent;\n }\n\n // Cache the processed result\n addToCache(cacheKey, processedContent);\n return processedContent;\n }, [\n cacheKey,\n children,\n enableLatex,\n enableCustomFootnotes,\n citationsLength,\n animated,\n validContent,\n ]);\n};\n"],"mappings":";;;;;;AASA,MAAa,sBAAsB,aAAyC;CAC1E,MAAM,EAAE,UAAU,cAAc,MAAM,uBAAuB,cAAc,oBAAoB;CAC/F,MAAM,CAAC,cAAc,mBAAmB,SAAiB,GAAG;CAC5D,MAAM,uBAAuB,OAAe,GAAG;CAE/C,MAAM,kBAAkB,WAAW,UAAU;CAG7C,MAAM,WAAW,cACT,GAAG,SAAS,GAAG,cAAc,IAAI,EAAE,GAAG,wBAAwB,IAAI,EAAE,GAAG,mBAC7E;EAAC;EAAU;EAAa;EAAuB;EAAgB,CAChE;AAGD,QAAO,cAAc;AAEnB,MAAI,aAAa,IAAI,SAAS,CAC5B,QAAO,aAAa,IAAI,SAAS;EAInC,IAAI,mBAAmB,0BAA0B,UAAU;GACzD;GACA;GACA;GACD,CAAC;AAGF,MAAI,YAAY;OAEV,CADiB,wBAAwB,iBAC5B,IAAI,aACnB,oBAAmB;;AAKvB,MAAI,qBAAqB,qBAAqB,SAAS;AACrD,mBAAgB,iBAAiB;AACjC,wBAAqB,UAAU;;AAIjC,aAAW,UAAU,iBAAiB;AACtC,SAAO;IACN;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMermaid.mjs","names":[],"sources":["../../src/hooks/useMermaid.ts"],"sourcesContent":["'use client';\n\nimport { useTheme } from 'antd-style';\nimport type { MermaidConfig } from 'mermaid';\nimport { useEffect, useMemo, useState } from 'react';\nimport { Md5 } from 'ts-md5';\n\n// 缓存已验证的图表内容\nexport const MD5_LENGTH_THRESHOLD = 10_000;\n\n// Application-level cache for rendered Mermaid SVG\n// Key: cacheKey string, Value: Promise<string>\nconst mermaidCache = new Map<string, Promise<string>>();\n\n// Maximum cache size to prevent memory leaks\nconst MAX_CACHE_SIZE = 500;\n\n// Clean up old cache entries when limit is reached\nconst cleanupCache = () => {\n if (mermaidCache.size > MAX_CACHE_SIZE) {\n // Remove oldest 20% of entries\n const entriesToRemove = Math.floor(MAX_CACHE_SIZE * 0.2);\n const keysToRemove = Array.from(mermaidCache.keys()).slice(0, entriesToRemove);\n for (const key of keysToRemove) {\n mermaidCache.delete(key);\n }\n }\n};\n\n// 懒加载 mermaid 实例\nlet mermaidPromise: Promise<typeof import('mermaid').default | null> | null = null;\n\nexport const loadMermaid = (): Promise<typeof import('mermaid').default | null> => {\n if (typeof window === 'undefined') return Promise.resolve(null);\n\n if (!mermaidPromise) {\n mermaidPromise = import('mermaid').then((mod) => mod.default);\n }\n\n return mermaidPromise;\n};\n\n// Helper to create mermaid config\nexport const createMermaidConfig = (\n theme: ReturnType<typeof useTheme>,\n customTheme?: MermaidConfig['theme'],\n // SECURITY: Keep 'strict' as the default. Using 'loose' causes Mermaid to render\n // node labels via innerHTML, enabling XSS when diagram content is user-controlled.\n // Only pass 'loose' if your use case explicitly requires HTML labels and you control\n // the diagram source entirely.\n securityLevel: MermaidConfig['securityLevel'] = 'strict',\n): MermaidConfig => ({\n fontFamily: theme.fontFamilyCode,\n gantt: {\n useWidth: 1920,\n },\n securityLevel,\n startOnLoad: false,\n theme: customTheme || (theme.isDarkMode ? 'dark' : 'neutral'),\n themeVariables: customTheme\n ? undefined\n : {\n errorBkgColor: theme.colorTextDescription,\n errorTextColor: theme.colorTextDescription,\n fontFamily: theme.fontFamily,\n lineColor: theme.colorTextSecondary,\n mainBkg: theme.colorBgContainer,\n noteBkgColor: theme.colorInfoBg,\n noteTextColor: theme.colorInfoText,\n pie1: theme.geekblue,\n pie2: theme.colorWarning,\n pie3: theme.colorSuccess,\n pie4: theme.colorError,\n primaryBorderColor: theme.colorBorder,\n primaryColor: theme.colorBgContainer,\n primaryTextColor: theme.colorText,\n secondaryBorderColor: theme.colorInfoBorder,\n secondaryColor: theme.colorInfoBg,\n secondaryTextColor: theme.colorInfoText,\n tertiaryBorderColor: theme.colorSuccessBorder,\n tertiaryColor: theme.colorSuccessBg,\n tertiaryTextColor: theme.colorSuccessText,\n textColor: theme.colorText,\n },\n});\n\n/**\n * 验证并处理 Mermaid 图表内容 - 优化版本(移除 SWR)\n */\nexport const useMermaid = (\n content: string,\n {\n id,\n theme: customTheme,\n securityLevel,\n }: {\n id: string;\n // SECURITY: Defaults to 'strict'. Set to 'loose' only when you fully control\n // the diagram source and intentionally need HTML rendering in node labels.\n securityLevel?: MermaidConfig['securityLevel'];\n theme?: MermaidConfig['theme'];\n },\n): string => {\n const theme = useTheme();\n const [data, setData] = useState<string>('');\n\n // 提取主题相关配置到 useMemo 中 - 只依赖实际使用的 theme 属性\n const mermaidConfig = useMemo(\n () => createMermaidConfig(theme, customTheme, securityLevel),\n [\n theme.fontFamilyCode,\n theme.isDarkMode,\n theme.colorTextDescription,\n theme.fontFamily,\n theme.colorTextSecondary,\n theme.colorBgContainer,\n theme.colorInfoBg,\n theme.colorInfoText,\n theme.geekblue,\n theme.colorWarning,\n theme.colorSuccess,\n theme.colorError,\n theme.colorBorder,\n theme.colorInfoBorder,\n theme.colorSuccessBorder,\n theme.colorSuccessBg,\n theme.colorSuccessText,\n theme.colorText,\n customTheme,\n securityLevel,\n ],\n );\n\n // 为长内容生成哈希键\n const cacheKey = useMemo((): string => {\n const hash = content.length < MD5_LENGTH_THRESHOLD ? content : Md5.hashStr(content);\n return [id, customTheme || (theme.isDarkMode ? 'd' : 'l'), hash].filter(Boolean).join('-');\n }, [content, id, theme.isDarkMode, customTheme]);\n\n useEffect(() => {\n // Check cache first\n const cachedPromise = mermaidCache.get(cacheKey);\n if (cachedPromise) {\n cachedPromise\n .then((svg) => {\n setData(svg);\n })\n .catch(() => {\n // Silently handle errors, fallback will be handled in the promise\n });\n return;\n }\n\n // Create new promise for rendering\n const renderPromise = (async (): Promise<string> => {\n try {\n const mermaidInstance = await loadMermaid();\n if (!mermaidInstance) return '';\n\n // 验证语法\n const isValid = await mermaidInstance.parse(content);\n\n if (isValid) {\n // 初始化并渲染\n mermaidInstance.initialize(mermaidConfig);\n const { svg } = await mermaidInstance.render(id, content);\n return svg;\n } else {\n throw new Error('Mermaid 语法无效');\n }\n } catch (error_) {\n console.error('Mermaid 解析错误:', error_);\n return '';\n }\n })();\n\n // Cache the promise\n mermaidCache.set(cacheKey, renderPromise);\n cleanupCache();\n\n // Handle promise result\n renderPromise\n .then((svg) => {\n // Only update if this is still the current cache key\n if (mermaidCache.get(cacheKey) === renderPromise) {\n setData(svg);\n }\n })\n .catch(() => {\n // Remove failed promise from cache\n if (mermaidCache.get(cacheKey) === renderPromise) {\n mermaidCache.delete(cacheKey);\n }\n });\n }, [cacheKey, content, id, mermaidConfig]);\n\n return data;\n};\n"],"mappings":";;;;AAYA,MAAM,+BAAe,IAAI,KAA8B;AAGvD,MAAM,iBAAiB;AAGvB,MAAM,qBAAqB;AACzB,KAAI,aAAa,OAAO,gB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N,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN;EACA;EACD,CACF;CAGD,MAAM,WAAW,cAAsB;EACrC,MAAM,OAAO,QAAQ,SAAA,MAAgC,UAAU,IAAI,QAAQ,QAAQ;AACnF,SAAO;GAAC;GAAI,gBAAgB,MAAM,aAAa,MAAM;GAAM;GAAK,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;IACzF;EAAC;EAAS;EAAI,MAAM;EAAY;EAAY,CAAC;AAEhD,iBAAgB;EAEd,MAAM,gBAAgB,aAAa,IAAI,SAAS;AAChD,MAAI,eAAe;AACjB,iBACG,MAAM,QAAQ;AACb,YAAQ,IAAI;KACZ,CACD,YAAY,GAEX;AACJ;;EAIF,MAAM,iBAAiB,YAA6B;AAClD,OAAI;IACF,MAAM,kBAAkB,MAAM,aAAa;AAC3C,QAAI,CAAC,gBAAiB,QAAO;AAK7B,
|
|
1
|
+
{"version":3,"file":"useMermaid.mjs","names":[],"sources":["../../src/hooks/useMermaid.ts"],"sourcesContent":["'use client';\n\nimport { useTheme } from 'antd-style';\nimport type { MermaidConfig } from 'mermaid';\nimport { useEffect, useMemo, useState } from 'react';\nimport { Md5 } from 'ts-md5';\n\n// 缓存已验证的图表内容\nexport const MD5_LENGTH_THRESHOLD = 10_000;\n\n// Application-level cache for rendered Mermaid SVG\n// Key: cacheKey string, Value: Promise<string>\nconst mermaidCache = new Map<string, Promise<string>>();\n\n// Maximum cache size to prevent memory leaks\nconst MAX_CACHE_SIZE = 500;\n\n// Clean up old cache entries when limit is reached\nconst cleanupCache = () => {\n if (mermaidCache.size > MAX_CACHE_SIZE) {\n // Remove oldest 20% of entries\n const entriesToRemove = Math.floor(MAX_CACHE_SIZE * 0.2);\n const keysToRemove = Array.from(mermaidCache.keys()).slice(0, entriesToRemove);\n for (const key of keysToRemove) {\n mermaidCache.delete(key);\n }\n }\n};\n\n// 懒加载 mermaid 实例\nlet mermaidPromise: Promise<typeof import('mermaid').default | null> | null = null;\n\nexport const loadMermaid = (): Promise<typeof import('mermaid').default | null> => {\n if (typeof window === 'undefined') return Promise.resolve(null);\n\n if (!mermaidPromise) {\n mermaidPromise = import('mermaid').then((mod) => mod.default);\n }\n\n return mermaidPromise;\n};\n\n// Helper to create mermaid config\nexport const createMermaidConfig = (\n theme: ReturnType<typeof useTheme>,\n customTheme?: MermaidConfig['theme'],\n // SECURITY: Keep 'strict' as the default. Using 'loose' causes Mermaid to render\n // node labels via innerHTML, enabling XSS when diagram content is user-controlled.\n // Only pass 'loose' if your use case explicitly requires HTML labels and you control\n // the diagram source entirely.\n securityLevel: MermaidConfig['securityLevel'] = 'strict',\n): MermaidConfig => ({\n fontFamily: theme.fontFamilyCode,\n gantt: {\n useWidth: 1920,\n },\n securityLevel,\n startOnLoad: false,\n theme: customTheme || (theme.isDarkMode ? 'dark' : 'neutral'),\n themeVariables: customTheme\n ? undefined\n : {\n errorBkgColor: theme.colorTextDescription,\n errorTextColor: theme.colorTextDescription,\n fontFamily: theme.fontFamily,\n lineColor: theme.colorTextSecondary,\n mainBkg: theme.colorBgContainer,\n noteBkgColor: theme.colorInfoBg,\n noteTextColor: theme.colorInfoText,\n pie1: theme.geekblue,\n pie2: theme.colorWarning,\n pie3: theme.colorSuccess,\n pie4: theme.colorError,\n primaryBorderColor: theme.colorBorder,\n primaryColor: theme.colorBgContainer,\n primaryTextColor: theme.colorText,\n secondaryBorderColor: theme.colorInfoBorder,\n secondaryColor: theme.colorInfoBg,\n secondaryTextColor: theme.colorInfoText,\n tertiaryBorderColor: theme.colorSuccessBorder,\n tertiaryColor: theme.colorSuccessBg,\n tertiaryTextColor: theme.colorSuccessText,\n textColor: theme.colorText,\n },\n});\n\n/**\n * 验证并处理 Mermaid 图表内容 - 优化版本(移除 SWR)\n */\nexport const useMermaid = (\n content: string,\n {\n id,\n theme: customTheme,\n securityLevel,\n }: {\n id: string;\n // SECURITY: Defaults to 'strict'. Set to 'loose' only when you fully control\n // the diagram source and intentionally need HTML rendering in node labels.\n securityLevel?: MermaidConfig['securityLevel'];\n theme?: MermaidConfig['theme'];\n },\n): string => {\n const theme = useTheme();\n const [data, setData] = useState<string>('');\n\n // 提取主题相关配置到 useMemo 中 - 只依赖实际使用的 theme 属性\n const mermaidConfig = useMemo(\n () => createMermaidConfig(theme, customTheme, securityLevel),\n [\n theme.fontFamilyCode,\n theme.isDarkMode,\n theme.colorTextDescription,\n theme.fontFamily,\n theme.colorTextSecondary,\n theme.colorBgContainer,\n theme.colorInfoBg,\n theme.colorInfoText,\n theme.geekblue,\n theme.colorWarning,\n theme.colorSuccess,\n theme.colorError,\n theme.colorBorder,\n theme.colorInfoBorder,\n theme.colorSuccessBorder,\n theme.colorSuccessBg,\n theme.colorSuccessText,\n theme.colorText,\n customTheme,\n securityLevel,\n ],\n );\n\n // 为长内容生成哈希键\n const cacheKey = useMemo((): string => {\n const hash = content.length < MD5_LENGTH_THRESHOLD ? content : Md5.hashStr(content);\n return [id, customTheme || (theme.isDarkMode ? 'd' : 'l'), hash].filter(Boolean).join('-');\n }, [content, id, theme.isDarkMode, customTheme]);\n\n useEffect(() => {\n // Check cache first\n const cachedPromise = mermaidCache.get(cacheKey);\n if (cachedPromise) {\n cachedPromise\n .then((svg) => {\n setData(svg);\n })\n .catch(() => {\n // Silently handle errors, fallback will be handled in the promise\n });\n return;\n }\n\n // Create new promise for rendering\n const renderPromise = (async (): Promise<string> => {\n try {\n const mermaidInstance = await loadMermaid();\n if (!mermaidInstance) return '';\n\n // 验证语法\n const isValid = await mermaidInstance.parse(content);\n\n if (isValid) {\n // 初始化并渲染\n mermaidInstance.initialize(mermaidConfig);\n const { svg } = await mermaidInstance.render(id, content);\n return svg;\n } else {\n throw new Error('Mermaid 语法无效');\n }\n } catch (error_) {\n console.error('Mermaid 解析错误:', error_);\n return '';\n }\n })();\n\n // Cache the promise\n mermaidCache.set(cacheKey, renderPromise);\n cleanupCache();\n\n // Handle promise result\n renderPromise\n .then((svg) => {\n // Only update if this is still the current cache key\n if (mermaidCache.get(cacheKey) === renderPromise) {\n setData(svg);\n }\n })\n .catch(() => {\n // Remove failed promise from cache\n if (mermaidCache.get(cacheKey) === renderPromise) {\n mermaidCache.delete(cacheKey);\n }\n });\n }, [cacheKey, content, id, mermaidConfig]);\n\n return data;\n};\n"],"mappings":";;;;AAYA,MAAM,+BAAe,IAAI,KAA8B;AAGvD,MAAM,iBAAiB;AAGvB,MAAM,qBAAqB;AACzB,KAAI,aAAa,OAAO,gBAAgB;EAEtC,MAAM,kBAAkB,KAAK,MAAM,iBAAiB,GAAI;EACxD,MAAM,eAAe,MAAM,KAAK,aAAa,MAAM,CAAC,CAAC,MAAM,GAAG,gBAAgB;AAC9E,OAAK,MAAM,OAAO,aAChB,cAAa,OAAO,IAAI;;;AAM9B,IAAI,iBAA0E;AAE9E,MAAa,oBAAsE;AACjF,KAAI,OAAO,WAAW,YAAa,QAAO,QAAQ,QAAQ,KAAK;AAE/D,KAAI,CAAC,eACH,kBAAiB,OAAO,WAAW,MAAM,QAAQ,IAAI,QAAQ;AAG/D,QAAO;;AAIT,MAAa,uBACX,OACA,aAKA,gBAAgD,cAC7B;CACnB,YAAY,MAAM;CAClB,OAAO,EACL,UAAU,MACX;CACD;CACA,aAAa;CACb,OAAO,gBAAgB,MAAM,aAAa,SAAS;CACnD,gBAAgB,cACZ,KAAA,IACA;EACE,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACtB,YAAY,MAAM;EAClB,WAAW,MAAM;EACjB,SAAS,MAAM;EACf,cAAc,MAAM;EACpB,eAAe,MAAM;EACrB,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,oBAAoB,MAAM;EAC1B,cAAc,MAAM;EACpB,kBAAkB,MAAM;EACxB,sBAAsB,MAAM;EAC5B,gBAAgB,MAAM;EACtB,oBAAoB,MAAM;EAC1B,qBAAqB,MAAM;EAC3B,eAAe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,gBACG,MAAM,QAAQ;AAEb,OAAI,aAAa,IAAI,SAAS,KAAK,cACjC,SAAQ,IAAI;IAEd,CACD,YAAY;AAEX,OAAI,aAAa,IAAI,SAAS,KAAK,cACjC,cAAa,OAAO,SAAS;IAE/B;IACH;EAAC;EAAU;EAAS;EAAI;EAAc,CAAC;AAE1C,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNativeButton.mjs","names":[],"sources":["../../src/hooks/useNativeButton.ts"],"sourcesContent":["import { isValidElement, type ReactElement, type ReactNode, useMemo } from 'react';\n\nexport interface UseNativeButtonOptions {\n /**\n * The children element that will be used as the trigger\n */\n children: ReactNode;\n /**\n * User-provided nativeButton prop\n */\n nativeButton?: boolean;\n /**\n * Additional nativeButton from trigger props (for DropdownMenu)\n */\n triggerNativeButton?: boolean;\n}\n\nexport interface UseNativeButtonResult {\n /**\n * Whether the trigger element is a native button\n */\n isNativeButtonTriggerElement: boolean;\n /**\n * The resolved nativeButton value to pass to Base UI components\n */\n resolvedNativeButton: boolean | undefined;\n}\n\n/**\n * Map of component displayNames to their nativeButton values.\n * Components that render native <button> elements should be true,\n * components that render non-button elements should be false.\n */\nconst NATIVE_BUTTON_MAP: Record<string, boolean> = {\n A: false,\n ActionIcon: false,\n ActionIconGroup: false,\n Alert: false,\n Avatar: false,\n AvatarGroup: false,\n Block: false,\n BottomGradientButton: true,\n Burger: false,\n Button: true,\n Center: false,\n Checkbox: false,\n CheckboxGroup: false,\n Collapse: false,\n ColorSwatches: false,\n CopyButton: false,\n DownloadButton: false,\n EditableText: false,\n Empty: false,\n FileTypeIcon: false,\n Flexbox: false,\n FluentEmoji: false,\n GradientButton: true,\n Highlighter: false,\n Hotkey: false,\n Icon: false,\n Image: false,\n Img: false,\n Input: false,\n InputNumber: false,\n InputPassword: false,\n List: false,\n ListItem: false,\n Select: false,\n Switch: false,\n Markdown: false,\n MaterialFileTypeIcon: false,\n Segmented: false,\n Skeleton: false,\n SkeletonAvatar: false,\n SkeletonBlock: false,\n SkeletonButton: false,\n SkeletonParagraph: false,\n SkeletonTags: false,\n SkeletonTitle: false,\n Snippet: false,\n Tag: false,\n Text: false,\n TextArea: false,\n ThemeSwitch: false,\n Video: false,\n};\n\n/**\n * Get the displayName of a React component from an element.\n * Handles function components, forwardRef, memo, etc.\n */\nfunction getComponentDisplayName(element: ReactElement): string | undefined {\n const type = element.type;\n\n if (typeof type === 'string') return undefined;\n\n if (typeof type === 'function') {\n return (type as any).displayName || type.name;\n }\n\n if (typeof type === 'object' && type !== null) {\n // Handle forwardRef, memo, etc.\n const displayName =\n (type as any).displayName ||\n (type as any).render?.displayName ||\n (type as any).render?.name ||\n (type as any).type?.displayName ||\n (type as any).type?.name;\n return displayName;\n }\n\n return undefined;\n}\n\n/**\n * Hook to resolve nativeButton prop for Base UI trigger components.\n *\n * When using `render`, Base UI expects the rendered element to be a native <button> by default.\n * If we can infer it's not, we opt out to avoid warnings (users can still override via `nativeButton`).\n */\nexport function useNativeButton({\n children,\n nativeButton,\n triggerNativeButton,\n}: UseNativeButtonOptions): UseNativeButtonResult {\n const isNativeButtonTriggerElement = useMemo(() => {\n if (!isValidElement(children)) return false;\n return typeof children.type === 'string' && children.type === 'button';\n }, [children]);\n\n const resolvedNativeButton = useMemo(() => {\n // User-provided nativeButton takes highest priority\n if (nativeButton !== undefined) return nativeButton;\n // Trigger props nativeButton (for DropdownMenu) takes second priority\n if (triggerNativeButton !== undefined) return triggerNativeButton;\n // If it's a native button element, return true\n if (isNativeButtonTriggerElement) return true;\n // If children is not a valid element, let Base UI decide\n if (!isValidElement(children)) return undefined;\n // If it's a string type but not a button (e.g., 'div'), return false\n if (typeof children.type === 'string') return false;\n\n // Check if it's a known component from the library\n const displayName = getComponentDisplayName(children);\n if (displayName && displayName in NATIVE_BUTTON_MAP) {\n return NATIVE_BUTTON_MAP[displayName];\n }\n\n // For unknown React components, default to false to avoid warnings\n // since most custom components don't render native buttons\n return false;\n }, [children, isNativeButtonTriggerElement, nativeButton, triggerNativeButton]);\n\n return {\n isNativeButtonTriggerElement,\n resolvedNativeButton,\n };\n}\n"],"mappings":";;;;;;;AAiCA,MAAM,oBAA6C;CACjD,GAAG;CACH,YAAY;CACZ,iBAAiB;CACjB,OAAO;CACP,QAAQ;CACR,aAAa;CACb,OAAO;CACP,sBAAsB;CACtB,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,eAAe;CACf,UAAU;CACV,eAAe;CACf,YAAY;CACZ,gBAAgB;CAChB,cAAc;CACd,OAAO;CACP,cAAc;CACd,SAAS;CACT,aAAa;CACb,gBAAgB;CAChB,aAAa;CACb,QAAQ;CACR,MAAM;CACN,OAAO;CACP,KAAK;CACL,OAAO;CACP,aAAa;CACb,eAAe;CACf,MAAM;CACN,UAAU;CACV,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,sBAAsB;CACtB,WAAW;CACX,UAAU;CACV,gBAAgB;CAChB,eAAe;CACf,gBAAgB;CAChB,mBAAmB;CACnB,cAAc;CACd,eAAe;CACf,SAAS;CACT,KAAK;CACL,MAAM;CACN,UAAU;CACV,aAAa;CACb,OAAO;CACR;;;;;AAMD,SAAS,wBAAwB,SAA2C;CAC1E,MAAM,OAAO,QAAQ;AAErB,KAAI,OAAO,SAAS,SAAU,QAAO,KAAA;AAErC,KAAI,OAAO,SAAS,WAClB,QAAQ,KAAa,eAAe,KAAK;AAG3C,KAAI,OAAO,SAAS,YAAY,SAAS,KAQvC,QALG,KAAa,eACb,KAAa,QAAQ,eACrB,KAAa,QAAQ,QACrB,KAAa,MAAM,eACnB,KAAa,MAAM;;;;;;;;AAa1B,SAAgB,gBAAgB,EAC9B,UACA,cACA,uBACgD;CAChD,MAAM,+BAA+B,cAAc;AACjD,MAAI,CAAC,eAAe,SAAS,CAAE,QAAO;AACtC,SAAO,OAAO,SAAS,SAAS,YAAY,SAAS,SAAS;IAC7D,CAAC,SAAS,CAAC;AAyBd,QAAO;EACL;EACA,sBAzB2B,cAAc;AAEzC,OAAI,iBAAiB,KAAA,EAAW,QAAO;AAEvC,OAAI,wBAAwB,KAAA,EAAW,QAAO;AAE9C,OAAI,6BAA8B,QAAO;AAEzC,OAAI,CAAC,eAAe,SAAS,CAAE,QAAO,KAAA;AAEtC,OAAI,OAAO,SAAS,SAAS,SAAU,QAAO;GAG9C,MAAM,cAAc,wBAAwB,SAAS;AACrD,OAAI,eAAe,eAAe,kBAChC,QAAO,kBAAkB;AAK3B,UAAO;KACN;GAAC;GAAU;GAA8B;GAAc;GAAoB,
|
|
1
|
+
{"version":3,"file":"useNativeButton.mjs","names":[],"sources":["../../src/hooks/useNativeButton.ts"],"sourcesContent":["import { isValidElement, type ReactElement, type ReactNode, useMemo } from 'react';\n\nexport interface UseNativeButtonOptions {\n /**\n * The children element that will be used as the trigger\n */\n children: ReactNode;\n /**\n * User-provided nativeButton prop\n */\n nativeButton?: boolean;\n /**\n * Additional nativeButton from trigger props (for DropdownMenu)\n */\n triggerNativeButton?: boolean;\n}\n\nexport interface UseNativeButtonResult {\n /**\n * Whether the trigger element is a native button\n */\n isNativeButtonTriggerElement: boolean;\n /**\n * The resolved nativeButton value to pass to Base UI components\n */\n resolvedNativeButton: boolean | undefined;\n}\n\n/**\n * Map of component displayNames to their nativeButton values.\n * Components that render native <button> elements should be true,\n * components that render non-button elements should be false.\n */\nconst NATIVE_BUTTON_MAP: Record<string, boolean> = {\n A: false,\n ActionIcon: false,\n ActionIconGroup: false,\n Alert: false,\n Avatar: false,\n AvatarGroup: false,\n Block: false,\n BottomGradientButton: true,\n Burger: false,\n Button: true,\n Center: false,\n Checkbox: false,\n CheckboxGroup: false,\n Collapse: false,\n ColorSwatches: false,\n CopyButton: false,\n DownloadButton: false,\n EditableText: false,\n Empty: false,\n FileTypeIcon: false,\n Flexbox: false,\n FluentEmoji: false,\n GradientButton: true,\n Highlighter: false,\n Hotkey: false,\n Icon: false,\n Image: false,\n Img: false,\n Input: false,\n InputNumber: false,\n InputPassword: false,\n List: false,\n ListItem: false,\n Select: false,\n Switch: false,\n Markdown: false,\n MaterialFileTypeIcon: false,\n Segmented: false,\n Skeleton: false,\n SkeletonAvatar: false,\n SkeletonBlock: false,\n SkeletonButton: false,\n SkeletonParagraph: false,\n SkeletonTags: false,\n SkeletonTitle: false,\n Snippet: false,\n Tag: false,\n Text: false,\n TextArea: false,\n ThemeSwitch: false,\n Video: false,\n};\n\n/**\n * Get the displayName of a React component from an element.\n * Handles function components, forwardRef, memo, etc.\n */\nfunction getComponentDisplayName(element: ReactElement): string | undefined {\n const type = element.type;\n\n if (typeof type === 'string') return undefined;\n\n if (typeof type === 'function') {\n return (type as any).displayName || type.name;\n }\n\n if (typeof type === 'object' && type !== null) {\n // Handle forwardRef, memo, etc.\n const displayName =\n (type as any).displayName ||\n (type as any).render?.displayName ||\n (type as any).render?.name ||\n (type as any).type?.displayName ||\n (type as any).type?.name;\n return displayName;\n }\n\n return undefined;\n}\n\n/**\n * Hook to resolve nativeButton prop for Base UI trigger components.\n *\n * When using `render`, Base UI expects the rendered element to be a native <button> by default.\n * If we can infer it's not, we opt out to avoid warnings (users can still override via `nativeButton`).\n */\nexport function useNativeButton({\n children,\n nativeButton,\n triggerNativeButton,\n}: UseNativeButtonOptions): UseNativeButtonResult {\n const isNativeButtonTriggerElement = useMemo(() => {\n if (!isValidElement(children)) return false;\n return typeof children.type === 'string' && children.type === 'button';\n }, [children]);\n\n const resolvedNativeButton = useMemo(() => {\n // User-provided nativeButton takes highest priority\n if (nativeButton !== undefined) return nativeButton;\n // Trigger props nativeButton (for DropdownMenu) takes second priority\n if (triggerNativeButton !== undefined) return triggerNativeButton;\n // If it's a native button element, return true\n if (isNativeButtonTriggerElement) return true;\n // If children is not a valid element, let Base UI decide\n if (!isValidElement(children)) return undefined;\n // If it's a string type but not a button (e.g., 'div'), return false\n if (typeof children.type === 'string') return false;\n\n // Check if it's a known component from the library\n const displayName = getComponentDisplayName(children);\n if (displayName && displayName in NATIVE_BUTTON_MAP) {\n return NATIVE_BUTTON_MAP[displayName];\n }\n\n // For unknown React components, default to false to avoid warnings\n // since most custom components don't render native buttons\n return false;\n }, [children, isNativeButtonTriggerElement, nativeButton, triggerNativeButton]);\n\n return {\n isNativeButtonTriggerElement,\n resolvedNativeButton,\n };\n}\n"],"mappings":";;;;;;;AAiCA,MAAM,oBAA6C;CACjD,GAAG;CACH,YAAY;CACZ,iBAAiB;CACjB,OAAO;CACP,QAAQ;CACR,aAAa;CACb,OAAO;CACP,sBAAsB;CACtB,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,eAAe;CACf,UAAU;CACV,eAAe;CACf,YAAY;CACZ,gBAAgB;CAChB,cAAc;CACd,OAAO;CACP,cAAc;CACd,SAAS;CACT,aAAa;CACb,gBAAgB;CAChB,aAAa;CACb,QAAQ;CACR,MAAM;CACN,OAAO;CACP,KAAK;CACL,OAAO;CACP,aAAa;CACb,eAAe;CACf,MAAM;CACN,UAAU;CACV,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,sBAAsB;CACtB,WAAW;CACX,UAAU;CACV,gBAAgB;CAChB,eAAe;CACf,gBAAgB;CAChB,mBAAmB;CACnB,cAAc;CACd,eAAe;CACf,SAAS;CACT,KAAK;CACL,MAAM;CACN,UAAU;CACV,aAAa;CACb,OAAO;CACR;;;;;AAMD,SAAS,wBAAwB,SAA2C;CAC1E,MAAM,OAAO,QAAQ;AAErB,KAAI,OAAO,SAAS,SAAU,QAAO,KAAA;AAErC,KAAI,OAAO,SAAS,WAClB,QAAQ,KAAa,eAAe,KAAK;AAG3C,KAAI,OAAO,SAAS,YAAY,SAAS,KAQvC,QALG,KAAa,eACb,KAAa,QAAQ,eACrB,KAAa,QAAQ,QACrB,KAAa,MAAM,eACnB,KAAa,MAAM;;;;;;;;AAa1B,SAAgB,gBAAgB,EAC9B,UACA,cACA,uBACgD;CAChD,MAAM,+BAA+B,cAAc;AACjD,MAAI,CAAC,eAAe,SAAS,CAAE,QAAO;AACtC,SAAO,OAAO,SAAS,SAAS,YAAY,SAAS,SAAS;IAC7D,CAAC,SAAS,CAAC;AAyBd,QAAO;EACL;EACA,sBAzB2B,cAAc;AAEzC,OAAI,iBAAiB,KAAA,EAAW,QAAO;AAEvC,OAAI,wBAAwB,KAAA,EAAW,QAAO;AAE9C,OAAI,6BAA8B,QAAO;AAEzC,OAAI,CAAC,eAAe,SAAS,CAAE,QAAO,KAAA;AAEtC,OAAI,OAAO,SAAS,SAAS,SAAU,QAAO;GAG9C,MAAM,cAAc,wBAAwB,SAAS;AACrD,OAAI,eAAe,eAAe,kBAChC,QAAO,kBAAkB;AAK3B,UAAO;KACN;GAAC;GAAU;GAA8B;GAAc;GAAoB,CAIxD;EACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStreamHighlight.mjs","names":["lobeTheme"],"sources":["../../src/hooks/useStreamHighlight.ts"],"sourcesContent":["'use client';\n\nimport { type CSSProperties, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { type BuiltinTheme, type ThemedToken } from 'shiki';\nimport { ShikiStreamTokenizer } from 'shiki-stream';\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;AACrE,KAAI,CAAC,OAAO,OAAQ,QAAO,CAAC,EAAE,CAAC;CAE/B,MAAM,QAAyB,EAAE;CACjC,IAAI,cAA6B,EAAE;AAEnC,MAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,UAAU,MAAM,WAAW;AAEjC,MAAI,YAAY,MAAM;AACpB,SAAM,KAAK,YAAY;AACvB,iBAAc,EAAE;AAChB;;AAIF,MADqB,QAAQ,QAAQ,KAAK,KACrB,GAEnB,aAAY,KAAK,MAAM;OAClB;GAEL,MAAM,WAAW,QAAQ,MAAM,KAAK;AACpC,QAAK,MAAM,CAAC,GAAG,YAAY,SAAS,SAAS,EAAE;AAC7C,QAAI,QAEF,aAAY,KAAK,MAAM,KAAK,YAAY,UAAU,QAAQ;KAAE,GAAG;KAAO,SAAS;KAAS,CAAC;AAE3F,QAAI,IAAI,SAAS,SAAS,GAAG;AAC3B,WAAM,KAAK,YAAY;AACvB,mBAAc,EAAE;;;;;AAOxB,KAAI,YAAY,SAAS,KAAK,MAAM,WAAW,EAC7C,OAAM,KAAK,YAAY;AAGzB,QAAO,MAAM,SAAS,IAAI,QAAQ,CAAC,EAAE,CAAC;;AAGxC,MAAM,kBAAkB,IAAa,OAA2C;AAC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AAW,QAAQ;CACzB,MAAM,QAAQ,YAAY,aAAa,aAAa;CAGpD,MAAM,kBAAkB,cAAc,uBAAuB,KAAK,EAAE,CAAC,KAAK,CAAC;AAI3E,QAAO,wBAAwB,UAAU;EACvC,cAAc,EACZ,cAAcA,oBACf;EACD,SAAS;EACT,UAAU;EACV,OARqB,gBAAgB;EAStC,CAAC"}
|
|
1
|
+
{"version":3,"file":"useStreamHighlight.mjs","names":["lobeTheme"],"sources":["../../src/hooks/useStreamHighlight.ts"],"sourcesContent":["'use client';\n\nimport { type CSSProperties, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { type BuiltinTheme, type ThemedToken } from 'shiki';\nimport { ShikiStreamTokenizer } from 'shiki-stream';\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;AACrE,KAAI,CAAC,OAAO,OAAQ,QAAO,CAAC,EAAE,CAAC;CAE/B,MAAM,QAAyB,EAAE;CACjC,IAAI,cAA6B,EAAE;AAEnC,MAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,UAAU,MAAM,WAAW;AAEjC,MAAI,YAAY,MAAM;AACpB,SAAM,KAAK,YAAY;AACvB,iBAAc,EAAE;AAChB;;AAIF,MADqB,QAAQ,QAAQ,KACrB,KAAK,GAEnB,aAAY,KAAK,MAAM;OAClB;GAEL,MAAM,WAAW,QAAQ,MAAM,KAAK;AACpC,QAAK,MAAM,CAAC,GAAG,YAAY,SAAS,SAAS,EAAE;AAC7C,QAAI,QAEF,aAAY,KAAK,MAAM,KAAK,YAAY,UAAU,QAAQ;KAAE,GAAG;KAAO,SAAS;KAAS,CAAC;AAE3F,QAAI,IAAI,SAAS,SAAS,GAAG;AAC3B,WAAM,KAAK,YAAY;AACvB,mBAAc,EAAE;;;;;AAOxB,KAAI,YAAY,SAAS,KAAK,MAAM,WAAW,EAC7C,OAAM,KAAK,YAAY;AAGzB,QAAO,MAAM,SAAS,IAAI,QAAQ,CAAC,EAAE,CAAC;;AAGxC,MAAM,kBAAkB,IAAa,OAA2C;AAC9E,KAAI,CAAC,MAAM,CAAC,GAAI,QAAO,KAAA;AACvB,QAAO;EACL,iBAAiB;EACjB,OAAO;EACR;;AAGH,MAAM,2BACJ,MACA,YACyC;CACzC,MAAM,EAAE,cAAc,SAAS,UAAU,UAAU;CACnD,MAAM,CAAC,QAAQ,aAAa,UAAoC;CAChE,MAAM,eAAe,OAAoC,KA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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStreamMermaid.mjs","names":[],"sources":["../../src/hooks/useStreamMermaid.ts"],"sourcesContent":["'use client';\n\nimport { useTheme } from 'antd-style';\nimport type { MermaidConfig } from 'mermaid';\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { createMermaidConfig, loadMermaid } from './useMermaid';\n\n/**\n * 流式 Mermaid 渲染 - 支持内容逐步更新\n */\nexport const useStreamMermaid = (\n content: string,\n {\n enabled = true,\n id,\n theme: customTheme,\n }: {\n enabled?: boolean;\n id: string;\n theme?: MermaidConfig['theme'];\n },\n): string => {\n const theme = useTheme();\n const [data, setData] = useState<string>('');\n const previousContentRef = useRef<string>('');\n const latestContentRef = useRef(content);\n const renderTimeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n // 提取主题相关配置到 useMemo 中\n const mermaidConfig = useMemo(\n () => createMermaidConfig(theme, customTheme),\n [\n theme.fontFamilyCode,\n theme.isDarkMode,\n theme.colorTextDescription,\n theme.fontFamily,\n theme.colorTextSecondary,\n theme.colorBgContainer,\n theme.colorInfoBg,\n theme.colorInfoText,\n theme.geekblue,\n theme.colorWarning,\n theme.colorSuccess,\n theme.colorError,\n theme.colorBorder,\n theme.colorInfoBorder,\n theme.colorSuccessBorder,\n theme.colorSuccessBg,\n theme.colorSuccessText,\n theme.colorText,\n customTheme,\n ],\n );\n\n // Update latest content ref\n useEffect(() => {\n latestContentRef.current = content;\n }, [content]);\n\n // Debounced rendering for streaming content\n useEffect(() => {\n if (!enabled) {\n setData('');\n previousContentRef.current = '';\n const timeoutId = renderTimeoutRef.current;\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n return;\n }\n\n const currentContent = latestContentRef.current;\n\n // Skip if content hasn't changed\n if (currentContent === previousContentRef.current && data) {\n return;\n }\n\n // Clear previous timeout\n const timeoutId = renderTimeoutRef.current;\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n\n // Debounce rendering for streaming content (wait 300ms after last change)\n renderTimeoutRef.current = setTimeout(async () => {\n const contentToRender = latestContentRef.current;\n\n // Skip if content changed during debounce\n if (contentToRender !== currentContent) {\n return;\n }\n\n try {\n const mermaidInstance = await loadMermaid();\n if (!mermaidInstance) return;\n\n // 验证语法\n const isValid = await mermaidInstance.parse(contentToRender);\n\n if (isValid) {\n // 初始化并渲染\n mermaidInstance.initialize(mermaidConfig);\n const { svg } = await mermaidInstance.render(id, contentToRender);\n\n // Only update if content hasn't changed during rendering\n if (latestContentRef.current === contentToRender) {\n setData(svg);\n previousContentRef.current = contentToRender;\n }\n }\n } catch (error_) {\n // Silently handle errors during streaming\n // Only log if this is the final content\n if (contentToRender === latestContentRef.current) {\n console.error('Mermaid 解析错误:', error_);\n }\n }\n }, 300);\n\n return () => {\n const timeoutId = renderTimeoutRef.current;\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n };\n }, [enabled, content, id, mermaidConfig, data]);\n\n return data;\n};\n"],"mappings":";;;;;;;;AAWA,MAAa,oBACX,SACA,EACE,UAAU,MACV,IACA,OAAO,kBAME;CACX,MAAM,QAAQ,UAAU;CACxB,MAAM,CAAC,MAAM,WAAW,SAAiB,GAAG;CAC5C,MAAM,qBAAqB,OAAe,GAAG;CAC7C,MAAM,mBAAmB,OAAO,QAAQ;CACxC,MAAM,mBAAmB,OAAkD,KAAA,EAAU;CAGrF,MAAM,gBAAgB,cACd,oBAAoB,OAAO,YAAY,EAC7C;EACE,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN;EACD,CACF;AAGD,iBAAgB;AACd,mBAAiB,UAAU;IAC1B,CAAC,QAAQ,CAAC;AAGb,iBAAgB;AACd,MAAI,CAAC,SAAS;AACZ,WAAQ,GAAG;AACX,sBAAmB,UAAU;GAC7B,MAAM,YAAY,iBAAiB;AACnC,OAAI,UACF,cAAa,UAAU;AAEzB;;EAGF,MAAM,iBAAiB,iBAAiB;AAGxC,MAAI,mBAAmB,mBAAmB,WAAW,KACnD;EAIF,MAAM,YAAY,iBAAiB;AACnC,MAAI,UACF,cAAa,UAAU;AAIzB,mBAAiB,UAAU,WAAW,YAAY;GAChD,MAAM,kBAAkB,iBAAiB;AAGzC,OAAI,oBAAoB,eACtB;AAGF,OAAI;IACF,MAAM,kBAAkB,MAAM,aAAa;AAC3C,QAAI,CAAC,gBAAiB;AAKtB,
|
|
1
|
+
{"version":3,"file":"useStreamMermaid.mjs","names":[],"sources":["../../src/hooks/useStreamMermaid.ts"],"sourcesContent":["'use client';\n\nimport { useTheme } from 'antd-style';\nimport type { MermaidConfig } from 'mermaid';\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { createMermaidConfig, loadMermaid } from './useMermaid';\n\n/**\n * 流式 Mermaid 渲染 - 支持内容逐步更新\n */\nexport const useStreamMermaid = (\n content: string,\n {\n enabled = true,\n id,\n theme: customTheme,\n }: {\n enabled?: boolean;\n id: string;\n theme?: MermaidConfig['theme'];\n },\n): string => {\n const theme = useTheme();\n const [data, setData] = useState<string>('');\n const previousContentRef = useRef<string>('');\n const latestContentRef = useRef(content);\n const renderTimeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n // 提取主题相关配置到 useMemo 中\n const mermaidConfig = useMemo(\n () => createMermaidConfig(theme, customTheme),\n [\n theme.fontFamilyCode,\n theme.isDarkMode,\n theme.colorTextDescription,\n theme.fontFamily,\n theme.colorTextSecondary,\n theme.colorBgContainer,\n theme.colorInfoBg,\n theme.colorInfoText,\n theme.geekblue,\n theme.colorWarning,\n theme.colorSuccess,\n theme.colorError,\n theme.colorBorder,\n theme.colorInfoBorder,\n theme.colorSuccessBorder,\n theme.colorSuccessBg,\n theme.colorSuccessText,\n theme.colorText,\n customTheme,\n ],\n );\n\n // Update latest content ref\n useEffect(() => {\n latestContentRef.current = content;\n }, [content]);\n\n // Debounced rendering for streaming content\n useEffect(() => {\n if (!enabled) {\n setData('');\n previousContentRef.current = '';\n const timeoutId = renderTimeoutRef.current;\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n return;\n }\n\n const currentContent = latestContentRef.current;\n\n // Skip if content hasn't changed\n if (currentContent === previousContentRef.current && data) {\n return;\n }\n\n // Clear previous timeout\n const timeoutId = renderTimeoutRef.current;\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n\n // Debounce rendering for streaming content (wait 300ms after last change)\n renderTimeoutRef.current = setTimeout(async () => {\n const contentToRender = latestContentRef.current;\n\n // Skip if content changed during debounce\n if (contentToRender !== currentContent) {\n return;\n }\n\n try {\n const mermaidInstance = await loadMermaid();\n if (!mermaidInstance) return;\n\n // 验证语法\n const isValid = await mermaidInstance.parse(contentToRender);\n\n if (isValid) {\n // 初始化并渲染\n mermaidInstance.initialize(mermaidConfig);\n const { svg } = await mermaidInstance.render(id, contentToRender);\n\n // Only update if content hasn't changed during rendering\n if (latestContentRef.current === contentToRender) {\n setData(svg);\n previousContentRef.current = contentToRender;\n }\n }\n } catch (error_) {\n // Silently handle errors during streaming\n // Only log if this is the final content\n if (contentToRender === latestContentRef.current) {\n console.error('Mermaid 解析错误:', error_);\n }\n }\n }, 300);\n\n return () => {\n const timeoutId = renderTimeoutRef.current;\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n };\n }, [enabled, content, id, mermaidConfig, data]);\n\n return data;\n};\n"],"mappings":";;;;;;;;AAWA,MAAa,oBACX,SACA,EACE,UAAU,MACV,IACA,OAAO,kBAME;CACX,MAAM,QAAQ,UAAU;CACxB,MAAM,CAAC,MAAM,WAAW,SAAiB,GAAG;CAC5C,MAAM,qBAAqB,OAAe,GAAG;CAC7C,MAAM,mBAAmB,OAAO,QAAQ;CACxC,MAAM,mBAAmB,OAAkD,KAAA,EAAU;CAGrF,MAAM,gBAAgB,cACd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":["../../src/i18n/useTranslation.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport { useI18n } from './context';\nimport type { TranslationKey, TranslationResources } from './types';\n\nexport const useTranslation = (fallbackResources?: TranslationResources) => {\n const { t, locale } = useI18n();\n\n const translate = useMemo((): ((key: TranslationKey) => string) => {\n if (!fallbackResources) return t;\n\n return (key: TranslationKey): string => {\n const value = t(key);\n const fallback = fallbackResources[key];\n return value === key && fallback ? fallback : value;\n };\n }, [t, fallbackResources]);\n\n return { locale, t: translate };\n};\n"],"mappings":";;;AAKA,MAAa,kBAAkB,sBAA6C;CAC1E,MAAM,EAAE,GAAG,WAAW,SAAS;AAY/B,QAAO;EAAE;EAAQ,GAVC,cAAiD;AACjE,OAAI,CAAC,kBAAmB,QAAO;AAE/B,WAAQ,QAAgC;IACtC,MAAM,QAAQ,EAAE,IAAI;IACpB,MAAM,WAAW,kBAAkB;AACnC,WAAO,UAAU,OAAO,WAAW,WAAW;;KAE/C,CAAC,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"useTranslation.mjs","names":[],"sources":["../../src/i18n/useTranslation.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport { useI18n } from './context';\nimport type { TranslationKey, TranslationResources } from './types';\n\nexport const useTranslation = (fallbackResources?: TranslationResources) => {\n const { t, locale } = useI18n();\n\n const translate = useMemo((): ((key: TranslationKey) => string) => {\n if (!fallbackResources) return t;\n\n return (key: TranslationKey): string => {\n const value = t(key);\n const fallback = fallbackResources[key];\n return value === key && fallback ? fallback : value;\n };\n }, [t, fallbackResources]);\n\n return { locale, t: translate };\n};\n"],"mappings":";;;AAKA,MAAa,kBAAkB,sBAA6C;CAC1E,MAAM,EAAE,GAAG,WAAW,SAAS;AAY/B,QAAO;EAAE;EAAQ,GAVC,cAAiD;AACjE,OAAI,CAAC,kBAAmB,QAAO;AAE/B,WAAQ,QAAgC;IACtC,MAAM,QAAQ,EAAE,IAAI;IACpB,MAAM,WAAW,kBAAkB;AACnC,WAAO,UAAU,OAAO,WAAW,WAAW;;KAE/C,CAAC,GAAG,kBAAkB,CAEI;EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.mjs","names":[],"sources":["../../../src/mdx/mdxComponents/CodeBlock.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { FALLBACK_LANG } from '@/Highlighter/const';\nimport type { MermaidProps } from '@/Mermaid';\n\nimport { Pre, PreMermaid, PreSingleLine } from '../mdxComponents/Pre';\n\nconst countLines = (str: string): number => {\n const regex = /\\n/g;\n const matches = str.match(regex);\n return matches ? matches.length : 1;\n};\n\nconst useCode = (raw: any) => {\n if (!raw) return;\n\n const { children = '', className } = raw?.props || { children: '' };\n\n if (!children) return;\n\n const content = Array.isArray(children) ? (children[0] as string) : children;\n\n const lang = className?.replace('language-', '') || FALLBACK_LANG;\n\n const isSingleLine = countLines(content) <= 1 && content.length <= 32;\n\n return {\n content,\n isSingleLine,\n lang,\n };\n};\n\ninterface CodeBlockProps {\n children: any;\n enableMermaid?: boolean;\n fullFeatured?: boolean;\n mermaid?: MermaidProps;\n}\n\nconst CodeBlock: FC<CodeBlockProps> = ({ children, fullFeatured, enableMermaid, mermaid }) => {\n const code = useCode(children);\n\n if (!code) return;\n\n if (enableMermaid && code.lang === 'mermaid')\n return (\n <PreMermaid fullFeatured={fullFeatured} {...mermaid}>\n {code.content}\n </PreMermaid>\n );\n\n if (code.isSingleLine) return <PreSingleLine language={code.lang}>{code.content}</PreSingleLine>;\n\n return (\n <Pre allowChangeLanguage={false} fullFeatured={fullFeatured} language={code.lang}>\n {code.content}\n </Pre>\n );\n};\n\nCodeBlock.displayName = 'MdxCodeBlock';\n\nexport default CodeBlock;\n"],"mappings":";;;;;AASA,MAAM,cAAc,QAAwB;CAE1C,MAAM,UAAU,IAAI,
|
|
1
|
+
{"version":3,"file":"CodeBlock.mjs","names":[],"sources":["../../../src/mdx/mdxComponents/CodeBlock.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { FALLBACK_LANG } from '@/Highlighter/const';\nimport type { MermaidProps } from '@/Mermaid';\n\nimport { Pre, PreMermaid, PreSingleLine } from '../mdxComponents/Pre';\n\nconst countLines = (str: string): number => {\n const regex = /\\n/g;\n const matches = str.match(regex);\n return matches ? matches.length : 1;\n};\n\nconst useCode = (raw: any) => {\n if (!raw) return;\n\n const { children = '', className } = raw?.props || { children: '' };\n\n if (!children) return;\n\n const content = Array.isArray(children) ? (children[0] as string) : children;\n\n const lang = className?.replace('language-', '') || FALLBACK_LANG;\n\n const isSingleLine = countLines(content) <= 1 && content.length <= 32;\n\n return {\n content,\n isSingleLine,\n lang,\n };\n};\n\ninterface CodeBlockProps {\n children: any;\n enableMermaid?: boolean;\n fullFeatured?: boolean;\n mermaid?: MermaidProps;\n}\n\nconst CodeBlock: FC<CodeBlockProps> = ({ children, fullFeatured, enableMermaid, mermaid }) => {\n const code = useCode(children);\n\n if (!code) return;\n\n if (enableMermaid && code.lang === 'mermaid')\n return (\n <PreMermaid fullFeatured={fullFeatured} {...mermaid}>\n {code.content}\n </PreMermaid>\n );\n\n if (code.isSingleLine) return <PreSingleLine language={code.lang}>{code.content}</PreSingleLine>;\n\n return (\n <Pre allowChangeLanguage={false} fullFeatured={fullFeatured} language={code.lang}>\n {code.content}\n </Pre>\n );\n};\n\nCodeBlock.displayName = 'MdxCodeBlock';\n\nexport default CodeBlock;\n"],"mappings":";;;;;AASA,MAAM,cAAc,QAAwB;CAE1C,MAAM,UAAU,IAAI,MAAM,MAAM;AAChC,QAAO,UAAU,QAAQ,SAAS;;AAGpC,MAAM,WAAW,QAAa;AAC5B,KAAI,CAAC,IAAK;CAEV,MAAM,EAAE,WAAW,IAAI,cAAc,KAAK,SAAS,EAAE,UAAU,IAAI;AAEnE,KAAI,CAAC,SAAU;CAEf,MAAM,UAAU,MAAM,QAAQ,SAAS,GAAI,SAAS,KAAgB;CAEpE,MAAM,OAAO,WAAW,QAAQ,aAAa,GAAG,IAAA;AAIhD,QAAO;EACL;EACA,cAJmB,WAAW,QAAQ,IAAI,KAAK,QAAQ,UAAU;EAKjE;EACD;;AAUH,MAAM,aAAiC,EAAE,UAAU,cAAc,eAAe,cAAc;CAC5F,MAAM,OAAO,QAAQ,SAAS;AAE9B,KAAI,CAAC,KAAM;AAEX,KAAI,iBAAiB,KAAK,SAAS,UACjC,QACE,oBAAC,YAAD;EAA0B;EAAc,GAAI;YACzC,KAAK;EACK,CAAA;AAGjB,KAAI,KAAK,aAAc,QAAO,oBAAC,eAAD;EAAe,UAAU,KAAK;YAAO,KAAK;EAAwB,CAAA;AAEhG,QACE,oBAAC,KAAD;EAAK,qBAAqB;EAAqB;EAAc,UAAU,KAAK;YACzE,KAAK;EACF,CAAA;;AAIV,UAAU,cAAc"}
|
|
@@ -5,10 +5,10 @@ import { styles } from "./style.mjs";
|
|
|
5
5
|
import { memo } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { cx } from "antd-style";
|
|
8
|
-
import
|
|
8
|
+
import useMergeState from "use-merge-value";
|
|
9
9
|
//#region src/mobile/TabBar/TabBar.tsx
|
|
10
10
|
const TabBar = memo(({ ref, className, safeArea, items, activeKey, defaultActiveKey, onChange, ...rest }) => {
|
|
11
|
-
const [currentActive, setCurrentActive] =
|
|
11
|
+
const [currentActive, setCurrentActive] = useMergeState(defaultActiveKey || items[0].key, {
|
|
12
12
|
defaultValue: defaultActiveKey,
|
|
13
13
|
onChange,
|
|
14
14
|
value: activeKey
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabBar.mjs","names":["
|
|
1
|
+
{"version":3,"file":"TabBar.mjs","names":["Flexbox"],"sources":["../../../src/mobile/TabBar/TabBar.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport { memo } from 'react';\nimport useMergeState from 'use-merge-value';\n\nimport { Flexbox } from '@/Flex';\nimport SafeArea from '@/mobile/SafeArea';\n\nimport { styles } from './style';\nimport type { TabBarProps } from './type';\n\nconst TabBar = memo<TabBarProps>(\n ({ ref, className, safeArea, items, activeKey, defaultActiveKey, onChange, ...rest }) => {\n const [currentActive, setCurrentActive] = useMergeState<string>(\n defaultActiveKey || items[0].key,\n {\n defaultValue: defaultActiveKey,\n onChange,\n value: activeKey,\n },\n );\n\n return (\n <Flexbox as={'footer'} className={cx(styles.container, className)} ref={ref} {...rest}>\n <Flexbox\n horizontal\n align={'center'}\n className={cx(styles.inner, className)}\n justify={'space-around'}\n >\n {items.map((item) => {\n const active = item.key === currentActive;\n return (\n <Flexbox\n align={'center'}\n className={cx(styles.tab, active && styles.active)}\n gap={4}\n justify={'center'}\n key={item.key}\n onClick={() => {\n setCurrentActive(item.key);\n item?.onClick?.();\n }}\n >\n <Flexbox align={'center'} className={styles.icon} justify={'center'}>\n {typeof item.icon === 'function' ? item.icon(active) : item.icon}\n </Flexbox>\n <div className={styles.title}>\n {typeof item.title === 'function' ? item.title(active) : item.title}\n </div>\n </Flexbox>\n );\n })}\n </Flexbox>\n {safeArea && <SafeArea position={'bottom'} />}\n </Flexbox>\n );\n },\n);\n\nTabBar.displayName = 'MobileTabBar';\n\nexport default TabBar;\n"],"mappings":";;;;;;;;;AAYA,MAAM,SAAS,MACZ,EAAE,KAAK,WAAW,UAAU,OAAO,WAAW,kBAAkB,UAAU,GAAG,WAAW;CACvF,MAAM,CAAC,eAAe,oBAAoB,cACxC,oBAAoB,MAAM,GAAG,KAC7B;EACE,cAAc;EACd;EACA,OAAO;EACR,CACF;AAED,QACE,qBAACA,mBAAD;EAAS,IAAI;EAAU,WAAW,GAAG,OAAO,WAAW,UAAU;EAAO;EAAK,GAAI;YAAjF,CACE,oBAACA,mBAAD;GACE,YAAA;GACA,OAAO;GACP,WAAW,GAAG,OAAO,OAAO,UAAU;GACtC,SAAS;aAER,MAAM,KAAK,SAAS;IACnB,MAAM,SAAS,KAAK,QAAQ;AAC5B,WACE,qBAACA,mBAAD;KACE,OAAO;KACP,WAAW,GAAG,OAAO,KAAK,UAAU,OAAO,OAAO;KAClD,KAAK;KACL,SAAS;KAET,eAAe;AACb,uBAAiB,KAAK,IAAI;AAC1B,YAAM,WAAW;;eARrB,CAWE,oBAACA,mBAAD;MAAS,OAAO;MAAU,WAAW,OAAO;MAAM,SAAS;gBACxD,OAAO,KAAK,SAAS,aAAa,KAAK,KAAK,OAAO,GAAG,KAAK;MACpD,CAAA,EACV,oBAAC,OAAD;MAAK,WAAW,OAAO;gBACpB,OAAO,KAAK,UAAU,aAAa,KAAK,MAAM,OAAO,GAAG,KAAK;MAC1D,CAAA,CACE;OAZH,KAAK,IAYF;KAEZ;GACM,CAAA,EACT,YAAY,oBAAC,UAAD,EAAU,UAAU,UAAY,CAAA,CACrC;;EAGf;AAED,OAAO,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTheme.mjs","names":[],"sources":["../../src/styles/customTheme.ts"],"sourcesContent":["import {\n blue,\n cyan,\n geekblue,\n gold,\n green,\n lime,\n magenta,\n orange,\n purple,\n red,\n volcano,\n yellow,\n} from '@/color/colors';\nimport { mauve, olive, sage, sand, slate } from '@/color/neutrals';\n\nexport const primaryColors = {\n blue: blue.dark[9],\n cyan: cyan.dark[9],\n geekblue: geekblue.dark[9],\n gold: gold.dark[9],\n green: green.dark[9],\n lime: lime.dark[9],\n magenta: magenta.dark[9],\n orange: orange.dark[9],\n purple: purple.dark[9],\n red: red.dark[9],\n volcano: volcano.dark[9],\n yellow: yellow.dark[9],\n};\n\nexport type PrimaryColorsObj = typeof primaryColors;\nexport type PrimaryColors = keyof PrimaryColorsObj;\nexport const primaryColorsSwatches = [\n primaryColors.red,\n primaryColors.orange,\n primaryColors.gold,\n primaryColors.yellow,\n primaryColors.lime,\n primaryColors.green,\n primaryColors.cyan,\n primaryColors.blue,\n primaryColors.geekblue,\n primaryColors.purple,\n primaryColors.magenta,\n primaryColors.volcano,\n];\nexport const neutralColors = {\n mauve: mauve.dark[9],\n olive: olive.dark[9],\n sage: sage.dark[9],\n sand: sand.dark[9],\n slate: slate.dark[9],\n};\nexport const neutralColorsSwatches = [\n neutralColors.mauve,\n neutralColors.slate,\n neutralColors.sage,\n neutralColors.olive,\n neutralColors.sand,\n];\n\nexport type NeutralColorsObj = typeof neutralColors;\nexport type NeutralColors = keyof NeutralColorsObj;\n\nexport const findCustomThemeName = (type: 'primary' | 'neutral', value: string) => {\n const res = type === 'primary' ? primaryColors : neutralColors;\n const result = Object.entries(res).find((item) => item[1] === value);\n return result?.[0];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,MAAa,gBAAgB;CAC3B,MAAM,KAAK,KAAK;CAChB,MAAM,KAAK,KAAK;CAChB,UAAU,SAAS,KAAK;CACxB,MAAM,KAAK,KAAK;CAChB,OAAO,MAAM,KAAK;CAClB,MAAM,KAAK,KAAK;CAChB,SAAS,QAAQ,KAAK;CACtB,QAAQ,OAAO,KAAK;CACpB,QAAQ,OAAO,KAAK;CACpB,KAAK,IAAI,KAAK;CACd,SAAS,QAAQ,KAAK;CACtB,QAAQ,OAAO,KAAK;CACrB;AAID,MAAa,wBAAwB;CACnC,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACf;AACD,MAAa,gBAAgB;CAC3B,OAAO,MAAM,KAAK;CAClB,OAAO,MAAM,KAAK;CAClB,MAAM,KAAK,KAAK;CAChB,MAAM,KAAK,KAAK;CAChB,OAAO,MAAM,KAAK;CACnB;AACD,MAAa,wBAAwB;CACnC,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACf;AAKD,MAAa,uBAAuB,MAA6B,UAAkB;AAGjF,QADe,OAAO,QADV,SAAS,YAAY,gBAAgB,cACf,CAAC,MAAM,SAAS,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"customTheme.mjs","names":[],"sources":["../../src/styles/customTheme.ts"],"sourcesContent":["import {\n blue,\n cyan,\n geekblue,\n gold,\n green,\n lime,\n magenta,\n orange,\n purple,\n red,\n volcano,\n yellow,\n} from '@/color/colors';\nimport { mauve, olive, sage, sand, slate } from '@/color/neutrals';\n\nexport const primaryColors = {\n blue: blue.dark[9],\n cyan: cyan.dark[9],\n geekblue: geekblue.dark[9],\n gold: gold.dark[9],\n green: green.dark[9],\n lime: lime.dark[9],\n magenta: magenta.dark[9],\n orange: orange.dark[9],\n purple: purple.dark[9],\n red: red.dark[9],\n volcano: volcano.dark[9],\n yellow: yellow.dark[9],\n};\n\nexport type PrimaryColorsObj = typeof primaryColors;\nexport type PrimaryColors = keyof PrimaryColorsObj;\nexport const primaryColorsSwatches = [\n primaryColors.red,\n primaryColors.orange,\n primaryColors.gold,\n primaryColors.yellow,\n primaryColors.lime,\n primaryColors.green,\n primaryColors.cyan,\n primaryColors.blue,\n primaryColors.geekblue,\n primaryColors.purple,\n primaryColors.magenta,\n primaryColors.volcano,\n];\nexport const neutralColors = {\n mauve: mauve.dark[9],\n olive: olive.dark[9],\n sage: sage.dark[9],\n sand: sand.dark[9],\n slate: slate.dark[9],\n};\nexport const neutralColorsSwatches = [\n neutralColors.mauve,\n neutralColors.slate,\n neutralColors.sage,\n neutralColors.olive,\n neutralColors.sand,\n];\n\nexport type NeutralColorsObj = typeof neutralColors;\nexport type NeutralColors = keyof NeutralColorsObj;\n\nexport const findCustomThemeName = (type: 'primary' | 'neutral', value: string) => {\n const res = type === 'primary' ? primaryColors : neutralColors;\n const result = Object.entries(res).find((item) => item[1] === value);\n return result?.[0];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,MAAa,gBAAgB;CAC3B,MAAM,KAAK,KAAK;CAChB,MAAM,KAAK,KAAK;CAChB,UAAU,SAAS,KAAK;CACxB,MAAM,KAAK,KAAK;CAChB,OAAO,MAAM,KAAK;CAClB,MAAM,KAAK,KAAK;CAChB,SAAS,QAAQ,KAAK;CACtB,QAAQ,OAAO,KAAK;CACpB,QAAQ,OAAO,KAAK;CACpB,KAAK,IAAI,KAAK;CACd,SAAS,QAAQ,KAAK;CACtB,QAAQ,OAAO,KAAK;CACrB;AAID,MAAa,wBAAwB;CACnC,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACf;AACD,MAAa,gBAAgB;CAC3B,OAAO,MAAM,KAAK;CAClB,OAAO,MAAM,KAAK;CAClB,MAAM,KAAK,KAAK;CAChB,MAAM,KAAK,KAAK;CAChB,OAAO,MAAM,KAAK;CACnB;AACD,MAAa,wBAAwB;CACnC,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACd,cAAc;CACf;AAKD,MAAa,uBAAuB,MAA6B,UAAkB;AAGjF,QADe,OAAO,QADV,SAAS,YAAY,gBAAgB,cACf,CAAC,MAAM,SAAS,KAAK,OAAO,MACjD,GAAG"}
|
|
@@ -85,6 +85,11 @@ const staticStylish = createStaticStyles(({ css, cssVar }) => ({
|
|
|
85
85
|
color: ${cssVar.colorText};
|
|
86
86
|
}
|
|
87
87
|
`,
|
|
88
|
+
/**
|
|
89
|
+
* Shadow style using CSS variables.
|
|
90
|
+
* Note: This uses CSS variables which automatically adapt to light/dark mode.
|
|
91
|
+
* For more control, use the dynamic version from customStylish.
|
|
92
|
+
*/
|
|
88
93
|
shadow: css`
|
|
89
94
|
box-shadow:
|
|
90
95
|
0 1px 0 -1px ${cssVar.colorBorder},
|
|
@@ -101,6 +106,11 @@ const staticStylish = createStaticStyles(({ css, cssVar }) => ({
|
|
|
101
106
|
background: ${cssVar.colorFillTertiary};
|
|
102
107
|
}
|
|
103
108
|
`,
|
|
109
|
+
/**
|
|
110
|
+
* Variant borderless danger style.
|
|
111
|
+
* Note: Uses colorErrorBg as fallback since colorErrorFillTertiary is not in cssVar.
|
|
112
|
+
* For exact match, use the dynamic version from customStylish.
|
|
113
|
+
*/
|
|
104
114
|
variantBorderlessDanger: css`
|
|
105
115
|
border: none;
|
|
106
116
|
background: none;
|
|
@@ -123,6 +133,11 @@ const staticStylish = createStaticStyles(({ css, cssVar }) => ({
|
|
|
123
133
|
background: ${cssVar.colorFillSecondary};
|
|
124
134
|
}
|
|
125
135
|
`,
|
|
136
|
+
/**
|
|
137
|
+
* Variant filled danger style.
|
|
138
|
+
* Note: Uses colorErrorBg as fallback since colorErrorFillTertiary/Secondary are not in cssVar.
|
|
139
|
+
* For exact match, use the dynamic version from customStylish.
|
|
140
|
+
*/
|
|
126
141
|
variantFilledDanger: css`
|
|
127
142
|
background: ${cssVar.colorErrorBg};
|
|
128
143
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customStylishStatic.mjs","names":[],"sources":["../../../src/styles/theme/customStylishStatic.ts"],"sourcesContent":["import { createStaticStyles, keyframes } from 'antd-style';\n\nimport type { LobeCustomStylish } from '@/types/customStylish';\n\n/**\n * Static version of custom stylish utilities.\n * This can be used with createStaticStyles for better performance.\n *\n * Note: Some styles that depend on isDarkMode or custom tokens may have limitations.\n * For full dynamic support, use the regular customStylish from './customStylish'.\n */\nconst gradient = keyframes`\n 0% {\n background-position: 0% 50%;\n }\n 50% {\n background-position: 100% 50%;\n }\n 100% {\n background-position: 0% 50%;\n }\n`;\n\nexport const staticStylish = createStaticStyles(({ css, cssVar }) => ({\n active: css`\n color: ${cssVar.colorText};\n background: ${cssVar.colorFillSecondary};\n\n &:hover {\n color: ${cssVar.colorText};\n background: ${cssVar.colorFill};\n }\n `,\n\n blur: css`\n backdrop-filter: saturate(150%) blur(10px);\n `,\n\n blurStrong: css`\n backdrop-filter: saturate(150%) blur(36px);\n `,\n\n bottomScrollbar: css`\n ::-webkit-scrollbar {\n width: 0;\n height: 4px;\n background-color: transparent;\n\n &-thumb {\n border-radius: 4px;\n background-color: ${cssVar.colorFill};\n transition: background-color 500ms ${cssVar.motionEaseOut};\n }\n\n &-corner {\n display: none;\n width: 0;\n height: 0;\n }\n }\n `,\n\n disabled: css`\n cursor: not-allowed;\n opacity: 0.5;\n `,\n\n gradientAnimation: css`\n border-radius: inherit;\n background-image: linear-gradient(\n -45deg,\n ${cssVar.gold},\n ${cssVar.magenta},\n ${cssVar.geekblue},\n ${cssVar.cyan}\n );\n background-size: 400% 400%;\n animation: 5s ${gradient} 5s ease infinite;\n `,\n\n noScrollbar: css`\n ::-webkit-scrollbar {\n display: none;\n width: 0;\n height: 0;\n background-color: transparent;\n }\n `,\n\n resetLinkColor: css`\n cursor: pointer;\n color: ${cssVar.colorTextSecondary};\n\n &:hover {\n color: ${cssVar.colorText};\n }\n `,\n\n /**\n * Shadow style using CSS variables.\n * Note: This uses CSS variables which automatically adapt to light/dark mode.\n * For more control, use the dynamic version from customStylish.\n */\n shadow: css`\n box-shadow:\n 0 1px 0 -1px ${cssVar.colorBorder},\n 0 1px 2px -0.5px ${cssVar.colorBorder},\n 0 2px 2px -1px ${cssVar.colorBorderSecondary},\n 0 3px 6px -4px ${cssVar.colorBorderSecondary};\n `,\n\n variantBorderless: css`\n border: none;\n background: none;\n box-shadow: none;\n\n &:hover {\n background: ${cssVar.colorFillTertiary};\n }\n `,\n\n /**\n * Variant borderless danger style.\n * Note: Uses colorErrorBg as fallback since colorErrorFillTertiary is not in cssVar.\n * For exact match, use the dynamic version from customStylish.\n */\n variantBorderlessDanger: css`\n border: none;\n background: none;\n box-shadow: none;\n\n &:hover {\n background: ${cssVar.colorErrorBg};\n box-shadow: inset 0 0 0 1px ${cssVar.colorErrorBg};\n }\n `,\n\n variantBorderlessWithoutHover: css`\n border: none;\n background: none;\n box-shadow: none;\n `,\n\n variantFilled: css`\n background: ${cssVar.colorFillTertiary};\n\n &:hover {\n background: ${cssVar.colorFillSecondary};\n }\n `,\n\n /**\n * Variant filled danger style.\n * Note: Uses colorErrorBg as fallback since colorErrorFillTertiary/Secondary are not in cssVar.\n * For exact match, use the dynamic version from customStylish.\n */\n variantFilledDanger: css`\n background: ${cssVar.colorErrorBg};\n\n &:hover {\n background: ${cssVar.colorErrorBgHover};\n }\n `,\n\n variantFilledWithoutHover: css`\n background: ${cssVar.colorFillTertiary};\n `,\n\n variantOutlined: css`\n border: 1px solid ${cssVar.colorBorderSecondary};\n background: ${cssVar.colorBgContainer};\n\n &:hover {\n border: 1px solid ${cssVar.colorBorder};\n background: ${cssVar.colorBgContainer};\n }\n `,\n\n variantOutlinedDanger: css`\n border: 1px solid ${cssVar.colorErrorBorder};\n\n &:hover {\n border: 1px solid ${cssVar.colorErrorBorder};\n }\n `,\n\n variantOutlinedWithoutHover: css`\n border: 1px solid ${cssVar.colorBorderSecondary};\n background: ${cssVar.colorBgContainer};\n `,\n})) as LobeCustomStylish;\n"],"mappings":";;;;;;;;;AAWA,MAAM,WAAW,SAAS;;;;;;;;;;;AAY1B,MAAa,gBAAgB,oBAAoB,EAAE,KAAK,cAAc;CACpE,QAAQ,GAAG;aACA,OAAO,UAAU;kBACZ,OAAO,mBAAmB;;;eAG7B,OAAO,UAAU;oBACZ,OAAO,UAAU;;;CAInC,MAAM,GAAG;;;CAIT,YAAY,GAAG;;;CAIf,iBAAiB,GAAG;;;;;;;;4BAQM,OAAO,UAAU;6CACA,OAAO,cAAc;;;;;;;;;;CAWhE,UAAU,GAAG;;;;CAKb,mBAAmB,GAAG;;;;QAIhB,OAAO,KAAK;QACZ,OAAO,QAAQ;QACf,OAAO,SAAS;QAChB,OAAO,KAAK;;;oBAGA,SAAS;;CAG3B,aAAa,GAAG;;;;;;;;CAShB,gBAAgB,GAAG;;aAER,OAAO,mBAAmB;;;eAGxB,OAAO,UAAU
|
|
1
|
+
{"version":3,"file":"customStylishStatic.mjs","names":[],"sources":["../../../src/styles/theme/customStylishStatic.ts"],"sourcesContent":["import { createStaticStyles, keyframes } from 'antd-style';\n\nimport type { LobeCustomStylish } from '@/types/customStylish';\n\n/**\n * Static version of custom stylish utilities.\n * This can be used with createStaticStyles for better performance.\n *\n * Note: Some styles that depend on isDarkMode or custom tokens may have limitations.\n * For full dynamic support, use the regular customStylish from './customStylish'.\n */\nconst gradient = keyframes`\n 0% {\n background-position: 0% 50%;\n }\n 50% {\n background-position: 100% 50%;\n }\n 100% {\n background-position: 0% 50%;\n }\n`;\n\nexport const staticStylish = createStaticStyles(({ css, cssVar }) => ({\n active: css`\n color: ${cssVar.colorText};\n background: ${cssVar.colorFillSecondary};\n\n &:hover {\n color: ${cssVar.colorText};\n background: ${cssVar.colorFill};\n }\n `,\n\n blur: css`\n backdrop-filter: saturate(150%) blur(10px);\n `,\n\n blurStrong: css`\n backdrop-filter: saturate(150%) blur(36px);\n `,\n\n bottomScrollbar: css`\n ::-webkit-scrollbar {\n width: 0;\n height: 4px;\n background-color: transparent;\n\n &-thumb {\n border-radius: 4px;\n background-color: ${cssVar.colorFill};\n transition: background-color 500ms ${cssVar.motionEaseOut};\n }\n\n &-corner {\n display: none;\n width: 0;\n height: 0;\n }\n }\n `,\n\n disabled: css`\n cursor: not-allowed;\n opacity: 0.5;\n `,\n\n gradientAnimation: css`\n border-radius: inherit;\n background-image: linear-gradient(\n -45deg,\n ${cssVar.gold},\n ${cssVar.magenta},\n ${cssVar.geekblue},\n ${cssVar.cyan}\n );\n background-size: 400% 400%;\n animation: 5s ${gradient} 5s ease infinite;\n `,\n\n noScrollbar: css`\n ::-webkit-scrollbar {\n display: none;\n width: 0;\n height: 0;\n background-color: transparent;\n }\n `,\n\n resetLinkColor: css`\n cursor: pointer;\n color: ${cssVar.colorTextSecondary};\n\n &:hover {\n color: ${cssVar.colorText};\n }\n `,\n\n /**\n * Shadow style using CSS variables.\n * Note: This uses CSS variables which automatically adapt to light/dark mode.\n * For more control, use the dynamic version from customStylish.\n */\n shadow: css`\n box-shadow:\n 0 1px 0 -1px ${cssVar.colorBorder},\n 0 1px 2px -0.5px ${cssVar.colorBorder},\n 0 2px 2px -1px ${cssVar.colorBorderSecondary},\n 0 3px 6px -4px ${cssVar.colorBorderSecondary};\n `,\n\n variantBorderless: css`\n border: none;\n background: none;\n box-shadow: none;\n\n &:hover {\n background: ${cssVar.colorFillTertiary};\n }\n `,\n\n /**\n * Variant borderless danger style.\n * Note: Uses colorErrorBg as fallback since colorErrorFillTertiary is not in cssVar.\n * For exact match, use the dynamic version from customStylish.\n */\n variantBorderlessDanger: css`\n border: none;\n background: none;\n box-shadow: none;\n\n &:hover {\n background: ${cssVar.colorErrorBg};\n box-shadow: inset 0 0 0 1px ${cssVar.colorErrorBg};\n }\n `,\n\n variantBorderlessWithoutHover: css`\n border: none;\n background: none;\n box-shadow: none;\n `,\n\n variantFilled: css`\n background: ${cssVar.colorFillTertiary};\n\n &:hover {\n background: ${cssVar.colorFillSecondary};\n }\n `,\n\n /**\n * Variant filled danger style.\n * Note: Uses colorErrorBg as fallback since colorErrorFillTertiary/Secondary are not in cssVar.\n * For exact match, use the dynamic version from customStylish.\n */\n variantFilledDanger: css`\n background: ${cssVar.colorErrorBg};\n\n &:hover {\n background: ${cssVar.colorErrorBgHover};\n }\n `,\n\n variantFilledWithoutHover: css`\n background: ${cssVar.colorFillTertiary};\n `,\n\n variantOutlined: css`\n border: 1px solid ${cssVar.colorBorderSecondary};\n background: ${cssVar.colorBgContainer};\n\n &:hover {\n border: 1px solid ${cssVar.colorBorder};\n background: ${cssVar.colorBgContainer};\n }\n `,\n\n variantOutlinedDanger: css`\n border: 1px solid ${cssVar.colorErrorBorder};\n\n &:hover {\n border: 1px solid ${cssVar.colorErrorBorder};\n }\n `,\n\n variantOutlinedWithoutHover: css`\n border: 1px solid ${cssVar.colorBorderSecondary};\n background: ${cssVar.colorBgContainer};\n `,\n})) as LobeCustomStylish;\n"],"mappings":";;;;;;;;;AAWA,MAAM,WAAW,SAAS;;;;;;;;;;;AAY1B,MAAa,gBAAgB,oBAAoB,EAAE,KAAK,cAAc;CACpE,QAAQ,GAAG;aACA,OAAO,UAAU;kBACZ,OAAO,mBAAmB;;;eAG7B,OAAO,UAAU;oBACZ,OAAO,UAAU;;;CAInC,MAAM,GAAG;;;CAIT,YAAY,GAAG;;;CAIf,iBAAiB,GAAG;;;;;;;;4BAQM,OAAO,UAAU;6CACA,OAAO,cAAc;;;;;;;;;;CAWhE,UAAU,GAAG;;;;CAKb,mBAAmB,GAAG;;;;QAIhB,OAAO,KAAK;QACZ,OAAO,QAAQ;QACf,OAAO,SAAS;QAChB,OAAO,KAAK;;;oBAGA,SAAS;;CAG3B,aAAa,GAAG;;;;;;;;CAShB,gBAAgB,GAAG;;aAER,OAAO,mBAAmB;;;eAGxB,OAAO,UAAU;;;;;;;;CAS9B,QAAQ,GAAG;;qBAEQ,OAAO,YAAY;yBACf,OAAO,YAAY;uBACrB,OAAO,qBAAqB;uBAC5B,OAAO,qBAAqB;;CAGjD,mBAAmB,GAAG;;;;;;oBAMJ,OAAO,kBAAkB;;;;;;;;CAS3C,yBAAyB,GAAG;;;;;;oBAMV,OAAO,aAAa;oCACJ,OAAO,aAAa;;;CAItD,+BAA+B,GAAG;;;;;CAMlC,eAAe,GAAG;kBACF,OAAO,kBAAkB;;;oBAGvB,OAAO,mBAAmB;;;;;;;;CAS5C,qBAAqB,GAAG;kBACR,OAAO,aAAa;;;oBAGlB,OAAO,kBAAkB;;;CAI3C,2BAA2B,GAAG;kBACd,OAAO,kBAAkB;;CAGzC,iBAAiB,GAAG;wBACE,OAAO,qBAAqB;kBAClC,OAAO,iBAAiB;;;0BAGhB,OAAO,YAAY;oBACzB,OAAO,iBAAiB;;;CAI1C,uBAAuB,GAAG;wBACJ,OAAO,iBAAiB;;;0BAGtB,OAAO,iBAAiB;;;CAIhD,6BAA6B,GAAG;wBACV,OAAO,qBAAqB;kBAClC,OAAO,iBAAiB;;CAEzC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.mjs","names":[],"sources":["../../../../src/styles/theme/token/base.ts"],"sourcesContent":["import type { AliasToken } from 'antd/es/theme/interface';\n\nconst FONT_EMOJI = `\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Apple Color Emoji\",\"Twemoji Mozilla\",\"Noto Color Emoji\",\"Android Emoji\"`;\nconst FONT_EN = `\"HarmonyOS Sans\",\"Segoe UI\",\"SF Pro Display\",-apple-system,BlinkMacSystemFont,Roboto,Oxygen,Ubuntu,Cantarell,\"Open Sans\",\"Helvetica Neue\",sans-serif`;\nconst FONT_CN = `\"HarmonyOS Sans SC\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft Yahei UI\",\"Microsoft Yahei\",\"Source Han Sans CN\",sans-serif`;\nconst FONT_CODE = `Hack,ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas`;\n\nexport const baseToken: Partial<AliasToken> = {\n borderRadius: 8,\n borderRadiusLG: 12,\n borderRadiusSM: 6,\n borderRadiusXS: 4,\n controlHeight: 36,\n fontFamily: [FONT_EN, FONT_CN, FONT_EMOJI].join(','),\n fontFamilyCode: [FONT_CODE, FONT_CN, FONT_EMOJI].join(','),\n};\n"],"mappings":";AAEA,MAAM,aAAa;AACnB,MAAM,UAAU;AAChB,MAAM,UAAU;AAGhB,MAAa,YAAiC;CAC5C,cAAc;CACd,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,eAAe;CACf,YAAY;EAAC;EAAS;EAAS;EAAW,CAAC,KAAK,IAAI;CACpD,gBAAgB;
|
|
1
|
+
{"version":3,"file":"base.mjs","names":[],"sources":["../../../../src/styles/theme/token/base.ts"],"sourcesContent":["import type { AliasToken } from 'antd/es/theme/interface';\n\nconst FONT_EMOJI = `\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Apple Color Emoji\",\"Twemoji Mozilla\",\"Noto Color Emoji\",\"Android Emoji\"`;\nconst FONT_EN = `\"HarmonyOS Sans\",\"Segoe UI\",\"SF Pro Display\",-apple-system,BlinkMacSystemFont,Roboto,Oxygen,Ubuntu,Cantarell,\"Open Sans\",\"Helvetica Neue\",sans-serif`;\nconst FONT_CN = `\"HarmonyOS Sans SC\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft Yahei UI\",\"Microsoft Yahei\",\"Source Han Sans CN\",sans-serif`;\nconst FONT_CODE = `Hack,ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas`;\n\nexport const baseToken: Partial<AliasToken> = {\n borderRadius: 8,\n borderRadiusLG: 12,\n borderRadiusSM: 6,\n borderRadiusXS: 4,\n controlHeight: 36,\n fontFamily: [FONT_EN, FONT_CN, FONT_EMOJI].join(','),\n fontFamilyCode: [FONT_CODE, FONT_CN, FONT_EMOJI].join(','),\n};\n"],"mappings":";AAEA,MAAM,aAAa;AACnB,MAAM,UAAU;AAChB,MAAM,UAAU;AAGhB,MAAa,YAAiC;CAC5C,cAAc;CACd,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,eAAe;CACf,YAAY;EAAC;EAAS;EAAS;EAAW,CAAC,KAAK,IAAI;CACpD,gBAAgB;EAAC;EAAW;EAAS;EAAW,CAAC,KAAK,IAAI;CAC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blobToPng.mjs","names":[],"sources":["../../src/utils/blobToPng.ts"],"sourcesContent":["/**\n * Convert image blob to PNG format.\n * Clipboard API only supports image/png and image/svg+xml.\n * WebP, JPEG and other formats need to be converted for clipboard copy.\n */\nexport const blobToPng = (blob: Blob): Promise<Blob> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const url = URL.createObjectURL(blob);\n\n img.onload = () => {\n URL.revokeObjectURL(url);\n const canvas = document.createElement('canvas');\n canvas.width = img.naturalWidth;\n canvas.height = img.naturalHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) {\n reject(new Error('Canvas context not available'));\n return;\n }\n ctx.drawImage(img, 0, 0);\n canvas.toBlob(\n (pngBlob) => {\n if (pngBlob) {\n resolve(pngBlob);\n } else {\n reject(new Error('Failed to convert to PNG'));\n }\n },\n 'image/png',\n 1,\n );\n };\n\n img.onerror = () => {\n URL.revokeObjectURL(url);\n reject(new Error('Failed to load image'));\n };\n\n img.src = url;\n });\n\nconst CLIPBOARD_SUPPORTED_TYPES = ['image/png', 'image/svg+xml'] as const;\n\nexport const getClipboardBlob = async (\n blob: Blob,\n): Promise<{ 'image/png': Blob } | { 'image/svg+xml': Blob }> => {\n const type = (blob.type || '').toLowerCase();\n\n if (type === 'image/png' || type === 'image/svg+xml') {\n return { [type]: blob } as { 'image/png': Blob } | { 'image/svg+xml': Blob };\n }\n\n const pngBlob = await blobToPng(blob);\n return { 'image/png': pngBlob };\n};\n"],"mappings":";;;;;;AAKA,MAAa,aAAa,SACxB,IAAI,SAAS,SAAS,WAAW;CAC/B,MAAM,MAAM,IAAI,OAAO;CACvB,MAAM,MAAM,IAAI,gBAAgB,KAAK;AAErC,KAAI,eAAe;AACjB,MAAI,gBAAgB,IAAI;EACxB,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,SAAO,QAAQ,IAAI;AACnB,SAAO,SAAS,IAAI;EACpB,MAAM,MAAM,OAAO,WAAW,KAAK;AACnC,MAAI,CAAC,KAAK;AACR,0BAAO,IAAI,MAAM,+BAA+B,CAAC;AACjD;;AAEF,MAAI,UAAU,KAAK,GAAG,EAAE;AACxB,SAAO,QACJ,YAAY;AACX,OAAI,QACF,SAAQ,QAAQ;OAEhB,wBAAO,IAAI,MAAM,2BAA2B,CAAC;KAGjD,aACA,EACD;;AAGH,KAAI,gBAAgB;AAClB,MAAI,gBAAgB,IAAI;AACxB,yBAAO,IAAI,MAAM,uBAAuB,CAAC;;AAG3C,KAAI,MAAM;EACV;AAIJ,MAAa,mBAAmB,OAC9B,SAC+D;CAC/D,MAAM,QAAQ,KAAK,QAAQ,IAAI,aAAa;AAE5C,KAAI,SAAS,eAAe,SAAS,gBACnC,QAAO,GAAG,OAAO,MAAM;AAIzB,QAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"blobToPng.mjs","names":[],"sources":["../../src/utils/blobToPng.ts"],"sourcesContent":["/**\n * Convert image blob to PNG format.\n * Clipboard API only supports image/png and image/svg+xml.\n * WebP, JPEG and other formats need to be converted for clipboard copy.\n */\nexport const blobToPng = (blob: Blob): Promise<Blob> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const url = URL.createObjectURL(blob);\n\n img.onload = () => {\n URL.revokeObjectURL(url);\n const canvas = document.createElement('canvas');\n canvas.width = img.naturalWidth;\n canvas.height = img.naturalHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) {\n reject(new Error('Canvas context not available'));\n return;\n }\n ctx.drawImage(img, 0, 0);\n canvas.toBlob(\n (pngBlob) => {\n if (pngBlob) {\n resolve(pngBlob);\n } else {\n reject(new Error('Failed to convert to PNG'));\n }\n },\n 'image/png',\n 1,\n );\n };\n\n img.onerror = () => {\n URL.revokeObjectURL(url);\n reject(new Error('Failed to load image'));\n };\n\n img.src = url;\n });\n\nconst CLIPBOARD_SUPPORTED_TYPES = ['image/png', 'image/svg+xml'] as const;\n\nexport const getClipboardBlob = async (\n blob: Blob,\n): Promise<{ 'image/png': Blob } | { 'image/svg+xml': Blob }> => {\n const type = (blob.type || '').toLowerCase();\n\n if (type === 'image/png' || type === 'image/svg+xml') {\n return { [type]: blob } as { 'image/png': Blob } | { 'image/svg+xml': Blob };\n }\n\n const pngBlob = await blobToPng(blob);\n return { 'image/png': pngBlob };\n};\n"],"mappings":";;;;;;AAKA,MAAa,aAAa,SACxB,IAAI,SAAS,SAAS,WAAW;CAC/B,MAAM,MAAM,IAAI,OAAO;CACvB,MAAM,MAAM,IAAI,gBAAgB,KAAK;AAErC,KAAI,eAAe;AACjB,MAAI,gBAAgB,IAAI;EACxB,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,SAAO,QAAQ,IAAI;AACnB,SAAO,SAAS,IAAI;EACpB,MAAM,MAAM,OAAO,WAAW,KAAK;AACnC,MAAI,CAAC,KAAK;AACR,0BAAO,IAAI,MAAM,+BAA+B,CAAC;AACjD;;AAEF,MAAI,UAAU,KAAK,GAAG,EAAE;AACxB,SAAO,QACJ,YAAY;AACX,OAAI,QACF,SAAQ,QAAQ;OAEhB,wBAAO,IAAI,MAAM,2BAA2B,CAAC;KAGjD,aACA,EACD;;AAGH,KAAI,gBAAgB;AAClB,MAAI,gBAAgB,IAAI;AACxB,yBAAO,IAAI,MAAM,uBAAuB,CAAC;;AAG3C,KAAI,MAAM;EACV;AAIJ,MAAa,mBAAmB,OAC9B,SAC+D;CAC/D,MAAM,QAAQ,KAAK,QAAQ,IAAI,aAAa;AAE5C,KAAI,SAAS,eAAe,SAAS,gBACnC,QAAO,GAAG,OAAO,MAAM;AAIzB,QAAO,EAAE,aAAa,MADA,UAAU,KAAK,EACN"}
|