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.
Files changed (110) hide show
  1. package/README.md +15 -10
  2. package/bin/calmlens.js +1848 -679
  3. package/cjs/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
  4. package/cjs/{BrowserUpload-CjSHjx3C.js → BrowserUpload-Bwlib4Zc.js} +1 -1
  5. package/cjs/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
  6. package/cjs/{CalmLensAppClient-NaCxOVlM.js → CalmLensAppClient-DUYMo9PZ.js} +30 -10
  7. package/cjs/{CalmLensOptionKeys-p2QK687A.js → CalmLensOptionKeys-YvgV995V.js} +318 -374
  8. package/cjs/{CalmLensServerClient-BDzTthxE.js → CalmLensServerClient-3N-gdsxC.js} +346 -89
  9. package/cjs/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
  10. package/cjs/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
  11. package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
  12. package/cjs/Core-C33pkBmf.d.ts +826 -0
  13. package/cjs/Core-Cm5Z1oJ9.js +1001 -0
  14. package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
  15. package/cjs/{ModerationContextLimits-2nIv7Zh3.js → ModerationContextLimits-ud1xpZRK.js} +727 -268
  16. package/cjs/{ReactUpload-BdTRCTGA.js → ReactUpload-DQ0BYISX.js} +1 -1
  17. package/cjs/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
  18. package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
  19. package/cjs/{TestTriggers-DbhsNPdg-DjvVuc2h.js → TestTriggers-D29T_R0M-D6Bu-Mln.js} +355 -47
  20. package/cjs/{UploadController-MLVs97Zt.js → UploadController-l8fZM2qT.js} +34 -14
  21. package/{esm/WebhookPayload-DkukERKE.d.ts → cjs/WebhookPayload-Dt6DttS0.d.ts} +120 -86
  22. package/cjs/app.d.ts +6 -7
  23. package/cjs/app.js +4 -3
  24. package/cjs/elements.d.ts +123 -22
  25. package/cjs/elements.js +553 -156
  26. package/cjs/file-icons.d.ts +2 -67
  27. package/cjs/index-Bde1wjiw.d.ts +16 -0
  28. package/cjs/index.d.ts +5 -6
  29. package/cjs/index.js +3 -2
  30. package/cjs/react-native.d.ts +52 -11
  31. package/cjs/react-native.js +231 -99
  32. package/cjs/react.d.ts +42 -9
  33. package/cjs/react.js +381 -118
  34. package/cjs/server.d.ts +48 -7
  35. package/cjs/server.js +7 -3
  36. package/cjs/test-inputs.d.ts +2 -2
  37. package/cjs/test-inputs.js +13 -9
  38. package/cjs/testing.d.ts +29 -15
  39. package/cjs/testing.js +1722 -433
  40. package/cjs/ui-BRA4HQ8r.js +1359 -0
  41. package/cjs/ui-YQuvbidU.d.ts +139 -0
  42. package/cjs/ui.d.ts +3 -2
  43. package/cjs/ui.js +45 -22
  44. package/cjs/vue.d.ts +802 -199
  45. package/cjs/vue.js +359 -127
  46. package/esm/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
  47. package/esm/{BrowserUpload-CAVkRotw.js → BrowserUpload-GRZVB0G_.js} +1 -1
  48. package/esm/{CalmLensAppClient-PQ9VBvlW.js → CalmLensAppClient-B5QIJ6KS.js} +30 -10
  49. package/esm/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
  50. package/esm/{CalmLensOptionKeys-Do2mPP6w.js → CalmLensOptionKeys-BG7Qrh8-.js} +317 -367
  51. package/esm/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
  52. package/esm/{CalmLensServerClient-C_H5aAsV.js → CalmLensServerClient-bRUAebi-.js} +323 -90
  53. package/esm/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
  54. package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
  55. package/esm/Core-BvQe4moS.js +846 -0
  56. package/esm/Core-C33pkBmf.d.ts +826 -0
  57. package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
  58. package/esm/{ModerationContextLimits-Chw-AzgL.js → ModerationContextLimits-CrxSnVZ3.js} +682 -253
  59. package/esm/{ReactUpload-CMmL0R5Q.js → ReactUpload-BMO8saxT.js} +1 -1
  60. package/esm/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
  61. package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
  62. package/esm/{TestTriggers-DbhsNPdg-CUdrv8Nm.js → TestTriggers-D29T_R0M-Ztc74ucs.js} +332 -48
  63. package/esm/{UploadController-BJZghJpg.js → UploadController-DnJrWiE4.js} +34 -14
  64. package/{cjs/WebhookPayload-DkukERKE.d.ts → esm/WebhookPayload-Dt6DttS0.d.ts} +120 -86
  65. package/esm/app.d.ts +6 -7
  66. package/esm/app.js +3 -3
  67. package/esm/elements.d.ts +123 -22
  68. package/esm/elements.js +497 -128
  69. package/esm/file-icons.d.ts +2 -67
  70. package/esm/index-Bde1wjiw.d.ts +16 -0
  71. package/esm/index.d.ts +5 -6
  72. package/esm/index.js +1 -1
  73. package/esm/react-native.d.ts +52 -11
  74. package/esm/react-native.js +205 -75
  75. package/esm/react.d.ts +42 -9
  76. package/esm/react.js +327 -91
  77. package/esm/server.d.ts +48 -7
  78. package/esm/server.js +3 -3
  79. package/esm/styles.css +142 -22
  80. package/esm/svelte/AssetViewer.svelte +25 -0
  81. package/esm/svelte/CalmLensAsset.svelte +318 -0
  82. package/esm/svelte/CalmLensDocumentViewer.svelte +7 -0
  83. package/esm/svelte/CalmLensImageViewer.svelte +7 -0
  84. package/esm/svelte/CalmLensSpreadsheetViewer.svelte +7 -0
  85. package/esm/svelte/CalmLensTextViewer.svelte +7 -0
  86. package/esm/svelte/CalmLensWebsiteViewer.svelte +7 -0
  87. package/esm/svelte/index.d.ts +29 -6
  88. package/esm/svelte/index.js +7 -2
  89. package/esm/test-inputs.d.ts +2 -2
  90. package/esm/test-inputs.js +1 -1
  91. package/esm/testing.d.ts +29 -15
  92. package/esm/testing.js +1718 -429
  93. package/esm/ui-YQuvbidU.d.ts +139 -0
  94. package/esm/ui-heryDd6g.js +1258 -0
  95. package/esm/ui.d.ts +3 -2
  96. package/esm/ui.js +4 -3
  97. package/esm/vue.d.ts +802 -199
  98. package/esm/vue.js +308 -103
  99. package/package.json +4 -2
  100. package/cjs/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
  101. package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
  102. package/cjs/index-DxbJ_Xaa.d.ts +0 -253
  103. package/cjs/ui-BSqPGKrZ.d.ts +0 -539
  104. package/cjs/ui-CX1z2pD9.js +0 -586
  105. package/esm/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
  106. package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
  107. package/esm/index-DxbJ_Xaa.d.ts +0 -253
  108. package/esm/svelte/CalmLensMedia.svelte +0 -134
  109. package/esm/ui-BSqPGKrZ.d.ts +0 -539
  110. package/esm/ui-CXH7xJpb.js +0 -461
