calmlens 0.4.0 → 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.
Files changed (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +673 -130
  3. package/bin/calmlens.js +15994 -1164
  4. package/bin/package.json +1 -0
  5. package/cjs/BrowserUpload-BT091eOB.d.ts +11 -0
  6. package/cjs/BrowserUpload-CQwXEGFv.js +10 -0
  7. package/cjs/CalmLensAppClient-CHQGu-Do.js +89 -0
  8. package/cjs/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  9. package/cjs/CalmLensConnection-B8Bu2j3y.js +659 -0
  10. package/cjs/CalmLensServerClient-C5o2A8MW.js +645 -0
  11. package/cjs/CalmLensServerClient-JtP687a3.d.ts +235 -0
  12. package/cjs/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  13. package/cjs/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  14. package/cjs/CryptoUtils-B_x8lMIx-YBW1-bvL.js +42 -0
  15. package/cjs/FileIcons-Ob003MdS.js +175 -0
  16. package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +91 -0
  17. package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  18. package/cjs/ModerationContextLimits-DelWfmiJ.js +1311 -0
  19. package/cjs/ReactUpload-CAyCsyG6.d.ts +17 -0
  20. package/cjs/ReactUpload-Cfg5JYUq.js +54 -0
  21. package/cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  22. package/cjs/TestTriggers-DTc_iMJF-BjMPq4_3.js +1327 -0
  23. package/cjs/UploadController-BGO1eyzb.js +618 -0
  24. package/cjs/WebhookPayload-2aL31v0J.d.ts +352 -0
  25. package/cjs/app.d.ts +7 -0
  26. package/cjs/app.js +13 -0
  27. package/cjs/elements.d.ts +88 -0
  28. package/cjs/elements.js +555 -0
  29. package/cjs/file-icons.d.ts +67 -0
  30. package/cjs/file-icons.js +10 -0
  31. package/cjs/index-CI4BzN4W.d.ts +252 -0
  32. package/cjs/index.d.ts +6 -163
  33. package/cjs/index.js +9 -796
  34. package/cjs/react-native.d.ts +56 -0
  35. package/cjs/react-native.js +495 -0
  36. package/cjs/react.d.ts +30 -0
  37. package/cjs/react.js +370 -0
  38. package/cjs/server.d.ts +33 -0
  39. package/cjs/server.js +20 -0
  40. package/cjs/test-inputs.d.ts +2 -0
  41. package/cjs/test-inputs.js +10 -0
  42. package/cjs/testing.d.ts +309 -80
  43. package/cjs/testing.js +10453 -689
  44. package/cjs/ui-CC1GOoMg.js +583 -0
  45. package/cjs/ui-wIiMfqMB.d.ts +526 -0
  46. package/cjs/ui.d.ts +2 -0
  47. package/cjs/ui.js +27 -0
  48. package/cjs/vue.d.ts +490 -0
  49. package/cjs/vue.js +419 -0
  50. package/esm/BrowserUpload-BT091eOB.d.ts +11 -0
  51. package/esm/BrowserUpload-D2xBWqhm.js +5 -0
  52. package/esm/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  53. package/esm/CalmLensAppClient-DuFas_dW.js +84 -0
  54. package/esm/CalmLensConnection-MxwwLXdl.js +582 -0
  55. package/esm/CalmLensServerClient-D80_mKpW.js +586 -0
  56. package/esm/CalmLensServerClient-JtP687a3.d.ts +235 -0
  57. package/esm/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  58. package/esm/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  59. package/esm/CryptoUtils-B_x8lMIx-DhuWGzqn.js +25 -0
  60. package/esm/FileIcons-M6dzjFxd.js +128 -0
  61. package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +46 -0
  62. package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  63. package/esm/ModerationContextLimits-BaX2QnU8.js +1114 -0
  64. package/esm/ReactUpload-CAyCsyG6.d.ts +17 -0
  65. package/esm/ReactUpload-CL2XC8WS.js +37 -0
  66. package/esm/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  67. package/esm/TestTriggers-DTc_iMJF-HfB533Gx.js +1267 -0
  68. package/esm/UploadController-qjoYGCwx.js +589 -0
  69. package/esm/WebhookPayload-2aL31v0J.d.ts +352 -0
  70. package/esm/app.d.ts +7 -0
  71. package/esm/app.js +4 -0
  72. package/esm/elements.d.ts +88 -0
  73. package/esm/elements.js +528 -0
  74. package/esm/file-icons.d.ts +67 -0
  75. package/esm/file-icons.js +1 -0
  76. package/esm/index-CI4BzN4W.d.ts +252 -0
  77. package/esm/index.d.ts +6 -163
  78. package/esm/index.js +1 -794
  79. package/esm/react-native.d.ts +56 -0
  80. package/esm/react-native.js +467 -0
  81. package/esm/react.d.ts +30 -0
  82. package/esm/react.js +343 -0
  83. package/esm/server.d.ts +33 -0
  84. package/esm/server.js +4 -0
  85. package/esm/styles.css +147 -0
  86. package/esm/svelte/CalmLensMedia.svelte +134 -0
  87. package/esm/svelte/CalmLensUploader.svelte +175 -0
  88. package/esm/svelte/Icon.svelte +7 -0
  89. package/esm/svelte/index.d.ts +37 -0
  90. package/esm/svelte/index.js +6 -0
  91. package/esm/test-inputs.d.ts +2 -0
  92. package/esm/test-inputs.js +1 -0
  93. package/esm/testing.d.ts +309 -80
  94. package/esm/testing.js +10432 -656
  95. package/esm/ui-CCY3yXFn.js +458 -0
  96. package/esm/ui-wIiMfqMB.d.ts +526 -0
  97. package/esm/ui.d.ts +2 -0
  98. package/esm/ui.js +3 -0
  99. package/esm/vue.d.ts +490 -0
  100. package/esm/vue.js +392 -0
  101. package/package.json +173 -34
  102. package/cjs/CalmLensTypes-DkqoKBwF.d.ts +0 -1761
  103. package/cjs/CalmLensUtils-CjdO9v--.js +0 -549
  104. package/esm/CalmLensTypes-DkqoKBwF.d.ts +0 -1761
  105. package/esm/CalmLensUtils-B3Eiz2Ro.js +0 -430
package/esm/react.js ADDED
@@ -0,0 +1,343 @@
1
+ "use client";
2
+ import { _ as getMediaState, a as getMediaAspectRatio, b as ICONS, c as describeUploadItem, d as formatMessage, f as getDropzoneHint, g as resolveMessages, h as getUploadItemOutcome, i as resolveTheme, l as describeUploader, m as getUploadItemMessage, n as CALMLENS_STYLES_ID, o as getMediaLoadKey, p as getMediaUnavailableMessage, r as CALMLENS_THEME, s as DEFAULT_MESSAGES, t as CALMLENS_STYLES, u as formatBytes, v as pickMediaSource, x as ICON_ATTRIBUTES, y as resolveMediaProps } from "./ui-CCY3yXFn.js";
3
+ import { i as createProgressFetch, r as isFileAccepted, t as UploadController } from "./UploadController-qjoYGCwx.js";
4
+ import { n as useOwnController, r as useUploadSnapshot, t as useCalmLensUpload$1 } from "./ReactUpload-CL2XC8WS.js";
5
+ import { t as createUploadController } from "./BrowserUpload-D2xBWqhm.js";
6
+ import { useEffect, useMemo, useRef, useState } from "react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ // src/react.tsx
9
+ /**
10
+ * Uploads files through an upload preset and re-renders as each one uploads and is checked. Use
11
+ * it to build your own upload UI; `CalmLensUploader` is built on it. Uploads still running when
12
+ * the component unmounts are cancelled.
13
+ */
14
+ const useCalmLensUpload = (options) => useCalmLensUpload$1(options);
15
+ const joinClassNames = (...names) => names.filter(Boolean).join(" ");
16
+ const Icon = ({ name }) => {
17
+ const { "stroke-width": strokeWidth, "stroke-linecap": strokeLinecap, "stroke-linejoin": strokeLinejoin, "aria-hidden": ariaHidden, ...rest } = ICON_ATTRIBUTES;
18
+ return /* @__PURE__ */ jsx("svg", {
19
+ ...rest,
20
+ strokeWidth,
21
+ strokeLinecap,
22
+ strokeLinejoin,
23
+ "aria-hidden": ariaHidden,
24
+ children: /* @__PURE__ */ jsx("path", { d: ICONS[name] })
25
+ });
26
+ };
27
+ /**
28
+ * The components' stylesheet, rendered with them: React hoists it into the document head, on the
29
+ * server as well as in the browser, and adds it once however many components render.
30
+ */
31
+ const CalmLensStyles = ({ unstyled }) => unstyled ? null : /* @__PURE__ */ jsx("style", {
32
+ href: CALMLENS_STYLES_ID,
33
+ precedence: "calmlens",
34
+ children: CALMLENS_STYLES
35
+ });
36
+ /**
37
+ * A drop zone and file list that uploads through an upload preset, shows each file's progress
38
+ * and moderation decision, and reports finished uploads to `onUploaded`.
39
+ */
40
+ function CalmLensUploader({ disabled, capture, messages: overrides, unstyled, controller: external, className, style, ...options }) {
41
+ const own = useOwnController(options, !external);
42
+ const upload = useUploadSnapshot(external ?? own);
43
+ const { accept, multiple } = upload.controller.options;
44
+ const messages = useMemo(() => resolveMessages(overrides), [overrides]);
45
+ const view = describeUploader(upload, upload.controller.options, messages);
46
+ const [dragging, setDragging] = useState(false);
47
+ const input = useRef(null);
48
+ const openPicker = () => {
49
+ if (!disabled) input.current?.click();
50
+ };
51
+ const onDragOver = (event) => {
52
+ event.preventDefault();
53
+ if (!disabled) setDragging(true);
54
+ };
55
+ return /* @__PURE__ */ jsxs("div", {
56
+ className: joinClassNames("calmlens-uploader", className),
57
+ style,
58
+ children: [
59
+ /* @__PURE__ */ jsx(CalmLensStyles, { unstyled }),
60
+ view.showDropzone && /* @__PURE__ */ jsxs("div", {
61
+ className: "calmlens-dropzone",
62
+ "data-dragging": dragging || void 0,
63
+ "data-disabled": disabled || void 0,
64
+ onClick: openPicker,
65
+ onDragOver,
66
+ onDragEnter: onDragOver,
67
+ onDragLeave: (event) => {
68
+ if (!event.currentTarget.contains(event.relatedTarget)) setDragging(false);
69
+ },
70
+ onDrop: (event) => {
71
+ event.preventDefault();
72
+ setDragging(false);
73
+ if (!disabled) upload.addFiles(event.dataTransfer.files);
74
+ },
75
+ onPaste: (event) => {
76
+ if (!disabled && event.clipboardData.files.length) upload.addFiles(event.clipboardData.files);
77
+ },
78
+ children: [
79
+ /* @__PURE__ */ jsx("span", {
80
+ className: "calmlens-dropzone__icon",
81
+ children: /* @__PURE__ */ jsx(Icon, { name: "upload" })
82
+ }),
83
+ /* @__PURE__ */ jsxs("div", {
84
+ className: "calmlens-dropzone__text",
85
+ children: [/* @__PURE__ */ jsx("p", {
86
+ className: "calmlens-dropzone__title",
87
+ children: dragging ? messages.dropzoneTitleDragging : messages.dropzoneTitle
88
+ }), view.hint && /* @__PURE__ */ jsx("p", {
89
+ className: "calmlens-dropzone__hint",
90
+ children: view.hint
91
+ })]
92
+ }),
93
+ /* @__PURE__ */ jsx("button", {
94
+ type: "button",
95
+ className: "calmlens-button",
96
+ "data-variant": "outline",
97
+ disabled,
98
+ onClick: (event) => {
99
+ event.stopPropagation();
100
+ openPicker();
101
+ },
102
+ children: view.chooseLabel
103
+ })
104
+ ]
105
+ }),
106
+ /* @__PURE__ */ jsx("input", {
107
+ ref: input,
108
+ type: "file",
109
+ hidden: true,
110
+ accept,
111
+ multiple,
112
+ capture,
113
+ disabled,
114
+ onChange: (event) => {
115
+ if (event.target.files) upload.addFiles(event.target.files);
116
+ event.target.value = "";
117
+ }
118
+ }),
119
+ upload.items.length > 0 && /* @__PURE__ */ jsx("ul", {
120
+ className: "calmlens-uploads",
121
+ children: upload.items.map((item) => {
122
+ const itemView = describeUploadItem(item, messages);
123
+ return /* @__PURE__ */ jsxs("li", {
124
+ className: "calmlens-upload",
125
+ "data-stage": item.stage,
126
+ "data-outcome": itemView.outcome,
127
+ children: [
128
+ item.previewUrl ? /* @__PURE__ */ jsx("img", {
129
+ className: "calmlens-upload__thumb",
130
+ src: item.previewUrl,
131
+ alt: ""
132
+ }) : /* @__PURE__ */ jsx("span", {
133
+ className: "calmlens-upload__thumb",
134
+ "data-kind": "file",
135
+ "aria-hidden": "true",
136
+ dangerouslySetInnerHTML: { __html: itemView.fileIcon }
137
+ }),
138
+ /* @__PURE__ */ jsxs("div", {
139
+ className: "calmlens-upload__body",
140
+ children: [
141
+ /* @__PURE__ */ jsx("span", {
142
+ className: "calmlens-upload__name",
143
+ children: item.file.name
144
+ }),
145
+ /* @__PURE__ */ jsx("span", {
146
+ className: "calmlens-upload__size",
147
+ children: itemView.size
148
+ }),
149
+ itemView.busy && /* @__PURE__ */ jsx("div", {
150
+ className: "calmlens-progress",
151
+ role: "progressbar",
152
+ "aria-label": itemView.message,
153
+ "aria-valuemin": 0,
154
+ "aria-valuemax": 100,
155
+ "aria-valuenow": itemView.progressPercent,
156
+ children: /* @__PURE__ */ jsx("div", {
157
+ className: "calmlens-progress__bar",
158
+ style: itemView.progressPercent === void 0 ? void 0 : { width: `${itemView.progressPercent}%` }
159
+ })
160
+ }),
161
+ itemView.message && /* @__PURE__ */ jsx("p", {
162
+ className: "calmlens-upload__message",
163
+ role: "status",
164
+ children: itemView.message
165
+ })
166
+ ]
167
+ }),
168
+ /* @__PURE__ */ jsxs("div", {
169
+ className: "calmlens-upload__actions",
170
+ children: [
171
+ !view.showDropzone && /* @__PURE__ */ jsx("button", {
172
+ type: "button",
173
+ className: "calmlens-button",
174
+ "data-variant": "outline",
175
+ "data-size": "small",
176
+ disabled,
177
+ onClick: openPicker,
178
+ children: messages.chooseAnother
179
+ }),
180
+ itemView.canRetry && /* @__PURE__ */ jsx("button", {
181
+ type: "button",
182
+ className: "calmlens-icon-button",
183
+ "aria-label": messages.retry,
184
+ title: messages.retry,
185
+ onClick: () => upload.retry(item.key),
186
+ children: /* @__PURE__ */ jsx(Icon, { name: "retry" })
187
+ }),
188
+ /* @__PURE__ */ jsx("button", {
189
+ type: "button",
190
+ className: "calmlens-icon-button",
191
+ "aria-label": itemView.removeLabel,
192
+ title: itemView.removeLabel,
193
+ onClick: () => upload.remove(item.key),
194
+ children: /* @__PURE__ */ jsx(Icon, { name: "remove" })
195
+ })
196
+ ]
197
+ })
198
+ ]
199
+ }, item.key);
200
+ })
201
+ })
202
+ ]
203
+ });
204
+ }
205
+ /**
206
+ * Shows an asset from the CalmLens CDN with responsive widths and a blurred placeholder while
207
+ * it loads. Age-restricted assets stay behind the placeholder and a reveal button until
208
+ * `ageConfirmed` is set; blocked and purged assets show an unavailable notice.
209
+ */
210
+ function CalmLensMedia(input) {
211
+ const { asset: _asset, projectId, assetId, status, contentRemoved, type, resource, lens, transform, widths, url, placeholder, placeholderHash, placeholderUrl: customPlaceholderUrl, cdnBaseUrl, viewerClaims, alt = "", aspectRatio, width, height, sizes, averageColor, fit, position, lazy = true, fetchPriority, controls = true, messages: overrides, unstyled, onReveal, className, style, ...attributes } = resolveMediaProps(input);
212
+ const messages = useMemo(() => resolveMessages(overrides), [overrides]);
213
+ const state = getMediaState({
214
+ asset: _asset,
215
+ projectId,
216
+ assetId,
217
+ status,
218
+ contentRemoved,
219
+ type,
220
+ resource,
221
+ lens,
222
+ transform,
223
+ widths,
224
+ url,
225
+ placeholder,
226
+ placeholderHash,
227
+ placeholderUrl: customPlaceholderUrl,
228
+ cdnBaseUrl,
229
+ viewerClaims
230
+ });
231
+ const loadKey = getMediaLoadKey(state);
232
+ const [load, setLoad] = useState({
233
+ key: loadKey,
234
+ state: "loading"
235
+ });
236
+ const current = load.key === loadKey ? load : {
237
+ key: loadKey,
238
+ state: "loading"
239
+ };
240
+ const image = useRef(null);
241
+ useEffect(() => {
242
+ if (image.current?.complete && image.current.naturalWidth > 0) setLoad({
243
+ key: loadKey,
244
+ state: "loaded"
245
+ });
246
+ }, [loadKey]);
247
+ const ratio = getMediaAspectRatio({
248
+ aspectRatio,
249
+ width,
250
+ height
251
+ });
252
+ const kind = current.state === "error" ? "unavailable" : state.kind;
253
+ const placeholderUrl = state.kind === "audio" || state.kind === "unavailable" ? void 0 : state.placeholderUrl;
254
+ const showPlaceholder = placeholderUrl && (state.kind === "gated" || state.kind === "image" && current.state !== "loaded");
255
+ return /* @__PURE__ */ jsxs("figure", {
256
+ ...attributes,
257
+ className: joinClassNames("calmlens-media", className),
258
+ "data-kind": state.kind,
259
+ "data-state": current.state,
260
+ "data-sized": ratio ? "" : void 0,
261
+ style: {
262
+ aspectRatio: ratio,
263
+ backgroundColor: averageColor,
264
+ "--calmlens-fit": fit,
265
+ "--calmlens-position": position,
266
+ ...style
267
+ },
268
+ children: [
269
+ /* @__PURE__ */ jsx(CalmLensStyles, { unstyled }),
270
+ showPlaceholder && /* @__PURE__ */ jsx("img", {
271
+ className: "calmlens-media__placeholder",
272
+ src: placeholderUrl,
273
+ alt: "",
274
+ "aria-hidden": "true"
275
+ }),
276
+ state.kind === "image" && current.state !== "error" && /* @__PURE__ */ jsx("img", {
277
+ ref: image,
278
+ className: "calmlens-media__content",
279
+ src: state.src,
280
+ srcSet: state.srcSet,
281
+ sizes,
282
+ alt,
283
+ width,
284
+ height,
285
+ loading: lazy ? "lazy" : void 0,
286
+ decoding: "async",
287
+ fetchPriority,
288
+ onLoad: () => setLoad({
289
+ key: loadKey,
290
+ state: "loaded"
291
+ }),
292
+ onError: () => setLoad({
293
+ key: loadKey,
294
+ state: "error"
295
+ })
296
+ }, loadKey),
297
+ state.kind === "video" && current.state !== "error" && /* @__PURE__ */ jsx("video", {
298
+ className: "calmlens-media__content",
299
+ src: state.src,
300
+ controls,
301
+ playsInline: true,
302
+ preload: "metadata",
303
+ "aria-label": alt || void 0,
304
+ onError: () => setLoad({
305
+ key: loadKey,
306
+ state: "error"
307
+ })
308
+ }),
309
+ state.kind === "audio" && current.state !== "error" && /* @__PURE__ */ jsx("audio", {
310
+ className: "calmlens-media__content",
311
+ src: state.src,
312
+ controls,
313
+ preload: "metadata",
314
+ "aria-label": alt || void 0,
315
+ onError: () => setLoad({
316
+ key: loadKey,
317
+ state: "error"
318
+ })
319
+ }),
320
+ state.kind === "gated" && /* @__PURE__ */ jsxs("figcaption", {
321
+ className: "calmlens-media__notice",
322
+ children: [
323
+ /* @__PURE__ */ jsx("strong", { children: messages.sensitiveTitle }),
324
+ /* @__PURE__ */ jsx("p", { children: messages.sensitiveBody }),
325
+ onReveal && /* @__PURE__ */ jsx("button", {
326
+ type: "button",
327
+ className: "calmlens-button",
328
+ onClick: onReveal,
329
+ children: messages.reveal
330
+ })
331
+ ]
332
+ }),
333
+ kind === "unavailable" && /* @__PURE__ */ jsx("figcaption", {
334
+ className: "calmlens-media__notice",
335
+ children: /* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx(Icon, { name: "unavailable" }), /* @__PURE__ */ jsx("span", {
336
+ className: "calmlens-media__label",
337
+ children: getMediaUnavailableMessage(state, messages)
338
+ })] })
339
+ })
340
+ ]
341
+ });
342
+ }
343
+ export { CALMLENS_STYLES, CALMLENS_THEME, CalmLensMedia, CalmLensUploader, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, UploadController, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme, useCalmLensUpload };
@@ -0,0 +1,33 @@
1
+ import { a as selectModerationContextItems, i as ModerationContextItem, n as MODERATION_CONTEXT_USED_CHARACTERS, o as HashList, r as MODERATION_CONTEXT_USED_ITEMS, s as HashListEntry, t as ModerationContext } from "./ModerationContext-9lGm-Mna-CcmbRnOy.js";
2
+ import { $ as IterateAssetsOptions, $t as ExtractedText, A as ClassifyTextOptions, At as WebhookPayloadInput, B as EnsureLensesOptions, Bt as EventSeverity, C as BatchAssetsResponse, Ct as UploadAssetPartOptions, D as CdnResource, Dt as ViewerClaims, E as CdnAssetUrlOptions, Et as VerifyWebhookSignatureOptions, F as CreateMultipartUploadPartOptions, Ft as TypedEvent, G as HashListEntryIdOptions, Gt as Order, H as FolderIdOptions, I as DecideAssetOptions, It as EventCategory, J as HashListPage, Jt as AssetSearchQuery, K as HashListEntryPage, Kt as LensType, L as DeleteAssetContentOptions, Lt as EventFact, M as CreateAssetSignedUrlOptions, Mt as GetEventsResponse, N as CreateFolderOptions, O as CdnServeOptions, Ot as WaitForAssetDecisionOptions, P as CreateHashListOptions, Pt as EventAsset, Q as IterateAssetChildrenOptions, Qt as AssetSafetyHoldReason, R as DeleteAssetOptions, Rt as EventFactValues, S as BatchAssetsOptions, St as UpdateHashListOptions, T as CalmLensServerClientOptions, Tt as UploadedAsset, Ut as Folder, V as ExplainAssetOptions, Vt as EventType, W as GetAssetUrlOptions, Wt as CursorPage, X as ImageTransform, Xt as AssetImage, Y as IdempotencyOptions, Z as ImageTransformOptions, Zt as AssetSafetyHold, _ as AssetSearchResult, _t as SignedUploadToken, a as AssetClassification, b as AssetUploadStatus, bt as UpdateAssetOptions, c as AssetContent, ct as MoveAssetOptions, d as AssetContentStatus, dt as MultipartUploadPartOptions, en as FileMetadata, et as Lens, f as AssetModeration, ft as RequestOptions, g as AssetSearchResponse, gt as SignUploadTokenOptions, h as AssetPage, ht as SearchAssetsOptions, i as AssetChildrenPage, it as ListEventsOptions, j as ConnectionOptions, jt as AssetBatchOperation, k as CdnTransform, kt as WebhookHeadersInput, l as AssetContentOptions, lt as MoveFolderOptions, m as AssetModerationStatus, mt as RetryAssetOptions, n as Asset, nn as ProcessingOptions, nt as ListAssetChildrenOptions, o as AssetClassificationFailureReason, ot as ListHashListEntriesOptions, p as AssetModerationDecision, pt as RetrieveAssetOptions, q as HashListIdOptions, qt as AssetSearchMatchField, r as AssetChecksums, rt as ListAssetsOptions, s as AssetClassificationStatus, st as ListHashListsOptions, t as AddHashListEntryOptions, tn as MetadataItem, tt as LensTransform, u as AssetContentRemovalReason, ut as MultipartUploadOptions, v as AssetType, vt as SignedUrl, w as CalmLensAppClientOptions, wt as UploadPresetSubmitAssetOptions, x as AssetVisibility, xt as UpdateFolderOptions, y as AssetUpload, yt as SubmitAssetOptions, z as EnsureLensOptions, zt as EventFacts } from "./CalmLensTypes-9Vt16pc7.js";
3
+ import { a as CalmLensErrorCode, c as SdkErrorCode, i as CalmLensError, l as ApiErrorCode, o as CalmLensErrorDetails, r as CALMLENS_ERROR_CODES, s as CalmLensErrorOptions, t as ReceivedWebhookEventPayload } from "./WebhookPayload-2aL31v0J.js";
4
+ import { a as ProcessingFeatureId, c as ProcessingFeatures, d as getAssetUrl, i as DetectedPerson, l as SDK_VERSION, n as BoundingBox, o as ProcessingFeatureResults, r as DetectedFace, s as ProcessingFeatureStage, t as AgeRange, u as DEFAULT_CDN_BASE_URL } from "./index-CI4BzN4W.js";
5
+ import { a as ClassificationNotEvaluatedReason, c as ModerationQualifier, i as ClassificationLabel, l as PolicyAction, n as ClassificationCategory, o as ClassificationQualifierResults, r as ClassificationCategoryReport, s as Likelihood, t as ClassificationCategories } from "./Classification-94kSYWZw-CMnQKW13.js";
6
+ import { t as CalmLensServerClient } from "./CalmLensServerClient-JtP687a3.js";
7
+ export declare const WEBHOOK_DELIVERY_HEADER = "x-calmlens-delivery";
8
+ export declare const WEBHOOK_TIMESTAMP_HEADER = "x-calmlens-timestamp";
9
+ export declare const WEBHOOK_SIGNATURE_HEADER = "x-calmlens-signature";
10
+ /** Deliveries whose timestamp is further than this from the receiver's clock are rejected. */
11
+ export declare const WEBHOOK_SIGNATURE_TOLERANCE_SECONDS = 300;
12
+ /**
13
+ * Verifies a webhook delivery: `x-calmlens-signature` must contain a `v1=` HMAC-SHA256 of
14
+ * `"<x-calmlens-timestamp>.<raw body>"`, and the timestamp must be within `toleranceSeconds`
15
+ * (default 300) of now. Returns `false` for anything missing, malformed or stale, and throws
16
+ * `sdk/invalid-argument` when `payload` is not a raw body (for example, parsed JSON).
17
+ */
18
+ export declare function verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<boolean>;
19
+ /**
20
+ * Verifies a webhook delivery and parses its body. Throws `sdk/invalid-webhook-signature`
21
+ * when the signature or timestamp does not verify, and `sdk/invalid-webhook-payload` when a
22
+ * verified body is not a webhook event. Unknown event types, fact values and fields remain available.
23
+ *
24
+ * Event types and fact keys added to CalmLens after this SDK version are returned as they are,
25
+ * so keep a default branch when you switch on `type`.
26
+ */
27
+ export declare function parseWebhookEvent(options: VerifyWebhookSignatureOptions): Promise<ReceivedWebhookEventPayload>;
28
+ /**
29
+ * Whether a webhook event is a test send from the portal or the CLI rather than a real event: it
30
+ * carries the registered `{ key: "test", value: true }` fact.
31
+ */
32
+ export declare const isTestWebhookEvent: (event: Pick<ReceivedWebhookEventPayload, "facts">) => boolean;
33
+ export { type AddHashListEntryOptions, type AgeRange, type ApiErrorCode, type Asset, type AssetBatchOperation, type AssetChecksums, type AssetChildrenPage, type AssetClassification, type AssetClassificationFailureReason, type AssetClassificationStatus, type AssetContent, type AssetContentOptions, type AssetContentRemovalReason, type AssetContentStatus, type AssetImage, type AssetModeration, type AssetModerationDecision, type AssetModerationStatus, type AssetPage, type AssetSafetyHold, type AssetSafetyHoldReason, type AssetSearchMatchField, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetType, type AssetUpload, type AssetUploadStatus, type AssetVisibility, type BatchAssetsOptions, type BatchAssetsResponse, type BoundingBox, CALMLENS_ERROR_CODES, type CalmLensAppClientOptions, CalmLensError, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, CalmLensServerClient, type CalmLensServerClientOptions, type CdnAssetUrlOptions, type CdnResource, type CdnServeOptions, type CdnTransform, type ClassificationCategories, type ClassificationCategory, type ClassificationCategoryReport, type ClassificationLabel, type ClassificationNotEvaluatedReason, type ClassificationQualifierResults, type ClassifyTextOptions, type ConnectionOptions, type CreateAssetSignedUrlOptions, type CreateFolderOptions, type CreateHashListOptions, type CreateMultipartUploadPartOptions, type CursorPage, DEFAULT_CDN_BASE_URL, type DecideAssetOptions, type DeleteAssetContentOptions, type DeleteAssetOptions, type DetectedFace, type DetectedPerson, type EnsureLensOptions, type EnsureLensesOptions, type EventAsset, type EventCategory, type EventFact, type EventFactValues, type EventFacts, type EventSeverity, type EventType, type GetEventsResponse as EventsPage, type ExplainAssetOptions, type ExtractedText, type FileMetadata, type Folder, type FolderIdOptions, type GetAssetUrlOptions, type HashList, type HashListEntry, type HashListEntryIdOptions, type HashListEntryPage, type HashListIdOptions, type HashListPage, type IdempotencyOptions, type ImageTransform, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, type LensType, type Likelihood, type ListAssetChildrenOptions, type ListAssetsOptions, type ListEventsOptions, type ListHashListEntriesOptions, type ListHashListsOptions, MODERATION_CONTEXT_USED_CHARACTERS, MODERATION_CONTEXT_USED_ITEMS, type MetadataItem, type ModerationContext, type ModerationContextItem, type ModerationQualifier, type MoveAssetOptions, type MoveFolderOptions, type MultipartUploadOptions, type MultipartUploadPartOptions, type Order, type PolicyAction, type ProcessingFeatureId, type ProcessingFeatureResults, type ProcessingFeatureStage, type ProcessingFeatures, type ProcessingOptions, type RequestOptions, type RetrieveAssetOptions, type RetryAssetOptions, SDK_VERSION, type SdkErrorCode, type SearchAssetsOptions, type SignUploadTokenOptions, type SignedUploadToken, type SignedUrl, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UpdateHashListOptions, type UploadAssetPartOptions, type UploadPresetSubmitAssetOptions, type UploadedAsset, type VerifyWebhookSignatureOptions, type ViewerClaims, type WaitForAssetDecisionOptions, type ReceivedWebhookEventPayload as WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput, getAssetUrl, selectModerationContextItems };
package/esm/server.js ADDED
@@ -0,0 +1,4 @@
1
+ import { D as CALMLENS_ERROR_CODES, O as CalmLensError, c as DEFAULT_CDN_BASE_URL, i as SDK_VERSION, n as MODERATION_CONTEXT_USED_ITEMS, r as selectModerationContextItems, t as MODERATION_CONTEXT_USED_CHARACTERS, u as getAssetUrl } from "./ModerationContextLimits-BaX2QnU8.js";
2
+ import "./index.js";
3
+ import { a as WEBHOOK_TIMESTAMP_HEADER, c as verifyWebhookSignature, i as WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, n as WEBHOOK_DELIVERY_HEADER, o as isTestWebhookEvent, r as WEBHOOK_SIGNATURE_HEADER, s as parseWebhookEvent, t as CalmLensServerClient } from "./CalmLensServerClient-D80_mKpW.js";
4
+ export { CALMLENS_ERROR_CODES, CalmLensError, CalmLensServerClient, DEFAULT_CDN_BASE_URL, MODERATION_CONTEXT_USED_CHARACTERS, MODERATION_CONTEXT_USED_ITEMS, SDK_VERSION, WEBHOOK_DELIVERY_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, WEBHOOK_TIMESTAMP_HEADER, getAssetUrl, isTestWebhookEvent, parseWebhookEvent, selectModerationContextItems, verifyWebhookSignature };
package/esm/styles.css ADDED
@@ -0,0 +1,147 @@
1
+ /* Zero specificity, so a page's own --calmlens-* values win even on the same element. */
2
+ :where(.calmlens-uploader, .calmlens-media) {
3
+ --calmlens-accent: #635bff;
4
+ --calmlens-accent-text: #fff;
5
+ --calmlens-radius: 12px;
6
+ --calmlens-border: color-mix(in srgb, currentColor 18%, transparent);
7
+ --calmlens-surface: color-mix(in srgb, currentColor 4%, transparent);
8
+ --calmlens-background: transparent;
9
+ --calmlens-muted: color-mix(in srgb, currentColor 72%, transparent);
10
+ --calmlens-success: #12a26f;
11
+ --calmlens-warning: #e8a317;
12
+ --calmlens-danger: #e5484d;
13
+ --calmlens-focus-ring: var(--calmlens-accent);
14
+ --calmlens-focus-width: 2px;
15
+ --calmlens-focus-offset: 2px;
16
+ box-sizing: border-box;
17
+ font: inherit;
18
+ }
19
+ .calmlens-uploader *, .calmlens-media * { box-sizing: border-box; }
20
+ .calmlens-uploader { display: grid; gap: 12px; }
21
+ .calmlens-uploader > [hidden] { display: none; }
22
+ .calmlens-dropzone {
23
+ display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
24
+ padding: 40px 24px; text-align: center;
25
+ border: 1.5px dashed var(--calmlens-border); border-radius: var(--calmlens-radius);
26
+ background: var(--calmlens-surface); cursor: pointer;
27
+ transition: border-color 200ms ease-in-out, background-color 200ms ease-in-out;
28
+ }
29
+ .calmlens-dropzone:hover, .calmlens-dropzone:focus-within {
30
+ border-color: color-mix(in srgb, var(--calmlens-accent) 30%, transparent);
31
+ background: color-mix(in srgb, var(--calmlens-accent) 4%, transparent);
32
+ }
33
+ .calmlens-dropzone[data-dragging] {
34
+ border-color: var(--calmlens-accent);
35
+ background: color-mix(in srgb, var(--calmlens-accent) 9%, transparent);
36
+ }
37
+ .calmlens-dropzone[data-disabled] {
38
+ cursor: not-allowed; border-color: var(--calmlens-border); background: none; color: var(--calmlens-muted);
39
+ }
40
+ .calmlens-dropzone__icon {
41
+ display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
42
+ color: var(--calmlens-accent); background: color-mix(in srgb, var(--calmlens-accent) 10%, transparent);
43
+ transition: transform 200ms;
44
+ }
45
+ .calmlens-dropzone[data-disabled] .calmlens-dropzone__icon { color: inherit; background: var(--calmlens-surface); }
46
+ .calmlens-dropzone[data-dragging] .calmlens-dropzone__icon { transform: scale(1.1); }
47
+ .calmlens-dropzone__text { display: grid; gap: 4px; }
48
+ .calmlens-dropzone__title { font-weight: 500; margin: 0; }
49
+ .calmlens-dropzone__hint { font-size: 0.875em; margin: 0; color: var(--calmlens-muted); }
50
+ .calmlens-button, .calmlens-icon-button { margin: 0; width: auto; text-transform: none; letter-spacing: normal; }
51
+ .calmlens-button {
52
+ font: inherit; font-weight: 500; font-size: 0.875em; padding: 7px 14px; border-radius: 8px; cursor: pointer;
53
+ border: 1px solid var(--calmlens-accent); background: var(--calmlens-accent); color: var(--calmlens-accent-text);
54
+ white-space: nowrap; transition: background-color 150ms, border-color 150ms;
55
+ }
56
+ .calmlens-button:focus-visible, .calmlens-icon-button:focus-visible {
57
+ outline: var(--calmlens-focus-width) solid var(--calmlens-focus-ring); outline-offset: var(--calmlens-focus-offset);
58
+ }
59
+ .calmlens-button:hover:not(:disabled) { background: var(--calmlens-accent); filter: brightness(1.08); }
60
+ .calmlens-button[data-variant="outline"] { background: none; color: inherit; border-color: var(--calmlens-border); }
61
+ .calmlens-button[data-variant="outline"]:hover:not(:disabled) {
62
+ filter: none; background: color-mix(in srgb, var(--calmlens-accent) 8%, transparent); border-color: var(--calmlens-accent);
63
+ }
64
+ .calmlens-button[data-size="small"] { padding: 4px 10px; }
65
+ .calmlens-button:disabled {
66
+ cursor: not-allowed; border-style: dashed; background: none; color: var(--calmlens-muted); border-color: var(--calmlens-border);
67
+ }
68
+ .calmlens-uploads { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
69
+ .calmlens-upload {
70
+ display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px;
71
+ border: 1px solid var(--calmlens-border); border-radius: var(--calmlens-radius); background: var(--calmlens-background);
72
+ }
73
+ /* A finished file's outcome is a dot in its status colour before the message. */
74
+ .calmlens-upload[data-outcome] .calmlens-upload__message::before {
75
+ content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%;
76
+ vertical-align: 0.05em;
77
+ }
78
+ .calmlens-upload[data-outcome="accepted"] .calmlens-upload__message::before { background: var(--calmlens-success); }
79
+ .calmlens-upload[data-outcome="restricted"] .calmlens-upload__message::before { background: var(--calmlens-warning); }
80
+ .calmlens-upload[data-outcome="rejected"] .calmlens-upload__message::before { background: var(--calmlens-danger); }
81
+ .calmlens-upload__thumb {
82
+ width: 40px; height: 40px; border-radius: 8px; object-fit: cover; display: grid; place-items: center;
83
+ background: var(--calmlens-surface); border: 1px solid var(--calmlens-border);
84
+ font-size: 0.6875em; font-weight: 700; text-transform: uppercase; overflow: hidden;
85
+ }
86
+ .calmlens-upload__thumb[data-kind="file"] { background: none; border: none; }
87
+ .calmlens-upload[data-outcome="rejected"] img.calmlens-upload__thumb { filter: blur(6px); }
88
+ .calmlens-upload__body { min-width: 0; display: grid; gap: 4px; }
89
+ .calmlens-upload__name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
90
+ .calmlens-upload__size { font-size: 0.875em; color: var(--calmlens-muted); }
91
+ .calmlens-upload__message { font-size: 0.875em; margin: 0; }
92
+ .calmlens-progress {
93
+ height: 4px; border-radius: 2px; overflow: hidden; background: var(--calmlens-border); position: relative;
94
+ }
95
+ .calmlens-progress__bar {
96
+ position: absolute; inset: 0 auto 0 0; background: var(--calmlens-accent); border-radius: inherit;
97
+ transition: width 150ms;
98
+ }
99
+ .calmlens-progress:not([aria-valuenow]) .calmlens-progress__bar {
100
+ width: 35%; animation: calmlens-indeterminate 1.1s ease-in-out infinite;
101
+ }
102
+ @keyframes calmlens-indeterminate { from { left: -35%; } to { left: 100%; } }
103
+ .calmlens-upload__actions { display: flex; gap: 8px; align-items: center; }
104
+ .calmlens-icon-button {
105
+ display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border-radius: 8px; cursor: pointer;
106
+ border: 1px solid transparent; background: none; color: inherit;
107
+ }
108
+ .calmlens-icon-button:hover { background: color-mix(in srgb, var(--calmlens-accent) 8%, transparent); border-color: var(--calmlens-border); }
109
+ @media (prefers-reduced-motion: reduce) {
110
+ .calmlens-progress__bar, .calmlens-dropzone, .calmlens-dropzone__icon, .calmlens-media__content { transition: none; }
111
+ .calmlens-progress:not([aria-valuenow]) .calmlens-progress__bar { animation: none; left: 0; width: 100%; }
112
+ }
113
+
114
+ .calmlens-media {
115
+ position: relative; display: block; overflow: hidden; margin: 0; border-radius: var(--calmlens-media-radius, 0);
116
+ background: var(--calmlens-surface);
117
+ }
118
+ .calmlens-media__placeholder, .calmlens-media__content {
119
+ position: absolute; inset: 0; width: 100%; height: 100%; object-fit: var(--calmlens-fit, cover);
120
+ object-position: var(--calmlens-position, center);
121
+ }
122
+ .calmlens-media:not([data-sized]) .calmlens-media__content { position: relative; height: auto; }
123
+ .calmlens-media:not([data-sized])[data-kind="gated"], .calmlens-media:not([data-sized])[data-kind="unavailable"],
124
+ .calmlens-media:not([data-sized])[data-state="error"] { min-height: 160px; }
125
+ .calmlens-media__placeholder { transform: scale(1.1); filter: blur(12px); }
126
+ .calmlens-media__content { opacity: 0; transition: opacity 250ms; }
127
+ .calmlens-media[data-state="loaded"] .calmlens-media__content { opacity: 1; }
128
+ .calmlens-media[data-kind="video"] .calmlens-media__content, .calmlens-media[data-kind="audio"] .calmlens-media__content { opacity: 1; }
129
+ .calmlens-media[data-kind="audio"] { background: none; }
130
+ .calmlens-media[data-kind="audio"] .calmlens-media__content { position: static; height: auto; }
131
+ .calmlens-media__notice {
132
+ position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 6px;
133
+ padding: 12px; text-align: center; color: #fff; background: rgba(0, 0, 0, 0.45);
134
+ }
135
+ .calmlens-media__notice p { margin: 0; display: flex; gap: 6px; align-items: center; }
136
+ /* Thumbnails keep the notice's icon and leave its text to screen readers. */
137
+ .calmlens-media[data-sized] { container-type: inline-size; }
138
+ @container (max-width: 119px) {
139
+ .calmlens-media__label, .calmlens-media__notice > strong, .calmlens-media__notice > p:not(:has(svg)) {
140
+ position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
141
+ }
142
+ }
143
+ .calmlens-media__notice strong { font-weight: 600; }
144
+ .calmlens-media__notice .calmlens-button { margin-top: 4px; border-color: #fff; background: #fff; color: #111; }
145
+ .calmlens-media[data-state="error"] .calmlens-media__notice, .calmlens-media[data-kind="unavailable"] .calmlens-media__notice {
146
+ color: inherit; background: var(--calmlens-surface);
147
+ }
@@ -0,0 +1,134 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import {
4
+ getMediaAspectRatio,
5
+ getMediaLoadKey,
6
+ getMediaState,
7
+ getMediaUnavailableMessage,
8
+ type MediaOptions,
9
+ type MediaProps,
10
+ resolveMediaProps,
11
+ resolveMessages,
12
+ } from "../ui.js";
13
+ import Icon from "./Icon.svelte";
14
+
15
+ let {
16
+ alt = "",
17
+ aspectRatio,
18
+ width,
19
+ height,
20
+ sizes,
21
+ averageColor,
22
+ fit,
23
+ position,
24
+ lazy = true,
25
+ fetchPriority,
26
+ controls = true,
27
+ messages: overrides,
28
+ onReveal,
29
+ ...options
30
+ }: MediaProps = $props();
31
+
32
+ const messages = $derived(resolveMessages(overrides));
33
+ // An `asset` fills in what isn't passed: the source, status and type, and its preview's size.
34
+ const view = $derived(
35
+ resolveMediaProps({ ...(options as MediaOptions), width, height, averageColor }),
36
+ );
37
+ const state = $derived(getMediaState(view));
38
+ const loadKey = $derived(getMediaLoadKey(state));
39
+ const ratio = $derived(
40
+ getMediaAspectRatio({ aspectRatio, width: view.width, height: view.height }),
41
+ );
42
+ let load: "loading" | "loaded" | "error" = $state("loading");
43
+ let image: HTMLImageElement | undefined = $state();
44
+
45
+ $effect.pre(() => {
46
+ void loadKey;
47
+ load = "loading";
48
+ });
49
+ onMount(() => {
50
+ // An image that loaded before hydration fires no load event.
51
+ if (image?.complete && image.naturalWidth > 0) load = "loaded";
52
+ });
53
+
54
+ const onError = () => {
55
+ load = "error";
56
+ };
57
+ const placeholderUrl = $derived(
58
+ state.kind === "audio" || state.kind === "unavailable" ? undefined : state.placeholderUrl,
59
+ );
60
+ const showPlaceholder = $derived(
61
+ placeholderUrl && (state.kind === "gated" || (state.kind === "image" && load !== "loaded")),
62
+ );
63
+ const failed = $derived(load === "error");
64
+ </script>
65
+
66
+ <figure
67
+ class="calmlens-media"
68
+ data-kind={state.kind}
69
+ data-state={load}
70
+ data-sized={ratio ? "" : undefined}
71
+ style:aspect-ratio={ratio}
72
+ style:background-color={view.averageColor}
73
+ style:--calmlens-fit={fit}
74
+ style:--calmlens-position={position}
75
+ >
76
+ {#if showPlaceholder}
77
+ <img class="calmlens-media__placeholder" src={placeholderUrl} alt="" aria-hidden="true" />
78
+ {/if}
79
+ {#if state.kind === "image" && !failed}
80
+ {#key loadKey}
81
+ <img
82
+ bind:this={image}
83
+ class="calmlens-media__content"
84
+ src={state.src}
85
+ srcset={state.srcSet}
86
+ {sizes}
87
+ {alt}
88
+ width={view.width}
89
+ height={view.height}
90
+ loading={lazy ? "lazy" : undefined}
91
+ decoding="async"
92
+ fetchpriority={fetchPriority}
93
+ onload={() => (load = "loaded")}
94
+ onerror={onError}
95
+ />
96
+ {/key}
97
+ {:else if state.kind === "video" && !failed}
98
+ <!-- svelte-ignore a11y_media_has_caption -->
99
+ <!-- biome-ignore lint/a11y/useMediaCaption: captions are your app's to add -->
100
+ <video
101
+ class="calmlens-media__content"
102
+ src={state.src}
103
+ {controls}
104
+ playsinline
105
+ preload="metadata"
106
+ aria-label={alt || undefined}
107
+ onerror={() => (load = "error")}
108
+ ></video>
109
+ {:else if state.kind === "audio" && !failed}
110
+ <!-- biome-ignore lint/a11y/useMediaCaption: audio has no captions track to add here -->
111
+ <audio
112
+ class="calmlens-media__content"
113
+ src={state.src}
114
+ {controls}
115
+ preload="metadata"
116
+ aria-label={alt || undefined}
117
+ onerror={() => (load = "error")}
118
+ ></audio>
119
+ {/if}
120
+ {#if state.kind === "gated"}
121
+ <figcaption class="calmlens-media__notice">
122
+ <strong>{messages.sensitiveTitle}</strong>
123
+ <p>{messages.sensitiveBody}</p>
124
+ {#if onReveal}
125
+ <button type="button" class="calmlens-button" onclick={onReveal}>{messages.reveal}</button>
126
+ {/if}
127
+ </figcaption>
128
+ {/if}
129
+ {#if state.kind === "unavailable" || failed}
130
+ <figcaption class="calmlens-media__notice">
131
+ <p><Icon name="unavailable" /><span class="calmlens-media__label">{getMediaUnavailableMessage(state, messages)}</span></p>
132
+ </figcaption>
133
+ {/if}
134
+ </figure>