UNPKG

@koalarx/ui

Version:

Koala UI is a modern and accessible component library designed to speed up interface development in Angular projects. With simple integration and clear documentation, you can easily build robust and visually appealing applications.

1 lines 6.05 kB
{"version":3,"file":"koalarx-ui-shared-components-on-this-page.mjs","sources":["../../projects/koala-ui/shared/components/on-this-page/on-this-page.ts","../../projects/koala-ui/shared/components/on-this-page/on-this-page.html","../../projects/koala-ui/shared/components/on-this-page/koalarx-ui-shared-components-on-this-page.ts"],"sourcesContent":["import {\n ChangeDetectionStrategy,\n Component,\n inject,\n input,\n linkedSignal,\n OnDestroy,\n OnInit,\n signal,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { NavigationEnd, Router } from '@angular/router';\nimport { AppConfig } from '@koalarx/ui/core/config';\n\nexport interface OnThisPageLink {\n label: string;\n elementId: string;\n}\n\n@Component({\n selector: 'kl-on-this-page',\n templateUrl: './on-this-page.html',\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class OnThisPage implements OnInit, OnDestroy {\n private readonly router = inject(Router);\n\n readonly translations = inject(AppConfig).translation.onThisPage;\n\n links = input.required<OnThisPageLink[]>();\n activeSection = signal<string | null>(null);\n\n linkSections = linkedSignal(() => {\n const links = this.links();\n const currentSection = this.activeSection();\n\n return links.map((link) => ({\n label: link.label,\n elementId: link.elementId,\n isActive: link.elementId === currentSection,\n }));\n });\n\n private onScroll = () => {\n const links = this.links();\n let current: string | null = null;\n for (const link of links) {\n const el = document.getElementById(link.elementId);\n if (el) {\n const rect = el.getBoundingClientRect();\n if (rect.top <= 250) {\n current = link.elementId;\n }\n }\n }\n if (current) {\n this.activeSection.set(current);\n }\n };\n\n constructor() {\n this.router.events.pipe(takeUntilDestroyed()).subscribe((event) => {\n if (event instanceof NavigationEnd) {\n window.scrollTo({ top: 0 });\n }\n });\n }\n\n ngOnDestroy(): void {\n window.removeEventListener('scroll', this.onScroll);\n }\n\n ngOnInit(): void {\n this.activeSection.set(\n location.hash.match(/#[a-zA-Z]+/)?.[0]?.replace(/#/g, '') || null\n );\n window.addEventListener('scroll', this.onScroll, { passive: true });\n }\n\n scrollTo(elementId: string) {\n const element = document.getElementById(elementId);\n if (element) {\n this.activeSection.set(elementId);\n const link = location.hash.match(/#[a-zA-Z]+/)\n ? location.hash.replace(/#([^#]*)$/, `#${elementId}`)\n : `${location.hash}#${elementId}`;\n\n history.pushState({}, '', link);\n\n const scrollPosition =\n element.getBoundingClientRect().top + window.scrollY - 100;\n\n window.scrollTo({\n top: scrollPosition,\n behavior: 'smooth',\n });\n }\n }\n}\n","<div class=\"fixed\">\n <small class=\"opacity-70\">\n <ng-content select=\"[title]\">\n {{translations.title}}\n </ng-content>\n </small>\n\n <div class=\"flex flex-col gap-2 mt-2\">\n @for (item of linkSections(); track $index) {\n <a class=\"hover:cursor-pointer hover:opacity-90 transition duration-100 opacity-60\" [class]=\"{'opacity-100': item.isActive}\" (click)=\"scrollTo(item.elementId)\">\n {{ item.label }}\n </a>\n }\n </div>\n</div>\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAwBa,UAAU,CAAA;AACJ,IAAA,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAE/B,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,UAAU;AAEhE,IAAA,KAAK,GAAG,KAAK,CAAC,QAAQ,gDAAoB;AAC1C,IAAA,aAAa,GAAG,MAAM,CAAgB,IAAI,yDAAC;AAE3C,IAAA,YAAY,GAAG,YAAY,CAAC,MAAK;AAC/B,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE;AAC1B,QAAA,MAAM,cAAc,GAAG,IAAI,CAAC,aAAa,EAAE;QAE3C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,MAAM;YAC1B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;AACzB,YAAA,QAAQ,EAAE,I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