@stll/folio-core 0.32.1 → 0.33.0

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 (222) hide show
  1. package/dist/ai-edits/__fixtures__/paragraphs.d.ts +17 -0
  2. package/dist/ai-edits/__fixtures__/paragraphs.js +33 -0
  3. package/dist/ai-edits/apply.d.ts +49 -3
  4. package/dist/ai-edits/apply.js +692 -75
  5. package/dist/ai-edits/blockRange.d.ts +7 -3
  6. package/dist/ai-edits/blockRange.js +14 -6
  7. package/dist/ai-edits/headless.d.ts +39 -5
  8. package/dist/ai-edits/headless.js +76 -17
  9. package/dist/ai-edits/index.d.ts +6 -6
  10. package/dist/ai-edits/index.js +3 -3
  11. package/dist/ai-edits/read.d.ts +4 -0
  12. package/dist/ai-edits/read.js +30 -6
  13. package/dist/ai-edits/scoped-reading.js +4 -3
  14. package/dist/ai-edits/snapshot.d.ts +42 -2
  15. package/dist/ai-edits/snapshot.js +127 -62
  16. package/dist/ai-edits/table-row-column-mutations.d.ts +24 -1
  17. package/dist/ai-edits/table-row-column-mutations.js +98 -6
  18. package/dist/ai-edits/table-targets.d.ts +12 -3
  19. package/dist/ai-edits/table-targets.js +15 -5
  20. package/dist/ai-edits/types.d.ts +235 -7
  21. package/dist/ai-edits/word-diff.d.ts +54 -11
  22. package/dist/ai-edits/word-diff.js +221 -61
  23. package/dist/compare/__fixtures__/body-sequence.d.ts +33 -0
  24. package/dist/compare/__fixtures__/body-sequence.js +67 -0
  25. package/dist/compare/__fixtures__/nested-table.d.ts +16 -0
  26. package/dist/compare/__fixtures__/nested-table.js +50 -0
  27. package/dist/compare/__fixtures__/numbered-list.d.ts +34 -0
  28. package/dist/compare/__fixtures__/numbered-list.js +85 -0
  29. package/dist/compare/column-alignment.d.ts +27 -0
  30. package/dist/compare/column-alignment.js +162 -0
  31. package/dist/compare/compare.d.ts +107 -0
  32. package/dist/compare/compare.js +406 -0
  33. package/dist/compare/formatting.d.ts +29 -0
  34. package/dist/compare/formatting.js +84 -0
  35. package/dist/compare/plan.d.ts +22 -0
  36. package/dist/compare/plan.js +1059 -0
  37. package/dist/compare/reproducible-package.d.ts +17 -0
  38. package/dist/compare/reproducible-package.js +30 -0
  39. package/dist/compare/scenario.d.ts +77 -0
  40. package/dist/compare/scenario.js +263 -0
  41. package/dist/compare/types.d.ts +282 -0
  42. package/dist/compare/types.js +32 -0
  43. package/dist/compare/verification.d.ts +55 -0
  44. package/dist/compare/verification.js +146 -0
  45. package/dist/compat/eigenpal.d.ts +9 -6
  46. package/dist/compat/eigenpal.js +6 -3
  47. package/dist/controller/layoutPipeline.d.ts +13 -0
  48. package/dist/controller/layoutPipeline.js +15 -1
  49. package/dist/display-list/build/buildContext.d.ts +39 -0
  50. package/dist/display-list/build/buildContext.js +31 -0
  51. package/dist/display-list/build/buildDisplayList.d.ts +79 -0
  52. package/dist/display-list/build/buildDisplayList.js +283 -0
  53. package/dist/display-list/build/colors.d.ts +20 -0
  54. package/dist/display-list/build/colors.js +136 -0
  55. package/dist/display-list/build/floatingImages.d.ts +24 -0
  56. package/dist/display-list/build/floatingImages.js +41 -0
  57. package/dist/display-list/build/fontTable.d.ts +31 -0
  58. package/dist/display-list/build/fontTable.js +97 -0
  59. package/dist/display-list/build/furniture.d.ts +86 -0
  60. package/dist/display-list/build/furniture.js +98 -0
  61. package/dist/display-list/build/glyphs.d.ts +55 -0
  62. package/dist/display-list/build/glyphs.js +103 -0
  63. package/dist/display-list/build/headerFooterPrimitives.d.ts +17 -0
  64. package/dist/display-list/build/headerFooterPrimitives.js +40 -0
  65. package/dist/display-list/build/imagePrimitives.d.ts +35 -0
  66. package/dist/display-list/build/imagePrimitives.js +264 -0
  67. package/dist/display-list/build/pageBorderPrimitives.d.ts +23 -0
  68. package/dist/display-list/build/pageBorderPrimitives.js +111 -0
  69. package/dist/display-list/build/pageFurniture.d.ts +35 -0
  70. package/dist/display-list/build/pageFurniture.js +141 -0
  71. package/dist/display-list/build/paragraphPrimitives.d.ts +19 -0
  72. package/dist/display-list/build/paragraphPrimitives.js +819 -0
  73. package/dist/display-list/build/regions.d.ts +46 -0
  74. package/dist/display-list/build/regions.js +56 -0
  75. package/dist/display-list/build/storyPrimitives.d.ts +29 -0
  76. package/dist/display-list/build/storyPrimitives.js +279 -0
  77. package/dist/display-list/build/strokes.d.ts +19 -0
  78. package/dist/display-list/build/strokes.js +78 -0
  79. package/dist/display-list/build/tablePrimitives.d.ts +38 -0
  80. package/dist/display-list/build/tablePrimitives.js +409 -0
  81. package/dist/display-list/build/textBoxPrimitives.d.ts +14 -0
  82. package/dist/display-list/build/textBoxPrimitives.js +129 -0
  83. package/dist/display-list/build/textDecorations.d.ts +29 -0
  84. package/dist/display-list/build/textDecorations.js +29 -0
  85. package/dist/display-list/build/unsupported.d.ts +57 -0
  86. package/dist/display-list/build/unsupported.js +0 -0
  87. package/dist/display-list/build/watermarkPrimitives.d.ts +15 -0
  88. package/dist/display-list/build/watermarkPrimitives.js +128 -0
  89. package/dist/display-list/dom/renderDisplayListToDom.d.ts +26 -0
  90. package/dist/display-list/dom/renderDisplayListToDom.js +620 -0
  91. package/dist/display-list/editor/displayListPagePainter.d.ts +22 -0
  92. package/dist/display-list/editor/displayListPagePainter.js +63 -0
  93. package/dist/display-list/editor/pageRenderer.d.ts +24 -0
  94. package/dist/display-list/editor/pageRenderer.js +36 -0
  95. package/dist/display-list/primitives.d.ts +95 -0
  96. package/dist/display-list/primitives.js +127 -0
  97. package/dist/display-list/types.d.ts +472 -0
  98. package/dist/display-list/types.js +0 -0
  99. package/dist/document-operations.d.ts +42 -9
  100. package/dist/document-operations.js +171 -16
  101. package/dist/document-stories.d.ts +16 -0
  102. package/dist/document-stories.js +48 -4
  103. package/dist/docx/packageParts.d.ts +35 -0
  104. package/dist/docx/packageParts.js +120 -0
  105. package/dist/docx/paragraphParser.js +22 -22
  106. package/dist/docx/paragraphTraversal.js +1 -1
  107. package/dist/docx/renderedPageBreakNormalization.js +3 -1
  108. package/dist/docx/revisionIdNormalization.d.ts +13 -0
  109. package/dist/docx/revisionIdNormalization.js +103 -0
  110. package/dist/docx/rezip.js +26 -17
  111. package/dist/docx/selectiveSave.js +2 -2
  112. package/dist/docx/serializer/commentSerializer.js +6 -1
  113. package/dist/docx/serializer/paragraphSerializer.js +33 -4
  114. package/dist/docx/serializer/runSerializer.js +11 -10
  115. package/dist/docx/serializer/tableSerializer.js +2 -1
  116. package/dist/docx/server/applyDocxXmlPatchProposal.js +1 -1
  117. package/dist/docx/server/createBilingualDocx.js +3 -2
  118. package/dist/docx/streamingXmlParser.d.ts +13 -1
  119. package/dist/docx/streamingXmlParser.js +49 -11
  120. package/dist/docx/unzip.d.ts +1 -2
  121. package/dist/docx/unzip.js +25 -6
  122. package/dist/docx/xmlParser.d.ts +3 -1
  123. package/dist/docx/xmlParser.js +33 -27
  124. package/dist/export-pdf.d.ts +43 -0
  125. package/dist/export-pdf.js +98 -0
  126. package/dist/fonts/headlessMeasure.d.ts +76 -0
  127. package/dist/fonts/headlessMeasure.js +0 -0
  128. package/dist/fonts/sfnt/parse.d.ts +51 -0
  129. package/dist/fonts/sfnt/parse.js +525 -0
  130. package/dist/fonts/sfnt/subset.d.ts +20 -0
  131. package/dist/fonts/sfnt/subset.js +350 -0
  132. package/dist/fonts/sfnt/tables.d.ts +88 -0
  133. package/dist/fonts/sfnt/tables.js +131 -0
  134. package/dist/fonts/sfnt/woff.d.ts +14 -0
  135. package/dist/fonts/sfnt/woff.js +163 -0
  136. package/dist/generated/text_shaper.js +324 -0
  137. package/dist/generated/text_shaper_bg.wasm +0 -0
  138. package/dist/headless-layout.d.ts +75 -0
  139. package/dist/headless-layout.js +350 -0
  140. package/dist/index.d.ts +9 -6
  141. package/dist/index.js +6 -3
  142. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  143. package/dist/layout-bridge/convert/footnoteLayout.js +1 -0
  144. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  145. package/dist/layout-bridge/convert/headerFooterLayout.js +2 -0
  146. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +3 -1
  147. package/dist/layout-bridge/convert/toFlowBlocks.js +2 -0
  148. package/dist/layout-engine/measure/advanceComposition.d.ts +62 -0
  149. package/dist/layout-engine/measure/advanceComposition.js +148 -0
  150. package/dist/layout-engine/measure/cache.d.ts +2 -0
  151. package/dist/layout-engine/measure/measureContainer.js +13 -0
  152. package/dist/layout-engine/measure/measureParagraph.js +1 -2
  153. package/dist/layout-engine/measure/measureTypes.d.ts +12 -0
  154. package/dist/layout-engine/measure/tableInlinePlacement.d.ts +3 -2
  155. package/dist/layout-engine/measure/tableInlinePlacement.js +14 -1
  156. package/dist/layout-engine/tableIndentCompatibility.d.ts +5 -0
  157. package/dist/layout-engine/tableIndentCompatibility.js +15 -0
  158. package/dist/layout-engine/types.d.ts +8 -0
  159. package/dist/layout-painter/renderPage.d.ts +29 -1
  160. package/dist/layout-painter/renderPage.js +47 -19
  161. package/dist/layout-painter/renderParagraph.d.ts +21 -2
  162. package/dist/layout-painter/renderParagraph.js +1 -1
  163. package/dist/layout-painter/renderTable.js +37 -4
  164. package/dist/managers/editorShortcuts.d.ts +33 -1
  165. package/dist/managers/editorShortcuts.js +20 -1
  166. package/dist/markdown/renderRuns.js +7 -2
  167. package/dist/markdown/renderTable.js +5 -1
  168. package/dist/model.d.ts +3 -3
  169. package/dist/model.js +2 -2
  170. package/dist/pdf/contentStream.d.ts +73 -0
  171. package/dist/pdf/contentStream.js +143 -0
  172. package/dist/pdf/fonts.d.ts +96 -0
  173. package/dist/pdf/fonts.js +593 -0
  174. package/dist/pdf/images.d.ts +28 -0
  175. package/dist/pdf/images.js +439 -0
  176. package/dist/pdf/objects.d.ts +93 -0
  177. package/dist/pdf/objects.js +237 -0
  178. package/dist/pdf/pageSpace.d.ts +43 -0
  179. package/dist/pdf/pageSpace.js +57 -0
  180. package/dist/pdf/paint.d.ts +32 -0
  181. package/dist/pdf/paint.js +442 -0
  182. package/dist/pdf/writePdf.d.ts +56 -0
  183. package/dist/pdf/writePdf.js +345 -0
  184. package/dist/prosemirror/commands/comments.js +91 -6
  185. package/dist/prosemirror/conversion/fromProseDoc.js +41 -7
  186. package/dist/prosemirror/conversion/toProseDoc.js +41 -4
  187. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +15 -2
  188. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +35 -6
  189. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +2 -2
  190. package/dist/prosemirror/extensions/features/pasteCleanup.js +4 -3
  191. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.d.ts +3 -1
  192. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -3
  193. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.d.ts +7 -1
  194. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +9 -3
  195. package/dist/prosemirror/extensions/nodes/TableExtension.js +56 -39
  196. package/dist/prosemirror/extensions/nodes/TextBoxAnchorExtension.d.ts +3 -1
  197. package/dist/prosemirror/extensions/nodes/TextBoxAnchorExtension.js +5 -3
  198. package/dist/prosemirror/plugins/suggestionMode.js +1 -0
  199. package/dist/prosemirror/revisionCarriers.js +19 -2
  200. package/dist/prosemirror/utils/extractTrackedChanges.d.ts +2 -2
  201. package/dist/prosemirror/utils/extractTrackedChanges.js +59 -23
  202. package/dist/prosemirror/validation.js +55 -27
  203. package/dist/prosemirror/zeroWidthAnchors.d.ts +10 -0
  204. package/dist/prosemirror/zeroWidthAnchors.js +23 -0
  205. package/dist/redline.js +12 -79
  206. package/dist/server.d.ts +4 -4
  207. package/dist/server.js +2 -2
  208. package/dist/shaping/placeRun.d.ts +51 -0
  209. package/dist/shaping/placeRun.js +84 -0
  210. package/dist/shaping/shaper.d.ts +92 -0
  211. package/dist/shaping/shaper.js +102 -0
  212. package/dist/types/block-id.d.ts +18 -2
  213. package/dist/types/block-id.js +49 -5
  214. package/dist/types/content.d.ts +2 -2
  215. package/dist/utils/clipboard.js +4 -3
  216. package/dist/utils/fontResolver.js +183 -0
  217. package/dist/utils/htmlComments.d.ts +17 -0
  218. package/dist/utils/htmlComments.js +22 -0
  219. package/dist/utils/scriptSegments.d.ts +12 -1
  220. package/dist/utils/scriptSegments.js +17 -1
  221. package/dist/version-comparison.d.ts +1 -1
  222. package/package.json +7 -3
