calmlens 0.31.1 → 0.32.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/bin/calmlens.js +47 -39
- package/cjs/{BrowserUpload-BwBE37LM.js → BrowserUpload-CbbFE-2v.js} +1 -1
- package/cjs/{BrowserUpload-BAH54V1q.d.ts → BrowserUpload-Dx2l9wC0.d.ts} +2 -2
- package/cjs/{CalmLensAppClient-D6Y7MgH_.js → CalmLensAppClient-DOYOJ70t.js} +4 -4
- package/cjs/{CalmLensAppClient-CdlcDd5l.d.ts → CalmLensAppClient-v1Ho7mJQ.d.ts} +3 -3
- package/cjs/{CalmLensCdn-Q68faCEE.js → CalmLensCdn-xQMrClXN.js} +56 -22
- package/cjs/{CalmLensConnection-j2aBsuNx.js → CalmLensConnection-DbsCA8xF.js} +7 -16
- package/cjs/{CalmLensServerClient-CtS66dCU.d.ts → CalmLensServerClient-CoiZN7Fr.d.ts} +9 -9
- package/cjs/{CalmLensServerClient-CjK691kq.js → CalmLensServerClient-DtqFQgUn.js} +12 -15
- package/cjs/{CalmLensTypes-87kiUg0H.d.ts → CalmLensTypes-DjuOXp3b.d.ts} +8 -15
- package/cjs/{Core-Dsj4tRNP.js → Core-BtFJ2xfb.js} +2 -2
- package/cjs/{Core-Ccy4-_sN.d.ts → Core-DaCkaDkb.d.ts} +2 -2
- package/cjs/{ReactUpload-B7SdNAel.js → ReactUpload-CRtUXzMP.js} +1 -1
- package/cjs/{ReactUpload-DBhppuxM.d.ts → ReactUpload-DMtaeFN2.d.ts} +1 -1
- package/{esm/TestTriggers-Daxebd0V.d.ts → cjs/TestTriggers-CjDhhz78.d.ts} +1 -11
- package/cjs/{UploadController-DsIENVY1.js → UploadController-tKqKphf3.js} +1 -1
- package/cjs/{WebhookPayload-B4rA_Dvm.d.ts → WebhookPayload-C3F9j4p7.d.ts} +1 -1
- package/cjs/app.d.ts +4 -4
- package/cjs/app.js +2 -2
- package/cjs/elements.d.ts +4 -4
- package/cjs/elements.js +4 -4
- package/cjs/{index-CWUnLKoF.d.ts → index-xF6Neq8A.d.ts} +2 -2
- package/cjs/index.d.ts +3 -3
- package/cjs/index.js +1 -1
- package/cjs/react-native.d.ts +2 -2
- package/cjs/react-native.js +4 -4
- package/cjs/react.d.ts +4 -4
- package/cjs/react.js +5 -5
- package/cjs/server.d.ts +4 -4
- package/cjs/server.js +2 -2
- package/cjs/test-inputs.d.ts +15 -3
- package/cjs/test-inputs.js +105 -2
- package/cjs/testing.d.ts +14 -6
- package/cjs/testing.js +113 -50
- package/cjs/{ui-BC70R8KT.js → ui-B5tgw_En.js} +8 -8
- package/cjs/{ui-sjnJhloQ.d.ts → ui-C_AhYdIA.d.ts} +2 -2
- package/cjs/ui.d.ts +2 -2
- package/cjs/ui.js +3 -3
- package/cjs/vue.d.ts +5 -5
- package/cjs/vue.js +4 -4
- package/esm/{BrowserUpload-DSLCpWgz.js → BrowserUpload-Dizcs8rx.js} +1 -1
- package/esm/{BrowserUpload-BAH54V1q.d.ts → BrowserUpload-Dx2l9wC0.d.ts} +2 -2
- package/esm/{CalmLensAppClient-BKanqwYL.js → CalmLensAppClient-C0Ud7eYa.js} +4 -4
- package/esm/{CalmLensAppClient-CdlcDd5l.d.ts → CalmLensAppClient-v1Ho7mJQ.d.ts} +3 -3
- package/esm/{CalmLensCdn-CL1P1v2t.js → CalmLensCdn--hZgorld.js} +39 -23
- package/esm/{CalmLensConnection-CHNNULpg.js → CalmLensConnection-dz5Kl3uC.js} +7 -16
- package/esm/{CalmLensServerClient-CBjSqROz.js → CalmLensServerClient-BBPwU8mm.js} +12 -15
- package/esm/{CalmLensServerClient-CtS66dCU.d.ts → CalmLensServerClient-CoiZN7Fr.d.ts} +9 -9
- package/esm/{CalmLensTypes-87kiUg0H.d.ts → CalmLensTypes-DjuOXp3b.d.ts} +8 -15
- package/esm/{Core-Ccy4-_sN.d.ts → Core-DaCkaDkb.d.ts} +2 -2
- package/esm/{Core-WxPuobo_.js → Core-Dti4LlA-.js} +2 -2
- package/esm/{ReactUpload-U49veoZl.js → ReactUpload-Cmz063Os.js} +1 -1
- package/esm/{ReactUpload-DBhppuxM.d.ts → ReactUpload-DMtaeFN2.d.ts} +1 -1
- package/{cjs/TestTriggers-Daxebd0V.d.ts → esm/TestTriggers-CjDhhz78.d.ts} +1 -11
- package/esm/{UploadController-X2gEFMGy.js → UploadController-D3um1cq9.js} +1 -1
- package/esm/{WebhookPayload-B4rA_Dvm.d.ts → WebhookPayload-C3F9j4p7.d.ts} +1 -1
- package/esm/app.d.ts +4 -4
- package/esm/app.js +2 -2
- package/esm/elements.d.ts +4 -4
- package/esm/elements.js +4 -4
- package/esm/{index-CWUnLKoF.d.ts → index-xF6Neq8A.d.ts} +2 -2
- package/esm/index.d.ts +3 -3
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +2 -2
- package/esm/react-native.js +4 -4
- package/esm/react.d.ts +4 -4
- package/esm/react.js +5 -5
- package/esm/server.d.ts +4 -4
- package/esm/server.js +2 -2
- package/esm/test-inputs.d.ts +15 -3
- package/esm/test-inputs.js +105 -2
- package/esm/testing.d.ts +14 -6
- package/esm/testing.js +113 -50
- package/esm/{ui-DS85DGfi.js → ui-B7Z6FH5F.js} +8 -8
- package/esm/{ui-sjnJhloQ.d.ts → ui-C_AhYdIA.d.ts} +2 -2
- package/esm/ui.d.ts +2 -2
- package/esm/ui.js +3 -3
- package/esm/vue.d.ts +5 -5
- package/esm/vue.js +4 -4
- package/package.json +1 -1
package/cjs/testing.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Lt as SignUploadTokenOptions, O as CalmLensAppClientOptions, Xt as UploadPresetDefinition, bn as PermissionGrant, fn as TypedEvent, k as CalmLensServerClientOptions, m as AssetModeration, r as Asset, xn as Folder, zn as AssetBinaryPayloadInput, zt as SignedUploadToken } from "./CalmLensTypes-
|
|
2
|
-
import { t as CalmLensAppClient } from "./CalmLensAppClient-
|
|
3
|
-
import { I as ApiErrorCode, n as WebhookEventPayload } from "./WebhookPayload-
|
|
4
|
-
import { t as CalmLensServerClient } from "./CalmLensServerClient-
|
|
5
|
-
import { t as ClassificationTestSignal } from "./TestTriggers-
|
|
1
|
+
import { Lt as SignUploadTokenOptions, O as CalmLensAppClientOptions, Xt as UploadPresetDefinition, bn as PermissionGrant, fn as TypedEvent, k as CalmLensServerClientOptions, m as AssetModeration, r as Asset, xn as Folder, zn as AssetBinaryPayloadInput, zt as SignedUploadToken } from "./CalmLensTypes-DjuOXp3b.js";
|
|
2
|
+
import { t as CalmLensAppClient } from "./CalmLensAppClient-v1Ho7mJQ.js";
|
|
3
|
+
import { I as ApiErrorCode, n as WebhookEventPayload } from "./WebhookPayload-C3F9j4p7.js";
|
|
4
|
+
import { t as CalmLensServerClient } from "./CalmLensServerClient-CoiZN7Fr.js";
|
|
5
|
+
import { t as ClassificationTestSignal } from "./TestTriggers-CjDhhz78.js";
|
|
6
6
|
import "zod";
|
|
7
7
|
/**
|
|
8
8
|
* Signs a single-use upload token with `apiKey`, locally. `CalmLensServerClient` and
|
|
@@ -381,7 +381,7 @@ export declare class MockCalmLensServerClient extends CalmLensServerClient {
|
|
|
381
381
|
callsTo(operation: MockCalmLensOperation): MockCalmLensCall[];
|
|
382
382
|
/**
|
|
383
383
|
* Fetches a URL of the mock's CDN as a browser would, without the API key: a signed asset URL
|
|
384
|
-
* from `cdn.signAssetUrl
|
|
384
|
+
* from `cdn.signAssetUrl`, or a public one from `cdn.getAssetUrl`.
|
|
385
385
|
* The request is recorded like any other.
|
|
386
386
|
*/
|
|
387
387
|
fetchCdn(url: string, init?: RequestInit): Promise<Response>;
|
|
@@ -410,6 +410,14 @@ export declare class MockCalmLensServerClient extends CalmLensServerClient {
|
|
|
410
410
|
* is typed by its path's extension, and has no content.
|
|
411
411
|
*/
|
|
412
412
|
serveUrl(url: string, content: MockServedUrl): void;
|
|
413
|
+
/**
|
|
414
|
+
* Makes the mock hash an image upload of exactly `content` (bytes, or text as UTF-8) as `hash`, a
|
|
415
|
+
* PDQ hash of 64 hexadecimal characters, with `quality` (0 to 100, default 100), instead of the
|
|
416
|
+
* SHA-256 of its bytes. Hash list entries match hashes up to 31 bits away, as in CalmLens, so a
|
|
417
|
+
* test can make a resized or recompressed copy a near match of a listed image: declare the
|
|
418
|
+
* copy's hash a few bits from the entry's.
|
|
419
|
+
*/
|
|
420
|
+
setPerceptualHash(content: Uint8Array | ArrayBuffer | string, hash: string, quality?: number): void;
|
|
413
421
|
/**
|
|
414
422
|
* Changes the grants of the mock's API key, as editing the key in the portal would: later
|
|
415
423
|
* requests, such as `cdn.serve`, use them. The key itself stays the same, so idempotency keys
|
package/cjs/testing.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_CalmLensTestInputArguments = require("./CalmLensTestInputArguments-PYuRmE0j.js");
|
|
3
3
|
const require_CalmLensError = require("./CalmLensError-ifj5rLmk.js");
|
|
4
|
-
const require_CalmLensCdn = require("./CalmLensCdn-
|
|
5
|
-
const require_CalmLensServerClient = require("./CalmLensServerClient-
|
|
6
|
-
const require_CalmLensConnection = require("./CalmLensConnection-
|
|
4
|
+
const require_CalmLensCdn = require("./CalmLensCdn-xQMrClXN.js");
|
|
5
|
+
const require_CalmLensServerClient = require("./CalmLensServerClient-DtqFQgUn.js");
|
|
6
|
+
const require_CalmLensConnection = require("./CalmLensConnection-DbsCA8xF.js");
|
|
7
7
|
const require_CryptoUtils_BLCa_oZe = require("./CryptoUtils-BLCa-oZe-leCkr1ko.js");
|
|
8
|
-
const require_CalmLensAppClient = require("./CalmLensAppClient-
|
|
9
|
-
const require_UploadController = require("./UploadController-
|
|
8
|
+
const require_CalmLensAppClient = require("./CalmLensAppClient-DOYOJ70t.js");
|
|
9
|
+
const require_UploadController = require("./UploadController-tKqKphf3.js");
|
|
10
10
|
let zod = require("zod");
|
|
11
11
|
let zod$1 = require_CalmLensTestInputArguments.__toESM(zod, 1);
|
|
12
12
|
zod = require_CalmLensTestInputArguments.__toESM(zod);
|
|
@@ -8703,20 +8703,6 @@ const MOCK_ASSET_FILTER_FIELDS = {
|
|
|
8703
8703
|
"=out="
|
|
8704
8704
|
]
|
|
8705
8705
|
},
|
|
8706
|
-
description: {
|
|
8707
|
-
kind: "text",
|
|
8708
|
-
nullable: true,
|
|
8709
|
-
operators: [
|
|
8710
|
-
"==",
|
|
8711
|
-
"!=",
|
|
8712
|
-
">",
|
|
8713
|
-
">=",
|
|
8714
|
-
"<",
|
|
8715
|
-
"<=",
|
|
8716
|
-
"=in=",
|
|
8717
|
-
"=out="
|
|
8718
|
-
]
|
|
8719
|
-
},
|
|
8720
8706
|
externalId: {
|
|
8721
8707
|
kind: "text",
|
|
8722
8708
|
nullable: true,
|
|
@@ -9235,17 +9221,20 @@ const filterAssets = (items, filter) => {
|
|
|
9235
9221
|
return items.filter((item) => matchesNode(item, node));
|
|
9236
9222
|
};
|
|
9237
9223
|
const MAX_SEARCH_TOKENS = 8;
|
|
9238
|
-
/**
|
|
9239
|
-
|
|
9224
|
+
/**
|
|
9225
|
+
* The keyword fields the API searches, in the order it reports matches. `extractedText` is the
|
|
9226
|
+
* asset's retained text: empty unless its content is stored.
|
|
9227
|
+
*/
|
|
9228
|
+
const searchFieldValues = (asset, extractedText) => [
|
|
9240
9229
|
["name", asset.name],
|
|
9241
9230
|
["id", asset.id],
|
|
9242
9231
|
["externalId", asset.externalId ?? ""],
|
|
9243
|
-
["description", asset.description ?? ""],
|
|
9244
9232
|
["tags", asset.tags?.join(" ") ?? ""],
|
|
9245
9233
|
["type", asset.type],
|
|
9246
9234
|
["content.format", asset.content?.format ?? ""],
|
|
9247
9235
|
["content.extension", asset.content?.extension ?? ""],
|
|
9248
|
-
["classification.moderation.decision", asset.classification.moderation.decision ?? "pending"]
|
|
9236
|
+
["classification.moderation.decision", asset.classification.moderation.decision ?? "pending"],
|
|
9237
|
+
["content.extractedText", extractedText]
|
|
9249
9238
|
];
|
|
9250
9239
|
/** The API's keyword score for the whole lowercased query. */
|
|
9251
9240
|
const keywordScore = (values, query) => {
|
|
@@ -9264,15 +9253,15 @@ const keywordScore = (values, query) => {
|
|
|
9264
9253
|
};
|
|
9265
9254
|
/**
|
|
9266
9255
|
* Keyword search as the API runs it: every whitespace-separated token (case-insensitive, at
|
|
9267
|
-
* most 8) must appear in some searchable field
|
|
9268
|
-
* newest first.
|
|
9256
|
+
* most 8) must appear in some searchable field, including the asset's retained text, which
|
|
9257
|
+
* `extractedTexts` maps by asset ID. Results are ranked by the API's score, then newest first.
|
|
9269
9258
|
*/
|
|
9270
|
-
const searchAssets = (assets, query, limit) => {
|
|
9259
|
+
const searchAssets = (assets, extractedTexts, query, limit) => {
|
|
9271
9260
|
const normalized = query.trim().toLowerCase();
|
|
9272
9261
|
const tokens = [...new Set(normalized.split(/\s+/).filter(Boolean))].slice(0, MAX_SEARCH_TOKENS);
|
|
9273
9262
|
if (tokens.length === 0) return [];
|
|
9274
9263
|
return assets.map((asset) => {
|
|
9275
|
-
const fields = searchFieldValues(asset).map(([field, value]) => [field, value.toLowerCase()]);
|
|
9264
|
+
const fields = searchFieldValues(asset, extractedTexts.get(asset.id) ?? "").map(([field, value]) => [field, value.toLowerCase()]);
|
|
9276
9265
|
return {
|
|
9277
9266
|
asset,
|
|
9278
9267
|
matches: tokens.every((token) => fields.some(([, value]) => value.includes(token))),
|
|
@@ -9382,8 +9371,12 @@ const checkMockUploadPreset = (preset) => {
|
|
|
9382
9371
|
if (unknown.length) throw require_CalmLensError.invalidArgument(`Unknown mockOptions.preset key${unknown.length > 1 ? "s" : ""}: ${unknown.join(", ")}`, { options: unknown });
|
|
9383
9372
|
};
|
|
9384
9373
|
const MAX_PAGE_SIZE = 100;
|
|
9385
|
-
/**
|
|
9374
|
+
/** Hashes with a lower PDQ quality never match (HashList.ts, HASH_MATCH_MIN_QUALITY). */
|
|
9386
9375
|
const HASH_MATCH_MIN_QUALITY = 50;
|
|
9376
|
+
/** Hashes this many bits apart or fewer match (HashList.ts, HASH_MATCH_MAX_DISTANCE). */
|
|
9377
|
+
const HASH_MATCH_MAX_DISTANCE = 31;
|
|
9378
|
+
/** A block list blocks only matches this close; looser ones are flagged (HASH_BLOCK_MAX_DISTANCE). */
|
|
9379
|
+
const HASH_BLOCK_MAX_DISTANCE = 16;
|
|
9387
9380
|
/** The most hash matches an asset records (HashList.ts). */
|
|
9388
9381
|
const MAX_RECORDED_HASH_MATCHES = 10;
|
|
9389
9382
|
const MAX_DECISION_NOTE_LENGTH = 1499;
|
|
@@ -9628,7 +9621,6 @@ const invalidField = (code, path) => new ApiFailure(400, require_CalmLensError.A
|
|
|
9628
9621
|
/** The asset fields an upload carries in its body; the API refuses them in the query string. */
|
|
9629
9622
|
const UPLOAD_OPTION_KEYS = [
|
|
9630
9623
|
"name",
|
|
9631
|
-
"description",
|
|
9632
9624
|
"processingOptions",
|
|
9633
9625
|
"visibility",
|
|
9634
9626
|
"metadata",
|
|
@@ -9867,6 +9859,7 @@ var MockCalmLensApi = class {
|
|
|
9867
9859
|
this.idempotentResults = /* @__PURE__ */ new Map();
|
|
9868
9860
|
this.pendingFailures = [];
|
|
9869
9861
|
this.servedUrls = /* @__PURE__ */ new Map();
|
|
9862
|
+
this.perceptualHashes = [];
|
|
9870
9863
|
this.pendingReviews = /* @__PURE__ */ new Map();
|
|
9871
9864
|
this.requestCount = 0;
|
|
9872
9865
|
this.useTimers = false;
|
|
@@ -9931,6 +9924,24 @@ var MockCalmLensApi = class {
|
|
|
9931
9924
|
type: type.trim()
|
|
9932
9925
|
});
|
|
9933
9926
|
}
|
|
9927
|
+
/**
|
|
9928
|
+
* Makes an image upload of exactly `content` hash as `hash` (64 hexadecimal characters, a PDQ
|
|
9929
|
+
* hash) with `quality`, instead of the SHA-256 of its bytes.
|
|
9930
|
+
*/
|
|
9931
|
+
setPerceptualHash(content, hash, quality = 100) {
|
|
9932
|
+
const bytes = typeof content === "string" ? new TextEncoder().encode(content) : content instanceof ArrayBuffer ? new Uint8Array(content.slice(0)) : content instanceof Uint8Array ? new Uint8Array(content) : void 0;
|
|
9933
|
+
if (!bytes) throw require_CalmLensError.invalidArgument("content must be bytes or a string");
|
|
9934
|
+
if (typeof hash !== "string" || !/^[0-9a-f]{64}$/i.test(hash.trim())) throw require_CalmLensError.invalidArgument("hash must be a PDQ hash of 64 hexadecimal characters");
|
|
9935
|
+
if (typeof quality !== "number" || !Number.isInteger(quality) || quality < 0 || quality > 100) throw require_CalmLensError.invalidArgument("quality must be a whole number from 0 to 100");
|
|
9936
|
+
const declared = {
|
|
9937
|
+
bytes,
|
|
9938
|
+
hash: hash.trim().toLowerCase(),
|
|
9939
|
+
quality
|
|
9940
|
+
};
|
|
9941
|
+
const index = this.perceptualHashes.findIndex((known) => sameBytes(known.bytes, bytes));
|
|
9942
|
+
if (index === -1) this.perceptualHashes.push(declared);
|
|
9943
|
+
else this.perceptualHashes[index] = declared;
|
|
9944
|
+
}
|
|
9934
9945
|
/** A `fetch` that answers a client's requests from memory; app clients pass their session. */
|
|
9935
9946
|
createFetch(endpoints, session) {
|
|
9936
9947
|
return ((input, init) => this.handle(input, init, endpoints(), session));
|
|
@@ -10736,8 +10747,9 @@ var MockCalmLensApi = class {
|
|
|
10736
10747
|
}
|
|
10737
10748
|
/**
|
|
10738
10749
|
* Keyword search like the API's: every whitespace-separated token must appear,
|
|
10739
|
-
* case-insensitively, in the asset's name, ID, external ID,
|
|
10740
|
-
*
|
|
10750
|
+
* case-insensitively, in the asset's name, ID, external ID, tags, type, content format or
|
|
10751
|
+
* extension, moderation status, or retained text while its content is stored. There is no
|
|
10752
|
+
* semantic search.
|
|
10741
10753
|
*/
|
|
10742
10754
|
async searchAssets(params) {
|
|
10743
10755
|
const query = (params.get("query") ?? "").trim();
|
|
@@ -10746,9 +10758,11 @@ var MockCalmLensApi = class {
|
|
|
10746
10758
|
const pageSize = this.integer(params, "pageSize", 10);
|
|
10747
10759
|
if (pageSize < 1) throw invalidField("validation/too-small", "pageSize");
|
|
10748
10760
|
if (pageSize > MAX_SEARCH_PAGE_SIZE) throw invalidField("validation/too-big", "pageSize");
|
|
10761
|
+
const assets = await this.databaseStorage.listAssets(this.projectId);
|
|
10762
|
+
const extractedTexts = new Map(await Promise.all(assets.map(async (asset) => [asset.id, await this.searchText(asset)])));
|
|
10749
10763
|
return {
|
|
10750
10764
|
query,
|
|
10751
|
-
items: searchAssets(
|
|
10765
|
+
items: searchAssets(assets, extractedTexts, query, pageSize),
|
|
10752
10766
|
semanticStatus: "disabled"
|
|
10753
10767
|
};
|
|
10754
10768
|
}
|
|
@@ -11091,7 +11105,6 @@ var MockCalmLensApi = class {
|
|
|
11091
11105
|
createdAt: now,
|
|
11092
11106
|
updatedAt: now,
|
|
11093
11107
|
name: fields.name,
|
|
11094
|
-
description: fields.description ?? null,
|
|
11095
11108
|
externalId: fields.externalId ?? null,
|
|
11096
11109
|
externalUrl: fields.url ?? fields.externalUrl ?? null,
|
|
11097
11110
|
type,
|
|
@@ -11288,10 +11301,19 @@ var MockCalmLensApi = class {
|
|
|
11288
11301
|
}
|
|
11289
11302
|
/** An earlier post's text, to the most CalmLens reads of one post; empty once its content is gone. */
|
|
11290
11303
|
async contextText(asset) {
|
|
11304
|
+
const text = (await this.retainedText(asset)).trim();
|
|
11305
|
+
return Array.from(text).slice(0, MODERATION_CONTEXT_MAX_ITEM_CHARACTERS).join("");
|
|
11306
|
+
}
|
|
11307
|
+
/** The text keyword search reads, like the API: the retained text, only while content is stored. */
|
|
11308
|
+
async searchText(asset) {
|
|
11309
|
+
return asset.content.status === "stored" ? this.retainedText(asset) : "";
|
|
11310
|
+
}
|
|
11311
|
+
/** A text upload's stored bytes, or the text extracted from its content (such as OCR). */
|
|
11312
|
+
async retainedText(asset) {
|
|
11291
11313
|
const extracted = asset.content.extractedText;
|
|
11292
11314
|
const bytes = asset.type === "plaintext-document" && await this.storedBytes(asset);
|
|
11293
|
-
|
|
11294
|
-
return
|
|
11315
|
+
if (bytes) return new TextDecoder().decode(bytes);
|
|
11316
|
+
return extracted?.type === "string" ? extracted.content : "";
|
|
11295
11317
|
}
|
|
11296
11318
|
async storedBytes(asset) {
|
|
11297
11319
|
if (asset.content.status === "removed") return null;
|
|
@@ -11302,28 +11324,40 @@ var MockCalmLensApi = class {
|
|
|
11302
11324
|
}
|
|
11303
11325
|
/**
|
|
11304
11326
|
* A decided image with its hash and the project's hash list matches, as the API records them
|
|
11305
|
-
* (AssetClassification.ts,
|
|
11327
|
+
* (AssetClassification.ts, HashMatching.ts and HashList.ts). The mock computes no PDQ hash: an
|
|
11306
11328
|
* image's `content.perceptualHash` is the SHA-256 of its bytes in lowercase hex, with quality
|
|
11307
|
-
* 100,
|
|
11308
|
-
*
|
|
11309
|
-
*
|
|
11310
|
-
*
|
|
11329
|
+
* 100, unless `setPerceptualHash` declared one for those bytes. An entry matches a hash up to 31
|
|
11330
|
+
* bits away, so different images' SHA-256 stand-ins never match, and an entry taken from an
|
|
11331
|
+
* image matches the same bytes at distance 0. Hashes below quality 50 never match. A match takes
|
|
11332
|
+
* its list's action, except that a block list only flags matches more than 16 bits away;
|
|
11333
|
+
* blocking matches come first, then the closest. A block raises an allowed, limited or
|
|
11334
|
+
* age-restricted decision to `blocked`, with `source: "hash-list"`, and a flag only records the
|
|
11335
|
+
* match.
|
|
11311
11336
|
*/
|
|
11312
11337
|
async withHashMatches(asset, bytes) {
|
|
11313
|
-
const hash
|
|
11314
|
-
|
|
11315
|
-
|
|
11316
|
-
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11338
|
+
const { hash, quality } = this.perceptualHashes.find((known) => sameBytes(known.bytes, bytes)) ?? {
|
|
11339
|
+
hash: await sha256Hex(bytes),
|
|
11340
|
+
quality: 100
|
|
11341
|
+
};
|
|
11342
|
+
const matches = [...this.hashListEntries.values()].flatMap((entry) => {
|
|
11343
|
+
const list = this.hashLists.get(entry.hashListId);
|
|
11344
|
+
const distance = hashDistance(hash, entry.hash);
|
|
11345
|
+
if (!list || quality < HASH_MATCH_MIN_QUALITY || entry.quality !== null && entry.quality < HASH_MATCH_MIN_QUALITY || distance > HASH_MATCH_MAX_DISTANCE) return [];
|
|
11346
|
+
const action = list.action === "block" && distance <= HASH_BLOCK_MAX_DISTANCE ? "block" : "flag";
|
|
11347
|
+
return [{
|
|
11348
|
+
source: "hash-list",
|
|
11349
|
+
hashListId: entry.hashListId,
|
|
11350
|
+
hashListEntryId: entry.id,
|
|
11351
|
+
distance,
|
|
11352
|
+
action
|
|
11353
|
+
}];
|
|
11354
|
+
}).sort((a, b) => Number(b.action === "block") - Number(a.action === "block") || a.distance - b.distance).slice(0, MAX_RECORDED_HASH_MATCHES);
|
|
11321
11355
|
const hashed = {
|
|
11322
11356
|
...asset,
|
|
11323
11357
|
content: {
|
|
11324
11358
|
...asset.content,
|
|
11325
11359
|
perceptualHash: hash,
|
|
11326
|
-
perceptualHashQuality:
|
|
11360
|
+
perceptualHashQuality: quality
|
|
11327
11361
|
}
|
|
11328
11362
|
};
|
|
11329
11363
|
if (!matches.length) return hashed;
|
|
@@ -12246,6 +12280,25 @@ var MockCalmLensApi = class {
|
|
|
12246
12280
|
});
|
|
12247
12281
|
}
|
|
12248
12282
|
};
|
|
12283
|
+
/** The SHA-256 of `bytes` in lowercase hex. */
|
|
12284
|
+
async function sha256Hex(bytes) {
|
|
12285
|
+
return [...new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
12286
|
+
}
|
|
12287
|
+
/** How many bits two 64-character hex hashes differ by. */
|
|
12288
|
+
function hashDistance(a, b) {
|
|
12289
|
+
let distance = 0;
|
|
12290
|
+
for (let i = 0; i < 64; i += 8) {
|
|
12291
|
+
let bits = (Number.parseInt(a.slice(i, i + 8), 16) ^ Number.parseInt(b.slice(i, i + 8), 16)) >>> 0;
|
|
12292
|
+
while (bits) {
|
|
12293
|
+
bits &= bits - 1;
|
|
12294
|
+
distance++;
|
|
12295
|
+
}
|
|
12296
|
+
}
|
|
12297
|
+
return distance;
|
|
12298
|
+
}
|
|
12299
|
+
function sameBytes(a, b) {
|
|
12300
|
+
return a.length === b.length && a.every((byte, i) => byte === b[i]);
|
|
12301
|
+
}
|
|
12249
12302
|
// src/testing/MockStorage.ts
|
|
12250
12303
|
var InMemoryMockImageStorage = class {
|
|
12251
12304
|
constructor() {
|
|
@@ -12431,7 +12484,7 @@ var MockCalmLensServerClient = class extends require_CalmLensServerClient.CalmLe
|
|
|
12431
12484
|
}
|
|
12432
12485
|
/**
|
|
12433
12486
|
* Fetches a URL of the mock's CDN as a browser would, without the API key: a signed asset URL
|
|
12434
|
-
* from `cdn.signAssetUrl
|
|
12487
|
+
* from `cdn.signAssetUrl`, or a public one from `cdn.getAssetUrl`.
|
|
12435
12488
|
* The request is recorded like any other.
|
|
12436
12489
|
*/
|
|
12437
12490
|
fetchCdn(url, init) {
|
|
@@ -12477,6 +12530,16 @@ var MockCalmLensServerClient = class extends require_CalmLensServerClient.CalmLe
|
|
|
12477
12530
|
this.#api.serveUrl(url, content);
|
|
12478
12531
|
}
|
|
12479
12532
|
/**
|
|
12533
|
+
* Makes the mock hash an image upload of exactly `content` (bytes, or text as UTF-8) as `hash`, a
|
|
12534
|
+
* PDQ hash of 64 hexadecimal characters, with `quality` (0 to 100, default 100), instead of the
|
|
12535
|
+
* SHA-256 of its bytes. Hash list entries match hashes up to 31 bits away, as in CalmLens, so a
|
|
12536
|
+
* test can make a resized or recompressed copy a near match of a listed image: declare the
|
|
12537
|
+
* copy's hash a few bits from the entry's.
|
|
12538
|
+
*/
|
|
12539
|
+
setPerceptualHash(content, hash, quality = 100) {
|
|
12540
|
+
this.#api.setPerceptualHash(content, hash, quality);
|
|
12541
|
+
}
|
|
12542
|
+
/**
|
|
12480
12543
|
* Changes the grants of the mock's API key, as editing the key in the portal would: later
|
|
12481
12544
|
* requests, such as `cdn.serve`, use them. The key itself stays the same, so idempotency keys
|
|
12482
12545
|
* it used still replay.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_CalmLensCdn = require("./CalmLensCdn-
|
|
2
|
-
require("./Core-
|
|
1
|
+
const require_CalmLensCdn = require("./CalmLensCdn-xQMrClXN.js");
|
|
2
|
+
require("./Core-BtFJ2xfb.js");
|
|
3
3
|
// src/ui/viewers/PdfLoader.ts
|
|
4
4
|
let loading;
|
|
5
5
|
/**
|
|
@@ -81,11 +81,11 @@ const responseCode = async (response) => {
|
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
/**
|
|
84
|
-
* The CDN URLs a viewer loads: resource paths beneath the asset URL
|
|
85
|
-
* with the viewer claims that say something. When a URL
|
|
86
|
-
* signed one does, it asks `onExpired` once for a fresh
|
|
87
|
-
* has worked (`loaded`), so a URL that keeps failing ends in the
|
|
88
|
-
* `onExpired` nothing is refreshed.
|
|
84
|
+
* The CDN URLs a viewer loads: resource paths beneath the asset URL of `src` (a public or signed
|
|
85
|
+
* asset URL, or a resource URL beneath one), with the viewer claims that say something. When a URL
|
|
86
|
+
* stops working (`refresh`), as an expired signed one does, it asks `onExpired` once for a fresh
|
|
87
|
+
* URL, and again only after that one has worked (`loaded`), so a URL that keeps failing ends in the
|
|
88
|
+
* viewer's fallback. Without `onExpired` nothing is refreshed.
|
|
89
89
|
*/
|
|
90
90
|
var ViewerUrls = class {
|
|
91
91
|
#options;
|
|
@@ -112,7 +112,7 @@ var ViewerUrls = class {
|
|
|
112
112
|
/** A resource's URL beneath the asset URL. The placeholder is never age-gated, so it needs no age claim. */
|
|
113
113
|
url(resource, transform) {
|
|
114
114
|
const { viewerClaims } = this.#options;
|
|
115
|
-
return require_CalmLensCdn.appendAssetLocation(this.#src, {
|
|
115
|
+
return require_CalmLensCdn.appendAssetLocation(require_CalmLensCdn.assetUrlOf(this.#src), {
|
|
116
116
|
resource,
|
|
117
117
|
transform,
|
|
118
118
|
viewerClaims: resource === "placeholder" && viewerClaims ? { region: viewerClaims.region } : viewerClaims
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./CalmLensTypes-
|
|
2
|
-
import { K as AssetOptions, Z as AssetView, ct as DocumentViewerOptions, dt as TextViewerOptions, lt as PdfAssetOptions, pt as ViewerOptions, q as AssetSession, ut as SpreadsheetViewerOptions } from "./Core-
|
|
1
|
+
import "./CalmLensTypes-DjuOXp3b.js";
|
|
2
|
+
import { K as AssetOptions, Z as AssetView, ct as DocumentViewerOptions, dt as TextViewerOptions, lt as PdfAssetOptions, pt as ViewerOptions, q as AssetSession, ut as SpreadsheetViewerOptions } from "./Core-DaCkaDkb.js";
|
|
3
3
|
import "pdfjs-dist";
|
|
4
4
|
/** A viewer mounted into an element, which it owns the children of. */
|
|
5
5
|
interface AssetViewer<O extends ViewerOptions = ViewerOptions> {
|
package/cjs/ui.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as MediaPlayback, A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadFile, G as AssetImageSource, H as AssetDisplay, I as UploadItem, J as AssetSessionState, K as AssetOptions, L as UploadSnapshot, M as UploadClient, N as UploadController, O as CalmLensProvidedOptions, P as UploadControllerOptions, Q as INSTANT_LOAD_MS, R as UploadStage, S as formatBytes, T as getUploadItemMessage, U as AssetDocumentOptions, V as withProvidedOptions, W as AssetImageOptions, X as AssetVideoOptions, Y as AssetSpreadsheetOptions, Z as AssetView, _ as DEFAULT_MESSAGES, _t as DEFAULT_VIEWER_MESSAGES, a as ProgressFetchOptions, at as isImageReady, b as describeUploadItem, bt as resolveViewerMessages, c as ICON_ATTRIBUTES, ct as DocumentViewerOptions, d as AssetDisplayOptions, dt as TextViewerOptions, et as getAssetAspectRatio, f as AssetEventHandlers, ft as ViewerAsset, g as CalmLensMessages, gt as isSpreadsheetFormat, h as UploaderProps, ht as getAssetViewerKind, i as CALMLENS_STYLES, it as getPlayedPercent, j as CustomUploadResult, k as CalmLensUpload, l as IconName, lt as PdfAssetOptions, m as UploaderDisplayOptions, mt as ViewerTextOptions, n as CalmLensTheme, nt as getAssetViewKey, o as createProgressFetch, ot as pickAssetSource, p as AssetProps, pt as ViewerOptions, q as AssetSession, r as resolveTheme, rt as getPeakHeights, s as ICONS, st as AssetViewerKind, t as CALMLENS_THEME, tt as getAssetView, u as ASSET_FILE_ICON_SIZE, ut as SpreadsheetViewerOptions, v as UploadItemView, vt as ViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, yt as formatViewerMessage, z as createUploadController } from "./Core-
|
|
2
|
-
import { _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as AssetViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as ViewerState, y as createDocumentViewer } from "./ui-
|
|
1
|
+
import { $ as MediaPlayback, A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadFile, G as AssetImageSource, H as AssetDisplay, I as UploadItem, J as AssetSessionState, K as AssetOptions, L as UploadSnapshot, M as UploadClient, N as UploadController, O as CalmLensProvidedOptions, P as UploadControllerOptions, Q as INSTANT_LOAD_MS, R as UploadStage, S as formatBytes, T as getUploadItemMessage, U as AssetDocumentOptions, V as withProvidedOptions, W as AssetImageOptions, X as AssetVideoOptions, Y as AssetSpreadsheetOptions, Z as AssetView, _ as DEFAULT_MESSAGES, _t as DEFAULT_VIEWER_MESSAGES, a as ProgressFetchOptions, at as isImageReady, b as describeUploadItem, bt as resolveViewerMessages, c as ICON_ATTRIBUTES, ct as DocumentViewerOptions, d as AssetDisplayOptions, dt as TextViewerOptions, et as getAssetAspectRatio, f as AssetEventHandlers, ft as ViewerAsset, g as CalmLensMessages, gt as isSpreadsheetFormat, h as UploaderProps, ht as getAssetViewerKind, i as CALMLENS_STYLES, it as getPlayedPercent, j as CustomUploadResult, k as CalmLensUpload, l as IconName, lt as PdfAssetOptions, m as UploaderDisplayOptions, mt as ViewerTextOptions, n as CalmLensTheme, nt as getAssetViewKey, o as createProgressFetch, ot as pickAssetSource, p as AssetProps, pt as ViewerOptions, q as AssetSession, r as resolveTheme, rt as getPeakHeights, s as ICONS, st as AssetViewerKind, t as CALMLENS_THEME, tt as getAssetView, u as ASSET_FILE_ICON_SIZE, ut as SpreadsheetViewerOptions, v as UploadItemView, vt as ViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, yt as formatViewerMessage, z as createUploadController } from "./Core-DaCkaDkb.js";
|
|
2
|
+
import { _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as AssetViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as ViewerState, y as createDocumentViewer } from "./ui-C_AhYdIA.js";
|
|
3
3
|
export { ASSET_FILE_ICON_SIZE, ASSET_VIEWERS, type AssetDisplay, type AssetDisplayOptions, type AssetDocumentOptions, type AssetEventHandlers, type AssetImageOptions, type AssetImageSource, type AssetOptions, type AssetProps, AssetSession, type AssetSessionState, type AssetSpreadsheetOptions, type AssetVideoOptions, type AssetView, type AssetViewer, type AssetViewerKind, AssetViewerMount, AssetViewerName, AssetViewerOptionsByKind, CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensProvidedOptions, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, DEFAULT_VIEWER_MESSAGES, type DocumentViewerOptions, ICONS, ICON_ATTRIBUTES, INSTANT_LOAD_MS, type IconName, type MediaPlayback, MediaStreamPlayer, type MountedViewerKind, type PdfAssetOptions, type ProgressFetchOptions, type SpreadsheetCell, type SpreadsheetRow, type SpreadsheetSheet, type SpreadsheetViewerOptions, type TextViewerOptions, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, VIEWER_STYLES, type ViewerAsset, type ViewerMessages, type ViewerOptions, type ViewerState, type ViewerTextOptions, createDocumentViewer, createProgressFetch, createSpreadsheetViewer, createTextViewer, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, formatViewerMessage, getAssetAspectRatio, getAssetView, getAssetViewKey, getAssetViewerKind, getDropzoneHint, getMountedViewerOptions, getPeakHeights, getPlayedPercent, getSpreadsheetPage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, isImageReady, isMountedViewerKind, isSpreadsheetFormat, loadPdfJs, parseSpreadsheetText, pickAssetSource, resolveMessages, resolveTheme, resolveViewerMessages, spreadsheetColumnIndex, withProvidedOptions };
|
package/cjs/ui.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_ui = require("./ui-
|
|
3
|
-
const require_Core = require("./Core-
|
|
4
|
-
const require_UploadController = require("./UploadController-
|
|
2
|
+
const require_ui = require("./ui-B5tgw_En.js");
|
|
3
|
+
const require_Core = require("./Core-BtFJ2xfb.js");
|
|
4
|
+
const require_UploadController = require("./UploadController-tKqKphf3.js");
|
|
5
5
|
exports.ASSET_FILE_ICON_SIZE = require_Core.ASSET_FILE_ICON_SIZE;
|
|
6
6
|
exports.ASSET_VIEWERS = require_ui.ASSET_VIEWERS;
|
|
7
7
|
exports.AssetSession = require_Core.AssetSession;
|
package/cjs/vue.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { O as CalmLensAppClientOptions, g as AssetModerationStatus, i as AssetAvailability, nn as ViewerClaims } from "./CalmLensTypes-
|
|
2
|
-
import "./index-
|
|
3
|
-
import { $ as MediaPlayback, A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadFile, G as AssetImageSource, H as AssetDisplay, J as AssetSessionState, K as AssetOptions, M as UploadClient, N as UploadController, O as CalmLensProvidedOptions, Q as INSTANT_LOAD_MS, R as UploadStage, S as formatBytes, T as getUploadItemMessage, U as AssetDocumentOptions, V as withProvidedOptions, W as AssetImageOptions, X as AssetVideoOptions, Y as AssetSpreadsheetOptions, Z as AssetView, _ as DEFAULT_MESSAGES, _t as DEFAULT_VIEWER_MESSAGES, a as ProgressFetchOptions, at as isImageReady, b as describeUploadItem, bt as resolveViewerMessages, c as ICON_ATTRIBUTES, ct as DocumentViewerOptions, d as AssetDisplayOptions, dt as TextViewerOptions, et as getAssetAspectRatio, f as AssetEventHandlers, ft as ViewerAsset, g as CalmLensMessages, gt as isSpreadsheetFormat, ht as getAssetViewerKind, i as CALMLENS_STYLES, it as getPlayedPercent, j as CustomUploadResult, l as IconName, lt as PdfAssetOptions, m as UploaderDisplayOptions, mt as ViewerTextOptions, n as CalmLensTheme, nt as getAssetViewKey, o as createProgressFetch, ot as pickAssetSource, p as AssetProps, pt as ViewerOptions, q as AssetSession, r as resolveTheme, rt as getPeakHeights, s as ICONS, st as AssetViewerKind, t as CALMLENS_THEME, tt as getAssetView, u as ASSET_FILE_ICON_SIZE, ut as SpreadsheetViewerOptions, v as UploadItemView, vt as ViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, yt as formatViewerMessage } from "./Core-
|
|
4
|
-
import { a as UploaderProps, i as UploadSnapshot, n as UploadControllerOptions, r as UploadItem, s as createUploadController, t as CalmLensUpload } from "./BrowserUpload-
|
|
5
|
-
import { _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as AssetViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as ViewerState, y as createDocumentViewer } from "./ui-
|
|
1
|
+
import { O as CalmLensAppClientOptions, g as AssetModerationStatus, i as AssetAvailability, nn as ViewerClaims } from "./CalmLensTypes-DjuOXp3b.js";
|
|
2
|
+
import "./index-xF6Neq8A.js";
|
|
3
|
+
import { $ as MediaPlayback, A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadFile, G as AssetImageSource, H as AssetDisplay, J as AssetSessionState, K as AssetOptions, M as UploadClient, N as UploadController, O as CalmLensProvidedOptions, Q as INSTANT_LOAD_MS, R as UploadStage, S as formatBytes, T as getUploadItemMessage, U as AssetDocumentOptions, V as withProvidedOptions, W as AssetImageOptions, X as AssetVideoOptions, Y as AssetSpreadsheetOptions, Z as AssetView, _ as DEFAULT_MESSAGES, _t as DEFAULT_VIEWER_MESSAGES, a as ProgressFetchOptions, at as isImageReady, b as describeUploadItem, bt as resolveViewerMessages, c as ICON_ATTRIBUTES, ct as DocumentViewerOptions, d as AssetDisplayOptions, dt as TextViewerOptions, et as getAssetAspectRatio, f as AssetEventHandlers, ft as ViewerAsset, g as CalmLensMessages, gt as isSpreadsheetFormat, ht as getAssetViewerKind, i as CALMLENS_STYLES, it as getPlayedPercent, j as CustomUploadResult, l as IconName, lt as PdfAssetOptions, m as UploaderDisplayOptions, mt as ViewerTextOptions, n as CalmLensTheme, nt as getAssetViewKey, o as createProgressFetch, ot as pickAssetSource, p as AssetProps, pt as ViewerOptions, q as AssetSession, r as resolveTheme, rt as getPeakHeights, s as ICONS, st as AssetViewerKind, t as CALMLENS_THEME, tt as getAssetView, u as ASSET_FILE_ICON_SIZE, ut as SpreadsheetViewerOptions, v as UploadItemView, vt as ViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, yt as formatViewerMessage } from "./Core-DaCkaDkb.js";
|
|
4
|
+
import { a as UploaderProps, i as UploadSnapshot, n as UploadControllerOptions, r as UploadItem, s as createUploadController, t as CalmLensUpload } from "./BrowserUpload-Dx2l9wC0.js";
|
|
5
|
+
import { _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as AssetViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as ViewerState, y as createDocumentViewer } from "./ui-C_AhYdIA.js";
|
|
6
6
|
import { App, MaybeRefOrGetter, PropType, ShallowRef } from "vue";
|
|
7
7
|
/** Shows a text asset's text, escaped, in a scrolling region. */
|
|
8
8
|
export declare const CalmLensTextViewer: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
package/cjs/vue.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_ui = require("./ui-
|
|
3
|
-
const require_Core = require("./Core-
|
|
4
|
-
const require_UploadController = require("./UploadController-
|
|
2
|
+
const require_ui = require("./ui-B5tgw_En.js");
|
|
3
|
+
const require_Core = require("./Core-BtFJ2xfb.js");
|
|
4
|
+
const require_UploadController = require("./UploadController-tKqKphf3.js");
|
|
5
5
|
const require_FileIcons = require("./FileIcons-Ob003MdS.js");
|
|
6
|
-
const require_BrowserUpload = require("./BrowserUpload-
|
|
6
|
+
const require_BrowserUpload = require("./BrowserUpload-CbbFE-2v.js");
|
|
7
7
|
let vue = require("vue");
|
|
8
8
|
// src/viewers/Vue.ts
|
|
9
9
|
const optional$1 = (type) => ({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createUploadController$1 } from "./UploadController-
|
|
1
|
+
import { n as createUploadController$1 } from "./UploadController-D3um1cq9.js";
|
|
2
2
|
// src/ui/BrowserUpload.ts
|
|
3
3
|
/** Creates an upload queue for the browser components, such as one a form starts on submit. */
|
|
4
4
|
const createUploadController = (options) => createUploadController$1(options);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as UploadFile, I as UploadItem$1, L as UploadSnapshot$1, N as UploadController, P as UploadControllerOptions$1, h as UploaderProps$1, k as CalmLensUpload$1 } from "./Core-
|
|
2
|
-
import { r as UseCalmLensUploadResult$1 } from "./ReactUpload-
|
|
1
|
+
import { F as UploadFile, I as UploadItem$1, L as UploadSnapshot$1, N as UploadController, P as UploadControllerOptions$1, h as UploaderProps$1, k as CalmLensUpload$1 } from "./Core-DaCkaDkb.js";
|
|
2
|
+
import { r as UseCalmLensUploadResult$1 } from "./ReactUpload-DMtaeFN2.js";
|
|
3
3
|
type UploadItem<F extends UploadFile = File> = UploadItem$1<F>;
|
|
4
4
|
type CalmLensUpload<F extends UploadFile = File> = CalmLensUpload$1<F>;
|
|
5
5
|
type UploadSnapshot<F extends UploadFile = File> = UploadSnapshot$1<F>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as invalidConfig, S as invalidArgument } from "./CalmLensError-C15tWu8W.js";
|
|
2
|
-
import { S as validateAppClientOptions, d as checkOptionKeys, o as buildAssetUrl, p as encodePathSegment, u as DEFAULT_CDN_BASE_URL } from "./CalmLensCdn
|
|
3
|
-
import { c as prepareSubmitAssetOptions, f as APP_OPTION_KEYS, i as expectUploadedAsset, l as resolveConnectionOptions, t as CalmLensConnection, u as splitsIntoParts } from "./CalmLensConnection-
|
|
2
|
+
import { S as validateAppClientOptions, d as checkOptionKeys, o as buildAssetUrl, p as encodePathSegment, u as DEFAULT_CDN_BASE_URL } from "./CalmLensCdn--hZgorld.js";
|
|
3
|
+
import { c as prepareSubmitAssetOptions, f as APP_OPTION_KEYS, i as expectUploadedAsset, l as resolveConnectionOptions, t as CalmLensConnection, u as splitsIntoParts } from "./CalmLensConnection-dz5Kl3uC.js";
|
|
4
4
|
// src/client/CalmLensAppClient.ts
|
|
5
5
|
const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
6
6
|
/** `options`, once `checkOptionKeys` finds only keys `operation` takes. */
|
|
@@ -85,8 +85,8 @@ var CalmLensAppClient = class {
|
|
|
85
85
|
get cdn() {
|
|
86
86
|
return {
|
|
87
87
|
/**
|
|
88
|
-
* Builds a public asset's CDN URL: the
|
|
89
|
-
*
|
|
88
|
+
* Builds a public asset's CDN URL: the URL of `resource` (`rendered` unless one is given),
|
|
89
|
+
* with its lens or transform and the viewer claims. Private assets need a URL your
|
|
90
90
|
* server signs with `cdn.signAssetUrl`. The project is the client's `projectId` unless the
|
|
91
91
|
* call names one.
|
|
92
92
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $t as UploadPresetSubmitAssetOptions, M as CdnAssetUrlOptions, Mt as RetrieveAssetOptions, O as CalmLensAppClientOptions, Yt as UploadAssetPartOptions, en as UploadedAsset, kt as RequestOptions } from "./CalmLensTypes-
|
|
1
|
+
import { $t as UploadPresetSubmitAssetOptions, M as CdnAssetUrlOptions, Mt as RetrieveAssetOptions, O as CalmLensAppClientOptions, Yt as UploadAssetPartOptions, en as UploadedAsset, kt as RequestOptions } from "./CalmLensTypes-DjuOXp3b.js";
|
|
2
2
|
declare const inspectSymbol: unique symbol;
|
|
3
3
|
/**
|
|
4
4
|
* The CalmLens client for browsers and React Native apps. It uploads through an upload preset,
|
|
@@ -25,8 +25,8 @@ declare class CalmLensAppClient {
|
|
|
25
25
|
/** Public asset URLs, built without a request. */
|
|
26
26
|
get cdn(): {
|
|
27
27
|
/**
|
|
28
|
-
* Builds a public asset's CDN URL: the
|
|
29
|
-
*
|
|
28
|
+
* Builds a public asset's CDN URL: the URL of `resource` (`rendered` unless one is given),
|
|
29
|
+
* with its lens or transform and the viewer claims. Private assets need a URL your
|
|
30
30
|
* server signs with `cdn.signAssetUrl`. The project is the client's `projectId` unless the
|
|
31
31
|
* call names one.
|
|
32
32
|
*/
|
|
@@ -152,7 +152,7 @@ const listPages = (fetchPage, { cursor, feed = false } = {}) => {
|
|
|
152
152
|
};
|
|
153
153
|
// src/client/CalmLensVersion.ts
|
|
154
154
|
/** This SDK's version, from its package.json. */
|
|
155
|
-
const SDK_VERSION = "0.
|
|
155
|
+
const SDK_VERSION = "0.32.0";
|
|
156
156
|
const runtimeName = () => {
|
|
157
157
|
const runtime = globalThis;
|
|
158
158
|
if (isReactNativeRuntime()) return "react-native";
|
|
@@ -536,7 +536,7 @@ var CalmLensTransport = class {
|
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
538
|
};
|
|
539
|
-
// src/contract/SharedConstants-
|
|
539
|
+
// src/contract/SharedConstants-CxzZSxDw.js
|
|
540
540
|
const IMPERSONATION_COOKIE_NAME = "CL_impersonation";
|
|
541
541
|
const DAY_MS = 864e5;
|
|
542
542
|
const YEAR_MS = 365 * DAY_MS;
|
|
@@ -745,6 +745,13 @@ const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
|
745
745
|
const MAX_DIRECT_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
746
746
|
const MAX_NON_IMAGE_UPLOAD_MB = 5e3;
|
|
747
747
|
const MAX_NON_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => MAX_NON_IMAGE_UPLOAD_MB * 1024 * 1024)();
|
|
748
|
+
/** PDFs: read in ranges of pages past `LONG_DOCUMENT_MIN_BYTES`, below the 4 GiB PDFium reads by range. */
|
|
749
|
+
const MAX_PDF_UPLOAD_BYTES = /* @__PURE__ */ (() => 2097152e3)();
|
|
750
|
+
/**
|
|
751
|
+
* Documents other than PDFs (Word, spreadsheets, presentations, OpenDocument and the formats
|
|
752
|
+
* LibreOffice converts): read whole, as the document processor reads at most this much.
|
|
753
|
+
*/
|
|
754
|
+
const MAX_OTHER_DOCUMENT_UPLOAD_BYTES = /* @__PURE__ */ (() => 52428800)();
|
|
748
755
|
const normalizeUploadMimeType = (mimeType) => mimeType.toLowerCase().split(";")[0]?.trim() || mimeType.toLowerCase().trim();
|
|
749
756
|
const getRejectedUploadMimeTypeError = (mimeType) => `${normalizeUploadMimeType(mimeType)} is not a valid upload file type. Uploads must use a concrete file MIME type that CalmLens can store and process, such as image/png, image/jpeg, application/pdf, or text/plain.`;
|
|
750
757
|
const DOMAIN = "calmlens.com";
|
|
@@ -924,6 +931,22 @@ const UPLOAD_MIME_TYPES = [
|
|
|
924
931
|
"application/xml",
|
|
925
932
|
"application/yaml"
|
|
926
933
|
];
|
|
934
|
+
const UPLOAD_MIME_DOCUMENTS = [
|
|
935
|
+
"application/pdf",
|
|
936
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
937
|
+
"application/vnd.ms-word.document.macroenabled.12",
|
|
938
|
+
"application/msword",
|
|
939
|
+
"application/rtf",
|
|
940
|
+
"application/vnd.oasis.opendocument.text",
|
|
941
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
942
|
+
"application/vnd.ms-excel.sheet.macroenabled.12",
|
|
943
|
+
"application/vnd.ms-excel",
|
|
944
|
+
"application/vnd.oasis.opendocument.spreadsheet",
|
|
945
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
946
|
+
"application/vnd.ms-powerpoint.presentation.macroenabled.12",
|
|
947
|
+
"application/vnd.ms-powerpoint",
|
|
948
|
+
"application/vnd.oasis.opendocument.presentation"
|
|
949
|
+
];
|
|
927
950
|
// src/client/CalmLensUtils.ts
|
|
928
951
|
const assertHttpUrl = (name, value) => {
|
|
929
952
|
if (value === void 0) return;
|
|
@@ -1367,35 +1390,28 @@ const viewerClaimsQuery = (claims) => {
|
|
|
1367
1390
|
return sent ? `?${new URLSearchParams({ viewerClaims: JSON.stringify(sent) })}` : "";
|
|
1368
1391
|
};
|
|
1369
1392
|
/**
|
|
1370
|
-
* Appends a resource, its `@lens` and transform selector, and the
|
|
1371
|
-
*
|
|
1393
|
+
* Appends a resource (`rendered` unless one is given), its `@lens` and transform selector, and the
|
|
1394
|
+
* viewer claims to an asset URL (public or signed).
|
|
1372
1395
|
*/
|
|
1373
1396
|
const appendAssetLocation = (assetUrl, location) => {
|
|
1374
|
-
const { resource, lens, transform, viewerClaims } = location;
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
if (UNSELECTABLE.has(resource) && selected) throw invalidArgument(`The ${resource} resource takes no lens or transform`);
|
|
1382
|
-
path = `${assetUrl}/${ASSET_RESOURCE_PATHS[resource]}`;
|
|
1383
|
-
const selector = transformSelector(transform);
|
|
1384
|
-
const parts = [...lens !== void 0 ? [`@${encodePathSegment(lens, "Lens")}`] : [], ...selector ? [typeof transform === "string" ? encodeURI(selector) : selector] : []];
|
|
1385
|
-
if (parts.length) path = `${path}/${parts.join(",")}`;
|
|
1386
|
-
}
|
|
1387
|
-
return `${path}${viewerClaimsQuery(viewerClaims)}`;
|
|
1397
|
+
const { resource = "rendered", lens, transform, viewerClaims } = location;
|
|
1398
|
+
if (typeof resource !== "string" || !Object.hasOwn(ASSET_RESOURCE_PATHS, resource)) throw invalidArgument(`resource must be one of ${CDN_RESOURCES.join(", ")}`);
|
|
1399
|
+
if (UNSELECTABLE.has(resource) && (lens !== void 0 || transform !== void 0)) throw invalidArgument(`The ${resource} resource takes no lens or transform`);
|
|
1400
|
+
const selector = transformSelector(transform);
|
|
1401
|
+
const parts = [...lens !== void 0 ? [`@${encodePathSegment(lens, "Lens")}`] : [], ...selector ? [typeof transform === "string" ? encodeURI(selector) : selector] : []];
|
|
1402
|
+
const path = `${assetUrl}/${ASSET_RESOURCE_PATHS[resource]}`;
|
|
1403
|
+
return `${parts.length ? `${path}/${parts.join(",")}` : path}${viewerClaimsQuery(viewerClaims)}`;
|
|
1388
1404
|
};
|
|
1389
1405
|
/**
|
|
1390
|
-
* The lens, transform and viewer claims added to a URL the API signed for `location.resource
|
|
1391
|
-
* which already ends in that resource.
|
|
1406
|
+
* The lens, transform and viewer claims added to a URL the API signed for `location.resource`
|
|
1407
|
+
* (`rendered` unless one is given), which already ends in that resource.
|
|
1392
1408
|
*/
|
|
1393
1409
|
const appendSignedLocation = (signedUrl, location) => {
|
|
1394
|
-
const resourcePath = location.resource
|
|
1410
|
+
const resourcePath = `/${ASSET_RESOURCE_PATHS[location.resource ?? "rendered"]}`;
|
|
1395
1411
|
if (!signedUrl.endsWith(resourcePath)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The signed asset URL doesn't end in the resource it was signed for" });
|
|
1396
1412
|
return `${signedUrl}${appendAssetLocation("", location).slice(resourcePath.length)}`;
|
|
1397
1413
|
};
|
|
1398
|
-
/** An asset's public URL beneath a CDN base URL, with any
|
|
1414
|
+
/** An asset's public resource URL beneath a CDN base URL, with any selector and claims. */
|
|
1399
1415
|
const buildAssetUrl = (cdnBaseUrl, projectId, options) => {
|
|
1400
1416
|
const { assetId, externalId, resource, lens, transform, viewerClaims } = options;
|
|
1401
1417
|
const base = `${cdnBaseUrl.replace(/\/+$/, "")}/assets/${encodePathSegment(projectId, "Project ID")}/${getAssetSegment({
|
|
@@ -1483,4 +1499,4 @@ const getAssetInfo = async (url, options = {}) => {
|
|
|
1483
1499
|
});
|
|
1484
1500
|
return data;
|
|
1485
1501
|
};
|
|
1486
|
-
export {
|
|
1502
|
+
export { MAX_OTHER_DOCUMENT_UPLOAD_BYTES as A, copyLastResponse as B, validateBatchAssetsOptions as C, MAX_DIRECT_IMAGE_UPLOAD_BYTES as D, DOMAIN as E, sleep as F, readEnv as H, SDK_VERSION as I, isBrowserRuntime as L, getRejectedUploadMimeTypeError as M, normalizeUploadMimeType as N, MAX_IMAGE_UPLOAD_BYTES as O, CalmLensTransport as P, isReactNativeRuntime as R, validateAppClientOptions as S, UPLOAD_MIME_DOCUMENTS as T, resolveLogLevel as U, listPages as V, randomUuid as _, assetUrlOf as a, toTextAssetOptions as b, toUrlViewerClaims as c, checkOptionKeys as d, checkTransformOptions as f, pollForDecision as g, parseTransformSelector as h, appendSignedLocation as i, MAX_PDF_UPLOAD_BYTES as j, MAX_NON_IMAGE_UPLOAD_BYTES as k, validateSignAssetUrlOptions as l, isAcceptedUploadMimeType as m, CDN_RESOURCES as n, buildAssetUrl as o, encodePathSegment as p, appendAssetLocation as r, getAssetInfo as s, ASSET_RESOURCE_PATHS as t, DEFAULT_CDN_BASE_URL as u, serializeTransform as v, validateServerClientOptions as w, transformSelector as x, stringifyQuery as y, AUTO_PAGING_TO_ARRAY_MAX as z };
|