package/esm/vue.js CHANGED
@@ -1,7 +1,75 @@
1
- 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, 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-CXH7xJpb.js";
2
- import { i as createProgressFetch, n as createUploadController$1, r as isFileAccepted, t as UploadController } from "./UploadController-BJZghJpg.js";
3
- import { t as createUploadController } from "./BrowserUpload-CAVkRotw.js";
4
- import { computed, defineComponent, h, onMounted, onScopeDispose, ref, shallowRef, toValue, watch, watchEffect } from "vue";
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
+ import { computed, defineComponent, h, onBeforeUnmount, onMounted, onScopeDispose, ref, shallowRef, toValue, watch, watchEffect } from "vue";
7
+ // src/viewers/Vue.ts
8
+ const optional$1 = (type) => ({
9
+ type,
10
+ default: void 0
11
+ });
12
+ const viewer = (name, kind) => defineComponent({
13
+ name,
14
+ props: {
15
+ /** The asset URL, public or signed. */
16
+ src: {
17
+ type: String,
18
+ required: true
19
+ },
20
+ /** The asset's display info (`getAssetInfo`), or the asset from the API. */
21
+ asset: {
22
+ type: Object,
23
+ required: true
24
+ },
25
+ /** Returns a fresh asset URL once a signed one expires. */
26
+ onExpired: optional$1(Function),
27
+ onUnavailable: optional$1(Function),
28
+ viewerClaims: optional$1(Object),
29
+ label: optional$1(String),
30
+ messages: optional$1(Object),
31
+ /** Images: the `sizes` of a public image's responsive widths. */
32
+ sizes: optional$1(String),
33
+ /** Text and spreadsheets: text your app already has. */
34
+ text: optional$1(String),
35
+ /** Text and spreadsheets: reads the text yourself. */
36
+ getText: optional$1(Function),
37
+ /** Spreadsheets: rows shown at a time. */
38
+ pageSize: optional$1(Number),
39
+ /** Documents: where pdf.js loads its worker, fonts and decoders from. */
40
+ pdf: optional$1(Object),
41
+ /** Documents: the page shown first. */
42
+ initialPage: optional$1(Number)
43
+ },
44
+ setup(props) {
45
+ const root = ref();
46
+ let mounted;
47
+ const options = () => ({ ...props });
48
+ onMounted(() => {
49
+ mounted = ASSET_VIEWERS[kind](root.value, options());
50
+ });
51
+ watch(options, (next) => mounted?.update(next));
52
+ onBeforeUnmount(() => {
53
+ mounted?.destroy();
54
+ mounted = void 0;
55
+ });
56
+ return () => h("div", {
57
+ ref: root,
58
+ class: "calmlens-viewer",
59
+ "data-kind": kind
60
+ });
61
+ }
62
+ });
63
+ /** Shows an image asset's rendered file, fitted to the element, over its placeholder. */
64
+ const CalmLensImageViewer = viewer("CalmLensImageViewer", "image");
65
+ /** Shows a website asset's screenshot with a link to the original page. */
66
+ const CalmLensWebsiteViewer = viewer("CalmLensWebsiteViewer", "website");
67
+ /** Shows a text asset's text, escaped, in a scrolling region. */
68
+ const CalmLensTextViewer = viewer("CalmLensTextViewer", "text");
69
+ /** Shows a PDF, or a document rendered as one, a page at a time with pdf.js (loaded lazily). */
70
+ const CalmLensDocumentViewer = viewer("CalmLensDocumentViewer", "document");
71
+ /** Shows a spreadsheet's sheets as tabs and paged tables, from its extracted text. */
72
+ const CalmLensSpreadsheetViewer = viewer("CalmLensSpreadsheetViewer", "spreadsheet");
5
73
  // src/vue.ts
