@globalpayments/vega 2.98.0 → 2.99.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 (447) hide show
  1. package/dist/cjs/{action-color-accessibility-validator-24498816.js → action-color-accessibility-validator-b8a9ef0f.js} +2 -2
  2. package/dist/cjs/{app-globals-b3f05631.js → app-globals-a306dce6.js} +10 -10
  3. package/dist/cjs/{code-block-d78c2b2c.js → code-block-ea1f5eb3.js} +43 -6
  4. package/dist/cjs/{component-global-style-slimmer-93c5fb50.js → component-global-style-slimmer-ba588eb4.js} +1 -1
  5. package/dist/cjs/{component-value-history-controller-slimmer.abstract-beb00fea.js → component-value-history-controller-slimmer.abstract-7071b064.js} +24 -5
  6. package/dist/cjs/{content-state-78a620a9.js → content-state-8d07d530.js} +60 -8
  7. package/dist/cjs/{dark-mode-style-controller-32d4054a.js → dark-mode-style-controller-f3da3342.js} +2 -2
  8. package/dist/cjs/{date-required-rule-5250f26d.js → date-required-rule-c0c498ad.js} +1 -1
  9. package/dist/cjs/{design-token-74674ee7.js → design-token-58bf7fe8.js} +3 -3
  10. package/dist/cjs/{element-appender-slimmer-597e9e48.js → element-appender-slimmer-a0269315.js} +2 -2
  11. package/dist/cjs/{form-field-controller-slimmer-a743be34.js → form-field-controller-slimmer-f73f200e.js} +2 -2
  12. package/dist/cjs/{image-annotation-action-85c4bd83.js → image-annotation-action-2a28038e.js} +3 -3
  13. package/dist/cjs/{image-extension-260fa69c.js → image-extension-9659708b.js} +2 -2
  14. package/dist/cjs/{index-592b4052.js → index-5d1adcd1.js} +86 -0
  15. package/dist/cjs/index.cjs.js +19 -19
  16. package/dist/cjs/{inject-keyboard-manager-6a6f5c9f.js → inject-keyboard-manager-4fa45f9c.js} +1 -1
  17. package/dist/cjs/{internal-calendar-period-factory-dfcdd3f6.js → internal-calendar-period-factory-6196bc80.js} +1 -1
  18. package/dist/cjs/{internal-translation-controller-1dac2df8.js → internal-translation-controller-51f7f865.js} +2 -0
  19. package/dist/cjs/{keyboard-manager-c56033b1.js → keyboard-manager-482fe257.js} +1 -1
  20. package/dist/cjs/{keyboard-manager-slimmer-7043a106.js → keyboard-manager-slimmer-a19430dd.js} +1 -1
  21. package/dist/cjs/{link-extension-220ff6a9.js → link-extension-11340e1c.js} +26 -7
  22. package/dist/cjs/loader.cjs.js +13 -13
  23. package/dist/cjs/{month-view-generator-7b704a80.js → month-view-generator-1a534451.js} +1 -1
  24. package/dist/cjs/{public-rules-5657bce4.js → public-rules-6c77b545.js} +9 -9
  25. package/dist/cjs/{range-c5afd53a.js → range-22ddd452.js} +1 -1
  26. package/dist/cjs/{responsive-format-facade-493d1763.js → responsive-format-facade-74e6d791.js} +1 -1
  27. package/dist/cjs/{rich-text-editor-required-rule-385c1b61.js → rich-text-editor-required-rule-09d1093a.js} +1 -1
  28. package/dist/cjs/{split-cell-operation-873d5db7.js → split-cell-operation-11bfb305.js} +14 -4
  29. package/dist/cjs/{state-border-formatter-711c7aaa.js → state-border-formatter-bf4f9f1c.js} +1 -1
  30. package/dist/cjs/{string-format-strategy.abstract-b61bdcbd.js → string-format-strategy.abstract-bf37b14c.js} +1 -1
  31. package/dist/cjs/{string-input-formatter-slimmer-ef65cca7.js → string-input-formatter-slimmer-ffeb18a6.js} +1 -1
  32. package/dist/cjs/{string-mask-strategy-ad3fa0ac.js → string-mask-strategy-7f394726.js} +2 -2
  33. package/dist/cjs/{style-formatter-8f711cb0.js → style-formatter-4ac63910.js} +2 -2
  34. package/dist/cjs/{time-required-rule-87417359.js → time-required-rule-e2a50003.js} +1 -1
  35. package/dist/cjs/{token-extension-78b5a026.js → token-extension-4686cb3b.js} +2920 -157
  36. package/dist/cjs/{translation-slimmer-77c7f37d.js → translation-slimmer-e4997f8f.js} +1 -1
  37. package/dist/cjs/{type-guard-a57ef3ac.js → type-guard-b8d7bb3f.js} +1 -1
  38. package/dist/cjs/{valid-credit-card-number-rule-4c0a3040.js → valid-credit-card-number-rule-f5a6f009.js} +1 -1
  39. package/dist/cjs/vega-accordion.cjs.entry.js +6 -6
  40. package/dist/cjs/vega-app-footer.cjs.entry.js +2 -2
  41. package/dist/cjs/vega-app-header-button.cjs.entry.js +5 -5
  42. package/dist/cjs/vega-box.cjs.entry.js +7 -7
  43. package/dist/cjs/vega-brand-logo.cjs.entry.js +2 -2
  44. package/dist/cjs/vega-breadcrumb.cjs.entry.js +2 -2
  45. package/dist/cjs/vega-button-circle.cjs.entry.js +6 -6
  46. package/dist/cjs/vega-button-link.cjs.entry.js +1 -1
  47. package/dist/cjs/vega-button.cjs.entry.js +4 -4
  48. package/dist/cjs/vega-calendar_5.cjs.entry.js +21 -10
  49. package/dist/cjs/vega-card.cjs.entry.js +5 -5
  50. package/dist/cjs/vega-carousel.cjs.entry.js +3 -3
  51. package/dist/cjs/vega-checkbox_2.cjs.entry.js +3 -3
  52. package/dist/cjs/vega-chip.cjs.entry.js +5 -5
  53. package/dist/cjs/vega-code-block.cjs.entry.js +11 -11
  54. package/dist/cjs/vega-color-picker.cjs.entry.js +3 -3
  55. package/dist/cjs/vega-color-swatch-picker.cjs.entry.js +4 -4
  56. package/dist/cjs/vega-color-swatch.cjs.entry.js +2 -2
  57. package/dist/cjs/vega-combo-box.cjs.entry.js +9 -9
  58. package/dist/cjs/vega-counter-badge.cjs.entry.js +2 -2
  59. package/dist/cjs/vega-date-picker_2.cjs.entry.js +14 -14
  60. package/dist/cjs/vega-dialog_2.cjs.entry.js +5 -5
  61. package/dist/cjs/vega-divider.cjs.entry.js +5 -5
  62. package/dist/cjs/vega-dropdown_5.cjs.entry.js +23 -14
  63. package/dist/cjs/vega-env-manager-23b8b23c.js +2 -2
  64. package/dist/cjs/vega-field-label.cjs.entry.js +3 -3
  65. package/dist/cjs/vega-file-uploader.cjs.entry.js +4 -4
  66. package/dist/cjs/vega-flag-icon.cjs.entry.js +5 -5
  67. package/dist/cjs/vega-flex.cjs.entry.js +6 -6
  68. package/dist/cjs/vega-font.cjs.entry.js +5 -5
  69. package/dist/cjs/vega-form.cjs.entry.js +2 -2
  70. package/dist/cjs/vega-grid.cjs.entry.js +5 -5
  71. package/dist/cjs/vega-icon.cjs.entry.js +6 -6
  72. package/dist/cjs/vega-image-uploader.cjs.entry.js +7 -7
  73. package/dist/cjs/vega-input-credit-card.cjs.entry.js +7 -7
  74. package/dist/cjs/vega-input-numeric.cjs.entry.js +6 -6
  75. package/dist/cjs/vega-input-passcode.cjs.entry.js +6 -6
  76. package/dist/cjs/vega-input-phone-number.cjs.entry.js +5 -5
  77. package/dist/cjs/vega-input-range.cjs.entry.js +4 -4
  78. package/dist/cjs/vega-input-select.cjs.entry.js +6 -6
  79. package/dist/cjs/vega-input.cjs.entry.js +7 -7
  80. package/dist/cjs/vega-left-nav_5.cjs.entry.js +10 -10
  81. package/dist/cjs/vega-loader-wrapper_2.cjs.entry.js +3 -3
  82. package/dist/cjs/vega-pagination-page-size-selector-mobile.cjs.entry.js +2 -2
  83. package/dist/cjs/vega-pagination.cjs.entry.js +4 -4
  84. package/dist/cjs/vega-popover_2.cjs.entry.js +8 -8
  85. package/dist/cjs/vega-progress-tracker_2.cjs.entry.js +3 -3
  86. package/dist/cjs/vega-radio_2.cjs.entry.js +6 -6
  87. package/dist/cjs/vega-rich-text-content.cjs.entry.js +39 -11
  88. package/dist/cjs/vega-rich-text-editor_4.cjs.entry.js +79 -22
  89. package/dist/cjs/vega-rich-text-find-replace-panel.cjs.entry.js +1 -1
  90. package/dist/cjs/vega-rich-text-special-characters-panel.cjs.entry.js +5 -5
  91. package/dist/cjs/vega-rich-text-table-properties_3.cjs.entry.js +10 -10
  92. package/dist/cjs/vega-selection-chip_2.cjs.entry.js +5 -5
  93. package/dist/cjs/vega-selection-tile_2.cjs.entry.js +3 -3
  94. package/dist/cjs/vega-sidenav_3.cjs.entry.js +3 -3
  95. package/dist/cjs/vega-signature-capture.cjs.entry.js +8 -8
  96. package/dist/cjs/vega-stepper.cjs.entry.js +3 -3
  97. package/dist/cjs/vega-tab-group_2.cjs.entry.js +21 -8
  98. package/dist/cjs/vega-table_11.cjs.entry.js +81 -45
  99. package/dist/cjs/vega-textarea.cjs.entry.js +3 -3
  100. package/dist/cjs/vega-time-picker_2.cjs.entry.js +10 -10
  101. package/dist/cjs/vega-toggle-switch.cjs.entry.js +3 -3
  102. package/dist/cjs/vega-tooltip_2.cjs.entry.js +6 -6
  103. package/dist/cjs/vega.cjs.js +13 -13
  104. package/dist/collection/components/vega-calendar/slimmers/common/renderers/vega-calendar-event-item-renderer.js +5 -2
  105. package/dist/collection/components/vega-calendar/vega-calendar-event-preview/slimmers/renderers/vega-calendar-event-preview-detail-renderer.js +9 -1
  106. package/dist/collection/components/vega-counter-badge/vega-counter-badge.js +2 -2
  107. package/dist/collection/components/vega-dropdown/vega-dropdown-group/slimmers/renderers/vega-dropdown-group-renderer.js +6 -4
  108. package/dist/collection/components/vega-dropdown/vega-dropdown-item/slimmers/renderers/vega-dropdown-item-renderer.js +10 -2
  109. package/dist/collection/components/vega-field-label/vega-field-label.css +1 -0
  110. package/dist/collection/components/vega-rich-text-editor/constants/constant.js +16 -0
  111. package/dist/collection/components/vega-rich-text-editor/dto/annotations/text-style-default-styles.js +2 -1
  112. package/dist/collection/components/vega-rich-text-editor/dto/blocks/block.abstract.js +11 -0
  113. package/dist/collection/components/vega-rich-text-editor/dto/filter-styles-strategies/filter-styles-strategy-registry.js +2 -1
  114. package/dist/collection/components/vega-rich-text-editor/dto/filter-styles-strategies/filter-styles-strategy.abstract.js +5 -2
  115. package/dist/collection/components/vega-rich-text-editor/dto/filter-styles-strategies/text-node/title-heading-node-filter-styles-strategy.js +36 -2
  116. package/dist/collection/components/vega-rich-text-editor/dto/renderers/blocks/block-text-nodes-renderer.abstract.js +20 -3
  117. package/dist/collection/components/vega-rich-text-editor/dto/renderers/nodes/text-node-renderer.js +12 -0
  118. package/dist/collection/components/vega-rich-text-editor/extensions/block-boundary-registry.js +34 -0
  119. package/dist/collection/components/vega-rich-text-editor/extensions/extension.abstract.js +20 -0
  120. package/dist/collection/components/vega-rich-text-editor/extensions/functions/action-handler-strategies/insert-function-block-strategy.js +3 -2
  121. package/dist/collection/components/vega-rich-text-editor/extensions/functions/constants.js +8 -0
  122. package/dist/collection/components/vega-rich-text-editor/extensions/functions/dto/function-block.js +14 -3
  123. package/dist/collection/components/vega-rich-text-editor/extensions/functions/dto/logic-control-block.js +2 -1
  124. package/dist/collection/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-containing-function-block-strategy.js +19 -0
  125. package/dist/collection/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-to-function-block-strategy.js +9 -5
  126. package/dist/collection/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-to-function-content-strategy.js +3 -3
  127. package/dist/collection/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-to-logic-control-block-strategy.js +4 -2
  128. package/dist/collection/components/vega-rich-text-editor/extensions/functions/function-extension.js +18 -0
  129. package/dist/collection/components/vega-rich-text-editor/extensions/functions/renderers/function-block-renderer.js +5 -2
  130. package/dist/collection/components/vega-rich-text-editor/extensions/functions/renderers/logic-control-block-renderer.js +2 -1
  131. package/dist/collection/components/vega-rich-text-editor/extensions/functions/utils.js +36 -0
  132. package/dist/collection/components/vega-rich-text-editor/extensions/languages/language-extension.js +1 -0
  133. package/dist/collection/components/vega-rich-text-editor/extensions/paste/action-handler-strategies/image-replace-src-strategy.js +21 -0
  134. package/dist/collection/components/vega-rich-text-editor/extensions/paste/actions/image-replace-src-action.js +13 -0
  135. package/dist/collection/components/vega-rich-text-editor/extensions/paste/parse-local-images-helper/paste-image-parser.js +295 -0
  136. package/dist/collection/components/vega-rich-text-editor/extensions/paste/parse-local-images-helper/pending-image-registry.js +116 -0
  137. package/dist/collection/components/vega-rich-text-editor/extensions/paste/paste-chooser-ui.js +13 -4
  138. package/dist/collection/components/vega-rich-text-editor/extensions/paste/paste-extension.js +70 -7
  139. package/dist/collection/components/vega-rich-text-editor/extensions/paste/strategies/default-paste-strategy.js +38 -0
  140. package/dist/collection/components/vega-rich-text-editor/extensions/paste/strategies/paste-processing-strategy.abstract.js +55 -0
  141. package/dist/collection/components/vega-rich-text-editor/extensions/paste/strategies/paste-strategy-selector.js +59 -0
  142. package/dist/collection/components/vega-rich-text-editor/extensions/paste/strategies/word-paste-strategy.js +416 -0
  143. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-code-block-transformer.js +106 -0
  144. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-image-transformer.js +198 -0
  145. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-list-transformer.js +591 -0
  146. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-paragraph-transformer.js +112 -0
  147. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-table-transformer.js +551 -0
  148. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-transformer.js +7 -0
  149. package/dist/collection/components/vega-rich-text-editor/extensions/table/dto/table-block.js +10 -0
  150. package/dist/collection/components/vega-rich-text-editor/extensions/tokens/span-to-token-node-strategy.js +4 -2
  151. package/dist/collection/components/vega-rich-text-editor/extensions/tokens/token-node.js +44 -0
  152. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/extension-controller.js +2 -0
  153. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/annotation-handler/text-style-annotation-handler.js +7 -4
  154. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/continue-inline-to-rte-text-block-strategy.js +17 -0
  155. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/input-event-handler/insert-paste-handler.js +18 -4
  156. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/selection-controller.js +21 -2
  157. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/source-edit-toolbar-button-slimmer.js +7 -0
  158. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/vega-rich-text-editor-source-view-renderer.js +5 -2
  159. package/dist/collection/components/vega-tab-group/slimmers/vega-tab-group/renderers/vega-tab-group-tab-list-renderer.js +14 -7
  160. package/dist/collection/components/vega-tab-group/vega-tab-group.css +6 -0
  161. package/dist/collection/components/vega-tab-group/vega-tab-group.js +5 -0
  162. package/dist/collection/components/vega-table/slimmers/controllers/vega-table-body-col-span-controller.js +31 -1
  163. package/dist/collection/components/vega-table/slimmers/renderers/vega-table-body-col-span-resolver.js +18 -11
  164. package/dist/collection/helpers/translation/locales/en.js +2 -0
  165. package/dist/collection/utils/sanitize/index.js +3 -2
  166. package/dist/collection/utils/sanitize/strategies/index.js +1 -0
  167. package/dist/collection/utils/sanitize/strategies/label-sanitize-strategy.js +14 -0
  168. package/dist/collection/utils/sanitize/strategies/plain-text-sanitize-strategy.js +70 -0
  169. package/dist/esm/{action-color-accessibility-validator-ce55cb07.js → action-color-accessibility-validator-08877515.js} +2 -2
  170. package/dist/esm/{app-globals-95c7110a.js → app-globals-c59364c2.js} +10 -10
  171. package/dist/esm/{code-block-9c513169.js → code-block-e6443949.js} +39 -7
  172. package/dist/esm/{component-global-style-slimmer-ac703085.js → component-global-style-slimmer-7d60a04a.js} +1 -1
  173. package/dist/esm/{component-value-history-controller-slimmer.abstract-9cef2a2a.js → component-value-history-controller-slimmer.abstract-ee393213.js} +24 -5
  174. package/dist/esm/{content-state-25c81c08.js → content-state-43cdacff.js} +60 -9
  175. package/dist/esm/{dark-mode-style-controller-ca5afd2d.js → dark-mode-style-controller-352f15ff.js} +2 -2
  176. package/dist/esm/{date-required-rule-85334d0c.js → date-required-rule-b5b67498.js} +1 -1
  177. package/dist/esm/{design-token-10ff79b5.js → design-token-8319bb59.js} +3 -3
  178. package/dist/esm/{element-appender-slimmer-8a06ecdd.js → element-appender-slimmer-c81d1fe3.js} +2 -2
  179. package/dist/esm/{form-field-controller-slimmer-68fc5380.js → form-field-controller-slimmer-511b7ac5.js} +2 -2
  180. package/dist/esm/{image-annotation-action-d7f2aecc.js → image-annotation-action-d7cb80aa.js} +3 -3
  181. package/dist/esm/{image-extension-fbd1ed6e.js → image-extension-9b8abd0d.js} +2 -2
  182. package/dist/esm/{index-3b327f29.js → index-35451d12.js} +86 -1
  183. package/dist/esm/index.js +19 -19
  184. package/dist/esm/{inject-keyboard-manager-ea1aad5b.js → inject-keyboard-manager-dd368d56.js} +1 -1
  185. package/dist/esm/{internal-calendar-period-factory-7b294fb6.js → internal-calendar-period-factory-d58f35c6.js} +1 -1
  186. package/dist/esm/{internal-translation-controller-fac22598.js → internal-translation-controller-b33430c6.js} +2 -0
  187. package/dist/esm/{keyboard-manager-50da85d7.js → keyboard-manager-b4a0d97d.js} +1 -1
  188. package/dist/esm/{keyboard-manager-slimmer-1f7c8bfb.js → keyboard-manager-slimmer-0517fc70.js} +1 -1
  189. package/dist/esm/{link-extension-e8ee103e.js → link-extension-230bae8d.js} +26 -7
  190. package/dist/esm/loader.js +13 -13
  191. package/dist/esm/{month-view-generator-a1a9a4ec.js → month-view-generator-f470caac.js} +1 -1
  192. package/dist/esm/{public-rules-49de79c7.js → public-rules-28ef32d3.js} +9 -9
  193. package/dist/esm/{range-b678c693.js → range-efad2578.js} +1 -1
  194. package/dist/esm/{responsive-format-facade-f19b601c.js → responsive-format-facade-dec87e46.js} +1 -1
  195. package/dist/esm/{rich-text-editor-required-rule-578e0958.js → rich-text-editor-required-rule-a697e5bd.js} +1 -1
  196. package/dist/esm/{split-cell-operation-1c8e7585.js → split-cell-operation-89b91a38.js} +14 -4
  197. package/dist/esm/{state-border-formatter-bfda33aa.js → state-border-formatter-1e900a2f.js} +1 -1
  198. package/dist/esm/{string-format-strategy.abstract-1f4ff1b3.js → string-format-strategy.abstract-d0ce3f65.js} +1 -1
  199. package/dist/esm/{string-input-formatter-slimmer-0006a107.js → string-input-formatter-slimmer-6546cfc7.js} +1 -1
  200. package/dist/esm/{string-mask-strategy-bbbcdbef.js → string-mask-strategy-dd13ae21.js} +2 -2
  201. package/dist/esm/{style-formatter-e9adc8f4.js → style-formatter-057d7120.js} +2 -2
  202. package/dist/esm/{time-required-rule-1ce2d0a0.js → time-required-rule-73753a54.js} +1 -1
  203. package/dist/esm/{token-extension-f2d009e3.js → token-extension-74a0eeb1.js} +2918 -155
  204. package/dist/esm/{translation-slimmer-ee0f0e76.js → translation-slimmer-ef970ffc.js} +1 -1
  205. package/dist/esm/{type-guard-f2624334.js → type-guard-6fc96870.js} +1 -1
  206. package/dist/esm/{valid-credit-card-number-rule-60212b1d.js → valid-credit-card-number-rule-b54a31e7.js} +1 -1
  207. package/dist/esm/vega-accordion.entry.js +6 -6
  208. package/dist/esm/vega-app-footer.entry.js +2 -2
  209. package/dist/esm/vega-app-header-button.entry.js +5 -5
  210. package/dist/esm/vega-box.entry.js +7 -7
  211. package/dist/esm/vega-brand-logo.entry.js +2 -2
  212. package/dist/esm/vega-breadcrumb.entry.js +2 -2
  213. package/dist/esm/vega-button-circle.entry.js +6 -6
  214. package/dist/esm/vega-button-link.entry.js +1 -1
  215. package/dist/esm/vega-button.entry.js +4 -4
  216. package/dist/esm/vega-calendar_5.entry.js +21 -10
  217. package/dist/esm/vega-card.entry.js +5 -5
  218. package/dist/esm/vega-carousel.entry.js +3 -3
  219. package/dist/esm/vega-checkbox_2.entry.js +3 -3
  220. package/dist/esm/vega-chip.entry.js +5 -5
  221. package/dist/esm/vega-code-block.entry.js +11 -11
  222. package/dist/esm/vega-color-picker.entry.js +3 -3
  223. package/dist/esm/vega-color-swatch-picker.entry.js +4 -4
  224. package/dist/esm/vega-color-swatch.entry.js +2 -2
  225. package/dist/esm/vega-combo-box.entry.js +9 -9
  226. package/dist/esm/vega-counter-badge.entry.js +2 -2
  227. package/dist/esm/vega-date-picker_2.entry.js +14 -14
  228. package/dist/esm/vega-dialog_2.entry.js +5 -5
  229. package/dist/esm/vega-divider.entry.js +5 -5
  230. package/dist/esm/vega-dropdown_5.entry.js +23 -14
  231. package/dist/esm/vega-env-manager-8f8dc473.js +2 -2
  232. package/dist/esm/vega-field-label.entry.js +3 -3
  233. package/dist/esm/vega-file-uploader.entry.js +4 -4
  234. package/dist/esm/vega-flag-icon.entry.js +5 -5
  235. package/dist/esm/vega-flex.entry.js +6 -6
  236. package/dist/esm/vega-font.entry.js +5 -5
  237. package/dist/esm/vega-form.entry.js +2 -2
  238. package/dist/esm/vega-grid.entry.js +5 -5
  239. package/dist/esm/vega-icon.entry.js +6 -6
  240. package/dist/esm/vega-image-uploader.entry.js +7 -7
  241. package/dist/esm/vega-input-credit-card.entry.js +7 -7
  242. package/dist/esm/vega-input-numeric.entry.js +6 -6
  243. package/dist/esm/vega-input-passcode.entry.js +6 -6
  244. package/dist/esm/vega-input-phone-number.entry.js +5 -5
  245. package/dist/esm/vega-input-range.entry.js +4 -4
  246. package/dist/esm/vega-input-select.entry.js +6 -6
  247. package/dist/esm/vega-input.entry.js +7 -7
  248. package/dist/esm/vega-left-nav_5.entry.js +10 -10
  249. package/dist/esm/vega-loader-wrapper_2.entry.js +3 -3
  250. package/dist/esm/vega-pagination-page-size-selector-mobile.entry.js +2 -2
  251. package/dist/esm/vega-pagination.entry.js +4 -4
  252. package/dist/esm/vega-popover_2.entry.js +8 -8
  253. package/dist/esm/vega-progress-tracker_2.entry.js +3 -3
  254. package/dist/esm/vega-radio_2.entry.js +6 -6
  255. package/dist/esm/vega-rich-text-content.entry.js +39 -11
  256. package/dist/esm/vega-rich-text-editor_4.entry.js +79 -22
  257. package/dist/esm/vega-rich-text-find-replace-panel.entry.js +1 -1
  258. package/dist/esm/vega-rich-text-special-characters-panel.entry.js +5 -5
  259. package/dist/esm/vega-rich-text-table-properties_3.entry.js +10 -10
  260. package/dist/esm/vega-selection-chip_2.entry.js +5 -5
  261. package/dist/esm/vega-selection-tile_2.entry.js +3 -3
  262. package/dist/esm/vega-sidenav_3.entry.js +3 -3
  263. package/dist/esm/vega-signature-capture.entry.js +8 -8
  264. package/dist/esm/vega-stepper.entry.js +3 -3
  265. package/dist/esm/vega-tab-group_2.entry.js +21 -8
  266. package/dist/esm/vega-table_11.entry.js +53 -17
  267. package/dist/esm/vega-textarea.entry.js +3 -3
  268. package/dist/esm/vega-time-picker_2.entry.js +10 -10
  269. package/dist/esm/vega-toggle-switch.entry.js +3 -3
  270. package/dist/esm/vega-tooltip_2.entry.js +6 -6
  271. package/dist/esm/vega.js +13 -13
  272. package/dist/sri/vega-sri-manifest.json +349 -349
  273. package/dist/types/components/vega-calendar/vega-calendar-event-preview/slimmers/renderers/vega-calendar-event-preview-detail-renderer.d.ts +2 -0
  274. package/dist/types/components/vega-dropdown/vega-dropdown-item/slimmers/renderers/vega-dropdown-item-renderer.d.ts +1 -0
  275. package/dist/types/components/vega-rich-text-editor/constants/constant.d.ts +16 -0
  276. package/dist/types/components/vega-rich-text-editor/dto/annotations/text-style-default-styles.d.ts +1 -0
  277. package/dist/types/components/vega-rich-text-editor/dto/blocks/block.abstract.d.ts +9 -0
  278. package/dist/types/components/vega-rich-text-editor/dto/filter-styles-strategies/filter-styles-strategy-registry.d.ts +1 -0
  279. package/dist/types/components/vega-rich-text-editor/dto/filter-styles-strategies/filter-styles-strategy.abstract.d.ts +3 -2
  280. package/dist/types/components/vega-rich-text-editor/dto/filter-styles-strategies/text-node/title-heading-node-filter-styles-strategy.d.ts +25 -3
  281. package/dist/types/components/vega-rich-text-editor/dto/renderers/blocks/block-text-nodes-renderer.abstract.d.ts +7 -0
  282. package/dist/types/components/vega-rich-text-editor/dto/renderers/nodes/text-node-renderer.d.ts +11 -0
  283. package/dist/types/components/vega-rich-text-editor/extensions/block-boundary-registry.d.ts +21 -0
  284. package/dist/types/components/vega-rich-text-editor/extensions/extension.abstract.d.ts +15 -0
  285. package/dist/types/components/vega-rich-text-editor/extensions/functions/constants.d.ts +4 -0
  286. package/dist/types/components/vega-rich-text-editor/extensions/functions/dto/function-block.d.ts +7 -0
  287. package/dist/types/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-containing-function-block-strategy.d.ts +8 -0
  288. package/dist/types/components/vega-rich-text-editor/extensions/functions/function-extension.d.ts +6 -0
  289. package/dist/types/components/vega-rich-text-editor/extensions/functions/utils.d.ts +29 -0
  290. package/dist/types/components/vega-rich-text-editor/extensions/paste/action-handler-strategies/image-replace-src-strategy.d.ts +12 -0
  291. package/dist/types/components/vega-rich-text-editor/extensions/paste/actions/image-replace-src-action.d.ts +11 -0
  292. package/dist/types/components/vega-rich-text-editor/extensions/paste/parse-local-images-helper/paste-image-parser.d.ts +136 -0
  293. package/dist/types/components/vega-rich-text-editor/extensions/paste/parse-local-images-helper/pending-image-registry.d.ts +68 -0
  294. package/dist/types/components/vega-rich-text-editor/extensions/paste/paste-chooser-ui.d.ts +9 -4
  295. package/dist/types/components/vega-rich-text-editor/extensions/paste/paste-extension.d.ts +39 -2
  296. package/dist/types/components/vega-rich-text-editor/extensions/paste/strategies/default-paste-strategy.d.ts +29 -0
  297. package/dist/types/components/vega-rich-text-editor/extensions/paste/strategies/paste-processing-strategy.abstract.d.ts +61 -0
  298. package/dist/types/components/vega-rich-text-editor/extensions/paste/strategies/paste-strategy-selector.d.ts +45 -0
  299. package/dist/types/components/vega-rich-text-editor/extensions/paste/strategies/word-paste-strategy.d.ts +186 -0
  300. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-code-block-transformer.d.ts +51 -0
  301. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-image-transformer.d.ts +86 -0
  302. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-list-transformer.d.ts +271 -0
  303. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-paragraph-transformer.d.ts +25 -0
  304. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-table-transformer.d.ts +240 -0
  305. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-transformer.d.ts +36 -0
  306. package/dist/types/components/vega-rich-text-editor/extensions/table/dto/table-block.d.ts +8 -0
  307. package/dist/types/components/vega-rich-text-editor/extensions/tokens/span-to-token-node-strategy.d.ts +2 -2
  308. package/dist/types/components/vega-rich-text-editor/extensions/tokens/token-node.d.ts +19 -1
  309. package/dist/types/components/vega-rich-text-editor/interface.d.ts +10 -0
  310. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/annotation-handler/text-style-annotation-handler.d.ts +4 -1
  311. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/continue-inline-to-rte-text-block-strategy.d.ts +8 -0
  312. package/dist/types/components/vega-rich-text-editor/slimmers/renderers/tools/source-edit-toolbar-button-slimmer.d.ts +1 -0
  313. package/dist/types/components/vega-tab-group/slimmers/vega-tab-group/renderers/vega-tab-group-tab-list-renderer.d.ts +1 -0
  314. package/dist/types/components/vega-tab-group/types.d.ts +3 -1
  315. package/dist/types/components/vega-tab-group/vega-tab-group.d.ts +2 -0
  316. package/dist/types/components/vega-table/interface.d.ts +4 -4
  317. package/dist/types/components/vega-table/slimmers/controllers/vega-table-body-col-span-controller.d.ts +16 -0
  318. package/dist/types/components/vega-table/slimmers/renderers/vega-table-body-col-span-resolver.d.ts +8 -10
  319. package/dist/types/helpers/translation/interface.d.ts +3 -1
  320. package/dist/types/types/public-api.d.ts +1 -0
  321. package/dist/types/utils/sanitize/index.d.ts +3 -2
  322. package/dist/types/utils/sanitize/strategies/index.d.ts +1 -0
  323. package/dist/types/utils/sanitize/strategies/label-sanitize-strategy.d.ts +9 -0
  324. package/dist/types/utils/sanitize/strategies/plain-text-sanitize-strategy.d.ts +36 -0
  325. package/dist/vega/index.esm.js +1 -1
  326. package/dist/vega/{p-0cbf09f7.entry.js → p-024db952.entry.js} +1 -1
  327. package/dist/vega/p-0b2c4c0b.js +1 -0
  328. package/dist/vega/{p-c2277448.entry.js → p-0ca3b4bf.entry.js} +1 -1
  329. package/dist/vega/{p-6f537797.entry.js → p-1a37d63c.entry.js} +1 -1
  330. package/dist/vega/{p-b622c455.js → p-1fa22fda.js} +1 -1
  331. package/dist/vega/{p-d609c3fd.js → p-2044eba9.js} +1 -1
  332. package/dist/vega/{p-56db3323.js → p-22edd3cc.js} +1 -1
  333. package/dist/vega/{p-5f96e741.entry.js → p-23c1f378.entry.js} +1 -1
  334. package/dist/vega/{p-6c95a6a3.js → p-2529820e.js} +1 -1
  335. package/dist/vega/{p-8d96f0e8.entry.js → p-2af1d8b8.entry.js} +1 -1
  336. package/dist/vega/{p-17c69503.entry.js → p-2f89ee14.entry.js} +1 -1
  337. package/dist/vega/{p-2bb5a232.js → p-3091b105.js} +1 -1
  338. package/dist/vega/{p-52c69f9e.entry.js → p-328ebbdb.entry.js} +1 -1
  339. package/dist/vega/p-35628af4.js +1 -0
  340. package/dist/vega/{p-9abf7d0a.entry.js → p-35d37477.entry.js} +1 -1
  341. package/dist/vega/{p-8c56d74d.entry.js → p-3a230d4b.entry.js} +1 -1
  342. package/dist/vega/{p-4bfe3258.entry.js → p-3c152bad.entry.js} +1 -1
  343. package/dist/vega/p-3c559c8b.js +1 -0
  344. package/dist/vega/{p-d470fce2.entry.js → p-3c8421d5.entry.js} +1 -1
  345. package/dist/vega/{p-7dcd2850.entry.js → p-4022412e.entry.js} +1 -1
  346. package/dist/vega/{p-c70748f7.entry.js → p-433b1395.entry.js} +1 -1
  347. package/dist/vega/{p-b98ead05.entry.js → p-4370b954.entry.js} +1 -1
  348. package/dist/vega/p-444e24c6.js +1 -0
  349. package/dist/vega/p-4473d8b1.js +3 -0
  350. package/dist/vega/{p-a484e32d.entry.js → p-44999c88.entry.js} +1 -1
  351. package/dist/vega/{p-f29ea345.entry.js → p-47a48329.entry.js} +1 -1
  352. package/dist/vega/{p-0cf3b5c1.entry.js → p-49d7cfed.entry.js} +1 -1
  353. package/dist/vega/{p-92528dc9.entry.js → p-4afd6715.entry.js} +1 -1
  354. package/dist/vega/{p-461100b8.entry.js → p-4f6aaac5.entry.js} +1 -1
  355. package/dist/vega/p-50eda925.js +1 -0
  356. package/dist/vega/{p-ae2abdfa.js → p-5110c84f.js} +1 -1
  357. package/dist/vega/{p-2a245138.entry.js → p-5147c30d.entry.js} +1 -1
  358. package/dist/vega/{p-874e5624.js → p-52878ea9.js} +1 -1
  359. package/dist/vega/{p-b00ec194.entry.js → p-55dc3053.entry.js} +1 -1
  360. package/dist/vega/p-5af312f8.js +1 -0
  361. package/dist/vega/{p-3e09aeed.js → p-5b3c8a56.js} +1 -1
  362. package/dist/vega/{p-2acf9b42.entry.js → p-5e9e04f3.entry.js} +1 -1
  363. package/dist/vega/p-5f377954.js +1 -1
  364. package/dist/vega/p-6493f13a.entry.js +1 -0
  365. package/dist/vega/{p-56598858.entry.js → p-6659c910.entry.js} +1 -1
  366. package/dist/vega/{p-95c18f79.entry.js → p-66728dd4.entry.js} +1 -1
  367. package/dist/vega/{p-4cbfc01e.entry.js → p-66a785d0.entry.js} +1 -1
  368. package/dist/vega/{p-36d9e782.entry.js → p-66fe8b4e.entry.js} +1 -1
  369. package/dist/vega/p-67e88cd7.entry.js +1 -0
  370. package/dist/vega/{p-456f678b.js → p-691bdc20.js} +1 -1
  371. package/dist/vega/{p-94975537.entry.js → p-6d6b4495.entry.js} +1 -1
  372. package/dist/vega/p-7754b10f.entry.js +1 -0
  373. package/dist/vega/{p-085d1647.entry.js → p-77fb3971.entry.js} +1 -1
  374. package/dist/vega/{p-544ce391.entry.js → p-7977352b.entry.js} +1 -1
  375. package/dist/vega/{p-a91927eb.entry.js → p-7b133734.entry.js} +1 -1
  376. package/dist/vega/p-7b84a943.entry.js +1 -0
  377. package/dist/vega/{p-02d3ce79.entry.js → p-840444c9.entry.js} +1 -1
  378. package/dist/vega/{p-3737b9e2.entry.js → p-860e76f5.entry.js} +1 -1
  379. package/dist/vega/{p-72fd17a1.entry.js → p-867cc602.entry.js} +1 -1
  380. package/dist/vega/p-8d2a9012.js +1 -0
  381. package/dist/vega/{p-7e8fdac4.js → p-8d4be607.js} +1 -1
  382. package/dist/vega/p-8d77c7cf.js +1 -0
  383. package/dist/vega/{p-4fd0cf01.js → p-8f3b93db.js} +1 -1
  384. package/dist/vega/{p-56417ec5.entry.js → p-944e284d.entry.js} +1 -1
  385. package/dist/vega/{p-6fd4f2c6.js → p-94b54a95.js} +1 -1
  386. package/dist/vega/p-9c2b3279.js +1 -0
  387. package/dist/vega/{p-ca3c1317.entry.js → p-9c5289dc.entry.js} +1 -1
  388. package/dist/vega/{p-810c9c29.js → p-9c9b0629.js} +1 -1
  389. package/dist/vega/{p-585e4f1c.entry.js → p-9c9ff871.entry.js} +1 -1
  390. package/dist/vega/{p-2f07d719.entry.js → p-9d90e271.entry.js} +1 -1
  391. package/dist/vega/{p-d319ebb5.js → p-9e9f49f4.js} +1 -1
  392. package/dist/vega/{p-dcd3e3a7.js → p-a1f220ca.js} +1 -1
  393. package/dist/vega/{p-035e2f05.entry.js → p-a4360b7e.entry.js} +1 -1
  394. package/dist/vega/{p-6d4518d7.entry.js → p-a7517760.entry.js} +1 -1
  395. package/dist/vega/{p-c5fb8a69.entry.js → p-aa433430.entry.js} +1 -1
  396. package/dist/vega/{p-1cff027b.entry.js → p-aa914dbd.entry.js} +1 -1
  397. package/dist/vega/{p-72ab5cd5.entry.js → p-b12de1bf.entry.js} +1 -1
  398. package/dist/vega/p-b21cc390.entry.js +1 -0
  399. package/dist/vega/{p-dbb4b1d1.js → p-b3c4943b.js} +1 -1
  400. package/dist/vega/{p-1aedbfd2.entry.js → p-ba6881da.entry.js} +1 -1
  401. package/dist/vega/{p-9834d5d4.entry.js → p-bd7725f7.entry.js} +1 -1
  402. package/dist/vega/{p-a090b2be.js → p-c348eaf5.js} +1 -1
  403. package/dist/vega/{p-ccbe3f1b.entry.js → p-c8ad7207.entry.js} +1 -1
  404. package/dist/vega/{p-b3733762.entry.js → p-c8fb3aac.entry.js} +1 -1
  405. package/dist/vega/p-cc569b54.js +1 -0
  406. package/dist/vega/{p-c98c2f5f.entry.js → p-ccbed811.entry.js} +1 -1
  407. package/dist/vega/{p-da867019.entry.js → p-ce82d6bb.entry.js} +1 -1
  408. package/dist/vega/{p-a81ad3bd.js → p-cede3535.js} +1 -1
  409. package/dist/vega/p-d35a31a5.entry.js +1 -0
  410. package/dist/vega/{p-ac94ba1b.entry.js → p-d4d90ce2.entry.js} +1 -1
  411. package/dist/vega/{p-cb81126a.entry.js → p-d6023dc0.entry.js} +1 -1
  412. package/dist/vega/{p-a8174ad8.entry.js → p-d62e618a.entry.js} +1 -1
  413. package/dist/vega/{p-1ea9ad9a.js → p-dd0bd78b.js} +1 -1
  414. package/dist/vega/{p-36d2df7a.entry.js → p-ded1ecc1.entry.js} +1 -1
  415. package/dist/vega/p-df63c2fb.entry.js +1 -0
  416. package/dist/vega/{p-c6d775b8.entry.js → p-e1a65e06.entry.js} +1 -1
  417. package/dist/vega/{p-39c5054b.js → p-e1c82ca9.js} +1 -1
  418. package/dist/vega/{p-f6c0e9e7.entry.js → p-e469ba27.entry.js} +1 -1
  419. package/dist/vega/{p-373541fa.js → p-e4c5cb4f.js} +1 -1
  420. package/dist/vega/{p-ec64cc59.entry.js → p-f0a0fc77.entry.js} +1 -1
  421. package/dist/vega/{p-12e8a1b2.js → p-f13b39d8.js} +1 -1
  422. package/dist/vega/{p-4e065ef7.entry.js → p-f2384411.entry.js} +1 -1
  423. package/dist/vega/{p-8d2501b2.js → p-f9a3805d.js} +1 -1
  424. package/dist/vega/{p-1e0a8fd3.js → p-fa5cd8b1.js} +1 -1
  425. package/dist/vega/{p-2c2e8615.js → p-fcb6b499.js} +1 -1
  426. package/dist/vega/vega.esm.js +1 -1
  427. package/package.json +1 -1
  428. package/dist/collection/components/vega-rich-text-editor/extensions/paste/paste-constants.js +0 -6
  429. package/dist/types/components/vega-rich-text-editor/extensions/paste/paste-constants.d.ts +0 -6
  430. package/dist/vega/p-03eeadc1.entry.js +0 -1
  431. package/dist/vega/p-0eb29065.js +0 -3
  432. package/dist/vega/p-10d30c03.js +0 -1
  433. package/dist/vega/p-1250b1ab.entry.js +0 -1
  434. package/dist/vega/p-1abd3c17.js +0 -1
  435. package/dist/vega/p-2d158cbd.js +0 -1
  436. package/dist/vega/p-3d0b4074.js +0 -1
  437. package/dist/vega/p-56493601.js +0 -1
  438. package/dist/vega/p-571ec00b.js +0 -1
  439. package/dist/vega/p-5b1f5e4a.entry.js +0 -1
  440. package/dist/vega/p-6234852e.entry.js +0 -1
  441. package/dist/vega/p-781b7a54.js +0 -1
  442. package/dist/vega/p-cd69aeae.js +0 -1
  443. package/dist/vega/p-cfe268a8.entry.js +0 -1
  444. package/dist/vega/p-de8f0d98.js +0 -1
  445. package/dist/vega/p-f0e828d8.js +0 -1
  446. package/dist/vega/p-f62c5a20.entry.js +0 -1
  447. package/dist/vega/p-fa65956c.entry.js +0 -1
