@frontfactory/vitepress-theme 1.9.0 → 1.11.0
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/CHANGELOG.md +31 -0
- package/README.md +12 -405
- package/config.js +7 -10
- package/dist/style.css +1 -1
- package/node/banner.d.ts +3 -0
- package/node/banner.js +14 -0
- package/node/blog.d.ts +8 -0
- package/node/blog.js +46 -0
- package/node/options.d.ts +1 -0
- package/node/options.js +17 -0
- package/node/page-actions.d.ts +12 -0
- package/node/page-actions.js +34 -0
- package/node/pages.js +20 -8
- package/node/rss.js +10 -15
- package/package.json +2 -1
- package/src/blog/posts.data.ts +5 -3
- package/src/components/FfBackToTop.vue +5 -35
- package/src/components/FfBanner.vue +3 -2
- package/src/components/FfCopyStatus.vue +6 -14
- package/src/components/FfDocMeta.vue +13 -17
- package/src/components/FfFeedback.vue +4 -9
- package/src/components/FfFooter.vue +2 -2
- package/src/components/FfHero.vue +2 -2
- package/src/components/FfPost.vue +2 -1
- package/src/components/FfProgress.vue +6 -40
- package/src/composables/blog.ts +8 -14
- package/src/composables/copy.ts +4 -11
- package/src/composables/frame.ts +50 -0
- package/src/composables/transient.ts +27 -0
- package/src/content/Card.vue +16 -4
- package/src/content/Tabs.vue +3 -0
- package/src/styles/_code.scss +6 -8
- package/src/styles/_content.scss +22 -3
- package/src/styles/_doc.scss +65 -1
- package/src/styles/_docsearch.scss +94 -0
- package/src/styles/_home.scss +28 -13
- package/src/styles/_mixins.scss +24 -0
- package/src/styles/_motion.scss +1 -1
- package/src/styles/_nav.scss +102 -0
- package/src/styles/_not-found.scss +81 -0
- package/src/styles/_team.scss +141 -0
- package/src/styles/index.scss +3 -0
- package/src/types.ts +3 -2
- package/types/composables/blog.d.ts +3 -4
- package/types/composables/frame.d.ts +6 -0
- package/types/composables/transient.d.ts +6 -0
- package/types/content/Tabs.vue.d.ts +2 -0
- package/types/types.d.ts +3 -2
package/src/blog/posts.data.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createContentLoader, type LoaderModule } from 'vitepress';
|
|
2
2
|
import type { ThemeConfig } from '../types.ts';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
blogDir, firstHeading, hasValidDate, toTags
|
|
5
|
+
} from '../../node/blog.js';
|
|
4
6
|
|
|
5
7
|
export interface Post {
|
|
6
8
|
url: string
|
|
@@ -34,10 +36,10 @@ const loader: LoaderModule<Post[]> = createContentLoader([
|
|
|
34
36
|
.filter(({ frontmatter }) => hasValidDate(frontmatter.date))
|
|
35
37
|
.map(({ url, src, frontmatter }): Post => ({
|
|
36
38
|
url,
|
|
37
|
-
title: frontmatter.title ||
|
|
39
|
+
title: frontmatter.title || firstHeading(src ?? '') || url,
|
|
38
40
|
date: new Date(frontmatter.date).toISOString(),
|
|
39
41
|
author: frontmatter.author,
|
|
40
|
-
tags:
|
|
42
|
+
tags: toTags(frontmatter.tags).map(String),
|
|
41
43
|
excerpt: frontmatter.excerpt
|
|
42
44
|
}))
|
|
43
45
|
.sort((a, b) => b.date.localeCompare(a.date));
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
computed, onMounted, ref, watchEffect
|
|
4
|
-
} from 'vue';
|
|
2
|
+
import { computed, ref } from 'vue';
|
|
5
3
|
import { useData } from 'vitepress';
|
|
6
4
|
import { useLabels, useThemeOptions } from '../composables/options';
|
|
5
|
+
import { useFrameListener } from '../composables/frame';
|
|
7
6
|
|
|
8
7
|
const { theme } = useData();
|
|
9
8
|
const options = useThemeOptions();
|
|
@@ -21,18 +20,6 @@ function update() {
|
|
|
21
20
|
visible.value = window.scrollY > window.innerHeight;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
// At most one state update per frame, however many scroll events fire.
|
|
25
|
-
let frame = 0;
|
|
26
|
-
|
|
27
|
-
function onScroll() {
|
|
28
|
-
if (!frame) {
|
|
29
|
-
frame = requestAnimationFrame(() => {
|
|
30
|
-
frame = 0;
|
|
31
|
-
update();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
23
|
function toTop() {
|
|
37
24
|
window.scrollTo({
|
|
38
25
|
top: 0,
|
|
@@ -40,26 +27,9 @@ function toTop() {
|
|
|
40
27
|
});
|
|
41
28
|
}
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
watchEffect((onCleanup) => {
|
|
47
|
-
if (!enabled.value) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
update();
|
|
52
|
-
window.addEventListener('scroll', onScroll, {
|
|
53
|
-
passive: true
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
onCleanup(() => {
|
|
57
|
-
cancelAnimationFrame(frame);
|
|
58
|
-
frame = 0;
|
|
59
|
-
window.removeEventListener('scroll', onScroll);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
30
|
+
useFrameListener(enabled, update, [
|
|
31
|
+
'scroll'
|
|
32
|
+
]);
|
|
63
33
|
</script>
|
|
64
34
|
|
|
65
35
|
<template>
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useLabels, useThemeOptions } from '../composables/options';
|
|
6
6
|
import { normalizeLink } from '../internal';
|
|
7
|
+
import { BANNER_DISMISSED_CLASS, bannerKey } from '../../node/banner.js';
|
|
7
8
|
|
|
8
9
|
const options = useThemeOptions();
|
|
9
10
|
const labels = useLabels();
|
|
@@ -14,7 +15,7 @@ let observer: ResizeObserver | undefined;
|
|
|
14
15
|
|
|
15
16
|
// The class is set on <html> by an inline script injected in the head, so a dismissed banner never
|
|
16
17
|
// paints. See transformHead() in config.js.
|
|
17
|
-
const DISMISSED =
|
|
18
|
+
const DISMISSED = BANNER_DISMISSED_CLASS;
|
|
18
19
|
|
|
19
20
|
function height() {
|
|
20
21
|
const root = document.documentElement;
|
|
@@ -34,7 +35,7 @@ function dismiss() {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
try {
|
|
37
|
-
localStorage.setItem(
|
|
38
|
+
localStorage.setItem(bannerKey(banner.value.id), 'dismissed');
|
|
38
39
|
} catch {
|
|
39
40
|
// Private mode or full quota: the banner is dismissed for this page view only.
|
|
40
41
|
}
|
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {
|
|
3
|
-
onMounted, onUnmounted
|
|
3
|
+
computed, onMounted, onUnmounted
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useLabels } from '../composables/options';
|
|
6
|
+
import { useTransientFlag } from '../composables/transient';
|
|
6
7
|
|
|
7
8
|
const labels = useLabels();
|
|
8
|
-
const
|
|
9
|
+
const { active, start, stop } = useTransientFlag();
|
|
10
|
+
const message = computed(() => (active.value ? labels.value.codeCopied : ''));
|
|
9
11
|
|
|
10
12
|
// VitePress confirms a code block copy with a CSS `::before` only, which screen readers never
|
|
11
13
|
// hear. Its click handler adds `.copied` once the clipboard write succeeds, so the class is what
|
|
12
14
|
// gets watched rather than the click itself.
|
|
13
15
|
const BUTTON = 'div[class*="language-"] > button.copy';
|
|
14
16
|
|
|
15
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
16
|
-
|
|
17
|
-
function announce() {
|
|
18
|
-
message.value = labels.value.codeCopied;
|
|
19
|
-
|
|
20
|
-
clearTimeout(timer);
|
|
21
|
-
timer = setTimeout(() => (message.value = ''), 2000);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
17
|
function onClick(event: MouseEvent) {
|
|
25
18
|
const button = (event.target as Element | null)?.closest?.(BUTTON);
|
|
26
19
|
|
|
@@ -29,12 +22,12 @@ function onClick(event: MouseEvent) {
|
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
// Cleared first, so a second copy within two seconds is announced again.
|
|
32
|
-
|
|
25
|
+
stop();
|
|
33
26
|
|
|
34
27
|
const observer = new MutationObserver(() => {
|
|
35
28
|
if (button.classList.contains('copied')) {
|
|
36
29
|
observer.disconnect();
|
|
37
|
-
|
|
30
|
+
start();
|
|
38
31
|
}
|
|
39
32
|
});
|
|
40
33
|
|
|
@@ -52,7 +45,6 @@ onMounted(() => window.addEventListener('click', onClick));
|
|
|
52
45
|
|
|
53
46
|
onUnmounted(() => {
|
|
54
47
|
window.removeEventListener('click', onClick);
|
|
55
|
-
clearTimeout(timer);
|
|
56
48
|
});
|
|
57
49
|
</script>
|
|
58
50
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {
|
|
3
|
-
computed, h, nextTick, onMounted, onUnmounted, ref, watch
|
|
3
|
+
computed, h, nextTick, onMounted, onUnmounted, ref, useId, watch
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useData } from 'vitepress';
|
|
6
6
|
import { useLayout } from '../internal';
|
|
7
7
|
import { useCopy } from '../composables/copy';
|
|
8
|
+
import { resolveOption } from '../../node/options.js';
|
|
9
|
+
import { resolvePageActions, type Network } from '../../node/page-actions.js';
|
|
8
10
|
import { formatRelative } from '../composables/relativeTime';
|
|
9
11
|
import {
|
|
10
12
|
format, useLabels, useThemeOptions
|
|
@@ -16,13 +18,9 @@ const { sidebarGroups } = useLayout();
|
|
|
16
18
|
const options = useThemeOptions();
|
|
17
19
|
const labels = useLabels();
|
|
18
20
|
|
|
19
|
-
const meta = computed(() =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return options.value.meta ?? {};
|
|
25
|
-
});
|
|
21
|
+
const meta = computed(() =>
|
|
22
|
+
resolveOption(options.value.meta ?? true, frontmatter.value.docMeta === false)
|
|
23
|
+
);
|
|
26
24
|
|
|
27
25
|
// --------------------------------------------------------------------------------------------- //
|
|
28
26
|
// Section, read from the sidebar the site already declares
|
|
@@ -118,8 +116,6 @@ const updatedAt = computed(() =>
|
|
|
118
116
|
// `pageActions: { copyMarkdown: true }`.
|
|
119
117
|
// --------------------------------------------------------------------------------------------- //
|
|
120
118
|
|
|
121
|
-
type Network = 'x' | 'linkedin' | 'bluesky' | 'mastodon';
|
|
122
|
-
|
|
123
119
|
// 24px viewBox paths: the interface icons are stroked, the brand ones (Simple Icons, CC0) filled.
|
|
124
120
|
const icons = {
|
|
125
121
|
copy: 'M10 8h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2zM4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2',
|
|
@@ -194,15 +190,11 @@ MetaIcon.props = [
|
|
|
194
190
|
const markdown = computed(() => (page.value as { ffMarkdown?: string }).ffMarkdown ?? '');
|
|
195
191
|
|
|
196
192
|
const actions = computed(() => {
|
|
197
|
-
const
|
|
198
|
-
const all = pageActions === true;
|
|
199
|
-
const config = typeof pageActions === 'object' ? pageActions : {};
|
|
193
|
+
const resolved = resolvePageActions(options.value);
|
|
200
194
|
|
|
201
195
|
return {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
share: all ? (Object.keys(networks) as Network[]) : (config.share ?? []),
|
|
205
|
-
instance: config.mastodonInstance ?? 'mastodon.social'
|
|
196
|
+
...resolved,
|
|
197
|
+
markdown: resolved.markdown && !!markdown.value
|
|
206
198
|
};
|
|
207
199
|
});
|
|
208
200
|
|
|
@@ -240,6 +232,7 @@ const root = ref<HTMLElement>();
|
|
|
240
232
|
const trigger = ref<HTMLButtonElement>();
|
|
241
233
|
const open = ref(false);
|
|
242
234
|
const pageUrl = ref('');
|
|
235
|
+
const menuId = useId();
|
|
243
236
|
|
|
244
237
|
const shares = computed(() =>
|
|
245
238
|
actions.value.share
|
|
@@ -257,6 +250,7 @@ function toggle() {
|
|
|
257
250
|
if (open.value) {
|
|
258
251
|
// Read on the client only, so the page renders the same on the server.
|
|
259
252
|
pageUrl.value = pageAddress();
|
|
253
|
+
nextTick(() => root.value?.querySelector<HTMLElement>('[role="menuitem"]')?.focus());
|
|
260
254
|
}
|
|
261
255
|
}
|
|
262
256
|
|
|
@@ -384,6 +378,7 @@ const hidden = computed(
|
|
|
384
378
|
:class="{ open }"
|
|
385
379
|
aria-haspopup="menu"
|
|
386
380
|
:aria-expanded="open"
|
|
381
|
+
:aria-controls="open ? menuId : undefined"
|
|
387
382
|
:aria-label="main ? labels.pageActions : undefined"
|
|
388
383
|
@click="toggle"
|
|
389
384
|
>
|
|
@@ -405,6 +400,7 @@ const hidden = computed(
|
|
|
405
400
|
|
|
406
401
|
<div
|
|
407
402
|
v-if="open"
|
|
403
|
+
:id="menuId"
|
|
408
404
|
class="ff-doc-meta-menu"
|
|
409
405
|
role="menu"
|
|
410
406
|
>
|
|
@@ -4,20 +4,15 @@ import {
|
|
|
4
4
|
} from 'vue';
|
|
5
5
|
import { useData } from 'vitepress';
|
|
6
6
|
import { useLabels, useThemeOptions } from '../composables/options';
|
|
7
|
+
import { resolveOption } from '../../node/options.js';
|
|
7
8
|
|
|
8
9
|
const { page, frontmatter, lang } = useData();
|
|
9
10
|
const options = useThemeOptions();
|
|
10
11
|
const labels = useLabels();
|
|
11
12
|
|
|
12
|
-
const config = computed(() =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!feedback || frontmatter.value.feedback === false) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return feedback === true ? {} : feedback;
|
|
20
|
-
});
|
|
13
|
+
const config = computed(() =>
|
|
14
|
+
resolveOption(options.value.feedback, frontmatter.value.feedback === false)
|
|
15
|
+
);
|
|
21
16
|
|
|
22
17
|
const question = computed(() => config.value?.question || labels.value.feedbackQuestion);
|
|
23
18
|
|
|
@@ -56,8 +56,8 @@ const visible = computed(
|
|
|
56
56
|
class="ff-footer-columns"
|
|
57
57
|
>
|
|
58
58
|
<nav
|
|
59
|
-
v-for="column in columns"
|
|
60
|
-
:key="column.title"
|
|
59
|
+
v-for="(column, index) in columns"
|
|
60
|
+
:key="`${index}-${column.title}`"
|
|
61
61
|
class="ff-footer-column"
|
|
62
62
|
:aria-label="column.title"
|
|
63
63
|
>
|
|
@@ -203,8 +203,8 @@ function hasInlineCommand() {
|
|
|
203
203
|
class="ff-hero-meta"
|
|
204
204
|
>
|
|
205
205
|
<div
|
|
206
|
-
v-for="item in meta"
|
|
207
|
-
:key="item.label"
|
|
206
|
+
v-for="(item, index) in meta"
|
|
207
|
+
:key="`${index}-${item.label}`"
|
|
208
208
|
class="ff-hero-meta-item"
|
|
209
209
|
>
|
|
210
210
|
<dt class="ff-label">
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
formatDate, resolveAuthor, useBlog
|
|
6
6
|
} from '../composables/blog';
|
|
7
7
|
import { format, useLabels } from '../composables/options';
|
|
8
|
+
import { toTags } from '../../node/blog.js';
|
|
8
9
|
import { normalizeLink } from '../internal';
|
|
9
10
|
|
|
10
11
|
const { frontmatter, lang } = useData();
|
|
@@ -13,7 +14,7 @@ const labels = useLabels();
|
|
|
13
14
|
|
|
14
15
|
const date = computed(() => (isPost.value ? new Date(frontmatter.value.date).toISOString() : ''));
|
|
15
16
|
const author = computed(() => resolveAuthor(authors.value, frontmatter.value.author));
|
|
16
|
-
const tags = computed<string[]>(() => (
|
|
17
|
+
const tags = computed<string[]>(() => (toTags(frontmatter.value.tags) as string[]));
|
|
17
18
|
</script>
|
|
18
19
|
|
|
19
20
|
<template>
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
computed, onMounted, ref, watchEffect
|
|
4
|
-
} from 'vue';
|
|
2
|
+
import { computed, ref } from 'vue';
|
|
5
3
|
import { useData } from 'vitepress';
|
|
6
4
|
import { useThemeOptions } from '../composables/options';
|
|
5
|
+
import { useFrameListener } from '../composables/frame';
|
|
7
6
|
|
|
8
7
|
const { frontmatter } = useData();
|
|
9
8
|
const options = useThemeOptions();
|
|
@@ -18,43 +17,10 @@ function update() {
|
|
|
18
17
|
progress.value = range > 0 ? Math.min(Math.max(window.scrollY / range, 0), 1) : 0;
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!frame) {
|
|
26
|
-
frame = requestAnimationFrame(() => {
|
|
27
|
-
frame = 0;
|
|
28
|
-
update();
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Listens only while the bar is enabled, and follows the option if it changes (locale switch,
|
|
34
|
-
// per-page frontmatter). The effect is stopped with the component, which runs its cleanup.
|
|
35
|
-
onMounted(() => {
|
|
36
|
-
watchEffect((onCleanup) => {
|
|
37
|
-
if (!enabled.value) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
update();
|
|
42
|
-
window.addEventListener('scroll', onChange, {
|
|
43
|
-
passive: true
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
window.addEventListener('resize', onChange, {
|
|
47
|
-
passive: true
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
onCleanup(() => {
|
|
51
|
-
cancelAnimationFrame(frame);
|
|
52
|
-
frame = 0;
|
|
53
|
-
window.removeEventListener('scroll', onChange);
|
|
54
|
-
window.removeEventListener('resize', onChange);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
});
|
|
20
|
+
useFrameListener(enabled, update, [
|
|
21
|
+
'scroll',
|
|
22
|
+
'resize'
|
|
23
|
+
]);
|
|
58
24
|
</script>
|
|
59
25
|
|
|
60
26
|
<template>
|
package/src/composables/blog.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { computed } from 'vue';
|
|
2
2
|
import { useData } from 'vitepress';
|
|
3
3
|
import { useThemeOptions } from './options';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
blogDir, isPostPath, resolveAuthor
|
|
6
|
+
} from '../../node/blog.js';
|
|
7
|
+
|
|
8
|
+
export { resolveAuthor };
|
|
6
9
|
|
|
7
10
|
/** Blog options, with the directory normalised (no slash at either end). */
|
|
8
11
|
export function useBlog() {
|
|
@@ -12,11 +15,9 @@ export function useBlog() {
|
|
|
12
15
|
const dir = computed(() => blogDir(options.value));
|
|
13
16
|
|
|
14
17
|
// A post is a dated page under the blog directory, the index excluded.
|
|
15
|
-
const isPost = computed(() =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return path.startsWith(`${dir.value}/`) && path !== `${dir.value}/index.md` && hasValidDate(frontmatter.value.date);
|
|
19
|
-
});
|
|
18
|
+
const isPost = computed(() =>
|
|
19
|
+
isPostPath(dir.value, page.value.relativePath, frontmatter.value.date)
|
|
20
|
+
);
|
|
20
21
|
|
|
21
22
|
return {
|
|
22
23
|
dir,
|
|
@@ -25,13 +26,6 @@ export function useBlog() {
|
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
/** `author` is a key of `ff.blog.authors`, or a plain name used as is. */
|
|
29
|
-
export function resolveAuthor(authors: Record<string, BlogAuthor>, value?: string): BlogAuthor | null {
|
|
30
|
-
return value ? authors[value] ?? {
|
|
31
|
-
name: value
|
|
32
|
-
} : null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
29
|
// UTC, so the server and the browser print the same day whatever their time zone.
|
|
36
30
|
export function formatDate(date: string, lang: string) {
|
|
37
31
|
return new Intl.DateTimeFormat(lang, {
|
package/src/composables/copy.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from 'vue';
|
|
1
|
+
import { toValue, type MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import { useTransientFlag } from './transient';
|
|
4
3
|
|
|
5
4
|
/** Copies a string to the clipboard and flags it as copied for two seconds. */
|
|
6
5
|
export function useCopy(text: MaybeRefOrGetter<string>) {
|
|
7
|
-
const copied =
|
|
8
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
6
|
+
const { active: copied, start } = useTransientFlag();
|
|
9
7
|
|
|
10
8
|
async function copy() {
|
|
11
9
|
const value = toValue(text);
|
|
@@ -21,14 +19,9 @@ export function useCopy(text: MaybeRefOrGetter<string>) {
|
|
|
21
19
|
return;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
clearTimeout(timer);
|
|
27
|
-
timer = setTimeout(() => (copied.value = false), 2000);
|
|
22
|
+
start();
|
|
28
23
|
}
|
|
29
24
|
|
|
30
|
-
onUnmounted(() => clearTimeout(timer));
|
|
31
|
-
|
|
32
25
|
return {
|
|
33
26
|
copied,
|
|
34
27
|
copy
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
onMounted, toValue, watchEffect, type MaybeRefOrGetter
|
|
3
|
+
} from 'vue';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Runs `update` once, then at most once per frame however many of the window `events` fire. Listens
|
|
7
|
+
* only while `enabled` is true and follows it if it changes; everything is undone on unmount.
|
|
8
|
+
*/
|
|
9
|
+
export function useFrameListener(
|
|
10
|
+
enabled: MaybeRefOrGetter<boolean>,
|
|
11
|
+
update: () => void,
|
|
12
|
+
events: string[]
|
|
13
|
+
) {
|
|
14
|
+
let frame = 0;
|
|
15
|
+
|
|
16
|
+
function onEvent() {
|
|
17
|
+
if (!frame) {
|
|
18
|
+
frame = requestAnimationFrame(() => {
|
|
19
|
+
frame = 0;
|
|
20
|
+
update();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// The effect is stopped with the component, which runs its cleanup.
|
|
26
|
+
onMounted(() => {
|
|
27
|
+
watchEffect((onCleanup) => {
|
|
28
|
+
if (!toValue(enabled)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
update();
|
|
33
|
+
|
|
34
|
+
for (const name of events) {
|
|
35
|
+
window.addEventListener(name, onEvent, {
|
|
36
|
+
passive: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onCleanup(() => {
|
|
41
|
+
cancelAnimationFrame(frame);
|
|
42
|
+
frame = 0;
|
|
43
|
+
|
|
44
|
+
for (const name of events) {
|
|
45
|
+
window.removeEventListener(name, onEvent);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { onUnmounted, ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
/** A flag that turns itself off `ms` milliseconds after `start()`; the timer dies with the component. */
|
|
4
|
+
export function useTransientFlag(ms = 2000) {
|
|
5
|
+
const active = ref(false);
|
|
6
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
7
|
+
|
|
8
|
+
function stop() {
|
|
9
|
+
clearTimeout(timer);
|
|
10
|
+
active.value = false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function start() {
|
|
14
|
+
active.value = true;
|
|
15
|
+
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
timer = setTimeout(() => (active.value = false), ms);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
onUnmounted(() => clearTimeout(timer));
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
active,
|
|
24
|
+
start,
|
|
25
|
+
stop
|
|
26
|
+
};
|
|
27
|
+
}
|
package/src/content/Card.vue
CHANGED
|
@@ -13,22 +13,34 @@ const props = defineProps<{
|
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
15
|
<template>
|
|
16
|
-
|
|
16
|
+
<!-- Only the title is the link, stretched over the card in CSS, as in FfFeature: wrapping the
|
|
17
|
+
whole card put the body in the link's accessible name. -->
|
|
18
|
+
<div
|
|
17
19
|
class="ff-card"
|
|
18
|
-
|
|
20
|
+
:class="{ 'ff-card-linked': link }"
|
|
19
21
|
>
|
|
20
22
|
<span
|
|
21
23
|
v-if="icon"
|
|
22
24
|
class="ff-card-icon"
|
|
25
|
+
aria-hidden="true"
|
|
23
26
|
v-html="icon"
|
|
24
27
|
/>
|
|
25
28
|
|
|
26
29
|
<p class="ff-card-title">
|
|
27
|
-
|
|
30
|
+
<VPLink
|
|
31
|
+
v-if="link"
|
|
32
|
+
class="ff-card-anchor"
|
|
33
|
+
v-bind="cardLinkProps(props.link, props.rel, props.target)"
|
|
34
|
+
>
|
|
35
|
+
{{ title }}
|
|
36
|
+
</VPLink>
|
|
37
|
+
<template v-else>
|
|
38
|
+
{{ title }}
|
|
39
|
+
</template>
|
|
28
40
|
</p>
|
|
29
41
|
|
|
30
42
|
<div class="ff-card-body">
|
|
31
43
|
<slot />
|
|
32
44
|
</div>
|
|
33
|
-
</
|
|
45
|
+
</div>
|
|
34
46
|
</template>
|
package/src/content/Tabs.vue
CHANGED
|
@@ -8,6 +8,8 @@ import { useTabs } from '../composables/tabs';
|
|
|
8
8
|
const props = defineProps<{
|
|
9
9
|
/** Groups sharing a key switch together, and the choice is remembered across visits. */
|
|
10
10
|
syncKey?: string
|
|
11
|
+
/** Accessible name of the tab list. */
|
|
12
|
+
ariaLabel?: string
|
|
11
13
|
}>();
|
|
12
14
|
|
|
13
15
|
const slots = useSlots();
|
|
@@ -60,6 +62,7 @@ const { active, select, onKeydown } = useTabs(
|
|
|
60
62
|
<div
|
|
61
63
|
class="ff-tabs-list"
|
|
62
64
|
role="tablist"
|
|
65
|
+
:aria-label="ariaLabel"
|
|
63
66
|
@keydown="onKeydown"
|
|
64
67
|
>
|
|
65
68
|
<button
|
package/src/styles/_code.scss
CHANGED
|
@@ -46,11 +46,8 @@
|
|
|
46
46
|
.vp-doc [class*="language-"] > button.copy {
|
|
47
47
|
top: 0.4375rem;
|
|
48
48
|
right: 0.625rem;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
border-radius: #{mg.ref("radius-sm")};
|
|
52
|
-
background-color: transparent;
|
|
53
|
-
background-size: 0.875rem;
|
|
49
|
+
|
|
50
|
+
@include mixins.copy-button;
|
|
54
51
|
|
|
55
52
|
// Fully opaque at rest: dimmed, the grey icon falls under the 3:1 non-text contrast minimum.
|
|
56
53
|
opacity: 1;
|
|
@@ -58,14 +55,15 @@
|
|
|
58
55
|
|
|
59
56
|
.vp-doc [class*="language-"] > button.copy.copied,
|
|
60
57
|
.vp-doc [class*="language-"] > button.copy:hover.copied {
|
|
61
|
-
|
|
58
|
+
@include mixins.copy-button-copied;
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
.vp-doc [class*="language-"] > button.copy.copied::before,
|
|
65
62
|
.vp-doc [class*="language-"] > button.copy:hover.copied::before {
|
|
66
63
|
top: 0;
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
|
|
65
|
+
@include mixins.copied-flag;
|
|
66
|
+
|
|
69
67
|
background: #{mg.ref("color-surface")};
|
|
70
68
|
font-family: #{mg.ref("font-mono")};
|
|
71
69
|
font-size: #{mg.ref("size-label")};
|
package/src/styles/_content.scss
CHANGED
|
@@ -238,7 +238,7 @@
|
|
|
238
238
|
.ff-doc-meta-main:focus-visible,
|
|
239
239
|
.ff-doc-meta-toggle:focus-visible,
|
|
240
240
|
.ff-doc-meta-menu > :focus-visible {
|
|
241
|
-
outline:
|
|
241
|
+
outline: #{mg.ref("rule-accent-width")} solid #{mg.ref("color-accent")};
|
|
242
242
|
outline-offset: -2px;
|
|
243
243
|
}
|
|
244
244
|
|
|
@@ -528,6 +528,7 @@
|
|
|
528
528
|
}
|
|
529
529
|
|
|
530
530
|
.vp-doc .ff-card {
|
|
531
|
+
position: relative;
|
|
531
532
|
display: block;
|
|
532
533
|
padding: 1.25rem;
|
|
533
534
|
border: #{mg.ref("rule-width")} solid #{mg.ref("color-rule")};
|
|
@@ -535,11 +536,29 @@
|
|
|
535
536
|
background: #{mg.ref("color-surface")};
|
|
536
537
|
}
|
|
537
538
|
|
|
538
|
-
.vp-doc a.ff-card {
|
|
539
|
+
.vp-doc a.ff-card-anchor {
|
|
540
|
+
color: inherit;
|
|
539
541
|
text-decoration: none;
|
|
540
542
|
}
|
|
541
543
|
|
|
542
|
-
|
|
544
|
+
// Stretched over the whole card, so it stays clickable everywhere.
|
|
545
|
+
.vp-doc a.ff-card-anchor::before {
|
|
546
|
+
content: "";
|
|
547
|
+
position: absolute;
|
|
548
|
+
inset: 0;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// The focus ring goes around the card the link covers, not around the title alone.
|
|
552
|
+
.vp-doc a.ff-card-anchor:focus-visible {
|
|
553
|
+
outline: none;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
.vp-doc .ff-card:has(.ff-card-anchor:focus-visible) {
|
|
557
|
+
outline: #{mg.ref("rule-accent-width")} solid #{mg.ref("color-accent")};
|
|
558
|
+
outline-offset: -2px;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
.vp-doc .ff-card-linked:hover {
|
|
543
562
|
border-color: #{mg.ref("color-accent")};
|
|
544
563
|
}
|
|
545
564
|
|