6
74
  const icon = (name) => h("svg", ICON_ATTRIBUTES, [h("path", { d: ICONS[name] })]);
7
75
  /** Keeps a ref to a controller's snapshot, following the controller if it changes. */
@@ -235,158 +303,295 @@ const CalmLensUploader = defineComponent({
235
303
  };
236
304
  }
237
305
  });
306
+ /** Audio's waveform: the preview still, with the played part of its peaks drawn over it. */
307
+ const waveform = (url, peaks, played) => {
308
+ if (!url && !peaks) return void 0;
309
+ const bars = () => getPeakHeights(peaks ?? []).map((height) => h("span", { style: { height: `${height}%` } }));
310
+ return h("div", { class: "calmlens-asset__waveform" }, [url && h("img", {
311
+ class: "calmlens-asset__wave",
312
+ src: url,
313
+ alt: "",
314
+ "aria-hidden": "true"
315
+ }), peaks && h("div", {
316
+ class: "calmlens-asset__progress",
317
+ role: "progressbar",
318
+ "aria-hidden": "true",
319
+ "aria-valuemin": 0,
320
+ "aria-valuemax": 100,
321
+ "aria-valuenow": played,
322
+ style: { "--calmlens-played": `${played}%` }
323
+ }, [h("div", { class: "calmlens-asset__peaks" }, bars()), h("div", {
324
+ class: "calmlens-asset__peaks",
325
+ "data-played": ""
326
+ }, bars())])]);
327
+ };
238
328
  /**
239
- * Shows an asset from the CalmLens CDN with responsive widths and a blurred placeholder while
240
- * it loads. Age-restricted assets stay behind the placeholder and a reveal button until
241
- * `ageConfirmed` is set; blocked and purged assets show an unavailable notice.
329
+ * Shows any asset from its asset URL (public, or signed by your server), natively in the page: an
330
+ * image with responsive widths, a website's screenshot and link, video and audio with their
331
+ * adaptive stream, a document, text or spreadsheet viewer, or a preview still or file icon. It
332
+ * reads `{src}/info` once mounted, unless `info` is given, in which case the first render, on the
333
+ * server too, is the real element. Emits `load`, `error`, `availability-change`, `play`, `ended`
334
+ * and `timeupdate`; listen for `age-confirm-request` to show the reveal button on age-restricted
335
+ * content. The `unavailable` and `age-gate` slots (`{ placeholderUrl, confirm }`) replace the
336
+ * notices.
242
337
  */
