RichText.d.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { TextAlign, TextVerticalAlign, ImageLike, Dictionary } from '../core/types';
  2. import ZRText from './Text';
  3. import ZRImage from './Image';
  4. import Rect from './shape/Rect';
  5. import BoundingRect from '../core/BoundingRect';
  6. import Displayable, { DisplayableStatePropNames, DisplayableProps } from './Displayable';
  7. interface RichTextStylePropsPart {
  8. text?: string;
  9. fill?: string;
  10. stroke?: string;
  11. opacity?: number;
  12. fillOpacity?: number;
  13. strokeOpacity?: number;
  14. lineWidth?: number;
  15. font?: string;
  16. textFont?: string;
  17. fontStyle?: 'normal' | 'italic' | 'oblique';
  18. fontWeight?: 'normal' | 'bold' | 'bolder' | 'lighter' | number;
  19. fontFamily?: string;
  20. fontSize?: number;
  21. align?: TextAlign;
  22. verticalAlign?: TextVerticalAlign;
  23. lineHeight?: number;
  24. width?: number | string;
  25. height?: number;
  26. tag?: string;
  27. textShadowColor?: string;
  28. textShadowBlur?: number;
  29. textShadowOffsetX?: number;
  30. textShadowOffsetY?: number;
  31. backgroundColor?: string | {
  32. image: ImageLike | string;
  33. };
  34. padding?: number | number[];
  35. borderColor?: string;
  36. borderWidth?: number;
  37. borderRadius?: number | number[];
  38. shadowColor?: string;
  39. shadowBlur?: number;
  40. shadowOffsetX?: number;
  41. shadowOffsetY?: number;
  42. }
  43. export interface RichTextStyleProps extends RichTextStylePropsPart {
  44. text?: string;
  45. x?: number;
  46. y?: number;
  47. width?: number;
  48. rich?: Dictionary<RichTextStylePropsPart>;
  49. overflow?: 'wrap' | 'truncate';
  50. lineOverflow?: 'truncate';
  51. ellipsis?: string;
  52. placeholder?: string;
  53. truncateMinChar?: number;
  54. }
  55. export interface RichTextProps extends DisplayableProps {
  56. style?: RichTextStyleProps;
  57. zlevel?: number;
  58. z?: number;
  59. z2?: number;
  60. culling?: boolean;
  61. cursor?: string;
  62. }
  63. export declare type RichTextState = Pick<RichTextProps, DisplayableStatePropNames>;
  64. declare class RichText extends Displayable<RichTextProps> {
  65. type: string;
  66. style: RichTextStyleProps;
  67. private _children;
  68. private _childCursor;
  69. private _defaultColor;
  70. constructor(opts?: RichTextProps);
  71. childrenRef(): (ZRText | ZRImage | Rect)[];
  72. update(): void;
  73. private _updateSubTexts;
  74. getBoundingRect(): BoundingRect;
  75. setDefaultTextColor(defaultTextStyle: Pick<RichTextStyleProps, 'fill' | 'stroke' | 'lineWidth'>): void;
  76. setTextContent(textContent: never): void;
  77. protected _mergeStyle(targetStyle: RichTextStyleProps, sourceStyle: RichTextStyleProps): RichTextStyleProps;
  78. private _mergeRich;
  79. private _getOrCreateChild;
  80. private _updatePlainTexts;
  81. private _updateRichTexts;
  82. private _placeToken;
  83. private _renderBackground;
  84. static makeFont(style: RichTextStylePropsPart): string;
  85. }
  86. export declare function normalizeTextStyle(style: RichTextStyleProps): RichTextStyleProps;
  87. export default RichText;