@8wave/ai-elements 0.126.0-beta.21 → 0.126.0-beta.23

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 (83) hide show
  1. package/dist/_chunks/{PkChatbotFilePreview-DHcHcy4x.js → PkChatbotFilePreview-B4vbUkNp.js} +2 -2
  2. package/dist/_chunks/{PkChatbotFilePreview-DHcHcy4x.js.map → PkChatbotFilePreview-B4vbUkNp.js.map} +1 -1
  3. package/dist/_chunks/{PkStreamingMarkdown-0lzE-l9f.js → PkStreamingMarkdown-GRB3Gg_x.js} +2 -2
  4. package/dist/_chunks/{PkStreamingMarkdown-0lzE-l9f.js.map → PkStreamingMarkdown-GRB3Gg_x.js.map} +1 -1
  5. package/dist/_chunks/{PkToolChatFile-x50rORrq.js → PkToolChatFile-DTm5-CE4.js} +2 -2
  6. package/dist/_chunks/{PkToolChatFile-x50rORrq.js.map → PkToolChatFile-DTm5-CE4.js.map} +1 -1
  7. package/dist/_chunks/{PkToolShareDocument-Cv7uBr5Z.js → PkToolShareDocument-DYr0Rq4D.js} +2 -2
  8. package/dist/_chunks/{PkToolShareDocument-Cv7uBr5Z.js.map → PkToolShareDocument-DYr0Rq4D.js.map} +1 -1
  9. package/dist/_chunks/{PkToolShowArtifact-DMIADTQ6.js → PkToolShowArtifact-C9_DHr5Y.js} +2 -2
  10. package/dist/_chunks/{PkToolShowArtifact-DMIADTQ6.js.map → PkToolShowArtifact-C9_DHr5Y.js.map} +1 -1
  11. package/dist/_chunks/{PkToolShowContactForm-B5DCcFqt.js → PkToolShowContactForm-DhyelktO.js} +2 -2
  12. package/dist/_chunks/{PkToolShowContactForm-B5DCcFqt.js.map → PkToolShowContactForm-DhyelktO.js.map} +1 -1
  13. package/dist/_chunks/{PkToolShowDiagram-DEFJr7zY.js → PkToolShowDiagram-DWVSCu33.js} +2 -2
  14. package/dist/_chunks/{PkToolShowDiagram-DEFJr7zY.js.map → PkToolShowDiagram-DWVSCu33.js.map} +1 -1
  15. package/dist/_chunks/{PkToolShowForm-BBxcDLyR.js → PkToolShowForm-Dz2Hnzts.js} +2 -2
  16. package/dist/_chunks/{PkToolShowForm-BBxcDLyR.js.map → PkToolShowForm-Dz2Hnzts.js.map} +1 -1
  17. package/dist/_chunks/{PkToolShowImageGallery-BYvCAUFX.js → PkToolShowImageGallery-By-CPFS0.js} +2 -2
  18. package/dist/_chunks/{PkToolShowImageGallery-BYvCAUFX.js.map → PkToolShowImageGallery-By-CPFS0.js.map} +1 -1
  19. package/dist/_chunks/{PkToolShowSources-DxZoqWZd.js → PkToolShowSources-YDHIZ6Ly.js} +2 -2
  20. package/dist/_chunks/{PkToolShowSources-DxZoqWZd.js.map → PkToolShowSources-YDHIZ6Ly.js.map} +1 -1
  21. package/dist/_chunks/{useLightbox-BlHExsUm.js → useLightbox-Co8iz61W.js} +117 -95
  22. package/dist/_chunks/useLightbox-Co8iz61W.js.map +1 -0
  23. package/dist/ai-elements.es.js +12 -12
  24. package/dist-vue/PkChatbot.js +1 -1
  25. package/dist-vue/PkChatbotEmptyState.js +1 -1
  26. package/dist-vue/PkChatbotFilePreview.js +1 -1
  27. package/dist-vue/PkChatbotInput.js +1 -1
  28. package/dist-vue/PkChatbotMessages.js +1 -1
  29. package/dist-vue/PkChatbotSteps.js +1 -1
  30. package/dist-vue/PkChatbotViewChat.js +1 -1
  31. package/dist-vue/_chunks/{PkChatbot-Ck4H-uln.js → PkChatbot-CwHVS4sT.js} +3 -3
  32. package/dist-vue/_chunks/{PkChatbot-Ck4H-uln.js.map → PkChatbot-CwHVS4sT.js.map} +1 -1
  33. package/dist-vue/_chunks/{PkChatbotEmptyState-Jxc1HNJ5.js → PkChatbotEmptyState-BF3Odn3v.js} +2 -2
  34. package/dist-vue/_chunks/{PkChatbotEmptyState-Jxc1HNJ5.js.map → PkChatbotEmptyState-BF3Odn3v.js.map} +1 -1
  35. package/dist-vue/_chunks/{PkChatbotFilePreview-BDU2vY0F.js → PkChatbotFilePreview-aKJBtw04.js} +2 -2
  36. package/dist-vue/_chunks/{PkChatbotFilePreview-BDU2vY0F.js.map → PkChatbotFilePreview-aKJBtw04.js.map} +1 -1
  37. package/dist-vue/_chunks/{PkChatbotInput-DSdGtBTs.js → PkChatbotInput-DNXvFvyG.js} +3 -3
  38. package/dist-vue/_chunks/{PkChatbotInput-DSdGtBTs.js.map → PkChatbotInput-DNXvFvyG.js.map} +1 -1
  39. package/dist-vue/_chunks/{PkChatbotMessages-C7WSS6sd.js → PkChatbotMessages-DOOQRLEc.js} +17 -17
  40. package/dist-vue/_chunks/{PkChatbotMessages-C7WSS6sd.js.map → PkChatbotMessages-DOOQRLEc.js.map} +1 -1
  41. package/dist-vue/_chunks/{PkChatbotSteps-BMWrHfC9.js → PkChatbotSteps-BalLo6DZ.js} +2 -2
  42. package/dist-vue/_chunks/{PkChatbotSteps-BMWrHfC9.js.map → PkChatbotSteps-BalLo6DZ.js.map} +1 -1
  43. package/dist-vue/_chunks/{PkChatbotViewChat-SQLnQry2.js → PkChatbotViewChat-BWdFuQ4P.js} +6 -6
  44. package/dist-vue/_chunks/{PkChatbotViewChat-SQLnQry2.js.map → PkChatbotViewChat-BWdFuQ4P.js.map} +1 -1
  45. package/dist-vue/_chunks/{PkFilePreview-CyA7aA5I.js → PkFilePreview-B4LOpz5I.js} +2 -2
  46. package/dist-vue/_chunks/{PkFilePreview-CyA7aA5I.js.map → PkFilePreview-B4LOpz5I.js.map} +1 -1
  47. package/dist-vue/_chunks/{PkFilePreviewDialog-1Pp-5cpt.js → PkFilePreviewDialog-C_JCOUKx.js} +2 -2
  48. package/dist-vue/_chunks/{PkFilePreviewDialog-1Pp-5cpt.js.map → PkFilePreviewDialog-C_JCOUKx.js.map} +1 -1
  49. package/dist-vue/_chunks/{PkStreamingMarkdown-BFBv_HdF.js → PkStreamingMarkdown-CMxiJTMR.js} +2 -2
  50. package/dist-vue/_chunks/{PkStreamingMarkdown-BFBv_HdF.js.map → PkStreamingMarkdown-CMxiJTMR.js.map} +1 -1
  51. package/dist-vue/_chunks/{PkSvgViewer-CRNwb6Yn.js → PkSvgViewer-PAr87kCa.js} +2 -2
  52. package/dist-vue/_chunks/{PkSvgViewer-CRNwb6Yn.js.map → PkSvgViewer-PAr87kCa.js.map} +1 -1
  53. package/dist-vue/_chunks/{PkToolChatFile-BntAINfN.js → PkToolChatFile-Bd6Ci7i1.js} +2 -2
  54. package/dist-vue/_chunks/{PkToolChatFile-BntAINfN.js.map → PkToolChatFile-Bd6Ci7i1.js.map} +1 -1
  55. package/dist-vue/_chunks/{PkToolShareDocument-Bf7OE8XA.js → PkToolShareDocument-Bkt9JVqk.js} +2 -2
  56. package/dist-vue/_chunks/{PkToolShareDocument-Bf7OE8XA.js.map → PkToolShareDocument-Bkt9JVqk.js.map} +1 -1
  57. package/dist-vue/_chunks/{PkToolShowArtifact-PTyAPKlR.js → PkToolShowArtifact-rlZ-AGWh.js} +2 -2
  58. package/dist-vue/_chunks/{PkToolShowArtifact-PTyAPKlR.js.map → PkToolShowArtifact-rlZ-AGWh.js.map} +1 -1
  59. package/dist-vue/_chunks/{PkToolShowContactForm-CGIA743D.js → PkToolShowContactForm-BVBL7Unx.js} +2 -2
  60. package/dist-vue/_chunks/{PkToolShowContactForm-CGIA743D.js.map → PkToolShowContactForm-BVBL7Unx.js.map} +1 -1
  61. package/dist-vue/_chunks/{PkToolShowDiagram-CppjE7Vr.js → PkToolShowDiagram-Bs39QQZ3.js} +2 -2
  62. package/dist-vue/_chunks/{PkToolShowDiagram-CppjE7Vr.js.map → PkToolShowDiagram-Bs39QQZ3.js.map} +1 -1
  63. package/dist-vue/_chunks/{PkToolShowForm-DLlcs1c4.js → PkToolShowForm-D-RJeA2F.js} +2 -2
  64. package/dist-vue/_chunks/{PkToolShowForm-DLlcs1c4.js.map → PkToolShowForm-D-RJeA2F.js.map} +1 -1
  65. package/dist-vue/_chunks/{PkToolShowImageGallery-KP_ptp0w.js → PkToolShowImageGallery-8nTrgIRm.js} +3 -3
  66. package/dist-vue/_chunks/{PkToolShowImageGallery-KP_ptp0w.js.map → PkToolShowImageGallery-8nTrgIRm.js.map} +1 -1
  67. package/dist-vue/_chunks/{PkToolShowLocation-Nhh_LwmN.js → PkToolShowLocation-CqqtwH_R.js} +2 -2
  68. package/dist-vue/_chunks/{PkToolShowLocation-Nhh_LwmN.js.map → PkToolShowLocation-CqqtwH_R.js.map} +1 -1
  69. package/dist-vue/_chunks/{PkToolShowProductList-CbI-ncWs.js → PkToolShowProductList-BwfUG41_.js} +2 -2
  70. package/dist-vue/_chunks/{PkToolShowProductList-CbI-ncWs.js.map → PkToolShowProductList-BwfUG41_.js.map} +1 -1
  71. package/dist-vue/_chunks/{PkToolShowSources-E02Gy3vC.js → PkToolShowSources-ChGsGtb3.js} +2 -2
  72. package/dist-vue/_chunks/{PkToolShowSources-E02Gy3vC.js.map → PkToolShowSources-ChGsGtb3.js.map} +1 -1
  73. package/dist-vue/_chunks/{PkToolShowVideo-DBqMV0U7.js → PkToolShowVideo-BK-jDVJd.js} +2 -2
  74. package/dist-vue/_chunks/{PkToolShowVideo-DBqMV0U7.js.map → PkToolShowVideo-BK-jDVJd.js.map} +1 -1
  75. package/dist-vue/_chunks/{PkToolShowWebPages-2023cqa1.js → PkToolShowWebPages-K3Jml1f7.js} +2 -2
  76. package/dist-vue/_chunks/{PkToolShowWebPages-2023cqa1.js.map → PkToolShowWebPages-K3Jml1f7.js.map} +1 -1
  77. package/dist-vue/_chunks/{useLightbox-DmtNa8bJ.js → useLightbox-DrEFS3gx.js} +117 -95
  78. package/dist-vue/_chunks/useLightbox-DrEFS3gx.js.map +1 -0
  79. package/dist-vue/index.js +22 -22
  80. package/dist-vue/packages/components/src/composables/useLightbox.d.ts +12 -0
  81. package/package.json +1 -1
  82. package/dist/_chunks/useLightbox-BlHExsUm.js.map +0 -1
  83. package/dist-vue/_chunks/useLightbox-DmtNa8bJ.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"PkToolShowVideo-DBqMV0U7.js","names":["$t","_openBlock","_createElementBlock","_createElementVNode","_createVNode","_toDisplayString","_Fragment","_renderList","_normalizeClass","PkHeldImage","_unref","useChatImageGate","sanitizeId","raw","hostMatches","host","domain","youtubeId","u","v","m","vimeoId","parseVideoSource","url","id","hint","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","IFRAME_ALLOW","PkToolShowVideo_default","defineComponent","props","__props","PLAYER_HOSTS","imageGate","videos","computed","source","video","gated","src","release","urls","_component_VvIcon","VvIcon","openBlock","createElementBlock","createElementVNode","createVNode","toDisplayString","_ctx","Fragment","renderList","normalizeClass","index","PkHeldImage_default","unref","createCommentVNode"],"sources":["../../../../packages/utils/src/video-source.ts","../../../../packages/components/src/chat/PkToolShowVideo.vue"],"sourcesContent":["/**\n * Video source parsing shared by the backend platform renderer and the frontend\n * player component, so both classify a video URL the same way.\n *\n * A URL is either a known provider (YouTube/Vimeo), which plays through the\n * provider's iframe embed, or a direct media file (`file`), which plays in a\n * native `<video>` element. Detection is by URL shape; an explicit `hint` is\n * used only as a fallback when the URL alone is inconclusive.\n */\n\nexport type VideoProvider = 'youtube' | 'vimeo' | 'file'\n\nexport interface ParsedVideoSource {\n provider: VideoProvider\n /** The original URL, unchanged. */\n url: string\n /**\n * The URL to actually load: the provider iframe embed URL for\n * YouTube/Vimeo, or the direct file URL for `file`.\n */\n embedUrl: string\n /** The provider video id (providers only). */\n videoId?: string\n /**\n * A preview image URL derived from the provider, when one is available\n * without an extra API call (currently YouTube only). Lets a link-only\n * surface (e.g. a Teams card) show a thumbnail instead of a bare link.\n */\n thumbnailUrl?: string\n}\n\n/** Keep only characters that are legal in a provider video id. */\nconst sanitizeId = (raw: string): string => raw.replace(/[^a-zA-Z0-9_-]/g, '')\n\n/**\n * True when `host` is exactly `domain` or a subdomain of it. Guards against\n * lookalike hosts (e.g. `notyoutube.com`) that a bare substring check would\n * misclassify.\n */\nconst hostMatches = (host: string, domain: string): boolean =>\n host === domain || host.endsWith(`.${domain}`)\n\n/** Extract the YouTube video id from any of its URL shapes, or null. */\nconst youtubeId = (u: URL): string | null => {\n // youtu.be/<id>\n if (u.hostname.endsWith('youtu.be')) {\n return sanitizeId(u.pathname.split('/')[1] ?? '') || null\n }\n // youtube.com/watch?v=<id>\n const v = u.searchParams.get('v')\n if (v) {\n return sanitizeId(v) || null\n }\n // youtube.com/shorts/<id>, /live/<id>, /embed/<id>, /v/<id>\n const m = u.pathname.match(/^\\/(?:shorts|live|embed|v)\\/([^/?#]+)/)\n return m ? sanitizeId(m[1]) || null : null\n}\n\n/** Extract the Vimeo (numeric) video id, or null. */\nconst vimeoId = (u: URL): string | null => {\n // player.vimeo.com/video/<id> or vimeo.com/<id>\n const m = u.pathname.match(/(?:^|\\/)(\\d+)(?:$|[/?#])/)\n return m ? m[1] : null\n}\n\n/**\n * Classify a video URL into a provider + a loadable embed/file URL.\n * Falls back to `file` (native `<video>`) for anything not recognized as a\n * supported provider, or when a provider is matched but no id can be extracted.\n */\nexport function parseVideoSource(\n url: string,\n hint?: VideoProvider,\n): ParsedVideoSource {\n let u: URL | undefined\n try {\n u = new URL(url)\n } catch {\n // Not an absolute URL: treat as a direct file reference.\n return { provider: 'file', url, embedUrl: url }\n }\n\n const host = u.hostname.toLowerCase()\n\n const isYouTube =\n hostMatches(host, 'youtube.com') ||\n hostMatches(host, 'youtu.be') ||\n hostMatches(host, 'youtube-nocookie.com')\n if (isYouTube) {\n const id = youtubeId(u)\n if (id) {\n return {\n provider: 'youtube',\n url,\n videoId: id,\n embedUrl: `https://www.youtube-nocookie.com/embed/${id}`,\n thumbnailUrl: `https://img.youtube.com/vi/${id}/hqdefault.jpg`,\n }\n }\n }\n\n if (hostMatches(host, 'vimeo.com')) {\n const id = vimeoId(u)\n if (id) {\n return {\n provider: 'vimeo',\n url,\n videoId: id,\n // `dnt=1`: the player sets no cookies and records no session\n // data, the Vimeo counterpart of youtube-nocookie above.\n embedUrl: `https://player.vimeo.com/video/${id}?dnt=1`,\n }\n }\n }\n\n // Honor an explicit provider hint only if we could not extract an id from a\n // provider URL (so a caller-tagged provider link still routes to an iframe\n // via its original URL rather than a broken native <video>).\n if (hint && hint !== 'file') {\n return { provider: hint, url, embedUrl: url }\n }\n\n return { provider: 'file', url, embedUrl: url }\n}\n","<script setup lang=\"ts\">\n import { computed } from 'vue'\n import { parseVideoSource, type VideoProvider } from 'utils'\n import { useChatImageGate } from './chatImagePolicy'\n import PkHeldImage from './PkHeldImage.vue'\n\n const props = defineProps<{\n part: unknown\n }>()\n\n interface VideoInput {\n url: string\n title?: string\n description?: string\n poster?: string\n provider?: VideoProvider\n }\n\n // Permissions granted to provider embeds (YouTube/Vimeo players).\n const IFRAME_ALLOW =\n 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share'\n\n /**\n * Where a YouTube or Vimeo player lives: the url is built here from the\n * video id, so nothing the model wrote reaches these hosts but the id.\n */\n const PLAYER_HOSTS = ['www.youtube-nocookie.com', 'player.vimeo.com']\n\n // A file, its poster, or an embed this card does not recognize, fetch the\n // url the model wrote as soon as they render: from a host the agent does\n // not list they wait for a click, like an image (chatImagePolicy.ts).\n const imageGate = useChatImageGate()\n\n const videos = computed(() => {\n const part = props.part as { input?: { videos?: VideoInput[] } }\n return (part.input?.videos ?? []).map((video) => {\n const source = parseVideoSource(video.url, video.provider)\n const fetched =\n source.provider === 'file'\n ? [source.embedUrl, video.poster]\n : [source.embedUrl]\n const gated = fetched.filter(\n (src): src is string =>\n !!src &&\n !PLAYER_HOSTS.includes(imageGate.hostOf(src) ?? ''),\n )\n return {\n ...video,\n source,\n gated,\n held: gated.some((src) => !imageGate.canLoad(src)),\n }\n })\n })\n\n function release(urls: string[]) {\n for (const url of urls) {\n imageGate.release(url)\n }\n }\n</script>\n\n<template>\n <div\n v-if=\"videos.length\"\n class=\"border border-surface-3 rounded-xl w-full overflow-hidden bg-surface\">\n <div\n class=\"px-sm py-6 bg-surface-1 text-12 border-b border-surface-3 text-word-3 flex items-center gap-8 min-h-40\">\n <VvIcon name=\"ri:film-line\" class=\"text-16\" />\n <strong class=\"font-bold\">\n {{ $t('label.video') }}\n </strong>\n </div>\n <!-- Each video bleeds to the card's edges, like the map of the\n location card: the card's overflow clips the bottom corners. -->\n <div\n v-for=\"(video, index) in videos\"\n :key=\"video.url\"\n class=\"flex flex-col\"\n :class=\"{ 'border-t border-surface-3': index > 0 }\">\n <!-- Direct file: native player. Handles MP4/WebM/OGG and works\n inside the widget's Shadow DOM without any extra CSS. -->\n <div\n v-if=\"video.held\"\n class=\"w-full overflow-hidden\"\n style=\"aspect-ratio: 16 / 9\">\n <PkHeldImage\n :host=\"imageGate.hostOf(video.gated[0])\"\n kind=\"video\"\n fill\n @release=\"release(video.gated)\" />\n </div>\n <video\n v-else-if=\"video.source.provider === 'file'\"\n :src=\"video.source.embedUrl\"\n :poster=\"video.poster\"\n controls\n preload=\"metadata\"\n playsinline\n class=\"w-full bg-black\"\n style=\"aspect-ratio: 16 / 9; max-height: 480px\">\n <a :href=\"video.url\" target=\"_blank\" rel=\"noopener noreferrer\">\n {{ video.title ?? video.url }}\n </a>\n </video>\n <!-- Provider (YouTube/Vimeo): iframe embed, 16:9 responsive. -->\n <div\n v-else\n class=\"relative w-full overflow-hidden bg-black\"\n style=\"aspect-ratio: 16 / 9\">\n <iframe\n :src=\"video.source.embedUrl\"\n :title=\"video.title ?? video.url\"\n loading=\"lazy\"\n referrerpolicy=\"strict-origin-when-cross-origin\"\n :allow=\"IFRAME_ALLOW\"\n allowfullscreen\n class=\"absolute inset-0 w-full h-full border-0\"></iframe>\n </div>\n <div\n v-if=\"video.title || video.description\"\n class=\"p-sm flex flex-col gap-4 border-t border-surface-3\">\n <strong v-if=\"video.title\" class=\"font-bold text-14\">\n {{ video.title }}\n </strong>\n <span v-if=\"video.description\" class=\"text-12 text-word-3\">\n {{ video.description }}\n </span>\n </div>\n </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EAIsCK,GAAA;IAHjC,MAAMC,EAAAiC,CAAA,CAAS,CAAC,OAAOI,EAAM,MAAK,EAAA;IACnC,MAAK;IACL,MAAA;IACC,YAAO,MAAEG,EAAQH,EAAM,KAAK;G,wCAGtBA,EAAM,OAAO,aAAQ,UADpC9C,EAAA,GAAAC,EAYQ,SAAA;;IAVH,KAAK6C,EAAM,OAAO;IAClB,QAAQA,EAAM;IACf,UAAA;IACA,SAAQ;IACR,aAAA;IACA,OAAM;IACN,OAAA;KAAA,gBAAA;KAAA,cAAA;IAAA;G,IACA5C,EAEI,KAAA;IAFA,MAAM4C,EAAM;IAAK,QAAO;IAAS,KAAI;GAClC,GAAA1C,EAAA0C,EAAM,SAASA,EAAM,GAAG,GAAA,GAAAhB,CAAA,C,aAInC9B,EAAA,GAAAC,EAYM,OAZN8B,GAYM,CARF7B,EAO6D,UAAA;IANxD,KAAK4C,EAAM,OAAO;IAClB,OAAOA,EAAM,SAASA,EAAM;IAC7B,SAAQ;IACR,gBAAe;IACd,OAAOV;IACR,iBAAA;IACA,OAAM;G,mBAGJU,EAAM,SAASA,EAAM,eAD/B9C,EAAA,GAAAC,EASM,OATNgC,GASM,CANYa,EAAM,SAApB9C,EAAA,GAAAC,EAES,UAFTiC,GAES9B,EADF0C,EAAM,KAAK,GAAA,CAAA,K,WAENA,EAAM,eAAlB9C,EAAA,GAAAC,EAEO,QAFPkC,GAEO/B,EADA0C,EAAM,WAAW,GAAA,CAAA,K"}
