calmlens 0.20.0 → 0.22.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/README.md +15 -10
- package/bin/calmlens.js +1848 -679
- package/cjs/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/cjs/{BrowserUpload-CjSHjx3C.js → BrowserUpload-Bwlib4Zc.js} +1 -1
- package/cjs/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/cjs/{CalmLensAppClient-NaCxOVlM.js → CalmLensAppClient-DUYMo9PZ.js} +30 -10
- package/cjs/{CalmLensOptionKeys-p2QK687A.js → CalmLensOptionKeys-YvgV995V.js} +318 -374
- package/cjs/{CalmLensServerClient-BDzTthxE.js → CalmLensServerClient-3N-gdsxC.js} +346 -89
- package/cjs/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/cjs/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/cjs/Core-C33pkBmf.d.ts +826 -0
- package/cjs/Core-Cm5Z1oJ9.js +1001 -0
- package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
- package/cjs/{ModerationContextLimits-2nIv7Zh3.js → ModerationContextLimits-ud1xpZRK.js} +727 -268
- package/cjs/{ReactUpload-BdTRCTGA.js → ReactUpload-DQ0BYISX.js} +1 -1
- package/cjs/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/cjs/{TestTriggers-DbhsNPdg-DjvVuc2h.js → TestTriggers-D29T_R0M-D6Bu-Mln.js} +355 -47
- package/cjs/{UploadController-MLVs97Zt.js → UploadController-l8fZM2qT.js} +34 -14
- package/{esm/WebhookPayload-DkukERKE.d.ts → cjs/WebhookPayload-Dt6DttS0.d.ts} +120 -86
- package/cjs/app.d.ts +6 -7
- package/cjs/app.js +4 -3
- package/cjs/elements.d.ts +123 -22
- package/cjs/elements.js +553 -156
- package/cjs/file-icons.d.ts +2 -67
- package/cjs/index-Bde1wjiw.d.ts +16 -0
- package/cjs/index.d.ts +5 -6
- package/cjs/index.js +3 -2
- package/cjs/react-native.d.ts +52 -11
- package/cjs/react-native.js +231 -99
- package/cjs/react.d.ts +42 -9
- package/cjs/react.js +381 -118
- package/cjs/server.d.ts +48 -7
- package/cjs/server.js +7 -3
- package/cjs/test-inputs.d.ts +2 -2
- package/cjs/test-inputs.js +13 -9
- package/cjs/testing.d.ts +29 -15
- package/cjs/testing.js +1722 -433
- package/cjs/ui-BRA4HQ8r.js +1359 -0
- package/cjs/ui-YQuvbidU.d.ts +139 -0
- package/cjs/ui.d.ts +3 -2
- package/cjs/ui.js +45 -22
- package/cjs/vue.d.ts +802 -199
- package/cjs/vue.js +359 -127
- package/esm/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/esm/{BrowserUpload-CAVkRotw.js → BrowserUpload-GRZVB0G_.js} +1 -1
- package/esm/{CalmLensAppClient-PQ9VBvlW.js → CalmLensAppClient-B5QIJ6KS.js} +30 -10
- package/esm/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/esm/{CalmLensOptionKeys-Do2mPP6w.js → CalmLensOptionKeys-BG7Qrh8-.js} +317 -367
- package/esm/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/esm/{CalmLensServerClient-C_H5aAsV.js → CalmLensServerClient-bRUAebi-.js} +323 -90
- package/esm/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/esm/Core-BvQe4moS.js +846 -0
- package/esm/Core-C33pkBmf.d.ts +826 -0
- package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
- package/esm/{ModerationContextLimits-Chw-AzgL.js → ModerationContextLimits-CrxSnVZ3.js} +682 -253
- package/esm/{ReactUpload-CMmL0R5Q.js → ReactUpload-BMO8saxT.js} +1 -1
- package/esm/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/esm/{TestTriggers-DbhsNPdg-CUdrv8Nm.js → TestTriggers-D29T_R0M-Ztc74ucs.js} +332 -48
- package/esm/{UploadController-BJZghJpg.js → UploadController-DnJrWiE4.js} +34 -14
- package/{cjs/WebhookPayload-DkukERKE.d.ts → esm/WebhookPayload-Dt6DttS0.d.ts} +120 -86
- package/esm/app.d.ts +6 -7
- package/esm/app.js +3 -3
- package/esm/elements.d.ts +123 -22
- package/esm/elements.js +497 -128
- package/esm/file-icons.d.ts +2 -67
- package/esm/index-Bde1wjiw.d.ts +16 -0
- package/esm/index.d.ts +5 -6
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +52 -11
- package/esm/react-native.js +205 -75
- package/esm/react.d.ts +42 -9
- package/esm/react.js +327 -91
- package/esm/server.d.ts +48 -7
- package/esm/server.js +3 -3
- package/esm/styles.css +142 -22
- package/esm/svelte/AssetViewer.svelte +25 -0
- package/esm/svelte/CalmLensAsset.svelte +318 -0
- package/esm/svelte/CalmLensDocumentViewer.svelte +7 -0
- package/esm/svelte/CalmLensImageViewer.svelte +7 -0
- package/esm/svelte/CalmLensSpreadsheetViewer.svelte +7 -0
- package/esm/svelte/CalmLensTextViewer.svelte +7 -0
- package/esm/svelte/CalmLensWebsiteViewer.svelte +7 -0
- package/esm/svelte/index.d.ts +29 -6
- package/esm/svelte/index.js +7 -2
- package/esm/test-inputs.d.ts +2 -2
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +29 -15
- package/esm/testing.js +1718 -429
- package/esm/ui-YQuvbidU.d.ts +139 -0
- package/esm/ui-heryDd6g.js +1258 -0
- package/esm/ui.d.ts +3 -2
- package/esm/ui.js +4 -3
- package/esm/vue.d.ts +802 -199
- package/esm/vue.js +308 -103
- package/package.json +4 -2
- package/cjs/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/cjs/index-DxbJ_Xaa.d.ts +0 -253
- package/cjs/ui-BSqPGKrZ.d.ts +0 -539
- package/cjs/ui-CX1z2pD9.js +0 -586
- package/esm/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/esm/index-DxbJ_Xaa.d.ts +0 -253
- package/esm/svelte/CalmLensMedia.svelte +0 -134
- package/esm/ui-BSqPGKrZ.d.ts +0 -539
- package/esm/ui-CXH7xJpb.js +0 -461
package/esm/elements.js
CHANGED
|
@@ -1,6 +1,180 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import { i as createProgressFetch, n as createUploadController$1, r as isFileAccepted, t as UploadController } from "./UploadController-
|
|
3
|
-
import { t as
|
|
1
|
+
import { _ as loadPdfJs, a as ASSET_VIEWERS, c as getSpreadsheetPage, d as createImageViewer, f as createWebsiteViewer, g as resolveViewerMessages, h as formatViewerMessage, i as isMountedViewerKind, l as parseSpreadsheetText, m as DEFAULT_VIEWER_MESSAGES, n as AssetViewerMount, o as createSpreadsheetViewer, p as createDocumentViewer, r as getMountedViewerOptions, s as createTextViewer, t as MediaStreamPlayer, u as spreadsheetColumnIndex } from "./ui-heryDd6g.js";
|
|
2
|
+
import { i as createProgressFetch, n as createUploadController$1, r as isFileAccepted, t as UploadController } from "./UploadController-DnJrWiE4.js";
|
|
3
|
+
import { C as CALMLENS_THEME, E as isSpreadsheetFormat, S as VIEWER_STYLES, T as getAssetViewerKind, _ as getAssetView, a as describeUploadItem, b as getPlayedPercent, c as formatMessage, d as getUploadItemOutcome, f as resolveMessages, g as getAssetAspectRatio, h as AssetSession, i as DEFAULT_MESSAGES, l as getDropzoneHint, m as ICON_ATTRIBUTES, o as describeUploader, p as ICONS, r as ASSET_FILE_ICON_SIZE, s as formatBytes, t as CALMLENS_STYLES, u as getUploadItemMessage, v as getAssetViewKey, w as resolveTheme, x as pickAssetSource, y as getPeakHeights } from "./Core-BvQe4moS.js";
|
|
4
|
+
import { c as renderFileIconSvg } from "./FileIcons-M6dzjFxd.js";
|
|
5
|
+
import { t as createUploadController } from "./BrowserUpload-GRZVB0G_.js";
|
|
6
|
+
// src/viewers/Elements.ts
|
|
7
|
+
const BaseElement$1 = typeof HTMLElement === "undefined" ? class {} : HTMLElement;
|
|
8
|
+
const PROPERTIES = [
|
|
9
|
+
"asset",
|
|
10
|
+
"onExpired",
|
|
11
|
+
"getText",
|
|
12
|
+
"text",
|
|
13
|
+
"messages",
|
|
14
|
+
"pdf"
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* An asset viewer element. Set the `src` attribute to the asset URL (public or signed) and the
|
|
18
|
+
* `asset` property to its display info or the asset from the API, and `onExpired` to refresh a
|
|
19
|
+
* signed URL; other attributes: `label`, `viewer-claims` (JSON), `sizes` (images), `page-size`
|
|
20
|
+
* (spreadsheets) and `initial-page` (documents). The `text` and `getText` properties supply text
|
|
21
|
+
* and spreadsheet viewers' text, `messages` replaces their text and `pdf` sets where pdf.js loads
|
|
22
|
+
* its files from.
|
|
23
|
+
*/
|
|
24
|
+
var ViewerElement = class extends BaseElement$1 {
|
|
25
|
+
static {
|
|
26
|
+
this.observedAttributes = [
|
|
27
|
+
"src",
|
|
28
|
+
"label",
|
|
29
|
+
"viewer-claims",
|
|
30
|
+
"sizes",
|
|
31
|
+
"page-size",
|
|
32
|
+
"initial-page"
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
#viewer;
|
|
36
|
+
#asset;
|
|
37
|
+
#onExpired;
|
|
38
|
+
#getText;
|
|
39
|
+
#text;
|
|
40
|
+
#messages;
|
|
41
|
+
#pdf;
|
|
42
|
+
/** The asset to show, from the API. */
|
|
43
|
+
get asset() {
|
|
44
|
+
return this.#asset;
|
|
45
|
+
}
|
|
46
|
+
set asset(value) {
|
|
47
|
+
this.#asset = value;
|
|
48
|
+
this.#render();
|
|
49
|
+
}
|
|
50
|
+
/** Returns a fresh asset URL from your server once a signed one expires. */
|
|
51
|
+
get onExpired() {
|
|
52
|
+
return this.#onExpired;
|
|
53
|
+
}
|
|
54
|
+
set onExpired(value) {
|
|
55
|
+
this.#onExpired = value;
|
|
56
|
+
this.#render();
|
|
57
|
+
}
|
|
58
|
+
/** Reads a text or spreadsheet viewer's text yourself. */
|
|
59
|
+
get getText() {
|
|
60
|
+
return this.#getText;
|
|
61
|
+
}
|
|
62
|
+
set getText(value) {
|
|
63
|
+
this.#getText = value;
|
|
64
|
+
this.#render();
|
|
65
|
+
}
|
|
66
|
+
/** Text your app already has, for a text or spreadsheet viewer. */
|
|
67
|
+
get text() {
|
|
68
|
+
return this.#text;
|
|
69
|
+
}
|
|
70
|
+
set text(value) {
|
|
71
|
+
this.#text = value;
|
|
72
|
+
this.#render();
|
|
73
|
+
}
|
|
74
|
+
get messages() {
|
|
75
|
+
return this.#messages;
|
|
76
|
+
}
|
|
77
|
+
set messages(value) {
|
|
78
|
+
this.#messages = value;
|
|
79
|
+
this.#render();
|
|
80
|
+
}
|
|
81
|
+
/** Where a document viewer's pdf.js loads its worker, fonts and decoders from. */
|
|
82
|
+
get pdf() {
|
|
83
|
+
return this.#pdf;
|
|
84
|
+
}
|
|
85
|
+
set pdf(value) {
|
|
86
|
+
this.#pdf = value;
|
|
87
|
+
this.#render();
|
|
88
|
+
}
|
|
89
|
+
connectedCallback() {
|
|
90
|
+
const record = this;
|
|
91
|
+
for (const name of PROPERTIES) {
|
|
92
|
+
if (!Object.hasOwn(this, name)) continue;
|
|
93
|
+
const value = record[name];
|
|
94
|
+
delete record[name];
|
|
95
|
+
record[name] = value;
|
|
96
|
+
}
|
|
97
|
+
this.#render();
|
|
98
|
+
}
|
|
99
|
+
attributeChangedCallback() {
|
|
100
|
+
this.#render();
|
|
101
|
+
}
|
|
102
|
+
disconnectedCallback() {
|
|
103
|
+
this.#viewer?.destroy();
|
|
104
|
+
this.#viewer = void 0;
|
|
105
|
+
}
|
|
106
|
+
#render() {
|
|
107
|
+
const src = this.getAttribute("src");
|
|
108
|
+
if (!this.isConnected || !this.#asset || !src) return;
|
|
109
|
+
const pageSize = this.getAttribute("page-size");
|
|
110
|
+
const initialPage = this.getAttribute("initial-page");
|
|
111
|
+
const claims = this.getAttribute("viewer-claims");
|
|
112
|
+
const options = {
|
|
113
|
+
src,
|
|
114
|
+
asset: this.#asset,
|
|
115
|
+
onExpired: this.#onExpired,
|
|
116
|
+
getText: this.#getText,
|
|
117
|
+
text: this.#text,
|
|
118
|
+
messages: this.#messages,
|
|
119
|
+
pdf: this.#pdf,
|
|
120
|
+
label: this.getAttribute("label") ?? void 0,
|
|
121
|
+
viewerClaims: claims ? JSON.parse(claims) : void 0,
|
|
122
|
+
sizes: this.getAttribute("sizes") ?? void 0,
|
|
123
|
+
pageSize: pageSize ? Number(pageSize) : void 0,
|
|
124
|
+
initialPage: initialPage ? Number(initialPage) : void 0
|
|
125
|
+
};
|
|
126
|
+
if (this.#viewer) this.#viewer.update(options);
|
|
127
|
+
else this.#viewer = ASSET_VIEWERS[this.kind](this, options);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
/** `<calmlens-image-viewer>`: an image asset's rendered file, fitted to the element. */
|
|
131
|
+
var CalmLensImageViewerElement = class extends ViewerElement {
|
|
132
|
+
constructor(..._args) {
|
|
133
|
+
super(..._args);
|
|
134
|
+
this.kind = "image";
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
/** `<calmlens-website-viewer>`: a website's screenshot and a link to the page. */
|
|
138
|
+
var CalmLensWebsiteViewerElement = class extends ViewerElement {
|
|
139
|
+
constructor(..._args2) {
|
|
140
|
+
super(..._args2);
|
|
141
|
+
this.kind = "website";
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
/** `<calmlens-text-viewer>`: text, escaped, in a scrolling region. */
|
|
145
|
+
var CalmLensTextViewerElement = class extends ViewerElement {
|
|
146
|
+
constructor(..._args3) {
|
|
147
|
+
super(..._args3);
|
|
148
|
+
this.kind = "text";
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
/** `<calmlens-document-viewer>`: a PDF a page at a time, with pdf.js loaded lazily. */
|
|
152
|
+
var CalmLensDocumentViewerElement = class extends ViewerElement {
|
|
153
|
+
constructor(..._args4) {
|
|
154
|
+
super(..._args4);
|
|
155
|
+
this.kind = "document";
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
/** `<calmlens-spreadsheet-viewer>`: a spreadsheet's sheets as tabs and paged tables. */
|
|
159
|
+
var CalmLensSpreadsheetViewerElement = class extends ViewerElement {
|
|
160
|
+
constructor(..._args5) {
|
|
161
|
+
super(..._args5);
|
|
162
|
+
this.kind = "spreadsheet";
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const ELEMENTS = {
|
|
166
|
+
"calmlens-image-viewer": CalmLensImageViewerElement,
|
|
167
|
+
"calmlens-website-viewer": CalmLensWebsiteViewerElement,
|
|
168
|
+
"calmlens-text-viewer": CalmLensTextViewerElement,
|
|
169
|
+
"calmlens-document-viewer": CalmLensDocumentViewerElement,
|
|
170
|
+
"calmlens-spreadsheet-viewer": CalmLensSpreadsheetViewerElement
|
|
171
|
+
};
|
|
172
|
+
/** Defines the asset viewer elements, if they aren't defined yet. */
|
|
173
|
+
const defineCalmLensViewerElements = () => {
|
|
174
|
+
if (typeof customElements === "undefined") return;
|
|
175
|
+
for (const [name, element] of Object.entries(ELEMENTS)) if (!customElements.get(name)) customElements.define(name, element);
|
|
176
|
+
};
|
|
177
|
+
defineCalmLensViewerElements();
|
|
4
178
|
// src/elements.ts
|
|
5
179
|
const el = (tag, attributes = {}, children = []) => {
|
|
6
180
|
const node = document.createElement(tag);
|
|
@@ -342,187 +516,382 @@ var CalmLensUploaderElement = class extends BaseElement {
|
|
|
342
516
|
}
|
|
343
517
|
};
|
|
344
518
|
/**
|
|
345
|
-
* `<calmlens-
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* `transform`, `widths` (comma-separated), `
|
|
350
|
-
* `
|
|
351
|
-
* `
|
|
352
|
-
* `
|
|
519
|
+
* `<calmlens-asset src="…" alt="…">` shows any asset from its asset URL (public, or signed by your
|
|
520
|
+
* server), natively in the page, the same way `CalmLensAsset` does in React, Vue and Svelte. It
|
|
521
|
+
* reads `{src}/info` once connected, unless the `info` property is set. Attributes: `src`,
|
|
522
|
+
* `display` (`full` or `preview`), `viewer-claims` (JSON), `alt`, `fit`, `aspect-ratio`, `eager`,
|
|
523
|
+
* `fetch-priority`, `lens`, `transform`, `widths` (comma-separated), `sizes`, `no-controls`,
|
|
524
|
+
* `autoplay`, `muted`, `loop`, `no-stream`, `initial-page` and `page-size`. Properties: `info`,
|
|
525
|
+
* `onExpired` (returns a fresh signed asset URL), `messages`, `pdf`, `getText` (a spreadsheet's
|
|
526
|
+
* sheets), and `renderUnavailable` / `renderAgeGate` (return your own notice's node). Events:
|
|
527
|
+
* `calmlens-load`, `calmlens-error`, `calmlens-availability-change` (detail: the availability),
|
|
528
|
+
* `calmlens-age-confirm-request`, `calmlens-play`, `calmlens-ended` and `calmlens-timeupdate`
|
|
529
|
+
* (detail: the position in seconds).
|
|
353
530
|
*/
|
|
354
|
-
var
|
|
531
|
+
var CalmLensAssetElement = class extends BaseElement {
|
|
355
532
|
static {
|
|
356
533
|
this.observedAttributes = [
|
|
357
|
-
"
|
|
358
|
-
"
|
|
359
|
-
"status",
|
|
360
|
-
"content-removed",
|
|
361
|
-
"type",
|
|
362
|
-
"resource",
|
|
363
|
-
"lens",
|
|
364
|
-
"transform",
|
|
365
|
-
"widths",
|
|
366
|
-
"url",
|
|
367
|
-
"no-placeholder",
|
|
368
|
-
"placeholder-hash",
|
|
369
|
-
"placeholder-url",
|
|
370
|
-
"average-color",
|
|
371
|
-
"cdn-base-url",
|
|
534
|
+
"src",
|
|
535
|
+
"display",
|
|
372
536
|
"viewer-claims",
|
|
373
537
|
"alt",
|
|
374
|
-
"aspect-ratio",
|
|
375
|
-
"width",
|
|
376
|
-
"height",
|
|
377
|
-
"sizes",
|
|
378
538
|
"fit",
|
|
379
|
-
"
|
|
539
|
+
"aspect-ratio",
|
|
380
540
|
"eager",
|
|
381
541
|
"fetch-priority",
|
|
382
|
-
"
|
|
542
|
+
"lens",
|
|
543
|
+
"transform",
|
|
544
|
+
"widths",
|
|
545
|
+
"sizes",
|
|
546
|
+
"no-controls",
|
|
547
|
+
"autoplay",
|
|
548
|
+
"muted",
|
|
549
|
+
"loop",
|
|
550
|
+
"no-stream",
|
|
551
|
+
"initial-page",
|
|
552
|
+
"page-size"
|
|
383
553
|
];
|
|
384
554
|
}
|
|
385
555
|
#messages;
|
|
386
|
-
#
|
|
556
|
+
#info;
|
|
557
|
+
#onExpired;
|
|
558
|
+
#pdf;
|
|
559
|
+
#getText;
|
|
560
|
+
#renderUnavailable;
|
|
561
|
+
#renderAgeGate;
|
|
387
562
|
#loadKey;
|
|
563
|
+
#availability;
|
|
564
|
+
#session = new AssetSession(() => this.#render());
|
|
565
|
+
#streams = new MediaStreamPlayer((media) => {
|
|
566
|
+
this.#session.mediaFailed({
|
|
567
|
+
position: media.currentTime || 0,
|
|
568
|
+
playing: !media.paused && !media.ended
|
|
569
|
+
});
|
|
570
|
+
return true;
|
|
571
|
+
});
|
|
572
|
+
#viewers = new AssetViewerMount();
|
|
388
573
|
get messages() {
|
|
389
574
|
return this.#messages;
|
|
390
575
|
}
|
|
391
576
|
set messages(value) {
|
|
392
577
|
this.#messages = value;
|
|
393
|
-
this.#
|
|
578
|
+
this.#rerender();
|
|
579
|
+
}
|
|
580
|
+
/** The asset's display info, prefetched with `getAssetInfo`, so nothing waits for `/info`. */
|
|
581
|
+
get info() {
|
|
582
|
+
return this.#info;
|
|
583
|
+
}
|
|
584
|
+
set info(value) {
|
|
585
|
+
this.#info = value;
|
|
394
586
|
this.#render();
|
|
395
587
|
}
|
|
396
|
-
/**
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
*/
|
|
400
|
-
get asset() {
|
|
401
|
-
return this.#asset;
|
|
588
|
+
/** Returns a fresh asset URL from your server once a signed one expires. */
|
|
589
|
+
get onExpired() {
|
|
590
|
+
return this.#onExpired;
|
|
402
591
|
}
|
|
403
|
-
set
|
|
404
|
-
this.#
|
|
592
|
+
set onExpired(value) {
|
|
593
|
+
this.#onExpired = value;
|
|
594
|
+
this.#render();
|
|
595
|
+
}
|
|
596
|
+
/** Where a document's pdf.js loads its worker, fonts and decoders from. */
|
|
597
|
+
get pdf() {
|
|
598
|
+
return this.#pdf;
|
|
599
|
+
}
|
|
600
|
+
set pdf(value) {
|
|
601
|
+
this.#pdf = value;
|
|
405
602
|
this.#render();
|
|
406
603
|
}
|
|
604
|
+
/** Reads a spreadsheet's sheets yourself, such as from its text child asset. */
|
|
605
|
+
get getText() {
|
|
606
|
+
return this.#getText;
|
|
607
|
+
}
|
|
608
|
+
set getText(value) {
|
|
609
|
+
this.#getText = value;
|
|
610
|
+
this.#render();
|
|
611
|
+
}
|
|
612
|
+
/** Returns your own unavailable notice. */
|
|
613
|
+
get renderUnavailable() {
|
|
614
|
+
return this.#renderUnavailable;
|
|
615
|
+
}
|
|
616
|
+
set renderUnavailable(value) {
|
|
617
|
+
this.#renderUnavailable = value;
|
|
618
|
+
this.#rerender();
|
|
619
|
+
}
|
|
620
|
+
/** Returns your own age notice; call `confirm` from its reveal button. */
|
|
621
|
+
get renderAgeGate() {
|
|
622
|
+
return this.#renderAgeGate;
|
|
623
|
+
}
|
|
624
|
+
set renderAgeGate(value) {
|
|
625
|
+
this.#renderAgeGate = value;
|
|
626
|
+
this.#rerender();
|
|
627
|
+
}
|
|
407
628
|
connectedCallback() {
|
|
408
|
-
upgradeProperties(this, [
|
|
409
|
-
|
|
629
|
+
upgradeProperties(this, [
|
|
630
|
+
"messages",
|
|
631
|
+
"info",
|
|
632
|
+
"onExpired",
|
|
633
|
+
"pdf",
|
|
634
|
+
"getText",
|
|
635
|
+
"renderUnavailable",
|
|
636
|
+
"renderAgeGate"
|
|
637
|
+
]);
|
|
638
|
+
this.classList.add("calmlens-asset");
|
|
410
639
|
this.setAttribute("role", "figure");
|
|
411
640
|
this.#render();
|
|
412
641
|
}
|
|
413
642
|
attributeChangedCallback() {
|
|
414
643
|
this.#render();
|
|
415
644
|
}
|
|
416
|
-
|
|
645
|
+
disconnectedCallback() {
|
|
646
|
+
this.#streams.stop();
|
|
647
|
+
this.#viewers.destroy();
|
|
648
|
+
this.#loadKey = void 0;
|
|
649
|
+
}
|
|
650
|
+
#rerender() {
|
|
651
|
+
this.#loadKey = void 0;
|
|
652
|
+
this.#render();
|
|
653
|
+
}
|
|
654
|
+
#emit(name, detail) {
|
|
655
|
+
this.dispatchEvent(new CustomEvent(name, {
|
|
656
|
+
bubbles: true,
|
|
657
|
+
detail
|
|
658
|
+
}));
|
|
659
|
+
}
|
|
660
|
+
#options() {
|
|
417
661
|
const list = (name) => this.getAttribute(name)?.split(",").map((value) => value.trim()).filter(Boolean);
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
662
|
+
let viewerClaims;
|
|
663
|
+
try {
|
|
664
|
+
viewerClaims = this.hasAttribute("viewer-claims") ? JSON.parse(this.getAttribute("viewer-claims")) : void 0;
|
|
665
|
+
} catch {}
|
|
666
|
+
return {
|
|
667
|
+
src: this.getAttribute("src") || void 0,
|
|
668
|
+
display: this.getAttribute("display") ?? void 0,
|
|
669
|
+
viewerClaims,
|
|
670
|
+
info: this.#info,
|
|
671
|
+
alt: this.getAttribute("alt") ?? "",
|
|
672
|
+
image: {
|
|
673
|
+
lens: this.getAttribute("lens") ?? void 0,
|
|
674
|
+
transform: this.getAttribute("transform") ?? void 0,
|
|
675
|
+
widths: list("widths")?.map(Number),
|
|
676
|
+
sizes: this.getAttribute("sizes") ?? void 0
|
|
677
|
+
},
|
|
678
|
+
video: {
|
|
679
|
+
controls: !this.hasAttribute("no-controls"),
|
|
680
|
+
autoPlay: this.hasAttribute("autoplay"),
|
|
681
|
+
muted: this.hasAttribute("muted"),
|
|
682
|
+
loop: this.hasAttribute("loop"),
|
|
683
|
+
stream: !this.hasAttribute("no-stream")
|
|
684
|
+
},
|
|
685
|
+
document: {
|
|
686
|
+
initialPage: numberAttribute(this, "initial-page"),
|
|
687
|
+
pdf: this.#pdf
|
|
688
|
+
},
|
|
689
|
+
spreadsheet: {
|
|
690
|
+
pageSize: numberAttribute(this, "page-size"),
|
|
691
|
+
getText: this.#getText
|
|
692
|
+
},
|
|
693
|
+
onExpired: this.#onExpired
|
|
694
|
+
};
|
|
439
695
|
}
|
|
440
696
|
#render() {
|
|
441
697
|
if (!this.isConnected) return;
|
|
442
|
-
const options = this.#
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
const ratio =
|
|
447
|
-
aspectRatio: numberAttribute(this, "aspect-ratio"),
|
|
448
|
-
width: options.width,
|
|
449
|
-
height: options.height
|
|
450
|
-
});
|
|
698
|
+
const options = this.#options();
|
|
699
|
+
const state = this.#session.update(options);
|
|
700
|
+
this.#session.load();
|
|
701
|
+
const view = getAssetView(options, state);
|
|
702
|
+
const ratio = getAssetAspectRatio(view, state.info, numberAttribute(this, "aspect-ratio"));
|
|
451
703
|
this.style.aspectRatio = ratio ? String(ratio) : "";
|
|
452
704
|
this.toggleAttribute("data-sized", Boolean(ratio));
|
|
453
|
-
this.style.backgroundColor =
|
|
705
|
+
this.style.backgroundColor = state.info?.content?.preview?.averageColor ?? "";
|
|
454
706
|
this.style.setProperty("--calmlens-fit", this.getAttribute("fit"));
|
|
455
|
-
this.
|
|
456
|
-
this.
|
|
457
|
-
|
|
707
|
+
this.dataset.kind = view.kind;
|
|
708
|
+
this.toggleAttribute("aria-busy", view.kind === "pending");
|
|
709
|
+
const availability = view.kind === "unavailable" ? "unavailable" : view.kind === "age-restricted" ? "age-restricted" : view.kind === "pending" ? void 0 : "available";
|
|
710
|
+
if (availability && availability !== this.#availability) {
|
|
711
|
+
this.#availability = availability;
|
|
712
|
+
this.#emit("calmlens-availability-change", availability);
|
|
713
|
+
}
|
|
714
|
+
const viewerOptions = getMountedViewerOptions(options, this.#session);
|
|
715
|
+
const loadKey = `${getAssetViewKey(view)} ${options.alt} ${options.image.sizes} ${options.video.controls}`;
|
|
716
|
+
if (loadKey === this.#loadKey) {
|
|
717
|
+
if (isMountedViewerKind(view.kind)) this.#viewers.update(this.querySelector(".calmlens-asset__viewer"), view.kind, viewerOptions);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
458
720
|
this.#loadKey = loadKey;
|
|
459
721
|
this.dataset.state = "loading";
|
|
722
|
+
this.#viewers.destroy();
|
|
460
723
|
const messages = resolveMessages(this.#messages);
|
|
461
|
-
const alt =
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
724
|
+
const { alt } = options;
|
|
725
|
+
const loaded = () => {
|
|
726
|
+
this.#session.loaded();
|
|
727
|
+
this.dataset.state = "loaded";
|
|
728
|
+
this.querySelector(":scope > .calmlens-asset__placeholder")?.remove();
|
|
729
|
+
this.#emit("calmlens-load");
|
|
730
|
+
};
|
|
731
|
+
const placeholderUrl = "placeholderUrl" in view ? view.placeholderUrl : void 0;
|
|
732
|
+
const placeholder = placeholderUrl ? el("img", {
|
|
733
|
+
class: "calmlens-asset__placeholder",
|
|
734
|
+
src: placeholderUrl,
|
|
466
735
|
alt: "",
|
|
467
736
|
"aria-hidden": "true"
|
|
468
737
|
}) : void 0;
|
|
469
|
-
const notice = (children) => el("div", { class: "calmlens-
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
738
|
+
const notice = (children) => el("div", { class: "calmlens-asset__notice" }, children);
|
|
739
|
+
const playable = (media) => {
|
|
740
|
+
media.addEventListener("loadedmetadata", () => {
|
|
741
|
+
this.#session.mediaLoaded(media);
|
|
742
|
+
this.dataset.state = "loaded";
|
|
743
|
+
this.#emit("calmlens-load");
|
|
744
|
+
});
|
|
745
|
+
media.addEventListener("error", () => {
|
|
746
|
+
if (this.#streams.recover(media)) return;
|
|
747
|
+
this.#session.mediaFailed({
|
|
748
|
+
position: media.currentTime || 0,
|
|
749
|
+
playing: !media.paused && !media.ended
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
media.addEventListener("play", () => this.#emit("calmlens-play"));
|
|
753
|
+
media.addEventListener("ended", () => this.#emit("calmlens-ended"));
|
|
754
|
+
media.addEventListener("timeupdate", () => this.#emit("calmlens-timeupdate", media.currentTime));
|
|
755
|
+
return media;
|
|
474
756
|
};
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}, [messages.reveal]);
|
|
482
|
-
reveal.addEventListener("click", () => this.dispatchEvent(new CustomEvent("calmlens-reveal", { bubbles: true })));
|
|
483
|
-
this.replaceChildren(...[placeholder].filter((node) => node !== void 0), notice([
|
|
484
|
-
el("strong", {}, [messages.sensitiveTitle]),
|
|
485
|
-
el("p", {}, [messages.sensitiveBody]),
|
|
486
|
-
reveal
|
|
487
|
-
]));
|
|
488
|
-
} else if (state.kind === "image") {
|
|
489
|
-
const image = el("img", {
|
|
490
|
-
class: "calmlens-media__content",
|
|
491
|
-
src: state.src,
|
|
492
|
-
srcset: state.srcSet,
|
|
493
|
-
sizes,
|
|
757
|
+
const image = (shown) => {
|
|
758
|
+
const content = el("img", {
|
|
759
|
+
class: "calmlens-asset__content",
|
|
760
|
+
src: shown.src,
|
|
761
|
+
srcset: shown.srcSet,
|
|
762
|
+
sizes: shown.srcSet ? options.image.sizes : void 0,
|
|
494
763
|
alt,
|
|
495
|
-
width:
|
|
496
|
-
height:
|
|
764
|
+
width: shown.width,
|
|
765
|
+
height: shown.height,
|
|
497
766
|
loading: this.hasAttribute("eager") ? void 0 : "lazy",
|
|
498
767
|
decoding: "async",
|
|
499
768
|
fetchpriority: this.getAttribute("fetch-priority") ?? void 0
|
|
500
769
|
});
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
770
|
+
content.addEventListener("load", loaded);
|
|
771
|
+
content.addEventListener("error", () => this.#session.failed());
|
|
772
|
+
return content;
|
|
773
|
+
};
|
|
774
|
+
const present = (...nodes) => this.replaceChildren(...nodes.filter((node) => node !== void 0));
|
|
775
|
+
if (view.kind === "unavailable") {
|
|
776
|
+
this.dataset.state = "error";
|
|
777
|
+
this.#emit("calmlens-error");
|
|
778
|
+
present(this.#renderUnavailable?.() ?? notice([el("p", {}, [icon("unavailable"), el("span", { class: "calmlens-asset__label" }, [messages.unavailable])])]));
|
|
779
|
+
} else if (view.kind === "age-restricted") {
|
|
780
|
+
const confirm = () => this.#emit("calmlens-age-confirm-request");
|
|
781
|
+
if (this.#renderAgeGate) present(placeholder, this.#renderAgeGate({
|
|
782
|
+
placeholderUrl,
|
|
783
|
+
confirm
|
|
784
|
+
}));
|
|
785
|
+
else {
|
|
786
|
+
const reveal = el("button", {
|
|
787
|
+
type: "button",
|
|
788
|
+
class: "calmlens-button"
|
|
789
|
+
}, [messages.reveal]);
|
|
790
|
+
reveal.addEventListener("click", confirm);
|
|
791
|
+
present(placeholder, notice([
|
|
792
|
+
el("strong", {}, [messages.sensitiveTitle]),
|
|
793
|
+
el("p", {}, [messages.sensitiveBody]),
|
|
794
|
+
reveal
|
|
795
|
+
]));
|
|
796
|
+
}
|
|
797
|
+
} else if (view.kind === "pending") present(placeholder);
|
|
798
|
+
else if (view.kind === "image") present(placeholder, image(view));
|
|
799
|
+
else if (view.kind === "website") present(placeholder, view.link ? el("div", { class: "calmlens-asset__bar" }, [el("a", {
|
|
800
|
+
class: "calmlens-button",
|
|
801
|
+
href: view.link,
|
|
802
|
+
target: "_blank",
|
|
803
|
+
rel: "noopener noreferrer nofollow"
|
|
804
|
+
}, [formatMessage(messages.openWebsite, { host: new URL(view.link).host })])]) : void 0, el("div", {
|
|
805
|
+
class: "calmlens-asset__scroll",
|
|
806
|
+
role: "region",
|
|
807
|
+
"aria-label": alt || void 0,
|
|
808
|
+
tabindex: 0
|
|
809
|
+
}, [image(view)]));
|
|
810
|
+
else if (view.kind === "video") present(playable(el("video", {
|
|
811
|
+
class: "calmlens-asset__content",
|
|
812
|
+
src: view.stream ? void 0 : view.src,
|
|
813
|
+
poster: view.poster,
|
|
814
|
+
controls: options.video.controls,
|
|
815
|
+
autoplay: options.video.autoPlay,
|
|
816
|
+
muted: options.video.muted,
|
|
817
|
+
loop: options.video.loop,
|
|
818
|
+
playsinline: true,
|
|
819
|
+
preload: "metadata",
|
|
820
|
+
"aria-label": alt || void 0
|
|
821
|
+
})));
|
|
822
|
+
else if (view.kind === "audio") {
|
|
823
|
+
const audio = playable(el("audio", {
|
|
824
|
+
class: "calmlens-asset__content",
|
|
825
|
+
src: view.stream ? void 0 : view.src,
|
|
826
|
+
controls: options.video.controls,
|
|
827
|
+
autoplay: options.video.autoPlay,
|
|
828
|
+
muted: options.video.muted,
|
|
829
|
+
loop: options.video.loop,
|
|
513
830
|
preload: "metadata",
|
|
514
831
|
"aria-label": alt || void 0
|
|
832
|
+
}));
|
|
833
|
+
const progress = view.peaks && waveformProgress(view.peaks);
|
|
834
|
+
if (progress) audio.addEventListener("timeupdate", () => {
|
|
835
|
+
const played = getPlayedPercent(audio);
|
|
836
|
+
progress.setAttribute("aria-valuenow", String(played));
|
|
837
|
+
progress.style.setProperty("--calmlens-played", `${played}%`);
|
|
838
|
+
});
|
|
839
|
+
present(view.waveformUrl || progress ? el("div", { class: "calmlens-asset__waveform" }, [view.waveformUrl && el("img", {
|
|
840
|
+
class: "calmlens-asset__wave",
|
|
841
|
+
src: view.waveformUrl,
|
|
842
|
+
alt: "",
|
|
843
|
+
"aria-hidden": "true"
|
|
844
|
+
}), progress]) : void 0, audio);
|
|
845
|
+
} else if (isMountedViewerKind(view.kind)) {
|
|
846
|
+
const root = el("div", { class: "calmlens-asset__viewer" });
|
|
847
|
+
present(root);
|
|
848
|
+
this.#viewers.update(root, view.kind, viewerOptions, (viewerState) => {
|
|
849
|
+
if (viewerState === "loading") return;
|
|
850
|
+
this.dataset.state = viewerState;
|
|
851
|
+
this.#emit(viewerState === "loaded" ? "calmlens-load" : "calmlens-error");
|
|
515
852
|
});
|
|
516
|
-
|
|
517
|
-
|
|
853
|
+
} else if (view.kind === "file") {
|
|
854
|
+
const file = el("span", {
|
|
855
|
+
class: "calmlens-asset__file",
|
|
856
|
+
role: "img",
|
|
857
|
+
"aria-label": alt || void 0,
|
|
858
|
+
"aria-hidden": alt ? void 0 : "true"
|
|
859
|
+
});
|
|
860
|
+
file.innerHTML = renderFileIconSvg({
|
|
861
|
+
family: view.icon,
|
|
862
|
+
extension: ""
|
|
863
|
+
}, 64);
|
|
864
|
+
present(file);
|
|
518
865
|
}
|
|
866
|
+
this.#streams.update(this.querySelector("video, audio"), view);
|
|
519
867
|
}
|
|
520
868
|
};
|
|
521
|
-
/**
|
|
869
|
+
/** Audio's progress drawn over its waveform; decorative, as the audio's own controls report it. */
|
|
870
|
+
const waveformProgress = (peaks) => {
|
|
871
|
+
const bars = (played) => el("div", {
|
|
872
|
+
class: "calmlens-asset__peaks",
|
|
873
|
+
"data-played": played
|
|
874
|
+
}, getPeakHeights(peaks).map((height) => {
|
|
875
|
+
const bar = el("span");
|
|
876
|
+
bar.style.height = `${height}%`;
|
|
877
|
+
return bar;
|
|
878
|
+
}));
|
|
879
|
+
const progress = el("div", {
|
|
880
|
+
class: "calmlens-asset__progress",
|
|
881
|
+
role: "progressbar",
|
|
882
|
+
"aria-hidden": "true",
|
|
883
|
+
"aria-valuemin": 0,
|
|
884
|
+
"aria-valuemax": 100,
|
|
885
|
+
"aria-valuenow": 0
|
|
886
|
+
}, [bars(false), bars(true)]);
|
|
887
|
+
progress.style.setProperty("--calmlens-played", "0%");
|
|
888
|
+
return progress;
|
|
889
|
+
};
|
|
890
|
+
/** Defines `<calmlens-uploader>` and `<calmlens-asset>`, if they aren't defined yet. */
|
|
522
891
|
const defineCalmLensElements = () => {
|
|
523
892
|
if (typeof customElements === "undefined") return;
|
|
524
893
|
if (!customElements.get("calmlens-uploader")) customElements.define("calmlens-uploader", CalmLensUploaderElement);
|
|
525
|
-
if (!customElements.get("calmlens-
|
|
894
|
+
if (!customElements.get("calmlens-asset")) customElements.define("calmlens-asset", CalmLensAssetElement);
|
|
526
895
|
};
|
|
527
896
|
defineCalmLensElements();
|
|
528
|
-
export { CALMLENS_STYLES, CALMLENS_THEME,
|
|
897
|
+
export { ASSET_FILE_ICON_SIZE, ASSET_VIEWERS, AssetSession, AssetViewerMount, CALMLENS_STYLES, CALMLENS_THEME, CalmLensAssetElement, CalmLensDocumentViewerElement, CalmLensImageViewerElement, CalmLensSpreadsheetViewerElement, CalmLensTextViewerElement, CalmLensUploaderElement, CalmLensWebsiteViewerElement, DEFAULT_MESSAGES, DEFAULT_VIEWER_MESSAGES, ICONS, ICON_ATTRIBUTES, MediaStreamPlayer, UploadController, VIEWER_STYLES, createDocumentViewer, createImageViewer, createProgressFetch, createSpreadsheetViewer, createTextViewer, createUploadController, createWebsiteViewer, defineCalmLensElements, defineCalmLensViewerElements, describeUploadItem, describeUploader, formatBytes, formatMessage, formatViewerMessage, getAssetAspectRatio, getAssetView, getAssetViewKey, getAssetViewerKind, getDropzoneHint, getMountedViewerOptions, getPeakHeights, getPlayedPercent, getSpreadsheetPage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, isMountedViewerKind, isSpreadsheetFormat, loadPdfJs, parseSpreadsheetText, pickAssetSource, resolveMessages, resolveTheme, resolveViewerMessages, spreadsheetColumnIndex };
|