@webority/ui-elements 0.37.0 → 0.38.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/WuiAutocomplete-Comrnbmf.js +13 -0
- package/dist/WuiCommandPalette-CKna1GlO.js +2 -0
- package/dist/WuiConsentBanner-CFll7vxN.js +201 -0
- package/dist/WuiContextMenu-CBy0O4HT.js +1 -0
- package/dist/WuiCountrySelect-oLBUHvMM.js +1 -0
- package/dist/WuiDatePicker-nB1B3eWW.js +31 -0
- package/dist/WuiDateRange-Di5YE9mg.js +25 -0
- package/dist/WuiDock-BD2HgMmP.js +1 -0
- package/dist/WuiImageCrop-Cr3D2iPo.js +17 -0
- package/dist/WuiMultiSelect-BUw-7apM.js +25 -0
- package/dist/WuiOtp-BbO_75RB.js +14 -0
- package/dist/WuiPhone-GJglNelp.js +15 -0
- package/dist/WuiSelect-DvtN4qC2.js +14 -0
- package/dist/WuiSlider-Br6V2amU.js +49 -0
- package/dist/WuiSortable-Bd7Fz5Ox.js +1 -0
- package/dist/WuiTagInput-DzEZooIn.js +6 -0
- package/dist/WuiTimePicker-Bolpp93P.js +9 -0
- package/dist/WuiTour-DiKZEWeb.js +15 -0
- package/dist/WuiTree-SA0QU9AF.js +1 -0
- package/dist/WuiWizardStep-DIHxrXn9.js +1 -0
- package/dist/anchorOverlay-WcDeH46q.js +1 -0
- package/dist/calendarMath-BC2wGCD-.js +1 -0
- package/dist/countries-CvmZ2xpG.js +1 -0
- package/dist/elementBase-BlsR4tqa.js +1 -0
- package/dist/elements/autocomplete.js +1 -6
- package/dist/elements/command-palette.js +1 -6
- package/dist/elements/consent-banner.js +1 -6
- package/dist/elements/context-menu.js +1 -6
- package/dist/elements/country-select.js +1 -6
- package/dist/elements/date-range.js +1 -6
- package/dist/elements/datepicker.js +1 -6
- package/dist/elements/dock.js +1 -6
- package/dist/elements/image-crop.js +1 -6
- package/dist/elements/kanban.js +1 -6
- package/dist/elements/multiselect.js +1 -6
- package/dist/elements/otp.js +1 -6
- package/dist/elements/phone.js +1 -6
- package/dist/elements/select.js +1 -6
- package/dist/elements/slider.js +1 -6
- package/dist/elements/sortable.js +1 -6
- package/dist/elements/status-icon.js +1 -6
- package/dist/elements/taginput.js +1 -6
- package/dist/elements/timepicker.js +1 -6
- package/dist/elements/tour.js +1 -6
- package/dist/elements/tree.js +1 -6
- package/dist/elements/wizard.js +1 -5
- package/dist/examples.mobile.json-GS1_MGh9.js +1 -0
- package/dist/fileViewerImage-Y9QBn2Rj.js +6 -0
- package/dist/fileViewerMedia-CaJaVnjE.js +1 -0
- package/dist/fileViewerPdf-BN0zuehw.js +19 -0
- package/dist/fileViewerUi-DasgDsU-.js +1 -0
- package/dist/focusOrigin-2imUSs-u.js +1 -0
- package/dist/formMirror-BgY7zkC3.js +1 -0
- package/dist/formatters-BAE__8ye.js +1 -0
- package/dist/helpers.js +1 -5
- package/dist/iconGlyphs.g-CUm_mfze.js +1 -0
- package/dist/kanban-CdELdS3U.js +1 -0
- package/dist/listboxKeyNav-DMIvs9d6.js +1 -0
- package/dist/max-CNrKnpEj.js +17 -0
- package/dist/optionLabel-DsX2fhWs.js +1 -0
- package/dist/statusIcons-2X4iGkKL.js +10 -0
- package/dist/textMatch-wdY7XLIc.js +1 -0
- package/dist/themeTransition-lkmQm8FR.js +1 -0
- package/dist/tokenCommit-BKckxgtg.js +2 -0
- package/dist/ui-calendar.global.js +1 -1
- package/dist/ui-calendar.js +1 -9905
- package/dist/ui-chart.js +21 -34563
- package/dist/ui-chat-core.js +10 -347
- package/dist/ui-chat.js +10 -1066
- package/dist/ui-elements.global.js +52 -53
- package/dist/ui-elements.js +1 -692
- package/dist/ui-file-viewer.js +1 -311
- package/dist/ui-rich-text.js +193 -16887
- package/dist/wuiHttp-BC8co934.js +1 -0
- package/package.json +5 -7
- package/dist/WuiAutocomplete-ByxnwJNQ.js +0 -283
- package/dist/WuiCommandPalette-CtZ04JxZ.js +0 -130
- package/dist/WuiConsentBanner-oVe-jxCO.js +0 -399
- package/dist/WuiContextMenu-Bx_U2X3t.js +0 -211
- package/dist/WuiCountrySelect-CUAwKnL9.js +0 -28
- package/dist/WuiDatePicker-DkNbc-z7.js +0 -325
- package/dist/WuiDateRange-BocnVO6L.js +0 -233
- package/dist/WuiDock-BSDY9g8Q.js +0 -57
- package/dist/WuiImageCrop-1yaAONTk.js +0 -462
- package/dist/WuiMultiSelect-BrCGRNCt.js +0 -416
- package/dist/WuiOtp-D8-4Pqil.js +0 -128
- package/dist/WuiPhone-BvbhiP2r.js +0 -731
- package/dist/WuiSelect-BXrpiuXG.js +0 -214
- package/dist/WuiSlider-BcU0psYf.js +0 -256
- package/dist/WuiSortable-JjJqstSU.js +0 -280
- package/dist/WuiTagInput-D1ay3OcL.js +0 -158
- package/dist/WuiTimePicker-C7n-VFGt.js +0 -370
- package/dist/WuiTour-R5O9l--J.js +0 -205
- package/dist/WuiTree-DXP7pGeI.js +0 -393
- package/dist/WuiWizardStep-BU5w9_Ds.js +0 -221
- package/dist/anchorOverlay-DluGZ8ef.js +0 -23
- package/dist/calendarMath-BAF2Jkg_.js +0 -42
- package/dist/countries-B-M_LTgS.js +0 -1234
- package/dist/elementBase-Bg1xpvup.js +0 -9
- package/dist/examples.mobile.json-BMXTGiGC.js +0 -250
- package/dist/fileViewerImage-Dky4nQZS.js +0 -185
- package/dist/fileViewerMedia-DPk_YcvC.js +0 -133
- package/dist/fileViewerPdf-BnIsj-J-.js +0 -15799
- package/dist/fileViewerUi-R6hlcShk.js +0 -272
- package/dist/formMirror-jGf5M4gk.js +0 -29
- package/dist/formatters-DusKbTyV.js +0 -138
- package/dist/iconGlyphs.g-Cpg1BUHm.js +0 -215
- package/dist/kanban-BIiEMkTK.js +0 -985
- package/dist/listboxKeyNav-zts_8d5e.js +0 -36
- package/dist/max-BDKx469G.js +0 -14478
- package/dist/optionLabel-Dn-I7zyp.js +0 -16
- package/dist/statusIcons-C3zjycpa.js +0 -37
- package/dist/textMatch-DEUjlkdy.js +0 -27
- package/dist/themeTransition-BpCuMnjk.js +0 -589
- package/dist/tokenCommit-VWz-2jEf.js +0 -20
- package/dist/wuiHttp-oeHs7X_c.js +0 -118
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
import { t as e } from "./elementBase-Bg1xpvup.js";
|
|
2
|
-
var t = 4096, n = [
|
|
3
|
-
.92,
|
|
4
|
-
.8,
|
|
5
|
-
.65,
|
|
6
|
-
.5
|
|
7
|
-
], r = .8, i = 8;
|
|
8
|
-
function a(e) {
|
|
9
|
-
if (e == null || e === "" || e === "free") return null;
|
|
10
|
-
let t = typeof e == "number" ? e : Number(e);
|
|
11
|
-
return Number.isFinite(t) && t > 0 ? t : null;
|
|
12
|
-
}
|
|
13
|
-
function o(e, t, n) {
|
|
14
|
-
if (!n) return {
|
|
15
|
-
x: 0,
|
|
16
|
-
y: 0,
|
|
17
|
-
w: e,
|
|
18
|
-
h: t
|
|
19
|
-
};
|
|
20
|
-
let r = e, i = r / n;
|
|
21
|
-
return i > t && (i = t, r = i * n), {
|
|
22
|
-
x: (e - r) / 2,
|
|
23
|
-
y: (t - i) / 2,
|
|
24
|
-
w: r,
|
|
25
|
-
h: i
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function s(e, t, n) {
|
|
29
|
-
return {
|
|
30
|
-
...e,
|
|
31
|
-
x: Math.min(Math.max(e.x, 0), Math.max(t - e.w, 0)),
|
|
32
|
-
y: Math.min(Math.max(e.y, 0), Math.max(n - e.h, 0))
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function c(e, t, n, r, i) {
|
|
36
|
-
return s({
|
|
37
|
-
...e,
|
|
38
|
-
x: e.x + t,
|
|
39
|
-
y: e.y + n
|
|
40
|
-
}, r, i);
|
|
41
|
-
}
|
|
42
|
-
function l(e, t) {
|
|
43
|
-
return Math.min(32, e, t);
|
|
44
|
-
}
|
|
45
|
-
function u(e, t) {
|
|
46
|
-
return t.w / e.w;
|
|
47
|
-
}
|
|
48
|
-
function d(e, t) {
|
|
49
|
-
return Math.max(4, u(e, t));
|
|
50
|
-
}
|
|
51
|
-
function f(e, t, n, r, i) {
|
|
52
|
-
let a = Math.min(Math.max(n, 1), d(e, t)), o = e.h / e.w, c = Math.min(r, i / o), u = Math.min(Math.max(l(r, i), l(r, i) / o), c), f = Math.min(Math.max(t.w / a, u), c), p = f * o, m = e.x + e.w / 2, h = e.y + e.h / 2;
|
|
53
|
-
return s({
|
|
54
|
-
x: m - f / 2,
|
|
55
|
-
y: h - p / 2,
|
|
56
|
-
w: f,
|
|
57
|
-
h: p
|
|
58
|
-
}, r, i);
|
|
59
|
-
}
|
|
60
|
-
var p = [
|
|
61
|
-
"nw",
|
|
62
|
-
"ne",
|
|
63
|
-
"sw",
|
|
64
|
-
"se"
|
|
65
|
-
];
|
|
66
|
-
function m(e, t, n, r, i, a) {
|
|
67
|
-
let o = l(i, a), s = t.endsWith("w"), c = t.startsWith("n"), u = s ? e.x + e.w : e.x, d = c ? e.y + e.h : e.y, f = Math.min(Math.max(n, 0), i), p = Math.min(Math.max(r, 0), a);
|
|
68
|
-
return f = s ? Math.min(f, u - o) : Math.max(f, u + o), p = c ? Math.min(p, d - o) : Math.max(p, d + o), {
|
|
69
|
-
x: Math.min(f, u),
|
|
70
|
-
y: Math.min(p, d),
|
|
71
|
-
w: Math.abs(f - u),
|
|
72
|
-
h: Math.abs(p - d)
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function h(e, n = t) {
|
|
76
|
-
let r = Math.min(1, n / Math.max(e.w, e.h));
|
|
77
|
-
return {
|
|
78
|
-
width: Math.max(1, Math.round(e.w * r)),
|
|
79
|
-
height: Math.max(1, Math.round(e.h * r))
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function g(e, t) {
|
|
83
|
-
let n = t / Math.max(e.w, e.h);
|
|
84
|
-
return {
|
|
85
|
-
width: Math.max(1, Math.round(e.w * n)),
|
|
86
|
-
height: Math.max(1, Math.round(e.h * n))
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function _(e, t, n) {
|
|
90
|
-
return n % 180 == 0 ? {
|
|
91
|
-
w: e,
|
|
92
|
-
h: t
|
|
93
|
-
} : {
|
|
94
|
-
w: t,
|
|
95
|
-
h: e
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function v(e, t, n) {
|
|
99
|
-
return s({
|
|
100
|
-
x: n - (e.y + e.h),
|
|
101
|
-
y: e.x,
|
|
102
|
-
w: e.h,
|
|
103
|
-
h: e.w
|
|
104
|
-
}, n, t);
|
|
105
|
-
}
|
|
106
|
-
function y(e) {
|
|
107
|
-
return String(e || "").split(/[\s,]+/).map(Number).filter((e) => Number.isInteger(e) && e > 0);
|
|
108
|
-
}
|
|
109
|
-
var b = [
|
|
110
|
-
"image/png",
|
|
111
|
-
"image/jpeg",
|
|
112
|
-
"image/webp"
|
|
113
|
-
], x = {
|
|
114
|
-
"image/png": ".png",
|
|
115
|
-
"image/jpeg": ".jpg",
|
|
116
|
-
"image/webp": ".webp"
|
|
117
|
-
};
|
|
118
|
-
function S(e) {
|
|
119
|
-
let t = String(e || "").toLowerCase();
|
|
120
|
-
return b.includes(t) ? t : "image/png";
|
|
121
|
-
}
|
|
122
|
-
function C(e, t) {
|
|
123
|
-
let n = String(e || "image"), r = x[t];
|
|
124
|
-
return (t === "image/jpeg" ? /\.jpe?g$/i.test(n) : n.toLowerCase().endsWith(r)) ? n : `${n.replace(/\.[^./\\]+$/, "") || "image"}${r}`;
|
|
125
|
-
}
|
|
126
|
-
async function w(e, { width: t, height: a, type: o, maxBytes: s }) {
|
|
127
|
-
let c = o, l = t, u = a, d = null;
|
|
128
|
-
for (let t = 0; t <= i; t++) {
|
|
129
|
-
let i = c === "image/png" ? [void 0] : t === 0 ? n : [n[1]];
|
|
130
|
-
for (let t of i) {
|
|
131
|
-
if (d = await e(l, u, c, t), !d || (d.type && d.type !== c && (c = d.type), !(s > 0) || d.size <= s)) return d;
|
|
132
|
-
if (c === "image/png") break;
|
|
133
|
-
}
|
|
134
|
-
l = Math.max(1, Math.round(l * r)), u = Math.max(1, Math.round(u * r));
|
|
135
|
-
}
|
|
136
|
-
return d;
|
|
137
|
-
}
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/WuiImageCrop.js
|
|
140
|
-
var T = .05, E = .2, D = {
|
|
141
|
-
w: 320,
|
|
142
|
-
h: 240
|
|
143
|
-
}, O = {
|
|
144
|
-
nw: "top left",
|
|
145
|
-
ne: "top right",
|
|
146
|
-
sw: "bottom left",
|
|
147
|
-
se: "bottom right"
|
|
148
|
-
}, k = "<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" aria-hidden=\"true\"><path d=\"M5 12h14\"/></svg>", A = "<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" aria-hidden=\"true\"><path d=\"M5 12h14M12 5v14\"/></svg>", j = "<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8\"/><path d=\"M21 3v5h-5\"/></svg>", M = "<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8\"/><path d=\"M3 3v5h5\"/></svg>", N = (e, t) => Math.hypot(e.x - t.x, e.y - t.y), P = class extends e {
|
|
149
|
-
static get observedAttributes() {
|
|
150
|
-
return [
|
|
151
|
-
"src",
|
|
152
|
-
"aspect",
|
|
153
|
-
"round",
|
|
154
|
-
"rotatable",
|
|
155
|
-
"previews"
|
|
156
|
-
];
|
|
157
|
-
}
|
|
158
|
-
constructor() {
|
|
159
|
-
super(), this._rect = null, this._base = null, this._natural = null, this._source = null, this._rotation = 0, this._drag = null, this._pointers = /* @__PURE__ */ new Map(), this._pinch = null, this._previewPending = !1, this._resizeObserver = null;
|
|
160
|
-
}
|
|
161
|
-
get src() {
|
|
162
|
-
return this.getAttribute("src") || "";
|
|
163
|
-
}
|
|
164
|
-
set src(e) {
|
|
165
|
-
e == null || e === "" ? this.removeAttribute("src") : this.setAttribute("src", String(e));
|
|
166
|
-
}
|
|
167
|
-
get aspect() {
|
|
168
|
-
return a(this.getAttribute("aspect"));
|
|
169
|
-
}
|
|
170
|
-
set aspect(e) {
|
|
171
|
-
e == null || e === "" ? this.removeAttribute("aspect") : this.setAttribute("aspect", String(e));
|
|
172
|
-
}
|
|
173
|
-
get round() {
|
|
174
|
-
return this.hasAttribute("round");
|
|
175
|
-
}
|
|
176
|
-
set round(e) {
|
|
177
|
-
this.toggleAttribute("round", !!e);
|
|
178
|
-
}
|
|
179
|
-
get rotatable() {
|
|
180
|
-
return this.hasAttribute("rotatable");
|
|
181
|
-
}
|
|
182
|
-
set rotatable(e) {
|
|
183
|
-
this.toggleAttribute("rotatable", !!e);
|
|
184
|
-
}
|
|
185
|
-
get previews() {
|
|
186
|
-
return this.getAttribute("previews") || "";
|
|
187
|
-
}
|
|
188
|
-
set previews(e) {
|
|
189
|
-
e == null || e === "" ? this.removeAttribute("previews") : this.setAttribute("previews", Array.isArray(e) ? e.join(" ") : String(e));
|
|
190
|
-
}
|
|
191
|
-
get rect() {
|
|
192
|
-
return this._rect ? { ...this._rect } : null;
|
|
193
|
-
}
|
|
194
|
-
get rotation() {
|
|
195
|
-
return this._rotation;
|
|
196
|
-
}
|
|
197
|
-
set rotation(e) {
|
|
198
|
-
if (!this._rect) return;
|
|
199
|
-
let t = (Math.round(Number(e) / 90) * 90 % 360 + 360) % 360;
|
|
200
|
-
if (!Number.isNaN(t)) for (; this._rotation !== t;) this.rotate();
|
|
201
|
-
}
|
|
202
|
-
get zoom() {
|
|
203
|
-
return this._rect ? u(this._rect, this._base) : 1;
|
|
204
|
-
}
|
|
205
|
-
set zoom(e) {
|
|
206
|
-
this._rect && (this._rect = f(this._rect, this._base, Number(e) || 1, this._natural.w, this._natural.h), this._paint(), this._announce());
|
|
207
|
-
}
|
|
208
|
-
connectedCallback() {
|
|
209
|
-
if (!this._rendered) {
|
|
210
|
-
this.render();
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
this._observe();
|
|
214
|
-
}
|
|
215
|
-
disconnectedCallback() {
|
|
216
|
-
this._resizeObserver?.disconnect(), this._resizeObserver = null;
|
|
217
|
-
}
|
|
218
|
-
attributeChangedCallback(e) {
|
|
219
|
-
this._rendered && (e === "src" ? this._loadImage() : e === "aspect" ? (this._rebuildHandles(), this._resetRect()) : e === "rotatable" ? this._tools.hidden = !this.rotatable : e === "previews" ? this._renderPreviews() : this._applyRound());
|
|
220
|
-
}
|
|
221
|
-
render() {
|
|
222
|
-
this.innerHTML = `<div>
|
|
223
|
-
<div class="wui-crop-stage" tabindex="0" role="group" aria-label="Crop area. Drag the frame or use the arrow keys to move it, and plus or minus to zoom.">
|
|
224
|
-
<img class="wui-crop-img" alt="" draggable="false">
|
|
225
|
-
<div class="wui-crop-frame"></div>
|
|
226
|
-
</div>
|
|
227
|
-
<div class="wui-crop-controls">
|
|
228
|
-
<button type="button" class="wui-crop-zoombtn" data-zoom="out" aria-label="Zoom out">${k}</button>
|
|
229
|
-
<input type="range" class="form-range wui-crop-zoom" min="1" max="4" step="0.01" value="1" aria-label="Zoom">
|
|
230
|
-
<button type="button" class="wui-crop-zoombtn" data-zoom="in" aria-label="Zoom in">${A}</button>
|
|
231
|
-
</div>
|
|
232
|
-
<div class="wui-crop-tools" hidden>
|
|
233
|
-
<button type="button" class="wui-crop-toolbtn" data-crop-action="rotate" aria-label="Rotate 90 degrees clockwise">${j}<span>Rotate</span></button>
|
|
234
|
-
<button type="button" class="wui-crop-toolbtn" data-crop-action="reset" aria-label="Reset the crop">${M}<span>Reset</span></button>
|
|
235
|
-
</div>
|
|
236
|
-
<div class="wui-crop-previews" aria-hidden="true" hidden></div>
|
|
237
|
-
<div class="visually-hidden" data-wui-crop-live aria-live="polite"></div>
|
|
238
|
-
</div>`, this._stage = this.querySelector(".wui-crop-stage"), this._img = this.querySelector(".wui-crop-img"), this._frame = this.querySelector(".wui-crop-frame"), this._slider = this.querySelector(".wui-crop-zoom"), this._tools = this.querySelector(".wui-crop-tools"), this._previewBox = this.querySelector(".wui-crop-previews"), this._live = this.querySelector("[data-wui-crop-live]"), this._rendered = !0, this._tools.hidden = !this.rotatable, this._applyRound(), this._rebuildHandles(), this._renderPreviews(), this._wire(), this._observe(), this._loadImage();
|
|
239
|
-
}
|
|
240
|
-
_applyRound() {
|
|
241
|
-
this._frame.classList.toggle("wui-crop-frame--round", this.round), this._previewBox.classList.toggle("wui-crop-previews--round", this.round);
|
|
242
|
-
}
|
|
243
|
-
_rebuildHandles() {
|
|
244
|
-
for (let e of this._frame.querySelectorAll(".wui-crop-handle")) e.remove();
|
|
245
|
-
if (!this.aspect) for (let e of p) {
|
|
246
|
-
let t = document.createElement("button");
|
|
247
|
-
t.type = "button", t.className = `wui-crop-handle wui-crop-handle--${e}`, t.dataset.handle = e, t.setAttribute("aria-label", `Resize ${O[e]} corner`), this._frame.appendChild(t);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
_renderPreviews() {
|
|
251
|
-
let e = y(this.previews);
|
|
252
|
-
this._previewBox.replaceChildren(), this._previewBox.hidden = e.length === 0;
|
|
253
|
-
for (let t of e) {
|
|
254
|
-
let e = document.createElement("canvas");
|
|
255
|
-
e.className = "wui-crop-preview", e.dataset.size = String(t), e.style.width = `${t}px`, e.style.height = `${t}px`, this._previewBox.appendChild(e);
|
|
256
|
-
}
|
|
257
|
-
this._schedulePreviews();
|
|
258
|
-
}
|
|
259
|
-
_loadImage() {
|
|
260
|
-
this._rect = null, this._natural = null, this._source = null, this._rotation = 0, this._drag = null, this._pinch = null, this._pointers.clear();
|
|
261
|
-
let e = this.src;
|
|
262
|
-
this._img.hidden = !e, this._frame.hidden = !0, e && (this._img.onload = () => {
|
|
263
|
-
this._source = {
|
|
264
|
-
w: this._img.naturalWidth,
|
|
265
|
-
h: this._img.naturalHeight
|
|
266
|
-
}, this._natural = { ...this._source }, this._resetRect(), this.dispatchEvent(new Event("load"));
|
|
267
|
-
}, this._img.onerror = () => {
|
|
268
|
-
this._frame.hidden = !0, this.dispatchEvent(new Event("error"));
|
|
269
|
-
}, this._img.src = e);
|
|
270
|
-
}
|
|
271
|
-
_resetRect() {
|
|
272
|
-
this._natural && (this._base = o(this._natural.w, this._natural.h, this.aspect), this._rect = { ...this._base }, this._frame.hidden = !1, this._paint());
|
|
273
|
-
}
|
|
274
|
-
_observe() {
|
|
275
|
-
typeof ResizeObserver > "u" || this._resizeObserver || (this._resizeObserver = new ResizeObserver(() => this._paint()), this._resizeObserver.observe(this._stage));
|
|
276
|
-
}
|
|
277
|
-
_view() {
|
|
278
|
-
let e = this._stage.clientWidth || D.w, t = this._stage.clientHeight || D.h, n = Math.min(e / this._natural.w, t / this._natural.h), r = this._natural.w * n, i = this._natural.h * n;
|
|
279
|
-
return {
|
|
280
|
-
scale: n,
|
|
281
|
-
left: (e - r) / 2,
|
|
282
|
-
top: (t - i) / 2,
|
|
283
|
-
iw: r,
|
|
284
|
-
ih: i
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
_paint() {
|
|
288
|
-
if (!this._rect) return;
|
|
289
|
-
let e = this._view(), t = this._rotation % 180 != 0, n = t ? e.ih : e.iw, r = t ? e.iw : e.ih;
|
|
290
|
-
Object.assign(this._img.style, {
|
|
291
|
-
left: `${e.left + (e.iw - n) / 2}px`,
|
|
292
|
-
top: `${e.top + (e.ih - r) / 2}px`,
|
|
293
|
-
width: `${n}px`,
|
|
294
|
-
height: `${r}px`,
|
|
295
|
-
transform: this._rotation ? `rotate(${this._rotation}deg)` : ""
|
|
296
|
-
});
|
|
297
|
-
let i = this._rect;
|
|
298
|
-
Object.assign(this._frame.style, {
|
|
299
|
-
left: `${e.left + i.x * e.scale}px`,
|
|
300
|
-
top: `${e.top + i.y * e.scale}px`,
|
|
301
|
-
width: `${i.w * e.scale}px`,
|
|
302
|
-
height: `${i.h * e.scale}px`
|
|
303
|
-
});
|
|
304
|
-
let a = u(i, this._base), o = d(i, this._base);
|
|
305
|
-
this._slider.max = String(o), this._slider.value = String(Math.min(Math.max(a, 1), o)), this._slider.setAttribute("aria-valuetext", `${Math.round(a * 100)}%`), this._schedulePreviews();
|
|
306
|
-
}
|
|
307
|
-
_schedulePreviews() {
|
|
308
|
-
if (!this._rect || this._previewBox.hidden || this._previewPending) return;
|
|
309
|
-
this._previewPending = !0;
|
|
310
|
-
let e = () => {
|
|
311
|
-
this._previewPending = !1, this._drawPreviews();
|
|
312
|
-
};
|
|
313
|
-
typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : e();
|
|
314
|
-
}
|
|
315
|
-
_drawPreviews() {
|
|
316
|
-
if (!this._rect) return;
|
|
317
|
-
let e = s(this._rect, this._natural.w, this._natural.h), t = typeof window < "u" && window.devicePixelRatio || 1;
|
|
318
|
-
for (let n of this._previewBox.children) {
|
|
319
|
-
let r = Number(n.dataset.size), i = Math.max(1, Math.round(r * e.h / e.w));
|
|
320
|
-
n.style.width = `${r}px`, n.style.height = `${i}px`, n.width = Math.round(r * t), n.height = Math.round(i * t);
|
|
321
|
-
let a = n.getContext("2d");
|
|
322
|
-
a && this._drawCrop(a, e, n.width, n.height);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
_drawCrop(e, t, n, r) {
|
|
326
|
-
if (!this._rotation) {
|
|
327
|
-
e.drawImage(this._img, t.x, t.y, t.w, t.h, 0, 0, n, r);
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
let i = this._source;
|
|
331
|
-
e.save(), e.scale(n / t.w, r / t.h), e.translate(-t.x, -t.y), e.translate(this._natural.w / 2, this._natural.h / 2), e.rotate(this._rotation * Math.PI / 180), e.drawImage(this._img, -i.w / 2, -i.h / 2, i.w, i.h), e.restore();
|
|
332
|
-
}
|
|
333
|
-
_announce() {
|
|
334
|
-
this.dispatchEvent(new CustomEvent("change", {
|
|
335
|
-
bubbles: !0,
|
|
336
|
-
detail: this.rect
|
|
337
|
-
}));
|
|
338
|
-
}
|
|
339
|
-
_say() {
|
|
340
|
-
let e = this._rect, t = this._rotation ? `, turned ${this._rotation} degrees` : "", n = `Frame ${Math.round(e.w)} by ${Math.round(e.h)} pixels, ${Math.round(e.x)} from the left, ${Math.round(e.y)} from the top, zoom ${Math.round(u(e, this._base) * 100)}%${t}.`;
|
|
341
|
-
this._live.textContent = n === this._live.textContent ? `${n} ` : n;
|
|
342
|
-
}
|
|
343
|
-
rotate() {
|
|
344
|
-
if (!this._rect) return;
|
|
345
|
-
let e = v(this._rect, this._natural.w, this._natural.h);
|
|
346
|
-
this._rotation = (this._rotation + 90) % 360, this._natural = _(this._source.w, this._source.h, this._rotation), this._base = o(this._natural.w, this._natural.h, this.aspect);
|
|
347
|
-
let t = this.aspect;
|
|
348
|
-
this._rect = t && t !== 1 ? { ...this._base } : e, this._paint(), this._announce();
|
|
349
|
-
}
|
|
350
|
-
reset() {
|
|
351
|
-
this._source && (this._rotation = 0, this._natural = { ...this._source }, this._resetRect(), this._announce());
|
|
352
|
-
}
|
|
353
|
-
_wire() {
|
|
354
|
-
let e = this._stage;
|
|
355
|
-
e.addEventListener("pointerdown", (t) => {
|
|
356
|
-
if (!this._rect || t.button > 0) return;
|
|
357
|
-
if (this._pointers.set(t.pointerId, {
|
|
358
|
-
x: t.clientX,
|
|
359
|
-
y: t.clientY
|
|
360
|
-
}), e.setPointerCapture?.(t.pointerId), this._pointers.size === 2) {
|
|
361
|
-
let [e, n] = [...this._pointers.values()];
|
|
362
|
-
this._drag = null, this._pinch = {
|
|
363
|
-
distance: N(e, n) || 1,
|
|
364
|
-
zoom: this.zoom,
|
|
365
|
-
done: !1
|
|
366
|
-
}, t.preventDefault();
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
if (this._pinch) return;
|
|
370
|
-
let n = t.target.closest?.(".wui-crop-handle");
|
|
371
|
-
this._drag = {
|
|
372
|
-
id: t.pointerId,
|
|
373
|
-
corner: n ? n.dataset.handle : null,
|
|
374
|
-
x: t.clientX,
|
|
375
|
-
y: t.clientY,
|
|
376
|
-
start: { ...this._rect }
|
|
377
|
-
}, n || e.focus(), t.preventDefault();
|
|
378
|
-
}), e.addEventListener("pointermove", (t) => {
|
|
379
|
-
if (this._pointers.has(t.pointerId) && this._pointers.set(t.pointerId, {
|
|
380
|
-
x: t.clientX,
|
|
381
|
-
y: t.clientY
|
|
382
|
-
}), this._pinch) {
|
|
383
|
-
if (this._pinch.done || this._pointers.size < 2 || !this._pointers.has(t.pointerId)) return;
|
|
384
|
-
let [e, n] = [...this._pointers.values()], r = this._pinch.zoom * N(e, n) / this._pinch.distance;
|
|
385
|
-
this._rect = f(this._rect, this._base, r, this._natural.w, this._natural.h), this._paint();
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
let n = this._drag;
|
|
389
|
-
if (!n || n.id !== t.pointerId) return;
|
|
390
|
-
let r = this._view(), { w: i, h: a } = this._natural;
|
|
391
|
-
if (n.corner) {
|
|
392
|
-
let o = e.getBoundingClientRect(), s = (t.clientX - o.left - e.clientLeft - r.left) / r.scale, c = (t.clientY - o.top - e.clientTop - r.top) / r.scale;
|
|
393
|
-
this._rect = m(this._rect, n.corner, s, c, i, a);
|
|
394
|
-
} else this._rect = c(n.start, (t.clientX - n.x) / r.scale, (t.clientY - n.y) / r.scale, i, a);
|
|
395
|
-
this._paint();
|
|
396
|
-
});
|
|
397
|
-
let t = (t) => {
|
|
398
|
-
if (this._pointers.delete(t.pointerId) && e.releasePointerCapture?.(t.pointerId), this._pinch) {
|
|
399
|
-
!this._pinch.done && this._pointers.size < 2 && (this._pinch.done = !0, this._announce()), this._pointers.size === 0 && (this._pinch = null);
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
let n = this._drag;
|
|
403
|
-
!n || n.id !== t.pointerId || (this._drag = null, this._announce());
|
|
404
|
-
};
|
|
405
|
-
e.addEventListener("pointerup", t), e.addEventListener("pointercancel", t), e.addEventListener("keydown", (e) => this._onKey(e)), e.addEventListener("wheel", (e) => {
|
|
406
|
-
!this._rect || !this.contains(document.activeElement) || (e.preventDefault(), this.zoom *= e.deltaY < 0 ? 1.1 : 1 / 1.1);
|
|
407
|
-
}, { passive: !1 });
|
|
408
|
-
for (let e of ["input", "change"]) this._slider.addEventListener(e, (e) => e.stopPropagation());
|
|
409
|
-
this._slider.addEventListener("input", () => {
|
|
410
|
-
this.zoom = Number(this._slider.value);
|
|
411
|
-
});
|
|
412
|
-
for (let e of this.querySelectorAll(".wui-crop-zoombtn")) e.addEventListener("click", () => {
|
|
413
|
-
this.zoom *= e.dataset.zoom === "in" ? 1.25 : .8;
|
|
414
|
-
});
|
|
415
|
-
this.querySelector("[data-crop-action=\"rotate\"]").addEventListener("click", () => this.rotate()), this.querySelector("[data-crop-action=\"reset\"]").addEventListener("click", () => this.reset());
|
|
416
|
-
}
|
|
417
|
-
_onKey(e) {
|
|
418
|
-
if (!this._rect || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
419
|
-
let { w: t, h: n } = this._natural;
|
|
420
|
-
if (e.key === "+" || e.key === "=") this.zoom *= 1.25, this._say();
|
|
421
|
-
else if (e.key === "-" || e.key === "_") this.zoom *= .8, this._say();
|
|
422
|
-
else if ((e.key === "r" || e.key === "R") && this.rotatable) this.rotate(), this._say();
|
|
423
|
-
else if (e.key.startsWith("Arrow")) {
|
|
424
|
-
let r = e.shiftKey ? E : T, i = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0, a = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0, o = e.target.closest?.(".wui-crop-handle")?.dataset.handle;
|
|
425
|
-
if (o) {
|
|
426
|
-
let e = this._rect, s = (o.endsWith("w") ? e.x : e.x + e.w) + i * r * e.w, c = (o.startsWith("n") ? e.y : e.y + e.h) + a * r * e.h;
|
|
427
|
-
this._rect = m(e, o, s, c, t, n);
|
|
428
|
-
} else this._rect = c(this._rect, i * r * this._rect.w, a * r * this._rect.h, t, n);
|
|
429
|
-
this._paint(), this._announce(), this._say();
|
|
430
|
-
} else return;
|
|
431
|
-
e.preventDefault();
|
|
432
|
-
}
|
|
433
|
-
async toBlob({ type: e, maxBytes: t = 0, size: n = 0 } = {}) {
|
|
434
|
-
if (!this._rect) return null;
|
|
435
|
-
let r = S(e), i = s(this._rect, this._natural.w, this._natural.h), { width: a, height: o } = n > 0 ? g(i, n) : h(i);
|
|
436
|
-
return w((e, t, n, r) => new Promise((a) => {
|
|
437
|
-
let o = document.createElement("canvas");
|
|
438
|
-
o.width = e, o.height = t;
|
|
439
|
-
let s = o.getContext("2d");
|
|
440
|
-
if (!s) {
|
|
441
|
-
a(null);
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
n === "image/jpeg" && (s.fillStyle = "#fff", s.fillRect(0, 0, e, t)), this._drawCrop(s, i, e, t), o.toBlob(a, n, r);
|
|
445
|
-
}), {
|
|
446
|
-
width: a,
|
|
447
|
-
height: o,
|
|
448
|
-
type: r,
|
|
449
|
-
maxBytes: t
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
async toFile({ name: e, type: t, maxBytes: n = 0, size: r = 0 } = {}) {
|
|
453
|
-
let i = await this.toBlob({
|
|
454
|
-
type: t,
|
|
455
|
-
maxBytes: n,
|
|
456
|
-
size: r
|
|
457
|
-
});
|
|
458
|
-
return i ? new File([i], C(e, i.type), { type: i.type }) : null;
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
//#endregion
|
|
462
|
-
export { P as t };
|