create-ngmd 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/index.mjs +165 -0
- package/package.json +49 -0
- package/template/README.md +26 -0
- package/template/angular.json +54 -0
- package/template/index.html +47 -0
- package/template/link-guard.plugin.ts +190 -0
- package/template/package.json +76 -0
- package/template/page-meta.plugin.ts +132 -0
- package/template/public/analog.svg +1 -0
- package/template/public/favicon.ico +0 -0
- package/template/public/favicon.svg +46 -0
- package/template/public/logo-mark.svg +46 -0
- package/template/public/logo.svg +53 -0
- package/template/public/vite.svg +1 -0
- package/template/sitemap.plugin.ts +148 -0
- package/template/src/app/app.config.server.ts +10 -0
- package/template/src/app/app.config.ts +59 -0
- package/template/src/app/app.spec.ts +20 -0
- package/template/src/app/app.ts +260 -0
- package/template/src/app/components/breadcrumb.ts +76 -0
- package/template/src/app/components/code-copy.ts +90 -0
- package/template/src/app/components/code-group.ts +70 -0
- package/template/src/app/components/command-palette.ts +299 -0
- package/template/src/app/components/external-links.ts +55 -0
- package/template/src/app/components/heading-anchors.ts +95 -0
- package/template/src/app/components/hlm-card.ts +31 -0
- package/template/src/app/components/media-enhancer.ts +95 -0
- package/template/src/app/components/page-footer.ts +107 -0
- package/template/src/app/components/sidebar.ts +65 -0
- package/template/src/app/components/toc.ts +131 -0
- package/template/src/app/layout-mode.service.ts +10 -0
- package/template/src/app/pages/[...not-found].page.ts +47 -0
- package/template/src/app/pages/index.page.ts +28 -0
- package/template/src/app/pages/welcome.page.ts +18 -0
- package/template/src/app/theme.ts +54 -0
- package/template/src/app/title-strategy.ts +48 -0
- package/template/src/app/ui/alert.ts +46 -0
- package/template/src/app/ui/callout.ts +57 -0
- package/template/src/app/ui/card.ts +41 -0
- package/template/src/app/ui/code-block.ts +76 -0
- package/template/src/app/ui/hero.ts +42 -0
- package/template/src/app/ui/image.ts +26 -0
- package/template/src/app/ui/index.ts +45 -0
- package/template/src/app/ui/pill.ts +42 -0
- package/template/src/app/ui/tabs.ts +76 -0
- package/template/src/app/ui/video.ts +40 -0
- package/template/src/app/ui/workflow.ts +51 -0
- package/template/src/content/welcome.md +19 -0
- package/template/src/main.server.ts +7 -0
- package/template/src/main.ts +6 -0
- package/template/src/marked-extensions/index.ts +47 -0
- package/template/src/marked-extensions/ngmd-code-group.ts +126 -0
- package/template/src/marked-extensions/ngmd-code-highlight.ts +102 -0
- package/template/src/marked-extensions/ngmd-code-import.ts +118 -0
- package/template/src/marked-extensions/ngmd-image.ts +41 -0
- package/template/src/marked-extensions/ngmd-keywords.ts +75 -0
- package/template/src/marked-extensions/ngmd-video.ts +48 -0
- package/template/src/marked-extensions/shiki-shared.ts +42 -0
- package/template/src/ngmd.config.ts +98 -0
- package/template/src/server/routes/api/v1/hello.ts +3 -0
- package/template/src/styles.css +347 -0
- package/template/src/test-setup.ts +6 -0
- package/template/src/vite-env.d.ts +9 -0
- package/template/tsconfig.app.json +14 -0
- package/template/tsconfig.json +34 -0
- package/template/tsconfig.spec.json +11 -0
- package/template/vite.config.ts +78 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { Component, computed, inject, OnInit, signal } from '@angular/core';
|
|
2
|
+
import { NavigationEnd, Router, RouterLink, RouterOutlet } from '@angular/router';
|
|
3
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
4
|
+
import { filter, map, startWith } from 'rxjs';
|
|
5
|
+
import {
|
|
6
|
+
LucideAngularModule,
|
|
7
|
+
Github,
|
|
8
|
+
Menu,
|
|
9
|
+
X,
|
|
10
|
+
Search,
|
|
11
|
+
Sun,
|
|
12
|
+
Moon,
|
|
13
|
+
SunMoon,
|
|
14
|
+
} from 'lucide-angular';
|
|
15
|
+
import { ThemeService } from './theme';
|
|
16
|
+
import { LayoutMode } from './layout-mode.service';
|
|
17
|
+
import { CommandPalette } from './components/command-palette';
|
|
18
|
+
import { Sidebar } from './components/sidebar';
|
|
19
|
+
import { Breadcrumb } from './components/breadcrumb';
|
|
20
|
+
import { Toc } from './components/toc';
|
|
21
|
+
import { CodeCopy } from './components/code-copy';
|
|
22
|
+
import { ExternalLinks } from './components/external-links';
|
|
23
|
+
import { HeadingAnchors } from './components/heading-anchors';
|
|
24
|
+
import { CodeGroup } from './components/code-group';
|
|
25
|
+
import { PageFooter } from './components/page-footer';
|
|
26
|
+
import { MediaEnhancer } from './components/media-enhancer';
|
|
27
|
+
|
|
28
|
+
@Component({
|
|
29
|
+
selector: 'app-root',
|
|
30
|
+
imports: [
|
|
31
|
+
RouterLink,
|
|
32
|
+
RouterOutlet,
|
|
33
|
+
LucideAngularModule,
|
|
34
|
+
CommandPalette,
|
|
35
|
+
Sidebar,
|
|
36
|
+
Breadcrumb,
|
|
37
|
+
Toc,
|
|
38
|
+
CodeCopy,
|
|
39
|
+
ExternalLinks,
|
|
40
|
+
HeadingAnchors,
|
|
41
|
+
CodeGroup,
|
|
42
|
+
MediaEnhancer,
|
|
43
|
+
PageFooter,
|
|
44
|
+
],
|
|
45
|
+
template: `
|
|
46
|
+
<div class="min-h-screen flex flex-col">
|
|
47
|
+
<header
|
|
48
|
+
class="sticky top-0 z-30 flex items-center gap-4 border-b border-zinc-200/60 dark:border-zinc-800/60 backdrop-blur-sm px-4 py-3"
|
|
49
|
+
>
|
|
50
|
+
@if (showSidebar()) {
|
|
51
|
+
<button
|
|
52
|
+
type="button"
|
|
53
|
+
(click)="drawerOpen.set(!drawerOpen())"
|
|
54
|
+
class="lg:hidden rounded p-1.5 hover:bg-zinc-100 dark:hover:bg-zinc-900"
|
|
55
|
+
[attr.aria-label]="drawerOpen() ? 'Close menu' : 'Open menu'"
|
|
56
|
+
>
|
|
57
|
+
<i-lucide [img]="drawerOpen() ? closeIcon : menuIcon" class="size-5"></i-lucide>
|
|
58
|
+
</button>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
<a routerLink="/" class="flex items-center gap-2 text-lg font-bold tracking-tight font-[Geist_Mono,ui-monospace,monospace]">
|
|
62
|
+
<img
|
|
63
|
+
src="/logo-mark.svg"
|
|
64
|
+
alt=""
|
|
65
|
+
class="size-[34px] text-zinc-900 dark:text-zinc-50"
|
|
66
|
+
aria-hidden="true"
|
|
67
|
+
/>
|
|
68
|
+
NgMd
|
|
69
|
+
</a>
|
|
70
|
+
|
|
71
|
+
<nav class="hidden sm:flex items-center gap-1 text-sm">
|
|
72
|
+
<a
|
|
73
|
+
routerLink="/welcome"
|
|
74
|
+
class="rounded px-3 py-1.5 hover:bg-zinc-100 dark:hover:bg-zinc-900"
|
|
75
|
+
>
|
|
76
|
+
Docs
|
|
77
|
+
</a>
|
|
78
|
+
<a
|
|
79
|
+
routerLink="/support"
|
|
80
|
+
class="rounded px-3 py-1.5 hover:bg-zinc-100 dark:hover:bg-zinc-900"
|
|
81
|
+
>
|
|
82
|
+
Support
|
|
83
|
+
</a>
|
|
84
|
+
</nav>
|
|
85
|
+
|
|
86
|
+
<div class="ml-auto flex items-center gap-2">
|
|
87
|
+
<button
|
|
88
|
+
type="button"
|
|
89
|
+
(click)="palette.toggle()"
|
|
90
|
+
class="hidden lg:inline-flex items-center gap-2 rounded-lg border border-zinc-200 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-900 px-3 py-1.5 text-sm text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800 min-w-56"
|
|
91
|
+
>
|
|
92
|
+
<i-lucide [img]="searchIcon" class="size-4"></i-lucide>
|
|
93
|
+
<span class="flex-1 text-left">Search documentation...</span>
|
|
94
|
+
<span class="flex items-center gap-0.5">
|
|
95
|
+
<kbd
|
|
96
|
+
class="inline-flex h-5 min-w-5 items-center justify-center rounded border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-950 px-1 text-xs font-medium"
|
|
97
|
+
>
|
|
98
|
+
⌘
|
|
99
|
+
</kbd>
|
|
100
|
+
<kbd
|
|
101
|
+
class="inline-flex h-5 min-w-5 items-center justify-center rounded border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-950 px-1 text-xs font-medium"
|
|
102
|
+
>
|
|
103
|
+
K
|
|
104
|
+
</kbd>
|
|
105
|
+
</span>
|
|
106
|
+
</button>
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
(click)="palette.toggle()"
|
|
110
|
+
class="lg:hidden rounded p-1.5 hover:bg-zinc-100 dark:hover:bg-zinc-900"
|
|
111
|
+
aria-label="Search"
|
|
112
|
+
>
|
|
113
|
+
<i-lucide [img]="searchIcon" class="size-5"></i-lucide>
|
|
114
|
+
</button>
|
|
115
|
+
<span class="h-4 w-px bg-zinc-300/60 dark:bg-zinc-700/60"></span>
|
|
116
|
+
<a
|
|
117
|
+
href="https://github.com"
|
|
118
|
+
target="_blank"
|
|
119
|
+
rel="noopener noreferrer"
|
|
120
|
+
class="rounded p-1.5 hover:bg-zinc-100 dark:hover:bg-zinc-900"
|
|
121
|
+
aria-label="GitHub"
|
|
122
|
+
>
|
|
123
|
+
<i-lucide [img]="githubIcon" class="size-5"></i-lucide>
|
|
124
|
+
</a>
|
|
125
|
+
<span class="h-4 w-px bg-zinc-300/60 dark:bg-zinc-700/60"></span>
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
(click)="theme.cycle()"
|
|
129
|
+
class="rounded p-1.5 hover:bg-zinc-100 dark:hover:bg-zinc-900"
|
|
130
|
+
[attr.aria-label]="'Theme: ' + theme.mode()"
|
|
131
|
+
[title]="'Theme: ' + theme.mode()"
|
|
132
|
+
>
|
|
133
|
+
<i-lucide
|
|
134
|
+
[img]="
|
|
135
|
+
theme.mode() === 'light'
|
|
136
|
+
? sunIcon
|
|
137
|
+
: theme.mode() === 'dark'
|
|
138
|
+
? moonIcon
|
|
139
|
+
: autoIcon
|
|
140
|
+
"
|
|
141
|
+
class="size-5"
|
|
142
|
+
></i-lucide>
|
|
143
|
+
</button>
|
|
144
|
+
</div>
|
|
145
|
+
</header>
|
|
146
|
+
|
|
147
|
+
<div class="flex flex-1">
|
|
148
|
+
@if (showSidebar()) {
|
|
149
|
+
<aside
|
|
150
|
+
class="hidden lg:flex w-64 shrink-0 flex-col border-r border-zinc-200 dark:border-zinc-800 p-4 overflow-y-auto sticky top-[57px] self-start h-[calc(100vh-57px)]"
|
|
151
|
+
>
|
|
152
|
+
<app-sidebar />
|
|
153
|
+
</aside>
|
|
154
|
+
|
|
155
|
+
@if (drawerOpen()) {
|
|
156
|
+
<div
|
|
157
|
+
class="lg:hidden fixed inset-0 z-40 bg-black/50"
|
|
158
|
+
(click)="drawerOpen.set(false)"
|
|
159
|
+
></div>
|
|
160
|
+
<aside
|
|
161
|
+
class="lg:hidden fixed left-0 top-[57px] bottom-0 z-40 w-64 overflow-y-auto border-r border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 p-4"
|
|
162
|
+
>
|
|
163
|
+
<app-sidebar />
|
|
164
|
+
</aside>
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
<main class="flex-1 min-w-0">
|
|
169
|
+
@if (showBreadcrumb()) {
|
|
170
|
+
<app-breadcrumb />
|
|
171
|
+
}
|
|
172
|
+
@if (showToc()) {
|
|
173
|
+
<details
|
|
174
|
+
class="xl:hidden mx-4 sm:mx-6 mt-4 rounded-lg border border-zinc-200 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-900 group"
|
|
175
|
+
>
|
|
176
|
+
<summary
|
|
177
|
+
class="flex items-center justify-between cursor-pointer list-none px-4 py-2.5 text-sm font-semibold"
|
|
178
|
+
>
|
|
179
|
+
On this page
|
|
180
|
+
<span class="text-zinc-400 transition-transform group-open:rotate-180">▾</span>
|
|
181
|
+
</summary>
|
|
182
|
+
<div class="px-4 pb-4">
|
|
183
|
+
<app-toc [showActive]="false" />
|
|
184
|
+
</div>
|
|
185
|
+
</details>
|
|
186
|
+
}
|
|
187
|
+
<router-outlet />
|
|
188
|
+
@if (showFooter()) {
|
|
189
|
+
<div class="mx-auto max-w-3xl px-4 sm:px-8">
|
|
190
|
+
<app-page-footer />
|
|
191
|
+
</div>
|
|
192
|
+
}
|
|
193
|
+
</main>
|
|
194
|
+
|
|
195
|
+
@if (showToc()) {
|
|
196
|
+
<aside
|
|
197
|
+
class="hidden xl:block w-56 shrink-0 border-l border-zinc-200 dark:border-zinc-800 p-6 sticky top-[57px] self-start max-h-[calc(100vh-57px)] overflow-y-auto"
|
|
198
|
+
>
|
|
199
|
+
<p class="mb-3 text-sm font-semibold">On this page</p>
|
|
200
|
+
<app-toc />
|
|
201
|
+
</aside>
|
|
202
|
+
}
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<app-command-palette #palette />
|
|
207
|
+
<app-code-copy />
|
|
208
|
+
<app-external-links />
|
|
209
|
+
<app-heading-anchors />
|
|
210
|
+
<app-code-group />
|
|
211
|
+
<app-media-enhancer />
|
|
212
|
+
`,
|
|
213
|
+
})
|
|
214
|
+
export class App implements OnInit {
|
|
215
|
+
readonly theme = inject(ThemeService);
|
|
216
|
+
private readonly router = inject(Router);
|
|
217
|
+
private readonly layout = inject(LayoutMode);
|
|
218
|
+
|
|
219
|
+
readonly menuIcon = Menu;
|
|
220
|
+
readonly closeIcon = X;
|
|
221
|
+
readonly searchIcon = Search;
|
|
222
|
+
readonly githubIcon = Github;
|
|
223
|
+
readonly sunIcon = Sun;
|
|
224
|
+
readonly moonIcon = Moon;
|
|
225
|
+
readonly autoIcon = SunMoon;
|
|
226
|
+
|
|
227
|
+
readonly drawerOpen = signal(false);
|
|
228
|
+
|
|
229
|
+
private readonly url = toSignal(
|
|
230
|
+
this.router.events.pipe(
|
|
231
|
+
filter((e) => e instanceof NavigationEnd),
|
|
232
|
+
map(() => this.router.url),
|
|
233
|
+
startWith(this.router.url),
|
|
234
|
+
),
|
|
235
|
+
{ initialValue: '/' },
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
private readonly cleanUrl = computed(() => this.url().split('?')[0].split('#')[0]);
|
|
239
|
+
private readonly isDocsRoute = computed(
|
|
240
|
+
() =>
|
|
241
|
+
this.cleanUrl() !== '/' &&
|
|
242
|
+
this.cleanUrl() !== '' &&
|
|
243
|
+
!this.layout.chromeHidden(),
|
|
244
|
+
);
|
|
245
|
+
readonly showSidebar = this.isDocsRoute;
|
|
246
|
+
readonly showBreadcrumb = this.isDocsRoute;
|
|
247
|
+
readonly showToc = this.isDocsRoute;
|
|
248
|
+
readonly showFooter = this.isDocsRoute;
|
|
249
|
+
|
|
250
|
+
ngOnInit(): void {
|
|
251
|
+
this.theme.initFromStorage();
|
|
252
|
+
this.router.events.pipe(filter((e) => e instanceof NavigationEnd)).subscribe(() => {
|
|
253
|
+
this.drawerOpen.set(false);
|
|
254
|
+
if (typeof window === 'undefined' || window.location.hash) return;
|
|
255
|
+
setTimeout(() => {
|
|
256
|
+
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
257
|
+
}, 0);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Component, computed, inject } from '@angular/core';
|
|
2
|
+
import { Router, NavigationEnd, RouterLink } from '@angular/router';
|
|
3
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
4
|
+
import { filter, map, startWith } from 'rxjs';
|
|
5
|
+
import { LucideAngularModule, ChevronRight, House } from 'lucide-angular';
|
|
6
|
+
|
|
7
|
+
interface Crumb {
|
|
8
|
+
label: string;
|
|
9
|
+
href: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const LABELS: Record<string, string> = {
|
|
13
|
+
'': 'Home',
|
|
14
|
+
welcome: 'Introduction',
|
|
15
|
+
'getting-started': 'Getting Started',
|
|
16
|
+
installation: 'Installation',
|
|
17
|
+
'quick-start': 'Quick Start',
|
|
18
|
+
introduction: 'Introduction',
|
|
19
|
+
about: 'About & Credits',
|
|
20
|
+
concepts: 'Core Concepts',
|
|
21
|
+
'markdown-routes': 'Markdown Routes',
|
|
22
|
+
theming: 'Theming',
|
|
23
|
+
components: 'Components',
|
|
24
|
+
support: 'Support',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
@Component({
|
|
28
|
+
selector: 'app-breadcrumb',
|
|
29
|
+
imports: [RouterLink, LucideAngularModule],
|
|
30
|
+
template: `
|
|
31
|
+
@if (crumbs().length > 0) {
|
|
32
|
+
<nav
|
|
33
|
+
class="flex items-center gap-1.5 px-6 py-3 text-sm border-b border-zinc-200 dark:border-zinc-800"
|
|
34
|
+
>
|
|
35
|
+
<a routerLink="/" class="text-zinc-500 hover:text-zinc-900 dark:hover:text-zinc-50">
|
|
36
|
+
<i-lucide [img]="home" class="size-4"></i-lucide>
|
|
37
|
+
</a>
|
|
38
|
+
@for (crumb of crumbs(); track crumb.href; let last = $last) {
|
|
39
|
+
<i-lucide [img]="chevron" class="size-3.5 text-zinc-400"></i-lucide>
|
|
40
|
+
@if (last) {
|
|
41
|
+
<span class="font-medium">{{ crumb.label }}</span>
|
|
42
|
+
} @else {
|
|
43
|
+
<span class="text-zinc-500">{{ crumb.label }}</span>
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
</nav>
|
|
47
|
+
}
|
|
48
|
+
`,
|
|
49
|
+
})
|
|
50
|
+
export class Breadcrumb {
|
|
51
|
+
private readonly router = inject(Router);
|
|
52
|
+
readonly home = House;
|
|
53
|
+
readonly chevron = ChevronRight;
|
|
54
|
+
|
|
55
|
+
private readonly url = toSignal(
|
|
56
|
+
this.router.events.pipe(
|
|
57
|
+
filter((e) => e instanceof NavigationEnd),
|
|
58
|
+
map(() => this.router.url),
|
|
59
|
+
startWith(this.router.url),
|
|
60
|
+
),
|
|
61
|
+
{ initialValue: '/' },
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
readonly crumbs = computed<Crumb[]>(() => {
|
|
65
|
+
const url = this.url().split('?')[0].split('#')[0];
|
|
66
|
+
const segments = url.split('/').filter((s) => s.length > 0);
|
|
67
|
+
return segments.map((segment, i) => ({
|
|
68
|
+
label: LABELS[segment] ?? this.humanize(segment),
|
|
69
|
+
href: '/' + segments.slice(0, i + 1).join('/'),
|
|
70
|
+
}));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
private humanize(segment: string): string {
|
|
74
|
+
return segment.replace(/-/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AfterViewInit,
|
|
3
|
+
Component,
|
|
4
|
+
DestroyRef,
|
|
5
|
+
inject,
|
|
6
|
+
} from '@angular/core';
|
|
7
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
8
|
+
import { NavigationEnd, Router } from '@angular/router';
|
|
9
|
+
import { filter } from 'rxjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Scans rendered markdown for <pre> code blocks and injects a copy button
|
|
13
|
+
* into each one. Runs on initial mount and after every route change.
|
|
14
|
+
*/
|
|
15
|
+
@Component({
|
|
16
|
+
selector: 'app-code-copy',
|
|
17
|
+
template: '',
|
|
18
|
+
styles: `
|
|
19
|
+
:host { display: none; }
|
|
20
|
+
`,
|
|
21
|
+
})
|
|
22
|
+
export class CodeCopy implements AfterViewInit {
|
|
23
|
+
private readonly router = inject(Router);
|
|
24
|
+
private readonly destroyRef = inject(DestroyRef);
|
|
25
|
+
|
|
26
|
+
ngAfterViewInit(): void {
|
|
27
|
+
this.enhanceWithRetry();
|
|
28
|
+
this.router.events
|
|
29
|
+
.pipe(
|
|
30
|
+
filter((e) => e instanceof NavigationEnd),
|
|
31
|
+
takeUntilDestroyed(this.destroyRef),
|
|
32
|
+
)
|
|
33
|
+
.subscribe(() => this.enhanceWithRetry());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private enhanceWithRetry(attempt = 0): void {
|
|
37
|
+
if (typeof document === 'undefined' || attempt > 20) return;
|
|
38
|
+
const pres = document.querySelectorAll('main pre:not([data-copy-enhanced])');
|
|
39
|
+
if (pres.length === 0) {
|
|
40
|
+
setTimeout(() => this.enhanceWithRetry(attempt + 1), 50);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
pres.forEach((pre) => this.enhance(pre as HTMLElement));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private enhance(pre: HTMLElement): void {
|
|
47
|
+
pre.setAttribute('data-copy-enhanced', 'true');
|
|
48
|
+
pre.style.position = 'relative';
|
|
49
|
+
|
|
50
|
+
const button = document.createElement('button');
|
|
51
|
+
button.type = 'button';
|
|
52
|
+
button.setAttribute('aria-label', 'Copy code');
|
|
53
|
+
button.className =
|
|
54
|
+
'absolute top-2 right-2 inline-flex items-center justify-center size-7 rounded-md bg-zinc-800/80 text-zinc-300 hover:bg-zinc-700 hover:text-white opacity-0 transition-opacity focus:opacity-100';
|
|
55
|
+
button.innerHTML = `
|
|
56
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
57
|
+
<rect width="14" height="14" x="8" y="8" rx="2" ry="2"/>
|
|
58
|
+
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>
|
|
59
|
+
</svg>
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
pre.addEventListener('mouseenter', () => (button.style.opacity = '1'));
|
|
63
|
+
pre.addEventListener('mouseleave', () => (button.style.opacity = '0'));
|
|
64
|
+
|
|
65
|
+
button.addEventListener('click', async (e) => {
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
const code = pre.querySelector('code')?.textContent ?? pre.textContent ?? '';
|
|
68
|
+
try {
|
|
69
|
+
await navigator.clipboard.writeText(code);
|
|
70
|
+
button.innerHTML = `
|
|
71
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
72
|
+
<polyline points="20 6 9 17 4 12"/>
|
|
73
|
+
</svg>
|
|
74
|
+
`;
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
button.innerHTML = `
|
|
77
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
78
|
+
<rect width="14" height="14" x="8" y="8" rx="2" ry="2"/>
|
|
79
|
+
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>
|
|
80
|
+
</svg>
|
|
81
|
+
`;
|
|
82
|
+
}, 1500);
|
|
83
|
+
} catch {
|
|
84
|
+
// clipboard API not available, fall back silently
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
pre.appendChild(button);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AfterViewInit, Component, DestroyRef, inject } from '@angular/core';
|
|
2
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
3
|
+
import { NavigationEnd, Router } from '@angular/router';
|
|
4
|
+
import { filter } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Wires tab-switching for `<div class="ngmd-code-group">` blocks emitted by
|
|
8
|
+
* the `ngmd-code-group` marked extension. Each tab's `data-target` points at
|
|
9
|
+
* a sibling panel's `data-id`; clicking flips `data-active` on the pair.
|
|
10
|
+
*
|
|
11
|
+
* Same pattern as CodeCopy / ExternalLinks / HeadingAnchors: scan `<main>`
|
|
12
|
+
* after each route change, idempotent via `data-enhanced` marker.
|
|
13
|
+
*/
|
|
14
|
+
@Component({
|
|
15
|
+
selector: 'app-code-group',
|
|
16
|
+
template: '',
|
|
17
|
+
styles: `:host { display: none; }`,
|
|
18
|
+
})
|
|
19
|
+
export class CodeGroup implements AfterViewInit {
|
|
20
|
+
private readonly router = inject(Router);
|
|
21
|
+
private readonly destroyRef = inject(DestroyRef);
|
|
22
|
+
|
|
23
|
+
ngAfterViewInit(): void {
|
|
24
|
+
this.enhanceWithRetry();
|
|
25
|
+
this.router.events
|
|
26
|
+
.pipe(
|
|
27
|
+
filter((e) => e instanceof NavigationEnd),
|
|
28
|
+
takeUntilDestroyed(this.destroyRef),
|
|
29
|
+
)
|
|
30
|
+
.subscribe(() => this.enhanceWithRetry());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private enhanceWithRetry(attempt = 0): void {
|
|
34
|
+
if (typeof document === 'undefined' || attempt > 20) return;
|
|
35
|
+
const groups = document.querySelectorAll<HTMLElement>(
|
|
36
|
+
'main .ngmd-code-group:not([data-enhanced])',
|
|
37
|
+
);
|
|
38
|
+
if (groups.length === 0) {
|
|
39
|
+
setTimeout(() => this.enhanceWithRetry(attempt + 1), 50);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
groups.forEach((group) => this.enhance(group));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private enhance(group: HTMLElement): void {
|
|
46
|
+
group.setAttribute('data-enhanced', 'true');
|
|
47
|
+
const tabs = group.querySelectorAll<HTMLButtonElement>(
|
|
48
|
+
'.ngmd-code-group__tab',
|
|
49
|
+
);
|
|
50
|
+
const panels = group.querySelectorAll<HTMLElement>(
|
|
51
|
+
'.ngmd-code-group__panel',
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
tabs.forEach((tab) => {
|
|
55
|
+
tab.addEventListener('click', () => {
|
|
56
|
+
const target = tab.getAttribute('data-target');
|
|
57
|
+
if (!target) return;
|
|
58
|
+
tabs.forEach((t) =>
|
|
59
|
+
t.setAttribute('data-active', t === tab ? 'true' : 'false'),
|
|
60
|
+
);
|
|
61
|
+
panels.forEach((p) =>
|
|
62
|
+
p.setAttribute(
|
|
63
|
+
'data-active',
|
|
64
|
+
p.getAttribute('data-id') === target ? 'true' : 'false',
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|