postext 1.34.0 → 1.34.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 (202) hide show
  1. package/dist/__tests__/bundle.test.js +33 -1
  2. package/dist/__tests__/bundle.test.js.map +1 -1
  3. package/dist/__tests__/codeBlocks.test.js +88 -0
  4. package/dist/__tests__/codeBlocks.test.js.map +1 -1
  5. package/dist/__tests__/composed/fixtures/page8.d.ts +20 -0
  6. package/dist/__tests__/composed/fixtures/page8.d.ts.map +1 -0
  7. package/dist/__tests__/composed/fixtures/page8.js +159 -0
  8. package/dist/__tests__/composed/fixtures/page8.js.map +1 -0
  9. package/dist/__tests__/composed/layout.test.d.ts +2 -0
  10. package/dist/__tests__/composed/layout.test.d.ts.map +1 -0
  11. package/dist/__tests__/composed/layout.test.js +387 -0
  12. package/dist/__tests__/composed/layout.test.js.map +1 -0
  13. package/dist/__tests__/composed/slotChecks.test.js +6 -3
  14. package/dist/__tests__/composed/slotChecks.test.js.map +1 -1
  15. package/dist/__tests__/composedPaint.test.d.ts +2 -0
  16. package/dist/__tests__/composedPaint.test.d.ts.map +1 -0
  17. package/dist/__tests__/composedPaint.test.js +191 -0
  18. package/dist/__tests__/composedPaint.test.js.map +1 -0
  19. package/dist/__tests__/defaults/stripRoundTrip.test.js +3 -2
  20. package/dist/__tests__/defaults/stripRoundTrip.test.js.map +1 -1
  21. package/dist/__tests__/exports.test.js +12 -0
  22. package/dist/__tests__/exports.test.js.map +1 -1
  23. package/dist/__tests__/highlightMarks.test.d.ts +2 -0
  24. package/dist/__tests__/highlightMarks.test.d.ts.map +1 -0
  25. package/dist/__tests__/highlightMarks.test.js +169 -0
  26. package/dist/__tests__/highlightMarks.test.js.map +1 -0
  27. package/dist/__tests__/tocPartLeader.test.d.ts +2 -0
  28. package/dist/__tests__/tocPartLeader.test.d.ts.map +1 -0
  29. package/dist/__tests__/tocPartLeader.test.js +133 -0
  30. package/dist/__tests__/tocPartLeader.test.js.map +1 -0
  31. package/dist/bundle/api.d.ts +8 -0
  32. package/dist/bundle/api.d.ts.map +1 -1
  33. package/dist/bundle/api.js +6 -3
  34. package/dist/bundle/api.js.map +1 -1
  35. package/dist/bundle/codec.d.ts +5 -0
  36. package/dist/bundle/codec.d.ts.map +1 -1
  37. package/dist/bundle/codec.js +4 -0
  38. package/dist/bundle/codec.js.map +1 -1
  39. package/dist/bundle/index.d.ts +2 -2
  40. package/dist/bundle/index.d.ts.map +1 -1
  41. package/dist/bundle/index.js +1 -1
  42. package/dist/bundle/index.js.map +1 -1
  43. package/dist/bundle/manifest.d.ts +14 -0
  44. package/dist/bundle/manifest.d.ts.map +1 -1
  45. package/dist/bundle/manifest.js +13 -0
  46. package/dist/bundle/manifest.js.map +1 -1
  47. package/dist/bundle/types.d.ts +7 -0
  48. package/dist/bundle/types.d.ts.map +1 -1
  49. package/dist/canvas-backend/annotations.d.ts +6 -0
  50. package/dist/canvas-backend/annotations.d.ts.map +1 -1
  51. package/dist/canvas-backend/annotations.js +39 -0
  52. package/dist/canvas-backend/annotations.js.map +1 -1
  53. package/dist/canvas-backend/blockRender.d.ts.map +1 -1
  54. package/dist/canvas-backend/blockRender.js +6 -1
  55. package/dist/canvas-backend/blockRender.js.map +1 -1
  56. package/dist/canvas-backend/composed.d.ts +15 -0
  57. package/dist/canvas-backend/composed.d.ts.map +1 -0
  58. package/dist/canvas-backend/composed.js +41 -0
  59. package/dist/canvas-backend/composed.js.map +1 -0
  60. package/dist/canvas-backend/index.d.ts.map +1 -1
  61. package/dist/canvas-backend/index.js +15 -1
  62. package/dist/canvas-backend/index.js.map +1 -1
  63. package/dist/canvas-backend/renderResourceBlock.d.ts.map +1 -1
  64. package/dist/canvas-backend/renderResourceBlock.js +4 -1
  65. package/dist/canvas-backend/renderResourceBlock.js.map +1 -1
  66. package/dist/composed/geometry.d.ts +108 -0
  67. package/dist/composed/geometry.d.ts.map +1 -0
  68. package/dist/composed/geometry.js +241 -0
  69. package/dist/composed/geometry.js.map +1 -0
  70. package/dist/composed/paint.d.ts +41 -0
  71. package/dist/composed/paint.d.ts.map +1 -0
  72. package/dist/composed/paint.js +83 -0
  73. package/dist/composed/paint.js.map +1 -0
  74. package/dist/composed/types.d.ts +1 -44
  75. package/dist/composed/types.d.ts.map +1 -1
  76. package/dist/composed/wrap.d.ts +52 -0
  77. package/dist/composed/wrap.d.ts.map +1 -0
  78. package/dist/composed/wrap.js +234 -0
  79. package/dist/composed/wrap.js.map +1 -0
  80. package/dist/configWarnings.js +1 -1
  81. package/dist/configWarnings.js.map +1 -1
  82. package/dist/defaults/codeStyle.d.ts.map +1 -1
  83. package/dist/defaults/codeStyle.js +1 -0
  84. package/dist/defaults/codeStyle.js.map +1 -1
  85. package/dist/defaults/index.d.ts +1 -0
  86. package/dist/defaults/index.d.ts.map +1 -1
  87. package/dist/defaults/index.js +9 -0
  88. package/dist/defaults/index.js.map +1 -1
  89. package/dist/defaults/markStyles.d.ts +23 -0
  90. package/dist/defaults/markStyles.d.ts.map +1 -0
  91. package/dist/defaults/markStyles.js +80 -0
  92. package/dist/defaults/markStyles.js.map +1 -0
  93. package/dist/defaults/shared.d.ts.map +1 -1
  94. package/dist/defaults/shared.js +12 -0
  95. package/dist/defaults/shared.js.map +1 -1
  96. package/dist/design/bidiText.d.ts +4 -1
  97. package/dist/design/bidiText.d.ts.map +1 -1
  98. package/dist/design/bidiText.js +5 -2
  99. package/dist/design/bidiText.js.map +1 -1
  100. package/dist/design/layout.d.ts +10 -0
  101. package/dist/design/layout.d.ts.map +1 -1
  102. package/dist/design/layout.js +110 -8
  103. package/dist/design/layout.js.map +1 -1
  104. package/dist/design/placeholders.d.ts +28 -2
  105. package/dist/design/placeholders.d.ts.map +1 -1
  106. package/dist/design/placeholders.js +24 -1
  107. package/dist/design/placeholders.js.map +1 -1
  108. package/dist/design/richText.d.ts +2 -0
  109. package/dist/design/richText.d.ts.map +1 -1
  110. package/dist/design/richText.js.map +1 -1
  111. package/dist/highlightMarks.d.ts +33 -0
  112. package/dist/highlightMarks.d.ts.map +1 -0
  113. package/dist/highlightMarks.js +209 -0
  114. package/dist/highlightMarks.js.map +1 -0
  115. package/dist/html-backend.d.ts.map +1 -1
  116. package/dist/html-backend.js +65 -8
  117. package/dist/html-backend.js.map +1 -1
  118. package/dist/htmlAnnotations.d.ts +5 -0
  119. package/dist/htmlAnnotations.d.ts.map +1 -1
  120. package/dist/htmlAnnotations.js +16 -0
  121. package/dist/htmlAnnotations.js.map +1 -1
  122. package/dist/index.d.ts +6 -4
  123. package/dist/index.d.ts.map +1 -1
  124. package/dist/index.js +4 -2
  125. package/dist/index.js.map +1 -1
  126. package/dist/knuthPlass/richAdapter.d.ts +3 -0
  127. package/dist/knuthPlass/richAdapter.d.ts.map +1 -1
  128. package/dist/knuthPlass/richAdapter.js +3 -2
  129. package/dist/knuthPlass/richAdapter.js.map +1 -1
  130. package/dist/measure/cache.js +3 -3
  131. package/dist/measure/cache.js.map +1 -1
  132. package/dist/measure/chipEdges.d.ts +13 -1
  133. package/dist/measure/chipEdges.d.ts.map +1 -1
  134. package/dist/measure/chipEdges.js +59 -1
  135. package/dist/measure/chipEdges.js.map +1 -1
  136. package/dist/measure/links.d.ts.map +1 -1
  137. package/dist/measure/links.js +78 -5
  138. package/dist/measure/links.js.map +1 -1
  139. package/dist/measure/rich.d.ts +3 -0
  140. package/dist/measure/rich.d.ts.map +1 -1
  141. package/dist/measure/rich.js +19 -4
  142. package/dist/measure/rich.js.map +1 -1
  143. package/dist/parse/inlineFormatting.d.ts +14 -0
  144. package/dist/parse/inlineFormatting.d.ts.map +1 -1
  145. package/dist/parse/inlineFormatting.js +104 -5
  146. package/dist/parse/inlineFormatting.js.map +1 -1
  147. package/dist/parse/links.js +1 -1
  148. package/dist/parse/links.js.map +1 -1
  149. package/dist/parse/softBreaks.js +1 -1
  150. package/dist/parse/softBreaks.js.map +1 -1
  151. package/dist/parse/sourceMapping.d.ts.map +1 -1
  152. package/dist/parse/sourceMapping.js +19 -3
  153. package/dist/parse/sourceMapping.js.map +1 -1
  154. package/dist/parse/types.d.ts +24 -0
  155. package/dist/parse/types.d.ts.map +1 -1
  156. package/dist/pipeline/build.d.ts.map +1 -1
  157. package/dist/pipeline/build.js +156 -300
  158. package/dist/pipeline/build.js.map +1 -1
  159. package/dist/pipeline/calloutLayout.d.ts +33 -0
  160. package/dist/pipeline/calloutLayout.d.ts.map +1 -1
  161. package/dist/pipeline/calloutLayout.js +91 -2
  162. package/dist/pipeline/calloutLayout.js.map +1 -1
  163. package/dist/pipeline/codeInline.d.ts +10 -1
  164. package/dist/pipeline/codeInline.d.ts.map +1 -1
  165. package/dist/pipeline/codeInline.js +96 -15
  166. package/dist/pipeline/codeInline.js.map +1 -1
  167. package/dist/pipeline/composedLayout.d.ts +88 -0
  168. package/dist/pipeline/composedLayout.d.ts.map +1 -0
  169. package/dist/pipeline/composedLayout.js +320 -0
  170. package/dist/pipeline/composedLayout.js.map +1 -0
  171. package/dist/pipeline/config.d.ts.map +1 -1
  172. package/dist/pipeline/config.js +2 -1
  173. package/dist/pipeline/config.js.map +1 -1
  174. package/dist/pipeline/contentWarnings.d.ts.map +1 -1
  175. package/dist/pipeline/contentWarnings.js +32 -1
  176. package/dist/pipeline/contentWarnings.js.map +1 -1
  177. package/dist/pipeline/floatSlots.js +1 -1
  178. package/dist/pipeline/floatSlots.js.map +1 -1
  179. package/dist/pipeline/frameLayout.d.ts +120 -0
  180. package/dist/pipeline/frameLayout.d.ts.map +1 -0
  181. package/dist/pipeline/frameLayout.js +279 -0
  182. package/dist/pipeline/frameLayout.js.map +1 -0
  183. package/dist/pipeline/headerFooter.d.ts.map +1 -1
  184. package/dist/pipeline/headerFooter.js +48 -3
  185. package/dist/pipeline/headerFooter.js.map +1 -1
  186. package/dist/pipeline/pageRoles.d.ts +1 -0
  187. package/dist/pipeline/pageRoles.d.ts.map +1 -1
  188. package/dist/pipeline/pageRoles.js +3 -0
  189. package/dist/pipeline/pageRoles.js.map +1 -1
  190. package/dist/pipeline/placement.js +1 -1
  191. package/dist/pipeline/placement.js.map +1 -1
  192. package/dist/pipeline/resourceLayout.d.ts.map +1 -1
  193. package/dist/pipeline/resourceLayout.js +5 -3
  194. package/dist/pipeline/resourceLayout.js.map +1 -1
  195. package/dist/pipeline/tabs.js +1 -1
  196. package/dist/pipeline/tabs.js.map +1 -1
  197. package/dist/types.d.ts +69 -3
  198. package/dist/types.d.ts.map +1 -1
  199. package/dist/vdt.d.ts +169 -1
  200. package/dist/vdt.d.ts.map +1 -1
  201. package/dist/vdt.js.map +1 -1
  202. package/package.json +1 -1
