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/react.d.ts CHANGED
@@ -1,6 +1,28 @@
1
- import { A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as getUploadItemOutcome, E as getUploadItemMessage, F as UploadFile, G as MediaSource, H as MediaImageSource, J as pickMediaSource, K as MediaState, M as UploadClient, N as UploadController, O as resolveMessages, R as UploadStage, S as formatBytes, T as getMediaUnavailableMessage, U as MediaOptions, V as MediaAsset, W as MediaSettings, Y as resolveMediaProps, _ as DEFAULT_MESSAGES, a as ProgressFetchOptions, b as describeUploadItem, c as ICON_ATTRIBUTES, d as MediaProps, f as UploaderDisplayOptions, g as CalmLensMessages, h as getMediaLoadKey, i as CALMLENS_STYLES, j as CustomUploadResult, l as IconName, m as getMediaAspectRatio, n as CalmLensTheme, o as createProgressFetch, q as getMediaState, r as resolveTheme, s as ICONS, t as CALMLENS_THEME, u as MediaDisplayOptions, v as UploadItemView, w as getDropzoneHint, x as describeUploader, y as UploaderView } from "./ui-BSqPGKrZ.js";
2
- import { a as UploaderProps, i as UploadSnapshot, n as UploadControllerOptions, o as UseCalmLensUploadResult, r as UploadItem, s as createUploadController, t as CalmLensUpload } from "./BrowserUpload-C07aL9Vq.js";
3
- import { CSSProperties, HTMLAttributes } from "react";
1
+ import { $ as getAssetViewKey, A as CustomUploadResult, B as AssetDisplay, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, G as AssetSession, H as AssetImageOptions, J as AssetVideoOptions, K as AssetSessionState, L as UploadStage, M as UploadController, P as UploadFile, Q as getAssetView, S as formatBytes, T as getUploadItemMessage, U as AssetImageSource, V as AssetDocumentOptions, W as AssetOptions, X as MediaPlayback, Y as AssetView, Z as getAssetAspectRatio, _ as DEFAULT_MESSAGES, _t as formatViewerMessage, a as ProgressFetchOptions, at as ImageViewerOptions, b as describeUploadItem, c as ICON_ATTRIBUTES, ct as TextViewerOptions, d as AssetDisplayOptions, dt as ViewerTextOptions, et as getPeakHeights, f as AssetEventHandlers, ft as WebsiteViewerOptions, g as CalmLensMessages, gt as ViewerMessages, ht as DEFAULT_VIEWER_MESSAGES, i as CALMLENS_STYLES, it as DocumentViewerOptions, j as UploadClient, k as CustomUploadContext, l as IconName, lt as ViewerAsset, m as UploaderDisplayOptions, mt as isSpreadsheetFormat, n as CalmLensTheme, nt as pickAssetSource, o as createProgressFetch, ot as PdfAssetOptions, p as AssetProps, pt as getAssetViewerKind, q as AssetSpreadsheetOptions, r as resolveTheme, rt as AssetViewerKind, s as ICONS, st as SpreadsheetViewerOptions, t as CALMLENS_THEME, tt as getPlayedPercent, u as ASSET_FILE_ICON_SIZE, ut as ViewerOptions, v as UploadItemView, vt as resolveViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, z as isFileAccepted } from "./Core-C33pkBmf.js";
2
+ import { a as UploaderProps, i as UploadSnapshot, n as UploadControllerOptions, o as UseCalmLensUploadResult, r as UploadItem, s as createUploadController, t as CalmLensUpload } from "./BrowserUpload-BWjZ9ntu.js";
3
+ import { C as ViewerState, S as AssetViewer, _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as createWebsiteViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as createDocumentViewer, y as createImageViewer } from "./ui-YQuvbidU.js";
4
+ import { CSSProperties, HTMLAttributes, ReactNode } from "react";
5
+ type ElementProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
6
+ /** Leaves out the stylesheet the viewers render, so you can style the `calmlens-*` classes. */
7
+ unstyled?: boolean;
8
+ className?: string;
9
+ style?: CSSProperties;
10
+ };
11
+ export type CalmLensImageViewerProps = ImageViewerOptions & ElementProps;
12
+ export type CalmLensWebsiteViewerProps = WebsiteViewerOptions & ElementProps;
13
+ export type CalmLensTextViewerProps = TextViewerOptions & ElementProps;
14
+ export type CalmLensDocumentViewerProps = DocumentViewerOptions & ElementProps;
15
+ export type CalmLensSpreadsheetViewerProps = SpreadsheetViewerOptions & ElementProps;
16
+ /** Shows an image asset's rendered file, fitted to the element, over its placeholder. */
17
+ export declare function CalmLensImageViewer(props: CalmLensImageViewerProps): import("react").JSX.Element;
18
+ /** Shows a website asset's screenshot with a link to the original page. */
19
+ export declare function CalmLensWebsiteViewer(props: CalmLensWebsiteViewerProps): import("react").JSX.Element;
20
+ /** Shows a text asset's text, escaped, in a scrolling region. */
21
+ export declare function CalmLensTextViewer(props: CalmLensTextViewerProps): import("react").JSX.Element;
22
+ /** Shows a PDF, or a document rendered as one, a page at a time with pdf.js (loaded lazily). */
23
+ export declare function CalmLensDocumentViewer(props: CalmLensDocumentViewerProps): import("react").JSX.Element;
24
+ /** Shows a spreadsheet's sheets as tabs and paged tables, from its extracted text. */
25
+ export declare function CalmLensSpreadsheetViewer(props: CalmLensSpreadsheetViewerProps): import("react").JSX.Element;
4
26
  /**
5
27
  * Uploads files through an upload preset and re-renders as each one uploads and is checked. Use
6
28
  * it to build your own upload UI; `CalmLensUploader` is built on it. Uploads still running when
@@ -20,11 +42,22 @@ export type CalmLensUploaderProps = UploaderProps & StyleOptions & {
20
42
  * and moderation decision, and reports finished uploads to `onUploaded`.
21
43
  */
