@stryke/hooks 0.4.47 → 0.4.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  3. package/dist/env/src/runtime-checks.cjs +57 -1
  4. package/dist/env/src/runtime-checks.mjs +56 -1
  5. package/dist/env/src/runtime-checks.mjs.map +1 -1
  6. package/dist/helpers/src/debounce.cjs +62 -1
  7. package/dist/helpers/src/debounce.mjs +61 -1
  8. package/dist/helpers/src/debounce.mjs.map +1 -1
  9. package/dist/helpers/src/throttle.cjs +43 -1
  10. package/dist/helpers/src/throttle.mjs +42 -1
  11. package/dist/helpers/src/throttle.mjs.map +1 -1
  12. package/dist/index.cjs +41 -1
  13. package/dist/index.mjs +19 -1
  14. package/dist/type-checks/src/get-object-tag.cjs +15 -1
  15. package/dist/type-checks/src/get-object-tag.mjs +14 -1
  16. package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
  17. package/dist/type-checks/src/is-equal.cjs +19 -1
  18. package/dist/type-checks/src/is-equal.mjs +18 -1
  19. package/dist/type-checks/src/is-equal.mjs.map +1 -1
  20. package/dist/type-checks/src/is-function.cjs +25 -1
  21. package/dist/type-checks/src/is-function.mjs +25 -1
  22. package/dist/type-checks/src/is-function.mjs.map +1 -1
  23. package/dist/types/src/base.cjs +6 -1
  24. package/dist/types/src/base.mjs +5 -1
  25. package/dist/types/src/base.mjs.map +1 -1
  26. package/dist/use-battery.cjs +60 -1
  27. package/dist/use-battery.mjs +58 -1
  28. package/dist/use-battery.mjs.map +1 -1
  29. package/dist/use-callback-ref.cjs +18 -1
  30. package/dist/use-callback-ref.mjs +17 -1
  31. package/dist/use-callback-ref.mjs.map +1 -1
  32. package/dist/use-callback-stable.cjs +26 -1
  33. package/dist/use-callback-stable.mjs +26 -1
  34. package/dist/use-callback-stable.mjs.map +1 -1
  35. package/dist/use-click-away.cjs +33 -1
  36. package/dist/use-click-away.mjs +32 -1
  37. package/dist/use-click-away.mjs.map +1 -1
  38. package/dist/use-compose-refs.cjs +43 -1
  39. package/dist/use-compose-refs.mjs +40 -1
  40. package/dist/use-compose-refs.mjs.map +1 -1
  41. package/dist/use-copy-to-clipboard.cjs +38 -1
  42. package/dist/use-copy-to-clipboard.mjs +37 -1
  43. package/dist/use-copy-to-clipboard.mjs.map +1 -1
  44. package/dist/use-debounce.cjs +44 -1
  45. package/dist/use-debounce.mjs +42 -1
  46. package/dist/use-debounce.mjs.map +1 -1
  47. package/dist/use-did-finish-ssr.cjs +27 -1
  48. package/dist/use-did-finish-ssr.mjs +24 -1
  49. package/dist/use-did-finish-ssr.mjs.map +1 -1
  50. package/dist/use-escape-keydown.cjs +23 -1
  51. package/dist/use-escape-keydown.mjs +22 -1
  52. package/dist/use-escape-keydown.mjs.map +1 -1
  53. package/dist/use-event.cjs +27 -1
  54. package/dist/use-event.mjs +26 -1
  55. package/dist/use-event.mjs.map +1 -1
  56. package/dist/use-hover.cjs +33 -1
  57. package/dist/use-hover.mjs +32 -1
  58. package/dist/use-hover.mjs.map +1 -1
  59. package/dist/use-idle.cjs +50 -1
  60. package/dist/use-idle.mjs +49 -1
  61. package/dist/use-idle.mjs.map +1 -1
  62. package/dist/use-isomorphic-layout-effect.cjs +14 -1
  63. package/dist/use-isomorphic-layout-effect.mjs +13 -1
  64. package/dist/use-isomorphic-layout-effect.mjs.map +1 -1
  65. package/dist/use-keyboard-visible.cjs +24 -1
  66. package/dist/use-keyboard-visible.mjs +23 -1
  67. package/dist/use-keyboard-visible.mjs.map +1 -1
  68. package/dist/use-memo-stable.cjs +48 -1
  69. package/dist/use-memo-stable.mjs +47 -1
  70. package/dist/use-memo-stable.mjs.map +1 -1
  71. package/dist/use-network-state.cjs +57 -1
  72. package/dist/use-network-state.mjs +55 -1
  73. package/dist/use-network-state.mjs.map +1 -1
  74. package/dist/use-previous.cjs +20 -1
  75. package/dist/use-previous.mjs +19 -1
  76. package/dist/use-previous.mjs.map +1 -1
  77. package/package.json +2 -2
@@ -1 +1,25 @@
1
- const e=require(`./get-object-tag.cjs`);function t(t){return e.getObjectTag(t)===`[object Function]`}function n(t){return e.getObjectTag(t)===`[object AsyncFunction]`}const r=e=>{try{return e instanceof Function||typeof e==`function`||!!(e?.constructor&&e?.call&&e?.apply)||t(e)||n(e)}catch{return!1}};exports.isFunction=r;
1
+ const require_get_object_tag = require('./get-object-tag.cjs');
2
+
3
+ //#region ../type-checks/src/is-function.ts
4
+ function isSyncFunction(value) {
5
+ return require_get_object_tag.getObjectTag(value) === "[object Function]";
6
+ }
7
+ function isAsyncFunction(value) {
8
+ return require_get_object_tag.getObjectTag(value) === "[object AsyncFunction]";
9
+ }
10
+ /**
11
+ * Check if the provided value's type is `Function`
12
+ *
13
+ * @param value - The value to type check
14
+ * @returns An indicator specifying if the value provided is of type `Function`
15
+ */
16
+ const isFunction = (value) => {
17
+ try {
18
+ return value instanceof Function || typeof value === "function" || Boolean(value?.constructor && value?.call && value?.apply) || isSyncFunction(value) || isAsyncFunction(value);
19
+ } catch {
20
+ return false;
21
+ }
22
+ };
23
+
24
+ //#endregion
25
+ exports.isFunction = isFunction;
@@ -1,2 +1,26 @@
1
- import{getObjectTag as e}from"./get-object-tag.mjs";function t(t){return e(t)===`[object Function]`}function n(t){return e(t)===`[object AsyncFunction]`}const r=e=>{try{return e instanceof Function||typeof e==`function`||!!(e?.constructor&&e?.call&&e?.apply)||t(e)||n(e)}catch{return!1}};export{r as isFunction};
1
+ import { getObjectTag } from "./get-object-tag.mjs";
2
+
3
+ //#region ../type-checks/src/is-function.ts
4
+ function isSyncFunction(value) {
5
+ return getObjectTag(value) === "[object Function]";
6
+ }
7
+ function isAsyncFunction(value) {
8
+ return getObjectTag(value) === "[object AsyncFunction]";
9
+ }
10
+ /**
11
+ * Check if the provided value's type is `Function`
12
+ *
13
+ * @param value - The value to type check
14
+ * @returns An indicator specifying if the value provided is of type `Function`
15
+ */
16
+ const isFunction = (value) => {
17
+ try {
18
+ return value instanceof Function || typeof value === "function" || Boolean(value?.constructor && value?.call && value?.apply) || isSyncFunction(value) || isAsyncFunction(value);
19
+ } catch {
20
+ return false;
21
+ }
22
+ };
23
+
24
+ //#endregion
25
+ export { isFunction };
2
26
  //# sourceMappingURL=is-function.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-function.mjs","names":[],"sources":["../../../../type-checks/src/is-function.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { AnyFunction } from \"@stryke/types/base\";\nimport { getObjectTag } from \"./get-object-tag\";\n\nexport function isSyncFunction(value?: any): value is AnyFunction {\n return getObjectTag(value) === \"[object Function]\";\n}\n\nexport function isAsyncFunction(value?: any): value is AnyFunction {\n return getObjectTag(value) === \"[object AsyncFunction]\";\n}\n\n/**\n * Check if the provided value's type is `Function`\n *\n * @param value - The value to type check\n * @returns An indicator specifying if the value provided is of type `Function`\n */\nexport const isFunction = (value: unknown): value is AnyFunction => {\n try {\n return (\n value instanceof Function ||\n typeof value === \"function\" ||\n Boolean(\n value?.constructor && (value as any)?.call && (value as any)?.apply\n ) ||\n isSyncFunction(value) ||\n isAsyncFunction(value)\n );\n } catch {\n return false;\n }\n};\n"],"mappings":"oDAqBA,SAAgB,EAAe,EAAmC,CAChE,OAAO,EAAa,EAAM,GAAK,oBAGjC,SAAgB,EAAgB,EAAmC,CACjE,OAAO,EAAa,EAAM,GAAK,yBASjC,MAAa,EAAc,GAAyC,CAClE,GAAI,CACF,OACE,aAAiB,UACjB,OAAO,GAAU,YACjB,GACE,GAAO,aAAgB,GAAe,MAAS,GAAe,QAEhE,EAAe,EAAM,EACrB,EAAgB,EAAM,MAElB,CACN,MAAO"}