@@ -0,0 +1,63 @@
1
+ import { createDisplayListBuilder } from "../build/buildDisplayList.js";
2
+ import { renderDisplayPageToDom } from "../dom/renderDisplayListToDom.js";
3
+ import { panic } from "better-result";
4
+ //#region src/display-list/editor/displayListPagePainter.ts
5
+ /**
6
+ * Paint the editor's pages from the display list instead of from `Layout`.
7
+ *
8
+ * This is a composition root, not a backend: it is the one place that knows
9
+ * both the producer and the DOM backend, which is why it may import each of
10
+ * them and why neither may import it.
11
+ *
12
+ * ## What it replaces, and what it deliberately does not
13
+ *
14
+ * `renderPages` owns two separable jobs. One is *painting* a page, which is
15
+ * what diverges between two renderers and what the display list exists to make
16
+ * single. The other is the page *container*: shells, virtualization, the
17
+ * fingerprint comparison that skips an unchanged page, the intersection
18
+ * observer, the painted event. That second job is renderer-independent, so
19
+ * this module supplies only a `paintPage` and leaves the container alone.
20
+ * Reimplementing the container behind a second renderer would be exactly the
21
+ * second copy the display list was introduced to remove, and it would silently
22
+ * lose incremental repaint on documents past the virtualization threshold.
23
+ *
24
+ * ## Why a page is built when it is painted
25
+ *
26
+ * `renderPage` is called per page, so building the whole list per call would be
27
+ * quadratic in page count. Building it once per layout run is not right either:
28
+ * the container paints a window of pages and skips every page whose fingerprint
29
+ * has not changed, so a document of ninety pages would build ninety to paint
30
+ * three, on every keystroke. The builder computes what belongs to the document
31
+ * once and each page when it is asked for, so the work follows the screen.
32
+ */
33
+ /**
34
+ * Page numbers are the engine's own and may restart or skip across sections,
35
+ * so a display page is found by its position in the layout rather than by its
36
+ * number. Both sequences come from the same `Layout`, so they align by
37
+ * construction; a mismatch is a programming error, not a document one.
38
+ */
39
+ const indexByPageNumber = (layout) => new Map(layout.pages.map((page, index) => [page.number, index]));
40
+ const createDisplayListPagePainter = (options) => {
41
+ const { doc, ...build } = options;
42
+ const builder = createDisplayListBuilder(build);
43
+ const indexOf = indexByPageNumber(build.layout);
44
+ const paintPage = ({ page }) => {
45
+ const index = indexOf.get(page.number);
46
+ if (index === void 0) return null;
47
+ const displayPage = builder.pageAt(index);
48
+ if (displayPage === void 0) panic(`display list page ${String(index)} is indexed but absent`);
49
+ const { fonts, images } = builder.snapshot();
50
+ return renderDisplayPageToDom(displayPage, {
51
+ doc,
52
+ fonts,
53
+ images,
54
+ pageIndex: index
55
+ });
56
+ };
57
+ return {
58
+ paintPage,
59
+ list: builder.snapshot
60
+ };
61
+ };
62
+ //#endregion
63
+ export { createDisplayListPagePainter };
@@ -0,0 +1,24 @@
1
+ import { RenderPageOptions } from "../../layout-painter/renderPage.js";
2
+ import { PageFurnitureInputs } from "../build/furniture.js";
3
+ //#region src/display-list/editor/pageRenderer.d.ts
4
+ declare const PAGE_RENDERER: {
5
+ /** The painter that has always painted the editor. */
6
+ readonly legacy: "legacy";
7
+ /** Builds the paint IR from the layout and paints the pages from it. */
8
+ readonly displayList: "display-list";
9
+ };
10
+ type PageRendererName = (typeof PAGE_RENDERER)[keyof typeof PAGE_RENDERER];
11
+ declare const isPageRendererName: (value: unknown) => value is PageRendererName;
12
+ /**
13
+ * Read the display-list producer's furniture inputs out of the render options
14
+ * the pipeline already computed.
15
+ *
16
+ * Both sides describe the same constructs, and the pipeline is the only place
17
+ * that knows how to derive them from a package, so the display-list path reads
18
+ * what the existing path receives rather than deriving them a second time. A
19
+ * second derivation is how the two renderers would come to disagree about
20
+ * which header a page carries.
21
+ */
22
+ declare const displayListFurnitureFrom: (options: RenderPageOptions) => PageFurnitureInputs;
23
+ //#endregion
24
+ export { PAGE_RENDERER, PageRendererName, displayListFurnitureFrom, isPageRendererName };
@@ -0,0 +1,36 @@
1
+ //#region src/display-list/editor/pageRenderer.ts
2
+ const PAGE_RENDERER = {
3
+ /** The painter that has always painted the editor. */
4
+ legacy: "legacy",
5
+ /** Builds the paint IR from the layout and paints the pages from it. */
6
+ displayList: "display-list"
7
+ };
8
+ const isPageRendererName = (value) => value === PAGE_RENDERER.legacy || value === PAGE_RENDERER.displayList;
9
+ /**
10
+ * Read the display-list producer's furniture inputs out of the render options
11
+ * the pipeline already computed.
12
+ *
13
+ * Both sides describe the same constructs, and the pipeline is the only place
14
+ * that knows how to derive them from a package, so the display-list path reads
15
+ * what the existing path receives rather than deriving them a second time. A
16
+ * second derivation is how the two renderers would come to disagree about
17
+ * which header a page carries.
18
+ */
19
+ const displayListFurnitureFrom = (options) => ({
20
+ ...options.pageBorders === void 0 ? {} : { pageBorders: options.pageBorders },
21
+ ...options.theme === void 0 ? {} : { theme: options.theme },
22
+ ...options.watermark === void 0 ? {} : { watermark: options.watermark },
23
+ ...options.watermarkByHeaderRId === void 0 ? {} : { watermarkByHeaderRId: options.watermarkByHeaderRId },
24
+ ...options.watermarkImageSrc === void 0 ? {} : { watermarkImageSrc: options.watermarkImageSrc },
25
+ ...options.headerContent === void 0 ? {} : { headerContent: options.headerContent },
26
+ ...options.footerContent === void 0 ? {} : { footerContent: options.footerContent },
27
+ ...options.headerContentByRId === void 0 ? {} : { headerContentByRId: options.headerContentByRId },
28
+ ...options.footerContentByRId === void 0 ? {} : { footerContentByRId: options.footerContentByRId },
29
+ ...options.firstPageHeaderContent === void 0 ? {} : { firstPageHeaderContent: options.firstPageHeaderContent },
30
+ ...options.firstPageFooterContent === void 0 ? {} : { firstPageFooterContent: options.firstPageFooterContent },
31
+ ...options.titlePg === void 0 ? {} : { titlePg: options.titlePg },
32
+ ...options.headerDistance === void 0 ? {} : { headerDistancePx: options.headerDistance },
33
+ ...options.footerDistance === void 0 ? {} : { footerDistancePx: options.footerDistance }
34
+ });
35
+ //#endregion
36
+ export { PAGE_RENDERER, displayListFurnitureFrom, isPageRendererName };
@@ -0,0 +1,95 @@
1
+ import { DisplayColor, DisplayGlyphRun, DisplayHitRegion, DisplayPrimitive } from "./types.js";
2
+ import { hasCursiveLetter, joinsAcrossBoundary } from "../utils/cursiveJoining.js";
3
+ import { hasComplexScript, isComplexScriptCodePoint } from "../utils/scriptSegments.js";
4
+ //#region src/display-list/primitives.d.ts
5
+ /**
6
+ * Left edge of every code point of a run, as an offset from the run's `xPx`.
7
+ *
8
+ * One implementation for both backends. The ordering rule is prose in
9
+ * `types.ts`, and two backends reading that prose separately is the
10
+ * divergence the display list exists to prevent: a run occupies
11
+ * `[xPx, xPx + sum(advancesPx)]` whichever way it runs, so under `ltr` code
12
+ * point `i` starts at `sum(advancesPx[0..i))` and under `rtl` it ends there,
13
+ * counted back from the run's right edge. A backend adds its own origin: the
14
+ * left edge is where a glyph is placed in either direction, because a glyph
15
+ * advances rightward from its origin whatever the paragraph does.
16
+ */
17
+ declare const glyphCellOffsetsPx: (run: DisplayGlyphRun) => readonly number[];
18
+ declare const DISPLAY_PRIMITIVE_KINDS: ("glyphRun" | "rect" | "line" | "image" | "clipGroup" | "rotateGroup" | "opacityGroup")[];
19
+ /**
20
+ * Dash geometry of each stroke pattern, as multiples of the stroke thickness.
21
+ *
22
+ * `null` means the pattern is not a dash: `solid` draws one unbroken line,
23
+ * `double` two parallel lines, `wavy` a periodic curve. Sharing the factors is
24
+ * what keeps a dashed underline in the editor and a dashed underline in the
25
+ * export the same dash: with the pattern name alone, each backend would pick
26
+ * its own period and nobody would notice until the two were laid side by side.
27
+ */
28
+ declare const STROKE_DASH_FACTORS: {
29
+ readonly solid: null;
30
+ readonly dashed: {
31
+ readonly dash: 3;
32
+ readonly gap: 2;
33
+ };
34
+ readonly dotted: {
35
+ readonly dash: 1;
36
+ readonly gap: 1;
37
+ };
38
+ readonly double: null;
39
+ readonly wavy: null;
40
+ };
41
+ /**
42
+ * Gap between the two lines of a `double` stroke, as a multiple of thickness.
43
+ * Word draws the pair at the authored width with an equal gap between them.
44
+ */
45
+ declare const DOUBLE_STROKE_GAP_FACTOR = 1;
46
+ /**
47
+ * Period and peak-to-peak amplitude of a `wavy` stroke, in thicknesses.
48
+ *
49
+ * The amplitude is measured between the centres of the curve at its extremes,
50
+ * so the stroke's own thickness lies outside it: a wavy stroke's total cross
51
+ * extent is `(WAVY_STROKE_AMPLITUDE_FACTOR + 1) * thicknessPx`, centred on the
52
+ * path. Stated because "amplitude" alone leaves each backend to decide whether
53
+ * the thickness is inside or outside, and the two answers differ by a
54
+ * thickness on every wavy underline in the document.
55
+ */
56
+ declare const WAVY_STROKE_PERIOD_FACTOR = 6;
57
+ declare const WAVY_STROKE_AMPLITUDE_FACTOR = 2;
58
+ declare const BLACK: DisplayColor;
59
+ declare const WHITE: DisplayColor;
60
+ /**
61
+ * The kinds of region a click can land in, as a total map over the union: a
62
+ * new kind that is not listed fails to compile, and so does a name that is not
63
+ * a kind.
64
+ */
65
+ declare const HIT_REGION_KINDS: {
66
+ readonly pageContent: "pageContent";
67
+ readonly headerSlot: "headerSlot";
68
+ readonly footerSlot: "footerSlot";
69
+ readonly note: "note";
70
+ readonly paragraph: "paragraph";
71
+ readonly line: "line";
72
+ readonly emptyRun: "emptyRun";
73
+ readonly tab: "tab";
74
+ readonly image: "image";
75
+ readonly table: "table";
76
+ readonly tableRow: "tableRow";
77
+ readonly tableCell: "tableCell";
78
+ readonly textBox: "textBox";
79
+ };
80
+ /**
81
+ * Walk a region tree with the primitives each level owns directly.
82
+ *
83
+ * A backend that paints structure needs both, interleaved in paint order: the
84
+ * primitives before a child, then the child, then the ones after it. Reading
85
+ * the tree any other way would paint a page in an order the producer did not
86
+ * choose.
87
+ */
88
+ type RegionVisitor = {
89
+ readonly onPrimitive: (primitive: DisplayPrimitive, index: number) => void;
90
+ readonly enter: (region: DisplayHitRegion) => void;
91
+ readonly exit: (region: DisplayHitRegion) => void;
92
+ };
93
+ declare const walkRegions: (primitives: readonly DisplayPrimitive[], regions: readonly DisplayHitRegion[], visitor: RegionVisitor) => void;
94
+ //#endregion
95
+ export { BLACK, DISPLAY_PRIMITIVE_KINDS, DOUBLE_STROKE_GAP_FACTOR, HIT_REGION_KINDS, RegionVisitor, STROKE_DASH_FACTORS, WAVY_STROKE_AMPLITUDE_FACTOR, WAVY_STROKE_PERIOD_FACTOR, WHITE, glyphCellOffsetsPx, hasComplexScript, hasCursiveLetter, isComplexScriptCodePoint, joinsAcrossBoundary, walkRegions };
@@ -0,0 +1,127 @@
1
+ import { hasCursiveLetter, joinsAcrossBoundary } from "../utils/cursiveJoining.js";
2
+ import { hasComplexScript, isComplexScriptCodePoint } from "../utils/scriptSegments.js";
3
+ //#region src/display-list/primitives.ts
4
+ /**
5
+ * Left edge of every code point of a run, as an offset from the run's `xPx`.
6
+ *
7
+ * One implementation for both backends. The ordering rule is prose in
8
+ * `types.ts`, and two backends reading that prose separately is the
9
+ * divergence the display list exists to prevent: a run occupies
10
+ * `[xPx, xPx + sum(advancesPx)]` whichever way it runs, so under `ltr` code
11
+ * point `i` starts at `sum(advancesPx[0..i))` and under `rtl` it ends there,
12
+ * counted back from the run's right edge. A backend adds its own origin: the
13
+ * left edge is where a glyph is placed in either direction, because a glyph
14
+ * advances rightward from its origin whatever the paragraph does.
15
+ */
16
+ const glyphCellOffsetsPx = (run) => {
17
+ const totalPx = run.advancesPx.reduce((total, advance) => total + advance, 0);
18
+ const offsetsPx = [];
19
+ let consumedPx = 0;
20
+ for (const advancePx of run.advancesPx) {
21
+ offsetsPx.push(run.direction === "ltr" ? consumedPx : totalPx - consumedPx - advancePx);
22
+ consumedPx += advancePx;
23
+ }
24
+ return offsetsPx;
25
+ };
26
+ const DISPLAY_PRIMITIVE_KINDS = Object.values({
27
+ glyphRun: "glyphRun",
28
+ rect: "rect",
29
+ line: "line",
30
+ image: "image",
31
+ clipGroup: "clipGroup",
32
+ rotateGroup: "rotateGroup",
33
+ opacityGroup: "opacityGroup"
34
+ });
35
+ /**
36
+ * Dash geometry of each stroke pattern, as multiples of the stroke thickness.
37
+ *
38
+ * `null` means the pattern is not a dash: `solid` draws one unbroken line,
39
+ * `double` two parallel lines, `wavy` a periodic curve. Sharing the factors is
40
+ * what keeps a dashed underline in the editor and a dashed underline in the
41
+ * export the same dash: with the pattern name alone, each backend would pick
42
+ * its own period and nobody would notice until the two were laid side by side.
43
+ */
44
+ const STROKE_DASH_FACTORS = {
45
+ solid: null,
46
+ dashed: {
47
+ dash: 3,
48
+ gap: 2
49
+ },
50
+ dotted: {
51
+ dash: 1,
52
+ gap: 1
53
+ },
54
+ double: null,
55
+ wavy: null
56
+ };
57
+ /**
58
+ * Gap between the two lines of a `double` stroke, as a multiple of thickness.
59
+ * Word draws the pair at the authored width with an equal gap between them.
60
+ */
61
+ const DOUBLE_STROKE_GAP_FACTOR = 1;
62
+ /**
63
+ * Period and peak-to-peak amplitude of a `wavy` stroke, in thicknesses.
64
+ *
65
+ * The amplitude is measured between the centres of the curve at its extremes,
66
+ * so the stroke's own thickness lies outside it: a wavy stroke's total cross
67
+ * extent is `(WAVY_STROKE_AMPLITUDE_FACTOR + 1) * thicknessPx`, centred on the
68
+ * path. Stated because "amplitude" alone leaves each backend to decide whether
69
+ * the thickness is inside or outside, and the two answers differ by a
70
+ * thickness on every wavy underline in the document.
71
+ */
72
+ const WAVY_STROKE_PERIOD_FACTOR = 6;
73
+ const WAVY_STROKE_AMPLITUDE_FACTOR = 2;
74
+ const BLACK = {
75
+ r: 0,
76
+ g: 0,
77
+ b: 0,
78
+ a: 1
79
+ };
80
+ const WHITE = {
81
+ r: 255,
82
+ g: 255,
83
+ b: 255,
84
+ a: 1
85
+ };
86
+ /**
87
+ * The kinds of region a click can land in, as a total map over the union: a
88
+ * new kind that is not listed fails to compile, and so does a name that is not
89
+ * a kind.
90
+ */
91
+ const HIT_REGION_KINDS = {
92
+ pageContent: "pageContent",
93
+ headerSlot: "headerSlot",
94
+ footerSlot: "footerSlot",
95
+ note: "note",
96
+ paragraph: "paragraph",
97
+ line: "line",
98
+ emptyRun: "emptyRun",
99
+ tab: "tab",
100
+ image: "image",
101
+ table: "table",
102
+ tableRow: "tableRow",
103
+ tableCell: "tableCell",
104
+ textBox: "textBox"
105
+ };
106
+ const walkRegions = (primitives, regions, visitor) => {
107
+ const visit = (from, to, children) => {
108
+ let cursor = from;
109
+ for (const child of children) {
110
+ for (; cursor < child.from; cursor += 1) {
111
+ const primitive = primitives[cursor];
112
+ if (primitive !== void 0) visitor.onPrimitive(primitive, cursor);
113
+ }
114
+ visitor.enter(child);
115
+ visit(child.from, child.to, child.children);
116
+ visitor.exit(child);
117
+ cursor = child.to;
118
+ }
119
+ for (; cursor < to; cursor += 1) {
120
+ const primitive = primitives[cursor];
121
+ if (primitive !== void 0) visitor.onPrimitive(primitive, cursor);
122
+ }
123
+ };
124
+ visit(0, primitives.length, regions);
125
+ };
126
+ //#endregion
127
+ export { BLACK, DISPLAY_PRIMITIVE_KINDS, DOUBLE_STROKE_GAP_FACTOR, HIT_REGION_KINDS, STROKE_DASH_FACTORS, WAVY_STROKE_AMPLITUDE_FACTOR, WAVY_STROKE_PERIOD_FACTOR, WHITE, glyphCellOffsetsPx, hasComplexScript, hasCursiveLetter, isComplexScriptCodePoint, joinsAcrossBoundary, walkRegions };