@calmlens/sdk 0.16.3 → 0.18.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 +425 -181
- package/bin/calmlens.js +16016 -0
- package/bin/package.json +1 -0
- package/cjs/BrowserUpload-BT091eOB.d.ts +11 -0
- package/cjs/BrowserUpload-CQwXEGFv.js +10 -0
- package/cjs/CalmLensAppClient-CHQGu-Do.js +89 -0
- package/cjs/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
- package/cjs/CalmLensConnection-B8Bu2j3y.js +659 -0
- package/cjs/CalmLensServerClient-C5o2A8MW.js +645 -0
- package/cjs/CalmLensServerClient-JtP687a3.d.ts +235 -0
- package/cjs/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
- package/cjs/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
- package/cjs/CryptoUtils-B_x8lMIx-YBW1-bvL.js +42 -0
- package/cjs/FileIcons-Ob003MdS.js +175 -0
- package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +91 -0
- package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
- package/cjs/ModerationContextLimits-DelWfmiJ.js +1311 -0
- package/cjs/ReactUpload-CAyCsyG6.d.ts +17 -0
- package/cjs/ReactUpload-Cfg5JYUq.js +54 -0
- package/cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
- package/cjs/TestTriggers-DTc_iMJF-BjMPq4_3.js +1327 -0
- package/cjs/UploadController-BGO1eyzb.js +618 -0
- package/{esm/index-C9Xw1aid.d.ts → cjs/WebhookPayload-2aL31v0J.d.ts} +131 -155
- package/cjs/app.d.ts +7 -44
- package/cjs/app.js +11 -89
- package/cjs/elements.d.ts +88 -0
- package/cjs/elements.js +555 -0
- package/cjs/file-icons.d.ts +67 -0
- package/cjs/file-icons.js +10 -0
- package/cjs/index-CI4BzN4W.d.ts +252 -0
- package/cjs/index.d.ts +6 -4
- package/cjs/index.js +9 -4
- package/cjs/react-native.d.ts +56 -0
- package/cjs/react-native.js +495 -0
- package/cjs/react.d.ts +30 -0
- package/cjs/react.js +370 -0
- package/cjs/server.d.ts +12 -191
- package/cjs/server.js +18 -378
- package/cjs/test-inputs.d.ts +2 -2
- package/cjs/test-inputs.js +9 -264
- package/cjs/testing.d.ts +285 -190
- package/cjs/testing.js +2393 -1203
- package/cjs/ui-CC1GOoMg.js +583 -0
- package/cjs/ui-wIiMfqMB.d.ts +526 -0
- package/cjs/ui.d.ts +2 -0
- package/cjs/ui.js +27 -0
- package/cjs/vue.d.ts +490 -0
- package/cjs/vue.js +419 -0
- package/esm/BrowserUpload-BT091eOB.d.ts +11 -0
- package/esm/BrowserUpload-D2xBWqhm.js +5 -0
- package/esm/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
- package/esm/CalmLensAppClient-DuFas_dW.js +84 -0
- package/esm/CalmLensConnection-MxwwLXdl.js +582 -0
- package/esm/CalmLensServerClient-D80_mKpW.js +586 -0
- package/esm/CalmLensServerClient-JtP687a3.d.ts +235 -0
- package/esm/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
- package/esm/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
- package/esm/CryptoUtils-B_x8lMIx-DhuWGzqn.js +25 -0
- package/esm/FileIcons-M6dzjFxd.js +128 -0
- package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +46 -0
- package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
- package/esm/ModerationContextLimits-BaX2QnU8.js +1114 -0
- package/esm/ReactUpload-CAyCsyG6.d.ts +17 -0
- package/esm/ReactUpload-CL2XC8WS.js +37 -0
- package/esm/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
- package/esm/TestTriggers-DTc_iMJF-HfB533Gx.js +1267 -0
- package/esm/UploadController-qjoYGCwx.js +589 -0
- package/{cjs/index-C9Xw1aid.d.ts → esm/WebhookPayload-2aL31v0J.d.ts} +131 -155
- package/esm/app.d.ts +7 -44
- package/esm/app.js +3 -86
- package/esm/elements.d.ts +88 -0
- package/esm/elements.js +528 -0
- package/esm/file-icons.d.ts +67 -0
- package/esm/file-icons.js +1 -0
- package/esm/index-CI4BzN4W.d.ts +252 -0
- package/esm/index.d.ts +6 -4
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +56 -0
- package/esm/react-native.js +467 -0
- package/esm/react.d.ts +30 -0
- package/esm/react.js +343 -0
- package/esm/server.d.ts +12 -191
- package/esm/server.js +3 -369
- package/esm/styles.css +147 -0
- package/esm/svelte/CalmLensMedia.svelte +134 -0
- package/esm/svelte/CalmLensUploader.svelte +175 -0
- package/esm/svelte/Icon.svelte +7 -0
- package/esm/svelte/index.d.ts +37 -0
- package/esm/svelte/index.js +6 -0
- package/esm/test-inputs.d.ts +2 -2
- package/esm/test-inputs.js +1 -256
- package/esm/testing.d.ts +285 -190
- package/esm/testing.js +2329 -1122
- package/esm/ui-CCY3yXFn.js +458 -0
- package/esm/ui-wIiMfqMB.d.ts +526 -0
- package/esm/ui.d.ts +2 -0
- package/esm/ui.js +3 -0
- package/esm/vue.d.ts +490 -0
- package/esm/vue.js +392 -0
- package/package.json +118 -13
- package/cjs/CalmLensConnection-BNUHp_AQ.js +0 -234
- package/cjs/CalmLensUtils-o171ownK.js +0 -699
- package/cjs/CalmLensVersion-DwhgxQK5.js +0 -480
- package/cjs/CalmLensWebhooks-BKrq30Yp.js +0 -201
- package/cjs/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
- package/cjs/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
- package/cjs/WebhookPayload-CJoIkGBD.d.ts +0 -11753
- package/esm/CalmLensConnection-XTqmlwzG.js +0 -193
- package/esm/CalmLensUtils-DsF8Aa_x.js +0 -574
- package/esm/CalmLensVersion-DcifRKsx.js +0 -415
- package/esm/CalmLensWebhooks-BvGyk5d3.js +0 -148
- package/esm/Classification-BNhgwGEm-DmA9VEuE.d.ts +0 -4806
- package/esm/TestTriggers-CRKtulyp-vrzEq2wm.d.ts +0 -44
- package/esm/WebhookPayload-CJoIkGBD.d.ts +0 -11753
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { A as CustomUploadResult, B as MediaAsset, C as getDropzoneHint, D as resolveMessages, E as getUploadItemOutcome, G as MediaState, H as MediaOptions, J as resolveMediaProps, K as getMediaState, L as UploadStage, M as UploadController, P as UploadFile, S as formatMessage, T as getUploadItemMessage, U as MediaSettings, V as MediaImageSource, W as MediaSource, _ as UploadItemView, a as createProgressFetch, b as describeUploader, c as IconName, d as UploaderDisplayOptions, g as DEFAULT_MESSAGES, h as CalmLensMessages, i as CALMLENS_STYLES, j as UploadClient, k as CustomUploadContext, l as MediaDisplayOptions, m as getMediaLoadKey, n as CalmLensTheme, o as ICONS, p as getMediaAspectRatio, q as pickMediaSource, r as resolveTheme, s as ICON_ATTRIBUTES, t as CALMLENS_THEME, u as MediaProps, v as UploaderView, w as getMediaUnavailableMessage, x as formatBytes, y as describeUploadItem, z as isFileAccepted } from "./ui-wIiMfqMB.js";
|
|
2
|
+
import { a as UploaderProps, i as UploadSnapshot, n as UploadControllerOptions, r as UploadItem, s as createUploadController, t as CalmLensUpload } from "./BrowserUpload-BT091eOB.js";
|
|
3
|
+
/** The `detail` of each event the elements dispatch. */
|
|
4
|
+
export interface CalmLensElementEvents {
|
|
5
|
+
"calmlens-uploaded": CalmLensUpload;
|
|
6
|
+
"calmlens-rejected": UploadItem;
|
|
7
|
+
"calmlens-failed": UploadItem;
|
|
8
|
+
"calmlens-removed": UploadItem;
|
|
9
|
+
"calmlens-change": UploadSnapshot;
|
|
10
|
+
"calmlens-reveal": undefined;
|
|
11
|
+
}
|
|
12
|
+
declare const BaseElement: typeof HTMLElement;
|
|
13
|
+
/**
|
|
14
|
+
* `<calmlens-uploader upload-preset-id="…" token-url="/api/upload-token">` uploads through an
|
|
15
|
+
* upload preset and dispatches `calmlens-uploaded` with `{ assetId, status, file }` for each
|
|
16
|
+
* finished upload. Attributes: `upload-preset-id`, `token-url`, `accept`, `max-file-size`
|
|
17
|
+
* (bytes), `no-auto-upload`, `multiple`, `max-files`, `disabled`, `capture` and `base-url`. Set
|
|
18
|
+
* the `token`, `upload`, `checkStatus`, `messages` and `controller` properties from script for
|
|
19
|
+
* anything an attribute can't hold.
|
|
20
|
+
*/
|
|
21
|
+
export declare class CalmLensUploaderElement extends BaseElement {
|
|
22
|
+
#private;
|
|
23
|
+
static observedAttributes: string[];
|
|
24
|
+
/** The upload token, or a function returning one per file, instead of `token-url`. */
|
|
25
|
+
get token(): UploadControllerOptions["token"];
|
|
26
|
+
set token(value: UploadControllerOptions["token"]);
|
|
27
|
+
/** Uploads each file your own way instead of through `upload-preset-id`. */
|
|
28
|
+
get upload(): UploadControllerOptions["upload"];
|
|
29
|
+
set upload(value: UploadControllerOptions["upload"]);
|
|
30
|
+
/** Checks a pending upload made with `upload`. */
|
|
31
|
+
get checkStatus(): UploadControllerOptions["checkStatus"];
|
|
32
|
+
set checkStatus(value: UploadControllerOptions["checkStatus"]);
|
|
33
|
+
/** Creates the client for each upload, for example a `MockCalmLensAppClient` in tests. */
|
|
34
|
+
get createClient(): UploadControllerOptions["createClient"];
|
|
35
|
+
set createClient(value: UploadControllerOptions["createClient"]);
|
|
36
|
+
get messages(): Partial<CalmLensMessages> | undefined;
|
|
37
|
+
set messages(value: Partial<CalmLensMessages> | undefined);
|
|
38
|
+
/**
|
|
39
|
+
* The upload queue, for reading items or calling `start`, `retry`, `remove` and `clear`. Set it
|
|
40
|
+
* to show a queue your script created; its own options then apply instead of the attributes.
|
|
41
|
+
*/
|
|
42
|
+
get controller(): UploadController<File>;
|
|
43
|
+
set controller(value: UploadController<File>);
|
|
44
|
+
connectedCallback(): void;
|
|
45
|
+
disconnectedCallback(): void;
|
|
46
|
+
attributeChangedCallback(): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* `<calmlens-media project-id="…" asset-id="…" status="allowed" alt="…">` shows an asset from the
|
|
50
|
+
* CalmLens CDN with a blurred placeholder while it loads. Age-restricted assets show the
|
|
51
|
+
* placeholder and a reveal button, which dispatches `calmlens-reveal`, until `age-confirmed` is set.
|
|
52
|
+
* Attributes: `project-id`, `asset-id`, `status`, `age-confirmed`, `type`, `resource`, `lens`,
|
|
53
|
+
* `transform`, `widths` (comma-separated), `url`, `no-placeholder`, `placeholder-hash`,
|
|
54
|
+
* `placeholder-url`, `average-color`, `cdn-base-url`, `alt`, `aspect-ratio`, `width`, `height`,
|
|
55
|
+
* `sizes`, `fit`, `position`, `eager`, `fetch-priority` and `no-controls`. Set the
|
|
56
|
+
* `asset` property to an API asset instead of `project-id` and `asset-id`.
|
|
57
|
+
*/
|
|
58
|
+
export declare class CalmLensMediaElement extends BaseElement {
|
|
59
|
+
#private;
|
|
60
|
+
static observedAttributes: string[];
|
|
61
|
+
get messages(): Partial<CalmLensMessages> | undefined;
|
|
62
|
+
set messages(value: Partial<CalmLensMessages> | undefined);
|
|
63
|
+
/**
|
|
64
|
+
* An asset from the API, in place of `project-id` and `asset-id`. It supplies the status, type
|
|
65
|
+
* and preview too; attributes you set win over it.
|
|
66
|
+
*/
|
|
67
|
+
get asset(): MediaAsset | undefined;
|
|
68
|
+
set asset(value: MediaAsset | undefined);
|
|
69
|
+
connectedCallback(): void;
|
|
70
|
+
attributeChangedCallback(): void;
|
|
71
|
+
}
|
|
72
|
+
/** Defines `<calmlens-uploader>` and `<calmlens-media>`, if they aren't defined yet. */
|
|
73
|
+
export declare const defineCalmLensElements: () => void;
|
|
74
|
+
declare global {
|
|
75
|
+
interface HTMLElementTagNameMap {
|
|
76
|
+
"calmlens-uploader": CalmLensUploaderElement;
|
|
77
|
+
"calmlens-media": CalmLensMediaElement;
|
|
78
|
+
}
|
|
79
|
+
interface HTMLElementEventMap {
|
|
80
|
+
"calmlens-uploaded": CustomEvent<CalmLensUpload>;
|
|
81
|
+
"calmlens-rejected": CustomEvent<UploadItem>;
|
|
82
|
+
"calmlens-failed": CustomEvent<UploadItem>;
|
|
83
|
+
"calmlens-removed": CustomEvent<UploadItem>;
|
|
84
|
+
"calmlens-change": CustomEvent<UploadSnapshot>;
|
|
85
|
+
"calmlens-reveal": CustomEvent<undefined>;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export { CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, type IconName, type MediaAsset, type MediaDisplayOptions, type MediaImageSource, type MediaOptions, type MediaProps, type MediaSettings, type MediaSource, type MediaState, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme };
|
package/cjs/elements.js
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_ui = require("./ui-CC1GOoMg.js");
|
|
3
|
+
const require_UploadController = require("./UploadController-BGO1eyzb.js");
|
|
4
|
+
const require_BrowserUpload = require("./BrowserUpload-CQwXEGFv.js");
|
|
5
|
+
// src/elements.ts
|
|
6
|
+
const el = (tag, attributes = {}, children = []) => {
|
|
7
|
+
const node = document.createElement(tag);
|
|
8
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
9
|
+
if (value === void 0 || value === false) continue;
|
|
10
|
+
node.setAttribute(name, value === true ? "" : String(value));
|
|
11
|
+
}
|
|
12
|
+
for (const child of children) if (child) node.append(child);
|
|
13
|
+
return node;
|
|
14
|
+
};
|
|
15
|
+
const icon = (name) => {
|
|
16
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
17
|
+
for (const [attribute, value] of Object.entries(require_ui.ICON_ATTRIBUTES)) svg.setAttribute(attribute, value);
|
|
18
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
19
|
+
path.setAttribute("d", require_ui.ICONS[name]);
|
|
20
|
+
svg.append(path);
|
|
21
|
+
return svg;
|
|
22
|
+
};
|
|
23
|
+
/** A row's file-type icon, from the SDK's own SVG markup. */
|
|
24
|
+
const fileThumbnail = (svg) => {
|
|
25
|
+
const thumbnail = el("span", {
|
|
26
|
+
class: "calmlens-upload__thumb",
|
|
27
|
+
"data-kind": "file",
|
|
28
|
+
"aria-hidden": "true"
|
|
29
|
+
});
|
|
30
|
+
thumbnail.innerHTML = svg;
|
|
31
|
+
return thumbnail;
|
|
32
|
+
};
|
|
33
|
+
const numberAttribute = (element, name) => {
|
|
34
|
+
const value = element.getAttribute(name);
|
|
35
|
+
return value === null || value === "" ? void 0 : Number(value);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Moves properties set on an element before it was defined onto its setters. Until then they're
|
|
39
|
+
* plain own properties, which would hide the class's accessors.
|
|
40
|
+
*/
|
|
41
|
+
const upgradeProperties = (element, names) => {
|
|
42
|
+
const record = element;
|
|
43
|
+
for (const name of names) {
|
|
44
|
+
if (!Object.hasOwn(element, name)) continue;
|
|
45
|
+
const value = record[name];
|
|
46
|
+
delete record[name];
|
|
47
|
+
record[name] = value;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const BaseElement = typeof HTMLElement === "undefined" ? class {} : HTMLElement;
|
|
51
|
+
/**
|
|
52
|
+
* `<calmlens-uploader upload-preset-id="…" token-url="/api/upload-token">` uploads through an
|
|
53
|
+
* upload preset and dispatches `calmlens-uploaded` with `{ assetId, status, file }` for each
|
|
54
|
+
* finished upload. Attributes: `upload-preset-id`, `token-url`, `accept`, `max-file-size`
|
|
55
|
+
* (bytes), `no-auto-upload`, `multiple`, `max-files`, `disabled`, `capture` and `base-url`. Set
|
|
56
|
+
* the `token`, `upload`, `checkStatus`, `messages` and `controller` properties from script for
|
|
57
|
+
* anything an attribute can't hold.
|
|
58
|
+
*/
|
|
59
|
+
var CalmLensUploaderElement = class extends BaseElement {
|
|
60
|
+
static {
|
|
61
|
+
this.observedAttributes = [
|
|
62
|
+
"upload-preset-id",
|
|
63
|
+
"token-url",
|
|
64
|
+
"accept",
|
|
65
|
+
"max-file-size",
|
|
66
|
+
"no-auto-upload",
|
|
67
|
+
"multiple",
|
|
68
|
+
"max-files",
|
|
69
|
+
"disabled",
|
|
70
|
+
"capture",
|
|
71
|
+
"base-url"
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
#token;
|
|
75
|
+
#upload;
|
|
76
|
+
#checkStatus;
|
|
77
|
+
#createClient;
|
|
78
|
+
#messages;
|
|
79
|
+
#controller;
|
|
80
|
+
/** Whether `controller` was set from script, so its options and uploads aren't this element's. */
|
|
81
|
+
#external = false;
|
|
82
|
+
#unsubscribe;
|
|
83
|
+
#dragging = false;
|
|
84
|
+
#input;
|
|
85
|
+
/** The upload token, or a function returning one per file, instead of `token-url`. */
|
|
86
|
+
get token() {
|
|
87
|
+
return this.#token;
|
|
88
|
+
}
|
|
89
|
+
set token(value) {
|
|
90
|
+
this.#token = value;
|
|
91
|
+
this.#updateOptions();
|
|
92
|
+
}
|
|
93
|
+
/** Uploads each file your own way instead of through `upload-preset-id`. */
|
|
94
|
+
get upload() {
|
|
95
|
+
return this.#upload;
|
|
96
|
+
}
|
|
97
|
+
set upload(value) {
|
|
98
|
+
this.#upload = value;
|
|
99
|
+
this.#updateOptions();
|
|
100
|
+
}
|
|
101
|
+
/** Checks a pending upload made with `upload`. */
|
|
102
|
+
get checkStatus() {
|
|
103
|
+
return this.#checkStatus;
|
|
104
|
+
}
|
|
105
|
+
set checkStatus(value) {
|
|
106
|
+
this.#checkStatus = value;
|
|
107
|
+
this.#updateOptions();
|
|
108
|
+
}
|
|
109
|
+
/** Creates the client for each upload, for example a `MockCalmLensAppClient` in tests. */
|
|
110
|
+
get createClient() {
|
|
111
|
+
return this.#createClient;
|
|
112
|
+
}
|
|
113
|
+
set createClient(value) {
|
|
114
|
+
this.#createClient = value;
|
|
115
|
+
this.#updateOptions();
|
|
116
|
+
}
|
|
117
|
+
get messages() {
|
|
118
|
+
return this.#messages;
|
|
119
|
+
}
|
|
120
|
+
set messages(value) {
|
|
121
|
+
this.#messages = value;
|
|
122
|
+
this.#render();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The upload queue, for reading items or calling `start`, `retry`, `remove` and `clear`. Set it
|
|
126
|
+
* to show a queue your script created; its own options then apply instead of the attributes.
|
|
127
|
+
*/
|
|
128
|
+
get controller() {
|
|
129
|
+
this.#controller ??= require_UploadController.createUploadController(this.#options());
|
|
130
|
+
return this.#controller;
|
|
131
|
+
}
|
|
132
|
+
set controller(value) {
|
|
133
|
+
if (value === this.#controller) return;
|
|
134
|
+
this.#unsubscribe?.();
|
|
135
|
+
if (!this.#external) this.#controller?.clear();
|
|
136
|
+
this.#controller = value;
|
|
137
|
+
this.#external = true;
|
|
138
|
+
if (this.isConnected) {
|
|
139
|
+
this.#subscribe();
|
|
140
|
+
this.#render();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
#updateOptions() {
|
|
144
|
+
if (!this.#external) this.#controller?.setOptions(this.#options());
|
|
145
|
+
}
|
|
146
|
+
#subscribe() {
|
|
147
|
+
this.#unsubscribe = this.controller.subscribe((snapshot) => {
|
|
148
|
+
this.#renderItems();
|
|
149
|
+
this.dispatchEvent(new CustomEvent("calmlens-change", { detail: snapshot }));
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
#options() {
|
|
153
|
+
const emit = (type, detail) => this.dispatchEvent(new CustomEvent(type, {
|
|
154
|
+
detail,
|
|
155
|
+
bubbles: true
|
|
156
|
+
}));
|
|
157
|
+
return {
|
|
158
|
+
uploadPresetId: this.getAttribute("upload-preset-id") ?? void 0,
|
|
159
|
+
upload: this.upload,
|
|
160
|
+
checkStatus: this.checkStatus,
|
|
161
|
+
createClient: this.createClient,
|
|
162
|
+
token: this.token,
|
|
163
|
+
tokenUrl: this.getAttribute("token-url") ?? void 0,
|
|
164
|
+
accept: this.getAttribute("accept") ?? void 0,
|
|
165
|
+
maxFileSize: numberAttribute(this, "max-file-size"),
|
|
166
|
+
autoUpload: !this.hasAttribute("no-auto-upload"),
|
|
167
|
+
multiple: this.hasAttribute("multiple"),
|
|
168
|
+
maxFiles: numberAttribute(this, "max-files"),
|
|
169
|
+
baseUrl: this.getAttribute("base-url") ?? void 0,
|
|
170
|
+
onUploaded: (upload) => emit("calmlens-uploaded", upload),
|
|
171
|
+
onRejected: (item) => emit("calmlens-rejected", item),
|
|
172
|
+
onFailed: (item) => emit("calmlens-failed", item),
|
|
173
|
+
onRemoved: (item) => emit("calmlens-removed", item)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
connectedCallback() {
|
|
177
|
+
upgradeProperties(this, [
|
|
178
|
+
"token",
|
|
179
|
+
"upload",
|
|
180
|
+
"checkStatus",
|
|
181
|
+
"createClient",
|
|
182
|
+
"messages",
|
|
183
|
+
"controller"
|
|
184
|
+
]);
|
|
185
|
+
this.classList.add("calmlens-uploader");
|
|
186
|
+
this.#subscribe();
|
|
187
|
+
this.#render();
|
|
188
|
+
}
|
|
189
|
+
disconnectedCallback() {
|
|
190
|
+
this.#unsubscribe?.();
|
|
191
|
+
if (!this.#external) this.controller.clear();
|
|
192
|
+
}
|
|
193
|
+
attributeChangedCallback() {
|
|
194
|
+
this.#updateOptions();
|
|
195
|
+
if (this.isConnected) this.#render();
|
|
196
|
+
}
|
|
197
|
+
#render() {
|
|
198
|
+
if (!this.isConnected) return;
|
|
199
|
+
this.#updateOptions();
|
|
200
|
+
const { accept, multiple } = this.controller.options;
|
|
201
|
+
const messages = require_ui.resolveMessages(this.#messages);
|
|
202
|
+
const disabled = this.hasAttribute("disabled");
|
|
203
|
+
const view = require_ui.describeUploader(this.controller.getSnapshot(), this.controller.options, messages);
|
|
204
|
+
const input = el("input", {
|
|
205
|
+
type: "file",
|
|
206
|
+
hidden: true,
|
|
207
|
+
accept,
|
|
208
|
+
multiple,
|
|
209
|
+
capture: this.getAttribute("capture") ?? void 0,
|
|
210
|
+
disabled
|
|
211
|
+
});
|
|
212
|
+
this.#input = input;
|
|
213
|
+
input.addEventListener("change", () => {
|
|
214
|
+
if (input.files) this.controller.addFiles(input.files);
|
|
215
|
+
input.value = "";
|
|
216
|
+
});
|
|
217
|
+
const button = el("button", {
|
|
218
|
+
type: "button",
|
|
219
|
+
class: "calmlens-button",
|
|
220
|
+
"data-variant": "outline",
|
|
221
|
+
disabled
|
|
222
|
+
}, [view.chooseLabel]);
|
|
223
|
+
button.addEventListener("click", (event) => {
|
|
224
|
+
event.stopPropagation();
|
|
225
|
+
this.#openPicker();
|
|
226
|
+
});
|
|
227
|
+
const title = el("p", { class: "calmlens-dropzone__title" }, [messages.dropzoneTitle]);
|
|
228
|
+
const zone = el("div", {
|
|
229
|
+
class: "calmlens-dropzone",
|
|
230
|
+
"data-disabled": disabled
|
|
231
|
+
}, [
|
|
232
|
+
el("span", { class: "calmlens-dropzone__icon" }, [icon("upload")]),
|
|
233
|
+
el("div", { class: "calmlens-dropzone__text" }, [title, view.hint && el("p", { class: "calmlens-dropzone__hint" }, [view.hint])]),
|
|
234
|
+
button
|
|
235
|
+
]);
|
|
236
|
+
const setDragging = (dragging) => {
|
|
237
|
+
this.#dragging = dragging;
|
|
238
|
+
zone.toggleAttribute("data-dragging", dragging);
|
|
239
|
+
title.textContent = dragging ? messages.dropzoneTitleDragging : messages.dropzoneTitle;
|
|
240
|
+
};
|
|
241
|
+
const onDragOver = (event) => {
|
|
242
|
+
event.preventDefault();
|
|
243
|
+
if (!this.hasAttribute("disabled") && !this.#dragging) setDragging(true);
|
|
244
|
+
};
|
|
245
|
+
zone.addEventListener("click", () => this.#openPicker());
|
|
246
|
+
zone.addEventListener("dragover", onDragOver);
|
|
247
|
+
zone.addEventListener("dragenter", onDragOver);
|
|
248
|
+
zone.addEventListener("dragleave", (event) => {
|
|
249
|
+
if (!zone.contains(event.relatedTarget)) setDragging(false);
|
|
250
|
+
});
|
|
251
|
+
zone.addEventListener("drop", (event) => {
|
|
252
|
+
event.preventDefault();
|
|
253
|
+
setDragging(false);
|
|
254
|
+
if (!this.hasAttribute("disabled") && event.dataTransfer) this.controller.addFiles(event.dataTransfer.files);
|
|
255
|
+
});
|
|
256
|
+
zone.addEventListener("paste", (event) => {
|
|
257
|
+
const files = event.clipboardData?.files;
|
|
258
|
+
if (!this.hasAttribute("disabled") && files?.length) this.controller.addFiles(files);
|
|
259
|
+
});
|
|
260
|
+
this.replaceChildren(zone, input, el("ul", {
|
|
261
|
+
class: "calmlens-uploads",
|
|
262
|
+
hidden: true
|
|
263
|
+
}));
|
|
264
|
+
this.#renderItems();
|
|
265
|
+
}
|
|
266
|
+
#openPicker() {
|
|
267
|
+
if (!this.hasAttribute("disabled")) this.#input?.click();
|
|
268
|
+
}
|
|
269
|
+
#renderItems() {
|
|
270
|
+
const list = this.querySelector(":scope > .calmlens-uploads");
|
|
271
|
+
const zone = this.querySelector(":scope > .calmlens-dropzone");
|
|
272
|
+
if (!list || !zone) return;
|
|
273
|
+
const messages = require_ui.resolveMessages(this.#messages);
|
|
274
|
+
const snapshot = this.controller.getSnapshot();
|
|
275
|
+
const { items } = snapshot;
|
|
276
|
+
const view = require_ui.describeUploader(snapshot, this.controller.options, messages);
|
|
277
|
+
zone.hidden = !view.showDropzone;
|
|
278
|
+
list.hidden = items.length === 0;
|
|
279
|
+
const thumbnails = new Map([...list.querySelectorAll(".calmlens-upload")].map((row) => [row.dataset.key, row.querySelector(".calmlens-upload__thumb")]));
|
|
280
|
+
const disabled = this.hasAttribute("disabled");
|
|
281
|
+
list.replaceChildren(...items.map((item) => {
|
|
282
|
+
const itemView = require_ui.describeUploadItem(item, messages);
|
|
283
|
+
const thumbnail = thumbnails.get(item.key) ?? (item.previewUrl ? el("img", {
|
|
284
|
+
class: "calmlens-upload__thumb",
|
|
285
|
+
src: item.previewUrl,
|
|
286
|
+
alt: ""
|
|
287
|
+
}) : fileThumbnail(itemView.fileIcon));
|
|
288
|
+
const bar = el("div", { class: "calmlens-progress__bar" });
|
|
289
|
+
if (itemView.progressPercent !== void 0) bar.style.width = `${itemView.progressPercent}%`;
|
|
290
|
+
const chooseAnother = !view.showDropzone && el("button", {
|
|
291
|
+
type: "button",
|
|
292
|
+
class: "calmlens-button",
|
|
293
|
+
"data-variant": "outline",
|
|
294
|
+
"data-size": "small",
|
|
295
|
+
disabled
|
|
296
|
+
}, [messages.chooseAnother]);
|
|
297
|
+
if (chooseAnother) chooseAnother.addEventListener("click", () => this.#openPicker());
|
|
298
|
+
const retry = itemView.canRetry && el("button", {
|
|
299
|
+
type: "button",
|
|
300
|
+
class: "calmlens-icon-button",
|
|
301
|
+
"aria-label": messages.retry,
|
|
302
|
+
title: messages.retry
|
|
303
|
+
}, [icon("retry")]);
|
|
304
|
+
if (retry) retry.addEventListener("click", () => this.controller.retry(item.key));
|
|
305
|
+
const remove = el("button", {
|
|
306
|
+
type: "button",
|
|
307
|
+
class: "calmlens-icon-button",
|
|
308
|
+
"aria-label": itemView.removeLabel,
|
|
309
|
+
title: itemView.removeLabel
|
|
310
|
+
}, [icon("remove")]);
|
|
311
|
+
remove.addEventListener("click", () => this.controller.remove(item.key));
|
|
312
|
+
const row = el("li", {
|
|
313
|
+
class: "calmlens-upload",
|
|
314
|
+
"data-stage": item.stage,
|
|
315
|
+
"data-outcome": itemView.outcome
|
|
316
|
+
}, [
|
|
317
|
+
thumbnail,
|
|
318
|
+
el("div", { class: "calmlens-upload__body" }, [
|
|
319
|
+
el("span", { class: "calmlens-upload__name" }, [item.file.name]),
|
|
320
|
+
el("span", { class: "calmlens-upload__size" }, [itemView.size]),
|
|
321
|
+
itemView.busy && el("div", {
|
|
322
|
+
class: "calmlens-progress",
|
|
323
|
+
role: "progressbar",
|
|
324
|
+
"aria-label": itemView.message,
|
|
325
|
+
"aria-valuemin": 0,
|
|
326
|
+
"aria-valuemax": 100,
|
|
327
|
+
"aria-valuenow": itemView.progressPercent
|
|
328
|
+
}, [bar]),
|
|
329
|
+
itemView.message && el("p", {
|
|
330
|
+
class: "calmlens-upload__message",
|
|
331
|
+
role: "status"
|
|
332
|
+
}, [itemView.message])
|
|
333
|
+
]),
|
|
334
|
+
el("div", { class: "calmlens-upload__actions" }, [
|
|
335
|
+
chooseAnother,
|
|
336
|
+
retry,
|
|
337
|
+
remove
|
|
338
|
+
])
|
|
339
|
+
]);
|
|
340
|
+
row.dataset.key = item.key;
|
|
341
|
+
return row;
|
|
342
|
+
}));
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* `<calmlens-media project-id="…" asset-id="…" status="allowed" alt="…">` shows an asset from the
|
|
347
|
+
* CalmLens CDN with a blurred placeholder while it loads. Age-restricted assets show the
|
|
348
|
+
* placeholder and a reveal button, which dispatches `calmlens-reveal`, until `age-confirmed` is set.
|
|
349
|
+
* Attributes: `project-id`, `asset-id`, `status`, `age-confirmed`, `type`, `resource`, `lens`,
|
|
350
|
+
* `transform`, `widths` (comma-separated), `url`, `no-placeholder`, `placeholder-hash`,
|
|
351
|
+
* `placeholder-url`, `average-color`, `cdn-base-url`, `alt`, `aspect-ratio`, `width`, `height`,
|
|
352
|
+
* `sizes`, `fit`, `position`, `eager`, `fetch-priority` and `no-controls`. Set the
|
|
353
|
+
* `asset` property to an API asset instead of `project-id` and `asset-id`.
|
|
354
|
+
*/
|
|
355
|
+
var CalmLensMediaElement = class extends BaseElement {
|
|
356
|
+
static {
|
|
357
|
+
this.observedAttributes = [
|
|
358
|
+
"project-id",
|
|
359
|
+
"asset-id",
|
|
360
|
+
"status",
|
|
361
|
+
"content-removed",
|
|
362
|
+
"type",
|
|
363
|
+
"resource",
|
|
364
|
+
"lens",
|
|
365
|
+
"transform",
|
|
366
|
+
"widths",
|
|
367
|
+
"url",
|
|
368
|
+
"no-placeholder",
|
|
369
|
+
"placeholder-hash",
|
|
370
|
+
"placeholder-url",
|
|
371
|
+
"average-color",
|
|
372
|
+
"cdn-base-url",
|
|
373
|
+
"viewer-claims",
|
|
374
|
+
"alt",
|
|
375
|
+
"aspect-ratio",
|
|
376
|
+
"width",
|
|
377
|
+
"height",
|
|
378
|
+
"sizes",
|
|
379
|
+
"fit",
|
|
380
|
+
"position",
|
|
381
|
+
"eager",
|
|
382
|
+
"fetch-priority",
|
|
383
|
+
"no-controls"
|
|
384
|
+
];
|
|
385
|
+
}
|
|
386
|
+
#messages;
|
|
387
|
+
#asset;
|
|
388
|
+
#loadKey;
|
|
389
|
+
get messages() {
|
|
390
|
+
return this.#messages;
|
|
391
|
+
}
|
|
392
|
+
set messages(value) {
|
|
393
|
+
this.#messages = value;
|
|
394
|
+
this.#loadKey = void 0;
|
|
395
|
+
this.#render();
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* An asset from the API, in place of `project-id` and `asset-id`. It supplies the status, type
|
|
399
|
+
* and preview too; attributes you set win over it.
|
|
400
|
+
*/
|
|
401
|
+
get asset() {
|
|
402
|
+
return this.#asset;
|
|
403
|
+
}
|
|
404
|
+
set asset(value) {
|
|
405
|
+
this.#asset = value;
|
|
406
|
+
this.#render();
|
|
407
|
+
}
|
|
408
|
+
connectedCallback() {
|
|
409
|
+
upgradeProperties(this, ["messages", "asset"]);
|
|
410
|
+
this.classList.add("calmlens-media");
|
|
411
|
+
this.setAttribute("role", "figure");
|
|
412
|
+
this.#render();
|
|
413
|
+
}
|
|
414
|
+
attributeChangedCallback() {
|
|
415
|
+
this.#render();
|
|
416
|
+
}
|
|
417
|
+
#mediaOptions() {
|
|
418
|
+
const list = (name) => this.getAttribute(name)?.split(",").map((value) => value.trim()).filter(Boolean);
|
|
419
|
+
return require_ui.resolveMediaProps({
|
|
420
|
+
asset: this.#asset,
|
|
421
|
+
projectId: this.getAttribute("project-id") ?? void 0,
|
|
422
|
+
assetId: this.getAttribute("asset-id") ?? void 0,
|
|
423
|
+
status: this.getAttribute("status") ?? void 0,
|
|
424
|
+
contentRemoved: this.hasAttribute("content-removed") ? true : void 0,
|
|
425
|
+
type: this.getAttribute("type") ?? void 0,
|
|
426
|
+
resource: this.getAttribute("resource") ?? void 0,
|
|
427
|
+
lens: this.getAttribute("lens") ?? void 0,
|
|
428
|
+
transform: this.getAttribute("transform") ?? void 0,
|
|
429
|
+
widths: list("widths")?.map(Number),
|
|
430
|
+
url: this.getAttribute("url") ?? void 0,
|
|
431
|
+
placeholder: !this.hasAttribute("no-placeholder"),
|
|
432
|
+
placeholderHash: this.getAttribute("placeholder-hash") ?? void 0,
|
|
433
|
+
placeholderUrl: this.getAttribute("placeholder-url") ?? void 0,
|
|
434
|
+
viewerClaims: this.hasAttribute("viewer-claims") ? JSON.parse(this.getAttribute("viewer-claims")) : void 0,
|
|
435
|
+
cdnBaseUrl: this.getAttribute("cdn-base-url") ?? void 0,
|
|
436
|
+
width: numberAttribute(this, "width"),
|
|
437
|
+
height: numberAttribute(this, "height"),
|
|
438
|
+
averageColor: this.getAttribute("average-color") ?? void 0
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
#render() {
|
|
442
|
+
if (!this.isConnected) return;
|
|
443
|
+
const options = this.#mediaOptions();
|
|
444
|
+
if (!options.projectId || !options.assetId) return;
|
|
445
|
+
const state = require_ui.getMediaState(options);
|
|
446
|
+
const loadKey = `${require_ui.getMediaLoadKey(state)} ${this.getAttribute("alt")} ${this.getAttribute("sizes")} ${options.viewerClaims?.ageConfirmed}`;
|
|
447
|
+
const ratio = require_ui.getMediaAspectRatio({
|
|
448
|
+
aspectRatio: numberAttribute(this, "aspect-ratio"),
|
|
449
|
+
width: options.width,
|
|
450
|
+
height: options.height
|
|
451
|
+
});
|
|
452
|
+
this.style.aspectRatio = ratio ? String(ratio) : "";
|
|
453
|
+
this.toggleAttribute("data-sized", Boolean(ratio));
|
|
454
|
+
this.style.backgroundColor = options.averageColor ?? "";
|
|
455
|
+
this.style.setProperty("--calmlens-fit", this.getAttribute("fit"));
|
|
456
|
+
this.style.setProperty("--calmlens-position", this.getAttribute("position"));
|
|
457
|
+
this.dataset.kind = state.kind;
|
|
458
|
+
if (loadKey === this.#loadKey) return;
|
|
459
|
+
this.#loadKey = loadKey;
|
|
460
|
+
this.dataset.state = "loading";
|
|
461
|
+
const messages = require_ui.resolveMessages(this.#messages);
|
|
462
|
+
const alt = this.getAttribute("alt") ?? "";
|
|
463
|
+
const sizes = this.getAttribute("sizes") ?? void 0;
|
|
464
|
+
const placeholder = state.kind !== "audio" && state.kind !== "unavailable" && state.placeholderUrl ? el("img", {
|
|
465
|
+
class: "calmlens-media__placeholder",
|
|
466
|
+
src: state.placeholderUrl,
|
|
467
|
+
alt: "",
|
|
468
|
+
"aria-hidden": "true"
|
|
469
|
+
}) : void 0;
|
|
470
|
+
const notice = (children) => el("div", { class: "calmlens-media__notice" }, children);
|
|
471
|
+
const unavailable = () => notice([el("p", {}, [icon("unavailable"), el("span", { class: "calmlens-media__label" }, [require_ui.getMediaUnavailableMessage(state, messages)])])]);
|
|
472
|
+
const fail = () => {
|
|
473
|
+
this.dataset.state = "error";
|
|
474
|
+
this.replaceChildren(unavailable());
|
|
475
|
+
};
|
|
476
|
+
const controls = !this.hasAttribute("no-controls");
|
|
477
|
+
if (state.kind === "unavailable") this.replaceChildren(unavailable());
|
|
478
|
+
else if (state.kind === "gated") {
|
|
479
|
+
const reveal = el("button", {
|
|
480
|
+
type: "button",
|
|
481
|
+
class: "calmlens-button"
|
|
482
|
+
}, [messages.reveal]);
|
|
483
|
+
reveal.addEventListener("click", () => this.dispatchEvent(new CustomEvent("calmlens-reveal", { bubbles: true })));
|
|
484
|
+
this.replaceChildren(...[placeholder].filter((node) => node !== void 0), notice([
|
|
485
|
+
el("strong", {}, [messages.sensitiveTitle]),
|
|
486
|
+
el("p", {}, [messages.sensitiveBody]),
|
|
487
|
+
reveal
|
|
488
|
+
]));
|
|
489
|
+
} else if (state.kind === "image") {
|
|
490
|
+
const image = el("img", {
|
|
491
|
+
class: "calmlens-media__content",
|
|
492
|
+
src: state.src,
|
|
493
|
+
srcset: state.srcSet,
|
|
494
|
+
sizes,
|
|
495
|
+
alt,
|
|
496
|
+
width: options.width,
|
|
497
|
+
height: options.height,
|
|
498
|
+
loading: this.hasAttribute("eager") ? void 0 : "lazy",
|
|
499
|
+
decoding: "async",
|
|
500
|
+
fetchpriority: this.getAttribute("fetch-priority") ?? void 0
|
|
501
|
+
});
|
|
502
|
+
image.addEventListener("load", () => {
|
|
503
|
+
this.dataset.state = "loaded";
|
|
504
|
+
placeholder?.remove();
|
|
505
|
+
});
|
|
506
|
+
image.addEventListener("error", fail);
|
|
507
|
+
this.replaceChildren(...[placeholder, image].filter((node) => node !== void 0));
|
|
508
|
+
} else {
|
|
509
|
+
const media = el(state.kind, {
|
|
510
|
+
class: "calmlens-media__content",
|
|
511
|
+
src: state.src,
|
|
512
|
+
controls,
|
|
513
|
+
playsinline: state.kind === "video",
|
|
514
|
+
preload: "metadata",
|
|
515
|
+
"aria-label": alt || void 0
|
|
516
|
+
});
|
|
517
|
+
media.addEventListener("error", fail);
|
|
518
|
+
this.replaceChildren(media);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
/** Defines `<calmlens-uploader>` and `<calmlens-media>`, if they aren't defined yet. */
|
|
523
|
+
const defineCalmLensElements = () => {
|
|
524
|
+
if (typeof customElements === "undefined") return;
|
|
525
|
+
if (!customElements.get("calmlens-uploader")) customElements.define("calmlens-uploader", CalmLensUploaderElement);
|
|
526
|
+
if (!customElements.get("calmlens-media")) customElements.define("calmlens-media", CalmLensMediaElement);
|
|
527
|
+
};
|
|
528
|
+
defineCalmLensElements();
|
|
529
|
+
exports.CALMLENS_STYLES = require_ui.CALMLENS_STYLES;
|
|
530
|
+
exports.CALMLENS_THEME = require_ui.CALMLENS_THEME;
|
|
531
|
+
exports.CalmLensMediaElement = CalmLensMediaElement;
|
|
532
|
+
exports.CalmLensUploaderElement = CalmLensUploaderElement;
|
|
533
|
+
exports.DEFAULT_MESSAGES = require_ui.DEFAULT_MESSAGES;
|
|
534
|
+
exports.ICONS = require_ui.ICONS;
|
|
535
|
+
exports.ICON_ATTRIBUTES = require_ui.ICON_ATTRIBUTES;
|
|
536
|
+
exports.UploadController = require_UploadController.UploadController;
|
|
537
|
+
exports.createProgressFetch = require_UploadController.createProgressFetch;
|
|
538
|
+
exports.createUploadController = require_BrowserUpload.createUploadController;
|
|
539
|
+
exports.defineCalmLensElements = defineCalmLensElements;
|
|
540
|
+
exports.describeUploadItem = require_ui.describeUploadItem;
|
|
541
|
+
exports.describeUploader = require_ui.describeUploader;
|
|
542
|
+
exports.formatBytes = require_ui.formatBytes;
|
|
543
|
+
exports.formatMessage = require_ui.formatMessage;
|
|
544
|
+
exports.getDropzoneHint = require_ui.getDropzoneHint;
|
|
545
|
+
exports.getMediaAspectRatio = require_ui.getMediaAspectRatio;
|
|
546
|
+
exports.getMediaLoadKey = require_ui.getMediaLoadKey;
|
|
547
|
+
exports.getMediaState = require_ui.getMediaState;
|
|
548
|
+
exports.getMediaUnavailableMessage = require_ui.getMediaUnavailableMessage;
|
|
549
|
+
exports.getUploadItemMessage = require_ui.getUploadItemMessage;
|
|
550
|
+
exports.getUploadItemOutcome = require_ui.getUploadItemOutcome;
|
|
551
|
+
exports.isFileAccepted = require_UploadController.isFileAccepted;
|
|
552
|
+
exports.pickMediaSource = require_ui.pickMediaSource;
|
|
553
|
+
exports.resolveMediaProps = require_ui.resolveMediaProps;
|
|
554
|
+
exports.resolveMessages = require_ui.resolveMessages;
|
|
555
|
+
exports.resolveTheme = require_ui.resolveTheme;
|