@jant/core 1.1.0 → 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 (116) hide show
  1. package/bin/lib/site-snapshot.js +10 -0
  2. package/dist/{app-CKQ9PqAr.js → app-CbOZ2Irh.js} +7988 -5166
  3. package/dist/client/.vite/manifest.json +47 -47
  4. package/dist/client/_assets/chunks/{create-editor-BQkrw8Ax.js → create-editor-hWapNE40.js} +25 -25
  5. package/dist/client/_assets/chunks/footnote-rail-9zwl6jtV.js +2 -0
  6. package/dist/client/_assets/chunks/{settings-paths-B0bNUaih.js → settings-paths-BBVT8zKj.js} +1 -1
  7. package/dist/client/_assets/chunks/{slug-format-CYmQE5ln.js → slug-format-BuCPjSrB.js} +1 -1
  8. package/dist/client/_assets/chunks/sortable-list-DJXwkaOv.js +2 -0
  9. package/dist/client/_assets/chunks/types-DrYFqJH2.js +1 -0
  10. package/dist/client/_assets/chunks/unsafe-svg-CUrgo4Xg.js +1 -0
  11. package/dist/client/_assets/{client-Dp46QSht.js → client-BO8GOFfT.js} +12 -12
  12. package/dist/client/_assets/client-D8Rrsd73.css +2 -0
  13. package/dist/client/_assets/{client-auth-CG55rWb5.js → client-auth-CsUGM718.js} +1 -1
  14. package/dist/client/_assets/client-author-QPm1whbO.css +2 -0
  15. package/dist/client/_assets/client-compose-BB4U7Wz0.js +2004 -0
  16. package/dist/client/_assets/{client-manage-DnYdQAhf.js → client-manage-CI9-eh-8.js} +1 -1
  17. package/dist/client/_assets/{client-settings-CHgsIqXJ.js → client-settings-BnGPuqwc.js} +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/node.js +3 -2
  20. package/package.json +1 -1
  21. package/src/app.tsx +9 -0
  22. package/src/client/components/compose-types.ts +1 -0
  23. package/src/client/components/jant-compose-dialog.ts +1 -0
  24. package/src/client/components/jant-compose-editor.ts +30 -0
  25. package/src/client/components/jant-compose-fullscreen.ts +1 -0
  26. package/src/client/compose-bridge.ts +61 -1
  27. package/src/client/feed-video-player.ts +6 -0
  28. package/src/client/tiptap/bubble-menu.ts +25 -2
  29. package/src/client/tiptap/create-editor.ts +2 -0
  30. package/src/client/tiptap/extensions.ts +4 -0
  31. package/src/client/video-processor.ts +106 -52
  32. package/src/client/view-confirm.ts +108 -0
  33. package/src/client.ts +1 -0
  34. package/src/db/migrations/0035_brainy_next_avengers.sql +9 -0
  35. package/src/db/migrations/0036_gorgeous_smasher.sql +7 -0
  36. package/src/db/migrations/meta/0035_snapshot.json +2877 -0
  37. package/src/db/migrations/meta/0036_snapshot.json +2924 -0
  38. package/src/db/migrations/meta/_journal.json +14 -0
  39. package/src/db/migrations/pg/0033_cute_magdalene.sql +10 -0
  40. package/src/db/migrations/pg/0034_material_agent_brand.sql +8 -0
  41. package/src/db/migrations/pg/meta/0033_snapshot.json +3719 -0
  42. package/src/db/migrations/pg/meta/0034_snapshot.json +3766 -0
  43. package/src/db/migrations/pg/meta/_journal.json +14 -0
  44. package/src/db/pg/schema.ts +40 -0
  45. package/src/db/schema.ts +61 -0
  46. package/src/i18n/locales/public/en.po +5 -0
  47. package/src/i18n/locales/public/en.ts +1 -1
  48. package/src/i18n/locales/public/zh-Hans.po +5 -0
  49. package/src/i18n/locales/public/zh-Hans.ts +1 -1
  50. package/src/i18n/locales/public/zh-Hant.po +5 -0
  51. package/src/i18n/locales/public/zh-Hant.ts +1 -1
  52. package/src/i18n/locales/settings/en.po +149 -0
  53. package/src/i18n/locales/settings/en.ts +1 -1
  54. package/src/i18n/locales/settings/zh-Hans.po +149 -0
  55. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  56. package/src/i18n/locales/settings/zh-Hant.po +149 -0
  57. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  58. package/src/lib/env.ts +20 -0
  59. package/src/lib/github-app-state.ts +1 -1
  60. package/src/lib/github-app.ts +183 -1
  61. package/src/lib/markdown-manager.ts +129 -1
  62. package/src/lib/post-meta.ts +13 -3
  63. package/src/lib/referrer-aliases.ts +311 -0
  64. package/src/lib/render.tsx +10 -0
  65. package/src/lib/resolve-config.ts +14 -0
  66. package/src/lib/summary.ts +152 -54
  67. package/src/lib/tiptap-render.ts +1 -0
  68. package/src/lib/upload.ts +21 -1
  69. package/src/lib/video-playback.ts +55 -0
  70. package/src/lib/view-buffer.ts +201 -0
  71. package/src/lib/view-counting.ts +539 -0
  72. package/src/lib/view-token.ts +177 -0
  73. package/src/lib/view.ts +13 -1
  74. package/src/middleware/view-counter.ts +140 -0
  75. package/src/node/runtime.ts +4 -0
  76. package/src/preset.css +31 -14
  77. package/src/routes/api/media.ts +21 -3
  78. package/src/routes/dash/settings.tsx +433 -168
  79. package/src/routes/pages/archive.tsx +1 -0
  80. package/src/routes/pages/collection.tsx +6 -0
  81. package/src/routes/pages/collections.tsx +1 -0
  82. package/src/routes/pages/featured.tsx +1 -0
  83. package/src/routes/pages/home.tsx +1 -0
  84. package/src/routes/pages/page.tsx +3 -0
  85. package/src/routes/pages/smart-collection.tsx +2 -0
  86. package/src/routes/pages/subscribe.tsx +1 -0
  87. package/src/routes/view-confirm.ts +63 -0
  88. package/src/services/export-theme/assets/client-site.js +1 -1
  89. package/src/services/export-theme/styles/main.css +39 -21
  90. package/src/services/export.ts +2 -0
  91. package/src/services/index.ts +17 -0
  92. package/src/services/mcp.ts +31 -1
  93. package/src/services/media.ts +63 -0
  94. package/src/services/stats.ts +1130 -0
  95. package/src/styles/components-author.css +177 -0
  96. package/src/styles/components.css +11 -3
  97. package/src/styles/tokens.css +65 -30
  98. package/src/styles/ui.css +56 -13
  99. package/src/types/app-context.ts +9 -0
  100. package/src/types/bindings.ts +5 -0
  101. package/src/types/config.ts +54 -0
  102. package/src/types/views.ts +6 -0
  103. package/src/ui/compose/ComposeDialog.tsx +6 -0
  104. package/src/ui/dash/settings/SettingsRootContent.tsx +24 -6
  105. package/src/ui/dash/settings/StatsContent.tsx +855 -0
  106. package/src/ui/font-themes.ts +39 -6
  107. package/src/ui/layouts/BaseLayout.tsx +4 -2
  108. package/src/ui/layouts/SiteLayout.tsx +8 -3
  109. package/src/ui/shared/MediaGallery.tsx +19 -3
  110. package/dist/client/_assets/chunks/footnote-rail-B08scyhW.js +0 -2
  111. package/dist/client/_assets/chunks/sortable-list-t11Ma1Ek.js +0 -2
  112. package/dist/client/_assets/chunks/types-D5iF3H1a.js +0 -1
  113. package/dist/client/_assets/chunks/unsafe-svg-DZl-yjas.js +0 -1
  114. package/dist/client/_assets/client-B0-s9sqx.css +0 -2
  115. package/dist/client/_assets/client-author-CGVvrNZ8.css +0 -2
  116. package/dist/client/_assets/client-compose-DkUTuavR.js +0 -2004
