plitejs 54.0.0-beta.2 → 54.0.0-beta.3
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/{internal/view/annotation-store-metrics.js → annotation-store-metrics-Ccjkef45.js} +1 -1
- package/dist/annotations/index.d.ts +1 -1
- package/dist/annotations/index.js +1 -1
- package/dist/authored/index.d.ts +596 -9
- package/dist/authored/index.js +18557 -4
- package/dist/{core/authored-veto.js → authored-veto-DSnQcHGR.js} +2 -2
- package/dist/{internal/browser-protocol.js → browser-protocol-pvt4HFF7.js} +1 -1
- package/dist/comparison-plan-CEQL0ooW.js +1338 -0
- package/dist/{diff/lib/comparison-types.d.ts → comparison-types-Dt-unJZY.d.ts} +11 -6
- package/dist/create-editor-CkHtPWXV.js +1107 -0
- package/dist/diff/index.d.ts +31 -3
- package/dist/diff/index.js +1747 -1
- package/dist/dom/index.d.ts +2 -19
- package/dist/dom/index.js +2 -16
- package/dist/dom-Cgfscvnm.js +9220 -0
- package/dist/{core/same-result.js → editor-owner-IUmkTeXz.js} +77 -2
- package/dist/{core/editor-view-lifetime.js → editor-view-lifetime-GJKa_QGh.js} +1 -1
- package/dist/history/index.d.ts +169 -3
- package/dist/history/index.js +6717 -2
- package/dist/hyperscript/index.d.ts +1 -19
- package/dist/hyperscript/index.js +1 -8
- package/dist/{hyperscript/creators.js → hyperscript-FPuoArEi.js} +134 -8
- package/dist/index-BpQx2UG4.d.ts +1093 -0
- package/dist/{yjs/core/plugin.d.ts → index-Cw-oC2ps.d.ts} +88 -5
- package/dist/{annotations/store.d.ts → index-DPWyk3lG.d.ts} +21 -6
- package/dist/index-DpltOCot.d.ts +9753 -0
- package/dist/index-HPYawTae.d.ts +119 -0
- package/dist/index-K0Za9YXc.d.ts +1246 -0
- package/dist/index.d.ts +1 -50
- package/dist/index.js +4 -34
- package/dist/internal/index.d.ts +2 -54
- package/dist/internal/index.js +156 -52
- package/dist/{internal/view/mapped-view-store.js → mapped-view-store-ld-6uxEU.js} +2 -3
- package/dist/{core/native-grouping-input.js → native-grouping-input-DMNcsIaW.js} +2 -2
- package/dist/pagination/index.d.ts +1 -7
- package/dist/pagination/index.js +1 -693
- package/dist/pagination/react.d.ts +2 -4
- package/dist/pagination/react.js +436 -30
- package/dist/pagination-D_A8iPJP.js +1021 -0
- package/dist/plugin-DWzkJbnJ.js +50999 -0
- package/dist/{react/range-geometry.d.ts → range-geometry-BLAHRE11.d.ts} +2 -2
- package/dist/{react/range-geometry.js → range-geometry-BjeLHOnl.js} +23 -18
- package/dist/react/index.d.ts +5 -97
- package/dist/react/index.js +7 -72
- package/dist/react/virtualized.d.ts +2 -4
- package/dist/react/virtualized.js +146 -7
- package/dist/react-DZ15gmz2.js +1018 -0
- package/dist/{core/change/retraction.js → retraction-BMem8Rfk.js} +16 -4
- package/dist/src-cT1OTKP_.js +1386 -0
- package/dist/{internal/view/stable-id-mapped-source.js → store-Cz2mXyDe.js} +240 -3
- package/dist/testing/index.d.ts +182 -8
- package/dist/testing/index.js +95 -8
- package/dist/use-editor-dom-scope-BbMDSCpW.js +28354 -0
- package/dist/yjs/index.d.ts +1 -4
- package/dist/yjs/index.js +1 -2
- package/dist/yjs/react/index.d.ts +25 -5
- package/dist/yjs/react/index.js +84 -3
- package/dist/yjs-DOK-m7kl.js +13413 -0
- package/package.json +1 -1
- package/dist/annotations/store.js +0 -244
- package/dist/authored/authored.d.ts +0 -116
- package/dist/authored/authored.js +0 -1271
- package/dist/authored/changes.js +0 -365
- package/dist/authored/comparison.d.ts +0 -41
- package/dist/authored/comparison.js +0 -270
- package/dist/authored/decision-window.js +0 -42
- package/dist/authored/decision.js +0 -306
- package/dist/authored/facts/admission.js +0 -388
- package/dist/authored/facts/compact.d.ts +0 -2
- package/dist/authored/facts/compact.js +0 -91
- package/dist/authored/facts/dependencies.d.ts +0 -5
- package/dist/authored/facts/dependencies.js +0 -66
- package/dist/authored/facts/editing.js +0 -12
- package/dist/authored/facts/facts.d.ts +0 -8
- package/dist/authored/facts/facts.js +0 -535
- package/dist/authored/facts/records.d.ts +0 -28
- package/dist/authored/facts/records.js +0 -226
- package/dist/authored/facts/settle.js +0 -529
- package/dist/authored/format.d.ts +0 -34
- package/dist/authored/format.js +0 -175
- package/dist/authored/ledger/book.js +0 -809
- package/dist/authored/ledger/cards.js +0 -223
- package/dist/authored/ledger/ledger.js +0 -830
- package/dist/authored/ledger/level.js +0 -1081
- package/dist/authored/ledger/links.js +0 -20
- package/dist/authored/ledger/pairs.js +0 -334
- package/dist/authored/ledger/places.js +0 -524
- package/dist/authored/ledger/preview-lens.js +0 -252
- package/dist/authored/ledger/projection.js +0 -163
- package/dist/authored/ledger/roots.js +0 -11
- package/dist/authored/ledger/runs.js +0 -480
- package/dist/authored/ledger/slots.js +0 -330
- package/dist/authored/ledger/work.js +0 -66
- package/dist/authored/refusal.d.ts +0 -33
- package/dist/authored/refusal.js +0 -188
- package/dist/authored/resolve-schema.js +0 -62
- package/dist/authored/tree/alignment.js +0 -456
- package/dist/authored/tree/carried.js +0 -205
- package/dist/authored/tree/command-values.js +0 -344
- package/dist/authored/tree/cuts.js +0 -320
- package/dist/authored/tree/grid.js +0 -49
- package/dist/authored/tree/halves.js +0 -120
- package/dist/authored/tree/holders.js +0 -345
- package/dist/authored/tree/holds.js +0 -135
- package/dist/authored/tree/layers.d.ts +0 -49
- package/dist/authored/tree/layers.js +0 -354
- package/dist/authored/tree/marks.d.ts +0 -136
- package/dist/authored/tree/marks.js +0 -263
- package/dist/authored/tree/proposed.js +0 -212
- package/dist/authored/tree/readiness.js +0 -545
- package/dist/authored/tree/record-completion.js +0 -423
- package/dist/authored/tree/record.js +0 -2908
- package/dist/authored/tree/reserves.js +0 -449
- package/dist/authored/tree/resolve.d.ts +0 -9
- package/dist/authored/tree/resolve.js +0 -1860
- package/dist/authored/tree/shown.js +0 -153
- package/dist/authored/tree/spare-lines.js +0 -119
- package/dist/authored/tree/spares.js +0 -61
- package/dist/authored/types.d.ts +0 -177
- package/dist/core/anchor-state.d.ts +0 -15
- package/dist/core/anchor-state.js +0 -792
- package/dist/core/anchor.d.ts +0 -34
- package/dist/core/anchor.js +0 -843
- package/dist/core/authored-document-capability.d.ts +0 -106
- package/dist/core/authored-document-capability.js +0 -6
- package/dist/core/authored-runtime.d.ts +0 -10
- package/dist/core/authored-runtime.js +0 -67
- package/dist/core/authored-veto.d.ts +0 -30
- package/dist/core/change/builder.d.ts +0 -546
- package/dist/core/change/builder.js +0 -1120
- package/dist/core/change/carried-projection.js +0 -1518
- package/dist/core/change/carried-run.d.ts +0 -26
- package/dist/core/change/carried-run.js +0 -251
- package/dist/core/change/carry-program.js +0 -537
- package/dist/core/change/classification.d.ts +0 -22
- package/dist/core/change/classification.js +0 -205
- package/dist/core/change/cross-rule.js +0 -238
- package/dist/core/change/cross.js +0 -577
- package/dist/core/change/document-change.d.ts +0 -137
- package/dist/core/change/document-change.js +0 -872
- package/dist/core/change/document-index.d.ts +0 -117
- package/dist/core/change/document-index.js +0 -542
- package/dist/core/change/draft-facts.js +0 -323
- package/dist/core/change/enclosure.d.ts +0 -12
- package/dist/core/change/enclosure.js +0 -272
- package/dist/core/change/join.js +0 -751
- package/dist/core/change/json.d.ts +0 -4
- package/dist/core/change/json.js +0 -26
- package/dist/core/change/lazy-root.d.ts +0 -1
- package/dist/core/change/lazy-root.js +0 -73
- package/dist/core/change/lineage.d.ts +0 -49
- package/dist/core/change/lineage.js +0 -390
- package/dist/core/change/mapping.d.ts +0 -31
- package/dist/core/change/mapping.js +0 -186
- package/dist/core/change/new-letters.d.ts +0 -14
- package/dist/core/change/new-letters.js +0 -139
- package/dist/core/change/range-association.js +0 -10
- package/dist/core/change/read-back.d.ts +0 -7
- package/dist/core/change/read-back.js +0 -7
- package/dist/core/change/record.d.ts +0 -59
- package/dist/core/change/record.js +0 -346
- package/dist/core/change/root-change.d.ts +0 -180
- package/dist/core/change/root-change.js +0 -3544
- package/dist/core/change/slice-facts.js +0 -89
- package/dist/core/change/text-splices.js +0 -98
- package/dist/core/change/tokens.d.ts +0 -97
- package/dist/core/change/tokens.js +0 -449
- package/dist/core/change/transform.d.ts +0 -36
- package/dist/core/change/transform.js +0 -97
- package/dist/core/change/wrap-fidelity.js +0 -295
- package/dist/core/change-events.js +0 -223
- package/dist/core/clone.js +0 -28
- package/dist/core/command-definition.d.ts +0 -25
- package/dist/core/command-definition.js +0 -48
- package/dist/core/command-document.d.ts +0 -4
- package/dist/core/command-document.js +0 -20
- package/dist/core/command-frame.js +0 -628
- package/dist/core/command-registry.d.ts +0 -36
- package/dist/core/command-registry.js +0 -283
- package/dist/core/commit-publication.js +0 -40
- package/dist/core/commit.d.ts +0 -26
- package/dist/core/commit.js +0 -686
- package/dist/core/composition-stamp.d.ts +0 -14
- package/dist/core/composition-stamp.js +0 -79
- package/dist/core/content-completion.d.ts +0 -4
- package/dist/core/content-completion.js +0 -343
- package/dist/core/content-landing.js +0 -124
- package/dist/core/content-slice-roots.js +0 -36
- package/dist/core/content-slice.d.ts +0 -38
- package/dist/core/content-slice.js +0 -253
- package/dist/core/content.js +0 -18
- package/dist/core/correction.js +0 -25
- package/dist/core/default-storage.js +0 -53
- package/dist/core/document-admission.d.ts +0 -4
- package/dist/core/document-admission.js +0 -64
- package/dist/core/document-change.d.ts +0 -3
- package/dist/core/document-recorder.d.ts +0 -6
- package/dist/core/document-recorder.js +0 -67
- package/dist/core/document-shape.d.ts +0 -68
- package/dist/core/document-shape.js +0 -173
- package/dist/core/document-view-read.d.ts +0 -16
- package/dist/core/document-view-read.js +0 -36
- package/dist/core/draft-track.d.ts +0 -3
- package/dist/core/draft-track.js +0 -90
- package/dist/core/editor-commands.d.ts +0 -99
- package/dist/core/editor-commands.js +0 -505
- package/dist/core/editor-lifecycle-api.d.ts +0 -8
- package/dist/core/editor-lifecycle-api.js +0 -219
- package/dist/core/editor-lifetime.js +0 -12
- package/dist/core/editor-owner.d.ts +0 -24
- package/dist/core/editor-owner.js +0 -78
- package/dist/core/editor-read-execution.d.ts +0 -6
- package/dist/core/editor-read-execution.js +0 -64
- package/dist/core/editor-read-runtime.js +0 -176
- package/dist/core/editor-reads.d.ts +0 -128
- package/dist/core/editor-reads.js +0 -63
- package/dist/core/editor-runtime.d.ts +0 -112
- package/dist/core/editor-runtime.js +0 -20
- package/dist/core/editor-schema.d.ts +0 -314
- package/dist/core/editor-schema.js +0 -2295
- package/dist/core/element-owned-root-index.d.ts +0 -4
- package/dist/core/element-owned-root-index.js +0 -353
- package/dist/core/get-content-slice.js +0 -118
- package/dist/core/get-fragment.js +0 -22
- package/dist/core/identity-owner.js +0 -697
- package/dist/core/import-content-slice.js +0 -26
- package/dist/core/initial-value.js +0 -87
- package/dist/core/insert-limit.js +0 -81
- package/dist/core/is-empty-element.js +0 -20
- package/dist/core/json-fingerprint.js +0 -16
- package/dist/core/landing.d.ts +0 -11
- package/dist/core/landing.js +0 -279
- package/dist/core/lifecycle-error.d.ts +0 -11
- package/dist/core/lifecycle-error.js +0 -68
- package/dist/core/listener-state.d.ts +0 -1
- package/dist/core/listener-state.js +0 -59
- package/dist/core/measured-sequence.d.ts +0 -43
- package/dist/core/measured-sequence.js +0 -404
- package/dist/core/missing-reference.js +0 -15
- package/dist/core/node-property-mutation.js +0 -10
- package/dist/core/node-selection.js +0 -85
- package/dist/core/node-write-veto.d.ts +0 -37
- package/dist/core/node-write-veto.js +0 -17
- package/dist/core/persisted-document.d.ts +0 -6
- package/dist/core/persisted-document.js +0 -39
- package/dist/core/persistent-map.js +0 -139
- package/dist/core/plain-text.d.ts +0 -32
- package/dist/core/plain-text.js +0 -92
- package/dist/core/plugin-dispatch.d.ts +0 -21
- package/dist/core/plugin-dispatch.js +0 -166
- package/dist/core/plugin-point.d.ts +0 -6
- package/dist/core/plugin-point.js +0 -21
- package/dist/core/plugin-registry.d.ts +0 -78
- package/dist/core/plugin-registry.js +0 -485
- package/dist/core/plugin-slot.d.ts +0 -23
- package/dist/core/plugin-slot.js +0 -30
- package/dist/core/plugin.d.ts +0 -125
- package/dist/core/plugin.js +0 -1485
- package/dist/core/prefix-occupant-join.js +0 -52
- package/dist/core/profiling.js +0 -18
- package/dist/core/property-validity.d.ts +0 -14
- package/dist/core/property-validity.js +0 -65
- package/dist/core/public-root.d.ts +0 -10
- package/dist/core/public-root.js +0 -50
- package/dist/core/public-state.d.ts +0 -191
- package/dist/core/public-state.js +0 -6772
- package/dist/core/read-definition.js +0 -22
- package/dist/core/read-registry.js +0 -127
- package/dist/core/record-store.d.ts +0 -12
- package/dist/core/record-store.js +0 -297
- package/dist/core/refusal.d.ts +0 -1
- package/dist/core/refusal.js +0 -40
- package/dist/core/representation.d.ts +0 -11
- package/dist/core/representation.js +0 -844
- package/dist/core/resolved-token-cursor.d.ts +0 -21
- package/dist/core/resolved-token-cursor.js +0 -294
- package/dist/core/root-entries.js +0 -121
- package/dist/core/root-ownership.d.ts +0 -19
- package/dist/core/root-ownership.js +0 -354
- package/dist/core/root-target.d.ts +0 -7
- package/dist/core/root-target.js +0 -281
- package/dist/core/same-result.d.ts +0 -18
- package/dist/core/schema-compiler.d.ts +0 -345
- package/dist/core/schema-compiler.js +0 -3166
- package/dist/core/schema-contribution-registry.d.ts +0 -12
- package/dist/core/schema-contribution-registry.js +0 -88
- package/dist/core/schema-definition.d.ts +0 -307
- package/dist/core/schema-definition.js +0 -628
- package/dist/core/schema-source.internal.d.ts +0 -49
- package/dist/core/schema-validation.d.ts +0 -11
- package/dist/core/schema-validation.js +0 -85
- package/dist/core/screen-reader-announcement.d.ts +0 -13
- package/dist/core/screen-reader-announcement.js +0 -17
- package/dist/core/selection-protocol.d.ts +0 -38
- package/dist/core/selection-protocol.js +0 -523
- package/dist/core/selection-state.js +0 -9
- package/dist/core/semantic-update-method.d.ts +0 -11
- package/dist/core/semantic-update-method.js +0 -26
- package/dist/core/set-root.d.ts +0 -3
- package/dist/core/set-root.js +0 -244
- package/dist/core/slice-end-matter.js +0 -77
- package/dist/core/slice-fit/compiled-slice-fitter.d.ts +0 -56
- package/dist/core/slice-fit/compiled-slice-fitter.js +0 -2087
- package/dist/core/slice-fit/fit-report.d.ts +0 -36
- package/dist/core/slice-fit/fit-report.js +0 -122
- package/dist/core/slice-fit/frontier.js +0 -98
- package/dist/core/slice-fit/origin.js +0 -57
- package/dist/core/slice-fit/provenance.d.ts +0 -30
- package/dist/core/slice-fit/provenance.js +0 -245
- package/dist/core/slice-identities.js +0 -21
- package/dist/core/slice-landing-types.d.ts +0 -61
- package/dist/core/slice-landing.js +0 -124
- package/dist/core/snapshot-index.d.ts +0 -13
- package/dist/core/snapshot-index.js +0 -860
- package/dist/core/state-field.d.ts +0 -12
- package/dist/core/state-field.js +0 -102
- package/dist/core/state-fields.js +0 -36
- package/dist/core/survival.js +0 -61
- package/dist/core/target-runtime.d.ts +0 -5
- package/dist/core/target-runtime.js +0 -42
- package/dist/core/transaction-values.d.ts +0 -47
- package/dist/core/transaction-values.js +0 -66
- package/dist/core/transfer-guard.js +0 -299
- package/dist/core/transfer-types.d.ts +0 -170
- package/dist/core/transfer.d.ts +0 -72
- package/dist/core/transfer.js +0 -655
- package/dist/core/tx-only.d.ts +0 -64
- package/dist/core/tx-only.js +0 -84
- package/dist/core/unique-values.js +0 -298
- package/dist/core/update-context.js +0 -28
- package/dist/core/update-policy.d.ts +0 -17
- package/dist/core/update-policy.js +0 -45
- package/dist/core/value-codec.d.ts +0 -35
- package/dist/core/value-codec.js +0 -240
- package/dist/core/view-carets.d.ts +0 -39
- package/dist/core/view-carets.js +0 -676
- package/dist/core/view-presentation.d.ts +0 -9
- package/dist/core/view-presentation.js +0 -70
- package/dist/core/work.d.ts +0 -192
- package/dist/core/work.js +0 -122
- package/dist/core/writable-text.js +0 -37
- package/dist/create-editor.d.ts +0 -187
- package/dist/create-editor.js +0 -281
- package/dist/diff/lib/compare.d.ts +0 -33
- package/dist/diff/lib/compare.js +0 -459
- package/dist/diff/lib/comparison-align.js +0 -324
- package/dist/diff/lib/comparison-index.js +0 -160
- package/dist/diff/lib/comparison-internal.js +0 -108
- package/dist/diff/lib/comparison-matcher.js +0 -1221
- package/dist/diff/lib/comparison-moves.js +0 -151
- package/dist/diff/lib/comparison-plan.js +0 -556
- package/dist/diff/lib/index.d.ts +0 -3
- package/dist/dom/dom-soft-line-end.d.ts +0 -3
- package/dist/dom/dom-soft-line-end.js +0 -295
- package/dist/dom/internal/index.d.ts +0 -15
- package/dist/dom/plugin/data-transfer-format.d.ts +0 -90
- package/dist/dom/plugin/data-transfer-format.js +0 -525
- package/dist/dom/plugin/dom-clipboard-runtime.d.ts +0 -50
- package/dist/dom/plugin/dom-clipboard-runtime.js +0 -482
- package/dist/dom/plugin/dom-coverage.d.ts +0 -140
- package/dist/dom/plugin/dom-coverage.js +0 -443
- package/dist/dom/plugin/dom-drag-scroll.js +0 -176
- package/dist/dom/plugin/dom-drag.d.ts +0 -54
- package/dist/dom/plugin/dom-drag.js +0 -507
- package/dist/dom/plugin/dom-editor.d.ts +0 -421
- package/dist/dom/plugin/dom-editor.js +0 -1316
- package/dist/dom/plugin/dom-event-range-targets.js +0 -39
- package/dist/dom/plugin/dom-geometry.d.ts +0 -11
- package/dist/dom/plugin/dom-geometry.js +0 -888
- package/dist/dom/plugin/dom-input-runtime.d.ts +0 -1
- package/dist/dom/plugin/dom-input-runtime.js +0 -571
- package/dist/dom/plugin/dom-integrity-observer.js +0 -436
- package/dist/dom/plugin/dom-node-path.js +0 -61
- package/dist/dom/plugin/dom-phase-scheduler.d.ts +0 -1
- package/dist/dom/plugin/dom-phase-scheduler.js +0 -284
- package/dist/dom/plugin/dom-root-runtime.d.ts +0 -10
- package/dist/dom/plugin/dom-root-runtime.js +0 -716
- package/dist/dom/plugin/dom-sync-mutation-ownership.d.ts +0 -1
- package/dist/dom/plugin/dom-sync-mutation-ownership.js +0 -120
- package/dist/dom/plugin/dom-text-flow-index.js +0 -396
- package/dist/dom/plugin/dom-text-freshness.js +0 -188
- package/dist/dom/plugin/dom-text-proofs.d.ts +0 -2
- package/dist/dom/plugin/dom-text-proofs.js +0 -350
- package/dist/dom/plugin/dom-view-caret.js +0 -28
- package/dist/dom/plugin/with-dom.d.ts +0 -53
- package/dist/dom/plugin/with-dom.js +0 -101
- package/dist/dom/utils/constants.d.ts +0 -5
- package/dist/dom/utils/constants.js +0 -5
- package/dist/dom/utils/diff-text.d.ts +0 -51
- package/dist/dom/utils/diff-text.js +0 -264
- package/dist/dom/utils/dom.d.ts +0 -104
- package/dist/dom/utils/dom.js +0 -257
- package/dist/dom/utils/drag-session.d.ts +0 -2
- package/dist/dom/utils/drag-session.js +0 -115
- package/dist/dom/utils/drop-indicator.d.ts +0 -18
- package/dist/dom/utils/drop-indicator.js +0 -36
- package/dist/dom/utils/environment.d.ts +0 -12
- package/dist/dom/utils/environment.js +0 -118
- package/dist/dom/utils/hotkey-match.d.ts +0 -36
- package/dist/dom/utils/hotkey-match.js +0 -208
- package/dist/dom/utils/hotkeys.d.ts +0 -32
- package/dist/dom/utils/hotkeys.js +0 -121
- package/dist/dom/utils/key.d.ts +0 -14
- package/dist/dom/utils/key.js +0 -18
- package/dist/dom/utils/plite-dom-markers.d.ts +0 -26
- package/dist/dom/utils/plite-dom-markers.js +0 -25
- package/dist/dom/utils/selection-writes.d.ts +0 -18
- package/dist/dom/utils/selection-writes.js +0 -63
- package/dist/dom/utils/weak-maps.d.ts +0 -2
- package/dist/dom/utils/weak-maps.js +0 -51
- package/dist/editor/above.js +0 -30
- package/dist/editor/add-mark.js +0 -79
- package/dist/editor/adjacent-character-point.js +0 -120
- package/dist/editor/after.js +0 -37
- package/dist/editor/before.js +0 -124
- package/dist/editor/block-void-break.js +0 -20
- package/dist/editor/correct-document.js +0 -225
- package/dist/editor/delete-backward.js +0 -64
- package/dist/editor/delete-forward.js +0 -11
- package/dist/editor/delete-fragment.js +0 -40
- package/dist/editor/edges.js +0 -5
- package/dist/editor/element-read-only.js +0 -35
- package/dist/editor/end.d.ts +0 -7
- package/dist/editor/end.js +0 -5
- package/dist/editor/exit-break.js +0 -51
- package/dist/editor/first.js +0 -8
- package/dist/editor/get-void.js +0 -9
- package/dist/editor/has-blocks.js +0 -6
- package/dist/editor/has-inlines.js +0 -6
- package/dist/editor/has-path.js +0 -5
- package/dist/editor/has-texts.js +0 -5
- package/dist/editor/insert-break.js +0 -77
- package/dist/editor/insert-default-child.js +0 -55
- package/dist/editor/insert-soft-break.js +0 -14
- package/dist/editor/insert-text.js +0 -83
- package/dist/editor/is-block.js +0 -5
- package/dist/editor/is-edge.js +0 -5
- package/dist/editor/is-editor.js +0 -13
- package/dist/editor/is-empty.js +0 -6
- package/dist/editor/is-end.js +0 -9
- package/dist/editor/is-start.js +0 -9
- package/dist/editor/last.js +0 -20
- package/dist/editor/leaf.js +0 -9
- package/dist/editor/levels.js +0 -21
- package/dist/editor/next.js +0 -46
- package/dist/editor/node.js +0 -9
- package/dist/editor/nodes.js +0 -106
- package/dist/editor/parent.js +0 -14
- package/dist/editor/path.js +0 -26
- package/dist/editor/point.js +0 -52
- package/dist/editor/positions.js +0 -322
- package/dist/editor/previous.js +0 -48
- package/dist/editor/project-range.js +0 -6
- package/dist/editor/range.js +0 -12
- package/dist/editor/remove-mark.js +0 -65
- package/dist/editor/should-merge-nodes-remove-prev-node.js +0 -11
- package/dist/editor/string.js +0 -35
- package/dist/editor/toggle-mark.js +0 -71
- package/dist/editor/unhang-range.js +0 -71
- package/dist/editor-runtime-view.d.ts +0 -33
- package/dist/editor-runtime-view.js +0 -788
- package/dist/history/history-carets.js +0 -127
- package/dist/history/history-character-map.js +0 -425
- package/dist/history/history-codec.js +0 -176
- package/dist/history/history-merge-policy.js +0 -164
- package/dist/history/history-plugin.d.ts +0 -71
- package/dist/history/history-plugin.js +0 -814
- package/dist/history/history-replay.js +0 -799
- package/dist/history/history-selection.js +0 -75
- package/dist/history/history-state.js +0 -1287
- package/dist/history/history.d.ts +0 -112
- package/dist/history/history.js +0 -29
- package/dist/hyperscript/creators.d.ts +0 -51
- package/dist/hyperscript/hyperscript.d.ts +0 -36
- package/dist/hyperscript/hyperscript.js +0 -66
- package/dist/hyperscript/tokens.d.ts +0 -31
- package/dist/hyperscript/tokens.js +0 -63
- package/dist/interfaces/decoration.d.ts +0 -35
- package/dist/interfaces/editor.d.ts +0 -2783
- package/dist/interfaces/editor.js +0 -348
- package/dist/interfaces/element.d.ts +0 -66
- package/dist/interfaces/element.js +0 -34
- package/dist/interfaces/index.d.ts +0 -13
- package/dist/interfaces/json.d.ts +0 -7
- package/dist/interfaces/location.d.ts +0 -50
- package/dist/interfaces/location.js +0 -26
- package/dist/interfaces/node.d.ts +0 -306
- package/dist/interfaces/node.js +0 -339
- package/dist/interfaces/path.d.ts +0 -118
- package/dist/interfaces/path.js +0 -116
- package/dist/interfaces/point.d.ts +0 -45
- package/dist/interfaces/point.js +0 -32
- package/dist/interfaces/range.d.ts +0 -80
- package/dist/interfaces/range.js +0 -85
- package/dist/interfaces/schema-validation.d.ts +0 -33
- package/dist/interfaces/schema.d.ts +0 -870
- package/dist/interfaces/selection.d.ts +0 -61
- package/dist/interfaces/selection.js +0 -106
- package/dist/interfaces/text.d.ts +0 -68
- package/dist/interfaces/text.js +0 -52
- package/dist/interfaces/transforms/node.d.ts +0 -222
- package/dist/interfaces/transforms/selection.d.ts +0 -48
- package/dist/interfaces/transforms/text.d.ts +0 -58
- package/dist/internal/browser-protocol.d.ts +0 -5
- package/dist/internal/document-range.d.ts +0 -9
- package/dist/internal/document-range.js +0 -31
- package/dist/internal/editor-options.d.ts +0 -37
- package/dist/internal/editor-options.js +0 -36
- package/dist/internal/fail-invariant.d.ts +0 -4
- package/dist/internal/fail-invariant.js +0 -6
- package/dist/internal/get-defined.js +0 -7
- package/dist/internal/law-check.js +0 -7
- package/dist/internal/range-text-marks.js +0 -31
- package/dist/internal/root-location.d.ts +0 -23
- package/dist/internal/root-location.js +0 -86
- package/dist/internal/text-run.d.ts +0 -13
- package/dist/internal/text-run.js +0 -44
- package/dist/internal/view/annotation-store-metrics.d.ts +0 -11
- package/dist/internal/view/view-source.d.ts +0 -20
- package/dist/pagination/page-composition.internal.js +0 -313
- package/dist/pagination/page-geometry.internal.js +0 -99
- package/dist/pagination/page-layout-engine-invalidation.internal.js +0 -20
- package/dist/pagination/page-mount-plan.js +0 -84
- package/dist/pagination/paged-view-lines.js +0 -163
- package/dist/range-projection.d.ts +0 -7
- package/dist/range-projection.js +0 -50
- package/dist/react/components/dom-coverage-boundary.d.ts +0 -14
- package/dist/react/components/dom-coverage-boundary.js +0 -143
- package/dist/react/components/editable-descendant-binding.js +0 -70
- package/dist/react/components/editable-dom-commit-fence.js +0 -107
- package/dist/react/components/editable-element-placement.d.ts +0 -2
- package/dist/react/components/editable-element-placement.js +0 -117
- package/dist/react/components/editable-external-text.js +0 -47
- package/dist/react/components/editable-node-equality.js +0 -25
- package/dist/react/components/editable-rendered-element.d.ts +0 -3
- package/dist/react/components/editable-rendered-element.js +0 -61
- package/dist/react/components/editable-text-blocks.d.ts +0 -192
- package/dist/react/components/editable-text-blocks.js +0 -896
- package/dist/react/components/editable-text-containers.d.ts +0 -3
- package/dist/react/components/editable-text-containers.js +0 -28
- package/dist/react/components/editable-text-flow.js +0 -1039
- package/dist/react/components/editable-text-pieces.d.ts +0 -7
- package/dist/react/components/editable-text-pieces.js +0 -193
- package/dist/react/components/editable-text.d.ts +0 -80
- package/dist/react/components/editable-text.js +0 -322
- package/dist/react/components/editable.d.ts +0 -35
- package/dist/react/components/editable.js +0 -406
- package/dist/react/components/editor-announcement-live-region.js +0 -113
- package/dist/react/components/plite-element.d.ts +0 -18
- package/dist/react/components/plite-element.js +0 -54
- package/dist/react/components/plite-leaf.d.ts +0 -18
- package/dist/react/components/plite-leaf.js +0 -21
- package/dist/react/components/plite-placeholder.d.ts +0 -19
- package/dist/react/components/plite-placeholder.js +0 -39
- package/dist/react/components/plite-spacer.js +0 -14
- package/dist/react/components/plite-text.d.ts +0 -23
- package/dist/react/components/plite-text.js +0 -32
- package/dist/react/components/plite-void-shell.js +0 -49
- package/dist/react/components/plite.d.ts +0 -45
- package/dist/react/components/plite.js +0 -297
- package/dist/react/components/text-string.js +0 -18
- package/dist/react/components/windowed-editable.internal.js +0 -51
- package/dist/react/components/zero-width-string.js +0 -26
- package/dist/react/context.js +0 -11
- package/dist/react/decoration-context.d.ts +0 -2
- package/dist/react/decoration-context.js +0 -22
- package/dist/react/decoration-source.d.ts +0 -11
- package/dist/react/decoration-source.js +0 -1030
- package/dist/react/dom-text-sync.d.ts +0 -24
- package/dist/react/dom-text-sync.js +0 -48
- package/dist/react/editable/android-composition.d.ts +0 -3
- package/dist/react/editable/android-composition.js +0 -496
- package/dist/react/editable/browser-handle.js +0 -515
- package/dist/react/editable/caret-engine.js +0 -681
- package/dist/react/editable/clipboard-input-strategy.js +0 -632
- package/dist/react/editable/composition-lease.d.ts +0 -3
- package/dist/react/editable/composition-lease.js +0 -350
- package/dist/react/editable/composition-state.js +0 -716
- package/dist/react/editable/content-root-boundaries.js +0 -79
- package/dist/react/editable/content-root-coordinate-navigation.js +0 -28
- package/dist/react/editable/content-root-navigation-actions.js +0 -190
- package/dist/react/editable/content-root-navigation.js +0 -819
- package/dist/react/editable/content-root-owner-target.js +0 -36
- package/dist/react/editable/content-root-owners.js +0 -191
- package/dist/react/editable/content-root-vertical-geometry.js +0 -60
- package/dist/react/editable/decoration-repair-bridge.js +0 -29
- package/dist/react/editable/dom-coverage-selection.js +0 -158
- package/dist/react/editable/dom-coverage-vertical-selection.js +0 -446
- package/dist/react/editable/dom-input-event.js +0 -14
- package/dist/react/editable/dom-repair-queue.d.ts +0 -7
- package/dist/react/editable/dom-repair-queue.js +0 -543
- package/dist/react/editable/dom-repair-text.js +0 -47
- package/dist/react/editable/editable-command-types.d.ts +0 -1
- package/dist/react/editable/editable-dom-runtime.d.ts +0 -66
- package/dist/react/editable/editable-dom-runtime.js +0 -1022
- package/dist/react/editable/editing-epoch-adapter.js +0 -46
- package/dist/react/editable/editing-kernel.d.ts +0 -7
- package/dist/react/editable/editing-kernel.js +0 -593
- package/dist/react/editable/external-text-binding.js +0 -43
- package/dist/react/editable/external-text-runtime.d.ts +0 -5
- package/dist/react/editable/external-text-runtime.js +0 -851
- package/dist/react/editable/history-focus.js +0 -71
- package/dist/react/editable/history-keyboard.d.ts +0 -4
- package/dist/react/editable/history-keyboard.js +0 -9
- package/dist/react/editable/input-controller.d.ts +0 -7
- package/dist/react/editable/input-controller.js +0 -175
- package/dist/react/editable/input-history.js +0 -21
- package/dist/react/editable/input-router.js +0 -742
- package/dist/react/editable/input-state.d.ts +0 -18
- package/dist/react/editable/input-state.js +0 -330
- package/dist/react/editable/input-target.js +0 -30
- package/dist/react/editable/install-browser-handle.d.ts +0 -12
- package/dist/react/editable/install-browser-handle.js +0 -18
- package/dist/react/editable/interaction-owner.js +0 -88
- package/dist/react/editable/keyboard-input-strategy.js +0 -730
- package/dist/react/editable/line-boundary.js +0 -37
- package/dist/react/editable/model-input-strategy.d.ts +0 -9
- package/dist/react/editable/model-input-strategy.js +0 -242
- package/dist/react/editable/model-selection-dom-preference.js +0 -11
- package/dist/react/editable/mutation-block-editing.js +0 -48
- package/dist/react/editable/mutation-controller.d.ts +0 -32
- package/dist/react/editable/mutation-controller.js +0 -632
- package/dist/react/editable/mutation-full-block-editing.d.ts +0 -2
- package/dist/react/editable/mutation-full-block-editing.js +0 -44
- package/dist/react/editable/mutation-history.d.ts +0 -3
- package/dist/react/editable/mutation-history.js +0 -146
- package/dist/react/editable/native-input-strategy.js +0 -86
- package/dist/react/editable/native-text-input-delta.js +0 -40
- package/dist/react/editable/placed-drag.js +0 -177
- package/dist/react/editable/plite-string-coordinate-placement.js +0 -46
- package/dist/react/editable/press-fence.d.ts +0 -2
- package/dist/react/editable/press-fence.js +0 -70
- package/dist/react/editable/projected-clipboard.js +0 -123
- package/dist/react/editable/projected-native-affordance.js +0 -30
- package/dist/react/editable/projected-selection-target.js +0 -13
- package/dist/react/editable/render-contract-monitor.d.ts +0 -3
- package/dist/react/editable/render-contract-monitor.js +0 -152
- package/dist/react/editable/root-interaction-controller.js +0 -1400
- package/dist/react/editable/root-interaction-dom-selection-replay.js +0 -40
- package/dist/react/editable/root-interaction-resolver.js +0 -116
- package/dist/react/editable/root-selector-sources.js +0 -90
- package/dist/react/editable/runtime-android-engine.js +0 -40
- package/dist/react/editable/runtime-before-input-events.js +0 -671
- package/dist/react/editable/runtime-browser-handle-events.js +0 -40
- package/dist/react/editable/runtime-clipboard-events.js +0 -169
- package/dist/react/editable/runtime-composition-events.js +0 -163
- package/dist/react/editable/runtime-drag-events.js +0 -136
- package/dist/react/editable/runtime-editor-api.d.ts +0 -20
- package/dist/react/editable/runtime-editor-api.js +0 -21
- package/dist/react/editable/runtime-event-engine.js +0 -213
- package/dist/react/editable/runtime-focus-mouse-events.js +0 -264
- package/dist/react/editable/runtime-input-events.js +0 -166
- package/dist/react/editable/runtime-kernel-trace.js +0 -185
- package/dist/react/editable/runtime-keyboard-events.js +0 -333
- package/dist/react/editable/runtime-live-state.js +0 -44
- package/dist/react/editable/runtime-mutation-state.js +0 -11
- package/dist/react/editable/runtime-repair-engine.js +0 -118
- package/dist/react/editable/runtime-root-engine.js +0 -244
- package/dist/react/editable/runtime-root-lifecycle.js +0 -118
- package/dist/react/editable/runtime-root-selection-export.js +0 -38
- package/dist/react/editable/runtime-root-selection-import.js +0 -54
- package/dist/react/editable/runtime-root-state.js +0 -62
- package/dist/react/editable/runtime-selection-engine.js +0 -260
- package/dist/react/editable/runtime-selection-state.js +0 -12
- package/dist/react/editable/runtime-target-bridge.js +0 -29
- package/dist/react/editable/schema-runtime-invalidation.js +0 -26
- package/dist/react/editable/selection-change-listener.js +0 -99
- package/dist/react/editable/selection-claim.d.ts +0 -3
- package/dist/react/editable/selection-claim.js +0 -398
- package/dist/react/editable/selection-controller.d.ts +0 -8
- package/dist/react/editable/selection-controller.js +0 -693
- package/dist/react/editable/selection-dom-range.js +0 -84
- package/dist/react/editable/selection-projected-dom.js +0 -156
- package/dist/react/editable/selection-reconciler.js +0 -630
- package/dist/react/editable/selection-runtime.js +0 -89
- package/dist/react/editable/selection-side-effect-policy.js +0 -20
- package/dist/react/editable/selection-triple-click.js +0 -48
- package/dist/react/editable/selection-void-target.js +0 -172
- package/dist/react/editable/set-root-endpoints.js +0 -75
- package/dist/react/editable/soft-line-end-delete.js +0 -106
- package/dist/react/editable/text-direction.js +0 -82
- package/dist/react/editable/typed-text.d.ts +0 -17
- package/dist/react/editable/typed-text.js +0 -89
- package/dist/react/editable/unread-press.d.ts +0 -2
- package/dist/react/editable/unread-press.js +0 -86
- package/dist/react/editable/view-caret-restore.js +0 -128
- package/dist/react/editable/view-lines.d.ts +0 -7
- package/dist/react/editable/view-lines.js +0 -166
- package/dist/react/external-text.d.ts +0 -131
- package/dist/react/history-step-views.d.ts +0 -4
- package/dist/react/history-step-views.js +0 -119
- package/dist/react/hooks/android-input-manager/android-input-manager.d.ts +0 -7
- package/dist/react/hooks/android-input-manager/android-input-manager.js +0 -716
- package/dist/react/hooks/android-input-manager/use-android-input-manager.js +0 -53
- package/dist/react/hooks/focus-plite-editable.js +0 -116
- package/dist/react/hooks/use-claim-editable-dom-commit.d.ts +0 -12
- package/dist/react/hooks/use-claim-editable-dom-commit.js +0 -31
- package/dist/react/hooks/use-drop-indicator.d.ts +0 -9
- package/dist/react/hooks/use-drop-indicator.js +0 -14
- package/dist/react/hooks/use-editable-clip.d.ts +0 -18
- package/dist/react/hooks/use-editable-clip.js +0 -31
- package/dist/react/hooks/use-editable-layout-pass.js +0 -53
- package/dist/react/hooks/use-editor-composing.d.ts +0 -7
- package/dist/react/hooks/use-editor-composing.js +0 -12
- package/dist/react/hooks/use-editor-context.d.ts +0 -10
- package/dist/react/hooks/use-editor-context.js +0 -18
- package/dist/react/hooks/use-editor-dom-scope.d.ts +0 -27
- package/dist/react/hooks/use-editor-dom-scope.js +0 -23
- package/dist/react/hooks/use-editor-focused.d.ts +0 -7
- package/dist/react/hooks/use-editor-focused.js +0 -12
- package/dist/react/hooks/use-editor-read-only.d.ts +0 -25
- package/dist/react/hooks/use-editor-read-only.js +0 -19
- package/dist/react/hooks/use-editor-runtime-state.d.ts +0 -18
- package/dist/react/hooks/use-editor-runtime-state.js +0 -38
- package/dist/react/hooks/use-editor-selection.d.ts +0 -10
- package/dist/react/hooks/use-editor-selection.js +0 -13
- package/dist/react/hooks/use-editor-selector.d.ts +0 -38
- package/dist/react/hooks/use-editor-selector.js +0 -265
- package/dist/react/hooks/use-editor-view-state.d.ts +0 -16
- package/dist/react/hooks/use-editor-view-state.js +0 -20
- package/dist/react/hooks/use-editor.d.ts +0 -26
- package/dist/react/hooks/use-editor.js +0 -27
- package/dist/react/hooks/use-element-path.d.ts +0 -7
- package/dist/react/hooks/use-element-path.js +0 -36
- package/dist/react/hooks/use-element-selected.d.ts +0 -26
- package/dist/react/hooks/use-element-selected.js +0 -91
- package/dist/react/hooks/use-element.d.ts +0 -13
- package/dist/react/hooks/use-element.js +0 -17
- package/dist/react/hooks/use-generic-selector.js +0 -91
- package/dist/react/hooks/use-hydrated.js +0 -12
- package/dist/react/hooks/use-isomorphic-layout-effect.js +0 -9
- package/dist/react/hooks/use-node-selector.d.ts +0 -40
- package/dist/react/hooks/use-node-selector.js +0 -102
- package/dist/react/hooks/use-plite-annotation-store.d.ts +0 -21
- package/dist/react/hooks/use-plite-annotation-store.js +0 -61
- package/dist/react/hooks/use-plite-annotations.d.ts +0 -9
- package/dist/react/hooks/use-plite-annotations.js +0 -16
- package/dist/react/hooks/use-plite-child-root.d.ts +0 -14
- package/dist/react/hooks/use-plite-child-root.js +0 -38
- package/dist/react/hooks/use-plite-content-root.d.ts +0 -21
- package/dist/react/hooks/use-plite-content-root.js +0 -26
- package/dist/react/hooks/use-plite-history.d.ts +0 -43
- package/dist/react/hooks/use-plite-history.js +0 -137
- package/dist/react/hooks/use-plite-node-ref.js +0 -513
- package/dist/react/hooks/use-plite-root-chrome.d.ts +0 -34
- package/dist/react/hooks/use-plite-root-chrome.js +0 -98
- package/dist/react/hooks/use-plite-runtime.d.ts +0 -86
- package/dist/react/hooks/use-plite-runtime.js +0 -433
- package/dist/react/hooks/use-runtime-focus-state.js +0 -37
- package/dist/react/hooks/use-selection-geometry.d.ts +0 -12
- package/dist/react/hooks/use-selection-geometry.js +0 -39
- package/dist/react/hooks/use-selection-view.d.ts +0 -14
- package/dist/react/hooks/use-selection-view.js +0 -14
- package/dist/react/hooks/use-state-field.d.ts +0 -26
- package/dist/react/hooks/use-state-field.js +0 -38
- package/dist/react/inactive-selection.js +0 -175
- package/dist/react/plugin/react-editor.d.ts +0 -20
- package/dist/react/plugin/react-editor.js +0 -6
- package/dist/react/plugin/with-react.d.ts +0 -108
- package/dist/react/plugin/with-react.js +0 -58
- package/dist/react/render-profiler.js +0 -20
- package/dist/react/root-key.js +0 -12
- package/dist/react/shell-runtime.js +0 -29
- package/dist/react/update-policy.d.ts +0 -10
- package/dist/react/update-policy.js +0 -15
- package/dist/react/utils/environment.js +0 -5
- package/dist/react/view-boundary-graph-core.d.ts +0 -1
- package/dist/react/view-boundary-graph-core.js +0 -208
- package/dist/react/view-boundary-graph.js +0 -105
- package/dist/react/view-selection-decoration.js +0 -97
- package/dist/react/view-selection.js +0 -184
- package/dist/react/viewport-boundary.js +0 -45
- package/dist/react/viewport-commands.d.ts +0 -1
- package/dist/react/viewport-commands.js +0 -17
- package/dist/react/viewport-plan.d.ts +0 -2
- package/dist/react/viewport-plan.js +0 -77
- package/dist/react/virtualized/use-virtualized-root-plan.js +0 -148
- package/dist/testing/createDataTransfer.d.ts +0 -4
- package/dist/testing/createDataTransfer.js +0 -13
- package/dist/testing/jsx.d.ts +0 -181
- package/dist/testing/jsx.js +0 -82
- package/dist/transforms-node/insert-nodes.js +0 -143
- package/dist/transforms-node/lift-nodes.js +0 -117
- package/dist/transforms-node/merge-nodes.js +0 -180
- package/dist/transforms-node/move-nodes.js +0 -58
- package/dist/transforms-node/remove-nodes.js +0 -86
- package/dist/transforms-node/replace-children.js +0 -117
- package/dist/transforms-node/set-nodes.js +0 -188
- package/dist/transforms-node/split-nodes.js +0 -258
- package/dist/transforms-node/unset-nodes.js +0 -10
- package/dist/transforms-node/unwrap-nodes.js +0 -182
- package/dist/transforms-node/wrap-nodes.js +0 -250
- package/dist/transforms-selection/collapse.js +0 -20
- package/dist/transforms-selection/deselect.js +0 -8
- package/dist/transforms-selection/move.js +0 -35
- package/dist/transforms-selection/select.js +0 -59
- package/dist/transforms-selection/set-point.js +0 -32
- package/dist/transforms-selection/set-selection.js +0 -52
- package/dist/transforms-text/delete-text-collapsed-path-targets.js +0 -102
- package/dist/transforms-text/delete-text-grid.js +0 -402
- package/dist/transforms-text/delete-text-inline-points.js +0 -82
- package/dist/transforms-text/delete-text-plan.js +0 -55
- package/dist/transforms-text/delete-text-removal.js +0 -153
- package/dist/transforms-text/delete-text-structural-cleanup.js +0 -130
- package/dist/transforms-text/delete-text-whole-blocks.js +0 -70
- package/dist/transforms-text/delete-text.js +0 -804
- package/dist/transforms-text/full-document-range.js +0 -12
- package/dist/transforms-text/insert-text.js +0 -314
- package/dist/types/types.d.ts +0 -13
- package/dist/utils/format-debug-value.d.ts +0 -8
- package/dist/utils/format-debug-value.js +0 -31
- package/dist/utils/get-default-insert-location.js +0 -19
- package/dist/utils/is-object.d.ts +0 -4
- package/dist/utils/is-object.js +0 -4
- package/dist/utils/match-path.js +0 -8
- package/dist/utils/node-keys.d.ts +0 -15
- package/dist/utils/node-keys.js +0 -179
- package/dist/utils/node-match.js +0 -9
- package/dist/utils/string.js +0 -283
- package/dist/yjs/core/addresses.js +0 -98
- package/dist/yjs/core/ancestor-properties.js +0 -56
- package/dist/yjs/core/attributes.js +0 -21
- package/dist/yjs/core/awareness-adapter.d.ts +0 -5
- package/dist/yjs/core/awareness-adapter.js +0 -399
- package/dist/yjs/core/awareness-relative-selection.js +0 -22
- package/dist/yjs/core/awareness.js +0 -25
- package/dist/yjs/core/binding.d.ts +0 -3
- package/dist/yjs/core/binding.js +0 -128
- package/dist/yjs/core/boundaries.js +0 -453
- package/dist/yjs/core/canonical-split.js +0 -130
- package/dist/yjs/core/change-bridge.js +0 -124
- package/dist/yjs/core/change-regions.js +0 -119
- package/dist/yjs/core/controller-registry.js +0 -70
- package/dist/yjs/core/controller.d.ts +0 -6
- package/dist/yjs/core/controller.js +0 -1282
- package/dist/yjs/core/document.js +0 -1499
- package/dist/yjs/core/editor-adapter.d.ts +0 -18
- package/dist/yjs/core/editor-adapter.js +0 -145
- package/dist/yjs/core/editor-only-roots.js +0 -53
- package/dist/yjs/core/editor-types.d.ts +0 -1
- package/dist/yjs/core/enclosures.js +0 -410
- package/dist/yjs/core/event-change-bridge.js +0 -3642
- package/dist/yjs/core/index.d.ts +0 -4
- package/dist/yjs/core/joined-lines.js +0 -81
- package/dist/yjs/core/joins.js +0 -587
- package/dist/yjs/core/json-equality.js +0 -31
- package/dist/yjs/core/keys.js +0 -29
- package/dist/yjs/core/letter-scripts.js +0 -449
- package/dist/yjs/core/new-letters.js +0 -300
- package/dist/yjs/core/path.js +0 -25
- package/dist/yjs/core/plugin.js +0 -206
- package/dist/yjs/core/record.js +0 -4
- package/dist/yjs/core/replacement.js +0 -165
- package/dist/yjs/core/retraction.js +0 -132
- package/dist/yjs/core/root-owners.js +0 -110
- package/dist/yjs/core/root-projection-index.js +0 -428
- package/dist/yjs/core/schema-metadata.js +0 -88
- package/dist/yjs/core/selection.js +0 -34
- package/dist/yjs/core/set-valued-attributes.js +0 -57
- package/dist/yjs/core/shared-effect-log.d.ts +0 -4
- package/dist/yjs/core/shared-effect-log.js +0 -674
- package/dist/yjs/core/text-runs.js +0 -1596
- package/dist/yjs/core/types.d.ts +0 -76
- package/dist/yjs/react/useYjs.d.ts +0 -25
- package/dist/yjs/react/useYjs.js +0 -85
package/dist/diff/index.js
CHANGED
|
@@ -1,2 +1,1748 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Yu as DocumentChange, np as jsonEqual } from "../plugin-DWzkJbnJ.js";
|
|
2
|
+
import { _ as mergeGroups, a as comparisonTextRuns, b as uniqueSpans$1, c as COMPARISON_POLICY, d as comparisonDocumentsEqual, f as comparisonHash, g as disjointSets, h as detachComparisonEnvelope, i as comparisonTextPoint, l as COMPARISON_WORD, m as detachComparisonDocument, n as comparisonPlanOf, o as comparisonTextSpans, p as createComparisonSnapshot, r as planComparison, s as createComparisonIndex, t as closeOverRequired, u as assertComparisonActive, v as spanKey, x as yieldComparisonWork, y as stableStringify } from "../comparison-plan-CEQL0ooW.js";
|
|
3
|
+
import { DiffMatchPatch, DiffOp } from "diff-match-patch-ts";
|
|
4
|
+
//#region src/diff/lib/comparison-matcher.ts
|
|
5
|
+
const CANDIDATES_PER_NODE = 24;
|
|
6
|
+
const DIRECT_CANDIDATES_PER_NODE = 8;
|
|
7
|
+
const MAX_CANDIDATE_EDGES = 1e5;
|
|
8
|
+
const MAX_DIRECT_WINDOW_DISAMBIGUATIONS = 128;
|
|
9
|
+
const MAX_WINDOW = 4;
|
|
10
|
+
const YIELD_INTERVAL = 4096;
|
|
11
|
+
const MAX_TOKEN_CODE = 65535;
|
|
12
|
+
const TEXT_TOKEN = new RegExp(String.raw`${COMPARISON_WORD.source}|\s+|.`, "gsu");
|
|
13
|
+
const dmp = new DiffMatchPatch();
|
|
14
|
+
dmp.Diff_Timeout = .2;
|
|
15
|
+
const compareNodeOrder = (left, right) => {
|
|
16
|
+
const rootOrder = (left.root ?? "").localeCompare(right.root ?? "");
|
|
17
|
+
if (rootOrder !== 0) return rootOrder;
|
|
18
|
+
for (let index = 0; index < Math.min(left.path.length, right.path.length); index += 1) {
|
|
19
|
+
const difference = left.path[index] - right.path[index];
|
|
20
|
+
if (difference !== 0) return difference;
|
|
21
|
+
}
|
|
22
|
+
return left.path.length - right.path.length;
|
|
23
|
+
};
|
|
24
|
+
const nodeKey = (node) => `${node.root ?? ""}:${stableStringify(node.path)}`;
|
|
25
|
+
const pairKey = (before, after) => `${before}:${after}`;
|
|
26
|
+
const lastPathIndex = (node) => node.path.at(-1) ?? 0;
|
|
27
|
+
const graphemeSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter("und", { granularity: "grapheme" }) : null;
|
|
28
|
+
const semanticTokens = (text) => {
|
|
29
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
30
|
+
const lower = text.toLocaleLowerCase("und");
|
|
31
|
+
for (const match of lower.matchAll(/[\p{L}\p{N}]+|[^\s]/gu)) {
|
|
32
|
+
const token = match[0];
|
|
33
|
+
tokens.add(`w:${token}`);
|
|
34
|
+
if (tokens.size >= 96) break;
|
|
35
|
+
}
|
|
36
|
+
const compact = lower.replaceAll(/\s/gu, "");
|
|
37
|
+
const characters = graphemeSegmenter ? Array.from(graphemeSegmenter.segment(compact), ({ segment }) => segment) : Array.from(compact);
|
|
38
|
+
for (let index = 0; index + 2 < characters.length; index += 2) {
|
|
39
|
+
tokens.add(`g:${characters.slice(index, index + 3).join("")}`);
|
|
40
|
+
if (tokens.size >= 128) break;
|
|
41
|
+
}
|
|
42
|
+
return tokens;
|
|
43
|
+
};
|
|
44
|
+
const textSimilarityFromTokens = (beforeText, afterText, beforeTokens, afterTokens) => {
|
|
45
|
+
const similarity = semanticSimilarity(beforeTokens, afterTokens);
|
|
46
|
+
const length = beforeText.length === 0 && afterText.length === 0 ? 1 : Math.min(beforeText.length, afterText.length) / Math.max(beforeText.length, afterText.length, 1);
|
|
47
|
+
return similarity * .75 + length * .25;
|
|
48
|
+
};
|
|
49
|
+
const textSimilarity = (beforeText, afterText) => textSimilarityFromTokens(beforeText, afterText, semanticTokens(beforeText), semanticTokens(afterText));
|
|
50
|
+
const setSimilarity = (left, right) => {
|
|
51
|
+
if (left.size === 0 && right.size === 0) return 1;
|
|
52
|
+
let intersection = 0;
|
|
53
|
+
for (const value of left) if (right.has(value)) intersection += 1;
|
|
54
|
+
return 2 * intersection / (left.size + right.size);
|
|
55
|
+
};
|
|
56
|
+
const semanticSimilarity = (left, right) => {
|
|
57
|
+
const select = (values, prefix) => new Set([...values].filter((value) => value.startsWith(prefix)));
|
|
58
|
+
const leftWords = select(left, "w:");
|
|
59
|
+
const rightWords = select(right, "w:");
|
|
60
|
+
const leftGrams = select(left, "g:");
|
|
61
|
+
const rightGrams = select(right, "g:");
|
|
62
|
+
return Math.max(setSimilarity(left, right), leftWords.size > 0 && rightWords.size > 0 ? setSimilarity(leftWords, rightWords) : 0, leftGrams.size > 0 && rightGrams.size > 0 ? setSimilarity(leftGrams, rightGrams) : 0);
|
|
63
|
+
};
|
|
64
|
+
const createTokenNodeIndex = (nodeIndexes, index) => {
|
|
65
|
+
const result = /* @__PURE__ */ new Map();
|
|
66
|
+
for (const nodeIndex of nodeIndexes) {
|
|
67
|
+
const tokens = semanticTokens(index.nodes[nodeIndex].text);
|
|
68
|
+
for (const token of tokens) {
|
|
69
|
+
const values = result.get(token) ?? [];
|
|
70
|
+
if (values.length < CANDIDATES_PER_NODE) values.push(nodeIndex);
|
|
71
|
+
result.set(token, values);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
const boundedMatchingWindow = (text, siblingIndexes, positionByIndex, tokenNodes, index, matched) => {
|
|
77
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
78
|
+
for (const token of semanticTokens(text)) {
|
|
79
|
+
for (const anchor of tokenNodes.get(token) ?? []) {
|
|
80
|
+
const position = positionByIndex.get(anchor);
|
|
81
|
+
if (position === void 0) continue;
|
|
82
|
+
for (let size = 2; size <= MAX_WINDOW; size += 1) {
|
|
83
|
+
for (let offset = 0; offset < size; offset += 1) {
|
|
84
|
+
const start = position - offset;
|
|
85
|
+
const window = siblingIndexes.slice(start, start + size);
|
|
86
|
+
if (start < 0 || window.length !== size || window.some((nodeIndex) => matched.has(nodeIndex) || index.nodes[nodeIndex].text.length === 0)) continue;
|
|
87
|
+
candidates.set(`${start}:${size}`, window);
|
|
88
|
+
if (candidates.size >= CANDIDATES_PER_NODE) break;
|
|
89
|
+
}
|
|
90
|
+
if (candidates.size >= CANDIDATES_PER_NODE) break;
|
|
91
|
+
}
|
|
92
|
+
if (candidates.size >= CANDIDATES_PER_NODE) break;
|
|
93
|
+
}
|
|
94
|
+
if (candidates.size >= CANDIDATES_PER_NODE) break;
|
|
95
|
+
}
|
|
96
|
+
const ranked = [...candidates.values()].map((window) => ({
|
|
97
|
+
score: textSimilarity(text, window.map((nodeIndex) => index.nodes[nodeIndex].text).join("")),
|
|
98
|
+
window
|
|
99
|
+
})).toSorted((left, right) => right.score - left.score);
|
|
100
|
+
return Object.freeze({
|
|
101
|
+
score: ranked[0]?.score ?? 0,
|
|
102
|
+
window: ranked[0]?.score >= .62 ? ranked[0].window : void 0,
|
|
103
|
+
work: candidates.size
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const propertySimilarity = (before, after) => {
|
|
107
|
+
if (jsonEqual(before.properties, after.properties)) return 1;
|
|
108
|
+
const beforeKeys = new Set(Object.keys(before.properties));
|
|
109
|
+
const afterKeys = new Set(Object.keys(after.properties));
|
|
110
|
+
return setSimilarity(beforeKeys, afterKeys);
|
|
111
|
+
};
|
|
112
|
+
const candidateScore = (before, after, beforeTokens, afterTokens) => {
|
|
113
|
+
if (before.blockContainer !== after.blockContainer) return 0;
|
|
114
|
+
const text = semanticSimilarity(beforeTokens, afterTokens);
|
|
115
|
+
const length = before.text.length === 0 && after.text.length === 0 ? 1 : Math.min(before.text.length, after.text.length) / Math.max(before.text.length, after.text.length, 1);
|
|
116
|
+
const properties = propertySimilarity(before, after);
|
|
117
|
+
const type = before.type === after.type ? 1 : 0;
|
|
118
|
+
const structure = before.structure?.kind === after.structure?.kind && before.structure !== null && after.structure !== null ? 1 : 0;
|
|
119
|
+
const position = nodeKey(before) === nodeKey(after) ? 1 : 0;
|
|
120
|
+
if (text < .24 && position === 0 && !(before.text.length === 0 && properties === 1 && type === 1)) return 0;
|
|
121
|
+
return text * .45 + length * .15 + properties * .1 + type * .15 + structure * .05 + position * .25;
|
|
122
|
+
};
|
|
123
|
+
const longestIncreasingPairKeys = (pairs, after) => {
|
|
124
|
+
const positions = pairs.map((pair) => lastPathIndex(after.nodes[pair.after])).toSorted((left, right) => left - right).filter((value, index, values) => index === 0 || value !== values[index - 1]);
|
|
125
|
+
const positionByValue = new Map(positions.map((value, index) => [value, index + 1]));
|
|
126
|
+
const tree = new Array(positions.length + 1);
|
|
127
|
+
const previous = new Array(pairs.length).fill(-1);
|
|
128
|
+
const better = (left, right) => {
|
|
129
|
+
if (!left) return right;
|
|
130
|
+
if (!right) return left;
|
|
131
|
+
return right.length > left.length || right.length === left.length && right.exact > left.exact || right.length === left.length && right.exact === left.exact && right.pairIndex < left.pairIndex ? right : left;
|
|
132
|
+
};
|
|
133
|
+
const query = (position) => {
|
|
134
|
+
let result;
|
|
135
|
+
for (let cursor = position; cursor > 0; cursor -= cursor & -cursor) result = better(result, tree[cursor]);
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
const update = (position, value) => {
|
|
139
|
+
for (let cursor = position; cursor < tree.length; cursor += cursor & -cursor) tree[cursor] = better(tree[cursor], value);
|
|
140
|
+
};
|
|
141
|
+
pairs.forEach((pair, pairIndex) => {
|
|
142
|
+
const value = lastPathIndex(after.nodes[pair.after]);
|
|
143
|
+
const position = positionByValue.get(value);
|
|
144
|
+
if (position === void 0) throw new Error("Comparison placement coordinate is missing.");
|
|
145
|
+
const prior = query(position - 1);
|
|
146
|
+
const sequence = {
|
|
147
|
+
exact: (prior?.exact ?? 0) + (pair.evidence.kind === "inferred" && pair.evidence.basis === "exact" ? 1 : 0),
|
|
148
|
+
length: (prior?.length ?? 0) + 1,
|
|
149
|
+
pairIndex
|
|
150
|
+
};
|
|
151
|
+
previous[pairIndex] = prior?.pairIndex ?? -1;
|
|
152
|
+
update(position, sequence);
|
|
153
|
+
});
|
|
154
|
+
const result = /* @__PURE__ */ new Set();
|
|
155
|
+
let cursor = query(positions.length)?.pairIndex ?? -1;
|
|
156
|
+
while (cursor >= 0) {
|
|
157
|
+
const pair = pairs[cursor];
|
|
158
|
+
result.add(pairKey(pair.before, pair.after));
|
|
159
|
+
cursor = previous[cursor];
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
};
|
|
163
|
+
const matchedParent = (pair, before, after, byBefore) => {
|
|
164
|
+
const beforeNode = before.nodes[pair.before];
|
|
165
|
+
const afterNode = after.nodes[pair.after];
|
|
166
|
+
if (beforeNode.parentIndex === null || afterNode.parentIndex === null) return beforeNode.parentIndex === afterNode.parentIndex;
|
|
167
|
+
return byBefore.get(beforeNode.parentIndex)?.after === afterNode.parentIndex;
|
|
168
|
+
};
|
|
169
|
+
const placementPairs = (pairs, before, after) => {
|
|
170
|
+
const byBefore = new Map(pairs.map((pair) => [pair.before, pair]));
|
|
171
|
+
const stable = /* @__PURE__ */ new Set();
|
|
172
|
+
const siblings = /* @__PURE__ */ new Map();
|
|
173
|
+
for (const pair of pairs) {
|
|
174
|
+
const beforeNode = before.nodes[pair.before];
|
|
175
|
+
const afterNode = after.nodes[pair.after];
|
|
176
|
+
if (beforeNode.root !== afterNode.root || !matchedParent(pair, before, after, byBefore)) continue;
|
|
177
|
+
const key = `${beforeNode.root ?? ""}:${beforeNode.parentIndex ?? "root"}:${afterNode.parentIndex ?? "root"}`;
|
|
178
|
+
const values = siblings.get(key) ?? [];
|
|
179
|
+
values.push(pair);
|
|
180
|
+
siblings.set(key, values);
|
|
181
|
+
}
|
|
182
|
+
for (const values of siblings.values()) {
|
|
183
|
+
const ordered = values.toSorted((left, right) => lastPathIndex(before.nodes[left.before]) - lastPathIndex(before.nodes[right.before]));
|
|
184
|
+
for (const key of longestIncreasingPairKeys(ordered, after)) stable.add(key);
|
|
185
|
+
}
|
|
186
|
+
return new Set(pairs.flatMap((pair) => {
|
|
187
|
+
const beforeNode = before.nodes[pair.before];
|
|
188
|
+
const afterNode = after.nodes[pair.after];
|
|
189
|
+
const key = pairKey(pair.before, pair.after);
|
|
190
|
+
return beforeNode.root !== afterNode.root || !matchedParent(pair, before, after, byBefore) || !stable.has(key) ? [key] : [];
|
|
191
|
+
}));
|
|
192
|
+
};
|
|
193
|
+
const hasMovedMatchedAncestor = (pair, moved, before, byBefore) => {
|
|
194
|
+
let parent = before.nodes[pair.before].parentIndex;
|
|
195
|
+
while (parent !== null) {
|
|
196
|
+
const parentPair = byBefore.get(parent);
|
|
197
|
+
if (!parentPair) return false;
|
|
198
|
+
if (moved.has(pairKey(parentPair.before, parentPair.after))) return true;
|
|
199
|
+
parent = before.nodes[parent].parentIndex;
|
|
200
|
+
}
|
|
201
|
+
return false;
|
|
202
|
+
};
|
|
203
|
+
const semanticDiff = (beforeText, afterText) => {
|
|
204
|
+
const chunks = dmp.diff_main(beforeText, afterText);
|
|
205
|
+
dmp.diff_cleanupSemantic(chunks);
|
|
206
|
+
return chunks;
|
|
207
|
+
};
|
|
208
|
+
const wordDiff = (beforeSegments, afterSegments) => {
|
|
209
|
+
const tokens = [];
|
|
210
|
+
const codes = /* @__PURE__ */ new Map();
|
|
211
|
+
const encode = (texts) => {
|
|
212
|
+
let encoded = "";
|
|
213
|
+
for (const text of texts) for (const [token] of text.matchAll(TEXT_TOKEN)) {
|
|
214
|
+
let code = codes.get(token);
|
|
215
|
+
if (code === void 0) {
|
|
216
|
+
if (tokens.length > MAX_TOKEN_CODE) return null;
|
|
217
|
+
code = String.fromCharCode(tokens.length);
|
|
218
|
+
tokens.push(token);
|
|
219
|
+
codes.set(token, code);
|
|
220
|
+
}
|
|
221
|
+
encoded += code;
|
|
222
|
+
}
|
|
223
|
+
return encoded;
|
|
224
|
+
};
|
|
225
|
+
const beforeCodes = encode(beforeSegments);
|
|
226
|
+
const afterCodes = encode(afterSegments);
|
|
227
|
+
if (beforeCodes === null || afterCodes === null) return semanticDiff(beforeSegments.join(""), afterSegments.join(""));
|
|
228
|
+
return semanticDiff(beforeCodes, afterCodes).map(([operation, codesText]) => {
|
|
229
|
+
let text = "";
|
|
230
|
+
for (let at = 0; at < codesText.length; at += 1) text += tokens[codesText.charCodeAt(at)];
|
|
231
|
+
return [operation, text];
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
const segmentEdges = (texts) => {
|
|
235
|
+
const edges = [];
|
|
236
|
+
let offset = 0;
|
|
237
|
+
for (const text of texts.slice(0, -1)) {
|
|
238
|
+
offset += text.length;
|
|
239
|
+
edges.push(offset);
|
|
240
|
+
}
|
|
241
|
+
return edges;
|
|
242
|
+
};
|
|
243
|
+
const cutAtSegmentEdges = (edges, [beforeFrom, beforeTo], [afterFrom, afterTo]) => {
|
|
244
|
+
const inside = (all, from, to) => all.filter((edge) => edge > from && edge < to);
|
|
245
|
+
let beforeCuts = inside(edges[0], beforeFrom, beforeTo);
|
|
246
|
+
let afterCuts = inside(edges[1], afterFrom, afterTo);
|
|
247
|
+
if (beforeFrom === beforeTo) beforeCuts = afterCuts.map(() => beforeFrom);
|
|
248
|
+
if (afterFrom === afterTo) afterCuts = beforeCuts.map(() => afterFrom);
|
|
249
|
+
if (beforeCuts.length !== afterCuts.length) {
|
|
250
|
+
beforeCuts = [];
|
|
251
|
+
afterCuts = [];
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
after: [
|
|
255
|
+
afterFrom,
|
|
256
|
+
...afterCuts,
|
|
257
|
+
afterTo
|
|
258
|
+
],
|
|
259
|
+
before: [
|
|
260
|
+
beforeFrom,
|
|
261
|
+
...beforeCuts,
|
|
262
|
+
beforeTo
|
|
263
|
+
]
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
const textDifferenceParts = (beforeSegments, afterSegments, beforeRange, afterRange, beforePoint, afterPoint) => {
|
|
267
|
+
const beforeAll = beforeSegments.join("");
|
|
268
|
+
const afterAll = afterSegments.join("");
|
|
269
|
+
if (beforeAll === afterAll) return [];
|
|
270
|
+
const chunks = wordDiff(beforeSegments, afterSegments);
|
|
271
|
+
const edges = [segmentEdges(beforeSegments), segmentEdges(afterSegments)];
|
|
272
|
+
const differences = [];
|
|
273
|
+
let beforeOffset = 0;
|
|
274
|
+
let afterOffset = 0;
|
|
275
|
+
let index = 0;
|
|
276
|
+
while (index < chunks.length) {
|
|
277
|
+
const [operation, text] = chunks[index];
|
|
278
|
+
if (operation === DiffOp.Equal) {
|
|
279
|
+
beforeOffset += text.length;
|
|
280
|
+
afterOffset += text.length;
|
|
281
|
+
index += 1;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const beforeStart = beforeOffset;
|
|
285
|
+
const afterStart = afterOffset;
|
|
286
|
+
while (index < chunks.length && chunks[index][0] !== DiffOp.Equal) {
|
|
287
|
+
const [innerOperation, innerText] = chunks[index];
|
|
288
|
+
if (innerOperation === DiffOp.Delete) beforeOffset += innerText.length;
|
|
289
|
+
else afterOffset += innerText.length;
|
|
290
|
+
index += 1;
|
|
291
|
+
}
|
|
292
|
+
const bounds = cutAtSegmentEdges(edges, [beforeStart, beforeOffset], [afterStart, afterOffset]);
|
|
293
|
+
for (let piece = 1; piece < bounds.before.length; piece += 1) {
|
|
294
|
+
const [beforeFrom, beforeTo] = bounds.before.slice(piece - 1, piece + 1);
|
|
295
|
+
const [afterFrom, afterTo] = bounds.after.slice(piece - 1, piece + 1);
|
|
296
|
+
differences.push({
|
|
297
|
+
after: afterFrom === afterTo ? [afterPoint(afterFrom)] : afterRange(afterFrom, afterTo),
|
|
298
|
+
afterText: afterAll.slice(afterFrom, afterTo),
|
|
299
|
+
before: beforeFrom === beforeTo ? [beforePoint(beforeFrom)] : beforeRange(beforeFrom, beforeTo),
|
|
300
|
+
beforeText: beforeAll.slice(beforeFrom, beforeTo)
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return differences;
|
|
305
|
+
};
|
|
306
|
+
const wordSegments = (node, index) => {
|
|
307
|
+
if (node.kind === "text" || node.inline) return [node.text];
|
|
308
|
+
const segments = [];
|
|
309
|
+
let afterText = false;
|
|
310
|
+
for (const child of node.childIndexes.map((at) => index.nodes[at])) {
|
|
311
|
+
if (child.kind === "text" && afterText) segments[segments.length - 1] += child.text;
|
|
312
|
+
else segments.push(...wordSegments(child, index));
|
|
313
|
+
afterText = child.kind === "text";
|
|
314
|
+
}
|
|
315
|
+
return segments;
|
|
316
|
+
};
|
|
317
|
+
const textDifferences = (before, after, beforeIndex, afterIndex) => textDifferenceParts(wordSegments(before, beforeIndex), wordSegments(after, afterIndex), (from, to) => comparisonTextSpans(before, from, to), (from, to) => comparisonTextSpans(after, from, to), (offset) => comparisonTextPoint(before, offset), (offset) => comparisonTextPoint(after, offset));
|
|
318
|
+
const sequenceTextSpans = (nodes, from, to) => {
|
|
319
|
+
let offset = 0;
|
|
320
|
+
return Object.freeze(nodes.flatMap((node) => {
|
|
321
|
+
const nodeFrom = offset;
|
|
322
|
+
const nodeTo = nodeFrom + node.text.length;
|
|
323
|
+
const overlapFrom = Math.max(from, nodeFrom);
|
|
324
|
+
const overlapTo = Math.min(to, nodeTo);
|
|
325
|
+
offset = nodeTo;
|
|
326
|
+
return overlapFrom < overlapTo ? comparisonTextSpans(node, overlapFrom - nodeFrom, overlapTo - nodeFrom) : [];
|
|
327
|
+
}));
|
|
328
|
+
};
|
|
329
|
+
const sequenceTextPoint = (nodes, offset) => {
|
|
330
|
+
let from = 0;
|
|
331
|
+
for (const node of nodes) {
|
|
332
|
+
const to = from + node.text.length;
|
|
333
|
+
if (offset < to) return comparisonTextPoint(node, offset - from);
|
|
334
|
+
from = to;
|
|
335
|
+
}
|
|
336
|
+
const last = nodes.at(-1);
|
|
337
|
+
if (!last) throw new Error("Comparison relation has no text owner.");
|
|
338
|
+
return comparisonTextPoint(last, last.text.length);
|
|
339
|
+
};
|
|
340
|
+
const sequenceTextRuns = (nodes) => {
|
|
341
|
+
const result = [];
|
|
342
|
+
for (const node of nodes) for (const run of comparisonTextRuns(node)) {
|
|
343
|
+
const previous = result.at(-1);
|
|
344
|
+
if (previous && stableStringify(previous.properties) === stableStringify(run.properties)) result[result.length - 1] = Object.freeze({
|
|
345
|
+
properties: previous.properties,
|
|
346
|
+
text: previous.text + run.text
|
|
347
|
+
});
|
|
348
|
+
else result.push(Object.freeze({
|
|
349
|
+
properties: run.properties,
|
|
350
|
+
text: run.text
|
|
351
|
+
}));
|
|
352
|
+
}
|
|
353
|
+
return Object.freeze(result);
|
|
354
|
+
};
|
|
355
|
+
const sequenceOwnProperties = (nodes) => {
|
|
356
|
+
const result = [];
|
|
357
|
+
for (const { properties } of nodes) if (result.length === 0 || stableStringify(result.at(-1)) !== stableStringify(properties)) result.push(properties);
|
|
358
|
+
return Object.freeze(result);
|
|
359
|
+
};
|
|
360
|
+
const sequenceTextDifferences = (beforeNodes, afterNodes, beforeIndex, afterIndex) => textDifferenceParts(beforeNodes.flatMap((node) => wordSegments(node, beforeIndex)), afterNodes.flatMap((node) => wordSegments(node, afterIndex)), (from, to) => sequenceTextSpans(beforeNodes, from, to), (from, to) => sequenceTextSpans(afterNodes, from, to), (offset) => sequenceTextPoint(beforeNodes, offset), (offset) => sequenceTextPoint(afterNodes, offset));
|
|
361
|
+
const childOrderChanged = (pair, before, after, byBefore) => {
|
|
362
|
+
const beforeChildren = before.nodes[pair.before].childIndexes.filter((index) => before.nodes[index].kind === "element");
|
|
363
|
+
const afterChildren = after.nodes[pair.after].childIndexes.filter((index) => after.nodes[index].kind === "element");
|
|
364
|
+
const mapped = beforeChildren.flatMap((index) => {
|
|
365
|
+
const child = byBefore.get(index);
|
|
366
|
+
return child ? [child.after] : [];
|
|
367
|
+
});
|
|
368
|
+
return mapped.length !== beforeChildren.length || mapped.length !== afterChildren.length || mapped.some((index, position) => index !== afterChildren[position]);
|
|
369
|
+
};
|
|
370
|
+
const changedMatchedElementDescendants = (pair, before, after, byBefore) => {
|
|
371
|
+
const result = [];
|
|
372
|
+
const pending = [...before.nodes[pair.before].childIndexes];
|
|
373
|
+
while (pending.length > 0) {
|
|
374
|
+
const sourceIndex = pending.pop();
|
|
375
|
+
if (sourceIndex === void 0) continue;
|
|
376
|
+
const source = before.nodes[sourceIndex];
|
|
377
|
+
pending.push(...source.childIndexes);
|
|
378
|
+
if (source.kind !== "element") continue;
|
|
379
|
+
const targetPair = byBefore.get(sourceIndex);
|
|
380
|
+
if (targetPair && source.text !== after.nodes[targetPair.after].text) result.push(targetPair);
|
|
381
|
+
}
|
|
382
|
+
return result;
|
|
383
|
+
};
|
|
384
|
+
const spanContains = (outer, inner) => outer.root === inner.root && outer.from <= inner.from && outer.to >= inner.to;
|
|
385
|
+
const textDifferenceOwnedByDescendant = (difference, descendants, before, after) => descendants.some((descendant) => {
|
|
386
|
+
const source = before.nodes[descendant.before].span;
|
|
387
|
+
const target = after.nodes[descendant.after].span;
|
|
388
|
+
return difference.before.every((span) => spanContains(source, span)) && difference.after.every((span) => spanContains(target, span));
|
|
389
|
+
});
|
|
390
|
+
const maximalUnmatched = (index, matched) => index.nodes.filter((node) => {
|
|
391
|
+
if (node.kind !== "element" || matched.has(node.index)) return false;
|
|
392
|
+
return node.parentIndex === null || matched.has(node.parentIndex);
|
|
393
|
+
});
|
|
394
|
+
const blockText = (index, node) => node.blockContainer ? node.childIndexes.map((childIndex) => blockText(index, index.nodes[childIndex])).join("\n") : node.text;
|
|
395
|
+
const ancestorsWithMatchedDescendants = (index, matched) => {
|
|
396
|
+
const result = /* @__PURE__ */ new Set();
|
|
397
|
+
for (const matchedIndex of matched) {
|
|
398
|
+
let parent = index.nodes[matchedIndex].parentIndex;
|
|
399
|
+
while (parent !== null) {
|
|
400
|
+
result.add(parent);
|
|
401
|
+
parent = index.nodes[parent].parentIndex;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return result;
|
|
405
|
+
};
|
|
406
|
+
const relationSpans = (indexes, source) => Object.freeze(indexes.map((index) => source.nodes[index].span));
|
|
407
|
+
const composeWrapperGroups = (changes) => {
|
|
408
|
+
let result = [...changes];
|
|
409
|
+
const wrappers = changes.flatMap((change) => change.effects.flatMap((effect) => effect.kind === "wrapper" ? [{
|
|
410
|
+
change,
|
|
411
|
+
effect
|
|
412
|
+
}] : [])).toSorted((left, right) => {
|
|
413
|
+
const leftSpan = left.effect.action === "add" ? left.effect.after[0] : left.effect.before[0];
|
|
414
|
+
const rightSpan = right.effect.action === "add" ? right.effect.after[0] : right.effect.before[0];
|
|
415
|
+
return leftSpan.to - leftSpan.from - (rightSpan.to - rightSpan.from);
|
|
416
|
+
});
|
|
417
|
+
for (const { change: originalWrapper, effect } of wrappers) {
|
|
418
|
+
const wrapperIndex = result.findIndex(({ id }) => id === originalWrapper.id);
|
|
419
|
+
if (wrapperIndex === -1) continue;
|
|
420
|
+
const wrapperSpan = effect.action === "add" ? effect.after[0] : effect.before[0];
|
|
421
|
+
const nestedIndexes = result.flatMap((candidate, index) => {
|
|
422
|
+
if (index === wrapperIndex) return [];
|
|
423
|
+
return (effect.action === "add" ? candidate.after : candidate.before).some((candidateSpan) => candidateSpan.root === wrapperSpan.root && candidateSpan.from >= wrapperSpan.from && candidateSpan.to <= wrapperSpan.to) ? [index] : [];
|
|
424
|
+
});
|
|
425
|
+
if (nestedIndexes.length === 0) continue;
|
|
426
|
+
result = mergeGroups(result, [{
|
|
427
|
+
members: [wrapperIndex, ...nestedIndexes],
|
|
428
|
+
owner: wrapperIndex
|
|
429
|
+
}]);
|
|
430
|
+
}
|
|
431
|
+
return Object.freeze(result);
|
|
432
|
+
};
|
|
433
|
+
const logicalOutlineSpan = (index, node) => {
|
|
434
|
+
if (node.structure?.kind !== "outline") return null;
|
|
435
|
+
const siblings = node.parentIndex === null ? index.roots.get(node.root)?.topLevelIndexes ?? [] : index.nodes[node.parentIndex].childIndexes;
|
|
436
|
+
const position = siblings.indexOf(node.index);
|
|
437
|
+
const levelValue = node.properties[node.structure.level.key];
|
|
438
|
+
const level = typeof levelValue === "number" ? levelValue : 1;
|
|
439
|
+
const { from, root, to: nodeTo } = node;
|
|
440
|
+
let to = nodeTo;
|
|
441
|
+
for (let cursor = position + 1; cursor < siblings.length; cursor += 1) {
|
|
442
|
+
const sibling = index.nodes[siblings[cursor]];
|
|
443
|
+
if (sibling.structure?.kind === "outline") {
|
|
444
|
+
const siblingLevelValue = sibling.properties[sibling.structure.level.key];
|
|
445
|
+
if ((typeof siblingLevelValue === "number" ? siblingLevelValue : 1) <= level) break;
|
|
446
|
+
}
|
|
447
|
+
const { to: siblingTo } = sibling;
|
|
448
|
+
to = siblingTo;
|
|
449
|
+
}
|
|
450
|
+
return Object.freeze({
|
|
451
|
+
from,
|
|
452
|
+
root,
|
|
453
|
+
to
|
|
454
|
+
});
|
|
455
|
+
};
|
|
456
|
+
const spanWithin = (span, container) => span.root === container.root && span.from >= container.from && span.to <= container.to;
|
|
457
|
+
const composeLogicalGroups = (changes, pairs, before, after) => {
|
|
458
|
+
let result = [...changes];
|
|
459
|
+
const logicalPairs = pairs.filter((pair) => {
|
|
460
|
+
const source = before.nodes[pair.before];
|
|
461
|
+
const target = after.nodes[pair.after];
|
|
462
|
+
return source.structure?.kind === "outline" && target.structure?.kind === "outline" || source.structure?.kind === "grid" && source.structure.role === "row" && target.structure?.kind === "grid" && target.structure.role === "row";
|
|
463
|
+
});
|
|
464
|
+
for (const pair of logicalPairs) {
|
|
465
|
+
const source = before.nodes[pair.before];
|
|
466
|
+
const target = after.nodes[pair.after];
|
|
467
|
+
const sourceSpan = source.structure?.kind === "outline" ? logicalOutlineSpan(before, source) : source.span;
|
|
468
|
+
const targetSpan = target.structure?.kind === "outline" ? logicalOutlineSpan(after, target) : target.span;
|
|
469
|
+
if (!sourceSpan || !targetSpan) continue;
|
|
470
|
+
const indexes = result.flatMap((change, index) => {
|
|
471
|
+
const beforeContained = change.before.length === 0 || change.before.every((span) => spanWithin(span, sourceSpan));
|
|
472
|
+
const afterContained = change.after.length === 0 || change.after.every((span) => spanWithin(span, targetSpan));
|
|
473
|
+
return beforeContained && afterContained ? [index] : [];
|
|
474
|
+
});
|
|
475
|
+
if (indexes.length < 2) continue;
|
|
476
|
+
const ownerIndex = indexes.find((index) => result[index].effects.some(({ kind }) => kind === "placement")) ?? -1;
|
|
477
|
+
if (ownerIndex === -1) continue;
|
|
478
|
+
result = mergeGroups(result, [{
|
|
479
|
+
members: indexes,
|
|
480
|
+
owner: ownerIndex
|
|
481
|
+
}]);
|
|
482
|
+
}
|
|
483
|
+
return Object.freeze(result);
|
|
484
|
+
};
|
|
485
|
+
const setMemberOf = (index, node) => {
|
|
486
|
+
const root = index.roots.get(node.root);
|
|
487
|
+
return root?.structure?.kind === "set" ? root.topLevelIndexes[node.path[0]] ?? null : null;
|
|
488
|
+
};
|
|
489
|
+
const pairSetMembers = (before, after, matchedBefore, matchedAfter) => {
|
|
490
|
+
const result = [];
|
|
491
|
+
for (const [root, beforeRoot] of before.roots) {
|
|
492
|
+
const afterRoot = after.roots.get(root);
|
|
493
|
+
if (beforeRoot.structure?.kind !== "set" || afterRoot?.structure?.kind !== "set") continue;
|
|
494
|
+
const sources = beforeRoot.topLevelIndexes.filter((index) => !matchedBefore.has(index));
|
|
495
|
+
const targets = afterRoot.topLevelIndexes.filter((index) => !matchedAfter.has(index));
|
|
496
|
+
const sameAt = (source, target) => before.nodes[sources[source]].exactHash === after.nodes[targets[target]].exactHash;
|
|
497
|
+
let prefix = 0;
|
|
498
|
+
let suffix = 0;
|
|
499
|
+
while (prefix < Math.min(sources.length, targets.length) && sameAt(prefix, prefix)) prefix += 1;
|
|
500
|
+
while (suffix < Math.min(sources.length, targets.length) - prefix && sameAt(sources.length - 1 - suffix, targets.length - 1 - suffix)) suffix += 1;
|
|
501
|
+
const fromStart = Math.min(sources.length, targets.length) - suffix;
|
|
502
|
+
for (let position = 0; position < fromStart; position += 1) result.push({
|
|
503
|
+
after: targets[position],
|
|
504
|
+
before: sources[position]
|
|
505
|
+
});
|
|
506
|
+
for (let fromEnd = 1; fromEnd <= suffix; fromEnd += 1) result.push({
|
|
507
|
+
after: targets[targets.length - fromEnd],
|
|
508
|
+
before: sources[sources.length - fromEnd]
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
return result;
|
|
512
|
+
};
|
|
513
|
+
const membersHolding = (index, members) => {
|
|
514
|
+
const byRoot = /* @__PURE__ */ new Map();
|
|
515
|
+
for (const member of members) {
|
|
516
|
+
const { root } = index.nodes[member].span;
|
|
517
|
+
const list = byRoot.get(root) ?? [];
|
|
518
|
+
list.push(member);
|
|
519
|
+
byRoot.set(root, list);
|
|
520
|
+
}
|
|
521
|
+
for (const list of byRoot.values()) list.sort((left, right) => index.nodes[left].span.from - index.nodes[right].span.from);
|
|
522
|
+
return (span) => {
|
|
523
|
+
const list = byRoot.get(span.root) ?? [];
|
|
524
|
+
let low = 0;
|
|
525
|
+
let high = list.length;
|
|
526
|
+
while (low < high) {
|
|
527
|
+
const middle = low + high >> 1;
|
|
528
|
+
if (index.nodes[list[middle]].span.from <= span.from) low = middle + 1;
|
|
529
|
+
else high = middle;
|
|
530
|
+
}
|
|
531
|
+
const holding = [];
|
|
532
|
+
for (let at = low - 1; at >= 0 && index.nodes[list[at]].span.to >= span.from; at -= 1) if (spanWithin(span, index.nodes[list[at]].span)) holding.push(list[at]);
|
|
533
|
+
return holding;
|
|
534
|
+
};
|
|
535
|
+
};
|
|
536
|
+
const composeSetMemberGroups = (changes, members, before, after) => {
|
|
537
|
+
const sourcesHolding = membersHolding(before, members.keys());
|
|
538
|
+
const targetsHolding = membersHolding(after, members.values());
|
|
539
|
+
const sourcesOf = /* @__PURE__ */ new Map();
|
|
540
|
+
for (const [source, target] of members) sourcesOf.set(target, [...sourcesOf.get(target) ?? [], source]);
|
|
541
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
542
|
+
changes.forEach((change, index) => {
|
|
543
|
+
const [firstBefore] = change.before;
|
|
544
|
+
const [firstAfter] = change.after;
|
|
545
|
+
const sources = firstBefore ? sourcesHolding(firstBefore) : firstAfter ? targetsHolding(firstAfter).flatMap((target) => sourcesOf.get(target) ?? []) : [...members.keys()];
|
|
546
|
+
for (const source of sources) {
|
|
547
|
+
const target = members.get(source);
|
|
548
|
+
if (target !== void 0 && change.before.every((span) => spanWithin(span, before.nodes[source].span)) && change.after.every((span) => spanWithin(span, after.nodes[target].span))) {
|
|
549
|
+
const bucket = buckets.get(source) ?? [];
|
|
550
|
+
bucket.push(index);
|
|
551
|
+
buckets.set(source, bucket);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
const merges = [...members.keys()].flatMap((source) => {
|
|
556
|
+
const indexes = buckets.get(source) ?? [];
|
|
557
|
+
return indexes.length < 2 ? [] : [{
|
|
558
|
+
members: indexes,
|
|
559
|
+
owner: indexes[0]
|
|
560
|
+
}];
|
|
561
|
+
});
|
|
562
|
+
return merges.length === 0 ? changes : Object.freeze(mergeGroups(changes, merges));
|
|
563
|
+
};
|
|
564
|
+
const matchComparison = async (before, after, comparisonId, options) => {
|
|
565
|
+
const { createdRoots, deletedRoots, lineage, signal } = options;
|
|
566
|
+
const beforeElements = before.nodes.filter(({ kind, root }) => kind === "element" && !deletedRoots.has(root ?? ""));
|
|
567
|
+
const afterElements = after.nodes.filter(({ kind, root }) => kind === "element" && !createdRoots.has(root ?? ""));
|
|
568
|
+
const exactBefore = /* @__PURE__ */ new Map();
|
|
569
|
+
const exactAfter = /* @__PURE__ */ new Map();
|
|
570
|
+
const pairs = [];
|
|
571
|
+
const matchedBefore = /* @__PURE__ */ new Set();
|
|
572
|
+
const matchedAfter = /* @__PURE__ */ new Set();
|
|
573
|
+
const structuralRelations = [];
|
|
574
|
+
const diagnostics = [];
|
|
575
|
+
let ambiguous = false;
|
|
576
|
+
let work = 0;
|
|
577
|
+
let candidateEdges = 0;
|
|
578
|
+
let directWindowDisambiguations = 0;
|
|
579
|
+
let localAlignmentCells = 0;
|
|
580
|
+
const recordPair = (source, target, duplicate, evidence = Object.freeze({
|
|
581
|
+
basis: "exact",
|
|
582
|
+
kind: "inferred"
|
|
583
|
+
})) => {
|
|
584
|
+
pairs.push(Object.freeze({
|
|
585
|
+
after: target.index,
|
|
586
|
+
ambiguous: duplicate,
|
|
587
|
+
before: source.index,
|
|
588
|
+
evidence
|
|
589
|
+
}));
|
|
590
|
+
matchedBefore.add(source.index);
|
|
591
|
+
matchedAfter.add(target.index);
|
|
592
|
+
};
|
|
593
|
+
if (lineage?.kind === "expired") diagnostics.push(Object.freeze({
|
|
594
|
+
code: "expired-lineage",
|
|
595
|
+
message: "Recorded continuity is no longer available; this comparison uses content inference without historical attribution.",
|
|
596
|
+
severity: "warning"
|
|
597
|
+
}));
|
|
598
|
+
else if (lineage?.kind === "complete") {
|
|
599
|
+
const beforeBySpan = new Map(beforeElements.map((node) => [spanKey(node.span), node]));
|
|
600
|
+
const afterBySpan = new Map(afterElements.map((node) => [spanKey(node.span), node]));
|
|
601
|
+
for (const relation of lineage.relations) {
|
|
602
|
+
const sourceNodes = relation.before.map((value) => beforeBySpan.get(spanKey(value)));
|
|
603
|
+
const targetNodes = relation.after.map((value) => afterBySpan.get(spanKey(value)));
|
|
604
|
+
if (!(relation.operationIds.length > 0 && sourceNodes.length > 0 && targetNodes.length > 0 && sourceNodes.every((node) => node !== void 0) && targetNodes.every((node) => node !== void 0) && sourceNodes.every((node) => !matchedBefore.has(node.index)) && targetNodes.every((node) => !matchedAfter.has(node.index)))) {
|
|
605
|
+
diagnostics.push(Object.freeze({
|
|
606
|
+
code: "identity-hint-rejected",
|
|
607
|
+
message: "A recorded correspondence did not bind unique endpoint spans and was ignored.",
|
|
608
|
+
severity: "warning",
|
|
609
|
+
spans: Object.freeze([...relation.before, ...relation.after])
|
|
610
|
+
}));
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
const sources = sourceNodes;
|
|
614
|
+
const targets = targetNodes;
|
|
615
|
+
const evidence = Object.freeze({
|
|
616
|
+
kind: "recorded",
|
|
617
|
+
operationIds: Object.freeze([...relation.operationIds])
|
|
618
|
+
});
|
|
619
|
+
if (sources.length === 1 && targets.length === 1) recordPair(sources[0], targets[0], false, evidence);
|
|
620
|
+
else {
|
|
621
|
+
structuralRelations.push(Object.freeze({
|
|
622
|
+
after: Object.freeze(targets.map(({ index }) => index)),
|
|
623
|
+
ambiguous: false,
|
|
624
|
+
before: Object.freeze(sources.map(({ index }) => index)),
|
|
625
|
+
evidence,
|
|
626
|
+
kind: sources.length === 1 ? "split" : targets.length === 1 ? "join" : "many"
|
|
627
|
+
}));
|
|
628
|
+
sources.forEach(({ index }) => matchedBefore.add(index));
|
|
629
|
+
targets.forEach(({ index }) => matchedAfter.add(index));
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
for (const member of pairSetMembers(before, after, matchedBefore, matchedAfter)) {
|
|
634
|
+
const source = before.nodes[member.before];
|
|
635
|
+
const target = after.nodes[member.after];
|
|
636
|
+
recordPair(source, target, false, Object.freeze({
|
|
637
|
+
basis: source.exactHash === target.exactHash ? "exact" : "structure",
|
|
638
|
+
kind: "inferred"
|
|
639
|
+
}));
|
|
640
|
+
}
|
|
641
|
+
const memberPairs = new Map(pairs.flatMap((pair) => setMemberOf(before, before.nodes[pair.before]) === pair.before && setMemberOf(after, after.nodes[pair.after]) === pair.after ? [[pair.before, pair.after]] : []));
|
|
642
|
+
const beforeScope = (node) => {
|
|
643
|
+
const member = setMemberOf(before, node);
|
|
644
|
+
if (member === null) return null;
|
|
645
|
+
const target = memberPairs.get(member);
|
|
646
|
+
return target === void 0 ? `removed:${member}` : `${target}`;
|
|
647
|
+
};
|
|
648
|
+
const afterScope = (node) => {
|
|
649
|
+
const member = setMemberOf(after, node);
|
|
650
|
+
return member === null ? null : `${member}`;
|
|
651
|
+
};
|
|
652
|
+
const sameScope = (source, target) => beforeScope(source) === afterScope(target);
|
|
653
|
+
const scopedKey = (scope, key) => scope === null ? key : `${scope}\u0000${key}`;
|
|
654
|
+
for (const node of beforeElements) {
|
|
655
|
+
const key = scopedKey(beforeScope(node), node.exactHash);
|
|
656
|
+
const values = exactBefore.get(key) ?? [];
|
|
657
|
+
values.push(node);
|
|
658
|
+
exactBefore.set(key, values);
|
|
659
|
+
}
|
|
660
|
+
for (const node of afterElements) {
|
|
661
|
+
const key = scopedKey(afterScope(node), node.exactHash);
|
|
662
|
+
const values = exactAfter.get(key) ?? [];
|
|
663
|
+
values.push(node);
|
|
664
|
+
exactAfter.set(key, values);
|
|
665
|
+
}
|
|
666
|
+
for (const [hash, beforeBucket] of exactBefore) {
|
|
667
|
+
const afterBucket = exactAfter.get(hash);
|
|
668
|
+
if (!afterBucket) continue;
|
|
669
|
+
if (beforeBucket.length === 1 && afterBucket.length === 1 && beforeBucket[0].canonical === afterBucket[0].canonical && !matchedBefore.has(beforeBucket[0].index) && !matchedAfter.has(afterBucket[0].index)) {
|
|
670
|
+
recordPair(beforeBucket[0], afterBucket[0], false);
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const byCanonicalBefore = Map.groupBy(beforeBucket, ({ canonical }) => canonical);
|
|
674
|
+
const byCanonicalAfter = Map.groupBy(afterBucket, ({ canonical }) => canonical);
|
|
675
|
+
for (const [canonical, sourceNodes] of byCanonicalBefore) {
|
|
676
|
+
const targetNodes = byCanonicalAfter.get(canonical);
|
|
677
|
+
if (!targetNodes) continue;
|
|
678
|
+
const availableSources = sourceNodes.filter(({ index }) => !matchedBefore.has(index));
|
|
679
|
+
const availableTargets = targetNodes.filter(({ index }) => !matchedAfter.has(index));
|
|
680
|
+
const duplicate = availableSources.length > 1 || availableTargets.length > 1;
|
|
681
|
+
if (availableSources.length === 1 && availableTargets.length === 1) {
|
|
682
|
+
recordPair(availableSources[0], availableTargets[0], false);
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
const sortedSources = availableSources.toSorted(compareNodeOrder);
|
|
686
|
+
const sortedTargets = availableTargets.toSorted(compareNodeOrder);
|
|
687
|
+
const targetByPath = new Map(sortedTargets.map((target) => [nodeKey(target), target]));
|
|
688
|
+
const usedTargets = /* @__PURE__ */ new Set();
|
|
689
|
+
const remainingSources = [];
|
|
690
|
+
for (const source of sortedSources) {
|
|
691
|
+
const target = targetByPath.get(nodeKey(source));
|
|
692
|
+
if (target && !usedTargets.has(target.index)) {
|
|
693
|
+
recordPair(source, target, duplicate);
|
|
694
|
+
usedTargets.add(target.index);
|
|
695
|
+
} else remainingSources.push(source);
|
|
696
|
+
}
|
|
697
|
+
const remainingTargets = sortedTargets.filter((target) => !usedTargets.has(target.index));
|
|
698
|
+
for (let index = 0; index < Math.min(remainingSources.length, remainingTargets.length); index += 1) recordPair(remainingSources[index], remainingTargets[index], duplicate);
|
|
699
|
+
ambiguous ||= duplicate && Math.min(availableSources.length, availableTargets.length) > 0;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
let matchedGridParent = true;
|
|
703
|
+
while (matchedGridParent) {
|
|
704
|
+
matchedGridParent = false;
|
|
705
|
+
const pairByBefore = new Map(pairs.map((pair) => [pair.before, pair]));
|
|
706
|
+
const sources = beforeElements.filter((node) => !matchedBefore.has(node.index) && node.structure?.kind === "grid").toSorted((left, right) => right.path.length - left.path.length);
|
|
707
|
+
for (const source of sources) {
|
|
708
|
+
const sourceStructure = source.structure;
|
|
709
|
+
if (sourceStructure?.kind !== "grid") continue;
|
|
710
|
+
const counts = /* @__PURE__ */ new Map();
|
|
711
|
+
for (const childIndex of source.childIndexes) {
|
|
712
|
+
const childPair = pairByBefore.get(childIndex);
|
|
713
|
+
if (!childPair) continue;
|
|
714
|
+
const targetParent = after.nodes[childPair.after].parentIndex;
|
|
715
|
+
if (targetParent !== null) counts.set(targetParent, (counts.get(targetParent) ?? 0) + 1);
|
|
716
|
+
}
|
|
717
|
+
const candidates = [...counts.entries()].filter(([targetIndex, count]) => {
|
|
718
|
+
const target = after.nodes[targetIndex];
|
|
719
|
+
const targetStructure = target.structure;
|
|
720
|
+
const sourceChildren = source.childIndexes.filter((index) => before.nodes[index].kind === "element").length;
|
|
721
|
+
const targetChildren = target.childIndexes.filter((index) => after.nodes[index].kind === "element").length;
|
|
722
|
+
return !matchedAfter.has(targetIndex) && target.type === source.type && targetStructure?.kind === "grid" && targetStructure.role === sourceStructure.role && count * 2 >= Math.min(sourceChildren, targetChildren);
|
|
723
|
+
}).toSorted((left, right) => right[1] - left[1] || compareNodeOrder(after.nodes[left[0]], after.nodes[right[0]]));
|
|
724
|
+
if (!candidates[0] || candidates[0][1] === candidates[1]?.[1]) continue;
|
|
725
|
+
recordPair(source, after.nodes[candidates[0][0]], false, Object.freeze({
|
|
726
|
+
basis: "structure",
|
|
727
|
+
kind: "inferred"
|
|
728
|
+
}));
|
|
729
|
+
matchedGridParent = true;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
for (const [root, beforeRoot] of before.roots) {
|
|
733
|
+
const afterRoot = after.roots.get(root);
|
|
734
|
+
if (!afterRoot) continue;
|
|
735
|
+
const beforeNodes = beforeRoot.topLevelIndexes.filter((index) => before.nodes[index].kind === "element" && !matchedBefore.has(index));
|
|
736
|
+
const afterNodes = afterRoot.topLevelIndexes.filter((index) => after.nodes[index].kind === "element" && !matchedAfter.has(index));
|
|
737
|
+
const targetWindows = /* @__PURE__ */ new Map();
|
|
738
|
+
const targetWindowCounts = /* @__PURE__ */ new Map();
|
|
739
|
+
const sourceWindows = /* @__PURE__ */ new Map();
|
|
740
|
+
const targetPositionByIndex = new Map(afterNodes.map((nodeIndex, position) => [nodeIndex, position]));
|
|
741
|
+
const sourcePositionByIndex = new Map(beforeNodes.map((nodeIndex, position) => [nodeIndex, position]));
|
|
742
|
+
const targetTokenNodes = createTokenNodeIndex(afterNodes, after);
|
|
743
|
+
const sourceTokenNodes = createTokenNodeIndex(beforeNodes, before);
|
|
744
|
+
const targetByPath = new Map(afterNodes.map((index) => [nodeKey(after.nodes[index]), index]));
|
|
745
|
+
const sourceByPath = new Map(beforeNodes.map((index) => [nodeKey(before.nodes[index]), index]));
|
|
746
|
+
const bestDirectTargetScore = (source) => {
|
|
747
|
+
if (directWindowDisambiguations >= MAX_DIRECT_WINDOW_DISAMBIGUATIONS) return 0;
|
|
748
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
749
|
+
const samePath = targetByPath.get(nodeKey(source));
|
|
750
|
+
const sourceTokens = semanticTokens(source.text);
|
|
751
|
+
if (samePath !== void 0) candidates.add(samePath);
|
|
752
|
+
for (const token of sourceTokens) {
|
|
753
|
+
for (const index of targetTokenNodes.get(token) ?? []) {
|
|
754
|
+
candidates.add(index);
|
|
755
|
+
if (candidates.size >= DIRECT_CANDIDATES_PER_NODE) break;
|
|
756
|
+
}
|
|
757
|
+
if (candidates.size >= DIRECT_CANDIDATES_PER_NODE) break;
|
|
758
|
+
}
|
|
759
|
+
localAlignmentCells += candidates.size;
|
|
760
|
+
let best = 0;
|
|
761
|
+
for (const index of candidates) {
|
|
762
|
+
if (directWindowDisambiguations >= MAX_DIRECT_WINDOW_DISAMBIGUATIONS) return 0;
|
|
763
|
+
directWindowDisambiguations += 1;
|
|
764
|
+
const target = after.nodes[index];
|
|
765
|
+
const targetTokens = semanticTokens(target.text);
|
|
766
|
+
if (!matchedAfter.has(index) && candidateScore(source, target, sourceTokens, targetTokens) >= .58) best = Math.max(best, textSimilarityFromTokens(source.text, target.text, sourceTokens, targetTokens));
|
|
767
|
+
}
|
|
768
|
+
return best;
|
|
769
|
+
};
|
|
770
|
+
const bestDirectSourceScore = (target) => {
|
|
771
|
+
if (directWindowDisambiguations >= MAX_DIRECT_WINDOW_DISAMBIGUATIONS) return 0;
|
|
772
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
773
|
+
const samePath = sourceByPath.get(nodeKey(target));
|
|
774
|
+
const targetTokens = semanticTokens(target.text);
|
|
775
|
+
if (samePath !== void 0) candidates.add(samePath);
|
|
776
|
+
for (const token of targetTokens) {
|
|
777
|
+
for (const index of sourceTokenNodes.get(token) ?? []) {
|
|
778
|
+
candidates.add(index);
|
|
779
|
+
if (candidates.size >= DIRECT_CANDIDATES_PER_NODE) break;
|
|
780
|
+
}
|
|
781
|
+
if (candidates.size >= DIRECT_CANDIDATES_PER_NODE) break;
|
|
782
|
+
}
|
|
783
|
+
localAlignmentCells += candidates.size;
|
|
784
|
+
let best = 0;
|
|
785
|
+
for (const index of candidates) {
|
|
786
|
+
if (directWindowDisambiguations >= MAX_DIRECT_WINDOW_DISAMBIGUATIONS) return 0;
|
|
787
|
+
directWindowDisambiguations += 1;
|
|
788
|
+
const source = before.nodes[index];
|
|
789
|
+
const sourceTokens = semanticTokens(source.text);
|
|
790
|
+
if (!matchedBefore.has(index) && candidateScore(source, target, sourceTokens, targetTokens) >= .58) best = Math.max(best, textSimilarityFromTokens(source.text, target.text, sourceTokens, targetTokens));
|
|
791
|
+
}
|
|
792
|
+
return best;
|
|
793
|
+
};
|
|
794
|
+
for (let start = 0; start < afterNodes.length; start += 1) for (let size = 2; size <= MAX_WINDOW; size += 1) {
|
|
795
|
+
const window = afterNodes.slice(start, start + size);
|
|
796
|
+
if (window.length !== size) continue;
|
|
797
|
+
const text = window.map((index) => after.nodes[index].text).join("");
|
|
798
|
+
const values = targetWindows.get(text) ?? [];
|
|
799
|
+
if (values.length < CANDIDATES_PER_NODE) values.push(window);
|
|
800
|
+
targetWindows.set(text, values);
|
|
801
|
+
targetWindowCounts.set(text, (targetWindowCounts.get(text) ?? 0) + 1);
|
|
802
|
+
}
|
|
803
|
+
for (let start = 0; start < beforeNodes.length; start += 1) for (let size = 2; size <= MAX_WINDOW; size += 1) {
|
|
804
|
+
const window = beforeNodes.slice(start, start + size);
|
|
805
|
+
if (window.length !== size) continue;
|
|
806
|
+
const text = window.map((index) => before.nodes[index].text).join("");
|
|
807
|
+
const values = sourceWindows.get(text) ?? [];
|
|
808
|
+
if (values.length < CANDIDATES_PER_NODE) values.push(window);
|
|
809
|
+
sourceWindows.set(text, values);
|
|
810
|
+
}
|
|
811
|
+
for (let start = 0; start < beforeNodes.length; start += 1) for (let size = 2; size <= MAX_WINDOW; size += 1) {
|
|
812
|
+
const window = beforeNodes.slice(start, start + size);
|
|
813
|
+
if (window.length !== size || window.some((index) => matchedBefore.has(index) || before.nodes[index].text.length === 0)) continue;
|
|
814
|
+
const text = window.map((index) => before.nodes[index].text).join("");
|
|
815
|
+
const target = targetWindows.get(text)?.find((candidate) => candidate.every((index) => !matchedAfter.has(index) && after.nodes[index].text.length > 0));
|
|
816
|
+
localAlignmentCells += 1;
|
|
817
|
+
if (!target || text.length === 0) continue;
|
|
818
|
+
structuralRelations.push(Object.freeze({
|
|
819
|
+
after: Object.freeze([...target]),
|
|
820
|
+
ambiguous: (targetWindowCounts.get(text) ?? 0) > 1,
|
|
821
|
+
before: Object.freeze([...window]),
|
|
822
|
+
evidence: Object.freeze({
|
|
823
|
+
basis: "structure",
|
|
824
|
+
kind: "inferred"
|
|
825
|
+
}),
|
|
826
|
+
kind: "many"
|
|
827
|
+
}));
|
|
828
|
+
window.forEach((index) => matchedBefore.add(index));
|
|
829
|
+
target.forEach((index) => matchedAfter.add(index));
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
for (const sourceIndex of beforeNodes) {
|
|
833
|
+
if (matchedBefore.has(sourceIndex)) continue;
|
|
834
|
+
const source = before.nodes[sourceIndex];
|
|
835
|
+
const exactTarget = targetWindows.get(source.text)?.find((window) => window.every((index) => !matchedAfter.has(index) && after.nodes[index].text.length > 0));
|
|
836
|
+
const approximate = exactTarget ? void 0 : boundedMatchingWindow(source.text, afterNodes, targetPositionByIndex, targetTokenNodes, after, matchedAfter);
|
|
837
|
+
const target = exactTarget ?? (approximate?.window && approximate.score > bestDirectTargetScore(source) ? approximate.window : void 0);
|
|
838
|
+
localAlignmentCells += (targetWindows.get(source.text)?.length ?? 0) + (approximate?.work ?? 0);
|
|
839
|
+
if (!target) continue;
|
|
840
|
+
structuralRelations.push(Object.freeze({
|
|
841
|
+
after: Object.freeze(target),
|
|
842
|
+
ambiguous: (targetWindowCounts.get(source.text) ?? 0) > 1,
|
|
843
|
+
before: Object.freeze([sourceIndex]),
|
|
844
|
+
evidence: Object.freeze({
|
|
845
|
+
basis: "structure",
|
|
846
|
+
kind: "inferred"
|
|
847
|
+
}),
|
|
848
|
+
kind: "split"
|
|
849
|
+
}));
|
|
850
|
+
matchedBefore.add(sourceIndex);
|
|
851
|
+
target.forEach((index) => matchedAfter.add(index));
|
|
852
|
+
}
|
|
853
|
+
for (const targetIndex of afterNodes) {
|
|
854
|
+
if (matchedAfter.has(targetIndex)) continue;
|
|
855
|
+
const target = after.nodes[targetIndex];
|
|
856
|
+
const exactSource = sourceWindows.get(target.text)?.find((window) => window.every((index) => !matchedBefore.has(index) && before.nodes[index].text.length > 0));
|
|
857
|
+
const approximate = exactSource ? void 0 : boundedMatchingWindow(target.text, beforeNodes, sourcePositionByIndex, sourceTokenNodes, before, matchedBefore);
|
|
858
|
+
const source = exactSource ?? (approximate?.window && approximate.score > bestDirectSourceScore(target) ? approximate.window : void 0);
|
|
859
|
+
localAlignmentCells += (sourceWindows.get(target.text)?.length ?? 0) + (approximate?.work ?? 0);
|
|
860
|
+
if (!source) continue;
|
|
861
|
+
structuralRelations.push(Object.freeze({
|
|
862
|
+
after: Object.freeze([targetIndex]),
|
|
863
|
+
ambiguous: (sourceWindows.get(target.text)?.length ?? 0) > 1,
|
|
864
|
+
before: Object.freeze(source),
|
|
865
|
+
evidence: Object.freeze({
|
|
866
|
+
basis: "structure",
|
|
867
|
+
kind: "inferred"
|
|
868
|
+
}),
|
|
869
|
+
kind: "join"
|
|
870
|
+
}));
|
|
871
|
+
matchedAfter.add(targetIndex);
|
|
872
|
+
source.forEach((index) => matchedBefore.add(index));
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
await yieldComparisonWork(signal);
|
|
876
|
+
const unmatchedBefore = beforeElements.filter(({ index }) => !matchedBefore.has(index));
|
|
877
|
+
const unmatchedAfter = afterElements.filter(({ index }) => !matchedAfter.has(index));
|
|
878
|
+
const unmatchedAfterByPath = new Map(unmatchedAfter.map((node) => [nodeKey(node), node]));
|
|
879
|
+
const afterTokens = /* @__PURE__ */ new Map();
|
|
880
|
+
const tokenTargets = /* @__PURE__ */ new Map();
|
|
881
|
+
for (const node of unmatchedAfter) {
|
|
882
|
+
const tokens = semanticTokens(node.text);
|
|
883
|
+
const scope = afterScope(node);
|
|
884
|
+
afterTokens.set(node.index, tokens);
|
|
885
|
+
for (const token of tokens) {
|
|
886
|
+
const key = scopedKey(scope, token);
|
|
887
|
+
const values = tokenTargets.get(key) ?? [];
|
|
888
|
+
if (values.length < CANDIDATES_PER_NODE) values.push(node.index);
|
|
889
|
+
tokenTargets.set(key, values);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
const candidates = [];
|
|
893
|
+
let exhausted = false;
|
|
894
|
+
for (const source of unmatchedBefore) {
|
|
895
|
+
const sourceTokens = semanticTokens(source.text);
|
|
896
|
+
const scope = beforeScope(source);
|
|
897
|
+
const targetIndexes = /* @__PURE__ */ new Set();
|
|
898
|
+
const samePath = unmatchedAfterByPath.get(nodeKey(source));
|
|
899
|
+
if (samePath && sameScope(source, samePath)) targetIndexes.add(samePath.index);
|
|
900
|
+
for (const token of sourceTokens) {
|
|
901
|
+
for (const target of tokenTargets.get(scopedKey(scope, token)) ?? []) {
|
|
902
|
+
targetIndexes.add(target);
|
|
903
|
+
if (targetIndexes.size >= CANDIDATES_PER_NODE) break;
|
|
904
|
+
}
|
|
905
|
+
if (targetIndexes.size >= CANDIDATES_PER_NODE) break;
|
|
906
|
+
}
|
|
907
|
+
if (targetIndexes.size === 0 && source.text.length === 0) for (const target of unmatchedAfter) {
|
|
908
|
+
if (target.type === source.type && sameScope(source, target)) targetIndexes.add(target.index);
|
|
909
|
+
if (targetIndexes.size >= CANDIDATES_PER_NODE) break;
|
|
910
|
+
}
|
|
911
|
+
for (const targetIndex of targetIndexes) {
|
|
912
|
+
if (candidateEdges === MAX_CANDIDATE_EDGES) {
|
|
913
|
+
exhausted = true;
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
candidateEdges += 1;
|
|
917
|
+
work += 1;
|
|
918
|
+
const target = after.nodes[targetIndex];
|
|
919
|
+
const score = candidateScore(source, target, sourceTokens, afterTokens.get(targetIndex) ?? /* @__PURE__ */ new Set());
|
|
920
|
+
if (score >= .58) candidates.push({
|
|
921
|
+
after: targetIndex,
|
|
922
|
+
before: source.index,
|
|
923
|
+
score
|
|
924
|
+
});
|
|
925
|
+
if (work % YIELD_INTERVAL === 0) await yieldComparisonWork(signal);
|
|
926
|
+
}
|
|
927
|
+
if (exhausted) break;
|
|
928
|
+
}
|
|
929
|
+
candidates.toSorted((left, right) => right.score - left.score || compareNodeOrder(before.nodes[left.before], before.nodes[right.before]) || compareNodeOrder(after.nodes[left.after], after.nodes[right.after])).forEach((candidate) => {
|
|
930
|
+
if (matchedBefore.has(candidate.before) || matchedAfter.has(candidate.after)) return;
|
|
931
|
+
const pair = Object.freeze({
|
|
932
|
+
after: candidate.after,
|
|
933
|
+
ambiguous: false,
|
|
934
|
+
before: candidate.before,
|
|
935
|
+
evidence: Object.freeze({
|
|
936
|
+
basis: "unique-content",
|
|
937
|
+
kind: "inferred"
|
|
938
|
+
})
|
|
939
|
+
});
|
|
940
|
+
pairs.push(pair);
|
|
941
|
+
matchedBefore.add(pair.before);
|
|
942
|
+
matchedAfter.add(pair.after);
|
|
943
|
+
});
|
|
944
|
+
const relations = [...pairs.map((pair) => Object.freeze({
|
|
945
|
+
after: Object.freeze([pair.after]),
|
|
946
|
+
ambiguous: pair.ambiguous,
|
|
947
|
+
before: Object.freeze([pair.before]),
|
|
948
|
+
evidence: pair.evidence,
|
|
949
|
+
kind: "match"
|
|
950
|
+
})), ...structuralRelations];
|
|
951
|
+
const relatedBefore = new Set(matchedBefore);
|
|
952
|
+
const relatedAfter = new Set(matchedAfter);
|
|
953
|
+
const siblings = (index, node) => (node.parentIndex === null ? index.roots.get(node.root)?.topLevelIndexes ?? [] : index.nodes[node.parentIndex].childIndexes).filter((child) => index.nodes[child].kind === "element");
|
|
954
|
+
const parentPairByBefore = new Map(pairs.map((pair) => [pair.before, pair.after]));
|
|
955
|
+
const sameParentContext = (source, target) => source.root === target.root && (source.parentIndex === null ? target.parentIndex === null : parentPairByBefore.get(source.parentIndex) === target.parentIndex);
|
|
956
|
+
for (const source of beforeElements) {
|
|
957
|
+
if (relatedBefore.has(source.index) || source.text.length === 0) continue;
|
|
958
|
+
const targets = afterElements.filter((target) => !relatedAfter.has(target.index) && sameParentContext(source, target));
|
|
959
|
+
const targetSiblings = targets.length > 0 ? siblings(after, targets[0]) : [];
|
|
960
|
+
for (let start = 0; start < targetSiblings.length; start += 1) for (let size = 2; size <= MAX_WINDOW; size += 1) {
|
|
961
|
+
const window = targetSiblings.slice(start, start + size);
|
|
962
|
+
localAlignmentCells += 1;
|
|
963
|
+
if (window.length !== size || window.some((index) => relatedAfter.has(index))) continue;
|
|
964
|
+
if (window.map((index) => after.nodes[index].text).join("") !== source.text) continue;
|
|
965
|
+
relations.push(Object.freeze({
|
|
966
|
+
after: Object.freeze(window),
|
|
967
|
+
ambiguous: false,
|
|
968
|
+
before: Object.freeze([source.index]),
|
|
969
|
+
evidence: Object.freeze({
|
|
970
|
+
basis: "structure",
|
|
971
|
+
kind: "inferred"
|
|
972
|
+
}),
|
|
973
|
+
kind: "split"
|
|
974
|
+
}));
|
|
975
|
+
relatedBefore.add(source.index);
|
|
976
|
+
window.forEach((index) => relatedAfter.add(index));
|
|
977
|
+
start = targetSiblings.length;
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
for (const target of afterElements) {
|
|
982
|
+
if (relatedAfter.has(target.index) || target.text.length === 0) continue;
|
|
983
|
+
const sources = beforeElements.filter((source) => !relatedBefore.has(source.index) && sameParentContext(source, target));
|
|
984
|
+
const sourceSiblings = sources.length > 0 ? siblings(before, sources[0]) : [];
|
|
985
|
+
for (let start = 0; start < sourceSiblings.length; start += 1) for (let size = 2; size <= MAX_WINDOW; size += 1) {
|
|
986
|
+
const window = sourceSiblings.slice(start, start + size);
|
|
987
|
+
localAlignmentCells += 1;
|
|
988
|
+
if (window.length !== size || window.some((index) => relatedBefore.has(index))) continue;
|
|
989
|
+
if (window.map((index) => before.nodes[index].text).join("") !== target.text) continue;
|
|
990
|
+
relations.push(Object.freeze({
|
|
991
|
+
after: Object.freeze([target.index]),
|
|
992
|
+
ambiguous: false,
|
|
993
|
+
before: Object.freeze(window),
|
|
994
|
+
evidence: Object.freeze({
|
|
995
|
+
basis: "structure",
|
|
996
|
+
kind: "inferred"
|
|
997
|
+
}),
|
|
998
|
+
kind: "join"
|
|
999
|
+
}));
|
|
1000
|
+
relatedAfter.add(target.index);
|
|
1001
|
+
window.forEach((index) => relatedBefore.add(index));
|
|
1002
|
+
start = sourceSiblings.length;
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
const copies = [];
|
|
1007
|
+
const copyTargets = maximalUnmatched(after, relatedAfter);
|
|
1008
|
+
if (copyTargets.length > 0) {
|
|
1009
|
+
const uniqueSourceByCanonical = /* @__PURE__ */ new Map();
|
|
1010
|
+
for (const source of beforeElements) uniqueSourceByCanonical.set(source.canonical, uniqueSourceByCanonical.has(source.canonical) ? null : source);
|
|
1011
|
+
for (const target of copyTargets) {
|
|
1012
|
+
const source = uniqueSourceByCanonical.get(target.canonical);
|
|
1013
|
+
if (source) copies.push(Object.freeze({
|
|
1014
|
+
after: target.index,
|
|
1015
|
+
before: source.index
|
|
1016
|
+
}));
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
if (ambiguous) diagnostics.push(Object.freeze({
|
|
1020
|
+
code: "ambiguous",
|
|
1021
|
+
message: "Repeated indistinguishable content was aligned deterministically without claiming historical identity.",
|
|
1022
|
+
severity: "warning"
|
|
1023
|
+
}));
|
|
1024
|
+
if (exhausted) diagnostics.push(Object.freeze({
|
|
1025
|
+
code: "work-limit",
|
|
1026
|
+
message: "Semantic candidate work reached its deterministic limit; unmatched content remains an exact replacement.",
|
|
1027
|
+
severity: "warning"
|
|
1028
|
+
}));
|
|
1029
|
+
const moved = placementPairs(pairs, before, after);
|
|
1030
|
+
const byBefore = new Map(pairs.map((pair) => [pair.before, pair]));
|
|
1031
|
+
const changes = [];
|
|
1032
|
+
let changeIndex = 0;
|
|
1033
|
+
let effectIndex = 0;
|
|
1034
|
+
let correspondenceIndex = 0;
|
|
1035
|
+
const addChange = (beforeSpans, afterSpans, evidence, buildEffects, kind = "primary") => {
|
|
1036
|
+
const effects = [];
|
|
1037
|
+
const add = (value) => {
|
|
1038
|
+
effects.push(Object.freeze({
|
|
1039
|
+
...value,
|
|
1040
|
+
id: `${comparisonId}:effect:${effectIndex}`
|
|
1041
|
+
}));
|
|
1042
|
+
effectIndex += 1;
|
|
1043
|
+
};
|
|
1044
|
+
buildEffects(add);
|
|
1045
|
+
if (effects.length === 0) return;
|
|
1046
|
+
const correspondence = Object.freeze({
|
|
1047
|
+
after: Object.freeze([...afterSpans]),
|
|
1048
|
+
before: Object.freeze([...beforeSpans]),
|
|
1049
|
+
evidence,
|
|
1050
|
+
id: `${comparisonId}:correspondence:${correspondenceIndex}`,
|
|
1051
|
+
kind
|
|
1052
|
+
});
|
|
1053
|
+
correspondenceIndex += 1;
|
|
1054
|
+
changes.push(Object.freeze({
|
|
1055
|
+
after: correspondence.after,
|
|
1056
|
+
before: correspondence.before,
|
|
1057
|
+
correspondence: Object.freeze([correspondence]),
|
|
1058
|
+
effects: Object.freeze(effects),
|
|
1059
|
+
evidence,
|
|
1060
|
+
id: `${comparisonId}:change:${changeIndex}`,
|
|
1061
|
+
requiredChangeIds: Object.freeze([])
|
|
1062
|
+
}));
|
|
1063
|
+
changeIndex += 1;
|
|
1064
|
+
};
|
|
1065
|
+
for (const relation of relations.toSorted((left, right) => {
|
|
1066
|
+
const leftNode = before.nodes[left.before[0]] ?? after.nodes[left.after[0]];
|
|
1067
|
+
const rightNode = before.nodes[right.before[0]] ?? after.nodes[right.after[0]];
|
|
1068
|
+
return compareNodeOrder(leftNode, rightNode);
|
|
1069
|
+
})) {
|
|
1070
|
+
const beforeSpans = relationSpans(relation.before, before);
|
|
1071
|
+
const afterSpans = relationSpans(relation.after, after);
|
|
1072
|
+
if (relation.kind !== "match") {
|
|
1073
|
+
const sourceNodes = relation.before.map((index) => before.nodes[index]);
|
|
1074
|
+
const targetNodes = relation.after.map((index) => after.nodes[index]);
|
|
1075
|
+
const sourceText = sourceNodes.map(({ text }) => text).join("");
|
|
1076
|
+
const targetText = targetNodes.map(({ text }) => text).join("");
|
|
1077
|
+
const sourceTextRuns = sequenceTextRuns(sourceNodes);
|
|
1078
|
+
const targetTextRuns = sequenceTextRuns(targetNodes);
|
|
1079
|
+
const textPropertiesChanged = stableStringify(sourceTextRuns.map(({ properties, text }) => sourceText === targetText ? {
|
|
1080
|
+
properties,
|
|
1081
|
+
text
|
|
1082
|
+
} : properties)) !== stableStringify(targetTextRuns.map(({ properties, text }) => sourceText === targetText ? {
|
|
1083
|
+
properties,
|
|
1084
|
+
text
|
|
1085
|
+
} : properties));
|
|
1086
|
+
const ownPropertiesChanged = stableStringify(sequenceOwnProperties(sourceNodes)) !== stableStringify(sequenceOwnProperties(targetNodes));
|
|
1087
|
+
const differences = sequenceTextDifferences(sourceNodes, targetNodes, before, after);
|
|
1088
|
+
addChange(beforeSpans, afterSpans, relation.evidence, (add) => {
|
|
1089
|
+
if (relation.kind === "split") add({
|
|
1090
|
+
after: afterSpans,
|
|
1091
|
+
before: beforeSpans,
|
|
1092
|
+
kind: "split",
|
|
1093
|
+
parts: relation.after.length
|
|
1094
|
+
});
|
|
1095
|
+
else if (relation.kind === "join") add({
|
|
1096
|
+
after: afterSpans,
|
|
1097
|
+
before: beforeSpans,
|
|
1098
|
+
kind: "join",
|
|
1099
|
+
parts: relation.before.length
|
|
1100
|
+
});
|
|
1101
|
+
else add({
|
|
1102
|
+
after: afterSpans,
|
|
1103
|
+
before: beforeSpans,
|
|
1104
|
+
kind: "structure"
|
|
1105
|
+
});
|
|
1106
|
+
if (ownPropertiesChanged || textPropertiesChanged) add({
|
|
1107
|
+
after: afterSpans,
|
|
1108
|
+
afterProperties: Object.freeze([...targetNodes.map(({ properties }) => properties), ...targetTextRuns.map(({ properties }) => properties)]),
|
|
1109
|
+
before: beforeSpans,
|
|
1110
|
+
beforeProperties: Object.freeze([...sourceNodes.map(({ properties }) => properties), ...sourceTextRuns.map(({ properties }) => properties)]),
|
|
1111
|
+
kind: "property"
|
|
1112
|
+
});
|
|
1113
|
+
differences.forEach((difference) => add({
|
|
1114
|
+
...difference,
|
|
1115
|
+
kind: "text"
|
|
1116
|
+
}));
|
|
1117
|
+
});
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
const pair = byBefore.get(relation.before[0]);
|
|
1121
|
+
if (!pair) continue;
|
|
1122
|
+
const source = before.nodes[pair.before];
|
|
1123
|
+
const target = after.nodes[pair.after];
|
|
1124
|
+
const ownPlacement = moved.has(pairKey(pair.before, pair.after)) && !hasMovedMatchedAncestor(pair, moved, before, byBefore);
|
|
1125
|
+
if (source.canonical === target.canonical && !ownPlacement) continue;
|
|
1126
|
+
const propertiesChanged = !jsonEqual(source.properties, target.properties);
|
|
1127
|
+
const sourceTextRuns = comparisonTextRuns(source);
|
|
1128
|
+
const targetTextRuns = comparisonTextRuns(target);
|
|
1129
|
+
const textPropertiesChanged = stableStringify(sourceTextRuns.map(({ properties, text }) => source.text === target.text ? {
|
|
1130
|
+
properties,
|
|
1131
|
+
text
|
|
1132
|
+
} : properties)) !== stableStringify(targetTextRuns.map(({ properties, text }) => source.text === target.text ? {
|
|
1133
|
+
properties,
|
|
1134
|
+
text
|
|
1135
|
+
} : properties));
|
|
1136
|
+
const typeChanged = source.type !== target.type;
|
|
1137
|
+
const structureChanged = childOrderChanged(pair, before, after, byBefore);
|
|
1138
|
+
const changedDescendants = changedMatchedElementDescendants(pair, before, after, byBefore);
|
|
1139
|
+
const differences = source.blockContainer && changedDescendants.length > 0 ? [] : textDifferences(source, target, before, after).filter((difference) => !textDifferenceOwnedByDescendant(difference, changedDescendants, before, after));
|
|
1140
|
+
const gridChildrenOwnStructure = structureChanged && source.structure?.kind === "grid";
|
|
1141
|
+
if (!ownPlacement && !propertiesChanged && !textPropertiesChanged && !typeChanged && !structureChanged && differences.length === 0) continue;
|
|
1142
|
+
addChange(beforeSpans, afterSpans, relation.evidence, (add) => {
|
|
1143
|
+
if (ownPlacement) add({
|
|
1144
|
+
after: afterSpans,
|
|
1145
|
+
before: beforeSpans,
|
|
1146
|
+
kind: "placement",
|
|
1147
|
+
sourcePath: source.path,
|
|
1148
|
+
sourceRoot: source.root,
|
|
1149
|
+
targetPath: target.path,
|
|
1150
|
+
targetRoot: target.root
|
|
1151
|
+
});
|
|
1152
|
+
if (propertiesChanged || textPropertiesChanged) add({
|
|
1153
|
+
after: afterSpans,
|
|
1154
|
+
afterProperties: Object.freeze([target.properties, ...targetTextRuns.map(({ properties }) => properties)]),
|
|
1155
|
+
before: beforeSpans,
|
|
1156
|
+
beforeProperties: Object.freeze([source.properties, ...sourceTextRuns.map(({ properties }) => properties)]),
|
|
1157
|
+
kind: "property"
|
|
1158
|
+
});
|
|
1159
|
+
if (typeChanged) add({
|
|
1160
|
+
after: afterSpans,
|
|
1161
|
+
afterType: target.type,
|
|
1162
|
+
before: beforeSpans,
|
|
1163
|
+
beforeType: source.type,
|
|
1164
|
+
kind: "node-type"
|
|
1165
|
+
});
|
|
1166
|
+
if (structureChanged && !gridChildrenOwnStructure) add({
|
|
1167
|
+
after: afterSpans,
|
|
1168
|
+
before: beforeSpans,
|
|
1169
|
+
kind: "structure"
|
|
1170
|
+
});
|
|
1171
|
+
differences.forEach((difference) => add({
|
|
1172
|
+
...difference,
|
|
1173
|
+
kind: "text"
|
|
1174
|
+
}));
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
const unmatchedBeforeNodes = maximalUnmatched(before, relatedBefore);
|
|
1178
|
+
const unmatchedAfterNodes = maximalUnmatched(after, relatedAfter);
|
|
1179
|
+
const beforeWrapperNodes = ancestorsWithMatchedDescendants(before, relatedBefore);
|
|
1180
|
+
const afterWrapperNodes = ancestorsWithMatchedDescendants(after, relatedAfter);
|
|
1181
|
+
const copyByAfter = new Map(copies.map((copy) => [copy.after, copy]));
|
|
1182
|
+
for (const source of unmatchedBeforeNodes) {
|
|
1183
|
+
const beforeSpans = Object.freeze([source.span]);
|
|
1184
|
+
const wrapper = beforeWrapperNodes.has(source.index);
|
|
1185
|
+
addChange(beforeSpans, Object.freeze([]), Object.freeze({
|
|
1186
|
+
basis: wrapper ? "structure" : "replacement",
|
|
1187
|
+
kind: "inferred"
|
|
1188
|
+
}), (add) => add(wrapper ? {
|
|
1189
|
+
action: "remove",
|
|
1190
|
+
after: [],
|
|
1191
|
+
before: beforeSpans,
|
|
1192
|
+
kind: "wrapper",
|
|
1193
|
+
type: source.type
|
|
1194
|
+
} : {
|
|
1195
|
+
after: [],
|
|
1196
|
+
before: beforeSpans,
|
|
1197
|
+
beforeText: blockText(before, source),
|
|
1198
|
+
kind: "delete"
|
|
1199
|
+
}));
|
|
1200
|
+
}
|
|
1201
|
+
for (const target of unmatchedAfterNodes) {
|
|
1202
|
+
const afterSpans = Object.freeze([target.span]);
|
|
1203
|
+
const copy = copyByAfter.get(target.index);
|
|
1204
|
+
const wrapper = afterWrapperNodes.has(target.index);
|
|
1205
|
+
const evidence = Object.freeze({
|
|
1206
|
+
basis: copy ? "unique-content" : wrapper ? "structure" : "replacement",
|
|
1207
|
+
kind: "inferred"
|
|
1208
|
+
});
|
|
1209
|
+
addChange(copy ? Object.freeze([before.nodes[copy.before].span]) : Object.freeze([]), afterSpans, evidence, (add) => add(wrapper ? {
|
|
1210
|
+
action: "add",
|
|
1211
|
+
after: afterSpans,
|
|
1212
|
+
before: [],
|
|
1213
|
+
kind: "wrapper",
|
|
1214
|
+
type: target.type
|
|
1215
|
+
} : {
|
|
1216
|
+
after: afterSpans,
|
|
1217
|
+
afterText: blockText(after, target),
|
|
1218
|
+
before: [],
|
|
1219
|
+
kind: "insert"
|
|
1220
|
+
}), copy ? "copy" : "primary");
|
|
1221
|
+
}
|
|
1222
|
+
for (const root of [...deletedRoots].sort()) {
|
|
1223
|
+
const rootIndex = before.roots.get(root);
|
|
1224
|
+
const beforeSpans = Object.freeze([Object.freeze({
|
|
1225
|
+
from: 0,
|
|
1226
|
+
root,
|
|
1227
|
+
to: rootIndex?.length ?? 0
|
|
1228
|
+
})]);
|
|
1229
|
+
addChange(beforeSpans, Object.freeze([]), Object.freeze({
|
|
1230
|
+
basis: "structure",
|
|
1231
|
+
kind: "inferred"
|
|
1232
|
+
}), (add) => add({
|
|
1233
|
+
after: [],
|
|
1234
|
+
before: beforeSpans,
|
|
1235
|
+
kind: "root-delete",
|
|
1236
|
+
root
|
|
1237
|
+
}));
|
|
1238
|
+
}
|
|
1239
|
+
for (const root of [...createdRoots].sort()) {
|
|
1240
|
+
const rootIndex = after.roots.get(root);
|
|
1241
|
+
const afterSpans = Object.freeze([Object.freeze({
|
|
1242
|
+
from: 0,
|
|
1243
|
+
root,
|
|
1244
|
+
to: rootIndex?.length ?? 0
|
|
1245
|
+
})]);
|
|
1246
|
+
addChange(Object.freeze([]), afterSpans, Object.freeze({
|
|
1247
|
+
basis: "structure",
|
|
1248
|
+
kind: "inferred"
|
|
1249
|
+
}), (add) => add({
|
|
1250
|
+
after: afterSpans,
|
|
1251
|
+
before: [],
|
|
1252
|
+
kind: "root-create",
|
|
1253
|
+
root
|
|
1254
|
+
}));
|
|
1255
|
+
}
|
|
1256
|
+
const beforeNodeBySpan = new Map(beforeElements.map((node) => [spanKey(node.span), node]));
|
|
1257
|
+
const afterNodeBySpan = new Map(afterElements.map((node) => [spanKey(node.span), node]));
|
|
1258
|
+
const unsupportedSpans = uniqueSpans$1(changes.flatMap(({ effects }) => effects.flatMap((effect) => {
|
|
1259
|
+
if (effect.kind !== "structure" && effect.kind !== "wrapper" && effect.kind !== "node-type") return [];
|
|
1260
|
+
return [...effect.before.filter((value) => {
|
|
1261
|
+
const node = beforeNodeBySpan.get(spanKey(value));
|
|
1262
|
+
return node?.blockContainer === true && node.structure === null && setMemberOf(before, node) === null;
|
|
1263
|
+
}), ...effect.after.filter((value) => {
|
|
1264
|
+
const node = afterNodeBySpan.get(spanKey(value));
|
|
1265
|
+
return node?.blockContainer === true && node.structure === null && setMemberOf(after, node) === null;
|
|
1266
|
+
})];
|
|
1267
|
+
})));
|
|
1268
|
+
if (unsupportedSpans.length > 0) diagnostics.push(Object.freeze({
|
|
1269
|
+
code: "unsupported-structure",
|
|
1270
|
+
message: "The schema has no logical structure facet for a changed container; exact tree effects are preserved without higher-level grouping.",
|
|
1271
|
+
severity: "info",
|
|
1272
|
+
spans: unsupportedSpans
|
|
1273
|
+
}));
|
|
1274
|
+
assertComparisonActive(signal);
|
|
1275
|
+
const visibleEquivalent = createdRoots.size === 0 && deletedRoots.size === 0 && beforeElements.length === afterElements.length && pairs.length === beforeElements.length && moved.size === 0 && pairs.every((pair) => {
|
|
1276
|
+
const source = before.nodes[pair.before];
|
|
1277
|
+
const target = after.nodes[pair.after];
|
|
1278
|
+
return source.type === target.type && jsonEqual(source.properties, target.properties) && source.text === target.text && stableStringify(comparisonTextRuns(source).map(({ properties, text }) => ({
|
|
1279
|
+
properties,
|
|
1280
|
+
text
|
|
1281
|
+
}))) === stableStringify(comparisonTextRuns(target).map(({ properties, text }) => ({
|
|
1282
|
+
properties,
|
|
1283
|
+
text
|
|
1284
|
+
})));
|
|
1285
|
+
});
|
|
1286
|
+
return Object.freeze({
|
|
1287
|
+
candidateEdges,
|
|
1288
|
+
changes: composeSetMemberGroups(composeWrapperGroups(composeLogicalGroups(changes, pairs, before, after)), memberPairs, before, after),
|
|
1289
|
+
diagnostics: Object.freeze(diagnostics),
|
|
1290
|
+
localAlignmentCells,
|
|
1291
|
+
visibleEquivalent
|
|
1292
|
+
});
|
|
1293
|
+
};
|
|
1294
|
+
//#endregion
|
|
1295
|
+
//#region src/diff/lib/compare.ts
|
|
1296
|
+
const THREE_WAY_STATE = /* @__PURE__ */ new WeakMap();
|
|
1297
|
+
const allRootSpans = (index) => Object.freeze([...index.roots.values()].map(({ length, name }) => Object.freeze({
|
|
1298
|
+
from: 0,
|
|
1299
|
+
root: name,
|
|
1300
|
+
to: length
|
|
1301
|
+
})));
|
|
1302
|
+
const coarseFallback = (id, before, after) => {
|
|
1303
|
+
const beforeSpans = allRootSpans(before);
|
|
1304
|
+
const afterSpans = allRootSpans(after);
|
|
1305
|
+
const evidence = Object.freeze({
|
|
1306
|
+
basis: "replacement",
|
|
1307
|
+
kind: "inferred"
|
|
1308
|
+
});
|
|
1309
|
+
const effect = Object.freeze({
|
|
1310
|
+
after: afterSpans,
|
|
1311
|
+
before: beforeSpans,
|
|
1312
|
+
id: `${id}:effect:0`,
|
|
1313
|
+
kind: "structure"
|
|
1314
|
+
});
|
|
1315
|
+
return Object.freeze({
|
|
1316
|
+
change: Object.freeze({
|
|
1317
|
+
after: afterSpans,
|
|
1318
|
+
before: beforeSpans,
|
|
1319
|
+
correspondence: Object.freeze([Object.freeze({
|
|
1320
|
+
after: afterSpans,
|
|
1321
|
+
before: beforeSpans,
|
|
1322
|
+
evidence,
|
|
1323
|
+
id: `${id}:correspondence:0`,
|
|
1324
|
+
kind: "primary"
|
|
1325
|
+
})]),
|
|
1326
|
+
effects: Object.freeze([effect]),
|
|
1327
|
+
evidence,
|
|
1328
|
+
id: `${id}:change:0`,
|
|
1329
|
+
requiredChangeIds: Object.freeze([])
|
|
1330
|
+
}),
|
|
1331
|
+
diagnostic: Object.freeze({
|
|
1332
|
+
code: "coarse-replacement",
|
|
1333
|
+
message: "The exact canonical change is available, but semantic grouping fell back to a complete document replacement.",
|
|
1334
|
+
severity: "warning",
|
|
1335
|
+
spans: Object.freeze([...beforeSpans, ...afterSpans])
|
|
1336
|
+
})
|
|
1337
|
+
});
|
|
1338
|
+
};
|
|
1339
|
+
const groupSemanticKey = (group) => comparisonHash({
|
|
1340
|
+
after: group.after,
|
|
1341
|
+
before: group.before,
|
|
1342
|
+
correspondence: group.correspondence.map(({ after, before, evidence, kind }) => ({
|
|
1343
|
+
after,
|
|
1344
|
+
before,
|
|
1345
|
+
evidence,
|
|
1346
|
+
kind
|
|
1347
|
+
})),
|
|
1348
|
+
effects: group.effects.map(({ id: _id, ...effect }) => effect),
|
|
1349
|
+
evidence: group.evidence
|
|
1350
|
+
});
|
|
1351
|
+
const publishThreeWayGroup = (comparisonId, index, group, branches) => {
|
|
1352
|
+
const id = `${comparisonId}:change:${index}`;
|
|
1353
|
+
return Object.freeze({
|
|
1354
|
+
after: group.after,
|
|
1355
|
+
before: group.before,
|
|
1356
|
+
branches: Object.freeze([...branches]),
|
|
1357
|
+
correspondence: Object.freeze(group.correspondence.map((item, correspondenceIndex) => Object.freeze({
|
|
1358
|
+
...item,
|
|
1359
|
+
id: `${id}:correspondence:${correspondenceIndex}`
|
|
1360
|
+
}))),
|
|
1361
|
+
effects: Object.freeze(group.effects.map((effect, effectIndex) => Object.freeze({
|
|
1362
|
+
...effect,
|
|
1363
|
+
id: `${id}:effect:${effectIndex}`
|
|
1364
|
+
}))),
|
|
1365
|
+
evidence: group.evidence,
|
|
1366
|
+
id,
|
|
1367
|
+
requiredChangeIds: Object.freeze([])
|
|
1368
|
+
});
|
|
1369
|
+
};
|
|
1370
|
+
const spansTouch = (left, right) => left.some((a) => right.some((b) => {
|
|
1371
|
+
if (a.root !== b.root) return false;
|
|
1372
|
+
if (a.from === a.to && b.from === b.to) return a.from === b.from;
|
|
1373
|
+
if (a.from === a.to) return b.from <= a.from && a.from <= b.to;
|
|
1374
|
+
if (b.from === b.to) return a.from <= b.from && b.from <= a.to;
|
|
1375
|
+
return Math.max(a.from, b.from) < Math.min(a.to, b.to);
|
|
1376
|
+
}));
|
|
1377
|
+
const propertyKeys = (group) => new Set(group.effects.flatMap((effect) => effect.kind === "property" ? [...effect.beforeProperties, ...effect.afterProperties].flatMap(Object.keys) : []));
|
|
1378
|
+
const groupsConflict = (left, right) => {
|
|
1379
|
+
if (!spansTouch(left.before, right.before)) return false;
|
|
1380
|
+
const leftKinds = new Set(left.effects.map(({ kind }) => kind));
|
|
1381
|
+
const rightKinds = new Set(right.effects.map(({ kind }) => kind));
|
|
1382
|
+
if (leftKinds.size === 1 && leftKinds.has("placement") && [...rightKinds].every((kind) => kind === "text" || kind === "property") || rightKinds.size === 1 && rightKinds.has("placement") && [...leftKinds].every((kind) => kind === "text" || kind === "property")) return false;
|
|
1383
|
+
if ([...leftKinds].every((kind) => kind === "property") && [...rightKinds].every((kind) => kind === "property")) {
|
|
1384
|
+
const rightProperties = propertyKeys(right);
|
|
1385
|
+
return [...propertyKeys(left)].some((key) => rightProperties.has(key));
|
|
1386
|
+
}
|
|
1387
|
+
return true;
|
|
1388
|
+
};
|
|
1389
|
+
const conflictKind = (local, remote, gridSpans) => {
|
|
1390
|
+
const effects = [...local, ...remote].flatMap(({ effects: value }) => value);
|
|
1391
|
+
const kinds = new Set(effects.map(({ kind }) => kind));
|
|
1392
|
+
if (kinds.has("root-create") || kinds.has("root-delete")) return "root";
|
|
1393
|
+
if ([...local, ...remote].some(({ before }) => spansTouch(before, gridSpans))) return "grid";
|
|
1394
|
+
if (kinds.has("delete") && [...kinds].some((kind) => kind !== "delete" && kind !== "structure")) return "delete-edit";
|
|
1395
|
+
if (kinds.has("placement")) return "placement";
|
|
1396
|
+
if (local.every(({ effects: value }) => value.some(({ kind }) => kind === "insert")) && remote.every(({ effects: value }) => value.some(({ kind }) => kind === "insert"))) return "order";
|
|
1397
|
+
return "structure";
|
|
1398
|
+
};
|
|
1399
|
+
const uniqueSpans = (spans) => Object.freeze([...new Map(spans.map((span) => [`${span.root}:${span.from}:${span.to}`, span])).values()]);
|
|
1400
|
+
const buildConflicts = (comparisonId, local, remote, gridSpans) => {
|
|
1401
|
+
const { find, join } = disjointSets(local.length + remote.length);
|
|
1402
|
+
const edges = local.flatMap((localGroup, localIndex) => remote.flatMap((remoteGroup, remoteIndex) => groupsConflict(localGroup, remoteGroup) ? [[localIndex, local.length + remoteIndex]] : []));
|
|
1403
|
+
for (const [left, right] of edges) join(left, right);
|
|
1404
|
+
for (const [offset, branchGroups] of [[0, local], [local.length, remote]]) {
|
|
1405
|
+
const indexById = new Map(branchGroups.map(({ id: groupId }, index) => [groupId, offset + index]));
|
|
1406
|
+
branchGroups.forEach(({ requiredChangeIds }, index) => {
|
|
1407
|
+
for (const requiredId of requiredChangeIds) {
|
|
1408
|
+
const required = indexById.get(requiredId);
|
|
1409
|
+
if (required !== void 0) join(offset + index, required);
|
|
1410
|
+
}
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
const components = [...new Set(edges.map(([left]) => find(left)))].map((root) => ({
|
|
1414
|
+
local: local.filter((_group, index) => find(index) === root),
|
|
1415
|
+
remote: remote.filter((_group, index) => find(local.length + index) === root)
|
|
1416
|
+
}));
|
|
1417
|
+
return Object.freeze(components.map((component, index) => {
|
|
1418
|
+
const localGroups = [...component.local];
|
|
1419
|
+
const remoteGroups = [...component.remote];
|
|
1420
|
+
const localIds = Object.freeze(localGroups.map(({ id }) => id));
|
|
1421
|
+
const remoteIds = Object.freeze(remoteGroups.map(({ id }) => id));
|
|
1422
|
+
const kind = conflictKind(localGroups, remoteGroups, gridSpans);
|
|
1423
|
+
const changeIds = Object.freeze([...localIds, ...remoteIds]);
|
|
1424
|
+
const requiredChangeIds = Object.freeze([...new Set([...localGroups, ...remoteGroups].flatMap(({ requiredChangeIds: ids }) => ids))].filter((id) => !changeIds.includes(id)));
|
|
1425
|
+
return Object.freeze({
|
|
1426
|
+
base: uniqueSpans([...localGroups, ...remoteGroups].flatMap(({ before }) => before)),
|
|
1427
|
+
changeIds,
|
|
1428
|
+
id: `${comparisonId}:conflict:${index}:${comparisonHash({
|
|
1429
|
+
kind,
|
|
1430
|
+
localIds,
|
|
1431
|
+
remoteIds
|
|
1432
|
+
})}`,
|
|
1433
|
+
kind,
|
|
1434
|
+
local: Object.freeze({
|
|
1435
|
+
branch: "local",
|
|
1436
|
+
changeIds: localIds,
|
|
1437
|
+
spans: uniqueSpans(localGroups.flatMap(({ after }) => after))
|
|
1438
|
+
}),
|
|
1439
|
+
remote: Object.freeze({
|
|
1440
|
+
branch: "remote",
|
|
1441
|
+
changeIds: remoteIds,
|
|
1442
|
+
spans: uniqueSpans(remoteGroups.flatMap(({ after }) => after))
|
|
1443
|
+
}),
|
|
1444
|
+
requiredChangeIds
|
|
1445
|
+
});
|
|
1446
|
+
}));
|
|
1447
|
+
};
|
|
1448
|
+
const compareTwoWay = async (input) => {
|
|
1449
|
+
assertComparisonActive(input.signal);
|
|
1450
|
+
const beforeEnvelopeFingerprint = detachComparisonEnvelope(input.before);
|
|
1451
|
+
const afterEnvelopeFingerprint = detachComparisonEnvelope(input.after);
|
|
1452
|
+
const beforeDocument = detachComparisonDocument(input.before, input.schema);
|
|
1453
|
+
const afterDocument = detachComparisonDocument(input.after, input.schema);
|
|
1454
|
+
const before = createComparisonSnapshot(beforeDocument, input.schema, input.projection?.before ?? "accepted", beforeEnvelopeFingerprint);
|
|
1455
|
+
const after = createComparisonSnapshot(afterDocument, input.schema, input.projection?.after ?? "accepted", afterEnvelopeFingerprint);
|
|
1456
|
+
await yieldComparisonWork(input.signal);
|
|
1457
|
+
const id = `comparison:${comparisonHash({
|
|
1458
|
+
after: after.fingerprint,
|
|
1459
|
+
before: before.fingerprint,
|
|
1460
|
+
policy: COMPARISON_POLICY
|
|
1461
|
+
})}`;
|
|
1462
|
+
const beforeIndex = createComparisonIndex(beforeDocument, input.schema);
|
|
1463
|
+
const afterIndex = createComparisonIndex(afterDocument, input.schema);
|
|
1464
|
+
const beforeRoots = beforeDocument.roots ?? {};
|
|
1465
|
+
const afterRoots = afterDocument.roots ?? {};
|
|
1466
|
+
const matched = await matchComparison(beforeIndex, afterIndex, id, {
|
|
1467
|
+
createdRoots: new Set(Object.keys(afterRoots).filter((root) => !Object.hasOwn(beforeRoots, root))),
|
|
1468
|
+
deletedRoots: new Set(Object.keys(beforeRoots).filter((root) => !Object.hasOwn(afterRoots, root))),
|
|
1469
|
+
signal: input.signal
|
|
1470
|
+
});
|
|
1471
|
+
let { changes: matchedChanges, diagnostics } = matched;
|
|
1472
|
+
if (matchedChanges.length === 0 && !matched.visibleEquivalent && !comparisonDocumentsEqual(beforeDocument, afterDocument)) {
|
|
1473
|
+
const fallback = coarseFallback(id, beforeIndex, afterIndex);
|
|
1474
|
+
matchedChanges = Object.freeze([fallback.change]);
|
|
1475
|
+
diagnostics = Object.freeze([...diagnostics, fallback.diagnostic]);
|
|
1476
|
+
}
|
|
1477
|
+
const { change, changes } = planComparison({
|
|
1478
|
+
after: afterDocument,
|
|
1479
|
+
afterIndex,
|
|
1480
|
+
before: beforeDocument,
|
|
1481
|
+
beforeIndex,
|
|
1482
|
+
groups: matchedChanges
|
|
1483
|
+
});
|
|
1484
|
+
if (!comparisonDocumentsEqual(change.apply(beforeDocument), afterDocument)) throw new Error("Comparison change does not reconstruct the target document.");
|
|
1485
|
+
if (!comparisonDocumentsEqual(change.invert(beforeDocument).apply(afterDocument), beforeDocument)) throw new Error("Comparison inverse does not reconstruct the source document.");
|
|
1486
|
+
assertComparisonActive(input.signal);
|
|
1487
|
+
const comparisonId = `${id}:${comparisonHash({
|
|
1488
|
+
change: change.toJSON(),
|
|
1489
|
+
changes,
|
|
1490
|
+
diagnostics
|
|
1491
|
+
})}`;
|
|
1492
|
+
return Object.freeze({
|
|
1493
|
+
after,
|
|
1494
|
+
before,
|
|
1495
|
+
change,
|
|
1496
|
+
changes,
|
|
1497
|
+
diagnostics,
|
|
1498
|
+
id: comparisonId,
|
|
1499
|
+
kind: "two-way",
|
|
1500
|
+
policy: COMPARISON_POLICY
|
|
1501
|
+
});
|
|
1502
|
+
};
|
|
1503
|
+
const compareThreeWay = async (input) => {
|
|
1504
|
+
assertComparisonActive(input.signal);
|
|
1505
|
+
const [local, remote] = await Promise.all([compareTwoWay({
|
|
1506
|
+
after: input.local,
|
|
1507
|
+
before: input.base,
|
|
1508
|
+
schema: input.schema,
|
|
1509
|
+
signal: input.signal
|
|
1510
|
+
}), compareTwoWay({
|
|
1511
|
+
after: input.remote,
|
|
1512
|
+
before: input.base,
|
|
1513
|
+
schema: input.schema,
|
|
1514
|
+
signal: input.signal
|
|
1515
|
+
})]);
|
|
1516
|
+
const base = local.before;
|
|
1517
|
+
const id = `comparison:${comparisonHash({
|
|
1518
|
+
base: base.fingerprint,
|
|
1519
|
+
local: local.after.fingerprint,
|
|
1520
|
+
policy: COMPARISON_POLICY,
|
|
1521
|
+
remote: remote.after.fingerprint
|
|
1522
|
+
})}`;
|
|
1523
|
+
const localIds = /* @__PURE__ */ new Map();
|
|
1524
|
+
const remoteIds = /* @__PURE__ */ new Map();
|
|
1525
|
+
const commonRemoteIds = /* @__PURE__ */ new Set();
|
|
1526
|
+
const remoteByKey = /* @__PURE__ */ new Map();
|
|
1527
|
+
for (const group of remote.changes) {
|
|
1528
|
+
const key = groupSemanticKey(group);
|
|
1529
|
+
const bucket = remoteByKey.get(key) ?? [];
|
|
1530
|
+
bucket.push(group);
|
|
1531
|
+
remoteByKey.set(key, bucket);
|
|
1532
|
+
}
|
|
1533
|
+
const staged = [];
|
|
1534
|
+
for (const group of local.changes) {
|
|
1535
|
+
const matching = remoteByKey.get(groupSemanticKey(group))?.shift();
|
|
1536
|
+
staged.push(Object.freeze({
|
|
1537
|
+
branches: matching ? Object.freeze(["local", "remote"]) : Object.freeze(["local"]),
|
|
1538
|
+
group,
|
|
1539
|
+
localId: group.id,
|
|
1540
|
+
...matching ? { remoteId: matching.id } : {}
|
|
1541
|
+
}));
|
|
1542
|
+
}
|
|
1543
|
+
for (const groups of remoteByKey.values()) for (const group of groups) staged.push(Object.freeze({
|
|
1544
|
+
branches: Object.freeze(["remote"]),
|
|
1545
|
+
group,
|
|
1546
|
+
remoteId: group.id
|
|
1547
|
+
}));
|
|
1548
|
+
const published = staged.map((item, index) => {
|
|
1549
|
+
const group = publishThreeWayGroup(id, index, item.group, item.branches);
|
|
1550
|
+
if (item.localId) localIds.set(group.id, item.localId);
|
|
1551
|
+
if (item.remoteId) {
|
|
1552
|
+
remoteIds.set(group.id, item.remoteId);
|
|
1553
|
+
if (item.localId) commonRemoteIds.add(group.id);
|
|
1554
|
+
}
|
|
1555
|
+
return group;
|
|
1556
|
+
});
|
|
1557
|
+
const localPublicBySource = new Map([...localIds].map(([publishedId, sourceId]) => [sourceId, publishedId]));
|
|
1558
|
+
const remotePublicBySource = new Map([...remoteIds].map(([publishedId, sourceId]) => [sourceId, publishedId]));
|
|
1559
|
+
const changes = Object.freeze(published.map((group, index) => {
|
|
1560
|
+
const source = staged[index];
|
|
1561
|
+
if (!source) throw new Error("Missing three-way comparison source.");
|
|
1562
|
+
const requiredChangeIds = Object.freeze([...new Set([...source.localId ? local.changes.find(({ id: sourceId }) => sourceId === source.localId)?.requiredChangeIds.map((sourceId) => localPublicBySource.get(sourceId)) ?? [] : [], ...source.remoteId ? remote.changes.find(({ id: sourceId }) => sourceId === source.remoteId)?.requiredChangeIds.map((sourceId) => remotePublicBySource.get(sourceId)) ?? [] : []].filter((required) => Boolean(required && required !== group.id)))]);
|
|
1563
|
+
return Object.freeze({
|
|
1564
|
+
...group,
|
|
1565
|
+
requiredChangeIds
|
|
1566
|
+
});
|
|
1567
|
+
}));
|
|
1568
|
+
const localGroups = changes.filter(({ branches }) => branches?.includes("local"));
|
|
1569
|
+
const remoteGroups = changes.filter(({ branches, id: groupId }) => branches?.includes("remote") && !commonRemoteIds.has(groupId));
|
|
1570
|
+
const gridSpans = createComparisonIndex(base.document, input.schema).nodes.flatMap(({ span, structure }) => structure?.kind === "grid" ? [span] : []);
|
|
1571
|
+
const conflicts = buildConflicts(id, localGroups, remoteGroups, gridSpans);
|
|
1572
|
+
const diagnostics = Object.freeze([
|
|
1573
|
+
...local.diagnostics,
|
|
1574
|
+
...remote.diagnostics,
|
|
1575
|
+
...conflicts.length > 0 ? [Object.freeze({
|
|
1576
|
+
code: "ambiguous",
|
|
1577
|
+
message: "Concurrent branch contributions require explicit conflict resolution.",
|
|
1578
|
+
severity: "warning",
|
|
1579
|
+
spans: uniqueSpans(conflicts.flatMap(({ base: spans }) => spans))
|
|
1580
|
+
})] : []
|
|
1581
|
+
]);
|
|
1582
|
+
const comparisonId = `${id}:${comparisonHash({
|
|
1583
|
+
changes,
|
|
1584
|
+
conflicts,
|
|
1585
|
+
diagnostics
|
|
1586
|
+
})}`;
|
|
1587
|
+
const comparison = Object.freeze({
|
|
1588
|
+
base,
|
|
1589
|
+
changes,
|
|
1590
|
+
conflicts,
|
|
1591
|
+
diagnostics,
|
|
1592
|
+
id: comparisonId,
|
|
1593
|
+
kind: "three-way",
|
|
1594
|
+
local: local.after,
|
|
1595
|
+
policy: COMPARISON_POLICY,
|
|
1596
|
+
remote: remote.after
|
|
1597
|
+
});
|
|
1598
|
+
THREE_WAY_STATE.set(comparison, Object.freeze({
|
|
1599
|
+
local,
|
|
1600
|
+
localIds,
|
|
1601
|
+
remote,
|
|
1602
|
+
remoteIds,
|
|
1603
|
+
schema: input.schema
|
|
1604
|
+
}));
|
|
1605
|
+
return comparison;
|
|
1606
|
+
};
|
|
1607
|
+
function compare(input) {
|
|
1608
|
+
return "base" in input ? compareThreeWay(input) : compareTwoWay(input);
|
|
1609
|
+
}
|
|
1610
|
+
const invalidResolution = (message) => Object.freeze({
|
|
1611
|
+
diagnostics: Object.freeze([Object.freeze({
|
|
1612
|
+
code: "invalid-resolution",
|
|
1613
|
+
message,
|
|
1614
|
+
severity: "warning"
|
|
1615
|
+
})]),
|
|
1616
|
+
status: "invalid"
|
|
1617
|
+
});
|
|
1618
|
+
const annotateResolvedComparison = (comparison, branches) => {
|
|
1619
|
+
if (comparison.changes.length === 0 || branches.length === 0) return comparison;
|
|
1620
|
+
const changes = Object.freeze(comparison.changes.map((group) => Object.freeze({
|
|
1621
|
+
...group,
|
|
1622
|
+
branches: Object.freeze([...branches])
|
|
1623
|
+
})));
|
|
1624
|
+
const prefix = `comparison:${comparisonHash({
|
|
1625
|
+
after: comparison.after.fingerprint,
|
|
1626
|
+
before: comparison.before.fingerprint,
|
|
1627
|
+
policy: comparison.policy
|
|
1628
|
+
})}`;
|
|
1629
|
+
return Object.freeze({
|
|
1630
|
+
...comparison,
|
|
1631
|
+
changes,
|
|
1632
|
+
id: `${prefix}:${comparisonHash({
|
|
1633
|
+
change: comparison.change.toJSON(),
|
|
1634
|
+
changes,
|
|
1635
|
+
diagnostics: comparison.diagnostics
|
|
1636
|
+
})}`
|
|
1637
|
+
});
|
|
1638
|
+
};
|
|
1639
|
+
const restoreBaselineSnapshot = (comparison, before) => {
|
|
1640
|
+
const prefix = `comparison:${comparisonHash({
|
|
1641
|
+
after: comparison.after.fingerprint,
|
|
1642
|
+
before: before.fingerprint,
|
|
1643
|
+
policy: comparison.policy
|
|
1644
|
+
})}`;
|
|
1645
|
+
return Object.freeze({
|
|
1646
|
+
...comparison,
|
|
1647
|
+
before,
|
|
1648
|
+
id: `${prefix}:${comparisonHash({
|
|
1649
|
+
change: comparison.change.toJSON(),
|
|
1650
|
+
changes: comparison.changes,
|
|
1651
|
+
diagnostics: comparison.diagnostics
|
|
1652
|
+
})}`
|
|
1653
|
+
});
|
|
1654
|
+
};
|
|
1655
|
+
/** Resolve one published three-way comparison without rematching its inputs. */
|
|
1656
|
+
async function resolveComparison(input) {
|
|
1657
|
+
assertComparisonActive(input.signal);
|
|
1658
|
+
const state = THREE_WAY_STATE.get(input.comparison);
|
|
1659
|
+
if (!state) return invalidResolution("The comparison was not created by this resolver.");
|
|
1660
|
+
const resolutions = input.resolutions ?? [];
|
|
1661
|
+
const byConflict = /* @__PURE__ */ new Map();
|
|
1662
|
+
for (const resolution of resolutions) {
|
|
1663
|
+
if (resolution.comparisonId !== input.comparison.id || byConflict.has(resolution.conflictId) || !input.comparison.conflicts.some(({ id }) => id === resolution.conflictId)) return invalidResolution("A resolution has an unknown, duplicate, or stale comparison identity.");
|
|
1664
|
+
byConflict.set(resolution.conflictId, resolution);
|
|
1665
|
+
}
|
|
1666
|
+
const unresolved = input.comparison.conflicts.filter(({ id }) => !byConflict.has(id));
|
|
1667
|
+
if (unresolved.length > 0) return Object.freeze({
|
|
1668
|
+
conflicts: Object.freeze([...unresolved]),
|
|
1669
|
+
status: "unresolved"
|
|
1670
|
+
});
|
|
1671
|
+
const customChoices = resolutions.filter(({ choice }) => typeof choice === "object");
|
|
1672
|
+
if (customChoices.length > 0) {
|
|
1673
|
+
if (customChoices.length !== resolutions.length || customChoices.length !== input.comparison.conflicts.length) return invalidResolution("Custom resolution documents must resolve every conflict together.");
|
|
1674
|
+
let target;
|
|
1675
|
+
try {
|
|
1676
|
+
const custom = customChoices[0];
|
|
1677
|
+
if (!custom) return invalidResolution("A custom resolution target is missing.");
|
|
1678
|
+
target = detachComparisonDocument(custom.choice.document, state.schema);
|
|
1679
|
+
if (customChoices.some(({ choice }) => {
|
|
1680
|
+
return !comparisonDocumentsEqual(detachComparisonDocument(choice.document, state.schema), target);
|
|
1681
|
+
})) return invalidResolution("Custom resolutions must name one identical target document.");
|
|
1682
|
+
} catch {
|
|
1683
|
+
return invalidResolution("A custom resolution document does not satisfy the comparison schema.");
|
|
1684
|
+
}
|
|
1685
|
+
const baseline = input.comparison[input.baseline];
|
|
1686
|
+
const comparison = restoreBaselineSnapshot(await compareTwoWay({
|
|
1687
|
+
after: target,
|
|
1688
|
+
before: baseline.document,
|
|
1689
|
+
schema: state.schema,
|
|
1690
|
+
signal: input.signal
|
|
1691
|
+
}), baseline);
|
|
1692
|
+
return Object.freeze({
|
|
1693
|
+
comparison,
|
|
1694
|
+
status: "resolved"
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
const excludedLocal = /* @__PURE__ */ new Set();
|
|
1698
|
+
const excludedRemote = /* @__PURE__ */ new Set();
|
|
1699
|
+
for (const conflict of input.comparison.conflicts) {
|
|
1700
|
+
const choice = byConflict.get(conflict.id)?.choice;
|
|
1701
|
+
if (choice === "local") for (const groupId of conflict.remote.changeIds) excludedRemote.add(groupId);
|
|
1702
|
+
else if (choice === "remote") for (const groupId of conflict.local.changeIds) excludedLocal.add(groupId);
|
|
1703
|
+
}
|
|
1704
|
+
const localSelected = [...state.localIds.keys()].filter((groupId) => !excludedLocal.has(groupId));
|
|
1705
|
+
const sourcesOf = (ids, groupIds) => [...groupIds].flatMap((groupId) => {
|
|
1706
|
+
const sourceId = ids.get(groupId);
|
|
1707
|
+
return sourceId ? [sourceId] : [];
|
|
1708
|
+
});
|
|
1709
|
+
const leftOut = new Set(sourcesOf(state.remoteIds, localSelected));
|
|
1710
|
+
const branch = (comparison, ids, selected, excluded, met) => {
|
|
1711
|
+
const plan = comparisonPlanOf(comparison, state.schema);
|
|
1712
|
+
if (!plan) return null;
|
|
1713
|
+
const closed = closeOverRequired(comparison.changes.map((group) => ({
|
|
1714
|
+
...group,
|
|
1715
|
+
requiredChangeIds: group.requiredChangeIds.filter((id) => !met.has(id))
|
|
1716
|
+
})), sourcesOf(ids, selected));
|
|
1717
|
+
const excludedSources = new Set(sourcesOf(ids, excluded));
|
|
1718
|
+
const all = closed.size === comparison.changes.length;
|
|
1719
|
+
if ([...closed].some((id) => excludedSources.has(id)) || plan.windows.some(({ owners }) => owners.some((id) => closed.has(id)) && owners.some((id) => met.has(id))) || !all && !plan.partitioned) return null;
|
|
1720
|
+
return {
|
|
1721
|
+
change: plan.select(all ? "all" : closed),
|
|
1722
|
+
size: closed.size
|
|
1723
|
+
};
|
|
1724
|
+
};
|
|
1725
|
+
const local = branch(state.local, state.localIds, localSelected, excludedLocal, /* @__PURE__ */ new Set());
|
|
1726
|
+
const remote = branch(state.remote, state.remoteIds, [...state.remoteIds.keys()].filter((groupId) => !excludedRemote.has(groupId) && !leftOut.has(state.remoteIds.get(groupId) ?? "")), excludedRemote, leftOut);
|
|
1727
|
+
if (!local || !remote) return invalidResolution("The selected branch contributions cannot be separated into one exact change.");
|
|
1728
|
+
let target;
|
|
1729
|
+
try {
|
|
1730
|
+
target = detachComparisonDocument(DocumentChange.transform(local.change, remote.change, input.comparison.base.document).b.apply(local.change.apply(input.comparison.base.document)), state.schema);
|
|
1731
|
+
} catch {
|
|
1732
|
+
return invalidResolution("The selected branch contributions do not form one schema-valid document.");
|
|
1733
|
+
}
|
|
1734
|
+
const baseline = input.comparison[input.baseline];
|
|
1735
|
+
const compared = restoreBaselineSnapshot(await compareTwoWay({
|
|
1736
|
+
after: target,
|
|
1737
|
+
before: baseline.document,
|
|
1738
|
+
schema: state.schema,
|
|
1739
|
+
signal: input.signal
|
|
1740
|
+
}), baseline);
|
|
1741
|
+
const branches = Object.freeze([...local.size > 0 ? ["local"] : [], ...remote.size > 0 ? ["remote"] : []]);
|
|
1742
|
+
return Object.freeze({
|
|
1743
|
+
comparison: annotateResolvedComparison(compared, branches),
|
|
1744
|
+
status: "resolved"
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
//#endregion
|
|
2
1748
|
export { compare, resolveComparison };
|