1
+ {"version":3,"file":"PkToolShowVideo-BK-jDVJd.js","names":["$t","_openBlock","_createElementBlock","_createElementVNode","_createVNode","_toDisplayString","_Fragment","_renderList","_normalizeClass","PkHeldImage","_unref","useChatImageGate","sanitizeId","raw","hostMatches","host","domain","youtubeId","u","v","m","vimeoId","parseVideoSource","url","id","hint","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","IFRAME_ALLOW","PkToolShowVideo_default","defineComponent","props","__props","PLAYER_HOSTS","imageGate","videos","computed","source","video","gated","src","release","urls","_component_VvIcon","VvIcon","openBlock","createElementBlock","createElementVNode","createVNode","toDisplayString","_ctx","Fragment","renderList","normalizeClass","index","PkHeldImage_default","unref","createCommentVNode"],"sources":["../../../../packages/utils/src/video-source.ts","../../../../packages/components/src/chat/PkToolShowVideo.vue"],"sourcesContent":["/**\n * Video source parsing shared by the backend platform renderer and the frontend\n * player component, so both classify a video URL the same way.\n *\n * A URL is either a known provider (YouTube/Vimeo), which plays through the\n * provider's iframe embed, or a direct media file (`file`), which plays in a\n * native `<video>` element. Detection is by URL shape; an explicit `hint` is\n * used only as a fallback when the URL alone is inconclusive.\n */\n\nexport type VideoProvider = 'youtube' | 'vimeo' | 'file'\n\nexport interface ParsedVideoSource {\n provider: VideoProvider\n /** The original URL, unchanged. */\n url: string\n /**\n * The URL to actually load: the provider iframe embed URL for\n * YouTube/Vimeo, or the direct file URL for `file`.\n */\n embedUrl: string\n /** The provider video id (providers only). */\n videoId?: string\n /**\n * A preview image URL derived from the provider, when one is available\n * without an extra API call (currently YouTube only). Lets a link-only\n * surface (e.g. a Teams card) show a thumbnail instead of a bare link.\n */\n thumbnailUrl?: string\n}\n\n/** Keep only characters that are legal in a provider video id. */\nconst sanitizeId = (raw: string): string => raw.replace(/[^a-zA-Z0-9_-]/g, '')\n\n/**\n * True when `host` is exactly `domain` or a subdomain of it. Guards against\n * lookalike hosts (e.g. `notyoutube.com`) that a bare substring check would\n * misclassify.\n */\nconst hostMatches = (host: string, domain: string): boolean =>\n host === domain || host.endsWith(`.${domain}`)\n\n/** Extract the YouTube video id from any of its URL shapes, or null. */\nconst youtubeId = (u: URL): string | null => {\n // youtu.be/<id>\n if (u.hostname.endsWith('youtu.be')) {\n return sanitizeId(u.pathname.split('/')[1] ?? '') || null\n }\n // youtube.com/watch?v=<id>\n const v = u.searchParams.get('v')\n if (v) {\n return sanitizeId(v) || null\n }\n // youtube.com/shorts/<id>, /live/<id>, /embed/<id>, /v/<id>\n const m = u.pathname.match(/^\\/(?:shorts|live|embed|v)\\/([^/?#]+)/)\n return m ? sanitizeId(m[1]) || null : null\n}\n\n/** Extract the Vimeo (numeric) video id, or null. */\nconst vimeoId = (u: URL): string | null => {\n // player.vimeo.com/video/<id> or vimeo.com/<id>\n const m = u.pathname.match(/(?:^|\\/)(\\d+)(?:$|[/?#])/)\n return m ? m[1] : null\n}\n\n/**\n * Classify a video URL into a provider + a loadable embed/file URL.\n * Falls back to `file` (native `<video>`) for anything not recognized as a\n * supported provider, or when a provider is matched but no id can be extracted.\n */\nexport function parseVideoSource(\n url: string,\n hint?: VideoProvider,\n): ParsedVideoSource {\n let u: URL | undefined\n try {\n u = new URL(url)\n } catch {\n // Not an absolute URL: treat as a direct file reference.\n return { provider: 'file', url, embedUrl: url }\n }\n\n const host = u.hostname.toLowerCase()\n\n const isYouTube =\n hostMatches(host, 'youtube.com') ||\n hostMatches(host, 'youtu.be') ||\n hostMatches(host, 'youtube-nocookie.com')\n if (isYouTube) {\n const id = youtubeId(u)\n if (id) {\n return {\n provider: 'youtube',\n url,\n videoId: id,\n embedUrl: `https://www.youtube-nocookie.com/embed/${id}`,\n thumbnailUrl: `https://img.youtube.com/vi/${id}/hqdefault.jpg`,\n }\n }\n }\n\n if (hostMatches(host, 'vimeo.com')) {\n const id = vimeoId(u)\n if (id) {\n return {\n provider: 'vimeo',\n url,\n videoId: id,\n // `dnt=1`: the player sets no cookies and records no session\n // data, the Vimeo counterpart of youtube-nocookie above.\n embedUrl: `https://player.vimeo.com/video/${id}?dnt=1`,\n }\n }\n }\n\n // Honor an explicit provider hint only if we could not extract an id from a\n // provider URL (so a caller-tagged provider link still routes to an iframe\n // via its original URL rather than a broken native <video>).\n if (hint && hint !== 'file') {\n return { provider: hint, url, embedUrl: url }\n }\n\n return { provider: 'file', url, embedUrl: url }\n}\n","<script setup lang=\"ts\">\n import { computed } from 'vue'\n import { parseVideoSource, type VideoProvider } from 'utils'\n import { useChatImageGate } from './chatImagePolicy'\n import PkHeldImage from './PkHeldImage.vue'\n\n const props = defineProps<{\n part: unknown\n }>()\n\n interface VideoInput {\n url: string\n title?: string\n description?: string\n poster?: string\n provider?: VideoProvider\n }\n\n // Permissions granted to provider embeds (YouTube/Vimeo players).\n const IFRAME_ALLOW =\n 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share'\n\n /**\n * Where a YouTube or Vimeo player lives: the url is built here from the\n * video id, so nothing the model wrote reaches these hosts but the id.\n */\n const PLAYER_HOSTS = ['www.youtube-nocookie.com', 'player.vimeo.com']\n\n // A file, its poster, or an embed this card does not recognize, fetch the\n // url the model wrote as soon as they render: from a host the agent does\n // not list they wait for a click, like an image (chatImagePolicy.ts).\n const imageGate = useChatImageGate()\n\n const videos = computed(() => {\n const part = props.part as { input?: { videos?: VideoInput[] } }\n return (part.input?.videos ?? []).map((video) => {\n const source = parseVideoSource(video.url, video.provider)\n const fetched =\n source.provider === 'file'\n ? [source.embedUrl, video.poster]\n : [source.embedUrl]\n const gated = fetched.filter(\n (src): src is string =>\n !!src &&\n !PLAYER_HOSTS.includes(imageGate.hostOf(src) ?? ''),\n )\n return {\n ...video,\n source,\n gated,\n held: gated.some((src) => !imageGate.canLoad(src)),\n }\n })\n })\n\n function release(urls: string[]) {\n for (const url of urls) {\n imageGate.release(url)\n }\n }\n</script>\n\n<template>\n <div\n v-if=\"videos.length\"\n class=\"border border-surface-3 rounded-xl w-full overflow-hidden bg-surface\">\n <div\n class=\"px-sm py-6 bg-surface-1 text-12 border-b border-surface-3 text-word-3 flex items-center gap-8 min-h-40\">\n <VvIcon name=\"ri:film-line\" class=\"text-16\" />\n <strong class=\"font-bold\">\n {{ $t('label.video') }}\n </strong>\n </div>\n <!-- Each video bleeds to the card's edges, like the map of the\n location card: the card's overflow clips the bottom corners. -->\n <div\n v-for=\"(video, index) in videos\"\n :key=\"video.url\"\n class=\"flex flex-col\"\n :class=\"{ 'border-t border-surface-3': index > 0 }\">\n <!-- Direct file: native player. Handles MP4/WebM/OGG and works\n inside the widget's Shadow DOM without any extra CSS. -->\n <div\n v-if=\"video.held\"\n class=\"w-full overflow-hidden\"\n style=\"aspect-ratio: 16 / 9\">\n <PkHeldImage\n :host=\"imageGate.hostOf(video.gated[0])\"\n kind=\"video\"\n fill\n @release=\"release(video.gated)\" />\n </div>\n <video\n v-else-if=\"video.source.provider === 'file'\"\n :src=\"video.source.embedUrl\"\n :poster=\"video.poster\"\n controls\n preload=\"metadata\"\n playsinline\n class=\"w-full bg-black\"\n style=\"aspect-ratio: 16 / 9; max-height: 480px\">\n <a :href=\"video.url\" target=\"_blank\" rel=\"noopener noreferrer\">\n {{ video.title ?? video.url }}\n </a>\n </video>\n <!-- Provider (YouTube/Vimeo): iframe embed, 16:9 responsive. -->\n <div\n v-else\n class=\"relative w-full overflow-hidden bg-black\"\n style=\"aspect-ratio: 16 / 9\">\n <iframe\n :src=\"video.source.embedUrl\"\n :title=\"video.title ?? video.url\"\n loading=\"lazy\"\n referrerpolicy=\"strict-origin-when-cross-origin\"\n :allow=\"IFRAME_ALLOW\"\n allowfullscreen\n class=\"absolute inset-0 w-full h-full border-0\"></iframe>\n </div>\n <div\n v-if=\"video.title || video.description\"\n class=\"p-sm flex flex-col gap-4 border-t border-surface-3\">\n <strong v-if=\"video.title\" class=\"font-bold text-14\">\n {{ video.title }}\n </strong>\n <span v-if=\"video.description\" class=\"text-12 text-word-3\">\n {{ video.description }}\n </span>\n </div>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;AAgCA,IAAMY,KAAc,MAAwBC,EAAI,QAAQ,mBAAmB,EAAE,GAOvEC,KAAe,GAAc,MAC/BC,MAASC,KAAUD,EAAK,SAAS,IAAIC,GAAQ,GAG3CC,KAAa,MAA0B;CAEzC,IAAIC,EAAE,SAAS,SAAS,UAAU,GAC9B,OAAON,EAAWM,EAAE,SAAS,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK;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OAAM;IACN,OAAA;KAAA,gBAAA;KAAA,cAAA;IAAA;G,IACA5C,EAEI,KAAA;IAFA,MAAM4C,EAAM;IAAK,QAAO;IAAS,KAAI;GAClC,GAAA1C,EAAA0C,EAAM,SAASA,EAAM,GAAG,GAAA,GAAAhB,CAAA,C,aAInC9B,EAAA,GAAAC,EAYM,OAZN8B,GAYM,CARF7B,EAO6D,UAAA;IANxD,KAAK4C,EAAM,OAAO;IAClB,OAAOA,EAAM,SAASA,EAAM;IAC7B,SAAQ;IACR,gBAAe;IACd,OAAOV;IACR,iBAAA;IACA,OAAM;G,mBAGJU,EAAM,SAASA,EAAM,eAD/B9C,EAAA,GAAAC,EASM,OATNgC,GASM,CANYa,EAAM,SAApB9C,EAAA,GAAAC,EAES,UAFTiC,GAES9B,EADF0C,EAAM,KAAK,GAAA,CAAA,K,WAENA,EAAM,eAAlB9C,EAAA,GAAAC,EAEO,QAFPkC,GAEO/B,EADA0C,EAAM,WAAW,GAAA,CAAA,K"}
@@ -2,7 +2,7 @@ import { t as e } from "./rolldown-runtime-CGnMp29N.js";
2
2
  import "./src-nb8MU1sh.js";
3
3
  import { t } from "./PkLazyImg-D_Tmtfz3.js";
4
4
  import { n } from "./url-validation-CJV9pp4v.js";
5
- import { r } from "./PkStreamingMarkdown-BFBv_HdF.js";
5
+ import { r } from "./PkStreamingMarkdown-CMxiJTMR.js";
6
6
  import { t as i } from "./PkHeldImage-CK1xwkvq.js";
7
7
  import { t as a } from "./PkUrl-IFszepUi.js";
8
8
  import { VvIcon as o } from "@volverjs/ui-vue/components";
@@ -82,4 +82,4 @@ var x = {
82
82
  }), k = /* @__PURE__ */ e({ default: () => A }), A = O;
