@stll/folio-core 0.32.2 → 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 +649 -85
  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 +219 -15
  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 +39 -8
  100. package/dist/document-operations.js +169 -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 +3 -3
  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,163 @@
1
+ import { SFNT_VERSION, readSfntVersion, readTag } from "./tables.js";
2
+ import { Result, TaggedError } from "better-result";
3
+ import { inflateSync } from "node:zlib";
4
+ //#region src/fonts/sfnt/woff.ts
5
+ /**
6
+ * WOFF 1.0 container decoding.
7
+ *
8
+ * WOFF 1.0 is a repackaging, not a transform: each table is stored either raw
9
+ * or zlib-deflated, and the sfnt is recovered by inflating the tables and
10
+ * writing a fresh directory around them. WOFF 2.0 is a different problem (its
11
+ * `glyf`/`loca` transform has to be reversed and Brotli decoded), so it is
12
+ * rejected here rather than half-supported.
13
+ */
14
+ var WoffDecodeError = class extends TaggedError("WoffDecodeError") {};
15
+ const fail = (message) => Result.err(new WoffDecodeError({ message }));
16
+ /** Byte offsets inside the WOFF header. */
17
+ const WOFF_HEADER = {
18
+ signature: 0,
19
+ flavor: 4,
20
+ length: 8,
21
+ numTables: 12,
22
+ size: 44
23
+ };
24
+ /** Byte offsets inside a WOFF table directory entry. */
25
+ const WOFF_ENTRY = {
26
+ tag: 0,
27
+ offset: 4,
28
+ compLength: 8,
29
+ origLength: 12,
30
+ origChecksum: 16,
31
+ size: 20
32
+ };
33
+ /**
34
+ * Ceiling on a single decompressed table. Inflate is a decompression bomb
35
+ * vector, and a font table larger than this is not a font we can use anyway.
36
+ */
37
+ const MAX_TABLE_LENGTH = 1 << 27;
38
+ /**
39
+ * Ceiling on the whole decoded font. Nothing stops two directory entries from
40
+ * naming the same compressed span, so a per-table limit bounds one inflate but
41
+ * not what 65535 of them add up to. The largest faces anyone ships as web
42
+ * fonts, full CJK OpenType, decompress to some tens of megabytes; 256 MB
43
+ * clears that with room to spare and still refuses the terabytes an adversarial
44
+ * directory could otherwise claim.
45
+ */
46
+ const MAX_DECODED_FONT_LENGTH = 1 << 28;
47
+ const alignUp = (value) => Math.ceil(value / 4) * 4;
48
+ /**
49
+ * `searchRange`, `entrySelector` and `rangeShift` from the sfnt header: a
50
+ * binary-search hint derived from the table count. Wrong values do not break
51
+ * every consumer, but they do break the strict ones.
52
+ */
53
+ const searchParametersFor = (numTables) => {
54
+ let entrySelector = 0;
55
+ while (1 << entrySelector + 1 <= numTables) entrySelector += 1;
56
+ const searchRange = (1 << entrySelector) * 16;
57
+ return {
58
+ searchRange,
59
+ entrySelector,
60
+ rangeShift: numTables * 16 - searchRange
61
+ };
62
+ };
63
+ /** Assembles decoded tables into a standard sfnt, directory sorted by tag. */
64
+ const buildSfnt = (flavor, tables) => {
65
+ const sorted = [...tables].sort((left, right) => left.tag < right.tag ? -1 : 1);
66
+ const directorySize = sorted.length * 16;
67
+ const bodySize = sorted.reduce((total, table) => total + alignUp(table.data.byteLength), 0);
68
+ const output = new Uint8Array(12 + directorySize + bodySize);
69
+ const view = new DataView(output.buffer);
70
+ const { searchRange, entrySelector, rangeShift } = searchParametersFor(sorted.length);
71
+ view.setUint32(0, flavor);
72
+ view.setUint16(4, sorted.length);
73
+ view.setUint16(6, searchRange);
74
+ view.setUint16(8, entrySelector);
75
+ view.setUint16(10, rangeShift);
76
+ let entry = 12;
77
+ let dataOffset = 12 + directorySize;
78
+ for (const table of sorted) {
79
+ for (let index = 0; index < table.tag.length; index++) view.setUint8(entry + index, table.tag.charCodeAt(index));
80
+ view.setUint32(entry + 4, table.checksum);
81
+ view.setUint32(entry + 8, dataOffset);
82
+ view.setUint32(entry + 12, table.data.byteLength);
83
+ output.set(table.data, dataOffset);
84
+ dataOffset += alignUp(table.data.byteLength);
85
+ entry += 16;
86
+ }
87
+ return output;
88
+ };
89
+ const decodeWoff = (bytes) => {
90
+ if (bytes.byteLength < WOFF_HEADER.size) return fail(`WOFF header needs ${WOFF_HEADER.size} bytes, buffer has ${bytes.byteLength}`);
91
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
92
+ const signature = view.getUint32(WOFF_HEADER.signature);
93
+ if (signature !== SFNT_VERSION.woff) return fail(signature === SFNT_VERSION.woff2 ? "this is a WOFF2 container; decodeWoff only handles WOFF 1.0" : `not a WOFF container: signature 0x${signature.toString(16).padStart(8, "0")}`);
94
+ const flavor = view.getUint32(WOFF_HEADER.flavor);
95
+ const numTables = view.getUint16(WOFF_HEADER.numTables);
96
+ if (numTables === 0) return fail("WOFF declares 0 tables");
97
+ const directorySize = numTables * WOFF_ENTRY.size;
98
+ if (WOFF_HEADER.size + directorySize > bytes.byteLength) return fail(`WOFF declares ${numTables} tables, whose directory does not fit in ${bytes.byteLength} bytes`);
99
+ const entries = [];
100
+ let decodedLength = 0;
101
+ for (let index = 0; index < numTables; index++) {
102
+ const entry = WOFF_HEADER.size + index * WOFF_ENTRY.size;
103
+ const tag = readTag(view, entry + WOFF_ENTRY.tag);
104
+ const offset = view.getUint32(entry + WOFF_ENTRY.offset);
105
+ const compLength = view.getUint32(entry + WOFF_ENTRY.compLength);
106
+ const origLength = view.getUint32(entry + WOFF_ENTRY.origLength);
107
+ const checksum = view.getUint32(entry + WOFF_ENTRY.origChecksum);
108
+ if (offset + compLength > bytes.byteLength) return fail(`WOFF table '${tag}' spans [${offset}, ${offset + compLength}) outside the ${bytes.byteLength}-byte container`);
109
+ if (origLength > MAX_TABLE_LENGTH) return fail(`WOFF table '${tag}' claims ${origLength} bytes, above the decode ceiling`);
110
+ decodedLength += origLength;
111
+ if (decodedLength > MAX_DECODED_FONT_LENGTH) return fail(`WOFF directory claims ${decodedLength} decoded bytes in total, above the ${MAX_DECODED_FONT_LENGTH}-byte container ceiling`);
112
+ entries.push({
113
+ tag,
114
+ offset,
115
+ compLength,
116
+ origLength,
117
+ checksum
118
+ });
119
+ }
120
+ const tables = [];
121
+ for (const { tag, offset, compLength, origLength, checksum } of entries) {
122
+ const stored = bytes.subarray(offset, offset + compLength);
123
+ if (compLength === origLength) {
124
+ tables.push({
125
+ tag,
126
+ checksum,
127
+ data: stored
128
+ });
129
+ continue;
130
+ }
131
+ const inflated = Result.try({
132
+ try: () => inflateSync(stored, { maxOutputLength: origLength }),
133
+ catch: (cause) => new WoffDecodeError({ message: `WOFF table '${tag}' failed to inflate: ${cause instanceof Error ? cause.message : String(cause)}` })
134
+ });
135
+ if (inflated.isErr()) return Result.err(inflated.error);
136
+ if (inflated.value.byteLength !== origLength) return fail(`WOFF table '${tag}' inflated to ${inflated.value.byteLength} bytes, not the declared ${origLength}`);
137
+ tables.push({
138
+ tag,
139
+ checksum,
140
+ data: new Uint8Array(inflated.value.buffer, inflated.value.byteOffset, inflated.value.byteLength)
141
+ });
142
+ }
143
+ return Result.ok(buildSfnt(flavor, tables));
144
+ };
145
+ /**
146
+ * The entry point a caller with bytes of unknown provenance wants: plain sfnt
147
+ * passes through untouched, WOFF is decoded, WOFF2 is refused by name.
148
+ */
149
+ const toSfntBytes = (bytes) => {
150
+ const version = readSfntVersion(bytes);
151
+ if (version === void 0) return fail(`buffer is ${bytes.byteLength} bytes, too short to identify`);
152
+ switch (version) {
153
+ case SFNT_VERSION.woff: return decodeWoff(bytes);
154
+ case SFNT_VERSION.woff2: return fail("WOFF2 is not supported: its glyf/loca transform has to be reversed, which is a separate decoder");
155
+ case SFNT_VERSION.trueType:
156
+ case SFNT_VERSION.trueMac:
157
+ case SFNT_VERSION.openTypeCff:
158
+ case SFNT_VERSION.collection: return Result.ok(bytes);
159
+ default: return fail(`unrecognized font container 0x${version.toString(16).padStart(8, "0")}`);
160
+ }
161
+ };
162
+ //#endregion
163
+ export { WoffDecodeError, decodeWoff, toSfntBytes };
@@ -0,0 +1,324 @@
1
+ // @ts-nocheck -- generated and verified by build-shaper-wasm.ts
2
+ /* @ts-self-types="./text_shaper.d.ts" */
3
+
4
+ /**
5
+ * Shape one run of text with one face.
6
+ *
7
+ * Returns `[unitsPerEm, glyphCount, (glyphId, cluster, xAdvance, yAdvance,
8
+ * xOffset, yOffset) * glyphCount]` in font units.
9
+ *
10
+ * # Errors
11
+ *
12
+ * A string describing why the run could not be shaped: bytes that are not a
13
+ * readable face, or a feature tag that is not four characters. The caller gets
14
+ * a rejection rather than a run of no glyphs, which would paint as nothing.
15
+ * @param {Uint8Array} font
16
+ * @param {number} face_index
17
+ * @param {string} text
18
+ * @param {boolean} right_to_left
19
+ * @param {string} script
20
+ * @param {string} language
21
+ * @param {string[]} features_on
22
+ * @param {string[]} features_off
23
+ * @returns {Int32Array}
24
+ */
25
+ export function shapeRun(font, face_index, text, right_to_left, script, language, features_on, features_off) {
26
+ try {
27
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
28
+ const ptr0 = passArray8ToWasm0(font, wasm.__wbindgen_export);
29
+ const len0 = WASM_VECTOR_LEN;
30
+ const ptr1 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
31
+ const len1 = WASM_VECTOR_LEN;
32
+ const ptr2 = passStringToWasm0(script, wasm.__wbindgen_export, wasm.__wbindgen_export2);
33
+ const len2 = WASM_VECTOR_LEN;
34
+ const ptr3 = passStringToWasm0(language, wasm.__wbindgen_export, wasm.__wbindgen_export2);
35
+ const len3 = WASM_VECTOR_LEN;
36
+ const ptr4 = passArrayJsValueToWasm0(features_on, wasm.__wbindgen_export);
37
+ const len4 = WASM_VECTOR_LEN;
38
+ const ptr5 = passArrayJsValueToWasm0(features_off, wasm.__wbindgen_export);
39
+ const len5 = WASM_VECTOR_LEN;
40
+ wasm.shapeRun(retptr, ptr0, len0, face_index, ptr1, len1, right_to_left, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
41
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
42
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
43
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
44
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
45
+ if (r3) {
46
+ throw takeObject(r2);
47
+ }
48
+ var v7 = getArrayI32FromWasm0(r0, r1).slice();
49
+ wasm.__wbindgen_export3(r0, r1 * 4, 4);
50
+ return v7;
51
+ } finally {
52
+ wasm.__wbindgen_add_to_stack_pointer(16);
53
+ }
54
+ }
55
+ function __wbg_get_imports() {
56
+ const import0 = {
57
+ __proto__: null,
58
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
59
+ const obj = getObject(arg1);
60
+ const ret = typeof(obj) === 'string' ? obj : undefined;
61
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
62
+ var len1 = WASM_VECTOR_LEN;
63
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
64
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
65
+ },
66
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
67
+ throw new Error(getStringFromWasm0(arg0, arg1));
68
+ },
69
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
70
+ // Cast intrinsic for `Ref(String) -> Externref`.
71
+ const ret = getStringFromWasm0(arg0, arg1);
72
+ return addHeapObject(ret);
73
+ },
74
+ __wbindgen_object_drop_ref: function(arg0) {
75
+ takeObject(arg0);
76
+ },
77
+ };
78
+ return {
79
+ __proto__: null,
80
+ "./text_shaper_bg.js": import0,
81
+ };
82
+ }
83
+
84
+ function addHeapObject(obj) {
85
+ if (heap_next === heap.length) heap.push(heap.length + 1);
86
+ const idx = heap_next;
87
+ heap_next = heap[idx];
88
+
89
+ heap[idx] = obj;
90
+ return idx;
91
+ }
92
+
93
+ function dropObject(idx) {
94
+ if (idx < 1028) return;
95
+ heap[idx] = heap_next;
96
+ heap_next = idx;
97
+ }
98
+
99
+ function getArrayI32FromWasm0(ptr, len) {
100
+ ptr = ptr >>> 0;
101
+ return getInt32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
102
+ }
103
+
104
+ let cachedDataViewMemory0 = null;
105
+ function getDataViewMemory0() {
106
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
107
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
108
+ }
109
+ return cachedDataViewMemory0;
110
+ }
111
+
112
+ let cachedInt32ArrayMemory0 = null;
113
+ function getInt32ArrayMemory0() {
114
+ if (cachedInt32ArrayMemory0 === null || cachedInt32ArrayMemory0.byteLength === 0) {
115
+ cachedInt32ArrayMemory0 = new Int32Array(wasm.memory.buffer);
116
+ }
117
+ return cachedInt32ArrayMemory0;
118
+ }
119
+
120
+ function getStringFromWasm0(ptr, len) {
121
+ return decodeText(ptr >>> 0, len);
122
+ }
123
+
124
+ let cachedUint8ArrayMemory0 = null;
125
+ function getUint8ArrayMemory0() {
126
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
127
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
128
+ }
129
+ return cachedUint8ArrayMemory0;
130
+ }
131
+
132
+ function getObject(idx) { return heap[idx]; }
133
+
134
+ let heap = new Array(1024).fill(undefined);
135
+ heap.push(undefined, null, true, false);
136
+
137
+ let heap_next = heap.length;
138
+
139
+ function isLikeNone(x) {
140
+ return x === undefined || x === null;
141
+ }
142
+
143
+ function passArray8ToWasm0(arg, malloc) {
144
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
145
+ getUint8ArrayMemory0().set(arg, ptr / 1);
146
+ WASM_VECTOR_LEN = arg.length;
147
+ return ptr;
148
+ }
149
+
150
+ function passArrayJsValueToWasm0(array, malloc) {
151
+ const ptr = malloc(array.length * 4, 4) >>> 0;
152
+ const mem = getDataViewMemory0();
153
+ for (let i = 0; i < array.length; i++) {
154
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
155
+ }
156
+ WASM_VECTOR_LEN = array.length;
157
+ return ptr;
158
+ }
159
+
160
+ function passStringToWasm0(arg, malloc, realloc) {
161
+ if (realloc === undefined) {
162
+ const buf = cachedTextEncoder.encode(arg);
163
+ const ptr = malloc(buf.length, 1) >>> 0;
164
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
165
+ WASM_VECTOR_LEN = buf.length;
166
+ return ptr;
167
+ }
168
+
169
+ let len = arg.length;
170
+ let ptr = malloc(len, 1) >>> 0;
171
+
172
+ const mem = getUint8ArrayMemory0();
173
+
174
+ let offset = 0;
175
+
176
+ for (; offset < len; offset++) {
177
+ const code = arg.charCodeAt(offset);
178
+ if (code > 0x7F) break;
179
+ mem[ptr + offset] = code;
180
+ }
181
+ if (offset !== len) {
182
+ if (offset !== 0) {
183
+ arg = arg.slice(offset);
184
+ }
185
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
186
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
187
+ const ret = cachedTextEncoder.encodeInto(arg, view);
188
+
189
+ offset += ret.written;
190
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
191
+ }
192
+
193
+ WASM_VECTOR_LEN = offset;
194
+ return ptr;
195
+ }
196
+
197
+ function takeObject(idx) {
198
+ const ret = getObject(idx);
199
+ dropObject(idx);
200
+ return ret;
201
+ }
202
+
203
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
204
+ cachedTextDecoder.decode();
205
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
206
+ let numBytesDecoded = 0;
207
+ function decodeText(ptr, len) {
208
+ numBytesDecoded += len;
209
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
210
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
211
+ cachedTextDecoder.decode();
212
+ numBytesDecoded = len;
213
+ }
214
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
215
+ }
216
+
217
+ const cachedTextEncoder = new TextEncoder();
218
+
219
+ if (!('encodeInto' in cachedTextEncoder)) {
220
+ cachedTextEncoder.encodeInto = function (arg, view) {
221
+ const buf = cachedTextEncoder.encode(arg);
222
+ view.set(buf);
223
+ return {
224
+ read: arg.length,
225
+ written: buf.length
226
+ };
227
+ };
228
+ }
229
+
230
+ let WASM_VECTOR_LEN = 0;
231
+
232
+ let wasmModule, wasmInstance, wasm;
233
+ function __wbg_finalize_init(instance, module) {
234
+ wasmInstance = instance;
235
+ wasm = instance.exports;
236
+ wasmModule = module;
237
+ cachedDataViewMemory0 = null;
238
+ cachedInt32ArrayMemory0 = null;
239
+ cachedUint8ArrayMemory0 = null;
240
+ return wasm;
241
+ }
242
+
243
+ async function __wbg_load(module, imports) {
244
+ if (typeof Response === 'function' && module instanceof Response) {
245
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
246
+ try {
247
+ return await WebAssembly.instantiateStreaming(module, imports);
248
+ } catch (e) {
249
+ const validResponse = module.ok && expectedResponseType(module.type);
250
+
251
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
252
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
253
+
254
+ } else { throw e; }
255
+ }
256
+ }
257
+
258
+ const bytes = await module.arrayBuffer();
259
+ return await WebAssembly.instantiate(bytes, imports);
260
+ } else {
261
+ const instance = await WebAssembly.instantiate(module, imports);
262
+
263
+ if (instance instanceof WebAssembly.Instance) {
264
+ return { instance, module };
265
+ } else {
266
+ return instance;
267
+ }
268
+ }
269
+
270
+ function expectedResponseType(type) {
271
+ switch (type) {
272
+ case 'basic': case 'cors': case 'default': return true;
273
+ }
274
+ return false;
275
+ }
276
+ }
277
+
278
+ function initSync(module) {
279
+ if (wasm !== undefined) return wasm;
280
+
281
+
282
+ if (module !== undefined) {
283
+ if (Object.getPrototypeOf(module) === Object.prototype) {
284
+ ({module} = module)
285
+ } else {
286
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
287
+ }
288
+ }
289
+
290
+ const imports = __wbg_get_imports();
291
+ if (!(module instanceof WebAssembly.Module)) {
292
+ module = new WebAssembly.Module(module);
293
+ }
294
+ const instance = new WebAssembly.Instance(module, imports);
295
+ return __wbg_finalize_init(instance, module);
296
+ }
297
+
298
+ async function __wbg_init(module_or_path) {
299
+ if (wasm !== undefined) return wasm;
300
+
301
+
302
+ if (module_or_path !== undefined) {
303
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
304
+ ({module_or_path} = module_or_path)
305
+ } else {
306
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
307
+ }
308
+ }
309
+
310
+ if (module_or_path === undefined) {
311
+ module_or_path = new URL('./text_shaper_bg.wasm', import.meta.url);
312
+ }
313
+ const imports = __wbg_get_imports();
314
+
315
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
316
+ module_or_path = fetch(module_or_path);
317
+ }
318
+
319
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
320
+
321
+ return __wbg_finalize_init(instance, module);
322
+ }
323
+
324
+ export { initSync, __wbg_init as default };
@@ -0,0 +1,75 @@
1
+ import { document_d_exports } from "./types/document.js";
2
+ import { DocxInput } from "./utils/docxInput.js";
3
+ import { EmbeddedFont } from "./fonts/embeddedFonts.js";
4
+ import { Layout } from "./layout-engine/types.js";
5
+ import { BlockLookup } from "./layout-painter/index.js";
6
+ import { PageFurnitureInputs } from "./display-list/build/furniture.js";
7
+ import { DocumentFeatures } from "./display-list/build/buildDisplayList.js";
8
+ import { Node } from "prosemirror-model";
9
+ import { Result } from "better-result";
10
+ //#region src/headless-layout.d.ts
11
+ /**
12
+ * Constructs the painter takes from render options rather than from `Layout`.
13
+ *
14
+ * Imported from the display-list producer rather than restated, so a feature
15
+ * added there cannot silently go unreported here: the producer derives the
16
+ * shape from its own gap list, and this module has to fill whatever that list
17
+ * names.
18
+ */
19
+ type DocumentPaintFeatures = DocumentFeatures;
20
+ /** A story this entry does not paginate, named so a caller can see the hole. */
21
+ type HeadlessLayoutGap = {
22
+ readonly story: "endnote";
23
+ readonly detail: string;
24
+ };
25
+ declare const HeadlessLayoutError_base: import("better-result").TaggedErrorClass<"HeadlessLayoutError">;
26
+ declare class HeadlessLayoutError extends HeadlessLayoutError_base<{
27
+ message: string;
28
+ cause?: unknown;
29
+ }> {}
30
+ type HeadlessLayoutOptions = {
31
+ /** Gap between pages. Only a viewer cares; export passes 0. */
32
+ readonly pageGap?: number;
33
+ /**
34
+ * The instant `DATE` and `TIME` fields in a header or footer are measured
35
+ * with. Defaults to the wall clock; pass a fixed instant when two runs over
36
+ * one package must produce byte-identical output.
37
+ */
38
+ readonly now?: Date;
39
+ };
40
+ type HeadlessLayoutResult = {
41
+ readonly layout: Layout;
42
+ /** Block and measure per fragment `blockId`, as the painter expects them. */
43
+ readonly blockLookup: BlockLookup;
44
+ readonly document: document_d_exports.Document;
45
+ /**
46
+ * The editable projection the pages were laid out from. Returned because a
47
+ * fragment addresses its content by ProseMirror range, so reading a page's
48
+ * text (`getPageTextFromLayout`) is impossible without it.
49
+ */
50
+ readonly proseDoc: Node;
51
+ /**
52
+ * Whether the package authors constructs that reach the editor's painter
53
+ * through render options rather than through `Layout`. A display-list
54
+ * producer cannot see them, and needs to know whether it is reporting a real
55
+ * gap or a construct the document never had.
56
+ */
57
+ readonly documentFeatures: DocumentPaintFeatures;
58
+ /**
59
+ * The page furniture, in the shapes `buildDisplayList` takes: page borders,
60
+ * the watermark, the header and footer stories by relationship id, and the
61
+ * footnote bodies by note id. Spread it into the builder's options and the
62
+ * exported pages carry what the editor's pages carry.
63
+ */
64
+ readonly furniture: PageFurnitureInputs;
65
+ /**
66
+ * The package's own font faces, de-obfuscated. Empty when `fontTable.xml`
67
+ * declares no embedded face, so a backend that finds nothing here knows the
68
+ * document expects host fonts rather than that extraction was skipped.
69
+ */
70
+ readonly embeddedFonts: readonly EmbeddedFont[];
71
+ readonly unsupported: readonly HeadlessLayoutGap[];
72
+ };
73
+ declare const layoutDocxHeadless: (input: DocxInput, options?: HeadlessLayoutOptions) => Promise<Result<HeadlessLayoutResult, HeadlessLayoutError>>;
74
+ //#endregion
75
+ export { DocumentPaintFeatures, HeadlessLayoutError, HeadlessLayoutGap, HeadlessLayoutOptions, HeadlessLayoutResult, layoutDocxHeadless };