@lobehub/ui 5.24.0 → 5.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/A/index.mjs +2 -1
- package/es/A/index.mjs.map +1 -1
- package/es/Accordion/AccordionItem.mjs +0 -1
- package/es/Accordion/AccordionItem.mjs.map +1 -1
- package/es/ActionIcon/components/utils.mjs +7 -9
- package/es/ActionIcon/components/utils.mjs.map +1 -1
- package/es/Checkbox/CheckboxGroup.mjs +4 -2
- package/es/Checkbox/CheckboxGroup.mjs.map +1 -1
- package/es/CodeDiff/CodeDiff.mjs +20 -18
- package/es/CodeDiff/CodeDiff.mjs.map +1 -1
- package/es/CodeDiff/PatchDiff.mjs +18 -16
- package/es/CodeDiff/PatchDiff.mjs.map +1 -1
- package/es/CopyButton/CopyButton.mjs +2 -1
- package/es/CopyButton/CopyButton.mjs.map +1 -1
- package/es/Highlighter/LangSelect.mjs +41 -40
- package/es/Highlighter/LangSelect.mjs.map +1 -1
- package/es/Highlighter/SyntaxHighlighter/StaticRenderer.mjs +2 -1
- package/es/Highlighter/SyntaxHighlighter/StaticRenderer.mjs.map +1 -1
- package/es/HotkeyInput/HotkeyInput.mjs +3 -1
- package/es/HotkeyInput/HotkeyInput.mjs.map +1 -1
- package/es/HtmlPreview/const.mjs +1 -1
- package/es/HtmlPreview/const.mjs.map +1 -1
- package/es/Icon/components/utils.mjs +7 -9
- package/es/Icon/components/utils.mjs.map +1 -1
- package/es/Image/Image.mjs +138 -37
- package/es/Image/Image.mjs.map +1 -1
- package/es/Image/PreviewGroup.d.mts +1 -0
- package/es/Image/PreviewGroup.mjs +33 -10
- package/es/Image/PreviewGroup.mjs.map +1 -1
- package/es/Image/index.d.mts +2 -2
- package/es/Image/index.mjs +1 -1
- package/es/Image/style.mjs +126 -71
- package/es/Image/style.mjs.map +1 -1
- package/es/Image/type.d.mts +14 -17
- package/es/Image/viewer/GalleryNav.mjs +44 -0
- package/es/Image/viewer/GalleryNav.mjs.map +1 -0
- package/es/Image/viewer/ImageViewer.mjs +275 -0
- package/es/Image/viewer/ImageViewer.mjs.map +1 -0
- package/es/Image/viewer/PreviewOutlet.mjs +19 -0
- package/es/Image/viewer/PreviewOutlet.mjs.map +1 -0
- package/es/Image/viewer/Toolbar.mjs +184 -0
- package/es/Image/viewer/Toolbar.mjs.map +1 -0
- package/es/Image/viewer/ViewerChrome.mjs +54 -0
- package/es/Image/viewer/ViewerChrome.mjs.map +1 -0
- package/es/Image/viewer/geometry.mjs +85 -0
- package/es/Image/viewer/geometry.mjs.map +1 -0
- package/es/Image/viewer/registry.d.mts +2 -0
- package/es/Image/viewer/registry.mjs +52 -0
- package/es/Image/viewer/registry.mjs.map +1 -0
- package/es/Image/viewer/useChromeIdle.mjs +72 -0
- package/es/Image/viewer/useChromeIdle.mjs.map +1 -0
- package/es/Image/viewer/useFinalFocus.mjs +10 -0
- package/es/Image/viewer/useFinalFocus.mjs.map +1 -0
- package/es/Image/viewer/useFlipTransition.mjs +321 -0
- package/es/Image/viewer/useFlipTransition.mjs.map +1 -0
- package/es/Image/viewer/useGalleryNav.mjs +89 -0
- package/es/Image/viewer/useGalleryNav.mjs.map +1 -0
- package/es/Image/viewer/useRefitTransition.mjs +47 -0
- package/es/Image/viewer/useRefitTransition.mjs.map +1 -0
- package/es/Image/viewer/useViewerGestures.mjs +148 -0
- package/es/Image/viewer/useViewerGestures.mjs.map +1 -0
- package/es/Image/viewer/useZoomPan.mjs +346 -0
- package/es/Image/viewer/useZoomPan.mjs.map +1 -0
- package/es/Img/index.mjs +2 -1
- package/es/Img/index.mjs.map +1 -1
- package/es/Markdown/SyntaxMarkdown/StreamdownRender.mjs +2 -1
- package/es/Markdown/SyntaxMarkdown/StreamdownRender.mjs.map +1 -1
- package/es/Markdown/SyntaxMarkdown/useSmoothStreamContent.mjs +2 -2
- package/es/Markdown/SyntaxMarkdown/useSmoothStreamContent.mjs.map +1 -1
- package/es/Modal/RawModalStackItem.mjs +6 -5
- package/es/Modal/RawModalStackItem.mjs.map +1 -1
- package/es/Modal/imperative.mjs +4 -2
- package/es/Modal/imperative.mjs.map +1 -1
- package/es/NeuralNetworkLoading/NeuralNetworkLoading.mjs +1 -1
- package/es/NeuralNetworkLoading/NeuralNetworkLoading.mjs.map +1 -1
- package/es/ScrollShadow/ScrollShadow.mjs +13 -12
- package/es/ScrollShadow/ScrollShadow.mjs.map +1 -1
- package/es/Skeleton/SkeletonButton.mjs +2 -1
- package/es/Skeleton/SkeletonButton.mjs.map +1 -1
- package/es/SortableList/SortableList.mjs +5 -1
- package/es/SortableList/SortableList.mjs.map +1 -1
- package/es/Text/Text.mjs +22 -21
- package/es/Text/Text.mjs.map +1 -1
- package/es/ThemeProvider/ThemeProvider.mjs +3 -2
- package/es/ThemeProvider/ThemeProvider.mjs.map +1 -1
- package/es/awesome/GradientButton/GradientButton.mjs +1 -3
- package/es/awesome/GradientButton/GradientButton.mjs.map +1 -1
- package/es/awesome/Spotlight/Spotlight.mjs +2 -1
- package/es/awesome/Spotlight/Spotlight.mjs.map +1 -1
- package/es/base-ui/Button/Button.mjs +13 -11
- package/es/base-ui/Button/Button.mjs.map +1 -1
- package/es/base-ui/Button/SplitButton.mjs +2 -1
- package/es/base-ui/Button/SplitButton.mjs.map +1 -1
- package/es/base-ui/ContextMenu/ContextMenuTrigger.mjs +2 -1
- package/es/base-ui/ContextMenu/ContextMenuTrigger.mjs.map +1 -1
- package/es/base-ui/ContextMenu/renderItems.mjs +2 -1
- package/es/base-ui/ContextMenu/renderItems.mjs.map +1 -1
- package/es/base-ui/Drawer/Drawer.d.mts +6 -0
- package/es/base-ui/Drawer/Drawer.mjs +152 -0
- package/es/base-ui/Drawer/Drawer.mjs.map +1 -0
- package/es/base-ui/Drawer/DrawerLayerContext.mjs +10 -0
- package/es/base-ui/Drawer/DrawerLayerContext.mjs.map +1 -0
- package/es/base-ui/Drawer/DrawerPushContext.mjs +27 -0
- package/es/base-ui/Drawer/DrawerPushContext.mjs.map +1 -0
- package/es/base-ui/Drawer/atoms.d.mts +58 -0
- package/es/base-ui/Drawer/atoms.mjs +262 -0
- package/es/base-ui/Drawer/atoms.mjs.map +1 -0
- package/es/base-ui/Drawer/constants.d.mts +17 -0
- package/es/base-ui/Drawer/constants.mjs +72 -0
- package/es/base-ui/Drawer/constants.mjs.map +1 -0
- package/es/base-ui/Drawer/index.d.mts +5 -0
- package/es/base-ui/Drawer/style.mjs +295 -0
- package/es/base-ui/Drawer/style.mjs.map +1 -0
- package/es/base-ui/Drawer/type.d.mts +65 -0
- package/es/base-ui/DropdownMenu/DropdownMenu.mjs +2 -1
- package/es/base-ui/DropdownMenu/DropdownMenu.mjs.map +1 -1
- package/es/base-ui/DropdownMenu/atoms.mjs +2 -1
- package/es/base-ui/DropdownMenu/atoms.mjs.map +1 -1
- package/es/base-ui/DropdownMenu/renderItems.mjs +2 -1
- package/es/base-ui/DropdownMenu/renderItems.mjs.map +1 -1
- package/es/base-ui/FloatingSheet/FloatingSheet.mjs +4 -1
- package/es/base-ui/FloatingSheet/FloatingSheet.mjs.map +1 -1
- package/es/base-ui/Input/style.d.mts +1 -1
- package/es/base-ui/Modal/atoms.mjs +7 -5
- package/es/base-ui/Modal/atoms.mjs.map +1 -1
- package/es/base-ui/Modal/imperative.mjs +2 -1
- package/es/base-ui/Modal/imperative.mjs.map +1 -1
- package/es/base-ui/Popover/atoms.mjs +2 -1
- package/es/base-ui/Popover/atoms.mjs.map +1 -1
- package/es/base-ui/Popover/context.mjs +4 -2
- package/es/base-ui/Popover/context.mjs.map +1 -1
- package/es/base-ui/Select/atoms.mjs +2 -1
- package/es/base-ui/Select/atoms.mjs.map +1 -1
- package/es/base-ui/Toast/hostGuard.mjs +26 -0
- package/es/base-ui/Toast/hostGuard.mjs.map +1 -0
- package/es/base-ui/Toast/imperative.mjs +43 -20
- package/es/base-ui/Toast/imperative.mjs.map +1 -1
- package/es/base-ui/Toast/pendingQueue.mjs +30 -0
- package/es/base-ui/Toast/pendingQueue.mjs.map +1 -0
- package/es/base-ui/index.d.mts +6 -1
- package/es/base-ui/index.mjs +5 -2
- package/es/brand/LobeChat/index.mjs +0 -1
- package/es/brand/LobeChat/index.mjs.map +1 -1
- package/es/brand/LobeHub/index.mjs +0 -1
- package/es/brand/LobeHub/index.mjs.map +1 -1
- package/es/brand/Logo3d/index.mjs +2 -1
- package/es/brand/Logo3d/index.mjs.map +1 -1
- package/es/chat/ChatItem/components/Actions.mjs +5 -4
- package/es/chat/ChatItem/components/Actions.mjs.map +1 -1
- package/es/chat/ChatList/ChatList.mjs +2 -1
- package/es/chat/ChatList/ChatList.mjs.map +1 -1
- package/es/color/ColorScales/ScaleRow.mjs +0 -2
- package/es/color/ColorScales/ScaleRow.mjs.map +1 -1
- package/es/hooks/useMermaid.mjs +2 -1
- package/es/hooks/useMermaid.mjs.map +1 -1
- package/es/i18n/resources/en/image.d.mts +5 -0
- package/es/i18n/resources/en/image.mjs +6 -1
- package/es/i18n/resources/en/image.mjs.map +1 -1
- package/es/i18n/resources/zhCn/image.d.mts +5 -0
- package/es/i18n/resources/zhCn/image.mjs +6 -1
- package/es/i18n/resources/zhCn/image.mjs.map +1 -1
- package/es/index.mjs +8 -8
- package/package.json +1 -1
- package/es/Image/components/Preview.mjs +0 -23
- package/es/Image/components/Preview.mjs.map +0 -1
- package/es/Image/components/Toolbar.mjs +0 -128
- package/es/Image/components/Toolbar.mjs.map +0 -1
- package/es/Image/components/usePreview.mjs +0 -58
- package/es/Image/components/usePreview.mjs.map +0 -1
- package/es/Image/components/usePreviewGroup.mjs +0 -57
- package/es/Image/components/usePreviewGroup.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSmoothStreamContent.mjs","names":["now"],"sources":["../../../src/Markdown/SyntaxMarkdown/useSmoothStreamContent.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { useStreamdownProfiler } from '@/Markdown/streamProfiler';\nimport { type StreamSmoothingPreset } from '@/Markdown/type';\nimport { getNow } from '@/utils/getNow';\n\nimport { findOpenFenceLanguage } from './fenceState';\n\ninterface StreamSmoothingPresetConfig {\n activeInputWindowMs: number;\n /**\n * Code-fence languages whose contents bypass smoothing entirely. While\n * the input ends inside an open fence in this set, every chunk is\n * `syncImmediate`-d to the display so downstream consumers (the\n * HtmlPreview iframe in particular) see partial HTML at the demo's\n * actual production rate instead of waiting on the smoother's\n * ~maxFlushCps budget. As soon as the fence closes — or another\n * non-bypass fence opens — smoothing resumes for the rest of the\n * stream. Default `['html']` covers the artifact case that motivated\n * this; tune via preset if you need to bypass `mermaid`, `svg`, etc.\n */\n bypassFencedLanguages: readonly string[];\n defaultCps: number;\n emaAlpha: number;\n flushCps: number;\n largeAppendChars: number;\n maxActiveCps: number;\n maxCps: number;\n maxFlushCps: number;\n minCommitIntervalMs: number;\n minCps: number;\n settleAfterMs: number;\n settleDrainMaxMs: number;\n settleDrainMinMs: number;\n targetBufferMs: number;\n}\n\nconst DEFAULT_BYPASS_LANGUAGES = ['html'] as const;\n\nconst PRESET_CONFIG: Record<StreamSmoothingPreset, StreamSmoothingPresetConfig> = {\n balanced: {\n activeInputWindowMs: 220,\n bypassFencedLanguages: DEFAULT_BYPASS_LANGUAGES,\n defaultCps: 38,\n emaAlpha: 0.2,\n flushCps: 120,\n largeAppendChars: 120,\n maxActiveCps: 132,\n maxCps: 72,\n maxFlushCps: 280,\n minCommitIntervalMs: 48,\n minCps: 18,\n settleAfterMs: 360,\n settleDrainMaxMs: 520,\n settleDrainMinMs: 180,\n targetBufferMs: 120,\n },\n realtime: {\n activeInputWindowMs: 140,\n bypassFencedLanguages: DEFAULT_BYPASS_LANGUAGES,\n defaultCps: 50,\n emaAlpha: 0.3,\n flushCps: 170,\n largeAppendChars: 180,\n maxActiveCps: 180,\n maxCps: 96,\n maxFlushCps: 360,\n minCommitIntervalMs: 32,\n minCps: 24,\n settleAfterMs: 260,\n settleDrainMaxMs: 360,\n settleDrainMinMs: 140,\n targetBufferMs: 40,\n },\n silky: {\n activeInputWindowMs: 320,\n bypassFencedLanguages: DEFAULT_BYPASS_LANGUAGES,\n defaultCps: 28,\n emaAlpha: 0.14,\n flushCps: 96,\n largeAppendChars: 100,\n maxActiveCps: 102,\n maxCps: 56,\n maxFlushCps: 220,\n minCommitIntervalMs: 56,\n minCps: 14,\n settleAfterMs: 460,\n settleDrainMaxMs: 680,\n settleDrainMinMs: 240,\n targetBufferMs: 170,\n },\n};\n\nconst clamp = (value: number, min: number, max: number): number => {\n return Math.min(max, Math.max(min, value));\n};\n\n// Every reveal commit re-parses and re-wraps the entire trailing block, so\n// the per-commit cost grows linearly with how far the content is from the\n// last block boundary. Widen the commit interval as that distance grows —\n// long paragraphs/code fences keep total work bounded while short blocks\n// stay at the preset's snappy interval. Per-char animation-delay stagger\n// hides the lower commit rate.\nconst MAX_COMMIT_INTERVAL_MS = 96;\nconst COMMIT_INTERVAL_TAIL_SCALE_UNITS = 256;\n\nconst findTailUnits = (content: string): number => {\n const boundary = content.lastIndexOf('\\n\\n');\n return boundary === -1 ? content.length : content.length - boundary - 2;\n};\n\nexport const countChars = (text: string): number => {\n let count = 0;\n for (const _char of text) count += 1;\n return count;\n};\n\ninterface UseSmoothStreamContentOptions {\n enabled?: boolean;\n preset?: StreamSmoothingPreset;\n}\n\nexport const useSmoothStreamContent = (\n content: string,\n { enabled = true, preset = 'balanced' }: UseSmoothStreamContentOptions = {},\n): string => {\n const config = PRESET_CONFIG[preset];\n const profiler = useStreamdownProfiler();\n const [displayedContent, setDisplayedContent] = useState(content);\n\n const displayedContentRef = useRef(content);\n const displayedCountRef = useRef(countChars(content));\n\n const targetContentRef = useRef(content);\n const targetCharsRef = useRef([...content]);\n const targetCountRef = useRef(targetCharsRef.current.length);\n\n const emaCpsRef = useRef(config.defaultCps);\n const tailUnitsRef = useRef(findTailUnits(content));\n const lastInputTsRef = useRef(0);\n const lastInputCountRef = useRef(targetCountRef.current);\n const chunkSizeEmaRef = useRef(1);\n const arrivalCpsEmaRef = useRef(config.defaultCps);\n\n const rafRef = useRef<number | null>(null);\n const lastFrameTsRef = useRef<number | null>(null);\n const wakeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const clearWakeTimer = useCallback(() => {\n if (wakeTimerRef.current !== null) {\n clearTimeout(wakeTimerRef.current);\n wakeTimerRef.current = null;\n }\n }, []);\n\n const stopFrameLoop = useCallback(() => {\n if (rafRef.current !== null) {\n cancelAnimationFrame(rafRef.current);\n rafRef.current = null;\n }\n lastFrameTsRef.current = null;\n }, []);\n\n const stopScheduling = useCallback(() => {\n stopFrameLoop();\n clearWakeTimer();\n }, [clearWakeTimer, stopFrameLoop]);\n\n const startFrameLoopRef = useRef<() => void>(() => {});\n\n const scheduleFrameWake = useCallback(\n (delayMs: number) => {\n clearWakeTimer();\n\n wakeTimerRef.current = setTimeout(\n () => {\n wakeTimerRef.current = null;\n startFrameLoopRef.current();\n },\n Math.max(1, Math.ceil(delayMs)),\n );\n },\n [clearWakeTimer],\n );\n\n const syncImmediate = useCallback(\n (nextContent: string) => {\n stopScheduling();\n\n const chars = [...nextContent];\n const now = getNow();\n\n targetContentRef.current = nextContent;\n targetCharsRef.current = chars;\n targetCountRef.current = chars.length;\n\n displayedContentRef.current = nextContent;\n displayedCountRef.current = chars.length;\n setDisplayedContent(nextContent);\n\n emaCpsRef.current = config.defaultCps;\n chunkSizeEmaRef.current = 1;\n arrivalCpsEmaRef.current = config.defaultCps;\n tailUnitsRef.current = findTailUnits(nextContent);\n lastInputTsRef.current = now;\n lastInputCountRef.current = chars.length;\n },\n [config.defaultCps, stopScheduling],\n );\n\n const startFrameLoop = useCallback(() => {\n clearWakeTimer();\n if (rafRef.current !== null) return;\n\n const tick = (ts: number) => {\n const targetCount = targetCountRef.current;\n const displayedCount = displayedCountRef.current;\n const backlog = targetCount - displayedCount;\n\n if (backlog <= 0) {\n stopFrameLoop();\n return;\n }\n\n if (lastFrameTsRef.current === null) {\n lastFrameTsRef.current = ts;\n rafRef.current = requestAnimationFrame(tick);\n return;\n }\n\n // Reveal commits are throttled below the display refresh rate: each\n // commit re-renders the tail block and re-runs remend + lexing, so\n // committing at 60-120fps burns CPU without visible benefit — the\n // per-char stagger inside a commit is carried by animation-delay.\n const commitIntervalMs = Math.min(\n MAX_COMMIT_INTERVAL_MS,\n config.minCommitIntervalMs * (1 + tailUnitsRef.current / COMMIT_INTERVAL_TAIL_SCALE_UNITS),\n );\n const frameIntervalMs = Math.max(0, ts - lastFrameTsRef.current);\n if (frameIntervalMs < commitIntervalMs) {\n rafRef.current = requestAnimationFrame(tick);\n return;\n }\n\n const frameStart = getNow();\n const dtSeconds = Math.max(0.001, Math.min(frameIntervalMs / 1000, 0.12));\n lastFrameTsRef.current = ts;\n\n const now = frameStart;\n const idleMs = now - lastInputTsRef.current;\n const inputActive = idleMs <= config.activeInputWindowMs;\n const settling = !inputActive && idleMs >= config.settleAfterMs;\n\n const baseCps = clamp(emaCpsRef.current, config.minCps, config.maxCps);\n const baseLagChars = Math.max(1, Math.round((baseCps * config.targetBufferMs) / 1000));\n const lagUpperBound = Math.max(baseLagChars + 2, baseLagChars * 3);\n const targetLagChars = inputActive\n ? Math.round(\n clamp(baseLagChars + chunkSizeEmaRef.current * 0.35, baseLagChars, lagUpperBound),\n )\n : 0;\n const desiredDisplayed = Math.max(0, targetCount - targetLagChars);\n\n let currentCps: number;\n if (inputActive) {\n const backlogPressure = targetLagChars > 0 ? backlog / targetLagChars : 1;\n const chunkPressure = targetLagChars > 0 ? chunkSizeEmaRef.current / targetLagChars : 1;\n const arrivalPressure = arrivalCpsEmaRef.current / Math.max(baseCps, 1);\n const combinedPressure = clamp(\n backlogPressure * 0.6 + chunkPressure * 0.25 + arrivalPressure * 0.15,\n 1,\n 4.5,\n );\n const activeCap = clamp(\n config.maxActiveCps + chunkSizeEmaRef.current * 6,\n config.maxActiveCps,\n config.maxFlushCps,\n );\n currentCps = clamp(baseCps * combinedPressure, config.minCps, activeCap);\n } else if (settling) {\n // If upstream likely ended, cap the remaining tail duration so\n // we do not keep replaying old backlog for seconds.\n const drainTargetMs = clamp(backlog * 8, config.settleDrainMinMs, config.settleDrainMaxMs);\n const settleCps = (backlog * 1000) / drainTargetMs;\n currentCps = clamp(settleCps, config.flushCps, config.maxFlushCps);\n } else {\n const idleFlushCps = Math.max(\n config.flushCps,\n baseCps * 1.8,\n arrivalCpsEmaRef.current * 0.8,\n );\n currentCps = clamp(idleFlushCps, config.flushCps, config.maxFlushCps);\n }\n\n const urgentBacklog = inputActive && targetLagChars > 0 && backlog > targetLagChars * 2.2;\n const burstyInput = inputActive && chunkSizeEmaRef.current >= targetLagChars * 0.9;\n const minRevealChars = inputActive ? (urgentBacklog || burstyInput ? 2 : 1) : 2;\n let revealChars = Math.max(minRevealChars, Math.round(currentCps * dtSeconds));\n\n if (inputActive) {\n const shortfall = desiredDisplayed - displayedCount;\n if (shortfall <= 0) {\n stopFrameLoop();\n scheduleFrameWake(config.activeInputWindowMs - idleMs);\n\n profiler?.recordAnimationFrame({\n backlog,\n durationMs: getNow() - frameStart,\n frameIntervalMs,\n inputActive,\n revealChars: 0,\n settling,\n });\n return;\n }\n revealChars = Math.min(revealChars, shortfall, backlog);\n } else {\n revealChars = Math.min(revealChars, backlog);\n }\n\n const nextCount = displayedCount + revealChars;\n const segment = targetCharsRef.current.slice(displayedCount, nextCount).join('');\n\n if (segment) {\n const nextDisplayed = displayedContentRef.current + segment;\n displayedContentRef.current = nextDisplayed;\n displayedCountRef.current = nextCount;\n setDisplayedContent(nextDisplayed);\n } else {\n displayedContentRef.current = targetContentRef.current;\n displayedCountRef.current = targetCount;\n setDisplayedContent(targetContentRef.current);\n }\n\n profiler?.recordAnimationFrame({\n backlog,\n durationMs: getNow() - frameStart,\n frameIntervalMs,\n inputActive,\n revealChars: segment ? revealChars : backlog,\n settling,\n });\n\n rafRef.current = requestAnimationFrame(tick);\n };\n\n rafRef.current = requestAnimationFrame(tick);\n }, [\n clearWakeTimer,\n config.activeInputWindowMs,\n config.flushCps,\n config.maxActiveCps,\n config.maxCps,\n config.maxFlushCps,\n config.minCommitIntervalMs,\n config.minCps,\n config.settleAfterMs,\n config.settleDrainMaxMs,\n config.settleDrainMinMs,\n config.targetBufferMs,\n scheduleFrameWake,\n stopFrameLoop,\n ]);\n startFrameLoopRef.current = startFrameLoop;\n\n useEffect(() => {\n if (!enabled) {\n syncImmediate(content);\n return;\n }\n\n const prevTargetContent = targetContentRef.current;\n if (content === prevTargetContent) return;\n\n const now = getNow();\n const appendOnly = content.startsWith(prevTargetContent);\n\n if (!appendOnly) {\n syncImmediate(content);\n return;\n }\n\n // Bypass smoothing entirely while the input ends inside an open\n // fence whose language is opted out — see the preset config.\n // Without this, a 5 KB inline `<style>` block can keep `</style>`\n // (and therefore the HtmlPreview head-close trigger) trapped in the\n // smoother's buffer for tens of seconds, leaving the iframe pinned\n // on the loading placeholder while the artifact \"looks stuck\".\n if (config.bypassFencedLanguages.length > 0) {\n const openLang = findOpenFenceLanguage(content);\n if (openLang !== null && config.bypassFencedLanguages.includes(openLang)) {\n syncImmediate(content);\n return;\n }\n }\n\n const appended = content.slice(prevTargetContent.length);\n const appendedChars = [...appended];\n const appendedCount = appendedChars.length;\n\n profiler?.recordInputAppend({\n appendedChars: appendedCount,\n contentLength: countChars(content),\n });\n\n if (appendedCount > config.largeAppendChars) {\n syncImmediate(content);\n return;\n }\n\n targetContentRef.current = content;\n targetCharsRef.current.push(...appendedChars);\n targetCountRef.current += appendedCount;\n\n tailUnitsRef.current = findTailUnits(content);\n\n const deltaChars = targetCountRef.current - lastInputCountRef.current;\n const deltaMs = Math.max(1, now - lastInputTsRef.current);\n\n if (deltaChars > 0) {\n const instantCps = (deltaChars * 1000) / deltaMs;\n const normalizedInstantCps = clamp(instantCps, config.minCps, config.maxFlushCps * 2);\n const chunkEmaAlpha = 0.35;\n chunkSizeEmaRef.current =\n chunkSizeEmaRef.current * (1 - chunkEmaAlpha) + appendedCount * chunkEmaAlpha;\n arrivalCpsEmaRef.current =\n arrivalCpsEmaRef.current * (1 - chunkEmaAlpha) + normalizedInstantCps * chunkEmaAlpha;\n\n const clampedCps = clamp(instantCps, config.minCps, config.maxActiveCps);\n emaCpsRef.current = emaCpsRef.current * (1 - config.emaAlpha) + clampedCps * config.emaAlpha;\n }\n\n lastInputTsRef.current = now;\n lastInputCountRef.current = targetCountRef.current;\n\n startFrameLoop();\n }, [\n config.bypassFencedLanguages,\n config.emaAlpha,\n config.largeAppendChars,\n config.maxActiveCps,\n config.maxCps,\n config.maxFlushCps,\n config.minCps,\n content,\n enabled,\n startFrameLoop,\n syncImmediate,\n profiler,\n ]);\n\n useEffect(() => {\n return () => {\n stopScheduling();\n };\n }, [stopScheduling]);\n\n return displayedContent;\n};\n"],"mappings":";;;;;AAqCA,MAAM,2BAA2B,CAAC,MAAM;AAExC,MAAM,gBAA4E;CAChF,UAAU;EACR,qBAAqB;EACrB,uBAAuB;EACvB,YAAY;EACZ,UAAU;EACV,UAAU;EACV,kBAAkB;EAClB,cAAc;EACd,QAAQ;EACR,aAAa;EACb,qBAAqB;EACrB,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,kBAAkB;EAClB,gBAAgB;CAClB;CACA,UAAU;EACR,qBAAqB;EACrB,uBAAuB;EACvB,YAAY;EACZ,UAAU;EACV,UAAU;EACV,kBAAkB;EAClB,cAAc;EACd,QAAQ;EACR,aAAa;EACb,qBAAqB;EACrB,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,kBAAkB;EAClB,gBAAgB;CAClB;CACA,OAAO;EACL,qBAAqB;EACrB,uBAAuB;EACvB,YAAY;EACZ,UAAU;EACV,UAAU;EACV,kBAAkB;EAClB,cAAc;EACd,QAAQ;EACR,aAAa;EACb,qBAAqB;EACrB,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,kBAAkB;EAClB,gBAAgB;CAClB;AACF;AAEA,MAAM,SAAS,OAAe,KAAa,QAAwB;CACjE,OAAO,KAAK,IAAI,KAAK,KAAK,IA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IAAI,OAAO,YAAY,aAAa,OAAO;EACtF;EAEA,eAAe,UAAU;EACzB,kBAAkB,UAAU,eAAe;EAE3C,eAAe;CACjB,GAAG;EACD,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,gBAAgB;EACd,aAAa;GACX,eAAe;EACjB;CACF,GAAG,CAAC,cAAc,CAAC;CAEnB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"useSmoothStreamContent.mjs","names":["now"],"sources":["../../../src/Markdown/SyntaxMarkdown/useSmoothStreamContent.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { useStreamdownProfiler } from '@/Markdown/streamProfiler';\nimport { type StreamSmoothingPreset } from '@/Markdown/type';\nimport { getNow } from '@/utils/getNow';\n\nimport { findOpenFenceLanguage } from './fenceState';\n\ninterface StreamSmoothingPresetConfig {\n activeInputWindowMs: number;\n /**\n * Code-fence languages whose contents bypass smoothing entirely. While\n * the input ends inside an open fence in this set, every chunk is\n * `syncImmediate`-d to the display so downstream consumers (the\n * HtmlPreview iframe in particular) see partial HTML at the demo's\n * actual production rate instead of waiting on the smoother's\n * ~maxFlushCps budget. As soon as the fence closes — or another\n * non-bypass fence opens — smoothing resumes for the rest of the\n * stream. Default `['html']` covers the artifact case that motivated\n * this; tune via preset if you need to bypass `mermaid`, `svg`, etc.\n */\n bypassFencedLanguages: readonly string[];\n defaultCps: number;\n emaAlpha: number;\n flushCps: number;\n largeAppendChars: number;\n maxActiveCps: number;\n maxCps: number;\n maxFlushCps: number;\n minCommitIntervalMs: number;\n minCps: number;\n settleAfterMs: number;\n settleDrainMaxMs: number;\n settleDrainMinMs: number;\n targetBufferMs: number;\n}\n\nconst DEFAULT_BYPASS_LANGUAGES = ['html'] as const;\n\nconst PRESET_CONFIG: Record<StreamSmoothingPreset, StreamSmoothingPresetConfig> = {\n balanced: {\n activeInputWindowMs: 220,\n bypassFencedLanguages: DEFAULT_BYPASS_LANGUAGES,\n defaultCps: 38,\n emaAlpha: 0.2,\n flushCps: 120,\n largeAppendChars: 120,\n maxActiveCps: 132,\n maxCps: 72,\n maxFlushCps: 280,\n minCommitIntervalMs: 48,\n minCps: 18,\n settleAfterMs: 360,\n settleDrainMaxMs: 520,\n settleDrainMinMs: 180,\n targetBufferMs: 120,\n },\n realtime: {\n activeInputWindowMs: 140,\n bypassFencedLanguages: DEFAULT_BYPASS_LANGUAGES,\n defaultCps: 50,\n emaAlpha: 0.3,\n flushCps: 170,\n largeAppendChars: 180,\n maxActiveCps: 180,\n maxCps: 96,\n maxFlushCps: 360,\n minCommitIntervalMs: 32,\n minCps: 24,\n settleAfterMs: 260,\n settleDrainMaxMs: 360,\n settleDrainMinMs: 140,\n targetBufferMs: 40,\n },\n silky: {\n activeInputWindowMs: 320,\n bypassFencedLanguages: DEFAULT_BYPASS_LANGUAGES,\n defaultCps: 28,\n emaAlpha: 0.14,\n flushCps: 96,\n largeAppendChars: 100,\n maxActiveCps: 102,\n maxCps: 56,\n maxFlushCps: 220,\n minCommitIntervalMs: 56,\n minCps: 14,\n settleAfterMs: 460,\n settleDrainMaxMs: 680,\n settleDrainMinMs: 240,\n targetBufferMs: 170,\n },\n};\n\nconst clamp = (value: number, min: number, max: number): number => {\n return Math.min(max, Math.max(min, value));\n};\n\n// Every reveal commit re-parses and re-wraps the entire trailing block, so\n// the per-commit cost grows linearly with how far the content is from the\n// last block boundary. Widen the commit interval as that distance grows —\n// long paragraphs/code fences keep total work bounded while short blocks\n// stay at the preset's snappy interval. Per-char animation-delay stagger\n// hides the lower commit rate.\nconst MAX_COMMIT_INTERVAL_MS = 96;\nconst COMMIT_INTERVAL_TAIL_SCALE_UNITS = 256;\n\nconst findTailUnits = (content: string): number => {\n const boundary = content.lastIndexOf('\\n\\n');\n return boundary === -1 ? content.length : content.length - boundary - 2;\n};\n\nexport const countChars = (text: string): number => {\n let count = 0;\n for (const _char of text) count += 1;\n return count;\n};\n\ninterface UseSmoothStreamContentOptions {\n enabled?: boolean;\n preset?: StreamSmoothingPreset;\n}\n\nexport const useSmoothStreamContent = (\n content: string,\n { enabled = true, preset = 'balanced' }: UseSmoothStreamContentOptions = {},\n): string => {\n const config = PRESET_CONFIG[preset];\n const profiler = useStreamdownProfiler();\n const [displayedContent, setDisplayedContent] = useState(content);\n\n const displayedContentRef = useRef(content);\n const displayedCountRef = useRef(countChars(content));\n\n const targetContentRef = useRef(content);\n const targetCharsRef = useRef([...content]);\n const targetCountRef = useRef(targetCharsRef.current.length);\n\n const emaCpsRef = useRef(config.defaultCps);\n const tailUnitsRef = useRef(findTailUnits(content));\n const lastInputTsRef = useRef(0);\n const lastInputCountRef = useRef(targetCountRef.current);\n const chunkSizeEmaRef = useRef(1);\n const arrivalCpsEmaRef = useRef(config.defaultCps);\n\n const rafRef = useRef<number | null>(null);\n const lastFrameTsRef = useRef<number | null>(null);\n const wakeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const clearWakeTimer = useCallback(() => {\n if (wakeTimerRef.current !== null) {\n clearTimeout(wakeTimerRef.current);\n wakeTimerRef.current = null;\n }\n }, []);\n\n const stopFrameLoop = useCallback(() => {\n if (rafRef.current !== null) {\n cancelAnimationFrame(rafRef.current);\n rafRef.current = null;\n }\n lastFrameTsRef.current = null;\n }, []);\n\n const stopScheduling = useCallback(() => {\n stopFrameLoop();\n clearWakeTimer();\n }, [clearWakeTimer, stopFrameLoop]);\n\n const startFrameLoopRef = useRef<() => void>(() => {});\n\n const scheduleFrameWake = useCallback(\n (delayMs: number) => {\n clearWakeTimer();\n\n wakeTimerRef.current = setTimeout(\n () => {\n wakeTimerRef.current = null;\n startFrameLoopRef.current();\n },\n Math.max(1, Math.ceil(delayMs)),\n );\n },\n [clearWakeTimer],\n );\n\n const syncImmediate = useCallback(\n (nextContent: string) => {\n stopScheduling();\n\n const chars = [...nextContent];\n const now = getNow();\n\n targetContentRef.current = nextContent;\n targetCharsRef.current = chars;\n targetCountRef.current = chars.length;\n\n displayedContentRef.current = nextContent;\n displayedCountRef.current = chars.length;\n setDisplayedContent(nextContent);\n\n emaCpsRef.current = config.defaultCps;\n chunkSizeEmaRef.current = 1;\n arrivalCpsEmaRef.current = config.defaultCps;\n tailUnitsRef.current = findTailUnits(nextContent);\n lastInputTsRef.current = now;\n lastInputCountRef.current = chars.length;\n },\n [config.defaultCps, stopScheduling],\n );\n\n const startFrameLoop = useCallback(() => {\n clearWakeTimer();\n if (rafRef.current !== null) return;\n\n const tick = (ts: number) => {\n const targetCount = targetCountRef.current;\n const displayedCount = displayedCountRef.current;\n const backlog = targetCount - displayedCount;\n\n if (backlog <= 0) {\n stopFrameLoop();\n return;\n }\n\n if (lastFrameTsRef.current === null) {\n lastFrameTsRef.current = ts;\n rafRef.current = requestAnimationFrame(tick);\n return;\n }\n\n // Reveal commits are throttled below the display refresh rate: each\n // commit re-renders the tail block and re-runs remend + lexing, so\n // committing at 60-120fps burns CPU without visible benefit — the\n // per-char stagger inside a commit is carried by animation-delay.\n const commitIntervalMs = Math.min(\n MAX_COMMIT_INTERVAL_MS,\n config.minCommitIntervalMs * (1 + tailUnitsRef.current / COMMIT_INTERVAL_TAIL_SCALE_UNITS),\n );\n const frameIntervalMs = Math.max(0, ts - lastFrameTsRef.current);\n if (frameIntervalMs < commitIntervalMs) {\n rafRef.current = requestAnimationFrame(tick);\n return;\n }\n\n const frameStart = getNow();\n const dtSeconds = Math.max(0.001, Math.min(frameIntervalMs / 1000, 0.12));\n lastFrameTsRef.current = ts;\n\n const now = frameStart;\n const idleMs = now - lastInputTsRef.current;\n const inputActive = idleMs <= config.activeInputWindowMs;\n const settling = !inputActive && idleMs >= config.settleAfterMs;\n\n const baseCps = clamp(emaCpsRef.current, config.minCps, config.maxCps);\n const baseLagChars = Math.max(1, Math.round((baseCps * config.targetBufferMs) / 1000));\n const lagUpperBound = Math.max(baseLagChars + 2, baseLagChars * 3);\n const targetLagChars = inputActive\n ? Math.round(\n clamp(baseLagChars + chunkSizeEmaRef.current * 0.35, baseLagChars, lagUpperBound),\n )\n : 0;\n const desiredDisplayed = Math.max(0, targetCount - targetLagChars);\n\n let currentCps: number;\n if (inputActive) {\n const backlogPressure = targetLagChars > 0 ? backlog / targetLagChars : 1;\n const chunkPressure = targetLagChars > 0 ? chunkSizeEmaRef.current / targetLagChars : 1;\n const arrivalPressure = arrivalCpsEmaRef.current / Math.max(baseCps, 1);\n const combinedPressure = clamp(\n backlogPressure * 0.6 + chunkPressure * 0.25 + arrivalPressure * 0.15,\n 1,\n 4.5,\n );\n const activeCap = clamp(\n config.maxActiveCps + chunkSizeEmaRef.current * 6,\n config.maxActiveCps,\n config.maxFlushCps,\n );\n currentCps = clamp(baseCps * combinedPressure, config.minCps, activeCap);\n } else if (settling) {\n // If upstream likely ended, cap the remaining tail duration so\n // we do not keep replaying old backlog for seconds.\n const drainTargetMs = clamp(backlog * 8, config.settleDrainMinMs, config.settleDrainMaxMs);\n const settleCps = (backlog * 1000) / drainTargetMs;\n currentCps = clamp(settleCps, config.flushCps, config.maxFlushCps);\n } else {\n const idleFlushCps = Math.max(\n config.flushCps,\n baseCps * 1.8,\n arrivalCpsEmaRef.current * 0.8,\n );\n currentCps = clamp(idleFlushCps, config.flushCps, config.maxFlushCps);\n }\n\n const urgentBacklog = inputActive && targetLagChars > 0 && backlog > targetLagChars * 2.2;\n const burstyInput = inputActive && chunkSizeEmaRef.current >= targetLagChars * 0.9;\n const minRevealChars = inputActive ? (urgentBacklog || burstyInput ? 2 : 1) : 2;\n let revealChars = Math.max(minRevealChars, Math.round(currentCps * dtSeconds));\n\n if (inputActive) {\n const shortfall = desiredDisplayed - displayedCount;\n if (shortfall <= 0) {\n stopFrameLoop();\n scheduleFrameWake(config.activeInputWindowMs - idleMs);\n\n profiler?.recordAnimationFrame({\n backlog,\n durationMs: getNow() - frameStart,\n frameIntervalMs,\n inputActive,\n revealChars: 0,\n settling,\n });\n return;\n }\n revealChars = Math.min(revealChars, shortfall, backlog);\n } else {\n revealChars = Math.min(revealChars, backlog);\n }\n\n const nextCount = displayedCount + revealChars;\n const segment = targetCharsRef.current.slice(displayedCount, nextCount).join('');\n\n if (segment) {\n const nextDisplayed = displayedContentRef.current + segment;\n displayedContentRef.current = nextDisplayed;\n displayedCountRef.current = nextCount;\n setDisplayedContent(nextDisplayed);\n } else {\n displayedContentRef.current = targetContentRef.current;\n displayedCountRef.current = targetCount;\n setDisplayedContent(targetContentRef.current);\n }\n\n profiler?.recordAnimationFrame({\n backlog,\n durationMs: getNow() - frameStart,\n frameIntervalMs,\n inputActive,\n revealChars: segment ? revealChars : backlog,\n settling,\n });\n\n rafRef.current = requestAnimationFrame(tick);\n };\n\n rafRef.current = requestAnimationFrame(tick);\n }, [\n clearWakeTimer,\n config.activeInputWindowMs,\n config.flushCps,\n config.maxActiveCps,\n config.maxCps,\n config.maxFlushCps,\n config.minCommitIntervalMs,\n config.minCps,\n config.settleAfterMs,\n config.settleDrainMaxMs,\n config.settleDrainMinMs,\n config.targetBufferMs,\n scheduleFrameWake,\n stopFrameLoop,\n ]);\n startFrameLoopRef.current = startFrameLoop;\n\n useEffect(() => {\n if (!enabled) {\n syncImmediate(content);\n return;\n }\n\n const prevTargetContent = targetContentRef.current;\n if (content === prevTargetContent) return;\n\n const now = getNow();\n const appendOnly = content.startsWith(prevTargetContent);\n\n if (!appendOnly) {\n syncImmediate(content);\n return;\n }\n\n // Bypass smoothing entirely while the input ends inside an open\n // fence whose language is opted out — see the preset config.\n // Without this, a 5 KB inline `<style>` block can keep `</style>`\n // (and therefore the HtmlPreview head-close trigger) trapped in the\n // smoother's buffer for tens of seconds, leaving the iframe pinned\n // on the loading placeholder while the artifact \"looks stuck\".\n if (config.bypassFencedLanguages.length > 0) {\n const openLang = findOpenFenceLanguage(content);\n if (openLang !== null && config.bypassFencedLanguages.includes(openLang)) {\n syncImmediate(content);\n return;\n }\n }\n\n const appended = content.slice(prevTargetContent.length);\n const appendedChars = [...appended];\n const appendedCount = appendedChars.length;\n\n profiler?.recordInputAppend({\n appendedChars: appendedCount,\n contentLength: countChars(content),\n });\n\n if (appendedCount > config.largeAppendChars) {\n syncImmediate(content);\n return;\n }\n\n targetContentRef.current = content;\n targetCharsRef.current.push(...appendedChars);\n targetCountRef.current += appendedCount;\n\n tailUnitsRef.current = findTailUnits(content);\n\n const deltaChars = targetCountRef.current - lastInputCountRef.current;\n const deltaMs = Math.max(1, now - lastInputTsRef.current);\n\n if (deltaChars > 0) {\n const instantCps = (deltaChars * 1000) / deltaMs;\n const normalizedInstantCps = clamp(instantCps, config.minCps, config.maxFlushCps * 2);\n const chunkEmaAlpha = 0.35;\n chunkSizeEmaRef.current =\n chunkSizeEmaRef.current * (1 - chunkEmaAlpha) + appendedCount * chunkEmaAlpha;\n arrivalCpsEmaRef.current =\n arrivalCpsEmaRef.current * (1 - chunkEmaAlpha) + normalizedInstantCps * chunkEmaAlpha;\n\n const clampedCps = clamp(instantCps, config.minCps, config.maxActiveCps);\n emaCpsRef.current = emaCpsRef.current * (1 - config.emaAlpha) + clampedCps * config.emaAlpha;\n }\n\n lastInputTsRef.current = now;\n lastInputCountRef.current = targetCountRef.current;\n\n startFrameLoop();\n }, [\n config.bypassFencedLanguages,\n config.emaAlpha,\n config.largeAppendChars,\n config.maxActiveCps,\n config.maxCps,\n config.maxFlushCps,\n config.minCps,\n content,\n enabled,\n startFrameLoop,\n syncImmediate,\n profiler,\n ]);\n\n useEffect(() => {\n return () => {\n stopScheduling();\n };\n }, [stopScheduling]);\n\n return displayedContent;\n};\n"],"mappings":";;;;;AAqCA,MAAM,2BAA2B,CAAC,MAAM;AAExC,MAAM,gBAA4E;CAChF,UAAU;EACR,qBAAqB;EACrB,uBAAuB;EACvB,YAAY;EACZ,UAAU;EACV,UAAU;EACV,kBAAkB;EAClB,cAAc;EACd,QAAQ;EACR,aAAa;EACb,qBAAqB;EACrB,QAAQ;EACR,eAAe;EACf,kBAAkB;EAClB,kBAAkB;EACl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,QAAQ,KAAK,GAAG,aAAa;EAC5C,eAAe,WAAW;EAE1B,aAAa,UAAU,cAAc,OAAO;EAE5C,MAAM,aAAa,eAAe,UAAU,kBAAkB;EAC9D,MAAM,UAAU,KAAK,IAAI,GAAG,MAAM,eAAe,OAAO;EAExD,IAAI,aAAa,GAAG;GAClB,MAAM,aAAc,aAAa,MAAQ;GACzC,MAAM,uBAAuB,MAAM,YAAY,OAAO,QAAQ,OAAO,cAAc,CAAC;GACpF,MAAM,gBAAgB;GACtB,gBAAgB,UACd,gBAAgB,UAAW,MAAqB,gBAAgB;GAClE,iBAAiB,UACf,iBAAiB,UAAW,MAAqB,uBAAuB;GAE1E,MAAM,aAAa,MAAM,YAAY,OAAO,QAAQ,OAAO,YAAY;GACvE,UAAU,UAAU,UAAU,WAAW,IAAI,OAAO,YAAY,aAAa,OAAO;EACtF;EAEA,eAAe,UAAU;EACzB,kBAAkB,UAAU,eAAe;EAE3C,eAAe;CACjB,GAAG;EACD,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,gBAAgB;EACd,aAAa;GACX,eAAe;EACjB;CACF,GAAG,CAAC,cAAc,CAAC;CAEnB,OAAO;AACT"}
|
|
@@ -16,13 +16,14 @@ const RawModalStackItem = memo(({ component: Component, id, onClose, onUpdate, o
|
|
|
16
16
|
}), [close, setCanDismissByClickOutside]);
|
|
17
17
|
const openKey = options?.openKey ?? "open";
|
|
18
18
|
const onCloseKey = options?.onCloseKey ?? "onClose";
|
|
19
|
+
const injectedProps = {
|
|
20
|
+
...props,
|
|
21
|
+
[onCloseKey]: close,
|
|
22
|
+
[openKey]: open
|
|
23
|
+
};
|
|
19
24
|
return /* @__PURE__ */ jsx(ModalProvider, {
|
|
20
25
|
value: contextValue,
|
|
21
|
-
children: /* @__PURE__ */ jsx(Component, {
|
|
22
|
-
...props,
|
|
23
|
-
[onCloseKey]: close,
|
|
24
|
-
[openKey]: open
|
|
25
|
-
})
|
|
26
|
+
children: /* @__PURE__ */ jsx(Component, { ...injectedProps })
|
|
26
27
|
});
|
|
27
28
|
});
|
|
28
29
|
RawModalStackItem.displayName = "RawModalStackItem";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RawModalStackItem.mjs","names":[],"sources":["../../src/Modal/RawModalStackItem.tsx"],"sourcesContent":["'use client';\n\nimport type { ComponentType } from 'react';\nimport { memo, useMemo } from 'react';\n\nimport { useEventCallback } from '@/hooks/useEventCallback';\n\nimport { ModalProvider } from './ModalProvider';\nimport type { ModalContextValue, RawModalOptions } from './type';\n\nexport type RawModalStackItemProps = {\n component: ComponentType<any>;\n id: string;\n onClose: (id: string) => void;\n onUpdate: (id: string, nextProps: Record<string, unknown>) => void;\n open: boolean;\n options?: RawModalOptions<PropertyKey, PropertyKey>;\n props: Record<string, unknown>;\n};\n\nexport const RawModalStackItem = memo(\n ({\n component: Component,\n id,\n onClose,\n onUpdate,\n open,\n options,\n props,\n }: RawModalStackItemProps) => {\n const stableOnClose = useEventCallback(onClose);\n const close = useEventCallback(() => stableOnClose(id));\n\n const setCanDismissByClickOutside = useEventCallback((value: boolean) => {\n onUpdate(id, { mask: { closable: value } });\n });\n const contextValue: ModalContextValue = useMemo(\n () => ({ close, setCanDismissByClickOutside }),\n [close, setCanDismissByClickOutside],\n );\n const openKey = options?.openKey ?? 'open';\n const onCloseKey = options?.onCloseKey ?? 'onClose';\n const injectedProps = {\n ...props,\n [onCloseKey]: close,\n [openKey]: open,\n };\n\n return (\n <ModalProvider value={contextValue}>\n <Component {...injectedProps} />\n </ModalProvider>\n );\n },\n);\n\nRawModalStackItem.displayName = 'RawModalStackItem';\n"],"mappings":";;;;;;AAoBA,MAAa,oBAAoB,MAC9B,EACC,WAAW,WACX,IACA,SACA,UACA,MACA,SACA,YAC4B;CAC5B,MAAM,gBAAgB,iBAAiB,OAAO;CAC9C,MAAM,QAAQ,uBAAuB,cAAc,EAAE,CAAC;CAEtD,MAAM,8BAA8B,kBAAkB,UAAmB;EACvE,SAAS,IAAI,EAAE,MAAM,EAAE,UAAU,MAAM,EAAE,CAAC;CAC5C,CAAC;CACD,MAAM,eAAkC,eAC/B;EAAE;EAAO;CAA4B,IAC5C,CAAC,OAAO,2BAA2B,CACrC;CACA,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,aAAa,SAAS,cAAc;
|
|
1
|
+
{"version":3,"file":"RawModalStackItem.mjs","names":[],"sources":["../../src/Modal/RawModalStackItem.tsx"],"sourcesContent":["'use client';\n\nimport type { ComponentType } from 'react';\nimport { memo, useMemo } from 'react';\n\nimport { useEventCallback } from '@/hooks/useEventCallback';\n\nimport { ModalProvider } from './ModalProvider';\nimport type { ModalContextValue, RawModalOptions } from './type';\n\nexport type RawModalStackItemProps = {\n component: ComponentType<any>;\n id: string;\n onClose: (id: string) => void;\n onUpdate: (id: string, nextProps: Record<string, unknown>) => void;\n open: boolean;\n options?: RawModalOptions<PropertyKey, PropertyKey>;\n props: Record<string, unknown>;\n};\n\nexport const RawModalStackItem = memo(\n ({\n component: Component,\n id,\n onClose,\n onUpdate,\n open,\n options,\n props,\n }: RawModalStackItemProps) => {\n const stableOnClose = useEventCallback(onClose);\n const close = useEventCallback(() => stableOnClose(id));\n\n const setCanDismissByClickOutside = useEventCallback((value: boolean) => {\n onUpdate(id, { mask: { closable: value } });\n });\n const contextValue: ModalContextValue = useMemo(\n () => ({ close, setCanDismissByClickOutside }),\n [close, setCanDismissByClickOutside],\n );\n const openKey = options?.openKey ?? 'open';\n const onCloseKey = options?.onCloseKey ?? 'onClose';\n const injectedProps = {\n ...props,\n [onCloseKey]: close,\n [openKey]: open,\n };\n\n return (\n <ModalProvider value={contextValue}>\n <Component {...injectedProps} />\n </ModalProvider>\n );\n },\n);\n\nRawModalStackItem.displayName = 'RawModalStackItem';\n"],"mappings":";;;;;;AAoBA,MAAa,oBAAoB,MAC9B,EACC,WAAW,WACX,IACA,SACA,UACA,MACA,SACA,YAC4B;CAC5B,MAAM,gBAAgB,iBAAiB,OAAO;CAC9C,MAAM,QAAQ,uBAAuB,cAAc,EAAE,CAAC;CAEtD,MAAM,8BAA8B,kBAAkB,UAAmB;EACvE,SAAS,IAAI,EAAE,MAAM,EAAE,UAAU,MAAM,EAAE,CAAC;CAC5C,CAAC;CACD,MAAM,eAAkC,eAC/B;EAAE;EAAO;CAA4B,IAC5C,CAAC,OAAO,2BAA2B,CACrC;CACA,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,aAAa,SAAS,cAAc;CAC1C,MAAM,gBAAgB;EACpB,GAAG;GACF,aAAa;GACb,UAAU;CACb;CAEA,OACE,oBAAC,eAAD;EAAe,OAAO;EACpB,UAAA,oBAAC,WAAD,EAAW,GAAI,cAAgB,CAAA;CAClB,CAAA;AAEnB,CACF;AAEA,kBAAkB,cAAc"}
|
package/es/Modal/imperative.mjs
CHANGED
|
@@ -24,7 +24,8 @@ const getSnapshot = () => modalStack;
|
|
|
24
24
|
const getServerSnapshot = () => EMPTY_STACK;
|
|
25
25
|
const ModalPortal = ({ children, root }) => {
|
|
26
26
|
const appElement = useAppElement();
|
|
27
|
-
|
|
27
|
+
const container = root ?? appElement ?? document.body;
|
|
28
|
+
return createPortal(children, container);
|
|
28
29
|
};
|
|
29
30
|
const updateModal = (id, nextProps) => {
|
|
30
31
|
let changed = false;
|
|
@@ -135,7 +136,8 @@ const ModalHost = ({ root }) => {
|
|
|
135
136
|
const isClient = useIsClient();
|
|
136
137
|
useEffect(() => {
|
|
137
138
|
if (!isClient) return;
|
|
138
|
-
|
|
139
|
+
const scope = root ?? document.body;
|
|
140
|
+
return registerDevSingleton("ModalHost", scope);
|
|
139
141
|
}, [isClient, root]);
|
|
140
142
|
if (!isClient) return null;
|
|
141
143
|
if (stack.length === 0) return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imperative.mjs","names":[],"sources":["../../src/Modal/imperative.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\nimport { memo, useEffect, useSyncExternalStore } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport { useIsClient } from '@/hooks/useIsClient';\nimport { useAppElement } from '@/ThemeProvider';\nimport { registerDevSingleton } from '@/utils/devSingleton';\n\nimport { ModalStackItem } from './ModalStackItem';\nimport { RawModalStackItem } from './RawModalStackItem';\nimport type {\n ImperativeModalProps,\n ModalInstance,\n RawModalComponent,\n RawModalComponentProps,\n RawModalInstance,\n RawModalKeyOptions,\n RawModalOptions,\n} from './type';\n\ntype ModalStackItemBase = {\n id: string;\n};\n\ntype ModalStackItemModal = ModalStackItemBase & {\n kind: 'modal';\n props: ImperativeModalProps;\n};\n\ntype ModalStackItemRaw = ModalStackItemBase & {\n component: RawModalComponent;\n kind: 'raw';\n open: boolean;\n options?: RawModalOptions<PropertyKey, PropertyKey>;\n props: Record<string, unknown>;\n};\n\ntype TModalStackItem = ModalStackItemModal | ModalStackItemRaw;\n\ntype ModalStackProps = {\n stack: TModalStackItem[];\n};\n\nexport type ModalHostProps = {\n root?: HTMLElement | ShadowRoot | null;\n};\n\nlet modalStack: TModalStackItem[] = [];\nlet modalSeed = 0;\nconst listeners = new Set<() => void>();\nconst rawDestroyTimers = new Map<string, number>();\n\nconst notify = () => {\n listeners.forEach((listener) => listener());\n};\n\nconst subscribe = (listener: () => void) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n};\n\nconst EMPTY_STACK: TModalStackItem[] = [];\nconst getSnapshot = () => modalStack;\nconst getServerSnapshot = () => EMPTY_STACK;\n\nconst ModalPortal = ({\n children,\n root,\n}: {\n children: ReactNode;\n root?: HTMLElement | ShadowRoot | null;\n}) => {\n const appElement = useAppElement();\n const container = root ?? appElement ?? document.body;\n\n return createPortal(children, container);\n};\n\nconst updateModal = (id: string, nextProps: Partial<ImperativeModalProps>) => {\n let changed = false;\n modalStack = modalStack.map((item) => {\n if (item.id !== id) return item;\n if (item.kind !== 'modal') return item;\n changed = true;\n return {\n ...item,\n props: { ...item.props, ...nextProps },\n };\n });\n\n if (changed) notify();\n};\n\nconst updateRawProps = (id: string, nextProps: Record<string, unknown>) => {\n let changed = false;\n modalStack = modalStack.map((item) => {\n if (item.id !== id) return item;\n if (item.kind !== 'raw') return item;\n changed = true;\n return {\n ...item,\n props: { ...item.props, ...nextProps },\n };\n });\n\n if (changed) notify();\n};\n\nconst setRawOpen = (id: string, open: boolean) => {\n let changed = false;\n modalStack = modalStack.map((item) => {\n if (item.id !== id) return item;\n if (item.kind !== 'raw') return item;\n if (item.open === open) return item;\n changed = true;\n return { ...item, open };\n });\n\n if (open) {\n const timer = rawDestroyTimers.get(id);\n if (timer) {\n clearTimeout(timer);\n rawDestroyTimers.delete(id);\n }\n }\n\n if (changed) notify();\n};\n\nconst closeModal = (id: string) => {\n const target = modalStack.find((item) => item.id === id);\n if (!target) return;\n\n if (target.kind === 'modal') {\n updateModal(id, { open: false });\n return;\n }\n\n setRawOpen(id, false);\n\n const shouldDestroy = target.options?.destroyOnClose ?? true;\n if (!shouldDestroy) return;\n\n const delay = target.options?.destroyDelay ?? 200;\n const existing = rawDestroyTimers.get(id);\n if (existing) clearTimeout(existing);\n const timer = window.setTimeout(() => {\n rawDestroyTimers.delete(id);\n\n destroyModal(id);\n }, delay);\n rawDestroyTimers.set(id, timer);\n};\n\nconst destroyModal = (id: string) => {\n const timer = rawDestroyTimers.get(id);\n if (timer) {\n clearTimeout(timer);\n rawDestroyTimers.delete(id);\n }\n const nextStack = modalStack.filter((item) => item.id !== id);\n if (nextStack.length === modalStack.length) return;\n modalStack = nextStack;\n notify();\n};\n\nconst ModalStack = memo(({ stack }: ModalStackProps) => {\n const isClient = useIsClient();\n if (!isClient) return null;\n return stack.map((item) => {\n if (item.kind === 'modal') {\n return (\n <ModalStackItem\n id={item.id}\n key={item.id}\n props={item.props}\n onClose={closeModal}\n onDestroy={destroyModal}\n onUpdate={updateModal}\n />\n );\n }\n\n return (\n <RawModalStackItem\n component={item.component}\n id={item.id}\n key={item.id}\n open={item.open}\n options={item.options}\n props={item.props}\n onClose={closeModal}\n onUpdate={updateRawProps}\n />\n );\n });\n});\n\nModalStack.displayName = 'ModalStack';\n\nexport const ModalHost = ({ root }: ModalHostProps) => {\n const stack = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n const isClient = useIsClient();\n\n useEffect(() => {\n if (!isClient) return;\n // Enforce singleton per portal root (dev-only).\n const scope = root ?? document.body;\n return registerDevSingleton('ModalHost', scope);\n }, [isClient, root]);\n\n if (!isClient) return null;\n if (stack.length === 0) return null;\n\n return (\n <ModalPortal root={root}>\n <ModalStack stack={stack} />\n </ModalPortal>\n );\n};\n\nexport const createModal = (props: ImperativeModalProps): ModalInstance => {\n const id = `modal-${Date.now()}-${modalSeed++}`;\n modalStack = [\n ...modalStack,\n { id, kind: 'modal', props: { ...props, open: props.open ?? true } },\n ];\n notify();\n\n return {\n close: () => closeModal(id),\n destroy: () => destroyModal(id),\n setCanDismissByClickOutside: (value) => updateModal(id, { mask: { closable: value } }),\n update: (nextProps) => updateModal(id, nextProps),\n };\n};\n\nexport function createRawModal<P extends RawModalComponentProps>(\n component: RawModalComponent<P>,\n props: Omit<P, 'open' | 'onClose'>,\n options?: RawModalOptions,\n): RawModalInstance<P>;\n\nexport function createRawModal<P, OpenKey extends keyof P, CloseKey extends keyof P>(\n component: RawModalComponent<P>,\n props: Omit<P, OpenKey | CloseKey>,\n options: RawModalKeyOptions<OpenKey, CloseKey>,\n): RawModalInstance<P, OpenKey, CloseKey>;\n\nexport function createRawModal<P, OpenKey extends keyof P, CloseKey extends keyof P>(\n component: RawModalComponent<P>,\n props: Omit<P, OpenKey | CloseKey>,\n options?: RawModalOptions<OpenKey, CloseKey>,\n): RawModalInstance<P, OpenKey, CloseKey> {\n const id = `modal-${Date.now()}-${modalSeed++}`;\n modalStack = [\n ...modalStack,\n {\n component,\n id,\n kind: 'raw',\n open: true,\n options,\n props: props as Record<string, unknown>,\n },\n ];\n notify();\n\n return {\n close: () => closeModal(id),\n destroy: () => destroyModal(id),\n setCanDismissByClickOutside: (value) => updateRawProps(id, { mask: { closable: value } }),\n update: (nextProps) => updateRawProps(id, nextProps as Record<string, unknown>),\n };\n}\n"],"mappings":";;;;;;;;;;AAiDA,IAAI,aAAgC,CAAC;AACrC,IAAI,YAAY;AAChB,MAAM,4BAAY,IAAI,IAAgB;AACtC,MAAM,mCAAmB,IAAI,IAAoB;AAEjD,MAAM,eAAe;CACnB,UAAU,SAAS,aAAa,SAAS,CAAC;AAC5C;AAEA,MAAM,aAAa,aAAyB;CAC1C,UAAU,IAAI,QAAQ;CACtB,aAAa,UAAU,OAAO,QAAQ;AACxC;AAEA,MAAM,cAAiC,CAAC;AACxC,MAAM,oBAAoB;AAC1B,MAAM,0BAA0B;AAEhC,MAAM,eAAe,EACnB,UACA,WAII;CACJ,MAAM,aAAa,cAAc;CAGjC,OAAO,aAAa,UAFF,QAAQ,cAAc,SAAS,IAEV;AACzC;AAEA,MAAM,eAAe,IAAY,cAA6C;CAC5E,IAAI,UAAU;CACd,aAAa,WAAW,KAAK,SAAS;EACpC,IAAI,KAAK,OAAO,IAAI,OAAO;EAC3B,IAAI,KAAK,SAAS,SAAS,OAAO;EAClC,UAAU;EACV,OAAO;GACL,GAAG;GACH,OAAO;IAAE,GAAG,KAAK;IAAO,GAAG;GAAU;EACvC;CACF,CAAC;CAED,IAAI,SAAS,OAAO;AACtB;AAEA,MAAM,kBAAkB,IAAY,cAAuC;CACzE,IAAI,UAAU;CACd,aAAa,WAAW,KAAK,SAAS;EACpC,IAAI,KAAK,OAAO,IAAI,OAAO;EAC3B,IAAI,KAAK,SAAS,OAAO,OAAO;EAChC,UAAU;EACV,OAAO;GACL,GAAG;GACH,OAAO;IAAE,GAAG,KAAK;IAAO,GAAG;GAAU;EACvC;CACF,CAAC;CAED,IAAI,SAAS,OAAO;AACtB;AAEA,MAAM,cAAc,IAAY,SAAkB;CAChD,IAAI,UAAU;CACd,aAAa,WAAW,KA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CACA,OAAO;CAEP,OAAO;EACL,aAAa,WAAW,EAAE;EAC1B,eAAe,aAAa,EAAE;EAC9B,8BAA8B,UAAU,eAAe,IAAI,EAAE,MAAM,EAAE,UAAU,MAAM,EAAE,CAAC;EACxF,SAAS,cAAc,eAAe,IAAI,SAAoC;CAChF;AACF"}
|
|
1
|
+
{"version":3,"file":"imperative.mjs","names":[],"sources":["../../src/Modal/imperative.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\nimport { memo, useEffect, useSyncExternalStore } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport { useIsClient } from '@/hooks/useIsClient';\nimport { useAppElement } from '@/ThemeProvider';\nimport { registerDevSingleton } from '@/utils/devSingleton';\n\nimport { ModalStackItem } from './ModalStackItem';\nimport { RawModalStackItem } from './RawModalStackItem';\nimport type {\n ImperativeModalProps,\n ModalInstance,\n RawModalComponent,\n RawModalComponentProps,\n RawModalInstance,\n RawModalKeyOptions,\n RawModalOptions,\n} from './type';\n\ntype ModalStackItemBase = {\n id: string;\n};\n\ntype ModalStackItemModal = ModalStackItemBase & {\n kind: 'modal';\n props: ImperativeModalProps;\n};\n\ntype ModalStackItemRaw = ModalStackItemBase & {\n component: RawModalComponent;\n kind: 'raw';\n open: boolean;\n options?: RawModalOptions<PropertyKey, PropertyKey>;\n props: Record<string, unknown>;\n};\n\ntype TModalStackItem = ModalStackItemModal | ModalStackItemRaw;\n\ntype ModalStackProps = {\n stack: TModalStackItem[];\n};\n\nexport type ModalHostProps = {\n root?: HTMLElement | ShadowRoot | null;\n};\n\nlet modalStack: TModalStackItem[] = [];\nlet modalSeed = 0;\nconst listeners = new Set<() => void>();\nconst rawDestroyTimers = new Map<string, number>();\n\nconst notify = () => {\n listeners.forEach((listener) => listener());\n};\n\nconst subscribe = (listener: () => void) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n};\n\nconst EMPTY_STACK: TModalStackItem[] = [];\nconst getSnapshot = () => modalStack;\nconst getServerSnapshot = () => EMPTY_STACK;\n\nconst ModalPortal = ({\n children,\n root,\n}: {\n children: ReactNode;\n root?: HTMLElement | ShadowRoot | null;\n}) => {\n const appElement = useAppElement();\n const container = root ?? appElement ?? document.body;\n\n return createPortal(children, container);\n};\n\nconst updateModal = (id: string, nextProps: Partial<ImperativeModalProps>) => {\n let changed = false;\n modalStack = modalStack.map((item) => {\n if (item.id !== id) return item;\n if (item.kind !== 'modal') return item;\n changed = true;\n return {\n ...item,\n props: { ...item.props, ...nextProps },\n };\n });\n\n if (changed) notify();\n};\n\nconst updateRawProps = (id: string, nextProps: Record<string, unknown>) => {\n let changed = false;\n modalStack = modalStack.map((item) => {\n if (item.id !== id) return item;\n if (item.kind !== 'raw') return item;\n changed = true;\n return {\n ...item,\n props: { ...item.props, ...nextProps },\n };\n });\n\n if (changed) notify();\n};\n\nconst setRawOpen = (id: string, open: boolean) => {\n let changed = false;\n modalStack = modalStack.map((item) => {\n if (item.id !== id) return item;\n if (item.kind !== 'raw') return item;\n if (item.open === open) return item;\n changed = true;\n return { ...item, open };\n });\n\n if (open) {\n const timer = rawDestroyTimers.get(id);\n if (timer) {\n clearTimeout(timer);\n rawDestroyTimers.delete(id);\n }\n }\n\n if (changed) notify();\n};\n\nconst closeModal = (id: string) => {\n const target = modalStack.find((item) => item.id === id);\n if (!target) return;\n\n if (target.kind === 'modal') {\n updateModal(id, { open: false });\n return;\n }\n\n setRawOpen(id, false);\n\n const shouldDestroy = target.options?.destroyOnClose ?? true;\n if (!shouldDestroy) return;\n\n const delay = target.options?.destroyDelay ?? 200;\n const existing = rawDestroyTimers.get(id);\n if (existing) clearTimeout(existing);\n const timer = window.setTimeout(() => {\n rawDestroyTimers.delete(id);\n\n destroyModal(id);\n }, delay);\n rawDestroyTimers.set(id, timer);\n};\n\nconst destroyModal = (id: string) => {\n const timer = rawDestroyTimers.get(id);\n if (timer) {\n clearTimeout(timer);\n rawDestroyTimers.delete(id);\n }\n const nextStack = modalStack.filter((item) => item.id !== id);\n if (nextStack.length === modalStack.length) return;\n modalStack = nextStack;\n notify();\n};\n\nconst ModalStack = memo(({ stack }: ModalStackProps) => {\n const isClient = useIsClient();\n if (!isClient) return null;\n return stack.map((item) => {\n if (item.kind === 'modal') {\n return (\n <ModalStackItem\n id={item.id}\n key={item.id}\n props={item.props}\n onClose={closeModal}\n onDestroy={destroyModal}\n onUpdate={updateModal}\n />\n );\n }\n\n return (\n <RawModalStackItem\n component={item.component}\n id={item.id}\n key={item.id}\n open={item.open}\n options={item.options}\n props={item.props}\n onClose={closeModal}\n onUpdate={updateRawProps}\n />\n );\n });\n});\n\nModalStack.displayName = 'ModalStack';\n\nexport const ModalHost = ({ root }: ModalHostProps) => {\n const stack = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n const isClient = useIsClient();\n\n useEffect(() => {\n if (!isClient) return;\n // Enforce singleton per portal root (dev-only).\n const scope = root ?? document.body;\n return registerDevSingleton('ModalHost', scope);\n }, [isClient, root]);\n\n if (!isClient) return null;\n if (stack.length === 0) return null;\n\n return (\n <ModalPortal root={root}>\n <ModalStack stack={stack} />\n </ModalPortal>\n );\n};\n\nexport const createModal = (props: ImperativeModalProps): ModalInstance => {\n const id = `modal-${Date.now()}-${modalSeed++}`;\n modalStack = [\n ...modalStack,\n { id, kind: 'modal', props: { ...props, open: props.open ?? true } },\n ];\n notify();\n\n return {\n close: () => closeModal(id),\n destroy: () => destroyModal(id),\n setCanDismissByClickOutside: (value) => updateModal(id, { mask: { closable: value } }),\n update: (nextProps) => updateModal(id, nextProps),\n };\n};\n\nexport function createRawModal<P extends RawModalComponentProps>(\n component: RawModalComponent<P>,\n props: Omit<P, 'open' | 'onClose'>,\n options?: RawModalOptions,\n): RawModalInstance<P>;\n\nexport function createRawModal<P, OpenKey extends keyof P, CloseKey extends keyof P>(\n component: RawModalComponent<P>,\n props: Omit<P, OpenKey | CloseKey>,\n options: RawModalKeyOptions<OpenKey, CloseKey>,\n): RawModalInstance<P, OpenKey, CloseKey>;\n\nexport function createRawModal<P, OpenKey extends keyof P, CloseKey extends keyof P>(\n component: RawModalComponent<P>,\n props: Omit<P, OpenKey | CloseKey>,\n options?: RawModalOptions<OpenKey, CloseKey>,\n): RawModalInstance<P, OpenKey, CloseKey> {\n const id = `modal-${Date.now()}-${modalSeed++}`;\n modalStack = [\n ...modalStack,\n {\n component,\n id,\n kind: 'raw',\n open: true,\n options,\n props: props as Record<string, unknown>,\n },\n ];\n notify();\n\n return {\n close: () => closeModal(id),\n destroy: () => destroyModal(id),\n setCanDismissByClickOutside: (value) => updateRawProps(id, { mask: { closable: value } }),\n update: (nextProps) => updateRawProps(id, nextProps as Record<string, unknown>),\n };\n}\n"],"mappings":";;;;;;;;;;AAiDA,IAAI,aAAgC,CAAC;AACrC,IAAI,YAAY;AAChB,MAAM,4BAAY,IAAI,IAAgB;AACtC,MAAM,mCAAmB,IAAI,IAAoB;AAEjD,MAAM,eAAe;CACnB,UAAU,SAAS,aAAa,SAAS,CAAC;AAC5C;AAEA,MAAM,aAAa,aAAyB;CAC1C,UAAU,IAAI,QAAQ;CACtB,aAAa,UAAU,OAAO,QAAQ;AACxC;AAEA,MAAM,cAAiC,CAAC;AACxC,MAAM,oBAAoB;AAC1B,MAAM,0BAA0B;AAEhC,MAAM,eAAe,EACnB,UACA,WAII;CACJ,MAAM,aAAa,cAAc;CACjC,MAAM,YAAY,QAAQ,cAAc,SAAS;CAEjD,OAAO,aAAa,UAAU,SAAS;AACzC;AAEA,MAAM,eAAe,IAAY,cAA6C;CAC5E,IAAI,UAAU;CACd,aAAa,WAAW,KAAK,SAAS;EACpC,IAAI,KAAK,OAAO,IAAI,OAAO;EAC3B,IAAI,KAAK,SAAS,SAAS,OAAO;EAClC,UAAU;EACV,OAAO;GACL,GAAG;GACH,OAAO;IAAE,GAAG,KAAK;IAAO,GAAG;GAAU;EACvC;CACF,CAAC;CAED,IAAI,SAAS,OAAO;AACtB;AAEA,MAAM,kBAAkB,IAAY,cAAuC;CACzE,IAAI,UAAU;CACd,a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EAAE;EAC1B,eAAe,aAAa,EAAE;EAC9B,8BAA8B,UAAU,YAAY,IAAI,EAAE,MAAM,EAAE,UAAU,MAAM,EAAE,CAAC;EACrF,SAAS,cAAc,YAAY,IAAI,SAAS;CAClD;AACF;AAcA,SAAgB,eACd,WACA,OACA,SACwC;CACxC,MAAM,KAAK,SAAS,KAAK,IAAI,EAAE,GAAG;CAClC,aAAa,CACX,GAAG,YACH;EACE;EACA;EACA,MAAM;EACN,MAAM;EACN;EACO;CACT,CACF;CACA,OAAO;CAEP,OAAO;EACL,aAAa,WAAW,EAAE;EAC1B,eAAe,aAAa,EAAE;EAC9B,8BAA8B,UAAU,eAAe,IAAI,EAAE,MAAM,EAAE,UAAU,MAAM,EAAE,CAAC;EACxF,SAAS,cAAc,eAAe,IAAI,SAAoC;CAChF;AACF"}
|
|
@@ -74,7 +74,7 @@ const NeuralNetworkLoading = memo(({ size = 16, className, style }) => {
|
|
|
74
74
|
}, `node-${layerIndex}-${nodeIndex}`));
|
|
75
75
|
}
|
|
76
76
|
const connections = [];
|
|
77
|
-
for (let layerIndex = 0; layerIndex <
|
|
77
|
+
for (let layerIndex = 0; layerIndex < 2; layerIndex++) for (let nodeIndex = 0; nodeIndex < NODE_COUNT; nodeIndex++) {
|
|
78
78
|
const x1 = 25 + layerIndex * 25;
|
|
79
79
|
const y1 = 25 + nodeIndex * 25;
|
|
80
80
|
for (let targetIndex = 0; targetIndex < NODE_COUNT; targetIndex++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NeuralNetworkLoading.mjs","names":[],"sources":["../../src/NeuralNetworkLoading/NeuralNetworkLoading.tsx"],"sourcesContent":["'use client';\n\nimport { createStaticStyles, keyframes } from 'antd-style';\nimport { type CSSProperties, memo } from 'react';\n\nimport type { NeuralNetworkLoadingProps } from './type';\n\nconst pulseAnim = keyframes`\n 0%, 100% { opacity: 0.3; }\n 50% { opacity: 1; }\n`;\n\nconst flowAnim = keyframes`\n 0% { transform: translateX(0); opacity: 0.5; }\n 50% { opacity: 1; }\n 100% { transform: translateX(var(--flow-distance)); opacity: 0.5; }\n`;\n\nconst rotateAnim = keyframes`\n 100% { transform: rotate(360deg); }\n`;\n\nconst scaleAnim = keyframes`\n 0%, 100% { transform: scale(0.8); opacity: 0.5; }\n 50% { transform: scale(1); opacity: 1; }\n`;\n\nconst styles = createStaticStyles(({ css, cssVar }) => ({\n center: css`\n fill: ${cssVar.colorTextSecondary};\n animation: ${scaleAnim} 2s infinite;\n `,\n connection: css`\n opacity: 0.3;\n stroke: ${cssVar.colorTextSecondary};\n stroke-width: 0.5;\n `,\n container: css`\n display: flex;\n align-items: center;\n justify-content: center;\n `,\n node: css`\n fill: ${cssVar.colorTextSecondary};\n animation: ${pulseAnim} 2s infinite;\n `,\n particle: css`\n fill: ${cssVar.colorTextSecondary};\n animation: ${flowAnim} 2s infinite;\n `,\n ring: css`\n transform-origin: center;\n\n fill: none;\n stroke: ${cssVar.colorFill};\n stroke-dasharray: 0 8;\n stroke-width: 1;\n\n animation: ${rotateAnim} 20s infinite linear;\n `,\n svg: css`\n width: 100%;\n height: 100%;\n `,\n}));\n\nconst LAYER_COUNT = 3;\nconst NODE_COUNT = 3;\n\nconst NeuralNetworkLoading = memo<NeuralNetworkLoadingProps>(({ size = 16, className, style }) => {\n const nodes = [];\n for (let layerIndex = 0; layerIndex < LAYER_COUNT; layerIndex++) {\n for (let nodeIndex = 0; nodeIndex < NODE_COUNT; nodeIndex++) {\n const x = 25 + layerIndex * 25;\n const y = 25 + nodeIndex * 25;\n const delay = (layerIndex * NODE_COUNT + nodeIndex) * 0.2;\n nodes.push(\n <circle\n className={styles.node}\n cx={x}\n cy={y}\n key={`node-${layerIndex}-${nodeIndex}`}\n r=\"3\"\n style={{ animationDelay: `${delay}s` }}\n />,\n );\n }\n }\n\n const connections = [];\n for (let layerIndex = 0; layerIndex < LAYER_COUNT - 1; layerIndex++) {\n for (let nodeIndex = 0; nodeIndex < NODE_COUNT; nodeIndex++) {\n const x1 = 25 + layerIndex * 25;\n const y1 = 25 + nodeIndex * 25;\n for (let targetIndex = 0; targetIndex < NODE_COUNT; targetIndex++) {\n const x2 = 25 + (layerIndex + 1) * 25;\n const y2 = 25 + targetIndex * 25;\n connections.push(\n <line\n className={styles.connection}\n key={`connection-${layerIndex}-${nodeIndex}-${targetIndex}`}\n x1={x1}\n x2={x2}\n y1={y1}\n y2={y2}\n />,\n );\n }\n }\n }\n\n const particles = [0, 1, 2].map((index) => (\n <circle\n className={styles.particle}\n cx={25}\n cy={50}\n key={`particle-${index}`}\n r=\"1.5\"\n style={\n {\n '--flow-distance': '50px',\n 'animationDelay': `${index * 0.6}s`,\n } as CSSProperties\n }\n />\n ));\n\n return (\n <div\n className={[styles.container, className].filter(Boolean).join(' ')}\n style={{ height: size, width: size, ...style }}\n >\n <svg className={styles.svg} viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">\n {connections}\n {nodes}\n {particles}\n <rect className={styles.center} height=\"6\" width=\"6\" x=\"47\" y=\"47\" />\n <circle className={styles.ring} cx=\"50\" cy=\"50\" r=\"40\" />\n </svg>\n </div>\n );\n});\n\nNeuralNetworkLoading.displayName = 'NeuralNetworkLoading';\n\nexport default NeuralNetworkLoading;\n"],"mappings":";;;;;AAOA,MAAM,YAAY,SAAS;;;;AAK3B,MAAM,WAAW,SAAS;;;;;AAM1B,MAAM,aAAa,SAAS;;;AAI5B,MAAM,YAAY,SAAS;;;;AAK3B,MAAM,SAAS,oBAAoB,EAAE,KAAK,cAAc;CACtD,QAAQ,GAAG;YACD,OAAO,mBAAmB;iBACrB,UAAU;;CAEzB,YAAY,GAAG;;cAEH,OAAO,mBAAmB;;;CAGtC,WAAW,GAAG;;;;;CAKd,MAAM,GAAG;YACC,OAAO,mBAAmB;iBACrB,UAAU;;CAEzB,UAAU,GAAG;YACH,OAAO,mBAAmB;iBACrB,SAAS;;CAExB,MAAM,GAAG;;;;cAIG,OAAO,UAAU;;;;iBAId,WAAW;;CAE1B,KAAK,GAAG;;;;AAIV,EAAE;AAEF,MAAM,cAAc;AACpB,MAAM,aAAa;AAEnB,MAAM,uBAAuB,MAAiC,EAAE,OAAO,IAAI,WAAW,YAAY;CAChG,MAAM,QAAQ,CAAC;CACf,KAAK,IAAI,aAAa,GAAG,aAAa,aAAa,cACjD,KAAK,IAAI,YAAY,GAAG,YAAY,YAAY,aAAa;EAC3D,MAAM,IAAI,KAAK,aAAa;EAC5B,MAAM,IAAI,KAAK,YAAY;EAC3B,MAAM,SAAS,aAAa,aAAa,aAAa;EACtD,MAAM,KACJ,oBAAC,UAAD;GACE,WAAW,OAAO;GAClB,IAAI;GACJ,IAAI;GAEJ,GAAE;GACF,OAAO,EAAE,gBAAgB,GAAG,MAAM,GAAG;EACtC,GAHM,QAAQ,WAAW,GAAG,WAG5B,CACH;CACF;CAGF,MAAM,cAAc,CAAC;CACrB,KAAK,IAAI,aAAa,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"NeuralNetworkLoading.mjs","names":[],"sources":["../../src/NeuralNetworkLoading/NeuralNetworkLoading.tsx"],"sourcesContent":["'use client';\n\nimport { createStaticStyles, keyframes } from 'antd-style';\nimport { type CSSProperties, memo } from 'react';\n\nimport type { NeuralNetworkLoadingProps } from './type';\n\nconst pulseAnim = keyframes`\n 0%, 100% { opacity: 0.3; }\n 50% { opacity: 1; }\n`;\n\nconst flowAnim = keyframes`\n 0% { transform: translateX(0); opacity: 0.5; }\n 50% { opacity: 1; }\n 100% { transform: translateX(var(--flow-distance)); opacity: 0.5; }\n`;\n\nconst rotateAnim = keyframes`\n 100% { transform: rotate(360deg); }\n`;\n\nconst scaleAnim = keyframes`\n 0%, 100% { transform: scale(0.8); opacity: 0.5; }\n 50% { transform: scale(1); opacity: 1; }\n`;\n\nconst styles = createStaticStyles(({ css, cssVar }) => ({\n center: css`\n fill: ${cssVar.colorTextSecondary};\n animation: ${scaleAnim} 2s infinite;\n `,\n connection: css`\n opacity: 0.3;\n stroke: ${cssVar.colorTextSecondary};\n stroke-width: 0.5;\n `,\n container: css`\n display: flex;\n align-items: center;\n justify-content: center;\n `,\n node: css`\n fill: ${cssVar.colorTextSecondary};\n animation: ${pulseAnim} 2s infinite;\n `,\n particle: css`\n fill: ${cssVar.colorTextSecondary};\n animation: ${flowAnim} 2s infinite;\n `,\n ring: css`\n transform-origin: center;\n\n fill: none;\n stroke: ${cssVar.colorFill};\n stroke-dasharray: 0 8;\n stroke-width: 1;\n\n animation: ${rotateAnim} 20s infinite linear;\n `,\n svg: css`\n width: 100%;\n height: 100%;\n `,\n}));\n\nconst LAYER_COUNT = 3;\nconst NODE_COUNT = 3;\n\nconst NeuralNetworkLoading = memo<NeuralNetworkLoadingProps>(({ size = 16, className, style }) => {\n const nodes = [];\n for (let layerIndex = 0; layerIndex < LAYER_COUNT; layerIndex++) {\n for (let nodeIndex = 0; nodeIndex < NODE_COUNT; nodeIndex++) {\n const x = 25 + layerIndex * 25;\n const y = 25 + nodeIndex * 25;\n const delay = (layerIndex * NODE_COUNT + nodeIndex) * 0.2;\n nodes.push(\n <circle\n className={styles.node}\n cx={x}\n cy={y}\n key={`node-${layerIndex}-${nodeIndex}`}\n r=\"3\"\n style={{ animationDelay: `${delay}s` }}\n />,\n );\n }\n }\n\n const connections = [];\n for (let layerIndex = 0; layerIndex < LAYER_COUNT - 1; layerIndex++) {\n for (let nodeIndex = 0; nodeIndex < NODE_COUNT; nodeIndex++) {\n const x1 = 25 + layerIndex * 25;\n const y1 = 25 + nodeIndex * 25;\n for (let targetIndex = 0; targetIndex < NODE_COUNT; targetIndex++) {\n const x2 = 25 + (layerIndex + 1) * 25;\n const y2 = 25 + targetIndex * 25;\n connections.push(\n <line\n className={styles.connection}\n key={`connection-${layerIndex}-${nodeIndex}-${targetIndex}`}\n x1={x1}\n x2={x2}\n y1={y1}\n y2={y2}\n />,\n );\n }\n }\n }\n\n const particles = [0, 1, 2].map((index) => (\n <circle\n className={styles.particle}\n cx={25}\n cy={50}\n key={`particle-${index}`}\n r=\"1.5\"\n style={\n {\n '--flow-distance': '50px',\n 'animationDelay': `${index * 0.6}s`,\n } as CSSProperties\n }\n />\n ));\n\n return (\n <div\n className={[styles.container, className].filter(Boolean).join(' ')}\n style={{ height: size, width: size, ...style }}\n >\n <svg className={styles.svg} viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">\n {connections}\n {nodes}\n {particles}\n <rect className={styles.center} height=\"6\" width=\"6\" x=\"47\" y=\"47\" />\n <circle className={styles.ring} cx=\"50\" cy=\"50\" r=\"40\" />\n </svg>\n </div>\n );\n});\n\nNeuralNetworkLoading.displayName = 'NeuralNetworkLoading';\n\nexport default NeuralNetworkLoading;\n"],"mappings":";;;;;AAOA,MAAM,YAAY,SAAS;;;;AAK3B,MAAM,WAAW,SAAS;;;;;AAM1B,MAAM,aAAa,SAAS;;;AAI5B,MAAM,YAAY,SAAS;;;;AAK3B,MAAM,SAAS,oBAAoB,EAAE,KAAK,cAAc;CACtD,QAAQ,GAAG;YACD,OAAO,mBAAmB;iBACrB,UAAU;;CAEzB,YAAY,GAAG;;cAEH,OAAO,mBAAmB;;;CAGtC,WAAW,GAAG;;;;;CAKd,MAAM,GAAG;YACC,OAAO,mBAAmB;iBACrB,UAAU;;CAEzB,UAAU,GAAG;YACH,OAAO,mBAAmB;iBACrB,SAAS;;CAExB,MAAM,GAAG;;;;cAIG,OAAO,UAAU;;;;iBAId,WAAW;;CAE1B,KAAK,GAAG;;;;AAIV,EAAE;AAEF,MAAM,cAAc;AACpB,MAAM,aAAa;AAEnB,MAAM,uBAAuB,MAAiC,EAAE,OAAO,IAAI,WAAW,YAAY;CAChG,MAAM,QAAQ,CAAC;CACf,KAAK,IAAI,aAAa,GAAG,aAAa,aAAa,cACjD,KAAK,IAAI,YAAY,GAAG,YAAY,YAAY,aAAa;EAC3D,MAAM,IAAI,KAAK,aAAa;EAC5B,MAAM,IAAI,KAAK,YAAY;EAC3B,MAAM,SAAS,aAAa,aAAa,aAAa;EAC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AAK,IAAG;KAAK,GAAE;IAAM,CAAA;GACrD;;CACF,CAAA;AAET,CAAC;AAED,qBAAqB,cAAc"}
|
|
@@ -48,22 +48,23 @@ const ScrollShadow = ({ className, children, orientation = "vertical", hideScrol
|
|
|
48
48
|
else if (finalScrollState.right) attributes["data-right-scroll"] = true;
|
|
49
49
|
return attributes;
|
|
50
50
|
}, [orientation, finalScrollState]);
|
|
51
|
+
const scrollPosition = useMemo(() => {
|
|
52
|
+
if (orientation === "vertical") {
|
|
53
|
+
if (finalScrollState.top && finalScrollState.bottom) return "top-bottom";
|
|
54
|
+
if (finalScrollState.top) return "top";
|
|
55
|
+
if (finalScrollState.bottom) return "bottom";
|
|
56
|
+
} else {
|
|
57
|
+
if (finalScrollState.left && finalScrollState.right) return "left-right";
|
|
58
|
+
if (finalScrollState.left) return "left";
|
|
59
|
+
if (finalScrollState.right) return "right";
|
|
60
|
+
}
|
|
61
|
+
return "none";
|
|
62
|
+
}, [orientation, finalScrollState]);
|
|
51
63
|
return /* @__PURE__ */ jsx(FlexBasic_default, {
|
|
52
64
|
className: cx(variants({
|
|
53
65
|
hideScrollBar,
|
|
54
66
|
orientation,
|
|
55
|
-
scrollPosition
|
|
56
|
-
if (orientation === "vertical") {
|
|
57
|
-
if (finalScrollState.top && finalScrollState.bottom) return "top-bottom";
|
|
58
|
-
if (finalScrollState.top) return "top";
|
|
59
|
-
if (finalScrollState.bottom) return "bottom";
|
|
60
|
-
} else {
|
|
61
|
-
if (finalScrollState.left && finalScrollState.right) return "left-right";
|
|
62
|
-
if (finalScrollState.left) return "left";
|
|
63
|
-
if (finalScrollState.right) return "right";
|
|
64
|
-
}
|
|
65
|
-
return "none";
|
|
66
|
-
}, [orientation, finalScrollState])
|
|
67
|
+
scrollPosition
|
|
67
68
|
}), className),
|
|
68
69
|
ref: mergeRefs([domRef, ref]),
|
|
69
70
|
style: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollShadow.mjs","names":["Flexbox"],"sources":["../../src/ScrollShadow/ScrollShadow.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport type { FC } from 'react';\nimport { useMemo, useRef } from 'react';\nimport { mergeRefs } from 'react-merge-refs';\n\nimport { Flexbox } from '@/Flex';\nimport { useEventCallback } from '@/hooks/useEventCallback';\n\nimport { variants } from './style';\nimport type { ScrollShadowProps } from './type';\nimport { useScrollOverflow } from './useScrollOverflow';\n\nconst ScrollShadow: FC<ScrollShadowProps> = ({\n className,\n children,\n orientation = 'vertical',\n hideScrollBar = false,\n size = 16,\n offset = 8,\n visibility = 'auto',\n isEnabled = true,\n onVisibilityChange,\n style,\n ref,\n ...rest\n}) => {\n // Convert size prop to CSS variable\n const cssVariables = useMemo<Record<string, string>>(\n () => ({\n '--scroll-shadow-size': `${size}%`,\n }),\n [size],\n );\n const domRef = useRef<HTMLDivElement>(null);\n\n const onVisibilityChangeEvent = useEventCallback<\n NonNullable<ScrollShadowProps['onVisibilityChange']>\n >((visibility) => {\n onVisibilityChange?.(visibility);\n });\n // 使用滚动检测钩子\n const scrollState = useScrollOverflow({\n domRef,\n isEnabled: isEnabled && visibility === 'auto',\n offset,\n onVisibilityChange: onVisibilityChangeEvent,\n orientation,\n updateDeps: [children],\n });\n\n // 决定最终的滚动状态\n const finalScrollState = useMemo(() => {\n if (visibility === 'always') {\n return {\n bottom: true,\n left: true,\n right: true,\n top: true,\n };\n }\n\n if (visibility === 'never') {\n return {\n bottom: false,\n left: false,\n right: false,\n top: false,\n };\n }\n\n return scrollState;\n }, [visibility, scrollState]);\n\n // 计算数据属性\n const dataAttributes = useMemo(() => {\n const attributes: Record<string, boolean | string> = {\n 'data-orientation': orientation,\n };\n\n if (orientation === 'vertical') {\n if (finalScrollState.top && finalScrollState.bottom) {\n attributes['data-top-bottom-scroll'] = true;\n } else if (finalScrollState.top) {\n attributes['data-top-scroll'] = true;\n } else if (finalScrollState.bottom) {\n attributes['data-bottom-scroll'] = true;\n }\n } else {\n if (finalScrollState.left && finalScrollState.right) {\n attributes['data-left-right-scroll'] = true;\n } else if (finalScrollState.left) {\n attributes['data-left-scroll'] = true;\n } else if (finalScrollState.right) {\n attributes['data-right-scroll'] = true;\n }\n }\n\n return attributes;\n }, [orientation, finalScrollState]);\n\n // 计算滚动位置变体\n const scrollPosition = useMemo(() => {\n if (orientation === 'vertical') {\n if (finalScrollState.top && finalScrollState.bottom) return 'top-bottom';\n if (finalScrollState.top) return 'top';\n if (finalScrollState.bottom) return 'bottom';\n } else {\n if (finalScrollState.left && finalScrollState.right) return 'left-right';\n if (finalScrollState.left) return 'left';\n if (finalScrollState.right) return 'right';\n }\n return 'none';\n }, [orientation, finalScrollState]);\n\n return (\n <Flexbox\n className={cx(variants({ hideScrollBar, orientation, scrollPosition }), className)}\n ref={mergeRefs<HTMLDivElement>([domRef, ref])}\n style={{\n ...cssVariables,\n ...style,\n }}\n {...dataAttributes}\n {...rest}\n >\n {children}\n </Flexbox>\n );\n};\n\nScrollShadow.displayName = 'ScrollShadow';\n\nexport default ScrollShadow;\n"],"mappings":";;;;;;;;;;AAcA,MAAM,gBAAuC,EAC3C,WACA,UACA,cAAc,YACd,gBAAgB,OAChB,OAAO,IACP,SAAS,GACT,aAAa,QACb,YAAY,MACZ,oBACA,OACA,KACA,GAAG,WACC;CAEJ,MAAM,eAAe,eACZ,EACL,wBAAwB,GAAG,KAAK,GAClC,IACA,CAAC,IAAI,CACP;CACA,MAAM,SAAS,OAAuB,IAAI;CAE1C,MAAM,0BAA0B,kBAE7B,eAAe;EAChB,qBAAqB,UAAU;CACjC,CAAC;CAED,MAAM,cAAc,kBAAkB;EACpC;EACA,WAAW,aAAa,eAAe;EACvC;EACA,oBAAoB;EACpB;EACA,YAAY,CAAC,QAAQ;CACvB,CAAC;CAGD,MAAM,mBAAmB,cAAc;EACrC,IAAI,eAAe,UACjB,OAAO;GACL,QAAQ;GACR,MAAM;GACN,OAAO;GACP,KAAK;EACP;EAGF,IAAI,eAAe,SACjB,OAAO;GACL,QAAQ;GACR,MAAM;GACN,OAAO;GACP,KAAK;EACP;EAGF,OAAO;CACT,GAAG,CAAC,YAAY,WAAW,CAAC;CAG5B,MAAM,iBAAiB,cAAc;EACnC,MAAM,aAA+C,EACnD,oBAAoB,YACtB;EAEA,IAAI,gBAAgB,YACd;OAAA,iBAAiB,OAAO,iBAAiB,QAC3C,WAAW,4BAA4B;QAClC,IAAI,iBAAiB,KAC1B,WAAW,qBAAqB;QAC3B,IAAI,iBAAiB,QAC1B,WAAW,wBAAwB;EAAA,OAGrC,IAAI,iBAAiB,QAAQ,iBAAiB,OAC5C,WAAW,4BAA4B;OAClC,IAAI,iBAAiB,MAC1B,WAAW,sBAAsB;OAC5B,IAAI,iBAAiB,OAC1B,WAAW,uBAAuB;EAItC,OAAO;CACT,GAAG,CAAC,aAAa,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ScrollShadow.mjs","names":["Flexbox"],"sources":["../../src/ScrollShadow/ScrollShadow.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport type { FC } from 'react';\nimport { useMemo, useRef } from 'react';\nimport { mergeRefs } from 'react-merge-refs';\n\nimport { Flexbox } from '@/Flex';\nimport { useEventCallback } from '@/hooks/useEventCallback';\n\nimport { variants } from './style';\nimport type { ScrollShadowProps } from './type';\nimport { useScrollOverflow } from './useScrollOverflow';\n\nconst ScrollShadow: FC<ScrollShadowProps> = ({\n className,\n children,\n orientation = 'vertical',\n hideScrollBar = false,\n size = 16,\n offset = 8,\n visibility = 'auto',\n isEnabled = true,\n onVisibilityChange,\n style,\n ref,\n ...rest\n}) => {\n // Convert size prop to CSS variable\n const cssVariables = useMemo<Record<string, string>>(\n () => ({\n '--scroll-shadow-size': `${size}%`,\n }),\n [size],\n );\n const domRef = useRef<HTMLDivElement>(null);\n\n const onVisibilityChangeEvent = useEventCallback<\n NonNullable<ScrollShadowProps['onVisibilityChange']>\n >((visibility) => {\n onVisibilityChange?.(visibility);\n });\n // 使用滚动检测钩子\n const scrollState = useScrollOverflow({\n domRef,\n isEnabled: isEnabled && visibility === 'auto',\n offset,\n onVisibilityChange: onVisibilityChangeEvent,\n orientation,\n updateDeps: [children],\n });\n\n // 决定最终的滚动状态\n const finalScrollState = useMemo(() => {\n if (visibility === 'always') {\n return {\n bottom: true,\n left: true,\n right: true,\n top: true,\n };\n }\n\n if (visibility === 'never') {\n return {\n bottom: false,\n left: false,\n right: false,\n top: false,\n };\n }\n\n return scrollState;\n }, [visibility, scrollState]);\n\n // 计算数据属性\n const dataAttributes = useMemo(() => {\n const attributes: Record<string, boolean | string> = {\n 'data-orientation': orientation,\n };\n\n if (orientation === 'vertical') {\n if (finalScrollState.top && finalScrollState.bottom) {\n attributes['data-top-bottom-scroll'] = true;\n } else if (finalScrollState.top) {\n attributes['data-top-scroll'] = true;\n } else if (finalScrollState.bottom) {\n attributes['data-bottom-scroll'] = true;\n }\n } else {\n if (finalScrollState.left && finalScrollState.right) {\n attributes['data-left-right-scroll'] = true;\n } else if (finalScrollState.left) {\n attributes['data-left-scroll'] = true;\n } else if (finalScrollState.right) {\n attributes['data-right-scroll'] = true;\n }\n }\n\n return attributes;\n }, [orientation, finalScrollState]);\n\n // 计算滚动位置变体\n const scrollPosition = useMemo(() => {\n if (orientation === 'vertical') {\n if (finalScrollState.top && finalScrollState.bottom) return 'top-bottom';\n if (finalScrollState.top) return 'top';\n if (finalScrollState.bottom) return 'bottom';\n } else {\n if (finalScrollState.left && finalScrollState.right) return 'left-right';\n if (finalScrollState.left) return 'left';\n if (finalScrollState.right) return 'right';\n }\n return 'none';\n }, [orientation, finalScrollState]);\n\n return (\n <Flexbox\n className={cx(variants({ hideScrollBar, orientation, scrollPosition }), className)}\n ref={mergeRefs<HTMLDivElement>([domRef, ref])}\n style={{\n ...cssVariables,\n ...style,\n }}\n {...dataAttributes}\n {...rest}\n >\n {children}\n </Flexbox>\n );\n};\n\nScrollShadow.displayName = 'ScrollShadow';\n\nexport default ScrollShadow;\n"],"mappings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AAO;GACjC,IAAI,iBAAiB,QAAQ,OAAO;EACtC,OAAO;GACL,IAAI,iBAAiB,QAAQ,iBAAiB,OAAO,OAAO;GAC5D,IAAI,iBAAiB,MAAM,OAAO;GAClC,IAAI,iBAAiB,OAAO,OAAO;EACrC;EACA,OAAO;CACT,GAAG,CAAC,aAAa,gBAAgB,CAAC;CAElC,OACE,oBAACA,mBAAD;EACE,WAAW,GAAG,SAAS;GAAE;GAAe;GAAa;EAAe,CAAC,GAAG,SAAS;EACjF,KAAK,UAA0B,CAAC,QAAQ,GAAG,CAAC;EAC5C,OAAO;GACL,GAAG;GACH,GAAG;EACL;EACA,GAAI;EACJ,GAAI;EAEH;CACM,CAAA;AAEb;AAEA,aAAa,cAAc"}
|
|
@@ -17,12 +17,13 @@ const SkeletonButton = ({ active, block = false, shape = "default", size = "defa
|
|
|
17
17
|
large: cssVar.borderRadiusLG,
|
|
18
18
|
small: cssVar.borderRadiusSM
|
|
19
19
|
};
|
|
20
|
+
const borderRadius = shape === "circle" ? "50%" : shape === "round" ? `calc(${cssVar.borderRadius} * 2)` : RADIUS_MAP[resolvedSize];
|
|
20
21
|
return /* @__PURE__ */ jsx(SkeletonBlock, {
|
|
21
22
|
active,
|
|
22
23
|
className,
|
|
23
24
|
height: baseHeight,
|
|
24
25
|
style: {
|
|
25
|
-
borderRadius
|
|
26
|
+
borderRadius,
|
|
26
27
|
...style
|
|
27
28
|
},
|
|
28
29
|
width: finalWidth,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SkeletonButton.mjs","names":[],"sources":["../../src/Skeleton/SkeletonButton.tsx"],"sourcesContent":["'use client';\n\nimport { cssVar } from 'antd-style';\nimport { type FC } from 'react';\n\nimport SkeletonBlock from './SkeletonBlock';\nimport type { SkeletonButtonProps } from './type';\n\nconst HEIGHT_MAP: Record<'large' | 'small' | 'default', number> = {\n default: 36,\n large: 46,\n small: 28,\n};\n\nconst SkeletonButton: FC<SkeletonButtonProps> = ({\n active,\n block = false,\n shape = 'default',\n size = 'default',\n width,\n height,\n style,\n className,\n ...rest\n}) => {\n const resolvedSize = size ?? 'default';\n const baseHeight = height ?? HEIGHT_MAP[resolvedSize];\n const defaultWidth = block ? '100%' : shape === 'circle' ? baseHeight : 80;\n const finalWidth = width ?? defaultWidth;\n\n const RADIUS_MAP: Record<'large' | 'small' | 'default', string> = {\n default: cssVar.borderRadius,\n large: cssVar.borderRadiusLG,\n small: cssVar.borderRadiusSM,\n };\n\n const borderRadius =\n shape === 'circle'\n ? '50%'\n : shape === 'round'\n ? `calc(${cssVar.borderRadius} * 2)`\n : RADIUS_MAP[resolvedSize];\n\n return (\n <SkeletonBlock\n active={active}\n className={className}\n height={baseHeight}\n style={{ borderRadius, ...style }}\n width={finalWidth}\n {...rest}\n />\n );\n};\n\nSkeletonButton.displayName = 'SkeletonButton';\n\nexport default SkeletonButton;\n"],"mappings":";;;;;AAQA,MAAM,aAA4D;CAChE,SAAS;CACT,OAAO;CACP,OAAO;AACT;AAEA,MAAM,kBAA2C,EAC/C,QACA,QAAQ,OACR,QAAQ,WACR,OAAO,WACP,OACA,QACA,OACA,WACA,GAAG,WACC;CACJ,MAAM,eAAe,QAAQ;CAC7B,MAAM,aAAa,UAAU,WAAW;CAExC,MAAM,aAAa,UADE,QAAQ,SAAS,UAAU,WAAW,aAAa;CAGxE,MAAM,aAA4D;EAChE,SAAS,OAAO;EAChB,OAAO,OAAO;EACd,OAAO,OAAO;CAChB;
|
|
1
|
+
{"version":3,"file":"SkeletonButton.mjs","names":[],"sources":["../../src/Skeleton/SkeletonButton.tsx"],"sourcesContent":["'use client';\n\nimport { cssVar } from 'antd-style';\nimport { type FC } from 'react';\n\nimport SkeletonBlock from './SkeletonBlock';\nimport type { SkeletonButtonProps } from './type';\n\nconst HEIGHT_MAP: Record<'large' | 'small' | 'default', number> = {\n default: 36,\n large: 46,\n small: 28,\n};\n\nconst SkeletonButton: FC<SkeletonButtonProps> = ({\n active,\n block = false,\n shape = 'default',\n size = 'default',\n width,\n height,\n style,\n className,\n ...rest\n}) => {\n const resolvedSize = size ?? 'default';\n const baseHeight = height ?? HEIGHT_MAP[resolvedSize];\n const defaultWidth = block ? '100%' : shape === 'circle' ? baseHeight : 80;\n const finalWidth = width ?? defaultWidth;\n\n const RADIUS_MAP: Record<'large' | 'small' | 'default', string> = {\n default: cssVar.borderRadius,\n large: cssVar.borderRadiusLG,\n small: cssVar.borderRadiusSM,\n };\n\n const borderRadius =\n shape === 'circle'\n ? '50%'\n : shape === 'round'\n ? `calc(${cssVar.borderRadius} * 2)`\n : RADIUS_MAP[resolvedSize];\n\n return (\n <SkeletonBlock\n active={active}\n className={className}\n height={baseHeight}\n style={{ borderRadius, ...style }}\n width={finalWidth}\n {...rest}\n />\n );\n};\n\nSkeletonButton.displayName = 'SkeletonButton';\n\nexport default SkeletonButton;\n"],"mappings":";;;;;AAQA,MAAM,aAA4D;CAChE,SAAS;CACT,OAAO;CACP,OAAO;AACT;AAEA,MAAM,kBAA2C,EAC/C,QACA,QAAQ,OACR,QAAQ,WACR,OAAO,WACP,OACA,QACA,OACA,WACA,GAAG,WACC;CACJ,MAAM,eAAe,QAAQ;CAC7B,MAAM,aAAa,UAAU,WAAW;CAExC,MAAM,aAAa,UADE,QAAQ,SAAS,UAAU,WAAW,aAAa;CAGxE,MAAM,aAA4D;EAChE,SAAS,OAAO;EAChB,OAAO,OAAO;EACd,OAAO,OAAO;CAChB;CAEA,MAAM,eACJ,UAAU,WACN,QACA,UAAU,UACR,QAAQ,OAAO,aAAa,SAC5B,WAAW;CAEnB,OACE,oBAAC,eAAD;EACU;EACG;EACX,QAAQ;EACR,OAAO;GAAE;GAAc,GAAG;EAAM;EAChC,OAAO;EACP,GAAI;CACL,CAAA;AAEL;AAEA,eAAe,cAAc"}
|
|
@@ -25,7 +25,11 @@ const SortableListParent = memo(({ ref, items, onChange, renderItem, renderOverl
|
|
|
25
25
|
setActive(null);
|
|
26
26
|
},
|
|
27
27
|
onDragEnd: ({ active, over }) => {
|
|
28
|
-
if (over && active.id !== over?.id)
|
|
28
|
+
if (over && active.id !== over?.id) {
|
|
29
|
+
const activeIndex = items.findIndex(({ id }) => id === active.id);
|
|
30
|
+
const overIndex = items.findIndex(({ id }) => id === over.id);
|
|
31
|
+
onChange(arrayMove(items, activeIndex, overIndex));
|
|
32
|
+
}
|
|
29
33
|
setActive(null);
|
|
30
34
|
},
|
|
31
35
|
onDragStart: ({ active }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortableList.mjs","names":["Flexbox"],"sources":["../../src/SortableList/SortableList.tsx"],"sourcesContent":["'use client';\n\nimport {\n type Active,\n closestCenter,\n DndContext,\n KeyboardSensor,\n MeasuringStrategy,\n PointerSensor,\n useSensor,\n useSensors,\n} from '@dnd-kit/core';\nimport { restrictToVerticalAxis, restrictToWindowEdges } from '@dnd-kit/modifiers';\nimport {\n arrayMove,\n SortableContext,\n sortableKeyboardCoordinates,\n verticalListSortingStrategy,\n} from '@dnd-kit/sortable';\nimport { Fragment, memo, type ReactNode, useMemo, useState } from 'react';\n\nimport { Flexbox } from '@/Flex';\n\nimport DragHandle from './components/DragHandle';\nimport SortableItem from './components/SortableItem';\nimport SortableOverlay from './components/SortableOverlay';\nimport { styles } from './style';\nimport { type SortableListItem, type SortableListProps } from './type';\n\nconst measuringConfig = {\n droppable: {\n strategy: MeasuringStrategy.Always,\n },\n};\n\nconst SortableListParent = memo<SortableListProps>(\n ({ ref, items, onChange, renderItem, renderOverlay, gap = 8, ...rest }) => {\n const [active, setActive] = useState<Active | null>(null);\n const activeItem = useMemo(() => items.find((item) => item.id === active?.id), [active, items]);\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n const overlayRenderer = renderOverlay ?? renderItem;\n\n return (\n <DndContext\n collisionDetection={closestCenter}\n measuring={measuringConfig}\n modifiers={[restrictToVerticalAxis, restrictToWindowEdges]}\n sensors={sensors}\n onDragCancel={() => {\n setActive(null);\n }}\n onDragEnd={({ active, over }) => {\n if (over && active.id !== over?.id) {\n const activeIndex = items.findIndex(({ id }) => id === active.id);\n const overIndex = items.findIndex(({ id }) => id === over.id);\n\n onChange(arrayMove(items, activeIndex, overIndex));\n }\n setActive(null);\n }}\n onDragStart={({ active }) => {\n setActive(active);\n }}\n >\n <SortableContext items={items} strategy={verticalListSortingStrategy}>\n <Flexbox as={'ul'} className={styles.container} gap={gap} ref={ref} {...rest}>\n {items.map((item) => (\n <Fragment key={item.id}>{renderItem(item)}</Fragment>\n ))}\n </Flexbox>\n </SortableContext>\n <SortableOverlay>{activeItem ? overlayRenderer(activeItem) : null}</SortableOverlay>\n </DndContext>\n );\n },\n);\n\nSortableListParent.displayName = 'SortableList';\n\nexport interface ISortableList {\n <T extends SortableListItem = SortableListItem>(props: SortableListProps<T>): ReactNode;\n DragHandle: typeof DragHandle;\n Item: typeof SortableItem;\n}\n\nconst SortableList = SortableListParent as unknown as ISortableList;\n\nSortableList.Item = SortableItem;\nSortableList.DragHandle = DragHandle;\n\nexport default SortableList;\n"],"mappings":";;;;;;;;;;;;AA6BA,MAAM,kBAAkB,EACtB,WAAW,EACT,UAAU,kBAAkB,OAC9B,EACF;AAEA,MAAM,qBAAqB,MACxB,EAAE,KAAK,OAAO,UAAU,YAAY,eAAe,MAAM,GAAG,GAAG,WAAW;CACzE,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CACxD,MAAM,aAAa,cAAc,MAAM,MAAM,SAAS,KAAK,OAAO,QAAQ,EAAE,GAAG,CAAC,QAAQ,KAAK,CAAC;CAC9F,MAAM,UAAU,WACd,UAAU,aAAa,GACvB,UAAU,gBAAgB,EACxB,kBAAkB,4BACpB,CAAC,CACH;CAEA,MAAM,kBAAkB,iBAAiB;CAEzC,OACE,qBAAC,YAAD;EACE,oBAAoB;EACpB,WAAW;EACX,WAAW,CAAC,wBAAwB,qBAAqB;EAChD;EACT,oBAAoB;GAClB,UAAU,IAAI;EAChB;EACA,YAAY,EAAE,QAAQ,WAAW;GAC/B,IAAI,QAAQ,OAAO,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"SortableList.mjs","names":["Flexbox"],"sources":["../../src/SortableList/SortableList.tsx"],"sourcesContent":["'use client';\n\nimport {\n type Active,\n closestCenter,\n DndContext,\n KeyboardSensor,\n MeasuringStrategy,\n PointerSensor,\n useSensor,\n useSensors,\n} from '@dnd-kit/core';\nimport { restrictToVerticalAxis, restrictToWindowEdges } from '@dnd-kit/modifiers';\nimport {\n arrayMove,\n SortableContext,\n sortableKeyboardCoordinates,\n verticalListSortingStrategy,\n} from '@dnd-kit/sortable';\nimport { Fragment, memo, type ReactNode, useMemo, useState } from 'react';\n\nimport { Flexbox } from '@/Flex';\n\nimport DragHandle from './components/DragHandle';\nimport SortableItem from './components/SortableItem';\nimport SortableOverlay from './components/SortableOverlay';\nimport { styles } from './style';\nimport { type SortableListItem, type SortableListProps } from './type';\n\nconst measuringConfig = {\n droppable: {\n strategy: MeasuringStrategy.Always,\n },\n};\n\nconst SortableListParent = memo<SortableListProps>(\n ({ ref, items, onChange, renderItem, renderOverlay, gap = 8, ...rest }) => {\n const [active, setActive] = useState<Active | null>(null);\n const activeItem = useMemo(() => items.find((item) => item.id === active?.id), [active, items]);\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n const overlayRenderer = renderOverlay ?? renderItem;\n\n return (\n <DndContext\n collisionDetection={closestCenter}\n measuring={measuringConfig}\n modifiers={[restrictToVerticalAxis, restrictToWindowEdges]}\n sensors={sensors}\n onDragCancel={() => {\n setActive(null);\n }}\n onDragEnd={({ active, over }) => {\n if (over && active.id !== over?.id) {\n const activeIndex = items.findIndex(({ id }) => id === active.id);\n const overIndex = items.findIndex(({ id }) => id === over.id);\n\n onChange(arrayMove(items, activeIndex, overIndex));\n }\n setActive(null);\n }}\n onDragStart={({ active }) => {\n setActive(active);\n }}\n >\n <SortableContext items={items} strategy={verticalListSortingStrategy}>\n <Flexbox as={'ul'} className={styles.container} gap={gap} ref={ref} {...rest}>\n {items.map((item) => (\n <Fragment key={item.id}>{renderItem(item)}</Fragment>\n ))}\n </Flexbox>\n </SortableContext>\n <SortableOverlay>{activeItem ? overlayRenderer(activeItem) : null}</SortableOverlay>\n </DndContext>\n );\n },\n);\n\nSortableListParent.displayName = 'SortableList';\n\nexport interface ISortableList {\n <T extends SortableListItem = SortableListItem>(props: SortableListProps<T>): ReactNode;\n DragHandle: typeof DragHandle;\n Item: typeof SortableItem;\n}\n\nconst SortableList = SortableListParent as unknown as ISortableList;\n\nSortableList.Item = SortableItem;\nSortableList.DragHandle = DragHandle;\n\nexport default SortableList;\n"],"mappings":";;;;;;;;;;;;AA6BA,MAAM,kBAAkB,EACtB,WAAW,EACT,UAAU,kBAAkB,OAC9B,EACF;AAEA,MAAM,qBAAqB,MACxB,EAAE,KAAK,OAAO,UAAU,YAAY,eAAe,MAAM,GAAG,GAAG,WAAW;CACzE,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CACxD,MAAM,aAAa,cAAc,MAAM,MAAM,SAAS,KAAK,OAAO,QAAQ,EAAE,GAAG,CAAC,QAAQ,KAAK,CAAC;CAC9F,MAAM,UAAU,WACd,UAAU,aAAa,GACvB,UAAU,gBAAgB,EACxB,kBAAkB,4BACpB,CAAC,CACH;CAEA,MAAM,kBAAkB,iBAAiB;CAEzC,OACE,qBAAC,YAAD;EACE,oBAAoB;EACpB,WAAW;EACX,WAAW,CAAC,wBAAwB,qBAAqB;EAChD;EACT,oBAAoB;GAClB,UAAU,IAAI;EAChB;EACA,YAAY,EAAE,QAAQ,WAAW;GAC/B,IAAI,QAAQ,OAAO,OAAO,MAAM,IAAI;IAClC,MAAM,cAAc,MAAM,WAAW,EAAE,SAAS,OAAO,OAAO,EAAE;IAChE,MAAM,YAAY,MAAM,WAAW,EAAE,SAAS,OAAO,KAAK,EAAE;IAE5D,SAAS,UAAU,OAAO,aAAa,SAAS,CAAC;GACnD;GACA,UAAU,IAAI;EAChB;EACA,cAAc,EAAE,aAAa;GAC3B,UAAU,MAAM;EAClB;EAnBF,UAAA,CAqBE,oBAAC,iBAAD;GAAwB;GAAO,UAAU;GACvC,UAAA,oBAACA,mBAAD;IAAS,IAAI;IAAM,WAAW,OAAO;IAAgB;IAAU;IAAK,GAAI;IACrE,UAAA,MAAM,KAAK,SACV,oBAAC,UAAD,EAAA,UAAyB,WAAW,IAAI,EAAY,GAArC,KAAK,EAAgC,CACrD;GACM,CAAA;EACM,CAAA,GACjB,oBAAC,iBAAD,EAAA,UAAkB,aAAa,gBAAgB,UAAU,IAAI,KAAsB,CAAA,CACzE;;AAEhB,CACF;AAEA,mBAAmB,cAAc;AAQjC,MAAM,eAAe;AAErB,aAAa,OAAO;AACpB,aAAa,aAAa"}
|
package/es/Text/Text.mjs
CHANGED
|
@@ -11,29 +11,30 @@ const Text = ({ as: Container = "div", align, className, children, style, type,
|
|
|
11
11
|
const isOverflow = useTextOverflow(textRef, ellipsis, children);
|
|
12
12
|
const isMultiEllipsis = typeof ellipsis === "object" && !!ellipsis.rows && ellipsis.rows > 1;
|
|
13
13
|
const tooltipWhenOverflow = typeof ellipsis === "object" && ellipsis.tooltipWhenOverflow;
|
|
14
|
+
const textStyle = {
|
|
15
|
+
...color && { color },
|
|
16
|
+
...weight && { fontWeight: weight },
|
|
17
|
+
...lineHeight && { lineHeight },
|
|
18
|
+
...textTransform && { textTransform },
|
|
19
|
+
...textDecoration && { textDecoration },
|
|
20
|
+
...wordBreak && { wordBreak },
|
|
21
|
+
...typeof ellipsis === "object" && ellipsis.rows && { WebkitLineClamp: ellipsis.rows },
|
|
22
|
+
...!ellipsis && !!lineClamp && {
|
|
23
|
+
WebkitBoxOrient: "vertical",
|
|
24
|
+
WebkitLineClamp: lineClamp,
|
|
25
|
+
display: "-webkit-box",
|
|
26
|
+
overflow: "hidden",
|
|
27
|
+
textOverflow: "ellipsis"
|
|
28
|
+
},
|
|
29
|
+
...fontSize && { fontSize },
|
|
30
|
+
...align && { textAlign: align },
|
|
31
|
+
...!isMultiEllipsis && noWrap && { whiteSpace: "nowrap" },
|
|
32
|
+
...whiteSpace && { whiteSpace },
|
|
33
|
+
...style
|
|
34
|
+
};
|
|
14
35
|
const content = /* @__PURE__ */ jsx(Container, {
|
|
15
36
|
ref: textRef,
|
|
16
|
-
style:
|
|
17
|
-
...color && { color },
|
|
18
|
-
...weight && { fontWeight: weight },
|
|
19
|
-
...lineHeight && { lineHeight },
|
|
20
|
-
...textTransform && { textTransform },
|
|
21
|
-
...textDecoration && { textDecoration },
|
|
22
|
-
...wordBreak && { wordBreak },
|
|
23
|
-
...typeof ellipsis === "object" && ellipsis.rows && { WebkitLineClamp: ellipsis.rows },
|
|
24
|
-
...!ellipsis && !!lineClamp && {
|
|
25
|
-
WebkitBoxOrient: "vertical",
|
|
26
|
-
WebkitLineClamp: lineClamp,
|
|
27
|
-
display: "-webkit-box",
|
|
28
|
-
overflow: "hidden",
|
|
29
|
-
textOverflow: "ellipsis"
|
|
30
|
-
},
|
|
31
|
-
...fontSize && { fontSize },
|
|
32
|
-
...align && { textAlign: align },
|
|
33
|
-
...!isMultiEllipsis && noWrap && { whiteSpace: "nowrap" },
|
|
34
|
-
...whiteSpace && { whiteSpace },
|
|
35
|
-
...style
|
|
36
|
-
},
|
|
37
|
+
style: textStyle,
|
|
37
38
|
className: cx(variants({
|
|
38
39
|
as: [
|
|
39
40
|
"h1",
|
package/es/Text/Text.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.mjs","names":[],"sources":["../../src/Text/Text.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport { type FC, useRef } from 'react';\n\nimport { useTextOverflow } from '@/hooks/useTextOverflow';\nimport Tooltip from '@/Tooltip';\n\nimport { variants } from './styles';\nimport { type TextProps } from './type';\n\nconst Text: FC<TextProps> = ({\n as: Container = 'div',\n align,\n className,\n children,\n style,\n type,\n disabled,\n strong,\n italic,\n underline,\n delete: deleteStyle,\n fontSize,\n lineClamp,\n lineHeight,\n mark,\n code,\n color,\n weight,\n ellipsis,\n noWrap,\n textDecoration,\n textTransform,\n whiteSpace,\n wordBreak,\n ...rest\n}) => {\n const textRef = useRef<HTMLElement>(null);\n const isOverflow = useTextOverflow(textRef, ellipsis, children);\n\n const isMultiEllipsis = typeof ellipsis === 'object' && !!ellipsis.rows && ellipsis.rows > 1;\n const tooltipWhenOverflow = typeof ellipsis === 'object' && ellipsis.tooltipWhenOverflow;\n\n const textStyle = {\n ...(color && { color }),\n ...(weight && { fontWeight: weight }),\n ...(lineHeight && { lineHeight }),\n ...(textTransform && { textTransform }),\n ...(textDecoration && { textDecoration }),\n ...(wordBreak && { wordBreak }),\n ...(typeof ellipsis === 'object' &&\n ellipsis.rows && {\n WebkitLineClamp: ellipsis.rows,\n }),\n ...(!ellipsis &&\n !!lineClamp && {\n WebkitBoxOrient: 'vertical',\n WebkitLineClamp: lineClamp,\n display: '-webkit-box',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }),\n ...(fontSize && { fontSize }),\n ...(align && { textAlign: align }),\n ...(!isMultiEllipsis && noWrap && { whiteSpace: 'nowrap' as const }),\n ...(whiteSpace && { whiteSpace }),\n ...style,\n };\n\n const content = (\n <Container\n ref={textRef}\n style={textStyle}\n className={cx(\n variants({\n as: ['h1', 'h2', 'h3', 'h4', 'h5', 'p'].includes(Container as string)\n ? (Container as any)\n : undefined,\n code,\n delete: deleteStyle,\n disabled,\n ellipsis: ellipsis\n ? typeof ellipsis === 'object' && ellipsis.rows\n ? 'multi'\n : true\n : undefined,\n italic,\n mark,\n strong,\n type,\n underline,\n }),\n className,\n )}\n {...rest}\n >\n {children}\n </Container>\n );\n\n // 处理带有 tooltip 的省略\n if (\n ellipsis &&\n typeof ellipsis === 'object' &&\n (ellipsis.tooltip || ellipsis.tooltipWhenOverflow)\n ) {\n // 如果设置了 tooltipWhenOverflow,只在溢出时显示 tooltip\n if (tooltipWhenOverflow && !isOverflow) {\n return content;\n }\n\n const title = typeof ellipsis.tooltip === 'string' ? ellipsis.tooltip : children;\n if (ellipsis.tooltip && typeof ellipsis.tooltip === 'object')\n return (\n <Tooltip {...ellipsis.tooltip} title={ellipsis.tooltip?.title || title}>\n {content}\n </Tooltip>\n );\n return <Tooltip title={title}>{content}</Tooltip>;\n }\n\n return content;\n};\n\nText.displayName = 'Text';\n\nexport default Text;\n"],"mappings":";;;;;;;;AAWA,MAAM,QAAuB,EAC3B,IAAI,YAAY,OAChB,OACA,WACA,UACA,OACA,MACA,UACA,QACA,QACA,WACA,QAAQ,aACR,UACA,WACA,YACA,MACA,MACA,OACA,QACA,UACA,QACA,gBACA,eACA,YACA,WACA,GAAG,WACC;CACJ,MAAM,UAAU,OAAoB,IAAI;CACxC,MAAM,aAAa,gBAAgB,SAAS,UAAU,QAAQ;CAE9D,MAAM,kBAAkB,OAAO,aAAa,YAAY,CAAC,CAAC,SAAS,QAAQ,SAAS,OAAO;CAC3F,MAAM,sBAAsB,OAAO,aAAa,YAAY,SAAS;
|
|
1
|
+
{"version":3,"file":"Text.mjs","names":[],"sources":["../../src/Text/Text.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport { type FC, useRef } from 'react';\n\nimport { useTextOverflow } from '@/hooks/useTextOverflow';\nimport Tooltip from '@/Tooltip';\n\nimport { variants } from './styles';\nimport { type TextProps } from './type';\n\nconst Text: FC<TextProps> = ({\n as: Container = 'div',\n align,\n className,\n children,\n style,\n type,\n disabled,\n strong,\n italic,\n underline,\n delete: deleteStyle,\n fontSize,\n lineClamp,\n lineHeight,\n mark,\n code,\n color,\n weight,\n ellipsis,\n noWrap,\n textDecoration,\n textTransform,\n whiteSpace,\n wordBreak,\n ...rest\n}) => {\n const textRef = useRef<HTMLElement>(null);\n const isOverflow = useTextOverflow(textRef, ellipsis, children);\n\n const isMultiEllipsis = typeof ellipsis === 'object' && !!ellipsis.rows && ellipsis.rows > 1;\n const tooltipWhenOverflow = typeof ellipsis === 'object' && ellipsis.tooltipWhenOverflow;\n\n const textStyle = {\n ...(color && { color }),\n ...(weight && { fontWeight: weight }),\n ...(lineHeight && { lineHeight }),\n ...(textTransform && { textTransform }),\n ...(textDecoration && { textDecoration }),\n ...(wordBreak && { wordBreak }),\n ...(typeof ellipsis === 'object' &&\n ellipsis.rows && {\n WebkitLineClamp: ellipsis.rows,\n }),\n ...(!ellipsis &&\n !!lineClamp && {\n WebkitBoxOrient: 'vertical',\n WebkitLineClamp: lineClamp,\n display: '-webkit-box',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }),\n ...(fontSize && { fontSize }),\n ...(align && { textAlign: align }),\n ...(!isMultiEllipsis && noWrap && { whiteSpace: 'nowrap' as const }),\n ...(whiteSpace && { whiteSpace }),\n ...style,\n };\n\n const content = (\n <Container\n ref={textRef}\n style={textStyle}\n className={cx(\n variants({\n as: ['h1', 'h2', 'h3', 'h4', 'h5', 'p'].includes(Container as string)\n ? (Container as any)\n : undefined,\n code,\n delete: deleteStyle,\n disabled,\n ellipsis: ellipsis\n ? typeof ellipsis === 'object' && ellipsis.rows\n ? 'multi'\n : true\n : undefined,\n italic,\n mark,\n strong,\n type,\n underline,\n }),\n className,\n )}\n {...rest}\n >\n {children}\n </Container>\n );\n\n // 处理带有 tooltip 的省略\n if (\n ellipsis &&\n typeof ellipsis === 'object' &&\n (ellipsis.tooltip || ellipsis.tooltipWhenOverflow)\n ) {\n // 如果设置了 tooltipWhenOverflow,只在溢出时显示 tooltip\n if (tooltipWhenOverflow && !isOverflow) {\n return content;\n }\n\n const title = typeof ellipsis.tooltip === 'string' ? ellipsis.tooltip : children;\n if (ellipsis.tooltip && typeof ellipsis.tooltip === 'object')\n return (\n <Tooltip {...ellipsis.tooltip} title={ellipsis.tooltip?.title || title}>\n {content}\n </Tooltip>\n );\n return <Tooltip title={title}>{content}</Tooltip>;\n }\n\n return content;\n};\n\nText.displayName = 'Text';\n\nexport default Text;\n"],"mappings":";;;;;;;;AAWA,MAAM,QAAuB,EAC3B,IAAI,YAAY,OAChB,OACA,WACA,UACA,OACA,MACA,UACA,QACA,QACA,WACA,QAAQ,aACR,UACA,WACA,YACA,MACA,MACA,OACA,QACA,UACA,QACA,gBACA,eACA,YACA,WACA,GAAG,WACC;CACJ,MAAM,UAAU,OAAoB,IAAI;CACxC,MAAM,aAAa,gBAAgB,SAAS,UAAU,QAAQ;CAE9D,MAAM,kBAAkB,OAAO,aAAa,YAAY,CAAC,CAAC,SAAS,QAAQ,SAAS,OAAO;CAC3F,MAAM,sBAAsB,OAAO,aAAa,YAAY,SAAS;CAErE,MAAM,YAAY;EAChB,GAAI,SAAS,EAAE,MAAM;EACrB,GAAI,UAAU,EAAE,YAAY,OAAO;EACnC,GAAI,cAAc,EAAE,WAAW;EAC/B,GAAI,iBAAiB,EAAE,cAAc;EACrC,GAAI,kBAAkB,EAAE,eAAe;EACvC,GAAI,aAAa,EAAE,UAAU;EAC7B,GAAI,OAAO,aAAa,YACtB,SAAS,QAAQ,EACf,iBAAiB,SAAS,KAC5B;EACF,GAAI,CAAC,YACH,CAAC,CAAC,aAAa;GACb,iBAAiB;GACjB,iBAAiB;GACjB,SAAS;GACT,UAAU;GACV,cAAc;EAChB;EACF,GAAI,YAAY,EAAE,SAAS;EAC3B,GAAI,SAAS,EAAE,WAAW,MAAM;EAChC,GAAI,CAAC,mBAAmB,UAAU,EAAE,YAAY,SAAkB;EAClE,GAAI,cAAc,EAAE,WAAW;EAC/B,GAAG;CACL;CAEA,MAAM,UACJ,oBAAC,WAAD;EACE,KAAK;EACL,OAAO;EACP,WAAW,GACT,SAAS;GACP,IAAI;IAAC;IAAM;IAAM;IAAM;IAAM;IAAM;GAAG,CAAC,CAAC,SAAS,SAAmB,IAC/D,YACD,KAAA;GACJ;GACA,QAAQ;GACR;GACA,UAAU,WACN,OAAO,aAAa,YAAY,SAAS,OACvC,UACA,OACF,KAAA;GACJ;GACA;GACA;GACA;GACA;EACF,CAAC,GACD,SACF;EACA,GAAI;EAEH;CACQ,CAAA;CAIb,IACE,YACA,OAAO,aAAa,aACnB,SAAS,WAAW,SAAS,sBAC9B;EAEA,IAAI,uBAAuB,CAAC,YAC1B,OAAO;EAGT,MAAM,QAAQ,OAAO,SAAS,YAAY,WAAW,SAAS,UAAU;EACxE,IAAI,SAAS,WAAW,OAAO,SAAS,YAAY,UAClD,OACE,oBAAC,SAAD;GAAS,GAAI,SAAS;GAAS,OAAO,SAAS,SAAS,SAAS;GAC9D,UAAA;EACM,CAAA;EAEb,OAAO,oBAAC,SAAD;GAAgB;GAAQ,UAAA;EAAiB,CAAA;CAClD;CAEA,OAAO;AACT;AAEA,KAAK,cAAc"}
|
|
@@ -48,11 +48,12 @@ const ThemeProvider$1 = memo(({ appId = LOBE_THEME_APP_ID, children, customStyli
|
|
|
48
48
|
...customToken?.(theme)
|
|
49
49
|
}), [customToken]);
|
|
50
50
|
const theme = useCallback((appearance) => {
|
|
51
|
-
|
|
51
|
+
const lobeTheme = createLobeAntdTheme({
|
|
52
52
|
appearance,
|
|
53
53
|
neutralColor: customTheme.neutralColor,
|
|
54
54
|
primaryColor: customTheme.primaryColor
|
|
55
|
-
})
|
|
55
|
+
});
|
|
56
|
+
return merge(lobeTheme, antdTheme);
|
|
56
57
|
}, [
|
|
57
58
|
customTheme.primaryColor,
|
|
58
59
|
customTheme.neutralColor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.mjs","names":["ThemeProvider","lobeCustomStylish","lobeCustomToken","AntdThemeProvider","AntdConfigProvider"],"sources":["../../src/ThemeProvider/ThemeProvider.tsx"],"sourcesContent":["'use client';\n\nimport { App } from 'antd';\nimport {\n type CustomStylishParams,\n type CustomTokenParams,\n type GetAntdTheme,\n ThemeProvider as AntdThemeProvider,\n} from 'antd-style';\nimport { merge } from 'es-toolkit/compat';\nimport { memo, useCallback, useMemo, useState } from 'react';\n\nimport { useCdnFn } from '@/ConfigProvider';\nimport FontLoader from '@/FontLoader';\nimport { lobeCustomStylish, lobeCustomToken } from '@/styles';\nimport { createLobeAntdTheme } from '@/styles/theme/antdTheme';\nimport { type LobeCustomToken } from '@/types/customToken';\n\nimport AppElementContext from './AppElementContext';\nimport AntdConfigProvider from './ConfigProvider';\nimport { LOBE_THEME_APP_ID } from './constants';\nimport GlobalStyle, { EssentialStyle } from './GlobalStyle';\nimport { type ThemeProviderProps } from './type';\n\nconst ThemeProvider = memo<ThemeProviderProps>(\n ({\n appId = LOBE_THEME_APP_ID,\n children,\n customStylish,\n customToken,\n enableCustomFonts = true,\n enableGlobalStyle = true,\n customFonts,\n customTheme = {},\n className,\n style,\n theme: antdTheme,\n ...rest\n }) => {\n const genCdnUrl = useCdnFn();\n const [appRef, setAppRef] = useState<HTMLDivElement | null>(null);\n\n const webfontUrls = useMemo(\n () =>\n customFonts || [\n genCdnUrl({\n path: 'css/index.css',\n pkg: '@lobehub/webfont-geist-mono',\n version: '1.0.0',\n }),\n genCdnUrl({\n path: 'css/index-full.css',\n pkg: '@lobehub/webfont-geist',\n version: '1.0.0',\n }),\n genCdnUrl({\n path: 'css/index.css',\n pkg: '@lobehub/webfont-harmony-sans-sc',\n // pkg: '@lobehub/webfont-harmony-sans-sc-mini',\n version: '1.0.0',\n }),\n genCdnUrl({\n path: 'dist/katex.min.css',\n pkg: 'katex',\n version: '0.18.1',\n }),\n ],\n [customFonts, genCdnUrl],\n );\n\n const stylish = useCallback(\n (theme: CustomStylishParams) => ({ ...lobeCustomStylish(theme), ...customStylish?.(theme) }),\n [customStylish],\n );\n\n const token = useCallback(\n (theme: CustomTokenParams) => ({ ...lobeCustomToken(theme), ...customToken?.(theme) }),\n [customToken],\n );\n\n const theme = useCallback<GetAntdTheme>(\n (appearance) => {\n const lobeTheme = createLobeAntdTheme({\n appearance,\n neutralColor: customTheme.neutralColor,\n primaryColor: customTheme.primaryColor,\n });\n return merge(lobeTheme, antdTheme);\n },\n [customTheme.primaryColor, customTheme.neutralColor, antdTheme],\n );\n\n return (\n <>\n {enableCustomFonts &&\n webfontUrls?.length > 0 &&\n webfontUrls.map((webfont) => <FontLoader key={webfont} url={webfont} />)}\n <AntdThemeProvider<LobeCustomToken>\n customStylish={stylish}\n customToken={token}\n theme={theme}\n {...rest}\n >\n <AntdConfigProvider>\n <EssentialStyle />\n {enableGlobalStyle && <GlobalStyle />}\n\n <App\n className={className}\n style={{ isolation: 'isolate', minHeight: 'inherit', width: 'inherit', ...style }}\n >\n <div id={appId} style={contentsStyle}>\n <AppElementContext value={appRef}>\n {children}\n {/*\n In-tree portal host for Base UI floating components\n (Select, Combobox, etc.). Keeping it inside `<App>` keeps\n the antd-style / emotion theme cascade intact so popups\n render with the correct tokens, while the layout-bearing\n block lets Base UI's Portal actually mount — the outer\n wrapper uses `display: contents` and cannot host portals.\n */}\n <div data-lobe-portal-host=\"\" ref={setAppRef} style={hostPortalHostStyle} />\n </AppElementContext>\n </div>\n </App>\n </AntdConfigProvider>\n </AntdThemeProvider>\n </>\n );\n },\n);\n\nThemeProvider.displayName = 'LobeThemeProvider';\n\nexport default ThemeProvider;\n\nconst hostPortalHostStyle: React.CSSProperties = {\n // `height: 0` keeps the host invisible and gives it no hit region of\n // its own; absolute children (Base UI Positioner) have their own hit\n // region, so we must NOT set `pointer-events: none` here — it would\n // be inherited by popup descendants and break clicks/hover.\n height: 0,\n left: 0,\n // `position: fixed` keeps a stacking context so portaled popups can\n // win over sibling z-indexes. `right: 0` (instead of `width: 0`)\n // gives the host a full viewport-width containing block — without it,\n // Base UI Positioner uses `position: absolute` against a 0-width\n // containing block and collapses text to one character per line.\n position: 'fixed',\n right: 0,\n top: 0,\n zIndex: 1100,\n};\n\nconst contentsStyle: React.CSSProperties = {\n display: 'contents',\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,MAAMA,kBAAgB,MACnB,EACC,QAAQ,mBACR,UACA,eACA,aACA,oBAAoB,MACpB,oBAAoB,MACpB,aACA,cAAc,CAAC,GACf,WACA,OACA,OAAO,WACP,GAAG,WACC;CACJ,MAAM,YAAY,SAAS;CAC3B,MAAM,CAAC,QAAQ,aAAa,SAAgC,IAAI;CAEhE,MAAM,cAAc,cAEhB,eAAe;EACb,UAAU;GACR,MAAM;GACN,KAAK;GACL,SAAS;EACX,CAAC;EACD,UAAU;GACR,MAAM;GACN,KAAK;GACL,SAAS;EACX,CAAC;EACD,UAAU;GACR,MAAM;GACN,KAAK;GAEL,SAAS;EACX,CAAC;EACD,UAAU;GACR,MAAM;GACN,KAAK;GACL,SAAS;EACX,CAAC;CACH,GACF,CAAC,aAAa,SAAS,CACzB;CAEA,MAAM,UAAU,aACb,WAAgC;EAAE,GAAGC,sBAAkB,KAAK;EAAG,GAAG,gBAAgB,KAAK;CAAE,IAC1F,CAAC,aAAa,CAChB;CAEA,MAAM,QAAQ,aACX,WAA8B;EAAE,GAAGC,oBAAgB,KAAK;EAAG,GAAG,cAAc,KAAK;CAAE,IACpF,CAAC,WAAW,CACd;CAEA,MAAM,QAAQ,aACX,eAAe;
|
|
1
|
+
{"version":3,"file":"ThemeProvider.mjs","names":["ThemeProvider","lobeCustomStylish","lobeCustomToken","AntdThemeProvider","AntdConfigProvider"],"sources":["../../src/ThemeProvider/ThemeProvider.tsx"],"sourcesContent":["'use client';\n\nimport { App } from 'antd';\nimport {\n type CustomStylishParams,\n type CustomTokenParams,\n type GetAntdTheme,\n ThemeProvider as AntdThemeProvider,\n} from 'antd-style';\nimport { merge } from 'es-toolkit/compat';\nimport { memo, useCallback, useMemo, useState } from 'react';\n\nimport { useCdnFn } from '@/ConfigProvider';\nimport FontLoader from '@/FontLoader';\nimport { lobeCustomStylish, lobeCustomToken } from '@/styles';\nimport { createLobeAntdTheme } from '@/styles/theme/antdTheme';\nimport { type LobeCustomToken } from '@/types/customToken';\n\nimport AppElementContext from './AppElementContext';\nimport AntdConfigProvider from './ConfigProvider';\nimport { LOBE_THEME_APP_ID } from './constants';\nimport GlobalStyle, { EssentialStyle } from './GlobalStyle';\nimport { type ThemeProviderProps } from './type';\n\nconst ThemeProvider = memo<ThemeProviderProps>(\n ({\n appId = LOBE_THEME_APP_ID,\n children,\n customStylish,\n customToken,\n enableCustomFonts = true,\n enableGlobalStyle = true,\n customFonts,\n customTheme = {},\n className,\n style,\n theme: antdTheme,\n ...rest\n }) => {\n const genCdnUrl = useCdnFn();\n const [appRef, setAppRef] = useState<HTMLDivElement | null>(null);\n\n const webfontUrls = useMemo(\n () =>\n customFonts || [\n genCdnUrl({\n path: 'css/index.css',\n pkg: '@lobehub/webfont-geist-mono',\n version: '1.0.0',\n }),\n genCdnUrl({\n path: 'css/index-full.css',\n pkg: '@lobehub/webfont-geist',\n version: '1.0.0',\n }),\n genCdnUrl({\n path: 'css/index.css',\n pkg: '@lobehub/webfont-harmony-sans-sc',\n // pkg: '@lobehub/webfont-harmony-sans-sc-mini',\n version: '1.0.0',\n }),\n genCdnUrl({\n path: 'dist/katex.min.css',\n pkg: 'katex',\n version: '0.18.1',\n }),\n ],\n [customFonts, genCdnUrl],\n );\n\n const stylish = useCallback(\n (theme: CustomStylishParams) => ({ ...lobeCustomStylish(theme), ...customStylish?.(theme) }),\n [customStylish],\n );\n\n const token = useCallback(\n (theme: CustomTokenParams) => ({ ...lobeCustomToken(theme), ...customToken?.(theme) }),\n [customToken],\n );\n\n const theme = useCallback<GetAntdTheme>(\n (appearance) => {\n const lobeTheme = createLobeAntdTheme({\n appearance,\n neutralColor: customTheme.neutralColor,\n primaryColor: customTheme.primaryColor,\n });\n return merge(lobeTheme, antdTheme);\n },\n [customTheme.primaryColor, customTheme.neutralColor, antdTheme],\n );\n\n return (\n <>\n {enableCustomFonts &&\n webfontUrls?.length > 0 &&\n webfontUrls.map((webfont) => <FontLoader key={webfont} url={webfont} />)}\n <AntdThemeProvider<LobeCustomToken>\n customStylish={stylish}\n customToken={token}\n theme={theme}\n {...rest}\n >\n <AntdConfigProvider>\n <EssentialStyle />\n {enableGlobalStyle && <GlobalStyle />}\n\n <App\n className={className}\n style={{ isolation: 'isolate', minHeight: 'inherit', width: 'inherit', ...style }}\n >\n <div id={appId} style={contentsStyle}>\n <AppElementContext value={appRef}>\n {children}\n {/*\n In-tree portal host for Base UI floating components\n (Select, Combobox, etc.). Keeping it inside `<App>` keeps\n the antd-style / emotion theme cascade intact so popups\n render with the correct tokens, while the layout-bearing\n block lets Base UI's Portal actually mount — the outer\n wrapper uses `display: contents` and cannot host portals.\n */}\n <div data-lobe-portal-host=\"\" ref={setAppRef} style={hostPortalHostStyle} />\n </AppElementContext>\n </div>\n </App>\n </AntdConfigProvider>\n </AntdThemeProvider>\n </>\n );\n },\n);\n\nThemeProvider.displayName = 'LobeThemeProvider';\n\nexport default ThemeProvider;\n\nconst hostPortalHostStyle: React.CSSProperties = {\n // `height: 0` keeps the host invisible and gives it no hit region of\n // its own; absolute children (Base UI Positioner) have their own hit\n // region, so we must NOT set `pointer-events: none` here — it would\n // be inherited by popup descendants and break clicks/hover.\n height: 0,\n left: 0,\n // `position: fixed` keeps a stacking context so portaled popups can\n // win over sibling z-indexes. `right: 0` (instead of `width: 0`)\n // gives the host a full viewport-width containing block — without it,\n // Base UI Positioner uses `position: absolute` against a 0-width\n // containing block and collapses text to one character per line.\n position: 'fixed',\n right: 0,\n top: 0,\n zIndex: 1100,\n};\n\nconst contentsStyle: React.CSSProperties = {\n display: 'contents',\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,MAAMA,kBAAgB,MACnB,EACC,QAAQ,mBACR,UACA,eACA,aACA,oBAAoB,MACpB,oBAAoB,MACpB,aACA,cAAc,CAAC,GACf,WACA,OACA,OAAO,WACP,GAAG,WACC;CACJ,MAAM,YAAY,SAAS;CAC3B,MAAM,CAAC,QAAQ,aAAa,SAAgC,IAAI;CAEhE,MAAM,cAAc,cAEhB,eAAe;EACb,UAAU;GACR,MAAM;GACN,KAAK;GACL,SAAS;EACX,CAAC;EACD,UAAU;GACR,MAAM;G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EAAA,CAAA;AAEN,CACF;AAEA,gBAAc,cAAc;AAI5B,MAAM,sBAA2C;CAK/C,QAAQ;CACR,MAAM;CAMN,UAAU;CACV,OAAO;CACP,KAAK;CACL,QAAQ;AACV;AAEA,MAAM,gBAAqC,EACzC,SAAS,WACX"}
|
|
@@ -17,9 +17,7 @@ const GradientButton = memo(({ glow = true, children, className, size, disabled,
|
|
|
17
17
|
case "small":
|
|
18
18
|
borderRadius = cssVar.borderRadiusSM;
|
|
19
19
|
break;
|
|
20
|
-
default:
|
|
21
|
-
borderRadius = cssVar.borderRadius;
|
|
22
|
-
break;
|
|
20
|
+
default: borderRadius = cssVar.borderRadius;
|
|
23
21
|
}
|
|
24
22
|
return { "--gradient-button-border-radius": borderRadius };
|
|
25
23
|
}, [size, disabled]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GradientButton.mjs","names":[],"sources":["../../../src/awesome/GradientButton/GradientButton.tsx"],"sourcesContent":["'use client';\n\nimport { cssVar, cx, useThemeMode } from 'antd-style';\nimport { memo, useMemo } from 'react';\n\nimport Button from '@/Button';\n\nimport { styles } from './style';\nimport type { GradientButtonProps } from './type';\n\nconst GradientButton = memo<GradientButtonProps>(\n ({ glow = true, children, className, size, disabled, style, ...rest }) => {\n const { isDarkMode } = useThemeMode();\n\n // Convert size prop to CSS variable for borderRadius\n const cssVariables = useMemo<Record<string, string>>(() => {\n if (!size || disabled) return {} as Record<string, string>;\n let borderRadius: string;\n switch (size) {\n case 'large': {\n borderRadius = cssVar.borderRadiusLG;\n break;\n }\n case 'small': {\n borderRadius = cssVar.borderRadiusSM;\n break;\n }\n default: {\n borderRadius = cssVar.borderRadius;\n break;\n }\n }\n return {\n '--gradient-button-border-radius': borderRadius,\n };\n }, [size, disabled]);\n\n return (\n <Button\n disabled={disabled}\n size={size}\n variant={disabled ? undefined : 'text'}\n className={cx(\n !disabled && (isDarkMode ? styles.buttonDark : styles.buttonLight),\n className,\n )}\n style={{\n ...cssVariables,\n ...style,\n }}\n {...rest}\n >\n {glow && <div className={styles.glow} />}\n {children}\n </Button>\n );\n },\n);\n\nGradientButton.displayName = 'GradientButton';\n\nexport default GradientButton;\n"],"mappings":";;;;;;;AAUA,MAAM,iBAAiB,MACpB,EAAE,OAAO,MAAM,UAAU,WAAW,MAAM,UAAU,OAAO,GAAG,WAAW;CACxE,MAAM,EAAE,eAAe,aAAa;CAGpC,MAAM,eAAe,cAAsC;EACzD,IAAI,CAAC,QAAQ,UAAU,OAAO,CAAC;EAC/B,IAAI;EACJ,QAAQ,MAAR;GACE,KAAK;IACH,eAAe,OAAO;IACtB;GAEF,KAAK;IACH,eAAe,OAAO;IACtB;GAEF
|
|
1
|
+
{"version":3,"file":"GradientButton.mjs","names":[],"sources":["../../../src/awesome/GradientButton/GradientButton.tsx"],"sourcesContent":["'use client';\n\nimport { cssVar, cx, useThemeMode } from 'antd-style';\nimport { memo, useMemo } from 'react';\n\nimport Button from '@/Button';\n\nimport { styles } from './style';\nimport type { GradientButtonProps } from './type';\n\nconst GradientButton = memo<GradientButtonProps>(\n ({ glow = true, children, className, size, disabled, style, ...rest }) => {\n const { isDarkMode } = useThemeMode();\n\n // Convert size prop to CSS variable for borderRadius\n const cssVariables = useMemo<Record<string, string>>(() => {\n if (!size || disabled) return {} as Record<string, string>;\n let borderRadius: string;\n switch (size) {\n case 'large': {\n borderRadius = cssVar.borderRadiusLG;\n break;\n }\n case 'small': {\n borderRadius = cssVar.borderRadiusSM;\n break;\n }\n default: {\n borderRadius = cssVar.borderRadius;\n break;\n }\n }\n return {\n '--gradient-button-border-radius': borderRadius,\n };\n }, [size, disabled]);\n\n return (\n <Button\n disabled={disabled}\n size={size}\n variant={disabled ? undefined : 'text'}\n className={cx(\n !disabled && (isDarkMode ? styles.buttonDark : styles.buttonLight),\n className,\n )}\n style={{\n ...cssVariables,\n ...style,\n }}\n {...rest}\n >\n {glow && <div className={styles.glow} />}\n {children}\n </Button>\n );\n },\n);\n\nGradientButton.displayName = 'GradientButton';\n\nexport default GradientButton;\n"],"mappings":";;;;;;;AAUA,MAAM,iBAAiB,MACpB,EAAE,OAAO,MAAM,UAAU,WAAW,MAAM,UAAU,OAAO,GAAG,WAAW;CACxE,MAAM,EAAE,eAAe,aAAa;CAGpC,MAAM,eAAe,cAAsC;EACzD,IAAI,CAAC,QAAQ,UAAU,OAAO,CAAC;EAC/B,IAAI;EACJ,QAAQ,MAAR;GACE,KAAK;IACH,eAAe,OAAO;IACtB;GAEF,KAAK;IACH,eAAe,OAAO;IACtB;GAEF,SACE,eAAe,OAAO;EAG1B;EACA,OAAO,EACL,mCAAmC,aACrC;CACF,GAAG,CAAC,MAAM,QAAQ,CAAC;CAEnB,OACE,qBAAC,QAAD;EACY;EACJ;EACN,SAAS,WAAW,KAAA,IAAY;EAChC,WAAW,GACT,CAAC,aAAa,aAAa,OAAO,aAAa,OAAO,cACtD,SACF;EACA,OAAO;GACL,GAAG;GACH,GAAG;EACL;EACA,GAAI;EAZN,UAAA,CAcG,QAAQ,oBAAC,OAAD,EAAK,WAAW,OAAO,KAAO,CAAA,GACtC,QACK;;AAEZ,CACF;AAEA,eAAe,cAAc"}
|
|
@@ -18,8 +18,9 @@ const Spotlight = memo(({ className, size = 64, ...properties }) => {
|
|
|
18
18
|
size,
|
|
19
19
|
outside
|
|
20
20
|
]);
|
|
21
|
+
const spotlightStyle = isDarkMode ? outside ? styles.spotlightDarkOutside : styles.spotlightDark : outside ? styles.spotlightLightOutside : styles.spotlightLight;
|
|
21
22
|
return /* @__PURE__ */ jsx("div", {
|
|
22
|
-
className: cx(
|
|
23
|
+
className: cx(spotlightStyle, className),
|
|
23
24
|
ref: reference,
|
|
24
25
|
style: cssVariables,
|
|
25
26
|
...properties
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Spotlight.mjs","names":[],"sources":["../../../src/awesome/Spotlight/Spotlight.tsx"],"sourcesContent":["'use client';\n\nimport { cx, useThemeMode } from 'antd-style';\nimport { memo, useMemo } from 'react';\n\nimport { styles } from './style';\nimport type { SpotlightProps } from './type';\nimport { useMouseOffset } from './useMouseOffset';\n\nconst Spotlight = memo<SpotlightProps>(({ className, size = 64, ...properties }) => {\n const [offset, outside, reference] = useMouseOffset();\n const { isDarkMode } = useThemeMode();\n\n const cssVariables = useMemo<Record<string, string>>(\n () => ({\n '--spotlight-opacity': outside ? '0' : '0.1',\n '--spotlight-size': `${size}px`,\n '--spotlight-x': `${offset?.x ?? 0}px`,\n '--spotlight-y': `${offset?.y ?? 0}px`,\n }),\n [offset, size, outside],\n );\n\n const spotlightStyle = isDarkMode\n ? outside\n ? styles.spotlightDarkOutside\n : styles.spotlightDark\n : outside\n ? styles.spotlightLightOutside\n : styles.spotlightLight;\n\n return (\n <div\n className={cx(spotlightStyle, className)}\n ref={reference}\n style={cssVariables}\n {...properties}\n />\n );\n});\n\nSpotlight.displayName = 'Spotlight';\n\nexport default Spotlight;\n"],"mappings":";;;;;;;AASA,MAAM,YAAY,MAAsB,EAAE,WAAW,OAAO,IAAI,GAAG,iBAAiB;CAClF,MAAM,CAAC,QAAQ,SAAS,aAAa,eAAe;CACpD,MAAM,EAAE,eAAe,aAAa;CAEpC,MAAM,eAAe,eACZ;EACL,uBAAuB,UAAU,MAAM;EACvC,oBAAoB,GAAG,KAAK;EAC5B,iBAAiB,GAAG,QAAQ,KAAK,EAAE;EACnC,iBAAiB,GAAG,QAAQ,KAAK,EAAE;CACrC,IACA;EAAC;EAAQ;EAAM;CAAO,CACxB;
|
|
1
|
+
{"version":3,"file":"Spotlight.mjs","names":[],"sources":["../../../src/awesome/Spotlight/Spotlight.tsx"],"sourcesContent":["'use client';\n\nimport { cx, useThemeMode } from 'antd-style';\nimport { memo, useMemo } from 'react';\n\nimport { styles } from './style';\nimport type { SpotlightProps } from './type';\nimport { useMouseOffset } from './useMouseOffset';\n\nconst Spotlight = memo<SpotlightProps>(({ className, size = 64, ...properties }) => {\n const [offset, outside, reference] = useMouseOffset();\n const { isDarkMode } = useThemeMode();\n\n const cssVariables = useMemo<Record<string, string>>(\n () => ({\n '--spotlight-opacity': outside ? '0' : '0.1',\n '--spotlight-size': `${size}px`,\n '--spotlight-x': `${offset?.x ?? 0}px`,\n '--spotlight-y': `${offset?.y ?? 0}px`,\n }),\n [offset, size, outside],\n );\n\n const spotlightStyle = isDarkMode\n ? outside\n ? styles.spotlightDarkOutside\n : styles.spotlightDark\n : outside\n ? styles.spotlightLightOutside\n : styles.spotlightLight;\n\n return (\n <div\n className={cx(spotlightStyle, className)}\n ref={reference}\n style={cssVariables}\n {...properties}\n />\n );\n});\n\nSpotlight.displayName = 'Spotlight';\n\nexport default Spotlight;\n"],"mappings":";;;;;;;AASA,MAAM,YAAY,MAAsB,EAAE,WAAW,OAAO,IAAI,GAAG,iBAAiB;CAClF,MAAM,CAAC,QAAQ,SAAS,aAAa,eAAe;CACpD,MAAM,EAAE,eAAe,aAAa;CAEpC,MAAM,eAAe,eACZ;EACL,uBAAuB,UAAU,MAAM;EACvC,oBAAoB,GAAG,KAAK;EAC5B,iBAAiB,GAAG,QAAQ,KAAK,EAAE;EACnC,iBAAiB,GAAG,QAAQ,KAAK,EAAE;CACrC,IACA;EAAC;EAAQ;EAAM;CAAO,CACxB;CAEA,MAAM,iBAAiB,aACnB,UACE,OAAO,uBACP,OAAO,gBACT,UACE,OAAO,wBACP,OAAO;CAEb,OACE,oBAAC,OAAD;EACE,WAAW,GAAG,gBAAgB,SAAS;EACvC,KAAK;EACL,OAAO;EACP,GAAI;CACL,CAAA;AAEL,CAAC;AAED,UAAU,cAAc"}
|