@abraca/junis 2.85.0 → 2.86.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 +17 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +235 -19
- package/dist/runtime/assets/css/jun.css +1 -1
- package/dist/runtime/components/JunCampfirePresence.client.vue +75 -10
- package/dist/runtime/components/JunCollectionIntro.d.vue.ts +11 -0
- package/dist/runtime/components/JunCollectionIntro.vue +45 -0
- package/dist/runtime/components/JunCollectionIntro.vue.d.ts +11 -0
- package/dist/runtime/components/JunConfigRow.d.vue.ts +43 -0
- package/dist/runtime/components/JunConfigRow.vue +34 -0
- package/dist/runtime/components/JunConfigRow.vue.d.ts +43 -0
- package/dist/runtime/components/JunFooter.vue +1 -1
- package/dist/runtime/components/JunHorizontalTimeline.d.vue.ts +30 -0
- package/dist/runtime/components/JunHorizontalTimeline.vue.d.ts +30 -0
- package/dist/runtime/components/JunLinksRow.d.vue.ts +16 -1
- package/dist/runtime/components/JunLinksRow.vue +17 -7
- package/dist/runtime/components/JunLinksRow.vue.d.ts +16 -1
- package/dist/runtime/components/JunMedia.client.d.vue.ts +1 -1
- package/dist/runtime/components/JunMedia.client.vue.d.ts +1 -1
- package/dist/runtime/components/JunNavigation.vue +21 -4
- package/dist/runtime/components/JunNoteLinks.d.vue.ts +6 -0
- package/dist/runtime/components/JunNoteLinks.vue +57 -0
- package/dist/runtime/components/JunNoteLinks.vue.d.ts +6 -0
- package/dist/runtime/components/JunPageHero.d.vue.ts +8 -2
- package/dist/runtime/components/JunPageHero.vue +15 -3
- package/dist/runtime/components/JunPageHero.vue.d.ts +8 -2
- package/dist/runtime/components/JunReaders.d.vue.ts +11 -0
- package/dist/runtime/components/JunReaders.vue +99 -0
- package/dist/runtime/components/JunReaders.vue.d.ts +11 -0
- package/dist/runtime/components/JunSearch.client.vue +2 -2
- package/dist/runtime/components/JunSectionPresence.client.d.vue.ts +17 -0
- package/dist/runtime/components/JunSectionPresence.client.vue +99 -0
- package/dist/runtime/components/JunSectionPresence.client.vue.d.ts +17 -0
- package/dist/runtime/components/JunThreadComposer.d.vue.ts +37 -0
- package/dist/runtime/components/JunThreadComposer.vue +54 -0
- package/dist/runtime/components/JunThreadComposer.vue.d.ts +37 -0
- package/dist/runtime/components/JunTravellersChip.vue +35 -5
- package/dist/runtime/components/JunVideoEmbed.client.d.vue.ts +1 -1
- package/dist/runtime/components/JunVideoEmbed.client.vue.d.ts +1 -1
- package/dist/runtime/components/JunViewControl.d.vue.ts +29 -0
- package/dist/runtime/components/JunViewControl.vue +340 -0
- package/dist/runtime/components/JunViewControl.vue.d.ts +29 -0
- package/dist/runtime/components/JunViewControls.d.vue.ts +27 -0
- package/dist/runtime/components/JunViewControls.vue +94 -0
- package/dist/runtime/components/JunViewControls.vue.d.ts +27 -0
- package/dist/runtime/components/renderers/JunAppsRenderer.vue +45 -4
- package/dist/runtime/components/renderers/JunCinemaRenderer.vue +42 -4
- package/dist/runtime/components/renderers/JunConfigRenderer.vue +348 -225
- package/dist/runtime/components/renderers/JunCourseRenderer.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/JunCourseRenderer.vue +229 -0
- package/dist/runtime/components/renderers/JunCourseRenderer.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/JunCvRenderer.vue +44 -6
- package/dist/runtime/components/renderers/JunDeckRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/renderers/JunDeckRenderer.vue +370 -0
- package/dist/runtime/components/renderers/JunDeckRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/renderers/JunEntryRenderer.vue +151 -23
- package/dist/runtime/components/renderers/JunFestivalRenderer.vue +41 -4
- package/dist/runtime/components/renderers/JunGardenRenderer.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/JunGardenRenderer.vue +280 -0
- package/dist/runtime/components/renderers/JunGardenRenderer.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/JunGuestbookRenderer.vue +96 -14
- package/dist/runtime/components/renderers/JunHomeRenderer.vue +28 -129
- package/dist/runtime/components/renderers/JunItemRenderer.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/JunItemRenderer.vue +398 -0
- package/dist/runtime/components/renderers/JunItemRenderer.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/JunJournalRenderer.vue +141 -11
- package/dist/runtime/components/renderers/JunLibraryRenderer.vue +295 -12
- package/dist/runtime/components/renderers/JunLinksRenderer.vue +33 -1
- package/dist/runtime/components/renderers/JunLiveRenderer.vue +37 -1
- package/dist/runtime/components/renderers/JunMosaicRenderer.vue +3 -2
- package/dist/runtime/components/renderers/JunMovieRenderer.vue +32 -5
- package/dist/runtime/components/renderers/JunNowRenderer.vue +38 -5
- package/dist/runtime/components/renderers/JunPollRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/renderers/JunPollRenderer.vue +231 -0
- package/dist/runtime/components/renderers/JunPollRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/renderers/JunProjectRenderer.vue +74 -18
- package/dist/runtime/components/renderers/JunServicesRenderer.vue +40 -2
- package/dist/runtime/components/renderers/JunStatsRenderer.vue +37 -50
- package/dist/runtime/components/renderers/JunThreadRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/renderers/JunThreadRenderer.vue +304 -0
- package/dist/runtime/components/renderers/JunThreadRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/renderers/JunTrackRenderer.vue +32 -4
- package/dist/runtime/components/renderers/JunUsesRenderer.vue +51 -5
- package/dist/runtime/components/renderers/JunWallRenderer.vue +60 -5
- package/dist/runtime/composables/useJunDeck.d.ts +66 -0
- package/dist/runtime/composables/useJunDeck.js +61 -0
- package/dist/runtime/composables/useJunDocPage.d.ts +14 -11
- package/dist/runtime/composables/useJunDocPage.js +67 -3
- package/dist/runtime/composables/useJunFollow.d.ts +65 -9
- package/dist/runtime/composables/useJunFollow.js +237 -20
- package/dist/runtime/composables/useJunGarden.d.ts +67 -0
- package/dist/runtime/composables/useJunGarden.js +92 -0
- package/dist/runtime/composables/useJunPresence.d.ts +26 -0
- package/dist/runtime/composables/useJunPresence.js +9 -2
- package/dist/runtime/composables/useJunSections.d.ts +73 -0
- package/dist/runtime/composables/useJunSections.js +117 -0
- package/dist/runtime/composables/useJunSettings.d.ts +1 -1
- package/dist/runtime/composables/useJunSettings.js +5 -1
- package/dist/runtime/composables/useJunSiteConfig.d.ts +37 -0
- package/dist/runtime/composables/useJunTheme.js +40 -2
- package/dist/runtime/composables/useJunViewOptions.d.ts +85 -0
- package/dist/runtime/composables/useJunViewOptions.js +63 -0
- package/dist/runtime/pages/doc.vue +14 -8
- package/dist/runtime/server/api/health.get.d.ts +19 -0
- package/dist/runtime/server/api/health.get.js +40 -0
- package/dist/runtime/server/api/links.get.d.ts +19 -0
- package/dist/runtime/server/api/links.get.js +37 -0
- package/dist/runtime/server/api/resolve/[...slug].get.d.ts +9 -0
- package/dist/runtime/server/api/resolve/[...slug].get.js +5 -0
- package/dist/runtime/server/api/stats.get.js +2 -1
- package/dist/runtime/server/janitor/junJanitorChores.js +8 -0
- package/dist/runtime/server/plugins/jun-bootstrap.js +103 -15
- package/dist/runtime/server/plugins/jun-doc-cache.js +42 -4
- package/dist/runtime/server/plugins/jun-janitor.js +7 -0
- package/dist/runtime/server/plugins/jun-rpc.js +293 -0
- package/dist/runtime/server/plugins/jun-watchdog.d.ts +2 -0
- package/dist/runtime/server/plugins/jun-watchdog.js +54 -0
- package/dist/runtime/server/routes/sitemap.xml.get.js +2 -0
- package/dist/runtime/server/utils/junBoot.d.ts +1 -0
- package/dist/runtime/server/utils/junBoot.js +4 -0
- package/dist/runtime/server/utils/junCache.d.ts +17 -0
- package/dist/runtime/server/utils/junCache.js +5 -0
- package/dist/runtime/server/utils/junSeedGate.d.ts +68 -0
- package/dist/runtime/server/utils/junSeedGate.js +41 -0
- package/dist/runtime/types.d.ts +57 -1
- package/dist/runtime/utils/junCourse.d.ts +106 -0
- package/dist/runtime/utils/junCourse.js +65 -0
- package/dist/runtime/utils/junGarden.d.ts +193 -0
- package/dist/runtime/utils/junGarden.js +233 -0
- package/dist/runtime/utils/junMetaSchemas.js +8 -1
- package/dist/runtime/utils/junModeration.d.ts +67 -0
- package/dist/runtime/utils/junModeration.js +20 -0
- package/dist/runtime/utils/junMotion.d.ts +26 -0
- package/dist/runtime/utils/junMotion.js +31 -0
- package/dist/runtime/utils/junPeople.d.ts +43 -0
- package/dist/runtime/utils/junPeople.js +9 -0
- package/dist/runtime/utils/junPoll.d.ts +79 -0
- package/dist/runtime/utils/junPoll.js +82 -0
- package/dist/runtime/utils/junReadiness.d.ts +131 -0
- package/dist/runtime/utils/junReadiness.js +69 -0
- package/dist/runtime/utils/junSections.d.ts +115 -0
- package/dist/runtime/utils/junSections.js +45 -0
- package/dist/runtime/utils/junSlides.d.ts +66 -0
- package/dist/runtime/utils/junSlides.js +47 -0
- package/dist/runtime/utils/junThread.d.ts +81 -0
- package/dist/runtime/utils/junThread.js +75 -0
- package/dist/runtime/utils/junViewSpecs.d.ts +671 -0
- package/dist/runtime/utils/junViewSpecs.js +534 -0
- package/dist/runtime/utils/junViewValues.d.ts +125 -0
- package/dist/runtime/utils/junViewValues.js +104 -0
- package/dist/types.d.mts +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
export const JUN_MATURITIES = [
|
|
2
|
+
{ value: "seedling", label: "Seedling", icon: "i-lucide-sprout", hint: "Rough, and says so" },
|
|
3
|
+
{ value: "budding", label: "Budding", icon: "i-lucide-flower-2", hint: "Taking shape" },
|
|
4
|
+
{ value: "evergreen", label: "Evergreen", icon: "i-lucide-trees", hint: "Tended, and holds up" }
|
|
5
|
+
];
|
|
6
|
+
const MATURITY_VALUES = JUN_MATURITIES.map((m) => m.value);
|
|
7
|
+
export function junMaturityOf(meta) {
|
|
8
|
+
const raw = meta?.maturity;
|
|
9
|
+
return typeof raw === "string" && MATURITY_VALUES.includes(raw) ? raw : null;
|
|
10
|
+
}
|
|
11
|
+
const HREF_RE = /<a\s[^>]*?href\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi;
|
|
12
|
+
const DOC_ID_ATTR_RE = /\bdata-doc-id\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
|
|
13
|
+
const DOC_PATH_RE = /^\/doc\/([\w-]+)/;
|
|
14
|
+
function unescapeAttr(value) {
|
|
15
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code)));
|
|
16
|
+
}
|
|
17
|
+
export function junScanLinkTargets(html) {
|
|
18
|
+
if (!html) return [];
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const re of [HREF_RE, DOC_ID_ATTR_RE]) {
|
|
21
|
+
re.lastIndex = 0;
|
|
22
|
+
let m;
|
|
23
|
+
while (m = re.exec(html)) {
|
|
24
|
+
const raw = m[1] ?? m[2] ?? m[3] ?? "";
|
|
25
|
+
if (raw) out.push(unescapeAttr(raw).trim());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
export function junResolveLinkTarget(target, slugToId, knownIds) {
|
|
31
|
+
const raw = (target ?? "").trim();
|
|
32
|
+
if (!raw) return null;
|
|
33
|
+
if (knownIds.has(raw)) return raw;
|
|
34
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith("//")) return null;
|
|
35
|
+
if (raw.startsWith("#")) return null;
|
|
36
|
+
const path = raw.replace(/[?#].*$/, "");
|
|
37
|
+
const doc = DOC_PATH_RE.exec(path);
|
|
38
|
+
if (doc) return knownIds.has(doc[1]) ? doc[1] : null;
|
|
39
|
+
let slug = path;
|
|
40
|
+
try {
|
|
41
|
+
slug = decodeURIComponent(path);
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
slug = slug.replace(/^\/+/, "").replace(/\/+$/, "").toLowerCase();
|
|
45
|
+
const id = slugToId[slug];
|
|
46
|
+
return id && knownIds.has(id) ? id : null;
|
|
47
|
+
}
|
|
48
|
+
export function junGardenEdges(sources, slugToId, knownIds) {
|
|
49
|
+
const edges = [];
|
|
50
|
+
const seen = /* @__PURE__ */ new Map();
|
|
51
|
+
for (const source of sources) {
|
|
52
|
+
if (!source?.id || !knownIds.has(source.id)) continue;
|
|
53
|
+
const targets = source.targets ?? junScanLinkTargets(source.html);
|
|
54
|
+
for (const target of targets) {
|
|
55
|
+
const id = junResolveLinkTarget(target, slugToId, knownIds);
|
|
56
|
+
if (!id || id === source.id) continue;
|
|
57
|
+
const key = `${source.id}\0${id}`;
|
|
58
|
+
const existing = seen.get(key);
|
|
59
|
+
if (existing) {
|
|
60
|
+
existing.weight++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const edge = { source: source.id, target: id, weight: 1 };
|
|
64
|
+
seen.set(key, edge);
|
|
65
|
+
edges.push(edge);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return edges;
|
|
69
|
+
}
|
|
70
|
+
export function junGardenNotes(entries, edges, scope) {
|
|
71
|
+
const byId = /* @__PURE__ */ new Map();
|
|
72
|
+
for (const entry of entries) if (entry?.id) byId.set(entry.id, entry);
|
|
73
|
+
const refOf = (id, weight) => {
|
|
74
|
+
const entry = byId.get(id);
|
|
75
|
+
return {
|
|
76
|
+
id,
|
|
77
|
+
label: (entry?.label ?? "").trim() || "Untitled",
|
|
78
|
+
href: entry?.href,
|
|
79
|
+
weight
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const notes = /* @__PURE__ */ new Map();
|
|
83
|
+
for (const id of scope) {
|
|
84
|
+
const entry = byId.get(id);
|
|
85
|
+
if (!entry) continue;
|
|
86
|
+
notes.set(id, {
|
|
87
|
+
id,
|
|
88
|
+
label: (entry.label ?? "").trim() || "Untitled",
|
|
89
|
+
href: entry.href,
|
|
90
|
+
type: entry.type,
|
|
91
|
+
maturity: junMaturityOf(entry.meta),
|
|
92
|
+
updatedAt: entry.updatedAt ?? entry.createdAt ?? 0,
|
|
93
|
+
inbound: [],
|
|
94
|
+
outbound: [],
|
|
95
|
+
degree: 0
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
for (const edge of edges) {
|
|
99
|
+
const from = notes.get(edge.source);
|
|
100
|
+
const to = notes.get(edge.target);
|
|
101
|
+
if (from && byId.has(edge.target)) from.outbound.push(refOf(edge.target, edge.weight));
|
|
102
|
+
if (to && byId.has(edge.source)) to.inbound.push(refOf(edge.source, edge.weight));
|
|
103
|
+
}
|
|
104
|
+
for (const note of notes.values()) {
|
|
105
|
+
note.inbound.sort((a, b) => b.weight - a.weight || a.label.localeCompare(b.label));
|
|
106
|
+
note.outbound.sort((a, b) => b.weight - a.weight || a.label.localeCompare(b.label));
|
|
107
|
+
note.degree = note.inbound.length + note.outbound.length;
|
|
108
|
+
}
|
|
109
|
+
return [...notes.values()];
|
|
110
|
+
}
|
|
111
|
+
export function junGardenOrphans(notes) {
|
|
112
|
+
return notes.filter((n) => n.inbound.length === 0);
|
|
113
|
+
}
|
|
114
|
+
export function junGardenSort(notes, key) {
|
|
115
|
+
const byLabel = (a, b) => a.label.localeCompare(b.label);
|
|
116
|
+
const list = [...notes];
|
|
117
|
+
if (key === "alpha") return list.sort(byLabel);
|
|
118
|
+
if (key === "recent") return list.sort((a, b) => b.updatedAt - a.updatedAt || byLabel(a, b));
|
|
119
|
+
return list.sort((a, b) => b.inbound.length - a.inbound.length || b.degree - a.degree || byLabel(a, b));
|
|
120
|
+
}
|
|
121
|
+
export function junGardenCounts(notes) {
|
|
122
|
+
let links = 0;
|
|
123
|
+
let orphans = 0;
|
|
124
|
+
let evergreen = 0;
|
|
125
|
+
for (const note of notes) {
|
|
126
|
+
links += note.outbound.length;
|
|
127
|
+
if (note.inbound.length === 0) orphans++;
|
|
128
|
+
if (note.maturity === "evergreen") evergreen++;
|
|
129
|
+
}
|
|
130
|
+
return { notes: notes.length, links, orphans, evergreen };
|
|
131
|
+
}
|
|
132
|
+
const GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
|
|
133
|
+
const GRAVITY = 0.035;
|
|
134
|
+
export function junGardenLayout(ids, edges, options = {}) {
|
|
135
|
+
const width = options.width ?? 1e3;
|
|
136
|
+
const height = options.height ?? 640;
|
|
137
|
+
const padding = options.padding ?? 28;
|
|
138
|
+
const iterations = options.iterations ?? 240;
|
|
139
|
+
const spread = options.spread ?? 1;
|
|
140
|
+
const n = ids.length;
|
|
141
|
+
if (n === 0) return [];
|
|
142
|
+
if (n === 1) return [{ id: ids[0], x: width / 2, y: height / 2 }];
|
|
143
|
+
const index = /* @__PURE__ */ new Map();
|
|
144
|
+
ids.forEach((id, i) => index.set(id, i));
|
|
145
|
+
const xs = new Float64Array(n);
|
|
146
|
+
const ys = new Float64Array(n);
|
|
147
|
+
for (let i = 0; i < n; i++) {
|
|
148
|
+
const r = 0.5 * Math.sqrt((i + 0.5) / n);
|
|
149
|
+
const a = i * GOLDEN_ANGLE;
|
|
150
|
+
xs[i] = 0.5 + r * Math.cos(a);
|
|
151
|
+
ys[i] = 0.5 + r * Math.sin(a);
|
|
152
|
+
}
|
|
153
|
+
const links = [];
|
|
154
|
+
for (const edge of edges) {
|
|
155
|
+
const a = index.get(edge.source);
|
|
156
|
+
const b = index.get(edge.target);
|
|
157
|
+
if (a === void 0 || b === void 0 || a === b) continue;
|
|
158
|
+
links.push([a, b, Math.min(edge.weight || 1, 4)]);
|
|
159
|
+
}
|
|
160
|
+
const k = spread * Math.sqrt(1 / n);
|
|
161
|
+
const dx = new Float64Array(n);
|
|
162
|
+
const dy = new Float64Array(n);
|
|
163
|
+
for (let step = 0; step < iterations; step++) {
|
|
164
|
+
const temp = 0.1 * (1 - step / iterations);
|
|
165
|
+
dx.fill(0);
|
|
166
|
+
dy.fill(0);
|
|
167
|
+
for (let i = 0; i < n; i++) {
|
|
168
|
+
for (let j = i + 1; j < n; j++) {
|
|
169
|
+
let vx = xs[i] - xs[j];
|
|
170
|
+
let vy = ys[i] - ys[j];
|
|
171
|
+
let dist = Math.sqrt(vx * vx + vy * vy);
|
|
172
|
+
if (dist < 1e-9) {
|
|
173
|
+
vx = ((i * 7 + j * 3) % 11 - 5) * 1e-4 || 1e-4;
|
|
174
|
+
vy = ((i * 5 + j * 9) % 13 - 6) * 1e-4 || 1e-4;
|
|
175
|
+
dist = Math.sqrt(vx * vx + vy * vy);
|
|
176
|
+
}
|
|
177
|
+
const force = k * k / dist;
|
|
178
|
+
const fx = vx / dist * force;
|
|
179
|
+
const fy = vy / dist * force;
|
|
180
|
+
dx[i] += fx;
|
|
181
|
+
dy[i] += fy;
|
|
182
|
+
dx[j] -= fx;
|
|
183
|
+
dy[j] -= fy;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const [a, b, weight] of links) {
|
|
187
|
+
const vx = xs[a] - xs[b];
|
|
188
|
+
const vy = ys[a] - ys[b];
|
|
189
|
+
const dist = Math.max(Math.sqrt(vx * vx + vy * vy), 1e-9);
|
|
190
|
+
const force = dist * dist / k * weight;
|
|
191
|
+
const fx = vx / dist * force;
|
|
192
|
+
const fy = vy / dist * force;
|
|
193
|
+
dx[a] -= fx;
|
|
194
|
+
dy[a] -= fy;
|
|
195
|
+
dx[b] += fx;
|
|
196
|
+
dy[b] += fy;
|
|
197
|
+
}
|
|
198
|
+
for (let i = 0; i < n; i++) {
|
|
199
|
+
dx[i] += (0.5 - xs[i]) * GRAVITY;
|
|
200
|
+
dy[i] += (0.5 - ys[i]) * GRAVITY;
|
|
201
|
+
const len = Math.sqrt(dx[i] * dx[i] + dy[i] * dy[i]);
|
|
202
|
+
if (len > 1e-12) {
|
|
203
|
+
const move = Math.min(len, temp);
|
|
204
|
+
xs[i] += dx[i] / len * move;
|
|
205
|
+
ys[i] += dy[i] / len * move;
|
|
206
|
+
}
|
|
207
|
+
xs[i] = Math.min(1.2, Math.max(-0.2, xs[i]));
|
|
208
|
+
ys[i] = Math.min(1.2, Math.max(-0.2, ys[i]));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
let minX = Infinity;
|
|
212
|
+
let maxX = -Infinity;
|
|
213
|
+
let minY = Infinity;
|
|
214
|
+
let maxY = -Infinity;
|
|
215
|
+
for (let i = 0; i < n; i++) {
|
|
216
|
+
minX = Math.min(minX, xs[i]);
|
|
217
|
+
maxX = Math.max(maxX, xs[i]);
|
|
218
|
+
minY = Math.min(minY, ys[i]);
|
|
219
|
+
maxY = Math.max(maxY, ys[i]);
|
|
220
|
+
}
|
|
221
|
+
const spanX = Math.max(maxX - minX, 1e-6);
|
|
222
|
+
const spanY = Math.max(maxY - minY, 1e-6);
|
|
223
|
+
const boxW = Math.max(width - padding * 2, 1);
|
|
224
|
+
const boxH = Math.max(height - padding * 2, 1);
|
|
225
|
+
return ids.map((id, i) => ({
|
|
226
|
+
id,
|
|
227
|
+
x: round(padding + (xs[i] - minX) / spanX * boxW),
|
|
228
|
+
y: round(padding + (ys[i] - minY) / spanY * boxH)
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
function round(value) {
|
|
232
|
+
return Math.round(value * 100) / 100;
|
|
233
|
+
}
|
|
@@ -43,10 +43,17 @@ const SCHEMAS = {
|
|
|
43
43
|
{ type: "icon", key: "icon", label: "Icon" },
|
|
44
44
|
{ type: "text", key: "description", label: "Description" }
|
|
45
45
|
],
|
|
46
|
+
// `rating` and `description` are declared even though the SHELF edits both
|
|
47
|
+
// (stars on the row, a chip beside them). This schema is what a book's OWN
|
|
48
|
+
// page offers, and a field a page type stores but cannot be given from the
|
|
49
|
+
// document holding it is a field that only exists where somebody happens to
|
|
50
|
+
// be standing.
|
|
46
51
|
library: [
|
|
47
52
|
{ type: "select", key: "status", options: [...JUN_LIBRARY_STATUSES], label: "Status" },
|
|
48
53
|
{ type: "text", key: "author", label: "Author" },
|
|
49
|
-
{ type: "
|
|
54
|
+
{ type: "rating", key: "rating", label: "Rating" },
|
|
55
|
+
{ type: "url", key: "url", label: "URL" },
|
|
56
|
+
{ type: "text", key: "description", label: "Description" }
|
|
50
57
|
],
|
|
51
58
|
apps: [
|
|
52
59
|
{ type: "select", key: "status", options: [...JUN_APP_STATUSES], label: "Status" },
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an owner can do to something a visitor wrote — the two meta keys, once.
|
|
3
|
+
*
|
|
4
|
+
* No Vue, no `#imports`, **no imports at all**: three surfaces read these keys
|
|
5
|
+
* (the conversation, the guestbook, and the server when it refuses to post into a
|
|
6
|
+
* closed thread), and a second spelling of "removed" would mean a post hidden on
|
|
7
|
+
* one page and visible on another.
|
|
8
|
+
*
|
|
9
|
+
* ── Removing is not deleting ─────────────────────────────────────────────────
|
|
10
|
+
*
|
|
11
|
+
* `meta.moderated` takes something out of the conversation and KEEPS the
|
|
12
|
+
* document: the owner still sees it, greyed, and can put it back. Destroying
|
|
13
|
+
* somebody's words is the trash — deliberately a second, separate act, with its
|
|
14
|
+
* own undo.
|
|
15
|
+
*
|
|
16
|
+
* ── Pinning is an owner saying "read this one" ────────────────────────────────
|
|
17
|
+
*
|
|
18
|
+
* So it wins over every ordering. An order that could bury a pinned item makes
|
|
19
|
+
* the act meaningless, which is why this is a sort rather than a flag the
|
|
20
|
+
* renderers each apply in their own way.
|
|
21
|
+
*/
|
|
22
|
+
export interface JunModeratable {
|
|
23
|
+
meta?: Record<string, unknown> | null;
|
|
24
|
+
}
|
|
25
|
+
/** Removed by the owner: out of the list, still a document. */
|
|
26
|
+
export declare function junIsModerated(meta: Record<string, unknown> | null | undefined): boolean;
|
|
27
|
+
/** Held at the top by the owner. */
|
|
28
|
+
export declare function junIsPinned(meta: Record<string, unknown> | null | undefined): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Does this document count as something a visitor said?
|
|
31
|
+
*
|
|
32
|
+
* The predicate behind the Pulse page's *Signatures*, and it lives here because
|
|
33
|
+
* **two separate computations use it** — `stats.get` in Nitro and the live
|
|
34
|
+
* recompute in `JunStatsRenderer` — and the two must never disagree about the same
|
|
35
|
+
* number. That is not hypothetical: for one release the pair counted removed
|
|
36
|
+
* signatures, because the count predates moderation and neither half had heard of
|
|
37
|
+
* `meta.moderated`.
|
|
38
|
+
*
|
|
39
|
+
* A removed signature does NOT count. The Pulse page is public, the number is what
|
|
40
|
+
* a visitor is told the site holds, and telling them about a line the owner took
|
|
41
|
+
* down is the one reading that is definitely wrong. The document still exists — the
|
|
42
|
+
* owner can still see it and restore it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function junIsVisibleMessage(meta: Record<string, unknown> | null | undefined): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* A visitor-written list, moderated: hidden entries dropped, pinned ones first.
|
|
47
|
+
*
|
|
48
|
+
* `includeHidden` is the OWNER's view — they must be able to see what they have
|
|
49
|
+
* removed, or "restore" is a button for something invisible. It is never derived
|
|
50
|
+
* from anything but edit mode: a reader must not be able to ask for the hidden
|
|
51
|
+
* ones.
|
|
52
|
+
*
|
|
53
|
+
* The incoming order is otherwise preserved exactly. Deciding the sort here would
|
|
54
|
+
* mean this function owned two decisions, and every caller already has its own
|
|
55
|
+
* (newest first, oldest first, by weight).
|
|
56
|
+
*/
|
|
57
|
+
export declare function junModerateList<T extends JunModeratable>(list: T[], options?: {
|
|
58
|
+
includeHidden?: boolean;
|
|
59
|
+
}): T[];
|
|
60
|
+
/**
|
|
61
|
+
* The next value for a toggled flag.
|
|
62
|
+
*
|
|
63
|
+
* `undefined` rather than `false`, because that is what CLEARS the key — the same
|
|
64
|
+
* rule every setting in this module follows, and the reason a restored post is
|
|
65
|
+
* indistinguishable from one that was never removed.
|
|
66
|
+
*/
|
|
67
|
+
export declare function junToggleFlag(current: boolean): true | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function junIsModerated(meta) {
|
|
2
|
+
return meta?.moderated === true;
|
|
3
|
+
}
|
|
4
|
+
export function junIsPinned(meta) {
|
|
5
|
+
return meta?.pinned === true;
|
|
6
|
+
}
|
|
7
|
+
export function junIsVisibleMessage(meta) {
|
|
8
|
+
const message = meta?.message;
|
|
9
|
+
return typeof message === "string" && !!message.trim() && !junIsModerated(meta);
|
|
10
|
+
}
|
|
11
|
+
export function junModerateList(list, options = {}) {
|
|
12
|
+
const visible = options.includeHidden ? [...list] : list.filter((entry) => !junIsModerated(entry?.meta));
|
|
13
|
+
const pinned = [];
|
|
14
|
+
const rest = [];
|
|
15
|
+
for (const entry of visible) (junIsPinned(entry?.meta) ? pinned : rest).push(entry);
|
|
16
|
+
return [...pinned, ...rest];
|
|
17
|
+
}
|
|
18
|
+
export function junToggleFlag(current) {
|
|
19
|
+
return current ? void 0 : true;
|
|
20
|
+
}
|
|
@@ -55,10 +55,36 @@ export interface JunMotionVariants {
|
|
|
55
55
|
tapped?: JunMotionState;
|
|
56
56
|
focused?: JunMotionState;
|
|
57
57
|
}
|
|
58
|
+
/** How much movement the page is allowed. */
|
|
59
|
+
export type JunMotionLevel = 'full' | 'reduced' | 'none';
|
|
60
|
+
export declare const JUN_MOTION_LEVELS: JunMotionLevel[];
|
|
61
|
+
/** Set from the site config (`useJunThemeApply`). */
|
|
62
|
+
export declare function junSetMotionLevel(level: JunMotionLevel | string | undefined): void;
|
|
63
|
+
/** Set from `prefers-reduced-motion` on the client. */
|
|
64
|
+
export declare function junSetMotionFloor(reduced: boolean): void;
|
|
65
|
+
/** What actually applies: the stricter of the two. */
|
|
66
|
+
export declare function junMotionLevel(): JunMotionLevel;
|
|
67
|
+
/**
|
|
68
|
+
* The variants with every MOVEMENT removed — opacity only, and quickly.
|
|
69
|
+
*
|
|
70
|
+
* "Reduced" is not "none": something appearing still has to announce that it
|
|
71
|
+
* appeared, and a fade does that without moving anything. This is the same
|
|
72
|
+
* distinction `jun.css` draws in its `prefers-reduced-motion` blocks, which take
|
|
73
|
+
* the transform and keep the fade.
|
|
74
|
+
*/
|
|
75
|
+
export declare function junReduceVariants(variants: JunMotionVariants): JunMotionVariants;
|
|
58
76
|
/**
|
|
59
77
|
* Pass motion variants to `v-motion` with the OBJECT type-checked and the
|
|
60
78
|
* directive value left unchecked.
|
|
61
79
|
*
|
|
80
|
+
* ── It now honours the motion level, and it never did ────────────────────────
|
|
81
|
+
*
|
|
82
|
+
* `v-motion` animates in JAVASCRIPT. Every `prefers-reduced-motion` block in
|
|
83
|
+
* `jun.css` is therefore invisible to it: a visitor who asked their system for
|
|
84
|
+
* less motion still got every card sliding up, every list staggering in and every
|
|
85
|
+
* hero rising on every page, because nothing in the JS path had ever read the
|
|
86
|
+
* preference. This function is the only place all ~20 call sites pass through.
|
|
87
|
+
*
|
|
62
88
|
* The return type is `any`, not `unknown`, and that is forced: the directive
|
|
63
89
|
* resolves to a declared `Options<any>` whose shape does not match what
|
|
64
90
|
* `v-motion` actually accepts, and `unknown` is not assignable to it
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
export const JUN_MOTION_LEVELS = ["full", "reduced", "none"];
|
|
2
|
+
let siteLevel = "full";
|
|
3
|
+
let visitorReduced = false;
|
|
4
|
+
export function junSetMotionLevel(level) {
|
|
5
|
+
siteLevel = JUN_MOTION_LEVELS.includes(level) ? level : "full";
|
|
6
|
+
}
|
|
7
|
+
export function junSetMotionFloor(reduced) {
|
|
8
|
+
visitorReduced = reduced;
|
|
9
|
+
}
|
|
10
|
+
export function junMotionLevel() {
|
|
11
|
+
if (siteLevel === "none") return "none";
|
|
12
|
+
return visitorReduced ? "reduced" : siteLevel;
|
|
13
|
+
}
|
|
14
|
+
export function junReduceVariants(variants) {
|
|
15
|
+
const fade = (state) => {
|
|
16
|
+
if (!state) return void 0;
|
|
17
|
+
const out2 = {};
|
|
18
|
+
if (state.opacity !== void 0) out2.opacity = state.opacity;
|
|
19
|
+
out2.transition = { duration: Math.min(state.transition?.duration ?? 200, 200) };
|
|
20
|
+
return out2;
|
|
21
|
+
};
|
|
22
|
+
const out = {};
|
|
23
|
+
for (const key of Object.keys(variants)) {
|
|
24
|
+
const reduced = fade(variants[key]);
|
|
25
|
+
if (reduced) out[key] = reduced;
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
1
29
|
export function junMotion(variants) {
|
|
30
|
+
const level = junMotionLevel();
|
|
31
|
+
if (level === "none") return {};
|
|
32
|
+
if (level === "reduced") return junReduceVariants(variants);
|
|
2
33
|
return variants;
|
|
3
34
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One rule, in one place: **a person is not a session.**
|
|
3
|
+
*
|
|
4
|
+
* Awareness is per tab. Anything the site COUNTS or LISTS has to collapse a
|
|
5
|
+
* peer's sessions down to the person behind them, and last round found five
|
|
6
|
+
* separate consumers each deciding that for itself — three of them wrongly, so
|
|
7
|
+
* one visitor with a second window read as two travellers in the navbar, in
|
|
8
|
+
* `byDocId` and in the travellers chip.
|
|
9
|
+
*
|
|
10
|
+
* It lived in `useJunPresence.ts` after that, which fixed the duplication but
|
|
11
|
+
* left the rule untestable: that file imports `vue` and `#imports`, so it cannot
|
|
12
|
+
* be loaded outside a Nuxt app. Here it has no imports at all, and
|
|
13
|
+
* `test/sections.test.mts` pins it — including the two tie-breaks that are easy
|
|
14
|
+
* to get subtly wrong and impossible to see on a page.
|
|
15
|
+
*
|
|
16
|
+
* Structural, not typed to `JunTraveller`: section presence deduplicates peer
|
|
17
|
+
* MARKS, which carry a different payload and the same identity.
|
|
18
|
+
*/
|
|
19
|
+
export interface JunPersonLike {
|
|
20
|
+
/** The session. Unique per tab, and never stable across a reload. */
|
|
21
|
+
clientId: number;
|
|
22
|
+
/** The person. Null only for a peer whose awareness state carries no key. */
|
|
23
|
+
publicKey?: string | null;
|
|
24
|
+
/** A background tab. */
|
|
25
|
+
idle?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One entry per person, from a list with one entry per session.
|
|
29
|
+
*
|
|
30
|
+
* Two tie-breaks, both deliberate:
|
|
31
|
+
*
|
|
32
|
+
* - **The awake session speaks for the person.** An idle background tab must
|
|
33
|
+
* not report where its owner is, and somebody present in both an idle and an
|
|
34
|
+
* active tab should read as present.
|
|
35
|
+
* - **A peer with no public key falls back to its session** rather than being
|
|
36
|
+
* dropped. That is the same tolerance rule the renderers apply to foreign
|
|
37
|
+
* children: an unrecognised shape is still somebody, and silently deleting
|
|
38
|
+
* people from a presence list is the worse failure.
|
|
39
|
+
*
|
|
40
|
+
* Order is preserved — first-seen wins position, so a list that was sorted stays
|
|
41
|
+
* sorted.
|
|
42
|
+
*/
|
|
43
|
+
export declare function junDedupePeople<T extends JunPersonLike>(list: T[]): T[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function junDedupePeople(list) {
|
|
2
|
+
const byPerson = /* @__PURE__ */ new Map();
|
|
3
|
+
for (const entry of list) {
|
|
4
|
+
const key = entry.publicKey ?? `session:${entry.clientId}`;
|
|
5
|
+
const held = byPerson.get(key);
|
|
6
|
+
if (!held || held.idle && !entry.idle) byPerson.set(key, entry);
|
|
7
|
+
}
|
|
8
|
+
return [...byPerson.values()];
|
|
9
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic behind `jun-poll` — counting votes without lying about them.
|
|
3
|
+
*
|
|
4
|
+
* No Vue, no `#imports`, **no imports at all**: the server's RPC handler and the
|
|
5
|
+
* renderer both need this, and neither may hold its own copy of the counting
|
|
6
|
+
* rules. That is not a style preference — the SERVER decides what a vote is worth
|
|
7
|
+
* and the CLIENT draws the bars, and if they disagree the page shows a total
|
|
8
|
+
* nobody cast.
|
|
9
|
+
*
|
|
10
|
+
* ── One vote per PERSON ──────────────────────────────────────────────────────
|
|
11
|
+
*
|
|
12
|
+
* Votes are stored as `meta.pollVotes: { [signerId]: number[] }` — keyed by the
|
|
13
|
+
* voter's server-stamped identity, so a second tab, a reload and a reconnect are
|
|
14
|
+
* all the same vote. That is the same rule every count in this module follows,
|
|
15
|
+
* and it is the only one a poll cannot get away with breaking: a tally that counts
|
|
16
|
+
* sessions is not a tally, it is a measure of how many windows people keep open.
|
|
17
|
+
*
|
|
18
|
+
* The server stamps the key (`ctx.from`), never the client. A client-supplied
|
|
19
|
+
* voter id would make ballot-stuffing a one-line change.
|
|
20
|
+
*/
|
|
21
|
+
/** How many voters one poll may record. Beyond this the oldest are dropped. */
|
|
22
|
+
export declare const JUN_POLL_VOTERS_MAX = 5000;
|
|
23
|
+
/** How many choices a poll may offer, and how long each may be. */
|
|
24
|
+
export declare const JUN_POLL_CHOICES_MAX = 12;
|
|
25
|
+
export declare const JUN_POLL_CHOICE_LENGTH = 80;
|
|
26
|
+
export interface JunPollTally {
|
|
27
|
+
/** Per choice index, in the choices' own order. */
|
|
28
|
+
counts: number[];
|
|
29
|
+
/** Percentages that sum to exactly 100 (or all zero when nobody has voted). */
|
|
30
|
+
percentages: number[];
|
|
31
|
+
/** Distinct people who have voted. */
|
|
32
|
+
voters: number;
|
|
33
|
+
/** The highest count, for drawing bars relative to the leader. */
|
|
34
|
+
leader: number;
|
|
35
|
+
}
|
|
36
|
+
/** The choices a poll offers, cleaned. Stored as `meta.pollOptions`. */
|
|
37
|
+
export declare function junPollChoices(raw: unknown): string[];
|
|
38
|
+
/** Every ballot, keyed by voter, with anything unparseable dropped. */
|
|
39
|
+
export declare function junPollBallots(raw: unknown, choiceCount: number): Record<string, number[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Count them.
|
|
42
|
+
*
|
|
43
|
+
* Percentages are of VOTERS, not of votes cast, so a multi-choice poll reads as
|
|
44
|
+
* "62% of people picked this" rather than as a set of fractions that mean nothing
|
|
45
|
+
* on their own. They are rounded so the visible numbers sum to exactly 100 —
|
|
46
|
+
* largest-remainder, because three equal thirds displayed as 33/33/33 makes a
|
|
47
|
+
* reader who adds them up think a vote went missing.
|
|
48
|
+
*/
|
|
49
|
+
export declare function junTallyVotes(ballots: Record<string, number[]>, choiceCount: number): JunPollTally;
|
|
50
|
+
/**
|
|
51
|
+
* Round a set of shares to whole percentages that still add up.
|
|
52
|
+
*
|
|
53
|
+
* Only when the shares CAN add up: in a multi-choice poll one person may pick
|
|
54
|
+
* three things, so the sum is meaningfully over 100 and forcing it down would be
|
|
55
|
+
* a lie of a different kind. The correction is applied only when the raw total is
|
|
56
|
+
* within a point of 100.
|
|
57
|
+
*/
|
|
58
|
+
export declare function junLargestRemainder(counts: number[], total: number): number[];
|
|
59
|
+
/** What this voter picked, or an empty list. */
|
|
60
|
+
export declare function junMyBallot(ballots: Record<string, number[]>, voter: string | null): number[];
|
|
61
|
+
/**
|
|
62
|
+
* The ballot to store after somebody picks `choice`.
|
|
63
|
+
*
|
|
64
|
+
* Three behaviours in one function, because they are one decision:
|
|
65
|
+
*
|
|
66
|
+
* - single choice → replaces whatever was there;
|
|
67
|
+
* - multiple choice → toggles that one option;
|
|
68
|
+
* - no re-voting → the existing ballot stands, and the caller says so.
|
|
69
|
+
*
|
|
70
|
+
* Returns `null` when the vote must be REFUSED, which the server turns into an
|
|
71
|
+
* error rather than a silent no-op: a button that appears to work and changes
|
|
72
|
+
* nothing is worse than one that says why it will not.
|
|
73
|
+
*/
|
|
74
|
+
export declare function junNextBallot(existing: number[], choice: number, options: {
|
|
75
|
+
multiple?: boolean;
|
|
76
|
+
revote?: boolean;
|
|
77
|
+
}): number[] | null;
|
|
78
|
+
/** Keep the stored map bounded, dropping the oldest keys first. */
|
|
79
|
+
export declare function junCapBallots(ballots: Record<string, number[]>, keep?: number): Record<string, number[]>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export const JUN_POLL_VOTERS_MAX = 5e3;
|
|
2
|
+
export const JUN_POLL_CHOICES_MAX = 12;
|
|
3
|
+
export const JUN_POLL_CHOICE_LENGTH = 80;
|
|
4
|
+
export function junPollChoices(raw) {
|
|
5
|
+
if (!Array.isArray(raw)) return [];
|
|
6
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7
|
+
const out = [];
|
|
8
|
+
for (const entry of raw) {
|
|
9
|
+
if (typeof entry !== "string") continue;
|
|
10
|
+
const value = entry.replace(/\s+/g, " ").trim().slice(0, JUN_POLL_CHOICE_LENGTH);
|
|
11
|
+
const key = value.toLowerCase();
|
|
12
|
+
if (!value || seen.has(key)) continue;
|
|
13
|
+
seen.add(key);
|
|
14
|
+
out.push(value);
|
|
15
|
+
if (out.length >= JUN_POLL_CHOICES_MAX) break;
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
export function junPollBallots(raw, choiceCount) {
|
|
20
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
21
|
+
const out = {};
|
|
22
|
+
for (const [voter, value] of Object.entries(raw)) {
|
|
23
|
+
if (!voter) continue;
|
|
24
|
+
const list = Array.isArray(value) ? value : [value];
|
|
25
|
+
const choices = [];
|
|
26
|
+
for (const pick of list) {
|
|
27
|
+
const n = typeof pick === "number" ? pick : Number(pick);
|
|
28
|
+
if (!Number.isInteger(n) || n < 0 || n >= choiceCount) continue;
|
|
29
|
+
if (!choices.includes(n)) choices.push(n);
|
|
30
|
+
}
|
|
31
|
+
if (choices.length) out[voter] = choices;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
export function junTallyVotes(ballots, choiceCount) {
|
|
36
|
+
const counts = Array.from({ length: Math.max(0, choiceCount) }, () => 0);
|
|
37
|
+
let voters = 0;
|
|
38
|
+
for (const choices of Object.values(ballots)) {
|
|
39
|
+
if (!choices.length) continue;
|
|
40
|
+
voters++;
|
|
41
|
+
for (const choice of choices) {
|
|
42
|
+
if (choice >= 0 && choice < counts.length) counts[choice] = (counts[choice] ?? 0) + 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const percentages = junLargestRemainder(counts, voters);
|
|
46
|
+
return { counts, percentages, voters, leader: counts.reduce((a, b) => Math.max(a, b), 0) };
|
|
47
|
+
}
|
|
48
|
+
export function junLargestRemainder(counts, total) {
|
|
49
|
+
if (!total) return counts.map(() => 0);
|
|
50
|
+
const exact = counts.map((c) => c / total * 100);
|
|
51
|
+
const floors = exact.map(Math.floor);
|
|
52
|
+
const sum = floors.reduce((a, b) => a + b, 0);
|
|
53
|
+
const rawTotal = exact.reduce((a, b) => a + b, 0);
|
|
54
|
+
if (rawTotal > 101) return exact.map(Math.round);
|
|
55
|
+
let remaining = 100 - sum;
|
|
56
|
+
const order = exact.map((value, index) => ({ index, remainder: value - Math.floor(value) })).sort((a, b) => b.remainder - a.remainder || a.index - b.index);
|
|
57
|
+
const out = [...floors];
|
|
58
|
+
for (const { index } of order) {
|
|
59
|
+
if (remaining <= 0) break;
|
|
60
|
+
out[index] = (out[index] ?? 0) + 1;
|
|
61
|
+
remaining--;
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
export function junMyBallot(ballots, voter) {
|
|
66
|
+
if (!voter) return [];
|
|
67
|
+
return ballots[voter] ?? [];
|
|
68
|
+
}
|
|
69
|
+
export function junNextBallot(existing, choice, options) {
|
|
70
|
+
const had = existing.length > 0;
|
|
71
|
+
if (had && options.revote === false) return null;
|
|
72
|
+
if (!options.multiple) return [choice];
|
|
73
|
+
const next = existing.includes(choice) ? existing.filter((c) => c !== choice) : [...existing, choice].sort((a, b) => a - b);
|
|
74
|
+
return next;
|
|
75
|
+
}
|
|
76
|
+
export function junCapBallots(ballots, keep = JUN_POLL_VOTERS_MAX) {
|
|
77
|
+
const keys = Object.keys(ballots);
|
|
78
|
+
if (keys.length <= keep) return ballots;
|
|
79
|
+
const out = {};
|
|
80
|
+
for (const key of keys.slice(keys.length - keep)) out[key] = ballots[key];
|
|
81
|
+
return out;
|
|
82
|
+
}
|