UNPKG

@ng-doc/app

Version:

<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>

54 lines (50 loc) 4.54 kB
import { NgIf, NgTemplateOutlet } from '@angular/common'; import * as i0 from '@angular/core'; import { inject, ElementRef, Component, ChangeDetectionStrategy, Input } from '@angular/core'; import { RouterLink } from '@angular/router'; import { NgDocDecodeUriComponentPipe } from '@ng-doc/app/pipes'; import { NgDocIconComponent } from '@ng-doc/ui-kit'; import { LOCATION } from '@ng-web-apis/common'; class NgDocPageLinkComponent { constructor() { this.href = ''; this.classes = ''; this.isInCode = false; this.location = inject(LOCATION); this.elementRef = inject(ElementRef); } ngOnInit() { this.isInCode = this.elementRef.nativeElement.closest('code') !== null; } ngOnChanges() { this.link = new URL(this.href, this.location.origin); } get isExternalLink() { return this.link?.origin !== this.location.origin; } get path() { return (!this.isExternalLink ? this.link?.pathname : this.href) ?? ''; } get fragment() { return this.link?.hash.replace(/^#/, '') || undefined; } get queryParams() { return Object.fromEntries(this.link?.searchParams.entries() ?? []); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocPageLinkComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.3", type: NgDocPageLinkComponent, isStandalone: true, selector: "ng-doc-page-link", inputs: { href: "href", classes: "classes" }, usesOnChanges: true, ngImport: i0, template: "<a\n [class]=\"classes\"\n [routerLink]=\"path\"\n [fragment]=\"fragment ? (fragment | decodeUriComponent) : undefined\"\n [queryParams]=\"queryParams\"\n *ngIf=\"!isExternalLink\">\n <ng-container *ngTemplateOutlet=\"content\"></ng-container>\n</a>\n\n<a [class]=\"classes\" [href]=\"path\" *ngIf=\"isExternalLink\" target=\"_blank\">\n <ng-container *ngTemplateOutlet=\"content\"></ng-container>\n <ng-doc-icon icon=\"external-link\" *ngIf=\"!isInCode\"></ng-doc-icon>\n</a>\n\n<ng-template #content>\n <ng-content></ng-content>\n</ng-template>\n", styles: [":host{white-space:nowrap}:host ng-doc-icon{margin-left:calc(var(--ng-doc-base-gutter) / 2);--ng-doc-icon-color: currentColor}\n"], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: NgDocIconComponent, selector: "ng-doc-icon", inputs: ["icon", "customIcon", "size"] }, { kind: "pipe", type: NgDocDecodeUriComponentPipe, name: "decodeUriComponent" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocPageLinkComponent, decorators: [{ type: Component, args: [{ selector: 'ng-doc-page-link', changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgIf, RouterLink, NgTemplateOutlet, NgDocIconComponent, NgDocDecodeUriComponentPipe], template: "<a\n [class]=\"classes\"\n [routerLink]=\"path\"\n [fragment]=\"fragment ? (fragment | decodeUriComponent) : undefined\"\n [queryParams]=\"queryParams\"\n *ngIf=\"!isExternalLink\">\n <ng-container *ngTemplateOutlet=\"content\"></ng-container>\n</a>\n\n<a [class]=\"classes\" [href]=\"path\" *ngIf=\"isExternalLink\" target=\"_blank\">\n <ng-container *ngTemplateOutlet=\"content\"></ng-container>\n <ng-doc-icon icon=\"external-link\" *ngIf=\"!isInCode\"></ng-doc-icon>\n</a>\n\n<ng-template #content>\n <ng-content></ng-content>\n</ng-template>\n", styles: [":host{white-space:nowrap}:host ng-doc-icon{margin-left:calc(var(--ng-doc-base-gutter) / 2);--ng-doc-icon-color: currentColor}\n"] }] }], propDecorators: { href: [{ type: Input, args: [{ required: true }] }], classes: [{ type: Input }] } }); /** * Generated bundle index. Do not edit. */ export { NgDocPageLinkComponent }; //# sourceMappingURL=ng-doc-app-components-page-link.mjs.map