@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.
Files changed (148) hide show
  1. package/bin/lib/site-snapshot.js +10 -0
  2. package/dist/{app-Gt7_skt6.js → app-CbOZ2Irh.js} +8704 -5180
  3. package/dist/client/.vite/manifest.json +125 -85
  4. package/dist/client/_assets/chunks/{confirm-D7GrwsCN.js → confirm-CMe01lne.js} +1 -1
  5. package/dist/client/_assets/chunks/{create-editor-5Y49x7h5.js → create-editor-hWapNE40.js} +26 -26
  6. package/dist/client/_assets/chunks/footnote-rail-9zwl6jtV.js +2 -0
  7. package/dist/client/_assets/chunks/{jant-locale-picker-DL6mIOT5.js → jant-locale-picker-2L4rkDaz.js} +1 -1
  8. package/dist/client/_assets/chunks/lit-Bw_voPoW.js +2 -0
  9. package/dist/client/_assets/chunks/preload-helper-Czpn1I53.js +1 -0
  10. package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +1 -0
  11. package/dist/client/_assets/chunks/{settings-paths-h6RjIe3C.js → settings-paths-BBVT8zKj.js} +1 -1
  12. package/dist/client/_assets/chunks/slug-format-BuCPjSrB.js +1 -0
  13. package/dist/client/_assets/chunks/sortable-list-DJXwkaOv.js +2 -0
  14. package/dist/client/_assets/chunks/types-DrYFqJH2.js +1 -0
  15. package/dist/client/_assets/chunks/{unsafe-html-B5ZEXaxg.js → unsafe-html-CWos3v6N.js} +1 -1
  16. package/dist/client/_assets/chunks/unsafe-svg-CUrgo4Xg.js +1 -0
  17. package/dist/client/_assets/client-BO8GOFfT.js +354 -0
  18. package/dist/client/_assets/client-D8Rrsd73.css +2 -0
  19. package/dist/client/_assets/client-auth-CsUGM718.js +859 -0
  20. package/dist/client/_assets/client-author-QPm1whbO.css +2 -0
  21. package/dist/client/_assets/client-compose-BB4U7Wz0.js +2004 -0
  22. package/dist/client/_assets/{client-manage-C1eDB1Rc.js → client-manage-CI9-eh-8.js} +176 -176
  23. package/dist/client/_assets/{client-settings-DIM44Zqh.js → client-settings-BnGPuqwc.js} +166 -166
  24. package/dist/client/_assets/client-share-0DICJjAc.css +1 -0
  25. package/dist/client/_assets/client-share-C59mOLJ1.js +149 -0
  26. package/dist/index.js +1 -1
  27. package/dist/node.js +3 -2
  28. package/package.json +2 -1
  29. package/src/app.tsx +9 -0
  30. package/src/client/components/compose-types.ts +1 -0
  31. package/src/client/components/jant-compose-dialog.ts +1 -0
  32. package/src/client/components/jant-compose-editor.ts +30 -0
  33. package/src/client/components/jant-compose-fullscreen.ts +1 -0
  34. package/src/client/components/jant-post-menu.ts +80 -13
  35. package/src/client/components/jant-share-dialog.ts +422 -0
  36. package/src/client/components/jant-share-menu.ts +188 -0
  37. package/src/client/compose-bridge.ts +61 -1
  38. package/src/client/feed-video-player.ts +6 -0
  39. package/src/client/lazy-entries.ts +21 -1
  40. package/src/client/post-menu-shared.ts +100 -0
  41. package/src/client/share-capture.ts +443 -0
  42. package/src/client/share-launch.ts +133 -0
  43. package/src/client/tiptap/bubble-menu.ts +25 -2
  44. package/src/client/tiptap/create-editor.ts +2 -0
  45. package/src/client/tiptap/extensions.ts +4 -0
  46. package/src/client/video-processor.ts +106 -52
  47. package/src/client/view-confirm.ts +108 -0
  48. package/src/client-share.ts +8 -0
  49. package/src/client.ts +2 -0
  50. package/src/db/migrations/0035_brainy_next_avengers.sql +9 -0
  51. package/src/db/migrations/0036_gorgeous_smasher.sql +7 -0
  52. package/src/db/migrations/meta/0035_snapshot.json +2877 -0
  53. package/src/db/migrations/meta/0036_snapshot.json +2924 -0
  54. package/src/db/migrations/meta/_journal.json +14 -0
  55. package/src/db/migrations/pg/0033_cute_magdalene.sql +10 -0
  56. package/src/db/migrations/pg/0034_material_agent_brand.sql +8 -0
  57. package/src/db/migrations/pg/meta/0033_snapshot.json +3719 -0
  58. package/src/db/migrations/pg/meta/0034_snapshot.json +3766 -0
  59. package/src/db/migrations/pg/meta/_journal.json +14 -0
  60. package/src/db/pg/schema.ts +40 -0
  61. package/src/db/schema.ts +61 -0
  62. package/src/i18n/locales/public/en.po +5 -0
  63. package/src/i18n/locales/public/en.ts +1 -1
  64. package/src/i18n/locales/public/zh-Hans.po +5 -0
  65. package/src/i18n/locales/public/zh-Hans.ts +1 -1
  66. package/src/i18n/locales/public/zh-Hant.po +5 -0
  67. package/src/i18n/locales/public/zh-Hant.ts +1 -1
  68. package/src/i18n/locales/settings/en.po +149 -0
  69. package/src/i18n/locales/settings/en.ts +1 -1
  70. package/src/i18n/locales/settings/zh-Hans.po +149 -0
  71. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  72. package/src/i18n/locales/settings/zh-Hant.po +149 -0
  73. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  74. package/src/lib/discover.ts +31 -0
  75. package/src/lib/env.ts +20 -0
  76. package/src/lib/github-app-state.ts +1 -1
  77. package/src/lib/github-app.ts +183 -1
  78. package/src/lib/markdown-manager.ts +129 -1
  79. package/src/lib/post-meta.ts +13 -3
  80. package/src/lib/referrer-aliases.ts +311 -0
  81. package/src/lib/render.tsx +10 -0
  82. package/src/lib/resolve-config.ts +14 -0
  83. package/src/lib/share-card.ts +653 -0
  84. package/src/lib/summary.ts +152 -54
  85. package/src/lib/tiptap-render.ts +1 -0
  86. package/src/lib/upload.ts +21 -1
  87. package/src/lib/version.ts +2 -0
  88. package/src/lib/video-playback.ts +55 -0
  89. package/src/lib/view-buffer.ts +201 -0
  90. package/src/lib/view-counting.ts +539 -0
  91. package/src/lib/view-token.ts +177 -0
  92. package/src/lib/view.ts +13 -1
  93. package/src/middleware/view-counter.ts +140 -0
  94. package/src/node/runtime.ts +4 -0
  95. package/src/preset.css +31 -14
  96. package/src/routes/api/media.ts +21 -3
  97. package/src/routes/auth/setup.tsx +37 -1
  98. package/src/routes/dash/settings.tsx +433 -168
  99. package/src/routes/pages/archive.tsx +1 -0
  100. package/src/routes/pages/collection.tsx +6 -0
  101. package/src/routes/pages/collections.tsx +1 -0
  102. package/src/routes/pages/featured.tsx +1 -0
  103. package/src/routes/pages/home.tsx +1 -0
  104. package/src/routes/pages/page.tsx +3 -0
  105. package/src/routes/pages/partials.tsx +23 -0
  106. package/src/routes/pages/smart-collection.tsx +2 -0
  107. package/src/routes/pages/subscribe.tsx +1 -0
  108. package/src/routes/view-confirm.ts +63 -0
  109. package/src/services/export-theme/assets/client-site.js +1 -1
  110. package/src/services/export-theme/styles/main.css +39 -21
  111. package/src/services/export.ts +2 -0
  112. package/src/services/index.ts +17 -0
  113. package/src/services/mcp.ts +31 -1
  114. package/src/services/media.ts +63 -0
  115. package/src/services/stats.ts +1130 -0
  116. package/src/style-share.css +16 -0
  117. package/src/styles/components-author.css +177 -0
  118. package/src/styles/components.css +25 -3
  119. package/src/styles/share.css +1103 -0
  120. package/src/styles/tokens.css +65 -30
  121. package/src/styles/ui.css +62 -13
  122. package/src/types/app-context.ts +9 -0
  123. package/src/types/bindings.ts +5 -0
  124. package/src/types/config.ts +54 -0
  125. package/src/types/views.ts +6 -0
  126. package/src/ui/compose/ComposeDialog.tsx +6 -0
  127. package/src/ui/dash/settings/SettingsRootContent.tsx +24 -6
  128. package/src/ui/dash/settings/StatsContent.tsx +855 -0
  129. package/src/ui/font-themes.ts +39 -6
  130. package/src/ui/layouts/BaseLayout.tsx +11 -2
  131. package/src/ui/layouts/SiteLayout.tsx +9 -3
  132. package/src/ui/share/ShareCard.tsx +298 -0
  133. package/src/ui/shared/Icon.tsx +23 -3
  134. package/src/ui/shared/MediaGallery.tsx +31 -4
  135. package/src/ui/shared/PostFooter.tsx +20 -4
  136. package/src/ui/shared/icon-collector.ts +28 -0
  137. package/src/ui/shared/post-article-attributes.ts +3 -0
  138. package/dist/client/_assets/chunks/footnote-rail-BJwswtVQ.js +0 -1
  139. package/dist/client/_assets/chunks/lit-DW8VmJAT.js +0 -2
  140. package/dist/client/_assets/chunks/slug-format-Dsi0e9Xn.js +0 -1
  141. package/dist/client/_assets/chunks/sortable-list-DWNKv782.js +0 -2
  142. package/dist/client/_assets/chunks/types-D5iF3H1a.js +0 -1
  143. package/dist/client/_assets/chunks/unsafe-svg-DTZZEvLU.js +0 -2
  144. package/dist/client/_assets/client-BaqmpPQ-.css +0 -2
  145. package/dist/client/_assets/client-C6melOtG.js +0 -296
  146. package/dist/client/_assets/client-auth-Ccq8kSqq.js +0 -828
  147. package/dist/client/_assets/client-author-CGVvrNZ8.css +0 -2
  148. package/dist/client/_assets/client-compose-oxzPb3SS.js +0 -2004
