calmlens 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +15 -10
  2. package/bin/calmlens.js +1848 -679
  3. package/cjs/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
  4. package/cjs/{BrowserUpload-CjSHjx3C.js → BrowserUpload-Bwlib4Zc.js} +1 -1
  5. package/cjs/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
  6. package/cjs/{CalmLensAppClient-NaCxOVlM.js → CalmLensAppClient-DUYMo9PZ.js} +30 -10
  7. package/cjs/{CalmLensOptionKeys-p2QK687A.js → CalmLensOptionKeys-YvgV995V.js} +318 -374
  8. package/cjs/{CalmLensServerClient-BDzTthxE.js → CalmLensServerClient-3N-gdsxC.js} +346 -89
  9. package/cjs/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
  10. package/cjs/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
  11. package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
  12. package/cjs/Core-C33pkBmf.d.ts +826 -0
  13. package/cjs/Core-Cm5Z1oJ9.js +1001 -0
  14. package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
  15. package/cjs/{ModerationContextLimits-2nIv7Zh3.js → ModerationContextLimits-ud1xpZRK.js} +727 -268
  16. package/cjs/{ReactUpload-BdTRCTGA.js → ReactUpload-DQ0BYISX.js} +1 -1
  17. package/cjs/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
  18. package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
  19. package/cjs/{TestTriggers-DbhsNPdg-DjvVuc2h.js → TestTriggers-D29T_R0M-D6Bu-Mln.js} +355 -47
  20. package/cjs/{UploadController-MLVs97Zt.js → UploadController-l8fZM2qT.js} +34 -14
  21. package/{esm/WebhookPayload-DkukERKE.d.ts → cjs/WebhookPayload-Dt6DttS0.d.ts} +120 -86
  22. package/cjs/app.d.ts +6 -7
  23. package/cjs/app.js +4 -3
  24. package/cjs/elements.d.ts +123 -22
  25. package/cjs/elements.js +553 -156
  26. package/cjs/file-icons.d.ts +2 -67
  27. package/cjs/index-Bde1wjiw.d.ts +16 -0
  28. package/cjs/index.d.ts +5 -6
  29. package/cjs/index.js +3 -2
  30. package/cjs/react-native.d.ts +52 -11
  31. package/cjs/react-native.js +231 -99
  32. package/cjs/react.d.ts +42 -9
  33. package/cjs/react.js +381 -118
  34. package/cjs/server.d.ts +48 -7
  35. package/cjs/server.js +7 -3
  36. package/cjs/test-inputs.d.ts +2 -2
  37. package/cjs/test-inputs.js +13 -9
  38. package/cjs/testing.d.ts +29 -15
  39. package/cjs/testing.js +1722 -433
  40. package/cjs/ui-BRA4HQ8r.js +1359 -0
  41. package/cjs/ui-YQuvbidU.d.ts +139 -0
  42. package/cjs/ui.d.ts +3 -2
  43. package/cjs/ui.js +45 -22
  44. package/cjs/vue.d.ts +802 -199
  45. package/cjs/vue.js +359 -127
  46. package/esm/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
  47. package/esm/{BrowserUpload-CAVkRotw.js → BrowserUpload-GRZVB0G_.js} +1 -1
  48. package/esm/{CalmLensAppClient-PQ9VBvlW.js → CalmLensAppClient-B5QIJ6KS.js} +30 -10
  49. package/esm/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
  50. package/esm/{CalmLensOptionKeys-Do2mPP6w.js → CalmLensOptionKeys-BG7Qrh8-.js} +317 -367
  51. package/esm/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
  52. package/esm/{CalmLensServerClient-C_H5aAsV.js → CalmLensServerClient-bRUAebi-.js} +323 -90
  53. package/esm/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
  54. package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
  55. package/esm/Core-BvQe4moS.js +846 -0
  56. package/esm/Core-C33pkBmf.d.ts +826 -0
  57. package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
  58. package/esm/{ModerationContextLimits-Chw-AzgL.js → ModerationContextLimits-CrxSnVZ3.js} +682 -253
  59. package/esm/{ReactUpload-CMmL0R5Q.js → ReactUpload-BMO8saxT.js} +1 -1
  60. package/esm/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
  61. package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
  62. package/esm/{TestTriggers-DbhsNPdg-CUdrv8Nm.js → TestTriggers-D29T_R0M-Ztc74ucs.js} +332 -48
  63. package/esm/{UploadController-BJZghJpg.js → UploadController-DnJrWiE4.js} +34 -14
  64. package/{cjs/WebhookPayload-DkukERKE.d.ts → esm/WebhookPayload-Dt6DttS0.d.ts} +120 -86
  65. package/esm/app.d.ts +6 -7
  66. package/esm/app.js +3 -3
  67. package/esm/elements.d.ts +123 -22
  68. package/esm/elements.js +497 -128
  69. package/esm/file-icons.d.ts +2 -67
  70. package/esm/index-Bde1wjiw.d.ts +16 -0
  71. package/esm/index.d.ts +5 -6
  72. package/esm/index.js +1 -1
  73. package/esm/react-native.d.ts +52 -11
  74. package/esm/react-native.js +205 -75
  75. package/esm/react.d.ts +42 -9
  76. package/esm/react.js +327 -91
  77. package/esm/server.d.ts +48 -7
  78. package/esm/server.js +3 -3
  79. package/esm/styles.css +142 -22
  80. package/esm/svelte/AssetViewer.svelte +25 -0
  81. package/esm/svelte/CalmLensAsset.svelte +318 -0
  82. package/esm/svelte/CalmLensDocumentViewer.svelte +7 -0
  83. package/esm/svelte/CalmLensImageViewer.svelte +7 -0
  84. package/esm/svelte/CalmLensSpreadsheetViewer.svelte +7 -0
  85. package/esm/svelte/CalmLensTextViewer.svelte +7 -0
  86. package/esm/svelte/CalmLensWebsiteViewer.svelte +7 -0
  87. package/esm/svelte/index.d.ts +29 -6
  88. package/esm/svelte/index.js +7 -2
  89. package/esm/test-inputs.d.ts +2 -2
  90. package/esm/test-inputs.js +1 -1
  91. package/esm/testing.d.ts +29 -15
  92. package/esm/testing.js +1718 -429
  93. package/esm/ui-YQuvbidU.d.ts +139 -0
  94. package/esm/ui-heryDd6g.js +1258 -0
  95. package/esm/ui.d.ts +3 -2
  96. package/esm/ui.js +4 -3
  97. package/esm/vue.d.ts +802 -199
  98. package/esm/vue.js +308 -103
  99. package/package.json +4 -2
  100. package/cjs/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
  101. package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
  102. package/cjs/index-DxbJ_Xaa.d.ts +0 -253
  103. package/cjs/ui-BSqPGKrZ.d.ts +0 -539
  104. package/cjs/ui-CX1z2pD9.js +0 -586
  105. package/esm/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
  106. package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
  107. package/esm/index-DxbJ_Xaa.d.ts +0 -253
  108. package/esm/svelte/CalmLensMedia.svelte +0 -134
  109. package/esm/ui-BSqPGKrZ.d.ts +0 -539
  110. package/esm/ui-CXH7xJpb.js +0 -461
