index.d.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { ValuesType } from 'utility-types';
  2. import { KeyValue } from '@antv/x6-common';
  3. import { Registry } from '../registry';
  4. export declare namespace Background {
  5. interface Options {
  6. color?: string;
  7. image?: string;
  8. position?: Background.BackgroundPosition<{
  9. x: number;
  10. y: number;
  11. }>;
  12. size?: Background.BackgroundSize<{
  13. width: number;
  14. height: number;
  15. }>;
  16. repeat?: Background.BackgroundRepeat;
  17. opacity?: number;
  18. }
  19. interface CommonOptions extends Omit<Options, 'repeat'> {
  20. quality?: number;
  21. }
  22. type Definition<T extends CommonOptions = CommonOptions> = (img: HTMLImageElement, options: T) => HTMLCanvasElement;
  23. }
  24. export declare namespace Background {
  25. type Presets = (typeof Background)['presets'];
  26. type OptionsMap = {
  27. readonly [K in keyof Presets]-?: Parameters<Presets[K]>[1] & {
  28. repeat: K;
  29. };
  30. };
  31. type NativeNames = keyof Presets;
  32. type NativeItem = ValuesType<OptionsMap>;
  33. type ManaualItem = CommonOptions & KeyValue & {
  34. repeat: string;
  35. };
  36. }
  37. export declare namespace Background {
  38. const presets: {
  39. [name: string]: Definition;
  40. };
  41. const registry: Registry<Definition<CommonOptions>, {
  42. [name: string]: Definition<CommonOptions>;
  43. }, never>;
  44. }
  45. export declare namespace Background {
  46. type Globals = '-moz-initial' | 'inherit' | 'initial' | 'revert' | 'unset';
  47. type BgPosition<TLength> = TLength | 'bottom' | 'center' | 'left' | 'right' | 'top' | (string & {});
  48. type BgSize<TLength> = TLength | 'auto' | 'contain' | 'cover' | (string & {});
  49. type RepeatStyle = 'no-repeat' | 'repeat' | 'repeat-x' | 'repeat-y' | 'round' | 'space' | (string & {});
  50. export type BackgroundPosition<TLength = (string & {}) | 0> = Globals | BgPosition<TLength> | (string & {});
  51. export type BackgroundSize<TLength = (string & {}) | 0> = Globals | BgSize<TLength> | (string & {});
  52. export type BackgroundRepeat = Globals | RepeatStyle | (string & {});
  53. export interface Padding {
  54. left: number;
  55. top: number;
  56. right: number;
  57. bottom: number;
  58. }
  59. export {};
  60. }