calmlens 0.20.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 +1329 -664
- package/cjs/{BrowserUpload-CjSHjx3C.js → BrowserUpload-CeSwiMo5.js} +1 -1
- package/cjs/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-D-NnAN7g.d.ts} +2 -2
- package/cjs/{CalmLensAppClient-NaCxOVlM.js → CalmLensAppClient-0UVCuNqW.js} +30 -10
- package/cjs/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-gG16T2py.d.ts} +13 -3
- package/cjs/{CalmLensOptionKeys-p2QK687A.js → CalmLensOptionKeys-CYY6elxg.js} +183 -347
- package/cjs/{CalmLensServerClient-C-jsjn8m.d.ts → CalmLensServerClient-BHx3x_nZ.d.ts} +106 -48
- package/cjs/{CalmLensServerClient-BDzTthxE.js → CalmLensServerClient-nfu6_YEW.js} +288 -88
- package/cjs/{CalmLensTypes-COJbOuiv.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-2nIv7Zh3.js → ModerationContextLimits-BxOmeSqq.js} +669 -269
- package/cjs/{ReactUpload-BdTRCTGA.js → ReactUpload-BK2O3dnK.js} +1 -1
- package/cjs/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DiiXfKvj.d.ts} +1 -1
- package/cjs/{TestTriggers-DbhsNPdg-DjvVuc2h.js → TestTriggers-BTyXtX0Q-ATuFDhLX.js} +342 -34
- package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/cjs/{UploadController-MLVs97Zt.js → UploadController-DLyiLDTB.js} +34 -14
- package/cjs/{WebhookPayload-DkukERKE.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 +24 -14
- package/cjs/testing.js +1413 -402
- 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/esm/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-D-NnAN7g.d.ts} +2 -2
- package/esm/{BrowserUpload-CAVkRotw.js → BrowserUpload-i9OhCzMJ.js} +1 -1
- package/esm/{CalmLensAppClient-PQ9VBvlW.js → CalmLensAppClient-CK4_Py0c.js} +30 -10
- package/esm/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-gG16T2py.d.ts} +13 -3
- package/esm/{CalmLensOptionKeys-Do2mPP6w.js → CalmLensOptionKeys-BGZlIsT2.js} +182 -340
- package/esm/{CalmLensServerClient-C-jsjn8m.d.ts → CalmLensServerClient-BHx3x_nZ.d.ts} +106 -48
- package/esm/{CalmLensServerClient-C_H5aAsV.js → CalmLensServerClient-dAQUcDWb.js} +265 -89
- package/esm/{CalmLensTypes-COJbOuiv.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-Chw-AzgL.js → ModerationContextLimits-B6_RalCQ.js} +624 -254
- package/esm/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DiiXfKvj.d.ts} +1 -1
- package/esm/{ReactUpload-CMmL0R5Q.js → ReactUpload-DxwVqfX1.js} +1 -1
- package/esm/{TestTriggers-DbhsNPdg-CUdrv8Nm.js → TestTriggers-BTyXtX0Q-GRB9jQwo.js} +319 -35
- package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/esm/{UploadController-BJZghJpg.js → UploadController-D9Z-h00Q.js} +34 -14
- package/esm/{WebhookPayload-DkukERKE.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 +24 -14
- package/esm/testing.js +1409 -398
- 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-DxbJ_Xaa.d.ts +0 -253
- package/cjs/ui-BSqPGKrZ.d.ts +0 -539
- package/cjs/ui-CX1z2pD9.js +0 -586
- 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
package/esm/server.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { a as selectModerationContextItems,
|
|
2
|
-
import { $ as
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
5
|
-
import {
|
|
6
|
-
import { t as CalmLensServerClient } from "./CalmLensServerClient-C-jsjn8m.js";
|
|
1
|
+
import { a as ClassificationNotEvaluatedReason, c as ModerationQualifier, d as HashListEntry, f as ModerationContext, g as selectModerationContextItems, h as ModerationContextItem, i as ClassificationCategoryReport, l as PolicyAction, m as MODERATION_CONTEXT_USED_ITEMS, n as ClassificationCategories, o as ClassificationQualifierResults, p as MODERATION_CONTEXT_USED_CHARACTERS, r as ClassificationCategory, s as Likelihood, u as HashList } from "./Classification-Q5zGpR8l-CEWjnE39.js";
|
|
2
|
+
import { $ as HashListPage, $t as WebhookHeadersInput, A as CdnAssetReference, An as AssetHls, At as ResetPolicyOptions, B as CreateMultipartUploadPartOptions, Bn as ProcessingOptions, Bt as SubmitAssetOptions, C as AssetVisibility, Cn as Policy, Ct as MoveFolderOptions, D as CalmLensAppClientOptions, Dn as AssetSearchQuery, Dt as PolicyPage, E as BatchAssetsResponse, En as AssetSearchMatchField, Et as PolicyIdOptions, F as ClassifyTextOptions, Fn as AssetSafetyHold, Ft as SignAssetUrlOptions, G as EnsureLensesOptions, Gt as UpdatePolicyOptions, H as DecideAssetOptions, Ht as UpdateFolderOptions, I as ConnectionOptions, In as AssetSafetyHoldReason, It as SignUploadTokenOptions, J as FolderPage, Jt as UploadPresetSubmitAssetOptions, K as ExplainAssetOptions, Kt as UpgradePolicyOptions, L as CreateFolderOptions, Ln as ExtractedText, Lt as SignedAssetUrl, M as CdnResource, Mn as AssetPreview, Mt as RetryAssetOptions, N as CdnServeOptions, Nn as AssetRendered, Nt as SearchAssetsOptions, O as CalmLensServerClientOptions, Ot as RemoveAssetContentOptions, P as CdnTransform, Pn as AssetRenderedKind, Pt as SetPolicyAutomaticUpdatesOptions, Q as HashListIdOptions, Qt as WaitForAssetDecisionOptions, R as CreateHashListOptions, Rn as FileMetadata, Rt as SignedUploadToken, S as AssetUploadStatus, Sn as ProcessingFeatures, St as MoveAssetOptions, T as BatchAssetsOptions, Tn as LensType, Tt as MultipartUploadPartOptions, U as DeleteAssetOptions, Ut as UpdateHashListOptions, V as CreatePolicyOptions, Vt as UpdateAssetOptions, W as EnsureLensOptions, Wt as UpdateLensOptions, X as HashListEntryIdOptions, Xt as VerifyWebhookSignatureOptions, Y as GetAssetInfoOptions, Yt as UploadedAsset, Z as HashListEntryPage, Zt as ViewerClaims, _ as AssetSearchResponse, _n as DetectedFace, _t as ListFoldersOptions, a as AssetChildrenPage, an as EventAsset, at as IterateFoldersOptions, b as AssetType, bn as ProcessingFeatureResults, bt as ListLensesOptions, c as AssetClassificationStatus, cn as EventFact, ct as IterateLensesOptions, d as AssetContentRemovalReason, dn as EventSeverity, dt as LensIdOptions, en as WebhookPayloadInput, et as IdempotencyOptions, f as AssetContentStatus, fn as EventType, ft as LensPage, g as AssetPage, gn as BoundingBox, gt as ListEventsOptions, h as AssetModerationStatus, hn as AgeRange, ht as ListAssetsOptions, i as AssetChecksums, it as IterateAssetsOptions, j as CdnAssetUrlOptions, jn as AssetHlsRendition, jt as RetrieveAssetOptions, k as CdnAssetLocation, kn as AssetInfo, kt as RequestOptions, l as AssetContent, ln as EventFactValues, lt as IteratePoliciesOptions, m as AssetModerationDecision, mn as Folder, mt as ListAssetTimelineOptions, n as Asset, nn as AssetTimelineSegment, nt as IterateAssetChildrenOptions, o as AssetClassification, on as TypedEvent, ot as IterateHashListEntriesOptions, p as AssetModeration, pt as ListAssetChildrenOptions, q as FolderIdOptions, qt as UploadAssetPartOptions, r as AssetAvailability, rn as GetEventsResponse, rt as IterateAssetTimelineOptions, s as AssetClassificationFailureReason, sn as EventCategory, st as IterateHashListsOptions, t as AddHashListEntryOptions, tn as AssetBatchOperation, tt as ImageTransformOptions, u as AssetContentOptions, un as EventFacts, ut as Lens, v as AssetSearchResult, vn as DetectedPerson, vt as ListHashListEntriesOptions, w as AssignPolicyOptions, wn as CursorPage, wt as MultipartUploadOptions, x as AssetUpload, xn as ProcessingFeatureStage, xt as ListPoliciesOptions, y as AssetTimelinePage, yn as ProcessingFeatureId, yt as ListHashListsOptions, z as CreateLensOptions, zn as MetadataItem, zt as StreamingFeatureOptions } from "./CalmLensTypes-CUB0YYVz.js";
|
|
3
|
+
import { i as getAssetInfo, n as DEFAULT_CDN_BASE_URL, r as CDN_RESOURCES, t as SDK_VERSION } from "./index-CKRgjV16.js";
|
|
4
|
+
import { a as CalmLensErrorCode, c as SdkErrorCode, i as CalmLensError, l as ApiErrorCode, o as CalmLensErrorDetails, r as CALMLENS_ERROR_CODES, s as CalmLensErrorOptions, t as ReceivedWebhookEventPayload } from "./WebhookPayload-BLT2y_Jy.js";
|
|
5
|
+
import { t as CalmLensServerClient } from "./CalmLensServerClient-BHx3x_nZ.js";
|
|
7
6
|
export declare const WEBHOOK_DELIVERY_HEADER = "x-calmlens-delivery";
|
|
8
7
|
export declare const WEBHOOK_TIMESTAMP_HEADER = "x-calmlens-timestamp";
|
|
9
8
|
export declare const WEBHOOK_SIGNATURE_HEADER = "x-calmlens-signature";
|
|
@@ -25,9 +24,51 @@ export declare function verifyWebhookSignature(options: VerifyWebhookSignatureOp
|
|
|
25
24
|
* so keep a default branch when you switch on `type`.
|
|
26
25
|
*/
|
|
27
26
|
export declare function parseWebhookEvent(options: VerifyWebhookSignatureOptions): Promise<ReceivedWebhookEventPayload>;
|
|
27
|
+
type FactsOf<TEvent> = TEvent extends {
|
|
28
|
+
facts: ReadonlyArray<infer TFact>;
|
|
29
|
+
} ? TFact : never;
|
|
30
|
+
type FactValue<TEvent, TKey> = Extract<FactsOf<TEvent>, {
|
|
31
|
+
key: TKey;
|
|
32
|
+
}> extends {
|
|
33
|
+
value: infer V;
|
|
34
|
+
} ? V : unknown;
|
|
35
|
+
/**
|
|
36
|
+
* The value of one of an event's facts, by key, or `undefined` when the event doesn't carry it.
|
|
37
|
+
* Typed by the event's `type`, so `getEventFact(event, "flagged-categories")` on an
|
|
38
|
+
* `asset.blocked` event is a list of categories. The fact's `url`, when it has one, is on the fact
|
|
39
|
+
* in `event.facts`.
|
|
40
|
+
*/
|
|
41
|
+
export declare const getEventFact: <TEvent extends {
|
|
42
|
+
facts?: ReadonlyArray<{
|
|
43
|
+
key: string;
|
|
44
|
+
value: unknown;
|
|
45
|
+
}>;
|
|
46
|
+
}, TKey extends FactsOf<TEvent> extends {
|
|
47
|
+
key: infer K;
|
|
48
|
+
} ? K : string>(event: TEvent, key: TKey) => FactValue<TEvent, TKey> | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* An event's facts as an object of values by key, such as `{ "flagged-categories": ["hate"] }`.
|
|
51
|
+
* A key the event repeats keeps its first value, as `getEventFact` reads it.
|
|
52
|
+
*/
|
|
53
|
+
export declare const getEventFacts: <TEvent extends {
|
|
54
|
+
facts?: ReadonlyArray<{
|
|
55
|
+
key: string;
|
|
56
|
+
value: unknown;
|
|
57
|
+
}>;
|
|
58
|
+
}>(event: TEvent) => { [TKey in FactsOf<TEvent> extends {
|
|
59
|
+
key: infer K extends string;
|
|
60
|
+
} ? K : string]?: FactValue<TEvent, TKey>; };
|
|
28
61
|
/**
|
|
29
62
|
* Whether a webhook event is a test send from the portal or the CLI rather than a real event: it
|
|
30
63
|
* carries the registered `{ key: "test", value: true }` fact.
|
|
31
64
|
*/
|
|
32
65
|
export declare const isTestWebhookEvent: (event: Pick<ReceivedWebhookEventPayload, "facts">) => boolean;
|
|
33
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Whether to apply `event` after `lastSequence`, the highest `assetSequence` you have applied for
|
|
68
|
+
* its asset (`null` or `undefined` when none). Deliveries can arrive out of order: an event about
|
|
69
|
+
* an asset is newer only with a higher `assetSequence`, so a retried or repeated delivery of an
|
|
70
|
+
* earlier one returns `false`. Events that aren't about an asset have no sequence and are always
|
|
71
|
+
* new. Store the event's `assetSequence` per `assetId` once you have applied it.
|
|
72
|
+
*/
|
|
73
|
+
export declare const isNewerAssetEvent: (event: Pick<ReceivedWebhookEventPayload, "assetSequence">, lastSequence: number | null | undefined) => boolean;
|
|
74
|
+
export { type AddHashListEntryOptions, type AgeRange, type ApiErrorCode, type Asset, type AssetAvailability, type AssetBatchOperation, type AssetChecksums, type AssetChildrenPage, type AssetClassification, type AssetClassificationFailureReason, type AssetClassificationStatus, type AssetContent, type AssetContentOptions, type AssetContentRemovalReason, type AssetContentStatus, type AssetHls, type AssetHlsRendition, type AssetInfo, type AssetModeration, type AssetModerationDecision, type AssetModerationStatus, type AssetPage, type AssetPreview, type AssetRendered, type AssetRenderedKind, type AssetSafetyHold, type AssetSafetyHoldReason, type AssetSearchMatchField, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetTimelinePage, type AssetTimelineSegment, type AssetType, type AssetUpload, type AssetUploadStatus, type AssetVisibility, type AssignPolicyOptions, type BatchAssetsOptions, type BatchAssetsResponse, type BoundingBox, CALMLENS_ERROR_CODES, CDN_RESOURCES, type CalmLensAppClientOptions, CalmLensError, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, CalmLensServerClient, type CalmLensServerClientOptions, type CdnAssetLocation, type CdnAssetReference, type CdnAssetUrlOptions, type CdnResource, type CdnServeOptions, type CdnTransform, type ClassificationCategories, type ClassificationCategory, type ClassificationCategoryReport, type ClassificationNotEvaluatedReason, type ClassificationQualifierResults, type ClassifyTextOptions, type ConnectionOptions, type CreateFolderOptions, type CreateHashListOptions, type CreateLensOptions, type CreateMultipartUploadPartOptions, type CreatePolicyOptions, type CursorPage, DEFAULT_CDN_BASE_URL, type DecideAssetOptions, type DeleteAssetOptions, type DetectedFace, type DetectedPerson, type EnsureLensOptions, type EnsureLensesOptions, type EventAsset, type EventCategory, type EventFact, type EventFactValues, type EventFacts, type EventSeverity, type EventType, type GetEventsResponse as EventsPage, type ExplainAssetOptions, type ExtractedText, type FileMetadata, type Folder, type FolderIdOptions, type FolderPage, type GetAssetInfoOptions, type HashList, type HashListEntry, type HashListEntryIdOptions, type HashListEntryPage, type HashListIdOptions, type HashListPage, type IdempotencyOptions, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetTimelineOptions, type IterateAssetsOptions, type IterateFoldersOptions, type IterateHashListEntriesOptions, type IterateHashListsOptions, type IterateLensesOptions, type IteratePoliciesOptions, type Lens, type LensIdOptions, type LensPage, type LensType, type Likelihood, type ListAssetChildrenOptions, type ListAssetTimelineOptions, type ListAssetsOptions, type ListEventsOptions, type ListFoldersOptions, type ListHashListEntriesOptions, type ListHashListsOptions, type ListLensesOptions, type ListPoliciesOptions, MODERATION_CONTEXT_USED_CHARACTERS, MODERATION_CONTEXT_USED_ITEMS, type MetadataItem, type ModerationContext, type ModerationContextItem, type ModerationQualifier, type MoveAssetOptions, type MoveFolderOptions, type MultipartUploadOptions, type MultipartUploadPartOptions, type Policy, type PolicyAction, type PolicyIdOptions, type PolicyPage, type ProcessingFeatureId, type ProcessingFeatureResults, type ProcessingFeatureStage, type ProcessingFeatures, type ProcessingOptions, type RemoveAssetContentOptions, type RequestOptions, type ResetPolicyOptions, type RetrieveAssetOptions, type RetryAssetOptions, SDK_VERSION, type SdkErrorCode, type SearchAssetsOptions, type SetPolicyAutomaticUpdatesOptions, type SignAssetUrlOptions, type SignUploadTokenOptions, type SignedAssetUrl, type SignedUploadToken, type StreamingFeatureOptions, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UpdateHashListOptions, type UpdateLensOptions, type UpdatePolicyOptions, type UpgradePolicyOptions, type UploadAssetPartOptions, type UploadPresetSubmitAssetOptions, type UploadedAsset, type VerifyWebhookSignatureOptions, type ViewerClaims, type WaitForAssetDecisionOptions, type ReceivedWebhookEventPayload as WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput, getAssetInfo, selectModerationContextItems };
|
package/esm/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L as CALMLENS_ERROR_CODES, P as SDK_VERSION, R as CalmLensError, i as CDN_RESOURCES, n as MODERATION_CONTEXT_USED_ITEMS, r as selectModerationContextItems, s as getAssetInfo, t as MODERATION_CONTEXT_USED_CHARACTERS, u as DEFAULT_CDN_BASE_URL } from "./ModerationContextLimits-B6_RalCQ.js";
|
|
2
2
|
import "./index.js";
|
|
3
|
-
import { a as WEBHOOK_TIMESTAMP_HEADER, c as verifyWebhookSignature, i as WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, n as WEBHOOK_DELIVERY_HEADER, o as
|
|
4
|
-
export { CALMLENS_ERROR_CODES, CalmLensError, CalmLensServerClient, DEFAULT_CDN_BASE_URL, MODERATION_CONTEXT_USED_CHARACTERS, MODERATION_CONTEXT_USED_ITEMS, SDK_VERSION, WEBHOOK_DELIVERY_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, WEBHOOK_TIMESTAMP_HEADER,
|
|
3
|
+
import { a as WEBHOOK_TIMESTAMP_HEADER, c as isNewerAssetEvent, d as verifyWebhookSignature, i as WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, l as isTestWebhookEvent, n as WEBHOOK_DELIVERY_HEADER, o as getEventFact, r as WEBHOOK_SIGNATURE_HEADER, s as getEventFacts, t as CalmLensServerClient, u as parseWebhookEvent } from "./CalmLensServerClient-dAQUcDWb.js";
|
|
4
|
+
export { CALMLENS_ERROR_CODES, CDN_RESOURCES, CalmLensError, CalmLensServerClient, DEFAULT_CDN_BASE_URL, MODERATION_CONTEXT_USED_CHARACTERS, MODERATION_CONTEXT_USED_ITEMS, SDK_VERSION, WEBHOOK_DELIVERY_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, WEBHOOK_TIMESTAMP_HEADER, getAssetInfo, getEventFact, getEventFacts, isNewerAssetEvent, isTestWebhookEvent, parseWebhookEvent, selectModerationContextItems, verifyWebhookSignature };
|
package/esm/styles.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Zero specificity, so a page's own --calmlens-* values win even on the same element. */
|
|
2
|
-
:where(.calmlens-uploader, .calmlens-
|
|
2
|
+
:where(.calmlens-uploader, .calmlens-asset) {
|
|
3
3
|
--calmlens-accent: #635bff;
|
|
4
4
|
--calmlens-accent-text: #fff;
|
|
5
5
|
--calmlens-radius: 12px;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
box-sizing: border-box;
|
|
17
17
|
font: inherit;
|
|
18
18
|
}
|
|
19
|
-
.calmlens-uploader *, .calmlens-
|
|
19
|
+
.calmlens-uploader *, .calmlens-asset * { box-sizing: border-box; }
|
|
20
20
|
.calmlens-uploader { display: grid; gap: 12px; }
|
|
21
21
|
.calmlens-uploader > [hidden] { display: none; }
|
|
22
22
|
.calmlens-dropzone {
|
|
@@ -107,41 +107,161 @@
|
|
|
107
107
|
}
|
|
108
108
|
.calmlens-icon-button:hover { background: color-mix(in srgb, var(--calmlens-accent) 8%, transparent); border-color: var(--calmlens-border); }
|
|
109
109
|
@media (prefers-reduced-motion: reduce) {
|
|
110
|
-
.calmlens-progress__bar, .calmlens-dropzone, .calmlens-dropzone__icon, .calmlens-
|
|
110
|
+
.calmlens-progress__bar, .calmlens-dropzone, .calmlens-dropzone__icon, .calmlens-asset__content { transition: none; }
|
|
111
111
|
.calmlens-progress:not([aria-valuenow]) .calmlens-progress__bar { animation: none; left: 0; width: 100%; }
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
.calmlens-
|
|
114
|
+
.calmlens-asset {
|
|
115
115
|
position: relative; display: block; overflow: hidden; margin: 0; border-radius: var(--calmlens-media-radius, 0);
|
|
116
116
|
background: var(--calmlens-surface);
|
|
117
117
|
}
|
|
118
|
-
.calmlens-
|
|
119
|
-
position: absolute; inset: 0; width: 100%; height: 100%; object-fit: var(--calmlens-fit,
|
|
118
|
+
.calmlens-asset__placeholder, .calmlens-asset__content {
|
|
119
|
+
position: absolute; inset: 0; width: 100%; height: 100%; object-fit: var(--calmlens-fit, contain);
|
|
120
120
|
object-position: var(--calmlens-position, center);
|
|
121
121
|
}
|
|
122
|
-
.calmlens-
|
|
123
|
-
.calmlens-
|
|
124
|
-
.calmlens-
|
|
125
|
-
.calmlens-
|
|
126
|
-
.calmlens-
|
|
127
|
-
.calmlens-
|
|
128
|
-
.calmlens-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
.calmlens-
|
|
122
|
+
.calmlens-asset:not([data-sized]) .calmlens-asset__content { position: relative; height: auto; }
|
|
123
|
+
.calmlens-asset:not([data-sized])[data-kind="age-restricted"], .calmlens-asset:not([data-sized])[data-kind="unavailable"],
|
|
124
|
+
.calmlens-asset:not([data-sized])[data-state="error"] { min-height: 160px; }
|
|
125
|
+
.calmlens-asset__placeholder { transform: scale(1.1); filter: blur(12px); }
|
|
126
|
+
.calmlens-asset__content { opacity: 0; transition: opacity 250ms; }
|
|
127
|
+
.calmlens-asset[data-state="loaded"] .calmlens-asset__content { opacity: 1; }
|
|
128
|
+
.calmlens-asset[data-kind="video"] .calmlens-asset__content, .calmlens-asset[data-kind="audio"] .calmlens-asset__content { opacity: 1; }
|
|
129
|
+
/* Documents, text and spreadsheets fill the box with their viewer; a document shows its first
|
|
130
|
+
page's still and an open link until the viewer loads. */
|
|
131
|
+
.calmlens-asset__viewer { position: absolute; inset: 0; }
|
|
132
|
+
.calmlens-asset:not([data-sized])[data-kind="document"], .calmlens-asset:not([data-sized])[data-kind="text"],
|
|
133
|
+
.calmlens-asset:not([data-sized])[data-kind="spreadsheet"] { height: 480px; }
|
|
134
|
+
.calmlens-asset[data-kind="document"] .calmlens-asset__content { opacity: 1; }
|
|
135
|
+
.calmlens-asset__open { position: absolute; right: 8px; bottom: 8px; text-decoration: none; }
|
|
136
|
+
/* A website's screenshot scrolls beneath the link to its page. */
|
|
137
|
+
.calmlens-asset[data-kind="website"] { display: flex; flex-direction: column; }
|
|
138
|
+
.calmlens-asset__bar { position: relative; z-index: 1; padding: 8px; }
|
|
139
|
+
.calmlens-asset__scroll { position: relative; flex: 1; overflow: auto; }
|
|
140
|
+
.calmlens-asset[data-kind="website"] .calmlens-asset__content { position: relative; height: auto; object-fit: initial; }
|
|
141
|
+
.calmlens-asset__file { position: absolute; inset: 0; display: grid; place-items: center; }
|
|
142
|
+
.calmlens-asset:not([data-sized])[data-kind="file"], .calmlens-asset:not([data-sized])[data-kind="pending"] { min-height: 160px; }
|
|
143
|
+
.calmlens-asset[data-kind="audio"] { background: none; display: grid; gap: 8px; }
|
|
144
|
+
.calmlens-asset[data-kind="audio"] .calmlens-asset__content { position: static; height: auto; }
|
|
145
|
+
/* Audio's waveform: the preview still, with the played part of its peaks in the accent colour. */
|
|
146
|
+
.calmlens-asset__waveform {
|
|
147
|
+
position: relative; height: var(--calmlens-waveform-height, 64px); border-radius: var(--calmlens-media-radius, 0);
|
|
148
|
+
overflow: hidden; background: var(--calmlens-surface);
|
|
149
|
+
}
|
|
150
|
+
.calmlens-asset__wave { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
|
|
151
|
+
.calmlens-asset__progress, .calmlens-asset__peaks { position: absolute; inset: 0; pointer-events: none; }
|
|
152
|
+
.calmlens-asset__peaks { display: flex; align-items: center; gap: 1px; }
|
|
153
|
+
.calmlens-asset__peaks > span { flex: 1 1 0; min-width: 1px; border-radius: 1px; background: var(--calmlens-border); }
|
|
154
|
+
.calmlens-asset__wave ~ .calmlens-asset__progress .calmlens-asset__peaks:not([data-played]) { visibility: hidden; }
|
|
155
|
+
.calmlens-asset__peaks[data-played] { clip-path: inset(0 calc(100% - var(--calmlens-played, 0%)) 0 0); }
|
|
156
|
+
.calmlens-asset__peaks[data-played] > span { background: var(--calmlens-accent); }
|
|
157
|
+
.calmlens-asset__notice {
|
|
132
158
|
position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 6px;
|
|
133
159
|
padding: 12px; text-align: center; color: #fff; background: rgba(0, 0, 0, 0.45);
|
|
134
160
|
}
|
|
135
|
-
.calmlens-
|
|
161
|
+
.calmlens-asset__notice p { margin: 0; display: flex; gap: 6px; align-items: center; }
|
|
136
162
|
/* Thumbnails keep the notice's icon and leave its text to screen readers. */
|
|
137
|
-
.calmlens-
|
|
163
|
+
.calmlens-asset[data-sized] { container-type: inline-size; }
|
|
138
164
|
@container (max-width: 119px) {
|
|
139
|
-
.calmlens-
|
|
165
|
+
.calmlens-asset__label, .calmlens-asset__notice > strong, .calmlens-asset__notice > p:not(:has(svg)) {
|
|
140
166
|
position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
|
|
141
167
|
}
|
|
142
168
|
}
|
|
143
|
-
.calmlens-
|
|
144
|
-
.calmlens-
|
|
145
|
-
.calmlens-
|
|
169
|
+
.calmlens-asset__notice strong { font-weight: 600; }
|
|
170
|
+
.calmlens-asset__notice .calmlens-button { margin-top: 4px; border-color: #fff; background: #fff; color: #111; }
|
|
171
|
+
.calmlens-asset[data-state="error"] .calmlens-asset__notice, .calmlens-asset[data-kind="unavailable"] .calmlens-asset__notice {
|
|
146
172
|
color: inherit; background: var(--calmlens-surface);
|
|
147
173
|
}
|
|
174
|
+
|
|
175
|
+
:where(.calmlens-viewer) {
|
|
176
|
+
--calmlens-accent: #635bff;
|
|
177
|
+
--calmlens-accent-text: #fff;
|
|
178
|
+
--calmlens-radius: 12px;
|
|
179
|
+
--calmlens-focus-width: 2px;
|
|
180
|
+
--calmlens-focus-offset: 2px;
|
|
181
|
+
--calmlens-border: color-mix(in srgb, currentColor 18%, transparent);
|
|
182
|
+
--calmlens-surface: color-mix(in srgb, currentColor 4%, transparent);
|
|
183
|
+
--calmlens-muted: color-mix(in srgb, currentColor 72%, transparent);
|
|
184
|
+
--calmlens-focus-ring: var(--calmlens-accent);
|
|
185
|
+
box-sizing: border-box;
|
|
186
|
+
font: inherit;
|
|
187
|
+
}
|
|
188
|
+
.calmlens-viewer *, .calmlens-viewer *::before, .calmlens-viewer *::after { box-sizing: border-box; }
|
|
189
|
+
.calmlens-viewer { display: block; position: relative; width: 100%; height: 100%; }
|
|
190
|
+
.calmlens-viewer__frame {
|
|
191
|
+
position: relative; display: flex; flex-direction: column; width: 100%; height: 100%;
|
|
192
|
+
min-height: 0; overflow: hidden;
|
|
193
|
+
/* An opaque surface of its own, so sticky headers and the toolbar cover what scrolls under them. */
|
|
194
|
+
background: var(--calmlens-viewer-background, Canvas); color: var(--calmlens-viewer-text, CanvasText);
|
|
195
|
+
}
|
|
196
|
+
.calmlens-viewer:is([data-kind="text"], [data-kind="document"], [data-kind="spreadsheet"], [data-kind="website"]) > .calmlens-viewer__frame { min-height: 320px; }
|
|
197
|
+
.calmlens-viewer :focus-visible {
|
|
198
|
+
outline: 2px solid var(--calmlens-focus-ring); outline-offset: -2px;
|
|
199
|
+
}
|
|
200
|
+
.calmlens-viewer__sr {
|
|
201
|
+
position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
|
|
202
|
+
clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
|
|
203
|
+
}
|
|
204
|
+
.calmlens-viewer__notice {
|
|
205
|
+
display: grid; place-content: center; justify-items: center; gap: 12px; flex: 1;
|
|
206
|
+
padding: 24px 16px; text-align: center; color: var(--calmlens-muted);
|
|
207
|
+
}
|
|
208
|
+
.calmlens-viewer__notice p { margin: 0; max-width: 40ch; }
|
|
209
|
+
.calmlens-viewer__bar {
|
|
210
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 8px;
|
|
211
|
+
border-bottom: 1px solid var(--calmlens-border); background: var(--calmlens-viewer-background, Canvas);
|
|
212
|
+
}
|
|
213
|
+
.calmlens-viewer__bar .calmlens-button { min-width: 36px; min-height: 36px; }
|
|
214
|
+
.calmlens-viewer__spacer { flex: 1; }
|
|
215
|
+
.calmlens-viewer__link { text-decoration: none; overflow-wrap: anywhere; }
|
|
216
|
+
.calmlens-viewer__scroll { flex: 1; min-height: 0; overflow: auto; position: relative; }
|
|
217
|
+
/* Images fit inside the frame, keeping their shape; without a frame height, the box takes it. */
|
|
218
|
+
.calmlens-viewer[data-kind="image"] > .calmlens-viewer__frame { aspect-ratio: var(--calmlens-viewer-ratio, auto); max-height: 100%; }
|
|
219
|
+
.calmlens-viewer[data-kind="image"] > .calmlens-viewer__frame > img {
|
|
220
|
+
position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
|
|
221
|
+
}
|
|
222
|
+
.calmlens-viewer:not([data-kind="image"]) .calmlens-viewer__placeholder {
|
|
223
|
+
position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top;
|
|
224
|
+
}
|
|
225
|
+
.calmlens-viewer__placeholder { filter: blur(12px); transform: scale(1.05); }
|
|
226
|
+
.calmlens-viewer__image { opacity: 0; transition: opacity 250ms; }
|
|
227
|
+
.calmlens-viewer[data-state="loaded"] .calmlens-viewer__image { opacity: 1; }
|
|
228
|
+
.calmlens-viewer[data-kind="website"] .calmlens-viewer__image { position: relative; display: block; width: 100%; height: auto; }
|
|
229
|
+
.calmlens-viewer__text {
|
|
230
|
+
margin: 0 auto; padding: 20px 24px; max-width: 75ch; white-space: pre-wrap; overflow-wrap: anywhere;
|
|
231
|
+
font-family: inherit; font-size: 1rem; line-height: 1.6;
|
|
232
|
+
}
|
|
233
|
+
.calmlens-viewer__pages { flex: 1; min-height: 0; overflow: auto; padding: 16px; text-align: center; }
|
|
234
|
+
.calmlens-viewer__page { display: inline-block; position: relative; vertical-align: top; }
|
|
235
|
+
.calmlens-viewer__page canvas { display: block; background: #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.2); }
|
|
236
|
+
.calmlens-viewer__page-field { width: 4.5em; min-height: 36px; padding: 4px 6px; font: inherit; border: 1px solid var(--calmlens-border); border-radius: calc(var(--calmlens-radius) / 2); background: transparent; color: inherit; }
|
|
237
|
+
.calmlens-viewer__zoom { min-width: 4ch; text-align: center; font-variant-numeric: tabular-nums; }
|
|
238
|
+
.calmlens-viewer__sheets { display: flex; flex-direction: column; flex: 1; min-height: 0; }
|
|
239
|
+
.calmlens-viewer__tabs {
|
|
240
|
+
display: flex; gap: 2px; overflow-x: auto; padding: 6px 8px 0; border-bottom: 1px solid var(--calmlens-border);
|
|
241
|
+
}
|
|
242
|
+
.calmlens-viewer__tab {
|
|
243
|
+
padding: 6px 12px; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0;
|
|
244
|
+
background: none; color: inherit; font: inherit; white-space: nowrap; cursor: pointer;
|
|
245
|
+
}
|
|
246
|
+
.calmlens-viewer__tab[aria-selected="true"] { border-color: var(--calmlens-border); background: var(--calmlens-viewer-background, Canvas); font-weight: 600; }
|
|
247
|
+
.calmlens-viewer__tab[data-hidden], .calmlens-viewer__table [data-hidden] { font-style: italic; }
|
|
248
|
+
.calmlens-viewer__panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
|
|
249
|
+
.calmlens-viewer__table { flex: 1; min-height: 0; overflow: auto; }
|
|
250
|
+
.calmlens-viewer__table table { border-collapse: collapse; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
|
|
251
|
+
.calmlens-viewer__table th, .calmlens-viewer__table td {
|
|
252
|
+
padding: 4px 8px; border: 1px solid var(--calmlens-border); text-align: left; vertical-align: top;
|
|
253
|
+
max-width: 40ch; overflow-wrap: anywhere; white-space: pre-wrap;
|
|
254
|
+
}
|
|
255
|
+
.calmlens-viewer__table thead th { position: sticky; top: 0; z-index: 1; }
|
|
256
|
+
.calmlens-viewer__table th { background: var(--calmlens-viewer-background, Canvas); font-weight: 600; color: var(--calmlens-muted); }
|
|
257
|
+
.calmlens-viewer__table tbody th { position: sticky; left: 0; text-align: right; }
|
|
258
|
+
.calmlens-viewer__corner { background: var(--calmlens-viewer-background, Canvas); }
|
|
259
|
+
.calmlens-viewer__tag { margin-left: 6px; font-size: 0.75em; font-weight: 400; }
|
|
260
|
+
.calmlens-viewer__pager {
|
|
261
|
+
display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px;
|
|
262
|
+
border-top: 1px solid var(--calmlens-border);
|
|
263
|
+
}
|
|
264
|
+
.calmlens-viewer__pager p { margin: 0; }
|
|
265
|
+
.calmlens-viewer__empty { margin: 0; padding: 24px 16px; color: var(--calmlens-muted); }
|
|
266
|
+
.calmlens-viewer__notes { padding: 8px 16px; border-top: 1px solid var(--calmlens-border); font-size: 0.875rem; }
|
|
267
|
+
.calmlens-viewer__notes ul { margin: 0; padding-left: 1.25em; }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// Mounts one of the shared asset viewers (preview) into its element; the named viewer
|
|
3
|
+
// components wrap it.
|
|
4
|
+
import { onMount } from "svelte";
|
|
5
|
+
import { ASSET_VIEWERS, type AssetViewer, type AssetViewerName } from "../ui.js";
|
|
6
|
+
|
|
7
|
+
let { kind, ...options }: { kind: AssetViewerName } & Record<string, unknown> = $props();
|
|
8
|
+
let root: HTMLElement | undefined = $state();
|
|
9
|
+
let viewer: AssetViewer<never> | undefined;
|
|
10
|
+
|
|
11
|
+
// Every change of props: the viewer loads again only when what it shows changed.
|
|
12
|
+
$effect(() => {
|
|
13
|
+
const next = { ...options } as never;
|
|
14
|
+
if (!root) return;
|
|
15
|
+
if (viewer) viewer.update(next);
|
|
16
|
+
else viewer = ASSET_VIEWERS[kind](root, next) as AssetViewer<never>;
|
|
17
|
+
});
|
|
18
|
+
onMount(() => () => {
|
|
19
|
+
viewer?.destroy();
|
|
20
|
+
viewer = undefined;
|
|
21
|
+
});
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<!-- The viewer owns the element's children; Svelte renders none. -->
|
|
25
|
+
<div bind:this={root} class="calmlens-viewer" data-kind={kind}></div>
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, type Snippet } from "svelte";
|
|
3
|
+
import { renderFileIconSvg } from "../file-icons.js";
|
|
4
|
+
import {
|
|
5
|
+
ASSET_FILE_ICON_SIZE,
|
|
6
|
+
type AssetProps,
|
|
7
|
+
AssetSession,
|
|
8
|
+
type AssetView,
|
|
9
|
+
AssetViewerMount,
|
|
10
|
+
formatMessage,
|
|
11
|
+
getAssetAspectRatio,
|
|
12
|
+
getAssetView,
|
|
13
|
+
getAssetViewKey,
|
|
14
|
+
getMountedViewerOptions,
|
|
15
|
+
getPeakHeights,
|
|
16
|
+
getPlayedPercent,
|
|
17
|
+
isMountedViewerKind,
|
|
18
|
+
MediaStreamPlayer,
|
|
19
|
+
resolveMessages,
|
|
20
|
+
} from "../ui.js";
|
|
21
|
+
import Icon from "./Icon.svelte";
|
|
22
|
+
|
|
23
|
+
let {
|
|
24
|
+
src,
|
|
25
|
+
display,
|
|
26
|
+
viewerClaims,
|
|
27
|
+
info,
|
|
28
|
+
image: imageOptions,
|
|
29
|
+
video: videoOptions,
|
|
30
|
+
document: documentOptions,
|
|
31
|
+
spreadsheet,
|
|
32
|
+
onExpired,
|
|
33
|
+
alt = "",
|
|
34
|
+
fit,
|
|
35
|
+
aspectRatio,
|
|
36
|
+
lazy = true,
|
|
37
|
+
fetchPriority,
|
|
38
|
+
messages: overrides,
|
|
39
|
+
onLoad,
|
|
40
|
+
onError,
|
|
41
|
+
onAvailabilityChange,
|
|
42
|
+
onAgeConfirmRequest,
|
|
43
|
+
onPlay,
|
|
44
|
+
onEnded,
|
|
45
|
+
onTimeUpdate,
|
|
46
|
+
renderUnavailable,
|
|
47
|
+
renderAgeGate,
|
|
48
|
+
}: AssetProps & {
|
|
49
|
+
renderUnavailable?: Snippet;
|
|
50
|
+
renderAgeGate?: Snippet<[{ placeholderUrl?: string; confirm?: () => void }]>;
|
|
51
|
+
} = $props();
|
|
52
|
+
|
|
53
|
+
const messages = $derived(resolveMessages(overrides));
|
|
54
|
+
const options = $derived({
|
|
55
|
+
src,
|
|
56
|
+
display,
|
|
57
|
+
viewerClaims,
|
|
58
|
+
info,
|
|
59
|
+
image: imageOptions,
|
|
60
|
+
video: videoOptions,
|
|
61
|
+
document: documentOptions,
|
|
62
|
+
spreadsheet,
|
|
63
|
+
onExpired,
|
|
64
|
+
alt,
|
|
65
|
+
});
|
|
66
|
+
let version = $state(0);
|
|
67
|
+
const session = new AssetSession(() => {
|
|
68
|
+
version++;
|
|
69
|
+
});
|
|
70
|
+
const sessionState = $derived.by(() => {
|
|
71
|
+
void version;
|
|
72
|
+
return session.update(options);
|
|
73
|
+
});
|
|
74
|
+
const view: AssetView = $derived(getAssetView(options, sessionState));
|
|
75
|
+
const loadKey = $derived(getAssetViewKey(view));
|
|
76
|
+
const ratio = $derived(getAssetAspectRatio(view, sessionState.info, aspectRatio));
|
|
77
|
+
let load: "loading" | "loaded" | "error" = $state("loading");
|
|
78
|
+
let played = $state(0);
|
|
79
|
+
let mounted = $state(false);
|
|
80
|
+
let image: HTMLImageElement | undefined = $state();
|
|
81
|
+
let media: HTMLMediaElement | undefined = $state();
|
|
82
|
+
let viewerRoot: HTMLElement | undefined = $state();
|
|
83
|
+
const failedAt = (element: HTMLMediaElement) => ({
|
|
84
|
+
position: element.currentTime || 0,
|
|
85
|
+
playing: !element.paused && !element.ended,
|
|
86
|
+
});
|
|
87
|
+
const streams = new MediaStreamPlayer((element) => {
|
|
88
|
+
session.mediaFailed(failedAt(element));
|
|
89
|
+
return true;
|
|
90
|
+
});
|
|
91
|
+
const viewers = new AssetViewerMount();
|
|
92
|
+
// The info is read once mounted, never during server rendering.
|
|
93
|
+
$effect(() => {
|
|
94
|
+
void sessionState;
|
|
95
|
+
if (mounted) session.load();
|
|
96
|
+
});
|
|
97
|
+
// A video or audio stream plays through its element, so it starts after the render.
|
|
98
|
+
$effect(() => streams.update(media, view));
|
|
99
|
+
$effect(() => {
|
|
100
|
+
void sessionState;
|
|
101
|
+
viewers.update(
|
|
102
|
+
viewerRoot,
|
|
103
|
+
isMountedViewerKind(view.kind) ? view.kind : undefined,
|
|
104
|
+
getMountedViewerOptions(options, session),
|
|
105
|
+
(viewerState) => {
|
|
106
|
+
if (viewerState !== "loading") load = viewerState;
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
onMount(() => {
|
|
111
|
+
mounted = true;
|
|
112
|
+
// An image that loaded before hydration fires no load event.
|
|
113
|
+
if (image?.complete && image.naturalWidth > 0) load = "loaded";
|
|
114
|
+
return () => {
|
|
115
|
+
streams.stop();
|
|
116
|
+
viewers.destroy();
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
$effect.pre(() => {
|
|
120
|
+
void loadKey;
|
|
121
|
+
load = "loading";
|
|
122
|
+
});
|
|
123
|
+
$effect(() => {
|
|
124
|
+
if (load === "loaded") onLoad?.();
|
|
125
|
+
if (load === "error") onError?.();
|
|
126
|
+
});
|
|
127
|
+
const availability = $derived(
|
|
128
|
+
view.kind === "unavailable"
|
|
129
|
+
? "unavailable"
|
|
130
|
+
: view.kind === "age-restricted"
|
|
131
|
+
? "age-restricted"
|
|
132
|
+
: view.kind === "pending"
|
|
133
|
+
? undefined
|
|
134
|
+
: "available",
|
|
135
|
+
);
|
|
136
|
+
$effect(() => {
|
|
137
|
+
if (availability) onAvailabilityChange?.(availability);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const onMediaError = (event: Event) => {
|
|
141
|
+
const element = event.currentTarget as HTMLMediaElement;
|
|
142
|
+
if (!streams.recover(element)) session.mediaFailed(failedAt(element));
|
|
143
|
+
};
|
|
144
|
+
const onLoadedMetadata = (event: Event) => {
|
|
145
|
+
session.mediaLoaded(event.currentTarget as HTMLMediaElement);
|
|
146
|
+
load = "loaded";
|
|
147
|
+
};
|
|
148
|
+
const onMediaTime = (event: Event) => {
|
|
149
|
+
const element = event.currentTarget as HTMLMediaElement;
|
|
150
|
+
played = getPlayedPercent(element);
|
|
151
|
+
onTimeUpdate?.(element.currentTime);
|
|
152
|
+
};
|
|
153
|
+
const onImageLoad = () => {
|
|
154
|
+
session.loaded();
|
|
155
|
+
load = "loaded";
|
|
156
|
+
};
|
|
157
|
+
const placeholderUrl = $derived(
|
|
158
|
+
"placeholderUrl" in view &&
|
|
159
|
+
(view.kind === "age-restricted" || view.kind === "pending" || load !== "loaded")
|
|
160
|
+
? view.placeholderUrl
|
|
161
|
+
: undefined,
|
|
162
|
+
);
|
|
163
|
+
const heights = $derived(view.kind === "audio" && view.peaks ? getPeakHeights(view.peaks) : []);
|
|
164
|
+
const viewerShown = $derived(isMountedViewerKind(view.kind) && mounted);
|
|
165
|
+
const controls = $derived(videoOptions?.controls ?? true);
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
{#snippet still(shown: Extract<AssetView, { kind: "image" | "website" }>)}
|
|
169
|
+
{#key loadKey}
|
|
170
|
+
<img
|
|
171
|
+
bind:this={image}
|
|
172
|
+
class="calmlens-asset__content"
|
|
173
|
+
src={shown.src}
|
|
174
|
+
srcset={shown.srcSet}
|
|
175
|
+
sizes={shown.srcSet ? imageOptions?.sizes : undefined}
|
|
176
|
+
{alt}
|
|
177
|
+
width={shown.width}
|
|
178
|
+
height={shown.height}
|
|
179
|
+
loading={lazy ? "lazy" : undefined}
|
|
180
|
+
decoding="async"
|
|
181
|
+
fetchpriority={fetchPriority}
|
|
182
|
+
onload={onImageLoad}
|
|
183
|
+
onerror={() => session.failed()}
|
|
184
|
+
/>
|
|
185
|
+
{/key}
|
|
186
|
+
{/snippet}
|
|
187
|
+
|
|
188
|
+
<figure
|
|
189
|
+
class="calmlens-asset"
|
|
190
|
+
data-kind={view.kind}
|
|
191
|
+
data-state={load}
|
|
192
|
+
data-sized={ratio ? "" : undefined}
|
|
193
|
+
aria-busy={view.kind === "pending" ? "true" : undefined}
|
|
194
|
+
style:aspect-ratio={ratio}
|
|
195
|
+
style:background-color={sessionState.info?.content?.preview?.averageColor ?? undefined}
|
|
196
|
+
style:--calmlens-fit={fit}
|
|
197
|
+
>
|
|
198
|
+
{#if placeholderUrl}
|
|
199
|
+
<img class="calmlens-asset__placeholder" src={placeholderUrl} alt="" aria-hidden="true" />
|
|
200
|
+
{/if}
|
|
201
|
+
{#if view.kind === "image"}
|
|
202
|
+
{@render still(view)}
|
|
203
|
+
{:else if view.kind === "website"}
|
|
204
|
+
{#if view.link}
|
|
205
|
+
<div class="calmlens-asset__bar">
|
|
206
|
+
<a class="calmlens-button" href={view.link} target="_blank" rel="noopener noreferrer nofollow"
|
|
207
|
+
>{formatMessage(messages.openWebsite, { host: new URL(view.link).host })}</a
|
|
208
|
+
>
|
|
209
|
+
</div>
|
|
210
|
+
{/if}
|
|
211
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
212
|
+
<!-- biome-ignore lint/a11y/noNoninteractiveTabindex: the screenshot scrolls, so keyboards must reach it -->
|
|
213
|
+
<section class="calmlens-asset__scroll" aria-label={alt || undefined} tabindex="0">
|
|
214
|
+
{@render still(view)}
|
|
215
|
+
</section>
|
|
216
|
+
{:else if view.kind === "video"}
|
|
217
|
+
<!-- svelte-ignore a11y_media_has_caption -->
|
|
218
|
+
<video
|
|
219
|
+
bind:this={media}
|
|
220
|
+
class="calmlens-asset__content"
|
|
221
|
+
src={view.stream ? undefined : view.src}
|
|
222
|
+
poster={view.poster}
|
|
223
|
+
{controls}
|
|
224
|
+
autoplay={videoOptions?.autoPlay}
|
|
225
|
+
muted={videoOptions?.muted}
|
|
226
|
+
loop={videoOptions?.loop}
|
|
227
|
+
playsinline
|
|
228
|
+
preload="metadata"
|
|
229
|
+
aria-label={alt || undefined}
|
|
230
|
+
onloadedmetadata={onLoadedMetadata}
|
|
231
|
+
onerror={onMediaError}
|
|
232
|
+
onplay={() => onPlay?.()}
|
|
233
|
+
onended={() => onEnded?.()}
|
|
234
|
+
ontimeupdate={onMediaTime}
|
|
235
|
+
></video>
|
|
236
|
+
{:else if view.kind === "audio"}
|
|
237
|
+
{#if view.waveformUrl || view.peaks}
|
|
238
|
+
<div class="calmlens-asset__waveform">
|
|
239
|
+
{#if view.waveformUrl}
|
|
240
|
+
<img class="calmlens-asset__wave" src={view.waveformUrl} alt="" aria-hidden="true" />
|
|
241
|
+
{/if}
|
|
242
|
+
{#if view.peaks}
|
|
243
|
+
<!-- Decorative: the audio element's own controls report its progress. -->
|
|
244
|
+
<div
|
|
245
|
+
class="calmlens-asset__progress"
|
|
246
|
+
role="progressbar"
|
|
247
|
+
aria-hidden="true"
|
|
248
|
+
aria-valuemin={0}
|
|
249
|
+
aria-valuemax={100}
|
|
250
|
+
aria-valuenow={played}
|
|
251
|
+
style:--calmlens-played={`${played}%`}
|
|
252
|
+
>
|
|
253
|
+
<div class="calmlens-asset__peaks">
|
|
254
|
+
{#each heights as height}<span style:height={`${height}%`}></span>{/each}
|
|
255
|
+
</div>
|
|
256
|
+
<div class="calmlens-asset__peaks" data-played="">
|
|
257
|
+
{#each heights as height}<span style:height={`${height}%`}></span>{/each}
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
{/if}
|
|
261
|
+
</div>
|
|
262
|
+
{/if}
|
|
263
|
+
<!-- biome-ignore lint/a11y/useMediaCaption: audio has no captions track to add here -->
|
|
264
|
+
<audio
|
|
265
|
+
bind:this={media}
|
|
266
|
+
class="calmlens-asset__content"
|
|
267
|
+
src={view.stream ? undefined : view.src}
|
|
268
|
+
{controls}
|
|
269
|
+
autoplay={videoOptions?.autoPlay}
|
|
270
|
+
muted={videoOptions?.muted}
|
|
271
|
+
loop={videoOptions?.loop}
|
|
272
|
+
preload="metadata"
|
|
273
|
+
aria-label={alt || undefined}
|
|
274
|
+
onloadedmetadata={onLoadedMetadata}
|
|
275
|
+
onerror={onMediaError}
|
|
276
|
+
onplay={() => onPlay?.()}
|
|
277
|
+
onended={() => onEnded?.()}
|
|
278
|
+
ontimeupdate={onMediaTime}
|
|
279
|
+
></audio>
|
|
280
|
+
{:else if viewerShown}
|
|
281
|
+
<!-- The viewer owns this element's children; Svelte renders none. -->
|
|
282
|
+
<div bind:this={viewerRoot} class="calmlens-asset__viewer"></div>
|
|
283
|
+
{:else if view.kind === "document"}
|
|
284
|
+
{#if view.still}
|
|
285
|
+
<img class="calmlens-asset__content" src={view.still} {alt} decoding="async" />
|
|
286
|
+
{/if}
|
|
287
|
+
<a class="calmlens-button calmlens-asset__open" href={view.src} target="_blank" rel="noopener noreferrer"
|
|
288
|
+
>{messages.openDocument}</a
|
|
289
|
+
>
|
|
290
|
+
{:else if view.kind === "file"}
|
|
291
|
+
<span
|
|
292
|
+
class="calmlens-asset__file"
|
|
293
|
+
role="img"
|
|
294
|
+
aria-label={alt || undefined}
|
|
295
|
+
aria-hidden={alt ? undefined : "true"}
|
|
296
|
+
>{@html renderFileIconSvg({ family: view.icon, extension: "" }, ASSET_FILE_ICON_SIZE)}</span>
|
|
297
|
+
{:else if view.kind === "age-restricted"}
|
|
298
|
+
{#if renderAgeGate}
|
|
299
|
+
{@render renderAgeGate({ placeholderUrl: view.placeholderUrl, confirm: onAgeConfirmRequest })}
|
|
300
|
+
{:else}
|
|
301
|
+
<figcaption class="calmlens-asset__notice">
|
|
302
|
+
<strong>{messages.sensitiveTitle}</strong>
|
|
303
|
+
<p>{messages.sensitiveBody}</p>
|
|
304
|
+
{#if onAgeConfirmRequest}
|
|
305
|
+
<button type="button" class="calmlens-button" onclick={onAgeConfirmRequest}>{messages.reveal}</button>
|
|
306
|
+
{/if}
|
|
307
|
+
</figcaption>
|
|
308
|
+
{/if}
|
|
309
|
+
{:else if view.kind === "unavailable"}
|
|
310
|
+
{#if renderUnavailable}
|
|
311
|
+
{@render renderUnavailable()}
|
|
312
|
+
{:else}
|
|
313
|
+
<figcaption class="calmlens-asset__notice">
|
|
314
|
+
<p><Icon name="unavailable" /><span class="calmlens-asset__label">{messages.unavailable}</span></p>
|
|
315
|
+
</figcaption>
|
|
316
|
+
{/if}
|
|
317
|
+
{/if}
|
|
318
|
+
</figure>
|