@@ -33,12 +33,20 @@ export interface FontTheme {
33
33
  description: MessageDescriptor;
34
34
  }
35
35
 
36
+ /*
37
+ * Serif stacks lead on the system face with real weights, then the vendored
38
+ * Noto Serif (loaded by the profile stylesheet) and its installed siblings,
39
+ * and only then SimSun / PMingLiU. Those two ship one weight: a heading set
40
+ * in them is synthetic bold, smeared at every size, which is what every
41
+ * Windows reader of a serif-headed site used to get because they sat ahead
42
+ * of the face the site ships.
43
+ */
36
44
  const HANS_CJK_SERIF_FALLBACK =
37
- '"Songti SC", STSong, SimSun, "Noto Serif SC", "Noto Serif CJK SC", "Songti TC", PMingLiU, MingLiU, "Noto Serif TC", "Noto Serif CJK TC"';
45
+ '"Songti SC", "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", STSong, SimSun, "Songti TC", "Noto Serif TC", "Noto Serif CJK TC", "Source Han Serif TC", PMingLiU, MingLiU';
38
46
  const HANS_CJK_SANS_FALLBACK =
39
47
  '"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", "PingFang TC", "Hiragino Sans CNS", "Microsoft JhengHei", "Noto Sans TC", "Noto Sans CJK TC"';
