@zero-library/common 2.2.1 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -194,7 +194,7 @@ declare const _default$g: ({ fileUrl }: VideoPlayerProps) => react_jsx_runtime.J
194
194
  * Iframe组件属性接口
195
195
  */
196
196
  interface IframeProps {
197
- /** 默认主源 */
197
+ /** 默认主源 用于在内部区分来源 */
198
198
  defaultMainSource?: string;
199
199
  /** iframe ID */
200
200
  id?: string;
@@ -276,20 +276,18 @@ interface RenderMarkdownProps {
276
276
  content?: string;
277
277
  /** 搜索关键字 */
278
278
  searchValue?: string;
279
- /** 自定义组件映射 */
279
+ /** 自定义组件映射, 默认会传入loading、data 属性以及透传参数 */
280
280
  customComponents?: ComponentMapType;
281
- /** 内容变化回调 */
282
- onChange?: (value: string) => void;
283
- /** 部分内容变化回调 */
284
- onPartialChange?: (oldValue: string, newValue: string) => void;
281
+ /** 透传入自定义组件的参数方法 */
282
+ [key: string]: any;
285
283
  }
286
284
  /**
287
285
  * Markdown渲染组件
288
286
  * 将Markdown文本转换为HTML并渲染为React组件
289
- * 支持自定义组件、搜索高亮、内容编辑等功能
287
+ * 支持自定义组件、搜索高亮等功能
290
288
  * @param RenderMarkdownProps - 组件属性
291
289
  */
292
- declare const _default$c: ({ content, searchValue, customComponents, onChange, onPartialChange }: RenderMarkdownProps) => react_jsx_runtime.JSX.Element;
290
+ declare const _default$c: ({ content, searchValue, customComponents, ...rest }: RenderMarkdownProps) => react_jsx_runtime.JSX.Element;
293
291
 
294
292
  /**
295
293
  * 渲染控制对象类型
@@ -702,6 +700,22 @@ declare const objToOptions: (obj: Record<string, string> | string[], filter?: (k
702
700
  declare const arrToObj: <T>(arr: T[], key: string) => {
703
701
  [key: string]: T;
704
702
  };
703
+ /**
704
+ * setInterval函数返回的控制对象类型接口
705
+ * 提供对定时器运行状态的检查和取消操作
706
+ */
707
+ interface SetIntervalType {
708
+ /**
709
+ * 检查定时器是否正在运行
710
+ * @returns boolean - true表示正在运行,false表示已停止
711
+ */
712
+ isRun: () => boolean;
713
+ /**
714
+ * 取消定时器
715
+ * 调用后将停止后续的函数执行并清理资源
716
+ */
717
+ cancel: () => void;
718
+ }
705
719
  /**
706
720
  * 使用 setTimeout 模拟 setInterval,避免堆积
707
721
  *
@@ -1084,6 +1098,43 @@ declare function aesEncrypt<T = any>(data: T, key: string): string;
1084
1098
  * @returns 解密后的数据,解密失败时返回null
1085
1099
  */
1086
1100
  declare function aesDecrypt<T = any>(data: string, key: string): T | null;
1101
+ type SizeUnit = 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'PB';
1102
+ interface FormatSizeOptions {
1103
+ /** 起始单位,默认 KB */
1104
+ from?: SizeUnit;
1105
+ /** 保留小数位数,默认 2 */
1106
+ precision?: number;
1107
+ /** 是否去除多余的 0,如 1.00 -> 1 */
1108
+ trimZero?: boolean;
1109
+ /** 最大单位限制 */
1110
+ maxUnit?: SizeUnit;
1111
+ }
1112
+ /**
1113
+ * 格式化文件大小显示
1114
+ *
1115
+ * 将给定的数值按照指定单位转换为更友好的可读格式(如KB, MB, GB等)
1116
+ * 支持从不同单位开始转换,并可自定义精度和最大单位限制
1117
+ *
1118
+ * @param value - 需要格式化的数值(可以是数字或数字字符串)
1119
+ * @param options - 格式化选项
1120
+ * @param options.from - 输入数值的单位,默认为 'KB'
1121
+ * @param options.precision - 保留的小数位数,默认为 2
1122
+ * @param options.trimZero - 是否去除尾部的零,默认为 false
1123
+ * @param options.maxUnit - 最大转换单位,超过该单位则不再转换,默认无限制
1124
+ *
1125
+ * @returns 格式化后的文件大小字符串,如果输入无效则返回原值
1126
+ *
1127
+ * @example
1128
+ * formatSize(1024) // "1024.00KB"
1129
+ * formatSize(1024, { from: 'B' }) // "1.00KB"
1130
+ * formatSize(1024, { precision: 0 }) // "1024KB"
1131
+ * formatSize(1024, { trimZero: true }) // "1024KB"
1132
+ * formatSize(2048, { maxUnit: 'KB' }) // "2048.00KB" (不会转换为MB)
1133
+ *
1134
+ * @remarks
1135
+ * - 支持从 B, KB, MB, GB, TB, PB 等单位开始转换
1136
+ */
1137
+ declare function formatSize(value: number | string, options?: FormatSizeOptions): number | string;
1087
1138
 
1088
1139
  type DateType = string | number | Date | dayjs.Dayjs | null;
1089
1140
  /** 默认日期时间格式:年-月-日 时:分:秒 */
@@ -1847,6 +1898,19 @@ declare const RegDetailAddress: {
1847
1898
  pattern: RegExp;
1848
1899
  message: string;
1849
1900
  };
1901
+ /**
1902
+ * 密码强度验证规则
1903
+ *
1904
+ * 正则表达式要求:
1905
+ * 1. 长度在8到26位之间
1906
+ * 2. 必须包含至少一个字母(大小写均可)
1907
+ * 3. 必须包含至少一个数字
1908
+ * 4. 只能包含字母和数字(不允许特殊字符)
1909
+ */
1910
+ declare const RegPassword: {
1911
+ pattern: RegExp;
1912
+ message: string;
1913
+ };
1850
1914
  /**
1851
1915
  * 手机号或固定电话验证器
1852
1916
  * 验证输入是否符合手机号或固定电话格式
@@ -2163,4 +2227,4 @@ declare function createTokenManager({ key, storage }: TokenManagerProps): {
2163
2227
  clear: () => void;
2164
2228
  };
2165
2229
 
2166
- export { _default$m as AudioPlayer, type AudioPlayerProps, BusinessCode, type CacheMessage, type ComponentMapType, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, _default$l as FileIcon, type FileIconProps, _default$k as FilePreview, _default$j as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, HttpStatus, _default$f as Iframe, type IframeProps, _default$e as LazyComponent, type LazyComponentProps, _default$d as MarkdownEditor, type MarkdownEditorProps, _default$i as MarkdownPreview, type MarkdownPreviewProps, MultiEmailValidator, _default$h as PdfPreview, type PdfPreviewProps, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegSmsCode, RegTaxNo, RegTelePhone, type RenderControl, _default$c as RenderMarkdown, type RenderMarkdownProps, _default$b as RenderWrapper, type RenderWrapperProps, type RequestConfig, type SecureManagerProps, ThanNumLengthValidator, ThanNumValidator, type TokenManagerProps, _default$a as UserAvatar, type UserAvatarProps, _default$g as VideoPlayer, type VideoPlayerProps, type WebSocketProps, type WebSocketType, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, formatDate, formatNumberWithCommas, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, _default$8 as useAutoRefresh, _default$7 as useCountDown, _default$6 as useCreateValtioContext, _default$5 as useDebounce, _default$4 as useDeepEffect, _default$9 as useIframeRelayBridge, _default$3 as useRefState, _default$2 as useSyncInput, _default$1 as useThrottle, _default as useWebSocket };
2230
+ export { _default$m as AudioPlayer, type AudioPlayerProps, BusinessCode, type CacheMessage, type ComponentMapType, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, _default$l as FileIcon, type FileIconProps, _default$k as FilePreview, _default$j as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, type FormatSizeOptions, HttpStatus, _default$f as Iframe, type IframeProps, _default$e as LazyComponent, type LazyComponentProps, _default$d as MarkdownEditor, type MarkdownEditorProps, _default$i as MarkdownPreview, type MarkdownPreviewProps, MultiEmailValidator, _default$h as PdfPreview, type PdfPreviewProps, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegPassword, RegSmsCode, RegTaxNo, RegTelePhone, type RenderControl, _default$c as RenderMarkdown, type RenderMarkdownProps, _default$b as RenderWrapper, type RenderWrapperProps, type RequestConfig, type SecureManagerProps, type SetIntervalType, type SizeUnit, ThanNumLengthValidator, ThanNumValidator, type TokenManagerProps, _default$a as UserAvatar, type UserAvatarProps, _default$g as VideoPlayer, type VideoPlayerProps, type WebSocketProps, type WebSocketType, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, formatDate, formatNumberWithCommas, formatSize, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, _default$8 as useAutoRefresh, _default$7 as useCountDown, _default$6 as useCreateValtioContext, _default$5 as useDebounce, _default$4 as useDeepEffect, _default$9 as useIframeRelayBridge, _default$3 as useRefState, _default$2 as useSyncInput, _default$1 as useThrottle, _default as useWebSocket };
package/dist/index.d.ts CHANGED
@@ -194,7 +194,7 @@ declare const _default$g: ({ fileUrl }: VideoPlayerProps) => react_jsx_runtime.J
194
194
  * Iframe组件属性接口
195
195
  */
196
196
  interface IframeProps {
197
- /** 默认主源 */
197
+ /** 默认主源 用于在内部区分来源 */
198
198
  defaultMainSource?: string;
199
199
  /** iframe ID */
200
200
  id?: string;
@@ -276,20 +276,18 @@ interface RenderMarkdownProps {
276
276
  content?: string;
277
277
  /** 搜索关键字 */
278
278
  searchValue?: string;
279
- /** 自定义组件映射 */
279
+ /** 自定义组件映射, 默认会传入loading、data 属性以及透传参数 */
280
280
  customComponents?: ComponentMapType;
281
- /** 内容变化回调 */
282
- onChange?: (value: string) => void;
283
- /** 部分内容变化回调 */
284
- onPartialChange?: (oldValue: string, newValue: string) => void;
281
+ /** 透传入自定义组件的参数方法 */
282
+ [key: string]: any;
285
283
  }
286
284
  /**
287
285
  * Markdown渲染组件
288
286
  * 将Markdown文本转换为HTML并渲染为React组件
289
- * 支持自定义组件、搜索高亮、内容编辑等功能
287
+ * 支持自定义组件、搜索高亮等功能
290
288
  * @param RenderMarkdownProps - 组件属性
291
289
  */
292
- declare const _default$c: ({ content, searchValue, customComponents, onChange, onPartialChange }: RenderMarkdownProps) => react_jsx_runtime.JSX.Element;
290
+ declare const _default$c: ({ content, searchValue, customComponents, ...rest }: RenderMarkdownProps) => react_jsx_runtime.JSX.Element;
293
291
 
294
292
  /**
295
293
  * 渲染控制对象类型
@@ -702,6 +700,22 @@ declare const objToOptions: (obj: Record<string, string> | string[], filter?: (k
702
700
  declare const arrToObj: <T>(arr: T[], key: string) => {
703
701
  [key: string]: T;
704
702
  };
703
+ /**
704
+ * setInterval函数返回的控制对象类型接口
705
+ * 提供对定时器运行状态的检查和取消操作
706
+ */
707
+ interface SetIntervalType {
708
+ /**
709
+ * 检查定时器是否正在运行
710
+ * @returns boolean - true表示正在运行,false表示已停止
711
+ */
712
+ isRun: () => boolean;
713
+ /**
714
+ * 取消定时器
715
+ * 调用后将停止后续的函数执行并清理资源
716
+ */
717
+ cancel: () => void;
718
+ }
705
719
  /**
706
720
  * 使用 setTimeout 模拟 setInterval,避免堆积
707
721
  *
@@ -1084,6 +1098,43 @@ declare function aesEncrypt<T = any>(data: T, key: string): string;
1084
1098
  * @returns 解密后的数据,解密失败时返回null
1085
1099
  */
1086
1100
  declare function aesDecrypt<T = any>(data: string, key: string): T | null;
1101
+ type SizeUnit = 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'PB';
1102
+ interface FormatSizeOptions {
1103
+ /** 起始单位,默认 KB */
1104
+ from?: SizeUnit;
1105
+ /** 保留小数位数,默认 2 */
1106
+ precision?: number;
1107
+ /** 是否去除多余的 0,如 1.00 -> 1 */
1108
+ trimZero?: boolean;
1109
+ /** 最大单位限制 */
1110
+ maxUnit?: SizeUnit;
1111
+ }
1112
+ /**
1113
+ * 格式化文件大小显示
1114
+ *
1115
+ * 将给定的数值按照指定单位转换为更友好的可读格式(如KB, MB, GB等)
1116
+ * 支持从不同单位开始转换,并可自定义精度和最大单位限制
1117
+ *
1118
+ * @param value - 需要格式化的数值(可以是数字或数字字符串)
1119
+ * @param options - 格式化选项
1120
+ * @param options.from - 输入数值的单位,默认为 'KB'
1121
+ * @param options.precision - 保留的小数位数,默认为 2
1122
+ * @param options.trimZero - 是否去除尾部的零,默认为 false
1123
+ * @param options.maxUnit - 最大转换单位,超过该单位则不再转换,默认无限制
1124
+ *
1125
+ * @returns 格式化后的文件大小字符串,如果输入无效则返回原值
1126
+ *
1127
+ * @example
1128
+ * formatSize(1024) // "1024.00KB"
1129
+ * formatSize(1024, { from: 'B' }) // "1.00KB"
1130
+ * formatSize(1024, { precision: 0 }) // "1024KB"
1131
+ * formatSize(1024, { trimZero: true }) // "1024KB"
1132
+ * formatSize(2048, { maxUnit: 'KB' }) // "2048.00KB" (不会转换为MB)
1133
+ *
1134
+ * @remarks
1135
+ * - 支持从 B, KB, MB, GB, TB, PB 等单位开始转换
1136
+ */
1137
+ declare function formatSize(value: number | string, options?: FormatSizeOptions): number | string;
1087
1138
 
1088
1139
  type DateType = string | number | Date | dayjs.Dayjs | null;
1089
1140
  /** 默认日期时间格式:年-月-日 时:分:秒 */
@@ -1847,6 +1898,19 @@ declare const RegDetailAddress: {
1847
1898
  pattern: RegExp;
1848
1899
  message: string;
1849
1900
  };
1901
+ /**
1902
+ * 密码强度验证规则
1903
+ *
1904
+ * 正则表达式要求:
1905
+ * 1. 长度在8到26位之间
1906
+ * 2. 必须包含至少一个字母(大小写均可)
1907
+ * 3. 必须包含至少一个数字
1908
+ * 4. 只能包含字母和数字(不允许特殊字符)
1909
+ */
1910
+ declare const RegPassword: {
1911
+ pattern: RegExp;
1912
+ message: string;
1913
+ };
1850
1914
  /**
1851
1915
  * 手机号或固定电话验证器
1852
1916
  * 验证输入是否符合手机号或固定电话格式
@@ -2163,4 +2227,4 @@ declare function createTokenManager({ key, storage }: TokenManagerProps): {
2163
2227
  clear: () => void;
2164
2228
  };
2165
2229
 
2166
- export { _default$m as AudioPlayer, type AudioPlayerProps, BusinessCode, type CacheMessage, type ComponentMapType, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, _default$l as FileIcon, type FileIconProps, _default$k as FilePreview, _default$j as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, HttpStatus, _default$f as Iframe, type IframeProps, _default$e as LazyComponent, type LazyComponentProps, _default$d as MarkdownEditor, type MarkdownEditorProps, _default$i as MarkdownPreview, type MarkdownPreviewProps, MultiEmailValidator, _default$h as PdfPreview, type PdfPreviewProps, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegSmsCode, RegTaxNo, RegTelePhone, type RenderControl, _default$c as RenderMarkdown, type RenderMarkdownProps, _default$b as RenderWrapper, type RenderWrapperProps, type RequestConfig, type SecureManagerProps, ThanNumLengthValidator, ThanNumValidator, type TokenManagerProps, _default$a as UserAvatar, type UserAvatarProps, _default$g as VideoPlayer, type VideoPlayerProps, type WebSocketProps, type WebSocketType, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, formatDate, formatNumberWithCommas, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, _default$8 as useAutoRefresh, _default$7 as useCountDown, _default$6 as useCreateValtioContext, _default$5 as useDebounce, _default$4 as useDeepEffect, _default$9 as useIframeRelayBridge, _default$3 as useRefState, _default$2 as useSyncInput, _default$1 as useThrottle, _default as useWebSocket };
2230
+ export { _default$m as AudioPlayer, type AudioPlayerProps, BusinessCode, type CacheMessage, type ComponentMapType, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, _default$l as FileIcon, type FileIconProps, _default$k as FilePreview, _default$j as FilePreviewDrawer, type FilePreviewDrawerProps, type FilePreviewProps, type FormatSizeOptions, HttpStatus, _default$f as Iframe, type IframeProps, _default$e as LazyComponent, type LazyComponentProps, _default$d as MarkdownEditor, type MarkdownEditorProps, _default$i as MarkdownPreview, type MarkdownPreviewProps, MultiEmailValidator, _default$h as PdfPreview, type PdfPreviewProps, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegPassword, RegSmsCode, RegTaxNo, RegTelePhone, type RenderControl, _default$c as RenderMarkdown, type RenderMarkdownProps, _default$b as RenderWrapper, type RenderWrapperProps, type RequestConfig, type SecureManagerProps, type SetIntervalType, type SizeUnit, ThanNumLengthValidator, ThanNumValidator, type TokenManagerProps, _default$a as UserAvatar, type UserAvatarProps, _default$g as VideoPlayer, type VideoPlayerProps, type WebSocketProps, type WebSocketType, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, formatDate, formatNumberWithCommas, formatSize, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, _default$8 as useAutoRefresh, _default$7 as useCountDown, _default$6 as useCreateValtioContext, _default$5 as useDebounce, _default$4 as useDeepEffect, _default$9 as useIframeRelayBridge, _default$3 as useRefState, _default$2 as useSyncInput, _default$1 as useThrottle, _default as useWebSocket };
package/dist/index.esm.js CHANGED
@@ -15,9 +15,9 @@ import zh_CN from '@react-pdf-viewer/locales/lib/zh_CN.json';
15
15
  import '@react-pdf-viewer/page-navigation/lib/styles/index.css';
16
16
  import AES from 'crypto-js/aes';
17
17
  import encUtf8 from 'crypto-js/enc-utf8';
18
+ import Decimal from 'decimal.js';
18
19
  import dayjs from 'dayjs';
19
20
  import relativeTime from 'dayjs/plugin/relativeTime';
20
- import Decimal from 'decimal.js';
21
21
  import axios from 'axios';
22
22
  import '@react-pdf-viewer/thumbnail/lib/styles/index.css';
23
23
  import '@react-pdf-viewer/zoom/lib/styles/index.css';
@@ -215,7 +215,7 @@ try {
215
215
  md.use(alertInlinePlugin);
216
216
  } catch {
217
217
  }
218
- var RenderMarkdown_default = ({ content = "", searchValue, customComponents, onChange, onPartialChange }) => {
218
+ var RenderMarkdown_default = ({ content = "", searchValue, customComponents, ...rest }) => {
219
219
  const reactContent = useMemo(() => {
220
220
  if (!content) return null;
221
221
  const { text: preprocessed, placeholders } = alertMarkClean(content);
@@ -235,18 +235,7 @@ var RenderMarkdown_default = ({ content = "", searchValue, customComponents, onC
235
235
  const raw = placeholders.get(dataAttr) ?? "";
236
236
  data = parseData(raw);
237
237
  }
238
- return /* @__PURE__ */ jsx(
239
- LazyComponent_default,
240
- {
241
- type,
242
- data,
243
- loading,
244
- customComponents,
245
- onChange,
246
- onPartialChange
247
- },
248
- `${type}${lazyIndex}`
249
- );
238
+ return /* @__PURE__ */ jsx(LazyComponent_default, { customComponents, type, data, loading, ...rest }, `${type}${lazyIndex}`);
250
239
  }
251
240
  }
