util.d.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { Dictionary, ArrayLike, KeyOfDistributive } from './types';
  2. import { GradientObject } from '../graphic/Gradient';
  3. import { ImagePatternObject } from '../graphic/Pattern';
  4. declare const nativeSlice: (start?: number, end?: number) => any[];
  5. export declare function guid(): number;
  6. export declare function logError(...args: any[]): void;
  7. export declare function clone<T extends any>(source: T): T;
  8. export declare function merge<T extends Dictionary<any>, S extends Dictionary<any>>(target: T, source: S, overwrite?: boolean): T & S;
  9. export declare function merge<T extends any, S extends any>(target: T, source: S, overwrite?: boolean): T | S;
  10. export declare function mergeAll(targetAndSources: any[], overwrite?: boolean): any;
  11. export declare function extend<T extends Dictionary<any>, S extends Dictionary<any>>(target: T, source: S): T & S;
  12. export declare function defaults<T extends Dictionary<any>, S extends Dictionary<any>>(target: T, source: S, overlay?: boolean): T & S;
  13. export declare const createCanvas: () => HTMLCanvasElement;
  14. export declare function indexOf<T>(array: T[] | readonly T[] | ArrayLike<T>, value: T): number;
  15. export declare function inherits(clazz: Function, baseClazz: Function): void;
  16. export declare function mixin<T, S>(target: T | Function, source: S | Function, override?: boolean): void;
  17. export declare function isArrayLike(data: any): data is ArrayLike<any>;
  18. export declare function each<I extends Dictionary<any> | any[] | readonly any[] | ArrayLike<any>, Context>(arr: I, cb: (this: Context, value: I extends (infer T)[] | readonly (infer T)[] | ArrayLike<infer T> ? T : I extends Dictionary<any> ? I extends Record<infer K, infer T> ? T : unknown : unknown, index?: I extends any[] | readonly any[] | ArrayLike<any> ? number : keyof I & string, arr?: I) => void, context?: Context): void;
  19. export declare function map<T, R, Context>(arr: readonly T[], cb: (this: Context, val: T, index?: number, arr?: readonly T[]) => R, context?: Context): R[];
  20. export declare function reduce<T, S, Context>(arr: readonly T[], cb: (this: Context, previousValue: S, currentValue: T, currentIndex?: number, arr?: readonly T[]) => S, memo?: S, context?: Context): S;
  21. export declare function filter<T, Context>(arr: readonly T[], cb: (this: Context, value: T, index: number, arr: readonly T[]) => boolean, context?: Context): T[];
  22. export declare function find<T, Context>(arr: readonly T[], cb: (this: Context, value: T, index?: number, arr?: readonly T[]) => boolean, context?: Context): T;
  23. export declare function keys<T extends object>(obj: T): (KeyOfDistributive<T> & string)[];
  24. export declare type Bind1<F, Ctx> = F extends (this: Ctx, ...args: infer A) => infer R ? (...args: A) => R : unknown;
  25. export declare type Bind2<F, Ctx, T1> = F extends (this: Ctx, a: T1, ...args: infer A) => infer R ? (...args: A) => R : unknown;
  26. export declare type Bind3<F, Ctx, T1, T2> = F extends (this: Ctx, a: T1, b: T2, ...args: infer A) => infer R ? (...args: A) => R : unknown;
  27. export declare type Bind4<F, Ctx, T1, T2, T3> = F extends (this: Ctx, a: T1, b: T2, c: T3, ...args: infer A) => infer R ? (...args: A) => R : unknown;
  28. export declare type Bind5<F, Ctx, T1, T2, T3, T4> = F extends (this: Ctx, a: T1, b: T2, c: T3, d: T4, ...args: infer A) => infer R ? (...args: A) => R : unknown;
  29. declare type BindFunc<Ctx> = (this: Ctx, ...arg: any[]) => any;
  30. interface FunctionBind {
  31. <F extends BindFunc<Ctx>, Ctx>(func: F, ctx: Ctx): Bind1<F, Ctx>;
  32. <F extends BindFunc<Ctx>, Ctx, T1 extends Parameters<F>[0]>(func: F, ctx: Ctx, a: T1): Bind2<F, Ctx, T1>;
  33. <F extends BindFunc<Ctx>, Ctx, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1]>(func: F, ctx: Ctx, a: T1, b: T2): Bind3<F, Ctx, T1, T2>;
  34. <F extends BindFunc<Ctx>, Ctx, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1], T3 extends Parameters<F>[2]>(func: F, ctx: Ctx, a: T1, b: T2, c: T3): Bind4<F, Ctx, T1, T2, T3>;
  35. <F extends BindFunc<Ctx>, Ctx, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1], T3 extends Parameters<F>[2], T4 extends Parameters<F>[3]>(func: F, ctx: Ctx, a: T1, b: T2, c: T3, d: T4): Bind5<F, Ctx, T1, T2, T3, T4>;
  36. }
  37. export declare const bind: FunctionBind;
  38. export declare type Curry1<F, T1> = F extends (a: T1, ...args: infer A) => infer R ? (...args: A) => R : unknown;
  39. export declare type Curry2<F, T1, T2> = F extends (a: T1, b: T2, ...args: infer A) => infer R ? (...args: A) => R : unknown;
  40. export declare type Curry3<F, T1, T2, T3> = F extends (a: T1, b: T2, c: T3, ...args: infer A) => infer R ? (...args: A) => R : unknown;
  41. export declare type Curry4<F, T1, T2, T3, T4> = F extends (a: T1, b: T2, c: T3, d: T4, ...args: infer A) => infer R ? (...args: A) => R : unknown;
  42. declare type CurryFunc = (...arg: any[]) => any;
  43. declare function curry<F extends CurryFunc, T1 extends Parameters<F>[0]>(func: F, a: T1): Curry1<F, T1>;
  44. declare function curry<F extends CurryFunc, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1]>(func: F, a: T1, b: T2): Curry2<F, T1, T2>;
  45. declare function curry<F extends CurryFunc, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1], T3 extends Parameters<F>[2]>(func: F, a: T1, b: T2, c: T3): Curry3<F, T1, T2, T3>;
  46. declare function curry<F extends CurryFunc, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1], T3 extends Parameters<F>[2], T4 extends Parameters<F>[3]>(func: F, a: T1, b: T2, c: T3, d: T4): Curry4<F, T1, T2, T3, T4>;
  47. export { curry };
  48. export declare function isArray(value: any): value is any[];
  49. export declare function isFunction(value: any): value is Function;
  50. export declare function isString(value: any): value is string;
  51. export declare function isStringSafe(value: any): value is string;
  52. export declare function isNumber(value: any): value is number;
  53. export declare function isObject<T = unknown>(value: T): value is (object & T);
  54. export declare function isBuiltInObject(value: any): boolean;
  55. export declare function isTypedArray(value: any): boolean;
  56. export declare function isDom(value: any): value is HTMLElement;
  57. export declare function isGradientObject(value: any): value is GradientObject;
  58. export declare function isImagePatternObject(value: any): value is ImagePatternObject;
  59. export declare function isRegExp(value: unknown): value is RegExp;
  60. export declare function eqNaN(value: any): boolean;
  61. export declare function retrieve<T>(...args: T[]): T;
  62. export declare function retrieve2<T, R>(value0: T, value1: R): T | R;
  63. export declare function retrieve3<T, R, W>(value0: T, value1: R, value2: W): T | R | W;
  64. declare type SliceParams = Parameters<typeof nativeSlice>;
  65. export declare function slice<T>(arr: ArrayLike<T>, ...args: SliceParams): T[];
  66. export declare function normalizeCssArray(val: number | number[]): number[];
  67. export declare function assert(condition: any, message?: string): void;
  68. export declare function trim(str: string): string;
  69. export declare function setAsPrimitive(obj: any): void;
  70. export declare function isPrimitive(obj: any): boolean;
  71. interface MapInterface<T, KEY extends string | number = string | number> {
  72. delete(key: KEY): boolean;
  73. has(key: KEY): boolean;
  74. get(key: KEY): T | undefined;
  75. set(key: KEY, value: T): this;
  76. keys(): KEY[];
  77. forEach(callback: (value: T, key: KEY) => void): void;
  78. }
  79. export declare class HashMap<T, KEY extends string | number = string | number> {
  80. data: MapInterface<T, KEY>;
  81. constructor(obj?: HashMap<T, KEY> | {
  82. [key in KEY]?: T;
  83. } | KEY[]);
  84. hasKey(key: KEY): boolean;
  85. get(key: KEY): T;
  86. set(key: KEY, value: T): T;
  87. each<Context>(cb: (this: Context, value?: T, key?: KEY) => void, context?: Context): void;
  88. keys(): KEY[];
  89. removeKey(key: KEY): void;
  90. }
  91. export declare function createHashMap<T, KEY extends string | number = string | number>(obj?: HashMap<T, KEY> | {
  92. [key in KEY]?: T;
  93. } | KEY[]): HashMap<T, KEY>;
  94. export declare function concatArray<T, R>(a: ArrayLike<T>, b: ArrayLike<R>): ArrayLike<T | R>;
  95. export declare function createObject<T>(proto?: object, properties?: T): T;
  96. export declare function disableUserSelect(dom: HTMLElement): void;
  97. export declare function hasOwn(own: object, prop: string): boolean;
  98. export declare function noop(): void;
  99. export declare const RADIAN_TO_DEGREE: number;