@@ -7,7 +7,8 @@
7
7
  * as they are. Without `codeStyle.inline` inline code is set in the text's
8
8
  * face, as before #624.
9
9
  */
10
- import type { ContentBlock } from '../parse';
10
+ import type { ContentBlock, InlineSpan } from '../parse';
11
+ import type { ResolvedInlineCodeStyleConfig } from '../types';
11
12
  import type { ResolvedConfig } from '../vdt';
12
13
  /** Style id of an inline code chip: no chip style can name it. */
13
14
  export declare const INLINE_CODE_CHIP_STYLE = "__postext-code";
@@ -19,4 +20,12 @@ export declare const INLINE_CODE_CHIP_STYLE = "__postext-code";
19
20
  * between backticks.
20
21
  */
21
22
  export declare function withInlineCode(block: ContentBlock, raw: ContentBlock, resolved: ResolvedConfig, fontSizePx: number): ContentBlock;
23
+ /**
24
+ * The spans of an inline snippet (a table cell, a caption, a note) with the
25
+ * characters of its inline code set as code chips, when `inline` is set and
26
+ * `content` (the snippet as written, which `spans` were parsed from) has
27
+ * inline code. Run on the spans {@link parseInlineSnippetSpans} returns,
28
+ * before formulas and references are resolved.
29
+ */
30
+ export declare function withSnippetInlineCode(spans: InlineSpan[], content: string, inline: ResolvedInlineCodeStyleConfig | undefined, dpi: number, fontSizePx: number): InlineSpan[];
22
31
  //# sourceMappingURL=codeInline.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codeInline.d.ts","sourceRoot":"","sources":["../../src/pipeline/codeInline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAW,YAAY,EAAc,MAAM,UAAU,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAK7C,kEAAkE;AAClE,eAAO,MAAM,sBAAsB,mBAAmB,CAAC;AA2BvD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,YAAY,CAwCjI"}
