@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
|
@@ -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,
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counts the Threads a reader reads in full in a list.
|
|
3
|
+
*
|
|
4
|
+
* A list page — the home feed, a collection, Featured, the archive's list —
|
|
5
|
+
* marks each item that shows a whole Thread with `data-view-unit`
|
|
6
|
+
* (`lib/list-views.ts`), and its view token names the same Threads. This
|
|
7
|
+
* script watches those items and, when the page is hidden (the reader leaves,
|
|
8
|
+
* switches tabs, locks the phone), posts the token back followed by the
|
|
9
|
+
* Threads read in full since the last report. The server counts each toward
|
|
10
|
+
* its Thread (`routes/view-confirm.ts`).
|
|
11
|
+
*
|
|
12
|
+
* A Thread is read in full once all of these hold:
|
|
13
|
+
*
|
|
14
|
+
* - nothing of it is folded: no clamped note, no capped thread context;
|
|
15
|
+
* - its top and its bottom have each been on screen, so all of it has passed
|
|
16
|
+
* through the screen;
|
|
17
|
+
* - in a media strip too wide for its column, every item has been wholly
|
|
18
|
+
* inside the strip, or shown in the lightbox;
|
|
19
|
+
* - it has been in front of the reader, with the page visible, as long as a
|
|
20
|
+
* fast reader takes to read it ({@link readingTimeMs}). In front is half
|
|
21
|
+
* of it on screen, or half the screen taken by it.
|
|
22
|
+
*
|
|
23
|
+
* A page load counts each Thread once. Following a link to one of a
|
|
24
|
+
* Thread's posts leaves the Thread to the page it opens, which counts it
|
|
25
|
+
* itself; a Thread already reported stays reported. Nothing is reported
|
|
26
|
+
* before the page view itself is confirmed (`view-confirm.ts`), and nothing
|
|
27
|
+
* about the reader is read or sent: the token and the Threads' ids are the
|
|
28
|
+
* whole report.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import {
|
|
32
|
+
MEDIA_LIGHTBOX_SHOW_EVENT,
|
|
33
|
+
type MediaLightboxShowDetail,
|
|
34
|
+
} from "./media-lightbox-events.js";
|
|
35
|
+
import { publicPath } from "./runtime-paths.js";
|
|
36
|
+
import { CONFIRM_PATH, deliver, isViewConfirmed } from "./view-confirm.js";
|
|
37
|
+
|
|
38
|
+
/** An average reader's pace in words a minute, for scripts that space words. */
|
|
39
|
+
export const LIST_VIEW_WORDS_PER_MINUTE = 250;
|
|
40
|
+
|
|
41
|
+
/** An average reader's pace in characters a minute, for Chinese, Japanese and Korean. */
|
|
42
|
+
export const LIST_VIEW_CJK_CHARACTERS_PER_MINUTE = 500;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* How much faster than average a reader may read and still count: the time
|
|
46
|
+
* asked for is the average's share of this. A reader who reads every word
|
|
47
|
+
* faster than this is missed; one who scrolls past is not counted.
|
|
48
|
+
*/
|
|
49
|
+
const FAST_READER_FACTOR = 2;
|
|
50
|
+
|
|
51
|
+
/** Added for each picture, video or attachment the Thread carries. */
|
|
52
|
+
const MEDIA_ITEM_MS = 1_000;
|
|
53
|
+
|
|
54
|
+
/** The least time a Thread must be in front of the reader. */
|
|
55
|
+
const MIN_READ_MS = 1_000;
|
|
56
|
+
|
|
57
|
+
/** How often the time in front is added up while a Thread is on screen. */
|
|
58
|
+
const TICK_MS = 500;
|
|
59
|
+
|
|
60
|
+
/** The most one tick may add: a machine waking from sleep adds nothing it slept. */
|
|
61
|
+
const MAX_TICK_MS = 1_000;
|
|
62
|
+
|
|
63
|
+
/** Rounding slack, in pixels, for an edge on the screen's edge. */
|
|
64
|
+
const EDGE_SLACK_PX = 2;
|
|
65
|
+
|
|
66
|
+
/** A thread context clipping less than this shows all of it (`thread-context.ts`). */
|
|
67
|
+
const CLIP_SLACK_PX = 8;
|
|
68
|
+
|
|
69
|
+
const CJK =
|
|
70
|
+
/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/gu;
|
|
71
|
+
const WORD = /[\p{L}\p{N}]/u;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* How long a Thread must be in front of the reader to count as read.
|
|
75
|
+
*
|
|
76
|
+
* @param text - The Thread's text
|
|
77
|
+
* @param mediaItems - Pictures, videos and attachments it carries
|
|
78
|
+
* @returns Milliseconds
|
|
79
|
+
* @example
|
|
80
|
+
* readingTimeMs("A short note with ten words in it, more or less.", 0); // 1200
|
|
81
|
+
*/
|
|
82
|
+
export function readingTimeMs(text: string, mediaItems: number): number {
|
|
83
|
+
const characters = text.match(CJK)?.length ?? 0;
|
|
84
|
+
const words = text
|
|
85
|
+
.replace(CJK, " ")
|
|
86
|
+
.split(/\s+/)
|
|
87
|
+
.filter((word) => WORD.test(word)).length;
|
|
88
|
+
const minutes =
|
|
89
|
+
words / LIST_VIEW_WORDS_PER_MINUTE +
|
|
90
|
+
characters / LIST_VIEW_CJK_CHARACTERS_PER_MINUTE;
|
|
91
|
+
const ms =
|
|
92
|
+
(minutes * 60_000) / FAST_READER_FACTOR + mediaItems * MEDIA_ITEM_MS;
|
|
93
|
+
return Math.max(MIN_READ_MS, Math.round(ms));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface Unit {
|
|
97
|
+
id: string;
|
|
98
|
+
element: HTMLElement;
|
|
99
|
+
requiredMs: number;
|
|
100
|
+
visibleMs: number;
|
|
101
|
+
topSeen: boolean;
|
|
102
|
+
/** The height the bottom was on screen at; `null` until then, or once the Thread grew. */
|
|
103
|
+
bottomSeenAt: number | null;
|
|
104
|
+
/** `left`: the reader followed a link to it, and its page counts it. */
|
|
105
|
+
state: "reading" | "read" | "sent" | "left";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** What a page's tracker exposes; the page itself needs none of it. */
|
|
109
|
+
export interface ListViewTracker {
|
|
110
|
+
/** Measure now: what is on screen, and for how long it has been. */
|
|
111
|
+
check(): void;
|
|
112
|
+
/** Send what has been read and not yet sent. */
|
|
113
|
+
report(): void;
|
|
114
|
+
/** The Threads read in full and not yet sent. */
|
|
115
|
+
pending(): string[];
|
|
116
|
+
/** Stop watching: no more measuring, no more reports. */
|
|
117
|
+
stop(): void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Watch the page's whole Threads, if the page has any and a token to report
|
|
122
|
+
* them with.
|
|
123
|
+
*
|
|
124
|
+
* @param doc - The document, the current one unless a test passes another
|
|
125
|
+
* @param options.now - Clock in milliseconds, for tests
|
|
126
|
+
* @param options.confirmed - Whether the page view is confirmed, for tests
|
|
127
|
+
* @returns The tracker, or `null` when there is nothing to watch
|
|
128
|
+
* @example
|
|
129
|
+
* trackListViews();
|
|
130
|
+
*/
|
|
131
|
+
export function trackListViews(
|
|
132
|
+
doc: globalThis.Document = document,
|
|
133
|
+
options: {
|
|
134
|
+
now?: () => number;
|
|
135
|
+
confirmed?: () => boolean;
|
|
136
|
+
} = {},
|
|
137
|
+
): ListViewTracker | null {
|
|
138
|
+
const token = doc
|
|
139
|
+
.querySelector<globalThis.HTMLMetaElement>('meta[name="jant-view"]')
|
|
140
|
+
?.getAttribute("content");
|
|
141
|
+
if (!token) return null;
|
|
142
|
+
if (navigator.webdriver) return null;
|
|
143
|
+
const now = options.now ?? Date.now;
|
|
144
|
+
const confirmed = options.confirmed ?? (() => isViewConfirmed(doc));
|
|
145
|
+
const view = doc.defaultView ?? window;
|
|
146
|
+
|
|
147
|
+
const units: Unit[] = [];
|
|
148
|
+
const byPath = new Map<string, Unit>();
|
|
149
|
+
for (const element of doc.querySelectorAll<HTMLElement>("[data-view-unit]")) {
|
|
150
|
+
const id = element.dataset.viewUnit;
|
|
151
|
+
if (!id || units.some((unit) => unit.id === id)) continue;
|
|
152
|
+
const media =
|
|
153
|
+
element.querySelectorAll("[data-media-gallery] > *").length +
|
|
154
|
+
element.querySelectorAll("[data-post-body] img").length;
|
|
155
|
+
const unit: Unit = {
|
|
156
|
+
id,
|
|
157
|
+
element,
|
|
158
|
+
requiredMs: readingTimeMs(element.textContent ?? "", media),
|
|
159
|
+
visibleMs: 0,
|
|
160
|
+
topSeen: false,
|
|
161
|
+
bottomSeenAt: null,
|
|
162
|
+
state: "reading",
|
|
163
|
+
};
|
|
164
|
+
units.push(unit);
|
|
165
|
+
for (const article of element.querySelectorAll<HTMLElement>(
|
|
166
|
+
"article[data-post-permalink]",
|
|
167
|
+
)) {
|
|
168
|
+
const path = pathOf(article.dataset.postPermalink, doc);
|
|
169
|
+
if (path) byPath.set(path, unit);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (units.length === 0) return null;
|
|
173
|
+
|
|
174
|
+
/** Strip items that have been wholly in view, in their strip or the lightbox. */
|
|
175
|
+
const seenItems = new WeakSet<globalThis.Element>();
|
|
176
|
+
|
|
177
|
+
const isFolded = (unit: Unit): boolean =>
|
|
178
|
+
unit.element.querySelector("[data-note-clamp]") !== null ||
|
|
179
|
+
[
|
|
180
|
+
...unit.element.querySelectorAll<HTMLElement>("[data-thread-context]"),
|
|
181
|
+
].some((shell) => shell.scrollHeight > shell.clientHeight + CLIP_SLACK_PX);
|
|
182
|
+
|
|
183
|
+
const strips = (unit: Unit): HTMLElement[] =>
|
|
184
|
+
[
|
|
185
|
+
...unit.element.querySelectorAll<HTMLElement>("[data-media-gallery]"),
|
|
186
|
+
].filter((strip) => strip.scrollWidth > strip.clientWidth + 1);
|
|
187
|
+
|
|
188
|
+
const markStripItems = (unit: Unit, viewportHeight: number): void => {
|
|
189
|
+
for (const strip of strips(unit)) {
|
|
190
|
+
const box = strip.getBoundingClientRect();
|
|
191
|
+
if (box.bottom <= 0 || box.top >= viewportHeight) continue;
|
|
192
|
+
for (const item of strip.children) {
|
|
193
|
+
const rect = item.getBoundingClientRect();
|
|
194
|
+
if (
|
|
195
|
+
rect.left >= box.left - EDGE_SLACK_PX &&
|
|
196
|
+
rect.right <= box.right + EDGE_SLACK_PX
|
|
197
|
+
) {
|
|
198
|
+
seenItems.add(item);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const isRead = (unit: Unit): boolean =>
|
|
205
|
+
unit.topSeen &&
|
|
206
|
+
unit.bottomSeenAt !== null &&
|
|
207
|
+
unit.visibleMs >= unit.requiredMs &&
|
|
208
|
+
!isFolded(unit) &&
|
|
209
|
+
strips(unit).every((strip) =>
|
|
210
|
+
[...strip.children].every((item) => seenItems.has(item)),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
let lastMeasured: number | null = null;
|
|
214
|
+
let timer: ReturnType<typeof setInterval> | null = null;
|
|
215
|
+
|
|
216
|
+
/** Update every Thread still being read; whether any is on screen. */
|
|
217
|
+
const measure = (): boolean => {
|
|
218
|
+
const at = now();
|
|
219
|
+
const elapsed =
|
|
220
|
+
lastMeasured === null ? 0 : Math.min(at - lastMeasured, MAX_TICK_MS);
|
|
221
|
+
lastMeasured = at;
|
|
222
|
+
const viewportHeight = view.innerHeight;
|
|
223
|
+
const visible = doc.visibilityState === "visible";
|
|
224
|
+
let onScreen = false;
|
|
225
|
+
|
|
226
|
+
for (const unit of units) {
|
|
227
|
+
if (unit.state !== "reading") continue;
|
|
228
|
+
const rect = unit.element.getBoundingClientRect();
|
|
229
|
+
if (rect.bottom <= 0 || rect.top >= viewportHeight) continue;
|
|
230
|
+
onScreen = true;
|
|
231
|
+
|
|
232
|
+
const onEdge = (y: number) =>
|
|
233
|
+
y >= -EDGE_SLACK_PX && y <= viewportHeight + EDGE_SLACK_PX;
|
|
234
|
+
if (onEdge(rect.top)) unit.topSeen = true;
|
|
235
|
+
// Unfolding grows the Thread downward: its new bottom has to be seen.
|
|
236
|
+
if (
|
|
237
|
+
unit.bottomSeenAt !== null &&
|
|
238
|
+
rect.height > unit.bottomSeenAt + EDGE_SLACK_PX
|
|
239
|
+
) {
|
|
240
|
+
unit.bottomSeenAt = null;
|
|
241
|
+
}
|
|
242
|
+
if (onEdge(rect.bottom)) unit.bottomSeenAt = rect.height;
|
|
243
|
+
markStripItems(unit, viewportHeight);
|
|
244
|
+
|
|
245
|
+
const shown =
|
|
246
|
+
Math.min(rect.bottom, viewportHeight) - Math.max(rect.top, 0);
|
|
247
|
+
if (visible && shown >= Math.min(rect.height, viewportHeight) / 2) {
|
|
248
|
+
unit.visibleMs += elapsed;
|
|
249
|
+
}
|
|
250
|
+
if (isRead(unit)) unit.state = "read";
|
|
251
|
+
}
|
|
252
|
+
return onScreen;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const stopTimer = (): void => {
|
|
256
|
+
if (timer !== null) clearInterval(timer);
|
|
257
|
+
timer = null;
|
|
258
|
+
lastMeasured = null;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const check = (): void => {
|
|
262
|
+
const onScreen = measure();
|
|
263
|
+
const reading = units.some((unit) => unit.state === "reading");
|
|
264
|
+
if (!onScreen || !reading || doc.visibilityState !== "visible") {
|
|
265
|
+
stopTimer();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (timer === null) timer = setInterval(check, TICK_MS);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const pending = (): string[] =>
|
|
272
|
+
units.filter((unit) => unit.state === "read").map((unit) => unit.id);
|
|
273
|
+
|
|
274
|
+
const report = (): void => {
|
|
275
|
+
if (!confirmed()) return;
|
|
276
|
+
const read = units.filter((unit) => unit.state === "read");
|
|
277
|
+
if (read.length === 0) return;
|
|
278
|
+
for (const unit of read) unit.state = "sent";
|
|
279
|
+
deliver(
|
|
280
|
+
publicPath(CONFIRM_PATH),
|
|
281
|
+
`${token}\n${read.map((unit) => unit.id).join(" ")}`,
|
|
282
|
+
);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
let frame = 0;
|
|
286
|
+
const schedule = (): void => {
|
|
287
|
+
if (frame !== 0) return;
|
|
288
|
+
frame = view.requestAnimationFrame(() => {
|
|
289
|
+
frame = 0;
|
|
290
|
+
check();
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// A link to one of a Thread's posts opens the page that counts it.
|
|
295
|
+
const onFollow = (event: MouseEvent): void => {
|
|
296
|
+
if (event.type === "click" ? event.defaultPrevented : event.button !== 1) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const target = event.target;
|
|
300
|
+
if (!(target instanceof view.Element)) return;
|
|
301
|
+
const link = target.closest<HTMLAnchorElement>("a[href]");
|
|
302
|
+
const path = link ? pathOf(link.getAttribute("href"), doc) : null;
|
|
303
|
+
const unit = path ? byPath.get(path) : undefined;
|
|
304
|
+
if (unit && (unit.state === "reading" || unit.state === "read")) {
|
|
305
|
+
unit.state = "left";
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const onLightbox = (event: Event): void => {
|
|
310
|
+
const { source, index } = (event as CustomEvent<MediaLightboxShowDetail>)
|
|
311
|
+
.detail;
|
|
312
|
+
const link = source?.querySelector(`[data-lightbox-index="${index}"]`);
|
|
313
|
+
// The strip's item is the child holding the link; a short video wraps it.
|
|
314
|
+
const item = link
|
|
315
|
+
? [...(source?.children ?? [])].find((child) => child.contains(link))
|
|
316
|
+
: undefined;
|
|
317
|
+
if (item) seenItems.add(item);
|
|
318
|
+
schedule();
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const listening = new AbortController();
|
|
322
|
+
const { signal } = listening;
|
|
323
|
+
doc.addEventListener("scroll", schedule, {
|
|
324
|
+
capture: true,
|
|
325
|
+
passive: true,
|
|
326
|
+
signal,
|
|
327
|
+
});
|
|
328
|
+
view.addEventListener("resize", schedule, { passive: true, signal });
|
|
329
|
+
doc.addEventListener("click", schedule, { signal });
|
|
330
|
+
doc.addEventListener(MEDIA_LIGHTBOX_SHOW_EVENT, onLightbox, { signal });
|
|
331
|
+
// On the window, after the document's own handlers: a click they turned
|
|
332
|
+
// into an in-place action (expanding a note) has its default prevented.
|
|
333
|
+
view.addEventListener("click", onFollow, { signal });
|
|
334
|
+
view.addEventListener("auxclick", onFollow, { signal });
|
|
335
|
+
doc.addEventListener(
|
|
336
|
+
"visibilitychange",
|
|
337
|
+
() => {
|
|
338
|
+
if (doc.visibilityState === "visible") {
|
|
339
|
+
check();
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
measure();
|
|
343
|
+
stopTimer();
|
|
344
|
+
report();
|
|
345
|
+
},
|
|
346
|
+
{ signal },
|
|
347
|
+
);
|
|
348
|
+
view.addEventListener("pagehide", report, { signal });
|
|
349
|
+
view.addEventListener("pageshow", check, { signal });
|
|
350
|
+
check();
|
|
351
|
+
|
|
352
|
+
const stop = (): void => {
|
|
353
|
+
listening.abort();
|
|
354
|
+
stopTimer();
|
|
355
|
+
if (frame !== 0) view.cancelAnimationFrame(frame);
|
|
356
|
+
frame = 0;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
return { check, report, pending, stop };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** A same-site address's path, or `null` for any other address. */
|
|
363
|
+
function pathOf(
|
|
364
|
+
href: string | null | undefined,
|
|
365
|
+
doc: globalThis.Document,
|
|
366
|
+
): string | null {
|
|
367
|
+
if (!href) return null;
|
|
368
|
+
try {
|
|
369
|
+
const url = new URL(href, doc.baseURI);
|
|
370
|
+
return url.origin === new URL(doc.baseURI).origin ? url.pathname : null;
|
|
371
|
+
} catch {
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (document.readyState === "loading") {
|
|
377
|
+
document.addEventListener("DOMContentLoaded", () => trackListViews(), {
|
|
378
|
+
once: true,
|
|
379
|
+
});
|
|
380
|
+
} else {
|
|
381
|
+
trackListViews();
|
|
382
|
+
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
export const MEDIA_LIGHTBOX_TOGGLE_EVENT = "jant:media-lightbox-toggle";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Fired on `document` each time the lightbox shows an item, on opening and on
|
|
5
|
+
* paging: the element it was opened from (a gallery's `[data-lightbox-group]`
|
|
6
|
+
* or a post body) and the item's index there.
|
|
7
|
+
*/
|
|
8
|
+
export const MEDIA_LIGHTBOX_SHOW_EVENT = "jant:media-lightbox-show";
|
|
9
|
+
|
|
10
|
+
export interface MediaLightboxShowDetail {
|
|
11
|
+
source: globalThis.Element | null;
|
|
12
|
+
index: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
3
15
|
export const MEDIA_VIDEO_PLAYBACK_INTENT_EVENT =
|
|
4
16
|
"jant:media-video-playback-intent";
|
|
5
17
|
|
|
@@ -49,6 +49,18 @@ export function publicPath(path: string): string {
|
|
|
49
49
|
return toPublicHref(path, sitePathPrefix());
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Where the page's static assets are served from: the site's own `_assets`
|
|
54
|
+
* directory, or the host `ASSET_BASE_URL` names.
|
|
55
|
+
*
|
|
56
|
+
* @returns Absolute URL of the asset base, ending in `/`
|
|
57
|
+
* @example
|
|
58
|
+
* assetBaseUrl().href; // "https://media.jant.me/_assets/" with a CDN
|
|
59
|
+
*/
|
|
60
|
+
export function assetBaseUrl(): URL {
|
|
61
|
+
return new URL(`${publicPath(ASSET_BASE_PATH)}/`, window.location.href);
|
|
62
|
+
}
|
|
63
|
+
|
|
52
64
|
/**
|
|
53
65
|
* Build a link to a target the caller knows exists once per language.
|
|
54
66
|
*
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { snapdom } from "@zumer/snapdom";
|
|
12
|
+
import { assetBaseUrl } from "./runtime-paths.js";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Tallest card, in CSS px: one 9:19.5 phone screen viewed at full width
|
|
@@ -133,6 +134,65 @@ function unusedFontFamilies(): string[] {
|
|
|
133
134
|
return [...declared].filter((family) => !used.has(family));
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
function isReadable(link: globalThis.HTMLLinkElement): boolean {
|
|
138
|
+
try {
|
|
139
|
+
return link.sheet?.cssRules != null;
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Fetch `url` as snapdom will, and again past the browser's cache if the
|
|
147
|
+
* cached copy fails.
|
|
148
|
+
*/
|
|
149
|
+
async function cacheReadableCopy(url: string): Promise<void> {
|
|
150
|
+
const read = async (cache: "default" | "reload"): Promise<boolean> => {
|
|
151
|
+
try {
|
|
152
|
+
// snapdom fetches another origin without credentials.
|
|
153
|
+
const response = await fetch(url, { credentials: "omit", cache });
|
|
154
|
+
// The cache keeps the copy once its body has been read.
|
|
155
|
+
await response.blob();
|
|
156
|
+
return response.ok;
|
|
157
|
+
} catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
if (!(await read("default"))) await read("reload");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Let snapdom read the page's stylesheets on the asset host, and name the
|
|
166
|
+
* host for its `fontStylesheetDomains`.
|
|
167
|
+
*
|
|
168
|
+
* snapdom embeds a web font only from a stylesheet on the page's origin, or
|
|
169
|
+
* one it may fetch from a host it is told about. The font themes' faces are
|
|
170
|
+
* in `client.css`, which `ASSET_BASE_URL` puts on another origin. Left out,
|
|
171
|
+
* the picture paints in a local font while the card was laid out in the web
|
|
172
|
+
* font: lines break in other places and a gap opens under the title.
|
|
173
|
+
*
|
|
174
|
+
* snapdom's fetch reads the browser's cache, and the copy there came from
|
|
175
|
+
* the page's own link, made without CORS. An asset host like R2 sends
|
|
176
|
+
* `Access-Control-Allow-Origin` only to a request that carries an `Origin`,
|
|
177
|
+
* so Chromium fails a CORS read of that copy. A sheet whose copy fails is
|
|
178
|
+
* fetched again past the cache, which replaces it.
|
|
179
|
+
*
|
|
180
|
+
* @returns The asset host, or none when assets share the page's origin
|
|
181
|
+
*/
|
|
182
|
+
async function readableAssetStylesheets(): Promise<string[]> {
|
|
183
|
+
const base = assetBaseUrl();
|
|
184
|
+
if (base.origin === window.location.origin) return [];
|
|
185
|
+
const links = document.querySelectorAll<globalThis.HTMLLinkElement>(
|
|
186
|
+
'link[rel~="stylesheet"]',
|
|
187
|
+
);
|
|
188
|
+
await Promise.all(
|
|
189
|
+
Array.from(links)
|
|
190
|
+
.filter((link) => link.href.startsWith(base.href) && !isReadable(link))
|
|
191
|
+
.map((link) => cacheReadableCopy(link.href)),
|
|
192
|
+
);
|
|
193
|
+
return [base.host];
|
|
194
|
+
}
|
|
195
|
+
|
|
136
196
|
/** Fonts the card uses, then every image in it, decoded. */
|
|
137
197
|
async function settle(card: HTMLElement): Promise<void> {
|
|
138
198
|
void card.offsetHeight;
|
|
@@ -383,6 +443,8 @@ export async function prepareShareCard(
|
|
|
383
443
|
host.innerHTML = cardHtml;
|
|
384
444
|
document.body.appendChild(host);
|
|
385
445
|
const dispose = () => host.remove();
|
|
446
|
+
// Alongside the layout; only the painting needs it.
|
|
447
|
+
const fontStylesheetDomains = readableAssetStylesheets();
|
|
386
448
|
try {
|
|
387
449
|
const card = host.querySelector<HTMLElement>("[data-share-card]");
|
|
388
450
|
if (!card) throw new Error("The share card is missing.");
|
|
@@ -405,6 +467,7 @@ export async function prepareShareCard(
|
|
|
405
467
|
dpr: 1,
|
|
406
468
|
reconcile: true,
|
|
407
469
|
excludeFonts: { families: excludedFamilies },
|
|
470
|
+
fontStylesheetDomains: await fontStylesheetDomains,
|
|
408
471
|
});
|
|
409
472
|
return capture.toCanvas();
|
|
410
473
|
}),
|
|
@@ -22,34 +22,61 @@ async function fetchShareCard(postId: string): Promise<string> {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
let styles: Promise<void> | undefined;
|
|
25
|
+
let stylesFailed = false;
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Link the share stylesheet, which `<html data-share-stylesheet>` names, and
|
|
28
29
|
* resolve once it has loaded. A load that fails is forgotten, so the next
|
|
29
|
-
* call links it again.
|
|
30
|
+
* call links it again, after fetching it past the browser's cache.
|
|
31
|
+
*
|
|
32
|
+
* Linked with CORS, so the page can read its rules when `ASSET_BASE_URL`
|
|
33
|
+
* puts it on another origin. snapdom paints a `::before` or `::after` only
|
|
34
|
+
* when a stylesheet it can read has one, and the card's are all in this
|
|
35
|
+
* sheet: read none, and the picture loses the fade where the summary stops,
|
|
36
|
+
* the Thread's rail, and the dash before a source. The asset host already
|
|
37
|
+
* answers with CORS, which the module scripts beside this sheet need.
|
|
38
|
+
*
|
|
39
|
+
* The fetch on a retry is for a copy cached without CORS. An asset host like
|
|
40
|
+
* R2 sends `Access-Control-Allow-Origin` only to a request that carries an
|
|
41
|
+
* `Origin`, without `Vary: Origin`, and the sheet is cached as immutable. A
|
|
42
|
+
* browser that once linked it without CORS, as Jant did before, keeps a copy
|
|
43
|
+
* Chromium will not hand to a CORS request, and every load fails until the
|
|
44
|
+
* fetch replaces that copy with one that carries the header.
|
|
30
45
|
*/
|
|
31
46
|
function ensureShareStyles(): Promise<void> {
|
|
32
|
-
return (styles ??=
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
47
|
+
return (styles ??= loadShareStyles().catch((error: unknown) => {
|
|
48
|
+
styles = undefined;
|
|
49
|
+
stylesFailed = true;
|
|
50
|
+
throw error;
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function loadShareStyles(): Promise<void> {
|
|
55
|
+
const href = document.documentElement.dataset.shareStylesheet;
|
|
56
|
+
if (!href) return;
|
|
57
|
+
// The cache keeps the new copy once its body has been read. A failure here
|
|
58
|
+
// leaves the link below to fail and report it.
|
|
59
|
+
if (stylesFailed) {
|
|
60
|
+
await fetch(href, { cache: "reload" })
|
|
61
|
+
.then((response) => response.blob())
|
|
62
|
+
.catch(() => {});
|
|
63
|
+
}
|
|
64
|
+
await new Promise<void>((resolve, reject) => {
|
|
38
65
|
const link = document.createElement("link");
|
|
39
66
|
link.rel = "stylesheet";
|
|
67
|
+
link.crossOrigin = "anonymous";
|
|
40
68
|
link.href = href;
|
|
41
69
|
link.addEventListener("load", () => resolve(), { once: true });
|
|
42
70
|
link.addEventListener(
|
|
43
71
|
"error",
|
|
44
72
|
() => {
|
|
45
73
|
link.remove();
|
|
46
|
-
styles = undefined;
|
|
47
74
|
reject(new Error(`Could not load ${href}`));
|
|
48
75
|
},
|
|
49
76
|
{ once: true },
|
|
50
77
|
);
|
|
51
78
|
document.head.appendChild(link);
|
|
52
|
-
})
|
|
79
|
+
});
|
|
53
80
|
}
|
|
54
81
|
|
|
55
82
|
/** Wait for the bundle and the stylesheet, and return what failed. */
|