@jant/core 1.1.0 → 1.3.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/commands/site/import.js +2 -1
- package/bin/lib/site-snapshot.js +10 -0
- package/dist/{app-CKQ9PqAr.js → app-C8dETvgL.js} +9267 -5697
- package/dist/client/.vite/manifest.json +82 -93
- package/dist/client/_assets/chunks/{confirm-CMe01lne.js → confirm-BQebcuNB.js} +1 -1
- package/dist/client/_assets/chunks/{create-editor-BQkrw8Ax.js → create-editor-B8KuszlS.js} +38 -38
- package/dist/client/_assets/chunks/footnote-rail-DUrqz0Py.js +2 -0
- package/dist/client/_assets/chunks/{jant-locale-picker-2L4rkDaz.js → jant-locale-picker-CLq0iKDH.js} +1 -1
- package/dist/client/_assets/chunks/lit-BN4mrI3j.js +2 -0
- package/dist/client/_assets/chunks/{settings-paths-B0bNUaih.js → settings-paths-_fry4yWW.js} +1 -1
- package/dist/client/_assets/chunks/{slug-format-CYmQE5ln.js → slug-format-bcJ2ozr4.js} +1 -1
- package/dist/client/_assets/chunks/sortable-list-Bz2Na2E9.js +2 -0
- package/dist/client/_assets/chunks/types-DrYFqJH2.js +1 -0
- package/dist/client/_assets/chunks/{unsafe-html-CWos3v6N.js → unsafe-html-OJ9m154w.js} +1 -1
- package/dist/client/_assets/chunks/unsafe-svg-DVJ4NPcb.js +1 -0
- package/dist/client/_assets/client-CoNHvipV.css +2 -0
- package/dist/client/_assets/{client-auth-CG55rWb5.js → client-auth-CbnZkLJ6.js} +99 -129
- package/dist/client/_assets/{client-author-CGVvrNZ8.css → client-author-2WYBkgni.css} +1 -1
- package/dist/client/_assets/client-compose-DYtDlYm-.js +2008 -0
- package/dist/client/_assets/{client-manage-DnYdQAhf.js → client-manage-BODyYP5Z.js} +157 -157
- package/dist/client/_assets/client-pq6sVS7y.js +354 -0
- package/dist/client/_assets/{client-settings-CHgsIqXJ.js → client-settings-DDpe_tXJ.js} +166 -166
- package/dist/client/_assets/client-share-B9OsXx9p.js +149 -0
- package/dist/{constants-DEgyqWDl.js → constants-C2CdWAqt.js} +55 -5
- 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 +6 -1
- package/src/client/components/jant-compose-dialog.ts +26 -4
- 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-media-lightbox.ts +18 -3
- package/src/client/components/jant-nav-manager.ts +2 -0
- package/src/client/components/jant-post-menu.ts +42 -89
- package/src/client/components/nav-manager-types.ts +2 -0
- package/src/client/components/settings-types.ts +1 -1
- package/src/client/compose-bridge.ts +61 -1
- package/src/client/feed-video-player.ts +6 -0
- package/src/client/list-views.ts +382 -0
- package/src/client/media-lightbox-events.ts +12 -0
- package/src/client/runtime-paths.ts +12 -0
- package/src/client/share-capture.ts +63 -0
- package/src/client/share-launch.ts +36 -9
- package/src/client/tiptap/bubble-menu.ts +25 -2
- package/src/client/tiptap/create-editor.ts +6 -0
- package/src/client/tiptap/embed-node.ts +3 -1
- package/src/client/tiptap/extensions.ts +4 -0
- package/src/client/tiptap/html-block-node.ts +3 -1
- package/src/client/tiptap/image-node.ts +3 -1
- package/src/client/video-processor.ts +106 -52
- package/src/client/view-confirm.ts +136 -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/0037_round_post.sql +16 -0
- package/src/db/migrations/0038_flashy_changeling.sql +15 -0
- package/src/db/migrations/0039_mixed_sister_grimm.sql +1 -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/0037_snapshot.json +2932 -0
- package/src/db/migrations/meta/0038_snapshot.json +2924 -0
- package/src/db/migrations/meta/0039_snapshot.json +2931 -0
- package/src/db/migrations/meta/_journal.json +35 -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/0035_flimsy_outlaw_kid.sql +3 -0
- package/src/db/migrations/pg/0036_milky_wolverine.sql +5 -0
- package/src/db/migrations/pg/0037_fuzzy_hammerhead.sql +1 -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/0035_snapshot.json +3773 -0
- package/src/db/migrations/pg/meta/0036_snapshot.json +3766 -0
- package/src/db/migrations/pg/meta/0037_snapshot.json +3772 -0
- package/src/db/migrations/pg/meta/_journal.json +35 -0
- package/src/db/pg/schema.ts +41 -0
- package/src/db/post-visibility.ts +37 -6
- package/src/db/schema.ts +64 -0
- package/src/i18n/locales/glossary.zh-Hans.yml +4 -0
- package/src/i18n/locales/glossary.zh-Hant.yml +4 -0
- package/src/i18n/locales/public/en.po +26 -7
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +25 -6
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +25 -6
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +159 -0
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +159 -0
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +159 -0
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/lib/api-public-posts.ts +10 -0
- package/src/lib/env.ts +20 -0
- package/src/lib/feed-policy.ts +2 -2
- package/src/lib/filter-dimensions.ts +11 -4
- package/src/lib/github-app-state.ts +1 -1
- package/src/lib/github-app.ts +183 -1
- package/src/lib/hugo-markdown.ts +7 -0
- package/src/lib/icons.ts +2 -0
- package/src/lib/link-preview.ts +499 -0
- package/src/lib/list-views.ts +117 -0
- package/src/lib/markdown-manager.ts +169 -2
- package/src/lib/navigation.ts +1 -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 +4 -3
- package/src/lib/summary.ts +152 -54
- package/src/lib/thread-query.ts +6 -2
- package/src/lib/timeline.ts +12 -11
- package/src/lib/tiptap-render.ts +1 -0
- package/src/lib/upload.ts +21 -1
- package/src/lib/url-fetch.ts +291 -74
- package/src/lib/video-playback.ts +55 -0
- package/src/lib/view-buffer.ts +201 -0
- package/src/lib/view-counting.ts +540 -0
- package/src/lib/view-token.ts +199 -0
- package/src/lib/view.ts +30 -1
- package/src/middleware/view-counter.ts +145 -0
- package/src/node/runtime.ts +4 -0
- package/src/preset.css +36 -17
- package/src/routes/api/media.ts +21 -3
- package/src/routes/api/search.ts +1 -1
- package/src/routes/dash/settings.tsx +434 -169
- package/src/routes/feed/sitemap.ts +1 -1
- package/src/routes/pages/archive.tsx +26 -19
- package/src/routes/pages/collection.tsx +9 -3
- 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 +18 -3
- package/src/routes/pages/search.tsx +3 -3
- package/src/routes/pages/smart-collection.tsx +2 -0
- package/src/routes/pages/subscribe.tsx +1 -0
- package/src/routes/view-confirm.ts +71 -0
- package/src/services/collection.ts +1 -1
- package/src/services/export-theme/assets/client-site.js +19 -19
- package/src/services/export-theme/layouts/archive/list.html +4 -2
- package/src/services/export-theme/layouts/partials/collection-members.html +4 -3
- package/src/services/export-theme/layouts/partials/featured-members.html +3 -3
- package/src/services/export-theme/layouts/partials/head.html +2 -0
- package/src/services/export-theme/layouts/partials/latest-members.html +4 -4
- package/src/services/export-theme/layouts/partials/post-card.html +1 -9
- package/src/services/export-theme/layouts/partials/reply.html +1 -9
- package/src/services/export-theme/layouts/partials/smart-collection-members.html +4 -3
- package/src/services/export-theme/layouts/post/list.html +1 -9
- package/src/services/export-theme/styles/main.css +41 -47
- package/src/services/export.ts +12 -3
- package/src/services/index.ts +17 -0
- package/src/services/mcp.ts +36 -6
- package/src/services/media.ts +63 -0
- package/src/services/navigation.ts +9 -4
- package/src/services/post.ts +102 -112
- package/src/services/search.ts +22 -7
- package/src/services/smart-collection.ts +3 -3
- package/src/services/stats.ts +1137 -0
- package/src/services/thread.ts +6 -2
- package/src/styles/components-author.css +242 -3
- package/src/styles/components.css +11 -3
- package/src/styles/tokens.css +89 -55
- package/src/styles/ui-author.css +140 -353
- package/src/styles/ui.css +90 -45
- 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/constants.ts +68 -4
- package/src/types/entities.ts +1 -0
- package/src/types/views.ts +8 -0
- package/src/ui/compose/ComposeDialog.tsx +26 -1
- package/src/ui/dash/StatusBadge.tsx +11 -0
- package/src/ui/dash/appearance/FontThemeContent.tsx +1 -1
- package/src/ui/dash/appearance/NavigationContent.tsx +8 -0
- package/src/ui/dash/settings/SettingsRootContent.tsx +24 -6
- package/src/ui/dash/settings/StatsContent.tsx +855 -0
- package/src/ui/feed/LinkCard.tsx +19 -2
- package/src/ui/feed/PostStatusBadges.tsx +19 -3
- package/src/ui/feed/TimelineFeed.tsx +3 -0
- package/src/ui/font-themes.ts +56 -6
- package/src/ui/layouts/BaseLayout.tsx +4 -2
- package/src/ui/layouts/SiteLayout.tsx +8 -3
- package/src/ui/pages/ArchivePage.tsx +1 -0
- package/src/ui/shared/MediaGallery.tsx +19 -3
- package/src/ui/shared/PostFooter.tsx +1 -22
- package/src/ui/shared/custom-icons.ts +5 -5
- package/dist/client/_assets/chunks/footnote-rail-B08scyhW.js +0 -2
- package/dist/client/_assets/chunks/lit-Bw_voPoW.js +0 -2
- package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +0 -1
- package/dist/client/_assets/chunks/sortable-list-t11Ma1Ek.js +0 -2
- package/dist/client/_assets/chunks/types-D5iF3H1a.js +0 -1
- package/dist/client/_assets/chunks/unsafe-svg-DZl-yjas.js +0 -1
- package/dist/client/_assets/client-B0-s9sqx.css +0 -2
- package/dist/client/_assets/client-Dp46QSht.js +0 -354
- package/dist/client/_assets/client-compose-DkUTuavR.js +0 -2004
- package/dist/client/_assets/client-share-C59mOLJ1.js +0 -149
|
@@ -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,
|
|
@@ -52,6 +54,10 @@ export function createTiptapEditor(options: CreateEditorOptions): Editor {
|
|
|
52
54
|
}),
|
|
53
55
|
content: options.content ?? undefined,
|
|
54
56
|
editorProps: {
|
|
57
|
+
// The document is the post body being written, so it wears the class the
|
|
58
|
+
// published body wears and takes the reader's typography as it is. A
|
|
59
|
+
// second copy of those rules for the editor is what drifted before.
|
|
60
|
+
attributes: { class: "prose" },
|
|
55
61
|
scrollMargin: { top: 5, right: 5, bottom: 80, left: 5 },
|
|
56
62
|
scrollThreshold: { top: 5, right: 5, bottom: 80, left: 5 },
|
|
57
63
|
},
|
|
@@ -61,7 +61,9 @@ class EmbedNodeView {
|
|
|
61
61
|
this.editor = editor;
|
|
62
62
|
|
|
63
63
|
const card = document.createElement("div");
|
|
64
|
-
|
|
64
|
+
// `not-prose`: this is editor chrome, not post content, so the reader's
|
|
65
|
+
// typography defaults stay out of its controls.
|
|
66
|
+
card.className = "tiptap-embed-card not-prose";
|
|
65
67
|
card.dataset.selected = "false";
|
|
66
68
|
this.dom = card;
|
|
67
69
|
|
|
@@ -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,
|
|
@@ -55,7 +55,9 @@ class HtmlBlockNodeView {
|
|
|
55
55
|
this.editor = editor;
|
|
56
56
|
|
|
57
57
|
const wrapper = document.createElement("div");
|
|
58
|
-
|
|
58
|
+
// `not-prose`: this is editor chrome, not post content, so the reader's
|
|
59
|
+
// typography defaults stay out of its controls.
|
|
60
|
+
wrapper.className = "tiptap-html-block-card not-prose";
|
|
59
61
|
wrapper.dataset.selected = "false";
|
|
60
62
|
this.dom = wrapper;
|
|
61
63
|
|
|
@@ -115,7 +115,9 @@ class ImageNodeView {
|
|
|
115
115
|
|
|
116
116
|
// --- Build DOM tree ---
|
|
117
117
|
const figure = document.createElement("figure");
|
|
118
|
-
|
|
118
|
+
// `not-prose`: this is editor chrome, not post content, so the reader's
|
|
119
|
+
// typography defaults stay out of its controls.
|
|
120
|
+
figure.className = "tiptap-image-figure not-prose";
|
|
119
121
|
figure.dataset.selected = "false";
|
|
120
122
|
figure.dataset.layout = String(node.attrs.layout || "regular");
|
|
121
123
|
figure.dataset.loadState = "loading";
|
|
@@ -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,136 @@
|
|
|
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
|
+
* The Threads read in full in a list page's feed go out the same way, once
|
|
16
|
+
* the page is confirmed (`list-views.ts`).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { publicPath } from "./runtime-paths.js";
|
|
20
|
+
|
|
21
|
+
/** Visible time after which a page counts as seen, without any interaction. */
|
|
22
|
+
export const VIEW_CONFIRM_DWELL_MS = 5_000;
|
|
23
|
+
|
|
24
|
+
/** Where the token goes; the same path `lib/view-token.ts` names. */
|
|
25
|
+
export const CONFIRM_PATH = "/_/seen";
|
|
26
|
+
|
|
27
|
+
/** Anything a reader does that a crawler fetching a page does not. */
|
|
28
|
+
const INTERACTION_EVENTS = [
|
|
29
|
+
"pointerdown",
|
|
30
|
+
"pointermove",
|
|
31
|
+
"keydown",
|
|
32
|
+
"wheel",
|
|
33
|
+
"touchstart",
|
|
34
|
+
"scroll",
|
|
35
|
+
] as const;
|
|
36
|
+
|
|
37
|
+
/** Documents whose view has been confirmed. */
|
|
38
|
+
const confirmed = new WeakSet<globalThis.Document>();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Post a body to the site, surviving the page being closed: a beacon, or a
|
|
42
|
+
* `keepalive` fetch when the browser will not queue one.
|
|
43
|
+
*
|
|
44
|
+
* @param url - Where to post
|
|
45
|
+
* @param body - The plain-text body
|
|
46
|
+
* @returns Nothing; nothing waits for the answer
|
|
47
|
+
* @example
|
|
48
|
+
* deliver(publicPath(CONFIRM_PATH), token);
|
|
49
|
+
*/
|
|
50
|
+
export function deliver(url: string, body: string): void {
|
|
51
|
+
const sent =
|
|
52
|
+
typeof navigator.sendBeacon === "function" &&
|
|
53
|
+
navigator.sendBeacon(url, new Blob([body], { type: "text/plain" }));
|
|
54
|
+
if (sent) return;
|
|
55
|
+
void fetch(url, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
body,
|
|
58
|
+
keepalive: true,
|
|
59
|
+
headers: { "content-type": "text/plain" },
|
|
60
|
+
}).catch(() => {});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Whether this document has confirmed its view.
|
|
65
|
+
*
|
|
66
|
+
* @param doc - The document, the current one unless a test passes another
|
|
67
|
+
* @returns `true` once the confirmation went out
|
|
68
|
+
* @example
|
|
69
|
+
* if (isViewConfirmed()) report();
|
|
70
|
+
*/
|
|
71
|
+
export function isViewConfirmed(doc: globalThis.Document = document): boolean {
|
|
72
|
+
return confirmed.has(doc);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Arm the page's confirmation, if the page carries a token.
|
|
77
|
+
*
|
|
78
|
+
* @param doc - The document, the current one unless a test passes another
|
|
79
|
+
* @returns Nothing
|
|
80
|
+
* @example
|
|
81
|
+
* confirmView();
|
|
82
|
+
*/
|
|
83
|
+
export function confirmView(doc: globalThis.Document = document): void {
|
|
84
|
+
const token = doc
|
|
85
|
+
.querySelector<globalThis.HTMLMetaElement>('meta[name="jant-view"]')
|
|
86
|
+
?.getAttribute("content");
|
|
87
|
+
if (!token) return;
|
|
88
|
+
if (navigator.webdriver) return;
|
|
89
|
+
|
|
90
|
+
const url = publicPath(CONFIRM_PATH);
|
|
91
|
+
let done = false;
|
|
92
|
+
let remaining = VIEW_CONFIRM_DWELL_MS;
|
|
93
|
+
let visibleSince: number | null = null;
|
|
94
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
95
|
+
|
|
96
|
+
const stopClock = () => {
|
|
97
|
+
if (timer === null) return;
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
timer = null;
|
|
100
|
+
remaining = Math.max(0, remaining - (Date.now() - (visibleSince ?? 0)));
|
|
101
|
+
};
|
|
102
|
+
const startClock = () => {
|
|
103
|
+
if (done || timer !== null || doc.visibilityState !== "visible") return;
|
|
104
|
+
visibleSince = Date.now();
|
|
105
|
+
timer = setTimeout(send, remaining);
|
|
106
|
+
};
|
|
107
|
+
const onVisibility = () => {
|
|
108
|
+
if (doc.visibilityState === "visible") startClock();
|
|
109
|
+
else stopClock();
|
|
110
|
+
};
|
|
111
|
+
const send = () => {
|
|
112
|
+
if (done) return;
|
|
113
|
+
done = true;
|
|
114
|
+
stopClock();
|
|
115
|
+
for (const event of INTERACTION_EVENTS) {
|
|
116
|
+
doc.removeEventListener(event, send);
|
|
117
|
+
}
|
|
118
|
+
doc.removeEventListener("visibilitychange", onVisibility);
|
|
119
|
+
confirmed.add(doc);
|
|
120
|
+
deliver(url, token);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
for (const event of INTERACTION_EVENTS) {
|
|
124
|
+
doc.addEventListener(event, send, { passive: true });
|
|
125
|
+
}
|
|
126
|
+
doc.addEventListener("visibilitychange", onVisibility);
|
|
127
|
+
startClock();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (document.readyState === "loading") {
|
|
131
|
+
document.addEventListener("DOMContentLoaded", () => confirmView(), {
|
|
132
|
+
once: true,
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
confirmView();
|
|
136
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -9,6 +9,8 @@ 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";
|
|
13
|
+
import "./client/list-views.js";
|
|
12
14
|
import "./client/media-scroll-hint.js";
|
|
13
15
|
import "./client/form-enter-submit.js";
|
|
14
16
|
import "./client/copy-field.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
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
2
|
+
CREATE TABLE `__new_view_count` (
|
|
3
|
+
`site_id` text NOT NULL,
|
|
4
|
+
`day` text NOT NULL,
|
|
5
|
+
`page` text NOT NULL,
|
|
6
|
+
`referrer` text NOT NULL,
|
|
7
|
+
`via` text DEFAULT 'page' NOT NULL,
|
|
8
|
+
`count` integer DEFAULT 0 NOT NULL,
|
|
9
|
+
PRIMARY KEY(`site_id`, `day`, `page`, `referrer`, `via`),
|
|
10
|
+
FOREIGN KEY (`site_id`) REFERENCES `site`(`id`) ON UPDATE no action ON DELETE cascade
|
|
11
|
+
);
|
|
12
|
+
--> statement-breakpoint
|
|
13
|
+
INSERT INTO `__new_view_count`("site_id", "day", "page", "referrer", "count") SELECT "site_id", "day", "page", "referrer", "count" FROM `view_count`;--> statement-breakpoint
|
|
14
|
+
DROP TABLE `view_count`;--> statement-breakpoint
|
|
15
|
+
ALTER TABLE `__new_view_count` RENAME TO `view_count`;--> statement-breakpoint
|
|
16
|
+
PRAGMA foreign_keys=ON;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
2
|
+
CREATE TABLE `__new_view_count` (
|
|
3
|
+
`site_id` text NOT NULL,
|
|
4
|
+
`day` text NOT NULL,
|
|
5
|
+
`page` text NOT NULL,
|
|
6
|
+
`referrer` text NOT NULL,
|
|
7
|
+
`count` integer DEFAULT 0 NOT NULL,
|
|
8
|
+
PRIMARY KEY(`site_id`, `day`, `page`, `referrer`),
|
|
9
|
+
FOREIGN KEY (`site_id`) REFERENCES `site`(`id`) ON UPDATE no action ON DELETE cascade
|
|
10
|
+
);
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
INSERT INTO `__new_view_count`("site_id", "day", "page", "referrer", "count") SELECT "site_id", "day", "page", "referrer", SUM("count") FROM `view_count` GROUP BY "site_id", "day", "page", "referrer";--> statement-breakpoint
|
|
13
|
+
DROP TABLE `view_count`;--> statement-breakpoint
|
|
14
|
+
ALTER TABLE `__new_view_count` RENAME TO `view_count`;--> statement-breakpoint
|
|
15
|
+
PRAGMA foreign_keys=ON;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE `post` ADD `preview_icon_key` text;
|