@squiz/dx-page-contents-lib 1.53.1-alpha.22 → 1.53.1-alpha.4
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/lib/formatted-text.d.ts +10 -36
- package/lib/formatted-text.js +2 -8
- package/lib/formatted-text.js.map +1 -1
- package/lib/layout-content.d.ts +6 -154
- package/lib/layout-content.js +19 -31
- package/lib/layout-content.js.map +1 -1
- package/lib/layouts/index.d.ts +43 -1291
- package/lib/layouts/single-column.layout.d.ts +5 -420
- package/lib/layouts/single-column.layout.js +1 -1
- package/lib/layouts/single-column.layout.js.map +1 -1
- package/lib/layouts/two-column.layout.d.ts +9 -840
- package/lib/layouts/two-column.layout.js +2 -2
- package/lib/layouts/two-column.layout.js.map +1 -1
- package/lib/mocks/PageContentsHelpers.d.ts +65 -1589
- package/lib/page-contents-lib.js +3 -4
- package/lib/page-contents-lib.js.map +1 -1
- package/lib/page-contents-lib.spec.js +11 -50
- package/lib/page-contents-lib.spec.js.map +1 -1
- package/lib/resolvers/create-variant-resolver.js +4 -7
- package/lib/resolvers/create-variant-resolver.js.map +1 -1
- package/package.json +3 -3
- package/lib/layout-content.spec.d.ts +0 -1
- package/lib/layout-content.spec.js +0 -129
- package/lib/layout-content.spec.js.map +0 -1
package/lib/formatted-text.d.ts
CHANGED
|
@@ -177,59 +177,33 @@ export declare const ComponentNode: z.ZodObject<{
|
|
|
177
177
|
}>;
|
|
178
178
|
export declare const Variant: z.ZodObject<{
|
|
179
179
|
conditions: z.ZodObject<{
|
|
180
|
-
segment: z.
|
|
180
|
+
segment: z.ZodObject<{
|
|
181
181
|
code: z.ZodString;
|
|
182
182
|
}, "strip", z.ZodTypeAny, {
|
|
183
183
|
code: string;
|
|
184
184
|
}, {
|
|
185
185
|
code: string;
|
|
186
|
-
}
|
|
187
|
-
experiment: z.ZodOptional<z.ZodObject<{
|
|
188
|
-
id: z.ZodString;
|
|
189
|
-
variantId: z.ZodString;
|
|
190
|
-
}, "strip", z.ZodTypeAny, {
|
|
191
|
-
id: string;
|
|
192
|
-
variantId: string;
|
|
193
|
-
}, {
|
|
194
|
-
id: string;
|
|
195
|
-
variantId: string;
|
|
196
|
-
}>>;
|
|
186
|
+
}>;
|
|
197
187
|
}, "strip", z.ZodTypeAny, {
|
|
198
|
-
segment
|
|
188
|
+
segment: {
|
|
199
189
|
code: string;
|
|
200
|
-
}
|
|
201
|
-
experiment?: {
|
|
202
|
-
id: string;
|
|
203
|
-
variantId: string;
|
|
204
|
-
} | undefined;
|
|
190
|
+
};
|
|
205
191
|
}, {
|
|
206
|
-
segment
|
|
192
|
+
segment: {
|
|
207
193
|
code: string;
|
|
208
|
-
}
|
|
209
|
-
experiment?: {
|
|
210
|
-
id: string;
|
|
211
|
-
variantId: string;
|
|
212
|
-
} | undefined;
|
|
194
|
+
};
|
|
213
195
|
}>;
|
|
214
196
|
}, "strip", z.ZodTypeAny, {
|
|
215
197
|
conditions: {
|
|
216
|
-
segment
|
|
198
|
+
segment: {
|
|
217
199
|
code: string;
|
|
218
|
-
}
|
|
219
|
-
experiment?: {
|
|
220
|
-
id: string;
|
|
221
|
-
variantId: string;
|
|
222
|
-
} | undefined;
|
|
200
|
+
};
|
|
223
201
|
};
|
|
224
202
|
}, {
|
|
225
203
|
conditions: {
|
|
226
|
-
segment
|
|
204
|
+
segment: {
|
|
227
205
|
code: string;
|
|
228
|
-
}
|
|
229
|
-
experiment?: {
|
|
230
|
-
id: string;
|
|
231
|
-
variantId: string;
|
|
232
|
-
} | undefined;
|
|
206
|
+
};
|
|
233
207
|
};
|
|
234
208
|
}>;
|
|
235
209
|
export declare const VariationNode: z.ZodObject<{
|
package/lib/formatted-text.js
CHANGED
|
@@ -55,17 +55,11 @@ exports.ComponentNode = zod_1.z.object({
|
|
|
55
55
|
.optional(),
|
|
56
56
|
});
|
|
57
57
|
exports.Variant = zod_1.z.object({
|
|
58
|
-
conditions: zod_1.z
|
|
59
|
-
.object({
|
|
58
|
+
conditions: zod_1.z.object({
|
|
60
59
|
segment: zod_1.z.object({
|
|
61
60
|
code: zod_1.z.string(),
|
|
62
61
|
}),
|
|
63
|
-
|
|
64
|
-
id: zod_1.z.string(),
|
|
65
|
-
variantId: zod_1.z.string(),
|
|
66
|
-
}),
|
|
67
|
-
})
|
|
68
|
-
.partial(),
|
|
62
|
+
}),
|
|
69
63
|
});
|
|
70
64
|
exports.VariationNode = zod_1.z.object({
|
|
71
65
|
type: zod_1.z.literal('variation'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatted-text.js","sourceRoot":"","sources":["../src/formatted-text.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,sEAAsE;AAEtE,MAAM,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACjC,SAAS,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;CAC1D,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,IAAI,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC5B,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC/B,SAAS,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACjC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAEU,QAAA,QAAQ,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACvB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC;AAEU,QAAA,OAAO,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QAAQ,EAAE;IACvC,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,iBAAiB,EAAE,iBAAiB,CAAC,QAAQ,EAAE;CAChD,CAAC,CAAC;AAEU,QAAA,aAAa,GAAG,OAAC,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,WAAW,CAAC;IAC5B,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;IACvB,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE;IACxB,WAAW,EAAE,OAAC;SACX,MAAM,CAAC;QACN,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;KACf,CAAC;SACD,EAAE,CACD,OAAC,CAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,OAAO,EAAE,CAAC;QAC9B,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;KACvB,CAAC,CACH;SACA,QAAQ,EAAE;CACd,CAAC,CAAC;AAEU,QAAA,OAAO,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9B,UAAU,EAAE,OAAC,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;YAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;SACjB,CAAC;KACH,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,aAAa,GAAG,OAAC,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,WAAW,CAAC;IAC5B,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC;CACtB,CAAC,CAAC"}
|
package/lib/layout-content.d.ts
CHANGED
|
@@ -188,165 +188,17 @@ export type LayoutVariationNode = z.infer<typeof VariationNode> & {
|
|
|
188
188
|
variants: LayoutVariant[];
|
|
189
189
|
};
|
|
190
190
|
export declare const LayoutVariationNode: z.ZodType<LayoutVariationNode, z.ZodTypeDef, z.infer<typeof VariationNode>>;
|
|
191
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Comprehensive list of all nodes and the existence of child nodes within
|
|
193
|
+
*/
|
|
194
|
+
export type LayoutContentNodes = Exclude<BaseLayoutContentNodes, NodesWithChildren> | LayoutVariationNode | (NodesWithChildren & {
|
|
192
195
|
children: LayoutContentNodes[];
|
|
193
196
|
});
|
|
194
|
-
declare const SimpleContentNodes: z.ZodType<SimpleContentNodes, z.ZodTypeDef, BaseLayoutContentNodes>;
|
|
195
197
|
/**
|
|
196
198
|
* Schema for all possible layout content nodes with checks for children
|
|
197
199
|
*/
|
|
198
|
-
export declare const LayoutContentNodes: z.
|
|
199
|
-
|
|
200
|
-
type: "text";
|
|
201
|
-
} | {
|
|
202
|
-
type: "tag";
|
|
203
|
-
tag: string;
|
|
204
|
-
attributes?: Record<string, string> | undefined;
|
|
205
|
-
font?: {
|
|
206
|
-
bold?: boolean | undefined;
|
|
207
|
-
italics?: boolean | undefined;
|
|
208
|
-
underline?: boolean | undefined;
|
|
209
|
-
color?: string | undefined;
|
|
210
|
-
size?: string | undefined;
|
|
211
|
-
fontFamily?: string | undefined;
|
|
212
|
-
} | undefined;
|
|
213
|
-
formattingOptions?: {
|
|
214
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
215
|
-
} | undefined;
|
|
216
|
-
} | {
|
|
217
|
-
type: "link-to-matrix-asset";
|
|
218
|
-
matrixDomain: string;
|
|
219
|
-
matrixAssetId: string;
|
|
220
|
-
target: "_blank" | "_self" | "_parent" | "_top";
|
|
221
|
-
matrixIdentifier?: string | undefined;
|
|
222
|
-
formattingOptions?: {
|
|
223
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
224
|
-
} | undefined;
|
|
225
|
-
} | {
|
|
226
|
-
type: "matrix-image";
|
|
227
|
-
matrixDomain: string;
|
|
228
|
-
matrixAssetId: string;
|
|
229
|
-
matrixIdentifier?: string | undefined;
|
|
230
|
-
formattingOptions?: {
|
|
231
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
232
|
-
} | undefined;
|
|
233
|
-
} | {
|
|
234
|
-
type: "component";
|
|
235
|
-
componentId: string;
|
|
236
|
-
componentSet: string;
|
|
237
|
-
contentItem?: {
|
|
238
|
-
id: string;
|
|
239
|
-
} | {
|
|
240
|
-
content: Record<string, unknown>;
|
|
241
|
-
schemaName: string;
|
|
242
|
-
} | undefined;
|
|
243
|
-
}>, z.ZodType<LayoutVariationNode, z.ZodTypeDef, {
|
|
244
|
-
type: "variation";
|
|
245
|
-
default: {};
|
|
246
|
-
}>]>;
|
|
247
|
-
/**
|
|
248
|
-
* Comprehensive list of all nodes and the existence of child nodes within
|
|
249
|
-
*/
|
|
250
|
-
export type LayoutContentNodes = z.infer<typeof LayoutContentNodes>;
|
|
251
|
-
export declare function getNestedNodes(nodes: LayoutContentNodes[]): LayoutContentNodes[];
|
|
252
|
-
export declare const PageLayoutContent: z.ZodEffects<z.ZodArray<z.ZodUnion<[z.ZodType<SimpleContentNodes, z.ZodTypeDef, {
|
|
253
|
-
value: string;
|
|
254
|
-
type: "text";
|
|
255
|
-
} | {
|
|
256
|
-
type: "tag";
|
|
257
|
-
tag: string;
|
|
258
|
-
attributes?: Record<string, string> | undefined;
|
|
259
|
-
font?: {
|
|
260
|
-
bold?: boolean | undefined;
|
|
261
|
-
italics?: boolean | undefined;
|
|
262
|
-
underline?: boolean | undefined;
|
|
263
|
-
color?: string | undefined;
|
|
264
|
-
size?: string | undefined;
|
|
265
|
-
fontFamily?: string | undefined;
|
|
266
|
-
} | undefined;
|
|
267
|
-
formattingOptions?: {
|
|
268
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
269
|
-
} | undefined;
|
|
270
|
-
} | {
|
|
271
|
-
type: "link-to-matrix-asset";
|
|
272
|
-
matrixDomain: string;
|
|
273
|
-
matrixAssetId: string;
|
|
274
|
-
target: "_blank" | "_self" | "_parent" | "_top";
|
|
275
|
-
matrixIdentifier?: string | undefined;
|
|
276
|
-
formattingOptions?: {
|
|
277
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
278
|
-
} | undefined;
|
|
279
|
-
} | {
|
|
280
|
-
type: "matrix-image";
|
|
281
|
-
matrixDomain: string;
|
|
282
|
-
matrixAssetId: string;
|
|
283
|
-
matrixIdentifier?: string | undefined;
|
|
284
|
-
formattingOptions?: {
|
|
285
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
286
|
-
} | undefined;
|
|
287
|
-
} | {
|
|
288
|
-
type: "component";
|
|
289
|
-
componentId: string;
|
|
290
|
-
componentSet: string;
|
|
291
|
-
contentItem?: {
|
|
292
|
-
id: string;
|
|
293
|
-
} | {
|
|
294
|
-
content: Record<string, unknown>;
|
|
295
|
-
schemaName: string;
|
|
296
|
-
} | undefined;
|
|
297
|
-
}>, z.ZodType<LayoutVariationNode, z.ZodTypeDef, {
|
|
298
|
-
type: "variation";
|
|
299
|
-
default: {};
|
|
300
|
-
}>]>, "many">, (LayoutVariationNode | SimpleContentNodes)[], ({
|
|
301
|
-
value: string;
|
|
302
|
-
type: "text";
|
|
303
|
-
} | {
|
|
304
|
-
type: "tag";
|
|
305
|
-
tag: string;
|
|
306
|
-
attributes?: Record<string, string> | undefined;
|
|
307
|
-
font?: {
|
|
308
|
-
bold?: boolean | undefined;
|
|
309
|
-
italics?: boolean | undefined;
|
|
310
|
-
underline?: boolean | undefined;
|
|
311
|
-
color?: string | undefined;
|
|
312
|
-
size?: string | undefined;
|
|
313
|
-
fontFamily?: string | undefined;
|
|
314
|
-
} | undefined;
|
|
315
|
-
formattingOptions?: {
|
|
316
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
317
|
-
} | undefined;
|
|
318
|
-
} | {
|
|
319
|
-
type: "link-to-matrix-asset";
|
|
320
|
-
matrixDomain: string;
|
|
321
|
-
matrixAssetId: string;
|
|
322
|
-
target: "_blank" | "_self" | "_parent" | "_top";
|
|
323
|
-
matrixIdentifier?: string | undefined;
|
|
324
|
-
formattingOptions?: {
|
|
325
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
326
|
-
} | undefined;
|
|
327
|
-
} | {
|
|
328
|
-
type: "matrix-image";
|
|
329
|
-
matrixDomain: string;
|
|
330
|
-
matrixAssetId: string;
|
|
331
|
-
matrixIdentifier?: string | undefined;
|
|
332
|
-
formattingOptions?: {
|
|
333
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
334
|
-
} | undefined;
|
|
335
|
-
} | {
|
|
336
|
-
type: "component";
|
|
337
|
-
componentId: string;
|
|
338
|
-
componentSet: string;
|
|
339
|
-
contentItem?: {
|
|
340
|
-
id: string;
|
|
341
|
-
} | {
|
|
342
|
-
content: Record<string, unknown>;
|
|
343
|
-
schemaName: string;
|
|
344
|
-
} | undefined;
|
|
345
|
-
} | {
|
|
346
|
-
type: "variation";
|
|
347
|
-
default: {};
|
|
348
|
-
})[]>;
|
|
349
|
-
export type PageLayoutContent = z.infer<typeof PageLayoutContent>;
|
|
200
|
+
export declare const LayoutContentNodes: z.ZodType<LayoutContentNodes, z.ZodTypeDef, z.infer<typeof VariationNode> | BaseLayoutContentNodes>;
|
|
201
|
+
export type PageLayoutContent = LayoutContentNodes[];
|
|
350
202
|
export type NodeResolver = (node: LayoutContentNodes) => Promise<LayoutContentNodes | void>;
|
|
351
203
|
export type ContentResolver<K extends LayoutContentNodes['type']> = (node: Extract<LayoutContentNodes, {
|
|
352
204
|
type: K;
|
package/lib/layout-content.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PageLayoutContentResolver = exports.
|
|
3
|
+
exports.PageLayoutContentResolver = exports.LayoutContentNodes = exports.LayoutVariationNode = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const formatted_text_1 = require("./formatted-text");
|
|
6
6
|
const resolvers_1 = require("./resolvers");
|
|
@@ -15,7 +15,8 @@ const BaseLayoutContentNodes = zod_1.z.discriminatedUnion('type', [
|
|
|
15
15
|
* All the nodes which allow children
|
|
16
16
|
*/
|
|
17
17
|
const NODES_WITH_CHILDREN = ['tag', 'link-to-matrix-asset'];
|
|
18
|
-
exports.LayoutVariationNode =
|
|
18
|
+
exports.LayoutVariationNode = zod_1.z
|
|
19
|
+
.object({
|
|
19
20
|
default: zod_1.z.object({
|
|
20
21
|
node: zod_1.z.lazy(() => exports.LayoutContentNodes).nullable(),
|
|
21
22
|
}),
|
|
@@ -25,15 +26,26 @@ exports.LayoutVariationNode = formatted_text_1.VariationNode.extend({
|
|
|
25
26
|
.array()
|
|
26
27
|
.min(1)
|
|
27
28
|
.refine((variants) => {
|
|
28
|
-
const
|
|
29
|
-
return
|
|
29
|
+
const uniqueKeys = {};
|
|
30
|
+
return (variants.findIndex((variant) => {
|
|
31
|
+
const uniqueKey = JSON.stringify([variant.conditions.segment.code]);
|
|
32
|
+
if (!uniqueKeys[uniqueKey]) {
|
|
33
|
+
uniqueKeys[uniqueKey] = true;
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}) < 0);
|
|
30
38
|
}, { message: 'The conditions assigned to a variant must be unique.' }),
|
|
31
|
-
})
|
|
32
|
-
|
|
39
|
+
})
|
|
40
|
+
.and(formatted_text_1.VariationNode);
|
|
41
|
+
/**
|
|
42
|
+
* Schema for all possible layout content nodes with checks for children
|
|
43
|
+
*/
|
|
44
|
+
exports.LayoutContentNodes = zod_1.z
|
|
33
45
|
.object({
|
|
34
46
|
children: zod_1.z.lazy(() => zod_1.z.array(exports.LayoutContentNodes)).optional(),
|
|
35
47
|
})
|
|
36
|
-
.and(BaseLayoutContentNodes)
|
|
48
|
+
.and(zod_1.z.union([exports.LayoutVariationNode, BaseLayoutContentNodes]))
|
|
37
49
|
.refine((value) => {
|
|
38
50
|
// Only certain node types to contain children
|
|
39
51
|
if ('children' in value && NODES_WITH_CHILDREN.includes(value.type) === false) {
|
|
@@ -41,30 +53,6 @@ const SimpleContentNodes = zod_1.z
|
|
|
41
53
|
}
|
|
42
54
|
return true;
|
|
43
55
|
});
|
|
44
|
-
/**
|
|
45
|
-
* Schema for all possible layout content nodes with checks for children
|
|
46
|
-
*/
|
|
47
|
-
exports.LayoutContentNodes = zod_1.z.union([SimpleContentNodes, exports.LayoutVariationNode]);
|
|
48
|
-
function isRecursiveNode(node) {
|
|
49
|
-
return node.type === 'variation';
|
|
50
|
-
}
|
|
51
|
-
function pickNestedNodes(node) {
|
|
52
|
-
return [node.default.node].concat(node.variants.map((v) => v.node)).filter((n) => !!n);
|
|
53
|
-
}
|
|
54
|
-
function getNestedNodes(nodes) {
|
|
55
|
-
const topLevelNodes = nodes.filter(isRecursiveNode).map(pickNestedNodes);
|
|
56
|
-
return topLevelNodes.flatMap(getNestedNodes).concat(topLevelNodes.flat());
|
|
57
|
-
}
|
|
58
|
-
exports.getNestedNodes = getNestedNodes;
|
|
59
|
-
exports.PageLayoutContent = zod_1.z.array(exports.LayoutContentNodes).refine((nodes) => {
|
|
60
|
-
// Enforce singular experiment ID within the Page Content
|
|
61
|
-
return nodes
|
|
62
|
-
.concat(getNestedNodes(nodes))
|
|
63
|
-
.filter((n) => n.type === 'variation')
|
|
64
|
-
.flatMap((n) => n.variants)
|
|
65
|
-
.filter((v) => !!v.conditions.experiment)
|
|
66
|
-
.every((v, _, list) => v.conditions.experiment.id === list[0].conditions.experiment.id);
|
|
67
|
-
}, { message: 'all experiment nodes must have same experimentId' });
|
|
68
56
|
/**
|
|
69
57
|
* Walk through the layout content and resolve the content items.
|
|
70
58
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout-content.js","sourceRoot":"","sources":["../src/layout-content.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,qDAQ0B;AAC1B,2CAAuD;AAEvD,MAAM,sBAAsB,GAAG,OAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE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