datakeen-session-react 1.1.193 → 1.1.194-rc.1
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/.gitlab-ci.yml +9 -3
- package/dist/cjs/components/document-collection/DocumentProcessing.js +18 -2
- package/dist/cjs/components/document-collection/DocumentProcessing.js.map +1 -1
- package/dist/cjs/components/id-check/BeforePhoto.js +1 -1
- package/dist/cjs/components/id-check/BeforePhoto.js.map +1 -1
- package/dist/cjs/components/id-check/CameraMask.js +12 -6
- package/dist/cjs/components/id-check/CameraMask.js.map +1 -1
- package/dist/cjs/components/id-check/Photo.js +66 -18
- package/dist/cjs/components/id-check/Photo.js.map +1 -1
- package/dist/cjs/components/jdi/JDIProcessing.js +17 -2
- package/dist/cjs/components/jdi/JDIProcessing.js.map +1 -1
- package/dist/cjs/components/start-flow/CGU.js +1 -1
- package/dist/cjs/components/start-flow/Start.js +1 -1
- package/dist/cjs/i18n/en.json.js +16 -14
- package/dist/cjs/i18n/en.json.js.map +1 -1
- package/dist/cjs/i18n/es.json.js +1208 -0
- package/dist/cjs/i18n/es.json.js.map +1 -0
- package/dist/cjs/i18n/fr.json.js +8 -6
- package/dist/cjs/i18n/fr.json.js.map +1 -1
- package/dist/cjs/i18n/index.js +5 -1
- package/dist/cjs/i18n/index.js.map +1 -1
- package/dist/cjs/index.css.js +1 -1
- package/dist/cjs/services/cameraService.js +34 -90
- package/dist/cjs/services/cameraService.js.map +1 -1
- package/dist/cjs/services/documentEdgeDetectionService.js +182 -0
- package/dist/cjs/services/documentEdgeDetectionService.js.map +1 -0
- package/dist/cjs/utils/analysisErrors.js +18 -0
- package/dist/cjs/utils/analysisErrors.js.map +1 -1
- package/dist/cjs/utils/languageFlags.js +6 -0
- package/dist/cjs/utils/languageFlags.js.map +1 -1
- package/dist/esm/components/document-collection/DocumentProcessing.js +19 -3
- package/dist/esm/components/document-collection/DocumentProcessing.js.map +1 -1
- package/dist/esm/components/id-check/BeforePhoto.js +1 -1
- package/dist/esm/components/id-check/BeforePhoto.js.map +1 -1
- package/dist/esm/components/id-check/CameraMask.js +12 -6
- package/dist/esm/components/id-check/CameraMask.js.map +1 -1
- package/dist/esm/components/id-check/Photo.js +66 -18
- package/dist/esm/components/id-check/Photo.js.map +1 -1
- package/dist/esm/components/jdi/JDIProcessing.js +18 -3
- package/dist/esm/components/jdi/JDIProcessing.js.map +1 -1
- package/dist/esm/components/start-flow/CGU.js +1 -1
- package/dist/esm/components/start-flow/Start.js +1 -1
- package/dist/esm/i18n/en.json.js +16 -14
- package/dist/esm/i18n/en.json.js.map +1 -1
- package/dist/esm/i18n/es.json.js +1167 -0
- package/dist/esm/i18n/es.json.js.map +1 -0
- package/dist/esm/i18n/fr.json.js +8 -6
- package/dist/esm/i18n/fr.json.js.map +1 -1
- package/dist/esm/i18n/index.js +5 -1
- package/dist/esm/i18n/index.js.map +1 -1
- package/dist/esm/index.css.js +1 -1
- package/dist/esm/services/cameraService.js +34 -90
- package/dist/esm/services/cameraService.js.map +1 -1
- package/dist/esm/services/documentEdgeDetectionService.js +176 -0
- package/dist/esm/services/documentEdgeDetectionService.js.map +1 -0
- package/dist/esm/utils/analysisErrors.js +17 -1
- package/dist/esm/utils/analysisErrors.js.map +1 -1
- package/dist/esm/utils/languageFlags.js +6 -0
- package/dist/esm/utils/languageFlags.js.map +1 -1
- package/package.json +1 -4
- package/dist/cjs/services/documentDetectionService.js +0 -156
- package/dist/cjs/services/documentDetectionService.js.map +0 -1
- package/dist/esm/services/documentDetectionService.js +0 -153
- package/dist/esm/services/documentDetectionService.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"documentDetectionService.js","sources":["../../../../src/services/documentDetectionService.ts"],"sourcesContent":["import type { ObjectDetection } from \"@tensorflow-models/coco-ssd\";\n\nexport interface DocumentDetectionResult {\n hasDocument: boolean;\n score?: number;\n label?: string;\n bbox?: [number, number, number, number];\n timestamp: number;\n}\n\nexport class DocumentDetectionService {\n private detectionTimeoutId: number | null = null;\n private model: ObjectDetection | null = null;\n private isDetecting = false;\n private lastResult: DocumentDetectionResult | null = null;\n private readonly DETECTION_INTERVAL_MS = 350;\n\n async loadModel() {\n if (!this.model) {\n const tf = await import(\"@tensorflow/tfjs\");\n await import(\"@tensorflow/tfjs-backend-webgl\");\n const cocoSsd = await import(\"@tensorflow-models/coco-ssd\");\n\n await tf.setBackend(\"webgl\");\n await tf.ready();\n\n this.model = await cocoSsd.load();\n }\n }\n\n async startDocumentDetection(\n videoElement: HTMLVideoElement | null,\n onDetectionChange: (result: DocumentDetectionResult) => void\n ): Promise<{ stop: () => void }> {\n this.stopDocumentDetection();\n await this.loadModel();\n\n const detect = async () => {\n if (!videoElement || !this.model || !videoElement.videoWidth) {\n this.scheduleNextDetection(detect);\n return;\n }\n\n if (this.isDetecting) {\n this.scheduleNextDetection(detect);\n return;\n }\n\n this.isDetecting = true;\n\n try {\n const predictions = await this.model.detect(videoElement);\n\n const documentLike = predictions.find(\n (pred) =>\n [\"book\", \"cell phone\", \"tv\", \"laptop\"].includes(pred.class) &&\n pred.score > 0.6\n );\n\n const result: DocumentDetectionResult = documentLike\n ? {\n hasDocument: true,\n score: documentLike.score,\n label: documentLike.class,\n bbox: documentLike.bbox,\n timestamp: Date.now(),\n }\n : {\n hasDocument: false,\n timestamp: Date.now(),\n };\n\n if (this.shouldEmitResult(result)) {\n onDetectionChange(result);\n this.lastResult = result;\n }\n } catch (err) {\n console.error(\"[DocumentDetection] Error during detection:\", err);\n } finally {\n this.isDetecting = false;\n this.scheduleNextDetection(detect);\n }\n };\n\n detect();\n\n return {\n stop: () => this.stopDocumentDetection(),\n };\n }\n\n stopDocumentDetection() {\n if (this.detectionTimeoutId) {\n clearTimeout(this.detectionTimeoutId);\n this.detectionTimeoutId = null;\n }\n this.isDetecting = false;\n this.lastResult = null;\n }\n\n private shouldEmitResult(result: DocumentDetectionResult): boolean {\n if (!this.lastResult) {\n return true;\n }\n\n if (this.lastResult.hasDocument !== result.hasDocument) {\n return true;\n }\n\n if (!result.hasDocument) {\n return false;\n }\n\n if (!this.lastResult.bbox || !result.bbox) {\n return true;\n }\n\n const [x1, y1, w1, h1] = this.lastResult.bbox;\n const [x2, y2, w2, h2] = result.bbox;\n\n const delta = Math.abs(x1 - x2) + Math.abs(y1 - y2);\n const sizeDelta = Math.abs(w1 - w2) + Math.abs(h1 - h2);\n\n return delta > 10 || sizeDelta > 10;\n }\n\n private scheduleNextDetection(callback: () => void) {\n if (this.detectionTimeoutId) {\n clearTimeout(this.detectionTimeoutId);\n }\n this.detectionTimeoutId = window.setTimeout(\n callback,\n this.DETECTION_INTERVAL_MS\n );\n }\n}\n\nexport const documentDetectionService = new DocumentDetectionService();\n"],"names":["__awaiter"],"mappings":";;;;AAUA,IAAA,wBAAA,kBAAA,YAAA;AAAA,IAAA,SAAA,wBAAA,GAAA;QACU,IAAA,CAAA,kBAAkB,GAAkB,IAAI;QACxC,IAAA,CAAA,KAAK,GAA2B,IAAI;QACpC,IAAA,CAAA,WAAW,GAAG,KAAK;QACnB,IAAA,CAAA,UAAU,GAAmC,IAAI;QACxC,IAAA,CAAA,qBAAqB,GAAG,GAAG;IAwH9C;AAtHQ,IAAA,wBAAA,CAAA,SAAA,CAAA,SAAS,GAAf,YAAA;;;;;;AACM,wBAAA,IAAA,CAAA,CAAC,IAAI,CAAC,KAAK,EAAX,OAAA,CAAA,CAAA,YAAA,CAAA,CAAA;AACS,wBAAA,OAAA,CAAA,CAAA,YAAM,OAAO,kBAAkB,CAAC,CAAA;;AAArC,wBAAA,EAAE,GAAG,EAAA,CAAA,IAAA,EAAgC;AAC3C,wBAAA,OAAA,CAAA,CAAA,YAAM,OAAO,gCAAgC,CAAC,CAAA;;AAA9C,wBAAA,EAAA,CAAA,IAAA,EAA8C;AAC9B,wBAAA,OAAA,CAAA,CAAA,YAAM,OAAO,6BAA6B,CAAC,CAAA;;AAArD,wBAAA,OAAO,GAAG,EAAA,CAAA,IAAA,EAA2C;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AO,KAAK,GAAG,EAAE,IAAI,SAAS,GAAG,EAAE;IACrC,CAAC;IAEO,wBAAA,CAAA,SAAA,CAAA,qBAAqB,GAA7B,UAA8B,QAAoB,EAAA;AAChD,QAAA,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC3B,YAAA,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC;QACvC;AACA,QAAA,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,UAAU,CACzC,QAAQ,EACR,IAAI,CAAC,qBAAqB,CAC3B;IACH,CAAC;IACH,OAAA,wBAAC;AAAD,CAAC,EA7HD;AA+HO,IAAM,wBAAwB,GAAG,IAAI,wBAAwB;;;;;"}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { __awaiter, __generator } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
-
|
|
3
|
-
var DocumentDetectionService = /** @class */ (function () {
|
|
4
|
-
function DocumentDetectionService() {
|
|
5
|
-
this.detectionTimeoutId = null;
|
|
6
|
-
this.model = null;
|
|
7
|
-
this.isDetecting = false;
|
|
8
|
-
this.lastResult = null;
|
|
9
|
-
this.DETECTION_INTERVAL_MS = 350;
|
|
10
|
-
}
|
|
11
|
-
DocumentDetectionService.prototype.loadModel = function () {
|
|
12
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
13
|
-
var tf, cocoSsd, _a;
|
|
14
|
-
return __generator(this, function (_b) {
|
|
15
|
-
switch (_b.label) {
|
|
16
|
-
case 0:
|
|
17
|
-
if (!!this.model) return [3 /*break*/, 7];
|
|
18
|
-
return [4 /*yield*/, import('@tensorflow/tfjs')];
|
|
19
|
-
case 1:
|
|
20
|
-
tf = _b.sent();
|
|
21
|
-
return [4 /*yield*/, import('@tensorflow/tfjs-backend-webgl')];
|
|
22
|
-
case 2:
|
|
23
|
-
_b.sent();
|
|
24
|
-
return [4 /*yield*/, import('@tensorflow-models/coco-ssd')];
|
|
25
|
-
case 3:
|
|
26
|
-
cocoSsd = _b.sent();
|
|
27
|
-
return [4 /*yield*/, tf.setBackend("webgl")];
|
|
28
|
-
case 4:
|
|
29
|
-
_b.sent();
|
|
30
|
-
return [4 /*yield*/, tf.ready()];
|
|
31
|
-
case 5:
|
|
32
|
-
_b.sent();
|
|
33
|
-
_a = this;
|
|
34
|
-
return [4 /*yield*/, cocoSsd.load()];
|
|
35
|
-
case 6:
|
|
36
|
-
_a.model = _b.sent();
|
|
37
|
-
_b.label = 7;
|
|
38
|
-
case 7: return [2 /*return*/];
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
DocumentDetectionService.prototype.startDocumentDetection = function (videoElement, onDetectionChange) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
-
var detect;
|
|
46
|
-
var _this = this;
|
|
47
|
-
return __generator(this, function (_a) {
|
|
48
|
-
switch (_a.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
this.stopDocumentDetection();
|
|
51
|
-
return [4 /*yield*/, this.loadModel()];
|
|
52
|
-
case 1:
|
|
53
|
-
_a.sent();
|
|
54
|
-
detect = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
55
|
-
var predictions, documentLike, result, err_1;
|
|
56
|
-
return __generator(this, function (_a) {
|
|
57
|
-
switch (_a.label) {
|
|
58
|
-
case 0:
|
|
59
|
-
if (!videoElement || !this.model || !videoElement.videoWidth) {
|
|
60
|
-
this.scheduleNextDetection(detect);
|
|
61
|
-
return [2 /*return*/];
|
|
62
|
-
}
|
|
63
|
-
if (this.isDetecting) {
|
|
64
|
-
this.scheduleNextDetection(detect);
|
|
65
|
-
return [2 /*return*/];
|
|
66
|
-
}
|
|
67
|
-
this.isDetecting = true;
|
|
68
|
-
_a.label = 1;
|
|
69
|
-
case 1:
|
|
70
|
-
_a.trys.push([1, 3, 4, 5]);
|
|
71
|
-
return [4 /*yield*/, this.model.detect(videoElement)];
|
|
72
|
-
case 2:
|
|
73
|
-
predictions = _a.sent();
|
|
74
|
-
documentLike = predictions.find(function (pred) {
|
|
75
|
-
return ["book", "cell phone", "tv", "laptop"].includes(pred.class) &&
|
|
76
|
-
pred.score > 0.6;
|
|
77
|
-
});
|
|
78
|
-
result = documentLike
|
|
79
|
-
? {
|
|
80
|
-
hasDocument: true,
|
|
81
|
-
score: documentLike.score,
|
|
82
|
-
label: documentLike.class,
|
|
83
|
-
bbox: documentLike.bbox,
|
|
84
|
-
timestamp: Date.now(),
|
|
85
|
-
}
|
|
86
|
-
: {
|
|
87
|
-
hasDocument: false,
|
|
88
|
-
timestamp: Date.now(),
|
|
89
|
-
};
|
|
90
|
-
if (this.shouldEmitResult(result)) {
|
|
91
|
-
onDetectionChange(result);
|
|
92
|
-
this.lastResult = result;
|
|
93
|
-
}
|
|
94
|
-
return [3 /*break*/, 5];
|
|
95
|
-
case 3:
|
|
96
|
-
err_1 = _a.sent();
|
|
97
|
-
console.error("[DocumentDetection] Error during detection:", err_1);
|
|
98
|
-
return [3 /*break*/, 5];
|
|
99
|
-
case 4:
|
|
100
|
-
this.isDetecting = false;
|
|
101
|
-
this.scheduleNextDetection(detect);
|
|
102
|
-
return [7 /*endfinally*/];
|
|
103
|
-
case 5: return [2 /*return*/];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}); };
|
|
107
|
-
detect();
|
|
108
|
-
return [2 /*return*/, {
|
|
109
|
-
stop: function () { return _this.stopDocumentDetection(); },
|
|
110
|
-
}];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
DocumentDetectionService.prototype.stopDocumentDetection = function () {
|
|
116
|
-
if (this.detectionTimeoutId) {
|
|
117
|
-
clearTimeout(this.detectionTimeoutId);
|
|
118
|
-
this.detectionTimeoutId = null;
|
|
119
|
-
}
|
|
120
|
-
this.isDetecting = false;
|
|
121
|
-
this.lastResult = null;
|
|
122
|
-
};
|
|
123
|
-
DocumentDetectionService.prototype.shouldEmitResult = function (result) {
|
|
124
|
-
if (!this.lastResult) {
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
if (this.lastResult.hasDocument !== result.hasDocument) {
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
if (!result.hasDocument) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
if (!this.lastResult.bbox || !result.bbox) {
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
var _a = this.lastResult.bbox, x1 = _a[0], y1 = _a[1], w1 = _a[2], h1 = _a[3];
|
|
137
|
-
var _b = result.bbox, x2 = _b[0], y2 = _b[1], w2 = _b[2], h2 = _b[3];
|
|
138
|
-
var delta = Math.abs(x1 - x2) + Math.abs(y1 - y2);
|
|
139
|
-
var sizeDelta = Math.abs(w1 - w2) + Math.abs(h1 - h2);
|
|
140
|
-
return delta > 10 || sizeDelta > 10;
|
|
141
|
-
};
|
|
142
|
-
DocumentDetectionService.prototype.scheduleNextDetection = function (callback) {
|
|
143
|
-
if (this.detectionTimeoutId) {
|
|
144
|
-
clearTimeout(this.detectionTimeoutId);
|
|
145
|
-
}
|
|
146
|
-
this.detectionTimeoutId = window.setTimeout(callback, this.DETECTION_INTERVAL_MS);
|
|
147
|
-
};
|
|
148
|
-
return DocumentDetectionService;
|
|
149
|
-
}());
|
|
150
|
-
var documentDetectionService = new DocumentDetectionService();
|
|
151
|
-
|
|
152
|
-
export { DocumentDetectionService, documentDetectionService };
|
|
153
|
-
//# sourceMappingURL=documentDetectionService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"documentDetectionService.js","sources":["../../../../src/services/documentDetectionService.ts"],"sourcesContent":["import type { ObjectDetection } from \"@tensorflow-models/coco-ssd\";\n\nexport interface DocumentDetectionResult {\n hasDocument: boolean;\n score?: number;\n label?: string;\n bbox?: [number, number, number, number];\n timestamp: number;\n}\n\nexport class DocumentDetectionService {\n private detectionTimeoutId: number | null = null;\n private model: ObjectDetection | null = null;\n private isDetecting = false;\n private lastResult: DocumentDetectionResult | null = null;\n private readonly DETECTION_INTERVAL_MS = 350;\n\n async loadModel() {\n if (!this.model) {\n const tf = await import(\"@tensorflow/tfjs\");\n await import(\"@tensorflow/tfjs-backend-webgl\");\n const cocoSsd = await import(\"@tensorflow-models/coco-ssd\");\n\n await tf.setBackend(\"webgl\");\n await tf.ready();\n\n this.model = await cocoSsd.load();\n }\n }\n\n async startDocumentDetection(\n videoElement: HTMLVideoElement | null,\n onDetectionChange: (result: DocumentDetectionResult) => void\n ): Promise<{ stop: () => void }> {\n this.stopDocumentDetection();\n await this.loadModel();\n\n const detect = async () => {\n if (!videoElement || !this.model || !videoElement.videoWidth) {\n this.scheduleNextDetection(detect);\n return;\n }\n\n if (this.isDetecting) {\n this.scheduleNextDetection(detect);\n return;\n }\n\n this.isDetecting = true;\n\n try {\n const predictions = await this.model.detect(videoElement);\n\n const documentLike = predictions.find(\n (pred) =>\n [\"book\", \"cell phone\", \"tv\", \"laptop\"].includes(pred.class) &&\n pred.score > 0.6\n );\n\n const result: DocumentDetectionResult = documentLike\n ? {\n hasDocument: true,\n score: documentLike.score,\n label: documentLike.class,\n bbox: documentLike.bbox,\n timestamp: Date.now(),\n }\n : {\n hasDocument: false,\n timestamp: Date.now(),\n };\n\n if (this.shouldEmitResult(result)) {\n onDetectionChange(result);\n this.lastResult = result;\n }\n } catch (err) {\n console.error(\"[DocumentDetection] Error during detection:\", err);\n } finally {\n this.isDetecting = false;\n this.scheduleNextDetection(detect);\n }\n };\n\n detect();\n\n return {\n stop: () => this.stopDocumentDetection(),\n };\n }\n\n stopDocumentDetection() {\n if (this.detectionTimeoutId) {\n clearTimeout(this.detectionTimeoutId);\n this.detectionTimeoutId = null;\n }\n this.isDetecting = false;\n this.lastResult = null;\n }\n\n private shouldEmitResult(result: DocumentDetectionResult): boolean {\n if (!this.lastResult) {\n return true;\n }\n\n if (this.lastResult.hasDocument !== result.hasDocument) {\n return true;\n }\n\n if (!result.hasDocument) {\n return false;\n }\n\n if (!this.lastResult.bbox || !result.bbox) {\n return true;\n }\n\n const [x1, y1, w1, h1] = this.lastResult.bbox;\n const [x2, y2, w2, h2] = result.bbox;\n\n const delta = Math.abs(x1 - x2) + Math.abs(y1 - y2);\n const sizeDelta = Math.abs(w1 - w2) + Math.abs(h1 - h2);\n\n return delta > 10 || sizeDelta > 10;\n }\n\n private scheduleNextDetection(callback: () => void) {\n if (this.detectionTimeoutId) {\n clearTimeout(this.detectionTimeoutId);\n }\n this.detectionTimeoutId = window.setTimeout(\n callback,\n this.DETECTION_INTERVAL_MS\n );\n }\n}\n\nexport const documentDetectionService = new DocumentDetectionService();\n"],"names":[],"mappings":";;AAUA,IAAA,wBAAA,kBAAA,YAAA;AAAA,IAAA,SAAA,wBAAA,GAAA;QACU,IAAA,CAAA,kBAAkB,GAAkB,IAAI;QACxC,IAAA,CAAA,KAAK,GAA2B,IAAI;QACpC,IAAA,CAAA,WAAW,GAAG,KAAK;QACnB,IAAA,CAAA,UAAU,GAAmC,IAAI;QACxC,IAAA,CAAA,qBAAqB,GAAG,GAAG;IAwH9C;AAtHQ,IAAA,wBAAA,CAAA,SAAA,CAAA,SAAS,GAAf,YAAA;;;;;;AACM,wBAAA,IAAA,CAAA,CAAC,IAAI,CAAC,KAAK,EAAX,OAAA,CAAA,CAAA,YAAA,CAAA,CAAA;AACS,wBAAA,OAAA,CAAA,CAAA,YAAM,OAAO,kBAAkB,CAAC,CAAA;;AAArC,wBAAA,EAAE,GAAG,EAAA,CAAA,IAAA,EAAgC;AAC3C,wBAAA,OAAA,CAAA,CAAA,YAAM,OAAO,gCAAgC,CAAC,CAAA;;AAA9C,wBAAA,EAAA,CAAA,IAAA,EAA8C;AAC9B,wBAAA,OAAA,CAAA,CAAA,YAAM,OAAO,6BAA6B,CAAC,CAAA;;AAArD,wBAAA,OAAO,GAAG,EAAA,CAAA,IAAA,EAA2C;AAE3D,wBAAA,OAAA,CAAA,CAAA,YAAM,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,C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