global.d.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  2. interface Document {
  3. fonts?: {
  4. ready?: Promise<void>;
  5. check?: (font: string, text?: string) => boolean;
  6. load?: (font: string, text?: string) => Promise<FontFace[]>;
  7. addEventListener?(
  8. type: "loading" | "loadingdone" | "loadingerror",
  9. listener: (this: Document, ev: Event) => any,
  10. ): void;
  11. };
  12. }
  13. interface Window {
  14. ClipboardItem: any;
  15. __EXCALIDRAW_SHA__: string | undefined;
  16. EXCALIDRAW_ASSET_PATH: string | undefined;
  17. EXCALIDRAW_EXPORT_SOURCE: string;
  18. EXCALIDRAW_THROTTLE_RENDER: boolean | undefined;
  19. gtag: Function;
  20. }
  21. interface CanvasRenderingContext2D {
  22. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect
  23. roundRect?: (
  24. x: number,
  25. y: number,
  26. width: number,
  27. height: number,
  28. radii:
  29. | number // [all-corners]
  30. | [number] // [all-corners]
  31. | [number, number] // [top-left-and-bottom-right, top-right-and-bottom-left]
  32. | [number, number, number] // [top-left, top-right-and-bottom-left, bottom-right]
  33. | [number, number, number, number], // [top-left, top-right, bottom-right, bottom-left]
  34. ) => void;
  35. }
  36. // https://github.com/facebook/create-react-app/blob/ddcb7d5/packages/react-scripts/lib/react-app.d.ts
  37. declare namespace NodeJS {
  38. interface ProcessEnv {
  39. readonly REACT_APP_BACKEND_V2_GET_URL: string;
  40. readonly REACT_APP_BACKEND_V2_POST_URL: string;
  41. readonly REACT_APP_PORTAL_URL: string;
  42. readonly REACT_APP_FIREBASE_CONFIG: string;
  43. }
  44. }
  45. interface Clipboard extends EventTarget {
  46. write(data: any[]): Promise<void>;
  47. }
  48. type Mutable<T> = {
  49. -readonly [P in keyof T]: T[P];
  50. };
  51. type ValueOf<T> = T[keyof T];
  52. type Merge<M, N> = Omit<M, keyof N> & N;
  53. /** utility type to assert that the second type is a subtype of the first type.
  54. * Returns the subtype. */
  55. type SubtypeOf<Supertype, Subtype extends Supertype> = Subtype;
  56. type ResolutionType<T extends (...args: any) => any> = T extends (
  57. ...args: any
  58. ) => Promise<infer R>
  59. ? R
  60. : any;
  61. // https://github.com/krzkaczor/ts-essentials
  62. type MarkOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
  63. type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> &
  64. Required<Pick<T, RK>>;
  65. type MarkNonNullable<T, K extends keyof T> = {
  66. [P in K]-?: P extends K ? NonNullable<T[P]> : T[P];
  67. } & { [P in keyof T]: T[P] };
  68. type NonOptional<T> = Exclude<T, undefined>;
  69. // PNG encoding/decoding
  70. // -----------------------------------------------------------------------------
  71. type TEXtChunk = { name: "tEXt"; data: Uint8Array };
  72. declare module "png-chunk-text" {
  73. function encode(
  74. name: string,
  75. value: string,
  76. ): { name: "tEXt"; data: Uint8Array };
  77. function decode(data: Uint8Array): { keyword: string; text: string };
  78. }
  79. declare module "png-chunks-encode" {
  80. function encode(chunks: TEXtChunk[]): Uint8Array;
  81. export = encode;
  82. }
  83. declare module "png-chunks-extract" {
  84. function extract(buffer: Uint8Array): TEXtChunk[];
  85. export = extract;
  86. }
  87. // -----------------------------------------------------------------------------
  88. // -----------------------------------------------------------------------------
  89. // type getter for interface's callable type
  90. // src: https://stackoverflow.com/a/58658851/927631
  91. // -----------------------------------------------------------------------------
  92. type SignatureType<T> = T extends (...args: infer R) => any ? R : never;
  93. type CallableType<T extends (...args: any[]) => any> = (
  94. ...args: SignatureType<T>
  95. ) => ReturnType<T>;
  96. // --------------------------------------------------------------------------—
  97. // Type for React.forwardRef --- supply only the first generic argument T
  98. type ForwardRef<T, P = any> = Parameters<
  99. CallableType<React.ForwardRefRenderFunction<T, P>>
  100. >[1];
  101. // --------------------------------------------------------------------------—
  102. interface Blob {
  103. handle?: import("browser-fs-acces").FileSystemHandle;
  104. name?: string;
  105. }
  106. declare module "*.scss";
  107. // --------------------------------------------------------------------------—
  108. // ensure Uint8Array isn't assignable to ArrayBuffer
  109. // (due to TS structural typing)
  110. // https://github.com/microsoft/TypeScript/issues/31311#issuecomment-490690695
  111. interface ArrayBuffer {
  112. _brand?: "ArrayBuffer";
  113. }
  114. interface Uint8Array {
  115. _brand?: "Uint8Array";
  116. }
  117. // --------------------------------------------------------------------------—
  118. // https://github.com/nodeca/image-blob-reduce/issues/23#issuecomment-783271848
  119. declare module "image-blob-reduce" {
  120. import { PicaResizeOptions, Pica } from "pica";
  121. namespace ImageBlobReduce {
  122. interface ImageBlobReduce {
  123. toBlob(file: File, options: ImageBlobReduceOptions): Promise<Blob>;
  124. _create_blob(
  125. this: { pica: Pica },
  126. env: {
  127. out_canvas: HTMLCanvasElement;
  128. out_blob: Blob;
  129. },
  130. ): Promise<any>;
  131. }
  132. interface ImageBlobReduceStatic {
  133. new (options?: any): ImageBlobReduce;
  134. (options?: any): ImageBlobReduce;
  135. }
  136. interface ImageBlobReduceOptions extends PicaResizeOptions {
  137. max: number;
  138. }
  139. }
  140. const reduce: ImageBlobReduce.ImageBlobReduceStatic;
  141. export = reduce;
  142. }