@beyondwork/docx-react-component 1.0.27 → 1.0.29
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.
- package/dist/canonical-document-BLEbzL2J.d.cts +844 -0
- package/dist/canonical-document-BLEbzL2J.d.ts +844 -0
- package/dist/chunk-2FJS5GZM.js +763 -0
- package/dist/chunk-2FJS5GZM.js.map +1 -0
- package/{src/core/commands/section-layout-commands.ts → dist/chunk-2OQBZS3F.js} +106 -340
- package/dist/chunk-2OQBZS3F.js.map +1 -0
- package/dist/chunk-2S7W4KFO.js +127 -0
- package/dist/chunk-2S7W4KFO.js.map +1 -0
- package/dist/chunk-2TG72QSW.js +3874 -0
- package/dist/chunk-2TG72QSW.js.map +1 -0
- package/{src/core/commands/table-structure-commands.ts → dist/chunk-36QNIZBO.js} +126 -315
- package/dist/chunk-36QNIZBO.js.map +1 -0
- package/dist/chunk-4AQOYAW4.js +3069 -0
- package/dist/chunk-4AQOYAW4.js.map +1 -0
- package/dist/chunk-4D5EWJ3P.js +77 -0
- package/dist/chunk-4D5EWJ3P.js.map +1 -0
- package/dist/chunk-5FN54NDH.js +2257 -0
- package/dist/chunk-5FN54NDH.js.map +1 -0
- package/dist/chunk-BOYGQYRQ.js +7306 -0
- package/dist/chunk-BOYGQYRQ.js.map +1 -0
- package/dist/chunk-CN3XMECL.js +212 -0
- package/dist/chunk-CN3XMECL.js.map +1 -0
- package/dist/chunk-EBI3BX6U.js +164 -0
- package/dist/chunk-EBI3BX6U.js.map +1 -0
- package/dist/chunk-EILUG3VB.js +1275 -0
- package/dist/chunk-EILUG3VB.js.map +1 -0
- package/dist/chunk-FUDY333O.js +70 -0
- package/dist/chunk-FUDY333O.js.map +1 -0
- package/dist/chunk-GBVOWFIK.js +1237 -0
- package/dist/chunk-GBVOWFIK.js.map +1 -0
- package/dist/chunk-H4TQ3H3Y.js +262 -0
- package/dist/chunk-H4TQ3H3Y.js.map +1 -0
- package/{src/core/commands/style-commands.ts → dist/chunk-JGB3IXZO.js} +40 -113
- package/dist/chunk-JGB3IXZO.js.map +1 -0
- package/dist/chunk-KD2QRQPY.js +4342 -0
- package/dist/chunk-KD2QRQPY.js.map +1 -0
- package/dist/chunk-KLMXQVYK.js +369 -0
- package/dist/chunk-KLMXQVYK.js.map +1 -0
- package/dist/chunk-KZUG5KFQ.js +214 -0
- package/dist/chunk-KZUG5KFQ.js.map +1 -0
- package/{src/core/state/text-transaction.ts → dist/chunk-QDAQ4CJU.js} +79 -236
- package/dist/chunk-QDAQ4CJU.js.map +1 -0
- package/{src/legal/bookmarks.ts → dist/chunk-RMH72RZI.js} +44 -130
- package/dist/chunk-RMH72RZI.js.map +1 -0
- package/dist/chunk-SWKWQZXM.js +117 -0
- package/dist/chunk-SWKWQZXM.js.map +1 -0
- package/{src/core/commands/formatting-commands.ts → dist/chunk-TJBP2K4T.js} +196 -536
- package/dist/chunk-TJBP2K4T.js.map +1 -0
- package/dist/chunk-TLCEAQDQ.js +542 -0
- package/dist/chunk-TLCEAQDQ.js.map +1 -0
- package/{src/core/commands/text-commands.ts → dist/chunk-UZXBISGO.js} +86 -142
- package/dist/chunk-UZXBISGO.js.map +1 -0
- package/dist/chunk-WGBAKP3Q.js +3220 -0
- package/dist/chunk-WGBAKP3Q.js.map +1 -0
- package/dist/compare/index.cjs +5475 -0
- package/dist/compare/index.cjs.map +1 -0
- package/dist/compare/index.d.cts +114 -0
- package/dist/compare/index.d.ts +114 -0
- package/dist/compare/index.js +731 -0
- package/dist/compare/index.js.map +1 -0
- package/dist/core/commands/formatting-commands.cjs +828 -0
- package/dist/core/commands/formatting-commands.cjs.map +1 -0
- package/dist/core/commands/formatting-commands.d.cts +63 -0
- package/dist/core/commands/formatting-commands.d.ts +63 -0
- package/dist/core/commands/formatting-commands.js +37 -0
- package/dist/core/commands/formatting-commands.js.map +1 -0
- package/dist/core/commands/image-commands.cjs +2023 -0
- package/dist/core/commands/image-commands.cjs.map +1 -0
- package/dist/core/commands/image-commands.d.cts +58 -0
- package/dist/core/commands/image-commands.d.ts +58 -0
- package/dist/core/commands/image-commands.js +18 -0
- package/dist/core/commands/image-commands.js.map +1 -0
- package/dist/core/commands/section-layout-commands.cjs +477 -0
- package/dist/core/commands/section-layout-commands.cjs.map +1 -0
- package/dist/core/commands/section-layout-commands.d.cts +62 -0
- package/dist/core/commands/section-layout-commands.d.ts +62 -0
- package/dist/core/commands/section-layout-commands.js +21 -0
- package/dist/core/commands/section-layout-commands.js.map +1 -0
- package/dist/core/commands/style-commands.cjs +214 -0
- package/dist/core/commands/style-commands.cjs.map +1 -0
- package/dist/core/commands/style-commands.d.cts +13 -0
- package/dist/core/commands/style-commands.d.ts +13 -0
- package/dist/core/commands/style-commands.js +9 -0
- package/dist/core/commands/style-commands.js.map +1 -0
- package/dist/core/commands/table-structure-commands.cjs +1883 -0
- package/dist/core/commands/table-structure-commands.cjs.map +1 -0
- package/dist/core/commands/table-structure-commands.d.cts +59 -0
- package/dist/core/commands/table-structure-commands.d.ts +59 -0
- package/dist/core/commands/table-structure-commands.js +12 -0
- package/dist/core/commands/table-structure-commands.js.map +1 -0
- package/dist/core/commands/text-commands.cjs +2391 -0
- package/dist/core/commands/text-commands.cjs.map +1 -0
- package/dist/core/commands/text-commands.d.cts +24 -0
- package/dist/core/commands/text-commands.d.ts +24 -0
- package/dist/core/commands/text-commands.js +28 -0
- package/dist/core/commands/text-commands.js.map +1 -0
- package/dist/core/selection/mapping.cjs +200 -0
- package/dist/core/selection/mapping.cjs.map +1 -0
- package/dist/core/selection/mapping.d.cts +2 -0
- package/dist/core/selection/mapping.d.ts +2 -0
- package/dist/core/selection/mapping.js +31 -0
- package/dist/core/selection/mapping.js.map +1 -0
- package/dist/core/state/editor-state.cjs +2278 -0
- package/dist/core/state/editor-state.cjs.map +1 -0
- package/dist/core/state/editor-state.d.cts +2 -0
- package/dist/core/state/editor-state.d.ts +2 -0
- package/dist/core/state/editor-state.js +26 -0
- package/dist/core/state/editor-state.js.map +1 -0
- package/dist/index.cjs +38553 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +7856 -0
- package/dist/index.js.map +1 -0
- package/dist/io/docx-session.cjs +16236 -0
- package/dist/io/docx-session.cjs.map +1 -0
- package/dist/io/docx-session.d.cts +21 -0
- package/dist/io/docx-session.d.ts +21 -0
- package/dist/io/docx-session.js +18 -0
- package/dist/io/docx-session.js.map +1 -0
- package/dist/legal/index.cjs +3900 -0
- package/dist/legal/index.cjs.map +1 -0
- package/dist/legal/index.d.cts +86 -0
- package/dist/legal/index.d.ts +86 -0
- package/dist/legal/index.js +616 -0
- package/dist/legal/index.js.map +1 -0
- package/dist/public-types-7ZL_94cz.d.ts +1573 -0
- package/dist/public-types-CeMaDueh.d.cts +1573 -0
- package/dist/public-types.cjs +19 -0
- package/dist/public-types.cjs.map +1 -0
- package/dist/public-types.d.cts +2 -0
- package/dist/public-types.d.ts +2 -0
- package/dist/public-types.js +1 -0
- package/dist/public-types.js.map +1 -0
- package/dist/runtime/document-runtime.cjs +11140 -0
- package/dist/runtime/document-runtime.cjs.map +1 -0
- package/dist/runtime/document-runtime.d.cts +231 -0
- package/dist/runtime/document-runtime.d.ts +231 -0
- package/dist/runtime/document-runtime.js +21 -0
- package/dist/runtime/document-runtime.js.map +1 -0
- package/dist/structural-helpers-CilgOVhh.d.cts +10 -0
- package/dist/structural-helpers-q0Gd-eBN.d.ts +10 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs +313 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +1 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +67 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +67 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.js +23 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.js.map +1 -0
- package/dist/ui-tailwind/index.cjs +4833 -0
- package/dist/ui-tailwind/index.cjs.map +1 -0
- package/dist/ui-tailwind/index.d.cts +617 -0
- package/dist/ui-tailwind/index.d.ts +617 -0
- package/dist/ui-tailwind/index.js +575 -0
- package/dist/ui-tailwind/index.js.map +1 -0
- package/package.json +64 -54
- package/src/README.md +0 -85
- package/src/api/README.md +0 -26
- package/src/api/public-types.ts +0 -1418
- package/src/api/session-state.ts +0 -60
- package/src/compare/diff-engine.ts +0 -623
- package/src/compare/export-redlines.ts +0 -280
- package/src/compare/index.ts +0 -25
- package/src/compare/snapshot.ts +0 -97
- package/src/component-inventory.md +0 -99
- package/src/core/README.md +0 -10
- package/src/core/commands/README.md +0 -3
- package/src/core/commands/image-commands.ts +0 -373
- package/src/core/commands/index.ts +0 -1757
- package/src/core/commands/list-commands.ts +0 -565
- package/src/core/commands/paragraph-layout-commands.ts +0 -339
- package/src/core/commands/review-commands.ts +0 -108
- package/src/core/commands/structural-helpers.ts +0 -309
- package/src/core/schema/README.md +0 -3
- package/src/core/schema/text-schema.ts +0 -516
- package/src/core/search/search-text.ts +0 -357
- package/src/core/selection/README.md +0 -3
- package/src/core/selection/mapping.ts +0 -289
- package/src/core/selection/review-anchors.ts +0 -183
- package/src/core/state/README.md +0 -3
- package/src/core/state/editor-state.ts +0 -892
- package/src/formats/xlsx/io/parse-shared-strings.ts +0 -41
- package/src/formats/xlsx/io/parse-sheet.ts +0 -459
- package/src/formats/xlsx/io/parse-styles.ts +0 -59
- package/src/formats/xlsx/io/parse-workbook.ts +0 -75
- package/src/formats/xlsx/io/serialize-shared-strings.ts +0 -72
- package/src/formats/xlsx/io/serialize-sheet.ts +0 -333
- package/src/formats/xlsx/io/serialize-styles.ts +0 -98
- package/src/formats/xlsx/io/serialize-workbook.ts +0 -429
- package/src/formats/xlsx/io/xlsx-session.ts +0 -314
- package/src/formats/xlsx/model/cell.ts +0 -189
- package/src/formats/xlsx/model/sheet.ts +0 -326
- package/src/formats/xlsx/model/styles.ts +0 -118
- package/src/formats/xlsx/model/workbook.ts +0 -453
- package/src/formats/xlsx/runtime/cell-commands.ts +0 -567
- package/src/formats/xlsx/runtime/sheet-commands.ts +0 -206
- package/src/formats/xlsx/runtime/workbook-runtime.ts +0 -177
- package/src/formats/xlsx/runtime/workbook-transaction.ts +0 -822
- package/src/index.ts +0 -101
- package/src/io/README.md +0 -10
- package/src/io/docx-session.ts +0 -2882
- package/src/io/export/README.md +0 -3
- package/src/io/export/export-session.ts +0 -220
- package/src/io/export/minimal-docx.ts +0 -115
- package/src/io/export/reattach-preserved-parts.ts +0 -54
- package/src/io/export/serialize-comments.ts +0 -947
- package/src/io/export/serialize-footnotes.ts +0 -399
- package/src/io/export/serialize-headers-footers.ts +0 -372
- package/src/io/export/serialize-main-document.ts +0 -1376
- package/src/io/export/serialize-numbering.ts +0 -118
- package/src/io/export/serialize-revisions.ts +0 -389
- package/src/io/export/serialize-runtime-revisions.ts +0 -269
- package/src/io/export/serialize-tables.ts +0 -174
- package/src/io/export/split-review-boundaries.ts +0 -356
- package/src/io/normalize/README.md +0 -3
- package/src/io/normalize/normalize-text.ts +0 -639
- package/src/io/ooxml/README.md +0 -3
- package/src/io/ooxml/highlight-colors.ts +0 -39
- package/src/io/ooxml/numbering-sentinels.ts +0 -44
- package/src/io/ooxml/parse-comments.ts +0 -846
- package/src/io/ooxml/parse-complex-content.ts +0 -287
- package/src/io/ooxml/parse-fields.ts +0 -834
- package/src/io/ooxml/parse-footnotes.ts +0 -896
- package/src/io/ooxml/parse-headers-footers.ts +0 -1169
- package/src/io/ooxml/parse-inline-media.ts +0 -461
- package/src/io/ooxml/parse-main-document.ts +0 -2877
- package/src/io/ooxml/parse-numbering.ts +0 -432
- package/src/io/ooxml/parse-revisions.ts +0 -931
- package/src/io/ooxml/parse-settings.ts +0 -184
- package/src/io/ooxml/parse-shapes.ts +0 -296
- package/src/io/ooxml/parse-styles.ts +0 -463
- package/src/io/ooxml/parse-tables.ts +0 -618
- package/src/io/ooxml/parse-theme.ts +0 -346
- package/src/io/ooxml/part-manifest.ts +0 -136
- package/src/io/ooxml/revision-boundaries.ts +0 -351
- package/src/io/opc/README.md +0 -3
- package/src/io/opc/corrupt-package.ts +0 -166
- package/src/io/opc/docx-package.ts +0 -74
- package/src/io/opc/package-reader.ts +0 -325
- package/src/io/opc/package-writer.ts +0 -273
- package/src/io/source-package-provenance.ts +0 -241
- package/src/legal/cross-references.ts +0 -414
- package/src/legal/defined-terms.ts +0 -203
- package/src/legal/index.ts +0 -32
- package/src/legal/signature-blocks.ts +0 -259
- package/src/model/README.md +0 -3
- package/src/model/canonical-document.ts +0 -2632
- package/src/model/cds-1.0.0.ts +0 -212
- package/src/model/snapshot.ts +0 -649
- package/src/preservation/README.md +0 -3
- package/src/preservation/markup-compatibility.ts +0 -48
- package/src/preservation/opaque-fragment-store.ts +0 -89
- package/src/preservation/opaque-region.ts +0 -233
- package/src/preservation/package-preservation.ts +0 -113
- package/src/preservation/preserved-part-manifest.ts +0 -56
- package/src/preservation/relationship-retention.ts +0 -57
- package/src/preservation/store.ts +0 -185
- package/src/review/README.md +0 -16
- package/src/review/store/README.md +0 -3
- package/src/review/store/comment-anchors.ts +0 -70
- package/src/review/store/comment-remapping.ts +0 -154
- package/src/review/store/comment-store.ts +0 -331
- package/src/review/store/comment-thread.ts +0 -109
- package/src/review/store/revision-actions.ts +0 -394
- package/src/review/store/revision-store.ts +0 -312
- package/src/review/store/revision-types.ts +0 -171
- package/src/review/store/runtime-comment-store.ts +0 -43
- package/src/runtime/README.md +0 -3
- package/src/runtime/ai-action-policy.ts +0 -764
- package/src/runtime/collab-review-sync.ts +0 -254
- package/src/runtime/document-layout.ts +0 -332
- package/src/runtime/document-navigation.ts +0 -603
- package/src/runtime/document-runtime.ts +0 -3159
- package/src/runtime/document-search.ts +0 -145
- package/src/runtime/numbering-prefix.ts +0 -216
- package/src/runtime/page-layout-estimation.ts +0 -212
- package/src/runtime/read-only-diagnostics-runtime.ts +0 -241
- package/src/runtime/review-runtime.ts +0 -44
- package/src/runtime/revision-runtime.ts +0 -107
- package/src/runtime/session-capabilities.ts +0 -192
- package/src/runtime/story-context.ts +0 -164
- package/src/runtime/story-targeting.ts +0 -162
- package/src/runtime/surface-projection.ts +0 -1357
- package/src/runtime/table-commands.ts +0 -173
- package/src/runtime/table-schema.ts +0 -309
- package/src/runtime/view-state.ts +0 -477
- package/src/runtime/virtualized-rendering.ts +0 -258
- package/src/runtime/workflow-markup.ts +0 -353
- package/src/ui/README.md +0 -30
- package/src/ui/WordReviewEditor.tsx +0 -4097
- package/src/ui/browser-export.ts +0 -52
- package/src/ui/comments/README.md +0 -3
- package/src/ui/compatibility/README.md +0 -3
- package/src/ui/editor-command-bag.ts +0 -120
- package/src/ui/editor-runtime-boundary.ts +0 -1457
- package/src/ui/editor-shell-view.tsx +0 -142
- package/src/ui/editor-surface/README.md +0 -3
- package/src/ui/editor-surface-controller.tsx +0 -63
- package/src/ui/headless/comment-decoration-model.ts +0 -124
- package/src/ui/headless/preserve-editor-selection.ts +0 -5
- package/src/ui/headless/revision-decoration-model.ts +0 -128
- package/src/ui/headless/selection-helpers.ts +0 -54
- package/src/ui/headless/selection-toolbar-model.ts +0 -34
- package/src/ui/headless/use-editor-keyboard.ts +0 -103
- package/src/ui/review/README.md +0 -3
- package/src/ui/runtime-snapshot-selectors.ts +0 -197
- package/src/ui/shared/revision-filters.ts +0 -31
- package/src/ui/status/README.md +0 -3
- package/src/ui/theme/README.md +0 -3
- package/src/ui/toolbar/README.md +0 -3
- package/src/ui/workflow-surface-blocked-rails.ts +0 -94
- package/src/ui-tailwind/chrome/tw-alert-banner.tsx +0 -64
- package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +0 -129
- package/src/ui-tailwind/chrome/tw-layout-panel.tsx +0 -114
- package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +0 -34
- package/src/ui-tailwind/chrome/tw-page-ruler.tsx +0 -386
- package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +0 -186
- package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +0 -139
- package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +0 -128
- package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +0 -58
- package/src/ui-tailwind/chrome/use-before-unload.ts +0 -20
- package/src/ui-tailwind/editor-surface/perf-probe.ts +0 -179
- package/src/ui-tailwind/editor-surface/pm-collab-plugins.ts +0 -40
- package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +0 -178
- package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +0 -31
- package/src/ui-tailwind/editor-surface/pm-decorations.ts +0 -427
- package/src/ui-tailwind/editor-surface/pm-position-map.ts +0 -123
- package/src/ui-tailwind/editor-surface/pm-schema.ts +0 -876
- package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +0 -504
- package/src/ui-tailwind/editor-surface/search-plugin.ts +0 -168
- package/src/ui-tailwind/editor-surface/surface-build-keys.ts +0 -61
- package/src/ui-tailwind/editor-surface/tw-caret.tsx +0 -12
- package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +0 -150
- package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +0 -129
- package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +0 -58
- package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +0 -151
- package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +0 -973
- package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +0 -111
- package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -436
- package/src/ui-tailwind/index.ts +0 -62
- package/src/ui-tailwind/page-chrome-model.ts +0 -27
- package/src/ui-tailwind/review/tw-comment-sidebar.tsx +0 -406
- package/src/ui-tailwind/review/tw-health-panel.tsx +0 -149
- package/src/ui-tailwind/review/tw-review-rail.tsx +0 -120
- package/src/ui-tailwind/review/tw-revision-sidebar.tsx +0 -164
- package/src/ui-tailwind/status/tw-status-bar.tsx +0 -61
- package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +0 -52
- package/src/ui-tailwind/toolbar/tw-toolbar.tsx +0 -1064
- package/src/ui-tailwind/tw-review-workspace.tsx +0 -1417
- package/src/validation/README.md +0 -3
- package/src/validation/compatibility-engine.ts +0 -634
- package/src/validation/compatibility-report.ts +0 -161
- package/src/validation/diagnostics.ts +0 -204
- package/src/validation/docx-comment-proof.ts +0 -707
- package/src/validation/import-diagnostics.ts +0 -128
- package/src/validation/low-priority-word-surfaces.ts +0 -373
- /package/{src → dist}/ui-tailwind/theme/editor-theme.css +0 -0
|
@@ -0,0 +1,828 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core/commands/formatting-commands.ts
|
|
21
|
+
var formatting_commands_exports = {};
|
|
22
|
+
__export(formatting_commands_exports, {
|
|
23
|
+
applyFormattingOperationToDocument: () => applyFormattingOperationToDocument,
|
|
24
|
+
getFormattingStateFromRenderSnapshot: () => getFormattingStateFromRenderSnapshot,
|
|
25
|
+
isMarkActive: () => isMarkActive,
|
|
26
|
+
makeSetAlignment: () => makeSetAlignment,
|
|
27
|
+
makeSetFontFamily: () => makeSetFontFamily,
|
|
28
|
+
makeSetFontSize: () => makeSetFontSize,
|
|
29
|
+
makeSetHighlight: () => makeSetHighlight,
|
|
30
|
+
makeSetTextColor: () => makeSetTextColor,
|
|
31
|
+
makeToggleAllCaps: () => makeToggleAllCaps,
|
|
32
|
+
makeToggleBold: () => makeToggleBold,
|
|
33
|
+
makeToggleItalic: () => makeToggleItalic,
|
|
34
|
+
makeToggleSmallCaps: () => makeToggleSmallCaps,
|
|
35
|
+
makeToggleStrikethrough: () => makeToggleStrikethrough,
|
|
36
|
+
makeToggleSubscript: () => makeToggleSubscript,
|
|
37
|
+
makeToggleSuperscript: () => makeToggleSuperscript,
|
|
38
|
+
makeToggleUnderline: () => makeToggleUnderline
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(formatting_commands_exports);
|
|
41
|
+
var import_prosemirror_commands = require("prosemirror-commands");
|
|
42
|
+
function makeToggleBold(schema) {
|
|
43
|
+
return (0, import_prosemirror_commands.toggleMark)(schema.marks.bold);
|
|
44
|
+
}
|
|
45
|
+
function makeToggleItalic(schema) {
|
|
46
|
+
return (0, import_prosemirror_commands.toggleMark)(schema.marks.italic);
|
|
47
|
+
}
|
|
48
|
+
function makeToggleUnderline(schema) {
|
|
49
|
+
return (0, import_prosemirror_commands.toggleMark)(schema.marks.underline);
|
|
50
|
+
}
|
|
51
|
+
function makeToggleStrikethrough(schema) {
|
|
52
|
+
return (0, import_prosemirror_commands.toggleMark)(schema.marks.strikethrough);
|
|
53
|
+
}
|
|
54
|
+
function makeToggleSuperscript(schema) {
|
|
55
|
+
return (0, import_prosemirror_commands.toggleMark)(schema.marks.superscript);
|
|
56
|
+
}
|
|
57
|
+
function makeToggleSubscript(schema) {
|
|
58
|
+
return (0, import_prosemirror_commands.toggleMark)(schema.marks.subscript);
|
|
59
|
+
}
|
|
60
|
+
function makeToggleSmallCaps(schema) {
|
|
61
|
+
return (0, import_prosemirror_commands.toggleMark)(schema.marks.small_caps);
|
|
62
|
+
}
|
|
63
|
+
function makeToggleAllCaps(schema) {
|
|
64
|
+
return (0, import_prosemirror_commands.toggleMark)(schema.marks.all_caps);
|
|
65
|
+
}
|
|
66
|
+
function makeSetValueMark(markType, attrKey, value) {
|
|
67
|
+
return (state, dispatch) => {
|
|
68
|
+
const { from, to, empty } = state.selection;
|
|
69
|
+
if (empty) return false;
|
|
70
|
+
if (!dispatch) return true;
|
|
71
|
+
const tr = state.tr;
|
|
72
|
+
if (value === null) {
|
|
73
|
+
tr.removeMark(from, to, markType);
|
|
74
|
+
} else {
|
|
75
|
+
const mark = markType.create({ [attrKey]: value });
|
|
76
|
+
tr.addMark(from, to, mark);
|
|
77
|
+
}
|
|
78
|
+
dispatch(tr);
|
|
79
|
+
return true;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function makeSetFontFamily(schema, family) {
|
|
83
|
+
return makeSetValueMark(schema.marks.font_family, "family", family);
|
|
84
|
+
}
|
|
85
|
+
function makeSetFontSize(schema, size) {
|
|
86
|
+
return makeSetValueMark(schema.marks.font_size, "size", size);
|
|
87
|
+
}
|
|
88
|
+
function makeSetTextColor(schema, color) {
|
|
89
|
+
return makeSetValueMark(schema.marks.text_color, "color", color);
|
|
90
|
+
}
|
|
91
|
+
function makeSetHighlight(schema, color) {
|
|
92
|
+
return makeSetValueMark(schema.marks.highlight, "color", color);
|
|
93
|
+
}
|
|
94
|
+
function makeSetAlignment(schema, alignment) {
|
|
95
|
+
return (state, dispatch) => {
|
|
96
|
+
const { from, to } = state.selection;
|
|
97
|
+
if (!dispatch) return true;
|
|
98
|
+
const tr = state.tr;
|
|
99
|
+
let applied = false;
|
|
100
|
+
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
101
|
+
if (node.type === schema.nodes.paragraph) {
|
|
102
|
+
tr.setNodeMarkup(pos, void 0, { ...node.attrs, alignment });
|
|
103
|
+
applied = true;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
if (!applied) return false;
|
|
107
|
+
dispatch(tr);
|
|
108
|
+
return true;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function isMarkActive(schema, markName, state) {
|
|
112
|
+
const markType = schema.marks[markName];
|
|
113
|
+
if (!markType) return false;
|
|
114
|
+
const { from, to, empty } = state.selection;
|
|
115
|
+
if (empty) {
|
|
116
|
+
return Boolean(markType.isInSet(state.storedMarks ?? state.selection.$from.marks()));
|
|
117
|
+
}
|
|
118
|
+
let active = true;
|
|
119
|
+
state.doc.nodesBetween(from, to, (node) => {
|
|
120
|
+
if (node.isText && !markType.isInSet(node.marks)) {
|
|
121
|
+
active = false;
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return active;
|
|
126
|
+
}
|
|
127
|
+
var DEFAULT_FORMATTING_STATE = {
|
|
128
|
+
bold: false,
|
|
129
|
+
italic: false,
|
|
130
|
+
underline: false,
|
|
131
|
+
strikethrough: false,
|
|
132
|
+
superscript: false,
|
|
133
|
+
subscript: false,
|
|
134
|
+
breadcrumb: []
|
|
135
|
+
};
|
|
136
|
+
var INDENT_STEP_TWIPS = 720;
|
|
137
|
+
function getFormattingStateFromRenderSnapshot(snapshot) {
|
|
138
|
+
const surface = snapshot.surface;
|
|
139
|
+
if (!surface) {
|
|
140
|
+
return { ...DEFAULT_FORMATTING_STATE };
|
|
141
|
+
}
|
|
142
|
+
const paragraphs = collectParagraphSurfaces(surface.blocks).filter(
|
|
143
|
+
(paragraph) => selectionTouchesRange(
|
|
144
|
+
snapshot.selection.anchor,
|
|
145
|
+
snapshot.selection.head,
|
|
146
|
+
paragraph.from,
|
|
147
|
+
paragraph.to
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
const textSegments = collectFormattingTextSegments(paragraphs, snapshot.selection);
|
|
151
|
+
return {
|
|
152
|
+
bold: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "bold")) : false,
|
|
153
|
+
italic: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "italic")) : false,
|
|
154
|
+
underline: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "underline")) : false,
|
|
155
|
+
strikethrough: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "strikethrough")) : false,
|
|
156
|
+
superscript: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "superscript")) : false,
|
|
157
|
+
subscript: textSegments.length > 0 ? textSegments.every((segment) => segmentHasMark(segment, "subscript")) : false,
|
|
158
|
+
fontFamily: getConsistentValue(textSegments, (segment) => segment.markAttrs?.fontFamily),
|
|
159
|
+
fontSize: getConsistentValue(textSegments, (segment) => {
|
|
160
|
+
const size = segment.markAttrs?.fontSize;
|
|
161
|
+
return typeof size === "number" ? size / 2 : void 0;
|
|
162
|
+
}),
|
|
163
|
+
textColor: getConsistentValue(
|
|
164
|
+
textSegments,
|
|
165
|
+
(segment) => toPublicColor(segment.markAttrs?.textColor)
|
|
166
|
+
),
|
|
167
|
+
highlightColor: getConsistentValue(
|
|
168
|
+
textSegments,
|
|
169
|
+
(segment) => toPublicColor(segment.markAttrs?.backgroundColor) ?? null,
|
|
170
|
+
{
|
|
171
|
+
emptyFallback: null
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
alignment: getConsistentValue(
|
|
175
|
+
paragraphs,
|
|
176
|
+
(paragraph) => toPublicAlignment(paragraph.alignment)
|
|
177
|
+
),
|
|
178
|
+
paragraphStyleId: getConsistentValue(paragraphs, (paragraph) => paragraph.styleId),
|
|
179
|
+
breadcrumb: getSelectionBreadcrumb(surface.blocks, snapshot.selection)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function getSelectionBreadcrumb(blocks, selection) {
|
|
183
|
+
const paths = collectSelectionBreadcrumbPaths(blocks, selection);
|
|
184
|
+
if (paths.length === 0) {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
let commonLength = paths[0]?.length ?? 0;
|
|
188
|
+
for (let pathIndex = 1; pathIndex < paths.length; pathIndex += 1) {
|
|
189
|
+
const currentPath = paths[pathIndex] ?? [];
|
|
190
|
+
commonLength = Math.min(commonLength, currentPath.length);
|
|
191
|
+
let compareIndex = 0;
|
|
192
|
+
while (compareIndex < commonLength && breadcrumbItemsEqual(paths[0][compareIndex], currentPath[compareIndex])) {
|
|
193
|
+
compareIndex += 1;
|
|
194
|
+
}
|
|
195
|
+
commonLength = compareIndex;
|
|
196
|
+
}
|
|
197
|
+
return paths[0].slice(0, commonLength);
|
|
198
|
+
}
|
|
199
|
+
function collectSelectionBreadcrumbPaths(blocks, selection, path = [], output = []) {
|
|
200
|
+
for (let blockIndex = 0; blockIndex < blocks.length; blockIndex += 1) {
|
|
201
|
+
const block = blocks[blockIndex];
|
|
202
|
+
if (!block) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (!selectionTouchesRange(
|
|
206
|
+
selection.anchor,
|
|
207
|
+
selection.head,
|
|
208
|
+
block.from,
|
|
209
|
+
block.to
|
|
210
|
+
)) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (block.kind === "paragraph") {
|
|
214
|
+
output.push([
|
|
215
|
+
...path,
|
|
216
|
+
{
|
|
217
|
+
kind: "paragraph",
|
|
218
|
+
label: block.styleId ? `Paragraph (${block.styleId})` : "Paragraph",
|
|
219
|
+
from: block.from,
|
|
220
|
+
to: block.to
|
|
221
|
+
}
|
|
222
|
+
]);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (block.kind === "opaque_block") {
|
|
226
|
+
output.push([
|
|
227
|
+
...path,
|
|
228
|
+
{
|
|
229
|
+
kind: "opaque_block",
|
|
230
|
+
label: block.label,
|
|
231
|
+
from: block.from,
|
|
232
|
+
to: block.to
|
|
233
|
+
}
|
|
234
|
+
]);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (block.kind === "sdt_block") {
|
|
238
|
+
collectSelectionBreadcrumbPaths(
|
|
239
|
+
block.children,
|
|
240
|
+
selection,
|
|
241
|
+
[
|
|
242
|
+
...path,
|
|
243
|
+
{
|
|
244
|
+
kind: "sdt_block",
|
|
245
|
+
label: block.alias ?? block.tag ?? block.sdtType ?? "Content control",
|
|
246
|
+
from: block.from,
|
|
247
|
+
to: block.to
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
output
|
|
251
|
+
);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (block.kind === "table") {
|
|
255
|
+
const tablePath = [
|
|
256
|
+
...path,
|
|
257
|
+
{
|
|
258
|
+
kind: "table",
|
|
259
|
+
label: block.styleId ? `Table (${block.styleId})` : "Table",
|
|
260
|
+
from: block.from,
|
|
261
|
+
to: block.to
|
|
262
|
+
}
|
|
263
|
+
];
|
|
264
|
+
for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
|
|
265
|
+
const row = block.rows[rowIndex];
|
|
266
|
+
if (!row) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const rowRange = getTableRowRange(block, row);
|
|
270
|
+
if (!selectionTouchesRange(
|
|
271
|
+
selection.anchor,
|
|
272
|
+
selection.head,
|
|
273
|
+
rowRange.from,
|
|
274
|
+
rowRange.to
|
|
275
|
+
)) {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const rowPath = [
|
|
279
|
+
...tablePath,
|
|
280
|
+
{
|
|
281
|
+
kind: "table_row",
|
|
282
|
+
label: `Row ${rowIndex + 1}`,
|
|
283
|
+
from: rowRange.from,
|
|
284
|
+
to: rowRange.to
|
|
285
|
+
}
|
|
286
|
+
];
|
|
287
|
+
for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
|
|
288
|
+
const cell = row.cells[cellIndex];
|
|
289
|
+
if (!cell) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const cellRange = getTableCellRange(block, cell);
|
|
293
|
+
if (!selectionTouchesRange(
|
|
294
|
+
selection.anchor,
|
|
295
|
+
selection.head,
|
|
296
|
+
cellRange.from,
|
|
297
|
+
cellRange.to
|
|
298
|
+
)) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
collectSelectionBreadcrumbPaths(
|
|
302
|
+
cell.content,
|
|
303
|
+
selection,
|
|
304
|
+
[
|
|
305
|
+
...rowPath,
|
|
306
|
+
{
|
|
307
|
+
kind: "table_cell",
|
|
308
|
+
label: `Cell ${cellIndex + 1}`,
|
|
309
|
+
from: cellRange.from,
|
|
310
|
+
to: cellRange.to
|
|
311
|
+
}
|
|
312
|
+
],
|
|
313
|
+
output
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return output;
|
|
320
|
+
}
|
|
321
|
+
function getTableRowRange(table, row) {
|
|
322
|
+
let from = Number.POSITIVE_INFINITY;
|
|
323
|
+
let to = Number.NEGATIVE_INFINITY;
|
|
324
|
+
for (const cell of row.cells) {
|
|
325
|
+
const range = getTableCellRange(table, cell);
|
|
326
|
+
from = Math.min(from, range.from);
|
|
327
|
+
to = Math.max(to, range.to);
|
|
328
|
+
}
|
|
329
|
+
return Number.isFinite(from) && Number.isFinite(to) ? { from, to } : { from: table.from, to: table.to };
|
|
330
|
+
}
|
|
331
|
+
function getTableCellRange(table, cell) {
|
|
332
|
+
if (cell.content.length === 0) {
|
|
333
|
+
return { from: table.from, to: table.to };
|
|
334
|
+
}
|
|
335
|
+
let from = Number.POSITIVE_INFINITY;
|
|
336
|
+
let to = Number.NEGATIVE_INFINITY;
|
|
337
|
+
for (const child of cell.content) {
|
|
338
|
+
from = Math.min(from, child.from);
|
|
339
|
+
to = Math.max(to, child.to);
|
|
340
|
+
}
|
|
341
|
+
return Number.isFinite(from) && Number.isFinite(to) ? { from, to } : { from: table.from, to: table.to };
|
|
342
|
+
}
|
|
343
|
+
function breadcrumbItemsEqual(left, right) {
|
|
344
|
+
return left.kind === right.kind && left.label === right.label && left.from === right.from && left.to === right.to;
|
|
345
|
+
}
|
|
346
|
+
function applyFormattingOperationToDocument(document, snapshot, operation) {
|
|
347
|
+
const surface = snapshot.surface;
|
|
348
|
+
if (!surface) {
|
|
349
|
+
return {
|
|
350
|
+
document,
|
|
351
|
+
selection: snapshot.selection,
|
|
352
|
+
changed: false
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
const nextDocument = structuredClone(document);
|
|
356
|
+
const root = nextDocument.content;
|
|
357
|
+
let changed = false;
|
|
358
|
+
const selectionFrom = Math.min(snapshot.selection.anchor, snapshot.selection.head);
|
|
359
|
+
const selectionTo = Math.max(snapshot.selection.anchor, snapshot.selection.head);
|
|
360
|
+
if (operation.type === "set-alignment" || operation.type === "indent" || operation.type === "outdent") {
|
|
361
|
+
visitParagraphBindings(root.children, surface.blocks, (paragraph, paragraphSurface) => {
|
|
362
|
+
if (!selectionTouchesRange(
|
|
363
|
+
snapshot.selection.anchor,
|
|
364
|
+
snapshot.selection.head,
|
|
365
|
+
paragraphSurface.from,
|
|
366
|
+
paragraphSurface.to
|
|
367
|
+
)) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const paragraphChanged = operation.type === "set-alignment" ? applyAlignment(paragraph, operation.alignment) : applyIndentation(paragraph, operation.type === "indent" ? 1 : -1);
|
|
371
|
+
changed = changed || paragraphChanged;
|
|
372
|
+
});
|
|
373
|
+
return {
|
|
374
|
+
document: changed ? nextDocument : document,
|
|
375
|
+
selection: snapshot.selection,
|
|
376
|
+
changed
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
if (selectionFrom === selectionTo) {
|
|
380
|
+
return {
|
|
381
|
+
document,
|
|
382
|
+
selection: snapshot.selection,
|
|
383
|
+
changed: false
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
const nextMarks = resolveMarkUpdater(snapshot, operation);
|
|
387
|
+
visitParagraphBindings(root.children, surface.blocks, (paragraph, paragraphSurface) => {
|
|
388
|
+
if (!rangesOverlap(
|
|
389
|
+
selectionFrom,
|
|
390
|
+
selectionTo,
|
|
391
|
+
paragraphSurface.from,
|
|
392
|
+
paragraphSurface.to
|
|
393
|
+
)) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
const transformed = transformInlineNodes(
|
|
397
|
+
paragraph.children,
|
|
398
|
+
paragraphSurface.from,
|
|
399
|
+
selectionFrom,
|
|
400
|
+
selectionTo,
|
|
401
|
+
nextMarks
|
|
402
|
+
);
|
|
403
|
+
if (!transformed.changed) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
paragraph.children = transformed.nodes;
|
|
407
|
+
changed = true;
|
|
408
|
+
});
|
|
409
|
+
return {
|
|
410
|
+
document: changed ? nextDocument : document,
|
|
411
|
+
selection: snapshot.selection,
|
|
412
|
+
changed
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function resolveMarkUpdater(snapshot, operation) {
|
|
416
|
+
const formatting = getFormattingStateFromRenderSnapshot(snapshot);
|
|
417
|
+
switch (operation.type) {
|
|
418
|
+
case "toggle":
|
|
419
|
+
return (marks) => toggleMarks(marks, operation.mark, !formatting[operation.mark]);
|
|
420
|
+
case "set-font-family":
|
|
421
|
+
return (marks) => setMarkValue(marks, "fontFamily", sanitizeFontFamily(operation.fontFamily));
|
|
422
|
+
case "set-font-size":
|
|
423
|
+
return (marks) => setMarkValue(marks, "fontSize", sanitizeFontSize(operation.size));
|
|
424
|
+
case "set-text-color":
|
|
425
|
+
return (marks) => setMarkValue(marks, "textColor", sanitizeColor(operation.color));
|
|
426
|
+
case "set-highlight-color":
|
|
427
|
+
return (marks) => setMarkValue(marks, "backgroundColor", sanitizeColor(operation.color));
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function applyAlignment(paragraph, alignment) {
|
|
431
|
+
const nextAlignment = alignment === "justify" ? "both" : alignment;
|
|
432
|
+
if (paragraph.alignment === nextAlignment) {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
paragraph.alignment = nextAlignment;
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
function applyIndentation(paragraph, delta) {
|
|
439
|
+
if (paragraph.numbering) {
|
|
440
|
+
const nextLevel = clamp(paragraph.numbering.level + delta, 0, 8);
|
|
441
|
+
if (nextLevel === paragraph.numbering.level) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
paragraph.numbering = {
|
|
445
|
+
...paragraph.numbering,
|
|
446
|
+
level: nextLevel
|
|
447
|
+
};
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
const currentLeft = paragraph.indentation?.left ?? 0;
|
|
451
|
+
const nextLeft = Math.max(0, currentLeft + delta * INDENT_STEP_TWIPS);
|
|
452
|
+
if (nextLeft === currentLeft) {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
const nextIndentation = {
|
|
456
|
+
...paragraph.indentation ?? {}
|
|
457
|
+
};
|
|
458
|
+
if (nextLeft > 0) {
|
|
459
|
+
nextIndentation.left = nextLeft;
|
|
460
|
+
paragraph.indentation = nextIndentation;
|
|
461
|
+
} else if (paragraph.indentation) {
|
|
462
|
+
delete nextIndentation.left;
|
|
463
|
+
paragraph.indentation = Object.keys(nextIndentation).length > 0 ? nextIndentation : void 0;
|
|
464
|
+
}
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
function collectParagraphSurfaces(blocks, output = []) {
|
|
468
|
+
for (const block of blocks) {
|
|
469
|
+
if (block.kind === "paragraph") {
|
|
470
|
+
output.push(block);
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (block.kind === "table") {
|
|
474
|
+
for (const row of block.rows) {
|
|
475
|
+
for (const cell of row.cells) {
|
|
476
|
+
collectParagraphSurfaces(cell.content, output);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
if (block.kind === "sdt_block") {
|
|
482
|
+
collectParagraphSurfaces(block.children, output);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return output;
|
|
486
|
+
}
|
|
487
|
+
function collectFormattingTextSegments(paragraphs, selection) {
|
|
488
|
+
const caret = selection.anchor;
|
|
489
|
+
const isCollapsed = selection.isCollapsed;
|
|
490
|
+
const selectionFrom = Math.min(selection.anchor, selection.head);
|
|
491
|
+
const selectionTo = Math.max(selection.anchor, selection.head);
|
|
492
|
+
const segments = [];
|
|
493
|
+
for (const paragraph of paragraphs) {
|
|
494
|
+
for (const segment of paragraph.segments) {
|
|
495
|
+
if (segment.kind !== "text") {
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (isCollapsed ? segmentContainsCaret(segment, caret) : rangesOverlap(selectionFrom, selectionTo, segment.from, segment.to)) {
|
|
499
|
+
segments.push(segment);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (!isCollapsed || segments.length > 0) {
|
|
504
|
+
return segments;
|
|
505
|
+
}
|
|
506
|
+
for (const paragraph of paragraphs) {
|
|
507
|
+
const fallback = paragraph.segments.find(
|
|
508
|
+
(segment) => segment.kind === "text" && segment.to === caret
|
|
509
|
+
);
|
|
510
|
+
if (fallback) {
|
|
511
|
+
return [fallback];
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return [];
|
|
515
|
+
}
|
|
516
|
+
function segmentContainsCaret(segment, caret) {
|
|
517
|
+
return segment.from <= caret && (caret < segment.to || segment.to === caret && segment.to > segment.from);
|
|
518
|
+
}
|
|
519
|
+
function segmentHasMark(segment, mark) {
|
|
520
|
+
const marks = segment.marks ?? [];
|
|
521
|
+
if (mark === "superscript") {
|
|
522
|
+
return marks.includes("superscript");
|
|
523
|
+
}
|
|
524
|
+
if (mark === "subscript") {
|
|
525
|
+
return marks.includes("subscript");
|
|
526
|
+
}
|
|
527
|
+
return marks.includes(mark);
|
|
528
|
+
}
|
|
529
|
+
function getConsistentValue(items, getter, options = {}) {
|
|
530
|
+
if (items.length === 0) {
|
|
531
|
+
return options.emptyFallback;
|
|
532
|
+
}
|
|
533
|
+
let value = void 0;
|
|
534
|
+
let initialized = false;
|
|
535
|
+
for (const item of items) {
|
|
536
|
+
const next = getter(item);
|
|
537
|
+
if (!initialized) {
|
|
538
|
+
value = next;
|
|
539
|
+
initialized = true;
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
if (next !== value) {
|
|
543
|
+
return void 0;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return value;
|
|
547
|
+
}
|
|
548
|
+
function visitParagraphBindings(blocks, surfaceBlocks, visitor) {
|
|
549
|
+
for (let index = 0; index < Math.min(blocks.length, surfaceBlocks.length); index += 1) {
|
|
550
|
+
const block = blocks[index];
|
|
551
|
+
const surface = surfaceBlocks[index];
|
|
552
|
+
if (!block || !surface) {
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
if (block.type === "paragraph" && surface.kind === "paragraph") {
|
|
556
|
+
visitor(block, surface);
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
if (block.type === "table" && surface.kind === "table") {
|
|
560
|
+
for (let rowIndex = 0; rowIndex < Math.min(block.rows.length, surface.rows.length); rowIndex += 1) {
|
|
561
|
+
const row = block.rows[rowIndex];
|
|
562
|
+
const surfaceRow = surface.rows[rowIndex];
|
|
563
|
+
if (!row || !surfaceRow) {
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
for (let cellIndex = 0; cellIndex < Math.min(row.cells.length, surfaceRow.cells.length); cellIndex += 1) {
|
|
567
|
+
const cell = row.cells[cellIndex];
|
|
568
|
+
const surfaceCell = surfaceRow.cells[cellIndex];
|
|
569
|
+
if (!cell || !surfaceCell) {
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
visitParagraphBindings(cell.children, surfaceCell.content, visitor);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (block.type === "sdt" && surface.kind === "sdt_block") {
|
|
578
|
+
visitParagraphBindings(block.children, surface.children, visitor);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function transformInlineNodes(nodes, start, selectionFrom, selectionTo, updateMarks) {
|
|
583
|
+
let changed = false;
|
|
584
|
+
let position = start;
|
|
585
|
+
const nextNodes = [];
|
|
586
|
+
for (const node of nodes) {
|
|
587
|
+
if (node.type === "text") {
|
|
588
|
+
const transformed = transformTextNode(
|
|
589
|
+
node,
|
|
590
|
+
position,
|
|
591
|
+
selectionFrom,
|
|
592
|
+
selectionTo,
|
|
593
|
+
updateMarks
|
|
594
|
+
);
|
|
595
|
+
nextNodes.push(...transformed.nodes);
|
|
596
|
+
position = transformed.nextPosition;
|
|
597
|
+
changed = changed || transformed.changed;
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
if (node.type === "hyperlink") {
|
|
601
|
+
const transformed = transformInlineNodes(
|
|
602
|
+
node.children,
|
|
603
|
+
position,
|
|
604
|
+
selectionFrom,
|
|
605
|
+
selectionTo,
|
|
606
|
+
updateMarks
|
|
607
|
+
);
|
|
608
|
+
nextNodes.push(
|
|
609
|
+
transformed.changed ? {
|
|
610
|
+
...node,
|
|
611
|
+
children: transformed.nodes
|
|
612
|
+
} : node
|
|
613
|
+
);
|
|
614
|
+
position = transformed.nextPosition;
|
|
615
|
+
changed = changed || transformed.changed;
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
nextNodes.push(node);
|
|
619
|
+
position += inlineNodeLength(node);
|
|
620
|
+
}
|
|
621
|
+
return {
|
|
622
|
+
nodes: nextNodes,
|
|
623
|
+
changed,
|
|
624
|
+
nextPosition: position
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
function transformTextNode(node, start, selectionFrom, selectionTo, updateMarks) {
|
|
628
|
+
const characters = Array.from(node.text);
|
|
629
|
+
const end = start + characters.length;
|
|
630
|
+
const overlapFrom = Math.max(selectionFrom, start);
|
|
631
|
+
const overlapTo = Math.min(selectionTo, end);
|
|
632
|
+
if (overlapFrom >= overlapTo) {
|
|
633
|
+
return {
|
|
634
|
+
nodes: [node],
|
|
635
|
+
changed: false,
|
|
636
|
+
nextPosition: end
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
const localFrom = overlapFrom - start;
|
|
640
|
+
const localTo = overlapTo - start;
|
|
641
|
+
const nextNodes = [];
|
|
642
|
+
if (localFrom > 0) {
|
|
643
|
+
nextNodes.push(createTextNode(characters.slice(0, localFrom).join(""), node.marks));
|
|
644
|
+
}
|
|
645
|
+
const transformedMarks = updateMarks(node.marks);
|
|
646
|
+
nextNodes.push(
|
|
647
|
+
createTextNode(characters.slice(localFrom, localTo).join(""), transformedMarks)
|
|
648
|
+
);
|
|
649
|
+
if (localTo < characters.length) {
|
|
650
|
+
nextNodes.push(createTextNode(characters.slice(localTo).join(""), node.marks));
|
|
651
|
+
}
|
|
652
|
+
return {
|
|
653
|
+
nodes: nextNodes.filter((candidate) => candidate.text.length > 0),
|
|
654
|
+
changed: !marksEqual(node.marks, transformedMarks) || localFrom > 0 || localTo < characters.length,
|
|
655
|
+
nextPosition: end
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
function createTextNode(text, marks) {
|
|
659
|
+
return {
|
|
660
|
+
type: "text",
|
|
661
|
+
text,
|
|
662
|
+
...marks && marks.length > 0 ? { marks: cloneMarks(marks) } : {}
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
function toggleMarks(marks, mark, enabled) {
|
|
666
|
+
const nextMarks = cloneMarks(marks);
|
|
667
|
+
if (mark === "superscript" || mark === "subscript") {
|
|
668
|
+
const filtered2 = nextMarks.filter((candidate) => candidate.type !== "position");
|
|
669
|
+
if (enabled) {
|
|
670
|
+
filtered2.push({
|
|
671
|
+
type: "position",
|
|
672
|
+
val: mark === "superscript" ? 1 : -1
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
return filtered2.length > 0 ? filtered2 : void 0;
|
|
676
|
+
}
|
|
677
|
+
const filtered = nextMarks.filter((candidate) => candidate.type !== mark);
|
|
678
|
+
if (enabled) {
|
|
679
|
+
filtered.push({ type: mark });
|
|
680
|
+
}
|
|
681
|
+
return filtered.length > 0 ? filtered : void 0;
|
|
682
|
+
}
|
|
683
|
+
function setMarkValue(marks, markType, value) {
|
|
684
|
+
const nextMarks = cloneMarks(marks).filter((candidate) => {
|
|
685
|
+
if (markType === "backgroundColor") {
|
|
686
|
+
return candidate.type !== "backgroundColor" && candidate.type !== "highlight";
|
|
687
|
+
}
|
|
688
|
+
return candidate.type !== markType;
|
|
689
|
+
});
|
|
690
|
+
if (value !== null) {
|
|
691
|
+
switch (markType) {
|
|
692
|
+
case "fontFamily":
|
|
693
|
+
nextMarks.push({ type: "fontFamily", val: value });
|
|
694
|
+
break;
|
|
695
|
+
case "fontSize":
|
|
696
|
+
nextMarks.push({ type: "fontSize", val: value });
|
|
697
|
+
break;
|
|
698
|
+
case "textColor":
|
|
699
|
+
nextMarks.push({ type: "textColor", color: value });
|
|
700
|
+
break;
|
|
701
|
+
case "backgroundColor":
|
|
702
|
+
nextMarks.push({ type: "backgroundColor", color: value });
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return nextMarks.length > 0 ? nextMarks : void 0;
|
|
707
|
+
}
|
|
708
|
+
function cloneMarks(marks) {
|
|
709
|
+
return marks ? marks.map((mark) => ({ ...mark })) : [];
|
|
710
|
+
}
|
|
711
|
+
function marksEqual(left, right) {
|
|
712
|
+
if (!left?.length && !right?.length) {
|
|
713
|
+
return true;
|
|
714
|
+
}
|
|
715
|
+
if (!left || !right || left.length !== right.length) {
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
return left.every((mark, index) => JSON.stringify(mark) === JSON.stringify(right[index]));
|
|
719
|
+
}
|
|
720
|
+
function inlineNodeLength(node) {
|
|
721
|
+
switch (node.type) {
|
|
722
|
+
case "text":
|
|
723
|
+
return Array.from(node.text).length;
|
|
724
|
+
case "hyperlink":
|
|
725
|
+
return node.children.reduce(
|
|
726
|
+
(total, child) => total + inlineNodeLength(child),
|
|
727
|
+
0
|
|
728
|
+
);
|
|
729
|
+
case "hard_break":
|
|
730
|
+
case "column_break":
|
|
731
|
+
case "tab":
|
|
732
|
+
case "symbol":
|
|
733
|
+
case "image":
|
|
734
|
+
case "opaque_inline":
|
|
735
|
+
case "footnote_ref":
|
|
736
|
+
case "chart_preview":
|
|
737
|
+
case "smartart_preview":
|
|
738
|
+
case "shape":
|
|
739
|
+
case "wordart":
|
|
740
|
+
case "vml_shape":
|
|
741
|
+
return 1;
|
|
742
|
+
case "field":
|
|
743
|
+
return node.children.reduce(
|
|
744
|
+
(total, child) => total + inlineNodeLength(child),
|
|
745
|
+
0
|
|
746
|
+
);
|
|
747
|
+
case "bookmark_start":
|
|
748
|
+
case "bookmark_end":
|
|
749
|
+
return 0;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
function toPublicAlignment(alignment) {
|
|
753
|
+
switch (alignment) {
|
|
754
|
+
case "both":
|
|
755
|
+
case "distribute":
|
|
756
|
+
return "justify";
|
|
757
|
+
case "left":
|
|
758
|
+
case "center":
|
|
759
|
+
case "right":
|
|
760
|
+
return alignment;
|
|
761
|
+
default:
|
|
762
|
+
return void 0;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function toPublicColor(color) {
|
|
766
|
+
if (!color) {
|
|
767
|
+
return void 0;
|
|
768
|
+
}
|
|
769
|
+
return /^[0-9A-F]{3,8}$/iu.test(color) ? `#${color.toUpperCase()}` : color;
|
|
770
|
+
}
|
|
771
|
+
function sanitizeFontFamily(fontFamily) {
|
|
772
|
+
const normalized = fontFamily?.trim();
|
|
773
|
+
return normalized ? normalized : null;
|
|
774
|
+
}
|
|
775
|
+
function sanitizeFontSize(size) {
|
|
776
|
+
if (typeof size !== "number" || !Number.isFinite(size) || size <= 0) {
|
|
777
|
+
return null;
|
|
778
|
+
}
|
|
779
|
+
return Math.round(size * 2);
|
|
780
|
+
}
|
|
781
|
+
function sanitizeColor(color) {
|
|
782
|
+
const normalized = color?.trim();
|
|
783
|
+
if (!normalized) {
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
786
|
+
const raw = normalized.startsWith("#") ? normalized.slice(1) : normalized;
|
|
787
|
+
return /^[0-9A-F]{3,8}$/iu.test(raw) ? raw.toUpperCase() : null;
|
|
788
|
+
}
|
|
789
|
+
function selectionTouchesRange(anchor, head, rangeFrom, rangeTo) {
|
|
790
|
+
const selectionFrom = Math.min(anchor, head);
|
|
791
|
+
const selectionTo = Math.max(anchor, head);
|
|
792
|
+
if (selectionFrom === selectionTo) {
|
|
793
|
+
return selectionFrom >= rangeFrom && selectionFrom <= rangeTo;
|
|
794
|
+
}
|
|
795
|
+
return rangesOverlap(selectionFrom, selectionTo, rangeFrom, rangeTo);
|
|
796
|
+
}
|
|
797
|
+
function rangesOverlap(leftFrom, leftTo, rightFrom, rightTo) {
|
|
798
|
+
if (leftFrom === leftTo) {
|
|
799
|
+
return leftFrom >= rightFrom && leftFrom <= rightTo;
|
|
800
|
+
}
|
|
801
|
+
if (rightFrom === rightTo) {
|
|
802
|
+
return rightFrom >= leftFrom && rightFrom <= leftTo;
|
|
803
|
+
}
|
|
804
|
+
return leftFrom < rightTo && leftTo > rightFrom;
|
|
805
|
+
}
|
|
806
|
+
function clamp(value, min, max) {
|
|
807
|
+
return Math.min(max, Math.max(min, value));
|
|
808
|
+
}
|
|
809
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
810
|
+
0 && (module.exports = {
|
|
811
|
+
applyFormattingOperationToDocument,
|
|
812
|
+
getFormattingStateFromRenderSnapshot,
|
|
813
|
+
isMarkActive,
|
|
814
|
+
makeSetAlignment,
|
|
815
|
+
makeSetFontFamily,
|
|
816
|
+
makeSetFontSize,
|
|
817
|
+
makeSetHighlight,
|
|
818
|
+
makeSetTextColor,
|
|
819
|
+
makeToggleAllCaps,
|
|
820
|
+
makeToggleBold,
|
|
821
|
+
makeToggleItalic,
|
|
822
|
+
makeToggleSmallCaps,
|
|
823
|
+
makeToggleStrikethrough,
|
|
824
|
+
makeToggleSubscript,
|
|
825
|
+
makeToggleSuperscript,
|
|
826
|
+
makeToggleUnderline
|
|
827
|
+
});
|
|
828
|
+
//# sourceMappingURL=formatting-commands.cjs.map
|