@@ -1,4 +1,4 @@
1
- import{a as e,i as t,l as n,o as r,p as i,r as a,u as o}from"./chunks/runtime-paths-y0_gHowM.js";import{d as s,i as c,n as l,t as u,u as d}from"./chunks/lit-Bw_voPoW.js";import{n as f}from"./chunks/unsafe-html-CWos3v6N.js";import{n as p,t as m}from"./chunks/site-header-nav-DzXsFk05.js";import{n as h}from"./chunks/confirm-CMe01lne.js";import{_ as g,a as _,c as ee,i as v,n as te,o as y,p as b,r as ne,s as re}from"./chunks/types-D5iF3H1a.js";import{n as ie,r as x,t as S}from"./chunks/slug-format-CYmQE5ln.js";import{a as ae,i as oe,n as C,r as w,t as T}from"./chunks/settings-paths-B0bNUaih.js";import{a as E,c as se,d as ce,f as D,i as le,l as ue,n as de,o as O,r as k,s as A,t as fe}from"./chunks/sortable-list-t11Ma1Ek.js";import{_ as pe,r as j,t as M}from"./chunks/create-editor-BQkrw8Ax.js";function N(e){if(!e)return;let t=document.createElement(`template`);t.innerHTML=e.trim();let n=[`[data-site-header-fragment="header"]`,`[data-site-header-fragment="drawer-backdrop"]`,`[data-site-header-fragment="drawer"]`],r=!1;m(document);for(let e of n){let n=document.querySelector(e),i=t.content.querySelector(e);n&&i&&(n.replaceWith(i),r=!0)}r&&p(document)}var P=`<svg class="lucide lucide-funnel icon-fine" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z"/></svg>`,me=250,he=c`<svg
1
+ import{a as e,i as t,l as n,o as r,p as i,r as a,u as o}from"./chunks/runtime-paths-y0_gHowM.js";import{d as s,i as c,n as l,t as u,u as d}from"./chunks/lit-Bw_voPoW.js";import{n as f}from"./chunks/unsafe-html-CWos3v6N.js";import{n as p,t as m}from"./chunks/site-header-nav-DzXsFk05.js";import{n as h}from"./chunks/confirm-CMe01lne.js";import{_ as g,a as _,c as ee,i as v,n as te,o as y,p as b,r as ne,s as re}from"./chunks/types-DrYFqJH2.js";import{n as ie,r as x,t as S}from"./chunks/slug-format-BuCPjSrB.js";import{a as ae,i as oe,n as C,r as w,t as T}from"./chunks/settings-paths-BBVT8zKj.js";import{a as E,c as se,d as ce,f as D,i as le,l as ue,n as de,o as O,r as k,s as A,t as fe}from"./chunks/sortable-list-DJXwkaOv.js";import{_ as pe,r as j,t as M}from"./chunks/create-editor-hWapNE40.js";function N(e){if(!e)return;let t=document.createElement(`template`);t.innerHTML=e.trim();let n=[`[data-site-header-fragment="header"]`,`[data-site-header-fragment="drawer-backdrop"]`,`[data-site-header-fragment="drawer"]`],r=!1;m(document);for(let e of n){let n=document.querySelector(e),i=t.content.querySelector(e);n&&i&&(n.replaceWith(i),r=!0)}r&&p(document)}var P=`<svg class="lucide lucide-funnel icon-fine" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z"/></svg>`,me=250,he=c`<svg
2
2
  viewBox="0 0 24 24"
3
3
  fill="none"
4
4
  stroke="currentColor"
