@jant/core 1.0.1 → 1.2.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/bin/lib/site-snapshot.js +10 -0
- package/dist/{app-Gt7_skt6.js → app-CbOZ2Irh.js} +8704 -5180
- package/dist/client/.vite/manifest.json +125 -85
- package/dist/client/_assets/chunks/{confirm-D7GrwsCN.js → confirm-CMe01lne.js} +1 -1
- package/dist/client/_assets/chunks/{create-editor-5Y49x7h5.js → create-editor-hWapNE40.js} +26 -26
- package/dist/client/_assets/chunks/footnote-rail-9zwl6jtV.js +2 -0
- package/dist/client/_assets/chunks/{jant-locale-picker-DL6mIOT5.js → jant-locale-picker-2L4rkDaz.js} +1 -1
- package/dist/client/_assets/chunks/lit-Bw_voPoW.js +2 -0
- package/dist/client/_assets/chunks/preload-helper-Czpn1I53.js +1 -0
- package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +1 -0
- package/dist/client/_assets/chunks/{settings-paths-h6RjIe3C.js → settings-paths-BBVT8zKj.js} +1 -1
- package/dist/client/_assets/chunks/slug-format-BuCPjSrB.js +1 -0
- package/dist/client/_assets/chunks/sortable-list-DJXwkaOv.js +2 -0
- package/dist/client/_assets/chunks/types-DrYFqJH2.js +1 -0
- package/dist/client/_assets/chunks/{unsafe-html-B5ZEXaxg.js → unsafe-html-CWos3v6N.js} +1 -1
- package/dist/client/_assets/chunks/unsafe-svg-CUrgo4Xg.js +1 -0
- package/dist/client/_assets/client-BO8GOFfT.js +354 -0
- package/dist/client/_assets/client-D8Rrsd73.css +2 -0
- package/dist/client/_assets/client-auth-CsUGM718.js +859 -0
- package/dist/client/_assets/client-author-QPm1whbO.css +2 -0
- package/dist/client/_assets/client-compose-BB4U7Wz0.js +2004 -0
- package/dist/client/_assets/{client-manage-C1eDB1Rc.js → client-manage-CI9-eh-8.js} +176 -176
- package/dist/client/_assets/{client-settings-DIM44Zqh.js → client-settings-BnGPuqwc.js} +166 -166
- package/dist/client/_assets/client-share-0DICJjAc.css +1 -0
- package/dist/client/_assets/client-share-C59mOLJ1.js +149 -0
- package/dist/index.js +1 -1
- package/dist/node.js +3 -2
- package/package.json +2 -1
- package/src/app.tsx +9 -0
- package/src/client/components/compose-types.ts +1 -0
- package/src/client/components/jant-compose-dialog.ts +1 -0
- package/src/client/components/jant-compose-editor.ts +30 -0
- package/src/client/components/jant-compose-fullscreen.ts +1 -0
- package/src/client/components/jant-post-menu.ts +80 -13
- package/src/client/components/jant-share-dialog.ts +422 -0
- package/src/client/components/jant-share-menu.ts +188 -0
- package/src/client/compose-bridge.ts +61 -1
- package/src/client/feed-video-player.ts +6 -0
- package/src/client/lazy-entries.ts +21 -1
- package/src/client/post-menu-shared.ts +100 -0
- package/src/client/share-capture.ts +443 -0
- package/src/client/share-launch.ts +133 -0
- package/src/client/tiptap/bubble-menu.ts +25 -2
- package/src/client/tiptap/create-editor.ts +2 -0
- package/src/client/tiptap/extensions.ts +4 -0
- package/src/client/video-processor.ts +106 -52
- package/src/client/view-confirm.ts +108 -0
- package/src/client-share.ts +8 -0
- package/src/client.ts +2 -0
- package/src/db/migrations/0035_brainy_next_avengers.sql +9 -0
- package/src/db/migrations/0036_gorgeous_smasher.sql +7 -0
- package/src/db/migrations/meta/0035_snapshot.json +2877 -0
- package/src/db/migrations/meta/0036_snapshot.json +2924 -0
- package/src/db/migrations/meta/_journal.json +14 -0
- package/src/db/migrations/pg/0033_cute_magdalene.sql +10 -0
- package/src/db/migrations/pg/0034_material_agent_brand.sql +8 -0
- package/src/db/migrations/pg/meta/0033_snapshot.json +3719 -0
- package/src/db/migrations/pg/meta/0034_snapshot.json +3766 -0
- package/src/db/migrations/pg/meta/_journal.json +14 -0
- package/src/db/pg/schema.ts +40 -0
- package/src/db/schema.ts +61 -0
- package/src/i18n/locales/public/en.po +5 -0
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +5 -0
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +5 -0
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +149 -0
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +149 -0
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +149 -0
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/lib/discover.ts +31 -0
- package/src/lib/env.ts +20 -0
- package/src/lib/github-app-state.ts +1 -1
- package/src/lib/github-app.ts +183 -1
- package/src/lib/markdown-manager.ts +129 -1
- package/src/lib/post-meta.ts +13 -3
- package/src/lib/referrer-aliases.ts +311 -0
- package/src/lib/render.tsx +10 -0
- package/src/lib/resolve-config.ts +14 -0
- package/src/lib/share-card.ts +653 -0
- package/src/lib/summary.ts +152 -54
- package/src/lib/tiptap-render.ts +1 -0
- package/src/lib/upload.ts +21 -1
- package/src/lib/version.ts +2 -0
- package/src/lib/video-playback.ts +55 -0
- package/src/lib/view-buffer.ts +201 -0
- package/src/lib/view-counting.ts +539 -0
- package/src/lib/view-token.ts +177 -0
- package/src/lib/view.ts +13 -1
- package/src/middleware/view-counter.ts +140 -0
- package/src/node/runtime.ts +4 -0
- package/src/preset.css +31 -14
- package/src/routes/api/media.ts +21 -3
- package/src/routes/auth/setup.tsx +37 -1
- package/src/routes/dash/settings.tsx +433 -168
- package/src/routes/pages/archive.tsx +1 -0
- package/src/routes/pages/collection.tsx +6 -0
- package/src/routes/pages/collections.tsx +1 -0
- package/src/routes/pages/featured.tsx +1 -0
- package/src/routes/pages/home.tsx +1 -0
- package/src/routes/pages/page.tsx +3 -0
- package/src/routes/pages/partials.tsx +23 -0
- package/src/routes/pages/smart-collection.tsx +2 -0
- package/src/routes/pages/subscribe.tsx +1 -0
- package/src/routes/view-confirm.ts +63 -0
- package/src/services/export-theme/assets/client-site.js +1 -1
- package/src/services/export-theme/styles/main.css +39 -21
- package/src/services/export.ts +2 -0
- package/src/services/index.ts +17 -0
- package/src/services/mcp.ts +31 -1
- package/src/services/media.ts +63 -0
- package/src/services/stats.ts +1130 -0
- package/src/style-share.css +16 -0
- package/src/styles/components-author.css +177 -0
- package/src/styles/components.css +25 -3
- package/src/styles/share.css +1103 -0
- package/src/styles/tokens.css +65 -30
- package/src/styles/ui.css +62 -13
- package/src/types/app-context.ts +9 -0
- package/src/types/bindings.ts +5 -0
- package/src/types/config.ts +54 -0
- package/src/types/views.ts +6 -0
- package/src/ui/compose/ComposeDialog.tsx +6 -0
- package/src/ui/dash/settings/SettingsRootContent.tsx +24 -6
- package/src/ui/dash/settings/StatsContent.tsx +855 -0
- package/src/ui/font-themes.ts +39 -6
- package/src/ui/layouts/BaseLayout.tsx +11 -2
- package/src/ui/layouts/SiteLayout.tsx +9 -3
- package/src/ui/share/ShareCard.tsx +298 -0
- package/src/ui/shared/Icon.tsx +23 -3
- package/src/ui/shared/MediaGallery.tsx +31 -4
- package/src/ui/shared/PostFooter.tsx +20 -4
- package/src/ui/shared/icon-collector.ts +28 -0
- package/src/ui/shared/post-article-attributes.ts +3 -0
- package/dist/client/_assets/chunks/footnote-rail-BJwswtVQ.js +0 -1
- package/dist/client/_assets/chunks/lit-DW8VmJAT.js +0 -2
- package/dist/client/_assets/chunks/slug-format-Dsi0e9Xn.js +0 -1
- package/dist/client/_assets/chunks/sortable-list-DWNKv782.js +0 -2
- package/dist/client/_assets/chunks/types-D5iF3H1a.js +0 -1
- package/dist/client/_assets/chunks/unsafe-svg-DTZZEvLU.js +0 -2
- package/dist/client/_assets/client-BaqmpPQ-.css +0 -2
- package/dist/client/_assets/client-C6melOtG.js +0 -296
- package/dist/client/_assets/client-auth-Ccq8kSqq.js +0 -828
- package/dist/client/_assets/client-author-CGVvrNZ8.css +0 -2
- package/dist/client/_assets/client-compose-oxzPb3SS.js +0 -2004
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opens the "Share as image" dialog from a post menu, the author's or a
|
|
3
|
+
* reader's.
|
|
4
|
+
*
|
|
5
|
+
* The dialog and snapdom ship in their own bundle, and their styles in their
|
|
6
|
+
* own stylesheet. The menu starts loading both when it opens; picking the
|
|
7
|
+
* item asks the server for the card at the same time as it waits for them,
|
|
8
|
+
* and only then talks to the element.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { JantShareDialog } from "./components/jant-share-dialog.js";
|
|
12
|
+
import { ensureShare } from "./lazy-entries.js";
|
|
13
|
+
import { publicPath } from "./runtime-paths.js";
|
|
14
|
+
import { showToast } from "./toast.js";
|
|
15
|
+
|
|
16
|
+
async function fetchShareCard(postId: string): Promise<string> {
|
|
17
|
+
const response = await fetch(
|
|
18
|
+
publicPath(`/_/share-card/${encodeURIComponent(postId)}`),
|
|
19
|
+
);
|
|
20
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
21
|
+
return response.text();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let styles: Promise<void> | undefined;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Link the share stylesheet, which `<html data-share-stylesheet>` names, and
|
|
28
|
+
* resolve once it has loaded. A load that fails is forgotten, so the next
|
|
29
|
+
* call links it again.
|
|
30
|
+
*/
|
|
31
|
+
function ensureShareStyles(): Promise<void> {
|
|
32
|
+
return (styles ??= new Promise<void>((resolve, reject) => {
|
|
33
|
+
const href = document.documentElement.dataset.shareStylesheet;
|
|
34
|
+
if (!href) {
|
|
35
|
+
resolve();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const link = document.createElement("link");
|
|
39
|
+
link.rel = "stylesheet";
|
|
40
|
+
link.href = href;
|
|
41
|
+
link.addEventListener("load", () => resolve(), { once: true });
|
|
42
|
+
link.addEventListener(
|
|
43
|
+
"error",
|
|
44
|
+
() => {
|
|
45
|
+
link.remove();
|
|
46
|
+
styles = undefined;
|
|
47
|
+
reject(new Error(`Could not load ${href}`));
|
|
48
|
+
},
|
|
49
|
+
{ once: true },
|
|
50
|
+
);
|
|
51
|
+
document.head.appendChild(link);
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Wait for the bundle and the stylesheet, and return what failed. */
|
|
56
|
+
async function settleShareLoads(): Promise<unknown[]> {
|
|
57
|
+
const results = await Promise.allSettled([
|
|
58
|
+
ensureShare(),
|
|
59
|
+
ensureShareStyles(),
|
|
60
|
+
]);
|
|
61
|
+
return results.flatMap((result) =>
|
|
62
|
+
result.status === "rejected" ? [result.reason] : [],
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Load the share bundle and its styles, trying once more what fails: a
|
|
68
|
+
* dropped request is the usual cause, and both loads forget a failure. Both
|
|
69
|
+
* settle before the retry, so neither is still on its first try.
|
|
70
|
+
*
|
|
71
|
+
* @returns Whether both loaded
|
|
72
|
+
*/
|
|
73
|
+
async function loadShare(): Promise<boolean> {
|
|
74
|
+
let failures = await settleShareLoads();
|
|
75
|
+
if (failures.length > 0) {
|
|
76
|
+
// eslint-disable-next-line no-console -- the toast names no cause; the console keeps it
|
|
77
|
+
console.warn("[jant] share: loading failed, trying again", ...failures);
|
|
78
|
+
failures = await settleShareLoads();
|
|
79
|
+
}
|
|
80
|
+
if (failures.length > 0) {
|
|
81
|
+
// eslint-disable-next-line no-console -- the toast names no cause; the console keeps it
|
|
82
|
+
console.error("[jant] share: could not load", ...failures);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Start loading the share bundle and its styles, so the dialog opens without
|
|
90
|
+
* waiting for them. Out of the way of the menu's first frame; a failure is
|
|
91
|
+
* left for {@link openShareImage} to retry and report.
|
|
92
|
+
*/
|
|
93
|
+
export function warmShareImage(): void {
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
ensureShare().catch(() => {});
|
|
96
|
+
ensureShareStyles().catch(() => {});
|
|
97
|
+
}, 0);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Show the share dialog for a post.
|
|
102
|
+
*
|
|
103
|
+
* @param postId - TypeID of the post to share
|
|
104
|
+
* @param returnFocus - Element to focus again when the dialog closes
|
|
105
|
+
*/
|
|
106
|
+
export async function openShareImage(
|
|
107
|
+
postId: string,
|
|
108
|
+
returnFocus?: HTMLElement | null,
|
|
109
|
+
): Promise<void> {
|
|
110
|
+
// The first card is asked for now, alongside the bundle; "Try again" in
|
|
111
|
+
// the dialog asks again.
|
|
112
|
+
let first: Promise<string> | null = fetchShareCard(postId);
|
|
113
|
+
first.catch(() => {});
|
|
114
|
+
const loadCard = () => {
|
|
115
|
+
const card = first ?? fetchShareCard(postId);
|
|
116
|
+
first = null;
|
|
117
|
+
return card;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
if (!(await loadShare())) {
|
|
121
|
+
showToast(
|
|
122
|
+
"Could not open sharing. Check your connection and try again.",
|
|
123
|
+
"error",
|
|
124
|
+
);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
let dialog = document.querySelector<JantShareDialog>("jant-share-dialog");
|
|
128
|
+
if (!dialog) {
|
|
129
|
+
dialog = document.createElement("jant-share-dialog") as JantShareDialog;
|
|
130
|
+
document.body.appendChild(dialog);
|
|
131
|
+
}
|
|
132
|
+
await dialog.open(loadCard, returnFocus ?? null);
|
|
133
|
+
}
|
|
@@ -31,6 +31,7 @@ const bubbleMenuKey = new PluginKey("bubbleMenu");
|
|
|
31
31
|
// SVG icons (16×16, stroke-based)
|
|
32
32
|
const ICONS = {
|
|
33
33
|
bold: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 12h9a4 4 0 0 1 0 8H6V4h8a4 4 0 0 1 0 8"/></svg>`,
|
|
34
|
+
highlight: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 11 8-8 4 4-8 8-4-4Z"/><path d="m9 11-3 3 4 4 3-3M6 14l-3 7 7-3M3 21h7"/></svg>`,
|
|
34
35
|
italic: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>`,
|
|
35
36
|
h1: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17 12l3-2v10"/></svg>`,
|
|
36
37
|
h2: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"/></svg>`,
|
|
@@ -169,6 +170,7 @@ export function clearFormatting(editor: Editor): void {
|
|
|
169
170
|
function getButtons(
|
|
170
171
|
editor: Editor,
|
|
171
172
|
toolbarMode: FormattingToolbarMode,
|
|
173
|
+
highlightLabel: string,
|
|
172
174
|
): BubbleBtn[] {
|
|
173
175
|
if (toolbarMode === "compose") {
|
|
174
176
|
return [
|
|
@@ -186,6 +188,13 @@ function getButtons(
|
|
|
186
188
|
action: () => toggleMarkAndExit(editor, "italic"),
|
|
187
189
|
isActive: () => editor.isActive("italic"),
|
|
188
190
|
},
|
|
191
|
+
{
|
|
192
|
+
key: "highlight",
|
|
193
|
+
icon: ICONS.highlight,
|
|
194
|
+
title: highlightLabel,
|
|
195
|
+
action: () => toggleMarkAndExit(editor, "highlight"),
|
|
196
|
+
isActive: () => editor.isActive("highlight"),
|
|
197
|
+
},
|
|
189
198
|
{
|
|
190
199
|
key: "sep",
|
|
191
200
|
icon: "",
|
|
@@ -231,6 +240,13 @@ function getButtons(
|
|
|
231
240
|
action: () => toggleMarkAndExit(editor, "italic"),
|
|
232
241
|
isActive: () => editor.isActive("italic"),
|
|
233
242
|
},
|
|
243
|
+
{
|
|
244
|
+
key: "highlight",
|
|
245
|
+
icon: ICONS.highlight,
|
|
246
|
+
title: highlightLabel,
|
|
247
|
+
action: () => toggleMarkAndExit(editor, "highlight"),
|
|
248
|
+
isActive: () => editor.isActive("highlight"),
|
|
249
|
+
},
|
|
234
250
|
{
|
|
235
251
|
key: "h1",
|
|
236
252
|
icon: ICONS.h1,
|
|
@@ -281,12 +297,14 @@ export const BubbleMenu = Extension.create({
|
|
|
281
297
|
addOptions() {
|
|
282
298
|
return {
|
|
283
299
|
toolbarMode: "default" as FormattingToolbarMode,
|
|
300
|
+
highlightLabel: "Highlight",
|
|
284
301
|
};
|
|
285
302
|
},
|
|
286
303
|
|
|
287
304
|
addProseMirrorPlugins() {
|
|
288
305
|
const editor = this.editor;
|
|
289
306
|
const toolbarMode = this.options.toolbarMode as FormattingToolbarMode;
|
|
307
|
+
const highlightLabel = this.options.highlightLabel;
|
|
290
308
|
let el: HTMLElement | null = null;
|
|
291
309
|
let buttons: BubbleBtn[] = [];
|
|
292
310
|
const btnEls: Map<string, HTMLButtonElement> = new Map();
|
|
@@ -298,7 +316,7 @@ export const BubbleMenu = Extension.create({
|
|
|
298
316
|
el.style.position = "fixed";
|
|
299
317
|
el.style.display = "none";
|
|
300
318
|
|
|
301
|
-
buttons = getButtons(editor, toolbarMode);
|
|
319
|
+
buttons = getButtons(editor, toolbarMode, highlightLabel);
|
|
302
320
|
for (const btn of buttons) {
|
|
303
321
|
if (btn.key === "sep") {
|
|
304
322
|
const sep = document.createElement("span");
|
|
@@ -310,6 +328,7 @@ export const BubbleMenu = Extension.create({
|
|
|
310
328
|
b.type = "button";
|
|
311
329
|
b.innerHTML = btn.icon;
|
|
312
330
|
b.title = btn.title;
|
|
331
|
+
b.setAttribute("aria-label", btn.title);
|
|
313
332
|
b.className = "tiptap-bubble-btn";
|
|
314
333
|
b.addEventListener("mousedown", (e) => {
|
|
315
334
|
e.preventDefault();
|
|
@@ -372,7 +391,11 @@ export const BubbleMenu = Extension.create({
|
|
|
372
391
|
for (const btn of buttons) {
|
|
373
392
|
if (btn.key === "sep") continue;
|
|
374
393
|
const b = btnEls.get(btn.key);
|
|
375
|
-
if (b)
|
|
394
|
+
if (b) {
|
|
395
|
+
const active = btn.isActive(editor.view);
|
|
396
|
+
b.classList.toggle("is-active", active);
|
|
397
|
+
b.setAttribute("aria-pressed", String(active));
|
|
398
|
+
}
|
|
376
399
|
}
|
|
377
400
|
}
|
|
378
401
|
|
|
@@ -27,6 +27,7 @@ export interface CreateEditorOptions {
|
|
|
27
27
|
onBlur?: () => void;
|
|
28
28
|
onSelectionUpdate?: (selection: { from: number; to: number }) => void;
|
|
29
29
|
toolbarMode?: FormattingToolbarMode;
|
|
30
|
+
highlightLabel?: string;
|
|
30
31
|
pasteMedia?: PasteMediaOptions;
|
|
31
32
|
rehostImages?: RehostImagesOptions;
|
|
32
33
|
imageNodeLabels?: Partial<ImageNodeLabels>;
|
|
@@ -45,6 +46,7 @@ export function createTiptapEditor(options: CreateEditorOptions): Editor {
|
|
|
45
46
|
extensions: createEditorExtensions({
|
|
46
47
|
placeholder: options.placeholder,
|
|
47
48
|
toolbarMode: options.toolbarMode,
|
|
49
|
+
highlightLabel: options.highlightLabel,
|
|
48
50
|
pasteMedia: options.pasteMedia,
|
|
49
51
|
rehostImages: options.rehostImages,
|
|
50
52
|
imageNodeLabels: options.imageNodeLabels,
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
export interface EditorExtensionOptions {
|
|
39
39
|
placeholder?: string;
|
|
40
40
|
toolbarMode?: FormattingToolbarMode;
|
|
41
|
+
highlightLabel?: string;
|
|
41
42
|
pasteMedia?: PasteMediaOptions;
|
|
42
43
|
rehostImages?: RehostImagesOptions;
|
|
43
44
|
imageNodeLabels?: Partial<ImageNodeLabels>;
|
|
@@ -129,6 +130,9 @@ export function createEditorExtensions(
|
|
|
129
130
|
RehostImages.configure(options.rehostImages ?? {}),
|
|
130
131
|
BubbleMenu.configure({
|
|
131
132
|
toolbarMode: options.toolbarMode ?? "default",
|
|
133
|
+
...(options.highlightLabel
|
|
134
|
+
? { highlightLabel: options.highlightLabel }
|
|
135
|
+
: {}),
|
|
132
136
|
}),
|
|
133
137
|
LinkToolbar,
|
|
134
138
|
InsertParagraphAround,
|
|
@@ -12,15 +12,19 @@
|
|
|
12
12
|
* browser to double-rotate)
|
|
13
13
|
* - Clears the alternate_group track flag (mediabunny sets it non-zero,
|
|
14
14
|
* which stops Safari's native video controls from auto-hiding)
|
|
15
|
-
* - Extracts poster frame + blurhash during processing
|
|
15
|
+
* - Extracts poster frame + blurhash during processing, and makes a poster
|
|
16
|
+
* for a clip already uploaded without one
|
|
16
17
|
*
|
|
17
18
|
* Requires WebCodecs API support — check `isSupported()` before use.
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
|
-
import type { VideoCodec } from "mediabunny";
|
|
21
|
+
import type { InputVideoTrack, VideoCodec } from "mediabunny";
|
|
21
22
|
import { loadMediabunny } from "./mediabunny.js";
|
|
22
23
|
import { encode } from "blurhash";
|
|
23
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
getPosterFrameSeconds,
|
|
26
|
+
normalizeDurationSeconds,
|
|
27
|
+
} from "../lib/video-playback.js";
|
|
24
28
|
import { zeroTrackAlternateGroups } from "../lib/mp4-track-flags.js";
|
|
25
29
|
|
|
26
30
|
/** Maximum pixels for the long edge of the output video. */
|
|
@@ -169,9 +173,66 @@ function drawFrame(
|
|
|
169
173
|
return { canvas, ctx };
|
|
170
174
|
}
|
|
171
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Capture a clip's poster frame and blurhash from its video track. The frame
|
|
178
|
+
* is the one `getPosterFrameSeconds` names, the same one a reader's browser
|
|
179
|
+
* draws for a clip stored without a poster.
|
|
180
|
+
*
|
|
181
|
+
* @param videoTrack - The clip's primary video track
|
|
182
|
+
* @param duration - Clip length in seconds, when known
|
|
183
|
+
* @returns Poster blob (640px-wide WebP) and blurhash, each when it could be made
|
|
184
|
+
*/
|
|
185
|
+
async function captureStill(
|
|
186
|
+
videoTrack: InputVideoTrack,
|
|
187
|
+
duration: number | undefined,
|
|
188
|
+
): Promise<{ poster?: Blob; blurhash?: string }> {
|
|
189
|
+
const { CanvasSink } = await loadMediabunny();
|
|
190
|
+
const wrapped = await optional("capture frame", () =>
|
|
191
|
+
new CanvasSink(videoTrack).getCanvas(getPosterFrameSeconds(duration)),
|
|
192
|
+
);
|
|
193
|
+
if (!wrapped) return {};
|
|
194
|
+
|
|
195
|
+
const canvas = wrapped.canvas as HTMLCanvasElement;
|
|
196
|
+
const srcW = canvas.width;
|
|
197
|
+
const srcH = canvas.height;
|
|
198
|
+
|
|
199
|
+
// Poster: 640px wide WebP
|
|
200
|
+
const posterScale = Math.min(POSTER_WIDTH / srcW, 1);
|
|
201
|
+
const posterFrame = drawFrame(
|
|
202
|
+
canvas,
|
|
203
|
+
Math.round(srcW * posterScale),
|
|
204
|
+
Math.round(srcH * posterScale),
|
|
205
|
+
);
|
|
206
|
+
const poster = posterFrame
|
|
207
|
+
? await optional(
|
|
208
|
+
"encode poster",
|
|
209
|
+
() =>
|
|
210
|
+
new Promise<Blob | undefined>((resolve) => {
|
|
211
|
+
posterFrame.canvas.toBlob(
|
|
212
|
+
(blob) => resolve(blob ?? undefined),
|
|
213
|
+
"image/webp",
|
|
214
|
+
0.8,
|
|
215
|
+
);
|
|
216
|
+
}),
|
|
217
|
+
)
|
|
218
|
+
: undefined;
|
|
219
|
+
|
|
220
|
+
// Blurhash: 32px canvas, 4×3 components
|
|
221
|
+
const bhScale = Math.min(BLURHASH_SIZE / srcW, BLURHASH_SIZE / srcH, 1);
|
|
222
|
+
const bw = Math.max(Math.round(srcW * bhScale), 1);
|
|
223
|
+
const bh = Math.max(Math.round(srcH * bhScale), 1);
|
|
224
|
+
const bhFrame = drawFrame(canvas, bw, bh);
|
|
225
|
+
const blurhash = bhFrame
|
|
226
|
+
? await optional("encode blurhash", async () =>
|
|
227
|
+
encode(bhFrame.ctx.getImageData(0, 0, bw, bh).data, bw, bh, 4, 3),
|
|
228
|
+
)
|
|
229
|
+
: undefined;
|
|
230
|
+
|
|
231
|
+
return { poster, blurhash };
|
|
232
|
+
}
|
|
233
|
+
|
|
172
234
|
/**
|
|
173
235
|
* Probe a video file and extract its poster frame and blurhash in one pass.
|
|
174
|
-
* Seeks to `min(duration × 0.1, 1s)` and captures the frame.
|
|
175
236
|
*
|
|
176
237
|
* Returns the source dimensions, codec, and bitrate alongside, so the caller
|
|
177
238
|
* can decide whether a re-encode is needed at all — and at what bitrate —
|
|
@@ -186,7 +247,7 @@ function drawFrame(
|
|
|
186
247
|
* @returns Poster blob (640px-wide WebP), blurhash, dimensions, codec, bitrate
|
|
187
248
|
*/
|
|
188
249
|
async function probeSource(file: File): Promise<SourceProbe> {
|
|
189
|
-
const { Input, BlobSource, ALL_FORMATS
|
|
250
|
+
const { Input, BlobSource, ALL_FORMATS } = await loadMediabunny();
|
|
190
251
|
const input = new Input({
|
|
191
252
|
source: new BlobSource(file),
|
|
192
253
|
formats: ALL_FORMATS,
|
|
@@ -212,8 +273,7 @@ async function probeSource(file: File): Promise<SourceProbe> {
|
|
|
212
273
|
input.computeDuration(),
|
|
213
274
|
);
|
|
214
275
|
|
|
215
|
-
|
|
216
|
-
const base: SourceProbe = {
|
|
276
|
+
return {
|
|
217
277
|
sourceWidth: videoTrack.displayWidth,
|
|
218
278
|
sourceHeight: videoTrack.displayHeight,
|
|
219
279
|
rotation: videoTrack.rotation,
|
|
@@ -221,54 +281,44 @@ async function probeSource(file: File): Promise<SourceProbe> {
|
|
|
221
281
|
duration === undefined ? undefined : normalizeDurationSeconds(duration),
|
|
222
282
|
videoCodec,
|
|
223
283
|
videoBitrate,
|
|
284
|
+
...(await captureStill(videoTrack, duration)),
|
|
224
285
|
};
|
|
286
|
+
} finally {
|
|
287
|
+
input.dispose();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
225
290
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Make a poster for a clip that is already uploaded, reading the file where
|
|
293
|
+
* it is stored. mediabunny fetches it in byte ranges, so only the metadata
|
|
294
|
+
* and the samples up to the poster frame cross the network, not the clip.
|
|
295
|
+
*
|
|
296
|
+
* @param url - The stored clip's address; its host has to allow this origin
|
|
297
|
+
* @returns Poster blob (640px-wide WebP), or `undefined` when the browser
|
|
298
|
+
* cannot decode video or the file could not be read
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* const poster = await VideoProcessor.extractPosterFromUrl(media.url);
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
async function extractPosterFromUrl(url: string): Promise<Blob | undefined> {
|
|
305
|
+
if (typeof VideoDecoder === "undefined") return undefined;
|
|
306
|
+
|
|
307
|
+
const { Input, UrlSource, ALL_FORMATS } = await loadMediabunny();
|
|
308
|
+
const input = new Input({
|
|
309
|
+
source: new UrlSource(url),
|
|
310
|
+
formats: ALL_FORMATS,
|
|
311
|
+
});
|
|
312
|
+
try {
|
|
313
|
+
const videoTrack = await optional("open video track", () =>
|
|
314
|
+
input.getPrimaryVideoTrack(),
|
|
245
315
|
);
|
|
246
|
-
|
|
247
|
-
? await optional(
|
|
248
|
-
"encode poster",
|
|
249
|
-
() =>
|
|
250
|
-
new Promise<Blob | undefined>((resolve) => {
|
|
251
|
-
posterFrame.canvas.toBlob(
|
|
252
|
-
(blob) => resolve(blob ?? undefined),
|
|
253
|
-
"image/webp",
|
|
254
|
-
0.8,
|
|
255
|
-
);
|
|
256
|
-
}),
|
|
257
|
-
)
|
|
258
|
-
: undefined;
|
|
259
|
-
|
|
260
|
-
// Blurhash: 32px canvas, 4×3 components
|
|
261
|
-
const bhScale = Math.min(BLURHASH_SIZE / srcW, BLURHASH_SIZE / srcH, 1);
|
|
262
|
-
const bw = Math.max(Math.round(srcW * bhScale), 1);
|
|
263
|
-
const bh = Math.max(Math.round(srcH * bhScale), 1);
|
|
264
|
-
const bhFrame = drawFrame(canvas, bw, bh);
|
|
265
|
-
const blurhash = bhFrame
|
|
266
|
-
? await optional("encode blurhash", async () =>
|
|
267
|
-
encode(bhFrame.ctx.getImageData(0, 0, bw, bh).data, bw, bh, 4, 3),
|
|
268
|
-
)
|
|
269
|
-
: undefined;
|
|
316
|
+
if (!videoTrack) return undefined;
|
|
270
317
|
|
|
271
|
-
|
|
318
|
+
const duration = await optional("compute duration", () =>
|
|
319
|
+
input.computeDuration(),
|
|
320
|
+
);
|
|
321
|
+
return (await captureStill(videoTrack, duration)).poster;
|
|
272
322
|
} finally {
|
|
273
323
|
input.dispose();
|
|
274
324
|
}
|
|
@@ -614,4 +664,8 @@ function probeVideoDimensions(
|
|
|
614
664
|
});
|
|
615
665
|
}
|
|
616
666
|
|
|
617
|
-
export const VideoProcessor = {
|
|
667
|
+
export const VideoProcessor = {
|
|
668
|
+
isSupported,
|
|
669
|
+
processToFile,
|
|
670
|
+
extractPosterFromUrl,
|
|
671
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tells the site that this page was seen.
|
|
3
|
+
*
|
|
4
|
+
* The server embeds a signed token in a page it would count as a view
|
|
5
|
+
* (`<meta name="jant-view">`, see `lib/view-token.ts`). It counts the view
|
|
6
|
+
* only once this script posts the token back, which it does once the page
|
|
7
|
+
* has been in front of the reader for five seconds in total, or sooner, on
|
|
8
|
+
* the first scroll, tap, key or pointer movement. A crawler that runs a real
|
|
9
|
+
* browser closes the page long before either, and an automated browser that
|
|
10
|
+
* admits to it (`navigator.webdriver`) is not asked at all.
|
|
11
|
+
*
|
|
12
|
+
* The token names the page and where the reader came from, decided on the
|
|
13
|
+
* server from the request; nothing about the reader is read here or sent.
|
|
14
|
+
* No cookie, no storage, one request, and nothing waits for its answer.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { publicPath } from "./runtime-paths.js";
|
|
18
|
+
|
|
19
|
+
/** Visible time after which a page counts as seen, without any interaction. */
|
|
20
|
+
export const VIEW_CONFIRM_DWELL_MS = 5_000;
|
|
21
|
+
|
|
22
|
+
/** Where the token goes; the same path `lib/view-token.ts` names. */
|
|
23
|
+
const CONFIRM_PATH = "/_/seen";
|
|
24
|
+
|
|
25
|
+
/** Anything a reader does that a crawler fetching a page does not. */
|
|
26
|
+
const INTERACTION_EVENTS = [
|
|
27
|
+
"pointerdown",
|
|
28
|
+
"pointermove",
|
|
29
|
+
"keydown",
|
|
30
|
+
"wheel",
|
|
31
|
+
"touchstart",
|
|
32
|
+
"scroll",
|
|
33
|
+
] as const;
|
|
34
|
+
|
|
35
|
+
function deliver(url: string, token: string): void {
|
|
36
|
+
const sent =
|
|
37
|
+
typeof navigator.sendBeacon === "function" &&
|
|
38
|
+
navigator.sendBeacon(url, new Blob([token], { type: "text/plain" }));
|
|
39
|
+
if (sent) return;
|
|
40
|
+
void fetch(url, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
body: token,
|
|
43
|
+
keepalive: true,
|
|
44
|
+
headers: { "content-type": "text/plain" },
|
|
45
|
+
}).catch(() => {});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Arm the page's confirmation, if the page carries a token.
|
|
50
|
+
*
|
|
51
|
+
* @param doc - The document, the current one unless a test passes another
|
|
52
|
+
* @returns Nothing
|
|
53
|
+
* @example
|
|
54
|
+
* confirmView();
|
|
55
|
+
*/
|
|
56
|
+
export function confirmView(doc: globalThis.Document = document): void {
|
|
57
|
+
const token = doc
|
|
58
|
+
.querySelector<globalThis.HTMLMetaElement>('meta[name="jant-view"]')
|
|
59
|
+
?.getAttribute("content");
|
|
60
|
+
if (!token) return;
|
|
61
|
+
if (navigator.webdriver) return;
|
|
62
|
+
|
|
63
|
+
const url = publicPath(CONFIRM_PATH);
|
|
64
|
+
let done = false;
|
|
65
|
+
let remaining = VIEW_CONFIRM_DWELL_MS;
|
|
66
|
+
let visibleSince: number | null = null;
|
|
67
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
68
|
+
|
|
69
|
+
const stopClock = () => {
|
|
70
|
+
if (timer === null) return;
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
timer = null;
|
|
73
|
+
remaining = Math.max(0, remaining - (Date.now() - (visibleSince ?? 0)));
|
|
74
|
+
};
|
|
75
|
+
const startClock = () => {
|
|
76
|
+
if (done || timer !== null || doc.visibilityState !== "visible") return;
|
|
77
|
+
visibleSince = Date.now();
|
|
78
|
+
timer = setTimeout(send, remaining);
|
|
79
|
+
};
|
|
80
|
+
const onVisibility = () => {
|
|
81
|
+
if (doc.visibilityState === "visible") startClock();
|
|
82
|
+
else stopClock();
|
|
83
|
+
};
|
|
84
|
+
const send = () => {
|
|
85
|
+
if (done) return;
|
|
86
|
+
done = true;
|
|
87
|
+
stopClock();
|
|
88
|
+
for (const event of INTERACTION_EVENTS) {
|
|
89
|
+
doc.removeEventListener(event, send);
|
|
90
|
+
}
|
|
91
|
+
doc.removeEventListener("visibilitychange", onVisibility);
|
|
92
|
+
deliver(url, token);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
for (const event of INTERACTION_EVENTS) {
|
|
96
|
+
doc.addEventListener(event, send, { passive: true });
|
|
97
|
+
}
|
|
98
|
+
doc.addEventListener("visibilitychange", onVisibility);
|
|
99
|
+
startClock();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (document.readyState === "loading") {
|
|
103
|
+
document.addEventListener("DOMContentLoaded", () => confirmView(), {
|
|
104
|
+
once: true,
|
|
105
|
+
});
|
|
106
|
+
} else {
|
|
107
|
+
confirmView();
|
|
108
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Share entry: the "Share as image" dialog, and snapdom with it.
|
|
3
|
+
*
|
|
4
|
+
* Loaded by `client/share-launch.ts` the first time an author picks "Share as
|
|
5
|
+
* image" from a post menu. Never referenced from a script tag.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import "./client/components/jant-share-dialog.js";
|
package/src/client.ts
CHANGED
|
@@ -9,11 +9,13 @@ import "./vendor/datastar.js";
|
|
|
9
9
|
import { installPrefixedFetch } from "./client/runtime-paths.js";
|
|
10
10
|
import "./client/audio-player.js";
|
|
11
11
|
import "./client/feed-video-player.js";
|
|
12
|
+
import "./client/view-confirm.js";
|
|
12
13
|
import "./client/media-scroll-hint.js";
|
|
13
14
|
import "./client/form-enter-submit.js";
|
|
14
15
|
import "./client/copy-field.js";
|
|
15
16
|
import "./client/components/jant-media-lightbox.js";
|
|
16
17
|
import "./client/components/jant-text-preview.js";
|
|
18
|
+
import "./client/components/jant-share-menu.js";
|
|
17
19
|
// First-run setup is a signed-out page, so the language picker it shares with
|
|
18
20
|
// the settings page has to ship in the public bundle.
|
|
19
21
|
import "./client/components/jant-locale-picker.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
CREATE TABLE `view_count` (
|
|
2
|
+
`site_id` text NOT NULL,
|
|
3
|
+
`day` text NOT NULL,
|
|
4
|
+
`page` text NOT NULL,
|
|
5
|
+
`referrer` text NOT NULL,
|
|
6
|
+
`count` integer DEFAULT 0 NOT NULL,
|
|
7
|
+
PRIMARY KEY(`site_id`, `day`, `page`, `referrer`),
|
|
8
|
+
FOREIGN KEY (`site_id`) REFERENCES `site`(`id`) ON UPDATE no action ON DELETE cascade
|
|
9
|
+
);
|