1
+ {"version":3,"file":"is-function.mjs","names":[],"sources":["../../../../type-checks/src/is-function.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { AnyFunction } from \"@stryke/types/base\";\nimport { getObjectTag } from \"./get-object-tag\";\n\nexport function isSyncFunction(value?: any): value is AnyFunction {\n return getObjectTag(value) === \"[object Function]\";\n}\n\nexport function isAsyncFunction(value?: any): value is AnyFunction {\n return getObjectTag(value) === \"[object AsyncFunction]\";\n}\n\n/**\n * Check if the provided value's type is `Function`\n *\n * @param value - The value to type check\n * @returns An indicator specifying if the value provided is of type `Function`\n */\nexport const isFunction = (value: unknown): value is AnyFunction => {\n try {\n return (\n value instanceof Function ||\n typeof value === \"function\" ||\n Boolean(\n value?.constructor && (value as any)?.call && (value as any)?.apply\n ) ||\n isSyncFunction(value) ||\n isAsyncFunction(value)\n );\n } catch {\n return false;\n }\n};\n"],"mappings":";;;AAqBA,SAAgB,eAAe,OAAmC;AAChE,QAAO,aAAa,MAAM,KAAK;;AAGjC,SAAgB,gBAAgB,OAAmC;AACjE,QAAO,aAAa,MAAM,KAAK;;;;;;;;AASjC,MAAa,cAAc,UAAyC;AAClE,KAAI;AACF,SACE,iBAAiB,YACjB,OAAO,UAAU,cACjB,QACE,OAAO,eAAgB,OAAe,QAAS,OAAe,MAC/D,IACD,eAAe,MAAM,IACrB,gBAAgB,MAAM;SAElB;AACN,SAAO"}
@@ -1 +1,6 @@
1
- const e=``;exports.EMPTY_STRING=``;
1
+
2
+ //#region ../types/src/base.ts
3
+ const EMPTY_STRING = "";
4
+
5
+ //#endregion
6
+ exports.EMPTY_STRING = EMPTY_STRING;
@@ -1,2 +1,6 @@
1
- const e=``;export{e as EMPTY_STRING};
1
+ //#region ../types/src/base.ts
2
+ const EMPTY_STRING = "";
3
+
4
+ //#endregion
5
+ export { EMPTY_STRING };
2
6
  //# sourceMappingURL=base.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.mjs","names":[],"sources":["../../../../types/src/base.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { TypedArray } from \"./array\";\n\nexport type SerializablePrimitive =\n | null\n | undefined\n | string\n | number\n | boolean\n | bigint;\nexport type Primitive = SerializablePrimitive | symbol;\n\n/**\n * Matches any primitive, `void`, `Date`, or `RegExp` value.\n */\nexport type BuiltIns = Primitive | void | Date | RegExp;\n\n/**\n * Matches any non-primitive object\n */\n// eslint-disable-next-line ts/no-unsafe-function-type\nexport type AtomicObject = Function | Promise<any> | Date | RegExp;\n\n/** Determines if the passed value is of a specific type */\nexport type TypeTester = (value: any) => boolean;\n\n/**\n * The interface for a type mapping (key =\\> function) to use for {@link getType}.\n * export * The key represents the name of the type. The function represents the {@link TypeTester | test method}.\n * The map should be ordered by testing preference, with more specific tests first.\n * If a test returns true, it is selected, and the key is returned as the type.\n */\nexport type TypeMap = Record<string, TypeTester>;\n\ndeclare const emptyObjectSymbol: unique symbol;\n\nexport type FunctionOrValue<Value> = Value extends () => infer X ? X : Value;\n\n/**\n * A [[List]]\n *\n * @example\n * ```ts\n * type list0 = [1, 2, 3]\n * type list1 = number[]\n * ```\n *\n * @param A - its type\n * @returns [[List]]\n */\nexport type List<A = any> = ReadonlyArray<A>;\n\n/**\n * Alias to create a [[Function]]\n *\n * @example\n * ```ts\n * import { FunctionLike } from '@stryke/types'\n *\n * type test0 = FunctionLike<[string, number], boolean>\n * /// (args_0: string, args_1: number) => boolean\n * ```\n *\n * @param P - parameters\n * @param R - return type\n * @returns [[Function]]\n */\nexport type FunctionLike<P extends List = any, R = any> = (...args: P) => R;\n\nexport type AnyFunction = FunctionLike<any, any>;\nexport type Nullish = undefined | null;\nexport type Nullishable<T> = T | Nullish;\nexport type NonNullishObject = object; // not null/undefined which are Object\nexport type NativeClass = abstract new (...args: any) => any;\nexport type AnyNumber = number | number;\nexport type AnyString = string | string;\nexport type AnyBoolean = boolean | boolean;\nexport type AnyArray = any[];\nexport type PlainObject = Record<any, object>; // https://stackoverflow.com/a/75052315/130638\nexport type AnyMap = Map<any, any>;\nexport type AnyWeakMap = WeakMap<WeakKey, any>;\nexport type EmptyArray = [];\nexport interface EmptyObject {\n [emptyObjectSymbol]?: never;\n}\n\nexport type Any =\n | boolean\n | number\n | bigint\n | string\n | null\n | undefined\n | void\n | symbol\n | object\n | PlainObject\n | AnyArray\n | AnyMap\n | AnyWeakMap;\n\n/**\n * The valid types of the index for an `Indexable` type object\n */\nexport type IndexType = string | number | symbol;\n\n/**\n * The declaration of a ***dictionary-type*** object with a specific type\n *\n * @see {@link Indexable}\n * @see {@link IndexType}\n * @see {@link Dictionary}\n */\nexport type TypedIndexable<T> = Record<IndexType, T>;\n\n/**\n * The declaration of a ***dictionary-type*** object\n *\n * @see {@link TypedIndexable}\n * @see {@link IndexType}\n * @see {@link Dictionary}\n */\nexport type Indexable = TypedIndexable<any>;\n\n/**\n * The declaration of a ***dictionary-type*** object with a specific type\n *\n * @see {@link Indexable}\n * @see {@link IndexType}\n * @see {@link TypedIndexable}\n */\nexport type Dictionary<T> = Record<string, T>;\n\nexport const EMPTY_STRING = \"\";\nexport const NEWLINE_STRING = \"\\r\\n\";\nexport const EMPTY_OBJECT = {};\n\nexport type AnyCase<T extends IndexType> = string extends T\n ? string\n : T extends `${infer F1}${infer F2}${infer R}`\n ? `${Uppercase<F1> | Lowercase<F1>}${Uppercase<F2> | Lowercase<F2>}${AnyCase<R>}`\n : T extends `${infer F}${infer R}`\n ? `${Uppercase<F> | Lowercase<F>}${AnyCase<R>}`\n : typeof EMPTY_STRING;\n\nexport type Newable<T> = new (..._args: never[]) => T;\n\nexport interface Abstract<T> {\n prototype: T;\n}\n\nexport interface Clonable<T> {\n clone: () => T;\n}\n\nexport type MaybePromise<T> = T | Promise<T>;\n\nexport type ReducerFunction<TState, TAction> = (\n state: TState,\n action: TAction\n) => TState;\n\n// NOTE: for the file size optimization\nexport const TYPE_ARGUMENTS = \"Arguments\";\nexport const TYPE_ARRAY = \"Array\";\nexport const TYPE_OBJECT = \"Object\";\nexport const TYPE_MAP = \"Map\";\nexport const TYPE_SET = \"Set\";\n\nexport type Collection =\n | IArguments\n | unknown[]\n | Map<unknown, unknown>\n | Record<string | number | symbol, unknown>\n | Set<unknown>;\n\nexport type NonUndefined<T> = T extends undefined ? never : T;\n\nexport type BrowserNativeObject = Date | File;\n\nexport type DeepPartial<T> = T extends BrowserNativeObject | NestedValue\n ? T\n : {\n [K in keyof T]?: DeepPartial<T[K]>;\n };\n\nexport type Rollback = Record<\n string,\n (initialValue: any, currentValue: any) => any\n>;\n\n/**\n * Extract all required keys from the given type.\n *\n * @remarks\n * This 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 */\nexport type RequiredKeysOf<BaseType extends object> = Exclude<\n {\n [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>\n ? Key\n : never;\n }[keyof BaseType],\n undefined\n>;\n\n/**\n * Returns a boolean for whether the two given types are equal.\n *\n * @remarks\n * Use-cases: If you want to make a conditional branch based on the result of a comparison of two types.\n *\n * @see https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650\n * @see https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796\n */\nexport type IsEqual<A, B> =\n (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B ? 1 : 2\n ? true\n : false;\n\nexport type Filter<KeyType, ExcludeType> =\n IsEqual<KeyType, ExcludeType> extends true\n ? never\n : KeyType extends ExcludeType\n ? never\n : KeyType;\n\ninterface ExceptOptions {\n /**\n Disallow assigning non-specified properties.\n\n Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.\n\n @defaultValue false\n */\n requireExactProps?: boolean;\n}\n\n/**\n * Create a type from an object type without certain keys.\n *\n * @remarks\n * We recommend setting the `requireExactProps` option to `true`.\n *\n * This 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 *\n * This 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 */\nexport type Except<\n ObjectType,\n KeysType extends keyof ObjectType,\n Options extends ExceptOptions = { requireExactProps: false }\n> = {\n [KeyType in keyof ObjectType as Filter<\n KeyType,\n KeysType\n >]: ObjectType[KeyType];\n} & (Options[\"requireExactProps\"] extends true\n ? Partial<Record<KeysType, never>>\n : Record<string, never>);\n\n/**\n * Useful 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 * @remarks\n * Sometimes 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 *\n * If 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 * @see https://github.com/microsoft/TypeScript/issues/15300\n */\nexport type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};\n\n/**\n * Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.\n *\n * @remarks\n * Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are required.\n */\nexport type SetRequired<\n BaseType,\n Keys extends keyof BaseType\n> = BaseType extends unknown // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types). // union into a [distributive conditional // `extends unknown` is always going to be the case and is used to convert any\n ? Simplify<\n // Pick just the keys that are optional from the base type.\n Except<BaseType, Keys> &\n // Pick the keys that should be required from the base type and make them required.\n Required<Pick<BaseType, Keys>>\n >\n : never;\n\nexport const $NestedValue: unique symbol = Symbol(\"NestedValue\");\n\nexport type NestedValue<TValue extends object = object> = {\n [$NestedValue]: never;\n} & TValue;\n\nexport interface RefObject<T> {\n current: T;\n}\n\nexport interface Identity<T = string> {\n id: T;\n}\n\nexport interface Versioned {\n version: number;\n}\n\nexport interface Sequenced {\n /**\n * The sequence number (version, or event counter, etc.) of the record\n */\n sequence: number;\n}\n\nexport interface Typed {\n /**\n * The type of the record\n */\n __type: string;\n}\n\nexport interface ClassTypeCheckable<T> extends Typed {\n /**\n * Run type check on the given value\n * @param value - The value to check\n * @returns True if the value is of the type of the class\n */\n isTypeOf: (value: unknown) => value is T;\n}\n\n/**\n * Matches non-recursive types.\n */\nexport type NonRecursiveType =\n | BuiltIns\n // eslint-disable-next-line ts/no-unsafe-function-type\n | Function\n | (new (...arguments_: any[]) => unknown);\n\nexport type IsPrimitive<T> = [T] extends [Primitive] ? true : false;\nexport type IsNever<T> = [T] extends [never] ? true : false;\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\nexport type IsNull<T> = [T] extends [null] ? true : false;\nexport type IsUndefined<T> = T extends undefined ? true : false;\nexport type IsUnknown<T> = unknown extends T // `T` can be `unknown` or `any`\n ? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be\n ? true\n : false\n : false;\nexport type IsNullish<T> = IsNull<T> & IsUndefined<T>;\nexport type IsFunction<T> = T extends AnyFunction ? true : false;\n\n/**\n * Declare locally scoped properties on `globalThis`.\n *\n * When defining a global variable in a declaration file is inappropriate, it can be helpful to define a `type` or `interface` (say `ExtraGlobals`) with the global variable and then cast `globalThis` via code like `globalThis as unknown as ExtraGlobals`.\n *\n * Instead of casting through `unknown`, you can update your `type` or `interface` to extend `GlobalThis` and then directly cast `globalThis`.\n *\n * @example\n * ```\n * import type { GlobalThis } from '@stryke/types';\n *\n * type ExtraGlobals = GlobalThis & {\n * readonly GLOBAL_TOKEN: string;\n * };\n *\n * (globalThis as ExtraGlobals).GLOBAL_TOKEN;\n * ```\n */\nexport type GlobalThis = typeof globalThis;\n\n/**\n * Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).\n */\nexport interface Class<T, Arguments extends unknown[] = any[]> {\n prototype: Pick<T, keyof T>;\n new (...arguments_: Arguments): T;\n}\n\n/**\n * Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).\n */\nexport type Constructor<T, Arguments extends unknown[] = any[]> = new (\n ...arguments_: Arguments\n) => T;\n\n/**\n * Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/classes.html#abstract-classes).\n *\n * @privateRemarks\n * We cannot use a `type` here because TypeScript throws: 'abstract' modifier cannot appear on a type member. (1070)\n */\n\nexport interface AbstractClass<\n T,\n Arguments extends unknown[] = any[]\n> extends AbstractConstructor<T, Arguments> {\n prototype: Pick<T, keyof T>;\n}\n\n/**\n * Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#abstract-construct-signatures) constructor.\n */\nexport type AbstractConstructor<\n T,\n Arguments extends unknown[] = any[]\n> = abstract new (...arguments_: Arguments) => T;\n\n/**\n * Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.\n *\n * If `<Fill>` is not provided, it will default to `unknown`.\n *\n * @see https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f\n */\nexport type BuildTuple<\n L extends number,\n Fill = unknown,\n T extends readonly unknown[] = []\n> = T[\"length\"] extends L ? T : BuildTuple<L, Fill, [...T, Fill]>;\n\n/**\n * Test if the given function has multiple call signatures.\n *\n * Needed to handle the case of a single call signature with properties.\n *\n * Multiple call signatures cannot currently be supported due to a TypeScript limitation.\n * @see https://github.com/microsoft/TypeScript/issues/29732\n */\nexport type HasMultipleCallSignatures<\n T extends (...arguments_: any[]) => unknown\n> = T extends {\n (...arguments_: infer A): unknown;\n (...arguments_: infer B): unknown;\n}\n ? B extends A\n ? A extends B\n ? false\n : true\n : true\n : false;\n\ntype StructuredCloneablePrimitive =\n | string\n | number\n | bigint\n | boolean\n | null\n | undefined\n | boolean\n | number\n | string;\n\ntype StructuredCloneableData =\n | ArrayBuffer\n | DataView\n | Date\n | Error\n | RegExp\n | TypedArray\n | Blob\n | File;\n\n// DOM exclusive types\n// | AudioData\n// | CropTarget\n// | CryptoKey\n// | DOMException\n// | DOMMatrix\n// | DOMMatrixReadOnly\n// | DOMPoint\n// | DOMPointReadOnly\n// | DOMQuad\n// | DOMRect\n// | DOMRectReadOnly\n// | FileList\n// | FileSystemDirectoryHandle\n// | FileSystemFileHandle\n// | FileSystemHandle\n// | GPUCompilationInfo\n// | GPUCompilationMessage\n// | ImageBitmap\n// | ImageData\n// | RTCCertificate\n// | VideoFrame\n\ntype StructuredCloneableCollection =\n | readonly StructuredCloneable[]\n | {\n readonly [key: string]: StructuredCloneable;\n readonly [key: number]: StructuredCloneable;\n }\n | ReadonlyMap<StructuredCloneable, StructuredCloneable>\n | ReadonlySet<StructuredCloneable>;\n\n/**\n * Matches a value that can be losslessly cloned using `structuredClone`.\n *\n * Note:\n * - Custom error types will be cloned as the base `Error` type\n * - This type doesn't include types exclusive to the TypeScript DOM library (e.g. `DOMRect` and `VideoFrame`)\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n *\n * @example\n * ```\n * import type { StructuredCloneable } from '@stryke/types';\n *\n * class CustomClass {}\n *\n * // @ts-expect-error\n * const error: StructuredCloneable = {\n * custom: new CustomClass(),\n * };\n *\n * structuredClone(error);\n * //=> {custom: {}}\n *\n * const good: StructuredCloneable = {\n * number: 3,\n * date: new Date(),\n * map: new Map<string, number>(),\n * }\n *\n * good.map.set('key', 1);\n *\n * structuredClone(good);\n * //=> {number: 3, date: Date(2022-10-17 22:22:35.920), map: Map {'key' -> 1}}\n * ```\n */\nexport type StructuredCloneable =\n | StructuredCloneablePrimitive\n | StructuredCloneableData\n | StructuredCloneableCollection;\n"],"mappings":"AAsJA,MAAa,EAAe"}
