calmlens 0.18.3 → 0.19.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 +5373 -5002
- package/cjs/{BrowserUpload-UxIAGNdv.js → BrowserUpload-CJ4Xc9bR.js} +1 -1
- package/cjs/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-RkxV_Vv7.d.ts} +2 -2
- package/{esm/CalmLensAppClient-CV_K26Ce.d.ts → cjs/CalmLensAppClient-B5gfOB6J.d.ts} +3 -3
- package/cjs/{CalmLensAppClient-D6p7MAFz.js → CalmLensAppClient-LHMEQ-UZ.js} +32 -11
- package/cjs/{CalmLensConnection-CYoUl5go.js → CalmLensOptionKeys-BUj7v5AG.js} +368 -8
- package/cjs/{CalmLensServerClient-p23cl97D.js → CalmLensServerClient-BVOEUT_v.js} +167 -54
- package/cjs/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-DCSbwIBs.d.ts} +53 -29
- package/cjs/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-DpU-hXq2.d.ts} +2677 -30
- package/cjs/{ModerationContextLimits-DCLXMxyA.js → ModerationContextLimits-FDpQmw_T.js} +195 -41
- package/cjs/{ReactUpload-BcdNWLiU.js → ReactUpload-BvpW4hJi.js} +1 -1
- package/cjs/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-huIMnOJ4.d.ts} +1 -1
- package/cjs/{TestTriggers-DTc_iMJF-BjMPq4_3.js → TestTriggers-CMwMrbjy-K0YBzu2a.js} +433 -73
- package/{esm/TestTriggers-By07LR31-CmK0yTyR.d.ts → cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
- package/cjs/{UploadController-Cxu0bufo.js → UploadController-D4qOZZc3.js} +17 -5
- package/{esm/WebhookPayload-2aL31v0J.d.ts → cjs/WebhookPayload-CQg8BBZQ.d.ts} +29 -3
- package/cjs/app.d.ts +6 -6
- package/cjs/app.js +2 -2
- package/cjs/elements.d.ts +3 -3
- package/cjs/elements.js +3 -3
- package/cjs/{index-CI4BzN4W.d.ts → index-BcDDQJF2.d.ts} +7 -6
- package/cjs/index.d.ts +5 -5
- package/cjs/index.js +1 -1
- package/cjs/react-native.d.ts +3 -3
- package/cjs/react-native.js +3 -3
- package/cjs/react.d.ts +3 -3
- package/cjs/react.js +4 -4
- package/cjs/server.d.ts +6 -6
- package/cjs/server.js +2 -2
- package/cjs/test-inputs.d.ts +1 -1
- package/cjs/test-inputs.js +9 -9
- package/cjs/testing.d.ts +7 -6
- package/cjs/testing.js +189 -29
- package/{esm/ui-wIiMfqMB.d.ts → cjs/ui-B23r8BvW.d.ts} +17 -4
- package/cjs/{ui-C0XXJS52.js → ui-Dq-cm6Rx.js} +13 -10
- package/cjs/ui.d.ts +2 -2
- package/cjs/ui.js +2 -2
- package/cjs/vue.d.ts +5 -5
- package/cjs/vue.js +3 -3
- package/esm/{BrowserUpload-BXG2isHV.js → BrowserUpload-DpzS2bbj.js} +1 -1
- package/esm/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-RkxV_Vv7.d.ts} +2 -2
- package/{cjs/CalmLensAppClient-CV_K26Ce.d.ts → esm/CalmLensAppClient-B5gfOB6J.d.ts} +3 -3
- package/esm/{CalmLensAppClient-BMgXamoN.js → CalmLensAppClient-BjlvBweS.js} +28 -7
- package/esm/{CalmLensConnection-DBoDh06c.js → CalmLensOptionKeys-BKez0Wiw.js} +351 -9
- package/esm/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-DCSbwIBs.d.ts} +53 -29
- package/esm/{CalmLensServerClient-Dt7rCITa.js → CalmLensServerClient-DemxbNMn.js} +159 -46
- package/esm/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-DpU-hXq2.d.ts} +2677 -30
- package/esm/{ModerationContextLimits-KMQ8puoa.js → ModerationContextLimits-lLfmyLni.js} +176 -40
- package/esm/{ReactUpload-CFy_wETY.js → ReactUpload-6klucehl.js} +1 -1
- package/esm/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-huIMnOJ4.d.ts} +1 -1
- package/esm/{TestTriggers-DTc_iMJF-HfB533Gx.js → TestTriggers-CMwMrbjy-bdowBBKw.js} +404 -71
- package/{cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts → esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
- package/esm/{UploadController-Cs-bxUbt.js → UploadController-UxP6gj7A.js} +17 -5
- package/{cjs/WebhookPayload-2aL31v0J.d.ts → esm/WebhookPayload-CQg8BBZQ.d.ts} +29 -3
- package/esm/app.d.ts +6 -6
- package/esm/app.js +2 -2
- package/esm/elements.d.ts +3 -3
- package/esm/elements.js +3 -3
- package/esm/{index-CI4BzN4W.d.ts → index-BcDDQJF2.d.ts} +7 -6
- package/esm/index.d.ts +5 -5
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +3 -3
- package/esm/react-native.js +3 -3
- package/esm/react.d.ts +3 -3
- package/esm/react.js +4 -4
- package/esm/server.d.ts +6 -6
- package/esm/server.js +2 -2
- package/esm/test-inputs.d.ts +1 -1
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +7 -6
- package/esm/testing.js +178 -17
- package/{cjs/ui-wIiMfqMB.d.ts → esm/ui-B23r8BvW.d.ts} +17 -4
- package/esm/{ui-BqYkISSE.js → ui-Bn29rfAi.js} +12 -9
- package/esm/ui.d.ts +2 -2
- package/esm/ui.js +2 -2
- package/esm/vue.d.ts +5 -5
- package/esm/vue.js +3 -3
- package/package.json +1 -1
- package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +0 -91
- package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +0 -46
- /package/cjs/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
- /package/esm/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
2
22
|
const require_CryptoUtils_B_x8lMIx = require("./CryptoUtils-B_x8lMIx-YBW1-bvL.js");
|
|
3
23
|
let zod = require("zod");
|
|
4
|
-
zod =
|
|
24
|
+
zod = __toESM(zod, 1);
|
|
5
25
|
// src/contract/ModerationCategories-CHFRoeWV.js
|
|
6
26
|
const CLASSIFICATION_CATEGORIES = [
|
|
7
27
|
"sexual",
|
|
@@ -13,7 +33,66 @@ const CLASSIFICATION_CATEGORIES = [
|
|
|
13
33
|
"personal-information",
|
|
14
34
|
"profanity"
|
|
15
35
|
];
|
|
16
|
-
// src/contract/
|
|
36
|
+
// src/contract/Jurisdiction-DF7spSE4.js
|
|
37
|
+
/**
|
|
38
|
+
* Jurisdictions with legal rules always apply to every project. An opt-in jurisdiction is a product
|
|
39
|
+
* standard rather than a legal floor, so a project chooses whether to serve it.
|
|
40
|
+
*/
|
|
41
|
+
const JURISDICTIONS = {
|
|
42
|
+
global: {
|
|
43
|
+
name: "Global",
|
|
44
|
+
ageCheckStandard: "any",
|
|
45
|
+
optIn: false
|
|
46
|
+
},
|
|
47
|
+
DE: {
|
|
48
|
+
name: "Germany",
|
|
49
|
+
ageCheckStandard: "any",
|
|
50
|
+
optIn: false
|
|
51
|
+
},
|
|
52
|
+
AT: {
|
|
53
|
+
name: "Austria",
|
|
54
|
+
ageCheckStandard: "any",
|
|
55
|
+
optIn: false
|
|
56
|
+
},
|
|
57
|
+
FR: {
|
|
58
|
+
name: "France",
|
|
59
|
+
ageCheckStandard: "any",
|
|
60
|
+
optIn: false
|
|
61
|
+
},
|
|
62
|
+
GB: {
|
|
63
|
+
name: "United Kingdom",
|
|
64
|
+
ageCheckStandard: "verified",
|
|
65
|
+
optIn: false
|
|
66
|
+
},
|
|
67
|
+
EU: {
|
|
68
|
+
name: "European Union",
|
|
69
|
+
ageCheckStandard: "verified",
|
|
70
|
+
optIn: true
|
|
71
|
+
},
|
|
72
|
+
AU: {
|
|
73
|
+
name: "Australia",
|
|
74
|
+
ageCheckStandard: "verified",
|
|
75
|
+
optIn: false
|
|
76
|
+
},
|
|
77
|
+
BR: {
|
|
78
|
+
name: "Brazil",
|
|
79
|
+
ageCheckStandard: "verified",
|
|
80
|
+
optIn: false
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const JURISDICTION_SCHEMA = zod.enum(Object.keys(JURISDICTIONS));
|
|
84
|
+
Object.keys(JURISDICTIONS).filter((code) => !JURISDICTIONS[code].optIn);
|
|
85
|
+
const OPT_IN_JURISDICTIONS = Object.keys(JURISDICTIONS).filter((code) => JURISDICTIONS[code].optIn);
|
|
86
|
+
zod.enum(OPT_IN_JURISDICTIONS).array().refine((codes) => new Set(codes).size === codes.length, { message: "jurisdiction/duplicate" });
|
|
87
|
+
JURISDICTION_SCHEMA.array().min(1).refine((regions) => regions.includes("global") && new Set(regions).size === regions.length, { message: "jurisdiction/global-required-or-duplicate" });
|
|
88
|
+
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(" "));
|
|
89
|
+
const VIEWER_REGION_SCHEMA = zod.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.");
|
|
90
|
+
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(" "));
|
|
91
|
+
zod.object({
|
|
92
|
+
region: VIEWER_REGION_SCHEMA.optional().describe("Viewer country. Defaults to the country of the connection reaching CalmLens; proxies should forward the viewer country explicitly."),
|
|
93
|
+
ageConfirmed: zod.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 a public asset's URL can set it, so it is not an access control: to restrict who can load an age-restricted asset, make the asset private and include the claim in a signed URL, whose signature covers it.")
|
|
94
|
+
}).strict();
|
|
95
|
+
// src/contract/TestRegionalActions-6yfnXdpa.js
|
|
17
96
|
/**
|
|
18
97
|
* Marks English text in shared, backend and data modules that the portal shows, so the app's
|
|
19
98
|
* message catalog (packages/app/vite/messageCatalog.ts) extracts it and the portal can translate it
|
|
@@ -1012,14 +1091,333 @@ function getModerationQualifierInfo(qualifier) {
|
|
|
1012
1091
|
}
|
|
1013
1092
|
/** Authenticated test inputs can add regional delivery restrictions without inventing evidence. */
|
|
1014
1093
|
const TEST_REGIONAL_ACTIONS_SCHEMA = zod.array(zod.object({
|
|
1015
|
-
region:
|
|
1094
|
+
region: JURISDICTION_SCHEMA.exclude(["global"]),
|
|
1016
1095
|
action: zod.enum([
|
|
1017
1096
|
"limit",
|
|
1018
1097
|
"age-restrict",
|
|
1019
1098
|
"block"
|
|
1020
1099
|
])
|
|
1021
1100
|
}).strict()).max(7).refine((entries) => new Set(entries.map((entry) => entry.region)).size === entries.length, "Choose each region once");
|
|
1022
|
-
// src/contract/TestTriggers-
|
|
1101
|
+
// src/contract/TestTriggers-CMwMrbjy.js
|
|
1102
|
+
/**
|
|
1103
|
+
* The visual encoding of test images (shared by images and video frames), independent of what the
|
|
1104
|
+
* bytes mean. An odd N×N grid of square cells fills the image. Its outer ring alternates black and
|
|
1105
|
+
* white (black corners), which locates the grid, sets the black and white reference levels and
|
|
1106
|
+
* rejects ordinary pictures cheaply. Each interior cell, row by row, holds two bits as one of four
|
|
1107
|
+
* Gray-coded luma levels, coloured in chroma only (which the reader ignores). The bytes carry
|
|
1108
|
+
* Reed–Solomon parity, so a few damaged cells are corrected. Coarse levels and large cells survive
|
|
1109
|
+
* video chroma subsampling and compression, lossy image formats and resizing, which lowest-bit
|
|
1110
|
+
* encodings do not.
|
|
1111
|
+
*
|
|
1112
|
+
* SDKs port the painter byte for byte (the shared contract fixtures check it); only CalmLens reads.
|
|
1113
|
+
*/
|
|
1114
|
+
/**
|
|
1115
|
+
* Target luma of the four data levels. The ring is pure black (0) and white (255); data levels
|
|
1116
|
+
* stay inside them so every level has room for colour.
|
|
1117
|
+
*/
|
|
1118
|
+
const TEST_IMAGE_GRID_LEVELS = [
|
|
1119
|
+
72,
|
|
1120
|
+
128,
|
|
1121
|
+
184,
|
|
1122
|
+
240
|
|
1123
|
+
];
|
|
1124
|
+
const LEVEL_STEP = TEST_IMAGE_GRID_LEVELS[1] - TEST_IMAGE_GRID_LEVELS[0];
|
|
1125
|
+
/** The neutral colour of grids without categories. */
|
|
1126
|
+
const TEST_IMAGE_GRID_NEUTRAL = [
|
|
1127
|
+
144,
|
|
1128
|
+
152,
|
|
1129
|
+
160
|
|
1130
|
+
];
|
|
1131
|
+
/** BT.601 luma in integers; the reader uses the same formula. */
|
|
1132
|
+
const luma = (r, g, b) => 77 * r + 150 * g + 29 * b >> 8;
|
|
1133
|
+
/** Two-bit symbol → level, Gray coded so a one-level misread flips one bit. */
|
|
1134
|
+
const SYMBOL_LEVEL = [
|
|
1135
|
+
0,
|
|
1136
|
+
1,
|
|
1137
|
+
3,
|
|
1138
|
+
2
|
|
1139
|
+
];
|
|
1140
|
+
const LEVEL_SYMBOL = [
|
|
1141
|
+
0,
|
|
1142
|
+
1,
|
|
1143
|
+
3,
|
|
1144
|
+
2
|
|
1145
|
+
];
|
|
1146
|
+
const MAX_BLOCK = 255;
|
|
1147
|
+
const EXP = /* @__PURE__ */ new Uint8Array(512);
|
|
1148
|
+
const LOG = /* @__PURE__ */ new Uint8Array(256);
|
|
1149
|
+
for (let i = 0, x = 1; i < 255; i++) {
|
|
1150
|
+
EXP[i] = x;
|
|
1151
|
+
LOG[x] = i;
|
|
1152
|
+
x <<= 1;
|
|
1153
|
+
if (x & 256) x ^= 285;
|
|
1154
|
+
}
|
|
1155
|
+
for (let i = 255; i < 512; i++) EXP[i] = EXP[i - 255];
|
|
1156
|
+
const mul = (a, b) => a && b ? EXP[LOG[a] + LOG[b]] : 0;
|
|
1157
|
+
const div = (a, b) => a ? EXP[LOG[a] + 255 - LOG[b]] : 0;
|
|
1158
|
+
/** g(x) = (x − α^0)(x − α^1)…(x − α^(parity−1)), highest coefficient first. */
|
|
1159
|
+
const GENERATOR = (() => {
|
|
1160
|
+
let g = [1];
|
|
1161
|
+
for (let i = 0; i < 32; i++) {
|
|
1162
|
+
const next = new Array(g.length + 1).fill(0);
|
|
1163
|
+
for (let j = 0; j < g.length; j++) {
|
|
1164
|
+
next[j] ^= g[j];
|
|
1165
|
+
next[j + 1] ^= mul(g[j], EXP[i]);
|
|
1166
|
+
}
|
|
1167
|
+
g = next;
|
|
1168
|
+
}
|
|
1169
|
+
return g;
|
|
1170
|
+
})();
|
|
1171
|
+
/** Systematic encoding: the parity is data(x)·x^parity mod g(x). */
|
|
1172
|
+
const rsEncode = (data) => {
|
|
1173
|
+
const parity = /* @__PURE__ */ new Uint8Array(32);
|
|
1174
|
+
for (const byte of data) {
|
|
1175
|
+
const factor = byte ^ parity[0];
|
|
1176
|
+
parity.copyWithin(0, 1);
|
|
1177
|
+
parity[31] = 0;
|
|
1178
|
+
if (factor) for (let j = 0; j < 32; j++) parity[j] ^= mul(GENERATOR[j + 1], factor);
|
|
1179
|
+
}
|
|
1180
|
+
return parity;
|
|
1181
|
+
};
|
|
1182
|
+
/** Corrects a codeword (data then parity) in place; false when it has too many errors. */
|
|
1183
|
+
const rsDecode = (codeword) => {
|
|
1184
|
+
const n = codeword.length;
|
|
1185
|
+
const syndromes = new Array(32);
|
|
1186
|
+
let clean = true;
|
|
1187
|
+
for (let i = 0; i < 32; i++) {
|
|
1188
|
+
let s = 0;
|
|
1189
|
+
for (const byte of codeword) s = mul(s, EXP[i]) ^ byte;
|
|
1190
|
+
syndromes[i] = s;
|
|
1191
|
+
if (s) clean = false;
|
|
1192
|
+
}
|
|
1193
|
+
if (clean) return true;
|
|
1194
|
+
let locator = [1];
|
|
1195
|
+
let previous = [1];
|
|
1196
|
+
let length = 0;
|
|
1197
|
+
let shift = 1;
|
|
1198
|
+
let lastDiscrepancy = 1;
|
|
1199
|
+
for (let k = 0; k < 32; k++) {
|
|
1200
|
+
let discrepancy = syndromes[k];
|
|
1201
|
+
for (let i = 1; i <= length; i++) discrepancy ^= mul(locator[i] ?? 0, syndromes[k - i]);
|
|
1202
|
+
if (!discrepancy) {
|
|
1203
|
+
shift++;
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
const scale = div(discrepancy, lastDiscrepancy);
|
|
1207
|
+
const next = locator.slice();
|
|
1208
|
+
for (let i = 0; i < previous.length; i++) next[i + shift] = (next[i + shift] ?? 0) ^ mul(scale, previous[i]);
|
|
1209
|
+
if (2 * length <= k) {
|
|
1210
|
+
previous = locator;
|
|
1211
|
+
length = k + 1 - length;
|
|
1212
|
+
lastDiscrepancy = discrepancy;
|
|
1213
|
+
shift = 1;
|
|
1214
|
+
} else shift++;
|
|
1215
|
+
locator = next;
|
|
1216
|
+
}
|
|
1217
|
+
if (2 * length > 32) return false;
|
|
1218
|
+
const positions = [];
|
|
1219
|
+
for (let j = 0; j < n; j++) {
|
|
1220
|
+
const inverse = EXP[(255 - (n - 1 - j) % 255) % 255];
|
|
1221
|
+
let value = 0;
|
|
1222
|
+
for (let i = locator.length - 1; i >= 0; i--) value = mul(value, inverse) ^ (locator[i] ?? 0);
|
|
1223
|
+
if (!value) positions.push(j);
|
|
1224
|
+
}
|
|
1225
|
+
if (positions.length !== length) return false;
|
|
1226
|
+
const evaluator = new Array(32).fill(0);
|
|
1227
|
+
for (let i = 0; i < 32; i++) for (let j = 0; j <= i && j < locator.length; j++) evaluator[i] ^= mul(locator[j], syndromes[i - j]);
|
|
1228
|
+
for (const j of positions) {
|
|
1229
|
+
const power = (n - 1 - j) % 255;
|
|
1230
|
+
const x = EXP[power];
|
|
1231
|
+
const inverse = EXP[(255 - power) % 255];
|
|
1232
|
+
let omega = 0;
|
|
1233
|
+
for (let i = evaluator.length - 1; i >= 0; i--) omega = mul(omega, inverse) ^ evaluator[i];
|
|
1234
|
+
let derivative = 0;
|
|
1235
|
+
for (let i = 1; i < locator.length; i += 2) derivative ^= mul(locator[i], EXP[LOG[inverse] * (i - 1) % 255]);
|
|
1236
|
+
if (!derivative) return false;
|
|
1237
|
+
codeword[j] ^= mul(x, div(omega, derivative));
|
|
1238
|
+
}
|
|
1239
|
+
for (let i = 0; i < 32; i++) {
|
|
1240
|
+
let s = 0;
|
|
1241
|
+
for (const byte of codeword) s = mul(s, EXP[i]) ^ byte;
|
|
1242
|
+
if (s) return false;
|
|
1243
|
+
}
|
|
1244
|
+
return true;
|
|
1245
|
+
};
|
|
1246
|
+
/**
|
|
1247
|
+
* XORs stream byte i with (i·151 + 77) mod 256, so a uniform area (all codeword bytes equal, such
|
|
1248
|
+
* as a dark interior inside a ring) never reads as the all-zero codeword.
|
|
1249
|
+
*/
|
|
1250
|
+
const whiten = (stream) => {
|
|
1251
|
+
for (let i = 0; i < stream.length; i++) stream[i] ^= i * 151 + 77 & 255;
|
|
1252
|
+
};
|
|
1253
|
+
/** Codeword bytes an N-cell grid holds, and how they split into Reed–Solomon blocks. */
|
|
1254
|
+
const testImageGridLayout = (cells) => {
|
|
1255
|
+
const capacity = Math.floor((cells - 2) * (cells - 2) / 4);
|
|
1256
|
+
const blocks = Math.ceil(capacity / MAX_BLOCK);
|
|
1257
|
+
return {
|
|
1258
|
+
capacity,
|
|
1259
|
+
lengths: Array.from({ length: blocks }, (_, index) => Math.floor(capacity / blocks) + (index < capacity % blocks ? 1 : 0)),
|
|
1260
|
+
dataBytes: capacity - blocks * 32
|
|
1261
|
+
};
|
|
1262
|
+
};
|
|
1263
|
+
/** The smallest grid whose data bytes hold `length` bytes; undefined when none does. */
|
|
1264
|
+
const testImageGridCells = (length) => {
|
|
1265
|
+
for (let cells = 15; cells <= 127; cells += 2) if (testImageGridLayout(cells).dataBytes >= length) return cells;
|
|
1266
|
+
};
|
|
1267
|
+
/**
|
|
1268
|
+
* The colour of a data cell: `palette` blended between opposite corners (the first colour at the
|
|
1269
|
+
* top left and bottom right, the last at the other two), in integers.
|
|
1270
|
+
*/
|
|
1271
|
+
const blendedColour = (palette, column, row, cells) => {
|
|
1272
|
+
const span = cells - 1;
|
|
1273
|
+
const denominator = span * span;
|
|
1274
|
+
const position = (column * (span - row) + (span - column) * row) * (palette.length - 1);
|
|
1275
|
+
const start = Math.floor(position / denominator);
|
|
1276
|
+
const remainder = position - start * denominator;
|
|
1277
|
+
const end = palette[Math.min(start + 1, palette.length - 1)];
|
|
1278
|
+
return palette[start].map((channel, index) => Math.floor((channel * (denominator - remainder) + end[index] * remainder) / denominator));
|
|
1279
|
+
};
|
|
1280
|
+
/**
|
|
1281
|
+
* A cell's pixel: the colour's chroma (its difference from its own luma) on the level's luma,
|
|
1282
|
+
* scaled by the largest s/16 that keeps every channel in 0–255. Truncating each scaled difference
|
|
1283
|
+
* toward zero keeps the luma within about one step of the level.
|
|
1284
|
+
*/
|
|
1285
|
+
const testImageGridPixel = (colour, level) => {
|
|
1286
|
+
const target = TEST_IMAGE_GRID_LEVELS[level];
|
|
1287
|
+
const own = luma(colour[0], colour[1], colour[2]);
|
|
1288
|
+
const differences = colour.map((channel) => channel - own);
|
|
1289
|
+
for (let scale = 16;; scale--) {
|
|
1290
|
+
const pixel = differences.map((difference) => target + Math.sign(difference) * (Math.abs(difference) * scale >> 4));
|
|
1291
|
+
if (pixel.every((channel) => channel >= 0 && channel <= 255)) return pixel;
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
/**
|
|
1295
|
+
* Paints bytes as a grid, its data cells coloured by `palette` (TestTriggers.ts passes the
|
|
1296
|
+
* scenario's category colours). Unused data bytes are padded with 0xEC, 0x11, …
|
|
1297
|
+
*/
|
|
1298
|
+
function paintTestImageGrid(data, palette = [TEST_IMAGE_GRID_NEUTRAL]) {
|
|
1299
|
+
const cells = testImageGridCells(data.length);
|
|
1300
|
+
if (!cells) throw new RangeError("Test scenario is too large for a test image");
|
|
1301
|
+
const { capacity, lengths, dataBytes } = testImageGridLayout(cells);
|
|
1302
|
+
const padded = new Uint8Array(dataBytes);
|
|
1303
|
+
padded.set(data);
|
|
1304
|
+
for (let i = data.length; i < dataBytes; i++) padded[i] = (i - data.length) % 2 ? 17 : 236;
|
|
1305
|
+
const codewords = [];
|
|
1306
|
+
let offset = 0;
|
|
1307
|
+
for (const length of lengths) {
|
|
1308
|
+
const block = padded.subarray(offset, offset + length - 32);
|
|
1309
|
+
offset += block.length;
|
|
1310
|
+
const codeword = new Uint8Array(length);
|
|
1311
|
+
codeword.set(block);
|
|
1312
|
+
codeword.set(rsEncode(block), block.length);
|
|
1313
|
+
codewords.push(codeword);
|
|
1314
|
+
}
|
|
1315
|
+
const stream = new Uint8Array(capacity);
|
|
1316
|
+
let position = 0;
|
|
1317
|
+
for (let i = 0; i < Math.max(...lengths); i++) for (const codeword of codewords) if (i < codeword.length) stream[position++] = codeword[i];
|
|
1318
|
+
whiten(stream);
|
|
1319
|
+
const pixels = [];
|
|
1320
|
+
for (let y = 0; y < cells; y++) for (let x = 0; x < cells; x++) {
|
|
1321
|
+
if (x === 0 || y === 0 || x === cells - 1 || y === cells - 1) {
|
|
1322
|
+
const grey = (x + y) % 2 ? 255 : 0;
|
|
1323
|
+
pixels.push([
|
|
1324
|
+
grey,
|
|
1325
|
+
grey,
|
|
1326
|
+
grey
|
|
1327
|
+
]);
|
|
1328
|
+
continue;
|
|
1329
|
+
}
|
|
1330
|
+
const symbol = (y - 1) * (cells - 2) + x - 1;
|
|
1331
|
+
const byte = symbol >> 2;
|
|
1332
|
+
const level = byte < capacity ? SYMBOL_LEVEL[stream[byte] >> 6 - 2 * (symbol & 3) & 3] : 0;
|
|
1333
|
+
pixels.push(testImageGridPixel(blendedColour(palette, x, y, cells), level));
|
|
1334
|
+
}
|
|
1335
|
+
const cellSize = 2 * Math.floor(256 / cells);
|
|
1336
|
+
const width = cells * cellSize;
|
|
1337
|
+
const rgba = new Uint8Array(width * width * 4);
|
|
1338
|
+
for (let y = 0; y < width; y++) for (let x = 0; x < width; x++) rgba.set([...pixels[Math.floor(y / cellSize) * cells + Math.floor(x / cellSize)], 255], (y * width + x) * 4);
|
|
1339
|
+
return {
|
|
1340
|
+
width,
|
|
1341
|
+
height: width,
|
|
1342
|
+
rgba
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Reads the bytes a grid carries, or undefined when the image holds no readable grid. The grid
|
|
1347
|
+
* may be scaled (also unevenly) and surrounded by a uniform border, such as video letterboxing.
|
|
1348
|
+
* Cost is bounded by sampling, not by the image size, so every video frame can be checked.
|
|
1349
|
+
*/
|
|
1350
|
+
function readTestImageGrid({ width, height, rgba }) {
|
|
1351
|
+
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 30 || height < 30 || rgba.length !== width * height * 4) return;
|
|
1352
|
+
const lumaAt = (x, y) => {
|
|
1353
|
+
const offset = (y * width + x) * 4;
|
|
1354
|
+
return luma(rgba[offset], rgba[offset + 1], rgba[offset + 2]);
|
|
1355
|
+
};
|
|
1356
|
+
const background = lumaAt(0, 0);
|
|
1357
|
+
const differs = (count, at) => {
|
|
1358
|
+
const step = Math.max(1, Math.floor(count / 128));
|
|
1359
|
+
let total = 0;
|
|
1360
|
+
let hits = 0;
|
|
1361
|
+
for (let i = 0; i < count; i += step, total++) if (Math.abs(at(i) - background) >= 80) hits++;
|
|
1362
|
+
return hits * 8 >= total;
|
|
1363
|
+
};
|
|
1364
|
+
let top = 0;
|
|
1365
|
+
while (top < height && !differs(width, (x) => lumaAt(x, top))) top++;
|
|
1366
|
+
let bottom = height - 1;
|
|
1367
|
+
while (bottom > top && !differs(width, (x) => lumaAt(x, bottom))) bottom--;
|
|
1368
|
+
let left = 0;
|
|
1369
|
+
while (left < width && !differs(height, (y) => lumaAt(left, y))) left++;
|
|
1370
|
+
let right = width - 1;
|
|
1371
|
+
while (right > left && !differs(height, (y) => lumaAt(right, y))) right--;
|
|
1372
|
+
const gridWidth = right - left + 1;
|
|
1373
|
+
const gridHeight = bottom - top + 1;
|
|
1374
|
+
if (gridWidth < 30 || gridHeight < 30) return;
|
|
1375
|
+
for (let cells = 15; cells <= 127 && gridWidth >= cells * 2 && gridHeight >= cells * 2; cells += 2) {
|
|
1376
|
+
const cellWidth = gridWidth / cells;
|
|
1377
|
+
const cellHeight = gridHeight / cells;
|
|
1378
|
+
const cell = (column, row) => {
|
|
1379
|
+
let sum = 0;
|
|
1380
|
+
for (let dy = 0; dy < 3; dy++) for (let dx = 0; dx < 3; dx++) sum += lumaAt(Math.floor(left + (column + (dx + 3) / 9) * cellWidth), Math.floor(top + (row + (dy + 3) / 9) * cellHeight));
|
|
1381
|
+
return sum / 9;
|
|
1382
|
+
};
|
|
1383
|
+
const topEdge = Array.from({ length: cells }, (_, x) => [cell(x, 0), x % 2]);
|
|
1384
|
+
if (!ringMatches(topEdge)) continue;
|
|
1385
|
+
const samples = [...topEdge];
|
|
1386
|
+
for (let i = 1; i < cells; i++) samples.push([cell(cells - 1, i), (cells - 1 + i) % 2], [cell(0, i), i % 2]);
|
|
1387
|
+
for (let x = 1; x < cells - 1; x++) samples.push([cell(x, cells - 1), (x + cells - 1) % 2]);
|
|
1388
|
+
const reference = ringMatches(samples);
|
|
1389
|
+
if (!reference) continue;
|
|
1390
|
+
const { black, white } = reference;
|
|
1391
|
+
const { capacity, lengths } = testImageGridLayout(cells);
|
|
1392
|
+
const stream = new Uint8Array(capacity);
|
|
1393
|
+
for (let symbol = 0; symbol < capacity * 4; symbol++) {
|
|
1394
|
+
const interior = cells - 2;
|
|
1395
|
+
const scaled = (cell(symbol % interior + 1, Math.floor(symbol / interior) + 1) - black) / (white - black) * 255;
|
|
1396
|
+
const level = Math.min(3, Math.max(0, Math.round((scaled - TEST_IMAGE_GRID_LEVELS[0]) / LEVEL_STEP)));
|
|
1397
|
+
stream[symbol >> 2] |= LEVEL_SYMBOL[level] << 6 - 2 * (symbol & 3);
|
|
1398
|
+
}
|
|
1399
|
+
whiten(stream);
|
|
1400
|
+
const codewords = lengths.map((length) => new Uint8Array(length));
|
|
1401
|
+
let position = 0;
|
|
1402
|
+
for (let i = 0; i < Math.max(...lengths); i++) for (const codeword of codewords) if (i < codeword.length) codeword[i] = stream[position++];
|
|
1403
|
+
if (!codewords.every(rsDecode)) continue;
|
|
1404
|
+
return new Uint8Array(codewords.flatMap((codeword) => [...codeword.subarray(0, codeword.length - 32)]));
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
const ringMatches = (samples) => {
|
|
1408
|
+
let black = 0;
|
|
1409
|
+
let white = 0;
|
|
1410
|
+
for (const [value, isWhite] of samples) isWhite ? white += value : black += value;
|
|
1411
|
+
const whites = samples.filter(([, isWhite]) => isWhite).length;
|
|
1412
|
+
black /= samples.length - whites;
|
|
1413
|
+
white /= whites;
|
|
1414
|
+
if (white - black < 64) return;
|
|
1415
|
+
const middle = (black + white) / 2;
|
|
1416
|
+
return samples.filter(([value, isWhite]) => value > middle !== Boolean(isWhite)).length * 16 <= samples.length ? {
|
|
1417
|
+
black,
|
|
1418
|
+
white
|
|
1419
|
+
} : void 0;
|
|
1420
|
+
};
|
|
1023
1421
|
/** A project's test input key: 32 hexadecimal characters only its members can see. */
|
|
1024
1422
|
const TEST_INPUT_KEY_PATTERN = /^[a-f0-9]{32}$/;
|
|
1025
1423
|
const TEXT_CODE_SIGNALS = [
|
|
@@ -1150,7 +1548,7 @@ async function detectTestTrigger(text, key) {
|
|
|
1150
1548
|
return;
|
|
1151
1549
|
}
|
|
1152
1550
|
}
|
|
1153
|
-
/** Category colours
|
|
1551
|
+
/** Category colours, in the portal's builder and in test images' chroma; they never decide findings. */
|
|
1154
1552
|
const TEST_INPUT_CATEGORY_COLORS = {
|
|
1155
1553
|
sexual: [
|
|
1156
1554
|
232,
|
|
@@ -1193,77 +1591,33 @@ const TEST_INPUT_CATEGORY_COLORS = {
|
|
|
1193
1591
|
48
|
|
1194
1592
|
]
|
|
1195
1593
|
};
|
|
1196
|
-
/**
|
|
1594
|
+
/**
|
|
1595
|
+
* The text code's signed bytes as a grid (TestImageGrid.ts): the scenario JSON's length (two
|
|
1596
|
+
* bytes, big-endian), the 16-byte tag, then the JSON. The reader rebuilds the text code, so images
|
|
1597
|
+
* and text share one verification.
|
|
1598
|
+
*/
|
|
1197
1599
|
async function paintTestImage(scenario, key) {
|
|
1198
1600
|
const input = TEST_INPUT_SCHEMA.parse(typeof scenario === "string" ? testInputForSignal(scenario, "image") : scenario);
|
|
1199
|
-
const
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1207
|
-
76,
|
|
1208
|
-
84,
|
|
1209
|
-
83,
|
|
1210
|
-
2,
|
|
1211
|
-
bytes.length >> 8,
|
|
1212
|
-
bytes.length & 255,
|
|
1213
|
-
...bytes
|
|
1214
|
-
]);
|
|
1215
|
-
const cells = Math.ceil(Math.sqrt(data.length));
|
|
1216
|
-
const width = cells * 4;
|
|
1217
|
-
const height = width;
|
|
1218
|
-
const rgba = new Uint8Array(width * height * 4);
|
|
1219
|
-
for (let i = 0; i < width * height; i++) {
|
|
1220
|
-
const row = Math.floor(i / width / 4);
|
|
1221
|
-
const cell = row * cells + Math.floor(i % width / 4);
|
|
1222
|
-
const value = data[cell % data.length];
|
|
1223
|
-
const x = cell % cells / (cells - 1);
|
|
1224
|
-
const y = row / (cells - 1);
|
|
1225
|
-
const position = (x * (1 - y) + (1 - x) * y) * (palette.length - 1);
|
|
1226
|
-
const start = Math.floor(position);
|
|
1227
|
-
const blend = position - start;
|
|
1228
|
-
const shade = (value * 73 + 41 & 255) / 255;
|
|
1229
|
-
const color = palette[start].map((channel, index) => {
|
|
1230
|
-
const mixed = channel + (palette[Math.min(start + 1, palette.length - 1)][index] - channel) * blend;
|
|
1231
|
-
return Math.round(mixed * (.65 + shade * .2) + 38 * shade);
|
|
1232
|
-
});
|
|
1233
|
-
rgba.set([
|
|
1234
|
-
color[0] & 248 | value >> 5,
|
|
1235
|
-
color[1] & 248 | value >> 2 & 7,
|
|
1236
|
-
color[2] & 252 | value & 3,
|
|
1237
|
-
255
|
|
1238
|
-
], i * 4);
|
|
1239
|
-
}
|
|
1240
|
-
return {
|
|
1241
|
-
width,
|
|
1242
|
-
height,
|
|
1243
|
-
rgba
|
|
1244
|
-
};
|
|
1601
|
+
const [, signature, payload] = (await generateTestTextCode(input, key)).slice(0, -1).split(" ");
|
|
1602
|
+
const json = Uint8Array.from(atob(payload.replaceAll("-", "+").replaceAll("_", "/")), (char) => char.charCodeAt(0));
|
|
1603
|
+
const data = new Uint8Array(18 + json.length);
|
|
1604
|
+
data.set([json.length >> 8, json.length & 255]);
|
|
1605
|
+
data.set(signature.match(/../g).map((hex) => Number.parseInt(hex, 16)), 2);
|
|
1606
|
+
data.set(json, 18);
|
|
1607
|
+
const categories = [...new Set(input.instances.map((instance) => instance.category))];
|
|
1608
|
+
return paintTestImageGrid(data, categories.length ? categories.map((category) => TEST_INPUT_CATEGORY_COLORS[category]) : void 0);
|
|
1245
1609
|
}
|
|
1610
|
+
const base64Url = (bytes) => btoa(String.fromCharCode(...bytes)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
1611
|
+
/** The test input a project's test image carries, also after video encoding and resizing. */
|
|
1246
1612
|
async function detectTestImage(image, key) {
|
|
1247
|
-
if (!
|
|
1248
|
-
const
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
const value = legacy ? red : (red & 7) << 5 | (green & 7) << 2 | blue & 3;
|
|
1256
|
-
if (legacy && (green !== 255 - red || blue !== 123)) return;
|
|
1257
|
-
for (let dy = 0; dy < 4; dy++) for (let dx = 0; dx < 4; dx++) {
|
|
1258
|
-
const pos = ((y + dy) * image.width + x + dx) * 4;
|
|
1259
|
-
if (image.rgba[pos] !== red || image.rgba[pos + 1] !== green || image.rgba[pos + 2] !== blue || image.rgba[pos + 3] !== 255) return;
|
|
1260
|
-
}
|
|
1261
|
-
bytes.push(value);
|
|
1262
|
-
}
|
|
1263
|
-
if (bytes.slice(0, 5).join() !== `67,76,84,83,${legacy ? 1 : 2}`) return;
|
|
1264
|
-
const length = bytes[5] << 8 | bytes[6];
|
|
1265
|
-
if (length > bytes.length - 7) return;
|
|
1266
|
-
return detectTestTrigger(new TextDecoder().decode(new Uint8Array(bytes.slice(7, 7 + length))), key);
|
|
1613
|
+
if (!TEST_INPUT_KEY_PATTERN.test(key)) return;
|
|
1614
|
+
const data = readTestImageGrid(image);
|
|
1615
|
+
if (!data) return;
|
|
1616
|
+
const length = data[0] << 8 | data[1];
|
|
1617
|
+
if (18 + length > data.length) return;
|
|
1618
|
+
const json = data.subarray(18, 18 + length);
|
|
1619
|
+
if (json.some((byte) => byte > 127)) return;
|
|
1620
|
+
return detectTestTrigger(`<!calmlens-test ${[...data.subarray(2, 18)].map((byte) => byte.toString(16).padStart(2, "0")).join("")} ${base64Url(json)}>`, key);
|
|
1267
1621
|
}
|
|
1268
1622
|
Object.defineProperty(exports, "CLASSIFICATION_CATEGORIES", {
|
|
1269
1623
|
enumerable: true,
|
|
@@ -1283,6 +1637,12 @@ Object.defineProperty(exports, "TEST_INPUT_PRESETS", {
|
|
|
1283
1637
|
return TEST_INPUT_PRESETS;
|
|
1284
1638
|
}
|
|
1285
1639
|
});
|
|
1640
|
+
Object.defineProperty(exports, "__toESM", {
|
|
1641
|
+
enumerable: true,
|
|
1642
|
+
get: function() {
|
|
1643
|
+
return __toESM;
|
|
1644
|
+
}
|
|
1645
|
+
});
|
|
1286
1646
|
Object.defineProperty(exports, "detectTestImage", {
|
|
1287
1647
|
enumerable: true,
|
|
1288
1648
|
get: function() {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { n as ClassificationCategory } from "./Classification-
|
|
1
|
+
import { n as ClassificationCategory } from "./Classification-D3SkprrQ-CMnQKW13.js";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
+
interface RgbaImage {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
rgba: Uint8Array | Uint8ClampedArray;
|
|
7
|
+
}
|
|
3
8
|
type ClassificationTestSignal = ClassificationCategory | "sexual.involving-minors" | "violence.graphic" | "harassment.insult" | "sexual.adult" | "hate.regional-symbol";
|
|
4
9
|
/** A project's test input key: 32 hexadecimal characters only its members can see. */
|
|
5
10
|
declare const TEST_INPUT_KEY_PATTERN: RegExp;
|
|
@@ -245,17 +250,18 @@ declare const TEST_INPUT_PRESETS: {
|
|
|
245
250
|
};
|
|
246
251
|
declare function generateTestTextCode(scenario: TestInput | ClassificationTestSignal, key: string): Promise<string>;
|
|
247
252
|
declare function detectTestTrigger(text: string, key: string): Promise<TestInput | undefined>;
|
|
248
|
-
/**
|
|
253
|
+
/**
|
|
254
|
+
* The text code's signed bytes as a grid (TestImageGrid.ts): the scenario JSON's length (two
|
|
255
|
+
* bytes, big-endian), the 16-byte tag, then the JSON. The reader rebuilds the text code, so images
|
|
256
|
+
* and text share one verification.
|
|
257
|
+
*/
|
|
249
258
|
declare function paintTestImage(scenario: TestInput | ClassificationTestSignal, key: string): Promise<{
|
|
250
259
|
width: number;
|
|
251
260
|
height: number;
|
|
252
261
|
rgba: Uint8Array<ArrayBuffer>;
|
|
253
262
|
}>;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
height: number;
|
|
257
|
-
rgba: Uint8Array;
|
|
258
|
-
}, key: string): Promise<{
|
|
263
|
+
/** The test input a project's test image carries, also after video encoding and resizing. */
|
|
264
|
+
declare function detectTestImage(image: RgbaImage, key: string): Promise<{
|
|
259
265
|
regionalActions?: {
|
|
260
266
|
region: "AT" | "AU" | "BR" | "DE" | "EU" | "FR" | "GB";
|
|
261
267
|
action: "age-restrict" | "block" | "limit";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_ModerationContextLimits = require("./ModerationContextLimits-
|
|
2
|
-
const require_CalmLensAppClient = require("./CalmLensAppClient-
|
|
1
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-FDpQmw_T.js");
|
|
2
|
+
const require_CalmLensAppClient = require("./CalmLensAppClient-LHMEQ-UZ.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.
|
|
@@ -206,9 +206,16 @@ function placeholderHashToDataURL(hash) {
|
|
|
206
206
|
* can't do. It sends through `XMLHttpRequest`, so the upload components pass it to
|
|
207
207
|
* `CalmLensAppClient` as `uploadFetch`. Without `XMLHttpRequest` it falls back to `fetch` and
|
|
208
208
|
* reports nothing.
|
|
209
|
+
*
|
|
210
|
+
* The count runs across the requests sent through it: `sentBytes` adds the bodies of earlier
|
|
211
|
+
* requests that succeeded, so a file uploaded in parts keeps counting up. `totalBytes` is
|
|
212
|
+
* `options.totalBytes` when given, otherwise those earlier bodies plus the current one. Create
|
|
213
|
+
* one for each file.
|
|
209
214
|
*/
|
|
210
|
-
const createProgressFetch = (onProgress) => {
|
|
215
|
+
const createProgressFetch = (onProgress, { totalBytes } = {}) => {
|
|
211
216
|
if (typeof XMLHttpRequest === "undefined") return (input, init) => fetch(input, init);
|
|
217
|
+
/** The bodies of the requests that succeeded, which a retry won't send again. */
|
|
218
|
+
let accepted = 0;
|
|
212
219
|
return (input, init = {}) => new Promise((resolve, reject) => {
|
|
213
220
|
const signal = init.signal;
|
|
214
221
|
const abortError = () => signal?.reason ?? new DOMException("The upload was cancelled", "AbortError");
|
|
@@ -221,14 +228,19 @@ const createProgressFetch = (onProgress) => {
|
|
|
221
228
|
xhr.open(init.method ?? "GET", url);
|
|
222
229
|
xhr.responseType = "arraybuffer";
|
|
223
230
|
for (const [name, value] of new Headers(init.headers)) xhr.setRequestHeader(name, value);
|
|
231
|
+
let bodyBytes = 0;
|
|
224
232
|
xhr.upload.onprogress = (event) => {
|
|
225
|
-
if (event.lengthComputable)
|
|
233
|
+
if (!event.lengthComputable) return;
|
|
234
|
+
bodyBytes = event.total;
|
|
235
|
+
const total = totalBytes ?? accepted + event.total;
|
|
236
|
+
onProgress(Math.min(accepted + event.loaded, total), total);
|
|
226
237
|
};
|
|
227
238
|
const onAbort = () => xhr.abort();
|
|
228
239
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
229
240
|
const done = () => signal?.removeEventListener("abort", onAbort);
|
|
230
241
|
xhr.onload = () => {
|
|
231
242
|
done();
|
|
243
|
+
if (xhr.status >= 200 && xhr.status < 300) accepted += bodyBytes;
|
|
232
244
|
const headers = new Headers();
|
|
233
245
|
for (const line of xhr.getAllResponseHeaders().trim().split(/[\r\n]+/)) {
|
|
234
246
|
const separator = line.indexOf(":");
|
|
@@ -544,7 +556,7 @@ var UploadController = class {
|
|
|
544
556
|
token: await this.#tokenFor(file, signal),
|
|
545
557
|
baseUrl,
|
|
546
558
|
signal,
|
|
547
|
-
uploadFetch: createProgressFetch(onProgress)
|
|
559
|
+
uploadFetch: createProgressFetch(onProgress, { totalBytes: file.size })
|
|
548
560
|
};
|
|
549
561
|
const client = createClient ? createClient(options) : new require_CalmLensAppClient.CalmLensAppClient(options);
|
|
550
562
|
return {
|