piral-ng
Version:
Plugin for integrating Angular components in Piral.
54 lines • 1.95 kB
JavaScript
import { VERSION } from '@angular/core';
export function getId() {
return Math.random().toString(36);
}
export function getNgVersion() {
return VERSION.major || VERSION.full.split('.')[0];
}
export function getMinVersion() {
const major = getNgVersion();
return `${major}.0.0`;
}
export function getAnnotations(component) {
let annotations = component?.__annotations__;
if (!annotations && typeof Reflect !== 'undefined' && 'getOwnMetadata' in Reflect) {
annotations = Reflect.getOwnMetadata('annotations', component);
}
if (!annotations && typeof component.ɵcmp !== 'undefined') {
annotations = [component.ɵcmp];
}
if (!annotations && typeof component.ɵmod !== 'undefined') {
annotations = [component.ɵmod];
}
return annotations || [];
}
export function hasSelector(component, selector) {
const [annotation] = getAnnotations(component);
if (annotation.selector === selector) {
return true;
}
if (!Array.isArray(annotation.selectors)) {
return false;
}
return annotation.selectors.some((sels) => sels.includes(selector));
}
export function findComponents(exports) {
const components = [];
if (Array.isArray(exports)) {
for (const ex of exports) {
const [annotation] = getAnnotations(ex);
if (annotation) {
if (annotation.exports) {
components.push(...findComponents(annotation.exports));
// Angular 19+ defaults to standalone: true, omitting it from compiled metadata.
// Check selectors to reliably detect components (modules never have selectors).
}
else if (!annotation.imports || annotation.standalone || annotation.selectors?.length) {
components.push(ex);
}
}
}
}
return components;
}
//# sourceMappingURL=utils.js.map