Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

postcss-selector-parser.d.ts 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. // Type definitions for postcss-selector-parser 2.2.3
  2. // Definitions by: Chris Eppstein <chris@eppsteins.net>
  3. /*~ Note that ES6 modules cannot directly export callable functions.
  4. *~ This file should be imported using the CommonJS-style:
  5. *~ import x = require('someLibrary');
  6. *~
  7. *~ Refer to the documentation to understand common
  8. *~ workarounds for this limitation of ES6 modules.
  9. */
  10. /*~ This declaration specifies that the function
  11. *~ is the exported object from the file
  12. */
  13. export = parser;
  14. // A type that's T but not U.
  15. type Diff<T, U> = T extends U ? never : T;
  16. // TODO: Conditional types in TS 1.8 will really clean this up.
  17. declare function parser(): parser.Processor<never>;
  18. declare function parser<Transform>(processor: parser.AsyncProcessor<Transform>): parser.Processor<Transform, never>;
  19. declare function parser(processor: parser.AsyncProcessor<void>): parser.Processor<never, never>;
  20. declare function parser<Transform>(processor: parser.SyncProcessor<Transform>): parser.Processor<Transform>;
  21. declare function parser(processor: parser.SyncProcessor<void>): parser.Processor<never>;
  22. declare function parser<Transform>(processor?: parser.SyncProcessor<Transform> | parser.AsyncProcessor<Transform>): parser.Processor<Transform>;
  23. /*~ If you want to expose types from your module as well, you can
  24. *~ place them in this block. Often you will want to describe the
  25. *~ shape of the return type of the function; that type should
  26. *~ be declared in here, as this example shows.
  27. */
  28. declare namespace parser {
  29. /* copied from postcss -- so we don't need to add a dependency */
  30. type ErrorOptions = {
  31. plugin?: string;
  32. word?: string;
  33. index?: number
  34. };
  35. /* the bits we use of postcss.Rule, copied from postcss -- so we don't need to add a dependency */
  36. type PostCSSRuleNode = {
  37. selector: string
  38. /**
  39. * @returns postcss.CssSyntaxError but it's a complex object, caller
  40. * should cast to it if they have a dependency on postcss.
  41. */
  42. error(message: string, options?: ErrorOptions): Error;
  43. };
  44. /** Accepts a string */
  45. type Selectors = string | PostCSSRuleNode
  46. type ProcessorFn<ReturnType = void> = (root: parser.Root) => ReturnType;
  47. type SyncProcessor<Transform = void> = ProcessorFn<Transform>;
  48. type AsyncProcessor<Transform = void> = ProcessorFn<PromiseLike<Transform>>;
  49. const TAG: "tag";
  50. const STRING: "string";
  51. const SELECTOR: "selector";
  52. const ROOT: "root";
  53. const PSEUDO: "pseudo";
  54. const NESTING: "nesting";
  55. const ID: "id";
  56. const COMMENT: "comment";
  57. const COMBINATOR: "combinator";
  58. const CLASS: "class";
  59. const ATTRIBUTE: "attribute";
  60. const UNIVERSAL: "universal";
  61. interface NodeTypes {
  62. tag: Tag,
  63. string: String,
  64. selector: Selector,
  65. root: Root,
  66. pseudo: Pseudo,
  67. nesting: Nesting,
  68. id: Identifier,
  69. comment: Comment,
  70. combinator: Combinator,
  71. class: ClassName,
  72. attribute: Attribute,
  73. universal: Universal
  74. }
  75. type Node = NodeTypes[keyof NodeTypes];
  76. function isNode(node: any): node is Node;
  77. interface Options {
  78. /**
  79. * Preserve whitespace when true. Default: false;
  80. */
  81. lossless: boolean;
  82. /**
  83. * When true and a postcss.Rule is passed, set the result of
  84. * processing back onto the rule when done. Default: false.
  85. */
  86. updateSelector: boolean;
  87. }
  88. class Processor<
  89. TransformType = never,
  90. SyncSelectorsType extends Selectors | never = Selectors
  91. > {
  92. res: Root;
  93. readonly result: String;
  94. ast(selectors: Selectors, options?: Partial<Options>): Promise<Root>;
  95. astSync(selectors: SyncSelectorsType, options?: Partial<Options>): Root;
  96. transform(selectors: Selectors, options?: Partial<Options>): Promise<TransformType>;
  97. transformSync(selectors: SyncSelectorsType, options?: Partial<Options>): TransformType;
  98. process(selectors: Selectors, options?: Partial<Options>): Promise<string>;
  99. processSync(selectors: SyncSelectorsType, options?: Partial<Options>): string;
  100. }
  101. interface ParserOptions {
  102. css: string;
  103. error: (message: string, options: ErrorOptions) => Error;
  104. options: Options;
  105. }
  106. class Parser {
  107. input: ParserOptions;
  108. lossy: boolean;
  109. position: number;
  110. root: Root;
  111. selectors: string;
  112. current: Selector;
  113. constructor(input: ParserOptions);
  114. /**
  115. * Raises an error, if the processor is invoked on
  116. * a postcss Rule node, a better error message is raised.
  117. */
  118. error(message: string, options?: ErrorOptions): void;
  119. }
  120. interface NodeSource {
  121. start?: {
  122. line: number,
  123. column: number
  124. },
  125. end?: {
  126. line: number,
  127. column: number
  128. }
  129. }
  130. interface SpaceAround {
  131. before: string;
  132. after: string;
  133. }
  134. interface Spaces extends SpaceAround {
  135. [spaceType: string]: string | Partial<SpaceAround> | undefined;
  136. }
  137. interface NodeOptions<Value = string> {
  138. value: Value;
  139. spaces?: Partial<Spaces>;
  140. source?: NodeSource;
  141. sourceIndex?: number;
  142. }
  143. interface Base<
  144. Value extends string | undefined = string,
  145. ParentType extends Container | undefined = Container | undefined
  146. > {
  147. type: keyof NodeTypes;
  148. parent: ParentType;
  149. value: Value;
  150. spaces: Spaces;
  151. source?: NodeSource;
  152. sourceIndex: number;
  153. rawSpaceBefore: string;
  154. rawSpaceAfter: string;
  155. remove(): Node;
  156. replaceWith(...nodes: Node[]): Node;
  157. next(): Node;
  158. prev(): Node;
  159. clone(opts: {[override: string]:any}): Node;
  160. /**
  161. * Return whether this node includes the character at the position of the given line and column.
  162. * Returns undefined if the nodes lack sufficient source metadata to determine the position.
  163. * @param line 1-index based line number relative to the start of the selector.
  164. * @param column 1-index based column number relative to the start of the selector.
  165. */
  166. isAtPosition(line: number, column: number): boolean | undefined;
  167. /**
  168. * Some non-standard syntax doesn't follow normal escaping rules for css,
  169. * this allows the escaped value to be specified directly, allowing illegal characters to be
  170. * directly inserted into css output.
  171. * @param name the property to set
  172. * @param value the unescaped value of the property
  173. * @param valueEscaped optional. the escaped value of the property.
  174. */
  175. setPropertyAndEscape(name: string, value: any, valueEscaped: string): void;
  176. /**
  177. * When you want a value to passed through to CSS directly. This method
  178. * deletes the corresponding raw value causing the stringifier to fallback
  179. * to the unescaped value.
  180. * @param name the property to set.
  181. * @param value The value that is both escaped and unescaped.
  182. */
  183. setPropertyWithoutEscape(name: string, value: any): void;
  184. /**
  185. * Some non-standard syntax doesn't follow normal escaping rules for css.
  186. * This allows non standard syntax to be appended to an existing property
  187. * by specifying the escaped value. By specifying the escaped value,
  188. * illegal characters are allowed to be directly inserted into css output.
  189. * @param {string} name the property to set
  190. * @param {any} value the unescaped value of the property
  191. * @param {string} valueEscaped optional. the escaped value of the property.
  192. */
  193. appendToPropertyAndEscape(name: string, value: any, valueEscaped: string): void;
  194. toString(): string;
  195. }
  196. interface ContainerOptions extends NodeOptions {
  197. nodes?: Array<Node>;
  198. }
  199. interface Container<
  200. Value extends string | undefined = string,
  201. Child extends Node = Node
  202. > extends Base<Value> {
  203. nodes: Array<Child>;
  204. append(selector: Selector): this;
  205. prepend(selector: Selector): this;
  206. at(index: number): Child;
  207. /**
  208. * Return the most specific node at the line and column number given.
  209. * The source location is based on the original parsed location, locations aren't
  210. * updated as selector nodes are mutated.
  211. *
  212. * Note that this location is relative to the location of the first character
  213. * of the selector, and not the location of the selector in the overall document
  214. * when used in conjunction with postcss.
  215. *
  216. * If not found, returns undefined.
  217. * @param line The line number of the node to find. (1-based index)
  218. * @param col The column number of the node to find. (1-based index)
  219. */
  220. atPosition(line: number, column: number): Child;
  221. index(child: Child): number;
  222. readonly first: Child;
  223. readonly last: Child;
  224. readonly length: number;
  225. removeChild(child: Child): this;
  226. removeAll(): Container;
  227. empty(): Container;
  228. insertAfter(oldNode: Child, newNode: Child): this;
  229. insertBefore(oldNode: Child, newNode: Child): this;
  230. each(callback: (node: Child) => boolean | void): boolean | undefined;
  231. walk(
  232. callback: (node: Node) => boolean | void
  233. ): boolean | undefined;
  234. walkAttributes(
  235. callback: (node: Attribute) => boolean | void
  236. ): boolean | undefined;
  237. walkClasses(
  238. callback: (node: ClassName) => boolean | void
  239. ): boolean | undefined;
  240. walkCombinators(
  241. callback: (node: Combinator) => boolean | void
  242. ): boolean | undefined;
  243. walkComments(
  244. callback: (node: Comment) => boolean | void
  245. ): boolean | undefined;
  246. walkIds(
  247. callback: (node: Identifier) => boolean | void
  248. ): boolean | undefined;
  249. walkNesting(
  250. callback: (node: Nesting) => boolean | void
  251. ): boolean | undefined;
  252. walkPseudos(
  253. callback: (node: Pseudo) => boolean | void
  254. ): boolean | undefined;
  255. walkTags(callback: (node: Tag) => boolean | void): boolean | undefined;
  256. split(callback: (node: Child) => boolean): [Child[], Child[]];
  257. map<T>(callback: (node: Child) => T): T[];
  258. reduce(
  259. callback: (
  260. previousValue: Child,
  261. currentValue: Child,
  262. currentIndex: number,
  263. array: readonly Child[]
  264. ) => Child
  265. ): Child;
  266. reduce(
  267. callback: (
  268. previousValue: Child,
  269. currentValue: Child,
  270. currentIndex: number,
  271. array: readonly Child[]
  272. ) => Child,
  273. initialValue: Child
  274. ): Child;
  275. reduce<T>(
  276. callback: (
  277. previousValue: T,
  278. currentValue: Child,
  279. currentIndex: number,
  280. array: readonly Child[]
  281. ) => T,
  282. initialValue: T
  283. ): T;
  284. every(callback: (node: Child) => boolean): boolean;
  285. some(callback: (node: Child) => boolean): boolean;
  286. filter(callback: (node: Child) => boolean): Child[];
  287. sort(callback: (nodeA: Child, nodeB: Child) => number): Child[];
  288. toString(): string;
  289. }
  290. function isContainer(node: any): node is Root | Selector | Pseudo;
  291. interface NamespaceOptions<Value extends string | undefined = string> extends NodeOptions<Value> {
  292. namespace?: string | true;
  293. }
  294. interface Namespace<Value extends string | undefined = string> extends Base<Value> {
  295. /** alias for namespace */
  296. ns: string | true;
  297. /**
  298. * namespace prefix.
  299. */
  300. namespace: string | true;
  301. /**
  302. * If a namespace exists, prefix the value provided with it, separated by |.
  303. */
  304. qualifiedName(value: string): string;
  305. /**
  306. * A string representing the namespace suitable for output.
  307. */
  308. readonly namespaceString: string;
  309. }
  310. function isNamespace(node: any): node is Attribute | Tag;
  311. interface Root extends Container<undefined, Selector> {
  312. type: "root";
  313. /**
  314. * Raises an error, if the processor is invoked on
  315. * a postcss Rule node, a better error message is raised.
  316. */
  317. error(message: string, options?: ErrorOptions): Error;
  318. nodeAt(line: number, column: number): Node
  319. }
  320. function root(opts: ContainerOptions): Root;
  321. function isRoot(node: any): node is Root;
  322. interface _Selector<S> extends Container<string, Diff<Node, S>> {
  323. type: "selector";
  324. }
  325. type Selector = _Selector<Selector>;
  326. function selector(opts: ContainerOptions): Selector;
  327. function isSelector(node: any): node is Selector;
  328. interface Combinator extends Base {
  329. type: "combinator"
  330. }
  331. function combinator(opts: NodeOptions): Combinator;
  332. function isCombinator(node: any): node is Combinator;
  333. interface ClassName extends Base {
  334. type: "class";
  335. }
  336. function className(opts: NamespaceOptions): ClassName;
  337. function isClassName(node: any): node is ClassName;
  338. type AttributeOperator = "=" | "~=" | "|=" | "^=" | "$=" | "*=";
  339. type QuoteMark = '"' | "'" | null;
  340. interface PreferredQuoteMarkOptions {
  341. quoteMark?: QuoteMark;
  342. preferCurrentQuoteMark?: boolean;
  343. }
  344. interface SmartQuoteMarkOptions extends PreferredQuoteMarkOptions {
  345. smart?: boolean;
  346. }
  347. interface AttributeOptions extends NamespaceOptions<string | undefined> {
  348. attribute: string;
  349. operator?: AttributeOperator;
  350. insensitive?: boolean;
  351. quoteMark?: QuoteMark;
  352. /** @deprecated Use quoteMark instead. */
  353. quoted?: boolean;
  354. spaces?: {
  355. before?: string;
  356. after?: string;
  357. attribute?: Partial<SpaceAround>;
  358. operator?: Partial<SpaceAround>;
  359. value?: Partial<SpaceAround>;
  360. insensitive?: Partial<SpaceAround>;
  361. }
  362. raws: {
  363. unquoted?: string;
  364. attribute?: string;
  365. operator?: string;
  366. value?: string;
  367. insensitive?: string;
  368. spaces?: {
  369. attribute?: Partial<Spaces>;
  370. operator?: Partial<Spaces>;
  371. value?: Partial<Spaces>;
  372. insensitive?: Partial<Spaces>;
  373. }
  374. };
  375. }
  376. interface Attribute extends Namespace<string | undefined> {
  377. type: "attribute";
  378. attribute: string;
  379. operator?: AttributeOperator;
  380. insensitive?: boolean;
  381. quoteMark: QuoteMark;
  382. quoted?: boolean;
  383. spaces: {
  384. before: string;
  385. after: string;
  386. attribute?: Partial<Spaces>;
  387. operator?: Partial<Spaces>;
  388. value?: Partial<Spaces>;
  389. insensitive?: Partial<Spaces>;
  390. }
  391. raws: {
  392. /** @deprecated The attribute value is unquoted, use that instead.. */
  393. unquoted?: string;
  394. attribute?: string;
  395. operator?: string;
  396. /** The value of the attribute with quotes and escapes. */
  397. value?: string;
  398. insensitive?: string;
  399. spaces?: {
  400. attribute?: Partial<Spaces>;
  401. operator?: Partial<Spaces>;
  402. value?: Partial<Spaces>;
  403. insensitive?: Partial<Spaces>;
  404. }
  405. };
  406. /**
  407. * The attribute name after having been qualified with a namespace.
  408. */
  409. readonly qualifiedAttribute: string;
  410. /**
  411. * The case insensitivity flag or an empty string depending on whether this
  412. * attribute is case insensitive.
  413. */
  414. readonly insensitiveFlag : 'i' | '';
  415. /**
  416. * Returns the attribute's value quoted such that it would be legal to use
  417. * in the value of a css file. The original value's quotation setting
  418. * used for stringification is left unchanged. See `setValue(value, options)`
  419. * if you want to control the quote settings of a new value for the attribute or
  420. * `set quoteMark(mark)` if you want to change the quote settings of the current
  421. * value.
  422. *
  423. * You can also change the quotation used for the current value by setting quoteMark.
  424. **/
  425. getQuotedValue(options?: SmartQuoteMarkOptions): string;
  426. /**
  427. * Set the unescaped value with the specified quotation options. The value
  428. * provided must not include any wrapping quote marks -- those quotes will
  429. * be interpreted as part of the value and escaped accordingly.
  430. * @param value
  431. */
  432. setValue(value: string, options?: SmartQuoteMarkOptions): void;
  433. /**
  434. * Intelligently select a quoteMark value based on the value's contents. If
  435. * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
  436. * mark will be picked that minimizes the number of escapes.
  437. *
  438. * If there's no clear winner, the quote mark from these options is used,
  439. * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
  440. * true). If the quoteMark is unspecified, a double quote is used.
  441. **/
  442. smartQuoteMark(options: PreferredQuoteMarkOptions): QuoteMark;
  443. /**
  444. * Selects the preferred quote mark based on the options and the current quote mark value.
  445. * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
  446. * instead.
  447. */
  448. preferredQuoteMark(options: PreferredQuoteMarkOptions): QuoteMark
  449. /**
  450. * returns the offset of the attribute part specified relative to the
  451. * start of the node of the output string.
  452. *
  453. * * "ns" - alias for "namespace"
  454. * * "namespace" - the namespace if it exists.
  455. * * "attribute" - the attribute name
  456. * * "attributeNS" - the start of the attribute or its namespace
  457. * * "operator" - the match operator of the attribute
  458. * * "value" - The value (string or identifier)
  459. * * "insensitive" - the case insensitivity flag;
  460. * @param part One of the possible values inside an attribute.
  461. * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
  462. */
  463. offsetOf(part: "ns" | "namespace" | "attribute" | "attributeNS" | "operator" | "value" | "insensitive"): number;
  464. }
  465. function attribute(opts: AttributeOptions): Attribute;
  466. function isAttribute(node: any): node is Attribute;
  467. interface Pseudo extends Container<string, Selector> {
  468. type: "pseudo";
  469. }
  470. function pseudo(opts: ContainerOptions): Pseudo;
  471. /**
  472. * Checks wether the node is the Psuedo subtype of node.
  473. */
  474. function isPseudo(node: any): node is Pseudo;
  475. /**
  476. * Checks wether the node is, specifically, a pseudo element instead of
  477. * pseudo class.
  478. */
  479. function isPseudoElement(node: any): node is Pseudo;
  480. /**
  481. * Checks wether the node is, specifically, a pseudo class instead of
  482. * pseudo element.
  483. */
  484. function isPseudoClass(node: any): node is Pseudo;
  485. interface Tag extends Namespace {
  486. type: "tag";
  487. }
  488. function tag(opts: NamespaceOptions): Tag;
  489. function isTag(node: any): node is Tag;
  490. interface Comment extends Base {
  491. type: "comment";
  492. }
  493. function comment(opts: NodeOptions): Comment;
  494. function isComment(node: any): node is Comment;
  495. interface Identifier extends Base {
  496. type: "id";
  497. }
  498. function id(opts: any): any;
  499. function isIdentifier(node: any): node is Identifier;
  500. interface Nesting extends Base {
  501. type: "nesting";
  502. }
  503. function nesting(opts: any): any;
  504. function isNesting(node: any): node is Nesting;
  505. interface String extends Base {
  506. type: "string";
  507. }
  508. function string(opts: NodeOptions): String;
  509. function isString(node: any): node is String;
  510. interface Universal extends Base {
  511. type: "universal";
  512. }
  513. function universal(opts?: NamespaceOptions): any;
  514. function isUniversal(node: any): node is Universal;
  515. }