1
+ {"version":3,"file":"base.mjs","names":[],"sources":["../../../../types/src/base.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { TypedArray } from \"./array\";\n\nexport type SerializablePrimitive =\n | null\n | undefined\n | string\n | number\n | boolean\n | bigint;\nexport type Primitive = SerializablePrimitive | symbol;\n\n/**\n * Matches any primitive, `void`, `Date`, or `RegExp` value.\n */\nexport type BuiltIns = Primitive | void | Date | RegExp;\n\n/**\n * Matches any non-primitive object\n */\n// eslint-disable-next-line ts/no-unsafe-function-type\nexport type AtomicObject = Function | Promise<any> | Date | RegExp;\n\n/** Determines if the passed value is of a specific type */\nexport type TypeTester = (value: any) => boolean;\n\n/**\n * The interface for a type mapping (key =\\> function) to use for {@link getType}.\n * export * The key represents the name of the type. The function represents the {@link TypeTester | test method}.\n * The map should be ordered by testing preference, with more specific tests first.\n * If a test returns true, it is selected, and the key is returned as the type.\n */\nexport type TypeMap = Record<string, TypeTester>;\n\ndeclare const emptyObjectSymbol: unique symbol;\n\nexport type FunctionOrValue<Value> = Value extends () => infer X ? X : Value;\n\n/**\n * A [[List]]\n *\n * @example\n * ```ts\n * type list0 = [1, 2, 3]\n * type list1 = number[]\n * ```\n *\n * @param A - its type\n * @returns [[List]]\n */\nexport type List<A = any> = ReadonlyArray<A>;\n\n/**\n * Alias to create a [[Function]]\n *\n * @example\n * ```ts\n * import { FunctionLike } from '@stryke/types'\n *\n * type test0 = FunctionLike<[string, number], boolean>\n * /// (args_0: string, args_1: number) => boolean\n * ```\n *\n * @param P - parameters\n * @param R - return type\n * @returns [[Function]]\n */\nexport type FunctionLike<P extends List = any, R = any> = (...args: P) => R;\n\nexport type AnyFunction = FunctionLike<any, any>;\nexport type Nullish = undefined | null;\nexport type Nullishable<T> = T | Nullish;\nexport type NonNullishObject = object; // not null/undefined which are Object\nexport type NativeClass = abstract new (...args: any) => any;\nexport type AnyNumber = number | number;\nexport type AnyString = string | string;\nexport type AnyBoolean = boolean | boolean;\nexport type AnyArray = any[];\nexport type PlainObject = Record<any, object>; // https://stackoverflow.com/a/75052315/130638\nexport type AnyMap = Map<any, any>;\nexport type AnyWeakMap = WeakMap<WeakKey, any>;\nexport type EmptyArray = [];\nexport interface EmptyObject {\n [emptyObjectSymbol]?: never;\n}\n\nexport type Any =\n | boolean\n | number\n | bigint\n | string\n | null\n | undefined\n | void\n | symbol\n | object\n | PlainObject\n | AnyArray\n | AnyMap\n | AnyWeakMap;\n\n/**\n * The valid types of the index for an `Indexable` type object\n */\nexport type IndexType = string | number | symbol;\n\n/**\n * The declaration of a ***dictionary-type*** object with a specific type\n *\n * @see {@link Indexable}\n * @see {@link IndexType}\n * @see {@link Dictionary}\n */\nexport type TypedIndexable<T> = Record<IndexType, T>;\n\n/**\n * The declaration of a ***dictionary-type*** object\n *\n * @see {@link TypedIndexable}\n * @see {@link IndexType}\n * @see {@link Dictionary}\n */\nexport type Indexable = TypedIndexable<any>;\n\n/**\n * The declaration of a ***dictionary-type*** object with a specific type\n *\n * @see {@link Indexable}\n * @see {@link IndexType}\n * @see {@link TypedIndexable}\n */\nexport type Dictionary<T> = Record<string, T>;\n\nexport const EMPTY_STRING = \"\";\nexport const NEWLINE_STRING = \"\\r\\n\";\nexport const EMPTY_OBJECT = {};\n\nexport type AnyCase<T extends IndexType> = string extends T\n ? string\n : T extends `${infer F1}${infer F2}${infer R}`\n ? `${Uppercase<F1> | Lowercase<F1>}${Uppercase<F2> | Lowercase<F2>}${AnyCase<R>}`\n : T extends `${infer F}${infer R}`\n ? `${Uppercase<F> | Lowercase<F>}${AnyCase<R>}`\n : typeof EMPTY_STRING;\n\nexport type Newable<T> = new (..._args: never[]) => T;\n\nexport interface Abstract<T> {\n prototype: T;\n}\n\nexport interface Clonable<T> {\n clone: () => T;\n}\n\nexport type MaybePromise<T> = T | Promise<T>;\n\nexport type ReducerFunction<TState, TAction> = (\n state: TState,\n action: TAction\n) => TState;\n\n// NOTE: for the file size optimization\nexport const TYPE_ARGUMENTS = \"Arguments\";\nexport const TYPE_ARRAY = \"Array\";\nexport const TYPE_OBJECT = \"Object\";\nexport const TYPE_MAP = \"Map\";\nexport const TYPE_SET = \"Set\";\n\nexport type Collection =\n | IArguments\n | unknown[]\n | Map<unknown, unknown>\n | Record<string | number | symbol, unknown>\n | Set<unknown>;\n\nexport type NonUndefined<T> = T extends undefined ? never : T;\n\nexport type BrowserNativeObject = Date | File;\n\nexport type DeepPartial<T> = T extends BrowserNativeObject | NestedValue\n ? T\n : {\n [K in keyof T]?: DeepPartial<T[K]>;\n };\n\nexport type Rollback = Record<\n string,\n (initialValue: any, currentValue: any) => any\n>;\n\n/**\n * Extract all required keys from the given type.\n *\n * @remarks\n * This 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 */\nexport type RequiredKeysOf<BaseType extends object> = Exclude<\n {\n [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>\n ? Key\n : never;\n }[keyof BaseType],\n undefined\n>;\n\n/**\n * Returns a boolean for whether the two given types are equal.\n *\n * @remarks\n * Use-cases: If you want to make a conditional branch based on the result of a comparison of two types.\n *\n * @see https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650\n * @see https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796\n */\nexport type IsEqual<A, B> =\n (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B ? 1 : 2\n ? true\n : false;\n\nexport type Filter<KeyType, ExcludeType> =\n IsEqual<KeyType, ExcludeType> extends true\n ? never\n : KeyType extends ExcludeType\n ? never\n : KeyType;\n\ninterface ExceptOptions {\n /**\n Disallow assigning non-specified properties.\n\n Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.\n\n @defaultValue false\n */\n requireExactProps?: boolean;\n}\n\n/**\n * Create a type from an object type without certain keys.\n *\n * @remarks\n * We recommend setting the `requireExactProps` option to `true`.\n *\n * This 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 *\n * This 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 */\nexport type Except<\n ObjectType,\n KeysType extends keyof ObjectType,\n Options extends ExceptOptions = { requireExactProps: false }\n> = {\n [KeyType in keyof ObjectType as Filter<\n KeyType,\n KeysType\n >]: ObjectType[KeyType];\n} & (Options[\"requireExactProps\"] extends true\n ? Partial<Record<KeysType, never>>\n : Record<string, never>);\n\n/**\n * Useful 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 * @remarks\n * Sometimes 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 *\n * If 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 * @see https://github.com/microsoft/TypeScript/issues/15300\n */\nexport type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};\n\n/**\n * Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.\n *\n * @remarks\n * Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are required.\n */\nexport type SetRequired<\n BaseType,\n Keys extends keyof BaseType\n> = BaseType extends unknown // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types). // union into a [distributive conditional // `extends unknown` is always going to be the case and is used to convert any\n ? Simplify<\n // Pick just the keys that are optional from the base type.\n Except<BaseType, Keys> &\n // Pick the keys that should be required from the base type and make them required.\n Required<Pick<BaseType, Keys>>\n >\n : never;\n\nexport const $NestedValue: unique symbol = Symbol(\"NestedValue\");\n\nexport type NestedValue<TValue extends object = object> = {\n [$NestedValue]: never;\n} & TValue;\n\nexport interface RefObject<T> {\n current: T;\n}\n\nexport interface Identity<T = string> {\n id: T;\n}\n\nexport interface Versioned {\n version: number;\n}\n\nexport interface Sequenced {\n /**\n * The sequence number (version, or event counter, etc.) of the record\n */\n sequence: number;\n}\n\nexport interface Typed {\n /**\n * The type of the record\n */\n __type: string;\n}\n\nexport interface ClassTypeCheckable<T> extends Typed {\n /**\n * Run type check on the given value\n * @param value - The value to check\n * @returns True if the value is of the type of the class\n */\n isTypeOf: (value: unknown) => value is T;\n}\n\n/**\n * Matches non-recursive types.\n */\nexport type NonRecursiveType =\n | BuiltIns\n // eslint-disable-next-line ts/no-unsafe-function-type\n | Function\n | (new (...arguments_: any[]) => unknown);\n\nexport type IsPrimitive<T> = [T] extends [Primitive] ? true : false;\nexport type IsNever<T> = [T] extends [never] ? true : false;\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\nexport type IsNull<T> = [T] extends [null] ? true : false;\nexport type IsUndefined<T> = T extends undefined ? true : false;\nexport type IsUnknown<T> = unknown extends T // `T` can be `unknown` or `any`\n ? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be\n ? true\n : false\n : false;\nexport type IsNullish<T> = IsNull<T> & IsUndefined<T>;\nexport type IsFunction<T> = T extends AnyFunction ? true : false;\n\n/**\n * Declare locally scoped properties on `globalThis`.\n *\n * When defining a global variable in a declaration file is inappropriate, it can be helpful to define a `type` or `interface` (say `ExtraGlobals`) with the global variable and then cast `globalThis` via code like `globalThis as unknown as ExtraGlobals`.\n *\n * Instead of casting through `unknown`, you can update your `type` or `interface` to extend `GlobalThis` and then directly cast `globalThis`.\n *\n * @example\n * ```\n * import type { GlobalThis } from '@stryke/types';\n *\n * type ExtraGlobals = GlobalThis & {\n * readonly GLOBAL_TOKEN: string;\n * };\n *\n * (globalThis as ExtraGlobals).GLOBAL_TOKEN;\n * ```\n */\nexport type GlobalThis = typeof globalThis;\n\n/**\n * Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).\n */\nexport interface Class<T, Arguments extends unknown[] = any[]> {\n prototype: Pick<T, keyof T>;\n new (...arguments_: Arguments): T;\n}\n\n/**\n * Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).\n */\nexport type Constructor<T, Arguments extends unknown[] = any[]> = new (\n ...arguments_: Arguments\n) => T;\n\n/**\n * Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/classes.html#abstract-classes).\n *\n * @privateRemarks\n * We cannot use a `type` here because TypeScript throws: 'abstract' modifier cannot appear on a type member. (1070)\n */\n\nexport interface AbstractClass<\n T,\n Arguments extends unknown[] = any[]\n> extends AbstractConstructor<T, Arguments> {\n prototype: Pick<T, keyof T>;\n}\n\n/**\n * Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#abstract-construct-signatures) constructor.\n */\nexport type AbstractConstructor<\n T,\n Arguments extends unknown[] = any[]\n> = abstract new (...arguments_: Arguments) => T;\n\n/**\n * Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.\n *\n * If `<Fill>` is not provided, it will default to `unknown`.\n *\n * @see https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f\n */\nexport type BuildTuple<\n L extends number,\n Fill = unknown,\n T extends readonly unknown[] = []\n> = T[\"length\"] extends L ? T : BuildTuple<L, Fill, [...T, Fill]>;\n\n/**\n * Test if the given function has multiple call signatures.\n *\n * Needed to handle the case of a single call signature with properties.\n *\n * Multiple call signatures cannot currently be supported due to a TypeScript limitation.\n * @see https://github.com/microsoft/TypeScript/issues/29732\n */\nexport type HasMultipleCallSignatures<\n T extends (...arguments_: any[]) => unknown\n> = T extends {\n (...arguments_: infer A): unknown;\n (...arguments_: infer B): unknown;\n}\n ? B extends A\n ? A extends B\n ? false\n : true\n : true\n : false;\n\ntype StructuredCloneablePrimitive =\n | string\n | number\n | bigint\n | boolean\n | null\n | undefined\n | boolean\n | number\n | string;\n\ntype StructuredCloneableData =\n | ArrayBuffer\n | DataView\n | Date\n | Error\n | RegExp\n | TypedArray\n | Blob\n | File;\n\n// DOM exclusive types\n// | AudioData\n// | CropTarget\n// | CryptoKey\n// | DOMException\n// | DOMMatrix\n// | DOMMatrixReadOnly\n// | DOMPoint\n// | DOMPointReadOnly\n// | DOMQuad\n// | DOMRect\n// | DOMRectReadOnly\n// | FileList\n// | FileSystemDirectoryHandle\n// | FileSystemFileHandle\n// | FileSystemHandle\n// | GPUCompilationInfo\n// | GPUCompilationMessage\n// | ImageBitmap\n// | ImageData\n// | RTCCertificate\n// | VideoFrame\n\ntype StructuredCloneableCollection =\n | readonly StructuredCloneable[]\n | {\n readonly [key: string]: StructuredCloneable;\n readonly [key: number]: StructuredCloneable;\n }\n | ReadonlyMap<StructuredCloneable, StructuredCloneable>\n | ReadonlySet<StructuredCloneable>;\n\n/**\n * Matches a value that can be losslessly cloned using `structuredClone`.\n *\n * Note:\n * - Custom error types will be cloned as the base `Error` type\n * - This type doesn't include types exclusive to the TypeScript DOM library (e.g. `DOMRect` and `VideoFrame`)\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n *\n * @example\n * ```\n * import type { StructuredCloneable } from '@stryke/types';\n *\n * class CustomClass {}\n *\n * // @ts-expect-error\n * const error: StructuredCloneable = {\n * custom: new CustomClass(),\n * };\n *\n * structuredClone(error);\n * //=> {custom: {}}\n *\n * const good: StructuredCloneable = {\n * number: 3,\n * date: new Date(),\n * map: new Map<string, number>(),\n * }\n *\n * good.map.set('key', 1);\n *\n * structuredClone(good);\n * //=> {number: 3, date: Date(2022-10-17 22:22:35.920), map: Map {'key' -> 1}}\n * ```\n */\nexport type StructuredCloneable =\n | StructuredCloneablePrimitive\n | StructuredCloneableData\n | StructuredCloneableCollection;\n"],"mappings":";AAsJA,MAAa,eAAe"}
@@ -1 +1,60 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./type-checks/src/is-function.cjs`);let n=require(`react`);n=e.__toESM(n);const r={supported:!0,loading:!0,level:null,charging:null,chargingTime:null,dischargingTime:null};function i(){let[e,i]=n.default.useState(r),a=navigator.getBattery;return(0,n.useEffect)(()=>{if(!t.isFunction(a)){i(e=>({...e,supported:!1,loading:!1}));return}let e=null,n=()=>{i({...r,supported:!0,loading:!1,...e})};return a().then(t=>{e=t,n(),t?.addEventListener(`levelchange`,n),t?.addEventListener(`chargingchange`,n),t?.addEventListener(`chargingtimechange`,n),t?.addEventListener(`dischargingtimechange`,n)}),()=>{e&&(e.removeEventListener(`levelchange`,n),e.removeEventListener(`chargingchange`,n),e.removeEventListener(`chargingtimechange`,n),e.removeEventListener(`dischargingtimechange`,n))}},[a]),e}exports.useBattery=i;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_is_function = require('./type-checks/src/is-function.cjs');
3
+ let react = require("react");
4
+ react = require_rolldown_runtime.__toESM(react);
5
+
6
+ //#region src/use-battery.ts
7
+ const defaultBatteryManagerState = {
8
+ supported: true,
9
+ loading: true,
10
+ level: null,
11
+ charging: null,
12
+ chargingTime: null,
13
+ dischargingTime: null
14
+ };
15
+ /**
16
+ * Listens for updates to the mobile/desktop battery status
17
+ */
18
+ function useBattery() {
19
+ const [state, setState] = react.default.useState(defaultBatteryManagerState);
20
+ const getBattery = navigator["getBattery"];
21
+ (0, react.useEffect)(() => {
22
+ if (!require_is_function.isFunction(getBattery)) {
23
+ setState((s) => ({
24
+ ...s,
25
+ supported: false,
26
+ loading: false
27
+ }));
28
+ return;
29
+ }
30
+ let battery = null;
31
+ const handleChange = () => {
32
+ setState({
33
+ ...defaultBatteryManagerState,
34
+ supported: true,
35
+ loading: false,
36
+ ...battery
37
+ });
38
+ };
39
+ getBattery().then((b) => {
40
+ battery = b;
41
+ handleChange();
42
+ b?.addEventListener("levelchange", handleChange);
43
+ b?.addEventListener("chargingchange", handleChange);
44
+ b?.addEventListener("chargingtimechange", handleChange);
45
+ b?.addEventListener("dischargingtimechange", handleChange);
46
+ });
47
+ return () => {
48
+ if (battery) {
49
+ battery.removeEventListener("levelchange", handleChange);
50
+ battery.removeEventListener("chargingchange", handleChange);
51
+ battery.removeEventListener("chargingtimechange", handleChange);
52
+ battery.removeEventListener("dischargingtimechange", handleChange);
53
+ }
54
+ };
55
+ }, [getBattery]);
56
+ return state;
57
+ }
58
+
59
+ //#endregion
60
+ exports.useBattery = useBattery;
@@ -1,2 +1,59 @@
1
- import{isFunction as e}from"./type-checks/src/is-function.mjs";import t,{useEffect as n}from"react";const r={supported:!0,loading:!0,level:null,charging:null,chargingTime:null,dischargingTime:null};function i(){let[i,a]=t.useState(r),o=navigator.getBattery;return n(()=>{if(!e(o)){a(e=>({...e,supported:!1,loading:!1}));return}let t=null,n=()=>{a({...r,supported:!0,loading:!1,...t})};return o().then(e=>{t=e,n(),e?.addEventListener(`levelchange`,n),e?.addEventListener(`chargingchange`,n),e?.addEventListener(`chargingtimechange`,n),e?.addEventListener(`dischargingtimechange`,n)}),()=>{t&&(t.removeEventListener(`levelchange`,n),t.removeEventListener(`chargingchange`,n),t.removeEventListener(`chargingtimechange`,n),t.removeEventListener(`dischargingtimechange`,n))}},[o]),i}export{i as useBattery};
1
+ import { isFunction } from "./type-checks/src/is-function.mjs";
2
+ import React, { useEffect } from "react";
3
+
4
+ //#region src/use-battery.ts
5
+ const defaultBatteryManagerState = {
6
+ supported: true,
7
+ loading: true,
8
+ level: null,
9
+ charging: null,
10
+ chargingTime: null,
11
+ dischargingTime: null
12
+ };
13
+ /**
14
+ * Listens for updates to the mobile/desktop battery status
15
+ */
16
+ function useBattery() {
17
+ const [state, setState] = React.useState(defaultBatteryManagerState);
18
+ const getBattery = navigator["getBattery"];
19
+ useEffect(() => {
20
+ if (!isFunction(getBattery)) {
21
+ setState((s) => ({
22
+ ...s,
23
+ supported: false,
24
+ loading: false
25
+ }));
26
+ return;
27
+ }
28
+ let battery = null;
29
+ const handleChange = () => {
30
+ setState({
31
+ ...defaultBatteryManagerState,
32
+ supported: true,
33
+ loading: false,
34
+ ...battery
35
+ });
36
+ };
37
+ getBattery().then((b) => {
38
+ battery = b;
39
+ handleChange();
40
+ b?.addEventListener("levelchange", handleChange);
41
+ b?.addEventListener("chargingchange", handleChange);
42
+ b?.addEventListener("chargingtimechange", handleChange);
43
+ b?.addEventListener("dischargingtimechange", handleChange);
44
+ });
45
+ return () => {
46
+ if (battery) {
47
+ battery.removeEventListener("levelchange", handleChange);
48
+ battery.removeEventListener("chargingchange", handleChange);
49
+ battery.removeEventListener("chargingtimechange", handleChange);
50
+ battery.removeEventListener("dischargingtimechange", handleChange);
51
+ }
52
+ };
53
+ }, [getBattery]);
54
+ return state;
55
+ }
56
+
57
+ //#endregion
58
+ export { useBattery };
2
59
  //# sourceMappingURL=use-battery.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-battery.mjs","names":[],"sources":["../src/use-battery.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport type { BatteryManager } from \"@stryke/types/navigator\";\nimport React, { useEffect } from \"react\";\n\nconst defaultBatteryManagerState = {\n supported: true,\n loading: true,\n level: null,\n charging: null,\n chargingTime: null,\n dischargingTime: null\n};\n\n/**\n * Listens for updates to the mobile/desktop battery status\n */\nexport function useBattery() {\n const [state, setState] = React.useState<\n Omit<BatteryManager, \"addEventListener\" | \"removeEventListener\">\n >(defaultBatteryManagerState);\n\n const key = \"getBattery\" as keyof typeof navigator;\n const getBattery = navigator[key] as () => Promise<BatteryManager>;\n\n useEffect(() => {\n if (!isFunction(getBattery)) {\n setState(s => ({\n ...s,\n supported: false,\n loading: false\n }));\n return;\n }\n\n let battery = null as BatteryManager | null;\n\n const handleChange = () => {\n setState({\n ...defaultBatteryManagerState,\n supported: true,\n loading: false,\n ...battery\n });\n };\n\n void getBattery().then(b => {\n battery = b;\n handleChange();\n\n b?.addEventListener(\"levelchange\", handleChange);\n b?.addEventListener(\"chargingchange\", handleChange);\n b?.addEventListener(\"chargingtimechange\", handleChange);\n b?.addEventListener(\"dischargingtimechange\", handleChange);\n });\n\n return () => {\n if (battery) {\n battery.removeEventListener(\"levelchange\", handleChange);\n battery.removeEventListener(\"chargingchange\", handleChange);\n battery.removeEventListener(\"chargingtimechange\", handleChange);\n battery.removeEventListener(\"dischargingtimechange\", handleChange);\n }\n };\n }, [getBattery]);\n\n return state;\n}\n"],"mappings":"oGAsBA,MAAM,EAA6B,CACjC,UAAW,GACX,QAAS,GACT,MAAO,KACP,SAAU,KACV,aAAc,KACd,gBAAiB,KAClB,CAKD,SAAgB,GAAa,CAC3B,GAAM,CAAC,EAAO,GAAY,EAAM,SAE9B,EAA2B,CAGvB,EAAa,UADP,WA4CZ,OAzCA,MAAgB,CACd,GAAI,CAAC,EAAW,EAAW,CAAE,CAC3B,EAAS,IAAM,CACb,GAAG,EACH,UAAW,GACX,QAAS,GACV,EAAE,CACH,OAGF,IAAI,EAAU,KAER,MAAqB,CACzB,EAAS,CACP,GAAG,EACH,UAAW,GACX,QAAS,GACT,GAAG,EACJ,CAAC,EAaJ,OAVK,GAAY,CAAC,KAAK,GAAK,CAC1B,EAAU,EACV,GAAc,CAEd,GAAG,iBAAiB,cAAe,EAAa,CAChD,GAAG,iBAAiB,iBAAkB,EAAa,CACnD,GAAG,iBAAiB,qBAAsB,EAAa,CACvD,GAAG,iBAAiB,wBAAyB,EAAa,EAC1D,KAEW,CACP,IACF,EAAQ,oBAAoB,cAAe,EAAa,CACxD,EAAQ,oBAAoB,iBAAkB,EAAa,CAC3D,EAAQ,oBAAoB,qBAAsB,EAAa,CAC/D,EAAQ,oBAAoB,wBAAyB,EAAa,IAGrE,CAAC,EAAW,CAAC,CAET"}
1
+ {"version":3,"file":"use-battery.mjs","names":[],"sources":["../src/use-battery.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport type { BatteryManager } from \"@stryke/types/navigator\";\nimport React, { useEffect } from \"react\";\n\nconst defaultBatteryManagerState = {\n supported: true,\n loading: true,\n level: null,\n charging: null,\n chargingTime: null,\n dischargingTime: null\n};\n\n/**\n * Listens for updates to the mobile/desktop battery status\n */\nexport function useBattery() {\n const [state, setState] = React.useState<\n Omit<BatteryManager, \"addEventListener\" | \"removeEventListener\">\n >(defaultBatteryManagerState);\n\n const key = \"getBattery\" as keyof typeof navigator;\n const getBattery = navigator[key] as () => Promise<BatteryManager>;\n\n useEffect(() => {\n if (!isFunction(getBattery)) {\n setState(s => ({\n ...s,\n supported: false,\n loading: false\n }));\n return;\n }\n\n let battery = null as BatteryManager | null;\n\n const handleChange = () => {\n setState({\n ...defaultBatteryManagerState,\n supported: true,\n loading: false,\n ...battery\n });\n };\n\n void getBattery().then(b => {\n battery = b;\n handleChange();\n\n b?.addEventListener(\"levelchange\", handleChange);\n b?.addEventListener(\"chargingchange\", handleChange);\n b?.addEventListener(\"chargingtimechange\", handleChange);\n b?.addEventListener(\"dischargingtimechange\", handleChange);\n });\n\n return () => {\n if (battery) {\n battery.removeEventListener(\"levelchange\", handleChange);\n battery.removeEventListener(\"chargingchange\", handleChange);\n battery.removeEventListener(\"chargingtimechange\", handleChange);\n battery.removeEventListener(\"dischargingtimechange\", handleChange);\n }\n };\n }, [getBattery]);\n\n return state;\n}\n"],"mappings":";;;;AAsBA,MAAM,6BAA6B;CACjC,WAAW;CACX,SAAS;CACT,OAAO;CACP,UAAU;CACV,cAAc;CACd,iBAAiB;CAClB;;;;AAKD,SAAgB,aAAa;CAC3B,MAAM,CAAC,OAAO,YAAY,MAAM,SAE9B,2BAA2B;CAG7B,MAAM,aAAa,UADP;AAGZ,iBAAgB;AACd,MAAI,CAAC,WAAW,WAAW,EAAE;AAC3B,aAAS,OAAM;IACb,GAAG;IACH,WAAW;IACX,SAAS;IACV,EAAE;AACH;;EAGF,IAAI,UAAU;EAEd,MAAM,qBAAqB;AACzB,YAAS;IACP,GAAG;IACH,WAAW;IACX,SAAS;IACT,GAAG;IACJ,CAAC;;AAGJ,EAAK,YAAY,CAAC,MAAK,MAAK;AAC1B,aAAU;AACV,iBAAc;AAEd,MAAG,iBAAiB,eAAe,aAAa;AAChD,MAAG,iBAAiB,kBAAkB,aAAa;AACnD,MAAG,iBAAiB,sBAAsB,aAAa;AACvD,MAAG,iBAAiB,yBAAyB,aAAa;IAC1D;AAEF,eAAa;AACX,OAAI,SAAS;AACX,YAAQ,oBAAoB,eAAe,aAAa;AACxD,YAAQ,oBAAoB,kBAAkB,aAAa;AAC3D,YAAQ,oBAAoB,sBAAsB,aAAa;AAC/D,YAAQ,oBAAoB,yBAAyB,aAAa;;;IAGrE,CAAC,WAAW,CAAC;AAEhB,QAAO"}
@@ -1 +1,18 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`react`);function n(e){let n=(0,t.useRef)(e);return(0,t.useEffect)(()=>{n.current=e}),(0,t.useMemo)(()=>((...e)=>n.current?.(...e)),[])}exports.useCallbackRef=n;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let react = require("react");
3
+
4
+ //#region src/use-callback-ref.ts
5
+ /**
6
+ * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
7
+ * prop or avoid re-executing effects when passed as a dependency
8
+ */
9
+ function useCallbackRef(callback) {
10
+ const callbackRef = (0, react.useRef)(callback);
11
+ (0, react.useEffect)(() => {
12
+ callbackRef.current = callback;
13
+ });
14
+ return (0, react.useMemo)(() => ((...args) => callbackRef.current?.(...args)), []);
15
+ }
16
+
17
+ //#endregion
18
+ exports.useCallbackRef = useCallbackRef;
@@ -1,2 +1,18 @@
1
- import{useEffect as e,useMemo as t,useRef as n}from"react";function r(r){let i=n(r);return e(()=>{i.current=r}),t(()=>((...e)=>i.current?.(...e)),[])}export{r as useCallbackRef};
1
+ import { useEffect, useMemo, useRef } from "react";
2
+
3
+ //#region src/use-callback-ref.ts
4
+ /**
5
+ * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
6
+ * prop or avoid re-executing effects when passed as a dependency
7
+ */
8
+ function useCallbackRef(callback) {
9
+ const callbackRef = useRef(callback);
10
+ useEffect(() => {
11
+ callbackRef.current = callback;
12
+ });
13
+ return useMemo(() => ((...args) => callbackRef.current?.(...args)), []);
14
+ }
15
+
16
+ //#endregion
17
+ export { useCallbackRef };
2
18
  //# sourceMappingURL=use-callback-ref.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-callback-ref.mjs","names":[],"sources":["../src/use-callback-ref.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useEffect, useMemo, useRef } from \"react\";\n\n/**\n * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a\n * prop or avoid re-executing effects when passed as a dependency\n */\nexport function useCallbackRef<T extends (...args: any[]) => any>(\n callback: T | undefined\n): T {\n const callbackRef = useRef(callback);\n\n useEffect(() => {\n callbackRef.current = callback;\n });\n\n // https://github.com/facebook/react/issues/19240\n return useMemo(() => ((...args) => callbackRef.current?.(...args)) as T, []);\n}\n"],"mappings":"2DAwBA,SAAgB,EACd,EACG,CACH,IAAM,EAAc,EAAO,EAAS,CAOpC,OALA,MAAgB,CACd,EAAY,QAAU,GACtB,CAGK,QAAgB,GAAG,IAAS,EAAY,UAAU,GAAG,EAAK,EAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"use-callback-ref.mjs","names":[],"sources":["../src/use-callback-ref.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useEffect, useMemo, useRef } from \"react\";\n\n/**\n * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a\n * prop or avoid re-executing effects when passed as a dependency\n */\nexport function useCallbackRef<T extends (...args: any[]) => any>(\n callback: T | undefined\n): T {\n const callbackRef = useRef(callback);\n\n useEffect(() => {\n callbackRef.current = callback;\n });\n\n // https://github.com/facebook/react/issues/19240\n return useMemo(() => ((...args) => callbackRef.current?.(...args)) as T, []);\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,eACd,UACG;CACH,MAAM,cAAc,OAAO,SAAS;AAEpC,iBAAgB;AACd,cAAY,UAAU;GACtB;AAGF,QAAO,gBAAgB,GAAG,SAAS,YAAY,UAAU,GAAG,KAAK,GAAQ,EAAE,CAAC"}
@@ -1 +1,26 @@
1
- const e=require(`./use-memo-stable.cjs`);function t(t,n){return e.useMemoStable(()=>t,n)}exports.useCallbackStable=t;
1
+ const require_use_memo_stable = require('./use-memo-stable.cjs');
2
+
3
+ //#region src/use-callback-stable.ts
4
+ /**
5
+ * Forked from use-memo-one by Alex Reardon
6
+ */
7
+ /**
8
+ * `useMemo` and `useCallback` cache the most recent result. However, this cache can be destroyed by React when it wants to.
9
+ *
10
+ * `useMemoStable` and `useCallbackStable` are concurrent mode safe alternatives to `useMemo` and `useCallback` that do provide semantic guarantee. What this means is that you will always get the same reference for a memoized value so long as there is no input change.
11
+ *
12
+ * Using `useMemoStable` and `useCallbackStable` will consume more memory than useMemo and `useCallback` in order to provide a stable cache. React can release the cache of `useMemo` and `useCallback`, but `useMemoStable` will not release the cache until it is garbage collected.
13
+ *
14
+ * @remarks
15
+ * You may rely on useMemo as a performance optimization, not as a semantic guarantee. In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without `useMemo` — and then add it to optimize performance.
16
+ *
17
+ * @param callback - The callback function to memoize
18
+ * @param inputs - The inputs to watch for changes
19
+ * @returns The memoized callback function
20
+ */
21
+ function useCallbackStable(callback, inputs) {
22
+ return require_use_memo_stable.useMemoStable(() => callback, inputs);
23
+ }
24
+
25
+ //#endregion
26
+ exports.useCallbackStable = useCallbackStable;
@@ -1,2 +1,27 @@
1
- import{useMemoStable as e}from"./use-memo-stable.mjs";function t(t,n){return e(()=>t,n)}export{t as useCallbackStable};
1
+ import { useMemoStable } from "./use-memo-stable.mjs";
2
+
3
+ //#region src/use-callback-stable.ts
4
+ /**
5
+ * Forked from use-memo-one by Alex Reardon
6
+ */
7
+ /**
8
+ * `useMemo` and `useCallback` cache the most recent result. However, this cache can be destroyed by React when it wants to.
9
+ *
10
+ * `useMemoStable` and `useCallbackStable` are concurrent mode safe alternatives to `useMemo` and `useCallback` that do provide semantic guarantee. What this means is that you will always get the same reference for a memoized value so long as there is no input change.
11
+ *
12
+ * Using `useMemoStable` and `useCallbackStable` will consume more memory than useMemo and `useCallback` in order to provide a stable cache. React can release the cache of `useMemo` and `useCallback`, but `useMemoStable` will not release the cache until it is garbage collected.
13
+ *
14
+ * @remarks
15
+ * You may rely on useMemo as a performance optimization, not as a semantic guarantee. In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without `useMemo` — and then add it to optimize performance.
16
+ *
17
+ * @param callback - The callback function to memoize
18
+ * @param inputs - The inputs to watch for changes
19
+ * @returns The memoized callback function
20
+ */
21
+ function useCallbackStable(callback, inputs) {
22
+ return useMemoStable(() => callback, inputs);
23
+ }
24
+
25
+ //#endregion
26
+ export { useCallbackStable };
2
27
  //# sourceMappingURL=use-callback-stable.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-callback-stable.mjs","names":[],"sources":["../src/use-callback-stable.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { AnyFunction } from \"@stryke/types/base\";\nimport { useMemoStable } from \"./use-memo-stable\";\n\n/**\n * Forked from use-memo-one by Alex Reardon\n */\n\n/**\n * `useMemo` and `useCallback` cache the most recent result. However, this cache can be destroyed by React when it wants to.\n *\n * `useMemoStable` and `useCallbackStable` are concurrent mode safe alternatives to `useMemo` and `useCallback` that do provide semantic guarantee. What this means is that you will always get the same reference for a memoized value so long as there is no input change.\n *\n * Using `useMemoStable` and `useCallbackStable` will consume more memory than useMemo and `useCallback` in order to provide a stable cache. React can release the cache of `useMemo` and `useCallback`, but `useMemoStable` will not release the cache until it is garbage collected.\n *\n * @remarks\n * You may rely on useMemo as a performance optimization, not as a semantic guarantee. In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without `useMemo` — and then add it to optimize performance.\n *\n * @param callback - The callback function to memoize\n * @param inputs - The inputs to watch for changes\n * @returns The memoized callback function\n */\nexport function useCallbackStable<TCallback extends AnyFunction = AnyFunction>(\n callback: TCallback,\n inputs?: any[]\n): TCallback {\n return useMemoStable(() => callback, inputs);\n}\n"],"mappings":"sDAuCA,SAAgB,EACd,EACA,EACW,CACX,OAAO,MAAoB,EAAU,EAAO"}
1
+ {"version":3,"file":"use-callback-stable.mjs","names":[],"sources":["../src/use-callback-stable.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { AnyFunction } from \"@stryke/types/base\";\nimport { useMemoStable } from \"./use-memo-stable\";\n\n/**\n * Forked from use-memo-one by Alex Reardon\n */\n\n/**\n * `useMemo` and `useCallback` cache the most recent result. However, this cache can be destroyed by React when it wants to.\n *\n * `useMemoStable` and `useCallbackStable` are concurrent mode safe alternatives to `useMemo` and `useCallback` that do provide semantic guarantee. What this means is that you will always get the same reference for a memoized value so long as there is no input change.\n *\n * Using `useMemoStable` and `useCallbackStable` will consume more memory than useMemo and `useCallback` in order to provide a stable cache. React can release the cache of `useMemo` and `useCallback`, but `useMemoStable` will not release the cache until it is garbage collected.\n *\n * @remarks\n * You may rely on useMemo as a performance optimization, not as a semantic guarantee. In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without `useMemo` — and then add it to optimize performance.\n *\n * @param callback - The callback function to memoize\n * @param inputs - The inputs to watch for changes\n * @returns The memoized callback function\n */\nexport function useCallbackStable<TCallback extends AnyFunction = AnyFunction>(\n callback: TCallback,\n inputs?: any[]\n): TCallback {\n return useMemoStable(() => callback, inputs);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,kBACd,UACA,QACW;AACX,QAAO,oBAAoB,UAAU,OAAO"}
@@ -1 +1,33 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`react`);function n(e){let n=(0,t.useRef)(null),r=(0,t.useRef)(e);return(0,t.useLayoutEffect)(()=>{r.current=e}),(0,t.useEffect)(()=>{let e=e=>{let t=n.current;t&&!t.contains(e.target)&&r.current(e)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[]),n}exports.useClickAway=n;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let react = require("react");
3
+
4
+ //#region src/use-click-away.ts
5
+ /**
6
+ * Listens for when a click is away from the element
7
+ *
8
+ * @param cb - Callback function
9
+ * @returns A Ref object
10
+ */
11
+ function useClickAway(cb) {
12
+ const ref = (0, react.useRef)(null);
13
+ const refCb = (0, react.useRef)(cb);
14
+ (0, react.useLayoutEffect)(() => {
15
+ refCb.current = cb;
16
+ });
17
+ (0, react.useEffect)(() => {
18
+ const handler = (e) => {
19
+ const element = ref.current;
20
+ if (element && !element.contains(e.target)) refCb.current(e);
21
+ };
22
+ document.addEventListener("mousedown", handler);
23
+ document.addEventListener("touchstart", handler);
24
+ return () => {
25
+ document.removeEventListener("mousedown", handler);
26
+ document.removeEventListener("touchstart", handler);
27
+ };
28
+ }, []);
29
+ return ref;
30
+ }
31
+
32
+ //#endregion
33
+ exports.useClickAway = useClickAway;
@@ -1,2 +1,33 @@
1
- import{useEffect as e,useLayoutEffect as t,useRef as n}from"react";function r(r){let i=n(null),a=n(r);return t(()=>{a.current=r}),e(()=>{let e=e=>{let t=i.current;t&&!t.contains(e.target)&&a.current(e)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[]),i}export{r as useClickAway};
1
+ import { useEffect, useLayoutEffect, useRef } from "react";
2
+
3
+ //#region src/use-click-away.ts
4
+ /**
5
+ * Listens for when a click is away from the element
6
+ *
7
+ * @param cb - Callback function
8
+ * @returns A Ref object
9
+ */
10
+ function useClickAway(cb) {
11
+ const ref = useRef(null);
12
+ const refCb = useRef(cb);
13
+ useLayoutEffect(() => {
14
+ refCb.current = cb;
15
+ });
16
+ useEffect(() => {
17
+ const handler = (e) => {
18
+ const element = ref.current;
19
+ if (element && !element.contains(e.target)) refCb.current(e);
20
+ };
21
+ document.addEventListener("mousedown", handler);
22
+ document.addEventListener("touchstart", handler);
23
+ return () => {
24
+ document.removeEventListener("mousedown", handler);
25
+ document.removeEventListener("touchstart", handler);
26
+ };
27
+ }, []);
28
+ return ref;
29
+ }
30
+
31
+ //#endregion
32
+ export { useClickAway };
2
33
  //# sourceMappingURL=use-click-away.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-click-away.mjs","names":[],"sources":["../src/use-click-away.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useEffect, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Listens for when a click is away from the element\n *\n * @param cb - Callback function\n * @returns A Ref object\n */\nexport function useClickAway(cb: any) {\n const ref = useRef<HTMLElement | null>(null);\n const refCb = useRef(cb);\n\n useLayoutEffect(() => {\n refCb.current = cb;\n });\n\n useEffect(() => {\n const handler = (e: { target: any }) => {\n const element = ref.current;\n if (element && !element.contains(e.target)) {\n // eslint-disable-next-line ts/no-unsafe-call\n refCb.current(e);\n }\n };\n\n document.addEventListener(\"mousedown\", handler);\n document.addEventListener(\"touchstart\", handler);\n\n return () => {\n document.removeEventListener(\"mousedown\", handler);\n document.removeEventListener(\"touchstart\", handler);\n };\n }, []);\n\n return ref;\n}\n"],"mappings":"mEA0BA,SAAgB,EAAa,EAAS,CACpC,IAAM,EAAM,EAA2B,KAAK,CACtC,EAAQ,EAAO,EAAG,CAwBxB,OAtBA,MAAsB,CACpB,EAAM,QAAU,GAChB,CAEF,MAAgB,CACd,IAAM,EAAW,GAAuB,CACtC,IAAM,EAAU,EAAI,QAChB,GAAW,CAAC,EAAQ,SAAS,EAAE,OAAO,EAExC,EAAM,QAAQ,EAAE,EAOpB,OAHA,SAAS,iBAAiB,YAAa,EAAQ,CAC/C,SAAS,iBAAiB,aAAc,EAAQ,KAEnC,CACX,SAAS,oBAAoB,YAAa,EAAQ,CAClD,SAAS,oBAAoB,aAAc,EAAQ,GAEpD,EAAE,CAAC,CAEC"}
1
+ {"version":3,"file":"use-click-away.mjs","names":[],"sources":["../src/use-click-away.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useEffect, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Listens for when a click is away from the element\n *\n * @param cb - Callback function\n * @returns A Ref object\n */\nexport function useClickAway(cb: any) {\n const ref = useRef<HTMLElement | null>(null);\n const refCb = useRef(cb);\n\n useLayoutEffect(() => {\n refCb.current = cb;\n });\n\n useEffect(() => {\n const handler = (e: { target: any }) => {\n const element = ref.current;\n if (element && !element.contains(e.target)) {\n // eslint-disable-next-line ts/no-unsafe-call\n refCb.current(e);\n }\n };\n\n document.addEventListener(\"mousedown\", handler);\n document.addEventListener(\"touchstart\", handler);\n\n return () => {\n document.removeEventListener(\"mousedown\", handler);\n document.removeEventListener(\"touchstart\", handler);\n };\n }, []);\n\n return ref;\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAgB,aAAa,IAAS;CACpC,MAAM,MAAM,OAA2B,KAAK;CAC5C,MAAM,QAAQ,OAAO,GAAG;AAExB,uBAAsB;AACpB,QAAM,UAAU;GAChB;AAEF,iBAAgB;EACd,MAAM,WAAW,MAAuB;GACtC,MAAM,UAAU,IAAI;AACpB,OAAI,WAAW,CAAC,QAAQ,SAAS,EAAE,OAAO,CAExC,OAAM,QAAQ,EAAE;;AAIpB,WAAS,iBAAiB,aAAa,QAAQ;AAC/C,WAAS,iBAAiB,cAAc,QAAQ;AAEhD,eAAa;AACX,YAAS,oBAAoB,aAAa,QAAQ;AAClD,YAAS,oBAAoB,cAAc,QAAQ;;IAEpD,EAAE,CAAC;AAEN,QAAO"}
@@ -1 +1,43 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./type-checks/src/is-function.cjs`);let n=require(`react`);function r(e,n){e&&(t.isFunction(e)?e(n):e.current=n)}function i(...e){return t=>{for(let n of e)r(n,t)}}function a(...e){return(0,n.useCallback)(i(...e),e)}exports.composeRefs=i,exports.setRef=r,exports.useComposedRefs=a;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_is_function = require('./type-checks/src/is-function.cjs');
3
+ let react = require("react");
4
+
5
+ //#region src/use-compose-refs.ts
6
+ /**
7
+ * Set a given ref to a given value
8
+ * This utility takes care of different types of refs: callback refs and RefObject(s)
9
+ *
10
+ * @param ref - The ref to set
11
+ * @param value - The value to set the ref to
12
+ */
13
+ function setRef(ref, value) {
14
+ if (ref) if (require_is_function.isFunction(ref)) ref(value);
15
+ else ref.current = value;
16
+ }
17
+ /**
18
+ * A utility to compose multiple refs together
19
+ * Accepts callback refs and RefObject(s)
20
+ *
21
+ * @param refs - The refs to compose
22
+ * @returns A function that sets all refs to a given value
23
+ */
24
+ function composeRefs(...refs) {
25
+ return (node) => {
26
+ for (const ref of refs) setRef(ref, node);
27
+ };
28
+ }
29
+ /**
30
+ * A custom hook that composes multiple refs
31
+ * Accepts callback refs and RefObject(s)
32
+ *
33
+ * @param refs - The refs to compose
34
+ * @returns A function that sets all refs to a given value
35
+ */
36
+ function useComposedRefs(...refs) {
37
+ return (0, react.useCallback)(composeRefs(...refs), refs);
38
+ }
39
+
40
+ //#endregion
41
+ exports.composeRefs = composeRefs;
42
+ exports.setRef = setRef;
43
+ exports.useComposedRefs = useComposedRefs;
@@ -1,2 +1,41 @@
1
- import{isFunction as e}from"./type-checks/src/is-function.mjs";import{useCallback as t}from"react";function n(t,n){t&&(e(t)?t(n):t.current=n)}function r(...e){return t=>{for(let r of e)n(r,t)}}function i(...e){return t(r(...e),e)}export{r as composeRefs,n as setRef,i as useComposedRefs};
1
+ import { isFunction } from "./type-checks/src/is-function.mjs";
2
+ import { useCallback } from "react";
3
+
4
+ //#region src/use-compose-refs.ts
5
+ /**
6
+ * Set a given ref to a given value
7
+ * This utility takes care of different types of refs: callback refs and RefObject(s)
8
+ *
9
+ * @param ref - The ref to set
10
+ * @param value - The value to set the ref to
11
+ */
12
+ function setRef(ref, value) {
13
+ if (ref) if (isFunction(ref)) ref(value);
14
+ else ref.current = value;
15
+ }
16
+ /**
17
+ * A utility to compose multiple refs together
18
+ * Accepts callback refs and RefObject(s)
19
+ *
20
+ * @param refs - The refs to compose
21
+ * @returns A function that sets all refs to a given value
22
+ */
23
+ function composeRefs(...refs) {
24
+ return (node) => {
25
+ for (const ref of refs) setRef(ref, node);
26
+ };
27
+ }
28
+ /**
29
+ * A custom hook that composes multiple refs
30
+ * Accepts callback refs and RefObject(s)
31
+ *
32
+ * @param refs - The refs to compose
33
+ * @returns A function that sets all refs to a given value
34
+ */
35
+ function useComposedRefs(...refs) {
36
+ return useCallback(composeRefs(...refs), refs);
37
+ }
38
+
39
+ //#endregion
40
+ export { composeRefs, setRef, useComposedRefs };
2
41
  //# sourceMappingURL=use-compose-refs.mjs.map