@portone/docx-editor 0.1.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 (347) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/CONTRIBUTING.md +63 -0
  3. package/LICENSE +203 -0
  4. package/README.md +48 -0
  5. package/assets/editor.png +0 -0
  6. package/dist/DocxEditor.d.ts +123 -0
  7. package/dist/DocxEditor.js +348 -0
  8. package/dist/core.d.ts +36 -0
  9. package/dist/core.js +38 -0
  10. package/dist/docx/comments/constants.d.ts +8 -0
  11. package/dist/docx/comments/constants.js +20 -0
  12. package/dist/docx/comments/model.d.ts +37 -0
  13. package/dist/docx/comments/model.js +104 -0
  14. package/dist/docx/comments/reading.d.ts +36 -0
  15. package/dist/docx/comments/reading.js +149 -0
  16. package/dist/docx/comments/writing.d.ts +11 -0
  17. package/dist/docx/comments/writing.js +327 -0
  18. package/dist/docx/comments.d.ts +3 -0
  19. package/dist/docx/comments.js +4 -0
  20. package/dist/docx/container.d.ts +12 -0
  21. package/dist/docx/container.js +130 -0
  22. package/dist/docx/documentSettings.d.ts +4 -0
  23. package/dist/docx/documentSettings.js +14 -0
  24. package/dist/docx/exportDocx.d.ts +15 -0
  25. package/dist/docx/exportDocx.js +163 -0
  26. package/dist/docx/exportRefs.d.ts +16 -0
  27. package/dist/docx/exportRefs.js +10 -0
  28. package/dist/docx/formatting/direct.d.ts +30 -0
  29. package/dist/docx/formatting/direct.js +201 -0
  30. package/dist/docx/formatting/effectiveParagraph.d.ts +15 -0
  31. package/dist/docx/formatting/effectiveParagraph.js +81 -0
  32. package/dist/docx/formatting/styles.d.ts +67 -0
  33. package/dist/docx/formatting/styles.js +165 -0
  34. package/dist/docx/formatting/tabStops.d.ts +8 -0
  35. package/dist/docx/formatting/tabStops.js +65 -0
  36. package/dist/docx/formatting.d.ts +4 -0
  37. package/dist/docx/formatting.js +4 -0
  38. package/dist/docx/headersFooters.d.ts +36 -0
  39. package/dist/docx/headersFooters.js +218 -0
  40. package/dist/docx/hyperlink.d.ts +75 -0
  41. package/dist/docx/hyperlink.js +71 -0
  42. package/dist/docx/importDocx.d.ts +21 -0
  43. package/dist/docx/importDocx.js +263 -0
  44. package/dist/docx/importParagraph.d.ts +32 -0
  45. package/dist/docx/importParagraph.js +308 -0
  46. package/dist/docx/importTable.d.ts +9 -0
  47. package/dist/docx/importTable.js +275 -0
  48. package/dist/docx/media.d.ts +60 -0
  49. package/dist/docx/media.js +213 -0
  50. package/dist/docx/notes.d.ts +22 -0
  51. package/dist/docx/notes.js +71 -0
  52. package/dist/docx/pageGeometry.d.ts +75 -0
  53. package/dist/docx/pageGeometry.js +88 -0
  54. package/dist/docx/paraProps.d.ts +74 -0
  55. package/dist/docx/paraProps.js +167 -0
  56. package/dist/docx/propsXml.d.ts +49 -0
  57. package/dist/docx/propsXml.js +302 -0
  58. package/dist/docx/relationships.d.ts +42 -0
  59. package/dist/docx/relationships.js +94 -0
  60. package/dist/docx/runProps.d.ts +51 -0
  61. package/dist/docx/runProps.js +207 -0
  62. package/dist/docx/scan.d.ts +20 -0
  63. package/dist/docx/scan.js +110 -0
  64. package/dist/docx/sdt.d.ts +56 -0
  65. package/dist/docx/sdt.js +104 -0
  66. package/dist/docx/sdtProps.d.ts +18 -0
  67. package/dist/docx/sdtProps.js +11 -0
  68. package/dist/docx/serializeBlock.d.ts +4 -0
  69. package/dist/docx/serializeBlock.js +30 -0
  70. package/dist/docx/serializeParagraph.d.ts +15 -0
  71. package/dist/docx/serializeParagraph.js +208 -0
  72. package/dist/docx/serializeTable.d.ts +12 -0
  73. package/dist/docx/serializeTable.js +134 -0
  74. package/dist/docx/session.d.ts +81 -0
  75. package/dist/docx/session.js +79 -0
  76. package/dist/docx/tableFormatting/editing.d.ts +64 -0
  77. package/dist/docx/tableFormatting/editing.js +318 -0
  78. package/dist/docx/tableFormatting/reading.d.ts +96 -0
  79. package/dist/docx/tableFormatting/reading.js +221 -0
  80. package/dist/docx/tableFormatting.d.ts +2 -0
  81. package/dist/docx/tableFormatting.js +3 -0
  82. package/dist/docx/tableTemplate.d.ts +22 -0
  83. package/dist/docx/tableTemplate.js +111 -0
  84. package/dist/docx/theme.d.ts +40 -0
  85. package/dist/docx/theme.js +61 -0
  86. package/dist/docx/uniqueControls.d.ts +14 -0
  87. package/dist/docx/uniqueControls.js +62 -0
  88. package/dist/download.d.ts +57 -0
  89. package/dist/download.js +44 -0
  90. package/dist/editor/clipboard/images.d.ts +14 -0
  91. package/dist/editor/clipboard/images.js +158 -0
  92. package/dist/editor/clipboard/inlineFormatting.d.ts +21 -0
  93. package/dist/editor/clipboard/inlineFormatting.js +232 -0
  94. package/dist/editor/commands/breakCommands.d.ts +8 -0
  95. package/dist/editor/commands/breakCommands.js +19 -0
  96. package/dist/editor/commands/canRunCommand.d.ts +6 -0
  97. package/dist/editor/commands/canRunCommand.js +10 -0
  98. package/dist/editor/commands/commentCommands.d.ts +3 -0
  99. package/dist/editor/commands/commentCommands.js +4 -0
  100. package/dist/editor/commands/comments/editing.d.ts +21 -0
  101. package/dist/editor/commands/comments/editing.js +305 -0
  102. package/dist/editor/commands/comments/model.d.ts +31 -0
  103. package/dist/editor/commands/comments/model.js +0 -0
  104. package/dist/editor/commands/comments/reading.d.ts +8 -0
  105. package/dist/editor/commands/comments/reading.js +58 -0
  106. package/dist/editor/commands/formatting/editing.d.ts +32 -0
  107. package/dist/editor/commands/formatting/editing.js +138 -0
  108. package/dist/editor/commands/formatting/reading.d.ts +57 -0
  109. package/dist/editor/commands/formatting/reading.js +82 -0
  110. package/dist/editor/commands/formatting/shared.d.ts +32 -0
  111. package/dist/editor/commands/formatting/shared.js +53 -0
  112. package/dist/editor/commands/formattingCommands.d.ts +2 -0
  113. package/dist/editor/commands/formattingCommands.js +3 -0
  114. package/dist/editor/commands/historyCommands.d.ts +11 -0
  115. package/dist/editor/commands/historyCommands.js +16 -0
  116. package/dist/editor/commands/indentCommands.d.ts +15 -0
  117. package/dist/editor/commands/indentCommands.js +44 -0
  118. package/dist/editor/commands/index.d.ts +82 -0
  119. package/dist/editor/commands/index.js +171 -0
  120. package/dist/editor/commands/linkCommands.d.ts +56 -0
  121. package/dist/editor/commands/linkCommands.js +146 -0
  122. package/dist/editor/commands/listCommands.d.ts +58 -0
  123. package/dist/editor/commands/listCommands.js +140 -0
  124. package/dist/editor/commands/lockCommands.d.ts +47 -0
  125. package/dist/editor/commands/lockCommands.js +198 -0
  126. package/dist/editor/commands/noteQueries.d.ts +12 -0
  127. package/dist/editor/commands/noteQueries.js +29 -0
  128. package/dist/editor/commands/paragraphCommands.d.ts +59 -0
  129. package/dist/editor/commands/paragraphCommands.js +113 -0
  130. package/dist/editor/commands/spacingCommands.d.ts +23 -0
  131. package/dist/editor/commands/spacingCommands.js +48 -0
  132. package/dist/editor/commands/tabCommands.d.ts +5 -0
  133. package/dist/editor/commands/tabCommands.js +65 -0
  134. package/dist/editor/createEditor.d.ts +59 -0
  135. package/dist/editor/createEditor.js +160 -0
  136. package/dist/editor/documentStyles.d.ts +60 -0
  137. package/dist/editor/documentStyles.js +80 -0
  138. package/dist/editor/externalClipboard.d.ts +11 -0
  139. package/dist/editor/externalClipboard.js +323 -0
  140. package/dist/editor/imageFiles.d.ts +74 -0
  141. package/dist/editor/imageFiles.js +173 -0
  142. package/dist/editor/insertImage.d.ts +31 -0
  143. package/dist/editor/insertImage.js +35 -0
  144. package/dist/editor/insertTable.d.ts +18 -0
  145. package/dist/editor/insertTable.js +44 -0
  146. package/dist/editor/paragraphEdits.d.ts +42 -0
  147. package/dist/editor/paragraphEdits.js +59 -0
  148. package/dist/editor/plainText.d.ts +3 -0
  149. package/dist/editor/plainText.js +50 -0
  150. package/dist/editor/plugins/bookmarkProtection.d.ts +3 -0
  151. package/dist/editor/plugins/bookmarkProtection.js +28 -0
  152. package/dist/editor/plugins/columnResize.d.ts +27 -0
  153. package/dist/editor/plugins/columnResize.js +192 -0
  154. package/dist/editor/plugins/commentDecorations.d.ts +3 -0
  155. package/dist/editor/plugins/commentDecorations.js +23 -0
  156. package/dist/editor/plugins/commentReservations.d.ts +5 -0
  157. package/dist/editor/plugins/commentReservations.js +26 -0
  158. package/dist/editor/plugins/dropCaret.d.ts +10 -0
  159. package/dist/editor/plugins/dropCaret.js +11 -0
  160. package/dist/editor/plugins/imagePaste.d.ts +8 -0
  161. package/dist/editor/plugins/imagePaste.js +265 -0
  162. package/dist/editor/plugins/keymap.d.ts +5 -0
  163. package/dist/editor/plugins/keymap.js +94 -0
  164. package/dist/editor/plugins/linkPanel.d.ts +23 -0
  165. package/dist/editor/plugins/linkPanel.js +39 -0
  166. package/dist/editor/plugins/listInputRules.d.ts +14 -0
  167. package/dist/editor/plugins/listInputRules.js +36 -0
  168. package/dist/editor/plugins/lockedContent.d.ts +6 -0
  169. package/dist/editor/plugins/lockedContent.js +41 -0
  170. package/dist/editor/plugins/noteProtection.d.ts +3 -0
  171. package/dist/editor/plugins/noteProtection.js +25 -0
  172. package/dist/editor/plugins/numberingDecorations.d.ts +42 -0
  173. package/dist/editor/plugins/numberingDecorations.js +110 -0
  174. package/dist/editor/plugins/rowResize.d.ts +15 -0
  175. package/dist/editor/plugins/rowResize.js +196 -0
  176. package/dist/editor/plugins/styledParagraphs.d.ts +15 -0
  177. package/dist/editor/plugins/styledParagraphs.js +65 -0
  178. package/dist/editor/plugins/tabCaret.d.ts +3 -0
  179. package/dist/editor/plugins/tabCaret.js +126 -0
  180. package/dist/editor/plugins/tabDecorations.d.ts +11 -0
  181. package/dist/editor/plugins/tabDecorations.js +87 -0
  182. package/dist/editor/plugins/tabLayout.d.ts +16 -0
  183. package/dist/editor/plugins/tabLayout.js +328 -0
  184. package/dist/editor/plugins/tabPointer.d.ts +7 -0
  185. package/dist/editor/plugins/tabPointer.js +95 -0
  186. package/dist/editor/plugins/tableContextMenu.d.ts +21 -0
  187. package/dist/editor/plugins/tableContextMenu.js +88 -0
  188. package/dist/editor/plugins/textContextMenu.d.ts +15 -0
  189. package/dist/editor/plugins/textContextMenu.js +90 -0
  190. package/dist/editor/views/imageResize.d.ts +53 -0
  191. package/dist/editor/views/imageResize.js +167 -0
  192. package/dist/editor/views/runMarkView.d.ts +15 -0
  193. package/dist/editor/views/runMarkView.js +9 -0
  194. package/dist/editor/views/tableView.d.ts +24 -0
  195. package/dist/editor/views/tableView.js +32 -0
  196. package/dist/index.d.ts +44 -0
  197. package/dist/index.js +38 -0
  198. package/dist/model/format.d.ts +240 -0
  199. package/dist/model/format.js +305 -0
  200. package/dist/model/tabStops.d.ts +17 -0
  201. package/dist/model/tabStops.js +22 -0
  202. package/dist/numbering/listTemplate.d.ts +29 -0
  203. package/dist/numbering/listTemplate.js +83 -0
  204. package/dist/numbering/markers.d.ts +24 -0
  205. package/dist/numbering/markers.js +93 -0
  206. package/dist/numbering/parseNumbering.d.ts +65 -0
  207. package/dist/numbering/parseNumbering.js +116 -0
  208. package/dist/numbering/writeNumbering.d.ts +13 -0
  209. package/dist/numbering/writeNumbering.js +49 -0
  210. package/dist/ooxml/errors.d.ts +39 -0
  211. package/dist/ooxml/errors.js +21 -0
  212. package/dist/ooxml/image.d.ts +88 -0
  213. package/dist/ooxml/image.js +106 -0
  214. package/dist/ooxml/tabStops.d.ts +3 -0
  215. package/dist/ooxml/tabStops.js +51 -0
  216. package/dist/ooxml/units.d.ts +37 -0
  217. package/dist/ooxml/units.js +116 -0
  218. package/dist/ooxml/xml.d.ts +36 -0
  219. package/dist/ooxml/xml.js +89 -0
  220. package/dist/page/PageGuides.d.ts +16 -0
  221. package/dist/page/PageGuides.js +114 -0
  222. package/dist/page/measureBlocks.d.ts +25 -0
  223. package/dist/page/measureBlocks.js +80 -0
  224. package/dist/page/pageDecorations.d.ts +36 -0
  225. package/dist/page/pageDecorations.js +211 -0
  226. package/dist/page/pageLayout.d.ts +176 -0
  227. package/dist/page/pageLayout.js +157 -0
  228. package/dist/page/tableMeasurements.d.ts +10 -0
  229. package/dist/page/tableMeasurements.js +115 -0
  230. package/dist/page/usePageLayout.d.ts +57 -0
  231. package/dist/page/usePageLayout.js +141 -0
  232. package/dist/schema/docxSchema.d.ts +9 -0
  233. package/dist/schema/docxSchema.js +863 -0
  234. package/dist/schema/index.d.ts +2 -0
  235. package/dist/schema/index.js +9 -0
  236. package/dist/schema/locks.d.ts +112 -0
  237. package/dist/schema/locks.js +211 -0
  238. package/dist/schema/rendering.d.ts +6 -0
  239. package/dist/schema/rendering.js +46 -0
  240. package/dist/styles/classNames.d.ts +214 -0
  241. package/dist/styles/classNames.js +208 -0
  242. package/dist/styles/colors.d.ts +11 -0
  243. package/dist/styles/colors.js +14 -0
  244. package/dist/styles/fontSizes.d.ts +6 -0
  245. package/dist/styles/fontSizes.js +20 -0
  246. package/dist/styles/fontStack.d.ts +55 -0
  247. package/dist/styles/fontStack.js +262 -0
  248. package/dist/styles/fonts.d.ts +6 -0
  249. package/dist/styles/fonts.js +11 -0
  250. package/dist/styles/inlineStyle.d.ts +67 -0
  251. package/dist/styles/inlineStyle.js +212 -0
  252. package/dist/styles/lineSpacings.d.ts +11 -0
  253. package/dist/styles/lineSpacings.js +10 -0
  254. package/dist/styles.css +1650 -0
  255. package/dist/table/cellBorders.d.ts +12 -0
  256. package/dist/table/cellBorders.js +9 -0
  257. package/dist/table/cellFormatting.d.ts +57 -0
  258. package/dist/table/cellFormatting.js +173 -0
  259. package/dist/table/columns.d.ts +25 -0
  260. package/dist/table/columns.js +155 -0
  261. package/dist/table/commands.d.ts +19 -0
  262. package/dist/table/commands.js +63 -0
  263. package/dist/table/format.d.ts +35 -0
  264. package/dist/table/format.js +26 -0
  265. package/dist/table/gridBorders.d.ts +42 -0
  266. package/dist/table/gridBorders.js +192 -0
  267. package/dist/table/index.d.ts +16 -0
  268. package/dist/table/index.js +52 -0
  269. package/dist/table/merge.d.ts +36 -0
  270. package/dist/table/merge.js +125 -0
  271. package/dist/table/resize.d.ts +55 -0
  272. package/dist/table/resize.js +66 -0
  273. package/dist/table/rowResize.d.ts +14 -0
  274. package/dist/table/rowResize.js +44 -0
  275. package/dist/table/rows.d.ts +32 -0
  276. package/dist/table/rows.js +89 -0
  277. package/dist/table/widths.d.ts +69 -0
  278. package/dist/table/widths.js +97 -0
  279. package/dist/ui/AlignMenu.d.ts +15 -0
  280. package/dist/ui/AlignMenu.js +64 -0
  281. package/dist/ui/CellStyleGroup.d.ts +15 -0
  282. package/dist/ui/CellStyleGroup.js +232 -0
  283. package/dist/ui/ColorPicker.d.ts +13 -0
  284. package/dist/ui/ColorPicker.js +165 -0
  285. package/dist/ui/CommentsPanel.d.ts +15 -0
  286. package/dist/ui/CommentsPanel.js +348 -0
  287. package/dist/ui/FontFamilySelect.d.ts +14 -0
  288. package/dist/ui/FontFamilySelect.js +59 -0
  289. package/dist/ui/FontSizeSelect.d.ts +11 -0
  290. package/dist/ui/FontSizeSelect.js +49 -0
  291. package/dist/ui/InsertImageButton.d.ts +9 -0
  292. package/dist/ui/InsertImageButton.js +47 -0
  293. package/dist/ui/LinkCard.d.ts +12 -0
  294. package/dist/ui/LinkCard.js +127 -0
  295. package/dist/ui/LinkPanel.d.ts +9 -0
  296. package/dist/ui/LinkPanel.js +121 -0
  297. package/dist/ui/MenuChoice.d.ts +11 -0
  298. package/dist/ui/MenuChoice.js +32 -0
  299. package/dist/ui/NotesPanel.d.ts +6 -0
  300. package/dist/ui/NotesPanel.js +33 -0
  301. package/dist/ui/ParagraphStyleSelect.d.ts +11 -0
  302. package/dist/ui/ParagraphStyleSelect.js +62 -0
  303. package/dist/ui/Popover.d.ts +22 -0
  304. package/dist/ui/Popover.js +74 -0
  305. package/dist/ui/SpacingMenu.d.ts +12 -0
  306. package/dist/ui/SpacingMenu.js +54 -0
  307. package/dist/ui/TableMenu.d.ts +12 -0
  308. package/dist/ui/TableMenu.js +112 -0
  309. package/dist/ui/TableSizePicker.d.ts +9 -0
  310. package/dist/ui/TableSizePicker.js +53 -0
  311. package/dist/ui/TextMenu.d.ts +15 -0
  312. package/dist/ui/TextMenu.js +194 -0
  313. package/dist/ui/Toolbar.d.ts +19 -0
  314. package/dist/ui/Toolbar.js +448 -0
  315. package/dist/ui/ToolbarButton.d.ts +23 -0
  316. package/dist/ui/ToolbarButton.js +56 -0
  317. package/dist/ui/Tooltip.d.ts +19 -0
  318. package/dist/ui/Tooltip.js +47 -0
  319. package/dist/ui/ZoomSelect.d.ts +7 -0
  320. package/dist/ui/ZoomSelect.js +44 -0
  321. package/dist/ui/comments/CommentComposer.d.ts +17 -0
  322. package/dist/ui/comments/CommentComposer.js +59 -0
  323. package/dist/ui/comments/useCommentRailLayout.d.ts +18 -0
  324. package/dist/ui/comments/useCommentRailLayout.js +183 -0
  325. package/dist/ui/keyboardWalk.d.ts +22 -0
  326. package/dist/ui/keyboardWalk.js +70 -0
  327. package/dist/ui/openAddress.d.ts +11 -0
  328. package/dist/ui/openAddress.js +16 -0
  329. package/dist/ui/panelPlacement.d.ts +51 -0
  330. package/dist/ui/panelPlacement.js +71 -0
  331. package/dist/ui/presets.d.ts +11 -0
  332. package/dist/ui/presets.js +0 -0
  333. package/dist/ui/rovingFocus.d.ts +20 -0
  334. package/dist/ui/rovingFocus.js +61 -0
  335. package/dist/ui/runCommand.d.ts +5 -0
  336. package/dist/ui/runCommand.js +13 -0
  337. package/dist/ui/useDismiss.d.ts +6 -0
  338. package/dist/ui/useDismiss.js +31 -0
  339. package/dist/ui/useFitWidthZoom.d.ts +2 -0
  340. package/dist/ui/useFitWidthZoom.js +26 -0
  341. package/dist/ui/useGridKeyboard.d.ts +12 -0
  342. package/dist/ui/useGridKeyboard.js +90 -0
  343. package/dist/ui/useMenuKeyboard.d.ts +12 -0
  344. package/dist/ui/useMenuKeyboard.js +56 -0
  345. package/dist/ui/zoom.d.ts +4 -0
  346. package/dist/ui/zoom.js +21 -0
  347. package/package.json +120 -0
