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.
- package/README.md +15 -10
- package/bin/calmlens.js +1848 -679
- package/cjs/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/cjs/{BrowserUpload-CjSHjx3C.js → BrowserUpload-Bwlib4Zc.js} +1 -1
- package/cjs/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/cjs/{CalmLensAppClient-NaCxOVlM.js → CalmLensAppClient-DUYMo9PZ.js} +30 -10
- package/cjs/{CalmLensOptionKeys-p2QK687A.js → CalmLensOptionKeys-YvgV995V.js} +318 -374
- package/cjs/{CalmLensServerClient-BDzTthxE.js → CalmLensServerClient-3N-gdsxC.js} +346 -89
- package/cjs/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/cjs/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/cjs/Core-C33pkBmf.d.ts +826 -0
- package/cjs/Core-Cm5Z1oJ9.js +1001 -0
- package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
- package/cjs/{ModerationContextLimits-2nIv7Zh3.js → ModerationContextLimits-ud1xpZRK.js} +727 -268
- package/cjs/{ReactUpload-BdTRCTGA.js → ReactUpload-DQ0BYISX.js} +1 -1
- package/cjs/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/cjs/{TestTriggers-DbhsNPdg-DjvVuc2h.js → TestTriggers-D29T_R0M-D6Bu-Mln.js} +355 -47
- package/cjs/{UploadController-MLVs97Zt.js → UploadController-l8fZM2qT.js} +34 -14
- package/{esm/WebhookPayload-DkukERKE.d.ts → cjs/WebhookPayload-Dt6DttS0.d.ts} +120 -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-Bde1wjiw.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 -15
- package/cjs/testing.js +1722 -433
- package/cjs/ui-BRA4HQ8r.js +1359 -0
- package/cjs/ui-YQuvbidU.d.ts +139 -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/esm/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/esm/{BrowserUpload-CAVkRotw.js → BrowserUpload-GRZVB0G_.js} +1 -1
- package/esm/{CalmLensAppClient-PQ9VBvlW.js → CalmLensAppClient-B5QIJ6KS.js} +30 -10
- package/esm/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/esm/{CalmLensOptionKeys-Do2mPP6w.js → CalmLensOptionKeys-BG7Qrh8-.js} +317 -367
- package/esm/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/esm/{CalmLensServerClient-C_H5aAsV.js → CalmLensServerClient-bRUAebi-.js} +323 -90
- package/esm/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/esm/Core-BvQe4moS.js +846 -0
- package/esm/Core-C33pkBmf.d.ts +826 -0
- package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
- package/esm/{ModerationContextLimits-Chw-AzgL.js → ModerationContextLimits-CrxSnVZ3.js} +682 -253
- package/esm/{ReactUpload-CMmL0R5Q.js → ReactUpload-BMO8saxT.js} +1 -1
- package/esm/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/esm/{TestTriggers-DbhsNPdg-CUdrv8Nm.js → TestTriggers-D29T_R0M-Ztc74ucs.js} +332 -48
- package/esm/{UploadController-BJZghJpg.js → UploadController-DnJrWiE4.js} +34 -14
- package/{cjs/WebhookPayload-DkukERKE.d.ts → esm/WebhookPayload-Dt6DttS0.d.ts} +120 -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-Bde1wjiw.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 -15
- package/esm/testing.js +1718 -429
- package/esm/ui-YQuvbidU.d.ts +139 -0
- package/esm/ui-heryDd6g.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 +4 -2
- package/cjs/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/cjs/index-DxbJ_Xaa.d.ts +0 -253
- package/cjs/ui-BSqPGKrZ.d.ts +0 -539
- package/cjs/ui-CX1z2pD9.js +0 -586
- package/esm/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/esm/index-DxbJ_Xaa.d.ts +0 -253
- package/esm/svelte/CalmLensMedia.svelte +0 -134
- package/esm/ui-BSqPGKrZ.d.ts +0 -539
- package/esm/ui-CXH7xJpb.js +0 -461
|
@@ -0,0 +1,826 @@
|
|
|
1
|
+
import { D as CalmLensAppClientOptions, P as CdnTransform, h as AssetModerationStatus, r as AssetAvailability, sn as ViewerClaims } from "./CalmLensTypes-BDKwThbO.js";
|
|
2
|
+
import { t as CalmLensAppClient } from "./CalmLensAppClient-BaW3ddUR.js";
|
|
3
|
+
import { o as UploadFileIconFamily } from "./FileIcons-4qSX7DW2.js";
|
|
4
|
+
/**
|
|
5
|
+
* The text the asset viewers show, keyed by name. `{name}` placeholders are filled in when shown.
|
|
6
|
+
* Pass some or all of them as `messages` to change or translate them.
|
|
7
|
+
*/
|
|
8
|
+
interface ViewerMessages {
|
|
9
|
+
loading: string;
|
|
10
|
+
/** An image that can't be loaded. */
|
|
11
|
+
imageFailed: string;
|
|
12
|
+
/** The website viewer's link to the original page; `{host}` is the page's host name. */
|
|
13
|
+
openWebsite: string;
|
|
14
|
+
/** The website screenshot's accessible name when no `label` is set. */
|
|
15
|
+
websiteLabel: string;
|
|
16
|
+
textLabel: string;
|
|
17
|
+
textFailed: string;
|
|
18
|
+
documentLabel: string;
|
|
19
|
+
documentControls: string;
|
|
20
|
+
documentFailed: string;
|
|
21
|
+
openDocument: string;
|
|
22
|
+
previousPage: string;
|
|
23
|
+
nextPage: string;
|
|
24
|
+
pageNumber: string;
|
|
25
|
+
/** After the page number field; `{count}` is the number of pages. */
|
|
26
|
+
pageCount: string;
|
|
27
|
+
/** Each page's accessible name, also announced when the page changes. */
|
|
28
|
+
pageStatus: string;
|
|
29
|
+
zoomIn: string;
|
|
30
|
+
zoomOut: string;
|
|
31
|
+
fitWidth: string;
|
|
32
|
+
/** `{percent}` is the zoom level, such as 125. */
|
|
33
|
+
zoomLevel: string;
|
|
34
|
+
spreadsheetLabel: string;
|
|
35
|
+
spreadsheetFailed: string;
|
|
36
|
+
sheets: string;
|
|
37
|
+
/** A hidden sheet's tab; `{name}` is the sheet's name. */
|
|
38
|
+
hiddenSheet: string;
|
|
39
|
+
hidden: string;
|
|
40
|
+
emptySheet: string;
|
|
41
|
+
previousRows: string;
|
|
42
|
+
nextRows: string;
|
|
43
|
+
/** The rows a sheet shows; `{from}`, `{to}` and `{count}` are row positions and the total. */
|
|
44
|
+
rowRange: string;
|
|
45
|
+
/** The sheet's comments and chart titles, below its table. */
|
|
46
|
+
sheetNotes: string;
|
|
47
|
+
}
|
|
48
|
+
declare const DEFAULT_VIEWER_MESSAGES: ViewerMessages;
|
|
49
|
+
/** The default messages with your replacements. */
|
|
50
|
+
declare const resolveViewerMessages: (overrides?: Partial<ViewerMessages>) => ViewerMessages;
|
|
51
|
+
/** Fills a message's `{name}` placeholders. */
|
|
52
|
+
declare const formatViewerMessage: (message: string, values: Record<string, string | number>) => string;
|
|
53
|
+
/** An asset's displayable file, as `content.rendered` describes it. */
|
|
54
|
+
interface ViewerRendered {
|
|
55
|
+
kind: "image" | "video" | "audio" | "pdf";
|
|
56
|
+
format?: string | null;
|
|
57
|
+
width?: number | null;
|
|
58
|
+
height?: number | null;
|
|
59
|
+
/** Audio's waveform peaks, from 0 to 1. */
|
|
60
|
+
peaks?: readonly number[] | null;
|
|
61
|
+
}
|
|
62
|
+
/** An asset's still image, as `content.preview` describes it. */
|
|
63
|
+
interface ViewerPreview {
|
|
64
|
+
width?: number | null;
|
|
65
|
+
height?: number | null;
|
|
66
|
+
thumbhash?: string | null;
|
|
67
|
+
averageColor?: string | null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* What the viewers read of an asset: its display info from the CDN (`/info`, `getAssetInfo`) or
|
|
71
|
+
* the asset as the API returns it, which fits as it is. The extra fields only an API asset has,
|
|
72
|
+
* such as inline extracted text, are used when present.
|
|
73
|
+
*/
|
|
74
|
+
interface ViewerAsset {
|
|
75
|
+
id: string;
|
|
76
|
+
projectId?: string;
|
|
77
|
+
type?: string | null;
|
|
78
|
+
name?: string | null;
|
|
79
|
+
/** A website's page address, linked from the website viewer. */
|
|
80
|
+
externalUrl?: string | null;
|
|
81
|
+
/** Whether this viewer may see the content, as `/info` reports it. */
|
|
82
|
+
availability?: AssetAvailability;
|
|
83
|
+
content?: {
|
|
84
|
+
/** MIME type of the uploaded file, which tells spreadsheets from other documents. */
|
|
85
|
+
format?: string | null;
|
|
86
|
+
width?: number | null;
|
|
87
|
+
height?: number | null;
|
|
88
|
+
durationSeconds?: number | null;
|
|
89
|
+
pageCount?: number | null;
|
|
90
|
+
/** The displayable file the CDN serves at `/rendered`, or `null` when the asset has none. */
|
|
91
|
+
rendered?: ViewerRendered | null;
|
|
92
|
+
/** The still image the CDN serves at `/preview`, or `null` when the asset has none. */
|
|
93
|
+
preview?: ViewerPreview | null;
|
|
94
|
+
/** The adaptive (HLS) stream of video or audio, or `null` until one is prepared. */
|
|
95
|
+
hls?: {
|
|
96
|
+
renditions?: readonly unknown[];
|
|
97
|
+
} | null;
|
|
98
|
+
/** The text extracted from the content, inline when it is small (API assets only). */
|
|
99
|
+
extractedText?: {
|
|
100
|
+
type: "string";
|
|
101
|
+
content: string;
|
|
102
|
+
} | {
|
|
103
|
+
type: "document";
|
|
104
|
+
id: string;
|
|
105
|
+
} | null;
|
|
106
|
+
} | null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Which viewer shows an asset: `image` (the rendered image), `website` (its screenshot and a link
|
|
110
|
+
* to the page), `text` (its text), `document` (a PDF, or a document or presentation rendered as
|
|
111
|
+
* one), `spreadsheet` (its sheets), `media` (video and audio, which `CalmLensAsset` plays) or
|
|
112
|
+
* `none` when there is nothing to show yet.
|
|
113
|
+
*/
|
|
114
|
+
type AssetViewerKind = "image" | "website" | "text" | "document" | "spreadsheet" | "media" | "none";
|
|
115
|
+
/** Whether a MIME type is a spreadsheet's. */
|
|
116
|
+
declare const isSpreadsheetFormat: (format: string | null | undefined) => boolean;
|
|
117
|
+
/** The viewer that shows an asset, from its type and `content.rendered.kind`. */
|
|
118
|
+
declare const getAssetViewerKind: (asset: ViewerAsset) => AssetViewerKind;
|
|
119
|
+
/** The options every asset viewer takes. */
|
|
120
|
+
interface ViewerOptions {
|
|
121
|
+
/**
|
|
122
|
+
* The asset URL, public (`cdn.getAssetUrl`) or signed (`cdn.signAssetUrl`), which the viewer
|
|
123
|
+
* loads resources beneath.
|
|
124
|
+
*/
|
|
125
|
+
src: string;
|
|
126
|
+
/** The asset's display info (`getAssetInfo`), or the asset from the API. */
|
|
127
|
+
asset: ViewerAsset;
|
|
128
|
+
/**
|
|
129
|
+
* Returns a fresh asset URL when the one in use stops working, as a signed URL does once it
|
|
130
|
+
* expires; your server signs it. Without it, an expired URL shows the viewer's failure notice.
|
|
131
|
+
*/
|
|
132
|
+
onExpired?: () => string | Promise<string>;
|
|
133
|
+
/** Called when the CDN refuses the asset to this viewer (`asset/not-available`). */
|
|
134
|
+
onUnavailable?: () => void;
|
|
135
|
+
/** The viewer's region and age confirmation, added to every resource URL. */
|
|
136
|
+
viewerClaims?: ViewerClaims;
|
|
137
|
+
/** The viewer's accessible name, such as the asset's title. Images use it as their `alt`. */
|
|
138
|
+
label?: string;
|
|
139
|
+
/** Replaces some or all of the text the viewer shows. */
|
|
140
|
+
messages?: Partial<ViewerMessages>;
|
|
141
|
+
}
|
|
142
|
+
/** Where the text and spreadsheet viewers read their text. */
|
|
143
|
+
interface ViewerTextOptions {
|
|
144
|
+
/** Text your app already has, shown instead of reading it. */
|
|
145
|
+
text?: string;
|
|
146
|
+
/**
|
|
147
|
+
* Reads the text yourself, such as a large spreadsheet's from its text child asset. Without
|
|
148
|
+
* `text` or `getText`, the viewer shows `content.extractedText` when it is inline, and otherwise
|
|
149
|
+
* reads a text asset's `original` file.
|
|
150
|
+
*/
|
|
151
|
+
getText?: () => Promise<string>;
|
|
152
|
+
}
|
|
153
|
+
interface ImageViewerOptions extends ViewerOptions {
|
|
154
|
+
/** The `sizes` attribute of a public image's responsive widths. Defaults to `100vw`. */
|
|
155
|
+
sizes?: string;
|
|
156
|
+
}
|
|
157
|
+
type WebsiteViewerOptions = ViewerOptions;
|
|
158
|
+
type TextViewerOptions = ViewerOptions & ViewerTextOptions;
|
|
159
|
+
interface SpreadsheetViewerOptions extends ViewerOptions, ViewerTextOptions {
|
|
160
|
+
/** Rows shown at a time. Defaults to 100. */
|
|
161
|
+
pageSize?: number;
|
|
162
|
+
}
|
|
163
|
+
/** Where pdf.js finds the files it loads, for an app that serves them itself. */
|
|
164
|
+
interface PdfAssetOptions {
|
|
165
|
+
/**
|
|
166
|
+
* The URL your app serves pdf.js's worker at (`pdfjs-dist/build/pdf.worker.min.mjs` of the
|
|
167
|
+
* version the SDK depends on), so documents are read off the main thread. Without it, the
|
|
168
|
+
* viewer imports the worker module lazily and reads documents on the main thread.
|
|
169
|
+
*/
|
|
170
|
+
workerSrc?: string;
|
|
171
|
+
/** The URL of pdf.js's `standard_fonts/` folder, for documents that don't embed their fonts. */
|
|
172
|
+
standardFontDataUrl?: string;
|
|
173
|
+
/** The URL of pdf.js's `cmaps/` folder, for documents in CJK and other non-Latin encodings. */
|
|
174
|
+
cMapUrl?: string;
|
|
175
|
+
/** The URL of pdf.js's `wasm/` folder, for JPEG 2000 and JBIG2 images. */
|
|
176
|
+
wasmUrl?: string;
|
|
177
|
+
}
|
|
178
|
+
interface DocumentViewerOptions extends ViewerOptions {
|
|
179
|
+
/** Where pdf.js loads its worker, fonts and decoders from. */
|
|
180
|
+
pdf?: PdfAssetOptions;
|
|
181
|
+
/** The page shown first, from 1. Defaults to 1. */
|
|
182
|
+
initialPage?: number;
|
|
183
|
+
}
|
|
184
|
+
/** `full` shows the asset itself; `preview` shows its still, for grids and lists. */
|
|
185
|
+
type AssetDisplay = "full" | "preview";
|
|
186
|
+
/** How images, preview stills and website screenshots load. */
|
|
187
|
+
interface AssetImageOptions {
|
|
188
|
+
/** A named lens, such as `avatar`. */
|
|
189
|
+
lens?: string;
|
|
190
|
+
/** A transform applied after the lens, as a selector string or structured options. */
|
|
191
|
+
transform?: CdnTransform;
|
|
192
|
+
/** Widths to offer in `srcset`, so browsers fetch the smallest that fits `sizes`. */
|
|
193
|
+
widths?: number[];
|
|
194
|
+
/** The `sizes` attribute for `widths`, such as `(min-width: 768px) 50vw, 100vw`. */
|
|
195
|
+
sizes?: string;
|
|
196
|
+
}
|
|
197
|
+
/** How video and audio play. */
|
|
198
|
+
interface AssetVideoOptions {
|
|
199
|
+
autoPlay?: boolean;
|
|
200
|
+
/** Needed for `autoPlay` in most browsers. */
|
|
201
|
+
muted?: boolean;
|
|
202
|
+
loop?: boolean;
|
|
203
|
+
/** The player's controls. Defaults to `true`. */
|
|
204
|
+
controls?: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Whether to play the adaptive stream when the asset has one; defaults to `true`. It plays
|
|
207
|
+
* natively where the browser plays HLS (Safari and iOS), and otherwise through hls.js, which
|
|
208
|
+
* loads only then; browsers with neither, and a stream that fails, play the rendered file.
|
|
209
|
+
*/
|
|
210
|
+
stream?: boolean;
|
|
211
|
+
}
|
|
212
|
+
/** How documents (PDFs, and documents and presentations rendered as one) show. */
|
|
213
|
+
interface AssetDocumentOptions {
|
|
214
|
+
/** The page shown first, from 1. */
|
|
215
|
+
initialPage?: number;
|
|
216
|
+
/** Where pdf.js loads its worker, fonts and decoders from. */
|
|
217
|
+
pdf?: PdfAssetOptions;
|
|
218
|
+
}
|
|
219
|
+
/** How spreadsheets show. */
|
|
220
|
+
interface AssetSpreadsheetOptions {
|
|
221
|
+
/** Rows shown at a time. Defaults to 100. */
|
|
222
|
+
pageSize?: number;
|
|
223
|
+
/**
|
|
224
|
+
* Reads the sheets' text yourself, such as from the spreadsheet's text child asset. A
|
|
225
|
+
* spreadsheet's sheets are not beneath its own asset URL, so without it the viewer shows its
|
|
226
|
+
* failure notice.
|
|
227
|
+
*/
|
|
228
|
+
getText?: () => Promise<string>;
|
|
229
|
+
}
|
|
230
|
+
/** The options every binding's `CalmLensAsset` reads to decide what it shows. */
|
|
231
|
+
interface AssetOptions {
|
|
232
|
+
/**
|
|
233
|
+
* The asset URL: public (`cdn.getAssetUrl`) or signed (`cdn.signAssetUrl`). Nothing is requested
|
|
234
|
+
* until it is set.
|
|
235
|
+
*/
|
|
236
|
+
src?: string;
|
|
237
|
+
/** Defaults to `full`. */
|
|
238
|
+
display?: AssetDisplay;
|
|
239
|
+
/** The viewer's region and age confirmation, added to every request. */
|
|
240
|
+
viewerClaims?: ViewerClaims;
|
|
241
|
+
/**
|
|
242
|
+
* The asset's display info, prefetched with `getAssetInfo` (on your server, for server
|
|
243
|
+
* rendering). Without it, the component fetches `{src}/info` once mounted.
|
|
244
|
+
*/
|
|
245
|
+
info?: ViewerAsset;
|
|
246
|
+
image?: AssetImageOptions;
|
|
247
|
+
video?: AssetVideoOptions;
|
|
248
|
+
document?: AssetDocumentOptions;
|
|
249
|
+
spreadsheet?: AssetSpreadsheetOptions;
|
|
250
|
+
/**
|
|
251
|
+
* Returns a fresh asset URL once a signed one expires; your server signs it. Without it, an
|
|
252
|
+
* expired URL shows the unavailable notice.
|
|
253
|
+
*/
|
|
254
|
+
onExpired?: () => string | Promise<string>;
|
|
255
|
+
}
|
|
256
|
+
/** An image at one of the widths in `image.widths`. */
|
|
257
|
+
interface AssetImageSource {
|
|
258
|
+
src: string;
|
|
259
|
+
width: number;
|
|
260
|
+
}
|
|
261
|
+
/** What `CalmLensAsset` renders. */
|
|
262
|
+
type AssetView =
|
|
263
|
+
/** No `src` yet, or its info is loading: a box sized from `aspectRatio`. */
|
|
264
|
+
{
|
|
265
|
+
kind: "pending";
|
|
266
|
+
placeholderUrl?: string;
|
|
267
|
+
} | {
|
|
268
|
+
kind: "unavailable";
|
|
269
|
+
} |
|
|
270
|
+
/** Age-restricted for this viewer: the blurred placeholder behind a notice. */
|
|
271
|
+
{
|
|
272
|
+
kind: "age-restricted";
|
|
273
|
+
placeholderUrl?: string;
|
|
274
|
+
} | {
|
|
275
|
+
kind: "image";
|
|
276
|
+
src: string;
|
|
277
|
+
srcSet?: string;
|
|
278
|
+
/** One URL per width, smallest first, for apps that pick their own (React Native). */
|
|
279
|
+
sources?: AssetImageSource[];
|
|
280
|
+
width?: number;
|
|
281
|
+
height?: number;
|
|
282
|
+
placeholderUrl?: string;
|
|
283
|
+
} |
|
|
284
|
+
/** A website's screenshot, with a link to the page when it is an http(s) address. */
|
|
285
|
+
{
|
|
286
|
+
kind: "website";
|
|
287
|
+
src: string;
|
|
288
|
+
srcSet?: string;
|
|
289
|
+
sources?: AssetImageSource[];
|
|
290
|
+
width?: number;
|
|
291
|
+
height?: number;
|
|
292
|
+
placeholderUrl?: string;
|
|
293
|
+
link?: string;
|
|
294
|
+
} |
|
|
295
|
+
/** Video, whose `stream`, when there is one, plays in place of the rendered file `src`. */
|
|
296
|
+
{
|
|
297
|
+
kind: "video";
|
|
298
|
+
src: string;
|
|
299
|
+
stream?: string;
|
|
300
|
+
poster?: string;
|
|
301
|
+
width?: number;
|
|
302
|
+
height?: number;
|
|
303
|
+
placeholderUrl?: string;
|
|
304
|
+
} |
|
|
305
|
+
/** Audio, whose `stream`, when there is one, plays in place of the rendered file `src`. */
|
|
306
|
+
{
|
|
307
|
+
kind: "audio";
|
|
308
|
+
src: string;
|
|
309
|
+
stream?: string;
|
|
310
|
+
waveformUrl?: string;
|
|
311
|
+
peaks?: readonly number[];
|
|
312
|
+
} |
|
|
313
|
+
/**
|
|
314
|
+
* A PDF, or a document rendered as one, shown by the document viewer once it loads; until then,
|
|
315
|
+
* its first page's still (`still`) and a link that opens it (`src`).
|
|
316
|
+
*/
|
|
317
|
+
{
|
|
318
|
+
kind: "document";
|
|
319
|
+
src: string;
|
|
320
|
+
still?: string;
|
|
321
|
+
} |
|
|
322
|
+
/** Text, shown by the text viewer. */
|
|
323
|
+
{
|
|
324
|
+
kind: "text";
|
|
325
|
+
} |
|
|
326
|
+
/** A spreadsheet, shown by the spreadsheet viewer. */
|
|
327
|
+
{
|
|
328
|
+
kind: "spreadsheet";
|
|
329
|
+
} |
|
|
330
|
+
/** An asset with nothing to show, as its file-type icon. */
|
|
331
|
+
{
|
|
332
|
+
kind: "file";
|
|
333
|
+
icon: UploadFileIconFamily | "unknown";
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* What `CalmLensAsset` shows for an asset URL and its display info: the image with its
|
|
337
|
+
* responsive widths, a website's screenshot and link, video with its poster and stream, audio with
|
|
338
|
+
* its waveform, a document, text or spreadsheet viewer, a preview still, a file icon, the age
|
|
339
|
+
* notice or the unavailable notice. `unavailable` is the session's verdict after the CDN refused
|
|
340
|
+
* the asset.
|
|
341
|
+
*/
|
|
342
|
+
declare const getAssetView: (options: Pick<AssetOptions, "display" | "viewerClaims" | "image" | "video">, state: {
|
|
343
|
+
src?: string;
|
|
344
|
+
info?: ViewerAsset;
|
|
345
|
+
unavailable?: boolean;
|
|
346
|
+
}) => AssetView;
|
|
347
|
+
/** Width divided by height of what the view shows, when it is known, so the box keeps its size. */
|
|
348
|
+
declare const getAssetAspectRatio: (view: AssetView, info: ViewerAsset | undefined, aspectRatio?: number) => number | undefined;
|
|
349
|
+
/** A key that changes whenever the view must load something new. */
|
|
350
|
+
declare const getAssetViewKey: (view: AssetView) => string;
|
|
351
|
+
/**
|
|
352
|
+
* The image URL to load for a box `displayWidth` pixels wide: the smallest width that covers it,
|
|
353
|
+
* or the largest when none does. Without widths, or before the box is measured, the view's own
|
|
354
|
+
* `src`. React Native, which has no `srcset`, calls this with its measured size.
|
|
355
|
+
*/
|
|
356
|
+
declare const pickAssetSource: (view: Extract<AssetView, {
|
|
357
|
+
kind: "image" | "website";
|
|
358
|
+
}>, displayWidth: number | undefined) => string;
|
|
359
|
+
/** Audio's waveform peaks as bar heights, in percent of the waveform's height. */
|
|
360
|
+
declare const getPeakHeights: (peaks: readonly number[]) => number[];
|
|
361
|
+
/** How much of a media element has played, in percent, to one decimal place. */
|
|
362
|
+
declare const getPlayedPercent: (media: {
|
|
363
|
+
currentTime: number;
|
|
364
|
+
duration: number;
|
|
365
|
+
}) => number;
|
|
366
|
+
/** Where a video or audio element was when its URL failed, to resume once a fresh one loads. */
|
|
367
|
+
interface MediaPlayback {
|
|
368
|
+
position: number;
|
|
369
|
+
playing: boolean;
|
|
370
|
+
}
|
|
371
|
+
/** What a session knows: the asset URL in use, the display info, and the CDN's verdict. */
|
|
372
|
+
interface AssetSessionState {
|
|
373
|
+
src?: string;
|
|
374
|
+
info?: ViewerAsset;
|
|
375
|
+
/** The CDN refused the asset, or its URL expired with no fresh one. */
|
|
376
|
+
unavailable: boolean;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* One `CalmLensAsset`'s connection to the CDN. Each render calls `update` with the options and
|
|
380
|
+
* renders `getAssetView` of what it returns; once mounted, `load` fetches `{src}/info` when `info`
|
|
381
|
+
* isn't given. Nothing is requested before `src` is set. A resource that fails to load
|
|
382
|
+
* (`failed`) is retried once beneath a fresh asset URL from `onExpired`; then, or without
|
|
383
|
+
* `onExpired`, the info is read again, and the CDN's answer decides: content it now refuses shows
|
|
384
|
+
* the unavailable or age notice, whatever the info said before. `onChange` runs whenever the state
|
|
385
|
+
* changes, so the component renders again.
|
|
386
|
+
*/
|
|
387
|
+
declare class AssetSession {
|
|
388
|
+
#private;
|
|
389
|
+
constructor(onChange: () => void);
|
|
390
|
+
/** The state for these options. It sends nothing: call `load` once mounted. */
|
|
391
|
+
update(options: AssetOptions): AssetSessionState;
|
|
392
|
+
/** The current state, without new options. */
|
|
393
|
+
get state(): AssetSessionState;
|
|
394
|
+
/** Fetches the display info when it is needed and not yet fetched or loading. Call once mounted. */
|
|
395
|
+
load(): void;
|
|
396
|
+
/**
|
|
397
|
+
* For a resource that failed to load, such as an image's `error`: retries once beneath a fresh
|
|
398
|
+
* asset URL, or asks the CDN whether the viewer may still see the asset.
|
|
399
|
+
*/
|
|
400
|
+
failed(): void;
|
|
401
|
+
/** For a resource that loaded: a later failure may refresh the asset URL again. */
|
|
402
|
+
loaded(): void;
|
|
403
|
+
/** For a refusal the component read itself: `asset/not-available` shows the unavailable notice. */
|
|
404
|
+
unavailable(): void;
|
|
405
|
+
/**
|
|
406
|
+
* A fresh asset URL from `onExpired`, which every resource then loads beneath. Rejects without
|
|
407
|
+
* `onExpired`, or when it fails, and the component shows the unavailable notice.
|
|
408
|
+
*/
|
|
409
|
+
refresh(): Promise<string>;
|
|
410
|
+
/** For a video or audio element's `error`: where it was, so it resumes beneath a fresh URL. */
|
|
411
|
+
mediaFailed(playback: MediaPlayback): void;
|
|
412
|
+
/** For `loadedmetadata`: the URL works, and a recovered element resumes where it stopped. */
|
|
413
|
+
mediaLoaded(media?: HTMLMediaElement): void;
|
|
414
|
+
/** Where to resume a recovered player, once: React Native hands it to your player. */
|
|
415
|
+
takeResume(): MediaPlayback | undefined;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Where a file is in the upload: picked and waiting for `start()` (with `autoUpload: false`),
|
|
419
|
+
* waiting its turn, sending bytes, being moderated, or finished.
|
|
420
|
+
*/
|
|
421
|
+
type UploadStage = "selected" | "queued" | "uploading" | "checking" | "complete" | "failed";
|
|
422
|
+
/**
|
|
423
|
+
* A file to upload: a browser `File`, or a file on a phone, such as a `File` from
|
|
424
|
+
* `expo-file-system`. Anything with a name, MIME type, size and bytes works.
|
|
425
|
+
*/
|
|
426
|
+
interface UploadFile {
|
|
427
|
+
readonly name: string;
|
|
428
|
+
readonly type: string;
|
|
429
|
+
readonly size: number;
|
|
430
|
+
/** The file's local URI on a phone, such as `file:///…`, used for the image preview. */
|
|
431
|
+
readonly uri?: string;
|
|
432
|
+
/** Reads the file's bytes when its upload starts. */
|
|
433
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
434
|
+
}
|
|
435
|
+
/** One file the uploader has picked, as the components render it. */
|
|
436
|
+
interface UploadItem<F extends UploadFile = UploadFile> {
|
|
437
|
+
/** A local ID for the file in this uploader, not the asset ID. */
|
|
438
|
+
readonly key: string;
|
|
439
|
+
readonly file: F;
|
|
440
|
+
readonly stage: UploadStage;
|
|
441
|
+
/** Sent bytes as a fraction from 0 to 1 while uploading, `null` when unknown. */
|
|
442
|
+
readonly progress: number | null;
|
|
443
|
+
/**
|
|
444
|
+
* A local preview of an image file while it's checked: an object URL in browsers, or the file's
|
|
445
|
+
* own URI on a phone.
|
|
446
|
+
*/
|
|
447
|
+
readonly previewUrl?: string;
|
|
448
|
+
readonly assetId?: string;
|
|
449
|
+
/** The moderation status, when the upload preset shows decisions to the uploader. */
|
|
450
|
+
readonly status?: AssetModerationStatus;
|
|
451
|
+
/**
|
|
452
|
+
* Why the file failed: a `CalmLensError` code, or `file/not-accepted` and `file/too-large` when
|
|
453
|
+
* the uploader refused the file before sending it.
|
|
454
|
+
*/
|
|
455
|
+
readonly errorCode?: string;
|
|
456
|
+
}
|
|
457
|
+
/** A finished upload that wasn't blocked, which your app saves with its record. */
|
|
458
|
+
interface CalmLensUpload<F extends UploadFile = UploadFile> {
|
|
459
|
+
assetId: string;
|
|
460
|
+
/** `undefined` when the upload preset doesn't show decisions to the uploader. */
|
|
461
|
+
status?: AssetModerationStatus;
|
|
462
|
+
file: F;
|
|
463
|
+
}
|
|
464
|
+
interface UploadSnapshot<F extends UploadFile = UploadFile> {
|
|
465
|
+
readonly items: readonly UploadItem<F>[];
|
|
466
|
+
/** Whether any file is still waiting, uploading or being checked. */
|
|
467
|
+
readonly busy: boolean;
|
|
468
|
+
}
|
|
469
|
+
/** The part of `CalmLensAppClient` the uploader uses, which `MockCalmLensAppClient` also has. */
|
|
470
|
+
interface UploadClient {
|
|
471
|
+
assets: Pick<CalmLensAppClient["assets"], "create" | "retrieve">;
|
|
472
|
+
}
|
|
473
|
+
/** What a custom `upload` function returns for each file. */
|
|
474
|
+
interface CustomUploadResult {
|
|
475
|
+
assetId: string;
|
|
476
|
+
/** The moderation status, if your API returns it. */
|
|
477
|
+
status?: AssetModerationStatus;
|
|
478
|
+
}
|
|
479
|
+
interface CustomUploadContext {
|
|
480
|
+
/** Aborted when the uploader cancels or removes the file. */
|
|
481
|
+
signal: AbortSignal;
|
|
482
|
+
/** Reports sent bytes, for the progress bar. `createProgressFetch` reports them for you. */
|
|
483
|
+
onProgress: (sentBytes: number, totalBytes: number) => void;
|
|
484
|
+
}
|
|
485
|
+
interface UploadControllerOptions<F extends UploadFile = UploadFile> {
|
|
486
|
+
/** The upload preset the files upload through. Not needed with `upload`. */
|
|
487
|
+
uploadPresetId?: string;
|
|
488
|
+
/**
|
|
489
|
+
* Uploads each file your own way instead of through an upload preset, for example through your
|
|
490
|
+
* app's API, which creates the asset with its API key. The uploader still shows progress, the
|
|
491
|
+
* decision and errors: throw a `CalmLensError` to show its code's message.
|
|
492
|
+
*/
|
|
493
|
+
upload?: (file: F, context: CustomUploadContext) => Promise<CustomUploadResult>;
|
|
494
|
+
/**
|
|
495
|
+
* Checks a pending upload made with `upload`, returning its current moderation status. Without
|
|
496
|
+
* it, a pending upload finishes as pending.
|
|
497
|
+
*/
|
|
498
|
+
checkStatus?: (assetId: string, context: {
|
|
499
|
+
signal: AbortSignal;
|
|
500
|
+
}) => Promise<AssetModerationStatus | undefined>;
|
|
501
|
+
/**
|
|
502
|
+
* The upload token, or a function that returns a fresh one for each file. Leave it out for
|
|
503
|
+
* presets that anyone can upload to.
|
|
504
|
+
*/
|
|
505
|
+
token?: string | ((file: F) => string | Promise<string>);
|
|
506
|
+
/**
|
|
507
|
+
* An endpoint on your server that returns `{ token }` for each file. It receives a `POST` with
|
|
508
|
+
* the file's `{ name, type, size }` as JSON. Use `token` instead for anything more custom.
|
|
509
|
+
*/
|
|
510
|
+
tokenUrl?: string;
|
|
511
|
+
/** File types to accept, as in an `<input accept>`: `image/*`, `.png`, `video/mp4`. */
|
|
512
|
+
accept?: string;
|
|
513
|
+
/** The largest file to accept, in bytes. Your preset's own limit still applies. */
|
|
514
|
+
maxFileSize?: number;
|
|
515
|
+
/**
|
|
516
|
+
* Upload files as soon as they're picked. Defaults to `true`. With `false`, picked files wait in
|
|
517
|
+
* the `selected` stage until you call `start()`, for example when a form is submitted.
|
|
518
|
+
*/
|
|
519
|
+
autoUpload?: boolean;
|
|
520
|
+
/** Accept more than one file. Defaults to `false`; a new file then replaces the last one. */
|
|
521
|
+
multiple?: boolean;
|
|
522
|
+
/** The most files kept at once when `multiple` is on. Defaults to 10. */
|
|
523
|
+
maxFiles?: number;
|
|
524
|
+
/** How many files upload at the same time. Defaults to 3. */
|
|
525
|
+
concurrency?: number;
|
|
526
|
+
/**
|
|
527
|
+
* How long to keep checking for a moderation decision, in milliseconds. Defaults to 15
|
|
528
|
+
* seconds; anything still pending after that is settled by your server's webhook.
|
|
529
|
+
*/
|
|
530
|
+
decisionTimeoutMs?: number;
|
|
531
|
+
/** The CalmLens API base URL, for local development. */
|
|
532
|
+
baseUrl?: string;
|
|
533
|
+
/**
|
|
534
|
+
* Creates the client for each upload. Defaults to `CalmLensAppClient`; tests can return a
|
|
535
|
+
* `MockCalmLensAppClient` from `calmlens/testing` instead.
|
|
536
|
+
*/
|
|
537
|
+
createClient?: (options: CalmLensAppClientOptions) => UploadClient;
|
|
538
|
+
/**
|
|
539
|
+
* Called for each finished upload that wasn't blocked or purged, and again with the new status
|
|
540
|
+
* when `retry` checks one that was still pending.
|
|
541
|
+
*/
|
|
542
|
+
onUploaded?: (upload: CalmLensUpload<F>) => void;
|
|
543
|
+
/** Called when moderation blocks or purges a file. */
|
|
544
|
+
onRejected?: (item: UploadItem<F>) => void;
|
|
545
|
+
/** Called when a file couldn't be uploaded. */
|
|
546
|
+
onFailed?: (item: UploadItem<F>) => void;
|
|
547
|
+
/** Called when the uploader removes a file, including a finished upload. */
|
|
548
|
+
onRemoved?: (item: UploadItem<F>) => void;
|
|
549
|
+
}
|
|
550
|
+
/** Whether a file matches an `accept` list such as `image/*,.pdf`. */
|
|
551
|
+
declare const isFileAccepted: (file: Pick<UploadFile, "name" | "type">, accept?: string) => boolean;
|
|
552
|
+
/**
|
|
553
|
+
* Uploads files through an upload preset and tracks each one until it has a moderation
|
|
554
|
+
* decision. It holds no UI: the React, Vue, Svelte and web components render its snapshot, and
|
|
555
|
+
* you can render your own with `subscribe`, which also makes it a Svelte store.
|
|
556
|
+
*/
|
|
557
|
+
declare class UploadController<F extends UploadFile = UploadFile> {
|
|
558
|
+
#private;
|
|
559
|
+
constructor(options: UploadControllerOptions<F>);
|
|
560
|
+
/** The current options. */
|
|
561
|
+
get options(): Readonly<UploadControllerOptions<F>>;
|
|
562
|
+
/** Replaces the options, for example when a component's props change. */
|
|
563
|
+
setOptions(options: UploadControllerOptions<F>): void;
|
|
564
|
+
getSnapshot: () => UploadSnapshot<F>;
|
|
565
|
+
/**
|
|
566
|
+
* Calls `listener` with the current snapshot now and after every change, and returns a
|
|
567
|
+
* function that stops. This is the Svelte store contract, and works with React's
|
|
568
|
+
* `useSyncExternalStore`.
|
|
569
|
+
*/
|
|
570
|
+
subscribe: (listener: (snapshot: UploadSnapshot<F>) => void) => (() => void);
|
|
571
|
+
/**
|
|
572
|
+
* Adds files from a file input, a drop, a paste or a phone's picker, and starts uploading them,
|
|
573
|
+
* or keeps them `selected` with `autoUpload: false`.
|
|
574
|
+
*/
|
|
575
|
+
addFiles(files: Iterable<F> | ArrayLike<F>): void;
|
|
576
|
+
/** Uploads every `selected` file, for an uploader with `autoUpload: false`. */
|
|
577
|
+
start(): void;
|
|
578
|
+
/**
|
|
579
|
+
* Tries a failed file again: an upload that finished but couldn't be checked is checked again,
|
|
580
|
+
* anything else is uploaded again. A finished upload still `pending` is checked again too.
|
|
581
|
+
*/
|
|
582
|
+
retry(key: string): void;
|
|
583
|
+
/**
|
|
584
|
+
* Stops a queued or running file and keeps it in the list as failed with `sdk/cancelled`, so
|
|
585
|
+
* `retry` can upload it again. Finished files are left as they are.
|
|
586
|
+
*/
|
|
587
|
+
cancel(key: string): void;
|
|
588
|
+
/** Cancels a file's upload if it's running and removes it from the list. */
|
|
589
|
+
remove(key: string): void;
|
|
590
|
+
/** Cancels every upload and empties the list, without calling `onRemoved`. */
|
|
591
|
+
clear(): void;
|
|
592
|
+
}
|
|
593
|
+
declare const createUploadController: <F extends UploadFile = UploadFile>(options: UploadControllerOptions<F>) => UploadController<F>;
|
|
594
|
+
/**
|
|
595
|
+
* The text the components show. Pass `messages` to any component to replace some or all of it,
|
|
596
|
+
* for example to translate it. Keys other than the named ones are error codes, so you can give
|
|
597
|
+
* any `CalmLensError` code its own message.
|
|
598
|
+
*/
|
|
599
|
+
interface CalmLensMessages {
|
|
600
|
+
dropzoneTitle: string;
|
|
601
|
+
dropzoneTitleDragging: string;
|
|
602
|
+
/** The picker button when the uploader takes one file. */
|
|
603
|
+
chooseFile: string;
|
|
604
|
+
/** The picker button with `multiple`. */
|
|
605
|
+
chooseFiles: string;
|
|
606
|
+
/** Replaces the picked file when the uploader takes one file. */
|
|
607
|
+
chooseAnother: string;
|
|
608
|
+
/** `{size}` is replaced with the largest accepted size, such as `20 MiB`. */
|
|
609
|
+
maxFileSizeHint: string;
|
|
610
|
+
/** Under a file waiting for `start()`. Empty by default, so the row shows only its size. */
|
|
611
|
+
selected: string;
|
|
612
|
+
queued: string;
|
|
613
|
+
uploading: string;
|
|
614
|
+
checking: string;
|
|
615
|
+
/** Finished, when the upload preset doesn't show decisions to the uploader. */
|
|
616
|
+
submitted: string;
|
|
617
|
+
pending: string;
|
|
618
|
+
allowed: string;
|
|
619
|
+
limited: string;
|
|
620
|
+
"age-restricted": string;
|
|
621
|
+
blocked: string;
|
|
622
|
+
purged: string;
|
|
623
|
+
failed: string;
|
|
624
|
+
"file/not-accepted": string;
|
|
625
|
+
"file/too-large": string;
|
|
626
|
+
retry: string;
|
|
627
|
+
/** `{name}` is replaced with the file name. */
|
|
628
|
+
remove: string;
|
|
629
|
+
/** `{name}` is replaced with the file name. */
|
|
630
|
+
cancel: string;
|
|
631
|
+
sensitiveTitle: string;
|
|
632
|
+
sensitiveBody: string;
|
|
633
|
+
reveal: string;
|
|
634
|
+
/** The link that opens a document on its own, shown until the document viewer loads. */
|
|
635
|
+
openDocument: string;
|
|
636
|
+
/** The link to a website asset's page; `{host}` is replaced with its host. */
|
|
637
|
+
openWebsite: string;
|
|
638
|
+
/** React Native: opens a video or audio without `renderPlayer` in the device's player. */
|
|
639
|
+
play: string;
|
|
640
|
+
/** React Native: opens a document, text, spreadsheet or website the component doesn't show. */
|
|
641
|
+
open: string;
|
|
642
|
+
unavailable: string;
|
|
643
|
+
[errorCode: string]: string;
|
|
644
|
+
}
|
|
645
|
+
declare const DEFAULT_MESSAGES: CalmLensMessages;
|
|
646
|
+
declare const resolveMessages: (overrides?: Partial<CalmLensMessages>) => CalmLensMessages;
|
|
647
|
+
/** Fills `{name}`-style placeholders. */
|
|
648
|
+
declare const formatMessage: (message: string, values: Record<string, string>) => string;
|
|
649
|
+
/** The message for a file's current state. */
|
|
650
|
+
declare const getUploadItemMessage: (item: UploadItem, messages: CalmLensMessages) => string;
|
|
651
|
+
/** How a finished file turned out, for styling: `accepted`, `restricted` or `rejected`. */
|
|
652
|
+
declare const getUploadItemOutcome: (item: UploadItem) => "accepted" | "restricted" | "rejected" | undefined;
|
|
653
|
+
/**
|
|
654
|
+
* A byte count for people, such as `1.2 MiB`: binary units, labelled as such, the unit of every
|
|
655
|
+
* CalmLens size limit.
|
|
656
|
+
*/
|
|
657
|
+
declare const formatBytes: (bytes: number) => string;
|
|
658
|
+
/** Everything a file's row shows, worked out once for every framework's uploader. */
|
|
659
|
+
interface UploadItemView {
|
|
660
|
+
message: string;
|
|
661
|
+
outcome?: "accepted" | "restricted" | "rejected";
|
|
662
|
+
busy: boolean;
|
|
663
|
+
/** Sent bytes from 0 to 100, or `undefined` for an indeterminate bar while checking. */
|
|
664
|
+
progressPercent?: number;
|
|
665
|
+
canRetry: boolean;
|
|
666
|
+
/** The remove button's accessible name: cancel while the file is busy. */
|
|
667
|
+
removeLabel: string;
|
|
668
|
+
/** The file-type icon shown when there is no image preview, as SVG markup. */
|
|
669
|
+
fileIcon: string;
|
|
670
|
+
size: string;
|
|
671
|
+
}
|
|
672
|
+
declare const describeUploadItem: (item: UploadItem, messages: CalmLensMessages) => UploadItemView;
|
|
673
|
+
/** The hint under the drop zone's title, or `undefined` without a size limit. */
|
|
674
|
+
declare const getDropzoneHint: (messages: CalmLensMessages, maxFileSize?: number) => string | undefined;
|
|
675
|
+
/** What an uploader shows around its file list, worked out once for every framework. */
|
|
676
|
+
interface UploaderView {
|
|
677
|
+
/**
|
|
678
|
+
* Whether to show the drop zone. An uploader that takes one file swaps it for the file's row,
|
|
679
|
+
* with a button to choose another, once a file is picked.
|
|
680
|
+
*/
|
|
681
|
+
showDropzone: boolean;
|
|
682
|
+
chooseLabel: string;
|
|
683
|
+
hint?: string;
|
|
684
|
+
}
|
|
685
|
+
declare const describeUploader: (snapshot: UploadSnapshot, options: Pick<UploadControllerOptions, "multiple" | "maxFileSize">, messages: CalmLensMessages) => UploaderView;
|
|
686
|
+
/** Props every framework's uploader takes, on top of the upload options. */
|
|
687
|
+
interface UploaderDisplayOptions<F extends UploadFile = UploadFile> {
|
|
688
|
+
disabled?: boolean;
|
|
689
|
+
/** Opens the camera on phones: `user` for the front camera, `environment` for the back. */
|
|
690
|
+
capture?: "user" | "environment";
|
|
691
|
+
/** Replaces some or all of the text the uploader shows. */
|
|
692
|
+
messages?: Partial<CalmLensMessages>;
|
|
693
|
+
/**
|
|
694
|
+
* Shows this upload queue instead of creating one, such as `useCalmLensUpload`'s `controller`,
|
|
695
|
+
* so your app can read the picked files and call `start()`. The upload options then come from
|
|
696
|
+
* the controller, and the uploader leaves its uploads running when it unmounts.
|
|
697
|
+
*/
|
|
698
|
+
controller?: UploadController<F>;
|
|
699
|
+
}
|
|
700
|
+
type UploaderProps<F extends UploadFile = UploadFile> = UploadControllerOptions<F> & UploaderDisplayOptions<F>;
|
|
701
|
+
/** Props every framework's `CalmLensAsset` takes, on top of the asset options. */
|
|
702
|
+
interface AssetDisplayOptions {
|
|
703
|
+
/**
|
|
704
|
+
* Describes an image or still, and labels video, audio, documents, text and file icons. Leave it
|
|
705
|
+
* empty only for decorative images.
|
|
706
|
+
*/
|
|
707
|
+
alt?: string;
|
|
708
|
+
/** How the content fills its box: `contain` (default) or `cover`. */
|
|
709
|
+
fit?: "contain" | "cover";
|
|
710
|
+
/** Width divided by height, which reserves the box's size before the info arrives. */
|
|
711
|
+
aspectRatio?: number;
|
|
712
|
+
/** Load images only when they near the viewport. Defaults to `true`. */
|
|
713
|
+
lazy?: boolean;
|
|
714
|
+
fetchPriority?: "high" | "low" | "auto";
|
|
715
|
+
/** Replaces some or all of the text the component shows. */
|
|
716
|
+
messages?: Partial<CalmLensMessages>;
|
|
717
|
+
}
|
|
718
|
+
/** What `CalmLensAsset` reports, in every binding (as callbacks, events or `on*` props). */
|
|
719
|
+
interface AssetEventHandlers {
|
|
720
|
+
/** The content shown loaded: an image, a player's metadata, or a viewer's content. */
|
|
721
|
+
onLoad?: () => void;
|
|
722
|
+
/** The content couldn't be shown, after any refresh of the asset URL. */
|
|
723
|
+
onError?: () => void;
|
|
724
|
+
/** The viewer's availability became known or changed, from the info or the CDN's refusal. */
|
|
725
|
+
onAvailabilityChange?: (availability: AssetAvailability) => void;
|
|
726
|
+
/**
|
|
727
|
+
* The viewer pressed the reveal button on age-restricted content. Run your app's age check,
|
|
728
|
+
* then render again with `viewerClaims.ageConfirmed`. Without it, the notice has no button.
|
|
729
|
+
*/
|
|
730
|
+
onAgeConfirmRequest?: () => void;
|
|
731
|
+
onPlay?: () => void;
|
|
732
|
+
onEnded?: () => void;
|
|
733
|
+
/** Video or audio played on, with its position in seconds. */
|
|
734
|
+
onTimeUpdate?: (currentTime: number) => void;
|
|
735
|
+
}
|
|
736
|
+
type AssetProps = AssetOptions & AssetDisplayOptions & AssetEventHandlers;
|
|
737
|
+
/** The size of the file icon shown for an asset with nothing else to show. */
|
|
738
|
+
declare const ASSET_FILE_ICON_SIZE = 64;
|
|
739
|
+
/** Path data for the components' 24×24 stroke icons, so every framework draws the same ones. */
|
|
740
|
+
declare const ICONS: {
|
|
741
|
+
readonly upload: "M12 16V4m0 0L7 9m5-5 5 5M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2";
|
|
742
|
+
readonly remove: "M18 6 6 18M6 6l12 12";
|
|
743
|
+
readonly retry: "M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7";
|
|
744
|
+
readonly unavailable: "M3 3l18 18M10.6 10.6a2 2 0 0 0 2.8 2.8M9.9 5.1A9.8 9.8 0 0 1 12 5c5 0 9 5 10 7a17 17 0 0 1-3.3 4.2M6.6 6.6C4.4 8 2.8 10.4 2 12c1 2 5 7 10 7a9.6 9.6 0 0 0 5.4-1.6";
|
|
745
|
+
};
|
|
746
|
+
type IconName = keyof typeof ICONS;
|
|
747
|
+
/** Attributes shared by every icon's `<svg>`. */
|
|
748
|
+
declare const ICON_ATTRIBUTES: {
|
|
749
|
+
readonly width: "18";
|
|
750
|
+
readonly height: "18";
|
|
751
|
+
readonly viewBox: "0 0 24 24";
|
|
752
|
+
readonly fill: "none";
|
|
753
|
+
readonly stroke: "currentColor";
|
|
754
|
+
readonly "stroke-width": "2";
|
|
755
|
+
readonly "stroke-linecap": "round";
|
|
756
|
+
readonly "stroke-linejoin": "round";
|
|
757
|
+
readonly "aria-hidden": "true";
|
|
758
|
+
};
|
|
759
|
+
interface ProgressFetchOptions {
|
|
760
|
+
/**
|
|
761
|
+
* The size of everything this fetch will send, such as the file's size. An upload larger than
|
|
762
|
+
* the client's `partSizeBytes` goes in several requests, and only this total keeps the
|
|
763
|
+
* reported share of the file from restarting with each part.
|
|
764
|
+
*/
|
|
765
|
+
totalBytes?: number;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* A `fetch` that reports how many bytes of the request body have been sent, which `fetch` itself
|
|
769
|
+
* can't do. It sends through `XMLHttpRequest`, so the upload components pass it to
|
|
770
|
+
* `CalmLensAppClient` as `uploadFetch`. Without `XMLHttpRequest` it falls back to `fetch` and
|
|
771
|
+
* reports nothing.
|
|
772
|
+
*
|
|
773
|
+
* The count runs across the requests sent through it: `sentBytes` adds the bodies of earlier
|
|
774
|
+
* requests that succeeded, so a file uploaded in parts keeps counting up. `totalBytes` is
|
|
775
|
+
* `options.totalBytes` when given, otherwise those earlier bodies plus the current one. Create
|
|
776
|
+
* one for each file.
|
|
777
|
+
*/
|
|
778
|
+
declare const createProgressFetch: (onProgress: (sentBytes: number, totalBytes: number) => void, { totalBytes }?: ProgressFetchOptions) => ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>);
|
|
779
|
+
/**
|
|
780
|
+
* The components' stylesheet, also shipped as `calmlens/styles.css`. The React components
|
|
781
|
+
* render it themselves (React hoists it into the head, on the server too); with Vue, Svelte or
|
|
782
|
+
* the web components, import or link `calmlens/styles.css` once. Nothing is added to the page
|
|
783
|
+
* at runtime. Theme it with the `--calmlens-*` custom properties, or leave it out and style the
|
|
784
|
+
* `calmlens-*` classes yourself.
|
|
785
|
+
*/
|
|
786
|
+
declare const CALMLENS_STYLES: string;
|
|
787
|
+
/**
|
|
788
|
+
* The components' colours and corner radius. The stylesheet uses them as its `--calmlens-*`
|
|
789
|
+
* defaults, and the React Native components take them as `theme`.
|
|
790
|
+
*/
|
|
791
|
+
interface CalmLensTheme {
|
|
792
|
+
accent: string;
|
|
793
|
+
/** Text on the accent colour. */
|
|
794
|
+
accentText: string;
|
|
795
|
+
/** Corner radius of the drop zone, file rows and media, in pixels. */
|
|
796
|
+
radius: number;
|
|
797
|
+
/** Body text. The stylesheet inherits it from the page instead. */
|
|
798
|
+
text: string;
|
|
799
|
+
/** Secondary text, such as a file's size. Defaults to `text` at 72%. */
|
|
800
|
+
muted: string;
|
|
801
|
+
/** Borders and the progress track. Defaults to `text` at 18%. */
|
|
802
|
+
border: string;
|
|
803
|
+
/** The drop zone's fill. Defaults to `text` at 4%. */
|
|
804
|
+
surface: string;
|
|
805
|
+
/** The file rows' fill. Defaults to none, so rows show what's behind them. */
|
|
806
|
+
background: string;
|
|
807
|
+
success: string;
|
|
808
|
+
warning: string;
|
|
809
|
+
danger: string;
|
|
810
|
+
}
|
|
811
|
+
declare const CALMLENS_THEME: {
|
|
812
|
+
readonly accent: "#635bff";
|
|
813
|
+
readonly accentText: "#fff";
|
|
814
|
+
readonly radius: 12;
|
|
815
|
+
readonly text: "#1f2328";
|
|
816
|
+
readonly background: "transparent";
|
|
817
|
+
readonly success: "#12a26f";
|
|
818
|
+
readonly warning: "#e8a317";
|
|
819
|
+
readonly danger: "#e5484d";
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* The full theme from your overrides, mixing the muted, border and surface colours from `text`
|
|
823
|
+
* as the stylesheet mixes them from the page's text colour.
|
|
824
|
+
*/
|
|
825
|
+
declare const resolveTheme: (overrides?: Partial<CalmLensTheme>) => CalmLensTheme;
|
|
826
|
+
export { getAssetViewKey as $, CustomUploadResult as A, AssetDisplay as B, formatMessage as C, resolveMessages as D, getUploadItemOutcome as E, UploadItem as F, AssetSession as G, AssetImageOptions as H, UploadSnapshot as I, AssetVideoOptions as J, AssetSessionState as K, UploadStage as L, UploadController as M, UploadControllerOptions as N, CalmLensUpload as O, UploadFile as P, getAssetView as Q, createUploadController as R, formatBytes as S, getUploadItemMessage as T, AssetImageSource as U, AssetDocumentOptions as V, AssetOptions as W, MediaPlayback as X, AssetView as Y, getAssetAspectRatio as Z, DEFAULT_MESSAGES as _, formatViewerMessage as _t, ProgressFetchOptions as a, ImageViewerOptions as at, describeUploadItem as b, ICON_ATTRIBUTES as c, TextViewerOptions as ct, AssetDisplayOptions as d, ViewerTextOptions as dt, getPeakHeights as et, AssetEventHandlers as f, WebsiteViewerOptions as ft, CalmLensMessages as g, ViewerMessages as gt, UploaderProps as h, DEFAULT_VIEWER_MESSAGES as ht, CALMLENS_STYLES as i, DocumentViewerOptions as it, UploadClient as j, CustomUploadContext as k, IconName as l, ViewerAsset as lt, UploaderDisplayOptions as m, isSpreadsheetFormat as mt, CalmLensTheme as n, pickAssetSource as nt, createProgressFetch as o, PdfAssetOptions as ot, AssetProps as p, getAssetViewerKind as pt, AssetSpreadsheetOptions as q, resolveTheme as r, AssetViewerKind as rt, ICONS as s, SpreadsheetViewerOptions as st, CALMLENS_THEME as t, getPlayedPercent as tt, ASSET_FILE_ICON_SIZE as u, ViewerOptions as ut, UploadItemView as v, resolveViewerMessages as vt, getDropzoneHint as w, describeUploader as x, UploaderView as y, isFileAccepted as z };
|