@brandup/ui-ajax 2.0.1 → 2.0.2

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/dist/cjs/index.js CHANGED
@@ -1,502 +1,14 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * Builds a `URLSearchParams` from query data or a `FormData`.
5
- *
6
- * Array values produce repeated keys; `null` values are skipped.
7
- *
8
- * @param query Source parameters.
9
- * @returns The populated `URLSearchParams` (empty when `query` is nullish).
10
- */
11
- const createQuery = (query) => {
12
- const urlParams = new URLSearchParams();
13
- if (!query)
14
- return urlParams;
15
- if (query instanceof FormData) {
16
- query.forEach((value, key) => {
17
- if (!key)
18
- return;
19
- urlParams.append(key, value.toString());
20
- });
21
- }
22
- else {
23
- for (const key in query) {
24
- const val = query[key];
25
- if (val === null)
26
- continue;
27
- if (Array.isArray(val))
28
- val.forEach(v => urlParams.append(key, v));
29
- else
30
- urlParams.append(key, val);
31
- }
32
- }
33
- return urlParams;
34
- };
35
- /**
36
- * Appends query parameters to a URL, choosing `?` or `&` as appropriate.
37
- *
38
- * @param url Base URL.
39
- * @param query Parameters to append; nothing is added when empty.
40
- * @returns The resulting URL.
41
- */
42
- const addQuery = (url, query) => {
43
- if (query) {
44
- const urlParams = createQuery(query);
45
- if (urlParams.size) {
46
- if (url.indexOf("?") === -1)
47
- url += "?";
48
- else
49
- url += "&";
50
- url += urlParams.toString();
51
- }
52
- }
53
- return url;
54
- };
55
- /**
56
- * Encodes a `FormData` as an `application/x-www-form-urlencoded` string.
57
- *
58
- * @param data Form data to encode.
59
- * @returns The URL-encoded form string.
60
- */
61
- const encodeForm = (data) => {
62
- const query = createQuery(data);
63
- return query.toString();
64
- };
3
+ var request = require('./request.js');
4
+ var ajaxRequest = require('./ajax-request.js');
5
+ var queue = require('./queue.js');
6
+ var helpers = require('./helpers.js');
65
7
 
66
- var helpers = /*#__PURE__*/Object.freeze({
67
- __proto__: null,
68
- addQuery: addQuery,
69
- createQuery: createQuery,
70
- encodeForm: encodeForm
71
- });
72
8
 
73
- const DEFAULT_TIMEOUT = 30000;
74
- const FORM_URL = "application/x-www-form-urlencoded";
75
- const FORM_DATA = "multipart/form-data";
76
- const detectRequestType = (options) => {
77
- if (!options.type && options.data) {
78
- const body = options.data;
79
- if (body instanceof Blob)
80
- options.type = "BLOB";
81
- else if (body instanceof FormData)
82
- options.type = "FORMDATA";
83
- else if (body instanceof HTMLFormElement)
84
- options.type = "FORM";
85
- else if (body instanceof Object)
86
- options.type = "JSON";
87
- else if (typeof body === "string")
88
- options.type = "TEXT";
89
- }
90
- };
91
- const prepareRequest = (options, body) => {
92
- const headers = {};
93
- if (options.headers) {
94
- for (const key in options.headers) {
95
- const value = options.headers[key];
96
- if (!value)
97
- continue;
98
- headers[key] = value;
99
- }
100
- }
101
- if (options.type) {
102
- let contentType = null;
103
- let accept = null;
104
- switch (options.type) {
105
- case "XML":
106
- contentType = "application/xml; charset=utf-8";
107
- accept = "application/xml, text/xml, */*; q=0.01";
108
- break;
109
- case "JSON":
110
- contentType = "application/json; charset=utf-8";
111
- accept = "application/json, text/json, */*; q=0.01";
112
- body = JSON.stringify(body);
113
- break;
114
- case "FORM":
115
- // Convert HTMLFormElement to FormData first, then URL-encode both paths
116
- if (body instanceof HTMLFormElement)
117
- body = new FormData(body);
118
- if (body instanceof FormData) {
119
- body = encodeForm(body);
120
- contentType = FORM_URL;
121
- }
122
- break;
123
- case "FORMDATA":
124
- break;
125
- case "TEXT":
126
- contentType = "text/plain";
127
- break;
128
- }
129
- if (accept)
130
- headers["Accept"] = accept;
131
- if (contentType)
132
- headers['Content-Type'] = contentType;
133
- }
134
- return {
135
- headers,
136
- body
137
- };
138
- };
139
- var internals = {
140
- DEFAULT_TIMEOUT,
141
- FORM_URL,
142
- FORM_DATA,
143
- detectRequestType,
144
- prepareRequest
145
- };
146
9
 