22
44
  export declare function CalmLensUploader({ disabled, capture, messages: overrides, unstyled, controller: external, className, style, ...options }: CalmLensUploaderProps): import("react").JSX.Element;
23
- export type CalmLensMediaProps = MediaProps & StyleOptions & Omit<HTMLAttributes<HTMLElement>, "children" | "placeholder">;
45
+ export type CalmLensAssetProps = AssetProps & StyleOptions & Omit<HTMLAttributes<HTMLElement>, "children" | "placeholder" | "onLoad" | "onError" | "onPlay" | "onEnded" | "onTimeUpdate"> & {
46
+ /** Replaces the unavailable notice. */
47
+ renderUnavailable?: () => ReactNode;
48
+ /** Replaces the age notice; call `confirm` from your own reveal button. */
49
+ renderAgeGate?: (props: {
50
+ placeholderUrl?: string;
51
+ confirm?: () => void;
52
+ }) => ReactNode;
53
+ };
24
54
  /**
25
- * Shows an asset from the CalmLens CDN with responsive widths and a blurred placeholder while
26
- * it loads. Age-restricted assets stay behind the placeholder and a reveal button until
27
- * `ageConfirmed` is set; blocked and purged assets show an unavailable notice.
55
+ * Shows any asset from its asset URL (public, or signed by your server), natively in the page: an
56
+ * image with responsive widths, a website's screenshot and link, video and audio with their
57
+ * adaptive stream, a document, text or spreadsheet viewer, or a preview still or file icon. It
58
+ * reads `{src}/info` once mounted, unless `info` is given, in which case the first render, on the
59
+ * server too, is the real element. Age-restricted content stays behind its blurred placeholder
60
+ * and a reveal button; content the CDN refuses shows the unavailable notice.
28
61
  */
