@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
package/dist/ui-file-viewer.js
CHANGED
|
@@ -1,311 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/elementBase.js
|
|
3
|
-
var r = typeof HTMLElement > "u" ? class {} : HTMLElement, i = {
|
|
4
|
-
pdf: "pdf",
|
|
5
|
-
jpg: "image",
|
|
6
|
-
jpeg: "image",
|
|
7
|
-
png: "image",
|
|
8
|
-
webp: "image",
|
|
9
|
-
gif: "image",
|
|
10
|
-
avif: "image",
|
|
11
|
-
bmp: "image",
|
|
12
|
-
svg: "image",
|
|
13
|
-
mp4: "video",
|
|
14
|
-
m4v: "video",
|
|
15
|
-
webm: "video",
|
|
16
|
-
ogv: "video",
|
|
17
|
-
mp3: "audio",
|
|
18
|
-
m4a: "audio",
|
|
19
|
-
aac: "audio",
|
|
20
|
-
wav: "audio",
|
|
21
|
-
ogg: "audio",
|
|
22
|
-
oga: "audio",
|
|
23
|
-
opus: "audio",
|
|
24
|
-
flac: "audio"
|
|
25
|
-
}, a = {
|
|
26
|
-
"application/pdf": "pdf",
|
|
27
|
-
"image/jpeg": "image",
|
|
28
|
-
"image/png": "image",
|
|
29
|
-
"image/webp": "image",
|
|
30
|
-
"image/gif": "image",
|
|
31
|
-
"image/avif": "image",
|
|
32
|
-
"image/bmp": "image",
|
|
33
|
-
"image/svg+xml": "image",
|
|
34
|
-
"video/mp4": "video",
|
|
35
|
-
"video/webm": "video",
|
|
36
|
-
"video/ogg": "video",
|
|
37
|
-
"audio/mpeg": "audio",
|
|
38
|
-
"audio/mp4": "audio",
|
|
39
|
-
"audio/aac": "audio",
|
|
40
|
-
"audio/wav": "audio",
|
|
41
|
-
"audio/x-wav": "audio",
|
|
42
|
-
"audio/ogg": "audio",
|
|
43
|
-
"audio/opus": "audio",
|
|
44
|
-
"audio/webm": "audio",
|
|
45
|
-
"audio/flac": "audio"
|
|
46
|
-
}, o = "wui-file-viewer:load", s = "wui-file-viewer:error", c = "wui-file-viewer:prefs-change";
|
|
47
|
-
function l(e, t) {
|
|
48
|
-
let n = String(e ?? "").split(";")[0].trim().toLowerCase();
|
|
49
|
-
if (n) return a[n] ?? null;
|
|
50
|
-
let r = String(t ?? "").split(/[?#]/)[0];
|
|
51
|
-
return i[r.includes(".") ? r.split(".").pop().toLowerCase() : ""] ?? null;
|
|
52
|
-
}
|
|
53
|
-
function u(e) {
|
|
54
|
-
let t = String(e ?? "").split(/[?#]/)[0].split("/").filter(Boolean).pop() ?? "";
|
|
55
|
-
try {
|
|
56
|
-
return decodeURIComponent(t);
|
|
57
|
-
} catch {
|
|
58
|
-
return t;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
var d = {
|
|
62
|
-
pdf: () => import("./fileViewerPdf-BnIsj-J-.js").then((e) => e.PdfView),
|
|
63
|
-
image: () => import("./fileViewerImage-Dky4nQZS.js").then((e) => e.ImageView),
|
|
64
|
-
video: () => import("./fileViewerMedia-DPk_YcvC.js").then((e) => e.MediaView),
|
|
65
|
-
audio: () => import("./fileViewerMedia-DPk_YcvC.js").then((e) => e.MediaView)
|
|
66
|
-
}, f = 0, p = class i extends r {
|
|
67
|
-
static defaultAssetBase = "";
|
|
68
|
-
static get observedAttributes() {
|
|
69
|
-
return [
|
|
70
|
-
"src",
|
|
71
|
-
"name",
|
|
72
|
-
"type",
|
|
73
|
-
"download",
|
|
74
|
-
"worker-src",
|
|
75
|
-
"asset-base",
|
|
76
|
-
"captions"
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
constructor() {
|
|
80
|
-
super(), f += 1, this.uid = `wui-file-viewer-${f}`, this._prefs = {}, this._onFullscreen = () => this._syncFullscreen();
|
|
81
|
-
}
|
|
82
|
-
get src() {
|
|
83
|
-
return this.getAttribute("src") ?? "";
|
|
84
|
-
}
|
|
85
|
-
set src(e) {
|
|
86
|
-
this.setAttribute("src", String(e ?? ""));
|
|
87
|
-
}
|
|
88
|
-
get name() {
|
|
89
|
-
return this.getAttribute("name") ?? "";
|
|
90
|
-
}
|
|
91
|
-
set name(e) {
|
|
92
|
-
this.setAttribute("name", String(e ?? ""));
|
|
93
|
-
}
|
|
94
|
-
get type() {
|
|
95
|
-
return this.getAttribute("type") ?? "";
|
|
96
|
-
}
|
|
97
|
-
set type(e) {
|
|
98
|
-
this.setAttribute("type", String(e ?? ""));
|
|
99
|
-
}
|
|
100
|
-
get viewKey() {
|
|
101
|
-
return this.getAttribute("view-key") ?? "";
|
|
102
|
-
}
|
|
103
|
-
set viewKey(e) {
|
|
104
|
-
this.setAttribute("view-key", String(e ?? ""));
|
|
105
|
-
}
|
|
106
|
-
get download() {
|
|
107
|
-
return this.hasAttribute("download");
|
|
108
|
-
}
|
|
109
|
-
set download(e) {
|
|
110
|
-
this.toggleAttribute("download", e === !0 || e === "" || e === "true");
|
|
111
|
-
}
|
|
112
|
-
get workerSrc() {
|
|
113
|
-
return this.getAttribute("worker-src") ?? "";
|
|
114
|
-
}
|
|
115
|
-
set workerSrc(e) {
|
|
116
|
-
this.setAttribute("worker-src", String(e ?? ""));
|
|
117
|
-
}
|
|
118
|
-
get captions() {
|
|
119
|
-
return this.getAttribute("captions") ?? "";
|
|
120
|
-
}
|
|
121
|
-
set captions(e) {
|
|
122
|
-
this.setAttribute("captions", String(e ?? ""));
|
|
123
|
-
}
|
|
124
|
-
get assetBase() {
|
|
125
|
-
return this.getAttribute("asset-base") ?? "";
|
|
126
|
-
}
|
|
127
|
-
set assetBase(e) {
|
|
128
|
-
this.setAttribute("asset-base", String(e ?? ""));
|
|
129
|
-
}
|
|
130
|
-
get prefs() {
|
|
131
|
-
return { ...this._prefs };
|
|
132
|
-
}
|
|
133
|
-
set prefs(e) {
|
|
134
|
-
this._hostPrefs = !0, this._prefs = e && typeof e == "object" ? { ...e } : {};
|
|
135
|
-
}
|
|
136
|
-
get actionsContainer() {
|
|
137
|
-
return this._actionsBox ?? null;
|
|
138
|
-
}
|
|
139
|
-
seekTo(e) {
|
|
140
|
-
if (typeof e != "number" || !Number.isFinite(e)) throw TypeError(`[wui-file-viewer] seekTo takes a number of seconds; got ${String(e)}.`);
|
|
141
|
-
return this._view?.seekTo ? (this._view.seekTo(e), !0) : !1;
|
|
142
|
-
}
|
|
143
|
-
displayName() {
|
|
144
|
-
return this.name || u(this.src) || "Document";
|
|
145
|
-
}
|
|
146
|
-
connectedCallback() {
|
|
147
|
-
if (Object.hasOwn(this, "prefs")) {
|
|
148
|
-
let e = this.prefs;
|
|
149
|
-
delete this.prefs, this.prefs = e;
|
|
150
|
-
}
|
|
151
|
-
document.addEventListener("fullscreenchange", this._onFullscreen), this._open();
|
|
152
|
-
}
|
|
153
|
-
disconnectedCallback() {
|
|
154
|
-
document.removeEventListener("fullscreenchange", this._onFullscreen), this._close();
|
|
155
|
-
}
|
|
156
|
-
attributeChangedCallback(e, t, n) {
|
|
157
|
-
!this.isConnected || !this._parts || t === n || (e === "name" ? this._parts.name.textContent = this.displayName() : e === "download" ? this._syncDownload() : this._open());
|
|
158
|
-
}
|
|
159
|
-
_close() {
|
|
160
|
-
this._view?.destroy(), this._view = null, this._loadId = (this._loadId ?? 0) + 1;
|
|
161
|
-
}
|
|
162
|
-
async _open() {
|
|
163
|
-
this._close();
|
|
164
|
-
let e = this._loadId;
|
|
165
|
-
this._render(), this._prefs = this._readPrefs();
|
|
166
|
-
let t = l(this.type, this.name || this.src);
|
|
167
|
-
if (!this.src) {
|
|
168
|
-
this._status("No file to show.");
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (!t) {
|
|
172
|
-
this._status("This file can't be shown here.", { offerDownload: !0 });
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
this._status("Loading...");
|
|
176
|
-
let n;
|
|
177
|
-
try {
|
|
178
|
-
n = await d[t]();
|
|
179
|
-
} catch (t) {
|
|
180
|
-
e === this._loadId && this._fail(t);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
e === this._loadId && (this._view = new n(this._shell(e), {
|
|
184
|
-
src: this.src,
|
|
185
|
-
kind: t,
|
|
186
|
-
captions: this.captions,
|
|
187
|
-
workerSrc: this.workerSrc,
|
|
188
|
-
assetBase: m(this.assetBase || i.defaultAssetBase)
|
|
189
|
-
}), this._view.load());
|
|
190
|
-
}
|
|
191
|
-
_shell(e) {
|
|
192
|
-
let t = () => e === this._loadId, n = this._parts;
|
|
193
|
-
return {
|
|
194
|
-
host: this,
|
|
195
|
-
start: n.start,
|
|
196
|
-
center: n.center,
|
|
197
|
-
end: n.viewEnd,
|
|
198
|
-
search: n.search,
|
|
199
|
-
body: n.body,
|
|
200
|
-
prefs: { ...this._prefs },
|
|
201
|
-
name: () => this.displayName(),
|
|
202
|
-
savePrefs: (e) => {
|
|
203
|
-
t() && this._savePrefs(e);
|
|
204
|
-
},
|
|
205
|
-
loaded: (e) => {
|
|
206
|
-
t() && (n.body.removeAttribute("aria-busy"), this.dispatchEvent(new CustomEvent(o, {
|
|
207
|
-
bubbles: !0,
|
|
208
|
-
detail: e
|
|
209
|
-
})));
|
|
210
|
-
},
|
|
211
|
-
fail: (e) => {
|
|
212
|
-
t() && this._fail(e);
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
_render() {
|
|
217
|
-
let r = (e, t) => {
|
|
218
|
-
let n = document.createElement(e);
|
|
219
|
-
return n.className = t, n;
|
|
220
|
-
}, i = r("div", "wui-file-viewer-toolbar"), a = r("div", "wui-file-viewer-group wui-file-viewer-start"), o = r("span", "wui-file-viewer-name");
|
|
221
|
-
o.textContent = this.displayName(), o.title = this.displayName(), a.append(o);
|
|
222
|
-
let s = r("div", "wui-file-viewer-group wui-file-viewer-center"), c = r("div", "wui-file-viewer-group wui-file-viewer-end"), l = r("div", "wui-file-viewer-group wui-file-viewer-view-end"), u = r("a", "u-action wui-file-viewer-download");
|
|
223
|
-
u.style.setProperty("--wui-action-size", "32px"), t(u, "download"), e(u, "Download");
|
|
224
|
-
let d = n("maximize-4", "Full screen", { className: "wui-file-viewer-fullscreen" });
|
|
225
|
-
d.addEventListener("click", () => this.toggleFullscreen()), d.hidden = !document.fullscreenEnabled, this._actionsBox ??= r("div", "wui-file-viewer-actions");
|
|
226
|
-
let f = this._actionsBox;
|
|
227
|
-
f.append(...this.querySelectorAll(":scope > [slot=\"actions\"]")), c.append(l, u, d, f);
|
|
228
|
-
let p = r("search", "wui-file-viewer-search");
|
|
229
|
-
p.hidden = !0, i.append(a, s, c, p);
|
|
230
|
-
let m = r("div", "wui-file-viewer-body");
|
|
231
|
-
m.setAttribute("aria-busy", "true"), this.replaceChildren(i, m), this._parts = {
|
|
232
|
-
toolbar: i,
|
|
233
|
-
start: a,
|
|
234
|
-
name: o,
|
|
235
|
-
center: s,
|
|
236
|
-
end: c,
|
|
237
|
-
viewEnd: l,
|
|
238
|
-
downloadLink: u,
|
|
239
|
-
fullscreen: d,
|
|
240
|
-
actionsBox: f,
|
|
241
|
-
search: p,
|
|
242
|
-
body: m
|
|
243
|
-
}, this._syncDownload(), this._syncFullscreen();
|
|
244
|
-
}
|
|
245
|
-
_syncDownload() {
|
|
246
|
-
let e = this._parts.downloadLink;
|
|
247
|
-
e.hidden = !this.download || !this.src, e.href = this.src, e.setAttribute("download", this.displayName());
|
|
248
|
-
}
|
|
249
|
-
_status(e, { offerDownload: t = !1 } = {}) {
|
|
250
|
-
let n = document.createElement("div");
|
|
251
|
-
n.className = "wui-file-viewer-status";
|
|
252
|
-
let r = document.createElement("p");
|
|
253
|
-
if (r.textContent = e, n.append(r), t && this.src) {
|
|
254
|
-
let e = document.createElement("a");
|
|
255
|
-
e.className = "btn btn-sm btn-outline-secondary", e.href = this.src, e.setAttribute("download", this.displayName()), e.textContent = "Download", n.append(e);
|
|
256
|
-
}
|
|
257
|
-
this._parts.body.replaceChildren(n);
|
|
258
|
-
}
|
|
259
|
-
_fail(e) {
|
|
260
|
-
this._view?.destroy(), this._view = null, this._parts.body.removeAttribute("aria-busy"), this._status("Couldn't open this file.", { offerDownload: !0 }), this.dispatchEvent(new CustomEvent(s, {
|
|
261
|
-
bubbles: !0,
|
|
262
|
-
detail: { message: e?.message ?? String(e) }
|
|
263
|
-
}));
|
|
264
|
-
}
|
|
265
|
-
toggleFullscreen() {
|
|
266
|
-
if (document.fullscreenElement) {
|
|
267
|
-
document.exitFullscreen();
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
this.requestFullscreen().catch((e) => {
|
|
271
|
-
console.warn("[wui-file-viewer] full screen refused:", e?.message);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
_syncFullscreen() {
|
|
275
|
-
if (!this._parts) return;
|
|
276
|
-
let n = document.fullscreenElement === this, r = this._parts.fullscreen;
|
|
277
|
-
t(r, n ? "x" : "maximize-4"), e(r, n ? "Exit full screen" : "Full screen"), this._parts.actionsBox.hidden = n;
|
|
278
|
-
}
|
|
279
|
-
_readPrefs() {
|
|
280
|
-
if (this._hostPrefs || !this.viewKey) return { ...this._prefs };
|
|
281
|
-
try {
|
|
282
|
-
return JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`) ?? "{}") ?? {};
|
|
283
|
-
} catch {
|
|
284
|
-
return {};
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
_savePrefs(e) {
|
|
288
|
-
if (this._prefs = {
|
|
289
|
-
...this._prefs,
|
|
290
|
-
...e
|
|
291
|
-
}, this.dispatchEvent(new CustomEvent(c, {
|
|
292
|
-
bubbles: !0,
|
|
293
|
-
detail: { ...this._prefs }
|
|
294
|
-
})), !(this._hostPrefs || !this.viewKey)) try {
|
|
295
|
-
window.localStorage.setItem(`wui-view:${this.viewKey}`, JSON.stringify(this._prefs));
|
|
296
|
-
} catch {}
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
function m(e) {
|
|
300
|
-
return e && new URL(e, document.baseURI).href;
|
|
301
|
-
}
|
|
302
|
-
//#endregion
|
|
303
|
-
//#region src/fileViewer.js
|
|
304
|
-
var h = typeof document > "u" ? null : document.currentScript;
|
|
305
|
-
h?.src && (p.defaultAssetBase = new URL("pdfjs/", h.src).href), typeof customElements < "u" && !customElements.get("wui-file-viewer") && customElements.define("wui-file-viewer", p);
|
|
306
|
-
var g = (e, t) => import("./fileViewerPdf-BnIsj-J-.js").then((n) => n.renderFirstPage(e, {
|
|
307
|
-
assetBase: p.defaultAssetBase || void 0,
|
|
308
|
-
...t
|
|
309
|
-
}));
|
|
310
|
-
//#endregion
|
|
311
|
-
export { p as WuiFileViewer, l as fileKind, u as fileNameFromUrl, g as renderPdfFirstPage };
|
|
1
|
+
import{i as e,r as t,t as n}from"./fileViewerUi-DasgDsU-.js";var r=typeof HTMLElement>`u`?class{}:HTMLElement,i={pdf:`pdf`,jpg:`image`,jpeg:`image`,png:`image`,webp:`image`,gif:`image`,avif:`image`,bmp:`image`,svg:`image`,mp4:`video`,m4v:`video`,webm:`video`,ogv:`video`,mp3:`audio`,m4a:`audio`,aac:`audio`,wav:`audio`,ogg:`audio`,oga:`audio`,opus:`audio`,flac:`audio`},a={"application/pdf":`pdf`,"image/jpeg":`image`,"image/png":`image`,"image/webp":`image`,"image/gif":`image`,"image/avif":`image`,"image/bmp":`image`,"image/svg+xml":`image`,"video/mp4":`video`,"video/webm":`video`,"video/ogg":`video`,"audio/mpeg":`audio`,"audio/mp4":`audio`,"audio/aac":`audio`,"audio/wav":`audio`,"audio/x-wav":`audio`,"audio/ogg":`audio`,"audio/opus":`audio`,"audio/webm":`audio`,"audio/flac":`audio`},o=`wui-file-viewer:load`,s=`wui-file-viewer:error`,c=`wui-file-viewer:prefs-change`;function l(e,t){let n=String(e??``).split(`;`)[0].trim().toLowerCase();if(n)return a[n]??null;let r=String(t??``).split(/[?#]/)[0];return i[r.includes(`.`)?r.split(`.`).pop().toLowerCase():``]??null}function u(e){let t=String(e??``).split(/[?#]/)[0].split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}var d={pdf:()=>import(`./fileViewerPdf-BN0zuehw.js`).then(e=>e.PdfView),image:()=>import(`./fileViewerImage-Y9QBn2Rj.js`).then(e=>e.ImageView),video:()=>import(`./fileViewerMedia-CaJaVnjE.js`).then(e=>e.MediaView),audio:()=>import(`./fileViewerMedia-CaJaVnjE.js`).then(e=>e.MediaView)},f=0,p=class i extends r{static defaultAssetBase=``;static get observedAttributes(){return[`src`,`name`,`type`,`download`,`worker-src`,`asset-base`,`captions`]}constructor(){super(),f+=1,this.uid=`wui-file-viewer-${f}`,this._prefs={},this._onFullscreen=()=>this._syncFullscreen()}get src(){return this.getAttribute(`src`)??``}set src(e){this.setAttribute(`src`,String(e??``))}get name(){return this.getAttribute(`name`)??``}set name(e){this.setAttribute(`name`,String(e??``))}get type(){return this.getAttribute(`type`)??``}set type(e){this.setAttribute(`type`,String(e??``))}get viewKey(){return this.getAttribute(`view-key`)??``}set viewKey(e){this.setAttribute(`view-key`,String(e??``))}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get workerSrc(){return this.getAttribute(`worker-src`)??``}set workerSrc(e){this.setAttribute(`worker-src`,String(e??``))}get captions(){return this.getAttribute(`captions`)??``}set captions(e){this.setAttribute(`captions`,String(e??``))}get assetBase(){return this.getAttribute(`asset-base`)??``}set assetBase(e){this.setAttribute(`asset-base`,String(e??``))}get prefs(){return{...this._prefs}}set prefs(e){this._hostPrefs=!0,this._prefs=e&&typeof e==`object`?{...e}:{}}get actionsContainer(){return this._actionsBox??null}seekTo(e){if(typeof e!=`number`||!Number.isFinite(e))throw TypeError(`[wui-file-viewer] seekTo takes a number of seconds; got ${String(e)}.`);return this._view?.seekTo?(this._view.seekTo(e),!0):!1}displayName(){return this.name||u(this.src)||`Document`}connectedCallback(){if(Object.hasOwn(this,`prefs`)){let e=this.prefs;delete this.prefs,this.prefs=e}document.addEventListener(`fullscreenchange`,this._onFullscreen),this._open()}disconnectedCallback(){document.removeEventListener(`fullscreenchange`,this._onFullscreen),this._close()}attributeChangedCallback(e,t,n){!this.isConnected||!this._parts||t===n||(e===`name`?this._parts.name.textContent=this.displayName():e===`download`?this._syncDownload():this._open())}_close(){this._view?.destroy(),this._view=null,this._loadId=(this._loadId??0)+1}async _open(){this._close();let e=this._loadId;this._render(),this._prefs=this._readPrefs();let t=l(this.type,this.name||this.src);if(!this.src){this._status(`No file to show.`);return}if(!t){this._status(`This file can't be shown here.`,{offerDownload:!0});return}this._status(`Loading...`);let n;try{n=await d[t]()}catch(t){e===this._loadId&&this._fail(t);return}e===this._loadId&&(this._view=new n(this._shell(e),{src:this.src,kind:t,captions:this.captions,workerSrc:this.workerSrc,assetBase:m(this.assetBase||i.defaultAssetBase)}),this._view.load())}_shell(e){let t=()=>e===this._loadId,n=this._parts;return{host:this,start:n.start,center:n.center,end:n.viewEnd,search:n.search,body:n.body,prefs:{...this._prefs},name:()=>this.displayName(),savePrefs:e=>{t()&&this._savePrefs(e)},loaded:e=>{t()&&(n.body.removeAttribute(`aria-busy`),this.dispatchEvent(new CustomEvent(o,{bubbles:!0,detail:e})))},fail:e=>{t()&&this._fail(e)}}}_render(){let r=(e,t)=>{let n=document.createElement(e);return n.className=t,n},i=r(`div`,`wui-file-viewer-toolbar`),a=r(`div`,`wui-file-viewer-group wui-file-viewer-start`),o=r(`span`,`wui-file-viewer-name`);o.textContent=this.displayName(),o.title=this.displayName(),a.append(o);let s=r(`div`,`wui-file-viewer-group wui-file-viewer-center`),c=r(`div`,`wui-file-viewer-group wui-file-viewer-end`),l=r(`div`,`wui-file-viewer-group wui-file-viewer-view-end`),u=r(`a`,`u-action wui-file-viewer-download`);u.style.setProperty(`--wui-action-size`,`32px`),t(u,`download`),e(u,`Download`);let d=n(`maximize-4`,`Full screen`,{className:`wui-file-viewer-fullscreen`});d.addEventListener(`click`,()=>this.toggleFullscreen()),d.hidden=!document.fullscreenEnabled,this._actionsBox??=r(`div`,`wui-file-viewer-actions`);let f=this._actionsBox;f.append(...this.querySelectorAll(`:scope > [slot="actions"]`)),c.append(l,u,d,f);let p=r(`search`,`wui-file-viewer-search`);p.hidden=!0,i.append(a,s,c,p);let m=r(`div`,`wui-file-viewer-body`);m.setAttribute(`aria-busy`,`true`),this.replaceChildren(i,m),this._parts={toolbar:i,start:a,name:o,center:s,end:c,viewEnd:l,downloadLink:u,fullscreen:d,actionsBox:f,search:p,body:m},this._syncDownload(),this._syncFullscreen()}_syncDownload(){let e=this._parts.downloadLink;e.hidden=!this.download||!this.src,e.href=this.src,e.setAttribute(`download`,this.displayName())}_status(e,{offerDownload:t=!1}={}){let n=document.createElement(`div`);n.className=`wui-file-viewer-status`;let r=document.createElement(`p`);if(r.textContent=e,n.append(r),t&&this.src){let e=document.createElement(`a`);e.className=`btn btn-sm btn-outline-secondary`,e.href=this.src,e.setAttribute(`download`,this.displayName()),e.textContent=`Download`,n.append(e)}this._parts.body.replaceChildren(n)}_fail(e){this._view?.destroy(),this._view=null,this._parts.body.removeAttribute(`aria-busy`),this._status(`Couldn't open this file.`,{offerDownload:!0}),this.dispatchEvent(new CustomEvent(s,{bubbles:!0,detail:{message:e?.message??String(e)}}))}toggleFullscreen(){if(document.fullscreenElement){document.exitFullscreen();return}this.requestFullscreen().catch(e=>{console.warn(`[wui-file-viewer] full screen refused:`,e?.message)})}_syncFullscreen(){if(!this._parts)return;let n=document.fullscreenElement===this,r=this._parts.fullscreen;t(r,n?`x`:`maximize-4`),e(r,n?`Exit full screen`:`Full screen`),this._parts.actionsBox.hidden=n}_readPrefs(){if(this._hostPrefs||!this.viewKey)return{...this._prefs};try{return JSON.parse(window.localStorage.getItem(`wui-view:${this.viewKey}`)??`{}`)??{}}catch{return{}}}_savePrefs(e){if(this._prefs={...this._prefs,...e},this.dispatchEvent(new CustomEvent(c,{bubbles:!0,detail:{...this._prefs}})),!(this._hostPrefs||!this.viewKey))try{window.localStorage.setItem(`wui-view:${this.viewKey}`,JSON.stringify(this._prefs))}catch{}}};function m(e){return e&&new URL(e,document.baseURI).href}var h=typeof document>`u`?null:document.currentScript;h?.src&&(p.defaultAssetBase=new URL(`pdfjs/`,h.src).href),typeof customElements<`u`&&!customElements.get(`wui-file-viewer`)&&customElements.define(`wui-file-viewer`,p);var g=(e,t)=>import(`./fileViewerPdf-BN0zuehw.js`).then(n=>n.renderFirstPage(e,{assetBase:p.defaultAssetBase||void 0,...t}));export{p as WuiFileViewer,l as fileKind,u as fileNameFromUrl,g as renderPdfFirstPage};
|