ckeditor5-elements-schema 0.0.0-stage → 49.0.0-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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -2
  3. package/dist/augmentation.d.ts +25 -0
  4. package/dist/augmentation.d.ts.map +1 -0
  5. package/dist/augmentation.js +2 -0
  6. package/dist/augmentation.js.map +1 -0
  7. package/dist/commands/elementBlockCommand.d.ts +46 -0
  8. package/dist/commands/elementBlockCommand.d.ts.map +1 -0
  9. package/dist/commands/elementBlockCommand.js +71 -0
  10. package/dist/commands/elementBlockCommand.js.map +1 -0
  11. package/dist/commands/elementContainerCommand.d.ts +36 -0
  12. package/dist/commands/elementContainerCommand.d.ts.map +1 -0
  13. package/dist/commands/elementContainerCommand.js +67 -0
  14. package/dist/commands/elementContainerCommand.js.map +1 -0
  15. package/dist/commands/elementInlineCommand.d.ts +87 -0
  16. package/dist/commands/elementInlineCommand.d.ts.map +1 -0
  17. package/dist/commands/elementInlineCommand.js +253 -0
  18. package/dist/commands/elementInlineCommand.js.map +1 -0
  19. package/dist/commands/elementInsertCommand.d.ts +33 -0
  20. package/dist/commands/elementInsertCommand.d.ts.map +1 -0
  21. package/dist/commands/elementInsertCommand.js +61 -0
  22. package/dist/commands/elementInsertCommand.js.map +1 -0
  23. package/dist/commands/elementSchemaCommand.d.ts +62 -0
  24. package/dist/commands/elementSchemaCommand.d.ts.map +1 -0
  25. package/dist/commands/elementSchemaCommand.js +107 -0
  26. package/dist/commands/elementSchemaCommand.js.map +1 -0
  27. package/dist/conversion/convertElementSchema.d.ts +17 -0
  28. package/dist/conversion/convertElementSchema.d.ts.map +1 -0
  29. package/dist/conversion/convertElementSchema.js +55 -0
  30. package/dist/conversion/convertElementSchema.js.map +1 -0
  31. package/dist/conversion/inlineTextElement.d.ts +24 -0
  32. package/dist/conversion/inlineTextElement.d.ts.map +1 -0
  33. package/dist/conversion/inlineTextElement.js +28 -0
  34. package/dist/conversion/inlineTextElement.js.map +1 -0
  35. package/dist/definition/canHold.d.ts +10 -0
  36. package/dist/definition/canHold.d.ts.map +1 -0
  37. package/dist/definition/canHold.js +22 -0
  38. package/dist/definition/canHold.js.map +1 -0
  39. package/dist/definition/compileElementSchema.d.ts +41 -0
  40. package/dist/definition/compileElementSchema.d.ts.map +1 -0
  41. package/dist/definition/compileElementSchema.js +60 -0
  42. package/dist/definition/compileElementSchema.js.map +1 -0
  43. package/dist/definition/elementSchemaError.d.ts +12 -0
  44. package/dist/definition/elementSchemaError.d.ts.map +1 -0
  45. package/dist/definition/elementSchemaError.js +16 -0
  46. package/dist/definition/elementSchemaError.js.map +1 -0
  47. package/dist/definition/readDefinition.d.ts +18 -0
  48. package/dist/definition/readDefinition.d.ts.map +1 -0
  49. package/dist/definition/readDefinition.js +60 -0
  50. package/dist/definition/readDefinition.js.map +1 -0
  51. package/dist/definition/suggest.d.ts +5 -0
  52. package/dist/definition/suggest.d.ts.map +1 -0
  53. package/dist/definition/suggest.js +27 -0
  54. package/dist/definition/suggest.js.map +1 -0
  55. package/dist/definition/types.d.ts +105 -0
  56. package/dist/definition/types.d.ts.map +1 -0
  57. package/dist/definition/types.js +2 -0
  58. package/dist/definition/types.js.map +1 -0
  59. package/dist/definition/validateElementSchema.d.ts +26 -0
  60. package/dist/definition/validateElementSchema.d.ts.map +1 -0
  61. package/dist/definition/validateElementSchema.js +145 -0
  62. package/dist/definition/validateElementSchema.js.map +1 -0
  63. package/dist/elementSchema.d.ts +47 -0
  64. package/dist/elementSchema.d.ts.map +1 -0
  65. package/dist/elementSchema.js +108 -0
  66. package/dist/elementSchema.js.map +1 -0
  67. package/dist/elementSchemaCommands.d.ts +83 -0
  68. package/dist/elementSchemaCommands.d.ts.map +1 -0
  69. package/dist/elementSchemaCommands.js +137 -0
  70. package/dist/elementSchemaCommands.js.map +1 -0
  71. package/dist/index.d.ts +18 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +22 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/typing/twoStepCaretMovement.d.ts +11 -0
  76. package/dist/typing/twoStepCaretMovement.d.ts.map +1 -0
  77. package/dist/typing/twoStepCaretMovement.js +76 -0
  78. package/dist/typing/twoStepCaretMovement.js.map +1 -0
  79. package/dist/validate.d.ts +12 -0
  80. package/dist/validate.d.ts.map +1 -0
  81. package/dist/validate.js +11 -0
  82. package/dist/validate.js.map +1 -0
  83. package/package.json +49 -3
  84. package/src/augmentation.ts +28 -0
  85. package/src/commands/elementBlockCommand.ts +87 -0
  86. package/src/commands/elementContainerCommand.ts +83 -0
  87. package/src/commands/elementInlineCommand.ts +311 -0
  88. package/src/commands/elementInsertCommand.ts +74 -0
  89. package/src/commands/elementSchemaCommand.ts +140 -0
  90. package/src/conversion/convertElementSchema.ts +65 -0
  91. package/src/conversion/inlineTextElement.ts +31 -0
  92. package/src/definition/canHold.ts +29 -0
  93. package/src/definition/compileElementSchema.ts +88 -0
  94. package/src/definition/elementSchemaError.ts +21 -0
  95. package/src/definition/readDefinition.ts +98 -0
  96. package/src/definition/suggest.ts +38 -0
  97. package/src/definition/types.ts +123 -0
  98. package/src/definition/validateElementSchema.ts +238 -0
  99. package/src/elementSchema.ts +133 -0
  100. package/src/elementSchemaCommands.ts +202 -0
  101. package/src/index.ts +30 -0
  102. package/src/typing/twoStepCaretMovement.ts +119 -0
  103. package/src/validate.ts +20 -0