29
- export declare function CalmLensMedia(input: CalmLensMediaProps): import("react").JSX.Element;
30
- 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 ProgressFetchOptions, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, type UseCalmLensUploadResult, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme };
62
+ export declare function CalmLensAsset(props: CalmLensAssetProps): import("react").JSX.Element;
63
+ export { ASSET_FILE_ICON_SIZE, ASSET_VIEWERS, type AssetDisplay, type AssetDisplayOptions, type AssetDocumentOptions, type AssetEventHandlers, type AssetImageOptions, type AssetImageSource, type AssetOptions, type AssetProps, AssetSession, type AssetSessionState, type AssetSpreadsheetOptions, type AssetVideoOptions, type AssetView, type AssetViewer, type AssetViewerKind, AssetViewerMount, AssetViewerName, AssetViewerOptionsByKind, CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, DEFAULT_VIEWER_MESSAGES, type DocumentViewerOptions, ICONS, ICON_ATTRIBUTES, type IconName, type ImageViewerOptions, type MediaPlayback, MediaStreamPlayer, type MountedViewerKind, type PdfAssetOptions, type ProgressFetchOptions, type SpreadsheetCell, type SpreadsheetRow, type SpreadsheetSheet, type SpreadsheetViewerOptions, type TextViewerOptions, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, type UseCalmLensUploadResult, VIEWER_STYLES, type ViewerAsset, type ViewerMessages, type ViewerOptions, type ViewerState, type ViewerTextOptions, type WebsiteViewerOptions, 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 };
package/esm/react.js CHANGED
@@ -1,10 +1,101 @@
1
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-CXH7xJpb.js";
3
- import { i as createProgressFetch, r as isFileAccepted, t as UploadController } from "./UploadController-BJZghJpg.js";
4
- import { n as useOwnController, r as useUploadSnapshot, t as useCalmLensUpload$1 } from "./ReactUpload-CMmL0R5Q.js";
5
- import { t as createUploadController } from "./BrowserUpload-CAVkRotw.js";
2
+ 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";
3
+ import { i as createProgressFetch, r as isFileAccepted, t as UploadController } from "./UploadController-DnJrWiE4.js";
4
+ 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, n as CALMLENS_STYLES_ID, 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";
5
+ import { c as renderFileIconSvg } from "./FileIcons-M6dzjFxd.js";
6
+ import { n as useOwnController, r as useUploadSnapshot, t as useCalmLensUpload$1 } from "./ReactUpload-BMO8saxT.js";
7
+ import { t as createUploadController } from "./BrowserUpload-GRZVB0G_.js";
6
8
  import { useEffect, useMemo, useRef, useState } from "react";
7
- import { jsx, jsxs } from "react/jsx-runtime";
9
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ const OPTION_NAMES = /* @__PURE__ */ new Set([
11
+ "src",
12
+ "asset",
13
+ "onExpired",
14
+ "onUnavailable",
15
+ "viewerClaims",
16
+ "label",
17
+ "messages",
18
+ "sizes",
19
+ "text",
20
+ "getText",
21
+ "pageSize",
22
+ "pdf",
23
+ "initialPage"
24
+ ]);
25
+ /** Splits a binding's props into the viewer's options and the element's own attributes. */
26
+ const splitViewerProps = (props) => {
27
+ const options = {};
28
+ const rest = {};
29
+ for (const [name, value] of Object.entries(props)) (OPTION_NAMES.has(name) ? options : rest)[name] = value;
30
+ return {
31
+ options,
32
+ rest
33
+ };
34
+ };
35
+ // src/viewers/React.tsx
36
+ /** Mounts a viewer into the element after it renders, and shows each render's options. */
37
+ function Viewer({ kind, props }) {
38
+ const { options, rest } = splitViewerProps(props);
39
+ const { unstyled, className, ...attributes } = rest;
40
+ const root = useRef(null);
41
+ const viewer = useRef(void 0);
42
+ const latest = useRef(options);
43
+ latest.current = options;
44
+ useEffect(() => {
45
+ const mounted = ASSET_VIEWERS[kind](root.current, latest.current);
46
+ viewer.current = mounted;
47
+ return () => {
48
+ mounted.destroy();
49
+ viewer.current = void 0;
50
+ };
51
+ }, [kind]);
52
+ useEffect(() => viewer.current?.update(options));
53
+ return /* @__PURE__ */ jsxs(Fragment, { children: [unstyled ? null : /* @__PURE__ */ jsx("style", {
54
+ href: CALMLENS_STYLES_ID,
55
+ precedence: "calmlens",
56
+ children: CALMLENS_STYLES
57
+ }), /* @__PURE__ */ jsx("div", {
58
+ ...attributes,
59
+ ref: root,
60
+ className: className ? `calmlens-viewer ${className}` : "calmlens-viewer",
61
+ "data-kind": kind
62
+ })] });
63
+ }
64
+ /** Shows an image asset's rendered file, fitted to the element, over its placeholder. */
65
+ function CalmLensImageViewer(props) {
66
+ return /* @__PURE__ */ jsx(Viewer, {
67
+ kind: "image",
68
+ props
69
+ });
70
+ }
71
+ /** Shows a website asset's screenshot with a link to the original page. */
72
+ function CalmLensWebsiteViewer(props) {
73
+ return /* @__PURE__ */ jsx(Viewer, {
74
+ kind: "website",
75
+ props
76
+ });
77
+ }
78
+ /** Shows a text asset's text, escaped, in a scrolling region. */
79
+ function CalmLensTextViewer(props) {
80
+ return /* @__PURE__ */ jsx(Viewer, {
81
+ kind: "text",
82
+ props
83
+ });
84
+ }
85
+ /** Shows a PDF, or a document rendered as one, a page at a time with pdf.js (loaded lazily). */
86
+ function CalmLensDocumentViewer(props) {
87
+ return /* @__PURE__ */ jsx(Viewer, {
88
+ kind: "document",
89
+ props
90
+ });
91
+ }
92
+ /** Shows a spreadsheet's sheets as tabs and paged tables, from its extracted text. */
93
+ function CalmLensSpreadsheetViewer(props) {
94
+ return /* @__PURE__ */ jsx(Viewer, {
95
+ kind: "spreadsheet",
96
+ props
97
+ });
98
+ }
8
99
  // src/react.tsx
