croppie.d.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * This file is part of Threema Web.
  3. *
  4. * Threema Web is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU Affero General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. declare namespace croppie {
  18. type WheelZoomType = 'ctrl';
  19. type ViewportType = 'square' | 'circle';
  20. type ImageUrl = string;
  21. // String representation as returned by Number.prototype.toFixed()
  22. type Point = string | number;
  23. // [topLeftX, topLeftY, bottomRightX, bottomRightY]
  24. type Points = [Point, Point, Point, Point];
  25. type Orientation = number;
  26. type Type = 'canvas' | 'base64' | 'html' | 'blob' | 'rawcanvas';
  27. type Size = 'viewport' | 'original' | { width: number, height: number };
  28. type Format = 'jpeg' | 'png' | 'webp';
  29. type Degrees = 90 | 180 | 270 | -90 | -180 | -270;
  30. // Dispatched on element constructed on as 'update.croppie'
  31. type UpdateEvent = CustomEvent<State>;
  32. interface Viewport {
  33. width?: number,
  34. height?: number,
  35. type?: ViewportType,
  36. }
  37. interface Boundary {
  38. width?: number,
  39. height: number,
  40. }
  41. interface ResizeControls {
  42. width?: boolean,
  43. height?: boolean,
  44. }
  45. interface CreateOptions {
  46. viewport?: Viewport,
  47. boundary?: Boundary,
  48. resizeControls?: ResizeControls,
  49. customClass?: string,
  50. showZoomer?: boolean,
  51. enableZoom?: boolean,
  52. enableResize?: boolean,
  53. mouseWheelZoom?: boolean | WheelZoomType,
  54. enableExif?: boolean,
  55. enforceBoundary?: boolean,
  56. enableOrientation?: boolean,
  57. enableKeyMovement?: boolean,
  58. url?: ImageUrl,
  59. points?: Points,
  60. update?: (UpdateEvent) => void,
  61. }
  62. interface State {
  63. points: Points;
  64. zoom: number,
  65. orientation?: Orientation,
  66. }
  67. interface BindOptions {
  68. url?: ImageUrl,
  69. points?: Points,
  70. zoom?: number,
  71. orientation?: Orientation,
  72. }
  73. interface ResultOptions {
  74. type?: Type;
  75. size?: Size;
  76. format?: Format;
  77. quality?: number; // Range: [0..1]
  78. backgroundColor?: string,
  79. circle?: boolean;
  80. }
  81. }
  82. declare class Croppie {
  83. constructor(element: HTMLElement, options?: croppie.CreateOptions);
  84. get(): croppie.State;
  85. bind(options?: croppie.BindOptions | croppie.ImageUrl | croppie.Points): Promise<void>;
  86. destroy(): void;
  87. result(options: croppie.ResultOptions & { type: 'base64' | 'canvas' }): Promise<string>;
  88. result(options: croppie.ResultOptions & { type: 'html' }): Promise<HTMLElement>;
  89. result(options: croppie.ResultOptions & { type: 'blob' }): Promise<Blob>;
  90. result(options: croppie.ResultOptions & { type: 'rawcanvas' }): Promise<HTMLCanvasElement>;
  91. result(options?: croppie.ResultOptions): Promise<HTMLCanvasElement>;
  92. rotate(degrees: croppie.Degrees): void;
  93. setZoom(zoom: number): void;
  94. destroy(): void;
  95. }