adobe-css-tools.d.cts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. declare class CssParseError extends Error {
  2. readonly reason: string;
  3. readonly filename?: string;
  4. readonly line: number;
  5. readonly column: number;
  6. readonly source: string;
  7. constructor(filename: string, msg: string, lineno: number, column: number, css: string);
  8. }
  9. /**
  10. * Store position information for a node
  11. */
  12. declare class Position {
  13. start: {
  14. line: number;
  15. column: number;
  16. };
  17. end: {
  18. line: number;
  19. column: number;
  20. };
  21. source?: string;
  22. constructor(start: {
  23. line: number;
  24. column: number;
  25. }, end: {
  26. line: number;
  27. column: number;
  28. }, source: string);
  29. }
  30. declare enum CssTypes {
  31. stylesheet = "stylesheet",
  32. rule = "rule",
  33. declaration = "declaration",
  34. comment = "comment",
  35. container = "container",
  36. charset = "charset",
  37. document = "document",
  38. customMedia = "custom-media",
  39. fontFace = "font-face",
  40. host = "host",
  41. import = "import",
  42. keyframes = "keyframes",
  43. keyframe = "keyframe",
  44. layer = "layer",
  45. media = "media",
  46. namespace = "namespace",
  47. page = "page",
  48. startingStyle = "starting-style",
  49. supports = "supports"
  50. }
  51. type CssCommonAST = {
  52. type: CssTypes;
  53. };
  54. type CssCommonPositionAST = CssCommonAST & {
  55. position?: Position;
  56. parent?: unknown;
  57. };
  58. type CssStylesheetAST = CssCommonAST & {
  59. type: CssTypes.stylesheet;
  60. stylesheet: {
  61. source?: string;
  62. rules: Array<CssAtRuleAST>;
  63. parsingErrors?: Array<CssParseError>;
  64. };
  65. };
  66. type CssRuleAST = CssCommonPositionAST & {
  67. type: CssTypes.rule;
  68. selectors: Array<string>;
  69. declarations: Array<CssDeclarationAST | CssCommentAST>;
  70. };
  71. type CssDeclarationAST = CssCommonPositionAST & {
  72. type: CssTypes.declaration;
  73. property: string;
  74. value: string;
  75. };
  76. type CssCommentAST = CssCommonPositionAST & {
  77. type: CssTypes.comment;
  78. comment: string;
  79. };
  80. type CssContainerAST = CssCommonPositionAST & {
  81. type: CssTypes.container;
  82. container: string;
  83. rules: Array<CssAtRuleAST>;
  84. };
  85. type CssCharsetAST = CssCommonPositionAST & {
  86. type: CssTypes.charset;
  87. charset: string;
  88. };
  89. type CssCustomMediaAST = CssCommonPositionAST & {
  90. type: CssTypes.customMedia;
  91. name: string;
  92. media: string;
  93. };
  94. type CssDocumentAST = CssCommonPositionAST & {
  95. type: CssTypes.document;
  96. document: string;
  97. vendor?: string;
  98. rules: Array<CssAtRuleAST>;
  99. };
  100. type CssFontFaceAST = CssCommonPositionAST & {
  101. type: CssTypes.fontFace;
  102. declarations: Array<CssDeclarationAST | CssCommentAST>;
  103. };
  104. type CssHostAST = CssCommonPositionAST & {
  105. type: CssTypes.host;
  106. rules: Array<CssAtRuleAST>;
  107. };
  108. type CssImportAST = CssCommonPositionAST & {
  109. type: CssTypes.import;
  110. import: string;
  111. };
  112. type CssKeyframesAST = CssCommonPositionAST & {
  113. type: CssTypes.keyframes;
  114. name: string;
  115. vendor?: string;
  116. keyframes: Array<CssKeyframeAST | CssCommentAST>;
  117. };
  118. type CssKeyframeAST = CssCommonPositionAST & {
  119. type: CssTypes.keyframe;
  120. values: Array<string>;
  121. declarations: Array<CssDeclarationAST | CssCommentAST>;
  122. };
  123. type CssLayerAST = CssCommonPositionAST & {
  124. type: CssTypes.layer;
  125. layer: string;
  126. rules?: Array<CssAtRuleAST>;
  127. };
  128. type CssMediaAST = CssCommonPositionAST & {
  129. type: CssTypes.media;
  130. media: string;
  131. rules: Array<CssAtRuleAST>;
  132. };
  133. type CssNamespaceAST = CssCommonPositionAST & {
  134. type: CssTypes.namespace;
  135. namespace: string;
  136. };
  137. type CssPageAST = CssCommonPositionAST & {
  138. type: CssTypes.page;
  139. selectors: Array<string>;
  140. declarations: Array<CssDeclarationAST | CssCommentAST>;
  141. };
  142. type CssSupportsAST = CssCommonPositionAST & {
  143. type: CssTypes.supports;
  144. supports: string;
  145. rules: Array<CssAtRuleAST>;
  146. };
  147. type CssStartingStyleAST = CssCommonPositionAST & {
  148. type: CssTypes.startingStyle;
  149. rules: Array<CssAtRuleAST>;
  150. };
  151. type CssAtRuleAST = CssRuleAST | CssCommentAST | CssContainerAST | CssCharsetAST | CssCustomMediaAST | CssDocumentAST | CssFontFaceAST | CssHostAST | CssImportAST | CssKeyframesAST | CssLayerAST | CssMediaAST | CssNamespaceAST | CssPageAST | CssSupportsAST | CssStartingStyleAST;
  152. type CssAllNodesAST = CssAtRuleAST | CssStylesheetAST | CssDeclarationAST | CssKeyframeAST;
  153. type CompilerOptions = {
  154. indent?: string;
  155. compress?: boolean;
  156. };
  157. declare const parse: (css: string, options?: {
  158. source?: string;
  159. silent?: boolean;
  160. }) => CssStylesheetAST;
  161. declare const stringify: (node: CssStylesheetAST, options?: CompilerOptions) => string;
  162. declare const _default: {
  163. parse: (css: string, options?: {
  164. source?: string;
  165. silent?: boolean;
  166. }) => CssStylesheetAST;
  167. stringify: (node: CssStylesheetAST, options?: CompilerOptions) => string;
  168. };
  169. export { CssTypes, _default as default, parse, stringify };
  170. export type { CssAllNodesAST, CssAtRuleAST, CssCharsetAST, CssCommentAST, CssCommonAST, CssCommonPositionAST, CssContainerAST, CssCustomMediaAST, CssDeclarationAST, CssDocumentAST, CssFontFaceAST, CssHostAST, CssImportAST, CssKeyframeAST, CssKeyframesAST, CssLayerAST, CssMediaAST, CssNamespaceAST, CssPageAST, CssRuleAST, CssStartingStyleAST, CssStylesheetAST, CssSupportsAST };