@abraca/junis 2.87.0 → 2.88.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.
Files changed (89) hide show
  1. package/dist/module.d.mts +4 -2
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +64 -6
  4. package/dist/runtime/assets/css/jun.css +2 -2
  5. package/dist/runtime/components/JunDocSurface.d.vue.ts +20 -2
  6. package/dist/runtime/components/JunDocSurface.vue +27 -2
  7. package/dist/runtime/components/JunDocSurface.vue.d.ts +20 -2
  8. package/dist/runtime/components/JunHead.vue +16 -4
  9. package/dist/runtime/components/JunNavDock.d.vue.ts +15 -0
  10. package/dist/runtime/components/JunNavDock.vue +94 -0
  11. package/dist/runtime/components/JunNavDock.vue.d.ts +15 -0
  12. package/dist/runtime/components/JunNavMenu.client.d.vue.ts +15 -0
  13. package/dist/runtime/components/JunNavMenu.client.vue +478 -0
  14. package/dist/runtime/components/JunNavMenu.client.vue.d.ts +15 -0
  15. package/dist/runtime/components/JunNavPreview.d.vue.ts +17 -0
  16. package/dist/runtime/components/JunNavPreview.vue +169 -0
  17. package/dist/runtime/components/JunNavPreview.vue.d.ts +17 -0
  18. package/dist/runtime/components/JunNavigation.d.vue.ts +4 -11
  19. package/dist/runtime/components/JunNavigation.vue +813 -138
  20. package/dist/runtime/components/JunNavigation.vue.d.ts +4 -11
  21. package/dist/runtime/components/JunNoteLinks.vue +1 -1
  22. package/dist/runtime/components/JunPageHero.vue +3 -3
  23. package/dist/runtime/components/JunSectionBar.d.vue.ts +41 -0
  24. package/dist/runtime/components/JunSectionBar.vue +144 -0
  25. package/dist/runtime/components/JunSectionBar.vue.d.ts +41 -0
  26. package/dist/runtime/components/renderers/JunConfigRenderer.vue +486 -6
  27. package/dist/runtime/components/renderers/JunEntryRenderer.vue +48 -0
  28. package/dist/runtime/composables/useJunCreatePage.js +7 -1
  29. package/dist/runtime/composables/useJunDocPage.d.ts +28 -0
  30. package/dist/runtime/composables/useJunDocPage.js +111 -20
  31. package/dist/runtime/composables/useJunGarden.d.ts +1 -1
  32. package/dist/runtime/composables/useJunGarden.js +3 -2
  33. package/dist/runtime/composables/useJunGestures.d.ts +53 -0
  34. package/dist/runtime/composables/useJunGestures.js +89 -0
  35. package/dist/runtime/composables/useJunMenuState.d.ts +4 -0
  36. package/dist/runtime/composables/useJunMenuState.js +5 -0
  37. package/dist/runtime/composables/useJunNavItems.d.ts +50 -0
  38. package/dist/runtime/composables/useJunNavItems.js +188 -0
  39. package/dist/runtime/composables/useJunNavSettings.d.ts +58 -1
  40. package/dist/runtime/composables/useJunNavSettings.js +110 -8
  41. package/dist/runtime/composables/useJunOptions.d.ts +1 -0
  42. package/dist/runtime/composables/useJunSiblings.d.ts +30 -0
  43. package/dist/runtime/composables/useJunSiblings.js +38 -0
  44. package/dist/runtime/composables/useJunSiteConfig.d.ts +51 -3
  45. package/dist/runtime/composables/useJunTheme.js +4 -1
  46. package/dist/runtime/composables/useJunViewingAccent.js +10 -0
  47. package/dist/runtime/layouts/jun.vue +21 -1
  48. package/dist/runtime/pages/doc.vue +2 -0
  49. package/dist/runtime/pages/index.vue +2 -0
  50. package/dist/runtime/server/api/health.get.d.ts +15 -0
  51. package/dist/runtime/server/api/health.get.js +7 -2
  52. package/dist/runtime/server/api/links.get.js +27 -3
  53. package/dist/runtime/server/api/resolve/[...slug].get.d.ts +20 -0
  54. package/dist/runtime/server/api/resolve/[...slug].get.js +31 -0
  55. package/dist/runtime/server/api/search.get.d.ts +1 -1
  56. package/dist/runtime/server/api/search.get.js +42 -39
  57. package/dist/runtime/server/api/tree.get.js +3 -1
  58. package/dist/runtime/server/janitor/junJanitorChores.d.ts +14 -7
  59. package/dist/runtime/server/janitor/junJanitorChores.js +21 -3
  60. package/dist/runtime/server/janitor/junJanitorMachine.js +36 -4
  61. package/dist/runtime/server/janitor/junJanitorPerform.d.ts +15 -1
  62. package/dist/runtime/server/janitor/junJanitorPerform.js +13 -5
  63. package/dist/runtime/server/janitor/junJanitorYText.d.ts +40 -3
  64. package/dist/runtime/server/janitor/junJanitorYText.js +60 -14
  65. package/dist/runtime/server/plugins/jun-janitor.js +132 -81
  66. package/dist/runtime/server/routes/jun-card.png.get.d.ts +2 -0
  67. package/dist/runtime/server/routes/jun-card.png.get.js +40 -0
  68. package/dist/runtime/server/utils/junCard.d.ts +39 -0
  69. package/dist/runtime/server/utils/junCard.js +159 -0
  70. package/dist/runtime/server/utils/junIcon.d.ts +27 -2
  71. package/dist/runtime/server/utils/junIcon.js +5 -5
  72. package/dist/runtime/server/utils/junJanitorStatus.d.ts +59 -0
  73. package/dist/runtime/server/utils/junJanitorStatus.js +27 -0
  74. package/dist/runtime/types.d.ts +225 -0
  75. package/dist/runtime/utils/junAdopt.d.ts +43 -0
  76. package/dist/runtime/utils/junAdopt.js +7 -0
  77. package/dist/runtime/utils/junGesture.d.ts +84 -0
  78. package/dist/runtime/utils/junGesture.js +40 -0
  79. package/dist/runtime/utils/junLetters.d.ts +86 -0
  80. package/dist/runtime/utils/junLetters.js +173 -0
  81. package/dist/runtime/utils/junNavValue.d.ts +56 -0
  82. package/dist/runtime/utils/junNavValue.js +36 -0
  83. package/dist/runtime/utils/junSearchRank.d.ts +79 -0
  84. package/dist/runtime/utils/junSearchRank.js +73 -0
  85. package/dist/runtime/utils/junSocial.d.ts +59 -0
  86. package/dist/runtime/utils/junSocial.js +56 -0
  87. package/dist/runtime/utils/junViewSpecs.d.ts +38 -0
  88. package/dist/runtime/utils/junViewSpecs.js +92 -1
  89. package/package.json +10 -8