1
+ {"version":3,"file":"codeInline.d.ts","sourceRoot":"","sources":["../../src/pipeline/codeInline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAW,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAM7C,kEAAkE;AAClE,eAAO,MAAM,sBAAsB,mBAAmB,CAAC;AAyBvD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,YAAY,CAajI;AAMD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,UAAU,EAAE,EACnB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,6BAA6B,GAAG,SAAS,EACjD,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GACjB,UAAU,EAAE,CAad"}
@@ -8,16 +8,13 @@
8
8
  * face, as before #624.
9
9
  */
10
10
  import { sliceSpan } from '../parse/links';
11
+ import { computeSourceMap } from '../parse/sourceMapping';
11
12
  import { setsObject } from '../measure/rich';
12
13
  import { dimensionToPx } from '../units';
13
14
  /** Style id of an inline code chip: no chip style can name it. */
14
15
  export const INLINE_CODE_CHIP_STYLE = '__postext-code';
15
16
  /** The chip box of inline code in text of `fontSizePx`. */
16
- function inlineCodeBox(resolved, fontSizePx) {
17
- const inline = resolved.codeStyle?.inline;
18
- if (!inline)
19
- return undefined;
20
- const dpi = resolved.page.dpi;
17
+ function inlineCodeBox(inline, dpi, fontSizePx) {
21
18
  const sizePx = dimensionToPx(inline.fontSize, dpi, fontSizePx);
22
19
  const px = (d) => Math.max(0, dimensionToPx(d, dpi, sizePx));
23
20
  const borderWidthPx = inline.borderColor ? px(inline.borderWidth) : 0;
@@ -35,6 +32,7 @@ function inlineCodeBox(resolved, fontSizePx) {
35
32
  paddingXPx: px(inline.paddingX),
36
33
  paddingYPx: px(inline.paddingY),
37
34
  gapPx: 0,
35
+ direction: 'ltr',
38
36
  };
39
37
  }
40
38
  /**
@@ -46,24 +44,108 @@ function inlineCodeBox(resolved, fontSizePx) {
46
44
  */
47
45
  export function withInlineCode(block, raw, resolved, fontSizePx) {
48
46
  const ranges = raw.inlineCode;
49
- if (!ranges || ranges.length === 0 || !resolved.codeStyle?.inline)
50
- return block;
51
- const box = inlineCodeBox(resolved, fontSizePx);
52
- if (!box)
47
+ const inline = resolved.codeStyle?.inline;
48
+ if (!ranges || ranges.length === 0 || !inline)
53
49
  return block;
54
50
  const prefix = block.text.length - raw.text.length;
55
51
  const map = raw.sourceMap;
56
- const isCode = (p) => {
52
+ const spans = codeChipSpans(block.spans, (p) => {
57
53
  const i = p - prefix;
58
54
  if (i < 0 || i >= map.length)
59
55
  return false;
60
56
  const at = map[i];
61
57
  return ranges.some((r) => at >= r.start && at < r.end);
62
- };
58
+ }, inlineCodeBox(inline, resolved.page.dpi, fontSizePx), inline.otherScripts === 'text');
59
+ return spans === block.spans ? block : { ...block, spans };
60
+ }
61
+ /** Inline code between two backticks on one line, outside an escape, as
62
+ * the block parser reads it. */
63
+ const SNIPPET_CODE_RE = /(?<!\\)`([^`\n]+?)`/g;
64
+ /**
65
+ * The spans of an inline snippet (a table cell, a caption, a note) with the
66
+ * characters of its inline code set as code chips, when `inline` is set and
67
+ * `content` (the snippet as written, which `spans` were parsed from) has
68
+ * inline code. Run on the spans {@link parseInlineSnippetSpans} returns,
69
+ * before formulas and references are resolved.
70
+ */
71
+ export function withSnippetInlineCode(spans, content, inline, dpi, fontSizePx) {
72
+ if (!inline || !content.includes('`'))
73
+ return spans;
74
+ const ranges = [];
75
+ SNIPPET_CODE_RE.lastIndex = 0;
76
+ for (let m = SNIPPET_CODE_RE.exec(content); m; m = SNIPPET_CODE_RE.exec(content)) {
77
+ ranges.push({ start: m.index + 1, end: m.index + 1 + m[1].length });
78
+ }
79
+ if (ranges.length === 0)
80
+ return spans;
81
+ const map = computeSourceMap(content, 0, content.length, spans.map((s) => s.text).join(''));
82
+ return codeChipSpans(spans, (p) => {
83
+ const at = map[p];
84
+ return at !== undefined && ranges.some((r) => at >= r.start && at < r.end);
85
+ }, inlineCodeBox(inline, dpi, fontSizePx), inline.otherScripts === 'text');
86
+ }
87
+ /** The spans of one run of inline code: a chip per piece between its
88
+ * inner spaces, each space a code space a line may break at (#845), so a
89
+ * long piece of code never leaves a line it cannot fill. A hyphen between
90
+ * a letter or digit and a letter (`simp-chinese-informal`) is a place to
91
+ * break too, behind an empty code space: the hyphen stays the code's, and
92
+ * none is added. Spaces that open or close the run stay inside its first
93
+ * or last piece. */
94
+ function codePieces(span, text, box, textFace) {
95
+ const chip = (t, joinNext) => ({
96
+ text: t, bold: span.bold, italic: span.italic,
97
+ chip: { style: INLINE_CODE_CHIP_STYLE, spans: textFace ? codeWords(t) : [{ text: t, bold: false, italic: false }], box, ...(joinNext ? { joinNext: true } : {}) },
98
+ });
99
+ const parts = /^(\s*)(.*?)(\s*)$/s.exec(text);
100
+ const inner = parts[2].split(/( +)|(?<=[\p{L}\p{N}]-)(?=\p{L})/u).map((t) => t ?? '');
101
+ if (inner.length === 1)
102
+ return [chip(text, false)];
103
+ inner[0] = parts[1] + inner[0];
104
+ inner[inner.length - 1] = inner[inner.length - 1] + parts[3];
105
+ const out = [];
106
+ for (let i = 0; i < inner.length; i += 2) {
107
+ const last = i === inner.length - 1;
108
+ out.push(chip(inner[i], !last));
109
+ if (!last)
110
+ out.push({ text: inner[i + 1], bold: span.bold, italic: span.italic, codeSpace: box });
111
+ }
112
+ return out;
113
+ }
114
+ /** Letters a code face does not carry: Arabic, Hebrew, Syriac and Thaana,
115
+ * and Chinese, Japanese and Korean, with their full-width marks. */
116
+ const TEXT_FACE_RE = /[\p{Script=Arabic}\p{Script=Hebrew}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Bopomofo}\u3000-\u303f\uff00-\uffef]/u;
117
+ const MARK_RE = /\p{M}/u;
118
+ /** The words of a piece of code: one span, or, when it holds letters a
119
+ * code face does not carry (an Arabic word in `:index[…]`, kanji in a
120
+ * ruby), a span per run, those runs set in the text's face (#845). A
121
+ * combining mark goes with the letter before it. */
122
+ function codeWords(text) {
123
+ if (!TEXT_FACE_RE.test(text))
124
+ return [{ text, bold: false, italic: false }];
125
+ const out = [];
126
+ let run = '';
127
+ let face = false;
128
+ for (const ch of text) {
129
+ const own = MARK_RE.test(ch) && run ? face : TEXT_FACE_RE.test(ch);
130
+ if (run && own !== face) {
131
+ out.push({ text: run, bold: false, italic: false, ...(face ? { textFace: true } : {}) });
132
+ run = '';
133
+ }
134
+ face = own;
135
+ run += ch;
136
+ }
137
+ if (run)
138
+ out.push({ text: run, bold: false, italic: false, ...(face ? { textFace: true } : {}) });
139
+ return out;
140
+ }
141
+ /** `spans` with every run of characters `isCode` names (by offset in the
142
+ * spans' joined text) set as one code chip in `box`; `spans` itself when
143
+ * none is. Objects (formulas, references, chips…) stay as they are. */
144
+ function codeChipSpans(spans, isCode, box, textFace) {
63
145
  const out = [];
64
146
  let at = 0;
65
147
  let changed = false;
66
- for (const span of block.spans) {
148
+ for (const span of spans) {
67
149
  const len = span.text.length;
68
150
  if (setsObject(span) || span.tab || span.inserted || len === 0) {
69
151
  out.push(span);
@@ -80,14 +162,13 @@ export function withInlineCode(block, raw, resolved, fontSizePx) {
80
162
  out.push(k === 0 && j === len ? span : sliceSpan(span, k, j));
81
163
  }
82
164
  else {
83
- const text = span.text.slice(k, j);
84
- out.push({ text, bold: span.bold, italic: span.italic, chip: { style: INLINE_CODE_CHIP_STYLE, spans: [{ text, bold: false, italic: false }], box } });
165
+ out.push(...codePieces(span, span.text.slice(k, j), box, textFace));
85
166
  changed = true;
86
167
  }
87
168
  k = j;
88
169
  }
89
170
  at += len;
90
171
  }
91
- return changed ? { ...block, spans: out } : block;
172
+ return changed ? out : spans;
92
173
  }
93
174
  //# sourceMappingURL=codeInline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"codeInline.js","sourceRoot":"","sources":["../../src/pipeline/codeInline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,kEAAkE;AAClE,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AAEvD,2DAA2D;AAC3D,SAAS,aAAa,CAAC,QAAwB,EAAE,UAAkB;IACjE,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC1C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;IAC9B,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;IAC/D,MAAM,EAAE,GAAG,CAAC,CAAsC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,GAAG,EAA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(`composed/wrap.ts`) into its frames with
4
+ * the box typesetter (`frameLayout.ts`), and hand back the blocks for the
5
+ * page's floats with the page's `VDTComposedPage`.
6
+ *
7
+ * Per frame, in {@link frameOrder}: its box ({@link placeBox}, an `'auto'`
8
+ * height measured with the content the frame will hold), then its content:
9
+ * the story from where the frame before it in the chain stopped, cut at the
10
+ * frame's foot when a `next` frame takes the rest, else laid whole and
11
+ * clipped at the foot (`frameOverflow`). Text runs round the frames that
12
+ * push it (`exclude: 'push'`) already placed. The groups' negotiation
13
+ * (#856), the reflow ladder (#858) and continuation on other pages (#859)
14
+ * build on this.
15
+ */
16
+ import type { ComposedPageFence, ContentBlock } from '../parse/types';
17
+ import type { ResolvedCalloutStyleConfig } from '../types';
18
+ import type { ContentWarning, VDTBlock, VDTComposedPage, VDTPage } from '../vdt';
19
+ import { dimensionToPx } from '../units';
20
+ import { type FrameAreas } from '../composed/geometry';
21
+ import type { ResolvedFrame, ResolvedPageTemplate } from '../composed/types';
22
+ import { type PageTemplateSource } from '../composed/templates';
23
+ import { type PlannedCallout } from './calloutLayout';
24
+ import { type FrameLayoutPass } from './frameLayout';
25
+ /** A story of the page: the box `composed/wrap.ts` made of a chain's
26
+ * content, by the name of the chain's first frame. */
27
+ export interface ComposedStory {
28
+ startIdx: number;
29
+ plan: PlannedCallout;
30
+ }
31
+ export interface ComposedPageInput {
32
+ pass: FrameLayoutPass;
33
+ page: VDTPage;
34
+ template: ResolvedPageTemplate;
35
+ fence: ComposedPageFence;
36
+ /** Content index of the page's opening and closing markers. */
37
+ startIdx: number;
38
+ endIdx: number;
39
+ /** The page's stories by head frame name. */
40
+ stories: ReadonlyMap<string, ComposedStory>;
41
+ /** The style a frame is drawn with: its `style`, or frameless. */
42
+ styleOf(frame: ResolvedFrame): ResolvedCalloutStyleConfig;
43
+ areas: FrameAreas;
44
+ dpi: number;
45
+ emPx: number;
46
+ /** Source offset of the body in the chapter file. */
47
+ bodyOffset: number;
48
+ /** The page swaps its mirrored margins (an `'outer'` corner icon). */
49
+ mirrored: boolean;
50
+ /** The gap text keeps from a frame that pushes it. */
51
+ pushGapPx: number;
52
+ }
53
+ export interface ComposedPageLayout {
54
+ composed: VDTComposedPage;
55
+ /** Frame boxes and their content, in paint-independent page order (each
56
+ * frame's box first): for `page.floats` and `doc.blocks`. */
57
+ blocks: VDTBlock[];
58
+ warnings: ContentWarning[];
59
+ /** Story heads laid in a frame of this page. A story left out (its frame
60
+ * is missing on this side) is set in the flow after the page. */
61
+ laid: Set<string>;
62
+ }
63
+ export declare function layoutComposedPage(input: ComposedPageInput): ComposedPageLayout;
64
+ /** The callout style a frame is drawn with: `base` (its `style`, or the
65
+ * frameless frame style) with what a frame sets of its own: its padding
66
+ * (side by side) and a measure that is the frame's. A style's placement,
67
+ * span, width and margins do not apply to a frame. */
68
+ export declare function frameStyleOf(base: ResolvedCalloutStyleConfig, frame: ResolvedFrame): ResolvedCalloutStyleConfig;
69
+ /** The story heads of a composed page's stories, by the head frame's
70
+ * name, read from the boxes `wrapComposedPages` made (`FRAME_ATTR`). */
71
+ export declare function composedStories(startIdx: number, endIdx: number, plans: ReadonlyMap<number, PlannedCallout>): Map<string, ComposedStory>;
72
+ /** `d` in px, 0 when unset. */
73
+ export declare function lengthPx(d: Parameters<typeof dimensionToPx>[0] | undefined, dpi: number, emPx: number): number;
74
+ /** A composed page of the pass whose template is known: its markers and
75
+ * its stories. */
76
+ export interface PlannedComposedPage {
77
+ startIdx: number;
78
+ endIdx: number;
79
+ stories: Map<string, ComposedStory>;
80
+ /** The story box holding block `idx`, if any. */
81
+ storyAt(idx: number): ComposedStory | undefined;
82
+ }
83
+ /** The composed pages of `blocks` whose template `source` has, by their
84
+ * opening marker's index. */
85
+ export declare function planComposedPages(blocks: readonly ContentBlock[], plans: ReadonlyMap<number, PlannedCallout>, source: PageTemplateSource): Map<number, PlannedComposedPage>;
86
+ /** The planned composed page whose markers enclose block `idx`. */
87
+ export declare function composedPageAt(pages: ReadonlyMap<number, PlannedComposedPage>, idx: number): PlannedComposedPage | undefined;
88
+ //# sourceMappingURL=composedLayout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composedLayout.d.ts","sourceRoot":"","sources":["../../src/pipeline/composedLayout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAe,QAAQ,EAAE,eAAe,EAAY,OAAO,EAAE,MAAM,QAAQ,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,OAAO,EAAgF,KAAK,UAAU,EAAa,MAAM,sBAAsB,CAAC;AAChJ,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAuB,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAqD,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACzG,OAAO,EAAoI,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAEvL;uDACuD;AACvD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,KAAK,EAAE,iBAAiB,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC5C,kEAAkE;IAClE,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,0BA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AAG,SAAS,CAAC;CACjD;AAED;8BAC8B;AAC9B,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,YAAY,EAAE,EAC/B,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,EAC1C,MAAM,EAAE,kBAAkB,GACzB,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAqBlC;AAED,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,mBAAmB,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAG5H"}
@@ -0,0 +1,320 @@
1
+ import { dimensionToPx } from '../units';
2
+ import { frameBounds } from '../composed/paint';
3
+ import { FRAME_ATTR } from '../composed/wrap';
4
+ import { frameOrder, framePlaceable, nextFrameOf, groupPlaceable, placeBox, unionRect } from '../composed/geometry';
5
+ import { resolvePageTemplate } from '../composed/templates';
6
+ import { offsetCalloutToAbsolute } from './calloutLayout';
7
+ import { CUT_START, fragmentRange, makeCalloutLayouter, splitCalloutFragment } from './frameLayout';
8
+ const MM_PER_IN = 25.4;
9
+ export function layoutComposedPage(input) {
10
+ const { pass, page, template, fence, dpi } = input;
11
+ const fi = fence.fenceIndex;
12
+ const frameIdOf = (name) => `cp${fi}:${name}`;
13
+ const byName = new Map(template.frames.map((f) => [f.name, f]));
14
+ const prev = new Map();
15
+ for (const f of template.frames) {
16
+ const n = nextFrameOf(f);
17
+ if (n && byName.has(n) && !prev.has(n))
18
+ prev.set(n, f.name);
19
+ }
20
+ /** The head of the chain a frame belongs to. */
21
+ const headOf = (name) => {
22
+ let at = name;
23
+ const seen = new Set([at]);
24
+ for (let p = prev.get(at); p !== undefined && !seen.has(p); p = prev.get(at)) {
25
+ seen.add(p);
26
+ at = p;
27
+ }
28
+ return at;
29
+ };
30
+ /** Place and fill every frame. `seed`: the boxes of the frames that push
31
+ * text, from a first run, so a frame placed before one that pushes it
32
+ * (the photo anchored to its box) still runs round it. */
33
+ const run = (seed) => {
34
+ const pushRects = new Map();
35
+ const states = new Map();
36
+ const stateOf = (frame) => {
37
+ const head = headOf(frame.name);
38
+ const known = states.get(head);
39
+ if (known)
40
+ return known;
41
+ const story = input.stories.get(head);
42
+ const headFrame = byName.get(head);
43
+ if (!story || !headFrame)
44
+ return undefined;
45
+ const st = {
46
+ story,
47
+ L: makeCalloutLayouter(pass, story.startIdx, story.plan, input.styleOf(frame)),
48
+ cut: CUT_START,
49
+ pieces: 0,
50
+ headBlockId: frameIdOf(head),
51
+ headFrameId: frameIdOf(head),
52
+ };
53
+ states.set(head, st);
54
+ return st;
55
+ };
56
+ const atEnd = (st) => st.cut.child >= st.L.end.child && st.cut.line === 0 && !st.cut.group;
57
+ const rects = new Map();
58
+ const groupRect = (name) => {
59
+ const g = template.groups.find((gr) => gr.name === name);
60
+ if (!g)
61
+ return undefined;
62
+ const own = groupPlaceable(g);
63
+ if (own)
64
+ return placeBox(own, template, input, (n) => rects.get(n) ?? groupRect(n), () => 0);
65
+ return unionRect(g.frames.flatMap((m) => (rects.has(m) ? [rects.get(m)] : [])));
66
+ };
67
+ const refOf = (name) => rects.get(name) ?? groupRect(name);
68
+ const frames = [];
69
+ const vdtByName = new Map();
70
+ const blocks = [];
71
+ const warnings = [];
72
+ const log = [];
73
+ const laid = new Set();
74
+ const pushed = seed ? [...seed].map(([name, box]) => ({ name, box })) : [];
75
+ /** The rectangles of the pushing frames placed so far that `rect`
76
+ * meets, in the frame block's coordinates. */
77
+ const exclusionsFor = (frame, rect, open) => {
78
+ const out = [];
79
+ const g = input.pushGapPx;
80
+ for (const p of pushed) {
81
+ if (p.name === frame.name)
82
+ continue;
83
+ const b = p.box;
84
+ const below = open ? true : b.y < rect.y + rect.height;
85
+ if (b.x - g >= rect.x + rect.width || b.x + b.width + g <= rect.x || !below || b.y + b.height + g <= rect.y)
86
+ continue;
87
+ out.push({ x: b.x - g - rect.x, y: b.y - g - rect.y, width: b.width + 2 * g, height: b.height + 2 * g });
88
+ }
89
+ return out.length > 0 ? out : undefined;
90
+ };
91
+ for (const frame of frameOrder(template)) {
92
+ const st = stateOf(frame);
93
+ // Each frame of a chain sets the story in its own style: the cuts are
94
+ // positions in the story's blocks, the same in any.
95
+ if (st)
96
+ st.L = makeCalloutLayouter(pass, st.story.startIdx, st.story.plan, input.styleOf(frame));
97
+ // A frame continues its story only once the frame before it in the
98
+ // chain was filled (a frame placed before it, through an anchor, starts
99
+ // empty).
100
+ const before = prev.get(frame.name);
101
+ const reached = st !== undefined && (before === undefined || vdtByName.has(before));
102
+ const holds = reached && !atEnd(st);
103
+ const continuation = st !== undefined && st.pieces > 0;
104
+ const blockId = st && st.pieces > 0 ? `${st.headBlockId}-cont-${st.pieces}` : frameIdOf(frame.name);
105
+ const style = input.styleOf(frame);
106
+ const placeable = framePlaceable(frame);
107
+ /** The content's height at `width`, running round the pushing
108
+ * frames below the top of `at` (the frame's box as first placed). */
109
+ const natural = (at) => (width) => {
110
+ if (!holds)
111
+ return 0;
112
+ const exclusions = at ? exclusionsFor(frame, { ...at, width }, true) : undefined;
113
+ const r = st.L.layoutRange(st.cut, st.L.end, width, blockId, continuation, input.mirrored, exclusions ? { exclusions } : undefined);
114
+ return r.totalHeight;
115
+ };
116
+ // The box: placed with the content's own height, then again with the
117
+ // height it takes running round the frames that push it there.
118
+ const rect0 = placeBox(placeable, template, input, refOf, natural());
119
+ const rect = holds && exclusionsFor(frame, rect0, true) ? placeBox(placeable, template, input, refOf, natural(rect0)) : rect0;
120
+ rects.set(frame.name, rect);
121
+ let result;
122
+ let overflowPx = 0;
123
+ const from = st?.cut ?? CUT_START;
124
+ if (holds) {
125
+ const opts = {
126
+ boxHeight: rect.height,
127
+ verticalAlign: frame.verticalAlign,
128
+ ...(exclusionsFor(frame, rect, false) ? { exclusions: exclusionsFor(frame, rect, false) } : {}),
129
+ };
130
+ const whole = st.L.layoutRange(from, st.L.end, rect.width, blockId, continuation, input.mirrored, opts);
131
+ const nextName = nextFrameOf(frame);
132
+ const nextFrame = nextName !== undefined ? byName.get(nextName) : undefined;
133
+ if ((whole.overflowPx ?? 0) > 0.5 && nextFrame && !vdtByName.has(nextFrame.name)) {
134
+ // The rest goes on in the next frame of the chain.
135
+ const minLines = Math.max(1, style.splitMinLines);
136
+ const frag = splitCalloutFragment(pass, st.L, from, rect.width, rect.height, blockId, continuation, minLines, input.mirrored, opts.exclusions ? { exclusions: opts.exclusions } : undefined);
137
+ const to = frag?.to ?? from;
138
+ result = frag
139
+ ? st.L.layoutRange(from, to, rect.width, blockId, continuation, input.mirrored, opts)
140
+ : undefined;
141
+ st.cut = to;
142
+ }
143
+ else {
144
+ result = whole;
145
+ overflowPx = whole.overflowPx ?? 0;
146
+ st.cut = st.L.end;
147
+ }
148
+ }
149
+ else if (st && frame.style) {
150
+ // A styled frame with nothing (left) to hold still draws its box.
151
+ result = st.L.layoutRange(st.L.end, st.L.end, rect.width, blockId, true, input.mirrored, { boxHeight: rect.height });
152
+ }
153
+ const vdt = {
154
+ id: frameIdOf(frame.name),
155
+ name: frame.name,
156
+ rect: { ...rect },
157
+ rotate: frame.rotate,
158
+ layer: frame.layer,
159
+ ...(frame.style ? { styleId: frame.style } : {}),
160
+ scale: 1,
161
+ overflowPx,
162
+ blockIds: [],
163
+ configPath: frame.configPath,
164
+ ...(frame.exclude === 'push' ? { push: true } : {}),
165
+ };
166
+ if (before && vdtByName.has(before) && st && st.lastFrameId) {
167
+ vdt.continuedFrom = st.lastFrameId;
168
+ const p = frames.find((f) => f.id === st.lastFrameId);
169
+ if (p)
170
+ p.continuesTo = vdt.id;
171
+ }
172
+ if (result && st) {
173
+ const range = fragmentRange(st.L, from, st.cut);
174
+ commitFrame(result, rect, st.story, range, input, vdt, blocks);
175
+ st.pieces++;
176
+ st.lastFrameId = vdt.id;
177
+ laid.add(headOf(frame.name));
178
+ }
179
+ if (overflowPx > 0.5) {
180
+ const overflowMm = Math.round((overflowPx / dpi) * MM_PER_IN * 10) / 10;
181
+ log.push({ frame: frame.name, kind: 'overflow', toMm: overflowMm });
182
+ warnings.push({
183
+ kind: 'frameOverflow',
184
+ template: template.id,
185
+ frame: frame.name,
186
+ fenceIndex: fi,
187
+ overflowMm,
188
+ configPath: frame.configPath,
189
+ ...(vdt.sourceStart !== undefined ? { sourceStart: vdt.sourceStart, sourceEnd: vdt.sourceEnd } : {}),
190
+ pageIndex: page.index,
191
+ });
192
+ }
193
+ if (frame.exclude === 'push') {
194
+ const box = frameBounds({ rect, rotate: frame.rotate });
195
+ pushRects.set(frame.name, box);
196
+ if (!seed)
197
+ pushed.push({ name: frame.name, box });
198
+ }
199
+ frames.push(vdt);
200
+ vdtByName.set(frame.name, vdt);
201
+ }
202
+ return { frames, blocks, warnings, log, laid, pushRects };
203
+ };
204
+ const first = run();
205
+ const { frames, blocks, warnings, log, laid } = first.pushRects.size > 0 ? run(first.pushRects) : first;
206
+ // Template order on the page record.
207
+ const order = new Map(template.frames.map((f, i) => [f.name, i]));
208
+ frames.sort((a, b) => order.get(a.name) - order.get(b.name));
209
+ const contentBlocks = pass.contentBlocks;
210
+ const composed = {
211
+ template: template.id,
212
+ ...(template.variant ? { variant: template.variant } : {}),
213
+ fenceIndex: fi,
214
+ role: template.role,
215
+ attrs: { ...fence.attrs },
216
+ attrSources: Object.fromEntries(Object.entries(fence.attrSources).map(([k, v]) => [k, { sourceStart: v.sourceStart + input.bodyOffset, sourceEnd: v.sourceEnd + input.bodyOffset }])),
217
+ frames,
218
+ log,
219
+ configPath: template.configPath,
220
+ sourceStart: contentBlocks[input.startIdx].sourceStart + input.bodyOffset,
221
+ sourceEnd: contentBlocks[input.endIdx].sourceEnd + input.bodyOffset,
222
+ };
223
+ return { composed, blocks, warnings, laid };
224
+ }
225
+ /** Stamp a frame's laid-out box with its source and page, move it to the
226
+ * frame's place and add it (box first) to `out` and to the frame's ids. */
227
+ function commitFrame(result, rect, story, range, input, vdt, out) {
228
+ const { pass, page, bodyOffset } = input;
229
+ const blocks = pass.contentBlocks;
230
+ const box = result.frame;
231
+ box.contentIndex = story.startIdx;
232
+ const first = blocks[Math.max(story.startIdx + 1, Math.min(range.firstChildIdx, story.plan.endIdx - 1))];
233
+ const last = blocks[Math.max(story.startIdx + 1, Math.min(range.lastChildIdx, story.plan.endIdx - 1))];
234
+ if (first && last && range.lastChildIdx >= range.firstChildIdx) {
235
+ box.sourceStart = first.sourceStart + bodyOffset;
236
+ box.sourceEnd = last.sourceEnd + bodyOffset;
237
+ vdt.sourceStart = box.sourceStart;
238
+ vdt.sourceEnd = box.sourceEnd;
239
+ }
240
+ box.pageIndex = page.index;
241
+ box.columnIndex = 0;
242
+ offsetCalloutToAbsolute(result, rect.x, rect.y);
243
+ out.push(box);
244
+ vdt.blockIds.push(box.id);
245
+ for (const child of result.children) {
246
+ child.pageIndex = page.index;
247
+ child.columnIndex = 0;
248
+ out.push(child);
249
+ vdt.blockIds.push(child.id);
250
+ }
251
+ }
252
+ /** The callout style a frame is drawn with: `base` (its `style`, or the
253
+ * frameless frame style) with what a frame sets of its own: its padding
254
+ * (side by side) and a measure that is the frame's. A style's placement,
255
+ * span, width and margins do not apply to a frame. */
256
+ export function frameStyleOf(base, frame) {
257
+ const padding = frame.padding ? { ...base.padding, ...frame.padding } : base.padding;
258
+ return {
259
+ ...base,
260
+ padding,
261
+ width: 'fill',
262
+ placement: 'here',
263
+ span: 'column',
264
+ marginTop: { value: 0, unit: 'px' },
265
+ marginBottom: { value: 0, unit: 'px' },
266
+ };
267
+ }
268
+ /** The story heads of a composed page's stories, by the head frame's
269
+ * name, read from the boxes `wrapComposedPages` made (`FRAME_ATTR`). */
270
+ export function composedStories(startIdx, endIdx, plans) {
271
+ const out = new Map();
272
+ for (let i = startIdx + 1; i < endIdx; i++) {
273
+ const plan = plans.get(i);
274
+ if (!plan)
275
+ continue;
276
+ const head = plan.attrs[FRAME_ATTR];
277
+ if (head !== undefined && !out.has(head))
278
+ out.set(head, { startIdx: i, plan });
279
+ i = plan.endIdx;
280
+ }
281
+ return out;
282
+ }
283
+ /** `d` in px, 0 when unset. */
284
+ export function lengthPx(d, dpi, emPx) {
285
+ return d ? dimensionToPx(d, dpi, emPx) : 0;
286
+ }
287
+ /** The composed pages of `blocks` whose template `source` has, by their
288
+ * opening marker's index. */
289
+ export function planComposedPages(blocks, plans, source) {
290
+ const out = new Map();
291
+ for (let i = 0; i < blocks.length; i++) {
292
+ const b = blocks[i];
293
+ if (b.type !== 'containerStart' || b.containerName !== 'composedPage' || !b.composedPage)
294
+ continue;
295
+ let end = i + 1;
296
+ while (end < blocks.length && !(blocks[end].type === 'containerEnd' && blocks[end].containerId === b.containerId))
297
+ end++;
298
+ end = Math.min(end, blocks.length - 1);
299
+ if (resolvePageTemplate(source, b.composedPage.template)) {
300
+ const stories = composedStories(i, end, plans);
301
+ const list = [...stories.values()];
302
+ out.set(i, {
303
+ startIdx: i,
304
+ endIdx: end,
305
+ stories,
306
+ storyAt: (idx) => list.find((s) => idx > s.startIdx && idx < s.plan.endIdx),
307
+ });
308
+ }
309
+ i = end;
310
+ }
311
+ return out;
312
+ }
313
+ /** The planned composed page whose markers enclose block `idx`. */
314
+ export function composedPageAt(pages, idx) {
315
+ for (const p of pages.values())
316
+ if (idx > p.startIdx && idx < p.endIdx)
317
+ return p;
318
+ return undefined;
319
+ }
320
+ //# sourceMappingURL=composedLayout.js.map