package/esm/server.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { a as selectModerationContextItems, i as ModerationContextItem, n as MODERATION_CONTEXT_USED_CHARACTERS, o as HashList, r as MODERATION_CONTEXT_USED_ITEMS, s as HashListEntry, t as ModerationContext } from "./ModerationContext-9lGm-Mna-CcmbRnOy.js";
2
- import { $ as ImageTransformOptions, $t as AssetSearchMatchField, A as CdnServeOptions, At as UploadedAsset, B as DeleteAssetContentOptions, Bt as TypedEvent, C as AssignPolicyOptions, Ct as SubmitAssetOptions, D as CalmLensServerClientOptions, Dt as UpdatePolicyOptions, E as CalmLensAppClientOptions, Et as UpdateHashListOptions, F as CreateFolderOptions, Ft as WebhookPayloadInput, G as FolderIdOptions, Gt as EventSeverity, H as EnsureLensOptions, Ht as EventFact, I as CreateHashListOptions, It as AssetBatchOperation, J as HashListEntryIdOptions, Jt as Folder, Kt as EventType, L as CreateMultipartUploadPartOptions, Lt as GetEventsResponse, M as ClassifyTextOptions, Mt as ViewerClaims, N as ConnectionOptions, Nt as WaitForAssetDecisionOptions, O as CdnAssetUrlOptions, Ot as UploadAssetPartOptions, P as CreateAssetSignedUrlOptions, Pt as WebhookHeadersInput, Q as IdempotencyOptions, Qt as LensType, R as CreatePolicyOptions, S as AssetVisibility, St as SignedUrl, T as BatchAssetsResponse, Tt as UpdateFolderOptions, U as EnsureLensesOptions, Ut as EventFactValues, V as DeleteAssetOptions, Vt as EventCategory, W as ExplainAssetOptions, Wt as EventFacts, X as HashListIdOptions, Xt as CursorPage, Y as HashListEntryPage, Yt as Policy, Z as HashListPage, Zt as Order, _ as AssetSearchResponse, _t as RetryAssetOptions, a as AssetChildrenPage, an as ExtractedText, at as ListEventsOptions, b as AssetUpload, bt as SignUploadTokenOptions, c as AssetClassificationStatus, cn as ProcessingOptions, ct as ListHashListsOptions, d as AssetContentRemovalReason, dt as MultipartUploadOptions, en as AssetSearchQuery, et as IterateAssetChildrenOptions, f as AssetContentStatus, ft as MultipartUploadPartOptions, g as AssetPage, gt as RetrieveAssetOptions, h as AssetModerationStatus, ht as RequestOptions, i as AssetChecksums, in as AssetSafetyHoldReason, it as ListAssetsOptions, j as CdnTransform, jt as VerifyWebhookSignatureOptions, k as CdnResource, kt as UploadPresetSubmitAssetOptions, l as AssetContent, lt as MoveAssetOptions, m as AssetModerationDecision, mt as PolicyList, n as ApplyPolicyPresetOptions, nn as AssetImage, nt as Lens, o as AssetClassification, on as FileMetadata, p as AssetModeration, pt as PolicyIdOptions, q as GetAssetUrlOptions, r as Asset, rn as AssetSafetyHold, rt as ListAssetChildrenOptions, s as AssetClassificationFailureReason, sn as MetadataItem, st as ListHashListEntriesOptions, t as AddHashListEntryOptions, tt as IterateAssetsOptions, u as AssetContentOptions, ut as MoveFolderOptions, v as AssetSearchResult, vt as SearchAssetsOptions, w as BatchAssetsOptions, wt as UpdateAssetOptions, x as AssetUploadStatus, xt as SignedUploadToken, y as AssetType, yt as SetPolicyAutomaticUpdatesOptions, z as DecideAssetOptions, zt as EventAsset } from "./CalmLensTypes-COJbOuiv.js";
3
- 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-DkukERKE.js";
4
- import { a as ProcessingFeatureId, c as ProcessingFeatures, d as getAssetUrl, i as DetectedPerson, l as SDK_VERSION, n as BoundingBox, o as ProcessingFeatureResults, r as DetectedFace, s as ProcessingFeatureStage, t as AgeRange, u as DEFAULT_CDN_BASE_URL } from "./index-DxbJ_Xaa.js";
5
- import { a as ClassificationNotEvaluatedReason, c as ModerationQualifier, i as ClassificationLabel, l as PolicyAction, n as ClassificationCategory, o as ClassificationQualifierResults, r as ClassificationCategoryReport, s as Likelihood, t as ClassificationCategories } from "./Classification-D3SkprrQ-CMnQKW13.js";
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 GetAssetInfoOptions, $n as FileMetadata, $t as UpgradePolicyOptions, A as CdnAssetReference, An as BoundingBox, At as MultipartUploadOptions, B as CreateMultipartUploadPartOptions, Bn as AssetSearchMatchField, Bt as SetPolicyAutomaticUpdatesOptions, C as AssetVisibility, Ct as ListHashListEntriesOptions, D as CalmLensAppClientOptions, Dn as PublicProjectSettings, Dt as ListUploadPresetsOptions, E as BatchAssetsResponse, En as ProjectSettingsResource, Et as ListPoliciesOptions, F as ClassifyTextOptions, Fn as ProcessingFeatureStage, Ft as RequestOptions, G as EnsureLensOptions, Gn as AssetHlsRendition, Gt as StreamingFeatureOptions, H as DecideAssetOptions, Ht as SignUploadTokenOptions, I as ConnectionOptions, In as ProcessingFeatures, It as ResetPolicyOptions, J as EnsureUploadPresetsOptions, Jn as AssetRendered, Jt as UpdateFolderOptions, K as EnsureLensesOptions, Kn as AssetHlsStatus, Kt as SubmitAssetOptions, L as CreateFolderOptions, Ln as Policy, Lt as RetrieveAssetOptions, M as CdnResource, Mn as DetectedPerson, Mt as PolicyIdOptions, N as CdnServeOptions, Nn as ProcessingFeatureId, Nt as PolicyPage, O as CalmLensServerClientOptions, On as UploadPreset, Ot as MoveAssetOptions, P as CdnTransform, Pn as ProcessingFeatureResults, Pt as RemoveAssetContentOptions, Q as FolderPage, Qn as ExtractedText, Qt as UpdateProjectSettingsOptions, R as CreateHashListOptions, Rn as CursorPage, Rt as RetryAssetOptions, S as AssetUploadStatus, Sn as EventType, St as ListFoldersOptions, T as BatchAssetsOptions, Tn as MetadataFieldsResource, Tt as ListLensesOptions, U as DeleteAssetOptions, Un as AssetInfo, Ut as SignedAssetUrl, V as CreatePolicyOptions, Vn as AssetSearchQuery, Vt as SignAssetUrlOptions, W as DeleteMetadataFieldOptions, Wn as AssetHls, Wt as SignedUploadToken, X as ExplainAssetOptions, Xn as AssetSafetyHold, Xt as UpdateLensOptions, Y as EnsureUploadPresetsResponse, Yn as AssetRenderedKind, Yt as UpdateHashListOptions, Z as FolderIdOptions, Zn as AssetSafetyHoldReason, Zt as UpdatePolicyOptions, _ as AssetSearchResponse, _n as EventCategory, _t as LensPage, a as AssetChildrenPage, an as UploadedAsset, at as ImageTransformOptions, b as AssetType, bn as EventFacts, bt as ListAssetsOptions, c as AssetClassificationStatus, cn as WaitForAssetDecisionOptions, ct as IterateAssetsOptions, d as AssetContentRemovalReason, dn as AssetBatchOperation, dt as IterateHashListsOptions, en as UploadAssetPartOptions, er as MetadataItem, et as HashListEntryIdOptions, f as AssetContentStatus, fn as AssetTimelineSegment, ft as IterateLensesOptions, g as AssetPage, gn as TypedEvent, gt as LensIdOptions, h as AssetModerationStatus, hn as EventAsset, ht as Lens, i as AssetChecksums, in as UploadPresetSubmitAssetOptions, it as IdempotencyOptions, j as CdnAssetUrlOptions, jn as DetectedFace, jt as MultipartUploadPartOptions, k as CdnAssetLocation, kn as AgeRange, kt as MoveFolderOptions, l as AssetContent, ln as WebhookHeadersInput, lt as IterateFoldersOptions, m as AssetModerationDecision, mt as IterateUploadPresetsOptions, n as Asset, nn as UploadPresetIdOptions, nt as HashListIdOptions, o as AssetClassification, on as VerifyWebhookSignatureOptions, ot as IterateAssetChildrenOptions, p as AssetModeration, pn as GetEventsResponse, pt as IteratePoliciesOptions, q as EnsureMetadataFieldsOptions, qn as AssetPreview, qt as UpdateAssetOptions, r as AssetAvailability, rn as UploadPresetPage, rt as HashListPage, s as AssetClassificationFailureReason, sn as ViewerClaims, st as IterateAssetTimelineOptions, t as AddHashListEntryOptions, tn as UploadPresetDefinition, tr as ProcessingOptions, tt as HashListEntryPage, u as AssetContentOptions, un as WebhookPayloadInput, ut as IterateHashListEntriesOptions, v as AssetSearchResult, vn as EventFact, vt as ListAssetChildrenOptions, w as AssignPolicyOptions, wn as Folder, wt as ListHashListsOptions, x as AssetUpload, xn as EventSeverity, xt as ListEventsOptions, y as AssetTimelinePage, yn as EventFactValues, yt as ListAssetTimelineOptions, z as CreateLensOptions, zn as LensType, zt as SearchAssetsOptions } from "./CalmLensTypes-BDKwThbO.js";
3
+ import { i as getAssetInfo, n as DEFAULT_CDN_BASE_URL, r as CDN_RESOURCES, t as SDK_VERSION } from "./index-Bde1wjiw.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-Dt6DttS0.js";
5
+ import { t as CalmLensServerClient } from "./CalmLensServerClient-BKzn8zmp.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
- export { type AddHashListEntryOptions, type AgeRange, type ApiErrorCode, type ApplyPolicyPresetOptions, type Asset, type AssetBatchOperation, type AssetChecksums, type AssetChildrenPage, type AssetClassification, type AssetClassificationFailureReason, type AssetClassificationStatus, type AssetContent, type AssetContentOptions, type AssetContentRemovalReason, type AssetContentStatus, type AssetImage, type AssetModeration, type AssetModerationDecision, type AssetModerationStatus, type AssetPage, type AssetSafetyHold, type AssetSafetyHoldReason, type AssetSearchMatchField, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetType, type AssetUpload, type AssetUploadStatus, type AssetVisibility, type AssignPolicyOptions, type BatchAssetsOptions, type BatchAssetsResponse, type BoundingBox, CALMLENS_ERROR_CODES, type CalmLensAppClientOptions, CalmLensError, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, CalmLensServerClient, type CalmLensServerClientOptions, type CdnAssetUrlOptions, type CdnResource, type CdnServeOptions, type CdnTransform, type ClassificationCategories, type ClassificationCategory, type ClassificationCategoryReport, type ClassificationLabel, type ClassificationNotEvaluatedReason, type ClassificationQualifierResults, type ClassifyTextOptions, type ConnectionOptions, type CreateAssetSignedUrlOptions, type CreateFolderOptions, type CreateHashListOptions, type CreateMultipartUploadPartOptions, type CreatePolicyOptions, type CursorPage, DEFAULT_CDN_BASE_URL, type DecideAssetOptions, type DeleteAssetContentOptions, 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 GetAssetUrlOptions, type HashList, type HashListEntry, type HashListEntryIdOptions, type HashListEntryPage, type HashListIdOptions, type HashListPage, type IdempotencyOptions, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensType, type Likelihood, type ListAssetChildrenOptions, type ListAssetsOptions, type ListEventsOptions, type ListHashListEntriesOptions, type ListHashListsOptions, 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 Order, type Policy, type PolicyAction, type PolicyIdOptions, type PolicyList, type ProcessingFeatureId, type ProcessingFeatureResults, type ProcessingFeatureStage, type ProcessingFeatures, type ProcessingOptions, type RequestOptions, type RetrieveAssetOptions, type RetryAssetOptions, SDK_VERSION, type SdkErrorCode, type SearchAssetsOptions, type SetPolicyAutomaticUpdatesOptions, type SignUploadTokenOptions, type SignedUploadToken, type SignedUrl, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UpdateHashListOptions, type UpdatePolicyOptions, type UploadAssetPartOptions, type UploadPresetSubmitAssetOptions, type UploadedAsset, type VerifyWebhookSignatureOptions, type ViewerClaims, type WaitForAssetDecisionOptions, type ReceivedWebhookEventPayload as WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput, getAssetUrl, selectModerationContextItems };
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 AssetHlsStatus, 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 DeleteMetadataFieldOptions, type DetectedFace, type DetectedPerson, type EnsureLensOptions, type EnsureLensesOptions, type EnsureMetadataFieldsOptions, type EnsureUploadPresetsOptions, type EnsureUploadPresetsResponse, 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 IterateUploadPresetsOptions, 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, type ListUploadPresetsOptions, MODERATION_CONTEXT_USED_CHARACTERS, MODERATION_CONTEXT_USED_ITEMS, type MetadataFieldsResource, 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 ProjectSettingsResource, type PublicProjectSettings, 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 UpdateProjectSettingsOptions, type UpgradePolicyOptions, type UploadAssetPartOptions, type UploadPreset, type UploadPresetDefinition, type UploadPresetIdOptions, type UploadPresetPage, 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 { M as CALMLENS_ERROR_CODES, N as CalmLensError, c as DEFAULT_CDN_BASE_URL, f as getAssetUrl, i as SDK_VERSION, n as MODERATION_CONTEXT_USED_ITEMS, r as selectModerationContextItems, t as MODERATION_CONTEXT_USED_CHARACTERS } from "./ModerationContextLimits-Chw-AzgL.js";
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-CrxSnVZ3.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 isTestWebhookEvent, r as WEBHOOK_SIGNATURE_HEADER, s as parseWebhookEvent, t as CalmLensServerClient } from "./CalmLensServerClient-C_H5aAsV.js";
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, getAssetUrl, isTestWebhookEvent, parseWebhookEvent, selectModerationContextItems, verifyWebhookSignature };
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-bRUAebi-.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-media) {
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-media * { box-sizing: border-box; }
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-media__content { transition: none; }
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-media {
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-media__placeholder, .calmlens-media__content {
119
- position: absolute; inset: 0; width: 100%; height: 100%; object-fit: var(--calmlens-fit, cover);
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-media:not([data-sized]) .calmlens-media__content { position: relative; height: auto; }
123
- .calmlens-media:not([data-sized])[data-kind="gated"], .calmlens-media:not([data-sized])[data-kind="unavailable"],
124
- .calmlens-media:not([data-sized])[data-state="error"] { min-height: 160px; }
125
- .calmlens-media__placeholder { transform: scale(1.1); filter: blur(12px); }
126
- .calmlens-media__content { opacity: 0; transition: opacity 250ms; }
127
- .calmlens-media[data-state="loaded"] .calmlens-media__content { opacity: 1; }
128
- .calmlens-media[data-kind="video"] .calmlens-media__content, .calmlens-media[data-kind="audio"] .calmlens-media__content { opacity: 1; }
129
- .calmlens-media[data-kind="audio"] { background: none; }
130
- .calmlens-media[data-kind="audio"] .calmlens-media__content { position: static; height: auto; }
131
- .calmlens-media__notice {
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-media__notice p { margin: 0; display: flex; gap: 6px; align-items: center; }
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-media[data-sized] { container-type: inline-size; }
163
+ .calmlens-asset[data-sized] { container-type: inline-size; }
138
164
  @container (max-width: 119px) {
139
- .calmlens-media__label, .calmlens-media__notice > strong, .calmlens-media__notice > p:not(:has(svg)) {
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-media__notice strong { font-weight: 600; }
144
- .calmlens-media__notice .calmlens-button { margin-top: 4px; border-color: #fff; background: #fff; color: #111; }
145
- .calmlens-media[data-state="error"] .calmlens-media__notice, .calmlens-media[data-kind="unavailable"] .calmlens-media__notice {
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>