@abraca/junis 2.87.0 → 2.90.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/dist/module.d.mts +43 -4
- package/dist/module.json +1 -1
- package/dist/module.mjs +121 -6
- package/dist/runtime/assets/css/jun.css +2 -2
- package/dist/runtime/components/JunDocSurface.d.vue.ts +20 -2
- package/dist/runtime/components/JunDocSurface.vue +27 -2
- package/dist/runtime/components/JunDocSurface.vue.d.ts +20 -2
- package/dist/runtime/components/JunHead.vue +16 -4
- package/dist/runtime/components/JunNavDock.d.vue.ts +15 -0
- package/dist/runtime/components/JunNavDock.vue +94 -0
- package/dist/runtime/components/JunNavDock.vue.d.ts +15 -0
- package/dist/runtime/components/JunNavMenu.client.d.vue.ts +15 -0
- package/dist/runtime/components/JunNavMenu.client.vue +501 -0
- package/dist/runtime/components/JunNavMenu.client.vue.d.ts +15 -0
- package/dist/runtime/components/JunNavPreview.d.vue.ts +17 -0
- package/dist/runtime/components/JunNavPreview.vue +169 -0
- package/dist/runtime/components/JunNavPreview.vue.d.ts +17 -0
- package/dist/runtime/components/JunNavigation.d.vue.ts +4 -11
- package/dist/runtime/components/JunNavigation.vue +813 -138
- package/dist/runtime/components/JunNavigation.vue.d.ts +4 -11
- package/dist/runtime/components/JunNoteLinks.vue +1 -1
- package/dist/runtime/components/JunOfflinePanel.client.d.vue.ts +3 -0
- package/dist/runtime/components/JunOfflinePanel.client.vue +293 -0
- package/dist/runtime/components/JunOfflinePanel.client.vue.d.ts +3 -0
- package/dist/runtime/components/JunPageHero.vue +3 -3
- package/dist/runtime/components/JunSectionBar.d.vue.ts +41 -0
- package/dist/runtime/components/JunSectionBar.vue +144 -0
- package/dist/runtime/components/JunSectionBar.vue.d.ts +41 -0
- package/dist/runtime/components/renderers/JunConfigRenderer.vue +618 -6
- package/dist/runtime/components/renderers/JunEntryRenderer.vue +48 -0
- package/dist/runtime/composables/useJunCommands.d.ts +1 -1
- package/dist/runtime/composables/useJunCommands.js +14 -1
- package/dist/runtime/composables/useJunCreatePage.js +7 -1
- package/dist/runtime/composables/useJunDocPage.d.ts +28 -0
- package/dist/runtime/composables/useJunDocPage.js +111 -20
- package/dist/runtime/composables/useJunGarden.d.ts +1 -1
- package/dist/runtime/composables/useJunGarden.js +3 -2
- package/dist/runtime/composables/useJunGestures.d.ts +53 -0
- package/dist/runtime/composables/useJunGestures.js +89 -0
- package/dist/runtime/composables/useJunMenuState.d.ts +4 -0
- package/dist/runtime/composables/useJunMenuState.js +5 -0
- package/dist/runtime/composables/useJunNavItems.d.ts +50 -0
- package/dist/runtime/composables/useJunNavItems.js +188 -0
- package/dist/runtime/composables/useJunNavSettings.d.ts +58 -1
- package/dist/runtime/composables/useJunNavSettings.js +110 -8
- package/dist/runtime/composables/useJunOffline.d.ts +109 -0
- package/dist/runtime/composables/useJunOffline.js +294 -0
- package/dist/runtime/composables/useJunOptions.d.ts +1 -0
- package/dist/runtime/composables/useJunSettings.d.ts +1 -1
- package/dist/runtime/composables/useJunSettings.js +2 -0
- package/dist/runtime/composables/useJunSiblings.d.ts +30 -0
- package/dist/runtime/composables/useJunSiblings.js +38 -0
- package/dist/runtime/composables/useJunSiteConfig.d.ts +70 -3
- package/dist/runtime/composables/useJunTheme.js +4 -1
- package/dist/runtime/composables/useJunViewingAccent.js +10 -0
- package/dist/runtime/layouts/jun.vue +32 -2
- package/dist/runtime/pages/doc.vue +2 -0
- package/dist/runtime/pages/index.vue +2 -0
- package/dist/runtime/server/api/health.get.d.ts +15 -0
- package/dist/runtime/server/api/health.get.js +7 -2
- package/dist/runtime/server/api/links.get.js +27 -3
- package/dist/runtime/server/api/offline.get.d.ts +10 -0
- package/dist/runtime/server/api/offline.get.js +13 -0
- package/dist/runtime/server/api/resolve/[...slug].get.d.ts +20 -0
- package/dist/runtime/server/api/resolve/[...slug].get.js +31 -0
- package/dist/runtime/server/api/search.get.d.ts +1 -1
- package/dist/runtime/server/api/search.get.js +42 -39
- package/dist/runtime/server/api/tree.get.js +3 -1
- package/dist/runtime/server/janitor/junJanitorChores.d.ts +14 -7
- package/dist/runtime/server/janitor/junJanitorChores.js +21 -3
- package/dist/runtime/server/janitor/junJanitorMachine.js +36 -4
- package/dist/runtime/server/janitor/junJanitorPerform.d.ts +15 -1
- package/dist/runtime/server/janitor/junJanitorPerform.js +13 -5
- package/dist/runtime/server/janitor/junJanitorYText.d.ts +40 -3
- package/dist/runtime/server/janitor/junJanitorYText.js +60 -14
- package/dist/runtime/server/plugins/jun-compress.d.ts +2 -0
- package/dist/runtime/server/plugins/jun-compress.js +76 -0
- package/dist/runtime/server/plugins/jun-janitor.js +132 -81
- package/dist/runtime/server/routes/jun-card.png.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-card.png.get.js +40 -0
- package/dist/runtime/server/routes/jun-sw.js.get.js +66 -13
- package/dist/runtime/server/routes/sitemap.xml.get.js +5 -18
- package/dist/runtime/server/utils/junCard.d.ts +39 -0
- package/dist/runtime/server/utils/junCard.js +159 -0
- package/dist/runtime/server/utils/junIcon.d.ts +27 -2
- package/dist/runtime/server/utils/junIcon.js +5 -5
- package/dist/runtime/server/utils/junJanitorStatus.d.ts +59 -0
- package/dist/runtime/server/utils/junJanitorStatus.js +27 -0
- package/dist/runtime/server/utils/junPages.d.ts +51 -0
- package/dist/runtime/server/utils/junPages.js +70 -0
- package/dist/runtime/types.d.ts +295 -0
- package/dist/runtime/utils/junAdopt.d.ts +43 -0
- package/dist/runtime/utils/junAdopt.js +7 -0
- package/dist/runtime/utils/junGesture.d.ts +84 -0
- package/dist/runtime/utils/junGesture.js +40 -0
- package/dist/runtime/utils/junLetters.d.ts +86 -0
- package/dist/runtime/utils/junLetters.js +173 -0
- package/dist/runtime/utils/junNavValue.d.ts +56 -0
- package/dist/runtime/utils/junNavValue.js +36 -0
- package/dist/runtime/utils/junOffline.d.ts +138 -0
- package/dist/runtime/utils/junOffline.js +73 -0
- package/dist/runtime/utils/junSearchRank.d.ts +79 -0
- package/dist/runtime/utils/junSearchRank.js +73 -0
- package/dist/runtime/utils/junSocial.d.ts +59 -0
- package/dist/runtime/utils/junSocial.js +56 -0
- package/dist/runtime/utils/junViewSpecs.d.ts +39 -1
- package/dist/runtime/utils/junViewSpecs.js +92 -1
- package/dist/types.d.mts +1 -1
- package/package.json +13 -9
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
const GLYPHS = {
|
|
2
|
+
"A": "6.4|0,10 3,0 6,10|1.2,7 4.8,7",
|
|
3
|
+
"B": "6.2|0,0 0,10|0,0 4,0 5.4,1.4 5.4,3.6 4,5 0,5|0,5 4.4,5 6,6.6 6,8.4 4.4,10 0,10",
|
|
4
|
+
"C": "6.4|6,2.2 4,0 2,0 0,2.2 0,7.8 2,10 4,10 6,7.8",
|
|
5
|
+
"D": "6.4|0,0 0,10|0,0 3.2,0 5.6,2.4 5.6,7.6 3.2,10 0,10",
|
|
6
|
+
"E": "5.8|5.6,0 0,0 0,10 5.6,10|0,5 4.4,5",
|
|
7
|
+
"F": "5.6|5.6,0 0,0 0,10|0,5 4.4,5",
|
|
8
|
+
"G": "6.6|6,2.2 4,0 2,0 0,2.2 0,7.8 2,10 4.2,10 6,8 6,5.4 3.6,5.4",
|
|
9
|
+
"H": "6.4|0,0 0,10|6,0 6,10|0,5 6,5",
|
|
10
|
+
"I": "2.4|1.2,0 1.2,10",
|
|
11
|
+
"J": "5.6|5,0 5,7.6 3.4,10 1.4,10 0,8",
|
|
12
|
+
"K": "6.2|0,0 0,10|5.6,0 0.6,5.4|2,3.8 6,10",
|
|
13
|
+
"L": "5.4|0,0 0,10 5.2,10",
|
|
14
|
+
"M": "7.6|0,10 0,0 3.6,5.6 7.2,0 7.2,10",
|
|
15
|
+
"N": "6.6|0,10 0,0 6.2,10 6.2,0",
|
|
16
|
+
"O": "6.8|2.2,0 4.2,0 6.4,2.2 6.4,7.8 4.2,10 2.2,10 0,7.8 0,2.2 2.2,0",
|
|
17
|
+
"P": "6.2|0,10 0,0 4,0 6,2 6,4.2 4,6.2 0,6.2",
|
|
18
|
+
"Q": "6.8|2.2,0 4.2,0 6.4,2.2 6.4,7.8 4.2,10 2.2,10 0,7.8 0,2.2 2.2,0|3.8,6.8 6.8,11.4",
|
|
19
|
+
"R": "6.2|0,10 0,0 4,0 6,2 6,4.2 4,6.2 0,6.2|3.4,6.2 6.2,10",
|
|
20
|
+
"S": "6.2|6,2 4.2,0 2,0 0,1.8 0,3.6 2,5 4.2,5 6,6.6 6,8.2 4,10 1.8,10 0,8.2",
|
|
21
|
+
"T": "6|0,0 6,0|3,0 3,10",
|
|
22
|
+
"U": "6.4|0,0 0,7.8 2.2,10 4.2,10 6.4,7.8 6.4,0",
|
|
23
|
+
"V": "6.4|0,0 3.2,10 6.4,0",
|
|
24
|
+
"W": "8.6|0,0 1.9,10 4.3,3.4 6.7,10 8.6,0",
|
|
25
|
+
"X": "6.4|0,0 6.2,10|6.2,0 0,10",
|
|
26
|
+
"Y": "6.2|0,0 3.1,5.2 6.2,0|3.1,5.2 3.1,10",
|
|
27
|
+
"Z": "6.2|0,0 6.2,0 0,10 6.2,10",
|
|
28
|
+
"0": "6.6|2.2,0 4.2,0 6.4,2.2 6.4,7.8 4.2,10 2.2,10 0,7.8 0,2.2 2.2,0|1,8 5.4,2",
|
|
29
|
+
"1": "4|0.6,1.8 2.6,0 2.6,10|0.4,10 4.6,10",
|
|
30
|
+
"2": "6.2|0,2.2 2,0 4.2,0 6.2,2 6.2,3.6 0,10 6.2,10",
|
|
31
|
+
"3": "6.2|0,1.2 2,0 4.4,0 6.2,1.8 6.2,3.6 4.2,5 6.2,6.4 6.2,8.2 4.4,10 2,10 0,8.8",
|
|
32
|
+
"4": "6.4|4.6,10 4.6,0 0,7 6.4,7",
|
|
33
|
+
"5": "6.2|6,0 0.4,0 0,4.6 3.8,4 6.2,5.8 6.2,8.2 4.2,10 1.8,10 0,8.8",
|
|
34
|
+
"6": "6.2|5.6,0.8 3.6,0 1.4,1.4 0,4.4 0,8 2,10 4.2,10 6.2,8.2 6.2,6.6 4.2,5 1.6,5 0,6.6",
|
|
35
|
+
"7": "5.8|0,0 5.8,0 2,10",
|
|
36
|
+
"8": "6.4|2.2,5 0,3.6 0,1.6 2.2,0 4.2,0 6.4,1.6 6.4,3.6 4.2,5 2.2,5|2.2,5 0,6.5 0,8.4 2.2,10 4.2,10 6.4,8.4 6.4,6.5 4.2,5",
|
|
37
|
+
"9": "6.2|0.6,9.2 2.6,10 4.8,8.6 6.2,5.6 6.2,2 4.2,0 2,0 0,1.8 0,3.4 2,5 4.6,5 6.2,3.4",
|
|
38
|
+
" ": "4",
|
|
39
|
+
".": "2.6|1.1,9.4 1.5,9.4",
|
|
40
|
+
",": "2.6|1.5,9.2 0.7,11.6",
|
|
41
|
+
":": "2.6|1.1,3.4 1.5,3.4|1.1,9.4 1.5,9.4",
|
|
42
|
+
";": "2.6|1.1,3.4 1.5,3.4|1.5,9.2 0.7,11.6",
|
|
43
|
+
"!": "2.6|1.3,0 1.3,7|1.1,9.4 1.5,9.4",
|
|
44
|
+
"?": "5.6|0,2 2,0 3.6,0 5.4,1.8 5.4,3.4 2.7,5.4 2.7,7|2.5,9.4 2.9,9.4",
|
|
45
|
+
"'": "2.4|1.3,0 0.9,2.6",
|
|
46
|
+
'"': "4|1.2,0 0.8,2.6|3.2,0 2.8,2.6",
|
|
47
|
+
"-": "4.6|0.4,5.2 4.2,5.2",
|
|
48
|
+
"\u2013": "6|0,5.2 6,5.2",
|
|
49
|
+
"\u2014": "7.4|0,5.2 7.4,5.2",
|
|
50
|
+
"_": "5.6|0,10.8 5.6,10.8",
|
|
51
|
+
"/": "5|4.6,0 0.4,11",
|
|
52
|
+
"\\": "5|0.4,0 4.6,11",
|
|
53
|
+
"(": "3.6|3.2,0 1,3 1,7 3.2,10",
|
|
54
|
+
")": "3.6|0.4,0 2.6,3 2.6,7 0.4,10",
|
|
55
|
+
"[": "3.2|3,0 1,0 1,10 3,10",
|
|
56
|
+
"]": "3.2|0.2,0 2.2,0 2.2,10 0.2,10",
|
|
57
|
+
"&": "7|6.8,10 1.6,1.6 3,0 4.4,1.4 0,6.6 0,8.4 1.6,10 3.6,10 6.4,6.6",
|
|
58
|
+
"+": "6|3,2 3,8|0,5 6,5",
|
|
59
|
+
"=": "6|0,3.6 6,3.6|0,6.4 6,6.4",
|
|
60
|
+
"@": "8|5.8,6.8 4.4,6.8 4.4,3.6 5.8,3.6 5.8,7.4 6.8,8 8,6.4 8,3.4 5.6,0 3,0 0.6,1.8 0,5 0.6,8.4 3,10 5.6,10",
|
|
61
|
+
"#": "6.6|1.8,0.6 0.8,9.4|4.6,0.6 3.6,9.4|0,3.4 5.8,3.4|0,6.6 5.8,6.6",
|
|
62
|
+
"%": "7|1.4,0 0,1.4 1.4,2.8 2.8,1.4 1.4,0|6.4,0 0.6,10|5.6,7.2 4.2,8.6 5.6,10 7,8.6 5.6,7.2",
|
|
63
|
+
"\u2026": "6.4|0.6,9.4 1,9.4|3,9.4 3.4,9.4|5.4,9.4 5.8,9.4",
|
|
64
|
+
"\xB7": "2.6|1.1,5 1.5,5",
|
|
65
|
+
"\u2022": "3.4|1.3,4.6 1.9,4.6|1.3,5.4 1.9,5.4",
|
|
66
|
+
"*": "5|2.5,0 2.5,5|0.4,1.4 4.6,3.8|4.6,1.4 0.4,3.8"
|
|
67
|
+
};
|
|
68
|
+
export const JUN_CAP_HEIGHT = 10;
|
|
69
|
+
const TRACKING = 1.4;
|
|
70
|
+
const parsed = /* @__PURE__ */ new Map();
|
|
71
|
+
function glyph(char) {
|
|
72
|
+
const hit = parsed.get(char);
|
|
73
|
+
if (hit) return hit;
|
|
74
|
+
const raw = GLYPHS[char];
|
|
75
|
+
if (!raw) return void 0;
|
|
76
|
+
const [head, ...rest] = raw.split("|");
|
|
77
|
+
const g = {
|
|
78
|
+
advance: Number.parseFloat(head ?? "6") || 6,
|
|
79
|
+
lines: rest.map((line) => line.trim().split(/\s+/).map((pt) => {
|
|
80
|
+
const [x, y] = pt.split(",");
|
|
81
|
+
return [Number.parseFloat(x ?? "0"), Number.parseFloat(y ?? "0")];
|
|
82
|
+
}))
|
|
83
|
+
};
|
|
84
|
+
parsed.set(char, g);
|
|
85
|
+
return g;
|
|
86
|
+
}
|
|
87
|
+
export function junCanDraw(text) {
|
|
88
|
+
for (const char of text.toUpperCase()) {
|
|
89
|
+
if (char.trim() && GLYPHS[char]) return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
export function junTextWidth(text) {
|
|
94
|
+
const chars = [...text.toUpperCase()];
|
|
95
|
+
let w = 0;
|
|
96
|
+
for (const [i, char] of chars.entries()) {
|
|
97
|
+
const g = glyph(char) ?? glyph(" ");
|
|
98
|
+
w += g.advance + (i < chars.length - 1 ? TRACKING : 0);
|
|
99
|
+
}
|
|
100
|
+
return w;
|
|
101
|
+
}
|
|
102
|
+
export function junWrapText(text, maxWidth, maxLines) {
|
|
103
|
+
return junWrapInfo(text, maxWidth, maxLines).lines;
|
|
104
|
+
}
|
|
105
|
+
export function junWrapInfo(text, maxWidth, maxLines) {
|
|
106
|
+
const words = text.toUpperCase().split(/\s+/).filter(Boolean);
|
|
107
|
+
const lines = [];
|
|
108
|
+
let line = "";
|
|
109
|
+
let dropped = false;
|
|
110
|
+
const pushLine = () => {
|
|
111
|
+
if (line) lines.push(line);
|
|
112
|
+
line = "";
|
|
113
|
+
};
|
|
114
|
+
for (const word of words) {
|
|
115
|
+
const candidate = line ? `${line} ${word}` : word;
|
|
116
|
+
if (junTextWidth(candidate) <= maxWidth) {
|
|
117
|
+
line = candidate;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
pushLine();
|
|
121
|
+
if (lines.length >= maxLines) {
|
|
122
|
+
dropped = true;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
if (junTextWidth(word) > maxWidth) {
|
|
126
|
+
let cut = "";
|
|
127
|
+
for (const char of word) {
|
|
128
|
+
if (junTextWidth(cut + char) > maxWidth) break;
|
|
129
|
+
cut += char;
|
|
130
|
+
}
|
|
131
|
+
line = cut;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
line = word;
|
|
135
|
+
}
|
|
136
|
+
pushLine();
|
|
137
|
+
if (dropped || lines.length > maxLines) {
|
|
138
|
+
lines.length = Math.min(lines.length, maxLines);
|
|
139
|
+
let cut = lines[lines.length - 1] ?? "";
|
|
140
|
+
while (cut && junTextWidth(`${cut}\u2026`) > maxWidth) cut = cut.slice(0, -1);
|
|
141
|
+
if (lines.length) lines[lines.length - 1] = `${cut.trimEnd()}\u2026`;
|
|
142
|
+
return { lines, truncated: true };
|
|
143
|
+
}
|
|
144
|
+
return { lines, truncated: false };
|
|
145
|
+
}
|
|
146
|
+
export function junTextStrokes(text, x, y, size) {
|
|
147
|
+
const scale = size / JUN_CAP_HEIGHT;
|
|
148
|
+
const groups = [];
|
|
149
|
+
let penX = x;
|
|
150
|
+
for (const char of text.toUpperCase()) {
|
|
151
|
+
const g = glyph(char);
|
|
152
|
+
if (!g) {
|
|
153
|
+
penX += (glyph(" ").advance + TRACKING) * scale;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const segs = [];
|
|
157
|
+
for (const line of g.lines) {
|
|
158
|
+
for (let i = 1; i < line.length; i++) {
|
|
159
|
+
const a = line[i - 1];
|
|
160
|
+
const b = line[i];
|
|
161
|
+
segs.push([
|
|
162
|
+
penX + a[0] * scale,
|
|
163
|
+
y + (a[1] - JUN_CAP_HEIGHT) * scale,
|
|
164
|
+
penX + b[0] * scale,
|
|
165
|
+
y + (b[1] - JUN_CAP_HEIGHT) * scale
|
|
166
|
+
]);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (segs.length) groups.push(segs);
|
|
170
|
+
penX += (g.advance + TRACKING) * scale;
|
|
171
|
+
}
|
|
172
|
+
return groups;
|
|
173
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The navbar's THREE layers, as arithmetic.
|
|
3
|
+
*
|
|
4
|
+
* A navigation setting is answered by whichever of these speaks first:
|
|
5
|
+
*
|
|
6
|
+
* 1. the DOCUMENT being viewed — `meta.junView`, the same place every other
|
|
7
|
+
* per-page display setting lives;
|
|
8
|
+
* 2. the SITE CONFIG document — the owner's live choice;
|
|
9
|
+
* 3. `jun.navigation` — what a fresh site boots with.
|
|
10
|
+
*
|
|
11
|
+
* The rules that make that safe are the ones no page can show you, which is why
|
|
12
|
+
* they are here, with no imports, rather than inline in the composable:
|
|
13
|
+
*
|
|
14
|
+
* - **`inherit` is not a value, it is a refusal to answer.** Every per-document
|
|
15
|
+
* nav option defaults to it, because `useJunViewOptions` resolves to a spec's
|
|
16
|
+
* default when a document stores nothing — so an option whose default were
|
|
17
|
+
* `top` would mean every untouched page overriding the site's placement with
|
|
18
|
+
* `top`, forever.
|
|
19
|
+
* - **An unknown value degrades to the next layer, never to `undefined`.** A
|
|
20
|
+
* config document is CRDT data a NEWER build may have written; a stale client
|
|
21
|
+
* reading `mobileMode: 'carousel'` must fall back, not render nothing.
|
|
22
|
+
* - **…and if the build default is unknown too, the first value in the
|
|
23
|
+
* vocabulary.** That case looks impossible and is what a dev server produces
|
|
24
|
+
* when it hot-reloads a runtime file without re-reading `module.ts`: the
|
|
25
|
+
* navbar concluded a menu had replaced its track and rendered the track
|
|
26
|
+
* `display: none` at every width.
|
|
27
|
+
*
|
|
28
|
+
* `useJunNavSettings` is the reactive wrapper; it cannot load outside a Nuxt
|
|
29
|
+
* app. This is the half that decides, and it is tested.
|
|
30
|
+
*/
|
|
31
|
+
/** The document's answer, or `undefined` when it has none. */
|
|
32
|
+
export declare function junNavDocValue(stored: unknown): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve one CHOICE through all three layers.
|
|
35
|
+
*
|
|
36
|
+
* `allowed` is the vocabulary THIS build knows, ordered with the shipped
|
|
37
|
+
* default first — that ordering is what the last fallback relies on.
|
|
38
|
+
*/
|
|
39
|
+
export declare function junNavPick<T extends string>(layers: {
|
|
40
|
+
doc?: unknown;
|
|
41
|
+
site?: unknown;
|
|
42
|
+
build: T;
|
|
43
|
+
}, allowed: readonly T[]): T;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve one FLAG through all three layers.
|
|
46
|
+
*
|
|
47
|
+
* The document speaks in `on` / `off` rather than in booleans, because
|
|
48
|
+
* `meta.junView` values are the strings a `select` control stores and a boolean
|
|
49
|
+
* has no way to spell "no opinion".
|
|
50
|
+
*/
|
|
51
|
+
export declare function junNavFlag(layers: {
|
|
52
|
+
doc?: unknown;
|
|
53
|
+
site?: unknown;
|
|
54
|
+
build: boolean;
|
|
55
|
+
}): boolean;
|
|
56
|
+
export declare function junNavPreview(raw: unknown): Record<string, string>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function junNavDocValue(stored) {
|
|
2
|
+
return typeof stored === "string" && stored !== "inherit" ? stored : void 0;
|
|
3
|
+
}
|
|
4
|
+
export function junNavPick(layers, allowed) {
|
|
5
|
+
const doc = junNavDocValue(layers.doc);
|
|
6
|
+
for (const candidate of [doc, layers.site]) {
|
|
7
|
+
if (typeof candidate === "string" && allowed.includes(candidate)) {
|
|
8
|
+
return candidate;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return allowed.includes(layers.build) ? layers.build : allowed[0];
|
|
12
|
+
}
|
|
13
|
+
export function junNavFlag(layers) {
|
|
14
|
+
const doc = junNavDocValue(layers.doc);
|
|
15
|
+
if (doc === "on") return true;
|
|
16
|
+
if (doc === "off") return false;
|
|
17
|
+
return typeof layers.site === "boolean" ? layers.site : layers.build;
|
|
18
|
+
}
|
|
19
|
+
const PREVIEW_KEYS = {
|
|
20
|
+
mobile: "navMobileMode",
|
|
21
|
+
placement: "navPlacement",
|
|
22
|
+
item: "navItemMode",
|
|
23
|
+
autohide: "navAutoHide",
|
|
24
|
+
section: "navSection"
|
|
25
|
+
};
|
|
26
|
+
export function junNavPreview(raw) {
|
|
27
|
+
const text = Array.isArray(raw) ? raw[0] : raw;
|
|
28
|
+
if (typeof text !== "string" || !text.trim()) return {};
|
|
29
|
+
const out = {};
|
|
30
|
+
for (const pair of text.split(",")) {
|
|
31
|
+
const [key, value] = pair.split(":").map((part) => part.trim().toLowerCase());
|
|
32
|
+
const mapped = key ? PREVIEW_KEYS[key] : void 0;
|
|
33
|
+
if (mapped && value) out[mapped] = value;
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an offline copy of a site IS — the arithmetic and the rules, with no
|
|
3
|
+
* imports, so every one of them can be checked without a browser.
|
|
4
|
+
*
|
|
5
|
+
* The service worker is the module's least testable surface by a wide margin:
|
|
6
|
+
* it only exists in a production build (dev serves a tombstone — see
|
|
7
|
+
* `jun-sw.js.get.ts`), it runs in a context with no DOM, and its failures look
|
|
8
|
+
* like a site that is merely slow. So as little as possible lives in it. The
|
|
9
|
+
* worker answers requests; **the page decides what a copy contains and does the
|
|
10
|
+
* saving itself**, through the same Cache Storage API, which is available in a
|
|
11
|
+
* window context and not only in a worker.
|
|
12
|
+
*
|
|
13
|
+
* That split is the reason this file can exist at all. Everything below is
|
|
14
|
+
* exercised by `test/offline.test.mts`.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* How much of the site this device keeps.
|
|
18
|
+
*
|
|
19
|
+
* `visited` is the default and it is the only one of the three that downloads
|
|
20
|
+
* NOTHING on its own: it keeps the pages the reader opened anyway, so that the
|
|
21
|
+
* moment the signal drops they are still there. `site` is a copy the visitor
|
|
22
|
+
* asked for out loud. `off` is a visitor who would rather no storage were used.
|
|
23
|
+
*/
|
|
24
|
+
export type JunOfflineMode = 'off' | 'visited' | 'site';
|
|
25
|
+
export declare const JUN_OFFLINE_MODES: JunOfflineMode[];
|
|
26
|
+
/** `localStorage`, per device — an offline copy belongs to the phone, not the site. */
|
|
27
|
+
export declare const JUN_OFFLINE_MODE_KEY = "jun_offline_mode";
|
|
28
|
+
export declare const JUN_OFFLINE_MEDIA_KEY = "jun_offline_media";
|
|
29
|
+
export declare const JUN_OFFLINE_SAVED_KEY = "jun_offline_saved";
|
|
30
|
+
/**
|
|
31
|
+
* Where the worker reads the mode from.
|
|
32
|
+
*
|
|
33
|
+
* A path inside the worker's scope, holding a synthetic `Response` the page
|
|
34
|
+
* writes. It is NOT a route — nothing serves it — and the double underscore is
|
|
35
|
+
* there so it can never collide with a slug: `junSlugify` cannot produce a
|
|
36
|
+
* leading underscore.
|
|
37
|
+
*
|
|
38
|
+
* The mode has to live somewhere the WORKER can read, and `localStorage` is not
|
|
39
|
+
* that place: it is unavailable in a worker context entirely. Cache Storage is
|
|
40
|
+
* the one store both sides can see.
|
|
41
|
+
*/
|
|
42
|
+
export declare const JUN_OFFLINE_MODE_URL = "/__jun-offline-mode";
|
|
43
|
+
/**
|
|
44
|
+
* The cache a saved copy lives in.
|
|
45
|
+
*
|
|
46
|
+
* Keyed on the BUILD, so a deploy orphans the previous one and the worker's
|
|
47
|
+
* `activate` deletes it. The page and the worker have to agree on this string
|
|
48
|
+
* or the page saves into a cache nothing reads — which is why it is computed
|
|
49
|
+
* here and imported by both rather than written out twice.
|
|
50
|
+
*/
|
|
51
|
+
export declare function junOfflineCacheName(buildId: string | undefined): string;
|
|
52
|
+
/** A stored preference, validated. Anything unrecognised means "never chose". */
|
|
53
|
+
export declare function junReadOfflineMode(stored: string | null | undefined, fallback?: JunOfflineMode): JunOfflineMode;
|
|
54
|
+
/**
|
|
55
|
+
* The assets a saved page needs in order to be a PAGE when it is served back.
|
|
56
|
+
*
|
|
57
|
+
* A cached HTML document whose modules are missing hydrates into nothing: the
|
|
58
|
+
* markup paints, and then every interactive surface on it is dead. So saving a
|
|
59
|
+
* page means saving what its HTML asks for.
|
|
60
|
+
*
|
|
61
|
+
* Two families, and the second is optional because it is the heavy one:
|
|
62
|
+
*
|
|
63
|
+
* - `/_nuxt/*` — the build's modules and styles. Content-hashed, so a stale
|
|
64
|
+
* entry is unreachable rather than wrong, and shared across pages: the
|
|
65
|
+
* hundredth page saved adds almost none.
|
|
66
|
+
* - `/uploads/*` — the site's images. Only when the visitor asked for media,
|
|
67
|
+
* and only when the OWNER allows it. This is what turns a text copy into a
|
|
68
|
+
* copy that weighs whatever the photographs weigh.
|
|
69
|
+
*
|
|
70
|
+
* Same-origin only, and by construction: both patterns are rooted paths. A
|
|
71
|
+
* cross-origin URL in the markup (an embed, a font CDN) is not matched, which
|
|
72
|
+
* is the same boundary the worker's fetch handler draws.
|
|
73
|
+
*/
|
|
74
|
+
export declare function junPageAssets(html: string, options?: {
|
|
75
|
+
media?: boolean;
|
|
76
|
+
}): string[];
|
|
77
|
+
/** Megabytes as a byte count. `0` and nonsense mean the built-in ceiling. */
|
|
78
|
+
export declare function junOfflineBudgetBytes(mb: number | undefined, fallbackMb?: number): number;
|
|
79
|
+
/**
|
|
80
|
+
* A size a person can read.
|
|
81
|
+
*
|
|
82
|
+
* Decimal units on purpose — a phone's storage settings say MB meaning
|
|
83
|
+
* 1,000,000, and a copy this reports as 24 MB sitting beside a system figure of
|
|
84
|
+
* 25 MB reads as a bug in one of them.
|
|
85
|
+
*/
|
|
86
|
+
export declare function junFormatBytes(bytes: number | null | undefined): string;
|
|
87
|
+
/**
|
|
88
|
+
* What a whole-site copy will cost, from ONE page.
|
|
89
|
+
*
|
|
90
|
+
* Every page on a jun site carries the same Nuxt payload — the doc tree, the
|
|
91
|
+
* site config, the nav — and on the playground that shared part is 66.7 KB of a
|
|
92
|
+
* 199 KB page. So pages are close enough in size that one measured sample times
|
|
93
|
+
* the count is a better estimate than anything short of downloading them, and
|
|
94
|
+
* it costs one request instead of 136.
|
|
95
|
+
*
|
|
96
|
+
* It is an ESTIMATE and the UI must say so. Compression is the reason: this
|
|
97
|
+
* measures the decompressed body, and what the copy occupies on disk is
|
|
98
|
+
* whatever the browser decides to store.
|
|
99
|
+
*/
|
|
100
|
+
export declare function junEstimateCopyBytes(sampleBytes: number, pages: number): number;
|
|
101
|
+
/** Fraction complete, clamped, safe on an empty plan. */
|
|
102
|
+
export declare function junOfflineProgress(done: number, total: number): number;
|
|
103
|
+
export interface JunOfflinePage {
|
|
104
|
+
path: string;
|
|
105
|
+
label: string;
|
|
106
|
+
/** The top-level page this one sits under — `''` for a top-level page itself. */
|
|
107
|
+
section: string;
|
|
108
|
+
}
|
|
109
|
+
export interface JunOfflineSection {
|
|
110
|
+
/** Top-level path, `/` for the ones that hang off the root. */
|
|
111
|
+
path: string;
|
|
112
|
+
label: string;
|
|
113
|
+
pages: JunOfflinePage[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The site's pages, grouped by the section a reader would name.
|
|
117
|
+
*
|
|
118
|
+
* "The whole site" is 136 pages on the playground, and a reader who wants the
|
|
119
|
+
* writing does not want the film chapters. The panel does not offer per-section
|
|
120
|
+
* saving yet (`ROUND-11.md` §8), but the grouping is what makes the SIZE of the
|
|
121
|
+
* ask legible — "136 pages across 9 sections" is a sentence; "136 pages" is a
|
|
122
|
+
* number you either accept or do not.
|
|
123
|
+
*
|
|
124
|
+
* Order is the order the pages arrive in, which is the tree's own `order` —
|
|
125
|
+
* the same sequence the navigation shows. Sorting alphabetically here would
|
|
126
|
+
* make the panel disagree with the navbar for no gain.
|
|
127
|
+
*/
|
|
128
|
+
export declare function junGroupOfflinePages(pages: JunOfflinePage[]): JunOfflineSection[];
|
|
129
|
+
/**
|
|
130
|
+
* Should this URL be saved at all?
|
|
131
|
+
*
|
|
132
|
+
* The worker's pass-through list, restated for the SAVING side — the two have
|
|
133
|
+
* to agree or the page writes entries the worker will never read. Live data
|
|
134
|
+
* (`/api/`), the feeds and the manifest are all things whose freshness is the
|
|
135
|
+
* whole point; a saved copy of them is worse than no copy, because it would be
|
|
136
|
+
* served in preference to a network that had come back.
|
|
137
|
+
*/
|
|
138
|
+
export declare function junOfflineSavable(path: string): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export const JUN_OFFLINE_MODES = ["off", "visited", "site"];
|
|
2
|
+
export const JUN_OFFLINE_MODE_KEY = "jun_offline_mode";
|
|
3
|
+
export const JUN_OFFLINE_MEDIA_KEY = "jun_offline_media";
|
|
4
|
+
export const JUN_OFFLINE_SAVED_KEY = "jun_offline_saved";
|
|
5
|
+
export const JUN_OFFLINE_MODE_URL = "/__jun-offline-mode";
|
|
6
|
+
export function junOfflineCacheName(buildId) {
|
|
7
|
+
return `jun-${buildId || "dev"}`;
|
|
8
|
+
}
|
|
9
|
+
export function junReadOfflineMode(stored, fallback = "visited") {
|
|
10
|
+
return JUN_OFFLINE_MODES.includes(stored ?? "") ? stored : fallback;
|
|
11
|
+
}
|
|
12
|
+
export function junPageAssets(html, options) {
|
|
13
|
+
const out = /* @__PURE__ */ new Set();
|
|
14
|
+
for (const m of html.matchAll(/["'(]([^"'()\s]*\/_nuxt\/[^"'()\s]+)["')]/g)) {
|
|
15
|
+
const url = m[1];
|
|
16
|
+
if (url.startsWith("/")) out.add(url);
|
|
17
|
+
}
|
|
18
|
+
if (options?.media) {
|
|
19
|
+
for (const m of html.matchAll(/["'(\s]([^"'()\s,]*\/uploads\/[^"'()\s,]+)["')\s,]/g)) {
|
|
20
|
+
const url = m[1];
|
|
21
|
+
if (url.startsWith("/")) out.add(url);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return [...out];
|
|
25
|
+
}
|
|
26
|
+
export function junOfflineBudgetBytes(mb, fallbackMb = 60) {
|
|
27
|
+
const value = typeof mb === "number" && Number.isFinite(mb) && mb > 0 ? mb : fallbackMb;
|
|
28
|
+
return Math.round(value * 1024 * 1024);
|
|
29
|
+
}
|
|
30
|
+
export function junFormatBytes(bytes) {
|
|
31
|
+
if (typeof bytes !== "number" || !Number.isFinite(bytes) || bytes < 0) return "\u2014";
|
|
32
|
+
if (bytes < 1e3) return `${Math.round(bytes)} B`;
|
|
33
|
+
const units = ["kB", "MB", "GB"];
|
|
34
|
+
let value = bytes / 1e3;
|
|
35
|
+
let unit = 0;
|
|
36
|
+
while (value >= 1e3 && unit < units.length - 1) {
|
|
37
|
+
value /= 1e3;
|
|
38
|
+
unit++;
|
|
39
|
+
}
|
|
40
|
+
return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`;
|
|
41
|
+
}
|
|
42
|
+
export function junEstimateCopyBytes(sampleBytes, pages) {
|
|
43
|
+
if (!(sampleBytes > 0) || !(pages > 0)) return 0;
|
|
44
|
+
return Math.round(sampleBytes * pages);
|
|
45
|
+
}
|
|
46
|
+
export function junOfflineProgress(done, total) {
|
|
47
|
+
if (!(total > 0)) return 0;
|
|
48
|
+
return Math.max(0, Math.min(1, done / total));
|
|
49
|
+
}
|
|
50
|
+
export function junGroupOfflinePages(pages) {
|
|
51
|
+
const sections = [];
|
|
52
|
+
const index = /* @__PURE__ */ new Map();
|
|
53
|
+
for (const page of pages) {
|
|
54
|
+
const key = page.section || page.path;
|
|
55
|
+
let section = index.get(key);
|
|
56
|
+
if (!section) {
|
|
57
|
+
section = { path: key, label: page.section ? key.replace(/^\//, "") : page.label, pages: [] };
|
|
58
|
+
index.set(key, section);
|
|
59
|
+
sections.push(section);
|
|
60
|
+
}
|
|
61
|
+
if (!page.section) section.label = page.label;
|
|
62
|
+
section.pages.push(page);
|
|
63
|
+
}
|
|
64
|
+
return sections;
|
|
65
|
+
}
|
|
66
|
+
export function junOfflineSavable(path) {
|
|
67
|
+
if (!path.startsWith("/")) return false;
|
|
68
|
+
if (path.startsWith("/api/")) return false;
|
|
69
|
+
if (path === JUN_OFFLINE_MODE_URL) return false;
|
|
70
|
+
if (path === "/manifest.webmanifest") return false;
|
|
71
|
+
if (path === "/feed.xml" || path === "/feed.json" || path === "/sitemap.xml") return false;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a search query means, and which page answers it best.
|
|
3
|
+
*
|
|
4
|
+
* Zero imports, like `junNavValue` and `junSocial` — the rules here are
|
|
5
|
+
* arithmetic over strings, they decide what a person sees when they type two
|
|
6
|
+
* words, and none of them is visible on a rendered page.
|
|
7
|
+
*
|
|
8
|
+
* ## The bug this replaced
|
|
9
|
+
*
|
|
10
|
+
* Every one of the endpoint's three passes was
|
|
11
|
+
* `haystack.toLowerCase().includes(query)` — the WHOLE query, as one string.
|
|
12
|
+
* So on a site with a page called *Making it look like yours*:
|
|
13
|
+
*
|
|
14
|
+
* "making" → found
|
|
15
|
+
* "look yours" → nothing, because those two words are not adjacent
|
|
16
|
+
* "yours making" → nothing, ever, on any page
|
|
17
|
+
*
|
|
18
|
+
* A person typing two words means "both of these", not "these two, in this
|
|
19
|
+
* order, touching". So: terms, AND, and a score that says which page has more
|
|
20
|
+
* of them and in a better place.
|
|
21
|
+
*/
|
|
22
|
+
/** Where a term was found. Higher is a better place to be found. */
|
|
23
|
+
export declare const JUN_FIELD_WEIGHT: {
|
|
24
|
+
readonly label: 100;
|
|
25
|
+
readonly excerpt: 60;
|
|
26
|
+
readonly body: 40;
|
|
27
|
+
};
|
|
28
|
+
export type JunSearchField = keyof typeof JUN_FIELD_WEIGHT;
|
|
29
|
+
export interface JunSearchFields {
|
|
30
|
+
label?: string;
|
|
31
|
+
excerpt?: string;
|
|
32
|
+
body?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The query, as terms.
|
|
36
|
+
*
|
|
37
|
+
* Capped at eight: past that a query is a paste rather than a search, and the
|
|
38
|
+
* scoring loop runs per term per document. Deduped, because "the the" should
|
|
39
|
+
* not double a page's score.
|
|
40
|
+
*/
|
|
41
|
+
export declare function junSearchTerms(query: string): string[];
|
|
42
|
+
/**
|
|
43
|
+
* How well a document answers a query. `0` means it does not.
|
|
44
|
+
*
|
|
45
|
+
* Every term must appear SOMEWHERE — that is the AND a person means. Beyond
|
|
46
|
+
* that:
|
|
47
|
+
*
|
|
48
|
+
* - a term is scored by the best field it appears in (a title beats a body);
|
|
49
|
+
* - a term at the very start of the label scores higher than one in the
|
|
50
|
+
* middle, which is the one rule carried over from the old endpoint;
|
|
51
|
+
* - the whole query appearing as a PHRASE is worth a bonus, so an exact title
|
|
52
|
+
* still wins against a page that merely contains the same words apart.
|
|
53
|
+
*
|
|
54
|
+
* The per-term scores are AVERAGED rather than summed, so a two-word query and
|
|
55
|
+
* a five-word one produce comparable numbers and a caller can use one
|
|
56
|
+
* threshold for both.
|
|
57
|
+
*/
|
|
58
|
+
export declare function junSearchScore(terms: readonly string[], fields: JunSearchFields): number;
|
|
59
|
+
export interface JunSnippetRange {
|
|
60
|
+
start: number;
|
|
61
|
+
end: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The stretch of `text` worth showing, and where the terms are inside it.
|
|
65
|
+
*
|
|
66
|
+
* Centred on the densest WINDOW rather than on the first match. With one term
|
|
67
|
+
* those are the same thing; with two they are not, and a snippet built around
|
|
68
|
+
* the first occurrence of the first term routinely shows neither word in
|
|
69
|
+
* context — which is what the old endpoint did.
|
|
70
|
+
*
|
|
71
|
+
* Returns offsets rather than marked-up text: the caller escapes, because
|
|
72
|
+
* escaping and marking in the same pass is how a search result ends up
|
|
73
|
+
* rendering somebody's `<script>`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function junSearchSnippet(text: string, terms: readonly string[], width?: number): {
|
|
76
|
+
start: number;
|
|
77
|
+
end: number;
|
|
78
|
+
marks: JunSnippetRange[];
|
|
79
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export const JUN_FIELD_WEIGHT = {
|
|
2
|
+
label: 100,
|
|
3
|
+
excerpt: 60,
|
|
4
|
+
body: 40
|
|
5
|
+
};
|
|
6
|
+
export function junSearchTerms(query) {
|
|
7
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8
|
+
for (const raw of query.toLowerCase().split(/\s+/)) {
|
|
9
|
+
const term = raw.trim();
|
|
10
|
+
if (term) seen.add(term);
|
|
11
|
+
if (seen.size >= 8) break;
|
|
12
|
+
}
|
|
13
|
+
return [...seen];
|
|
14
|
+
}
|
|
15
|
+
export function junSearchScore(terms, fields) {
|
|
16
|
+
if (!terms.length) return 0;
|
|
17
|
+
const label = (fields.label ?? "").toLowerCase();
|
|
18
|
+
const excerpt = (fields.excerpt ?? "").toLowerCase();
|
|
19
|
+
const body = (fields.body ?? "").toLowerCase();
|
|
20
|
+
let total = 0;
|
|
21
|
+
for (const term of terms) {
|
|
22
|
+
const inLabel = label.indexOf(term);
|
|
23
|
+
const inExcerpt = excerpt.indexOf(term);
|
|
24
|
+
const inBody = body.indexOf(term);
|
|
25
|
+
if (inLabel < 0 && inExcerpt < 0 && inBody < 0) return 0;
|
|
26
|
+
let best = 0;
|
|
27
|
+
if (inLabel >= 0) best = JUN_FIELD_WEIGHT.label + (inLabel === 0 ? 20 : 0);
|
|
28
|
+
else if (inExcerpt >= 0) best = JUN_FIELD_WEIGHT.excerpt;
|
|
29
|
+
else best = JUN_FIELD_WEIGHT.body;
|
|
30
|
+
total += best;
|
|
31
|
+
}
|
|
32
|
+
let score = total / terms.length;
|
|
33
|
+
if (terms.length > 1) {
|
|
34
|
+
const phrase = terms.join(" ");
|
|
35
|
+
if (label.includes(phrase)) score += 25;
|
|
36
|
+
else if (excerpt.includes(phrase) || body.includes(phrase)) score += 10;
|
|
37
|
+
}
|
|
38
|
+
return score;
|
|
39
|
+
}
|
|
40
|
+
export function junSearchSnippet(text, terms, width = 150) {
|
|
41
|
+
const haystack = text.toLowerCase();
|
|
42
|
+
const hits = [];
|
|
43
|
+
for (const term of terms) {
|
|
44
|
+
let from = 0;
|
|
45
|
+
for (let n = 0; n < 12; n++) {
|
|
46
|
+
const at = haystack.indexOf(term, from);
|
|
47
|
+
if (at < 0) break;
|
|
48
|
+
hits.push({ start: at, end: at + term.length });
|
|
49
|
+
from = at + term.length;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!hits.length) return { start: 0, end: Math.min(width, text.length), marks: [] };
|
|
53
|
+
hits.sort((a, b) => a.start - b.start);
|
|
54
|
+
let best = { start: hits[0].start, count: 0 };
|
|
55
|
+
for (const hit of hits) {
|
|
56
|
+
const windowEnd = hit.start + width;
|
|
57
|
+
const inside = /* @__PURE__ */ new Set();
|
|
58
|
+
for (const other of hits) {
|
|
59
|
+
if (other.start >= hit.start && other.end <= windowEnd) {
|
|
60
|
+
inside.add(haystack.slice(other.start, other.end));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (inside.size > best.count) best = { start: hit.start, count: inside.size };
|
|
64
|
+
}
|
|
65
|
+
let start = Math.max(0, best.start - 40);
|
|
66
|
+
while (start > 0 && !/\s/.test(text[start - 1] ?? "")) start--;
|
|
67
|
+
const end = Math.min(text.length, start + width);
|
|
68
|
+
return {
|
|
69
|
+
start,
|
|
70
|
+
end,
|
|
71
|
+
marks: hits.filter((h) => h.start >= start && h.end <= end)
|
|
72
|
+
};
|
|
73
|
+
}
|