40
48
  const HANT_CJK_SERIF_FALLBACK =
41
- '"Songti TC", PMingLiU, MingLiU, "Noto Serif TC", "Noto Serif CJK TC", "Songti SC", STSong, SimSun, "Noto Serif SC", "Noto Serif CJK SC"';
49
+ '"Songti TC", "Noto Serif TC", "Noto Serif CJK TC", "Source Han Serif TC", PMingLiU, MingLiU, "Songti SC", "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", STSong, SimSun';
42
50
  const HANT_CJK_SANS_FALLBACK =
43
51
  '"PingFang TC", "Hiragino Sans CNS", "Microsoft JhengHei", "Noto Sans TC", "Noto Sans CJK TC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC"';
44
52
  const JP_CJK_SERIF_FALLBACK =
@@ -148,18 +156,33 @@ export function resolveCjkFontProfile(
148
156
  return language ? getCjkFontFromLanguageTag(language) : undefined;
149
157
  }
150
158
 
159
+ /*
160
+ * Reading rhythm for a CJK page. Han, kana and hangul glyphs fill the em box
161
+ * where Latin lowercase sits at the x-height, so the Latin leadings in
162
+ * tokens.css pack CJK lines visibly tighter: 1.7 reads as 1.5 does in Latin.
163
+ * The surfaces Chinese readers hold up as well set — sspai, WeChat articles —
164
+ * run 1.75 to 1.8, and a multi-line Chinese title at 1.2 has its rows touching.
165
+ */
166
+ const CJK_READING_RHYTHM = {
167
+ "--type-body-leading": "1.75",
168
+ "--type-heading-leading": "1.3",
169
+ };
170
+
151
171
  /**
152
- * Build serif and sans fallback variables for the resolved language profile.
172
+ * Build the CSS variables a page in a CJK language needs: the serif and sans
173
+ * fallback stacks for its script, and the reading rhythm its glyphs call for.
153
174
  *
154
175
  * Empty for a language with no profile: `tokens.css` already carries a real
155
- * script-neutral stack in both variables, so there is nothing to override.
176
+ * script-neutral stack in both variables and the Latin leadings, so there is
177
+ * nothing to override. `BaseLayout` writes these on `:root` ahead of the theme
178
+ * style, so a font theme or custom CSS that sets a leading still wins.
156
179
  *
157
180
  * @param language - BCP 47 content language tag
158
181
  * @returns CSS variables consumed by every font theme, empty when the token
159
182
  * defaults already apply
160
183
  * @example
161
184
  * getCjkFontCssVariables("zh-Hans")
162
- * // => { "--font-cjk-serif-fallback": '"Songti SC", ...', ... }
185
+ * // => { "--font-cjk-serif-fallback": '"Songti SC", ...', ..., "--type-body-leading": "1.8", ... }
163
186
  */