@@ -57,6 +57,34 @@ export interface JunResolvedDoc {
57
57
  parentId?: string | null;
58
58
  parentType?: string | null;
59
59
  parentTitle?: string | null;
60
+ /**
61
+ * Every ancestor, root-first — `[{ id, title, slug }]`.
62
+ *
63
+ * A breadcrumb the client can walk from the live tree, but a crawler reads
64
+ * the page before there IS a live tree, which is why the trail is sent.
65
+ */
66
+ trail?: {
67
+ id: string;
68
+ title: string;
69
+ slug: string | null;
70
+ }[];
71
+ /**
72
+ * The pages beside this one — the children of its top-level ancestor.
73
+ *
74
+ * What `<JunSectionBar>` draws before the live tree can answer. `null` on the
75
+ * home page, whose children ARE the navbar.
76
+ */
77
+ section?: {
78
+ parentId: string;
79
+ parentTitle: string;
80
+ parentSlug: string | null;
81
+ items: {
82
+ id: string;
83
+ title: string;
84
+ slug: string | null;
85
+ icon?: string;
86
+ }[];
87
+ } | null;
60
88
  html?: string | null;
61
89
  }
62
90
  export type JunLayoutBucket = 'immersive' | 'panel' | 'flowing';
@@ -1,5 +1,6 @@
1
1
  import { computed, onUnmounted, watchEffect } from "vue";
2
- import { useHead, useNuxtData, useSeoMeta } from "#app";
2
+ import { useHead, useNuxtData, useRequestURL, useSeoMeta } from "#app";
3
+ import { useRoute } from "vue-router";
3
4
  import {
4
5
  useDocTree,
5
6
  useJunBrand,
@@ -10,8 +11,17 @@ import {
10
11
  junConfigStr,
11
12
  isJunOwnerOnlyDoc
12
13
  } from "#imports";
13
- import { JUN_CHROME_OPTIONS } from "../utils/junViewSpecs.js";
14
+ import { JUN_CHROME_OPTIONS, JUN_HERO_OPTIONS } from "../utils/junViewSpecs.js";
14
15
  import { junResolveViewValue } from "../utils/junViewValues.js";
16
+ import {
17
+ junAbsoluteUrl,
18
+ junIsArticleOg,
19
+ junIsoTime,
20
+ junOgType,
21
+ junOrigin
22
+ } from "../utils/junSocial.js";
23
+ import { junFingerprint } from "../utils/junIdentity.js";
24
+ import { junCanDraw } from "../utils/junLetters.js";
15
25
  const FLAG = {
16
26
  chromeNav: "no-nav",
17
27
  chromeFooter: "no-footer",
@@ -97,16 +107,11 @@ export function useJunDocPage(docId, options = {}) {
97
107
  meta: resolved?.value?.meta
98
108
  })
99
109
  );