9
100
  /**
10
101
  * Uploads files through an upload preset and re-renders as each one uploads and is checked. Use
@@ -202,33 +293,73 @@ function CalmLensUploader({ disabled, capture, messages: overrides, unstyled, co
202
293
  ]
203
294
  });
204
295
  }
296
+ /** Audio's waveform: the preview still, with the played part of its peaks drawn over it. */
297
+ const Waveform = ({ url, peaks, played }) => {
298
+ if (!url && !peaks) return null;
299
+ const bars = (peaks ? getPeakHeights(peaks) : []).map((height, index) => /* @__PURE__ */ jsx("span", { style: { height: `${height}%` } }, index));
300
+ return /* @__PURE__ */ jsxs("div", {
301
+ className: "calmlens-asset__waveform",
302
+ children: [url && /* @__PURE__ */ jsx("img", {
303
+ className: "calmlens-asset__wave",
304
+ src: url,
305
+ alt: "",
306
+ "aria-hidden": "true"
307
+ }), peaks && /* @__PURE__ */ jsxs("div", {
308
+ className: "calmlens-asset__progress",
309
+ role: "progressbar",
310
+ "aria-hidden": "true",
311
+ "aria-valuemin": 0,
312
+ "aria-valuemax": 100,
313
+ "aria-valuenow": played,
314
+ style: { "--calmlens-played": `${played}%` },
315
+ children: [/* @__PURE__ */ jsx("div", {
316
+ className: "calmlens-asset__peaks",
317
+ children: bars
318
+ }), /* @__PURE__ */ jsx("div", {
319
+ className: "calmlens-asset__peaks",
320
+ "data-played": "",
321
+ children: bars
322
+ })]
323
+ })]
324
+ });
325
+ };
205
326
  /**
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.
327
+ * Shows any asset from its asset URL (public, or signed by your server), natively in the page: an
328
+ * image with responsive widths, a website's screenshot and link, video and audio with their
329
+ * adaptive stream, a document, text or spreadsheet viewer, or a preview still or file icon. It
330
+ * reads `{src}/info` once mounted, unless `info` is given, in which case the first render, on the
331
+ * server too, is the real element. Age-restricted content stays behind its blurred placeholder
332
+ * and a reveal button; content the CDN refuses shows the unavailable notice.
209
333
  */
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);
334
+ function CalmLensAsset(props) {
335
+ const { src, display, viewerClaims, info, image, video, document: documentOptions, spreadsheet, onExpired, alt = "", fit, aspectRatio, lazy = true, fetchPriority, messages: overrides, onLoad, onError, onAvailabilityChange, onAgeConfirmRequest, onPlay, onEnded, onTimeUpdate, renderUnavailable, renderAgeGate, unstyled, className, style, ...attributes } = props;
336
+ const options = {
337
+ src,
338
+ display,
339
+ viewerClaims,
340
+ info,
341
+ image,
342
+ video,
343
+ document: documentOptions,
344
+ spreadsheet,
345
+ onExpired,
346
+ alt
347
+ };
212
348
  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);
