calmlens 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -9
- package/bin/calmlens.js +1646 -706
- package/cjs/{BrowserUpload-CJ4Xc9bR.js → BrowserUpload-CeSwiMo5.js} +1 -1
- package/{esm/BrowserUpload-RkxV_Vv7.d.ts → cjs/BrowserUpload-D-NnAN7g.d.ts} +2 -2
- package/cjs/{CalmLensAppClient-LHMEQ-UZ.js → CalmLensAppClient-0UVCuNqW.js} +30 -10
- package/cjs/{CalmLensAppClient-B5gfOB6J.d.ts → CalmLensAppClient-gG16T2py.d.ts} +13 -3
- package/cjs/{CalmLensOptionKeys-BUj7v5AG.js → CalmLensOptionKeys-CYY6elxg.js} +242 -345
- package/cjs/{CalmLensServerClient-DCSbwIBs.d.ts → CalmLensServerClient-BHx3x_nZ.d.ts} +107 -49
- package/cjs/{CalmLensServerClient-BVOEUT_v.js → CalmLensServerClient-nfu6_YEW.js} +297 -92
- package/cjs/{CalmLensTypes-DpU-hXq2.d.ts → CalmLensTypes-CUB0YYVz.d.ts} +26601 -27354
- package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/cjs/Core-C82YmjjX.d.ts +823 -0
- package/cjs/Core-Dc3cteU7.js +998 -0
- package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
- package/cjs/{ModerationContextLimits-FDpQmw_T.js → ModerationContextLimits-BxOmeSqq.js} +970 -278
- package/cjs/{ReactUpload-BvpW4hJi.js → ReactUpload-BK2O3dnK.js} +1 -1
- package/cjs/{ReactUpload-huIMnOJ4.d.ts → ReactUpload-DiiXfKvj.d.ts} +1 -1
- package/cjs/{TestTriggers-CMwMrbjy-K0YBzu2a.js → TestTriggers-BTyXtX0Q-ATuFDhLX.js} +343 -35
- package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/cjs/{UploadController-D4qOZZc3.js → UploadController-DLyiLDTB.js} +34 -14
- package/cjs/{WebhookPayload-CQg8BBZQ.d.ts → WebhookPayload-BLT2y_Jy.d.ts} +93 -86
- package/cjs/app.d.ts +6 -7
- package/cjs/app.js +4 -3
- package/cjs/elements.d.ts +123 -22
- package/cjs/elements.js +553 -156
- package/cjs/file-icons.d.ts +2 -67
- package/cjs/index-CKRgjV16.d.ts +16 -0
- package/cjs/index.d.ts +5 -6
- package/cjs/index.js +3 -2
- package/cjs/react-native.d.ts +52 -11
- package/cjs/react-native.js +231 -99
- package/cjs/react.d.ts +42 -9
- package/cjs/react.js +381 -118
- package/cjs/server.d.ts +48 -7
- package/cjs/server.js +7 -3
- package/cjs/test-inputs.d.ts +2 -2
- package/cjs/test-inputs.js +13 -9
- package/cjs/testing.d.ts +29 -16
- package/cjs/testing.js +1511 -397
- package/cjs/ui-CTBUxnVp.d.ts +139 -0
- package/cjs/ui-CZ8exACq.js +1359 -0
- package/cjs/ui.d.ts +3 -2
- package/cjs/ui.js +45 -22
- package/cjs/vue.d.ts +802 -199
- package/cjs/vue.js +359 -127
- package/{cjs/BrowserUpload-RkxV_Vv7.d.ts → esm/BrowserUpload-D-NnAN7g.d.ts} +2 -2
- package/esm/{BrowserUpload-DpzS2bbj.js → BrowserUpload-i9OhCzMJ.js} +1 -1
- package/esm/{CalmLensAppClient-BjlvBweS.js → CalmLensAppClient-CK4_Py0c.js} +30 -10
- package/esm/{CalmLensAppClient-B5gfOB6J.d.ts → CalmLensAppClient-gG16T2py.d.ts} +13 -3
- package/esm/{CalmLensOptionKeys-BKez0Wiw.js → CalmLensOptionKeys-BGZlIsT2.js} +235 -338
- package/esm/{CalmLensServerClient-DCSbwIBs.d.ts → CalmLensServerClient-BHx3x_nZ.d.ts} +107 -49
- package/esm/{CalmLensServerClient-DemxbNMn.js → CalmLensServerClient-dAQUcDWb.js} +274 -93
- package/esm/{CalmLensTypes-DpU-hXq2.d.ts → CalmLensTypes-CUB0YYVz.d.ts} +26601 -27354
- package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/esm/Core-BxeIud_S.js +843 -0
- package/esm/Core-C82YmjjX.d.ts +823 -0
- package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
- package/esm/{ModerationContextLimits-lLfmyLni.js → ModerationContextLimits-B6_RalCQ.js} +911 -261
- package/esm/{ReactUpload-huIMnOJ4.d.ts → ReactUpload-DiiXfKvj.d.ts} +1 -1
- package/esm/{ReactUpload-6klucehl.js → ReactUpload-DxwVqfX1.js} +1 -1
- package/esm/{TestTriggers-CMwMrbjy-bdowBBKw.js → TestTriggers-BTyXtX0Q-GRB9jQwo.js} +320 -36
- package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/esm/{UploadController-UxP6gj7A.js → UploadController-D9Z-h00Q.js} +34 -14
- package/esm/{WebhookPayload-CQg8BBZQ.d.ts → WebhookPayload-BLT2y_Jy.d.ts} +93 -86
- package/esm/app.d.ts +6 -7
- package/esm/app.js +3 -3
- package/esm/elements.d.ts +123 -22
- package/esm/elements.js +497 -128
- package/esm/file-icons.d.ts +2 -67
- package/esm/index-CKRgjV16.d.ts +16 -0
- package/esm/index.d.ts +5 -6
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +52 -11
- package/esm/react-native.js +205 -75
- package/esm/react.d.ts +42 -9
- package/esm/react.js +327 -91
- package/esm/server.d.ts +48 -7
- package/esm/server.js +3 -3
- package/esm/styles.css +142 -22
- package/esm/svelte/AssetViewer.svelte +25 -0
- package/esm/svelte/CalmLensAsset.svelte +318 -0
- package/esm/svelte/CalmLensDocumentViewer.svelte +7 -0
- package/esm/svelte/CalmLensImageViewer.svelte +7 -0
- package/esm/svelte/CalmLensSpreadsheetViewer.svelte +7 -0
- package/esm/svelte/CalmLensTextViewer.svelte +7 -0
- package/esm/svelte/CalmLensWebsiteViewer.svelte +7 -0
- package/esm/svelte/index.d.ts +29 -6
- package/esm/svelte/index.js +7 -2
- package/esm/test-inputs.d.ts +2 -2
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +29 -16
- package/esm/testing.js +1507 -393
- package/esm/ui-CTBUxnVp.d.ts +139 -0
- package/esm/ui-Cr7s6JHm.js +1258 -0
- package/esm/ui.d.ts +3 -2
- package/esm/ui.js +4 -3
- package/esm/vue.d.ts +802 -199
- package/esm/vue.js +308 -103
- package/package.json +3 -1
- package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/cjs/index-BcDDQJF2.d.ts +0 -253
- package/cjs/ui-B23r8BvW.d.ts +0 -539
- package/cjs/ui-Dq-cm6Rx.js +0 -586
- package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/esm/index-BcDDQJF2.d.ts +0 -253
- package/esm/svelte/CalmLensMedia.svelte +0 -134
- package/esm/ui-B23r8BvW.d.ts +0 -539
- package/esm/ui-Bn29rfAi.js +0 -461
package/esm/react.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
import { A as
|
|
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-
|
|
3
|
-
import {
|
|
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-C82YmjjX.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-D-NnAN7g.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-CTBUxnVp.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
|
|
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
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
|
30
|
-
export { CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, type IconName, type
|
|
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
|
|
3
|
-
import { i as createProgressFetch, r as isFileAccepted, t as UploadController } from "./UploadController-
|
|
4
|
-
import { n as
|
|
5
|
-
import {
|
|
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-Cr7s6JHm.js";
|
|
3
|
+
import { i as createProgressFetch, r as isFileAccepted, t as UploadController } from "./UploadController-D9Z-h00Q.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-BxeIud_S.js";
|
|
5
|
+
import { c as renderFileIconSvg } from "./FileIcons-M6dzjFxd.js";
|
|
6
|
+
import { n as useOwnController, r as useUploadSnapshot, t as useCalmLensUpload$1 } from "./ReactUpload-DxwVqfX1.js";
|
|
7
|
+
import { t as createUploadController } from "./BrowserUpload-i9OhCzMJ.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
|
|
207
|
-
*
|
|
208
|
-
*
|
|
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
|
|
211
|
-
const {
|
|
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
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
|
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 (
|
|
388
|
+
if (imageRef.current?.complete && imageRef.current.naturalWidth > 0) setLoad({
|
|
243
389
|
key: loadKey,
|
|
244
390
|
state: "loaded"
|
|
245
391
|
});
|
|
246
392
|
}, [loadKey]);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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-
|
|
258
|
-
"data-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
|
-
|
|
271
|
-
className: "calmlens-
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
className: "calmlens-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
},
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
305
|
-
key: loadKey,
|
|
306
|
-
state: "error"
|
|
307
|
-
})
|
|
509
|
+
...playerEvents
|
|
308
510
|
}),
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
321
|
-
|
|
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
|
-
|
|
561
|
+
confirm && /* @__PURE__ */ jsx("button", {
|
|
326
562
|
type: "button",
|
|
327
563
|
className: "calmlens-button",
|
|
328
|
-
onClick:
|
|
564
|
+
onClick: confirm,
|
|
329
565
|
children: messages.reveal
|
|
330
566
|
})
|
|
331
567
|
]
|
|
332
|
-
}),
|
|
333
|
-
kind === "unavailable" && /* @__PURE__ */ jsx("figcaption", {
|
|
334
|
-
className: "calmlens-
|
|
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-
|
|
337
|
-
children:
|
|
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,
|
|
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 };
|