@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
@@ -0,0 +1,2004 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_assets/chunks/emoji-mart-C4RpRKcU.js","_assets/chunks/rolldown-runtime-hePW80VL.js","_assets/chunks/mediabunny-DRaCQ1r-.js"])))=>i.map(i=>d[i]);
2
+ import{c as e,r as t}from"./chunks/runtime-paths-y0_gHowM.js";import{o as n,s as r}from"./chunks/footnote-rail-9zwl6jtV.js";import{c as i,f as a,i as o,l as s,n as c,s 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{t as p}from"./chunks/preload-helper-Czpn1I53.js";import{c as m,i as h,n as g,o as _,r as v,s as y,t as b}from"./chunks/unsafe-svg-CUrgo4Xg.js";import{_ as x,h as S,p as C}from"./chunks/types-DrYFqJH2.js";import{r as w,t as ee}from"./chunks/slug-format-BuCPjSrB.js";import{a as te,f as T,i as E,n as D,o as O,r as k,s as ne,t as re,u as A}from"./chunks/sortable-list-DJXwkaOv.js";import{_ as j,a as M,c as N,d as P,f as ie,g as ae,h as oe,i as se,l as ce,m as le,n as ue,o as de,p as fe,s as pe,u as me}from"./chunks/create-editor-hWapNE40.js";var he=e=>e??c;function ge(e){let t=e.trim().toLowerCase();if(!t)return;let n=t.split(`-`)[0];if(n===`zh`){let e=t.slice(3);return e===`hant`||e===`tw`||e===`hk`||e===`mo`?`zh-Hant`:`zh-Hans`}if(n===`ja`)return`ja`;if(n===`ko`)return`ko`}var _e=`们这会说对时国学个来过现发经应关点无义与从门问间东车长马鸟鱼见贝页风飞头语话认识讲论议记让试该请读谁调谈变边达运还进远连适选递邮释钟银错锁闭开闻阅队阶阳阴陆陈险隐难静韩须顾频颜题类飘饭饮饰馆驻驾验骑骗体处备够夺奋妇妈宁宝实宽宾寻导尔尘尝尽层属岁岂岛币帅帮归当录彻忆态怀恋恶悬惊惧惨愤愿战户扩扫扬担拟挂挤挥换据摄击敌断旧显术机杀杂权条极构柜标树桥检楼欢欧残毁气汉汤沟泪洁济浏浅浆涛润涨渐渔渗湾湿满滨滤灭灯灵灾炉烦烧热营爱状犹狮独狱猎猪献猫环电画畅疗疯皱监盘矿码确础礼祸种积称稳穷窃竞笔筹简签粮紧纪纯纲纳纵纷纸线组细织终绍结绕绘给络绝统继绩绪续维综绿缓编缘缩缴网罗罚罢习联声职聪肃肠胀脑脱腊舰艰节苏药荐荡获萧蓝虏虚虽蚀蜡补装观规觉计订讨训讯词译诉诊证评诚误诸课谅谓谢谱贡财责贤败货质贩贪购贯贱贴贵贷贸费贺资赏赐赔赖赚赛赢赠赶趋践轨转轮软载较辅辈辉输辐辑辞迁迈违迟逊遗邓邻郑针钉钓钙钝钞钢钥钦钩钱钻铁铃铅铜铝铺链销锋锐锦键镇镜闪闯闲闷闹阀阁阵际隶随雾项顶预领颇颈颗颠饥饱饼馈驰驱驶骂骄鲁鲜鸡鸣鸦鸭鸽鹅鹰麦黄齐齿龄龙龟儿优传伤侦侧俭债倾偿储兰兴军农决净减凤凭则刘创剑剧劝办务动励劳势勋医华单卖卫厅历压厌厨参叶号叹吗启呐员呜响哑唤啸喷嘱团园围图圆场坏块坚坛垒垦堕墙壮壳复`,ve=`們這會說對時國學後個來過現發經應關點無義與從門問間東車長馬鳥魚見貝頁風飛頭語話認識講論議記讓試該請讀誰調談變邊達運還進遠連適選遞郵釋鐘銀錯鎖閉開聞閱隊階陽陰陸陳險隱難靜韓須顧頻顏題類飄飯飲飾館駐駕驗騎騙體處備夠奪奮婦媽寧寶實寬賓尋導爾塵嘗盡層屬歲豈島幣帥幫歸當錄徹憶態懷戀惡懸驚懼慘憤願戰戶擴掃揚擔擬掛擠揮換據攝擊敵斷舊顯術機殺雜權條極構櫃標樹橋檢樓歡歐殘毀氣漢湯溝淚潔濟瀏淺漿濤潤漲漸漁滲灣濕滿濱濾滅燈靈災爐煩燒熱營愛狀猶獅獨獄獵豬獻貓環電畫暢療瘋皺監盤礦碼確礎禮禍種積稱穩窮竊競筆籌簡簽糧緊紀純綱納縱紛紙線組細織終紹結繞繪給絡絕統繼績緒續維綜綠緩編緣縮繳網羅罰罷習聯聲職聰肅腸脹腦脫臘艦艱節蘇藥薦蕩獲蕭藍虜虛雖蝕蠟補裝觀規覺計訂討訓訊詞譯訴診證評誠誤諸課諒謂謝譜貢財責賢敗貨質販貪購貫賤貼貴貸貿費賀資賞賜賠賴賺賽贏贈趕趨踐軌轉輪軟載較輔輩輝輸輻輯辭遷邁違遲遜遺鄧鄰鄭針釘釣鈣鈍鈔鋼鑰欽鉤錢鑽鐵鈴鉛銅鋁鋪鏈銷鋒銳錦鍵鎮鏡閃闖閒悶鬧閥閣陣際隸隨霧項頂預領頗頸顆顛飢飽餅饋馳驅駛罵驕魯鮮雞鳴鴉鴨鴿鵝鷹麥黃齊齒齡龍龜兒優傳傷偵側儉債傾償儲蘭興軍農衝決淨減鳳憑劃則劉創劍劇勸辦務動勵勞勢勳醫華單賣衛廳歷壓厭廚參疊隻臺葉號嘆嗎啟吶員嗚響啞喚嘯噴囑團園圍圖圓場壞塊堅壇壘墾墮牆壯殼複`,ye=new Set(_e),be=new Set(ve);function xe(e){let t={hangul:0,kana:0,han:0,latin:0,simplified:0,traditional:0};for(let n of e){let e=n.codePointAt(0);if(e!==void 0){if(e>=44032&&e<=55203||e>=4352&&e<=4607||e>=12592&&e<=12687){t.hangul++;continue}if(e>=12352&&e<=12447||e>=12448&&e<=12543||e>=12784&&e<=12799){t.kana++;continue}if(e>=19968&&e<=40959||e>=13312&&e<=19903||e>=63744&&e<=64255){t.han++,ye.has(n)?t.simplified++:be.has(n)&&t.traditional++;continue}(e>=65&&e<=90||e>=97&&e<=122||e>=192&&e<=591)&&t.latin++}}return t}var Se=3,Ce=10;function we(e){let t=xe(e),n=(t.hangul+t.kana+t.han)*Se;return n>=t.latin&&n>=Ce?t.hangul>0?`ko`:t.kana>0?`ja`:t.simplified>t.traditional?`zh-Hans`:t.traditional>t.simplified?`zh-Hant`:`han`:t.latin>=Ce?`latin`:null}function Te(e,t){let{languages:n}=t;if(n.length===0)return null;let r=we(e);if(!r)return null;if(r===`latin`){let e=n.filter(e=>!ge(e));return e.length===1?e[0]:null}if(r===`han`){let e=n.filter(e=>{let t=ge(e);return t===`zh-Hans`||t===`zh-Hant`});return e.length===1?e[0]:null}return n.find(e=>ge(e)===r)??null}var Ee=/^—\s*(.*?)(?:\s+(https?:\/\/\S+))?\s*$/;function De(e){return e?JSON.parse(JSON.stringify(e)):null}function Oe(e){return e?typeof e.text==`string`?e.text:Array.isArray(e.content)?e.content.map(Oe).join(``):``:``}function ke(e,t=2){return{type:`heading`,attrs:{level:t},content:[{type:`text`,text:e}]}}function Ae(e){return e?{type:`paragraph`,content:[{type:`text`,text:e}]}:{type:`paragraph`}}function je(e){return{type:`paragraph`,content:[{type:`text`,text:e,marks:[{type:`link`,attrs:{href:e}}]}]}}function Me(e){let t=Ee.exec(e.trim());return t?{author:t[1].trim(),url:t[2]??null}:{author:``,url:null}}function Ne(e){if(!e)return null;if(Array.isArray(e.marks)){let t=e.marks.find(e=>e.type===`link`)?.attrs?.href;if(typeof t==`string`&&t)return t}if(Array.isArray(e.content))for(let t of e.content){let e=Ne(t);if(e)return e}return null}function Pe(e,t){let n=e.trim(),r=t?.trim()??``;if(!n&&!r)return null;let i=e=>({type:`text`,text:e,marks:[{type:`link`,attrs:{href:r}}]});return n&&r?{type:`paragraph`,content:[{type:`text`,text:`— `},i(n)]}:n?{type:`paragraph`,content:[{type:`text`,text:`— ${n}`}]}:{type:`paragraph`,content:[{type:`text`,text:`— `},i(r)]}}function Fe(e,t){let n=e.split(`
3
+ `).map(e=>Ae(e));return t&&n.push(t),{type:`blockquote`,content:n}}function Ie(e,t,n){if(e===t)return n;let r={...n},i=De(n.bodyJson),a=Array.isArray(i?.content)?[...i.content]:[];if(t===`link`&&r.url===``){let e=a[0],t=Ne(e);t&&e?.type===`paragraph`&&Array.isArray(e.content)&&e.content.length===1&&Oe(e)===t&&(r.url=t,a.shift())}if(t===`quote`&&r.quoteText===``&&a[0]?.type===`blockquote`){let e=Array.isArray(a[0].content)?[...a[0].content]:[],t=e[e.length-1],n=Oe(t);if(e.length>0&&/^—/.test(n.trim())){let i=Me(n),a=Ne(t)??i.url,o=i.author===a?``:i.author;o&&(r.quoteAuthor=r.quoteAuthor||o),a&&r.url===``&&(r.url=a),e.pop()}r.quoteText=e.map(Oe).join(`
4
+ `).trim(),a.shift()}let o=[];if(t===`quote`&&r.title.trim()!==``&&(o.push(ke(r.title.trim())),r.title=``),t!==`quote`&&r.quoteText.trim()!==``){let e=t===`note`?r.url:null;o.push(Fe(r.quoteText,Pe(r.quoteAuthor,e))),r.quoteText=``,r.quoteAuthor=``,t===`note`&&(r.url=``)}else t===`note`&&r.url.trim()!==``&&(o.push(je(r.url.trim())),r.url=``);return o.length&&a.unshift(...o),r.bodyJson=a.length?{type:`doc`,content:a}:null,t===`note`&&r.title.trim().length>0&&(r.showTitle=!0),r}var Le=[`image/jpeg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`,`image/avif`,`image/bmp`,`image/x-icon`],Re=[`video/mp4`,`video/webm`,`video/quicktime`,`video/x-msvideo`,`video/x-matroska`,`video/mpeg`,`video/3gpp`,`video/x-flv`,`video/ogg`],ze=[`audio/mpeg`,`audio/ogg`,`audio/wav`,`audio/mp4`,`audio/x-m4a`,`audio/flac`,`audio/aac`,`audio/webm`,`audio/x-aiff`,`audio/opus`,`audio/3gpp`,`audio/midi`],Be=[`application/pdf`,`application/epub+zip`,`application/x-mobipocket-ebook`,`application/vnd.amazon.ebook`],Ve=[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`,`application/vnd.oasis.opendocument.text`,`application/vnd.oasis.opendocument.spreadsheet`,`application/vnd.oasis.opendocument.presentation`,`application/vnd.apple.pages`,`application/vnd.apple.numbers`,`application/vnd.apple.keynote`],He=[`text/plain`,`text/markdown`,`text/csv`,`text/html`,`text/css`,`text/javascript`,`text/xml`,`text/rtf`,`text/tab-separated-values`,`text/calendar`,`application/json`,`application/xml`,`application/yaml`,`application/toml`],Ue=[`application/zip`,`application/x-tar`,`application/gzip`,`application/x-bzip2`,`application/x-7z-compressed`,`application/x-rar-compressed`,`application/zstd`],We=[`font/ttf`,`font/otf`,`font/woff`,`font/woff2`],Ge=[`model/gltf+json`,`model/gltf-binary`,`model/obj`,`application/x-figma`,`image/vnd.dxf`],Ke=[`application/sql`,`application/wasm`,`application/x-ipynb+json`,`application/x-sh`,`application/x-python-code`],qe=new Map([...Le.map(e=>[e,`image`]),...Re.map(e=>[e,`video`]),...ze.map(e=>[e,`audio`]),...Be.map(e=>[e,`document`]),...Ve.map(e=>[e,`office`]),...He.map(e=>[e,`text`]),...Ue.map(e=>[e,`archive`]),...We.map(e=>[e,`font`]),...Ge.map(e=>[e,`3d`]),...Ke.map(e=>[e,`code`])]);function F(e){return qe.get(e)||(e.startsWith(`image/`)?`image`:e.startsWith(`video/`)?`video`:e.startsWith(`audio/`)?`audio`:e.startsWith(`font/`)?`font`:e.startsWith(`model/`)?`3d`:e.startsWith(`text/`)?`text`:`archive`)}function Je(e){return e.startsWith(`image/`)}new Set(Le);var Ye=new Set([`heic`,`heix`,`hevc`,`hevx`,`mif1`,`msf1`]);function Xe(e){if(e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255)return`image/jpeg`;if(e.length>=8&&e[0]===137&&I(e,1,3)===`PNG`)return`image/png`;if(e.length>=6&&/^GIF8[79]a$/.test(I(e,0,6)))return`image/gif`;if(e.length>=12&&I(e,0,4)===`RIFF`&&I(e,8,4)===`WEBP`)return`image/webp`;if(e.length>=12&&I(e,4,4)===`ftyp`){let t=I(e,8,4);if(t===`avif`||t===`avis`)return`image/avif`;if(Ye.has(t))return`image/heic`}return e.length>=2&&e[0]===66&&e[1]===77?`image/bmp`:e.length>=4&&e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0?`image/x-icon`:new TextDecoder().decode(e.subarray(0,1024)).toLowerCase().includes(`<svg`)?`image/svg+xml`:null}function Ze(e,t){return Qe(e.type,e.size,t)}function Qe(e,t,n){if(n?.imagesOnly&&!Je(e))return`File type not allowed.`;let r=n.maxFileSizeMB;return t>r*1024*1024?`File too large (max ${r}MB).`:null}function I(e,t,n){return new TextDecoder(`ascii`).decode(e.slice(t,t+n))}var L=()=>typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)}),$e=`[data-editor-floating-ui]`,et=`single`,tt=`(max-width: 700px), (max-height: 760px), (hover: none) and (pointer: coarse)`,nt={drafts:`
5
+ <rect x="3.85" y="3.45" width="7.85" height="8.35" rx="2.35" />
6
+ <rect
7
+ x="6.15"
8
+ y="5.75"
9
+ width="7.85"
10
+ height="8.35"
11
+ rx="2.35"
12
+ fill="var(--compose-icon-paper-fill)"
13
+ stroke="none"
14
+ />
15
+ <rect x="6.15" y="5.75" width="7.85" height="8.35" rx="2.35" />
16
+ <path d="M8.55 8.55h3.2" stroke-width="1.2" />
17
+ <path d="M8.55 10.8h3.95" stroke-width="1.2" />
18
+ <path d="M8.55 13.05h2.45" stroke-width="1.2" />
19
+ `,saveDraft:`
20
+ <path d="M6.65 3.6h4.7a2 2 0 0 1 2 2v8.7L9 11.75l-4.35 2.55V5.6a2 2 0 0 1 2-2Z" />
21
+ `},rt={public:`
22
+ <circle cx="8" cy="8" r="5.15" />
23
+ <path d="M3.85 8h8.3" />
24
+ <path d="M8 2.85c1.22 1.32 1.95 3.08 1.95 5.15S9.22 11.83 8 13.15" />
25
+ <path d="M8 2.85C6.78 4.17 6.05 5.93 6.05 8S6.78 11.83 8 13.15" />
26
+ `,latest_hidden:`
27
+ <path
28
+ d="M2.55 8c1.38-2.18 3.44-3.4 5.45-3.4S12.07 5.82 13.45 8c-1.38 2.18-3.44 3.4-5.45 3.4S3.93 10.18 2.55 8Z"
29
+ />
30
+ <path d="M4.35 11.1 11.65 4.9" />
31
+ `,private:`
32
+ <rect x="4.05" y="7.05" width="7.9" height="5.4" rx="1.75" />
33
+ <path d="M5.95 7.05V5.9A2.05 2.05 0 0 1 8 3.85a2.05 2.05 0 0 1 2.05 2.05v1.15" />
34
+ `},R={check:`
35
+ <path d="M3.75 7.25 6 9.5l4.25-4.25" />
36
+ `,caretRight:`
37
+ <path d="M5.65 4.5 8.15 7l-2.5 2.5" />
38
+ `,calendar:`
39
+ <rect x="2.5" y="3.5" width="9" height="8" rx="2" stroke-width="1" />
40
+ <path d="M4.5 2.5v2" stroke-width="1" />
41
+ <path d="M9.5 2.5v2" stroke-width="1" />
42
+ <path d="M2.5 6.5h9" stroke-width="1" />
43
+ `,options:`
44
+ <path d="M4 8.5h3.4" stroke-width="1.8" />
45
+ <path d="M12.6 8.5H20" stroke-width="1.8" />
46
+ <circle cx="10" cy="8.5" r="2.2" stroke-width="1.8" />
47
+ <path d="M4 15.5h7.4" stroke-width="1.8" />
48
+ <path d="M16.6 15.5H20" stroke-width="1.8" />
49
+ <circle cx="14" cy="15.5" r="2.2" stroke-width="1.8" />
50
+ `},it=`
51
+ <circle cx="12" cy="12" r="10" />
52
+ <path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" />
53
+ <path d="M2 12h20" />
54
+ `,at={collection:`
55
+ <path d="M2.5 6.3 8 3.5l5.5 2.8L8 9.1 2.5 6.3Z" />
56
+ <path d="M2.5 9.7 8 12.5l5.5-2.8" />
57
+ `,search:`
58
+ <circle cx="7.1" cy="7.1" r="3.65" />
59
+ <path d="m10.1 10.1 2.45 2.45" />
60
+ `,plus:`
61
+ <path d="M8 3.5v9" />
62
+ <path d="M3.5 8h9" />
63
+ `,plusCircle:`
64
+ <circle cx="8" cy="8" r="5.7" />
65
+ <path d="M8 5.55v4.9" />
66
+ <path d="M5.55 8h4.9" />
67
+ `};function ot(e){return o`<svg
68
+ class="compose-sheet-row-icon"
69
+ width="18"
70
+ height="18"
71
+ viewBox="0 0 18 18"
72
+ fill="none"
73
+ stroke="currentColor"
74
+ stroke-width="1.25"
75
+ stroke-linecap="round"
76
+ stroke-linejoin="round"
77
+ aria-hidden="true"
78
+ >
79
+ ${b(e)}
80
+ </svg>`}function st(e,t){return o`<span class=${t} aria-hidden="true">
81
+ <svg
82
+ class="compose-publish-visibility-svg"
83
+ width="16"
84
+ height="16"
85
+ viewBox="0 0 16 16"
86
+ fill="none"
87
+ stroke="currentColor"
88
+ stroke-width="1.35"
89
+ stroke-linecap="round"
90
+ stroke-linejoin="round"
91
+ >
92
+ ${b(e)}
93
+ </svg>
94
+ </span>`}function z(e,t){return o`<svg
95
+ class=${t}
96
+ width="16"
97
+ height="16"
98
+ viewBox="0 0 16 16"
99
+ fill="none"
100
+ stroke="currentColor"
101
+ stroke-width="1.35"
102
+ stroke-linecap="round"
103
+ stroke-linejoin="round"
104
+ aria-hidden="true"
105
+ >
106
+ ${b(e)}
107
+ </svg>`}function B(e,t){return o`<svg
108
+ class=${t}
109
+ width="14"
110
+ height="14"
111
+ viewBox="0 0 14 14"
112
+ fill="none"
113
+ stroke="currentColor"
114
+ stroke-width="1.35"
115
+ stroke-linecap="round"
116
+ stroke-linejoin="round"
117
+ aria-hidden="true"
118
+ >
119
+ ${b(e)}
120
+ </svg>`}function ct(e){return Array.isArray(e)?e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`title`),r=Reflect.get(e,`slug`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,title:n,slug:typeof r==`string`?r:``}]}):[]}function lt(e){return!e.content||e.content.length===0||e.content.every(e=>e.type===`paragraph`&&(!e.content||e.content.length===0))}function V(e){return e?lt(e)?null:e:null}function ut(e){return String(e).padStart(2,`0`)}function dt(e){let t=new Date(e*1e3);return`${t.getFullYear()}-${ut(t.getMonth()+1)}-${ut(t.getDate())}`}function H(e){let t=e.trim();if(!t)return null;let n=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!n)return null;let r=Number(n[1]),i=Number(n[2]),a=Number(n[3]),o=new Date(r,i-1,a);return Number.isNaN(o.getTime())||o.getFullYear()!==r||o.getMonth()!==i-1||o.getDate()!==a?null:{year:r,monthIndex:i-1,day:a}}function U(e){let t=new Date(e*1e3);return t.getHours()*60+t.getMinutes()}function ft(e,t){let n=H(e);if(!n)return null;let r=Math.min(Math.max(t,0),1439),i=Math.floor(r/60),a=r%60;return Math.floor(new Date(n.year,n.monthIndex,n.day,i,a,0,0).getTime()/1e3)}async function pt(e){let t=e.filter(e=>e.type===`media`),n=e.filter(e=>e.type===`text`);return{media:t.map(e=>({id:e.id,previewUrl:e.previewUrl,posterUrl:e.posterUrl??null,alt:e.alt,mimeType:e.mimeType,originalName:e.originalName,summary:e.summary,chars:e.chars,persisted:!0})),textAttachments:await Promise.all(n.map(async e=>{try{let t=await fetch(e.contentUrl);if(t.ok){let n=await t.json(),r=n.contentFormat===`markdown`&&n.content?n.content:``,i=r?j(r):null;if(i)return{bodyJson:JSON.stringify(i),bodyHtml:``,summary:e.summary??``,mediaId:e.id}}}catch{}return{bodyJson:JSON.stringify({type:`doc`,content:[{type:`paragraph`}]}),bodyHtml:``,summary:e.summary??``,mediaId:e.id}})),attachmentOrder:e.map(e=>e.id)}}var mt=class e extends u{static _lastNewPostVisibility=`public`;_sourceCollectionId=null;static _collectionVisibilityKey(e){return`jant:collection-visibility:${e}`}static _getCollectionVisibility(t){try{let n=globalThis.localStorage.getItem(e._collectionVisibilityKey(t));if(n===`public`||n===`latest_hidden`||n===`private`)return n}catch{}return null}static _setCollectionVisibility(t,n){try{globalThis.localStorage.setItem(e._collectionVisibilityKey(t),n)}catch{}}static _NOTE_TITLE_KEY=`jant:compose-note-title`;static _getNoteTitleDefault(){try{return globalThis.localStorage.getItem(e._NOTE_TITLE_KEY)!==`0`}catch{return!0}}static _setNoteTitleDefault(t){try{globalThis.localStorage.setItem(e._NOTE_TITLE_KEY,t?`1`:`0`)}catch{}}static properties={collections:{type:Array},languages:{type:Array},contextLanguage:{type:String,attribute:`context-language`},labels:{type:Object},uploadMaxFileSize:{type:Number,attribute:`upload-max-file-size`},pageMode:{type:Boolean,attribute:`page-mode`},closeHref:{type:String,attribute:`close-href`},autoRestoreDraft:{type:Boolean,attribute:`auto-restore-draft`},slashCommandDiscovered:{type:Boolean,attribute:`slash-command-discovered`},_format:{state:!0},_status:{state:!0},_loading:{state:!0},_openingEdit:{state:!0},_collectionIds:{state:!0},_showCollection:{state:!0},_collectionSearch:{state:!0},_altPanelOpen:{state:!0},_altPanelIndex:{state:!0},_attachedPanelOpen:{state:!0},_attachedTextIndex:{state:!0},_confirmPanelOpen:{state:!0},_editPostId:{state:!0},_draftSourceId:{state:!0},_draftsPanelOpen:{state:!0},_drafts:{state:!0},_draftsLoading:{state:!0},_draftsError:{state:!0},_draftMenuOpenId:{state:!0},_addCollectionPanelOpen:{state:!0},_replyToId:{state:!0},_replyToData:{state:!0},_replyParentPosition:{state:!0},_replyExpanded:{state:!0},_threadItems:{state:!0},_rowStatus:{state:!0},_focusedThreadIndex:{state:!0},_slug:{state:!0},_publishedAtInput:{state:!0},_visibility:{state:!0},_showPublishPanel:{state:!0},_postMetaIndex:{state:!0},_publishPanelFullscreen:{state:!0},_suggestedSlug:{state:!0},_suggestedSlugLoading:{state:!0},_slugCheckLoading:{state:!0},_slugTaken:{state:!0},_visibilityLocked:{state:!0},_quietReply:{state:!0},_language:{state:!0},_showLanguagePicker:{state:!0},_translationOf:{state:!0},_translationCollapsed:{state:!0}};_attachedEditor=null;_attachedTextSnapshot=null;_seededFromSource=!1;_confirmForDrafts=!1;_confirmForAttachedText=!1;_draftSaveTimer=null;_draftRestored=!1;_hasOwnedContent=!1;_reportedStorageFailure=!1;_initialSnapshot=null;_pageFocusApplied=!1;_pageLeaveRequested=!1;_replyThreadRootId=null;_replyRefreshKind=null;_replyRefreshId=null;_publishedAtTimeMinutes=null;_originalPublishedAt=null;_initialPublishedAtTimeMinutes=null;_initialPublishedAtInput=``;_initialSlug=``;_slugCheckTimer=null;_slugSuggestTimer=null;_slugSuggestRequestId=0;_slugCheckRequestId=0;_slugSuggestionKey=``;_suppressBeforeUnload=!1;_dialogEl=null;_mousedownOnBackdrop=!1;_mousedownPos=null;_filePickerActive=!1;_ignoreNextEscapeClose=!1;_openEditRequestId=0;_collectionPickerOrder=[];_suppressCollectionOptionClickUntil=0;_suppressedCollectionOptionId=null;createRenderRoot(){return this.innerHTML=``,this}constructor(){super(),this.collections=[],this.languages=[],this.contextLanguage=``,this.labels={},this.uploadMaxFileSize=1024,this.pageMode=!1,this.closeHref=`/`,this.autoRestoreDraft=!1,this.slashCommandDiscovered=!1,this._format=`note`,this._status=`published`,this._loading=!1,this._openingEdit=!1,this._collectionIds=[],this._showCollection=!1,this._collectionSearch=``,this._altPanelOpen=!1,this._altPanelIndex=0,this._attachedPanelOpen=!1,this._attachedTextIndex=0,this._confirmPanelOpen=!1,this._editPostId=null,this._draftSourceId=null,this._draftsPanelOpen=!1,this._drafts=[],this._draftsLoading=!1,this._draftsError=null,this._draftMenuOpenId=null,this._addCollectionPanelOpen=!1,this._replyToId=null,this._replyToData=null,this._replyExpanded=!1,this._threadItems=[],this._rowStatus=new Map,this._focusedThreadIndex=0,this._replyThreadRootId=null,this._replyParentPosition=null,this._replyRefreshKind=null,this._replyRefreshId=null,this._slug=``,this._publishedAtInput=``,this._publishedAtTimeMinutes=null,this._originalPublishedAt=null,this._initialPublishedAtTimeMinutes=null,this._initialPublishedAtInput=``,this._initialSlug=``,this._visibility=e._lastNewPostVisibility,this._sourceCollectionId=null,this._showPublishPanel=!1,this._publishPanelFullscreen=!1,this._postMetaIndex=null,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugCheckLoading=!1,this._slugTaken=!1,this._visibilityLocked=!1,this._quietReply=!1,this._language=null,this._showLanguagePicker=!1,this._translationOf=null,this._translationCollapsed=!1,this._seededFromSource=!1}get _editor(){return this.querySelector(`jant-compose-editor`)}get _rowIds(){return this._threadItems.length>0?this._threadItems.map(e=>e.id):[et]}_handleRowStatus(e,t){let n=this._rowStatus.get(e);if(n?.hasContent===t.hasContent&&n?.publishable===t.publishable)return;let r=new Map(this._rowStatus);r.set(e,t),this._rowStatus=r}willUpdate(e){if(super.willUpdate(e),e.has(`_threadItems`)){let e=new Set(this._rowIds);[...this._rowStatus.keys()].some(t=>!e.has(t))&&(this._rowStatus=new Map([...this._rowStatus].filter(([t])=>e.has(t))))}}updated(e){super.updated(e),this._initialSnapshot===null&&this._editor&&this._captureInitialSnapshot(),this._adoptTranslationPreview(),e.has(`labels`)&&this._dialogEl&&this.labels&&this._dialogEl.setAttribute(`aria-label`,this.labels.composeDialogLabel),e.has(`_addCollectionPanelOpen`)&&this._addCollectionPanelOpen&&this.updateComplete.then(()=>{let e=this.querySelector(`[data-collection-quick-dialog] [data-collection-title-input]`);e?.focus(),e?.select()}),e.has(`_showCollection`)&&this._showCollection&&this._scheduleCollectionPickerAutofocus(),(e.has(`_collectionIds`)||e.has(`_slug`)||e.has(`_publishedAtInput`)||e.has(`_visibility`))&&(this._draftSourceId||this._scheduleDraftSave()),this._showPublishPanel&&this._updatePublishPanelLayout(),this._showCollection&&this._updateCollectionPopoverSide(),this._postMetaIndex!==null&&this._updatePostMetaPanelLayout()}reset(){this._openEditRequestId+=1,this._format=`note`,this._status=`published`,this._loading=!1,this._openingEdit=!1,this._collectionIds=[],this._closeCollectionPicker(),this._altPanelOpen=!1,this._altPanelIndex=0,this._attachedPanelOpen=!1,this._attachedTextIndex=0,this._confirmPanelOpen=!1,this._editPostId=null,this._draftSourceId=null,this._draftsPanelOpen=!1,this._drafts=[],this._draftsLoading=!1,this._draftsError=null,this._draftMenuOpenId=null,this._addCollectionPanelOpen=!1,this._replyToId=null,this._replyToData=null,this._replyExpanded=!1,this._threadItems=[],this._rowStatus=new Map,this._focusedThreadIndex=0,this._replyThreadRootId=null,this._replyParentPosition=null,this._replyRefreshKind=null,this._replyRefreshId=null,this._slug=``,this._publishedAtInput=``,this._publishedAtTimeMinutes=null,this._originalPublishedAt=null,this._initialPublishedAtTimeMinutes=null,this._initialPublishedAtInput=``,this._initialSlug=``,this._visibility=e._lastNewPostVisibility,this._sourceCollectionId=null,this._showPublishPanel=!1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugCheckLoading=!1,this._slugTaken=!1,this._slugSuggestionKey=``,this._visibilityLocked=!1,this._quietReply=!1,this._language=null,this._showLanguagePicker=!1,this._translationOf=null,this._translationCollapsed=!1,this._seededFromSource=!1,this._confirmForDrafts=!1,this._confirmForAttachedText=!1,this._initialSnapshot=null,this._hasOwnedContent=!1,this._reportedStorageFailure=!1,this._pageFocusApplied=!1,this._pageLeaveRequested=!1,this._slugSuggestRequestId+=1,this._slugCheckRequestId+=1,this._suppressBeforeUnload=!1,this._filePickerActive=!1,this._ignoreNextEscapeClose=!1,this._cancelSlugTimers(),this._destroyAttachedEditor(),this._editor?.reset(),this._captureInitialSnapshot()}async refreshCollections(){try{let e=await fetch(`/api/collections?view=compose`,{cache:`no-store`,headers:{Accept:`application/json`}});if(!e.ok)return!1;let t=await e.json().catch(()=>null);return Array.isArray(t?.collections)?(this.collections=ct(t.collections),!0):!1}catch{return!1}}async openEdit(e,t){this.reset();let n=++this._openEditRequestId;this._openingEdit=!0,this._editPostId=e;let r=this.closest(`dialog`);r&&!r.open&&r.showModal(),await this.updateComplete,this._focusDialogShell();try{let r=await fetch(`/api/posts/${e}`);if(!r.ok)throw Error(`Failed to load post`);let i=await r.json();if(n!==this._openEditRequestId||(this._format=i.format,this._slug=i.slug??``,this._slugTaken=!1,this._slugCheckLoading=!1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugSuggestionKey=``,this._publishedAtInput=i.publishedAt?dt(i.publishedAt):``,this._publishedAtTimeMinutes=i.publishedAt?U(i.publishedAt):null,this._originalPublishedAt=i.publishedAt??null,this._initialPublishedAtTimeMinutes=this._publishedAtTimeMinutes,this._initialPublishedAtInput=this._publishedAtInput,this._initialSlug=this._slug.trim(),this._visibility=i.visibility??`public`,this._visibilityLocked=!!i.replyToId,this._language=i.language??null,i.replyToId&&(this._replyToId=i.replyToId,await this._fetchReplyContext(i.replyToId),n!==this._openEditRequestId)))return;!i.replyToId&&i.collectionIds?.length&&(this._collectionIds=i.collectionIds);let{media:a,textAttachments:o,attachmentOrder:s}=await pt(i.attachments??[]);if(n!==this._openEditRequestId||(this._openingEdit=!1,await this.updateComplete,n!==this._openEditRequestId))return;this._restoreEditDraftIfAvailable(e,t?.restoreToast)||this._editor?.populate({format:i.format,title:i.format===`quote`?void 0:i.title??void 0,bodyJson:i.body??void 0,url:i.format===`quote`?i.sourceUrl??void 0:i.url??void 0,quoteText:i.quoteText??void 0,quoteAuthor:i.format===`quote`?i.sourceName??void 0:void 0,rating:i.rating??void 0,media:a,textAttachments:o,attachmentOrder:s}),globalThis.requestAnimationFrame(()=>{n===this._openEditRequestId&&(this._focusDialogShell(),this._captureInitialSnapshot())})}catch{if(n!==this._openEditRequestId)return;this._openingEdit=!1,this._closeDialog(),this.reset(),d(this.labels.loadPostFailed,`error`)}}async openDraft(e){let t=this.closest(`dialog`);t&&!t.open&&t.showModal(),await this.updateComplete,this._focusDialogShell(),await this._loadDraft(e)}async openNew(t){this.reset(),this._editor?.setTitleDefault(e._getNoteTitleDefault());let n=`none`;if(t?.restoreDraft!==!1&&(n=await this.restoreLocalDraft({notify:t?.restoreToast,extraMedia:t?.restoreMedia})),t?.initialFormat&&(this._format=t.initialFormat),t?.collectionId&&!this._collectionIds.includes(t.collectionId)&&(this._collectionIds=[t.collectionId,...this._collectionIds]),t?.collectionId){this._sourceCollectionId=t.collectionId;let r=n===`restored`?null:e._getCollectionVisibility(t.collectionId);r&&(this._visibility=r)}this.closest(`dialog`)?.showModal(),await this.updateComplete,this._editor?.focusInput(),this._captureInitialSnapshot()}async openTranslation(t,n){this.reset(),this._editor?.setTitleDefault(e._getNoteTitleDefault()),this.languages.some(e=>e.tag===n)&&(this._language=n),this.closest(`dialog`)?.showModal(),await this.updateComplete,this._editor?.focusInput(),this._captureInitialSnapshot(),await this._loadTranslationSource(t,{seed:!0})}async openReply(e,t,n,r,i){this.reset(),this._replyToId=e,this._replyThreadRootId=n??e,this._replyRefreshKind=r?.kind??null,this._replyRefreshId=r?.id??null,this._replyToData=t??null,this._visibilityLocked=!0,this._format=i?.initialFormat??`note`,i?.restoreDraft!==!1&&await this.restoreLocalDraft({expectedReplyToId:e,notify:i?.restoreToast,extraMedia:i?.restoreMedia}),this._collectionIds=[],this.closest(`dialog`)?.showModal(),await this.updateComplete,this._editor?.focusInput(),this._captureInitialSnapshot(),this._loadReplyParentPosition(e)}async _loadReplyParentPosition(e){try{let t=await fetch(`/api/posts/${e}`);if(!t.ok)return;let n=await t.json();if(this._replyToId!==e)return;this._replyParentPosition=n.threadPosition??null}catch{}}async _fetchReplyContext(e){try{let t=await fetch(`/api/posts/${e}`);if(!t.ok)return;let n=await t.json();this._replyThreadRootId=n.replyToId?n.threadId:n.id,this._replyParentPosition=n.threadPosition??null;let r=n.publishedAt?new Date(n.publishedAt*1e3).toLocaleDateString(void 0,{month:`short`,day:`numeric`}):``,i=(n.attachments??[]).filter(e=>e.type===`media`).map(e=>({url:e.url??e.previewUrl,previewUrl:e.previewUrl,alt:e.alt,mimeType:e.mimeType,width:e.width,height:e.height}));this._replyToData={contentHtml:n.bodyHtml??``,dateText:r,media:i.length>0?i:void 0}}catch{}}set loading(e){this._loading=e}_closeDialog(){let e=this.closest(`dialog`);if(e){e.close(),document.activeElement?.blur();return}this.pageMode&&(this._suppressBeforeUnload=!0,globalThis.location.assign(this.closeHref||t(`/`)))}requestCloseAndLeave(){this._pageLeaveRequested=!0,this.requestClose()}consumePageLeaveRequest(){let e=this._pageLeaveRequested;return this._pageLeaveRequested=!1,e}preparePageLeave(){this._suppressBeforeUnload=!0}_clearFilePickerEscapeState(){this._filePickerActive=!1,this._ignoreNextEscapeClose=!1}_shouldIgnoreEscapeClose(){return this._filePickerActive||this._ignoreNextEscapeClose?(this._clearFilePickerEscapeState(),!0):!1}_hasContent(){return this._rowIds.some(e=>this._rowStatus.get(e)?.hasContent===!0)}_hasWorkToLose(){return this._hasContent()?!this._seededFromSource||this._hasUnsavedChanges():!1}_hasWorkToLoseOnLeave(){return this._editPostId||this._draftSourceId?this._hasUnsavedChanges():this._hasWorkToLose()}_buildSnapshot(){let t=this._editor;if(!t)return null;let n=this._threadItems.length>0?Array.from(this.querySelectorAll(`jant-compose-editor`)):[];return{format:this._format,collectionIds:[...this._collectionIds],slug:this._slug,publishedAtInput:this._publishedAtInput,publishedAtTimeMinutes:this._publishedAtTimeMinutes,visibility:this._visibility,language:this._language,...e._snapshotEditor(t),threadPosts:this._threadItems.flatMap((t,r)=>{let i=n[r];return i?[{format:t.format,slug:t.slug??``,publishedAtInput:t.publishedAtInput??``,publishedAtTimeMinutes:t.publishedAtTimeMinutes??null,...e._snapshotEditor(i)}]:[]})}}static _snapshotEditor(e){let t=e.getData(),n=e.getEffectiveAttachedTexts(),r=t.rating>0&&e._showRating;return{title:t.title,bodyJson:e.getNormalizedBodyJson(),url:t.url,quoteText:t.quoteText,quoteAuthor:t.quoteAuthor,rating:t.rating,showRating:r,attachments:e._attachments.map(e=>({clientId:e.clientId,mediaId:e.mediaId,previewUrl:e.previewUrl,mimeType:e.file.type,alt:e.alt,status:e.status,summary:e.summary,chars:e.chars})),attachedTexts:n.map(e=>({clientId:e.clientId,mediaId:e.mediaId??null,bodyJson:e.bodyJson,bodyHtml:e.bodyHtml,summary:e.summary})),attachmentOrder:e.getEffectiveAttachmentOrder()}}_serializeSnapshot(e){return e?JSON.stringify(e):null}_captureInitialSnapshot(){this._initialSnapshot=this._serializeSnapshot(this._buildSnapshot())}_hasUnsavedChanges(){let e=this._serializeSnapshot(this._buildSnapshot());return e===null||!this._editPostId&&!this._draftSourceId&&!this._hasContent()?!1:this._initialSnapshot===null?this._hasContent():e!==this._initialSnapshot}requestClose(){if(!this._loading){if(this._showCollection&&this._closeCollectionPicker(),this._showPublishPanel&&=!1,this._showLanguagePicker=!1,this._confirmPanelOpen){let e=this._confirmForAttachedText;this._confirmPanelOpen=!1,this._confirmForDrafts=!1,this._confirmForAttachedText=!1,this._pageLeaveRequested=!1,this.updateComplete.then(()=>{if(e){this._attachedEditor?.commands.focus();return}this._editor?.focusInput()});return}this._hasWorkToLoseOnLeave()?(this._confirmForDrafts=!1,this._confirmForAttachedText=!1,this._confirmPanelOpen=!0):(this._closeDialog(),this.reset())}}_discardAndClose(){this._clearDraftFromStorage(),this._confirmPanelOpen=!1,this._confirmForAttachedText=!1,this._closeDialog(),this.reset()}_discardAttachedPanel(){this._confirmForAttachedText=!1,this._destroyAttachedEditor(),this._attachedPanelOpen=!1,this._editor?.closeAttachedPanel(this._attachedTextIndex)}_handleConfirmSave(){this._confirmForAttachedText?(this._confirmPanelOpen=!1,this._confirmForAttachedText=!1,this._doneAttachedPanel()):this._confirmForDrafts?(this._confirmPanelOpen=!1,this._editor?.hasPendingInlineImageUploads()?this._saveDraftAndOpenDrafts():this._finishDraftSaveAndOpenDrafts()):this._editPostId?(this._confirmPanelOpen=!1,this._submit(`published`)):(this._confirmPanelOpen=!1,this._submit(`draft`))}_handleConfirmDiscard(){this._confirmForAttachedText?(this._confirmPanelOpen=!1,this._discardAttachedPanel()):this._confirmForDrafts?(this._confirmPanelOpen=!1,this.reset(),this._openDraftsPanel()):this._discardAndClose()}_buildEditorPostDetail(e,t,n,r){e.promoteLeadingH1Title({force:!0});let i=e.getData(),a=new Map((i.attachments??[]).map(e=>[e.clientId,e])),o=new Map(i.attachedTexts.map(e=>[e.clientId,e])),s=[];for(let e of i.attachmentOrder){let t=a.get(e);if(t){s.push({type:`media`,clientId:e,mediaId:t.mediaId,alt:t.alt});continue}let n=o.get(e);n?.bodyJson&&s.push({type:`text`,clientId:e,bodyJson:n.bodyJson,summary:n.summary,mediaId:n.mediaId,originalBodyJson:V(n.originalBodyJson??null)})}let c=n===0;return{format:t,title:i.title,body:i.body,url:i.url,quoteText:i.quoteText,quoteAuthor:i.quoteAuthor,status:r,slug:this._getPostSlug(n).trim()||void 0,publishedAt:this._getPostPublishedAtSubmitValue(n,r),visibility:c?this._visibilityLocked?void 0:this._visibility:void 0,rating:i.rating,collectionIds:c&&!this._replyToId?[...this._collectionIds]:[],attachments:s,replyToId:c?this._replyToId??void 0:void 0,quietReply:c&&this._canReplyQuietly()&&this._quietReply||void 0,replyThreadRootId:c?this._replyThreadRootId??void 0:void 0,replyRefreshKind:c?this._replyRefreshKind??void 0:void 0,replyRefreshId:c?this._replyRefreshId??void 0:void 0,language:c&&!this._replyToId?this._effectiveLanguage()??void 0:void 0,translationOfId:c?this._translationOf?.id:void 0}}_buildSubmitDetail(e){let t=this._editor;return t?{...this._buildEditorPostDetail(t,this._format,0,e),editPostId:this._editPostId??this._draftSourceId??void 0,draftSourceId:this._draftSourceId??void 0}:null}_focusBlockedSubmitField(e){if(e===`published`){let e=Math.max(1,this._threadItems.length);for(let t=0;t<e;t++)if(this._getPostPublishedAtValidationMessage(t)!==null)return this._revealPublishedAtField(t),!0}{let e=Math.max(1,this._threadItems.length);for(let t=0;t<e;t++)if(this._getPostSlugValidationMessage(t))return this._revealSlugField(t),!0}if(this._threadItems.length>0){let e=Array.from(this.querySelectorAll(`jant-compose-editor`));for(let t=0;t<this._threadItems.length;t++){let n=this._threadItems[t],r=e[t];if(r){if(r.getUrlValidationMessage())return r.revealUrlValidation(),r.focusUrlInput(`end`),!0;if(r.getLinkTitleValidationMessage())return r.revealLinkTitleValidation(),r.focusLinkTitleInput(`end`),!0;if(n.format===`quote`&&!r._quoteText.trim())return r.focusInput(`end`),!0}}return!1}let t=this._editor;return t?t.getUrlValidationMessage()?(t.revealUrlValidation(),t.focusUrlInput(`end`),!0):t.getLinkTitleValidationMessage()?(t.revealLinkTitleValidation(),t.focusLinkTitleInput(`end`),!0):this._format===`quote`&&!t._quoteText.trim()&&(t.focusInput(`end`),!0):!1}_dispatchSubmit(e){if(this._loading||this._focusBlockedSubmitField(e))return!1;if(this._draftSourceId||(this._cancelDraftSaveTimer(),this._saveDraftToStorage()),this._threadItems.length>0){if(this._threadItems.length>20)return d(this._getThreadLimitMessage(),`error`),!1;let t=Array.from(this.querySelectorAll(`jant-compose-editor`));if(t.length!==this._threadItems.length)return!1;let n=[],r=[];for(let i=0;i<this._threadItems.length;i++){let a=this._threadItems[i],o=t[i];if(!o)return!1;n.push(this._buildEditorPostDetail(o,a.format,i,e)),r.push(...(o._attachments??[]).filter(e=>e.status===`pending`||e.status===`processing`||e.status===`uploading`))}return this.dispatchEvent(new CustomEvent(`jant:compose-submit-deferred`,{bubbles:!0,detail:{...n[0],editPostId:this._editPostId??this._draftSourceId??void 0,draftSourceId:this._draftSourceId??void 0,threadPosts:n,pendingAttachments:r}})),!0}let t=this._editor;if(!t)return!1;let n=this._buildSubmitDetail(e);if(!n)return!1;let r=(t._attachments??[]).filter(e=>e.status===`pending`||e.status===`processing`||e.status===`uploading`);return this.dispatchEvent(new CustomEvent(`jant:compose-submit-deferred`,{bubbles:!0,detail:{...n,pendingAttachments:r}})),!0}_saveDraftAndOpenDrafts(){this._finishDraftSaveAndOpenDrafts()}_finishDraftSaveAndOpenDrafts(){if(!this._dispatchSubmit(`draft`))return;this.reset();let e=()=>{clearTimeout(t),this.isConnected&&this._openDraftsPanel()},t=globalThis.setTimeout(()=>{document.removeEventListener(`jant:compose-submit-complete`,e)},1e4);document.addEventListener(`jant:compose-submit-complete`,e,{once:!0})}_finishSubmit(e){if(this._dispatchSubmit(e)){if(this.pageMode){this._loading=!0;return}this._closeDialog(),this.reset()}}_submit(e){this._showPublishPanel=!1,this._finishSubmit(e)}_toggleCollection(e){this._collectionIds=this._collectionIds.includes(e)?this._collectionIds.filter(t=>t!==e):[...this._collectionIds,e]}_selectedCollectionLabel(e){let t=this._collectionIds,n=e.find(e=>e.id===t[0]);if(!n)return``;if(t.length===1)return n.title;if(t.length===2){let r=e.find(e=>e.id===t[1]);return r?`${n.title}, ${r.title}`:n.title}return this.labels.collectionCountLabel.replace(`%name%`,n.title).replace(`%count%`,String(t.length-1))}_prepareCollectionPickerOrder(){this._collectionPickerOrder=h(this.collections??[],this._collectionIds)}_focusCollectionPickerInitialTarget(){this.querySelector(`.compose-collection-search-input, .compose-collection-option, .compose-collection-add-action`)?.focus()}_focusCollectionSearchInput(){let e=this.querySelector(`.compose-collection-search-input`);if(!e)return!1;e.focus();let t=e.value.length;return e.setSelectionRange(t,t),!0}_closeCollectionPicker(e){if(this._showCollection=!1,this._collectionSearch=``,this._suppressedCollectionOptionId=null,this._suppressCollectionOptionClickUntil=0,e?.restoreFocus===`trigger`){this.updateComplete.then(()=>{this.querySelector(`.compose-collection-trigger`)?.focus()});return}e?.restoreFocus===`editor`&&this._restorePageEditorFocus()}_suppressNextCollectionOptionClick(e){this._suppressedCollectionOptionId=e,this._suppressCollectionOptionClickUntil=Date.now()+250}_isTouchViewport(){return globalThis.matchMedia?.(`(hover: none) and (pointer: coarse)`)?.matches??!1}_shouldAutofocusCollectionPicker(){return!this._isTouchViewport()}_shouldAutofocusFormatInput(){return!this._isTouchViewport()}_scheduleCollectionPickerAutofocus(){this._shouldAutofocusCollectionPicker()&&globalThis.requestAnimationFrame(()=>{this._showCollection&&this._focusCollectionPickerInitialTarget()})}_scheduleCollectionSearchFocus(){globalThis.requestAnimationFrame(()=>{this._showCollection&&(this._focusCollectionSearchInput()||this._focusCollectionPickerInitialTarget())})}_isPrintableCollectionSearchKey(e){return e.length===1&&e.trim().length>0}_handleCollectionTriggerKeydown=e=>{if(!(e.defaultPrevented||e.isComposing||e.altKey||e.ctrlKey||e.metaKey)){if(e.key===`ArrowDown`){e.preventDefault(),this._scheduleCollectionSearchFocus();return}this._showCollection&&this._isPrintableCollectionSearchKey(e.key)&&(e.preventDefault(),this._collectionSearch+=e.key,this._scheduleCollectionSearchFocus())}};_getCollectionOptionElements(){return Array.from(this.querySelectorAll(`.compose-collection-option`))}_handleCollectionSearchKeydown=e=>{if(e.defaultPrevented||e.isComposing||e.altKey||e.ctrlKey||e.metaKey)return;if(e.key===`Enter`){e.preventDefault(),this._closeCollectionPicker({restoreFocus:`trigger`});return}if(e.key!==`ArrowDown`)return;let[t]=this._getCollectionOptionElements(),n=this.querySelector(`.compose-collection-add-action`),r=t??n;r&&(e.preventDefault(),r.focus())};_handleCollectionOptionKeydown=(e,t)=>{if(e.defaultPrevented||e.isComposing||e.altKey||e.ctrlKey||e.metaKey)return;let n=this._getCollectionOptionElements(),r=e.currentTarget,i=r?n.indexOf(r):-1;if(e.key===`ArrowDown`){let t=this.querySelector(`.compose-collection-add-action`),r=i>=0?n[i+1]??t:n[0];if(!r)return;e.preventDefault(),r.focus();return}if(e.key===`ArrowUp`){let t=this.querySelector(`.compose-collection-search-input`),r=i>0?n[i-1]:t;if(!r)return;e.preventDefault(),r.focus();return}if(e.key===` `||e.key===`Spacebar`){e.preventDefault(),this._suppressNextCollectionOptionClick(t),this._toggleCollection(t);return}e.key===`Enter`&&(e.preventDefault(),this._suppressNextCollectionOptionClick(t),this._closeCollectionPicker({restoreFocus:`trigger`}))};_handleCollectionOptionClick=e=>{if(this._suppressedCollectionOptionId===e&&Date.now()<=this._suppressCollectionOptionClickUntil){this._suppressedCollectionOptionId=null,this._suppressCollectionOptionClickUntil=0;return}this._suppressedCollectionOptionId=null,this._suppressCollectionOptionClickUntil=0,this._toggleCollection(e)};_handleCollectionAddActionKeydown=e=>{if(e.defaultPrevented||e.isComposing||e.altKey||e.ctrlKey||e.metaKey||e.key!==`ArrowUp`)return;let t=this._getCollectionOptionElements(),n=this.querySelector(`.compose-collection-search-input`),r=t.at(-1)??n;r&&(e.preventDefault(),r.focus())};_updateCollectionPopoverSide(){let e=this.querySelector(`.compose-collection-trigger`),t=this.querySelector(`.compose-collection-popover[data-popover]`);if(!e||!t)return;let n=globalThis.visualViewport,r=n?.offsetTop??0,i=r+(n?.height??globalThis.innerHeight),a=e.getBoundingClientRect(),o=Math.max(0,i-12-a.bottom-4),s=Math.max(0,a.top-r-12-4);t.dataset.side=o>=s?`bottom`:`top`}_cancelSlugTimers(){this._slugCheckTimer!==null&&(clearTimeout(this._slugCheckTimer),this._slugCheckTimer=null),this._slugSuggestTimer!==null&&(clearTimeout(this._slugSuggestTimer),this._slugSuggestTimer=null)}_currentSlugOwnerId(){return this._editPostId??this._draftSourceId??void 0}_hasManualSlug(){return this._slug.trim().length>0}_currentSuggestionTitle(){return this._editor?.getData().title.trim()??``}_canSuggestSlug(){return this._currentSuggestionTitle().length>0}_currentSuggestionKey(){return`${this._currentSlugOwnerId()??``}::${this._currentSuggestionTitle()}`}_scheduleSuggestedSlugRefresh(e=!1){if(this._postMetaIndex!==0||this._hasManualSlug())return;if(!this._canSuggestSlug()){this._slugSuggestRequestId+=1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugSuggestionKey=``;return}let t=this._currentSuggestionKey();if(this._slugSuggestionKey!==t&&(this._suggestedSlug=``),!e&&!this._suggestedSlugLoading&&this._suggestedSlug&&this._slugSuggestionKey===t)return;this._slugSuggestTimer!==null&&(clearTimeout(this._slugSuggestTimer),this._slugSuggestTimer=null);let n=()=>void this._refreshSuggestedSlug(t);if(e){n();return}this._slugSuggestTimer=setTimeout(n,250)}async _refreshSuggestedSlug(e){if(this._slugSuggestTimer=null,this._hasManualSlug()||!this._canSuggestSlug())return;let t=++this._slugSuggestRequestId;this._suggestedSlugLoading=!0;let n=new URLSearchParams({mode:`suggest`}),r=this._currentSuggestionTitle();r&&n.set(`title`,r);let i=this._currentSlugOwnerId();i&&n.set(`postId`,i);try{let r=await fetch(`/api/posts/slug?${n.toString()}`);if(!r.ok)return;let i=await r.json();if(t!==this._slugSuggestRequestId||this._hasManualSlug()||this._postMetaIndex!==0)return;this._suggestedSlug=i.slug?.trim()??``,this._slugSuggestionKey=e}catch{}finally{t===this._slugSuggestRequestId&&(this._suggestedSlugLoading=!1)}}_scheduleSlugAvailabilityCheck(e=0){if(!this._hasPostManualSlug(e)){this._setPostSlugTaken(e,!1),this._slugCheckLoading=!1;return}if(this._slugCheckTimer!==null&&(clearTimeout(this._slugCheckTimer),this._slugCheckTimer=null),this._getPostSlugSyncValidationMessage(e)){this._setPostSlugTaken(e,!1),this._slugCheckLoading=!1;return}this._slugCheckLoading=!0;let t=this._getPostSlug(e).trim();this._slugCheckTimer=setTimeout(()=>{this._checkSlugAvailability(t,e)},250)}async _checkSlugAvailability(e,t=0){this._slugCheckTimer=null;let n=++this._slugCheckRequestId,r=new URLSearchParams({mode:`check`,slug:e}),i=t===0?this._currentSlugOwnerId():this._threadItems[t]?.sourcePostId;i&&r.set(`postId`,i);try{let i=await fetch(`/api/posts/slug?${r.toString()}`);if(!i.ok)return;let a=await i.json();if(n!==this._slugCheckRequestId||this._getPostSlug(t).trim()!==e)return;this._setPostSlugTaken(t,a.available===!1)}catch{}finally{n===this._slugCheckRequestId&&(this._slugCheckLoading=!1)}}_useSuggestedSlug(){this._suggestedSlug&&(this._slug=this._suggestedSlug,this._slugTaken=!1,this._slugCheckLoading=!1,this.updateComplete.then(()=>{this.querySelector(`.compose-publish-slug-input`)?.focus()}))}_resetCustomSlug(e=0){this._setPostSlug(e,``),this._setPostSlugTaken(e,!1),this._slugCheckLoading=!1,this._scheduleSuggestedSlugRefresh(!0),this.updateComplete.then(()=>{this.querySelector(`.compose-publish-slug-input`)?.focus()})}connectedCallback(){super.connectedCallback(),this._syncPublishPanelPresentation(),this.addEventListener(`keydown`,this._handleKeydown),this.addEventListener(`jant:alt-panel-open`,this._handleAltPanelOpen),this.addEventListener(`jant:alt-panel-close`,this._handleAltPanelClose),this.addEventListener(`jant:attached-panel-open`,this._handleAttachedPanelOpen),this.addEventListener(`jant:compose-content-changed`,this._onContentChanged),this.addEventListener(`jant:title-toggle`,this._handleTitleToggle),this.addEventListener(`jant:file-picker-open`,this._handleFilePickerOpen),this.addEventListener(`jant:file-picker-close`,this._handleFilePickerClose),this.addEventListener(`jant:fullscreen-open`,this._handleFullscreenOpen),this.addEventListener(`pointerdown`,this._handlePointerDown),document.addEventListener(`jant:fullscreen-close`,this._handleFullscreenClose),window.addEventListener(`beforeunload`,this._onBeforeUnload),window.addEventListener(`resize`,this._handleViewportChange),window.addEventListener(`scroll`,this._handleViewportChange,{passive:!0}),document.addEventListener(`scroll`,this._handleAnyScroll,{capture:!0,passive:!0}),globalThis.visualViewport?.addEventListener(`resize`,this._handleViewportChange),globalThis.visualViewport?.addEventListener(`scroll`,this._handleViewportChange),this._dialogEl=this.closest(`dialog`),this._dialogEl&&(this._dialogEl.addEventListener(`cancel`,this._handleDialogCancel),this._dialogEl.addEventListener(`mousedown`,this._handleDialogMousedown),this._dialogEl.addEventListener(`click`,this._handleDialogClick)),this.pageMode&&this.updateComplete.then(()=>this._focusPageEditorOnMount())}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(`keydown`,this._handleKeydown),this.removeEventListener(`jant:alt-panel-open`,this._handleAltPanelOpen),this.removeEventListener(`jant:alt-panel-close`,this._handleAltPanelClose),this.removeEventListener(`jant:attached-panel-open`,this._handleAttachedPanelOpen),this.removeEventListener(`jant:compose-content-changed`,this._onContentChanged),this.removeEventListener(`jant:title-toggle`,this._handleTitleToggle),this.removeEventListener(`jant:file-picker-open`,this._handleFilePickerOpen),this.removeEventListener(`jant:file-picker-close`,this._handleFilePickerClose),this.removeEventListener(`jant:fullscreen-open`,this._handleFullscreenOpen),this.removeEventListener(`pointerdown`,this._handlePointerDown),document.removeEventListener(`jant:fullscreen-close`,this._handleFullscreenClose),window.removeEventListener(`beforeunload`,this._onBeforeUnload),window.removeEventListener(`resize`,this._handleViewportChange),window.removeEventListener(`scroll`,this._handleViewportChange),document.removeEventListener(`scroll`,this._handleAnyScroll,{capture:!0}),globalThis.visualViewport?.removeEventListener(`resize`,this._handleViewportChange),globalThis.visualViewport?.removeEventListener(`scroll`,this._handleViewportChange),this._cancelSlugTimers(),this._destroyAttachedEditor(),this._cancelDraftSaveTimer(),this._dialogEl&&=(this._dialogEl.removeEventListener(`cancel`,this._handleDialogCancel),this._dialogEl.removeEventListener(`mousedown`,this._handleDialogMousedown),this._dialogEl.removeEventListener(`click`,this._handleDialogClick),null)}_handleFilePickerOpen=()=>{this._filePickerActive=!0,this._ignoreNextEscapeClose=!1};_handleFilePickerClose=e=>{this._filePickerActive=!1,this._ignoreNextEscapeClose=!!e.detail?.cancelled};_handlePointerDown=()=>{this._clearFilePickerEscapeState()};_syncPublishPanelPresentation(){let e=globalThis.matchMedia?.(tt)?.matches??!1;e!==this._publishPanelFullscreen&&(this._publishPanelFullscreen=e)}_handleViewportChange=()=>{this._syncPublishPanelPresentation(),this._showPublishPanel&&this.updateComplete.then(()=>this._updatePublishPanelLayout()),this._showCollection&&this.updateComplete.then(()=>this._updateCollectionPopoverSide()),this._postMetaIndex!==null&&this.updateComplete.then(()=>this._updatePostMetaPanelLayout())};_handleAnyScroll=()=>{this._postMetaIndex!==null&&this._updatePostMetaPanelLayout()};_handleDialogCancel=e=>{e.preventDefault();let t=e;t.isComposing||t.keyCode===229||this._shouldIgnoreEscapeClose()||this._dismissEscapeOverlay()||this.requestClose()};_pointInOpenPopover(e,t){for(let n of document.querySelectorAll(`:popover-open`)){let r=n.getBoundingClientRect();if(e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom)return!0}return!1}_handleDialogMousedown=e=>{let t=e;this._mousedownOnBackdrop=e.target===this._dialogEl&&!this._pointInOpenPopover(t.clientX,t.clientY),this._mousedownPos=this._mousedownOnBackdrop?{x:t.clientX,y:t.clientY}:null};_handleDialogClick=e=>{if(!this._dialogEl||e.target!==this._dialogEl||!this._mousedownOnBackdrop)return;let t=e;if(this._mousedownPos){let e=t.clientX-this._mousedownPos.x,n=t.clientY-this._mousedownPos.y;if(e*e+n*n>16)return}let n=document.getSelection();if(n&&!n.isCollapsed||this._pointInOpenPopover(t.clientX,t.clientY))return;let r=document.elementFromPoint(t.clientX,t.clientY);r instanceof globalThis.Element&&r.closest($e)||this.requestClose()};_focusDialogShell(){let e=this.querySelector(`.compose-dialog-inner`);if(e){e.focus();return}this._dialogEl?.focus()}_restorePageEditorFocus(){this.updateComplete.then(()=>this._editor?.focusInput())}_dismissEscapeOverlay(){return this._confirmPanelOpen?(this.requestClose(),!0):this._addCollectionPanelOpen?(this._closeAddCollectionPanel(),!0):this._editor?.isEmojiPickerOpen()?(this._editor.closeEmojiPicker({restoreFocus:!0}),!0):this._showLanguagePicker?(this._closeLanguagePicker(!0),!0):this._showCollection?(this._closeCollectionPicker({restoreFocus:`editor`}),!0):this._showPublishPanel?(this._closePublishPanel(!0),!0):this._postMetaIndex===null?this._altPanelOpen?(this._closeAltPanel(),this._restorePageEditorFocus(),!0):this._draftMenuOpenId?(this._draftMenuOpenId=null,!0):this._draftsPanelOpen?(this._closeDraftsPanel(),!0):this._attachedPanelOpen?(this._cancelAttachedPanel(),!0):!1:(this._closePostMeta(),!0)}_handleKeydown=t=>{let n=t;if(!(n.isComposing||n.keyCode===229)){if(n.key!==`Escape`&&this._clearFilePickerEscapeState(),n.key===`Escape`){if(n.preventDefault(),n.stopPropagation(),this._shouldIgnoreEscapeClose()||this._dismissEscapeOverlay())return;this.requestClose()}else if(n.key===`Enter`&&this._confirmPanelOpen)n.preventDefault(),this._handleConfirmSave();else if((n.metaKey||n.ctrlKey)&&n.key===`Enter`)t.preventDefault(),this._publishFromShortcut();else if((n.metaKey||n.ctrlKey)&&!n.altKey&&!n.shiftKey&&n.key>=`1`&&n.key<=String(e._FORMATS.length)){n.preventDefault();let t=e._FORMATS[Number(n.key)-1];this._threadItems.length>0?this.querySelectorAll(`jant-compose-editor`)[this._focusedThreadIndex]?.dispatchEvent(new CustomEvent(`jant:format-change`,{detail:{format:t},bubbles:!0})):this._switchFormat(t)}}};_publishFromShortcut(){if(this._attachedPanelOpen){this._doneAttachedPanel();return}if(!this._canPublish()){this._focusBlockedSubmitField(`published`);return}this._submit(`published`)}_handleAltPanelOpen=e=>{let t=e.detail;this._altPanelIndex=t.index,this._altPanelOpen=!0,this.updateComplete.then(()=>{this.querySelector(`.compose-alt-input`)?.focus()})};_handleAltPanelClose=()=>{this._altPanelOpen=!1};_getAltAttachment(){return this._editor?._attachments[this._altPanelIndex]??null}_onAltInput(e){let t=e.target.value;this._editor?.updateAlt(this._altPanelIndex,t)}_closeAltPanel(){this._altPanelOpen=!1}_handleFullscreenClose=e=>{let t=Array.from(this.querySelectorAll(`jant-compose-editor`))[e.detail.editorIndex??0]??this._editor;t&&(t.setEditorState(e.detail.json,e.detail.title,e.detail.showTitle,e.detail.selection),t.adoptPendingUploads(),e.detail.intent!==`publish`&&this.updateComplete.then(()=>t.focusSelection(e.detail.selection))),this._replyExpanded=e.detail.replyExpanded,e.detail.intent===`publish`&&this._publishFromShortcut()};_buildFullscreenReplyContext(){return!this._replyToId||!this._replyToData?null:{contentHtml:this._replyToData.contentHtml,dateText:this._replyToData.dateText,expanded:this._replyExpanded}}_handleFullscreenOpen=e=>{e.detail.replyContext=this._buildFullscreenReplyContext();let t=Array.from(this.querySelectorAll(`jant-compose-editor`)).indexOf(e.target);e.detail.editorIndex=t>=0?t:0};_handleAttachedPanelOpen=e=>{let t=e.detail;this._attachedTextIndex=t.index,this._attachedPanelOpen=!0,this.updateComplete.then(()=>{let e=this.querySelector(`.compose-attached-tiptap`);if(!e)return;let t=this._editor?._attachedTexts[this._attachedTextIndex]?.bodyJson??null;this._attachedTextSnapshot=t?JSON.parse(JSON.stringify(t)):null,this._attachedEditor=ue({element:e,placeholder:this.labels.attachedTextPlaceholder,content:t,toolbarMode:`compose`,tableControlLabels:this.labels.tableControls,highlightLabel:this.labels.highlight}),this._focusAttachedEditorBoundary(t)})};_focusAttachedEditorBoundary(e){if(!this._attachedEditor)return;let t=V(e??this._attachedEditor.getJSON())?`end`:`start`;this._attachedEditor.commands.focus(t)}_isAttachedTextDirty(){return this._attachedEditor?JSON.stringify(V(this._attachedEditor.getJSON()))!==JSON.stringify(V(this._attachedTextSnapshot)):!1}_destroyAttachedEditor(){this._attachedEditor&&=(this._attachedEditor.destroy(),null),this._attachedTextSnapshot=null}_doneAttachedPanel(){if(this._attachedEditor){let e=this._attachedEditor.getJSON(),t=this._attachedEditor.getHTML();this._editor?.updateAttachedText(this._attachedTextIndex,e,t)}this._confirmForAttachedText=!1,this._destroyAttachedEditor(),this._attachedPanelOpen=!1,this._editor?.closeAttachedPanel(this._attachedTextIndex)}_cancelAttachedPanel(){if(this._isAttachedTextDirty()){this._confirmForDrafts=!1,this._confirmForAttachedText=!0,this._confirmPanelOpen=!0;return}this._discardAttachedPanel()}_handleAttachedEditorMouseDown(e){e.target===e.currentTarget&&(e.preventDefault(),this._focusAttachedEditorBoundary())}_handleDraftButtonClick(){this._loading||(this._hasWorkToLoseOnLeave()?(this._confirmForDrafts=!0,this._confirmPanelOpen=!0):this._openDraftsPanel())}async _openDraftsPanel(){this._draftsPanelOpen=!0,this._draftsLoading=!0,this._draftsError=null,this._draftMenuOpenId=null;try{let e=await fetch(`/api/posts?status=draft&limit=50`);if(!e.ok)throw Error(`Failed to load drafts`);let t=await e.json(),n=(Array.isArray(t)?t:t.posts??[]).map(e=>({id:e.id,slug:e.slug,format:e.format,title:(e.format===`quote`?e.sourceName:e.title)??null,bodyText:e.bodyText??null,bodyHtml:e.bodyHtml??null,url:(e.format===`quote`?e.sourceUrl:e.url)??null,quoteText:e.quoteText??null,replyToId:e.replyToId??null,updatedAt:e.updatedAt,mediaAttachments:(e.attachments??[]).filter(e=>e.type===`media`).map(e=>({id:e.id,previewUrl:e.previewUrl,alt:e.alt??null,mimeType:e.mimeType}))})),r=new Set(n.map(e=>e.id));this._drafts=n.filter(e=>!e.replyToId||!r.has(e.replyToId))}catch{this._draftsError=`Could not load drafts. Try again.`,this._drafts=[]}finally{this._draftsLoading=!1}}_closeDraftsPanel(){this._draftsPanelOpen=!1,this._draftMenuOpenId=null,this.updateComplete.then(()=>this._editor?.focusInput())}async _populateEditorFromPost(e,t){let{media:n,textAttachments:r,attachmentOrder:i}=await pt(t.attachments??[]);e.populate({format:t.format,title:t.format===`quote`?void 0:t.title??void 0,bodyJson:t.body??void 0,url:t.format===`quote`?t.sourceUrl??void 0:t.url??void 0,quoteText:t.quoteText??void 0,quoteAuthor:t.format===`quote`?t.sourceName??void 0:void 0,rating:t.rating??void 0,media:n,textAttachments:r,attachmentOrder:i})}async _loadDraft(e){this._draftsPanelOpen=!1,this._draftMenuOpenId=null,this.reset();let t=await fetch(`/api/posts/${e}`);if(!t.ok)return;let n=await t.json();if(this._draftSourceId=e,this._format=n.format,this._slug=n.slug??``,this._slugTaken=!1,this._slugCheckLoading=!1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugSuggestionKey=``,this._publishedAtInput=n.publishedAt?dt(n.publishedAt):``,this._publishedAtTimeMinutes=n.publishedAt?U(n.publishedAt):null,this._originalPublishedAt=n.publishedAt??null,this._initialPublishedAtTimeMinutes=this._publishedAtTimeMinutes,this._initialPublishedAtInput=this._publishedAtInput,this._initialSlug=this._slug.trim(),this._visibility=n.visibility??`public`,this._visibilityLocked=!!n.replyToId,!n.replyToId&&n.collectionIds?.length&&(this._collectionIds=n.collectionIds),n.replyToId&&(this._replyToId=n.replyToId,await this._fetchReplyContext(n.replyToId)),n.threadId===n.id||n.threadId===void 0)try{let e=await fetch(`/api/posts?status=draft&limit=50`);if(e.ok){let t=await e.json(),r=(Array.isArray(t)?t:t.posts??[]).filter(e=>e.id!==n.id&&e.threadId===n.id&&e.status===`draft`).map(e=>({id:e.id,format:e.format,slug:e.slug??null,replyToId:e.replyToId??null,title:e.title??null,body:e.body??null,url:e.url??null,sourceUrl:e.sourceUrl??null,sourceName:e.sourceName??null,quoteText:e.quoteText??null,rating:e.rating??null,attachments:e.attachments??[],visibility:e.visibility??null}));if(r.length>0){let e=[],t=n.id;for(let n=0;n<r.length;n++){let n=r.find(e=>e.replyToId===t);if(!n)break;e.push(n),t=n.id}for(let t of r)e.includes(t)||e.push(t);this._threadItems=[{id:L(),format:n.format},...e.map(e=>({id:L(),format:e.format,slug:e.slug??``,sourcePostId:e.id}))],this._focusedThreadIndex=0,await this.updateComplete;let i=Array.from(this.querySelectorAll(`jant-compose-editor`)),a=i[0];a&&await this._populateEditorFromPost(a,n);for(let t=0;t<e.length;t++){let r=i[t+1];if(!r)continue;let a=e[t];await this._populateEditorFromPost(r,{id:a.id,threadId:n.id,format:a.format,replyToId:a.replyToId,title:a.title,body:a.body,url:a.url,sourceUrl:a.sourceUrl,sourceName:a.sourceName,quoteText:a.quoteText,rating:a.rating,attachments:a.attachments,visibility:a.visibility})}globalThis.requestAnimationFrame(()=>{i[0]?.focusInput(),this._captureInitialSnapshot()});return}}}catch{}await this.updateComplete;let r=this._editor;r&&await this._populateEditorFromPost(r,n),globalThis.requestAnimationFrame(()=>{this._editor?.focusInput(),this._captureInitialSnapshot()})}async _deleteDraft(e){this._draftMenuOpenId=null,this._drafts=this._drafts.filter(t=>t.id!==e);try{if(!(await fetch(`/api/posts/${e}`,{method:`DELETE`})).ok)throw Error();d(this.labels.draftDeleted)}catch{d(`Failed to delete draft. Try again.`,`error`),this._openDraftsPanel()}}_formatDraftDate(e){let t=Date.now()/1e3-e;return t<60?`now`:t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:t<604800?`${Math.floor(t/86400)}d`:new Date(e*1e3).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}_getDraftPreview(e){return e.format===`quote`&&e.quoteText?e.quoteText:e.title?e.title:e.bodyText?e.bodyText:e.url?e.url:null}_getThreadLimitMessage(){return this.labels.threadLimitReached||`Threads can include up to 20 posts.`}static _DRAFT_KEY=`jant:compose-draft`;static _EDIT_DRAFT_KEY_PREFIX=`jant:compose-edit:`;static _DRAFT_MAX_AGE=6048e5;_currentDraftStorageKey(){return this._editPostId?e._EDIT_DRAFT_KEY_PREFIX+this._editPostId:e._DRAFT_KEY}_onContentChanged=()=>{this.requestUpdate(),this._hasManualSlug()||this._scheduleSuggestedSlugRefresh(),this._draftSourceId||this._scheduleDraftSave()};_handleTitleToggle=t=>{this._editPostId||this._draftSourceId||this._replyToId||t.target?.threadItem||e._setNoteTitleDefault(t.detail.showTitle)};_cancelDraftSaveTimer(){this._draftSaveTimer!==null&&(clearTimeout(this._draftSaveTimer),this._draftSaveTimer=null)}_scheduleDraftSave(){this._cancelDraftSaveTimer(),this._draftSaveTimer=setTimeout(()=>this._saveDraftToStorage(),1e3)}_onBeforeUnload=e=>{if(this._suppressBeforeUnload)return;this._draftSaveTimer!==null&&(this._cancelDraftSaveTimer(),this._saveDraftToStorage());let t=this.closest(`dialog`);this._hasUnsavedChanges()&&(this.pageMode||t?.open===!0)&&(e.preventDefault(),e.returnValue=``)};_saveDraftToStorage(){if(this._threadItems.length>0){let t=Array.from(this.querySelectorAll(`jant-compose-editor`));if(!t.some(e=>{let t=e.getData();return!!t.body||!!t.title.trim()||!!t.url.trim()||!!t.quoteText.trim()||t.rating>0||t.attachedTexts.length>0||t.attachments.length>0})){this._releaseStoredDraft();return}let n=this._threadItems.map((n,r)=>{let i=t[r];if(!i)return null;let a=i.getData();return{format:n.format,publishedAtInput:n.publishedAtInput,publishedAtTimeMinutes:n.publishedAtTimeMinutes,slug:n.slug,title:a.title,bodyJson:i.getNormalizedBodyJson(),url:a.url,quoteText:a.quoteText,quoteAuthor:a.quoteAuthor,rating:a.rating,showTitle:n.format===`note`&&i._showTitle,showRating:a.rating>0&&i._showRating,attachedTexts:a.attachedTexts.map(e=>({clientId:e.clientId,bodyJson:e.bodyJson,bodyHtml:e.bodyHtml,summary:e.summary})),attachmentOrder:[...a.attachmentOrder],mediaAttachments:e._mediaSnapshotFromAttachments(a.attachments)}}).filter(e=>e!==null),r={format:this._threadItems[0]?.format??this._format,title:``,bodyJson:null,url:``,quoteText:``,quoteAuthor:``,slug:this._slug,publishedAtInput:this._publishedAtInput,publishedAtTimeMinutes:this._publishedAtTimeMinutes,visibility:this._visibility,rating:0,showTitle:!1,showRating:!1,collectionIds:[...this._collectionIds],replyToId:this._replyToId,language:this._language,translationOfId:this._translationOf?.id??null,attachedTexts:[],attachmentOrder:[],threadItems:n,savedAt:Date.now()};this._writeStoredDraft(r);return}let t=this._editor;if(!t)return;if(!this._hasUnsavedChanges()){this._releaseStoredDraft();return}let n=t.getData();if(!(n.body||n.title.trim()||n.url.trim()||n.quoteText.trim()||n.quoteAuthor.trim()||n.rating>0||n.attachments.length>0||n.attachedTexts.length>0)){this._releaseStoredDraft();return}let r={format:this._format,title:n.title,bodyJson:t.getNormalizedBodyJson(),url:n.url,quoteText:n.quoteText,quoteAuthor:n.quoteAuthor,slug:this._slug,publishedAtInput:this._publishedAtInput,publishedAtTimeMinutes:this._publishedAtTimeMinutes,visibility:this._visibility,rating:n.rating,showTitle:this._format===`note`&&t._showTitle,showRating:n.rating>0&&t._showRating,collectionIds:[...this._collectionIds],replyToId:this._replyToId,language:this._language,translationOfId:this._translationOf?.id??null,attachedTexts:n.attachedTexts.map(e=>({clientId:e.clientId,bodyJson:e.bodyJson,bodyHtml:e.bodyHtml,summary:e.summary,mediaId:e.mediaId,originalBodyJson:e.mediaId?e.originalBodyJson??null:void 0})),attachmentOrder:[...n.attachmentOrder],mediaAttachments:e._mediaSnapshotFromAttachments(n.attachments),savedAt:Date.now()};this._writeStoredDraft(r)}_writeStoredDraft(e){try{globalThis.localStorage.setItem(this._currentDraftStorageKey(),JSON.stringify(e)),this._hasOwnedContent=!0}catch(e){console.warn(`[jant] compose draft could not be stored`,e),this._reportedStorageFailure||(this._reportedStorageFailure=!0,d(this.labels.draftStoreFailed,`error`))}}_releaseStoredDraft(){this._hasOwnedContent&&(this._hasOwnedContent=!1,globalThis.localStorage.removeItem(this._currentDraftStorageKey()))}_clearDraftFromStorage(){this._cancelDraftSaveTimer(),this._hasOwnedContent=!1,globalThis.localStorage.removeItem(this._currentDraftStorageKey())}clearLocalDraftFromStorage(){this._clearDraftFromStorage()}clearEditDraftFromStorage(t){globalThis.localStorage.removeItem(e._EDIT_DRAFT_KEY_PREFIX+t)}static _mediaSnapshotFromAttachments(e){return e.flatMap(e=>e.status===`done`&&e.mediaId&&e.remoteUrl?[{clientId:e.clientId,mediaId:e.mediaId,url:e.remoteUrl,mimeType:e.file.type,name:e.file.name||void 0,alt:e.alt||void 0,summary:e.summary,chars:e.chars,persisted:e.persisted||void 0}]:[])}static _restoredMediaToPopulate(e){return e.map(e=>({id:e.mediaId,clientId:e.clientId,previewUrl:e.url,mimeType:e.mimeType,originalName:e.name,alt:e.alt,summary:e.summary??void 0,chars:e.chars??void 0,persisted:e.persisted??!1}))}static _mergeRestoredMedia(e,t){let n=new Map;for(let t of e??[])n.set(t.clientId,t);for(let e of t??[])n.set(e.clientId,e);return n}async restoreLocalDraft(t){let n=e._DRAFT_KEY;if(this._editPostId||this._draftSourceId)return this._reportRestoreOutcome(`composer-busy`,n);if(this._hasContent())return this._reportRestoreOutcome(`composer-has-content`,n);let r;try{r=globalThis.localStorage.getItem(n)}catch{return`none`}if(!r)return`none`;let i;try{i=JSON.parse(r)}catch{return this._reportRestoreOutcome(`unreadable`,n,r)}if(Date.now()-i.savedAt>e._DRAFT_MAX_AGE)return this._reportRestoreOutcome(`expired`,n,r,i);if(t?.expectedReplyToId!==void 0&&i.replyToId!==t.expectedReplyToId)return this._reportRestoreOutcome(`other-reply`,n,r,i);if(this._collectionIds=i.replyToId?[]:[...i.collectionIds??[]],this._slug=i.slug??``,this._slugTaken=!1,this._slugCheckLoading=!1,this._suggestedSlug=``,this._suggestedSlugLoading=!1,this._slugSuggestionKey=``,this._publishedAtInput=i.publishedAtInput??``,this._publishedAtTimeMinutes=i.publishedAtTimeMinutes??null,this._visibility=i.visibility??`public`,this._language=i.language??null,i.translationOfId&&await this._loadTranslationSource(i.translationOfId),i.replyToId&&(this._replyToId=i.replyToId,this._visibilityLocked=!0,await this._fetchReplyContext(i.replyToId)),i.threadItems&&i.threadItems.length>=2){this._format=i.threadItems[0].format,this._threadItems=i.threadItems.map(e=>({id:L(),format:e.format,publishedAtInput:e.publishedAtInput,publishedAtTimeMinutes:e.publishedAtTimeMinutes,slug:e.slug})),this._focusedThreadIndex=0,await this.updateComplete;let n=Array.from(this.querySelectorAll(`jant-compose-editor`));for(let r=0;r<i.threadItems.length;r++){let a=i.threadItems[r],o=n[r];if(!o)continue;let s=a.attachedTexts?.flatMap(e=>{let t=V(e.bodyJson);return t?[{clientId:e.clientId,bodyJson:JSON.stringify(t),bodyHtml:e.bodyHtml,summary:e.summary}]:[]}),c=t?.extraMedia?.filter(e=>a.attachmentOrder?.includes(e.clientId)),l=[...e._mergeRestoredMedia(a.mediaAttachments,c).values()];o.populate({format:a.format,title:a.title||void 0,bodyJson:a.bodyJson?JSON.stringify(a.bodyJson):void 0,url:a.url||void 0,quoteText:a.quoteText||void 0,quoteAuthor:a.quoteAuthor||void 0,rating:a.rating||void 0,showTitle:a.showTitle,showRating:a.showRating,media:l.length?e._restoredMediaToPopulate(l):void 0,textAttachments:s?.length?s:void 0,attachmentOrder:a.attachmentOrder})}return this._draftRestored=!0,this._hasOwnedContent=!0,t?.notify!==!1&&d(this.labels.draftRestored),globalThis.requestAnimationFrame(()=>{this._captureInitialSnapshot()}),`restored`}this._format=i.format,await this.updateComplete;let a=i.attachedTexts?.flatMap(e=>{let t=V(e.bodyJson);return t?[{clientId:e.clientId,bodyJson:JSON.stringify(t),bodyHtml:e.bodyHtml,summary:e.summary}]:[]}),o=[...e._mergeRestoredMedia(i.mediaAttachments,t?.extraMedia).values()];return this._editor?.populate({format:i.format,title:i.title||void 0,bodyJson:i.bodyJson?JSON.stringify(i.bodyJson):void 0,url:i.url||void 0,quoteText:i.quoteText||void 0,quoteAuthor:i.quoteAuthor||void 0,rating:i.rating||void 0,showTitle:i.showTitle,showRating:i.showRating,media:o.length?e._restoredMediaToPopulate(o):void 0,textAttachments:a?.length?a:void 0,attachmentOrder:i.attachmentOrder}),this._draftRestored=!0,this._hasOwnedContent=!0,t?.notify!==!1&&d(this.labels.draftRestored),globalThis.requestAnimationFrame(()=>{this._captureInitialSnapshot()}),`restored`}_reportRestoreOutcome(e,t,n,r){if(e===`restored`||e===`none`)return e;let i=n;if(i===void 0)try{i=globalThis.localStorage.getItem(t)}catch{i=null}return i?(console.warn(`[jant] compose draft not restored: ${e}`,{key:t,bytes:i.length,savedAt:r?.savedAt?new Date(r.savedAt).toISOString():null,thread:r?.threadItems?.length??null}),e):`none`}_restoreEditDraftIfAvailable(t,n){let r=e._EDIT_DRAFT_KEY_PREFIX+t,i;try{i=globalThis.localStorage.getItem(r)}catch{return!1}if(!i)return!1;let a;try{a=JSON.parse(i)}catch{return this._reportRestoreOutcome(`unreadable`,r,i),!1}if(Date.now()-a.savedAt>e._DRAFT_MAX_AGE)return this._reportRestoreOutcome(`expired`,r,i,a),!1;this._format=a.format,this._collectionIds=this._replyToId?[]:[...a.collectionIds??[]],this._slug=a.slug??``,this._publishedAtInput=a.publishedAtInput??``,this._publishedAtTimeMinutes=a.publishedAtTimeMinutes??null,this._visibility=a.visibility??`public`,this._language=a.language??null;let o=a.attachedTexts?.flatMap(e=>{let t=V(e.bodyJson);return t?[{clientId:e.clientId,bodyJson:JSON.stringify(t),bodyHtml:e.bodyHtml,summary:e.summary,mediaId:e.mediaId,originalBodyJson:e.mediaId?JSON.stringify(e.originalBodyJson??null):void 0}]:[]}),s=a.mediaAttachments??[];return this._editor?.populate({format:a.format,title:a.title||void 0,bodyJson:a.bodyJson?JSON.stringify(a.bodyJson):void 0,url:a.url||void 0,quoteText:a.quoteText||void 0,quoteAuthor:a.quoteAuthor||void 0,rating:a.rating||void 0,showTitle:a.showTitle,showRating:a.showRating,media:s.length?e._restoredMediaToPopulate(s):void 0,textAttachments:o?.length?o:void 0,attachmentOrder:a.attachmentOrder}),this._draftRestored=!0,this._hasOwnedContent=!0,n!==!1&&d(this.labels.draftRestored),!0}async _applyTranslationRequestFromUrl(){let e=new URLSearchParams(globalThis.location?.search??``),t=e.get(`translationOf`);if(!t)return;let n=e.get(`lang`);n&&this.languages.some(e=>e.tag===n)&&(this._language=n),this._translationOf||await this._loadTranslationSource(t,{seed:!0})}async _focusPageEditorOnMount(){this._pageFocusApplied||(this.autoRestoreDraft&&await this.restoreLocalDraft(),await this._applyTranslationRequestFromUrl(),await this.updateComplete,globalThis.requestAnimationFrame(()=>{this._editor?.focusInput(),this._pageFocusApplied=!0}))}_renderDraftsPanel(){return this._draftsPanelOpen?o`
121
+ <div class="compose-drafts-panel">
122
+ <div class="compose-alt-header">
123
+ <button
124
+ type="button"
125
+ class="compose-attached-panel-back"
126
+ @click=${()=>this._closeDraftsPanel()}
127
+ >
128
+ <svg
129
+ class="icon-fine"
130
+ width="16"
131
+ height="16"
132
+ viewBox="0 0 16 16"
133
+ fill="none"
134
+ stroke="currentColor"
135
+ stroke-width="1.5"
136
+ stroke-linecap="round"
137
+ stroke-linejoin="round"
138
+ >
139
+ <path d="M11 3L6 8l5 5" />
140
+ </svg>
141
+ </button>
142
+ <span class="compose-alt-title">${this.labels.drafts}</span>
143
+ </div>
144
+ ${this._draftsLoading?o`<div class="compose-drafts-loading">
145
+ <svg
146
+ class="animate-spin size-5"
147
+ xmlns="http://www.w3.org/2000/svg"
148
+ viewBox="0 0 24 24"
149
+ fill="none"
150
+ stroke="currentColor"
151
+ stroke-width="2"
152
+ stroke-linecap="round"
153
+ stroke-linejoin="round"
154
+ >
155
+ <path d="M21 12a9 9 0 1 1-6.219-8.56" />
156
+ </svg>
157
+ </div>`:this._draftsError?o`<div class="compose-drafts-empty">
158
+ ${this._draftsError}
159
+ </div>`:this._drafts.length===0?o`<div class="compose-drafts-empty">
160
+ ${this.labels.draftsEmpty}
161
+ </div>`:o`<div class="compose-drafts-list">
162
+ ${this._drafts.map((e,t)=>o`
163
+ ${t>0?o`<div class="compose-drafts-divider"></div>`:c}
164
+ ${this._renderDraftItem(e)}
165
+ `)}
166
+ </div>`}
167
+ </div>
168
+ `:c}_renderDraftItem(e){let n=this._getDraftPreview(e),r=this.labels[e.format],i=`draft-actions-${e.id}`,a=this._draftMenuOpenId===e.id;return o`
169
+ <div class="compose-draft-item" @click=${()=>this.openDraft(e.id)}>
170
+ <div class="compose-draft-content">
171
+ ${n?o`<div class="compose-draft-preview">${n}</div>`:o`<div
172
+ class="compose-draft-preview compose-draft-preview-empty"
173
+ >
174
+ Empty draft
175
+ </div>`}
176
+ <div class="compose-draft-meta">
177
+ <span class="compose-draft-format">${r}</span>
178
+ <span aria-hidden="true">·</span>
179
+ ${this._formatDraftDate(e.updatedAt)}
180
+ </div>
181
+ </div>
182
+ <div class="relative">
183
+ ${a?o`<div
184
+ class="compose-dropdown-backdrop"
185
+ @click=${e=>{e.stopPropagation(),this._draftMenuOpenId=null}}
186
+ ></div>`:c}
187
+ <button
188
+ type="button"
189
+ class="compose-draft-more"
190
+ aria-label=${this.labels.draftActions}
191
+ aria-haspopup="menu"
192
+ aria-expanded=${a?`true`:`false`}
193
+ aria-controls=${i}
194
+ @click=${t=>{t.stopPropagation(),this._draftMenuOpenId=this._draftMenuOpenId===e.id?null:e.id}}
195
+ >
196
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
197
+ <circle cx="4" cy="8" r="1.2" />
198
+ <circle cx="8" cy="8" r="1.2" />
199
+ <circle cx="12" cy="8" r="1.2" />
200
+ </svg>
201
+ </button>
202
+ ${a?o`
203
+ <div
204
+ id=${i}
205
+ class="compose-dropdown compose-dropdown-right"
206
+ role="menu"
207
+ >
208
+ <a
209
+ class="compose-dropdown-item"
210
+ href=${t(`/preview/${e.slug}`)}
211
+ target="_blank"
212
+ rel="noopener noreferrer"
213
+ role="menuitem"
214
+ @click=${e=>{e.stopPropagation(),this._draftMenuOpenId=null}}
215
+ >
216
+ ${this.labels.previewDraft}
217
+ </a>
218
+ <div
219
+ class="compose-dropdown-separator"
220
+ role="separator"
221
+ ></div>
222
+ <button
223
+ type="button"
224
+ class="compose-dropdown-item compose-dropdown-item-danger"
225
+ role="menuitem"
226
+ @click=${t=>{t.stopPropagation(),this._deleteDraft(e.id)}}
227
+ >
228
+ ${this.labels.deleteDraft}
229
+ </button>
230
+ </div>
231
+ `:c}
232
+ </div>
233
+ </div>
234
+ `}_renderTranslationContext(){let e=this._translationOf;if(!e)return c;let t=this.languages.find(e=>e.tag===this._language)?.label??``,n=t?this.labels.translationContextInLanguage.replace(`{language}`,t):this.labels.translationContext,r=this._translationCollapsed;return o`
235
+ <div class="compose-translation-context">
236
+ ${r?c:e.previewHtml?o`<div
237
+ class="compose-translation-original"
238
+ tabindex="0"
239
+ role="region"
240
+ aria-label=${this.labels.translationContextOriginal}
241
+ >
242
+ <div class="compose-translation-preview">
243
+ ${f(e.previewHtml)}
244
+ </div>
245
+ </div>`:o`<p class="compose-translation-fallback">
246
+ ${e.href?o`<a
247
+ href=${e.href}
248
+ target="_blank"
249
+ rel="noopener noreferrer"
250
+ title=${this.labels.translationContextOpen}
251
+ >${e.title}</a
252
+ >`:e.title}
253
+ </p>`}
254
+ <div class="compose-translation-seam">
255
+ <span class="compose-translation-seam-label">
256
+ ${this._iconArrowDown()}${n}
257
+ </span>
258
+ <span class="compose-translation-seam-dot" aria-hidden="true">·</span>
259
+ <button
260
+ type="button"
261
+ class="compose-translation-seam-toggle"
262
+ aria-expanded=${r?`false`:`true`}
263
+ aria-label=${r?this.labels.translationContextShowLong:this.labels.translationContextHideLong}
264
+ @click=${()=>{this._translationCollapsed=!this._translationCollapsed}}
265
+ >
266
+ ${r?this.labels.translationContextShow:this.labels.translationContextHide}
267
+ </button>
268
+ </div>
269
+ </div>
270
+ `}_adoptTranslationPreview(){let e=this.querySelector(`.compose-translation-preview:not([data-preview-adopted])`);if(e){e.dataset.previewAdopted=``;for(let t of e.querySelectorAll(`a[href]`))t.setAttribute(`target`,`_blank`),t.setAttribute(`rel`,`noopener noreferrer`);for(let t of e.querySelectorAll(`[data-post-id]`))delete t.dataset.postId,delete t.dataset.post,delete t.dataset.threadRootId,delete t.dataset.postMenuTarget,t.classList.remove(`post-menu-target`);for(let t of e.querySelectorAll(`[data-post-menu-trigger], [data-reply-trigger], [data-timeline-item]`))t.remove()}}_iconArrowDown(){return o`<svg
271
+ class="compose-translation-seam-icon"
272
+ xmlns="http://www.w3.org/2000/svg"
273
+ viewBox="0 0 24 24"
274
+ fill="none"
275
+ stroke="currentColor"
276
+ stroke-width="1.9"
277
+ stroke-linecap="round"
278
+ stroke-linejoin="round"
279
+ aria-hidden="true"
280
+ >
281
+ <path d="M12 5v14" />
282
+ <path d="m19 12-7 7-7-7" />
283
+ </svg>`}_renderReplyContext(){if(!this._replyToId||!this._replyToData)return c;let{contentHtml:e,dateText:t,media:n}=this._replyToData,r=this._replyExpanded;return o`
284
+ <div class="compose-reply-row">
285
+ <div class="compose-thread-dot"></div>
286
+ <div
287
+ class=${w({"compose-reply-context":!0,expanded:r})}
288
+ >
289
+ <div class="compose-reply-context-body">
290
+ ${f(e)}
291
+ ${n?.length?o`<div
292
+ class="compose-reply-context-media"
293
+ data-post-media
294
+ data-lightbox-group=${JSON.stringify(n.map(e=>({url:e.url,alt:e.alt??``,width:e.width,height:e.height,mimeType:e.mimeType})))}
295
+ >
296
+ ${n.map((e,t)=>o`
297
+ <a
298
+ href=${e.url}
299
+ data-lightbox-index=${t}
300
+ class="compose-reply-context-media-link"
301
+ >
302
+ <img
303
+ src=${e.previewUrl}
304
+ alt=${e.alt??``}
305
+ class="compose-reply-context-media-img"
306
+ loading="lazy"
307
+ />
308
+ </a>
309
+ `)}
310
+ </div>`:c}
311
+ </div>
312
+ ${r?c:o`<div class="compose-reply-fade"></div>`}
313
+ </div>
314
+ </div>
315
+ <div class="compose-reply-meta">
316
+ ${t?o`<span>${t}</span><span>·</span>`:c}
317
+ <button
318
+ type="button"
319
+ class="compose-reply-toggle"
320
+ @click=${()=>{this._replyExpanded=!this._replyExpanded}}
321
+ >
322
+ ${r?this.labels.showLess:this.labels.showMore}
323
+ </button>
324
+ </div>
325
+ `}static _FORMATS=[`note`,`link`,`quote`];_shouldConvertOnFormatSwitch(){return!!(this._editPostId||this._draftSourceId)}_convertForFormatSwitch(e,t,n){e&&t!==n&&this._shouldConvertOnFormatSwitch()&&e.applyConvertedFields(Ie(t,n,e.getConvertibleFields()))}_switchFormat(e){this._format!==e&&(this._convertForFormatSwitch(this._editor,this._format,e),this._cancelDraftSaveTimer(),this._format=e,this._showPublishPanel=!1,this._shouldAutofocusFormatInput()&&globalThis.requestAnimationFrame(()=>this._editor?.focusInput()))}_renderCloseComposeControl(){return this.pageMode||this._threadItems.length>0?c:o`
326
+ <button
327
+ type="button"
328
+ class="compose-close-btn"
329
+ aria-label=${this.labels.close}
330
+ title=${this.labels.close}
331
+ @click=${()=>this.requestClose()}
332
+ >
333
+ <svg
334
+ width="14"
335
+ height="14"
336
+ viewBox="0 0 16 16"
337
+ fill="none"
338
+ stroke="currentColor"
339
+ stroke-width="1.8"
340
+ stroke-linecap="round"
341
+ aria-hidden="true"
342
+ >
343
+ <path d="M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5" />
344
+ </svg>
345
+ </button>
346
+ `}_renderCollectionSelector(){let e=this.collections??[],t=g(e,this._collectionPickerOrder),n=this._collectionSearch.trim().length>0,r=v(t,this._collectionSearch),i=this._collectionIds.length,a=i>0?this._selectedCollectionLabel(e):this.labels.collection,s=n?this.labels.noCollections:this.labels.emptyCollections;return o`
347
+ <div class="flex-1 min-w-0">
348
+ ${this._showCollection?o`<div
349
+ class="compose-dropdown-backdrop"
350
+ @click=${()=>this._closeCollectionPicker()}
351
+ ></div>`:c}
352
+ <div
353
+ class="select compose-collection-select"
354
+ data-select-initialized
355
+ data-open=${this._showCollection?`true`:c}
356
+ >
357
+ <button
358
+ type="button"
359
+ class="compose-collection-trigger"
360
+ aria-haspopup="listbox"
361
+ aria-expanded=${this._showCollection?`true`:`false`}
362
+ data-open=${this._showCollection?`true`:c}
363
+ data-selected=${i>0?`true`:c}
364
+ @keydown=${this._handleCollectionTriggerKeydown}
365
+ @click=${()=>{let e=!this._showCollection;this._showPublishPanel=!1,this._showLanguagePicker=!1,e&&this._prepareCollectionPickerOrder(),this._showCollection=e,e||this._closeCollectionPicker()}}
366
+ >
367
+ <!-- No chevron: the glyph already says "picker", and a second one
368
+ pointing down only made the control wider. -->
369
+ ${z(at.collection,`compose-collection-trigger-svg`)}
370
+ <span class="compose-collection-label">${a}</span>
371
+ </button>
372
+ <div
373
+ class="compose-collection-popover"
374
+ data-popover
375
+ aria-hidden=${this._showCollection?`false`:`true`}
376
+ >
377
+ ${e.length>0?o`<div class="compose-collection-popover-header">
378
+ <label class="compose-collection-search-shell">
379
+ ${z(at.search,`compose-collection-search-icon`)}
380
+ <input
381
+ type="text"
382
+ role="combobox"
383
+ class="compose-collection-search-input"
384
+ placeholder=${this.labels.searchCollections}
385
+ autocomplete="off"
386
+ autocorrect="off"
387
+ spellcheck="false"
388
+ .value=${this._collectionSearch}
389
+ @keydown=${this._handleCollectionSearchKeydown}
390
+ @input=${e=>{this._collectionSearch=e.target.value}}
391
+ />
392
+ </label>
393
+ </div>`:c}
394
+ <div
395
+ role="listbox"
396
+ class="compose-collection-options"
397
+ aria-multiselectable="true"
398
+ >
399
+ ${r.length>0?r.map(e=>{let t=this._collectionIds.includes(e.id);return o`
400
+ <button
401
+ type="button"
402
+ class=${w({"compose-collection-option":!0,"compose-collection-option-selected":t})}
403
+ role="option"
404
+ data-value=${e.id}
405
+ aria-selected=${t?`true`:`false`}
406
+ @keydown=${t=>this._handleCollectionOptionKeydown(t,e.id)}
407
+ @click=${()=>this._handleCollectionOptionClick(e.id)}
408
+ >
409
+ <span class="compose-collection-option-label"
410
+ >${e.title}</span
411
+ >
412
+ <span
413
+ class=${w({"compose-collection-option-marker":!0,"compose-collection-option-marker-selected":t,"compose-collection-option-marker-add":!t})}
414
+ >
415
+ ${t?o`<svg
416
+ xmlns="http://www.w3.org/2000/svg"
417
+ class="compose-collection-option-check-circle"
418
+ viewBox="0 0 24 24"
419
+ fill="none"
420
+ aria-hidden="true"
421
+ >
422
+ <circle
423
+ cx="12"
424
+ cy="12"
425
+ r="10"
426
+ fill="currentColor"
427
+ />
428
+ <path
429
+ d="M8 12.5 10.7 15.2 16.4 9.5"
430
+ stroke="var(--site-page-bg)"
431
+ stroke-width="2.3"
432
+ stroke-linecap="round"
433
+ stroke-linejoin="round"
434
+ />
435
+ </svg>`:z(at.plusCircle,`compose-collection-option-plus-circle`)}
436
+ </span>
437
+ </button>
438
+ `}):o`<div class="compose-collection-empty">
439
+ ${s}
440
+ </div>`}
441
+ </div>
442
+ <div class="compose-collection-footer">
443
+ <button
444
+ type="button"
445
+ class="compose-collection-add-action"
446
+ @keydown=${this._handleCollectionAddActionKeydown}
447
+ @click=${()=>{this._closeCollectionPicker(),this._addCollectionPanelOpen=!0}}
448
+ >
449
+ <span class="compose-collection-add-icon">
450
+ ${z(at.plus,`compose-collection-add-svg`)}
451
+ </span>
452
+ ${this.labels.addCollection}
453
+ </button>
454
+ </div>
455
+ </div>
456
+ </div>
457
+ </div>
458
+ `}_closeAddCollectionPanel(){this._addCollectionPanelOpen=!1,this.updateComplete.then(()=>{this.querySelector(`.compose-collection-trigger`)?.focus()})}async _handleAddCollectionSubmit(e){let t=e;t.stopPropagation();let n=t.detail;if(!n)return;let r=this.querySelector(`jant-collection-form`);r&&(r.loading=!0);try{let e=await fetch(`/api/collections`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n.data)}),t=await e.json().catch(()=>null);if(!e.ok)throw Error(t?.error||`Couldn't create collection. Try again.`);if(!t?.id||!t.title)throw Error(`Couldn't create collection. Try again.`);let r={id:t.id,title:t.title,slug:t.slug??``};(!await this.refreshCollections()||!this.collections.some(e=>e.id===t.id))&&(this.collections=[...this.collections,r]),this._collectionIds=[...this._collectionIds,t.id],this._closeAddCollectionPanel(),d(this.labels.collectionFormLabels.createdLabel)}catch(e){d(e instanceof Error?e.message:`Couldn't create collection. Try again.`,`error`)}finally{r&&(r.loading=!1)}}_submitAddCollectionForm(){let e=this.querySelector(`[data-collection-quick-dialog] form`);e&&e.requestSubmit()}_renderAddCollectionPanel(){return this._addCollectionPanelOpen?o`
459
+ <div
460
+ class="collection-quick-dialog-backdrop"
461
+ @click=${()=>this._closeAddCollectionPanel()}
462
+ ></div>
463
+ <div
464
+ class="collection-quick-dialog"
465
+ data-collection-quick-dialog
466
+ role="dialog"
467
+ aria-modal="true"
468
+ aria-label=${this.labels.addCollection}
469
+ @click=${e=>e.stopPropagation()}
470
+ >
471
+ <div class="collection-quick-dialog-header">
472
+ <div class="collection-quick-dialog-title-block">
473
+ <h2 class="collection-quick-dialog-title">
474
+ ${this.labels.addCollection}
475
+ </h2>
476
+ <p class="collection-quick-dialog-note">
477
+ ${this.labels.collectionFormLabels.quickHint}
478
+ </p>
479
+ </div>
480
+ <button
481
+ type="button"
482
+ class="collection-quick-dialog-cancel"
483
+ @click=${()=>this._closeAddCollectionPanel()}
484
+ >
485
+ ${this.labels.collectionFormLabels.cancelLabel}
486
+ </button>
487
+ </div>
488
+ <div class="collection-quick-dialog-body">
489
+ <jant-collection-form
490
+ .labels=${this.labels.collectionFormLabels}
491
+ .initial=${{title:``,slug:``}}
492
+ action=${t(`/api/collections`)}
493
+ @jant:collection-submit=${e=>this._handleAddCollectionSubmit(e)}
494
+ ></jant-collection-form>
495
+ </div>
496
+ <div class="collection-quick-dialog-footer">
497
+ <button
498
+ type="button"
499
+ class="compose-post-btn collection-quick-dialog-submit"
500
+ @click=${()=>this._submitAddCollectionForm()}
501
+ >
502
+ ${this.labels.collectionFormLabels.quickSubmitLabel}
503
+ </button>
504
+ </div>
505
+ </div>
506
+ `:c}_renderAttachedPanel(){return this._attachedPanelOpen?o`
507
+ <div class="compose-attached-panel">
508
+ <div class="compose-alt-header">
509
+ <button
510
+ type="button"
511
+ class="compose-attached-cancel"
512
+ @click=${()=>this._cancelAttachedPanel()}
513
+ >
514
+ ${this.labels.cancel}
515
+ </button>
516
+ <span class="compose-alt-title">${this.labels.attachedText}</span>
517
+ <button
518
+ type="button"
519
+ class="compose-attached-done"
520
+ @click=${()=>this._doneAttachedPanel()}
521
+ >
522
+ ${this.labels.done}
523
+ </button>
524
+ </div>
525
+ <div class="flex-1 p-4 overflow-hidden flex flex-col">
526
+ <div
527
+ class="compose-attached-tiptap compose-tiptap-body"
528
+ @mousedown=${e=>this._handleAttachedEditorMouseDown(e)}
529
+ ></div>
530
+ </div>
531
+ </div>
532
+ `:c}_renderAltPanel(){if(!this._altPanelOpen)return c;let e=this._getAltAttachment();if(!e)return c;let t=F(e.file.type);return o`
533
+ <div class="compose-alt-panel">
534
+ <div class="compose-alt-header">
535
+ <button
536
+ type="button"
537
+ class="compose-attached-panel-back"
538
+ @click=${()=>this._closeAltPanel()}
539
+ >
540
+ <svg
541
+ class="icon-fine"
542
+ width="16"
543
+ height="16"
544
+ viewBox="0 0 16 16"
545
+ fill="none"
546
+ stroke="currentColor"
547
+ stroke-width="1.5"
548
+ stroke-linecap="round"
549
+ stroke-linejoin="round"
550
+ >
551
+ <path d="M11 3L6 8l5 5" />
552
+ </svg>
553
+ </button>
554
+ <span class="compose-alt-title">${this.labels.addAltTitle}</span>
555
+ </div>
556
+ <div class="compose-alt-preview">
557
+ ${t===`image`?o`<img
558
+ src=${e.previewUrl}
559
+ alt=""
560
+ class="compose-alt-preview-img"
561
+ />`:t===`video`?o`<video
562
+ src=${e.previewUrl}
563
+ class="compose-alt-preview-img"
564
+ preload="metadata"
565
+ muted
566
+ ></video>`:o`<span class="text-sm text-muted-foreground"
567
+ >${e.file.name}</span
568
+ >`}
569
+ </div>
570
+ <div class="compose-alt-input-row">
571
+ <input
572
+ type="text"
573
+ .value=${e.alt}
574
+ @input=${e=>this._onAltInput(e)}
575
+ class="compose-input compose-alt-input"
576
+ placeholder=${this.labels.altPlaceholder}
577
+ />
578
+ </div>
579
+ <div class="compose-alt-footer">
580
+ <span class="text-xs text-muted-foreground"
581
+ >${this.labels.altHint}</span
582
+ >
583
+ <button
584
+ type="button"
585
+ class="compose-post-btn"
586
+ @click=${()=>this._closeAltPanel()}
587
+ >
588
+ ${this.labels.done}
589
+ </button>
590
+ </div>
591
+ </div>
592
+ `}_renderConfirmPanel(){if(!this._confirmPanelOpen)return c;let e=!!this._editPostId,t=this._confirmForAttachedText?this.labels.confirmAttachedTitle:e?this.labels.confirmEditTitle:this.labels.confirmCloseTitle,n=this._confirmForAttachedText?this.labels.confirmAttachedSubtitle:e?this.labels.confirmEditSubtitle:this.labels.confirmCloseSubtitle,r=this._confirmForAttachedText?this.labels.confirmAttachedSave:e?this.labels.confirmEditPublish:this.labels.confirmCloseSave,i=this._confirmForAttachedText?this.labels.confirmAttachedDiscard:e?this.labels.confirmEditDiscard:this.labels.confirmCloseDiscard;return o`
593
+ <div class="compose-confirm-panel">
594
+ <div class="compose-confirm-sheet">
595
+ <div class="compose-confirm-header">
596
+ <p class="compose-confirm-title">${t}</p>
597
+ <p class="compose-confirm-subtitle">${n}</p>
598
+ </div>
599
+ <button
600
+ type="button"
601
+ class="compose-confirm-action compose-confirm-save"
602
+ @click=${()=>this._handleConfirmSave()}
603
+ >
604
+ ${r}
605
+ </button>
606
+ <button
607
+ type="button"
608
+ class="compose-confirm-action compose-confirm-discard"
609
+ @click=${()=>this._handleConfirmDiscard()}
610
+ >
611
+ ${i}
612
+ </button>
613
+ <button
614
+ type="button"
615
+ class="compose-confirm-action compose-confirm-cancel"
616
+ @click=${()=>this.requestClose()}
617
+ >
618
+ ${this.labels.confirmCloseCancel}
619
+ </button>
620
+ </div>
621
+ </div>
622
+ `}_getSubmitLabel(){return this._editPostId?this.labels.update:this._replyToId?this._quietReply?this.labels.quietReplyLabel:this.labels.reply:this._visibility===`latest_hidden`?this.labels.postHiddenFromLatest:this._visibility===`private`?this.labels.postPrivately:this.labels.post}_getSlugSyncValidationMessage(){let e=ee(this._slug);return e===`invalid`?this.labels.publishSlugInvalid:e===`reserved`?this.labels.publishSlugReserved:null}_getSlugValidationMessage(){return this._getSlugSyncValidationMessage()||(this._hasManualSlug()&&this._slugTaken?this.labels.publishSlugTaken:null)}_getSlugPreviewUrl(){if(!this._hasManualSlug()||this._getSlugValidationMessage())return null;let e=t(`/${this._slug.trim()}`),n=globalThis.location?.origin&&globalThis.location.origin!==`null`?globalThis.location.origin:`http://localhost`;return new URL(e,`${n}/`).toString()}_getSlugPreviewParts(){let e=this._getSlugPreviewUrl();if(!e)return null;let t=new URL(e);return{full:e,origin:t.origin,path:`${t.pathname}${t.search}${t.hash}`}}_getSlugStatusMessage(){return this._hasManualSlug()?this._getSlugValidationMessage()?this._getSlugValidationMessage():null:this._suggestedSlugLoading?this.labels.publishSlugGenerating:null}_getCurrentTimestamp(){return Math.floor(Date.now()/1e3)}_getPublishedAtMaxInput(){return dt(this._getCurrentTimestamp())}_getPublishedAtTimeMinutes(){return this._publishedAtTimeMinutes??U(this._getCurrentTimestamp())}_hasPublishedAtValue(){return this._publishedAtInput.trim().length>0}_getPublishedAtValidationMessage(){return this._hasPublishedAtValue()?H(this._publishedAtInput)===null?this.labels.publishDateInvalid:this._publishedAtInput>this._getPublishedAtMaxInput()?this.labels.publishDateFutureError:null:null}_getPublishedAtSummary(){if(this._editPostId||this._draftSourceId){if(this._publishedAtInput===this._initialPublishedAtInput)return null;if(!this._hasPublishedAtValue())return{input:``,text:this.labels.publishDateSummaryNow}}if(this._getPublishedAtValidationMessage()!==null)return null;let e=H(this._publishedAtInput);return e===null?null:{input:this._publishedAtInput,text:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(new Date(e.year,e.monthIndex,e.day))}}_getPostPublishedAtSubmitValue(e,t){if(e===0)return this._getPublishedAtSubmitValue(t);if(t===`draft`)return;let n=this._threadItems[e],r=n?.publishedAtInput??``;if(!r.trim())return;let i=ft(r,n?.publishedAtTimeMinutes??U(this._getCurrentTimestamp()));if(i!==null)return Math.min(i,this._getCurrentTimestamp())}_getPublishedAtSubmitValue(e){if(e===`draft`)return;let t=ft(this._publishedAtInput,this._getPublishedAtTimeMinutes());if(t!==null)return this._originalPublishedAt!==null&&this._publishedAtInput===this._initialPublishedAtInput&&this._publishedAtTimeMinutes===this._initialPublishedAtTimeMinutes?Math.min(this._originalPublishedAt,this._getCurrentTimestamp()):Math.min(t,this._getCurrentTimestamp());if(!(this._publishedAtInput.trim().length>0)&&this._editPostId)return this._getCurrentTimestamp()}_openPublishPanelAndFocus(e,t=0){this._showCollection=!1,this._collectionSearch=``,this._showPublishPanel=!1,this._showLanguagePicker=!1,this._postMetaIndex=t,this._confirmPanelOpen=!1,this._scheduleSuggestedSlugRefresh(!0),this._placeAndFocusPostMetaPanel(e)}_revealSlugField(e=0){this._openPublishPanelAndFocus(`.compose-publish-slug-input`,e)}_revealPublishedAtField(e=0){this._openPublishPanelAndFocus(`.compose-publish-date-input`,e)}_canPublish(){if(this._loading)return!1;let e=this._rowIds;for(let t=0;t<e.length;t++)if(this._getPostPublishedAtValidationMessage(t)||this._getPostSlugValidationMessage(t))return!1;return e.every(e=>this._rowStatus.get(e)?.publishable===!0)}_focusPublishPanelInitialField(){let e=this._visibilityLocked?`.compose-publish-date-input`:`.compose-publish-option[role='radio']`;this.querySelector(e)?.focus()}_closePublishPanel(e=!1){this._showPublishPanel&&(this._showPublishPanel=!1,e&&this.updateComplete.then(()=>this._restorePageEditorFocus()))}_togglePublishPanel(){this._showCollection=!1,this._collectionSearch=``,this._showLanguagePicker=!1;let e=!this._showPublishPanel;this._showPublishPanel=e,e&&(this._scheduleSuggestedSlugRefresh(!0),this.updateComplete.then(()=>this._focusPublishPanelInitialField()))}_setVisibility(t){this._visibilityLocked||(this._visibility=t,this._showPublishPanel&&this._closePublishPanel(!0),!this._editPostId&&!this._draftSourceId&&!this._replyToId&&(e._lastNewPostVisibility=t,this._sourceCollectionId&&e._setCollectionVisibility(this._sourceCollectionId,t)))}_onSlugInput(e,t=0){let n=e.target.value;if(this._setPostSlug(t,n.toLowerCase()),this._setPostSlugTaken(t,!1),this._slugCheckLoading=!1,this._hasPostManualSlug(t)){this._scheduleSlugAvailabilityCheck(t);return}this._scheduleSuggestedSlugRefresh()}_resetPublishedAt(e=0){let t=this._getCurrentTimestamp();this._setPostPublishedAtInput(e,dt(t)),this._setPostPublishedAtTimeMinutes(e,U(t)),this.updateComplete.then(()=>{this.querySelector(`.compose-publish-date-input`)?.focus()})}_renderVisibilityIcon(e,t=`menu`){let n=w({"compose-publish-visibility-icon":!0,"compose-publish-visibility-icon-toggle":t===`toggle`,"compose-publish-visibility-icon-public":e===`public`,"compose-publish-visibility-icon-latest_hidden":e===`latest_hidden`,"compose-publish-visibility-icon-private":e===`private`});return st(rt[e],n)}_renderVisibilityRow(e,t,n){let r=this._visibility===e;return o`
623
+ <button
624
+ type="button"
625
+ class=${w({"compose-sheet-row":!0,"compose-sheet-row-selected":r})}
626
+ role="radio"
627
+ aria-checked=${r?`true`:`false`}
628
+ ?disabled=${this._visibilityLocked}
629
+ @click=${()=>this._setVisibility(e)}
630
+ >
631
+ ${this._renderVisibilityIcon(e)}
632
+ <span class="compose-sheet-main">
633
+ <span class="compose-sheet-title">${t}</span>
634
+ <span class="compose-sheet-sub">${n}</span>
635
+ </span>
636
+ ${r?o`<span class="compose-sheet-check" aria-hidden="true">
637
+ ${B(R.check,`compose-sheet-check-icon`)}
638
+ </span>`:c}
639
+ </button>
640
+ `}async _loadTranslationSource(e,n={}){try{let r=await fetch(t(`/api/posts/${e}`),{credentials:`same-origin`});if(!r.ok)return;let i=await r.json();this._translationOf={id:i.id,title:i.displayTitle||i.slug||``,href:i.slug?t(`/${i.slug}`):``,previewHtml:await this._fetchTranslationPreview(i.id)},n.seed&&await this._seedFromTranslationSource(i)}catch{}}async _fetchTranslationPreview(e){try{let n=await fetch(t(`/_/post-preview/${encodeURIComponent(e)}`),{headers:{Accept:`text/html`},credentials:`same-origin`});return n.ok?await n.text():``}catch{return``}}async _seedFromTranslationSource(e){if(this._hasContent()||this._editPostId||this._draftSourceId)return;let t=e.format;this._format=t,e.collectionIds?.length&&(this._collectionIds=[...e.collectionIds]),e.visibility&&(this._visibility=e.visibility),await this.updateComplete,this._editor?.populate({format:t,url:t===`quote`?e.sourceUrl??void 0:e.url??void 0,quoteAuthor:t===`quote`?e.sourceName??void 0:void 0,rating:e.rating??void 0}),await this.updateComplete,this._seededFromSource=!0,this._captureInitialSnapshot()}_composeTextForDetection(){let e=this._editor;if(!e)return``;let t=e.getData(),n=t.body?A(t.body)??``:``;return[t.title,t.quoteText,n].filter(Boolean).join(` `)}_contextLanguageTag(){let e=this.languages.map(e=>e.tag);return e.length===0?null:e.includes(this.contextLanguage)?this.contextLanguage:e[0]}_readLanguage(){return Te(this._composeTextForDetection(),{languages:this.languages.map(e=>e.tag)})}_effectiveLanguage(){return this._language??this._readLanguage()??this._contextLanguageTag()}_renderLanguageRow(e,t,n){let r=this._language===e;return o`
641
+ <button
642
+ type="button"
643
+ class=${w({"compose-sheet-row":!0,"compose-sheet-row-selected":r})}
644
+ role="radio"
645
+ aria-checked=${r?`true`:`false`}
646
+ lang=${he(e??void 0)}
647
+ data-compose-language-row
648
+ @click=${()=>{this._language=e,this._scheduleDraftSave(),this._closeLanguagePicker(!0)}}
649
+ >
650
+ <span class="compose-sheet-main">
651
+ <span class="compose-sheet-title">${t}</span>
652
+ ${n?o`<span class="compose-sheet-sub">${n}</span>`:c}
653
+ </span>
654
+ ${r?o`<span class="compose-sheet-check" aria-hidden="true">
655
+ ${B(R.check,`compose-sheet-check-icon`)}
656
+ </span>`:c}
657
+ </button>
658
+ `}_closeLanguagePicker(e=!1){this._showLanguagePicker&&(this._showLanguagePicker=!1,e&&this.updateComplete.then(()=>{this.querySelector(`[data-compose-language-trigger]`)?.focus()}))}_toggleLanguagePicker(){if(this._showLanguagePicker){this._closeLanguagePicker(!0);return}this._showCollection=!1,this._collectionSearch=``,this._showPublishPanel=!1,this._postMetaIndex=null,this._showLanguagePicker=!0,this.updateComplete.then(()=>{let e=this.querySelectorAll(`[data-compose-language-row]`);(Array.from(e).find(e=>e.getAttribute(`aria-checked`)===`true`)??e[0])?.focus()})}_renderLanguageControl(){if(this._replyToId||this.languages.length<2)return c;let e=this._effectiveLanguage(),t=this.languages.find(t=>t.tag===e)?.label??``,n=this._language!==null,r=n||e!==this._contextLanguageTag(),i=this._showLanguagePicker,a=this.labels.languageTriggerLabel.replace(`{language}`,t);return o`
659
+ <div
660
+ class=${w({"compose-language":!0,"compose-language-open":i})}
661
+ >
662
+ ${i?o`<div
663
+ class="compose-dropdown-backdrop"
664
+ @click=${()=>this._closeLanguagePicker(!0)}
665
+ ></div>`:c}
666
+ <button
667
+ type="button"
668
+ class=${w({"compose-language-trigger":!0,"compose-language-trigger-bare":!r})}
669
+ data-compose-language-trigger
670
+ data-open=${i?`true`:c}
671
+ data-chosen=${n?`true`:c}
672
+ ?disabled=${this._loading}
673
+ aria-haspopup="dialog"
674
+ aria-expanded=${i?`true`:`false`}
675
+ aria-label=${a}
676
+ title=${a}
677
+ @click=${()=>this._toggleLanguagePicker()}
678
+ >
679
+ <svg
680
+ class="compose-language-trigger-svg"
681
+ width="24"
682
+ height="24"
683
+ viewBox="0 0 24 24"
684
+ fill="none"
685
+ stroke="currentColor"
686
+ stroke-width="1.9"
687
+ stroke-linecap="round"
688
+ stroke-linejoin="round"
689
+ aria-hidden="true"
690
+ >
691
+ ${b(it)}
692
+ </svg>
693
+ ${r?o`<span
694
+ class="compose-language-label"
695
+ lang=${he(e??void 0)}
696
+ >${t}</span
697
+ >`:c}
698
+ </button>
699
+ ${i?this._renderLanguagePicker():c}
700
+ </div>
701
+ `}_renderLanguagePicker(){let e=e=>this.languages.find(t=>t.tag===e)?.label??``,t=this._readLanguage(),n=e(this._contextLanguageTag()),r=t?this.labels.languageAutoDetected.replace(`{language}`,e(t)):n?this.labels.languageAutoPending.replace(`{language}`,n):this.labels.languageAutoHint;return o`
702
+ <div
703
+ class="compose-language-popover"
704
+ role="dialog"
705
+ aria-label=${this.labels.languageLabel}
706
+ >
707
+ <p class="compose-sheet-label">${this.labels.languageLabel}</p>
708
+ ${this._translationOf?o`<p class="compose-sheet-note">
709
+ ${this.labels.translationOf.replace(`{title}`,this._translationOf.title)}
710
+ </p>`:c}
711
+ <div role="radiogroup" aria-label=${this.labels.languageLabel}>
712
+ ${this._renderLanguageRow(null,this.labels.languageAuto,r)}
713
+ ${this.languages.map(e=>this._renderLanguageRow(e.tag,e.label,``))}
714
+ </div>
715
+ </div>
716
+ `}_renderMetaFieldHead(e,t){return o`
717
+ <div class="compose-meta-field-head">
718
+ <span class="compose-meta-label">${e}</span>
719
+ ${t}
720
+ </div>
721
+ `}_openDatePicker(e){let t=this.querySelectorAll(`.compose-publish-date-input`),n=t[e]??t[0];if(n){n.focus();try{n.showPicker()}catch{}}}_renderPublishDateSection(e){let t=this._getPostPublishedAtValidationMessage(e),n=this._hasPostPublishedAtValue(e);return o`
722
+ <div class="compose-meta-field compose-publish-date-field">
723
+ ${this._renderMetaFieldHead(this.labels.publishDateLabel,n?o`<button
724
+ type="button"
725
+ class="compose-publish-section-action"
726
+ @click=${()=>this._resetPublishedAt(e)}
727
+ >
728
+ ${this.labels.publishDateReset}
729
+ </button>`:c)}
730
+ <div class="compose-publish-date-input-wrap">
731
+ <input
732
+ type="date"
733
+ class=${w({"compose-input":!0,"compose-publish-date-input":!0,"compose-publish-date-input-empty":!n})}
734
+ .value=${this._getPostPublishedAtInput(e)}
735
+ max=${this._getPublishedAtMaxInput()}
736
+ aria-label=${this.labels.publishDateLabel}
737
+ aria-invalid=${t?`true`:`false`}
738
+ @input=${t=>this._setPostPublishedAtInput(e,t.target.value)}
739
+ />
740
+ <button
741
+ type="button"
742
+ class="compose-publish-date-picker"
743
+ aria-label=${this.labels.publishDateSummaryAction}
744
+ data-compose-date-picker
745
+ @click=${()=>this._openDatePicker(e)}
746
+ >
747
+ ${B(R.calendar,`compose-publish-date-picker-icon`)}
748
+ </button>
749
+ </div>
750
+ ${t?o`<p
751
+ class="compose-publish-date-status compose-publish-date-status-error"
752
+ >
753
+ ${t}
754
+ </p>`:n?c:o`<p class="compose-sheet-hint">
755
+ ${this.labels.publishDateHint}
756
+ </p>`}
757
+ </div>
758
+ `}_renderPublishSlugSection(e){let t=e===0,n=this._getPostSlugValidationMessage(e),r=t?this._getSlugStatusMessage():n,i=t?this._getSlugPreviewParts():null,a=t&&!this._hasManualSlug()&&!this._suggestedSlugLoading&&!!this._suggestedSlug;return o`
759
+ <div class="compose-meta-field compose-publish-slug-field">
760
+ ${this._renderMetaFieldHead(this.labels.publishSlugLabel,this._hasManualSlug()?o`<button
761
+ type="button"
762
+ class="compose-publish-section-action"
763
+ @click=${()=>this._resetCustomSlug()}
764
+ >
765
+ ${this.labels.publishSlugReset}
766
+ </button>`:c)}
767
+ <div class="compose-publish-slug-input-wrap">
768
+ <span class="compose-publish-slug-prefix" aria-hidden="true">/</span>
769
+ <input
770
+ type="text"
771
+ class="compose-input compose-publish-slug-input"
772
+ .value=${this._getPostSlug(e)}
773
+ placeholder=${this.labels.publishSlugPlaceholder}
774
+ aria-label=${this.labels.publishSlugLabel}
775
+ aria-invalid=${n?`true`:`false`}
776
+ spellcheck="false"
777
+ autocapitalize="off"
778
+ autocomplete="off"
779
+ @input=${t=>this._onSlugInput(t,e)}
780
+ />
781
+ </div>
782
+ ${a?o`
783
+ <button
784
+ type="button"
785
+ class="compose-slug-suggestion"
786
+ @click=${()=>this._useSuggestedSlug()}
787
+ >
788
+ <span class="compose-slug-suggestion-label"
789
+ >${this.labels.publishSlugSuggested}</span
790
+ >
791
+ <span class="compose-slug-suggestion-value"
792
+ >/${this._suggestedSlug}</span
793
+ >
794
+ <span class="compose-slug-suggestion-icon" aria-hidden="true">
795
+ <svg
796
+ width="13"
797
+ height="13"
798
+ viewBox="0 0 14 14"
799
+ fill="none"
800
+ stroke="currentColor"
801
+ stroke-width="1.4"
802
+ stroke-linecap="round"
803
+ stroke-linejoin="round"
804
+ >
805
+ <path d="M3 7h8" />
806
+ <path d="m8 3 4 4-4 4" />
807
+ </svg>
808
+ </span>
809
+ </button>
810
+ `:c}
811
+ ${r?o`<p
812
+ class=${w({"compose-publish-slug-status":!0,"compose-publish-slug-status-error":!!n})}
813
+ data-compose-slug-error=${n?`true`:c}
814
+ >
815
+ ${r}
816
+ </p>`:i?o`<p
817
+ class="compose-publish-slug-preview"
818
+ data-compose-slug-preview
819
+ title=${i.full}
820
+ >
821
+ <span class="compose-publish-slug-preview-origin"
822
+ >${i.origin}</span
823
+ ><span class="compose-publish-slug-preview-path"
824
+ >${i.path}</span
825
+ >
826
+ </p>`:this._hasPostManualSlug(e)?c:o`<p class="compose-sheet-hint">
827
+ ${this.labels.publishSlugHint}
828
+ </p>`}
829
+ </div>
830
+ `}_canReplyQuietly(){return this._replyToId?!(this._editPostId||this._draftSourceId)||this._threadItems.length>=2:!1}_renderQuietReplySection(){return this._canReplyQuietly()?o`
831
+ <label class="compose-sheet-row compose-sheet-row-switch">
832
+ <span class="compose-sheet-main">
833
+ <span class="compose-sheet-title"
834
+ >${this.labels.quietReplyLabel}</span
835
+ >
836
+ <span class="compose-sheet-sub">${this.labels.quietReplyHint}</span>
837
+ </span>
838
+ <input
839
+ type="checkbox"
840
+ role="switch"
841
+ class="input"
842
+ .checked=${this._quietReply}
843
+ @change=${e=>{this._quietReply=e.target.checked}}
844
+ />
845
+ </label>
846
+ `:c}_getPublishedAtRowValue(){let e=H(this._publishedAtInput);return e===null?this.labels.publishDateSummaryNow:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(new Date(e.year,e.monthIndex,e.day))}_getPostSlugRowValue(e){let t=this._getPostSlug(e).trim();return t?`/${t}`:this.labels.publishSlugSummaryAuto}_getPostSlug(e){return e===0?this._slug:this._threadItems[e]?.slug??``}_setPostSlug(e,t){if(e===0){this._slug=t;return}this._threadItems=this._threadItems.map((n,r)=>r===e?{...n,slug:t}:n)}_setPostSlugTaken(e,t){if(e===0){this._slugTaken=t;return}this._threadItems=this._threadItems.map((n,r)=>r===e?{...n,slugTaken:t}:n)}_hasPostManualSlug(e){return this._getPostSlug(e).trim().length>0}_getPostSlugSyncValidationMessage(e){let t=ee(this._getPostSlug(e));return t===`invalid`?this.labels.publishSlugInvalid:t===`reserved`?this.labels.publishSlugReserved:null}_getPostSlugValidationMessage(e){let t=this._getPostSlugSyncValidationMessage(e);if(t)return t;let n=e===0?this._slugTaken:this._threadItems[e]?.slugTaken;return this._hasPostManualSlug(e)&&n?this.labels.publishSlugTaken:null}_getPostPublishedAtInput(e){return e===0?this._publishedAtInput:this._threadItems[e]?.publishedAtInput??``}_setPostPublishedAtInput(e,t){if(e===0){this._publishedAtInput=t;return}this._threadItems=this._threadItems.map((n,r)=>r===e?{...n,publishedAtInput:t}:n)}_setPostPublishedAtTimeMinutes(e,t){if(e===0){this._publishedAtTimeMinutes=t;return}this._threadItems=this._threadItems.map((n,r)=>r===e?{...n,publishedAtTimeMinutes:t}:n)}_hasPostPublishedAtValue(e){return this._getPostPublishedAtInput(e).trim().length>0}_getPostPublishedAtValidationMessage(e){let t=this._getPostPublishedAtInput(e);return t.trim()?H(t)===null?this.labels.publishDateInvalid:t>this._getPublishedAtMaxInput()?this.labels.publishDateFutureError:null:null}_getPostPublishedAtRowValue(e){let t=H(this._getPostPublishedAtInput(e));return t===null?e>0&&this._hasPublishedAtValue()?this._getPublishedAtRowValue():this.labels.publishDateSummaryNow:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(new Date(t.year,t.monthIndex,t.day))}_renderPostMetaControl(e){if(this._openingEdit)return c;let t=e===0,n=this._postMetaIndex===e,r=this._hasPostPublishedAtValue(e)||this._hasPostManualSlug(e);return o`
847
+ <div
848
+ class=${w({"compose-post-meta":!0,"compose-post-meta-set":r,"compose-post-meta-open":n})}
849
+ >
850
+ ${n?o`<div
851
+ class="compose-dropdown-backdrop"
852
+ @click=${()=>this._closePostMeta()}
853
+ ></div>`:c}
854
+ <button
855
+ type="button"
856
+ class="compose-post-meta-pill"
857
+ aria-haspopup="dialog"
858
+ aria-expanded=${n?`true`:`false`}
859
+ data-compose-post-meta-pill
860
+ data-post-index=${e}
861
+ @click=${()=>{if(n)return this._closePostMeta();this._showPublishPanel=!1,this._showCollection=!1,this._showLanguagePicker=!1,this._postMetaIndex=e,t&&this._scheduleSuggestedSlugRefresh(!0),this._placeAndFocusPostMetaPanel()}}
862
+ >
863
+ ${B(R.calendar,`compose-post-meta-icon`)}
864
+ <span class="compose-post-meta-value"
865
+ >${this._getPostPublishedAtRowValue(e)}</span
866
+ >
867
+ <span class="compose-post-meta-sep" aria-hidden="true">·</span>
868
+ <!-- No link icon: the permalink already renders with its leading
869
+ slash, and two icons in a control this quiet read as clutter. -->
870
+ <span class="compose-post-meta-value compose-post-meta-value-slug"
871
+ >${this._getPostSlugRowValue(e)}</span
872
+ >
873
+ </button>
874
+ ${n?o`<div
875
+ class="compose-post-meta-panel"
876
+ role="dialog"
877
+ aria-label=${this.labels.publishSettings}
878
+ tabindex="-1"
879
+ data-compose-post-meta-panel
880
+ >
881
+ ${this._renderPublishDateSection(e)}
882
+ ${this._renderPublishSlugSection(e)}
883
+ <div class="compose-post-meta-footer">
884
+ <button
885
+ type="button"
886
+ class="compose-publish-done"
887
+ data-compose-post-meta-done
888
+ @click=${()=>this._closePostMeta()}
889
+ >
890
+ ${this.labels.done}
891
+ </button>
892
+ </div>
893
+ </div>`:c}
894
+ </div>
895
+ `}_placeAndFocusPostMetaPanel(e){this.updateComplete.then(()=>{this._updatePostMetaPanelLayout(),this.querySelector(e??`[data-compose-post-meta-panel]`)?.focus({preventScroll:!0})})}_updatePostMetaPanelLayout(){let e=this._postMetaIndex;if(e===null)return;let t=this.querySelector(`[data-compose-post-meta-panel]`),n=this.querySelector(`[data-compose-post-meta-pill][data-post-index="${e}"]`);if(!t||!n)return;let r=globalThis.visualViewport,i=r?.offsetTop??0,a=r?.offsetLeft??0,o=i+(r?.height??globalThis.innerHeight),s=a+(r?.width??globalThis.innerWidth),c=n.getBoundingClientRect(),l=Math.max(0,c.top-(i+12)-6),u=Math.max(0,o-12-c.bottom-6),d=u>=l?`down`:`up`,f=Math.max(1,Math.floor(d===`up`?l:u));t.style.top=`0px`,t.style.left=`0px`;let p=t.getBoundingClientRect(),m=p.width/(t.offsetWidth||p.width||1)||1;t.style.setProperty(`--compose-post-meta-panel-max-height`,`${f/m}px`);let h=t.offsetHeight*m,g=d===`down`?c.bottom+6:c.top-6-h,_=Math.min(Math.max(c.right-p.width,a+12),Math.max(s-12-p.width,a));t.style.top=`${(g-p.top)/m}px`,t.style.left=`${(_-p.left)/m}px`}_closePostMeta(){let e=this._postMetaIndex;if(e===null)return;let t=this.querySelector(`[data-compose-post-meta-panel]`)?.contains(document.activeElement)??!1;this._postMetaIndex=null,t&&this.updateComplete.then(()=>{let t=this.querySelectorAll(`jant-compose-editor`);(t[e]??t[0])?.focusInput()})}_hasPublishPanelContent(){return!this._visibilityLocked||this._replyToId&&this._renderQuietReplySection()!==c?!0:this._renderSaveDraftRow()!==c||this._renderDraftsRow()!==c}_renderPublishPanelSections(){let e=o`<div
896
+ class="compose-sheet-divider"
897
+ aria-hidden="true"
898
+ ></div>`,t=this._renderSaveDraftRow(),n=this._renderDraftsRow(),r=t!==c||n!==c;return o`
899
+ <div class="compose-sheet">
900
+ ${this._visibilityLocked?c:o`
901
+ <p class="compose-sheet-label">
902
+ ${this.labels.publishVisibilityLabel}
903
+ </p>
904
+ <div
905
+ role="radiogroup"
906
+ aria-label=${this.labels.publishVisibilityLabel}
907
+ >
908
+ ${this._renderVisibilityRow(`public`,this.labels.publishVisibilityPublic,this.labels.publishVisibilityPublicHint)}
909
+ ${this._renderVisibilityRow(`latest_hidden`,this.labels.publishVisibilityHiddenFromLatest,this.labels.publishVisibilityHiddenFromLatestHint)}
910
+ ${this._renderVisibilityRow(`private`,this.labels.publishVisibilityPrivate,this.labels.publishVisibilityPrivateHint)}
911
+ </div>
912
+ `}
913
+ ${this._replyToId?o`${this._visibilityLocked?c:e}
914
+ ${this._renderQuietReplySection()}`:c}
915
+ ${r?o`${e} ${t} ${n}`:c}
916
+ </div>
917
+ `}_renderSaveDraftRow(){return this._editPostId||!this._hasWorkToLose()?c:o`
918
+ <button
919
+ type="button"
920
+ class="compose-sheet-row"
921
+ ?disabled=${this._loading}
922
+ @click=${()=>{this._closePublishPanel(!1),this._submit(`draft`)}}
923
+ >
924
+ ${ot(nt.saveDraft)}
925
+ <span class="compose-sheet-main">
926
+ <span class="compose-sheet-title">${this.labels.saveAsDraft}</span>
927
+ </span>
928
+ </button>
929
+ `}_renderDraftsRow(){return this._editPostId?c:o`
930
+ <button
931
+ type="button"
932
+ class="compose-sheet-row"
933
+ ?disabled=${this._loading}
934
+ @click=${()=>{this._closePublishPanel(!1),this._handleDraftButtonClick()}}
935
+ >
936
+ ${ot(nt.drafts)}
937
+ <span class="compose-sheet-main">
938
+ <span class="compose-sheet-title">${this.labels.drafts}</span>
939
+ </span>
940
+ ${B(R.caretRight,`compose-sheet-caret`)}
941
+ </button>
942
+ `}_renderCloseComposeQuickAction(){return this.pageMode||this._threadItems.length===0?c:o`
943
+ <button
944
+ type="button"
945
+ class="compose-quick-actions-close"
946
+ ?disabled=${this._loading}
947
+ @click=${()=>this.requestClose()}
948
+ >
949
+ ${this.labels.close}
950
+ </button>
951
+ `}_renderDesktopPublishPanel(){return!this._showPublishPanel||this._publishPanelFullscreen?c:o`
952
+ <div
953
+ class="compose-publish-panel compose-publish-panel-desktop"
954
+ role="dialog"
955
+ aria-label=${this.labels.publishSettings}
956
+ data-position="up"
957
+ data-compose-publish-panel
958
+ data-compose-publish-panel-desktop
959
+ >
960
+ ${this._renderPublishPanelSections()}
961
+ </div>
962
+ `}_renderMobilePublishPanel(){return!this._showPublishPanel||!this._publishPanelFullscreen?c:o`
963
+ <div
964
+ class="compose-publish-panel compose-publish-panel-mobile"
965
+ role="dialog"
966
+ aria-label=${this.labels.publishSettings}
967
+ aria-modal="true"
968
+ data-compose-publish-panel
969
+ data-compose-publish-panel-mobile
970
+ >
971
+ <div class="compose-alt-header compose-publish-mobile-header">
972
+ <button
973
+ type="button"
974
+ class="compose-attached-panel-back"
975
+ @click=${()=>this._closePublishPanel(!0)}
976
+ >
977
+ <svg
978
+ class="icon-fine"
979
+ width="16"
980
+ height="16"
981
+ viewBox="0 0 16 16"
982
+ fill="none"
983
+ stroke="currentColor"
984
+ stroke-width="1.5"
985
+ stroke-linecap="round"
986
+ stroke-linejoin="round"
987
+ >
988
+ <path d="M11 3L6 8l5 5" />
989
+ </svg>
990
+ </button>
991
+ <span class="compose-alt-title">${this.labels.publishSettings}</span>
992
+ <button
993
+ type="button"
994
+ class="compose-attached-cancel compose-publish-mobile-done"
995
+ @click=${()=>this._closePublishPanel(!0)}
996
+ >
997
+ ${this.labels.done}
998
+ </button>
999
+ </div>
1000
+ <div class="compose-publish-mobile-body">
1001
+ ${this._renderPublishPanelSections()}
1002
+ </div>
1003
+ </div>
1004
+ `}_updatePublishPanelLayout(){if(this._publishPanelFullscreen)return;let e=this.querySelector(`.compose-publish-group`),t=this.querySelector(`[data-compose-publish-panel-desktop]`);if(!e||!t)return;let n=globalThis.visualViewport,r=n?.offsetTop??0,i=r+(n?.height??globalThis.innerHeight),a=e.getBoundingClientRect(),o=r+12,s=i-12,c=Math.max(0,a.top-o-10),l=Math.max(0,s-a.bottom-10),u=l>=c?`down`:`up`,d=Math.max(1,Math.floor(u===`up`?c:l));t.dataset.position=u,t.style.setProperty(`--compose-publish-panel-max-height`,`${d}px`)}_renderPublishButton(){let e=o`<svg
1005
+ class="animate-spin size-4"
1006
+ xmlns="http://www.w3.org/2000/svg"
1007
+ viewBox="0 0 24 24"
1008
+ fill="none"
1009
+ stroke="currentColor"
1010
+ stroke-width="2"
1011
+ stroke-linecap="round"
1012
+ stroke-linejoin="round"
1013
+ role="status"
1014
+ >
1015
+ <path d="M21 12a9 9 0 1 1-6.219-8.56" />
1016
+ </svg>`,t=this._canPublish();return o`
1017
+ <div class="compose-publish-shell">
1018
+ <div
1019
+ class=${w({"compose-publish-group":!0,"compose-publish-group-open":this._showPublishPanel})}
1020
+ >
1021
+ ${this._showPublishPanel&&!this._publishPanelFullscreen?o`<div
1022
+ class="compose-dropdown-backdrop"
1023
+ @click=${()=>this._closePublishPanel(!0)}
1024
+ ></div>`:c}
1025
+ <div
1026
+ role="group"
1027
+ class=${w({"compose-publish-buttons":!0,"compose-publish-buttons-inactive":!t&&!this._loading})}
1028
+ >
1029
+ <button
1030
+ type="button"
1031
+ class=${w({"compose-publish-main":!0,"compose-publish-main-loading":this._loading})}
1032
+ ?disabled=${!t}
1033
+ @click=${()=>void this._submit(`published`)}
1034
+ >
1035
+ ${this._loading?e:c} ${this._getSubmitLabel()}
1036
+ </button>
1037
+ </div>
1038
+ <!-- Options sits past Publish as its own control rather than a
1039
+ chevron welded to it: a split button reads as one button, which
1040
+ is why nobody found the settings. -->
1041
+ ${this._hasPublishPanelContent()?o`<button
1042
+ type="button"
1043
+ class=${w({"compose-options-trigger":!0,"compose-options-trigger-open":this._showPublishPanel})}
1044
+ ?disabled=${this._loading}
1045
+ aria-haspopup="dialog"
1046
+ aria-expanded=${this._showPublishPanel?`true`:`false`}
1047
+ aria-label=${this.labels.publishSettings}
1048
+ title=${this.labels.publishSettings}
1049
+ @click=${()=>this._togglePublishPanel()}
1050
+ >
1051
+ <svg
1052
+ class="compose-options-trigger-icon"
1053
+ width="22"
1054
+ height="22"
1055
+ viewBox="0 0 24 24"
1056
+ fill="none"
1057
+ stroke="currentColor"
1058
+ stroke-linecap="round"
1059
+ stroke-linejoin="round"
1060
+ aria-hidden="true"
1061
+ >
1062
+ ${b(R.options)}
1063
+ </svg>
1064
+ </button>`:c}
1065
+ ${this._renderDesktopPublishPanel()}
1066
+ </div>
1067
+ </div>
1068
+ `}_renderQuickActionsRow(){let e=this._renderCloseComposeQuickAction(),t=this._renderHideFromLatestQuickToggle(),n=this._renderQuietReplyQuickToggle();return e===c&&t===c&&n===c?c:o`
1069
+ <div class="compose-quick-actions-row">
1070
+ ${e} ${t} ${n}
1071
+ </div>
1072
+ `}_renderQuietReplyQuickToggle(){return this._canReplyQuietly()?o`
1073
+ <label class="compose-publish-quick-toggle">
1074
+ <input
1075
+ type="checkbox"
1076
+ class="input compose-publish-quick-toggle-input"
1077
+ .checked=${this._quietReply}
1078
+ ?disabled=${this._loading}
1079
+ @change=${e=>{this._quietReply=e.target.checked}}
1080
+ />
1081
+ <span>${this.labels.quietReplyLabel}</span>
1082
+ </label>
1083
+ `:c}_renderHideFromLatestQuickToggle(){if(this._visibilityLocked||this._visibility===`private`)return c;let e=this._visibility===`latest_hidden`;return o`
1084
+ <label class="compose-publish-quick-toggle">
1085
+ <input
1086
+ type="checkbox"
1087
+ class="input compose-publish-quick-toggle-input"
1088
+ .checked=${e}
1089
+ ?disabled=${this._loading}
1090
+ @change=${e=>{let t=e.target;this._setVisibility(t.checked?`latest_hidden`:`public`)}}
1091
+ />
1092
+ <span>${this.labels.publishHideFromLatest}</span>
1093
+ </label>
1094
+ `}_renderEditLoadingState(){return o`
1095
+ <div
1096
+ class="compose-edit-loading"
1097
+ role="status"
1098
+ aria-live="polite"
1099
+ aria-busy="true"
1100
+ >
1101
+ <!-- The post header this normally rides on has not rendered yet, so the
1102
+ close control gets its own row rather than leaving a fetch with no
1103
+ way out on a phone, where there is no Escape key. -->
1104
+ <div class="compose-edit-loading-close">
1105
+ ${this._renderCloseComposeControl()}
1106
+ </div>
1107
+ <div class="compose-edit-loading-status">
1108
+ <svg
1109
+ class="animate-spin size-5"
1110
+ xmlns="http://www.w3.org/2000/svg"
1111
+ viewBox="0 0 24 24"
1112
+ fill="none"
1113
+ stroke="currentColor"
1114
+ stroke-width="2"
1115
+ stroke-linecap="round"
1116
+ stroke-linejoin="round"
1117
+ aria-hidden="true"
1118
+ >
1119
+ <path d="M21 12a9 9 0 1 1-6.219-8.56" />
1120
+ </svg>
1121
+ <span>${this.labels.loadingPost}</span>
1122
+ </div>
1123
+ <div class="compose-edit-loading-skeleton">
1124
+ <div class="skel-input compose-edit-loading-title"></div>
1125
+ <div class="skel-section-lg compose-edit-loading-body"></div>
1126
+ <div class="compose-edit-loading-footer">
1127
+ <div class="skel-input compose-edit-loading-chip"></div>
1128
+ <div class="skel-input compose-edit-loading-submit"></div>
1129
+ </div>
1130
+ </div>
1131
+ </div>
1132
+ `}_addThreadItem(){if((this._threadItems.length===0?2:this._threadItems.length+1)>20){d(this._getThreadLimitMessage(),`error`);return}let e=this._threadItems.length>0?this._threadItems[this._threadItems.length-1].format:this._format;if(this._threadItems.length===0){let t=this._editor;this._threadItems=[{id:L(),format:this._format},{id:L(),format:e}],this.updateComplete.then(()=>{let e=this.querySelector(`jant-compose-editor`);t&&e&&e.takeOver(t)})}else this._threadItems=[...this._threadItems,{id:L(),format:e}];this._focusedThreadIndex=this._threadItems.length-1,this.updateComplete.then(()=>{this.querySelectorAll(`jant-compose-editor`)[this._focusedThreadIndex]?.focusInput();let e=this.querySelector(`.compose-scroll`);e&&(e.scrollTop=e.scrollHeight)})}_removeThreadItem(e){if(this._threadItems.length<=1)return;let t=this._threadItems.filter((t,n)=>n!==e);if(e===0){let e=t[0];this._slug=e.slug??``,this._slugTaken=e.slugTaken??!1,this._publishedAtInput=e.publishedAtInput??``,this._publishedAtTimeMinutes=e.publishedAtTimeMinutes??null}if(t.length===1){let e=this.querySelector(`jant-compose-editor[data-thread-id="${t[0].id}"]`);this._threadItems=[],this._focusedThreadIndex=0,this._format=t[0].format,this.updateComplete.then(()=>{let t=this._editor;t&&(e&&t.takeOver(e),t.focusInput())})}else this._threadItems=t,this._focusedThreadIndex=Math.min(this._focusedThreadIndex,t.length-1)}_positionLabel(e){if(this._editPostId)return``;let t=!!(this._replyToId&&this._replyToData);if(t&&this._replyParentPosition===null)return``;let n=t?this._replyParentPosition??0:0,r=n+(this._threadItems.length||1);return r<2?``:`${n+e+1}/${r}`}_renderThreadPost(e,t,n,r){return o`
1133
+ <div
1134
+ class=${w({"compose-editor-row":!0,"compose-thread-post":!0,"is-current":t===this._focusedThreadIndex})}
1135
+ data-thread-index=${t}
1136
+ @focusin=${()=>{this._focusedThreadIndex=t}}
1137
+ @jant:format-change=${n=>{n.stopPropagation(),this._convertForFormatSwitch(n.target,e.format,n.detail.format),this._threadItems=this._threadItems.map((e,r)=>r===t?{...e,format:n.detail.format}:e),this._format=n.detail.format,this._shouldAutofocusFormatInput()&&this.updateComplete.then(()=>{let e=this.querySelectorAll(`jant-compose-editor`)[t];e?.updateComplete.then(()=>e.focusInput())})}}
1138
+ @jant:thread-remove=${e=>{e.stopPropagation(),this._removeThreadItem(t)}}
1139
+ @jant:compose-status=${t=>{t.stopPropagation(),this._handleRowStatus(e.id,t.detail)}}
1140
+ >
1141
+ <div class="compose-thread-dot"></div>
1142
+ <jant-compose-editor
1143
+ .format=${e.format}
1144
+ .labels=${this.labels}
1145
+ .uploadMaxFileSize=${this.uploadMaxFileSize}
1146
+ .threadItem=${!0}
1147
+ .removable=${n}
1148
+ .titleByDefault=${r}
1149
+ .positionLabel=${this._positionLabel(t)}
1150
+ .headerExtra=${this._renderPostMetaControl(t)}
1151
+ .slashCommandDiscovered=${this.slashCommandDiscovered}
1152
+ data-thread-id=${e.id}
1153
+ ></jant-compose-editor>
1154
+ </div>
1155
+ `}_renderAddToThreadRow(){let e=this._rowIds,t=e[e.length-1],n=!this._rowStatus.get(t)?.hasContent,r=this._threadItems.length>=20;return o`
1156
+ <div class="compose-thread-add-row">
1157
+ <div class="compose-thread-add-dot"></div>
1158
+ <button
1159
+ type="button"
1160
+ class="compose-thread-add-btn"
1161
+ ?disabled=${n||r}
1162
+ @click=${()=>this._addThreadItem()}
1163
+ >
1164
+ Add to thread
1165
+ </button>
1166
+ </div>
1167
+ `}_renderThreadComposeLayout(){let e=!!(this._replyToId&&this._replyToData),t=this._threadItems,n=t.length>1;return o`
1168
+ <div
1169
+ class=${w({"compose-thread-layout":!0,"compose-thread-compose-layout":!0,"compose-reply-compose-layout":e})}
1170
+ @jant:compose-content-changed=${()=>this._scheduleDraftSave()}
1171
+ >
1172
+ ${e?this._renderReplyContext():this._renderTranslationContext()}
1173
+ <!-- Keyed by row id, not by position: an editor holds its own content,
1174
+ so an unkeyed list would reuse elements by position and drop the
1175
+ last one when a middle post is removed — taking that post's text
1176
+ with it, and pairing the survivors with the wrong dates and
1177
+ permalinks. -->
1178
+ ${T(t,e=>e.id,(t,r)=>this._renderThreadPost(t,r,n,r===0&&!e))}
1179
+ ${this._renderAddToThreadRow()}
1180
+ </div>
1181
+ `}_renderAddThreadTrigger(e){let t=!this._hasWorkToLose(),n=o`
1182
+ <button
1183
+ type="button"
1184
+ class="compose-thread-add-btn"
1185
+ ?disabled=${t}
1186
+ @click=${()=>this._addThreadItem()}
1187
+ >
1188
+ Add to thread
1189
+ </button>
1190
+ `;return e?o`
1191
+ <div class="compose-thread-add-row">
1192
+ <div class="compose-thread-add-dot"></div>
1193
+ ${n}
1194
+ </div>
1195
+ `:o`<div class="compose-add-thread-trigger">${n}</div>`}render(){let t=!!(this._replyToId&&this._replyToData),n=this._threadItems.length>0,r=this._openingEdit,i=o`<jant-compose-editor
1196
+ .format=${this._format}
1197
+ .labels=${this.labels}
1198
+ .uploadMaxFileSize=${this.uploadMaxFileSize}
1199
+ .inlineFormat=${t}
1200
+ .titleByDefault=${!t&&e._getNoteTitleDefault()}
1201
+ .positionLabel=${this._positionLabel(0)}
1202
+ .badgeLabel=${this._editPostId?this.labels.editing:``}
1203
+ .headerExtra=${o`${this._renderPostMetaControl(0)}
1204
+ ${this._renderCloseComposeControl()}`}
1205
+ .slashCommandDiscovered=${this.slashCommandDiscovered}
1206
+ @jant:format-change=${e=>{e.stopPropagation(),this._switchFormat(e.detail.format)}}
1207
+ @jant:compose-status=${e=>{e.stopPropagation(),this._handleRowStatus(et,e.detail)}}
1208
+ ></jant-compose-editor>`,a=r||n||this._editPostId?c:this._renderAddThreadTrigger(t);return o`
1209
+ <div
1210
+ class=${w({"compose-dialog-inner":!0,"compose-dialog-inner-page":this.pageMode,"compose-dialog-inner-suspended":this._addCollectionPanelOpen})}
1211
+ tabindex="-1"
1212
+ aria-hidden=${this._addCollectionPanelOpen?`true`:`false`}
1213
+ ?inert=${this._addCollectionPanelOpen}
1214
+ >
1215
+ <div class="compose-scroll">
1216
+ ${r?this._renderEditLoadingState():n?this._renderThreadComposeLayout():t?o`
1217
+ <div
1218
+ class="compose-thread-layout compose-reply-compose-layout"
1219
+ >
1220
+ ${this._renderReplyContext()}
1221
+ <div class="compose-editor-row is-current">
1222
+ <div class="compose-thread-dot"></div>
1223
+ ${i}
1224
+ </div>
1225
+ ${a}
1226
+ </div>
1227
+ `:o`${this._renderTranslationContext()}${i}${a}`}
1228
+ </div>
1229
+ ${r?c:o`<div
1230
+ class=${w({"compose-action-row":!0,"compose-action-row-without-collection":!!this._replyToId,"compose-action-row-overlay-open":this._showPublishPanel||this._showCollection||this._showLanguagePicker})}
1231
+ >
1232
+ ${this._replyToId?c:this._renderCollectionSelector()}
1233
+ ${this._renderLanguageControl()}
1234
+ ${this._renderPublishButton()}
1235
+ </div>
1236
+ ${this._renderQuickActionsRow()}`}
1237
+ ${this._renderMobilePublishPanel()} ${this._renderAttachedPanel()}
1238
+ ${this._renderAltPanel()} ${this._renderDraftsPanel()}
1239
+ ${this._renderConfirmPanel()}
1240
+ </div>
1241
+ ${this._renderAddCollectionPanel()}
1242
+ `}};customElements.define(`jant-compose-dialog`,mt);function ht(e){return typeof e.text==`string`?e.text:e.content?e.content.map(ht).join(``):e.type===`hardBreak`?` `:``}function gt(e){return!e.content||e.content.length===0||e.content.every(e=>e.type===`text`?!e.text?.trim():e.type===`hardBreak`)}function _t(e){return(e.type===`paragraph`||e.type===`heading`)&&gt(e)}function vt(e){return e.replace(/\s+/g,` `).trim()}function yt(e){let t=e?.content;if(!e||!t?.length)return null;let n=t.findIndex(e=>!_t(e));if(n<0)return null;let r=t[n];if(r?.type!==`heading`||r.attrs?.level!==1)return null;let i=vt(ht(r));if(!i)return null;let a=t.slice(n+1);return a.length===0?{title:i,bodyJson:null,headingIndex:n}:{title:i,bodyJson:{...e,content:a},headingIndex:n}}var bt=`0 0 96 96`,xt=[`M24.4 10.5C16.9 17.7 11.5 26.8 8.2 37.7C4.9 48.7 4.8 58.9 7.8 68.2C10.3 75.7 15.4 79.5 22.9 79.5C28 79.5 32.2 77.8 35.4 74.2C38.6 70.7 40.2 66.5 40.2 61.4C40.2 56.5 38.8 52.6 36 49.6C33.3 46.6 29.7 45.1 25.2 45.1C23.4 45.1 21.8 45.3 20.2 45.8C22.2 37.3 26.7 29.2 33.6 21.4L24.4 10.5Z`,`M60.8 10.5C53.3 17.7 47.9 26.8 44.6 37.7C41.3 48.7 41.2 58.9 44.2 68.2C46.7 75.7 51.8 79.5 59.3 79.5C64.4 79.5 68.6 77.8 71.8 74.2C75 70.7 76.6 66.5 76.6 61.4C76.6 56.5 75.2 52.6 72.4 49.6C69.7 46.6 66.1 45.1 61.6 45.1C59.8 45.1 58.2 45.3 56.6 45.8C58.6 37.3 63.1 29.2 70 21.4L60.8 10.5Z`].map(e=>`<path fill="currentColor" d="${e}" />`).join(``),St=`jant.slashCommandDiscovery`,Ct=`/api/settings/discovery/slash-command`,wt=600,Tt=3,W=`compose-slash-discovery-visible`,Et=!1,Dt=null,G=null;function Ot(){try{return globalThis.localStorage!==void 0}catch{return!1}}function kt(){if(!Ot())return{shownCount:0,completed:!1};let e=globalThis.localStorage.getItem(St);if(!e)return{shownCount:0,completed:!1};try{let t=JSON.parse(e);return{shownCount:typeof t.shownCount==`number`&&t.shownCount>=0?t.shownCount:0,completed:t.completed===!0}}catch{return globalThis.localStorage.removeItem(St),{shownCount:0,completed:!1}}}function At(e){if(Ot())try{globalThis.localStorage.setItem(St,JSON.stringify(e))}catch{}}function jt(){Dt!==null&&(clearTimeout(Dt),Dt=null)}function Mt(){return typeof globalThis.matchMedia==`function`&&globalThis.matchMedia(`(min-width: 700px)`).matches}function Nt(e){return kt().completed?!0:e.dataset.slashCommandDiscovered===`true`}function Pt(){document.querySelectorAll(`jant-compose-editor`).forEach(e=>{e.dataset.slashCommandDiscovered=`true`,e.classList.remove(W)})}function Ft(){let e=kt();e.completed||Et||e.shownCount>=Tt||(Et=!0,At({...e,shownCount:e.shownCount+1}))}function It(e){return!Mt()||Nt(e)?!1:kt().shownCount<Tt||Et}function Lt(e){jt(),e?e.classList.remove(W):G&&G.classList.remove(W),(!e||e===G)&&(G=null)}function Rt(e){It(e)&&(Lt(G),G=e,e.classList.add(W),Ft())}function zt(e){It(e)&&(e.classList.contains(W)||(jt(),Dt=setTimeout(()=>{Rt(e)},wt)))}function Bt(){let e=kt();e.completed||At({shownCount:Math.max(e.shownCount,Tt),completed:!0}),Pt(),Lt(G),typeof globalThis.fetch==`function`&&globalThis.fetch(Ct,{method:`POST`,headers:{Accept:`application/json`},credentials:`same-origin`}).catch(()=>{})}function Vt(e){let t={};return e.brokenImageUnavailable&&(t.unavailable=e.brokenImageUnavailable),e.brokenImageDelete&&(t.delete=e.brokenImageDelete),e.brokenImageReplace&&(t.replace=e.brokenImageReplace),e.brokenImageOpen&&(t.open=e.brokenImageOpen),t}var K={media:`
1243
+ <rect x="2.75" y="3" width="12.5" height="11.25" rx="3" />
1244
+ <circle cx="6.15" cy="6.85" r="0.85" fill="currentColor" stroke="none" />
1245
+ <path d="M3.6 11.95 6.75 8.8c.42-.42 1.11-.42 1.53 0l1.4 1.4" />
1246
+ <path d="m8.95 10.2 1.38-1.38c.46-.46 1.21-.46 1.67 0l2.4 2.4" />
1247
+ `,attachedText:`
1248
+ <rect x="3" y="2.75" width="12" height="12.5" rx="3.1" />
1249
+ <path d="M5.85 6.35h6.3" />
1250
+ <path d="M5.85 9h6.3" />
1251
+ <path d="M5.85 11.65h4.35" />
1252
+ `,emoji:`
1253
+ <circle cx="9" cy="9" r="6.8" />
1254
+ <path d="M6.2 10.55c.52 1.08 1.46 1.8 2.8 1.8s2.28-.72 2.8-1.8" />
1255
+ <circle cx="6.5" cy="7.15" r="0.7" fill="currentColor" stroke="none" />
1256
+ <circle cx="11.5" cy="7.15" r="0.7" fill="currentColor" stroke="none" />
1257
+ `,rate:`
1258
+ <path
1259
+ d="m9 1.95 2.08 4.21 4.65.67-3.36 3.29.8 4.63L9 12.55l-4.17 2.2.8-4.63-3.36-3.29 4.65-.67z"
1260
+ fill="currentColor"
1261
+ fill-opacity="0.12"
1262
+ stroke="none"
1263
+ />
1264
+ <path
1265
+ d="m9 1.95 2.08 4.21 4.65.67-3.36 3.29.8 4.63L9 12.55l-4.17 2.2.8-4.63-3.36-3.29 4.65-.67z"
1266
+ />
1267
+ `,title:`
1268
+ <rect
1269
+ x="3.35"
1270
+ y="3.37"
1271
+ width="11.3"
1272
+ height="1.72"
1273
+ rx="0.6"
1274
+ fill="currentColor"
1275
+ stroke="none"
1276
+ />
1277
+ <rect
1278
+ x="7.99"
1279
+ y="4.6"
1280
+ width="2.02"
1281
+ height="9.45"
1282
+ rx="0.68"
1283
+ fill="currentColor"
1284
+ stroke="none"
1285
+ />
1286
+ <rect
1287
+ x="6.75"
1288
+ y="13.32"
1289
+ width="4.5"
1290
+ height="0.95"
1291
+ rx="0.48"
1292
+ fill="currentColor"
1293
+ stroke="none"
1294
+ />
1295
+ `,fullscreen:`
1296
+ <path d="M5.85 3H3v2.85" />
1297
+ <path d="M12.15 3H15v2.85" />
1298
+ <path d="M3 12.15V15h2.85" />
1299
+ <path d="M15 12.15V15h-2.85" />
1300
+ `};function q(e){return o`<svg
1301
+ class="compose-tool-icon"
1302
+ width="18"
1303
+ height="18"
1304
+ viewBox="0 0 18 18"
1305
+ fill="none"
1306
+ stroke="currentColor"
1307
+ stroke-linecap="round"
1308
+ stroke-linejoin="round"
1309
+ aria-hidden="true"
1310
+ >
1311
+ ${b(e)}
1312
+ </svg>`}function Ht(e){return o`<span
1313
+ class=${`decorative-quote-mark ${e}`}
1314
+ aria-hidden="true"
1315
+ >
1316
+ <svg
1317
+ viewBox=${bt}
1318
+ role="presentation"
1319
+ focusable="false"
1320
+ >
1321
+ ${b(xt)}
1322
+ </svg>
1323
+ </span>`}function Ut(e,t){let n=e.state.doc.content.size,r=Math.max(1,Math.min(t.from,n));return{from:r,to:Math.max(r,Math.min(t.to,n))}}var Wt=class t extends u{static properties={format:{type:String},labels:{type:Object},uploadMaxFileSize:{type:Number},threadItem:{type:Boolean,attribute:`thread-item`},removable:{type:Boolean},inlineFormat:{type:Boolean,attribute:`inline-format`},titleByDefault:{type:Boolean,attribute:`title-by-default`},positionLabel:{type:String,attribute:`position-label`},badgeLabel:{type:String,attribute:`badge-label`},headerExtra:{attribute:!1},slashCommandDiscovered:{type:Boolean},_title:{state:!0},_bodyJson:{state:!0},_url:{state:!0},_quoteText:{state:!0},_quoteAuthor:{state:!0},_rating:{state:!0},_showTitle:{state:!0},_showRating:{state:!0},_attachedTexts:{state:!0},_attachments:{state:!0},_attachmentOrder:{state:!0},_failedAttachmentPreviews:{state:!0},_showAltPanel:{state:!0},_altPanelIndex:{state:!0},_showEmojiPicker:{state:!0},_showUrlValidation:{state:!0},_showLinkTitleValidation:{state:!0}};_editor=null;_fileInput=null;_lastFocusedField=null;_lastEditorSelection=null;_emojiPickerEl=null;_emojiContainer=null;_urlStatusId=`compose-url-status-${L()}`;_onDocClickBound=this._onDocumentClick.bind(this);_filePickerCleanup=null;_suppressAttachedTextOpenUntil=0;_suppressContentChangedOnce=!1;#e=!1;#t=0;#n=new Set;#r=0;#i;#a=null;#o=null;#s=null;#c;createRenderRoot(){return this}constructor(){super(),this.format=`note`,this.labels={},this.uploadMaxFileSize=1024,this.threadItem=!1,this.removable=!1,this.inlineFormat=!1,this.titleByDefault=!0,this.positionLabel=``,this.badgeLabel=``,this.headerExtra=null,this.slashCommandDiscovered=!1,this._title=``,this._bodyJson=null,this._url=``,this._quoteText=``,this._quoteAuthor=``,this._rating=0,this._showTitle=!0,this._showRating=!1,this._attachedTexts=[],this._attachments=[],this._attachmentOrder=[],this._failedAttachmentPreviews=[],this._showAltPanel=!1,this._altPanelIndex=0,this._showEmojiPicker=!1,this._showUrlValidation=!1,this._showLinkTitleValidation=!1}connectedCallback(){super.connectedCallback(),document.addEventListener(`jant:slash-image`,this._onSlashImage),document.addEventListener(`jant:slash-command-discovered`,this._onSlashCommandDiscovered),this.addEventListener(`dragenter`,this._onDragEnter),this.addEventListener(`dragover`,this._onDragOver,!0),this.addEventListener(`dragleave`,this._onDragLeave),this.addEventListener(`drop`,this._onDrop),this.#x()?.addEventListener(`change`,this._onPointerTypeChange)}disconnectedCallback(){super.disconnectedCallback(),this.#h(),this._editor?.destroy(),this._editor=null,this.#a?.destroy(),this.#a=null,document.removeEventListener(`jant:slash-image`,this._onSlashImage),document.removeEventListener(`jant:slash-command-discovered`,this._onSlashCommandDiscovered),document.removeEventListener(`click`,this._onDocClickBound),this.removeEventListener(`dragenter`,this._onDragEnter),this.removeEventListener(`dragover`,this._onDragOver,!0),this.removeEventListener(`dragleave`,this._onDragLeave),this.removeEventListener(`drop`,this._onDrop),Lt(this),this._emojiContainer?.remove(),this._emojiPickerEl=null,this._filePickerCleanup?.(),this._filePickerCleanup=null,this.#x()?.removeEventListener(`change`,this._onPointerTypeChange)}#l=0;#u(e){let t=e.dataTransfer?.types;return t?Array.from(t).includes(`Files`):!1}_onDragEnter=e=>{this.#u(e)&&(this.#l+=1,this.classList.add(`compose-editor-dragover`))};_onDragOver=e=>{this.#u(e)&&(e.stopPropagation(),e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`))};_onDragLeave=e=>{this.#u(e)&&(this.#l=Math.max(0,this.#l-1),this.#l===0&&this.classList.remove(`compose-editor-dragover`))};_onDrop=e=>{if(this.#l=0,this.classList.remove(`compose-editor-dragover`),e.defaultPrevented)return;let t=de(e.dataTransfer);if(t.length===0)return;e.preventDefault();let n=[],r=[];for(let e of t)this._editor&&this._shouldPasteInlineImage(e)?n.push(e):r.push(e);for(let e of n)this._uploadAndInsertImage(e);r.length>0&&this.addFiles(r)};_onSlashCommandDiscovered=()=>{Bt()};_onSlashImage=()=>{document.querySelector(`.compose-fullscreen-dialog[open]`)||this._editor&&this._triggerSlashImagePicker()};_slashImageInput=null;_triggerSlashImagePicker(){this._slashImageInput||(this._slashImageInput=document.createElement(`input`),this._slashImageInput.type=`file`,this._slashImageInput.accept=`image/*`,this._slashImageInput.style.display=`none`,this._slashImageInput.addEventListener(`change`,()=>{let e=this._slashImageInput?.files?.[0];e&&this._editor&&this._uploadAndInsertImage(e),this._slashImageInput&&(this._slashImageInput.value=``)}),document.body.appendChild(this._slashImageInput)),this._trackFilePickerSession(this._slashImageInput),this._slashImageInput.click()}_uploadAndInsertImage(e){let t=this._editor;if(!t)return Promise.resolve();let n=this.#t,r=ie(t,e).finally(()=>{n===this.#t&&this.#n.delete(r)});return this.#n.add(r),r}#d(e){if(e.startsWith(`data:`))return!0;if(!/^https?:\/\//i.test(e))return!1;let t;try{t=new URL(e).origin}catch{return!1}if(t===window.location.origin)return!1;let n=document.documentElement.dataset.mediaBase;return!(n&&e.startsWith(n))}#f(e){let t=this._editor;if(!t){M(e);return}let n=e.startsWith(`data:`)?async()=>{let t=await(await fetch(e)).blob(),n=new File([t],`pasted-image`,{type:t.type||`image/png`});return(await fe(n)).url}:async()=>(await P(e)).url,r=async()=>{try{return await n()}catch(e){throw this.#p(),e}},i=this.#t,a=ce(t,e,r).finally(()=>{M(e),i===this.#t&&this.#n.delete(a)});this.#n.add(a)}#p(){this.#r+=1,this.#i===void 0&&(this.#i=setTimeout(()=>{this.#m()},800))}#m(){this.#i=void 0;let e=this.#r;if(this.#r=0,e<=0||!this.isConnected)return;let t=e===1?this.labels.imageNotRehosted??`An image couldn't be saved to your library — its original link was kept.`:(this.labels.imagesNotRehosted??`{count} images couldn't be saved to your library — their original links were kept.`).replace(`{count}`,String(e));d(t,`error`)}hasPendingInlineImageUploads(){return this.#n.size>0}async waitForPendingInlineImageUploads(){let e=this.#t;for(;e===this.#t&&this.#n.size>0;)await Promise.allSettled(Array.from(this.#n))}#h(){this.#t+=1,this.#n.clear(),this.#i!==void 0&&(clearTimeout(this.#i),this.#i=void 0),this.#r=0}adoptPendingUploads(){if(!this._editor)return;let e=this.#t,t=pe(this._editor);for(let n of t){let t=n.finally(()=>{e===this.#t&&this.#n.delete(t)});this.#n.add(t)}}_dispatchFilePickerEvent(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}_trackFilePickerSession(e){this._filePickerCleanup?.();let t=!1,n=e=>{t||(t=!0,o(),this._dispatchFilePickerEvent(`jant:file-picker-close`,{cancelled:e}))},r=()=>n(!1),i=()=>n(!0),a=()=>{globalThis.setTimeout(()=>{n(!(e.files&&e.files.length>0))},0)},o=()=>{e.removeEventListener(`change`,r),e.removeEventListener(`cancel`,i),window.removeEventListener(`focus`,a),this._filePickerCleanup===o&&(this._filePickerCleanup=null)};this._filePickerCleanup=o,e.addEventListener(`change`,r,{once:!0}),e.addEventListener(`cancel`,i,{once:!0}),window.addEventListener(`focus`,a,{once:!0}),this._dispatchFilePickerEvent(`jant:file-picker-open`)}_isEmptyDoc(e){return!e.content||e.content.length===0||e.content.every(e=>e.type===`paragraph`&&(!e.content||e.content.length===0||e.content.every(e=>e.type===`hardBreak`)))}_normalizeDocJson(e){return e?this._isEmptyDoc(e)?null:e:null}_isSelectionInsideTopLevelBlock(e){let t=this._editor;return t?t.state.selection.$from.index(0)===e:!1}_removedTopLevelSize(e){let t=this._editor?.state.doc;if(!t)return 0;let n=0;for(let r=0;r<=e.headingIndex;r+=1)n+=t.child(r)?.nodeSize??0;return n}promoteLeadingH1Title(e={}){if(this.format!==`note`||this._title.trim())return!1;let t=yt(this._editor?.getJSON()??this._bodyJson);if(!t||!e.force&&this._isSelectionInsideTopLevelBlock(t.headingIndex))return!1;let n=this._editor,r=!!n?.isFocused,i=n?.state.selection.from??null,a=this._removedTopLevelSize(t);if(this._title=t.title,this._showTitle=!0,this._bodyJson=t.bodyJson,n&&(t.bodyJson?n.commands.setContent(t.bodyJson):n.commands.clearContent(),r&&i!==null)){let e=n.state.doc.content.size;e>0&&(n.commands.setTextSelection(Math.max(1,Math.min(i-a,e))),n.commands.focus())}return!0}getNormalizedBodyJson(){return this._normalizeDocJson(this._bodyJson)}getEffectiveAttachedTexts(){return this._attachedTexts.flatMap(e=>{let t=this._normalizeDocJson(e.bodyJson);return t?[{...e,bodyJson:t,originalBodyJson:this._normalizeDocJson(e.originalBodyJson??null)}]:[]})}getEffectiveAttachmentOrder(){let e=new Set(this.getEffectiveAttachedTexts().map(e=>e.clientId)),t=new Set(this._attachments.map(e=>e.clientId));return this._attachmentOrder.filter(n=>t.has(n)||e.has(n))}_getEffectiveRating(){return this._showRating?this._rating:0}getData(){let e=this.getNormalizedBodyJson(),t=this.getEffectiveAttachedTexts(),n=this.getEffectiveAttachmentOrder(),r=e?JSON.stringify(e):``,i={rating:this._getEffectiveRating(),attachedTexts:t,attachments:this._attachments,attachmentOrder:n};switch(this.format){case`link`:return{...i,title:this._title,body:r,url:this._url,quoteText:``,quoteAuthor:``};case`quote`:return{...i,title:``,body:r,url:this._url,quoteText:this._quoteText,quoteAuthor:this._quoteAuthor};default:return{...i,title:this._showTitle?this._title:``,body:r,url:``,quoteText:``,quoteAuthor:``}}}getStatus(){let e=this.getData(),t=!!e.body||!!e.title.trim()||!!e.url.trim()||!!e.quoteText.trim()||!!e.quoteAuthor.trim()||e.rating>0||e.attachments.length>0||e.attachedTexts.length>0,n=!this.getUrlValidationMessage()&&!this.getLinkTitleValidationMessage(),r;switch(this.format){case`link`:r=n;break;case`quote`:r=n&&!!e.quoteText.trim();break;default:r=n&&t}return{hasContent:t,publishable:r}}#g=null;#_(){let e=this.getStatus();(this.#g?.hasContent!==e.hasContent||this.#g?.publishable!==e.publishable)&&(this.#g=e,this.dispatchEvent(new CustomEvent(`jant:compose-status`,{bubbles:!0,detail:e})))}setTitleDefault(e){this.titleByDefault=e,this._showTitle=e}reset(){this.#h(),this._title=``,this._showTitle=this.titleByDefault,this._bodyJson=null,this._editor?.commands.clearContent(),this._lastEditorSelection=null,this._url=``,this._quoteText=``,this._quoteAuthor=``,this._rating=0,this._showRating=!1,this._attachedTexts=[];for(let e of this._attachments)URL.revokeObjectURL(e.previewUrl),e.posterUrl&&URL.revokeObjectURL(e.posterUrl);this._attachments=[],this._attachmentOrder=[],this._failedAttachmentPreviews=[],this._showAltPanel=!1,this._altPanelIndex=0,this._showUrlValidation=!1,this._showLinkTitleValidation=!1,this.closeEmojiPicker()}updateAttachmentStatus(e,t,n,r,i){this._attachments=this._attachments.map(a=>a.clientId===e?{...a,status:t,mediaId:n,error:r,remoteUrl:i??a.remoteUrl}:a)}updateAttachmentPreview(e,t){this._setAttachmentPreviewFailure(e,!1),this._attachments=this._attachments.map(n=>n.clientId===e?(URL.revokeObjectURL(n.previewUrl),n.posterUrl&&URL.revokeObjectURL(n.posterUrl),{...n,file:t,previewUrl:URL.createObjectURL(t),posterUrl:null}):n)}updateAttachmentPoster(e,t){let n=URL.createObjectURL(t);this._attachments=this._attachments.map(t=>t.clientId===e?{...t,posterUrl:n}:t)}updateAttachmentProgress(e,t){this._attachments=this._attachments.map(n=>n.clientId===e?{...n,progress:t}:n)}focusInput(e){if(this.format===`link`){this.focusUrlInput(e);return}if(this.format===`quote`){this._focusTextControl(this.querySelector(`.compose-quote-text`),e);return}if(e){this._editor?.commands.focus(e);return}this._editor?.commands.focus()}focusSelection(e){if(this.format!==`note`||!this._editor){this.focusInput();return}let t=e??this.getEditorSelection();if(!t){this.focusInput();return}let n=Ut(this._editor,t);this._lastEditorSelection=n,this._editor.chain().focus().setTextSelection(n).run()}focusUrlInput(e){this._focusTextControl(this.querySelector(`.compose-url-input`),e)}focusLinkTitleInput(e){this._focusTextControl(this.querySelector(`.compose-link-title`),e)}getUrlValidationMessage(){return this.format===`note`?null:this._url.trim()?e(this._url)?null:this.labels.urlInvalid:this.format===`link`?this.labels.linkUrlRequired:null}getLinkTitleValidationMessage(){return this.format===`link`?this._title.trim()?null:this.labels.linkTitleRequired:null}revealUrlValidation(){return this._showUrlValidation=!0,this.getUrlValidationMessage()}revealLinkTitleValidation(){return this._showLinkTitleValidation=!0,this.getLinkTitleValidationMessage()}getEditorSelection(){return this._readEditorSelection()??this._lastEditorSelection}isEmojiPickerOpen(){return this._showEmojiPicker}_readEditorSelection(){if(!this._editor)return null;let{from:e,to:t}=this._editor.state.selection;return{from:e,to:t}}_focusTextControl(e,t){if(!e||(e.focus(),!t))return;let n=t===`end`?e.value.length:0;e.setSelectionRange(n,n)}_initEditor(){let e=this.querySelector(`.compose-tiptap-body`);e&&!this._editor&&(this.dataset.slashCommandDiscovered=this.slashCommandDiscovered?`true`:`false`,this._editor=ue({element:e,placeholder:this.format===`note`?this.labels.bodyPlaceholder:this.labels.thoughtsPlaceholder,content:this._bodyJson,toolbarMode:`compose`,onUpdate:e=>{this._bodyJson=e,this.promoteLeadingH1Title(),Lt(this)},onFocus:()=>{this._lastFocusedField=null,this._editor?.isEmpty&&zt(this)},onBlur:()=>{this.promoteLeadingH1Title({force:!0})},onSelectionUpdate:e=>{this._lastEditorSelection=e},pasteMedia:{shouldInsertInline:e=>this._shouldPasteInlineImage(e),uploadInlineImage:e=>this._uploadAndInsertImage(e),onPasteFiles:e=>{this.addFiles(e)}},rehostImages:{shouldRehost:e=>this.#d(e),rehost:e=>this.#f(e)},imageNodeLabels:Vt(this.labels),tableControlLabels:this.labels.tableControls,highlightLabel:this.labels.highlight}),this._lastEditorSelection=this._readEditorSelection(),this.adoptPendingUploads())}_destroyEditor(){this.#h(),this._editor?.destroy(),this._editor=null}static _CONTENT_PROPS=new Set([`_title`,`_bodyJson`,`_url`,`_quoteText`,`_quoteAuthor`,`_rating`,`_showTitle`,`_showRating`,`_attachedTexts`,`_attachmentOrder`]);willUpdate(e){super.willUpdate(e),!this.hasUpdated&&!this.#e&&(this._showTitle=this.titleByDefault)}updated(e){if(super.updated(e),this._editor||this._initEditor(),e.has(`format`)&&e.get(`format`)!==void 0&&(this._showUrlValidation&&=!1,this._showLinkTitleValidation&&=!1,this._destroyEditor(),this.updateComplete.then(()=>this._initEditor())),(e.has(`_attachmentOrder`)||e.has(`_attachments`)||e.has(`_attachedTexts`))&&(e.has(`_attachments`)&&this._syncFailedAttachmentPreviews(),this._attachmentOrder.length>1?this.#S():(this.#a?.destroy(),this.#a=null),this.#y()),this.#_(),this._suppressContentChangedOnce)this._suppressContentChangedOnce=!1;else for(let n of e.keys())if(t._CONTENT_PROPS.has(n)){this.dispatchEvent(new Event(`jant:compose-content-changed`,{bubbles:!0}));break}}getEditorState(){return{json:this._editor?.getJSON()??this._bodyJson,title:this._title,showTitle:this._showTitle,selection:this.getEditorSelection()}}getConvertibleFields(){return{title:this._title,url:this._url,quoteText:this._quoteText,quoteAuthor:this._quoteAuthor,showTitle:this._showTitle,bodyJson:this._normalizeDocJson(this._editor?.getJSON()??this._bodyJson)}}applyConvertedFields(e){this._suppressContentChangedOnce=!0,this._title=e.title,this._url=e.url,this._quoteText=e.quoteText,this._quoteAuthor=e.quoteAuthor,this._showTitle=e.showTitle,this._bodyJson=e.bodyJson}takeOver(e){this._title=e._title,this._showTitle=e._showTitle,this.#e=!0,this._bodyJson=e._editor?.getJSON()??e._bodyJson,this._url=e._url,this._quoteText=e._quoteText,this._quoteAuthor=e._quoteAuthor,this._rating=e._rating,this._showRating=e._showRating,this._attachedTexts=[...e._attachedTexts],this._attachments=[...e._attachments],this._attachmentOrder=[...e._attachmentOrder],this._lastEditorSelection=e.getEditorSelection(),this._editor&&(this._editor.commands.setContent(this._bodyJson??{type:`doc`,content:[{type:`paragraph`}]}),this.adoptPendingUploads()),this.#_()}hasAttachment(e){return this._attachments.some(t=>t.clientId===e)}#v(){let e=this._attachments.flatMap(e=>e.file.type.startsWith(`video/`)&&e.mediaId&&e.remoteUrl&&e.posterUrl===null?[{clientId:e.clientId,mediaId:e.mediaId,url:e.remoteUrl}]:[]);e.length!==0&&this.updateComplete.then(()=>{this.dispatchEvent(new CustomEvent(`jant:video-posters-missing`,{bubbles:!0,detail:{attachments:e}}))})}populate(e){if(e.title&&(this._title=e.title),e.url&&(this._url=e.url),e.quoteText&&(this._quoteText=e.quoteText),e.quoteAuthor&&(this._quoteAuthor=e.quoteAuthor),e.rating&&e.rating>0&&(this._rating=e.rating,this._showRating=!0),e.showTitle===void 0?e.title&&e.format===`note`&&(this._showTitle=!0):this._showTitle=e.showTitle,e.showRating!==void 0&&(this._showRating=e.showRating),this._failedAttachmentPreviews=[],e.bodyJson)try{let t=JSON.parse(e.bodyJson);this._bodyJson=t,this._editor&&this._editor.commands.setContent(t)}catch{}if(e.media?.length){let t=e.media.map(e=>({clientId:e.clientId??L(),file:new File([],e.originalName??`existing`,{type:e.mimeType}),previewUrl:e.previewUrl,posterUrl:e.posterUrl??null,status:`done`,progress:null,mediaId:e.id,persisted:e.persisted??!1,remoteUrl:e.previewUrl,alt:e.alt??``,error:null,summary:e.summary??null,chars:e.chars??null}));this._attachments=t,this._attachmentOrder=t.map(e=>e.clientId),this.#v()}if(e.textAttachments?.length){let t=e=>{try{return JSON.parse(e)}catch{return null}},n=e.textAttachments.map(e=>{let n=t(e.bodyJson);return{clientId:e.clientId??L(),bodyJson:n,bodyHtml:e.bodyHtml??``,summary:e.summary,mediaId:e.mediaId,originalBodyJson:e.originalBodyJson===void 0?n:t(e.originalBodyJson)}});this._attachedTexts=n,this._attachmentOrder=[...this._attachmentOrder,...n.map(e=>e.clientId)]}if(e.attachmentOrder?.length){let t=e.attachmentOrder.map(e=>this._attachments.find(t=>t.mediaId===e||t.clientId===e)?.clientId||this._attachedTexts.find(t=>t.mediaId===e||t.clientId===e)?.clientId).filter(e=>e!==void 0),n=this._attachmentOrder.filter(e=>!t.includes(e));this._attachmentOrder=[...t,...n]}this._showUrlValidation=!1,this._showLinkTitleValidation=!1,this.#_()}setEditorState(e,t,n,r){this._bodyJson=e,this._title=t,this.format===`note`&&(this._showTitle=n||t.length>0),this._editor&&this._editor.commands.setContent(e??{type:`doc`,content:[{type:`paragraph`}]}),this._lastEditorSelection=r??this._readEditorSelection(),this.#_()}static SUMMARY_LENGTH=100;_computeSummary(e){let n=e.replace(/\s+/g,` `).trim();return n.length<=t.SUMMARY_LENGTH?n:n.slice(0,t.SUMMARY_LENGTH)+`…`}_openAttachedText(){let e={clientId:L(),bodyJson:null,bodyHtml:``,summary:``};this._attachedTexts=[...this._attachedTexts,e],this._attachmentOrder=[...this._attachmentOrder,e.clientId];let t=this._attachedTexts.length-1;this.dispatchEvent(new CustomEvent(`jant:attached-panel-open`,{bubbles:!0,detail:{index:t}}))}_moveAttachment(e,t,n=`handle`){let r=this._attachmentOrder.indexOf(e),i=r+t;if(r===-1||i<0||i>=this._attachmentOrder.length)return;let a=[...this._attachmentOrder],[o]=a.splice(r,1);o&&(a.splice(i,0,o),this._attachmentOrder=a,this.#s={clientId:e,direction:t,focusTarget:n},this.#C(e))}#y(){let e=this.#s;if(!e)return;this.#s=null;let t=this.querySelector(`[data-attachment-id="${e.clientId}"]`);if(t){if(e.focusTarget===`handle`){t.querySelector(`[data-attachment-sortable]`)?.focus({preventScroll:!0});return}(this.#b(t,e.direction)??this.#b(t,e.direction===1?-1:1))?.focus({preventScroll:!0})}}#b(e,t){let n=e.querySelector(`[data-attachment-move="${t===-1?`earlier`:`later`}"]`);return n&&!n.disabled?n:null}_handleAttachmentKeydown(e,t,n){if(t.key===`ArrowLeft`||t.key===`ArrowUp`){t.preventDefault(),this._moveAttachment(e,-1);return}if(t.key===`ArrowRight`||t.key===`ArrowDown`){t.preventDefault(),this._moveAttachment(e,1);return}n&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n())}#x(){return this.#c===void 0&&(this.#c=typeof window.matchMedia==`function`?window.matchMedia(`(pointer: coarse)`):null),this.#c}_onPointerTypeChange=()=>{this.#a?.destroy(),this.#a=null,this.#S()};#S(){let e=this.querySelector(`[data-attachment-list]`);!e||this.#a||this._attachmentOrder.length<=1||this.#x()?.matches||(this.#a=ne.create(e,{...E,chosenClass:`compose-attachment-chosen`,delay:250,direction:`horizontal`,dragClass:`compose-attachment-drag`,filter:`button, a, input, textarea, select, option, [contenteditable='true']`,ghostClass:`compose-attachment-ghost`,handle:`[data-attachment-sortable]`,preventOnFilter:!1,scroll:e,onChoose:()=>{O(e,!0)},onStart:e=>{this.#o=re(e)},onUnchoose:()=>{O(e,!1)},onEnd:t=>{let n=k(e,`[data-attachment-id]`,`attachmentId`);if(te(e,t,this.#o),this.#o=null,O(e,!1),this.#a?.destroy(),this.#a=null,n.length===this._attachmentOrder.length){this._attachmentOrder=n;let{movedId:e}=D(n,t.newIndex);e&&(this._suppressAttachedTextOpenUntil=Date.now()+250,this.#C(e))}}}))}#C(e){this.updateComplete.then(()=>{this.querySelector(`[data-attachment-id="${e}"]`)?.scrollIntoView({behavior:`smooth`,block:`nearest`,inline:`nearest`})})}_maybeEditAttachedText(e){Date.now()<this._suppressAttachedTextOpenUntil||this._editAttachedText(e)}_editAttachedText(e){this.dispatchEvent(new CustomEvent(`jant:attached-panel-open`,{bubbles:!0,detail:{index:e}}))}_removeAttachedText(e){let t=this._attachedTexts[e];this._attachedTexts=this._attachedTexts.filter((t,n)=>n!==e),t&&(this._attachmentOrder=this._attachmentOrder.filter(e=>e!==t.clientId))}updateAttachedText(e,t,n){let r=this._normalizeDocJson(t),i=this._extractPlainText(r);this._attachedTexts=this._attachedTexts.map((t,a)=>a===e?{...t,bodyJson:r,bodyHtml:r?n??``:``,summary:this._computeSummary(i)}:t)}closeAttachedPanel(e){let t=this._attachedTexts[e];t&&(t.mediaId||this._hasAttachedTextContent(t.bodyJson)||(this._attachedTexts=this._attachedTexts.filter((t,n)=>n!==e),this._attachmentOrder=this._attachmentOrder.filter(e=>e!==t.clientId)))}_hasAttachedTextContent(e){let t=this._normalizeDocJson(e);return t?this._extractPlainText(t).trim().length>0:!1}_extractPlainText(e){if(!e)return``;let t=``,n=e=>{e.text&&(t+=e.text),e.content&&e.content.forEach(n)};return n(e),t}_onInput(e,t){let n=t.target;this[e]=n.value,n.tagName===`TEXTAREA`&&this._autoResize(n)}_autoResize(e){e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`}#w=null;#T=null;_recordBodyPress=e=>{this.#w=e.target,this.#T=null};_recordBodyRelease=e=>{this.#T=e.target};_focusBodyFromBlankSpace=e=>{let t=this.#w,n=this.#T;if(this.#w=null,this.#T=null,t!==e.target||n!==e.target)return;let r=e.target;r&&(r.classList.contains(`compose-body`)||r.classList.contains(`compose-field-enter`)||r.classList.contains(`compose-tiptap-wrap`))&&this._editor?.commands.focus(`end`)};_setRating(e){this._rating=this._rating===e?0:e}_shouldPasteInlineImage(e){return!e.type.startsWith(`image/`)||this.format!==`note`||!this._showTitle?!1:this._title.trim().length>0}_openFilePicker(){this._fileInput||(this._fileInput=document.createElement(`input`),this._fileInput.type=`file`,this._fileInput.multiple=!0,this._fileInput.style.display=`none`,this._fileInput.addEventListener(`change`,()=>this._handleFilesSelected()),this.appendChild(this._fileInput)),this._fileInput.value=``,this._trackFilePickerSession(this._fileInput),this._fileInput.click()}_handleFilesSelected(){let e=this._fileInput?.files;e&&e.length!==0&&this.addFiles(e)}addFiles(e){let t=Array.from(e);if(t.length===0)return;let n=[],r=[];for(let e of t){let t=Ze(e,{maxFileSizeMB:this.uploadMaxFileSize});if(t){d(t,`error`);continue}let i=L(),a=URL.createObjectURL(e);n.push({clientId:i,file:e,previewUrl:a,posterUrl:null,status:`pending`,progress:null,mediaId:null,persisted:!1,remoteUrl:null,alt:``,error:null,summary:null,chars:null}),r.push({file:e,clientId:i})}if(n.length!==0){this._attachments=[...this._attachments,...n],this._attachmentOrder=[...this._attachmentOrder,...n.map(e=>e.clientId)];for(let e of n)F(e.file.type)===`text`&&e.file.text().then(t=>{let n=this._computeSummary(t),r=t.length;this._attachments=this._attachments.map(t=>t.clientId===e.clientId?{...t,summary:n,chars:r}:t)});this.dispatchEvent(new CustomEvent(`jant:files-selected`,{bubbles:!0,detail:{files:r}}))}}removeAttachment(e){let t=this._attachments.findIndex(t=>t.clientId===e);t!==-1&&this._removeAttachment(t)}_removeAttachment(e){let t=this._attachments[e];t&&(this._setAttachmentPreviewFailure(t.clientId,!1),URL.revokeObjectURL(t.previewUrl),t.posterUrl&&URL.revokeObjectURL(t.posterUrl),this.dispatchEvent(new CustomEvent(`jant:attachment-removed`,{bubbles:!0,detail:{clientId:t.clientId,mediaId:t.mediaId,persisted:t.persisted}}))),t&&(this._attachmentOrder=this._attachmentOrder.filter(e=>e!==t.clientId)),this._attachments=this._attachments.filter((t,n)=>n!==e),this._showAltPanel&&this._altPanelIndex===e?(this._showAltPanel=!1,this.dispatchEvent(new CustomEvent(`jant:alt-panel-close`,{bubbles:!0}))):this._showAltPanel&&this._altPanelIndex>e&&--this._altPanelIndex}_retryAllFailed(){let e=this._attachments.filter(e=>e.status===`error`);e.length!==0&&(this._attachments=this._attachments.map(e=>e.status===`error`?{...e,status:`pending`,progress:null,error:null}:e),this.dispatchEvent(new CustomEvent(`jant:files-selected`,{bubbles:!0,detail:{files:e.map(e=>({file:e.file,clientId:e.clientId}))}})))}_openAltPanel(e){this._altPanelIndex=e,this._showAltPanel=!0,this.dispatchEvent(new CustomEvent(`jant:alt-panel-open`,{bubbles:!0,detail:{index:e}}))}updateAlt(e,t){this._attachments=this._attachments.map((n,r)=>r===e?{...n,alt:t}:n)}_onFieldFocus(e){let t=e.target;this._lastFocusedField=t}_handleTitleKeydown(e){e.isComposing||e.keyCode===229||e.key!==`Enter`||e.metaKey||e.ctrlKey||e.altKey||(e.preventDefault(),this._editor?.commands.focus(`start`))}_toggleEmojiPicker(){this._showEmojiPicker?this.closeEmojiPicker():(this._showEmojiPicker=!0,this._mountEmojiPicker(),globalThis.setTimeout(()=>{document.addEventListener(`click`,this._onDocClickBound)},0))}closeEmojiPicker(e){if(!this._showEmojiPicker){e?.restoreFocus&&this._restoreEmojiFocus();return}this._showEmojiPicker=!1,this._emojiContainer?.remove(),this._emojiPickerEl=null,document.removeEventListener(`click`,this._onDocClickBound),e?.restoreFocus&&this._restoreEmojiFocus()}_restoreEmojiFocus(){let e=this._lastFocusedField;if(e&&this.contains(e)&&!e.disabled){e.focus();return}this.focusSelection()}_onDocumentClick(e){let t=e.target;this.querySelector(`.compose-emoji-btn`)?.contains(t)||this._emojiContainer?.contains(t)||this.closeEmojiPicker()}async _mountEmojiPicker(){let e=this.closest(`dialog`);if(this._emojiContainer||(this._emojiContainer=document.createElement(`div`),this._emojiContainer.className=`compose-emoji-picker`),(e??document.body).appendChild(this._emojiContainer),!this._emojiPickerEl){let[{default:e},{Picker:t}]=await Promise.all([p(()=>import(`./chunks/emoji-mart-C4RpRKcU.js`).then(e=>e.n),__vite__mapDeps([0,1])),p(()=>import(`./chunks/emoji-mart-C4RpRKcU.js`).then(e=>e.t),__vite__mapDeps([0,1]))]);if(!this._showEmojiPicker)return;let n=new t({data:e,onEmojiSelect:e=>{this._insertEmoji(e.native),this.closeEmojiPicker()},theme:`auto`,previewPosition:`none`,skinTonePosition:`none`});this._emojiPickerEl=n}this._emojiContainer.innerHTML=``,this._emojiContainer.appendChild(this._emojiPickerEl);let t=this.querySelector(`.compose-emoji-btn`);if(t&&e){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),i=n.left-r.left,a=n.top-r.top,o=i+n.width/2-176;o=Math.max(-r.left+8,Math.min(o,r.width-8));let s=a-435-8;r.top+s<8&&(s=a+n.height+8),this._emojiContainer.style.left=`${o}px`,this._emojiContainer.style.top=`${s}px`}}_insertEmoji(e){let t=this._lastFocusedField;if(!t){this._editor&&this._editor.chain().focus().insertContent(e).run();return}let n=t.selectionStart??t.value.length,r=t.selectionEnd??n,i=t.value.slice(0,n),a=t.value.slice(r);t.value=i+e+a,t.dispatchEvent(new Event(`input`,{bubbles:!0}));let o=n+e.length;globalThis.requestAnimationFrame(()=>{t.focus(),t.setSelectionRange(o,o)})}_getCategory(e){return F(e.file.type)}_formatSize(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}_formatChars(e){return e<1e3?`${e} chars`:e<1e6?`${parseFloat((e/1e3).toFixed(1))}k chars`:`${parseFloat((e/1e6).toFixed(1))}M chars`}_renderFileIcon(e,t){let n;return n=e===`application/pdf`?`<text x="12" y="16.5" text-anchor="middle" fill="currentColor" stroke="none" font-size="6" font-weight="700" font-family="system-ui, sans-serif">PDF</text>`:e===`text/markdown`?`<text x="12" y="16.5" text-anchor="middle" fill="currentColor" stroke="none" font-size="10" font-weight="700" font-family="system-ui, sans-serif">#</text>`:e===`text/csv`?`<line x1="8" y1="12" x2="16" y2="12"/><line x1="8" y1="15" x2="16" y2="15"/><line x1="8" y1="18" x2="16" y2="18"/><line x1="10.7" y1="12" x2="10.7" y2="18"/><line x1="13.3" y1="12" x2="13.3" y2="18"/>`:F(e)===`archive`?`<line x1="12" y1="10" x2="12" y2="11.5"/><line x1="12" y1="13" x2="12" y2="14.5"/><line x1="12" y1="16" x2="12" y2="17.5"/>`:e===`text/html; charset=utf-8`?`<line x1="16" y1="11" x2="8" y2="11"/><line x1="16" y1="14" x2="8" y2="14"/><line x1="12" y1="17" x2="8" y2="17"/>`:`<line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><line x1="10" y1="9" x2="8" y2="9"/>`,o`<svg
1324
+ width="${t}"
1325
+ height="${t}"
1326
+ viewBox="0 0 24 24"
1327
+ fill="none"
1328
+ stroke="currentColor"
1329
+ stroke-width="1.5"
1330
+ stroke-linecap="round"
1331
+ stroke-linejoin="round"
1332
+ >
1333
+ ${b(`<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/>`+n)}
1334
+ </svg>`}_hasFailedAttachmentPreview(e){return this._failedAttachmentPreviews.includes(e)}_setAttachmentPreviewFailure(e,t){t!==this._failedAttachmentPreviews.includes(e)&&(this._failedAttachmentPreviews=t?[...this._failedAttachmentPreviews,e]:this._failedAttachmentPreviews.filter(t=>t!==e))}_syncFailedAttachmentPreviews(){let e=new Set(this._attachments.map(e=>e.clientId)),t=this._failedAttachmentPreviews.filter(t=>e.has(t));t.length!==this._failedAttachmentPreviews.length&&(this._failedAttachmentPreviews=t)}_renderAttachmentPreviewFallback(e){let t=this.labels.brokenImageUnavailable??`Image unavailable`;return o`
1335
+ <div
1336
+ class="compose-attachment-preview-fallback"
1337
+ data-preview-failed=${e}
1338
+ aria-label=${t}
1339
+ >
1340
+ <svg
1341
+ width="28"
1342
+ height="28"
1343
+ viewBox="0 0 24 24"
1344
+ fill="none"
1345
+ stroke="currentColor"
1346
+ stroke-width="1.5"
1347
+ stroke-linecap="round"
1348
+ stroke-linejoin="round"
1349
+ >
1350
+ <rect x="3.5" y="5" width="17" height="14" rx="2.5" />
1351
+ <circle cx="9" cy="10" r="1.25" />
1352
+ <path d="m7 16 3.4-3.45 2.65 2.45 2.45-3.05 1.95 2.5" />
1353
+ </svg>
1354
+ <span class="compose-attachment-preview-fallback-label">
1355
+ ${t}
1356
+ </span>
1357
+ ${e===`video`?o`
1358
+ <div class="compose-attachment-play-icon">
1359
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="white">
1360
+ <path d="M8 5v14l11-7z" />
1361
+ </svg>
1362
+ </div>
1363
+ `:c}
1364
+ </div>
1365
+ `}_renderNoteFields(){return o`
1366
+ <div class="compose-field-enter">
1367
+ ${this._showTitle?o`<input
1368
+ type="text"
1369
+ .value=${this._title}
1370
+ @input=${e=>this._onInput(`_title`,e)}
1371
+ @focus=${e=>this._onFieldFocus(e)}
1372
+ @keydown=${this._handleTitleKeydown}
1373
+ class="compose-input compose-note-title"
1374
+ placeholder=${this.labels.titlePlaceholder}
1375
+ />`:c}
1376
+ <div class="compose-tiptap-wrap">
1377
+ <div class="compose-tiptap-body"></div>
1378
+ <span class="compose-slash-discovery-hint" aria-hidden="true">
1379
+ ${this.labels.slashHint}
1380
+ </span>
1381
+ </div>
1382
+ </div>
1383
+ `}_renderLinkFields(){let e=this._showUrlValidation?this.getUrlValidationMessage():null,t=this._showLinkTitleValidation?this.getLinkTitleValidationMessage():null;return o`
1384
+ <div class="compose-field-enter">
1385
+ <div
1386
+ class=${w({"compose-link-url-wrap":!0,"compose-link-url-wrap-invalid":!!e})}
1387
+ >
1388
+ <span class="text-base opacity-50 shrink-0">🔗</span>
1389
+ <input
1390
+ type="url"
1391
+ .value=${this._url}
1392
+ @input=${e=>this._onInput(`_url`,e)}
1393
+ @focus=${e=>this._onFieldFocus(e)}
1394
+ @blur=${()=>{this._url.trim()&&(this._showUrlValidation=!0)}}
1395
+ class="compose-input compose-url-input"
1396
+ placeholder=${this.labels.urlPlaceholder}
1397
+ aria-invalid=${e?`true`:`false`}
1398
+ aria-describedby=${he(e?this._urlStatusId:void 0)}
1399
+ />
1400
+ </div>
1401
+ ${e?o`<p
1402
+ id=${this._urlStatusId}
1403
+ class="compose-url-status compose-url-status-error"
1404
+ data-compose-url-status="error"
1405
+ >
1406
+ ${e}
1407
+ </p>`:c}
1408
+ <input
1409
+ type="text"
1410
+ .value=${this._title}
1411
+ @input=${e=>this._onInput(`_title`,e)}
1412
+ @focus=${e=>this._onFieldFocus(e)}
1413
+ @keydown=${this._handleTitleKeydown}
1414
+ @blur=${()=>{this._title.trim()&&(this._showLinkTitleValidation=!0)}}
1415
+ class="compose-input compose-link-title"
1416
+ placeholder=${this.labels.linkTitlePlaceholder}
1417
+ aria-invalid=${t?`true`:`false`}
1418
+ />
1419
+ ${t?o`<p
1420
+ class="compose-url-status compose-url-status-error"
1421
+ data-compose-link-title-error="error"
1422
+ >
1423
+ ${t}
1424
+ </p>`:c}
1425
+ <div class="compose-divider"></div>
1426
+ <div class="compose-tiptap-wrap">
1427
+ <div class="compose-tiptap-body compose-tiptap-link"></div>
1428
+ <span class="compose-slash-discovery-hint" aria-hidden="true">
1429
+ ${this.labels.slashHint}
1430
+ </span>
1431
+ </div>
1432
+ </div>
1433
+ `}_renderQuoteFields(){let e=this._showUrlValidation?this.getUrlValidationMessage():null;return o`
1434
+ <div class="compose-field-enter">
1435
+ <div class="compose-quote-wrap">
1436
+ ${Ht(`compose-quote-mark`)}
1437
+ <textarea
1438
+ .value=${this._quoteText}
1439
+ @input=${e=>this._onInput(`_quoteText`,e)}
1440
+ @focus=${e=>this._onFieldFocus(e)}
1441
+ class="compose-input compose-quote-text"
1442
+ placeholder=${this.labels.quotePlaceholder}
1443
+ rows="4"
1444
+ ></textarea>
1445
+ </div>
1446
+ <div class="compose-quote-author-row">
1447
+ <span class="compose-quote-dash" aria-hidden="true">—</span>
1448
+ <input
1449
+ type="text"
1450
+ .value=${this._quoteAuthor}
1451
+ @input=${e=>this._onInput(`_quoteAuthor`,e)}
1452
+ @focus=${e=>this._onFieldFocus(e)}
1453
+ class="compose-input compose-quote-author"
1454
+ placeholder=${this.labels.authorPlaceholder}
1455
+ />
1456
+ </div>
1457
+ <div class="compose-quote-source">
1458
+ <input
1459
+ type="url"
1460
+ .value=${this._url}
1461
+ @input=${e=>this._onInput(`_url`,e)}
1462
+ @focus=${e=>this._onFieldFocus(e)}
1463
+ @blur=${()=>{this._showUrlValidation=!0}}
1464
+ class="compose-input compose-url-input compose-quote-source-input"
1465
+ placeholder=${this.labels.sourcePlaceholder}
1466
+ aria-invalid=${e?`true`:`false`}
1467
+ aria-describedby=${he(e?this._urlStatusId:void 0)}
1468
+ />
1469
+ ${e?o`<p
1470
+ id=${this._urlStatusId}
1471
+ class="compose-url-status compose-url-status-error"
1472
+ data-compose-url-status="error"
1473
+ >
1474
+ ${e}
1475
+ </p>`:c}
1476
+ </div>
1477
+ <div
1478
+ class="compose-divider compose-divider-quote"
1479
+ aria-hidden="true"
1480
+ ></div>
1481
+ <div class="compose-tiptap-wrap">
1482
+ <div class="compose-tiptap-body"></div>
1483
+ <span class="compose-slash-discovery-hint" aria-hidden="true">
1484
+ ${this.labels.slashHint}
1485
+ </span>
1486
+ </div>
1487
+ </div>
1488
+ `}_renderStarRating(){return this._showRating?o`
1489
+ <div class="compose-star-rating">
1490
+ ${[1,2,3,4,5].map(e=>o`
1491
+ <button
1492
+ type="button"
1493
+ class=${w({"compose-star":!0,"compose-star-filled":this._rating>=e})}
1494
+ @click=${()=>this._setRating(e)}
1495
+ >
1496
+ ★
1497
+ </button>
1498
+ `)}
1499
+ ${this._rating>0?o`<span class="compose-star-label">${this._rating}/5</span>`:c}
1500
+ </div>
1501
+ `:c}_renderAttachmentPreview(e){let t=this._getCategory(e);return t===`video`?o`
1502
+ <div class="compose-attachment-thumb">
1503
+ <video
1504
+ src=${e.previewUrl}
1505
+ class="compose-attachment-img"
1506
+ preload="metadata"
1507
+ muted
1508
+ ></video>
1509
+ <div class="compose-attachment-play-icon">
1510
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="white">
1511
+ <path d="M8 5v14l11-7z" />
1512
+ </svg>
1513
+ </div>
1514
+ </div>
1515
+ `:t===`audio`?o`
1516
+ <div class="compose-attachment-file-card">
1517
+ <div class="compose-attachment-file-icon">
1518
+ <svg
1519
+ width="20"
1520
+ height="20"
1521
+ viewBox="0 0 24 24"
1522
+ fill="none"
1523
+ stroke="currentColor"
1524
+ stroke-width="1.5"
1525
+ stroke-linecap="round"
1526
+ stroke-linejoin="round"
1527
+ >
1528
+ <path d="M9 18V5l12-2v13" />
1529
+ <circle cx="6" cy="18" r="3" />
1530
+ <circle cx="18" cy="16" r="3" />
1531
+ </svg>
1532
+ </div>
1533
+ <span class="compose-attachment-file-name">${e.file.name}</span>
1534
+ <span class="compose-attachment-file-size"
1535
+ >${this._formatSize(e.file.size)}</span
1536
+ >
1537
+ </div>
1538
+ `:t===`document`?o`
1539
+ <div class="compose-attachment-file-card">
1540
+ <div class="compose-attachment-file-icon">
1541
+ ${this._renderFileIcon(e.file.type,20)}
1542
+ </div>
1543
+ <span class="compose-attachment-file-name">${e.file.name}</span>
1544
+ <span class="compose-attachment-file-size"
1545
+ >${this._formatSize(e.file.size)}</span
1546
+ >
1547
+ </div>
1548
+ `:t===`text`?o`
1549
+ <div class="compose-attachment-file-card">
1550
+ <div class="compose-attachment-file-icon">
1551
+ ${this._renderFileIcon(e.file.type,20)}
1552
+ </div>
1553
+ <span class="compose-attachment-file-name">${e.file.name}</span>
1554
+ ${e.summary?o`<span class="compose-attachment-text-summary"
1555
+ >${e.summary}</span
1556
+ >`:c}
1557
+ ${typeof e.chars==`number`&&e.chars>0?o`<span class="compose-attachment-file-size"
1558
+ >${this._formatChars(e.chars)}</span
1559
+ >`:c}
1560
+ </div>
1561
+ `:t===`image`?o`
1562
+ <div class="compose-attachment-thumb">
1563
+ <img src=${e.previewUrl} alt="" class="compose-attachment-img" />
1564
+ </div>
1565
+ `:o`
1566
+ <div class="compose-attachment-file-card">
1567
+ <div class="compose-attachment-file-icon">
1568
+ ${this._renderFileIcon(e.file.type,20)}
1569
+ </div>
1570
+ <span class="compose-attachment-file-name">${e.file.name}</span>
1571
+ <span class="compose-attachment-file-size"
1572
+ >${this._formatSize(e.file.size)}</span
1573
+ >
1574
+ </div>
1575
+ `}_renderAttachmentOverlay(e,t){return o`
1576
+ ${e.status===`error`?o`
1577
+ <button
1578
+ type="button"
1579
+ class="compose-attachment-overlay compose-attachment-retry"
1580
+ @click=${e=>{e.stopPropagation(),this._retryAllFailed()}}
1581
+ >
1582
+ <span class="compose-retry-content">
1583
+ <svg
1584
+ width="20"
1585
+ height="20"
1586
+ viewBox="0 0 24 24"
1587
+ fill="none"
1588
+ stroke="currentColor"
1589
+ stroke-width="2"
1590
+ stroke-linecap="round"
1591
+ stroke-linejoin="round"
1592
+ >
1593
+ <path
1594
+ d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"
1595
+ />
1596
+ <path d="M3 3v5h5" />
1597
+ <path
1598
+ d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"
1599
+ />
1600
+ <path d="M16 16h5v5" />
1601
+ </svg>
1602
+ <span class="compose-retry-label"
1603
+ >${this.labels.retryAll}</span
1604
+ >
1605
+ </span>
1606
+ ${e.error?o`<span class="compose-attachment-error-msg"
1607
+ >${e.error}</span
1608
+ >`:c}
1609
+ </button>
1610
+ `:c}
1611
+ ${this._renderAttachmentRemoveButton(e=>{e.stopPropagation(),this._removeAttachment(t)})}
1612
+ `}_renderAttachmentRemoveButton(e){return o`
1613
+ <button
1614
+ type="button"
1615
+ class="compose-attachment-remove"
1616
+ aria-label=${this.labels.removeAttachment}
1617
+ @click=${e}
1618
+ >
1619
+ <svg
1620
+ width="14"
1621
+ height="14"
1622
+ viewBox="0 0 14 14"
1623
+ fill="none"
1624
+ stroke="currentColor"
1625
+ stroke-width="1.9"
1626
+ stroke-linecap="round"
1627
+ >
1628
+ <path d="M3.5 3.5 10.5 10.5" />
1629
+ <path d="M10.5 3.5 3.5 10.5" />
1630
+ </svg>
1631
+ </button>
1632
+ `}_renderAttachmentMoveButton(e,t,n){let r=t===-1,i=r?this.labels.moveAttachmentEarlier:this.labels.moveAttachmentLater;return o`
1633
+ <button
1634
+ type="button"
1635
+ class="compose-attachment-move"
1636
+ data-attachment-move=${r?`earlier`:`later`}
1637
+ ?disabled=${n}
1638
+ aria-label=${i}
1639
+ title=${i}
1640
+ @click=${n=>{n.stopPropagation(),this._moveAttachment(e,t,`move`)}}
1641
+ >
1642
+ <svg
1643
+ width="14"
1644
+ height="14"
1645
+ viewBox="0 0 14 14"
1646
+ fill="none"
1647
+ stroke="currentColor"
1648
+ stroke-width="1.9"
1649
+ stroke-linecap="round"
1650
+ stroke-linejoin="round"
1651
+ >
1652
+ <path
1653
+ d=${r?`M8.75 3.5 5.25 7l3.5 3.5`:`M5.25 3.5 8.75 7l-3.5 3.5`}
1654
+ />
1655
+ </svg>
1656
+ </button>
1657
+ `}_renderAttachmentActions(e,t=c){let n=this._attachmentOrder.length,r=this._attachmentOrder.indexOf(e),i=n>1&&r!==-1;return!i&&t===c?c:o`
1658
+ <div class="compose-attachment-actions">
1659
+ ${i?o`
1660
+ <div class="compose-attachment-move-group">
1661
+ ${this._renderAttachmentMoveButton(e,-1,r===0)}
1662
+ ${this._renderAttachmentMoveButton(e,1,r===n-1)}
1663
+ </div>
1664
+ `:c}
1665
+ ${t}
1666
+ </div>
1667
+ `}_renderAttachedTextCard(e,t){return o`
1668
+ <div class="compose-attachment" data-attachment-id=${e.clientId}>
1669
+ <div
1670
+ class="compose-attachment-thumb compose-attachment-sortable"
1671
+ data-attachment-sortable
1672
+ tabindex="0"
1673
+ @click=${()=>this._maybeEditAttachedText(t)}
1674
+ @keydown=${n=>this._handleAttachmentKeydown(e.clientId,n,()=>this._maybeEditAttachedText(t))}
1675
+ >
1676
+ <div class="compose-attachment-text-card">
1677
+ <div class="compose-attachment-file-icon">
1678
+ ${this._renderFileIcon(`text/html; charset=utf-8`,20)}
1679
+ </div>
1680
+ <span class="compose-attachment-text-summary">${e.summary}</span>
1681
+ ${e.bodyJson?o`<span class="compose-attachment-file-size"
1682
+ >${this._formatChars(this._extractPlainText(e.bodyJson).length)}</span
1683
+ >`:c}
1684
+ </div>
1685
+ ${this._renderAttachmentRemoveButton(e=>{e.stopPropagation(),this._removeAttachedText(t)})}
1686
+ </div>
1687
+ ${this._renderAttachmentActions(e.clientId)}
1688
+ </div>
1689
+ `}_renderMediaAttachment(e,t){let n=this._getCategory(e),r=n!==`image`&&n!==`video`,i=n===`video`?`video`:`image`,a=this._hasFailedAttachmentPreview(e.clientId);return o`
1690
+ <div class="compose-attachment" data-attachment-id=${e.clientId}>
1691
+ ${r?o`
1692
+ <div class="compose-attachment-thumb">
1693
+ <div
1694
+ class="compose-attachment-sortable"
1695
+ data-attachment-sortable
1696
+ tabindex="0"
1697
+ @keydown=${t=>this._handleAttachmentKeydown(e.clientId,t)}
1698
+ >
1699
+ ${this._renderAttachmentPreview(e)}
1700
+ </div>
1701
+ ${this._renderAttachmentOverlay(e,t)}
1702
+ </div>
1703
+ `:o`
1704
+ <div class="compose-attachment-thumb">
1705
+ <div
1706
+ class="compose-attachment-sortable"
1707
+ data-attachment-sortable
1708
+ tabindex="0"
1709
+ @keydown=${t=>this._handleAttachmentKeydown(e.clientId,t)}
1710
+ >
1711
+ ${a?this._renderAttachmentPreviewFallback(i):n===`video`?o`
1712
+ <video
1713
+ src=${e.previewUrl}
1714
+ poster=${e.posterUrl??c}
1715
+ class="compose-attachment-img"
1716
+ preload="metadata"
1717
+ .playsInline=${!0}
1718
+ .muted=${!0}
1719
+ @loadeddata=${()=>this._setAttachmentPreviewFailure(e.clientId,!1)}
1720
+ @error=${()=>this._setAttachmentPreviewFailure(e.clientId,!0)}
1721
+ ></video>
1722
+ <div class="compose-attachment-play-icon">
1723
+ <svg
1724
+ width="24"
1725
+ height="24"
1726
+ viewBox="0 0 24 24"
1727
+ fill="white"
1728
+ >
1729
+ <path d="M8 5v14l11-7z" />
1730
+ </svg>
1731
+ </div>
1732
+ `:e.status===`processing`?o`
1733
+ <div class="compose-attachment-processing">
1734
+ <svg
1735
+ class="animate-spin size-5"
1736
+ viewBox="0 0 24 24"
1737
+ fill="none"
1738
+ stroke="currentColor"
1739
+ stroke-width="2"
1740
+ >
1741
+ <path
1742
+ d="M12 2a10 10 0 1 0 10 10"
1743
+ stroke-linecap="round"
1744
+ />
1745
+ </svg>
1746
+ </div>
1747
+ `:o`
1748
+ <img
1749
+ src=${e.previewUrl}
1750
+ alt=""
1751
+ class="compose-attachment-img"
1752
+ @load=${()=>this._setAttachmentPreviewFailure(e.clientId,!1)}
1753
+ @error=${()=>this._setAttachmentPreviewFailure(e.clientId,!0)}
1754
+ />
1755
+ `}
1756
+ </div>
1757
+ ${this._renderAttachmentOverlay(e,t)}
1758
+ </div>
1759
+ `}
1760
+ ${this._renderAttachmentActions(e.clientId,n===`image`?o`
1761
+ <button
1762
+ type="button"
1763
+ class=${w({"compose-attachment-alt":!0,"compose-attachment-alt-set":e.alt.length>0})}
1764
+ @click=${()=>this._openAltPanel(t)}
1765
+ >
1766
+ ${e.alt.length>0?`ALT`:`+ ALT`}
1767
+ </button>
1768
+ `:c)}
1769
+ </div>
1770
+ `}_renderAttachments(){return this._attachments.length===0&&this._attachedTexts.length===0?c:o`
1771
+ <div class="compose-attachments" data-attachment-list>
1772
+ ${this._attachmentOrder.map(e=>{let t=this._attachments.findIndex(t=>t.clientId===e);if(t!==-1)return this._renderMediaAttachment(this._attachments[t],t);let n=this._attachedTexts.findIndex(t=>t.clientId===e);return n===-1?c:this._renderAttachedTextCard(this._attachedTexts[n],n)})}
1773
+ </div>
1774
+ `}_renderAttachmentDock(){return this._attachments.length===0&&this._attachedTexts.length===0?c:o`
1775
+ <div class="compose-attachments-dock">${this._renderAttachments()}</div>
1776
+ `}_renderToolsRow(){let e=this._attachedTexts.length>0;return o`
1777
+ <div class="compose-tools-row">
1778
+ <button
1779
+ type="button"
1780
+ class=${w({"compose-tool-btn":!0,"compose-tool-btn-add":this._attachments.length>0})}
1781
+ title=${this._attachments.length>0?``:this.labels.media}
1782
+ @click=${()=>this._openFilePicker()}
1783
+ >
1784
+ ${q(K.media)}
1785
+ ${this._attachments.length>0?o`<span class="compose-tool-label"
1786
+ >${this.labels.addMore}</span
1787
+ >`:c}
1788
+ </button>
1789
+
1790
+ <button
1791
+ type="button"
1792
+ class=${w({"compose-tool-btn":!0,"compose-tool-btn-add":e})}
1793
+ title=${e?``:this.labels.attachedText}
1794
+ @click=${()=>this._openAttachedText()}
1795
+ >
1796
+ ${q(K.attachedText)}
1797
+ ${e?o`<span class="compose-tool-label"
1798
+ >${this.labels.addMore}</span
1799
+ >`:c}
1800
+ </button>
1801
+
1802
+ <button
1803
+ type="button"
1804
+ class=${w({"compose-tool-btn":!0,"compose-emoji-btn":!0,"compose-tool-btn-active":this._showEmojiPicker})}
1805
+ title=${this.labels.emoji}
1806
+ aria-pressed=${this._showEmojiPicker?`true`:`false`}
1807
+ @click=${()=>this._toggleEmojiPicker()}
1808
+ >
1809
+ ${q(K.emoji)}
1810
+ </button>
1811
+
1812
+ <div class="compose-tool-gap"></div>
1813
+
1814
+ <button
1815
+ type="button"
1816
+ class=${w({"compose-tool-btn":!0,"compose-tool-btn-active":this._showRating})}
1817
+ title=${this.labels.rate}
1818
+ aria-pressed=${this._showRating?`true`:`false`}
1819
+ @click=${()=>{let e=!this._showRating;this._showRating=e,e&&this.updateComplete.then(()=>{this.querySelector(`.compose-star-rating`)?.scrollIntoView({block:`nearest`,behavior:`smooth`})})}}
1820
+ >
1821
+ ${q(K.rate)}
1822
+ </button>
1823
+
1824
+ ${this.format===`note`?o`
1825
+ <button
1826
+ type="button"
1827
+ class=${w({"compose-tool-btn":!0,"compose-tool-btn-active":this._showTitle})}
1828
+ title=${this.labels.title}
1829
+ aria-pressed=${this._showTitle?`true`:`false`}
1830
+ @click=${()=>{let e=!this._showTitle;this._showTitle=e,this.dispatchEvent(new CustomEvent(`jant:title-toggle`,{bubbles:!0,detail:{showTitle:e}})),e&&this.updateComplete.then(()=>{this.querySelector(`.compose-note-title`)?.focus()})}}
1831
+ >
1832
+ ${q(K.title)}
1833
+ </button>
1834
+ `:c}
1835
+ ${this.format===`note`?o`
1836
+ <div class="compose-tool-view-group">
1837
+ <button
1838
+ type="button"
1839
+ class="compose-tool-btn compose-tool-btn-view"
1840
+ title=${this.labels.fullscreen}
1841
+ aria-label=${this.labels.fullscreen}
1842
+ @click=${()=>this.openFullscreen()}
1843
+ >
1844
+ ${q(K.fullscreen)}
1845
+ </button>
1846
+ </div>
1847
+ `:c}
1848
+ </div>
1849
+ `}_renderFormatHeader(){let e={note:this.labels.note,link:this.labels.link,quote:this.labels.quote};return o`
1850
+ <div class="compose-thread-post-header">
1851
+ <div class="compose-segmented">
1852
+ <!-- No sliding indicator: the items size to their labels now, so a
1853
+ thirds-based pill would not line up. The active item carries its
1854
+ own background instead. -->
1855
+ ${[`note`,`link`,`quote`].map(t=>o`
1856
+ <button
1857
+ type="button"
1858
+ class=${w({"compose-segmented-item":!0,"compose-segmented-item-active":this.format===t})}
1859
+ @click=${()=>{this.format!==t&&this.dispatchEvent(new CustomEvent(`jant:format-change`,{bubbles:!0,detail:{format:t}}))}}
1860
+ >
1861
+ ${e[t]}
1862
+ </button>
1863
+ `)}
1864
+ </div>
1865
+ ${this.positionLabel?o`<span class="compose-post-position"
1866
+ >${this.positionLabel}</span
1867
+ >`:c}
1868
+ ${this.badgeLabel?o`<span class="compose-post-position compose-post-badge"
1869
+ >${this.badgeLabel}</span
1870
+ >`:c}
1871
+ ${this.headerExtra??c}
1872
+ ${this.removable?o`<button
1873
+ type="button"
1874
+ class="compose-thread-post-remove"
1875
+ title="Remove post"
1876
+ @click=${()=>{this.dispatchEvent(new CustomEvent(`jant:thread-remove`,{bubbles:!0}))}}
1877
+ >
1878
+ <svg
1879
+ width="14"
1880
+ height="14"
1881
+ viewBox="0 0 16 16"
1882
+ fill="none"
1883
+ stroke="currentColor"
1884
+ stroke-width="1.8"
1885
+ stroke-linecap="round"
1886
+ aria-hidden="true"
1887
+ >
1888
+ ${b(`<path d="M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5"/>`)}
1889
+ </svg>
1890
+ </button>`:c}
1891
+ </div>
1892
+ `}openFullscreen(){if(this.format!==`note`)return;let e=this.getEditorState();this.dispatchEvent(new CustomEvent(`jant:fullscreen-open`,{bubbles:!0,detail:{...e,labels:this.labels}}))}render(){return o`
1893
+ ${this._renderFormatHeader()}
1894
+ <section
1895
+ class="compose-body"
1896
+ @mousedown=${this._recordBodyPress}
1897
+ @mouseup=${this._recordBodyRelease}
1898
+ @click=${this._focusBodyFromBlankSpace}
1899
+ >
1900
+ ${this.format===`note`?this._renderNoteFields():this.format===`link`?this._renderLinkFields():this._renderQuoteFields()}
1901
+ </section>
1902
+ ${this._renderAttachmentDock()} ${this._renderStarRating()}
1903
+ ${this._renderToolsRow()}
1904
+ `}};customElements.define(`jant-compose-editor`,Wt);var Gt=`.tiptap-slash-menu, .tiptap-link-input, .tiptap-table-size-picker, .tiptap-table-options:not([hidden])`,Kt=class extends u{static properties={labels:{type:Object},_open:{state:!0},_title:{state:!0},_showTitle:{state:!0},_replyContext:{state:!0},_replyExpanded:{state:!0}};_editor=null;_content=null;_selection=null;_editorIndex=0;_fileInput=null;#e=new Set;createRenderRoot(){return this}constructor(){super(),this.labels={},this._open=!1,this._title=``,this._showTitle=!0,this._replyContext=null,this._replyExpanded=!1}connectedCallback(){super.connectedCallback(),document.addEventListener(`jant:fullscreen-open`,this._onOpen),document.addEventListener(`jant:slash-image`,this._onSlashImage),document.addEventListener(`keydown`,this._onDocumentKeydown,!0)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(`jant:fullscreen-open`,this._onOpen),document.removeEventListener(`jant:slash-image`,this._onSlashImage),document.removeEventListener(`keydown`,this._onDocumentKeydown,!0),this._fileInput?.remove(),this._destroyEditor()}_onSlashImage=()=>{this._open&&this._editor&&this._triggerImagePicker()};_triggerImagePicker(){this._fileInput||(this._fileInput=document.createElement(`input`),this._fileInput.type=`file`,this._fileInput.accept=`image/*`,this._fileInput.style.display=`none`,this._fileInput.addEventListener(`change`,()=>{let e=this._fileInput?.files?.[0];e&&this._editor&&this._uploadAndInsertImage(e),this._fileInput&&(this._fileInput.value=``)}),document.body.appendChild(this._fileInput)),this._fileInput.click()}_uploadAndInsertImage(e){let t=this._editor;if(!t)return Promise.resolve();let n=ie(t,e).finally(()=>{this.#e.delete(n)});return this.#e.add(n),n}_onOpen=e=>{this._content=e.detail.json,this._selection=e.detail.selection??null,this._title=e.detail.title,e.detail.labels&&(this.labels=e.detail.labels),this._showTitle=e.detail.showTitle||e.detail.title.trim().length>0,this._replyContext=e.detail.replyContext??null,this._replyExpanded=e.detail.replyContext?.expanded??!1,this._editorIndex=e.detail.editorIndex??0,this._open=!0,this.updateComplete.then(()=>{let e=this.querySelector(`.compose-fullscreen-dialog`);e&&!e.open&&e.showModal(),this._initEditor()})};_initEditor(){let e=this.querySelector(`.compose-fullscreen .compose-tiptap-body`);if(!e||this._editor)return;this._editor=ue({element:e,placeholder:this.labels.bodyPlaceholder??`Write something…`,content:this._content,toolbarMode:`compose`,onUpdate:e=>{this._content=e},pasteMedia:{shouldInsertInline:e=>e.type.startsWith(`image/`),uploadInlineImage:e=>this._uploadAndInsertImage(e)},imageNodeLabels:Vt(this.labels),tableControlLabels:this.labels.tableControls,highlightLabel:this.labels.highlight});let t=this._selection;if(t){let e=this._editor.state.doc.content.size,n=Math.max(1,Math.min(t.from,e)),r=Math.max(n,Math.min(t.to,e));this._selection={from:n,to:r},this._editor.chain().focus().setTextSelection({from:n,to:r}).run();return}this._editor.commands.focus()}_destroyEditor(){this.#e.clear(),this._editor?.destroy(),this._editor=null}_onDialogCancel=e=>{e.preventDefault(),this._close()};_onDocumentKeydown=e=>{if(this._open&&!(e.isComposing||e.keyCode===229)){if((e.metaKey||e.ctrlKey)&&e.key===`Enter`){e.preventDefault(),e.stopPropagation(),this._publish();return}e.key===`Escape`&&(this._hasActiveEscapeOverlay()||(e.preventDefault(),e.stopPropagation(),this._close()))}};_hasActiveEscapeOverlay(){let e=this.querySelector(`.compose-fullscreen-dialog[open]`);return e?Array.from(e.querySelectorAll(Gt)).some(e=>getComputedStyle(e).display!==`none`):!1}_finishClose(e){let t=this._editor?.getJSON()??this._content,n=this._editor?{from:this._editor.state.selection.from,to:this._editor.state.selection.to}:this._selection;this._destroyEditor(),this.querySelector(`.compose-fullscreen-dialog`)?.close(),this._open=!1,this._replyContext=null,document.dispatchEvent(new CustomEvent(`jant:fullscreen-close`,{bubbles:!0,detail:{json:t,title:this._title,showTitle:this._showTitle||this._title.trim().length>0,selection:n,replyExpanded:this._replyExpanded,intent:e,editorIndex:this._editorIndex}}))}_close(){this._open&&this._finishClose()}_publish(){this._open&&this._finishClose(`publish`)}_revealTitle(){this._showTitle=!0,this.updateComplete.then(()=>{this.querySelector(`.compose-fullscreen-title`)?.focus()})}_renderTitleField(e){let t=w({"compose-fullscreen-title":!0,"compose-fullscreen-title-reply":e===`reply`}),n=w({"compose-fullscreen-title-placeholder":!0,"compose-fullscreen-title-placeholder-reply":e===`reply`});return this._showTitle?o`
1905
+ <div class="compose-fullscreen-title-shell">
1906
+ <input
1907
+ type="text"
1908
+ .value=${this._title}
1909
+ @input=${e=>{this._title=e.target.value}}
1910
+ @keydown=${e=>{e.isComposing||e.keyCode===229||e.key===`Enter`&&(e.preventDefault(),this._editor?.commands.focus(`start`))}}
1911
+ class=${t}
1912
+ placeholder=${this.labels.titlePlaceholder??`Title`}
1913
+ />
1914
+ </div>
1915
+ `:o`
1916
+ <button
1917
+ type="button"
1918
+ class=${n}
1919
+ @click=${()=>this._revealTitle()}
1920
+ >
1921
+ ${this.labels.titlePlaceholder||this.labels.title||`Title`}
1922
+ </button>
1923
+ `}render(){if(!this._open)return c;let e=this._replyContext,t=e=>o`
1924
+ <div
1925
+ class=${w({"compose-fullscreen-editor-surface":!0,"compose-fullscreen-editor-surface-reply":e===`reply`})}
1926
+ >
1927
+ ${this._renderTitleField(e)}
1928
+ <div class="compose-tiptap-body"></div>
1929
+ </div>
1930
+ `;return o`
1931
+ <dialog
1932
+ class="compose-fullscreen-dialog"
1933
+ aria-label=${this.labels.fullscreen||this.labels.note||`Fullscreen`}
1934
+ @cancel=${this._onDialogCancel}
1935
+ >
1936
+ <div class="compose-fullscreen">
1937
+ <header class="compose-fullscreen-toolbar">
1938
+ <div class="compose-fullscreen-toolbar-inner">
1939
+ <button
1940
+ type="button"
1941
+ class="compose-fullscreen-done"
1942
+ title=${this.labels.exitFullscreen||`Exit fullscreen`}
1943
+ aria-label=${this.labels.exitFullscreen||`Exit fullscreen`}
1944
+ @click=${()=>void this._close()}
1945
+ >
1946
+ <svg
1947
+ width="18"
1948
+ height="18"
1949
+ viewBox="0 0 18 18"
1950
+ fill="none"
1951
+ stroke="currentColor"
1952
+ stroke-width="1.48"
1953
+ stroke-linecap="round"
1954
+ stroke-linejoin="round"
1955
+ >
1956
+ <path d="M3 6.85h2.85V4" />
1957
+ <path d="M15 6.85h-2.85V4" />
1958
+ <path d="M6.85 15V12.15H4" />
1959
+ <path d="M11.15 15V12.15H14" />
1960
+ </svg>
1961
+ </button>
1962
+ </div>
1963
+ </header>
1964
+ <div class="compose-fullscreen-content">
1965
+ <div class="compose-fullscreen-inner">
1966
+ ${e?o`
1967
+ <div
1968
+ class="compose-thread-layout compose-fullscreen-thread-layout"
1969
+ >
1970
+ <div class="compose-reply-row">
1971
+ <div class="compose-thread-dot"></div>
1972
+ <div
1973
+ class=${w({"compose-reply-context":!0,expanded:this._replyExpanded})}
1974
+ >
1975
+ <div class="compose-reply-context-body">
1976
+ ${f(e.contentHtml)}
1977
+ </div>
1978
+ ${this._replyExpanded?c:o`<div class="compose-reply-fade"></div>`}
1979
+ </div>
1980
+ </div>
1981
+ <div class="compose-reply-meta">
1982
+ ${e.dateText?o`<span>${e.dateText}</span
1983
+ ><span>·</span>`:c}
1984
+ <button
1985
+ type="button"
1986
+ class="compose-reply-toggle"
1987
+ @click=${()=>{this._replyExpanded=!this._replyExpanded}}
1988
+ >
1989
+ ${this._replyExpanded?this.labels.showLess:this.labels.showMore}
1990
+ </button>
1991
+ </div>
1992
+ <div
1993
+ class="compose-editor-row compose-fullscreen-editor-row is-current"
1994
+ >
1995
+ <div class="compose-thread-dot"></div>
1996
+ ${t(`reply`)}
1997
+ </div>
1998
+ </div>
1999
+ `:t(`note`)}
2000
+ </div>
2001
+ </div>
2002
+ </div>
2003
+ </dialog>
2004
+ `}};customElements.define(`jant-compose-fullscreen`,Kt);var qt;function J(){return qt??=p(()=>import(`./chunks/mediabunny-DRaCQ1r-.js`).then(e=>e.t),__vite__mapDeps([2,1])),qt}function Jt(){return typeof AudioEncoder<`u`}async function Yt(e,t){let{Input:n,Output:r,Mp4OutputFormat:i,BufferTarget:a,BlobSource:o,Conversion:s,ALL_FORMATS:c}=await J(),l=new n({source:new o(e),formats:c}),u=new a,d=new r({format:new i({fastStart:`in-memory`}),target:u});try{let n=await s.init({input:l,output:d,video:{discard:!0},audio:{codec:`aac`}});t&&(n.onProgress=t),await n.execute();let r=u.buffer;if(!r)throw Error(`Audio processing produced no output`);let i=e.name.replace(/\.[^.]+$/,``);return{file:new File([r],`${i}.m4a`,{type:`audio/mp4`})}}finally{l.dispose()}}var Xt={isSupported:Jt,processToFile:Yt},Zt=new Set([`moov`,`trak`]);function Qt(e){return 12+(e===1?32:20)+8+2}function $t(e){let t=new DataView(e),n=(e,r)=>{let i=e;for(;i+8<=r;){let e=t.getUint32(i),a=String.fromCharCode(t.getUint8(i+4),t.getUint8(i+5),t.getUint8(i+6),t.getUint8(i+7));if(e===0&&(e=r-i),e<8||i+e>r)break;if(a===`tkhd`){let n=t.getUint8(i+8),r=i+Qt(n);r+2<=i+e&&t.getUint16(r)!==0&&t.setUint16(r,0)}else Zt.has(a)&&n(i+8,i+e);i+=e}};n(0,e.byteLength)}var en=1920,tn=1080,nn=640,rn=32,an=79e5,on=2073600,sn=.95,cn={avc:1,hevc:1/.6,vp9:1/.6,av1:1/.4,vp8:1/1.2};function ln(e,t){let n=an*(t/on)**sn;if(!e.bitrate||!e.pixels)return Math.round(n);let r=(e.codec&&cn[e.codec])??1,i=e.bitrate*r*(t/e.pixels)**sn;return Math.round(Math.min(n,i))}function un(){return typeof VideoEncoder<`u`}function dn(e,t){console.warn(`[jant] video probe: ${e} failed`,t)}async function Y(e,t){try{return await t()}catch(t){dn(e,t);return}}function fn(e,t,n){let r=document.createElement(`canvas`);r.width=t,r.height=n;let i=r.getContext(`2d`);return i?(i.drawImage(e,0,0,t,n),{canvas:r,ctx:i}):null}async function pn(e,t){let{CanvasSink:r}=await J(),i=await Y(`capture frame`,()=>new r(e).getCanvas(n(t)));if(!i)return{};let a=i.canvas,o=a.width,s=a.height,c=Math.min(nn/o,1),l=fn(a,Math.round(o*c),Math.round(s*c)),u=l?await Y(`encode poster`,()=>new Promise(e=>{l.canvas.toBlob(t=>e(t??void 0),`image/webp`,.8)})):void 0,d=Math.min(rn/o,rn/s,1),f=Math.max(Math.round(o*d),1),p=Math.max(Math.round(s*d),1),m=fn(a,f,p);return{poster:u,blurhash:m?await Y(`encode blurhash`,async()=>ae(m.ctx.getImageData(0,0,f,p).data,f,p,4,3)):void 0}}async function mn(e){let{Input:t,BlobSource:n,ALL_FORMATS:i}=await J(),a=new t({source:new n(e),formats:i});try{let e=await Y(`open video track`,()=>a.getPrimaryVideoTrack());if(!e)return{};let t=await Y(`read codec`,()=>e.getCodec()),n=await Y(`compute bitrate`,async()=>(await e.computePacketStats()).averageBitrate),i=await Y(`compute duration`,()=>a.computeDuration());return{sourceWidth:e.displayWidth,sourceHeight:e.displayHeight,rotation:e.rotation,durationSeconds:i===void 0?void 0:r(i),videoCodec:t,videoBitrate:n,...await pn(e,i)}}finally{a.dispose()}}async function hn(e){if(typeof VideoDecoder>`u`)return;let{Input:t,UrlSource:n,ALL_FORMATS:r}=await J(),i=new t({source:new n(e),formats:r});try{let e=await Y(`open video track`,()=>i.getPrimaryVideoTrack());return e?(await pn(e,await Y(`compute duration`,()=>i.computeDuration()))).poster:void 0}finally{i.dispose()}}function gn(e,t){let{width:n,height:r}=e,i=n||t.maxLongEdge,a=r||t.maxShortEdge,o=!1;if(n&&r){let e=Math.max(n,r),s=Math.min(n,r),c=Math.min(t.maxLongEdge/e,t.maxShortEdge/s,1);o=c<1,o&&(i=Math.round(n*c),a=Math.round(r*c),i+=i%2,a+=a%2)}let s=o||e.videoCodec!==`avc`;return{needsResize:o,width:i,height:a,videoNeedsReencode:s,videoBitrate:s?ln({pixels:(n??0)*(r??0),bitrate:e.videoBitrate,codec:e.videoCodec},i*a):void 0}}async function _n(e,t){let{poster:n,blurhash:r,sourceWidth:i,sourceHeight:a,rotation:o,durationSeconds:s,videoCodec:c,videoBitrate:l}=await mn(e),{needsResize:u,width:d,height:f,videoBitrate:p}=gn({width:i,height:a,videoCodec:c,videoBitrate:l},{maxLongEdge:en,maxShortEdge:tn}),{Input:m,Output:h,Mp4OutputFormat:g,BufferTarget:_,BlobSource:v,Conversion:y,Quality:b,ALL_FORMATS:x}=await J(),S=new m({source:new v(e),formats:x}),C=new _,w=new h({format:new g({fastStart:`in-memory`}),target:C});try{let i=await y.init({input:S,output:w,video:{codec:`avc`,...u?{width:d,height:f,fit:`contain`}:{},...p===void 0?{}:{quality:new b({bitrate:p})}},audio:{codec:`aac`}});t&&(i.onProgress=t),await i.execute();let a=C.buffer;if(!a)throw Error(`Video processing produced no output`);$t(a);let c=e.name.replace(/\.[^.]+$/,``),l=new File([a],`${c}.mp4`,{type:`video/mp4`}),m=await xn(l),h=Math.abs(m.width-d)<=2&&Math.abs(m.height-f)<=2;return o&&!h&&(bn(a),l=new File([a],`${c}.mp4`,{type:`video/mp4`}),m=await xn(l)),{file:l,width:m.width,height:m.height,durationSeconds:s,poster:n,blurhash:r}}finally{S.dispose()}}var vn=[65536,0,0,0,65536,0,0,0,1073741824];function yn(e,t,n,r){let i=t;for(;i+8<=n;){let t=e.getUint32(i),a=String.fromCharCode(e.getUint8(i+4),e.getUint8(i+5),e.getUint8(i+6),e.getUint8(i+7));if(t===0&&(t=n-i),t<8||i+t>n)break;r(i,t,a),(a===`moov`||a===`trak`||a===`mdia`||a===`edts`)&&yn(e,i+8,i+t,r),i+=t}}function bn(e){let t=new DataView(e);yn(t,0,e.byteLength,(n,r,i)=>{if(i!==`tkhd`)return;let a=n+8,o=a+(t.getUint8(a)===0?40:52);if(o+36>e.byteLength)return;let s=!0;for(let e=0;e<9;e++)if(t.getInt32(o+e*4)!==vn[e]){s=!1;break}if(!s)for(let e=0;e<9;e++)t.setInt32(o+e*4,vn[e])})}function xn(e){return new Promise((t,n)=>{let r=URL.createObjectURL(e),i=document.createElement(`video`);i.preload=`metadata`,i.onloadedmetadata=()=>{URL.revokeObjectURL(r),t({width:i.videoWidth,height:i.videoHeight})},i.onerror=()=>{URL.revokeObjectURL(r),n(Error(`Failed to probe transcoded video dimensions`))},i.src=r})}var Sn={isSupported:un,processToFile:_n,extractPosterFromUrl:hn};async function Cn(e){let t=await e.arrayBuffer(),n=new AudioContext;try{let e=(await n.decodeAudioData(t)).getChannelData(0),r=Math.max(1,Math.floor(e.length/100)),i=Array(100);for(let t=0;t<100;t++){let n=0,a=t*r,o=Math.min(a+r,e.length);for(let t=a;t<o;t++){let r=Math.abs(e[t]);r>n&&(n=r)}i[t]=n}let a=0;for(let e of i)e>a&&(a=e);if(a>0)for(let e=0;e<100;e++)i[e]=Math.round(i[e]/a*100)/100;return JSON.stringify(i)}finally{await n.close()}}async function wn(e,t,n=`POST`){try{return await fetch(e,{method:n,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:t})}catch{return null}}async function Tn(e,t){if(!e)return t?.publishFailedOffline??`Couldn't reach the server. Try again.`;let n=await x(e);return C(n,`error`)??t?.publishFailed??`Couldn't publish. Try again.`}function En(e){try{return N(JSON.parse(e))}catch{return!1}}function Dn(e){return e instanceof globalThis.Element?e.closest(`jant-compose-editor`):null}function On(e){return e instanceof globalThis.Element?e.closest(`jant-compose-dialog`):null}async function kn(e){return!e.replyRefreshKind||!e.replyRefreshId?!1:e.replyRefreshKind===`timeline-item`?m(e.replyThreadRootId??e.replyRefreshId):e.replyRefreshKind===`post-view`?y(e.replyRefreshId):_(e.replyRefreshId)}var An=new Map,jn=new Set,X=new Map,Z=null;function Q(){if(!Z)return;let{clientIds:e,baseMsg:t}=Z;if(e.length===0)return;let n=0,r=0;for(let t of e){let e=X.get(t)??0;n+=Math.min(1,Math.max(0,e)),e>=1&&(r+=1)}let i=e.length,o=Math.floor(n/i*100),s=Math.min(r+1,i),c=i===1?`${t} ${o}%`:`${t} ${o}% ${s}/${i}`;a(`compose-deferred`,c)}var $=new Map;function Mn(e,t){if(!e||e.isConnected)return e;let n=document.querySelectorAll(`jant-compose-editor`);for(let e of n)if(e.hasAttachment(t))return e;return e}function Nn(e){return new Promise(t=>{let n=setTimeout(()=>{a(),t(null)},3e3),r=URL.createObjectURL(e),i=document.createElement(`video`);i.muted=!0,i.playsInline=!0,i.preload=`auto`;function a(){clearTimeout(n),i.removeAttribute(`src`),i.load(),URL.revokeObjectURL(r)}i.onloadeddata=()=>{try{let e=i.videoWidth,n=i.videoHeight;if(!e||!n){a(),t(null);return}let r=Math.min(640/e,1),o=Math.round(e*r),s=Math.round(n*r),c=document.createElement(`canvas`);c.width=o,c.height=s;let l=c.getContext(`2d`);if(!l){a(),t(null);return}l.drawImage(i,0,0,o,s),c.toBlob(e=>{a(),t(e)},`image/webp`,.6)}catch{a(),t(null)}},i.onerror=()=>{a(),t(null)},i.src=r})}var Pn=12;async function Fn(e){let t=await e.slice(0,Pn).arrayBuffer();return Xe(new Uint8Array(t))===`image/heic`}async function In(e,t,n){let r=()=>Mn(n,t),i=e.type,a=e.name;try{let n,o,s,c,l,u,f;if(i.startsWith(`video/`)){if(!Sn.isSupported())return r()?.updateAttachmentStatus(t,`error`,null,`Your browser doesn't support video processing. Use Chrome or Edge to upload videos.`),null;let i=Nn(e).then(e=>(e&&r()?.updateAttachmentPoster(t,e),e)).catch(()=>null);r()?.updateAttachmentStatus(t,`processing`,null,null);let a=await Sn.processToFile(e,e=>{r()?.updateAttachmentProgress(t,e)});n=a.file,e=null,o=a.width,s=a.height,c=a.durationSeconds,l=a.blurhash,f=a.poster??await i??void 0,f&&r()?.updateAttachmentPoster(t,f)}else if(i.startsWith(`audio/`)){if(!Xt.isSupported())return r()?.updateAttachmentStatus(t,`error`,null,`Your browser doesn't support audio processing. Use Chrome or Edge to upload audio.`),null;try{u=await Cn(e)}catch{}r()?.updateAttachmentStatus(t,`processing`,null,null),n=(await Xt.processToFile(e,e=>{r()?.updateAttachmentProgress(t,e)})).file,e=null}else if(i.startsWith(`image/`)||/\.heic$/i.test(a)||/\.heif$/i.test(a)){let i=e;try{if(await Fn(i)){let{heicTo:e}=await p(async()=>{let{heicTo:e}=await import(`./chunks/heic-to-CuP2Qlsw.js`);return{heicTo:e}},[]);r()?.updateAttachmentStatus(t,`processing`,null,null);let n=await e({blob:i,type:`image/jpeg`,quality:.92});i=new File([n],a.replace(/\.heic$/i,`.jpg`),{type:`image/jpeg`}),r()?.updateAttachmentPreview(t,i)}let c=await oe.processToFile(i);n=c.file,o=c.width,s=c.height,l=c.blurhash,e=null,i=null}catch{return r()?.removeAttachment(t),d(`Image format not supported.`,`error`),null}}else n=e;r()?.updateAttachmentStatus(t,`uploading`,null,null);let m,h;if(F(i)===`text`)try{let e=await n.text(),t=e.replace(/\s+/g,` `).trim();h=e.length,m=t.length<=100?t:t.slice(0,100)+`…`}catch{}X.set(t,0),Q();let g=await le(n,{width:o,height:s,durationSeconds:c,blurhash:l,waveform:u,poster:f,summary:m,chars:h},e=>{r()?.updateAttachmentProgress(t,e),X.set(t,e),Q()});return X.set(t,1),Q(),r()?.updateAttachmentStatus(t,`done`,g.id,null,g.url),$.set(t,g),g.id}catch(e){X.delete(t),Q();let i=e instanceof Error?e.message:`Upload failed`;return r()?.updateAttachmentStatus(t,`error`,null,i),n||d(i,`error`),null}}document.addEventListener(`jant:attachment-removed`,e=>{let{clientId:n,mediaId:r,persisted:i}=e.detail;$.delete(n),!i&&(r?fetch(t(`/api/media/${r}`),{method:`DELETE`}).catch(()=>{}):jn.add(n))}),document.addEventListener(`jant:files-selected`,e=>{let n=e,r=Dn(n.target);for(let{file:e,clientId:i}of n.detail.files){let n=In(e,i,r).then(e=>jn.has(i)?(jn.delete(i),e&&fetch(t(`/api/media/${e}`),{method:`DELETE`}).catch(()=>{}),null):e);An.set(i,n),n.finally(()=>An.delete(i))}});var Ln=new Set;async function Rn(e,n){try{let r=await Sn.extractPosterFromUrl(e.url);if(!r)return;let i=await fetch(t(`/api/media/${e.mediaId}/poster`),{method:`PUT`,headers:{"Content-Type":r.type||`image/webp`},body:r});if(!i.ok)throw Error(await S(i,`Failed to upload poster`));Mn(n,e.clientId)?.updateAttachmentPoster(e.clientId,r)}catch(e){console.warn(`[jant] poster for an uploaded video failed`,e)}}document.addEventListener(`jant:video-posters-missing`,e=>{let t=e,n=Dn(t.target);for(let e of t.detail.attachments)Ln.has(e.mediaId)||(Ln.add(e.mediaId),Rn(e,n))});function zn(e,t){let n=e.format===`quote`,r=e.format===`link`,i=!!e.editPostId,a=e=>e||void 0,o=e=>e||null;return{format:e.format,title:n?void 0:i?o(e.title):a(e.title),body:i?o(e.body):a(e.body),url:r?i?o(e.url):a(e.url):i?null:void 0,sourceName:n?i?o(e.quoteAuthor):a(e.quoteAuthor):void 0,sourceUrl:n?i?o(e.url):a(e.url):void 0,quoteText:n?i?o(e.quoteText):a(e.quoteText):i?null:void 0,slug:e.slug||void 0,status:e.status,publishedAt:e.status===`published`?e.publishedAt:void 0,visibility:e.visibility||void 0,rating:i?e.rating>0?e.rating:null:e.rating||void 0,collectionIds:e.replyToId?void 0:e.collectionIds,attachments:i||t.length>0?t:void 0,replyToId:e.replyToId||void 0,quietReply:e.quietReply||void 0,language:e.language||void 0,translationOfId:i?void 0:e.translationOfId||void 0}}function Bn(e){return JSON.stringify(e.bodyJson)!==JSON.stringify(e.originalBodyJson??null)}function Vn(e,t){let n=[];for(let r of e.attachments){if(r.type===`media`){let e=r.mediaId??t.get(r.clientId)??$.get(r.clientId)?.id;if(!e)continue;n.push({type:`media`,mediaId:e,alt:r.alt});continue}if(r.mediaId&&!Bn(r)){n.push({type:`media`,mediaId:r.mediaId});continue}n.push({type:`text`,contentFormat:`markdown`,content:se(JSON.stringify(r.bodyJson)),summary:r.summary})}return n}document.addEventListener(`jant:compose-submit-deferred`,async e=>{let n=e,r=n.detail,a=On(n.target)??document.querySelector(`jant-compose-dialog`),o=!!a?.pageMode,c=!!document.querySelector(`[data-preview-status]`),u=a?.labels,f=u?.uploading??`Uploading...`,p=u?.publishing??`Publishing...`,h=u?.saving??`Saving...`,g=r.threadPosts?r.threadPosts.some(e=>En(e.body)):En(r.body),v=r.pendingAttachments.length>0||g,b=u?.published??`Published!`,S=u?.view??`View`,w=!!r.editPostId,ee=!!(r.threadPosts&&r.threadPosts.length>=2),te=r.status===`published`&&(!w||!!r.draftSourceId),T=!0;s(`compose-deferred`,v?f:te?p:h),r.pendingAttachments.length>0&&(Z={clientIds:r.pendingAttachments.map(e=>e.clientId),baseMsg:f},Q());let E=(e,t=`success`)=>{if(Z){for(let e of Z.clientIds)X.delete(e);Z=null}T?(T=!1,i(`compose-deferred`,e,t)):d(e,t)},D=()=>{o&&a&&(a.reset(),a.updateComplete.then(()=>{a.querySelector(`jant-compose-editor`)?.focusInput()}))},O=()=>{o&&a&&(a.loading=!1)},k=()=>{if(w){r.editPostId&&a?.clearEditDraftFromStorage?.(r.editPostId);return}a?.clearLocalDraftFromStorage?.()},ne=()=>{let e=r.threadPosts?.length?r.threadPosts:[r],t=[],n=new Set;for(let r of e)for(let e of r.attachments){if(e.type!==`media`||n.has(e.clientId))continue;n.add(e.clientId);let r=$.get(e.clientId);r&&t.push({clientId:e.clientId,mediaId:r.id,url:r.url,mimeType:r.mimeType,name:r.originalName||void 0,alt:e.alt||void 0})}return t},re=async()=>{if(a&&!o){if(r.draftSourceId){if(typeof a.openDraft!=`function`)return;await a.openDraft(r.draftSourceId);return}if(w&&r.editPostId){if(typeof a.openEdit!=`function`)return;await a.openEdit(r.editPostId,{restoreToast:!1});return}if(r.replyToId){if(typeof a.openReply!=`function`)return;await a.openReply(r.replyToId,void 0,r.replyThreadRootId,r.replyRefreshKind&&r.replyRefreshId?{kind:r.replyRefreshKind,id:r.replyRefreshId}:void 0,{restoreDraft:!0,initialFormat:r.format,restoreToast:!1,restoreMedia:ne()});return}typeof a.openNew==`function`&&await a.openNew({restoreDraft:!0,restoreToast:!1,restoreMedia:ne()})}},A=async e=>{O(),await re(),E(e,`error`)},j=async()=>{await a?.refreshCollections()},M=(e,t)=>{l(e,`success`,t)},N=()=>!o||!a||!a.consumePageLeaveRequest()?!1:(a.preparePageLeave(),globalThis.location.assign(a.closeHref||t(`/`)),!0),P=null;try{let e=r.pendingAttachments.map(e=>e.clientId),n=e.map(e=>An.get(e)??Promise.resolve(null)),i=await Promise.all(n);if(i.filter((t,n)=>t===null&&!$.has(e[n]??``)).length>0){if(r.status===`published`&&!w)P=`upload`;else{await A(`Upload failed. Post not created.`);return}}let s=new Map;for(let t=0;t<e.length;t++){let n=e[t],r=i[t];n&&r&&s.set(n,r)}if(ee&&r.threadPosts){let e=r.threadPosts,t=P?`draft`:r.status,n=(await Promise.all(e.map(async e=>{let n=e.body;if(En(n))try{let e=JSON.parse(n),t=await me(e);n=t?JSON.stringify(t):``}catch{}return{...e,body:n,status:t}}))).map(e=>zn(e,Vn(e,s))),i={posts:n};w&&r.editPostId&&(i.replaceThreadId=r.editPostId);let l=await wn(`/compose/thread`,JSON.stringify(i));if(!l?.ok){if(r.status===`published`&&!P){let e={posts:n.map(e=>({...e,status:`draft`}))};if((await wn(`/compose/thread`,JSON.stringify(e)))?.ok){P=`server`,k();let e=u?.publishFailedDraft??`Couldn't publish. Saved as draft.`;await j(),N()||D(),E(e);return}}await A(await Tn(l,u));return}if(P===`upload`){k();let e=u?.uploadFailedDraft??`Some uploads failed. Saved as draft.`;await j(),D(),E(e);return}let d=await x(l),f=C(d,`status`),p=C(d,`permalink`),m=C(d,`toast`);if(f===`published`)k(),c&&r.draftSourceId?(M(b),globalThis.location.assign(p??globalThis.location.pathname)):o?(await j(),D(),E(b)):(M(b,p?{label:S,href:p}:void 0),globalThis.location.reload());else{if(k(),c&&r.draftSourceId){M(m??`Draft saved.`),globalThis.location.assign(globalThis.location.pathname);return}await j(),N()||D(),E(m??`Draft saved.`),Hn(a,`draft`)}return}let l=Vn(r,s);if(g)try{let e=JSON.parse(r.body),t=await me(e);r.body=t?JSON.stringify(t):``}catch{}let d=w?`/api/posts/${r.editPostId}`:`/compose`,f=w?`PUT`:`POST`,p=zn({...r,status:P?`draft`:r.status},l),h=await wn(d,JSON.stringify(p),f);if(!h?.ok){if(r.status===`published`&&!w&&!P){let e={...p,status:`draft`},t=await wn(d,JSON.stringify(e),f);if(t?.ok){P=`server`,k();let e=await x(t),n=u?.publishFailedDraft??`Couldn't publish. Saved as draft.`;await j(),N()||D(),E(n);let r=C(e,`toast`);r&&E(r);return}}await A(await Tn(h,u));return}if(w){k();let e=await x(h),n=r.editPostId??``,i=C(e,`slug`),s=C(e,`status`)??r.status,l=i?t(s===`draft`?`/preview/${i}`:`/${i}`):null,u=s===`draft`?`Draft saved.`:r.draftSourceId?b:`Post updated.`;if(s===`draft`){if(c){M(u),globalThis.location.assign(l??globalThis.location.pathname);return}await j(),E(u),Hn(a,`draft`);return}if(o)l&&l!==globalThis.location.pathname?(M(u),globalThis.location.assign(l)):n&&await y(n)?E(u):(M(u),globalThis.location.assign(globalThis.location.pathname));else if(n){if(document.querySelector(`[data-post-view][data-post-view-id="${n}"]`)){if(l&&l!==globalThis.location.pathname){M(u),globalThis.location.assign(l);return}await y(n)?E(u):(M(u),globalThis.location.reload())}else{let e=document.querySelector(`article[data-post-id="${n}"]`)?.closest(`[data-timeline-item]`)?.dataset.threadRootId;(e?await m(e):await _(n))?E(u):(M(u),globalThis.location.reload())}}else M(u),globalThis.location.reload();return}if(P===`upload`){k();let e=u?.uploadFailedDraft??`Some uploads failed. Saved as draft.`;await j(),D(),E(e);return}let v=await x(h),te=C(v,`status`),T=C(v,`permalink`),O=C(v,`toast`);if(te===`published`){if(k(),o)await j(),D(),E(b);else if(r.replyToId){if(await j(),!await kn(r)){M(b,T?{label:S,href:T}:void 0),globalThis.location.reload();return}E(b)}else M(b,T?{label:S,href:T}:void 0),globalThis.location.reload();return}k(),await j(),N()||D(),E(O??`Draft saved.`),Hn(a,`draft`)}catch{await A(await Tn(null,u))}});function Hn(e,t){(e??document).dispatchEvent(new CustomEvent(`jant:compose-submit-complete`,{bubbles:!0,detail:{status:t}}))}document.readyState===`loading`&&document.addEventListener(`DOMContentLoaded`,()=>{}),document.querySelector(`jant-compose-fullscreen`)||document.body.appendChild(document.createElement(`jant-compose-fullscreen`));