252
241
  });
@@ -589,6 +578,60 @@ var useDebounce_default = (func, wait = 400) => {
589
578
  debounce.cancel = cancel;
590
579
  return useCallback(debounce, []);
591
580
  };
581
+ var OperatorToMethodName = {
582
+ "+": "plus",
583
+ "-": "minus",
584
+ "*": "times",
585
+ "/": "dividedBy"
586
+ };
587
+ var calculate = (operator, ...args) => {
588
+ if (args.length === 0) return "0";
589
+ const [arg, ...newArgs] = args;
590
+ return newArgs.reduce((acc, val) => acc[OperatorToMethodName[operator]](new Decimal(val)), new Decimal(arg)).toString();
591
+ };
592
+ var plus = (...args) => calculate("+", ...args);
593
+ var minus = (...args) => calculate("-", ...args);
594
+ var times = (...args) => calculate("*", ...args);
595
+ var dividedBy = (...args) => calculate("/", ...args);
596
+ var decimalPlaces = (arg1) => {
597
+ return new Decimal(arg1).decimalPlaces();
598
+ };
599
+ var precision = (arg1) => {
600
+ return new Decimal(arg1).precision(true);
601
+ };
602
+ var absVal = (arg1) => new Decimal(arg1).abs().toString();
603
+ var compareNum = (arg1, arg2, type) => {
604
+ const x = new Decimal(arg1);
605
+ const y = new Decimal(arg2);
606
+ switch (type) {
607
+ case ">":
608
+ return x.greaterThan(y);
609
+ case ">=":
610
+ return x.greaterThanOrEqualTo(y);
611
+ case "<":
612
+ return x.lessThan(y);
613
+ case "<=":
614
+ return x.lessThanOrEqualTo(y);
615
+ case "==":
616
+ return x.equals(y);
617
+ }
618
+ };
619
+ var toFixed = (num, decimals = 2, fill = true) => {
620
+ const x = new Decimal(num);
621
+ if (fill) {
622
+ return x.toFixed(decimals, Decimal.ROUND_HALF_UP);
623
+ } else {
624
+ return x.toDecimalPlaces(decimals, Decimal.ROUND_HALF_UP).toString();
625
+ }
626
+ };
627
+ var isInteger = (num) => {
628
+ return new Decimal(num).isInteger();
629
+ };
630
+ var isNegative = (num) => {
631
+ return new Decimal(num).isNegative();
632
+ };
633
+
634
+ // src/utils/common.ts
592
635
  var deepCopy = (obj, isJson2 = true) => {
593
636
  if (isJson2) {
594
637
  try {
@@ -1073,6 +1116,27 @@ function aesDecrypt(data, key) {
1073
1116
  return null;
1074
1117
  }
1075
1118
  }
1119
+ function formatSize(value, options = {}) {
1120
+ if (isNullOrUnDef(value) || !isNumberNoNaN(Number(value))) return value;
1121
+ const UNIT_LIST = ["B", "KB", "MB", "GB", "TB", "PB"];
1122
+ const { from = "KB", precision: precision2 = 2, trimZero = false, maxUnit } = options;
1123
+ let index = UNIT_LIST.indexOf(from);
1124
+ if (index === -1) {
1125
+ console.warn(`Invalid from: ${from}`);
1126
+ return value;
1127
+ }
1128
+ const maxIndex = maxUnit ? UNIT_LIST.indexOf(maxUnit) : UNIT_LIST.length - 1;
1129
+ if (maxIndex === -1) {
1130
+ console.warn(`Invalid maxUnit: ${maxUnit}`);
1131
+ return value;
1132
+ }
1133
+ let size = value;
1134
+ while (compareNum(size, 1024, ">=") && index < maxIndex) {
1135
+ size = dividedBy(size, 1024);
1136
+ index++;
1137
+ }
1138
+ return `${toFixed(size, precision2, !trimZero)}${UNIT_LIST[index]}`;
1139
+ }
1076
1140
 
1077
1141
  // src/hooks/useDeepEffect.ts
1078
1142
  var useDeepEffect_default = (effect, deps) => {
@@ -1170,58 +1234,6 @@ var getTimestamp = (date) => {
1170
1234
  var isExpire = (date) => {
1171
1235
  return dayjs(date).isBefore(getStartOfTimestamp());
1172
1236
  };
1173
- var OperatorToMethodName = {
1174
- "+": "plus",
1175
- "-": "minus",
1176
- "*": "times",
1177
- "/": "dividedBy"
1178
- };
1179
- var calculate = (operator, ...args) => {
1180
- if (args.length === 0) return "0";
1181
- const [arg, ...newArgs] = args;
1182
- return newArgs.reduce((acc, val) => acc[OperatorToMethodName[operator]](new Decimal(val)), new Decimal(arg)).toString();
1183
- };
1184
- var plus = (...args) => calculate("+", ...args);
1185
- var minus = (...args) => calculate("-", ...args);
1186
- var times = (...args) => calculate("*", ...args);
1187
- var dividedBy = (...args) => calculate("/", ...args);
1188
- var decimalPlaces = (arg1) => {
1189
- return new Decimal(arg1).decimalPlaces();
1190
- };
1191
- var precision = (arg1) => {
1192
- return new Decimal(arg1).precision(true);
1193
- };
1194
- var absVal = (arg1) => new Decimal(arg1).abs().toString();
1195
- var compareNum = (arg1, arg2, type) => {
1196
- const x = new Decimal(arg1);
1197
- const y = new Decimal(arg2);
1198
- switch (type) {
1199
- case ">":
1200
- return x.greaterThan(y);
1201
- case ">=":
1202
- return x.greaterThanOrEqualTo(y);
1203
- case "<":
1204
- return x.lessThan(y);
1205
- case "<=":
1206
- return x.lessThanOrEqualTo(y);
1207
- case "==":
1208
- return x.equals(y);
1209
- }
1210
- };
1211
- var toFixed = (num, decimals = 2, fill = true) => {
1212
- const x = new Decimal(num);
1213
- if (fill) {
1214
- return x.toFixed(decimals, Decimal.ROUND_HALF_UP);
1215
- } else {
1216
- return x.toDecimalPlaces(decimals, Decimal.ROUND_HALF_UP).toString();
1217
- }
1218
- };
1219
- var isInteger = (num) => {
1220
- return new Decimal(num).isInteger();
1221
- };
1222
- var isNegative = (num) => {
1223
- return new Decimal(num).isNegative();
1224
- };
1225
1237
  var createCachedMessage = () => {
1226
1238
  const messageCache = {};
1227
1239
  return ({ title = "\u63D0\u793A", content, type = "warning", duration = 3, onClose, isCache = true, isOnly = false }) => {
@@ -1306,6 +1318,10 @@ var RegDetailAddress = {
1306
1318
  pattern: /.*(街|路|村|乡|镇|道|巷|号).*/,
1307
1319
  message: "\u5FC5\u987B\u5305\u542B\u201C\u8857\u3001\u8DEF\u3001\u6751\u3001\u4E61\u3001\u9547\u3001\u9053\u3001\u5DF7\u3001\u53F7\u201D\u7B49\u5173\u952E\u8BCD\u4E4B\u4E00"
1308
1320
  };
1321
+ var RegPassword = {
1322
+ pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,26}$/,
1323
+ message: "\u5BC6\u7801\u4E3A8\u523026\u4F4D\u4E4B\u95F4\u6570\u5B57\u4E0E\u5B57\u6BCD\u7EC4\u5408"
1324
+ };
1309
1325
  var PhoneOrMobileValidator = (errMessage = "\u8054\u7CFB\u7535\u8BDD\u683C\u5F0F\u4E0D\u6B63\u786E") => ({
1310
1326
  validator: (_, value) => !value || RegFixedTelePhone.pattern.test(value) || RegMobile.pattern.test(value) ? Promise.resolve() : Promise.reject(new Error(errMessage))
1311
1327
  });
@@ -5756,6 +5772,6 @@ var UserAvatar_default = ({ size, avatarSrc, userName }) => {
5756
5772
  return avatarSrc ? /* @__PURE__ */ jsx(Avatar, { size, src: avatarSrc }) : /* @__PURE__ */ jsx(Avatar, { size, className: "cursor-pointer", style: { backgroundColor: "var(--ant-color-primary)" }, children: userName?.slice(0, 1)?.toLocaleUpperCase() });
5757
5773
  };
5758
5774
 
5759
- export { AudioPlayer_default as AudioPlayer, BusinessCode, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, FileIcon_default as FileIcon, FilePreview_default as FilePreview, FilePreviewDrawer_default as FilePreviewDrawer, HttpStatus, Iframe_default as Iframe, LazyComponent_default as LazyComponent, MarkdownEditor_default as MarkdownEditor, MarkdownPreview_default as MarkdownPreview, MultiEmailValidator, PdfPreview_default as PdfPreview, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegSmsCode, RegTaxNo, RegTelePhone, RenderMarkdown_default as RenderMarkdown, RenderWrapper_default as RenderWrapper, ThanNumLengthValidator, ThanNumValidator, UserAvatar_default as UserAvatar, VideoPlayer_default as VideoPlayer, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, formatDate, formatNumberWithCommas, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval2 as setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, useAutoRefresh_default as useAutoRefresh, useCountDown_default as useCountDown, useCreateValtioContext_default as useCreateValtioContext, useDebounce_default as useDebounce, useDeepEffect_default as useDeepEffect, useIframeRelayBridge_default as useIframeRelayBridge, useRefState_default as useRefState, useSyncInput_default as useSyncInput, useThrottle_default as useThrottle, useWebSocket_default as useWebSocket };
5775
+ export { AudioPlayer_default as AudioPlayer, BusinessCode, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, FileIcon_default as FileIcon, FilePreview_default as FilePreview, FilePreviewDrawer_default as FilePreviewDrawer, HttpStatus, Iframe_default as Iframe, LazyComponent_default as LazyComponent, MarkdownEditor_default as MarkdownEditor, MarkdownPreview_default as MarkdownPreview, MultiEmailValidator, PdfPreview_default as PdfPreview, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegPassword, RegSmsCode, RegTaxNo, RegTelePhone, RenderMarkdown_default as RenderMarkdown, RenderWrapper_default as RenderWrapper, ThanNumLengthValidator, ThanNumValidator, UserAvatar_default as UserAvatar, VideoPlayer_default as VideoPlayer, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, formatDate, formatNumberWithCommas, formatSize, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval2 as setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, useAutoRefresh_default as useAutoRefresh, useCountDown_default as useCountDown, useCreateValtioContext_default as useCreateValtioContext, useDebounce_default as useDebounce, useDeepEffect_default as useDeepEffect, useIframeRelayBridge_default as useIframeRelayBridge, useRefState_default as useRefState, useSyncInput_default as useSyncInput, useThrottle_default as useThrottle, useWebSocket_default as useWebSocket };
5760
5776
  //# sourceMappingURL=index.esm.js.map
5761
5777
  //# sourceMappingURL=index.esm.js.map