index.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Rectangle, Point } from '@antv/x6-geometry';
  2. import { JSONObject } from '@antv/x6-common';
  3. import { Registry } from '../registry';
  4. import { Cell } from '../../model';
  5. import { CellView } from '../../view';
  6. export declare namespace Attr {
  7. type SimpleAttrValue = null | undefined | string | number;
  8. type SimpleAttrs = {
  9. [name: string]: SimpleAttrValue;
  10. };
  11. type ComplexAttrValue = null | undefined | boolean | string | number | JSONObject;
  12. type ComplexAttrs = {
  13. [name: string]: ComplexAttrValue;
  14. };
  15. type CellAttrs = {
  16. [selector: string]: ComplexAttrs;
  17. };
  18. }
  19. export declare namespace Attr {
  20. interface QualifyOptions {
  21. elem: Element;
  22. attrs: ComplexAttrs;
  23. cell: Cell;
  24. view: CellView;
  25. }
  26. type QualifyFucntion = (this: CellView, val: ComplexAttrValue, options: QualifyOptions) => boolean;
  27. interface Options extends QualifyOptions {
  28. refBBox: Rectangle;
  29. }
  30. type SetFunction = (this: CellView, val: ComplexAttrValue, options: Options) => SimpleAttrValue | SimpleAttrs | void;
  31. type OffsetFunction = (this: CellView, val: ComplexAttrValue, options: Options) => Point.PointLike;
  32. type PositionFunction = (this: CellView, val: ComplexAttrValue, options: Options) => Point.PointLike | undefined | null;
  33. interface Qualify {
  34. qualify?: QualifyFucntion;
  35. }
  36. interface SetDefinition extends Qualify {
  37. set: SetFunction;
  38. }
  39. interface OffsetDefinition extends Qualify {
  40. offset: OffsetFunction;
  41. }
  42. interface PositionDefinition extends Qualify {
  43. /**
  44. * Returns a point from the reference bounding box.
  45. */
  46. position: PositionFunction;
  47. }
  48. type Definition = string | Qualify | SetDefinition | OffsetDefinition | PositionDefinition;
  49. type Definitions = {
  50. [attrName: string]: Definition;
  51. };
  52. type GetDefinition = (name: string) => Definition | null | undefined;
  53. }
  54. export declare namespace Attr {
  55. function isValidDefinition(this: CellView, def: Definition | undefined | null, val: ComplexAttrValue, options: QualifyOptions): def is Definition;
  56. }
  57. export declare namespace Attr {
  58. type Presets = (typeof Attr)['presets'];
  59. type NativeNames = keyof Presets;
  60. }
  61. export declare namespace Attr {
  62. const presets: Definitions;
  63. const registry: Registry<Definition, Definitions, never>;
  64. }