@ -12,6 +12,8 @@
|
||||
// This is important to prevent a build cycle, as @angular/core needs to
|
||||
// be compiled with the compiler.
|
||||
|
||||
import {CssSelector} from './selector';
|
||||
|
||||
export interface Inject { token: any; }
|
||||
export const createInject = makeMetadataFactory<Inject>('Inject', (token: any) => ({token}));
|
||||
export const createInjectionToken = makeMetadataFactory<object>(
|
||||
@ -295,3 +297,67 @@ export interface Route {
|
||||
children?: Route[];
|
||||
loadChildren?: string|Type|any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags used to generate R3-style CSS Selectors. They are pasted from
|
||||
* core/src/render3/projection.ts because they cannot be referenced directly.
|
||||
*/
|
||||
export const enum SelectorFlags {
|
||||
/** Indicates this is the beginning of a new negative selector */
|
||||
NOT = 0b0001,
|
||||
|
||||
/** Mode for matching attributes */
|
||||
ATTRIBUTE = 0b0010,
|
||||
|
||||
/** Mode for matching tag names */
|
||||
ELEMENT = 0b0100,
|
||||
|
||||
/** Mode for matching class names */
|
||||
CLASS = 0b1000,
|
||||
}
|
||||
|
||||
// These are a copy the CSS types from core/src/render3/interfaces/projection.ts
|
||||
// They are duplicated here as they cannot be directly referenced from core.
|
||||
export type R3CssSelector = (string | SelectorFlags)[];
|
||||
export type R3CssSelectorList = R3CssSelector[];
|
||||
|
||||
function parserSelectorToSimpleSelector(selector: CssSelector): R3CssSelector {
|
||||
const classes = selector.classNames && selector.classNames.length ?
|
||||
[SelectorFlags.CLASS, ...selector.classNames] :
|
||||
[];
|
||||
const elementName = selector.element && selector.element !== '*' ? selector.element : '';
|
||||
return [elementName, ...selector.attrs, ...classes];
|
||||
}
|
||||
|
||||
function parserSelectorToNegativeSelector(selector: CssSelector): R3CssSelector {
|
||||
const classes = selector.classNames && selector.classNames.length ?
|
||||
[SelectorFlags.CLASS, ...selector.classNames] :
|
||||
[];
|
||||
|
||||
if (selector.element) {
|
||||
return [
|
||||
SelectorFlags.NOT | SelectorFlags.ELEMENT, selector.element, ...selector.attrs, ...classes
|
||||
];
|
||||
} else if (selector.attrs.length) {
|
||||
return [SelectorFlags.NOT | SelectorFlags.ATTRIBUTE, ...selector.attrs, ...classes];
|
||||
} else {
|
||||
return selector.classNames && selector.classNames.length ?
|
||||
[SelectorFlags.NOT | SelectorFlags.CLASS, ...selector.classNames] :
|
||||
[];
|
||||
}
|
||||
}
|
||||
|
||||
function parserSelectorToR3Selector(selector: CssSelector): R3CssSelector {
|
||||
const positive = parserSelectorToSimpleSelector(selector);
|
||||
|
||||
const negative: R3CssSelectorList = selector.notSelectors && selector.notSelectors.length ?
|
||||
selector.notSelectors.map(notSelector => parserSelectorToNegativeSelector(notSelector)) :
|
||||
[];
|
||||
|
||||
return positive.concat(...negative);
|
||||
}
|
||||
|
||||
export function parseSelectorToR3Selector(selector: string): R3CssSelectorList {
|
||||
const selectors = CssSelector.parse(selector);
|
||||
return selectors.map(parserSelectorToR3Selector);
|
||||
}
|
||||
|
Reference in New Issue
Block a user