@movk/core 1.1.0 → 1.2.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/README.md +4 -1
- package/dist/index.d.mts +107 -2
- package/dist/index.d.ts +107 -2
- package/dist/index.mjs +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
[](https://core.mhaibaraai.cn/)
|
|
2
2
|
|
|
3
|
+
[](https://core.mhaibaraai.cn/mcp/deeplink)
|
|
4
|
+
[](https://core.mhaibaraai.cn/mcp/deeplink?ide=vscode)
|
|
5
|
+
|
|
3
6
|
> `@movk/core` 是一个为 TypeScript 项目设计的现代化、支持 Tree-Shaking 的工具函数库,涵盖了数组、对象、字符串、异步操作等多个方面。
|
|
4
7
|
|
|
5
8
|
[](https://www.typescriptlang.org/)
|
|
@@ -67,7 +70,7 @@ Vue 组合式函数,用于状态管理、剪贴板操作等常见场景。
|
|
|
67
70
|
|
|
68
71
|
## 📁 目录结构
|
|
69
72
|
|
|
70
|
-
```
|
|
73
|
+
```text
|
|
71
74
|
src/
|
|
72
75
|
├── composables/ # Vue 组合式函数
|
|
73
76
|
│ ├── useAppStorage # 应用存储管理
|
package/dist/index.d.mts
CHANGED
|
@@ -295,6 +295,27 @@ type IsPlainObject<T> = NonNullable<T> extends Record<string, any> ? NonNullable
|
|
|
295
295
|
type DeepPartial<T> = {
|
|
296
296
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P] | undefined;
|
|
297
297
|
};
|
|
298
|
+
/** 递归深度计数器,用于限制类型递归层数 */
|
|
299
|
+
type MergeDepth = [never, 0, 1, 2, 3, 4];
|
|
300
|
+
/**
|
|
301
|
+
* 递归合并两个对象类型,`U` 中的属性优先级高于 `T`。
|
|
302
|
+
* 仅对双方都是纯对象的属性做深度递归,其余类型直接取 `U` 的值。
|
|
303
|
+
*
|
|
304
|
+
* @typeParam T - 基础对象类型
|
|
305
|
+
* @typeParam U - 覆盖对象类型
|
|
306
|
+
* @typeParam D - 递归深度限制,默认为 4
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* type A = { a: { b: number; c: string }; d: boolean }
|
|
311
|
+
* type B = { a: { b: string; e: number }; f: Date }
|
|
312
|
+
* type R = DeepMerge<A, B>
|
|
313
|
+
* // { a: { b: string; c: string; e: number }; d: boolean; f: Date }
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
type DeepMerge<T, U, D extends number = 4> = [D] extends [never] ? T & U : {
|
|
317
|
+
[K in keyof T | keyof U]: K extends keyof U ? K extends keyof T ? IsPlainObject<T[K]> extends true ? IsPlainObject<U[K]> extends true ? DeepMerge<NonNullable<T[K]>, NonNullable<U[K]>, MergeDepth[D]> : U[K] : U[K] : U[K] : K extends keyof T ? T[K] : never;
|
|
318
|
+
};
|
|
298
319
|
|
|
299
320
|
/**
|
|
300
321
|
* 深度控制类型,用于限制类型递归的深度
|
|
@@ -518,6 +539,90 @@ type FirstParam<T, K extends keyof T> = T[K] extends [infer P, ...any[]] ? P : n
|
|
|
518
539
|
*/
|
|
519
540
|
type FirstParameter<T> = T extends (arg: infer P, ...args: any[]) => any ? P : undefined;
|
|
520
541
|
|
|
542
|
+
/**
|
|
543
|
+
* 数组合并策略
|
|
544
|
+
* - `'concat'` : 将 source 数组拼接在 target 数组之后(默认)
|
|
545
|
+
* - `'replace'` : 用 source 数组整体替换 target 数组
|
|
546
|
+
* - `'unique'` : 拼接后去重(基于 SameValueZero 比较)
|
|
547
|
+
*/
|
|
548
|
+
type ArrayMergeStrategy = 'concat' | 'replace' | 'unique';
|
|
549
|
+
/**
|
|
550
|
+
* null/undefined 处理策略
|
|
551
|
+
* - `'skip'` : 忽略 source 中的 null/undefined,保留 target 中的值(默认)
|
|
552
|
+
* - `'override'` : 允许 source 中的 null/undefined 覆盖 target 中的值
|
|
553
|
+
*/
|
|
554
|
+
type NullHandlingStrategy = 'skip' | 'override';
|
|
555
|
+
/**
|
|
556
|
+
* 自定义合并函数。
|
|
557
|
+
*
|
|
558
|
+
* @param key 当前正在处理的键(string 或 Symbol)
|
|
559
|
+
* @param targetVal target 中该键的当前值
|
|
560
|
+
* @param sourceVal source 中该键的值
|
|
561
|
+
* @param path 从根对象到当前层级的键路径
|
|
562
|
+
* @returns 返回合并结果;返回 `undefined` 则交由默认逻辑处理
|
|
563
|
+
*/
|
|
564
|
+
type CustomMerger = (key: string | symbol, targetVal: unknown, sourceVal: unknown, path: ReadonlyArray<string | symbol>) => unknown;
|
|
565
|
+
/**
|
|
566
|
+
* deepMerge 配置选项
|
|
567
|
+
*/
|
|
568
|
+
interface DeepMergeOptions {
|
|
569
|
+
/** 数组合并策略,默认 `'concat'` */
|
|
570
|
+
arrayStrategy?: ArrayMergeStrategy;
|
|
571
|
+
/** null/undefined 处理策略,默认 `'skip'` */
|
|
572
|
+
nullHandling?: NullHandlingStrategy;
|
|
573
|
+
/** 自定义合并函数,返回 `undefined` 则交由默认逻辑处理 */
|
|
574
|
+
customMerger?: CustomMerger;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* 递归地将多个 source 对象深度合并为一个新对象。
|
|
578
|
+
*
|
|
579
|
+
* - 后面的 source 优先级更高,会覆盖前面的同名属性
|
|
580
|
+
* - 双方都是纯对象的属性会递归合并,而非覆盖
|
|
581
|
+
* - 数组合并策略、null 处理和自定义合并函数均可配置
|
|
582
|
+
* - 支持 Symbol 键,防止原型污染(跳过 `__proto__` 和 `constructor`)
|
|
583
|
+
* - 不修改任何输入对象
|
|
584
|
+
*
|
|
585
|
+
* @category Object
|
|
586
|
+
* @typeParam T 合并结果的对象类型
|
|
587
|
+
* @param sources 要合并的源对象数组,后面的对象优先级更高
|
|
588
|
+
* @param options 合并行为配置项(可选)
|
|
589
|
+
* @returns 合并后的新对象
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts
|
|
593
|
+
* const defaults = { theme: 'light', pagination: { page: 1, size: 10 } }
|
|
594
|
+
* const userConfig = { pagination: { size: 20 }, debug: true }
|
|
595
|
+
* const result = deepMerge([defaults, userConfig])
|
|
596
|
+
* // => { theme: 'light', pagination: { page: 1, size: 20 }, debug: true }
|
|
597
|
+
* ```
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```ts
|
|
601
|
+
* // 数组去重合并
|
|
602
|
+
* const result = deepMerge(
|
|
603
|
+
* [{ tags: ['a', 'b'] }, { tags: ['b', 'c'] }],
|
|
604
|
+
* { arrayStrategy: 'unique' },
|
|
605
|
+
* )
|
|
606
|
+
* // => { tags: ['a', 'b', 'c'] }
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
declare function deepMerge<T extends AnyObject>(sources: T[], options?: DeepMergeOptions): T;
|
|
610
|
+
/**
|
|
611
|
+
* 创建一个预绑定配置的 deepMerge 函数。
|
|
612
|
+
*
|
|
613
|
+
* @category Object
|
|
614
|
+
* @param options 合并行为配置项
|
|
615
|
+
* @returns 预配置的 deepMerge 函数
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```ts
|
|
619
|
+
* const mergeReplace = createDeepMerge({ arrayStrategy: 'replace' })
|
|
620
|
+
* const result = mergeReplace([{ tags: ['a'] }, { tags: ['b'] }])
|
|
621
|
+
* // => { tags: ['b'] }
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
624
|
+
declare function createDeepMerge(options: DeepMergeOptions): <T extends AnyObject>(sources: T[]) => T;
|
|
625
|
+
|
|
521
626
|
/**
|
|
522
627
|
* 从对象中排除指定的键,返回新对象
|
|
523
628
|
*
|
|
@@ -2470,5 +2575,5 @@ declare function isString(value: any): value is string;
|
|
|
2470
2575
|
*/
|
|
2471
2576
|
declare function isValidContainer(value: any): boolean;
|
|
2472
2577
|
|
|
2473
|
-
export { Tree, appendQueryParam, buildUrl, camelCase, capitalize, chunk, convertSvgToPng, convertToKebabCase, debounce, deepClone, ensureLeadingSlash, ensureTrailingSlash, extractFilename, flatten, formatFileSize, getDomain, getPath, getQueryParam, getQueryParams, getRandomUUID, getRelativePath, getRootDomain, getUrlExtension, getUrlFilename, hasQueryParam, isAbsoluteUrl, isArray, isEmpty, isFunction, isNumber, isObject, isPlainObject, isRelativeUrl, isSameOrigin, isString, isValidContainer, isValidUrl, joinPath, joinUrl, kebabCase, lowerCase, lowerFirst, normalizeUrl, omit, omitUndefined, parseQuery, parseUrl, pascalCase, pick, removeLeadingSlash, removeQueryParam, removeTrailingSlash, replaceCurrentColor, safeDecodeURIComponent, safeEncodeURIComponent, separate, separateMany, setPath, setQueryParam, setQueryParams, simpleHash, sleep, sleepWithCancel, snakeCase, startCase, stringifyQuery, throttle, toAbsoluteUrl, toPath, triggerDownload, unique, upperCase, upperFirst, useAppStorage, useCopyCode, words };
|
|
2474
|
-
export type { AnyObject, ApiAwaitable, ApiAwaitedReturn, ApiUnwrapPromise, AppStorageReturn, ArrayFieldKeys, ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots, ComponentType, DeepPartial, FirstParam, FirstParameter, GetFieldValue, GetObjectField, IsComponent, IsPlainObject, Merge, MutableByKeys, NestedKeys, NonObjectFieldKeys, ObjectFieldKeys, OmitByKey, ParsedUrl, PartialByKeys, PathInput, PathSegment, PathSegments, PickByKey, QueryParamValue, QueryParams, ReactiveValue, ReadonlyByKeys, RenameKeys, RequiredByKeys, StorageConfig, StorageConfigInput, StorageType, StringOrVNode, StripNullable, Suggest, TreeConfig, TreeConfigInput, TreeNode, TreePredicate, TreeStats, TreeTransformer, TreeVisitor, UnionToIntersection, UnknownObject };
|
|
2578
|
+
export { Tree, appendQueryParam, buildUrl, camelCase, capitalize, chunk, convertSvgToPng, convertToKebabCase, createDeepMerge, debounce, deepClone, deepMerge, ensureLeadingSlash, ensureTrailingSlash, extractFilename, flatten, formatFileSize, getDomain, getPath, getQueryParam, getQueryParams, getRandomUUID, getRelativePath, getRootDomain, getUrlExtension, getUrlFilename, hasQueryParam, isAbsoluteUrl, isArray, isEmpty, isFunction, isNumber, isObject, isPlainObject, isRelativeUrl, isSameOrigin, isString, isValidContainer, isValidUrl, joinPath, joinUrl, kebabCase, lowerCase, lowerFirst, normalizeUrl, omit, omitUndefined, parseQuery, parseUrl, pascalCase, pick, removeLeadingSlash, removeQueryParam, removeTrailingSlash, replaceCurrentColor, safeDecodeURIComponent, safeEncodeURIComponent, separate, separateMany, setPath, setQueryParam, setQueryParams, simpleHash, sleep, sleepWithCancel, snakeCase, startCase, stringifyQuery, throttle, toAbsoluteUrl, toPath, triggerDownload, unique, upperCase, upperFirst, useAppStorage, useCopyCode, words };
|
|
2579
|
+
export type { AnyObject, ApiAwaitable, ApiAwaitedReturn, ApiUnwrapPromise, AppStorageReturn, ArrayFieldKeys, ArrayMergeStrategy, ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots, ComponentType, CustomMerger, DeepMerge, DeepMergeOptions, DeepPartial, FirstParam, FirstParameter, GetFieldValue, GetObjectField, IsComponent, IsPlainObject, Merge, MutableByKeys, NestedKeys, NonObjectFieldKeys, NullHandlingStrategy, ObjectFieldKeys, OmitByKey, ParsedUrl, PartialByKeys, PathInput, PathSegment, PathSegments, PickByKey, QueryParamValue, QueryParams, ReactiveValue, ReadonlyByKeys, RenameKeys, RequiredByKeys, StorageConfig, StorageConfigInput, StorageType, StringOrVNode, StripNullable, Suggest, TreeConfig, TreeConfigInput, TreeNode, TreePredicate, TreeStats, TreeTransformer, TreeVisitor, UnionToIntersection, UnknownObject };
|
package/dist/index.d.ts
CHANGED
|
@@ -295,6 +295,27 @@ type IsPlainObject<T> = NonNullable<T> extends Record<string, any> ? NonNullable
|
|
|
295
295
|
type DeepPartial<T> = {
|
|
296
296
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P] | undefined;
|
|
297
297
|
};
|
|
298
|
+
/** 递归深度计数器,用于限制类型递归层数 */
|
|
299
|
+
type MergeDepth = [never, 0, 1, 2, 3, 4];
|
|
300
|
+
/**
|
|
301
|
+
* 递归合并两个对象类型,`U` 中的属性优先级高于 `T`。
|
|
302
|
+
* 仅对双方都是纯对象的属性做深度递归,其余类型直接取 `U` 的值。
|
|
303
|
+
*
|
|
304
|
+
* @typeParam T - 基础对象类型
|
|
305
|
+
* @typeParam U - 覆盖对象类型
|
|
306
|
+
* @typeParam D - 递归深度限制,默认为 4
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* type A = { a: { b: number; c: string }; d: boolean }
|
|
311
|
+
* type B = { a: { b: string; e: number }; f: Date }
|
|
312
|
+
* type R = DeepMerge<A, B>
|
|
313
|
+
* // { a: { b: string; c: string; e: number }; d: boolean; f: Date }
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
type DeepMerge<T, U, D extends number = 4> = [D] extends [never] ? T & U : {
|
|
317
|
+
[K in keyof T | keyof U]: K extends keyof U ? K extends keyof T ? IsPlainObject<T[K]> extends true ? IsPlainObject<U[K]> extends true ? DeepMerge<NonNullable<T[K]>, NonNullable<U[K]>, MergeDepth[D]> : U[K] : U[K] : U[K] : K extends keyof T ? T[K] : never;
|
|
318
|
+
};
|
|
298
319
|
|
|
299
320
|
/**
|
|
300
321
|
* 深度控制类型,用于限制类型递归的深度
|
|
@@ -518,6 +539,90 @@ type FirstParam<T, K extends keyof T> = T[K] extends [infer P, ...any[]] ? P : n
|
|
|
518
539
|
*/
|
|
519
540
|
type FirstParameter<T> = T extends (arg: infer P, ...args: any[]) => any ? P : undefined;
|
|
520
541
|
|
|
542
|
+
/**
|
|
543
|
+
* 数组合并策略
|
|
544
|
+
* - `'concat'` : 将 source 数组拼接在 target 数组之后(默认)
|
|
545
|
+
* - `'replace'` : 用 source 数组整体替换 target 数组
|
|
546
|
+
* - `'unique'` : 拼接后去重(基于 SameValueZero 比较)
|
|
547
|
+
*/
|
|
548
|
+
type ArrayMergeStrategy = 'concat' | 'replace' | 'unique';
|
|
549
|
+
/**
|
|
550
|
+
* null/undefined 处理策略
|
|
551
|
+
* - `'skip'` : 忽略 source 中的 null/undefined,保留 target 中的值(默认)
|
|
552
|
+
* - `'override'` : 允许 source 中的 null/undefined 覆盖 target 中的值
|
|
553
|
+
*/
|
|
554
|
+
type NullHandlingStrategy = 'skip' | 'override';
|
|
555
|
+
/**
|
|
556
|
+
* 自定义合并函数。
|
|
557
|
+
*
|
|
558
|
+
* @param key 当前正在处理的键(string 或 Symbol)
|
|
559
|
+
* @param targetVal target 中该键的当前值
|
|
560
|
+
* @param sourceVal source 中该键的值
|
|
561
|
+
* @param path 从根对象到当前层级的键路径
|
|
562
|
+
* @returns 返回合并结果;返回 `undefined` 则交由默认逻辑处理
|
|
563
|
+
*/
|
|
564
|
+
type CustomMerger = (key: string | symbol, targetVal: unknown, sourceVal: unknown, path: ReadonlyArray<string | symbol>) => unknown;
|
|
565
|
+
/**
|
|
566
|
+
* deepMerge 配置选项
|
|
567
|
+
*/
|
|
568
|
+
interface DeepMergeOptions {
|
|
569
|
+
/** 数组合并策略,默认 `'concat'` */
|
|
570
|
+
arrayStrategy?: ArrayMergeStrategy;
|
|
571
|
+
/** null/undefined 处理策略,默认 `'skip'` */
|
|
572
|
+
nullHandling?: NullHandlingStrategy;
|
|
573
|
+
/** 自定义合并函数,返回 `undefined` 则交由默认逻辑处理 */
|
|
574
|
+
customMerger?: CustomMerger;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* 递归地将多个 source 对象深度合并为一个新对象。
|
|
578
|
+
*
|
|
579
|
+
* - 后面的 source 优先级更高,会覆盖前面的同名属性
|
|
580
|
+
* - 双方都是纯对象的属性会递归合并,而非覆盖
|
|
581
|
+
* - 数组合并策略、null 处理和自定义合并函数均可配置
|
|
582
|
+
* - 支持 Symbol 键,防止原型污染(跳过 `__proto__` 和 `constructor`)
|
|
583
|
+
* - 不修改任何输入对象
|
|
584
|
+
*
|
|
585
|
+
* @category Object
|
|
586
|
+
* @typeParam T 合并结果的对象类型
|
|
587
|
+
* @param sources 要合并的源对象数组,后面的对象优先级更高
|
|
588
|
+
* @param options 合并行为配置项(可选)
|
|
589
|
+
* @returns 合并后的新对象
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts
|
|
593
|
+
* const defaults = { theme: 'light', pagination: { page: 1, size: 10 } }
|
|
594
|
+
* const userConfig = { pagination: { size: 20 }, debug: true }
|
|
595
|
+
* const result = deepMerge([defaults, userConfig])
|
|
596
|
+
* // => { theme: 'light', pagination: { page: 1, size: 20 }, debug: true }
|
|
597
|
+
* ```
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```ts
|
|
601
|
+
* // 数组去重合并
|
|
602
|
+
* const result = deepMerge(
|
|
603
|
+
* [{ tags: ['a', 'b'] }, { tags: ['b', 'c'] }],
|
|
604
|
+
* { arrayStrategy: 'unique' },
|
|
605
|
+
* )
|
|
606
|
+
* // => { tags: ['a', 'b', 'c'] }
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
declare function deepMerge<T extends AnyObject>(sources: T[], options?: DeepMergeOptions): T;
|
|
610
|
+
/**
|
|
611
|
+
* 创建一个预绑定配置的 deepMerge 函数。
|
|
612
|
+
*
|
|
613
|
+
* @category Object
|
|
614
|
+
* @param options 合并行为配置项
|
|
615
|
+
* @returns 预配置的 deepMerge 函数
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```ts
|
|
619
|
+
* const mergeReplace = createDeepMerge({ arrayStrategy: 'replace' })
|
|
620
|
+
* const result = mergeReplace([{ tags: ['a'] }, { tags: ['b'] }])
|
|
621
|
+
* // => { tags: ['b'] }
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
624
|
+
declare function createDeepMerge(options: DeepMergeOptions): <T extends AnyObject>(sources: T[]) => T;
|
|
625
|
+
|
|
521
626
|
/**
|
|
522
627
|
* 从对象中排除指定的键,返回新对象
|
|
523
628
|
*
|
|
@@ -2470,5 +2575,5 @@ declare function isString(value: any): value is string;
|
|
|
2470
2575
|
*/
|
|
2471
2576
|
declare function isValidContainer(value: any): boolean;
|
|
2472
2577
|
|
|
2473
|
-
export { Tree, appendQueryParam, buildUrl, camelCase, capitalize, chunk, convertSvgToPng, convertToKebabCase, debounce, deepClone, ensureLeadingSlash, ensureTrailingSlash, extractFilename, flatten, formatFileSize, getDomain, getPath, getQueryParam, getQueryParams, getRandomUUID, getRelativePath, getRootDomain, getUrlExtension, getUrlFilename, hasQueryParam, isAbsoluteUrl, isArray, isEmpty, isFunction, isNumber, isObject, isPlainObject, isRelativeUrl, isSameOrigin, isString, isValidContainer, isValidUrl, joinPath, joinUrl, kebabCase, lowerCase, lowerFirst, normalizeUrl, omit, omitUndefined, parseQuery, parseUrl, pascalCase, pick, removeLeadingSlash, removeQueryParam, removeTrailingSlash, replaceCurrentColor, safeDecodeURIComponent, safeEncodeURIComponent, separate, separateMany, setPath, setQueryParam, setQueryParams, simpleHash, sleep, sleepWithCancel, snakeCase, startCase, stringifyQuery, throttle, toAbsoluteUrl, toPath, triggerDownload, unique, upperCase, upperFirst, useAppStorage, useCopyCode, words };
|
|
2474
|
-
export type { AnyObject, ApiAwaitable, ApiAwaitedReturn, ApiUnwrapPromise, AppStorageReturn, ArrayFieldKeys, ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots, ComponentType, DeepPartial, FirstParam, FirstParameter, GetFieldValue, GetObjectField, IsComponent, IsPlainObject, Merge, MutableByKeys, NestedKeys, NonObjectFieldKeys, ObjectFieldKeys, OmitByKey, ParsedUrl, PartialByKeys, PathInput, PathSegment, PathSegments, PickByKey, QueryParamValue, QueryParams, ReactiveValue, ReadonlyByKeys, RenameKeys, RequiredByKeys, StorageConfig, StorageConfigInput, StorageType, StringOrVNode, StripNullable, Suggest, TreeConfig, TreeConfigInput, TreeNode, TreePredicate, TreeStats, TreeTransformer, TreeVisitor, UnionToIntersection, UnknownObject };
|
|
2578
|
+
export { Tree, appendQueryParam, buildUrl, camelCase, capitalize, chunk, convertSvgToPng, convertToKebabCase, createDeepMerge, debounce, deepClone, deepMerge, ensureLeadingSlash, ensureTrailingSlash, extractFilename, flatten, formatFileSize, getDomain, getPath, getQueryParam, getQueryParams, getRandomUUID, getRelativePath, getRootDomain, getUrlExtension, getUrlFilename, hasQueryParam, isAbsoluteUrl, isArray, isEmpty, isFunction, isNumber, isObject, isPlainObject, isRelativeUrl, isSameOrigin, isString, isValidContainer, isValidUrl, joinPath, joinUrl, kebabCase, lowerCase, lowerFirst, normalizeUrl, omit, omitUndefined, parseQuery, parseUrl, pascalCase, pick, removeLeadingSlash, removeQueryParam, removeTrailingSlash, replaceCurrentColor, safeDecodeURIComponent, safeEncodeURIComponent, separate, separateMany, setPath, setQueryParam, setQueryParams, simpleHash, sleep, sleepWithCancel, snakeCase, startCase, stringifyQuery, throttle, toAbsoluteUrl, toPath, triggerDownload, unique, upperCase, upperFirst, useAppStorage, useCopyCode, words };
|
|
2579
|
+
export type { AnyObject, ApiAwaitable, ApiAwaitedReturn, ApiUnwrapPromise, AppStorageReturn, ArrayFieldKeys, ArrayMergeStrategy, ComponentAttrs, ComponentEmit, ComponentExposed, ComponentProps, ComponentSlots, ComponentType, CustomMerger, DeepMerge, DeepMergeOptions, DeepPartial, FirstParam, FirstParameter, GetFieldValue, GetObjectField, IsComponent, IsPlainObject, Merge, MutableByKeys, NestedKeys, NonObjectFieldKeys, NullHandlingStrategy, ObjectFieldKeys, OmitByKey, ParsedUrl, PartialByKeys, PathInput, PathSegment, PathSegments, PickByKey, QueryParamValue, QueryParams, ReactiveValue, ReadonlyByKeys, RenameKeys, RequiredByKeys, StorageConfig, StorageConfigInput, StorageType, StringOrVNode, StripNullable, Suggest, TreeConfig, TreeConfigInput, TreeNode, TreePredicate, TreeStats, TreeTransformer, TreeVisitor, UnionToIntersection, UnknownObject };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useStorage as Q}from"@vueuse/core";function Z(e){const{key:n,defaultValue:r,storage:t="localStorage",prefix:i="movk"}=e,o=`${i}:${n}`,a=(()=>{if(!(typeof window>"u"))return t==="localStorage"?localStorage:sessionStorage})();function s(f){if(f===null)return r;try{return JSON.parse(f)}catch(p){return console.warn(`[AppStorage] Failed to parse value for key "${o}". Using default value.`,p),r}}const c=Q(o,r,a,{mergeDefaults:!0,serializer:{read:s,write:f=>JSON.stringify(f)}});function u(){if(!a)return r;const f=a.getItem(o);return s(f)}function l(f){c.value=f}function h(){a&&(c.value=null)}return{state:c,getItem:u,setItem:l,removeItem:h}}async function q(e){if(typeof e!="string")throw new TypeError("Text must be a string");if(typeof window>"u")return console.warn("useCopyCode: Not available in server environment"),!1;if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch(n){console.warn("Clipboard API failed, falling back to legacy method:",n)}try{return K(e)}catch(n){return console.error("Failed to copy text:",n),!1}}function K(e){if(typeof document>"u")return console.warn("copyTextLegacy: Document not available"),!1;const n=document.createElement("textarea"),r=document.activeElement,t=document.getSelection(),i=t&&t.rangeCount>0?t.getRangeAt(0):null;try{return n.value=e,n.setAttribute("readonly",""),n.setAttribute("contenteditable","true"),Object.assign(n.style,{contain:"strict",position:"absolute",left:"-9999px",top:"-9999px",fontSize:"12pt",border:"0",padding:"0",margin:"0",outline:"none",boxShadow:"none",background:"transparent"}),document.body.appendChild(n),n.focus(),n.select(),n.setSelectionRange&&n.setSelectionRange(0,e.length),document.execCommand("copy")}catch(o){return console.error("Legacy copy method failed:",o),!1}finally{n.parentNode&&document.body.removeChild(n),i&&t&&(t.removeAllRanges(),t.addRange(i)),r instanceof HTMLElement&&r.focus()}}async function _(e){if(!e||typeof e!="string")throw new Error("Invalid SVG string provided");if(typeof window>"u"||typeof document>"u")throw new TypeError("convertSvgToPng is only available in browser environment");return new Promise((n,r)=>{const t=new Image,i=document.createElement("canvas"),o=i.getContext("2d");if(!o){r(new Error("Canvas context not available"));return}t.onload=()=>{try{i.width=t.width,i.height=t.height,o.drawImage(t,0,0),i.toBlob(a=>{a?n(a):r(new Error("Failed to convert canvas to Blob"))},"image/png")}catch(a){r(new Error(`Error during canvas conversion: ${a}`))}},t.onerror=()=>{r(new Error("Failed to load SVG image"))};try{t.src=`data:image/svg+xml;base64,${btoa(e)}`}catch(a){r(new Error(`Failed to encode SVG: ${a}`))}})}function H(e,n="file"){if(!e)return n;const r=e.get("content-disposition");if(r){const t=r.match(/filename\*?=(?:"([^"]+)"|([^;]+))/i);if(t){let i=t[1]??t[2];if(!i)return n;if(i.startsWith('"')&&i.endsWith('"')&&(i=i.slice(1,-1)),r.includes("filename*=")){const o=i.split("''");if(o.length===2&&o[1])try{i=decodeURIComponent(o[1])}catch{return n}}return i}}return n}function J(e){if(!Number.isFinite(e)||e<0||e===0)return"0 Bytes";const n=1024,r=["Bytes","KB","MB","GB","TB","PB"],t=Math.floor(Math.log(e)/Math.log(n));return t>=r.length?`${Number.parseFloat((e/n**(r.length-1)).toFixed(2))} ${r[r.length-1]}`:`${Number.parseFloat((e/n**t).toFixed(2))} ${r[t]}`}async function X(e,n){if(!e||typeof e!="string")throw new Error("Invalid SVG path provided");try{const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch SVG file: ${r.status} ${r.statusText}`);const t=await r.text();if(!n)return t;if(typeof window>"u"||typeof DOMParser>"u")return console.warn("replaceCurrentColor: DOM manipulation not available in server environment, returning original SVG"),t;const i=new DOMParser().parseFromString(t,"image/svg+xml");if(i.querySelector("parsererror"))throw new Error("Invalid SVG content");const o=i.querySelector("svg");if(!o)throw new Error("No SVG element found in the document");o.hasAttribute("fill")||o.setAttribute("fill","currentColor");const a=s=>{s.getAttribute("fill")==="currentColor"&&s.setAttribute("fill",n),s.getAttribute("stroke")==="currentColor"&&s.setAttribute("stroke",n),Array.from(s.children).forEach(c=>{a(c)})};return a(o),new XMLSerializer().serializeToString(i)}catch(r){throw r instanceof Error?r:new Error(`Unexpected error occurred: ${r}`)}}function Y(e,n){if(typeof window>"u"||typeof document>"u"){console.warn("triggerDownload: Not available in server environment");return}const r=URL.createObjectURL(e),t=document.createElement("a");t.href=r,t.download=n,t.style.display="none",document.body.appendChild(t),t.click(),document.body.removeChild(t),URL.revokeObjectURL(r)}function w(e,n=new WeakMap){if(e===null||typeof e!="object")return e;try{const s=globalThis.structuredClone;if(typeof s=="function")return s(e)}catch(s){console.error("Error occurred while cloning:",s)}const r=e,t=n.get(r);if(t)return t;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){const s=new Map;n.set(r,s);for(const[c,u]of e.entries())s.set(w(c,n),w(u,n));return s}if(e instanceof Set){const s=new Set;n.set(r,s);for(const c of e.values())s.add(w(c,n));return s}if(e instanceof ArrayBuffer)return e.slice(0);if(ArrayBuffer.isView(e)){const s=e.constructor;return new s(e)}if(e instanceof URL)return new URL(e.toString());if(e instanceof Error){const s=new e.constructor(e.message);return s.name=e.name,s.stack=e.stack,s}if(Array.isArray(e)){const s=[];n.set(r,s);for(const c of e)s.push(w(c,n));return s}const i=Object.getPrototypeOf(e),o=Object.create(i);n.set(r,o);const a=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const s of a){const c=Object.getOwnPropertyDescriptor(e,s);c&&("value"in c&&(c.value=w(e[s],n)),Object.defineProperty(o,s,c))}return o}function ee(e,n){if(!e||typeof e!="object")return{};const r=new Set(n),t={};for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&!r.has(i)&&(t[i]=e[i]);return t}function te(e){return!e||typeof e!="object"||Array.isArray(e)?e:Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}function ne(e,n){if(!e||typeof e!="object")return{};const r={};for(const t of n)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t]);return r}function re(e,n){if(!e||typeof e!="object")return{picked:{},omitted:{}};if(n.length===0)return{picked:{},omitted:{...e}};const r=new Set(n),t={},i={};for(const o in e)if(Object.hasOwn(e,o)){const a=o;r.has(a)?t[o]=e[a]:i[o]=e[a]}return{picked:t,omitted:i}}function oe(e,n){if(!e||typeof e!="object")return{...Object.fromEntries(Object.keys(n).map(o=>[o,{}])),others:{}};const r=Object.keys(n),t=new Map;for(const o of r){const a=new Set(n[o]);t.set(o,a)}const i=Object.create(null);for(const o of r)i[o]={};i.others={};for(const o in e)if(Object.hasOwn(e,o)){const a=o;let s=!1;for(const c of r)if(t.get(c).has(a)){i[c][o]=e[a],s=!0;break}s||(i.others[o]=e[a])}return i}function S(e){if(Array.isArray(e))return e.slice();const n=[];if(e==="")return n;let r=0;const t=e,i=t.length;function o(s){let c="",u=s;for(;u<i;){const l=t.charCodeAt(u);if(l===46)break;if(l===92){u++,u<i&&(c+=t[u]),u++;continue}if(l===91)break;c+=t[u],u++}return{value:c,next:u}}function a(s){let c=s+1;for(;c<i&&/\s/.test(t[c]);)c++;if(c>=i)throw new Error('Invalid path: missing closing "]"');const u=t[c];if(u==='"'||u==="'"){const f=u;c++;let p="",d=!1;for(;c<i;){if(t.charCodeAt(c)===92){c++,c<i&&(p+=t[c]),c++;continue}if(t[c]===f){d=!0,c++;break}p+=t[c],c++}if(!d)throw new Error("Invalid path: missing closing quote in bracket");for(;c<i&&/\s/.test(t[c]);)c++;if(c>=i||t[c]!=="]")throw new Error('Invalid path: missing closing "]"');return c++,{segment:p,next:c}}let l="";for(;c<i&&t[c]!=="]";)l+=t[c],c++;if(c>=i)throw new Error('Invalid path: missing closing "]"');const h=l.trim();return/^(?:0|[1-9]\d*)$/.test(h)?(c++,{segment:Number(h),next:c}):(c++,{segment:h,next:c})}for(;r<i;){const s=t.charCodeAt(r);if(s===46){r++;continue}if(s===91){const{segment:l,next:h}=a(r);l!==null&&n.push(l),r=h;continue}const{value:c,next:u}=o(r);(c.length>0||u<i&&t[u]===".")&&n.push(c),r=u}return n}function ie(e,n,r){const t=S(n);if(t.length===0)return e;let i=e;for(let o=0;o<t.length;o++){if(i==null)return r;const a=t[o];i=i[a]}return i===void 0?r:i}function se(e){let n="";for(let r=0;r<e.length;r++){const t=e[r];if(typeof t=="number"&&Number.isInteger(t)&&t>=0){n+=`[${t}]`;continue}const i=String(t),o=/^[A-Z_$][\w$]*$/i.test(i);if(n.length===0&&o){n+=i;continue}if(o){n+=`.${i}`;continue}const a=i.replace(/\\/g,"\\\\").replace(/'/g,"\\'");n+=`['${a}']`}return n}function O(e){return e!==null&&typeof e=="object"}function ce(e,n,r){const t=S(n);if(t.length===0)return e;let i=e;for(let o=0;o<t.length;o++){const a=t[o];if(o===t.length-1){i[a]=r;break}const s=t[o+1];let c=i[a];const u=typeof s=="number";if(O(c)?u&&!Array.isArray(c)&&(c=[],i[a]=c):(c=u?[]:{},i[a]=c),u&&Array.isArray(c)){const l=Number(s);Number.isInteger(l)&&l>=0&&c.length<=l&&(c.length=l+1)}i=c}return e}function ae(e){let n=0;for(let r=0;r<e.length;r++){const t=e.charCodeAt(r);n=(n<<5)-n+t,n=n&n}return Math.abs(n).toString(36)}function ue(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)})}function R(e,n=!1){if(!e||typeof e!="object"||Array.isArray(e))return e;const r=i=>i.replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase(),t={};for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){const o=r(i),a=e[i];n&&a&&typeof a=="object"&&!Array.isArray(a)?t[o]=R(a,!0):t[o]=a}return t}function $(e){return e?e.replace(/[_-]/g," ").match(/[A-Z]{2,}(?=[A-Z][a-z]|\b)|[A-Z]?[a-z]+|\d+/g)||[]:[]}function b(e,n){if(!e)return"";const r=$(e);return r.length===0?"":r.map((t,i)=>{const o=t.toLowerCase(),a=t.toUpperCase();if(n.transform)return n.transform(t,i,o,a);switch(n.casing){case"lower":return o;case"upper":return a;case"capitalize":return o.charAt(0).toUpperCase()+o.slice(1);default:return t}}).join(n.separator??"")}function k(e,n){if(!e)return"";const r=e.charAt(0);return(n?r.toUpperCase():r.toLowerCase())+e.slice(1)}function le(e){return b(e,{separator:"",transform:(n,r,t)=>r===0?t:t.charAt(0).toUpperCase()+t.slice(1)})}function fe(e){return e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():""}function he(e){return b(e,{separator:"-",casing:"lower"})}function pe(e){return b(e,{separator:" ",casing:"lower"})}function de(e){return k(e,!1)}function ge(e){return b(e,{separator:"",casing:"capitalize"})}function me(e){return b(e,{separator:"_",casing:"lower"})}function ye(e){return e?$(e).map(n=>n.toUpperCase()===n&&n.length>1?n:n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()).join(" "):""}function we(e){return b(e,{separator:" ",casing:"upper"})}function be(e){return k(e,!0)}const U={id:"id",pid:"pid",children:"children"};function g(e={}){return{id:e.id??U.id,pid:e.pid??U.pid,children:e.children??U.children}}function*v(e,n={},r=[]){const{children:t}=g(n);let i=0;for(const o of e){const a=[...r,o];yield{node:o,path:a,depth:r.length,index:i++};const s=o[t];s&&s.length>0&&(yield*v(s,n,a))}}function*E(e,n={}){const{children:r}=g(n),t=e.map((o,a)=>({node:o,path:[o],depth:0,index:a}));let i=e.length;for(;t.length>0;){const o=t.shift();yield o;const a=o.node[r];a&&a.length>0&&a.forEach(s=>{const c=[...o.path,s];t.push({node:s,path:c,depth:o.depth+1,index:i++})})}}function j(e){switch(e){case"find":case"findAll":case"filter":case"transform":case"forEach":case"stats":case"validate":return"dfs";default:return"dfs"}}function Ae(e,n={}){const{id:r,pid:t,children:i}=g(n);if(!Array.isArray(e)||e.length===0)return[];const o=new Map,a=[];return e.forEach(s=>{const{[i]:c,...u}=s,l={...u,[i]:[]};o.set(s[r],l)}),e.forEach(s=>{const c=o.get(s[r]),u=s[t];u&&o.has(u)?o.get(u)[i].push(c):a.push(c)}),a}function xe(e,n={}){const{children:r}=g(n),t=[],i=Array.isArray(e)?e:[e],o=a=>{const{[r]:s,...c}=a;t.push(c),s&&s.length>0&&s.forEach(o)};return i.forEach(o),t}function ve(e,n={}){const{children:r}=g(n),t=Array.isArray(e)?e:[e];let i=0;const o=a=>{i++;const s=a[r];s&&s.length>0&&s.forEach(o)};return t.forEach(o),i}function Ce(e,n,r,t={}){const{id:i,children:o}=g(t),{[o]:a,...s}=r,c={...s,[o]:[]},u=(l,h)=>{for(let f=0;f<l.length;f++){const p=l[f];if(!p)continue;if(p[i]===n)return l.splice(f,0,c),!0;const d=p[o];if(d&&d.length>0){const y=[...h,p];if(u(d,y))return!0}}return!1};return u(e,[])}function Se(e,n,r,t={}){const{id:i,children:o}=g(t),{[o]:a,...s}=r,c={...s,[o]:[]},u=(l,h)=>{for(let f=0;f<l.length;f++){const p=l[f];if(!p)continue;if(p[i]===n)return l.splice(f+1,0,c),!0;const d=p[o];if(d&&d.length>0){const y=[...h,p];if(u(d,y))return!0}}return!1};return u(e,[])}function $e(e,n,r={}){const{id:t,children:i}=g(r),o=a=>{for(let s=0;s<a.length;s++){const c=a[s];if(!c)continue;if(c[t]===n)return a.splice(s,1)[0];const u=c[i];if(u&&u.length>0){const l=o(u);if(l)return l}}};return o(e)}function I(e,n,r={}){const t=Array.isArray(e)?e:[e],i=j("find")==="dfs"?v(t,r):E(t,r);for(const o of i)if(n({node:o.node,depth:o.depth,path:o.path,index:o.index}))return o.node}function Ue(e,n,r={}){const t=Array.isArray(e)?e:[e],i=j("findAll"),o=[],a=i==="dfs"?v(t,r):E(t,r);for(const s of a)n({node:s.node,depth:s.depth,path:s.path,index:s.index})&&o.push(s.node);return o}function Ee(e,n,r={}){const{id:t}=g(r);return I(e,({node:i})=>i[t]===n,r)}function je(e,n,r={}){const{children:t}=g(r),i=Array.isArray(e)?e:[e],o=[],a=(s,c,u,l=0)=>{const h=s[t],f=[];if(h&&h.length>0){const p=[...u,s];h.forEach((d,y)=>{const x=a(d,c+1,p,y);x&&f.push(x)})}if(n({node:s,depth:c,path:u,index:l})||f.length>0){const{[t]:p,...d}=s;return{...d,[t]:f}}return null};return i.forEach((s,c)=>{const u=a(s,0,[s],c);u&&o.push(u)}),o}function Oe(e,n,r={}){const{children:t}=g(r),i=Array.isArray(e)?e:[e],o=[],a=(s,c,u,l=0)=>{const h=s[t],f=[];if(h&&h.length>0){const x=[...u,s];h.forEach((V,G)=>{f.push(a(V,c+1,x,G))})}const p=n({node:s,depth:c,path:u,index:l}),{[t]:d,...y}=p;return{...y,[t]:f}};return i.forEach((s,c)=>{o.push(a(s,0,[s],c))}),o}function Re(e,n,r={}){const t=Array.isArray(e)?e:[e],i=j("forEach")==="dfs"?v(t,r):E(t,r);for(const o of i)if(n({node:o.node,depth:o.depth,path:o.path,index:o.index})===!1)break}function ke(e,n={}){const{children:r}=g(n),t=Array.isArray(e)?e:[e];let i=0,o=0,a=0,s=0;const c=(u,l)=>{i++,a=Math.max(a,l);const h=u[r];h&&h.length>0?(s++,h.forEach(f=>c(f,l+1))):o++};return t.forEach(u=>c(u,1)),{total:i,leaves:o,depth:a,branches:s}}function Ie(e,n={}){const{id:r,children:t}=g(n),i=Array.isArray(e)?e:[e],o=[],a=new Set,s=(c,u,l)=>{const h=c[r];if(!h||typeof h!="string"){o.push(`Node at depth ${u} has invalid or missing ID`);return}if(a.has(h)){o.push(`Duplicate ID found: ${h}`);return}if(a.add(h),l.some(p=>p[r]===h)){o.push(`Circular reference detected for ID: ${h}`);return}const f=c[t];if(f!==void 0&&!Array.isArray(f)){o.push(`Node ${h} has invalid children property (not an array)`);return}if(f&&f.length>0){const p=[...l,c];f.forEach(d=>{s(d,u+1,p)})}};return i.forEach(c=>s(c,0,[])),{isValid:o.length===0,errors:o}}class Pe{static fromList=Ae;static toList=xe;static estimateSize=ve;static find=I;static findAll=Ue;static findById=Ee;static insertBefore=Ce;static insertAfter=Se;static remove=$e;static filter=je;static transform=Oe;static forEach=Re;static getStats=ke;static validate=Ie}function Le(e,n){const r=[];for(let t=0;t<e.length;t+=n)r.push(e.slice(t,t+n));return r}function Te(e,n=1){return n===1?e.flat():e.flat(n)}function Ne(e){return[...new Set(e)]}function Fe(e,n){let r;return(...t)=>{clearTimeout(r),r=setTimeout(()=>e(...t),n)}}function Me(e){return new Promise(n=>setTimeout(n,e))}function ze(e){let n,r;return{promise:new Promise((t,i)=>{r=i,n=setTimeout(t,e)}),cancel:()=>{clearTimeout(n),r(new Error("Sleep was cancelled"))}}}function Be(e,n){let r=!1;return function(...t){r||(e.apply(this,t),r=!0,setTimeout(()=>{r=!1},n))}}function m(e,n){if(!e)return null;try{const r=n?new URL(e,n):new URL(e);return{href:r.href,protocol:r.protocol,host:r.host,hostname:r.hostname,port:r.port,pathname:r.pathname,search:r.search,hash:r.hash,auth:r.username?`${r.username}${r.password?`:${r.password}`:""}`:"",origin:r.origin}}catch{return null}}function De(e){if(!e)return!1;try{return!!new URL(e)}catch{return!1}}function P(e){return e?e.startsWith("//")?!0:/^[a-z][a-z0-9+.-]*:/i.test(e):!1}function We(e){return e?!P(e):!1}function L(e){return m(e)?.hostname??""}function Ve(e){const n=L(e);if(!n)return"";const r=["co.uk","co.jp","co.kr","co.nz","co.za","co.in","com.au","com.br","com.cn","com.tw","com.hk","com.sg","org.uk","org.au","net.au","net.cn","gov.uk","gov.au","edu.au","edu.cn","ac.uk","ac.jp"],t=n.split(".");if(t.length>=3){const i=t.slice(-2).join(".");if(r.includes(i))return t.slice(-3).join(".")}return t.length>=2?t.slice(-2).join("."):n}function Ge(e){const n=m(e);if(!n)return"";const r=n.pathname.split("/").pop()||"",t=r.lastIndexOf(".");return t===-1||t===0?"":r.slice(t+1).toLowerCase()}function Qe(e,n=!0){const r=m(e);if(!r)return"";const t=r.pathname.split("/").pop()||"";if(!t||t==="/")return"";if(n)return t;const i=t.lastIndexOf(".");return i>0?t.slice(0,i):t}function A(e){if(!e)return{};const n=e.startsWith("?")?e.slice(1):e;if(!n)return{};const r={},t=new URLSearchParams(n);for(const[i,o]of t.entries()){const a=r[i];a!==void 0?Array.isArray(a)?a.push(o):r[i]=[a,o]:r[i]=o}return r}function C(e,n={}){const{skipNull:r=!1,skipEmpty:t=!1,arrayFormat:i="repeat"}=n,o=[];for(const[a,s]of Object.entries(e)){if(s==null){if(r)continue;o.push(`${encodeURIComponent(a)}=`);continue}if(Array.isArray(s)){const u=s.filter(l=>l==null?!r:l===""?!t:!0);if(u.length===0)continue;switch(i){case"bracket":for(const l of u)o.push(`${encodeURIComponent(a)}[]=${encodeURIComponent(String(l??""))}`);break;case"index":u.forEach((l,h)=>{o.push(`${encodeURIComponent(a)}[${h}]=${encodeURIComponent(String(l??""))}`)});break;case"comma":o.push(`${encodeURIComponent(a)}=${u.map(l=>encodeURIComponent(String(l??""))).join(",")}`);break;default:for(const l of u)o.push(`${encodeURIComponent(a)}=${encodeURIComponent(String(l??""))}`)}continue}const c=String(s);c===""&&t||o.push(`${encodeURIComponent(a)}=${encodeURIComponent(c)}`)}return o.join("&")}function Ze(e,n){if(!e||!n)return null;try{return new URL(e,"http://localhost").searchParams.get(n)}catch{const r=e.indexOf("?");if(r===-1)return null;const t=A(e.slice(r))[n];return Array.isArray(t)?t[0]??null:t??null}}function qe(e,n){if(!e||!n)return[];try{return new URL(e,"http://localhost").searchParams.getAll(n)}catch{const r=e.indexOf("?");if(r===-1)return[];const t=A(e.slice(r))[n];return t?Array.isArray(t)?t:[t]:[]}}function T(e,n,r){if(!e||!n)return e;try{const t=new URL(e);return r==null?t.searchParams.delete(n):t.searchParams.set(n,String(r)),t.toString()}catch{const t=e.indexOf("#"),i=t!==-1?e.slice(t+1):"",o=t!==-1?e.slice(0,t):e,a=o.indexOf("?"),s=a!==-1?o.slice(0,a):o,c=a!==-1?o.slice(a+1):"",u=A(c);r==null?delete u[n]:u[n]=String(r);const l=C(u);let h=s;return l&&(h+=`?${l}`),i&&(h+=`#${i}`),h}}function Ke(e,n){let r=e;for(const[t,i]of Object.entries(n))if(Array.isArray(i)){r=F(r,t);for(const o of i)r=N(r,t,o)}else r=T(r,t,i);return r}function N(e,n,r){if(!e||!n||r===null||r===void 0)return e;try{const t=new URL(e);return t.searchParams.append(n,String(r)),t.toString()}catch{const[t,i]=e.split("?"),[o,a]=(i||"").split("#"),s=o?"&":"",c=`${encodeURIComponent(n)}=${encodeURIComponent(String(r))}`;let u=t||"";return u+=`?${o||""}${s}${c}`,a&&(u+=`#${a}`),u}}function F(e,n){if(!e||!n)return e;try{const r=new URL(e);return r.searchParams.delete(n),r.toString()}catch{const[r,t]=e.split("?"),[i,o]=(t||"").split("#"),a=A(i||"");delete a[n];const s=C(a);let c=r||"";return s&&(c+=`?${s}`),o&&(c+=`#${o}`),c}}function _e(e,n){if(!e||!n)return!1;try{return new URL(e,"http://localhost").searchParams.has(n)}catch{const r=e.indexOf("?");if(r===-1)return!1;const t=A(e.slice(r));return n in t}}function M(...e){if(e.length===0)return"";const n=e.filter(t=>t!=null&&t!=="");if(n.length===0)return"";let r=n[0];for(let t=1;t<n.length;t++){const i=n[t],o=r.endsWith("/"),a=i.startsWith("/");o&&a?r+=i.slice(1):!o&&!a?r+=`/${i}`:r+=i}return r}function He(e){if(!e)return"";const n=m(e);if(n){const i=z(n.pathname);return`${n.origin}${i}${n.search}${n.hash}`}const[r,t]=e.split(/(?=[?#])/);return z(r||"")+(t||"")}function z(e){if(!e)return"";const n=e.startsWith("/"),r=e.endsWith("/")&&e.length>1,t=e.split("/").filter(Boolean),i=[];for(const a of t)if(a!=="."){if(a===".."){i.pop();continue}i.push(a)}let o=i.join("/");return n&&(o=`/${o}`),r&&o!=="/"&&(o+="/"),o||(n?"/":"")}function Je(e){if(!e)return"";const[n,...r]=e.split(/(?=[?#])/);return n?(n.length>1&&n.endsWith("/")?n.slice(0,-1):n)+r.join(""):e}function Xe(e){if(!e)return"/";const n=e.search(/[?#]/),r=n===-1?e:e.slice(0,n),t=n===-1?"":e.slice(n);return r?(r.endsWith("/")?r:`${r}/`)+t:`/${t}`}function Ye(e){return e?e.replace(/^\/+/,""):""}function et(e){return e?e.startsWith("/")?e:`/${e}`:"/"}function tt(e,n,r,t){let i=e;if(n&&(i=M(i,n)),r&&Object.keys(r).length>0){const o=C(r);o&&(i+=(i.includes("?")?"&":"?")+o)}if(t){const o=t.startsWith("#")?t:`#${t}`;i+=o}return i}function nt(e){if(!e)return"";try{return decodeURIComponent(e)}catch{return e}}function rt(e){if(!e)return"";try{return encodeURIComponent(e)}catch{return e}}function ot(e,n){const r=m(e),t=m(n);return!r||!t?!1:r.origin===t.origin}function it(e,n){if(!e)return n;try{return new URL(e,n).href}catch{return e}}function st(e,n){const r=m(e),t=m(n);if(!r||!t||r.origin!==t.origin)return n;const i=r.pathname.split("/").filter(Boolean),o=t.pathname.split("/").filter(Boolean);let a=0;const s=Math.min(i.length,o.length);for(let f=0;f<s&&i[f]===o[f];f++)a++;const c=i.length-a,u=o.slice(a),l=[];for(let f=0;f<c;f++)l.push("..");l.push(...u);let h=l.join("/")||".";return t.search&&(h+=t.search),t.hash&&(h+=t.hash),h}function B(e){return Array.isArray(e)}function D(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function W(e){return typeof e=="string"}function ct(e){return e==null?!0:B(e)||W(e)?e.length===0:D(e)?Object.keys(e).length===0:!1}function at(e){return typeof e=="function"}function ut(e){return typeof e=="number"&&!Number.isNaN(e)}function lt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.prototype.toString.call(e)==="[object Object]"}export{Pe as Tree,N as appendQueryParam,tt as buildUrl,le as camelCase,fe as capitalize,Le as chunk,_ as convertSvgToPng,R as convertToKebabCase,Fe as debounce,w as deepClone,et as ensureLeadingSlash,Xe as ensureTrailingSlash,H as extractFilename,Te as flatten,J as formatFileSize,L as getDomain,ie as getPath,Ze as getQueryParam,qe as getQueryParams,ue as getRandomUUID,st as getRelativePath,Ve as getRootDomain,Ge as getUrlExtension,Qe as getUrlFilename,_e as hasQueryParam,P as isAbsoluteUrl,B as isArray,ct as isEmpty,at as isFunction,ut as isNumber,D as isObject,lt as isPlainObject,We as isRelativeUrl,ot as isSameOrigin,W as isString,O as isValidContainer,De as isValidUrl,se as joinPath,M as joinUrl,he as kebabCase,pe as lowerCase,de as lowerFirst,He as normalizeUrl,ee as omit,te as omitUndefined,A as parseQuery,m as parseUrl,ge as pascalCase,ne as pick,Ye as removeLeadingSlash,F as removeQueryParam,Je as removeTrailingSlash,X as replaceCurrentColor,nt as safeDecodeURIComponent,rt as safeEncodeURIComponent,re as separate,oe as separateMany,ce as setPath,T as setQueryParam,Ke as setQueryParams,ae as simpleHash,Me as sleep,ze as sleepWithCancel,me as snakeCase,ye as startCase,C as stringifyQuery,Be as throttle,it as toAbsoluteUrl,S as toPath,Y as triggerDownload,Ne as unique,we as upperCase,be as upperFirst,Z as useAppStorage,q as useCopyCode,$ as words};
|
|
1
|
+
import{useStorage as H}from"@vueuse/core";function Z(e){const{key:t,defaultValue:r,storage:n="localStorage",prefix:i="movk"}=e,o=`${i}:${t}`,s=(()=>{if(!(typeof window>"u"))return n==="localStorage"?localStorage:sessionStorage})();function a(h){if(h===null)return r;try{return JSON.parse(h)}catch(p){return console.warn(`[AppStorage] Failed to parse value for key "${o}". Using default value.`,p),r}}const c=H(o,r,s,{mergeDefaults:!0,serializer:{read:a,write:h=>JSON.stringify(h)}});function u(){if(!s)return r;const h=s.getItem(o);return a(h)}function l(h){c.value=h}function f(){s&&(c.value=null)}return{state:c,getItem:u,setItem:l,removeItem:f}}async function K(e){if(typeof e!="string")throw new TypeError("Text must be a string");if(typeof window>"u")return console.warn("useCopyCode: Not available in server environment"),!1;if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("Clipboard API failed, falling back to legacy method:",t)}try{return J(e)}catch(t){return console.error("Failed to copy text:",t),!1}}function J(e){if(typeof document>"u")return console.warn("copyTextLegacy: Document not available"),!1;const t=document.createElement("textarea"),r=document.activeElement,n=document.getSelection(),i=n&&n.rangeCount>0?n.getRangeAt(0):null;try{return t.value=e,t.setAttribute("readonly",""),t.setAttribute("contenteditable","true"),Object.assign(t.style,{contain:"strict",position:"absolute",left:"-9999px",top:"-9999px",fontSize:"12pt",border:"0",padding:"0",margin:"0",outline:"none",boxShadow:"none",background:"transparent"}),document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange&&t.setSelectionRange(0,e.length),document.execCommand("copy")}catch(o){return console.error("Legacy copy method failed:",o),!1}finally{t.parentNode&&document.body.removeChild(t),i&&n&&(n.removeAllRanges(),n.addRange(i)),r instanceof HTMLElement&&r.focus()}}async function X(e){if(!e||typeof e!="string")throw new Error("Invalid SVG string provided");if(typeof window>"u"||typeof document>"u")throw new TypeError("convertSvgToPng is only available in browser environment");return new Promise((t,r)=>{const n=new Image,i=document.createElement("canvas"),o=i.getContext("2d");if(!o){r(new Error("Canvas context not available"));return}n.onload=()=>{try{i.width=n.width,i.height=n.height,o.drawImage(n,0,0),i.toBlob(s=>{s?t(s):r(new Error("Failed to convert canvas to Blob"))},"image/png")}catch(s){r(new Error(`Error during canvas conversion: ${s}`))}},n.onerror=()=>{r(new Error("Failed to load SVG image"))};try{n.src=`data:image/svg+xml;base64,${btoa(e)}`}catch(s){r(new Error(`Failed to encode SVG: ${s}`))}})}function Y(e,t="file"){if(!e)return t;const r=e.get("content-disposition");if(r){const n=r.match(/filename\*?=(?:"([^"]+)"|([^;]+))/i);if(n){let i=n[1]??n[2];if(!i)return t;if(i.startsWith('"')&&i.endsWith('"')&&(i=i.slice(1,-1)),r.includes("filename*=")){const o=i.split("''");if(o.length===2&&o[1])try{i=decodeURIComponent(o[1])}catch{return t}}return i}}return t}function ee(e){if(!Number.isFinite(e)||e<0||e===0)return"0 Bytes";const t=1024,r=["Bytes","KB","MB","GB","TB","PB"],n=Math.floor(Math.log(e)/Math.log(t));return n>=r.length?`${Number.parseFloat((e/t**(r.length-1)).toFixed(2))} ${r[r.length-1]}`:`${Number.parseFloat((e/t**n).toFixed(2))} ${r[n]}`}async function te(e,t){if(!e||typeof e!="string")throw new Error("Invalid SVG path provided");try{const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch SVG file: ${r.status} ${r.statusText}`);const n=await r.text();if(!t)return n;if(typeof window>"u"||typeof DOMParser>"u")return console.warn("replaceCurrentColor: DOM manipulation not available in server environment, returning original SVG"),n;const i=new DOMParser().parseFromString(n,"image/svg+xml");if(i.querySelector("parsererror"))throw new Error("Invalid SVG content");const o=i.querySelector("svg");if(!o)throw new Error("No SVG element found in the document");o.hasAttribute("fill")||o.setAttribute("fill","currentColor");const s=a=>{a.getAttribute("fill")==="currentColor"&&a.setAttribute("fill",t),a.getAttribute("stroke")==="currentColor"&&a.setAttribute("stroke",t),Array.from(a.children).forEach(c=>{s(c)})};return s(o),new XMLSerializer().serializeToString(i)}catch(r){throw r instanceof Error?r:new Error(`Unexpected error occurred: ${r}`)}}function ne(e,t){if(typeof window>"u"||typeof document>"u"){console.warn("triggerDownload: Not available in server environment");return}const r=URL.createObjectURL(e),n=document.createElement("a");n.href=r,n.download=t,n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(r)}function w(e,t=new WeakMap){if(e===null||typeof e!="object")return e;try{const a=globalThis.structuredClone;if(typeof a=="function")return a(e)}catch(a){console.error("Error occurred while cloning:",a)}const r=e,n=t.get(r);if(n)return n;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){const a=new Map;t.set(r,a);for(const[c,u]of e.entries())a.set(w(c,t),w(u,t));return a}if(e instanceof Set){const a=new Set;t.set(r,a);for(const c of e.values())a.add(w(c,t));return a}if(e instanceof ArrayBuffer)return e.slice(0);if(ArrayBuffer.isView(e)){const a=e.constructor;return new a(e)}if(e instanceof URL)return new URL(e.toString());if(e instanceof Error){const a=new e.constructor(e.message);return a.name=e.name,a.stack=e.stack,a}if(Array.isArray(e)){const a=[];t.set(r,a);for(const c of e)a.push(w(c,t));return a}const i=Object.getPrototypeOf(e),o=Object.create(i);t.set(r,o);const s=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const a of s){const c=Object.getOwnPropertyDescriptor(e,a);c&&("value"in c&&(c.value=w(e[a],t)),Object.defineProperty(o,a,c))}return o}function v(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.prototype.toString.call(e)==="[object Object]"}const re=new Set(["__proto__","constructor"]);function oe(e){return{arrayStrategy:e?.arrayStrategy??"concat",nullHandling:e?.nullHandling??"skip",customMerger:e?.customMerger}}function ie(e){return[...Object.keys(e),...Object.getOwnPropertySymbols(e).filter(t=>Object.prototype.propertyIsEnumerable.call(e,t))]}function $(e,t,r,n,i){const o={...e};for(const s of ie(t)){if(typeof s=="string"&&re.has(s))continue;const a=o[s],c=t[s];if(r.customMerger){const u=r.customMerger(s,a,c,n);if(u!==void 0){o[s]=u;continue}}if(c==null){if(r.nullHandling==="skip"&&s in o)continue;o[s]=c;continue}if(Array.isArray(c)){if(Array.isArray(a))switch(r.arrayStrategy){case"replace":o[s]=[...c];break;case"unique":o[s]=[...new Set([...a,...c])];break;case"concat":default:o[s]=[...a,...c];break}else o[s]=[...c];continue}if(v(c)){if(i.has(c)){o[s]=i.get(c);continue}const u=[...n,s],l={};if(i.set(c,l),v(a)){const f=$(a,c,r,u,i);Object.assign(l,f),o[s]=l}else{const f=$({},c,r,u,i);Object.assign(l,f),o[s]=l}continue}o[s]=c}return o}function R(e,t){if(!Array.isArray(e))return{};const r=oe(t),n=e.filter(v);if(n.length===0)return{};const i=new WeakMap;return n.reduce((o,s)=>$(o,s,r,[],i),{})}function se(e){return t=>R(t,e)}function ce(e,t){if(!e||typeof e!="object")return{};const r=new Set(t),n={};for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&!r.has(i)&&(n[i]=e[i]);return n}function ae(e){return!e||typeof e!="object"||Array.isArray(e)?e:Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function ue(e,t){if(!e||typeof e!="object")return{};const r={};for(const n of t)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}function le(e,t){if(!e||typeof e!="object")return{picked:{},omitted:{}};if(t.length===0)return{picked:{},omitted:{...e}};const r=new Set(t),n={},i={};for(const o in e)if(Object.hasOwn(e,o)){const s=o;r.has(s)?n[o]=e[s]:i[o]=e[s]}return{picked:n,omitted:i}}function fe(e,t){if(!e||typeof e!="object")return{...Object.fromEntries(Object.keys(t).map(o=>[o,{}])),others:{}};const r=Object.keys(t),n=new Map;for(const o of r){const s=new Set(t[o]);n.set(o,s)}const i=Object.create(null);for(const o of r)i[o]={};i.others={};for(const o in e)if(Object.hasOwn(e,o)){const s=o;let a=!1;for(const c of r)if(n.get(c).has(s)){i[c][o]=e[s],a=!0;break}a||(i.others[o]=e[s])}return i}function j(e){if(Array.isArray(e))return e.slice();const t=[];if(e==="")return t;let r=0;const n=e,i=n.length;function o(a){let c="",u=a;for(;u<i;){const l=n.charCodeAt(u);if(l===46)break;if(l===92){u++,u<i&&(c+=n[u]),u++;continue}if(l===91)break;c+=n[u],u++}return{value:c,next:u}}function s(a){let c=a+1;for(;c<i&&/\s/.test(n[c]);)c++;if(c>=i)throw new Error('Invalid path: missing closing "]"');const u=n[c];if(u==='"'||u==="'"){const h=u;c++;let p="",d=!1;for(;c<i;){if(n.charCodeAt(c)===92){c++,c<i&&(p+=n[c]),c++;continue}if(n[c]===h){d=!0,c++;break}p+=n[c],c++}if(!d)throw new Error("Invalid path: missing closing quote in bracket");for(;c<i&&/\s/.test(n[c]);)c++;if(c>=i||n[c]!=="]")throw new Error('Invalid path: missing closing "]"');return c++,{segment:p,next:c}}let l="";for(;c<i&&n[c]!=="]";)l+=n[c],c++;if(c>=i)throw new Error('Invalid path: missing closing "]"');const f=l.trim();return/^(?:0|[1-9]\d*)$/.test(f)?(c++,{segment:Number(f),next:c}):(c++,{segment:f,next:c})}for(;r<i;){const a=n.charCodeAt(r);if(a===46){r++;continue}if(a===91){const{segment:l,next:f}=s(r);l!==null&&t.push(l),r=f;continue}const{value:c,next:u}=o(r);(c.length>0||u<i&&n[u]===".")&&t.push(c),r=u}return t}function he(e,t,r){const n=j(t);if(n.length===0)return e;let i=e;for(let o=0;o<n.length;o++){if(i==null)return r;const s=n[o];i=i[s]}return i===void 0?r:i}function pe(e){let t="";for(let r=0;r<e.length;r++){const n=e[r];if(typeof n=="number"&&Number.isInteger(n)&&n>=0){t+=`[${n}]`;continue}const i=String(n),o=/^[A-Z_$][\w$]*$/i.test(i);if(t.length===0&&o){t+=i;continue}if(o){t+=`.${i}`;continue}const s=i.replace(/\\/g,"\\\\").replace(/'/g,"\\'");t+=`['${s}']`}return t}function I(e){return e!==null&&typeof e=="object"}function de(e,t,r){const n=j(t);if(n.length===0)return e;let i=e;for(let o=0;o<n.length;o++){const s=n[o];if(o===n.length-1){i[s]=r;break}const a=n[o+1];let c=i[s];const u=typeof a=="number";if(I(c)?u&&!Array.isArray(c)&&(c=[],i[s]=c):(c=u?[]:{},i[s]=c),u&&Array.isArray(c)){const l=Number(a);Number.isInteger(l)&&l>=0&&c.length<=l&&(c.length=l+1)}i=c}return e}function ge(e){let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);t=(t<<5)-t+n,t=t&t}return Math.abs(t).toString(36)}function me(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function P(e,t=!1){if(!e||typeof e!="object"||Array.isArray(e))return e;const r=i=>i.replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase(),n={};for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){const o=r(i),s=e[i];t&&s&&typeof s=="object"&&!Array.isArray(s)?n[o]=P(s,!0):n[o]=s}return n}function E(e){return e?e.replace(/[_-]/g," ").match(/[A-Z]{2,}(?=[A-Z][a-z]|\b)|[A-Z]?[a-z]+|\d+/g)||[]:[]}function b(e,t){if(!e)return"";const r=E(e);return r.length===0?"":r.map((n,i)=>{const o=n.toLowerCase(),s=n.toUpperCase();if(t.transform)return t.transform(n,i,o,s);switch(t.casing){case"lower":return o;case"upper":return s;case"capitalize":return o.charAt(0).toUpperCase()+o.slice(1);default:return n}}).join(t.separator??"")}function L(e,t){if(!e)return"";const r=e.charAt(0);return(t?r.toUpperCase():r.toLowerCase())+e.slice(1)}function ye(e){return b(e,{separator:"",transform:(t,r,n)=>r===0?n:n.charAt(0).toUpperCase()+n.slice(1)})}function we(e){return e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():""}function be(e){return b(e,{separator:"-",casing:"lower"})}function Ae(e){return b(e,{separator:" ",casing:"lower"})}function xe(e){return L(e,!1)}function ve(e){return b(e,{separator:"",casing:"capitalize"})}function Se(e){return b(e,{separator:"_",casing:"lower"})}function Ce(e){return e?E(e).map(t=>t.toUpperCase()===t&&t.length>1?t:t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function $e(e){return b(e,{separator:" ",casing:"upper"})}function je(e){return L(e,!0)}const U={id:"id",pid:"pid",children:"children"};function g(e={}){return{id:e.id??U.id,pid:e.pid??U.pid,children:e.children??U.children}}function*S(e,t={},r=[]){const{children:n}=g(t);let i=0;for(const o of e){const s=[...r,o];yield{node:o,path:s,depth:r.length,index:i++};const a=o[n];a&&a.length>0&&(yield*S(a,t,s))}}function*O(e,t={}){const{children:r}=g(t),n=e.map((o,s)=>({node:o,path:[o],depth:0,index:s}));let i=e.length;for(;n.length>0;){const o=n.shift();yield o;const s=o.node[r];s&&s.length>0&&s.forEach(a=>{const c=[...o.path,a];n.push({node:a,path:c,depth:o.depth+1,index:i++})})}}function k(e){switch(e){case"find":case"findAll":case"filter":case"transform":case"forEach":case"stats":case"validate":return"dfs";default:return"dfs"}}function Ee(e,t={}){const{id:r,pid:n,children:i}=g(t);if(!Array.isArray(e)||e.length===0)return[];const o=new Map,s=[];return e.forEach(a=>{const{[i]:c,...u}=a,l={...u,[i]:[]};o.set(a[r],l)}),e.forEach(a=>{const c=o.get(a[r]),u=a[n];u&&o.has(u)?o.get(u)[i].push(c):s.push(c)}),s}function Ue(e,t={}){const{children:r}=g(t),n=[],i=Array.isArray(e)?e:[e],o=s=>{const{[r]:a,...c}=s;n.push(c),a&&a.length>0&&a.forEach(o)};return i.forEach(o),n}function Oe(e,t={}){const{children:r}=g(t),n=Array.isArray(e)?e:[e];let i=0;const o=s=>{i++;const a=s[r];a&&a.length>0&&a.forEach(o)};return n.forEach(o),i}function ke(e,t,r,n={}){const{id:i,children:o}=g(n),{[o]:s,...a}=r,c={...a,[o]:[]},u=(l,f)=>{for(let h=0;h<l.length;h++){const p=l[h];if(!p)continue;if(p[i]===t)return l.splice(h,0,c),!0;const d=p[o];if(d&&d.length>0){const y=[...f,p];if(u(d,y))return!0}}return!1};return u(e,[])}function Re(e,t,r,n={}){const{id:i,children:o}=g(n),{[o]:s,...a}=r,c={...a,[o]:[]},u=(l,f)=>{for(let h=0;h<l.length;h++){const p=l[h];if(!p)continue;if(p[i]===t)return l.splice(h+1,0,c),!0;const d=p[o];if(d&&d.length>0){const y=[...f,p];if(u(d,y))return!0}}return!1};return u(e,[])}function Ie(e,t,r={}){const{id:n,children:i}=g(r),o=s=>{for(let a=0;a<s.length;a++){const c=s[a];if(!c)continue;if(c[n]===t)return s.splice(a,1)[0];const u=c[i];if(u&&u.length>0){const l=o(u);if(l)return l}}};return o(e)}function T(e,t,r={}){const n=Array.isArray(e)?e:[e],i=k("find")==="dfs"?S(n,r):O(n,r);for(const o of i)if(t({node:o.node,depth:o.depth,path:o.path,index:o.index}))return o.node}function Pe(e,t,r={}){const n=Array.isArray(e)?e:[e],i=k("findAll"),o=[],s=i==="dfs"?S(n,r):O(n,r);for(const a of s)t({node:a.node,depth:a.depth,path:a.path,index:a.index})&&o.push(a.node);return o}function Le(e,t,r={}){const{id:n}=g(r);return T(e,({node:i})=>i[n]===t,r)}function Te(e,t,r={}){const{children:n}=g(r),i=Array.isArray(e)?e:[e],o=[],s=(a,c,u,l=0)=>{const f=a[n],h=[];if(f&&f.length>0){const p=[...u,a];f.forEach((d,y)=>{const x=s(d,c+1,p,y);x&&h.push(x)})}if(t({node:a,depth:c,path:u,index:l})||h.length>0){const{[n]:p,...d}=a;return{...d,[n]:h}}return null};return i.forEach((a,c)=>{const u=s(a,0,[a],c);u&&o.push(u)}),o}function Me(e,t,r={}){const{children:n}=g(r),i=Array.isArray(e)?e:[e],o=[],s=(a,c,u,l=0)=>{const f=a[n],h=[];if(f&&f.length>0){const x=[...u,a];f.forEach((_,q)=>{h.push(s(_,c+1,x,q))})}const p=t({node:a,depth:c,path:u,index:l}),{[n]:d,...y}=p;return{...y,[n]:h}};return i.forEach((a,c)=>{o.push(s(a,0,[a],c))}),o}function Ne(e,t,r={}){const n=Array.isArray(e)?e:[e],i=k("forEach")==="dfs"?S(n,r):O(n,r);for(const o of i)if(t({node:o.node,depth:o.depth,path:o.path,index:o.index})===!1)break}function Fe(e,t={}){const{children:r}=g(t),n=Array.isArray(e)?e:[e];let i=0,o=0,s=0,a=0;const c=(u,l)=>{i++,s=Math.max(s,l);const f=u[r];f&&f.length>0?(a++,f.forEach(h=>c(h,l+1))):o++};return n.forEach(u=>c(u,1)),{total:i,leaves:o,depth:s,branches:a}}function De(e,t={}){const{id:r,children:n}=g(t),i=Array.isArray(e)?e:[e],o=[],s=new Set,a=(c,u,l)=>{const f=c[r];if(!f||typeof f!="string"){o.push(`Node at depth ${u} has invalid or missing ID`);return}if(s.has(f)){o.push(`Duplicate ID found: ${f}`);return}if(s.add(f),l.some(p=>p[r]===f)){o.push(`Circular reference detected for ID: ${f}`);return}const h=c[n];if(h!==void 0&&!Array.isArray(h)){o.push(`Node ${f} has invalid children property (not an array)`);return}if(h&&h.length>0){const p=[...l,c];h.forEach(d=>{a(d,u+1,p)})}};return i.forEach(c=>a(c,0,[])),{isValid:o.length===0,errors:o}}class ze{static fromList=Ee;static toList=Ue;static estimateSize=Oe;static find=T;static findAll=Pe;static findById=Le;static insertBefore=ke;static insertAfter=Re;static remove=Ie;static filter=Te;static transform=Me;static forEach=Ne;static getStats=Fe;static validate=De}function Be(e,t){const r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function We(e,t=1){return t===1?e.flat():e.flat(t)}function Ve(e){return[...new Set(e)]}function Ge(e,t){let r;return(...n)=>{clearTimeout(r),r=setTimeout(()=>e(...n),t)}}function Qe(e){return new Promise(t=>setTimeout(t,e))}function _e(e){let t,r;return{promise:new Promise((n,i)=>{r=i,t=setTimeout(n,e)}),cancel:()=>{clearTimeout(t),r(new Error("Sleep was cancelled"))}}}function qe(e,t){let r=!1;return function(...n){r||(e.apply(this,n),r=!0,setTimeout(()=>{r=!1},t))}}function m(e,t){if(!e)return null;try{const r=t?new URL(e,t):new URL(e);return{href:r.href,protocol:r.protocol,host:r.host,hostname:r.hostname,port:r.port,pathname:r.pathname,search:r.search,hash:r.hash,auth:r.username?`${r.username}${r.password?`:${r.password}`:""}`:"",origin:r.origin}}catch{return null}}function He(e){if(!e)return!1;try{return!!new URL(e)}catch{return!1}}function M(e){return e?e.startsWith("//")?!0:/^[a-z][a-z0-9+.-]*:/i.test(e):!1}function Ze(e){return e?!M(e):!1}function N(e){return m(e)?.hostname??""}function Ke(e){const t=N(e);if(!t)return"";const r=["co.uk","co.jp","co.kr","co.nz","co.za","co.in","com.au","com.br","com.cn","com.tw","com.hk","com.sg","org.uk","org.au","net.au","net.cn","gov.uk","gov.au","edu.au","edu.cn","ac.uk","ac.jp"],n=t.split(".");if(n.length>=3){const i=n.slice(-2).join(".");if(r.includes(i))return n.slice(-3).join(".")}return n.length>=2?n.slice(-2).join("."):t}function Je(e){const t=m(e);if(!t)return"";const r=t.pathname.split("/").pop()||"",n=r.lastIndexOf(".");return n===-1||n===0?"":r.slice(n+1).toLowerCase()}function Xe(e,t=!0){const r=m(e);if(!r)return"";const n=r.pathname.split("/").pop()||"";if(!n||n==="/")return"";if(t)return n;const i=n.lastIndexOf(".");return i>0?n.slice(0,i):n}function A(e){if(!e)return{};const t=e.startsWith("?")?e.slice(1):e;if(!t)return{};const r={},n=new URLSearchParams(t);for(const[i,o]of n.entries()){const s=r[i];s!==void 0?Array.isArray(s)?s.push(o):r[i]=[s,o]:r[i]=o}return r}function C(e,t={}){const{skipNull:r=!1,skipEmpty:n=!1,arrayFormat:i="repeat"}=t,o=[];for(const[s,a]of Object.entries(e)){if(a==null){if(r)continue;o.push(`${encodeURIComponent(s)}=`);continue}if(Array.isArray(a)){const u=a.filter(l=>l==null?!r:l===""?!n:!0);if(u.length===0)continue;switch(i){case"bracket":for(const l of u)o.push(`${encodeURIComponent(s)}[]=${encodeURIComponent(String(l??""))}`);break;case"index":u.forEach((l,f)=>{o.push(`${encodeURIComponent(s)}[${f}]=${encodeURIComponent(String(l??""))}`)});break;case"comma":o.push(`${encodeURIComponent(s)}=${u.map(l=>encodeURIComponent(String(l??""))).join(",")}`);break;default:for(const l of u)o.push(`${encodeURIComponent(s)}=${encodeURIComponent(String(l??""))}`)}continue}const c=String(a);c===""&&n||o.push(`${encodeURIComponent(s)}=${encodeURIComponent(c)}`)}return o.join("&")}function Ye(e,t){if(!e||!t)return null;try{return new URL(e,"http://localhost").searchParams.get(t)}catch{const r=e.indexOf("?");if(r===-1)return null;const n=A(e.slice(r))[t];return Array.isArray(n)?n[0]??null:n??null}}function et(e,t){if(!e||!t)return[];try{return new URL(e,"http://localhost").searchParams.getAll(t)}catch{const r=e.indexOf("?");if(r===-1)return[];const n=A(e.slice(r))[t];return n?Array.isArray(n)?n:[n]:[]}}function F(e,t,r){if(!e||!t)return e;try{const n=new URL(e);return r==null?n.searchParams.delete(t):n.searchParams.set(t,String(r)),n.toString()}catch{const n=e.indexOf("#"),i=n!==-1?e.slice(n+1):"",o=n!==-1?e.slice(0,n):e,s=o.indexOf("?"),a=s!==-1?o.slice(0,s):o,c=s!==-1?o.slice(s+1):"",u=A(c);r==null?delete u[t]:u[t]=String(r);const l=C(u);let f=a;return l&&(f+=`?${l}`),i&&(f+=`#${i}`),f}}function tt(e,t){let r=e;for(const[n,i]of Object.entries(t))if(Array.isArray(i)){r=z(r,n);for(const o of i)r=D(r,n,o)}else r=F(r,n,i);return r}function D(e,t,r){if(!e||!t||r===null||r===void 0)return e;try{const n=new URL(e);return n.searchParams.append(t,String(r)),n.toString()}catch{const[n,i]=e.split("?"),[o,s]=(i||"").split("#"),a=o?"&":"",c=`${encodeURIComponent(t)}=${encodeURIComponent(String(r))}`;let u=n||"";return u+=`?${o||""}${a}${c}`,s&&(u+=`#${s}`),u}}function z(e,t){if(!e||!t)return e;try{const r=new URL(e);return r.searchParams.delete(t),r.toString()}catch{const[r,n]=e.split("?"),[i,o]=(n||"").split("#"),s=A(i||"");delete s[t];const a=C(s);let c=r||"";return a&&(c+=`?${a}`),o&&(c+=`#${o}`),c}}function nt(e,t){if(!e||!t)return!1;try{return new URL(e,"http://localhost").searchParams.has(t)}catch{const r=e.indexOf("?");if(r===-1)return!1;const n=A(e.slice(r));return t in n}}function B(...e){if(e.length===0)return"";const t=e.filter(n=>n!=null&&n!=="");if(t.length===0)return"";let r=t[0];for(let n=1;n<t.length;n++){const i=t[n],o=r.endsWith("/"),s=i.startsWith("/");o&&s?r+=i.slice(1):!o&&!s?r+=`/${i}`:r+=i}return r}function rt(e){if(!e)return"";const t=m(e);if(t){const i=W(t.pathname);return`${t.origin}${i}${t.search}${t.hash}`}const[r,n]=e.split(/(?=[?#])/);return W(r||"")+(n||"")}function W(e){if(!e)return"";const t=e.startsWith("/"),r=e.endsWith("/")&&e.length>1,n=e.split("/").filter(Boolean),i=[];for(const s of n)if(s!=="."){if(s===".."){i.pop();continue}i.push(s)}let o=i.join("/");return t&&(o=`/${o}`),r&&o!=="/"&&(o+="/"),o||(t?"/":"")}function ot(e){if(!e)return"";const[t,...r]=e.split(/(?=[?#])/);return t?(t.length>1&&t.endsWith("/")?t.slice(0,-1):t)+r.join(""):e}function it(e){if(!e)return"/";const t=e.search(/[?#]/),r=t===-1?e:e.slice(0,t),n=t===-1?"":e.slice(t);return r?(r.endsWith("/")?r:`${r}/`)+n:`/${n}`}function st(e){return e?e.replace(/^\/+/,""):""}function ct(e){return e?e.startsWith("/")?e:`/${e}`:"/"}function at(e,t,r,n){let i=e;if(t&&(i=B(i,t)),r&&Object.keys(r).length>0){const o=C(r);o&&(i+=(i.includes("?")?"&":"?")+o)}if(n){const o=n.startsWith("#")?n:`#${n}`;i+=o}return i}function ut(e){if(!e)return"";try{return decodeURIComponent(e)}catch{return e}}function lt(e){if(!e)return"";try{return encodeURIComponent(e)}catch{return e}}function ft(e,t){const r=m(e),n=m(t);return!r||!n?!1:r.origin===n.origin}function ht(e,t){if(!e)return t;try{return new URL(e,t).href}catch{return e}}function pt(e,t){const r=m(e),n=m(t);if(!r||!n||r.origin!==n.origin)return t;const i=r.pathname.split("/").filter(Boolean),o=n.pathname.split("/").filter(Boolean);let s=0;const a=Math.min(i.length,o.length);for(let h=0;h<a&&i[h]===o[h];h++)s++;const c=i.length-s,u=o.slice(s),l=[];for(let h=0;h<c;h++)l.push("..");l.push(...u);let f=l.join("/")||".";return n.search&&(f+=n.search),n.hash&&(f+=n.hash),f}function V(e){return Array.isArray(e)}function G(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Q(e){return typeof e=="string"}function dt(e){return e==null?!0:V(e)||Q(e)?e.length===0:G(e)?Object.keys(e).length===0:!1}function gt(e){return typeof e=="function"}function mt(e){return typeof e=="number"&&!Number.isNaN(e)}export{ze as Tree,D as appendQueryParam,at as buildUrl,ye as camelCase,we as capitalize,Be as chunk,X as convertSvgToPng,P as convertToKebabCase,se as createDeepMerge,Ge as debounce,w as deepClone,R as deepMerge,ct as ensureLeadingSlash,it as ensureTrailingSlash,Y as extractFilename,We as flatten,ee as formatFileSize,N as getDomain,he as getPath,Ye as getQueryParam,et as getQueryParams,me as getRandomUUID,pt as getRelativePath,Ke as getRootDomain,Je as getUrlExtension,Xe as getUrlFilename,nt as hasQueryParam,M as isAbsoluteUrl,V as isArray,dt as isEmpty,gt as isFunction,mt as isNumber,G as isObject,v as isPlainObject,Ze as isRelativeUrl,ft as isSameOrigin,Q as isString,I as isValidContainer,He as isValidUrl,pe as joinPath,B as joinUrl,be as kebabCase,Ae as lowerCase,xe as lowerFirst,rt as normalizeUrl,ce as omit,ae as omitUndefined,A as parseQuery,m as parseUrl,ve as pascalCase,ue as pick,st as removeLeadingSlash,z as removeQueryParam,ot as removeTrailingSlash,te as replaceCurrentColor,ut as safeDecodeURIComponent,lt as safeEncodeURIComponent,le as separate,fe as separateMany,de as setPath,F as setQueryParam,tt as setQueryParams,ge as simpleHash,Qe as sleep,_e as sleepWithCancel,Se as snakeCase,Ce as startCase,C as stringifyQuery,qe as throttle,ht as toAbsoluteUrl,j as toPath,ne as triggerDownload,Ve as unique,$e as upperCase,je as upperFirst,Z as useAppStorage,K as useCopyCode,E as words};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@movk/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"packageManager": "pnpm@10.
|
|
4
|
+
"version": "1.2.0",
|
|
5
|
+
"packageManager": "pnpm@10.30.3",
|
|
6
6
|
"description": "为 TypeScript 项目设计的现代化、支持 Tree-Shaking 的工具函数库。",
|
|
7
7
|
"author": "YiXuan <mhaibaraai@gmail.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
"vue": "^3.5.25"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@vueuse/core": "^14.1
|
|
55
|
+
"@vueuse/core": "^14.2.1",
|
|
56
56
|
"fast-glob": "^3.3.3"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@antfu/eslint-config": "^6.
|
|
60
|
-
"@release-it/conventional-changelog": "^10.0.
|
|
61
|
-
"@types/node": "^
|
|
62
|
-
"eslint": "^
|
|
63
|
-
"release-it": "^19.2.
|
|
59
|
+
"@antfu/eslint-config": "^7.6.1",
|
|
60
|
+
"@release-it/conventional-changelog": "^10.0.5",
|
|
61
|
+
"@types/node": "^25.3.3",
|
|
62
|
+
"eslint": "^10.0.2",
|
|
63
|
+
"release-it": "^19.2.4",
|
|
64
64
|
"typescript": "^5.9.3",
|
|
65
65
|
"unbuild": "^3.6.1",
|
|
66
|
-
"vitest": "^4.0.
|
|
66
|
+
"vitest": "^4.0.18"
|
|
67
67
|
}
|
|
68
68
|
}
|