2021-12-10 02:37:01 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2021-12-10 02:37:01 +00:00
|
|
|
*/
|
|
|
|
|
|
2025-03-05 23:31:05 +00:00
|
|
|
import {ngDebugApiIsSupported, ngDebugClient} from './ng-debug-api/ng-debug-api';
|
2023-12-06 16:02:03 +00:00
|
|
|
|
2023-12-07 22:55:05 +00:00
|
|
|
export const runOutsideAngular = (f: () => void): void => {
|
2020-01-27 18:40:18 +00:00
|
|
|
const w = window as any;
|
2020-05-01 21:18:36 +00:00
|
|
|
if (!w.Zone || !w.Zone.current) {
|
2020-08-27 15:55:01 +00:00
|
|
|
f();
|
2020-05-01 21:18:36 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (w.Zone.current._name !== 'angular') {
|
|
|
|
|
w.Zone.current.run(f);
|
2020-01-27 18:40:18 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2021-04-29 17:23:49 +00:00
|
|
|
const parent = w.Zone.current._parent;
|
|
|
|
|
if (parent && parent.run) {
|
|
|
|
|
parent.run(f);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
f();
|
2020-01-27 18:40:18 +00:00
|
|
|
};
|
|
|
|
|
|
2020-03-09 23:13:34 +00:00
|
|
|
export const isCustomElement = (node: Node) => {
|
|
|
|
|
if (typeof customElements === 'undefined') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!(node instanceof HTMLElement)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const tagName = node.tagName.toLowerCase();
|
|
|
|
|
return !!customElements.get(tagName);
|
|
|
|
|
};
|
2023-12-06 16:02:03 +00:00
|
|
|
|
2024-05-28 13:38:27 +00:00
|
|
|
export function isSignal(prop: unknown): prop is (() => unknown) & {set: (value: unknown) => void} {
|
2025-03-05 23:31:05 +00:00
|
|
|
const ng = ngDebugClient();
|
|
|
|
|
if (!ngDebugApiIsSupported(ng, 'isSignal')) {
|
2023-12-06 16:02:03 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return (window as any).ng.isSignal(prop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function unwrapSignal(s: any): any {
|
|
|
|
|
return isSignal(s) ? s() : s;
|
|
|
|
|
}
|