calmlens 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -10
- package/bin/calmlens.js +1848 -679
- package/cjs/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/cjs/{BrowserUpload-CjSHjx3C.js → BrowserUpload-Bwlib4Zc.js} +1 -1
- package/cjs/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/cjs/{CalmLensAppClient-NaCxOVlM.js → CalmLensAppClient-DUYMo9PZ.js} +30 -10
- package/cjs/{CalmLensOptionKeys-p2QK687A.js → CalmLensOptionKeys-YvgV995V.js} +318 -374
- package/cjs/{CalmLensServerClient-BDzTthxE.js → CalmLensServerClient-3N-gdsxC.js} +346 -89
- package/cjs/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/cjs/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/cjs/Core-C33pkBmf.d.ts +826 -0
- package/cjs/Core-Cm5Z1oJ9.js +1001 -0
- package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
- package/cjs/{ModerationContextLimits-2nIv7Zh3.js → ModerationContextLimits-ud1xpZRK.js} +727 -268
- package/cjs/{ReactUpload-BdTRCTGA.js → ReactUpload-DQ0BYISX.js} +1 -1
- package/cjs/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/cjs/{TestTriggers-DbhsNPdg-DjvVuc2h.js → TestTriggers-D29T_R0M-D6Bu-Mln.js} +355 -47
- package/cjs/{UploadController-MLVs97Zt.js → UploadController-l8fZM2qT.js} +34 -14
- package/{esm/WebhookPayload-DkukERKE.d.ts → cjs/WebhookPayload-Dt6DttS0.d.ts} +120 -86
- package/cjs/app.d.ts +6 -7
- package/cjs/app.js +4 -3
- package/cjs/elements.d.ts +123 -22
- package/cjs/elements.js +553 -156
- package/cjs/file-icons.d.ts +2 -67
- package/cjs/index-Bde1wjiw.d.ts +16 -0
- package/cjs/index.d.ts +5 -6
- package/cjs/index.js +3 -2
- package/cjs/react-native.d.ts +52 -11
- package/cjs/react-native.js +231 -99
- package/cjs/react.d.ts +42 -9
- package/cjs/react.js +381 -118
- package/cjs/server.d.ts +48 -7
- package/cjs/server.js +7 -3
- package/cjs/test-inputs.d.ts +2 -2
- package/cjs/test-inputs.js +13 -9
- package/cjs/testing.d.ts +29 -15
- package/cjs/testing.js +1722 -433
- package/cjs/ui-BRA4HQ8r.js +1359 -0
- package/cjs/ui-YQuvbidU.d.ts +139 -0
- package/cjs/ui.d.ts +3 -2
- package/cjs/ui.js +45 -22
- package/cjs/vue.d.ts +802 -199
- package/cjs/vue.js +359 -127
- package/esm/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/esm/{BrowserUpload-CAVkRotw.js → BrowserUpload-GRZVB0G_.js} +1 -1
- package/esm/{CalmLensAppClient-PQ9VBvlW.js → CalmLensAppClient-B5QIJ6KS.js} +30 -10
- package/esm/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/esm/{CalmLensOptionKeys-Do2mPP6w.js → CalmLensOptionKeys-BG7Qrh8-.js} +317 -367
- package/esm/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/esm/{CalmLensServerClient-C_H5aAsV.js → CalmLensServerClient-bRUAebi-.js} +323 -90
- package/esm/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/esm/Core-BvQe4moS.js +846 -0
- package/esm/Core-C33pkBmf.d.ts +826 -0
- package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
- package/esm/{ModerationContextLimits-Chw-AzgL.js → ModerationContextLimits-CrxSnVZ3.js} +682 -253
- package/esm/{ReactUpload-CMmL0R5Q.js → ReactUpload-BMO8saxT.js} +1 -1
- package/esm/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/esm/{TestTriggers-DbhsNPdg-CUdrv8Nm.js → TestTriggers-D29T_R0M-Ztc74ucs.js} +332 -48
- package/esm/{UploadController-BJZghJpg.js → UploadController-DnJrWiE4.js} +34 -14
- package/{cjs/WebhookPayload-DkukERKE.d.ts → esm/WebhookPayload-Dt6DttS0.d.ts} +120 -86
- package/esm/app.d.ts +6 -7
- package/esm/app.js +3 -3
- package/esm/elements.d.ts +123 -22
- package/esm/elements.js +497 -128
- package/esm/file-icons.d.ts +2 -67
- package/esm/index-Bde1wjiw.d.ts +16 -0
- package/esm/index.d.ts +5 -6
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +52 -11
- package/esm/react-native.js +205 -75
- package/esm/react.d.ts +42 -9
- package/esm/react.js +327 -91
- package/esm/server.d.ts +48 -7
- package/esm/server.js +3 -3
- package/esm/styles.css +142 -22
- package/esm/svelte/AssetViewer.svelte +25 -0
- package/esm/svelte/CalmLensAsset.svelte +318 -0
- package/esm/svelte/CalmLensDocumentViewer.svelte +7 -0
- package/esm/svelte/CalmLensImageViewer.svelte +7 -0
- package/esm/svelte/CalmLensSpreadsheetViewer.svelte +7 -0
- package/esm/svelte/CalmLensTextViewer.svelte +7 -0
- package/esm/svelte/CalmLensWebsiteViewer.svelte +7 -0
- package/esm/svelte/index.d.ts +29 -6
- package/esm/svelte/index.js +7 -2
- package/esm/test-inputs.d.ts +2 -2
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +29 -15
- package/esm/testing.js +1718 -429
- package/esm/ui-YQuvbidU.d.ts +139 -0
- package/esm/ui-heryDd6g.js +1258 -0
- package/esm/ui.d.ts +3 -2
- package/esm/ui.js +4 -3
- package/esm/vue.d.ts +802 -199
- package/esm/vue.js +308 -103
- package/package.json +4 -2
- package/cjs/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/cjs/index-DxbJ_Xaa.d.ts +0 -253
- package/cjs/ui-BSqPGKrZ.d.ts +0 -539
- package/cjs/ui-CX1z2pD9.js +0 -586
- package/esm/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/esm/index-DxbJ_Xaa.d.ts +0 -253
- package/esm/svelte/CalmLensMedia.svelte +0 -134
- package/esm/ui-BSqPGKrZ.d.ts +0 -539
- package/esm/ui-CXH7xJpb.js +0 -461
|
@@ -11,66 +11,66 @@ const CLASSIFICATION_CATEGORIES = [
|
|
|
11
11
|
"personal-information",
|
|
12
12
|
"profanity"
|
|
13
13
|
];
|
|
14
|
-
// src/contract/Jurisdiction-
|
|
14
|
+
// src/contract/Jurisdiction-LWQvqyxL.js
|
|
15
15
|
/**
|
|
16
|
-
* Jurisdictions with legal rules always apply to every project. An
|
|
17
|
-
* standard rather than a legal floor
|
|
16
|
+
* Jurisdictions with legal rules always apply to every project. An optional jurisdiction is a
|
|
17
|
+
* product standard rather than a legal floor: every project serves it unless it opts out.
|
|
18
18
|
*/
|
|
19
19
|
const JURISDICTIONS = {
|
|
20
20
|
global: {
|
|
21
21
|
name: "Global",
|
|
22
22
|
ageCheckStandard: "any",
|
|
23
|
-
|
|
23
|
+
optional: false
|
|
24
24
|
},
|
|
25
25
|
DE: {
|
|
26
26
|
name: "Germany",
|
|
27
27
|
ageCheckStandard: "any",
|
|
28
|
-
|
|
28
|
+
optional: false
|
|
29
29
|
},
|
|
30
30
|
AT: {
|
|
31
31
|
name: "Austria",
|
|
32
32
|
ageCheckStandard: "any",
|
|
33
|
-
|
|
33
|
+
optional: false
|
|
34
34
|
},
|
|
35
35
|
FR: {
|
|
36
36
|
name: "France",
|
|
37
37
|
ageCheckStandard: "any",
|
|
38
|
-
|
|
38
|
+
optional: false
|
|
39
39
|
},
|
|
40
40
|
GB: {
|
|
41
41
|
name: "United Kingdom",
|
|
42
42
|
ageCheckStandard: "verified",
|
|
43
|
-
|
|
43
|
+
optional: false
|
|
44
44
|
},
|
|
45
45
|
EU: {
|
|
46
46
|
name: "European Union",
|
|
47
47
|
ageCheckStandard: "verified",
|
|
48
|
-
|
|
48
|
+
optional: true
|
|
49
49
|
},
|
|
50
50
|
AU: {
|
|
51
51
|
name: "Australia",
|
|
52
52
|
ageCheckStandard: "verified",
|
|
53
|
-
|
|
53
|
+
optional: false
|
|
54
54
|
},
|
|
55
55
|
BR: {
|
|
56
56
|
name: "Brazil",
|
|
57
57
|
ageCheckStandard: "verified",
|
|
58
|
-
|
|
58
|
+
optional: false
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
const JURISDICTION_SCHEMA = z.enum(Object.keys(JURISDICTIONS));
|
|
62
|
-
Object.keys(JURISDICTIONS).filter((code) => !JURISDICTIONS[code].
|
|
63
|
-
const
|
|
64
|
-
z.enum(
|
|
62
|
+
Object.keys(JURISDICTIONS).filter((code) => !JURISDICTIONS[code].optional);
|
|
63
|
+
const OPTIONAL_JURISDICTIONS = Object.keys(JURISDICTIONS).filter((code) => JURISDICTIONS[code].optional);
|
|
64
|
+
z.enum(OPTIONAL_JURISDICTIONS).array().refine((codes) => new Set(codes).size === codes.length, { message: "jurisdiction/duplicate" });
|
|
65
65
|
JURISDICTION_SCHEMA.array().min(1).refine((regions) => regions.includes("global") && new Set(regions).size === regions.length, { message: "jurisdiction/global-required-or-duplicate" });
|
|
66
66
|
const COUNTRIES = new Set("AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW".split(" "));
|
|
67
67
|
const VIEWER_REGION_SCHEMA = z.enum([...COUNTRIES]).describe("Viewer's ISO 3166-1 alpha-2 country, supplied by your integration; not the proxy server's country. EU is not a viewer country.");
|
|
68
68
|
new Set("AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE".split(" "));
|
|
69
69
|
z.object({
|
|
70
70
|
region: VIEWER_REGION_SCHEMA.optional().describe("Viewer country. Defaults to the country of the connection reaching CalmLens; proxies should forward the viewer country explicitly."),
|
|
71
|
-
ageConfirmed: z.boolean().optional().describe("Your platform's confirmation that the viewer passed its age check, so age-restricted content may be delivered. Defaults to false. Your platform confirms the viewer's age; CalmLens does not verify this claim. Anyone requesting
|
|
71
|
+
ageConfirmed: z.boolean().optional().describe("Your platform's confirmation that the viewer passed its age check, so age-restricted content may be delivered. Defaults to false. Your platform confirms the viewer's age; CalmLens does not verify this claim. Anyone requesting an asset's URL, public or signed, can set it: a signed URL's signature does not cover viewer claims, so the claim is not an access control. To restrict who can load an age-restricted asset, make it private and issue signed URLs only to viewers who passed your age check.")
|
|
72
72
|
}).strict();
|
|
73
|
-
// src/contract/TestRegionalActions-
|
|
73
|
+
// src/contract/TestRegionalActions-C2mw3ntb.js
|
|
74
74
|
/**
|
|
75
75
|
* Marks English text in shared, backend and data modules that the portal shows, so the app's
|
|
76
76
|
* message catalog (packages/app/vite/messageCatalog.ts) extracts it and the portal can translate it
|
|
@@ -373,6 +373,24 @@ const MODERATION_QUALIFIER_INFO = {
|
|
|
373
373
|
description: msg("Pornographic content showing or describing sex with an animal or with a dead body, or a sexual act that threatens a person's life or is likely to cause serious injury to the anus, breasts or genitals, including realistic drawn or generated depictions."),
|
|
374
374
|
exclusions: "Consensual adult content without such an act, including bondage, role play or rough play; non-sexual images of animals, death or injury; reports, education, support or discussion that present no such material."
|
|
375
375
|
},
|
|
376
|
+
"sexual-strangulation": {
|
|
377
|
+
category: "sexual",
|
|
378
|
+
kind: "harm",
|
|
379
|
+
harmOption: false,
|
|
380
|
+
displayName: msg("Pornographic strangulation or suffocation"),
|
|
381
|
+
description: msg("A pornographic image or video frame showing a person strangling, choking or suffocating another: pressure on the neck from a hand, arm or ligature, or breathing blocked by covering the mouth and nose, smothering or compressing the chest. Realistic staged, generated or computer-made depictions count."),
|
|
382
|
+
exclusions: "A person alone in the image holding their own throat or miming being choked; a hand resting on the shoulder, jaw or chest without gripping the throat; collars and choker jewellery; oral sex, including gagging, without breathing deliberately held off; non-sexual violence, combat sport or medical images; drawings or animation that don't look real; reports, education or support that show no such image.",
|
|
383
|
+
inputs: ["image"]
|
|
384
|
+
},
|
|
385
|
+
"sexual-incest": {
|
|
386
|
+
category: "sexual",
|
|
387
|
+
kind: "harm",
|
|
388
|
+
harmOption: false,
|
|
389
|
+
displayName: msg("Pornographic incest"),
|
|
390
|
+
description: msg("A pornographic image or video frame showing sexual activity between people who are, or are presented as, related as parent, grandparent, child, grandchild, brother, sister, half-brother, half-sister, uncle, aunt, nephew or niece, including by adoption. The relationship can be shown by the image or by its caption, title, dialogue or other accompanying text. Realistic staged, generated or computer-made depictions count."),
|
|
391
|
+
exclusions: "Step, foster and in-law relationships between adults; a family word that is plainly a nickname or fanciful, such as daddy between adult partners; drawings or animation that don't look real; non-sexual family images; reports or discussion that show no such image. Someone presented as under 18 is Sexualised minors.",
|
|
392
|
+
inputs: ["image"]
|
|
393
|
+
},
|
|
376
394
|
"sexual-minors": {
|
|
377
395
|
category: "sexual",
|
|
378
396
|
kind: "harm",
|
|
@@ -1076,7 +1094,7 @@ const TEST_REGIONAL_ACTIONS_SCHEMA = z.array(z.object({
|
|
|
1076
1094
|
"block"
|
|
1077
1095
|
])
|
|
1078
1096
|
}).strict()).max(7).refine((entries) => new Set(entries.map((entry) => entry.region)).size === entries.length, "Choose each region once");
|
|
1079
|
-
// src/contract/TestTriggers-
|
|
1097
|
+
// src/contract/TestTriggers-D29T_R0M.js
|
|
1080
1098
|
/**
|
|
1081
1099
|
* The visual encoding of test images (shared by images and video frames), independent of what the
|
|
1082
1100
|
* bytes mean. An odd N×N grid of square cells fills the image. Its outer ring alternates black and
|
|
@@ -1323,7 +1341,8 @@ function paintTestImageGrid(data, palette = [TEST_IMAGE_GRID_NEUTRAL]) {
|
|
|
1323
1341
|
/**
|
|
1324
1342
|
* Reads the bytes a grid carries, or undefined when the image holds no readable grid. The grid
|
|
1325
1343
|
* may be scaled (also unevenly) and surrounded by a uniform border, such as video letterboxing.
|
|
1326
|
-
* Cost is bounded by sampling, not by the image size, so every video frame can be checked.
|
|
1344
|
+
* Cost is bounded by sampling, not by the image size, so every video frame can be checked. Reading
|
|
1345
|
+
* only samples cells: `matchesTestImageGrid` checks that nothing else is in the image.
|
|
1327
1346
|
*/
|
|
1328
1347
|
function readTestImageGrid({ width, height, rgba }) {
|
|
1329
1348
|
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 30 || height < 30 || rgba.length !== width * height * 4) return;
|
|
@@ -1379,8 +1398,93 @@ function readTestImageGrid({ width, height, rgba }) {
|
|
|
1379
1398
|
let position = 0;
|
|
1380
1399
|
for (let i = 0; i < Math.max(...lengths); i++) for (const codeword of codewords) if (i < codeword.length) codeword[i] = stream[position++];
|
|
1381
1400
|
if (!codewords.every(rsDecode)) continue;
|
|
1382
|
-
return
|
|
1401
|
+
return {
|
|
1402
|
+
data: new Uint8Array(codewords.flatMap((codeword) => [...codeword.subarray(0, codeword.length - 32)])),
|
|
1403
|
+
cells,
|
|
1404
|
+
left,
|
|
1405
|
+
top,
|
|
1406
|
+
gridWidth,
|
|
1407
|
+
gridHeight
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
/** BT.601 full-range Y, Cb and Cr, as JPEG and WebP store colour. */
|
|
1412
|
+
const ycbcr = (r, g, b) => [
|
|
1413
|
+
.299 * r + .587 * g + .114 * b,
|
|
1414
|
+
128 - .168736 * r - .331264 * g + .5 * b,
|
|
1415
|
+
128 + .5 * r - .418688 * g - .081312 * b
|
|
1416
|
+
];
|
|
1417
|
+
/**
|
|
1418
|
+
* Whether the whole image is the grid `expected` (painted from the bytes `found` read) on a
|
|
1419
|
+
* uniform border: every pixel is opaque and its luma and chroma lie within the tolerances of those
|
|
1420
|
+
* of the repainted cells (or the border) near its place. "Near" is a few pixels, which absorbs the
|
|
1421
|
+
* blur scaling and compression put on cell edges. Damage the reader's error correction repaired,
|
|
1422
|
+
* an overlay and anything drawn in chroma alone all fail.
|
|
1423
|
+
*/
|
|
1424
|
+
function matchesTestImageGrid({ width, height, rgba }, found, expected) {
|
|
1425
|
+
const { cells, left, top, gridWidth, gridHeight } = found;
|
|
1426
|
+
if (rgba.length !== width * height * 4 || expected.width % cells) return false;
|
|
1427
|
+
const cellSize = expected.width / cells;
|
|
1428
|
+
if (cellSize < 1 || expected.height !== expected.width) return false;
|
|
1429
|
+
const colours = [];
|
|
1430
|
+
for (let row = 0; row < cells; row++) for (let column = 0; column < cells; column++) {
|
|
1431
|
+
const offset = ((row * cellSize + (cellSize >> 1)) * expected.width + column * cellSize + (cellSize >> 1)) * 4;
|
|
1432
|
+
colours.push(ycbcr(expected.rgba[offset], expected.rgba[offset + 1], expected.rgba[offset + 2]));
|
|
1433
|
+
}
|
|
1434
|
+
const border = ycbcr(rgba[0], rgba[1], rgba[2]);
|
|
1435
|
+
const radius = 2 + Math.ceil(Math.max(gridWidth, gridHeight) / expected.width);
|
|
1436
|
+
const right = left + gridWidth - 1;
|
|
1437
|
+
const bottom = top + gridHeight - 1;
|
|
1438
|
+
const span = (from, to, start, end, size) => {
|
|
1439
|
+
const outside = from < start || to > end;
|
|
1440
|
+
if (to < start || from > end) return {
|
|
1441
|
+
outside,
|
|
1442
|
+
first: 0,
|
|
1443
|
+
last: -1
|
|
1444
|
+
};
|
|
1445
|
+
return {
|
|
1446
|
+
outside,
|
|
1447
|
+
first: Math.max(0, Math.floor((Math.max(from, start) - start) * cells / size)),
|
|
1448
|
+
last: Math.min(cells - 1, Math.floor((Math.min(to, end) - start) * cells / size))
|
|
1449
|
+
};
|
|
1450
|
+
};
|
|
1451
|
+
const columns = Array.from({ length: width }, (_, x) => span(x - radius, x + radius, left, right, gridWidth));
|
|
1452
|
+
const tolerance = [
|
|
1453
|
+
48,
|
|
1454
|
+
40,
|
|
1455
|
+
40
|
|
1456
|
+
];
|
|
1457
|
+
const low = [
|
|
1458
|
+
0,
|
|
1459
|
+
0,
|
|
1460
|
+
0
|
|
1461
|
+
];
|
|
1462
|
+
const high = [
|
|
1463
|
+
0,
|
|
1464
|
+
0,
|
|
1465
|
+
0
|
|
1466
|
+
];
|
|
1467
|
+
const include = (colour) => {
|
|
1468
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
1469
|
+
low[channel] = Math.min(low[channel], colour[channel]);
|
|
1470
|
+
high[channel] = Math.max(high[channel], colour[channel]);
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
for (let y = 0; y < height; y++) {
|
|
1474
|
+
const rows = span(y - radius, y + radius, top, bottom, gridHeight);
|
|
1475
|
+
for (let x = 0; x < width; x++) {
|
|
1476
|
+
const offset = (y * width + x) * 4;
|
|
1477
|
+
if (rgba[offset + 3] < 250) return false;
|
|
1478
|
+
const near = columns[x];
|
|
1479
|
+
low.fill(Number.POSITIVE_INFINITY);
|
|
1480
|
+
high.fill(Number.NEGATIVE_INFINITY);
|
|
1481
|
+
if (rows.outside || near.outside) include(border);
|
|
1482
|
+
for (let row = rows.first; row <= rows.last; row++) for (let column = near.first; column <= near.last; column++) include(colours[row * cells + column]);
|
|
1483
|
+
const pixel = ycbcr(rgba[offset], rgba[offset + 1], rgba[offset + 2]);
|
|
1484
|
+
for (let channel = 0; channel < 3; channel++) if (pixel[channel] < low[channel] - tolerance[channel] || pixel[channel] > high[channel] + tolerance[channel]) return false;
|
|
1485
|
+
}
|
|
1383
1486
|
}
|
|
1487
|
+
return true;
|
|
1384
1488
|
}
|
|
1385
1489
|
const ringMatches = (samples) => {
|
|
1386
1490
|
let black = 0;
|
|
@@ -1431,6 +1535,48 @@ function testInputForSignal(signal, kind = "text") {
|
|
|
1431
1535
|
}
|
|
1432
1536
|
}
|
|
1433
1537
|
const getImageTestCategories = () => [...TEXT_CODE_SIGNALS];
|
|
1538
|
+
/** Each detection list holds at most this many entries; 32 faces fit a test image. */
|
|
1539
|
+
const TEST_DETECTIONS_MAX = 32;
|
|
1540
|
+
/** Box values are integer basis points of the image width and height: 10000 is the full side. */
|
|
1541
|
+
const TEST_DETECTION_BOX_MAX = 1e4;
|
|
1542
|
+
/** Age presets and the range a custom estimate may use. */
|
|
1543
|
+
const TEST_FACE_AGE_PRESETS = {
|
|
1544
|
+
adult: {
|
|
1545
|
+
low: 25,
|
|
1546
|
+
high: 35
|
|
1547
|
+
},
|
|
1548
|
+
minor: {
|
|
1549
|
+
low: 12,
|
|
1550
|
+
high: 16
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
const TEST_FACE_AGE_MAX = 120;
|
|
1554
|
+
const basisPoints = z.number().int().min(0).max(TEST_DETECTION_BOX_MAX);
|
|
1555
|
+
const detectionShape = {
|
|
1556
|
+
box: z.tuple([
|
|
1557
|
+
basisPoints,
|
|
1558
|
+
basisPoints,
|
|
1559
|
+
basisPoints,
|
|
1560
|
+
basisPoints
|
|
1561
|
+
]),
|
|
1562
|
+
confidence: z.number().int().min(0).max(100).optional()
|
|
1563
|
+
};
|
|
1564
|
+
const fitsImage = ({ box: [left, top, width, height] }) => left + width <= 1e4 && top + height <= 1e4;
|
|
1565
|
+
const BOX_MESSAGE = msg("A box must lie inside the image: left + width and top + height are at most 10000.");
|
|
1566
|
+
const ageYears = z.number().int().min(0).max(120);
|
|
1567
|
+
const TEST_DETECTED_PERSON_SCHEMA = z.object(detectionShape).strict().refine(fitsImage, BOX_MESSAGE);
|
|
1568
|
+
const TEST_DETECTED_FACE_SCHEMA = z.object({
|
|
1569
|
+
...detectionShape,
|
|
1570
|
+
age: z.union([z.enum(["adult", "minor"]), z.object({
|
|
1571
|
+
low: ageYears,
|
|
1572
|
+
high: ageYears
|
|
1573
|
+
}).strict().refine(({ low, high }) => low <= high, msg("An age range's low must not be above its high."))]).optional()
|
|
1574
|
+
}).strict().refine(fitsImage, BOX_MESSAGE);
|
|
1575
|
+
/** Person and face detection results a test image reports instead of running detection. */
|
|
1576
|
+
const TEST_DETECTIONS_SCHEMA = z.object({
|
|
1577
|
+
people: z.union([z.array(TEST_DETECTED_PERSON_SCHEMA).max(32), z.literal("unavailable")]).optional(),
|
|
1578
|
+
faces: z.union([z.array(TEST_DETECTED_FACE_SCHEMA).max(32), z.literal("unavailable")]).optional()
|
|
1579
|
+
}).strict();
|
|
1434
1580
|
/** Each row is one qualifying instance. Unselected qualifiers are explicitly absent. */
|
|
1435
1581
|
const TEST_INPUT_SCHEMA = z.object({
|
|
1436
1582
|
regionalActions: TEST_REGIONAL_ACTIONS_SCHEMA.optional(),
|
|
@@ -1450,7 +1596,8 @@ const TEST_INPUT_SCHEMA = z.object({
|
|
|
1450
1596
|
code: "custom",
|
|
1451
1597
|
message: "Choose unique content qualifiers from this category; input-type facts are automatic."
|
|
1452
1598
|
});
|
|
1453
|
-
})).max(128)
|
|
1599
|
+
})).max(128),
|
|
1600
|
+
detections: TEST_DETECTIONS_SCHEMA.optional()
|
|
1454
1601
|
}).strict().superRefine((scenario, context) => {
|
|
1455
1602
|
if (scenario.instances.some((instance) => instance.action !== void 0) && scenario.instances.some((instance) => instance.action === void 0)) context.addIssue({
|
|
1456
1603
|
code: "custom",
|
|
@@ -1503,24 +1650,152 @@ const TEST_INPUT_PRESETS = {
|
|
|
1503
1650
|
}, {
|
|
1504
1651
|
category: "harassment",
|
|
1505
1652
|
qualifiers: ["harassment-threat"]
|
|
1506
|
-
}] }
|
|
1653
|
+
}] },
|
|
1654
|
+
oneFace: {
|
|
1655
|
+
instances: [],
|
|
1656
|
+
detections: {
|
|
1657
|
+
people: [{ box: [
|
|
1658
|
+
2500,
|
|
1659
|
+
1500,
|
|
1660
|
+
5e3,
|
|
1661
|
+
8500
|
|
1662
|
+
] }],
|
|
1663
|
+
faces: [{ box: [
|
|
1664
|
+
3500,
|
|
1665
|
+
2e3,
|
|
1666
|
+
3e3,
|
|
1667
|
+
3500
|
|
1668
|
+
] }]
|
|
1669
|
+
}
|
|
1670
|
+
},
|
|
1671
|
+
noFace: {
|
|
1672
|
+
instances: [],
|
|
1673
|
+
detections: {
|
|
1674
|
+
people: [],
|
|
1675
|
+
faces: []
|
|
1676
|
+
}
|
|
1677
|
+
},
|
|
1678
|
+
adultFace: {
|
|
1679
|
+
instances: [],
|
|
1680
|
+
detections: {
|
|
1681
|
+
people: [{ box: [
|
|
1682
|
+
2500,
|
|
1683
|
+
1500,
|
|
1684
|
+
5e3,
|
|
1685
|
+
8500
|
|
1686
|
+
] }],
|
|
1687
|
+
faces: [{
|
|
1688
|
+
box: [
|
|
1689
|
+
3500,
|
|
1690
|
+
2e3,
|
|
1691
|
+
3e3,
|
|
1692
|
+
3500
|
|
1693
|
+
],
|
|
1694
|
+
age: "adult"
|
|
1695
|
+
}]
|
|
1696
|
+
}
|
|
1697
|
+
},
|
|
1698
|
+
minorFace: {
|
|
1699
|
+
instances: [],
|
|
1700
|
+
detections: {
|
|
1701
|
+
people: [{ box: [
|
|
1702
|
+
2500,
|
|
1703
|
+
1500,
|
|
1704
|
+
5e3,
|
|
1705
|
+
8500
|
|
1706
|
+
] }],
|
|
1707
|
+
faces: [{
|
|
1708
|
+
box: [
|
|
1709
|
+
3500,
|
|
1710
|
+
2e3,
|
|
1711
|
+
3e3,
|
|
1712
|
+
3500
|
|
1713
|
+
],
|
|
1714
|
+
age: "minor"
|
|
1715
|
+
}]
|
|
1716
|
+
}
|
|
1717
|
+
},
|
|
1718
|
+
group: {
|
|
1719
|
+
instances: [],
|
|
1720
|
+
detections: {
|
|
1721
|
+
people: [
|
|
1722
|
+
{ box: [
|
|
1723
|
+
500,
|
|
1724
|
+
2e3,
|
|
1725
|
+
2800,
|
|
1726
|
+
8e3
|
|
1727
|
+
] },
|
|
1728
|
+
{ box: [
|
|
1729
|
+
3600,
|
|
1730
|
+
2e3,
|
|
1731
|
+
2800,
|
|
1732
|
+
8e3
|
|
1733
|
+
] },
|
|
1734
|
+
{ box: [
|
|
1735
|
+
6700,
|
|
1736
|
+
2e3,
|
|
1737
|
+
2800,
|
|
1738
|
+
8e3
|
|
1739
|
+
] }
|
|
1740
|
+
],
|
|
1741
|
+
faces: [
|
|
1742
|
+
{ box: [
|
|
1743
|
+
1200,
|
|
1744
|
+
2500,
|
|
1745
|
+
1400,
|
|
1746
|
+
2e3
|
|
1747
|
+
] },
|
|
1748
|
+
{ box: [
|
|
1749
|
+
4300,
|
|
1750
|
+
2500,
|
|
1751
|
+
1400,
|
|
1752
|
+
2e3
|
|
1753
|
+
] },
|
|
1754
|
+
{ box: [
|
|
1755
|
+
7400,
|
|
1756
|
+
2500,
|
|
1757
|
+
1400,
|
|
1758
|
+
2e3
|
|
1759
|
+
] }
|
|
1760
|
+
]
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1507
1763
|
};
|
|
1508
|
-
|
|
1509
|
-
|
|
1764
|
+
/**
|
|
1765
|
+
* A text code: the tag, then the signed payload, base64url of the scenario's canonical JSON. Text
|
|
1766
|
+
* extracted from a document (a PDF, or a Word file converted to one) breaks a code that its layout wrapped: a line break between its parts, after a
|
|
1767
|
+
* hyphen or anywhere in a long payload. Whitespace inside a code is layout, not content, so it is
|
|
1768
|
+
* removed before the signature is checked.
|
|
1769
|
+
*/
|
|
1770
|
+
const WHOLE_CODE = /^<!calmlens-\s*test\s+([A-Za-z0-9_\s-]{33,16384})>$/;
|
|
1771
|
+
const tag = async (payload, key) => (await hmacSha256Hex(key, `calmlens-test:v2:${payload}`)).slice(0, 32);
|
|
1772
|
+
const toBase64Url = (bytes) => btoa(String.fromCharCode(...bytes)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
1773
|
+
const fromBase64Url = (text) => Uint8Array.from(atob(text.replaceAll("-", "+").replaceAll("_", "/")), (char) => char.charCodeAt(0));
|
|
1774
|
+
/** The signed bytes: the scenario's canonical JSON (ASCII). */
|
|
1775
|
+
const envelope = (scenario) => new TextEncoder().encode(JSON.stringify(TEST_INPUT_SCHEMA.parse(scenario)));
|
|
1510
1776
|
async function generateTestTextCode(scenario, key) {
|
|
1511
1777
|
if (!/^[a-f0-9]{32}$/.test(key)) throw new TypeError("Invalid test input key");
|
|
1512
|
-
const payload =
|
|
1778
|
+
const payload = toBase64Url(envelope(typeof scenario === "string" ? testInputForSignal(scenario) : scenario));
|
|
1513
1779
|
if (payload.length > 8e3) throw new RangeError("Test scenario is too large");
|
|
1514
1780
|
return `<!calmlens-test ${await tag(payload, key)} ${payload}>`;
|
|
1515
1781
|
}
|
|
1782
|
+
/**
|
|
1783
|
+
* The scenario a text declares when the whole text is one code signed with `key`; surrounding
|
|
1784
|
+
* text, a second code or an altered code all return undefined, so the text is moderated as
|
|
1785
|
+
* ordinary content.
|
|
1786
|
+
*/
|
|
1516
1787
|
async function detectTestTrigger(text, key) {
|
|
1517
1788
|
if (!/^[a-f0-9]{32}$/.test(key)) return;
|
|
1518
|
-
const
|
|
1519
|
-
if (
|
|
1520
|
-
const
|
|
1521
|
-
|
|
1789
|
+
const match = WHOLE_CODE.exec(text.trim());
|
|
1790
|
+
if (!match) return;
|
|
1791
|
+
const code = match[1].replace(/\s+/g, "");
|
|
1792
|
+
const signature = code.slice(0, 32);
|
|
1793
|
+
const payload = code.slice(32);
|
|
1794
|
+
if (!/^[a-f0-9]{32}$/.test(signature) || !payload || payload.length > 8e3 || !timingSafeEqual(signature, await tag(payload, key))) return;
|
|
1522
1795
|
try {
|
|
1523
|
-
const
|
|
1796
|
+
const json = fromBase64Url(payload);
|
|
1797
|
+
if (json.some((byte) => byte > 127)) return;
|
|
1798
|
+
const parsed = TEST_INPUT_SCHEMA.safeParse(JSON.parse(new TextDecoder().decode(json)));
|
|
1524
1799
|
return parsed.success ? parsed.data : void 0;
|
|
1525
1800
|
} catch {
|
|
1526
1801
|
return;
|
|
@@ -1570,31 +1845,40 @@ const TEST_INPUT_CATEGORY_COLORS = {
|
|
|
1570
1845
|
]
|
|
1571
1846
|
};
|
|
1572
1847
|
/**
|
|
1573
|
-
* The text code's signed bytes as a grid (TestImageGrid.ts): the
|
|
1574
|
-
* bytes, big-endian), the 16-byte tag, then the JSON. The reader rebuilds
|
|
1575
|
-
* and text share one verification.
|
|
1848
|
+
* The text code's signed bytes as a grid (TestImageGrid.ts): the signed payload's length (two
|
|
1849
|
+
* bytes, big-endian), the 16-byte tag, then the payload (the scenario JSON). The reader rebuilds
|
|
1850
|
+
* the text code, so images and text share one verification.
|
|
1576
1851
|
*/
|
|
1577
1852
|
async function paintTestImage(scenario, key) {
|
|
1578
1853
|
const input = TEST_INPUT_SCHEMA.parse(typeof scenario === "string" ? testInputForSignal(scenario, "image") : scenario);
|
|
1579
1854
|
const [, signature, payload] = (await generateTestTextCode(input, key)).slice(0, -1).split(" ");
|
|
1580
|
-
const
|
|
1581
|
-
const data = new Uint8Array(18 +
|
|
1582
|
-
data.set([
|
|
1855
|
+
const signed = fromBase64Url(payload);
|
|
1856
|
+
const data = new Uint8Array(18 + signed.length);
|
|
1857
|
+
data.set([signed.length >> 8, signed.length & 255]);
|
|
1583
1858
|
data.set(signature.match(/../g).map((hex) => Number.parseInt(hex, 16)), 2);
|
|
1584
|
-
data.set(
|
|
1585
|
-
|
|
1586
|
-
return paintTestImageGrid(data, categories.length ? categories.map((category) => TEST_INPUT_CATEGORY_COLORS[category]) : void 0);
|
|
1859
|
+
data.set(signed, 18);
|
|
1860
|
+
return paintTestImageGrid(data, testImagePalette(input));
|
|
1587
1861
|
}
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1590
|
-
|
|
1862
|
+
const testImagePalette = (input) => {
|
|
1863
|
+
const categories = [...new Set(input.instances.map((instance) => instance.category))];
|
|
1864
|
+
return categories.length ? categories.map((category) => TEST_INPUT_CATEGORY_COLORS[category]) : void 0;
|
|
1865
|
+
};
|
|
1866
|
+
/**
|
|
1867
|
+
* The test input an image declares when the whole image is one of the project's test images,
|
|
1868
|
+
* also after lossy formats and resizing: the grid, optionally on a uniform border. Every pixel
|
|
1869
|
+
* must match the grid repainted from the bytes it carries (TestImageGrid.ts,
|
|
1870
|
+
* `matchesTestImageGrid`), so nothing else can be drawn on or around it.
|
|
1871
|
+
*/
|
|
1872
|
+
async function detectTestImage(image, key, { whole = true } = {}) {
|
|
1591
1873
|
if (!TEST_INPUT_KEY_PATTERN.test(key)) return;
|
|
1592
|
-
const
|
|
1593
|
-
if (!
|
|
1874
|
+
const grid = readTestImageGrid(image);
|
|
1875
|
+
if (!grid) return;
|
|
1876
|
+
const { data } = grid;
|
|
1594
1877
|
const length = data[0] << 8 | data[1];
|
|
1595
|
-
if (18 + length > data.length) return;
|
|
1596
|
-
const
|
|
1597
|
-
|
|
1598
|
-
|
|
1878
|
+
if (!length || 18 + length > data.length) return;
|
|
1879
|
+
const signed = data.subarray(18, 18 + length);
|
|
1880
|
+
const scenario = await detectTestTrigger(`<!calmlens-test ${[...data.subarray(2, 18)].map((byte) => byte.toString(16).padStart(2, "0")).join("")} ${toBase64Url(signed)}>`, key);
|
|
1881
|
+
if (!scenario || !whole) return scenario;
|
|
1882
|
+
return matchesTestImageGrid(image, grid, paintTestImageGrid(data.subarray(0, 18 + length), testImagePalette(scenario))) ? scenario : void 0;
|
|
1599
1883
|
}
|
|
1600
|
-
export {
|
|
1884
|
+
export { TEST_INPUT_KEY_PATTERN as a, detectTestTrigger as c, getTestInputTag as d, paintTestImage as f, TEST_FACE_AGE_PRESETS as i, generateTestTextCode as l, CLASSIFICATION_CATEGORIES as m, TEST_DETECTION_BOX_MAX as n, TEST_INPUT_PRESETS as o, testInputForSignal as p, TEST_FACE_AGE_MAX as r, detectTestImage as s, TEST_DETECTIONS_MAX as t, getImageTestCategories as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as CalmLensAppClient } from "./CalmLensAppClient-
|
|
1
|
+
import { R as CalmLensError, z as SDK_ERROR_CODES } from "./ModerationContextLimits-CrxSnVZ3.js";
|
|
2
|
+
import { t as CalmLensAppClient } from "./CalmLensAppClient-B5QIJ6KS.js";
|
|
3
3
|
// src/contract/PlaceholderHashDecode.js
|
|
4
4
|
/**
|
|
5
5
|
* Decodes a ThumbHash to an RGBA image. RGB is not be premultiplied by A.
|
|
@@ -307,6 +307,22 @@ const sleep = (ms, signal) => new Promise((resolve) => {
|
|
|
307
307
|
resolve();
|
|
308
308
|
});
|
|
309
309
|
});
|
|
310
|
+
/** A custom upload is settled once it has a status other than `pending`, or reports none. */
|
|
311
|
+
const checkedCustomUpload = (id, status) => ({
|
|
312
|
+
id,
|
|
313
|
+
status,
|
|
314
|
+
settled: status !== "pending"
|
|
315
|
+
});
|
|
316
|
+
/**
|
|
317
|
+
* An upload preset's upload is settled once its processing is `completed` or `failed`; its
|
|
318
|
+
* moderation status is present only when the preset shows decisions.
|
|
319
|
+
*/
|
|
320
|
+
const checkedPresetUpload = ({ id, classification }) => ({
|
|
321
|
+
id,
|
|
322
|
+
status: classification.moderation?.status,
|
|
323
|
+
settled: classification.status === "completed" || classification.status === "failed",
|
|
324
|
+
failed: classification.status === "failed"
|
|
325
|
+
});
|
|
310
326
|
let nextKey = 0;
|
|
311
327
|
/**
|
|
312
328
|
* Uploads files through an upload preset and tracks each one until it has a moderation
|
|
@@ -498,12 +514,22 @@ var UploadController = class {
|
|
|
498
514
|
});
|
|
499
515
|
}
|
|
500
516
|
const deadline = Date.now() + (options.decisionTimeoutMs ?? DEFAULT_DECISION_TIMEOUT_MS);
|
|
501
|
-
for (let delay = 1e3; asset.
|
|
517
|
+
for (let delay = 1e3; !asset.settled && check && Date.now() < deadline; delay *= 2) {
|
|
502
518
|
await sleep(Math.min(delay, Math.max(0, deadline - Date.now())), abort.signal);
|
|
503
519
|
if (abort.signal.aborted) return;
|
|
504
520
|
asset = await check(asset.id);
|
|
505
521
|
}
|
|
506
522
|
if (abort.signal.aborted) return;
|
|
523
|
+
if (asset.failed) {
|
|
524
|
+
this.#checks.delete(key);
|
|
525
|
+
this.#update(key, {
|
|
526
|
+
stage: "failed",
|
|
527
|
+
progress: null
|
|
528
|
+
});
|
|
529
|
+
const item = this.#find(key);
|
|
530
|
+
if (item) options.onFailed?.(item);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
507
533
|
this.#update(key, {
|
|
508
534
|
stage: "complete",
|
|
509
535
|
status: asset.status
|
|
@@ -540,15 +566,9 @@ var UploadController = class {
|
|
|
540
566
|
signal,
|
|
541
567
|
onProgress
|
|
542
568
|
});
|
|
543
|
-
return
|
|
544
|
-
id: assetId,
|
|
545
|
-
status
|
|
546
|
-
};
|
|
569
|
+
return checkedCustomUpload(assetId, status);
|
|
547
570
|
},
|
|
548
|
-
retrieve: checkStatus ? async (assetId) => ({
|
|
549
|
-
id: assetId,
|
|
550
|
-
status: await checkStatus(assetId, { signal })
|
|
551
|
-
}) : void 0
|
|
571
|
+
retrieve: checkStatus ? async (assetId) => checkedCustomUpload(assetId, await checkStatus(assetId, { signal })) : void 0
|
|
552
572
|
};
|
|
553
573
|
if (!uploadPresetId) throw new CalmLensError(SDK_ERROR_CODES.INVALID_CONFIG, { message: "The uploader needs an uploadPresetId or an upload function" });
|
|
554
574
|
const options = {
|
|
@@ -562,7 +582,7 @@ var UploadController = class {
|
|
|
562
582
|
return {
|
|
563
583
|
create: async () => {
|
|
564
584
|
const type = file.type || "application/octet-stream";
|
|
565
|
-
return client.assets.create({
|
|
585
|
+
return checkedPresetUpload(await client.assets.create({
|
|
566
586
|
name: file.name,
|
|
567
587
|
content: isBlob(file) ? {
|
|
568
588
|
data: file,
|
|
@@ -571,9 +591,9 @@ var UploadController = class {
|
|
|
571
591
|
uint8Array: new Uint8Array(await file.arrayBuffer()),
|
|
572
592
|
type
|
|
573
593
|
}
|
|
574
|
-
});
|
|
594
|
+
}));
|
|
575
595
|
},
|
|
576
|
-
retrieve: (assetId) => client.assets.retrieve({ assetId })
|
|
596
|
+
retrieve: async (assetId) => checkedPresetUpload(await client.assets.retrieve({ assetId }))
|
|
577
597
|
};
|
|
578
598
|
}
|
|
579
599
|
async #tokenFor(file, signal) {
|