@cloakapi/sdk 1.5.0 → 1.6.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/CHANGELOG.md +7 -0
- package/README.md +21 -1
- package/dist/browser/index.d.mts +3 -2
- package/dist/browser/index.d.ts +3 -2
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.mjs +8 -7
- package/dist/browser/light.d.mts +2 -1
- package/dist/browser/light.d.ts +2 -1
- package/dist/browser/light.mjs +1 -1
- package/dist/browser/names/public.mjs +2 -2
- package/dist/browser/ner-pipeline-worker.mjs +3 -3
- package/dist/{chunk-G6TZ6722.mjs → chunk-6E6T2YO5.mjs} +5 -915
- package/dist/{chunk-6TMC2A6M.mjs → chunk-6JZLCPZ7.mjs} +1 -1
- package/dist/{chunk-36BC4GYL.mjs → chunk-7OIXV4CE.mjs} +22 -20
- package/dist/{chunk-JV52VGVZ.mjs → chunk-JCTZ572R.mjs} +1 -1
- package/dist/chunk-L7RLVZMD.mjs +922 -0
- package/dist/device/index.d.mts +1448 -0
- package/dist/device/index.d.ts +1448 -0
- package/dist/device/index.js +4539 -0
- package/dist/device/index.mjs +3706 -0
- package/dist/{disclosure-Cx6xS8Tj.d.mts → disclosure-Cslh-RaS.d.mts} +2 -12
- package/dist/{disclosure-Cx6xS8Tj.d.ts → disclosure-Cslh-RaS.d.ts} +2 -12
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +14 -12
- package/dist/{local-pii-supplement-SUOJZO7X.mjs → local-pii-supplement-5KFFPDDN.mjs} +4 -4
- package/dist/node.d.mts +2 -1
- package/dist/node.d.ts +2 -1
- package/dist/node.mjs +10 -9
- package/dist/request-body-slots-BMShK1YO.d.mts +56 -0
- package/dist/request-body-slots-BMShK1YO.d.ts +56 -0
- package/package.json +9 -2
- package/dist/{chunk-PEDVEDAW.mjs → chunk-66SEKCCN.mjs} +8 -8
|
@@ -0,0 +1,4539 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/device/index.ts
|
|
21
|
+
var device_exports = {};
|
|
22
|
+
__export(device_exports, {
|
|
23
|
+
ACCEPTANCE_BLOCK_REASONS: () => ACCEPTANCE_BLOCK_REASONS,
|
|
24
|
+
ALL_BLOCK_REASONS: () => ALL_BLOCK_REASONS,
|
|
25
|
+
DETECTOR_UNAVAILABLE_REASON: () => DETECTOR_UNAVAILABLE_REASON,
|
|
26
|
+
ENHANCED_NER_MODEL_BYTES: () => ENHANCED_NER_MODEL_BYTES,
|
|
27
|
+
ENHANCED_NER_MODEL_LABEL: () => ENHANCED_NER_MODEL_LABEL,
|
|
28
|
+
H308_ENCODED_PAYLOAD_NOTICE: () => H308_ENCODED_PAYLOAD_NOTICE,
|
|
29
|
+
H308_UNREADABLE_MIME_REASON: () => H308_UNREADABLE_MIME_REASON,
|
|
30
|
+
K9_L3_MODEL_ID: () => K9_L3_MODEL_ID,
|
|
31
|
+
LOADER_STATES_FOR_RECEIPT: () => LOADER_STATES_FOR_RECEIPT,
|
|
32
|
+
LOAD_FAILURE_BLOCK_REASONS: () => LOAD_FAILURE_BLOCK_REASONS,
|
|
33
|
+
NER_BLOCK_CODE: () => NER_BLOCK_CODE,
|
|
34
|
+
NER_L2_DID_NOT_RUN_MESSAGE: () => NER_L2_DID_NOT_RUN_MESSAGE,
|
|
35
|
+
NER_READY_BUDGET_MS: () => NER_READY_BUDGET_MS,
|
|
36
|
+
NER_READY_MAX_WAIT_MS: () => NER_READY_MAX_WAIT_MS,
|
|
37
|
+
NER_READY_USER_WAIT_MS: () => NER_READY_USER_WAIT_MS,
|
|
38
|
+
NER_REQUIRED_MESSAGE: () => NER_REQUIRED_MESSAGE,
|
|
39
|
+
NER_STALL_BUDGET_MS: () => NER_STALL_BUDGET_MS,
|
|
40
|
+
NER_UNPROVEN_SCRIPT_CODE: () => NER_UNPROVEN_SCRIPT_CODE,
|
|
41
|
+
NER_UNPROVEN_SCRIPT_MESSAGE: () => NER_UNPROVEN_SCRIPT_MESSAGE,
|
|
42
|
+
NER_WAIT_BUDGET_MS: () => NER_WAIT_BUDGET_MS,
|
|
43
|
+
NerBlockedError: () => NerBlockedError,
|
|
44
|
+
OCR_LESEGOLV: () => OCR_LESEGOLV,
|
|
45
|
+
OCR_LESEGOLV_MAALT: () => OCR_LESEGOLV_MAALT,
|
|
46
|
+
OCR_LESEGOLV_NEMNAR: () => OCR_LESEGOLV_NEMNAR,
|
|
47
|
+
OCR_ULESE_SPAN_TYPE: () => OCR_ULESE_SPAN_TYPE,
|
|
48
|
+
OCR_ULESE_SURROGAT_PREFIKS: () => OCR_ULESE_SURROGAT_PREFIKS,
|
|
49
|
+
ORT_IN_WORKER: () => ORT_IN_WORKER,
|
|
50
|
+
OcrUfullstendigFeil: () => OcrUfullstendigFeil,
|
|
51
|
+
PLACEMENT_SCHEMA: () => PLACEMENT_SCHEMA,
|
|
52
|
+
TESSDATA_MAX_BYTES: () => TESSDATA_MAX_BYTES,
|
|
53
|
+
TESSDATA_PACKAGE_VERSION: () => TESSDATA_PACKAGE_VERSION,
|
|
54
|
+
TESSDATA_SHA256: () => TESSDATA_SHA256,
|
|
55
|
+
TESSDATA_SIZE: () => TESSDATA_SIZE,
|
|
56
|
+
TESSDATA_VARIANT: () => TESSDATA_VARIANT,
|
|
57
|
+
TIMING_BLOCK_REASONS: () => TIMING_BLOCK_REASONS,
|
|
58
|
+
TessdataIntegrityError: () => TessdataIntegrityError,
|
|
59
|
+
UnreadableImageError: () => UnreadableImageError,
|
|
60
|
+
acceptanceApplies: () => acceptanceApplies,
|
|
61
|
+
andrePassBidrag: () => andrePassBidrag,
|
|
62
|
+
applyLateFileTextIfUnchanged: () => applyLateFileTextIfUnchanged,
|
|
63
|
+
applyTransformersEnv: () => applyTransformersEnv,
|
|
64
|
+
assertContractLiteralSafe: () => assertContractLiteralSafe,
|
|
65
|
+
assertDecodableImage: () => assertDecodableImage,
|
|
66
|
+
assertNerAllowsEgress: () => assertNerAllowsEgress,
|
|
67
|
+
assertNonLatinSpansTaken: () => assertNonLatinSpansTaken,
|
|
68
|
+
assessH308Input: () => assessH308Input,
|
|
69
|
+
choiceNeeded: () => choiceNeeded,
|
|
70
|
+
collectRequestBodyTextSlots: () => collectRequestBodyTextSlots,
|
|
71
|
+
collectUserTypedLiteralMarkers: () => collectUserTypedLiteralMarkers,
|
|
72
|
+
collectValuePlacementWarnings: () => collectValuePlacementWarnings,
|
|
73
|
+
countDistinctReviewEntities: () => countDistinctReviewEntities,
|
|
74
|
+
coverageChoiceLatch: () => coverageChoiceLatch,
|
|
75
|
+
coverageReceiptClaims: () => coverageReceiptClaims,
|
|
76
|
+
coverageWarningFor: () => coverageWarningFor,
|
|
77
|
+
createCoverageChoiceLatch: () => createCoverageChoiceLatch,
|
|
78
|
+
createMultilingualNer: () => createMultilingualNer,
|
|
79
|
+
createNerGateBudget: () => createNerGateBudget,
|
|
80
|
+
createNerGateCoverage: () => createNerGateCoverage,
|
|
81
|
+
deepClone: () => deepClone,
|
|
82
|
+
detokeniseReply: () => detokeniseReply,
|
|
83
|
+
fetchVerifiedTessdata: () => fetchVerifiedTessdata,
|
|
84
|
+
finalCardBackstop: () => finalCardBackstop,
|
|
85
|
+
finalCardBackstopJson: () => finalCardBackstopJson,
|
|
86
|
+
finalCardBackstopJsonToFixedPoint: () => finalCardBackstopJsonToFixedPoint,
|
|
87
|
+
finalCardBackstopToFixedPoint: () => finalCardBackstopToFixedPoint,
|
|
88
|
+
gateStateToDecision: () => gateStateToDecision,
|
|
89
|
+
hasH308MimeHeader: () => hasH308MimeHeader,
|
|
90
|
+
hasIncompleteDetokenisationMap: () => hasIncompleteDetokenisationMap,
|
|
91
|
+
hasMimeHeaderBlock: () => hasMimeHeaderBlock,
|
|
92
|
+
hasUnprotectedCardJson: () => hasUnprotectedCardJson,
|
|
93
|
+
isImageFilenameOrMime: () => isImageFilenameOrMime,
|
|
94
|
+
isLateFileTextCurrent: () => isLateFileTextCurrent,
|
|
95
|
+
isLevel3Loading: () => isLevel3Loading,
|
|
96
|
+
isNerUnavailable: () => isNerUnavailable,
|
|
97
|
+
kickoffLevel3IfServed: () => kickoffLevel3IfServed,
|
|
98
|
+
l2RanForLoaderState: () => l2RanForLoaderState,
|
|
99
|
+
layersRanForReceipt: () => layersRanForReceipt,
|
|
100
|
+
layersRanWithListCheck: () => layersRanWithListCheck,
|
|
101
|
+
level3Load: () => level3Load,
|
|
102
|
+
level3LoadStore: () => level3LoadStore,
|
|
103
|
+
level3StillLoading: () => level3StillLoading,
|
|
104
|
+
looksNameLikely: () => looksNameLikely,
|
|
105
|
+
makeL3KickLatch: () => makeL3KickLatch,
|
|
106
|
+
makeNerBlockMessage: () => makeNerBlockMessage,
|
|
107
|
+
markLevel3Load: () => markLevel3Load,
|
|
108
|
+
nameLayerUnchecked: () => nameLayerUnchecked,
|
|
109
|
+
nerGate: () => nerGate,
|
|
110
|
+
nerGateDecision: () => nerGateDecision,
|
|
111
|
+
ordFraTesseract: () => ordFraTesseract,
|
|
112
|
+
ordFraTesseractFullstendig: () => ordFraTesseractFullstendig,
|
|
113
|
+
ordFraTesseractMedSkip: () => ordFraTesseractMedSkip,
|
|
114
|
+
ordUnderLesegolvet: () => ordUnderLesegolvet,
|
|
115
|
+
ordaUnderLesegolvet: () => ordaUnderLesegolvet,
|
|
116
|
+
recommendedNerThreads: () => recommendedNerThreads,
|
|
117
|
+
reconstructSourceFromMap: () => reconstructSourceFromMap,
|
|
118
|
+
repairOcrFragmentedEmails: () => repairOcrFragmentedEmails,
|
|
119
|
+
replaceUnicodeCaseFoldOccurrences: () => replaceUnicodeCaseFoldOccurrences,
|
|
120
|
+
resetLevel3LoadForTest: () => resetLevel3LoadForTest,
|
|
121
|
+
restoreMapOnce: () => restoreMapOnce,
|
|
122
|
+
reviewH308Text: () => reviewH308Text,
|
|
123
|
+
slotIsLeftAsWritten: () => slotIsLeftAsWritten,
|
|
124
|
+
sniffImageKind: () => sniffImageKind,
|
|
125
|
+
stallNeedsChoice: () => stallNeedsChoice,
|
|
126
|
+
tokeniserUleseOcrOrd: () => tokeniserUleseOcrOrd,
|
|
127
|
+
uleseOrdKjerne: () => uleseOrdKjerne,
|
|
128
|
+
unicodeNfkcCaseFold: () => unicodeNfkcCaseFold
|
|
129
|
+
});
|
|
130
|
+
module.exports = __toCommonJS(device_exports);
|
|
131
|
+
|
|
132
|
+
// src/request-body-slots.ts
|
|
133
|
+
function deepClone(v, seen) {
|
|
134
|
+
if (v === null || typeof v !== "object") return v;
|
|
135
|
+
const bag = seen ?? /* @__PURE__ */ new WeakSet();
|
|
136
|
+
if (bag.has(v)) {
|
|
137
|
+
throw new RequestBodyGuardError("request body contains a cycle");
|
|
138
|
+
}
|
|
139
|
+
bag.add(v);
|
|
140
|
+
try {
|
|
141
|
+
if (Array.isArray(v)) return v.map((x) => deepClone(x, bag));
|
|
142
|
+
if (v instanceof Map) {
|
|
143
|
+
return new Map([...v.entries()].map(([key, value]) => [key, deepClone(value, bag)]));
|
|
144
|
+
}
|
|
145
|
+
const out = {};
|
|
146
|
+
for (const k of Object.keys(v)) {
|
|
147
|
+
out[k] = deepClone(v[k], bag);
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
} finally {
|
|
151
|
+
bag.delete(v);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
var RequestBodyGuardError = class extends Error {
|
|
155
|
+
constructor(message) {
|
|
156
|
+
super(message);
|
|
157
|
+
this.code = "unreviewable_request_body";
|
|
158
|
+
this.name = "RequestBodyGuardError";
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
function slotIsLeftAsWritten(slot, value) {
|
|
162
|
+
return slot.policy === "reject-if-changed" || /^data:/i.test(value.trim());
|
|
163
|
+
}
|
|
164
|
+
function scanJsonArgumentLeaves(text) {
|
|
165
|
+
try {
|
|
166
|
+
JSON.parse(text);
|
|
167
|
+
} catch {
|
|
168
|
+
return void 0;
|
|
169
|
+
}
|
|
170
|
+
const leaves = [];
|
|
171
|
+
for (let index = 0; index < text.length; ) {
|
|
172
|
+
const char = text[index];
|
|
173
|
+
if (char === '"') {
|
|
174
|
+
const start = index;
|
|
175
|
+
index += 1;
|
|
176
|
+
while (index < text.length) {
|
|
177
|
+
if (text[index] === "\\") {
|
|
178
|
+
index += 2;
|
|
179
|
+
} else if (text[index] === '"') {
|
|
180
|
+
index += 1;
|
|
181
|
+
break;
|
|
182
|
+
} else {
|
|
183
|
+
index += 1;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const end = index;
|
|
187
|
+
let after = end;
|
|
188
|
+
while (after < text.length && /\s/.test(text[after])) after += 1;
|
|
189
|
+
if (text[after] === ":") continue;
|
|
190
|
+
const value = JSON.parse(text.slice(start, end));
|
|
191
|
+
if (typeof value === "string") leaves.push({ start, end, original: value, kind: "string", current: value });
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (char === "-" || char >= "0" && char <= "9") {
|
|
195
|
+
const start = index;
|
|
196
|
+
if (text[index] === "-") index += 1;
|
|
197
|
+
if (text[index] === "0") {
|
|
198
|
+
index += 1;
|
|
199
|
+
} else {
|
|
200
|
+
while (index < text.length && text[index] >= "0" && text[index] <= "9") index += 1;
|
|
201
|
+
}
|
|
202
|
+
if (text[index] === ".") {
|
|
203
|
+
index += 1;
|
|
204
|
+
while (index < text.length && text[index] >= "0" && text[index] <= "9") index += 1;
|
|
205
|
+
}
|
|
206
|
+
if (text[index] === "e" || text[index] === "E") {
|
|
207
|
+
index += 1;
|
|
208
|
+
if (text[index] === "+" || text[index] === "-") index += 1;
|
|
209
|
+
while (index < text.length && text[index] >= "0" && text[index] <= "9") index += 1;
|
|
210
|
+
}
|
|
211
|
+
const end = index;
|
|
212
|
+
const original = text.slice(start, end);
|
|
213
|
+
leaves.push({ start, end, original, kind: "number", current: original });
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
index += 1;
|
|
217
|
+
}
|
|
218
|
+
return leaves;
|
|
219
|
+
}
|
|
220
|
+
function renderJsonArgumentLeaves(text, leaves) {
|
|
221
|
+
let output = "";
|
|
222
|
+
let offset = 0;
|
|
223
|
+
for (const leaf of leaves) {
|
|
224
|
+
output += text.slice(offset, leaf.start);
|
|
225
|
+
output += leaf.current === leaf.original ? text.slice(leaf.start, leaf.end) : JSON.stringify(leaf.current);
|
|
226
|
+
offset = leaf.end;
|
|
227
|
+
}
|
|
228
|
+
return output + text.slice(offset);
|
|
229
|
+
}
|
|
230
|
+
var isRecord = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
231
|
+
var CONTENT_PART_KEYS_KEPT = /* @__PURE__ */ new Set([
|
|
232
|
+
"text",
|
|
233
|
+
"name",
|
|
234
|
+
"function_call",
|
|
235
|
+
"audio",
|
|
236
|
+
"input_audio",
|
|
237
|
+
"thinking",
|
|
238
|
+
"content",
|
|
239
|
+
"input",
|
|
240
|
+
"source",
|
|
241
|
+
"type",
|
|
242
|
+
"id",
|
|
243
|
+
"tool_use_id",
|
|
244
|
+
"tool_call_id",
|
|
245
|
+
"file_id",
|
|
246
|
+
"signature",
|
|
247
|
+
"cache_control",
|
|
248
|
+
"is_error",
|
|
249
|
+
"encrypted_content",
|
|
250
|
+
"encrypted_index",
|
|
251
|
+
"image_url",
|
|
252
|
+
"file"
|
|
253
|
+
]);
|
|
254
|
+
var KNOWN_CONTENT_BLOCK_TYPES = /* @__PURE__ */ new Set([
|
|
255
|
+
"text",
|
|
256
|
+
"image",
|
|
257
|
+
"document",
|
|
258
|
+
"tool_use",
|
|
259
|
+
"tool_result",
|
|
260
|
+
"server_tool_use",
|
|
261
|
+
"mcp_tool_use",
|
|
262
|
+
"thinking",
|
|
263
|
+
"redacted_thinking",
|
|
264
|
+
"input_text",
|
|
265
|
+
"input_image",
|
|
266
|
+
"input_audio",
|
|
267
|
+
"input_file",
|
|
268
|
+
"output_text",
|
|
269
|
+
"refusal",
|
|
270
|
+
"image_url",
|
|
271
|
+
"file",
|
|
272
|
+
"audio",
|
|
273
|
+
"output_audio",
|
|
274
|
+
"tool_call",
|
|
275
|
+
"function_call"
|
|
276
|
+
]);
|
|
277
|
+
function collectRequestBodyTextSlots(root) {
|
|
278
|
+
const slots = [];
|
|
279
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
280
|
+
const push = (holder, key, path, policy = "tokenise") => {
|
|
281
|
+
const cur = holder[key];
|
|
282
|
+
if (typeof cur !== "string" || cur.length === 0) return;
|
|
283
|
+
slots.push({
|
|
284
|
+
path,
|
|
285
|
+
policy,
|
|
286
|
+
get: () => holder[key],
|
|
287
|
+
set: (v) => {
|
|
288
|
+
holder[key] = v;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
const pushArrayItem = (arr, i, path, policy = "tokenise") => {
|
|
293
|
+
const cur = arr[i];
|
|
294
|
+
if (typeof cur !== "string" || cur.length === 0) return;
|
|
295
|
+
slots.push({
|
|
296
|
+
path,
|
|
297
|
+
policy,
|
|
298
|
+
get: () => arr[i],
|
|
299
|
+
set: (v) => {
|
|
300
|
+
arr[i] = v;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
const pushArrayNumber = (arr, i, path) => {
|
|
305
|
+
const original = arr[i];
|
|
306
|
+
if (typeof original !== "number" || !Number.isFinite(original)) return;
|
|
307
|
+
slots.push({
|
|
308
|
+
path,
|
|
309
|
+
policy: "json-number",
|
|
310
|
+
get: () => String(arr[i]),
|
|
311
|
+
set: (next) => {
|
|
312
|
+
if (next !== String(original)) arr[i] = next;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
const pushNumber = (holder, key, path) => {
|
|
317
|
+
const original = holder[key];
|
|
318
|
+
if (typeof original !== "number" || !Number.isFinite(original)) return;
|
|
319
|
+
slots.push({
|
|
320
|
+
path,
|
|
321
|
+
policy: "json-number",
|
|
322
|
+
get: () => String(holder[key]),
|
|
323
|
+
set: (next) => {
|
|
324
|
+
if (next !== String(original)) holder[key] = next;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
const jsonArgumentLeaves = (v, path, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
329
|
+
if (v && typeof v === "object") {
|
|
330
|
+
if (seen.has(v)) return;
|
|
331
|
+
seen.add(v);
|
|
332
|
+
}
|
|
333
|
+
if (Array.isArray(v)) {
|
|
334
|
+
v.forEach((value, i) => {
|
|
335
|
+
if (typeof value === "string") {
|
|
336
|
+
slots.push({
|
|
337
|
+
path: `${path}[${i}]`,
|
|
338
|
+
policy: "tokenise",
|
|
339
|
+
get: () => v[i],
|
|
340
|
+
set: (next) => {
|
|
341
|
+
v[i] = next;
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
} else if (typeof value !== "number") jsonArgumentLeaves(value, `${path}[${i}]`, seen);
|
|
345
|
+
});
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (!isRecord(v)) return;
|
|
349
|
+
for (const key of Object.keys(v)) {
|
|
350
|
+
const value = v[key];
|
|
351
|
+
if (typeof value === "string") {
|
|
352
|
+
slots.push({
|
|
353
|
+
path: `${path}.${key}`,
|
|
354
|
+
policy: "tokenise",
|
|
355
|
+
get: () => v[key],
|
|
356
|
+
set: (next) => {
|
|
357
|
+
v[key] = next;
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
} else if (typeof value !== "number") jsonArgumentLeaves(value, `${path}.${key}`, seen);
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
const jsonArgument = (holder, key, path) => {
|
|
364
|
+
const raw = holder[key];
|
|
365
|
+
if (typeof raw === "string") {
|
|
366
|
+
if (raw.length === 0) return;
|
|
367
|
+
const leaves = scanJsonArgumentLeaves(raw);
|
|
368
|
+
if (!leaves) {
|
|
369
|
+
push(holder, key, path);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
for (const leaf of leaves) {
|
|
373
|
+
if (leaf.kind === "number") continue;
|
|
374
|
+
slots.push({
|
|
375
|
+
path,
|
|
376
|
+
policy: "json-argument",
|
|
377
|
+
get: () => leaf.current,
|
|
378
|
+
set: (next) => {
|
|
379
|
+
leaf.current = next;
|
|
380
|
+
holder[key] = renderJsonArgumentLeaves(raw, leaves);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (Array.isArray(raw) || isRecord(raw)) jsonArgumentLeaves(raw, path);
|
|
387
|
+
};
|
|
388
|
+
const numericLeaf = (holder, key, path) => {
|
|
389
|
+
const raw = holder[key];
|
|
390
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || !Number.isInteger(raw)) return;
|
|
391
|
+
const digits = String(Math.trunc(Math.abs(raw))).replace(/\D/g, "");
|
|
392
|
+
if (digits.length >= 6 && digits.length <= 16) pushNumber(holder, key, path);
|
|
393
|
+
};
|
|
394
|
+
const jsonLeaves = (v, path) => {
|
|
395
|
+
if (v && typeof v === "object") {
|
|
396
|
+
if (visited.has(v)) return;
|
|
397
|
+
visited.add(v);
|
|
398
|
+
}
|
|
399
|
+
if (Array.isArray(v)) {
|
|
400
|
+
v.forEach((_, i) => {
|
|
401
|
+
pushArrayItem(v, i, `${path}[${i}]`);
|
|
402
|
+
jsonLeaves(v[i], `${path}[${i}]`);
|
|
403
|
+
});
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (v instanceof Map) {
|
|
407
|
+
let entryIndex = 0;
|
|
408
|
+
for (const [key, value] of v.entries()) {
|
|
409
|
+
const entryPath = `${path}[${entryIndex}]`;
|
|
410
|
+
entryIndex += 1;
|
|
411
|
+
if (typeof value === "string" && value.length > 0) {
|
|
412
|
+
slots.push({
|
|
413
|
+
path: entryPath,
|
|
414
|
+
policy: "tokenise",
|
|
415
|
+
get: () => v.get(key),
|
|
416
|
+
set: (next) => {
|
|
417
|
+
v.set(key, next);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
} else {
|
|
421
|
+
jsonLeaves(value, entryPath);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (!isRecord(v)) return;
|
|
427
|
+
for (const k of Object.keys(v)) {
|
|
428
|
+
push(v, k, `${path}.${k}`);
|
|
429
|
+
jsonLeaves(v[k], `${path}.${k}`);
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
const schemaLiteral = (v, path) => {
|
|
433
|
+
if (typeof v === "string") {
|
|
434
|
+
const holder = { value: v };
|
|
435
|
+
push(holder, "value", path, "reject-if-changed");
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
if (Array.isArray(v)) {
|
|
439
|
+
v.forEach((x, i) => schemaLiteral(x, `${path}[${i}]`));
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (!isRecord(v)) return;
|
|
443
|
+
for (const k of Object.keys(v)) schemaLiteral(v[k], `${path}.${k}`);
|
|
444
|
+
};
|
|
445
|
+
const schemaProse = (v, path) => {
|
|
446
|
+
if (Array.isArray(v)) {
|
|
447
|
+
v.forEach((x, i) => schemaProse(x, `${path}[${i}]`));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (!isRecord(v)) return;
|
|
451
|
+
push(v, "description", `${path}.description`);
|
|
452
|
+
push(v, "title", `${path}.title`);
|
|
453
|
+
if (Array.isArray(v.examples)) {
|
|
454
|
+
const ex = v.examples;
|
|
455
|
+
ex.forEach((_, i) => pushArrayItem(ex, i, `${path}.examples[${i}]`));
|
|
456
|
+
}
|
|
457
|
+
for (const k of Object.keys(v)) {
|
|
458
|
+
if (k === "description" || k === "title" || k === "examples") continue;
|
|
459
|
+
if (k === "enum" || k === "const" || k === "default") {
|
|
460
|
+
schemaLiteral(v[k], `${path}.${k}`);
|
|
461
|
+
} else {
|
|
462
|
+
schemaProse(v[k], `${path}.${k}`);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
const content = (holder, key, path) => {
|
|
467
|
+
const c = holder[key];
|
|
468
|
+
if (typeof c === "string") {
|
|
469
|
+
push(holder, key, path);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (c instanceof Map || isRecord(c)) {
|
|
473
|
+
jsonLeaves(c, path);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (!Array.isArray(c)) return;
|
|
477
|
+
c.forEach((part, i) => {
|
|
478
|
+
if (!isRecord(part)) return;
|
|
479
|
+
if (part.type === "thinking" || part.type === "redacted_thinking") return;
|
|
480
|
+
push(part, "text", `${path}[${i}].text`);
|
|
481
|
+
if (part.type !== "tool_use" && part.type !== "server_tool_use" && part.type !== "mcp_tool_use") {
|
|
482
|
+
push(part, "name", `${path}[${i}].name`);
|
|
483
|
+
}
|
|
484
|
+
if (isRecord(part.function_call)) jsonLeaves(part.function_call, `${path}[${i}].function_call`);
|
|
485
|
+
if (isRecord(part.audio)) jsonLeaves(part.audio, `${path}[${i}].audio`);
|
|
486
|
+
if (isRecord(part.input_audio)) jsonLeaves(part.input_audio, `${path}[${i}].input_audio`);
|
|
487
|
+
if (part.content !== void 0) content(part, "content", `${path}[${i}].content`);
|
|
488
|
+
if (isRecord(part.input)) jsonLeaves(part.input, `${path}[${i}].input`);
|
|
489
|
+
if (isRecord(part.source) && part.source.type === "text") {
|
|
490
|
+
push(part.source, "data", `${path}[${i}].source.data`);
|
|
491
|
+
}
|
|
492
|
+
if (isRecord(part.source) && part.source.type === "content" && part.source.content !== void 0) {
|
|
493
|
+
content(part.source, "content", `${path}[${i}].source.content`);
|
|
494
|
+
}
|
|
495
|
+
if (typeof part.source === "string") push(part, "source", `${path}[${i}].source`);
|
|
496
|
+
for (const key2 of Object.keys(part)) {
|
|
497
|
+
if (CONTENT_PART_KEYS_KEPT.has(key2)) continue;
|
|
498
|
+
const value = part[key2];
|
|
499
|
+
if (typeof value === "string") push(part, key2, `${path}[${i}].${key2}`);
|
|
500
|
+
else if (value !== null && typeof value === "object") jsonLeaves(value, `${path}[${i}].${key2}`);
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
const systemBlock = (part, path) => {
|
|
505
|
+
push(part, "text", `${path}.text`);
|
|
506
|
+
if (part.content !== void 0) content(part, "content", `${path}.content`);
|
|
507
|
+
};
|
|
508
|
+
const attachments = (a, path) => {
|
|
509
|
+
if (!Array.isArray(a)) return;
|
|
510
|
+
a.forEach((att, i) => {
|
|
511
|
+
if (isRecord(att)) {
|
|
512
|
+
push(att, "text", `${path}[${i}].text`);
|
|
513
|
+
push(att, "url", `${path}[${i}].url`, "reject-if-changed");
|
|
514
|
+
push(att, "name", `${path}[${i}].name`);
|
|
515
|
+
push(att, "filename", `${path}[${i}].filename`);
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
if (!isRecord(root)) return slots;
|
|
520
|
+
push(root, "preprompt", "preprompt");
|
|
521
|
+
push(root, "prompt", "prompt");
|
|
522
|
+
if (typeof root.input === "string") {
|
|
523
|
+
push(root, "input", "input");
|
|
524
|
+
} else if (Array.isArray(root.input)) {
|
|
525
|
+
const stringForm = root.input.every((value) => typeof value === "string");
|
|
526
|
+
const tokenIdForm = root.input.every((value) => Number.isInteger(value) || Array.isArray(value) && value.every((token) => Number.isInteger(token)));
|
|
527
|
+
if (stringForm) {
|
|
528
|
+
root.input.forEach((_, i) => pushArrayItem(root.input, i, `input[${i}]`));
|
|
529
|
+
} else if (!tokenIdForm) {
|
|
530
|
+
throw new RequestBodyGuardError("structured input body cannot be reviewed safely");
|
|
531
|
+
}
|
|
532
|
+
} else if (root.input !== void 0 && typeof root.input !== "number") {
|
|
533
|
+
throw new RequestBodyGuardError("input body cannot be reviewed safely");
|
|
534
|
+
}
|
|
535
|
+
jsonLeaves(root.metadata, "metadata");
|
|
536
|
+
if (typeof root.user === "string") push(root, "user", "user");
|
|
537
|
+
else if (root.user !== void 0) jsonLeaves(root.user, "user");
|
|
538
|
+
if (typeof root.system === "string") push(root, "system", "system");
|
|
539
|
+
else if (root.system instanceof Map) jsonLeaves(root.system, "system");
|
|
540
|
+
else if (Array.isArray(root.system)) {
|
|
541
|
+
root.system.forEach((part, i) => {
|
|
542
|
+
if (part instanceof Map) jsonLeaves(part, `system[${i}]`);
|
|
543
|
+
else if (isRecord(part)) systemBlock(part, `system[${i}]`);
|
|
544
|
+
});
|
|
545
|
+
} else if (isRecord(root.system)) systemBlock(root.system, "system");
|
|
546
|
+
push(root, "clipboard", "clipboard");
|
|
547
|
+
attachments(root.attachments, "attachments");
|
|
548
|
+
if (Array.isArray(root.messages)) {
|
|
549
|
+
root.messages.forEach((m, i) => {
|
|
550
|
+
if (!isRecord(m)) return;
|
|
551
|
+
if ("content" in m) content(m, "content", `messages[${i}].content`);
|
|
552
|
+
attachments(m.attachments, `messages[${i}].attachments`);
|
|
553
|
+
jsonLeaves(m.metadata, `messages[${i}].metadata`);
|
|
554
|
+
if (Array.isArray(m.tool_calls)) {
|
|
555
|
+
m.tool_calls.forEach((call, j) => {
|
|
556
|
+
if (!isRecord(call)) return;
|
|
557
|
+
const fn = call.function;
|
|
558
|
+
if (isRecord(fn)) {
|
|
559
|
+
jsonArgument(fn, "arguments", `messages[${i}].tool_calls[${j}].function.arguments`);
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
if (isRecord(m.function_call)) {
|
|
564
|
+
const call = m.function_call;
|
|
565
|
+
jsonArgument(call, "arguments", `messages[${i}].function_call.arguments`);
|
|
566
|
+
for (const [key, value] of Object.entries(call)) {
|
|
567
|
+
if (key !== "name" && key !== "arguments") jsonLeaves(value, `messages[${i}].function_call.${key}`);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (isRecord(m.audio)) jsonLeaves(m.audio, `messages[${i}].audio`);
|
|
571
|
+
if (isRecord(m.input_audio)) jsonLeaves(m.input_audio, `messages[${i}].input_audio`);
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
if (Array.isArray(root.tools)) {
|
|
575
|
+
root.tools.forEach((t, i) => {
|
|
576
|
+
if (!isRecord(t)) return;
|
|
577
|
+
push(t, "description", `tools[${i}].description`);
|
|
578
|
+
if (t.input_schema !== void 0) schemaProse(t.input_schema, `tools[${i}].input_schema`);
|
|
579
|
+
const fn = t.function;
|
|
580
|
+
if (isRecord(fn)) {
|
|
581
|
+
push(fn, "description", `tools[${i}].function.description`);
|
|
582
|
+
if (fn.parameters !== void 0) schemaProse(fn.parameters, `tools[${i}].function.parameters`);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
return slots;
|
|
587
|
+
}
|
|
588
|
+
var PLACEMENT_TOOL_KEY = "A key inside tool-call arguments looks like personal data. Keys there follow the tool's schema, so it was not replaced. It is sent as written.";
|
|
589
|
+
var PLACEMENT_SCHEMA = "A tool schema holds a fixed value or property name that looks like personal data. Replacing it would change the tool's contract, so it was not replaced. It is sent as written.";
|
|
590
|
+
var PLACEMENT_NUMBER = "A number looks like personal data. A number cannot be replaced without changing its type, so it was not replaced. It is sent as written.";
|
|
591
|
+
var PLACEMENT_MEDIA = "This request includes an image, audio clip or file that this device did not read. It is sent as provided.";
|
|
592
|
+
var PLACEMENT_METADATA_KEY_LEFT = "A personal detail in a metadata key was left as written. Metadata keys stay as written, so it was not replaced. It is sent as written.";
|
|
593
|
+
var PLACEMENT_TOOL_NAME = "A tool name or tool_choice looks like personal data. Those identifiers are not replaced. It is sent as written.";
|
|
594
|
+
var PLACEMENT_UNKNOWN_BLOCK = "This request includes a content block of a type this SDK does not know. Its text was checked like other text and it is sent.";
|
|
595
|
+
var PLACEMENT_ENCODED = "A value looks like encoded data. This device did not decode it, so it was not replaced. It is sent as written.";
|
|
596
|
+
function looksLikeLongId(value) {
|
|
597
|
+
if (!Number.isFinite(value) || !Number.isInteger(value)) return false;
|
|
598
|
+
const digits = String(Math.trunc(Math.abs(value))).replace(/\D/g, "");
|
|
599
|
+
return digits.length >= 6 && digits.length <= 16;
|
|
600
|
+
}
|
|
601
|
+
function collectValuePlacementWarnings(root, personal, options) {
|
|
602
|
+
let toolKey = false;
|
|
603
|
+
let schema = false;
|
|
604
|
+
let number = false;
|
|
605
|
+
let media = false;
|
|
606
|
+
let metadataKey = false;
|
|
607
|
+
let toolName = false;
|
|
608
|
+
let encoded = false;
|
|
609
|
+
const allowedTopLevel = /* @__PURE__ */ new Set(["max_tokens", "temperature", "top_p", "n"]);
|
|
610
|
+
const noteMediaRecord = (value) => {
|
|
611
|
+
const source = value.source;
|
|
612
|
+
if (isRecord(source) && source.type !== "text") {
|
|
613
|
+
if (typeof source.data === "string" && source.data !== "") media = true;
|
|
614
|
+
if (typeof source.url === "string" && source.url !== "") media = true;
|
|
615
|
+
}
|
|
616
|
+
const imageUrl = value.image_url;
|
|
617
|
+
if (isRecord(imageUrl) && typeof imageUrl.url === "string" && imageUrl.url !== "") media = true;
|
|
618
|
+
const file = value.file;
|
|
619
|
+
if (isRecord(file) && typeof file.file_data === "string" && file.file_data !== "") media = true;
|
|
620
|
+
};
|
|
621
|
+
const noteAttachments = (value) => {
|
|
622
|
+
if (!Array.isArray(value)) return;
|
|
623
|
+
for (const item of value) {
|
|
624
|
+
if (!isRecord(item)) continue;
|
|
625
|
+
if (item.data !== void 0 && item.data !== null && item.data !== "") media = true;
|
|
626
|
+
if (typeof item.url === "string" && item.url !== "") media = true;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
const walkArgs = (value) => {
|
|
630
|
+
if (Array.isArray(value)) {
|
|
631
|
+
value.forEach((item) => walkArgs(item));
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if (!isRecord(value)) return;
|
|
635
|
+
for (const key of Object.keys(value)) {
|
|
636
|
+
if (personal(key)) toolKey = true;
|
|
637
|
+
walkArgs(value[key]);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
const probeLiteral = (value) => {
|
|
641
|
+
if (typeof value === "string") {
|
|
642
|
+
if (personal(value)) schema = true;
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
if (Array.isArray(value)) {
|
|
646
|
+
value.forEach((item) => probeLiteral(item));
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
if (!isRecord(value)) return;
|
|
650
|
+
for (const inner of Object.values(value)) probeLiteral(inner);
|
|
651
|
+
};
|
|
652
|
+
const walkSchema = (value, propertyNames = false) => {
|
|
653
|
+
if (Array.isArray(value)) {
|
|
654
|
+
value.forEach((item) => walkSchema(item, propertyNames));
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (!isRecord(value)) return;
|
|
658
|
+
if (propertyNames) {
|
|
659
|
+
for (const key of Object.keys(value)) {
|
|
660
|
+
if (personal(key)) schema = true;
|
|
661
|
+
walkSchema(value[key], false);
|
|
662
|
+
}
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
for (const key of Object.keys(value)) {
|
|
666
|
+
if (key === "enum" || key === "const" || key === "default") probeLiteral(value[key]);
|
|
667
|
+
else if (key === "properties" || key === "patternProperties") walkSchema(value[key], true);
|
|
668
|
+
else if (key === "items" || key === "additionalProperties" || key === "unevaluatedProperties" || key === "not" || key === "contains" || key === "anyOf" || key === "oneOf" || key === "allOf" || key === "if" || key === "then" || key === "else" || key === "$defs" || key === "definitions" || key === "dependentSchemas" || key === "prefixItems") walkSchema(value[key], false);
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
const walkNumbers = (value, field, top) => {
|
|
672
|
+
if (typeof value === "number") {
|
|
673
|
+
if (top && field !== void 0 && allowedTopLevel.has(field)) return;
|
|
674
|
+
if (looksLikeLongId(value)) number = true;
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
if (Array.isArray(value)) {
|
|
678
|
+
value.forEach((item) => walkNumbers(item, void 0, false));
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
if (!isRecord(value)) return;
|
|
682
|
+
const childrenAreTop = top && field === void 0;
|
|
683
|
+
for (const key of Object.keys(value)) walkNumbers(value[key], key, childrenAreTop);
|
|
684
|
+
};
|
|
685
|
+
const walkMedia = (value) => {
|
|
686
|
+
if (typeof value === "string") {
|
|
687
|
+
if (/^data:/i.test(value.trim())) media = true;
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
if (Array.isArray(value)) {
|
|
691
|
+
value.forEach((item) => walkMedia(item));
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
if (!isRecord(value)) return;
|
|
695
|
+
noteMediaRecord(value);
|
|
696
|
+
for (const key of Object.keys(value)) walkMedia(value[key]);
|
|
697
|
+
};
|
|
698
|
+
if (isRecord(root)) {
|
|
699
|
+
noteAttachments(root.attachments);
|
|
700
|
+
if (Array.isArray(root.messages)) {
|
|
701
|
+
root.messages.forEach((message) => {
|
|
702
|
+
if (!isRecord(message)) return;
|
|
703
|
+
noteAttachments(message.attachments);
|
|
704
|
+
walkMetadataKeys(message.metadata);
|
|
705
|
+
noteToolChoice(message.tool_choice);
|
|
706
|
+
if (isRecord(message.function_call)) noteToolName(message.function_call.name);
|
|
707
|
+
if (Array.isArray(message.content)) {
|
|
708
|
+
for (const part of message.content) {
|
|
709
|
+
if (!isRecord(part)) continue;
|
|
710
|
+
if (part.type === "tool_use" || part.type === "server_tool_use" || part.type === "mcp_tool_use") noteToolName(part.name);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
if (Array.isArray(message.tool_calls)) {
|
|
714
|
+
for (const call of message.tool_calls) {
|
|
715
|
+
if (!isRecord(call) || !isRecord(call.function)) continue;
|
|
716
|
+
noteToolName(call.function.name);
|
|
717
|
+
const args = call.function.arguments;
|
|
718
|
+
if (typeof args === "string") {
|
|
719
|
+
try {
|
|
720
|
+
const parsed = JSON.parse(args);
|
|
721
|
+
walkArgs(parsed);
|
|
722
|
+
walkNumbers(parsed, void 0, false);
|
|
723
|
+
} catch {
|
|
724
|
+
}
|
|
725
|
+
} else {
|
|
726
|
+
walkArgs(args);
|
|
727
|
+
walkNumbers(args, void 0, false);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (isRecord(message.function_call)) {
|
|
732
|
+
const args = message.function_call.arguments;
|
|
733
|
+
if (typeof args === "string") {
|
|
734
|
+
try {
|
|
735
|
+
const parsed = JSON.parse(args);
|
|
736
|
+
walkArgs(parsed);
|
|
737
|
+
walkNumbers(parsed, void 0, false);
|
|
738
|
+
} catch {
|
|
739
|
+
}
|
|
740
|
+
} else {
|
|
741
|
+
walkArgs(args);
|
|
742
|
+
walkNumbers(args, void 0, false);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
const content = message.content;
|
|
746
|
+
if (Array.isArray(content)) {
|
|
747
|
+
for (const part of content) {
|
|
748
|
+
if (isRecord(part) && isRecord(part.input)) walkArgs(part.input);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
if (Array.isArray(root.tools)) {
|
|
754
|
+
for (const tool of root.tools) {
|
|
755
|
+
if (!isRecord(tool)) continue;
|
|
756
|
+
noteToolName(tool.name);
|
|
757
|
+
if (isRecord(tool.function)) noteToolName(tool.function.name);
|
|
758
|
+
if (tool.input_schema !== void 0) walkSchema(tool.input_schema, false);
|
|
759
|
+
if (isRecord(tool.function) && tool.function.parameters !== void 0) walkSchema(tool.function.parameters, false);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
noteToolChoice(root.tool_choice);
|
|
763
|
+
walkMetadataKeys(root.metadata);
|
|
764
|
+
}
|
|
765
|
+
let unknownBlock = false;
|
|
766
|
+
const walkBlockTypes = (value) => {
|
|
767
|
+
if (!Array.isArray(value)) return;
|
|
768
|
+
for (const part of value) {
|
|
769
|
+
if (!isRecord(part)) continue;
|
|
770
|
+
if (typeof part.type === "string" && !KNOWN_CONTENT_BLOCK_TYPES.has(part.type)) unknownBlock = true;
|
|
771
|
+
walkBlockTypes(part.content);
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
if (isRecord(root) && Array.isArray(root.messages)) {
|
|
775
|
+
for (const message of root.messages) if (isRecord(message)) walkBlockTypes(message.content);
|
|
776
|
+
}
|
|
777
|
+
if (isRecord(root)) walkBlockTypes(root.system);
|
|
778
|
+
walkNumbers(root, void 0, true);
|
|
779
|
+
walkMedia(root);
|
|
780
|
+
for (const slot of collectRequestBodyTextSlots(root)) {
|
|
781
|
+
if (slot.policy === "reject-if-changed" || slot.policy === "json-number") continue;
|
|
782
|
+
const value = slot.get();
|
|
783
|
+
if (isStandaloneEncodedProse(value, slot.path)) encoded = true;
|
|
784
|
+
}
|
|
785
|
+
const warnings = [];
|
|
786
|
+
if (toolKey) warnings.push({ reason: "value_not_replaced", message: PLACEMENT_TOOL_KEY });
|
|
787
|
+
if (toolName) warnings.push({ reason: "value_not_replaced", message: PLACEMENT_TOOL_NAME });
|
|
788
|
+
if (metadataKey && options?.metadataKeys !== false) {
|
|
789
|
+
warnings.push({ reason: "value_not_replaced", message: PLACEMENT_METADATA_KEY_LEFT });
|
|
790
|
+
}
|
|
791
|
+
if (schema) warnings.push({ reason: "value_not_replaced", message: PLACEMENT_SCHEMA });
|
|
792
|
+
if (number) warnings.push({ reason: "value_not_replaced", message: PLACEMENT_NUMBER });
|
|
793
|
+
if (encoded) warnings.push({ reason: "value_not_replaced", message: PLACEMENT_ENCODED });
|
|
794
|
+
if (media) warnings.push({ reason: "media_not_checked", message: PLACEMENT_MEDIA });
|
|
795
|
+
if (unknownBlock) warnings.push({ reason: "unrecognised_block", message: PLACEMENT_UNKNOWN_BLOCK });
|
|
796
|
+
return warnings;
|
|
797
|
+
function noteToolName(value) {
|
|
798
|
+
if (typeof value === "string" && value !== "" && personal(value)) toolName = true;
|
|
799
|
+
}
|
|
800
|
+
function noteToolChoice(choice) {
|
|
801
|
+
if (typeof choice === "string") {
|
|
802
|
+
noteToolName(choice);
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
if (!isRecord(choice)) return;
|
|
806
|
+
noteToolName(choice.name);
|
|
807
|
+
if (isRecord(choice.function)) noteToolName(choice.function.name);
|
|
808
|
+
}
|
|
809
|
+
function walkMetadataKeys(value) {
|
|
810
|
+
if (Array.isArray(value)) {
|
|
811
|
+
value.forEach((item) => walkMetadataKeys(item));
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
if (!isRecord(value)) return;
|
|
815
|
+
for (const key of Object.keys(value)) {
|
|
816
|
+
if (personal(key)) metadataKey = true;
|
|
817
|
+
walkMetadataKeys(value[key]);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
function isStandaloneEncodedProse(value, path) {
|
|
822
|
+
const text = value.trim();
|
|
823
|
+
if (/^data:/i.test(text)) return false;
|
|
824
|
+
if (!/^[A-Za-z0-9+/_-]{4,}={0,2}$/.test(text)) return false;
|
|
825
|
+
const sensitiveSlot = /(?:^|\.)(?:password|passphrase|secret|credential|token)$/i.test(path);
|
|
826
|
+
if (text.length < 12 && !sensitiveSlot) return false;
|
|
827
|
+
if (!/[0-9+/_=-]/.test(text) && !sensitiveSlot) return false;
|
|
828
|
+
try {
|
|
829
|
+
const decoder = globalThis.atob;
|
|
830
|
+
if (typeof decoder !== "function") return true;
|
|
831
|
+
const normalised = text.replace(/-/g, "+").replace(/_/g, "/");
|
|
832
|
+
const padded = normalised.padEnd(Math.ceil(normalised.length / 4) * 4, "=");
|
|
833
|
+
decoder(padded);
|
|
834
|
+
return true;
|
|
835
|
+
} catch {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
function assertContractLiteralSafe(_original, _tokenised, _path) {
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// src/device/coverage-choice-latch.ts
|
|
844
|
+
function createCoverageChoiceLatch() {
|
|
845
|
+
let closed = false;
|
|
846
|
+
const subs = /* @__PURE__ */ new Set();
|
|
847
|
+
const set = (v) => {
|
|
848
|
+
if (closed === v) return;
|
|
849
|
+
closed = v;
|
|
850
|
+
const errors = [];
|
|
851
|
+
for (const fn of [...subs]) {
|
|
852
|
+
try {
|
|
853
|
+
fn(closed);
|
|
854
|
+
} catch (error) {
|
|
855
|
+
errors.push(error);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (errors.length > 0) throw errors[0];
|
|
859
|
+
};
|
|
860
|
+
return {
|
|
861
|
+
isClosed: () => closed,
|
|
862
|
+
close: () => set(true),
|
|
863
|
+
open: () => set(false),
|
|
864
|
+
subscribe(fn) {
|
|
865
|
+
subs.add(fn);
|
|
866
|
+
try {
|
|
867
|
+
fn(closed);
|
|
868
|
+
} catch (error) {
|
|
869
|
+
subs.delete(fn);
|
|
870
|
+
throw error;
|
|
871
|
+
}
|
|
872
|
+
return () => {
|
|
873
|
+
subs.delete(fn);
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
var coverageChoiceLatch = createCoverageChoiceLatch();
|
|
879
|
+
|
|
880
|
+
// src/device/final-card-backstop.ts
|
|
881
|
+
var MAX_GAP = 6;
|
|
882
|
+
var SALT_LETTERS = 12;
|
|
883
|
+
var MIN_LEN = 13;
|
|
884
|
+
var MAX_LEN = 19;
|
|
885
|
+
var DOUBLED = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];
|
|
886
|
+
var DECIMAL = /\p{Nd}/u;
|
|
887
|
+
var OTHER_NUMBER = /\p{No}/u;
|
|
888
|
+
var SEPARATOR = /[\s\-./\u0085\u00AD\u00B7\u200B-\u200F\u2010-\u2015\u2027\u202A-\u202E\u2060\u2066-\u2069\u2212\u2219\uFEFF]/u;
|
|
889
|
+
var SHORT_FORM_SEPARATORS = /[,|_;:+*'\uFF0D\uFF0C\uFE50\uFE10\u3001\uFE51\uFE11\uFF64\u060C\u066C\uFF0F\u3002\uFF1B\uFF1A\uFF0B\uFF0A\uFF07\uFF3F\uFF5C\uFE63\u2044\u2215\u2022\u30FB]/u;
|
|
890
|
+
var SHORT_FORM_PUNCTUATION = "[,|_;:+*'\\uFF0D\\uFF0C\\uFE50\\uFE10\\u3001\\uFE51\\uFE11\\uFF64\\u060C\\u066C\\uFF0F\\u3002\\uFF1B\\uFF1A\\uFF0B\\uFF0A\\uFF07\\uFF3F\\uFF5C\\uFE63\\u2044\\u2215\\u2022\\u30FB]";
|
|
891
|
+
var SHORT_FORM_HORIZONTAL = "[ \\t\\u00A0\\u1680\\u2000-\\u200A\\u202F\\u205F\\u3000\\-./\\u00AD\\u00B7\\u200B-\\u200F\\u2010-\\u2015\\u2027\\u202A-\\u202E\\u2060\\u2066-\\u2069\\u2212\\u2219\\uFEFF]";
|
|
892
|
+
var SHORT_FORM_HORIZONTAL_CHAR = new RegExp(`^${SHORT_FORM_HORIZONTAL}$`, "u");
|
|
893
|
+
var SHORT_FORM_LINE_BREAK = "(?:\\r\\n|[\\n\\r\\u000B\\u000C\\u0085\\u2028\\u2029])";
|
|
894
|
+
var SHORT_FORM_GAP = `((?:${SHORT_FORM_PUNCTUATION}|${SHORT_FORM_HORIZONTAL}|${SHORT_FORM_LINE_BREAK}){1,9})`;
|
|
895
|
+
var SHORT_FORMS = [
|
|
896
|
+
// No trailing digit guard: `4111,1111,1111,11119` is still the 4-4-4-4 card. The 4-6-5 guard stays (AA-29).
|
|
897
|
+
new RegExp(`[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{4}`, "gu"),
|
|
898
|
+
new RegExp(`[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{6}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{5}(?![\\p{Nd}\\p{No}])`, "gu"),
|
|
899
|
+
new RegExp(`[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{3}(?![\\p{Nd}\\p{No}])`, "gu"),
|
|
900
|
+
new RegExp(`[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{4}${SHORT_FORM_GAP}[\\p{Nd}\\p{No}]{3}(?![\\p{Nd}\\p{No}])`, "gu")
|
|
901
|
+
];
|
|
902
|
+
function isShortFormGap(gap) {
|
|
903
|
+
let punctuation = 0;
|
|
904
|
+
let horizontal = 0;
|
|
905
|
+
let lineBreaks = 0;
|
|
906
|
+
for (let i = 0; i < gap.length; i++) {
|
|
907
|
+
if (gap.startsWith("\r\n", i)) {
|
|
908
|
+
horizontal++;
|
|
909
|
+
lineBreaks++;
|
|
910
|
+
i++;
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
const char = gap[i];
|
|
914
|
+
if (SHORT_FORM_SEPARATORS.test(char)) punctuation++;
|
|
915
|
+
else if (SHORT_FORM_HORIZONTAL_CHAR.test(char)) horizontal++;
|
|
916
|
+
else if (/[\n\r\u000B\u000C\u0085\u2028\u2029]/u.test(char)) {
|
|
917
|
+
horizontal++;
|
|
918
|
+
lineBreaks++;
|
|
919
|
+
} else return false;
|
|
920
|
+
}
|
|
921
|
+
return punctuation <= 3 && horizontal <= 6 && lineBreaks <= 2 && !lineBreakPipeIsTableJoin(gap, lineBreaks) && !(lineBreaks > 1 && !gap.includes(","));
|
|
922
|
+
}
|
|
923
|
+
function lineBreakPipeIsTableJoin(gap, lineBreaks) {
|
|
924
|
+
if (lineBreaks === 0 || !gap.includes("|")) return false;
|
|
925
|
+
for (let i = 0; i < gap.length; i++) {
|
|
926
|
+
if (gap[i] !== "|") continue;
|
|
927
|
+
const prev = i > 0 ? gap[i - 1] : "";
|
|
928
|
+
const next = i + 1 < gap.length ? gap[i + 1] : "";
|
|
929
|
+
if (prev === " " || prev === " " || prev === "\xA0" || next === " " || next === " " || next === "\xA0") return true;
|
|
930
|
+
}
|
|
931
|
+
return false;
|
|
932
|
+
}
|
|
933
|
+
var digitCache = /* @__PURE__ */ new Map();
|
|
934
|
+
function digitValue(cp) {
|
|
935
|
+
if (cp >= 48 && cp <= 57) return cp - 48;
|
|
936
|
+
if (cp < 128) return -1;
|
|
937
|
+
const cached = digitCache.get(cp);
|
|
938
|
+
if (cached !== void 0) return cached;
|
|
939
|
+
let value = -1;
|
|
940
|
+
if (DECIMAL.test(String.fromCodePoint(cp))) {
|
|
941
|
+
let start = cp;
|
|
942
|
+
while (start > 0 && DECIMAL.test(String.fromCodePoint(start - 1))) start--;
|
|
943
|
+
value = (cp - start) % 10;
|
|
944
|
+
} else if (OTHER_NUMBER.test(String.fromCodePoint(cp))) {
|
|
945
|
+
const normalized = String.fromCodePoint(cp).normalize("NFKC");
|
|
946
|
+
if ([...normalized].length === 1 && DECIMAL.test(normalized)) value = digitValue(normalized.codePointAt(0));
|
|
947
|
+
}
|
|
948
|
+
digitCache.set(cp, value);
|
|
949
|
+
return value;
|
|
950
|
+
}
|
|
951
|
+
function shortFormSeparatorOffsets(body) {
|
|
952
|
+
const offsets = /* @__PURE__ */ new Set();
|
|
953
|
+
addExactGroupedCardOffsets(body, offsets);
|
|
954
|
+
if (!SHORT_FORM_SEPARATORS.test(body)) return offsets;
|
|
955
|
+
for (const pattern of SHORT_FORMS) {
|
|
956
|
+
pattern.lastIndex = 0;
|
|
957
|
+
let match;
|
|
958
|
+
while (match = pattern.exec(body)) {
|
|
959
|
+
pattern.lastIndex = match.index + 1;
|
|
960
|
+
const gaps = match.slice(1);
|
|
961
|
+
if (gaps.some((gap) => !isShortFormGap(gap))) continue;
|
|
962
|
+
let cursor = match.index;
|
|
963
|
+
for (let group = 0; group < gaps.length; group++) {
|
|
964
|
+
cursor += group === 0 ? 4 : pattern === SHORT_FORMS[1] && group === 1 ? 6 : 4;
|
|
965
|
+
for (let i = 0; i < gaps[group].length; i++) {
|
|
966
|
+
offsets.add(cursor + i);
|
|
967
|
+
}
|
|
968
|
+
cursor += gaps[group].length;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return offsets;
|
|
973
|
+
}
|
|
974
|
+
function addExactGroupedCardOffsets(body, offsets) {
|
|
975
|
+
const n = body.length;
|
|
976
|
+
let i = 0;
|
|
977
|
+
while (i < n) {
|
|
978
|
+
const cp0 = body.codePointAt(i);
|
|
979
|
+
const width0 = cp0 > 65535 ? 2 : 1;
|
|
980
|
+
if (digitValue(cp0) < 0) {
|
|
981
|
+
i += width0;
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
const groups = [];
|
|
985
|
+
let p = i;
|
|
986
|
+
while (p < n) {
|
|
987
|
+
const from = p;
|
|
988
|
+
let digits2 = "";
|
|
989
|
+
while (p < n) {
|
|
990
|
+
const cp = body.codePointAt(p);
|
|
991
|
+
const width = cp > 65535 ? 2 : 1;
|
|
992
|
+
const value = digitValue(cp);
|
|
993
|
+
if (value < 0) break;
|
|
994
|
+
digits2 += String(value);
|
|
995
|
+
p += width;
|
|
996
|
+
}
|
|
997
|
+
if (digits2.length === 0) break;
|
|
998
|
+
groups.push({ from, to: p, digits: digits2 });
|
|
999
|
+
let q = p;
|
|
1000
|
+
while (q < n && q - p < 9 && digitValue(body.codePointAt(q)) < 0) {
|
|
1001
|
+
const cp = body.codePointAt(q);
|
|
1002
|
+
q += cp > 65535 ? 2 : 1;
|
|
1003
|
+
}
|
|
1004
|
+
const gap = body.slice(p, q);
|
|
1005
|
+
if (gap.length < 1 || gap.length > 9 || !isShortFormGap(gap)) break;
|
|
1006
|
+
if (q >= n || digitValue(body.codePointAt(q)) < 0) break;
|
|
1007
|
+
p = q;
|
|
1008
|
+
}
|
|
1009
|
+
const lengths = groups.map((group) => group.digits.length);
|
|
1010
|
+
const digits = groups.map((group) => group.digits).join("");
|
|
1011
|
+
if (groups.length >= 2 && EXACT_SHORT_JSON_SHAPES.some((shape) => sameShape(lengths, shape)) && digitsPassCard(digits)) {
|
|
1012
|
+
const from = groups[0].from;
|
|
1013
|
+
const to = groups[groups.length - 1].to;
|
|
1014
|
+
for (let k = from; k < to; k++) {
|
|
1015
|
+
if (digitValue(body.codePointAt(k)) < 0) offsets.add(k);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
const last = groups.length > 0 ? groups[groups.length - 1].to : i + width0;
|
|
1019
|
+
i = last > i ? last : i + width0;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
function isSeparator(cp, offset, shortFormOffsets) {
|
|
1023
|
+
if (cp === 32 || cp === 45 || cp === 46 || cp === 47 || cp === 10 || cp === 13 || cp === 9 || cp === 11 || cp === 12) return true;
|
|
1024
|
+
if (shortFormOffsets.has(offset)) return true;
|
|
1025
|
+
if (cp < 128) return false;
|
|
1026
|
+
return SEPARATOR.test(String.fromCodePoint(cp));
|
|
1027
|
+
}
|
|
1028
|
+
function plausible(d, s, len) {
|
|
1029
|
+
const p1 = d[s];
|
|
1030
|
+
const p2 = p1 * 10 + d[s + 1];
|
|
1031
|
+
const p3 = p2 * 10 + d[s + 2];
|
|
1032
|
+
const p4 = p3 * 10 + d[s + 3];
|
|
1033
|
+
const p6 = len >= 6 ? p4 * 100 + d[s + 4] * 10 + d[s + 5] : 0;
|
|
1034
|
+
if (p1 === 4) return len === 13 || len === 16 || len === 19;
|
|
1035
|
+
if (len === 16 && (p2 >= 51 && p2 <= 55 || p4 >= 2221 && p4 <= 2720)) return true;
|
|
1036
|
+
if (len === 15 && (p2 === 34 || p2 === 37)) return true;
|
|
1037
|
+
if (len >= 16 && (p4 === 6011 || p2 === 65 || p3 >= 644 && p3 <= 649)) return true;
|
|
1038
|
+
if (len >= 16 && p2 === 62) return true;
|
|
1039
|
+
if (len >= 16 && p6 >= 622126 && p6 <= 622925) return true;
|
|
1040
|
+
if (len >= 14 && (p3 >= 300 && p3 <= 305 || p4 === 3095 || p2 === 36 || p2 === 38 || p2 === 39)) return true;
|
|
1041
|
+
if (len >= 16 && p4 >= 3528 && p4 <= 3589) return true;
|
|
1042
|
+
if (len >= 16 && p4 >= 2200 && p4 <= 2204) return true;
|
|
1043
|
+
if (len === 16 && (p3 === 508 || p2 === 81 || p2 === 82 || p4 === 9792 || p4 === 5019)) return true;
|
|
1044
|
+
if (len >= 13 && (p4 === 5018 || p4 === 5020 || p4 === 5038 || p4 === 5893 || p4 === 6304 || p4 === 6759 || p4 >= 6761 && p4 <= 6763)) return true;
|
|
1045
|
+
return false;
|
|
1046
|
+
}
|
|
1047
|
+
var LETTERS = "abcdefghijklmnop";
|
|
1048
|
+
function randomSalt() {
|
|
1049
|
+
const bytes = new Uint8Array(SALT_LETTERS);
|
|
1050
|
+
const c = globalThis.crypto;
|
|
1051
|
+
if (c?.getRandomValues) c.getRandomValues(bytes);
|
|
1052
|
+
else for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
1053
|
+
let salt = "";
|
|
1054
|
+
for (let i = 0; i < SALT_LETTERS; i++) salt += LETTERS[bytes[i] & 15];
|
|
1055
|
+
return salt;
|
|
1056
|
+
}
|
|
1057
|
+
function freshSalt(body, reserved) {
|
|
1058
|
+
const keys = reserved ? [...reserved] : [];
|
|
1059
|
+
for (let attempt = 0; ; attempt++) {
|
|
1060
|
+
const salt = randomSalt();
|
|
1061
|
+
const prefix = `[CLK-CARD-${salt}`;
|
|
1062
|
+
if (attempt < 16 && (body.includes(prefix) || keys.some((k) => k.startsWith(prefix)))) continue;
|
|
1063
|
+
return salt;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
var PAIR = Array.from({ length: 256 }, (_, b) => LETTERS[b >> 4] + LETTERS[b & 15]);
|
|
1067
|
+
function markerAt(salt, index) {
|
|
1068
|
+
return `[CLK-CARD-${salt}${PAIR[index >>> 16 & 255]}${PAIR[index >>> 8 & 255]}${PAIR[index & 255]}]`;
|
|
1069
|
+
}
|
|
1070
|
+
function markerContext(body, reserved) {
|
|
1071
|
+
return { salt: freshSalt(body, reserved), index: 0 };
|
|
1072
|
+
}
|
|
1073
|
+
function finalCardBackstop(body, reserved) {
|
|
1074
|
+
const context = markerContext(body, reserved);
|
|
1075
|
+
const encoded = /%[0-9a-fA-F]{2}/u.test(body) ? lockPercentEncodedDigits(body, reserved, context) : lockJsonBoundaryCardRuns(body, reserved, context);
|
|
1076
|
+
const plain = finalCardBackstopWithContext(encoded.body, reserved, context);
|
|
1077
|
+
if (encoded.locked === 0) return plain;
|
|
1078
|
+
return { body: plain.body, locked: encoded.locked + plain.locked, map: { ...encoded.map, ...plain.map } };
|
|
1079
|
+
}
|
|
1080
|
+
function finalCardBackstopToFixedPoint(body, reserved, maxPasses = 5, firstPass = finalCardBackstop) {
|
|
1081
|
+
const reservedKeys = [...reserved ?? []];
|
|
1082
|
+
const passLimit = Math.max(1, Math.min(5, Math.floor(maxPasses)));
|
|
1083
|
+
let current = firstPass(body, reservedKeys);
|
|
1084
|
+
let total = current.locked;
|
|
1085
|
+
const map = { ...current.map };
|
|
1086
|
+
for (let pass = 1; current.locked > 0 && pass < passLimit; pass++) {
|
|
1087
|
+
current = finalCardBackstopWithContext(current.body, [...reservedKeys, ...Object.keys(map)]);
|
|
1088
|
+
Object.assign(map, current.map);
|
|
1089
|
+
total += current.locked;
|
|
1090
|
+
}
|
|
1091
|
+
if (current.locked > 0) {
|
|
1092
|
+
const verification = finalCardBackstopWithContext(current.body, [...reservedKeys, ...Object.keys(map)]);
|
|
1093
|
+
if (verification.locked > 0) throw new Error("Card backstop did not reach a fixed point.");
|
|
1094
|
+
}
|
|
1095
|
+
return { body: current.body, locked: total, map };
|
|
1096
|
+
}
|
|
1097
|
+
function hasUnprotectedCardJson(serialized) {
|
|
1098
|
+
return finalCardBackstopJson(serialized).locked > 0;
|
|
1099
|
+
}
|
|
1100
|
+
function finalCardBackstopJsonToFixedPoint(serialized, reserved, maxPasses = 5, firstPass = finalCardBackstopJson) {
|
|
1101
|
+
const reservedKeys = [...reserved ?? []];
|
|
1102
|
+
const passLimit = Math.max(1, Math.min(5, Math.floor(maxPasses)));
|
|
1103
|
+
let current = firstPass(serialized, reservedKeys);
|
|
1104
|
+
let total = current.locked;
|
|
1105
|
+
const map = { ...current.map };
|
|
1106
|
+
for (let pass = 1; current.locked > 0 && pass < passLimit; pass++) {
|
|
1107
|
+
current = firstPass(current.body, [...reservedKeys, ...Object.keys(map)]);
|
|
1108
|
+
Object.assign(map, current.map);
|
|
1109
|
+
total += current.locked;
|
|
1110
|
+
}
|
|
1111
|
+
if (current.locked > 0 && firstPass(current.body, [...reservedKeys, ...Object.keys(map)]).locked > 0) {
|
|
1112
|
+
throw new Error("Card backstop did not reach a fixed point.");
|
|
1113
|
+
}
|
|
1114
|
+
return { body: current.body, locked: total, map };
|
|
1115
|
+
}
|
|
1116
|
+
function finalCardBackstopWithContext(body, reserved, sharedContext, spanOffsets) {
|
|
1117
|
+
const shortFormOffsets = shortFormSeparatorOffsets(body);
|
|
1118
|
+
let cap = 1024;
|
|
1119
|
+
let D = new Uint8Array(cap);
|
|
1120
|
+
let S = new Int32Array(cap);
|
|
1121
|
+
let E = new Int32Array(cap);
|
|
1122
|
+
let n = 0;
|
|
1123
|
+
const runs = [];
|
|
1124
|
+
let runFrom = 0;
|
|
1125
|
+
let gap = 0;
|
|
1126
|
+
let shortGap = false;
|
|
1127
|
+
const endRun = () => {
|
|
1128
|
+
if (n - runFrom >= MIN_LEN) runs.push(runFrom, n);
|
|
1129
|
+
runFrom = n;
|
|
1130
|
+
gap = 0;
|
|
1131
|
+
shortGap = false;
|
|
1132
|
+
};
|
|
1133
|
+
for (let i = 0; i < body.length; ) {
|
|
1134
|
+
const cp = body.codePointAt(i);
|
|
1135
|
+
const width = cp > 65535 ? 2 : 1;
|
|
1136
|
+
const v = digitValue(cp);
|
|
1137
|
+
if (v >= 0) {
|
|
1138
|
+
if (n === cap) {
|
|
1139
|
+
cap *= 2;
|
|
1140
|
+
const D2 = new Uint8Array(cap);
|
|
1141
|
+
D2.set(D);
|
|
1142
|
+
D = D2;
|
|
1143
|
+
const S2 = new Int32Array(cap);
|
|
1144
|
+
S2.set(S);
|
|
1145
|
+
S = S2;
|
|
1146
|
+
const E2 = new Int32Array(cap);
|
|
1147
|
+
E2.set(E);
|
|
1148
|
+
E = E2;
|
|
1149
|
+
}
|
|
1150
|
+
D[n] = v;
|
|
1151
|
+
S[n] = i;
|
|
1152
|
+
E[n] = i + width;
|
|
1153
|
+
n++;
|
|
1154
|
+
gap = 0;
|
|
1155
|
+
shortGap = false;
|
|
1156
|
+
} else if (n > runFrom && isSeparator(cp, i, shortFormOffsets)) {
|
|
1157
|
+
shortGap || (shortGap = shortFormOffsets.has(i));
|
|
1158
|
+
if (gap < (shortGap ? 9 : MAX_GAP)) gap++;
|
|
1159
|
+
else endRun();
|
|
1160
|
+
} else if (n > runFrom) {
|
|
1161
|
+
endRun();
|
|
1162
|
+
}
|
|
1163
|
+
i += width;
|
|
1164
|
+
}
|
|
1165
|
+
endRun();
|
|
1166
|
+
if (runs.length === 0) return { body, locked: 0, map: {} };
|
|
1167
|
+
const P0 = new Int32Array(n + 1);
|
|
1168
|
+
const P1 = new Int32Array(n + 1);
|
|
1169
|
+
for (let t = 0; t < n; t++) {
|
|
1170
|
+
P0[t + 1] = P0[t] + (t % 2 === 0 ? DOUBLED[D[t]] : D[t]);
|
|
1171
|
+
P1[t + 1] = P1[t] + (t % 2 === 1 ? DOUBLED[D[t]] : D[t]);
|
|
1172
|
+
}
|
|
1173
|
+
const valid = (start, end) => {
|
|
1174
|
+
const P = end % 2 === 0 ? P0 : P1;
|
|
1175
|
+
return (P[end] - P[start]) % 10 === 0 && plausible(D, start, end - start);
|
|
1176
|
+
};
|
|
1177
|
+
const covStart = new Int32Array(n + 1);
|
|
1178
|
+
const covEnd = new Int32Array(n + 1);
|
|
1179
|
+
const spans = [];
|
|
1180
|
+
for (let r = 0; r < runs.length; r += 2) {
|
|
1181
|
+
const from = runs[r];
|
|
1182
|
+
const to = runs[r + 1];
|
|
1183
|
+
let any = false;
|
|
1184
|
+
for (let len = MIN_LEN; len <= MAX_LEN; len++) {
|
|
1185
|
+
for (let end = from + len; end <= to; end++) {
|
|
1186
|
+
if (!valid(end - len, end)) continue;
|
|
1187
|
+
covStart[end - len]++;
|
|
1188
|
+
covEnd[end]++;
|
|
1189
|
+
any = true;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
if (!any) continue;
|
|
1193
|
+
let cover = 0;
|
|
1194
|
+
let open = -1;
|
|
1195
|
+
for (let t = from; t <= to; t++) {
|
|
1196
|
+
if (t > from) cover -= covEnd[t];
|
|
1197
|
+
if (cover <= 0 && open >= 0) {
|
|
1198
|
+
pushTiled(spans, open, t, valid);
|
|
1199
|
+
open = -1;
|
|
1200
|
+
}
|
|
1201
|
+
if (t < to) cover += covStart[t];
|
|
1202
|
+
if (cover > 0 && open < 0) open = t;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
if (spans.length === 0) return { body, locked: 0, map: {} };
|
|
1206
|
+
const context = sharedContext ?? markerContext(body, reserved);
|
|
1207
|
+
const map = {};
|
|
1208
|
+
const out = [];
|
|
1209
|
+
let cursor = 0;
|
|
1210
|
+
for (const [a, b] of spans) {
|
|
1211
|
+
const from = S[a];
|
|
1212
|
+
const to = E[b - 1];
|
|
1213
|
+
spanOffsets?.push([from, to]);
|
|
1214
|
+
const marker = markerAt(context.salt, context.index++);
|
|
1215
|
+
map[marker] = body.slice(from, to);
|
|
1216
|
+
out.push(body.slice(cursor, from));
|
|
1217
|
+
out.push(marker);
|
|
1218
|
+
cursor = to;
|
|
1219
|
+
}
|
|
1220
|
+
out.push(body.slice(cursor));
|
|
1221
|
+
return { body: out.join(""), locked: spans.length, map };
|
|
1222
|
+
}
|
|
1223
|
+
function pushTiled(spans, from, to, valid) {
|
|
1224
|
+
const len = to - from;
|
|
1225
|
+
if (len <= MAX_LEN) {
|
|
1226
|
+
spans.push([from, to]);
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
const pieces = new Int32Array(len + 1);
|
|
1230
|
+
const via = new Int8Array(len + 1);
|
|
1231
|
+
for (let t = MIN_LEN; t <= len; t++) {
|
|
1232
|
+
for (let w = MIN_LEN; w <= MAX_LEN && w <= t; w++) {
|
|
1233
|
+
const before = t - w;
|
|
1234
|
+
if (before !== 0 && pieces[before] === 0) continue;
|
|
1235
|
+
if (!valid(from + before, from + t)) continue;
|
|
1236
|
+
const count = (before === 0 ? 0 : pieces[before]) + 1;
|
|
1237
|
+
if (count > pieces[t]) {
|
|
1238
|
+
pieces[t] = count;
|
|
1239
|
+
via[t] = w;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
if (pieces[len] <= 1) {
|
|
1244
|
+
spans.push([from, to]);
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
const cut = [];
|
|
1248
|
+
for (let t = len; t > 0; t -= via[t]) cut.push([from + t - via[t], from + t]);
|
|
1249
|
+
cut.reverse();
|
|
1250
|
+
for (const c of cut) spans.push(c);
|
|
1251
|
+
}
|
|
1252
|
+
function scannedEscapeUnit(cp) {
|
|
1253
|
+
if (cp >= 48 && cp <= 57) return String.fromCharCode(cp);
|
|
1254
|
+
if (cp < 0 || cp > 1114111) return null;
|
|
1255
|
+
const char = String.fromCodePoint(cp);
|
|
1256
|
+
return SHORT_FORM_SEPARATORS.test(char) ? char : null;
|
|
1257
|
+
}
|
|
1258
|
+
function lockOutsideEscapes(serialized, reserved) {
|
|
1259
|
+
let decoded = "";
|
|
1260
|
+
const sourceStart = [];
|
|
1261
|
+
const sourceEnd = [];
|
|
1262
|
+
for (let i = 0; i < serialized.length; ) {
|
|
1263
|
+
const escape = /^\\u([0-9a-fA-F]{4})/.exec(serialized.slice(i));
|
|
1264
|
+
const decodedUnit = escape ? scannedEscapeUnit(Number.parseInt(escape[1], 16)) : null;
|
|
1265
|
+
if (escape && decodedUnit !== null) {
|
|
1266
|
+
decoded += decodedUnit;
|
|
1267
|
+
sourceStart.push(i);
|
|
1268
|
+
i += escape[0].length;
|
|
1269
|
+
sourceEnd.push(i);
|
|
1270
|
+
} else {
|
|
1271
|
+
const escapeWidth = serialized[i] === "\\" ? /^\\(?:u[0-9a-fA-F]{4}|[\s\S])/.exec(serialized.slice(i))?.[0].length ?? 1 : 0;
|
|
1272
|
+
const width = escapeWidth || 1;
|
|
1273
|
+
decoded += escapeWidth ? "\0" : serialized[i];
|
|
1274
|
+
sourceStart.push(i);
|
|
1275
|
+
sourceEnd.push(i + width);
|
|
1276
|
+
i += width;
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
const lockedSpans = [];
|
|
1280
|
+
const result = finalCardBackstopWithContext(decoded, reserved, void 0, lockedSpans);
|
|
1281
|
+
if (result.locked === 0) return { body: serialized, locked: 0, map: {} };
|
|
1282
|
+
const out = [];
|
|
1283
|
+
let sourceCursor = 0;
|
|
1284
|
+
let index = 0;
|
|
1285
|
+
for (const marker of Object.keys(result.map)) {
|
|
1286
|
+
const [start, end] = lockedSpans[index++];
|
|
1287
|
+
const rawStart = sourceStart[start];
|
|
1288
|
+
const rawEnd = sourceEnd[end - 1];
|
|
1289
|
+
out.push(serialized.slice(sourceCursor, rawStart), marker);
|
|
1290
|
+
sourceCursor = rawEnd;
|
|
1291
|
+
}
|
|
1292
|
+
out.push(serialized.slice(sourceCursor));
|
|
1293
|
+
return { body: out.join(""), locked: result.locked, map: result.map };
|
|
1294
|
+
}
|
|
1295
|
+
var JSON_NUMBER = /-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/y;
|
|
1296
|
+
function jsonNumberEnd(serialized, start) {
|
|
1297
|
+
JSON_NUMBER.lastIndex = start;
|
|
1298
|
+
const match = JSON_NUMBER.exec(serialized);
|
|
1299
|
+
if (!match || match.index !== start) return null;
|
|
1300
|
+
return start + match[0].length;
|
|
1301
|
+
}
|
|
1302
|
+
function asciiDigitCount(literal) {
|
|
1303
|
+
let count = 0;
|
|
1304
|
+
for (let i = 0; i < literal.length; i++) {
|
|
1305
|
+
const code = literal.charCodeAt(i);
|
|
1306
|
+
if (code >= 48 && code <= 57) count++;
|
|
1307
|
+
}
|
|
1308
|
+
return count;
|
|
1309
|
+
}
|
|
1310
|
+
function isJsonWhitespace(code) {
|
|
1311
|
+
return code === 32 || code === 9 || code === 10 || code === 13;
|
|
1312
|
+
}
|
|
1313
|
+
function shortJsonNumberRunEnd(serialized, start) {
|
|
1314
|
+
const first = jsonNumberEnd(serialized, start);
|
|
1315
|
+
if (first === null || asciiDigitCount(serialized.slice(start, first)) >= 13) return null;
|
|
1316
|
+
let end = first;
|
|
1317
|
+
let count = 1;
|
|
1318
|
+
for (; ; ) {
|
|
1319
|
+
let k = end;
|
|
1320
|
+
while (k < serialized.length && isJsonWhitespace(serialized.charCodeAt(k))) k++;
|
|
1321
|
+
if (serialized.charCodeAt(k) !== 44) break;
|
|
1322
|
+
k++;
|
|
1323
|
+
while (k < serialized.length && isJsonWhitespace(serialized.charCodeAt(k))) k++;
|
|
1324
|
+
const next = jsonNumberEnd(serialized, k);
|
|
1325
|
+
if (next === null || asciiDigitCount(serialized.slice(k, next)) >= 13) break;
|
|
1326
|
+
end = next;
|
|
1327
|
+
count++;
|
|
1328
|
+
}
|
|
1329
|
+
return count >= 2 ? end : null;
|
|
1330
|
+
}
|
|
1331
|
+
var EXACT_SHORT_JSON_SHAPES = [
|
|
1332
|
+
[4, 4, 4, 4],
|
|
1333
|
+
[4, 6, 5],
|
|
1334
|
+
[4, 4, 4, 4, 3],
|
|
1335
|
+
[4, 4, 4, 3],
|
|
1336
|
+
[8, 8],
|
|
1337
|
+
[4, 4, 8],
|
|
1338
|
+
[4, 8, 4],
|
|
1339
|
+
[8, 4, 4]
|
|
1340
|
+
];
|
|
1341
|
+
function sameShape(lengths, shape) {
|
|
1342
|
+
if (lengths.length !== shape.length) return false;
|
|
1343
|
+
for (let i = 0; i < lengths.length; i++) if (lengths[i] !== shape[i]) return false;
|
|
1344
|
+
return true;
|
|
1345
|
+
}
|
|
1346
|
+
function digitsPassCard(digits) {
|
|
1347
|
+
const n = digits.length;
|
|
1348
|
+
if (n < MIN_LEN || n > MAX_LEN) return false;
|
|
1349
|
+
const D = new Uint8Array(n);
|
|
1350
|
+
let sum = 0;
|
|
1351
|
+
for (let t = 0; t < n; t++) {
|
|
1352
|
+
const v = digits.charCodeAt(t) - 48;
|
|
1353
|
+
if (v < 0 || v > 9) return false;
|
|
1354
|
+
D[t] = v;
|
|
1355
|
+
const doubled = n % 2 === 0 ? t % 2 === 0 : t % 2 === 1;
|
|
1356
|
+
sum += doubled ? DOUBLED[v] : v;
|
|
1357
|
+
}
|
|
1358
|
+
return sum % 10 === 0 && plausible(D, 0, n);
|
|
1359
|
+
}
|
|
1360
|
+
function exactShortJsonCardLiteral(literal) {
|
|
1361
|
+
const parts = literal.split(",");
|
|
1362
|
+
if (parts.length < 2 || parts.length > 5) return false;
|
|
1363
|
+
const lengths = [];
|
|
1364
|
+
let digits = "";
|
|
1365
|
+
for (const part of parts) {
|
|
1366
|
+
const token = part.trim();
|
|
1367
|
+
if (!/^\d+$/.test(token)) return false;
|
|
1368
|
+
lengths.push(token.length);
|
|
1369
|
+
digits += token;
|
|
1370
|
+
}
|
|
1371
|
+
if (!EXACT_SHORT_JSON_SHAPES.some((shape) => sameShape(lengths, shape))) return false;
|
|
1372
|
+
return digitsPassCard(digits);
|
|
1373
|
+
}
|
|
1374
|
+
function shortJsonRunLock(literal, context) {
|
|
1375
|
+
if (!exactShortJsonCardLiteral(literal)) return null;
|
|
1376
|
+
const marker = markerAt(context.salt, context.index++);
|
|
1377
|
+
return { body: JSON.stringify(marker), locked: 1, map: { [marker]: literal } };
|
|
1378
|
+
}
|
|
1379
|
+
function jsonStringTokens(serialized) {
|
|
1380
|
+
const tokens = [];
|
|
1381
|
+
let i = 0;
|
|
1382
|
+
let tokenIndex = 0;
|
|
1383
|
+
while (i < serialized.length) {
|
|
1384
|
+
if (serialized.charCodeAt(i) !== 34) {
|
|
1385
|
+
i++;
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1388
|
+
let j = i + 1;
|
|
1389
|
+
while (j < serialized.length) {
|
|
1390
|
+
const ch = serialized.charCodeAt(j);
|
|
1391
|
+
if (ch === 92) j += 2;
|
|
1392
|
+
else if (ch === 34) break;
|
|
1393
|
+
else j++;
|
|
1394
|
+
}
|
|
1395
|
+
if (j >= serialized.length) return null;
|
|
1396
|
+
const raw = serialized.slice(i + 1, j);
|
|
1397
|
+
if (/[\p{Nd}\p{No}]/u.test(raw) || /\\u[0-9a-fA-F]{4}/u.test(raw)) {
|
|
1398
|
+
try {
|
|
1399
|
+
tokens.push({ tokenIndex, value: raw.includes("\\") ? JSON.parse(serialized.slice(i, j + 1)) : raw });
|
|
1400
|
+
} catch {
|
|
1401
|
+
return null;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
tokenIndex++;
|
|
1405
|
+
i = j + 1;
|
|
1406
|
+
}
|
|
1407
|
+
return tokens;
|
|
1408
|
+
}
|
|
1409
|
+
function hexNibble(code) {
|
|
1410
|
+
if (code >= 48 && code <= 57) return code - 48;
|
|
1411
|
+
if (code >= 65 && code <= 70) return code - 55;
|
|
1412
|
+
if (code >= 97 && code <= 102) return code - 87;
|
|
1413
|
+
return -1;
|
|
1414
|
+
}
|
|
1415
|
+
function percentByteAt(text, i) {
|
|
1416
|
+
if (i + 2 >= text.length || text.charCodeAt(i) !== 37) return null;
|
|
1417
|
+
const hi = hexNibble(text.charCodeAt(i + 1));
|
|
1418
|
+
const lo = hexNibble(text.charCodeAt(i + 2));
|
|
1419
|
+
if (hi < 0 || lo < 0) return null;
|
|
1420
|
+
return { byte: hi << 4 | lo, next: i + 3 };
|
|
1421
|
+
}
|
|
1422
|
+
function takePercentChar(text, i) {
|
|
1423
|
+
const lead = percentByteAt(text, i);
|
|
1424
|
+
if (!lead) return null;
|
|
1425
|
+
const b0 = lead.byte;
|
|
1426
|
+
if (b0 === 9 || b0 === 10 || b0 === 11 || b0 === 12 || b0 === 13) {
|
|
1427
|
+
return { char: String.fromCharCode(b0), next: lead.next };
|
|
1428
|
+
}
|
|
1429
|
+
if (b0 >= 32 && b0 <= 126) return { char: String.fromCharCode(b0), next: lead.next };
|
|
1430
|
+
let need = 0;
|
|
1431
|
+
if (b0 >= 194 && b0 <= 223) need = 2;
|
|
1432
|
+
else if (b0 >= 224 && b0 <= 239) need = 3;
|
|
1433
|
+
else if (b0 >= 240 && b0 <= 244) need = 4;
|
|
1434
|
+
else return null;
|
|
1435
|
+
const bytes = [b0];
|
|
1436
|
+
let pos = lead.next;
|
|
1437
|
+
for (let n = 1; n < need; n++) {
|
|
1438
|
+
const cont = percentByteAt(text, pos);
|
|
1439
|
+
if (!cont || cont.byte < 128 || cont.byte > 191) return null;
|
|
1440
|
+
bytes.push(cont.byte);
|
|
1441
|
+
pos = cont.next;
|
|
1442
|
+
}
|
|
1443
|
+
if (b0 === 224 && bytes[1] < 160) return null;
|
|
1444
|
+
if (b0 === 237 && bytes[1] >= 160) return null;
|
|
1445
|
+
if (b0 === 240 && bytes[1] < 144) return null;
|
|
1446
|
+
if (b0 === 244 && bytes[1] > 143) return null;
|
|
1447
|
+
let cp = 0;
|
|
1448
|
+
if (need === 2) cp = (b0 & 31) << 6 | bytes[1] & 63;
|
|
1449
|
+
else if (need === 3) cp = (b0 & 15) << 12 | (bytes[1] & 63) << 6 | bytes[2] & 63;
|
|
1450
|
+
else cp = (b0 & 7) << 18 | (bytes[1] & 63) << 12 | (bytes[2] & 63) << 6 | bytes[3] & 63;
|
|
1451
|
+
return { char: String.fromCodePoint(cp), next: pos };
|
|
1452
|
+
}
|
|
1453
|
+
function projectPercentEncoded(text) {
|
|
1454
|
+
let projected = "";
|
|
1455
|
+
const starts = [];
|
|
1456
|
+
const ends = [];
|
|
1457
|
+
let decoded = false;
|
|
1458
|
+
for (let i = 0; i < text.length; ) {
|
|
1459
|
+
const tok = takePercentChar(text, i);
|
|
1460
|
+
if (tok) {
|
|
1461
|
+
decoded = true;
|
|
1462
|
+
for (let u = 0; u < tok.char.length; u++) {
|
|
1463
|
+
projected += tok.char[u];
|
|
1464
|
+
starts.push(i);
|
|
1465
|
+
ends.push(tok.next);
|
|
1466
|
+
}
|
|
1467
|
+
i = tok.next;
|
|
1468
|
+
} else if (text.charCodeAt(i) === 43) {
|
|
1469
|
+
decoded = true;
|
|
1470
|
+
projected += " ";
|
|
1471
|
+
starts.push(i);
|
|
1472
|
+
ends.push(i + 1);
|
|
1473
|
+
i++;
|
|
1474
|
+
} else {
|
|
1475
|
+
projected += text[i];
|
|
1476
|
+
starts.push(i);
|
|
1477
|
+
ends.push(i + 1);
|
|
1478
|
+
i++;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
if (!decoded || projected === text) return null;
|
|
1482
|
+
return { projected, starts, ends };
|
|
1483
|
+
}
|
|
1484
|
+
var PERCENT_DECODE_LIMIT = 32;
|
|
1485
|
+
var JSON_BOUNDARY_BACKSLASHES = [7, 3, 1, 0];
|
|
1486
|
+
var JSON_BOUNDARY_GAP = 6;
|
|
1487
|
+
var JSON_BOUNDARY_INDENT = 100;
|
|
1488
|
+
function isBoundaryQuote(code) {
|
|
1489
|
+
return code === 34 || code === 8220 || code === 8221 || code === 65282;
|
|
1490
|
+
}
|
|
1491
|
+
function isJsonBoundaryHorizontal(code) {
|
|
1492
|
+
if (code === 32 || code === 9 || code === 160 || code === 12288 || code === 5760 || code === 8239 || code === 8287) return true;
|
|
1493
|
+
return code >= 8192 && code <= 8202;
|
|
1494
|
+
}
|
|
1495
|
+
function consumeJsonBoundaryGap(text, p) {
|
|
1496
|
+
const n = text.length;
|
|
1497
|
+
let inline = 0;
|
|
1498
|
+
let broke = false;
|
|
1499
|
+
let indent = 0;
|
|
1500
|
+
while (p < n) {
|
|
1501
|
+
const c = text.charCodeAt(p);
|
|
1502
|
+
if (!broke && c === 13) {
|
|
1503
|
+
broke = true;
|
|
1504
|
+
p++;
|
|
1505
|
+
if (p < n && text.charCodeAt(p) === 10) p++;
|
|
1506
|
+
continue;
|
|
1507
|
+
}
|
|
1508
|
+
if (!broke && (c === 10 || c === 8232 || c === 8233)) {
|
|
1509
|
+
broke = true;
|
|
1510
|
+
p++;
|
|
1511
|
+
continue;
|
|
1512
|
+
}
|
|
1513
|
+
if (isJsonBoundaryHorizontal(c)) {
|
|
1514
|
+
if (!broke) {
|
|
1515
|
+
if (inline >= JSON_BOUNDARY_GAP) break;
|
|
1516
|
+
inline++;
|
|
1517
|
+
} else if (indent >= JSON_BOUNDARY_INDENT) {
|
|
1518
|
+
break;
|
|
1519
|
+
} else {
|
|
1520
|
+
indent++;
|
|
1521
|
+
}
|
|
1522
|
+
p++;
|
|
1523
|
+
continue;
|
|
1524
|
+
}
|
|
1525
|
+
break;
|
|
1526
|
+
}
|
|
1527
|
+
return p;
|
|
1528
|
+
}
|
|
1529
|
+
function isDigitAt(text, i) {
|
|
1530
|
+
if (i < 0 || i >= text.length) return false;
|
|
1531
|
+
const cu = text.charCodeAt(i);
|
|
1532
|
+
if (cu >= 56320 && cu <= 57343) return false;
|
|
1533
|
+
return digitValue(text.codePointAt(i)) >= 0;
|
|
1534
|
+
}
|
|
1535
|
+
function jsonStringBoundaryLength(text, i) {
|
|
1536
|
+
const n = text.length;
|
|
1537
|
+
for (const backs of JSON_BOUNDARY_BACKSLASHES) {
|
|
1538
|
+
let p = i;
|
|
1539
|
+
let ok = true;
|
|
1540
|
+
for (let k = 0; k < backs; k++) {
|
|
1541
|
+
if (p >= n || text.charCodeAt(p) !== 92) {
|
|
1542
|
+
ok = false;
|
|
1543
|
+
break;
|
|
1544
|
+
}
|
|
1545
|
+
p++;
|
|
1546
|
+
}
|
|
1547
|
+
if (!ok || p >= n || !isBoundaryQuote(text.charCodeAt(p)) || text.charCodeAt(p) !== 34 && backs !== 0) continue;
|
|
1548
|
+
p++;
|
|
1549
|
+
p = consumeJsonBoundaryGap(text, p);
|
|
1550
|
+
if (p >= n || text.charCodeAt(p) !== 44) continue;
|
|
1551
|
+
p++;
|
|
1552
|
+
p = consumeJsonBoundaryGap(text, p);
|
|
1553
|
+
for (let k = 0; k < backs; k++) {
|
|
1554
|
+
if (p >= n || text.charCodeAt(p) !== 92) {
|
|
1555
|
+
ok = false;
|
|
1556
|
+
break;
|
|
1557
|
+
}
|
|
1558
|
+
p++;
|
|
1559
|
+
}
|
|
1560
|
+
if (!ok || p >= n || !isBoundaryQuote(text.charCodeAt(p)) || text.charCodeAt(p) !== 34 && backs !== 0) continue;
|
|
1561
|
+
return p + 1 - i;
|
|
1562
|
+
}
|
|
1563
|
+
return 0;
|
|
1564
|
+
}
|
|
1565
|
+
function bridgeJsonStringBoundaries(text) {
|
|
1566
|
+
let bridged = "";
|
|
1567
|
+
const src = [];
|
|
1568
|
+
let crossed = false;
|
|
1569
|
+
for (let i = 0; i < text.length; ) {
|
|
1570
|
+
const boundary = jsonStringBoundaryLength(text, i);
|
|
1571
|
+
if (boundary > 0 && isDigitAt(text, i - 1) && isDigitAt(text, i + boundary)) {
|
|
1572
|
+
bridged += " ";
|
|
1573
|
+
src.push(-1);
|
|
1574
|
+
crossed = true;
|
|
1575
|
+
i += boundary;
|
|
1576
|
+
continue;
|
|
1577
|
+
}
|
|
1578
|
+
const cp = text.codePointAt(i);
|
|
1579
|
+
const width = cp > 65535 ? 2 : 1;
|
|
1580
|
+
bridged += text.slice(i, i + width);
|
|
1581
|
+
for (let k = 0; k < width; k++) src.push(i + k);
|
|
1582
|
+
i += width;
|
|
1583
|
+
}
|
|
1584
|
+
if (!crossed || src.length !== bridged.length) return null;
|
|
1585
|
+
return { bridged, src };
|
|
1586
|
+
}
|
|
1587
|
+
function boundaryRunIsIdColumn(bridged, src, spanFrom, spanTo) {
|
|
1588
|
+
const joins = (i) => {
|
|
1589
|
+
if (i < 0 || i >= bridged.length) return false;
|
|
1590
|
+
if (src[i] < 0) return true;
|
|
1591
|
+
const cu = bridged.charCodeAt(i);
|
|
1592
|
+
if (cu >= 56320 && cu <= 57343) return false;
|
|
1593
|
+
const cp = bridged.codePointAt(i);
|
|
1594
|
+
if (digitValue(cp) >= 0) return true;
|
|
1595
|
+
return cp === 32 || cp === 9 || cp === 10 || cp === 13 || cp === 45 || cp === 46 || cp === 47;
|
|
1596
|
+
};
|
|
1597
|
+
let from = spanFrom;
|
|
1598
|
+
while (from > 0 && joins(from - 1)) {
|
|
1599
|
+
const prev = bridged.charCodeAt(from - 1);
|
|
1600
|
+
from -= prev >= 56320 && prev <= 57343 ? 2 : 1;
|
|
1601
|
+
}
|
|
1602
|
+
let to = spanTo;
|
|
1603
|
+
while (to < bridged.length && joins(to)) {
|
|
1604
|
+
const cp = bridged.codePointAt(to);
|
|
1605
|
+
to += cp > 65535 ? 2 : 1;
|
|
1606
|
+
}
|
|
1607
|
+
let digits = 0;
|
|
1608
|
+
let bridges = 0;
|
|
1609
|
+
for (let i = from; i < to; ) {
|
|
1610
|
+
if (src[i] < 0) {
|
|
1611
|
+
bridges++;
|
|
1612
|
+
i++;
|
|
1613
|
+
continue;
|
|
1614
|
+
}
|
|
1615
|
+
const cp = bridged.codePointAt(i);
|
|
1616
|
+
const width = cp > 65535 ? 2 : 1;
|
|
1617
|
+
if (digitValue(cp) >= 0) digits++;
|
|
1618
|
+
i += width;
|
|
1619
|
+
}
|
|
1620
|
+
return digits > MAX_LEN && bridges + 1 > 5;
|
|
1621
|
+
}
|
|
1622
|
+
function boundarySpanGroupLengths(bridged, src, from, to) {
|
|
1623
|
+
if (from > 0 && src[from - 1] >= 0 && isDigitAt(bridged, from - 1)) return null;
|
|
1624
|
+
if (to < bridged.length && isDigitAt(bridged, to)) return null;
|
|
1625
|
+
const lengths = [];
|
|
1626
|
+
let count = 0;
|
|
1627
|
+
for (let i = from; i < to; ) {
|
|
1628
|
+
if (src[i] < 0) {
|
|
1629
|
+
if (count === 0) return null;
|
|
1630
|
+
lengths.push(count);
|
|
1631
|
+
count = 0;
|
|
1632
|
+
i++;
|
|
1633
|
+
continue;
|
|
1634
|
+
}
|
|
1635
|
+
const cp = bridged.codePointAt(i);
|
|
1636
|
+
const width = cp > 65535 ? 2 : 1;
|
|
1637
|
+
if (digitValue(cp) >= 0) count++;
|
|
1638
|
+
else if (count > 0) {
|
|
1639
|
+
lengths.push(count);
|
|
1640
|
+
count = 0;
|
|
1641
|
+
}
|
|
1642
|
+
i += width;
|
|
1643
|
+
}
|
|
1644
|
+
if (count > 0) lengths.push(count);
|
|
1645
|
+
return lengths.length > 0 ? lengths : null;
|
|
1646
|
+
}
|
|
1647
|
+
function lengthsAreCardShape(lengths) {
|
|
1648
|
+
return EXACT_SHORT_JSON_SHAPES.some((shape) => sameShape(lengths, shape));
|
|
1649
|
+
}
|
|
1650
|
+
function groupAlignedBridgeSpans(bridged, src) {
|
|
1651
|
+
const groups = [];
|
|
1652
|
+
let i = 0;
|
|
1653
|
+
while (i < bridged.length) {
|
|
1654
|
+
if (src[i] < 0 || !isDigitAt(bridged, i)) {
|
|
1655
|
+
i++;
|
|
1656
|
+
continue;
|
|
1657
|
+
}
|
|
1658
|
+
const from = i;
|
|
1659
|
+
let digits = "";
|
|
1660
|
+
while (i < bridged.length && src[i] >= 0 && isDigitAt(bridged, i)) {
|
|
1661
|
+
const cp = bridged.codePointAt(i);
|
|
1662
|
+
const width = cp > 65535 ? 2 : 1;
|
|
1663
|
+
const value = digitValue(cp);
|
|
1664
|
+
if (value >= 0) digits += String(value);
|
|
1665
|
+
i += width;
|
|
1666
|
+
}
|
|
1667
|
+
if (digits.length > 0) groups.push({ from, to: i, digits });
|
|
1668
|
+
}
|
|
1669
|
+
const out = [];
|
|
1670
|
+
let g = 0;
|
|
1671
|
+
while (g < groups.length) {
|
|
1672
|
+
let matched = 0;
|
|
1673
|
+
for (const shape of EXACT_SHORT_JSON_SHAPES) {
|
|
1674
|
+
if (g + shape.length > groups.length) continue;
|
|
1675
|
+
const slice = groups.slice(g, g + shape.length);
|
|
1676
|
+
if (!sameShape(slice.map((group) => group.digits.length), shape)) continue;
|
|
1677
|
+
if (!digitsPassCard(slice.map((group) => group.digits).join(""))) continue;
|
|
1678
|
+
out.push([slice[0].from, slice[slice.length - 1].to]);
|
|
1679
|
+
matched = shape.length;
|
|
1680
|
+
break;
|
|
1681
|
+
}
|
|
1682
|
+
g += matched > 0 ? matched : 1;
|
|
1683
|
+
}
|
|
1684
|
+
return out;
|
|
1685
|
+
}
|
|
1686
|
+
function jsonBoundarySourceSpans(text, reserved) {
|
|
1687
|
+
if (!text.includes('"') && !text.includes("\u201C") && !text.includes("\u201D") && !text.includes("\uFF02")) return [];
|
|
1688
|
+
const bridged = bridgeJsonStringBoundaries(text);
|
|
1689
|
+
if (!bridged) return [];
|
|
1690
|
+
const bridgedSpans = [];
|
|
1691
|
+
const result = finalCardBackstopWithContext(bridged.bridged, reserved, void 0, bridgedSpans);
|
|
1692
|
+
const aligned = groupAlignedBridgeSpans(bridged.bridged, bridged.src);
|
|
1693
|
+
if (result.locked === 0 && aligned.length === 0) return [];
|
|
1694
|
+
const out = [];
|
|
1695
|
+
for (const [from, to] of [...bridgedSpans, ...aligned]) {
|
|
1696
|
+
let crossed = false;
|
|
1697
|
+
for (let i = from; i < to; i++) {
|
|
1698
|
+
if (bridged.src[i] < 0) {
|
|
1699
|
+
crossed = true;
|
|
1700
|
+
break;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
if (!crossed) continue;
|
|
1704
|
+
if (boundaryRunIsIdColumn(bridged.bridged, bridged.src, from, to)) {
|
|
1705
|
+
const lengths = boundarySpanGroupLengths(bridged.bridged, bridged.src, from, to);
|
|
1706
|
+
if (!lengths || !lengthsAreCardShape(lengths)) continue;
|
|
1707
|
+
}
|
|
1708
|
+
let lo = -1;
|
|
1709
|
+
let prev = -1;
|
|
1710
|
+
for (let i = from; i < to; i++) {
|
|
1711
|
+
const source = bridged.src[i];
|
|
1712
|
+
if (source < 0) {
|
|
1713
|
+
if (lo >= 0) out.push([lo, prev + 1]);
|
|
1714
|
+
lo = -1;
|
|
1715
|
+
continue;
|
|
1716
|
+
}
|
|
1717
|
+
if (lo < 0) lo = source;
|
|
1718
|
+
prev = source;
|
|
1719
|
+
}
|
|
1720
|
+
if (lo >= 0) out.push([lo, prev + 1]);
|
|
1721
|
+
}
|
|
1722
|
+
return out;
|
|
1723
|
+
}
|
|
1724
|
+
function mapThroughLevels(levels, lo, hi) {
|
|
1725
|
+
let start = lo;
|
|
1726
|
+
let end = hi;
|
|
1727
|
+
for (let d = levels.length - 1; d >= 0; d--) {
|
|
1728
|
+
start = levels[d].starts[start];
|
|
1729
|
+
end = levels[d].ends[end - 1];
|
|
1730
|
+
}
|
|
1731
|
+
return [start, end];
|
|
1732
|
+
}
|
|
1733
|
+
function spliceMappedSpans(original, levels, spans, context) {
|
|
1734
|
+
const mapped = [];
|
|
1735
|
+
for (const [lo, hi] of spans) {
|
|
1736
|
+
if (hi <= lo) continue;
|
|
1737
|
+
const [start, end] = mapThroughLevels(levels, lo, hi);
|
|
1738
|
+
if (end <= start) continue;
|
|
1739
|
+
mapped.push({ lo: start, hi: end });
|
|
1740
|
+
}
|
|
1741
|
+
mapped.sort((a, b) => a.lo - b.lo || a.hi - b.hi);
|
|
1742
|
+
const kept = [];
|
|
1743
|
+
let last = -1;
|
|
1744
|
+
for (const item of mapped) {
|
|
1745
|
+
if (item.lo < last) continue;
|
|
1746
|
+
kept.push(item);
|
|
1747
|
+
last = item.hi;
|
|
1748
|
+
}
|
|
1749
|
+
if (kept.length === 0) return { body: original, locked: 0, map: {} };
|
|
1750
|
+
const out = [];
|
|
1751
|
+
const map = {};
|
|
1752
|
+
let cursor = 0;
|
|
1753
|
+
for (const item of kept) {
|
|
1754
|
+
const marker = markerAt(context.salt, context.index++);
|
|
1755
|
+
out.push(original.slice(cursor, item.lo), marker);
|
|
1756
|
+
map[marker] = original.slice(item.lo, item.hi);
|
|
1757
|
+
cursor = item.hi;
|
|
1758
|
+
}
|
|
1759
|
+
out.push(original.slice(cursor));
|
|
1760
|
+
return { body: out.join(""), locked: kept.length, map };
|
|
1761
|
+
}
|
|
1762
|
+
function lockJsonBoundaryCardRuns(text, reserved, context) {
|
|
1763
|
+
return spliceMappedSpans(text, [], jsonBoundarySourceSpans(text, reserved), context);
|
|
1764
|
+
}
|
|
1765
|
+
function lockPercentEncodedDigits(text, reserved, context) {
|
|
1766
|
+
if (!/%[0-9a-fA-F]{2}/u.test(text)) return lockJsonBoundaryCardRuns(text, reserved, context);
|
|
1767
|
+
const levels = [];
|
|
1768
|
+
let current = text;
|
|
1769
|
+
for (let depth = 0; depth < PERCENT_DECODE_LIMIT; depth++) {
|
|
1770
|
+
const proj = projectPercentEncoded(current);
|
|
1771
|
+
if (!proj) break;
|
|
1772
|
+
levels.push(proj);
|
|
1773
|
+
current = proj.projected;
|
|
1774
|
+
}
|
|
1775
|
+
if (levels.length === 0) return lockJsonBoundaryCardRuns(text, reserved, context);
|
|
1776
|
+
const boundarySpans = jsonBoundarySourceSpans(current, reserved);
|
|
1777
|
+
const normalSpans = [];
|
|
1778
|
+
finalCardBackstopWithContext(current, reserved, void 0, normalSpans);
|
|
1779
|
+
const chosen = [...boundarySpans];
|
|
1780
|
+
for (const span of normalSpans) {
|
|
1781
|
+
const overlaps = boundarySpans.some((boundary) => span[0] < boundary[1] && boundary[0] < span[1]);
|
|
1782
|
+
if (!overlaps) chosen.push(span);
|
|
1783
|
+
}
|
|
1784
|
+
if (chosen.length === 0) return { body: text, locked: 0, map: {} };
|
|
1785
|
+
return spliceMappedSpans(text, levels, chosen, context);
|
|
1786
|
+
}
|
|
1787
|
+
function crossFieldCardTokens(tokens, reserved, context) {
|
|
1788
|
+
const joined = [];
|
|
1789
|
+
const ranges = [];
|
|
1790
|
+
const tokenIndexes = [];
|
|
1791
|
+
let offset = 0;
|
|
1792
|
+
for (const token of tokens) {
|
|
1793
|
+
if (joined.length > 0) {
|
|
1794
|
+
joined.push(" ");
|
|
1795
|
+
offset++;
|
|
1796
|
+
}
|
|
1797
|
+
const start = offset;
|
|
1798
|
+
joined.push(token.value);
|
|
1799
|
+
offset += token.value.length;
|
|
1800
|
+
ranges.push([start, offset]);
|
|
1801
|
+
tokenIndexes.push(token.tokenIndex);
|
|
1802
|
+
}
|
|
1803
|
+
const spans = [];
|
|
1804
|
+
finalCardBackstopWithContext(joined.join(""), reserved, context, spans);
|
|
1805
|
+
const involved = /* @__PURE__ */ new Set();
|
|
1806
|
+
const digitCount = (value) => {
|
|
1807
|
+
let n = 0;
|
|
1808
|
+
for (let i = 0; i < value.length; ) {
|
|
1809
|
+
const cp = value.codePointAt(i);
|
|
1810
|
+
if (digitValue(cp) >= 0) n++;
|
|
1811
|
+
i += cp > 65535 ? 2 : 1;
|
|
1812
|
+
}
|
|
1813
|
+
return n;
|
|
1814
|
+
};
|
|
1815
|
+
const digitsPerToken = tokens.map((token) => digitCount(token.value));
|
|
1816
|
+
for (const [start, end] of spans) {
|
|
1817
|
+
const touching = [];
|
|
1818
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
1819
|
+
if (ranges[i][0] < end && ranges[i][1] > start) touching.push(i);
|
|
1820
|
+
}
|
|
1821
|
+
if (touching.length < 2) continue;
|
|
1822
|
+
let lo = touching[0];
|
|
1823
|
+
let hi = touching[touching.length - 1];
|
|
1824
|
+
while (lo > 0 && digitsPerToken[lo - 1] > 0) lo--;
|
|
1825
|
+
while (hi + 1 < tokens.length && digitsPerToken[hi + 1] > 0) hi++;
|
|
1826
|
+
let digits = 0;
|
|
1827
|
+
let groups = 0;
|
|
1828
|
+
for (let i = lo; i <= hi; i++) {
|
|
1829
|
+
if (digitsPerToken[i] > 0) {
|
|
1830
|
+
digits += digitsPerToken[i];
|
|
1831
|
+
groups++;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
if (digits > MAX_LEN && groups > 5) {
|
|
1835
|
+
const whole = touching.every((index) => ranges[index][0] >= start && ranges[index][1] <= end);
|
|
1836
|
+
if (!whole) continue;
|
|
1837
|
+
const lengths = touching.map((index) => digitsPerToken[index]);
|
|
1838
|
+
const pure = touching.every((index) => digitsPerToken[index] > 0 && digitsPerToken[index] === [...tokens[index].value].length);
|
|
1839
|
+
if (!pure || !lengthsAreCardShape(lengths)) continue;
|
|
1840
|
+
}
|
|
1841
|
+
for (const index of touching) involved.add(tokenIndexes[index]);
|
|
1842
|
+
}
|
|
1843
|
+
for (let g = 0; g < tokens.length; ) {
|
|
1844
|
+
let matched = 0;
|
|
1845
|
+
for (const shape of EXACT_SHORT_JSON_SHAPES) {
|
|
1846
|
+
if (g + shape.length > tokens.length) continue;
|
|
1847
|
+
const slice = tokens.slice(g, g + shape.length);
|
|
1848
|
+
const parts = [];
|
|
1849
|
+
let pure = true;
|
|
1850
|
+
for (const token of slice) {
|
|
1851
|
+
let ascii = "";
|
|
1852
|
+
for (const ch of token.value) {
|
|
1853
|
+
const value = digitValue(ch.codePointAt(0));
|
|
1854
|
+
if (value < 0) {
|
|
1855
|
+
pure = false;
|
|
1856
|
+
break;
|
|
1857
|
+
}
|
|
1858
|
+
ascii += String(value);
|
|
1859
|
+
}
|
|
1860
|
+
if (!pure || ascii.length === 0) {
|
|
1861
|
+
pure = false;
|
|
1862
|
+
break;
|
|
1863
|
+
}
|
|
1864
|
+
parts.push(ascii);
|
|
1865
|
+
}
|
|
1866
|
+
if (!pure || !sameShape(parts.map((part) => part.length), shape)) continue;
|
|
1867
|
+
if (!digitsPassCard(parts.join(""))) continue;
|
|
1868
|
+
for (const token of slice) involved.add(token.tokenIndex);
|
|
1869
|
+
matched = shape.length;
|
|
1870
|
+
break;
|
|
1871
|
+
}
|
|
1872
|
+
g += matched > 0 ? matched : 1;
|
|
1873
|
+
}
|
|
1874
|
+
return involved;
|
|
1875
|
+
}
|
|
1876
|
+
function mixedDigitPieces(serialized) {
|
|
1877
|
+
const pieces = [];
|
|
1878
|
+
let i = 0;
|
|
1879
|
+
let tokenIndex = 0;
|
|
1880
|
+
while (i < serialized.length) {
|
|
1881
|
+
const code = serialized.charCodeAt(i);
|
|
1882
|
+
if (code === 34) {
|
|
1883
|
+
let j = i + 1;
|
|
1884
|
+
while (j < serialized.length) {
|
|
1885
|
+
const ch = serialized.charCodeAt(j);
|
|
1886
|
+
if (ch === 92) j += 2;
|
|
1887
|
+
else if (ch === 34) break;
|
|
1888
|
+
else j++;
|
|
1889
|
+
}
|
|
1890
|
+
if (j >= serialized.length) return pieces;
|
|
1891
|
+
let decoded = "";
|
|
1892
|
+
try {
|
|
1893
|
+
decoded = JSON.parse(serialized.slice(i, j + 1));
|
|
1894
|
+
} catch {
|
|
1895
|
+
return pieces;
|
|
1896
|
+
}
|
|
1897
|
+
if (/^\d{1,12}$/.test(decoded)) {
|
|
1898
|
+
pieces.push({ kind: "string", start: i, end: j + 1, digits: decoded, tokenIndex });
|
|
1899
|
+
}
|
|
1900
|
+
tokenIndex++;
|
|
1901
|
+
i = j + 1;
|
|
1902
|
+
continue;
|
|
1903
|
+
}
|
|
1904
|
+
if (code === 45 || code >= 48 && code <= 57) {
|
|
1905
|
+
const end = jsonNumberEnd(serialized, i);
|
|
1906
|
+
if (end !== null) {
|
|
1907
|
+
const literal = serialized.slice(i, end);
|
|
1908
|
+
if (/^\d{1,12}$/.test(literal)) pieces.push({ kind: "number", start: i, end, digits: literal });
|
|
1909
|
+
i = end;
|
|
1910
|
+
continue;
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
i++;
|
|
1914
|
+
}
|
|
1915
|
+
return pieces;
|
|
1916
|
+
}
|
|
1917
|
+
function mixedNumberStringLocks(serialized) {
|
|
1918
|
+
const numbers = /* @__PURE__ */ new Map();
|
|
1919
|
+
const strings = /* @__PURE__ */ new Set();
|
|
1920
|
+
const pieces = mixedDigitPieces(serialized);
|
|
1921
|
+
let g = 0;
|
|
1922
|
+
while (g < pieces.length) {
|
|
1923
|
+
let matched = 0;
|
|
1924
|
+
for (const shape of EXACT_SHORT_JSON_SHAPES) {
|
|
1925
|
+
if (g + shape.length > pieces.length) continue;
|
|
1926
|
+
const slice = pieces.slice(g, g + shape.length);
|
|
1927
|
+
if (!sameShape(slice.map((piece) => piece.digits.length), shape)) continue;
|
|
1928
|
+
if (!slice.some((piece) => piece.kind === "number") || !slice.some((piece) => piece.kind === "string")) continue;
|
|
1929
|
+
if (!digitsPassCard(slice.map((piece) => piece.digits).join(""))) continue;
|
|
1930
|
+
for (const piece of slice) {
|
|
1931
|
+
if (piece.kind === "number") numbers.set(piece.start, piece.end);
|
|
1932
|
+
else if (piece.tokenIndex !== void 0) strings.add(piece.tokenIndex);
|
|
1933
|
+
}
|
|
1934
|
+
matched = shape.length;
|
|
1935
|
+
break;
|
|
1936
|
+
}
|
|
1937
|
+
g += matched > 0 ? matched : 1;
|
|
1938
|
+
}
|
|
1939
|
+
return { numbers, strings };
|
|
1940
|
+
}
|
|
1941
|
+
function decodeBase64Text(token) {
|
|
1942
|
+
if (token.length < 20 || token.length > 88 || token.length % 4 !== 0) return null;
|
|
1943
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(token)) return null;
|
|
1944
|
+
const atobFn = globalThis.atob;
|
|
1945
|
+
if (!atobFn) return null;
|
|
1946
|
+
let bin;
|
|
1947
|
+
try {
|
|
1948
|
+
bin = atobFn(token);
|
|
1949
|
+
} catch {
|
|
1950
|
+
return null;
|
|
1951
|
+
}
|
|
1952
|
+
if (bin.length < MIN_LEN || bin.length > 64) return null;
|
|
1953
|
+
let out = "";
|
|
1954
|
+
for (let i = 0; i < bin.length; i++) {
|
|
1955
|
+
const c = bin.charCodeAt(i);
|
|
1956
|
+
if (c !== 9 && c !== 10 && c !== 13 && (c < 32 || c > 126)) return null;
|
|
1957
|
+
out += bin[i];
|
|
1958
|
+
}
|
|
1959
|
+
return out;
|
|
1960
|
+
}
|
|
1961
|
+
function lockBase64CardTokens(value, context) {
|
|
1962
|
+
const re = /[A-Za-z0-9+/]{20,}={0,2}/g;
|
|
1963
|
+
const map = {};
|
|
1964
|
+
let locked = 0;
|
|
1965
|
+
const body = value.replace(re, (token) => {
|
|
1966
|
+
if (token.length > 88 || token.length % 4 !== 0) return token;
|
|
1967
|
+
const decoded = decodeBase64Text(token);
|
|
1968
|
+
if (decoded == null || finalCardBackstop(decoded).locked === 0) return token;
|
|
1969
|
+
const marker = markerAt(context.salt, context.index++);
|
|
1970
|
+
map[marker] = token;
|
|
1971
|
+
locked++;
|
|
1972
|
+
return marker;
|
|
1973
|
+
});
|
|
1974
|
+
return { body, locked, map };
|
|
1975
|
+
}
|
|
1976
|
+
function finalCardBackstopJson(serialized, reserved) {
|
|
1977
|
+
try {
|
|
1978
|
+
JSON.parse(serialized);
|
|
1979
|
+
} catch {
|
|
1980
|
+
return lockOutsideEscapes(serialized, reserved);
|
|
1981
|
+
}
|
|
1982
|
+
const out = [];
|
|
1983
|
+
const map = {};
|
|
1984
|
+
const context = markerContext(serialized, reserved);
|
|
1985
|
+
const tokens = jsonStringTokens(serialized);
|
|
1986
|
+
const splitTokens = tokens ? crossFieldCardTokens(tokens, reserved, context) : /* @__PURE__ */ new Set();
|
|
1987
|
+
const mixed = mixedNumberStringLocks(serialized);
|
|
1988
|
+
for (const index of mixed.strings) splitTokens.add(index);
|
|
1989
|
+
let locked = 0;
|
|
1990
|
+
let cursor = 0;
|
|
1991
|
+
let i = 0;
|
|
1992
|
+
let tokenIndex = 0;
|
|
1993
|
+
while (i < serialized.length) {
|
|
1994
|
+
const ch0 = serialized.charCodeAt(i);
|
|
1995
|
+
if (ch0 !== 34) {
|
|
1996
|
+
if (ch0 === 45 || ch0 >= 48 && ch0 <= 57) {
|
|
1997
|
+
const mixedEnd = mixed.numbers.get(i);
|
|
1998
|
+
if (mixedEnd !== void 0) {
|
|
1999
|
+
const literal = serialized.slice(i, mixedEnd);
|
|
2000
|
+
const marker = markerAt(context.salt, context.index++);
|
|
2001
|
+
map[marker] = literal;
|
|
2002
|
+
out.push(serialized.slice(cursor, i), JSON.stringify(marker));
|
|
2003
|
+
cursor = mixedEnd;
|
|
2004
|
+
locked++;
|
|
2005
|
+
i = mixedEnd;
|
|
2006
|
+
continue;
|
|
2007
|
+
}
|
|
2008
|
+
const runEnd = shortJsonNumberRunEnd(serialized, i);
|
|
2009
|
+
if (runEnd !== null) {
|
|
2010
|
+
let touchesMixed = false;
|
|
2011
|
+
for (const start of mixed.numbers.keys()) {
|
|
2012
|
+
if (start >= i && start < runEnd) {
|
|
2013
|
+
touchesMixed = true;
|
|
2014
|
+
break;
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
if (!touchesMixed) {
|
|
2018
|
+
const run = serialized.slice(i, runEnd);
|
|
2019
|
+
const lockedRun = shortJsonRunLock(run, context);
|
|
2020
|
+
if (lockedRun) {
|
|
2021
|
+
out.push(serialized.slice(cursor, i), lockedRun.body);
|
|
2022
|
+
cursor = runEnd;
|
|
2023
|
+
locked += lockedRun.locked;
|
|
2024
|
+
Object.assign(map, lockedRun.map);
|
|
2025
|
+
}
|
|
2026
|
+
i = runEnd;
|
|
2027
|
+
continue;
|
|
2028
|
+
}
|
|
2029
|
+
JSON_NUMBER.lastIndex = i;
|
|
2030
|
+
const single = JSON_NUMBER.exec(serialized);
|
|
2031
|
+
if (single) {
|
|
2032
|
+
i += single[0].length;
|
|
2033
|
+
continue;
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
JSON_NUMBER.lastIndex = i;
|
|
2037
|
+
const m = JSON_NUMBER.exec(serialized);
|
|
2038
|
+
if (m) {
|
|
2039
|
+
const token2 = m[0];
|
|
2040
|
+
if (token2.length >= 13) {
|
|
2041
|
+
const r2 = finalCardBackstopWithContext(token2, reserved, context);
|
|
2042
|
+
if (r2.locked > 0) {
|
|
2043
|
+
out.push(serialized.slice(cursor, i), JSON.stringify(r2.body));
|
|
2044
|
+
cursor = i + token2.length;
|
|
2045
|
+
locked += r2.locked;
|
|
2046
|
+
Object.assign(map, r2.map);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
i += token2.length;
|
|
2050
|
+
continue;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
i++;
|
|
2054
|
+
continue;
|
|
2055
|
+
}
|
|
2056
|
+
let j = i + 1;
|
|
2057
|
+
while (j < serialized.length) {
|
|
2058
|
+
const ch = serialized.charCodeAt(j);
|
|
2059
|
+
if (ch === 92) j += 2;
|
|
2060
|
+
else if (ch === 34) break;
|
|
2061
|
+
else j++;
|
|
2062
|
+
}
|
|
2063
|
+
if (j >= serialized.length) return lockOutsideEscapes(serialized, reserved);
|
|
2064
|
+
const token = serialized.slice(i, j + 1);
|
|
2065
|
+
let decoded;
|
|
2066
|
+
try {
|
|
2067
|
+
decoded = JSON.parse(token);
|
|
2068
|
+
} catch {
|
|
2069
|
+
return lockOutsideEscapes(serialized, reserved);
|
|
2070
|
+
}
|
|
2071
|
+
let value = decoded;
|
|
2072
|
+
let valueLocked = 0;
|
|
2073
|
+
const urlLocked = lockPercentEncodedDigits(value, reserved, context);
|
|
2074
|
+
if (urlLocked.locked > 0) {
|
|
2075
|
+
value = urlLocked.body;
|
|
2076
|
+
valueLocked += urlLocked.locked;
|
|
2077
|
+
Object.assign(map, urlLocked.map);
|
|
2078
|
+
}
|
|
2079
|
+
if (valueLocked === 0) {
|
|
2080
|
+
let nested = value;
|
|
2081
|
+
for (let depth = 0; depth < PERCENT_DECODE_LIMIT; depth++) {
|
|
2082
|
+
try {
|
|
2083
|
+
const next = decodeURIComponent(nested.replace(/\+/g, "%20"));
|
|
2084
|
+
if (next === nested) break;
|
|
2085
|
+
nested = next;
|
|
2086
|
+
} catch {
|
|
2087
|
+
break;
|
|
2088
|
+
}
|
|
2089
|
+
if (finalCardBackstop(nested).locked > 0) {
|
|
2090
|
+
const marker = markerAt(context.salt, context.index++);
|
|
2091
|
+
map[marker] = decoded;
|
|
2092
|
+
value = marker;
|
|
2093
|
+
valueLocked++;
|
|
2094
|
+
break;
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
if (valueLocked === 0) {
|
|
2099
|
+
const b64 = lockBase64CardTokens(value, context);
|
|
2100
|
+
if (b64.locked > 0) {
|
|
2101
|
+
value = b64.body;
|
|
2102
|
+
valueLocked += b64.locked;
|
|
2103
|
+
Object.assign(map, b64.map);
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
const r = finalCardBackstopWithContext(value, reserved, context);
|
|
2107
|
+
if (r.locked > 0) {
|
|
2108
|
+
value = r.body;
|
|
2109
|
+
valueLocked += r.locked;
|
|
2110
|
+
Object.assign(map, r.map);
|
|
2111
|
+
}
|
|
2112
|
+
if (splitTokens.has(tokenIndex)) {
|
|
2113
|
+
const marker = markerAt(context.salt, context.index++);
|
|
2114
|
+
map[marker] = decoded;
|
|
2115
|
+
value = marker;
|
|
2116
|
+
valueLocked++;
|
|
2117
|
+
}
|
|
2118
|
+
if (valueLocked > 0) {
|
|
2119
|
+
out.push(serialized.slice(cursor, i), JSON.stringify(value));
|
|
2120
|
+
cursor = j + 1;
|
|
2121
|
+
locked += valueLocked;
|
|
2122
|
+
}
|
|
2123
|
+
tokenIndex++;
|
|
2124
|
+
i = j + 1;
|
|
2125
|
+
}
|
|
2126
|
+
if (locked === 0) return { body: serialized, locked: 0, map: {} };
|
|
2127
|
+
out.push(serialized.slice(cursor));
|
|
2128
|
+
return { body: out.join(""), locked, map };
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
// src/device/h308-assessment.ts
|
|
2132
|
+
var H308_UNREADABLE_MIME_REASON = "could not be decoded as an email.";
|
|
2133
|
+
var H308_ENCODED_PAYLOAD_NOTICE = "[Encoded payload omitted]";
|
|
2134
|
+
var MIME_FIELDS = [
|
|
2135
|
+
"content-type",
|
|
2136
|
+
"content-transfer-encoding",
|
|
2137
|
+
"content-disposition",
|
|
2138
|
+
"content-id",
|
|
2139
|
+
"mime-version"
|
|
2140
|
+
];
|
|
2141
|
+
var MAX_MIME_HEADER_LINES = 64;
|
|
2142
|
+
function hasMimeHeaderBlock(raw) {
|
|
2143
|
+
const mbox = /^From \S+[^\r\n]*(?:\r\n|\r|\n)/.exec(raw);
|
|
2144
|
+
const source = mbox ? raw.slice(mbox[0].length) : raw;
|
|
2145
|
+
const fields = /* @__PURE__ */ new Set();
|
|
2146
|
+
let lineCount = 0;
|
|
2147
|
+
let hasBodySeparator = false;
|
|
2148
|
+
const headerLines = [];
|
|
2149
|
+
let start = 0;
|
|
2150
|
+
while (start <= source.length && lineCount < MAX_MIME_HEADER_LINES) {
|
|
2151
|
+
if (start === source.length) break;
|
|
2152
|
+
const lf = source.indexOf("\n", start);
|
|
2153
|
+
const cr = source.indexOf("\r", start);
|
|
2154
|
+
const candidates = [lf, cr].filter((index) => index >= 0);
|
|
2155
|
+
const end = candidates.length ? Math.min(...candidates) : -1;
|
|
2156
|
+
const next = end < 0 ? source.length : end;
|
|
2157
|
+
const line = source.slice(start, next);
|
|
2158
|
+
if (/^[ \t]*$/.test(line)) {
|
|
2159
|
+
hasBodySeparator = true;
|
|
2160
|
+
break;
|
|
2161
|
+
}
|
|
2162
|
+
lineCount += 1;
|
|
2163
|
+
if (/^[ \t]/.test(line) && headerLines.length) {
|
|
2164
|
+
headerLines[headerLines.length - 1] += ` ${line.trim()}`;
|
|
2165
|
+
} else {
|
|
2166
|
+
headerLines.push(line);
|
|
2167
|
+
}
|
|
2168
|
+
if (end < 0) break;
|
|
2169
|
+
start = source[end] === "\r" && source[end + 1] === "\n" ? end + 2 : end + 1;
|
|
2170
|
+
}
|
|
2171
|
+
for (const line of headerLines) {
|
|
2172
|
+
const indented = /^[ \t]+/.test(line);
|
|
2173
|
+
const header = /^([!-9;-~]+):[ \t]*(.*)$/.exec(line.replace(/^[ \t]+/, ""));
|
|
2174
|
+
if (!header) continue;
|
|
2175
|
+
const name = header[1].toLowerCase();
|
|
2176
|
+
const value = header[2].trim();
|
|
2177
|
+
if (indented && name.startsWith("content-")) return true;
|
|
2178
|
+
if (name === "content-type" && value) return true;
|
|
2179
|
+
if (name === "mime-version" && value) return true;
|
|
2180
|
+
if (name === "content-transfer-encoding" && /^(?:7bit|8bit|binary|base64|quoted-printable)$/i.test(value)) {
|
|
2181
|
+
return true;
|
|
2182
|
+
}
|
|
2183
|
+
if (name === "content-disposition" && /^(?:inline|attachment)(?:[ \t]*;.*)?$/i.test(value)) return true;
|
|
2184
|
+
if (name === "content-id" && /^<[^<>]+>$/.test(value)) return true;
|
|
2185
|
+
if (value && (name === "from" || name === "to" || name === "subject")) fields.add(name);
|
|
2186
|
+
if (/^<[^<>]+>$/.test(value) && name === "message-id") fields.add(name);
|
|
2187
|
+
}
|
|
2188
|
+
return hasBodySeparator && fields.has("message-id") && (fields.has("from") || fields.has("to") || fields.has("subject"));
|
|
2189
|
+
}
|
|
2190
|
+
function hasH308MimeHeader(raw) {
|
|
2191
|
+
if (hasMimeHeaderBlock(raw)) {
|
|
2192
|
+
const normalized = raw.replace(/\r\n?/g, "\n");
|
|
2193
|
+
const header = normalized.split("\n").slice(0, MAX_MIME_HEADER_LINES);
|
|
2194
|
+
const hasSeparator2 = header.some((line) => /^[ \t]*$/.test(line));
|
|
2195
|
+
const hasCompanion = header.some((line) => /^(?:content-type|mime-version|content-disposition|content-id|message-id|from|to|subject):/i.test(line));
|
|
2196
|
+
const hasTransferEncoding = header.some((line) => /^content-transfer-encoding:[ \t]*(?:7bit|8bit|binary|base64|quoted-printable)[ \t]*$/i.test(line));
|
|
2197
|
+
if (!hasSeparator2 && hasTransferEncoding && !hasCompanion) return false;
|
|
2198
|
+
return true;
|
|
2199
|
+
}
|
|
2200
|
+
let headerText = raw;
|
|
2201
|
+
try {
|
|
2202
|
+
headerText = new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(raw, (char) => char.charCodeAt(0) & 255));
|
|
2203
|
+
} catch {
|
|
2204
|
+
}
|
|
2205
|
+
const lines = headerText.replace(/\r\n?/g, "\n").replace(/^From \S+.*\n/, "").split("\n").slice(0, MAX_MIME_HEADER_LINES);
|
|
2206
|
+
const fields = /* @__PURE__ */ new Set();
|
|
2207
|
+
for (const original of lines) {
|
|
2208
|
+
const line = normalizeHeaderLine(original);
|
|
2209
|
+
if (!line) break;
|
|
2210
|
+
const field = (line.includes(":") ? line.slice(0, line.indexOf(":")) : line.split(/[\s:]/, 1)[0]).replace(/\s+/g, "-").toLowerCase();
|
|
2211
|
+
const match = MIME_FIELDS.find((known) => distanceAtMostOne(field, known));
|
|
2212
|
+
if (match) fields.add(match);
|
|
2213
|
+
}
|
|
2214
|
+
const hasSeparator = /\n[ \t]*\n/.test(headerText);
|
|
2215
|
+
if (fields.size === 1 && fields.has("content-transfer-encoding") && !hasSeparator) return false;
|
|
2216
|
+
return fields.size > 0;
|
|
2217
|
+
}
|
|
2218
|
+
function normalizeHeaderLine(line) {
|
|
2219
|
+
return line.replace(/^\uFEFF+/, "").replace(/^[\s\p{C}]+/u, "").replace(/[\u00a0\uFEFF]/g, " ").replace(/[\p{Cc}\p{Cf}]/gu, "").trim();
|
|
2220
|
+
}
|
|
2221
|
+
function distanceAtMostOne(a, b) {
|
|
2222
|
+
if (a === b) return true;
|
|
2223
|
+
if (Math.abs(a.length - b.length) > 1) return false;
|
|
2224
|
+
let i = 0;
|
|
2225
|
+
let j = 0;
|
|
2226
|
+
let edits = 0;
|
|
2227
|
+
while (i < a.length && j < b.length) {
|
|
2228
|
+
if (a[i] === b[j]) {
|
|
2229
|
+
i += 1;
|
|
2230
|
+
j += 1;
|
|
2231
|
+
continue;
|
|
2232
|
+
}
|
|
2233
|
+
edits += 1;
|
|
2234
|
+
if (edits > 1) return false;
|
|
2235
|
+
if (a.length > b.length) i += 1;
|
|
2236
|
+
else if (b.length > a.length) j += 1;
|
|
2237
|
+
else {
|
|
2238
|
+
i += 1;
|
|
2239
|
+
j += 1;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
if (i < a.length || j < b.length) edits += 1;
|
|
2243
|
+
return edits <= 1;
|
|
2244
|
+
}
|
|
2245
|
+
function hasMimeHazard(raw) {
|
|
2246
|
+
let decodedHeaders = raw;
|
|
2247
|
+
const hasUtf8Bom = raw.charCodeAt(0) === 239 && raw.charCodeAt(1) === 187 && raw.charCodeAt(2) === 191;
|
|
2248
|
+
try {
|
|
2249
|
+
const bytes = Uint8Array.from(raw, (char) => char.charCodeAt(0) & 255);
|
|
2250
|
+
decodedHeaders = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
2251
|
+
} catch {
|
|
2252
|
+
}
|
|
2253
|
+
const normalized = decodedHeaders.replace(/\r\n?/g, "\n").replace(/^From \S+.*\n/, "");
|
|
2254
|
+
const lines = [];
|
|
2255
|
+
const leadingWhitespace = [];
|
|
2256
|
+
let foldedMimeHeader = false;
|
|
2257
|
+
const sourceLines = normalized.split("\n").slice(0, MAX_MIME_HEADER_LINES);
|
|
2258
|
+
for (const original of sourceLines) {
|
|
2259
|
+
const line = normalizeHeaderLine(original);
|
|
2260
|
+
if (!line) break;
|
|
2261
|
+
if (/^[\s\p{C}]/u.test(original) && lines.length) {
|
|
2262
|
+
const priorField = lines[lines.length - 1].split(":", 1)[0].replace(/\s+/g, "-").toLowerCase();
|
|
2263
|
+
if (MIME_FIELDS.some((known) => distanceAtMostOne(priorField, known))) foldedMimeHeader = true;
|
|
2264
|
+
lines[lines.length - 1] += ` ${line}`;
|
|
2265
|
+
continue;
|
|
2266
|
+
}
|
|
2267
|
+
lines.push(line);
|
|
2268
|
+
leadingWhitespace.push(/^[\p{Z}\p{C}]/u.test(original));
|
|
2269
|
+
}
|
|
2270
|
+
const fields = /* @__PURE__ */ new Set();
|
|
2271
|
+
const validMimeHeaderBlock = hasMimeHeaderBlock(normalized);
|
|
2272
|
+
let malformedHeader = hasUtf8Bom || foldedMimeHeader;
|
|
2273
|
+
let preamble = false;
|
|
2274
|
+
let cteDeclared = false;
|
|
2275
|
+
let quotedPrintableDeclared = false;
|
|
2276
|
+
for (const [index, line] of lines.entries()) {
|
|
2277
|
+
const colon = line.indexOf(":");
|
|
2278
|
+
const fieldSource = colon < 0 ? line.split(/[\s:]/, 1)[0] : line.slice(0, colon).trim();
|
|
2279
|
+
const field = fieldSource.replace(/\s+/g, "-").toLowerCase();
|
|
2280
|
+
const match = MIME_FIELDS.find((known) => distanceAtMostOne(field, known));
|
|
2281
|
+
if (match) {
|
|
2282
|
+
fields.add(match);
|
|
2283
|
+
if (match === "content-transfer-encoding") {
|
|
2284
|
+
cteDeclared = true;
|
|
2285
|
+
quotedPrintableDeclared = colon >= 0 && /^quoted-printable$/i.test(line.slice(colon + 1).trim());
|
|
2286
|
+
}
|
|
2287
|
+
if (field !== match || colon < 0 || /\s+:/u.test(line) || leadingWhitespace[index]) malformedHeader = true;
|
|
2288
|
+
} else if (line.includes(":")) {
|
|
2289
|
+
if (fields.size) preamble = true;
|
|
2290
|
+
} else if (!fields.size) {
|
|
2291
|
+
preamble = true;
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
const declared = [...fields].some((field) => field !== "mime-version") || fields.size > 1;
|
|
2295
|
+
if (!declared) return false;
|
|
2296
|
+
const bodyStart = normalized.search(/\n[ \t]*\n/);
|
|
2297
|
+
let body;
|
|
2298
|
+
if (bodyStart >= 0) body = normalized.slice(bodyStart).split("\n").slice(1);
|
|
2299
|
+
else {
|
|
2300
|
+
const lines2 = normalized.split("\n");
|
|
2301
|
+
const cte = lines2.findIndex((line) => {
|
|
2302
|
+
const field = normalizeHeaderLine(line).split(":", 1)[0].replace(/\s+/g, "-").toLowerCase();
|
|
2303
|
+
return distanceAtMostOne(field, "content-transfer-encoding");
|
|
2304
|
+
});
|
|
2305
|
+
if (cte < 0) return malformedHeader || preamble;
|
|
2306
|
+
body = lines2.slice(cte + 1);
|
|
2307
|
+
}
|
|
2308
|
+
const hasEncodedBody = body.some((line) => /^[A-Za-z0-9+/]{16,}={0,2}%{0,3}$/.test(line.trim()));
|
|
2309
|
+
const hasUrlSafeBase64Body = cteDeclared && bodyStart < 0 && preamble && body.some((line) => /^[A-Za-z0-9_-]{16,}={0,2}$/.test(line.trim()) && /[-_]/.test(line.trim()));
|
|
2310
|
+
let wrappedBase64Length = 0;
|
|
2311
|
+
let hasWrappedBase64Body = false;
|
|
2312
|
+
for (const line of body) {
|
|
2313
|
+
const trimmed = line.trim();
|
|
2314
|
+
const standard = cteDeclared && /^[A-Za-z0-9+/]{4,76}={0,2}$/.test(trimmed);
|
|
2315
|
+
const urlSafe = cteDeclared && /^[A-Za-z0-9_-]{4,76}={0,2}$/.test(trimmed) && /[-_]/.test(trimmed);
|
|
2316
|
+
if (standard || urlSafe) {
|
|
2317
|
+
wrappedBase64Length += trimmed.length;
|
|
2318
|
+
if (wrappedBase64Length >= 16) hasWrappedBase64Body = true;
|
|
2319
|
+
} else if (!/^[\t ]*$/.test(line)) {
|
|
2320
|
+
wrappedBase64Length = 0;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
const hasQuotedPrintableBody = quotedPrintableDeclared && bodyStart < 0 && preamble && body.some((line) => /=(?:[0-9A-F]{2}|$)/i.test(line.trim()));
|
|
2324
|
+
const invalidEncodedBody = cteDeclared && body.some((line) => /^[A-Za-z0-9+/]{16,}={0,2}[^A-Za-z0-9+/=\s]+$/.test(line.trim()));
|
|
2325
|
+
return (hasEncodedBody || hasUrlSafeBase64Body || hasWrappedBase64Body || hasQuotedPrintableBody) && (malformedHeader || preamble && (!validMimeHeaderBlock || bodyStart < 0) || invalidEncodedBody);
|
|
2326
|
+
}
|
|
2327
|
+
function hasEncodedFieldContext(raw, valueStart) {
|
|
2328
|
+
const before = raw.slice(Math.max(0, valueStart - 256), valueStart);
|
|
2329
|
+
const field = /(?:^|[\s,{;])(?:["']?(?:data|content|payload|image_url|base64)["']?)\s*[:=]\s*["']?\s*$/i.test(before);
|
|
2330
|
+
const dataUri = /data:[^\r\n,]*;\s*base64\s*,[\r\n\t >#;/|*+\-:!~%]*$/i.test(before);
|
|
2331
|
+
const pem = /-----BEGIN (?:RSA |EC |PRIVATE |PUBLIC )?KEY-----[\s\S]{0,256}$/i.test(before);
|
|
2332
|
+
const mime = hasH308MimeHeader(raw) && /content-transfer-encoding\s*:\s*base64/i.test(raw) || /(?:^|\n)[\t >#;/|*+\-:!~%]*content-transfer-encoding\s*:\s*(?:\r?\n[\t ]+)?base64(?:\s|$)/im.test(raw);
|
|
2333
|
+
return field || dataUri || pem || mime;
|
|
2334
|
+
}
|
|
2335
|
+
function isOpaqueBase64(raw) {
|
|
2336
|
+
if (omitLargeDataUris(raw).omitted) return true;
|
|
2337
|
+
const normalized = raw.replace(/\r\n?/g, "\n").replace(/=\n/g, "");
|
|
2338
|
+
const lines = normalized.split("\n");
|
|
2339
|
+
let encodedTotal = 0;
|
|
2340
|
+
let lineOffset = 0;
|
|
2341
|
+
let wrapped = [];
|
|
2342
|
+
let wrappedHasFieldContext = false;
|
|
2343
|
+
const stripDataUris = (line) => line.replace(/data:[^\s,]+,[^\s"'<>)]*/gi, (uri) => " ".repeat(uri.length));
|
|
2344
|
+
const base64Rows = (line) => {
|
|
2345
|
+
const numberedList = line.match(/^\d+[.)][\t ]+/)?.[0] ?? "";
|
|
2346
|
+
const remainder = line.slice(numberedList.length);
|
|
2347
|
+
const matches = /* @__PURE__ */ new Map();
|
|
2348
|
+
if (numberedList.length && !/^\d+[.)][\t ]+$/.test(numberedList)) return matches;
|
|
2349
|
+
const valid = (body) => body.length >= 32 && body.length <= 200 && /^[A-Za-z0-9+/_-]+={0,2}$/.test(body);
|
|
2350
|
+
const prefixChars = /^[\t >#;/|*+\-:!~%]$/;
|
|
2351
|
+
for (let prefixLength = 0; prefixLength <= 8; prefixLength++) {
|
|
2352
|
+
const prefix = remainder.slice(0, prefixLength);
|
|
2353
|
+
if ([...prefix].some((char) => !prefixChars.test(char))) continue;
|
|
2354
|
+
const payload = remainder.slice(prefixLength).replace(/[\t ]+\|[\t ]*$/, "").trim();
|
|
2355
|
+
if (valid(payload)) matches.set(prefixLength, payload);
|
|
2356
|
+
}
|
|
2357
|
+
return matches;
|
|
2358
|
+
};
|
|
2359
|
+
const countWrapped = () => {
|
|
2360
|
+
const commonPrefixes = wrapped.length ? [...wrapped[0].keys()].filter((prefixLength) => wrapped.every((row) => row.has(prefixLength))) : [];
|
|
2361
|
+
const selectedPrefix = commonPrefixes.sort((a, b) => a - b)[0];
|
|
2362
|
+
const payloads = wrapped.flatMap((row) => {
|
|
2363
|
+
const prefixLength = selectedPrefix ?? [...row.keys()].sort((a, b) => a - b)[0];
|
|
2364
|
+
return prefixLength === void 0 ? [] : [row.get(prefixLength)];
|
|
2365
|
+
});
|
|
2366
|
+
const isUuid = (value) => /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{32})$/i.test(value);
|
|
2367
|
+
const allUuid = payloads.length >= 3 && payloads.every(isUuid);
|
|
2368
|
+
const isHashList = payloads.length >= 3 && payloads.every((line) => /^[A-Fa-f0-9]+$/.test(line) && [32, 40, 56, 64, 96, 128].includes(line.length) && new Set(line.toLowerCase()).size > 1);
|
|
2369
|
+
const hyphenPositions = (value) => [...value].flatMap((char, index) => char === "-" ? [index] : []).join(",");
|
|
2370
|
+
const fixedHyphens = payloads.length >= 3 && payloads.every((line) => line.includes("-")) && payloads.every((line) => hyphenPositions(line) === hyphenPositions(payloads[0])) && hyphenPositions(payloads[0]).split(",").some((position) => Number(position) > 1);
|
|
2371
|
+
const pathLike = (value) => value.includes("/") && (value.includes(".") || value.includes("://") || value.includes("_"));
|
|
2372
|
+
const ordinaryIdentifiers = payloads.length >= 3 && payloads.every(pathLike);
|
|
2373
|
+
const filtered = allUuid || isHashList || fixedHyphens || ordinaryIdentifiers;
|
|
2374
|
+
const total = payloads.reduce((sum, line) => sum + line.length, 0);
|
|
2375
|
+
if (wrappedHasFieldContext && !filtered && (payloads.length >= 3 || payloads.length === 1 && payloads[0].length >= 2048) && total >= 2048) {
|
|
2376
|
+
encodedTotal += total;
|
|
2377
|
+
}
|
|
2378
|
+
wrapped = [];
|
|
2379
|
+
wrappedHasFieldContext = false;
|
|
2380
|
+
};
|
|
2381
|
+
let inBinaryPatch = false;
|
|
2382
|
+
let hasSeenGitDiff = false;
|
|
2383
|
+
for (const line of lines) {
|
|
2384
|
+
if (line.startsWith("diff --git ")) {
|
|
2385
|
+
inBinaryPatch = false;
|
|
2386
|
+
hasSeenGitDiff = true;
|
|
2387
|
+
}
|
|
2388
|
+
if (/^GIT binary patch$/.test(line)) inBinaryPatch = true;
|
|
2389
|
+
if (inBinaryPatch) {
|
|
2390
|
+
countWrapped();
|
|
2391
|
+
lineOffset += line.length + 1;
|
|
2392
|
+
continue;
|
|
2393
|
+
}
|
|
2394
|
+
const trimmed = line.trim();
|
|
2395
|
+
const diffPayload = hasSeenGitDiff && /^[+ -]/.test(trimmed);
|
|
2396
|
+
if (diffPayload) {
|
|
2397
|
+
countWrapped();
|
|
2398
|
+
lineOffset += line.length + 1;
|
|
2399
|
+
continue;
|
|
2400
|
+
}
|
|
2401
|
+
const row = base64Rows(line);
|
|
2402
|
+
if (row.size) {
|
|
2403
|
+
if (!wrapped.length) {
|
|
2404
|
+
const firstPayload = [...row.values()][0];
|
|
2405
|
+
const valueStart = lineOffset + line.indexOf(firstPayload);
|
|
2406
|
+
wrappedHasFieldContext = hasEncodedFieldContext(normalized, valueStart);
|
|
2407
|
+
}
|
|
2408
|
+
wrapped.push(row);
|
|
2409
|
+
} else {
|
|
2410
|
+
countWrapped();
|
|
2411
|
+
const scanLine = stripDataUris(line);
|
|
2412
|
+
for (const match of scanLine.matchAll(/[A-Za-z0-9+/_-]{256,}={0,2}/g)) {
|
|
2413
|
+
const start = lineOffset + (match.index ?? 0);
|
|
2414
|
+
const contextual = hasEncodedFieldContext(normalized, start);
|
|
2415
|
+
if (contextual) encodedTotal += match[0].length;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
lineOffset += line.length + 1;
|
|
2419
|
+
}
|
|
2420
|
+
countWrapped();
|
|
2421
|
+
return encodedTotal >= 2048 && encodedTotal <= 256 * 1024;
|
|
2422
|
+
}
|
|
2423
|
+
function assessH308Input(raw) {
|
|
2424
|
+
if (hasMimeHazard(raw)) return "mime";
|
|
2425
|
+
if (isOpaqueBase64(raw)) return "opaque-base64";
|
|
2426
|
+
return "ordinary";
|
|
2427
|
+
}
|
|
2428
|
+
function hasBareEncodedCteBody(raw) {
|
|
2429
|
+
const normalized = raw.replace(/\r\n?/g, "\n");
|
|
2430
|
+
if (/\n[ \t]*\n/.test(normalized)) return false;
|
|
2431
|
+
const first = /^content-transfer-encoding:[ \t]*(base64|quoted-printable)[ \t]*\n/i.exec(normalized);
|
|
2432
|
+
if (!first) return false;
|
|
2433
|
+
const encoding = first[1].toLowerCase();
|
|
2434
|
+
const body = normalized.slice(first[0].length).split("\n");
|
|
2435
|
+
if (encoding === "quoted-printable") return body.some((line) => /=(?:[0-9A-F]{2}|$)/i.test(line.trim()));
|
|
2436
|
+
if (body.some((line) => /^[A-Za-z0-9+/]{16,}={0,2}$/.test(line.trim())) || body.some((line) => /^[A-Za-z0-9_-]{16,}={0,2}$/.test(line.trim()) && /[-_]/.test(line.trim()))) {
|
|
2437
|
+
return true;
|
|
2438
|
+
}
|
|
2439
|
+
let encodedLength = 0;
|
|
2440
|
+
for (const line of body) {
|
|
2441
|
+
const trimmed = line.trim();
|
|
2442
|
+
const standard = /^[A-Za-z0-9+/]{4,76}={0,2}$/.test(trimmed);
|
|
2443
|
+
const urlSafe = /^[A-Za-z0-9_-]{4,76}={0,2}$/.test(trimmed) && /[-_]/.test(trimmed);
|
|
2444
|
+
if (standard || urlSafe) {
|
|
2445
|
+
encodedLength += trimmed.length;
|
|
2446
|
+
if (encodedLength >= 16) return true;
|
|
2447
|
+
} else if (trimmed) {
|
|
2448
|
+
encodedLength = 0;
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
return false;
|
|
2452
|
+
}
|
|
2453
|
+
function isReadablePlainTextMail(raw) {
|
|
2454
|
+
const normalized = raw.replace(/\r\n?/g, "\n");
|
|
2455
|
+
const separator = normalized.indexOf("\n\n");
|
|
2456
|
+
if (separator < 0 || !normalized.slice(separator + 2).trim()) return false;
|
|
2457
|
+
const lines = normalized.slice(0, separator).split("\n");
|
|
2458
|
+
const body = normalized.slice(separator + 2);
|
|
2459
|
+
const headers = /* @__PURE__ */ new Map();
|
|
2460
|
+
let sawMimeVersion = false;
|
|
2461
|
+
let sawAddress = false;
|
|
2462
|
+
let sawSubject = false;
|
|
2463
|
+
for (const line of lines) {
|
|
2464
|
+
const match = /^([!-9;-~]+):[ \t]*(.*)$/.exec(line);
|
|
2465
|
+
if (!match) continue;
|
|
2466
|
+
const name = match[1].toLowerCase();
|
|
2467
|
+
const value = match[2].trim();
|
|
2468
|
+
if (name === "mime-version" && value === "1.0") sawMimeVersion = true;
|
|
2469
|
+
if ((name === "from" || name === "to") && value) sawAddress = true;
|
|
2470
|
+
if (name === "subject" && value) sawSubject = true;
|
|
2471
|
+
if (name === "content-type" && !/^text\/plain(?:[ \t]*;|[ \t]*$)/i.test(value)) return false;
|
|
2472
|
+
if (name === "content-transfer-encoding" && !/^(?:7bit|8bit|quoted-printable)$/i.test(value)) return false;
|
|
2473
|
+
if (name === "content-transfer-encoding" && /^quoted-printable$/i.test(value) && /=(?:[0-9A-F]{2}|[ \t]*\n)/i.test(body)) return false;
|
|
2474
|
+
if (["content-type", "content-transfer-encoding"].includes(name) && headers.has(name)) return false;
|
|
2475
|
+
headers.set(name, value);
|
|
2476
|
+
}
|
|
2477
|
+
return sawMimeVersion && sawAddress && sawSubject;
|
|
2478
|
+
}
|
|
2479
|
+
function reviewH308Text(raw) {
|
|
2480
|
+
try {
|
|
2481
|
+
const dataUriReview = omitLargeDataUris(raw);
|
|
2482
|
+
if (dataUriReview.omitted) return { text: dataUriReview.text, warning: H308_ENCODED_PAYLOAD_NOTICE };
|
|
2483
|
+
const reviewed = dataUriReview.text;
|
|
2484
|
+
if (hasBareEncodedCteBody(reviewed)) return { text: "", warning: H308_ENCODED_PAYLOAD_NOTICE };
|
|
2485
|
+
if (assessH308Input(reviewed) === "ordinary" && isReadablePlainTextMail(reviewed)) return { text: raw };
|
|
2486
|
+
const hasMimeHeader = hasH308MimeHeader(reviewed.replace(/^\s+/, ""));
|
|
2487
|
+
if (!/[\r\n]/.test(reviewed) && !hasMimeHeader && !/[A-Za-z0-9+/_-]{256,}={0,2}/.test(reviewed)) {
|
|
2488
|
+
return { text: raw };
|
|
2489
|
+
}
|
|
2490
|
+
const assessment = assessH308Input(reviewed);
|
|
2491
|
+
if (assessment === "ordinary" && !hasMimeHeader) {
|
|
2492
|
+
return { text: raw };
|
|
2493
|
+
}
|
|
2494
|
+
if (hasMimeHeader) return { text: safeMimePreamble(reviewed) ?? "", warning: H308_ENCODED_PAYLOAD_NOTICE };
|
|
2495
|
+
return { text: "", warning: H308_ENCODED_PAYLOAD_NOTICE };
|
|
2496
|
+
} catch {
|
|
2497
|
+
return { text: "", warning: H308_ENCODED_PAYLOAD_NOTICE };
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
function omitLargeDataUris(raw) {
|
|
2501
|
+
if (!raw.includes(",")) return { text: raw, omitted: false };
|
|
2502
|
+
const starts = /data:([A-Z0-9!#$&^_.+/%;= \t-]*),/gi;
|
|
2503
|
+
const prefixChars = /^[\t >#;/|*+\-:!~%]$/;
|
|
2504
|
+
const base64Char = /^[A-Za-z0-9+/_=-]$/;
|
|
2505
|
+
let output = "";
|
|
2506
|
+
let copiedThrough = 0;
|
|
2507
|
+
let omitted = false;
|
|
2508
|
+
for (const match of raw.matchAll(starts)) {
|
|
2509
|
+
const metadata = (match[1] ?? "").replace(/\s/g, "");
|
|
2510
|
+
if (!/(?:^|;)base64(?:;|$)/i.test(metadata)) continue;
|
|
2511
|
+
const commaEnd = (match.index ?? 0) + match[0].length;
|
|
2512
|
+
let cursor = commaEnd;
|
|
2513
|
+
let payloadLength = 0;
|
|
2514
|
+
let lastPayloadEnd = commaEnd;
|
|
2515
|
+
while (cursor < raw.length) {
|
|
2516
|
+
if (base64Char.test(raw[cursor])) {
|
|
2517
|
+
payloadLength += 1;
|
|
2518
|
+
cursor += 1;
|
|
2519
|
+
lastPayloadEnd = cursor;
|
|
2520
|
+
continue;
|
|
2521
|
+
}
|
|
2522
|
+
if (raw[cursor] === "%" && /^[\da-f]{2}$/i.test(raw.slice(cursor + 1, cursor + 3)) && base64Char.test(String.fromCharCode(Number.parseInt(raw.slice(cursor + 1, cursor + 3), 16)))) {
|
|
2523
|
+
payloadLength += 3;
|
|
2524
|
+
cursor += 3;
|
|
2525
|
+
lastPayloadEnd = cursor;
|
|
2526
|
+
continue;
|
|
2527
|
+
}
|
|
2528
|
+
if (raw[cursor] !== "\r" && raw[cursor] !== "\n") break;
|
|
2529
|
+
let rowStart = cursor + (raw.startsWith("\r\n", cursor) ? 2 : 1);
|
|
2530
|
+
let prefixLength = 0;
|
|
2531
|
+
while (rowStart + prefixLength < raw.length && prefixLength < 8 && prefixChars.test(raw[rowStart + prefixLength])) prefixLength += 1;
|
|
2532
|
+
const contentStart = rowStart + prefixLength;
|
|
2533
|
+
if (!base64Char.test(raw[contentStart] ?? "")) break;
|
|
2534
|
+
cursor = contentStart;
|
|
2535
|
+
lastPayloadEnd = contentStart;
|
|
2536
|
+
}
|
|
2537
|
+
if (payloadLength < 2048) continue;
|
|
2538
|
+
const start = match.index ?? 0;
|
|
2539
|
+
output += raw.slice(copiedThrough, start) + H308_ENCODED_PAYLOAD_NOTICE;
|
|
2540
|
+
copiedThrough = lastPayloadEnd;
|
|
2541
|
+
omitted = true;
|
|
2542
|
+
starts.lastIndex = lastPayloadEnd;
|
|
2543
|
+
}
|
|
2544
|
+
return omitted ? { text: output + raw.slice(copiedThrough), omitted } : { text: raw, omitted };
|
|
2545
|
+
}
|
|
2546
|
+
function safeMimePreamble(raw) {
|
|
2547
|
+
let offset = 0;
|
|
2548
|
+
for (const line of raw.split(/\r\n?|\n/)) {
|
|
2549
|
+
const normalized = normalizeHeaderLine(line);
|
|
2550
|
+
const colon = normalized.indexOf(":");
|
|
2551
|
+
const field = (colon < 0 ? normalized.split(/[\s:]/, 1)[0] : normalized.slice(0, colon).trim()).replace(/\s+/g, "-").toLowerCase();
|
|
2552
|
+
if (MIME_FIELDS.some((known) => distanceAtMostOne(field, known))) {
|
|
2553
|
+
const preamble = raw.slice(0, offset).trimEnd();
|
|
2554
|
+
if (!preamble || preamble.split(/\r\n?|\n/).some((prior) => prior.includes(":"))) return void 0;
|
|
2555
|
+
if (assessH308Input(preamble) !== "ordinary" || hasH308MimeHeader(preamble)) return void 0;
|
|
2556
|
+
return preamble;
|
|
2557
|
+
}
|
|
2558
|
+
offset += line.length + (raw.slice(offset + line.length, offset + line.length + 2) === "\r\n" ? 2 : 1);
|
|
2559
|
+
}
|
|
2560
|
+
return void 0;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
// src/device/image-decode-gate.ts
|
|
2564
|
+
var UnreadableImageError = class extends Error {
|
|
2565
|
+
constructor(message, curatedBrand) {
|
|
2566
|
+
super(message);
|
|
2567
|
+
this.code = "invalid-image";
|
|
2568
|
+
this.name = "UnreadableImageError";
|
|
2569
|
+
if (curatedBrand !== void 0) {
|
|
2570
|
+
this[curatedBrand] = true;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
};
|
|
2574
|
+
function startsWith(b, sig) {
|
|
2575
|
+
if (b.length < sig.length) return false;
|
|
2576
|
+
for (let i = 0; i < sig.length; i++) if (b[i] !== sig[i]) return false;
|
|
2577
|
+
return true;
|
|
2578
|
+
}
|
|
2579
|
+
function sniffImageKind(bytes) {
|
|
2580
|
+
if (!bytes || bytes.length === 0) return null;
|
|
2581
|
+
if (startsWith(bytes, [137, 80, 78, 71, 13, 10, 26, 10])) return "png";
|
|
2582
|
+
if (startsWith(bytes, [255, 216, 255])) return "jpeg";
|
|
2583
|
+
if (startsWith(bytes, [71, 73, 70, 56])) return "gif";
|
|
2584
|
+
if (startsWith(bytes, [66, 77])) return "bmp";
|
|
2585
|
+
if (startsWith(bytes, [73, 73, 42, 0]) || startsWith(bytes, [77, 77, 0, 42]))
|
|
2586
|
+
return "tiff";
|
|
2587
|
+
if (bytes.length >= 12 && startsWith(bytes, [82, 73, 70, 70]) && bytes[8] === 87 && bytes[9] === 69 && bytes[10] === 66 && bytes[11] === 80)
|
|
2588
|
+
return "webp";
|
|
2589
|
+
return null;
|
|
2590
|
+
}
|
|
2591
|
+
function mimeFor(kind) {
|
|
2592
|
+
switch (kind) {
|
|
2593
|
+
case "png":
|
|
2594
|
+
return "image/png";
|
|
2595
|
+
case "jpeg":
|
|
2596
|
+
return "image/jpeg";
|
|
2597
|
+
case "gif":
|
|
2598
|
+
return "image/gif";
|
|
2599
|
+
case "webp":
|
|
2600
|
+
return "image/webp";
|
|
2601
|
+
case "bmp":
|
|
2602
|
+
return "image/bmp";
|
|
2603
|
+
case "tiff":
|
|
2604
|
+
return "image/tiff";
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
function browserDecodable(kind) {
|
|
2608
|
+
return kind === "png" || kind === "jpeg" || kind === "gif" || kind === "webp";
|
|
2609
|
+
}
|
|
2610
|
+
function hasMinimalBmpHeader(bytes) {
|
|
2611
|
+
if (bytes.length < 26) return false;
|
|
2612
|
+
const dibSize = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(14, true);
|
|
2613
|
+
return [12, 40, 52, 56, 64, 108, 124].includes(dibSize) && bytes.length >= 14 + dibSize;
|
|
2614
|
+
}
|
|
2615
|
+
function hasMinimalTiffHeader(bytes) {
|
|
2616
|
+
if (bytes.length < 8) return false;
|
|
2617
|
+
const littleEndian = bytes[0] === 73;
|
|
2618
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
2619
|
+
const firstIfdOffset = view.getUint32(4, littleEndian);
|
|
2620
|
+
if (firstIfdOffset < 8 || firstIfdOffset > bytes.length - 2) return false;
|
|
2621
|
+
const entryCount = view.getUint16(firstIfdOffset, littleEndian);
|
|
2622
|
+
const ifdEnd = firstIfdOffset + 2 + entryCount * 12 + 4;
|
|
2623
|
+
return ifdEnd <= bytes.length;
|
|
2624
|
+
}
|
|
2625
|
+
function cantRead(copy) {
|
|
2626
|
+
const nothing = copy.nothingPhrase ?? "Nothing was sent";
|
|
2627
|
+
return `We couldn't read this image. ${nothing}. Use a PNG, JPEG, WEBP, GIF, BMP or TIFF file instead.`;
|
|
2628
|
+
}
|
|
2629
|
+
async function assertDecodableImage(bytes, copy = { product: "This app" }) {
|
|
2630
|
+
const kind = sniffImageKind(bytes);
|
|
2631
|
+
if (!kind) {
|
|
2632
|
+
throw new UnreadableImageError(cantRead(copy), copy.curatedBrand);
|
|
2633
|
+
}
|
|
2634
|
+
if (kind === "bmp" && !hasMinimalBmpHeader(bytes) || kind === "tiff" && !hasMinimalTiffHeader(bytes)) {
|
|
2635
|
+
throw new UnreadableImageError(cantRead(copy), copy.curatedBrand);
|
|
2636
|
+
}
|
|
2637
|
+
if (!browserDecodable(kind)) return kind;
|
|
2638
|
+
if (typeof createImageBitmap !== "function") return kind;
|
|
2639
|
+
const plain = new Uint8Array(bytes.byteLength);
|
|
2640
|
+
plain.set(bytes);
|
|
2641
|
+
const blob = new Blob([plain], { type: mimeFor(kind) });
|
|
2642
|
+
try {
|
|
2643
|
+
const bmp = await createImageBitmap(blob);
|
|
2644
|
+
bmp.close();
|
|
2645
|
+
} catch {
|
|
2646
|
+
throw new UnreadableImageError(cantRead(copy), copy.curatedBrand);
|
|
2647
|
+
}
|
|
2648
|
+
return kind;
|
|
2649
|
+
}
|
|
2650
|
+
var IMAGE_EXTS = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "webp", "bmp", "gif", "tiff", "tif"]);
|
|
2651
|
+
var IMAGE_MIMES = /* @__PURE__ */ new Set([
|
|
2652
|
+
"image/png",
|
|
2653
|
+
"image/jpeg",
|
|
2654
|
+
"image/jpg",
|
|
2655
|
+
"image/webp",
|
|
2656
|
+
"image/bmp",
|
|
2657
|
+
"image/gif",
|
|
2658
|
+
"image/tiff"
|
|
2659
|
+
]);
|
|
2660
|
+
function isImageFilenameOrMime(fileName, mimeType = "") {
|
|
2661
|
+
const mime = (mimeType || "").toLowerCase();
|
|
2662
|
+
if (IMAGE_MIMES.has(mime)) return true;
|
|
2663
|
+
const m = /\.([A-Za-z0-9]+)\s*$/.exec(fileName || "");
|
|
2664
|
+
const ext = m ? m[1].toLowerCase() : "";
|
|
2665
|
+
return IMAGE_EXTS.has(ext);
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
// src/device/ner-l3-load-state.ts
|
|
2669
|
+
var IDLE = { state: "idle" };
|
|
2670
|
+
var _l3 = IDLE;
|
|
2671
|
+
var _subs = /* @__PURE__ */ new Set();
|
|
2672
|
+
function markLevel3Load(state, startedAt) {
|
|
2673
|
+
const neste = state === "loading" ? { state, startedAt: startedAt ?? Date.now() } : (state === "idle" || state === "error") && typeof startedAt === "number" ? { state, startedAt } : { state };
|
|
2674
|
+
if (neste.state === _l3.state && neste.startedAt === _l3.startedAt) return;
|
|
2675
|
+
_l3 = neste;
|
|
2676
|
+
const errors = [];
|
|
2677
|
+
for (const fn of [..._subs]) {
|
|
2678
|
+
try {
|
|
2679
|
+
fn(_l3);
|
|
2680
|
+
} catch (error) {
|
|
2681
|
+
errors.push(error);
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
if (errors.length > 0) throw errors[0];
|
|
2685
|
+
}
|
|
2686
|
+
function level3Load() {
|
|
2687
|
+
return _l3;
|
|
2688
|
+
}
|
|
2689
|
+
function level3StillLoading() {
|
|
2690
|
+
return _l3.state === "loading";
|
|
2691
|
+
}
|
|
2692
|
+
function isLevel3Loading(l3) {
|
|
2693
|
+
return l3?.state === "loading";
|
|
2694
|
+
}
|
|
2695
|
+
var level3LoadStore = {
|
|
2696
|
+
subscribe(run) {
|
|
2697
|
+
_subs.add(run);
|
|
2698
|
+
try {
|
|
2699
|
+
run(_l3);
|
|
2700
|
+
} catch (error) {
|
|
2701
|
+
_subs.delete(run);
|
|
2702
|
+
throw error;
|
|
2703
|
+
}
|
|
2704
|
+
return () => {
|
|
2705
|
+
_subs.delete(run);
|
|
2706
|
+
};
|
|
2707
|
+
}
|
|
2708
|
+
};
|
|
2709
|
+
function resetLevel3LoadForTest() {
|
|
2710
|
+
_l3 = IDLE;
|
|
2711
|
+
for (const fn of _subs) fn(_l3);
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
// src/device/k9-level3-kick.ts
|
|
2715
|
+
var K9_L3_MODEL_ID = "ner-mmbert";
|
|
2716
|
+
function isAbortError(error) {
|
|
2717
|
+
try {
|
|
2718
|
+
return error !== null && (typeof error === "object" || typeof error === "function") && error.name === "AbortError";
|
|
2719
|
+
} catch {
|
|
2720
|
+
return false;
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
async function kickoffLevel3IfServed(args) {
|
|
2724
|
+
if (!args.l2Ready) return "skipped-l2-not-ready";
|
|
2725
|
+
if (args.alreadyActive?.()) {
|
|
2726
|
+
markLevel3Load("ready");
|
|
2727
|
+
return "skipped-already-active";
|
|
2728
|
+
}
|
|
2729
|
+
if (typeof args.loadNonLatin !== "function") {
|
|
2730
|
+
args.declareUnsupported?.("l3-loader-missing");
|
|
2731
|
+
return "no-loader";
|
|
2732
|
+
}
|
|
2733
|
+
const base = args.modelsBase.replace(/\/+$/, "");
|
|
2734
|
+
const id = args.modelId ?? K9_L3_MODEL_ID;
|
|
2735
|
+
let cfg;
|
|
2736
|
+
try {
|
|
2737
|
+
cfg = await args.head(`${base}/${id}/config.json`);
|
|
2738
|
+
} catch {
|
|
2739
|
+
args.declareUnsupported?.("l3-asset-unreadable");
|
|
2740
|
+
return "unavailable";
|
|
2741
|
+
}
|
|
2742
|
+
if (cfg.status !== 200) {
|
|
2743
|
+
args.declareUnsupported?.("surface-hosts-no-L3-asset");
|
|
2744
|
+
return "unavailable";
|
|
2745
|
+
}
|
|
2746
|
+
const startedAt = Date.now();
|
|
2747
|
+
markLevel3Load("loading", startedAt);
|
|
2748
|
+
let q8;
|
|
2749
|
+
let fp32;
|
|
2750
|
+
try {
|
|
2751
|
+
fp32 = await args.head(`${base}/${id}/onnx/model.onnx`);
|
|
2752
|
+
q8 = fp32.status === 200 ? { status: 404 } : await args.head(`${base}/${id}/onnx/model_quantized.onnx`);
|
|
2753
|
+
} catch {
|
|
2754
|
+
markLevel3Load("idle", startedAt);
|
|
2755
|
+
args.declareUnsupported?.("l3-asset-unreadable");
|
|
2756
|
+
return "unavailable";
|
|
2757
|
+
}
|
|
2758
|
+
if (q8.status !== 200 && fp32.status !== 200) {
|
|
2759
|
+
markLevel3Load("idle", startedAt);
|
|
2760
|
+
args.declareUnsupported?.("surface-hosts-no-L3-asset");
|
|
2761
|
+
return "unavailable";
|
|
2762
|
+
}
|
|
2763
|
+
const dtype = q8.status === 200 ? "q8" : "fp32";
|
|
2764
|
+
try {
|
|
2765
|
+
await args.loadNonLatin({ url: base, modelId: id, dtype });
|
|
2766
|
+
markLevel3Load("ready");
|
|
2767
|
+
return "started";
|
|
2768
|
+
} catch (e) {
|
|
2769
|
+
if (isAbortError(e)) {
|
|
2770
|
+
markLevel3Load("idle", startedAt);
|
|
2771
|
+
return "aborted";
|
|
2772
|
+
}
|
|
2773
|
+
markLevel3Load("error", startedAt);
|
|
2774
|
+
args.declareUnsupported?.("l3-load-failed");
|
|
2775
|
+
return "failed";
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
function makeL3KickLatch() {
|
|
2779
|
+
let pending = null;
|
|
2780
|
+
return {
|
|
2781
|
+
run(kick) {
|
|
2782
|
+
if (pending) return null;
|
|
2783
|
+
const p = kick();
|
|
2784
|
+
pending = p;
|
|
2785
|
+
const release = () => {
|
|
2786
|
+
if (pending === p) pending = null;
|
|
2787
|
+
};
|
|
2788
|
+
p.then(release, release);
|
|
2789
|
+
return p;
|
|
2790
|
+
},
|
|
2791
|
+
inFlight() {
|
|
2792
|
+
return pending !== null;
|
|
2793
|
+
},
|
|
2794
|
+
reset() {
|
|
2795
|
+
pending = null;
|
|
2796
|
+
}
|
|
2797
|
+
};
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
// src/device/late-file-text-guard.ts
|
|
2801
|
+
function isLateFileTextCurrent(startText, startVersion, currentText, currentVersion) {
|
|
2802
|
+
return startText === currentText && startVersion === currentVersion;
|
|
2803
|
+
}
|
|
2804
|
+
function applyLateFileTextIfUnchanged(startText, startVersion, currentText, currentVersion, extractedText, apply) {
|
|
2805
|
+
if (!isLateFileTextCurrent(startText, startVersion, currentText, currentVersion)) return false;
|
|
2806
|
+
apply(extractedText);
|
|
2807
|
+
return true;
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
// src/device/multilingual-ner-core.ts
|
|
2811
|
+
function recommendedNerThreads() {
|
|
2812
|
+
try {
|
|
2813
|
+
const isolated = typeof crossOriginIsolated !== "undefined" && crossOriginIsolated === true;
|
|
2814
|
+
if (!isolated) return 1;
|
|
2815
|
+
const cores = typeof navigator !== "undefined" && navigator.hardwareConcurrency ? navigator.hardwareConcurrency : 4;
|
|
2816
|
+
return Math.max(1, Math.min(4, cores));
|
|
2817
|
+
} catch {
|
|
2818
|
+
return 1;
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
function safeLoadErrorDetail(error) {
|
|
2822
|
+
try {
|
|
2823
|
+
if (error instanceof Error) {
|
|
2824
|
+
const message = error.message;
|
|
2825
|
+
return typeof message === "string" ? message : "";
|
|
2826
|
+
}
|
|
2827
|
+
return String(error);
|
|
2828
|
+
} catch {
|
|
2829
|
+
return "";
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
function isAbortError2(error) {
|
|
2833
|
+
try {
|
|
2834
|
+
return error !== null && (typeof error === "object" || typeof error === "function") && error.name === "AbortError";
|
|
2835
|
+
} catch {
|
|
2836
|
+
return false;
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
function looksNameLikely(text) {
|
|
2840
|
+
if (!text) return false;
|
|
2841
|
+
if (/\p{Lu}[\p{L}'’.\-]*[ \t]+\p{Lu}[\p{L}'’.\-]*/u.test(text)) return true;
|
|
2842
|
+
return /[^\P{L}\p{Script=Latin}]{2,}/u.test(text);
|
|
2843
|
+
}
|
|
2844
|
+
var ENHANCED_NER_MODEL_BYTES = 135e6;
|
|
2845
|
+
var ENHANCED_NER_MODEL_LABEL = "multilingual name detection";
|
|
2846
|
+
function applyTransformersEnv(mod, opts) {
|
|
2847
|
+
try {
|
|
2848
|
+
const env = mod?.env;
|
|
2849
|
+
if (!env) return;
|
|
2850
|
+
env.allowRemoteModels = false;
|
|
2851
|
+
env.allowLocalModels = true;
|
|
2852
|
+
env.localModelPath = opts.modelsBaseUrl + "/";
|
|
2853
|
+
const wasm = env.backends?.onnx?.wasm;
|
|
2854
|
+
if (wasm) {
|
|
2855
|
+
opts.tuneWasm(wasm);
|
|
2856
|
+
}
|
|
2857
|
+
} catch {
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
var ORT_IN_WORKER = true;
|
|
2861
|
+
function createMultilingualNer(deps, cfg) {
|
|
2862
|
+
const { writable, browser, loadSdk } = deps;
|
|
2863
|
+
const layer2IsCancelled = deps.layer2IsCancelled ?? (() => false);
|
|
2864
|
+
const MODELS_BASE_URL = cfg.modelsBaseUrl ?? "/models";
|
|
2865
|
+
const VENDOR_TRANSFORMERS_URL = cfg.vendorTransformersUrl ?? "/vendor/transformers/transformers.min.js";
|
|
2866
|
+
const VENDOR_WASM_BASE = cfg.vendorWasmBase ?? "/vendor/transformers/";
|
|
2867
|
+
const nerModelStatus = writable({ state: "idle", progress: 0 });
|
|
2868
|
+
function currentNerStatus() {
|
|
2869
|
+
let snap = { state: "idle", progress: 0 };
|
|
2870
|
+
const stop = nerModelStatus.subscribe((s) => snap = s);
|
|
2871
|
+
stop();
|
|
2872
|
+
return snap;
|
|
2873
|
+
}
|
|
2874
|
+
function readPref() {
|
|
2875
|
+
if (!browser) return true;
|
|
2876
|
+
try {
|
|
2877
|
+
const v = localStorage.getItem(cfg.prefKey);
|
|
2878
|
+
return v !== "0";
|
|
2879
|
+
} catch {
|
|
2880
|
+
return true;
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
function writePref(on) {
|
|
2884
|
+
if (!browser) return;
|
|
2885
|
+
try {
|
|
2886
|
+
localStorage.setItem(cfg.prefKey, on ? "1" : "0");
|
|
2887
|
+
} catch {
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
const multilingualPref = writable(readPref());
|
|
2891
|
+
const storageHost = globalThis;
|
|
2892
|
+
if (browser && typeof storageHost.addEventListener === "function") {
|
|
2893
|
+
storageHost.addEventListener("storage", (event) => {
|
|
2894
|
+
if (event.key !== null && event.key !== cfg.prefKey) return;
|
|
2895
|
+
const on = readPref();
|
|
2896
|
+
multilingualPref.set(on);
|
|
2897
|
+
if (on) void enableMultilingualNer();
|
|
2898
|
+
else void disableMultilingualNer();
|
|
2899
|
+
});
|
|
2900
|
+
}
|
|
2901
|
+
function beginModelLoadStatus(now = Date.now()) {
|
|
2902
|
+
return { state: "downloading", progress: 0, startedAt: now, lastAdvanceAt: 0 };
|
|
2903
|
+
}
|
|
2904
|
+
function nerRequired() {
|
|
2905
|
+
return readPref();
|
|
2906
|
+
}
|
|
2907
|
+
async function applyNerRequirement() {
|
|
2908
|
+
if (!browser) return;
|
|
2909
|
+
if (cfg.declareRequirementThrows) {
|
|
2910
|
+
const sdk = await loadSdk();
|
|
2911
|
+
sdk.setEnhancedNerRequirement(readPref() ? "required" : "off");
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
try {
|
|
2915
|
+
const sdk = await loadSdk();
|
|
2916
|
+
sdk.setEnhancedNerRequirement(readPref() ? "required" : "off");
|
|
2917
|
+
} catch {
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
async function isReady() {
|
|
2921
|
+
if (!browser) return false;
|
|
2922
|
+
try {
|
|
2923
|
+
const sdk = await loadSdk();
|
|
2924
|
+
return sdk.isEnhancedNerModelActive();
|
|
2925
|
+
} catch {
|
|
2926
|
+
return false;
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
const l3Latch = makeL3KickLatch();
|
|
2930
|
+
async function headStatus(url) {
|
|
2931
|
+
try {
|
|
2932
|
+
const r = await fetch(url, { method: "HEAD" });
|
|
2933
|
+
return { status: r.status };
|
|
2934
|
+
} catch {
|
|
2935
|
+
return { status: 0 };
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
function publishRan(ran) {
|
|
2939
|
+
if (!browser) return;
|
|
2940
|
+
document.documentElement.dataset.cloakLayersRan = ran.join(",");
|
|
2941
|
+
}
|
|
2942
|
+
function noteLayerReadyFromEngine(sdk, id) {
|
|
2943
|
+
const begin = sdk.beginDetectionLayerLoad;
|
|
2944
|
+
if (typeof begin !== "function") return;
|
|
2945
|
+
const report = sdk.detectionLayerReport;
|
|
2946
|
+
try {
|
|
2947
|
+
if (typeof report === "function") {
|
|
2948
|
+
const ran = report().ran;
|
|
2949
|
+
if (ran.includes(id)) {
|
|
2950
|
+
publishRan(ran);
|
|
2951
|
+
return;
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
} catch {
|
|
2955
|
+
}
|
|
2956
|
+
try {
|
|
2957
|
+
begin(id).ready();
|
|
2958
|
+
publishRan(typeof report === "function" ? report().ran : []);
|
|
2959
|
+
} catch {
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
function kickoffLevel3FromSdk(sdk) {
|
|
2963
|
+
if (l3Latch.inFlight()) return;
|
|
2964
|
+
const load = sdk.loadNonLatinNerModel;
|
|
2965
|
+
const declare = sdk.declareDetectionLayerUnsupported;
|
|
2966
|
+
const hasActiveProbe = typeof sdk.isNonLatinNerModelActive === "function";
|
|
2967
|
+
l3Latch.run(async () => {
|
|
2968
|
+
const r = await kickoffLevel3IfServed({
|
|
2969
|
+
l2Ready: true,
|
|
2970
|
+
modelsBase: MODELS_BASE_URL,
|
|
2971
|
+
modelId: K9_L3_MODEL_ID,
|
|
2972
|
+
head: headStatus,
|
|
2973
|
+
alreadyActive: hasActiveProbe ? () => sdk.isNonLatinNerModelActive() === true : void 0,
|
|
2974
|
+
loadNonLatin: typeof load === "function" ? async ({ url, modelId, dtype }) => {
|
|
2975
|
+
await load({
|
|
2976
|
+
url,
|
|
2977
|
+
modelId,
|
|
2978
|
+
backend: "wasm",
|
|
2979
|
+
dtype,
|
|
2980
|
+
wasmPaths: VENDOR_WASM_BASE,
|
|
2981
|
+
proxy: ORT_IN_WORKER,
|
|
2982
|
+
pipelineWorker: cfg.pipelineWorker,
|
|
2983
|
+
loadTransformers: async () => {
|
|
2984
|
+
const mod = await import(
|
|
2985
|
+
/* @vite-ignore */
|
|
2986
|
+
new URL(VENDOR_TRANSFORMERS_URL, location.origin).href
|
|
2987
|
+
);
|
|
2988
|
+
return mod;
|
|
2989
|
+
}
|
|
2990
|
+
});
|
|
2991
|
+
} : void 0,
|
|
2992
|
+
declareUnsupported: typeof declare === "function" ? (detail) => declare("L3", detail) : void 0
|
|
2993
|
+
});
|
|
2994
|
+
if (r === "started") noteLayerReadyFromEngine(sdk, "L3");
|
|
2995
|
+
return r;
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
let requestGeneration = 0;
|
|
2999
|
+
let inFlight = null;
|
|
3000
|
+
function enableMultilingualNer() {
|
|
3001
|
+
if (!browser) return Promise.resolve(false);
|
|
3002
|
+
if (layer2IsCancelled()) return Promise.resolve(false);
|
|
3003
|
+
const generation = requestGeneration;
|
|
3004
|
+
if (inFlight?.generation === generation) return inFlight.promise;
|
|
3005
|
+
const work = (async () => {
|
|
3006
|
+
await Promise.resolve();
|
|
3007
|
+
if (layer2IsCancelled()) return false;
|
|
3008
|
+
let sdk;
|
|
3009
|
+
try {
|
|
3010
|
+
sdk = await loadSdk();
|
|
3011
|
+
} catch (e) {
|
|
3012
|
+
if (generation !== requestGeneration) return false;
|
|
3013
|
+
nerModelStatus.update((s) => ({
|
|
3014
|
+
...s,
|
|
3015
|
+
state: "error",
|
|
3016
|
+
progress: 0,
|
|
3017
|
+
error: cfg.loadErrorMessage + safeLoadErrorDetail(e)
|
|
3018
|
+
}));
|
|
3019
|
+
return false;
|
|
3020
|
+
}
|
|
3021
|
+
if (generation !== requestGeneration) return false;
|
|
3022
|
+
if (layer2IsCancelled()) return false;
|
|
3023
|
+
let modelActive;
|
|
3024
|
+
try {
|
|
3025
|
+
sdk.setEnhancedNerRequirement("required");
|
|
3026
|
+
modelActive = sdk.isEnhancedNerModelActive();
|
|
3027
|
+
} catch (e) {
|
|
3028
|
+
nerModelStatus.update((s) => ({
|
|
3029
|
+
...s,
|
|
3030
|
+
state: "error",
|
|
3031
|
+
progress: 0,
|
|
3032
|
+
error: cfg.loadErrorMessage + safeLoadErrorDetail(e)
|
|
3033
|
+
}));
|
|
3034
|
+
return false;
|
|
3035
|
+
}
|
|
3036
|
+
if (modelActive) {
|
|
3037
|
+
nerModelStatus.set({
|
|
3038
|
+
state: "ready",
|
|
3039
|
+
progress: 1,
|
|
3040
|
+
startedAt: Date.now(),
|
|
3041
|
+
lastAdvanceAt: 0
|
|
3042
|
+
});
|
|
3043
|
+
noteLayerReadyFromEngine(sdk, "L2");
|
|
3044
|
+
kickoffLevel3FromSdk(sdk);
|
|
3045
|
+
return true;
|
|
3046
|
+
}
|
|
3047
|
+
nerModelStatus.set(beginModelLoadStatus());
|
|
3048
|
+
try {
|
|
3049
|
+
if (layer2IsCancelled()) return false;
|
|
3050
|
+
await sdk.loadEnhancedNerModel({
|
|
3051
|
+
url: MODELS_BASE_URL,
|
|
3052
|
+
modelId: sdk.PORTAL_ENHANCED_NER_MODEL_ID,
|
|
3053
|
+
backend: "wasm",
|
|
3054
|
+
// ORT session-create + inference in a Web Worker (ORT_IN_WORKER).
|
|
3055
|
+
proxy: ORT_IN_WORKER,
|
|
3056
|
+
pipelineWorker: cfg.pipelineWorker,
|
|
3057
|
+
// Self-host onnxruntime-web so ort loads its .wasm/.mjs from this
|
|
3058
|
+
// surface's own origin (never a CDN).
|
|
3059
|
+
wasmPaths: VENDOR_WASM_BASE,
|
|
3060
|
+
// Load transformers.js as a VENDORED runtime ESM asset vite NEVER
|
|
3061
|
+
// touches: a @vite-ignore dynamic import of a runtime URL.
|
|
3062
|
+
loadTransformers: async () => {
|
|
3063
|
+
const mod = await import(
|
|
3064
|
+
/* @vite-ignore */
|
|
3065
|
+
new URL(VENDOR_TRANSFORMERS_URL, location.origin).href
|
|
3066
|
+
);
|
|
3067
|
+
applyTransformersEnv(mod, { modelsBaseUrl: MODELS_BASE_URL, tuneWasm: cfg.tuneWasm });
|
|
3068
|
+
return mod;
|
|
3069
|
+
},
|
|
3070
|
+
onProgress: (p) => {
|
|
3071
|
+
if (!p || generation !== requestGeneration) return;
|
|
3072
|
+
if ((p.status === "progress" || p.status === "download") && typeof p.progress === "number" && Number.isFinite(p.progress) && p.progress >= 0 && p.progress <= 100) {
|
|
3073
|
+
const ratio = Math.max(0, Math.min(1, p.progress / 100));
|
|
3074
|
+
nerModelStatus.update((s) => {
|
|
3075
|
+
const loaded = typeof p.loaded === "number" && Number.isFinite(p.loaded) && p.loaded >= 0 ? p.loaded : void 0;
|
|
3076
|
+
const total = typeof p.total === "number" && Number.isFinite(p.total) && p.total >= 0 ? p.total : void 0;
|
|
3077
|
+
const transferChanged = total !== void 0 && total !== s.total;
|
|
3078
|
+
const bytesAdvanced = loaded !== void 0 && loaded > 0 && (typeof s.loaded !== "number" || transferChanged || loaded > s.loaded);
|
|
3079
|
+
return {
|
|
3080
|
+
...s,
|
|
3081
|
+
state: ratio >= 1 ? "initialising" : "downloading",
|
|
3082
|
+
progress: ratio,
|
|
3083
|
+
...loaded === void 0 ? {} : { loaded },
|
|
3084
|
+
...total === void 0 ? {} : { total },
|
|
3085
|
+
// Only a newly observed byte count buys more of the send-path budget.
|
|
3086
|
+
lastAdvanceAt: bytesAdvanced ? Date.now() : s.lastAdvanceAt ?? 0
|
|
3087
|
+
};
|
|
3088
|
+
});
|
|
3089
|
+
} else if (p.status === "done" || p.status === "ready") {
|
|
3090
|
+
nerModelStatus.update((s) => {
|
|
3091
|
+
const eventLoaded = typeof p.loaded === "number" && Number.isFinite(p.loaded) && p.loaded > 0 ? p.loaded : 0;
|
|
3092
|
+
const knownLoaded = typeof s.loaded === "number" && Number.isFinite(s.loaded) && s.loaded > 0 ? s.loaded : 0;
|
|
3093
|
+
if (eventLoaded === 0 && knownLoaded === 0) return s;
|
|
3094
|
+
const total = typeof p.total === "number" && Number.isFinite(p.total) && p.total >= 0 ? p.total : s.total;
|
|
3095
|
+
return {
|
|
3096
|
+
...s,
|
|
3097
|
+
state: "initialising",
|
|
3098
|
+
progress: 1,
|
|
3099
|
+
loaded: eventLoaded || knownLoaded,
|
|
3100
|
+
...total === void 0 ? {} : { total },
|
|
3101
|
+
lastAdvanceAt: Date.now()
|
|
3102
|
+
};
|
|
3103
|
+
});
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
});
|
|
3107
|
+
if (generation !== requestGeneration) {
|
|
3108
|
+
if (!readPref()) {
|
|
3109
|
+
sdk.setEnhancedNerRequirement("off");
|
|
3110
|
+
sdk.unloadEnhancedNerModel();
|
|
3111
|
+
nerModelStatus.set({ state: "idle", progress: 0 });
|
|
3112
|
+
}
|
|
3113
|
+
return false;
|
|
3114
|
+
}
|
|
3115
|
+
if (layer2IsCancelled()) {
|
|
3116
|
+
try {
|
|
3117
|
+
sdk.unloadEnhancedNerModel();
|
|
3118
|
+
} catch {
|
|
3119
|
+
}
|
|
3120
|
+
nerModelStatus.set({ state: "idle", progress: 0 });
|
|
3121
|
+
return false;
|
|
3122
|
+
}
|
|
3123
|
+
nerModelStatus.update((s) => ({ ...s, state: "ready", progress: 1 }));
|
|
3124
|
+
noteLayerReadyFromEngine(sdk, "L2");
|
|
3125
|
+
kickoffLevel3FromSdk(sdk);
|
|
3126
|
+
return true;
|
|
3127
|
+
} catch (e) {
|
|
3128
|
+
if (generation !== requestGeneration) return false;
|
|
3129
|
+
if (isAbortError2(e)) {
|
|
3130
|
+
nerModelStatus.update((s) => ({ ...s, state: "idle", progress: 0 }));
|
|
3131
|
+
return false;
|
|
3132
|
+
}
|
|
3133
|
+
try {
|
|
3134
|
+
(await loadSdk()).unloadEnhancedNerModel();
|
|
3135
|
+
} catch {
|
|
3136
|
+
}
|
|
3137
|
+
nerModelStatus.update((s) => ({
|
|
3138
|
+
...s,
|
|
3139
|
+
state: "error",
|
|
3140
|
+
progress: 0,
|
|
3141
|
+
error: cfg.loadErrorMessage + safeLoadErrorDetail(e)
|
|
3142
|
+
}));
|
|
3143
|
+
return false;
|
|
3144
|
+
}
|
|
3145
|
+
})();
|
|
3146
|
+
const promise = work.finally(() => {
|
|
3147
|
+
if (inFlight?.promise === promise) inFlight = null;
|
|
3148
|
+
});
|
|
3149
|
+
inFlight = { generation, promise };
|
|
3150
|
+
return promise;
|
|
3151
|
+
}
|
|
3152
|
+
async function disableMultilingualNer() {
|
|
3153
|
+
if (!browser) return;
|
|
3154
|
+
requestGeneration++;
|
|
3155
|
+
try {
|
|
3156
|
+
const sdk = await loadSdk();
|
|
3157
|
+
sdk.setEnhancedNerRequirement("off");
|
|
3158
|
+
sdk.unloadEnhancedNerModel();
|
|
3159
|
+
try {
|
|
3160
|
+
sdk.unloadNonLatinNerModel?.();
|
|
3161
|
+
} catch {
|
|
3162
|
+
}
|
|
3163
|
+
} catch {
|
|
3164
|
+
}
|
|
3165
|
+
nerModelStatus.set({ state: "idle", progress: 0 });
|
|
3166
|
+
}
|
|
3167
|
+
async function setMultilingualPref(on) {
|
|
3168
|
+
writePref(on);
|
|
3169
|
+
multilingualPref.set(on);
|
|
3170
|
+
if (on) await enableMultilingualNer();
|
|
3171
|
+
else await disableMultilingualNer();
|
|
3172
|
+
}
|
|
3173
|
+
function kickoffIfPreferred() {
|
|
3174
|
+
if (!browser) return;
|
|
3175
|
+
if (readPref()) void enableMultilingualNer();
|
|
3176
|
+
else void applyNerRequirement();
|
|
3177
|
+
}
|
|
3178
|
+
async function ensureMultilingualReady() {
|
|
3179
|
+
if (!browser) return;
|
|
3180
|
+
if (!readPref()) {
|
|
3181
|
+
await applyNerRequirement();
|
|
3182
|
+
return;
|
|
3183
|
+
}
|
|
3184
|
+
if (await isReady()) return;
|
|
3185
|
+
await enableMultilingualNer();
|
|
3186
|
+
}
|
|
3187
|
+
function prewarmMultilingualNer() {
|
|
3188
|
+
if (!browser) return;
|
|
3189
|
+
if (!readPref()) {
|
|
3190
|
+
void applyNerRequirement();
|
|
3191
|
+
return;
|
|
3192
|
+
}
|
|
3193
|
+
const start = () => void enableMultilingualNer();
|
|
3194
|
+
try {
|
|
3195
|
+
const ric = globalThis.requestIdleCallback;
|
|
3196
|
+
if (typeof ric === "function") ric(start);
|
|
3197
|
+
else start();
|
|
3198
|
+
} catch {
|
|
3199
|
+
start();
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
return {
|
|
3203
|
+
nerModelStatus,
|
|
3204
|
+
multilingualPref,
|
|
3205
|
+
currentNerStatus,
|
|
3206
|
+
readPref,
|
|
3207
|
+
beginModelLoadStatus,
|
|
3208
|
+
nerRequired,
|
|
3209
|
+
applyNerRequirement,
|
|
3210
|
+
isReady,
|
|
3211
|
+
enableMultilingualNer,
|
|
3212
|
+
disableMultilingualNer,
|
|
3213
|
+
setMultilingualPref,
|
|
3214
|
+
kickoffIfPreferred,
|
|
3215
|
+
ensureMultilingualReady,
|
|
3216
|
+
prewarmMultilingualNer,
|
|
3217
|
+
resetLevel3Latch: () => l3Latch.reset()
|
|
3218
|
+
};
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3221
|
+
// src/device/name-layer-unchecked.ts
|
|
3222
|
+
function nameLayerUnchecked(status) {
|
|
3223
|
+
return status !== "ok";
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
// src/device/ner-accept-gate.ts
|
|
3227
|
+
var ALL_BLOCK_REASONS = [
|
|
3228
|
+
"error",
|
|
3229
|
+
"stalled",
|
|
3230
|
+
"loading",
|
|
3231
|
+
"unavailable",
|
|
3232
|
+
"unproven-script"
|
|
3233
|
+
];
|
|
3234
|
+
var TIMING_BLOCK_REASONS = ["stalled", "loading"];
|
|
3235
|
+
var LOAD_FAILURE_BLOCK_REASONS = [];
|
|
3236
|
+
var ACCEPTANCE_BLOCK_REASONS = [
|
|
3237
|
+
...TIMING_BLOCK_REASONS,
|
|
3238
|
+
...LOAD_FAILURE_BLOCK_REASONS
|
|
3239
|
+
];
|
|
3240
|
+
function erAksepterbarBlokk(d) {
|
|
3241
|
+
return d.decision === "block" && typeof d.reason === "string" && ACCEPTANCE_BLOCK_REASONS.includes(d.reason);
|
|
3242
|
+
}
|
|
3243
|
+
function acceptanceApplies(d) {
|
|
3244
|
+
return d.decision === "wait" || erAksepterbarBlokk(d);
|
|
3245
|
+
}
|
|
3246
|
+
function stallNeedsChoice(d, hasAcceptance) {
|
|
3247
|
+
return choiceNeeded(d, hasAcceptance);
|
|
3248
|
+
}
|
|
3249
|
+
function choiceNeeded(d, hasAcceptance) {
|
|
3250
|
+
return !hasAcceptance && erAksepterbarBlokk(d);
|
|
3251
|
+
}
|
|
3252
|
+
function gateStateToDecision(state, modelState) {
|
|
3253
|
+
if (state === "loading") return { decision: "wait" };
|
|
3254
|
+
if (state === "blocked") {
|
|
3255
|
+
return { decision: "block", reason: modelState === "error" ? "error" : "stalled" };
|
|
3256
|
+
}
|
|
3257
|
+
return { decision: state };
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
// src/device/ner-receipt-core.ts
|
|
3261
|
+
function layersRanForReceipt(slots) {
|
|
3262
|
+
const ran = ["L1"];
|
|
3263
|
+
if (slots.l2Ran) ran.push("L2");
|
|
3264
|
+
if (slots.l3Ran) ran.push("L3");
|
|
3265
|
+
return ran;
|
|
3266
|
+
}
|
|
3267
|
+
function layersRanWithListCheck(layers, layerA) {
|
|
3268
|
+
return layerA === "ready" ? [...layers] : layers.filter((l) => l !== "L1");
|
|
3269
|
+
}
|
|
3270
|
+
var LOADER_STATES_FOR_RECEIPT = [
|
|
3271
|
+
"idle",
|
|
3272
|
+
"downloading",
|
|
3273
|
+
"initialising",
|
|
3274
|
+
"ready",
|
|
3275
|
+
"error"
|
|
3276
|
+
];
|
|
3277
|
+
function l2RanForLoaderState(state, required) {
|
|
3278
|
+
return required && state === "ready";
|
|
3279
|
+
}
|
|
3280
|
+
var NER_L2_DID_NOT_RUN_MESSAGE = "Names have not been checked \u2014 the on-device name model did not run.";
|
|
3281
|
+
var NER_UNPROVEN_SCRIPT_CODE = "unproven-script";
|
|
3282
|
+
function reconstructSourceFromMap(cloaked, detokMap) {
|
|
3283
|
+
const entries = Object.entries(detokMap ?? {}).filter(([surr, orig]) => Boolean(surr) && Boolean(orig)).sort((a, b) => b[0].length - a[0].length);
|
|
3284
|
+
if (entries.length === 0) return cloaked;
|
|
3285
|
+
const escaped = entries.map(([surr]) => surr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
3286
|
+
const surrogatePattern = new RegExp(escaped.join("|"), "g");
|
|
3287
|
+
const originalsBySurrogate = new Map(entries);
|
|
3288
|
+
return cloaked.replace(surrogatePattern, (surr) => originalsBySurrogate.get(surr));
|
|
3289
|
+
}
|
|
3290
|
+
function hasIncompleteDetokenisationMap(detokMap) {
|
|
3291
|
+
return Object.entries(detokMap ?? {}).some(
|
|
3292
|
+
([surrogate, original]) => !surrogate || typeof original !== "string" || original.length === 0
|
|
3293
|
+
);
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
// src/device/ner-gate-budget.ts
|
|
3297
|
+
function fragmentHasNonLatinLetter(s) {
|
|
3298
|
+
for (const ch of s) {
|
|
3299
|
+
if (/\p{L}/u.test(ch) && !/[A-Za-z\u00C0-\u024F]/.test(ch)) return true;
|
|
3300
|
+
}
|
|
3301
|
+
return false;
|
|
3302
|
+
}
|
|
3303
|
+
var NER_READY_BUDGET_MS = 25e3;
|
|
3304
|
+
var NER_STALL_BUDGET_MS = 45e3;
|
|
3305
|
+
var NER_READY_MAX_WAIT_MS = 30 * 6e4;
|
|
3306
|
+
var NER_READY_USER_WAIT_MS = 30 * 6e4;
|
|
3307
|
+
var NER_BLOCK_CODE = "detector-unavailable";
|
|
3308
|
+
var NER_REQUIRED_MESSAGE = "name-detection-unavailable";
|
|
3309
|
+
function nerGateDecision(s) {
|
|
3310
|
+
if (s.state === "error") return { decision: "degraded" };
|
|
3311
|
+
if (!s.required) return { decision: "proceed" };
|
|
3312
|
+
if (s.state === "ready") return { decision: "proceed" };
|
|
3313
|
+
const ceiling = s.startedAt + (s.userChoseToWait ? NER_READY_USER_WAIT_MS : NER_READY_MAX_WAIT_MS);
|
|
3314
|
+
const progressDeadline = s.state === "initialising" ? ceiling : s.lastAdvanceAt > 0 ? s.lastAdvanceAt + NER_STALL_BUDGET_MS : s.startedAt + NER_READY_BUDGET_MS;
|
|
3315
|
+
const deadline = Math.min(ceiling, Math.max(s.startedAt + NER_READY_BUDGET_MS, progressDeadline));
|
|
3316
|
+
const stalled = s.now >= deadline && s.now < ceiling;
|
|
3317
|
+
if (stalled) {
|
|
3318
|
+
return { decision: "degraded" };
|
|
3319
|
+
}
|
|
3320
|
+
const silentPastCeiling = s.now >= ceiling && s.state !== "initialising" && s.startedAt > 0 && (s.lastAdvanceAt > 0 ? s.now >= s.lastAdvanceAt + NER_STALL_BUDGET_MS : s.now >= s.startedAt + NER_READY_BUDGET_MS);
|
|
3321
|
+
if (silentPastCeiling) {
|
|
3322
|
+
return { decision: "degraded" };
|
|
3323
|
+
}
|
|
3324
|
+
return { decision: "wait", deadline, slow: s.now >= ceiling };
|
|
3325
|
+
}
|
|
3326
|
+
function makeNerBlockMessage(noun, tail) {
|
|
3327
|
+
return function nerBlockMessage(reason) {
|
|
3328
|
+
switch (reason) {
|
|
3329
|
+
case "error":
|
|
3330
|
+
return `The on-device name-detection model couldn't load on this device, so the names in your ${noun} have NOT been fully checked.` + tail + " This is a problem loading the privacy model here, not a problem reaching our servers \u2014 retry, or use a desktop browser.";
|
|
3331
|
+
case "stalled":
|
|
3332
|
+
return `The on-device name-detection model stopped downloading, so the names in your ${noun} have NOT been fully checked.` + tail + " Check your connection and retry.";
|
|
3333
|
+
case "loading":
|
|
3334
|
+
return `The on-device name-detection model is still downloading and ran out of time, so the names in your ${noun} have NOT been fully checked.` + tail + " Leave this tab open for a moment and try again \u2014 the download resumes where it left off.";
|
|
3335
|
+
case "unproven-script":
|
|
3336
|
+
return "This page contains writing in a script where our on-device name detection is not yet verified, so it has NOT been sent. Your text is still in the editor.";
|
|
3337
|
+
case "unavailable":
|
|
3338
|
+
default:
|
|
3339
|
+
return `The on-device name-detection model is not available in this browser, so the names in your ${noun} have NOT been fully checked.` + tail;
|
|
3340
|
+
}
|
|
3341
|
+
};
|
|
3342
|
+
}
|
|
3343
|
+
var NerBlockedError = class extends Error {
|
|
3344
|
+
constructor(reason) {
|
|
3345
|
+
super(`${NER_REQUIRED_MESSAGE}:${reason}`);
|
|
3346
|
+
this.code = NER_BLOCK_CODE;
|
|
3347
|
+
this.name = "NerBlockedError";
|
|
3348
|
+
this.reason = reason;
|
|
3349
|
+
}
|
|
3350
|
+
};
|
|
3351
|
+
function coverageReceiptClaims(coverage) {
|
|
3352
|
+
return { name_detection: coverage.status };
|
|
3353
|
+
}
|
|
3354
|
+
function coverageWarningFor(coverage, state, coverageWarning) {
|
|
3355
|
+
if (coverage.status === "off") return null;
|
|
3356
|
+
if (coverage.status === "ok" && state === "ready") return null;
|
|
3357
|
+
return coverageWarning;
|
|
3358
|
+
}
|
|
3359
|
+
function assertNerAllowsEgress(coverage, state, coverageWarning) {
|
|
3360
|
+
return { coverage, warning: coverageWarningFor(coverage, state, coverageWarning) };
|
|
3361
|
+
}
|
|
3362
|
+
function makeNonLatinProtectionUnproven(deps, requireNonLatinLetterInFragment) {
|
|
3363
|
+
return function nonLatinProtectionUnproven(cloaked, detokMap, spans) {
|
|
3364
|
+
const originals = [
|
|
3365
|
+
...Object.values(detokMap ?? {}),
|
|
3366
|
+
...(spans ?? []).map((s) => s.original ?? "")
|
|
3367
|
+
].filter((o) => typeof o === "string" && o.length >= 2);
|
|
3368
|
+
const source = reconstructSourceFromMap(cloaked, detokMap);
|
|
3369
|
+
const sentences = deps.splitSentenceRanges(source).map((r) => source.slice(r.start, r.end)).filter(
|
|
3370
|
+
(s) => s.trim().length > 0 && deps.sentenceIsNonLatin(s) && (!requireNonLatinLetterInFragment || fragmentHasNonLatinLetter(s))
|
|
3371
|
+
);
|
|
3372
|
+
if (sentences.length === 0) return false;
|
|
3373
|
+
if (requireNonLatinLetterInFragment) {
|
|
3374
|
+
const tookNonLatin = originals.some((o) => fragmentHasNonLatinLetter(o));
|
|
3375
|
+
return sentences.some((sentence) => {
|
|
3376
|
+
const taken = originals.filter((o) => sentence.includes(o));
|
|
3377
|
+
if (tookNonLatin) return taken.some((o) => cloaked.includes(o));
|
|
3378
|
+
if (taken.length === 0) return true;
|
|
3379
|
+
return taken.some((o) => cloaked.includes(o));
|
|
3380
|
+
});
|
|
3381
|
+
}
|
|
3382
|
+
return sentences.some((sentence) => {
|
|
3383
|
+
const taken = originals.filter((o) => sentence.includes(o));
|
|
3384
|
+
if (taken.length === 0) return true;
|
|
3385
|
+
return taken.some((o) => cloaked.includes(o));
|
|
3386
|
+
});
|
|
3387
|
+
};
|
|
3388
|
+
}
|
|
3389
|
+
function assertNonLatinSpansTaken(_cloaked, _detokMap, _spans) {
|
|
3390
|
+
return;
|
|
3391
|
+
}
|
|
3392
|
+
function createNerGateBudget(deps, cfg) {
|
|
3393
|
+
return {
|
|
3394
|
+
nerBlockMessage: makeNerBlockMessage(cfg.productNoun, cfg.blockTail),
|
|
3395
|
+
nonLatinProtectionUnproven: makeNonLatinProtectionUnproven(
|
|
3396
|
+
deps,
|
|
3397
|
+
cfg.requireNonLatinLetterInFragment === true
|
|
3398
|
+
)
|
|
3399
|
+
};
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3402
|
+
// src/device/ner-gate-coverage.ts
|
|
3403
|
+
var DETECTOR_UNAVAILABLE_REASON = "detector-unavailable";
|
|
3404
|
+
var NER_WAIT_BUDGET_MS = 30 * 6e4;
|
|
3405
|
+
function nerGate(status, prefOn, waitedMs = 0) {
|
|
3406
|
+
if (status.state === "error") return "blocked";
|
|
3407
|
+
if (!prefOn) return "off";
|
|
3408
|
+
if (status.state === "ready") return "ready";
|
|
3409
|
+
void waitedMs;
|
|
3410
|
+
return "loading";
|
|
3411
|
+
}
|
|
3412
|
+
function isNerUnavailable(e) {
|
|
3413
|
+
if (!e) return false;
|
|
3414
|
+
try {
|
|
3415
|
+
const anyE = e;
|
|
3416
|
+
if (anyE.code === "name-detection-unavailable") return true;
|
|
3417
|
+
if (anyE.name === "NerUnavailableError") return true;
|
|
3418
|
+
return typeof anyE.message === "string" && anyE.message.startsWith("name-detection-unavailable");
|
|
3419
|
+
} catch {
|
|
3420
|
+
return false;
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
var NER_UNPROVEN_SCRIPT_MESSAGE = "This page contains writing in a script where our on-device name detection is not yet verified, so it has NOT been sent. Your text is still in the editor.";
|
|
3424
|
+
function makeNonLatinProtectionUnproven2(deps) {
|
|
3425
|
+
return function nonLatinProtectionUnproven(cloaked, detokMap, spans) {
|
|
3426
|
+
if (hasIncompleteDetokenisationMap(detokMap)) return true;
|
|
3427
|
+
const originals = [
|
|
3428
|
+
...Object.values(detokMap ?? {}),
|
|
3429
|
+
...(spans ?? []).map((s) => s.original ?? "")
|
|
3430
|
+
].filter((o) => typeof o === "string" && o.length >= 2);
|
|
3431
|
+
const source = reconstructSourceFromMap(cloaked, detokMap);
|
|
3432
|
+
const sentences = deps.splitSentenceRanges(source).map((r) => source.slice(r.start, r.end)).filter((s) => s.trim().length > 0 && deps.sentenceIsNonLatin(s));
|
|
3433
|
+
if (sentences.length === 0) return false;
|
|
3434
|
+
return sentences.some((sentence) => {
|
|
3435
|
+
const taken = originals.filter((o) => sentence.includes(o));
|
|
3436
|
+
if (taken.length === 0) return true;
|
|
3437
|
+
return taken.some((o) => cloaked.includes(o));
|
|
3438
|
+
});
|
|
3439
|
+
};
|
|
3440
|
+
}
|
|
3441
|
+
function createNerGateCoverage(deps) {
|
|
3442
|
+
return {
|
|
3443
|
+
nerGate,
|
|
3444
|
+
isNerUnavailable,
|
|
3445
|
+
nonLatinProtectionUnproven: makeNonLatinProtectionUnproven2(deps)
|
|
3446
|
+
};
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3449
|
+
// src/device/ocr-union.ts
|
|
3450
|
+
function repairOcrFragmentedEmails(text) {
|
|
3451
|
+
if (typeof text !== "string") return "";
|
|
3452
|
+
const isLocal = (c) => c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 46 || c === 95 || c === 37 || c === 43 || c === 45;
|
|
3453
|
+
const isLetter = (c) => c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
3454
|
+
const isDomain = (c) => c >= 48 && c <= 57 || isLetter(c) || c === 46 || c === 45 || c === 32 || c === 9 || c === 13 || c === 10;
|
|
3455
|
+
const isWhitespace = (c) => c === 32 || c === 9 || c === 13 || c === 10;
|
|
3456
|
+
const n = text.length;
|
|
3457
|
+
let out = "";
|
|
3458
|
+
let copied = 0;
|
|
3459
|
+
let from = 0;
|
|
3460
|
+
let at = text.indexOf("@");
|
|
3461
|
+
while (at !== -1) {
|
|
3462
|
+
let start = at;
|
|
3463
|
+
while (start > from && isLocal(text.charCodeAt(start - 1))) start--;
|
|
3464
|
+
let end = -1;
|
|
3465
|
+
if (start < at) {
|
|
3466
|
+
let k = at + 1;
|
|
3467
|
+
while (k < n && isDomain(text.charCodeAt(k))) {
|
|
3468
|
+
if (isWhitespace(text.charCodeAt(k))) {
|
|
3469
|
+
let next = k;
|
|
3470
|
+
while (next < n && isWhitespace(text.charCodeAt(next))) next++;
|
|
3471
|
+
if (text[k - 1] !== "." && text[k - 1] !== "-" && text[next] !== ".") break;
|
|
3472
|
+
k = next;
|
|
3473
|
+
continue;
|
|
3474
|
+
}
|
|
3475
|
+
if (text.charCodeAt(k) === 46 && k + 2 < n && isLetter(text.charCodeAt(k + 1)) && isLetter(text.charCodeAt(k + 2))) {
|
|
3476
|
+
let e = k + 3;
|
|
3477
|
+
while (e < n && isLetter(text.charCodeAt(e))) e++;
|
|
3478
|
+
if (e + 2 < n && text.charCodeAt(e) === 46 && isLetter(text.charCodeAt(e + 1)) && isLetter(text.charCodeAt(e + 2))) {
|
|
3479
|
+
e += 3;
|
|
3480
|
+
while (e < n && isLetter(text.charCodeAt(e))) e++;
|
|
3481
|
+
}
|
|
3482
|
+
end = e;
|
|
3483
|
+
break;
|
|
3484
|
+
}
|
|
3485
|
+
k++;
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
if (end === -1) {
|
|
3489
|
+
at = text.indexOf("@", at + 1);
|
|
3490
|
+
continue;
|
|
3491
|
+
}
|
|
3492
|
+
out += text.slice(copied, start) + text.slice(start, end).replace(/[ \t\r\n]+/g, "");
|
|
3493
|
+
copied = end;
|
|
3494
|
+
from = end;
|
|
3495
|
+
at = text.indexOf("@", end);
|
|
3496
|
+
}
|
|
3497
|
+
return copied === 0 ? text : out + text.slice(copied);
|
|
3498
|
+
}
|
|
3499
|
+
function nyttReintBokstavToken(t) {
|
|
3500
|
+
if (!/[^\u0000-\u007F]/.test(t)) return false;
|
|
3501
|
+
const kjerne = t.replace(/^[^\p{L}\p{M}\p{N}@]+|[^\p{L}\p{M}\p{N}@]+$/gu, "");
|
|
3502
|
+
return /^[\p{L}\p{M}](?:[\p{L}\p{M}\-'\u2019]*[\p{L}\p{M}])?$/u.test(kjerne);
|
|
3503
|
+
}
|
|
3504
|
+
function andrePassBidrag(primaer, sekundaer) {
|
|
3505
|
+
if (typeof sekundaer !== "string" || !sekundaer) return "";
|
|
3506
|
+
if (typeof primaer !== "string" || !primaer.trim()) return sekundaer;
|
|
3507
|
+
const kjende = new Set(primaer.split(/\s+/).filter(Boolean));
|
|
3508
|
+
const ut = [];
|
|
3509
|
+
for (const linje of sekundaer.split(/\r?\n/)) {
|
|
3510
|
+
const token = linje.split(/\s+/).filter(Boolean);
|
|
3511
|
+
const nye = token.filter((t) => !kjende.has(t) && /[^\u0000-\u007F]/.test(t));
|
|
3512
|
+
if (nye.length === 0) continue;
|
|
3513
|
+
if (token.every((t) => kjende.has(t) || nyttReintBokstavToken(t))) {
|
|
3514
|
+
ut.push(linje.trim());
|
|
3515
|
+
continue;
|
|
3516
|
+
}
|
|
3517
|
+
ut.push(nye.join(" "));
|
|
3518
|
+
}
|
|
3519
|
+
return ut.join("\n");
|
|
3520
|
+
}
|
|
3521
|
+
var OCR_LESEGOLV = 85;
|
|
3522
|
+
var OCR_LESEGOLV_NEMNAR = 121;
|
|
3523
|
+
var OCR_LESEGOLV_MAALT = "2026-09-13";
|
|
3524
|
+
function ordUnderLesegolvet(ord, golv = OCR_LESEGOLV) {
|
|
3525
|
+
if (!ord || ord.length === 0) return null;
|
|
3526
|
+
let verst = null;
|
|
3527
|
+
for (const o of ord) {
|
|
3528
|
+
if (!o || typeof o.konfidens !== "number" || Number.isNaN(o.konfidens)) continue;
|
|
3529
|
+
if (!o.text || !o.text.trim()) continue;
|
|
3530
|
+
if (o.konfidens >= golv) continue;
|
|
3531
|
+
if (!verst || o.konfidens < verst.konfidens) verst = o;
|
|
3532
|
+
}
|
|
3533
|
+
return verst;
|
|
3534
|
+
}
|
|
3535
|
+
function ordFraTesseractMedSkip(data) {
|
|
3536
|
+
const ut = [];
|
|
3537
|
+
let hoppaOver = 0;
|
|
3538
|
+
const blokker = data?.blocks;
|
|
3539
|
+
if (!Array.isArray(blokker)) {
|
|
3540
|
+
if (blokker !== void 0 && blokker !== null && blokker !== false) hoppaOver += 1;
|
|
3541
|
+
return { ord: ut, hoppaOver };
|
|
3542
|
+
}
|
|
3543
|
+
for (const b of blokker) {
|
|
3544
|
+
const avsnitt = b?.paragraphs;
|
|
3545
|
+
if (!Array.isArray(avsnitt)) {
|
|
3546
|
+
hoppaOver += 1;
|
|
3547
|
+
continue;
|
|
3548
|
+
}
|
|
3549
|
+
for (const p of avsnitt) {
|
|
3550
|
+
const linjer = p?.lines;
|
|
3551
|
+
if (!Array.isArray(linjer)) {
|
|
3552
|
+
hoppaOver += 1;
|
|
3553
|
+
continue;
|
|
3554
|
+
}
|
|
3555
|
+
for (const l of linjer) {
|
|
3556
|
+
const ord = l?.words;
|
|
3557
|
+
if (!Array.isArray(ord)) {
|
|
3558
|
+
hoppaOver += 1;
|
|
3559
|
+
continue;
|
|
3560
|
+
}
|
|
3561
|
+
for (const o of ord) {
|
|
3562
|
+
if (typeof o?.text !== "string" || typeof o?.confidence !== "number" || !Number.isFinite(o.confidence) || o.confidence < 0 || o.confidence > 100) {
|
|
3563
|
+
hoppaOver += 1;
|
|
3564
|
+
continue;
|
|
3565
|
+
}
|
|
3566
|
+
ut.push({ text: o.text, konfidens: o.confidence });
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
return { ord: ut, hoppaOver };
|
|
3572
|
+
}
|
|
3573
|
+
function ordFraTesseract(data) {
|
|
3574
|
+
return ordFraTesseractMedSkip(data).ord;
|
|
3575
|
+
}
|
|
3576
|
+
var OcrUfullstendigFeil = class extends Error {
|
|
3577
|
+
constructor(hoppaOver) {
|
|
3578
|
+
super(`text recognition was incomplete (${hoppaOver} unreadable part${hoppaOver === 1 ? "" : "s"})`);
|
|
3579
|
+
this.name = "OcrUfullstendigFeil";
|
|
3580
|
+
this.hoppaOver = hoppaOver;
|
|
3581
|
+
}
|
|
3582
|
+
};
|
|
3583
|
+
function ordFraTesseractFullstendig(data) {
|
|
3584
|
+
const resultat = (() => {
|
|
3585
|
+
try {
|
|
3586
|
+
const parsed = ordFraTesseractMedSkip(data);
|
|
3587
|
+
const blocks = data?.blocks;
|
|
3588
|
+
return { ...parsed, harBlokker: Array.isArray(blocks) };
|
|
3589
|
+
} catch {
|
|
3590
|
+
throw new OcrUfullstendigFeil(1);
|
|
3591
|
+
}
|
|
3592
|
+
})();
|
|
3593
|
+
if (!resultat.harBlokker) throw new OcrUfullstendigFeil(Math.max(1, resultat.hoppaOver));
|
|
3594
|
+
const tekst = data?.text;
|
|
3595
|
+
if (resultat.ord.length === 0 && typeof tekst === "string" && tekst.trim().length > 0) {
|
|
3596
|
+
throw new OcrUfullstendigFeil(1);
|
|
3597
|
+
}
|
|
3598
|
+
if (resultat.hoppaOver > 0) throw new OcrUfullstendigFeil(resultat.hoppaOver);
|
|
3599
|
+
return resultat.ord;
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3602
|
+
// src/device/ocr-ulese-egress.ts
|
|
3603
|
+
var OCR_ULESE_SURROGAT_PREFIKS = "[OCR-ULESE-";
|
|
3604
|
+
var OCR_ULESE_SPAN_TYPE = "OTHER";
|
|
3605
|
+
function uleseOrdKjerne(t) {
|
|
3606
|
+
if (typeof t !== "string") return "";
|
|
3607
|
+
return t.replace(/^[^\p{L}\p{M}\p{N}]+|[^\p{L}\p{M}\p{N}]+$/gu, "");
|
|
3608
|
+
}
|
|
3609
|
+
function ordaUnderLesegolvet(ord, golv = OCR_LESEGOLV) {
|
|
3610
|
+
if (!ord || ord.length === 0) return [];
|
|
3611
|
+
const ut = [];
|
|
3612
|
+
for (const o of ord) {
|
|
3613
|
+
if (!o || typeof o.konfidens !== "number" || Number.isNaN(o.konfidens)) continue;
|
|
3614
|
+
if (typeof o.text !== "string" || !o.text.trim()) continue;
|
|
3615
|
+
if (o.konfidens >= golv) continue;
|
|
3616
|
+
ut.push(o);
|
|
3617
|
+
}
|
|
3618
|
+
return ut;
|
|
3619
|
+
}
|
|
3620
|
+
function verdTokenisering(kjerne) {
|
|
3621
|
+
if (kjerne.length < 2) return false;
|
|
3622
|
+
return /[\p{L}\p{N}]/u.test(kjerne);
|
|
3623
|
+
}
|
|
3624
|
+
function tokeniserUleseOcrOrd(review, ord, verktoy, golv = OCR_LESEGOLV, nummerFra = 0) {
|
|
3625
|
+
const tom = { review, tokeniserte: [], alleredeDekte: [] };
|
|
3626
|
+
if (!review || typeof review.body !== "string" || !review.map) return tom;
|
|
3627
|
+
if (!verktoy || typeof verktoy.indexOfWholeToken !== "function") return tom;
|
|
3628
|
+
const under = ordaUnderLesegolvet(ord, golv);
|
|
3629
|
+
if (under.length === 0) return tom;
|
|
3630
|
+
const verstePerKjerne = /* @__PURE__ */ new Map();
|
|
3631
|
+
for (const o of under) {
|
|
3632
|
+
const kjerne = uleseOrdKjerne(o.text);
|
|
3633
|
+
if (!verdTokenisering(kjerne)) continue;
|
|
3634
|
+
const fyrr = verstePerKjerne.get(kjerne);
|
|
3635
|
+
if (fyrr === void 0 || o.konfidens < fyrr) verstePerKjerne.set(kjerne, o.konfidens);
|
|
3636
|
+
}
|
|
3637
|
+
if (verstePerKjerne.size === 0) return tom;
|
|
3638
|
+
const kjerner = [...verstePerKjerne.keys()].sort((a, b) => b.length - a.length || (a < b ? -1 : 1));
|
|
3639
|
+
const eksisterandeSurrogat = [...new Set(Object.keys(review.map))].filter((s) => s.length > 0);
|
|
3640
|
+
const start = Number.isInteger(nummerFra) && nummerFra > 0 ? nummerFra : 0;
|
|
3641
|
+
let body = review.body;
|
|
3642
|
+
const nyeSpans = [];
|
|
3643
|
+
const nyMap = {};
|
|
3644
|
+
const tokeniserte = [];
|
|
3645
|
+
const alleredeDekte = [];
|
|
3646
|
+
let n = 0;
|
|
3647
|
+
for (const kjerne of kjerner) {
|
|
3648
|
+
if (typeof verktoy.indexOfWholeToken === "function" && (eksisterandeSurrogat.some((s) => verktoy.indexOfWholeToken(s, kjerne, 0) >= 0) || Object.keys(nyMap).some((s) => verktoy.indexOfWholeToken(s, kjerne, 0) >= 0))) {
|
|
3649
|
+
alleredeDekte.push(kjerne);
|
|
3650
|
+
continue;
|
|
3651
|
+
}
|
|
3652
|
+
let merkeId = start + n + 1;
|
|
3653
|
+
let merke = `${OCR_ULESE_SURROGAT_PREFIKS}${merkeId}]`;
|
|
3654
|
+
while (body.includes(merke) || Object.prototype.hasOwnProperty.call(review.map, merke) || Object.prototype.hasOwnProperty.call(nyMap, merke)) {
|
|
3655
|
+
merkeId += 1;
|
|
3656
|
+
merke = `${OCR_ULESE_SURROGAT_PREFIKS}${merkeId}]`;
|
|
3657
|
+
}
|
|
3658
|
+
const etter = body.split(kjerne).join(merke);
|
|
3659
|
+
if (etter === body) {
|
|
3660
|
+
alleredeDekte.push(kjerne);
|
|
3661
|
+
continue;
|
|
3662
|
+
}
|
|
3663
|
+
body = etter;
|
|
3664
|
+
n += 1;
|
|
3665
|
+
nyMap[merke] = kjerne;
|
|
3666
|
+
tokeniserte.push(kjerne);
|
|
3667
|
+
if (typeof review.originalText === "string") {
|
|
3668
|
+
const kjelde = review.originalText;
|
|
3669
|
+
for (let at = kjelde.indexOf(kjerne, 0); at >= 0; ) {
|
|
3670
|
+
const slutt = at + kjerne.length;
|
|
3671
|
+
const kolliderer = (review.spans ?? []).some(
|
|
3672
|
+
(s) => typeof s?.start === "number" && typeof s?.end === "number" && s.start < slutt && at < s.end
|
|
3673
|
+
);
|
|
3674
|
+
if (!kolliderer) {
|
|
3675
|
+
nyeSpans.push({ start: at, end: slutt, surrogate: merke });
|
|
3676
|
+
}
|
|
3677
|
+
at = kjelde.indexOf(kjerne, slutt);
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
if (tokeniserte.length === 0) return { review, tokeniserte: [], alleredeDekte };
|
|
3682
|
+
const brukteSpanIdar = new Set((review.spans ?? []).map((s) => s?.id).filter((id) => typeof id === "string"));
|
|
3683
|
+
let nesteSpanId = 0;
|
|
3684
|
+
const nyeIdar = nyeSpans.map(() => {
|
|
3685
|
+
while (brukteSpanIdar.has(`ocr-ulese-${nesteSpanId}`)) nesteSpanId += 1;
|
|
3686
|
+
const id = `ocr-ulese-${nesteSpanId}`;
|
|
3687
|
+
brukteSpanIdar.add(id);
|
|
3688
|
+
nesteSpanId += 1;
|
|
3689
|
+
return id;
|
|
3690
|
+
});
|
|
3691
|
+
const spans = [
|
|
3692
|
+
...review.spans ?? [],
|
|
3693
|
+
...nyeSpans.map((s, i) => ({
|
|
3694
|
+
id: nyeIdar[i],
|
|
3695
|
+
start: s.start,
|
|
3696
|
+
end: s.end,
|
|
3697
|
+
original: nyMap[s.surrogate],
|
|
3698
|
+
surrogate: s.surrogate,
|
|
3699
|
+
type: OCR_ULESE_SPAN_TYPE,
|
|
3700
|
+
source: "structured",
|
|
3701
|
+
secrets: false,
|
|
3702
|
+
ulestKonfidens: verstePerKjerne.get(nyMap[s.surrogate])
|
|
3703
|
+
}))
|
|
3704
|
+
];
|
|
3705
|
+
return {
|
|
3706
|
+
review: { ...review, body, map: { ...review.map, ...nyMap }, spans },
|
|
3707
|
+
tokeniserte,
|
|
3708
|
+
alleredeDekte
|
|
3709
|
+
};
|
|
3710
|
+
}
|
|
3711
|
+
|
|
3712
|
+
// src/device/restore-map.ts
|
|
3713
|
+
function restoreMapOnce(text, mappings) {
|
|
3714
|
+
const keys = Object.keys(mappings).filter(Boolean).sort((a, b) => b.length - a.length);
|
|
3715
|
+
if (!keys.length) return text;
|
|
3716
|
+
const escaped = keys.map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
3717
|
+
return text.replace(new RegExp(escaped.join("|"), "g"), (key) => mappings[key]);
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
// src/device/review-entity-count.ts
|
|
3721
|
+
function countDistinctReviewEntities(spans, lockedCardValues = []) {
|
|
3722
|
+
const surrogates = new Set(spans.map((span) => span.surrogate).filter((value) => Boolean(value)));
|
|
3723
|
+
return (/* @__PURE__ */ new Set([
|
|
3724
|
+
...spans.map((span) => span.original),
|
|
3725
|
+
...lockedCardValues.filter((value) => !surrogates.has(value))
|
|
3726
|
+
])).size;
|
|
3727
|
+
}
|
|
3728
|
+
|
|
3729
|
+
// src/device/sdk-restore.ts
|
|
3730
|
+
function collectUserTypedLiteralMarkers(text) {
|
|
3731
|
+
return new Set([...text.matchAll(/<<CLOAK:[A-Z0-9_]+:[^>]*>>|\[CLK-[A-Z0-9_]+(?:-[^\]]*)?\]/g)].map(([marker]) => marker));
|
|
3732
|
+
}
|
|
3733
|
+
var objectHasOwn = Object.hasOwn;
|
|
3734
|
+
function detokeniseReply(text, source, map, detokenise, options) {
|
|
3735
|
+
const userLiterals = options?.userTypedLiteralMarkers;
|
|
3736
|
+
const mapMayRestore = (marker) => objectHasOwn(map, marker) && !(userLiterals?.has(marker) ?? false);
|
|
3737
|
+
const protectedTokens = [];
|
|
3738
|
+
const protectedText = text.replace(/<<CLOAK:[A-Z0-9_]+:[^>]*>>|\[CLK-[A-Z0-9_]+(?:-[^\]]*)?\]/g, (marker) => {
|
|
3739
|
+
if (options?.rejectMappedMarkersAbsentFromSource && objectHasOwn(map, marker) && !source.includes(marker)) {
|
|
3740
|
+
throw new Error("references data no longer in your local map");
|
|
3741
|
+
}
|
|
3742
|
+
if (mapMayRestore(marker) || !source.includes(marker)) return marker;
|
|
3743
|
+
let placeholder;
|
|
3744
|
+
let placeholderIndex = protectedTokens.length;
|
|
3745
|
+
do {
|
|
3746
|
+
placeholder = `\u{F0000}CLOAK_LITERAL_${placeholderIndex++}\u{F0001}`;
|
|
3747
|
+
} while (protectedTokens.some(({ placeholder: existing }) => existing === placeholder) || text.includes(placeholder) || source.includes(placeholder) || Object.entries(map).some(([key, value]) => key.includes(placeholder) || value.includes(placeholder)));
|
|
3748
|
+
protectedTokens.push({ marker, placeholder });
|
|
3749
|
+
return placeholder;
|
|
3750
|
+
});
|
|
3751
|
+
let restored = detokenise(protectedText, map);
|
|
3752
|
+
for (const { marker, placeholder } of protectedTokens) {
|
|
3753
|
+
restored = restored.split(placeholder).join(marker);
|
|
3754
|
+
}
|
|
3755
|
+
return restored;
|
|
3756
|
+
}
|
|
3757
|
+
|
|
3758
|
+
// src/device/tessdata-pins.ts
|
|
3759
|
+
var TESSDATA_PACKAGE_VERSION = "1.0.0";
|
|
3760
|
+
var TESSDATA_VARIANT = "4.0.0_best_int";
|
|
3761
|
+
var TESSDATA_MAX_BYTES = 6 * 1024 * 1024;
|
|
3762
|
+
var TESSDATA_SHA256 = {
|
|
3763
|
+
afr: "a2a9ec1631e4d1a80f89518bd60c680464d3b87afa1483178859c1af19fdc9df",
|
|
3764
|
+
amh: "f1644849fd6afb587f7b2fea19b02a5c0a2a2f138cb04ff7cf0272ce66e28b80",
|
|
3765
|
+
ara: "f4746c44b02342dd5b3d4f0198000f47d7c49f1a229e63e0f436c0592dcd9639",
|
|
3766
|
+
asm: "d92c8b7cca44d3e19cf8aaac098eca74acb044a9d68ec614581afeb17c17aa20",
|
|
3767
|
+
aze: "2652f2c25d74582f4dce0dec6fe6f9c4f0ce445c931642cc69db707af04de8a3",
|
|
3768
|
+
aze_cyrl: "af2b210c3bcc12f3dd0d9ddf88ceb247717d4324467301433d5a4ae20beb805d",
|
|
3769
|
+
bel: "642fd20eb04ae62b217800cb39d09bee030554ccee37751cc4e4edaaca51cac2",
|
|
3770
|
+
ben: "a7c1fd170b796d6b8d01b401d4bfcc54409f47b313a200e9e3756ce20d742725",
|
|
3771
|
+
bod: "e43a8e96ff77d90c25bf401b5282bde758d9d1475d7017c8c6f7bfa4039adb1c",
|
|
3772
|
+
bos: "3304de098dbdf006ebb365d4f5187686e8eb7e773899ac1d1d2d65a60462ec7c",
|
|
3773
|
+
bre: "547c86a19b8e9b1eb2aeaf3b21c57160ee467f65f4eba1c066b687f7c8b6a7ff",
|
|
3774
|
+
bul: "a38fdba9367316dad1d595427a975756e8c31367fc94a6530d012827833db8d7",
|
|
3775
|
+
cat: "1003ea7490d8c88b9308ed5dead936910a662fc9a4222cd536b92a17178e41eb",
|
|
3776
|
+
ceb: "331aeeb921acc5d2e6b14f099c59bc1d7fe7fb3355f34ac0c730606319c5cca3",
|
|
3777
|
+
ces: "1ea33a8b6f9a9c18a6aae44a71eda06bbfdc206fe53cf1fc8121fb74def99166",
|
|
3778
|
+
chi_sim: "b8a23f10c7de500891eb458a8adc9cc58ab7f242f08b7d149f5e9aea4ad5db7c",
|
|
3779
|
+
chi_sim_vert: "35b2f01aae6642adef8270e50f54583ccef9efcdf21a74525b6f0594bfe84e24",
|
|
3780
|
+
chi_tra: "11fe2610dab05d8a880d02f193ce70203f4c4bbe061b987d5529a2c038a22743",
|
|
3781
|
+
chi_tra_vert: "19044982fdcfdc489a1ad30fca1b0a73d5acf782c9a0146e72d76fdbe7ad3442",
|
|
3782
|
+
chr: "bdaabd80b88c141382b51e50463825d50afe02b5cd727412cf2a62e9af3fc36f",
|
|
3783
|
+
cos: "29a7c7261444d58519db48f9bbdd77a5a4b543b573007f9f24acc0ef22f5a38c",
|
|
3784
|
+
cym: "9aa1e5a953c3241b74f9894252de51637c5d1ba1a11c1cf772f6db7cff0ca935",
|
|
3785
|
+
dan: "6af1a07c22894b728ebc75f0fd0c8519eca002cfab6da903eb4d62e24f163abc",
|
|
3786
|
+
deu: "306c4280d0cbed46fbff727486bd43b92730181bae80f56941a091f363bdf28b",
|
|
3787
|
+
div: "c355714790025a1be90fbe1ad5005f0b7d234134cfb683b3fd738f000c3eca1e",
|
|
3788
|
+
dzo: "09fa9e9456821634a9fce435e31fd9bb9b102449d12b5b938c8ab12b855f415b",
|
|
3789
|
+
ell: "e8a293abb398ec479176c1575aef24e2bacb0611c713f3fa996f97f0cd996fb3",
|
|
3790
|
+
eng: "45b4cb346724ac1774f1c36f42f182b887bcdb28ebe63e6fff90ac41f3fcff91",
|
|
3791
|
+
enm: "fe43ca0328ded47ffb312f14a1659729a7947e919265571670137beb49f2f05b",
|
|
3792
|
+
epo: "34e89c4f626c87fda7fe1769b748775b321869b2cbcb17944942a503b398f15c",
|
|
3793
|
+
est: "27a3ddb4ec40348c36277463285221c8638de4ac126e7da88af36837d2db9a4a",
|
|
3794
|
+
eus: "e5a4ba32654272462f3a87965ae9812a98b787f4d437dd63914b85b1c2bf8ea7",
|
|
3795
|
+
fao: "074c9a917520412ec00a34593805c55f5e75bab5b1a8ea519e0cb360ae11079f",
|
|
3796
|
+
fas: "b5847360e25f646c55449f1fe93eee57d53e406a265ead2374e7320bf0b82025",
|
|
3797
|
+
fil: "73e2af0cad8544a533581f6a036ca312ca3c45bc9d51451b19979ae4313da003",
|
|
3798
|
+
fin: "138c59f6a0bef68fd98d8baf565477f5cdb5198bfc4a68e558efd3b6a57acadd",
|
|
3799
|
+
fra: "d611139672b3752c7097e671e4a1d9209dfd37f2aeb081ef6487fba3351e9255",
|
|
3800
|
+
frk: "22186f9eae55cdc13846ea4d586f24f9fe64765c5400c41c2c46e55a8bb735be",
|
|
3801
|
+
frm: "8eedc2ae74b6b1af65f8e32b4300a86e69fc8c5cb601eb2348c79601998b3fcd",
|
|
3802
|
+
fry: "6f7780fb411199451ed95e8a0e4bf77c879402e55f3ff8ac6607d7241cc22a01",
|
|
3803
|
+
gla: "3820983a484c7f079cfe5b6454d5f4aec458d519d920469a247f55e8cd0a6245",
|
|
3804
|
+
gle: "89a1eca11aff0e62280bdaa6c0344eb1de765b67058a7cbace95bf5b8b4b7be4",
|
|
3805
|
+
glg: "950fe77dd9218d2bf642eeb423ab78fc2b3c7dab47c54cac6ccae2d1f81817f8",
|
|
3806
|
+
grc: "5900b2bf126da1d98f3d5aabeea871f3e7386323ee6292be069bc7ed2b6a15cf",
|
|
3807
|
+
guj: "f23bec3f02feca371fb37fe1733fca94881af376dc06ede6168ca54068f20efc",
|
|
3808
|
+
hat: "e8e31b94b546c840739d69e9066633cd336c939ad5ffdaf81acac5e40ff6a2e2",
|
|
3809
|
+
heb: "9c70b524200dae77fb25e3567566eee600ccbcae9aeb89722990ccae0e84e805",
|
|
3810
|
+
hin: "f3b6a0d320df38d886178cdd727b90dbf9df3db053adb32bd9cf73f0463cda07",
|
|
3811
|
+
hrv: "3256cd52165cb82f5f136264daf68ee54320ee68fad6a4a9ddfd1bc1861f806a",
|
|
3812
|
+
hun: "99feb1ac618ddd39942d646f1df792e5bd4504df45e1ef68e47df51db476a2ed",
|
|
3813
|
+
hye: "ff791a6c85736354350a487b40fa58337372e03291abf97863916aea35d603e8",
|
|
3814
|
+
iku: "46c5076e11b759dbda26f561716531675cb12bb12a0182551829db87809d8081",
|
|
3815
|
+
ind: "a8896d2f584a5baae73d658b86b765acc7b15b7ba05e014f62b1a2a23b699a91",
|
|
3816
|
+
isl: "002a0b366f0e96c06a65896033b0aabb313c6cc4c6d9c9cca0969dee11ff1f56",
|
|
3817
|
+
ita: "f702fcfad297ce028ede3626d1467b67939f23ff23595f9badd54681cf25a4d3",
|
|
3818
|
+
ita_old: "b7416567d680d1741128f3494ae3823fbc60efb1ab139b7494cdacffe97a6264",
|
|
3819
|
+
jav: "2a4f959dd02bc2013f958297c1c897b259f8c3b104659265d457c849b268a2bc",
|
|
3820
|
+
jpn: "2b63ebfbf1484de4a08ce53b29ef98a1c17658a93cbd38acb665d7d316d0be88",
|
|
3821
|
+
jpn_vert: "3a4f4df8df8f50f3389fe0da10502effced38faef763d8e540142bdc9b770308",
|
|
3822
|
+
kan: "3ce2f873f3a8371e82a85c204fcfae1635e01b5796be26df0610e6916cb54cf0",
|
|
3823
|
+
kat: "74505e238b208fc30471654b9f694bda08e521cdc7c8a5e0846d1340ed585899",
|
|
3824
|
+
kat_old: "5bda0d0036fed781b0252a24b5ebbd137e9343e1671306c3946a762eaa1b2489",
|
|
3825
|
+
kaz: "3c93708c240722194d473931c097e09f02510fe8b7593fa0c33ceb90ee87095a",
|
|
3826
|
+
khm: "f3aab6301b2570ee7cd6cd051094e1c4f075a0a7eeeb4ff111e7e67a9bc012c9",
|
|
3827
|
+
kir: "31c9579841744bc53dcf59392a63eb77e3ea648f67ef53106720c39d23281256",
|
|
3828
|
+
kmr: "6811f278103ceaedc4d860e1db5f74bbdc7ff0d5595fe7331a9bd9b4a0923b8c",
|
|
3829
|
+
kor: "78c21276ab14c9bb734d83be1055d9fe5469a4e7e977c51ad385be5737e61126",
|
|
3830
|
+
kor_vert: "e299cca7827988dad481beb5cd4601d02b4fff13efa03312b80224f372c232cf",
|
|
3831
|
+
lao: "660306d4a42941426256c723a7d6d3b65f81e6c428e5f83d5f25180a486d0011",
|
|
3832
|
+
lat: "22101c28f8f9b3e0b08a526a3e7895bb319d1e876684a150901c2e8580060e31",
|
|
3833
|
+
lav: "08bc2d5fd9c66a1893f2c4e131e3410321f4079e6d41810898706be49ae02a9c",
|
|
3834
|
+
lit: "b8dd9f13ee6570cd791b6e074176823f00fcf2c8102c0d37b665e7723933cd91",
|
|
3835
|
+
ltz: "2b33cc540a20d5ace6c73b6a081a220333f0dc3b0b903d30f6aa65df93ab0114",
|
|
3836
|
+
mal: "a4a5b24474889dbbe9943bb3cb7b24819c1cd594f2f371340bba83c30fd81bf0",
|
|
3837
|
+
mar: "e4c20d649ab646e1d46da35f45d357eea25b7f28af4b0a7af3e205abaf6be788",
|
|
3838
|
+
mkd: "043ca096871a4b58bb1b3bca34c6793187e060a12f3d1384ab4e6d8d77e8b802",
|
|
3839
|
+
mlt: "756b8c1962b8d68dd5a3868b6106f49004d4f66b877c9c018c88a9a1d9ff07ac",
|
|
3840
|
+
mon: "75abf4620220c6a9f84bbc25e548f1c3408ce2c3abd5904dfc1cc00f9d5ce3b2",
|
|
3841
|
+
mri: "e31d5b0810182f6181f00e9ed5121f858e0f1c40f972c59b0c6b6fbbd1b29a08",
|
|
3842
|
+
msa: "35ae490b99462d04cf4e2a7985d98f0ba5e10ca62adb13aeda070c6f1783f097",
|
|
3843
|
+
mya: "a6ac329fbc61a902c05bb10ec7a863e9983e3da65dc558fe1db909b61af67ce4",
|
|
3844
|
+
nep: "cda17f5f7c18a81167be44ce4f545d0b244f8b00912d55f6568ac08d0e0f3b0e",
|
|
3845
|
+
nld: "a2d904b6ddc4feb0d31ecfcd7361a554102e7aa2e278c54f4fc029e0d0815571",
|
|
3846
|
+
nor: "6c5d91a5b684da387bfcf16b38bae8d94771812dc9ef706b413c728ca1d37c93",
|
|
3847
|
+
oci: "1221f848173d4626711a2a16179ce427e06488795001e8dde6a2c11e40b46eca",
|
|
3848
|
+
ori: "b42f60e0460daf814952ed1b239723f9a4c4c694a29ab016d772a02c68ef5ddc",
|
|
3849
|
+
pan: "10624ae040eb967316fcb1a1843421786a48542b22ef2fdd50afc00de58d27b5",
|
|
3850
|
+
pol: "a20fdec4ff99d8f8e84c708da3e42a4e935c26863055a0ed88aef5c66a59b91b",
|
|
3851
|
+
por: "dacebc1386ddaaf8389f81094236cca0d690897cde693d48cbdaa881c86e2b4c",
|
|
3852
|
+
pus: "689b369c109107c4df1cd133446b9de0b10b79706a070d4c35dc885a52764105",
|
|
3853
|
+
que: "bb275fda63b001b2f23e255e7d124af31f34f145a5e55773bf349923cc82ae02",
|
|
3854
|
+
ron: "3c2f550b6369f43254adf637cfe1088c7b6faff3d0382555219315112a24582a",
|
|
3855
|
+
rus: "f51f5edc992249ff9b70a227b22f242dfa47b2b1bbc7ae0ea74908640c101f6a",
|
|
3856
|
+
san: "f1ed7e622f015c9caba5c2843a06deee9343955e7d57a38d96aa79b43e154916",
|
|
3857
|
+
sin: "02d34b1f6565d26991fa25605c0bbddd3e39d9eefe471fce4b8a27fe9363ec94",
|
|
3858
|
+
slk: "839350509c06e498448e35ce9faf13e24b28150b2d5cc39b900a751c5009127f",
|
|
3859
|
+
slv: "23550808c5ae045a2c6cabcb8a03a52239ffeaf45571d1120135ddc632d021f1",
|
|
3860
|
+
snd: "7a37e25a97dfab796d23d9c056d35eba94d642f605b12cd10da2800ea8d5bcfd",
|
|
3861
|
+
spa: "40be52f97b5d4eb7460073dc1f94cd546b27150333c0bf854ed7e7132db6bceb",
|
|
3862
|
+
spa_old: "9e4d121967b532a029e65bf628ffd57844ccdc0e09bbfcefd9cebd0b4409e9d4",
|
|
3863
|
+
sqi: "a84023c64e1c0910f8fddc25d13f2dbe1157ce2f478abb48adc8013de9b108f1",
|
|
3864
|
+
srp: "4a864eba46de4a7c264fc3c34b63db6889218eb51eefc5d38c5eaac548d58c96",
|
|
3865
|
+
srp_latn: "db283bbbb4802a2f9c271bf00c15eec71c8a8cf045297f5b172a8dfcd3fbedd9",
|
|
3866
|
+
sun: "04038b68475bf03e2a98c339485b4d5ab62e08967b15d281ab5a787b31e3a330",
|
|
3867
|
+
swa: "74c7bd51f173a3f174fbc8aaf8738819aa36000566857929ba6679ad5a2cf71f",
|
|
3868
|
+
swe: "b60d9fea7e570d11d6fdf26c8d0ef1d63b49222313773ce66777ed08fa20dc5a",
|
|
3869
|
+
syr: "2e739deb0522246785349f8ecf0bfe0b8d2b8f743c1c67d4b631b12fc8179eb4",
|
|
3870
|
+
tam: "2c4b255ede87931cb56c20a5b2b8e2cda4913e34fb3e4957f9b9e04ea069ff21",
|
|
3871
|
+
tat: "028a9c7efc932b833a7846e47332c62c8ef1a5bb7b685a2ecdfb03b0a7debb81",
|
|
3872
|
+
tel: "8b478895dfc1f5d6baee6f8e6cf84a873793dd8948124315437ff2dc38d49fe4",
|
|
3873
|
+
tgk: "660f8476c5635c93f83955f7bdce7c2c45bc685463a9c139b292c7f5853de0e9",
|
|
3874
|
+
tha: "4550a5505184d1b79cf10416d5b19e643001d95411d5e717954dd26feef3ae74",
|
|
3875
|
+
tir: "647f1d1e4f74262a253cce76ba835bb3be9d74b8268c9823cc794832b5ec8c1a",
|
|
3876
|
+
ton: "b812a327cccd7bf60ec9e10ddbae38c0c464ff593f7529d0091a8f1751762bdb",
|
|
3877
|
+
tur: "384ba0dc28040451b7818d7d60e0a88df0d3003fa5a01d713a468779bc3d8c04",
|
|
3878
|
+
uig: "3be33a65775f3dbfd72c0feb0b66a3f2198bb14378537ab770f583eb1f9fbad7",
|
|
3879
|
+
ukr: "ea2789a0ad99ff84bfd252a7410a1e8661a7bc5acaa41573d23b54b71446aa4c",
|
|
3880
|
+
urd: "9e1860440339543c935fca7cee2ce5ac742b1d1249c4ba5982385ce19d23096f",
|
|
3881
|
+
uzb: "16d7f4a0af8722227ea447c99a2159f1a186af137c392ff8caeb69f2d4ceee20",
|
|
3882
|
+
uzb_cyrl: "800d22c59b525b715015e1bf3aba49e98a0d6309305e245490f67698685f8842",
|
|
3883
|
+
vie: "2284f610f262a1b19ec8df9f196b9ff6ce38ddb4a66329e998941df4b8961c8d",
|
|
3884
|
+
yid: "90b3c603e53727a996a11bb6c9f9281cf893ed9275ceed4e0b27cbbc7c530de8",
|
|
3885
|
+
yor: "fde674f3f9592f192eae548cbef0958059780da82658524bbdc62c1ed892af58"
|
|
3886
|
+
};
|
|
3887
|
+
var TESSDATA_SIZE = {
|
|
3888
|
+
afr: 1834273,
|
|
3889
|
+
amh: 2366946,
|
|
3890
|
+
ara: 1661906,
|
|
3891
|
+
asm: 1469955,
|
|
3892
|
+
aze: 1664212,
|
|
3893
|
+
aze_cyrl: 996769,
|
|
3894
|
+
bel: 2106984,
|
|
3895
|
+
ben: 1373429,
|
|
3896
|
+
bod: 1269959,
|
|
3897
|
+
bos: 1155304,
|
|
3898
|
+
bre: 3384720,
|
|
3899
|
+
bul: 1411343,
|
|
3900
|
+
cat: 639438,
|
|
3901
|
+
ceb: 487818,
|
|
3902
|
+
ces: 2225029,
|
|
3903
|
+
chi_sim: 1718768,
|
|
3904
|
+
chi_sim_vert: 1706654,
|
|
3905
|
+
chi_tra: 1656239,
|
|
3906
|
+
chi_tra_vert: 1645318,
|
|
3907
|
+
chr: 288203,
|
|
3908
|
+
cos: 1380581,
|
|
3909
|
+
cym: 1363985,
|
|
3910
|
+
dan: 1845116,
|
|
3911
|
+
deu: 1333102,
|
|
3912
|
+
div: 888357,
|
|
3913
|
+
dzo: 384320,
|
|
3914
|
+
ell: 1324749,
|
|
3915
|
+
eng: 2952873,
|
|
3916
|
+
enm: 1991361,
|
|
3917
|
+
epo: 2144471,
|
|
3918
|
+
est: 3101722,
|
|
3919
|
+
eus: 2240649,
|
|
3920
|
+
fao: 1927747,
|
|
3921
|
+
fas: 424507,
|
|
3922
|
+
fil: 1506936,
|
|
3923
|
+
fin: 3795323,
|
|
3924
|
+
fra: 707406,
|
|
3925
|
+
frk: 3362304,
|
|
3926
|
+
frm: 1000934,
|
|
3927
|
+
fry: 1258612,
|
|
3928
|
+
gla: 1741804,
|
|
3929
|
+
gle: 678843,
|
|
3930
|
+
glg: 1743024,
|
|
3931
|
+
grc: 1091626,
|
|
3932
|
+
guj: 1219824,
|
|
3933
|
+
hat: 1515839,
|
|
3934
|
+
heb: 580576,
|
|
3935
|
+
hin: 1389692,
|
|
3936
|
+
hrv: 2290948,
|
|
3937
|
+
hun: 2854466,
|
|
3938
|
+
hye: 1620716,
|
|
3939
|
+
iku: 1463630,
|
|
3940
|
+
ind: 1194182,
|
|
3941
|
+
isl: 1696807,
|
|
3942
|
+
ita: 1660998,
|
|
3943
|
+
ita_old: 1784533,
|
|
3944
|
+
jav: 1645119,
|
|
3945
|
+
jpn: 2030256,
|
|
3946
|
+
jpn_vert: 2022755,
|
|
3947
|
+
kan: 1914250,
|
|
3948
|
+
kat: 1088063,
|
|
3949
|
+
kat_old: 372117,
|
|
3950
|
+
kaz: 2137822,
|
|
3951
|
+
khm: 1064461,
|
|
3952
|
+
kir: 4448704,
|
|
3953
|
+
kmr: 1910803,
|
|
3954
|
+
kor: 1572336,
|
|
3955
|
+
kor_vert: 620875,
|
|
3956
|
+
lao: 3699720,
|
|
3957
|
+
lat: 1739234,
|
|
3958
|
+
lav: 1318441,
|
|
3959
|
+
lit: 1901451,
|
|
3960
|
+
ltz: 1816965,
|
|
3961
|
+
mal: 2794667,
|
|
3962
|
+
mar: 1966154,
|
|
3963
|
+
mkd: 719182,
|
|
3964
|
+
mlt: 1164274,
|
|
3965
|
+
mon: 1318327,
|
|
3966
|
+
mri: 545094,
|
|
3967
|
+
msa: 1177136,
|
|
3968
|
+
mya: 2691297,
|
|
3969
|
+
nep: 1594252,
|
|
3970
|
+
nld: 3005696,
|
|
3971
|
+
nor: 2490241,
|
|
3972
|
+
oci: 3192816,
|
|
3973
|
+
ori: 1058704,
|
|
3974
|
+
pan: 1396216,
|
|
3975
|
+
pol: 2642356,
|
|
3976
|
+
por: 1392239,
|
|
3977
|
+
pus: 1420364,
|
|
3978
|
+
que: 2581676,
|
|
3979
|
+
ron: 1692160,
|
|
3980
|
+
rus: 2679598,
|
|
3981
|
+
san: 5707023,
|
|
3982
|
+
sin: 1138317,
|
|
3983
|
+
slk: 2377899,
|
|
3984
|
+
slv: 1346857,
|
|
3985
|
+
snd: 1401126,
|
|
3986
|
+
spa: 2100190,
|
|
3987
|
+
spa_old: 1651913,
|
|
3988
|
+
sqi: 962962,
|
|
3989
|
+
srp: 1537929,
|
|
3990
|
+
srp_latn: 1774421,
|
|
3991
|
+
sun: 762181,
|
|
3992
|
+
swa: 1094930,
|
|
3993
|
+
swe: 2503095,
|
|
3994
|
+
syr: 1607141,
|
|
3995
|
+
tam: 1446167,
|
|
3996
|
+
tat: 900603,
|
|
3997
|
+
tel: 1735518,
|
|
3998
|
+
tgk: 1164174,
|
|
3999
|
+
tha: 896631,
|
|
4000
|
+
tir: 295477,
|
|
4001
|
+
ton: 586622,
|
|
4002
|
+
tur: 2141291,
|
|
4003
|
+
uig: 1850426,
|
|
4004
|
+
ukr: 2114206,
|
|
4005
|
+
urd: 1023740,
|
|
4006
|
+
uzb: 3116151,
|
|
4007
|
+
uzb_cyrl: 832890,
|
|
4008
|
+
vie: 1423003,
|
|
4009
|
+
yid: 445286,
|
|
4010
|
+
yor: 591178
|
|
4011
|
+
};
|
|
4012
|
+
|
|
4013
|
+
// src/device/unicodeCaseFold.ts
|
|
4014
|
+
var FULL_FOLD_OVERRIDES = {
|
|
4015
|
+
223: "ss",
|
|
4016
|
+
837: "\u03B9",
|
|
4017
|
+
962: "\u03C3",
|
|
4018
|
+
5024: "\u13A0",
|
|
4019
|
+
5025: "\u13A1",
|
|
4020
|
+
5026: "\u13A2",
|
|
4021
|
+
5027: "\u13A3",
|
|
4022
|
+
5028: "\u13A4",
|
|
4023
|
+
5029: "\u13A5",
|
|
4024
|
+
5030: "\u13A6",
|
|
4025
|
+
5031: "\u13A7",
|
|
4026
|
+
5032: "\u13A8",
|
|
4027
|
+
5033: "\u13A9",
|
|
4028
|
+
5034: "\u13AA",
|
|
4029
|
+
5035: "\u13AB",
|
|
4030
|
+
5036: "\u13AC",
|
|
4031
|
+
5037: "\u13AD",
|
|
4032
|
+
5038: "\u13AE",
|
|
4033
|
+
5039: "\u13AF",
|
|
4034
|
+
5040: "\u13B0",
|
|
4035
|
+
5041: "\u13B1",
|
|
4036
|
+
5042: "\u13B2",
|
|
4037
|
+
5043: "\u13B3",
|
|
4038
|
+
5044: "\u13B4",
|
|
4039
|
+
5045: "\u13B5",
|
|
4040
|
+
5046: "\u13B6",
|
|
4041
|
+
5047: "\u13B7",
|
|
4042
|
+
5048: "\u13B8",
|
|
4043
|
+
5049: "\u13B9",
|
|
4044
|
+
5050: "\u13BA",
|
|
4045
|
+
5051: "\u13BB",
|
|
4046
|
+
5052: "\u13BC",
|
|
4047
|
+
5053: "\u13BD",
|
|
4048
|
+
5054: "\u13BE",
|
|
4049
|
+
5055: "\u13BF",
|
|
4050
|
+
5056: "\u13C0",
|
|
4051
|
+
5057: "\u13C1",
|
|
4052
|
+
5058: "\u13C2",
|
|
4053
|
+
5059: "\u13C3",
|
|
4054
|
+
5060: "\u13C4",
|
|
4055
|
+
5061: "\u13C5",
|
|
4056
|
+
5062: "\u13C6",
|
|
4057
|
+
5063: "\u13C7",
|
|
4058
|
+
5064: "\u13C8",
|
|
4059
|
+
5065: "\u13C9",
|
|
4060
|
+
5066: "\u13CA",
|
|
4061
|
+
5067: "\u13CB",
|
|
4062
|
+
5068: "\u13CC",
|
|
4063
|
+
5069: "\u13CD",
|
|
4064
|
+
5070: "\u13CE",
|
|
4065
|
+
5071: "\u13CF",
|
|
4066
|
+
5072: "\u13D0",
|
|
4067
|
+
5073: "\u13D1",
|
|
4068
|
+
5074: "\u13D2",
|
|
4069
|
+
5075: "\u13D3",
|
|
4070
|
+
5076: "\u13D4",
|
|
4071
|
+
5077: "\u13D5",
|
|
4072
|
+
5078: "\u13D6",
|
|
4073
|
+
5079: "\u13D7",
|
|
4074
|
+
5080: "\u13D8",
|
|
4075
|
+
5081: "\u13D9",
|
|
4076
|
+
5082: "\u13DA",
|
|
4077
|
+
5083: "\u13DB",
|
|
4078
|
+
5084: "\u13DC",
|
|
4079
|
+
5085: "\u13DD",
|
|
4080
|
+
5086: "\u13DE",
|
|
4081
|
+
5087: "\u13DF",
|
|
4082
|
+
5088: "\u13E0",
|
|
4083
|
+
5089: "\u13E1",
|
|
4084
|
+
5090: "\u13E2",
|
|
4085
|
+
5091: "\u13E3",
|
|
4086
|
+
5092: "\u13E4",
|
|
4087
|
+
5093: "\u13E5",
|
|
4088
|
+
5094: "\u13E6",
|
|
4089
|
+
5095: "\u13E7",
|
|
4090
|
+
5096: "\u13E8",
|
|
4091
|
+
5097: "\u13E9",
|
|
4092
|
+
5098: "\u13EA",
|
|
4093
|
+
5099: "\u13EB",
|
|
4094
|
+
5100: "\u13EC",
|
|
4095
|
+
5101: "\u13ED",
|
|
4096
|
+
5102: "\u13EE",
|
|
4097
|
+
5103: "\u13EF",
|
|
4098
|
+
5104: "\u13F0",
|
|
4099
|
+
5105: "\u13F1",
|
|
4100
|
+
5106: "\u13F2",
|
|
4101
|
+
5107: "\u13F3",
|
|
4102
|
+
5108: "\u13F4",
|
|
4103
|
+
5109: "\u13F5",
|
|
4104
|
+
5112: "\u13F0",
|
|
4105
|
+
5113: "\u13F1",
|
|
4106
|
+
5114: "\u13F2",
|
|
4107
|
+
5115: "\u13F3",
|
|
4108
|
+
5116: "\u13F4",
|
|
4109
|
+
5117: "\u13F5",
|
|
4110
|
+
7296: "\u0432",
|
|
4111
|
+
7297: "\u0434",
|
|
4112
|
+
7298: "\u043E",
|
|
4113
|
+
7299: "\u0441",
|
|
4114
|
+
7300: "\u0442",
|
|
4115
|
+
7301: "\u0442",
|
|
4116
|
+
7302: "\u044A",
|
|
4117
|
+
7303: "\u0463",
|
|
4118
|
+
7304: "\uA64B",
|
|
4119
|
+
7838: "ss",
|
|
4120
|
+
8064: "\u1F00\u03B9",
|
|
4121
|
+
8065: "\u1F01\u03B9",
|
|
4122
|
+
8066: "\u1F02\u03B9",
|
|
4123
|
+
8067: "\u1F03\u03B9",
|
|
4124
|
+
8068: "\u1F04\u03B9",
|
|
4125
|
+
8069: "\u1F05\u03B9",
|
|
4126
|
+
8070: "\u1F06\u03B9",
|
|
4127
|
+
8071: "\u1F07\u03B9",
|
|
4128
|
+
8072: "\u1F00\u03B9",
|
|
4129
|
+
8073: "\u1F01\u03B9",
|
|
4130
|
+
8074: "\u1F02\u03B9",
|
|
4131
|
+
8075: "\u1F03\u03B9",
|
|
4132
|
+
8076: "\u1F04\u03B9",
|
|
4133
|
+
8077: "\u1F05\u03B9",
|
|
4134
|
+
8078: "\u1F06\u03B9",
|
|
4135
|
+
8079: "\u1F07\u03B9",
|
|
4136
|
+
8080: "\u1F20\u03B9",
|
|
4137
|
+
8081: "\u1F21\u03B9",
|
|
4138
|
+
8082: "\u1F22\u03B9",
|
|
4139
|
+
8083: "\u1F23\u03B9",
|
|
4140
|
+
8084: "\u1F24\u03B9",
|
|
4141
|
+
8085: "\u1F25\u03B9",
|
|
4142
|
+
8086: "\u1F26\u03B9",
|
|
4143
|
+
8087: "\u1F27\u03B9",
|
|
4144
|
+
8088: "\u1F20\u03B9",
|
|
4145
|
+
8089: "\u1F21\u03B9",
|
|
4146
|
+
8090: "\u1F22\u03B9",
|
|
4147
|
+
8091: "\u1F23\u03B9",
|
|
4148
|
+
8092: "\u1F24\u03B9",
|
|
4149
|
+
8093: "\u1F25\u03B9",
|
|
4150
|
+
8094: "\u1F26\u03B9",
|
|
4151
|
+
8095: "\u1F27\u03B9",
|
|
4152
|
+
8096: "\u1F60\u03B9",
|
|
4153
|
+
8097: "\u1F61\u03B9",
|
|
4154
|
+
8098: "\u1F62\u03B9",
|
|
4155
|
+
8099: "\u1F63\u03B9",
|
|
4156
|
+
8100: "\u1F64\u03B9",
|
|
4157
|
+
8101: "\u1F65\u03B9",
|
|
4158
|
+
8102: "\u1F66\u03B9",
|
|
4159
|
+
8103: "\u1F67\u03B9",
|
|
4160
|
+
8104: "\u1F60\u03B9",
|
|
4161
|
+
8105: "\u1F61\u03B9",
|
|
4162
|
+
8106: "\u1F62\u03B9",
|
|
4163
|
+
8107: "\u1F63\u03B9",
|
|
4164
|
+
8108: "\u1F64\u03B9",
|
|
4165
|
+
8109: "\u1F65\u03B9",
|
|
4166
|
+
8110: "\u1F66\u03B9",
|
|
4167
|
+
8111: "\u1F67\u03B9",
|
|
4168
|
+
8114: "\u1F70\u03B9",
|
|
4169
|
+
8115: "\u03B1\u03B9",
|
|
4170
|
+
8116: "\u03AC\u03B9",
|
|
4171
|
+
8119: "\u03B1\u0342\u03B9",
|
|
4172
|
+
8124: "\u03B1\u03B9",
|
|
4173
|
+
8130: "\u1F74\u03B9",
|
|
4174
|
+
8131: "\u03B7\u03B9",
|
|
4175
|
+
8132: "\u03AE\u03B9",
|
|
4176
|
+
8135: "\u03B7\u0342\u03B9",
|
|
4177
|
+
8140: "\u03B7\u03B9",
|
|
4178
|
+
8178: "\u1F7C\u03B9",
|
|
4179
|
+
8179: "\u03C9\u03B9",
|
|
4180
|
+
8180: "\u03CE\u03B9",
|
|
4181
|
+
8183: "\u03C9\u0342\u03B9",
|
|
4182
|
+
8188: "\u03C9\u03B9",
|
|
4183
|
+
43888: "\u13A0",
|
|
4184
|
+
43889: "\u13A1",
|
|
4185
|
+
43890: "\u13A2",
|
|
4186
|
+
43891: "\u13A3",
|
|
4187
|
+
43892: "\u13A4",
|
|
4188
|
+
43893: "\u13A5",
|
|
4189
|
+
43894: "\u13A6",
|
|
4190
|
+
43895: "\u13A7",
|
|
4191
|
+
43896: "\u13A8",
|
|
4192
|
+
43897: "\u13A9",
|
|
4193
|
+
43898: "\u13AA",
|
|
4194
|
+
43899: "\u13AB",
|
|
4195
|
+
43900: "\u13AC",
|
|
4196
|
+
43901: "\u13AD",
|
|
4197
|
+
43902: "\u13AE",
|
|
4198
|
+
43903: "\u13AF",
|
|
4199
|
+
43904: "\u13B0",
|
|
4200
|
+
43905: "\u13B1",
|
|
4201
|
+
43906: "\u13B2",
|
|
4202
|
+
43907: "\u13B3",
|
|
4203
|
+
43908: "\u13B4",
|
|
4204
|
+
43909: "\u13B5",
|
|
4205
|
+
43910: "\u13B6",
|
|
4206
|
+
43911: "\u13B7",
|
|
4207
|
+
43912: "\u13B8",
|
|
4208
|
+
43913: "\u13B9",
|
|
4209
|
+
43914: "\u13BA",
|
|
4210
|
+
43915: "\u13BB",
|
|
4211
|
+
43916: "\u13BC",
|
|
4212
|
+
43917: "\u13BD",
|
|
4213
|
+
43918: "\u13BE",
|
|
4214
|
+
43919: "\u13BF",
|
|
4215
|
+
43920: "\u13C0",
|
|
4216
|
+
43921: "\u13C1",
|
|
4217
|
+
43922: "\u13C2",
|
|
4218
|
+
43923: "\u13C3",
|
|
4219
|
+
43924: "\u13C4",
|
|
4220
|
+
43925: "\u13C5",
|
|
4221
|
+
43926: "\u13C6",
|
|
4222
|
+
43927: "\u13C7",
|
|
4223
|
+
43928: "\u13C8",
|
|
4224
|
+
43929: "\u13C9",
|
|
4225
|
+
43930: "\u13CA",
|
|
4226
|
+
43931: "\u13CB",
|
|
4227
|
+
43932: "\u13CC",
|
|
4228
|
+
43933: "\u13CD",
|
|
4229
|
+
43934: "\u13CE",
|
|
4230
|
+
43935: "\u13CF",
|
|
4231
|
+
43936: "\u13D0",
|
|
4232
|
+
43937: "\u13D1",
|
|
4233
|
+
43938: "\u13D2",
|
|
4234
|
+
43939: "\u13D3",
|
|
4235
|
+
43940: "\u13D4",
|
|
4236
|
+
43941: "\u13D5",
|
|
4237
|
+
43942: "\u13D6",
|
|
4238
|
+
43943: "\u13D7",
|
|
4239
|
+
43944: "\u13D8",
|
|
4240
|
+
43945: "\u13D9",
|
|
4241
|
+
43946: "\u13DA",
|
|
4242
|
+
43947: "\u13DB",
|
|
4243
|
+
43948: "\u13DC",
|
|
4244
|
+
43949: "\u13DD",
|
|
4245
|
+
43950: "\u13DE",
|
|
4246
|
+
43951: "\u13DF",
|
|
4247
|
+
43952: "\u13E0",
|
|
4248
|
+
43953: "\u13E1",
|
|
4249
|
+
43954: "\u13E2",
|
|
4250
|
+
43955: "\u13E3",
|
|
4251
|
+
43956: "\u13E4",
|
|
4252
|
+
43957: "\u13E5",
|
|
4253
|
+
43958: "\u13E6",
|
|
4254
|
+
43959: "\u13E7",
|
|
4255
|
+
43960: "\u13E8",
|
|
4256
|
+
43961: "\u13E9",
|
|
4257
|
+
43962: "\u13EA",
|
|
4258
|
+
43963: "\u13EB",
|
|
4259
|
+
43964: "\u13EC",
|
|
4260
|
+
43965: "\u13ED",
|
|
4261
|
+
43966: "\u13EE",
|
|
4262
|
+
43967: "\u13EF"
|
|
4263
|
+
};
|
|
4264
|
+
function unicodeNfkcCaseFold(text) {
|
|
4265
|
+
if (/^[\x00-\x7f]*$/.test(text)) return text.toLowerCase();
|
|
4266
|
+
const compatible = text.normalize("NFKC");
|
|
4267
|
+
let folded = "";
|
|
4268
|
+
for (const character of compatible) {
|
|
4269
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
4270
|
+
if (codePoint === 304 || codePoint === 305) {
|
|
4271
|
+
folded += "i";
|
|
4272
|
+
continue;
|
|
4273
|
+
}
|
|
4274
|
+
folded += FULL_FOLD_OVERRIDES[codePoint] ?? character.toLowerCase();
|
|
4275
|
+
}
|
|
4276
|
+
return folded.normalize("NFKC").replace(/\u03c2/g, "\u03C3");
|
|
4277
|
+
}
|
|
4278
|
+
var NO_LETTER_BOUNDARY_SCRIPT = /[\p{scx=Han}\p{scx=Hiragana}\p{scx=Katakana}\p{scx=Hangul}\p{scx=Thai}\p{scx=Lao}\p{scx=Khmer}\p{scx=Myanmar}\p{scx=Tibetan}]/u;
|
|
4279
|
+
var LETTER_OR_MARK = /[\p{L}\p{M}]/u;
|
|
4280
|
+
function projectCaseFold(text) {
|
|
4281
|
+
if (/^[\x00-\x7f]*$/.test(text)) return { text: unicodeNfkcCaseFold(text), identityOffsets: true };
|
|
4282
|
+
try {
|
|
4283
|
+
const Segmenter = Intl.Segmenter;
|
|
4284
|
+
if (!Segmenter) return null;
|
|
4285
|
+
const parts = new Segmenter(void 0, { granularity: "grapheme" }).segment(text);
|
|
4286
|
+
let folded = "";
|
|
4287
|
+
const starts = [];
|
|
4288
|
+
const ends = [];
|
|
4289
|
+
for (const part of parts) {
|
|
4290
|
+
const foldedPart = unicodeNfkcCaseFold(part.segment);
|
|
4291
|
+
folded += foldedPart;
|
|
4292
|
+
for (let i = 0; i < foldedPart.length; i += 1) {
|
|
4293
|
+
starts.push(part.index);
|
|
4294
|
+
ends.push(part.index + part.segment.length);
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
return { text: folded, starts: Uint32Array.from(starts), ends: Uint32Array.from(ends) };
|
|
4298
|
+
} catch {
|
|
4299
|
+
return null;
|
|
4300
|
+
}
|
|
4301
|
+
}
|
|
4302
|
+
function sourceRange(projection, start, end) {
|
|
4303
|
+
if (start < 0 || end <= start || end > projection.text.length) return null;
|
|
4304
|
+
if (projection.identityOffsets) return { start, end };
|
|
4305
|
+
const sourceStart = projection.starts?.[start];
|
|
4306
|
+
const sourceEnd = projection.ends?.[end - 1];
|
|
4307
|
+
if (sourceStart === void 0 || sourceEnd === void 0 || sourceEnd <= sourceStart) return null;
|
|
4308
|
+
return { start: sourceStart, end: sourceEnd };
|
|
4309
|
+
}
|
|
4310
|
+
function runClass(text, index) {
|
|
4311
|
+
if (index < 0 || index >= text.length) return 0;
|
|
4312
|
+
const point = text.codePointAt(index);
|
|
4313
|
+
if (point === void 0) return 0;
|
|
4314
|
+
const character = String.fromCodePoint(point);
|
|
4315
|
+
if (!LETTER_OR_MARK.test(character)) return 0;
|
|
4316
|
+
return NO_LETTER_BOUNDARY_SCRIPT.test(character) ? 2 : 1;
|
|
4317
|
+
}
|
|
4318
|
+
function previousCodePointStart(text, index) {
|
|
4319
|
+
if (index <= 0) return -1;
|
|
4320
|
+
const before = index - 1;
|
|
4321
|
+
const unit = text.charCodeAt(before);
|
|
4322
|
+
if (unit >= 56320 && unit <= 57343 && before > 0) {
|
|
4323
|
+
const lead = text.charCodeAt(before - 1);
|
|
4324
|
+
if (lead >= 55296 && lead <= 56319) return before - 1;
|
|
4325
|
+
}
|
|
4326
|
+
return before;
|
|
4327
|
+
}
|
|
4328
|
+
function isWholeTokenRange(text, start, end) {
|
|
4329
|
+
if (start < 0 || end > text.length || start >= end) return false;
|
|
4330
|
+
const left = runClass(text, start);
|
|
4331
|
+
if (left === 1) {
|
|
4332
|
+
const previous = previousCodePointStart(text, start);
|
|
4333
|
+
if (previous >= 0 && runClass(text, previous) === 1) return false;
|
|
4334
|
+
}
|
|
4335
|
+
const rightEdge = previousCodePointStart(text, end);
|
|
4336
|
+
if (rightEdge >= 0 && runClass(text, rightEdge) === 1 && runClass(text, end) === 1) return false;
|
|
4337
|
+
return true;
|
|
4338
|
+
}
|
|
4339
|
+
function replaceUnicodeCaseFoldOccurrences(text, original, surrogate) {
|
|
4340
|
+
if (typeof text !== "string" || typeof original !== "string" || typeof surrogate !== "string" || original.length === 0 || surrogate.length === 0) {
|
|
4341
|
+
return text;
|
|
4342
|
+
}
|
|
4343
|
+
try {
|
|
4344
|
+
const foldedOriginal = unicodeNfkcCaseFold(original);
|
|
4345
|
+
if (!foldedOriginal || foldedOriginal === unicodeNfkcCaseFold(surrogate)) return text;
|
|
4346
|
+
const projection = projectCaseFold(text);
|
|
4347
|
+
if (!projection) return text;
|
|
4348
|
+
const ranges = [];
|
|
4349
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4350
|
+
let from = 0;
|
|
4351
|
+
while (from <= projection.text.length - foldedOriginal.length) {
|
|
4352
|
+
const at = projection.text.indexOf(foldedOriginal, from);
|
|
4353
|
+
if (at < 0) break;
|
|
4354
|
+
const mapped = sourceRange(projection, at, at + foldedOriginal.length);
|
|
4355
|
+
if (mapped && isWholeTokenRange(text, mapped.start, mapped.end)) {
|
|
4356
|
+
const key = `${mapped.start}:${mapped.end}`;
|
|
4357
|
+
if (!seen.has(key)) {
|
|
4358
|
+
seen.add(key);
|
|
4359
|
+
ranges.push(mapped);
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
from = at + Math.max(1, foldedOriginal.length);
|
|
4363
|
+
}
|
|
4364
|
+
if (ranges.length === 0) return text;
|
|
4365
|
+
let out = text;
|
|
4366
|
+
for (const range of ranges.sort((a, b) => b.start - a.start || b.end - a.end)) {
|
|
4367
|
+
out = out.slice(0, range.start) + surrogate + out.slice(range.end);
|
|
4368
|
+
}
|
|
4369
|
+
return out;
|
|
4370
|
+
} catch {
|
|
4371
|
+
return text;
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
|
|
4375
|
+
// src/device/verified-tessdata.ts
|
|
4376
|
+
var TessdataIntegrityError = class extends Error {
|
|
4377
|
+
constructor(message) {
|
|
4378
|
+
super(message);
|
|
4379
|
+
this.name = "TessdataIntegrityError";
|
|
4380
|
+
}
|
|
4381
|
+
};
|
|
4382
|
+
async function fetchVerifiedTessdata(lang, url, fetcher = globalThis.fetch.bind(globalThis)) {
|
|
4383
|
+
const objectHasOwn2 = Object.hasOwn;
|
|
4384
|
+
if (!objectHasOwn2(TESSDATA_SHA256, lang) || !objectHasOwn2(TESSDATA_SIZE, lang)) {
|
|
4385
|
+
throw new TessdataIntegrityError("OCR language has no valid built-in pin.");
|
|
4386
|
+
}
|
|
4387
|
+
const expectedHash = TESSDATA_SHA256[lang];
|
|
4388
|
+
const expectedSize = TESSDATA_SIZE[lang];
|
|
4389
|
+
if (!expectedHash || !expectedSize || expectedSize > TESSDATA_MAX_BYTES) {
|
|
4390
|
+
throw new TessdataIntegrityError("OCR language has no valid built-in pin.");
|
|
4391
|
+
}
|
|
4392
|
+
const response = await fetcher(url, { method: "GET", cache: "no-store", credentials: "omit", redirect: "error" });
|
|
4393
|
+
if (!response.ok || response.status !== 200 || response.redirected) {
|
|
4394
|
+
throw new TessdataIntegrityError("OCR language response was not a direct HTTP 200.");
|
|
4395
|
+
}
|
|
4396
|
+
const declaredLength = response.headers.get("content-length");
|
|
4397
|
+
if (declaredLength !== null && (!/^\d+$/.test(declaredLength) || Number(declaredLength) !== expectedSize)) {
|
|
4398
|
+
await response.body?.cancel();
|
|
4399
|
+
throw new TessdataIntegrityError("OCR language byte length did not match its pin.");
|
|
4400
|
+
}
|
|
4401
|
+
const reader = response.body?.getReader();
|
|
4402
|
+
if (!reader) throw new TessdataIntegrityError("OCR language response body was empty.");
|
|
4403
|
+
const chunks = [];
|
|
4404
|
+
let size = 0;
|
|
4405
|
+
try {
|
|
4406
|
+
while (true) {
|
|
4407
|
+
const { done, value } = await reader.read();
|
|
4408
|
+
if (done) break;
|
|
4409
|
+
if (value.byteLength > expectedSize - size) {
|
|
4410
|
+
await reader.cancel();
|
|
4411
|
+
throw new TessdataIntegrityError("OCR language byte length exceeded its pin.");
|
|
4412
|
+
}
|
|
4413
|
+
chunks.push(value);
|
|
4414
|
+
size += value.byteLength;
|
|
4415
|
+
}
|
|
4416
|
+
} finally {
|
|
4417
|
+
reader.releaseLock();
|
|
4418
|
+
}
|
|
4419
|
+
if (size !== expectedSize) throw new TessdataIntegrityError("OCR language byte length did not match its pin.");
|
|
4420
|
+
const data = new Uint8Array(size);
|
|
4421
|
+
let offset = 0;
|
|
4422
|
+
for (const chunk of chunks) {
|
|
4423
|
+
data.set(chunk, offset);
|
|
4424
|
+
offset += chunk.byteLength;
|
|
4425
|
+
}
|
|
4426
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", data);
|
|
4427
|
+
const sha256 = Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
4428
|
+
if (sha256 !== expectedHash) throw new TessdataIntegrityError("OCR language SHA-256 did not match its pin.");
|
|
4429
|
+
return { code: lang, data };
|
|
4430
|
+
}
|
|
4431
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4432
|
+
0 && (module.exports = {
|
|
4433
|
+
ACCEPTANCE_BLOCK_REASONS,
|
|
4434
|
+
ALL_BLOCK_REASONS,
|
|
4435
|
+
DETECTOR_UNAVAILABLE_REASON,
|
|
4436
|
+
ENHANCED_NER_MODEL_BYTES,
|
|
4437
|
+
ENHANCED_NER_MODEL_LABEL,
|
|
4438
|
+
H308_ENCODED_PAYLOAD_NOTICE,
|
|
4439
|
+
H308_UNREADABLE_MIME_REASON,
|
|
4440
|
+
K9_L3_MODEL_ID,
|
|
4441
|
+
LOADER_STATES_FOR_RECEIPT,
|
|
4442
|
+
LOAD_FAILURE_BLOCK_REASONS,
|
|
4443
|
+
NER_BLOCK_CODE,
|
|
4444
|
+
NER_L2_DID_NOT_RUN_MESSAGE,
|
|
4445
|
+
NER_READY_BUDGET_MS,
|
|
4446
|
+
NER_READY_MAX_WAIT_MS,
|
|
4447
|
+
NER_READY_USER_WAIT_MS,
|
|
4448
|
+
NER_REQUIRED_MESSAGE,
|
|
4449
|
+
NER_STALL_BUDGET_MS,
|
|
4450
|
+
NER_UNPROVEN_SCRIPT_CODE,
|
|
4451
|
+
NER_UNPROVEN_SCRIPT_MESSAGE,
|
|
4452
|
+
NER_WAIT_BUDGET_MS,
|
|
4453
|
+
NerBlockedError,
|
|
4454
|
+
OCR_LESEGOLV,
|
|
4455
|
+
OCR_LESEGOLV_MAALT,
|
|
4456
|
+
OCR_LESEGOLV_NEMNAR,
|
|
4457
|
+
OCR_ULESE_SPAN_TYPE,
|
|
4458
|
+
OCR_ULESE_SURROGAT_PREFIKS,
|
|
4459
|
+
ORT_IN_WORKER,
|
|
4460
|
+
OcrUfullstendigFeil,
|
|
4461
|
+
PLACEMENT_SCHEMA,
|
|
4462
|
+
TESSDATA_MAX_BYTES,
|
|
4463
|
+
TESSDATA_PACKAGE_VERSION,
|
|
4464
|
+
TESSDATA_SHA256,
|
|
4465
|
+
TESSDATA_SIZE,
|
|
4466
|
+
TESSDATA_VARIANT,
|
|
4467
|
+
TIMING_BLOCK_REASONS,
|
|
4468
|
+
TessdataIntegrityError,
|
|
4469
|
+
UnreadableImageError,
|
|
4470
|
+
acceptanceApplies,
|
|
4471
|
+
andrePassBidrag,
|
|
4472
|
+
applyLateFileTextIfUnchanged,
|
|
4473
|
+
applyTransformersEnv,
|
|
4474
|
+
assertContractLiteralSafe,
|
|
4475
|
+
assertDecodableImage,
|
|
4476
|
+
assertNerAllowsEgress,
|
|
4477
|
+
assertNonLatinSpansTaken,
|
|
4478
|
+
assessH308Input,
|
|
4479
|
+
choiceNeeded,
|
|
4480
|
+
collectRequestBodyTextSlots,
|
|
4481
|
+
collectUserTypedLiteralMarkers,
|
|
4482
|
+
collectValuePlacementWarnings,
|
|
4483
|
+
countDistinctReviewEntities,
|
|
4484
|
+
coverageChoiceLatch,
|
|
4485
|
+
coverageReceiptClaims,
|
|
4486
|
+
coverageWarningFor,
|
|
4487
|
+
createCoverageChoiceLatch,
|
|
4488
|
+
createMultilingualNer,
|
|
4489
|
+
createNerGateBudget,
|
|
4490
|
+
createNerGateCoverage,
|
|
4491
|
+
deepClone,
|
|
4492
|
+
detokeniseReply,
|
|
4493
|
+
fetchVerifiedTessdata,
|
|
4494
|
+
finalCardBackstop,
|
|
4495
|
+
finalCardBackstopJson,
|
|
4496
|
+
finalCardBackstopJsonToFixedPoint,
|
|
4497
|
+
finalCardBackstopToFixedPoint,
|
|
4498
|
+
gateStateToDecision,
|
|
4499
|
+
hasH308MimeHeader,
|
|
4500
|
+
hasIncompleteDetokenisationMap,
|
|
4501
|
+
hasMimeHeaderBlock,
|
|
4502
|
+
hasUnprotectedCardJson,
|
|
4503
|
+
isImageFilenameOrMime,
|
|
4504
|
+
isLateFileTextCurrent,
|
|
4505
|
+
isLevel3Loading,
|
|
4506
|
+
isNerUnavailable,
|
|
4507
|
+
kickoffLevel3IfServed,
|
|
4508
|
+
l2RanForLoaderState,
|
|
4509
|
+
layersRanForReceipt,
|
|
4510
|
+
layersRanWithListCheck,
|
|
4511
|
+
level3Load,
|
|
4512
|
+
level3LoadStore,
|
|
4513
|
+
level3StillLoading,
|
|
4514
|
+
looksNameLikely,
|
|
4515
|
+
makeL3KickLatch,
|
|
4516
|
+
makeNerBlockMessage,
|
|
4517
|
+
markLevel3Load,
|
|
4518
|
+
nameLayerUnchecked,
|
|
4519
|
+
nerGate,
|
|
4520
|
+
nerGateDecision,
|
|
4521
|
+
ordFraTesseract,
|
|
4522
|
+
ordFraTesseractFullstendig,
|
|
4523
|
+
ordFraTesseractMedSkip,
|
|
4524
|
+
ordUnderLesegolvet,
|
|
4525
|
+
ordaUnderLesegolvet,
|
|
4526
|
+
recommendedNerThreads,
|
|
4527
|
+
reconstructSourceFromMap,
|
|
4528
|
+
repairOcrFragmentedEmails,
|
|
4529
|
+
replaceUnicodeCaseFoldOccurrences,
|
|
4530
|
+
resetLevel3LoadForTest,
|
|
4531
|
+
restoreMapOnce,
|
|
4532
|
+
reviewH308Text,
|
|
4533
|
+
slotIsLeftAsWritten,
|
|
4534
|
+
sniffImageKind,
|
|
4535
|
+
stallNeedsChoice,
|
|
4536
|
+
tokeniserUleseOcrOrd,
|
|
4537
|
+
uleseOrdKjerne,
|
|
4538
|
+
unicodeNfkcCaseFold
|
|
4539
|
+
});
|