164
187
  export function getCjkFontCssVariables(
165
188
  language?: string,
@@ -169,21 +192,25 @@ export function getCjkFontCssVariables(
169
192
  return {
170
193
  "--font-cjk-serif-fallback": HANS_CJK_SERIF_FALLBACK,
171
194
  "--font-cjk-sans-fallback": HANS_CJK_SANS_FALLBACK,
195
+ ...CJK_READING_RHYTHM,
172
196
  };
173
197
  case "zh-Hant":
174
198
  return {
175
199
  "--font-cjk-serif-fallback": HANT_CJK_SERIF_FALLBACK,
176
200
  "--font-cjk-sans-fallback": HANT_CJK_SANS_FALLBACK,
201
+ ...CJK_READING_RHYTHM,
177
202
  };
178
203
  case "ja":
179
204
  return {
180
205
  "--font-cjk-serif-fallback": JP_CJK_SERIF_FALLBACK,
181
206
  "--font-cjk-sans-fallback": JP_CJK_SANS_FALLBACK,
207
+ ...CJK_READING_RHYTHM,
182
208
  };
183
209
  case "ko":
184
210
  return {
185
211
  "--font-cjk-serif-fallback": KO_CJK_SERIF_FALLBACK,
186
212
  "--font-cjk-sans-fallback": KO_CJK_SANS_FALLBACK,
213
+ ...CJK_READING_RHYTHM,
187
214
  };
188
215
  default:
189
216
  return {};
@@ -227,7 +254,13 @@ export const BUILTIN_FONT_THEMES: FontTheme[] = [
227
254
  },
228
255
  headingFontFamily: TUFTE_SERIF,
229
256
  bodyFontFamily: TUFTE_SERIF,
230
- cssVariables: {},
257
+ cssVariables: {
258
+ // Tufte CSS sets its headings in the regular weight and lets size and
259
+ // space carry the hierarchy; the semibold default would hand it
260
+ // Palatino Bold.
261
+ "--type-heading-weight": "var(--fw-regular)",
262
+ "--type-display-weight": "var(--fw-regular)",
263
+ },
231
264
  description: {
232
265
  id: "Palatino-based old-style serif matching Tufte CSS proportions",
233
266
  message: "Palatino-based old-style serif matching Tufte CSS proportions",
@@ -36,6 +36,7 @@ import {
36
36
  CLIENT_CJK_TC_CSS_FILE,
37
37
  CLIENT_CSS_FILE,
38
38
  CLIENT_JS_FILE,
39
+ CLIENT_SHARE_CSS_FILE,
39
40
  CORE_VERSION,
40
41
  } from "../../lib/version.js";
41
42
  import { IS_VITE_DEV } from "../../lib/build-env.js";
@@ -288,6 +289,11 @@ export const BaseLayout: FC<PropsWithChildren<BaseLayoutProps>> = ({
288
289
  ? assetPath("/src/style-author.css")
289
290
  : toPublicAssetPath(CLIENT_AUTHOR_CSS_FILE, assetBasePath)
290
291
  : null;
292
+ // "Share as image" is rare enough to stay off every page's critical path:
293
+ // the post menu links this when it opens, for a reader or the author.
294
+ const shareStylesheetPath = IS_VITE_DEV
295
+ ? assetPath("/src/style-share.css")
296
+ : toPublicAssetPath(CLIENT_SHARE_CSS_FILE, assetBasePath);
291
297
  const clientScriptPath = IS_VITE_DEV
292
298
  ? resolvedClientBundle === "full"
293
299
  ? assetPath("/src/client-auth.ts")
@@ -402,6 +408,7 @@ export const BaseLayout: FC<PropsWithChildren<BaseLayoutProps>> = ({
402
408
  data-view-lang={viewLang ?? undefined}
403
409
  data-asset-base-path={assetBasePath}
404
410
  data-media-base={mediaBase}
411
+ data-share-stylesheet={shareStylesheetPath}
405
412
  >
406
413
  <head>
407
414
  <meta charset="UTF-8" />
@@ -580,10 +587,12 @@ export const BaseLayout: FC<PropsWithChildren<BaseLayoutProps>> = ({
580
587
  <link rel="stylesheet" href={authorStylesheetPath} />
581
588
  )}
582
589
  {/* Critical inline style: prevent mobile nav jitter by applying
583
- responsive header layout before external CSS/JS loads */}
590
+ responsive header layout before external CSS/JS loads. The nav
591
+ tiers query the header's width, as in ui.css, so the container
592
+ is declared here too. */}
584
593
  <style
585
594
  dangerouslySetInnerHTML={{
586
- __html: `.site-header-search-link,.site-header-hamburger,.site-header-more-responsive-only,.site-header-more-link-responsive,.site-header-more-divider-responsive{display:none!important}@media(max-width:1200px){.site-header-search-form{display:none!important}.site-header-search-link{display:inline-flex!important}}@media(max-width:960px){.site-header-link-collapse-lg{display:none!important}.site-header-more-responsive-only.site-header-more-tier-lg{display:inline-flex!important}.site-header-more-link-show-lg{display:flex!important}.site-header-more-divider-show-lg{display:block!important}}@media(max-width:780px){.site-header-link-collapse-md{display:none!important}.site-header-more-responsive-only.site-header-more-tier-md{display:inline-flex!important}.site-header-more-link-show-md{display:flex!important}.site-header-more-divider-show-md{display:block!important}}@media(max-width:580px){.site-header-link-collapse-sm{display:none!important}.site-header-more-responsive-only.site-header-more-tier-sm{display:inline-flex!important}.site-header-more-link-show-sm{display:flex!important}.site-header-more-divider-show-sm{display:block!important}}@media(max-width:480px){.site-header-nav,.site-header-more{display:none!important}.site-header-search-slot{display:flex!important}.site-header-hamburger{display:flex!important}.site-header-right{margin-left:.35rem}}`,
595
+ __html: `.site-header{container:site-header/inline-size}.site-header-search-link,.site-header-hamburger,.site-header-more-responsive-only,.site-header-more-link-responsive,.site-header-more-divider-responsive{display:none!important}@media(max-width:1200px){.site-header-search-form{display:none!important}.site-header-search-link{display:inline-flex!important}}@container site-header (width<802px){.site-header-link-collapse-lg{display:none!important}.site-header-more-responsive-only.site-header-more-tier-lg{display:inline-flex!important}.site-header-more-link-show-lg{display:flex!important}.site-header-more-divider-show-lg{display:block!important}}@container site-header (width<652px){.site-header-link-collapse-md{display:none!important}.site-header-more-responsive-only.site-header-more-tier-md{display:inline-flex!important}.site-header-more-link-show-md{display:flex!important}.site-header-more-divider-show-md{display:block!important}}@container site-header (width<522px){.site-header-link-collapse-sm{display:none!important}.site-header-more-responsive-only.site-header-more-tier-sm{display:inline-flex!important}.site-header-more-link-show-sm{display:flex!important}.site-header-more-divider-show-sm{display:block!important}}@media(max-width:480px){.site-header-nav,.site-header-more{display:none!important}.site-header-search-slot{display:flex!important}.site-header-hamburger{display:flex!important}.site-header-right{margin-left:.35rem}}`,
587
596
  }}
588
597
  />
589
598
  {/* Emitted before the theme style so a font theme that names its own
@@ -634,6 +634,7 @@ export const SiteLayout: FC<PropsWithChildren<SiteLayoutProps>> = ({
634
634
  siteFooterHtml,
635
635
  showHomeBranding = false,
636
636
  sidebar,
637
+ wideFrame = false,
637
638
  uploadMaxFileSize,
638
639
  showComposeDialog = true,
639
640
  showHeader = true,
@@ -666,9 +667,13 @@ export const SiteLayout: FC<PropsWithChildren<SiteLayoutProps>> = ({
666
667
  .join(" ");
667
668
  // The page, not the content, keeps room for the button: the footer and the
668
669
  // Jant credit come after the content, and they must end above it too.
669
- const pageClass = showMobileComposeFab
670
- ? "site-page site-page-mobile-compose-enabled"
671
- : "site-page";
670
+ const pageClass = [
671
+ "site-page",
672
+ showMobileComposeFab ? "site-page-mobile-compose-enabled" : "",
673
+ wideFrame ? "site-page-wide" : "",
674
+ ]
675
+ .filter(Boolean)
676
+ .join(" ");
672
677
 
673
678
  return (
674
679
  <div class={pageClass}>
@@ -751,6 +756,7 @@ export const SiteLayout: FC<PropsWithChildren<SiteLayoutProps>> = ({
751
756
 
752
757
  <jant-media-lightbox />
753
758
  <jant-text-preview />
759
+ {!isAuthenticated && <jant-share-menu />}
754
760
  {isAuthenticated && (
755
761
  <jant-post-menu
756
762
  languages={JSON.stringify(composeLanguages ?? []).replace(
@@ -0,0 +1,298 @@
1
+ /**
2
+ * Share Card
3
+ *
4
+ * The post as "Share as image" paints it: a sheet of paper on a mat tinted
5
+ * from the site's theme, so the picture reads as a mounted card even on the
6
+ * white of a chat or a feed. Images run across the top of the paper; below
7
+ * them the date, the post set large in the site's fonts with each format's
8
+ * own marks, the files a picture cannot show, and a footer that says whose
9
+ * site it is and how to get there. A lone image keeps its own shape, cut
10
+ * only past 4:5 tall; two or more share a grid of fixed frames.
11
+ *
12
+ * A post in a Thread sits on the Thread's rail, as the timeline shows a
13
+ * Thread's newest post: the Thread's first post above it in up to three
14
+ * lines, the posts between folded to a few dots on the rail, a line of the
15
+ * post after below, and its place in the Thread beside its date. Its images
16
+ * then go after its text, inside its column, so the card reads top to
17
+ * bottom.
18
+ *
19
+ * 540 px wide, captured at 3x. Render it inside `renderIconsInline()`: the
20
+ * capture copies the card on its own, without the page's icon sprite.
21
+ */
22
+
23
+ import type { FC } from "hono/jsx";
24
+ import type {
25
+ ShareCardFile,
26
+ ShareCardThreadPost,
27
+ ShareCardView,
28
+ } from "../../lib/share-card.js";
29
+ import { DecorativeQuoteMark } from "../shared/DecorativeQuoteMark.js";
30
+ import { Icon } from "../shared/Icon.js";
31
+ import { formatChars, formatSize } from "../shared/MediaGallery.js";
32
+
33
+ /** "3:07", or "1:02:45" past an hour. */
34
+ function formatDuration(totalSeconds: number): string {
35
+ const seconds = Math.round(totalSeconds);
36
+ const hours = Math.floor(seconds / 3600);
37
+ const minutes = Math.floor((seconds % 3600) / 60);
38
+ const rest = String(seconds % 60).padStart(2, "0");
39
+ return hours > 0
40
+ ? `${hours}:${String(minutes).padStart(2, "0")}:${rest}`
41
+ : `${minutes}:${rest}`;
42
+ }
43
+
44
+ /** The one number that says how much of a file there is. */
45
+ function fileMeta(file: ShareCardFile): string | null {
46
+ if (file.size !== undefined) return formatSize(file.size);
47
+ if (file.durationSeconds !== undefined) {
48
+ return formatDuration(file.durationSeconds);
49
+ }
50
+ if (file.chars !== undefined && file.chars > 0)
51
+ return formatChars(file.chars);
52
+ return null;
53
+ }
54
+
55
+ const Files: FC<{ card: ShareCardView }> = ({ card }) => {
56
+ if (card.files.length === 0) return null;
57
+ return (
58
+ <ul class="share-card-files">
59
+ {card.files.map((file) => {
60
+ const meta = fileMeta(file);
61
+ return (
62
+ <li class="share-card-file" data-kind={file.kind}>
63
+ <span class="share-card-file-format">{file.format}</span>
64
+ <span class="share-card-file-text">
65
+ <span class="share-card-file-title">{file.title}</span>
66
+ {meta && <span class="share-card-file-meta">{meta}</span>}
67
+ </span>
68
+ </li>
69
+ );
70
+ })}
71
+ {card.moreFiles > 0 && (
72
+ <li class="share-card-file-more">+{card.moreFiles}</li>
73
+ )}
74
+ </ul>
75
+ );
76
+ };
77
+
78
+ const Images: FC<{ card: ShareCardView }> = ({ card }) => {
79
+ if (card.images.length === 0) return null;
80
+ const last = card.images.length - 1;
81
+ return (
82
+ <div class="share-card-images" data-count={String(card.images.length)}>
83
+ {card.images.map((image, index) => (
84
+ <div class="share-card-image">
85
+ <img
86
+ src={image.url}
87
+ alt=""
88
+ width={image.width}
89
+ height={image.height}
90
+ />
91
+ {image.video && (
92
+ <span class="share-card-play" aria-hidden="true">
93
+ <svg viewBox="0 0 24 24" fill="currentColor">
94
+ <path d="M8 5v14l11-7z" />
95
+ </svg>
96
+ </span>
97
+ )}
98
+ {index === last && card.moreImages > 0 && (
99
+ <span class="share-card-more-images">+{card.moreImages}</span>
100
+ )}
101
+ </div>
102
+ ))}
103
+ </div>
104
+ );
105
+ };
106
+
107
+ const Avatar: FC<{ card: ShareCardView }> = ({ card }) => {
108
+ if (card.avatarUrl) {
109
+ return <img class="share-card-avatar" src={card.avatarUrl} alt="" />;
110
+ }
111
+ const initial = Array.from(card.siteName.trim())[0];
112
+ return initial ? (
113
+ <span class="share-card-avatar" aria-hidden="true">
114
+ {initial}
115
+ </span>
116
+ ) : null;
117
+ };
118
+
119
+ /** The words; when the summary stops short of the post, its end fades. */
120
+ const Body: FC<{ card: ShareCardView }> = ({ card }) =>
121
+ card.bodyHtml ? (
122
+ <div
123
+ class={card.hasMore ? "share-card-body has-more" : "share-card-body"}
124
+ data-share-card-body
125
+ dangerouslySetInnerHTML={{ __html: card.bodyHtml }}
126
+ />
127
+ ) : null;
128
+
129
+ /** The post itself: its format's marks, its text, and its files. */
130
+ const PostContent: FC<{ card: ShareCardView; imagesInside?: boolean }> = ({
131
+ card,
132
+ imagesInside,
133
+ }) => {
134
+ const thread = card.thread;
135
+ const quoteSource = [card.quote?.attribution, card.quote?.source]
136
+ .filter(Boolean)
137
+ .join(" · ");
138
+
139
+ return (
140
+ <>
141
+ <div class="share-card-date">
142
+ {card.date}
143
+ {thread && (
144
+ <span class="share-card-thread-position">
145
+ {thread.position} / {thread.total}
146
+ </span>
147
+ )}
148
+ </div>
149
+
150
+ {card.link && (card.link.domain || card.link.title) && (
151
+ <div class="share-card-link">
152
+ {card.link.domain && (
153
+ <div class="share-card-link-domain">
154
+ <Icon name="link-domain" />
155
+ <span>{card.link.domain}</span>
156
+ </div>
157
+ )}
158
+ {card.link.title && (
159
+ <h2 class="share-card-link-title">{card.link.title}</h2>
160
+ )}
161
+ </div>
162
+ )}
163
+
164
+ {card.quote && (
165
+ <figure class="share-card-quote">
166
+ <DecorativeQuoteMark class="share-card-quote-mark" />
167
+ <blockquote class="share-card-quote-text" data-size={card.quote.size}>
168
+ {card.quote.text}
169
+ </blockquote>
170
+ {quoteSource && (
171
+ <figcaption class="share-card-quote-source">
172
+ {quoteSource}
173
+ </figcaption>
174
+ )}
175
+ </figure>
176
+ )}
177
+
178
+ {card.title && <h2 class="share-card-title">{card.title}</h2>}
179
+
180
+ <Body card={card} />
181
+
182
+ {card.hasMore && !card.bodyHtml && (
183
+ <div class="share-card-more" aria-hidden="true">
184
+ …
185
+ </div>
186
+ )}
187
+
188
+ {imagesInside && <Images card={card} />}
189
+
190
+ <Files card={card} />
191
+ </>
192
+ );
193
+ };
194
+
195
+ /** A wordless post's images: a few tiles, the last counting the rest. */
196
+ const ContextImages: FC<{ post: ShareCardThreadPost }> = ({ post }) => {
197
+ const images = post.images ?? [];
198
+ if (images.length === 0) return null;
199
+ const last = images.length - 1;
200
+ const more = post.moreImages ?? 0;
201
+ return (
202
+ <div class="share-card-context-images" data-count={String(images.length)}>
203
+ {images.map((image, index) => (
204
+ <span class="share-card-context-image">
205
+ <img src={image.url} alt="" />
206
+ {image.video && (
207
+ <span class="share-card-play" aria-hidden="true">
208
+ <svg viewBox="0 0 24 24" fill="currentColor">
209
+ <path d="M8 5v14l11-7z" />
210
+ </svg>
211
+ </span>
212
+ )}
213
+ {index === last && more > 0 && (
214
+ <span class="share-card-more-images">+{more}</span>
215
+ )}
216
+ </span>
217
+ ))}
218
+ </div>
219
+ );
220
+ };
221
+
222
+ /** The Thread's first post or the post after the shared one, quieter. */
223
+ const ContextPost: FC<{ post: ShareCardThreadPost; next?: boolean }> = ({
224
+ post,
225
+ next,
226
+ }) => (
227
+ <div
228
+ class={`share-card-thread-item share-card-context${next ? " is-next" : " is-root"}${post.source ? " has-source" : ""}`}
229
+ data-format={post.format}
230
+ >
231
+ {post.title || post.text ? (
232
+ <div class="share-card-context-text">
233
+ {post.title && (
234
+ <span class="share-card-context-title">{post.title}</span>
235
+ )}
236
+ {post.text && <span class="share-card-context-body">{post.text}</span>}
237
+ {post.source && (
238
+ <span class="share-card-context-source">{post.source}</span>
239
+ )}
240
+ </div>
241
+ ) : (
242
+ <ContextImages post={post} />
243
+ )}
244
+ </div>
245
+ );
246
+
247
+ const Thread: FC<{ card: ShareCardView }> = ({ card }) => {
248
+ const thread = card.thread;
249
+ if (!thread) return null;
250
+ return (
251
+ <div class="share-card-thread">
252
+ {thread.root && <ContextPost post={thread.root} />}
253
+ {thread.hidden > 0 && (
254
+ <div
255
+ class="share-card-thread-item share-card-thread-gap"
256
+ data-hidden={String(thread.hidden)}
257
+ aria-hidden="true"
258
+ />
259
+ )}
260
+ <div class="share-card-thread-item share-card-thread-current">
261
+ <PostContent card={card} imagesInside />
262
+ </div>
263
+ {thread.next && <ContextPost post={thread.next} next />}
264
+ </div>
265
+ );
266
+ };
267
+
268
+ export const ShareCard: FC<{ card: ShareCardView }> = ({ card }) => (
269
+ <div
270
+ class="share-card"
271
+ data-share-card
272
+ data-file-name={card.fileName}
273
+ data-layout={card.layout}
274
+ data-thread={card.thread ? "" : undefined}
275
+ lang={card.language}
276
+ >
277
+ <div class="share-card-paper">
278
+ {!card.thread && <Images card={card} />}
279
+ <div class="share-card-inner">
280
+ {card.thread ? <Thread card={card} /> : <PostContent card={card} />}
281
+
282
+ <footer class="share-card-foot">
283
+ <Avatar card={card} />
284
+ <div class="share-card-source">
285
+ <span class="share-card-site">{card.siteName}</span>
286
+ {card.siteAddress && (
287
+ <span class="share-card-address">{card.siteAddress}</span>
288
+ )}
289
+ </div>
290
+ <span
291
+ class="share-card-qr"
292
+ dangerouslySetInnerHTML={{ __html: card.qrSvg }}
293
+ />
294
+ </footer>
295
+ </div>
296
+ </div>
297
+ </div>
298
+ );
@@ -10,14 +10,30 @@
10
10
  * custom symbols defined in `custom-icons.ts`; any other name fails the
11
11
  * type check.
12
12
  *
13
+ * Inside `renderIconsInline()` it draws the icon's own paths instead, for
14
+ * markup that is copied out of the page (the share card).
15
+ *
13
16
  * Size: outer <svg> width/height in pixels. Defaults to 24 (lucide default).
14
17
  * Pass `class` to add CSS classes, e.g. for sizing via stylesheet instead
15
18
  * of inline width/height.
16
19
  */
17
20
 
18
21
  import type { FC } from "hono/jsx";
19
- import { collectIcon } from "./icon-collector.js";
20
- import { getIconViewBox, type IconName } from "./custom-icons.js";
22
+ import { raw } from "hono/html";
23
+ import { getIconInnerSvg, LUCIDE_SYMBOL_ATTRS } from "../../lib/icons.js";
24
+ import { collectIcon, iconsRenderInline } from "./icon-collector.js";
25
+ import {
26
+ getCustomSymbol,
27
+ getIconViewBox,
28
+ isCustomIconName,
29
+ type IconName,
30
+ } from "./custom-icons.js";
31
+
32
+ /** The icon's own drawing, as its sprite symbol would carry it. */
33
+ function inlineIconMarkup(name: IconName): string {
34
+ if (isCustomIconName(name)) return getCustomSymbol(name).inner;
35
+ return `<g ${LUCIDE_SYMBOL_ATTRS}>${getIconInnerSvg(name)}</g>`;
36
+ }
21
37
 
22
38
  export interface IconProps {
23
39
  /** Kebab-case icon name (lucide or custom). */
@@ -54,7 +70,11 @@ export const Icon: FC<IconProps> = ({
54
70
  {...(ariaLabel ? { "aria-label": ariaLabel, role: "img" } : {})}
55
71
  {...(hidden ? { "aria-hidden": "true" } : {})}
56
72
  >
57
- <use href={`#icon-${name}`} />
73
+ {iconsRenderInline() ? (
74
+ raw(inlineIconMarkup(name))
75
+ ) : (
76
+ <use href={`#icon-${name}`} />
77
+ )}
58
78
  </svg>
59
79
  );
60
80
  };
@@ -21,7 +21,10 @@
21
21
  import type { FC } from "hono/jsx";
22
22
  import type { MediaView } from "../../types.js";
23
23
  import { getMediaCategory } from "../../lib/upload.js";
24
- import { shouldUseShortVideoExperience } from "../../lib/video-playback.js";
24
+ import {
25
+ getPosterFrameUrl,
26
+ shouldUseShortVideoExperience,
27
+ } from "../../lib/video-playback.js";
25
28
  import {
26
29
  blurhashToDataUrl,
27
30
  getBlurhashDecodeSize,
@@ -35,7 +38,18 @@ export interface MediaGalleryProps {
35
38
 
36
39
  const DEFAULT_VISUAL_RATIO = 4 / 3;
37
40
 
38
- function formatSize(bytes: number): string {
41
+ /**
42
+ * A file size the way the gallery labels documents.
43
+ *
44
+ * @param bytes - Size in bytes
45
+ * @returns "512 B", "3.4 KB" or "2.1 MB"
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * formatSize(2_200_000); // "2.1 MB"
50
+ * ```
51
+ */
52
+ export function formatSize(bytes: number): string {
39
53
  if (bytes < 1024) return `${bytes} B`;
40
54
  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
41
55
  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
@@ -444,6 +458,14 @@ export const MediaGallery: FC<MediaGalleryProps> = ({
444
458
  ? undefined
445
459
  : `${Math.round(Math.max(160, rowHeight * ratio))}px`;
446
460
  const posterSrc = item.posterUrl || placeholder;
461
+ /* A clip stored without a poster (an API upload that sent
462
+ none) would show an empty box: these `<video>`s only ever
463
+ paint their poster. Without one, the browser reads the
464
+ file's metadata and draws the poster frame itself — at
465
+ once for a long clip, and for a short one when the feed
466
+ player hands it its source near the viewport. */
467
+ const drawsOwnFrame = !item.posterUrl;
468
+ const videoPreload = drawsOwnFrame ? "metadata" : "none";
447
469
  /* `video.u-photo` resolves to `poster`, which is the still
448
470
  the timeline already shows. Only a real poster qualifies:
449
471
  the blurhash fallback is a data URL, and publishing one as
@@ -494,7 +516,7 @@ export const MediaGallery: FC<MediaGalleryProps> = ({
494
516
  class="u-video media-visual-frame media-video-link"
495
517
  >
496
518
  <video
497
- preload="none"
519
+ preload={videoPreload}
498
520
  muted
499
521
  playsinline
500
522
  loop
@@ -558,10 +580,15 @@ export const MediaGallery: FC<MediaGalleryProps> = ({
558
580
  }
559
581
  >
560
582
  <video
561
- preload="none"
583
+ preload={videoPreload}
562
584
  muted
563
585
  playsinline
564
586
  poster={posterSrc}
587
+ src={
588
+ drawsOwnFrame
589
+ ? getPosterFrameUrl(item.url, item.durationSeconds)
590
+ : undefined
591
+ }
565
592
  width={item.width}
566
593
  height={item.height}
567
594
  style={videoStyle}
@@ -13,6 +13,7 @@ import type {
13
13
  PostFooterDisplayOptions,
14
14
  } from "../../types.js";
15
15
  import { useLingui } from "../../i18n/context.js";
16
+ import { canShareAsImage } from "../../lib/share-card.js";
16
17
  import { sanitizeUrl } from "../../lib/url.js";
17
18
  import { useViewer } from "../../lib/viewer-context.js";
18
19
  import { Icon } from "./Icon.js";
@@ -153,9 +154,15 @@ export const PostPublishedLink: FC<PostPublishedLinkProps> = ({
153
154
  );
154
155
  };
155
156
 
156
- export const PostMenuTriggerButton: FC<{ className?: string }> = ({
157
- className = "post-menu-trigger",
158
- }) => {
157
+ /**
158
+ * The post's "More" button. The author's opens `jant-post-menu`; a reader's
159
+ * (`reader`) opens `jant-share-menu`, which holds Copy link and Share as
160
+ * image.
161
+ */
162
+ export const PostMenuTriggerButton: FC<{
163
+ className?: string;
164
+ reader?: boolean;
165
+ }> = ({ className = "post-menu-trigger", reader = false }) => {
159
166
  const { i18n } = useLingui();
160
167
 
161
168
  return (
@@ -170,7 +177,9 @@ export const PostMenuTriggerButton: FC<{ className?: string }> = ({
170
177
  }),
171
178
  )}
172
179
  aria-expanded="false"
173
- data-post-menu-trigger
180
+ {...(reader
181
+ ? { "data-share-menu-trigger": true }
182
+ : { "data-post-menu-trigger": true })}
174
183
  >
175
184
  <Icon name="post-menu-dots" size={15} />
176
185
  </button>
@@ -283,6 +292,13 @@ export const PostFooter: FC<PostFooterProps> = ({ post, detail, display }) => {
283
292
  <PostMenuTriggerButton />
284
293
  </div>
285
294
  )}
295
+ {/* A reader's menu sits where the author's does, with what a reader can
296
+ do with a post: copy its link, share it as an image. */}
297
+ {!hideActions && !isAuthor && canShareAsImage(post) && (
298
+ <div class="post-menu-actions">
299
+ <PostMenuTriggerButton reader />
300
+ </div>
301
+ )}
286
302
  </footer>
287
303
  );
288
304
  };