@8wave/ai-elements 0.125.0-beta.39 → 0.125.0-beta.40
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-Dt0ygdJM.js → PkChatbotFilePreview-o0zIuCgN.js} +2 -2
- package/dist/_chunks/{PkChatbotFilePreview-Dt0ygdJM.js.map → PkChatbotFilePreview-o0zIuCgN.js.map} +1 -1
- package/dist/_chunks/{PkFilePreview-CT3_vRcU.js → PkFilePreview-D_1ZgiiA.js} +438 -438
- package/dist/_chunks/{PkFilePreview-CT3_vRcU.js.map → PkFilePreview-D_1ZgiiA.js.map} +1 -1
- package/dist/_chunks/{PkFilePreviewDialog-BOKJCapN.js → PkFilePreviewDialog-CI22huzK.js} +2 -2
- package/dist/_chunks/{PkFilePreviewDialog-BOKJCapN.js.map → PkFilePreviewDialog-CI22huzK.js.map} +1 -1
- package/dist/_chunks/{PkImageEditorDialog-D-ikpGo8.js → PkImageEditorDialog-CAEninFi.js} +152 -130
- package/dist/_chunks/PkImageEditorDialog-CAEninFi.js.map +1 -0
- package/dist/_chunks/{PkSelectionActions-CXQTnSXQ.js → PkSelectionActions-BriGyWCi.js} +2 -2
- package/dist/_chunks/{PkSelectionActions-CXQTnSXQ.js.map → PkSelectionActions-BriGyWCi.js.map} +1 -1
- package/dist/_chunks/{PkStreamingMarkdown-5fgxYt_s.js → PkStreamingMarkdown--9i0feuM.js} +3 -3
- package/dist/_chunks/{PkStreamingMarkdown-5fgxYt_s.js.map → PkStreamingMarkdown--9i0feuM.js.map} +1 -1
- package/dist/_chunks/{PkToolChatFile-Cbmu6I0S.js → PkToolChatFile-BKGUnWrj.js} +3 -3
- package/dist/_chunks/{PkToolChatFile-Cbmu6I0S.js.map → PkToolChatFile-BKGUnWrj.js.map} +1 -1
- package/dist/_chunks/{PkToolShareDocument-Bxm1pSpj.js → PkToolShareDocument-BUg-uDTO.js} +2 -2
- package/dist/_chunks/{PkToolShareDocument-Bxm1pSpj.js.map → PkToolShareDocument-BUg-uDTO.js.map} +1 -1
- package/dist/_chunks/{PkToolShowArtifact-CGUmoTfN.js → PkToolShowArtifact-BfLpz2-W.js} +2 -2
- package/dist/_chunks/{PkToolShowArtifact-CGUmoTfN.js.map → PkToolShowArtifact-BfLpz2-W.js.map} +1 -1
- package/dist/_chunks/{PkToolShowContactForm-DZ-kgXa6.js → PkToolShowContactForm-BsF6DFzV.js} +2 -2
- package/dist/_chunks/{PkToolShowContactForm-DZ-kgXa6.js.map → PkToolShowContactForm-BsF6DFzV.js.map} +1 -1
- package/dist/_chunks/{PkToolShowDiagram-CwINVecL.js → PkToolShowDiagram-CcRJNDHo.js} +2 -2
- package/dist/_chunks/{PkToolShowDiagram-CwINVecL.js.map → PkToolShowDiagram-CcRJNDHo.js.map} +1 -1
- package/dist/_chunks/{PkToolShowForm-BrxNGFCH.js → PkToolShowForm-w6RvbKEB.js} +3 -3
- package/dist/_chunks/{PkToolShowForm-BrxNGFCH.js.map → PkToolShowForm-w6RvbKEB.js.map} +1 -1
- package/dist/_chunks/{PkToolShowImageGallery-BGTncXxq.js → PkToolShowImageGallery-BEddh4He.js} +2 -2
- package/dist/_chunks/{PkToolShowImageGallery-BGTncXxq.js.map → PkToolShowImageGallery-BEddh4He.js.map} +1 -1
- package/dist/_chunks/{PkToolShowSources-B3RSUWP7.js → PkToolShowSources-CGESvGrm.js} +2 -2
- package/dist/_chunks/{PkToolShowSources-B3RSUWP7.js.map → PkToolShowSources-CGESvGrm.js.map} +1 -1
- package/dist/_chunks/{useLightbox-C54BCSbU.js → useLightbox-TagJmiah.js} +38 -37
- package/dist/_chunks/useLightbox-TagJmiah.js.map +1 -0
- package/dist/_chunks/{utils-Do6urHUh.js → utils-zkq8kMz-.js} +7 -4
- package/{dist-vue/_chunks/utils-Do3JWPJe.js.map → dist/_chunks/utils-zkq8kMz-.js.map} +1 -1
- package/dist/ai-elements.es.js +2711 -2711
- 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/PkChatbotStepPayload.js +1 -1
- package/dist-vue/PkChatbotStepToolDetail.js +1 -1
- package/dist-vue/PkChatbotSteps.js +1 -1
- package/dist-vue/PkChatbotViewChat.js +1 -1
- package/dist-vue/PkChatbotViewConversations.js +1 -1
- package/dist-vue/_chunks/{PkChart-BsF3OtnS.js → PkChart-DyyBXkd3.js} +2 -2
- package/dist-vue/_chunks/{PkChart-BsF3OtnS.js.map → PkChart-DyyBXkd3.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbot-BIQh81cA.js → PkChatbot-wsqj3EpU.js} +5 -5
- package/dist-vue/_chunks/{PkChatbot-BIQh81cA.js.map → PkChatbot-wsqj3EpU.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotEmptyState-pAeFPPQc.js → PkChatbotEmptyState-DcgIfNkX.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotEmptyState-pAeFPPQc.js.map → PkChatbotEmptyState-DcgIfNkX.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotFilePreview-BIta8Yg-.js → PkChatbotFilePreview-BDU2vY0F.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotFilePreview-BIta8Yg-.js.map → PkChatbotFilePreview-BDU2vY0F.js.map} +1 -1
- package/dist-vue/_chunks/PkChatbotInput-CN4rmNgu.js +520 -0
- package/dist-vue/_chunks/PkChatbotInput-CN4rmNgu.js.map +1 -0
- package/dist-vue/_chunks/PkChatbotMessages-BlF4Xp0_.js +1054 -0
- package/dist-vue/_chunks/{PkChatbotMessages-CZu8feEz.js.map → PkChatbotMessages-BlF4Xp0_.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotStepPayload-r25JHO7_.js → PkChatbotStepPayload-q9uXE5mr.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotStepPayload-r25JHO7_.js.map → PkChatbotStepPayload-q9uXE5mr.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotStepToolDetail-C897BpRX.js → PkChatbotStepToolDetail-BJz6Qwh3.js} +3 -3
- package/dist-vue/_chunks/{PkChatbotStepToolDetail-C897BpRX.js.map → PkChatbotStepToolDetail-BJz6Qwh3.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotSteps-CRtIVwJV.js → PkChatbotSteps-DvJYNl_k.js} +5 -5
- package/dist-vue/_chunks/{PkChatbotSteps-CRtIVwJV.js.map → PkChatbotSteps-DvJYNl_k.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotViewChat-BBCxj4Qz.js → PkChatbotViewChat-tmHyxxT3.js} +23 -23
- package/dist-vue/_chunks/{PkChatbotViewChat-BBCxj4Qz.js.map → PkChatbotViewChat-tmHyxxT3.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotViewConversations-rXGl7NKA.js → PkChatbotViewConversations-DOzUh_A7.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotViewConversations-rXGl7NKA.js.map → PkChatbotViewConversations-DOzUh_A7.js.map} +1 -1
- package/dist-vue/_chunks/{PkFilePreview-1ZNyDAo5.js → PkFilePreview-Bp5-Pl54.js} +227 -227
- package/dist-vue/_chunks/{PkFilePreview-1ZNyDAo5.js.map → PkFilePreview-Bp5-Pl54.js.map} +1 -1
- package/dist-vue/_chunks/{PkFilePreviewDialog-DnbUHGG2.js → PkFilePreviewDialog-CS885vBR.js} +2 -2
- package/dist-vue/_chunks/{PkFilePreviewDialog-DnbUHGG2.js.map → PkFilePreviewDialog-CS885vBR.js.map} +1 -1
- package/dist-vue/_chunks/{PkImageEditorDialog-Dn3HV_ny.js → PkImageEditorDialog-BhfdnsmX.js} +300 -278
- package/dist-vue/_chunks/PkImageEditorDialog-BhfdnsmX.js.map +1 -0
- package/dist-vue/_chunks/{PkStreamingMarkdown-COQLmP8b.js → PkStreamingMarkdown-NgrJUZPI.js} +3 -3
- package/dist-vue/_chunks/{PkStreamingMarkdown-COQLmP8b.js.map → PkStreamingMarkdown-NgrJUZPI.js.map} +1 -1
- package/dist-vue/_chunks/{PkSvgViewer-vkd5Dluw.js → PkSvgViewer-CRNwb6Yn.js} +2 -2
- package/dist-vue/_chunks/{PkSvgViewer-vkd5Dluw.js.map → PkSvgViewer-CRNwb6Yn.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolChatFile-e-7a0k7l.js → PkToolChatFile-DnmiNGF4.js} +3 -3
- package/dist-vue/_chunks/{PkToolChatFile-e-7a0k7l.js.map → PkToolChatFile-DnmiNGF4.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShareDocument-CspvFwRR.js → PkToolShareDocument-Bf7OE8XA.js} +2 -2
- package/dist-vue/_chunks/{PkToolShareDocument-CspvFwRR.js.map → PkToolShareDocument-Bf7OE8XA.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowArtifact-CUP3VaC9.js → PkToolShowArtifact-C8ueuIGQ.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowArtifact-CUP3VaC9.js.map → PkToolShowArtifact-C8ueuIGQ.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowChart-X6JZDAWD.js → PkToolShowChart-BWO6Hzlq.js} +3 -3
- package/dist-vue/_chunks/{PkToolShowChart-X6JZDAWD.js.map → PkToolShowChart-BWO6Hzlq.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowContactForm-BM8d9M5a.js → PkToolShowContactForm-BBcDsLEO.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowContactForm-BM8d9M5a.js.map → PkToolShowContactForm-BBcDsLEO.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowDiagram-DOdzpndK.js → PkToolShowDiagram-BzUcxOKy.js} +3 -3
- package/dist-vue/_chunks/{PkToolShowDiagram-DOdzpndK.js.map → PkToolShowDiagram-BzUcxOKy.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowForm-TYBf8q6g.js → PkToolShowForm-B6uhHzJ8.js} +3 -3
- package/dist-vue/_chunks/{PkToolShowForm-TYBf8q6g.js.map → PkToolShowForm-B6uhHzJ8.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowImageGallery-BvwuoyF6.js → PkToolShowImageGallery-C39nlJrJ.js} +3 -3
- package/dist-vue/_chunks/{PkToolShowImageGallery-BvwuoyF6.js.map → PkToolShowImageGallery-C39nlJrJ.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowLocation-WdRqG8Wi.js → PkToolShowLocation-Nhh_LwmN.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowLocation-WdRqG8Wi.js.map → PkToolShowLocation-Nhh_LwmN.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowProductList-_MHBAgNI.js → PkToolShowProductList-FLLkRCnm.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowProductList-_MHBAgNI.js.map → PkToolShowProductList-FLLkRCnm.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowSources-CHw7qZtw.js → PkToolShowSources-Cb7r5jrX.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowSources-CHw7qZtw.js.map → PkToolShowSources-Cb7r5jrX.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowVideo-D7oiBe4p.js → PkToolShowVideo-QDLhVlau.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowVideo-D7oiBe4p.js.map → PkToolShowVideo-QDLhVlau.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowWebPages-CRq9Jhmw.js → PkToolShowWebPages-P6PdJTEE.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowWebPages-CRq9Jhmw.js.map → PkToolShowWebPages-P6PdJTEE.js.map} +1 -1
- package/dist-vue/_chunks/{useLightbox-Ctl9zaMX.js → useLightbox-DmtNa8bJ.js} +38 -37
- package/dist-vue/_chunks/useLightbox-DmtNa8bJ.js.map +1 -0
- package/dist-vue/_chunks/{utils-Do3JWPJe.js → utils-D4B1FVGF.js} +6 -3
- package/dist-vue/_chunks/utils-D4B1FVGF.js.map +1 -0
- package/dist-vue/composables.js +1 -1
- package/dist-vue/index.js +61 -61
- package/dist-vue/index.js.map +1 -1
- package/dist-vue/packages/components/src/chat/imageEdits.d.ts +3 -1
- package/dist-vue/packages/components/src/chat/utils.d.ts +6 -0
- package/dist-vue/packages/components/src/composables/useLightbox.d.ts +6 -0
- package/package.json +1 -1
- package/dist/_chunks/PkImageEditorDialog-D-ikpGo8.js.map +0 -1
- package/dist/_chunks/useLightbox-C54BCSbU.js.map +0 -1
- package/dist/_chunks/utils-Do6urHUh.js.map +0 -1
- package/dist-vue/_chunks/PkChatbotInput-DSyIo0xB.js +0 -520
- package/dist-vue/_chunks/PkChatbotInput-DSyIo0xB.js.map +0 -1
- package/dist-vue/_chunks/PkChatbotMessages-CZu8feEz.js +0 -1054
- package/dist-vue/_chunks/PkImageEditorDialog-Dn3HV_ny.js.map +0 -1
- package/dist-vue/_chunks/useLightbox-Ctl9zaMX.js.map +0 -1
|
@@ -110,7 +110,9 @@ export declare function edgeWidth(width: number): number;
|
|
|
110
110
|
/**
|
|
111
111
|
* The lines a text takes in `maxWidth`, broken between words as the field
|
|
112
112
|
* it is typed in breaks them, and a word longer than a line where it meets
|
|
113
|
-
* the edge.
|
|
113
|
+
* the edge. A line break typed or pasted starts a new line, an empty one
|
|
114
|
+
* included; a non-breaking space joins its words. `measure` gives the width
|
|
115
|
+
* of a string in the text's font.
|
|
114
116
|
*/
|
|
115
117
|
export declare function wrapText(text: string, maxWidth: number, measure: (part: string) => number): string[];
|
|
116
118
|
/**
|
|
@@ -349,6 +349,12 @@ export declare const chatFileName: (filename: string, version?: number) => strin
|
|
|
349
349
|
* composer would otherwise pull into the main bundle of the widget.
|
|
350
350
|
*/
|
|
351
351
|
export declare function isEditableImage(mediaType: string): boolean;
|
|
352
|
+
/**
|
|
353
|
+
* An input method (Japanese, Chinese, Korean) is composing a word: its
|
|
354
|
+
* Enter and Esc confirm or drop the word. Safari reports the Enter that
|
|
355
|
+
* confirms it with `isComposing` already false, hence the 229.
|
|
356
|
+
*/
|
|
357
|
+
export declare function isImeComposing(event: KeyboardEvent): boolean;
|
|
352
358
|
/**
|
|
353
359
|
* Whether a chat stands in front of the place of the bar that shows the
|
|
354
360
|
* agent acting on the page (`PkPageControlBar`): the top centre of the
|
|
@@ -44,6 +44,12 @@ export interface LightboxOptions {
|
|
|
44
44
|
* (`provideSharedLightbox`), when there is one.
|
|
45
45
|
*/
|
|
46
46
|
shared?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Offers "Annota e chiedi" where a chat provides it
|
|
49
|
+
* (`provideImageAnnotation`): the conversation's lightbox only, not the
|
|
50
|
+
* one of an attachment still in the composer, which has its own editor.
|
|
51
|
+
*/
|
|
52
|
+
annotatable?: boolean;
|
|
47
53
|
}
|
|
48
54
|
export interface UseLightboxReturn {
|
|
49
55
|
lightbox: ShallowRef<PhotoSwipeLightbox | null>;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PkImageEditorDialog-D-ikpGo8.js","names":["_hoisted_1","_hoisted_2","_useModel","__unplugin_components_0","__unplugin_components_1","__unplugin_components_2","_openBlock","_createElementBlock","_createElementVNode","_createVNode","PkEditorRadioButtons","_unref","_createSlots","_renderList","_withCtx","_toDisplayString","_Fragment","_normalizeStyle","_normalizeClass","_createCommentVNode","_withDirectives","_withModifiers","_withKeys","_vModelText","_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","renderList","useTemplateRef","createBlock","createSlots","vModelText","withModifiers","Fragment","createBaseVNode","ref","computed","init_runtime_core_esm_bundler","toDisplayString","withDirectives","init_reactivity_esm_bundler","useId","init_runtime_dom_esm_bundler","withCtx","withKeys","createCommentVNode","shallowRef","defineComponent","unref","createElementBlock","openBlock","useI18n","useMediaQuery","useResizeObserver","ao","ou","uu","Ee","VvButtonLocalized","_plugin_vue_export_helper_default","PkEditorRadioButtons_default","ANNOTATION_COLORS","ANNOTATION_FONT","MAX_CANVAS_AREA","EXPORT_QUALITY","MIN_PIXEL_BLOCK","PIXEL_BLOCK_DIVISOR","MIN_STROKE","STROKE_DIVISOR","MIN_TEXT_SIZE","TEXT_SIZE_DIVISOR","TEXT_EDGE_DIVISOR","TEXT_LINE_HEIGHT","ARROW_HEAD_LENGTH","ARROW_HEAD_HALF_WIDTH","ARROW_HEAD_SHARE","EXTENSIONS","fitToArea","area","size","maxArea","scale","sizeAfterEdits","edit","edits","width","height","pixelBlock","strokeWidth","textSize","edgeWidth","wrapText","lines","line","word","text","joined","measure","maxWidth","rest","cut","arrowShape","dx","to","from","dy","length","ux","uy","headLength","half","base","dragRect","ax","clamp","bounds","ay","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","drawAnnotation","edge","fill","part","top","at","outline","extra","tracePath","lineEnd","head","exportCanvas","blob","resolve","reject","type","source","turn","rect","cover","style","pixels","first","points","last","point","end","pointIn","max","min","value","_hoisted_1$1","_hoisted_2$1","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_hoisted_13","MIN_DRAG","MIN_STEP","TEXT_MAX_LENGTH","PkImageEditor_default","\"edits\"","\"editsModifiers\"","__expose","__emit","props","__props","emit","$t","ASPECTS","tool","coverStyle","toolOptions","aspectOptions","coverOptions","colorOptions","annotationHint","aspectLabelId","colorLabelId","redoStack","push","undo","redo","stageEl","shown","draw","draftEl","areaEl","room","entry","frameStyle","frameEl","selection","dragFrom","draft","dragPointer","pointOf","box","event","onPointerDown","onPointerMove","stroke","distance","onPointerUp","visible","mark","drawn","onPointerCancel","drawDraft","frame","ratio","k","pendingCrop","applyCrop","selectionStyle","textDraft","textEl","openText","commitText","fitText","typed","composing","onTextEnter","onTextEscape","field","pendingText","textStyle","_component_VvIcon","_component_VvButton","_component_VvButtonGroup","_cache","$event","option","_hoisted_1","_hoisted_2","PkImageEditorDialog_default","fullscreen","loaded","failed","exporting","editorEl","unmounted","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/** The colors an annotation is drawn in, the same in both themes. */\nexport type AnnotationColor =\n 'red' | 'yellow' | 'green' | 'blue' | 'white' | 'black'\n\n/**\n * Each color with the edge drawn around it, which keeps a mark readable on a\n * background of its own color: a red arrow on a red chart, a white text on a\n * white page.\n */\nexport const ANNOTATION_COLORS: Record<\n AnnotationColor,\n { fill: string; edge: string }\n> = {\n red: { fill: '#ff3b30', edge: '#ffffff' },\n yellow: { fill: '#ffcc00', edge: '#000000' },\n green: { fill: '#34c759', edge: '#000000' },\n blue: { fill: '#007aff', edge: '#ffffff' },\n white: { fill: '#ffffff', edge: '#000000' },\n black: { fill: '#000000', edge: '#ffffff' },\n}\n\n/** The font of a text annotation: the system's, loaded on every page. */\nexport const ANNOTATION_FONT =\n 'system-ui, -apple-system, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif'\n\n/** The tools of the editor, each the kind of edit it adds. */\nexport type EditorTool = 'crop' | 'cover' | 'arrow' | 'rect' | 'path' | 'text'\n\n/**\n * A mark drawn over the image. Its line `width` (the font size of a text) is\n * fixed when it is drawn, so a crop afterwards does not thicken it.\n */\nexport type AnnotationEdit =\n | {\n kind: 'arrow'\n from: ImagePoint\n to: ImagePoint\n color: AnnotationColor\n width: number\n }\n | { kind: 'rect'; rect: ImageRect; color: AnnotationColor; width: number }\n | {\n kind: 'path'\n points: ImagePoint[]\n color: AnnotationColor\n width: number\n }\n | {\n kind: 'text'\n /** The top left corner of the first line. */\n at: ImagePoint\n text: string\n color: AnnotationColor\n size: number\n /** The width its lines wrap in: from `at` to the right edge. */\n maxWidth: number\n }\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 | AnnotationEdit\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\n/**\n * The line of an annotation, and the font size of a text, against the short\n * side of the image: thick enough to read once the chat shows the image\n * small, never under a few pixels on a small one.\n */\nconst MIN_STROKE = 3\nconst STROKE_DIVISOR = 160\nconst MIN_TEXT_SIZE = 16\nconst TEXT_SIZE_DIVISOR = 28\n/** The edge around the letters of a text, against its font size. */\nconst TEXT_EDGE_DIVISOR = 12\n\n/** The lines of a text, in font sizes: the field the text is typed in too. */\nexport const TEXT_LINE_HEIGHT = 1.2\n\n/** The head of an arrow, in line widths: its length, and its half width. */\nconst ARROW_HEAD_LENGTH = 4\nconst ARROW_HEAD_HALF_WIDTH = 2.2\n/** On a short arrow the head takes at most this part of its length. */\nconst ARROW_HEAD_SHARE = 0.6\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/** The line width of an arrow, a rectangle or a stroke on an image of `size`. */\nexport function strokeWidth(size: ImageSize): number {\n return Math.max(\n MIN_STROKE,\n Math.round(Math.min(size.width, size.height) / STROKE_DIVISOR),\n )\n}\n\n/** The font size of a text on an image of `size`. */\nexport function textSize(size: ImageSize): number {\n return Math.max(\n MIN_TEXT_SIZE,\n Math.round(Math.min(size.width, size.height) / TEXT_SIZE_DIVISOR),\n )\n}\n\n/** The edge on each side of a line `width` wide. */\nexport function edgeWidth(width: number): number {\n return Math.max(1, Math.round(width / 3))\n}\n\n/**\n * The lines a text takes in `maxWidth`, broken between words as the field\n * it is typed in breaks them, and a word longer than a line where it meets\n * the edge. `measure` gives the width of a string in the text's font.\n */\nexport function wrapText(\n text: string,\n maxWidth: number,\n measure: (part: string) => number,\n): string[] {\n const lines: string[] = []\n let line = ''\n for (const word of text.split(/\\s+/).filter(Boolean)) {\n const joined = line ? `${line} ${word}` : word\n if (measure(joined) <= maxWidth) {\n line = joined\n continue\n }\n if (line) {\n lines.push(line)\n }\n let rest = word\n while (rest.length > 1 && measure(rest) > maxWidth) {\n let cut = rest.length - 1\n while (cut > 1 && measure(rest.slice(0, cut)) > maxWidth) {\n cut--\n }\n lines.push(rest.slice(0, cut))\n rest = rest.slice(cut)\n }\n line = rest\n }\n if (line) {\n lines.push(line)\n }\n return lines\n}\n\n/**\n * An arrow from `from` to its tip `to`: the line stops where the head\n * starts, so its round end does not show past the tip. On a short arrow the\n * head shrinks to stay an arrow and not a triangle.\n */\nexport function arrowShape(\n from: ImagePoint,\n to: ImagePoint,\n width: number,\n): { lineEnd: ImagePoint; head: [ImagePoint, ImagePoint, ImagePoint] } {\n const dx = to.x - from.x\n const dy = to.y - from.y\n const length = Math.hypot(dx, dy)\n if (!length) {\n return { lineEnd: to, head: [to, to, to] }\n }\n const ux = dx / length\n const uy = dy / length\n const headLength = Math.min(\n width * ARROW_HEAD_LENGTH,\n length * ARROW_HEAD_SHARE,\n )\n const half = (headLength * ARROW_HEAD_HALF_WIDTH) / ARROW_HEAD_LENGTH\n const base = { x: to.x - ux * headLength, y: to.y - uy * headLength }\n return {\n lineEnd: base,\n head: [\n { x: to.x, y: to.y },\n { x: base.x - uy * half, y: base.y + ux * half },\n { x: base.x + uy * half, y: base.y - ux * half },\n ],\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 if (edit.kind !== 'rotate' && edit.kind !== 'crop') {\n drawAnnotation(context(canvas), edit)\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 * Draws an annotation in the coordinates `g` is set to: the edited image's\n * on a copy of it, the screen's scaled to the image while it is drawn. The\n * edge goes first, all of it, then the color over it.\n */\nexport function drawAnnotation(\n g: CanvasRenderingContext2D,\n edit: AnnotationEdit,\n): void {\n const { fill, edge } = ANNOTATION_COLORS[edit.color]\n g.save()\n g.lineCap = 'round'\n g.lineJoin = 'round'\n if (edit.kind === 'text') {\n const { at, size } = edit\n g.font = `700 ${size}px ${ANNOTATION_FONT}`\n g.textBaseline = 'top'\n g.lineWidth = Math.max(1, Math.round(size / TEXT_EDGE_DIVISOR)) * 2\n g.strokeStyle = edge\n g.fillStyle = fill\n const lines = wrapText(\n edit.text,\n edit.maxWidth,\n (part) => g.measureText(part).width,\n )\n // Each line sits in the middle of its height, as in the field\n const top = (i: number) =>\n at.y + size * (i * TEXT_LINE_HEIGHT + (TEXT_LINE_HEIGHT - 1) / 2)\n lines.forEach((line, i) => g.strokeText(line, at.x, top(i)))\n lines.forEach((line, i) => g.fillText(line, at.x, top(i)))\n g.restore()\n return\n }\n const outline = edgeWidth(edit.width)\n for (const [color, extra] of [\n [edge, outline * 2],\n [fill, 0],\n ] as const) {\n g.strokeStyle = color\n g.fillStyle = color\n g.lineWidth = edit.width + extra\n if (edit.kind === 'rect') {\n const { x, y, width, height } = edit.rect\n g.strokeRect(x, y, width, height)\n } else if (edit.kind === 'path') {\n tracePath(g, edit.points)\n g.stroke()\n } else {\n const { lineEnd, head } = arrowShape(edit.from, edit.to, edit.width)\n g.beginPath()\n g.moveTo(edit.from.x, edit.from.y)\n g.lineTo(lineEnd.x, lineEnd.y)\n g.stroke()\n g.beginPath()\n g.moveTo(head[0].x, head[0].y)\n g.lineTo(head[1].x, head[1].y)\n g.lineTo(head[2].x, head[2].y)\n g.closePath()\n g.fill()\n if (extra) {\n g.lineWidth = extra\n g.stroke()\n }\n }\n }\n g.restore()\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\n/**\n * A stroke through `points`, smoothed: each curve goes through the middle\n * of two points, with the point between them as its control, so a hand\n * drawn line has no corners where the pointer was sampled.\n */\nfunction tracePath(g: CanvasRenderingContext2D, points: ImagePoint[]): void {\n const [first, ...rest] = points\n const last = rest[rest.length - 1]\n g.beginPath()\n if (!first) {\n return\n }\n g.moveTo(first.x, first.y)\n for (let i = 0; i < rest.length - 1; i++) {\n const point = rest[i]\n const next = rest[i + 1]\n g.quadraticCurveTo(\n point.x,\n point.y,\n (point.x + next.x) / 2,\n (point.y + next.y) / 2,\n )\n }\n // A single point is a dot: a line to itself, drawn with its round ends\n const end = last ?? first\n g.lineTo(end.x, end.y)\n}\n\n/** `point`, moved inside an image of `size` when it is past an edge. */\nexport function pointIn(point: ImagePoint, size: ImageSize): ImagePoint {\n return {\n x: clamp(point.x, 0, size.width),\n y: clamp(point.y, 0, size.height),\n }\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 nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\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 ANNOTATION_COLORS,\n ANNOTATION_FONT,\n dragRect,\n drawAnnotation,\n pointIn,\n releaseCanvas,\n renderEdits,\n sizeAfterEdits,\n strokeWidth,\n TEXT_LINE_HEIGHT,\n textSize,\n type AnnotationColor,\n type AnnotationEdit,\n type CoverStyle,\n type EditorTool,\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 and F2): crop and cover by dragging on the\n * image, quarter turns, arrows, rectangles, freehand strokes and texts in\n * a few colors, undo and redo. The edits are the model, the image stays\n * as it was loaded. Drawing 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 /** The tool picked on opening: crop, unless the host says otherwise. */\n initialTool?: EditorTool\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 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<EditorTool>(props.initialTool ?? '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 const color = ref<AnnotationColor>('red')\n\n const toolOptions = computed<\n { value: EditorTool; label: string; icon: string }[]\n >(() => [\n { value: 'crop', label: $t('imageEditor.crop'), icon: 'ri:crop-line' },\n {\n value: 'cover',\n label: $t('imageEditor.cover'),\n icon: 'ri:eye-off-line',\n },\n {\n value: 'arrow',\n label: $t('imageEditor.arrow'),\n icon: 'ri:arrow-right-up-line',\n },\n {\n value: 'rect',\n label: $t('imageEditor.rect'),\n icon: 'ri:checkbox-blank-line',\n },\n {\n value: 'path',\n label: $t('imageEditor.path'),\n icon: 'ri:pencil-line',\n },\n { value: 'text', label: $t('imageEditor.text'), icon: 'ri:text' },\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 colorOptions = computed<{ value: AnnotationColor; label: string }[]>(\n () => [\n { value: 'red', label: $t('imageEditor.colorRed') },\n { value: 'yellow', label: $t('imageEditor.colorYellow') },\n { value: 'green', label: $t('imageEditor.colorGreen') },\n { value: 'blue', label: $t('imageEditor.colorBlue') },\n { value: 'white', label: $t('imageEditor.colorWhite') },\n { value: 'black', label: $t('imageEditor.colorBlack') },\n ],\n )\n const annotationHint = computed(() => {\n switch (tool.value) {\n case 'arrow':\n return $t('imageEditor.arrowHint')\n case 'rect':\n return $t('imageEditor.rectHint')\n case 'path':\n return $t('imageEditor.pathHint')\n default:\n return $t('imageEditor.textHint')\n }\n })\n const aspectLabelId = useId()\n const colorLabelId = 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 if (draftEl.value) {\n releaseCanvas(draftEl.value)\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 // --- Pointer gestures ---\n\n /** A mark shorter than this on screen is a click, not a drag. */\n const MIN_DRAG = 6\n /** A stroke takes a new point once the pointer moved this far on screen. */\n const MIN_STEP = 2\n\n const frameEl = useTemplateRef<HTMLDivElement>('frameEl')\n const selection = ref<ImageRect>()\n const dragFrom = ref<ImagePoint>()\n // The annotation being drawn, over the image until it is let go\n const draft = shallowRef<AnnotationEdit>()\n // The pointer of the gesture: a second finger on the screen is ignored,\n // not a new start that the moves of both would share\n let dragPointer: number | undefined\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 // A drag goes on past the edge of the image: the mark stops at it\n return pointIn(\n {\n x: ((event.clientX - box.left) / box.width) * size.value.width,\n y: ((event.clientY - box.top) / box.height) * size.value.height,\n },\n size.value,\n )\n }\n\n function onPointerDown(event: PointerEvent) {\n if (event.button !== 0 || dragPointer !== undefined) {\n return\n }\n dragPointer = event.pointerId\n frameEl.value?.setPointerCapture(event.pointerId)\n const point = pointOf(event)\n dragFrom.value = point\n selection.value = undefined\n if (tool.value === 'path') {\n draft.value = {\n kind: 'path',\n points: [point],\n color: color.value,\n width: strokeWidth(size.value),\n }\n }\n }\n\n function onPointerMove(event: PointerEvent) {\n const from = dragFrom.value\n if (!from || event.pointerId !== dragPointer) {\n return\n }\n const to = pointOf(event)\n const width = strokeWidth(size.value)\n switch (tool.value) {\n case 'crop':\n case 'cover':\n selection.value = dragRect(\n from,\n to,\n size.value,\n tool.value === 'crop' ? ASPECTS[aspect.value] : undefined,\n )\n break\n case 'rect':\n draft.value = {\n kind: 'rect',\n rect: dragRect(from, to, size.value),\n color: color.value,\n width,\n }\n break\n case 'arrow':\n draft.value = {\n kind: 'arrow',\n from,\n to,\n color: color.value,\n width,\n }\n break\n case 'path': {\n const stroke = draft.value\n const last =\n stroke?.kind === 'path'\n ? stroke.points[stroke.points.length - 1]\n : undefined\n if (\n stroke?.kind === 'path' &&\n last &&\n distance(last, to) * scale.value >= MIN_STEP\n ) {\n draft.value = { ...stroke, points: [...stroke.points, to] }\n }\n break\n }\n }\n }\n\n function onPointerUp(event: PointerEvent) {\n const from = dragFrom.value\n if (!from || event.pointerId !== dragPointer) {\n return\n }\n dragPointer = undefined\n dragFrom.value = undefined\n if (tool.value === 'crop' || tool.value === 'cover') {\n const rect = selection.value\n if (!rect || !visible(rect.width) || !visible(rect.height)) {\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 return\n }\n if (tool.value === 'text') {\n void openText(from)\n return\n }\n const mark = draft.value\n draft.value = undefined\n if (mark && drawn(mark)) {\n push(mark)\n }\n }\n\n function onPointerCancel(event: PointerEvent) {\n if (event.pointerId !== dragPointer) {\n return\n }\n dragPointer = undefined\n dragFrom.value = undefined\n selection.value = undefined\n draft.value = undefined\n }\n\n /** A length in the image's pixels shows on screen as a drag. */\n function visible(length: number): boolean {\n return length * scale.value >= MIN_DRAG\n }\n\n /** A mark let go is one, not a click that slipped. */\n function drawn(mark: AnnotationEdit): boolean {\n switch (mark.kind) {\n case 'arrow':\n return visible(distance(mark.from, mark.to))\n case 'rect':\n return visible(mark.rect.width) && visible(mark.rect.height)\n case 'path':\n return mark.points.length > 1\n default:\n return true\n }\n }\n\n // The mark being drawn, on a canvas of the frame's size over the image:\n // drawn by the same code as the file, so what shows is what goes. Out of\n // a drag it has no pixels, which Safari would count.\n const draftEl = useTemplateRef<HTMLCanvasElement>('draftEl')\n\n function drawDraft() {\n const canvas = draftEl.value\n const frame = frameEl.value\n if (!canvas || !frame) {\n return\n }\n const mark = draft.value\n if (!mark) {\n releaseCanvas(canvas)\n return\n }\n const ratio = window.devicePixelRatio || 1\n canvas.width = Math.round(frame.clientWidth * ratio)\n canvas.height = Math.round(frame.clientHeight * ratio)\n const g = canvas.getContext('2d')\n if (!g) {\n return\n }\n const k = canvas.width / size.value.width\n g.setTransform(k, 0, 0, k, 0, 0)\n drawAnnotation(g, mark)\n }\n\n watch(draft, drawDraft, { flush: 'post' })\n\n // --- Cropping ---\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 // 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 // --- Text ---\n\n // A text being typed, where it starts: it joins the edits on Enter or\n // when the field loses the focus, and goes away on Esc or empty. Its\n // lines wrap in the room up to the right edge, in the field as in the\n // file, where a single line was cut at the edge\n const textDraft = ref<{ at: ImagePoint; text: string }>()\n const textEl = useTemplateRef<HTMLTextAreaElement>('textEl')\n const TEXT_MAX_LENGTH = 200\n\n async function openText(at: ImagePoint) {\n commitText()\n textDraft.value = { at, text: '' }\n await nextTick()\n fitText()\n textEl.value?.focus()\n }\n\n function commitText() {\n const typed = textDraft.value\n textDraft.value = undefined\n const text = typed?.text.trim()\n if (typed && text) {\n push({\n kind: 'text',\n at: typed.at,\n text,\n color: color.value,\n size: textSize(size.value),\n maxWidth: size.value.width - typed.at.x,\n })\n }\n }\n\n /**\n * An input method is composing a word: Enter and Esc are its own, to\n * confirm or drop the word. Safari reports it with `isComposing`\n * already false, hence the 229.\n */\n const composing = (event: KeyboardEvent) =>\n event.isComposing || event.keyCode === 229\n\n function onTextEnter(event: KeyboardEvent) {\n if (!composing(event)) {\n event.preventDefault()\n commitText()\n }\n }\n\n function onTextEscape(event: KeyboardEvent) {\n if (!composing(event)) {\n event.preventDefault()\n textDraft.value = undefined\n }\n }\n\n // The field grows with its lines\n function fitText() {\n const field = textEl.value\n if (field) {\n field.style.height = 'auto'\n field.style.height = `${field.scrollHeight}px`\n }\n }\n\n const pendingText = computed(() => !!textDraft.value?.text.trim())\n\n // The field shows the text as it will be drawn: the color, the font and\n // its size on screen, a shadow standing for the edge\n const textStyle = computed(() => {\n const typed = textDraft.value\n if (!typed) {\n return undefined\n }\n const { fill, edge } = ANNOTATION_COLORS[color.value]\n return {\n left: `${(typed.at.x / size.value.width) * 100}%`,\n top: `${(typed.at.y / size.value.height) * 100}%`,\n fontFamily: ANNOTATION_FONT,\n fontSize: `${textSize(size.value) * scale.value}px`,\n lineHeight: String(TEXT_LINE_HEIGHT),\n color: fill,\n '--pk-image-editor-text-edge': edge,\n }\n })\n\n // A tool picked keeps nothing of the one before: a crop drawn, a mark\n // half drawn; a text typed joins the edits\n watch(tool, () => {\n selection.value = undefined\n draft.value = undefined\n commitText()\n })\n\n defineExpose({\n /** Something is drawn and not added yet: a crop, a text being typed. */\n pending: computed(() => pendingCrop.value || pendingText.value),\n /** Adds it, as Apply and Enter do: \"Use the image\" calls it first. */\n applyPending: () => {\n applyCrop()\n commitText()\n },\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\n function distance(a: ImagePoint, b: ImagePoint): number {\n return Math.hypot(b.x - a.x, b.y - a.y)\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\n v-for=\"option in toolOptions\"\n :key=\"option.value\"\n #[option.value]>\n <span class=\"pk-image-editor__tool\" :title=\"option.label\">\n <VvIcon :name=\"option.icon\" class=\"w-16 h-16\" />\n <span class=\"pk-image-editor__tool-label\">\n {{ option.label }}\n </span>\n </span>\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-if=\"tool === 'cover'\">\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 <template v-else>\n <span :id=\"colorLabelId\" class=\"pk-image-editor__label\">\n {{ $t('imageEditor.color') }}\n </span>\n <PkEditorRadioButtons\n v-model=\"color\"\n name=\"pk-image-editor-color\"\n segmented\n class=\"mb-0\"\n :aria-labelledby=\"colorLabelId\"\n :options=\"colorOptions\">\n <template\n v-for=\"option in colorOptions\"\n :key=\"option.value\"\n #[option.value]>\n <span\n class=\"pk-image-editor__color\"\n :title=\"option.label\">\n <span\n class=\"pk-image-editor__swatch\"\n :style=\"{\n backgroundColor:\n ANNOTATION_COLORS[option.value].fill,\n }\" />\n <span class=\"u-visually-hidden\">\n {{ option.label }}\n </span>\n </span>\n </template>\n </PkEditorRadioButtons>\n <span class=\"pk-image-editor__hint\">\n {{ annotationHint }}\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 :class=\"{ 'pk-image-editor__frame--text': tool === 'text' }\"\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 <canvas\n ref=\"draftEl\"\n class=\"pk-image-editor__draft\"\n width=\"0\"\n height=\"0\"\n aria-hidden=\"true\" />\n <div\n v-if=\"selection\"\n class=\"pk-image-editor__selection\"\n :class=\"`pk-image-editor__selection--${tool}`\"\n :style=\"selectionStyle\" />\n <textarea\n v-if=\"textDraft\"\n ref=\"textEl\"\n v-model=\"textDraft.text\"\n class=\"pk-image-editor__text\"\n rows=\"1\"\n :maxlength=\"TEXT_MAX_LENGTH\"\n :aria-label=\"$t('imageEditor.textLabel')\"\n :style=\"textStyle\"\n @pointerdown.stop\n @input=\"fitText\"\n @keydown.enter=\"onTextEnter\"\n @keydown.esc=\"onTextEscape\"\n @blur=\"commitText\" />\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 // The tool names hide when the dialog is too narrow for them: the\n // icons stay, named by their title and for a screen reader\n container: pk-image-editor / inline-size;\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 &__tool {\n display: inline-flex;\n align-items: center;\n gap: var(--spacing-4);\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 // Positioned, for the name a screen reader reads in it\n &__color {\n position: relative;\n display: inline-flex;\n }\n\n // A dot of the color, with a hairline that keeps the white one on a\n // light surface and the black one on a dark surface\n &__swatch {\n display: block;\n width: var(--spacing-16);\n height: var(--spacing-16);\n border-radius: 50%;\n box-shadow: inset 0 0 0 1px\n color-mix(in srgb, var(--color-word) 40%, transparent);\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 &--text {\n cursor: text;\n }\n }\n\n &__stage,\n &__stage > canvas {\n display: block;\n width: 100%;\n height: 100%;\n }\n\n &__draft {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\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 // The text being typed, where it will be drawn: from the point\n // clicked to the right edge of the image\n &__text {\n position: absolute;\n right: 0;\n display: block;\n margin: 0;\n padding: 0;\n overflow: hidden;\n border: 0;\n outline: 1px dashed\n color-mix(in srgb, var(--color-white) 80%, transparent);\n background: transparent;\n font-weight: 700;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n resize: none;\n caret-color: currentcolor;\n user-select: text;\n text-shadow:\n 0 0 1px var(--pk-image-editor-text-edge),\n 0 0 2px var(--pk-image-editor-text-edge),\n 0 0 3px var(--pk-image-editor-text-edge);\n }\n }\n\n // A finger gets 40px (DESIGN.md): a segment is drawn 32px tall, and its\n // area grows around it, as `u-touch-target` does\n @media (pointer: coarse) {\n .pk-image-editor .vv-radio--segment::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n width: max(100%, var(--spacing-40));\n height: max(100%, var(--spacing-40));\n transform: translate(-50%, -50%);\n }\n }\n\n // Same as `u-visually-hidden`, which a class cannot get from the width\n // of a container. Under 50rem the named tools pushed undo and redo to a\n // row of their own (760px, 2026-11-04)\n @container pk-image-editor (max-width: 50rem) {\n .pk-image-editor__tool-label {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\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 ANNOTATION_COLORS,\n ANNOTATION_FONT,\n dragRect,\n drawAnnotation,\n pointIn,\n releaseCanvas,\n renderEdits,\n sizeAfterEdits,\n strokeWidth,\n TEXT_LINE_HEIGHT,\n textSize,\n type AnnotationColor,\n type AnnotationEdit,\n type CoverStyle,\n type EditorTool,\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 and F2): crop and cover by dragging on the\n * image, quarter turns, arrows, rectangles, freehand strokes and texts in\n * a few colors, undo and redo. The edits are the model, the image stays\n * as it was loaded. Drawing 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 /** The tool picked on opening: crop, unless the host says otherwise. */\n initialTool?: EditorTool\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 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<EditorTool>(props.initialTool ?? '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 const color = ref<AnnotationColor>('red')\n\n const toolOptions = computed<\n { value: EditorTool; label: string; icon: string }[]\n >(() => [\n { value: 'crop', label: $t('imageEditor.crop'), icon: 'ri:crop-line' },\n {\n value: 'cover',\n label: $t('imageEditor.cover'),\n icon: 'ri:eye-off-line',\n },\n {\n value: 'arrow',\n label: $t('imageEditor.arrow'),\n icon: 'ri:arrow-right-up-line',\n },\n {\n value: 'rect',\n label: $t('imageEditor.rect'),\n icon: 'ri:checkbox-blank-line',\n },\n {\n value: 'path',\n label: $t('imageEditor.path'),\n icon: 'ri:pencil-line',\n },\n { value: 'text', label: $t('imageEditor.text'), icon: 'ri:text' },\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 colorOptions = computed<{ value: AnnotationColor; label: string }[]>(\n () => [\n { value: 'red', label: $t('imageEditor.colorRed') },\n { value: 'yellow', label: $t('imageEditor.colorYellow') },\n { value: 'green', label: $t('imageEditor.colorGreen') },\n { value: 'blue', label: $t('imageEditor.colorBlue') },\n { value: 'white', label: $t('imageEditor.colorWhite') },\n { value: 'black', label: $t('imageEditor.colorBlack') },\n ],\n )\n const annotationHint = computed(() => {\n switch (tool.value) {\n case 'arrow':\n return $t('imageEditor.arrowHint')\n case 'rect':\n return $t('imageEditor.rectHint')\n case 'path':\n return $t('imageEditor.pathHint')\n default:\n return $t('imageEditor.textHint')\n }\n })\n const aspectLabelId = useId()\n const colorLabelId = 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 if (draftEl.value) {\n releaseCanvas(draftEl.value)\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 // --- Pointer gestures ---\n\n /** A mark shorter than this on screen is a click, not a drag. */\n const MIN_DRAG = 6\n /** A stroke takes a new point once the pointer moved this far on screen. */\n const MIN_STEP = 2\n\n const frameEl = useTemplateRef<HTMLDivElement>('frameEl')\n const selection = ref<ImageRect>()\n const dragFrom = ref<ImagePoint>()\n // The annotation being drawn, over the image until it is let go\n const draft = shallowRef<AnnotationEdit>()\n // The pointer of the gesture: a second finger on the screen is ignored,\n // not a new start that the moves of both would share\n let dragPointer: number | undefined\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 // A drag goes on past the edge of the image: the mark stops at it\n return pointIn(\n {\n x: ((event.clientX - box.left) / box.width) * size.value.width,\n y: ((event.clientY - box.top) / box.height) * size.value.height,\n },\n size.value,\n )\n }\n\n function onPointerDown(event: PointerEvent) {\n if (event.button !== 0 || dragPointer !== undefined) {\n return\n }\n dragPointer = event.pointerId\n frameEl.value?.setPointerCapture(event.pointerId)\n const point = pointOf(event)\n dragFrom.value = point\n selection.value = undefined\n if (tool.value === 'path') {\n draft.value = {\n kind: 'path',\n points: [point],\n color: color.value,\n width: strokeWidth(size.value),\n }\n }\n }\n\n function onPointerMove(event: PointerEvent) {\n const from = dragFrom.value\n if (!from || event.pointerId !== dragPointer) {\n return\n }\n const to = pointOf(event)\n const width = strokeWidth(size.value)\n switch (tool.value) {\n case 'crop':\n case 'cover':\n selection.value = dragRect(\n from,\n to,\n size.value,\n tool.value === 'crop' ? ASPECTS[aspect.value] : undefined,\n )\n break\n case 'rect':\n draft.value = {\n kind: 'rect',\n rect: dragRect(from, to, size.value),\n color: color.value,\n width,\n }\n break\n case 'arrow':\n draft.value = {\n kind: 'arrow',\n from,\n to,\n color: color.value,\n width,\n }\n break\n case 'path': {\n const stroke = draft.value\n const last =\n stroke?.kind === 'path'\n ? stroke.points[stroke.points.length - 1]\n : undefined\n if (\n stroke?.kind === 'path' &&\n last &&\n distance(last, to) * scale.value >= MIN_STEP\n ) {\n draft.value = { ...stroke, points: [...stroke.points, to] }\n }\n break\n }\n }\n }\n\n function onPointerUp(event: PointerEvent) {\n const from = dragFrom.value\n if (!from || event.pointerId !== dragPointer) {\n return\n }\n dragPointer = undefined\n dragFrom.value = undefined\n if (tool.value === 'crop' || tool.value === 'cover') {\n const rect = selection.value\n if (!rect || !visible(rect.width) || !visible(rect.height)) {\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 return\n }\n if (tool.value === 'text') {\n void openText(from)\n return\n }\n const mark = draft.value\n draft.value = undefined\n if (mark && drawn(mark)) {\n push(mark)\n }\n }\n\n function onPointerCancel(event: PointerEvent) {\n if (event.pointerId !== dragPointer) {\n return\n }\n dragPointer = undefined\n dragFrom.value = undefined\n selection.value = undefined\n draft.value = undefined\n }\n\n /** A length in the image's pixels shows on screen as a drag. */\n function visible(length: number): boolean {\n return length * scale.value >= MIN_DRAG\n }\n\n /** A mark let go is one, not a click that slipped. */\n function drawn(mark: AnnotationEdit): boolean {\n switch (mark.kind) {\n case 'arrow':\n return visible(distance(mark.from, mark.to))\n case 'rect':\n return visible(mark.rect.width) && visible(mark.rect.height)\n case 'path':\n return mark.points.length > 1\n default:\n return true\n }\n }\n\n // The mark being drawn, on a canvas of the frame's size over the image:\n // drawn by the same code as the file, so what shows is what goes. Out of\n // a drag it has no pixels, which Safari would count.\n const draftEl = useTemplateRef<HTMLCanvasElement>('draftEl')\n\n function drawDraft() {\n const canvas = draftEl.value\n const frame = frameEl.value\n if (!canvas || !frame) {\n return\n }\n const mark = draft.value\n if (!mark) {\n releaseCanvas(canvas)\n return\n }\n const ratio = window.devicePixelRatio || 1\n canvas.width = Math.round(frame.clientWidth * ratio)\n canvas.height = Math.round(frame.clientHeight * ratio)\n const g = canvas.getContext('2d')\n if (!g) {\n return\n }\n const k = canvas.width / size.value.width\n g.setTransform(k, 0, 0, k, 0, 0)\n drawAnnotation(g, mark)\n }\n\n watch(draft, drawDraft, { flush: 'post' })\n\n // --- Cropping ---\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 // 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 // --- Text ---\n\n // A text being typed, where it starts: it joins the edits on Enter or\n // when the field loses the focus, and goes away on Esc or empty. Its\n // lines wrap in the room up to the right edge, in the field as in the\n // file, where a single line was cut at the edge\n const textDraft = ref<{ at: ImagePoint; text: string }>()\n const textEl = useTemplateRef<HTMLTextAreaElement>('textEl')\n const TEXT_MAX_LENGTH = 200\n\n async function openText(at: ImagePoint) {\n commitText()\n textDraft.value = { at, text: '' }\n await nextTick()\n fitText()\n textEl.value?.focus()\n }\n\n function commitText() {\n const typed = textDraft.value\n textDraft.value = undefined\n const text = typed?.text.trim()\n if (typed && text) {\n push({\n kind: 'text',\n at: typed.at,\n text,\n color: color.value,\n size: textSize(size.value),\n maxWidth: size.value.width - typed.at.x,\n })\n }\n }\n\n /**\n * An input method is composing a word: Enter and Esc are its own, to\n * confirm or drop the word. Safari reports it with `isComposing`\n * already false, hence the 229.\n */\n const composing = (event: KeyboardEvent) =>\n event.isComposing || event.keyCode === 229\n\n function onTextEnter(event: KeyboardEvent) {\n if (!composing(event)) {\n event.preventDefault()\n commitText()\n }\n }\n\n function onTextEscape(event: KeyboardEvent) {\n if (!composing(event)) {\n event.preventDefault()\n textDraft.value = undefined\n }\n }\n\n // The field grows with its lines\n function fitText() {\n const field = textEl.value\n if (field) {\n field.style.height = 'auto'\n field.style.height = `${field.scrollHeight}px`\n }\n }\n\n const pendingText = computed(() => !!textDraft.value?.text.trim())\n\n // The field shows the text as it will be drawn: the color, the font and\n // its size on screen, a shadow standing for the edge\n const textStyle = computed(() => {\n const typed = textDraft.value\n if (!typed) {\n return undefined\n }\n const { fill, edge } = ANNOTATION_COLORS[color.value]\n return {\n left: `${(typed.at.x / size.value.width) * 100}%`,\n top: `${(typed.at.y / size.value.height) * 100}%`,\n fontFamily: ANNOTATION_FONT,\n fontSize: `${textSize(size.value) * scale.value}px`,\n lineHeight: String(TEXT_LINE_HEIGHT),\n color: fill,\n '--pk-image-editor-text-edge': edge,\n }\n })\n\n // A tool picked keeps nothing of the one before: a crop drawn, a mark\n // half drawn; a text typed joins the edits\n watch(tool, () => {\n selection.value = undefined\n draft.value = undefined\n commitText()\n })\n\n defineExpose({\n /** Something is drawn and not added yet: a crop, a text being typed. */\n pending: computed(() => pendingCrop.value || pendingText.value),\n /** Adds it, as Apply and Enter do: \"Use the image\" calls it first. */\n applyPending: () => {\n applyCrop()\n commitText()\n },\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\n function distance(a: ImagePoint, b: ImagePoint): number {\n return Math.hypot(b.x - a.x, b.y - a.y)\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\n v-for=\"option in toolOptions\"\n :key=\"option.value\"\n #[option.value]>\n <span class=\"pk-image-editor__tool\" :title=\"option.label\">\n <VvIcon :name=\"option.icon\" class=\"w-16 h-16\" />\n <span class=\"pk-image-editor__tool-label\">\n {{ option.label }}\n </span>\n </span>\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-if=\"tool === 'cover'\">\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 <template v-else>\n <span :id=\"colorLabelId\" class=\"pk-image-editor__label\">\n {{ $t('imageEditor.color') }}\n </span>\n <PkEditorRadioButtons\n v-model=\"color\"\n name=\"pk-image-editor-color\"\n segmented\n class=\"mb-0\"\n :aria-labelledby=\"colorLabelId\"\n :options=\"colorOptions\">\n <template\n v-for=\"option in colorOptions\"\n :key=\"option.value\"\n #[option.value]>\n <span\n class=\"pk-image-editor__color\"\n :title=\"option.label\">\n <span\n class=\"pk-image-editor__swatch\"\n :style=\"{\n backgroundColor:\n ANNOTATION_COLORS[option.value].fill,\n }\" />\n <span class=\"u-visually-hidden\">\n {{ option.label }}\n </span>\n </span>\n </template>\n </PkEditorRadioButtons>\n <span class=\"pk-image-editor__hint\">\n {{ annotationHint }}\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 :class=\"{ 'pk-image-editor__frame--text': tool === 'text' }\"\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 <canvas\n ref=\"draftEl\"\n class=\"pk-image-editor__draft\"\n width=\"0\"\n height=\"0\"\n aria-hidden=\"true\" />\n <div\n v-if=\"selection\"\n class=\"pk-image-editor__selection\"\n :class=\"`pk-image-editor__selection--${tool}`\"\n :style=\"selectionStyle\" />\n <textarea\n v-if=\"textDraft\"\n ref=\"textEl\"\n v-model=\"textDraft.text\"\n class=\"pk-image-editor__text\"\n rows=\"1\"\n :maxlength=\"TEXT_MAX_LENGTH\"\n :aria-label=\"$t('imageEditor.textLabel')\"\n :style=\"textStyle\"\n @pointerdown.stop\n @input=\"fitText\"\n @keydown.enter=\"onTextEnter\"\n @keydown.esc=\"onTextEscape\"\n @blur=\"commitText\" />\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 // The tool names hide when the dialog is too narrow for them: the\n // icons stay, named by their title and for a screen reader\n container: pk-image-editor / inline-size;\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 &__tool {\n display: inline-flex;\n align-items: center;\n gap: var(--spacing-4);\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 // Positioned, for the name a screen reader reads in it\n &__color {\n position: relative;\n display: inline-flex;\n }\n\n // A dot of the color, with a hairline that keeps the white one on a\n // light surface and the black one on a dark surface\n &__swatch {\n display: block;\n width: var(--spacing-16);\n height: var(--spacing-16);\n border-radius: 50%;\n box-shadow: inset 0 0 0 1px\n color-mix(in srgb, var(--color-word) 40%, transparent);\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 &--text {\n cursor: text;\n }\n }\n\n &__stage,\n &__stage > canvas {\n display: block;\n width: 100%;\n height: 100%;\n }\n\n &__draft {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\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 // The text being typed, where it will be drawn: from the point\n // clicked to the right edge of the image\n &__text {\n position: absolute;\n right: 0;\n display: block;\n margin: 0;\n padding: 0;\n overflow: hidden;\n border: 0;\n outline: 1px dashed\n color-mix(in srgb, var(--color-white) 80%, transparent);\n background: transparent;\n font-weight: 700;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n resize: none;\n caret-color: currentcolor;\n user-select: text;\n text-shadow:\n 0 0 1px var(--pk-image-editor-text-edge),\n 0 0 2px var(--pk-image-editor-text-edge),\n 0 0 3px var(--pk-image-editor-text-edge);\n }\n }\n\n // A finger gets 40px (DESIGN.md): a segment is drawn 32px tall, and its\n // area grows around it, as `u-touch-target` does\n @media (pointer: coarse) {\n .pk-image-editor .vv-radio--segment::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n width: max(100%, var(--spacing-40));\n height: max(100%, var(--spacing-40));\n transform: translate(-50%, -50%);\n }\n }\n\n // Same as `u-visually-hidden`, which a class cannot get from the width\n // of a container. Under 50rem the named tools pushed undo and redo to a\n // row of their own (760px, 2026-11-04)\n @container pk-image-editor (max-width: 50rem) {\n .pk-image-editor__tool-label {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\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 ANNOTATION_COLORS,\n ANNOTATION_FONT,\n dragRect,\n drawAnnotation,\n pointIn,\n releaseCanvas,\n renderEdits,\n sizeAfterEdits,\n strokeWidth,\n TEXT_LINE_HEIGHT,\n textSize,\n type AnnotationColor,\n type AnnotationEdit,\n type CoverStyle,\n type EditorTool,\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 and F2): crop and cover by dragging on the\n * image, quarter turns, arrows, rectangles, freehand strokes and texts in\n * a few colors, undo and redo. The edits are the model, the image stays\n * as it was loaded. Drawing 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 /** The tool picked on opening: crop, unless the host says otherwise. */\n initialTool?: EditorTool\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 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<EditorTool>(props.initialTool ?? '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 const color = ref<AnnotationColor>('red')\n\n const toolOptions = computed<\n { value: EditorTool; label: string; icon: string }[]\n >(() => [\n { value: 'crop', label: $t('imageEditor.crop'), icon: 'ri:crop-line' },\n {\n value: 'cover',\n label: $t('imageEditor.cover'),\n icon: 'ri:eye-off-line',\n },\n {\n value: 'arrow',\n label: $t('imageEditor.arrow'),\n icon: 'ri:arrow-right-up-line',\n },\n {\n value: 'rect',\n label: $t('imageEditor.rect'),\n icon: 'ri:checkbox-blank-line',\n },\n {\n value: 'path',\n label: $t('imageEditor.path'),\n icon: 'ri:pencil-line',\n },\n { value: 'text', label: $t('imageEditor.text'), icon: 'ri:text' },\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 colorOptions = computed<{ value: AnnotationColor; label: string }[]>(\n () => [\n { value: 'red', label: $t('imageEditor.colorRed') },\n { value: 'yellow', label: $t('imageEditor.colorYellow') },\n { value: 'green', label: $t('imageEditor.colorGreen') },\n { value: 'blue', label: $t('imageEditor.colorBlue') },\n { value: 'white', label: $t('imageEditor.colorWhite') },\n { value: 'black', label: $t('imageEditor.colorBlack') },\n ],\n )\n const annotationHint = computed(() => {\n switch (tool.value) {\n case 'arrow':\n return $t('imageEditor.arrowHint')\n case 'rect':\n return $t('imageEditor.rectHint')\n case 'path':\n return $t('imageEditor.pathHint')\n default:\n return $t('imageEditor.textHint')\n }\n })\n const aspectLabelId = useId()\n const colorLabelId = 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 if (draftEl.value) {\n releaseCanvas(draftEl.value)\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 // --- Pointer gestures ---\n\n /** A mark shorter than this on screen is a click, not a drag. */\n const MIN_DRAG = 6\n /** A stroke takes a new point once the pointer moved this far on screen. */\n const MIN_STEP = 2\n\n const frameEl = useTemplateRef<HTMLDivElement>('frameEl')\n const selection = ref<ImageRect>()\n const dragFrom = ref<ImagePoint>()\n // The annotation being drawn, over the image until it is let go\n const draft = shallowRef<AnnotationEdit>()\n // The pointer of the gesture: a second finger on the screen is ignored,\n // not a new start that the moves of both would share\n let dragPointer: number | undefined\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 // A drag goes on past the edge of the image: the mark stops at it\n return pointIn(\n {\n x: ((event.clientX - box.left) / box.width) * size.value.width,\n y: ((event.clientY - box.top) / box.height) * size.value.height,\n },\n size.value,\n )\n }\n\n function onPointerDown(event: PointerEvent) {\n if (event.button !== 0 || dragPointer !== undefined) {\n return\n }\n dragPointer = event.pointerId\n frameEl.value?.setPointerCapture(event.pointerId)\n const point = pointOf(event)\n dragFrom.value = point\n selection.value = undefined\n if (tool.value === 'path') {\n draft.value = {\n kind: 'path',\n points: [point],\n color: color.value,\n width: strokeWidth(size.value),\n }\n }\n }\n\n function onPointerMove(event: PointerEvent) {\n const from = dragFrom.value\n if (!from || event.pointerId !== dragPointer) {\n return\n }\n const to = pointOf(event)\n const width = strokeWidth(size.value)\n switch (tool.value) {\n case 'crop':\n case 'cover':\n selection.value = dragRect(\n from,\n to,\n size.value,\n tool.value === 'crop' ? ASPECTS[aspect.value] : undefined,\n )\n break\n case 'rect':\n draft.value = {\n kind: 'rect',\n rect: dragRect(from, to, size.value),\n color: color.value,\n width,\n }\n break\n case 'arrow':\n draft.value = {\n kind: 'arrow',\n from,\n to,\n color: color.value,\n width,\n }\n break\n case 'path': {\n const stroke = draft.value\n const last =\n stroke?.kind === 'path'\n ? stroke.points[stroke.points.length - 1]\n : undefined\n if (\n stroke?.kind === 'path' &&\n last &&\n distance(last, to) * scale.value >= MIN_STEP\n ) {\n draft.value = { ...stroke, points: [...stroke.points, to] }\n }\n break\n }\n }\n }\n\n function onPointerUp(event: PointerEvent) {\n const from = dragFrom.value\n if (!from || event.pointerId !== dragPointer) {\n return\n }\n dragPointer = undefined\n dragFrom.value = undefined\n if (tool.value === 'crop' || tool.value === 'cover') {\n const rect = selection.value\n if (!rect || !visible(rect.width) || !visible(rect.height)) {\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 return\n }\n if (tool.value === 'text') {\n void openText(from)\n return\n }\n const mark = draft.value\n draft.value = undefined\n if (mark && drawn(mark)) {\n push(mark)\n }\n }\n\n function onPointerCancel(event: PointerEvent) {\n if (event.pointerId !== dragPointer) {\n return\n }\n dragPointer = undefined\n dragFrom.value = undefined\n selection.value = undefined\n draft.value = undefined\n }\n\n /** A length in the image's pixels shows on screen as a drag. */\n function visible(length: number): boolean {\n return length * scale.value >= MIN_DRAG\n }\n\n /** A mark let go is one, not a click that slipped. */\n function drawn(mark: AnnotationEdit): boolean {\n switch (mark.kind) {\n case 'arrow':\n return visible(distance(mark.from, mark.to))\n case 'rect':\n return visible(mark.rect.width) && visible(mark.rect.height)\n case 'path':\n return mark.points.length > 1\n default:\n return true\n }\n }\n\n // The mark being drawn, on a canvas of the frame's size over the image:\n // drawn by the same code as the file, so what shows is what goes. Out of\n // a drag it has no pixels, which Safari would count.\n const draftEl = useTemplateRef<HTMLCanvasElement>('draftEl')\n\n function drawDraft() {\n const canvas = draftEl.value\n const frame = frameEl.value\n if (!canvas || !frame) {\n return\n }\n const mark = draft.value\n if (!mark) {\n releaseCanvas(canvas)\n return\n }\n const ratio = window.devicePixelRatio || 1\n canvas.width = Math.round(frame.clientWidth * ratio)\n canvas.height = Math.round(frame.clientHeight * ratio)\n const g = canvas.getContext('2d')\n if (!g) {\n return\n }\n const k = canvas.width / size.value.width\n g.setTransform(k, 0, 0, k, 0, 0)\n drawAnnotation(g, mark)\n }\n\n watch(draft, drawDraft, { flush: 'post' })\n\n // --- Cropping ---\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 // 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 // --- Text ---\n\n // A text being typed, where it starts: it joins the edits on Enter or\n // when the field loses the focus, and goes away on Esc or empty. Its\n // lines wrap in the room up to the right edge, in the field as in the\n // file, where a single line was cut at the edge\n const textDraft = ref<{ at: ImagePoint; text: string }>()\n const textEl = useTemplateRef<HTMLTextAreaElement>('textEl')\n const TEXT_MAX_LENGTH = 200\n\n async function openText(at: ImagePoint) {\n commitText()\n textDraft.value = { at, text: '' }\n await nextTick()\n fitText()\n textEl.value?.focus()\n }\n\n function commitText() {\n const typed = textDraft.value\n textDraft.value = undefined\n const text = typed?.text.trim()\n if (typed && text) {\n push({\n kind: 'text',\n at: typed.at,\n text,\n color: color.value,\n size: textSize(size.value),\n maxWidth: size.value.width - typed.at.x,\n })\n }\n }\n\n /**\n * An input method is composing a word: Enter and Esc are its own, to\n * confirm or drop the word. Safari reports it with `isComposing`\n * already false, hence the 229.\n */\n const composing = (event: KeyboardEvent) =>\n event.isComposing || event.keyCode === 229\n\n function onTextEnter(event: KeyboardEvent) {\n if (!composing(event)) {\n event.preventDefault()\n commitText()\n }\n }\n\n function onTextEscape(event: KeyboardEvent) {\n if (!composing(event)) {\n event.preventDefault()\n textDraft.value = undefined\n }\n }\n\n // The field grows with its lines\n function fitText() {\n const field = textEl.value\n if (field) {\n field.style.height = 'auto'\n field.style.height = `${field.scrollHeight}px`\n }\n }\n\n const pendingText = computed(() => !!textDraft.value?.text.trim())\n\n // The field shows the text as it will be drawn: the color, the font and\n // its size on screen, a shadow standing for the edge\n const textStyle = computed(() => {\n const typed = textDraft.value\n if (!typed) {\n return undefined\n }\n const { fill, edge } = ANNOTATION_COLORS[color.value]\n return {\n left: `${(typed.at.x / size.value.width) * 100}%`,\n top: `${(typed.at.y / size.value.height) * 100}%`,\n fontFamily: ANNOTATION_FONT,\n fontSize: `${textSize(size.value) * scale.value}px`,\n lineHeight: String(TEXT_LINE_HEIGHT),\n color: fill,\n '--pk-image-editor-text-edge': edge,\n }\n })\n\n // A tool picked keeps nothing of the one before: a crop drawn, a mark\n // half drawn; a text typed joins the edits\n watch(tool, () => {\n selection.value = undefined\n draft.value = undefined\n commitText()\n })\n\n defineExpose({\n /** Something is drawn and not added yet: a crop, a text being typed. */\n pending: computed(() => pendingCrop.value || pendingText.value),\n /** Adds it, as Apply and Enter do: \"Use the image\" calls it first. */\n applyPending: () => {\n applyCrop()\n commitText()\n },\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\n function distance(a: ImagePoint, b: ImagePoint): number {\n return Math.hypot(b.x - a.x, b.y - a.y)\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\n v-for=\"option in toolOptions\"\n :key=\"option.value\"\n #[option.value]>\n <span class=\"pk-image-editor__tool\" :title=\"option.label\">\n <VvIcon :name=\"option.icon\" class=\"w-16 h-16\" />\n <span class=\"pk-image-editor__tool-label\">\n {{ option.label }}\n </span>\n </span>\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-if=\"tool === 'cover'\">\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 <template v-else>\n <span :id=\"colorLabelId\" class=\"pk-image-editor__label\">\n {{ $t('imageEditor.color') }}\n </span>\n <PkEditorRadioButtons\n v-model=\"color\"\n name=\"pk-image-editor-color\"\n segmented\n class=\"mb-0\"\n :aria-labelledby=\"colorLabelId\"\n :options=\"colorOptions\">\n <template\n v-for=\"option in colorOptions\"\n :key=\"option.value\"\n #[option.value]>\n <span\n class=\"pk-image-editor__color\"\n :title=\"option.label\">\n <span\n class=\"pk-image-editor__swatch\"\n :style=\"{\n backgroundColor:\n ANNOTATION_COLORS[option.value].fill,\n }\" />\n <span class=\"u-visually-hidden\">\n {{ option.label }}\n </span>\n </span>\n </template>\n </PkEditorRadioButtons>\n <span class=\"pk-image-editor__hint\">\n {{ annotationHint }}\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 :class=\"{ 'pk-image-editor__frame--text': tool === 'text' }\"\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 <canvas\n ref=\"draftEl\"\n class=\"pk-image-editor__draft\"\n width=\"0\"\n height=\"0\"\n aria-hidden=\"true\" />\n <div\n v-if=\"selection\"\n class=\"pk-image-editor__selection\"\n :class=\"`pk-image-editor__selection--${tool}`\"\n :style=\"selectionStyle\" />\n <textarea\n v-if=\"textDraft\"\n ref=\"textEl\"\n v-model=\"textDraft.text\"\n class=\"pk-image-editor__text\"\n rows=\"1\"\n :maxlength=\"TEXT_MAX_LENGTH\"\n :aria-label=\"$t('imageEditor.textLabel')\"\n :style=\"textStyle\"\n @pointerdown.stop\n @input=\"fitText\"\n @keydown.enter=\"onTextEnter\"\n @keydown.esc=\"onTextEscape\"\n @blur=\"commitText\" />\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 // The tool names hide when the dialog is too narrow for them: the\n // icons stay, named by their title and for a screen reader\n container: pk-image-editor / inline-size;\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 &__tool {\n display: inline-flex;\n align-items: center;\n gap: var(--spacing-4);\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 // Positioned, for the name a screen reader reads in it\n &__color {\n position: relative;\n display: inline-flex;\n }\n\n // A dot of the color, with a hairline that keeps the white one on a\n // light surface and the black one on a dark surface\n &__swatch {\n display: block;\n width: var(--spacing-16);\n height: var(--spacing-16);\n border-radius: 50%;\n box-shadow: inset 0 0 0 1px\n color-mix(in srgb, var(--color-word) 40%, transparent);\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 &--text {\n cursor: text;\n }\n }\n\n &__stage,\n &__stage > canvas {\n display: block;\n width: 100%;\n height: 100%;\n }\n\n &__draft {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\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 // The text being typed, where it will be drawn: from the point\n // clicked to the right edge of the image\n &__text {\n position: absolute;\n right: 0;\n display: block;\n margin: 0;\n padding: 0;\n overflow: hidden;\n border: 0;\n outline: 1px dashed\n color-mix(in srgb, var(--color-white) 80%, transparent);\n background: transparent;\n font-weight: 700;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n resize: none;\n caret-color: currentcolor;\n user-select: text;\n text-shadow:\n 0 0 1px var(--pk-image-editor-text-edge),\n 0 0 2px var(--pk-image-editor-text-edge),\n 0 0 3px var(--pk-image-editor-text-edge);\n }\n }\n\n // A finger gets 40px (DESIGN.md): a segment is drawn 32px tall, and its\n // area grows around it, as `u-touch-target` does\n @media (pointer: coarse) {\n .pk-image-editor .vv-radio--segment::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n width: max(100%, var(--spacing-40));\n height: max(100%, var(--spacing-40));\n transform: translate(-50%, -50%);\n }\n }\n\n // Same as `u-visually-hidden`, which a class cannot get from the width\n // of a container. Under 50rem the named tools pushed undo and redo to a\n // row of their own (760px, 2026-11-04)\n @container pk-image-editor (max-width: 50rem) {\n .pk-image-editor__tool-label {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\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 EditorTool,\n type ImageEdit,\n type LoadedImage,\n } from './imageEdits'\n\n /**\n * The image editor in a dialog (spec `chat-image-editor.md`): opens on an\n * image file and gives back the edited copy, same name and type. Open\n * while it is mounted: `close` asks the host to drop it. It keeps open on\n * a click outside and on `Esc`, which would throw the edits away.\n */\n const props = defineProps<{\n /**\n * The image: a file of the composer, or one still on its way, such\n * as an image of the conversation the lightbox reads.\n */\n file: File | Promise<File>\n /** The tool picked on opening, crop if none. */\n initialTool?: EditorTool\n }>()\n\n const emit = defineEmits<{\n close: []\n /** The edited copy 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 source = shallowRef<File>()\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 let unmounted = false\n\n onMounted(async () => {\n try {\n const file = await props.file\n const image = await loadEditableImage(file)\n // Closed while the image arrived: nothing will release it later\n if (unmounted) {\n releaseCanvas(image.image)\n return\n }\n source.value = file\n loaded.value = image\n } catch {\n failed.value = 'load'\n }\n })\n\n onBeforeUnmount(() => {\n unmounted = true\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?.pending,\n )\n\n async function useImage() {\n const editor = editorEl.value\n const file = source.value\n if (!editor || !file) {\n return\n }\n // A crop drawn and not applied, a text being typed: what the user\n // sees goes too\n editor.applyPending()\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, file.type)\n emit(\n 'apply',\n new File(\n [blob],\n editedFileName(file.name, 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 :initial-tool=\"initialTool\"\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 EditorTool,\n type ImageEdit,\n type LoadedImage,\n } from './imageEdits'\n\n /**\n * The image editor in a dialog (spec `chat-image-editor.md`): opens on an\n * image file and gives back the edited copy, same name and type. Open\n * while it is mounted: `close` asks the host to drop it. It keeps open on\n * a click outside and on `Esc`, which would throw the edits away.\n */\n const props = defineProps<{\n /**\n * The image: a file of the composer, or one still on its way, such\n * as an image of the conversation the lightbox reads.\n */\n file: File | Promise<File>\n /** The tool picked on opening, crop if none. */\n initialTool?: EditorTool\n }>()\n\n const emit = defineEmits<{\n close: []\n /** The edited copy 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 source = shallowRef<File>()\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 let unmounted = false\n\n onMounted(async () => {\n try {\n const file = await props.file\n const image = await loadEditableImage(file)\n // Closed while the image arrived: nothing will release it later\n if (unmounted) {\n releaseCanvas(image.image)\n return\n }\n source.value = file\n loaded.value = image\n } catch {\n failed.value = 'load'\n }\n })\n\n onBeforeUnmount(() => {\n unmounted = true\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?.pending,\n )\n\n async function useImage() {\n const editor = editorEl.value\n const file = source.value\n if (!editor || !file) {\n return\n }\n // A crop drawn and not applied, a text being typed: what the user\n // sees goes too\n editor.applyPending()\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, file.type)\n emit(\n 'apply',\n new File(\n [blob],\n editedFileName(file.name, 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 :initial-tool=\"initialTool\"\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 EditorTool,\n type ImageEdit,\n type LoadedImage,\n } from './imageEdits'\n\n /**\n * The image editor in a dialog (spec `chat-image-editor.md`): opens on an\n * image file and gives back the edited copy, same name and type. Open\n * while it is mounted: `close` asks the host to drop it. It keeps open on\n * a click outside and on `Esc`, which would throw the edits away.\n */\n const props = defineProps<{\n /**\n * The image: a file of the composer, or one still on its way, such\n * as an image of the conversation the lightbox reads.\n */\n file: File | Promise<File>\n /** The tool picked on opening, crop if none. */\n initialTool?: EditorTool\n }>()\n\n const emit = defineEmits<{\n close: []\n /** The edited copy 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 source = shallowRef<File>()\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 let unmounted = false\n\n onMounted(async () => {\n try {\n const file = await props.file\n const image = await loadEditableImage(file)\n // Closed while the image arrived: nothing will release it later\n if (unmounted) {\n releaseCanvas(image.image)\n return\n }\n source.value = file\n loaded.value = image\n } catch {\n failed.value = 'load'\n }\n })\n\n onBeforeUnmount(() => {\n unmounted = true\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?.pending,\n )\n\n async function useImage() {\n const editor = editorEl.value\n const file = source.value\n if (!editor || !file) {\n return\n }\n // A crop drawn and not applied, a text being typed: what the user\n // sees goes too\n editor.applyPending()\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, file.type)\n emit(\n 'apply',\n new File(\n [blob],\n editedFileName(file.name, 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 :initial-tool=\"initialTool\"\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":";;;;;;;;AAoCA,IAAasF,KAGT;CACA,KAAK;EAAE,MAAM;EAAW,MAAM;CAAU;CACxC,QAAQ;EAA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+BK,IAAA;;MAJvB,SAAA;MAAJ,KAAIkR;MACI,OAAO1M,EAAA;MAAA,kBAAA,AAAAgM,EAAA,QAAA,MAAA,EAAK,QAAAC;MACnB,OAAOM,EAAA,MAAO;MACd,gBAAcvE,EAAA;MACd,SAAK,AAAAgE,EAAA,QAAA,MAAE,EAAA,QAAM;;;;;K,MAEFQ,EAAA,Q,aADhBtR,EAAA,GAAAO,EAMM,OAAA;;MAJF,OAAM;MACN,MAAK;MACJ,cAAYL,EAAA8M,CAAA,CAAE,CAAA,qBAAA;K,IACf5M,EAA8BuQ,GAAA,EAAtB,MAAK,eAAc,CAAA,C;KAEtBlM,EAAA,SAATzE,EAAA,GAAAO,EAYI,KAZJ2Q,GAYI1Q,EAVIkR,EAAA,QAAiCxR,EAAA8M,CAAA,CAAE,CAAA,8BAAA;MAAkE,OAAAvI,EAAA,MAAK;MAAyC,QAAAA,EAAA,MAAK;K,KAAuDvE,EAAA8M,CAAA,CAAE,CAAA,oBAAA;MAAwD,OAAAvI,EAAA,MAAK;MAAyC,QAAAA,EAAA,MAAK"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLightbox-C54BCSbU.js","names":["inject","provide","onBeforeUnmount","onMounted","watch","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","IMAGE_ANNOTATION","provideImageAnnotation","annotation","SHARED_ITEMS","useLightbox","options","lightbox","sharedLightbox","shared","useSharedLightbox","$t","unmounted","gallery","injectPhotoSwipeOverrides","PhotoSwipeLightbox","zoomLevel","linkEl","itemData","element","src","caption","pswp","ANNOTATE_ICON","update","url","getCurrentSlideUrl","annotatableImageUrl","readable","file","readImageFile","canCopyImages","COPY_ICON","readableImageUrl","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","imageFileName","name","subtype","type","fetchImage","response","blob","readAsPng","objectUrl","canvas","png","resolve","reject","show","icon","label","button","labels","downloadUrl","toDownloadUrl","anchor","getFilenameFromUrl","overridesInjected","style"],"sources":["../../../../packages/components/src/composables/useLightbox.ts"],"sourcesContent":["import {\n inject,\n onBeforeUnmount,\n onMounted,\n provide,\n ref,\n shallowRef,\n watch,\n type InjectionKey,\n type Ref,\n type ShallowRef,\n} from 'vue'\nimport { useI18n } from 'vue-i18n'\nimport type PhotoSwipeLightbox from 'photoswipe/lightbox'\nimport type PhotoSwipe from 'photoswipe'\nimport { 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 * \"Annota e chiedi\" (spec `chat-image-editor.md`, F3): a conversation with a\n * composer takes an annotated copy of one of its images as an attachment.\n */\nexport interface ImageAnnotation {\n /** The composer takes an image now: it is shown, uploads on, not full. */\n available: () => boolean\n /** Opens the editor on the image, whose bytes arrive in `file`. */\n annotate: (file: Promise<File>) => void\n}\n\n/** Offers \"Annota e chiedi\" to the lightboxes of the components inside. */\nconst IMAGE_ANNOTATION: InjectionKey<ImageAnnotation> =\n Symbol('imageAnnotation')\n\n/**\n * Gives the lightboxes inside the \"Annota e chiedi\" button: only the chat\n * with a composer calls it, so a log of conversations shows none.\n */\nexport function provideImageAnnotation(annotation: ImageAnnotation): void {\n provide(IMAGE_ANNOTATION, annotation)\n}\n\n/**\n * The items of a shared lightbox: the anchors of the components that joined\n * it, and the images of a markdown that joined it, except an image inside a\n * link, which opens the link.\n */\nconst SHARED_ITEMS =\n 'a[data-pswp-src][data-pswp-shared], [data-pswp-images] img:not(a img)'\n\nexport interface LightboxImage {\n url: string\n caption?: string\n alt?: string\n /** Natural width in px, used by PhotoSwipe for proper sizing. */\n width?: number\n /** Natural height in px, used by PhotoSwipe for proper sizing. */\n height?: number\n}\n\nexport interface LightboxOptions {\n /** Container element whose child anchors are the gallery items */\n gallery: Readonly<Ref<HTMLElement | null | undefined>>\n /** CSS selector for gallery items inside the container (default: `'a[data-pswp-src]'`) */\n children?: string\n loop?: boolean\n /** Show a download button in the lightbox toolbar */\n downloadable?: boolean\n /** Show an open-in-new-tab button in the lightbox toolbar */\n openInNewTab?: boolean\n /**\n * Hands the items to the shared lightbox of a container above\n * (`provideSharedLightbox`), when there is one.\n */\n shared?: boolean\n}\n\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 annotation = inject(IMAGE_ANNOTATION, 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 // Annotate the image and ask about it: the lightbox closes, the\n // editor opens while the bytes arrive, and the copy joins the\n // attachments of the composer\n if (annotation) {\n lightbox.value.on('uiRegister', () => {\n lightbox.value?.pswp?.ui?.registerElement({\n name: 'annotate-button',\n order: 6,\n isButton: true,\n html: ANNOTATE_ICON,\n title: $t('lightbox.annotate'),\n onInit: (element, pswp) => {\n const update = () => {\n const url = getCurrentSlideUrl(pswp)\n element.hidden =\n !url ||\n !annotatableImageUrl(url) ||\n !annotation.available()\n }\n pswp.on('change', update)\n // The composer fills up, or comes back as a call\n // ends, while the lightbox stays on one slide\n pswp.on('destroy', watch(annotation.available, update))\n },\n onClick: (_, __, pswp) => {\n const url = getCurrentSlideUrl(pswp)\n const readable = url && annotatableImageUrl(url)\n if (!readable || !annotation.available()) {\n return\n }\n const file = readImageFile(\n readable,\n pswp.currSlide?.data.caption,\n )\n // The editor reads it; one that never opens must not\n // leave its failure unhandled\n void file.catch(() => undefined)\n // PhotoSwipe ignores a close while it opens: a quick\n // click left it over the page, trapping the focus\n if (pswp.opener.isOpen) {\n pswp.close()\n } else {\n pswp.on('openingAnimationEnd', () => pswp.close())\n }\n annotation.annotate(file)\n },\n })\n })\n }\n\n // Copy the image, on the slides whose bytes a page may read\n if (canCopyImages()) {\n lightbox.value.on('uiRegister', () => {\n lightbox.value?.pswp?.ui?.registerElement({\n name: 'copy-button',\n order: 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 ANNOTATE_ICON =\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m15.243 4.512l-6.738 6.737l-.707 2.121l-1.04 1.041l2.828 2.828l1.04-1.04l2.122-.708l6.737-6.737zm6.364 3.535a1 1 0 0 1 0 1.414l-7.778 7.778l-2.122.707l-1.414 1.415a1 1 0 0 1-1.414 0l-4.243-4.243a1 1 0 0 1 0-1.414L6.05 12.29l.707-2.122l7.779-7.778a1 1 0 0 1 1.414 0zm-6.364-.707l1.414 1.414l-4.95 4.95l-1.414-1.414zm-10.96 9.546l2.828 2.828l-1.414 1.415l-4.243-1.415z\"/></svg>'\nconst COPY_ICON =\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M7 6V3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-3v3c0 .552-.45 1-1.007 1H4.007A1 1 0 0 1 3 21l.003-14c0-.552.45-1 1.006-1zM5.002 8L5 20h10V8zM9 6h8v10h2V4H9z\"/></svg>'\nconst COPIED_ICON =\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"m10 15.172l9.192-9.193l1.415 1.414L10 18l-6.364-6.364l1.414-1.414z\"/></svg>'\nconst COPY_FAILED_ICON =\n '<svg aria-hidden=\"true\" class=\"pswp__icn\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path fill=\"#ffffff\" d=\"M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10s-4.477 10-10 10m0-2a8 8 0 1 0 0-16a8 8 0 0 0 0 16m-1-5h2v2h-2zm0-8h2v6h-2z\"/></svg>'\n\n// How long the button shows the outcome of a copy before it is a copy again.\nconst COPY_FEEDBACK_MS = 1500\nconst copyFeedbackTimers = new WeakMap<\n HTMLElement,\n ReturnType<typeof setTimeout>\n>()\n\n/** The browser can put an image on the clipboard. */\nfunction canCopyImages(): boolean {\n return (\n typeof ClipboardItem !== 'undefined' &&\n typeof navigator.clipboard?.write === 'function'\n )\n}\n\n/**\n * Where a page may read the bytes of a slide: a chat file through its\n * `/content` route, since its `/view` link redirects to the storage host,\n * which answers no page's CORS; an upload of this session or an inline image\n * as they are. Any other host would refuse the read, so that slide offers no\n * copy.\n */\nfunction readableImageUrl(url: string): string | undefined {\n if (url.startsWith('blob:') || url.startsWith('data:image/')) {\n return url\n }\n if (/\\/chats\\/[^/]+\\/media\\/[^/]+\\/view(\\?|$)/.test(url)) {\n return url.replace(/\\/view(\\?|$)/, '/content$1')\n }\n return undefined\n}\n\n/**\n * Where the editor may read the bytes of a slide: one a page may read\n * (`readableImageUrl`) that the canvas decodes, so not an inline drawing,\n * such as the SVG of a diagram.\n */\nexport function annotatableImageUrl(url: string): string | undefined {\n if (\n url.startsWith('data:') &&\n !/^data:image\\/(png|jpeg|webp|gif)[;,]/.test(url)\n ) {\n return undefined\n }\n return readableImageUrl(url)\n}\n\n/**\n * The name of the copy of an image: its caption when that is a file name,\n * as an attachment's is, else `image` with the extension of its type.\n */\nexport function imageFileName(\n caption: string | undefined,\n type: string,\n): string {\n const name = caption?.trim()\n if (name && /\\.(png|jpe?g|webp|gif)$/i.test(name)) {\n return name\n }\n const subtype = /^image\\/(png|jpeg|webp|gif)$/.exec(type)?.[1]\n return `image.${subtype === 'jpeg' ? 'jpg' : (subtype ?? 'png')}`\n}\n\n/** The bytes of the image at `url`, a readable one. */\nasync function fetchImage(url: string): Promise<Blob> {\n const response = await fetch(url, { credentials: 'include' })\n if (!response.ok) {\n throw new Error(`The image answered ${response.status}`)\n }\n return response.blob()\n}\n\n/** The image at `url` as a file, for the editor. */\nasync function readImageFile(url: string, caption?: string): Promise<File> {\n const blob = await fetchImage(url)\n return new File([blob], imageFileName(caption, blob.type), {\n type: blob.type,\n })\n}\n\n/**\n * The image at `url` as a PNG, the one type every browser puts on the\n * clipboard: another type is drawn on a canvas first.\n */\nasync function readAsPng(url: string): Promise<Blob> {\n const blob = await fetchImage(url)\n if (blob.type === 'image/png') {\n return blob\n }\n // An `<img>` and not `createImageBitmap`, which refuses an SVG\n const objectUrl = URL.createObjectURL(blob)\n try {\n const image = new Image()\n image.src = objectUrl\n await image.decode()\n const canvas = document.createElement('canvas')\n canvas.width = image.naturalWidth\n canvas.height = image.naturalHeight\n canvas.getContext('2d')?.drawImage(image, 0, 0)\n return await new Promise<Blob>((resolve, reject) => {\n canvas.toBlob(\n (png) =>\n png ? resolve(png) : reject(new Error('No PNG was drawn')),\n 'image/png',\n )\n })\n } finally {\n URL.revokeObjectURL(objectUrl)\n }\n}\n\n/**\n * Copies the image and shows on the button how it went. The PNG goes to the\n * clipboard as a promise, so Safari still counts the click as the gesture\n * while the bytes arrive.\n */\nasync function copyImage(\n url: string,\n button: HTMLElement,\n labels: { copy: string; copied: string; failed: string },\n): Promise<void> {\n const show = (icon: string, label: string) => {\n button.innerHTML = icon\n button.title = label\n button.setAttribute('aria-label', label)\n }\n const png = readAsPng(url)\n // The clipboard reads it below; a browser that refuses a promise in\n // `ClipboardItem` never does, and its failure must not go unhandled\n void png.catch(() => undefined)\n try {\n await navigator.clipboard.write([\n new ClipboardItem({ 'image/png': png }),\n ])\n show(COPIED_ICON, labels.copied)\n } catch {\n show(COPY_FAILED_ICON, labels.failed)\n }\n // A second copy restarts the wait instead of being cut short by the first\n clearTimeout(copyFeedbackTimers.get(button))\n copyFeedbackTimers.set(\n button,\n setTimeout(() => show(COPY_ICON, labels.copy), COPY_FEEDBACK_MS),\n )\n}\n\n/**\n * Triggers a client-side download for an image URL.\n *\n * For backend media URLs (.../media/:file/view), navigates to the\n * corresponding /download endpoint which redirects to an Azure SAS URL\n * with `Content-Disposition: attachment`, so no CORS issues.\n *\n * For blob: URLs (in-session uploads), uses the fetch → blob approach.\n *\n * For data: URLs (inline SVGs, etc.), use the download attribute.\n *\n * Falls back to opening in a new tab for all other cases.\n */\nfunction downloadImage(url: string): void {\n const downloadUrl = toDownloadUrl(url)\n\n const anchor = document.createElement('a')\n anchor.href = downloadUrl\n anchor.target = '_blank'\n anchor.rel = 'noopener noreferrer'\n // `download` attribute works for same-origin, data: and blob: URLs; for\n // cross-origin it is ignored but the browser still follows Content-Disposition.\n anchor.download = getFilenameFromUrl(url)\n document.body.appendChild(anchor)\n anchor.click()\n document.body.removeChild(anchor)\n}\n\n/**\n * Converts a `/view` media URL to its `/download` counterpart.\n * Leaves blob:, data: and all other URLs untouched.\n */\nfunction toDownloadUrl(url: string): string {\n return url.replace(/\\/view(\\?|$)/, '/download$1')\n}\n\nfunction getFilenameFromUrl(url: string): string {\n if (url.startsWith('data:image/svg+xml')) {\n return 'diagram.svg'\n }\n if (url.startsWith('data:')) {\n const mime = url.split(':')[1].split(';')[0]\n const ext = mime.split('/')[1] || 'bin'\n return `image.${ext}`\n }\n try {\n const pathname = new URL(url).pathname\n const name = pathname.split('/').pop()\n return name && name.includes('.') ? name : 'image'\n } catch {\n return 'image'\n }\n}\n\nlet overridesInjected = false\n\n/**\n * Injects a one-time `<style>` into `document.head` that raises\n * PhotoSwipe's z-index above any host UI (e.g. floating chat widgets\n * that use `z-index: 2147483647`), sizes its icons, lays a checkerboard\n * under transparent images and places the caption.\n */\nfunction injectPhotoSwipeOverrides(): void {\n if (overridesInjected) {\n return\n }\n overridesInjected = true\n const style = document.createElement('style')\n style.textContent = [\n '.pswp__counter { font-family: sans-serif; }',\n '.pswp { z-index: 2147483647 !important; }',\n '.pswp__icn { width: 20px; height: 20px; }',\n '.pswp__button { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; }',\n '.pswp__button[hidden] { display: none; }',\n '.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":";;;;;;AAiBA,IAAMW,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,GAcvEC,IACF,OAAO,iBAAiB;AAM5B,SAAgBC,EAAuB,GAAmC;CACtE,EAAQD,GAAkBE,CAAU;AACxC;AAOA,IAAMC,IACF;AAkDJ,SAAgBC,EAAY,GAA6C;CACrE,IAAM,EACF,YACA,cAAW,oBACX,UAAO,IACP,kBAAe,IACf,kBAAe,IACf,YAAS,OACTC,GAEEC,IAAWd,EAAsC,IAAI,GACrDe,IAAiBC,IAASC,EAAkB,IAAI,KAAA,GAChDP,IAAalB,EAAOgB,GAAkB,KAAA,CAAS,GAC/C,EAAE,GAAGU,MAAOjB,EAAQ,EAAE,UAAU,SAAS,CAAC,GAC5CkB,IAAY;CA4PhB,OANAzB,QAAsB;EAGlB,AAFA,IAAY,IACZoB,EAAS,OAAO,QAAQ,GACxB,EAAS,QAAQ;CACrB,CAAC,GAEM;EAAE;EAAU,kBA1PM;GACrB,IAAIC,GAAgB;IAChB,EAAe,KAAK;IACpB;GACJ;GACA,IAAI,CAACK,EAAQ,OACT;GAMJ,AADAlB,EAAWC,CAAc,GACzBkB,EAA0B;GAE1B,IAAM,EAAE,SAASC,MACb,MAAM,OAAO;GAEjB,AAAIH,MAIJ,EAAS,QAAQ,IAAIG,EAAmB;IACpC,SAASF,EAAQ;IACjB;IACA,kBAAkB,OAAO;IACzB;IAGA,aAAa;IAGb,qBAAqB,MACjB,KAAK,IACD,GACAf,KACKkB,EAAU,aAAa,KAAKlB,EACrC;IACJ,YAAYa,EAAG,cAAc;IAC7B,WAAWA,EAAG,eAAe;IAC7B,gBAAgBA,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