@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,422 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Share Dialog
|
|
3
|
+
*
|
|
4
|
+
* "Share as image" from the post menu: lays out the post's share card,
|
|
5
|
+
* paints it as a PNG (`share-capture.ts`), and offers the image to download,
|
|
6
|
+
* hand to the system share sheet, or copy. On a phone the image itself is
|
|
7
|
+
* the save button — press and hold.
|
|
8
|
+
*
|
|
9
|
+
* The card is on screen before the picture is: once it is laid out, the
|
|
10
|
+
* dialog shows it faded, as a print still developing, and the finished PNG
|
|
11
|
+
* takes its place at full strength. The two are the same pixels, so the
|
|
12
|
+
* swap shows only as the card coming up to strength.
|
|
13
|
+
*
|
|
14
|
+
* Light DOM only — BaseCoat and the author stylesheet apply directly.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { LitElement, html, nothing, svg } from "lit";
|
|
18
|
+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
19
|
+
import {
|
|
20
|
+
prepareShareCard,
|
|
21
|
+
type PreparedShareCard,
|
|
22
|
+
type ShareImage,
|
|
23
|
+
} from "../share-capture.js";
|
|
24
|
+
import { showToast } from "../toast.js";
|
|
25
|
+
|
|
26
|
+
type ShareStatus = "loading" | "developing" | "ready" | "error";
|
|
27
|
+
|
|
28
|
+
function pngFile(blob: Blob, fileName: string): File {
|
|
29
|
+
return new File([blob], fileName, { type: "image/png" });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Whether the system share sheet takes a PNG as a file. */
|
|
33
|
+
function canShareImage(): boolean {
|
|
34
|
+
try {
|
|
35
|
+
return (
|
|
36
|
+
navigator.canShare?.({ files: [pngFile(new Blob(), "post.png")] }) ??
|
|
37
|
+
false
|
|
38
|
+
);
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function canCopyImage(): boolean {
|
|
45
|
+
return (
|
|
46
|
+
globalThis.isSecureContext &&
|
|
47
|
+
typeof globalThis.ClipboardItem === "function" &&
|
|
48
|
+
typeof navigator.clipboard?.write === "function"
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A Lucide icon for a button, in the post menu's stroke. */
|
|
53
|
+
function icon(paths: ReturnType<typeof svg>) {
|
|
54
|
+
return html`<svg
|
|
55
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
56
|
+
viewBox="0 0 24 24"
|
|
57
|
+
fill="none"
|
|
58
|
+
stroke="currentColor"
|
|
59
|
+
stroke-width="1.75"
|
|
60
|
+
stroke-linecap="round"
|
|
61
|
+
stroke-linejoin="round"
|
|
62
|
+
aria-hidden="true"
|
|
63
|
+
>
|
|
64
|
+
${paths}
|
|
65
|
+
</svg>`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const ICON_SHARE = svg`<path d="M12 2v13" /><path d="m16 6-4-4-4 4" /><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8" />`;
|
|
69
|
+
const ICON_COPY = svg`<rect width="14" height="14" x="8" y="8" rx="2" ry="2" /><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />`;
|
|
70
|
+
const ICON_DOWNLOAD = svg`<path d="M12 15V3" /><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /><path d="m7 10 5 5 5-5" />`;
|
|
71
|
+
const ICON_CLOSE = svg`<path d="M18 6 6 18" /><path d="m6 6 12 12" />`;
|
|
72
|
+
|
|
73
|
+
/** Resolves once the image at `url` is decoded and can show at once. */
|
|
74
|
+
async function decoded(url: string): Promise<void> {
|
|
75
|
+
const image = new Image();
|
|
76
|
+
image.src = url;
|
|
77
|
+
await image.decode();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class JantShareDialog extends LitElement {
|
|
81
|
+
static properties = {
|
|
82
|
+
_open: { state: true },
|
|
83
|
+
_status: { state: true },
|
|
84
|
+
_card: { state: true },
|
|
85
|
+
_imageUrl: { state: true },
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
declare _open: boolean;
|
|
89
|
+
declare _status: ShareStatus;
|
|
90
|
+
/** The laid-out card, shown while its picture is painted. */
|
|
91
|
+
declare _card: { html: string; width: number; height: number } | null;
|
|
92
|
+
declare _imageUrl: string;
|
|
93
|
+
|
|
94
|
+
#image: ShareImage | null = null;
|
|
95
|
+
#prepared: PreparedShareCard | null = null;
|
|
96
|
+
#loadCard: () => Promise<string> = () => Promise.reject(new Error());
|
|
97
|
+
#returnFocus: HTMLElement | null = null;
|
|
98
|
+
/** Bumped per generation, so a capture that finishes late is dropped. */
|
|
99
|
+
#generation = 0;
|
|
100
|
+
|
|
101
|
+
constructor() {
|
|
102
|
+
super();
|
|
103
|
+
this._open = false;
|
|
104
|
+
this._status = "loading";
|
|
105
|
+
this._card = null;
|
|
106
|
+
this._imageUrl = "";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
createRenderRoot() {
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
disconnectedCallback() {
|
|
114
|
+
super.disconnectedCallback();
|
|
115
|
+
window.removeEventListener("resize", this.#fitCard);
|
|
116
|
+
this.#reset();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
updated() {
|
|
120
|
+
this.#fitCard();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Open the dialog and start painting the post.
|
|
125
|
+
*
|
|
126
|
+
* @param loadCard - Fetches the card's markup; called again by "Try again"
|
|
127
|
+
* @param returnFocus - Element to focus again on close
|
|
128
|
+
*/
|
|
129
|
+
async open(
|
|
130
|
+
loadCard: () => Promise<string>,
|
|
131
|
+
returnFocus: HTMLElement | null,
|
|
132
|
+
): Promise<void> {
|
|
133
|
+
this.#loadCard = loadCard;
|
|
134
|
+
this.#returnFocus = returnFocus;
|
|
135
|
+
this._open = true;
|
|
136
|
+
document.body.style.overflow = "hidden";
|
|
137
|
+
window.addEventListener("resize", this.#fitCard);
|
|
138
|
+
await this.updateComplete;
|
|
139
|
+
this.querySelector<HTMLDialogElement>(".share-dialog")?.showModal();
|
|
140
|
+
this.querySelector<HTMLElement>(".share-dialog-panel")?.focus();
|
|
141
|
+
await this.#generate();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async #generate(): Promise<void> {
|
|
145
|
+
const generation = ++this.#generation;
|
|
146
|
+
const current = () => generation === this.#generation && this._open;
|
|
147
|
+
this.#reset();
|
|
148
|
+
this._status = "loading";
|
|
149
|
+
try {
|
|
150
|
+
const prepared = await prepareShareCard(await this.#loadCard());
|
|
151
|
+
if (!current()) {
|
|
152
|
+
prepared.dispose();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
this.#prepared = prepared;
|
|
156
|
+
this._card = {
|
|
157
|
+
html: prepared.html,
|
|
158
|
+
width: prepared.width,
|
|
159
|
+
height: prepared.height,
|
|
160
|
+
};
|
|
161
|
+
this._status = "developing";
|
|
162
|
+
|
|
163
|
+
const image = await prepared.capture();
|
|
164
|
+
this.#prepared = null;
|
|
165
|
+
if (!current()) return;
|
|
166
|
+
const url = URL.createObjectURL(image.blob);
|
|
167
|
+
// Swapped in only once it can paint, so the card never blinks out.
|
|
168
|
+
await decoded(url).catch(() => {});
|
|
169
|
+
if (!current()) {
|
|
170
|
+
URL.revokeObjectURL(url);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this.#image = image;
|
|
174
|
+
this._imageUrl = url;
|
|
175
|
+
this._status = "ready";
|
|
176
|
+
} catch {
|
|
177
|
+
if (!current()) return;
|
|
178
|
+
this.#reset();
|
|
179
|
+
this._status = "error";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Drop the card and the image, and anything still laid out off screen. */
|
|
184
|
+
#reset(): void {
|
|
185
|
+
this.#prepared?.dispose();
|
|
186
|
+
this.#prepared = null;
|
|
187
|
+
if (this._imageUrl) URL.revokeObjectURL(this._imageUrl);
|
|
188
|
+
this._imageUrl = "";
|
|
189
|
+
this._card = null;
|
|
190
|
+
this.#image = null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Scale the laid-out card, 540 px wide, to the preview's width. */
|
|
194
|
+
#fitCard = () => {
|
|
195
|
+
const print = this.querySelector<HTMLElement>(".share-dialog-print");
|
|
196
|
+
const card = print?.querySelector<HTMLElement>(".share-dialog-card");
|
|
197
|
+
if (!print || !card || !this._card) return;
|
|
198
|
+
card.style.transform = `scale(${print.clientWidth / this._card.width})`;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
#close(): void {
|
|
202
|
+
this.#generation++;
|
|
203
|
+
this.querySelector<HTMLDialogElement>(".share-dialog")?.close();
|
|
204
|
+
document.body.style.overflow = "";
|
|
205
|
+
window.removeEventListener("resize", this.#fitCard);
|
|
206
|
+
this._open = false;
|
|
207
|
+
this.#reset();
|
|
208
|
+
const target = this.#returnFocus;
|
|
209
|
+
this.#returnFocus = null;
|
|
210
|
+
queueMicrotask(() => {
|
|
211
|
+
if (target?.isConnected) target.focus();
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#download(): void {
|
|
216
|
+
if (!this.#image || !this._imageUrl) return;
|
|
217
|
+
const link = document.createElement("a");
|
|
218
|
+
link.href = this._imageUrl;
|
|
219
|
+
link.download = this.#image.fileName;
|
|
220
|
+
document.body.appendChild(link);
|
|
221
|
+
link.click();
|
|
222
|
+
link.remove();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async #share(): Promise<void> {
|
|
226
|
+
if (!this.#image) return;
|
|
227
|
+
try {
|
|
228
|
+
await navigator.share({
|
|
229
|
+
files: [pngFile(this.#image.blob, this.#image.fileName)],
|
|
230
|
+
});
|
|
231
|
+
} catch (error) {
|
|
232
|
+
if (
|
|
233
|
+
error instanceof globalThis.DOMException &&
|
|
234
|
+
error.name === "AbortError"
|
|
235
|
+
) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
showToast("Could not share the image. Download it instead.", "error");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async #copy(): Promise<void> {
|
|
243
|
+
if (!this.#image) return;
|
|
244
|
+
try {
|
|
245
|
+
await navigator.clipboard.write([
|
|
246
|
+
new globalThis.ClipboardItem({ "image/png": this.#image.blob }),
|
|
247
|
+
]);
|
|
248
|
+
showToast("Image copied.");
|
|
249
|
+
} catch {
|
|
250
|
+
showToast("Could not copy the image. Download it instead.", "error");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#handleKeydown = (event: KeyboardEvent) => {
|
|
255
|
+
if (event.key === "Escape") {
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
event.stopPropagation();
|
|
258
|
+
this.#close();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
#renderPrint() {
|
|
263
|
+
const card = this._card;
|
|
264
|
+
const content =
|
|
265
|
+
this._status === "ready"
|
|
266
|
+
? html`<img
|
|
267
|
+
class="share-dialog-image"
|
|
268
|
+
src=${this._imageUrl}
|
|
269
|
+
alt="This post as an image"
|
|
270
|
+
/>`
|
|
271
|
+
: card
|
|
272
|
+
? html`<div class="share-dialog-card" inert>
|
|
273
|
+
${unsafeHTML(card.html)}
|
|
274
|
+
</div>`
|
|
275
|
+
: html`<div class="share-dialog-blank"></div>`;
|
|
276
|
+
return html`
|
|
277
|
+
<div
|
|
278
|
+
class="share-dialog-print"
|
|
279
|
+
data-status=${this._status}
|
|
280
|
+
style=${card ? `aspect-ratio: ${card.width} / ${card.height}` : ""}
|
|
281
|
+
>
|
|
282
|
+
${content}
|
|
283
|
+
</div>
|
|
284
|
+
`;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#renderPreview() {
|
|
288
|
+
if (this._status !== "error") return this.#renderPrint();
|
|
289
|
+
return html`
|
|
290
|
+
<p class="share-dialog-status">
|
|
291
|
+
Could not create the image. Check your connection and try again.
|
|
292
|
+
</p>
|
|
293
|
+
<button
|
|
294
|
+
type="button"
|
|
295
|
+
class="btn-outline"
|
|
296
|
+
@click=${() => void this.#generate()}
|
|
297
|
+
>
|
|
298
|
+
Try again
|
|
299
|
+
</button>
|
|
300
|
+
`;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
#renderNote() {
|
|
304
|
+
switch (this._status) {
|
|
305
|
+
case "loading":
|
|
306
|
+
case "developing":
|
|
307
|
+
return "Creating the image…";
|
|
308
|
+
case "ready":
|
|
309
|
+
return html`<span class="share-dialog-hint"
|
|
310
|
+
>Press and hold the image to save it.</span
|
|
311
|
+
>`;
|
|
312
|
+
case "error":
|
|
313
|
+
return nothing;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* On a phone the actions sit two to a row and the dialog closes from the
|
|
319
|
+
* bottom one, in reach of a thumb; the corner close is for wider screens.
|
|
320
|
+
*/
|
|
321
|
+
#renderActions() {
|
|
322
|
+
if (this._status === "error") return nothing;
|
|
323
|
+
const ready = this._status === "ready";
|
|
324
|
+
return html`
|
|
325
|
+
<footer class="share-dialog-actions">
|
|
326
|
+
${
|
|
327
|
+
canShareImage()
|
|
328
|
+
? html`<button
|
|
329
|
+
type="button"
|
|
330
|
+
class="btn-outline"
|
|
331
|
+
?disabled=${!ready}
|
|
332
|
+
@click=${() => void this.#share()}
|
|
333
|
+
>
|
|
334
|
+
${icon(ICON_SHARE)} Share…
|
|
335
|
+
</button>`
|
|
336
|
+
: nothing
|
|
337
|
+
}
|
|
338
|
+
${
|
|
339
|
+
canCopyImage()
|
|
340
|
+
? html`<button
|
|
341
|
+
type="button"
|
|
342
|
+
class="btn-outline"
|
|
343
|
+
?disabled=${!ready}
|
|
344
|
+
@click=${() => void this.#copy()}
|
|
345
|
+
>
|
|
346
|
+
${icon(ICON_COPY)} Copy image
|
|
347
|
+
</button>`
|
|
348
|
+
: nothing
|
|
349
|
+
}
|
|
350
|
+
<button
|
|
351
|
+
type="button"
|
|
352
|
+
class="btn-outline share-dialog-close"
|
|
353
|
+
@click=${() => this.#close()}
|
|
354
|
+
>
|
|
355
|
+
${icon(ICON_CLOSE)} Close
|
|
356
|
+
</button>
|
|
357
|
+
<button
|
|
358
|
+
type="button"
|
|
359
|
+
class="btn"
|
|
360
|
+
?disabled=${!ready}
|
|
361
|
+
@click=${() => this.#download()}
|
|
362
|
+
>
|
|
363
|
+
${icon(ICON_DOWNLOAD)} Download
|
|
364
|
+
</button>
|
|
365
|
+
</footer>
|
|
366
|
+
`;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
render() {
|
|
370
|
+
if (!this._open) return nothing;
|
|
371
|
+
return html`
|
|
372
|
+
<dialog
|
|
373
|
+
class="dialog share-dialog"
|
|
374
|
+
@cancel=${(event: Event) => {
|
|
375
|
+
event.preventDefault();
|
|
376
|
+
this.#close();
|
|
377
|
+
}}
|
|
378
|
+
@keydown=${this.#handleKeydown}
|
|
379
|
+
@click=${(event: Event) => {
|
|
380
|
+
if ((event.target as HTMLElement).tagName === "DIALOG") this.#close();
|
|
381
|
+
}}
|
|
382
|
+
>
|
|
383
|
+
<div
|
|
384
|
+
class="share-dialog-panel"
|
|
385
|
+
tabindex="-1"
|
|
386
|
+
role="document"
|
|
387
|
+
aria-labelledby="share-dialog-title"
|
|
388
|
+
>
|
|
389
|
+
<header>
|
|
390
|
+
<h2 id="share-dialog-title">Share as image</h2>
|
|
391
|
+
</header>
|
|
392
|
+
<section class="share-dialog-preview" data-status=${this._status}>
|
|
393
|
+
${this.#renderPreview()}
|
|
394
|
+
</section>
|
|
395
|
+
<p class="share-dialog-note" aria-live="polite">
|
|
396
|
+
${this.#renderNote()}
|
|
397
|
+
</p>
|
|
398
|
+
${this.#renderActions()}
|
|
399
|
+
<button
|
|
400
|
+
type="button"
|
|
401
|
+
aria-label="Close"
|
|
402
|
+
@click=${() => this.#close()}
|
|
403
|
+
>
|
|
404
|
+
<svg
|
|
405
|
+
viewBox="0 0 24 24"
|
|
406
|
+
fill="none"
|
|
407
|
+
stroke="currentColor"
|
|
408
|
+
stroke-width="2"
|
|
409
|
+
stroke-linecap="round"
|
|
410
|
+
stroke-linejoin="round"
|
|
411
|
+
aria-hidden="true"
|
|
412
|
+
>
|
|
413
|
+
<path d="M18 6 6 18M6 6l12 12" />
|
|
414
|
+
</svg>
|
|
415
|
+
</button>
|
|
416
|
+
</div>
|
|
417
|
+
</dialog>
|
|
418
|
+
`;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
customElements.define("jant-share-dialog", JantShareDialog);
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Share Menu
|
|
3
|
+
*
|
|
4
|
+
* A reader's post menu: the "More" button in a post's footer on a page
|
|
5
|
+
* nobody is signed in to, with what a reader can do with a post — copy its
|
|
6
|
+
* link, or share it as an image. One element per page (`SiteLayout` mounts
|
|
7
|
+
* it), opened from any post's `[data-share-menu-trigger]`; the author's menu
|
|
8
|
+
* is `jant-post-menu`, and this one wears its classes so the two read as one
|
|
9
|
+
* control. Light DOM.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { LitElement, html, nothing } from "lit";
|
|
13
|
+
import {
|
|
14
|
+
copyPostLink,
|
|
15
|
+
iconImage,
|
|
16
|
+
iconLink,
|
|
17
|
+
menuOpensAbove,
|
|
18
|
+
} from "../post-menu-shared.js";
|
|
19
|
+
import { openShareImage, warmShareImage } from "../share-launch.js";
|
|
20
|
+
|
|
21
|
+
/** Two items, about 52 px each, inside the panel's padding. */
|
|
22
|
+
const ESTIMATED_MENU_HEIGHT = 130;
|
|
23
|
+
|
|
24
|
+
/** The post a menu is open for, from its article. */
|
|
25
|
+
interface SharedPost {
|
|
26
|
+
id: string;
|
|
27
|
+
permalink: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class JantShareMenu extends LitElement {
|
|
31
|
+
static properties = {
|
|
32
|
+
_post: { state: true },
|
|
33
|
+
_x: { state: true },
|
|
34
|
+
_y: { state: true },
|
|
35
|
+
_openAbove: { state: true },
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
declare _post: SharedPost | null;
|
|
39
|
+
declare _x: number;
|
|
40
|
+
declare _y: number;
|
|
41
|
+
declare _openAbove: boolean;
|
|
42
|
+
|
|
43
|
+
#trigger: HTMLElement | null = null;
|
|
44
|
+
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
|
+
this._post = null;
|
|
48
|
+
this._x = 0;
|
|
49
|
+
this._y = 0;
|
|
50
|
+
this._openAbove = false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
createRenderRoot() {
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
connectedCallback() {
|
|
58
|
+
super.connectedCallback();
|
|
59
|
+
document.addEventListener("click", this.#handleDocumentClick);
|
|
60
|
+
document.addEventListener("keydown", this.#handleKeydown);
|
|
61
|
+
window.addEventListener("resize", this.#place);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
disconnectedCallback() {
|
|
65
|
+
super.disconnectedCallback();
|
|
66
|
+
document.removeEventListener("click", this.#handleDocumentClick);
|
|
67
|
+
document.removeEventListener("keydown", this.#handleKeydown);
|
|
68
|
+
window.removeEventListener("resize", this.#place);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#handleDocumentClick = (event: Event) => {
|
|
72
|
+
const trigger = (event.target as globalThis.Element).closest?.<HTMLElement>(
|
|
73
|
+
"[data-share-menu-trigger]",
|
|
74
|
+
);
|
|
75
|
+
if (!trigger) return;
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
|
|
78
|
+
if (this._post && trigger === this.#trigger) {
|
|
79
|
+
this.#close();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const article = trigger.closest<HTMLElement>("article[data-post-id]");
|
|
84
|
+
const id = article?.dataset.postId;
|
|
85
|
+
const permalink = article?.dataset.postPermalink;
|
|
86
|
+
if (!id || !permalink) return;
|
|
87
|
+
|
|
88
|
+
this.#trigger?.setAttribute("aria-expanded", "false");
|
|
89
|
+
this.#trigger = trigger;
|
|
90
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
91
|
+
this._post = { id, permalink };
|
|
92
|
+
this.#place();
|
|
93
|
+
warmShareImage();
|
|
94
|
+
void this.updateComplete.then(() => {
|
|
95
|
+
this.querySelector<HTMLElement>("[role='menuitem']")?.focus();
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
#handleKeydown = (event: Event) => {
|
|
100
|
+
const key = event as globalThis.KeyboardEvent;
|
|
101
|
+
if (key.key !== "Escape" || !this._post) return;
|
|
102
|
+
key.preventDefault();
|
|
103
|
+
this.#close();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/** Right-aligned to the trigger, above it when there is no room below. */
|
|
107
|
+
#place = () => {
|
|
108
|
+
const trigger = this.#trigger;
|
|
109
|
+
if (!this._post || !trigger) return;
|
|
110
|
+
if (!trigger.isConnected) {
|
|
111
|
+
this.#close({ restoreFocus: false });
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const rect = trigger.getBoundingClientRect();
|
|
115
|
+
this._openAbove = menuOpensAbove(rect, ESTIMATED_MENU_HEIGHT);
|
|
116
|
+
this._x = window.scrollX + rect.right;
|
|
117
|
+
this._y =
|
|
118
|
+
window.scrollY + (this._openAbove ? rect.top - 6 : rect.bottom + 6);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
#close({ restoreFocus = true }: { restoreFocus?: boolean } = {}) {
|
|
122
|
+
const trigger = this.#trigger;
|
|
123
|
+
trigger?.setAttribute("aria-expanded", "false");
|
|
124
|
+
this.#trigger = null;
|
|
125
|
+
this._post = null;
|
|
126
|
+
if (restoreFocus) trigger?.focus();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#copyLink() {
|
|
130
|
+
const permalink = this._post?.permalink;
|
|
131
|
+
this.#close();
|
|
132
|
+
if (permalink) void copyPostLink(permalink);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#shareImage() {
|
|
136
|
+
const id = this._post?.id;
|
|
137
|
+
const trigger = this.#trigger;
|
|
138
|
+
// The dialog takes focus, and gives it back to the trigger on close.
|
|
139
|
+
this.#close({ restoreFocus: false });
|
|
140
|
+
if (id) void openShareImage(id, trigger);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
render() {
|
|
144
|
+
if (!this._post) return nothing;
|
|
145
|
+
const transform = this._openAbove
|
|
146
|
+
? "transform:translate(-100%, -100%);"
|
|
147
|
+
: "transform:translateX(-100%);";
|
|
148
|
+
const style = `position:absolute;z-index:100;left:${Math.round(this._x)}px;top:${Math.round(this._y)}px;${transform}`;
|
|
149
|
+
return html`
|
|
150
|
+
<div
|
|
151
|
+
class="post-menu-backdrop"
|
|
152
|
+
@click=${() => this.#close({ restoreFocus: false })}
|
|
153
|
+
></div>
|
|
154
|
+
<div class="dropdown-menu" style=${style}>
|
|
155
|
+
<div data-popover aria-hidden="false" class="!static post-menu-panel">
|
|
156
|
+
<div class="post-menu-view post-menu-main">
|
|
157
|
+
<div role="menu" class="post-menu-list">
|
|
158
|
+
<div class="post-menu-section">
|
|
159
|
+
<button
|
|
160
|
+
type="button"
|
|
161
|
+
role="menuitem"
|
|
162
|
+
class="post-menu-item"
|
|
163
|
+
data-share-menu-copy-link
|
|
164
|
+
@click=${() => this.#copyLink()}
|
|
165
|
+
>
|
|
166
|
+
<span class="post-menu-item-label">Copy link</span>
|
|
167
|
+
<span class="post-menu-item-trailing">${iconLink()}</span>
|
|
168
|
+
</button>
|
|
169
|
+
<button
|
|
170
|
+
type="button"
|
|
171
|
+
role="menuitem"
|
|
172
|
+
class="post-menu-item"
|
|
173
|
+
data-share-menu-share-image
|
|
174
|
+
@click=${() => this.#shareImage()}
|
|
175
|
+
>
|
|
176
|
+
<span class="post-menu-item-label">Share as image</span>
|
|
177
|
+
<span class="post-menu-item-trailing">${iconImage()}</span>
|
|
178
|
+
</button>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
customElements.define("jant-share-menu", JantShareMenu);
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
refreshPostPageView,
|
|
29
29
|
refreshTimelineThreadView,
|
|
30
30
|
} from "./post-refresh.js";
|
|
31
|
-
import { getJsonString, readJsonObject } from "./json.js";
|
|
31
|
+
import { getJsonString, readErrorMessage, readJsonObject } from "./json.js";
|
|
32
32
|
import { uploadViaSession } from "./upload-session.js";
|
|
33
33
|
import type { UploadSessionResult } from "./upload-session.js";
|
|
34
34
|
import { publicPath } from "./runtime-paths.js";
|
|
@@ -583,6 +583,66 @@ document.addEventListener("jant:files-selected", (e: Event) => {
|
|
|
583
583
|
}
|
|
584
584
|
});
|
|
585
585
|
|
|
586
|
+
// ── Posters for videos uploaded without one ─────────────────────────
|
|
587
|
+
|
|
588
|
+
/** Media this page has already tried to give a poster, so it tries once. */
|
|
589
|
+
const posterBackfills = new Set<string>();
|
|
590
|
+
|
|
591
|
+
interface MissingPoster {
|
|
592
|
+
clientId: string;
|
|
593
|
+
mediaId: string;
|
|
594
|
+
/** Where the clip is stored */
|
|
595
|
+
url: string;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Make a poster for an uploaded clip that has none, store it on the media,
|
|
600
|
+
* and show it on the attachment card. Nothing here is the author's doing, so
|
|
601
|
+
* a failure stays in the console: the clip keeps the frame readers' browsers
|
|
602
|
+
* draw for it.
|
|
603
|
+
*/
|
|
604
|
+
async function backfillVideoPoster(
|
|
605
|
+
item: MissingPoster,
|
|
606
|
+
editor: JantComposeEditor | null,
|
|
607
|
+
): Promise<void> {
|
|
608
|
+
try {
|
|
609
|
+
const poster = await VideoProcessor.extractPosterFromUrl(item.url);
|
|
610
|
+
if (!poster) return;
|
|
611
|
+
|
|
612
|
+
const response = await fetch(
|
|
613
|
+
publicPath(`/api/media/${item.mediaId}/poster`),
|
|
614
|
+
{
|
|
615
|
+
method: "PUT",
|
|
616
|
+
headers: { "Content-Type": poster.type || "image/webp" },
|
|
617
|
+
body: poster,
|
|
618
|
+
},
|
|
619
|
+
);
|
|
620
|
+
if (!response.ok) {
|
|
621
|
+
throw new Error(
|
|
622
|
+
await readErrorMessage(response, "Failed to upload poster"),
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
attachmentOwner(editor, item.clientId)?.updateAttachmentPoster(
|
|
626
|
+
item.clientId,
|
|
627
|
+
poster,
|
|
628
|
+
);
|
|
629
|
+
} catch (error) {
|
|
630
|
+
// eslint-disable-next-line no-console -- a background repair failing is silent by design; say so
|
|
631
|
+
console.warn("[jant] poster for an uploaded video failed", error);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
document.addEventListener("jant:video-posters-missing", (e: Event) => {
|
|
636
|
+
const event = e as CustomEvent<{ attachments: MissingPoster[] }>;
|
|
637
|
+
const editor = getComposeEditorFromEventTarget(event.target);
|
|
638
|
+
|
|
639
|
+
for (const item of event.detail.attachments) {
|
|
640
|
+
if (posterBackfills.has(item.mediaId)) continue;
|
|
641
|
+
posterBackfills.add(item.mediaId);
|
|
642
|
+
void backfillVideoPoster(item, editor);
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
|
|
586
646
|
// ── Submit handler ──────────────────────────────────────────────────
|
|
587
647
|
|
|
588
648
|
/** Build the JSON body for both create and update requests */
|
|
@@ -252,8 +252,14 @@ function reevaluateAutoplay(): void {
|
|
|
252
252
|
function scheduleReevaluate(): void {
|
|
253
253
|
if (reevaluateTimer !== null) {
|
|
254
254
|
globalThis.clearTimeout(reevaluateTimer);
|
|
255
|
+
reevaluateTimer = null;
|
|
255
256
|
}
|
|
256
257
|
|
|
258
|
+
// A page without a feed video has nothing to choose between, so it gets no
|
|
259
|
+
// timer: one set anyway would fire after the document is gone, which in
|
|
260
|
+
// the test runner's torn-down environment is a crash.
|
|
261
|
+
if (registeredVideos.size === 0) return;
|
|
262
|
+
|
|
257
263
|
reevaluateTimer = globalThis.setTimeout(
|
|
258
264
|
reevaluateAutoplay,
|
|
259
265
|
FEED_VIDEO_REEVALUATE_DEBOUNCE_MS,
|