@8wave/ai-elements 0.125.0-beta.32 → 0.125.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{PkChatbotFilePreview-CqxtVySb.js → PkChatbotFilePreview-DsRAk1js.js} +2 -2
- package/dist/_chunks/{PkChatbotFilePreview-CqxtVySb.js.map → PkChatbotFilePreview-DsRAk1js.js.map} +1 -1
- package/dist/_chunks/PkImageEditorDialog-BQwM06kT.js +939 -0
- package/dist/_chunks/PkImageEditorDialog-BQwM06kT.js.map +1 -0
- package/dist/_chunks/{PkStreamingMarkdown-BqDooeUU.js → PkStreamingMarkdown-CjL7l_3E.js} +2 -2
- package/dist/_chunks/{PkStreamingMarkdown-BqDooeUU.js.map → PkStreamingMarkdown-CjL7l_3E.js.map} +1 -1
- package/dist/_chunks/{PkToolChatFile-DpStX3wS.js → PkToolChatFile-weptM8iA.js} +2 -2
- package/dist/_chunks/{PkToolChatFile-DpStX3wS.js.map → PkToolChatFile-weptM8iA.js.map} +1 -1
- package/dist/_chunks/{PkToolShareDocument-BvHklbzb.js → PkToolShareDocument-D5K3uJ2x.js} +2 -2
- package/dist/_chunks/{PkToolShareDocument-BvHklbzb.js.map → PkToolShareDocument-D5K3uJ2x.js.map} +1 -1
- package/dist/_chunks/{PkToolShowArtifact-YPwJLLlW.js → PkToolShowArtifact-Bm2zS5YS.js} +2 -2
- package/dist/_chunks/{PkToolShowArtifact-YPwJLLlW.js.map → PkToolShowArtifact-Bm2zS5YS.js.map} +1 -1
- package/dist/_chunks/{PkToolShowContactForm-CTc1mbA8.js → PkToolShowContactForm-BKJCv5To.js} +2 -2
- package/dist/_chunks/{PkToolShowContactForm-CTc1mbA8.js.map → PkToolShowContactForm-BKJCv5To.js.map} +1 -1
- package/dist/_chunks/{PkToolShowDiagram-COt1Z3q9.js → PkToolShowDiagram-jpaEAi2X.js} +2 -2
- package/dist/_chunks/{PkToolShowDiagram-COt1Z3q9.js.map → PkToolShowDiagram-jpaEAi2X.js.map} +1 -1
- package/dist/_chunks/{PkToolShowForm-DT5EyYVY.js → PkToolShowForm-DvAcJgDP.js} +2 -2
- package/dist/_chunks/{PkToolShowForm-DT5EyYVY.js.map → PkToolShowForm-DvAcJgDP.js.map} +1 -1
- package/dist/_chunks/{PkToolShowImageGallery-DKrCrrB5.js → PkToolShowImageGallery-D0htuXNL.js} +4 -4
- package/dist/_chunks/{PkToolShowImageGallery-DKrCrrB5.js.map → PkToolShowImageGallery-D0htuXNL.js.map} +1 -1
- package/dist/_chunks/{PkToolShowSources-CzSknPo6.js → PkToolShowSources-Cfj6iRGj.js} +2 -2
- package/dist/_chunks/{PkToolShowSources-CzSknPo6.js.map → PkToolShowSources-Cfj6iRGj.js.map} +1 -1
- package/dist/_chunks/{useLightbox-D2Zi-Fpe.js → useLightbox-C54BCSbU.js} +130 -89
- package/dist/_chunks/useLightbox-C54BCSbU.js.map +1 -0
- package/dist/ai-elements.es.js +2774 -2721
- package/dist/ai-elements.es.js.map +1 -1
- package/dist-vue/PkChatbot.js +1 -1
- package/dist-vue/PkChatbotEmptyState.js +1 -1
- package/dist-vue/PkChatbotFilePreview.js +1 -1
- package/dist-vue/PkChatbotInput.js +1 -1
- package/dist-vue/PkChatbotMessages.js +1 -1
- package/dist-vue/PkChatbotSteps.js +1 -1
- package/dist-vue/PkChatbotViewChat.js +1 -1
- package/dist-vue/_chunks/{PkChatbot-g-mj6Luo.js → PkChatbot-Bc2hlwFO.js} +3 -3
- package/dist-vue/_chunks/{PkChatbot-g-mj6Luo.js.map → PkChatbot-Bc2hlwFO.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotEmptyState-DMPEj1Qa.js → PkChatbotEmptyState-NHarCaDm.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotEmptyState-DMPEj1Qa.js.map → PkChatbotEmptyState-NHarCaDm.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotFilePreview-j_8sDZUE.js → PkChatbotFilePreview-BIta8Yg-.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotFilePreview-j_8sDZUE.js.map → PkChatbotFilePreview-BIta8Yg-.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotInput-OBoyFkZ-.js → PkChatbotInput-BSzDRoDD.js} +192 -181
- package/dist-vue/_chunks/PkChatbotInput-BSzDRoDD.js.map +1 -0
- package/dist-vue/_chunks/{PkChatbotMessages-bPBOSAv7.js → PkChatbotMessages-DEMKZDCb.js} +17 -17
- package/dist-vue/_chunks/{PkChatbotMessages-bPBOSAv7.js.map → PkChatbotMessages-DEMKZDCb.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotSteps-pibgqxus.js → PkChatbotSteps-DGQoYxJ9.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotSteps-pibgqxus.js.map → PkChatbotSteps-DGQoYxJ9.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotViewChat-C28g7dz-.js → PkChatbotViewChat-aKi08vCz.js} +440 -431
- package/dist-vue/_chunks/PkChatbotViewChat-aKi08vCz.js.map +1 -0
- package/dist-vue/_chunks/{PkFilePreview-BgyJngDt.js → PkFilePreview-D2HInDoA.js} +2 -2
- package/dist-vue/_chunks/{PkFilePreview-BgyJngDt.js.map → PkFilePreview-D2HInDoA.js.map} +1 -1
- package/dist-vue/_chunks/{PkFilePreviewDialog-B3-oF1_R.js → PkFilePreviewDialog-jxcUSzPx.js} +2 -2
- package/dist-vue/_chunks/{PkFilePreviewDialog-B3-oF1_R.js.map → PkFilePreviewDialog-jxcUSzPx.js.map} +1 -1
- package/dist-vue/_chunks/PkImageEditorDialog-Dn3HV_ny.js +934 -0
- package/dist-vue/_chunks/PkImageEditorDialog-Dn3HV_ny.js.map +1 -0
- package/dist-vue/_chunks/{PkStreamingMarkdown-B3VWOaWb.js → PkStreamingMarkdown-DdOv86Eb.js} +11 -11
- package/dist-vue/_chunks/{PkStreamingMarkdown-B3VWOaWb.js.map → PkStreamingMarkdown-DdOv86Eb.js.map} +1 -1
- package/dist-vue/_chunks/{PkSvgViewer-BsdSOBpH.js → PkSvgViewer-vkd5Dluw.js} +2 -2
- package/dist-vue/_chunks/{PkSvgViewer-BsdSOBpH.js.map → PkSvgViewer-vkd5Dluw.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolChatFile-PXpiJLZ6.js → PkToolChatFile-8nx166iM.js} +2 -2
- package/dist-vue/_chunks/{PkToolChatFile-PXpiJLZ6.js.map → PkToolChatFile-8nx166iM.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShareDocument-cMUqik6v.js → PkToolShareDocument-CspvFwRR.js} +2 -2
- package/dist-vue/_chunks/{PkToolShareDocument-cMUqik6v.js.map → PkToolShareDocument-CspvFwRR.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowArtifact-DouCz_dZ.js → PkToolShowArtifact-BppP_xSN.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowArtifact-DouCz_dZ.js.map → PkToolShowArtifact-BppP_xSN.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowContactForm-BmiNlFfx.js → PkToolShowContactForm-Bm0icz24.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowContactForm-BmiNlFfx.js.map → PkToolShowContactForm-Bm0icz24.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowDiagram-D6mYTDU-.js → PkToolShowDiagram-CgukB1Ss.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowDiagram-D6mYTDU-.js.map → PkToolShowDiagram-CgukB1Ss.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowForm-CksTiimD.js → PkToolShowForm-CyyN7GQP.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowForm-CksTiimD.js.map → PkToolShowForm-CyyN7GQP.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowImageGallery-B-lVY0xH.js → PkToolShowImageGallery-zQF_lsxI.js} +5 -5
- package/dist-vue/_chunks/{PkToolShowImageGallery-B-lVY0xH.js.map → PkToolShowImageGallery-zQF_lsxI.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowLocation-B8FE_Sqd.js → PkToolShowLocation-WdRqG8Wi.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowLocation-B8FE_Sqd.js.map → PkToolShowLocation-WdRqG8Wi.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowProductList-Dcq3Kdse.js → PkToolShowProductList-DW_P0gC2.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowProductList-Dcq3Kdse.js.map → PkToolShowProductList-DW_P0gC2.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowSources-DApWmwvk.js → PkToolShowSources-BugMybUx.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowSources-DApWmwvk.js.map → PkToolShowSources-BugMybUx.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowVideo-CjrYh9-q.js → PkToolShowVideo-BW7aRKs_.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowVideo-CjrYh9-q.js.map → PkToolShowVideo-BW7aRKs_.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowWebPages-DSIAizw-.js → PkToolShowWebPages-DxKimT-2.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowWebPages-DSIAizw-.js.map → PkToolShowWebPages-DxKimT-2.js.map} +1 -1
- package/dist-vue/_chunks/{useLightbox-FDyQrPWe.js → useLightbox-Ctl9zaMX.js} +132 -91
- package/dist-vue/_chunks/useLightbox-Ctl9zaMX.js.map +1 -0
- package/dist-vue/composables.js +36 -2
- package/dist-vue/composables.js.map +1 -1
- package/dist-vue/index.js +22 -22
- package/dist-vue/index.js.map +1 -1
- package/dist-vue/locales.js +34 -0
- package/dist-vue/packages/components/src/chat/PkChatbotInput.d.ts +5 -0
- package/dist-vue/packages/components/src/chat/PkImageEditor.d.ts +11 -9
- package/dist-vue/packages/components/src/chat/PkImageEditorDialog.d.ts +12 -5
- package/dist-vue/packages/components/src/chat/imageEdits.d.ts +77 -1
- package/dist-vue/packages/components/src/composables/useLightbox.d.ts +26 -0
- package/dist-vue/style.css +1 -1
- package/package.json +1 -1
- package/dist/_chunks/PkImageEditorDialog-BMCnqiqI.js +0 -555
- package/dist/_chunks/PkImageEditorDialog-BMCnqiqI.js.map +0 -1
- package/dist/_chunks/useLightbox-D2Zi-Fpe.js.map +0 -1
- package/dist-vue/_chunks/PkChatbotInput-OBoyFkZ-.js.map +0 -1
- package/dist-vue/_chunks/PkChatbotViewChat-C28g7dz-.js.map +0 -1
- package/dist-vue/_chunks/PkImageEditorDialog-3L4URgPw.js +0 -550
- package/dist-vue/_chunks/PkImageEditorDialog-3L4URgPw.js.map +0 -1
- package/dist-vue/_chunks/useLightbox-FDyQrPWe.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PkImageEditorDialog-BMCnqiqI.js","names":["_hoisted_1","_hoisted_2","_useModel","__unplugin_components_0","__unplugin_components_1","__unplugin_components_2","_openBlock","_createElementBlock","_createElementVNode","_createVNode","PkEditorRadioButtons","_unref","_withCtx","_createTextVNode","_toDisplayString","_Fragment","_normalizeStyle","_normalizeClass","_createCommentVNode","_sfc_main","_style_0","__unplugin_components_0","__unplugin_components_1","__unplugin_components_2","__unplugin_components_3","__unplugin_components_4","_openBlock","_createBlock","_unref","_withCtx","_createVNode","_createCommentVNode","PkImageEditor","_createElementBlock","_toDisplayString","_sfc_main","_style_0","normalizeClass","nextTick","onBeforeUnmount","useModel","onMounted","mergeModels","normalizeStyle","watch","createVNode","init_shared_esm_bundler","useTemplateRef","createBlock","createBaseVNode","ref","init_runtime_core_esm_bundler","toDisplayString","init_reactivity_esm_bundler","useId","withCtx","createCommentVNode","shallowRef","defineComponent","unref","createTextVNode","createElementBlock","openBlock","useI18n","useMediaQuery","useResizeObserver","au","nu","eo","Ce","VvButtonLocalized","_plugin_vue_export_helper_default","PkEditorRadioButtons_default","MAX_CANVAS_AREA","EXPORT_QUALITY","MIN_PIXEL_BLOCK","PIXEL_BLOCK_DIVISOR","EXTENSIONS","fitToArea","area","size","maxArea","scale","sizeAfterEdits","edit","edits","width","height","pixelBlock","dragRect","ax","clamp","from","bounds","ay","dx","to","dy","roomX","roomY","aspect","lead","x","y","pixelateData","blockEnd","start","block","by","bottom","bx","right","r","g","b","a","i","alpha","data","count","color","editedFileName","extension","writtenType","originalType","name","dot","loadEditableImage","bitmap","file","original","image","createCanvas","context","renderEdits","canvas","next","rotate","crop","releaseCanvas","exportCanvas","blob","resolve","reject","type","source","turn","rect","cover","style","pixels","max","min","value","_hoisted_1$1","_hoisted_2$1","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","MIN_DRAG","PkImageEditor_default","\"edits\"","\"editsModifiers\"","__expose","__emit","props","__props","emit","$t","ASPECTS","tool","coverStyle","toolOptions","computed","aspectOptions","coverOptions","aspectLabelId","redoStack","push","undo","last","redo","stageEl","shown","draw","areaEl","room","entry","frameStyle","frameEl","selection","dragFrom","pointOf","box","event","onPointerDown","onPointerMove","onPointerUp","onPointerCancel","pendingCrop","applyCrop","selectionStyle","_component_VvIcon","_component_VvButton","_component_VvButtonGroup","_cache","$event","option","Fragment","_hoisted_1","_hoisted_2","PkImageEditorDialog_default","fullscreen","loaded","failed","exporting","editorEl","scaledDown","changed","useImage","editor","failedLabel","_component_VvAlert","_component_VvDialog"],"sources":["../../../../packages/components/src/chat/imageEdits.ts","../../../../packages/components/src/chat/PkImageEditor.vue","../../../../packages/components/src/chat/PkImageEditor.vue","../../../../packages/components/src/chat/PkImageEditor.vue","../../../../packages/components/src/chat/PkImageEditorDialog.vue","../../../../packages/components/src/chat/PkImageEditorDialog.vue","../../../../packages/components/src/chat/PkImageEditorDialog.vue"],"sourcesContent":["/**\n * The model of the image editor (spec `chat-image-editor.md`): a list of\n * edits applied in order to the original, so every draw starts again from\n * the original and undo drops the last edit. The geometry is pure; the\n * drawing needs a canvas, which only a browser has.\n */\n\n/** A point in the pixels of the image an edit applies to. */\nexport interface ImagePoint {\n x: number\n y: number\n}\n\nexport interface ImageSize {\n width: number\n height: number\n}\n\n/** A rectangle in the pixels of the image an edit applies to. */\nexport interface ImageRect extends ImagePoint, ImageSize {}\n\n/**\n * How a covered area is drawn: a black box, the only cover a text cannot be\n * read back through, or large blocks of its average color, for a face.\n */\nexport type CoverStyle = 'solid' | 'pixelate'\n\n/**\n * One change, in the coordinates of the image the edits before it left: a\n * crop changes the size, a quarter turn swaps the sides.\n */\nexport type ImageEdit =\n /** A quarter turn, `1` clockwise and `-1` counterclockwise. */\n | { kind: 'rotate'; turn: 1 | -1 }\n | { kind: 'crop'; rect: ImageRect }\n | { kind: 'cover'; rect: ImageRect; style: CoverStyle }\n\n/**\n * Safari on iOS refuses a canvas larger than this area: a larger image is\n * scaled down to fit before it is edited.\n */\nexport const MAX_CANVAS_AREA = 4096 * 4096\n\n/** The quality of a JPEG or WebP written back. */\nexport const EXPORT_QUALITY = 0.92\n\n/**\n * The side of a block of a pixelated cover: never under 12 pixels, nor under\n * 1/32 of the short side, so a pixelated cover never turns into a light blur\n * that a face or a word can be guessed through.\n */\nconst MIN_PIXEL_BLOCK = 12\nconst PIXEL_BLOCK_DIVISOR = 32\n\nconst EXTENSIONS: Record<string, string> = {\n 'image/jpeg': 'jpg',\n 'image/png': 'png',\n 'image/webp': 'webp',\n}\n\n/**\n * The size an image is edited at: its own, or the largest with the same\n * proportions whose area fits `maxArea`.\n */\nexport function fitToArea(\n size: ImageSize,\n maxArea = MAX_CANVAS_AREA,\n): ImageSize {\n const area = size.width * size.height\n if (area <= maxArea) {\n return { width: size.width, height: size.height }\n }\n const scale = Math.sqrt(maxArea / area)\n return {\n width: Math.max(1, Math.floor(size.width * scale)),\n height: Math.max(1, Math.floor(size.height * scale)),\n }\n}\n\n/** The size of the image once `edits` are applied to one of `size`. */\nexport function sizeAfterEdits(\n size: ImageSize,\n edits: readonly ImageEdit[],\n): ImageSize {\n let { width, height } = size\n for (const edit of edits) {\n if (edit.kind === 'rotate') {\n ;[width, height] = [height, width]\n } else if (edit.kind === 'crop') {\n ;({ width, height } = edit.rect)\n }\n }\n return { width, height }\n}\n\n/** The side of a block of a pixelated cover on an image of `size`. */\nexport function pixelBlock(size: ImageSize): number {\n return Math.max(\n MIN_PIXEL_BLOCK,\n Math.round(Math.min(size.width, size.height) / PIXEL_BLOCK_DIVISOR),\n )\n}\n\n/**\n * The rectangle a drag from `from` to `to` draws, in any direction, inside\n * `bounds`. With an `aspect` (width over height) the longer side of the drag\n * leads, and both sides shrink together to stay inside the image.\n */\nexport function dragRect(\n from: ImagePoint,\n to: ImagePoint,\n bounds: ImageSize,\n aspect?: number,\n): ImageRect {\n const ax = clamp(from.x, 0, bounds.width)\n const ay = clamp(from.y, 0, bounds.height)\n const dx = to.x - ax\n const dy = to.y - ay\n // The room from the anchor to the edges the drag goes toward\n const roomX = dx < 0 ? ax : bounds.width - ax\n const roomY = dy < 0 ? ay : bounds.height - ay\n let width = Math.min(Math.abs(dx), roomX)\n let height = Math.min(Math.abs(dy), roomY)\n if (aspect) {\n const lead = Math.max(Math.abs(dx), Math.abs(dy) * aspect)\n width = Math.min(lead, roomX, roomY * aspect)\n height = width / aspect\n }\n const x = Math.round(dx < 0 ? ax - width : ax)\n const y = Math.round(dy < 0 ? ay - height : ay)\n return {\n x,\n y,\n width: Math.min(Math.round(width), bounds.width - x),\n height: Math.min(Math.round(height), bounds.height - y),\n }\n}\n\n/**\n * Pixelates RGBA pixels in place: each `block` square takes the average\n * color of the pixels it covers, weighted by their opacity, so the\n * transparent pixels of a PNG do not darken it. The blocks start at the top\n * left corner. What is left on the right and bottom edges, less than a\n * block, joins the last block: a strip of a few pixels would keep a detail\n * finer than the block promises.\n */\nexport function pixelateData(\n data: Uint8ClampedArray,\n width: number,\n height: number,\n block: number,\n): void {\n const blockEnd = (start: number, size: number) =>\n start + 2 * block > size ? size : start + block\n for (let by = 0; by < height; by = blockEnd(by, height)) {\n const bottom = blockEnd(by, height)\n for (let bx = 0; bx < width; bx = blockEnd(bx, width)) {\n const right = blockEnd(bx, width)\n let r = 0\n let g = 0\n let b = 0\n let a = 0\n for (let y = by; y < bottom; y++) {\n for (let x = bx; x < right; x++) {\n const i = (y * width + x) * 4\n const alpha = data[i + 3]\n r += data[i] * alpha\n g += data[i + 1] * alpha\n b += data[i + 2] * alpha\n a += alpha\n }\n }\n const count = (bottom - by) * (right - bx)\n const color =\n a > 0 ? [r / a, g / a, b / a, a / count] : [0, 0, 0, 0]\n for (let y = by; y < bottom; y++) {\n for (let x = bx; x < right; x++) {\n data.set(color, (y * width + x) * 4)\n }\n }\n }\n }\n}\n\n/**\n * The name of the edited file: the original one, with the extension of the\n * type written when the browser could not write the original type (Safari\n * writes no WebP and gives a PNG instead).\n */\nexport function editedFileName(\n name: string,\n originalType: string,\n writtenType: string,\n): string {\n const extension = EXTENSIONS[writtenType]\n if (writtenType === originalType || !extension) {\n return name\n }\n const dot = name.lastIndexOf('.')\n return `${dot > 0 ? name.slice(0, dot) : name}.${extension}`\n}\n\n// --- Canvas ---\n\nexport interface LoadedImage {\n /** The image as it is edited, at most `MAX_CANVAS_AREA` pixels. */\n image: HTMLCanvasElement\n /** The size of the file, larger than `image` when it was scaled down. */\n original: ImageSize\n}\n\n/**\n * Decodes an image file into the canvas the edits start from, upright as\n * the photo's orientation says and scaled down if it is too large for a\n * canvas.\n */\nexport async function loadEditableImage(file: Blob): Promise<LoadedImage> {\n const bitmap = await createImageBitmap(file, {\n imageOrientation: 'from-image',\n })\n try {\n const original = { width: bitmap.width, height: bitmap.height }\n const image = createCanvas(fitToArea(original))\n const g = context(image)\n g.imageSmoothingQuality = 'high'\n g.drawImage(bitmap, 0, 0, image.width, image.height)\n return { image, original }\n } finally {\n bitmap.close()\n }\n}\n\n/**\n * Draws `edits` over a copy of `image`, which stays untouched. The canvas\n * returned is new: the caller releases it with `releaseCanvas` when it\n * draws the next one.\n */\nexport function renderEdits(\n image: HTMLCanvasElement,\n edits: readonly ImageEdit[],\n): HTMLCanvasElement {\n let canvas = createCanvas(image)\n context(canvas).drawImage(image, 0, 0)\n for (const edit of edits) {\n if (edit.kind === 'cover') {\n cover(canvas, edit.rect, edit.style)\n continue\n }\n const next =\n edit.kind === 'rotate'\n ? rotate(canvas, edit.turn)\n : crop(canvas, edit.rect)\n releaseCanvas(canvas)\n canvas = next\n }\n return canvas\n}\n\n/**\n * Writes the canvas as a file of `type`, or as a PNG where the browser\n * cannot write that type. A canvas writes no metadata: the EXIF of a photo,\n * its position included, does not survive.\n */\nexport function exportCanvas(\n canvas: HTMLCanvasElement,\n type: string,\n): Promise<Blob> {\n return new Promise((resolve, reject) => {\n canvas.toBlob(\n (blob) =>\n blob\n ? resolve(blob)\n : reject(new Error('The image could not be written')),\n type,\n EXPORT_QUALITY,\n )\n })\n}\n\n/**\n * Frees the memory of a canvas no longer shown: Safari counts every canvas\n * until it is collected, and refuses new ones past its total.\n */\nexport function releaseCanvas(canvas: HTMLCanvasElement): void {\n canvas.width = 0\n canvas.height = 0\n}\n\nfunction createCanvas(size: ImageSize): HTMLCanvasElement {\n const canvas = document.createElement('canvas')\n canvas.width = size.width\n canvas.height = size.height\n return canvas\n}\n\nfunction context(canvas: HTMLCanvasElement): CanvasRenderingContext2D {\n const g = canvas.getContext('2d')\n if (!g) {\n throw new Error('No 2D canvas in this browser')\n }\n return g\n}\n\nfunction rotate(source: HTMLCanvasElement, turn: 1 | -1): HTMLCanvasElement {\n const canvas = createCanvas({\n width: source.height,\n height: source.width,\n })\n const g = context(canvas)\n // The context stays the canvas's: the edits after a turn draw through\n // it, and a turn left on it put a solid cover beside what it covers\n g.save()\n g.translate(canvas.width / 2, canvas.height / 2)\n g.rotate((turn * Math.PI) / 2)\n g.drawImage(source, -source.width / 2, -source.height / 2)\n g.restore()\n return canvas\n}\n\nfunction crop(source: HTMLCanvasElement, rect: ImageRect): HTMLCanvasElement {\n const canvas = createCanvas(rect)\n context(canvas).drawImage(\n source,\n rect.x,\n rect.y,\n rect.width,\n rect.height,\n 0,\n 0,\n rect.width,\n rect.height,\n )\n return canvas\n}\n\nfunction cover(\n canvas: HTMLCanvasElement,\n rect: ImageRect,\n style: CoverStyle,\n): void {\n const g = context(canvas)\n if (style === 'solid') {\n g.fillStyle = '#000000'\n g.fillRect(rect.x, rect.y, rect.width, rect.height)\n return\n }\n const pixels = g.getImageData(rect.x, rect.y, rect.width, rect.height)\n pixelateData(pixels.data, rect.width, rect.height, pixelBlock(canvas))\n g.putImageData(pixels, rect.x, rect.y)\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, value))\n}\n","<script setup lang=\"ts\">\n import {\n computed,\n onBeforeUnmount,\n onMounted,\n ref,\n useId,\n useTemplateRef,\n watch,\n } from 'vue'\n import { useI18n } from 'vue-i18n'\n import { useResizeObserver } from '@vueuse/core'\n import PkEditorRadioButtons from '../PkEditorRadioButtons.vue'\n import {\n dragRect,\n releaseCanvas,\n renderEdits,\n sizeAfterEdits,\n type CoverStyle,\n type ImageEdit,\n type ImagePoint,\n type ImageRect,\n } from './imageEdits'\n\n /**\n * The tools of the image editor over the image they change (spec\n * `chat-image-editor.md`, F1): crop and cover by dragging on the image,\n * quarter turns, undo and redo. The edits are the model, the image stays\n * as it was loaded. Dragging needs a mouse, a pen or a finger; the rest\n * works from the keyboard.\n */\n const props = defineProps<{\n /** The image the edits start from. */\n image: HTMLCanvasElement\n }>()\n\n const emit = defineEmits<{\n /** The browser could not draw the image, out of canvas memory. */\n error: []\n }>()\n\n const edits = defineModel<ImageEdit[]>('edits', { required: true })\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n // --- Tools ---\n\n type Tool = 'crop' | 'cover'\n type Aspect = 'free' | '1:1' | '4:3' | '16:9'\n\n const ASPECTS: Record<Aspect, number | undefined> = {\n free: undefined,\n '1:1': 1,\n '4:3': 4 / 3,\n '16:9': 16 / 9,\n }\n\n const tool = ref<Tool>('crop')\n const aspect = ref<Aspect>('free')\n // Every opening starts on the solid box, the only cover safe on a text:\n // the pixels picked for a face yesterday do not cover an IBAN today\n const coverStyle = ref<CoverStyle>('solid')\n\n const toolOptions = computed(() => [\n { value: 'crop', label: $t('imageEditor.crop') },\n { value: 'cover', label: $t('imageEditor.cover') },\n ])\n const aspectOptions = computed(() => [\n { value: 'free', label: $t('imageEditor.aspectFree') },\n { value: '1:1', label: '1:1' },\n { value: '4:3', label: '4:3' },\n { value: '16:9', label: '16:9' },\n ])\n const coverOptions = computed(() => [\n { value: 'solid', label: $t('imageEditor.coverSolid') },\n { value: 'pixelate', label: $t('imageEditor.coverPixelate') },\n ])\n const aspectLabelId = useId()\n\n // --- History ---\n\n const redoStack = ref<ImageEdit[]>([])\n\n function push(edit: ImageEdit) {\n edits.value = [...edits.value, edit]\n redoStack.value = []\n }\n\n function undo() {\n selection.value = undefined\n const last = edits.value[edits.value.length - 1]\n if (!last) {\n return\n }\n edits.value = edits.value.slice(0, -1)\n redoStack.value = [...redoStack.value, last]\n }\n\n function redo() {\n selection.value = undefined\n const next = redoStack.value[redoStack.value.length - 1]\n if (!next) {\n return\n }\n edits.value = [...edits.value, next]\n redoStack.value = redoStack.value.slice(0, -1)\n }\n\n function rotate(turn: 1 | -1) {\n selection.value = undefined\n push({ kind: 'rotate', turn })\n }\n\n // --- Drawing ---\n\n const size = computed(() => sizeAfterEdits(props.image, edits.value))\n const stageEl = useTemplateRef<HTMLDivElement>('stageEl')\n // The canvas on screen, outside Vue: a new one replaces it on each edit\n let shown: HTMLCanvasElement | undefined\n\n function draw() {\n if (!stageEl.value) {\n return\n }\n let canvas: HTMLCanvasElement\n try {\n canvas = renderEdits(props.image, edits.value)\n } catch {\n emit('error')\n return\n }\n canvas.setAttribute('role', 'img')\n canvas.setAttribute('aria-label', $t('imageEditor.canvasLabel'))\n stageEl.value.replaceChildren(canvas)\n if (shown) {\n releaseCanvas(shown)\n }\n shown = canvas\n }\n\n onMounted(draw)\n watch([() => props.image, edits], draw, { flush: 'post' })\n onBeforeUnmount(() => {\n if (shown) {\n releaseCanvas(shown)\n }\n })\n\n // The image fits the room it has, never drawn larger than its pixels\n const areaEl = useTemplateRef<HTMLDivElement>('areaEl')\n const room = ref({ width: 0, height: 0 })\n useResizeObserver(areaEl, ([entry]) => {\n if (entry) {\n room.value = {\n width: entry.contentRect.width,\n height: entry.contentRect.height,\n }\n }\n })\n const scale = computed(() =>\n Math.min(\n 1,\n room.value.width / size.value.width,\n room.value.height / size.value.height,\n ),\n )\n const frameStyle = computed(() => ({\n width: `${Math.max(1, Math.floor(size.value.width * scale.value))}px`,\n height: `${Math.max(1, Math.floor(size.value.height * scale.value))}px`,\n }))\n\n // --- Dragging a rectangle ---\n\n /** A rectangle thinner than this on screen is a click, not a drag. */\n const MIN_DRAG = 6\n\n const frameEl = useTemplateRef<HTMLDivElement>('frameEl')\n const selection = ref<ImageRect>()\n const dragFrom = ref<ImagePoint>()\n\n function pointOf(event: PointerEvent): ImagePoint {\n const box = frameEl.value?.getBoundingClientRect()\n if (!box?.width || !box.height) {\n return { x: 0, y: 0 }\n }\n return {\n x: ((event.clientX - box.left) / box.width) * size.value.width,\n y: ((event.clientY - box.top) / box.height) * size.value.height,\n }\n }\n\n function onPointerDown(event: PointerEvent) {\n if (event.button !== 0) {\n return\n }\n frameEl.value?.setPointerCapture(event.pointerId)\n dragFrom.value = pointOf(event)\n selection.value = undefined\n }\n\n function onPointerMove(event: PointerEvent) {\n if (!dragFrom.value) {\n return\n }\n selection.value = dragRect(\n dragFrom.value,\n pointOf(event),\n size.value,\n tool.value === 'crop' ? ASPECTS[aspect.value] : undefined,\n )\n }\n\n function onPointerUp() {\n if (!dragFrom.value) {\n return\n }\n dragFrom.value = undefined\n const rect = selection.value\n if (\n !rect ||\n rect.width * scale.value < MIN_DRAG ||\n rect.height * scale.value < MIN_DRAG\n ) {\n selection.value = undefined\n return\n }\n // A cover is written as soon as it is drawn; a crop waits for Apply\n if (tool.value === 'cover') {\n selection.value = undefined\n push({ kind: 'cover', rect, style: coverStyle.value })\n }\n }\n\n function onPointerCancel() {\n dragFrom.value = undefined\n selection.value = undefined\n }\n\n const pendingCrop = computed(\n () => tool.value === 'crop' && !dragFrom.value && !!selection.value,\n )\n\n function applyCrop() {\n const rect = selection.value\n if (!pendingCrop.value || !rect) {\n return\n }\n selection.value = undefined\n if (\n rect.width === size.value.width &&\n rect.height === size.value.height\n ) {\n return\n }\n push({ kind: 'crop', rect })\n }\n\n watch(tool, () => {\n selection.value = undefined\n })\n\n // A crop drawn and then given proportions keeps its corner and takes them\n watch(aspect, (value) => {\n const rect = selection.value\n if (rect && tool.value === 'crop') {\n selection.value = dragRect(\n rect,\n { x: rect.x + rect.width, y: rect.y + rect.height },\n size.value,\n ASPECTS[value],\n )\n }\n })\n\n const selectionStyle = computed(() => {\n const rect = selection.value\n if (!rect) {\n return undefined\n }\n return {\n left: `${(rect.x / size.value.width) * 100}%`,\n top: `${(rect.y / size.value.height) * 100}%`,\n width: `${(rect.width / size.value.width) * 100}%`,\n height: `${(rect.height / size.value.height) * 100}%`,\n }\n })\n\n defineExpose({\n /** A crop is drawn and not applied yet. */\n pendingCrop,\n /** Applies the crop drawn, as Apply does: \"Use the image\" calls it first. */\n applyCrop,\n /**\n * The canvas on screen, every edit drawn, which the host writes as\n * the file: it stays the editor's, released when the editor goes.\n */\n shownCanvas: () => shown,\n })\n</script>\n\n<template>\n <div class=\"pk-image-editor\">\n <div class=\"pk-image-editor__toolbar\">\n <PkEditorRadioButtons\n v-model=\"tool\"\n name=\"pk-image-editor-tool\"\n segmented\n class=\"mb-0\"\n :aria-label=\"$t('imageEditor.tool')\"\n :options=\"toolOptions\">\n <template #crop=\"{ option }\">\n <VvIcon name=\"ri:crop-line\" class=\"w-16 h-16\" />\n {{ option.label }}\n </template>\n <template #cover=\"{ option }\">\n <VvIcon name=\"ri:eye-off-line\" class=\"w-16 h-16\" />\n {{ option.label }}\n </template>\n </PkEditorRadioButtons>\n <VvButtonGroup modifiers=\"compact\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:anticlockwise-line\"\n :title=\"$t('imageEditor.rotateLeft')\"\n :aria-label=\"$t('imageEditor.rotateLeft')\"\n @click=\"rotate(-1)\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:clockwise-line\"\n :title=\"$t('imageEditor.rotateRight')\"\n :aria-label=\"$t('imageEditor.rotateRight')\"\n @click=\"rotate(1)\" />\n </VvButtonGroup>\n <!-- \"Annulla\" is already the dialog's button: two \"Annulla\"\n doing different things in one window read as one -->\n <VvButtonGroup modifiers=\"compact\" class=\"ml-auto\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-back-line\"\n :title=\"$t('imageEditor.undo')\"\n :aria-label=\"$t('imageEditor.undo')\"\n :disabled=\"!edits.length\"\n @click=\"undo\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-forward-line\"\n :title=\"$t('imageEditor.redo')\"\n :aria-label=\"$t('imageEditor.redo')\"\n :disabled=\"!redoStack.length\"\n @click=\"redo\" />\n </VvButtonGroup>\n </div>\n <div class=\"pk-image-editor__options\">\n <template v-if=\"tool === 'crop'\">\n <span :id=\"aspectLabelId\" class=\"pk-image-editor__label\">\n {{ $t('imageEditor.aspect') }}\n </span>\n <PkEditorRadioButtons\n v-model=\"aspect\"\n name=\"pk-image-editor-aspect\"\n segmented\n class=\"mb-0\"\n :aria-labelledby=\"aspectLabelId\"\n :options=\"aspectOptions\" />\n <span class=\"pk-image-editor__hint\">\n {{ $t('imageEditor.cropHint') }}\n </span>\n <VvButton\n class=\"ml-auto\"\n modifiers=\"secondary\"\n :label=\"$t('action.apply')\"\n :disabled=\"!pendingCrop\"\n @click=\"applyCrop\" />\n </template>\n <template v-else>\n <PkEditorRadioButtons\n v-model=\"coverStyle\"\n name=\"pk-image-editor-cover\"\n segmented\n class=\"mb-0\"\n :aria-label=\"$t('imageEditor.coverStyle')\"\n :options=\"coverOptions\" />\n <span class=\"pk-image-editor__hint\">\n {{ $t('imageEditor.coverHint') }}\n </span>\n </template>\n </div>\n <div ref=\"areaEl\" class=\"pk-image-editor__area\">\n <div\n ref=\"frameEl\"\n class=\"pk-image-editor__frame\"\n :style=\"frameStyle\"\n @pointerdown=\"onPointerDown\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"onPointerCancel\">\n <div ref=\"stageEl\" class=\"pk-image-editor__stage\" />\n <div\n v-if=\"selection\"\n class=\"pk-image-editor__selection\"\n :class=\"`pk-image-editor__selection--${tool}`\"\n :style=\"selectionStyle\" />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-image-editor {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n\n &__toolbar,\n &__options {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8);\n padding: var(--spacing-8) var(--spacing-md);\n border-bottom: 1px solid var(--color-surface-3);\n }\n\n &__toolbar {\n background-color: var(--color-surface-1);\n }\n\n // A segmented control is as wide as its options, each as wide as its\n // words: with the library's equal segments the longer one was cut\n // (\"Riquadro pien\") and its icon shrank. A row too narrow sends the\n // control to a line of its own.\n &__toolbar > .vv-radio-group,\n &__options > .vv-radio-group {\n flex: none;\n width: auto;\n\n .vv-radio {\n flex: none;\n }\n }\n\n &__label {\n color: var(--color-word-2);\n font-size: var(--text-14);\n }\n\n &__hint {\n color: var(--color-word-3);\n font-size: var(--text-12);\n }\n\n // A checkerboard, as in the lightbox: a transparent PNG shows where\n // it is transparent\n &__area {\n display: flex;\n flex: 1;\n align-items: center;\n justify-content: center;\n min-height: 12rem;\n padding: var(--spacing-md);\n overflow: hidden;\n background: repeating-conic-gradient(\n var(--color-surface-2) 0% 25%,\n var(--color-surface) 0% 50%\n )\n 50% / 16px 16px;\n }\n\n &__frame {\n position: relative;\n flex-shrink: 0;\n overflow: hidden;\n box-shadow: var(--shadow-sm);\n cursor: crosshair;\n\n // The drag is the gesture: no scroll or zoom of the page under it\n touch-action: none;\n user-select: none;\n }\n\n &__stage,\n &__stage > canvas {\n display: block;\n width: 100%;\n height: 100%;\n }\n\n // Drawn over a photo, so the same in both themes: white with a dark\n // edge reads on any image\n &__selection {\n position: absolute;\n pointer-events: none;\n border: 2px solid var(--color-white);\n outline: 1px solid\n color-mix(in srgb, var(--color-black) 50%, transparent);\n\n // What a crop leaves out goes dark\n &--crop {\n box-shadow: 0 0 0 100vmax\n color-mix(in srgb, var(--color-black) 55%, transparent);\n }\n\n &--cover {\n border-style: dashed;\n background-color: color-mix(\n in srgb,\n var(--color-black) 30%,\n transparent\n );\n }\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import {\n computed,\n onBeforeUnmount,\n onMounted,\n ref,\n useId,\n useTemplateRef,\n watch,\n } from 'vue'\n import { useI18n } from 'vue-i18n'\n import { useResizeObserver } from '@vueuse/core'\n import PkEditorRadioButtons from '../PkEditorRadioButtons.vue'\n import {\n dragRect,\n releaseCanvas,\n renderEdits,\n sizeAfterEdits,\n type CoverStyle,\n type ImageEdit,\n type ImagePoint,\n type ImageRect,\n } from './imageEdits'\n\n /**\n * The tools of the image editor over the image they change (spec\n * `chat-image-editor.md`, F1): crop and cover by dragging on the image,\n * quarter turns, undo and redo. The edits are the model, the image stays\n * as it was loaded. Dragging needs a mouse, a pen or a finger; the rest\n * works from the keyboard.\n */\n const props = defineProps<{\n /** The image the edits start from. */\n image: HTMLCanvasElement\n }>()\n\n const emit = defineEmits<{\n /** The browser could not draw the image, out of canvas memory. */\n error: []\n }>()\n\n const edits = defineModel<ImageEdit[]>('edits', { required: true })\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n // --- Tools ---\n\n type Tool = 'crop' | 'cover'\n type Aspect = 'free' | '1:1' | '4:3' | '16:9'\n\n const ASPECTS: Record<Aspect, number | undefined> = {\n free: undefined,\n '1:1': 1,\n '4:3': 4 / 3,\n '16:9': 16 / 9,\n }\n\n const tool = ref<Tool>('crop')\n const aspect = ref<Aspect>('free')\n // Every opening starts on the solid box, the only cover safe on a text:\n // the pixels picked for a face yesterday do not cover an IBAN today\n const coverStyle = ref<CoverStyle>('solid')\n\n const toolOptions = computed(() => [\n { value: 'crop', label: $t('imageEditor.crop') },\n { value: 'cover', label: $t('imageEditor.cover') },\n ])\n const aspectOptions = computed(() => [\n { value: 'free', label: $t('imageEditor.aspectFree') },\n { value: '1:1', label: '1:1' },\n { value: '4:3', label: '4:3' },\n { value: '16:9', label: '16:9' },\n ])\n const coverOptions = computed(() => [\n { value: 'solid', label: $t('imageEditor.coverSolid') },\n { value: 'pixelate', label: $t('imageEditor.coverPixelate') },\n ])\n const aspectLabelId = useId()\n\n // --- History ---\n\n const redoStack = ref<ImageEdit[]>([])\n\n function push(edit: ImageEdit) {\n edits.value = [...edits.value, edit]\n redoStack.value = []\n }\n\n function undo() {\n selection.value = undefined\n const last = edits.value[edits.value.length - 1]\n if (!last) {\n return\n }\n edits.value = edits.value.slice(0, -1)\n redoStack.value = [...redoStack.value, last]\n }\n\n function redo() {\n selection.value = undefined\n const next = redoStack.value[redoStack.value.length - 1]\n if (!next) {\n return\n }\n edits.value = [...edits.value, next]\n redoStack.value = redoStack.value.slice(0, -1)\n }\n\n function rotate(turn: 1 | -1) {\n selection.value = undefined\n push({ kind: 'rotate', turn })\n }\n\n // --- Drawing ---\n\n const size = computed(() => sizeAfterEdits(props.image, edits.value))\n const stageEl = useTemplateRef<HTMLDivElement>('stageEl')\n // The canvas on screen, outside Vue: a new one replaces it on each edit\n let shown: HTMLCanvasElement | undefined\n\n function draw() {\n if (!stageEl.value) {\n return\n }\n let canvas: HTMLCanvasElement\n try {\n canvas = renderEdits(props.image, edits.value)\n } catch {\n emit('error')\n return\n }\n canvas.setAttribute('role', 'img')\n canvas.setAttribute('aria-label', $t('imageEditor.canvasLabel'))\n stageEl.value.replaceChildren(canvas)\n if (shown) {\n releaseCanvas(shown)\n }\n shown = canvas\n }\n\n onMounted(draw)\n watch([() => props.image, edits], draw, { flush: 'post' })\n onBeforeUnmount(() => {\n if (shown) {\n releaseCanvas(shown)\n }\n })\n\n // The image fits the room it has, never drawn larger than its pixels\n const areaEl = useTemplateRef<HTMLDivElement>('areaEl')\n const room = ref({ width: 0, height: 0 })\n useResizeObserver(areaEl, ([entry]) => {\n if (entry) {\n room.value = {\n width: entry.contentRect.width,\n height: entry.contentRect.height,\n }\n }\n })\n const scale = computed(() =>\n Math.min(\n 1,\n room.value.width / size.value.width,\n room.value.height / size.value.height,\n ),\n )\n const frameStyle = computed(() => ({\n width: `${Math.max(1, Math.floor(size.value.width * scale.value))}px`,\n height: `${Math.max(1, Math.floor(size.value.height * scale.value))}px`,\n }))\n\n // --- Dragging a rectangle ---\n\n /** A rectangle thinner than this on screen is a click, not a drag. */\n const MIN_DRAG = 6\n\n const frameEl = useTemplateRef<HTMLDivElement>('frameEl')\n const selection = ref<ImageRect>()\n const dragFrom = ref<ImagePoint>()\n\n function pointOf(event: PointerEvent): ImagePoint {\n const box = frameEl.value?.getBoundingClientRect()\n if (!box?.width || !box.height) {\n return { x: 0, y: 0 }\n }\n return {\n x: ((event.clientX - box.left) / box.width) * size.value.width,\n y: ((event.clientY - box.top) / box.height) * size.value.height,\n }\n }\n\n function onPointerDown(event: PointerEvent) {\n if (event.button !== 0) {\n return\n }\n frameEl.value?.setPointerCapture(event.pointerId)\n dragFrom.value = pointOf(event)\n selection.value = undefined\n }\n\n function onPointerMove(event: PointerEvent) {\n if (!dragFrom.value) {\n return\n }\n selection.value = dragRect(\n dragFrom.value,\n pointOf(event),\n size.value,\n tool.value === 'crop' ? ASPECTS[aspect.value] : undefined,\n )\n }\n\n function onPointerUp() {\n if (!dragFrom.value) {\n return\n }\n dragFrom.value = undefined\n const rect = selection.value\n if (\n !rect ||\n rect.width * scale.value < MIN_DRAG ||\n rect.height * scale.value < MIN_DRAG\n ) {\n selection.value = undefined\n return\n }\n // A cover is written as soon as it is drawn; a crop waits for Apply\n if (tool.value === 'cover') {\n selection.value = undefined\n push({ kind: 'cover', rect, style: coverStyle.value })\n }\n }\n\n function onPointerCancel() {\n dragFrom.value = undefined\n selection.value = undefined\n }\n\n const pendingCrop = computed(\n () => tool.value === 'crop' && !dragFrom.value && !!selection.value,\n )\n\n function applyCrop() {\n const rect = selection.value\n if (!pendingCrop.value || !rect) {\n return\n }\n selection.value = undefined\n if (\n rect.width === size.value.width &&\n rect.height === size.value.height\n ) {\n return\n }\n push({ kind: 'crop', rect })\n }\n\n watch(tool, () => {\n selection.value = undefined\n })\n\n // A crop drawn and then given proportions keeps its corner and takes them\n watch(aspect, (value) => {\n const rect = selection.value\n if (rect && tool.value === 'crop') {\n selection.value = dragRect(\n rect,\n { x: rect.x + rect.width, y: rect.y + rect.height },\n size.value,\n ASPECTS[value],\n )\n }\n })\n\n const selectionStyle = computed(() => {\n const rect = selection.value\n if (!rect) {\n return undefined\n }\n return {\n left: `${(rect.x / size.value.width) * 100}%`,\n top: `${(rect.y / size.value.height) * 100}%`,\n width: `${(rect.width / size.value.width) * 100}%`,\n height: `${(rect.height / size.value.height) * 100}%`,\n }\n })\n\n defineExpose({\n /** A crop is drawn and not applied yet. */\n pendingCrop,\n /** Applies the crop drawn, as Apply does: \"Use the image\" calls it first. */\n applyCrop,\n /**\n * The canvas on screen, every edit drawn, which the host writes as\n * the file: it stays the editor's, released when the editor goes.\n */\n shownCanvas: () => shown,\n })\n</script>\n\n<template>\n <div class=\"pk-image-editor\">\n <div class=\"pk-image-editor__toolbar\">\n <PkEditorRadioButtons\n v-model=\"tool\"\n name=\"pk-image-editor-tool\"\n segmented\n class=\"mb-0\"\n :aria-label=\"$t('imageEditor.tool')\"\n :options=\"toolOptions\">\n <template #crop=\"{ option }\">\n <VvIcon name=\"ri:crop-line\" class=\"w-16 h-16\" />\n {{ option.label }}\n </template>\n <template #cover=\"{ option }\">\n <VvIcon name=\"ri:eye-off-line\" class=\"w-16 h-16\" />\n {{ option.label }}\n </template>\n </PkEditorRadioButtons>\n <VvButtonGroup modifiers=\"compact\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:anticlockwise-line\"\n :title=\"$t('imageEditor.rotateLeft')\"\n :aria-label=\"$t('imageEditor.rotateLeft')\"\n @click=\"rotate(-1)\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:clockwise-line\"\n :title=\"$t('imageEditor.rotateRight')\"\n :aria-label=\"$t('imageEditor.rotateRight')\"\n @click=\"rotate(1)\" />\n </VvButtonGroup>\n <!-- \"Annulla\" is already the dialog's button: two \"Annulla\"\n doing different things in one window read as one -->\n <VvButtonGroup modifiers=\"compact\" class=\"ml-auto\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-back-line\"\n :title=\"$t('imageEditor.undo')\"\n :aria-label=\"$t('imageEditor.undo')\"\n :disabled=\"!edits.length\"\n @click=\"undo\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-forward-line\"\n :title=\"$t('imageEditor.redo')\"\n :aria-label=\"$t('imageEditor.redo')\"\n :disabled=\"!redoStack.length\"\n @click=\"redo\" />\n </VvButtonGroup>\n </div>\n <div class=\"pk-image-editor__options\">\n <template v-if=\"tool === 'crop'\">\n <span :id=\"aspectLabelId\" class=\"pk-image-editor__label\">\n {{ $t('imageEditor.aspect') }}\n </span>\n <PkEditorRadioButtons\n v-model=\"aspect\"\n name=\"pk-image-editor-aspect\"\n segmented\n class=\"mb-0\"\n :aria-labelledby=\"aspectLabelId\"\n :options=\"aspectOptions\" />\n <span class=\"pk-image-editor__hint\">\n {{ $t('imageEditor.cropHint') }}\n </span>\n <VvButton\n class=\"ml-auto\"\n modifiers=\"secondary\"\n :label=\"$t('action.apply')\"\n :disabled=\"!pendingCrop\"\n @click=\"applyCrop\" />\n </template>\n <template v-else>\n <PkEditorRadioButtons\n v-model=\"coverStyle\"\n name=\"pk-image-editor-cover\"\n segmented\n class=\"mb-0\"\n :aria-label=\"$t('imageEditor.coverStyle')\"\n :options=\"coverOptions\" />\n <span class=\"pk-image-editor__hint\">\n {{ $t('imageEditor.coverHint') }}\n </span>\n </template>\n </div>\n <div ref=\"areaEl\" class=\"pk-image-editor__area\">\n <div\n ref=\"frameEl\"\n class=\"pk-image-editor__frame\"\n :style=\"frameStyle\"\n @pointerdown=\"onPointerDown\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"onPointerCancel\">\n <div ref=\"stageEl\" class=\"pk-image-editor__stage\" />\n <div\n v-if=\"selection\"\n class=\"pk-image-editor__selection\"\n :class=\"`pk-image-editor__selection--${tool}`\"\n :style=\"selectionStyle\" />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-image-editor {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n\n &__toolbar,\n &__options {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8);\n padding: var(--spacing-8) var(--spacing-md);\n border-bottom: 1px solid var(--color-surface-3);\n }\n\n &__toolbar {\n background-color: var(--color-surface-1);\n }\n\n // A segmented control is as wide as its options, each as wide as its\n // words: with the library's equal segments the longer one was cut\n // (\"Riquadro pien\") and its icon shrank. A row too narrow sends the\n // control to a line of its own.\n &__toolbar > .vv-radio-group,\n &__options > .vv-radio-group {\n flex: none;\n width: auto;\n\n .vv-radio {\n flex: none;\n }\n }\n\n &__label {\n color: var(--color-word-2);\n font-size: var(--text-14);\n }\n\n &__hint {\n color: var(--color-word-3);\n font-size: var(--text-12);\n }\n\n // A checkerboard, as in the lightbox: a transparent PNG shows where\n // it is transparent\n &__area {\n display: flex;\n flex: 1;\n align-items: center;\n justify-content: center;\n min-height: 12rem;\n padding: var(--spacing-md);\n overflow: hidden;\n background: repeating-conic-gradient(\n var(--color-surface-2) 0% 25%,\n var(--color-surface) 0% 50%\n )\n 50% / 16px 16px;\n }\n\n &__frame {\n position: relative;\n flex-shrink: 0;\n overflow: hidden;\n box-shadow: var(--shadow-sm);\n cursor: crosshair;\n\n // The drag is the gesture: no scroll or zoom of the page under it\n touch-action: none;\n user-select: none;\n }\n\n &__stage,\n &__stage > canvas {\n display: block;\n width: 100%;\n height: 100%;\n }\n\n // Drawn over a photo, so the same in both themes: white with a dark\n // edge reads on any image\n &__selection {\n position: absolute;\n pointer-events: none;\n border: 2px solid var(--color-white);\n outline: 1px solid\n color-mix(in srgb, var(--color-black) 50%, transparent);\n\n // What a crop leaves out goes dark\n &--crop {\n box-shadow: 0 0 0 100vmax\n color-mix(in srgb, var(--color-black) 55%, transparent);\n }\n\n &--cover {\n border-style: dashed;\n background-color: color-mix(\n in srgb,\n var(--color-black) 30%,\n transparent\n );\n }\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import {\n computed,\n onBeforeUnmount,\n onMounted,\n ref,\n useId,\n useTemplateRef,\n watch,\n } from 'vue'\n import { useI18n } from 'vue-i18n'\n import { useResizeObserver } from '@vueuse/core'\n import PkEditorRadioButtons from '../PkEditorRadioButtons.vue'\n import {\n dragRect,\n releaseCanvas,\n renderEdits,\n sizeAfterEdits,\n type CoverStyle,\n type ImageEdit,\n type ImagePoint,\n type ImageRect,\n } from './imageEdits'\n\n /**\n * The tools of the image editor over the image they change (spec\n * `chat-image-editor.md`, F1): crop and cover by dragging on the image,\n * quarter turns, undo and redo. The edits are the model, the image stays\n * as it was loaded. Dragging needs a mouse, a pen or a finger; the rest\n * works from the keyboard.\n */\n const props = defineProps<{\n /** The image the edits start from. */\n image: HTMLCanvasElement\n }>()\n\n const emit = defineEmits<{\n /** The browser could not draw the image, out of canvas memory. */\n error: []\n }>()\n\n const edits = defineModel<ImageEdit[]>('edits', { required: true })\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n // --- Tools ---\n\n type Tool = 'crop' | 'cover'\n type Aspect = 'free' | '1:1' | '4:3' | '16:9'\n\n const ASPECTS: Record<Aspect, number | undefined> = {\n free: undefined,\n '1:1': 1,\n '4:3': 4 / 3,\n '16:9': 16 / 9,\n }\n\n const tool = ref<Tool>('crop')\n const aspect = ref<Aspect>('free')\n // Every opening starts on the solid box, the only cover safe on a text:\n // the pixels picked for a face yesterday do not cover an IBAN today\n const coverStyle = ref<CoverStyle>('solid')\n\n const toolOptions = computed(() => [\n { value: 'crop', label: $t('imageEditor.crop') },\n { value: 'cover', label: $t('imageEditor.cover') },\n ])\n const aspectOptions = computed(() => [\n { value: 'free', label: $t('imageEditor.aspectFree') },\n { value: '1:1', label: '1:1' },\n { value: '4:3', label: '4:3' },\n { value: '16:9', label: '16:9' },\n ])\n const coverOptions = computed(() => [\n { value: 'solid', label: $t('imageEditor.coverSolid') },\n { value: 'pixelate', label: $t('imageEditor.coverPixelate') },\n ])\n const aspectLabelId = useId()\n\n // --- History ---\n\n const redoStack = ref<ImageEdit[]>([])\n\n function push(edit: ImageEdit) {\n edits.value = [...edits.value, edit]\n redoStack.value = []\n }\n\n function undo() {\n selection.value = undefined\n const last = edits.value[edits.value.length - 1]\n if (!last) {\n return\n }\n edits.value = edits.value.slice(0, -1)\n redoStack.value = [...redoStack.value, last]\n }\n\n function redo() {\n selection.value = undefined\n const next = redoStack.value[redoStack.value.length - 1]\n if (!next) {\n return\n }\n edits.value = [...edits.value, next]\n redoStack.value = redoStack.value.slice(0, -1)\n }\n\n function rotate(turn: 1 | -1) {\n selection.value = undefined\n push({ kind: 'rotate', turn })\n }\n\n // --- Drawing ---\n\n const size = computed(() => sizeAfterEdits(props.image, edits.value))\n const stageEl = useTemplateRef<HTMLDivElement>('stageEl')\n // The canvas on screen, outside Vue: a new one replaces it on each edit\n let shown: HTMLCanvasElement | undefined\n\n function draw() {\n if (!stageEl.value) {\n return\n }\n let canvas: HTMLCanvasElement\n try {\n canvas = renderEdits(props.image, edits.value)\n } catch {\n emit('error')\n return\n }\n canvas.setAttribute('role', 'img')\n canvas.setAttribute('aria-label', $t('imageEditor.canvasLabel'))\n stageEl.value.replaceChildren(canvas)\n if (shown) {\n releaseCanvas(shown)\n }\n shown = canvas\n }\n\n onMounted(draw)\n watch([() => props.image, edits], draw, { flush: 'post' })\n onBeforeUnmount(() => {\n if (shown) {\n releaseCanvas(shown)\n }\n })\n\n // The image fits the room it has, never drawn larger than its pixels\n const areaEl = useTemplateRef<HTMLDivElement>('areaEl')\n const room = ref({ width: 0, height: 0 })\n useResizeObserver(areaEl, ([entry]) => {\n if (entry) {\n room.value = {\n width: entry.contentRect.width,\n height: entry.contentRect.height,\n }\n }\n })\n const scale = computed(() =>\n Math.min(\n 1,\n room.value.width / size.value.width,\n room.value.height / size.value.height,\n ),\n )\n const frameStyle = computed(() => ({\n width: `${Math.max(1, Math.floor(size.value.width * scale.value))}px`,\n height: `${Math.max(1, Math.floor(size.value.height * scale.value))}px`,\n }))\n\n // --- Dragging a rectangle ---\n\n /** A rectangle thinner than this on screen is a click, not a drag. */\n const MIN_DRAG = 6\n\n const frameEl = useTemplateRef<HTMLDivElement>('frameEl')\n const selection = ref<ImageRect>()\n const dragFrom = ref<ImagePoint>()\n\n function pointOf(event: PointerEvent): ImagePoint {\n const box = frameEl.value?.getBoundingClientRect()\n if (!box?.width || !box.height) {\n return { x: 0, y: 0 }\n }\n return {\n x: ((event.clientX - box.left) / box.width) * size.value.width,\n y: ((event.clientY - box.top) / box.height) * size.value.height,\n }\n }\n\n function onPointerDown(event: PointerEvent) {\n if (event.button !== 0) {\n return\n }\n frameEl.value?.setPointerCapture(event.pointerId)\n dragFrom.value = pointOf(event)\n selection.value = undefined\n }\n\n function onPointerMove(event: PointerEvent) {\n if (!dragFrom.value) {\n return\n }\n selection.value = dragRect(\n dragFrom.value,\n pointOf(event),\n size.value,\n tool.value === 'crop' ? ASPECTS[aspect.value] : undefined,\n )\n }\n\n function onPointerUp() {\n if (!dragFrom.value) {\n return\n }\n dragFrom.value = undefined\n const rect = selection.value\n if (\n !rect ||\n rect.width * scale.value < MIN_DRAG ||\n rect.height * scale.value < MIN_DRAG\n ) {\n selection.value = undefined\n return\n }\n // A cover is written as soon as it is drawn; a crop waits for Apply\n if (tool.value === 'cover') {\n selection.value = undefined\n push({ kind: 'cover', rect, style: coverStyle.value })\n }\n }\n\n function onPointerCancel() {\n dragFrom.value = undefined\n selection.value = undefined\n }\n\n const pendingCrop = computed(\n () => tool.value === 'crop' && !dragFrom.value && !!selection.value,\n )\n\n function applyCrop() {\n const rect = selection.value\n if (!pendingCrop.value || !rect) {\n return\n }\n selection.value = undefined\n if (\n rect.width === size.value.width &&\n rect.height === size.value.height\n ) {\n return\n }\n push({ kind: 'crop', rect })\n }\n\n watch(tool, () => {\n selection.value = undefined\n })\n\n // A crop drawn and then given proportions keeps its corner and takes them\n watch(aspect, (value) => {\n const rect = selection.value\n if (rect && tool.value === 'crop') {\n selection.value = dragRect(\n rect,\n { x: rect.x + rect.width, y: rect.y + rect.height },\n size.value,\n ASPECTS[value],\n )\n }\n })\n\n const selectionStyle = computed(() => {\n const rect = selection.value\n if (!rect) {\n return undefined\n }\n return {\n left: `${(rect.x / size.value.width) * 100}%`,\n top: `${(rect.y / size.value.height) * 100}%`,\n width: `${(rect.width / size.value.width) * 100}%`,\n height: `${(rect.height / size.value.height) * 100}%`,\n }\n })\n\n defineExpose({\n /** A crop is drawn and not applied yet. */\n pendingCrop,\n /** Applies the crop drawn, as Apply does: \"Use the image\" calls it first. */\n applyCrop,\n /**\n * The canvas on screen, every edit drawn, which the host writes as\n * the file: it stays the editor's, released when the editor goes.\n */\n shownCanvas: () => shown,\n })\n</script>\n\n<template>\n <div class=\"pk-image-editor\">\n <div class=\"pk-image-editor__toolbar\">\n <PkEditorRadioButtons\n v-model=\"tool\"\n name=\"pk-image-editor-tool\"\n segmented\n class=\"mb-0\"\n :aria-label=\"$t('imageEditor.tool')\"\n :options=\"toolOptions\">\n <template #crop=\"{ option }\">\n <VvIcon name=\"ri:crop-line\" class=\"w-16 h-16\" />\n {{ option.label }}\n </template>\n <template #cover=\"{ option }\">\n <VvIcon name=\"ri:eye-off-line\" class=\"w-16 h-16\" />\n {{ option.label }}\n </template>\n </PkEditorRadioButtons>\n <VvButtonGroup modifiers=\"compact\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:anticlockwise-line\"\n :title=\"$t('imageEditor.rotateLeft')\"\n :aria-label=\"$t('imageEditor.rotateLeft')\"\n @click=\"rotate(-1)\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:clockwise-line\"\n :title=\"$t('imageEditor.rotateRight')\"\n :aria-label=\"$t('imageEditor.rotateRight')\"\n @click=\"rotate(1)\" />\n </VvButtonGroup>\n <!-- \"Annulla\" is already the dialog's button: two \"Annulla\"\n doing different things in one window read as one -->\n <VvButtonGroup modifiers=\"compact\" class=\"ml-auto\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-back-line\"\n :title=\"$t('imageEditor.undo')\"\n :aria-label=\"$t('imageEditor.undo')\"\n :disabled=\"!edits.length\"\n @click=\"undo\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-forward-line\"\n :title=\"$t('imageEditor.redo')\"\n :aria-label=\"$t('imageEditor.redo')\"\n :disabled=\"!redoStack.length\"\n @click=\"redo\" />\n </VvButtonGroup>\n </div>\n <div class=\"pk-image-editor__options\">\n <template v-if=\"tool === 'crop'\">\n <span :id=\"aspectLabelId\" class=\"pk-image-editor__label\">\n {{ $t('imageEditor.aspect') }}\n </span>\n <PkEditorRadioButtons\n v-model=\"aspect\"\n name=\"pk-image-editor-aspect\"\n segmented\n class=\"mb-0\"\n :aria-labelledby=\"aspectLabelId\"\n :options=\"aspectOptions\" />\n <span class=\"pk-image-editor__hint\">\n {{ $t('imageEditor.cropHint') }}\n </span>\n <VvButton\n class=\"ml-auto\"\n modifiers=\"secondary\"\n :label=\"$t('action.apply')\"\n :disabled=\"!pendingCrop\"\n @click=\"applyCrop\" />\n </template>\n <template v-else>\n <PkEditorRadioButtons\n v-model=\"coverStyle\"\n name=\"pk-image-editor-cover\"\n segmented\n class=\"mb-0\"\n :aria-label=\"$t('imageEditor.coverStyle')\"\n :options=\"coverOptions\" />\n <span class=\"pk-image-editor__hint\">\n {{ $t('imageEditor.coverHint') }}\n </span>\n </template>\n </div>\n <div ref=\"areaEl\" class=\"pk-image-editor__area\">\n <div\n ref=\"frameEl\"\n class=\"pk-image-editor__frame\"\n :style=\"frameStyle\"\n @pointerdown=\"onPointerDown\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"onPointerCancel\">\n <div ref=\"stageEl\" class=\"pk-image-editor__stage\" />\n <div\n v-if=\"selection\"\n class=\"pk-image-editor__selection\"\n :class=\"`pk-image-editor__selection--${tool}`\"\n :style=\"selectionStyle\" />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-image-editor {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n\n &__toolbar,\n &__options {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8);\n padding: var(--spacing-8) var(--spacing-md);\n border-bottom: 1px solid var(--color-surface-3);\n }\n\n &__toolbar {\n background-color: var(--color-surface-1);\n }\n\n // A segmented control is as wide as its options, each as wide as its\n // words: with the library's equal segments the longer one was cut\n // (\"Riquadro pien\") and its icon shrank. A row too narrow sends the\n // control to a line of its own.\n &__toolbar > .vv-radio-group,\n &__options > .vv-radio-group {\n flex: none;\n width: auto;\n\n .vv-radio {\n flex: none;\n }\n }\n\n &__label {\n color: var(--color-word-2);\n font-size: var(--text-14);\n }\n\n &__hint {\n color: var(--color-word-3);\n font-size: var(--text-12);\n }\n\n // A checkerboard, as in the lightbox: a transparent PNG shows where\n // it is transparent\n &__area {\n display: flex;\n flex: 1;\n align-items: center;\n justify-content: center;\n min-height: 12rem;\n padding: var(--spacing-md);\n overflow: hidden;\n background: repeating-conic-gradient(\n var(--color-surface-2) 0% 25%,\n var(--color-surface) 0% 50%\n )\n 50% / 16px 16px;\n }\n\n &__frame {\n position: relative;\n flex-shrink: 0;\n overflow: hidden;\n box-shadow: var(--shadow-sm);\n cursor: crosshair;\n\n // The drag is the gesture: no scroll or zoom of the page under it\n touch-action: none;\n user-select: none;\n }\n\n &__stage,\n &__stage > canvas {\n display: block;\n width: 100%;\n height: 100%;\n }\n\n // Drawn over a photo, so the same in both themes: white with a dark\n // edge reads on any image\n &__selection {\n position: absolute;\n pointer-events: none;\n border: 2px solid var(--color-white);\n outline: 1px solid\n color-mix(in srgb, var(--color-black) 50%, transparent);\n\n // What a crop leaves out goes dark\n &--crop {\n box-shadow: 0 0 0 100vmax\n color-mix(in srgb, var(--color-black) 55%, transparent);\n }\n\n &--cover {\n border-style: dashed;\n background-color: color-mix(\n in srgb,\n var(--color-black) 30%,\n transparent\n );\n }\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\n useTemplateRef,\n } from 'vue'\n import { useI18n } from 'vue-i18n'\n import { useMediaQuery } from '@vueuse/core'\n import PkImageEditor from './PkImageEditor.vue'\n import {\n editedFileName,\n exportCanvas,\n loadEditableImage,\n releaseCanvas,\n sizeAfterEdits,\n type ImageEdit,\n type LoadedImage,\n } from './imageEdits'\n\n /**\n * The image editor in a dialog (spec `chat-image-editor.md`, F1): opens\n * on an image file and gives back the edited copy, same name and type.\n * Open while it is mounted: `close` asks the host to drop it. It keeps\n * open on a click outside and on `Esc`, which would throw the edits away.\n */\n const props = defineProps<{\n file: File\n }>()\n\n const emit = defineEmits<{\n close: []\n /** The edited copy, to take the place of `file`. */\n apply: [file: File]\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n // The phone breakpoint of the design system: the dialog covers the screen\n const fullscreen = useMediaQuery('(max-width: 575.98px)')\n\n // A canvas is no state to make deeply reactive\n const loaded = shallowRef<LoadedImage>()\n const failed = ref<'load' | 'draw' | 'export'>()\n const edits = ref<ImageEdit[]>([])\n const exporting = ref(false)\n const editorEl =\n useTemplateRef<InstanceType<typeof PkImageEditor>>('editorEl')\n\n onMounted(async () => {\n try {\n loaded.value = await loadEditableImage(props.file)\n } catch {\n failed.value = 'load'\n }\n })\n\n onBeforeUnmount(() => {\n if (loaded.value) {\n releaseCanvas(loaded.value.image)\n }\n })\n\n const size = computed(\n () => loaded.value && sizeAfterEdits(loaded.value.image, edits.value),\n )\n const scaledDown = computed(\n () =>\n !!loaded.value &&\n loaded.value.image.width < loaded.value.original.width,\n )\n const changed = computed(\n () => edits.value.length > 0 || !!editorEl.value?.pendingCrop,\n )\n\n async function useImage() {\n const editor = editorEl.value\n if (!editor) {\n return\n }\n // A crop drawn and not applied is what the user sees: it goes too\n editor.applyCrop()\n // A crop of the whole image changes nothing\n if (!edits.value.length) {\n emit('close')\n return\n }\n failed.value = undefined\n exporting.value = true\n try {\n // The editor draws the crop above in its next update; the file is\n // written from that canvas, not from a second one of full size\n await nextTick()\n const canvas = editor.shownCanvas()\n if (failed.value === 'draw') {\n return\n }\n if (!canvas) {\n throw new Error('No image drawn')\n }\n const blob = await exportCanvas(canvas, props.file.type)\n emit(\n 'apply',\n new File(\n [blob],\n editedFileName(props.file.name, props.file.type, blob.type),\n { type: blob.type, lastModified: Date.now() },\n ),\n )\n } catch {\n failed.value = 'export'\n } finally {\n exporting.value = false\n }\n }\n\n const failedLabel = computed(() => {\n switch (failed.value) {\n case 'export':\n return $t('imageEditor.exportFailed')\n case 'draw':\n return $t('imageEditor.drawFailed')\n default:\n return $t('imageEditor.loadFailed')\n }\n })\n</script>\n\n<template>\n <VvDialog\n :model-value=\"true\"\n :title=\"$t('imageEditor.title')\"\n :modifiers=\"fullscreen ? 'fullscreen' : undefined\"\n keep-open\n class=\"pk-image-editor-dialog\"\n @update:model-value=\"!$event && emit('close')\">\n <VvAlert\n v-if=\"failed\"\n modifiers=\"danger\"\n class=\"m-md\"\n :content=\"failedLabel\" />\n <PkImageEditor\n v-if=\"loaded && failed !== 'draw'\"\n ref=\"editorEl\"\n v-model:edits=\"edits\"\n :image=\"loaded.image\"\n @error=\"failed = 'draw'\" />\n <div\n v-else-if=\"!failed\"\n class=\"pk-image-editor-dialog__loading\"\n role=\"status\"\n :aria-label=\"$t('imageEditor.loading')\">\n <VvIcon name=\"loading-loop\" />\n </div>\n <p v-if=\"size\" class=\"pk-image-editor-dialog__size\">\n {{\n scaledDown\n ? $t('imageEditor.sizeScaledDown', {\n width: size.width,\n height: size.height,\n })\n : $t('imageEditor.size', {\n width: size.width,\n height: size.height,\n })\n }}\n </p>\n <template #footer>\n <VvButtonGroup>\n <VvButton\n modifiers=\"secondary\"\n :label=\"$t('action.cancel')\"\n @click=\"emit('close')\" />\n <VvButton\n :label=\"$t('imageEditor.use')\"\n :loading=\"exporting\"\n :disabled=\"exporting || !changed || failed === 'draw'\"\n @click=\"useImage\" />\n </VvButtonGroup>\n </template>\n </VvDialog>\n</template>\n\n<style lang=\"scss\">\n // Most of the window, as the file viewer: room for a photo and the tools\n .pk-image-editor-dialog {\n &:not(.vv-dialog--fullscreen) > article {\n width: min(64rem, 94dvw);\n height: min(48rem, 92dvh);\n }\n\n // The library writes `max-height: auto`, which is no value (see\n // PkFilePreviewDialog)\n &.vv-dialog--fullscreen > article {\n max-height: none;\n }\n\n .vv-dialog__content {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n padding: 0;\n }\n\n &__loading {\n display: flex;\n flex: 1;\n align-items: center;\n justify-content: center;\n color: var(--color-word-3);\n font-size: var(--text-24);\n }\n\n &__size {\n margin: 0;\n padding: var(--spacing-8) var(--spacing-md);\n border-top: 1px solid var(--color-surface-3);\n color: var(--color-word-3);\n font-size: var(--text-12);\n font-variant-numeric: tabular-nums;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\n useTemplateRef,\n } from 'vue'\n import { useI18n } from 'vue-i18n'\n import { useMediaQuery } from '@vueuse/core'\n import PkImageEditor from './PkImageEditor.vue'\n import {\n editedFileName,\n exportCanvas,\n loadEditableImage,\n releaseCanvas,\n sizeAfterEdits,\n type ImageEdit,\n type LoadedImage,\n } from './imageEdits'\n\n /**\n * The image editor in a dialog (spec `chat-image-editor.md`, F1): opens\n * on an image file and gives back the edited copy, same name and type.\n * Open while it is mounted: `close` asks the host to drop it. It keeps\n * open on a click outside and on `Esc`, which would throw the edits away.\n */\n const props = defineProps<{\n file: File\n }>()\n\n const emit = defineEmits<{\n close: []\n /** The edited copy, to take the place of `file`. */\n apply: [file: File]\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n // The phone breakpoint of the design system: the dialog covers the screen\n const fullscreen = useMediaQuery('(max-width: 575.98px)')\n\n // A canvas is no state to make deeply reactive\n const loaded = shallowRef<LoadedImage>()\n const failed = ref<'load' | 'draw' | 'export'>()\n const edits = ref<ImageEdit[]>([])\n const exporting = ref(false)\n const editorEl =\n useTemplateRef<InstanceType<typeof PkImageEditor>>('editorEl')\n\n onMounted(async () => {\n try {\n loaded.value = await loadEditableImage(props.file)\n } catch {\n failed.value = 'load'\n }\n })\n\n onBeforeUnmount(() => {\n if (loaded.value) {\n releaseCanvas(loaded.value.image)\n }\n })\n\n const size = computed(\n () => loaded.value && sizeAfterEdits(loaded.value.image, edits.value),\n )\n const scaledDown = computed(\n () =>\n !!loaded.value &&\n loaded.value.image.width < loaded.value.original.width,\n )\n const changed = computed(\n () => edits.value.length > 0 || !!editorEl.value?.pendingCrop,\n )\n\n async function useImage() {\n const editor = editorEl.value\n if (!editor) {\n return\n }\n // A crop drawn and not applied is what the user sees: it goes too\n editor.applyCrop()\n // A crop of the whole image changes nothing\n if (!edits.value.length) {\n emit('close')\n return\n }\n failed.value = undefined\n exporting.value = true\n try {\n // The editor draws the crop above in its next update; the file is\n // written from that canvas, not from a second one of full size\n await nextTick()\n const canvas = editor.shownCanvas()\n if (failed.value === 'draw') {\n return\n }\n if (!canvas) {\n throw new Error('No image drawn')\n }\n const blob = await exportCanvas(canvas, props.file.type)\n emit(\n 'apply',\n new File(\n [blob],\n editedFileName(props.file.name, props.file.type, blob.type),\n { type: blob.type, lastModified: Date.now() },\n ),\n )\n } catch {\n failed.value = 'export'\n } finally {\n exporting.value = false\n }\n }\n\n const failedLabel = computed(() => {\n switch (failed.value) {\n case 'export':\n return $t('imageEditor.exportFailed')\n case 'draw':\n return $t('imageEditor.drawFailed')\n default:\n return $t('imageEditor.loadFailed')\n }\n })\n</script>\n\n<template>\n <VvDialog\n :model-value=\"true\"\n :title=\"$t('imageEditor.title')\"\n :modifiers=\"fullscreen ? 'fullscreen' : undefined\"\n keep-open\n class=\"pk-image-editor-dialog\"\n @update:model-value=\"!$event && emit('close')\">\n <VvAlert\n v-if=\"failed\"\n modifiers=\"danger\"\n class=\"m-md\"\n :content=\"failedLabel\" />\n <PkImageEditor\n v-if=\"loaded && failed !== 'draw'\"\n ref=\"editorEl\"\n v-model:edits=\"edits\"\n :image=\"loaded.image\"\n @error=\"failed = 'draw'\" />\n <div\n v-else-if=\"!failed\"\n class=\"pk-image-editor-dialog__loading\"\n role=\"status\"\n :aria-label=\"$t('imageEditor.loading')\">\n <VvIcon name=\"loading-loop\" />\n </div>\n <p v-if=\"size\" class=\"pk-image-editor-dialog__size\">\n {{\n scaledDown\n ? $t('imageEditor.sizeScaledDown', {\n width: size.width,\n height: size.height,\n })\n : $t('imageEditor.size', {\n width: size.width,\n height: size.height,\n })\n }}\n </p>\n <template #footer>\n <VvButtonGroup>\n <VvButton\n modifiers=\"secondary\"\n :label=\"$t('action.cancel')\"\n @click=\"emit('close')\" />\n <VvButton\n :label=\"$t('imageEditor.use')\"\n :loading=\"exporting\"\n :disabled=\"exporting || !changed || failed === 'draw'\"\n @click=\"useImage\" />\n </VvButtonGroup>\n </template>\n </VvDialog>\n</template>\n\n<style lang=\"scss\">\n // Most of the window, as the file viewer: room for a photo and the tools\n .pk-image-editor-dialog {\n &:not(.vv-dialog--fullscreen) > article {\n width: min(64rem, 94dvw);\n height: min(48rem, 92dvh);\n }\n\n // The library writes `max-height: auto`, which is no value (see\n // PkFilePreviewDialog)\n &.vv-dialog--fullscreen > article {\n max-height: none;\n }\n\n .vv-dialog__content {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n padding: 0;\n }\n\n &__loading {\n display: flex;\n flex: 1;\n align-items: center;\n justify-content: center;\n color: var(--color-word-3);\n font-size: var(--text-24);\n }\n\n &__size {\n margin: 0;\n padding: var(--spacing-8) var(--spacing-md);\n border-top: 1px solid var(--color-surface-3);\n color: var(--color-word-3);\n font-size: var(--text-12);\n font-variant-numeric: tabular-nums;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\n useTemplateRef,\n } from 'vue'\n import { useI18n } from 'vue-i18n'\n import { useMediaQuery } from '@vueuse/core'\n import PkImageEditor from './PkImageEditor.vue'\n import {\n editedFileName,\n exportCanvas,\n loadEditableImage,\n releaseCanvas,\n sizeAfterEdits,\n type ImageEdit,\n type LoadedImage,\n } from './imageEdits'\n\n /**\n * The image editor in a dialog (spec `chat-image-editor.md`, F1): opens\n * on an image file and gives back the edited copy, same name and type.\n * Open while it is mounted: `close` asks the host to drop it. It keeps\n * open on a click outside and on `Esc`, which would throw the edits away.\n */\n const props = defineProps<{\n file: File\n }>()\n\n const emit = defineEmits<{\n close: []\n /** The edited copy, to take the place of `file`. */\n apply: [file: File]\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n // The phone breakpoint of the design system: the dialog covers the screen\n const fullscreen = useMediaQuery('(max-width: 575.98px)')\n\n // A canvas is no state to make deeply reactive\n const loaded = shallowRef<LoadedImage>()\n const failed = ref<'load' | 'draw' | 'export'>()\n const edits = ref<ImageEdit[]>([])\n const exporting = ref(false)\n const editorEl =\n useTemplateRef<InstanceType<typeof PkImageEditor>>('editorEl')\n\n onMounted(async () => {\n try {\n loaded.value = await loadEditableImage(props.file)\n } catch {\n failed.value = 'load'\n }\n })\n\n onBeforeUnmount(() => {\n if (loaded.value) {\n releaseCanvas(loaded.value.image)\n }\n })\n\n const size = computed(\n () => loaded.value && sizeAfterEdits(loaded.value.image, edits.value),\n )\n const scaledDown = computed(\n () =>\n !!loaded.value &&\n loaded.value.image.width < loaded.value.original.width,\n )\n const changed = computed(\n () => edits.value.length > 0 || !!editorEl.value?.pendingCrop,\n )\n\n async function useImage() {\n const editor = editorEl.value\n if (!editor) {\n return\n }\n // A crop drawn and not applied is what the user sees: it goes too\n editor.applyCrop()\n // A crop of the whole image changes nothing\n if (!edits.value.length) {\n emit('close')\n return\n }\n failed.value = undefined\n exporting.value = true\n try {\n // The editor draws the crop above in its next update; the file is\n // written from that canvas, not from a second one of full size\n await nextTick()\n const canvas = editor.shownCanvas()\n if (failed.value === 'draw') {\n return\n }\n if (!canvas) {\n throw new Error('No image drawn')\n }\n const blob = await exportCanvas(canvas, props.file.type)\n emit(\n 'apply',\n new File(\n [blob],\n editedFileName(props.file.name, props.file.type, blob.type),\n { type: blob.type, lastModified: Date.now() },\n ),\n )\n } catch {\n failed.value = 'export'\n } finally {\n exporting.value = false\n }\n }\n\n const failedLabel = computed(() => {\n switch (failed.value) {\n case 'export':\n return $t('imageEditor.exportFailed')\n case 'draw':\n return $t('imageEditor.drawFailed')\n default:\n return $t('imageEditor.loadFailed')\n }\n })\n</script>\n\n<template>\n <VvDialog\n :model-value=\"true\"\n :title=\"$t('imageEditor.title')\"\n :modifiers=\"fullscreen ? 'fullscreen' : undefined\"\n keep-open\n class=\"pk-image-editor-dialog\"\n @update:model-value=\"!$event && emit('close')\">\n <VvAlert\n v-if=\"failed\"\n modifiers=\"danger\"\n class=\"m-md\"\n :content=\"failedLabel\" />\n <PkImageEditor\n v-if=\"loaded && failed !== 'draw'\"\n ref=\"editorEl\"\n v-model:edits=\"edits\"\n :image=\"loaded.image\"\n @error=\"failed = 'draw'\" />\n <div\n v-else-if=\"!failed\"\n class=\"pk-image-editor-dialog__loading\"\n role=\"status\"\n :aria-label=\"$t('imageEditor.loading')\">\n <VvIcon name=\"loading-loop\" />\n </div>\n <p v-if=\"size\" class=\"pk-image-editor-dialog__size\">\n {{\n scaledDown\n ? $t('imageEditor.sizeScaledDown', {\n width: size.width,\n height: size.height,\n })\n : $t('imageEditor.size', {\n width: size.width,\n height: size.height,\n })\n }}\n </p>\n <template #footer>\n <VvButtonGroup>\n <VvButton\n modifiers=\"secondary\"\n :label=\"$t('action.cancel')\"\n @click=\"emit('close')\" />\n <VvButton\n :label=\"$t('imageEditor.use')\"\n :loading=\"exporting\"\n :disabled=\"exporting || !changed || failed === 'draw'\"\n @click=\"useImage\" />\n </VvButtonGroup>\n </template>\n </VvDialog>\n</template>\n\n<style lang=\"scss\">\n // Most of the window, as the file viewer: room for a photo and the tools\n .pk-image-editor-dialog {\n &:not(.vv-dialog--fullscreen) > article {\n width: min(64rem, 94dvw);\n height: min(48rem, 92dvh);\n }\n\n // The library writes `max-height: auto`, which is no value (see\n // PkFilePreviewDialog)\n &.vv-dialog--fullscreen > article {\n max-height: none;\n }\n\n .vv-dialog__content {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n padding: 0;\n }\n\n &__loading {\n display: flex;\n flex: 1;\n align-items: center;\n justify-content: center;\n color: var(--color-word-3);\n font-size: var(--text-24);\n }\n\n &__size {\n margin: 0;\n padding: var(--spacing-8) var(--spacing-md);\n border-top: 1px solid var(--color-surface-3);\n color: var(--color-word-3);\n font-size: var(--text-12);\n font-variant-numeric: tabular-nums;\n }\n }\n</style>\n"],"mappings":";;;;;;;;AAyCA,IAAayE,KAAkB,UAGlBC,KAAiB,KAOxBC,IAAkB,IAClBC,IAAsB,IAEtBC,IAAqC;CACvC,cAAc;CACd,aAAa;CACb,cAAc;AAClB;AAMA,SAAgBC,GACZ,GACA,IAAUL,IACD;CACT,IAAMM,IAAOC,EAAK,QAAQA,EAAK;CAC/B,IAAID,KAAQE,GACR,OAAO;EAAE,OAAOD,EAAK;EAAO,QAAQA,EAAK;CAAO;CAEpD,IAAME,IAAQ,KAAK,KAAKD,IAAUF,CAAI;CACtC,OAAO;EACH,OAAO,KAAK,IAAI,GAAG,KAAK,MAAMC,EAAK,QAAQE,CAAK,CAAC;EACjD,QAAQ,KAAK,IA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 @@
|
|
|
1
|
-
{"version":3,"file":"useLightbox-D2Zi-Fpe.js","names":["inject","provide","onBeforeUnmount","onMounted","ref","init_runtime_core_esm_bundler","init_reactivity_esm_bundler","shallowRef","useI18n","loadCdnCss","PHOTOSWIPE_CSS","DEFAULT_IMAGE_SIZE","MAX_ZOOM_LAYER_WIDTH","ZOOM_KEYS","SHARED_LIGHTBOX","SHARED_ITEMS","useLightbox","options","lightbox","sharedLightbox","shared","useSharedLightbox","$t","unmounted","gallery","injectPhotoSwipeOverrides","PhotoSwipeLightbox","zoomLevel","linkEl","itemData","element","src","caption","pswp","canCopyImages","COPY_ICON","url","getCurrentSlideUrl","readableImageUrl","readable","copyImage","openInNewTab","downloadable","ui","downloadImage","event","factor","key","slide","ctrlKey","metaKey","altKey","provideSharedLightbox","container","joined","started","start","init","useImageSizes","sizes","image","images","img","COPIED_ICON","COPY_FAILED_ICON","COPY_FEEDBACK_MS","copyFeedbackTimers","readAsPng","response","blob","objectUrl","canvas","png","resolve","reject","show","icon","label","button","labels","downloadUrl","toDownloadUrl","anchor","getFilenameFromUrl","name","overridesInjected","style"],"sources":["../../../../packages/components/src/composables/useLightbox.ts"],"sourcesContent":["import {\n inject,\n onBeforeUnmount,\n onMounted,\n provide,\n ref,\n shallowRef,\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 { 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/** 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 * 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\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 } = options\n\n const lightbox = shallowRef<PhotoSwipeLightbox | null>(null)\n const sharedLightbox = shared ? useSharedLightbox() : 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 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 // 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: 7,\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: 8,\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: 9,\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 })\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\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 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 * 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 response = await fetch(url, { credentials: 'include' })\n if (!response.ok) {\n throw new Error(`The image answered ${response.status}`)\n }\n const blob = await response.blob()\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 '.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":";;;;;;AAgBA,IAAMU,IACF,iEAEEC,IAAqB;CAAE,OAAO;CAAM,QAAQ;AAAI,GAIhDC,IAAuB,KAGvBC,IAAgD;CAClD,KAAK;CACL,KAAK;CACL,KAAK;CACL,GAAG;AACP,GASMC,IAAgD,OAAO,gBAAgB,GAOvEC,IACF;AAkDJ,SAAgBC,EAAY,GAA6C;CACrE,IAAM,EACF,YACA,cAAW,oBACX,UAAO,IACP,kBAAe,IACf,kBAAe,IACf,YAAS,OACTC,GAEEC,IAAWX,EAAsC,IAAI,GACrDY,IAAiBC,IAASC,EAAkB,IAAI,KAAA,GAChD,EAAE,GAAGC,MAAOd,EAAQ,EAAE,UAAU,SAAS,CAAC,GAC5Ce,IAAY;CA0MhB,OANArB,QAAsB;EAGlB,AAFA,IAAY,IACZgB,EAAS,OAAO,QAAQ,GACxB,EAAS,QAAQ;CACrB,CAAC,GAEM;EAAE;EAAU,kBAxMM;GACrB,IAAIC,GAAgB;IAChB,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