@ant-design/agentic-ui 2.30.30 → 2.30.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/AILabel/index.d.ts +2 -0
  2. package/dist/AILabel/index.js +4 -2
  3. package/dist/AgentRunBar/Robot.js +0 -1
  4. package/dist/AgentRunBar/index.js +1 -0
  5. package/dist/AgenticLayout/index.js +1 -0
  6. package/dist/AnswerAlert/index.js +1 -0
  7. package/dist/BackTo/ScrollVisibleButton.d.ts +2 -0
  8. package/dist/BackTo/ScrollVisibleButton.js +4 -2
  9. package/dist/Bubble/AIBubble.js +6 -3
  10. package/dist/Bubble/List/PureBubbleList.js +24 -1
  11. package/dist/Bubble/List/index.js +7 -5
  12. package/dist/Bubble/MessagesContent/BubbleExtra.js +4 -2
  13. package/dist/Bubble/style.js +0 -1
  14. package/dist/ChatBootPage/ButtonTab.js +1 -0
  15. package/dist/ChatBootPage/ButtonTabGroup.js +1 -0
  16. package/dist/ChatBootPage/CaseReply.js +1 -0
  17. package/dist/ChatBootPage/Title.js +1 -0
  18. package/dist/ChatLayout/index.js +1 -0
  19. package/dist/Components/ActionIconBox/index.js +8 -8
  20. package/dist/Components/ActionItemBox/ActionItemBox.js +1 -0
  21. package/dist/Components/Button/IconButton/index.js +1 -0
  22. package/dist/Components/Button/SwitchButton/index.js +1 -0
  23. package/dist/Components/Button/ToggleButton/index.js +1 -0
  24. package/dist/Components/GradientText/index.js +1 -0
  25. package/dist/Components/LayoutHeader/index.js +2 -1
  26. package/dist/Components/Loading/Loading.js +2 -0
  27. package/dist/Components/Robot/index.js +1 -0
  28. package/dist/Components/SuggestionList/index.js +1 -0
  29. package/dist/Components/TextAnimate/index.js +1 -0
  30. package/dist/Components/TypingAnimation/index.js +2 -1
  31. package/dist/Components/VisualList/index.js +3 -0
  32. package/dist/Components/lotties/ThreeThinkingLottie/index.d.ts +68 -0
  33. package/dist/Components/lotties/ThreeThinkingLottie/index.js +151 -0
  34. package/dist/Components/lotties/ThreeThinkingLottie/three-thinking.json +130 -0
  35. package/dist/Components/lotties/index.d.ts +1 -0
  36. package/dist/Components/lotties/index.js +1 -0
  37. package/dist/History/index.js +1 -0
  38. package/dist/Hooks/useLanguage.d.ts +1 -0
  39. package/dist/I18n/locales.d.ts +1 -0
  40. package/dist/I18n/locales.js +2 -0
  41. package/dist/MarkdownEditor/BaseMarkdownEditor.js +2 -0
  42. package/dist/MarkdownEditor/editor/parser/parse/parseHtml.js +15 -6
  43. package/dist/MarkdownEditor/style.js +0 -4
  44. package/dist/MarkdownInputField/SendButton/index.d.ts +2 -2
  45. package/dist/MarkdownInputField/SendButton/index.js +44 -26
  46. package/dist/MarkdownInputField/SendButton/sendButtonPalette.d.ts +36 -0
  47. package/dist/MarkdownInputField/SendButton/sendButtonPalette.js +247 -0
  48. package/dist/MarkdownInputField/SendButton/style.js +3 -3
  49. package/dist/MarkdownInputField/style.js +3 -1
  50. package/dist/MarkdownRenderer/AnimationText.js +1 -2
  51. package/dist/MarkdownRenderer/CharacterQueue.js +3 -0
  52. package/dist/MarkdownRenderer/MarkdownRenderer.js +6 -18
  53. package/dist/MarkdownRenderer/markdownReactShared.d.ts +2 -1
  54. package/dist/MarkdownRenderer/markdownReactShared.js +57 -19
  55. package/dist/MarkdownRenderer/streaming/MarkdownBlockPiece.js +14 -10
  56. package/dist/MarkdownRenderer/streaming/fenceTracker.d.ts +7 -0
  57. package/dist/MarkdownRenderer/streaming/fenceTracker.js +28 -0
  58. package/dist/MarkdownRenderer/streaming/lastBlockThrottle.js +3 -1
  59. package/dist/MarkdownRenderer/streaming/useShallowMemo.d.ts +1 -0
  60. package/dist/MarkdownRenderer/streaming/useShallowMemo.js +36 -0
  61. package/dist/MarkdownRenderer/streaming/useStreamingMarkdownReact.js +6 -3
  62. package/dist/MarkdownRenderer/useStreaming.js +43 -41
  63. package/dist/Plugins/chart/components/ChartContainer/ChartContainer.d.ts +13 -3
  64. package/dist/Plugins/chart/components/ChartContainer/ChartContainer.js +19 -4
  65. package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundary.d.ts +2 -0
  66. package/dist/Plugins/chart/hooks/index.d.ts +2 -0
  67. package/dist/Plugins/chart/hooks/index.js +1 -0
  68. package/dist/Plugins/chart/hooks/useDetectTheme.d.ts +46 -0
  69. package/dist/Plugins/chart/hooks/useDetectTheme.js +222 -0
  70. package/dist/Schema/SchemaEditor/index.js +1 -0
  71. package/dist/Schema/SchemaForm/index.js +1 -0
  72. package/dist/TaskList/TaskList.js +45 -16
  73. package/dist/TaskList/components/TaskListItem.js +2 -1
  74. package/dist/TaskList/constants.d.ts +1 -1
  75. package/dist/TaskList/constants.js +9 -4
  76. package/dist/TaskList/style.js +30 -12
  77. package/dist/ThoughtChainList/index.js +1 -0
  78. package/dist/ToolUseBar/index.js +7 -6
  79. package/dist/ToolUseBarThink/index.d.ts +0 -23
  80. package/dist/ToolUseBarThink/index.js +178 -315
  81. package/dist/ToolUseBarThink/style.js +61 -52
  82. package/dist/Types/quicklink.d.ts +1 -1
  83. package/dist/WelcomeMessage/index.js +1 -0
  84. package/dist/Workspace/File/FileTree/FileTreeComponent.d.ts +4 -0
  85. package/dist/Workspace/File/FileTree/FileTreeComponent.js +283 -0
  86. package/dist/Workspace/File/FileTree/index.d.ts +2 -0
  87. package/dist/Workspace/File/FileTree/index.js +1 -0
  88. package/dist/Workspace/File/FileTree/style.d.ts +8 -0
  89. package/dist/Workspace/File/FileTree/style.js +80 -0
  90. package/dist/Workspace/File/index.d.ts +2 -1
  91. package/dist/Workspace/File/index.js +1 -0
  92. package/dist/Workspace/index.d.ts +4 -2
  93. package/dist/Workspace/index.js +73 -36
  94. package/dist/Workspace/types.d.ts +70 -2
  95. package/package.json +2 -1