243
- const CalmLensMedia = defineComponent({
244
- name: "CalmLensMedia",
338
+ const CalmLensAsset = defineComponent({
339
+ name: "CalmLensAsset",
245
340
  props: {
246
- /** An asset from the API, which supplies the project, ID, status, type and preview. */
247
- asset: optional(Object),
248
- /** Required without `asset`. */
249
- projectId: optional(String),
250
- /** Required without `asset`. */
251
- assetId: optional(String),
252
- status: optional(String),
253
- contentRemoved: optional(Boolean),
254
- type: optional(String),
255
- resource: optional(String),
256
- lens: optional(String),
257
- transform: optional([
258
- String,
259
- Object,
260
- Array
261
- ]),
262
- widths: optional(Array),
263
- url: optional(String),
264
- placeholder: {
265
- type: Boolean,
266
- default: true
267
- },
268
- placeholderHash: optional(String),
269
- placeholderUrl: optional(String),
270
- averageColor: optional(String),
271
- cdnBaseUrl: optional(String),
341
+ /** The asset URL, public or signed. Nothing is requested until it is set. */
342
+ src: optional(String),
343
+ display: optional(String),
272
344
  viewerClaims: optional(Object),
345
+ /** The asset's display info, prefetched with `getAssetInfo`. */
346
+ info: optional(Object),
273
347
  alt: {
274
348
  type: String,
275
349
  default: ""
276
350
  },
277
- aspectRatio: optional(Number),
278
- width: optional(Number),
279
- height: optional(Number),
280
- sizes: optional(String),
281
351
  fit: optional(String),
282
- position: optional(String),
352
+ aspectRatio: optional(Number),
283
353
  lazy: {
284
354
  type: Boolean,
285
355
  default: true
286
356
  },
287
357
  fetchPriority: optional(String),
288
- controls: {
289
- type: Boolean,
290
- default: true
291
- },
358
+ image: optional(Object),
359
+ video: optional(Object),
360
+ document: optional(Object),
361
+ spreadsheet: optional(Object),
362
+ /** Returns a fresh asset URL from your server once a signed one expires. */
363
+ onExpired: optional(Function),
292
364
  messages: messagesProp,
293
- /** Bound by `@reveal`; declared as a prop so the button shows only when something listens. */
294
- onReveal: optional(Function)
365
+ /** Bound by `@age-confirm-request`; a prop so the reveal button shows only when bound. */
366
+ onAgeConfirmRequest: optional(Function)
295
367
  },
296
- setup(props) {
368
+ emits: {
369
+ load: () => true,
370
+ error: () => true,
371
+ "availability-change": (_availability) => true,
372
+ play: () => true,
373
+ ended: () => true,
374
+ timeupdate: (_currentTime) => true
375
+ },
376
+ setup(props, { emit, slots }) {
297
377
  const messages = computed(() => resolveMessages(props.messages));
298
- const resolved = computed(() => resolveMediaProps(props));
299
- const state = computed(() => getMediaState(resolved.value));
300
- const loadKey = computed(() => getMediaLoadKey(state.value));
378
+ const version = ref(0);
379
+ const session = new AssetSession(() => {
380
+ version.value++;
381
+ });
382
+ const options = computed(() => ({
383
+ src: props.src,
384
+ display: props.display,
385
+ viewerClaims: props.viewerClaims,
386
+ info: props.info,
387
+ image: props.image,
388
+ video: props.video,
389
+ document: props.document,
390
+ spreadsheet: props.spreadsheet,
391
+ onExpired: props.onExpired,
392
+ alt: props.alt
393
+ }));
394
+ const state = computed(() => {
395
+ version.value;
396
+ return session.update(options.value);
397
+ });
398
+ const view = computed(() => getAssetView(options.value, state.value));
399
+ const loadKey = computed(() => getAssetViewKey(view.value));
301
400
  const load = ref("loading");
401
+ const played = ref(0);
402
+ const mounted = ref(false);
302
403
  const image = ref();
404
+ const media = ref();
405
+ const viewerRoot = ref();
406
+ const failedAt = (element) => ({
407
+ position: element.currentTime || 0,
408
+ playing: !element.paused && !element.ended
409
+ });
410
+ const streams = new MediaStreamPlayer((element) => {
411
+ session.mediaFailed(failedAt(element));
412
+ return true;
413
+ });
414
+ const viewers = new AssetViewerMount();
415
+ watchEffect(() => {
416
+ state.value;
417
+ if (mounted.value) session.load();
418
+ });
419
+ watch([media, view], () => streams.update(media.value, view.value), { flush: "post" });
420
+ watch([
421
+ viewerRoot,
422
+ view,
423
+ options,
424
+ state
425
+ ], () => {
426
+ const kind = view.value.kind;
427
+ viewers.update(viewerRoot.value, isMountedViewerKind(kind) ? kind : void 0, getMountedViewerOptions(options.value, session), (viewerState) => {
428
+ if (viewerState !== "loading") load.value = viewerState;
429
+ });
430
+ }, { flush: "post" });
431
+ onScopeDispose(() => {
432
+ streams.stop();
433
+ viewers.destroy();
434
+ });
303
435
  watch(loadKey, () => {
304
436
  load.value = "loading";
305
437
  });
438
+ watch(load, (value) => {
439
+ if (value === "loaded") emit("load");
440
+ if (value === "error") emit("error");
441
+ });
442
+ const availability = computed(() => view.value.kind === "unavailable" ? "unavailable" : view.value.kind === "age-restricted" ? "age-restricted" : view.value.kind === "pending" ? void 0 : "available");
443
+ watch(availability, (value) => {
444
+ if (value) emit("availability-change", value);
445
+ }, { immediate: true });
306
446
  onMounted(() => {
447
+ mounted.value = true;
307
448
  if (image.value?.complete && image.value.naturalWidth > 0) load.value = "loaded";
308
449
  });
309
- const onError = () => {
310
- load.value = "error";
450
+ const onMediaError = (event) => {
451
+ const element = event.target;
452
+ if (!streams.recover(element)) session.mediaFailed(failedAt(element));
453
+ };
454
+ const playerEvents = {
455
+ onLoadedmetadata: (event) => {
456
+ session.mediaLoaded(event.target);
457
+ load.value = "loaded";
458
+ },
459
+ onError: onMediaError,
460
+ onPlay: () => emit("play"),
461
+ onEnded: () => emit("ended"),
462
+ onTimeupdate: (event) => {
463
+ const element = event.target;
464
+ played.value = getPlayedPercent(element);
465
+ emit("timeupdate", element.currentTime);
466
+ }
311
467
  };
312
468
  return () => {
313
- const current = state.value;
469
+ const current = view.value;
314
470
  const text = messages.value;
315
- const view = resolved.value;
316
- const ratio = getMediaAspectRatio(view);
317
- const failed = load.value === "error";
318
- const placeholderUrl = current.kind === "audio" || current.kind === "unavailable" ? void 0 : current.placeholderUrl;
319
- const showPlaceholder = placeholderUrl && (current.kind === "gated" || current.kind === "image" && load.value !== "loaded");
320
- const notice = (children) => h("figcaption", { class: "calmlens-media__notice" }, children);
471
+ const ratio = getAssetAspectRatio(current, state.value.info, props.aspectRatio);
472
+ const placeholderUrl = "placeholderUrl" in current && (current.kind === "age-restricted" || current.kind === "pending" || load.value !== "loaded") ? current.placeholderUrl : void 0;
473
+ const notice = (children) => h("figcaption", { class: "calmlens-asset__notice" }, children);
474
+ const video = props.video ?? {};
475
+ const imageElement = (shown) => h("img", {
476
+ key: loadKey.value,
477
+ ref: image,
478
+ class: "calmlens-asset__content",
479
+ src: shown.src,
480
+ srcset: shown.srcSet,
481
+ sizes: shown.srcSet ? props.image?.sizes : void 0,
482
+ alt: props.alt,
483
+ width: shown.width,
484
+ height: shown.height,
485
+ loading: props.lazy ? "lazy" : void 0,
486
+ decoding: "async",
487
+ fetchpriority: props.fetchPriority,
488
+ onLoad: () => {
489
+ session.loaded();
490
+ load.value = "loaded";
491
+ },
492
+ onError: () => session.failed()
493
+ });
494
+ const viewerShown = isMountedViewerKind(current.kind) && mounted.value;
495
+ const confirm = props.onAgeConfirmRequest;
321
496
  return h("figure", {
322
- class: "calmlens-media",
497
+ class: "calmlens-asset",
323
498
  "data-kind": current.kind,
324
499
  "data-state": load.value,
325
500
  "data-sized": ratio ? "" : void 0,
501
+ "aria-busy": current.kind === "pending" ? "true" : void 0,
326
502
  style: {
327
503
  aspectRatio: ratio,
328
- backgroundColor: view.averageColor,
329
- "--calmlens-fit": props.fit,
330
- "--calmlens-position": props.position
504
+ backgroundColor: state.value.info?.content?.preview?.averageColor ?? void 0,
505
+ "--calmlens-fit": props.fit
331
506
  }
332
507
  }, [
333
- showPlaceholder && h("img", {
334
- class: "calmlens-media__placeholder",
508
+ placeholderUrl && h("img", {
509
+ class: "calmlens-asset__placeholder",
335
510
  src: placeholderUrl,
336
511
  alt: "",
337
512
  "aria-hidden": "true"
338
513
  }),
339
- current.kind === "image" && !failed && h("img", {
340
- key: loadKey.value,
341
- ref: image,
342
- class: "calmlens-media__content",
343
- src: current.src,
344
- srcset: current.srcSet,
345
- sizes: props.sizes,
346
- alt: props.alt,
347
- width: view.width,
348
- height: view.height,
349
- loading: props.lazy ? "lazy" : void 0,
350
- decoding: "async",
351
- fetchpriority: props.fetchPriority,
352
- onLoad: () => {
353
- load.value = "loaded";
354
- },
355
- onError
356
- }),
357
- current.kind === "video" && !failed && h("video", {
358
- class: "calmlens-media__content",
359
- src: current.src,
360
- controls: props.controls,
514
+ current.kind === "image" && imageElement(current),
515
+ current.kind === "website" && current.link && h("div", { class: "calmlens-asset__bar" }, [h("a", {
516
+ class: "calmlens-button",
517
+ href: current.link,
518
+ target: "_blank",
519
+ rel: "noopener noreferrer nofollow"
520
+ }, formatMessage(text.openWebsite, { host: new URL(current.link).host }))]),
521
+ current.kind === "website" && h("div", {
522
+ class: "calmlens-asset__scroll",
523
+ role: "region",
524
+ "aria-label": props.alt || void 0,
525
+ tabindex: 0
526
+ }, [imageElement(current)]),
527
+ current.kind === "video" && h("video", {
528
+ ref: media,
529
+ class: "calmlens-asset__content",
530
+ ...current.stream ? {} : { src: current.src },
531
+ poster: current.poster,
532
+ controls: video.controls ?? true,
533
+ autoplay: video.autoPlay,
534
+ muted: video.muted,
535
+ loop: video.loop,
361
536
  playsinline: true,
362
537
  preload: "metadata",
363
538
  "aria-label": props.alt || void 0,
364
- onError: () => {
365
- load.value = "error";
366
- }
539
+ ...playerEvents
367
540
  }),
368
- current.kind === "audio" && !failed && h("audio", {
369
- class: "calmlens-media__content",
370
- src: current.src,
371
- controls: props.controls,
541
+ current.kind === "audio" && waveform(current.waveformUrl, current.peaks, played.value),
542
+ current.kind === "audio" && h("audio", {
543
+ ref: media,
544
+ class: "calmlens-asset__content",
545
+ ...current.stream ? {} : { src: current.src },
546
+ controls: video.controls ?? true,
547
+ autoplay: video.autoPlay,
548
+ muted: video.muted,
549
+ loop: video.loop,
372
550
  preload: "metadata",
373
551
  "aria-label": props.alt || void 0,
374
- onError: () => {
375
- load.value = "error";
376
- }
552
+ ...playerEvents
377
553
  }),
378
- current.kind === "gated" && notice([
554
+ current.kind === "document" && !viewerShown && current.still && h("img", {
555
+ class: "calmlens-asset__content",
556
+ src: current.still,
557
+ alt: props.alt,
558
+ decoding: "async"
559
+ }),
560
+ current.kind === "document" && !viewerShown && h("a", {
561
+ class: "calmlens-button calmlens-asset__open",
562
+ href: current.src,
563
+ target: "_blank",
564
+ rel: "noopener noreferrer"
565
+ }, text.openDocument),
566
+ viewerShown && h("div", {
567
+ ref: viewerRoot,
568
+ class: "calmlens-asset__viewer"
569
+ }),
570
+ current.kind === "file" && h("span", {
571
+ class: "calmlens-asset__file",
572
+ role: "img",
573
+ "aria-label": props.alt || void 0,
574
+ "aria-hidden": props.alt ? void 0 : "true",
575
+ innerHTML: renderFileIconSvg({
576
+ family: current.icon,
577
+ extension: ""
578
+ }, 64)
579
+ }),
580
+ current.kind === "age-restricted" && (slots["age-gate"]?.({
581
+ placeholderUrl: current.placeholderUrl,
582
+ confirm
583
+ }) ?? notice([
379
584
  h("strong", text.sensitiveTitle),
380
585
  h("p", text.sensitiveBody),
381
- props.onReveal && h("button", {
586
+ confirm && h("button", {
382
587
  type: "button",
383
588
  class: "calmlens-button",
384
- onClick: props.onReveal
589
+ onClick: confirm
385
590
  }, text.reveal)
386
- ]),
387
- (current.kind === "unavailable" || failed) && notice([h("p", [icon("unavailable"), h("span", { class: "calmlens-media__label" }, getMediaUnavailableMessage(current, text))])])
591
+ ])),
592
+ current.kind === "unavailable" && (slots.unavailable?.() ?? notice([h("p", [icon("unavailable"), h("span", { class: "calmlens-asset__label" }, text.unavailable)])]))
388
593
  ]);
389
594
  };
390
595
  }
391
596
  });
392
- 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 };
597
+ export { ASSET_FILE_ICON_SIZE, ASSET_VIEWERS, AssetSession, AssetViewerMount, CALMLENS_STYLES, CALMLENS_THEME, CalmLensAsset, CalmLensDocumentViewer, CalmLensImageViewer, CalmLensSpreadsheetViewer, CalmLensTextViewer, CalmLensUploader, CalmLensWebsiteViewer, DEFAULT_MESSAGES, DEFAULT_VIEWER_MESSAGES, ICONS, ICON_ATTRIBUTES, MediaStreamPlayer, UploadController, VIEWER_STYLES, createDocumentViewer, createImageViewer, createProgressFetch, createSpreadsheetViewer, createTextViewer, createUploadController, createWebsiteViewer, 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, useCalmLensUpload };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "calmlens",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "Official CalmLens SDK for JavaScript and TypeScript: content moderation, asset storage and CDN delivery.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://calmlens.com/docs/sdk/javascript",
@@ -62,6 +62,7 @@
62
62
  "@types/bun": "^1.4.4",
63
63
  "@types/node": "26.6.5",
64
64
  "@types/react": "19.3.0",
65
+ "json-schema-to-ts": "^3.1.1",
65
66
  "react-native": "0.86.3",
66
67
  "rimraf": "6.1.3",
67
68
  "rolldown": "1.2.15",
@@ -71,7 +72,8 @@
71
72
  "vue": "3.5.44"
72
73
  },
73
74
  "dependencies": {
74
- "json-schema-to-ts": "^3.1.1",
75
+ "hls.js": "1.7.3",
76
+ "pdfjs-dist": "6.4.299",
75
77
  "zod": "^4.6.7"
76
78
  },
77
79
  "exports": {