@nubisco/ui 5.62.0 → 5.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AiProvider-BBaevvUs.cjs +1 -0
- package/dist/AiProvider-D-uWPJF3.js +170 -0
- package/dist/ImageCropper-Bz-bxRC5.cjs +1 -0
- package/dist/ImageCropper-C7HkrQdd.js +383 -0
- package/dist/all.cjs +1 -1
- package/dist/all.mjs +2 -2
- package/dist/components/AiProvider.cjs +1 -1
- package/dist/components/AiProvider.d.ts +16 -0
- package/dist/components/AiProvider.mjs +1 -1
- package/dist/components/AiProvider.vue.d.ts +1 -0
- package/dist/components/AiProvider.vue.d.ts.map +1 -1
- package/dist/components/ImageCropper.cjs +1 -1
- package/dist/components/ImageCropper.d.ts +14 -0
- package/dist/components/ImageCropper.mjs +1 -1
- package/dist/components/ImageCropper.vue.d.ts +2 -0
- package/dist/components/ImageCropper.vue.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/styles/ImageCropper.css +1 -1
- package/dist/ui.css +1 -1
- package/dist/utils/cropGeometry.helper.cjs +1 -0
- package/dist/utils/cropGeometry.helper.d.ts +66 -0
- package/dist/utils/cropGeometry.helper.d.ts.map +1 -0
- package/dist/utils/cropGeometry.helper.mjs +55 -0
- package/package.json +1 -1
- package/src/utils/cropGeometry.helper.ts +108 -0
- package/dist/AiProvider-CGB9EiSf.cjs +0 -1
- package/dist/AiProvider-CMbPWtU-.js +0 -137
- package/dist/ImageCropper-CgmDT83u.cjs +0 -1
- package/dist/ImageCropper-D61PEzb2.js +0 -413
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic behind `NbImageCropper`, kept out of the component so it can
|
|
3
|
+
* be tested without a canvas.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
interface ISize {
|
|
7
|
+
width: number
|
|
8
|
+
height: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface IRect {
|
|
12
|
+
x: number
|
|
13
|
+
y: number
|
|
14
|
+
width: number
|
|
15
|
+
height: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* How large to draw an image so it fits a box, keeping its proportions.
|
|
20
|
+
*
|
|
21
|
+
* @param image The image's natural size.
|
|
22
|
+
* @param box The largest size it may be drawn at.
|
|
23
|
+
*/
|
|
24
|
+
export function fitImage(image: ISize, box: ISize): ISize {
|
|
25
|
+
if (!image.width || !image.height || box.width <= 0 || box.height <= 0) {
|
|
26
|
+
return { width: 0, height: 0 }
|
|
27
|
+
}
|
|
28
|
+
const aspect = image.width / image.height
|
|
29
|
+
if (aspect > box.width / box.height) {
|
|
30
|
+
return { width: box.width, height: box.width / aspect }
|
|
31
|
+
}
|
|
32
|
+
return { width: box.height * aspect, height: box.height }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Where the crop area starts on a drawn image.
|
|
37
|
+
*
|
|
38
|
+
* `center` is half the image, centred, the cropper's long-standing default:
|
|
39
|
+
* a picture to be cut down to one part of it. `full` is the whole image, for
|
|
40
|
+
* a photograph whose edges only need trimming, such as a scanned page.
|
|
41
|
+
* `square` (circle crops and a locked aspect ratio) is half the shorter side,
|
|
42
|
+
* centred, whatever `initial` asks for, so a square never starts stretched.
|
|
43
|
+
*
|
|
44
|
+
* @param drawn The size the image is drawn at.
|
|
45
|
+
* @param initial Where to start.
|
|
46
|
+
* @param square Whether the crop area must be square.
|
|
47
|
+
*/
|
|
48
|
+
export function initialCropRect(
|
|
49
|
+
drawn: ISize,
|
|
50
|
+
initial: 'center' | 'full',
|
|
51
|
+
square: boolean,
|
|
52
|
+
): IRect {
|
|
53
|
+
if (square) {
|
|
54
|
+
const side = Math.min(drawn.width, drawn.height) * 0.5
|
|
55
|
+
return {
|
|
56
|
+
x: (drawn.width - side) / 2,
|
|
57
|
+
y: (drawn.height - side) / 2,
|
|
58
|
+
width: side,
|
|
59
|
+
height: side,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (initial === 'full') {
|
|
63
|
+
return { x: 0, y: 0, width: drawn.width, height: drawn.height }
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
x: drawn.width * 0.25,
|
|
67
|
+
y: drawn.height * 0.25,
|
|
68
|
+
width: drawn.width * 0.5,
|
|
69
|
+
height: drawn.height * 0.5,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A pointer position in the canvas's own pixels.
|
|
75
|
+
*
|
|
76
|
+
* The canvas can be drawn at one size and shown at another (CSS shrinks it to
|
|
77
|
+
* fit a narrow container), so a position measured on screen is scaled by the
|
|
78
|
+
* ratio between the two. Without that, a drag on a shrunk canvas lands short
|
|
79
|
+
* of where the finger is.
|
|
80
|
+
*
|
|
81
|
+
* @param client The pointer position, in viewport pixels.
|
|
82
|
+
* @param shown The canvas's on-screen box (`getBoundingClientRect()`).
|
|
83
|
+
* @param drawn The canvas's own size (`canvas.width`, `canvas.height`).
|
|
84
|
+
*/
|
|
85
|
+
export function toCanvasPoint(
|
|
86
|
+
client: { x: number; y: number },
|
|
87
|
+
shown: { left: number; top: number; width: number; height: number },
|
|
88
|
+
drawn: ISize,
|
|
89
|
+
): { x: number; y: number } {
|
|
90
|
+
const sx = shown.width ? drawn.width / shown.width : 1
|
|
91
|
+
const sy = shown.height ? drawn.height / shown.height : 1
|
|
92
|
+
return { x: (client.x - shown.left) * sx, y: (client.y - shown.top) * sy }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The same crop area on the image drawn at a new size, so resizing the window
|
|
97
|
+
* keeps what the person chose.
|
|
98
|
+
*/
|
|
99
|
+
export function rescaleRect(rect: IRect, from: ISize, to: ISize): IRect {
|
|
100
|
+
const sx = from.width ? to.width / from.width : 1
|
|
101
|
+
const sy = from.height ? to.height / from.height : 1
|
|
102
|
+
return {
|
|
103
|
+
x: rect.x * sx,
|
|
104
|
+
y: rect.y * sy,
|
|
105
|
+
width: rect.width * sx,
|
|
106
|
+
height: rect.height * sy,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require(`./chunk-D-qHiVGv.cjs`);const e=require(`./Button-CGIbF1e-.cjs`),t=require(`./TextInput-SJ34hD2Y.cjs`),n=require(`./AiLabel-jRrBTu6c.cjs`),r=require(`./Field-AXSzk3l3.cjs`),i=require(`./Panel-BKASZF-B.cjs`),a=require(`./Select-CJqwMI69.cjs`);let o=require(`vue`);var s={class:`nb-ai-provider__header`},c={class:`nb-ai-provider__title`},l={key:0,class:`nb-ai-provider__description`},u={class:`nb-ai-provider__row`},d={class:`nb-ai-provider__actions`},f=(0,o.defineComponent)({__name:`AiProvider`,props:{title:{default:`AI briefings`},providers:{default:()=>[{label:`Anthropic (Claude)`,value:`anthropic`},{label:`OpenAI`,value:`openai`},{label:`Google Gemini`,value:`gemini`}]},provider:{default:`anthropic`},model:{default:``},apiKey:{default:``},defaultModels:{default:()=>({})},hasKey:{type:Boolean,default:!1},busy:{type:Boolean,default:!1}},emits:[`update:provider`,`update:model`,`update:apiKey`,`save`,`remove`],setup(f,{emit:p}){let m=p;return(p,h)=>((0,o.openBlock)(),(0,o.createBlock)(i.t,{class:`nb-ai-provider`},{default:(0,o.withCtx)(()=>[(0,o.createElementVNode)(`header`,s,[(0,o.createElementVNode)(`h2`,c,[(0,o.createTextVNode)((0,o.toDisplayString)(f.title)+` `,1),(0,o.createVNode)(n.t,{static:``,size:`sm`})]),p.$slots.default?((0,o.openBlock)(),(0,o.createElementBlock)(`div`,l,[(0,o.renderSlot)(p.$slots,`default`)])):(0,o.createCommentVNode)(``,!0)]),(0,o.createElementVNode)(`div`,u,[(0,o.createVNode)(r.t,{label:`Provider`,orientation:`stack`},{default:(0,o.withCtx)(({id:e})=>[(0,o.createVNode)(a.t,{id:e,"model-value":f.provider,options:f.providers,disabled:f.busy,"onUpdate:modelValue":h[0]||=e=>m(`update:provider`,String(e))},null,8,[`id`,`model-value`,`options`,`disabled`])]),_:1}),(0,o.createVNode)(r.t,{label:`Model`,hint:`Empty uses the provider's default.`,orientation:`stack`},{default:(0,o.withCtx)(({id:e})=>[(0,o.createVNode)(t.t,{id:e,"model-value":f.model,placeholder:f.defaultModels[f.provider]??``,disabled:f.busy,"onUpdate:modelValue":h[1]||=e=>m(`update:model`,String(e??``))},null,8,[`id`,`model-value`,`placeholder`,`disabled`])]),_:1})]),(0,o.createVNode)(r.t,{label:`API key`,hint:`Encrypted at rest and never sent back to the browser, so this field is always empty when the page loads.`,orientation:`stack`},{default:(0,o.withCtx)(({id:e})=>[(0,o.createVNode)(t.t,{id:e,"model-value":f.apiKey,type:`password`,autocomplete:`off`,placeholder:f.hasKey?`Stored. Type a new key to replace it.`:`sk-...`,disabled:f.busy,"onUpdate:modelValue":h[2]||=e=>m(`update:apiKey`,String(e??``))},null,8,[`id`,`model-value`,`placeholder`,`disabled`])]),_:1}),(0,o.createElementVNode)(`div`,d,[(0,o.createVNode)(e.t,{variant:`primary`,loading:f.busy,onClick:h[3]||=e=>m(`save`)},{default:(0,o.withCtx)(()=>[...h[5]||=[(0,o.createTextVNode)(` Save AI settings `,-1)]]),_:1},8,[`loading`]),f.hasKey?((0,o.openBlock)(),(0,o.createBlock)(e.t,{key:0,variant:`ghost`,disabled:f.busy,onClick:h[4]||=e=>m(`remove`)},{default:(0,o.withCtx)(()=>[...h[6]||=[(0,o.createTextVNode)(` Remove key `,-1)]]),_:1},8,[`disabled`])):(0,o.createCommentVNode)(``,!0)])]),_:3}))}});Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return f}});
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { t as e } from "./Button-DmJ_J3UO.js";
|
|
2
|
-
import { t } from "./TextInput-BeqDf1R7.js";
|
|
3
|
-
import { t as n } from "./AiLabel-BDccQ2iQ.js";
|
|
4
|
-
import { t as r } from "./Field-B8wNroAI.js";
|
|
5
|
-
import { t as i } from "./Panel-4itscCsS.js";
|
|
6
|
-
import { t as a } from "./Select-CDs-7QtW.js";
|
|
7
|
-
import { createBlock as o, createCommentVNode as s, createElementBlock as c, createElementVNode as l, createTextVNode as u, createVNode as d, defineComponent as f, openBlock as p, renderSlot as m, toDisplayString as h, withCtx as g } from "vue";
|
|
8
|
-
//#region src/components/AiProvider.vue?vue&type=script&setup=true&lang.ts
|
|
9
|
-
var _ = { class: "nb-ai-provider__header" }, v = { class: "nb-ai-provider__title" }, y = {
|
|
10
|
-
key: 0,
|
|
11
|
-
class: "nb-ai-provider__description"
|
|
12
|
-
}, b = { class: "nb-ai-provider__row" }, x = { class: "nb-ai-provider__actions" }, S = /* @__PURE__ */ f({
|
|
13
|
-
__name: "AiProvider",
|
|
14
|
-
props: {
|
|
15
|
-
title: { default: "AI briefings" },
|
|
16
|
-
providers: { default: () => [
|
|
17
|
-
{
|
|
18
|
-
label: "Anthropic (Claude)",
|
|
19
|
-
value: "anthropic"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
label: "OpenAI",
|
|
23
|
-
value: "openai"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
label: "Google Gemini",
|
|
27
|
-
value: "gemini"
|
|
28
|
-
}
|
|
29
|
-
] },
|
|
30
|
-
provider: { default: "anthropic" },
|
|
31
|
-
model: { default: "" },
|
|
32
|
-
apiKey: { default: "" },
|
|
33
|
-
defaultModels: { default: () => ({}) },
|
|
34
|
-
hasKey: {
|
|
35
|
-
type: Boolean,
|
|
36
|
-
default: !1
|
|
37
|
-
},
|
|
38
|
-
busy: {
|
|
39
|
-
type: Boolean,
|
|
40
|
-
default: !1
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
emits: [
|
|
44
|
-
"update:provider",
|
|
45
|
-
"update:model",
|
|
46
|
-
"update:apiKey",
|
|
47
|
-
"save",
|
|
48
|
-
"remove"
|
|
49
|
-
],
|
|
50
|
-
setup(f, { emit: S }) {
|
|
51
|
-
let C = S;
|
|
52
|
-
return (S, w) => (p(), o(i, { class: "nb-ai-provider" }, {
|
|
53
|
-
default: g(() => [
|
|
54
|
-
l("header", _, [l("h2", v, [u(h(f.title) + " ", 1), d(n, {
|
|
55
|
-
static: "",
|
|
56
|
-
size: "sm"
|
|
57
|
-
})]), S.$slots.default ? (p(), c("div", y, [m(S.$slots, "default")])) : s("", !0)]),
|
|
58
|
-
l("div", b, [d(r, {
|
|
59
|
-
label: "Provider",
|
|
60
|
-
orientation: "stack"
|
|
61
|
-
}, {
|
|
62
|
-
default: g(({ id: e }) => [d(a, {
|
|
63
|
-
id: e,
|
|
64
|
-
"model-value": f.provider,
|
|
65
|
-
options: f.providers,
|
|
66
|
-
disabled: f.busy,
|
|
67
|
-
"onUpdate:modelValue": w[0] ||= (e) => C("update:provider", String(e))
|
|
68
|
-
}, null, 8, [
|
|
69
|
-
"id",
|
|
70
|
-
"model-value",
|
|
71
|
-
"options",
|
|
72
|
-
"disabled"
|
|
73
|
-
])]),
|
|
74
|
-
_: 1
|
|
75
|
-
}), d(r, {
|
|
76
|
-
label: "Model",
|
|
77
|
-
hint: "Empty uses the provider's default.",
|
|
78
|
-
orientation: "stack"
|
|
79
|
-
}, {
|
|
80
|
-
default: g(({ id: e }) => [d(t, {
|
|
81
|
-
id: e,
|
|
82
|
-
"model-value": f.model,
|
|
83
|
-
placeholder: f.defaultModels[f.provider] ?? "",
|
|
84
|
-
disabled: f.busy,
|
|
85
|
-
"onUpdate:modelValue": w[1] ||= (e) => C("update:model", String(e ?? ""))
|
|
86
|
-
}, null, 8, [
|
|
87
|
-
"id",
|
|
88
|
-
"model-value",
|
|
89
|
-
"placeholder",
|
|
90
|
-
"disabled"
|
|
91
|
-
])]),
|
|
92
|
-
_: 1
|
|
93
|
-
})]),
|
|
94
|
-
d(r, {
|
|
95
|
-
label: "API key",
|
|
96
|
-
hint: "Encrypted at rest and never sent back to the browser, so this field is always empty when the page loads.",
|
|
97
|
-
orientation: "stack"
|
|
98
|
-
}, {
|
|
99
|
-
default: g(({ id: e }) => [d(t, {
|
|
100
|
-
id: e,
|
|
101
|
-
"model-value": f.apiKey,
|
|
102
|
-
type: "password",
|
|
103
|
-
autocomplete: "off",
|
|
104
|
-
placeholder: f.hasKey ? "Stored. Type a new key to replace it." : "sk-...",
|
|
105
|
-
disabled: f.busy,
|
|
106
|
-
"onUpdate:modelValue": w[2] ||= (e) => C("update:apiKey", String(e ?? ""))
|
|
107
|
-
}, null, 8, [
|
|
108
|
-
"id",
|
|
109
|
-
"model-value",
|
|
110
|
-
"placeholder",
|
|
111
|
-
"disabled"
|
|
112
|
-
])]),
|
|
113
|
-
_: 1
|
|
114
|
-
}),
|
|
115
|
-
l("div", x, [d(e, {
|
|
116
|
-
variant: "primary",
|
|
117
|
-
loading: f.busy,
|
|
118
|
-
onClick: w[3] ||= (e) => C("save")
|
|
119
|
-
}, {
|
|
120
|
-
default: g(() => [...w[5] ||= [u(" Save AI settings ", -1)]]),
|
|
121
|
-
_: 1
|
|
122
|
-
}, 8, ["loading"]), f.hasKey ? (p(), o(e, {
|
|
123
|
-
key: 0,
|
|
124
|
-
variant: "ghost",
|
|
125
|
-
disabled: f.busy,
|
|
126
|
-
onClick: w[4] ||= (e) => C("remove")
|
|
127
|
-
}, {
|
|
128
|
-
default: g(() => [...w[6] ||= [u(" Remove key ", -1)]]),
|
|
129
|
-
_: 1
|
|
130
|
-
}, 8, ["disabled"])) : s("", !0)])
|
|
131
|
-
]),
|
|
132
|
-
_: 3
|
|
133
|
-
}));
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
//#endregion
|
|
137
|
-
export { S as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require(`./chunk-D-qHiVGv.cjs`);const e=require(`./_plugin-vue_export-helper-D0Q0f7-M.cjs`),t=require(`./Grid-tn5_R2fP.cjs`),n=require(`./vue-i18n-BaeznwnA.cjs`);let r=require(`vue`);var i=function(e){return e.TopLeft=`top-left`,e.Top=`top`,e.TopRight=`top-right`,e.Right=`right`,e.BottomRight=`bottom-right`,e.Bottom=`bottom`,e.BottomLeft=`bottom-left`,e.Left=`left`,e}(i||{}),a={class:`nb-image-cropper`},o=[`onMousedown`,`onTouchstart`],s=[`src`,`alt`],c=700,l=400,u=(0,r.defineComponent)({__name:`ImageCropper`,props:{image:{},cropAsCircle:{type:Boolean,default:!1},outputAsCircle:{type:Boolean,default:!1},lockAspectRatio:{type:Boolean,default:!1},showPreview:{type:Boolean,default:!1}},emits:[`crop`],setup(e,{emit:u}){let d={en:{X:`X`,Y:`Y`,WIDTH:`Width`,HEIGHT:`Height`,IMAGE_THUMBNAIL:`Cropped preview`},pt:{X:`X`,Y:`Y`,WIDTH:`Largura`,HEIGHT:`Altura`,IMAGE_THUMBNAIL:`Pré-visualização recortada`}},{t:f,te:p,locale:m}=n.t({useScope:`global`});function h(e){if(p(e))return f(e);let t=e.slice(7);return d[String(m.value).toLowerCase().split(`-`)[0]]?.[t]??d.en[t]??e}let g=e,_=u,v=(0,r.ref)(null),y=null,b=new Image,x=null,S={x:1,y:1},C=(0,r.ref)({x:50,y:50,width:200,height:200}),w=(0,r.ref)(null),T=(0,r.ref)(null),E=!1,D=!1,O={x:0,y:0},k=!1,A={x:0,y:0},j={x:0,y:0,width:0,height:0},M=null,N=!1,P=[{name:i.TopLeft},{name:i.Top},{name:i.TopRight},{name:i.Right},{name:i.BottomRight},{name:i.Bottom},{name:i.BottomLeft},{name:i.Left}],F=()=>{if(!g.image){console.error(`No image file provided`);return}x&&=(URL.revokeObjectURL(x),null),b.onload=()=>{let{drawWidth:e,drawHeight:t}=I();if(v.value){v.value.width=e,v.value.height=t;let n=(v.value.width-b.width*S.x)/2,r=(v.value.height-b.height*S.y)/2;if(g.cropAsCircle||g.lockAspectRatio){let e=Math.min(b.width*S.x,b.height*S.y)*.5;C.value={x:n+(b.width*S.x-e)/2,y:r+(b.height*S.y-e)/2,width:e,height:e}}else C.value={x:n+(b.width*S.x*.5-b.width*S.x*.25),y:r+(b.height*S.y*.5-b.height*S.y*.25),width:b.width*S.x*.5,height:b.height*S.y*.5};L(),Q()}},b.onerror=()=>{console.error(`Failed to load image`)},x=URL.createObjectURL(g.image),b.src=x};(0,r.onMounted)(()=>{v.value&&(y=v.value.getContext(`2d`),y&&(y.imageSmoothingEnabled=!0,y.imageSmoothingQuality=`high`),g.image&&F())}),(0,r.onBeforeUnmount)(()=>{x&&=(URL.revokeObjectURL(x),null);let e=w.value;e&&(URL.revokeObjectURL(e),w.value=null)}),(0,r.watch)(()=>g.image,e=>{e&&F()}),(0,r.watch)(()=>[g.cropAsCircle,g.outputAsCircle,g.lockAspectRatio],()=>{v.value&&y&&L()});let I=()=>{let e=b.width/b.height,t=c,n=l;return e>c/l?n=c/e:t=l*e,S.x=t/b.width,S.y=n/b.height,{drawWidth:t,drawHeight:n}},L=()=>{if(y&&v.value){y.clearRect(0,0,v.value.width,v.value.height);let e=(v.value.width-b.width*S.x)/2,t=(v.value.height-b.height*S.y)/2;y.drawImage(b,0,0,b.width,b.height,e,t,b.width*S.x,b.height*S.y),R()}},R=()=>{y&&v.value&&(y.save(),y.beginPath(),g.cropAsCircle?y.arc(C.value.x+C.value.width/2,C.value.y+C.value.height/2,C.value.width/2,0,Math.PI*2):y.rect(C.value.x,C.value.y,C.value.width,C.value.height),y.rect(0,0,v.value.width,v.value.height),y.clip(`evenodd`),y.fillStyle=`rgba(0, 0, 0, 0.5)`,y.fillRect(0,0,v.value.width,v.value.height),y.restore(),y.save(),y.strokeStyle=`rgba(255, 255, 255, 0.8)`,y.lineWidth=1,y.setLineDash([5,5]),y.imageSmoothingEnabled=!1,g.cropAsCircle?(y.beginPath(),y.arc(C.value.x+C.value.width/2,C.value.y+C.value.height/2,C.value.width/2,0,Math.PI*2),y.stroke()):y.strokeRect(C.value.x,C.value.y,C.value.width,C.value.height),y.restore())},z=(0,r.computed)(()=>{if(g.cropAsCircle){let e=C.value.x+C.value.width/2,t=C.value.y+C.value.height/2,n=C.value.width/2;return{"top-left":{left:`${e-n-5}px`,top:`${t-n-5}px`},top:{left:`${e-5}px`,top:`${t-n-5}px`},"top-right":{left:`${e+n-5}px`,top:`${t-n-5}px`},right:{left:`${e+n-5}px`,top:`${t-5}px`},"bottom-right":{left:`${e+n-5}px`,top:`${t+n-5}px`},bottom:{left:`${e-5}px`,top:`${t+n-5}px`},"bottom-left":{left:`${e-n-5}px`,top:`${t+n-5}px`},left:{left:`${e-n-5}px`,top:`${t-5}px`}}}else return{"top-left":{left:`${C.value.x-5}px`,top:`${C.value.y-5}px`},top:{left:`${C.value.x+C.value.width/2-5}px`,top:`${C.value.y-5}px`},"top-right":{left:`${C.value.x+C.value.width-5}px`,top:`${C.value.y-5}px`},right:{left:`${C.value.x+C.value.width-5}px`,top:`${C.value.y+C.value.height/2-5}px`},"bottom-right":{left:`${C.value.x+C.value.width-5}px`,top:`${C.value.y+C.value.height-5}px`},bottom:{left:`${C.value.x+C.value.width/2-5}px`,top:`${C.value.y+C.value.height-5}px`},"bottom-left":{left:`${C.value.x-5}px`,top:`${C.value.y+C.value.height-5}px`},left:{left:`${C.value.x-5}px`,top:`${C.value.y+C.value.height/2-5}px`}}}),B=e=>{if(`touches`in e&&e.touches.length>0){let t=e.touches[0];return{clientX:t.clientX,clientY:t.clientY}}else if(`clientX`in e&&`clientY`in e)return{clientX:e.clientX,clientY:e.clientY};return{clientX:0,clientY:0}},V=e=>{let t=v.value;if(!t)return null;let{clientX:n,clientY:r}=B(e),{left:i,top:a}=t.getBoundingClientRect();return{x:n-i,y:r-a}},H=e=>{e.preventDefault();let t=V(e);if(!t)return;let{x:n,y:r}=t;X(n,r)&&(D=!0,E=!0,O={x:n-C.value.x,y:r-C.value.y})},U=e=>{D?G(e):k&&J(e)},W=()=>{D&&(K(),D=!1,Q()),k&&(Y(),Q()),E=!1,D=!1},G=e=>{if(E){let t=V(e);if(!t)return;let{x:n,y:r}=t;C.value.x=Math.floor(n-O.x),C.value.y=Math.floor(r-O.y),L()}},K=()=>{E&&=(Z(),L(),!1)},q=(e,t)=>{e.preventDefault();let n=V(e);n&&(k=!0,M=t,A={x:n.x,y:n.y},j={...C.value},N=e instanceof MouseEvent&&e.shiftKey)},J=e=>{if(!k)return;if(g.lockAspectRatio&&v.value){let t=V(e);if(!t)return;let{x:n,y:r}=t,i=j.x+j.width/2,a=j.y+j.height/2;if(g.cropAsCircle){let e=Math.max(Math.abs(n-i),Math.abs(r-a)),t=e*2;C.value={x:i-e,y:a-e,width:t,height:t}}else{let e=j.width/j.height,t=Math.abs(n-i),r=Math.max(t*2,50),o=r/e;C.value={x:i-r/2,y:a-o/2,width:r,height:o}}L();return}let t=V(e);if(!t)return;let{x:n,y:r}=t,i=n-A.x,a=r-A.y;N=e instanceof MouseEvent&&e.shiftKey;let o={...j};switch(M){case`top-left`:o.x+=i,o.y+=a,o.width-=i,o.height-=a;break;case`top`:o.y+=a,o.height-=a;break;case`top-right`:o.y+=a,o.width+=i,o.height-=a;break;case`right`:o.width+=i;break;case`bottom-right`:o.width+=i,o.height+=a;break;case`bottom`:o.height+=a;break;case`bottom-left`:o.x+=i,o.width-=i,o.height+=a;break;case`left`:o.x+=i,o.width-=i;break}if(o.width<50&&(o.width=50),o.height<50&&(o.height=50),N&&M){let e=j.width/j.height;[`left`,`right`].includes(M)?(o.height=o.width/e,M===`left`&&(o.y=j.y-(o.height-j.height)/2)):[`top`,`bottom`].includes(M)&&(o.width=o.height*e,M===`top`&&(o.x=j.x-(o.width-j.width)/2))}C.value=o,L()},Y=()=>{k&&(Z(),L(),k=!1,M=null)},X=(e,t)=>{if(g.cropAsCircle){let n=C.value.x+C.value.width/2,r=C.value.y+C.value.height/2,i=C.value.width/2,a=e-n,o=t-r;return a*a+o*o<=i*i}else return e>=C.value.x-2&&e<=C.value.x+C.value.width+2&&t>=C.value.y-2&&t<=C.value.y+C.value.height+2},Z=()=>{let e=v.value.width,t=v.value.height;if(C.value.width<50&&(C.value.width=50),C.value.height<50&&(C.value.height=50),g.lockAspectRatio)if(g.cropAsCircle)C.value.height=C.value.width;else{let e=j.width/j.height;C.value.height=C.value.width/e}else if(N){let e=j.width/j.height;C.value.height=C.value.width/e}if(g.cropAsCircle||g.lockAspectRatio){let n=C.value.width/C.value.height;(C.value.width>e||C.value.height>t)&&(C.value.width>C.value.height?(C.value.width=e,C.value.height=e/n):(C.value.height=t,C.value.width=t*n)),C.value.x<0&&(C.value.x=0),C.value.y<0&&(C.value.y=0),C.value.x+C.value.width>e&&(C.value.x=e-C.value.width),C.value.y+C.value.height>t&&(C.value.y=t-C.value.height)}else C.value.x<0&&(C.value.x=0),C.value.y<0&&(C.value.y=0),C.value.width>e&&(C.value.width=e,C.value.x=0),C.value.height>t&&(C.value.height=t,C.value.y=0),C.value.x+C.value.width>e&&(C.value.x=e-C.value.width),C.value.y+C.value.height>t&&(C.value.y=t-C.value.height)},Q=()=>{if(v.value&&y){let e=(v.value.width-b.width*S.x)/2,t=(v.value.height-b.height*S.y)/2,n=(C.value.x-e)/S.x,r=(C.value.y-t)/S.y,i=C.value.width/S.x,a=C.value.height/S.y,o={x:Math.round(n),y:Math.round(r),width:Math.round(i),height:Math.round(a)},s=Math.max(0,Math.min(o.x,b.width)),c=Math.max(0,Math.min(o.y,b.height)),l=Math.min(o.width,b.width-s),u=Math.min(o.height,b.height-c),d=document.createElement(`canvas`);d.width=l,d.height=u;let f=d.getContext(`2d`);f&&(f.drawImage(b,s,c,l,u,0,0,l,u),g.cropAsCircle&&g.outputAsCircle&&(f.globalCompositeOperation=`destination-in`,f.beginPath(),f.arc(l/2,u/2,l/2,0,Math.PI*2),f.closePath(),f.fill(),f.globalCompositeOperation=`source-over`),d.toBlob(e=>{if(e){let t=w.value;t&&URL.revokeObjectURL(t),w.value=URL.createObjectURL(e),T.value=o,_(`crop`,{blob:e,geometry:o})}},`image/jpeg`,.8))}};return(0,r.watch)(()=>g,()=>{Q()},{deep:!0}),(n,i)=>((0,r.openBlock)(),(0,r.createElementBlock)(`div`,a,[(0,r.createElementVNode)(`div`,{class:`canvas-container`,onMousedown:H,onMousemove:U,onMouseup:W,onMouseleave:W,onTouchstart:H,onTouchmove:U,onTouchend:W},[(0,r.createElementVNode)(`canvas`,{ref_key:`canvas`,ref:v},null,512),((0,r.openBlock)(),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(P,e=>(0,r.createElementVNode)(`div`,{key:e.name,class:(0,r.normalizeClass)([`resize-handle`,e.name]),style:(0,r.normalizeStyle)(z.value[e.name]),onMousedown:(0,r.withModifiers)(t=>q(t,e.name),[`stop`]),onTouchstart:(0,r.withModifiers)(t=>q(t,e.name),[`stop`])},null,46,o)),64))],32),e.showPreview&&w.value&&T.value?((0,r.openBlock)(),(0,r.createBlock)(t.t,{key:0,class:`cropped-image-preview`},{default:(0,r.withCtx)(()=>[(0,r.createVNode)(t.t,{is:`ul`,dir:`col`,justify:`center`,gap:`sm`},{default:(0,r.withCtx)(()=>[(0,r.createElementVNode)(`li`,null,[(0,r.createElementVNode)(`strong`,null,(0,r.toDisplayString)(h(`common.X`)),1),(0,r.createTextVNode)(` `+(0,r.toDisplayString)(T.value.x.toFixed(0)),1)]),(0,r.createElementVNode)(`li`,null,[(0,r.createElementVNode)(`strong`,null,(0,r.toDisplayString)(h(`common.Y`)),1),(0,r.createTextVNode)(` `+(0,r.toDisplayString)(T.value.y.toFixed(0)),1)]),(0,r.createElementVNode)(`li`,null,[(0,r.createElementVNode)(`strong`,null,(0,r.toDisplayString)(h(`common.WIDTH`)),1),(0,r.createTextVNode)(` `+(0,r.toDisplayString)(T.value.width.toFixed(0)),1)]),(0,r.createElementVNode)(`li`,null,[(0,r.createElementVNode)(`strong`,null,(0,r.toDisplayString)(h(`common.HEIGHT`)),1),(0,r.createTextVNode)(` `+(0,r.toDisplayString)(T.value.height.toFixed(0)),1)])]),_:1}),(0,r.createElementVNode)(`img`,{src:w.value,alt:h(`common.IMAGE_THUMBNAIL`)},null,8,s)]),_:1})):(0,r.createCommentVNode)(``,!0)]))}}),d=e.t(u,[[`__scopeId`,`data-v-057c9675`]]);Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return d}});
|
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
import { t as e } from "./_plugin-vue_export-helper-C6QCLu9I.js";
|
|
2
|
-
import { t } from "./Grid-BVIhOyQ1.js";
|
|
3
|
-
import { t as n } from "./vue-i18n-DgCNp5tk.js";
|
|
4
|
-
import { Fragment as r, computed as i, createBlock as a, createCommentVNode as o, createElementBlock as s, createElementVNode as c, createTextVNode as l, createVNode as u, defineComponent as d, normalizeClass as f, normalizeStyle as p, onBeforeUnmount as ee, onMounted as te, openBlock as m, ref as h, renderList as ne, toDisplayString as g, watch as _, withCtx as v, withModifiers as y } from "vue";
|
|
5
|
-
//#region src/components/ImageCropper.d.ts
|
|
6
|
-
var b = /* @__PURE__ */ function(e) {
|
|
7
|
-
return e.TopLeft = "top-left", e.Top = "top", e.TopRight = "top-right", e.Right = "right", e.BottomRight = "bottom-right", e.Bottom = "bottom", e.BottomLeft = "bottom-left", e.Left = "left", e;
|
|
8
|
-
}(b || {}), x = { class: "nb-image-cropper" }, S = ["onMousedown", "onTouchstart"], re = ["src", "alt"], C = 700, w = 400, T = /* @__PURE__ */ e(/* @__PURE__ */ d({
|
|
9
|
-
__name: "ImageCropper",
|
|
10
|
-
props: {
|
|
11
|
-
image: {},
|
|
12
|
-
cropAsCircle: {
|
|
13
|
-
type: Boolean,
|
|
14
|
-
default: !1
|
|
15
|
-
},
|
|
16
|
-
outputAsCircle: {
|
|
17
|
-
type: Boolean,
|
|
18
|
-
default: !1
|
|
19
|
-
},
|
|
20
|
-
lockAspectRatio: {
|
|
21
|
-
type: Boolean,
|
|
22
|
-
default: !1
|
|
23
|
-
},
|
|
24
|
-
showPreview: {
|
|
25
|
-
type: Boolean,
|
|
26
|
-
default: !1
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
emits: ["crop"],
|
|
30
|
-
setup(e, { emit: d }) {
|
|
31
|
-
let T = {
|
|
32
|
-
en: {
|
|
33
|
-
X: "X",
|
|
34
|
-
Y: "Y",
|
|
35
|
-
WIDTH: "Width",
|
|
36
|
-
HEIGHT: "Height",
|
|
37
|
-
IMAGE_THUMBNAIL: "Cropped preview"
|
|
38
|
-
},
|
|
39
|
-
pt: {
|
|
40
|
-
X: "X",
|
|
41
|
-
Y: "Y",
|
|
42
|
-
WIDTH: "Largura",
|
|
43
|
-
HEIGHT: "Altura",
|
|
44
|
-
IMAGE_THUMBNAIL: "Pré-visualização recortada"
|
|
45
|
-
}
|
|
46
|
-
}, { t: ie, te: ae, locale: oe } = n({ useScope: "global" });
|
|
47
|
-
function E(e) {
|
|
48
|
-
if (ae(e)) return ie(e);
|
|
49
|
-
let t = e.slice(7);
|
|
50
|
-
return T[String(oe.value).toLowerCase().split("-")[0]]?.[t] ?? T.en[t] ?? e;
|
|
51
|
-
}
|
|
52
|
-
let D = e, O = d, k = h(null), A = null, j = new Image(), M = null, N = {
|
|
53
|
-
x: 1,
|
|
54
|
-
y: 1
|
|
55
|
-
}, P = h({
|
|
56
|
-
x: 50,
|
|
57
|
-
y: 50,
|
|
58
|
-
width: 200,
|
|
59
|
-
height: 200
|
|
60
|
-
}), F = h(null), I = h(null), L = !1, R = !1, z = {
|
|
61
|
-
x: 0,
|
|
62
|
-
y: 0
|
|
63
|
-
}, B = !1, V = {
|
|
64
|
-
x: 0,
|
|
65
|
-
y: 0
|
|
66
|
-
}, H = {
|
|
67
|
-
x: 0,
|
|
68
|
-
y: 0,
|
|
69
|
-
width: 0,
|
|
70
|
-
height: 0
|
|
71
|
-
}, U = null, W = !1, se = [
|
|
72
|
-
{ name: b.TopLeft },
|
|
73
|
-
{ name: b.Top },
|
|
74
|
-
{ name: b.TopRight },
|
|
75
|
-
{ name: b.Right },
|
|
76
|
-
{ name: b.BottomRight },
|
|
77
|
-
{ name: b.Bottom },
|
|
78
|
-
{ name: b.BottomLeft },
|
|
79
|
-
{ name: b.Left }
|
|
80
|
-
], G = () => {
|
|
81
|
-
if (!D.image) {
|
|
82
|
-
console.error("No image file provided");
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
M &&= (URL.revokeObjectURL(M), null), j.onload = () => {
|
|
86
|
-
let { drawWidth: e, drawHeight: t } = ce();
|
|
87
|
-
if (k.value) {
|
|
88
|
-
k.value.width = e, k.value.height = t;
|
|
89
|
-
let n = (k.value.width - j.width * N.x) / 2, r = (k.value.height - j.height * N.y) / 2;
|
|
90
|
-
if (D.cropAsCircle || D.lockAspectRatio) {
|
|
91
|
-
let e = Math.min(j.width * N.x, j.height * N.y) * .5;
|
|
92
|
-
P.value = {
|
|
93
|
-
x: n + (j.width * N.x - e) / 2,
|
|
94
|
-
y: r + (j.height * N.y - e) / 2,
|
|
95
|
-
width: e,
|
|
96
|
-
height: e
|
|
97
|
-
};
|
|
98
|
-
} else P.value = {
|
|
99
|
-
x: n + (j.width * N.x * .5 - j.width * N.x * .25),
|
|
100
|
-
y: r + (j.height * N.y * .5 - j.height * N.y * .25),
|
|
101
|
-
width: j.width * N.x * .5,
|
|
102
|
-
height: j.height * N.y * .5
|
|
103
|
-
};
|
|
104
|
-
K(), $();
|
|
105
|
-
}
|
|
106
|
-
}, j.onerror = () => {
|
|
107
|
-
console.error("Failed to load image");
|
|
108
|
-
}, M = URL.createObjectURL(D.image), j.src = M;
|
|
109
|
-
};
|
|
110
|
-
te(() => {
|
|
111
|
-
k.value && (A = k.value.getContext("2d"), A && (A.imageSmoothingEnabled = !0, A.imageSmoothingQuality = "high"), D.image && G());
|
|
112
|
-
}), ee(() => {
|
|
113
|
-
M &&= (URL.revokeObjectURL(M), null);
|
|
114
|
-
let e = F.value;
|
|
115
|
-
e && (URL.revokeObjectURL(e), F.value = null);
|
|
116
|
-
}), _(() => D.image, (e) => {
|
|
117
|
-
e && G();
|
|
118
|
-
}), _(() => [
|
|
119
|
-
D.cropAsCircle,
|
|
120
|
-
D.outputAsCircle,
|
|
121
|
-
D.lockAspectRatio
|
|
122
|
-
], () => {
|
|
123
|
-
k.value && A && K();
|
|
124
|
-
});
|
|
125
|
-
let ce = () => {
|
|
126
|
-
let e = j.width / j.height, t = C, n = w;
|
|
127
|
-
return e > C / w ? n = C / e : t = w * e, N.x = t / j.width, N.y = n / j.height, {
|
|
128
|
-
drawWidth: t,
|
|
129
|
-
drawHeight: n
|
|
130
|
-
};
|
|
131
|
-
}, K = () => {
|
|
132
|
-
if (A && k.value) {
|
|
133
|
-
A.clearRect(0, 0, k.value.width, k.value.height);
|
|
134
|
-
let e = (k.value.width - j.width * N.x) / 2, t = (k.value.height - j.height * N.y) / 2;
|
|
135
|
-
A.drawImage(j, 0, 0, j.width, j.height, e, t, j.width * N.x, j.height * N.y), le();
|
|
136
|
-
}
|
|
137
|
-
}, le = () => {
|
|
138
|
-
A && k.value && (A.save(), A.beginPath(), D.cropAsCircle ? A.arc(P.value.x + P.value.width / 2, P.value.y + P.value.height / 2, P.value.width / 2, 0, Math.PI * 2) : A.rect(P.value.x, P.value.y, P.value.width, P.value.height), A.rect(0, 0, k.value.width, k.value.height), A.clip("evenodd"), A.fillStyle = "rgba(0, 0, 0, 0.5)", A.fillRect(0, 0, k.value.width, k.value.height), A.restore(), A.save(), A.strokeStyle = "rgba(255, 255, 255, 0.8)", A.lineWidth = 1, A.setLineDash([5, 5]), A.imageSmoothingEnabled = !1, D.cropAsCircle ? (A.beginPath(), A.arc(P.value.x + P.value.width / 2, P.value.y + P.value.height / 2, P.value.width / 2, 0, Math.PI * 2), A.stroke()) : A.strokeRect(P.value.x, P.value.y, P.value.width, P.value.height), A.restore());
|
|
139
|
-
}, ue = i(() => {
|
|
140
|
-
if (D.cropAsCircle) {
|
|
141
|
-
let e = P.value.x + P.value.width / 2, t = P.value.y + P.value.height / 2, n = P.value.width / 2;
|
|
142
|
-
return {
|
|
143
|
-
"top-left": {
|
|
144
|
-
left: `${e - n - 5}px`,
|
|
145
|
-
top: `${t - n - 5}px`
|
|
146
|
-
},
|
|
147
|
-
top: {
|
|
148
|
-
left: `${e - 5}px`,
|
|
149
|
-
top: `${t - n - 5}px`
|
|
150
|
-
},
|
|
151
|
-
"top-right": {
|
|
152
|
-
left: `${e + n - 5}px`,
|
|
153
|
-
top: `${t - n - 5}px`
|
|
154
|
-
},
|
|
155
|
-
right: {
|
|
156
|
-
left: `${e + n - 5}px`,
|
|
157
|
-
top: `${t - 5}px`
|
|
158
|
-
},
|
|
159
|
-
"bottom-right": {
|
|
160
|
-
left: `${e + n - 5}px`,
|
|
161
|
-
top: `${t + n - 5}px`
|
|
162
|
-
},
|
|
163
|
-
bottom: {
|
|
164
|
-
left: `${e - 5}px`,
|
|
165
|
-
top: `${t + n - 5}px`
|
|
166
|
-
},
|
|
167
|
-
"bottom-left": {
|
|
168
|
-
left: `${e - n - 5}px`,
|
|
169
|
-
top: `${t + n - 5}px`
|
|
170
|
-
},
|
|
171
|
-
left: {
|
|
172
|
-
left: `${e - n - 5}px`,
|
|
173
|
-
top: `${t - 5}px`
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
} else return {
|
|
177
|
-
"top-left": {
|
|
178
|
-
left: `${P.value.x - 5}px`,
|
|
179
|
-
top: `${P.value.y - 5}px`
|
|
180
|
-
},
|
|
181
|
-
top: {
|
|
182
|
-
left: `${P.value.x + P.value.width / 2 - 5}px`,
|
|
183
|
-
top: `${P.value.y - 5}px`
|
|
184
|
-
},
|
|
185
|
-
"top-right": {
|
|
186
|
-
left: `${P.value.x + P.value.width - 5}px`,
|
|
187
|
-
top: `${P.value.y - 5}px`
|
|
188
|
-
},
|
|
189
|
-
right: {
|
|
190
|
-
left: `${P.value.x + P.value.width - 5}px`,
|
|
191
|
-
top: `${P.value.y + P.value.height / 2 - 5}px`
|
|
192
|
-
},
|
|
193
|
-
"bottom-right": {
|
|
194
|
-
left: `${P.value.x + P.value.width - 5}px`,
|
|
195
|
-
top: `${P.value.y + P.value.height - 5}px`
|
|
196
|
-
},
|
|
197
|
-
bottom: {
|
|
198
|
-
left: `${P.value.x + P.value.width / 2 - 5}px`,
|
|
199
|
-
top: `${P.value.y + P.value.height - 5}px`
|
|
200
|
-
},
|
|
201
|
-
"bottom-left": {
|
|
202
|
-
left: `${P.value.x - 5}px`,
|
|
203
|
-
top: `${P.value.y + P.value.height - 5}px`
|
|
204
|
-
},
|
|
205
|
-
left: {
|
|
206
|
-
left: `${P.value.x - 5}px`,
|
|
207
|
-
top: `${P.value.y + P.value.height / 2 - 5}px`
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
}), de = (e) => {
|
|
211
|
-
if ("touches" in e && e.touches.length > 0) {
|
|
212
|
-
let t = e.touches[0];
|
|
213
|
-
return {
|
|
214
|
-
clientX: t.clientX,
|
|
215
|
-
clientY: t.clientY
|
|
216
|
-
};
|
|
217
|
-
} else if ("clientX" in e && "clientY" in e) return {
|
|
218
|
-
clientX: e.clientX,
|
|
219
|
-
clientY: e.clientY
|
|
220
|
-
};
|
|
221
|
-
return {
|
|
222
|
-
clientX: 0,
|
|
223
|
-
clientY: 0
|
|
224
|
-
};
|
|
225
|
-
}, q = (e) => {
|
|
226
|
-
let t = k.value;
|
|
227
|
-
if (!t) return null;
|
|
228
|
-
let { clientX: n, clientY: r } = de(e), { left: i, top: a } = t.getBoundingClientRect();
|
|
229
|
-
return {
|
|
230
|
-
x: n - i,
|
|
231
|
-
y: r - a
|
|
232
|
-
};
|
|
233
|
-
}, J = (e) => {
|
|
234
|
-
e.preventDefault();
|
|
235
|
-
let t = q(e);
|
|
236
|
-
if (!t) return;
|
|
237
|
-
let { x: n, y: r } = t;
|
|
238
|
-
ge(n, r) && (R = !0, L = !0, z = {
|
|
239
|
-
x: n - P.value.x,
|
|
240
|
-
y: r - P.value.y
|
|
241
|
-
});
|
|
242
|
-
}, Y = (e) => {
|
|
243
|
-
R ? fe(e) : B && me(e);
|
|
244
|
-
}, X = () => {
|
|
245
|
-
R && (pe(), R = !1, $()), B && (he(), $()), L = !1, R = !1;
|
|
246
|
-
}, fe = (e) => {
|
|
247
|
-
if (L) {
|
|
248
|
-
let t = q(e);
|
|
249
|
-
if (!t) return;
|
|
250
|
-
let { x: n, y: r } = t;
|
|
251
|
-
P.value.x = Math.floor(n - z.x), P.value.y = Math.floor(r - z.y), K();
|
|
252
|
-
}
|
|
253
|
-
}, pe = () => {
|
|
254
|
-
L &&= (Q(), K(), !1);
|
|
255
|
-
}, Z = (e, t) => {
|
|
256
|
-
e.preventDefault();
|
|
257
|
-
let n = q(e);
|
|
258
|
-
n && (B = !0, U = t, V = {
|
|
259
|
-
x: n.x,
|
|
260
|
-
y: n.y
|
|
261
|
-
}, H = { ...P.value }, W = e instanceof MouseEvent && e.shiftKey);
|
|
262
|
-
}, me = (e) => {
|
|
263
|
-
if (!B) return;
|
|
264
|
-
if (D.lockAspectRatio && k.value) {
|
|
265
|
-
let t = q(e);
|
|
266
|
-
if (!t) return;
|
|
267
|
-
let { x: n, y: r } = t, i = H.x + H.width / 2, a = H.y + H.height / 2;
|
|
268
|
-
if (D.cropAsCircle) {
|
|
269
|
-
let e = Math.max(Math.abs(n - i), Math.abs(r - a)), t = e * 2;
|
|
270
|
-
P.value = {
|
|
271
|
-
x: i - e,
|
|
272
|
-
y: a - e,
|
|
273
|
-
width: t,
|
|
274
|
-
height: t
|
|
275
|
-
};
|
|
276
|
-
} else {
|
|
277
|
-
let e = H.width / H.height, t = Math.abs(n - i), r = Math.max(t * 2, 50), o = r / e;
|
|
278
|
-
P.value = {
|
|
279
|
-
x: i - r / 2,
|
|
280
|
-
y: a - o / 2,
|
|
281
|
-
width: r,
|
|
282
|
-
height: o
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
K();
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
let t = q(e);
|
|
289
|
-
if (!t) return;
|
|
290
|
-
let { x: n, y: r } = t, i = n - V.x, a = r - V.y;
|
|
291
|
-
W = e instanceof MouseEvent && e.shiftKey;
|
|
292
|
-
let o = { ...H };
|
|
293
|
-
switch (U) {
|
|
294
|
-
case "top-left":
|
|
295
|
-
o.x += i, o.y += a, o.width -= i, o.height -= a;
|
|
296
|
-
break;
|
|
297
|
-
case "top":
|
|
298
|
-
o.y += a, o.height -= a;
|
|
299
|
-
break;
|
|
300
|
-
case "top-right":
|
|
301
|
-
o.y += a, o.width += i, o.height -= a;
|
|
302
|
-
break;
|
|
303
|
-
case "right":
|
|
304
|
-
o.width += i;
|
|
305
|
-
break;
|
|
306
|
-
case "bottom-right":
|
|
307
|
-
o.width += i, o.height += a;
|
|
308
|
-
break;
|
|
309
|
-
case "bottom":
|
|
310
|
-
o.height += a;
|
|
311
|
-
break;
|
|
312
|
-
case "bottom-left":
|
|
313
|
-
o.x += i, o.width -= i, o.height += a;
|
|
314
|
-
break;
|
|
315
|
-
case "left":
|
|
316
|
-
o.x += i, o.width -= i;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
if (o.width < 50 && (o.width = 50), o.height < 50 && (o.height = 50), W && U) {
|
|
320
|
-
let e = H.width / H.height;
|
|
321
|
-
["left", "right"].includes(U) ? (o.height = o.width / e, U === "left" && (o.y = H.y - (o.height - H.height) / 2)) : ["top", "bottom"].includes(U) && (o.width = o.height * e, U === "top" && (o.x = H.x - (o.width - H.width) / 2));
|
|
322
|
-
}
|
|
323
|
-
P.value = o, K();
|
|
324
|
-
}, he = () => {
|
|
325
|
-
B && (Q(), K(), B = !1, U = null);
|
|
326
|
-
}, ge = (e, t) => {
|
|
327
|
-
if (D.cropAsCircle) {
|
|
328
|
-
let n = P.value.x + P.value.width / 2, r = P.value.y + P.value.height / 2, i = P.value.width / 2, a = e - n, o = t - r;
|
|
329
|
-
return a * a + o * o <= i * i;
|
|
330
|
-
} else return e >= P.value.x - 2 && e <= P.value.x + P.value.width + 2 && t >= P.value.y - 2 && t <= P.value.y + P.value.height + 2;
|
|
331
|
-
}, Q = () => {
|
|
332
|
-
let e = k.value.width, t = k.value.height;
|
|
333
|
-
if (P.value.width < 50 && (P.value.width = 50), P.value.height < 50 && (P.value.height = 50), D.lockAspectRatio) if (D.cropAsCircle) P.value.height = P.value.width;
|
|
334
|
-
else {
|
|
335
|
-
let e = H.width / H.height;
|
|
336
|
-
P.value.height = P.value.width / e;
|
|
337
|
-
}
|
|
338
|
-
else if (W) {
|
|
339
|
-
let e = H.width / H.height;
|
|
340
|
-
P.value.height = P.value.width / e;
|
|
341
|
-
}
|
|
342
|
-
if (D.cropAsCircle || D.lockAspectRatio) {
|
|
343
|
-
let n = P.value.width / P.value.height;
|
|
344
|
-
(P.value.width > e || P.value.height > t) && (P.value.width > P.value.height ? (P.value.width = e, P.value.height = e / n) : (P.value.height = t, P.value.width = t * n)), P.value.x < 0 && (P.value.x = 0), P.value.y < 0 && (P.value.y = 0), P.value.x + P.value.width > e && (P.value.x = e - P.value.width), P.value.y + P.value.height > t && (P.value.y = t - P.value.height);
|
|
345
|
-
} else P.value.x < 0 && (P.value.x = 0), P.value.y < 0 && (P.value.y = 0), P.value.width > e && (P.value.width = e, P.value.x = 0), P.value.height > t && (P.value.height = t, P.value.y = 0), P.value.x + P.value.width > e && (P.value.x = e - P.value.width), P.value.y + P.value.height > t && (P.value.y = t - P.value.height);
|
|
346
|
-
}, $ = () => {
|
|
347
|
-
if (k.value && A) {
|
|
348
|
-
let e = (k.value.width - j.width * N.x) / 2, t = (k.value.height - j.height * N.y) / 2, n = (P.value.x - e) / N.x, r = (P.value.y - t) / N.y, i = P.value.width / N.x, a = P.value.height / N.y, o = {
|
|
349
|
-
x: Math.round(n),
|
|
350
|
-
y: Math.round(r),
|
|
351
|
-
width: Math.round(i),
|
|
352
|
-
height: Math.round(a)
|
|
353
|
-
}, s = Math.max(0, Math.min(o.x, j.width)), c = Math.max(0, Math.min(o.y, j.height)), l = Math.min(o.width, j.width - s), u = Math.min(o.height, j.height - c), d = document.createElement("canvas");
|
|
354
|
-
d.width = l, d.height = u;
|
|
355
|
-
let f = d.getContext("2d");
|
|
356
|
-
f && (f.drawImage(j, s, c, l, u, 0, 0, l, u), D.cropAsCircle && D.outputAsCircle && (f.globalCompositeOperation = "destination-in", f.beginPath(), f.arc(l / 2, u / 2, l / 2, 0, Math.PI * 2), f.closePath(), f.fill(), f.globalCompositeOperation = "source-over"), d.toBlob((e) => {
|
|
357
|
-
if (e) {
|
|
358
|
-
let t = F.value;
|
|
359
|
-
t && URL.revokeObjectURL(t), F.value = URL.createObjectURL(e), I.value = o, O("crop", {
|
|
360
|
-
blob: e,
|
|
361
|
-
geometry: o
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}, "image/jpeg", .8));
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
return _(() => D, () => {
|
|
368
|
-
$();
|
|
369
|
-
}, { deep: !0 }), (n, i) => (m(), s("div", x, [c("div", {
|
|
370
|
-
class: "canvas-container",
|
|
371
|
-
onMousedown: J,
|
|
372
|
-
onMousemove: Y,
|
|
373
|
-
onMouseup: X,
|
|
374
|
-
onMouseleave: X,
|
|
375
|
-
onTouchstart: J,
|
|
376
|
-
onTouchmove: Y,
|
|
377
|
-
onTouchend: X
|
|
378
|
-
}, [c("canvas", {
|
|
379
|
-
ref_key: "canvas",
|
|
380
|
-
ref: k
|
|
381
|
-
}, null, 512), (m(), s(r, null, ne(se, (e) => c("div", {
|
|
382
|
-
key: e.name,
|
|
383
|
-
class: f(["resize-handle", e.name]),
|
|
384
|
-
style: p(ue.value[e.name]),
|
|
385
|
-
onMousedown: y((t) => Z(t, e.name), ["stop"]),
|
|
386
|
-
onTouchstart: y((t) => Z(t, e.name), ["stop"])
|
|
387
|
-
}, null, 46, S)), 64))], 32), e.showPreview && F.value && I.value ? (m(), a(t, {
|
|
388
|
-
key: 0,
|
|
389
|
-
class: "cropped-image-preview"
|
|
390
|
-
}, {
|
|
391
|
-
default: v(() => [u(t, {
|
|
392
|
-
is: "ul",
|
|
393
|
-
dir: "col",
|
|
394
|
-
justify: "center",
|
|
395
|
-
gap: "sm"
|
|
396
|
-
}, {
|
|
397
|
-
default: v(() => [
|
|
398
|
-
c("li", null, [c("strong", null, g(E("common.X")), 1), l(" " + g(I.value.x.toFixed(0)), 1)]),
|
|
399
|
-
c("li", null, [c("strong", null, g(E("common.Y")), 1), l(" " + g(I.value.y.toFixed(0)), 1)]),
|
|
400
|
-
c("li", null, [c("strong", null, g(E("common.WIDTH")), 1), l(" " + g(I.value.width.toFixed(0)), 1)]),
|
|
401
|
-
c("li", null, [c("strong", null, g(E("common.HEIGHT")), 1), l(" " + g(I.value.height.toFixed(0)), 1)])
|
|
402
|
-
]),
|
|
403
|
-
_: 1
|
|
404
|
-
}), c("img", {
|
|
405
|
-
src: F.value,
|
|
406
|
-
alt: E("common.IMAGE_THUMBNAIL")
|
|
407
|
-
}, null, 8, re)]),
|
|
408
|
-
_: 1
|
|
409
|
-
})) : o("", !0)]));
|
|
410
|
-
}
|
|
411
|
-
}), [["__scopeId", "data-v-057c9675"]]);
|
|
412
|
-
//#endregion
|
|
413
|
-
export { b as n, T as t };
|