83
83
  export { k as n, A as t };
84
84
 
85
- //# sourceMappingURL=PkToolShowWebPages-2023cqa1.js.map
85
+ //# sourceMappingURL=PkToolShowWebPages-K3Jml1f7.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PkToolShowWebPages-2023cqa1.js","names":["$t","_openBlock","_createElementBlock","_Fragment","_renderList","_createElementVNode","_unref","_createBlock","PkHeldImage","PkLazyImg","_toDisplayString","_createVNode","PkUrl","_createTextVNode","__exportAll","PkHeldImage_default","PkUrl_default","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","PkToolShowWebPages_vue_vue_type_script_setup_true_lang_default","props","__props","toolPart","computed","imageGate","useChatImageGate","normalizeUrl","u","url","uniquePages","seen","result","page","key","showMore","ref","pages","hasMore","_component_VvIcon","VvIcon","openBlock","createElementBlock","Fragment","renderList","index","createElementVNode","_ctx","unref","isSameSite","createBlock","PkLazyImg_default","createCommentVNode","toDisplayString","createVNode","_cache","createTextVNode","PkToolShowWebPages_exports","PkToolShowWebPages_default"],"sources":["../../../../packages/components/src/chat/PkToolShowWebPages.vue"],"sourcesContent":["<script setup lang=\"ts\">\n import { computed, ref } from 'vue'\n import { isSameSite } from 'utils'\n import PkLazyImg from '../PkLazyImg.vue'\n import { useChatImageGate } from './chatImagePolicy'\n import PkHeldImage from './PkHeldImage.vue'\n import PkUrl from '../PkUrl.vue'\n\n const props = defineProps<{\n part: unknown\n }>()\n\n const toolPart = computed(() => {\n const part = props.part as {\n input?: {\n pages: Array<{\n title: string\n url: string\n image?: string\n description?: string\n }>\n }\n }\n return part\n })\n\n // The model writes these urls: one from a host the agent does not list\n // waits for a click (chatImagePolicy.ts).\n const imageGate = useChatImageGate()\n\n // The model often passes the same URL several times (e.g. multiple KB\n // chunks from one page), so collapse duplicates, keeping the first (richest)\n // entry. Normalize by dropping the hash and any trailing slash.\n const normalizeUrl = (url: string) => {\n try {\n const u = new URL(url)\n u.hash = ''\n return u.toString().replace(/\\/$/, '')\n } catch {\n return url.trim().replace(/\\/$/, '')\n }\n }\n const uniquePages = computed(() => {\n const seen = new Set<string>()\n const result: NonNullable<typeof toolPart.value.input>['pages'] = []\n for (const page of toolPart.value.input?.pages || []) {\n const key = normalizeUrl(page.url)\n if (seen.has(key)) {\n continue\n }\n seen.add(key)\n result.push(page)\n }\n return result\n })\n\n const showMore = ref(false)\n const pages = computed(() => {\n if (showMore.value) {\n return uniquePages.value\n }\n return uniquePages.value.slice(0, 2)\n })\n const hasMore = computed(() => uniquePages.value.length > 2)\n</script>\n\n<template>\n <ul\n v-if=\"pages?.length\"\n class=\"vv-item-group vv-item-group--framed w-full shrink-0\">\n <li\n v-for=\"(page, index) in pages\"\n :key=\"index\"\n class=\"vv-item vv-item--top vv-item--roomy\">\n <a\n :href=\"page.url\"\n :title=\"$t('action.open')\"\n :target=\"isSameSite(page.url) ? undefined : '_blank'\"\n :rel=\"isSameSite(page.url) ? undefined : 'noopener noreferrer'\"\n class=\"vv-item__entry\">\n <!-- og:images the model scraped are third-party urls: a dead one\n degrades to an icon instead of breaking the card layout -->\n <PkHeldImage\n v-if=\"page.image && !imageGate.canLoad(page.image)\"\n :host=\"imageGate.hostOf(page.image)\"\n class=\"w-48 h-48 rounded-lg shrink-0 border border-surface-3 bg-surface\"\n @release=\"imageGate.release(page.image)\" />\n <PkLazyImg\n v-else-if=\"page.image\"\n :src=\"page.image\"\n :alt=\"page.title\"\n fallback-icon=\"ri:image-off-line\"\n class=\"w-48 h-48 object-contain rounded-lg shrink-0 border border-surface-3 bg-surface\" />\n <div class=\"flex flex-col gap-4 min-w-0 flex-1\">\n <strong\n class=\"vv-item__title font-medium text-12 text-word-1\">\n {{ page.title }}\n </strong>\n <span\n class=\"text-10 text-word-4 truncate flex items-center gap-4\">\n <VvIcon name=\"ri:link\" class=\"shrink-0 text-12\" />\n <PkUrl :url=\"page.url\" />\n </span>\n <p\n v-if=\"page.description\"\n class=\"text-12 text-word-3 line-clamp-2\">\n {{ page.description }}\n </p>\n </div>\n </a>\n </li>\n <li v-if=\"hasMore\" class=\"vv-item\">\n <button\n class=\"vv-item__entry justify-center cursor-pointer\"\n @click=\"showMore = !showMore\">\n <VvIcon\n :name=\"\n showMore ? 'ri:arrow-up-s-line' : 'ri:arrow-down-s-line'\n \"\n class=\"text-16\" />\n {{\n showMore\n ? $t('action.showLess')\n : $t('action.showMore', {\n count: uniquePages.length - 2,\n })\n }}\n </button>\n </li>\n </ul>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQI,IAAMyB,IAAQC,GAIRC,IAAWC,QACAH,EAAM,IAWtB,GAIKI,IAAYC,EAAiB,GAK7BC,KAAgB,MAAgB;GAClC,IAAI;IACA,IAAMC,IAAI,IAAI,IAAIC,CAAG;IAErB,OADA,EAAE,OAAO,IACFD,EAAE,SAAS,CAAC,CAAC,QAAQ,OAAO,EAAE;GACzC,QAAQ;IACJ,OAAOC,EAAI,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;GACvC;EACJ,GACMC,IAAcN,QAAe;GAC/B,IAAMO,oBAAO,IAAI,IAAY,GACvBC,IAA4D,CAAC;GACnE,KAAK,IAAMC,KAAQV,EAAS,MAAM,OAAO,SAAS,CAAC,GAAG;IAClD,IAAMW,IAAMP,EAAaM,EAAK,GAAG;IACjC,AAAIF,EAAK,IAAIG,CAAG,MAGhBH,EAAK,IAAIG,CAAG,GACZF,EAAO,KAAKC,CAAI;GACpB;GACA,OAAOD;EACX,CAAC,GAEKG,IAAWC,EAAI,EAAK,GACpBC,IAAQb,QACNW,EAAS,QACFL,EAAY,QAEhBA,EAAY,MAAM,MAAM,GAAG,CAAC,CACtC,GACKQ,IAAUd,QAAeM,EAAY,MAAM,SAAS,CAAC;;;GAKjD,OAAAO,EAAA,OAAO,UADjBxC,EAAA,GAAAC,EA8DK,MA9DLe,GA8DK,EA3DDhB,EAAA,EAAA,GAAAC,EAwCKC,GAAA,MAAAC,EAvCuBqC,EAAA,QAAhB,GAAM,OADlBxC,EAAA,GAAAC,EAwCK,MAAA;IAtCA,KAAK+C;IACN,OAAM;G,IACN5C,EAmCI,KAAA;IAlCC,MAAMgC,EAAK;IACX,OAAOrC,EAAAA,GAAE,aAAA;IACT,QAAQM,EAAA+C,CAAA,CAAU,CAAChB,EAAK,GAA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","_renderList","_createElementVNode","_unref","_createBlock","PkHeldImage","PkLazyImg","_toDisplayString","_createVNode","PkUrl","_createTextVNode","__exportAll","PkHeldImage_default","PkUrl_default","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","PkToolShowWebPages_vue_vue_type_script_setup_true_lang_default","props","__props","toolPart","computed","imageGate","useChatImageGate","normalizeUrl","u","url","uniquePages","seen","result","page","key","showMore","ref","pages","hasMore","_component_VvIcon","VvIcon","openBlock","createElementBlock","Fragment","renderList","index","createElementVNode","_ctx","unref","isSameSite","createBlock","PkLazyImg_default","createCommentVNode","toDisplayString","createVNode","_cache","createTextVNode","PkToolShowWebPages_exports","PkToolShowWebPages_default"],"sources":["../../../../packages/components/src/chat/PkToolShowWebPages.vue"],"sourcesContent":["<script setup lang=\"ts\">\n import { computed, ref } from 'vue'\n import { isSameSite } from 'utils'\n import PkLazyImg from '../PkLazyImg.vue'\n import { useChatImageGate } from './chatImagePolicy'\n import PkHeldImage from './PkHeldImage.vue'\n import PkUrl from '../PkUrl.vue'\n\n const props = defineProps<{\n part: unknown\n }>()\n\n const toolPart = computed(() => {\n const part = props.part as {\n input?: {\n pages: Array<{\n title: string\n url: string\n image?: string\n description?: string\n }>\n }\n }\n return part\n })\n\n // The model writes these urls: one from a host the agent does not list\n // waits for a click (chatImagePolicy.ts).\n const imageGate = useChatImageGate()\n\n // The model often passes the same URL several times (e.g. multiple KB\n // chunks from one page), so collapse duplicates, keeping the first (richest)\n // entry. Normalize by dropping the hash and any trailing slash.\n const normalizeUrl = (url: string) => {\n try {\n const u = new URL(url)\n u.hash = ''\n return u.toString().replace(/\\/$/, '')\n } catch {\n return url.trim().replace(/\\/$/, '')\n }\n }\n const uniquePages = computed(() => {\n const seen = new Set<string>()\n const result: NonNullable<typeof toolPart.value.input>['pages'] = []\n for (const page of toolPart.value.input?.pages || []) {\n const key = normalizeUrl(page.url)\n if (seen.has(key)) {\n continue\n }\n seen.add(key)\n result.push(page)\n }\n return result\n })\n\n const showMore = ref(false)\n const pages = computed(() => {\n if (showMore.value) {\n return uniquePages.value\n }\n return uniquePages.value.slice(0, 2)\n })\n const hasMore = computed(() => uniquePages.value.length > 2)\n</script>\n\n<template>\n <ul\n v-if=\"pages?.length\"\n class=\"vv-item-group vv-item-group--framed w-full shrink-0\">\n <li\n v-for=\"(page, index) in pages\"\n :key=\"index\"\n class=\"vv-item vv-item--top vv-item--roomy\">\n <a\n :href=\"page.url\"\n :title=\"$t('action.open')\"\n :target=\"isSameSite(page.url) ? undefined : '_blank'\"\n :rel=\"isSameSite(page.url) ? undefined : 'noopener noreferrer'\"\n class=\"vv-item__entry\">\n <!-- og:images the model scraped are third-party urls: a dead one\n degrades to an icon instead of breaking the card layout -->\n <PkHeldImage\n v-if=\"page.image && !imageGate.canLoad(page.image)\"\n :host=\"imageGate.hostOf(page.image)\"\n class=\"w-48 h-48 rounded-lg shrink-0 border border-surface-3 bg-surface\"\n @release=\"imageGate.release(page.image)\" />\n <PkLazyImg\n v-else-if=\"page.image\"\n :src=\"page.image\"\n :alt=\"page.title\"\n fallback-icon=\"ri:image-off-line\"\n class=\"w-48 h-48 object-contain rounded-lg shrink-0 border border-surface-3 bg-surface\" />\n <div class=\"flex flex-col gap-4 min-w-0 flex-1\">\n <strong\n class=\"vv-item__title font-medium text-12 text-word-1\">\n {{ page.title }}\n </strong>\n <span\n class=\"text-10 text-word-4 truncate flex items-center gap-4\">\n <VvIcon name=\"ri:link\" class=\"shrink-0 text-12\" />\n <PkUrl :url=\"page.url\" />\n </span>\n <p\n v-if=\"page.description\"\n class=\"text-12 text-word-3 line-clamp-2\">\n {{ page.description }}\n </p>\n </div>\n </a>\n </li>\n <li v-if=\"hasMore\" class=\"vv-item\">\n <button\n class=\"vv-item__entry justify-center cursor-pointer\"\n @click=\"showMore = !showMore\">\n <VvIcon\n :name=\"\n showMore ? 'ri:arrow-up-s-line' : 'ri:arrow-down-s-line'\n \"\n class=\"text-16\" />\n {{\n showMore\n ? $t('action.showLess')\n : $t('action.showMore', {\n count: uniquePages.length - 2,\n })\n }}\n </button>\n </li>\n </ul>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQI,IAAMyB,IAAQC,GAIRC,IAAWC,QACAH,EAAM,IAWtB,GAIKI,IAAYC,EAAiB,GAK7BC,KAAgB,MAAgB;GAClC,IAAI;IACA,IAAMC,IAAI,IAAI,IAAIC,CAAG;IAErB,OADA,EAAE,OAAO,IACFD,EAAE,SAAS,CAAC,CAAC,QAAQ,OAAO,EAAE;GACzC,QAAQ;IACJ,OAAOC,EAAI,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;GACvC;EACJ,GACMC,IAAcN,QAAe;GAC/B,IAAMO,oBAAO,IAAI,IAAY,GACvBC,IAA4D,CAAC;GACnE,KAAK,IAAMC,KAAQV,EAAS,MAAM,OAAO,SAAS,CAAC,GAAG;IAClD,IAAMW,IAAMP,EAAaM,EAAK,GAAG;IACjC,AAAIF,EAAK,IAAIG,CAAG,MAGhBH,EAAK,IAAIG,CAAG,GACZF,EAAO,KAAKC,CAAI;GACpB;GACA,OAAOD;EACX,CAAC,GAEKG,IAAWC,EAAI,EAAK,GACpBC,IAAQb,QACNW,EAAS,QACFL,EAAY,QAEhBA,EAAY,MAAM,MAAM,GAAG,CAAC,CACtC,GACKQ,IAAUd,QAAeM,EAAY,MAAM,SAAS,CAAC;;;GAKjD,OAAAO,EAAA,OAAO,UADjBxC,EAAA,GAAAC,EA8DK,MA9DLe,GA8DK,EA3DDhB,EAAA,EAAA,GAAAC,EAwCKC,GAAA,MAAAC,EAvCuBqC,EAAA,QAAhB,GAAM,OADlBxC,EAAA,GAAAC,EAwCK,MAAA;IAtCA,KAAK+C;IACN,OAAM;G,IACN5C,EAmCI,KAAA;IAlCC,MAAMgC,EAAK;IACX,OAAOrC,EAAAA,GAAE,aAAA;IACT,QAAQM,EAAA+C,CAAA,CAAU,CAAChB,EAAK,GAAG,IAA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"=": 1.25,
23
23
  "-": .8,
