/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/platform-browser/src/dom/debug/by.ts
69 строк
2 KB
Joey Perrott
refactor: update license text to point to angular.dev (#57901)
24 сен 2024, 16:33
24 сен 2024, 16:33
9dbe6fc
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {ɵgetDOM as getDOM} from '@angular/common'; import {DebugElement, DebugNode, Predicate, Type} from '@angular/core'; /** * Predicates for use with {@link DebugElement}'s query functions. * * @publicApi */ export class By { /** * Match all nodes. * * @usageNotes * ### Example * * {@example platform-browser/dom/debug/ts/by/by.ts region='by_all'} */ static all(): Predicate<DebugNode> { return () => true; } /** * Match elements by the given CSS selector. * * @usageNotes * ### Example * * {@example platform-browser/dom/debug/ts/by/by.ts region='by_css'} */ static css(selector: string): Predicate<DebugElement> { return (debugElement) => { return debugElement.nativeElement != null ? elementMatches(debugElement.nativeElement, selector) : false; }; } /** * Match nodes that have the given directive present. * * @usageNotes * ### Example * * {@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'} */ static directive(type: Type<any>): Predicate<DebugNode> { return (debugNode) => debugNode.providerTokens!.indexOf(type) !== -1; } } function elementMatches(n: any, selector: string): boolean { if (getDOM().isElementNode(n)) { return ( (n.matches && n.matches(selector)) || (n.msMatchesSelector && n.msMatchesSelector(selector)) || (n.webkitMatchesSelector && n.webkitMatchesSelector(selector)) ); } return false; }