@@ -6,27 +6,27 @@ import { I as InternalVegaZIndexManager } from './internal-vega-z-index-manager-
6
6
  import { c as createDynamicSlimmer } from './dynamic-slimmer-90b8af32.js';
7
7
  import { P as PageResizeObserverSlimmer } from './page-resize-observer-slimmer-e24d36c5.js';
8
8
  import { i as internalVegaEventManager } from './internal-vega-event-manager-2ecc9186.js';
9
- import { V as VegaInternalTranslation } from './internal-translation-controller-fac22598.js';
10
- import { I as InternalCalendarPeriodConverter } from './internal-calendar-period-factory-7b294fb6.js';
11
- import { R as RTEExtensionContextManager, a as VegaRTEExtensionRenderer, b as VegaRTEExtension } from './link-extension-e8ee103e.js';
12
- import { M as ModifyContentAction, A as ActionHandleStrategyRegistry, R as RTETextNode, a as RTEBlock, b as RTETextBlock, c as RTEAnnotationStyle, d as ActionHandleStrategy, I as InsertChildrenAfterAction, e as AppendChildrenAction, f as RTENode, s as stateEntityRenderingRegistry, g as InsertChildrenBeforeAction, h as InternalAnnotationTypeEnum, i as ModifyContentActionType, B as BlockAnnotation, j as AnnotationAction, k as RemoveChildrenAction, C as CommonAnnotationTypeEnum, l as CustomAttributeAnnotation, m as RTEDTOClassManager, n as RTEFilterStylesStrategy, o as RTEDecoratorNode, S as SplitBlockWithNodeAction, U as UpdateTextAction, p as RTECodeBlock, q as RTEListItemBlock, r as RTECodeBlockNode, N as NodeAnnotationTypeEnum, t as CustomStyleAnnotation, u as RTEFilterStylesStrategyRegistry } from './code-block-9c513169.js';
13
- import { U as UpdateCursorPositionAction, V as VegaRTEContent, B as BlockToRTEBlockStrategyAbstract, E as ElementToDTOStrategy, h as htmlElementToAnnotationGenerator, I as InsertNewParagraphAction, R as RTEImageBlock, a as InsertChildrenBeforeStrategy, P as PasteContentStrategy, A as AnnotationGeneratorStrategyAbstract } from './content-state-25c81c08.js';
14
- import { i as isNonNullable } from './type-guard-f2624334.js';
9
+ import { V as VegaInternalTranslation } from './internal-translation-controller-b33430c6.js';
10
+ import { I as InternalCalendarPeriodConverter } from './internal-calendar-period-factory-d58f35c6.js';
11
+ import { M as ModifyContentAction, A as ActionHandleStrategyRegistry, R as RTETextNode, H as HTML_VOID_TAGS, a as RTEBlock, b as RTETextBlock, c as RTE_BLOCK_BOUNDARY_ATTRIBUTE, d as RTEAnnotationStyle, e as ActionHandleStrategy, I as InsertChildrenAfterAction, f as AppendChildrenAction, g as RTENode, s as stateEntityRenderingRegistry, h as InsertChildrenBeforeAction, i as InternalAnnotationTypeEnum, j as ModifyContentActionType, B as BlockAnnotation, k as AnnotationAction, l as RemoveChildrenAction, C as CommonAnnotationTypeEnum, m as CustomAttributeAnnotation, n as RTEDTOClassManager, o as RTEFilterStylesStrategy, p as RTEDecoratorNode, S as SplitBlockWithNodeAction, U as UpdateTextAction, q as RTECodeBlock, r as RTEListItemBlock, t as RTECodeBlockNode, N as NodeAnnotationTypeEnum, u as CustomStyleAnnotation, v as RTEFilterStylesStrategyRegistry, w as RTE_PASTE_MODE_DATA_TYPE } from './code-block-e6443949.js';
12
+ import { U as UpdateCursorPositionAction, V as VegaRTEContent, B as BlockToRTEBlockStrategyAbstract, E as ElementToDTOStrategy, h as htmlElementToAnnotationGenerator, H as HtmlBlockStrategy, I as InsertNewParagraphAction, R as RTEImageBlock, a as InsertChildrenBeforeStrategy, P as PasteContentStrategy, A as AnnotationGeneratorStrategyAbstract, S as StylePreservator, b as RTEImageNode } from './content-state-43cdacff.js';
13
+ import { i as isNonNullable } from './type-guard-6fc96870.js';
14
+ import { e as extensionContextManager, a as VegaRTEExtensionRenderer, b as VegaRTEExtension } from './link-extension-230bae8d.js';
15
15
  import { V as VegaInternalIconManager } from './internal-icon-manager-e7c57096.js';
16
16
  import { v as vegaNonceManager } from './vega-nonce-manager-497e5eb5.js';
17
17
  import { D as DomNodeSubjectObserverFactory, d as domNodeSubjectFactory } from './dom-node-subject-observer-factory-ddff8662.js';
18
18
  import { V as VegaDropdownClick, a as VegaClick, b as VegaPopoverHide, c as VegaPopoverShow, d as VegaChange } from './vega-event-id-f55f6977.js';
19
- import { R as RTETableExtensionAnnotationTypeEnum, a as RTE_TABLE_HEAD_DEFAULT_BACKGROUND_COLOR, S as SettingEventHandler, T as TableSettingType, b as RTETableAnnotation, c as RTETableCellAnnotation, d as RTETableHeadCellBlock, e as RowOperationEventHandler, C as ColumnOperationEventHandler, M as MergeCellsOperationEventHandler, f as SplitCellOperationEventHandler, g as RTETableColorManager, h as RTETableBlock, i as generateTableBody, j as RTETableCellBlock, k as RTETableHeadBlock, l as RTETableBodyBlock, m as getParentBlockByType, n as RTETableHeadCellAnnotation, o as TableColumnStrategy, p as getAllTableRows, q as buildTableGrid, s as setSpanAttributes, r as findCellBlockById, t as getDefaultCellBlockTemplate, I as InsertTableColumnDirection, u as buildCellStartColumnMap, v as getTableColumnCount, w as getFirstNode, x as getCellSpan, y as createNewCell, z as MergeCellsOperationType, A as RTETableRowBlock, B as getActualColumnPosition, D as InsertTableRowDirection, E as RTE_TABLE_DEFAULT_COLORS, F as INSERT_TABLE_ROW_INTO_DIFFERENT_SECTION, G as INSERT_TABLE_ROW_INTO_SAME_SECTION, H as DELETE_TABLE_ROW, J as TOGGLE_HEADER_ROW, K as INSERT_TABLE_COLUMN, L as DELETE_TABLE_COLUMN, N as TOGGLE_HEADER_TABLE_COLUMN, O as ToggleHeaderTableColumnStrategy, P as SPLIT_TABLE_CELL, Q as REPLACE_TABLE_CELL, U as SPLIT_CELL_HORIZONTALLY, W as SPLIT_CELL_VERTICALLY, X as SELECT_TABLE_COLUMN, Y as MERGE_CELLS } from './split-cell-operation-1c8e7585.js';
19
+ import { R as RTETableExtensionAnnotationTypeEnum, a as RTE_TABLE_HEAD_DEFAULT_BACKGROUND_COLOR, S as SettingEventHandler, T as TableSettingType, b as RTETableAnnotation, c as RTETableCellAnnotation, d as RTETableHeadCellBlock, e as RowOperationEventHandler, C as ColumnOperationEventHandler, M as MergeCellsOperationEventHandler, f as SplitCellOperationEventHandler, g as RTETableColorManager, h as RTETableBlock, i as generateTableBody, j as RTETableCellBlock, k as RTETableHeadBlock, l as RTETableBodyBlock, m as getParentBlockByType, n as RTETableHeadCellAnnotation, o as TableColumnStrategy, p as getAllTableRows, q as buildTableGrid, s as setSpanAttributes, r as findCellBlockById, t as getDefaultCellBlockTemplate, I as InsertTableColumnDirection, u as buildCellStartColumnMap, v as getTableColumnCount, w as getFirstNode, x as getCellSpan, y as createNewCell, z as MergeCellsOperationType, A as RTETableRowBlock, B as getActualColumnPosition, D as InsertTableRowDirection, E as RTE_TABLE_DEFAULT_COLORS, F as INSERT_TABLE_ROW_INTO_DIFFERENT_SECTION, G as INSERT_TABLE_ROW_INTO_SAME_SECTION, H as DELETE_TABLE_ROW, J as TOGGLE_HEADER_ROW, K as INSERT_TABLE_COLUMN, L as DELETE_TABLE_COLUMN, N as TOGGLE_HEADER_TABLE_COLUMN, O as ToggleHeaderTableColumnStrategy, P as SPLIT_TABLE_CELL, Q as REPLACE_TABLE_CELL, U as SPLIT_CELL_HORIZONTALLY, W as SPLIT_CELL_VERTICALLY, X as SELECT_TABLE_COLUMN, Y as MERGE_CELLS } from './split-cell-operation-89b91a38.js';
20
20
  import { C as ChangeManager } from './change-manager-6a7eb88c.js';
21
21
  import { V as VegaInternalRTEExtensionTableCellsSelectionAnchor, a as VegaInternalPopoverUpdateTarget, b as VegaInternalRTEExtensionTableCellSelectionChange } from './vega-internal-event-id-86fce049.js';
22
22
  import { r as remoteInvocationRegistry } from './remote-invocation-registry-d69245c2.js';
23
- import { V as VegaInternalThemeManager, a as VegaDarkModeStyleController } from './dark-mode-style-controller-ca5afd2d.js';
23
+ import { V as VegaInternalThemeManager, a as VegaDarkModeStyleController } from './dark-mode-style-controller-352f15ff.js';
24
24
  import { t as tryGetDocument } from './try-get-document-bef0f526.js';
25
25
  import { p as parseToPixelString } from './pixel-f32c07ce.js';
26
26
  import { c as cleanObject } from './object-0c277f57.js';
27
27
  import { d as debounce } from './timer-9321173b.js';
28
28
  import { c as camelToDashCase } from './string-a953eafc.js';
29
- import { R as ReplaceSelectedTextAction } from './image-extension-fbd1ed6e.js';
29
+ import { R as ReplaceSelectedTextAction } from './image-extension-9b8abd0d.js';
30
30
  import { c as copy } from './copy-54e45e2d.js';
31
31
 
32
32
  const VegaLoaderRuntimeMetricsPayloadDefinition = [
@@ -1103,7 +1103,7 @@ class VegaRTEToolbarButtonRenderer {
1103
1103
  * @returns {Nullable<RTEExtensionContext>} - The extension context associated with the host.
1104
1104
  */
1105
1105
  getExtensionContext(el) {
1106
- return RTEExtensionContextManager.getExtensionContext(el);
1106
+ return extensionContextManager.getExtensionContext(el);
1107
1107
  }
1108
1108
  /**
1109
1109
  * Renders a dropdown component with the specified properties and children.
@@ -1542,6 +1542,47 @@ class RTETokenNode extends RTETextNode {
1542
1542
  toHtml() {
1543
1543
  return `<span class="token" contenteditable="false" template-token-key="${this.token}" token-key="${this.token}"${super.generateAttributeString()}>${this.text}</span>`;
1544
1544
  }
1545
+ /**
1546
+ * @inheritDoc
1547
+ */
1548
+ renderHtmlFromDepth(depth, options) {
1549
+ const annotation = this.getInlineHtmlAnnotationAtDepth(depth);
1550
+ if (!annotation)
1551
+ return this.toHtml();
1552
+ return this.renderTokenWithWrapperStr(annotation);
1553
+ }
1554
+ /**
1555
+ * Render token markup wrapped by inline HTML annotations, preserving token attributes.
1556
+ *
1557
+ * @param {InlineHtmlAnnotation} inlineHtmlNode - Current wrapper annotation.
1558
+ * @returns {string} Token HTML wrapped by inline HTML annotations.
1559
+ */
1560
+ renderTokenWithWrapperStr(inlineHtmlNode) {
1561
+ const { htmlTag, child } = inlineHtmlNode;
1562
+ const attrStr = this.inlineHtmlAnnotationAttrStr(inlineHtmlNode);
1563
+ if (!child) {
1564
+ if (HTML_VOID_TAGS.has(htmlTag)) {
1565
+ return `<${htmlTag}${attrStr}>`;
1566
+ }
1567
+ return `<${htmlTag}${attrStr}>${this.toHtml()}</${htmlTag}>`;
1568
+ }
1569
+ return `<${htmlTag}${attrStr}>${this.renderTokenWithWrapperStr(child)}</${htmlTag}>`;
1570
+ }
1571
+ /**
1572
+ * Build inline HTML wrapper attributes string.
1573
+ *
1574
+ * @param {InlineHtmlAnnotation} annotation - Inline HTML annotation.
1575
+ * @returns {string} Serialized attribute string.
1576
+ */
1577
+ inlineHtmlAnnotationAttrStr(annotation) {
1578
+ const { customAttribute, customClass, customStyle } = annotation;
1579
+ const attrs = [
1580
+ ...((customAttribute === null || customAttribute === void 0 ? void 0 : customAttribute.toString()) || []),
1581
+ customClass === null || customClass === void 0 ? void 0 : customClass.toString(),
1582
+ customStyle === null || customStyle === void 0 ? void 0 : customStyle.toString(),
1583
+ ].filter(isNonNullable);
1584
+ return attrs.length > 0 ? ` ${attrs.join(' ')}` : '';
1585
+ }
1545
1586
  }
1546
1587
  RTETokenNode.dtoName = 'RTETokenNode';
1547
1588
 
@@ -1853,6 +1894,7 @@ class VegaRTELanguageExtension extends VegaRTEExtension {
1853
1894
  options = {
1854
1895
  autoMatchFormat: (_a = host.sourceEditConfig.autoMatchFormat) !== null && _a !== void 0 ? _a : true,
1855
1896
  filterInlineStyles: host.sourceEditConfig.filterInlineStyles,
1897
+ blockBoundaryRegistry: this.extensionContext.blockBoundaryRegistry,
1856
1898
  };
1857
1899
  }
1858
1900
  result = VegaRTEContent.fromHtml(codeBlock.value.code, options);
@@ -1878,6 +1920,15 @@ class InsertFunctionBlockAction extends ModifyContentAction {
1878
1920
  }
1879
1921
  }