147
- /**
148
- * Performs an AJAX request using the Fetch API.
149
- *
150
- * The response body is parsed according to its `Content-Type`: JSON, `text/html`,
151
- * `text/plain`, otherwise a `Blob`. `disableCache` maps to `cache: "no-store"`.
152
- * The request is aborted when its `timeout` elapses (defaults to 30000 ms), or when
153
- * `options.abort` or the `abortSignal` argument signals.
154
- *
155
- * @param options Request options. `GET`/`HEAD` requests must not carry `data`.
156
- * @param abortSignal Optional additional signal used to cancel the request.
157
- * @returns The parsed response. `options.success` is also invoked before resolving.
158
- * @throws On network/abort/timeout errors, or for unsupported (opaque) response types; `options.error` is invoked before re-throwing.
159
- */
160
- async function request(options, abortSignal) {
161
- let { mode, credentials = "include" } = options;
162
- let url = options.url || location.href;
163
- url = addQuery(url, options.query);
164
- const method = options.method ? options.method.toUpperCase() : "GET";
165
- let body = options.data;
166
- if (body && (method === "GET" || method === "HEAD"))
167
- throw new Error(`${method} method does not support a request body.`);
168
- internals.detectRequestType(options);
169
- const prepared = internals.prepareRequest(options, body);
170
- const abortSignals = [AbortSignal.timeout(options.timeout ?? internals.DEFAULT_TIMEOUT)];
171
- if (options.abort)
172
- abortSignals.push(options.abort);
173
- if (abortSignal)
174
- abortSignals.push(abortSignal);
175
- try {
176
- const response = await fetch(url, {
177
- method,
178
- headers: new Headers(prepared.headers),
179
- cache: options.disableCache ? "no-store" : "default",
180
- mode,
181
- credentials,
182
- redirect: "follow",
183
- signal: AbortSignal.any(abortSignals),
184
- body: prepared.body
185
- });
186
- let result;
187
- switch (response.type) {
188
- case "basic":
189
- case "default":
190
- case "cors": {
191
- let responseData = null;
192
- let responseType = "none";
193
- let contentType = response.headers.get("content-type");
194
- if (!response.redirected && response.body) {
195
- if (contentType) {
196
- const ctSplitIndex = contentType.indexOf(";");
197
- if (ctSplitIndex > 0)
198
- contentType = contentType.substring(0, ctSplitIndex);
199
- if (contentType.includes("json")) {
200
- responseType = "json";
201
- responseData = await response.json();
202
- }
203
- else if (contentType.includes("text/html")) {
204
- responseType = "html";
205
- responseData = await response.text();
206
- }
207
- else if (contentType.includes("text/plain")) {
208
- responseType = "text";
209
- responseData = await response.text();
210
- }
211
- else {
212
- responseType = "blob";
213
- responseData = await response.blob();
214
- }
215
- }
216
- }
217
- result = {
218
- status: response.status,
219
- url: response.url,
220
- redirected: response.redirected,
221
- type: responseType,
222
- contentType,
223
- headers: response.headers,
224
- data: responseData,
225
- state: options.state
226
- };
227
- break;
228
- }
229
- case "opaqueredirect":
230
- case "opaque":
231
- throw new Error(`Not supported response type: ${response.type}`);
232
- case "error":
233
- throw new Error("Response error.");
234
- default:
235
- throw new Error(`Unknown response type: ${response.type}`);
236
- }
237
- if (options.success)
238
- options.success(result);
239
- return result;
240
- }
241
- catch (error) {
242
- if (options.error)
243
- options.error(options, error);
244
- throw error;
245
- }
246
- }
247
-
248
- /**
249
- * Performs an AJAX request using `XMLHttpRequest`, always with credentials.
250
- *
251
- * The response body is parsed by `Content-Type` into JSON, `text/plain` or `text/html`;
252
- * unlike the fetch-based {@link request}, there is no `blob` response type. `disableCache`
253
- * appends a `_=<timestamp>` cache-busting query parameter (rather than `cache: "no-store"`).
254
- * Results and errors are delivered through `options.success` / `options.error`; this
255
- * function does not return a promise.
256
- *
257
- * @param options Request options. `GET` requests must not carry `data`. `timeout` of `0` disables the timeout.
258
- * @returns The underlying `XMLHttpRequest`, which can be used to `abort()` the request.
259
- */
260
- const ajaxRequest = (options) => {
261
- let url = options.url || location.href;
262
- let { query } = options;
263
- if (options.disableCache) {
264
- if (!query)
265
- query = {};
266
- query["_"] = Date.now().toString();
267
- }
268
- url = addQuery(url, query);
269
- const method = options.method ? options.method.toUpperCase() : "GET";
270
- if (options.data && (method === "GET" || method === "HEAD"))
271
- throw new Error(`${method} method does not support a request body.`);
272
- internals.detectRequestType(options);
273
- const prepared = internals.prepareRequest(options, options.data);
274
- const xhr = new XMLHttpRequest();
275
- xhr.withCredentials = true;
276
- if (options.timeout === 0 || options.timeout)
277
- xhr.timeout = options.timeout;
278
- xhr.onreadystatechange = (_e) => {
279
- if (xhr.readyState !== XMLHttpRequest.DONE)
280
- return;
281
- if (options.success) {
282
- let responseData = null;
283
- let responseType = "none";
284
- const contentType = xhr.getResponseHeader("Content-Type");
285
- if (xhr.response && contentType) {
286
- if (contentType.includes("json")) {
287
- responseType = "json";
288
- try {
289
- responseData = JSON.parse(xhr.responseText);
290
- }
291
- catch (e) {
292
- if (options.error)
293
- options.error(options, e);
294
- return;
295
- }
296
- }
297
- else if (contentType.includes("text/plain")) {
298
- responseType = "text";
299
- responseData = xhr.responseText;
300
- }
301
- else if (contentType.includes("text/html")) {
302
- responseType = "html";
303
- responseData = xhr.responseText;
304
- }
305
- }
306
- const xhrRef = xhr;
307
- const headers = {
308
- get(name) {
309
- return xhrRef.getResponseHeader(name);
310
- },
311
- has(name) {
312
- return !!xhrRef.getResponseHeader(name);
313
- },
314
- forEach(callbackfn, thisArg) {
315
- xhrRef.getAllResponseHeaders()
316
- .trim()
317
- .split(/[\r\n]+/)
318
- .filter(Boolean)
319
- .forEach(line => {
320
- const idx = line.indexOf(": ");
321
- const key = idx >= 0 ? line.substring(0, idx).toLowerCase() : line.toLowerCase();
322
- const value = idx >= 0 ? line.substring(idx + 2) : "";
323
- callbackfn.call(thisArg, value, key, {});
324
- });
325
- }
326
- };
327
- options.success({
328
- status: xhr.status,
329
- url: xhr.responseURL,
330
- redirected: false,
331
- type: responseType,
332
- contentType,
333
- headers,
334
- data: responseData,
335
- state: options.state
336
- });
337
- }
338
- };
339
- xhr.onabort = (_e) => {
340
- if (options.error)
341
- options.error(options, new Error("Request aborted"));
342
- };
343
- xhr.onerror = (_e) => {
344
- if (options.error)
345
- options.error(options, new Error("Request network error"));
346
- };
347
- xhr.ontimeout = (_e) => {
348
- if (options.error)
349
- options.error(options, new Error("Request timeout"));
350
- };
351
- xhr.open(method, url, true);
352
- xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
353
- for (const key in prepared.headers) {
354
- const value = prepared.headers[key];
355
- if (!value)
356
- continue;
357
- xhr.setRequestHeader(key, value);
358
- }
359
- if (method === "GET")
360
- xhr.send();
361
- else
362
- xhr.send(prepared.body);
363
- return xhr;
364
- };
365
-
366
- /** Queue that executes AJAX requests one at a time, in the order they were added. */
367
- class AjaxQueue {
368
- _options;
369
- _requests = [];
370
- _current = null;
371
- _destroyed = false;
372
- /** @param options Optional queue-wide hooks. */
373
- constructor(options) {
374
- this._options = options ?? {};
375
- }
376
- /** Number of requests waiting in the queue (excluding the one currently executing). */
377
- get length() { return this._requests.length; }
378
- /** `true` when nothing is queued and no request is currently executing. */
379
- get isFree() { return !this._requests.length && !this._current; }
380
- /** `true` when no requests are waiting in the queue (a request may still be executing). */
381
- get isEmpty() { return !this._requests.length; }
382
- /**
383
- * Adds a request to the queue. Starts executing immediately if the queue is idle.
384
- *
385
- * @param request Request options; its `success`/`error` callbacks are invoked as usual.
386
- * @param abortSignal Optional signal used to cancel this specific request.
387
- * @throws If the queue has been destroyed.
388
- */
389
- push(request, abortSignal) {
390
- if (this._destroyed)
391
- throw new Error("AjaxQueue is destroyed.");
392
- this._requests.push({ request, cancel: abortSignal });
393
- if (!this._current)
394
- this.__execute();
395
- }
396
- /**
397
- * Adds a request to the queue and returns a promise for its response.
398
- *
399
- * Wraps {@link push}; the request's own `success`/`error` callbacks are still invoked,
400
- * then the promise resolves with the response or rejects with the failure reason.
401
- *
402
- * @param request Request options.
403
- * @param abortSignal Optional signal used to cancel this specific request.
404
- * @returns A promise resolving with the {@link AjaxResponse}.
405
- */
406
- enqueue(request, abortSignal) {
407
- const { success, error } = request;
408
- return new Promise((resolve, reject) => {
409
- request.success = (response) => {
410
- if (success)
411
- success(response);
412
- resolve(response);
413
- };
414
- request.error = (request, reason) => {
415
- if (error)
416
- error(request, reason);
417
- reject(reason);
418
- };
419
- this.push(request, abortSignal);
420
- });
421
- }
422
- /** @deprecated Renamed to {@link enqueue}. */
423
- enque(request, abortSignal) {
424
- return this.enqueue(request, abortSignal);
425
- }
426
- /**
427
- * Clears all queued (not-yet-started) requests.
428
- *
429
- * @param cancelCurrentRequest When `true`, also aborts the request currently executing.
430
- */
431
- reset(cancelCurrentRequest = false) {
432
- this._requests = [];
433
- const current = this._current;
434
- this._current = null;
435
- if (cancelCurrentRequest && current)
436
- current.abort?.abort("ResetAjaxQueue");
437
- }
438
- /** Destroys the queue: clears pending requests and aborts the current one. Subsequent {@link push} calls throw. */
439
- destroy() {
440
- if (this._destroyed)
441
- return;
442
- this._destroyed = true;
443
- this._requests = [];
444
- if (this._current) {
445
- this._current.abort?.abort("DestroyAjaxQueue");
446
- this._current = null;
447
- }
448
- }
449
- __execute() {
450
- if (this._destroyed)
451
- return;
452
- if (this._current)
453
- throw new Error("AjaxQueue currently is executing.");
454
- const task = this._current = this._requests.shift() ?? null;
455
- if (task) {
456
- if (this._options.canRequest && this._options.canRequest(task.request) === false) {
457
- this.__next(task);
458
- return;
459
- }
460
- if (task.request.abort?.aborted || task.cancel?.aborted) {
461
- const err = new Error("Request cancelled");
462
- task.request.error?.(task.request, err);
463
- task.result = Promise.reject(err);
464
- }
465
- else {
466
- task.abort = new AbortController();
467
- task.result = request(task.request, task.cancel ? AbortSignal.any([task.abort.signal, task.cancel]) : task.abort.signal);
468
- }
469
- task.result
470
- .then(response => {
471
- if (this._destroyed)
472
- return;
473
- if (this._options.successRequest)
474
- this._options.successRequest(task.request, response);
475
- })
476
- .catch(reason => {
477
- if (this._destroyed)
478
- return;
479
- if (this._options.errorRequest)
480
- this._options.errorRequest(task.request, reason);
481
- })
482
- .finally(() => this.__next(task));
483
- }
484
- }
485
- // completedTask is the task that finished — if _current already changed
486
- // (e.g. reset(true) was called and a new push() started a new task), bail out
487
- // to avoid clearing the new task's reference or double-executing the queue.
488
- __next(completedTask) {
489
- if (this._destroyed)
490
- return;
491
- if (this._current !== completedTask)
492
- return;
493
- this._current = null;
494
- this.__execute();
495
- }
496
- }
497
-
498
- exports.AjaxQueue = AjaxQueue;
10
+ exports.request = request.request;
11
+ exports.ajaxRequest = ajaxRequest.ajaxRequest;
12
+ exports.AjaxQueue = queue.AjaxQueue;
499
13
  exports.RequestHelper = helpers;
