postext 1.98.8 → 1.99.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.
Files changed (148) hide show
  1. package/dist/__tests__/bundle/bundle.test.js +19 -0
  2. package/dist/__tests__/bundle/bundle.test.js.map +1 -1
  3. package/dist/__tests__/bundle/join.test.d.ts +2 -0
  4. package/dist/__tests__/bundle/join.test.d.ts.map +1 -0
  5. package/dist/__tests__/bundle/join.test.js +182 -0
  6. package/dist/__tests__/bundle/join.test.js.map +1 -0
  7. package/dist/__tests__/color/inkFinishes.test.js +11 -2
  8. package/dist/__tests__/color/inkFinishes.test.js.map +1 -1
  9. package/dist/__tests__/comics/config.test.js +8 -0
  10. package/dist/__tests__/comics/config.test.js.map +1 -1
  11. package/dist/__tests__/hyphenation/exceptionsByLanguage.test.js +3 -3
  12. package/dist/__tests__/hyphenation/exceptionsByLanguage.test.js.map +1 -1
  13. package/dist/__tests__/hyphenation/exceptionsFile.test.js +3 -3
  14. package/dist/__tests__/hyphenation/exceptionsFile.test.js.map +1 -1
  15. package/dist/__tests__/hyphenation/greekHyphenation.test.d.ts +2 -0
  16. package/dist/__tests__/hyphenation/greekHyphenation.test.d.ts.map +1 -0
  17. package/dist/__tests__/hyphenation/greekHyphenation.test.js +87 -0
  18. package/dist/__tests__/hyphenation/greekHyphenation.test.js.map +1 -0
  19. package/dist/__tests__/hyphenation/hyphenationLocale.test.js +2 -2
  20. package/dist/__tests__/hyphenation/hyphenationLocale.test.js.map +1 -1
  21. package/dist/__tests__/hyphenation/passageLanguage.test.js +6 -6
  22. package/dist/__tests__/hyphenation/passageLanguage.test.js.map +1 -1
  23. package/dist/__tests__/locale/chineseLocale.test.js +2 -2
  24. package/dist/__tests__/locale/chineseLocale.test.js.map +1 -1
  25. package/dist/__tests__/numerals/europeanNumberWords.test.js +57 -0
  26. package/dist/__tests__/numerals/europeanNumberWords.test.js.map +1 -1
  27. package/dist/bundle/codec/plan.d.ts.map +1 -1
  28. package/dist/bundle/codec/plan.js +10 -3
  29. package/dist/bundle/codec/plan.js.map +1 -1
  30. package/dist/bundle/index.d.ts +1 -0
  31. package/dist/bundle/index.d.ts.map +1 -1
  32. package/dist/bundle/index.js +2 -0
  33. package/dist/bundle/index.js.map +1 -1
  34. package/dist/bundle/join/files.d.ts +72 -0
  35. package/dist/bundle/join/files.d.ts.map +1 -0
  36. package/dist/bundle/join/files.js +199 -0
  37. package/dist/bundle/join/files.js.map +1 -0
  38. package/dist/bundle/join/index.d.ts +8 -0
  39. package/dist/bundle/join/index.d.ts.map +1 -0
  40. package/dist/bundle/join/index.js +8 -0
  41. package/dist/bundle/join/index.js.map +1 -0
  42. package/dist/bundle/join/numbers.d.ts +27 -0
  43. package/dist/bundle/join/numbers.d.ts.map +1 -0
  44. package/dist/bundle/join/numbers.js +49 -0
  45. package/dist/bundle/join/numbers.js.map +1 -0
  46. package/dist/bundle/join/plan.d.ts +119 -0
  47. package/dist/bundle/join/plan.d.ts.map +1 -0
  48. package/dist/bundle/join/plan.js +256 -0
  49. package/dist/bundle/join/plan.js.map +1 -0
  50. package/dist/bundle/join/refs.d.ts +38 -0
  51. package/dist/bundle/join/refs.d.ts.map +1 -0
  52. package/dist/bundle/join/refs.js +163 -0
  53. package/dist/bundle/join/refs.js.map +1 -0
  54. package/dist/citations/bibtex.js +1 -1
  55. package/dist/citations/bibtex.js.map +1 -1
  56. package/dist/citations/html.d.ts.map +1 -1
  57. package/dist/citations/html.js +3 -1
  58. package/dist/citations/html.js.map +1 -1
  59. package/dist/color/finishes.d.ts.map +1 -1
  60. package/dist/color/finishes.js +15 -7
  61. package/dist/color/finishes.js.map +1 -1
  62. package/dist/comics/lettering/text.d.ts.map +1 -1
  63. package/dist/comics/lettering/text.js +2 -1
  64. package/dist/comics/lettering/text.js.map +1 -1
  65. package/dist/defaults/boxes/exercises.d.ts.map +1 -1
  66. package/dist/defaults/boxes/exercises.js +1 -0
  67. package/dist/defaults/boxes/exercises.js.map +1 -1
  68. package/dist/defaults/comics.d.ts +5 -3
  69. package/dist/defaults/comics.d.ts.map +1 -1
  70. package/dist/defaults/comics.js +14 -6
  71. package/dist/defaults/comics.js.map +1 -1
  72. package/dist/defaults/resources/resourceTypes.d.ts.map +1 -1
  73. package/dist/defaults/resources/resourceTypes.js +6 -0
  74. package/dist/defaults/resources/resourceTypes.js.map +1 -1
  75. package/dist/defaults/resources/tableStyle.d.ts.map +1 -1
  76. package/dist/defaults/resources/tableStyle.js +1 -0
  77. package/dist/defaults/resources/tableStyle.js.map +1 -1
  78. package/dist/defaults/structure/indexConfig.d.ts.map +1 -1
  79. package/dist/defaults/structure/indexConfig.js +1 -0
  80. package/dist/defaults/structure/indexConfig.js.map +1 -1
  81. package/dist/design/layout/slot.d.ts.map +1 -1
  82. package/dist/design/layout/slot.js +2 -1
  83. package/dist/design/layout/slot.js.map +1 -1
  84. package/dist/design/layout/text.d.ts.map +1 -1
  85. package/dist/design/layout/text.js +2 -1
  86. package/dist/design/layout/text.js.map +1 -1
  87. package/dist/hyphenation/hyphenate.d.ts.map +1 -1
  88. package/dist/hyphenation/hyphenate.js +14 -0
  89. package/dist/hyphenation/hyphenate.js.map +1 -1
  90. package/dist/hyphenation/locale.d.ts +2 -1
  91. package/dist/hyphenation/locale.d.ts.map +1 -1
  92. package/dist/hyphenation/locale.js +11 -3
  93. package/dist/hyphenation/locale.js.map +1 -1
  94. package/dist/numerals/greekNumberWords.d.ts +30 -0
  95. package/dist/numerals/greekNumberWords.d.ts.map +1 -0
  96. package/dist/numerals/greekNumberWords.js +113 -0
  97. package/dist/numerals/greekNumberWords.js.map +1 -0
  98. package/dist/numerals/numberWords.d.ts +7 -6
  99. package/dist/numerals/numberWords.d.ts.map +1 -1
  100. package/dist/numerals/numberWords.js +27 -11
  101. package/dist/numerals/numberWords.js.map +1 -1
  102. package/dist/parse/citations.js +7 -7
  103. package/dist/parse/citations.js.map +1 -1
  104. package/dist/pipeline/blocks/buildBlockKind.d.ts +1 -1
  105. package/dist/pipeline/blocks/buildBlockKind.d.ts.map +1 -1
  106. package/dist/pipeline/blocks/buildBlockKind.js +3 -2
  107. package/dist/pipeline/blocks/buildBlockKind.js.map +1 -1
  108. package/dist/pipeline/contents/indexDirective/tree.d.ts.map +1 -1
  109. package/dist/pipeline/contents/indexDirective/tree.js +1 -0
  110. package/dist/pipeline/contents/indexDirective/tree.js.map +1 -1
  111. package/dist/pipeline/pages/headerFooter/slotLayout.d.ts.map +1 -1
  112. package/dist/pipeline/pages/headerFooter/slotLayout.js +3 -2
  113. package/dist/pipeline/pages/headerFooter/slotLayout.js.map +1 -1
  114. package/dist/pipeline/references/crossRefs.d.ts.map +1 -1
  115. package/dist/pipeline/references/crossRefs.js +3 -1
  116. package/dist/pipeline/references/crossRefs.js.map +1 -1
  117. package/dist/pipeline/resources/resourceLayout/refSpans.d.ts.map +1 -1
  118. package/dist/pipeline/resources/resourceLayout/refSpans.js +2 -1
  119. package/dist/pipeline/resources/resourceLayout/refSpans.js.map +1 -1
  120. package/dist/pipeline/text/chips.d.ts.map +1 -1
  121. package/dist/pipeline/text/chips.js +3 -2
  122. package/dist/pipeline/text/chips.js.map +1 -1
  123. package/dist/pipeline/text/greekCaps.d.ts +25 -0
  124. package/dist/pipeline/text/greekCaps.d.ts.map +1 -0
  125. package/dist/pipeline/text/greekCaps.js +73 -0
  126. package/dist/pipeline/text/greekCaps.js.map +1 -0
  127. package/dist/production/coverLabels.d.ts.map +1 -1
  128. package/dist/production/coverLabels.js +1 -0
  129. package/dist/production/coverLabels.js.map +1 -1
  130. package/dist/types/comics.d.ts +1 -1
  131. package/dist/types/comics.d.ts.map +1 -1
  132. package/dist/types/text/locale.d.ts +1 -1
  133. package/dist/types/text/locale.d.ts.map +1 -1
  134. package/dist/word/semantic/design/heading.js +2 -2
  135. package/dist/word/semantic/design/heading.js.map +1 -1
  136. package/dist/word/semantic/exercises/exerciseBody.js +1 -0
  137. package/dist/word/semantic/exercises/exerciseBody.js.map +1 -1
  138. package/dist/word/semantic/layout/pageSpan.d.ts.map +1 -1
  139. package/dist/word/semantic/layout/pageSpan.js +14 -3
  140. package/dist/word/semantic/layout/pageSpan.js.map +1 -1
  141. package/dist/word/semantic/media/pages.d.ts.map +1 -1
  142. package/dist/word/semantic/media/pages.js +1 -0
  143. package/dist/word/semantic/media/pages.js.map +1 -1
  144. package/dist/word/template.js +3 -3
  145. package/dist/word/template.js.map +1 -1
  146. package/dist/word/word.test.js +2 -0
  147. package/dist/word/word.test.js.map +1 -1
  148. package/package.json +3 -1
