c7adb1449d996078a4c84cdb0e591444e3ea3a2049a5f84d077b1a8fbb9689694292603e6094fa180af9400e2638f05d766f25ebd52b873cebc7f649eed185 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. export type XastDoctype = {
  2. type: 'doctype';
  3. name: string;
  4. data: {
  5. doctype: string;
  6. };
  7. };
  8. export type XastInstruction = {
  9. type: 'instruction';
  10. name: string;
  11. value: string;
  12. };
  13. export type XastComment = {
  14. type: 'comment';
  15. value: string;
  16. };
  17. export type XastCdata = {
  18. type: 'cdata';
  19. value: string;
  20. };
  21. export type XastText = {
  22. type: 'text';
  23. value: string;
  24. };
  25. export type XastElement = {
  26. type: 'element';
  27. name: string;
  28. attributes: Record<string, string>;
  29. children: Array<XastChild>;
  30. };
  31. export type XastChild =
  32. | XastDoctype
  33. | XastInstruction
  34. | XastComment
  35. | XastCdata
  36. | XastText
  37. | XastElement;
  38. export type XastRoot = {
  39. type: 'root';
  40. children: Array<XastChild>;
  41. };
  42. export type XastParent = XastRoot | XastElement;
  43. export type XastNode = XastRoot | XastChild;
  44. export type StringifyOptions = {
  45. doctypeStart?: string;
  46. doctypeEnd?: string;
  47. procInstStart?: string;
  48. procInstEnd?: string;
  49. tagOpenStart?: string;
  50. tagOpenEnd?: string;
  51. tagCloseStart?: string;
  52. tagCloseEnd?: string;
  53. tagShortStart?: string;
  54. tagShortEnd?: string;
  55. attrStart?: string;
  56. attrEnd?: string;
  57. commentStart?: string;
  58. commentEnd?: string;
  59. cdataStart?: string;
  60. cdataEnd?: string;
  61. textStart?: string;
  62. textEnd?: string;
  63. indent?: number | string;
  64. regEntities?: RegExp;
  65. regValEntities?: RegExp;
  66. encodeEntity?: (char: string) => string;
  67. pretty?: boolean;
  68. useShortTags?: boolean;
  69. eol?: 'lf' | 'crlf';
  70. finalNewline?: boolean;
  71. };
  72. type VisitorNode<Node> = {
  73. enter?: (node: Node, parentNode: XastParent) => void | symbol;
  74. exit?: (node: Node, parentNode: XastParent) => void;
  75. };
  76. type VisitorRoot = {
  77. enter?: (node: XastRoot, parentNode: null) => void;
  78. exit?: (node: XastRoot, parentNode: null) => void;
  79. };
  80. export type Visitor = {
  81. doctype?: VisitorNode<XastDoctype>;
  82. instruction?: VisitorNode<XastInstruction>;
  83. comment?: VisitorNode<XastComment>;
  84. cdata?: VisitorNode<XastCdata>;
  85. text?: VisitorNode<XastText>;
  86. element?: VisitorNode<XastElement>;
  87. root?: VisitorRoot;
  88. };
  89. export type PluginInfo = {
  90. path?: string;
  91. multipassCount: number;
  92. };
  93. export type Plugin<Params> = (
  94. root: XastRoot,
  95. params: Params,
  96. info: PluginInfo
  97. ) => null | Visitor;
  98. export type Specificity = [number, number, number, number];
  99. export type StylesheetDeclaration = {
  100. name: string;
  101. value: string;
  102. important: boolean;
  103. };
  104. export type StylesheetRule = {
  105. dynamic: boolean;
  106. selectors: string;
  107. specificity: Specificity;
  108. declarations: Array<StylesheetDeclaration>;
  109. };
  110. export type Stylesheet = {
  111. rules: Array<StylesheetRule>;
  112. parents: Map<XastElement, XastParent>;
  113. };
  114. type StaticStyle = {
  115. type: 'static';
  116. inherited: boolean;
  117. value: string;
  118. };
  119. type DynamicStyle = {
  120. type: 'dynamic';
  121. inherited: boolean;
  122. };
  123. export type ComputedStyles = Record<string, StaticStyle | DynamicStyle>;
  124. export type PathDataCommand =
  125. | 'M'
  126. | 'm'
  127. | 'Z'
  128. | 'z'
  129. | 'L'
  130. | 'l'
  131. | 'H'
  132. | 'h'
  133. | 'V'
  134. | 'v'
  135. | 'C'
  136. | 'c'
  137. | 'S'
  138. | 's'
  139. | 'Q'
  140. | 'q'
  141. | 'T'
  142. | 't'
  143. | 'A'
  144. | 'a';
  145. export type PathDataItem = {
  146. command: PathDataCommand;
  147. args: Array<number>;
  148. };