@pawover/kit 0.0.0-beta.2 → 0.0.0-beta.20
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/enums-Bv0coVvD.js +97 -0
- package/dist/enums-Bv0coVvD.js.map +1 -0
- package/dist/enums.d.ts +2 -25
- package/dist/enums.js +2 -24
- package/dist/except-C38JazcR.d.ts +971 -0
- package/dist/except-C38JazcR.d.ts.map +1 -0
- package/dist/hooks-alova.js.map +1 -1
- package/dist/hooks-react.d.ts +7 -30
- package/dist/hooks-react.d.ts.map +1 -1
- package/dist/hooks-react.js +7 -189
- package/dist/hooks-react.js.map +1 -1
- package/dist/index-BKUSlLXA.d.ts +159 -0
- package/dist/index-BKUSlLXA.d.ts.map +1 -0
- package/dist/index-CjoMz104.d.ts +21 -0
- package/dist/index-CjoMz104.d.ts.map +1 -0
- package/dist/index.d.ts +2070 -1066
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1429
- package/dist/patches-fetchEventSource.d.ts +2 -721
- package/dist/patches-fetchEventSource.d.ts.map +1 -1
- package/dist/patches-fetchEventSource.js +1 -114
- package/dist/patches-fetchEventSource.js.map +1 -1
- package/dist/utils-khUJYSj2.js +1989 -0
- package/dist/utils-khUJYSj2.js.map +1 -0
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js.map +1 -1
- package/dist/zod.d.ts +5 -1
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +6 -1
- package/dist/zod.js.map +1 -1
- package/metadata.json +15 -3
- package/package.json +20 -17
- package/dist/enums.d.ts.map +0 -1
- package/dist/enums.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"except-C38JazcR.d.ts","names":["UnionToIntersection","Union","Intersection","UnionToIntersection","KeysOfUnion","ObjectType","Record","IsAny","T","NoInfer","IsAny","IsOptionalKeyOf","Type","Key","Record","IsOptionalKeyOf","OptionalKeysOf","Type","Key","OptionalKeysOf","RequiredKeysOf","Type","Exclude","IsNever","T","IsNever","If","Type","IfBranch","ElseBranch","UnknownArray","If","IsAny","IsNever","Primitive","UnknownArray","BuiltIns","Date","RegExp","NonRecursiveType","Function","Promise","MapsSetsOrArrays","ReadonlyMap","WeakKey","WeakMap","ReadonlySet","WeakSet","IsBothExtends","BaseType","FirstType","SecondType","HasMultipleCallSignatures","T","IsNotFalse","IsPrimitive","Not","A","IfNotAnyOrNever","IfAny","IfNever","IsAnyOrNever","IsExactOptionalPropertyTypesEnabled","Simplify","T","KeyType","IsNever","IsEqual","A","B","_IsEqual","G","OmitIndexSignature","ObjectType","KeyType","Record","PickIndexSignature","ObjectType","KeyType","Record","OmitIndexSignature","PickIndexSignature","Simplify","If","IsEqual","SimpleMerge","Destination","Source","Key","Merge","_Merge","Simplify","IsEqual","KeysOfUnion","RequiredKeysOf","Merge","OptionalKeysOf","IsAny","If","IsNever","FilterDefinedKeys","FilterOptionalKeys","MapsSetsOrArrays","NonRecursiveType","StringToNumber","ToString","BuildObject","Key","Value","CopiedFrom","PropertyKey","Pick","NumberKey","IsPlainObject","T","ObjectValue","K","NumberK","UndefinedToOptional","Exclude","HomomorphicPick","Keys","P","Extract","ValueOfUnion","Union","ReadonlyKeysOfUnion","ApplyDefaultOptions","Options","Defaults","SpecifiedOptions","Required","Omit","Record","Partial","CollapseLiterals","NormalizedKeys","ApplyDefaultOptions","IsEqual","Filter","KeyType","ExcludeType","ExceptOptions","DefaultExceptOptions","Except","ObjectType","KeysType","Options","_Except","Required","Record","Partial"],"sources":["../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/union-to-intersection.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/keys-of-union.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/is-any.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/is-optional-key-of.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/optional-keys-of.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/required-keys-of.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/is-never.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/if.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/unknown-array.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/internal/type.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/simplify.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/is-equal.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/omit-index-signature.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/pick-index-signature.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/merge.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/internal/object.d.ts","../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/except.d.ts"],"sourcesContent":["/**\nConvert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).\n\nInspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).\n\n@example\n```\nimport type {UnionToIntersection} from 'type-fest';\n\ntype Union = {the(): void} | {great(arg: string): void} | {escape: boolean};\n\ntype Intersection = UnionToIntersection<Union>;\n//=> {the(): void} & {great(arg: string): void} & {escape: boolean}\n```\n\n@category Type\n*/\nexport type UnionToIntersection<Union> = (\n\t// `extends unknown` is always going to be the case and is used to convert the\n\t// `Union` into a [distributive conditional\n\t// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).\n\tUnion extends unknown\n\t\t// The union type is used as the only argument to a function since the union\n\t\t// of function arguments is an intersection.\n\t\t? (distributedUnion: Union) => void\n\t\t// This won't happen.\n\t\t: never\n\t\t// Infer the `Intersection` type since TypeScript represents the positional\n\t\t// arguments of unions of functions as an intersection of the union.\n) extends ((mergedIntersection: infer Intersection) => void)\n\t// The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`\n\t? Intersection & Union\n\t: never;\n\nexport {};\n","import type {UnionToIntersection} from './union-to-intersection.d.ts';\n\n/**\nCreate a union of all keys from a given type, even those exclusive to specific union members.\n\nUnlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.\n\n@link https://stackoverflow.com/a/49402091\n\n@example\n```\nimport type {KeysOfUnion} from 'type-fest';\n\ntype A = {\n\tcommon: string;\n\ta: number;\n};\n\ntype B = {\n\tcommon: string;\n\tb: string;\n};\n\ntype C = {\n\tcommon: string;\n\tc: boolean;\n};\n\ntype Union = A | B | C;\n\ntype CommonKeys = keyof Union;\n//=> 'common'\n\ntype AllKeys = KeysOfUnion<Union>;\n//=> 'common' | 'a' | 'b' | 'c'\n```\n\n@category Object\n*/\nexport type KeysOfUnion<ObjectType> =\n // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008\n keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;\n\nexport {};\n","/**\nReturns a boolean for whether the given type is `any`.\n\n@link https://stackoverflow.com/a/49928360/1490091\n\nUseful in type utilities, such as disallowing `any`s to be passed to a function.\n\n@example\n```\nimport type {IsAny} from 'type-fest';\n\nconst typedObject = {a: 1, b: 2} as const;\nconst anyObject: any = {a: 1, b: 2};\n\nfunction get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {\n\treturn object[key];\n}\n\nconst typedA = get(typedObject, 'a');\n//=> 1\n\nconst anyA = get(anyObject, 'a');\n//=> any\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;\n\nexport {};\n","import type {IsAny} from './is-any.d.ts';\n\n/**\nReturns a boolean for whether the given key is an optional key of type.\n\nThis is useful when writing utility types or schema validators that need to differentiate `optional` keys.\n\n@example\n```\nimport type {IsOptionalKeyOf} from 'type-fest';\n\ntype User = {\n\tname: string;\n\tsurname: string;\n\n\tluckyNumber?: number;\n};\n\ntype Admin = {\n\tname: string;\n\tsurname?: string;\n};\n\ntype T1 = IsOptionalKeyOf<User, 'luckyNumber'>;\n//=> true\n\ntype T2 = IsOptionalKeyOf<User, 'name'>;\n//=> false\n\ntype T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;\n//=> boolean\n\ntype T4 = IsOptionalKeyOf<User | Admin, 'name'>;\n//=> false\n\ntype T5 = IsOptionalKeyOf<User | Admin, 'surname'>;\n//=> boolean\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =\n\tIsAny<Type | Key> extends true ? never\n\t\t: Key extends keyof Type\n\t\t\t? Type extends Record<Key, Type[Key]>\n\t\t\t\t? false\n\t\t\t\t: true\n\t\t\t: false;\n\nexport {};\n","import type {IsOptionalKeyOf} from './is-optional-key-of.d.ts';\n\n/**\nExtract all optional keys from the given type.\n\nThis is useful when you want to create a new type that contains different type values for the optional keys only.\n\n@example\n```\nimport type {OptionalKeysOf, Except} from 'type-fest';\n\ntype User = {\n\tname: string;\n\tsurname: string;\n\n\tluckyNumber?: number;\n};\n\nconst REMOVE_FIELD = Symbol('remove field symbol');\ntype UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {\n\t[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;\n};\n\nconst update1: UpdateOperation<User> = {\n\tname: 'Alice',\n};\n\nconst update2: UpdateOperation<User> = {\n\tname: 'Bob',\n\tluckyNumber: REMOVE_FIELD,\n};\n```\n\n@category Utilities\n*/\nexport type OptionalKeysOf<Type extends object> =\n\tType extends unknown // For distributing `Type`\n\t\t? (keyof {[Key in keyof Type as\n\t\t\tIsOptionalKeyOf<Type, Key> extends false\n\t\t\t\t? never\n\t\t\t\t: Key\n\t\t\t]: never\n\t\t}) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`\n\t\t: never; // Should never happen\n\nexport {};\n","import type {OptionalKeysOf} from './optional-keys-of.d.ts';\n\n/**\nExtract all required keys from the given type.\n\nThis is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...\n\n@example\n```\nimport type {RequiredKeysOf} from 'type-fest';\n\ndeclare function createValidation<\n\tEntity extends object,\n\tKey extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,\n>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;\n\ntype User = {\n\tname: string;\n\tsurname: string;\n\tluckyNumber?: number;\n};\n\nconst validator1 = createValidation<User>('name', value => value.length < 25);\nconst validator2 = createValidation<User>('surname', value => value.length < 25);\n\n// @ts-expect-error\nconst validator3 = createValidation<User>('luckyNumber', value => value > 0);\n// Error: Argument of type '\"luckyNumber\"' is not assignable to parameter of type '\"name\" | \"surname\"'.\n```\n\n@category Utilities\n*/\nexport type RequiredKeysOf<Type extends object> =\n\tType extends unknown // For distributing `Type`\n\t\t? Exclude<keyof Type, OptionalKeysOf<Type>>\n\t\t: never; // Should never happen\n\nexport {};\n","/**\nReturns a boolean for whether the given type is `never`.\n\n@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919\n@link https://stackoverflow.com/a/53984913/10292952\n@link https://www.zhenghao.io/posts/ts-never\n\nUseful in type utilities, such as checking if something does not occur.\n\n@example\n```\nimport type {IsNever, And} from 'type-fest';\n\ntype A = IsNever<never>;\n//=> true\n\ntype B = IsNever<any>;\n//=> false\n\ntype C = IsNever<unknown>;\n//=> false\n\ntype D = IsNever<never[]>;\n//=> false\n\ntype E = IsNever<object>;\n//=> false\n\ntype F = IsNever<string>;\n//=> false\n```\n\n@example\n```\nimport type {IsNever} from 'type-fest';\n\ntype IsTrue<T> = T extends true ? true : false;\n\n// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.\ntype A = IsTrue<never>;\n//=> never\n\n// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.\ntype IsTrueFixed<T> =\n\tIsNever<T> extends true ? false : T extends true ? true : false;\n\ntype B = IsTrueFixed<never>;\n//=> false\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsNever<T> = [T] extends [never] ? true : false;\n\nexport {};\n","import type {IsNever} from './is-never.d.ts';\n\n/**\nAn if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.\n\nUse-cases:\n- You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.\n\nNote:\n- Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.\n- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.\n\n@example\n```\nimport type {If} from 'type-fest';\n\ntype A = If<true, 'yes', 'no'>;\n//=> 'yes'\n\ntype B = If<false, 'yes', 'no'>;\n//=> 'no'\n\ntype C = If<boolean, 'yes', 'no'>;\n//=> 'yes' | 'no'\n\ntype D = If<any, 'yes', 'no'>;\n//=> 'yes' | 'no'\n\ntype E = If<never, 'yes', 'no'>;\n//=> 'no'\n```\n\n@example\n```\nimport type {If, IsAny, IsNever} from 'type-fest';\n\ntype A = If<IsAny<unknown>, 'is any', 'not any'>;\n//=> 'not any'\n\ntype B = If<IsNever<never>, 'is never', 'not never'>;\n//=> 'is never'\n```\n\n@example\n```\nimport type {If, IsEqual} from 'type-fest';\n\ntype IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;\n\ntype A = IfEqual<string, string, 'equal', 'not equal'>;\n//=> 'equal'\n\ntype B = IfEqual<string, number, 'equal', 'not equal'>;\n//=> 'not equal'\n```\n\nNote: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:\n\n@example\n```\nimport type {If, IsEqual, StringRepeat} from 'type-fest';\n\ntype HundredZeroes = StringRepeat<'0', 100>;\n\n// The following implementation is not tail recursive\ntype Includes<S extends string, Char extends string> =\n\tS extends `${infer First}${infer Rest}`\n\t\t? If<IsEqual<First, Char>,\n\t\t\t'found',\n\t\t\tIncludes<Rest, Char>>\n\t\t: 'not found';\n\n// Hence, instantiations with long strings will fail\n// @ts-expect-error\ntype Fails = Includes<HundredZeroes, '1'>;\n// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n// Error: Type instantiation is excessively deep and possibly infinite.\n\n// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive\ntype IncludesWithoutIf<S extends string, Char extends string> =\n\tS extends `${infer First}${infer Rest}`\n\t\t? IsEqual<First, Char> extends true\n\t\t\t? 'found'\n\t\t\t: IncludesWithoutIf<Rest, Char>\n\t\t: 'not found';\n\n// Now, instantiations with long strings will work\ntype Works = IncludesWithoutIf<HundredZeroes, '1'>;\n//=> 'not found'\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type If<Type extends boolean, IfBranch, ElseBranch> =\n\tIsNever<Type> extends true\n\t\t? ElseBranch\n\t\t: Type extends true\n\t\t\t? IfBranch\n\t\t\t: ElseBranch;\n\nexport {};\n","/**\nRepresents an array with `unknown` value.\n\nUse case: You want a type that all arrays can be assigned to, but you don't care about the value.\n\n@example\n```\nimport type {UnknownArray} from 'type-fest';\n\ntype IsArray<T> = T extends UnknownArray ? true : false;\n\ntype A = IsArray<['foo']>;\n//=> true\n\ntype B = IsArray<readonly number[]>;\n//=> true\n\ntype C = IsArray<string>;\n//=> false\n```\n\n@category Type\n@category Array\n*/\nexport type UnknownArray = readonly unknown[];\n\nexport {};\n","import type {If} from '../if.d.ts';\nimport type {IsAny} from '../is-any.d.ts';\nimport type {IsNever} from '../is-never.d.ts';\nimport type {Primitive} from '../primitive.d.ts';\nimport type {UnknownArray} from '../unknown-array.d.ts';\n\n/**\nMatches any primitive, `void`, `Date`, or `RegExp` value.\n*/\nexport type BuiltIns = Primitive | void | Date | RegExp;\n\n/**\nMatches non-recursive types.\n*/\nexport type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown) | Promise<unknown>;\n\n/**\nMatches maps, sets, or arrays.\n*/\nexport type MapsSetsOrArrays = ReadonlyMap<unknown, unknown> | WeakMap<WeakKey, unknown> | ReadonlySet<unknown> | WeakSet<WeakKey> | UnknownArray;\n\n/**\nReturns a boolean for whether the two given types extends the base type.\n*/\nexport type IsBothExtends<BaseType, FirstType, SecondType> = FirstType extends BaseType\n\t? SecondType extends BaseType\n\t\t? true\n\t\t: false\n\t: false;\n\n/**\nTest if the given function has multiple call signatures.\n\nNeeded to handle the case of a single call signature with properties.\n\nMultiple call signatures cannot currently be supported due to a TypeScript limitation.\n@see https://github.com/microsoft/TypeScript/issues/29732\n*/\nexport type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =\n\tT extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}\n\t\t? B extends A\n\t\t\t? A extends B\n\t\t\t\t? false\n\t\t\t\t: true\n\t\t\t: true\n\t\t: false;\n\n/**\nReturns a boolean for whether the given `boolean` is not `false`.\n*/\nexport type IsNotFalse<T extends boolean> = [T] extends [false] ? false : true;\n\n/**\nReturns a boolean for whether the given type is primitive value or primitive type.\n\n@example\n```\ntype A = IsPrimitive<'string'>;\n//=> true\n\ntype B = IsPrimitive<string>;\n//=> true\n\ntype C = IsPrimitive<Object>;\n//=> false\n```\n*/\nexport type IsPrimitive<T> = [T] extends [Primitive] ? true : false;\n\n/**\nReturns a boolean for whether A is false.\n\n@example\n```\ntype A = Not<true>;\n//=> false\n\ntype B = Not<false>;\n//=> true\n```\n*/\nexport type Not<A extends boolean> = A extends true\n\t? false\n\t: A extends false\n\t\t? true\n\t\t: never;\n\n/**\nAn if-else-like type that resolves depending on whether the given type is `any` or `never`.\n\n@example\n```\n// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch\ntype A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;\n//=> 'VALID'\n\n// When `T` is `any` => Returns `IfAny` branch\ntype B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;\n//=> 'IS_ANY'\n\n// When `T` is `never` => Returns `IfNever` branch\ntype C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;\n//=> 'IS_NEVER'\n```\n\nNote: Wrapping a tail-recursive type with `IfNotAnyOrNever` makes the implementation non-tail-recursive. To fix this, move the recursion into a helper type. Refer to the following example:\n\n@example\n```ts\nimport type {StringRepeat} from 'type-fest';\n\ntype NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;\n\n// The following implementation is not tail recursive\ntype TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;\n\n// Hence, instantiations with long strings will fail\n// @ts-expect-error\ntype T1 = TrimLeft<NineHundredNinetyNineSpaces>;\n// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n// Error: Type instantiation is excessively deep and possibly infinite.\n\n// To fix this, move the recursion into a helper type\ntype TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S>>;\n\ntype _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;\n\ntype T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;\n//=> ''\n```\n*/\nexport type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> =\n\tIf<IsAny<T>, IfAny, If<IsNever<T>, IfNever, IfNotAnyOrNever>>;\n\n/**\nReturns a boolean for whether the given type is `any` or `never`.\n\nThis type can be better to use than {@link IfNotAnyOrNever `IfNotAnyOrNever`} in recursive types because it does not evaluate any branches.\n\n@example\n```\n// When `T` is a NOT `any` or `never` (like `string`) => Returns `false`\ntype A = IsAnyOrNever<string>;\n//=> false\n\n// When `T` is `any` => Returns `true`\ntype B = IsAnyOrNever<any>;\n//=> true\n\n// When `T` is `never` => Returns `true`\ntype C = IsAnyOrNever<never>;\n//=> true\n```\n*/\nexport type IsAnyOrNever<T> = IsNotFalse<IsAny<T> | IsNever<T>>;\n\n/**\nIndicates the value of `exactOptionalPropertyTypes` compiler option.\n*/\nexport type IsExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?]\n\t? false\n\t: true;\n\nexport {};\n","/**\nUseful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.\n\n@example\n```\nimport type {Simplify} from 'type-fest';\n\ntype PositionProps = {\n\ttop: number;\n\tleft: number;\n};\n\ntype SizeProps = {\n\twidth: number;\n\theight: number;\n};\n\n// In your editor, hovering over `Props` will show a flattened object with all the properties.\ntype Props = Simplify<PositionProps & SizeProps>;\n```\n\nSometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.\n\nIf the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.\n\n@example\n```\nimport type {Simplify} from 'type-fest';\n\ninterface SomeInterface {\n\tfoo: number;\n\tbar?: string;\n\tbaz: number | undefined;\n}\n\ntype SomeType = {\n\tfoo: number;\n\tbar?: string;\n\tbaz: number | undefined;\n};\n\nconst literal = {foo: 123, bar: 'hello', baz: 456};\nconst someType: SomeType = literal;\nconst someInterface: SomeInterface = literal;\n\ndeclare function fn(object: Record<string, unknown>): void;\n\nfn(literal); // Good: literal object type is sealed\nfn(someType); // Good: type is sealed\n// @ts-expect-error\nfn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened\nfn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`\n```\n\n@link https://github.com/microsoft/TypeScript/issues/15300\n@see {@link SimplifyDeep}\n@category Object\n*/\nexport type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};\n\nexport {};\n","import type {IsNever} from './is-never.d.ts';\n/**\nReturns a boolean for whether the two given types are equal.\n\n@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650\n@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796\n\nUse-cases:\n- If you want to make a conditional branch based on the result of a comparison of two types.\n\n@example\n```\nimport type {IsEqual} from 'type-fest';\n\n// This type returns a boolean for whether the given array includes the given item.\n// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.\ntype Includes<Value extends readonly any[], Item> =\n\tValue extends readonly [Value[0], ...infer rest]\n\t\t? IsEqual<Value[0], Item> extends true\n\t\t\t? true\n\t\t\t: Includes<rest, Item>\n\t\t: false;\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsEqual<A, B> =\n\t[A] extends [B]\n\t\t? [B] extends [A]\n\t\t\t? _IsEqual<A, B>\n\t\t\t: false\n\t\t: false;\n\n// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.\ntype _IsEqual<A, B> =\n\t(<G>() => G extends A & G | G ? 1 : 2) extends\n\t(<G>() => G extends B & G | G ? 1 : 2)\n\t\t? true\n\t\t: false;\n\nexport {};\n","/**\nOmit any index signatures from the given object type, leaving only explicitly defined properties.\n\nThis is the counterpart of `PickIndexSignature`.\n\nUse-cases:\n- Remove overly permissive signatures from third-party types.\n\nThis type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).\n\nIt relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.\n\n(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)\n\n```\nconst indexed: Record<string, unknown> = {}; // Allowed\n\n// @ts-expect-error\nconst keyed: Record<'foo', unknown> = {}; // Error\n// TS2739: Type '{}' is missing the following properties from type 'Record<\"foo\" | \"bar\", unknown>': foo, bar\n```\n\nInstead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:\n\n```\ntype Indexed = {} extends Record<string, unknown>\n\t? '✅ `{}` is assignable to `Record<string, unknown>`'\n\t: '❌ `{}` is NOT assignable to `Record<string, unknown>`';\n\ntype IndexedResult = Indexed;\n//=> '✅ `{}` is assignable to `Record<string, unknown>`'\n\ntype Keyed = {} extends Record<'foo' | 'bar', unknown>\n\t? '✅ `{}` is assignable to `Record<\\'foo\\' | \\'bar\\', unknown>`'\n\t: '❌ `{}` is NOT assignable to `Record<\\'foo\\' | \\'bar\\', unknown>`';\n\ntype KeyedResult = Keyed;\n//=> '❌ `{}` is NOT assignable to `Record<\\'foo\\' | \\'bar\\', unknown>`'\n```\n\nUsing a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...\n\n```\ntype OmitIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType // Map each key of `ObjectType`...\n\t]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.\n};\n```\n\n...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...\n\n```\ntype OmitIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType\n\t// Is `{}` assignable to `Record<KeyType, unknown>`?\n\tas {} extends Record<KeyType, unknown>\n\t\t? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`\n\t\t: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`\n\t]: ObjectType[KeyType];\n};\n```\n\nIf `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a \"real\" key and we want to keep it.\n\n@example\n```\nimport type {OmitIndexSignature} from 'type-fest';\n\ntype Example = {\n\t// These index signatures will be removed.\n\t[x: string]: any;\n\t[x: number]: any;\n\t[x: symbol]: any;\n\t[x: `head-${string}`]: string;\n\t[x: `${string}-tail`]: string;\n\t[x: `head-${string}-tail`]: string;\n\t[x: `${bigint}`]: string;\n\t[x: `embedded-${number}`]: string;\n\n\t// These explicitly defined keys will remain.\n\tfoo: 'bar';\n\tqux?: 'baz';\n};\n\ntype ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;\n//=> {foo: 'bar'; qux?: 'baz'}\n```\n\n@see {@link PickIndexSignature}\n@category Object\n*/\nexport type OmitIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>\n\t\t? never\n\t\t: KeyType]: ObjectType[KeyType];\n};\n\nexport {};\n","/**\nPick only index signatures from the given object type, leaving out all explicitly defined properties.\n\nThis is the counterpart of `OmitIndexSignature`.\n\n@example\n```\nimport type {PickIndexSignature} from 'type-fest';\n\ndeclare const symbolKey: unique symbol;\n\ntype Example = {\n\t// These index signatures will remain.\n\t[x: string]: unknown;\n\t[x: number]: unknown;\n\t[x: symbol]: unknown;\n\t[x: `head-${string}`]: string;\n\t[x: `${string}-tail`]: string;\n\t[x: `head-${string}-tail`]: string;\n\t[x: `${bigint}`]: string;\n\t[x: `embedded-${number}`]: string;\n\n\t// These explicitly defined keys will be removed.\n\t['kebab-case-key']: string;\n\t[symbolKey]: string;\n\tfoo: 'bar';\n\tqux?: 'baz';\n};\n\ntype ExampleIndexSignature = PickIndexSignature<Example>;\n// {\n// \t[x: string]: unknown;\n// \t[x: number]: unknown;\n// \t[x: symbol]: unknown;\n// \t[x: `head-${string}`]: string;\n// \t[x: `${string}-tail`]: string;\n// \t[x: `head-${string}-tail`]: string;\n// \t[x: `${bigint}`]: string;\n// \t[x: `embedded-${number}`]: string;\n// }\n```\n\n@see {@link OmitIndexSignature}\n@category Object\n*/\nexport type PickIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>\n\t\t? KeyType\n\t\t: never]: ObjectType[KeyType];\n};\n\nexport {};\n","import type {OmitIndexSignature} from './omit-index-signature.d.ts';\nimport type {PickIndexSignature} from './pick-index-signature.d.ts';\nimport type {Simplify} from './simplify.d.ts';\nimport type {If} from './if.d.ts';\nimport type {IsEqual} from './is-equal.d.ts';\n\n// Merges two objects without worrying about index signatures.\ntype SimpleMerge<Destination, Source> = Simplify<{\n\t[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];\n} & Source>;\n\n/**\nMerge two types into a new type. Keys of the second type overrides keys of the first type.\n\n@example\n```\nimport type {Merge} from 'type-fest';\n\ntype Foo = {\n\t[x: string]: unknown;\n\t[x: number]: unknown;\n\tfoo: string;\n\tbar: symbol;\n};\n\ntype Bar = {\n\t[x: number]: number;\n\t[x: symbol]: unknown;\n\tbar: Date;\n\tbaz: boolean;\n};\n\nexport type FooBar = Merge<Foo, Bar>;\n//=> {\n// \t[x: string]: unknown;\n// \t[x: number]: number;\n// \t[x: symbol]: unknown;\n// \tfoo: string;\n// \tbar: Date;\n// \tbaz: boolean;\n// }\n```\n\nNote: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.\n\n@see {@link ObjectMerge}\n@category Object\n*/\nexport type Merge<Destination, Source> =\n\tDestination extends unknown // For distributing `Destination`\n\t\t? Source extends unknown // For distributing `Source`\n\t\t\t? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>>\n\t\t\t: never // Should never happen\n\t\t: never; // Should never happen\n\nexport type _Merge<Destination, Source> =\n\tSimplify<\n\t\tSimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>\n\t\t& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>\n\t>;\n\nexport {};\n","import type {Simplify} from '../simplify.d.ts';\nimport type {IsEqual} from '../is-equal.d.ts';\nimport type {KeysOfUnion} from '../keys-of-union.d.ts';\nimport type {RequiredKeysOf} from '../required-keys-of.d.ts';\nimport type {Merge} from '../merge.d.ts';\nimport type {OptionalKeysOf} from '../optional-keys-of.d.ts';\nimport type {IsAny} from '../is-any.d.ts';\nimport type {If} from '../if.d.ts';\nimport type {IsNever} from '../is-never.d.ts';\nimport type {FilterDefinedKeys, FilterOptionalKeys} from './keys.d.ts';\nimport type {MapsSetsOrArrays, NonRecursiveType} from './type.d.ts';\nimport type {StringToNumber, ToString} from './string.d.ts';\n\n/**\nCreate an object type with the given key `<Key>` and value `<Value>`.\n\nIt will copy the prefix and optional status of the same key from the given object `CopiedFrom` into the result.\n\n@example\n```\ntype A = BuildObject<'a', string>;\n//=> {a: string}\n\n// Copy `readonly` and `?` from the key `a` of `{readonly a?: any}`\ntype B = BuildObject<'a', string, {readonly a?: any}>;\n//=> {readonly a?: string}\n```\n*/\nexport type BuildObject<Key extends PropertyKey, Value, CopiedFrom extends object = {}> =\n\tKey extends keyof CopiedFrom\n\t\t? Pick<{[_ in keyof CopiedFrom]: Value}, Key>\n\t\t: Key extends `${infer NumberKey extends number}`\n\t\t\t? NumberKey extends keyof CopiedFrom\n\t\t\t\t? Pick<{[_ in keyof CopiedFrom]: Value}, NumberKey>\n\t\t\t\t: {[_ in Key]: Value}\n\t\t\t: {[_ in Key]: Value};\n\n/**\nReturns a boolean for whether the given type is a plain key-value object.\n*/\nexport type IsPlainObject<T> =\n\tIsNever<T> extends true\n\t\t? false\n\t\t: T extends NonRecursiveType | MapsSetsOrArrays\n\t\t\t? false\n\t\t\t: T extends object\n\t\t\t\t? true\n\t\t\t\t: false;\n\n/**\nExtract the object field type if T is an object and K is a key of T, return `never` otherwise.\n\nIt creates a type-safe way to access the member type of `unknown` type.\n*/\nexport type ObjectValue<T, K> =\n\tK extends keyof T\n\t\t? T[K]\n\t\t: ToString<K> extends keyof T\n\t\t\t? T[ToString<K>]\n\t\t\t: K extends `${infer NumberK extends number}`\n\t\t\t\t? NumberK extends keyof T\n\t\t\t\t\t? T[NumberK]\n\t\t\t\t\t: never\n\t\t\t\t: never;\n\n/**\nFor an object T, if it has any properties that are a union with `undefined`, make those into optional properties instead.\n\n@example\n```\ntype User = {\n\tfirstName: string;\n\tlastName: string | undefined;\n};\n\ntype OptionalizedUser = UndefinedToOptional<User>;\n//=> {\n// \tfirstName: string;\n// \tlastName?: string;\n// }\n```\n*/\nexport type UndefinedToOptional<T extends object> = Simplify<\n\t{\n\t// Property is not a union with `undefined`, keep it as-is.\n\t\t[Key in keyof Pick<T, FilterDefinedKeys<T>>]: T[Key];\n\t} & {\n\t// Property _is_ a union with defined value. Set as optional (via `?`) and remove `undefined` from the union.\n\t\t[Key in keyof Pick<T, FilterOptionalKeys<T>>]?: Exclude<T[Key], undefined>;\n\t}\n>;\n\n/**\nWorks similar to the built-in `Pick` utility type, except for the following differences:\n- Distributes over union types and allows picking keys from any member of the union type.\n- Primitives types are returned as-is.\n- Picks all keys if `Keys` is `any`.\n- Doesn't pick `number` from a `string` index signature.\n\n@example\n```\ntype ImageUpload = {\n\turl: string;\n\tsize: number;\n\tthumbnailUrl: string;\n};\n\ntype VideoUpload = {\n\turl: string;\n\tduration: number;\n\tencodingFormat: string;\n};\n\n// Distributes over union types and allows picking keys from any member of the union type\ntype MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, \"url\" | \"size\" | \"duration\">;\n//=> {url: string; size: number} | {url: string; duration: number}\n\n// Primitive types are returned as-is\ntype Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;\n//=> string | number\n\n// Picks all keys if `Keys` is `any`\ntype Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;\n//=> {a: 1; b: 2} | {c: 3}\n\n// Doesn't pick `number` from a `string` index signature\ntype IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;\n//=> {}\n*/\nexport type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = {\n\t[P in keyof T as Extract<P, Keys>]: T[P]\n};\n\n/**\nExtract all possible values for a given key from a union of object types.\n\n@example\n```\ntype Statuses = ValueOfUnion<{id: 1; status: 'open'} | {id: 2; status: 'closed'}, 'status'>;\n//=> \"open\" | \"closed\"\n```\n*/\nexport type ValueOfUnion<Union, Key extends KeysOfUnion<Union>> =\n\tUnion extends unknown ? Key extends keyof Union ? Union[Key] : never : never;\n\n/**\nExtract all readonly keys from a union of object types.\n\n@example\n```\ntype User = {\n\treadonly id: string;\n\tname: string;\n};\n\ntype Post = {\n\treadonly id: string;\n\treadonly author: string;\n\tbody: string;\n};\n\ntype ReadonlyKeys = ReadonlyKeysOfUnion<User | Post>;\n//=> \"id\" | \"author\"\n```\n*/\nexport type ReadonlyKeysOfUnion<Union> = Union extends unknown ? keyof {\n\t[Key in keyof Union as IsEqual<{[K in Key]: Union[Key]}, {readonly [K in Key]: Union[Key]}> extends true ? Key : never]: never\n} : never;\n\n/**\nMerges user specified options with default options.\n\n@example\n```\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};\ntype SpecifiedOptions = {leavesOnly: true};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n//=> {maxRecursionDepth: 10; leavesOnly: true}\n```\n\n@example\n```\n// Complains if default values are not provided for optional options\n\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10};\ntype SpecifiedOptions = {};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n// ~~~~~~~~~~~~~~~~~~~\n// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.\n```\n\n@example\n```\n// Complains if an option's default type does not conform to the expected type\n\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};\ntype SpecifiedOptions = {};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n// ~~~~~~~~~~~~~~~~~~~\n// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.\n```\n\n@example\n```\n// Complains if an option's specified type does not conform to the expected type\n\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};\ntype SpecifiedOptions = {leavesOnly: 'yes'};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n// ~~~~~~~~~~~~~~~~\n// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.\n```\n*/\nexport type ApplyDefaultOptions<\n\tOptions extends object,\n\tDefaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,\n\tSpecifiedOptions extends Options,\n> =\n\tIf<IsAny<SpecifiedOptions>, Defaults,\n\t\tIf<IsNever<SpecifiedOptions>, Defaults,\n\t\t\tSimplify<Merge<Defaults, {\n\t\t\t\t[Key in keyof SpecifiedOptions\n\t\t\t\tas Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key\n\t\t\t\t]: SpecifiedOptions[Key]\n\t\t\t}> & Required<Options>>>>; // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`\n\n/**\nCollapses literal types in a union into their corresponding primitive types, when possible. For example, `CollapseLiterals<'foo' | 'bar' | (string & {})>` returns `string`.\n\nNote: This doesn't collapse literals within tagged types. For example, `CollapseLiterals<Tagged<'foo' | (string & {}), 'Tag'>>` returns `(\"foo\" & Tag<\"Tag\", never>) | (string & Tag<\"Tag\", never>)` and not `string & Tag<\"Tag\", never>`.\n\nUse-case: For collapsing unions created using {@link LiteralUnion}.\n\n@example\n```\nimport type {LiteralUnion} from 'type-fest';\n\ntype A = CollapseLiterals<'foo' | 'bar' | (string & {})>;\n//=> string\n\ntype B = CollapseLiterals<LiteralUnion<1 | 2 | 3, number>>;\n//=> number\n\ntype C = CollapseLiterals<LiteralUnion<'onClick' | 'onChange', `on${string}`>>;\n//=> `on${string}`\n\ntype D = CollapseLiterals<'click' | 'change' | (`on${string}` & {})>;\n//=> 'click' | 'change' | `on${string}`\n\ntype E = CollapseLiterals<LiteralUnion<'foo' | 'bar', string> | null | undefined>;\n//=> string | null | undefined\n```\n*/\nexport type CollapseLiterals<T> = {} extends T\n\t? T\n\t: T extends infer U & {}\n\t\t? U\n\t\t: T;\n\n/**\nNormalize keys by including string and number representations wherever applicable.\n\n@example\n```ts\ntype A = NormalizedKeys<0 | '1'>;\n//=> 0 | '0' | 1 | '1'\n\ntype B = NormalizedKeys<string>;\n//=> string | number\n\ntype C = NormalizedKeys<number>;\n//=> number | `${number}`\n\ntype D = NormalizedKeys<symbol | 'foo'>;\n//=> symbol | 'foo'\n```\n*/\nexport type NormalizedKeys<Keys extends PropertyKey> =\n\t| Keys\n\t| (string extends Keys ? number : never)\n\t| StringToNumber<Keys & string>\n\t| ToString<Keys & number>;\n\nexport {};\n","import type {ApplyDefaultOptions} from './internal/index.d.ts';\nimport type {IsEqual} from './is-equal.d.ts';\n\n/**\nFilter out keys from an object.\n\nReturns `never` if `Exclude` is strictly equal to `Key`.\nReturns `never` if `Key` extends `Exclude`.\nReturns `Key` otherwise.\n\n@example\n```\ntype Filtered = Filter<'foo', 'foo'>;\n//=> never\n```\n\n@example\n```\ntype Filtered = Filter<'bar', string>;\n//=> never\n```\n\n@example\n```\ntype Filtered = Filter<'bar', 'foo'>;\n//=> 'bar'\n```\n\n@see {Except}\n*/\ntype Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);\n\nexport type ExceptOptions = {\n\t/**\n\tDisallow assigning non-specified properties.\n\n\tNote that any omitted properties in the resulting type will be present in autocomplete as `undefined`.\n\n\t@default false\n\t*/\n\trequireExactProps?: boolean;\n};\n\ntype DefaultExceptOptions = {\n\trequireExactProps: false;\n};\n\n/**\nCreate a type from an object type without certain keys.\n\nWe recommend setting the `requireExactProps` option to `true`.\n\nThis type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.\n\nThis type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).\n\n@example\n```\nimport type {Except} from 'type-fest';\n\ntype Foo = {\n\ta: number;\n\tb: string;\n};\n\ntype FooWithoutA = Except<Foo, 'a'>;\n//=> {b: string}\n\n// @ts-expect-error\nconst fooWithoutA: FooWithoutA = {a: 1, b: '2'};\n// errors: 'a' does not exist in type '{ b: string; }'\n\ntype FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;\n//=> {a: number} & Partial<Record<'b', never>>\n\n// @ts-expect-error\nconst fooWithoutB: FooWithoutB = {a: 1, b: '2'};\n// errors at 'b': Type 'string' is not assignable to type 'undefined'.\n\n// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.\n\n// Consider the following example:\n\ntype UserData = {\n\t[metadata: string]: string;\n\temail: string;\n\tname: string;\n\trole: 'admin' | 'user';\n};\n\n// `Omit` clearly doesn't behave as expected in this case:\ntype PostPayload = Omit<UserData, 'email'>;\n//=> {[x: string]: string; [x: number]: string}\n\n// In situations like this, `Except` works better.\n// It simply removes the `email` key while preserving all the other keys.\ntype PostPayloadFixed = Except<UserData, 'email'>;\n//=> {[x: string]: string; name: string; role: 'admin' | 'user'}\n```\n\n@category Object\n*/\nexport type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =\n\t_Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;\n\ntype _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {\n\t[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];\n} & (Options['requireExactProps'] extends true\n\t? Partial<Record<KeysType, never>>\n\t: {});\n\nexport {};\n"],"x_google_ignoreList":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],"mappings":";;AAiBA;;;;;;;;;ACsBA;;;;;;;KDtBYA;;AEWZ;;AFPCC;;AGqBD;AAAA,EAAmEW,CAAAA,gBAAAA,EHlB5CX,KGkB4CW,EAAAA,GAAAA;AAC5DA;AAAAA,EAAOC;AAAbH;AACGG;AAAAA,CAAkBD,SAAAA,CAAAA,CAAAA,kBAAAA,EAAAA,KAAAA,aAAAA,EAAAA,GAAAA,IAAAA;AACjBA;AAAAA,EHdFV,YGcsBW,GHdPZ,KGcOY,GAAKD,KAAAA;;;;;;;;;;;AFN9B;;;;;;;;;ACXA;;;;ACcA;;;;;;;;;;;;;;;;ACPYI,KHIAZ,WGJc,CAAA,UAAAa,CAAAA;AACzBA;AACyBA,MHIlBd,mBGJkBc,CHIEZ,UGJFY,SAAAA,OAAAA,GHI+BX,MGJ/BW,CAAAA,MHI4CZ,UGJ5CY,EAAAA,KAAAA,CAAAA,GAAAA,KAAAA,CAAAA;;;;AJpB1B;;;;;;;;;ACsBA;;;;;;;;;ACXA;;;;ACcA;;;;;AAEIJ,KDhBQN,KCgBRM,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,SAAAA,CAAAA,GDhBiCJ,OCgBjCI,CDhByCL,CCgBzCK,CAAAA,GAAAA,IAAAA,GAAAA,KAAAA;;;;;;;;;;;AFLJ;;;;;;;;;ACXA;;;;ACcA;;;;;;;;;;;;;;;;ACPA;;;AAGmBI,KDIPN,eCJOM,CAAAA,aAAAA,MAAAA,EA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,UAAAA,EAAAA,iBAAAA,MK6E8C6E,UL7E9C7E,EAAAA,gBK6E0EiF,QL7E1EjF,CK6EmF0E,aL7EnF1E,CAAAA,CAAAA,GAAAA,cAAYC,MK8EK4E,UL9EL5E,IK8EmBsE,ML9EnBtE,CK8E0BuE,OL9E1BvE,EK8EmC6E,QL9EnC7E,CAAAA,GK8E+C4E,UL9E/C5E,CK8E0DuE,OL9E1DvE,CAAAA,EACTA,GAAAA,CK8EA8E,OL9EA9E,CAAAA,mBAAAA,CAAAA,SAAAA,IAAAA,GK+EFkF,OL/EcnF,CK+ENkF,ML/EMlF,CK+EC8E,QL/ED9E,EAAAA,KAAAA,CAAAA,CAAAA,GACHA,CAAAA,CAAAA,CAAAA"}
|
package/dist/hooks-alova.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks-alova.js","names":[],"sources":["../src/hooks/alova/useAlovaRequest.ts","../src/hooks/alova/useAlovaWatcher.ts"],"sourcesContent":["/* eslint-disable ts/no-explicit-any */\n\nimport type { AlovaGenerics, Method } from \"alova\";\nimport {\n type AlovaFrontMiddlewareContext,\n type AlovaMethodHandler,\n type CompleteHandler,\n type ErrorHandler,\n type RequestHookConfig,\n type SuccessHandler,\n useRequest,\n} from \"alova/client\";\n\ninterface HookConfig<AG extends AlovaGenerics, Args extends any[]> extends RequestHookConfig<AG, Args> {\n onBeforeRequest?: (context: AlovaFrontMiddlewareContext<AG, Args>) => void;\n onSuccess?: SuccessHandler<AG, Args>;\n onError?: ErrorHandler<AG, Args>;\n onComplete?: CompleteHandler<AG, Args>;\n}\n\nexport function useAlovaRequest<AG extends AlovaGenerics, Args extends any[] = any[]>(\n methodHandler: Method<AG> | AlovaMethodHandler<AG, Args>,\n hookConfig?: HookConfig<AG, Args> | undefined,\n) {\n const config = hookConfig || {};\n config.immediate ??= true;\n\n if (config.onBeforeRequest) {\n const middleware = config.middleware;\n config.middleware = async (context, next) => {\n config.onBeforeRequest?.(context);\n\n if (middleware) {\n async function run() {\n await next();\n }\n await middleware?.(context, run);\n } else {\n await next();\n }\n };\n }\n\n const exposure = useRequest(methodHandler, config);\n\n if (config.onSuccess) {\n exposure.onSuccess(config.onSuccess);\n }\n if (config.onError) {\n exposure.onError(config.onError);\n }\n if (config.onComplete) {\n exposure.onComplete(config.onComplete);\n }\n\n return exposure;\n}\n","/* eslint-disable ts/no-explicit-any */\n\nimport type { AlovaGenerics, Method } from \"alova\";\nimport {\n type AlovaMethodHandler,\n type CompleteHandler,\n type ErrorHandler,\n type SuccessHandler,\n type WatcherHookConfig,\n useWatcher,\n} from \"alova/client\";\n\ninterface HookConfig<AG extends AlovaGenerics, Args extends any[]> extends WatcherHookConfig<AG, Args> {\n onSuccess?: SuccessHandler<AG, Args>;\n onError?: ErrorHandler<AG, Args>;\n onComplete?: CompleteHandler<AG, Args>;\n}\n\nexport function useAlovaWatcher<AG extends AlovaGenerics, Args extends any[] = any[]>(\n methodHandler: Method<AG> | AlovaMethodHandler<AG, Args>,\n watchingStates: AG[\"StatesExport\"][\"Watched\"][],\n hookConfig: HookConfig<AG, Args> = {},\n) {\n const config = hookConfig || {};\n const exposure = useWatcher(methodHandler, watchingStates, config);\n\n if (config.onSuccess) {\n exposure.onSuccess(config.onSuccess);\n }\n if (config.onError) {\n exposure.onError(config.onError);\n }\n if (config.onComplete) {\n exposure.onComplete(config.onComplete);\n }\n\n return exposure;\n}\n"],"mappings":";;;AAoBA,SAAgB,gBACd,eACA,YACA;CACA,MAAM,SAAS,cAAc,EAAE;AAC/B,QAAO,cAAP,OAAO,YAAc;AAErB,KAAI,OAAO,iBAAiB;EAC1B,MAAM,aAAa,OAAO;AAC1B,SAAO,aAAa,OAAO,SAAS,SAAS;AAC3C,UAAO,kBAAkB,QAAQ;AAEjC,OAAI,YAAY;IACd,eAAe,
|
|
1
|
+
{"version":3,"file":"hooks-alova.js","names":[],"sources":["../src/hooks/alova/useAlovaRequest.ts","../src/hooks/alova/useAlovaWatcher.ts"],"sourcesContent":["/* eslint-disable ts/no-explicit-any */\n\nimport type { AlovaGenerics, Method } from \"alova\";\nimport {\n type AlovaFrontMiddlewareContext,\n type AlovaMethodHandler,\n type CompleteHandler,\n type ErrorHandler,\n type RequestHookConfig,\n type SuccessHandler,\n useRequest,\n} from \"alova/client\";\n\ninterface HookConfig<AG extends AlovaGenerics, Args extends any[]> extends RequestHookConfig<AG, Args> {\n onBeforeRequest?: (context: AlovaFrontMiddlewareContext<AG, Args>) => void;\n onSuccess?: SuccessHandler<AG, Args>;\n onError?: ErrorHandler<AG, Args>;\n onComplete?: CompleteHandler<AG, Args>;\n}\n\nexport function useAlovaRequest<AG extends AlovaGenerics, Args extends any[] = any[]> (\n methodHandler: Method<AG> | AlovaMethodHandler<AG, Args>,\n hookConfig?: HookConfig<AG, Args> | undefined,\n) {\n const config = hookConfig || {};\n config.immediate ??= true;\n\n if (config.onBeforeRequest) {\n const middleware = config.middleware;\n config.middleware = async (context, next) => {\n config.onBeforeRequest?.(context);\n\n if (middleware) {\n async function run () {\n await next();\n }\n await middleware?.(context, run);\n } else {\n await next();\n }\n };\n }\n\n const exposure = useRequest(methodHandler, config);\n\n if (config.onSuccess) {\n exposure.onSuccess(config.onSuccess);\n }\n if (config.onError) {\n exposure.onError(config.onError);\n }\n if (config.onComplete) {\n exposure.onComplete(config.onComplete);\n }\n\n return exposure;\n}\n","/* eslint-disable ts/no-explicit-any */\n\nimport type { AlovaGenerics, Method } from \"alova\";\nimport {\n type AlovaMethodHandler,\n type CompleteHandler,\n type ErrorHandler,\n type SuccessHandler,\n type WatcherHookConfig,\n useWatcher,\n} from \"alova/client\";\n\ninterface HookConfig<AG extends AlovaGenerics, Args extends any[]> extends WatcherHookConfig<AG, Args> {\n onSuccess?: SuccessHandler<AG, Args>;\n onError?: ErrorHandler<AG, Args>;\n onComplete?: CompleteHandler<AG, Args>;\n}\n\nexport function useAlovaWatcher<AG extends AlovaGenerics, Args extends any[] = any[]> (\n methodHandler: Method<AG> | AlovaMethodHandler<AG, Args>,\n watchingStates: AG[\"StatesExport\"][\"Watched\"][],\n hookConfig: HookConfig<AG, Args> = {},\n) {\n const config = hookConfig || {};\n const exposure = useWatcher(methodHandler, watchingStates, config);\n\n if (config.onSuccess) {\n exposure.onSuccess(config.onSuccess);\n }\n if (config.onError) {\n exposure.onError(config.onError);\n }\n if (config.onComplete) {\n exposure.onComplete(config.onComplete);\n }\n\n return exposure;\n}\n"],"mappings":";;;AAoBA,SAAgB,gBACd,eACA,YACA;CACA,MAAM,SAAS,cAAc,EAAE;AAC/B,QAAO,cAAP,OAAO,YAAc;AAErB,KAAI,OAAO,iBAAiB;EAC1B,MAAM,aAAa,OAAO;AAC1B,SAAO,aAAa,OAAO,SAAS,SAAS;AAC3C,UAAO,kBAAkB,QAAQ;AAEjC,OAAI,YAAY;IACd,eAAe,MAAO;AACpB,WAAM,MAAM;;AAEd,UAAM,aAAa,SAAS,IAAI;SAEhC,OAAM,MAAM;;;CAKlB,MAAM,WAAW,WAAW,eAAe,OAAO;AAElD,KAAI,OAAO,UACT,UAAS,UAAU,OAAO,UAAU;AAEtC,KAAI,OAAO,QACT,UAAS,QAAQ,OAAO,QAAQ;AAElC,KAAI,OAAO,WACT,UAAS,WAAW,OAAO,WAAW;AAGxC,QAAO;;;;;ACrCT,SAAgB,gBACd,eACA,gBACA,aAAmC,EAAE,EACrC;CACA,MAAM,SAAS,cAAc,EAAE;CAC/B,MAAM,WAAW,WAAW,eAAe,gBAAgB,OAAO;AAElE,KAAI,OAAO,UACT,UAAS,UAAU,OAAO,UAAU;AAEtC,KAAI,OAAO,QACT,UAAS,QAAQ,OAAO,QAAQ;AAElC,KAAI,OAAO,WACT,UAAS,WAAW,OAAO,WAAW;AAGxC,QAAO"}
|
package/dist/hooks-react.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { r as BREAK_POINT_TOKEN_TYPE } from "./index-BKUSlLXA.js";
|
|
2
|
+
import { r as AnyFunction, t as AnyAsyncFunction } from "./index-CjoMz104.js";
|
|
1
3
|
import { DependencyList, EffectCallback, RefObject } from "react";
|
|
2
4
|
|
|
3
5
|
//#region src/hooks/react/useCreation.d.ts
|
|
@@ -6,9 +8,8 @@ import { DependencyList, EffectCallback, RefObject } from "react";
|
|
|
6
8
|
* useCreation
|
|
7
9
|
* @reference https://ahooks.js.org/zh-CN/hooks/use-creation
|
|
8
10
|
*
|
|
9
|
-
* @
|
|
10
|
-
* @param
|
|
11
|
-
* @param {DependencyList} deps
|
|
11
|
+
* @param factory
|
|
12
|
+
* @param deps
|
|
12
13
|
*/
|
|
13
14
|
declare function useCreation<T>(factory: () => T, deps: DependencyList): T;
|
|
14
15
|
//#endregion
|
|
@@ -17,8 +18,7 @@ declare function useCreation<T>(factory: () => T, deps: DependencyList): T;
|
|
|
17
18
|
* 返回当前最新值的 Hook
|
|
18
19
|
* @reference https://ahooks.js.org/zh-CN/hooks/use-latest
|
|
19
20
|
*
|
|
20
|
-
* @
|
|
21
|
-
* @param {T} value
|
|
21
|
+
* @param value
|
|
22
22
|
*/
|
|
23
23
|
declare function useLatest<T>(value: T): RefObject<T>;
|
|
24
24
|
//#endregion
|
|
@@ -29,33 +29,10 @@ type MountCallback = EffectCallback | AnyAsyncFunction;
|
|
|
29
29
|
* - 即使在严格模式下也只执行一次
|
|
30
30
|
* @reference https://ahooks.js.org/hooks/use-mount
|
|
31
31
|
*
|
|
32
|
-
* @param
|
|
32
|
+
* @param effect 副作用函数
|
|
33
33
|
*/
|
|
34
34
|
declare function useMount(effect: MountCallback): void;
|
|
35
35
|
//#endregion
|
|
36
|
-
//#region src/enums/grid.d.ts
|
|
37
|
-
type BREAK_POINT_TOKEN_TYPE = Record<keyof typeof BREAK_POINT_TOKEN_ENUM, number>;
|
|
38
|
-
/** 屏幕响应断点 token 配置 */
|
|
39
|
-
declare const BREAK_POINT_TOKEN_ENUM: {
|
|
40
|
-
readonly XS: 576;
|
|
41
|
-
readonly XSMin: 576;
|
|
42
|
-
readonly XSMax: 767;
|
|
43
|
-
readonly SM: 768;
|
|
44
|
-
readonly SMMin: 768;
|
|
45
|
-
readonly SMMax: 991;
|
|
46
|
-
readonly MD: 992;
|
|
47
|
-
readonly MDMin: 992;
|
|
48
|
-
readonly MDMax: 1199;
|
|
49
|
-
readonly LG: 1200;
|
|
50
|
-
readonly LGMin: 1200;
|
|
51
|
-
readonly LGMax: 1599;
|
|
52
|
-
readonly XL: 1600;
|
|
53
|
-
readonly XLMin: 1600;
|
|
54
|
-
readonly XLMax: 1919;
|
|
55
|
-
readonly XXL: 1920;
|
|
56
|
-
readonly XXLMin: 1920;
|
|
57
|
-
};
|
|
58
|
-
//#endregion
|
|
59
36
|
//#region src/hooks/react/useResponsive.d.ts
|
|
60
37
|
type Breakpoint = "xxl" | "xl" | "lg" | "md" | "sm" | "xs";
|
|
61
38
|
type ResponsiveValues = Record<Breakpoint, boolean>;
|
|
@@ -81,7 +58,7 @@ declare function useResponsive(options?: ResponsiveHookOptions): {
|
|
|
81
58
|
* 在组件卸载时执行的 Hook
|
|
82
59
|
* @reference https://ahooks.js.org/zh-CN/hooks/use-unmount
|
|
83
60
|
*
|
|
84
|
-
* @param
|
|
61
|
+
* @param effect 副作用函数
|
|
85
62
|
*/
|
|
86
63
|
declare function useUnmount(effect: AnyFunction): void;
|
|
87
64
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks-react.d.ts","names":[],"sources":["../src/hooks/react/useCreation.ts","../src/hooks/react/useLatest.ts","../src/hooks/react/useMount.ts","../src/
|
|
1
|
+
{"version":3,"file":"hooks-react.d.ts","names":[],"sources":["../src/hooks/react/useCreation.ts","../src/hooks/react/useLatest.ts","../src/hooks/react/useMount.ts","../src/hooks/react/useResponsive.ts","../src/hooks/react/useUnmount.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAgBA;;;AAAsE,iBAAtD,WAAsD,CAAA,CAAA,CAAA,CAAA,OAAA,EAAA,GAAA,GAAvB,CAAuB,EAAA,IAAA,EAAd,cAAc,CAAA,EAAA,CAAA;;;;;;;AAAtE;;AAAwD,iBCRxC,SDQwC,CAAA,CAAA,CAAA,CAAA,KAAA,ECRnB,CDQmB,CAAA,ECRf,SDQe,CCRL,CDQK,CAAA;;;KEXnD,aAAA,GAAgB,iBAAiB;;;AFWtC;;;;;iBEFgB,QAAA,SAAkB;;;KCV7B,UAAA;KAGA,gBAAA,GAAmB,OAAO;UAQd,qBAAA;;AHCjB;;;;EAAsE,iBAAA,CAAA,EGKhD,UHLgD;;qBGOjD;;AFfL,iBEiBA,aAAA,CFjBS,OAAA,CAAA,EEiBgB,qBFjBhB,CAAA,EAAA;EAAY,UAAA,kBAAA;EAAc,OAAA,YAAA;EAAV,SAAA,EAAA,OAAA;EAAS,gBAAA,wBAAA;;;;;;;;ADQlD;;AAAwD,iBILxC,UAAA,CJKwC,MAAA,EILpB,WJKoB,CAAA,EAAA,IAAA"}
|
package/dist/hooks-react.js
CHANGED
|
@@ -1,172 +1,14 @@
|
|
|
1
|
+
import { Et as isEqual, Mt as isFunction, S as objectAssign, ut as isPromiseLike, y as objectKeys } from "./utils-khUJYSj2.js";
|
|
2
|
+
import { n as BREAK_POINT_TOKEN_ENUM } from "./enums-Bv0coVvD.js";
|
|
1
3
|
import { useEffect, useRef, useState } from "react";
|
|
2
4
|
|
|
3
|
-
//#region src/utils/typeof/types.ts
|
|
4
|
-
const PROTOTYPE_TAGS = {
|
|
5
|
-
abortSignal: "[object AbortSignal]",
|
|
6
|
-
array: "[object Array]",
|
|
7
|
-
asyncFunction: "[object AsyncFunction]",
|
|
8
|
-
asyncGeneratorFunction: "[object AsyncGeneratorFunction]",
|
|
9
|
-
bigInt: "[object BigInt]",
|
|
10
|
-
blob: "[object Blob]",
|
|
11
|
-
boolean: "[object Boolean]",
|
|
12
|
-
date: "[object Date]",
|
|
13
|
-
error: "[object Error]",
|
|
14
|
-
file: "[object File]",
|
|
15
|
-
function: "[object Function]",
|
|
16
|
-
generatorFunction: "[object GeneratorFunction]",
|
|
17
|
-
map: "[object Map]",
|
|
18
|
-
null: "[object Null]",
|
|
19
|
-
number: "[object Number]",
|
|
20
|
-
object: "[object Object]",
|
|
21
|
-
promise: "[object Promise]",
|
|
22
|
-
readableStream: "[object ReadableStream]",
|
|
23
|
-
regExp: "[object RegExp]",
|
|
24
|
-
set: "[object Set]",
|
|
25
|
-
string: "[object String]",
|
|
26
|
-
symbol: "[object Symbol]",
|
|
27
|
-
undefined: "[object Undefined]",
|
|
28
|
-
URLSearchParams: "[object URLSearchParams]",
|
|
29
|
-
weakMap: "[object WeakMap]",
|
|
30
|
-
weakSet: "[object WeakSet]",
|
|
31
|
-
webSocket: "[object WebSocket]",
|
|
32
|
-
window: "[object Window]"
|
|
33
|
-
};
|
|
34
|
-
function resolvePrototypeString(value) {
|
|
35
|
-
return Object.prototype.toString.call(value);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/utils/typeof/isBoolean.ts
|
|
40
|
-
function isBoolean(value) {
|
|
41
|
-
return typeof value === "boolean";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/utils/typeof/isObject.ts
|
|
46
|
-
/**
|
|
47
|
-
* 判断是否为对象类型
|
|
48
|
-
* - 可选是否检查原型为 `Object.prototype`,防止原型链污染
|
|
49
|
-
*
|
|
50
|
-
* @param value 待检查值
|
|
51
|
-
* @param prototypeCheck 是否进行原型检查,默认 `true`
|
|
52
|
-
*/
|
|
53
|
-
function isObject(value, prototypeCheck = true) {
|
|
54
|
-
const check = resolvePrototypeString(value) === PROTOTYPE_TAGS.object;
|
|
55
|
-
return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/utils/typeof/isDate.ts
|
|
60
|
-
function isDate(value) {
|
|
61
|
-
if (!isObject(value)) return false;
|
|
62
|
-
try {
|
|
63
|
-
return resolvePrototypeString(value) === PROTOTYPE_TAGS.date && typeof value["getTime"] === "function";
|
|
64
|
-
} catch (error) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/utils/typeof/isEqual.ts
|
|
71
|
-
/**
|
|
72
|
-
* 检查给定的值是否相等
|
|
73
|
-
* @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
|
|
74
|
-
*
|
|
75
|
-
* @param {T} x
|
|
76
|
-
* @param {T} y
|
|
77
|
-
*/
|
|
78
|
-
function isEqual(x, y) {
|
|
79
|
-
if (Object.is(x, y)) return true;
|
|
80
|
-
if (isDate(x) && isDate(y)) return x.getTime() === y.getTime();
|
|
81
|
-
if (isRegExp(x) && isRegExp(y)) return x.toString() === y.toString();
|
|
82
|
-
if (typeof x !== "object" || x === null || typeof y !== "object" || y === null) return false;
|
|
83
|
-
const keysX = Reflect.ownKeys(x);
|
|
84
|
-
const keysY = Reflect.ownKeys(y);
|
|
85
|
-
if (keysX.length !== keysY.length) return false;
|
|
86
|
-
for (const key of keysX) {
|
|
87
|
-
if (!Reflect.has(y, key)) return false;
|
|
88
|
-
if (!isEqual(x[key], y[key])) return false;
|
|
89
|
-
}
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/utils/typeof/isFunction.ts
|
|
95
|
-
function isFunction(value) {
|
|
96
|
-
return typeof value === "function";
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region src/utils/typeof/isPromise.ts
|
|
101
|
-
function isPromise(value) {
|
|
102
|
-
return resolvePrototypeString(value) === PROTOTYPE_TAGS.promise;
|
|
103
|
-
}
|
|
104
|
-
function isPromiseLike(value) {
|
|
105
|
-
return isPromise(value) || isObject(value) && isFunction(value["then"]);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/utils/typeof/isRegExp.ts
|
|
110
|
-
function isRegExp(value) {
|
|
111
|
-
if (!isObject(value)) return false;
|
|
112
|
-
try {
|
|
113
|
-
const regex = value;
|
|
114
|
-
return resolvePrototypeString(value) === PROTOTYPE_TAGS.regExp && isString(regex.source) && isString(regex.flags) && isBoolean(regex.global) && isFunction(regex.test);
|
|
115
|
-
} catch (error) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
//#endregion
|
|
121
|
-
//#region src/utils/typeof/isString.ts
|
|
122
|
-
/**
|
|
123
|
-
* 检查 value 是否为 string 类型
|
|
124
|
-
*
|
|
125
|
-
* @param value 待检查值
|
|
126
|
-
* @param checkEmpty 是否排除空字符串
|
|
127
|
-
*/
|
|
128
|
-
function isString(value, checkEmpty = false) {
|
|
129
|
-
return typeof value === "string" && (!checkEmpty || !!value.length);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/utils/object/objectKeys.ts
|
|
134
|
-
/**
|
|
135
|
-
* 返回对象的可枚举属性和方法的名称
|
|
136
|
-
* - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
|
|
137
|
-
*
|
|
138
|
-
* @param obj 对象
|
|
139
|
-
*/
|
|
140
|
-
function objectKeys(obj) {
|
|
141
|
-
return Object.keys(obj);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
//#endregion
|
|
145
|
-
//#region src/utils/object/objectAssign.ts
|
|
146
|
-
/**
|
|
147
|
-
* 递归地将第二个对象合并到第一个对象的副本中
|
|
148
|
-
* - 只有普通对象才会递归合并
|
|
149
|
-
*
|
|
150
|
-
* @param initial 初始对象
|
|
151
|
-
* @param override 待合并对象
|
|
152
|
-
*/
|
|
153
|
-
function objectAssign(initial, override) {
|
|
154
|
-
if (!isObject(initial) || !isObject(override)) return initial ?? override ?? {};
|
|
155
|
-
const proto = Object.getPrototypeOf(initial);
|
|
156
|
-
const assigned = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
|
|
157
|
-
for (const key of Object.keys(override)) assigned[key] = isObject(initial[key]) && isObject(override[key]) ? objectAssign(initial[key], override[key]) : override[key];
|
|
158
|
-
return assigned;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
//#endregion
|
|
162
5
|
//#region src/hooks/react/useCreation.ts
|
|
163
6
|
/**
|
|
164
7
|
* useCreation
|
|
165
8
|
* @reference https://ahooks.js.org/zh-CN/hooks/use-creation
|
|
166
9
|
*
|
|
167
|
-
* @
|
|
168
|
-
* @param
|
|
169
|
-
* @param {DependencyList} deps
|
|
10
|
+
* @param factory
|
|
11
|
+
* @param deps
|
|
170
12
|
*/
|
|
171
13
|
function useCreation(factory, deps) {
|
|
172
14
|
const { current } = useRef({
|
|
@@ -188,8 +30,7 @@ function useCreation(factory, deps) {
|
|
|
188
30
|
* 返回当前最新值的 Hook
|
|
189
31
|
* @reference https://ahooks.js.org/zh-CN/hooks/use-latest
|
|
190
32
|
*
|
|
191
|
-
* @
|
|
192
|
-
* @param {T} value
|
|
33
|
+
* @param value
|
|
193
34
|
*/
|
|
194
35
|
function useLatest(value) {
|
|
195
36
|
const ref = useRef(value);
|
|
@@ -204,7 +45,7 @@ function useLatest(value) {
|
|
|
204
45
|
* - 即使在严格模式下也只执行一次
|
|
205
46
|
* @reference https://ahooks.js.org/hooks/use-mount
|
|
206
47
|
*
|
|
207
|
-
* @param
|
|
48
|
+
* @param effect 副作用函数
|
|
208
49
|
*/
|
|
209
50
|
function useMount(effect) {
|
|
210
51
|
if (!isFunction(effect)) console.error(`useMount expected parameter is a function, but got ${typeof effect}`);
|
|
@@ -219,29 +60,6 @@ function useMount(effect) {
|
|
|
219
60
|
}, []);
|
|
220
61
|
}
|
|
221
62
|
|
|
222
|
-
//#endregion
|
|
223
|
-
//#region src/enums/grid.ts
|
|
224
|
-
/** 屏幕响应断点 token 配置 */
|
|
225
|
-
const BREAK_POINT_TOKEN_ENUM = {
|
|
226
|
-
XS: 576,
|
|
227
|
-
XSMin: 576,
|
|
228
|
-
XSMax: 767,
|
|
229
|
-
SM: 768,
|
|
230
|
-
SMMin: 768,
|
|
231
|
-
SMMax: 991,
|
|
232
|
-
MD: 992,
|
|
233
|
-
MDMin: 992,
|
|
234
|
-
MDMax: 1199,
|
|
235
|
-
LG: 1200,
|
|
236
|
-
LGMin: 1200,
|
|
237
|
-
LGMax: 1599,
|
|
238
|
-
XL: 1600,
|
|
239
|
-
XLMin: 1600,
|
|
240
|
-
XLMax: 1919,
|
|
241
|
-
XXL: 1920,
|
|
242
|
-
XXLMin: 1920
|
|
243
|
-
};
|
|
244
|
-
|
|
245
63
|
//#endregion
|
|
246
64
|
//#region src/hooks/react/useResponsive.ts
|
|
247
65
|
const subscriberList = /* @__PURE__ */ new Set();
|
|
@@ -325,7 +143,7 @@ function calculate() {
|
|
|
325
143
|
* 在组件卸载时执行的 Hook
|
|
326
144
|
* @reference https://ahooks.js.org/zh-CN/hooks/use-unmount
|
|
327
145
|
*
|
|
328
|
-
* @param
|
|
146
|
+
* @param effect 副作用函数
|
|
329
147
|
*/
|
|
330
148
|
function useUnmount(effect) {
|
|
331
149
|
if (!isFunction(effect)) console.error(`useUnmount expected parameter is a function, got ${typeof effect}`);
|
package/dist/hooks-react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks-react.js","names":["defaultResponsiveValues: ResponsiveValues","responsiveConfig: ResponsiveConfig","responsiveValues: ResponsiveValues","tokens: BREAK_POINT_TOKEN_TYPE"],"sources":["../src/utils/typeof/types.ts","../src/utils/typeof/isBoolean.ts","../src/utils/typeof/isObject.ts","../src/utils/typeof/isDate.ts","../src/utils/typeof/isEqual.ts","../src/utils/typeof/isFunction.ts","../src/utils/typeof/isPromise.ts","../src/utils/typeof/isRegExp.ts","../src/utils/typeof/isString.ts","../src/utils/object/objectKeys.ts","../src/utils/object/objectAssign.ts","../src/hooks/react/useCreation.ts","../src/hooks/react/useLatest.ts","../src/hooks/react/useMount.ts","../src/enums/grid.ts","../src/hooks/react/useResponsive.ts","../src/hooks/react/useUnmount.ts"],"sourcesContent":["export const PROTOTYPE_TAGS = {\n abortSignal: \"[object AbortSignal]\",\n array: \"[object Array]\",\n asyncFunction: \"[object AsyncFunction]\",\n asyncGeneratorFunction: \"[object AsyncGeneratorFunction]\",\n bigInt: \"[object BigInt]\",\n blob: \"[object Blob]\",\n boolean: \"[object Boolean]\",\n date: \"[object Date]\",\n error: \"[object Error]\",\n file: \"[object File]\",\n function: \"[object Function]\",\n generatorFunction: \"[object GeneratorFunction]\",\n map: \"[object Map]\",\n null: \"[object Null]\",\n number: \"[object Number]\",\n object: \"[object Object]\",\n promise: \"[object Promise]\",\n readableStream: \"[object ReadableStream]\",\n regExp: \"[object RegExp]\",\n set: \"[object Set]\",\n string: \"[object String]\",\n symbol: \"[object Symbol]\",\n undefined: \"[object Undefined]\",\n URLSearchParams: \"[object URLSearchParams]\",\n weakMap: \"[object WeakMap]\",\n weakSet: \"[object WeakSet]\",\n webSocket: \"[object WebSocket]\",\n window: \"[object Window]\",\n} as const;\n\nexport const TYPED_ARRAY_TAGS = new Set([\n \"[object Int8Array]\",\n \"[object Uint8Array]\",\n \"[object Uint8ClampedArray]\",\n \"[object Int16Array]\",\n \"[object Uint16Array]\",\n \"[object Int32Array]\",\n \"[object Uint32Array]\",\n \"[object Float32Array]\",\n \"[object Float64Array]\",\n \"[object BigInt64Array]\",\n \"[object BigUint64Array]\",\n]);\n\nexport function resolvePrototypeString(value: unknown) {\n return Object.prototype.toString.call(value);\n}\n","export function isBoolean(value: unknown): value is boolean {\n return typeof value === \"boolean\";\n}\n","import { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\n/**\n * 判断是否为对象类型\n * - 可选是否检查原型为 `Object.prototype`,防止原型链污染\n *\n * @param value 待检查值\n * @param prototypeCheck 是否进行原型检查,默认 `true`\n */\nexport function isObject(value: unknown, prototypeCheck = true): value is Record<PropertyKey, unknown> {\n const check = resolvePrototypeString(value) === PROTOTYPE_TAGS.object;\n\n return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;\n}\n","import { isObject } from \"./isObject\";\nimport { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\nexport function isDate(value: unknown): value is Date {\n if (!isObject(value)) {\n return false;\n }\n\n try {\n return resolvePrototypeString(value) === PROTOTYPE_TAGS.date && typeof (value)[\"getTime\"] === \"function\";\n } catch (error) {\n return false;\n }\n}\n","import { isDate, isRegExp } from \".\";\n\n/**\n * 检查给定的值是否相等\n * @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts\n *\n * @param {T} x\n * @param {T} y\n */\nexport function isEqual<T>(x: T, y: T): boolean {\n if (Object.is(x, y)) {\n return true;\n }\n if (isDate(x) && isDate(y)) {\n return x.getTime() === y.getTime();\n }\n if (isRegExp(x) && isRegExp(y)) {\n return x.toString() === y.toString();\n }\n if (typeof x !== \"object\" || x === null || typeof y !== \"object\" || y === null) {\n return false;\n }\n\n const keysX = Reflect.ownKeys(x) as (keyof typeof x)[];\n const keysY = Reflect.ownKeys(y);\n if (keysX.length !== keysY.length) {\n return false;\n }\n\n for (const key of keysX) {\n if (!Reflect.has(y, key)) {\n return false;\n }\n if (!isEqual(x[key], y[key])) {\n return false;\n }\n }\n\n return true;\n}\n","import { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\nexport function isFunction(value: unknown): value is AnyFunction {\n return typeof value === \"function\";\n}\n\nexport function isAsyncFunction(value: unknown): value is AnyAsyncFunction {\n return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncFunction;\n}\n\nexport function isGeneratorFunction(value: unknown): value is AnyGeneratorFunction {\n return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.generatorFunction;\n}\n\nexport function isAsyncGeneratorFunction(value: unknown): value is AnyAsyncGeneratorFunction {\n return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncGeneratorFunction;\n}\n","import { isFunction } from \"./isFunction\";\nimport { isObject } from \"./isObject\";\nimport { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\nexport function isPromise(value: unknown): value is Promise<unknown> {\n return resolvePrototypeString(value) === PROTOTYPE_TAGS.promise;\n}\n\nexport function isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return isPromise(value) || (isObject(value) && isFunction(value[\"then\"]));\n}\n","import { isBoolean, isFunction, isObject, isString } from \".\";\nimport { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\nexport function isRegExp(value: unknown): value is RegExp {\n if (!isObject(value)) {\n return false;\n }\n\n try {\n const regex = value as unknown as RegExp;\n\n return (\n resolvePrototypeString(value) === PROTOTYPE_TAGS.regExp &&\n isString(regex.source) &&\n isString(regex.flags) &&\n isBoolean(regex.global) &&\n isFunction(regex.test)\n );\n } catch (error) {\n return false;\n }\n}\n","/**\n * 检查 value 是否为 string 类型\n *\n * @param value 待检查值\n * @param checkEmpty 是否排除空字符串\n */\nexport function isString(value: unknown, checkEmpty = false): value is string {\n return typeof value === \"string\" && (!checkEmpty || !!value.length);\n}\n","/**\n * 返回对象的可枚举属性和方法的名称\n * - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型\n *\n * @param obj 对象\n */\nexport function objectKeys<O extends AnyObject>(obj: O): (keyof O)[] {\n return Object.keys(obj);\n}\n","import type { Assign } from \"radashi\";\nimport { isObject } from \"../typeof\";\n\n/**\n * 递归地将第二个对象合并到第一个对象的副本中\n * - 只有普通对象才会递归合并\n *\n * @param initial 初始对象\n * @param override 待合并对象\n */\nexport function objectAssign<I extends PlainObject, O extends PlainObject>(initial: I, override: O): Assign<I, O> {\n if (!isObject(initial) || !isObject(override)) {\n return (initial ?? override ?? {}) as Assign<I, O>;\n }\n\n const proto = Object.getPrototypeOf(initial);\n const assigned = proto ? { ...initial } : Object.assign(Object.create(proto), initial);\n\n for (const key of Object.keys(override)) {\n assigned[key] = isObject(initial[key]) && isObject(override[key]) ? objectAssign(initial[key], override[key]) : override[key];\n }\n\n return assigned;\n}\n","import { useRef, type DependencyList } from \"react\";\nimport { isEqual } from \"src/utils\";\n\ninterface RefObject<T> {\n deps: DependencyList;\n result: T;\n isInitialized: boolean;\n}\n\n/**\n * useCreation\n * @reference https://ahooks.js.org/zh-CN/hooks/use-creation\n *\n * @template T\n * @param {() => T} factory\n * @param {DependencyList} deps\n */\nexport function useCreation<T>(factory: () => T, deps: DependencyList) {\n const { current } = useRef<RefObject<T>>({ deps, result: undefined!, isInitialized: false });\n\n if (current.isInitialized === false || !isEqual(current.deps, deps)) {\n current.deps = deps;\n current.result = factory();\n current.isInitialized = true;\n }\n\n return current.result;\n}\n\n","import { useRef, type RefObject } from \"react\";\n\n/**\n * 返回当前最新值的 Hook\n * @reference https://ahooks.js.org/zh-CN/hooks/use-latest\n *\n * @template T\n * @param {T} value\n */\nexport function useLatest<T>(value: T): RefObject<T> {\n const ref = useRef(value);\n ref.current = value;\n\n return ref;\n}\n\n","import { useEffect, useRef, type EffectCallback } from \"react\";\nimport { isFunction, isPromiseLike } from \"src/utils\";\nimport { useLatest } from \"./useLatest\";\n\ntype MountCallback = EffectCallback | AnyAsyncFunction;\n\n/**\n * 在组件初始化时执行的 Hook\n * - 即使在严格模式下也只执行一次\n * @reference https://ahooks.js.org/hooks/use-mount\n *\n * @param {MountCallback} effect 副作用函数\n */\nexport function useMount(effect: MountCallback) {\n if (!isFunction(effect)) {\n console.error(`useMount expected parameter is a function, but got ${typeof effect}`);\n }\n\n const isMountedRef = useRef(false);\n const effectRef = useLatest(effect);\n\n useEffect(() => {\n if (isMountedRef.current) {\n return;\n }\n\n isMountedRef.current = true;\n const result = effectRef.current?.();\n // If fn returns a Promise, don't return it as cleanup function\n if (isPromiseLike(result)) {\n return;\n }\n\n return result as ReturnType<EffectCallback>;\n }, []);\n}\n\n","export type BREAK_POINT_TOKEN_TYPE = Record<keyof typeof BREAK_POINT_TOKEN_ENUM, number>;\n/** 屏幕响应断点 token 配置 */\nexport const BREAK_POINT_TOKEN_ENUM = {\n XS: 576,\n XSMin: 576,\n XSMax: 767,\n SM: 768,\n SMMin: 768,\n SMMax: 991,\n MD: 992,\n MDMin: 992,\n MDMax: 1199,\n LG: 1200,\n LGMin: 1200,\n LGMax: 1599,\n XL: 1600,\n XLMin: 1600,\n XLMax: 1919,\n XXL: 1920,\n XXLMin: 1920,\n} as const;\n","import { useEffect, useState } from \"react\";\nimport { BREAK_POINT_TOKEN_ENUM, type BREAK_POINT_TOKEN_TYPE } from \"src/enums\";\nimport { objectAssign, objectKeys } from \"src/utils\";\n\ntype Breakpoint = \"xxl\" | \"xl\" | \"lg\" | \"md\" | \"sm\" | \"xs\";\ntype Subscriber = () => void;\ntype ResponsiveConfig = Record<Breakpoint, number>;\ntype ResponsiveValues = Record<Breakpoint, boolean>;\n\nconst subscriberList = new Set<Subscriber>();\nconst { XS, SM, MD, LG, XL, XXL } = BREAK_POINT_TOKEN_ENUM;\nconst defaultResponsiveValues: ResponsiveValues = { xxl: false, xl: false, lg: false, md: false, sm: false, xs: false };\nlet responsiveConfig: ResponsiveConfig = { xxl: XXL, xl: XL, lg: LG, md: MD, sm: SM, xs: XS };\nlet responsiveValues: ResponsiveValues = { ...defaultResponsiveValues };\n\nexport interface ResponsiveHookOptions {\n /**\n * 紧凑布局断点\n * - 低于此断点时使用紧凑布局\n * @default \"xl\"\n */\n compactBreakPoint?: Breakpoint;\n /** 屏幕响应断点 token 配置 */\n breakPointTokens?: BREAK_POINT_TOKEN_TYPE;\n}\nexport function useResponsive(options?: ResponsiveHookOptions) {\n const { compactBreakPoint = \"xl\", breakPointTokens = {} } = options || {};\n const tokens: BREAK_POINT_TOKEN_TYPE = objectAssign(BREAK_POINT_TOKEN_ENUM, breakPointTokens);\n responsiveConfig = { xxl: tokens.XXL, xl: tokens.XL, lg: tokens.LG, md: tokens.MD, sm: tokens.SM, xs: tokens.XS };\n\n calculate();\n\n const [responsive, setResponsive] = useState<ResponsiveValues>(responsiveValues);\n const isCompact = !responsive[compactBreakPoint];\n const current = objectKeys(defaultResponsiveValues).find((key) => responsive[key] === true) || \"xs\";\n\n useEffect(() => {\n addListener();\n\n const subscriber = () => {\n setResponsive(responsiveValues);\n };\n\n subscriberList.add(subscriber);\n\n return () => {\n subscriberList.delete(subscriber);\n\n if (subscriberList.size === 0) {\n removeListener();\n }\n };\n }, []);\n\n return { responsive, current, isCompact, breakPointTokens: tokens };\n}\n\nfunction resizeListener() {\n const oldInfo = responsiveValues;\n calculate();\n\n if (oldInfo === responsiveValues) {\n return;\n }\n\n for (const subscriber of subscriberList) {\n subscriber();\n }\n}\nfunction addListener() {\n window.addEventListener(\"resize\", resizeListener);\n}\nfunction removeListener() {\n window.removeEventListener(\"resize\", resizeListener);\n}\nfunction calculate() {\n const width = window.innerWidth;\n const newValues = { ...defaultResponsiveValues };\n let shouldUpdate = false;\n\n for (const key of objectKeys(responsiveConfig)) {\n newValues[key] = width >= responsiveConfig[key];\n if (newValues[key] !== responsiveValues[key]) {\n shouldUpdate = true;\n }\n }\n if (shouldUpdate) {\n responsiveValues = newValues;\n }\n}\n\n","import { useEffect } from \"react\";\nimport { isFunction } from \"src/utils\";\nimport { useLatest } from \"./useLatest\";\n\n/**\n * 在组件卸载时执行的 Hook\n * @reference https://ahooks.js.org/zh-CN/hooks/use-unmount\n *\n * @param {AnyFunction} effect 副作用函数\n */\nexport function useUnmount(effect: AnyFunction) {\n if (!isFunction(effect)) {\n console.error(`useUnmount expected parameter is a function, got ${typeof effect}`);\n }\n\n const effectRef = useLatest(effect);\n\n useEffect(\n () => () => {\n effectRef.current?.();\n },\n [],\n );\n}\n\n"],"mappings":";;;AAAA,MAAa,iBAAiB;CAC5B,aAAa;CACb,OAAO;CACP,eAAe;CACf,wBAAwB;CACxB,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,MAAM;CACN,UAAU;CACV,mBAAmB;CACnB,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AAS;CAGpF,MAAM,YAAY,UAAU,OAAO;AAEnC,uBACc;AACV,YAAU,WAAW;IAEvB,EAAE,CACH"}
|
|
1
|
+
{"version":3,"file":"hooks-react.js","names":["defaultResponsiveValues: ResponsiveValues","responsiveConfig: ResponsiveConfig","responsiveValues: ResponsiveValues","tokens: BREAK_POINT_TOKEN_TYPE"],"sources":["../src/hooks/react/useCreation.ts","../src/hooks/react/useLatest.ts","../src/hooks/react/useMount.ts","../src/hooks/react/useResponsive.ts","../src/hooks/react/useUnmount.ts"],"sourcesContent":["import { useRef, type DependencyList } from \"react\";\nimport { isEqual } from \"src/utils\";\n\ninterface RefObject<T> {\n deps: DependencyList;\n result: T;\n isInitialized: boolean;\n}\n\n/**\n * useCreation\n * @reference https://ahooks.js.org/zh-CN/hooks/use-creation\n *\n * @param factory\n * @param deps\n */\nexport function useCreation<T> (factory: () => T, deps: DependencyList) {\n const { current } = useRef<RefObject<T>>({ deps, result: undefined!, isInitialized: false });\n\n if (current.isInitialized === false || !isEqual(current.deps, deps)) {\n current.deps = deps;\n current.result = factory();\n current.isInitialized = true;\n }\n\n return current.result;\n}\n\n","import { useRef, type RefObject } from \"react\";\n\n/**\n * 返回当前最新值的 Hook\n * @reference https://ahooks.js.org/zh-CN/hooks/use-latest\n *\n * @param value\n */\nexport function useLatest<T> (value: T): RefObject<T> {\n const ref = useRef(value);\n ref.current = value;\n\n return ref;\n}\n\n","import type { AnyAsyncFunction } from \"@pawover/types\";\nimport { useEffect, useRef, type EffectCallback } from \"react\";\nimport { isFunction, isPromiseLike } from \"src/utils\";\nimport { useLatest } from \"./useLatest\";\n\ntype MountCallback = EffectCallback | AnyAsyncFunction;\n\n/**\n * 在组件初始化时执行的 Hook\n * - 即使在严格模式下也只执行一次\n * @reference https://ahooks.js.org/hooks/use-mount\n *\n * @param effect 副作用函数\n */\nexport function useMount (effect: MountCallback) {\n if (!isFunction(effect)) {\n console.error(`useMount expected parameter is a function, but got ${typeof effect}`);\n }\n\n const isMountedRef = useRef(false);\n const effectRef = useLatest(effect);\n\n useEffect(() => {\n if (isMountedRef.current) {\n return;\n }\n\n isMountedRef.current = true;\n const result = effectRef.current?.();\n // If fn returns a Promise, don't return it as cleanup function\n if (isPromiseLike(result)) {\n return;\n }\n\n return result as ReturnType<EffectCallback>;\n }, []);\n}\n\n","import { useEffect, useState } from \"react\";\nimport { BREAK_POINT_TOKEN_ENUM, type BREAK_POINT_TOKEN_TYPE } from \"src/enums\";\nimport { objectAssign, objectKeys } from \"src/utils\";\n\ntype Breakpoint = \"xxl\" | \"xl\" | \"lg\" | \"md\" | \"sm\" | \"xs\";\ntype Subscriber = () => void;\ntype ResponsiveConfig = Record<Breakpoint, number>;\ntype ResponsiveValues = Record<Breakpoint, boolean>;\n\nconst subscriberList = new Set<Subscriber>();\nconst { XS, SM, MD, LG, XL, XXL } = BREAK_POINT_TOKEN_ENUM;\nconst defaultResponsiveValues: ResponsiveValues = { xxl: false, xl: false, lg: false, md: false, sm: false, xs: false };\nlet responsiveConfig: ResponsiveConfig = { xxl: XXL, xl: XL, lg: LG, md: MD, sm: SM, xs: XS };\nlet responsiveValues: ResponsiveValues = { ...defaultResponsiveValues };\n\nexport interface ResponsiveHookOptions {\n /**\n * 紧凑布局断点\n * - 低于此断点时使用紧凑布局\n * @default \"xl\"\n */\n compactBreakPoint?: Breakpoint;\n /** 屏幕响应断点 token 配置 */\n breakPointTokens?: BREAK_POINT_TOKEN_TYPE;\n}\nexport function useResponsive (options?: ResponsiveHookOptions) {\n const { compactBreakPoint = \"xl\", breakPointTokens = {} } = options || {};\n const tokens: BREAK_POINT_TOKEN_TYPE = objectAssign(BREAK_POINT_TOKEN_ENUM, breakPointTokens);\n responsiveConfig = { xxl: tokens.XXL, xl: tokens.XL, lg: tokens.LG, md: tokens.MD, sm: tokens.SM, xs: tokens.XS };\n\n calculate();\n\n const [responsive, setResponsive] = useState<ResponsiveValues>(responsiveValues);\n const isCompact = !responsive[compactBreakPoint];\n const current = objectKeys(defaultResponsiveValues).find((key) => responsive[key] === true) || \"xs\";\n\n useEffect(() => {\n addListener();\n\n const subscriber = () => {\n setResponsive(responsiveValues);\n };\n\n subscriberList.add(subscriber);\n\n return () => {\n subscriberList.delete(subscriber);\n\n if (subscriberList.size === 0) {\n removeListener();\n }\n };\n }, []);\n\n return { responsive, current, isCompact, breakPointTokens: tokens };\n}\n\nfunction resizeListener () {\n const oldInfo = responsiveValues;\n calculate();\n\n if (oldInfo === responsiveValues) {\n return;\n }\n\n for (const subscriber of subscriberList) {\n subscriber();\n }\n}\nfunction addListener () {\n window.addEventListener(\"resize\", resizeListener);\n}\nfunction removeListener () {\n window.removeEventListener(\"resize\", resizeListener);\n}\nfunction calculate () {\n const width = window.innerWidth;\n const newValues = { ...defaultResponsiveValues };\n let shouldUpdate = false;\n\n for (const key of objectKeys(responsiveConfig)) {\n newValues[key] = width >= responsiveConfig[key];\n if (newValues[key] !== responsiveValues[key]) {\n shouldUpdate = true;\n }\n }\n if (shouldUpdate) {\n responsiveValues = newValues;\n }\n}\n\n","import type { AnyFunction } from \"@pawover/types\";\nimport { useEffect } from \"react\";\nimport { isFunction } from \"src/utils\";\nimport { useLatest } from \"./useLatest\";\n\n/**\n * 在组件卸载时执行的 Hook\n * @reference https://ahooks.js.org/zh-CN/hooks/use-unmount\n *\n * @param effect 副作用函数\n */\nexport function useUnmount (effect: AnyFunction) {\n if (!isFunction(effect)) {\n console.error(`useUnmount expected parameter is a function, got ${typeof effect}`);\n }\n\n const effectRef = useLatest(effect);\n\n useEffect(\n () => () => {\n effectRef.current?.();\n },\n [],\n );\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAgB,YAAgB,SAAkB,MAAsB;CACtE,MAAM,EAAE,YAAY,OAAqB;EAAE;EAAM,QAAQ;EAAY,eAAe;EAAO,CAAC;AAE5F,KAAI,QAAQ,kBAAkB,SAAS,CAAC,QAAQ,QAAQ,MAAM,KAAK,EAAE;AACnE,UAAQ,OAAO;AACf,UAAQ,SAAS,SAA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