100
- useHead({
101
- // `undefined`, NOT the site name, when there is no document title of our
102
- // own. `JunHead`'s titleTemplate already falls back to the site name for
103
- // an untitled page; returning it here too would run it through the
104
- // template and render `Jun!s — Jun!s`.
105
- title: computed(() => {
106
- if (!canEdit.value && ownerOnly.value) return void 0;
107
- return entry.value?.label ?? resolved?.value?.title ?? void 0;
108
- })
110
+ const pageTitle = computed(() => {
111
+ if (!canEdit.value && ownerOnly.value) return void 0;
112
+ return entry.value?.label ?? resolved?.value?.title ?? void 0;
109
113
  });
114
+ useHead({ title: pageTitle });
110
115
  const description = computed(() => {
111
116
  if (!(!canEdit.value && ownerOnly.value)) {
112
117
  const meta = entry.value?.meta ?? resolved?.value?.meta ?? {};
@@ -115,21 +120,71 @@ export function useJunDocPage(docId, options = {}) {
115
120
  }
116
121
  return junConfigStr(siteConfig.value.seoDescription) ?? brand.value.seoDescription;
117
122
  });
118
- const jsonLd = computed(() => {
123
+ const jsonLdObject = computed(() => {
119
124
  const type = docType.value;
120
125
  const builder = isItem.value ? itemPresentation.value?.jsonLd : type ? opts.jsonLd?.[type] : void 0;
121
- if (!builder || !resolved?.value?.found || ownerOnly.value) return "";
122
- const out = junBuildJsonLd(builder, {
126
+ if (!builder || !resolved?.value?.found || ownerOnly.value) return null;
127
+ return junBuildJsonLd(builder, {
123
128
  title: resolved.value.title ?? "",
124
129
  meta: resolved.value.meta ?? {},
125
130
  authorName: junConfigStr(siteConfig.value.authorName) ?? brand.value.name,
126
131
  description: description.value
127
132
  });
128
- return out ? JSON.stringify(out) : "";
133
+ });
134
+ const jsonLd = computed(() => jsonLdObject.value ? JSON.stringify(jsonLdObject.value) : "");
135
+ const requestUrl = useRequestURL();
136
+ const route = useRoute();
137
+ const origin = computed(() => junOrigin(
138
+ junConfigStr(siteConfig.value.seoSiteUrl),
139
+ requestUrl.origin
140
+ ));
141
+ const canonicalPath = computed(() => {
142
+ const former = resolved?.value?.canonical;
143
+ return former ? `/${former}` : route.path;
144
+ });
145
+ const canonicalUrl = computed(() => junAbsoluteUrl(origin.value, canonicalPath.value));
146
+ const ogType = computed(() => junOgType(jsonLdObject.value?.["@type"]));
147
+ const publishedTime = computed(
148
+ () => junIsArticleOg(ogType.value) ? junIsoTime(jsonLdObject.value?.datePublished) : void 0
149
+ );
150
+ const modifiedTime = computed(() => {
151
+ if (!junIsArticleOg(ogType.value)) return void 0;
152
+ const meta = entry.value?.meta ?? resolved?.value?.meta ?? {};
153
+ return junIsoTime(entry.value?.updatedAt ?? meta.updatedAt) ?? publishedTime.value;
154
+ });
155
+ const socialImage = computed(() => {
156
+ const meta = entry.value?.meta ?? resolved?.value?.meta ?? {};
157
+ const own = junConfigStr(meta.socialImage);
158
+ if (own) return /^https?:\/\//i.test(own) ? own : junAbsoluteUrl(origin.value, own);
159
+ const configured = junConfigStr(siteConfig.value.seoOgImage);
160
+ if (configured) return /^https?:\/\//i.test(configured) ? configured : junAbsoluteUrl(origin.value, configured);
161
+ if (!opts.features.socialCards) return void 0;
162
+ const id = docId.value;
163
+ if (!id) return void 0;
164
+ if (!junCanDraw(pageTitle.value ?? "")) return void 0;
165
+ const key = junFingerprint([pageTitle.value, docType.value, description.value].join("|"));
166
+ return junAbsoluteUrl(origin.value, `/jun-card.png?d=${encodeURIComponent(id)}&k=${key}`);
129
167
  });
130
168
  useSeoMeta({
131
169
  description: () => description.value,
132
- ogDescription: () => description.value
170
+ ogDescription: () => description.value,
171
+ ogTitle: () => pageTitle.value,
172
+ twitterTitle: () => pageTitle.value,
173
+ twitterDescription: () => description.value,
174
+ ogUrl: () => canonicalUrl.value,
175
+ ogType: () => ogType.value,
176
+ ogImage: () => socialImage.value,
177
+ twitterImage: () => socialImage.value,
178
+ articlePublishedTime: () => publishedTime.value,
179
+ articleModifiedTime: () => modifiedTime.value
180
+ });
181
+ useHead({
182
+ link: computed(() => (
183
+ // Only when the origin is known. A RELATIVE canonical is legal and
184
+ // useless; an absolute one built on a guessed origin points a crawler
185
+ // somewhere else entirely.
186
+ origin.value ? [{ key: "jun-canonical", rel: "canonical", href: canonicalUrl.value }] : []
187
+ ))
133
188
  });
134
189
  const typeKey = computed(() => {
135
190
  const id = docType.value;
@@ -154,16 +209,52 @@ export function useJunDocPage(docId, options = {}) {
154
209
  const flags = off.filter(Boolean).join(" ");
155
210
  return flags || void 0;
156
211
  });
212
+ const heroStyle = computed(() => {
213
+ const meta = entry.value?.meta ?? resolved?.value?.meta ?? {};
214
+ const stored = meta.junView && typeof meta.junView === "object" && !Array.isArray(meta.junView) ? meta.junView : {};
215
+ const key = typeKey.value;
216
+ const house = key ? {
217
+ ...opts.renderers?.[key] ?? {},
218
+ ...siteConfig.value.renderers?.[key] ?? {}
219
+ } : {};
220
+ const option = JUN_HERO_OPTIONS[0];
221
+ const value = junResolveViewValue(option, stored, house, meta);
222
+ return typeof value === "string" && value !== "classic" ? value : void 0;
223
+ });
157
224
  useHead({
158
225
  htmlAttrs: {
159
226
  "data-jun-type": computed(() => typeKey.value),
160
- "data-jun-chrome": computed(() => chromeFlags.value)
227
+ "data-jun-chrome": computed(() => chromeFlags.value),
228
+ "data-jun-hero": computed(() => heroStyle.value)
161
229
  }
162
230
  });
231
+ const breadcrumbLd = computed(() => {
232
+ const trail = resolved?.value?.trail ?? [];
233
+ if (!origin.value || ownerOnly.value || !pageTitle.value) return "";
234
+ const items = [
235
+ ...trail.map((step) => ({
236
+ name: step.title,
237
+ url: junAbsoluteUrl(origin.value, step.slug ? `/${step.slug}` : "/")
238
+ })),
239
+ { name: pageTitle.value, url: canonicalUrl.value }
240
+ ].filter((step) => !!step.name);
241
+ if (items.length < 2) return "";
242
+ return JSON.stringify({
243
+ "@context": "https://schema.org",
244
+ "@type": "BreadcrumbList",
245
+ "itemListElement": items.map((step, i) => ({
246
+ "@type": "ListItem",
247
+ "position": i + 1,
248
+ "name": step.name,
249
+ "item": step.url
250
+ }))
251
+ });
252
+ });
163
253
  useHead({
164
- script: computed(
165
- () => jsonLd.value ? [{ key: "jun-jsonld", type: "application/ld+json", textContent: jsonLd.value }] : []
166
- )
254
+ script: computed(() => [
255
+ ...jsonLd.value ? [{ key: "jun-jsonld", type: "application/ld+json", textContent: jsonLd.value }] : [],
256
+ ...breadcrumbLd.value ? [{ key: "jun-breadcrumb-ld", type: "application/ld+json", textContent: breadcrumbLd.value }] : []
257
+ ])
167
258
  });
168
259
  return {
169
260
  entry,
@@ -39,7 +39,7 @@ export interface JunLinkGraph {
39
39
  * falls through to the SPA catch-all and resolves with the page's HTML. That is not
40
40
  * a thrown error, so a `try`/`catch` never sees it; only checking the shape does.
41
41
  */
42
- export declare function useJunLinkGraph(): {
42
+ export declare function useJunLinkGraph(docId?: string): {
43
43
  graph: ComputedRef<JunLinkGraph>;
44
44
  refresh: () => Promise<void>;
45
45
  };
@@ -9,10 +9,11 @@ import {
9
9
  } from "../utils/junGarden.js";
10
10
  import { isJunOwnerOnlyDoc } from "../utils/junVisibility.js";
11
11
  const EMPTY = { nodes: [], edges: [], scanned: 0, generatedAt: 0 };
12
- export function useJunLinkGraph() {
12
+ export function useJunLinkGraph(docId) {
13
13
  const opts = useJunOptions();
14
14
  const { data, refresh } = useFetch(`${opts.apiBase}/links`, {
15
- key: "jun-links",
15
+ key: docId ? `jun-links-${docId}` : "jun-links",
16
+ query: docId ? { doc: docId } : void 0,
16
17
  default: () => EMPTY
17
18
  });
18
19
  const graph = computed(() => {
@@ -0,0 +1,53 @@
1
+ /**
2
+ * useJunGestures — swipe to turn the page, swipe from the edge to open the menu.
3
+ *
4
+ * The detection is `@abraca/nuxt`'s (`useSwipeGesture`, `useEdgeSwipe`), shared
5
+ * with cou-sh. Everything here is what a swipe MEANS on a site made of
6
+ * documents: which page is next, when the gesture applies, and how much of it
7
+ * to draw.
8
+ *
9
+ * ## Where it is mounted, and why only there
10
+ *
11
+ * The FLOWING bucket only — an ordinary reading page. The immersive and panel
12
+ * buckets are renderers that own their own pointer (a globe drags, a deck
13
+ * pages, a mosaic pans), and a page-level swipe would be competing with the
14
+ * thing the reader is actually touching. Those types can adopt the same
15
+ * composable themselves, deliberately, one at a time.
16
+ *
17
+ * ## What suppresses it
18
+ *
19
+ * Editing, an open overlay, a site that switched it off, and anything inside
20
+ * `data-swipe-ignore` — the navbar's own horizontal track, the editor, the
21
+ * timeline. That last one is the composable's own rule and costs nothing here.
22
+ *
23
+ * ## What it does NOT do
24
+ *
25
+ * Take over the browser's back gesture. Edge swipe OPENS things; history stays
26
+ * the platform's. `preventBrowserGesture` is left off for exactly that reason:
27
+ * on a site, the reader's swipe-to-go-back is worth more than a second way to
28
+ * reach the menu.
29
+ */
30
+ import { type ComputedRef, type Ref } from 'vue';
31
+ export interface JunGestureOptions {
32
+ /** The layout bucket this page is in. Only `flowing` gets page swipes. */
33
+ bucket: () => string;
34
+ /** The document being read. */
35
+ docId: Ref<string | null> | ComputedRef<string | null>;
36
+ /** The config snapshot, already fetched by the page. */
37
+ config: ComputedRef<Record<string, unknown>>;
38
+ }
39
+ export declare function useJunGestures(el: Ref<HTMLElement | null>, options: JunGestureOptions): {
40
+ swipeOffset: Ref<{
41
+ x: number;
42
+ y: number;
43
+ }, {
44
+ x: number;
45
+ y: number;
46
+ } | {
47
+ x: number;
48
+ y: number;
49
+ }>;
50
+ isSwiping: Ref<boolean, boolean>;
51
+ neighbours: ComputedRef<import("#imports").JunNeighbourPair<import("#imports").JunSibling>>;
52
+ applies: ComputedRef<boolean>;
53
+ };
@@ -0,0 +1,89 @@
1
+ import { computed, ref } from "vue";
2
+ import { useRouter } from "vue-router";
3
+ import { useDocSlugs, useEdgeSwipe, useSwipeGesture } from "#imports";
4
+ import { useJunImagePopup } from "./useJunImagePopup.js";
5
+ import { useJunMenuState } from "./useJunMenuState.js";
6
+ import { useJunNavSettings } from "./useJunNavSettings.js";
7
+ import { useJunOptions } from "./useJunOptions.js";
8
+ import { useJunSiblings } from "./useJunSiblings.js";
9
+ import { junConfigOn } from "./useJunSiteConfigValues.js";
10
+ import { useJunStudio } from "./useJunStudio.js";
11
+ import { junSwipeApplies, junSwipeDamp, junSwipeNeighbour } from "../utils/junGesture.js";
12
+ export function useJunGestures(el, options) {
13
+ const opts = useJunOptions();
14
+ const router = useRouter();
15
+ const { getDocUrl } = useDocSlugs();
16
+ const { editing } = useJunStudio();
17
+ const { state: popup } = useJunImagePopup();
18
+ const { open: menuOpen } = useJunMenuState();
19
+ const nav = useJunNavSettings();
20
+ const { neighbours } = useJunSiblings(options.docId);
21
+ const reducedMotion = ref(false);
22
+ if (import.meta.client) {
23
+ reducedMotion.value = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
24
+ }
25
+ const pageSwipeOn = computed(() => opts.features.gestures && junConfigOn(options.config.value.gesturePages ?? true));
26
+ const edgeSwipeOn = computed(() => opts.features.gestures && junConfigOn(options.config.value.gestureEdge ?? true));
27
+ const overlayOpen = computed(() => menuOpen.value || !!popup.value);
28
+ if (!opts.features.gestures) {
29
+ return {
30
+ swipeOffset: ref({ x: 0, y: 0 }),
31
+ isSwiping: ref(false),
32
+ neighbours,
33
+ applies: computed(() => false)
34
+ };
35
+ }
36
+ const applies = computed(() => junSwipeApplies({
37
+ enabled: pageSwipeOn.value,
38
+ bucket: options.bucket(),
39
+ editing: editing.value,
40
+ overlayOpen: overlayOpen.value
41
+ }));
42
+ function go(direction) {
43
+ const target = junSwipeNeighbour(direction, neighbours.value);
44
+ if (!target) return;
45
+ const url = getDocUrl(target.id);
46
+ if (url) void router.push(url);
47
+ }
48
+ const { swipeOffset, isSwiping } = useSwipeGesture({
49
+ el,
50
+ axis: "x",
51
+ /*
52
+ * TOUCH ONLY, and this was measured rather than assumed.
53
+ *
54
+ * `useSwipeGesture` also counts wheel deltas, which is right for a pager —
55
+ * cou-sh flicks through slides and windows that way. On a reading page it
56
+ * is a trap: a Mac trackpad emits horizontal deltas whenever somebody
57
+ * brushes sideways past a wide code block, and eight of them navigated a
58
+ * documentation page to its neighbour under a reader who had not asked to
59
+ * go anywhere.
60
+ */
61
+ pointer: "touch",
62
+ disabled: () => !applies.value,
63
+ damp: () => junSwipeDamp(reducedMotion.value),
64
+ // `canSwipe*` is about DAMPING, not permission: a direction with nothing
65
+ // in it still moves, a quarter as far, so the end of a collection is felt
66
+ // rather than merely not happening.
67
+ canSwipeLeft: () => !!neighbours.value.next,
68
+ canSwipeRight: () => !!neighbours.value.prev,
69
+ onSwipeLeft: () => go("left"),
70
+ onSwipeRight: () => go("right")
71
+ });
72
+ useEdgeSwipe({
73
+ disabled: () => !edgeSwipeOn.value || !nav.menuEnabled.value || editing.value || overlayOpen.value,
74
+ onFromLeft: () => {
75
+ menuOpen.value = true;
76
+ },
77
+ onFromRight: () => {
78
+ menuOpen.value = true;
79
+ }
80
+ });
81
+ return {
82
+ /** Live offset while a finger is down — bind it as a transform. */
83
+ swipeOffset,
84
+ isSwiping,
85
+ neighbours,
86
+ /** Whether a page swipe would do anything right now. */
87
+ applies
88
+ };
89
+ }
@@ -0,0 +1,4 @@
1
+ import type { Ref } from 'vue';
2
+ export declare function useJunMenuState(): {
3
+ open: Ref<boolean>;
4
+ };
@@ -0,0 +1,5 @@
1
+ import { useState } from "#app";
2
+ export function useJunMenuState() {
3
+ const open = useState("jun-nav-menu-open", () => false);
4
+ return { open };
5
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * useJunNavItems — everything a NAVIGATION ITEM knows about itself.
3
+ *
4
+ * The navbar used to be the only thing that rendered one, so all of this lived
5
+ * inside `JunNavigation`. There are three surfaces now — the track, the mobile
6
+ * menu and the dock — and every one of them needs the same six answers about
7
+ * the same item: what it is called, what icon it wears, where it actually
8
+ * goes, what is underneath it, who is standing on it, and whether it changed
9
+ * since this visitor last looked.
10
+ *
11
+ * The PRESENTATIONS are deliberately not shared: a pill, a menu row and a dock
12
+ * tab are different shapes, and a component flexible enough to be all three
13
+ * would be worse than three templates. The DATA is shared, because two copies
14
+ * of "does presence bubble up from the subtree" is how two surfaces come to
15
+ * disagree about how many people are on a page.
16
+ */
17
+ import { type Ref } from 'vue';
18
+ import { type JunTraveller } from './useJunPresence.js';
19
+ export interface JunNavigationItem {
20
+ id?: string;
21
+ name: string;
22
+ href: string;
23
+ type?: string;
24
+ icon?: string;
25
+ current: boolean;
26
+ }
27
+ /** A child page of a nav item, for the submenus and the menu's accordion. */
28
+ export interface JunNavChild {
29
+ id: string;
30
+ name: string;
31
+ href: string;
32
+ icon?: string;
33
+ type?: string;
34
+ }
35
+ export declare function useJunNavItems(items: Ref<JunNavigationItem[]>, options?: {
36
+ trackSeen?: boolean;
37
+ }): {
38
+ activeTrail: () => string[];
39
+ labelOf: (id: string) => string;
40
+ iconFor: (item: JunNavigationItem) => string;
41
+ navLabelFor: (item: JunNavigationItem) => string;
42
+ redirectTargetFor: (item: JunNavigationItem) => string | null;
43
+ isExternalTarget: (u: string | null) => boolean;
44
+ childrenOf: (id?: string) => JunNavChild[];
45
+ freshFor: (item: JunNavigationItem) => boolean;
46
+ countFor: (item: JunNavigationItem) => number | null;
47
+ presenceFor: (id?: string) => JunTraveller[];
48
+ topAncestorOf: (id: string) => string | null;
49
+ subtreeMaxById: import("vue").ComputedRef<Map<string, number>>;
50
+ };
@@ -0,0 +1,188 @@
1
+ import { computed, onMounted, ref, watch } from "vue";
2
+ import {
3
+ useAbracadabra,
4
+ useDocSlugs,
5
+ useDocTree,
6
+ useRoute,
7
+ useSlugRoute
8
+ } from "#imports";
9
+ import { useJunDocIcon, useJunOptions, useJunPageType } from "./useJunOptions.js";
10
+ import { useJunNavSettings } from "./useJunNavSettings.js";
11
+ import { junDedupeTravellers, useJunTravellers } from "./useJunPresence.js";
12
+ const SEEN_KEY = "jun_seen_v1";
13
+ export function useJunNavItems(items, options = {}) {
14
+ const route = useRoute();
15
+ const abra = useAbracadabra();
16
+ const { typeIds } = useJunOptions();
17
+ const { resolveType } = useJunPageType();
18
+ const { entries: treeEntries, getEntry } = useDocTree();
19
+ const { getDocUrl } = useDocSlugs();
20
+ const { docId } = useSlugRoute();
21
+ const { travellers } = useJunTravellers();
22
+ const nav = useJunNavSettings();
23
+ const docIcon = useJunDocIcon();
24
+ const iconFor = (item) => item.icon ?? docIcon(item.type);
25
+ function navLabelFor(item) {
26
+ if (!item.id) return item.name;
27
+ const nl = getEntry(item.id)?.meta?.navLabel;
28
+ return typeof nl === "string" && nl.trim() ? nl.trim() : item.name;
29
+ }
30
+ function redirectTargetFor(item) {
31
+ if (!typeIds.redirect || resolveType(item.type) !== typeIds.redirect || !item.id) return null;
32
+ const u = getEntry(item.id)?.meta?.url;
33
+ return typeof u === "string" && u.trim() ? u.trim() : null;
34
+ }
35
+ const isExternalTarget = (u) => !!u && /^https?:\/\//i.test(u);
36
+ const childrenByParent = computed(() => {
37
+ const map = /* @__PURE__ */ new Map();
38
+ for (const e of treeEntries.value) {
39
+ const arr = map.get(e.parentId ?? null) ?? [];
40
+ arr.push({ id: e.id, updatedAt: e.updatedAt });
41
+ map.set(e.parentId ?? null, arr);
42
+ }
43
+ return map;
44
+ });
45
+ function childrenOf(id) {
46
+ if (!id) return [];
47
+ return treeEntries.value.filter((e) => e.parentId === id && !e.trashed && e.meta?.hidden !== true).sort((a, b) => (a.order ?? 0) - (b.order ?? 0)).map((e) => ({
48
+ id: e.id,
49
+ name: e.label || "Untitled",
50
+ href: getDocUrl(e.id),
51
+ icon: e.meta?.icon,
52
+ type: e.type
53
+ }));
54
+ }
55
+ const seenMap = ref({});
56
+ function persistSeen() {
57
+ try {
58
+ localStorage.setItem(SEEN_KEY, JSON.stringify(seenMap.value));
59
+ } catch {
60
+ }
61
+ }
62
+ onMounted(() => {
63
+ try {
64
+ seenMap.value = JSON.parse(localStorage.getItem(SEEN_KEY) || "null") ?? {};
65
+ } catch {
66
+ seenMap.value = {};
67
+ }
68
+ });
69
+ const subtreeMaxById = computed(() => {
70
+ const m = /* @__PURE__ */ new Map();
71
+ for (const item of items.value) {
72
+ if (!item.id) continue;
73
+ let max = getEntry(item.id)?.updatedAt ?? 0;
74
+ const queue = [...childrenByParent.value.get(item.id) ?? []];
75
+ while (queue.length) {
76
+ const cur = queue.pop();
77
+ if ((cur.updatedAt ?? 0) > max) max = cur.updatedAt ?? 0;
78
+ for (const c of childrenByParent.value.get(cur.id) ?? []) queue.push(c);
79
+ }
80
+ m.set(item.id, max);
81
+ }
82
+ return m;
83
+ });
84
+ const countById = computed(() => {
85
+ const out = /* @__PURE__ */ new Map();
86
+ const mode = nav.counts.value;
87
+ if (mode === "off") return out;
88
+ for (const item of items.value) {
89
+ if (!item.id) continue;
90
+ if (mode === "children") {
91
+ const n2 = (childrenByParent.value.get(item.id) ?? []).length;
92
+ if (n2 > 0) out.set(item.id, n2);
93
+ continue;
94
+ }
95
+ const seen = seenMap.value[item.id];
96
+ if (!seen || item.current) continue;
97
+ let n = 0;
98
+ const queue = [...childrenByParent.value.get(item.id) ?? []];
99
+ while (queue.length) {
100
+ const cur = queue.pop();
101
+ if ((cur.updatedAt ?? 0) > seen + 2e3) n++;
102
+ for (const child of childrenByParent.value.get(cur.id) ?? []) queue.push(child);
103
+ }
104
+ if (n > 0) out.set(item.id, n);
105
+ }
106
+ return out;
107
+ });
108
+ function countFor(item) {
109
+ return (item.id ? countById.value.get(item.id) : void 0) ?? null;
110
+ }
111
+ function freshFor(item) {
112
+ if (!nav.freshnessDots.value || !item.id || item.current) return false;
113
+ const seen = seenMap.value[item.id];
114
+ if (!seen) return false;
115
+ return (subtreeMaxById.value.get(item.id) ?? 0) > seen + 2e3;
116
+ }
117
+ function activeTrail() {
118
+ const trail = [];
119
+ let cursor = docId.value ?? null;
120
+ for (let depth = 0; cursor && depth < 32; depth++) {
121
+ const entry = getEntry(cursor);
122
+ if (!entry) break;
123
+ trail.unshift(cursor);
124
+ const parent = entry.parentId ?? null;
125
+ if (!parent || parent === abra.spaceDocId.value) break;
126
+ cursor = parent;
127
+ }
128
+ return trail;
129
+ }
130
+ function labelOf(id) {
131
+ const entry = getEntry(id);
132
+ const nl = entry?.meta?.navLabel;
133
+ if (typeof nl === "string" && nl.trim()) return nl.trim();
134
+ return entry?.label || "Untitled";
135
+ }
136
+ function topAncestorOf(id) {
137
+ let cursor = id;
138
+ for (let depth = 0; cursor && depth < 32; depth++) {
139
+ const entry = getEntry(cursor);
140
+ if (!entry) return null;
141
+ const parent = entry.parentId ?? null;
142
+ if (!parent || parent === abra.spaceDocId.value) return cursor;
143
+ cursor = parent;
144
+ }
145
+ return null;
146
+ }
147
+ const presenceByNavId = computed(() => {
148
+ const map = /* @__PURE__ */ new Map();
149
+ for (const t of travellers.value) {
150
+ if (!t.docId) continue;
151
+ const top = topAncestorOf(t.docId);
152
+ if (!top) continue;
153
+ const list = map.get(top) ?? [];
154
+ list.push(t);
155
+ map.set(top, list);
156
+ }
157
+ for (const [id, list] of map) map.set(id, junDedupeTravellers(list));
158
+ return map;
159
+ });
160
+ const presenceFor = (id) => id ? presenceByNavId.value.get(id) ?? [] : [];
161
+ if (options.trackSeen) {
162
+ watch(
163
+ [() => route.path, docId, subtreeMaxById],
164
+ () => {
165
+ if (!import.meta.client) return;
166
+ const top = docId.value ? topAncestorOf(docId.value) : null;
167
+ if (!top) return;
168
+ seenMap.value = { ...seenMap.value, [top]: Date.now() };
169
+ persistSeen();
170
+ },
171
+ { immediate: true }
172
+ );
173
+ }
174
+ return {
175
+ activeTrail,
176
+ labelOf,
177
+ iconFor,
178
+ navLabelFor,
179
+ redirectTargetFor,
180
+ isExternalTarget,
181
+ childrenOf,
182
+ freshFor,
183
+ countFor,
184
+ presenceFor,
185
+ topAncestorOf,
186
+ subtreeMaxById
187
+ };
188
+ }