1880
1922
 
1923
+ const FUNCTION_BLOCK_CLASS = 'statement';
1924
+ const FUNCTION_CONTENT_CLASS = 'statementelement';
1925
+ const FUNCTION_SYNTAX_CLASS = 'statementsyntax';
1926
+ const FUNCTION_ELEMENT_CLASSES = [
1927
+ FUNCTION_BLOCK_CLASS,
1928
+ FUNCTION_CONTENT_CLASS,
1929
+ FUNCTION_SYNTAX_CLASS,
1930
+ ];
1931
+
1881
1932
  /**
1882
1933
  * RTE Function Block
1883
1934
  */
@@ -1897,7 +1948,7 @@ class RTEFunctionBlock extends RTEBlock {
1897
1948
  */
1898
1949
  static from(block, options) {
1899
1950
  const functionBlock = new RTEFunctionBlock(block.id);
1900
- const defaultAnnotation = { customClass: ['statement'] };
1951
+ const defaultAnnotation = { customClass: [FUNCTION_BLOCK_CLASS] };
1901
1952
  let { annotations } = block;
1902
1953
  annotations = annotations
1903
1954
  ? Object.assign(Object.assign({}, annotations), defaultAnnotation) : defaultAnnotation;
@@ -1915,14 +1966,14 @@ class RTEFunctionBlock extends RTEBlock {
1915
1966
  .map((child) => {
1916
1967
  if (child instanceof RTETextBlock) {
1917
1968
  const attrStr = this.getFunctionContentStyle(child);
1918
- return `<div class="statementelement"${attrStr}>${child.getChildrenHtml()}</div>`;
1969
+ return `<div class="${FUNCTION_CONTENT_CLASS}"${attrStr}>${child.getChildrenHtml()}</div>`;
1919
1970
  }
1920
1971
  else {
1921
1972
  return child.toHtml();
1922
1973
  }
1923
1974
  })
1924
1975
  .join('');
1925
- return `<div class="statement">${childrenHtml}</div>`;
1976
+ return `<div class="${FUNCTION_BLOCK_CLASS}" ${RTE_BLOCK_BOUNDARY_ATTRIBUTE}>${childrenHtml}</div>`;
1926
1977
  }
1927
1978
  /**
1928
1979
  * @inheritDoc
@@ -1943,6 +1994,15 @@ class RTEFunctionBlock extends RTEBlock {
1943
1994
  getLastNode() {
1944
1995
  return this.children[this.children.length - 1].getLastNode();
1945
1996
  }
1997
+ /**
1998
+ * The function block is an atomic caret boundary: descending would resolve the caret onto a
1999
+ * `contenteditable="false"` logic-control node instead of staying anchored to the block.
2000
+ *
2001
+ * @inheritDoc
2002
+ */
2003
+ allowsCaretDescend() {
2004
+ return false;
2005
+ }
1946
2006
  /**
1947
2007
  * @inheritDoc
1948
2008
  */
@@ -2016,7 +2076,7 @@ class InsertFunctionBlockStrategy extends ActionHandleStrategy {
2016
2076
  {
2017
2077
  id: `${id}-2`,
2018
2078
  annotations: {
2019
- customClass: ['statementelement'],
2079
+ customClass: [FUNCTION_CONTENT_CLASS],
2020
2080
  },
2021
2081
  type: 'paragraph',
2022
2082
  nodes: [
@@ -2035,7 +2095,7 @@ class InsertFunctionBlockStrategy extends ActionHandleStrategy {
2035
2095
  {
2036
2096
  id: `${id}-4`,
2037
2097
  annotations: {
2038
- customClass: ['statementelement'],
2098
+ customClass: [FUNCTION_CONTENT_CLASS],
2039
2099
  },
2040
2100
  type: 'paragraph',
2041
2101
  nodes: [
@@ -2186,7 +2246,7 @@ class RTELogicControlBlock extends RTEBlock {
2186
2246
  * @returns {string} - The HTML string of the logic control block.
2187
2247
  */
2188
2248
  toHtml() {
2189
- return `<div class='statementsyntax' contenteditable='false'>${this.statementText}</div>`;
2249
+ return `<div class='${FUNCTION_SYNTAX_CLASS}' contenteditable='false'>${this.statementText}</div>`;
2190
2250
  }
2191
2251
  /**
2192
2252
  * Clone the current block instance.
@@ -2294,7 +2354,7 @@ class RTELogicControlBlockRenderer extends VegaRTEExtensionRenderer {
2294
2354
  doRender(h, renderData) {
2295
2355
  return h('div', {
2296
2356
  key: renderData.id,
2297
- class: 'statementsyntax',
2357
+ class: FUNCTION_SYNTAX_CLASS,
2298
2358
  ref: this.useRef(renderData),
2299
2359
  }, h('span', {
2300
2360
  key: `${renderData.id}-1`,
@@ -2304,13 +2364,48 @@ class RTELogicControlBlockRenderer extends VegaRTEExtensionRenderer {
2304
2364
  }
2305
2365
  }
2306
2366
 
2367
+ /**
2368
+ * Returns true when the element belongs to function extension blocks by semantic
2369
+ * boundary attribute or known function element classes.
2370
+ *
2371
+ * Use this helper for broad detection (e.g., extension-level boundary predicate
2372
+ * registration) where both container and child function elements should be
2373
+ * treated as part of the function block structure.
2374
+ *
2375
+ * @param {HTMLElement} element - Element to inspect.
2376
+ * @returns {boolean} Whether the element belongs to a function block structure.
2377
+ * @example
2378
+ * this.registerBlockBoundaryPredicate(isFunctionBlockElement);
2379
+ */
2380
+ const isFunctionBlockElement = (element) => {
2381
+ return (element.hasAttribute(RTE_BLOCK_BOUNDARY_ATTRIBUTE) ||
2382
+ FUNCTION_ELEMENT_CLASSES.some((functionClass) => element.classList.contains(functionClass)));
2383
+ };
2384
+ /**
2385
+ * Returns true when the element is a function block boundary container.
2386
+ *
2387
+ * Use this helper when conversion logic must identify only the function block
2388
+ * container element (the DIV that maps to RTEFunctionBlock), not function child
2389
+ * elements such as syntax/content nodes.
2390
+ *
2391
+ * @param {HTMLElement} element - Element to inspect.
2392
+ * @returns {boolean} Whether the element is a function block boundary container.
2393
+ * @example
2394
+ * if (isFunctionBoundaryContainer(element)) {
2395
+ * // map the DIV to RTEFunctionBlock
2396
+ * }
2397
+ */
2398
+ const isFunctionBoundaryContainer = (element) => {
2399
+ return (element.hasAttribute(RTE_BLOCK_BOUNDARY_ATTRIBUTE) || element.classList.contains(FUNCTION_BLOCK_CLASS));
2400
+ };
2401
+
2307
2402
  /**
2308
2403
  * Strategy to convert a div with class 'statementsyntax' into an RTELogicControlBlock DTO.
2309
2404
  */
2310
2405
  class DivToLogicControlBlockStrategy extends BlockToRTEBlockStrategyAbstract {
2311
2406
  constructor() {
2312
2407
  super(...arguments);
2313
- this.blockClassName = 'statementsyntax';
2408
+ this.blockClassName = FUNCTION_SYNTAX_CLASS;
2314
2409
  }
2315
2410
  /**
2316
2411
  * @inheritDoc
@@ -2353,7 +2448,7 @@ class DivToLogicControlBlockStrategy extends BlockToRTEBlockStrategyAbstract {
2353
2448
  * @returns {boolean} True if the element is a child of a function block, false otherwise
2354
2449
  */
2355
2450
  isFunctionBlockChild(element) {
2356
- return !!(element.parentElement && element.parentElement.classList.contains('statement'));
2451
+ return !!(element.parentElement && isFunctionBoundaryContainer(element.parentElement));
2357
2452
  }
2358
2453
  }
2359
2454
 
@@ -2366,11 +2461,13 @@ class DivToFunctionBlockStrategy extends ElementToDTOStrategy {
2366
2461
  */
2367
2462
  canHandle(elementsArray, currentIndex) {
2368
2463
  const element = elementsArray[currentIndex];
2369
- return element &&
2370
- element.tagName === 'DIV' &&
2371
- element.classList.contains('statement') &&
2464
+ if (element.nodeType !== Node.ELEMENT_NODE)
2465
+ return 0;
2466
+ const isFunctionBoundary = isFunctionBoundaryContainer(element);
2467
+ return element.tagName === 'DIV' &&
2468
+ isFunctionBoundary &&
2372
2469
  element.childNodes.length &&
2373
- element.querySelector('.statementsyntax')
2470
+ element.querySelector(`.${FUNCTION_SYNTAX_CLASS}`)
2374
2471
  ? 1
2375
2472
  : 0;
2376
2473
  }
@@ -2382,7 +2479,7 @@ class DivToFunctionBlockStrategy extends ElementToDTOStrategy {
2382
2479
  id: generateUUID(),
2383
2480
  type: 'function-block',
2384
2481
  annotations: {
2385
- customClass: ['statement'],
2482
+ customClass: [FUNCTION_BLOCK_CLASS],
2386
2483
  },
2387
2484
  children: [],
2388
2485
  });
@@ -2410,7 +2507,7 @@ class DivToFunctionBlockStrategy extends ElementToDTOStrategy {
2410
2507
  class DivToFunctionContentStrategy extends DivToLogicControlBlockStrategy {
2411
2508
  constructor() {
2412
2509
  super(...arguments);
2413
- this.blockClassName = 'statementelement';
2510
+ this.blockClassName = FUNCTION_CONTENT_CLASS;
2414
2511
  }
2415
2512
  /**
2416
2513
  * @inheritDoc
@@ -2418,16 +2515,31 @@ class DivToFunctionContentStrategy extends DivToLogicControlBlockStrategy {
2418
2515
  handle(elementsArray, options) {
2419
2516
  const element = elementsArray[0];
2420
2517
  const annotations = htmlElementToAnnotationGenerator.generate(RTETextBlock, element);
2421
- const nodes = Array.from(elementsArray[0].childNodes);
2422
2518
  return RTETextBlock.from({
2423
2519
  id: generateUUID(),
2424
2520
  type: 'paragraph',
2425
2521
  annotations: Object.assign({ customClass: [this.blockClassName] }, annotations),
2426
- nodes: this.generateChildNodes(nodes, undefined, options),
2522
+ nodes: this.generateChildNodes(Array.from(elementsArray[0].childNodes), undefined, options),
2427
2523
  });
2428
2524
  }
2429
2525
  }
2430
2526
 
2527
+ /** Preserve a div that contains a function block during auto-formatting. */
2528
+ class FunctionBlockContainerStrategy extends HtmlBlockStrategy {
2529
+ /**
2530
+ * @inheritDoc
2531
+ */
2532
+ canHandle(elementsArray, currentIndex) {
2533
+ const element = elementsArray[currentIndex];
2534
+ if (element.nodeType !== Node.ELEMENT_NODE)
2535
+ return 0;
2536
+ const containsFunctionBlock = !!element.querySelector(`[${RTE_BLOCK_BOUNDARY_ATTRIBUTE}], .${FUNCTION_BLOCK_CLASS}`);
2537
+ return element.nodeName === 'DIV' && !isFunctionBlockElement(element) && containsFunctionBlock
2538
+ ? 1
2539
+ : 0;
2540
+ }
2541
+ }
2542
+
2431
2543
  const functionBlockStylesCss = "div.statement{padding:2px 4px;background:rgba(var(--v-bg-accent3-secondary, 255, 239, 200));border:1px solid rgba(var(--v-bg-accent3-primary, 255, 220, 131));border-radius:4px;display:flex;flex-direction:row;justify-content:flex-start;align-items:stretch;gap:4px}div.statement .statementsyntax{padding:3px 0;line-height:22px}.rich-text-content div.statement .statementsyntax,.rich-text-content div.statement .statementelement{display:inline-block}div.statement+div.statement{margin-top:2px}div.statement .statementsyntax span{color:rgb(38, 42, 255);font-weight:bold}div.statement .statementelement{padding:2px 4px;background:rgba(var(--v-bg-secondary, 245, 247, 247));border:1px solid rgba(var(--v-border-color-input-field, 171, 198, 216));border-radius:4px;margin:0;min-width:8px}";
2432
2544
 
2433
2545
  /**
@@ -2441,6 +2553,7 @@ class RTEFunctionBlockRenderer extends VegaRTEExtensionRenderer {
2441
2553
  return createElement('div', {
2442
2554
  key: renderData.id,
2443
2555
  class: this.getElementClassName(renderData),
2556
+ [RTE_BLOCK_BOUNDARY_ATTRIBUTE]: '',
2444
2557
  ref: this.useRef(renderData),
2445
2558
  });
2446
2559
  }
@@ -2460,8 +2573,8 @@ class RTEFunctionBlockRenderer extends VegaRTEExtensionRenderer {
2460
2573
  */
2461
2574
  getElementClassName(block) {
2462
2575
  let classes = block.getClasses();
2463
- if (classes.indexOf('statement') < 0) {
2464
- classes = 'statement ' + classes;
2576
+ if (classes.indexOf(FUNCTION_BLOCK_CLASS) < 0) {
2577
+ classes = FUNCTION_BLOCK_CLASS + ' ' + classes;
2465
2578
  }
2466
2579
  return classes.trim();
2467
2580
  }
@@ -2635,12 +2748,14 @@ class PastePlainTextStrategy extends ActionHandleStrategy {
2635
2748
  const convertLogicControlBlockStrategy = new DivToLogicControlBlockStrategy();
2636
2749
  const convertFunctionContentStrategy = new DivToFunctionContentStrategy();
2637
2750
  const convertFunctionBlockStrategy = new DivToFunctionBlockStrategy();
2751
+ const convertFunctionBlockContainerStrategy = new FunctionBlockContainerStrategy();
2638
2752
  /**
2639
2753
  * Function extension class for Vega Rich Text Editor.
2640
2754
  */
2641
2755
  class VegaRTEFunctionExtension extends VegaRTEExtension {
2642
2756
  constructor() {
2643
2757
  super();
2758
+ this.unregisterBlockBoundaryPredicate = null;
2644
2759
  this.registerBlockBasicStrategies(RTELogicControlBlock.name);
2645
2760
  this.registerBlockBasicStrategies(RTEFunctionBlock.name);
2646
2761
  this.preventFunctionBlockDefaultInsertNewParagraph();
@@ -2651,11 +2766,25 @@ class VegaRTEFunctionExtension extends VegaRTEExtension {
2651
2766
  this.registerElementToBlockDTOClassStrategy(convertLogicControlBlockStrategy);
2652
2767
  this.registerElementToBlockDTOClassStrategy(convertFunctionContentStrategy);
2653
2768
  this.registerElementToBlockDTOClassStrategy(convertFunctionBlockStrategy);
2769
+ this.registerElementToBlockDTOClassStrategy(convertFunctionBlockContainerStrategy);
2654
2770
  }
2655
2771
  /** @inheritDoc */
2656
2772
  prepareBeforeLoad(host) {
2657
2773
  this.registerToolbarButtonRenderer(VegaRTEFunctionExtension.TOOLBAR_BUTTON_KEY, new FunctionToolbarButtonRenderer(), host);
2658
2774
  }
2775
+ /** @inheritDoc */
2776
+ initialExtensionAfterLoad(context) {
2777
+ var _a;
2778
+ super.initialExtensionAfterLoad(context);
2779
+ (_a = this.unregisterBlockBoundaryPredicate) === null || _a === void 0 ? void 0 : _a.call(this);
2780
+ this.unregisterBlockBoundaryPredicate = this.registerBlockBoundaryPredicate(isFunctionBlockElement);
2781
+ }
2782
+ /** @inheritDoc */
2783
+ destroyExtension() {
2784
+ var _a;
2785
+ (_a = this.unregisterBlockBoundaryPredicate) === null || _a === void 0 ? void 0 : _a.call(this);
2786
+ this.unregisterBlockBoundaryPredicate = null;
2787
+ }
2659
2788
  /**
2660
2789
  * Remove the appen children strategies to prevent default insert new paragraph logic in function block
2661
2790
  */
@@ -3310,7 +3439,7 @@ class TablePopoverBaseRenderer {
3310
3439
  */
3311
3440
  getTableExtensionContext() {
3312
3441
  return this.renderContext
3313
- ? RTEExtensionContextManager.getExtensionContext(this.renderContext.host)
3442
+ ? extensionContextManager.getExtensionContext(this.renderContext.host)
3314
3443
  : null;
3315
3444
  }
3316
3445
  }
@@ -11040,6 +11169,62 @@ class VegaRTEFullscreenExtension extends VegaRTEExtension {
11040
11169
  VegaRTEFullscreenExtension.TOOLBAR_BUTTON_KEY = 'fullscreen';
11041
11170
  VegaRTEFullscreenExtension.controllerStore = VegaRTEFullscreenExtension.createStateStore();
11042
11171
 
11172
+ var RTEPasteMode;
11173
+ (function (RTEPasteMode) {
11174
+ RTEPasteMode["RICH"] = "rich";
11175
+ RTEPasteMode["WORD"] = "word";
11176
+ })(RTEPasteMode || (RTEPasteMode = {}));
11177
+ /**
11178
+ * Priority scale shared by all paste processing strategies.
11179
+ */
11180
+ var PasteProcessingStrategyPriority;
11181
+ (function (PasteProcessingStrategyPriority) {
11182
+ /** Fallback strategy used only when no specialized strategy matches. */
11183
+ PasteProcessingStrategyPriority[PasteProcessingStrategyPriority["DEFAULT_FALLBACK"] = -1] = "DEFAULT_FALLBACK";
11184
+ /** Baseline priority for generic strategies. */
11185
+ PasteProcessingStrategyPriority[PasteProcessingStrategyPriority["BASE"] = 0] = "BASE";
11186
+ /** Word strategy priority so it outranks generic strategies. */
11187
+ PasteProcessingStrategyPriority[PasteProcessingStrategyPriority["WORD"] = 10] = "WORD";
11188
+ })(PasteProcessingStrategyPriority || (PasteProcessingStrategyPriority = {}));
11189
+ /**
11190
+ * Abstract base class for paste processing strategies.
11191
+ *
11192
+ * Each strategy implements detection logic (`canHandle`) and transformation
11193
+ * logic (`process`) for a specific clipboard source (Word, Google Docs, etc.).
11194
+ * The strategy selector chooses the highest-priority strategy that can handle
11195
+ * the given HTML.
11196
+ */
11197
+ class AbstractPasteProcessingStrategy {
11198
+ /**
11199
+ * Downstream paste mode marker associated with this strategy.
11200
+ *
11201
+ * Defaults to regular rich-text paste unless a specialized strategy overrides it.
11202
+ *
11203
+ * @returns {RTEPasteMode} Paste mode marker for downstream handlers.
11204
+ */
11205
+ get type() {
11206
+ return RTEPasteMode.RICH;
11207
+ }
11208
+ /**
11209
+ * Optional: Strategy priority when multiple strategies match.
11210
+ * Higher numbers = higher priority. Default: 0.
11211
+ *
11212
+ * @returns {number} Strategy priority.
11213
+ */
11214
+ get priority() {
11215
+ return PasteProcessingStrategyPriority.BASE;
11216
+ }
11217
+ /**
11218
+ * Whether pasted images from this source should be extracted into local
11219
+ * previews by the paste extension after {@link process} runs.
11220
+ *
11221
+ * @returns {boolean} `false` unless a strategy opts into image processing.
11222
+ */
11223
+ get supportsImageProcessing() {
11224
+ return false;
11225
+ }
11226
+ }
11227
+
11043
11228
  const paste = {
11044
11229
  icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.3.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path fill="currentColor" d="M80 96v16c0 17.7 14.3 32 32 32h60.8c16.6-28.7 47.6-48 83.2-48h62c-7.1-27.6-32.2-48-62-48H215.4C211.6 20.9 188.2 0 160 0s-51.6 20.9-55.4 48H64C28.7 48 0 76.7 0 112V384c0 35.3 28.7 64 64 64h96V400H64c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16H80zm64-40a16 16 0 1 1 32 0 16 16 0 1 1 -32 0zM256 464c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H384v48c0 17.7 14.3 32 32 32h48V448c0 8.8-7.2 16-16 16H256zm192 48c35.3 0 64-28.7 64-64V227.9c0-12.7-5.1-24.9-14.1-33.9l-51.9-51.9c-9-9-21.2-14.1-33.9-14.1H256c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H448z"/></svg>`,
11045
11230
  };
@@ -11048,9 +11233,10 @@ const paste = {
11048
11233
  * Renders and manages the paste format chooser UI.
11049
11234
  */
11050
11235
  class RTEPasteChooserUI {
11051
- constructor(hostRoot, callbacks) {
11236
+ constructor(hostRoot, callbacks, options = {}) {
11052
11237
  this.hostRoot = hostRoot;
11053
11238
  this.callbacks = callbacks;
11239
+ this.options = options;
11054
11240
  this.chooserEl = null;
11055
11241
  this.dropdownEl = null;
11056
11242
  this.triggerButtonEl = null;
@@ -11151,11 +11337,17 @@ class RTEPasteChooserUI {
11151
11337
  dropdownEl.append(tooltipEl);
11152
11338
  const itemsContainer = doc.createElement('div');
11153
11339
  itemsContainer.setAttribute('slot', 'items');
11154
- itemsContainer.append(this.createDropdownItem(doc, 'rich', VegaInternalTranslation.t('Use rich text'), RTEPasteChooserUI.CHOOSER_RICH_ATTR));
11340
+ const dropdownItems = [
11341
+ this.createDropdownItem(doc, RTEPasteMode.RICH, VegaInternalTranslation.t('Use rich text'), RTEPasteChooserUI.CHOOSER_RICH_ATTR),
11342
+ ];
11343
+ if (this.options.showWordOption) {
11344
+ dropdownItems.push(this.createDropdownItem(doc, RTEPasteMode.WORD, VegaInternalTranslation.t('Use Word'), RTEPasteChooserUI.CHOOSER_WORD_ATTR));
11345
+ }
11346
+ itemsContainer.append(...dropdownItems);
11155
11347
  dropdownEl.append(itemsContainer);
11156
11348
  dropdownEl.addEventListener('vegaDropdownClick', (event) => {
11157
11349
  const mode = event.detail;
11158
- if (mode === 'rich') {
11350
+ if (mode === RTEPasteMode.RICH || mode === RTEPasteMode.WORD) {
11159
11351
  this.callbacks.onModeSelect(mode);
11160
11352
  }
11161
11353
  });
@@ -11165,7 +11357,7 @@ class RTEPasteChooserUI {
11165
11357
  * Creates a single dropdown item element for a paste mode.
11166
11358
  *
11167
11359
  * @param {Document} doc Document used to create the element.
11168
- * @param {PasteMode} key Paste mode key for the item.
11360
+ * @param {RTEPasteMode} key Paste mode key for the item.
11169
11361
  * @param {string} label Display label for the item.
11170
11362
  * @param {string} dataAttrName Data attribute marker for the item.
11171
11363
  * @returns {HTMLVegaDropdownItemElement} Configured dropdown item element.
@@ -11185,161 +11377,2689 @@ class RTEPasteChooserUI {
11185
11377
  })();
11186
11378
  RTEPasteChooserUI.CHOOSER_ATTR = 'data-rte-paste-chooser';
11187
11379
  RTEPasteChooserUI.CHOOSER_RICH_ATTR = 'data-rte-paste-type-rich';
11380
+ RTEPasteChooserUI.CHOOSER_WORD_ATTR = 'data-rte-paste-type-word';
11188
11381
  RTEPasteChooserUI.CHOOSER_TRIGGER_ATTR = 'data-rte-paste-trigger';
11189
11382
 
11190
11383
  /**
11191
- * Custom DataTransfer MIME type used to tag a synthetic paste with the chosen
11192
- * paste mode (e.g. 'rich' or 'plain'), so downstream paste handling can decide
11193
- * whether to preserve the original inline styles.
11384
+ * Default paste processing strategy that acts as a fallback when no other
11385
+ * strategy matches. This strategy always accepts the content and passes it
11386
+ * through unchanged the normal RTE paste pipeline (DOMParser +
11387
+ * ElementToDtoStrategyProcessor) handles the rest.
11194
11388
  */
11195
- const RTE_PASTE_MODE_DATA_TYPE = 'application/x-vega-rte-paste-mode';
11389
+ class DefaultPasteProcessingStrategy extends AbstractPasteProcessingStrategy {
11390
+ /**
11391
+ * Always matches as the terminal fallback strategy.
11392
+ *
11393
+ * @param {string} html Raw clipboard HTML.
11394
+ * @returns {boolean} Always `true`.
11395
+ */
11396
+ canHandle(html) {
11397
+ // Default strategy is the fallback — always returns true.
11398
+ return html !== undefined;
11399
+ }
11400
+ /**
11401
+ * Returns the original HTML unchanged.
11402
+ *
11403
+ * @param {string} html Raw clipboard HTML.
11404
+ * @returns {string} Unchanged HTML.
11405
+ */
11406
+ process(html) {
11407
+ // Current default behavior: pass through unchanged
11408
+ // (DOMParser + ElementToDtoStrategyProcessor handles the rest)
11409
+ return html;
11410
+ }
11411
+ /**
11412
+ * Fallback priority so other strategies can win when matched.
11413
+ *
11414
+ * @returns {number} Strategy priority.
11415
+ */
11416
+ get priority() {
11417
+ return PasteProcessingStrategyPriority.DEFAULT_FALLBACK;
11418
+ }
11419
+ }
11196
11420
 
11197
11421
  /**
11198
- * Vega Rich Text Editor paste extension.
11199
- * Intercepts keyboard paste and allows users to choose paste mode.
11422
+ * Contract for Word DOM structure transformers. Each transformer is responsible
11423
+ * for one structural concern (list markers, paragraph roles, tables, images…).
11424
+ * Register new transformers in {@link WordPasteProcessingStrategy.STRUCTURE_TRANSFORMERS}
11425
+ * to extend Word paste support without touching the core pipeline.
11200
11426
  */
11201
- class VegaRTEPasteExtension extends VegaRTEExtension {
11202
- constructor() {
11203
- super(...arguments);
11204
- this.editableEl = null;
11205
- this.contentHostEl = null;
11206
- this.chooserUI = null;
11207
- this.pendingPastePayload = null;
11208
- this.listenerDocument = null;
11209
- this.listenerWindow = null;
11210
- /**
11211
- * Handles a native paste event by capturing the clipboard payload and
11212
- * rendering the paste-mode chooser.
11213
- *
11214
- * @param {ClipboardEvent} event Native clipboard paste event.
11215
- */
11216
- this.handlePasteEvent = (event) => {
11217
- var _a, _b;
11218
- const clipboardData = event.clipboardData;
11219
- if (!clipboardData) {
11220
- return;
11221
- }
11222
- // HTML is sanitized via DOMParser and ElementToDtoStrategyProcessor pipeline
11223
- const html = clipboardData.getData('text/html') || '';
11224
- const text = clipboardData.getData('text/plain') || '';
11225
- if (!html && !text) {
11226
- // Empty clipboard paste should not mutate editor content.
11227
- event.preventDefault();
11228
- event.stopPropagation();
11229
- return;
11230
- }
11231
- event.preventDefault();
11232
- event.stopPropagation();
11233
- const range = this.cloneCurrentSelectionRange();
11234
- const selectedNodes = ((_b = (_a = this.extensionContext) === null || _a === void 0 ? void 0 : _a.getSelectedNodes) === null || _b === void 0 ? void 0 : _b.call(_a)) || [];
11235
- this.pendingPastePayload = { html, text, range, selectedNodes: [...selectedNodes] };
11236
- this.renderPasteChooser(event);
11237
- };
11238
- /**
11239
- * Dismisses the chooser when a pointer interaction occurs outside of it.
11240
- *
11241
- * @param {Event} event Pointer event captured on the document.
11242
- */
11243
- this.handleOutsidePointerDown = (event) => {
11244
- if (!this.chooserUI) {
11245
- return;
11246
- }
11247
- const eventPath = typeof event.composedPath === 'function' ? event.composedPath() : [];
11248
- if (this.chooserUI.includesEventPath(eventPath)) {
11249
- return;
11250
- }
11251
- this.clearPasteChooser();
11252
- };
11253
- /**
11254
- * Dismisses the chooser when the Escape key is pressed.
11255
- *
11256
- * @param {KeyboardEvent} event Keyboard event captured on the document.
11257
- */
11258
- this.handleOutsideKeyDown = (event) => {
11259
- if (event.key === 'Escape') {
11260
- this.clearPasteChooser();
11427
+ const WORD_SANITIZE_ALL_TAGS_KEY = '*';
11428
+
11429
+ /** CSS class prefix used by the RTE to encode text-style roles on elements. */
11430
+ const RTE_TEXT_STYLE_CLASS_PREFIX = 'v-rte--text-style-';
11431
+ /**
11432
+ * Maps Word title / subtitle / heading paragraph style class names onto RTE
11433
+ * CSS text-style classes. Any pre-existing `data-type` attributes are stripped
11434
+ * first so only trusted values remain. Using a class instead of a custom
11435
+ * attribute prevents the value from leaking into the DTO's custom-attribute
11436
+ * annotation and subsequently into the serialized HTML output.
11437
+ */
11438
+ class WordParagraphRoleTransformer {
11439
+ /** @inheritDoc */
11440
+ apply(root) {
11441
+ // Strip any pre-existing data-type attributes so untrusted source values
11442
+ // can never influence the role resolution.
11443
+ Array.from(root.querySelectorAll('[data-type]')).forEach((element) => {
11444
+ element.removeAttribute('data-type');
11445
+ });
11446
+ Array.from(root.querySelectorAll('p')).forEach((paragraph) => {
11447
+ const rawClass = paragraph.getAttribute('class');
11448
+ const role = this.resolveRole(rawClass);
11449
+ // Drop the Word paragraph class once its role has been extracted so
11450
+ // that Word artifacts (e.g. `MsoTitle`, `MsoNormal`) never leak into
11451
+ // the sanitized output.
11452
+ if (rawClass !== null) {
11453
+ paragraph.removeAttribute('class');
11454
+ }
11455
+ if (role) {
11456
+ // Encode the role as an RTE text-style CSS class so the downstream
11457
+ // DTO processor can resolve it via getElementTypeByClassName().
11458
+ paragraph.classList.add(`${RTE_TEXT_STYLE_CLASS_PREFIX}${role}`);
11261
11459
  }
11262
- };
11263
- /**
11264
- * Dismisses the chooser when any relevant scroll container scrolls.
11265
- */
11266
- this.handleOutsideScroll = () => {
11267
- this.clearPasteChooser();
11268
- };
11460
+ });
11269
11461
  }
11270
11462
  /** @inheritDoc */
11271
- initialExtensionAfterLoad(context) {
11272
- super.initialExtensionAfterLoad(context);
11273
- this.hostEl = context.host;
11274
- this.attachPasteListener();
11463
+ getAllowedTags() {
11464
+ return [
11465
+ 'P',
11466
+ 'BR',
11467
+ 'SPAN',
11468
+ 'STRONG',
11469
+ 'B',
11470
+ 'EM',
11471
+ 'I',
11472
+ 'U',
11473
+ 'S',
11474
+ 'STRIKE',
11475
+ 'DEL',
11476
+ 'H1',
11477
+ 'H2',
11478
+ 'H3',
11479
+ 'H4',
11480
+ 'H5',
11481
+ 'H6',
11482
+ 'A',
11483
+ // Inline `<code>` is treated as an inline text annotation (like
11484
+ // STRONG/EM/U) and therefore lives with the paragraph/inline
11485
+ // allowlist. Block-level `<pre>` code blocks are owned by
11486
+ // {@link WordCodeBlockTransformer}.
11487
+ 'CODE',
11488
+ ];
11275
11489
  }
11276
11490
  /** @inheritDoc */
11277
- destroyExtension() {
11278
- this.detachPasteListener();
11279
- this.clearPasteChooser();
11491
+ getAllowedAttributes() {
11492
+ // `class` must be preserved so this transformer can parse Word paragraph
11493
+ // roles (e.g., MsoTitle, MsoSubtitle, MsoHeadingN) in Phase 1. These classes
11494
+ // are ultimately stripped when pasting in autoMatchFormat mode.
11495
+ return new Map([
11496
+ [WORD_SANITIZE_ALL_TAGS_KEY, ['class', 'style']],
11497
+ ['A', ['href', 'target', 'title']],
11498
+ ]);
11499
+ }
11500
+ /** @inheritDoc */
11501
+ getAllowedStyles() {
11502
+ return [
11503
+ 'color',
11504
+ 'background',
11505
+ 'text-align',
11506
+ 'text-indent',
11507
+ 'text-decoration',
11508
+ 'margin',
11509
+ 'padding',
11510
+ 'font',
11511
+ 'line-height',
11512
+ 'letter-spacing',
11513
+ 'vertical-align',
11514
+ ];
11280
11515
  }
11281
11516
  /**
11282
- * Attaches the paste listener to the editable element.
11517
+ * Resolves the RTE text style for a Word paragraph class name.
11518
+ *
11519
+ * @param {string | null} className Raw `class` attribute value.
11520
+ * @returns {WordParagraphRole | null} Matched role or `null`.
11283
11521
  */
11284
- attachPasteListener() {
11285
- const { editableEl, contentHostEl, } = this.getEditorElements();
11286
- this.editableEl = editableEl;
11287
- this.contentHostEl = contentHostEl;
11288
- if (this.editableEl) {
11289
- this.editableEl.addEventListener('paste', this.handlePasteEvent);
11522
+ resolveRole(className) {
11523
+ if (!className) {
11524
+ return null;
11525
+ }
11526
+ const normalized = className.toLowerCase();
11527
+ const headingMatch = /msoheading([1-6])/.exec(normalized);
11528
+ if (headingMatch) {
11529
+ return `heading-${headingMatch[1]}`;
11530
+ }
11531
+ if (/msosubtitle/.test(normalized)) {
11532
+ return 'subtitle';
11533
+ }
11534
+ if (/msotitle/.test(normalized)) {
11535
+ return 'title';
11536
+ }
11537
+ return null;
11538
+ }
11539
+ }
11540
+
11541
+ /** Font families Word uses to render bullet symbols rather than real characters. */
11542
+ const BULLET_FONT_PATTERN = /symbol|wingdings|webdings/i;
11543
+ /**
11544
+ * Matches the paragraph-level Word list marker (`mso-list:l0 level1 lfo1`). The
11545
+ * presence of `l<number>` distinguishes a genuine list paragraph from the inner
11546
+ * `mso-list:Ignore` marker span.
11547
+ */
11548
+ const PARAGRAPH_LIST_PATTERN = /mso-list\s*:\s*l\d+/i;
11549
+ /** Extracts the Word nesting depth (`level<number>`) from a list paragraph. */
11550
+ const LIST_LEVEL_PATTERN = /mso-list\s*:\s*l\d+\s+level(\d+)/i;
11551
+ /** Extracts the abstract Word list template id (`l<number>`). */
11552
+ const LIST_TEMPLATE_ID_PATTERN = /mso-list\s*:\s*l(\d+)/i;
11553
+ /** Extracts the Word list-format override id (`lfo<number>`), unique per list instance. */
11554
+ const LIST_OVERRIDE_ID_PATTERN = /\blfo(\d+)/i;
11555
+ /** Matches the inner span that holds the Word-rendered bullet / number glyph. */
11556
+ const LIST_IGNORE_PATTERN = /mso-list\s*:\s*ignore/i;
11557
+ /** Extracts a `font-family` declaration value from a preserved style string. */
11558
+ const FONT_FAMILY_PATTERN = /font-family\s*:\s*([^;]+)/i;
11559
+ /** Fallback Word list paragraph class when no `mso-list` style is present. */
11560
+ const LIST_PARAGRAPH_CLASS_PATTERN = /MsoListParagraph/i;
11561
+ /**
11562
+ * CSS `list-style-type` values keyed by the shape of the Word marker token.
11563
+ * Decimal markers are intentionally absent: a plain `<ol>` already renders as
11564
+ * `1. 2. 3.`, so numeric lists keep the current behavior with no inline style.
11565
+ *
11566
+ * Roman patterns explicitly accept a lone `i` / `I` (representing 1), which is
11567
+ * the typical first item of a Roman-numeral list. Multi-character sequences
11568
+ * must contain only Roman letters.
11569
+ */
11570
+ const LOWER_ROMAN_PATTERN = /^(i|[ivxlcdm]{2,})$/;
11571
+ const UPPER_ROMAN_PATTERN = /^(I|[IVXLCDM]{2,})$/;
11572
+ const LOWER_ALPHA_PATTERN = /^[a-z]+$/;
11573
+ const UPPER_ALPHA_PATTERN = /^[A-Z]+$/;
11574
+ const DECIMAL_PATTERN = /^[0-9]+$/;
11575
+ /** Extracts the `list-style-type` value from a preserved style string. */
11576
+ const LIST_STYLE_TYPE_PATTERN = /list-style-type\s*:\s*([^;]+)/i;
11577
+ /**
11578
+ * Maps the HTML `<ol type>` attribute values Word emits on real ordered lists
11579
+ * to the equivalent CSS `list-style-type`. Decimal (`type=1`) is intentionally
11580
+ * absent: a plain `<ol>` already renders as `1. 2. 3.`, so it needs no inline
11581
+ * style (matching the marker-derived handling above).
11582
+ */
11583
+ const OL_TYPE_TO_LIST_STYLE_TYPE = {
11584
+ a: 'lower-alpha',
11585
+ A: 'upper-alpha',
11586
+ i: 'lower-roman',
11587
+ I: 'upper-roman',
11588
+ };
11589
+ /**
11590
+ * Rebuilds Word list paragraphs into real `<ul>` / `<ol>` / `<li>` structures.
11591
+ *
11592
+ * Word does not emit list elements: it emits a flat sequence of `<p>` blocks
11593
+ * that each carry an `mso-list:l<id> level<depth> lfo<override>` marker plus an
11594
+ * inner `mso-list:Ignore` span that renders the visible bullet or number. This
11595
+ * transformer walks every container that hosts list paragraphs (so nested
11596
+ * `<div>` / table cells are covered), strips the marker span, decides bullet
11597
+ * vs. numbered from the marker text / font, and folds the flat items back into
11598
+ * a nested list tree the RTE slimmer can parse.
11599
+ *
11600
+ * Runs before {@link WordParagraphRoleTransformer} so the converted `<li>`
11601
+ * elements are no longer seen as paragraphs during role resolution.
11602
+ */
11603
+ class WordListRoleTransformer {
11604
+ /** @inheritDoc */
11605
+ apply(root) {
11606
+ // Word can also emit real `<ol>` / `<ul>` structures where a nested list
11607
+ // is a **sibling** of the preceding `<li>` rather than a child of it (an
11608
+ // invalid nesting the HTML parser preserves as-is). Fix that first so the
11609
+ // rest of the pipeline sees the standard `<li><ol>…</ol></li>` shape.
11610
+ this.nestSiblingLists(root);
11611
+ // Word may nest list paragraphs inside containers (e.g. `<div>`, table
11612
+ // cells). Group by their direct parent so contiguous siblings in each
11613
+ // container are folded together, regardless of where they sit in the tree.
11614
+ const containers = new Set();
11615
+ Array.from(root.querySelectorAll('p')).forEach((paragraph) => {
11616
+ if (this.isWordListParagraph(paragraph) && paragraph.parentElement) {
11617
+ containers.add(paragraph.parentElement);
11618
+ }
11619
+ });
11620
+ // Include the root itself when it hosts list paragraphs directly.
11621
+ if (Array.from(root.children).some((child) => this.isWordListParagraph(child))) {
11622
+ containers.add(root);
11290
11623
  }
11624
+ containers.forEach((container) => this.processContainer(container));
11625
+ // Word also emits real `<ol type=...>` elements whose numbering style lives
11626
+ // on the (non-allowlisted) `type` attribute. Fold that into a preserved
11627
+ // `list-style-type` so the marker style survives the allowlist pass.
11628
+ this.applyOrderedListTypeAttributes(root);
11629
+ }
11630
+ /** @inheritDoc */
11631
+ getAllowedTags() {
11632
+ return ['UL', 'OL', 'LI'];
11633
+ }
11634
+ /** @inheritDoc */
11635
+ getAllowedAttributes() {
11636
+ return new Map();
11637
+ }
11638
+ /** @inheritDoc */
11639
+ getAllowedStyles() {
11640
+ return ['list-style'];
11291
11641
  }
11292
11642
  /**
11293
- * Detaches the paste listener from the editable element.
11643
+ * Moves any `<ol>` / `<ul>` that appears as a direct child of another
11644
+ * `<ol>` / `<ul>` into the preceding `<li>` sibling, so downstream strategies
11645
+ * see a well-formed nested list. Word emits this invalid shape when it uses
11646
+ * real list elements (rather than flat `mso-list` paragraphs) — the browser
11647
+ * parser keeps the nested list as a sibling of the `<li>` it should belong
11648
+ * to, and the RTE's OL/UL block strategy would drop it because its
11649
+ * `appendChildBlocks` only keeps `<li>` children.
11650
+ *
11651
+ * Runs bottom-up so a nested list that also has misplaced children is fixed
11652
+ * before its own parent list picks it up.
11653
+ *
11654
+ * @param {HTMLElement} root Parsed body element.
11294
11655
  */
11295
- detachPasteListener() {
11296
- if (this.editableEl) {
11297
- this.editableEl.removeEventListener('paste', this.handlePasteEvent);
11656
+ nestSiblingLists(root) {
11657
+ const lists = Array.from(root.querySelectorAll('ol, ul'));
11658
+ for (let index = lists.length - 1; index >= 0; index--) {
11659
+ Array.from(lists[index].children).forEach((child) => {
11660
+ if (child.tagName !== 'OL' && child.tagName !== 'UL') {
11661
+ return;
11662
+ }
11663
+ const previousItem = child.previousElementSibling;
11664
+ if (previousItem && previousItem.tagName === 'LI') {
11665
+ previousItem.appendChild(child);
11666
+ }
11667
+ });
11298
11668
  }
11299
- this.editableEl = null;
11300
- this.contentHostEl = null;
11301
11669
  }
11302
11670
  /**
11303
- * Resolves the content host and editable element from the host shadow tree.
11671
+ * Converts the HTML `<ol type>` attribute into a preserved
11672
+ * `list-style-type` declaration for every ordered list that carries one.
11304
11673
  *
11305
- * @returns {EditorElements} Editor elements.
11674
+ * Word can paste genuine `<ol>` elements (rather than flat list paragraphs)
11675
+ * that encode alpha / Roman numbering via the legacy `type` attribute
11676
+ * (`type=a`, `type=i`, `type=I`, …). The `type` attribute is not on the
11677
+ * allowlist and would be dropped, losing the numbering style, so it is mapped
11678
+ * onto `list-style-type` inside `data-style`. Decimal (`type=1`) lists are
11679
+ * left untouched because a bare `<ol>` already renders as `1. 2. 3.`. An
11680
+ * existing `list-style-type` declaration wins and is never overwritten.
11681
+ *
11682
+ * @param {HTMLElement} root Parsed body element.
11306
11683
  */
11307
- getEditorElements() {
11308
- var _a, _b, _c, _d, _e;
11309
- const contentHostEl = (_c = (_b = (_a = this.hostEl) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('vega-rich-text-content')) !== null && _c !== void 0 ? _c : null;
11310
- const editableEl = (_e = (_d = contentHostEl === null || contentHostEl === void 0 ? void 0 : contentHostEl.shadowRoot) === null || _d === void 0 ? void 0 : _d.querySelector('.rich-text-content')) !== null && _e !== void 0 ? _e : null;
11311
- return { editableEl, contentHostEl };
11684
+ applyOrderedListTypeAttributes(root) {
11685
+ Array.from(root.querySelectorAll('ol[type]')).forEach((orderedList) => {
11686
+ const type = orderedList.getAttribute('type') || '';
11687
+ const listStyleType = OL_TYPE_TO_LIST_STYLE_TYPE[type];
11688
+ if (!listStyleType) {
11689
+ return;
11690
+ }
11691
+ const style = orderedList.getAttribute('data-style') || '';
11692
+ if (LIST_STYLE_TYPE_PATTERN.test(style)) {
11693
+ return;
11694
+ }
11695
+ const prefix = style.trim() === '' ? '' : `${style.replace(/;\s*$/, '')}; `;
11696
+ orderedList.setAttribute('data-style', `${prefix}list-style-type: ${listStyleType}`);
11697
+ });
11312
11698
  }
11313
11699
  /**
11314
- * Resolves the editable content element from the host shadow tree.
11700
+ * Walks a container, folding each contiguous run of Word list paragraphs
11701
+ * into a nested list tree in place of the original paragraphs.
11315
11702
  *
11316
- * @returns {HTMLDivElement | null} Editable element or `null` when unavailable.
11703
+ * @param {HTMLElement} container Element whose direct children may include list paragraphs.
11317
11704
  */
11318
- getEditableElement() {
11319
- const { editableEl } = this.getEditorElements();
11320
- return editableEl;
11705
+ processContainer(container) {
11706
+ const children = Array.from(container.children);
11707
+ let index = 0;
11708
+ while (index < children.length) {
11709
+ if (!this.isWordListParagraph(children[index])) {
11710
+ index++;
11711
+ continue;
11712
+ }
11713
+ const run = [];
11714
+ while (index < children.length && this.isWordListParagraph(children[index])) {
11715
+ run.push(children[index]);
11716
+ index++;
11717
+ }
11718
+ this.transformRun(run, container);
11719
+ }
11321
11720
  }
11322
11721
  /**
11323
- * Clones the current selection range so it can be restored after the user
11324
- * chooses a paste mode.
11722
+ * Determines whether an element is a Word list paragraph.
11325
11723
  *
11326
- * @returns {Range | null} Cloned range or `null` when there is no selection.
11724
+ * A paragraph is only treated as a list when it carries a genuine Word list
11725
+ * marker: either the `mso-list:l<n>` paragraph style, or the `MsoListParagraph`
11726
+ * class **together with** an inner `mso-list:Ignore` marker span. The
11727
+ * `MsoListParagraph` class alone is not sufficient — Word also uses that
11728
+ * paragraph style for plain indented content (e.g. headings), which must not
11729
+ * be folded into a `<ul>` / `<ol>`.
11730
+ *
11731
+ * @param {HTMLElement} element Candidate element.
11732
+ * @returns {boolean} `true` when the element is a `<p>` carrying a Word list marker.
11327
11733
  */
11328
- cloneCurrentSelectionRange() {
11329
- var _a;
11330
- const selection = (_a = this.extensionContext) === null || _a === void 0 ? void 0 : _a.getSelection();
11331
- if (selection && selection.rangeCount > 0) {
11332
- return selection.getRangeAt(0).cloneRange();
11734
+ isWordListParagraph(element) {
11735
+ if (element.tagName !== 'P') {
11736
+ return false;
11333
11737
  }
11334
- return null;
11738
+ const style = element.getAttribute('data-style') || '';
11739
+ if (PARAGRAPH_LIST_PATTERN.test(style)) {
11740
+ return true;
11741
+ }
11742
+ const className = element.getAttribute('class') || '';
11743
+ return LIST_PARAGRAPH_CLASS_PATTERN.test(className) && this.findMarker(element) !== undefined;
11744
+ }
11745
+ /**
11746
+ * Folds a flat run of Word list paragraphs into a nested list tree inserted
11747
+ * before the run, then removes the original paragraphs.
11748
+ *
11749
+ * @param {HTMLElement[]} run Consecutive Word list paragraphs.
11750
+ * @param {HTMLElement} container Element hosting the run.
11751
+ */
11752
+ transformRun(run, container) {
11753
+ const anchor = run[0];
11754
+ const stack = [];
11755
+ run.forEach((paragraph) => {
11756
+ // Compute the marker once per paragraph and thread it through the
11757
+ // helpers that need it, so the DOM is not re-queried multiple times.
11758
+ const marker = this.findMarker(paragraph);
11759
+ const level = this.resolveLevel(paragraph);
11760
+ const ordered = marker ? this.isOrderedMarker(marker, paragraph) : false;
11761
+ const listId = this.resolveListId(paragraph);
11762
+ // Close any lists deeper than the current item.
11763
+ while (stack.length > 0 && stack[stack.length - 1].level > level) {
11764
+ stack.pop();
11765
+ }
11766
+ // Resolve the marker style with the same-level list already open in
11767
+ // context, so an ambiguous lone "i" / "I" continues an alpha list
11768
+ // instead of being misread as Roman 1. The marker text is still on the
11769
+ // paragraph here (buildListItem strips it below).
11770
+ let top = stack[stack.length - 1];
11771
+ const listStyleType = ordered && marker ? this.resolveListStyleType(marker, top, level, listId) : null;
11772
+ const listItem = this.buildListItem(paragraph, marker);
11773
+ if (!top || top.level < level) {
11774
+ top = this.openNestedList(stack, container, anchor, ordered, level, listStyleType, listId);
11775
+ }
11776
+ else if (this.needsSiblingList(top, ordered, listStyleType, listId)) {
11777
+ top = this.openSiblingList(stack, ordered, level, listStyleType, listId);
11778
+ }
11779
+ top.listEl.appendChild(listItem);
11780
+ });
11781
+ run.forEach((paragraph) => paragraph.remove());
11335
11782
  }
11336
11783
  /**
11337
- * Renders the paste-mode chooser and wires up dismissal listeners.
11784
+ * Reports whether a same-level item must break out into a new sibling list.
11785
+ * A different Word list instance always splits (so two separate lists pasted
11786
+ * back-to-back keep independent numbering). Bullet-vs-numbered switches also
11787
+ * split, and numbered lists additionally split when the CSS `list-style-type`
11788
+ * changes (e.g. `1.` → `a)`).
11789
+ *
11790
+ * @param {OpenList} top Currently open list at the same nesting depth.
11791
+ * @param {boolean} ordered Whether the incoming item is numbered.
11792
+ * @param {string | null} listStyleType Incoming numbered list style, if any.
11793
+ * @param {string | null} listId Incoming Word list instance id, if any.
11794
+ * @returns {boolean} `true` when a new sibling list should be opened.
11795
+ */
11796
+ needsSiblingList(top, ordered, listStyleType, listId) {
11797
+ // A known change of list instance means the two runs are distinct lists.
11798
+ if (top.listId !== null && listId !== null && top.listId !== listId) {
11799
+ return true;
11800
+ }
11801
+ if (top.ordered !== ordered) {
11802
+ return true;
11803
+ }
11804
+ if (!ordered) {
11805
+ return false;
11806
+ }
11807
+ return this.readListStyleType(top.listEl) !== listStyleType;
11808
+ }
11809
+ /**
11810
+ * Reads a previously-written `list-style-type` from an open list element.
11811
+ *
11812
+ * @param {HTMLElement} listEl List element.
11813
+ * @returns {string | null} The style value, or `null` when none is set.
11814
+ */
11815
+ readListStyleType(listEl) {
11816
+ const match = LIST_STYLE_TYPE_PATTERN.exec(listEl.getAttribute('data-style') || '');
11817
+ return match ? match[1].trim() : null;
11818
+ }
11819
+ /**
11820
+ * Opens a new list nested one or more levels deeper than the current top.
11821
+ * Word occasionally skips indent levels on paste (e.g. jumping from `level1`
11822
+ * to `level3`); this walks the gap one level at a time, inserting placeholder
11823
+ * lists so the deeper list is nested through empty `<li>` anchors instead of
11824
+ * appearing as a sibling of the shallower list.
11825
+ *
11826
+ * @param {OpenList[]} stack Stack of currently open lists.
11827
+ * @param {HTMLElement} container Host element for the top-level list.
11828
+ * @param {HTMLElement} anchor Element the top-level list is inserted before.
11829
+ * @param {boolean} ordered Whether the new list is numbered.
11830
+ * @param {number} level Word nesting depth for the new list.
11831
+ * @param {string | null} listStyleType CSS `list-style-type` for ordered lists.
11832
+ * @param {string | null} listId Word list instance id for the new list.
11833
+ * @returns {OpenList} The newly opened list.
11834
+ */
11835
+ openNestedList(stack, container, anchor, ordered, level, listStyleType, listId) {
11836
+ let currentTop = stack[stack.length - 1];
11837
+ let currentLevel = currentTop ? currentTop.level : 0;
11838
+ while (currentLevel < level - 1) {
11839
+ const bridge = this.createListElement(container, ordered, null);
11840
+ this.attachList(bridge, currentTop, container, anchor);
11841
+ // Empty `<li>` anchor so the next deeper list can be nested inside it.
11842
+ bridge.appendChild(bridge.ownerDocument.createElement('li'));
11843
+ stack.push({ level: currentLevel + 1, ordered, listId, listEl: bridge });
11844
+ currentTop = stack[stack.length - 1];
11845
+ currentLevel = currentTop.level;
11846
+ }
11847
+ const parent = stack[stack.length - 1];
11848
+ const listEl = this.createListElement(container, ordered, listStyleType);
11849
+ this.attachList(listEl, parent, container, anchor);
11850
+ const opened = { level, ordered, listId, listEl };
11851
+ stack.push(opened);
11852
+ return opened;
11853
+ }
11854
+ /**
11855
+ * Replaces the current top list with a sibling list at the same nesting
11856
+ * depth. Used when the list flavor (bullet vs. numbered, or the ordered
11857
+ * marker style) flips between two consecutive same-level items.
11858
+ *
11859
+ * @param {OpenList[]} stack Stack of currently open lists.
11860
+ * @param {boolean} ordered Whether the sibling list is numbered.
11861
+ * @param {number} level Word nesting depth for the sibling list.
11862
+ * @param {string | null} listStyleType CSS `list-style-type` for ordered lists.
11863
+ * @param {string | null} listId Word list instance id for the sibling list.
11864
+ * @returns {OpenList} The newly opened sibling list.
11865
+ */
11866
+ openSiblingList(stack, ordered, level, listStyleType, listId) {
11867
+ const current = stack[stack.length - 1];
11868
+ const listEl = this.createListElement(current.listEl, ordered, listStyleType);
11869
+ const parentNode = current.listEl.parentNode;
11870
+ if (parentNode) {
11871
+ parentNode.insertBefore(listEl, current.listEl.nextSibling);
11872
+ }
11873
+ stack.pop();
11874
+ const opened = { level, ordered, listId, listEl };
11875
+ stack.push(opened);
11876
+ return opened;
11877
+ }
11878
+ /**
11879
+ * Attaches a freshly created list element either inside the last item of the
11880
+ * parent list (for nested lists) or before the run anchor (top-level lists).
11881
+ *
11882
+ * @param {HTMLElement} listEl List element to attach.
11883
+ * @param {OpenList | undefined} parent Currently open parent list, if any.
11884
+ * @param {HTMLElement} container Host element used for top-level insertion.
11885
+ * @param {HTMLElement} anchor Element the top-level list is inserted before.
11886
+ */
11887
+ attachList(listEl, parent, container, anchor) {
11888
+ if (parent) {
11889
+ const parentItem = parent.listEl.lastElementChild;
11890
+ (parentItem || parent.listEl).appendChild(listEl);
11891
+ }
11892
+ else {
11893
+ container.insertBefore(listEl, anchor);
11894
+ }
11895
+ }
11896
+ /**
11897
+ * Creates an empty `<ol>` or `<ul>` element, tagging ordered lists with a
11898
+ * `list-style-type` when their markers are not plain decimals.
11899
+ *
11900
+ * @param {HTMLElement} reference Element whose document creates the list.
11901
+ * @param {boolean} ordered Whether to create a numbered list.
11902
+ * @param {string | null} listStyleType CSS `list-style-type` for ordered lists.
11903
+ * @returns {HTMLElement} The new list element.
11904
+ */
11905
+ createListElement(reference, ordered, listStyleType) {
11906
+ const listEl = reference.ownerDocument.createElement(ordered ? 'ol' : 'ul');
11907
+ if (ordered && listStyleType) {
11908
+ // Styles are preserved as `data-style` across the DOMParser boundary and
11909
+ // restored to `style` after the allowlist pass.
11910
+ listEl.setAttribute('data-style', `list-style-type: ${listStyleType}`);
11911
+ }
11912
+ return listEl;
11913
+ }
11914
+ /**
11915
+ * Converts a Word list paragraph into an `<li>` element: the marker span is
11916
+ * removed and the remaining content is moved into the list item.
11917
+ *
11918
+ * @param {HTMLElement} paragraph Word list paragraph.
11919
+ * @param {HTMLElement | undefined} marker Pre-resolved `mso-list:Ignore` span.
11920
+ * @returns {HTMLLIElement} The populated list item.
11921
+ */
11922
+ buildListItem(paragraph, marker) {
11923
+ const listItem = paragraph.ownerDocument.createElement('li');
11924
+ if (marker) {
11925
+ this.preserveMarkerPlaceholderImages(marker, paragraph);
11926
+ this.removeMarker(marker, paragraph);
11927
+ }
11928
+ while (paragraph.firstChild) {
11929
+ listItem.appendChild(paragraph.firstChild);
11930
+ }
11931
+ return listItem;
11932
+ }
11933
+ /**
11934
+ * Moves any local (`file://`) images out of the marker span so they survive
11935
+ * marker removal as list-item placeholders.
11936
+ *
11937
+ * Word renders a picture bullet as an `<img>` inside the `mso-list:Ignore`
11938
+ * marker span. That bullet still occupies one image slot in the clipboard RTF,
11939
+ * so silently dropping it here would leave its RTF blip unconsumed and shift
11940
+ * every following image onto the wrong file. Keeping the bullet as a `file://`
11941
+ * placeholder inside the `<li>` lets downstream preview pairing consume its RTF
11942
+ * slot and then drop it (list images have no editor representation), keeping the
11943
+ * remaining images aligned with their files. Non-local bullet images have no RTF
11944
+ * counterpart and are left in the marker to be removed with it.
11945
+ *
11946
+ * @param {HTMLElement} marker Marker span holding the bullet glyph / image.
11947
+ * @param {HTMLElement} paragraph Owning list paragraph (placeholder host).
11948
+ */
11949
+ preserveMarkerPlaceholderImages(marker, paragraph) {
11950
+ const localImages = Array.from(marker.querySelectorAll('img')).filter((image) => (image.getAttribute('src') || '').startsWith('file://'));
11951
+ // Capture the original first child once so images land ahead of the list
11952
+ // content in their document order (repeated inserts before a stable anchor).
11953
+ const anchor = paragraph.firstChild;
11954
+ localImages.forEach((image) => {
11955
+ paragraph.insertBefore(image, anchor);
11956
+ });
11957
+ }
11958
+ /**
11959
+ * Removes the `mso-list:Ignore` marker span and any wrapper elements it
11960
+ * leaves empty behind.
11961
+ *
11962
+ * @param {HTMLElement} marker Marker span to remove.
11963
+ * @param {HTMLElement} paragraph Owning list paragraph (stop boundary).
11964
+ */
11965
+ removeMarker(marker, paragraph) {
11966
+ let current = marker;
11967
+ while (current !== paragraph) {
11968
+ const parent = current.parentElement;
11969
+ current.remove();
11970
+ if (!parent || parent === paragraph || !this.isEmptyElement(parent)) {
11971
+ break;
11972
+ }
11973
+ current = parent;
11974
+ }
11975
+ }
11976
+ /**
11977
+ * Finds the `mso-list:Ignore` marker span within a list paragraph.
11978
+ *
11979
+ * @param {HTMLElement} paragraph Word list paragraph.
11980
+ * @returns {HTMLElement | undefined} The marker span, if present.
11981
+ */
11982
+ findMarker(paragraph) {
11983
+ return Array.from(paragraph.querySelectorAll('span')).find((span) => LIST_IGNORE_PATTERN.test(span.getAttribute('data-style') || ''));
11984
+ }
11985
+ /**
11986
+ * Reports whether an element has no meaningful (non-whitespace) content left.
11987
+ *
11988
+ * @param {HTMLElement} element Element to inspect.
11989
+ * @returns {boolean} `true` when only whitespace remains.
11990
+ */
11991
+ isEmptyElement(element) {
11992
+ return (element.textContent || '').replace(/[\s\u00A0]/g, '') === '';
11993
+ }
11994
+ /**
11995
+ * Resolves the Word nesting depth for a list paragraph (defaults to 1).
11996
+ *
11997
+ * @param {HTMLElement} paragraph Word list paragraph.
11998
+ * @returns {number} One-based nesting depth.
11999
+ */
12000
+ resolveLevel(paragraph) {
12001
+ const style = paragraph.getAttribute('data-style') || '';
12002
+ const match = LIST_LEVEL_PATTERN.exec(style);
12003
+ return match ? parseInt(match[1], 10) : 1;
12004
+ }
12005
+ /**
12006
+ * Resolves the Word list instance id for a paragraph. Prefers the list-format
12007
+ * override (`lfo<n>`), which is unique per pasted list, and falls back to the
12008
+ * abstract list template id (`l<n>`). Returns `null` when neither is present
12009
+ * (e.g. the `MsoListParagraph` class fallback).
12010
+ *
12011
+ * @param {HTMLElement} paragraph Word list paragraph.
12012
+ * @returns {string | null} The list instance id, or `null` when unknown.
12013
+ */
12014
+ resolveListId(paragraph) {
12015
+ const style = paragraph.getAttribute('data-style') || '';
12016
+ const override = LIST_OVERRIDE_ID_PATTERN.exec(style);
12017
+ if (override) {
12018
+ return `lfo${override[1]}`;
12019
+ }
12020
+ const template = LIST_TEMPLATE_ID_PATTERN.exec(style);
12021
+ return template ? `l${template[1]}` : null;
12022
+ }
12023
+ /**
12024
+ * Decides whether a resolved marker span represents a numbered (`<ol>`) or
12025
+ * bulleted (`<ul>`) item based on its text and font.
12026
+ *
12027
+ * @param {HTMLElement} marker Marker span.
12028
+ * @param {HTMLElement} paragraph Owning list paragraph.
12029
+ * @returns {boolean} `true` for numbered items, `false` for bulleted items.
12030
+ */
12031
+ isOrderedMarker(marker, paragraph) {
12032
+ const markerText = marker.textContent.replace(/[\s\u00A0]/g, '');
12033
+ if (BULLET_FONT_PATTERN.test(this.resolveMarkerFont(marker, paragraph))) {
12034
+ return false;
12035
+ }
12036
+ // Numbered markers are alphanumeric sequences ("1.", "a)", "iv)");
12037
+ // bullet markers are standalone symbols.
12038
+ return /[0-9]/.test(markerText) || /^[a-z]+[.)]/i.test(markerText);
12039
+ }
12040
+ /**
12041
+ * Resolves the CSS `list-style-type` for a numbered list marker.
12042
+ * Plain decimal markers ("1.", "2.") return `null` so a bare `<ol>` is used;
12043
+ * alphabetic and Roman markers map to the matching CSS value so their marker
12044
+ * style is preserved.
12045
+ *
12046
+ * A lone `i` / `I` is ambiguous: it is both Roman numeral 1 and the 9th
12047
+ * letter of the alphabet. When the same-level list already open for this
12048
+ * instance is alpha, the marker is kept alpha so a long `a) ... h) i) j)`
12049
+ * run does not split into a Roman sibling at item 9; otherwise the lone
12050
+ * marker is treated as Roman 1 (the first item of a Roman list).
12051
+ *
12052
+ * @param {HTMLElement} marker Marker span.
12053
+ * @param {OpenList | undefined} openList Same-depth list already open, if any.
12054
+ * @param {number} level Word nesting depth of the incoming item.
12055
+ * @param {string | null} listId Word list instance id of the incoming item.
12056
+ * @returns {string | null} The CSS `list-style-type`, or `null` for decimals.
12057
+ */
12058
+ resolveListStyleType(marker, openList, level, listId) {
12059
+ // Drop surrounding whitespace and the trailing "." / ")" separator to
12060
+ // isolate the numbering token (e.g. "a)" -> "a", "iv." -> "iv").
12061
+ const token = marker.textContent.replace(/[\s\u00A0]/g, '').replace(/[.)]+$/, '');
12062
+ if (DECIMAL_PATTERN.test(token)) {
12063
+ return null;
12064
+ }
12065
+ // Disambiguate a lone "i" / "I" from list context before the Roman check:
12066
+ // if the current same-level list is already alpha, continue it.
12067
+ if (token === 'i' || token === 'I') {
12068
+ const alphaStyle = token === 'i' ? 'lower-alpha' : 'upper-alpha';
12069
+ if (this.continuesAlphaList(openList, level, listId, alphaStyle)) {
12070
+ return alphaStyle;
12071
+ }
12072
+ }
12073
+ // Roman tokens are checked before alpha so "i" / "I" (Roman numeral 1) and
12074
+ // multi-character sequences like "ii" / "IV" are not mistaken for letters.
12075
+ if (LOWER_ROMAN_PATTERN.test(token)) {
12076
+ return 'lower-roman';
12077
+ }
12078
+ if (UPPER_ROMAN_PATTERN.test(token)) {
12079
+ return 'upper-roman';
12080
+ }
12081
+ if (LOWER_ALPHA_PATTERN.test(token)) {
12082
+ return 'lower-alpha';
12083
+ }
12084
+ if (UPPER_ALPHA_PATTERN.test(token)) {
12085
+ return 'upper-alpha';
12086
+ }
12087
+ return null;
12088
+ }
12089
+ /**
12090
+ * Reports whether a lone `i` / `I` marker continues an already-open alpha
12091
+ * list rather than starting a Roman one. True only when the same-depth list
12092
+ * is a matching alpha `<ol>` for the same Word list instance, so an ambiguous
12093
+ * marker at item 9 stays part of the surrounding `lower-alpha` / `upper-alpha`
12094
+ * run instead of opening a Roman sibling.
12095
+ *
12096
+ * @param {OpenList | undefined} openList Same-depth list already open, if any.
12097
+ * @param {number} level Word nesting depth of the incoming item.
12098
+ * @param {string | null} listId Word list instance id of the incoming item.
12099
+ * @param {string} alphaStyle The alpha style the marker would continue.
12100
+ * @returns {boolean} `true` when the marker should be treated as alpha.
12101
+ */
12102
+ continuesAlphaList(openList, level, listId, alphaStyle) {
12103
+ if (!openList || !openList.ordered || openList.level !== level) {
12104
+ return false;
12105
+ }
12106
+ // Distinct Word list instances are separate lists; do not carry style over.
12107
+ if (openList.listId !== null && listId !== null && openList.listId !== listId) {
12108
+ return false;
12109
+ }
12110
+ return this.readListStyleType(openList.listEl) === alphaStyle;
12111
+ }
12112
+ /**
12113
+ * Resolves the effective `font-family` for a marker by walking up to the
12114
+ * paragraph, so Word's `Symbol` / `Wingdings` bullet fonts can be detected.
12115
+ *
12116
+ * @param {HTMLElement} marker Marker span.
12117
+ * @param {HTMLElement} paragraph Owning list paragraph.
12118
+ * @returns {string} The resolved font family, or an empty string.
12119
+ */
12120
+ resolveMarkerFont(marker, paragraph) {
12121
+ let node = marker;
12122
+ while (node && node !== paragraph.parentElement) {
12123
+ const match = FONT_FAMILY_PATTERN.exec(node.getAttribute('data-style') || '');
12124
+ if (match) {
12125
+ return match[1];
12126
+ }
12127
+ node = node.parentElement;
12128
+ }
12129
+ return '';
12130
+ }
12131
+ }
12132
+
12133
+ /**
12134
+ * Normalizes Word image markup into plain <img> tags, drops list-marker images,
12135
+ * and optionally remaps image source paths.
12136
+ */
12137
+ class WordImageTransformer {
12138
+ /** @inheritDoc */
12139
+ getAllowedTags() {
12140
+ return ['IMG'];
12141
+ }
12142
+ /** @inheritDoc */
12143
+ getAllowedAttributes() {
12144
+ return new Map([['IMG', ['src', 'alt', 'title', 'width', 'height']]]);
12145
+ }
12146
+ /** @inheritDoc */
12147
+ getAllowedStyles() {
12148
+ return [];
12149
+ }
12150
+ /** @inheritDoc */
12151
+ apply(root) {
12152
+ this.normalizeWordImageDataElements(root);
12153
+ this.normalizeStandardImages(root);
12154
+ this.liftImagesOutOfTextStyleBlocks(root);
12155
+ this.insertSpanBetweenAdjacentImages(root);
12156
+ }
12157
+ /**
12158
+ * Lifts images out of text-style blocks (`h1`-`h6`, Word title / subtitle
12159
+ * paragraphs) so they become standalone top-level images.
12160
+ *
12161
+ * The RTE data model represents these blocks as text blocks whose children
12162
+ * are text nodes only, so an `<img>` nested inside one has no text-node
12163
+ * representation and would be silently dropped during DTO conversion. Moving
12164
+ * each image to a sibling position right after its block lets the downstream
12165
+ * image-block strategies pick it up. Images are re-inserted in document order
12166
+ * so they stay aligned with the RTF files paired later.
12167
+ *
12168
+ * Word title / subtitle paragraphs still carry their raw `MsoTitle` /
12169
+ * `MsoSubtitle` class here because {@link WordParagraphRoleTransformer} runs
12170
+ * after this transformer.
12171
+ *
12172
+ * @param {HTMLElement} root Parsed Word fragment root.
12173
+ */
12174
+ liftImagesOutOfTextStyleBlocks(root) {
12175
+ const blockElements = Array.from(root.querySelectorAll('h1, h2, h3, h4, h5, h6, p')).filter((element) => this.isImageLiftTargetBlock(element));
12176
+ blockElements.forEach((blockElement) => {
12177
+ if (!blockElement.parentNode) {
12178
+ return;
12179
+ }
12180
+ const imageElements = Array.from(blockElement.querySelectorAll('img'));
12181
+ let referenceNode = blockElement;
12182
+ imageElements.forEach((imageElement) => {
12183
+ blockElement.parentNode.insertBefore(imageElement, referenceNode.nextSibling);
12184
+ referenceNode = imageElement;
12185
+ });
12186
+ });
12187
+ }
12188
+ /**
12189
+ * Reports whether a block hosts its images as text-only children, requiring
12190
+ * nested images to be lifted out: any heading (`h1`-`h6`) or a Word title /
12191
+ * subtitle paragraph.
12192
+ *
12193
+ * @param {HTMLElement} element Candidate block element.
12194
+ * @returns {boolean} `true` when nested images must be lifted out of the block.
12195
+ */
12196
+ isImageLiftTargetBlock(element) {
12197
+ const tagName = element.tagName.toLowerCase();
12198
+ if (/^h[1-6]$/.test(tagName)) {
12199
+ return true;
12200
+ }
12201
+ if (tagName === 'p') {
12202
+ const className = (element.getAttribute('class') || '').toLowerCase();
12203
+ return /msotitle/.test(className) || /msosubtitle/.test(className);
12204
+ }
12205
+ return false;
12206
+ }
12207
+ /**
12208
+ * Converts Word VML `v:imagedata` elements to plain `<img>` elements.
12209
+ *
12210
+ * @param {HTMLElement} root Parsed Word fragment root.
12211
+ */
12212
+ normalizeWordImageDataElements(root) {
12213
+ const imageDataElements = Array.from(root.querySelectorAll('v\\:imagedata, imagedata'));
12214
+ imageDataElements.forEach((imageDataElement) => {
12215
+ const src = imageDataElement.getAttribute('src') ||
12216
+ imageDataElement.getAttribute('o:href') ||
12217
+ imageDataElement.getAttribute('href') ||
12218
+ '';
12219
+ const alt = imageDataElement.getAttribute('alt') ||
12220
+ imageDataElement.getAttribute('o:title') ||
12221
+ imageDataElement.getAttribute('title') ||
12222
+ '';
12223
+ const wrapperElement = imageDataElement.closest('v\\:shape, shape') || imageDataElement;
12224
+ if (!src) {
12225
+ wrapperElement.remove();
12226
+ return;
12227
+ }
12228
+ // Non-local list images have no RTF counterpart, so drop them now. Local
12229
+ // (file://) list images are kept as placeholders and removed later during
12230
+ // preview pairing so the image order stays aligned with the RTF files.
12231
+ if (this.isListImage(wrapperElement) && !src.startsWith('file://')) {
12232
+ wrapperElement.remove();
12233
+ return;
12234
+ }
12235
+ const imageElement = root.ownerDocument.createElement('img');
12236
+ imageElement.setAttribute('src', src);
12237
+ if (alt) {
12238
+ imageElement.setAttribute('alt', alt);
12239
+ }
12240
+ if (wrapperElement.parentNode) {
12241
+ const shapeId = wrapperElement.getAttribute('id') || '';
12242
+ if (shapeId) {
12243
+ this.removeFallbackImagesForShapeId(root, shapeId);
12244
+ }
12245
+ wrapperElement.parentNode.insertBefore(imageElement, wrapperElement);
12246
+ wrapperElement.parentNode.removeChild(wrapperElement);
12247
+ }
12248
+ });
12249
+ }
12250
+ /**
12251
+ * Removes non-VML fallback images that reference a specific Word VML shape id.
12252
+ *
12253
+ * Word clipboard HTML often includes both `v:imagedata` and an `<img v:shapes="...">`
12254
+ * fallback for the same visual image. Once VML is normalized, the fallback must
12255
+ * be removed to avoid duplicated image handling.
12256
+ *
12257
+ * @param {HTMLElement} root Parsed Word fragment root.
12258
+ * @param {string} shapeId VML shape id referenced by fallback images.
12259
+ */
12260
+ removeFallbackImagesForShapeId(root, shapeId) {
12261
+ const imageElements = Array.from(root.querySelectorAll('img'));
12262
+ imageElements.forEach((imageElement) => {
12263
+ const referencedShapeId = imageElement.getAttribute('v:shapes') || imageElement.getAttribute('shapes') || '';
12264
+ if (referencedShapeId === shapeId) {
12265
+ imageElement.remove();
12266
+ }
12267
+ });
12268
+ }
12269
+ /**
12270
+ * Removes list-marker images and sourceless `<img>` elements.
12271
+ *
12272
+ * @param {HTMLElement} root Parsed Word fragment root.
12273
+ */
12274
+ normalizeStandardImages(root) {
12275
+ const imageElements = Array.from(root.querySelectorAll('img'));
12276
+ imageElements.forEach((imageElement) => {
12277
+ const src = imageElement.getAttribute('src') || '';
12278
+ if (this.isListImage(imageElement)) {
12279
+ // Non-local list images have no RTF counterpart, so drop them now. Local
12280
+ // (file://) list images are kept as placeholders and removed later during
12281
+ // preview pairing so the image order stays aligned with the RTF files.
12282
+ if (!src.startsWith('file://')) {
12283
+ imageElement.remove();
12284
+ }
12285
+ return;
12286
+ }
12287
+ if (!src) {
12288
+ imageElement.remove();
12289
+ }
12290
+ });
12291
+ }
12292
+ /**
12293
+ * Inserts an empty `<span> </span>` between adjacent images to avoid
12294
+ * downstream image-block parsing treating a compact image run as a single image.
12295
+ *
12296
+ * @param {HTMLElement} root Parsed Word fragment root.
12297
+ */
12298
+ insertSpanBetweenAdjacentImages(root) {
12299
+ const imageElements = Array.from(root.querySelectorAll('img'));
12300
+ imageElements.forEach((imageElement) => {
12301
+ if (!imageElement.parentNode) {
12302
+ return;
12303
+ }
12304
+ const nextSibling = imageElement.nextSibling;
12305
+ if (nextSibling &&
12306
+ nextSibling.nodeType === Node.ELEMENT_NODE &&
12307
+ nextSibling.tagName.toLowerCase() === 'img') {
12308
+ const spacerElement = root.ownerDocument.createElement('span');
12309
+ spacerElement.innerHTML = ' ';
12310
+ imageElement.parentNode.insertBefore(spacerElement, nextSibling);
12311
+ }
12312
+ });
12313
+ }
12314
+ /**
12315
+ * Currently the RTE does not support list images, so they must be removed from the paste content.
12316
+ * Local (file://) list images are kept as placeholders here and removed later during preview pairing
12317
+ * so the local images stay aligned with the RTF images; non-local list images are removed immediately.
12318
+ * Returns true when the image is part of list content and should be ignored.
12319
+ *
12320
+ * Word list markup (`MsoListParagraph` / `mso-list`) is already normalized into
12321
+ * real `li/ul/ol` by {@link WordListRoleTransformer}, which runs before this
12322
+ * transformer, so a plain list-ancestor check is sufficient here.
12323
+ *
12324
+ * @param {Element} element Image element (or its wrapper).
12325
+ * @returns {boolean} Whether this image belongs to list content.
12326
+ */
12327
+ isListImage(element) {
12328
+ return Boolean(element.closest('li,ul,ol'));
12329
+ }
12330
+ }
12331
+
12332
+ /**
12333
+ * Attribute that carries inline styles after `StylePreservator` renamed `style`
12334
+ * to `data-style`. All style reads/writes in Phase 1 target this name so the
12335
+ * declarations survive the CSP-sensitive `DOMParser` boundary (mirrors the
12336
+ * handling in {@link WordListRoleTransformer}).
12337
+ */
12338
+ const PRESERVED_STYLE_ATTR$1 = 'data-style';
12339
+ /** Table structural tags Word decorates with `Mso*` class artifacts. */
12340
+ const TABLE_SECTION_SELECTOR = 'thead, tbody, tfoot, caption, tr';
12341
+ /**
12342
+ * Table containers whose direct text children are always layout whitespace.
12343
+ * Word exports newlines and indentation between structural tags; those text
12344
+ * nodes are not valid table content and must be dropped so they do not surface
12345
+ * as stray spaces in the pasted table.
12346
+ */
12347
+ const TABLE_CONTAINER_SELECTOR = 'thead, tbody, tfoot, tr';
12348
+ /** Cell tags that may carry Word presentational attributes and span markers. */
12349
+ const TABLE_CELL_SELECTOR = 'td, th';
12350
+ /**
12351
+ * Block-level tags that mark a cell as containing block content. When a cell
12352
+ * holds one of these, any whitespace-only text node sitting beside it is Word
12353
+ * indentation (layout whitespace) rather than meaningful inline text.
12354
+ */
12355
+ const CELL_BLOCK_CHILD_TAGS = new Set([
12356
+ 'P',
12357
+ 'DIV',
12358
+ 'UL',
12359
+ 'OL',
12360
+ 'LI',
12361
+ 'H1',
12362
+ 'H2',
12363
+ 'H3',
12364
+ 'H4',
12365
+ 'H5',
12366
+ 'H6',
12367
+ 'TABLE',
12368
+ 'BLOCKQUOTE',
12369
+ 'PRE',
12370
+ ]);
12371
+ /** Span attributes whose value must be a positive integer greater than one. */
12372
+ const SPAN_ATTRIBUTES = ['colspan', 'rowspan'];
12373
+ /** Strict span values Word should emit after normalization. */
12374
+ const SPAN_VALUE_PATTERN = /^\d+$/;
12375
+ /**
12376
+ * Matches the border box-model declarations (shorthand, per-side, and the
12377
+ * width/style/color long-hands) that Word writes with point/centimeter units
12378
+ * and system color keywords the RTE table model cannot parse. Word also emits
12379
+ * per-side `border-*: none` resets to avoid double borders in its own layout,
12380
+ * which would leave the pasted table with inconsistent cell borders. All of
12381
+ * these are removed so the editor applies its uniform default border.
12382
+ * `border-collapse` / `border-spacing` are intentionally excluded so table
12383
+ * collapsing is preserved.
12384
+ */
12385
+ const BORDER_BOX_STYLE_PATTERN = /^border(-(top|right|bottom|left))?(-(width|style|color))?$/;
12386
+ /**
12387
+ * Matches padding declarations (shorthand and per-side) that Word writes with
12388
+ * point/centimeter units the RTE cannot parse. Removed so the editor applies
12389
+ * its default cell padding.
12390
+ */
12391
+ const PADDING_STYLE_PATTERN = /^padding(-(top|right|bottom|left))?$/;
12392
+ /**
12393
+ * Matches the standalone `width` declaration (not `min-width` / `max-width`).
12394
+ * Word writes cell widths in points, so the point-based declaration is removed
12395
+ * and replaced with the clean pixel value carried by the `width` attribute.
12396
+ */
12397
+ const WIDTH_STYLE_PATTERN = /^width$/;
12398
+ /** Numeric zero (with optional decimal and optional unit suffix). */
12399
+ const ZERO_LENGTH_PATTERN = /^0+(\.0+)?([a-z%]+)?$/i;
12400
+ /**
12401
+ * Maps Word cell presentational attributes onto the CSS declarations the RTE
12402
+ * table cell annotation understands. These attributes are not on the paste
12403
+ * allowlist, so migrating them into `data-style` is the only way to preserve
12404
+ * the author's intent (shading, alignment) through sanitization. Only
12405
+ * properties whose prefix is retained by the sanitizer are migrated, so
12406
+ * fixed-width/height artifacts are intentionally dropped.
12407
+ */
12408
+ const CELL_ATTRIBUTE_STYLE_MAP = [
12409
+ // eslint-disable-next-line spellcheck/spell-checker
12410
+ { attribute: 'valign', property: 'vertical-align' },
12411
+ { attribute: 'align', property: 'text-align' },
12412
+ // eslint-disable-next-line spellcheck/spell-checker
12413
+ { attribute: 'bgcolor', property: 'background-color' },
12414
+ ];
12415
+ /**
12416
+ * Normalizes Microsoft Word table markup into clean, RTE-friendly tables.
12417
+ *
12418
+ * Word emits real `<table>/<tr>/<td>` elements, so the paste allowlist already
12419
+ * keeps the structure. What it cannot fix is the Word-specific decoration that
12420
+ * rides along:
12421
+ * - `Mso*` class names (e.g. `MsoTableGrid`) survive because `class` is globally
12422
+ * allowed; they are Word artifacts and must not leak into the output.
12423
+ * - Cell shading and alignment live in presentational attributes (`bgcolor`,
12424
+ * `align`, `valign`) that the allowlist strips, losing the formatting; they
12425
+ * are migrated into `data-style` so the RTE cell annotation can read them.
12426
+ * - `colspan`/`rowspan` may carry redundant `1` values or non-numeric junk that
12427
+ * is normalized so span tables map cleanly onto the RTE table model.
12428
+ * - Table and cell borders/padding are written with point/centimeter units,
12429
+ * system color keywords, and per-side `border-*: none` resets that the RTE
12430
+ * cannot parse and that render inconsistent borders; they are stripped so the
12431
+ * editor applies its uniform default border and padding.
12432
+ * - Cell widths arrive both as a point-based `width` style (which the RTE cannot
12433
+ * parse) and a pixel `width` attribute; the point style is dropped and the
12434
+ * attribute is migrated into a clean pixel `width` declaration.
12435
+ */
12436
+ class WordTableTransformer {
12437
+ /** @inheritDoc */
12438
+ apply(root) {
12439
+ Array.from(root.querySelectorAll('table')).forEach((table) => this.normalizeTable(table));
12440
+ }
12441
+ /** @inheritDoc */
12442
+ getAllowedTags() {
12443
+ return ['TABLE', 'THEAD', 'TBODY', 'TR', 'TH', 'TD', 'CAPTION'];
12444
+ }
12445
+ /** @inheritDoc */
12446
+ getAllowedAttributes() {
12447
+ return new Map([
12448
+ ['TD', ['colspan', 'rowspan']],
12449
+ ['TH', ['colspan', 'rowspan']],
12450
+ ]);
12451
+ }
12452
+ /** @inheritDoc */
12453
+ getAllowedStyles() {
12454
+ return ['border', 'width'];
12455
+ }
12456
+ /**
12457
+ * Strips Word class artifacts from a table and its structural descendants,
12458
+ * then normalizes every cell's span attributes and presentational styling.
12459
+ *
12460
+ * @param {HTMLTableElement} table Word table element to normalize in place.
12461
+ */
12462
+ normalizeTable(table) {
12463
+ this.removeStructuralWhitespace(table);
12464
+ this.stripClass(table);
12465
+ this.removeBorderAndPaddingStyles(table);
12466
+ Array.from(table.querySelectorAll(TABLE_SECTION_SELECTOR)).forEach((section) => this.stripClass(section));
12467
+ this.removeHiddenMisalignedCells(table);
12468
+ this.mergeFooterIntoBody(table);
12469
+ this.promoteHeadCells(table);
12470
+ Array.from(table.querySelectorAll(TABLE_CELL_SELECTOR)).forEach((cell) => {
12471
+ this.removeCellLayoutWhitespace(cell);
12472
+ this.stripClass(cell);
12473
+ this.normalizeSpanAttributes(cell);
12474
+ this.migrateCellAttributes(cell);
12475
+ this.migrateCellWidth(cell);
12476
+ this.removeBorderAndPaddingStyles(cell);
12477
+ });
12478
+ }
12479
+ /**
12480
+ * Removes Word's hidden `!supportMisalignedRows` placeholder cell. Word
12481
+ * appends it as a zero-width trailing cell to keep legacy layout engines
12482
+ * aligned, but it is not real content and should not survive paste as an
12483
+ * extra visible column. Only the row's last cell is considered so an
12484
+ * intentional interior zero-width cell is never dropped, and only rows that
12485
+ * belong to this table (not a nested one) are touched.
12486
+ *
12487
+ * @param {HTMLTableElement} table Word table element.
12488
+ */
12489
+ removeHiddenMisalignedCells(table) {
12490
+ Array.from(table.querySelectorAll('tr'))
12491
+ .filter((row) => this.isRowOfTable(table, row))
12492
+ .forEach((row) => {
12493
+ const lastCell = row.lastElementChild;
12494
+ if (lastCell &&
12495
+ (lastCell.tagName === 'TD' || lastCell.tagName === 'TH') &&
12496
+ this.isHiddenMisalignedCell(lastCell)) {
12497
+ row.removeChild(lastCell);
12498
+ }
12499
+ });
12500
+ }
12501
+ /**
12502
+ * Reports whether a row belongs directly to the given table rather than to a
12503
+ * nested table, so the recursive `tr` query never reaches into a child table.
12504
+ *
12505
+ * @param {HTMLTableElement} table Table being normalized.
12506
+ * @param {HTMLTableRowElement} row Row to test.
12507
+ * @returns {boolean} `true` when the row's nearest ancestor table is `table`.
12508
+ */
12509
+ isRowOfTable(table, row) {
12510
+ let ancestor = row.parentElement;
12511
+ while (ancestor && ancestor.tagName !== 'BODY') {
12512
+ if (ancestor.tagName === 'TABLE') {
12513
+ return ancestor === table;
12514
+ }
12515
+ ancestor = ancestor.parentElement;
12516
+ }
12517
+ return false;
12518
+ }
12519
+ /**
12520
+ * Detects Word's hidden misaligned-row placeholder cell.
12521
+ *
12522
+ * @param {HTMLTableCellElement} cell Cell to inspect.
12523
+ * @returns {boolean} `true` when the cell is a hidden placeholder.
12524
+ */
12525
+ isHiddenMisalignedCell(cell) {
12526
+ if (this.hasExplicitSpan(cell)) {
12527
+ return false;
12528
+ }
12529
+ if (!this.hasZeroWidthMarker(cell)) {
12530
+ return false;
12531
+ }
12532
+ return !this.hasMeaningfulCellContent(cell);
12533
+ }
12534
+ /**
12535
+ * Reports whether a cell explicitly spans rows/columns.
12536
+ *
12537
+ * @param {HTMLTableCellElement} cell Cell to inspect.
12538
+ * @returns {boolean} `true` when colspan/rowspan is present.
12539
+ */
12540
+ hasExplicitSpan(cell) {
12541
+ return SPAN_ATTRIBUTES.some((attribute) => cell.hasAttribute(attribute));
12542
+ }
12543
+ /**
12544
+ * Reports whether a cell is explicitly marked with zero width via attribute
12545
+ * or preserved inline style.
12546
+ *
12547
+ * @param {HTMLTableCellElement} cell Cell to inspect.
12548
+ * @returns {boolean} `true` when width is explicitly zero.
12549
+ */
12550
+ hasZeroWidthMarker(cell) {
12551
+ const widthAttribute = cell.getAttribute('width');
12552
+ if (widthAttribute !== null && ZERO_LENGTH_PATTERN.test(widthAttribute.trim())) {
12553
+ return true;
12554
+ }
12555
+ const style = cell.getAttribute(PRESERVED_STYLE_ATTR$1);
12556
+ if (style === null) {
12557
+ return false;
12558
+ }
12559
+ const widthDeclarationValue = this.readStyleDeclaration(style, 'width');
12560
+ return widthDeclarationValue !== null && ZERO_LENGTH_PATTERN.test(widthDeclarationValue);
12561
+ }
12562
+ /**
12563
+ * Reports whether a cell has meaningful text content. `trim()` already treats
12564
+ * the non-breaking space Word emits as blank, so a zero-width cell holding
12565
+ * only markup (including an image) is intentionally treated as empty and
12566
+ * removed.
12567
+ *
12568
+ * @param {HTMLTableCellElement} cell Cell to inspect.
12569
+ * @returns {boolean} `true` when the cell has meaningful text.
12570
+ */
12571
+ hasMeaningfulCellContent(cell) {
12572
+ return (cell.textContent || '').trim() !== '';
12573
+ }
12574
+ /**
12575
+ * Reads one declaration value from a style string.
12576
+ *
12577
+ * @param {string} style Preserved style text.
12578
+ * @param {string} property CSS property name to read.
12579
+ * @returns {string | null} Declaration value when present.
12580
+ */
12581
+ readStyleDeclaration(style, property) {
12582
+ const declarations = style
12583
+ .split(';')
12584
+ .map((declaration) => declaration.trim())
12585
+ .filter((declaration) => declaration !== '');
12586
+ for (const declaration of declarations) {
12587
+ const separator = declaration.indexOf(':');
12588
+ if (separator === -1) {
12589
+ continue;
12590
+ }
12591
+ const name = declaration.slice(0, separator).trim().toLowerCase();
12592
+ if (name !== property.toLowerCase()) {
12593
+ continue;
12594
+ }
12595
+ const value = declaration.slice(separator + 1).trim();
12596
+ return value === '' ? null : value;
12597
+ }
12598
+ return null;
12599
+ }
12600
+ /**
12601
+ * Collapses every `<tfoot>` into the table body because the RTE table model
12602
+ * has no footer section. Left in place, an unsupported `<tfoot>` is unwrapped
12603
+ * by the paste sanitizer into a bare `<tr>` under `<table>`, so its rows lose
12604
+ * their section placement. When the table already has a `<tbody>`, the
12605
+ * footer's rows are appended to the last body so they stay in document order;
12606
+ * otherwise the `<tfoot>` itself is renamed to `<tbody>` so its rows survive
12607
+ * as body content.
12608
+ *
12609
+ * @param {HTMLTableElement} table Word table element.
12610
+ */
12611
+ mergeFooterIntoBody(table) {
12612
+ const footers = Array.from(table.children).filter((child) => child.tagName === 'TFOOT');
12613
+ footers.forEach((footer) => {
12614
+ const bodies = Array.from(table.children).filter((child) => child.tagName === 'TBODY');
12615
+ const targetBody = bodies[bodies.length - 1];
12616
+ if (targetBody) {
12617
+ while (footer.firstChild) {
12618
+ targetBody.appendChild(footer.firstChild);
12619
+ }
12620
+ if (footer.parentNode) {
12621
+ footer.parentNode.removeChild(footer);
12622
+ }
12623
+ }
12624
+ else {
12625
+ this.replaceElementTag(footer, 'tbody');
12626
+ }
12627
+ });
12628
+ }
12629
+ /**
12630
+ * Promotes `<td>` cells that Word places directly inside a `<thead>` row to
12631
+ * `<th>`. The RTE identifies header cells solely by the `TH` tag, so without
12632
+ * this the head row would be parsed as ordinary body cells and lose its
12633
+ * header annotations and rendering. Only direct `thead > tr > td` cells are
12634
+ * converted so cells of a nested table are never touched.
12635
+ *
12636
+ * @param {HTMLTableElement} table Word table element.
12637
+ */
12638
+ promoteHeadCells(table) {
12639
+ Array.from(table.querySelectorAll('thead')).forEach((head) => {
12640
+ Array.from(head.children).forEach((row) => {
12641
+ if (row.tagName !== 'TR') {
12642
+ return;
12643
+ }
12644
+ Array.from(row.children).forEach((cell) => {
12645
+ if (cell.tagName === 'TD') {
12646
+ this.renameCell(cell, 'th');
12647
+ }
12648
+ });
12649
+ });
12650
+ });
12651
+ }
12652
+ /**
12653
+ * Replaces a table cell element with an equivalent cell of a different tag,
12654
+ * preserving its attributes and child nodes.
12655
+ *
12656
+ * @param {HTMLTableCellElement} cell Cell to replace.
12657
+ * @param {string} tagName Target cell tag name (`th` / `td`).
12658
+ */
12659
+ renameCell(cell, tagName) {
12660
+ this.replaceElementTag(cell, tagName);
12661
+ }
12662
+ /**
12663
+ * Replaces an element with an equivalent element of a different tag,
12664
+ * preserving its attributes and child nodes and its position in the tree.
12665
+ *
12666
+ * @param {Element} element Element to replace.
12667
+ * @param {string} tagName Target tag name.
12668
+ * @returns {HTMLElement} The replacement element.
12669
+ */
12670
+ replaceElementTag(element, tagName) {
12671
+ const replacement = element.ownerDocument.createElement(tagName);
12672
+ Array.from(element.attributes).forEach((attr) => {
12673
+ replacement.setAttribute(attr.name, attr.value);
12674
+ });
12675
+ while (element.firstChild) {
12676
+ replacement.appendChild(element.firstChild);
12677
+ }
12678
+ if (element.parentNode) {
12679
+ element.parentNode.replaceChild(replacement, element);
12680
+ }
12681
+ return replacement;
12682
+ }
12683
+ /**
12684
+ * Removes the `class` attribute so Word style class names cannot leak into
12685
+ * the sanitized output (the global allowlist keeps `class` on every tag).
12686
+ *
12687
+ * @param {HTMLElement} element Table structural element.
12688
+ */
12689
+ stripClass(element) {
12690
+ if (element.hasAttribute('class')) {
12691
+ element.removeAttribute('class');
12692
+ }
12693
+ }
12694
+ /**
12695
+ * Drops whitespace-only text nodes that sit directly inside the table and its
12696
+ * row containers. Word exports newlines/indentation between structural tags,
12697
+ * which are invalid as table content and would otherwise render as stray
12698
+ * spaces once the table is pasted.
12699
+ *
12700
+ * @param {HTMLTableElement} table Word table element.
12701
+ */
12702
+ removeStructuralWhitespace(table) {
12703
+ const containers = [
12704
+ table,
12705
+ ...Array.from(table.querySelectorAll(TABLE_CONTAINER_SELECTOR)),
12706
+ ];
12707
+ containers.forEach((container) => {
12708
+ Array.from(container.childNodes).forEach((node) => {
12709
+ if (node.nodeType === Node.TEXT_NODE && (node.textContent || '').trim() === '') {
12710
+ container.removeChild(node);
12711
+ }
12712
+ });
12713
+ });
12714
+ }
12715
+ /**
12716
+ * Drops whitespace-only text nodes that sit directly inside a cell whose
12717
+ * content is block-level (e.g. Word wraps every cell's text in `<p>`). Word
12718
+ * indents its markup, so these text nodes are pure layout whitespace; left in
12719
+ * place each one is wrapped into its own paragraph by the RTE, producing the
12720
+ * stray empty lines seen above and below the real cell content. Cells that
12721
+ * only hold inline content are skipped so meaningful spaces between inline
12722
+ * runs are never merged.
12723
+ *
12724
+ * @param {HTMLTableCellElement} cell Table cell element.
12725
+ */
12726
+ removeCellLayoutWhitespace(cell) {
12727
+ const hasBlockChild = Array.from(cell.children).some((child) => CELL_BLOCK_CHILD_TAGS.has(child.tagName));
12728
+ if (!hasBlockChild) {
12729
+ return;
12730
+ }
12731
+ Array.from(cell.childNodes).forEach((node) => {
12732
+ if (node.nodeType === Node.TEXT_NODE && (node.textContent || '').trim() === '') {
12733
+ cell.removeChild(node);
12734
+ }
12735
+ });
12736
+ }
12737
+ /**
12738
+ * Normalizes `colspan` / `rowspan` values: a redundant span of `1` or any
12739
+ * non-numeric value is removed, and valid spans are rewritten as a clean
12740
+ * integer so the RTE table model reads them consistently.
12741
+ *
12742
+ * @param {HTMLTableCellElement} cell Table cell element.
12743
+ */
12744
+ normalizeSpanAttributes(cell) {
12745
+ SPAN_ATTRIBUTES.forEach((attribute) => {
12746
+ const raw = cell.getAttribute(attribute);
12747
+ if (raw === null) {
12748
+ return;
12749
+ }
12750
+ const value = Number(raw);
12751
+ if (!SPAN_VALUE_PATTERN.test(raw) || value <= 1) {
12752
+ cell.removeAttribute(attribute);
12753
+ }
12754
+ else {
12755
+ cell.setAttribute(attribute, String(value));
12756
+ }
12757
+ });
12758
+ }
12759
+ /**
12760
+ * Migrates Word cell presentational attributes into `data-style` so the RTE
12761
+ * cell annotation can read the shading and alignment, then removes the
12762
+ * original attributes. An existing declaration for the same property always
12763
+ * wins and is never overwritten.
12764
+ *
12765
+ * @param {HTMLTableCellElement} cell Table cell element.
12766
+ */
12767
+ migrateCellAttributes(cell) {
12768
+ CELL_ATTRIBUTE_STYLE_MAP.forEach(({ attribute, property }) => {
12769
+ const value = cell.getAttribute(attribute);
12770
+ if (value && value.trim() !== '') {
12771
+ this.appendStyleDeclaration(cell, property, value.trim().toLowerCase());
12772
+ }
12773
+ cell.removeAttribute(attribute);
12774
+ });
12775
+ }
12776
+ /**
12777
+ * Converts a cell's `width` attribute into a `width` style declaration. Word
12778
+ * emits the width both as a point-based inline style (which the RTE cannot
12779
+ * parse) and as a pixel `width` attribute; the point style is dropped and the
12780
+ * attribute value becomes a clean pixel `width` declaration (a bare number is
12781
+ * treated as pixels, any explicit unit such as `%` is kept as-is).
12782
+ *
12783
+ * @param {HTMLTableCellElement} cell Table cell element.
12784
+ */
12785
+ migrateCellWidth(cell) {
12786
+ const attributeWidth = cell.getAttribute('width');
12787
+ cell.removeAttribute('width');
12788
+ // Drop Word's point-based width so it cannot survive as an unparseable value.
12789
+ this.removeMatchingStyleDeclarations(cell, (property) => WIDTH_STYLE_PATTERN.test(property));
12790
+ const cssWidth = this.toCssWidth(attributeWidth);
12791
+ if (cssWidth !== null) {
12792
+ this.appendStyleDeclaration(cell, 'width', cssWidth);
12793
+ }
12794
+ }
12795
+ /**
12796
+ * Normalizes a cell `width` attribute value into a CSS width value. A bare
12797
+ * number is treated as pixels; any value carrying an explicit unit (e.g. `%`)
12798
+ * is kept as-is. An empty or missing value yields `null`.
12799
+ *
12800
+ * @param {string | null} value Raw `width` attribute value.
12801
+ * @returns {string | null} CSS width value, or `null` when there is nothing to migrate.
12802
+ */
12803
+ toCssWidth(value) {
12804
+ if (value === null || value.trim() === '') {
12805
+ return null;
12806
+ }
12807
+ const trimmed = value.trim();
12808
+ return /^\d+(\.\d+)?$/.test(trimmed) ? `${trimmed}px` : trimmed;
12809
+ }
12810
+ /**
12811
+ * Appends a `property: value` declaration to the preserved style attribute
12812
+ * unless the property is already declared.
12813
+ *
12814
+ * @param {HTMLElement} element Element receiving the declaration.
12815
+ * @param {string} property CSS property name.
12816
+ * @param {string} value CSS value.
12817
+ */
12818
+ appendStyleDeclaration(element, property, value) {
12819
+ const existing = element.getAttribute(PRESERVED_STYLE_ATTR$1) || '';
12820
+ if (this.styleHasProperty(existing, property)) {
12821
+ return;
12822
+ }
12823
+ const prefix = existing.trim() === '' ? '' : `${existing.replace(/;\s*$/, '')}; `;
12824
+ element.setAttribute(PRESERVED_STYLE_ATTR$1, `${prefix}${property}: ${value}`);
12825
+ }
12826
+ /**
12827
+ * Removes every border box-model and padding declaration from the preserved
12828
+ * style so Word's point/centimeter units, system color keywords, and per-side
12829
+ * `border-*: none` resets cannot reach the RTE. Once these are gone the table
12830
+ * and cell annotations fall back to the editor's default border
12831
+ * (`solid 1px #ddd`) and padding (`12px`), giving every pasted cell a uniform
12832
+ * border. `border-collapse` / `border-spacing` are preserved so table
12833
+ * collapsing is unaffected.
12834
+ *
12835
+ * @param {HTMLElement} element Table or cell element to normalize.
12836
+ */
12837
+ removeBorderAndPaddingStyles(element) {
12838
+ this.removeMatchingStyleDeclarations(element, (property) => BORDER_BOX_STYLE_PATTERN.test(property) || PADDING_STYLE_PATTERN.test(property));
12839
+ }
12840
+ /**
12841
+ * Removes every preserved-style declaration whose property name matches the
12842
+ * given predicate, rewriting (or dropping) the `data-style` attribute.
12843
+ *
12844
+ * @param {HTMLElement} element Element whose preserved style is filtered.
12845
+ * @param {(property: string) => boolean} shouldRemove Predicate that returns
12846
+ * `true` for property names to drop (receives the lower-cased name).
12847
+ */
12848
+ removeMatchingStyleDeclarations(element, shouldRemove) {
12849
+ const raw = element.getAttribute(PRESERVED_STYLE_ATTR$1);
12850
+ if (raw === null || raw.trim() === '') {
12851
+ return;
12852
+ }
12853
+ const kept = raw
12854
+ .split(';')
12855
+ .map((declaration) => declaration.trim())
12856
+ .filter((declaration) => declaration !== '')
12857
+ .filter((declaration) => {
12858
+ const separator = declaration.indexOf(':');
12859
+ if (separator === -1) {
12860
+ return true;
12861
+ }
12862
+ const property = declaration.slice(0, separator).trim().toLowerCase();
12863
+ return !shouldRemove(property);
12864
+ });
12865
+ if (kept.length > 0) {
12866
+ element.setAttribute(PRESERVED_STYLE_ATTR$1, kept.join('; '));
12867
+ }
12868
+ else {
12869
+ element.removeAttribute(PRESERVED_STYLE_ATTR$1);
12870
+ }
12871
+ }
12872
+ /**
12873
+ * Reports whether a preserved style string already declares a property.
12874
+ *
12875
+ * @param {string} style Preserved style attribute value.
12876
+ * @param {string} property CSS property name.
12877
+ * @returns {boolean} `true` when the property is already present.
12878
+ */
12879
+ styleHasProperty(style, property) {
12880
+ return new RegExp(`(^|;)\\s*${property}\\s*:`, 'i').test(style);
12881
+ }
12882
+ }
12883
+
12884
+ /**
12885
+ * Attribute that the RTE code-block parser uses to recognize code content.
12886
+ */
12887
+ const CODE_LANGUAGE_ATTR = 'data-language';
12888
+ /**
12889
+ * Default language applied when pasted code has no language metadata.
12890
+ */
12891
+ const DEFAULT_CODE_LANGUAGE = 'plainText';
12892
+ /**
12893
+ * Matches language hints encoded as CSS classes (for example `language-js`).
12894
+ */
12895
+ const LANGUAGE_CLASS_PATTERN = /(?:^|\s)(?:language|lang)-([a-z0-9+_.-]+)(?:\s|$)/i;
12896
+ /**
12897
+ * Removes Word-only class artifacts from code elements while preserving other
12898
+ * classes. Kept as defense-in-depth: even though the shared sanitizer allowlist
12899
+ * generally strips `Mso*` classes, this transformer normalizes the `<pre>`
12900
+ * class list before language resolution so a stray `MsoPlainText` can never
12901
+ * leak into `LANGUAGE_CLASS_PATTERN` matching.
12902
+ */
12903
+ const WORD_CLASS_NAME_PATTERN = /^mso[a-z0-9_-]*$/i;
12904
+ /**
12905
+ * Normalizes pasted `<pre>` nodes so they can be parsed as RTE code blocks.
12906
+ *
12907
+ * The RTE recognizes a code block only when `data-language` is present on
12908
+ * `<pre>`. Word-exported snippets commonly use plain `<pre>` with no
12909
+ * language metadata, so this transformer adds a default language and copies any
12910
+ * detectable language hint from nested code markup when available.
12911
+ */
12912
+ class WordCodeBlockTransformer {
12913
+ /**
12914
+ * Determines whether a node is a code block whose whitespace must be preserved.
12915
+ *
12916
+ * @param {Node} node Node to inspect.
12917
+ * @returns {boolean} `true` when the node is a `<pre>` element.
12918
+ */
12919
+ static isCodeBlock(node) {
12920
+ return node.nodeType === Node.ELEMENT_NODE && node.tagName.toUpperCase() === 'PRE';
12921
+ }
12922
+ /** @inheritDoc */
12923
+ apply(root) {
12924
+ Array.from(root.querySelectorAll('pre')).forEach((preElement) => {
12925
+ this.stripWordClassArtifacts(preElement);
12926
+ if (!preElement.hasAttribute(CODE_LANGUAGE_ATTR)) {
12927
+ preElement.setAttribute(CODE_LANGUAGE_ATTR, this.resolveLanguage(preElement));
12928
+ }
12929
+ });
12930
+ }
12931
+ /** @inheritDoc */
12932
+ getAllowedTags() {
12933
+ return ['PRE'];
12934
+ }
12935
+ /** @inheritDoc */
12936
+ getAllowedAttributes() {
12937
+ return new Map([['PRE', [CODE_LANGUAGE_ATTR]]]);
12938
+ }
12939
+ /** @inheritDoc */
12940
+ getAllowedStyles() {
12941
+ return [];
12942
+ }
12943
+ /**
12944
+ * Resolves code language metadata from `<pre>` class hints, falling back to
12945
+ * {@link DEFAULT_CODE_LANGUAGE}.
12946
+ *
12947
+ * `apply()` only invokes this method when the `<pre>` has no
12948
+ * `data-language` attribute, so class-based inference is the only source
12949
+ * this method needs to consult.
12950
+ *
12951
+ * @param {HTMLElement} preElement Source `<pre>` element.
12952
+ * @returns {string} Resolved language id or `plainText` fallback.
12953
+ */
12954
+ resolveLanguage(preElement) {
12955
+ const classLanguage = this.resolveLanguageFromClassName(preElement).trim();
12956
+ return classLanguage !== '' ? classLanguage : DEFAULT_CODE_LANGUAGE;
12957
+ }
12958
+ /**
12959
+ * Extracts a language id from class names like `language-js` or `lang-ts`.
12960
+ *
12961
+ * @param {HTMLElement} preElement Source `<pre>` element.
12962
+ * @returns {string} Extracted language id or empty string.
12963
+ */
12964
+ resolveLanguageFromClassName(preElement) {
12965
+ const className = preElement.getAttribute('class') || '';
12966
+ const match = LANGUAGE_CLASS_PATTERN.exec(className);
12967
+ return match ? match[1] : '';
12968
+ }
12969
+ /**
12970
+ * Removes Word-only `Mso*` class names and keeps any non-Word classes.
12971
+ *
12972
+ * @param {HTMLElement} preElement Source `<pre>` element.
12973
+ */
12974
+ stripWordClassArtifacts(preElement) {
12975
+ const className = preElement.getAttribute('class') || '';
12976
+ if (!className) {
12977
+ return;
12978
+ }
12979
+ const filteredClasses = className
12980
+ .split(/\s+/)
12981
+ .map((name) => name.trim())
12982
+ .filter((name) => name !== '' && !WORD_CLASS_NAME_PATTERN.test(name));
12983
+ if (filteredClasses.length === 0) {
12984
+ preElement.removeAttribute('class');
12985
+ return;
12986
+ }
12987
+ preElement.setAttribute('class', filteredClasses.join(' '));
12988
+ }
12989
+ }
12990
+
12991
+ /**
12992
+ * Default Word transformers. Sanitizer allowlist is aggregated from these
12993
+ * transformer contracts so adding a new transformer automatically extends the
12994
+ * allowlist surface.
12995
+ */
12996
+ const WORD_STRUCTURE_TRANSFORMERS = [
12997
+ new WordTableTransformer(),
12998
+ new WordListRoleTransformer(),
12999
+ new WordImageTransformer(),
13000
+ new WordCodeBlockTransformer(),
13001
+ new WordParagraphRoleTransformer(),
13002
+ ];
13003
+ /**
13004
+ * Aggregates the sanitizer allowlist from each transformer's declared contract
13005
+ * (tags, attributes, style prefixes), removing duplicates and normalizing case
13006
+ * so the strategy allowlist can never drift from the transformers that depend on
13007
+ * it.
13008
+ *
13009
+ * @param {WordStructureTransformer[]} transformers Registered structure transformers.
13010
+ * @returns {WordSanitizeConfig} Combined sanitizer configuration.
13011
+ */
13012
+ function buildWordSanitizeConfig(transformers) {
13013
+ const tags = new Set();
13014
+ const stylePrefixes = new Set();
13015
+ const attributesMap = new Map();
13016
+ transformers.forEach((transformer) => {
13017
+ transformer.getAllowedTags().forEach((tag) => {
13018
+ tags.add(tag.toUpperCase());
13019
+ });
13020
+ transformer.getAllowedStyles().forEach((prefix) => {
13021
+ stylePrefixes.add(prefix.toLowerCase());
13022
+ });
13023
+ transformer.getAllowedAttributes().forEach((attrs, tagName) => {
13024
+ const normalizedTagName = tagName === WORD_SANITIZE_ALL_TAGS_KEY ? tagName : tagName.toUpperCase();
13025
+ if (!attributesMap.has(normalizedTagName)) {
13026
+ attributesMap.set(normalizedTagName, new Set());
13027
+ }
13028
+ const attrSet = attributesMap.get(normalizedTagName);
13029
+ attrs.forEach((attr) => {
13030
+ attrSet.add(attr.toLowerCase());
13031
+ });
13032
+ });
13033
+ });
13034
+ const allowedAttributes = {};
13035
+ attributesMap.forEach((attrs, tagName) => {
13036
+ allowedAttributes[tagName] = Array.from(attrs);
13037
+ });
13038
+ return {
13039
+ allowedTags: Array.from(tags),
13040
+ allowedAttributes,
13041
+ allowedStylePrefixes: Array.from(stylePrefixes),
13042
+ };
13043
+ }
13044
+ /**
13045
+ * Default sanitizer allowlist aggregated from
13046
+ * {@link WORD_STRUCTURE_TRANSFORMERS}. Exported so tests and callers can still
13047
+ * provide stable overrides.
13048
+ */
13049
+ const WORD_SANITIZE_CONFIG = buildWordSanitizeConfig(WORD_STRUCTURE_TRANSFORMERS);
13050
+ /**
13051
+ * Attribute name that carries inline styles after {@link StylePreservator} has
13052
+ * renamed `style` to `data-style`. All sanitization runs against this name so
13053
+ * the styles survive the CSP-sensitive `DOMParser` boundary.
13054
+ */
13055
+ const PRESERVED_STYLE_ATTR = 'data-style';
13056
+ /**
13057
+ * Block tag that can represent an intentional blank line pasted from Word
13058
+ * (an "empty" paragraph whose only content is a non-breaking space). Headings
13059
+ * are excluded — an empty heading is treated as noise, not an intentional
13060
+ * blank line.
13061
+ */
13062
+ const BLANK_LINE_ELIGIBLE_TAGS = 'p';
13063
+ /**
13064
+ * Zero-width space used to keep an intentional blank line alive. Unlike a
13065
+ * non-breaking space, it is not stripped by `String.prototype.trim()`, so the
13066
+ * downstream empty-block removal keeps the paragraph while it still renders as
13067
+ * blank.
13068
+ */
13069
+ const ZERO_WIDTH_SPACE = '\u200B';
13070
+ /**
13071
+ * Style values the RTE cannot resolve, so any declaration whose value contains
13072
+ * one of them is dropped during sanitization. These ride on allowed properties
13073
+ * (`color`, `border`, `background`, …), so the prefix allowlist alone cannot
13074
+ * remove them. Add legacy Word keywords here to filter them everywhere.
13075
+ */
13076
+ // eslint-disable-next-line spellcheck/spell-checker
13077
+ const INVALID_STYLE_VALUES = ['windowtext'];
13078
+ /**
13079
+ * Pre processes raw Word/Office clipboard HTML into clean, RTE-friendly HTML.
13080
+ *
13081
+ * The pipeline mirrors the two-phase design of the source Word cleaner:
13082
+ * 1. Structure fixing — maps Word paragraph styles onto RTE text styles and
13083
+ * drops Word list marker artifacts.
13084
+ * 2. Dynamic allowlist sanitizing — recursively strips disallowed tags,
13085
+ * attributes and inline style declarations while keeping inner content.
13086
+ */
13087
+ class WordPasteProcessingStrategy extends AbstractPasteProcessingStrategy {
13088
+ /**
13089
+ * Downstream paste mode marker for Word-specific processing.
13090
+ *
13091
+ * @returns {RTEPasteMode} `word` so downstream handlers preserve Word annotations.
13092
+ */
13093
+ get type() {
13094
+ return RTEPasteMode.WORD;
13095
+ }
13096
+ /**
13097
+ * Detects whether raw clipboard HTML originated from Microsoft Word / Office.
13098
+ *
13099
+ * Used to auto-route a normal "rich text" paste through the Word cleaning
13100
+ * pipeline when the source is actually Word, so users get correct formatting
13101
+ * without having to explicitly pick the Word paste option.
13102
+ *
13103
+ * @param {string} html Raw `text/html` clipboard payload.
13104
+ * @returns {boolean} `true` when the HTML carries Word/Office signatures.
13105
+ */
13106
+ canHandle(html) {
13107
+ if (!html) {
13108
+ return false;
13109
+ }
13110
+ return WordPasteProcessingStrategy.WORD_SIGNATURE_PATTERNS.some((pattern) => pattern.test(html));
13111
+ }
13112
+ /**
13113
+ * Returns the priority of this strategy relative to others; higher values run first.
13114
+ *
13115
+ * @returns {number} The priority value.
13116
+ */
13117
+ get priority() {
13118
+ return PasteProcessingStrategyPriority.WORD;
13119
+ }
13120
+ /**
13121
+ * Whether this strategy extracts pasted images and produces local previews.
13122
+ *
13123
+ * @returns {boolean} Always `true`; Word paste swaps `file://` images to previews.
13124
+ */
13125
+ get supportsImageProcessing() {
13126
+ return true;
13127
+ }
13128
+ /**
13129
+ * Cleans raw Word clipboard HTML so it can flow through the normal RTE paste
13130
+ * pipeline.
13131
+ *
13132
+ * @param {string} html Raw `text/html` clipboard payload from Word.
13133
+ * @param {WordSanitizeConfig} [config] Optional allowlist override.
13134
+ * @returns {string} Sanitized HTML string.
13135
+ */
13136
+ process(html, config = WORD_SANITIZE_CONFIG) {
13137
+ if (!html) {
13138
+ return '';
13139
+ }
13140
+ const withoutComments = this.stripWordComments(html);
13141
+ // Preserve inline styles across the DOMParser boundary to avoid
13142
+ // style-src-attr CSP violations (styles become data-style attributes).
13143
+ const preservedHtml = StylePreservator.preserve(withoutComments).getProcessedHtml();
13144
+ const parsedDoc = new DOMParser().parseFromString(preservedHtml, 'text/html');
13145
+ const container = parsedDoc.body;
13146
+ this.fixWordStructure(container);
13147
+ // Sanitize each top-level child instead of the <body> itself so the body
13148
+ // container is never unwrapped away.
13149
+ Array.from(container.childNodes).forEach((child) => {
13150
+ this.sanitizeNode(child, config);
13151
+ });
13152
+ // Collapse the source line wraps Word inserts inside text so a single
13153
+ // logical line does not paste as multiple lines.
13154
+ this.collapseInsignificantWhitespace(container);
13155
+ // Drop the whitespace Word inserts directly between block elements so it
13156
+ // does not paste as empty lines.
13157
+ this.removeInterBlockWhitespace(container);
13158
+ // Keep intentional blank lines (Word empty paragraphs) from being dropped by
13159
+ // the downstream empty-block removal.
13160
+ this.preserveWordEmptyLines(container);
13161
+ return this.restoreStyleAttributeName(container.innerHTML);
13162
+ }
13163
+ /**
13164
+ * Removes Office XML comments and down-level conditional markup that would
13165
+ * otherwise confuse `DOMParser`.
13166
+ *
13167
+ * @param {string} html Raw HTML string.
13168
+ * @returns {string} HTML without Word comment blocks.
13169
+ */
13170
+ stripWordComments(html) {
13171
+ return html.replace(/<!--[\s\S]*?-->/g, '').replace(/<!\[[\s\S]*?\]>/g, '');
13172
+ }
13173
+ /**
13174
+ * First phase: repairs Word-specific structure so it aligns with RTE text
13175
+ * styles before the allowlist pass runs.
13176
+ *
13177
+ * @param {HTMLElement} root Parsed body element.
13178
+ */
13179
+ fixWordStructure(root) {
13180
+ WordPasteProcessingStrategy.STRUCTURE_TRANSFORMERS.forEach((transformer) => {
13181
+ transformer.apply(root);
13182
+ });
13183
+ }
13184
+ /**
13185
+ * Removes the whitespace-only text nodes Word emits directly between block
13186
+ * elements (the `\n\n` at the top level of the fragment). After the allowlist
13187
+ * pass, disallowed containers are already unwrapped, so any remaining
13188
+ * top-level text node that is pure whitespace is an inter-block artifact.
13189
+ * Whitespace inside inline/text elements is left untouched.
13190
+ *
13191
+ * @param {HTMLElement} root Parsed body element.
13192
+ */
13193
+ removeInterBlockWhitespace(root) {
13194
+ Array.from(root.childNodes).forEach((node) => {
13195
+ if (node.nodeType === Node.TEXT_NODE && node.textContent.trim() === '') {
13196
+ root.removeChild(node);
13197
+ }
13198
+ });
13199
+ }
13200
+ /**
13201
+ * Collapses insignificant ASCII whitespace inside text nodes the way a
13202
+ * browser would when rendering. Word wraps long runs of text across multiple
13203
+ * source lines, so a single logical line such as "Number list 1" arrives as
13204
+ * "Number\nlist 1"; without normalization the newline surfaces as a spurious
13205
+ * line break in the editor. Non-breaking spaces (`\u00A0`) are left untouched
13206
+ * so intentional Word spacing and blank lines survive.
13207
+ *
13208
+ * @param {Node} node Node whose text descendants are normalized in place.
13209
+ */
13210
+ collapseInsignificantWhitespace(node) {
13211
+ // Code blocks preserve their original whitespace, so skip the whole subtree.
13212
+ if (WordCodeBlockTransformer.isCodeBlock(node)) {
13213
+ return;
13214
+ }
13215
+ if (node.nodeType === Node.TEXT_NODE) {
13216
+ const original = node.textContent;
13217
+ const collapsed = original.replace(/[ \t\r\n\f]+/g, ' ');
13218
+ if (collapsed !== original) {
13219
+ node.textContent = collapsed;
13220
+ }
13221
+ return;
13222
+ }
13223
+ Array.from(node.childNodes).forEach((child) => {
13224
+ this.collapseInsignificantWhitespace(child);
13225
+ });
13226
+ }
13227
+ /**
13228
+ * Preserves intentional blank lines authored in Word (empty paragraphs whose
13229
+ * only content is a non-breaking space). The downstream paste pipeline drops
13230
+ * any block whose text content trims to empty, and `trim()` also removes a
13231
+ * non-breaking space; replacing the content with a zero-width space keeps the
13232
+ * blank line because it survives `trim()` while still rendering as empty.
13233
+ *
13234
+ * @param {HTMLElement} root Parsed body element.
13235
+ */
13236
+ preserveWordEmptyLines(root) {
13237
+ Array.from(root.querySelectorAll(BLANK_LINE_ELIGIBLE_TAGS)).forEach((block) => {
13238
+ // Word paragraphs that host an image also carry a trailing
13239
+ // `<o:p>&nbsp;</o:p>` whose non-breaking space would misidentify the
13240
+ // paragraph as an empty line and wipe the image out.
13241
+ if (block.querySelector('img')) {
13242
+ return;
13243
+ }
13244
+ const text = block.textContent;
13245
+ const hasRealText = text.replace(/[\s\u200B]+/g, '') !== '';
13246
+ // Only an "empty" block that carries a non-breaking space is treated as
13247
+ // an intentional Word blank line.
13248
+ if (!hasRealText && /\u00A0/.test(text)) {
13249
+ block.textContent = ZERO_WIDTH_SPACE;
13250
+ }
13251
+ });
13252
+ }
13253
+ /**
13254
+ * Second phase: recursively enforces the dynamic allowlist on a node tree.
13255
+ *
13256
+ * @param {Node} node Node to sanitize in place.
13257
+ * @param {WordSanitizeConfig} config Active allowlist configuration.
13258
+ */
13259
+ sanitizeNode(node, config) {
13260
+ if (node.nodeType === Node.TEXT_NODE) {
13261
+ return;
13262
+ }
13263
+ if (node.nodeType !== Node.ELEMENT_NODE) {
13264
+ this.removeSelf(node);
13265
+ return;
13266
+ }
13267
+ const element = node;
13268
+ const tagName = element.tagName.toUpperCase();
13269
+ // Sanitize children first (reverse order keeps indices stable while nodes
13270
+ // may be removed or unwrapped).
13271
+ const children = Array.from(element.childNodes);
13272
+ for (let i = children.length - 1; i >= 0; i--) {
13273
+ this.sanitizeNode(children[i], config);
13274
+ }
13275
+ // Tag-level filter: unwrap disallowed elements but keep their content.
13276
+ if (!config.allowedTags.includes(tagName)) {
13277
+ while (element.firstChild) {
13278
+ if (element.parentNode && typeof element.parentNode.insertBefore === 'function') {
13279
+ element.parentNode.insertBefore(element.firstChild, element);
13280
+ }
13281
+ }
13282
+ this.removeSelf(element);
13283
+ return;
13284
+ }
13285
+ this.sanitizeAttributes(element, tagName, config);
13286
+ }
13287
+ /**
13288
+ * Removes disallowed attributes and filters style declarations.
13289
+ *
13290
+ * @param {Element} element Element being sanitized.
13291
+ * @param {string} tagName Upper-case tag name.
13292
+ * @param {WordSanitizeConfig} config Active sanitize configuration.
13293
+ */
13294
+ sanitizeAttributes(element, tagName, config) {
13295
+ const commonAttrs = config.allowedAttributes[WORD_SANITIZE_ALL_TAGS_KEY] || [];
13296
+ const tagAttrs = config.allowedAttributes[tagName] || [];
13297
+ const allowedAttrs = new Set([...commonAttrs, ...tagAttrs]);
13298
+ Array.from(element.attributes).forEach((attr) => {
13299
+ const attrName = attr.name.toLowerCase();
13300
+ const isStyle = attrName === PRESERVED_STYLE_ATTR;
13301
+ const normalizedName = isStyle ? 'style' : attrName;
13302
+ if (!allowedAttrs.has(normalizedName)) {
13303
+ element.removeAttribute(attr.name);
13304
+ return;
13305
+ }
13306
+ if (isStyle) {
13307
+ this.sanitizeStyleAttribute(element, attr.name, config);
13308
+ }
13309
+ });
13310
+ }
13311
+ /**
13312
+ * Filters CSS declarations inside a preserved style attribute: keeps only
13313
+ * properties matching a prefix in {@link WordSanitizeConfig.allowedStylePrefixes};
13314
+ * all others (including `mso-*` Word artifacts) are stripped.
13315
+ *
13316
+ * @param {Element} element Element owning the style attribute.
13317
+ * @param {string} attrName Preserved style attribute name.
13318
+ * @param {WordSanitizeConfig} config Active sanitize configuration.
13319
+ */
13320
+ sanitizeStyleAttribute(element, attrName, config) {
13321
+ const rawStyle = element.getAttribute(attrName) || '';
13322
+ // Delegate CSS parsing to the browser engine via a temporary element so
13323
+ // that edge cases (values containing semicolons, multi-value shorthand,
13324
+ // etc.) are handled correctly without a hand-rolled parser.
13325
+ const tempEl = element.ownerDocument.createElement('span');
13326
+ tempEl.setAttribute('style', rawStyle);
13327
+ const parsedStyle = tempEl.style;
13328
+ const cleanDeclarations = [];
13329
+ for (let i = 0; i < parsedStyle.length; i++) {
13330
+ const key = parsedStyle[i];
13331
+ // Keep only properties whose name starts with an allowed prefix.
13332
+ const isAllowed = config.allowedStylePrefixes.some((prefix) => key === prefix || key.startsWith(`${prefix}-`));
13333
+ const value = parsedStyle.getPropertyValue(key);
13334
+ // Drop declarations carrying a value the RTE cannot resolve (e.g. Word's
13335
+ // legacy `windowText` system color), even on otherwise allowed properties.
13336
+ const lowerCaseValue = value.toLowerCase();
13337
+ const hasInvalidValue = INVALID_STYLE_VALUES.some((invalid) => lowerCaseValue.includes(invalid));
13338
+ if (isAllowed && !hasInvalidValue) {
13339
+ cleanDeclarations.push(`${key}: ${value}`);
13340
+ }
13341
+ }
13342
+ const cleanStyle = cleanDeclarations.join('; ');
13343
+ if (cleanStyle) {
13344
+ element.setAttribute(attrName, cleanStyle);
13345
+ }
13346
+ else {
13347
+ element.removeAttribute(attrName);
13348
+ }
13349
+ }
13350
+ /**
13351
+ * Converts preserved `data-style` attributes back to `style` in the final
13352
+ * HTML string so downstream paste handling receives standard markup.
13353
+ *
13354
+ * @param {string} html Serialized sanitized HTML.
13355
+ * @returns {string} HTML with `style` attributes restored.
13356
+ */
13357
+ restoreStyleAttributeName(html) {
13358
+ return html.replace(/\sdata-style=/g, ' style=');
13359
+ }
13360
+ /**
13361
+ * Removes the element from its parent node if it has one.
13362
+ *
13363
+ * @param {Node | Element} elementToBeRemoved The element to be removed from the DOM.
13364
+ */
13365
+ removeSelf(elementToBeRemoved) {
13366
+ if (elementToBeRemoved.parentNode &&
13367
+ typeof elementToBeRemoved.parentNode.removeChild === 'function') {
13368
+ elementToBeRemoved.parentNode.removeChild(elementToBeRemoved);
13369
+ }
13370
+ }
13371
+ }
13372
+ /**
13373
+ * Ordered list of structure transformers applied in Phase 1 before allowlist
13374
+ * sanitization. To add support for a new node type (table, image, list…),
13375
+ * create a class that implements {@link WordStructureTransformer} and append
13376
+ * it here — no other changes to the pipeline are needed.
13377
+ */
13378
+ WordPasteProcessingStrategy.STRUCTURE_TRANSFORMERS = [
13379
+ ...WORD_STRUCTURE_TRANSFORMERS,
13380
+ ];
13381
+ /**
13382
+ * Signatures that identify clipboard HTML produced by Microsoft Word / Office.
13383
+ * Any single match is enough to treat the payload as Word content because
13384
+ * these markers do not appear in ordinary web or plain rich-text clipboards.
13385
+ */
13386
+ WordPasteProcessingStrategy.WORD_SIGNATURE_PATTERNS = [
13387
+ // <meta name=Generator content="Microsoft Word ...">
13388
+ /content=["']?Microsoft\s+Word/i,
13389
+ // eslint-disable-next-line spellcheck/spell-checker
13390
+ // Office namespace declarations (urn:schemas-microsoft-com:office:word).
13391
+ /urn:schemas-microsoft-com:office/i,
13392
+ // Word paragraph/character style classes (MsoNormal, MsoTitle, MsoListParagraph…).
13393
+ /class=["']?Mso[A-Za-z]/i,
13394
+ // Word-only inline style properties.
13395
+ /mso-[a-z-]+\s*:/i,
13396
+ // Office XML paragraph marker elements (<o:p></o:p>).
13397
+ /<\/?o:p>/i,
13398
+ ];
13399
+
13400
+ /**
13401
+ * Centralized selector for paste processing strategies.
13402
+ *
13403
+ * Maintains a registry of available strategies and selects the highest-priority
13404
+ * strategy that can handle the given clipboard HTML. Provides an extension
13405
+ * point for adding support for new clipboard sources (e.g., Google Docs, Notion)
13406
+ * without modifying the paste extension core logic.
13407
+ */
13408
+ class PasteStrategySelector {
13409
+ constructor() {
13410
+ this.defaultStrategy = new DefaultPasteProcessingStrategy();
13411
+ this.strategies = [
13412
+ new WordPasteProcessingStrategy(),
13413
+ this.defaultStrategy, // Fallback
13414
+ ];
13415
+ }
13416
+ /**
13417
+ * Select the appropriate strategy for the given HTML content.
13418
+ * Returns the highest-priority strategy that can handle the content.
13419
+ *
13420
+ * @param {string} html Raw clipboard HTML.
13421
+ * @returns {AbstractPasteProcessingStrategy} The selected strategy (always returns a strategy; default is the fallback).
13422
+ */
13423
+ selectStrategy(html) {
13424
+ return this.selectHighestPriorityStrategy(this.strategies.filter((strategy) => strategy.canHandle(html)));
13425
+ }
13426
+ /**
13427
+ * Selects the highest-priority registered strategy for an explicitly chosen paste mode.
13428
+ *
13429
+ * Used when the user manually chooses a non-default mode from the paste chooser.
13430
+ *
13431
+ * @param {RTEPasteMode} type Explicit paste mode selected by the user.
13432
+ * @returns {AbstractPasteProcessingStrategy} The matching strategy or the default fallback.
13433
+ */
13434
+ selectStrategyByType(type) {
13435
+ return this.selectHighestPriorityStrategy(this.strategies.filter((strategy) => strategy.type === type));
13436
+ }
13437
+ /**
13438
+ * Register a new paste processing strategy.
13439
+ * Useful for future extensions (e.g., GoogleDocsPasteStrategy).
13440
+ *
13441
+ * @param {AbstractPasteProcessingStrategy} strategy The strategy to register.
13442
+ */
13443
+ registerStrategy(strategy) {
13444
+ this.strategies.push(strategy);
13445
+ }
13446
+ /**
13447
+ * Returns the highest-priority strategy from a candidate set or the default fallback.
13448
+ *
13449
+ * @param {AbstractPasteProcessingStrategy[]} strategies Candidate strategies.
13450
+ * @returns {AbstractPasteProcessingStrategy} Selected strategy.
13451
+ */
13452
+ selectHighestPriorityStrategy(strategies) {
13453
+ const selectedStrategy = strategies.sort((a, b) => b.priority - a.priority)[0];
13454
+ return selectedStrategy || this.defaultStrategy;
13455
+ }
13456
+ }
13457
+
13458
+ /**
13459
+ * Extracts pasted image files from clipboard payloads and swaps matching
13460
+ * `<img>` elements to local object-URL previews.
13461
+ *
13462
+ * The parser is stateless: callers own the returned {@link PasteImagePreview}
13463
+ * list and decide how to track pending uploads.
13464
+ */
13465
+ class PasteImageParser {
13466
+ /**
13467
+ * Parses local `file://` images from the HTML, swaps matching `<img>`
13468
+ * elements to object-URL previews, and returns the rewritten HTML alongside
13469
+ * the resolved pending previews.
13470
+ *
13471
+ * When no local images are resolved, the original HTML is returned unchanged
13472
+ * with an empty preview list.
13473
+ *
13474
+ * @param {string} html HTML content to parse.
13475
+ * @param {ClipboardFileContent | null} clipboardFileContent Clipboard payload for image extraction.
13476
+ * @returns {ParseLocalImagesResult} Rewritten HTML and resolved previews.
13477
+ */
13478
+ parseLocalImages(html, clipboardFileContent) {
13479
+ if (!html.includes('<img')) {
13480
+ return { html, previews: [] };
13481
+ }
13482
+ const safeHtml = html.replace(/\s+style=/g, ' data-style=');
13483
+ const parser = new DOMParser();
13484
+ const parsedDoc = parser.parseFromString(safeHtml, 'text/html');
13485
+ const localImageElements = Array.from(parsedDoc.querySelectorAll('img')).filter((img) => img.src.startsWith('file://'));
13486
+ if (localImageElements.length === 0) {
13487
+ return { html, previews: [] };
13488
+ }
13489
+ const imageFiles = this.extractImageFiles(clipboardFileContent, localImageElements);
13490
+ if (imageFiles.length === 0) {
13491
+ return { html, previews: [] };
13492
+ }
13493
+ const previews = this.createImagePreviews(localImageElements, imageFiles);
13494
+ const rewrittenHtml = parsedDoc.body.innerHTML.replace(/ data-style=/g, ' style=');
13495
+ return { html: rewrittenHtml, previews };
13496
+ }
13497
+ /**
13498
+ * Swaps each `<img>` src to a local object-URL preview using the provided
13499
+ * image files (paired by order), returning one preview per resolved image.
13500
+ *
13501
+ * Images that live inside a list are dropped instead of being previewed: the
13502
+ * RTE does not support list images. They are removed here (after holding their
13503
+ * position while the RTF images are paired by order) so the remaining images
13504
+ * stay aligned with their files even when a list image is not the last one.
13505
+ *
13506
+ * @param {HTMLImageElement[]} images Placeholder `<img>` elements in document order.
13507
+ * @param {File[]} files Image files to pair with the elements, in the same order.
13508
+ * @returns {PasteImagePreview[]} Previews for the images that were resolved to a file.
13509
+ */
13510
+ createImagePreviews(images, files) {
13511
+ const previews = [];
13512
+ images.forEach((imageElement, index) => {
13513
+ // List images have no editor representation, so drop them here instead of
13514
+ // creating a preview. Removing them at this stage (rather than earlier)
13515
+ // keeps the remaining images aligned with their files.
13516
+ if (this.isListImage(imageElement)) {
13517
+ imageElement.remove();
13518
+ return;
13519
+ }
13520
+ const file = files[index];
13521
+ if (!file) {
13522
+ return;
13523
+ }
13524
+ const objectUrl = URL.createObjectURL(file);
13525
+ imageElement.setAttribute('src', objectUrl);
13526
+ const imageId = generateUUID();
13527
+ imageElement.setAttribute(PasteImageParser.PREVIEW_IMG_KEY, imageId);
13528
+ previews.push({ id: imageId, file, objectUrl });
13529
+ });
13530
+ return previews;
13531
+ }
13532
+ /**
13533
+ * Extracts image files from clipboard data, preferring Word RTF-decoded
13534
+ * images and falling back to the clipboard file list when RTF yields none.
13535
+ *
13536
+ * @param {ClipboardFileContent | null} clipboardFileContent Clipboard payload from a paste event.
13537
+ * @param {HTMLElement[]} images `<img>` elements the files will be paired with.
13538
+ * @returns {File[]} Image files found on the clipboard.
13539
+ */
13540
+ extractImageFiles(clipboardFileContent, images) {
13541
+ let result = [];
13542
+ if (clipboardFileContent) {
13543
+ if (clipboardFileContent.rtf) {
13544
+ result = this.safeExtractWordImages(clipboardFileContent.rtf, images);
13545
+ }
13546
+ if (result.length === 0 && clipboardFileContent.files) {
13547
+ result = clipboardFileContent.files.filter((file) => file.type.startsWith('image/'));
13548
+ }
13549
+ }
13550
+ return result;
13551
+ }
13552
+ /**
13553
+ * Safely extracts image files from Word RTF clipboard data.
13554
+ *
13555
+ * @param {string} rtf Clipboard payload from a paste event.
13556
+ * @param {HTMLElement[]} images Array of `<img>` elements that may be updated with staged previews.
13557
+ * @returns {File[]} Image files found in the clipboard data.
13558
+ */
13559
+ safeExtractWordImages(rtf, images) {
13560
+ // Word defines a list's picture bullet once in the list table
13561
+ // (`{\*\listpicture ...}`) with no rendered counterpart. Drop that
13562
+ // definition so its blip is not counted as a content image; the per-item
13563
+ // `{\listtext ...}` bullet blips are kept because each still pairs with a
13564
+ // preserved bullet placeholder `<img>`.
13565
+ const contentRtf = this.stripListPictureDefinitions(rtf);
13566
+ const fileObjects = [];
13567
+ const imageRegex = /\\pngblip|\\jpegblip/g;
13568
+ const matches = [...contentRtf.matchAll(imageRegex)];
13569
+ matches.forEach((match, index) => {
13570
+ if (index >= images.length || match.index === undefined) {
13571
+ return;
13572
+ }
13573
+ const mimeType = match[0].includes('png') ? 'image/png' : 'image/jpeg';
13574
+ const startIndex = match.index + match[0].length;
13575
+ const bytes = this.extractImageBytes(contentRtf, startIndex);
13576
+ if (bytes.length === 0) {
13577
+ return;
13578
+ }
13579
+ const extension = mimeType.split('/')[1];
13580
+ const file = new File(
13581
+ // eslint-disable-next-line spellcheck/spell-checker
13582
+ [new Uint8Array(bytes)], `word_img_${Date.now()}_${index}.${extension}`, { type: mimeType });
13583
+ fileObjects.push(file);
13584
+ });
13585
+ return fileObjects;
13586
+ }
13587
+ /**
13588
+ * Removes Word list-table picture-bullet definitions from the RTF so they are
13589
+ * not counted as content images.
13590
+ *
13591
+ * Word declares a list's picture bullet once as a `{\*\listpicture ...}`
13592
+ * destination inside the list table. It renders nothing on its own, so its
13593
+ * blip has no matching content `<img>`; leaving it in shifts the ordinal
13594
+ * pairing and makes the first real image resolve to the bullet. The per-item
13595
+ * `{\listtext ...}` bullets are intentionally left untouched because each is
13596
+ * kept as a placeholder `<img>` that consumes its blip downstream.
13597
+ *
13598
+ * @param {string} rtf Full RTF clipboard payload.
13599
+ * @returns {string} RTF with list-table picture-bullet definitions removed.
13600
+ */
13601
+ stripListPictureDefinitions(rtf) {
13602
+ // eslint-disable-next-line spellcheck/spell-checker
13603
+ return this.removeBalancedGroups(rtf, '{\\*\\listpicture');
13604
+ }
13605
+ /**
13606
+ * Removes every balanced-brace RTF group that starts with the given marker.
13607
+ *
13608
+ * @param {string} rtf RTF payload to scan.
13609
+ * @param {string} marker Opening delimiter of the group to remove (including its `{`).
13610
+ * @returns {string} RTF with the matching groups removed.
13611
+ */
13612
+ removeBalancedGroups(rtf, marker) {
13613
+ let index = rtf.indexOf(marker);
13614
+ while (index !== -1) {
13615
+ const end = this.findGroupEnd(rtf, index);
13616
+ rtf = rtf.slice(0, index) + rtf.slice(end);
13617
+ index = rtf.indexOf(marker, index);
13618
+ }
13619
+ return rtf;
13620
+ }
13621
+ /**
13622
+ * Finds the index just past the brace that closes the group opened at `start`.
13623
+ *
13624
+ * A backslash escapes the next character (such as `\{` or `\}`) so escaped
13625
+ * braces are not counted. When the group is unbalanced the RTF length is
13626
+ * returned so the trailing remainder is dropped.
13627
+ *
13628
+ * @param {string} rtf RTF payload to scan.
13629
+ * @param {number} start Index of the group's opening `{`.
13630
+ * @returns {number} Index immediately after the matching closing `}`.
13631
+ */
13632
+ findGroupEnd(rtf, start) {
13633
+ const length = rtf.length;
13634
+ let depth = 0;
13635
+ let position = start;
13636
+ while (position < length) {
13637
+ const char = rtf[position];
13638
+ if (char === '\\') {
13639
+ position += 2;
13640
+ continue;
13641
+ }
13642
+ if (char === '{') {
13643
+ depth++;
13644
+ }
13645
+ else if (char === '}') {
13646
+ depth--;
13647
+ if (depth === 0) {
13648
+ return position + 1;
13649
+ }
13650
+ }
13651
+ position++;
13652
+ }
13653
+ return length;
13654
+ }
13655
+ /**
13656
+ * Extracts the raw image bytes that follow a Word RTF blip marker.
13657
+ *
13658
+ * Starting just after the blip control word, RTF control words (such as
13659
+ * `\bliptag`) and nested groups (such as `{\*\blipuid ...}`) are skipped so
13660
+ * their hex is not mistaken for image data. Hex digits are decoded into bytes
13661
+ * until the enclosing `{\pict}` group is closed.
13662
+ *
13663
+ * @param {string} rtf Full RTF clipboard payload.
13664
+ * @param {number} startIndex Index immediately after the blip marker.
13665
+ * @returns {number[]} Decoded image byte values.
13666
+ */
13667
+ extractImageBytes(rtf, startIndex) {
13668
+ const length = rtf.length;
13669
+ const bytes = [];
13670
+ let depth = 0;
13671
+ let highNibble = -1;
13672
+ let position = startIndex;
13673
+ while (position < length) {
13674
+ const char = rtf[position];
13675
+ if (char === '{') {
13676
+ depth++;
13677
+ position++;
13678
+ continue;
13679
+ }
13680
+ if (char === '}') {
13681
+ if (depth === 0) {
13682
+ break;
13683
+ }
13684
+ depth--;
13685
+ position++;
13686
+ continue;
13687
+ }
13688
+ if (depth > 0) {
13689
+ position++;
13690
+ continue;
13691
+ }
13692
+ if (char === '\\') {
13693
+ position++;
13694
+ while (position < length && /[a-zA-Z]/.test(rtf[position])) {
13695
+ position++;
13696
+ }
13697
+ if (position < length && rtf[position] === '-') {
13698
+ position++;
13699
+ }
13700
+ while (position < length && /[0-9]/.test(rtf[position])) {
13701
+ position++;
13702
+ }
13703
+ continue;
13704
+ }
13705
+ const nibble = this.hexNibble(char);
13706
+ if (nibble >= 0) {
13707
+ if (highNibble < 0) {
13708
+ highNibble = nibble;
13709
+ }
13710
+ else {
13711
+ bytes.push((highNibble << 4) | nibble);
13712
+ highNibble = -1;
13713
+ }
13714
+ }
13715
+ position++;
13716
+ }
13717
+ return bytes;
13718
+ }
13719
+ /**
13720
+ * Converts a single hex character to its numeric value.
13721
+ *
13722
+ * @param {string} char Candidate hex character.
13723
+ * @returns {number} Value in `[0, 15]`, or `-1` when not a hex digit.
13724
+ */
13725
+ hexNibble(char) {
13726
+ if (char >= '0' && char <= '9') {
13727
+ return char.charCodeAt(0) - 48;
13728
+ }
13729
+ if (char >= 'a' && char <= 'f') {
13730
+ return char.charCodeAt(0) - 87;
13731
+ }
13732
+ if (char >= 'A' && char <= 'F') {
13733
+ return char.charCodeAt(0) - 55;
13734
+ }
13735
+ return -1;
13736
+ }
13737
+ /**
13738
+ * Returns whether an `<img>` element is nested inside list content.
13739
+ *
13740
+ * The Word paste sanitizer strips non-allowlisted attributes but keeps the
13741
+ * `ul`/`ol`/`li` structure, so list membership is detected by DOM ancestry
13742
+ * here rather than by a marker attribute set upstream.
13743
+ *
13744
+ * @param {HTMLImageElement} imageElement Image element to test.
13745
+ * @returns {boolean} Whether the image is part of list content.
13746
+ */
13747
+ isListImage(imageElement) {
13748
+ return Boolean(imageElement.closest('li,ul,ol'));
13749
+ }
13750
+ }
13751
+ PasteImageParser.PREVIEW_IMG_KEY = 'data-rte-id';
13752
+
13753
+ const REPLACE_IMAGE_SRC = 'REPLACE_IMAGE_SRC';
13754
+ /**
13755
+ * Action to replace the `src` attribute of an `<img>` element in the RTE content.
13756
+ */
13757
+ class ImageReplaceSrcAction extends ModifyContentAction {
13758
+ constructor(imageElement, url) {
13759
+ super();
13760
+ this.type = REPLACE_IMAGE_SRC;
13761
+ this.img = imageElement;
13762
+ this.url = url;
13763
+ }
13764
+ }
13765
+
13766
+ /**
13767
+ * Strategy to handle the `ImageReplaceSrcAction` for replacing the `src` attribute of an `<img>` element in the RTE content.
13768
+ */
13769
+ class ImageReplaceSrcStrategy extends ActionHandleStrategy {
13770
+ /**
13771
+ * @inheritDoc
13772
+ */
13773
+ handleAction(action, target) {
13774
+ const { img, url } = action;
13775
+ img.setAttribute('src', url);
13776
+ img.removeAttribute(PasteImageParser.PREVIEW_IMG_KEY);
13777
+ target.url = url;
13778
+ if (target.annotationMap && target.annotationMap.has('CUSTOM_ATTRIBUTE')) {
13779
+ const customAttributeAnnotation = target.annotationMap.get('CUSTOM_ATTRIBUTE');
13780
+ customAttributeAnnotation.customAttribute.src = url;
13781
+ delete customAttributeAnnotation.customAttribute[PasteImageParser.PREVIEW_IMG_KEY];
13782
+ }
13783
+ }
13784
+ }
13785
+
13786
+ /**
13787
+ * Owns the lifecycle of pasted images awaiting upload: it tracks their local
13788
+ * object-URL previews, notifies the consumer once they are inserted, applies the
13789
+ * uploaded URL back onto the live preview, and revokes object URLs on teardown.
13790
+ *
13791
+ * Keeping this state here rather than on the paste extension keeps the extension
13792
+ * focused on clipboard capture and the chooser UI.
13793
+ */
13794
+ class PendingImageRegistry {
13795
+ constructor() {
13796
+ /** Ids of pending images still holding an object URL owned by this registry. */
13797
+ this.ownedImageIds = new Set();
13798
+ /** Ids queued for the next {@link notifyInserted} call. */
13799
+ this.pendingNotifyImageIds = [];
13800
+ }
13801
+ /**
13802
+ * Registers freshly created previews so they can be notified and later
13803
+ * resolved to their uploaded URLs.
13804
+ *
13805
+ * @param {PasteImagePreview[]} previews Previews produced for the current paste.
13806
+ */
13807
+ register(previews) {
13808
+ this.pendingNotifyImageIds = [];
13809
+ previews.forEach((preview) => {
13810
+ this.pendingNotifyImageIds.push(preview.id);
13811
+ this.ownedImageIds.add(preview.id);
13812
+ PendingImageRegistry.pendingImages.set(preview.id, preview);
13813
+ });
13814
+ }
13815
+ /**
13816
+ * @returns {boolean} Whether previews are queued for notification.
13817
+ */
13818
+ hasPendingNotifications() {
13819
+ return this.pendingNotifyImageIds.length > 0;
13820
+ }
13821
+ /**
13822
+ * Notifies the consumer about newly inserted pasted images so they can upload
13823
+ * them and fill in the real URLs via the supplied `replaceUrl` callback.
13824
+ *
13825
+ * @param {ImageInsertedCallback | undefined} callback Consumer callback to invoke.
13826
+ * @param {GetEditableElement} getEditableElement Resolves the live editable element.
13827
+ * @param {ResolveImageNode} resolveImageNode Resolves the DTO node for a preview element.
13828
+ */
13829
+ notifyInserted(callback, getEditableElement, resolveImageNode) {
13830
+ const images = this.pendingNotifyImageIds
13831
+ .map((id) => PendingImageRegistry.pendingImages.get(id))
13832
+ .filter((preview) => !!preview);
13833
+ this.pendingNotifyImageIds = [];
13834
+ if (images.length && typeof callback === 'function') {
13835
+ // Mark as handed to the consumer so teardown keeps them for a later replaceUrl.
13836
+ images.forEach((image) => (image.notified = true));
13837
+ const pasteImages = images.map((image) => ({
13838
+ id: image.id,
13839
+ file: image.file,
13840
+ }));
13841
+ callback(pasteImages, (imageId, url) => this.replaceUrl(imageId, url, getEditableElement, resolveImageNode));
13842
+ }
13843
+ }
13844
+ /**
13845
+ * Revokes and forgets only previews that were never handed to a consumer for
13846
+ * upload. Previews already notified via {@link notifyInserted} are left intact
13847
+ * so an async {@link replaceUrl} can still resolve them after the extension is
13848
+ * recreated; that callback owns their teardown.
13849
+ */
13850
+ discardUnsentPreviews() {
13851
+ this.ownedImageIds.forEach((imageId) => {
13852
+ const pending = PendingImageRegistry.pendingImages.get(imageId);
13853
+ if (pending && pending.notified) {
13854
+ return;
13855
+ }
13856
+ if (pending && pending.objectUrl.startsWith('blob:')) {
13857
+ URL.revokeObjectURL(pending.objectUrl);
13858
+ }
13859
+ PendingImageRegistry.pendingImages.delete(imageId);
13860
+ this.ownedImageIds.delete(imageId);
13861
+ });
13862
+ this.pendingNotifyImageIds = [];
13863
+ }
13864
+ /**
13865
+ * Applies the uploaded URL for a pending pasted image, replacing its local
13866
+ * preview `src` and revoking the object URL.
13867
+ *
13868
+ * @param {string} imageId Pending image id supplied to the consumer callback.
13869
+ * @param {string} url Uploaded image URL to apply.
13870
+ * @param {GetEditableElement} getEditableElement Resolves the live editable element.
13871
+ * @param {ResolveImageNode} resolveImageNode Resolves the DTO node for a preview element.
13872
+ */
13873
+ replaceUrl(imageId, url, getEditableElement, resolveImageNode) {
13874
+ var _a;
13875
+ const editableEl = getEditableElement();
13876
+ if (editableEl) {
13877
+ const imageElement = (_a = editableEl.querySelector(`img[data-rte-id="${imageId}"]`)) !== null && _a !== void 0 ? _a : null;
13878
+ if (imageElement) {
13879
+ const imageNode = resolveImageNode(imageElement);
13880
+ imageNode && imageNode.apply(new ImageReplaceSrcAction(imageElement, url));
13881
+ }
13882
+ }
13883
+ const pending = PendingImageRegistry.pendingImages.get(imageId);
13884
+ if (pending) {
13885
+ if (pending.objectUrl.startsWith('blob:')) {
13886
+ URL.revokeObjectURL(pending.objectUrl);
13887
+ }
13888
+ PendingImageRegistry.pendingImages.delete(imageId);
13889
+ this.ownedImageIds.delete(imageId);
13890
+ }
13891
+ }
13892
+ }
13893
+ /**
13894
+ * Pasted images awaiting upload, keyed by their {@link VegaRTEPasteImage.id}.
13895
+ *
13896
+ * Shared statically across instances so previews survive a paste-extension
13897
+ * re-instantiation: the consumer may resolve `replaceUrl` after the editor
13898
+ * has re-mounted and created a new extension/registry instance.
13899
+ */
13900
+ PendingImageRegistry.pendingImages = new Map();
13901
+
13902
+ /**
13903
+ * Vega Rich Text Editor paste extension.
13904
+ * Intercepts keyboard paste and allows users to choose paste mode.
13905
+ */
13906
+ class VegaRTEPasteExtension extends VegaRTEExtension {
13907
+ constructor(options = {}) {
13908
+ super();
13909
+ this.editableEl = null;
13910
+ this.contentHostEl = null;
13911
+ this.chooserUI = null;
13912
+ this.pendingPastePayload = null;
13913
+ this.listenerDocument = null;
13914
+ this.listenerWindow = null;
13915
+ this.options = {};
13916
+ this.strategySelector = new PasteStrategySelector();
13917
+ this.clipboardFileContent = null;
13918
+ this.imageParser = new PasteImageParser();
13919
+ /** Owns pending pasted-image previews awaiting upload and their URL replacement. */
13920
+ this.pendingImageRegistry = new PendingImageRegistry();
13921
+ /**
13922
+ * Handles a native paste event by capturing the clipboard payload and
13923
+ * rendering the paste-mode chooser.
13924
+ *
13925
+ * @param {ClipboardEvent} event Native clipboard paste event.
13926
+ */
13927
+ this.handlePasteEvent = (event) => {
13928
+ var _a, _b;
13929
+ const clipboardData = event.clipboardData;
13930
+ if (!clipboardData) {
13931
+ return;
13932
+ }
13933
+ // HTML is sanitized via DOMParser and ElementToDtoStrategyProcessor pipeline
13934
+ const html = clipboardData.getData('text/html') || '';
13935
+ const text = clipboardData.getData('text/plain') || '';
13936
+ // RTF must be read synchronously here: the paste event's DataTransfer is only
13937
+ // readable during event dispatch, so reading it later (after the chooser) returns ''.
13938
+ const rtf = clipboardData.getData('text/rtf') || '';
13939
+ if (!html && !text) {
13940
+ // Empty clipboard paste should not mutate editor content.
13941
+ event.preventDefault();
13942
+ event.stopPropagation();
13943
+ return;
13944
+ }
13945
+ event.preventDefault();
13946
+ event.stopPropagation();
13947
+ const range = this.cloneCurrentSelectionRange();
13948
+ const selectedNodes = ((_b = (_a = this.extensionContext) === null || _a === void 0 ? void 0 : _a.getSelectedNodes) === null || _b === void 0 ? void 0 : _b.call(_a)) || [];
13949
+ this.pendingPastePayload = { html, text, range, selectedNodes: [...selectedNodes] };
13950
+ this.clipboardFileContent = {
13951
+ files: clipboardData.files ? Array.from(clipboardData.files) : [],
13952
+ rtf,
13953
+ };
13954
+ this.renderPasteChooser(event);
13955
+ };
13956
+ /**
13957
+ * Dismisses the chooser when a pointer interaction occurs outside of it.
13958
+ *
13959
+ * @param {Event} event Pointer event captured on the document.
13960
+ */
13961
+ this.handleOutsidePointerDown = (event) => {
13962
+ if (!this.chooserUI) {
13963
+ return;
13964
+ }
13965
+ const eventPath = typeof event.composedPath === 'function' ? event.composedPath() : [];
13966
+ if (this.chooserUI.includesEventPath(eventPath)) {
13967
+ return;
13968
+ }
13969
+ this.clearPasteChooser();
13970
+ };
13971
+ /**
13972
+ * Dismisses the chooser when the Escape key is pressed.
13973
+ *
13974
+ * @param {KeyboardEvent} event Keyboard event captured on the document.
13975
+ */
13976
+ this.handleOutsideKeyDown = (event) => {
13977
+ if (event.key === 'Escape') {
13978
+ this.clearPasteChooser();
13979
+ }
13980
+ };
13981
+ /**
13982
+ * Dismisses the chooser when any relevant scroll container scrolls.
13983
+ */
13984
+ this.handleOutsideScroll = () => {
13985
+ this.clearPasteChooser();
13986
+ };
13987
+ this.options = options;
13988
+ }
13989
+ /** @inheritDoc */
13990
+ initialExtensionAfterLoad(context) {
13991
+ super.initialExtensionAfterLoad(context);
13992
+ this.hostEl = context.host;
13993
+ this.attachPasteListener();
13994
+ }
13995
+ /** @inheritDoc */
13996
+ destroyExtension() {
13997
+ this.detachPasteListener();
13998
+ this.clearPasteChooser();
13999
+ this.pendingImageRegistry.discardUnsentPreviews();
14000
+ }
14001
+ /**
14002
+ * Attaches the paste listener to the editable element.
14003
+ */
14004
+ attachPasteListener() {
14005
+ const { editableEl, contentHostEl, } = this.getEditorElements();
14006
+ this.editableEl = editableEl;
14007
+ this.contentHostEl = contentHostEl;
14008
+ if (this.editableEl) {
14009
+ this.editableEl.addEventListener('paste', this.handlePasteEvent);
14010
+ }
14011
+ }
14012
+ /**
14013
+ * Detaches the paste listener from the editable element.
14014
+ */
14015
+ detachPasteListener() {
14016
+ if (this.editableEl) {
14017
+ this.editableEl.removeEventListener('paste', this.handlePasteEvent);
14018
+ }
14019
+ this.editableEl = null;
14020
+ this.contentHostEl = null;
14021
+ }
14022
+ /**
14023
+ * Resolves the content host and editable element from the host shadow tree.
14024
+ *
14025
+ * @returns {EditorElements} Editor elements.
14026
+ */
14027
+ getEditorElements() {
14028
+ var _a, _b, _c, _d, _e;
14029
+ const contentHostEl = (_c = (_b = (_a = this.hostEl) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('vega-rich-text-content')) !== null && _c !== void 0 ? _c : null;
14030
+ const editableEl = (_e = (_d = contentHostEl === null || contentHostEl === void 0 ? void 0 : contentHostEl.shadowRoot) === null || _d === void 0 ? void 0 : _d.querySelector('.rich-text-content')) !== null && _e !== void 0 ? _e : null;
14031
+ return { editableEl, contentHostEl };
14032
+ }
14033
+ /**
14034
+ * Resolves the editable content element from the host shadow tree.
14035
+ *
14036
+ * @returns {HTMLDivElement | null} Editable element or `null` when unavailable.
14037
+ */
14038
+ getEditableElement() {
14039
+ const { editableEl } = this.getEditorElements();
14040
+ return editableEl;
14041
+ }
14042
+ /**
14043
+ * Clones the current selection range so it can be restored after the user
14044
+ * chooses a paste mode.
14045
+ *
14046
+ * @returns {Range | null} Cloned range or `null` when there is no selection.
14047
+ */
14048
+ cloneCurrentSelectionRange() {
14049
+ var _a;
14050
+ const selection = (_a = this.extensionContext) === null || _a === void 0 ? void 0 : _a.getSelection();
14051
+ if (selection && selection.rangeCount > 0) {
14052
+ return selection.getRangeAt(0).cloneRange();
14053
+ }
14054
+ return null;
14055
+ }
14056
+ /**
14057
+ * Renders the paste-mode chooser and wires up dismissal listeners.
11338
14058
  *
11339
14059
  * @param {ClipboardEvent} pasteEvent Originating paste event used for positioning.
11340
14060
  */
11341
14061
  renderPasteChooser(pasteEvent) {
11342
- var _a, _b;
14062
+ var _a, _b, _c;
11343
14063
  const hostRoot = (_b = (_a = this.hostEl) === null || _a === void 0 ? void 0 : _a.shadowRoot) !== null && _b !== void 0 ? _b : null;
11344
14064
  if (!hostRoot) {
11345
14065
  return;
@@ -11351,6 +14071,8 @@ class VegaRTEPasteExtension extends VegaRTEExtension {
11351
14071
  onModeSelect: (mode) => {
11352
14072
  this.applyPasteMode(mode);
11353
14073
  },
14074
+ }, {
14075
+ showWordOption: ((_c = this.options) === null || _c === void 0 ? void 0 : _c.enableWordPaste) === true,
11354
14076
  });
11355
14077
  this.chooserUI.open(position);
11356
14078
  this.listenerDocument = this.hostEl.ownerDocument;
@@ -11480,7 +14202,10 @@ class VegaRTEPasteExtension extends VegaRTEExtension {
11480
14202
  /**
11481
14203
  * Applies the chosen paste mode by dispatching a synthetic paste input event.
11482
14204
  *
11483
- * @param {PasteMode} mode Selected paste mode.
14205
+ * `rich` keeps auto-detection enabled; any other explicit mode forces the
14206
+ * corresponding registered strategy.
14207
+ *
14208
+ * @param {RTEPasteMode} mode Selected paste mode.
11484
14209
  */
11485
14210
  applyPasteMode(mode) {
11486
14211
  var _a;
@@ -11496,9 +14221,42 @@ class VegaRTEPasteExtension extends VegaRTEExtension {
11496
14221
  editableEl.focus();
11497
14222
  this.restoreSelectionRange(this.pendingPastePayload.range);
11498
14223
  this.restoreSelectionControllerState(this.pendingPastePayload);
11499
- const dataTransfer = this.createDataTransfer(this.pendingPastePayload.html, this.pendingPastePayload.text, mode);
14224
+ const strategy = mode === RTEPasteMode.RICH
14225
+ ? this.strategySelector.selectStrategy(this.pendingPastePayload.html)
14226
+ : this.strategySelector.selectStrategyByType(mode);
14227
+ let processedHtml = strategy.process(this.pendingPastePayload.html);
14228
+ // If the strategy supports image processing and there is clipboard file content, parse local images.
14229
+ if (strategy.supportsImageProcessing && this.clipboardFileContent) {
14230
+ processedHtml = this.parseLocalImages(processedHtml, this.clipboardFileContent);
14231
+ }
14232
+ this.clipboardFileContent = null;
14233
+ const dataTransfer = this.createDataTransfer(processedHtml, this.pendingPastePayload.text, strategy.type);
11500
14234
  this.dispatchBeforeInputPaste(editableEl, dataTransfer);
11501
14235
  this.clearPasteChooser();
14236
+ this.emitLocalImageInsertedEvent();
14237
+ }
14238
+ /**
14239
+ * Parses local images from the HTML and emits events for further processing.
14240
+ *
14241
+ * @param {string} html HTML content to parse.
14242
+ * @param {ClipboardFileContent} clipboardFileContent Clipboard file content for image extraction.
14243
+ * @returns {string} Processed HTML with local image references replaced.
14244
+ */
14245
+ parseLocalImages(html, clipboardFileContent) {
14246
+ const { html: result, previews } = this.imageParser.parseLocalImages(html, clipboardFileContent);
14247
+ if (previews.length > 0) {
14248
+ this.pendingImageRegistry.register(previews);
14249
+ }
14250
+ return result;
14251
+ }
14252
+ /**
14253
+ * Emits the `imageInsertedCallback` for any pending previews, allowing the
14254
+ * consumer to upload them and resolve their URLs.
14255
+ */
14256
+ emitLocalImageInsertedEvent() {
14257
+ if (this.pendingImageRegistry.hasPendingNotifications()) {
14258
+ this.pendingImageRegistry.notifyInserted(this.options.imageInsertedCallback, () => { var _a; return (_a = this.editableEl) !== null && _a !== void 0 ? _a : this.getEditableElement(); }, (imageElement) => this.getDTOEntityByDom(imageElement));
14259
+ }
11502
14260
  }
11503
14261
  /**
11504
14262
  * Restores SelectionController state from the captured selection so synthetic
@@ -11572,7 +14330,7 @@ class VegaRTEPasteExtension extends VegaRTEExtension {
11572
14330
  *
11573
14331
  * @param {string} html HTML clipboard content.
11574
14332
  * @param {string} text Plain text clipboard content.
11575
- * @param {PasteMode} [mode] Selected paste mode marker.
14333
+ * @param {RTEPasteMode} [mode] Selected paste mode marker.
11576
14334
  * @returns {DataTransfer} Populated data transfer payload.
11577
14335
  */
11578
14336
  createDataTransfer(html, text, mode) {
@@ -11633,6 +14391,9 @@ class VegaRTEPasteExtension extends VegaRTEExtension {
11633
14391
  }
11634
14392
  }
11635
14393
  }
14394
+ (() => {
14395
+ VegaRTEExtension.registerActionHandleStrategy(RTEImageNode.name, REPLACE_IMAGE_SRC, new ImageReplaceSrcStrategy());
14396
+ })();
11636
14397
 
11637
14398
  /**
11638
14399
  * Action to extract the currently selected content (HTML and plain text) from the editor.
@@ -12087,7 +14848,7 @@ class SpanToTokenNodeStrategy extends ElementToDTOStrategy {
12087
14848
  /**
12088
14849
  * @inheritDoc
12089
14850
  */
12090
- handle(elementsArray) {
14851
+ handle(elementsArray, _options, parentTextAnnotations) {
12091
14852
  const element = elementsArray[0];
12092
14853
  const tokenKey = element.getAttribute('token-key');
12093
14854
  const text = element.textContent;
@@ -12100,7 +14861,9 @@ class SpanToTokenNodeStrategy extends ElementToDTOStrategy {
12100
14861
  type: 'token',
12101
14862
  token: tokenKey,
12102
14863
  text,
12103
- annotations: Object.assign(Object.assign({}, restAnnotations), { customAttribute: this.createCustomAttrs(customAttribute) }),
14864
+ annotations: Object.assign(Object.assign(Object.assign({}, restAnnotations), ((parentTextAnnotations === null || parentTextAnnotations === void 0 ? void 0 : parentTextAnnotations.inlineHtml)
14865
+ ? { inlineHtml: parentTextAnnotations.inlineHtml }
14866
+ : {})), { customAttribute: this.createCustomAttrs(customAttribute) }),
12104
14867
  };
12105
14868
  }
12106
14869
  /**