mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
/**
|
||||
* @module "ui/styling/css-selector"
|
||||
*/ /** */
|
||||
|
||||
import { Node as ParserNode } from "../../../css";
|
||||
|
||||
/**
|
||||
* An interface describing the shape of a type on which the selectors may apply.
|
||||
* Note, the ui/core/view.View implements Node.
|
||||
*/
|
||||
export interface Node {
|
||||
parent?: Node;
|
||||
|
||||
id?: string;
|
||||
nodeName?: string;
|
||||
cssType?: string;
|
||||
cssClasses?: Set<string>;
|
||||
cssPseudoClasses?: Set<string>;
|
||||
getChildIndex?(node: Node): number;
|
||||
getChildAt?(index: number): Node;
|
||||
}
|
||||
|
||||
export interface Declaration {
|
||||
property: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface SelectorCore {
|
||||
/**
|
||||
* Dynamic selectors depend on attributes and pseudo classes.
|
||||
*/
|
||||
dynamic: boolean;
|
||||
match(node: Node): boolean;
|
||||
ruleset: RuleSet;
|
||||
}
|
||||
|
||||
export class RuleSet {
|
||||
/**
|
||||
* Gets the selectors in this ruleset's selector group.
|
||||
*/
|
||||
selectors: SelectorCore[];
|
||||
|
||||
/**
|
||||
* Gets the key-value list of declarations for the ruleset.
|
||||
*/
|
||||
declarations: Declaration[];
|
||||
|
||||
/**
|
||||
* Optional Tag for rules
|
||||
**/
|
||||
tag: string | Number;
|
||||
}
|
||||
|
||||
export class SelectorsMap {
|
||||
constructor(rules: RuleSet[]);
|
||||
|
||||
/**
|
||||
* Get a list of selectors that are likely to match the node.
|
||||
*/
|
||||
query<T extends Node>(node: T): SelectorsMatch<T>;
|
||||
}
|
||||
|
||||
export type ChangeMap<T extends Node> = Map<T, Changes>;
|
||||
|
||||
export interface Changes {
|
||||
attributes?: Set<string>;
|
||||
pseudoClasses?: Set<string>;
|
||||
}
|
||||
|
||||
export class SelectorsMatch<T extends Node> {
|
||||
/**
|
||||
* Gets the static selectors that match the queried node and the dynamic selectors that may potentially match the queried node.
|
||||
*/
|
||||
selectors: SelectorCore[];
|
||||
|
||||
/**
|
||||
* Gets a map of nodes to attributes and pseudo classes, that may affect the state of the dynamic
|
||||
*/
|
||||
changeMap: ChangeMap<T>;
|
||||
}
|
||||
|
||||
export function fromAstNodes(astRules: ParserNode[]): RuleSet[];
|
||||
|
||||
export function createSelector(sel: string): SelectorCore;
|
||||
@@ -1,9 +1,36 @@
|
||||
import { Node, Declaration, Changes, ChangeMap } from ".";
|
||||
import { isNullOrUndefined } from "../../../utils/types";
|
||||
|
||||
import * as cssParser from "../../../css";
|
||||
import * as parser from "../../../css/parser";
|
||||
|
||||
/**
|
||||
* An interface describing the shape of a type on which the selectors may apply.
|
||||
* Note, the ui/core/view.View implements Node.
|
||||
*/
|
||||
export interface Node {
|
||||
parent?: Node;
|
||||
|
||||
id?: string;
|
||||
nodeName?: string;
|
||||
cssType?: string;
|
||||
cssClasses?: Set<string>;
|
||||
cssPseudoClasses?: Set<string>;
|
||||
getChildIndex?(node: Node): number;
|
||||
getChildAt?(index: number): Node;
|
||||
}
|
||||
|
||||
export interface Declaration {
|
||||
property: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export type ChangeMap<T extends Node> = Map<T, Changes>;
|
||||
|
||||
export interface Changes {
|
||||
attributes?: Set<string>;
|
||||
pseudoClasses?: Set<string>;
|
||||
}
|
||||
|
||||
const enum Specificity {
|
||||
Inline = 1000,
|
||||
Id = 100,
|
||||
@@ -75,6 +102,9 @@ export abstract class SelectorCore {
|
||||
public rarity: Rarity;
|
||||
public combinator: Combinator;
|
||||
public ruleset: RuleSet;
|
||||
/**
|
||||
* Dynamic selectors depend on attributes and pseudo classes.
|
||||
*/
|
||||
public dynamic: boolean;
|
||||
public abstract match(node: Node): boolean;
|
||||
/**
|
||||
@@ -405,7 +435,8 @@ export namespace Selector {
|
||||
}
|
||||
|
||||
export class RuleSet {
|
||||
constructor(public selectors: SelectorCore[], private declarations: Declaration[]) {
|
||||
tag: string | Number;
|
||||
constructor(public selectors: SelectorCore[], public declarations: Declaration[]) {
|
||||
this.selectors.forEach(sel => sel.ruleset = this);
|
||||
}
|
||||
public toString(): string { return `${this.selectors.join(", ")} {${this.declarations.map((d, i) => `${i === 0 ? " " : ""}${d.property}: ${d.value}`).join("; ")} }`; }
|
||||
@@ -589,7 +620,7 @@ export class SelectorsMatch<T extends Node> implements ChangeAccumulator {
|
||||
deps.pseudoClasses.add(pseudoClass);
|
||||
}
|
||||
|
||||
private properties(node: T): Changes {
|
||||
public properties(node: T): Changes {
|
||||
let set = this.changeMap.get(node);
|
||||
if (!set) {
|
||||
this.changeMap.set(node, set = {});
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "css-selector",
|
||||
"main": "css-selector",
|
||||
"types": "css-selector.d.ts"
|
||||
}
|
||||
Reference in New Issue
Block a user