@@ -46,6 +46,21 @@ function _iterable_to_array_limit(arr, i) {
46
46
  function _non_iterable_rest() {
47
47
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
48
48
  }
49
+ function _object_spread(target) {
50
+ for(var i = 1; i < arguments.length; i++){
51
+ var source = arguments[i] != null ? arguments[i] : {};
52
+ var ownKeys = Object.keys(source);
53
+ if (typeof Object.getOwnPropertySymbols === "function") {
54
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
55
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
56
+ }));
57
+ }
58
+ ownKeys.forEach(function(key) {
59
+ _define_property(target, key, source[key]);
60
+ });
61
+ }
62
+ return target;
63
+ }
49
64
  function _sliced_to_array(arr, i) {
50
65
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
51
66
  }
@@ -58,6 +73,7 @@ function _unsupported_iterable_to_array(o, minLen) {
58
73
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
59
74
  }
60
75
  import { useCallback, useEffect, useRef, useState } from "react";
76
+ import { INITIAL_FENCE_STATE, updateFenceStateForLine } from "./streaming/fenceTracker";
61
77
  /**
62
78
  * 流式 token 缓存类型。
63
79
  * 在流式场景中,部分 Markdown token(link、image、table 等)可能处于未闭合状态,
@@ -265,7 +281,9 @@ var getInitialCache = function getInitialCache() {
265
281
  pending: '',
266
282
  token: "text",
267
283
  processedLength: 0,
268
- completeMarkdown: ''
284
+ completeMarkdown: '',
285
+ fenceState: _object_spread({}, INITIAL_FENCE_STATE),
286
+ currentLine: ''
269
287
  };
270
288
  };
271
289
  var getStreamingOutput = function getStreamingOutput(cache) {
@@ -273,36 +291,6 @@ var getStreamingOutput = function getStreamingOutput(cache) {
273
291
  if (cache.pending) return STREAMING_LOADING_PLACEHOLDER;
274
292
  return '';
275
293
  };
276
- var isInCodeBlock = function isInCodeBlock(text) {
277
- var isFinalChunk = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
278
- var lines = text.split('\n');
279
- var inFenced = false;
280
- var fenceChar = '';
281
- var fenceLen = 0;
282
- for(var i = 0; i < lines.length; i++){
283
- var line = lines[i].endsWith('\r') ? lines[i].slice(0, -1) : lines[i];
284
- var match = line.match(/^(`{3,}|~{3,})(.*)$/);
285
- if (match) {
286
- var fence = match[1];
287
- var after = match[2];
288
- var char = fence[0];
289
- var len = fence.length;
290
- if (!inFenced) {
291
- inFenced = true;
292
- fenceChar = char;
293
- fenceLen = len;
294
- } else {
295
- var isValidEnd = char === fenceChar && len >= fenceLen && /^\s*$/.test(after);
296
- if (isValidEnd && (isFinalChunk || i < lines.length - 1)) {
297
- inFenced = false;
298
- fenceChar = '';
299
- fenceLen = 0;
300
- }
301
- }
302
- }
303
- }
304
- return inFenced;
305
- };
306
294
  /** 流式 token 缓存——暂缓不完整的 link/image/table 等,避免 parser 错误解析 */ export var useStreaming = function useStreaming(input, enabled) {
307
295
  var _useState = _sliced_to_array(useState(''), 2), output = _useState[0], setOutput = _useState[1];
308
296
  var cacheRef = useRef(getInitialCache());
@@ -319,22 +307,36 @@ var isInCodeBlock = function isInCodeBlock(text) {
319
307
  var cache = cacheRef.current;
320
308
  var chunk = text.slice(cache.processedLength);
321
309
  if (!chunk) return;
310
+ // 非前缀重置后重建围栏状态(全量兜底,仅此处 O(n))
311
+ if (cache.processedLength === 0 && text.length > 0) {
312
+ var existingText = cache.completeMarkdown + cache.pending;
313
+ if (existingText.length === 0) {
314
+ cache.fenceState = _object_spread({}, INITIAL_FENCE_STATE);
315
+ cache.currentLine = '';
316
+ }
317
+ }
322
318
  cache.processedLength += chunk.length;
323
- var wasInCodeBlock = isInCodeBlock(cache.completeMarkdown + cache.pending);
324
319
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
325
320
  try {
326
321
  for(var _iterator = chunk[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
327
322
  var char = _step.value;
328
323
  cache.pending += char;
329
- var inCodeBlock = isInCodeBlock(cache.completeMarkdown + cache.pending);
330
- if (inCodeBlock) {
331
- wasInCodeBlock = true;
332
- continue;
333
- }
334
- if (wasInCodeBlock) {
335
- wasInCodeBlock = false;
336
- commitCache(cache);
337
- continue;
324
+ if (char === '\n') {
325
+ var prevInFenced = cache.fenceState.inFenced;
326
+ cache.fenceState = updateFenceStateForLine(cache.fenceState, cache.currentLine);
327
+ cache.currentLine = '';
328
+ if (cache.fenceState.inFenced) {
329
+ continue;
330
+ }
331
+ if (prevInFenced && !cache.fenceState.inFenced) {
332
+ commitCache(cache);
333
+ continue;
334
+ }
335
+ } else {
336
+ cache.currentLine += char;
337
+ if (cache.fenceState.inFenced) {
338
+ continue;
339
+ }
338
340
  }
339
341
  if (cache.token === "text") {
340
342
  var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
@@ -7,6 +7,8 @@ export interface ChartContainerProps {
7
7
  style?: React.CSSProperties;
8
8
  /** 图表主题 */
9
9
  theme?: 'light' | 'dark';
10
+ /** 是否自动检测主题(检测 html[data-theme='dark'] 和 CSS 变量亮度) */
11
+ autoDetectTheme?: boolean;
10
12
  /** 是否为移动端 */
11
13
  isMobile?: boolean;
12
14
  /** 图表变体 */
@@ -42,7 +44,7 @@ export interface ChartContainerRef {
42
44
  * @param {string} [props.className] - 自定义CSS类名
43
45
  * @param {React.ReactNode} props.children - 子元素
44
46
  * @param {React.CSSProperties} [props.style] - 样式对象
45
- * @param {'light' | 'dark'} [props.theme='light'] - 图表主题
47
+ * @param {'light' | 'dark'} [props.theme] - 图表主题,不传时自动检测(检测 html[data-theme='dark'] CSS 变量亮度)
46
48
  * @param {boolean} [props.isMobile=false] - 是否为移动端
47
49
  * @param {object} [props.errorBoundary] - 错误边界配置
48
50
  * @param {boolean} [props.errorBoundary.enabled=true] - 是否启用错误边界
@@ -52,17 +54,24 @@ export interface ChartContainerRef {
52
54
  *
53
55
  * @example
54
56
  * ```tsx
55
- * // 基础使用
57
+ * // 基础使用(自动检测主题)
56
58
  * <ChartContainer
57
59
  * baseClassName="area-chart-container"
58
60
  * className="custom-chart"
59
- * theme="light"
60
61
  * isMobile={false}
61
62
  * style={{ width: 600, height: 400 }}
62
63
  * >
63
64
  * <div>图表内容</div>
64
65
  * </ChartContainer>
65
66
  *
67
+ * // 显式指定主题
68
+ * <ChartContainer
69
+ * baseClassName="area-chart-container"
70
+ * theme="dark"
71
+ * >
72
+ * <div>图表内容</div>
73
+ * </ChartContainer>
74
+ *
66
75
  * // 自定义错误边界
67
76
  * <ChartContainer
68
77
  * baseClassName="line-chart-container"
@@ -98,6 +107,7 @@ export interface ChartContainerRef {
98
107
  * - 内置错误边界保护,防止图表错误影响整个应用
99
108
  * - 错误边界默认启用,可通过配置禁用或自定义
100
109
  * - `theme="dark"` 时在本容器内嵌套 Ant Design 暗色算法,工具栏/筛选等 antd 控件与画布暗色一致(嵌套容器不重复包裹)
110
+ * - 支持自动主题检测:当 theme 未指定时,会自动检测 html[data-theme='dark'] 属性或 CSS 变量亮度判断主题
101
111
  */
102
112
  declare const ChartContainer: React.FC<ChartContainerProps & {
103
113
  baseClassName: string;
@@ -65,6 +65,7 @@ function _object_without_properties_loose(source, excluded) {
65
65
  import { ConfigProvider, theme as antdTheme } from "antd";
66
66
  import classNames from "clsx";
67
67
  import React from "react";
68
+ import { useDetectTheme } from "../../hooks";
68
69
  import { ChartDarkAntdProvidedContext, useChartDarkAntdProvided } from "./ChartDarkAntdContext";
69
70
  import ChartErrorBoundary from "./ChartErrorBoundary";
70
71
  import { useStyle } from "./style";
@@ -81,7 +82,7 @@ import { useStyle } from "./style";
81
82
  * @param {string} [props.className] - 自定义CSS类名
82
83
  * @param {React.ReactNode} props.children - 子元素
83
84
  * @param {React.CSSProperties} [props.style] - 样式对象
84
- * @param {'light' | 'dark'} [props.theme='light'] - 图表主题
85
+ * @param {'light' | 'dark'} [props.theme] - 图表主题,不传时自动检测(检测 html[data-theme='dark'] CSS 变量亮度)
85
86
  * @param {boolean} [props.isMobile=false] - 是否为移动端
86
87
  * @param {object} [props.errorBoundary] - 错误边界配置
87
88
  * @param {boolean} [props.errorBoundary.enabled=true] - 是否启用错误边界
@@ -91,17 +92,24 @@ import { useStyle } from "./style";
91
92
  *
92
93
  * @example
93
94
  * ```tsx
94
- * // 基础使用
95
+ * // 基础使用(自动检测主题)
95
96
  * <ChartContainer
96
97
  * baseClassName="area-chart-container"
97
98
  * className="custom-chart"
98
- * theme="light"
99
99
  * isMobile={false}
100
100
  * style={{ width: 600, height: 400 }}
101
101
  * >
102
102
  * <div>图表内容</div>
103
103
  * </ChartContainer>
104
104
  *
105
+ * // 显式指定主题
106
+ * <ChartContainer
107
+ * baseClassName="area-chart-container"
108
+ * theme="dark"
109
+ * >
110
+ * <div>图表内容</div>
111
+ * </ChartContainer>
112
+ *
105
113
  * // 自定义错误边界
106
114
  * <ChartContainer
107
115
  * baseClassName="line-chart-container"
@@ -137,8 +145,9 @@ import { useStyle } from "./style";
137
145
  * - 内置错误边界保护,防止图表错误影响整个应用
138
146
  * - 错误边界默认启用,可通过配置禁用或自定义
139
147
  * - `theme="dark"` 时在本容器内嵌套 Ant Design 暗色算法,工具栏/筛选等 antd 控件与画布暗色一致(嵌套容器不重复包裹)
148
+ * - 支持自动主题检测:当 theme 未指定时,会自动检测 html[data-theme='dark'] 属性或 CSS 变量亮度判断主题
140
149
  */ var ChartContainer = function ChartContainer(_0) {
141
- var baseClassName = _0.baseClassName, className = _0.className, children = _0.children, style = _0.style, classNamesProp = _0.classNames, stylesProp = _0.styles, _0_theme = _0.theme, theme = _0_theme === void 0 ? 'light' : _0_theme, _0_variant = _0.variant, variant = _0_variant === void 0 ? 'default' : _0_variant, _0_isMobile = _0.isMobile, isMobile = _0_isMobile === void 0 ? false : _0_isMobile, _0_errorBoundary = _0.errorBoundary, errorBoundary = _0_errorBoundary === void 0 ? {
150
+ var baseClassName = _0.baseClassName, className = _0.className, children = _0.children, style = _0.style, classNamesProp = _0.classNames, stylesProp = _0.styles, themeProp = _0.theme, _0_autoDetectTheme = _0.autoDetectTheme, autoDetectTheme = _0_autoDetectTheme === void 0 ? true : _0_autoDetectTheme, _0_variant = _0.variant, variant = _0_variant === void 0 ? 'default' : _0_variant, _0_isMobile = _0.isMobile, isMobile = _0_isMobile === void 0 ? false : _0_isMobile, _0_errorBoundary = _0.errorBoundary, errorBoundary = _0_errorBoundary === void 0 ? {
142
151
  enabled: true
143
152
  } : _0_errorBoundary, restProps = _object_without_properties(_0, [
144
153
  "baseClassName",
@@ -148,12 +157,18 @@ import { useStyle } from "./style";
148
157
  "classNames",
149
158
  "styles",
150
159
  "theme",
160
+ "autoDetectTheme",
151
161
  "variant",
152
162
  "isMobile",
153
163
  "errorBoundary"
154
164
  ]);
155
165
  var _useStyle = useStyle(baseClassName), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
156
166
  var ancestorDarkAntdProvided = useChartDarkAntdProvided();
167
+ // 自动检测主题:当 themeProp 未指定且 autoDetectTheme 为 true 时,自动检测
168
+ var detectedTheme = useDetectTheme({
169
+ observeChanges: autoDetectTheme
170
+ });
171
+ var theme = themeProp !== null && themeProp !== void 0 ? themeProp : autoDetectTheme ? detectedTheme : 'light';
157
172
  var wrapDarkAntd = theme === 'dark' && !ancestorDarkAntdProvided;
158
173
  // 构建动态类名
159
174
  var combinedClassName = classNames(baseClassName, hashId, theme === 'light' && "".concat(baseClassName, "-light-theme"), theme === 'dark' && "".concat(baseClassName, "-dark-theme"), isMobile && "".concat(baseClassName, "-mobile"), !isMobile && "".concat(baseClassName, "-desktop"), variant === 'outline' && "".concat(baseClassName, "-outline"), variant === 'borderless' && "".concat(baseClassName, "-borderless"), className, classNamesProp === null || classNamesProp === void 0 ? void 0 : classNamesProp.root);
@@ -290,6 +290,7 @@ declare class ChartErrorBoundary extends React.Component<ChartErrorBoundaryProps
290
290
  'workspace.browser': string;
291
291
  'workspace.task': string;
292
292
  'workspace.file': string;
293
+ 'workspace.fileTree': string;
293
294
  'workspace.custom': string;
294
295
  'workspace.terminalExecution': string;
295
296
  'workspace.createHtmlFile': string;
@@ -715,6 +716,7 @@ declare class ChartErrorBoundary extends React.Component<ChartErrorBoundaryProps
715
716
  'workspace.browser': string;
716
717
  'workspace.task': string;
717
718
  'workspace.file': string;
719
+ 'workspace.fileTree': string;
718
720
  'workspace.custom': string;
719
721
  'workspace.terminalExecution': string;
720
722
  'workspace.createHtmlFile': string;
@@ -7,4 +7,6 @@ export { useChartDataFilter } from './useChartDataFilter';
7
7
  export type { ChartStatisticConfig, StatisticConfigType, } from './useChartStatistic';
8
8
  export { useChartStatistics } from './useChartStatistics';
9
9
  export { useChartTheme } from './useChartTheme';
10
+ export { useDetectTheme } from './useDetectTheme';
11
+ export type { DetectThemeOptions } from './useDetectTheme';
10
12
  export { useResponsiveSize } from './useResponsiveSize';
@@ -5,4 +5,5 @@
5
5
  */ export { useChartDataFilter } from "./useChartDataFilter";
6
6
  export { useChartStatistics } from "./useChartStatistics";
7
7
  export { useChartTheme } from "./useChartTheme";
8
+ export { useDetectTheme } from "./useDetectTheme";
8
9
  export { useResponsiveSize } from "./useResponsiveSize";
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 主题检测配置选项
3
+ */
4
+ export interface DetectThemeOptions {
5
+ /**
6
+ * 用于检测主题的 CSS 变量名
7
+ * @default '--color-gray-bg-page'
8
+ */
9
+ cssVariable?: string;
10
+ /**
11
+ * 亮度阈值,低于此值认为是暗色主题
12
+ * @default 145
13
+ */
14
+ darknessThreshold?: number;
15
+ /**
16
+ * 是否监听主题变化
17
+ * @default true
18
+ */
19
+ observeChanges?: boolean;
20
+ }
21
+ /**
22
+ * 自动检测当前主题的 Hook
23
+ *
24
+ * 检测策略(按优先级):
25
+ * 1. 检查 `html[data-theme='dark']` 属性
26
+ * 2. 检查指定 CSS 变量的亮度值
27
+ * 3. 检查 `--color-gray-bg-page` 的亮度值
28
+ *
29
+ * @param options 检测配置选项
30
+ * @returns 检测到的主题 'light' | 'dark'
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * const theme = useDetectTheme();
35
+ * // theme: 'light' | 'dark'
36
+ *
37
+ * // 自定义配置
38
+ * const theme = useDetectTheme({
39
+ * cssVariable: '--color-primary-bg-page',
40
+ * darknessThreshold: 128,
41
+ * observeChanges: true,
42
+ * });
43
+ * ```
44
+ */
45
+ export declare const useDetectTheme: (options?: DetectThemeOptions) => 'light' | 'dark';
46
+ export default useDetectTheme;
@@ -0,0 +1,222 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _iterable_to_array_limit(arr, i) {
10
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
+ if (_i == null) return;
12
+ var _arr = [];
13
+ var _n = true;
14
+ var _d = false;
15
+ var _s, _e;
16
+ try {
17
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
+ _arr.push(_s.value);
19
+ if (i && _arr.length === i) break;
20
+ }
21
+ } catch (err) {
22
+ _d = true;
23
+ _e = err;
24
+ } finally{
25
+ try {
26
+ if (!_n && _i["return"] != null) _i["return"]();
27
+ } finally{
28
+ if (_d) throw _e;
29
+ }
30
+ }
31
+ return _arr;
32
+ }
33
+ function _non_iterable_rest() {
34
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ }
36
+ function _sliced_to_array(arr, i) {
37
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
+ }
39
+ function _unsupported_iterable_to_array(o, minLen) {
40
+ if (!o) return;
41
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
42
+ var n = Object.prototype.toString.call(o).slice(8, -1);
43
+ if (n === "Object" && o.constructor) n = o.constructor.name;
44
+ if (n === "Map" || n === "Set") return Array.from(n);
45
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
+ }
47
+ import { useEffect, useState } from "react";
48
+ /**
49
+ * 解析颜色值为 RGB
50
+ */ var parseColorToRgb = function parseColorToRgb(color) {
51
+ var normalizedColor = color.trim().toLowerCase();
52
+ // 短十六进制格式 #rgb
53
+ var shortHexMatch = normalizedColor.match(/^#([0-9a-f]{3})$/i);
54
+ if (shortHexMatch) {
55
+ var _shortHexMatch__split_map = _sliced_to_array(shortHexMatch[1].split('').map(function(char) {
56
+ return Number.parseInt(char + char, 16);
57
+ }), 3), r = _shortHexMatch__split_map[0], g = _shortHexMatch__split_map[1], b = _shortHexMatch__split_map[2];
58
+ return {
59
+ r: r,
60
+ g: g,
61
+ b: b
62
+ };
63
+ }
64
+ // 标准十六进制格式 #rrggbb
65
+ var hexMatch = normalizedColor.match(/^#([0-9a-f]{6})$/i);
66
+ if (hexMatch) {
67
+ return {
68
+ r: Number.parseInt(hexMatch[1].slice(0, 2), 16),
69
+ g: Number.parseInt(hexMatch[1].slice(2, 4), 16),
70
+ b: Number.parseInt(hexMatch[1].slice(4, 6), 16)
71
+ };
72
+ }
73
+ // rgb/rgba 格式
74
+ var rgbMatch = normalizedColor.match(/^rgba?\((\d{1,3})[\s,]+(\d{1,3})[\s,]+(\d{1,3})(?:[\s,]+[\d.]+)?\)$/i);
75
+ if (rgbMatch) {
76
+ return {
77
+ r: Number.parseInt(rgbMatch[1], 10),
78
+ g: Number.parseInt(rgbMatch[2], 10),
79
+ b: Number.parseInt(rgbMatch[3], 10)
80
+ };
81
+ }
82
+ return null;
83
+ };
84
+ /**
85
+ * 计算颜色的亮度
86
+ * 使用加权公式:Y = 0.299*R + 0.587*G + 0.114*B
87
+ */ var calculateBrightness = function calculateBrightness(color) {
88
+ var rgb = parseColorToRgb(color);
89
+ if (!rgb) return null;
90
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
91
+ };
92
+ /**
93
+ * 检测背景色是否为暗色
94
+ */ var isDarkBackground = function isDarkBackground(color) {
95
+ var threshold = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 145;
96
+ var brightness = calculateBrightness(color);
97
+ if (brightness === null) return false;
98
+ return brightness < threshold;
99
+ };
100
+ /**
101
+ * 检测 HTML 元素的 data-theme 属性是否为 dark
102
+ */ var checkDataTheme = function checkDataTheme() {
103
+ if (typeof document === 'undefined') return false;
104
+ var htmlElement = document.documentElement;
105
+ return htmlElement.getAttribute('data-theme') === 'dark';
106
+ };
107
+ /**
108
+ * 获取 CSS 变量的计算值
109
+ */ var getCSSVariableValue = function getCSSVariableValue(variableName) {
110
+ if (typeof window === 'undefined') return null;
111
+ var computedStyle = window.getComputedStyle(document.documentElement);
112
+ var value = computedStyle.getPropertyValue(variableName).trim();
113
+ return value || null;
114
+ };
115
+ /**
116
+ * 根据多种方式检测当前主题
117
+ */ var detectTheme = function detectTheme(cssVariable, darknessThreshold) {
118
+ // 1. 首先检查 html[data-theme='dark']
119
+ if (checkDataTheme()) {
120
+ return 'dark';
121
+ }
122
+ // 2. 检查 CSS 变量的亮度
123
+ var cssValue = getCSSVariableValue(cssVariable);
124
+ if (cssValue && isDarkBackground(cssValue, darknessThreshold)) {
125
+ return 'dark';
126
+ }
127
+ // 3. 检查背景色 CSS 变量
128
+ var bgColor = getCSSVariableValue('--color-gray-bg-page');
129
+ if (bgColor && isDarkBackground(bgColor, darknessThreshold)) {
130
+ return 'dark';
131
+ }
132
+ return 'light';
133
+ };
134
+ /**
135
+ * 自动检测当前主题的 Hook
136
+ *
137
+ * 检测策略(按优先级):
138
+ * 1. 检查 `html[data-theme='dark']` 属性
139
+ * 2. 检查指定 CSS 变量的亮度值
140
+ * 3. 检查 `--color-gray-bg-page` 的亮度值
141
+ *
142
+ * @param options 检测配置选项
143
+ * @returns 检测到的主题 'light' | 'dark'
144
+ *
145
+ * @example
146
+ * ```tsx
147
+ * const theme = useDetectTheme();
148
+ * // theme: 'light' | 'dark'
149
+ *
150
+ * // 自定义配置
151
+ * const theme = useDetectTheme({
152
+ * cssVariable: '--color-primary-bg-page',
153
+ * darknessThreshold: 128,
154
+ * observeChanges: true,
155
+ * });
156
+ * ```
157
+ */ export var useDetectTheme = function useDetectTheme() {
158
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
159
+ var _options_cssVariable = options.cssVariable, cssVariable = _options_cssVariable === void 0 ? '--color-gray-bg-page' : _options_cssVariable, _options_darknessThreshold = options.darknessThreshold, darknessThreshold = _options_darknessThreshold === void 0 ? 145 : _options_darknessThreshold, _options_observeChanges = options.observeChanges, observeChanges = _options_observeChanges === void 0 ? true : _options_observeChanges;
160
+ var _useState = _sliced_to_array(useState(function() {
161
+ return detectTheme(cssVariable, darknessThreshold);
162
+ }), 2), theme = _useState[0], setTheme = _useState[1];
163
+ useEffect(function() {
164
+ if (!observeChanges) return;
165
+ var updateTheme = function updateTheme() {
166
+ setTheme(detectTheme(cssVariable, darknessThreshold));
167
+ };
168
+ // 监听 data-theme 属性变化
169
+ var htmlElement = document.documentElement;
170
+ var observer = new MutationObserver(function(mutations) {
171
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
172
+ try {
173
+ for(var _iterator = mutations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
174
+ var mutation = _step.value;
175
+ if (mutation.type === 'attributes' && mutation.attributeName === 'data-theme') {
176
+ updateTheme();
177
+ break;
178
+ }
179
+ }
180
+ } catch (err) {
181
+ _didIteratorError = true;
182
+ _iteratorError = err;
183
+ } finally{
184
+ try {
185
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
186
+ _iterator.return();
187
+ }
188
+ } finally{
189
+ if (_didIteratorError) {
190
+ throw _iteratorError;
191
+ }
192
+ }
193
+ }
194
+ });
195
+ observer.observe(htmlElement, {
196
+ attributes: true,
197
+ attributeFilter: [
198
+ 'data-theme',
199
+ 'class',
200
+ 'style'
201
+ ]
202
+ });
203
+ // 监听 prefers-color-scheme 变化
204
+ var mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
205
+ var handleMediaChange = function handleMediaChange() {
206
+ updateTheme();
207
+ };
208
+ mediaQuery.addEventListener('change', handleMediaChange);
209
+ // 初始检测
210
+ updateTheme();
211
+ return function() {
212
+ observer.disconnect();
213
+ mediaQuery.removeEventListener('change', handleMediaChange);
214
+ };
215
+ }, [
216
+ cssVariable,
217
+ darknessThreshold,
218
+ observeChanges
219
+ ]);
220
+ return theme;
221
+ };
222
+ export default useDetectTheme;
@@ -442,6 +442,7 @@ import { useStyle } from "./style";
442
442
  ]);
443
443
  return wrapSSR(/*#__PURE__*/ React.createElement("div", {
444
444
  className: classNames(prefixCls, className, hashId),
445
+ "data-testid": prefixCls,
445
446
  style: {
446
447
  height: typeof height === 'number' ? "".concat(height, "px") : height
447
448
  }
@@ -452,6 +452,7 @@ import { I18nContext, compileTemplate } from "../../I18n";
452
452
  renderFormItem
453
453
  ]);
454
454
  return /*#__PURE__*/ React.createElement(Form, {
455
+ "data-testid": "schema-form",
455
456
  form: form,
456
457
  layout: "vertical",
457
458
  initialValues: defaultValues,