ContextService.d.ts 1.0 KB

1234567891011121314151617181920212223242526272829
  1. import type { CanvasLike } from '../types';
  2. export type DataURLType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/bmp';
  3. /**
  4. * The created image data will have a resolution of 96dpi.
  5. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLCanvasElement/toDataURL#%E5%8F%82%E6%95%B0
  6. */
  7. export interface DataURLOptions {
  8. /**
  9. * The default type is image/png.
  10. */
  11. type: DataURLType;
  12. /**
  13. * The image quality between 0 and 1 for image/jpeg and image/webp.
  14. */
  15. encoderOptions: number;
  16. }
  17. export interface ContextService<Context> {
  18. init?: () => void;
  19. initAsync?: () => Promise<void>;
  20. destroy: () => void;
  21. getContext: () => Context | null;
  22. getDomElement: () => CanvasLike | null;
  23. getDPR: () => number;
  24. getBoundingClientRect: () => DOMRect | undefined;
  25. resize: (width: number, height: number) => void;
  26. applyCursorStyle: (cursor: string) => void;
  27. toDataURL: (options: Partial<DataURLOptions>) => Promise<string>;
  28. }
  29. //# sourceMappingURL=ContextService.d.ts.map