@@ -0,0 +1,8 @@
1
+ // Chapters of another book joined to this one (#1727): the planner the
2
+ // Sandbox follows, its application to a bundle's files (the CLI's
3
+ // `postext join`), and the chapter numbers both count by.
4
+ export { chapterNumbers, chapterFileNumbers } from './numbers.js';
5
+ export { bookNumbers, partChapters, proposeChoices, replacedChapter, choiceProblems, broughtResources, resourceClashes, renameProblems, withChapterNumber, planPartJoin, } from './plan.js';
6
+ export { inspectBundleJoin, joinBundleFiles } from './files.js';
7
+ export { resourceIdRanges, renameResourceInText, renameResourceInResources, withResourceRenamed, resourcesNamedIn, configPathsNaming } from './refs.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/bundle/join/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,kEAAkE;AAClE,0DAA0D;AAE1D,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EACL,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAC7H,iBAAiB,EAAE,YAAY,GAChC,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { type ContentBlock } from '../../parse/index.js';
2
+ import type { HeadingCounters, PostextConfig } from '../../types.js';
3
+ /** A chapter's parsed body: its blocks, with `offset` the index in the
4
+ * chapter's text where the body (after any front matter) starts. */
5
+ export interface ChapterBody {
6
+ blocks: ContentBlock[];
7
+ offset: number;
8
+ numbered: (b: ContentBlock) => boolean;
9
+ }
10
+ /** `markdown` parsed as the layout parses a chapter under `config`. */
11
+ export declare function chapterBody(markdown: string, config?: PostextConfig): ChapterBody;
12
+ /** The chapter's first level-1 heading that the layout numbers. */
13
+ export declare function numberedChapterHeading(body: ChapterBody): ContentBlock | undefined;
14
+ /**
15
+ * Each chapter's number as the layout counts it, or `null` for a chapter
16
+ * with no numbered level-1 heading (a cover, a prologue): such a chapter
17
+ * has no number and leaves the count where it was. `start` is the bundle's
18
+ * `start.headings`, for a bundle that holds part of a longer book.
19
+ */
20
+ export declare function chapterNumbers(chapters: readonly {
21
+ markdown: string;
22
+ }[], config?: PostextConfig, start?: Partial<HeadingCounters>): (number | null)[];
23
+ /** The numbers chapter files are named after: a chapter's own number, or,
24
+ * for one with none, the number of the chapter before it (0 before the
25
+ * first), so that `00-cover.md`, `01-…`, `09-…` read in book order. */
26
+ export declare function chapterFileNumbers(numbers: readonly (number | null)[]): number[];
27
+ //# sourceMappingURL=numbers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../../src/bundle/join/numbers.ts"],"names":[],"mappings":"AAOA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAM5E,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAErE;qEACqE;AACrE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC;CACxC;AAED,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,WAAW,CAMrF;AAED,mEAAmE;AACnE,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,GAAG,SAAS,CAElF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,EACzC,MAAM,CAAC,EAAE,aAAa,EACtB,KAAK,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAC/B,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CASnB;AAED;;wEAEwE;AACxE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,CAGhF"}
@@ -0,0 +1,49 @@
1
+ // The number the book counts each chapter by, as the layout counts it: the
2
+ // level-1 counter at the chapter's first numbered level-1 heading, carried
3
+ // from chapter to chapter, from the bundle's `start` on. A heading whose
4
+ // style says `numbered: false` (a prologue, an appendix set apart) counts
5
+ // for nothing, and `{startAt=N}` sets the counter.
6
+ import { extractFrontmatter } from '../../parse/frontmatter.js';
7
+ import { parseMarkdownMemo } from '../../parse/index.js';
8
+ import { chapterConfigOf } from '../../defaults/chapterStyles.js';
9
+ import { resolveAllConfig } from '../../pipeline/config.js';
10
+ import { codeParseOptions } from '../../pipeline/code/codeBlocks.js';
11
+ import { headingIsNumbered } from '../../pipeline/sections/headingStyles.js';
12
+ import { computeHeadingContext } from '../../pipeline/resources/resourceNumbering.js';
13
+ /** `markdown` parsed as the layout parses a chapter under `config`. */
14
+ export function chapterBody(markdown, config = {}) {
15
+ const own = chapterConfigOf(config, markdown);
16
+ const resolved = resolveAllConfig(own);
17
+ const body = extractFrontmatter(markdown).content;
18
+ const offset = markdown.endsWith(body) ? markdown.length - body.length : 0;
19
+ return { blocks: parseMarkdownMemo(body, codeParseOptions(resolved)), offset, numbered: (b) => headingIsNumbered(b, resolved) };
20
+ }
21
+ /** The chapter's first level-1 heading that the layout numbers. */
22
+ export function numberedChapterHeading(body) {
23
+ return body.blocks.find((b) => b.type === 'heading' && b.level === 1 && body.numbered(b));
24
+ }
25
+ /**
26
+ * Each chapter's number as the layout counts it, or `null` for a chapter
27
+ * with no numbered level-1 heading (a cover, a prologue): such a chapter
28
+ * has no number and leaves the count where it was. `start` is the bundle's
29
+ * `start.headings`, for a bundle that holds part of a longer book.
30
+ */
31
+ export function chapterNumbers(chapters, config, start) {
32
+ let before = start ? { h1: 0, h2: 0, h3: 0, h4: 0, h5: 0, h6: 0, ...start } : undefined;
33
+ return chapters.map((c) => {
34
+ const body = chapterBody(c.markdown, config);
35
+ const context = computeHeadingContext(body.blocks, before, body.numbered);
36
+ const at = body.blocks.findIndex((b) => b.type === 'heading' && b.level === 1 && body.numbered(b));
37
+ if (context.length > 0)
38
+ before = context[context.length - 1];
39
+ return at >= 0 ? context[at].h1 : null;
40
+ });
41
+ }
42
+ /** The numbers chapter files are named after: a chapter's own number, or,
43
+ * for one with none, the number of the chapter before it (0 before the
44
+ * first), so that `00-cover.md`, `01-…`, `09-…` read in book order. */
45
+ export function chapterFileNumbers(numbers) {
46
+ let last = 0;
47
+ return numbers.map((n) => (last = n ?? last));
48
+ }
49
+ //# sourceMappingURL=numbers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../../src/bundle/join/numbers.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,mDAAmD;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAqB,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,iCAA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Resource } from '../../types.js';
2
+ import { type ResourceRefFields } from './refs.js';
3
+ /** What becomes of one chapter of the part. */
4
+ export type PartAction = 'add' | 'replace' | 'skip';
5
+ export interface PartChoice {
6
+ action: PartAction;
7
+ /** The chapter's number in the book: where it is added, or which of the
8
+ * book's chapters it replaces. */
9
+ number: number;
10
+ }
11
+ /** One side of a join: the book, or the part joined to it. */
12
+ export interface JoinSide<R extends ResourceRefFields = Resource> {
13
+ chapters: readonly {
14
+ title: string;
15
+ markdown: string;
16
+ }[];
17
+ resources: readonly R[];
18
+ config: PostextConfig;
19
+ /** The bundle's `start.headings`, for one that holds part of a longer book. */
20
+ start?: Partial<HeadingCounters>;
21
+ }
22
+ export interface PartChapterInfo {
23
+ /** Its position in the part (from 0). */
24
+ index: number;
25
+ title: string;
26
+ /** The number the layout gives it, or null when it has no numbered
27
+ * level-1 heading (a cover, a prologue). */
28
+ number: number | null;
29
+ /** The part's resources it uses, its own and the ones they name. */
30
+ resources: string[];
31
+ }
32
+ export type PartProblem =
33
+ /** A replace with no chapter of that number in the book. */
34
+ 'noSuchChapter'
35
+ /** Two chapters on one number, or an add on a number the book has. */
36
+ | 'sameNumber'
37
+ /** A number below 1, or not a whole number. */
38
+ | 'badNumber'
39
+ /** A replace by a chapter with no numbered heading: the chapters after
40
+ * it would lose a number. */
41
+ | 'unnumbered';
42
+ /** The numbers the book counts its chapters by (null: no number). */
43
+ export declare function bookNumbers(book: Pick<JoinSide<ResourceRefFields>, 'chapters' | 'config' | 'start'>): (number | null)[];
44
+ /** The part's chapters, with their numbers and the resources they use. */
45
+ export declare function partChapters<R extends ResourceRefFields>(part: JoinSide<R>): PartChapterInfo[];
46
+ /** What is proposed for each chapter of the part: to take the place of the
47
+ * book's chapter with its number when the book has one, else to be added
48
+ * at its place. A chapter with no number is left out. */
49
+ export declare function proposeChoices(book: JoinSide<ResourceRefFields>, part: JoinSide<ResourceRefFields>): PartChoice[];
50
+ /** The book's chapter a choice replaces (its position), or -1. */
51
+ export declare function replacedChapter(book: JoinSide<ResourceRefFields>, choice: PartChoice): number;
52
+ /** What is wrong with the choices (by the part's chapter, from 0), or an
53
+ * empty list. One problem per chapter, the first that applies. */
54
+ export declare function choiceProblems(book: JoinSide<ResourceRefFields>, part: JoinSide<ResourceRefFields>, choices: readonly PartChoice[]): {
55
+ chapter: number;
56
+ problem: PartProblem;
57
+ }[];
58
+ /** The part's resources the chosen chapters bring. */
59
+ export declare function broughtResources<R extends ResourceRefFields>(part: JoinSide<R>, choices: readonly PartChoice[]): R[];
60
+ /** The resources the part brings that are named as one of the book's which
61
+ * stays in use, with the name proposed for each. A resource only the
62
+ * replaced chapters use is not a clash: the part's takes its place. */
63
+ export declare function resourceClashes(book: JoinSide<ResourceRefFields>, part: JoinSide<ResourceRefFields>, choices: readonly PartChoice[]): {
64
+ id: string;
65
+ rename: string;
66
+ }[];
67
+ /** The clashing resources whose new name (`renames`, else the proposed one)
68
+ * cannot be used: not an id every reference reads, or taken by another
69
+ * resource of the book or the part, or given to two of them. */
70
+ export declare function renameProblems(book: JoinSide<ResourceRefFields>, part: JoinSide<ResourceRefFields>, choices: readonly PartChoice[], renames?: Readonly<Record<string, string>>): string[];
71
+ /** `markdown` with its first numbered level-1 heading given the number `n`
72
+ * (`{startAt=n}`): the attribute is set, or added to the heading's
73
+ * attributes, or given them. Front matter and code blocks are never taken
74
+ * for the heading (the parser finds it). A chapter with no such heading is
75
+ * left as it is. */
76
+ export declare function withChapterNumber(markdown: string, n: number, config?: PostextConfig): string;
77
+ export type PartStep =
78
+ /** The book's chapter at `at` (its position before the join) gets the
79
+ * part's text and title; it keeps its identity (id, history). */
80
+ {
81
+ kind: 'replace';
82
+ at: number;
83
+ part: number;
84
+ title: string;
85
+ markdown: string;
86
+ number: number;
87
+ }
88
+ /** A new chapter at `index`, counting the chapters added before it. */
89
+ | {
90
+ kind: 'add';
91
+ index: number;
92
+ part: number;
93
+ title: string;
94
+ markdown: string;
95
+ number: number;
96
+ };
97
+ export interface PartJoinPlan<R extends ResourceRefFields = Resource> {
98
+ /** In the order to apply them. */
99
+ steps: PartStep[];
100
+ /** The part's resources, renamed, to add or put in place of the book's
101
+ * with the same id. */
102
+ resources: R[];
103
+ /** Clashing resources and the id each takes. */
104
+ renamed: {
105
+ from: string;
106
+ to: string;
107
+ }[];
108
+ /** The book's font families with the part's missing ones added, when it
109
+ * lacks any; undefined when nothing is missing. */
110
+ customFonts?: CustomFontFamily[];
111
+ /** The part's families the book did not have. */
112
+ fontsAdded: string[];
113
+ }
114
+ /** What to change in the book to join the chosen chapters of the part, the
115
+ * clashing resources renamed as `renames` says (a clash it leaves out
116
+ * takes the proposed name). Throws when the choices or the names do not
117
+ * fit (see {@link choiceProblems}, {@link renameProblems}). */
118
+ export declare function planPartJoin<R extends ResourceRefFields>(book: JoinSide<ResourceRefFields>, part: JoinSide<R>, choices: readonly PartChoice[], renames?: Readonly<Record<string, string>>): PartJoinPlan<R>;
119
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../../src/bundle/join/plan.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjG,OAAO,EAAyG,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE1J,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;AAEpD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,CAAC;IACnB;uCACmC;IACnC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,8DAA8D;AAC9D,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,iBAAiB,GAAG,QAAQ;IAC9D,QAAQ,EAAE,SAAS;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC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IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElG,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,iBAAiB,GAAG,QAAQ;IAClE,kCAAkC;IAClC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB;4BACwB;IACxB,SAAS,EAAE,CAAC,EAAE,CAAC;IACf,gDAAgD;IAChD,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACxC;wDACoD;IACpD,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACjC,iDAAiD;IACjD,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;gEAGgE;AAChE,wBAAgB,YAAY,CAAC,CAAC,SAAS,iBAAiB,EACtD,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,EACjC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACjB,OAAO,EAAE,SAAS,UAAU,EAAE,EAC9B,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,GAC7C,YAAY,CAAC,CAAC,CAAC,CAiEjB"}
@@ -0,0 +1,256 @@
1
+ // Chapters of another book joined to this one (#1727): a part of the book
2
+ // converted or edited apart (a module of a course, a few chapters laid out
3
+ // elsewhere) that belongs in it. Each chapter of the part keeps the number
4
+ // the layout gives it, and is added at its place among the book's chapters
5
+ // or takes the place of the book's chapter with that number, as the reader
6
+ // chooses. The resources its text uses come along; one named as a resource
7
+ // the book keeps using is renamed, with every reference to it. The design
8
+ // stays the book's: of the part's configuration only the font families the
9
+ // book lacks are taken.
10
+ //
11
+ // Pure: it works on texts and records and says what to change. The Sandbox
12
+ // applies the plan to its state, `joinBundleFiles` to a bundle's files.
13
+ import { chapterBody, chapterNumbers, chapterFileNumbers, numberedChapterHeading } from './numbers.js';
14
+ import { configPathsNaming, renameResourceInResources, resourceIdRanges, resourcesNamedIn, withResourceRenamed } from './refs.js';
15
+ /** The resource ids a join can give: the forms every reference reads bare
16
+ * (`:ref{#id}`, `art=id`). */
17
+ const RESOURCE_ID_RE = /^[\p{L}\p{N}_][\p{L}\p{N}_.:-]*$/u;
18
+ /** The numbers the book counts its chapters by (null: no number). */
19
+ export function bookNumbers(book) {
20
+ return chapterNumbers(book.chapters, book.config, book.start);
21
+ }
22
+ /** The ids of the part's resources that `ids` bring with them: the ones
23
+ * their captions, notes and table cells name, and so on. */
24
+ function withNamedResources(ids, resources) {
25
+ const byId = new Map(resources.map((r) => [r.id, r]));
26
+ const wanted = new Set();
27
+ const queue = [...ids];
28
+ while (queue.length > 0) {
29
+ const id = queue.pop();
30
+ if (wanted.has(id) || !byId.has(id))
31
+ continue;
32
+ wanted.add(id);
33
+ const r = byId.get(id);
34
+ const texts = [r.caption, r.note, ...(r.table?.model.rows.flat().map((c) => c.content) ?? [])].filter((t) => !!t);
35
+ for (const text of texts)
36
+ queue.push(...resourcesNamedIn(text, byId.keys()));
37
+ for (const cell of r.table?.model.rows.flat() ?? [])
38
+ if (cell.image?.resourceId)
39
+ queue.push(cell.image.resourceId);
40
+ }
41
+ return wanted;
42
+ }
43
+ /** The part's chapters, with their numbers and the resources they use. */
44
+ export function partChapters(part) {
45
+ const numbers = chapterNumbers(part.chapters, part.config, part.start);
46
+ const ids = part.resources.map((r) => r.id);
47
+ return part.chapters.map((c, index) => {
48
+ const used = withNamedResources(resourcesNamedIn(c.markdown, ids), part.resources);
49
+ return { index, title: c.title, number: numbers[index], resources: ids.filter((id) => used.has(id)) };
50
+ });
51
+ }
52
+ /** What is proposed for each chapter of the part: to take the place of the
53
+ * book's chapter with its number when the book has one, else to be added
54
+ * at its place. A chapter with no number is left out. */
55
+ export function proposeChoices(book, part) {
56
+ const numbers = new Set(bookNumbers(book).filter((n) => n !== null));
57
+ return partChapters(part).map((c) => (c.number === null
58
+ ? { action: 'skip', number: 1 }
59
+ : { action: numbers.has(c.number) ? 'replace' : 'add', number: c.number }));
60
+ }
61
+ /** The book's chapter a choice replaces (its position), or -1. */
62
+ export function replacedChapter(book, choice) {
63
+ return choice.action === 'replace' ? bookNumbers(book).indexOf(choice.number) : -1;
64
+ }
65
+ /** What is wrong with the choices (by the part's chapter, from 0), or an
66
+ * empty list. One problem per chapter, the first that applies. */
67
+ export function choiceProblems(book, part, choices) {
68
+ const problems = [];
69
+ const numbers = new Set(bookNumbers(book).filter((n) => n !== null));
70
+ const own = chapterNumbers(part.chapters, part.config, part.start);
71
+ const seen = new Set();
72
+ choices.forEach((c, i) => {
73
+ if (c.action === 'skip')
74
+ return;
75
+ let problem;
76
+ if (!Number.isInteger(c.number) || c.number < 1)
77
+ problem = 'badNumber';
78
+ else if (seen.has(c.number))
79
+ problem = 'sameNumber';
80
+ else if (c.action === 'replace' && !numbers.has(c.number))
81
+ problem = 'noSuchChapter';
82
+ else if (c.action === 'replace' && own[i] === null)
83
+ problem = 'unnumbered';
84
+ else if (c.action === 'add' && numbers.has(c.number))
85
+ problem = 'sameNumber';
86
+ if (Number.isInteger(c.number))
87
+ seen.add(c.number);
88
+ if (problem)
89
+ problems.push({ chapter: i, problem });
90
+ });
91
+ return problems;
92
+ }
93
+ /** The part's resources the chosen chapters bring. */
94
+ export function broughtResources(part, choices) {
95
+ const ids = part.resources.map((r) => r.id);
96
+ const direct = part.chapters.flatMap((c, i) => (choices[i] && choices[i].action !== 'skip' ? resourcesNamedIn(c.markdown, ids) : []));
97
+ const wanted = withNamedResources(direct, part.resources);
98
+ return part.resources.filter((r) => wanted.has(r.id));
99
+ }
100
+ /** `id`, or `id-2`, `-3`… when taken. */
101
+ function freeId(id, taken) {
102
+ if (!taken.has(id))
103
+ return id;
104
+ let n = 2;
105
+ while (taken.has(`${id}-${n}`))
106
+ n++;
107
+ return `${id}-${n}`;
108
+ }
109
+ /** Whether the book keeps using its resource `id` once the chapters at
110
+ * `replaced` are gone: in another chapter, in its design (a callout's
111
+ * icon, a page template's picture), or in another of its resources that
112
+ * the part does not bring in its place. */
113
+ function bookKeepsUsing(book, id, replaced, brought) {
114
+ if (book.chapters.some((c, i) => !replaced.has(i) && resourceIdRanges(c.markdown, id).length > 0))
115
+ return true;
116
+ if (configPathsNaming(book.config, id).length > 0)
117
+ return true;
118
+ // Another resource names it when renaming it there would change something.
119
+ return book.resources.some((r) => r.id !== id && !brought.has(r.id) && renameResourceInResources([r], id, `${id}-`).length > 0);
120
+ }
121
+ /** The resources the part brings that are named as one of the book's which
122
+ * stays in use, with the name proposed for each. A resource only the
123
+ * replaced chapters use is not a clash: the part's takes its place. */
124
+ export function resourceClashes(book, part, choices) {
125
+ const replaced = new Set(choices.map((c) => replacedChapter(book, c)).filter((i) => i >= 0));
126
+ const bookIds = new Set(book.resources.map((r) => r.id));
127
+ const brought = broughtResources(part, choices);
128
+ const broughtIds = new Set(brought.map((r) => r.id));
129
+ const taken = new Set([...bookIds, ...part.resources.map((r) => r.id)]);
130
+ const clashes = [];
131
+ for (const r of brought) {
132
+ if (!bookIds.has(r.id) || !bookKeepsUsing(book, r.id, replaced, broughtIds))
133
+ continue;
134
+ const rename = freeId(r.id, taken);
135
+ taken.add(rename);
136
+ clashes.push({ id: r.id, rename });
137
+ }
138
+ return clashes;
139
+ }
140
+ /** The clashing resources whose new name (`renames`, else the proposed one)
141
+ * cannot be used: not an id every reference reads, or taken by another
142
+ * resource of the book or the part, or given to two of them. */
143
+ export function renameProblems(book, part, choices, renames = {}) {
144
+ const clashes = resourceClashes(book, part, choices);
145
+ const taken = new Set([...book.resources.map((r) => r.id), ...part.resources.map((r) => r.id)]);
146
+ const names = clashes.map((c) => renames[c.id] ?? c.rename);
147
+ return clashes.filter((c, i) => {
148
+ const name = names[i];
149
+ return !RESOURCE_ID_RE.test(name) || name === c.id || (taken.has(name) && name !== c.rename) || names.indexOf(name) !== i;
150
+ }).map((c) => c.id);
151
+ }
152
+ /** `markdown` with its first numbered level-1 heading given the number `n`
153
+ * (`{startAt=n}`): the attribute is set, or added to the heading's
154
+ * attributes, or given them. Front matter and code blocks are never taken
155
+ * for the heading (the parser finds it). A chapter with no such heading is
156
+ * left as it is. */
157
+ export function withChapterNumber(markdown, n, config) {
158
+ const body = chapterBody(markdown, config);
159
+ const heading = numberedChapterHeading(body);
160
+ if (!heading)
161
+ return markdown;
162
+ const start = body.offset + heading.sourceStart;
163
+ const lineEnd = markdown.indexOf('\n', start);
164
+ const end = lineEnd < 0 ? markdown.length : lineEnd;
165
+ const line = markdown.slice(start, end).replace(/[ \t\r]+$/, '');
166
+ const startAt = /(^|\s)startAt\s*=\s*("[^"]*"|'[^']*'|[^\s}]+)/;
167
+ const attrs = line.match(/\{([^{}]*)\}$/);
168
+ let next;
169
+ if (!attrs)
170
+ next = `${line} {startAt=${n}}`;
171
+ else {
172
+ const inside = startAt.test(attrs[1]) ? attrs[1].replace(startAt, `$1startAt=${n}`) : `startAt=${n} ${attrs[1].trim()}`.trim();
173
+ next = `${line.slice(0, attrs.index)}{${inside}}`;
174
+ }
175
+ return markdown.slice(0, start) + next + markdown.slice(start + line.length);
176
+ }
177
+ /** Whether the chapter's numbered heading carries `startAt`. */
178
+ function hasStartAt(markdown, config) {
179
+ return numberedChapterHeading(chapterBody(markdown, config))?.attrs?.startAt !== undefined;
180
+ }
181
+ /** What to change in the book to join the chosen chapters of the part, the
182
+ * clashing resources renamed as `renames` says (a clash it leaves out
183
+ * takes the proposed name). Throws when the choices or the names do not
184
+ * fit (see {@link choiceProblems}, {@link renameProblems}). */
185
+ export function planPartJoin(book, part, choices, renames = {}) {
186
+ if (choices.length !== part.chapters.length)
187
+ throw new Error(`The part has ${part.chapters.length} chapter(s): give one choice for each.`);
188
+ const problems = choiceProblems(book, part, choices);
189
+ if (problems.length > 0)
190
+ throw new Error(`The choices do not fit the book: ${problems.map((p) => `chapter ${p.chapter + 1} ${p.problem}`).join(', ')}.`);
191
+ const badNames = renameProblems(book, part, choices, renames);
192
+ if (badNames.length > 0)
193
+ throw new Error(`These resources cannot take the names given: ${badNames.join(', ')}.`);
194
+ const renamed = resourceClashes(book, part, choices).map((c) => ({ from: c.id, to: renames[c.id] ?? c.rename }));
195
+ // The resources brought, renamed, and every reference to them with them.
196
+ let resources = broughtResources(part, choices);
197
+ const texts = part.chapters.map((c) => c.markdown);
198
+ for (const { from, to } of renamed) {
199
+ texts.forEach((t, i) => { texts[i] = withResourceRenamed(t, from, to); });
200
+ const rewritten = new Map(renameResourceInResources(resources, from, to).map((x) => [x.resource.id, x.resource]));
201
+ resources = resources.map((r) => (r.id === from ? { ...r, id: to } : (rewritten.get(r.id) ?? r)));
202
+ }
203
+ // The steps, in the order of the numbers: an added chapter goes before the
204
+ // first chapter numbered above it (a chapter with no number counts as the
205
+ // one before it), counting those added already.
206
+ const numbers = bookNumbers(book);
207
+ const order = choices.map((c, i) => ({ c, i })).filter(({ c }) => c.action !== 'skip').sort((a, b) => a.c.number - b.c.number);
208
+ // The book as it will be: each entry the number it is counted by (null:
209
+ // none) and, for a chapter of the part, which one.
210
+ const book2 = numbers.map((number, orig) => ({ number, orig }));
211
+ const steps = [];
212
+ for (const { c, i } of order) {
213
+ const title = part.chapters[i].title;
214
+ if (c.action === 'replace') {
215
+ const at = numbers.indexOf(c.number);
216
+ book2[book2.findIndex((b) => b.orig === at)] = { number: c.number, part: i, orig: at };
217
+ steps.push({ kind: 'replace', at, part: i, title, markdown: texts[i], number: c.number });
218
+ }
219
+ else {
220
+ const own = chapterNumbers([part.chapters[i]], part.config)[0];
221
+ const fileNumbers = chapterFileNumbers(book2.map((b) => b.number));
222
+ let index = fileNumbers.findIndex((n) => n > c.number);
223
+ if (index < 0)
224
+ index = book2.length;
225
+ book2.splice(index, 0, { number: own === null ? null : c.number, part: i });
226
+ steps.push({ kind: 'add', index, part: i, title, markdown: texts[i], number: c.number });
227
+ }
228
+ }
229
+ // Each heading brought in gets the number it goes to, when its place does
230
+ // not give it that number already or it states one of its own.
231
+ let counter = book.start?.h1 ?? 0;
232
+ const natural = new Map();
233
+ for (const entry of book2) {
234
+ if (entry.number === null)
235
+ continue;
236
+ if (entry.part !== undefined)
237
+ natural.set(entry.part, counter + 1);
238
+ counter = entry.number;
239
+ }
240
+ for (const step of steps) {
241
+ const needs = natural.get(step.part) !== step.number || hasStartAt(step.markdown, part.config);
242
+ if (needs)
243
+ step.markdown = withChapterNumber(step.markdown, step.number, part.config);
244
+ }
245
+ // The fonts: the part's families the book has no family of that name for.
246
+ const own = book.config.customFonts ?? [];
247
+ const missing = (part.config.customFonts ?? []).filter((f) => !own.some((o) => o.name.toLowerCase() === f.name.toLowerCase()));
248
+ return {
249
+ steps,
250
+ resources,
251
+ renamed,
252
+ ...(missing.length > 0 ? { customFonts: [...own, ...missing] } : {}),
253
+ fontsAdded: missing.map((f) => f.name),
254
+ };
255
+ }
256
+ //# sourceMappingURL=plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.js","sourceRoot":"","sources":["../../../src/bundle/join/plan.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,0EAA0E;AAC1E,2EAA2E;AAC3E,wBAAwB;AACxB,EAAE;AACF,2EAA2E;AAC3E,wEAAwE;AAGxE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACvG,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,mBAAmB,EAA0B,MAAM,WAAW,CAAC;AA2C1J;+BAC+B;AAC/B,MAAM,cAAc,GAAG,mCAAmC,CAAC;AAE3D,qEAAqE;AACrE,MAAM,UAAU,WAAW,CAAC,IAAwE;IAClG,OAAO,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAA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AW,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;KACvC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { PostextConfig, Resource } from '../../types.js';
2
+ /** One replacement in a text: `[from, to)` becomes `insert`; `expect` is
3
+ * the text `[from, to)` held when the change was computed. */
4
+ export interface ResourceRefChange {
5
+ from: number;
6
+ to: number;
7
+ insert: string;
8
+ expect: string;
9
+ }
10
+ /** The fields of a resource that can name another one: what
11
+ * {@link renameResourceInResources} reads, so that it works on a bundle's
12
+ * resource specs as well as on loaded resources. */
13
+ export type ResourceRefFields = Pick<Resource, 'id' | 'caption' | 'note' | 'table'>;
14
+ /** The `[from, to)` ranges of `markdown` that hold the id `id` as a
15
+ * reference to a resource, in reading order. */
16
+ export declare function resourceIdRanges(markdown: string, id: string): {
17
+ from: number;
18
+ to: number;
19
+ }[];
20
+ /** The changes that turn every reference to the resource `from` in
21
+ * `markdown` into one to `to`. */
22
+ export declare function renameResourceInText(markdown: string, from: string, to: string): ResourceRefChange[];
23
+ /** `markdown` with every reference to the resource `from` renamed `to`. */
24
+ export declare function withResourceRenamed(markdown: string, from: string, to: string): string;
25
+ /** The ids of `ids` that `markdown` refers to as resources. */
26
+ export declare function resourcesNamedIn(markdown: string, ids: Iterable<string>): string[];
27
+ /** The resources that name the resource `from` — in a caption or a note's
28
+ * `:ref`, in a table cell's text or as a cell's picture — rewritten to
29
+ * name `to`, with how many references each held. Resources that do not
30
+ * name it are left out. */
31
+ export declare function renameResourceInResources<R extends ResourceRefFields>(resources: readonly R[], from: string, to: string): {
32
+ resource: R;
33
+ count: number;
34
+ }[];
35
+ /** The paths of the configuration that name the resource `id` (a design's
36
+ * image element, a callout's icon): `resourceId` members holding it. */
37
+ export declare function configPathsNaming(config: PostextConfig, id: string): string[];
38
+ //# sourceMappingURL=refs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../src/bundle/join/refs.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE9D;+DAC+D;AAC/D,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;qDAEqD;AACrD,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAuBpF;iDACiD;AACjD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CAqC7F;AAED;mCACmC;AACnC,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAEpG;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAItF;AAED,+DAA+D;AAC/D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAIlF;AAYD;;;4BAG4B;AAC5B,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,iBAAiB,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,G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