500
- exports.ajaxRequest = ajaxRequest;
501
- exports.request = request;
502
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../source/helpers.ts","../../source/internals.ts","../../source/request.ts","../../source/ajax-request.ts","../../source/queue.ts"],"sourcesContent":[null,null,null,null,null],"names":["helpers.encodeForm","helpers.addQuery"],"mappings":";;AAEA;;;;;;;AAOG;AACH,MAAM,WAAW,GAAG,CAAC,KAAmC,KAAI;AAC3D,IAAA,MAAM,SAAS,GAAG,IAAI,eAAe,EAAE;AAEvC,IAAA,IAAI,CAAC,KAAK;AACT,QAAA,OAAO,SAAS;AAEjB,IAAA,IAAI,KAAK,YAAY,QAAQ,EAAE;QAC9B,KAAK,CAAC,OAAO,CAAC,CAAC,KAAyB,EAAE,GAAW,KAAI;AACxD,YAAA,IAAI,CAAC,GAAG;gBACP;YACD,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;AACxC,QAAA,CAAC,CAAC;IACH;SACK;AACJ,QAAA,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;AACxB,YAAA,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YACtB,IAAI,GAAG,KAAK,IAAI;gBACf;AAED,YAAA,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;AACrB,gBAAA,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;;AAE1C,gBAAA,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC;QAC5B;IACD;AAEA,IAAA,OAAO,SAAS;AACjB,CAAC;AAED;;;;;;AAMG;AACH,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,KAAmC,KAAI;IACrE,IAAI,KAAK,EAAE;AACV,QAAA,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC;AAEpC,QAAA,IAAI,SAA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C,YAAY;oBAC7B,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;AAClD,YAAA,CAAC;iBACA,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACnC;IACD;;;;AAKQ,IAAA,MAAM,CAAC,aAA0B,EAAA;QACxC,IAAI,IAAI,CAAC,UAAU;YAClB;AACD,QAAA,IAAI,IAAI,CAAC,QAAQ,KAAK,aAAa;YAClC;AAED,QAAA,IAAI,CAAC,QAAQ,GAAG,IAAI;QACpB,IAAI,CAAC,SAAS,EAAE;IACjB;AACA;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -0,0 +1,82 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var helpers = require('./helpers.js');
6
+
7
+ const DEFAULT_TIMEOUT = 30000;
8
+ const FORM_URL = "application/x-www-form-urlencoded";
9
+ const FORM_DATA = "multipart/form-data";
10
+ const detectRequestType = (options) => {
11
+ if (!options.type && options.data) {
12
+ const body = options.data;
13
+ if (body instanceof Blob)
14
+ options.type = "BLOB";
15
+ else if (body instanceof FormData)
16
+ options.type = "FORMDATA";
17
+ else if (body instanceof HTMLFormElement)
18
+ options.type = "FORM";
19
+ else if (body instanceof Object)
20
+ options.type = "JSON";
21
+ else if (typeof body === "string")
22
+ options.type = "TEXT";
23
+ }
24
+ };
25
+ const prepareRequest = (options, body) => {
26
+ const headers = {};
27
+ if (options.headers) {
28
+ for (const key in options.headers) {
29
+ const value = options.headers[key];
30
+ if (!value)
31
+ continue;
32
+ headers[key] = value;
33
+ }
34
+ }
35
+ if (options.type) {
36
+ let contentType = null;
37
+ let accept = null;
38
+ switch (options.type) {
39
+ case "XML":
40
+ contentType = "application/xml; charset=utf-8";
41
+ accept = "application/xml, text/xml, */*; q=0.01";
42
+ break;
43
+ case "JSON":
44
+ contentType = "application/json; charset=utf-8";
45
+ accept = "application/json, text/json, */*; q=0.01";
46
+ body = JSON.stringify(body);
47
+ break;
48
+ case "FORM":
49
+ // Convert HTMLFormElement to FormData first, then URL-encode both paths
50
+ if (body instanceof HTMLFormElement)
51
+ body = new FormData(body);
52
+ if (body instanceof FormData) {
53
+ body = helpers.encodeForm(body);
54
+ contentType = FORM_URL;
55
+ }
56
+ break;
57
+ case "FORMDATA":
58
+ break;
59
+ case "TEXT":
60
+ contentType = "text/plain";
61
+ break;
62
+ }
63
+ if (accept)
64
+ headers["Accept"] = accept;
65
+ if (contentType)
66
+ headers['Content-Type'] = contentType;
67
+ }
68
+ return {
69
+ headers,
70
+ body
71
+ };
72
+ };
73
+ var internals = {
74
+ DEFAULT_TIMEOUT,
75
+ FORM_URL,
76
+ FORM_DATA,
77
+ detectRequestType,
78
+ prepareRequest
79
+ };
80
+
81
+ exports.default = internals;
82
+ //# sourceMappingURL=internals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internals.js","sources":["../../../source/internals.ts"],"sourcesContent":[null],"names":["helpers.encodeForm"],"mappings":";;;;;;AAGA,MAAM,eAAe,GAAG,KAAK;AAC7B,MAAM,QAAQ,GAAG,mCAAmC;AACpD,MAAM,SAAS,GAAG,qBAAqB;AAEvC,MAAM,iBAAiB,GAAG,CAAC,OAAoB,KAAI;IAClD,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE;AAClC,QAAA,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI;QACzB,IAAI,IAAI,YAAY,IAAI;AACvB,YAAA,OAAO,CAAC,IAAI,GAAG,MAAM;aACjB,IAAI,IAAI,YAAY,QAAQ;AAChC,YAAA,OAAO,CAAC,IAAI,GAAG,UAAU;aACrB,IAAI,IAAI,YAAY,eAAe;AACvC,YAAA,OAAO,CAAC,IAAI,GAAG,MAAM;aACjB,IAAI,IAAI,YAAY,MAAM;AAC9B,YAAA,OAAO,C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