@@ -1,4 +1,4 @@
1
- import{r as e}from"./chunks/runtime-paths-y0_gHowM.js";import{a as t,i as n,r,s as i,t as a}from"./chunks/jant-locale-picker-2L4rkDaz.js";import{i as o,n as s,s as c,t as l,u}from"./chunks/lit-Bw_voPoW.js";import{n as d}from"./chunks/confirm-CMe01lne.js";import{_ as f,d as p,h as m,l as h,m as g,p as _,u as v}from"./chunks/types-D5iF3H1a.js";import{r as y,t as b}from"./chunks/create-editor-BQkrw8Ax.js";var x={ICO_16:16,ICO_32:32,APPLE_TOUCH:512};function S(e){let t=e.length*16,n=6+t,r=new ArrayBuffer(6+t),i=new DataView(r);i.setUint16(0,0,!0),i.setUint16(2,1,!0),i.setUint16(4,e.length,!0);let a=[];for(let t=0;t<e.length;t++){let r=e[t],o=6+t*16;i.setUint8(o+0,r.size<256?r.size:0),i.setUint8(o+1,r.size<256?r.size:0),i.setUint8(o+2,0),i.setUint8(o+3,0),i.setUint16(o+4,1,!0),i.setUint16(o+6,32,!0),i.setUint32(o+8,r.png.byteLength,!0),i.setUint32(o+12,n,!0),n+=r.png.byteLength,a.push(r.png)}return new Blob([r,...a],{type:`image/x-icon`})}var C=180;function w(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>{URL.revokeObjectURL(r.src),t(r)},r.onerror=()=>n(Error(`Failed to load image`)),r.src=URL.createObjectURL(e)})}function T(e,t){let n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`);if(!r)throw Error(`Failed to get canvas context`);r.imageSmoothingEnabled=!0,r.imageSmoothingQuality=`high`;let i=Math.max(t/e.width,t/e.height),a=t/i,o=t/i,s=(e.width-a)/2,c=(e.height-o)/2;return r.drawImage(e,s,c,a,o,0,0,t,t),new Promise((e,t)=>{n.toBlob(n=>{n?e(n):t(Error(`Failed to create PNG blob`))},`image/png`)})}function E(e,t){return e.type===`image/png`&&t.width===t.height&&t.width>=C&&t.height>=C}async function D(t,n){let r=t.closest(`form`)?.querySelector(`label`),i=r?.textContent??``;try{r&&(r.textContent=t.dataset.textProcessing||`Processing...`);let i=await w(n),a=await T(i,512),o=new File([a],n.name.replace(/\.[^.]+$/,`.png`),{type:`image/png`}),s=o.name,c=E(n,i)?Promise.resolve(n):T(i,x.APPLE_TOUCH),[l,u,d]=await Promise.all([T(i,16),T(i,32),c]),[p,m]=await Promise.all([l.arrayBuffer(),u.arrayBuffer()]),h=S([{size:16,png:p},{size:32,png:m}]);r&&(r.textContent=t.dataset.textUploading||`Uploading...`);let g=new FormData;g.append(`file`,o,s),g.append(`favicon`,h,`favicon.ico`),g.append(`appleTouch`,d,`apple-touch-icon.png`);let v=await fetch(e(`/settings/avatar`),{method:`POST`,headers:{Accept:`application/json`},body:g});if(!v.ok){let e=t.dataset.textError||`Upload failed. Please try again.`;try{let t=await f(v);e=_(t,`error`)??_(t,`message`)??e}catch{}throw Error(e)}let y=await f(v),b=_(y,`status`),C=_(y,`url`);if(b===`redirect`&&C){window.location.href=C;return}window.location.href=e(`/settings/avatar?saved`)}catch(e){r&&(r.textContent=i),u(e instanceof Error&&e.message?e.message:t.dataset.textError||`Upload failed. Please try again.`,`error`)}t.value=``}function O(){document.addEventListener(`change`,e=>{let t=e.target.closest(`[data-avatar-upload]`);t?.files?.[0]&&(e.stopPropagation(),D(t,t.files[0]))})}O();var k=[`latest`,`off`];function A(e){let t=e?.trim();return t&&k.includes(t)?t:null}function ee(e){if(e.demoMode||!e.rssFeedsEnabled)return`none`;let t=A(e.storedValue);if(t)return t===`off`?`none`:t;if(e.noindex)return`none`;let n=A(e.defaultValue);return n?n===`off`?`none`:n:`none`}var j={links:`Links`,quotes:`Quotes`};function M(e,t){let n=[],r=t.filter(e=>e.term&&e.href).sort((e,t)=>t.term.length-e.term.length);for(let{term:t,href:i}of r)for(let r=e.indexOf(t);r!==-1;r=e.indexOf(t,r+1)){let e=r+t.length;if(!n.some(t=>r<t.end&&t.start<e)){n.push({start:r,end:e,href:i});break}}n.sort((e,t)=>e.start-t.start);let i=[],a=0;for(let{start:t,end:r,href:o}of n)t>a&&i.push({text:e.slice(a,t)}),i.push({text:e.slice(t,r),href:o}),a=r;return a<e.length&&i.push({text:e.slice(a)}),i}function N(e,t,n){return n?M(e,[{term:t.name,href:n.home},{term:j.links,href:n.links},{term:j.quotes,href:n.quotes},{term:t.rules,href:n.rules}]):[{text:e}]}var P=`flex flex-col py-8 first:pt-0 last:pb-0`,F=class extends l{static properties={labels:{type:Object},timezones:{type:Array},siteNameFallback:{type:String,attribute:`sitename-fallback`},siteDescriptionFallback:{type:String,attribute:`sitedescription-fallback`},demoMode:{type:Boolean,attribute:`demo-mode`},discoverDefault:{type:String,attribute:`discover-default`},discoverPages:{type:Object,attribute:`discover-pages`},discoverStatus:{type:String,attribute:`discover-status`},feedsEnabled:{type:Boolean,attribute:`feeds-enabled`},mainFeedUrl:{type:String,attribute:`main-feed-url`},latestFeedUrl:{type:String,attribute:`latest-feed-url`},featuredFeedUrl:{type:String,attribute:`featured-feed-url`},archiveFeedUrl:{type:String,attribute:`archive-feed-url`},feedsDocsUrl:{type:String,attribute:`feeds-docs-url`},aboutPage:{type:Object,attribute:`about-page`},aboutEditUrl:{type:String,attribute:`about-edit-url`},aboutCreateUrl:{type:String,attribute:`about-create-url`},_siteName:{state:!0},_siteDescription:{state:!0},_siteFooter:{state:!0},_origSite:{state:!0},_siteDirty:{state:!0},_siteLoading:{state:!0},_timeZone:{state:!0},_origLocale:{state:!0},_localeDirty:{state:!0},_localeLoading:{state:!0},_mainRssFeed:{state:!0},_origMainRssFeed:{state:!0},_feedLoading:{state:!0},_showJantBrandingOnHome:{state:!0},_origShowJantBrandingOnHome:{state:!0},_homeLoading:{state:!0},_noindex:{state:!0},_origNoindex:{state:!0},_searchLoading:{state:!0},_discover:{state:!0},_origDiscover:{state:!0},_discoverLoading:{state:!0}};_descEditor=null;_footerEditor=null;createRenderRoot(){return this.innerHTML=``,this}constructor(){super(),this.labels={},this.timezones=[],this.siteNameFallback=``,this.siteDescriptionFallback=``,this.demoMode=!1,this.mainFeedUrl=`/feed`,this.latestFeedUrl=`/latest/feed`,this.featuredFeedUrl=`/featured/feed`,this.archiveFeedUrl=`/archive/feed`,this.feedsDocsUrl=``,this.aboutPage={state:`missing`,path:`/about`},this.aboutEditUrl=`/about?edit=1`,this.aboutCreateUrl=`/settings/general/about-page`,this._siteName=``,this._siteDescription=``,this._siteFooter=``,this._origSite={siteName:``,siteDescription:``,siteFooter:``},this._siteDirty=!1,this._siteLoading=!1,this._timeZone=`UTC`,this._origLocale={timeZone:`UTC`},this._localeDirty=!1,this._localeLoading=!1,this._mainRssFeed=`featured`,this._origMainRssFeed=`featured`,this._feedLoading=!1,this._noindex=!1,this._origNoindex=!1,this._showJantBrandingOnHome=!1,this._origShowJantBrandingOnHome=!1,this._homeLoading=!1,this._searchLoading=!1,this.discoverDefault=``,this.discoverPages=null,this.discoverStatus=``,this.feedsEnabled=!1,this._discover=``,this._origDiscover=``,this._discoverLoading=!1}connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback(),this._descEditor?.destroy(),this._descEditor=null,this._footerEditor?.destroy(),this._footerEditor=null}initData(e){this._siteName=e.siteName,this._siteDescription=e.siteDescription,this._siteFooter=e.siteFooter,this._timeZone=e.timeZone,this._origLocale={timeZone:e.timeZone},this._mainRssFeed=e.mainRssFeed,this._origMainRssFeed=e.mainRssFeed,this._showJantBrandingOnHome=e.showJantBrandingOnHome,this._origShowJantBrandingOnHome=e.showJantBrandingOnHome,this._noindex=e.noindex,this._origNoindex=e.noindex,this._discover=e.discover,this._origDiscover=e.discover,this.updateComplete.then(()=>{this._initEditors(),this._origSite={siteName:e.siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter}})}sectionSaved(e){e===`site`?(this._origSite={siteName:this._siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter},this._siteDirty=!1,this._siteLoading=!1):e===`time`?(this._origLocale={timeZone:this._timeZone},this._localeDirty=!1,this._localeLoading=!1):e===`feeds`?(this._origMainRssFeed=this._mainRssFeed,this._feedLoading=!1):e===`home`?(this._origShowJantBrandingOnHome=this._showJantBrandingOnHome,this._homeLoading=!1):e===`search`?(this._origNoindex=this._noindex,this._searchLoading=!1):e===`discover`&&(this._origDiscover=this._discover,this._discoverLoading=!1)}sectionError(e){e===`site`?this._siteLoading=!1:e===`time`?this._localeLoading=!1:e===`feeds`?(this._mainRssFeed=this._origMainRssFeed,this._feedLoading=!1):e===`home`?(this._showJantBrandingOnHome=this._origShowJantBrandingOnHome,this._homeLoading=!1):e===`search`?(this._noindex=this._origNoindex,this._searchLoading=!1):e===`discover`&&(this._discover=this._origDiscover,this._discoverLoading=!1)}_initEditors(){this._initDescEditor(),this._initFooterEditor()}_initDescEditor(){let e=this.querySelector(`[data-settings-desc-editor]`);if(!e||this._descEditor)return;this._descEditor=b({element:e,placeholder:this.siteDescriptionFallback,content:this._siteDescription||void 0,onUpdate:e=>{this._siteDescription=e,this._syncSiteDirty()}}),this._siteDescription=y(this._descEditor.getJSON());let t=e.querySelector(`.ProseMirror`);t&&(t.style.outline=`none`,t.style.minHeight=`3rem`)}_initFooterEditor(){let e=this.querySelector(`[data-settings-footer-editor]`);if(!e||this._footerEditor)return;this._footerEditor=b({element:e,content:this._siteFooter||void 0,onUpdate:e=>{this._siteFooter=e,this._syncSiteDirty()}}),this._siteFooter=y(this._footerEditor.getJSON());let t=e.querySelector(`.ProseMirror`);t&&(t.style.outline=`none`,t.style.minHeight=`6rem`)}_syncSiteDirty(){this._siteDirty=this._siteName!==this._origSite.siteName||this._siteDescription!==this._origSite.siteDescription||this._siteFooter!==this._origSite.siteFooter}_saveSite(){!this._siteLoading&&this._siteDirty&&(this._siteLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general`,data:{siteName:this._siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter},section:`site`}})))}_syncLocaleDirty(){this._localeDirty=this._timeZone!==this._origLocale.timeZone}_saveLocale(){!this._localeLoading&&this._localeDirty&&(this._localeLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/time`,data:{timeZone:this._timeZone},section:`time`}})))}_saveMainRssFeed(e){this._feedLoading||e===this._mainRssFeed||(this._mainRssFeed=e,this._feedLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/feeds`,data:{mainRssFeed:e},section:`feeds`}})))}_saveHomeToggle(e){this._homeLoading||(this._showJantBrandingOnHome=e,this._homeLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/home`,data:{showJantBrandingOnHome:e},section:`home`}})))}_saveSearchToggle(e){this.demoMode||this._searchLoading||(this._noindex=!e,this._searchLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/search`,data:{allowIndexing:e},section:`search`}})))}_effectiveDiscoverMode(e={}){return ee({storedValue:this._discover||null,defaultValue:this.discoverDefault||null,demoMode:this.demoMode,noindex:e.noindex??this._noindex,rssFeedsEnabled:this.feedsEnabled})}_onDiscoverToggle(e){this._saveDiscover(e?`latest`:`off`)}_saveDiscover(e){this._discoverLoading||(this._discover=e,this._discoverLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/discover`,data:{discover:e},section:`discover`}})))}_onKeydown(e,t,n,r){e.isComposing||e.keyCode===229||e.key===`Enter`&&!r&&n&&!(e.target instanceof HTMLTextAreaElement)&&(e.preventDefault(),t())}_renderSaveAction(e,t,n){return o`
1
+ import{r as e}from"./chunks/runtime-paths-y0_gHowM.js";import{a as t,i as n,r,s as i,t as a}from"./chunks/jant-locale-picker-2L4rkDaz.js";import{i as o,n as s,s as c,t as l,u}from"./chunks/lit-Bw_voPoW.js";import{n as d}from"./chunks/confirm-CMe01lne.js";import{_ as f,d as p,h as m,l as h,m as g,p as _,u as v}from"./chunks/types-DrYFqJH2.js";import{r as y,t as b}from"./chunks/create-editor-hWapNE40.js";var x={ICO_16:16,ICO_32:32,APPLE_TOUCH:512};function S(e){let t=e.length*16,n=6+t,r=new ArrayBuffer(6+t),i=new DataView(r);i.setUint16(0,0,!0),i.setUint16(2,1,!0),i.setUint16(4,e.length,!0);let a=[];for(let t=0;t<e.length;t++){let r=e[t],o=6+t*16;i.setUint8(o+0,r.size<256?r.size:0),i.setUint8(o+1,r.size<256?r.size:0),i.setUint8(o+2,0),i.setUint8(o+3,0),i.setUint16(o+4,1,!0),i.setUint16(o+6,32,!0),i.setUint32(o+8,r.png.byteLength,!0),i.setUint32(o+12,n,!0),n+=r.png.byteLength,a.push(r.png)}return new Blob([r,...a],{type:`image/x-icon`})}var C=180;function w(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>{URL.revokeObjectURL(r.src),t(r)},r.onerror=()=>n(Error(`Failed to load image`)),r.src=URL.createObjectURL(e)})}function T(e,t){let n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`);if(!r)throw Error(`Failed to get canvas context`);r.imageSmoothingEnabled=!0,r.imageSmoothingQuality=`high`;let i=Math.max(t/e.width,t/e.height),a=t/i,o=t/i,s=(e.width-a)/2,c=(e.height-o)/2;return r.drawImage(e,s,c,a,o,0,0,t,t),new Promise((e,t)=>{n.toBlob(n=>{n?e(n):t(Error(`Failed to create PNG blob`))},`image/png`)})}function E(e,t){return e.type===`image/png`&&t.width===t.height&&t.width>=C&&t.height>=C}async function D(t,n){let r=t.closest(`form`)?.querySelector(`label`),i=r?.textContent??``;try{r&&(r.textContent=t.dataset.textProcessing||`Processing...`);let i=await w(n),a=await T(i,512),o=new File([a],n.name.replace(/\.[^.]+$/,`.png`),{type:`image/png`}),s=o.name,c=E(n,i)?Promise.resolve(n):T(i,x.APPLE_TOUCH),[l,u,d]=await Promise.all([T(i,16),T(i,32),c]),[p,m]=await Promise.all([l.arrayBuffer(),u.arrayBuffer()]),h=S([{size:16,png:p},{size:32,png:m}]);r&&(r.textContent=t.dataset.textUploading||`Uploading...`);let g=new FormData;g.append(`file`,o,s),g.append(`favicon`,h,`favicon.ico`),g.append(`appleTouch`,d,`apple-touch-icon.png`);let v=await fetch(e(`/settings/avatar`),{method:`POST`,headers:{Accept:`application/json`},body:g});if(!v.ok){let e=t.dataset.textError||`Upload failed. Please try again.`;try{let t=await f(v);e=_(t,`error`)??_(t,`message`)??e}catch{}throw Error(e)}let y=await f(v),b=_(y,`status`),C=_(y,`url`);if(b===`redirect`&&C){window.location.href=C;return}window.location.href=e(`/settings/avatar?saved`)}catch(e){r&&(r.textContent=i),u(e instanceof Error&&e.message?e.message:t.dataset.textError||`Upload failed. Please try again.`,`error`)}t.value=``}function O(){document.addEventListener(`change`,e=>{let t=e.target.closest(`[data-avatar-upload]`);t?.files?.[0]&&(e.stopPropagation(),D(t,t.files[0]))})}O();var k=[`latest`,`off`];function A(e){let t=e?.trim();return t&&k.includes(t)?t:null}function ee(e){if(e.demoMode||!e.rssFeedsEnabled)return`none`;let t=A(e.storedValue);if(t)return t===`off`?`none`:t;if(e.noindex)return`none`;let n=A(e.defaultValue);return n?n===`off`?`none`:n:`none`}var j={links:`Links`,quotes:`Quotes`};function M(e,t){let n=[],r=t.filter(e=>e.term&&e.href).sort((e,t)=>t.term.length-e.term.length);for(let{term:t,href:i}of r)for(let r=e.indexOf(t);r!==-1;r=e.indexOf(t,r+1)){let e=r+t.length;if(!n.some(t=>r<t.end&&t.start<e)){n.push({start:r,end:e,href:i});break}}n.sort((e,t)=>e.start-t.start);let i=[],a=0;for(let{start:t,end:r,href:o}of n)t>a&&i.push({text:e.slice(a,t)}),i.push({text:e.slice(t,r),href:o}),a=r;return a<e.length&&i.push({text:e.slice(a)}),i}function N(e,t,n){return n?M(e,[{term:t.name,href:n.home},{term:j.links,href:n.links},{term:j.quotes,href:n.quotes},{term:t.rules,href:n.rules}]):[{text:e}]}var P=`flex flex-col py-8 first:pt-0 last:pb-0`,F=class extends l{static properties={labels:{type:Object},timezones:{type:Array},siteNameFallback:{type:String,attribute:`sitename-fallback`},siteDescriptionFallback:{type:String,attribute:`sitedescription-fallback`},demoMode:{type:Boolean,attribute:`demo-mode`},discoverDefault:{type:String,attribute:`discover-default`},discoverPages:{type:Object,attribute:`discover-pages`},discoverStatus:{type:String,attribute:`discover-status`},feedsEnabled:{type:Boolean,attribute:`feeds-enabled`},mainFeedUrl:{type:String,attribute:`main-feed-url`},latestFeedUrl:{type:String,attribute:`latest-feed-url`},featuredFeedUrl:{type:String,attribute:`featured-feed-url`},archiveFeedUrl:{type:String,attribute:`archive-feed-url`},feedsDocsUrl:{type:String,attribute:`feeds-docs-url`},aboutPage:{type:Object,attribute:`about-page`},aboutEditUrl:{type:String,attribute:`about-edit-url`},aboutCreateUrl:{type:String,attribute:`about-create-url`},_siteName:{state:!0},_siteDescription:{state:!0},_siteFooter:{state:!0},_origSite:{state:!0},_siteDirty:{state:!0},_siteLoading:{state:!0},_timeZone:{state:!0},_origLocale:{state:!0},_localeDirty:{state:!0},_localeLoading:{state:!0},_mainRssFeed:{state:!0},_origMainRssFeed:{state:!0},_feedLoading:{state:!0},_showJantBrandingOnHome:{state:!0},_origShowJantBrandingOnHome:{state:!0},_homeLoading:{state:!0},_noindex:{state:!0},_origNoindex:{state:!0},_searchLoading:{state:!0},_discover:{state:!0},_origDiscover:{state:!0},_discoverLoading:{state:!0}};_descEditor=null;_footerEditor=null;createRenderRoot(){return this.innerHTML=``,this}constructor(){super(),this.labels={},this.timezones=[],this.siteNameFallback=``,this.siteDescriptionFallback=``,this.demoMode=!1,this.mainFeedUrl=`/feed`,this.latestFeedUrl=`/latest/feed`,this.featuredFeedUrl=`/featured/feed`,this.archiveFeedUrl=`/archive/feed`,this.feedsDocsUrl=``,this.aboutPage={state:`missing`,path:`/about`},this.aboutEditUrl=`/about?edit=1`,this.aboutCreateUrl=`/settings/general/about-page`,this._siteName=``,this._siteDescription=``,this._siteFooter=``,this._origSite={siteName:``,siteDescription:``,siteFooter:``},this._siteDirty=!1,this._siteLoading=!1,this._timeZone=`UTC`,this._origLocale={timeZone:`UTC`},this._localeDirty=!1,this._localeLoading=!1,this._mainRssFeed=`featured`,this._origMainRssFeed=`featured`,this._feedLoading=!1,this._noindex=!1,this._origNoindex=!1,this._showJantBrandingOnHome=!1,this._origShowJantBrandingOnHome=!1,this._homeLoading=!1,this._searchLoading=!1,this.discoverDefault=``,this.discoverPages=null,this.discoverStatus=``,this.feedsEnabled=!1,this._discover=``,this._origDiscover=``,this._discoverLoading=!1}connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback(),this._descEditor?.destroy(),this._descEditor=null,this._footerEditor?.destroy(),this._footerEditor=null}initData(e){this._siteName=e.siteName,this._siteDescription=e.siteDescription,this._siteFooter=e.siteFooter,this._timeZone=e.timeZone,this._origLocale={timeZone:e.timeZone},this._mainRssFeed=e.mainRssFeed,this._origMainRssFeed=e.mainRssFeed,this._showJantBrandingOnHome=e.showJantBrandingOnHome,this._origShowJantBrandingOnHome=e.showJantBrandingOnHome,this._noindex=e.noindex,this._origNoindex=e.noindex,this._discover=e.discover,this._origDiscover=e.discover,this.updateComplete.then(()=>{this._initEditors(),this._origSite={siteName:e.siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter}})}sectionSaved(e){e===`site`?(this._origSite={siteName:this._siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter},this._siteDirty=!1,this._siteLoading=!1):e===`time`?(this._origLocale={timeZone:this._timeZone},this._localeDirty=!1,this._localeLoading=!1):e===`feeds`?(this._origMainRssFeed=this._mainRssFeed,this._feedLoading=!1):e===`home`?(this._origShowJantBrandingOnHome=this._showJantBrandingOnHome,this._homeLoading=!1):e===`search`?(this._origNoindex=this._noindex,this._searchLoading=!1):e===`discover`&&(this._origDiscover=this._discover,this._discoverLoading=!1)}sectionError(e){e===`site`?this._siteLoading=!1:e===`time`?this._localeLoading=!1:e===`feeds`?(this._mainRssFeed=this._origMainRssFeed,this._feedLoading=!1):e===`home`?(this._showJantBrandingOnHome=this._origShowJantBrandingOnHome,this._homeLoading=!1):e===`search`?(this._noindex=this._origNoindex,this._searchLoading=!1):e===`discover`&&(this._discover=this._origDiscover,this._discoverLoading=!1)}_initEditors(){this._initDescEditor(),this._initFooterEditor()}_initDescEditor(){let e=this.querySelector(`[data-settings-desc-editor]`);if(!e||this._descEditor)return;this._descEditor=b({element:e,placeholder:this.siteDescriptionFallback,content:this._siteDescription||void 0,onUpdate:e=>{this._siteDescription=e,this._syncSiteDirty()}}),this._siteDescription=y(this._descEditor.getJSON());let t=e.querySelector(`.ProseMirror`);t&&(t.style.outline=`none`,t.style.minHeight=`3rem`)}_initFooterEditor(){let e=this.querySelector(`[data-settings-footer-editor]`);if(!e||this._footerEditor)return;this._footerEditor=b({element:e,content:this._siteFooter||void 0,onUpdate:e=>{this._siteFooter=e,this._syncSiteDirty()}}),this._siteFooter=y(this._footerEditor.getJSON());let t=e.querySelector(`.ProseMirror`);t&&(t.style.outline=`none`,t.style.minHeight=`6rem`)}_syncSiteDirty(){this._siteDirty=this._siteName!==this._origSite.siteName||this._siteDescription!==this._origSite.siteDescription||this._siteFooter!==this._origSite.siteFooter}_saveSite(){!this._siteLoading&&this._siteDirty&&(this._siteLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general`,data:{siteName:this._siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter},section:`site`}})))}_syncLocaleDirty(){this._localeDirty=this._timeZone!==this._origLocale.timeZone}_saveLocale(){!this._localeLoading&&this._localeDirty&&(this._localeLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/time`,data:{timeZone:this._timeZone},section:`time`}})))}_saveMainRssFeed(e){this._feedLoading||e===this._mainRssFeed||(this._mainRssFeed=e,this._feedLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/feeds`,data:{mainRssFeed:e},section:`feeds`}})))}_saveHomeToggle(e){this._homeLoading||(this._showJantBrandingOnHome=e,this._homeLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/home`,data:{showJantBrandingOnHome:e},section:`home`}})))}_saveSearchToggle(e){this.demoMode||this._searchLoading||(this._noindex=!e,this._searchLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/search`,data:{allowIndexing:e},section:`search`}})))}_effectiveDiscoverMode(e={}){return ee({storedValue:this._discover||null,defaultValue:this.discoverDefault||null,demoMode:this.demoMode,noindex:e.noindex??this._noindex,rssFeedsEnabled:this.feedsEnabled})}_onDiscoverToggle(e){this._saveDiscover(e?`latest`:`off`)}_saveDiscover(e){this._discoverLoading||(this._discover=e,this._discoverLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/discover`,data:{discover:e},section:`discover`}})))}_onKeydown(e,t,n,r){e.isComposing||e.keyCode===229||e.key===`Enter`&&!r&&n&&!(e.target instanceof HTMLTextAreaElement)&&(e.preventDefault(),t())}_renderSaveAction(e,t,n){return o`
2
2
  <div class="flex mt-4">
3
3
  <button
4
4
  type="button"
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as createApp$1 } from "./app-CKQ9PqAr.js";
1
+ import { n as createApp$1 } from "./app-CbOZ2Irh.js";
2
2
  //#region src/index.ts
3
3
  /**
4
4
  * Jant - A microblog system
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as getTelegramWebhookSecret, B as isAssetPath, C as getConfiguredSingleSitePathPrefix, D as getPort, E as getHostedControlPlaneBaseUrl, F as getFontThemeCssVariables, I as resolveCjkFontProfile, L as buildThemeStyle, M as now, N as BUILTIN_FONT_THEMES, O as getSiteResolutionMode, P as getCjkFontCssVariables, R as BUILTIN_COLOR_THEMES, S as getConfiguredSingleSiteOrigin, T as getEnvString, _ as resolveConfig, a as createNodeCliRuntime, b as setWebhook, c as createSiteService, d as createExportService, f as createStorageDriver, g as schema_exports, h as createNodeDatabase, i as listPendingMigrations, j as shouldTrustProxy, k as getTelegramBotPool, l as getHostBasedStartupConfigurationIssues, m as sqliteSchemaBundle, n as createApp, o as createNodeRequestRuntime, p as pgSchemaBundle, r as PendingMigrationsError, s as setUpNodeInstance, u as resolveDatabaseDialect, v as getWebhookUrl, w as getConfiguredStorageDriver, x as getEnvValueIssues, y as setMyCommands, z as getPublicAssetBasePath } from "./app-CKQ9PqAr.js";
1
+ import { A as getTelegramBotPool, B as getPublicAssetBasePath, C as getConfiguredSingleSiteOrigin, D as getHostedControlPlaneBaseUrl, E as getEnvString, F as getCjkFontCssVariables, I as getFontThemeCssVariables, L as resolveCjkFontProfile, M as shouldTrustProxy, N as now, O as getPort, P as BUILTIN_FONT_THEMES, R as buildThemeStyle, S as getEnvValueIssues, T as getConfiguredStorageDriver, V as isAssetPath, _ as createNodeDatabase, a as createNodeCliRuntime, b as setMyCommands, c as createSiteService, d as resolveDatabaseDialect, f as createExportService, g as sqliteSchemaBundle, h as pgSchemaBundle, i as listPendingMigrations, j as getTelegramWebhookSecret, k as getSiteResolutionMode, l as viewBuffer, m as resolveConfig, n as createApp, o as createNodeRequestRuntime, p as createStorageDriver, r as PendingMigrationsError, s as setUpNodeInstance, u as getHostBasedStartupConfigurationIssues, v as schema_exports, w as getConfiguredSingleSitePathPrefix, x as setWebhook, y as getWebhookUrl, z as BUILTIN_COLOR_THEMES } from "./app-CbOZ2Irh.js";
2
2
  import { drizzle } from "drizzle-orm/better-sqlite3";
3
3
  import { serve } from "@hono/node-server";
4
4
  import Database from "better-sqlite3";
@@ -626,7 +626,7 @@ async function createNodeRequestHandler(options) {
626
626
  async function start(env = process.env, app, options = {}) {
627
627
  const handler = await createNodeRequestHandler({
628
628
  env,
629
- app: async () => app ?? (await import("./app-CKQ9PqAr.js").then((n) => n.t)).createApp(),
629
+ app: async () => app ?? (await import("./app-CbOZ2Irh.js").then((n) => n.t)).createApp(),
630
630
  assetRoot: options.assetRoot
631
631
  });
632
632
  const hostname = resolveHost(env);
@@ -664,6 +664,7 @@ async function start(env = process.env, app, options = {}) {
664
664
  });
665
665
  });
666
666
  } finally {
667
+ await viewBuffer.flush();
667
668
  await handler.close();
668
669
  }
669
670
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jant/core",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "A modern, open-source microblogging platform built on Cloudflare Workers",
5
5
  "type": "module",
6
6
  "exports": {
package/src/app.tsx CHANGED
@@ -79,6 +79,8 @@ import { defaultCacheControl, noStore } from "./middleware/cache-control.js";
79
79
  import { requireOnboarding } from "./middleware/onboarding.js";
80
80
  import { errorHandler, notFoundHandler } from "./middleware/error-handler.js";
81
81
  import { prefetchSettings, withConfig } from "./middleware/config.js";
82
+ import { viewCounter } from "./middleware/view-counter.js";
83
+ import { viewConfirmRoutes } from "./routes/view-confirm.js";
82
84
  import { secureHeadersMiddleware } from "./middleware/secure-headers.js";
83
85
  import { apiCors } from "./middleware/cors.js";
84
86
  import { rejectCrossOriginWrites } from "./middleware/cross-origin.js";
@@ -549,6 +551,12 @@ export function createApp(): HonoApp {
549
551
  app.use("*", withConfig());
550
552
  app.use("*", i18nMiddleware());
551
553
 
554
+ // Page views: the page routes below name what they rendered
555
+ // (`c.var.viewTarget`), this marks the response with a view token, and
556
+ // `/_/seen` counts the view once the browser confirms it. Needs the
557
+ // config above for the stats switch.
558
+ app.use("*", viewCounter());
559
+
552
560
  // --- Routes that need config ---
553
561
 
554
562
  // Public machine-readable site guide
@@ -606,6 +614,7 @@ export function createApp(): HonoApp {
606
614
  app.route("/subscribe", subscribeRoutes);
607
615
  app.route("/latest", latestRoutes);
608
616
  app.route("/", partialPageRoutes);
617
+ app.route("/_", viewConfirmRoutes);
609
618
  app.route("/_", brandRoutes);
610
619
  app.route("/_", themeSampleRoutes);
611
620
  app.route("/collections", collectionsPageRoutes);
@@ -347,6 +347,7 @@ export interface ComposeLabels {
347
347
  editing: string;
348
348
  composeDialogLabel: string;
349
349
  slashHint: string;
350
+ highlight: string;
350
351
  tableControls: TableControlLabels;
351
352
  collectionFormLabels: CollectionFormLabels;
352
353
  }
@@ -2970,6 +2970,7 @@ export class JantComposeDialog extends LitElement {
2970
2970
  content,
2971
2971
  toolbarMode: "compose",
2972
2972
  tableControlLabels: this.labels.tableControls,
2973
+ highlightLabel: this.labels.highlight,
2973
2974
  });
2974
2975
  this._focusAttachedEditorBoundary(content);
2975
2976
  });
@@ -1130,6 +1130,7 @@ export class JantComposeEditor extends LitElement {
1130
1130
  },
1131
1131
  imageNodeLabels: getInlineImageNodeLabels(this.labels),
1132
1132
  tableControlLabels: this.labels.tableControls,
1133
+ highlightLabel: this.labels.highlight,
1133
1134
  });
1134
1135
  this._lastEditorSelection = this._readEditorSelection();
1135
1136
  // An editor built from existing content — after a format switch, or on a
@@ -1331,6 +1332,34 @@ export class JantComposeEditor extends LitElement {
1331
1332
  return this._attachments.some((a) => a.clientId === clientId);
1332
1333
  }
1333
1334
 
1335
+ /**
1336
+ * Ask for posters for the uploaded videos that have none. A clip that came
1337
+ * in through the API without a poster gets one made here, in the author's
1338
+ * browser, the only place every deployment can decode video. The bridge
1339
+ * stores it and shows it on the card.
1340
+ */
1341
+ #requestMissingPosters() {
1342
+ const attachments = this._attachments.flatMap((a) =>
1343
+ a.file.type.startsWith("video/") &&
1344
+ a.mediaId &&
1345
+ a.remoteUrl &&
1346
+ a.posterUrl === null
1347
+ ? [{ clientId: a.clientId, mediaId: a.mediaId, url: a.remoteUrl }]
1348
+ : [],
1349
+ );
1350
+ if (attachments.length === 0) return;
1351
+
1352
+ // Wait for the render, so the event leaves from a connected editor.
1353
+ void this.updateComplete.then(() => {
1354
+ this.dispatchEvent(
1355
+ new CustomEvent("jant:video-posters-missing", {
1356
+ bubbles: true,
1357
+ detail: { attachments },
1358
+ }),
1359
+ );
1360
+ });
1361
+ }
1362
+
1334
1363
  /** Pre-fill all fields for edit mode or draft restore */