@@ -0,0 +1,263 @@
1
+ // src/docx/importDocx.ts
2
+ import { Fragment } from "prosemirror-model";
3
+ import { toRunFormat } from "../model/format.js";
4
+ import { parseNumbering } from "../numbering/parseNumbering.js";
5
+ import { DocxImportError } from "../ooxml/errors.js";
6
+ import {
7
+ childByLocalName,
8
+ decodeUtf8,
9
+ elementChildren,
10
+ localPart,
11
+ parseXml,
12
+ R_NS
13
+ } from "../ooxml/xml.js";
14
+ import { docxSchema } from "../schema/index.js";
15
+ import { commentReferencesIn, readComments } from "./comments.js";
16
+ import { openParts } from "./container.js";
17
+ import { DEFAULT_TAB_STOP_PT, readDefaultTabStop } from "./documentSettings.js";
18
+ import {
19
+ defaultParagraphStyleIdOf,
20
+ defaultTableStyleIdOf,
21
+ effectiveParagraphFormat,
22
+ effectiveParagraphStyle,
23
+ layerRunFormat,
24
+ NO_DOCUMENT_DEFAULTS,
25
+ NO_STYLES,
26
+ readDefaultParagraphFormat,
27
+ readDocumentDefaults,
28
+ readParagraphStyles,
29
+ readStyles
30
+ } from "./formatting.js";
31
+ import { readHeadersFooters } from "./headersFooters.js";
32
+ import { readLinkTargets } from "./hyperlink.js";
33
+ import { buildParagraph } from "./importParagraph.js";
34
+ import { buildTable } from "./importTable.js";
35
+ import { readImageSources } from "./media.js";
36
+ import { readNotes } from "./notes.js";
37
+ import { readBodyGeometry } from "./pageGeometry.js";
38
+ import { resolveTarget } from "./relationships.js";
39
+ import { scanBody } from "./scan.js";
40
+ import { SessionStore } from "./session.js";
41
+ import { NO_THEME_FONTS, readThemeFonts } from "./theme.js";
42
+ var OFFICE_DOCUMENT_REL = `${R_NS}/officeDocument`;
43
+ var STYLES_REL = `${R_NS}/styles`;
44
+ var NUMBERING_REL = `${R_NS}/numbering`;
45
+ var THEME_REL = `${R_NS}/theme`;
46
+ var SETTINGS_REL = `${R_NS}/settings`;
47
+ function relationshipTarget(parts, relsPath, type) {
48
+ const rels = parts.get(relsPath);
49
+ if (!rels) return null;
50
+ for (const rel of elementChildren(
51
+ parseXml(decodeUtf8(rels).text).documentElement
52
+ )) {
53
+ if (rel.getAttribute("Type") === type) return rel.getAttribute("Target");
54
+ }
55
+ return null;
56
+ }
57
+ function findMainPartPath(parts) {
58
+ const target = relationshipTarget(parts, "_rels/.rels", OFFICE_DOCUMENT_REL);
59
+ if (!target) {
60
+ throw new DocxImportError(
61
+ "missing-part",
62
+ "no relationship pointing at the main document part"
63
+ );
64
+ }
65
+ return target.replace(/^\//, "");
66
+ }
67
+ function relatedPartPath(parts, mainPartPath, type) {
68
+ const directory = mainPartPath.replace(/[^/]+$/, "");
69
+ const fileName = mainPartPath.slice(directory.length);
70
+ const target = relationshipTarget(
71
+ parts,
72
+ `${directory}_rels/${fileName}.rels`,
73
+ type
74
+ );
75
+ if (!target) return null;
76
+ return resolveTarget(mainPartPath, target);
77
+ }
78
+ function readPart(parts, path) {
79
+ const bytes = path === null ? void 0 : parts.get(path);
80
+ return bytes ? decodeUtf8(bytes).text : null;
81
+ }
82
+ function buildBlock(el, srcId, sources, styles, defaultTableStyleId) {
83
+ if (el.localName === "bookmarkStart" || el.localName === "bookmarkEnd") {
84
+ return docxSchema.nodes.bookmarkBlock.create({
85
+ srcId,
86
+ name: el.nodeName
87
+ });
88
+ }
89
+ if (el.localName === "p") {
90
+ const paragraph = buildParagraph(el, srcId, sources);
91
+ if (paragraph) return paragraph;
92
+ }
93
+ if (el.localName === "tbl") {
94
+ const table = buildTable(el, srcId, sources, styles, defaultTableStyleId);
95
+ if (table) return table;
96
+ }
97
+ return docxSchema.nodes.docxRaw.create({ srcId, name: el.nodeName });
98
+ }
99
+ function styledInline(node, style) {
100
+ const mark = node.marks.find((entry) => entry.type === docxSchema.marks.run);
101
+ if (!mark) return node;
102
+ const format = layerRunFormat(style, toRunFormat(mark.attrs.format));
103
+ const next = mark.type.create({ ...mark.attrs, format });
104
+ return node.mark(next.addToSet(node.marks));
105
+ }
106
+ function styledParagraph(node, context) {
107
+ const style = effectiveParagraphStyle(node.attrs.pPr, context);
108
+ const inline = style ? node.children.map((child) => styledInline(child, style.run)) : node.children;
109
+ return node.type.create(
110
+ {
111
+ ...node.attrs,
112
+ format: effectiveParagraphFormat(node.attrs.pPr, context),
113
+ styleRun: style ? layerRunFormat(style.run, null) : null
114
+ },
115
+ Fragment.fromArray(inline),
116
+ node.marks
117
+ );
118
+ }
119
+ function withStyleFormats(node, context) {
120
+ if (node.type === docxSchema.nodes.paragraph) {
121
+ return styledParagraph(node, context);
122
+ }
123
+ if (node.childCount === 0) return node;
124
+ const children = node.children.map(
125
+ (child) => withStyleFormats(child, context)
126
+ );
127
+ if (children.every((child, i) => child === node.child(i))) return node;
128
+ return node.copy(Fragment.fromArray(children));
129
+ }
130
+ function assertScanMatchesDom(children, scan) {
131
+ if (children.length !== scan.blocks.length) {
132
+ throw new DocxImportError(
133
+ "malformed-xml",
134
+ "the body block count differs between the scan and the DOM"
135
+ );
136
+ }
137
+ children.forEach((el, i) => {
138
+ if (el.nodeName !== scan.blocks[i].name) {
139
+ throw new DocxImportError(
140
+ "malformed-xml",
141
+ `body block names disagree: ${el.nodeName} vs ${scan.blocks[i].name}`
142
+ );
143
+ }
144
+ });
145
+ }
146
+ function foldTrailingSectPr(scan) {
147
+ const last = scan.blocks.at(-1);
148
+ if (scan.blocks.length < 2 || !last) return scan;
149
+ if (localPart(last.name) !== "sectPr") return scan;
150
+ return {
151
+ prefix: scan.prefix,
152
+ blocks: scan.blocks.slice(0, -1),
153
+ suffix: last.xml + scan.suffix
154
+ };
155
+ }
156
+ function importDocx(input) {
157
+ const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
158
+ const parts = openParts(bytes);
159
+ const mainPartPath = findMainPartPath(parts);
160
+ const mainPart = parts.get(mainPartPath);
161
+ if (!mainPart) {
162
+ throw new DocxImportError("missing-part", `${mainPartPath} is missing`);
163
+ }
164
+ const { text: source, hadBom } = decodeUtf8(mainPart);
165
+ const scanned = scanBody(source);
166
+ const dom = parseXml(source);
167
+ const body = childByLocalName(dom.documentElement, "body");
168
+ if (!body) {
169
+ throw new DocxImportError("missing-body", "document has no w:body");
170
+ }
171
+ const children = elementChildren(body);
172
+ assertScanMatchesDom(children, scanned);
173
+ const geometry = readBodyGeometry(body);
174
+ const scan = foldTrailingSectPr(scanned);
175
+ const blockElements = children.slice(0, scan.blocks.length);
176
+ const stylesXml = readPart(
177
+ parts,
178
+ relatedPartPath(parts, mainPartPath, STYLES_REL)
179
+ );
180
+ const stylesDom = stylesXml === null ? null : parseXml(stylesXml);
181
+ const settingsXml = readPart(
182
+ parts,
183
+ relatedPartPath(parts, mainPartPath, SETTINGS_REL)
184
+ );
185
+ const defaultTabStopPt = readDefaultTabStop(settingsXml === null ? null : parseXml(settingsXml)) ?? DEFAULT_TAB_STOP_PT;
186
+ const numberingPartPath = relatedPartPath(parts, mainPartPath, NUMBERING_REL);
187
+ const themeXml = readPart(
188
+ parts,
189
+ relatedPartPath(parts, mainPartPath, THEME_REL)
190
+ );
191
+ const themeFonts = themeXml === null ? NO_THEME_FONTS : readThemeFonts(parseXml(themeXml));
192
+ const styles = stylesDom ? readStyles(stylesDom, themeFonts) : NO_STYLES;
193
+ const defaultTableStyleId = stylesDom ? defaultTableStyleIdOf(stylesDom) : null;
194
+ const defaultParagraphStyleId = stylesDom ? defaultParagraphStyleIdOf(stylesDom) : null;
195
+ const paragraphDefaults = stylesDom ? readDefaultParagraphFormat(stylesDom) : {};
196
+ const numberingXml = readPart(parts, numberingPartPath);
197
+ const numbering = parseNumbering(numberingXml);
198
+ const paragraphFormatting = {
199
+ styles,
200
+ defaultStyleId: defaultParagraphStyleId,
201
+ defaults: paragraphDefaults,
202
+ numbering
203
+ };
204
+ const comments = readComments(parts, mainPartPath);
205
+ const notes = readNotes(parts, mainPartPath);
206
+ const noteLabels = {
207
+ footnote: /* @__PURE__ */ new Map(),
208
+ endnote: /* @__PURE__ */ new Map()
209
+ };
210
+ const noteLabel = (kind, id) => {
211
+ const labels = noteLabels[kind];
212
+ const existing = labels.get(id);
213
+ if (existing) return existing;
214
+ const label = `${labels.size + 1}`;
215
+ labels.set(id, label);
216
+ return label;
217
+ };
218
+ const headersFooters = readHeadersFooters(parts, mainPartPath, body);
219
+ const sources = {
220
+ images: readImageSources(parts, mainPartPath),
221
+ themeFonts,
222
+ links: readLinkTargets(parts, mainPartPath),
223
+ comments,
224
+ notes,
225
+ noteLabel
226
+ };
227
+ const blockNodes = blockElements.map(
228
+ (el, i) => withStyleFormats(
229
+ buildBlock(el, i, sources, styles, defaultTableStyleId),
230
+ paragraphFormatting
231
+ )
232
+ );
233
+ return {
234
+ doc: docxSchema.nodes.doc.create(null, blockNodes),
235
+ session: new SessionStore({
236
+ parts,
237
+ mainPartPath,
238
+ documentPrefix: scan.prefix,
239
+ documentSuffix: scan.suffix,
240
+ documentHadBom: hadBom,
241
+ blocks: blockNodes.map((node, i) => ({ xml: scan.blocks[i].xml, node })),
242
+ defaults: stylesDom ? readDocumentDefaults(stylesDom, themeFonts) : NO_DOCUMENT_DEFAULTS,
243
+ defaultTabStopPt,
244
+ paragraphDefaults,
245
+ geometry,
246
+ styles,
247
+ paragraphStyles: stylesDom ? readParagraphStyles(stylesDom) : [],
248
+ defaultParagraphStyleId,
249
+ numberingXml,
250
+ numberingPartPath,
251
+ comments,
252
+ commentReferenceIds: new Set(
253
+ commentReferencesIn(
254
+ docxSchema.nodes.doc.create(null, blockNodes)
255
+ ).keys()
256
+ ),
257
+ headersFooters
258
+ })
259
+ };
260
+ }
261
+ export {
262
+ importDocx
263
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Moves a single `<w:p>` into an editable paragraph node.
3
+ *
4
+ * Body paragraphs and paragraphs inside table cells take the same path.
5
+ *
6
+ * A `w:sdt` content control and a `w:hyperlink` standing inside the paragraph are both unwrapped, so
7
+ * the text they hold stays editable, and the wrapper each came in rides along on a mark to go back
8
+ * out around the same text. A control may hold a link; a link holding a control is a nesting the
9
+ * marks cannot record in that order, so the paragraph stays preserved.
10
+ */
11
+ import type { Node as PMNode } from "prosemirror-model";
12
+ import { type ImportedComments } from "./comments";
13
+ import { type LinkTargets } from "./hyperlink";
14
+ import type { ImageSources } from "./media";
15
+ import { type ImportedNotes, type NoteKind } from "./notes";
16
+ import { type ThemeFonts } from "./theme";
17
+ /**
18
+ * What the body is read with: the images its drawings can point at, the fonts a theme reference
19
+ * resolves to, the addresses its links can point at, and the bodies of its comments and notes.
20
+ * They travel together from `docx/importDocx` down through the tables to here.
21
+ */
22
+ export interface ImportSources {
23
+ images: ImageSources;
24
+ themeFonts: ThemeFonts;
25
+ links: LinkTargets;
26
+ comments: ImportedComments;
27
+ notes: ImportedNotes;
28
+ noteLabel: (kind: NoteKind, id: string) => string;
29
+ }
30
+ export declare const NO_IMPORT_SOURCES: ImportSources;
31
+ /** Moves a paragraph into an editable node. null if it holds content we do not model */
32
+ export declare function buildParagraph(el: Element, srcId: number | null, sources?: ImportSources): PMNode | null;
@@ -0,0 +1,308 @@
1
+ // src/docx/importParagraph.ts
2
+ import { readDrawingPicture } from "../ooxml/image.js";
3
+ import {
4
+ attrString,
5
+ childByLocalName,
6
+ elementChildren,
7
+ serializeXml
8
+ } from "../ooxml/xml.js";
9
+ import { docxSchema } from "../schema/index.js";
10
+ import {
11
+ commentParaId,
12
+ importedCommentReplies,
13
+ NO_COMMENTS
14
+ } from "./comments.js";
15
+ import { readParagraphFormat, readRunFormat } from "./formatting.js";
16
+ import {
17
+ NO_LINK_TARGETS,
18
+ readHyperlinkWrapper
19
+ } from "./hyperlink.js";
20
+ import { NO_IMAGES } from "./media.js";
21
+ import { NO_NOTES, noteById } from "./notes.js";
22
+ import { readSdtWrapper } from "./sdt.js";
23
+ import { NO_THEME_FONTS } from "./theme.js";
24
+ function runMark(run, themeFonts) {
25
+ const rPr = childByLocalName(run, "rPr");
26
+ return docxSchema.marks.run.create({
27
+ rPr: rPr ? serializeXml(rPr) : null,
28
+ rAttrs: attrString(run),
29
+ format: readRunFormat(rPr, themeFonts)
30
+ });
31
+ }
32
+ function buildImage(el, marks, images) {
33
+ const picture = readDrawingPicture(el);
34
+ if (!picture) return null;
35
+ const src = images.get(picture.relId);
36
+ if (src === void 0) return null;
37
+ return docxSchema.nodes.image.create(
38
+ {
39
+ src,
40
+ extent: picture.extent,
41
+ alt: picture.alt,
42
+ xml: serializeXml(el)
43
+ },
44
+ null,
45
+ marks
46
+ );
47
+ }
48
+ function buildRunChild(el, marks, images, comments, notes, noteLabel) {
49
+ switch (el.localName) {
50
+ case "t": {
51
+ const text = el.textContent ?? "";
52
+ return text ? [docxSchema.text(text, marks)] : [];
53
+ }
54
+ case "br":
55
+ return [
56
+ docxSchema.nodes.hardBreak.create(
57
+ { brAttrs: attrString(el) },
58
+ null,
59
+ marks
60
+ )
61
+ ];
62
+ case "tab":
63
+ return [
64
+ docxSchema.text(
65
+ " ",
66
+ docxSchema.marks.tab.create({ tabAttrs: attrString(el) }).addToSet(marks)
67
+ )
68
+ ];
69
+ case "drawing": {
70
+ const image = buildImage(el, marks, images);
71
+ return image === null ? null : [image];
72
+ }
73
+ case "commentReference": {
74
+ const id = annotationId(el);
75
+ if (id === null) return null;
76
+ const comment = comments.byId.get(id);
77
+ const paraId = comment?.paraId ?? commentParaId(`comment-${id}`);
78
+ return [
79
+ docxSchema.nodes.commentReference.create(
80
+ {
81
+ id,
82
+ referenceXml: serializeXml(el),
83
+ author: comment?.author ?? null,
84
+ initials: comment?.initials ?? null,
85
+ date: comment?.date ?? null,
86
+ text: comment?.text ?? "",
87
+ commentXml: comment?.xml ?? null,
88
+ imported: true,
89
+ paraId,
90
+ resolved: comment?.resolved ?? false,
91
+ extensionXml: comment?.extensionXml ?? null,
92
+ threadImported: true,
93
+ replies: importedCommentReplies(comments, id)
94
+ },
95
+ null,
96
+ marks
97
+ )
98
+ ];
99
+ }
100
+ case "footnoteReference":
101
+ case "endnoteReference": {
102
+ const id = annotationId(el);
103
+ if (id === null) return null;
104
+ const kind = el.localName === "footnoteReference" ? "footnote" : "endnote";
105
+ const note = noteById(notes, kind, id);
106
+ const customMarkFollows = Array.from(el.attributes).some(
107
+ (entry) => entry.localName === "customMarkFollows" && !["0", "false", "off"].includes(entry.value)
108
+ );
109
+ return [
110
+ docxSchema.nodes.noteReference.create(
111
+ {
112
+ kind,
113
+ id,
114
+ label: note ? noteLabel(kind, id) : "?",
115
+ text: note?.text ?? "",
116
+ customMarkFollows,
117
+ referenceXml: serializeXml(el)
118
+ },
119
+ null,
120
+ marks
121
+ )
122
+ ];
123
+ }
124
+ default:
125
+ return null;
126
+ }
127
+ }
128
+ function buildRunNodes(run, images, themeFonts, comments, notes, noteLabel, wrappers = []) {
129
+ const mark = runMark(run, themeFonts);
130
+ const marks = wrappers.reduce(
131
+ (set, wrapper) => wrapper.addToSet(set),
132
+ [mark]
133
+ );
134
+ const nodes = [];
135
+ for (const child of elementChildren(run)) {
136
+ if (child.localName === "rPr") continue;
137
+ const built = buildRunChild(
138
+ child,
139
+ marks,
140
+ images,
141
+ comments,
142
+ notes,
143
+ noteLabel
144
+ );
145
+ if (built === null) return null;
146
+ nodes.push(...built);
147
+ }
148
+ if (nodes.length === 0) {
149
+ return [
150
+ docxSchema.nodes.rawInline.create(
151
+ { xml: serializeXml(run) },
152
+ null,
153
+ // The wrappers have to close again around this XML on export, so their marks ride along here too
154
+ wrappers
155
+ )
156
+ ];
157
+ }
158
+ return nodes;
159
+ }
160
+ var controlCounts = /* @__PURE__ */ new WeakMap();
161
+ var linkCounts = /* @__PURE__ */ new WeakMap();
162
+ function nextKey(counts, el) {
163
+ const key = counts.get(el.ownerDocument) ?? 0;
164
+ counts.set(el.ownerDocument, key + 1);
165
+ return key;
166
+ }
167
+ var NOTHING_ON_SCREEN = [
168
+ "bookmarkStart",
169
+ "bookmarkEnd",
170
+ "proofErr",
171
+ "permStart",
172
+ "permEnd"
173
+ ];
174
+ function annotationId(el) {
175
+ return Array.from(el.attributes).find((attribute) => attribute.localName === "id")?.value ?? null;
176
+ }
177
+ function commentRangeNode(el, marks = []) {
178
+ const id = annotationId(el);
179
+ if (id === null) return null;
180
+ const type = el.localName === "commentRangeStart" ? docxSchema.nodes.commentStart : el.localName === "commentRangeEnd" ? docxSchema.nodes.commentEnd : null;
181
+ return type?.create({ id, xml: serializeXml(el) }, null, marks) ?? null;
182
+ }
183
+ var NO_IMPORT_SOURCES = {
184
+ images: NO_IMAGES,
185
+ themeFonts: NO_THEME_FONTS,
186
+ links: NO_LINK_TARGETS,
187
+ comments: NO_COMMENTS,
188
+ notes: NO_NOTES,
189
+ noteLabel: () => "?"
190
+ };
191
+ function buildWrappedNodes(content, sources, wrappers, linkAllowed) {
192
+ const nodes = [];
193
+ for (const child of elementChildren(content)) {
194
+ if (child.localName === "r") {
195
+ const built = buildRunNodes(
196
+ child,
197
+ sources.images,
198
+ sources.themeFonts,
199
+ sources.comments,
200
+ sources.notes,
201
+ sources.noteLabel,
202
+ wrappers
203
+ );
204
+ if (built === null) return null;
205
+ nodes.push(...built);
206
+ continue;
207
+ }
208
+ if (child.localName === "hyperlink" && linkAllowed) {
209
+ const built = buildHyperlinkNodes(child, sources, wrappers);
210
+ if (built === null) return null;
211
+ nodes.push(...built);
212
+ continue;
213
+ }
214
+ const commentMarker = commentRangeNode(child, wrappers);
215
+ if (commentMarker) {
216
+ nodes.push(commentMarker);
217
+ continue;
218
+ }
219
+ if (!NOTHING_ON_SCREEN.includes(child.localName)) return null;
220
+ nodes.push(
221
+ docxSchema.nodes.rawInline.create(
222
+ { xml: serializeXml(child) },
223
+ null,
224
+ wrappers
225
+ )
226
+ );
227
+ }
228
+ if (nodes.length === 0) return null;
229
+ return nodes;
230
+ }
231
+ function buildHyperlinkNodes(el, sources, wrappers) {
232
+ const wrapper = readHyperlinkWrapper(el);
233
+ if (!wrapper) return null;
234
+ const mark = docxSchema.marks.link.create({
235
+ linkPrefix: wrapper.prefix,
236
+ href: wrapper.relId === null ? null : sources.links.get(wrapper.relId) ?? null,
237
+ linkKey: nextKey(linkCounts, el)
238
+ });
239
+ return buildWrappedNodes(el, sources, [...wrappers, mark], false);
240
+ }
241
+ function buildSdtNodes(el, sources) {
242
+ const wrapper = readSdtWrapper(el);
243
+ if (!wrapper) return null;
244
+ const mark = docxSchema.marks.sdt.create({
245
+ sdtPrefix: wrapper.prefix,
246
+ sdtKey: nextKey(controlCounts, el),
247
+ contentsLocked: wrapper.contentsLocked,
248
+ deletionLocked: wrapper.deletionLocked
249
+ });
250
+ return buildWrappedNodes(wrapper.content, sources, [mark], true);
251
+ }
252
+ function buildParagraph(el, srcId, sources = NO_IMPORT_SOURCES) {
253
+ const { images, themeFonts } = sources;
254
+ const inline = [];
255
+ let pPrElement = null;
256
+ for (const child of elementChildren(el)) {
257
+ if (child.localName === "pPr") {
258
+ pPrElement = child;
259
+ continue;
260
+ }
261
+ if (child.localName === "r") {
262
+ const runNodes = buildRunNodes(
263
+ child,
264
+ images,
265
+ themeFonts,
266
+ sources.comments,
267
+ sources.notes,
268
+ sources.noteLabel
269
+ );
270
+ if (runNodes === null) return null;
271
+ inline.push(...runNodes);
272
+ continue;
273
+ }
274
+ if (child.localName === "sdt") {
275
+ const sdtNodes = buildSdtNodes(child, sources);
276
+ if (sdtNodes === null) return null;
277
+ inline.push(...sdtNodes);
278
+ continue;
279
+ }
280
+ if (child.localName === "hyperlink") {
281
+ const linkNodes = buildHyperlinkNodes(child, sources, []);
282
+ if (linkNodes === null) return null;
283
+ inline.push(...linkNodes);
284
+ continue;
285
+ }
286
+ const commentMarker = commentRangeNode(child);
287
+ if (commentMarker) {
288
+ inline.push(commentMarker);
289
+ continue;
290
+ }
291
+ inline.push(
292
+ docxSchema.nodes.rawInline.create({ xml: serializeXml(child) })
293
+ );
294
+ }
295
+ return docxSchema.nodes.paragraph.create(
296
+ {
297
+ srcId,
298
+ pAttrs: attrString(el),
299
+ pPr: pPrElement ? serializeXml(pPrElement) : null,
300
+ format: readParagraphFormat(pPrElement)
301
+ },
302
+ inline
303
+ );
304
+ }
305
+ export {
306
+ NO_IMPORT_SOURCES,
307
+ buildParagraph
308
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Imports one OOXML table, converting vertical merge continuations to rowspans and layering style
3
+ * values for display. Unsupported grids return null so the caller can preserve their source XML.
4
+ */
5
+ import type { Node as PMNode } from "prosemirror-model";
6
+ import { type StyleTable } from "./formatting";
7
+ import { type ImportSources } from "./importParagraph";
8
+ /** Moves a `<w:tbl>` into a table node. null if it cannot be modelled */
9
+ export declare function buildTable(el: Element, srcId: number | null, sources?: ImportSources, styles?: StyleTable, defaultTableStyleId?: string | null): PMNode | null;