349
+ const [, setVersion] = useState(0);
350
+ const [session] = useState(() => new AssetSession(() => setVersion((count) => count + 1)));
351
+ const [streams] = useState(() => new MediaStreamPlayer((media) => {
352
+ session.mediaFailed({
353
+ position: media.currentTime || 0,
354
+ playing: !media.paused && !media.ended
355
+ });
356
+ return true;
357
+ }));
358
+ const [viewers] = useState(() => new AssetViewerMount());
359
+ const [mounted, setMounted] = useState(false);
360
+ const state = session.update(options);
361
+ const view = getAssetView(options, state);
362
+ const loadKey = getAssetViewKey(view);
232
363
  const [load, setLoad] = useState({
233
364
  key: loadKey,
234
365
  state: "loading"
@@ -237,107 +368,212 @@ function CalmLensMedia(input) {
237
368
  key: loadKey,
238
369
  state: "loading"
239
370
  };
240
- const image = useRef(null);
371
+ const [played, setPlayed] = useState(0);
372
+ const imageRef = useRef(null);
373
+ const media = useRef(null);
374
+ const viewerRoot = useRef(null);
375
+ const callbacks = useRef({
376
+ onLoad,
377
+ onError,
378
+ onAvailabilityChange
379
+ });
380
+ callbacks.current = {
381
+ onLoad,
382
+ onError,
383
+ onAvailabilityChange
384
+ };
385
+ useEffect(() => setMounted(true), []);
386
+ useEffect(() => session.load());
241
387
  useEffect(() => {
242
- if (image.current?.complete && image.current.naturalWidth > 0) setLoad({
388
+ if (imageRef.current?.complete && imageRef.current.naturalWidth > 0) setLoad({
243
389
  key: loadKey,
244
390
  state: "loaded"
245
391
  });
246
392
  }, [loadKey]);
247
- const ratio = getMediaAspectRatio({
248
- aspectRatio,
249
- width,
250
- height
393
+ useEffect(() => {
394
+ if (current.state === "loaded") callbacks.current.onLoad?.();
395
+ if (current.state === "error") callbacks.current.onError?.();
396
+ }, [current.state]);
397
+ const availability = view.kind === "unavailable" ? "unavailable" : view.kind === "age-restricted" ? "age-restricted" : view.kind === "pending" ? void 0 : "available";
398
+ useEffect(() => {
399
+ if (availability) callbacks.current.onAvailabilityChange?.(availability);
400
+ }, [availability]);
401
+ const viewerKind = isMountedViewerKind(view.kind) && mounted ? view.kind : void 0;
402
+ useEffect(() => {
403
+ viewers.update(viewerRoot.current, viewerKind, getMountedViewerOptions(options, session), (viewerState) => {
404
+ if (viewerState !== "loading") setLoad({
405
+ key: loadKey,
406
+ state: viewerState
407
+ });
408
+ });
251
409
  });
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");
410
+ useEffect(() => () => viewers.destroy(), [viewers]);
411
+ useEffect(() => streams.update(media.current, view));
412
+ useEffect(() => () => streams.stop(), [streams]);
413
+ const ratio = getAssetAspectRatio(view, state.info, aspectRatio);
414
+ const placeholderUrl = "placeholderUrl" in view && (view.kind === "age-restricted" || view.kind === "pending" || current.state !== "loaded") ? view.placeholderUrl : void 0;
415
+ const onMediaError = (element) => {
416
+ if (streams.recover(element)) return;
417
+ session.mediaFailed({
418
+ position: element.currentTime || 0,
419
+ playing: !element.paused && !element.ended
420
+ });
421
+ };
422
+ const playerEvents = {
423
+ onLoadedMetadata: (event) => {
424
+ session.mediaLoaded(event.currentTarget);
425
+ setLoad({
426
+ key: loadKey,
427
+ state: "loaded"
428
+ });
429
+ },
430
+ onError: (event) => onMediaError(event.currentTarget),
431
+ onPlay,
432
+ onEnded,
433
+ onTimeUpdate: (event) => {
434
+ setPlayed(getPlayedPercent(event.currentTarget));
435
+ onTimeUpdate?.(event.currentTarget.currentTime);
436
+ }
437
+ };
438
+ const confirm = onAgeConfirmRequest;
439
+ const imageElement = (shown) => /* @__PURE__ */ jsx("img", {
440
+ ref: imageRef,
441
+ className: "calmlens-asset__content",
442
+ src: shown.src,
443
+ srcSet: shown.srcSet,
444
+ sizes: shown.srcSet ? image?.sizes : void 0,
445
+ alt,
446
+ width: shown.width,
447
+ height: shown.height,
448
+ loading: lazy ? "lazy" : void 0,
449
+ decoding: "async",
450
+ fetchPriority,
451
+ onLoad: () => {
452
+ session.loaded();
453
+ setLoad({
454
+ key: loadKey,
455
+ state: "loaded"
456
+ });
457
+ },
458
+ onError: () => session.failed()
459
+ }, loadKey);
255
460
  return /* @__PURE__ */ jsxs("figure", {
256
461
  ...attributes,
257
- className: joinClassNames("calmlens-media", className),
258
- "data-kind": state.kind,
462
+ className: joinClassNames("calmlens-asset", className),
463
+ "data-kind": view.kind,
259
464
  "data-state": current.state,
260
465
  "data-sized": ratio ? "" : void 0,
466
+ "aria-busy": view.kind === "pending" ? true : void 0,
261
467
  style: {
262
468
  aspectRatio: ratio,
263
- backgroundColor: averageColor,
469
+ backgroundColor: state.info?.content?.preview?.averageColor ?? void 0,
264
470
  "--calmlens-fit": fit,
265
- "--calmlens-position": position,
266
471
  ...style
267
472
  },
268
473
  children: [
269
474
  /* @__PURE__ */ jsx(CalmLensStyles, { unstyled }),
270
- showPlaceholder && /* @__PURE__ */ jsx("img", {
271
- className: "calmlens-media__placeholder",
475
+ placeholderUrl && /* @__PURE__ */ jsx("img", {
476
+ className: "calmlens-asset__placeholder",
272
477
  src: placeholderUrl,
273
478
  alt: "",
274
479
  "aria-hidden": "true"
275
480
  }),
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"
481
+ view.kind === "image" && imageElement(view),
482
+ view.kind === "website" && /* @__PURE__ */ jsxs(Fragment, { children: [view.link && /* @__PURE__ */ jsx("div", {
483
+ className: "calmlens-asset__bar",
484
+ children: /* @__PURE__ */ jsx("a", {
485
+ className: "calmlens-button",
486
+ href: view.link,
487
+ target: "_blank",
488
+ rel: "noopener noreferrer nofollow",
489
+ children: formatMessage(messages.openWebsite, { host: new URL(view.link).host })
295
490
  })
296
- }, loadKey),
297
- state.kind === "video" && current.state !== "error" && /* @__PURE__ */ jsx("video", {
298
- className: "calmlens-media__content",
299
- src: state.src,
300
- controls,
491
+ }), /* @__PURE__ */ jsx("section", {
492
+ className: "calmlens-asset__scroll",
493
+ "aria-label": alt || void 0,
494
+ tabIndex: 0,
495
+ children: imageElement(view)
496
+ })] }),
497
+ view.kind === "video" && /* @__PURE__ */ jsx("video", {
498
+ ref: media,
499
+ className: "calmlens-asset__content",
500
+ src: view.stream ? void 0 : view.src,
501
+ poster: view.poster,
502
+ controls: video?.controls ?? true,
503
+ autoPlay: video?.autoPlay,
504
+ muted: video?.muted,
505
+ loop: video?.loop,
301
506
  playsInline: true,
302
507
  preload: "metadata",
303
508
  "aria-label": alt || void 0,
304
- onError: () => setLoad({
305
- key: loadKey,
306
- state: "error"
307
- })
509
+ ...playerEvents
308
510
  }),
309
- state.kind === "audio" && current.state !== "error" && /* @__PURE__ */ jsx("audio", {
310
- className: "calmlens-media__content",
311
- src: state.src,
312
- controls,
511
+ view.kind === "audio" && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Waveform, {
512
+ url: view.waveformUrl,
513
+ peaks: view.peaks,
514
+ played
515
+ }), /* @__PURE__ */ jsx("audio", {
516
+ ref: media,
517
+ className: "calmlens-asset__content",
518
+ src: view.stream ? void 0 : view.src,
519
+ controls: video?.controls ?? true,
520
+ autoPlay: video?.autoPlay,
521
+ muted: video?.muted,
522
+ loop: video?.loop,
313
523
  preload: "metadata",
314
524
  "aria-label": alt || void 0,
315
- onError: () => setLoad({
316
- key: loadKey,
317
- state: "error"
318
- })
525
+ ...playerEvents
526
+ })] }),
527
+ view.kind === "document" && !viewerKind && /* @__PURE__ */ jsxs(Fragment, { children: [view.still && /* @__PURE__ */ jsx("img", {
528
+ className: "calmlens-asset__content",
529
+ src: view.still,
530
+ alt,
531
+ decoding: "async"
532
+ }), /* @__PURE__ */ jsx("a", {
533
+ className: "calmlens-button calmlens-asset__open",
534
+ href: view.src,
535
+ target: "_blank",
536
+ rel: "noopener noreferrer",
537
+ children: messages.openDocument
538
+ })] }),
539
+ viewerKind && /* @__PURE__ */ jsx("div", {
540
+ ref: viewerRoot,
541
+ className: "calmlens-asset__viewer"
542
+ }),
543
+ view.kind === "file" && /* @__PURE__ */ jsx("span", {
544
+ className: "calmlens-asset__file",
545
+ role: "img",
546
+ "aria-label": alt || void 0,
547
+ "aria-hidden": alt ? void 0 : "true",
548
+ dangerouslySetInnerHTML: { __html: renderFileIconSvg({
549
+ family: view.icon,
550
+ extension: ""
551
+ }, 64) }
319
552
  }),
320
- state.kind === "gated" && /* @__PURE__ */ jsxs("figcaption", {
321
- className: "calmlens-media__notice",
553
+ view.kind === "age-restricted" && (renderAgeGate ? renderAgeGate({
554
+ placeholderUrl: view.placeholderUrl,
555
+ confirm
556
+ }) : /* @__PURE__ */ jsxs("figcaption", {
557
+ className: "calmlens-asset__notice",
322
558
  children: [
323
559
  /* @__PURE__ */ jsx("strong", { children: messages.sensitiveTitle }),
324
560
  /* @__PURE__ */ jsx("p", { children: messages.sensitiveBody }),
325
- onReveal && /* @__PURE__ */ jsx("button", {
561
+ confirm && /* @__PURE__ */ jsx("button", {
326
562
  type: "button",
327
563
  className: "calmlens-button",
328
- onClick: onReveal,
564
+ onClick: confirm,
329
565
  children: messages.reveal
330
566
  })
331
567
  ]
332
- }),
333
- kind === "unavailable" && /* @__PURE__ */ jsx("figcaption", {
334
- className: "calmlens-media__notice",
568
+ })),
569
+ view.kind === "unavailable" && (renderUnavailable ? renderUnavailable() : /* @__PURE__ */ jsx("figcaption", {
570
+ className: "calmlens-asset__notice",
335
571
  children: /* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx(Icon, { name: "unavailable" }), /* @__PURE__ */ jsx("span", {
336
- className: "calmlens-media__label",
337
- children: getMediaUnavailableMessage(state, messages)
572
+ className: "calmlens-asset__label",
573
+ children: messages.unavailable
338
574
  })] })
339
- })
575
+ }))
340
576
  ]
341
577
  });
342
578
  }
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 };
579
+ 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 };