24
24
  _: .8
25
- }, h = Symbol("sharedLightbox"), g = Symbol("imageAnnotation");
26
- function _(e) {
27
- r(g, e);
25
+ }, h = {
26
+ annotate: 8,
27
+ copy: 8.5,
28
+ openInNewTab: 9,
29
+ download: 9.5
30
+ }, g = Symbol("sharedLightbox"), _ = Symbol("imageAnnotation");
31
+ function v(e) {
32
+ r(_, e);
28
33
  }
29
- var v = "a[data-pswp-src][data-pswp-shared], [data-pswp-images] img:not(a img)";
30
- function y(n) {
31
- let { gallery: r, children: i = "a[data-pswp-src]", loop: c = !0, downloadable: u = !0, openInNewTab: h = !0, shared: _ = !1, annotatable: v = !1 } = n, y = a(null), x = _ ? b() : void 0, S = v ? e(g, void 0) : void 0, { t: E } = s({ useScope: "global" }), D = !1;
34
+ var y = "a[data-pswp-src][data-pswp-shared], [data-pswp-images] img:not(a img)";
35
+ function b(n) {
36
+ let { gallery: r, children: i = "a[data-pswp-src]", loop: c = !0, downloadable: u = !0, openInNewTab: g = !0, shared: v = !1, annotatable: y = !1 } = n, b = a(null), S = v ? x() : void 0, C = y ? e(_, void 0) : void 0, { t: w } = s({ useScope: "global" }), k = !1;
32
37
  return t(() => {
33
- D = !0, y.value?.destroy(), y.value = null;
38
+ k = !0, b.value?.destroy(), b.value = null;
34
39
  }), {
35
- lightbox: y,
40
+ lightbox: b,
36
41
  init: async () => {
37
- if (x) {
38
- x.join();
42
+ if (S) {
43
+ S.join();
39
44
  return;
40
45
  }
41
46
  if (!r.value) return;
42
- l(d), H();
47
+ l(d), G();
43
48
  let { default: e } = await import("photoswipe/lightbox");
44
- D || (y.value = new e({
49
+ k || (b.value = new e({
45
50
  gallery: r.value,
46
51
  children: i,
47
52
  pswpModule: () => import("photoswipe"),
48
53
  loop: c,
49
54
  wheelToZoom: !0,
50
55
  secondaryZoomLevel: (e) => Math.min(1, p / (e.elementSize?.x || p)),
51
- closeTitle: E("action.close"),
52
- zoomTitle: E("lightbox.zoom"),
53
- arrowPrevTitle: E("action.previous"),
54
- arrowNextTitle: E("action.next"),
55
- errorMsg: E("label.imageLoadError"),
56
+ closeTitle: w("action.close"),
57
+ zoomTitle: w("lightbox.zoom"),
58
+ arrowPrevTitle: w("action.previous"),
59
+ arrowNextTitle: w("action.next"),
60
+ errorMsg: w("label.imageLoadError"),
56
61
  arrowPrevSVG: "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m10.828 12l4.95 4.95l-1.414 1.415L8 12l6.364-6.364l1.414 1.414z\"/></svg>",
57
62
  arrowNextSVG: "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m13.172 12l-4.95-4.95l1.414-1.413L16 12l-6.364 6.364l-1.414-1.415z\"/></svg>",
58
63
  closeSVG: "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m12 10.587l4.95-4.95l1.414 1.414l-4.95 4.95l4.95 4.95l-1.415 1.414l-4.95-4.95l-4.949 4.95l-1.414-1.415l4.95-4.95l-4.95-4.95L7.05 5.638z\"/></svg>",
59
64
  zoomSVG: "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><g class=\"pswp__icn--zoom-in\"><path fill=\"#ffffff\" d=\"m18.031 16.617l4.283 4.282l-1.415 1.415l-4.282-4.283A8.96 8.96 0 0 1 11 20c-4.968 0-9-4.032-9-9s4.032-9 9-9s9 4.032 9 9a8.96 8.96 0 0 1-1.969 5.617m-2.006-.742A6.98 6.98 0 0 0 18 11c0-3.867-3.133-7-7-7s-7 3.133-7 7s3.133 7 7 7a6.98 6.98 0 0 0 4.875-1.975zM10 10V7h2v3h3v2h-3v3h-2v-3H7v-2z\"/></g><g class=\"pswp__icn--zoom-out\"><path fill=\"#ffffff\" d=\"m18.031 16.617l4.283 4.282l-1.415 1.415l-4.282-4.283A8.96 8.96 0 0 1 11 20c-4.968 0-9-4.032-9-9s4.032-9 9-9s9 4.032 9 9a8.96 8.96 0 0 1-1.969 5.617m-2.006-.742A6.98 6.98 0 0 0 18 11c0-3.867-3.133-7-7-7s-7 3.133-7 7s3.133 7 7 7a6.98 6.98 0 0 0 4.875-1.975zM7 10h8v2H7z\"/></g></svg>"
60
- }), y.value.addFilter("domItemData", (e, t, n) => {
65
+ }), b.value.addFilter("domItemData", (e, t, n) => {
61
66
  if (n) return {
62
67
  ...e,
63
68
  caption: n.dataset.pswpCaption
@@ -73,8 +78,11 @@ function y(n) {
73
78
  alt: t.alt,
74
79
  caption: t.alt
75
80
  };
76
- }), y.value.on("uiRegister", () => {
77
- y.value?.pswp?.ui?.registerElement({
81
+ }), b.value.on("uiRegister", () => {
82
+ let e = b.value?.pswp?.ui;
83
+ e && (e.uiElementsData = e.uiElementsData.map(T));
84
+ }), b.value.on("uiRegister", () => {
85
+ b.value?.pswp?.ui?.registerElement({
78
86
  name: "caption",
79
87
  className: "pswp__caption pswp__hide-on-close",
80
88
  appendTo: "root",
@@ -85,87 +93,87 @@ function y(n) {
85
93
  });
86
94
  }
87
95
  });
88
- }), S && y.value.on("uiRegister", () => {
89
- y.value?.pswp?.ui?.registerElement({
96
+ }), C && b.value.on("uiRegister", () => {
97
+ b.value?.pswp?.ui?.registerElement({
90
98
  name: "annotate-button",
91
- order: 6,
99
+ order: h.annotate,
92
100
  isButton: !0,
93
- html: w,
94
- title: E("lightbox.annotate"),
101
+ html: D,
102
+ title: w("lightbox.annotate"),
95
103
  onInit: (e, t) => {
96
104
  let n = () => {
97
- let n = C(t);
98
- e.hidden = !n || !M(n) || !S.available();
105
+ let n = E(t);
106
+ e.hidden = !n || !F(n) || !C.available();
99
107
  };
100
- t.on("change", n), t.on("destroy", o(S.available, n));
108
+ t.on("change", n), t.on("destroy", o(C.available, n));
101
109
  },
102
110
  onClick: (e, t, n) => {
103
- let r = C(n), i = r && M(r);
104
- if (!i || !S.available()) return;
105
- let a = F(i, n.currSlide?.data.caption);
106
- a.catch(() => void 0), n.opener.isOpen ? n.close() : n.on("openingAnimationEnd", () => n.close()), S.annotate(a);
111
+ let r = E(n), i = r && F(r);
112
+ if (!i || !C.available()) return;
113
+ let a = R(i, n.currSlide?.data.caption);
114
+ a.catch(() => void 0), n.opener.isOpen ? n.close() : n.on("openingAnimationEnd", () => n.close()), C.annotate(a);
107
115
  }
108
116
  });
109
- }), A() && y.value.on("uiRegister", () => {
110
- y.value?.pswp?.ui?.registerElement({
117
+ }), N() && b.value.on("uiRegister", () => {
118
+ b.value?.pswp?.ui?.registerElement({
111
119
  name: "copy-button",
112
- order: 7,
120
+ order: h.copy,
113
121
  isButton: !0,
114
- html: T,
115
- title: E("lightbox.copy"),
122
+ html: O,
123
+ title: w("lightbox.copy"),
116
124
  onInit: (e, t) => {
117
125
  t.on("change", () => {
118
- let n = C(t);
119
- e.hidden = !n || !j(n);
126
+ let n = E(t);
127
+ e.hidden = !n || !P(n);
120
128
  });
121
129
  },
122
130
  onClick: (e, t, n) => {
123
- let r = C(n), i = r && j(r);
124
- i && L(i, t, {
125
- copy: E("lightbox.copy"),
126
- copied: E("lightbox.copied"),
127
- failed: E("lightbox.copyFailed")
131
+ let r = E(n), i = r && P(r);
132
+ i && B(i, t, {
133
+ copy: w("lightbox.copy"),
134
+ copied: w("lightbox.copied"),
135
+ failed: w("lightbox.copyFailed")
128
136
  });
129
137
  }
130
138
  });
131
- }), (h || u) && y.value.on("uiRegister", () => {
132
- let e = y.value.pswp?.ui;
133
- e && (h && e.registerElement({
139
+ }), (g || u) && b.value.on("uiRegister", () => {
140
+ let e = b.value.pswp?.ui;
141
+ e && (g && e.registerElement({
134
142
  name: "open-in-new-tab-button",
135
- order: 8,
143
+ order: h.openInNewTab,
136
144
  isButton: !0,
137
145
  html: "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M10 6v2H5v11h11v-5h2v6a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1zm11-3v8h-2V6.413l-7.793 7.794l-1.414-1.414L17.585 5H13V3z\"/></svg>",
138
- title: E("lightbox.openInNewTab"),
146
+ title: w("lightbox.openInNewTab"),
139
147
  onClick: (e, t, n) => {
140
- let r = C(n);
148
+ let r = E(n);
141
149
  r && window.open(r, "_blank", "noopener,noreferrer");
142
150
  }
143
151
  }), u && e.registerElement({
144
152
  name: "download-button",
145
- order: 9,
153
+ order: h.download,
146
154
  isButton: !0,
147
155
  html: "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M3 19h18v2H3zm10-5.828L19.071 7.1l1.414 1.414L12 17L3.515 8.515L4.929 7.1L11 13.173V2h2z\"/></svg>",
148
- title: E("action.download"),
156
+ title: w("action.download"),
149
157
  onClick: (e, t, n) => {
150
- let r = C(n);
151
- r && R(r);
158
+ let r = E(n);
159
+ r && V(r);
152
160
  }
153
161
  }));
154
- }), y.value.on("keydown", (e) => {
155
- let { key: t, ctrlKey: n, metaKey: r, altKey: i } = e.originalEvent, a = m[t], o = y.value?.pswp, s = o?.currSlide;
162
+ }), b.value.on("keydown", (e) => {
163
+ let { key: t, ctrlKey: n, metaKey: r, altKey: i } = e.originalEvent, a = m[t], o = b.value?.pswp, s = o?.currSlide;
156
164
  !a || n || r || i || !s?.isZoomable() || (e.preventDefault(), e.originalEvent.preventDefault(), s.zoomTo(s.currZoomLevel * a, void 0, o?.options.zoomAnimationDuration));
157
- }), y.value.init());
165
+ }), b.value.init());
158
166
  },
159
- shared: !!x
167
+ shared: !!S
160
168
  };
161
169
  }
162
- function b() {
163
- return e(h, void 0);
170
+ function x() {
171
+ return e(g, void 0);
164
172
  }
165
- function x(e) {
166
- let { init: t } = y({
173
+ function S(e) {
174
+ let { init: t } = b({
167
175
  gallery: e,
168
- children: v,
176
+ children: y,
169
177
  loop: !1,
170
178
  annotatable: !0
171
179
  }), i = !1, a = !1, o = async () => {
@@ -178,11 +186,11 @@ function x(e) {
178
186
  }
179
187
  }
180
188
  };
181
- r(h, { join: () => {
189
+ r(g, { join: () => {
182
190
  i = !0, o();
183
191
  } }), n(o);
184
192
  }
185
- function S() {
193
+ function C() {
186
194
  let e = i(/* @__PURE__ */ new Map());
187
195
  return {
188
196
  preload: (t) => {
@@ -206,37 +214,51 @@ function S() {
206
214
  getSize: (t) => e.value.get(t) ?? f
207
215
  };
208
216
  }
209
- function C(e) {
217
+ var w = {
218
+ arrowPrev: "prev",
219
+ arrowNext: "next",
220
+ zoom: "toggleZoom"
221
+ };
222
+ function T(e) {
223
+ let t = w[e.name ?? ""];
224
+ return t ? {
225
+ ...e,
226
+ onClick: (e, n, r) => {
227
+ r.opener.isOpen && r[t]();
228
+ }
229
+ } : e;
230
+ }
231
+ function E(e) {
210
232
  return e.currSlide?.data?.src ?? e.currSlide?.data?.element?.querySelector("img")?.getAttribute("src") ?? e.currSlide?.data?.element?.querySelector("source")?.getAttribute("srcset") ?? e.currSlide?.data?.element?.getAttribute("src") ?? void 0;
211
233
  }
212
- var w = "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m15.243 4.512l-6.738 6.737l-.707 2.121l-1.04 1.041l2.828 2.828l1.04-1.04l2.122-.708l6.737-6.737zm6.364 3.535a1 1 0 0 1 0 1.414l-7.778 7.778l-2.122.707l-1.414 1.415a1 1 0 0 1-1.414 0l-4.243-4.243a1 1 0 0 1 0-1.414L6.05 12.29l.707-2.122l7.779-7.778a1 1 0 0 1 1.414 0zm-6.364-.707l1.414 1.414l-4.95 4.95l-1.414-1.414zm-10.96 9.546l2.828 2.828l-1.414 1.415l-4.243-1.415z\"/></svg>", T = "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M7 6V3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-3v3c0 .552-.45 1-1.007 1H4.007A1 1 0 0 1 3 21l.003-14c0-.552.45-1 1.006-1zM5.002 8L5 20h10V8zM9 6h8v10h2V4H9z\"/></svg>", E = "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m10 15.172l9.192-9.193l1.415 1.414L10 18l-6.364-6.364l1.414-1.414z\"/></svg>", D = "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10s-4.477 10-10 10m0-2a8 8 0 1 0 0-16a8 8 0 0 0 0 16m-1-5h2v2h-2zm0-8h2v6h-2z\"/></svg>", O = 1500, k = /* @__PURE__ */ new WeakMap();
213
- function A() {
234
+ var D = "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m15.243 4.512l-6.738 6.737l-.707 2.121l-1.04 1.041l2.828 2.828l1.04-1.04l2.122-.708l6.737-6.737zm6.364 3.535a1 1 0 0 1 0 1.414l-7.778 7.778l-2.122.707l-1.414 1.415a1 1 0 0 1-1.414 0l-4.243-4.243a1 1 0 0 1 0-1.414L6.05 12.29l.707-2.122l7.779-7.778a1 1 0 0 1 1.414 0zm-6.364-.707l1.414 1.414l-4.95 4.95l-1.414-1.414zm-10.96 9.546l2.828 2.828l-1.414 1.415l-4.243-1.415z\"/></svg>", O = "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M7 6V3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-3v3c0 .552-.45 1-1.007 1H4.007A1 1 0 0 1 3 21l.003-14c0-.552.45-1 1.006-1zM5.002 8L5 20h10V8zM9 6h8v10h2V4H9z\"/></svg>", k = "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m10 15.172l9.192-9.193l1.415 1.414L10 18l-6.364-6.364l1.414-1.414z\"/></svg>", A = "<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10s-4.477 10-10 10m0-2a8 8 0 1 0 0-16a8 8 0 0 0 0 16m-1-5h2v2h-2zm0-8h2v6h-2z\"/></svg>", j = 1500, M = /* @__PURE__ */ new WeakMap();
235
+ function N() {
214
236
  return typeof ClipboardItem < "u" && typeof navigator.clipboard?.write == "function";
215
237
  }
216
- function j(e) {
238
+ function P(e) {
217
239
  if (e.startsWith("blob:") || e.startsWith("data:image/")) return e;
218
240
  if (/\/chats\/[^/]+\/media\/[^/]+\/view(\?|$)/.test(e)) return e.replace(/\/view(\?|$)/, "/content$1");
219
241
  }
220
- function M(e) {
221
- if (!e.startsWith("data:") || /^data:image\/(png|jpeg|webp|gif)[;,]/.test(e)) return j(e);
242
+ function F(e) {
243
+ if (!e.startsWith("data:") || /^data:image\/(png|jpeg|webp|gif)[;,]/.test(e)) return P(e);
222
244
  }
223
- function N(e, t) {
245
+ function I(e, t) {
224
246
  let n = e?.trim();
225
247
  if (n && /\.(png|jpe?g|webp|gif)$/i.test(n)) return n;
226
248
  let r = /^image\/(png|jpeg|webp|gif)$/.exec(t)?.[1];
227
249
  return `image.${r === "jpeg" ? "jpg" : r ?? "png"}`;
228
250
  }
229
- async function P(e) {
251
+ async function L(e) {
230
252
  let t = await fetch(e, { credentials: "include" });
231
253
  if (!t.ok) throw Error(`The image answered ${t.status}`);
232
254
  return t.blob();
233
255
  }
234
- async function F(e, t) {
235
- let n = await P(e);
236
- return new File([n], N(t, n.type), { type: n.type });
256
+ async function R(e, t) {
257
+ let n = await L(e);
258
+ return new File([n], I(t, n.type), { type: n.type });
237
259
  }
238
- async function I(e) {
239
- let t = await P(e);
260
+ async function z(e) {
261
+ let t = await L(e);
240
262
  if (t.type === "image/png") return t;
241
263
  let n = URL.createObjectURL(t);
242
264
  try {
@@ -250,26 +272,26 @@ async function I(e) {
250
272
  URL.revokeObjectURL(n);
251
273
  }
252
274
  }
253
- async function L(e, t, n) {
275
+ async function B(e, t, n) {
254
276
  let r = (e, n) => {
255
277
  t.innerHTML = e, t.title = n, t.setAttribute("aria-label", n);
256
- }, i = I(e);
278
+ }, i = z(e);
257
279
  i.catch(() => void 0);
258
280
  try {
259
- await navigator.clipboard.write([new ClipboardItem({ "image/png": i })]), r(E, n.copied);
281
+ await navigator.clipboard.write([new ClipboardItem({ "image/png": i })]), r(k, n.copied);
260
282
  } catch {
261
- r(D, n.failed);
283
+ r(A, n.failed);
262
284
  }
263
- clearTimeout(k.get(t)), k.set(t, setTimeout(() => r(T, n.copy), O));
285
+ clearTimeout(M.get(t)), M.set(t, setTimeout(() => r(O, n.copy), j));
264
286
  }
265
- function R(e) {
266
- let t = z(e), n = document.createElement("a");
267
- n.href = t, n.target = "_blank", n.rel = "noopener noreferrer", n.download = B(e), document.body.appendChild(n), n.click(), document.body.removeChild(n);
287
+ function V(e) {
288
+ let t = H(e), n = document.createElement("a");
289
+ n.href = t, n.target = "_blank", n.rel = "noopener noreferrer", n.download = U(e), document.body.appendChild(n), n.click(), document.body.removeChild(n);
268
290
  }
269
- function z(e) {
291
+ function H(e) {
270
292
  return e.replace(/\/view(\?|$)/, "/download$1");
271
293
  }
272
- function B(e) {
294
+ function U(e) {
273
295
  if (e.startsWith("data:image/svg+xml")) return "diagram.svg";
274
296
  if (e.startsWith("data:")) return `image.${e.split(":")[1].split(";")[0].split("/")[1] || "bin"}`;
275
297
  try {
@@ -279,13 +301,13 @@ function B(e) {
279
301
  return "image";
280
302
  }
281
303
  }
282
- var V = !1;
283
- function H() {
284
- if (V) return;
285
- V = !0;
304
+ var W = !1;
305
+ function G() {
306
+ if (W) return;
307
+ W = !0;
286
308
  let e = document.createElement("style");
287
- e.textContent = ".pswp__counter { font-family: sans-serif; } .pswp { z-index: 2147483647 !important; } .pswp__icn { width: 20px; height: 20px; } .pswp__button { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; } .pswp__button[hidden] { display: none; } .pswp__icn--zoom-out { display: none; } .pswp--zoomed-in .pswp__icn--zoom-in { display: none; } .pswp--zoomed-in .pswp__icn--zoom-out { display: block; } .pswp__button--arrow .pswp__icn {left: auto; right: auto; width: 40px; height: 40px; transform: none; margin-top: -20px; } .pswp__img { background: repeating-conic-gradient(#e6e6e6 0% 25%, #ffffff 0% 50%) 50% / 16px 16px; } .pswp__caption { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(720px, calc(100% - 32px)); padding: 6px 12px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: #ffffff; font: 14px/1.4 sans-serif; text-align: center; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; } .pswp__caption[hidden] { display: none; }", document.head.appendChild(e);
309
+ e.textContent = ".pswp__counter { font-family: sans-serif; } .pswp { z-index: 2147483647 !important; } .pswp__icn { width: 20px; height: 20px; } .pswp__button { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; } .pswp__button[hidden] { display: none; } .pswp__button--zoom { display: none; } .pswp--zoom-allowed .pswp__button--zoom { display: flex; } .pswp__icn--zoom-out { display: none; } .pswp--zoomed-in .pswp__icn--zoom-in { display: none; } .pswp--zoomed-in .pswp__icn--zoom-out { display: block; } .pswp__button--arrow .pswp__icn {left: auto; right: auto; width: 40px; height: 40px; transform: none; margin-top: -20px; } .pswp__img { background: repeating-conic-gradient(#e6e6e6 0% 25%, #ffffff 0% 50%) 50% / 16px 16px; } .pswp__caption { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(720px, calc(100% - 32px)); padding: 6px 12px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: #ffffff; font: 14px/1.4 sans-serif; text-align: center; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; } .pswp__caption[hidden] { display: none; }", document.head.appendChild(e);
288
310
  }
289
- export { b as a, y as i, x as n, u as o, S as r, l as s, _ as t };
311
+ export { x as a, b as i, S as n, u as o, C as r, l as s, v as t };
290
312
 
291
- //# sourceMappingURL=useLightbox-DmtNa8bJ.js.map
313
+ //# sourceMappingURL=useLightbox-DrEFS3gx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLightbox-DrEFS3gx.js","names":["loaded","loadCdnCss","target","root","set","href","link","getShadowRoot","el","PHOTOSWIPE_CSS","DEFAULT_IMAGE_SIZE","MAX_ZOOM_LAYER_WIDTH","ZOOM_KEYS","TOOLBAR_ORDER","SHARED_LIGHTBOX","IMAGE_ANNOTATION","provideImageAnnotation","annotation","SHARED_ITEMS","useLightbox","options","lightbox","shallowRef","sharedLightbox","shared","useSharedLightbox","annotatable","inject","$t","useI18n","unmounted","onBeforeUnmount","gallery","injectPhotoSwipeOverrides","PhotoSwipeLightbox","zoomLevel","linkEl","itemData","element","src","ui","holdUntilOpen","caption","pswp","ANNOTATE_ICON","update","url","getCurrentSlideUrl","annotatableImageUrl","watch","readable","file","readImageFile","canCopyImages","COPY_ICON","readableImageUrl","copyImage","openInNewTab","downloadable","downloadImage","event","factor","key","slide","ctrlKey","metaKey","altKey","provideSharedLightbox","container","joined","started","start","init","provide","onMounted","useImageSizes","sizes","ref","image","images","img","HELD_UNTIL_OPEN","action","data","COPIED_ICON","COPY_FAILED_ICON","COPY_FEEDBACK_MS","copyFeedbackTimers","imageFileName","name","subtype","type","fetchImage","response","blob","readAsPng","objectUrl","canvas","png","resolve","reject","show","icon","label","button","labels","downloadUrl","toDownloadUrl","anchor","getFilenameFromUrl","overridesInjected","style"],"sources":["../../../../packages/utils/src/cdn-css.ts","../../../../packages/components/src/composables/useLightbox.ts"],"sourcesContent":["const loaded = new WeakMap<Node, Set<string>>()\n\n/**\n * Injects a CDN stylesheet `<link>` once per URL per root.\n * When a `ShadowRoot` is passed, the link is appended there so that\n * custom-element (Shadow DOM) encapsulation is respected.\n * Falls back to `document.head` for regular DOM usage.\n */\nexport function loadCdnCss(href: string, root?: ShadowRoot) {\n const target: Node = root ?? document.head\n let set = loaded.get(target)\n if (!set) {\n set = new Set()\n loaded.set(target, set)\n }\n if (set.has(href)) {\n return\n }\n const link = document.createElement('link')\n link.rel = 'stylesheet'\n link.href = href\n target.appendChild(link)\n set.add(href)\n}\n\n/** Returns the `ShadowRoot` ancestor of `el`, or `undefined` in regular DOM. */\nexport function getShadowRoot(el?: Element | null): ShadowRoot | undefined {\n const root = el?.getRootNode?.()\n return root instanceof ShadowRoot ? root : undefined\n}\n","import {\n inject,\n onBeforeUnmount,\n onMounted,\n provide,\n ref,\n shallowRef,\n watch,\n type InjectionKey,\n type Ref,\n type ShallowRef,\n} from 'vue'\nimport { useI18n } from 'vue-i18n'\nimport type PhotoSwipeLightbox from 'photoswipe/lightbox'\nimport type PhotoSwipe from 'photoswipe'\nimport type { UIElementData } from 'photoswipe'\nimport { loadCdnCss } from 'utils'\n\nconst PHOTOSWIPE_CSS =\n 'https://cdn.jsdelivr.net/npm/photoswipe@5/dist/photoswipe.css'\n\nconst DEFAULT_IMAGE_SIZE = { width: 1200, height: 800 }\n\n// The widest layer a zoom may draw, PhotoSwipe's own cap for its default\n// secondary zoom level: past it a very large image stops short of 100%.\nconst MAX_ZOOM_LAYER_WIDTH = 4000\n\n// The zoom factor of one press of `+` or `-`, with or without Shift.\nconst ZOOM_KEYS: Record<string, number | undefined> = {\n '+': 1.25,\n '=': 1.25,\n '-': 0.8,\n _: 0.8,\n}\n\n// PhotoSwipe's top bar runs by `order`: the counter (5) on the left, then the\n// preloader (7), whose `margin-right: auto` pushes everything after it to the\n// right, then zoom (10) and close (20). Our buttons sit between the preloader\n// and zoom, each with an order of its own: on a tie the bar falls back on the\n// order of registration.\nconst TOOLBAR_ORDER = {\n annotate: 8,\n copy: 8.5,\n openInNewTab: 9,\n download: 9.5,\n}\n\n/** The shared lightbox of a container, as the components inside see it. */\nexport interface SharedLightbox {\n /** An item joined: the first one starts the lightbox. */\n join: () => void\n}\n\n/** Lets the components inside a container join its shared lightbox. */\nconst SHARED_LIGHTBOX: InjectionKey<SharedLightbox> = Symbol('sharedLightbox')\n\n/**\n * \"Annota e chiedi\" (spec `chat-image-editor.md`, F3): a conversation with a\n * composer takes an annotated copy of one of its images as an attachment.\n */\nexport interface ImageAnnotation {\n /** The composer takes an image now: it is shown, uploads on, not full. */\n available: () => boolean\n /** Opens the editor on the image, whose bytes arrive in `file`. */\n annotate: (file: Promise<File>) => void\n}\n\n/** Offers \"Annota e chiedi\" to the lightboxes of the components inside. */\nconst IMAGE_ANNOTATION: InjectionKey<ImageAnnotation> =\n Symbol('imageAnnotation')\n\n/**\n * Gives the lightboxes inside the \"Annota e chiedi\" button: only the chat\n * with a composer calls it, so a log of conversations shows none.\n */\nexport function provideImageAnnotation(annotation: ImageAnnotation): void {\n provide(IMAGE_ANNOTATION, annotation)\n}\n\n/**\n * The items of a shared lightbox: the anchors of the components that joined\n * it, and the images of a markdown that joined it, except an image inside a\n * link, which opens the link.\n */\nconst SHARED_ITEMS =\n 'a[data-pswp-src][data-pswp-shared], [data-pswp-images] img:not(a img)'\n\nexport interface LightboxImage {\n url: string\n caption?: string\n alt?: string\n /** Natural width in px, used by PhotoSwipe for proper sizing. */\n width?: number\n /** Natural height in px, used by PhotoSwipe for proper sizing. */\n height?: number\n}\n\nexport interface LightboxOptions {\n /** Container element whose child anchors are the gallery items */\n gallery: Readonly<Ref<HTMLElement | null | undefined>>\n /** CSS selector for gallery items inside the container (default: `'a[data-pswp-src]'`) */\n children?: string\n loop?: boolean\n /** Show a download button in the lightbox toolbar */\n downloadable?: boolean\n /** Show an open-in-new-tab button in the lightbox toolbar */\n openInNewTab?: boolean\n /**\n * Hands the items to the shared lightbox of a container above\n * (`provideSharedLightbox`), when there is one.\n */\n shared?: boolean\n /**\n * Offers \"Annota e chiedi\" where a chat provides it\n * (`provideImageAnnotation`): the conversation's lightbox only, not the\n * one of an attachment still in the composer, which has its own editor.\n */\n annotatable?: boolean\n}\n\nexport interface UseLightboxReturn {\n lightbox: ShallowRef<PhotoSwipeLightbox | null>\n /** Initialises PhotoSwipe. Call this inside `onMounted`. */\n init: () => Promise<void>\n /**\n * The items went to a shared lightbox: their anchors carry\n * `data-pswp-shared`, and `init` starts that lightbox instead.\n */\n shared: boolean\n}\n\n/**\n * Encapsulates PhotoSwipe 5 initialisation, toolbar customisation, and lifecycle cleanup.\n * CSS is injected into `document.head` so the overlay works in both regular DOM and Shadow DOM.\n *\n * Usage:\n * ```ts\n * const { init } = useLightbox({ gallery: galleryRef, downloadable: true })\n * onMounted(init)\n * ```\n */\nexport function useLightbox(options: LightboxOptions): UseLightboxReturn {\n const {\n gallery,\n children = 'a[data-pswp-src]',\n loop = true,\n downloadable = true,\n openInNewTab = true,\n shared = false,\n annotatable = false,\n } = options\n\n const lightbox = shallowRef<PhotoSwipeLightbox | null>(null)\n const sharedLightbox = shared ? useSharedLightbox() : undefined\n const annotation = annotatable\n ? inject(IMAGE_ANNOTATION, undefined)\n : undefined\n const { t: $t } = useI18n({ useScope: 'global' })\n let unmounted = false\n\n const init = async () => {\n if (sharedLightbox) {\n sharedLightbox.join()\n return\n }\n if (!gallery.value) {\n return\n }\n\n // PhotoSwipe renders its overlay into document.body, so CSS must be in\n // document.head, not inside a shadow root.\n loadCdnCss(PHOTOSWIPE_CSS)\n injectPhotoSwipeOverrides()\n\n const { default: PhotoSwipeLightbox } =\n await import('photoswipe/lightbox')\n // Unmounted while PhotoSwipe loaded: nothing left to destroy it\n if (unmounted) {\n return\n }\n\n lightbox.value = new PhotoSwipeLightbox({\n gallery: gallery.value,\n children,\n pswpModule: () => import('photoswipe'),\n loop,\n // The wheel zooms around the pointer, as an image viewer does;\n // a drag pans\n wheelToZoom: true,\n // A click, a double tap, the zoom button and Z go from fit to the\n // real pixels, where PhotoSwipe stops at three times fit\n secondaryZoomLevel: (zoomLevel) =>\n Math.min(\n 1,\n MAX_ZOOM_LAYER_WIDTH /\n (zoomLevel.elementSize?.x || MAX_ZOOM_LAYER_WIDTH),\n ),\n closeTitle: $t('action.close'),\n zoomTitle: $t('lightbox.zoom'),\n arrowPrevTitle: $t('action.previous'),\n arrowNextTitle: $t('action.next'),\n errorMsg: $t('label.imageLoadError'),\n arrowPrevSVG:\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m10.828 12l4.95 4.95l-1.414 1.415L8 12l6.364-6.364l1.414 1.414z\"/></svg>',\n arrowNextSVG:\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m13.172 12l-4.95-4.95l1.414-1.413L16 12l-6.364 6.364l-1.414-1.415z\"/></svg>',\n closeSVG:\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m12 10.587l4.95-4.95l1.414 1.414l-4.95 4.95l4.95 4.95l-1.415 1.414l-4.95-4.95l-4.949 4.95l-1.414-1.415l4.95-4.95l-4.95-4.95L7.05 5.638z\"/></svg>',\n zoomSVG:\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><g class=\"pswp__icn--zoom-in\"><path fill=\"#ffffff\" d=\"m18.031 16.617l4.283 4.282l-1.415 1.415l-4.282-4.283A8.96 8.96 0 0 1 11 20c-4.968 0-9-4.032-9-9s4.032-9 9-9s9 4.032 9 9a8.96 8.96 0 0 1-1.969 5.617m-2.006-.742A6.98 6.98 0 0 0 18 11c0-3.867-3.133-7-7-7s-7 3.133-7 7s3.133 7 7 7a6.98 6.98 0 0 0 4.875-1.975zM10 10V7h2v3h3v2h-3v3h-2v-3H7v-2z\"/></g><g class=\"pswp__icn--zoom-out\"><path fill=\"#ffffff\" d=\"m18.031 16.617l4.283 4.282l-1.415 1.415l-4.282-4.283A8.96 8.96 0 0 1 11 20c-4.968 0-9-4.032-9-9s4.032-9 9-9s9 4.032 9 9a8.96 8.96 0 0 1-1.969 5.617m-2.006-.742A6.98 6.98 0 0 0 18 11c0-3.867-3.133-7-7-7s-7 3.133-7 7s3.133 7 7 7a6.98 6.98 0 0 0 4.875-1.975zM7 10h8v2H7z\"/></g></svg>',\n })\n\n // A markdown image is the `<img>` itself, already loaded: its source\n // and natural size stand in for the data attributes of an anchor\n lightbox.value.addFilter('domItemData', (itemData, element, linkEl) => {\n if (linkEl) {\n return { ...itemData, caption: linkEl.dataset.pswpCaption }\n }\n if (!(element instanceof HTMLImageElement)) {\n return itemData\n }\n const src = element.currentSrc || element.src\n return {\n ...itemData,\n src,\n msrc: src,\n width: element.naturalWidth || DEFAULT_IMAGE_SIZE.width,\n height: element.naturalHeight || DEFAULT_IMAGE_SIZE.height,\n alt: element.alt,\n caption: element.alt,\n }\n })\n\n // The arrows and the zoom button wait for the lightbox to open, as\n // the keyboard does\n lightbox.value.on('uiRegister', () => {\n const ui = lightbox.value?.pswp?.ui\n if (ui) {\n ui.uiElementsData = ui.uiElementsData.map(holdUntilOpen)\n }\n })\n\n // The caption under the image, as text: the agent or a page it read\n // may have written it\n lightbox.value.on('uiRegister', () => {\n lightbox.value?.pswp?.ui?.registerElement({\n name: 'caption',\n className: 'pswp__caption pswp__hide-on-close',\n appendTo: 'root',\n onInit: (element, pswp) => {\n pswp.on('change', () => {\n const caption = pswp.currSlide?.data.caption ?? ''\n element.textContent = caption\n element.hidden = !caption\n })\n },\n })\n })\n\n // Annotate the image and ask about it: the lightbox closes, the\n // editor opens while the bytes arrive, and the copy joins the\n // attachments of the composer\n if (annotation) {\n lightbox.value.on('uiRegister', () => {\n lightbox.value?.pswp?.ui?.registerElement({\n name: 'annotate-button',\n order: TOOLBAR_ORDER.annotate,\n isButton: true,\n html: ANNOTATE_ICON,\n title: $t('lightbox.annotate'),\n onInit: (element, pswp) => {\n const update = () => {\n const url = getCurrentSlideUrl(pswp)\n element.hidden =\n !url ||\n !annotatableImageUrl(url) ||\n !annotation.available()\n }\n pswp.on('change', update)\n // The composer fills up, or comes back as a call\n // ends, while the lightbox stays on one slide\n pswp.on('destroy', watch(annotation.available, update))\n },\n onClick: (_, __, pswp) => {\n const url = getCurrentSlideUrl(pswp)\n const readable = url && annotatableImageUrl(url)\n if (!readable || !annotation.available()) {\n return\n }\n const file = readImageFile(\n readable,\n pswp.currSlide?.data.caption,\n )\n // The editor reads it; one that never opens must not\n // leave its failure unhandled\n void file.catch(() => undefined)\n // PhotoSwipe ignores a close while it opens: a quick\n // click left it over the page, trapping the focus\n if (pswp.opener.isOpen) {\n pswp.close()\n } else {\n pswp.on('openingAnimationEnd', () => pswp.close())\n }\n annotation.annotate(file)\n },\n })\n })\n }\n\n // Copy the image, on the slides whose bytes a page may read\n if (canCopyImages()) {\n lightbox.value.on('uiRegister', () => {\n lightbox.value?.pswp?.ui?.registerElement({\n name: 'copy-button',\n order: TOOLBAR_ORDER.copy,\n isButton: true,\n html: COPY_ICON,\n title: $t('lightbox.copy'),\n onInit: (element, pswp) => {\n pswp.on('change', () => {\n const url = getCurrentSlideUrl(pswp)\n element.hidden = !url || !readableImageUrl(url)\n })\n },\n onClick: (_, element, pswp) => {\n const url = getCurrentSlideUrl(pswp)\n const readable = url && readableImageUrl(url)\n if (!readable) {\n return\n }\n void copyImage(readable, element, {\n copy: $t('lightbox.copy'),\n copied: $t('lightbox.copied'),\n failed: $t('lightbox.copyFailed'),\n })\n },\n })\n })\n }\n\n if (openInNewTab || downloadable) {\n lightbox.value.on('uiRegister', () => {\n const ui = lightbox.value!.pswp?.ui\n if (!ui) {\n return\n }\n\n if (openInNewTab) {\n ui.registerElement({\n name: 'open-in-new-tab-button',\n order: TOOLBAR_ORDER.openInNewTab,\n isButton: true,\n html: '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M10 6v2H5v11h11v-5h2v6a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1zm11-3v8h-2V6.413l-7.793 7.794l-1.414-1.414L17.585 5H13V3z\"/></svg>',\n title: $t('lightbox.openInNewTab'),\n onClick: (_, __, pswp) => {\n const url = getCurrentSlideUrl(pswp)\n if (url) {\n window.open(\n url,\n '_blank',\n 'noopener,noreferrer',\n )\n }\n },\n })\n }\n\n if (downloadable) {\n ui.registerElement({\n name: 'download-button',\n order: TOOLBAR_ORDER.download,\n isButton: true,\n html: '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M3 19h18v2H3zm10-5.828L19.071 7.1l1.414 1.414L12 17L3.515 8.515L4.929 7.1L11 13.173V2h2z\"/></svg>',\n title: $t('action.download'),\n onClick: (_, __, pswp) => {\n const url = getCurrentSlideUrl(pswp)\n if (url) {\n downloadImage(url)\n }\n },\n })\n }\n })\n }\n\n // `+` and `-` zoom by a step around the center of the screen\n lightbox.value.on('keydown', (event) => {\n const { key, ctrlKey, metaKey, altKey } = event.originalEvent\n const factor = ZOOM_KEYS[key]\n const pswp = lightbox.value?.pswp\n const slide = pswp?.currSlide\n if (\n !factor ||\n ctrlKey ||\n metaKey ||\n altKey ||\n !slide?.isZoomable()\n ) {\n return\n }\n // The first stops PhotoSwipe's own handling, the second the browser's\n event.preventDefault()\n event.originalEvent.preventDefault()\n slide.zoomTo(\n slide.currZoomLevel * factor,\n undefined,\n pswp?.options.zoomAnimationDuration,\n )\n })\n\n lightbox.value.init()\n }\n\n onBeforeUnmount(() => {\n unmounted = true\n lightbox.value?.destroy()\n lightbox.value = null\n })\n\n return { lightbox, init, shared: Boolean(sharedLightbox) }\n}\n\n/**\n * The shared lightbox above that takes this component's images, if any: a\n * markdown marks its container with `data-pswp-images` and joins when it\n * shows an image.\n */\nexport function useSharedLightbox(): SharedLightbox | undefined {\n return inject(SHARED_LIGHTBOX, undefined)\n}\n\n/**\n * One lightbox over the images of a container, a conversation: the arrows go\n * through all of them in page order instead of stopping at the card that was\n * clicked. The components inside that pass `shared` to `useLightbox` skip a\n * lightbox of their own and mark their anchors with `data-pswp-shared`; the\n * others, such as a diagram's, keep theirs. It starts when the first image\n * joins, so a conversation without images loads no PhotoSwipe.\n */\nexport function provideSharedLightbox(\n container: Readonly<Ref<HTMLElement | null | undefined>>,\n): void {\n const { init } = useLightbox({\n gallery: container,\n children: SHARED_ITEMS,\n loop: false,\n annotatable: true,\n })\n let joined = false\n let started = false\n const start = async () => {\n if (!joined || started || !container.value) {\n return\n }\n started = true\n try {\n await init()\n } catch {\n // PhotoSwipe did not load: the next image that joins tries again\n started = false\n }\n }\n provide(SHARED_LIGHTBOX, {\n join: () => {\n joined = true\n void start()\n },\n })\n // An image may join before the container is in place\n onMounted(start)\n}\n\n// ---------------------------------------------------------------------------\n// Image size preloading\n// ---------------------------------------------------------------------------\n\nexport interface UseImageSizesReturn {\n preload: (\n images: Array<{ url: string; width?: number; height?: number }>,\n ) => void\n getSize: (url: string) => { width: number; height: number }\n}\n\n/**\n * Preloads natural image dimensions so PhotoSwipe can size its slides correctly.\n * When `width`/`height` are already provided they are used as-is;\n * otherwise the image is loaded in the background to read `naturalWidth`/`naturalHeight`.\n */\nexport function useImageSizes(): UseImageSizesReturn {\n const sizes = ref(new Map<string, { width: number; height: number }>())\n\n const preload = (\n images: Array<{ url: string; width?: number; height?: number }>,\n ) => {\n for (const image of images) {\n if (image.width && image.height) {\n sizes.value.set(image.url, {\n width: image.width,\n height: image.height,\n })\n continue\n }\n const img = new Image()\n img.onload = () => {\n sizes.value.set(image.url, {\n width: img.naturalWidth,\n height: img.naturalHeight,\n })\n }\n img.src = image.url\n }\n }\n\n const getSize = (url: string) => sizes.value.get(url) ?? DEFAULT_IMAGE_SIZE\n\n return { preload, getSize }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n// PhotoSwipe's buttons that act on the slides, by the method they call.\nconst HELD_UNTIL_OPEN: Record<\n string,\n 'prev' | 'next' | 'toggleZoom' | undefined\n> = {\n arrowPrev: 'prev',\n arrowNext: 'next',\n zoom: 'toggleZoom',\n}\n\n/**\n * PhotoSwipe's arrows and zoom button, still until the lightbox has opened.\n * PhotoSwipe holds the keyboard and the gestures until its opening animation\n * ends, but not these buttons. An arrow pressed sooner landed on a slot the\n * end of the opening neither shows nor fills: empty, with no caption and\n * none of the buttons that read the slide. A zoom pressed sooner was still\n * animating when the opening's animation ended, which then never completed\n * the opening: the lightbox stayed over the page and no longer closed. Any\n * other element of the bar is returned as it is.\n */\nexport function holdUntilOpen(data: UIElementData): UIElementData {\n const action = HELD_UNTIL_OPEN[data.name ?? '']\n if (!action) {\n return data\n }\n return {\n ...data,\n onClick: (_, __, pswp) => {\n if (pswp.opener.isOpen) {\n pswp[action]()\n }\n },\n }\n}\n\nfunction getCurrentSlideUrl(pswp: PhotoSwipe): string | undefined {\n return (\n pswp.currSlide?.data?.src ??\n pswp.currSlide?.data?.element\n ?.querySelector('img')\n ?.getAttribute('src') ??\n pswp.currSlide?.data?.element\n ?.querySelector('source')\n ?.getAttribute('srcset') ??\n pswp.currSlide?.data?.element?.getAttribute('src') ??\n undefined\n )\n}\n\nconst ANNOTATE_ICON =\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m15.243 4.512l-6.738 6.737l-.707 2.121l-1.04 1.041l2.828 2.828l1.04-1.04l2.122-.708l6.737-6.737zm6.364 3.535a1 1 0 0 1 0 1.414l-7.778 7.778l-2.122.707l-1.414 1.415a1 1 0 0 1-1.414 0l-4.243-4.243a1 1 0 0 1 0-1.414L6.05 12.29l.707-2.122l7.779-7.778a1 1 0 0 1 1.414 0zm-6.364-.707l1.414 1.414l-4.95 4.95l-1.414-1.414zm-10.96 9.546l2.828 2.828l-1.414 1.415l-4.243-1.415z\"/></svg>'\nconst COPY_ICON =\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M7 6V3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-3v3c0 .552-.45 1-1.007 1H4.007A1 1 0 0 1 3 21l.003-14c0-.552.45-1 1.006-1zM5.002 8L5 20h10V8zM9 6h8v10h2V4H9z\"/></svg>'\nconst COPIED_ICON =\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m10 15.172l9.192-9.193l1.415 1.414L10 18l-6.364-6.364l1.414-1.414z\"/></svg>'\nconst COPY_FAILED_ICON =\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10s-4.477 10-10 10m0-2a8 8 0 1 0 0-16a8 8 0 0 0 0 16m-1-5h2v2h-2zm0-8h2v6h-2z\"/></svg>'\n\n// How long the button shows the outcome of a copy before it is a copy again.\nconst COPY_FEEDBACK_MS = 1500\nconst copyFeedbackTimers = new WeakMap<\n HTMLElement,\n ReturnType<typeof setTimeout>\n>()\n\n/** The browser can put an image on the clipboard. */\nfunction canCopyImages(): boolean {\n return (\n typeof ClipboardItem !== 'undefined' &&\n typeof navigator.clipboard?.write === 'function'\n )\n}\n\n/**\n * Where a page may read the bytes of a slide: a chat file through its\n * `/content` route, since its `/view` link redirects to the storage host,\n * which answers no page's CORS; an upload of this session or an inline image\n * as they are. Any other host would refuse the read, so that slide offers no\n * copy.\n */\nfunction readableImageUrl(url: string): string | undefined {\n if (url.startsWith('blob:') || url.startsWith('data:image/')) {\n return url\n }\n if (/\\/chats\\/[^/]+\\/media\\/[^/]+\\/view(\\?|$)/.test(url)) {\n return url.replace(/\\/view(\\?|$)/, '/content$1')\n }\n return undefined\n}\n\n/**\n * Where the editor may read the bytes of a slide: one a page may read\n * (`readableImageUrl`) that the canvas decodes, so not an inline drawing,\n * such as the SVG of a diagram.\n */\nexport function annotatableImageUrl(url: string): string | undefined {\n if (\n url.startsWith('data:') &&\n !/^data:image\\/(png|jpeg|webp|gif)[;,]/.test(url)\n ) {\n return undefined\n }\n return readableImageUrl(url)\n}\n\n/**\n * The name of the copy of an image: its caption when that is a file name,\n * as an attachment's is, else `image` with the extension of its type.\n */\nexport function imageFileName(\n caption: string | undefined,\n type: string,\n): string {\n const name = caption?.trim()\n if (name && /\\.(png|jpe?g|webp|gif)$/i.test(name)) {\n return name\n }\n const subtype = /^image\\/(png|jpeg|webp|gif)$/.exec(type)?.[1]\n return `image.${subtype === 'jpeg' ? 'jpg' : (subtype ?? 'png')}`\n}\n\n/** The bytes of the image at `url`, a readable one. */\nasync function fetchImage(url: string): Promise<Blob> {\n const response = await fetch(url, { credentials: 'include' })\n if (!response.ok) {\n throw new Error(`The image answered ${response.status}`)\n }\n return response.blob()\n}\n\n/** The image at `url` as a file, for the editor. */\nasync function readImageFile(url: string, caption?: string): Promise<File> {\n const blob = await fetchImage(url)\n return new File([blob], imageFileName(caption, blob.type), {\n type: blob.type,\n })\n}\n\n/**\n * The image at `url` as a PNG, the one type every browser puts on the\n * clipboard: another type is drawn on a canvas first.\n */\nasync function readAsPng(url: string): Promise<Blob> {\n const blob = await fetchImage(url)\n if (blob.type === 'image/png') {\n return blob\n }\n // An `<img>` and not `createImageBitmap`, which refuses an SVG\n const objectUrl = URL.createObjectURL(blob)\n try {\n const image = new Image()\n image.src = objectUrl\n await image.decode()\n const canvas = document.createElement('canvas')\n canvas.width = image.naturalWidth\n canvas.height = image.naturalHeight\n canvas.getContext('2d')?.drawImage(image, 0, 0)\n return await new Promise<Blob>((resolve, reject) => {\n canvas.toBlob(\n (png) =>\n png ? resolve(png) : reject(new Error('No PNG was drawn')),\n 'image/png',\n )\n })\n } finally {\n URL.revokeObjectURL(objectUrl)\n }\n}\n\n/**\n * Copies the image and shows on the button how it went. The PNG goes to the\n * clipboard as a promise, so Safari still counts the click as the gesture\n * while the bytes arrive.\n */\nasync function copyImage(\n url: string,\n button: HTMLElement,\n labels: { copy: string; copied: string; failed: string },\n): Promise<void> {\n const show = (icon: string, label: string) => {\n button.innerHTML = icon\n button.title = label\n button.setAttribute('aria-label', label)\n }\n const png = readAsPng(url)\n // The clipboard reads it below; a browser that refuses a promise in\n // `ClipboardItem` never does, and its failure must not go unhandled\n void png.catch(() => undefined)\n try {\n await navigator.clipboard.write([\n new ClipboardItem({ 'image/png': png }),\n ])\n show(COPIED_ICON, labels.copied)\n } catch {\n show(COPY_FAILED_ICON, labels.failed)\n }\n // A second copy restarts the wait instead of being cut short by the first\n clearTimeout(copyFeedbackTimers.get(button))\n copyFeedbackTimers.set(\n button,\n setTimeout(() => show(COPY_ICON, labels.copy), COPY_FEEDBACK_MS),\n )\n}\n\n/**\n * Triggers a client-side download for an image URL.\n *\n * For backend media URLs (.../media/:file/view), navigates to the\n * corresponding /download endpoint which redirects to an Azure SAS URL\n * with `Content-Disposition: attachment`, so no CORS issues.\n *\n * For blob: URLs (in-session uploads), uses the fetch → blob approach.\n *\n * For data: URLs (inline SVGs, etc.), use the download attribute.\n *\n * Falls back to opening in a new tab for all other cases.\n */\nfunction downloadImage(url: string): void {\n const downloadUrl = toDownloadUrl(url)\n\n const anchor = document.createElement('a')\n anchor.href = downloadUrl\n anchor.target = '_blank'\n anchor.rel = 'noopener noreferrer'\n // `download` attribute works for same-origin, data: and blob: URLs; for\n // cross-origin it is ignored but the browser still follows Content-Disposition.\n anchor.download = getFilenameFromUrl(url)\n document.body.appendChild(anchor)\n anchor.click()\n document.body.removeChild(anchor)\n}\n\n/**\n * Converts a `/view` media URL to its `/download` counterpart.\n * Leaves blob:, data: and all other URLs untouched.\n */\nfunction toDownloadUrl(url: string): string {\n return url.replace(/\\/view(\\?|$)/, '/download$1')\n}\n\nfunction getFilenameFromUrl(url: string): string {\n if (url.startsWith('data:image/svg+xml')) {\n return 'diagram.svg'\n }\n if (url.startsWith('data:')) {\n const mime = url.split(':')[1].split(';')[0]\n const ext = mime.split('/')[1] || 'bin'\n return `image.${ext}`\n }\n try {\n const pathname = new URL(url).pathname\n const name = pathname.split('/').pop()\n return name && name.includes('.') ? name : 'image'\n } catch {\n return 'image'\n }\n}\n\nlet overridesInjected = false\n\n/**\n * Injects a one-time `<style>` into `document.head` that raises\n * PhotoSwipe's z-index above any host UI (e.g. floating chat widgets\n * that use `z-index: 2147483647`), sizes its icons, lays a checkerboard\n * under transparent images and places the caption.\n */\nfunction injectPhotoSwipeOverrides(): void {\n if (overridesInjected) {\n return\n }\n overridesInjected = true\n const style = document.createElement('style')\n style.textContent = [\n '.pswp__counter { font-family: sans-serif; }',\n '.pswp { z-index: 2147483647 !important; }',\n '.pswp__icn { width: 20px; height: 20px; }',\n '.pswp__button { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; }',\n '.pswp__button[hidden] { display: none; }',\n // Zoom only where the slide zooms, as PhotoSwipe has it: the rule\n // above would show it on every slide\n '.pswp__button--zoom { display: none; }',\n '.pswp--zoom-allowed .pswp__button--zoom { display: flex; }',\n '.pswp__icn--zoom-out { display: none; }',\n '.pswp--zoomed-in .pswp__icn--zoom-in { display: none; }',\n '.pswp--zoomed-in .pswp__icn--zoom-out { display: block; }',\n '.pswp__button--arrow .pswp__icn {left: auto; right: auto; width: 40px; height: 40px; transform: none; margin-top: -20px; }',\n // A checkerboard under the transparent parts of an image, where a\n // dark logo would vanish into the dark backdrop\n '.pswp__img { background: repeating-conic-gradient(#e6e6e6 0% 25%, #ffffff 0% 50%) 50% / 16px 16px; }',\n '.pswp__caption { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(720px, calc(100% - 32px)); padding: 6px 12px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: #ffffff; font: 14px/1.4 sans-serif; text-align: center; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }',\n '.pswp__caption[hidden] { display: none; }',\n ].join(' ')\n document.head.appendChild(style)\n}\n"],"mappings":";;;;AAAA,IAAMA,oBAAS,IAAI,QAA2B;AAQ9C,SAAgBC,EAAW,GAAc,GAAmB;CACxD,IAAMC,IAAeC,KAAQ,SAAS,MAClCC,IAAMJ,EAAO,IAAIE,CAAM;CAK3B,IAJKE,MACD,oBAAM,IAAI,IAAI,GACdJ,EAAO,IAAIE,GAAQE,CAAG,IAEtBA,EAAI,IAAIC,CAAI,GACZ;CAEJ,IAAMC,IAAO,SAAS,cAAc,MAAM;CAI1C,AAHA,EAAK,MAAM,cACX,EAAK,OAAOD,GACZH,EAAO,YAAYI,CAAI,GACvBF,EAAI,IAAIC,CAAI;AAChB;AAGA,SAAgBE,EAAc,GAA6C;CACvE,IAAMJ,IAAOK,GAAI,cAAc;CAC/B,OAAOL,aAAgB,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