@@ -0,0 +1,24 @@
1
+ import type { ViewContainerElement, ViewDowncastWriter } from 'ckeditor5';
2
+ /**
3
+ * Makes a view element have no block filler, and returns it: for the view of an inline element with text, e.g. a bold
4
+ * that is an element, so that the cursor can go in it when it is empty.
5
+ *
6
+ * CKEditor puts a block filler, a `<br>`, in an empty container element, so that an empty paragraph has a height. In an
7
+ * inline element, the browser does not type there: the text goes before the element. Without the block filler, CKEditor
8
+ * puts its inline filler where the cursor is, as in the empty `<strong>` of its own bold, and the text goes in.
9
+ *
10
+ * ```ts
11
+ * conversion.for('downcast').elementToElement({
12
+ * model: 'bold',
13
+ * view: (element, { writer }) => withoutBlockFiller(writer.createContainerElement('strong'))
14
+ * });
15
+ * ```
16
+ *
17
+ * The converters of the element schema (`elementSchemaConverters`) and the `view` of `ElementSchemaCommands` do it already.
18
+ */
19
+ export declare function withoutBlockFiller<T extends ViewContainerElement>(element: T): T;
20
+ /**
21
+ * Creates the view of an inline element with text: an element with no block filler (see {@link withoutBlockFiller}).
22
+ */
23
+ export declare function createInlineTextElement(writer: ViewDowncastWriter, tag: string, name?: string): ViewContainerElement;
24
+ //# sourceMappingURL=inlineTextElement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inlineTextElement.d.ts","sourceRoot":"","sources":["../../src/conversion/inlineTextElement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE1E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,oBAAoB,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAIhF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAEpH"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Makes a view element have no block filler, and returns it: for the view of an inline element with text, e.g. a bold
3
+ * that is an element, so that the cursor can go in it when it is empty.
4
+ *
5
+ * CKEditor puts a block filler, a `<br>`, in an empty container element, so that an empty paragraph has a height. In an
6
+ * inline element, the browser does not type there: the text goes before the element. Without the block filler, CKEditor
7
+ * puts its inline filler where the cursor is, as in the empty `<strong>` of its own bold, and the text goes in.
8
+ *
9
+ * ```ts
10
+ * conversion.for('downcast').elementToElement({
11
+ * model: 'bold',
12
+ * view: (element, { writer }) => withoutBlockFiller(writer.createContainerElement('strong'))
13
+ * });
14
+ * ```
15
+ *
16
+ * The converters of the element schema (`elementSchemaConverters`) and the `view` of `ElementSchemaCommands` do it already.
17
+ */
18
+ export function withoutBlockFiller(element) {
19
+ element.getFillerOffset = () => null;
20
+ return element;
21
+ }
22
+ /**
23
+ * Creates the view of an inline element with text: an element with no block filler (see {@link withoutBlockFiller}).
24
+ */
25
+ export function createInlineTextElement(writer, tag, name) {
26
+ return withoutBlockFiller(writer.createContainerElement(tag, name ? { class: name } : {}));
27
+ }
28
+ //# sourceMappingURL=inlineTextElement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inlineTextElement.js","sourceRoot":"","sources":["../../src/conversion/inlineTextElement.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAiC,OAAU;IAC5E,OAAO,CAAC,eAAe,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;IAErC,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAA0B,EAAE,GAAW,EAAE,IAAa;IAC7F,OAAO,kBAAkB,CAAC,MAAM,CAAC,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5F,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ElementSchemaKind } from './types.js';
2
+ /**
3
+ * The root can hold blocks, containers and block-level empty elements, like a container.
4
+ */
5
+ export declare const ROOT: ElementSchemaKind;
6
+ /**
7
+ * Returns why `parent` cannot contain `child` (an element, or `'$text'`), or `null` when it can.
8
+ */
9
+ export declare function whyNot(parent: ElementSchemaKind, child: ElementSchemaKind | '$text'): string | null;
10
+ //# sourceMappingURL=canHold.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canHold.d.ts","sourceRoot":"","sources":["../../src/definition/canHold.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,iBAA0D,CAAC;AAE9E;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,iBAAiB,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAkBnG"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The root can hold blocks, containers and block-level empty elements, like a container.
3
+ */
4
+ export const ROOT = { type: 'container', isInline: false };
5
+ /**
6
+ * Returns why `parent` cannot contain `child` (an element, or `'$text'`), or `null` when it can.
7
+ */
8
+ export function whyNot(parent, child) {
9
+ const isText = child === '$text';
10
+ if (parent.type === 'empty') {
11
+ return 'an empty element cannot contain anything';
12
+ }
13
+ if (parent.type === 'block') {
14
+ const what = parent.isInline ? 'an inline text element' : 'a block';
15
+ return isText || child.isInline ? null : `${what} can contain only text and inline elements`;
16
+ }
17
+ if (isText) {
18
+ return 'a container cannot contain text: put the text in a block';
19
+ }
20
+ return child.isInline ? 'a container cannot contain inline elements: put them in a block' : null;
21
+ }
22
+ //# sourceMappingURL=canHold.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canHold.js","sourceRoot":"","sources":["../../src/definition/canHold.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAsB,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAE9E;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,MAAyB,EAAE,KAAkC;IACnF,MAAM,MAAM,GAAG,KAAK,KAAK,OAAO,CAAC;IAEjC,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,OAAO,0CAA0C,CAAC;IACnD,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,SAAS,CAAC;QAEpE,OAAO,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,4CAA4C,CAAC;IAC9F,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACZ,OAAO,0DAA0D,CAAC;IACnE,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,IAAI,CAAC;AAClG,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { ModelSchemaItemDefinition } from 'ckeditor5';
2
+ import type { ElementSchemaInput } from './types.js';
3
+ /**
4
+ * The result of {@link compileElementSchema}.
5
+ */
6
+ export interface CompiledElementSchema {
7
+ /**
8
+ * The items to register in CKEditor's schema, by name.
9
+ */
10
+ items: [name: string, definition: ModelSchemaItemDefinition][];
11
+ /**
12
+ * The `allowChildren` of the elements, as the places to add to the children: `schema.extend(child, { allowIn: parent })`.
13
+ * The child can be an element of another plugin, which is extended, not registered.
14
+ */
15
+ children: {
16
+ parent: string;
17
+ child: string;
18
+ }[];
19
+ }
20
+ /**
21
+ * Translates a valid element schema to the definitions of CKEditor's schema. Each type is made like a generic item of
22
+ * CKEditor:
23
+ *
24
+ * * `container`: like `$container`: allowed in the root and in containers; holds what is allowed in a container: blocks,
25
+ * containers and block objects, not text.
26
+ * * `block`: like `$block`: a block, allowed in the root and in containers; holds text and inline objects.
27
+ * * `empty` and not inline: like `$blockObject`: an object, allowed where blocks are.
28
+ * * `empty` and inline: like `$inlineObject`: an object, allowed where text is, with the attributes of text.
29
+ * * `block` and inline: an inline element that holds text and inline elements, allowed where text is, with the attributes
30
+ * of text: like `$text`, but an element, so it can have attributes of its own.
31
+ * * `container` and inline: a container laid out in a line, e.g. with others in a block: allowed where text is, like every
32
+ * inline element, and holds the same as a container: blocks, not text.
33
+ *
34
+ * `isInline` is about the layout and the position of an element, so it is set for every type, and CKEditor's features and
35
+ * the converters can use it.
36
+ *
37
+ * `allowAttributes` is passed as it is. `allowIn` replaces the default places of the type. `allowChildren` adds to what
38
+ * the type holds, as in CKEditor.
39
+ */
40
+ export declare function compileElementSchema(input: ElementSchemaInput): CompiledElementSchema;
41
+ //# sourceMappingURL=compileElementSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileElementSchema.d.ts","sourceRoot":"","sources":["../../src/definition/compileElementSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,EAAwB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC;;OAEG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,CAAC,EAAE,CAAC;IAE/D;;;OAGG;IACH,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,GAAG,qBAAqB,CAarF"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Translates a valid element schema to the definitions of CKEditor's schema. Each type is made like a generic item of
3
+ * CKEditor:
4
+ *
5
+ * * `container`: like `$container`: allowed in the root and in containers; holds what is allowed in a container: blocks,
6
+ * containers and block objects, not text.
7
+ * * `block`: like `$block`: a block, allowed in the root and in containers; holds text and inline objects.
8
+ * * `empty` and not inline: like `$blockObject`: an object, allowed where blocks are.
9
+ * * `empty` and inline: like `$inlineObject`: an object, allowed where text is, with the attributes of text.
10
+ * * `block` and inline: an inline element that holds text and inline elements, allowed where text is, with the attributes
11
+ * of text: like `$text`, but an element, so it can have attributes of its own.
12
+ * * `container` and inline: a container laid out in a line, e.g. with others in a block: allowed where text is, like every
13
+ * inline element, and holds the same as a container: blocks, not text.
14
+ *
15
+ * `isInline` is about the layout and the position of an element, so it is set for every type, and CKEditor's features and
16
+ * the converters can use it.
17
+ *
18
+ * `allowAttributes` is passed as it is. `allowIn` replaces the default places of the type. `allowChildren` adds to what
19
+ * the type holds, as in CKEditor.
20
+ */
21
+ export function compileElementSchema(input) {
22
+ const items = [];
23
+ const children = [];
24
+ for (const [name, element] of Object.entries(input)) {
25
+ items.push([name, compileElement(element)]);
26
+ for (const child of element.allowChildren ?? []) {
27
+ children.push({ parent: name, child });
28
+ }
29
+ }
30
+ return { items, children };
31
+ }
32
+ function compileElement({ type, isInline, allowIn, allowAttributes }) {
33
+ // Where the element is allowed: the places of its type, or the given ones.
34
+ const places = (defaultPlaces) => allowIn ? { allowIn } : { allowWhere: defaultPlaces };
35
+ const attributes = allowAttributes ? { allowAttributes } : {};
36
+ if (type === 'empty' && isInline) {
37
+ return { inheritTypesFrom: '$inlineObject', allowAttributesOf: '$text', ...places('$text'), ...attributes };
38
+ }
39
+ if (type === 'empty') {
40
+ return { inheritTypesFrom: '$blockObject', ...places('$block'), ...attributes };
41
+ }
42
+ if (type === 'block' && isInline) {
43
+ return {
44
+ isInline: true,
45
+ allowContentOf: '$block',
46
+ allowAttributesOf: '$text',
47
+ ...places('$text'),
48
+ ...attributes
49
+ };
50
+ }
51
+ if (type === 'block') {
52
+ return { inheritTypesFrom: '$block', allowContentOf: '$block', ...places('$block'), ...attributes };
53
+ }
54
+ return {
55
+ allowContentOf: '$container',
56
+ ...(isInline ? { isInline: true, ...places('$text') } : places('$block')),
57
+ ...attributes
58
+ };
59
+ }
60
+ //# sourceMappingURL=compileElementSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileElementSchema.js","sourceRoot":"","sources":["../../src/definition/compileElementSchema.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAyB;IAC7D,MAAM,KAAK,GAA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AAQ,EAAE,CAAC;QAClC,OAAO;YACN,QAAQ,EAAE,IAAI;YACd,cAAc,EAAE,QAAQ;YACxB,iBAAiB,EAAE,OAAO;YAC1B,GAAG,MAAM,CAAC,OAAO,CAAC;YAClB,GAAG,UAAU;SACb,CAAC;IACH,CAAC;IAED,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACtB,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC;IACrG,CAAC;IAED,OAAO;QACN,cAAc,EAAE,YAAY;QAC5B,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzE,GAAG,UAAU;KACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ElementSchemaIssue } from './types.js';
2
+ /**
3
+ * Thrown when the element schema is not valid. It lists all the problems, and has them in {@link issues}.
4
+ */
5
+ export default class ElementSchemaError extends Error {
6
+ /**
7
+ * The problems of the schema.
8
+ */
9
+ readonly issues: readonly ElementSchemaIssue[];
10
+ constructor(issues: readonly ElementSchemaIssue[]);
11
+ }
12
+ //# sourceMappingURL=elementSchemaError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementSchemaError.d.ts","sourceRoot":"","sources":["../../src/definition/elementSchemaError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK;IACpD;;OAEG;IACH,SAAgB,MAAM,EAAE,SAAS,kBAAkB,EAAE,CAAC;gBAE1C,MAAM,EAAE,SAAS,kBAAkB,EAAE;CASjD"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Thrown when the element schema is not valid. It lists all the problems, and has them in {@link issues}.
3
+ */
4
+ export default class ElementSchemaError extends Error {
5
+ /**
6
+ * The problems of the schema.
7
+ */
8
+ issues;
9
+ constructor(issues) {
10
+ super(`The element schema is not valid (${String(issues.length)} ${issues.length === 1 ? 'problem' : 'problems'}):\n` +
11
+ issues.map(({ path, message }) => `- ${path ? `${path}: ` : ''}${message}`).join('\n'));
12
+ this.name = 'ElementSchemaError';
13
+ this.issues = issues;
14
+ }
15
+ }
16
+ //# sourceMappingURL=elementSchemaError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementSchemaError.js","sourceRoot":"","sources":["../../src/definition/elementSchemaError.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK;IACpD;;OAEG;IACa,MAAM,CAAgC;IAEtD,YAAY,MAAqC;QAChD,KAAK,CACJ,oCAAoC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,MAAM;YAC9G,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CACvF,CAAC;QAEF,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;CACD"}
@@ -0,0 +1,18 @@
1
+ import type { ElementSchemaKind } from './types.js';
2
+ /**
3
+ * Reports a problem of the schema, at the path.
4
+ */
5
+ export type Report = (path: string, message: string) => void;
6
+ export declare const ELEMENT_KEYS: string[];
7
+ export declare const ELEMENT_NAME: RegExp;
8
+ export declare const ATTRIBUTE_NAME: RegExp;
9
+ export declare const TAG_NAME: RegExp;
10
+ export declare function readKind(definition: Record<string, unknown>, path: string, report: Report): ElementSchemaKind | null;
11
+ /**
12
+ * Reads a list of names, and reports what is not a list of unique, non-empty strings. Returns the list, or
13
+ * `undefined` when it is missing.
14
+ */
15
+ export declare function readNames(definition: Record<string, unknown>, key: string, path: string, report: Report): string[] | undefined;
16
+ export declare function checkKeys(object: Record<string, unknown>, allowed: readonly string[], path: string, report: Report): void;
17
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
18
+ //# sourceMappingURL=readDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readDefinition.d.ts","sourceRoot":"","sources":["../../src/definition/readDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGpD;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAG7D,eAAO,MAAM,YAAY,UAAoF,CAAC;AAE9G,eAAO,MAAM,YAAY,QAAwB,CAAC;AAClD,eAAO,MAAM,cAAc,QAAuB,CAAC;AACnD,eAAO,MAAM,QAAQ,QAAkC,CAAC;AAExD,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAuBpH;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACxB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACZ,MAAM,EAAE,GAAG,SAAS,CA4BtB;AAED,wBAAgB,SAAS,CACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACZ,IAAI,CASN;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE"}
@@ -0,0 +1,60 @@
1
+ import { suggest } from './suggest.js';
2
+ const TYPES = ['empty', 'block', 'container'];
3
+ export const ELEMENT_KEYS = ['type', 'isInline', 'allowChildren', 'allowIn', 'allowAttributes', 'editingTag'];
4
+ export const ELEMENT_NAME = /^[a-z][A-Za-z0-9]*$/;
5
+ export const ATTRIBUTE_NAME = /^[A-Za-z][\w.:-]*$/;
6
+ export const TAG_NAME = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
7
+ export function readKind(definition, path, report) {
8
+ const { type, isInline } = definition;
9
+ if (isInline !== undefined && typeof isInline !== 'boolean') {
10
+ report(`${path}.isInline`, 'must be true or false.');
11
+ }
12
+ if (type === undefined) {
13
+ report(`${path}.type`, 'is required: "empty", "block" or "container".');
14
+ return null;
15
+ }
16
+ if (typeof type !== 'string' || !TYPES.includes(type)) {
17
+ report(`${path}.type`, `must be "empty", "block" or "container", not ${JSON.stringify(type)}${typeof type === 'string' ? suggest(type, TYPES) : ''}.`);
18
+ return null;
19
+ }
20
+ return { type: type, isInline: isInline === true };
21
+ }
22
+ /**
23
+ * Reads a list of names, and reports what is not a list of unique, non-empty strings. Returns the list, or
24
+ * `undefined` when it is missing.
25
+ */
26
+ export function readNames(definition, key, path, report) {
27
+ const value = definition[key];
28
+ if (value === undefined) {
29
+ return undefined;
30
+ }
31
+ if (!Array.isArray(value)) {
32
+ report(`${path}.${key}`, `must be an array of names, e.g. ["a", "b"].`);
33
+ return undefined;
34
+ }
35
+ const names = [];
36
+ value.forEach((item, index) => {
37
+ const itemPath = `${path}.${key}[${String(index)}]`;
38
+ if (typeof item !== 'string' || !item) {
39
+ report(itemPath, 'must be a non-empty string.');
40
+ }
41
+ else if (names.includes(item)) {
42
+ report(itemPath, `"${item}" is listed twice.`);
43
+ }
44
+ else {
45
+ names.push(item);
46
+ }
47
+ });
48
+ return names;
49
+ }
50
+ export function checkKeys(object, allowed, path, report) {
51
+ for (const key of Object.keys(object)) {
52
+ if (!allowed.includes(key)) {
53
+ report(path ? `${path}.${key}` : key, `is not a known key${suggest(key, allowed)}. The keys are: ${allowed.map(name => `"${name}"`).join(', ')}.`);
54
+ }
55
+ }
56
+ }
57
+ export function isRecord(value) {
58
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
59
+ }
60
+ //# sourceMappingURL=readDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readDefinition.js","sourceRoot":"","sources":["../../src/definition/readDefinition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAOvC,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AAC9C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,iBAAiB,EAAE,YAAY,CAAC,CAAC;AAE9G,MAAM,CAAC,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAClD,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AACnD,MAAM,CAAC,MAAM,QAAQ,GAAG,+BAA+B,CAAC;AAExD,MAAM,UAAU,QAAQ,CAAC,UAAmC,EAAE,IAAY,EAAE,MAAc;IACzF,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC;IAEtC,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC7D,MAAM,CAAC,GAAG,IAAI,WAAW,EAAE,wBAAwB,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,CAAC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;QACjD,CAAC;aAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,MAAM,CAAC,QAAQ,EAAE,IAAI,IAAI,oBAAoB,CAAC,CAAC;QAChD,CAAC;aAAM,CAAC;YACP,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,SAAS,CACxB,MAA+B,EAC/B,OAA0B,EAC1B,IAAY,EACZ,MAAc;IAEd,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,CACL,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAC7B,qBAAqB,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,mBAAmB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC3G,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns ` Did you mean "x"?` for the closest candidate, when it is close enough to be a typo.
3
+ */
4
+ export declare function suggest(name: string, candidates: readonly string[]): string;
5
+ //# sourceMappingURL=suggest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../src/definition/suggest.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAc3E"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Returns ` Did you mean "x"?` for the closest candidate, when it is close enough to be a typo.
3
+ */
4
+ export function suggest(name, candidates) {
5
+ let best;
6
+ let bestDistance = 3;
7
+ for (const candidate of candidates) {
8
+ const distance = editDistance(name.toLowerCase(), candidate.toLowerCase());
9
+ if (distance < bestDistance) {
10
+ best = candidate;
11
+ bestDistance = distance;
12
+ }
13
+ }
14
+ return best ? ` (did you mean "${best}"?)` : '';
15
+ }
16
+ function editDistance(a, b) {
17
+ let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
18
+ for (let i = 1; i <= a.length; i++) {
19
+ const current = [i];
20
+ for (let j = 1; j <= b.length; j++) {
21
+ current[j] = Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, (previous[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1));
22
+ }
23
+ previous = current;
24
+ }
25
+ return previous[b.length] ?? 0;
26
+ }
27
+ //# sourceMappingURL=suggest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggest.js","sourceRoot":"","sources":["../../src/definition/suggest.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,UAA6B;IAClE,IAAI,IAAwB,CAAC;IAC7B,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC;QAE3E,IAAI,QAAQ,GAAG,YAAY,EAAE,CAAC;YAC7B,IAAI,GAAG,SAAS,CAAC;YACjB,YAAY,GAAG,QAAQ,CAAC;QACzB,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC,CAAC,CAAC,mBAAmB,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACjD,CAAC;AAED,SAAS,YAAY,CAAC,CAAS,EAAE,CAAS;IACzC,IAAI,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IAEzE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;QAEpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CACpB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EACtB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EACzB,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACxD,CAAC;QACH,CAAC;QAED,QAAQ,GAAG,OAAO,CAAC;IACpB,CAAC;IAED,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * The kinds of elements of an element schema:
3
+ *
4
+ * * `empty`: has no content, like an image or a line break. It is an object: selected as a whole.
5
+ * * `block`: can contain text and inline elements, like a paragraph or a heading. With `isInline`, it is an inline
6
+ * element with text, like a bold with an `id`.
7
+ *
8
+ * * `container`: cannot contain text; holds blocks, empty block elements and other containers, like a block quote or a
9
+ * note.
10
+ *
11
+ * Every type can be inline (see {@link ElementSchemaElement#isInline}): the type says what the element holds, `isInline`
12
+ * where and how it is laid out. Inline elements are allowed only in blocks.
13
+ */
14
+ export type ElementSchemaType = 'empty' | 'block' | 'container';
15
+ /**
16
+ * The kind of an element: what it is, and whether it is inline: laid out in a line with its siblings, instead of on a
17
+ * line of its own. Any type can be inline.
18
+ */
19
+ export interface ElementSchemaKind {
20
+ type: ElementSchemaType;
21
+ isInline: boolean;
22
+ }
23
+ /**
24
+ * The definition of one element of an element schema.
25
+ */
26
+ export interface ElementSchemaElement {
27
+ /**
28
+ * What the element is: `'empty'`, `'block'` or `'container'`.
29
+ */
30
+ type: ElementSchemaType;
31
+ /**
32
+ * Whether the element is inline: it is about the position and the layout of the element, not about text. An inline
33
+ * element is laid out in a line with its siblings, where a block-level one has a line of its own. Any type can be:
34
+ *
35
+ * * `empty`: like an inline image, or a line break;
36
+ * * `block`: an element with text in a line of text, like a bold that is an element, with attributes;
37
+ * * `container`: a box that is not typable, in a line with other boxes, e.g. several in a block.
38
+ *
39
+ * Inline elements are allowed only in blocks: by default, where text is. A block holds text and any number of inline
40
+ * elements; containers and the root hold no inline elements. Default: `false`.
41
+ */
42
+ isInline?: boolean;
43
+ /**
44
+ * The elements allowed inside this one, in addition to what its type allows: names of elements of the schema, or of
45
+ * elements of other plugins, and `'$text'`. As in CKEditor's `allowChildren`.
46
+ *
47
+ * What a type allows by default: a `block` has text and inline elements; a `container` has blocks, containers and
48
+ * `empty` block-level elements.
49
+ */
50
+ allowChildren?: string[];
51
+ /**
52
+ * The elements this one is allowed in, in addition to what its type allows: names of elements, and `'$root'`. As in
53
+ * CKEditor's `allowIn`.
54
+ *
55
+ * Unlike in CKEditor, when it is given it **replaces** the default places (a block-level element is allowed in the
56
+ * root and in containers; an inline element, where text is), so that an element can be restricted to its parent,
57
+ * e.g. a row to a table.
58
+ */
59
+ allowIn?: string[];
60
+ /**
61
+ * The attributes the element can have, as in CKEditor's `allowAttributes`.
62
+ */
63
+ allowAttributes?: string[];
64
+ /**
65
+ * The tag of the element in the editing view, e.g. `'section'`, when the converters of the schema are on (the
66
+ * `elementSchemaConverters` option). The data has `div` or `span`, whatever it is. Default: the tag of the data.
67
+ */
68
+ editingTag?: string;
69
+ }
70
+ /**
71
+ * An element schema: the definitions of the elements, by name.
72
+ */
73
+ export type ElementSchemaDefinition = Record<string, ElementSchemaElement>;
74
+ /**
75
+ * What the `elementSchema` option accepts: an {@link ElementSchemaDefinition}, or a JSON file imported as it is, whose
76
+ * strings TypeScript does not know are the allowed ones, and whose arrays are not known to be mutable. Either way, it is
77
+ * validated when the editor is created.
78
+ */
79
+ export type ElementSchemaInput = Record<string, {
80
+ [Key in keyof ElementSchemaElement]: Key extends 'type' ? string : ElementSchemaElement[Key] extends string[] | undefined ? readonly string[] | undefined : ElementSchemaElement[Key];
81
+ }>;
82
+ /**
83
+ * A problem of an element schema.
84
+ */
85
+ export interface ElementSchemaIssue {
86
+ /**
87
+ * Where the problem is, e.g. `note.allowChildren[1]`.
88
+ */
89
+ path: string;
90
+ /**
91
+ * What is wrong, and what to do about it.
92
+ */
93
+ message: string;
94
+ }
95
+ /**
96
+ * The options of {@link validateElementSchema}.
97
+ */
98
+ export interface ValidateElementSchemaOptions {
99
+ /**
100
+ * Elements that exist outside the schema, e.g. `paragraph` of the `Paragraph` plugin, by name. The schema can refer to
101
+ * them, but cannot declare them. Without them, the schema can refer only to its own elements.
102
+ */
103
+ external?: Readonly<Record<string, ElementSchemaKind>>;
104
+ }
105
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/definition/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,iBAAiB,GAAG,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-0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/definition/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import type { ElementSchemaIssue, ValidateElementSchemaOptions } from './types.js';
2
+ /**
3
+ * Checks an element schema, so that it is not contradictory, and returns the problems. An empty array means that the
4
+ * schema is valid.
5
+ *
6
+ * The schema is rejected when it:
7
+ *
8
+ * * is not of the shape {@link ElementSchemaDefinition}: an object of elements, by name; has keys that are not part of
9
+ * it (typos are problems), or has values of the wrong type;
10
+ * * declares an element with an unknown `type`, or an `empty` element with `allowChildren`;
11
+ * * has attribute names that are not valid, or that differ only in case (HTML attribute names are not case sensitive),
12
+ * or an `editingTag` that is not the name of a tag;
13
+ * * refers to elements that do not exist (a name that is neither declared in the schema, nor in `external`), or lists the
14
+ * same name twice;
15
+ * * allows what its type cannot hold: text or an inline element in a container or in the root, a block-level (not inline)
16
+ * element in a block, or anything in an `empty` element, whichever side says it: `allowChildren` of the parent, or
17
+ * `allowIn` of the child.
18
+ *
19
+ * `isInline` is about the position and the layout of an element, so it is valid for every type: an inline element is
20
+ * laid out in a line with its siblings. Inline elements are allowed only in blocks, which can hold several of them,
21
+ * e.g. inline containers, or inline images between text.
22
+ *
23
+ * It does not need an editor. The editor of `ElementSchema` runs it with the elements of the other plugins as `external`.
24
+ */
25
+ export declare function validateElementSchema(input: unknown, { external }?: ValidateElementSchemaOptions): ElementSchemaIssue[];
26
+ //# sourceMappingURL=validateElementSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateElementSchema.d.ts","sourceRoot":"","sources":["../../src/definition/validateElementSchema.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAqB,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAEtG;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,OAAO,EACd,EAAE,QAAa,EAAE,GAAE,4BAAiC,GAClD,kBAAkB,EAAE,CAkKtB"}