1335
1364
  populate(data: {
1336
1365
  format: string;
@@ -1418,6 +1447,7 @@ export class JantComposeEditor extends LitElement {
1418
1447
  }));
1419
1448
  this._attachments = attachments;
1420
1449
  this._attachmentOrder = attachments.map((a) => a.clientId);
1450
+ this.#requestMissingPosters();
1421
1451
  }
1422
1452
 
1423
1453
  // Restore attached texts from server data
@@ -165,6 +165,7 @@ export class JantComposeFullscreen extends LitElement {
165
165
  },
166
166
  imageNodeLabels: getInlineImageNodeLabels(this.labels),
167
167
  tableControlLabels: this.labels.tableControls,
168
+ highlightLabel: this.labels.highlight,
168
169
  });
169
170
 
170
171
  const selection = this._selection;
@@ -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,
@@ -31,6 +31,7 @@ const bubbleMenuKey = new PluginKey("bubbleMenu");
31
31
  // SVG icons (16×16, stroke-based)
32
32
  const ICONS = {
33
33
  bold: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 12h9a4 4 0 0 1 0 8H6V4h8a4 4 0 0 1 0 8"/></svg>`,
34
+ highlight: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 11 8-8 4 4-8 8-4-4Z"/><path d="m9 11-3 3 4 4 3-3M6 14l-3 7 7-3M3 21h7"/></svg>`,
34
35
  italic: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>`,
35
36
  h1: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17 12l3-2v10"/></svg>`,
36
37
  h2: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"/></svg>`,
@@ -169,6 +170,7 @@ export function clearFormatting(editor: Editor): void {
169
170
  function getButtons(
170
171
  editor: Editor,
171
172
  toolbarMode: FormattingToolbarMode,
173
+ highlightLabel: string,
172
174
  ): BubbleBtn[] {
173
175
  if (toolbarMode === "compose") {
174
176
  return [
@@ -186,6 +188,13 @@ function getButtons(
186
188
  action: () => toggleMarkAndExit(editor, "italic"),
187
189
  isActive: () => editor.isActive("italic"),
188
190
  },
191
+ {
192
+ key: "highlight",
193
+ icon: ICONS.highlight,
194
+ title: highlightLabel,
195
+ action: () => toggleMarkAndExit(editor, "highlight"),
196
+ isActive: () => editor.isActive("highlight"),
197
+ },
189
198
  {
190
199
  key: "sep",
191
200
  icon: "",
@@ -231,6 +240,13 @@ function getButtons(
231
240
  action: () => toggleMarkAndExit(editor, "italic"),
232
241
  isActive: () => editor.isActive("italic"),
233
242
  },
243
+ {
244
+ key: "highlight",
245
+ icon: ICONS.highlight,
246
+ title: highlightLabel,
247
+ action: () => toggleMarkAndExit(editor, "highlight"),
248
+ isActive: () => editor.isActive("highlight"),
249
+ },
234
250
  {
235
251
  key: "h1",
236
252
  icon: ICONS.h1,
@@ -281,12 +297,14 @@ export const BubbleMenu = Extension.create({
281
297
  addOptions() {
282
298
  return {
283
299
  toolbarMode: "default" as FormattingToolbarMode,
300
+ highlightLabel: "Highlight",
284
301
  };
285
302
  },
286
303
 
287
304
  addProseMirrorPlugins() {
288
305
  const editor = this.editor;
289
306
  const toolbarMode = this.options.toolbarMode as FormattingToolbarMode;
307
+ const highlightLabel = this.options.highlightLabel;
290
308
  let el: HTMLElement | null = null;
291
309
  let buttons: BubbleBtn[] = [];
292
310
  const btnEls: Map<string, HTMLButtonElement> = new Map();
@@ -298,7 +316,7 @@ export const BubbleMenu = Extension.create({
298
316
  el.style.position = "fixed";
299
317
  el.style.display = "none";
300
318
 
301
- buttons = getButtons(editor, toolbarMode);
319
+ buttons = getButtons(editor, toolbarMode, highlightLabel);
302
320
  for (const btn of buttons) {
303
321
  if (btn.key === "sep") {
304
322
  const sep = document.createElement("span");
@@ -310,6 +328,7 @@ export const BubbleMenu = Extension.create({
310
328
  b.type = "button";
311
329
  b.innerHTML = btn.icon;
312
330
  b.title = btn.title;
331
+ b.setAttribute("aria-label", btn.title);
313
332
  b.className = "tiptap-bubble-btn";
314
333
  b.addEventListener("mousedown", (e) => {
315
334
  e.preventDefault();
@@ -372,7 +391,11 @@ export const BubbleMenu = Extension.create({
372
391
  for (const btn of buttons) {
373
392
  if (btn.key === "sep") continue;
374
393
  const b = btnEls.get(btn.key);
375
- if (b) b.classList.toggle("is-active", btn.isActive(editor.view));
394
+ if (b) {
395
+ const active = btn.isActive(editor.view);
396
+ b.classList.toggle("is-active", active);
397
+ b.setAttribute("aria-pressed", String(active));
398
+ }
376
399
  }
377
400
  }
378
401
 
@@ -27,6 +27,7 @@ export interface CreateEditorOptions {
27
27
  onBlur?: () => void;
28
28
  onSelectionUpdate?: (selection: { from: number; to: number }) => void;
29
29
  toolbarMode?: FormattingToolbarMode;
30
+ highlightLabel?: string;
30
31
  pasteMedia?: PasteMediaOptions;
31
32
  rehostImages?: RehostImagesOptions;
32
33
  imageNodeLabels?: Partial<ImageNodeLabels>;
@@ -45,6 +46,7 @@ export function createTiptapEditor(options: CreateEditorOptions): Editor {
45
46
  extensions: createEditorExtensions({
46
47
  placeholder: options.placeholder,
47
48
  toolbarMode: options.toolbarMode,
49
+ highlightLabel: options.highlightLabel,
48
50
  pasteMedia: options.pasteMedia,
49
51
  rehostImages: options.rehostImages,
50
52
  imageNodeLabels: options.imageNodeLabels,
@@ -38,6 +38,7 @@ import {
38
38
  export interface EditorExtensionOptions {
39
39
  placeholder?: string;
40
40
  toolbarMode?: FormattingToolbarMode;
41
+ highlightLabel?: string;
41
42
  pasteMedia?: PasteMediaOptions;
42
43
  rehostImages?: RehostImagesOptions;
43
44
  imageNodeLabels?: Partial<ImageNodeLabels>;
@@ -129,6 +130,9 @@ export function createEditorExtensions(
129
130
  RehostImages.configure(options.rehostImages ?? {}),
130
131
  BubbleMenu.configure({
131
132
  toolbarMode: options.toolbarMode ?? "default",
133
+ ...(options.highlightLabel
134
+ ? { highlightLabel: options.highlightLabel }
135
+ : {}),
132
136
  }),
133
137
  LinkToolbar,
134
138
  InsertParagraphAround,
@@ -12,15 +12,19 @@
12
12
  * browser to double-rotate)
13
13
  * - Clears the alternate_group track flag (mediabunny sets it non-zero,
14
14
  * which stops Safari's native video controls from auto-hiding)
15
- * - Extracts poster frame + blurhash during processing
15
+ * - Extracts poster frame + blurhash during processing, and makes a poster
16
+ * for a clip already uploaded without one
16
17
  *
17
18
  * Requires WebCodecs API support — check `isSupported()` before use.
18
19
  */
19
20
 
20
- import type { VideoCodec } from "mediabunny";
21
+ import type { InputVideoTrack, VideoCodec } from "mediabunny";
21
22
  import { loadMediabunny } from "./mediabunny.js";
22
23
  import { encode } from "blurhash";
23
- import { normalizeDurationSeconds } from "../lib/video-playback.js";
24
+ import {
25
+ getPosterFrameSeconds,
26
+ normalizeDurationSeconds,
27
+ } from "../lib/video-playback.js";
24
28
  import { zeroTrackAlternateGroups } from "../lib/mp4-track-flags.js";
25
29
 
26
30
  /** Maximum pixels for the long edge of the output video. */
@@ -169,9 +173,66 @@ function drawFrame(
169
173
  return { canvas, ctx };
170
174
  }
171
175
 
176
+ /**
177
+ * Capture a clip's poster frame and blurhash from its video track. The frame
178
+ * is the one `getPosterFrameSeconds` names, the same one a reader's browser
179
+ * draws for a clip stored without a poster.
180
+ *
181
+ * @param videoTrack - The clip's primary video track
182
+ * @param duration - Clip length in seconds, when known
183
+ * @returns Poster blob (640px-wide WebP) and blurhash, each when it could be made
184
+ */
185
+ async function captureStill(
186
+ videoTrack: InputVideoTrack,
187
+ duration: number | undefined,
188
+ ): Promise<{ poster?: Blob; blurhash?: string }> {
189
+ const { CanvasSink } = await loadMediabunny();
190
+ const wrapped = await optional("capture frame", () =>
191
+ new CanvasSink(videoTrack).getCanvas(getPosterFrameSeconds(duration)),
192
+ );
193
+ if (!wrapped) return {};
194
+
195
+ const canvas = wrapped.canvas as HTMLCanvasElement;
196
+ const srcW = canvas.width;
197
+ const srcH = canvas.height;
198
+
199
+ // Poster: 640px wide WebP
200
+ const posterScale = Math.min(POSTER_WIDTH / srcW, 1);
201
+ const posterFrame = drawFrame(
202
+ canvas,
203
+ Math.round(srcW * posterScale),
204
+ Math.round(srcH * posterScale),
205
+ );
206
+ const poster = posterFrame
207
+ ? await optional(
208
+ "encode poster",
209
+ () =>
210
+ new Promise<Blob | undefined>((resolve) => {
211
+ posterFrame.canvas.toBlob(
212
+ (blob) => resolve(blob ?? undefined),
213
+ "image/webp",
214
+ 0.8,
215
+ );
216
+ }),
217
+ )
218
+ : undefined;
219
+
220
+ // Blurhash: 32px canvas, 4×3 components
221
+ const bhScale = Math.min(BLURHASH_SIZE / srcW, BLURHASH_SIZE / srcH, 1);
222
+ const bw = Math.max(Math.round(srcW * bhScale), 1);
223
+ const bh = Math.max(Math.round(srcH * bhScale), 1);
224
+ const bhFrame = drawFrame(canvas, bw, bh);
225
+ const blurhash = bhFrame
226
+ ? await optional("encode blurhash", async () =>
227
+ encode(bhFrame.ctx.getImageData(0, 0, bw, bh).data, bw, bh, 4, 3),
228
+ )
229
+ : undefined;
230
+
231
+ return { poster, blurhash };
232
+ }
233
+
172
234
  /**
173
235
  * Probe a video file and extract its poster frame and blurhash in one pass.
174
- * Seeks to `min(duration × 0.1, 1s)` and captures the frame.
175
236
  *
176
237
  * Returns the source dimensions, codec, and bitrate alongside, so the caller
177
238
  * can decide whether a re-encode is needed at all — and at what bitrate —
@@ -186,7 +247,7 @@ function drawFrame(
186
247
  * @returns Poster blob (640px-wide WebP), blurhash, dimensions, codec, bitrate
187
248
  */
188
249
  async function probeSource(file: File): Promise<SourceProbe> {
189
- const { Input, BlobSource, ALL_FORMATS, CanvasSink } = await loadMediabunny();
250
+ const { Input, BlobSource, ALL_FORMATS } = await loadMediabunny();
190
251
  const input = new Input({
191
252
  source: new BlobSource(file),
192
253
  formats: ALL_FORMATS,
@@ -212,8 +273,7 @@ async function probeSource(file: File): Promise<SourceProbe> {
212
273
  input.computeDuration(),
213
274
  );
214
275
 
215
- // Everything the caller needs to plan the conversion.
216
- const base: SourceProbe = {
276
+ return {
217
277
  sourceWidth: videoTrack.displayWidth,
218
278
  sourceHeight: videoTrack.displayHeight,
219
279
  rotation: videoTrack.rotation,
@@ -221,54 +281,44 @@ async function probeSource(file: File): Promise<SourceProbe> {
221
281
  duration === undefined ? undefined : normalizeDurationSeconds(duration),
222
282
  videoCodec,
223
283
  videoBitrate,
284
+ ...(await captureStill(videoTrack, duration)),
224
285
  };
286
+ } finally {
287
+ input.dispose();
288
+ }
289
+ }
225
290
 
226
- // A tenth of the way in, so the still is not the fade-from-black most
227
- // clips open on. With no duration to take a tenth of, the opening frame
228
- // is the only one we can name.
229
- const seekTime = duration === undefined ? 0 : Math.min(duration * 0.1, 1);
230
- const wrapped = await optional("capture frame", () =>
231
- new CanvasSink(videoTrack).getCanvas(seekTime),
232
- );
233
- if (!wrapped) return base;
234
-
235
- const canvas = wrapped.canvas as HTMLCanvasElement;
236
- const srcW = canvas.width;
237
- const srcH = canvas.height;
238
-
239
- // Poster: 640px wide WebP
240
- const posterScale = Math.min(POSTER_WIDTH / srcW, 1);
241
- const posterFrame = drawFrame(
242
- canvas,
243
- Math.round(srcW * posterScale),
244
- Math.round(srcH * posterScale),
291
+ /**
292
+ * Make a poster for a clip that is already uploaded, reading the file where
293
+ * it is stored. mediabunny fetches it in byte ranges, so only the metadata
294
+ * and the samples up to the poster frame cross the network, not the clip.
295
+ *
296
+ * @param url - The stored clip's address; its host has to allow this origin
297
+ * @returns Poster blob (640px-wide WebP), or `undefined` when the browser
298
+ * cannot decode video or the file could not be read
299
+ * @example
300
+ * ```ts
301
+ * const poster = await VideoProcessor.extractPosterFromUrl(media.url);
302
+ * ```
303
+ */
304
+ async function extractPosterFromUrl(url: string): Promise<Blob | undefined> {
305
+ if (typeof VideoDecoder === "undefined") return undefined;
306
+
307
+ const { Input, UrlSource, ALL_FORMATS } = await loadMediabunny();
308
+ const input = new Input({
309
+ source: new UrlSource(url),
310
+ formats: ALL_FORMATS,
311
+ });
312
+ try {
313
+ const videoTrack = await optional("open video track", () =>
314
+ input.getPrimaryVideoTrack(),
245
315
  );
246
- const poster = posterFrame
247
- ? await optional(
248
- "encode poster",
249
- () =>
250
- new Promise<Blob | undefined>((resolve) => {
251
- posterFrame.canvas.toBlob(
252
- (blob) => resolve(blob ?? undefined),
253
- "image/webp",
254
- 0.8,
255
- );
256
- }),
257
- )
258
- : undefined;
259
-
260
- // Blurhash: 32px canvas, 4×3 components
261
- const bhScale = Math.min(BLURHASH_SIZE / srcW, BLURHASH_SIZE / srcH, 1);
262
- const bw = Math.max(Math.round(srcW * bhScale), 1);
263
- const bh = Math.max(Math.round(srcH * bhScale), 1);
264
- const bhFrame = drawFrame(canvas, bw, bh);
265
- const blurhash = bhFrame
266
- ? await optional("encode blurhash", async () =>
267
- encode(bhFrame.ctx.getImageData(0, 0, bw, bh).data, bw, bh, 4, 3),
268
- )
269
- : undefined;
316
+ if (!videoTrack) return undefined;
270
317
 
271
- return { ...base, poster, blurhash };
318
+ const duration = await optional("compute duration", () =>
319
+ input.computeDuration(),
320
+ );
321
+ return (await captureStill(videoTrack, duration)).poster;
272
322
  } finally {
273
323
  input.dispose();
274
324
  }
@@ -614,4 +664,8 @@ function probeVideoDimensions(
614
664
  });
615
665
  }
616
666
 
617
- export const VideoProcessor = { isSupported, processToFile };
667
+ export const VideoProcessor = {
668
+ isSupported,
669
+ processToFile,
670
+ extractPosterFromUrl,
671
+ };