@notectl/core 2.3.6 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/AlignmentPlugin-Cp7HYGaH.mjs +2 -0
- package/dist/chunks/AlignmentPlugin-Cp7HYGaH.mjs.map +1 -0
- package/dist/chunks/{AttrRegistry-CtNhf2EF.mjs → AttrRegistry-Di936wMv.mjs} +2 -2
- package/dist/chunks/{AttrRegistry-CtNhf2EF.mjs.map → AttrRegistry-Di936wMv.mjs.map} +1 -1
- package/dist/chunks/{AttributedMarkCommands-B3MQdob_.mjs → AttributedMarkCommands-DKHuhZA7.mjs} +2 -2
- package/dist/chunks/{AttributedMarkCommands-B3MQdob_.mjs.map → AttributedMarkCommands-DKHuhZA7.mjs.map} +1 -1
- package/dist/chunks/BidiIsolationPlugin-GWukKdgJ.mjs +2 -0
- package/dist/chunks/{BidiIsolationPlugin-cOLlL3Y9.mjs.map → BidiIsolationPlugin-GWukKdgJ.mjs.map} +1 -1
- package/dist/chunks/BlockAlignment-BqyBQ4uV.mjs +2 -0
- package/dist/chunks/BlockAlignment-BqyBQ4uV.mjs.map +1 -0
- package/dist/chunks/{BlockInsertion-O5pAFKid.mjs → BlockInsertion-CxKdCKJd.mjs} +2 -2
- package/dist/chunks/{BlockInsertion-O5pAFKid.mjs.map → BlockInsertion-CxKdCKJd.mjs.map} +1 -1
- package/dist/chunks/BlockquotePlugin-CSL_7Yit.mjs +2 -0
- package/dist/chunks/BlockquotePlugin-CSL_7Yit.mjs.map +1 -0
- package/dist/chunks/CSSValueEquivalence-DeyUKPQ7.mjs +2 -0
- package/dist/chunks/CSSValueEquivalence-DeyUKPQ7.mjs.map +1 -0
- package/dist/chunks/{CaretNavigationPlugin-DEZU09LJ.mjs → CaretNavigationPlugin-BxWjR7SN.mjs} +2 -2
- package/dist/chunks/{CaretNavigationPlugin-DEZU09LJ.mjs.map → CaretNavigationPlugin-BxWjR7SN.mjs.map} +1 -1
- package/dist/chunks/CodeBlockPlugin-BIrkK4ER.mjs +2 -0
- package/dist/chunks/{CodeBlockPlugin-BandNM3t.mjs.map → CodeBlockPlugin-BIrkK4ER.mjs.map} +1 -1
- package/dist/chunks/{ColorGrid-D0vLHsG6.mjs → ColorGrid-DAs0--ty.mjs} +2 -2
- package/dist/chunks/{ColorGrid-D0vLHsG6.mjs.map → ColorGrid-DAs0--ty.mjs.map} +1 -1
- package/dist/chunks/ColorPickerPopup-B6340f3p.mjs +2 -0
- package/dist/chunks/{ColorPickerPopup-_C5JZhki.mjs.map → ColorPickerPopup-B6340f3p.mjs.map} +1 -1
- package/dist/chunks/{ColorValidation-B9d_umnf.mjs → ColorValidation-ZBKZ_gTr.mjs} +2 -2
- package/dist/chunks/ColorValidation-ZBKZ_gTr.mjs.map +1 -0
- package/dist/chunks/Commands-DBBCAYBn.mjs +2 -0
- package/dist/chunks/Commands-DBBCAYBn.mjs.map +1 -0
- package/dist/chunks/{ContentModel-Bzmzeqwg.mjs → ContentModel-BLC3Tez8.mjs} +2 -2
- package/dist/chunks/{ContentModel-Bzmzeqwg.mjs.map → ContentModel-BLC3Tez8.mjs.map} +1 -1
- package/dist/chunks/{CursorMarks-dx51OGBf.mjs → CursorMarks-CqHLzGNI.mjs} +2 -2
- package/dist/chunks/{CursorMarks-dx51OGBf.mjs.map → CursorMarks-CqHLzGNI.mjs.map} +1 -1
- package/dist/chunks/{Decoration-BwhoA4MU.mjs → Decoration-BoFcdSXk.mjs} +2 -2
- package/dist/chunks/{Decoration-BwhoA4MU.mjs.map → Decoration-BoFcdSXk.mjs.map} +1 -1
- package/dist/chunks/{DirectionDetection-ZrkMhyaL.mjs → DirectionDetection-a-1iksmh.mjs} +2 -2
- package/dist/chunks/{DirectionDetection-ZrkMhyaL.mjs.map → DirectionDetection-a-1iksmh.mjs.map} +1 -1
- package/dist/chunks/{Document-D_2cIBJG.mjs → Document-ssR6hBzG.mjs} +2 -2
- package/dist/chunks/{Document-D_2cIBJG.mjs.map → Document-ssR6hBzG.mjs.map} +1 -1
- package/dist/chunks/DocumentParser-BKUrtgw1.mjs +2 -0
- package/dist/chunks/DocumentParser-BKUrtgw1.mjs.map +1 -0
- package/dist/chunks/FontPlugin-BcXNFqqO.mjs +2 -0
- package/dist/chunks/FontPlugin-BcXNFqqO.mjs.map +1 -0
- package/dist/chunks/FontSizePlugin-BQ9Aj8cT.mjs +2 -0
- package/dist/chunks/FontSizePlugin-BQ9Aj8cT.mjs.map +1 -0
- package/dist/chunks/FormulaPlugin-Bw_sO_lq.mjs +2 -0
- package/dist/chunks/FormulaPlugin-Bw_sO_lq.mjs.map +1 -0
- package/dist/chunks/GapCursorPlugin-QDGwnaRR.mjs +2 -0
- package/dist/chunks/GapCursorPlugin-QDGwnaRR.mjs.map +1 -0
- package/dist/chunks/HTMLUtils-DTpsjZyK.mjs +2 -0
- package/dist/chunks/HTMLUtils-DTpsjZyK.mjs.map +1 -0
- package/dist/chunks/{HardBreakPlugin-CC4rntSX.mjs → HardBreakPlugin-svNnJ9Xj.mjs} +2 -2
- package/dist/chunks/{HardBreakPlugin-CC4rntSX.mjs.map → HardBreakPlugin-svNnJ9Xj.mjs.map} +1 -1
- package/dist/chunks/HeadingPlugin-B7EfynaH.mjs +2 -0
- package/dist/chunks/HeadingPlugin-B7EfynaH.mjs.map +1 -0
- package/dist/chunks/HighlightPlugin-LdO0INtJ.mjs +2 -0
- package/dist/chunks/HighlightPlugin-LdO0INtJ.mjs.map +1 -0
- package/dist/chunks/HorizontalRulePlugin-CQ5NT2Mo.mjs +2 -0
- package/dist/chunks/{HorizontalRulePlugin-CxmUMM34.mjs.map → HorizontalRulePlugin-CQ5NT2Mo.mjs.map} +1 -1
- package/dist/chunks/ImagePlugin-BzLvPXGo.mjs +2 -0
- package/dist/chunks/ImagePlugin-BzLvPXGo.mjs.map +1 -0
- package/dist/chunks/InlineCodePlugin-Bu9-rE4B.mjs +2 -0
- package/dist/chunks/InlineCodePlugin-Bu9-rE4B.mjs.map +1 -0
- package/dist/chunks/InlineStyleMarkSpec-BhfGgfH9.mjs +2 -0
- package/dist/chunks/InlineStyleMarkSpec-BhfGgfH9.mjs.map +1 -0
- package/dist/chunks/{LinkPlugin-BwXDGHPe.mjs → LinkPlugin-BuzrXo2c.mjs} +2 -2
- package/dist/chunks/{LinkPlugin-BwXDGHPe.mjs.map → LinkPlugin-BuzrXo2c.mjs.map} +1 -1
- package/dist/chunks/ListPlugin-DTgpvBEt.mjs +2 -0
- package/dist/chunks/{ListPlugin-DSFPSWQC.mjs.map → ListPlugin-DTgpvBEt.mjs.map} +1 -1
- package/dist/chunks/MarkCommands-C0ps9h0z.mjs +2 -0
- package/dist/chunks/MarkCommands-C0ps9h0z.mjs.map +1 -0
- package/dist/chunks/MarkdownHTMLRegistry-BunUDiza.mjs +2 -0
- package/dist/chunks/{MarkdownHTMLRegistry-CISsC0lH.mjs.map → MarkdownHTMLRegistry-BunUDiza.mjs.map} +1 -1
- package/dist/chunks/{MarkdownParser-D1d9zB0R.mjs → MarkdownParser-CvYOvU3d.mjs} +2 -2
- package/dist/chunks/{MarkdownParser-D1d9zB0R.mjs.map → MarkdownParser-CvYOvU3d.mjs.map} +1 -1
- package/dist/chunks/MarkdownSerializer-CdUBWWGI.mjs +2 -0
- package/dist/chunks/MarkdownSerializer-CdUBWWGI.mjs.map +1 -0
- package/dist/chunks/NavigationQueries-CaKfccu7.mjs +2 -0
- package/dist/chunks/NavigationQueries-CaKfccu7.mjs.map +1 -0
- package/dist/chunks/NodeResolver-F4RtpoEd.mjs +2 -0
- package/dist/chunks/NodeResolver-F4RtpoEd.mjs.map +1 -0
- package/dist/chunks/{NodeSelectionCommands-DK3iEh18.mjs → NodeSelectionCommands-B0Sb4ux4.mjs} +2 -2
- package/dist/chunks/{NodeSelectionCommands-DK3iEh18.mjs.map → NodeSelectionCommands-B0Sb4ux4.mjs.map} +1 -1
- package/dist/chunks/PluginHelpers-B3gk3VB3.mjs +2 -0
- package/dist/chunks/{PluginHelpers-WG1Lzzh3.mjs.map → PluginHelpers-B3gk3VB3.mjs.map} +1 -1
- package/dist/chunks/{PrintPlugin-BQ7LWbEB.mjs → PrintPlugin-BxNlFk2c.mjs} +2 -2
- package/dist/chunks/{PrintPlugin-BQ7LWbEB.mjs.map → PrintPlugin-BxNlFk2c.mjs.map} +1 -1
- package/dist/chunks/{RangeIterator-DDOxTQIf.mjs → RangeIterator-sJ_c9MNr.mjs} +2 -2
- package/dist/chunks/{RangeIterator-DDOxTQIf.mjs.map → RangeIterator-sJ_c9MNr.mjs.map} +1 -1
- package/dist/chunks/Schema-BSM4YLNT.mjs +2 -0
- package/dist/chunks/Schema-BSM4YLNT.mjs.map +1 -0
- package/dist/chunks/SchemaRegistry-Cs7rxafF.mjs +2 -0
- package/dist/chunks/SchemaRegistry-Cs7rxafF.mjs.map +1 -0
- package/dist/chunks/SelectionSync-BkjCwGp-.mjs +2 -0
- package/dist/chunks/SelectionSync-BkjCwGp-.mjs.map +1 -0
- package/dist/chunks/{SelectionTransactions-DNCzsl_b.mjs → SelectionTransactions-mQ1NfMEg.mjs} +2 -2
- package/dist/chunks/{SelectionTransactions-DNCzsl_b.mjs.map → SelectionTransactions-mQ1NfMEg.mjs.map} +1 -1
- package/dist/chunks/SimpleMark-D6vz3Nfd.mjs +2 -0
- package/dist/chunks/{SimpleMark-CTDtEIMV.mjs.map → SimpleMark-D6vz3Nfd.mjs.map} +1 -1
- package/dist/chunks/{SmartPastePlugin-CjExbE9Q.mjs → SmartPastePlugin-C3SVKkWK.mjs} +2 -2
- package/dist/chunks/{SmartPastePlugin-CjExbE9Q.mjs.map → SmartPastePlugin-C3SVKkWK.mjs.map} +1 -1
- package/dist/chunks/{StrikethroughPlugin-d-EW2YYx.mjs → StrikethroughPlugin-v-VJZzUZ.mjs} +2 -2
- package/dist/chunks/{StrikethroughPlugin-d-EW2YYx.mjs.map → StrikethroughPlugin-v-VJZzUZ.mjs.map} +1 -1
- package/dist/chunks/StyleClassNames-BsAx7k5T.mjs +2 -0
- package/dist/chunks/StyleClassNames-BsAx7k5T.mjs.map +1 -0
- package/dist/chunks/{SuperSubPlugin-C-kvFQyx.mjs → SuperSubPlugin-x1iPnZyt.mjs} +2 -2
- package/dist/chunks/{SuperSubPlugin-C-kvFQyx.mjs.map → SuperSubPlugin-x1iPnZyt.mjs.map} +1 -1
- package/dist/chunks/TableDimensions-BSEOEox2.mjs +2 -0
- package/dist/chunks/TableDimensions-BSEOEox2.mjs.map +1 -0
- package/dist/chunks/TablePlugin-WPwp902E.mjs +2 -0
- package/dist/chunks/TablePlugin-WPwp902E.mjs.map +1 -0
- package/dist/chunks/TextColorPlugin-Bnl9of9E.mjs +2 -0
- package/dist/chunks/TextColorPlugin-Bnl9of9E.mjs.map +1 -0
- package/dist/chunks/{TextDirectionAutoPlugin-LVDkKdDX.mjs → TextDirectionAutoPlugin-DOH5cfyy.mjs} +2 -2
- package/dist/chunks/{TextDirectionAutoPlugin-LVDkKdDX.mjs.map → TextDirectionAutoPlugin-DOH5cfyy.mjs.map} +1 -1
- package/dist/chunks/{TextDirectionPlugin-CtGwof7i.mjs → TextDirectionPlugin-JwlR-R-b.mjs} +2 -2
- package/dist/chunks/{TextDirectionPlugin-CtGwof7i.mjs.map → TextDirectionPlugin-JwlR-R-b.mjs.map} +1 -1
- package/dist/chunks/TextDirectionService-BcX07mw2.mjs +2 -0
- package/dist/chunks/{TextDirectionService-OFOU6r_s.mjs.map → TextDirectionService-BcX07mw2.mjs.map} +1 -1
- package/dist/chunks/{TextFormattingPlugin-DlS0SeW7.mjs → TextFormattingPlugin-Kc_UNoOz.mjs} +2 -2
- package/dist/chunks/{TextFormattingPlugin-DlS0SeW7.mjs.map → TextFormattingPlugin-Kc_UNoOz.mjs.map} +1 -1
- package/dist/chunks/ToolbarPlugin-DmVI7MN9.mjs +2 -0
- package/dist/chunks/ToolbarPlugin-DmVI7MN9.mjs.map +1 -0
- package/dist/chunks/VideoPlugin-D3zGQ6QV.mjs +2 -0
- package/dist/chunks/VideoPlugin-D3zGQ6QV.mjs.map +1 -0
- package/dist/chunks/color-picker-D6HrTsDM.mjs +2 -0
- package/dist/chunks/color-picker-D6HrTsDM.mjs.map +1 -0
- package/dist/chunks/full-BiQ93ERr.mjs +2 -0
- package/dist/chunks/{full-Cshz7aTP.mjs.map → full-BiQ93ERr.mjs.map} +1 -1
- package/dist/chunks/minimal-DO7LiFTa.mjs +2 -0
- package/dist/chunks/{minimal-7XqMY9kC.mjs.map → minimal-DO7LiFTa.mjs.map} +1 -1
- package/dist/chunks/register-Cb1YTAN4.mjs +3 -0
- package/dist/chunks/register-Cb1YTAN4.mjs.map +1 -0
- package/dist/commands/Commands.d.ts.map +1 -1
- package/dist/commands/CompositionCommands.d.ts +47 -0
- package/dist/commands/CompositionCommands.d.ts.map +1 -0
- package/dist/commands/CompositionRebase.d.ts +24 -0
- package/dist/commands/CompositionRebase.d.ts.map +1 -0
- package/dist/commands/PasteCommand.d.ts.map +1 -1
- package/dist/commands/SelectionDeletion.d.ts +15 -5
- package/dist/commands/SelectionDeletion.d.ts.map +1 -1
- package/dist/fonts/math.mjs +1 -1
- package/dist/fonts.mjs +1 -1
- package/dist/full.mjs +1 -1
- package/dist/html.mjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/input/CompositionController.d.ts +78 -0
- package/dist/input/CompositionController.d.ts.map +1 -0
- package/dist/input/HTMLParser.d.ts +15 -2
- package/dist/input/HTMLParser.d.ts.map +1 -1
- package/dist/input/InputHandler.d.ts +34 -1
- package/dist/input/InputHandler.d.ts.map +1 -1
- package/dist/input/InputManager.d.ts +3 -0
- package/dist/input/InputManager.d.ts.map +1 -1
- package/dist/input/PasteHTMLHandler.d.ts.map +1 -1
- package/dist/markdown.mjs +1 -1
- package/dist/model/BlockAlignment.d.ts +6 -0
- package/dist/model/BlockAlignment.d.ts.map +1 -1
- package/dist/model/BlockOffsetText.d.ts +11 -0
- package/dist/model/BlockOffsetText.d.ts.map +1 -0
- package/dist/model/CompositionState.d.ts +14 -0
- package/dist/model/CompositionState.d.ts.map +1 -1
- package/dist/model/HTMLUtils.d.ts +16 -3
- package/dist/model/HTMLUtils.d.ts.map +1 -1
- package/dist/model/MarkSpec.d.ts +5 -3
- package/dist/model/MarkSpec.d.ts.map +1 -1
- package/dist/model/NodeResolver.d.ts +2 -0
- package/dist/model/NodeResolver.d.ts.map +1 -1
- package/dist/model/NodeSpec.d.ts +2 -1
- package/dist/model/NodeSpec.d.ts.map +1 -1
- package/dist/model/Schema.d.ts +2 -0
- package/dist/model/Schema.d.ts.map +1 -1
- package/dist/model/SchemaRegistry.d.ts +26 -1
- package/dist/model/SchemaRegistry.d.ts.map +1 -1
- package/dist/model/StyleClass.d.ts +45 -0
- package/dist/model/StyleClass.d.ts.map +1 -0
- package/dist/model/StyleClassRegistry.d.ts +28 -0
- package/dist/model/StyleClassRegistry.d.ts.map +1 -0
- package/dist/model/TextChange.d.ts +40 -0
- package/dist/model/TextChange.d.ts.map +1 -0
- package/dist/notectl-core.mjs +1 -1
- package/dist/notectl-core.umd.js +1 -1
- package/dist/notectl-core.umd.js.map +1 -1
- package/dist/plugins/Plugin.d.ts +11 -0
- package/dist/plugins/Plugin.d.ts.map +1 -1
- package/dist/plugins/PluginContextFactory.d.ts +2 -0
- package/dist/plugins/PluginContextFactory.d.ts.map +1 -1
- package/dist/plugins/RegistrationTracker.d.ts.map +1 -1
- package/dist/plugins/alignment/AlignmentPlugin.d.ts +17 -0
- package/dist/plugins/alignment/AlignmentPlugin.d.ts.map +1 -1
- package/dist/plugins/alignment.mjs +1 -1
- package/dist/plugins/bidi-isolation.mjs +1 -1
- package/dist/plugins/blockquote.mjs +1 -1
- package/dist/plugins/caret-navigation.mjs +1 -1
- package/dist/plugins/code-block.mjs +1 -1
- package/dist/plugins/font/FontPlugin.d.ts +13 -0
- package/dist/plugins/font/FontPlugin.d.ts.map +1 -1
- package/dist/plugins/font-size/FontSizeOperations.d.ts +2 -0
- package/dist/plugins/font-size/FontSizeOperations.d.ts.map +1 -1
- package/dist/plugins/font-size/FontSizePlugin.d.ts +11 -0
- package/dist/plugins/font-size/FontSizePlugin.d.ts.map +1 -1
- package/dist/plugins/font-size.mjs +1 -1
- package/dist/plugins/font.mjs +1 -1
- package/dist/plugins/formula/FormulaPlugin.d.ts.map +1 -1
- package/dist/plugins/formula/latex/LatexParser.d.ts.map +1 -1
- package/dist/plugins/formula/latex/LatexSymbols.d.ts.map +1 -1
- package/dist/plugins/formula/latex/LookupOwn.d.ts +6 -0
- package/dist/plugins/formula/latex/LookupOwn.d.ts.map +1 -0
- package/dist/plugins/formula/latex/handlers/Accents.d.ts.map +1 -1
- package/dist/plugins/formula/latex/handlers/Delimiters.d.ts.map +1 -1
- package/dist/plugins/formula/latex/handlers/Environments.d.ts.map +1 -1
- package/dist/plugins/formula/latex/handlers/Fonts.d.ts.map +1 -1
- package/dist/plugins/formula/latex/handlers/Spacing.d.ts.map +1 -1
- package/dist/plugins/formula.mjs +1 -1
- package/dist/plugins/gap-cursor/GapCursorPlugin.d.ts.map +1 -1
- package/dist/plugins/gap-cursor.mjs +1 -1
- package/dist/plugins/hard-break.mjs +1 -1
- package/dist/plugins/heading.mjs +1 -1
- package/dist/plugins/highlight/HighlightPlugin.d.ts +11 -0
- package/dist/plugins/highlight/HighlightPlugin.d.ts.map +1 -1
- package/dist/plugins/highlight.mjs +1 -1
- package/dist/plugins/horizontal-rule.mjs +1 -1
- package/dist/plugins/image.mjs +1 -1
- package/dist/plugins/inline-code/InlineCodePlugin.d.ts.map +1 -1
- package/dist/plugins/inline-code.mjs +1 -1
- package/dist/plugins/link/LinkPlugin.d.ts.map +1 -1
- package/dist/plugins/link.mjs +1 -1
- package/dist/plugins/list/ListPlugin.d.ts +2 -1
- package/dist/plugins/list/ListPlugin.d.ts.map +1 -1
- package/dist/plugins/list.mjs +1 -1
- package/dist/plugins/print.mjs +1 -1
- package/dist/plugins/shared/ColorGrid.d.ts.map +1 -1
- package/dist/plugins/shared/ColorPickerPopup.d.ts.map +1 -1
- package/dist/plugins/shared/ColorValidation.d.ts +12 -4
- package/dist/plugins/shared/ColorValidation.d.ts.map +1 -1
- package/dist/plugins/shared/InlineStyleMarkSpec.d.ts +10 -0
- package/dist/plugins/shared/InlineStyleMarkSpec.d.ts.map +1 -1
- package/dist/plugins/shared/StyleClassNames.d.ts +10 -0
- package/dist/plugins/shared/StyleClassNames.d.ts.map +1 -0
- package/dist/plugins/shared.mjs +1 -1
- package/dist/plugins/smart-paste.mjs +1 -1
- package/dist/plugins/strikethrough.mjs +1 -1
- package/dist/plugins/super-sub.mjs +1 -1
- package/dist/plugins/table/TableBorderColor.d.ts.map +1 -1
- package/dist/plugins/table.mjs +1 -1
- package/dist/plugins/text-color/TextColorPlugin.d.ts +11 -0
- package/dist/plugins/text-color/TextColorPlugin.d.ts.map +1 -1
- package/dist/plugins/text-color.mjs +1 -1
- package/dist/plugins/text-direction-auto.mjs +1 -1
- package/dist/plugins/text-direction.mjs +1 -1
- package/dist/plugins/text-formatting.mjs +1 -1
- package/dist/plugins/toolbar/ToolbarOverflowController.d.ts.map +1 -1
- package/dist/plugins/toolbar/ToolbarPlugin.d.ts.map +1 -1
- package/dist/plugins/toolbar.mjs +1 -1
- package/dist/plugins/video.mjs +1 -1
- package/dist/presets/full.mjs +1 -1
- package/dist/presets/minimal.mjs +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/register.mjs +1 -1
- package/dist/serialization/AlignmentHTML.d.ts +43 -0
- package/dist/serialization/AlignmentHTML.d.ts.map +1 -0
- package/dist/serialization/CSSClassCollector.d.ts +20 -17
- package/dist/serialization/CSSClassCollector.d.ts.map +1 -1
- package/dist/serialization/CSSValueEquivalence.d.ts +24 -0
- package/dist/serialization/CSSValueEquivalence.d.ts.map +1 -0
- package/dist/serialization/DocumentParser.d.ts +2 -1
- package/dist/serialization/DocumentParser.d.ts.map +1 -1
- package/dist/serialization/DocumentSerializer.d.ts +0 -4
- package/dist/serialization/DocumentSerializer.d.ts.map +1 -1
- package/dist/serialization/FirstTagAttributes.d.ts +16 -0
- package/dist/serialization/FirstTagAttributes.d.ts.map +1 -0
- package/dist/serialization/HTMLParseRules.d.ts +32 -0
- package/dist/serialization/HTMLParseRules.d.ts.map +1 -0
- package/dist/serialization/HTMLParseSession.d.ts +21 -0
- package/dist/serialization/HTMLParseSession.d.ts.map +1 -0
- package/dist/serialization/MarkSerializer.d.ts.map +1 -1
- package/dist/serialization/StyleClassHTML.d.ts +37 -0
- package/dist/serialization/StyleClassHTML.d.ts.map +1 -0
- package/dist/serialization/StyleRehydration.d.ts +16 -0
- package/dist/serialization/StyleRehydration.d.ts.map +1 -0
- package/dist/serialization/TableDimensions.d.ts.map +1 -1
- package/dist/serialization/index.d.ts +2 -1
- package/dist/serialization/index.d.ts.map +1 -1
- package/dist/serialization/markdown/InlineSerializers.d.ts.map +1 -1
- package/dist/state/EditorState.d.ts.map +1 -1
- package/dist/state/History.d.ts +2 -1
- package/dist/state/History.d.ts.map +1 -1
- package/dist/state/NavigationQueries.d.ts.map +1 -1
- package/dist/state/SelectionValidation.d.ts +12 -0
- package/dist/state/SelectionValidation.d.ts.map +1 -0
- package/dist/state/StepMapping.d.ts.map +1 -1
- package/dist/state/TransactionBuilder.d.ts +7 -1
- package/dist/state/TransactionBuilder.d.ts.map +1 -1
- package/dist/test/PluginTestUtils.d.ts +25 -0
- package/dist/test/PluginTestUtils.d.ts.map +1 -1
- package/dist/test/TestUtils.d.ts.map +1 -1
- package/dist/view/CursorWrapper.d.ts.map +1 -1
- package/dist/view/EditorView.d.ts +25 -1
- package/dist/view/EditorView.d.ts.map +1 -1
- package/dist/view/InlineContentDOM.d.ts +44 -0
- package/dist/view/InlineContentDOM.d.ts.map +1 -0
- package/dist/view/Reconciler.d.ts +20 -1
- package/dist/view/Reconciler.d.ts.map +1 -1
- package/dist/view/RenderedBlockText.d.ts +27 -0
- package/dist/view/RenderedBlockText.d.ts.map +1 -0
- package/dist/view/SelectionSync.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/chunks/AlignmentPlugin-DIwrRsHd.mjs +0 -2
- package/dist/chunks/AlignmentPlugin-DIwrRsHd.mjs.map +0 -1
- package/dist/chunks/BidiIsolationPlugin-cOLlL3Y9.mjs +0 -2
- package/dist/chunks/BlockquotePlugin-D-jRWLQB.mjs +0 -2
- package/dist/chunks/BlockquotePlugin-D-jRWLQB.mjs.map +0 -1
- package/dist/chunks/CodeBlockPlugin-BandNM3t.mjs +0 -2
- package/dist/chunks/ColorPickerPopup-_C5JZhki.mjs +0 -2
- package/dist/chunks/ColorValidation-B9d_umnf.mjs.map +0 -1
- package/dist/chunks/Commands-D-0UXYvo.mjs +0 -2
- package/dist/chunks/Commands-D-0UXYvo.mjs.map +0 -1
- package/dist/chunks/DocumentParser-i-CreJ48.mjs +0 -2
- package/dist/chunks/DocumentParser-i-CreJ48.mjs.map +0 -1
- package/dist/chunks/FontPlugin-C_ScWZ0P.mjs +0 -2
- package/dist/chunks/FontPlugin-C_ScWZ0P.mjs.map +0 -1
- package/dist/chunks/FontSizePlugin-DB_0njtC.mjs +0 -2
- package/dist/chunks/FontSizePlugin-DB_0njtC.mjs.map +0 -1
- package/dist/chunks/FormulaPlugin-CI0r4X1o.mjs +0 -2
- package/dist/chunks/FormulaPlugin-CI0r4X1o.mjs.map +0 -1
- package/dist/chunks/GapCursorPlugin-NozsEK9J.mjs +0 -2
- package/dist/chunks/GapCursorPlugin-NozsEK9J.mjs.map +0 -1
- package/dist/chunks/HTMLUtils-B0nGyFLb.mjs +0 -2
- package/dist/chunks/HTMLUtils-B0nGyFLb.mjs.map +0 -1
- package/dist/chunks/HeadingPlugin-LK8Pg4h0.mjs +0 -2
- package/dist/chunks/HeadingPlugin-LK8Pg4h0.mjs.map +0 -1
- package/dist/chunks/HighlightPlugin-B4WlZawl.mjs +0 -2
- package/dist/chunks/HighlightPlugin-B4WlZawl.mjs.map +0 -1
- package/dist/chunks/HorizontalRulePlugin-CxmUMM34.mjs +0 -2
- package/dist/chunks/ImagePlugin-C5ESNNsA.mjs +0 -2
- package/dist/chunks/ImagePlugin-C5ESNNsA.mjs.map +0 -1
- package/dist/chunks/InlineCodePlugin-C1SqGfv5.mjs +0 -2
- package/dist/chunks/InlineCodePlugin-C1SqGfv5.mjs.map +0 -1
- package/dist/chunks/InlineStyleMarkSpec-Cx3goc3W.mjs +0 -2
- package/dist/chunks/InlineStyleMarkSpec-Cx3goc3W.mjs.map +0 -1
- package/dist/chunks/ListPlugin-DSFPSWQC.mjs +0 -2
- package/dist/chunks/MarkCommands-CJvLGL5G.mjs +0 -2
- package/dist/chunks/MarkCommands-CJvLGL5G.mjs.map +0 -1
- package/dist/chunks/MarkdownHTMLRegistry-CISsC0lH.mjs +0 -2
- package/dist/chunks/MarkdownSerializer-Oex2RzNw.mjs +0 -2
- package/dist/chunks/MarkdownSerializer-Oex2RzNw.mjs.map +0 -1
- package/dist/chunks/NavigationQueries-Bt4zZ17v.mjs +0 -2
- package/dist/chunks/NavigationQueries-Bt4zZ17v.mjs.map +0 -1
- package/dist/chunks/NodeResolver-BtIknXqD.mjs +0 -2
- package/dist/chunks/NodeResolver-BtIknXqD.mjs.map +0 -1
- package/dist/chunks/PluginHelpers-WG1Lzzh3.mjs +0 -2
- package/dist/chunks/SchemaRegistry-acc6q_5x.mjs +0 -2
- package/dist/chunks/SchemaRegistry-acc6q_5x.mjs.map +0 -1
- package/dist/chunks/SelectionSync-CwOHMMfI.mjs +0 -2
- package/dist/chunks/SelectionSync-CwOHMMfI.mjs.map +0 -1
- package/dist/chunks/SimpleMark-CTDtEIMV.mjs +0 -2
- package/dist/chunks/TableDimensions-BcARMxQB.mjs +0 -2
- package/dist/chunks/TableDimensions-BcARMxQB.mjs.map +0 -1
- package/dist/chunks/TablePlugin-C4WMYGWN.mjs +0 -2
- package/dist/chunks/TablePlugin-C4WMYGWN.mjs.map +0 -1
- package/dist/chunks/TextColorPlugin-D_MhNJT6.mjs +0 -2
- package/dist/chunks/TextColorPlugin-D_MhNJT6.mjs.map +0 -1
- package/dist/chunks/TextDirectionService-OFOU6r_s.mjs +0 -2
- package/dist/chunks/ToolbarPlugin-O7TirXQP.mjs +0 -2
- package/dist/chunks/ToolbarPlugin-O7TirXQP.mjs.map +0 -1
- package/dist/chunks/VideoPlugin-C9z4JfP_.mjs +0 -2
- package/dist/chunks/VideoPlugin-C9z4JfP_.mjs.map +0 -1
- package/dist/chunks/color-picker-DJ05ey9o.mjs +0 -2
- package/dist/chunks/color-picker-DJ05ey9o.mjs.map +0 -1
- package/dist/chunks/full-Cshz7aTP.mjs +0 -2
- package/dist/chunks/minimal-7XqMY9kC.mjs +0 -2
- package/dist/chunks/register-BVvV0Vl_.mjs +0 -3
- package/dist/chunks/register-BVvV0Vl_.mjs.map +0 -1
- package/dist/editor/styles/base.d.ts +0 -3
- package/dist/editor/styles/base.d.ts.map +0 -1
- package/dist/editor/styles/color-picker.d.ts +0 -3
- package/dist/editor/styles/color-picker.d.ts.map +0 -1
- package/dist/editor/styles/font-select.d.ts +0 -3
- package/dist/editor/styles/font-select.d.ts.map +0 -1
- package/dist/editor/styles/font-size-select.d.ts +0 -3
- package/dist/editor/styles/font-size-select.d.ts.map +0 -1
- package/dist/editor/styles/heading-select.d.ts +0 -3
- package/dist/editor/styles/heading-select.d.ts.map +0 -1
- package/dist/editor/styles/image.d.ts +0 -3
- package/dist/editor/styles/image.d.ts.map +0 -1
- package/dist/editor/styles/reduced-motion.d.ts +0 -3
- package/dist/editor/styles/reduced-motion.d.ts.map +0 -1
- package/dist/editor/styles/table.d.ts +0 -3
- package/dist/editor/styles/table.d.ts.map +0 -1
- package/dist/editor/styles/toolbar.d.ts +0 -3
- package/dist/editor/styles/toolbar.d.ts.map +0 -1
- package/dist/plugins/blockquote/BlockquoteStyles.d.ts +0 -3
- package/dist/plugins/blockquote/BlockquoteStyles.d.ts.map +0 -1
- package/dist/plugins/formula/FormulaStyles.d.ts +0 -12
- package/dist/plugins/formula/FormulaStyles.d.ts.map +0 -1
- package/dist/plugins/image/ImagePopupStyles.d.ts +0 -3
- package/dist/plugins/image/ImagePopupStyles.d.ts.map +0 -1
- package/dist/plugins/video/VideoPopupStyles.d.ts +0 -3
- package/dist/plugins/video/VideoPopupStyles.d.ts.map +0 -1
- package/dist/plugins/video/VideoStyles.d.ts +0 -3
- package/dist/plugins/video/VideoStyles.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Decoration-BwhoA4MU.mjs","names":["#values"],"sources":["../../src/state/Mapping.ts","../../src/decorations/PositionMapping.ts","../../src/decorations/Decoration.ts"],"sourcesContent":["/**\n * Generic position-mapping primitive.\n *\n * Each {@link Step} produces a {@link StepMap} that describes how positions\n * in `{blockId, offset}` space shift when the step is applied. A\n * {@link Mapping} composes a sequence of `StepMap`s — typically all the maps\n * of a transaction — into a single mapper, so any consumer (decorations,\n * comments, selections, remote cursors, history) can fold a position\n * through an entire change set without re-implementing per-step math.\n *\n * The model mirrors ProseMirror's `StepMap` / `Mapping`, adapted to\n * notectl's `{blockId, offset}` position space (positions are scoped to\n * blocks, not a flat document offset).\n *\n * ## Association (bias) semantics\n *\n * The optional `assoc` argument decides which side of a boundary a position\n * sticks to:\n *\n * - `assoc = -1` (\"sticky left\"): the position stays at the boundary when\n * content is inserted at, or split exactly at, the position. This is the\n * semantics expected by an inclusive-start range marker (a decoration's\n * `from`, the left edge of a selection).\n * - `assoc = +1` (\"sticky right\"): the position moves past inserted content\n * and migrates to the new block when its host block is split exactly at\n * the position. This is the semantics expected by an exclusive-end range\n * marker (a decoration's `to`, the right edge of a selection).\n *\n * The default is `-1`, matching the most common case (cursor and from-side\n * mappers).\n *\n * ## StepMap categories\n *\n * Every {@link Step} produces exactly one of six categories:\n *\n * 1. `identity` — no position shift (mark, attribute, schema, block-type).\n * 2. `shift` — within a single block, the range `[from, to)` is replaced\n * with content of length `newLen`. Covers `insertText`, `deleteText`,\n * `insertInlineNode`, `removeInlineNode` as a single primitive.\n * 3. `split` — a block is split at an offset; positions past the split\n * migrate to the new block with rebased offsets.\n * 4. `merge` — a source block is appended to a target block; positions in\n * the source block migrate to the target block with offsets shifted by\n * the target's previous length.\n * 5. `blockRemoval` — one block subtree vanishes; positions inside any\n * removed block are marked deleted, and sibling child-indices in the\n * same parent shift down by one past the removed index.\n * 6. `childIndexShift` — a new block was inserted at `fromIndex` in\n * `parentPath`'s children; sibling child-indices `≥ fromIndex` shift up.\n * Position space ({blockId, offset}) is unaffected.\n *\n * `blockRemoval` and `childIndexShift` are the two categories that carry\n * **structural** information about a parent's child list. They are\n * orthogonal to positions ({blockId, offset}) and are interpreted by\n * {@link mapChildIndex} when rebasing tree-structural steps\n * (`insertNode` / `removeNode`).\n */\n\nimport { isBlockNode } from '../model/Document.js';\nimport type { BlockNode } from '../model/Document.js';\nimport type { Position } from '../model/Selection.js';\nimport { createPosition } from '../model/Selection.js';\nimport type { BlockId } from '../model/TypeBrands.js';\n\n/**\n * Result of mapping an `(blockId, [from, to))` range through a {@link Mapping}.\n *\n * Both endpoints are guaranteed to live in the same block. Callers can rely\n * on `from <= to` (the helper returns `null` rather than producing an\n * inverted range).\n */\nexport interface MappedInBlockRange {\n\treadonly blockId: BlockId;\n\treadonly from: number;\n\treadonly to: number;\n}\n\n/** Position-mapping bias at a boundary. */\nexport type Assoc = -1 | 1;\n\n// --- StepMap variants ---\n\n/** No-op map: positions pass through unchanged. */\nexport interface IdentityMap {\n\treadonly type: 'identity';\n}\n\n/**\n * Within `blockId`, the offset range `[from, to)` is replaced with content\n * of length `newLen`. Covers all in-block content edits with a single\n * primitive:\n *\n * - `insertText(blockId, off, text)` → `{from: off, to: off, newLen: text.length}`.\n * - `deleteText(blockId, f, t)` → `{from: f, to: t, newLen: 0}`.\n * - `insertInlineNode(blockId, off)` → `{from: off, to: off, newLen: 1}`.\n * - `removeInlineNode(blockId, off)` → `{from: off, to: off + 1, newLen: 0}`.\n */\nexport interface ShiftMap {\n\treadonly type: 'shift';\n\treadonly blockId: BlockId;\n\treadonly from: number;\n\treadonly to: number;\n\treadonly newLen: number;\n}\n\n/**\n * A block is split at `offset`. Content `[0, offset)` stays in `blockId`;\n * content `[offset, length)` migrates to `newBlockId` rebased to start at 0.\n */\nexport interface SplitMap {\n\treadonly type: 'split';\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n\treadonly newBlockId: BlockId;\n}\n\n/**\n * `sourceBlockId` is appended to `targetBlockId`. Positions in the source\n * block migrate to the target block with offset shifted by\n * `targetLengthBefore` (the target's length before the merge).\n */\nexport interface MergeMap {\n\treadonly type: 'merge';\n\treadonly targetBlockId: BlockId;\n\treadonly sourceBlockId: BlockId;\n\treadonly targetLengthBefore: number;\n}\n\n/**\n * A block subtree is removed from the document. Positions whose `blockId`\n * is in `removedBlockIds` are marked deleted; `removedBlockIds` covers the\n * removed root **plus all descendant block IDs** (see\n * {@link collectRemovedBlockIds}).\n *\n * `parentPath` and `index` carry the removal's structural coordinates so\n * sibling child-indices in the same parent can be rebased: any\n * `(parentPath, i)` with `i === index` becomes invalid (the block is gone),\n * and `i > index` shifts down by one. See {@link mapChildIndex}.\n */\nexport interface BlockRemovalMap {\n\treadonly type: 'blockRemoval';\n\treadonly removedBlockIds: ReadonlySet<BlockId>;\n\treadonly parentPath: readonly BlockId[];\n\treadonly index: number;\n}\n\n/**\n * A new block was inserted at `fromIndex` in `parentPath`'s child list.\n * Sibling child-indices `≥ fromIndex` shift up by `delta` (always `+1`\n * since {@link InsertNodeStep} inserts a single block). Position space\n * (`{blockId, offset}`) is unaffected — the new block has no prior\n * positions, and positions inside other siblings keep their offsets.\n *\n * Consumed by {@link mapChildIndex}, {@link mapInsertionIndex}, and exact\n * structural inverse detection during history replay.\n */\nexport interface ChildIndexShiftMap {\n\treadonly type: 'childIndexShift';\n\treadonly parentPath: readonly BlockId[];\n\treadonly fromIndex: number;\n\treadonly delta: number;\n\t/**\n\t * IDs introduced by an InsertNodeStep. Optional for synthetic/test maps;\n\t * when present it makes the map an exact structural inverse of the matching\n\t * BlockRemovalMap during history replay.\n\t */\n\treadonly insertedBlockIds?: ReadonlySet<BlockId>;\n}\n\n/**\n * One existing subtree moves between child lists. Positions inside the moved\n * subtree keep their block IDs and offsets; sibling child indices in both\n * parents are shifted by the removal followed by the insertion.\n */\nexport interface MoveNodeMap {\n\treadonly type: 'moveNode';\n\treadonly movedNodeId: BlockId;\n\treadonly fromParentPath: readonly BlockId[];\n\treadonly fromIndex: number;\n\treadonly toParentPath: readonly BlockId[];\n\t/** Destination index after removing the source node. */\n\treadonly destinationIndex: number;\n}\n\n/** Discriminated union of all StepMap variants. */\nexport type StepMap =\n\t| IdentityMap\n\t| ShiftMap\n\t| SplitMap\n\t| MergeMap\n\t| BlockRemovalMap\n\t| ChildIndexShiftMap\n\t| MoveNodeMap;\n\n// --- Map results ---\n\n/** Result of mapping a single position. */\nexport interface MapResult {\n\treadonly pos: Position;\n\t/** True if the input position fell inside content removed by the map. */\n\treadonly deleted: boolean;\n}\n\n/** A range expressed in `Position` space. */\nexport interface PositionRange {\n\treadonly from: Position;\n\treadonly to: Position;\n}\n\n// --- Singletons / factories ---\n\n/** The shared identity StepMap; reuse instead of allocating per step. */\nexport const IDENTITY_MAP: IdentityMap = Object.freeze({ type: 'identity' });\n\n/**\n * Runtime-immutable ReadonlySet facade.\n *\n * `Object.freeze(new Set())` only freezes the wrapper object; its internal\n * slots remain mutable through `add`, `delete`, and `clear`. Keeping the real\n * Set in an ECMAScript private field and exposing only ReadonlySet operations\n * makes structural StepMap snapshots immutable at runtime as well as by type.\n */\nclass ImmutableReadonlySet<T> implements ReadonlySet<T> {\n\treadonly #values: Set<T>;\n\n\tconstructor(values: Iterable<T>) {\n\t\tthis.#values = new Set(values);\n\t\tObject.freeze(this);\n\t}\n\n\tget size(): number {\n\t\treturn this.#values.size;\n\t}\n\n\thas(value: T): boolean {\n\t\treturn this.#values.has(value);\n\t}\n\n\tentries(): SetIterator<[T, T]> {\n\t\treturn this.#values.entries();\n\t}\n\n\tkeys(): SetIterator<T> {\n\t\treturn this.#values.keys();\n\t}\n\n\tvalues(): SetIterator<T> {\n\t\treturn this.#values.values();\n\t}\n\n\t[Symbol.iterator](): SetIterator<T> {\n\t\treturn this.#values[Symbol.iterator]();\n\t}\n\n\tforEach(callback: (value: T, value2: T, set: ReadonlySet<T>) => void, thisArg?: unknown): void {\n\t\tfor (const value of this.#values) callback.call(thisArg, value, value, this);\n\t}\n\n\tunion<U>(other: ReadonlySetLike<U>): Set<T | U> {\n\t\treturn new Set<T | U>([...this.#values, ...setLikeValues(other)]);\n\t}\n\n\tintersection<U>(other: ReadonlySetLike<U>): Set<T & U> {\n\t\tconst otherValues = setLikeValues(other);\n\t\tconst intersection = new Set<T & U>();\n\t\tfor (const value of this.#values) {\n\t\t\tif (hasSetValue(otherValues, value)) intersection.add(value as T & U);\n\t\t}\n\t\treturn intersection;\n\t}\n\n\tdifference<U>(other: ReadonlySetLike<U>): Set<T> {\n\t\tconst otherValues = setLikeValues(other);\n\t\treturn new Set([...this.#values].filter((value) => !hasSetValue(otherValues, value)));\n\t}\n\n\tsymmetricDifference<U>(other: ReadonlySetLike<U>): Set<T | U> {\n\t\tconst otherValues = setLikeValues(other);\n\t\tconst difference = new Set<T | U>();\n\t\tfor (const value of this.#values) {\n\t\t\tif (!hasSetValue(otherValues, value)) difference.add(value);\n\t\t}\n\t\tfor (const value of otherValues) {\n\t\t\tif (!hasSetValue(this.#values, value)) difference.add(value);\n\t\t}\n\t\treturn difference;\n\t}\n\n\tisSubsetOf(other: ReadonlySetLike<unknown>): boolean {\n\t\tconst otherValues = setLikeValues(other);\n\t\tfor (const value of this.#values) {\n\t\t\tif (!otherValues.has(value)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tisSupersetOf(other: ReadonlySetLike<unknown>): boolean {\n\t\tfor (const value of setLikeValues(other)) {\n\t\t\tif (!hasSetValue(this.#values, value)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tisDisjointFrom(other: ReadonlySetLike<unknown>): boolean {\n\t\tfor (const value of setLikeValues(other)) {\n\t\t\tif (hasSetValue(this.#values, value)) return false;\n\t\t}\n\t\treturn true;\n\t}\n}\n\nfunction setLikeValues<T>(values: ReadonlySetLike<T>): Set<T> {\n\tconst copy = new Set<T>();\n\tconst iterator = values.keys();\n\tfor (let next = iterator.next(); !next.done; next = iterator.next()) copy.add(next.value);\n\treturn copy;\n}\n\nfunction hasSetValue(values: ReadonlySetLike<unknown>, value: unknown): boolean {\n\treturn values.has(value);\n}\n\n/** Creates a detached, deeply immutable snapshot of a StepMap payload. */\nexport function snapshotStepMap(stepMap: StepMap): StepMap {\n\tswitch (stepMap.type) {\n\t\tcase 'identity':\n\t\t\treturn IDENTITY_MAP;\n\t\tcase 'blockRemoval':\n\t\t\treturn Object.freeze({\n\t\t\t\t...stepMap,\n\t\t\t\tremovedBlockIds: new ImmutableReadonlySet(stepMap.removedBlockIds),\n\t\t\t\tparentPath: Object.freeze([...stepMap.parentPath]),\n\t\t\t});\n\t\tcase 'childIndexShift':\n\t\t\treturn Object.freeze({\n\t\t\t\t...stepMap,\n\t\t\t\tparentPath: Object.freeze([...stepMap.parentPath]),\n\t\t\t\t...(stepMap.insertedBlockIds\n\t\t\t\t\t? { insertedBlockIds: new ImmutableReadonlySet(stepMap.insertedBlockIds) }\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\tcase 'moveNode':\n\t\t\treturn Object.freeze({\n\t\t\t\t...stepMap,\n\t\t\t\tfromParentPath: Object.freeze([...stepMap.fromParentPath]),\n\t\t\t\ttoParentPath: Object.freeze([...stepMap.toParentPath]),\n\t\t\t});\n\t\tdefault:\n\t\t\treturn Object.freeze({ ...stepMap });\n\t}\n}\n\n/**\n * Walks a block subtree and returns the set of its own ID plus every\n * descendant block ID. Used to build {@link BlockRemovalMap.removedBlockIds}.\n */\nexport function collectRemovedBlockIds(node: BlockNode): Set<BlockId> {\n\tconst ids = new Set<BlockId>();\n\tconst walk = (n: BlockNode): void => {\n\t\tids.add(n.id);\n\t\tfor (const child of n.children) {\n\t\t\tif (isBlockNode(child)) walk(child);\n\t\t}\n\t};\n\twalk(node);\n\treturn ids;\n}\n\n// --- Single-StepMap application ---\n\n/**\n * Maps a single position through one {@link StepMap}.\n *\n * @param pos input position\n * @param map the StepMap describing the change\n * @param assoc which side of a boundary to stick to (default `-1`)\n * @returns mapped position plus a `deleted` flag indicating whether `pos`\n * fell inside content that the step removed\n */\nexport function mapPositionThroughStep(pos: Position, map: StepMap, assoc: Assoc = -1): MapResult {\n\tswitch (map.type) {\n\t\tcase 'identity':\n\t\t\treturn { pos, deleted: false };\n\t\tcase 'shift':\n\t\t\treturn mapPositionThroughShift(pos, map, assoc);\n\t\tcase 'split':\n\t\t\treturn mapPositionThroughSplit(pos, map, assoc);\n\t\tcase 'merge':\n\t\t\treturn mapPositionThroughMerge(pos, map);\n\t\tcase 'blockRemoval':\n\t\t\treturn mapPositionThroughBlockRemoval(pos, map);\n\t\tcase 'childIndexShift':\n\t\t\t// Child-index shifts do not touch position space ({blockId, offset}):\n\t\t\t// a new sibling block has no prior positions to map, and existing\n\t\t\t// siblings keep their internal offsets even if their parent-relative\n\t\t\t// index changed. Consumed only by {@link mapChildIndex}.\n\t\t\treturn { pos, deleted: false };\n\t\tcase 'moveNode':\n\t\t\t// A move preserves block identity and in-block offsets. Structural\n\t\t\t// child-index consumers handle the parent-list shifts separately.\n\t\t\treturn { pos, deleted: false };\n\t}\n}\n\nfunction mapPositionThroughShift(pos: Position, map: ShiftMap, assoc: Assoc): MapResult {\n\tif (pos.blockId !== map.blockId) return { pos, deleted: false };\n\n\tconst delta: number = map.newLen - (map.to - map.from);\n\tconst off: number = pos.offset;\n\n\t// Strictly before the affected range\n\tif (off < map.from) return { pos, deleted: false };\n\n\t// At the start boundary\n\tif (off === map.from) {\n\t\t// Pure insertion (from === to): assoc decides whether we stick before\n\t\t// or after the inserted run.\n\t\tif (map.from === map.to) {\n\t\t\tconst newOff: number = assoc === 1 ? map.from + map.newLen : map.from;\n\t\t\treturn newOff === off\n\t\t\t\t? { pos, deleted: false }\n\t\t\t\t: { pos: shiftedPos(pos, newOff), deleted: false };\n\t\t}\n\t\t// Deletion starts at this point — position stays at `from` regardless\n\t\t// of assoc; nothing was inserted to skip past.\n\t\treturn { pos, deleted: false };\n\t}\n\n\t// Strictly inside [from, to): position fell into removed content\n\tif (off < map.to) {\n\t\tconst newOff: number = assoc === 1 ? map.from + map.newLen : map.from;\n\t\treturn { pos: shiftedPos(pos, newOff), deleted: true };\n\t}\n\n\t// At or past the end boundary: shift by delta\n\tconst newOff: number = off + delta;\n\treturn newOff === off\n\t\t? { pos, deleted: false }\n\t\t: { pos: shiftedPos(pos, newOff), deleted: false };\n}\n\nfunction mapPositionThroughSplit(pos: Position, map: SplitMap, assoc: Assoc): MapResult {\n\tif (pos.blockId !== map.blockId) return { pos, deleted: false };\n\n\tif (pos.offset < map.offset) return { pos, deleted: false };\n\n\tif (pos.offset > map.offset) {\n\t\treturn {\n\t\t\tpos: createPosition(map.newBlockId, pos.offset - map.offset),\n\t\t\tdeleted: false,\n\t\t};\n\t}\n\n\t// At the split boundary: assoc decides which side keeps the cursor.\n\tif (assoc === 1) {\n\t\treturn { pos: createPosition(map.newBlockId, 0), deleted: false };\n\t}\n\treturn { pos, deleted: false };\n}\n\nfunction mapPositionThroughMerge(pos: Position, map: MergeMap): MapResult {\n\tif (pos.blockId !== map.sourceBlockId) return { pos, deleted: false };\n\treturn {\n\t\tpos: createPosition(map.targetBlockId, pos.offset + map.targetLengthBefore),\n\t\tdeleted: false,\n\t};\n}\n\nfunction mapPositionThroughBlockRemoval(pos: Position, map: BlockRemovalMap): MapResult {\n\tif (map.removedBlockIds.has(pos.blockId)) {\n\t\treturn { pos, deleted: true };\n\t}\n\treturn { pos, deleted: false };\n}\n\n/** Allocates a new Position with the given offset, preserving an optional `path`. */\nfunction shiftedPos(original: Position, newOffset: number): Position {\n\treturn createPosition(original.blockId, newOffset, original.path);\n}\n\n// --- Mapping ---\n\n/**\n * Composes a sequence of {@link StepMap}s into a single mapper. A `Mapping`\n * is immutable; `appendMap` returns a new instance.\n *\n * Construction always normalizes by dropping identity maps — they're a\n * common case and would otherwise inflate every transaction's mapping\n * pipeline with no-ops.\n */\nexport class Mapping {\n\t/** Shared empty Mapping. */\n\tstatic readonly empty: Mapping = new Mapping([]);\n\n\treadonly maps: readonly StepMap[];\n\n\tprivate constructor(maps: readonly StepMap[]) {\n\t\tthis.maps = Object.freeze(maps.map(snapshotStepMap));\n\t\tObject.freeze(this);\n\t}\n\n\t/** Creates a Mapping from a list of StepMaps, dropping identity maps. */\n\tstatic from(maps: readonly StepMap[]): Mapping {\n\t\tconst filtered: StepMap[] = [];\n\t\tfor (const m of maps) {\n\t\t\tif (m.type !== 'identity') filtered.push(m);\n\t\t}\n\t\tif (filtered.length === 0) return Mapping.empty;\n\t\treturn new Mapping(filtered);\n\t}\n\n\t/** Returns a new Mapping with `map` appended. */\n\tappendMap(map: StepMap): Mapping {\n\t\tif (map.type === 'identity') return this;\n\t\treturn new Mapping([...this.maps, map]);\n\t}\n\n\t/** Concatenates two mappings into a new one. */\n\tappendMapping(other: Mapping): Mapping {\n\t\tif (other.maps.length === 0) return this;\n\t\tif (this.maps.length === 0) return other;\n\t\treturn new Mapping([...this.maps, ...other.maps]);\n\t}\n\n\t/** True if the mapping contains no position-changing maps. */\n\tget isEmpty(): boolean {\n\t\treturn this.maps.length === 0;\n\t}\n\n\t/**\n\t * Folds a position through every contained StepMap in order.\n\t * Returns the mapped position; the `deleted` flag is **not** preserved\n\t * (use {@link mapResult} when you need it).\n\t */\n\tmap(pos: Position, assoc: Assoc = -1): Position {\n\t\treturn this.mapResult(pos, assoc).pos;\n\t}\n\n\t/**\n\t * Like {@link map}, but returns whether the position is deleted in the final\n\t * frame. Content deletion remains sticky across every later map. Structural\n\t * deletion can be recovered by an `insertNode` map carrying the same block\n\t * ID; a later removal can mark that identity deleted again.\n\t */\n\tmapResult(pos: Position, assoc: Assoc = -1): MapResult {\n\t\tlet current: Position = pos;\n\t\tlet contentDeleted = false;\n\t\tlet structurallyDeleted = false;\n\t\tfor (const m of this.maps) {\n\t\t\tconst result: MapResult = mapPositionThroughStep(current, m, assoc);\n\t\t\tcurrent = result.pos;\n\t\t\tif (result.deleted) {\n\t\t\t\tif (m.type === 'blockRemoval') {\n\t\t\t\t\tstructurallyDeleted = true;\n\t\t\t\t} else {\n\t\t\t\t\tcontentDeleted = true;\n\t\t\t\t}\n\t\t\t} else if (m.type === 'childIndexShift' && m.insertedBlockIds?.has(current.blockId)) {\n\t\t\t\tstructurallyDeleted = false;\n\t\t\t}\n\t\t}\n\t\treturn { pos: current, deleted: contentDeleted || structurallyDeleted };\n\t}\n\n\t/**\n\t * Maps a range. By convention, `from` is mapped with `assoc = -1`\n\t * (inclusive-start) and `to` with `assoc = +1` (exclusive-end). The\n\t * caller may override either bias.\n\t *\n\t * Returns `null` when both endpoints land in deleted content **and** the\n\t * mapped range would collapse to length zero or negative — i.e. the\n\t * range no longer covers any live content.\n\t *\n\t * The returned `from`/`to` may live in different blocks (e.g. after a\n\t * `split` map). Callers that require an in-block range (decorations,\n\t * inline selections) must detect and split accordingly.\n\t */\n\tmapRange(range: PositionRange, assocFrom: Assoc = -1, assocTo: Assoc = 1): PositionRange | null {\n\t\tconst from: MapResult = this.mapResult(range.from, assocFrom);\n\t\tconst to: MapResult = this.mapResult(range.to, assocTo);\n\n\t\tif (from.deleted && to.deleted) {\n\t\t\tif (from.pos.blockId === to.pos.blockId && from.pos.offset >= to.pos.offset) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn { from: from.pos, to: to.pos };\n\t}\n}\n\n// --- In-block range helpers (used by per-step Step→Step mapping) ---\n\n/**\n * Maps an `(blockId, [from, to))` range through `mapping`, asserting the\n * result lives in a single block.\n *\n * Returns `null` when the range no longer addresses live content in a single\n * block:\n *\n * - the host block was removed;\n * - the range was fully deleted (both endpoints flagged deleted and collapse);\n * - the endpoints migrated to different blocks (range fragmented, e.g. a\n * `split` map placed `from` and `to` on opposite sides of the cut).\n *\n * Default biases are **conservative for step rebasing**: `assocFrom = +1`,\n * `assocTo = -1`. An intervening insertion at either boundary therefore\n * does NOT expand the rebased range to cover the new content — the user's\n * original edit only addressed the original content, and the agent's\n * intervening insertion should be preserved across an undo/redo. This is\n * the opposite of {@link Mapping.mapRange}'s default biases, which model\n * selections (inclusive-start, exclusive-end) where boundary insertions\n * naturally extend the selection.\n */\nexport function mapInBlockRange(\n\tblockId: BlockId,\n\tfrom: number,\n\tto: number,\n\tmapping: Mapping,\n\tassocFrom: Assoc = 1,\n\tassocTo: Assoc = -1,\n): MappedInBlockRange | null {\n\tif (mapping.isEmpty) return { blockId, from, to };\n\n\tconst fromPos: Position = createPosition(blockId, from);\n\tconst toPos: Position = createPosition(blockId, to);\n\tconst fromResult: MapResult = mapping.mapResult(fromPos, assocFrom);\n\tconst toResult: MapResult = mapping.mapResult(toPos, assocTo);\n\n\t// If both endpoints fell inside removed/replaced content, the range no\n\t// longer addresses live document territory — abandon. A partial overlap\n\t// (one endpoint deleted, the other shifted) still survives clamped.\n\tif (fromResult.deleted && toResult.deleted) return null;\n\n\t// Range must remain within a single block. A split could have moved one\n\t// endpoint to the new block; that's a fragmentation we cannot represent\n\t// as a single in-block step.\n\tif (fromResult.pos.blockId !== toResult.pos.blockId) return null;\n\n\t// Defensive: a range whose endpoints inverted (from > to) is invalid.\n\t// An empty range with from === to is still valid (e.g. a pure-insertion\n\t// `shift` whose offset survived).\n\tif (fromResult.pos.offset > toResult.pos.offset) return null;\n\n\treturn {\n\t\tblockId: fromResult.pos.blockId,\n\t\tfrom: fromResult.pos.offset,\n\t\tto: toResult.pos.offset,\n\t};\n}\n\n/**\n * Maps an `(blockId, offset)` point through `mapping`, returning the\n * equivalent in-block position or `null` when the host block was removed.\n *\n * Convenience wrapper around {@link mapInBlockRange} for steps that carry a\n * single offset (`insertText`, `insertInlineNode`, `splitBlock`).\n */\nexport function mapOffsetInBlock(\n\tblockId: BlockId,\n\toffset: number,\n\tmapping: Mapping,\n\tassoc: Assoc = -1,\n): MappedInBlockRange | null {\n\tif (mapping.isEmpty) return { blockId, from: offset, to: offset };\n\n\tconst pos: Position = createPosition(blockId, offset);\n\tconst result: MapResult = mapping.mapResult(pos, assoc);\n\tif (result.deleted) return null;\n\treturn { blockId: result.pos.blockId, from: result.pos.offset, to: result.pos.offset };\n}\n\n// --- Child-index mapping (used by structural step rebasing) ---\n\n/**\n * Rebases a child-index `(parentPath, index)` through `mapping`. The\n * `index` is interpreted as the position of an **existing** child block:\n * if an intervening edit removed exactly that child, the result is\n * `null`. For an **insertion slot** (the target index of a future\n * `insertNode`), use {@link mapInsertionIndex} — slots stay valid even\n * when the block previously at that index is removed.\n *\n * Child-indices live in a coordinate space orthogonal to positions\n * (`{blockId, offset}`): they describe a slot in a parent's child list,\n * not a place inside text. Three {@link StepMap} categories carry\n * child-index-affecting information:\n *\n * - {@link ChildIndexShiftMap} (produced by `insertNode`): shifts\n * sibling indices `≥ fromIndex` by `delta` (always `+1` today).\n * - {@link BlockRemovalMap} (produced by `removeNode`): removes the child\n * at `index` (the input index becomes invalid → `null`), and shifts\n * sibling indices `> index` down by `1`.\n * - {@link MoveNodeMap} (produced by `moveNode`): combines the source removal\n * and destination insertion while preserving the moved subtree's identity.\n *\n * Maps whose `parentPath` differs from the input pass through; all\n * non-structural categories (`shift`, `split`, `merge`, `identity`) are\n * no-ops here.\n */\nexport function mapChildIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n): number | null {\n\treturn foldChildIndex(parentPath, index, mapping, 'existing');\n}\n\n/**\n * Rebases an **insertion slot** `(parentPath, index)` through `mapping`.\n * An insertion slot lives in `[0, children.length]` (inclusive of the\n * end) and represents \"where to insert\", not an existing block. Slots\n * remain valid across intervening edits — even when the block previously\n * at that index is removed — so this function never returns `null`.\n *\n * Difference from {@link mapChildIndex}: for a `BlockRemovalMap` with\n * matching parent and `index === map.index`, this function keeps the\n * slot (returning `map.index`, which is the same numeric position in the\n * post-removal frame); {@link mapChildIndex} would return `null`.\n * {@link ChildIndexShiftMap} handling is identical.\n */\nexport function mapInsertionIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n): number {\n\t// `foldChildIndex` with `'insertion'` provably never returns `null` —\n\t// the only path that would (BlockRemovalMap, matching parent, matching\n\t// index) is short-circuited inside `mapChildIndexThroughStep`. The\n\t// overload signature carries that invariant into the type system.\n\treturn foldChildIndex(parentPath, index, mapping, 'insertion');\n}\n\ntype ChildIndexKind = 'existing' | 'insertion';\n\nfunction foldChildIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n\tkind: 'existing',\n): number | null;\nfunction foldChildIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n\tkind: 'insertion',\n): number;\nfunction foldChildIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n\tkind: ChildIndexKind,\n): number | null {\n\tif (mapping.isEmpty) return index;\n\n\tlet current: number = index;\n\tfor (const m of mapping.maps) {\n\t\tconst next: number | null = mapChildIndexThroughStep(parentPath, current, m, kind);\n\t\tif (next === null) return null;\n\t\tcurrent = next;\n\t}\n\treturn current;\n}\n\nfunction mapChildIndexThroughStep(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmap: StepMap,\n\tkind: ChildIndexKind,\n): number | null {\n\tswitch (map.type) {\n\t\tcase 'identity':\n\t\tcase 'shift':\n\t\tcase 'split':\n\t\tcase 'merge':\n\t\t\treturn index;\n\t\tcase 'blockRemoval':\n\t\t\tif (!sameParentPath(parentPath, map.parentPath)) return index;\n\t\t\tif (index === map.index) {\n\t\t\t\t// Existing-child semantics: that child is gone → invalid.\n\t\t\t\t// Insertion-slot semantics: the slot survives; nothing was\n\t\t\t\t// inserted/removed *to the left* of `index`, so the slot\n\t\t\t\t// number is unchanged in the post-removal frame.\n\t\t\t\treturn kind === 'existing' ? null : index;\n\t\t\t}\n\t\t\tif (index > map.index) return index - 1;\n\t\t\treturn index;\n\t\tcase 'childIndexShift':\n\t\t\tif (!sameParentPath(parentPath, map.parentPath)) return index;\n\t\t\tif (index >= map.fromIndex) return index + map.delta;\n\t\t\treturn index;\n\t\tcase 'moveNode':\n\t\t\treturn mapChildIndexThroughMove(parentPath, index, map, kind);\n\t}\n}\n\nfunction mapChildIndexThroughMove(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmap: MoveNodeMap,\n\tkind: ChildIndexKind,\n): number | null {\n\tconst sameParent: boolean = sameParentPath(map.fromParentPath, map.toParentPath);\n\tif (sameParent && map.fromIndex === map.destinationIndex) return index;\n\tif (\n\t\tkind === 'existing' &&\n\t\tsameParent &&\n\t\tsameParentPath(parentPath, map.fromParentPath) &&\n\t\tindex === map.fromIndex\n\t) {\n\t\treturn map.destinationIndex;\n\t}\n\n\tlet current: number = index;\n\tif (sameParentPath(parentPath, map.fromParentPath)) {\n\t\tif (current === map.fromIndex) {\n\t\t\tif (kind === 'existing') return null;\n\t\t} else if (current > map.fromIndex) {\n\t\t\tcurrent--;\n\t\t}\n\t}\n\n\tif (sameParentPath(parentPath, map.toParentPath) && current >= map.destinationIndex) {\n\t\tcurrent++;\n\t}\n\treturn current;\n}\n\nfunction sameParentPath(a: readonly BlockId[], b: readonly BlockId[]): boolean {\n\tif (a === b) return true;\n\tif (a.length !== b.length) return false;\n\tfor (let i = 0; i < a.length; i++) {\n\t\tif (a[i] !== b[i]) return false;\n\t}\n\treturn true;\n}\n\n// --- StepMap inversion (used by history's frame-walk cancellation) ---\n\n/**\n * Returns the {@link StepMap} that undoes `map` in position space — i.e.\n * composing `map` with `invertStepMap(map)` is content-preserving (though\n * the composed position-mapping is *not* a true identity in our framework:\n * positions interior to a delete-then-reinsert round-trip clamp to the\n * deletion start during the deletion half and don't return on the insert\n * half).\n *\n * Used by history to detect mutually-inverse stepmaps in the rebase chain\n * and cancel them, sidestepping the round-trip clamping for cases where\n * the rebase is a no-op in content terms.\n *\n * Structural maps include enough metadata to recover their exact inverse\n * where possible. Synthetic ChildIndexShiftMaps without inserted subtree IDs\n * remain position-only and therefore invert to {@link IDENTITY_MAP}.\n */\nexport function invertStepMap(map: StepMap): StepMap {\n\tswitch (map.type) {\n\t\tcase 'identity':\n\t\t\treturn IDENTITY_MAP;\n\t\tcase 'shift':\n\t\t\treturn {\n\t\t\t\ttype: 'shift',\n\t\t\t\tblockId: map.blockId,\n\t\t\t\tfrom: map.from,\n\t\t\t\tto: map.from + map.newLen,\n\t\t\t\tnewLen: map.to - map.from,\n\t\t\t};\n\t\tcase 'split':\n\t\t\treturn {\n\t\t\t\ttype: 'merge',\n\t\t\t\ttargetBlockId: map.blockId,\n\t\t\t\tsourceBlockId: map.newBlockId,\n\t\t\t\ttargetLengthBefore: map.offset,\n\t\t\t};\n\t\tcase 'merge':\n\t\t\treturn {\n\t\t\t\ttype: 'split',\n\t\t\t\tblockId: map.targetBlockId,\n\t\t\t\toffset: map.targetLengthBefore,\n\t\t\t\tnewBlockId: map.sourceBlockId,\n\t\t\t};\n\t\tcase 'blockRemoval':\n\t\t\treturn {\n\t\t\t\ttype: 'childIndexShift',\n\t\t\t\tparentPath: map.parentPath,\n\t\t\t\tfromIndex: map.index,\n\t\t\t\tdelta: 1,\n\t\t\t\tinsertedBlockIds: map.removedBlockIds,\n\t\t\t};\n\t\tcase 'childIndexShift':\n\t\t\tif (map.delta === 1 && map.insertedBlockIds) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'blockRemoval',\n\t\t\t\t\tremovedBlockIds: map.insertedBlockIds,\n\t\t\t\t\tparentPath: map.parentPath,\n\t\t\t\t\tindex: map.fromIndex,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn IDENTITY_MAP;\n\t\tcase 'moveNode':\n\t\t\treturn {\n\t\t\t\ttype: 'moveNode',\n\t\t\t\tmovedNodeId: map.movedNodeId,\n\t\t\t\tfromParentPath: map.toParentPath,\n\t\t\t\tfromIndex: map.destinationIndex,\n\t\t\t\ttoParentPath: map.fromParentPath,\n\t\t\t\tdestinationIndex: map.fromIndex,\n\t\t\t};\n\t}\n}\n\n/**\n * Structural equality for {@link StepMap}s. Used by history to recognize\n * cancelling pairs in the rebase chain ({@link invertStepMap}(a) ≡ b).\n */\nexport function stepMapsEqual(a: StepMap, b: StepMap): boolean {\n\tif (a.type !== b.type) return false;\n\tswitch (a.type) {\n\t\tcase 'identity':\n\t\t\treturn true;\n\t\tcase 'shift': {\n\t\t\tconst bs = b as ShiftMap;\n\t\t\treturn (\n\t\t\t\ta.blockId === bs.blockId && a.from === bs.from && a.to === bs.to && a.newLen === bs.newLen\n\t\t\t);\n\t\t}\n\t\tcase 'split': {\n\t\t\tconst bs = b as SplitMap;\n\t\t\treturn a.blockId === bs.blockId && a.offset === bs.offset && a.newBlockId === bs.newBlockId;\n\t\t}\n\t\tcase 'merge': {\n\t\t\tconst bm = b as MergeMap;\n\t\t\treturn (\n\t\t\t\ta.targetBlockId === bm.targetBlockId &&\n\t\t\t\ta.sourceBlockId === bm.sourceBlockId &&\n\t\t\t\ta.targetLengthBefore === bm.targetLengthBefore\n\t\t\t);\n\t\t}\n\t\tcase 'blockRemoval': {\n\t\t\tconst br = b as BlockRemovalMap;\n\t\t\tif (a.index !== br.index) return false;\n\t\t\tif (!sameParentPath(a.parentPath, br.parentPath)) return false;\n\t\t\tif (a.removedBlockIds.size !== br.removedBlockIds.size) return false;\n\t\t\tfor (const id of a.removedBlockIds) {\n\t\t\t\tif (!br.removedBlockIds.has(id)) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tcase 'childIndexShift': {\n\t\t\tconst cs = b as ChildIndexShiftMap;\n\t\t\treturn (\n\t\t\t\ta.fromIndex === cs.fromIndex &&\n\t\t\t\ta.delta === cs.delta &&\n\t\t\t\tsameParentPath(a.parentPath, cs.parentPath) &&\n\t\t\t\toptionalIdSetsEqual(a.insertedBlockIds, cs.insertedBlockIds)\n\t\t\t);\n\t\t}\n\t\tcase 'moveNode': {\n\t\t\tif (b.type !== 'moveNode') return false;\n\t\t\treturn (\n\t\t\t\ta.movedNodeId === b.movedNodeId &&\n\t\t\t\ta.fromIndex === b.fromIndex &&\n\t\t\t\ta.destinationIndex === b.destinationIndex &&\n\t\t\t\tsameParentPath(a.fromParentPath, b.fromParentPath) &&\n\t\t\t\tsameParentPath(a.toParentPath, b.toParentPath)\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction optionalIdSetsEqual(\n\ta: ReadonlySet<BlockId> | undefined,\n\tb: ReadonlySet<BlockId> | undefined,\n): boolean {\n\tif (a === b) return true;\n\tif (!a || !b || a.size !== b.size) return false;\n\tfor (const id of a) {\n\t\tif (!b.has(id)) return false;\n\t}\n\treturn true;\n}\n","/**\n * Thin decoration-specific adapters over the generic {@link StepMap}\n * primitive. Position-shift arithmetic lives in `state/Mapping.ts`; this\n * module only contains the decoration-shape concerns:\n *\n * - splitting an {@link InlineDecoration} into two when a `splitBlock`\n * crosses its range,\n * - dropping a {@link NodeDecoration} when its block disappears\n * (`removeNode`) or is absorbed by a merge,\n * - applying widget `side` as the mapping `assoc`.\n *\n * The legacy entry point `mapDecorationThroughStep(deco, step)` is\n * preserved as a thin shim over `mapDecorationThroughStepMap` so existing\n * tests keep working; new consumers should reach for `Transaction.mapping`\n * directly via `DecorationSet.map(tr)`.\n */\n\nimport type { Document } from '../model/Document.js';\nimport { createPosition } from '../model/Selection.js';\nimport type { MergeMap, ShiftMap, SplitMap, StepMap } from '../state/Mapping.js';\nimport { mapPositionThroughStep } from '../state/Mapping.js';\nimport { getStepMap } from '../state/StepHandlers.js';\nimport type { Step } from '../state/Transaction.js';\nimport type {\n\tDecoration,\n\tInlineDecoration,\n\tNodeDecoration,\n\tWidgetDecoration,\n} from './Decoration.js';\n\nconst EMPTY_DOC: Document = { children: [] };\n\n/**\n * Maps a decoration through a single {@link StepMap}. Returns:\n * - the (possibly identical) decoration,\n * - an array of two decorations when a `splitBlock` cuts an inline range,\n * - or `null` when the decoration was deleted.\n */\nexport function mapDecorationThroughStepMap(\n\tdeco: Decoration,\n\tstepMap: StepMap,\n): Decoration | readonly Decoration[] | null {\n\tswitch (deco.type) {\n\t\tcase 'inline':\n\t\t\treturn mapInline(deco, stepMap);\n\t\tcase 'widget':\n\t\t\treturn mapWidget(deco, stepMap);\n\t\tcase 'node':\n\t\t\treturn mapNode(deco, stepMap);\n\t}\n}\n\n/**\n * Legacy entry point — kept for backward compatibility with callers and\n * tests that hold a {@link Step} rather than a {@link StepMap}. Internally\n * converts step → StepMap (cheap, no doc state needed for any of the\n * shape categories used here) and delegates to\n * {@link mapDecorationThroughStepMap}.\n */\nexport function mapDecorationThroughStep(\n\tdeco: Decoration,\n\tstep: Step,\n): Decoration | readonly Decoration[] | null {\n\treturn mapDecorationThroughStepMap(deco, getStepMap(EMPTY_DOC, step));\n}\n\n// --- Inline ---\n\nfunction mapInline(\n\tdeco: InlineDecoration,\n\tstepMap: StepMap,\n): InlineDecoration | readonly InlineDecoration[] | null {\n\tswitch (stepMap.type) {\n\t\tcase 'identity':\n\t\t\treturn deco;\n\t\tcase 'shift':\n\t\t\treturn mapInlineShift(deco, stepMap);\n\t\tcase 'split':\n\t\t\treturn mapInlineSplit(deco, stepMap);\n\t\tcase 'merge':\n\t\t\treturn mapInlineMerge(deco, stepMap);\n\t\tcase 'blockRemoval':\n\t\t\treturn stepMap.removedBlockIds.has(deco.blockId) ? null : deco;\n\t\tcase 'childIndexShift':\n\t\tcase 'moveNode':\n\t\t\t// Sibling-index shifts don't move text positions.\n\t\t\treturn deco;\n\t}\n}\n\nfunction mapInlineShift(deco: InlineDecoration, map: ShiftMap): InlineDecoration | null {\n\tif (deco.blockId !== map.blockId) return deco;\n\n\tconst fromPos = mapPositionThroughStep(createPosition(deco.blockId, deco.from), map, -1).pos;\n\tconst toPos = mapPositionThroughStep(createPosition(deco.blockId, deco.to), map, 1).pos;\n\n\tif (fromPos.offset >= toPos.offset) return null;\n\tif (fromPos.offset === deco.from && toPos.offset === deco.to) return deco;\n\treturn { ...deco, from: fromPos.offset, to: toPos.offset };\n}\n\nfunction mapInlineSplit(\n\tdeco: InlineDecoration,\n\tmap: SplitMap,\n): InlineDecoration | readonly InlineDecoration[] {\n\tif (deco.blockId !== map.blockId) return deco;\n\n\tif (deco.to <= map.offset) return deco;\n\n\tif (deco.from >= map.offset) {\n\t\treturn {\n\t\t\t...deco,\n\t\t\tblockId: map.newBlockId,\n\t\t\tfrom: deco.from - map.offset,\n\t\t\tto: deco.to - map.offset,\n\t\t};\n\t}\n\n\t// Spans the split — return both halves\n\tconst left: InlineDecoration = { ...deco, to: map.offset };\n\tconst right: InlineDecoration = {\n\t\t...deco,\n\t\tblockId: map.newBlockId,\n\t\tfrom: 0,\n\t\tto: deco.to - map.offset,\n\t};\n\treturn [left, right];\n}\n\nfunction mapInlineMerge(deco: InlineDecoration, map: MergeMap): InlineDecoration {\n\tif (deco.blockId !== map.sourceBlockId) return deco;\n\treturn {\n\t\t...deco,\n\t\tblockId: map.targetBlockId,\n\t\tfrom: deco.from + map.targetLengthBefore,\n\t\tto: deco.to + map.targetLengthBefore,\n\t};\n}\n\n// --- Widget ---\n\nfunction mapWidget(deco: WidgetDecoration, stepMap: StepMap): WidgetDecoration | null {\n\tswitch (stepMap.type) {\n\t\tcase 'identity':\n\t\t\treturn deco;\n\t\tcase 'shift':\n\t\t\treturn mapWidgetShift(deco, stepMap);\n\t\tcase 'split':\n\t\t\treturn mapWidgetSplit(deco, stepMap);\n\t\tcase 'merge':\n\t\t\treturn mapWidgetMerge(deco, stepMap);\n\t\tcase 'blockRemoval':\n\t\t\treturn stepMap.removedBlockIds.has(deco.blockId) ? null : deco;\n\t\tcase 'childIndexShift':\n\t\tcase 'moveNode':\n\t\t\treturn deco;\n\t}\n}\n\nfunction mapWidgetShift(deco: WidgetDecoration, map: ShiftMap): WidgetDecoration | null {\n\tif (deco.blockId !== map.blockId) return deco;\n\n\tconst result = mapPositionThroughStep(createPosition(deco.blockId, deco.offset), map, deco.side);\n\t// A widget that lands strictly inside removed content is deleted.\n\tif (result.deleted) return null;\n\tif (result.pos.offset === deco.offset) return deco;\n\treturn { ...deco, offset: result.pos.offset };\n}\n\nfunction mapWidgetSplit(deco: WidgetDecoration, map: SplitMap): WidgetDecoration {\n\tif (deco.blockId !== map.blockId) return deco;\n\tconst result = mapPositionThroughStep(createPosition(deco.blockId, deco.offset), map, deco.side);\n\tif (result.pos.blockId === deco.blockId && result.pos.offset === deco.offset) return deco;\n\treturn { ...deco, blockId: result.pos.blockId, offset: result.pos.offset };\n}\n\nfunction mapWidgetMerge(deco: WidgetDecoration, map: MergeMap): WidgetDecoration {\n\tif (deco.blockId !== map.sourceBlockId) return deco;\n\treturn {\n\t\t...deco,\n\t\tblockId: map.targetBlockId,\n\t\toffset: deco.offset + map.targetLengthBefore,\n\t};\n}\n\n// --- Node ---\n\nfunction mapNode(deco: NodeDecoration, stepMap: StepMap): NodeDecoration | null {\n\tswitch (stepMap.type) {\n\t\tcase 'identity':\n\t\tcase 'shift':\n\t\tcase 'split':\n\t\t\t// Node decorations are bound to a block; in-block content edits\n\t\t\t// and splits don't affect them. Splits keep the decoration on the\n\t\t\t// original block (the new block has no decoration of its own).\n\t\t\treturn deco;\n\t\tcase 'merge':\n\t\t\t// Source block disappears as a separate block → its decoration is dropped.\n\t\t\treturn deco.blockId === stepMap.sourceBlockId ? null : deco;\n\t\tcase 'blockRemoval':\n\t\t\treturn stepMap.removedBlockIds.has(deco.blockId) ? null : deco;\n\t\tcase 'childIndexShift':\n\t\tcase 'moveNode':\n\t\t\treturn deco;\n\t}\n}\n","/**\n * Decoration types and DecorationSet for transient, view-only annotations.\n * Decorations are NOT part of the document model and do NOT affect undo/redo.\n */\n\nimport type { PluginCallbackRegistration } from '../model/PluginCallbackExecutor.js';\nimport type { BlockId } from '../model/TypeBrands.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport { mapDecorationThroughStepMap } from './PositionMapping.js';\n\n// --- Decoration Attrs ---\n\nexport interface DecorationAttrs {\n\treadonly class?: string;\n\treadonly style?: string;\n\treadonly nodeName?: string;\n\treadonly [key: string]: string | undefined;\n}\n\n// --- Decoration Types ---\n\nconst WIDGET_CALLBACK_OWNER: unique symbol = Symbol('notectl.widget-callback-owner');\n\nexport interface InlineDecoration {\n\treadonly type: 'inline';\n\treadonly blockId: BlockId;\n\treadonly from: number;\n\treadonly to: number;\n\treadonly attrs: DecorationAttrs;\n}\n\nexport interface NodeDecoration {\n\treadonly type: 'node';\n\treadonly blockId: BlockId;\n\treadonly attrs: DecorationAttrs;\n}\n\nexport interface WidgetDecoration {\n\treadonly type: 'widget';\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n\treadonly toDOM: () => HTMLElement;\n\treadonly side: -1 | 1;\n\treadonly key?: string;\n\t/** Plugin ownership attached by PluginLifecycle before the decoration reaches the view. */\n\treadonly [WIDGET_CALLBACK_OWNER]?: PluginCallbackRegistration;\n}\n\nexport type Decoration = InlineDecoration | NodeDecoration | WidgetDecoration;\n\n/** Returns lifecycle-owned attribution for a widget renderer, when available. */\nexport function getWidgetCallbackOwner(\n\tdecoration: WidgetDecoration,\n): PluginCallbackRegistration | undefined {\n\treturn decoration[WIDGET_CALLBACK_OWNER];\n}\n\n// --- Factory Functions ---\n\n/** Creates an inline decoration for a text range within a block. */\nexport function inline(\n\tblockId: BlockId,\n\tfrom: number,\n\tto: number,\n\tattrs: DecorationAttrs,\n): InlineDecoration {\n\treturn { type: 'inline', blockId, from, to, attrs };\n}\n\n/** Creates a node decoration that applies to a whole block element. */\nexport function node(blockId: BlockId, attrs: DecorationAttrs): NodeDecoration {\n\treturn { type: 'node', blockId, attrs };\n}\n\n/** Creates a widget decoration that inserts a DOM element at a position. */\nexport function widget(\n\tblockId: BlockId,\n\toffset: number,\n\ttoDOM: () => HTMLElement,\n\toptions?: { readonly side?: -1 | 1; readonly key?: string },\n): WidgetDecoration {\n\treturn {\n\t\ttype: 'widget',\n\t\tblockId,\n\t\toffset,\n\t\ttoDOM,\n\t\tside: options?.side ?? -1,\n\t\tkey: options?.key,\n\t};\n}\n\n// --- DecorationSet ---\n\n/**\n * Immutable set of decorations indexed by block ID.\n * Provides efficient lookup and merging of decoration collections.\n */\nexport class DecorationSet {\n\tstatic readonly empty: DecorationSet = new DecorationSet(new Map());\n\n\tprivate constructor(private readonly byBlock: ReadonlyMap<BlockId, readonly Decoration[]>) {}\n\n\t/** Creates a DecorationSet from a flat array of decorations. */\n\tstatic create(decorations: readonly Decoration[]): DecorationSet {\n\t\tif (decorations.length === 0) return DecorationSet.empty;\n\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const deco of decorations) {\n\t\t\tconst existing = map.get(deco.blockId);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(deco);\n\t\t\t} else {\n\t\t\t\tmap.set(deco.blockId, [deco]);\n\t\t\t}\n\t\t}\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Returns all decorations for a given block. */\n\tfind(blockId: BlockId): readonly Decoration[] {\n\t\treturn this.byBlock.get(blockId) ?? [];\n\t}\n\n\t/** Returns only inline decorations for a given block. */\n\tfindInline(blockId: BlockId): readonly InlineDecoration[] {\n\t\tconst decos = this.byBlock.get(blockId);\n\t\tif (!decos) return [];\n\t\treturn decos.filter((d): d is InlineDecoration => d.type === 'inline');\n\t}\n\n\t/** Returns only node decorations for a given block. */\n\tfindNode(blockId: BlockId): readonly NodeDecoration[] {\n\t\tconst decos = this.byBlock.get(blockId);\n\t\tif (!decos) return [];\n\t\treturn decos.filter((d): d is NodeDecoration => d.type === 'node');\n\t}\n\n\t/** Returns only widget decorations for a given block. */\n\tfindWidget(blockId: BlockId): readonly WidgetDecoration[] {\n\t\tconst decos = this.byBlock.get(blockId);\n\t\tif (!decos) return [];\n\t\treturn decos.filter((d): d is WidgetDecoration => d.type === 'widget');\n\t}\n\n\t/** Returns a new DecorationSet with the given decorations added. */\n\tadd(decorations: readonly Decoration[]): DecorationSet {\n\t\tif (decorations.length === 0) return this;\n\t\tif (this.isEmpty) return DecorationSet.create(decorations);\n\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tmap.set(bid, [...decos]);\n\t\t}\n\t\tfor (const deco of decorations) {\n\t\t\tconst existing = map.get(deco.blockId);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(deco);\n\t\t\t} else {\n\t\t\t\tmap.set(deco.blockId, [deco]);\n\t\t\t}\n\t\t}\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Returns a new DecorationSet with decorations matching the predicate removed. */\n\tremove(predicate: (d: Decoration) => boolean): DecorationSet {\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tlet changed = false;\n\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tconst filtered = decos.filter((d) => !predicate(d));\n\t\t\tif (filtered.length !== decos.length) changed = true;\n\t\t\tif (filtered.length > 0) {\n\t\t\t\tmap.set(bid, filtered);\n\t\t\t}\n\t\t}\n\n\t\tif (!changed) return this;\n\t\tif (map.size === 0) return DecorationSet.empty;\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Returns a new DecorationSet merging this set with another. */\n\tmerge(other: DecorationSet): DecorationSet {\n\t\tif (other.isEmpty) return this;\n\t\tif (this.isEmpty) return other;\n\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tmap.set(bid, [...decos]);\n\t\t}\n\t\tfor (const [bid, decos] of other.byBlock) {\n\t\t\tconst existing = map.get(bid);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(...decos);\n\t\t\t} else {\n\t\t\t\tmap.set(bid, [...decos]);\n\t\t\t}\n\t\t}\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Attaches plugin attribution to widget callbacks without mutating plugin-owned objects. */\n\twithWidgetOwner(pluginId: string): DecorationSet {\n\t\tlet changed = false;\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const [bid, decorations] of this.byBlock) {\n\t\t\tconst attributed = decorations.map((decoration): Decoration => {\n\t\t\t\tif (decoration.type !== 'widget') return decoration;\n\t\t\t\tchanged = true;\n\t\t\t\treturn {\n\t\t\t\t\t...decoration,\n\t\t\t\t\t[WIDGET_CALLBACK_OWNER]: { pluginId, name: 'widget' },\n\t\t\t\t};\n\t\t\t});\n\t\t\tmap.set(bid, attributed);\n\t\t}\n\t\treturn changed ? new DecorationSet(map) : this;\n\t}\n\n\t/** Checks equality — reference first, then structural comparison. */\n\tequals(other: DecorationSet): boolean {\n\t\tif (this === other) return true;\n\t\tif (this.byBlock.size !== other.byBlock.size) return false;\n\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tconst otherDecos = other.byBlock.get(bid);\n\t\t\tif (!otherDecos) return false;\n\t\t\tif (!decorationArraysEqual(decos, otherDecos)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** True if the set contains no decorations. */\n\tget isEmpty(): boolean {\n\t\treturn this.byBlock.size === 0;\n\t}\n\n\t/**\n\t * Maps decorations through document changes described by a transaction.\n\t * Decorations that become invalid (e.g. fully deleted range) are removed.\n\t * Decorations that span a split point are split into two.\n\t *\n\t * Iterates over `tr.mapping.maps` (the position-space {@link StepMap}s)\n\t * rather than `tr.steps`. This means selection-only or other identity\n\t * transactions short-circuit (`tr.mapping.isEmpty`) without rebuilding\n\t * the set, and the decoration-specific shape concerns (split-into-two,\n\t * drop-on-block-removal) are the only logic that lives here.\n\t */\n\tmap(tr: Transaction): DecorationSet {\n\t\tif (this.isEmpty || tr.mapping.isEmpty) return this;\n\n\t\tlet mapped: Decoration[] = [];\n\t\tfor (const decos of this.byBlock.values()) {\n\t\t\tfor (const d of decos) {\n\t\t\t\tmapped.push(d);\n\t\t\t}\n\t\t}\n\n\t\tfor (const stepMap of tr.mapping.maps) {\n\t\t\tconst next: Decoration[] = [];\n\t\t\tfor (const deco of mapped) {\n\t\t\t\tconst result = mapDecorationThroughStepMap(deco, stepMap);\n\t\t\t\tif (result === null) continue;\n\t\t\t\tif (Array.isArray(result)) {\n\t\t\t\t\tfor (const r of result) {\n\t\t\t\t\t\tnext.push(r);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnext.push(result as Decoration);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmapped = next;\n\t\t}\n\n\t\tif (mapped.length === 0) return DecorationSet.empty;\n\t\treturn DecorationSet.create(mapped);\n\t}\n}\n\n// --- Helpers ---\n\n/** Compares two decoration arrays for structural equality. */\nexport function decorationArraysEqual(a: readonly Decoration[], b: readonly Decoration[]): boolean {\n\tif (a === b) return true;\n\tif (a.length !== b.length) return false;\n\n\tfor (let i = 0; i < a.length; i++) {\n\t\tconst ai = a[i];\n\t\tconst bi = b[i];\n\t\tif (!ai || !bi || !decorationsEqual(ai, bi)) return false;\n\t}\n\treturn true;\n}\n\n/** Compares two individual decorations for structural equality. */\nfunction decorationsEqual(a: Decoration, b: Decoration): boolean {\n\tif (a.type !== b.type) return false;\n\tif (a.blockId !== b.blockId) return false;\n\n\tswitch (a.type) {\n\t\tcase 'inline': {\n\t\t\tconst bi = b as InlineDecoration;\n\t\t\treturn a.from === bi.from && a.to === bi.to && attrsEqual(a.attrs, bi.attrs);\n\t\t}\n\t\tcase 'node': {\n\t\t\tconst bn = b as NodeDecoration;\n\t\t\treturn attrsEqual(a.attrs, bn.attrs);\n\t\t}\n\t\tcase 'widget': {\n\t\t\tconst bw = b as WidgetDecoration;\n\t\t\tconst sameIdentity: boolean =\n\t\t\t\ta.key !== undefined || bw.key !== undefined ? a.key === bw.key : a.toDOM === bw.toDOM;\n\t\t\treturn a.offset === bw.offset && a.side === bw.side && a.key === bw.key && sameIdentity;\n\t\t}\n\t}\n}\n\n/** Compares two DecorationAttrs objects. */\nfunction attrsEqual(a: DecorationAttrs, b: DecorationAttrs): boolean {\n\tif (a === b) return true;\n\tconst aKeys = Object.keys(a);\n\tconst bKeys = Object.keys(b);\n\tif (aKeys.length !== bKeys.length) return false;\n\tfor (const key of aKeys) {\n\t\tif (a[key] !== b[key]) return false;\n\t}\n\treturn true;\n}\n"],"mappings":"yFAoNA,IAAa,EAA4B,OAAO,OAAO,CAAE,KAAM,aAUzD,EAAN,MACC,GAEA,WAAA,CAAY,GACX,MAAKA,EAAU,IAAI,IAAI,GACvB,OAAO,OAAO,KACf,CAEA,QAAI,GACH,OAAO,MAAKA,EAAQ,IACrB,CAEA,GAAA,CAAI,GACH,OAAO,MAAKA,EAAQ,IAAI,EACzB,CAEA,OAAA,GACC,OAAO,MAAKA,EAAQ,SACrB,CAEA,IAAA,GACC,OAAO,MAAKA,EAAQ,MACrB,CAEA,MAAA,GACC,OAAO,MAAKA,EAAQ,QACrB,CAEA,CAAC,OAAO,YACP,OAAO,MAAKA,EAAQ,OAAO,WAC5B,CAEA,OAAA,CAAQ,EAA8D,GACrE,IAAK,MAAM,KAAS,MAAKA,EAAS,EAAS,KAAK,EAAS,EAAO,EAAO,KACxE,CAEA,KAAA,CAAS;AACR,OAAO,IAAI,IAAW,IAAI,MAAKA,KAAY,EAAc,IAC1D,CAEA,YAAA,CAAgB,GACf,MAAM,EAAc,EAAc,GAC5B,iBAAe,IAAI,IACzB,IAAK,MAAM,KAAS,MAAKA,EACpB,EAAY,EAAa,IAAQ,EAAa,IAAI,GAEvD,OAAO,CACR,CAEA,UAAA,CAAc,GACb,MAAM,EAAc,EAAc,GAClC,OAAO,IAAI,IAAI,IAAI,MAAKA,GAAS,OAAQ,IAAW,EAAY,EAAa,IAC9E,CAEA,mBAAA,CAAuB,GACtB,MAAM,EAAc,EAAc,GAC5B,iBAAa,IAAI,IACvB,IAAK,MAAM,KAAS,MAAKA,EACnB,EAAY,EAAa,IAAQ,EAAW,IAAI,GAEtD,IAAK,MAAM,KAAS,EACd,EAAY,MAAKA,EAAS,IAAQ,EAAW,IAAI,GAEvD,OAAO,CACR,CAEA,UAAA,CAAW,GACV,MAAM,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AAO,KAAK,GAC1B,GAAI,EAAM,SAAW,EAAM,OAAQ,OAAO,EAC1C,IAAK,MAAM,KAAO,EACjB,GAAI,EAAE,KAAS,EAAE,GAAM,OAAO,EAE/B,OAAO,CACR"}
|
|
1
|
+
{"version":3,"file":"Decoration-BoFcdSXk.mjs","names":["#values"],"sources":["../../src/state/Mapping.ts","../../src/decorations/PositionMapping.ts","../../src/decorations/Decoration.ts"],"sourcesContent":["/**\n * Generic position-mapping primitive.\n *\n * Each {@link Step} produces a {@link StepMap} that describes how positions\n * in `{blockId, offset}` space shift when the step is applied. A\n * {@link Mapping} composes a sequence of `StepMap`s — typically all the maps\n * of a transaction — into a single mapper, so any consumer (decorations,\n * comments, selections, remote cursors, history) can fold a position\n * through an entire change set without re-implementing per-step math.\n *\n * The model mirrors ProseMirror's `StepMap` / `Mapping`, adapted to\n * notectl's `{blockId, offset}` position space (positions are scoped to\n * blocks, not a flat document offset).\n *\n * ## Association (bias) semantics\n *\n * The optional `assoc` argument decides which side of a boundary a position\n * sticks to:\n *\n * - `assoc = -1` (\"sticky left\"): the position stays at the boundary when\n * content is inserted at, or split exactly at, the position. This is the\n * semantics expected by an inclusive-start range marker (a decoration's\n * `from`, the left edge of a selection).\n * - `assoc = +1` (\"sticky right\"): the position moves past inserted content\n * and migrates to the new block when its host block is split exactly at\n * the position. This is the semantics expected by an exclusive-end range\n * marker (a decoration's `to`, the right edge of a selection).\n *\n * The default is `-1`, matching the most common case (cursor and from-side\n * mappers).\n *\n * ## StepMap categories\n *\n * Every {@link Step} produces exactly one of six categories:\n *\n * 1. `identity` — no position shift (mark, attribute, schema, block-type).\n * 2. `shift` — within a single block, the range `[from, to)` is replaced\n * with content of length `newLen`. Covers `insertText`, `deleteText`,\n * `insertInlineNode`, `removeInlineNode` as a single primitive.\n * 3. `split` — a block is split at an offset; positions past the split\n * migrate to the new block with rebased offsets.\n * 4. `merge` — a source block is appended to a target block; positions in\n * the source block migrate to the target block with offsets shifted by\n * the target's previous length.\n * 5. `blockRemoval` — one block subtree vanishes; positions inside any\n * removed block are marked deleted, and sibling child-indices in the\n * same parent shift down by one past the removed index.\n * 6. `childIndexShift` — a new block was inserted at `fromIndex` in\n * `parentPath`'s children; sibling child-indices `≥ fromIndex` shift up.\n * Position space ({blockId, offset}) is unaffected.\n *\n * `blockRemoval` and `childIndexShift` are the two categories that carry\n * **structural** information about a parent's child list. They are\n * orthogonal to positions ({blockId, offset}) and are interpreted by\n * {@link mapChildIndex} when rebasing tree-structural steps\n * (`insertNode` / `removeNode`).\n */\n\nimport { isBlockNode } from '../model/Document.js';\nimport type { BlockNode } from '../model/Document.js';\nimport type { Position } from '../model/Selection.js';\nimport { createPosition } from '../model/Selection.js';\nimport type { BlockId } from '../model/TypeBrands.js';\n\n/**\n * Result of mapping an `(blockId, [from, to))` range through a {@link Mapping}.\n *\n * Both endpoints are guaranteed to live in the same block. Callers can rely\n * on `from <= to` (the helper returns `null` rather than producing an\n * inverted range).\n */\nexport interface MappedInBlockRange {\n\treadonly blockId: BlockId;\n\treadonly from: number;\n\treadonly to: number;\n}\n\n/** Position-mapping bias at a boundary. */\nexport type Assoc = -1 | 1;\n\n// --- StepMap variants ---\n\n/** No-op map: positions pass through unchanged. */\nexport interface IdentityMap {\n\treadonly type: 'identity';\n}\n\n/**\n * Within `blockId`, the offset range `[from, to)` is replaced with content\n * of length `newLen`. Covers all in-block content edits with a single\n * primitive:\n *\n * - `insertText(blockId, off, text)` → `{from: off, to: off, newLen: text.length}`.\n * - `deleteText(blockId, f, t)` → `{from: f, to: t, newLen: 0}`.\n * - `insertInlineNode(blockId, off)` → `{from: off, to: off, newLen: 1}`.\n * - `removeInlineNode(blockId, off)` → `{from: off, to: off + 1, newLen: 0}`.\n */\nexport interface ShiftMap {\n\treadonly type: 'shift';\n\treadonly blockId: BlockId;\n\treadonly from: number;\n\treadonly to: number;\n\treadonly newLen: number;\n}\n\n/**\n * A block is split at `offset`. Content `[0, offset)` stays in `blockId`;\n * content `[offset, length)` migrates to `newBlockId` rebased to start at 0.\n */\nexport interface SplitMap {\n\treadonly type: 'split';\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n\treadonly newBlockId: BlockId;\n}\n\n/**\n * `sourceBlockId` is appended to `targetBlockId`. Positions in the source\n * block migrate to the target block with offset shifted by\n * `targetLengthBefore` (the target's length before the merge).\n */\nexport interface MergeMap {\n\treadonly type: 'merge';\n\treadonly targetBlockId: BlockId;\n\treadonly sourceBlockId: BlockId;\n\treadonly targetLengthBefore: number;\n}\n\n/**\n * A block subtree is removed from the document. Positions whose `blockId`\n * is in `removedBlockIds` are marked deleted; `removedBlockIds` covers the\n * removed root **plus all descendant block IDs** (see\n * {@link collectRemovedBlockIds}).\n *\n * `parentPath` and `index` carry the removal's structural coordinates so\n * sibling child-indices in the same parent can be rebased: any\n * `(parentPath, i)` with `i === index` becomes invalid (the block is gone),\n * and `i > index` shifts down by one. See {@link mapChildIndex}.\n */\nexport interface BlockRemovalMap {\n\treadonly type: 'blockRemoval';\n\treadonly removedBlockIds: ReadonlySet<BlockId>;\n\treadonly parentPath: readonly BlockId[];\n\treadonly index: number;\n}\n\n/**\n * A new block was inserted at `fromIndex` in `parentPath`'s child list.\n * Sibling child-indices `≥ fromIndex` shift up by `delta` (always `+1`\n * since {@link InsertNodeStep} inserts a single block). Position space\n * (`{blockId, offset}`) is unaffected — the new block has no prior\n * positions, and positions inside other siblings keep their offsets.\n *\n * Consumed by {@link mapChildIndex}, {@link mapInsertionIndex}, and exact\n * structural inverse detection during history replay.\n */\nexport interface ChildIndexShiftMap {\n\treadonly type: 'childIndexShift';\n\treadonly parentPath: readonly BlockId[];\n\treadonly fromIndex: number;\n\treadonly delta: number;\n\t/**\n\t * IDs introduced by an InsertNodeStep. Optional for synthetic/test maps;\n\t * when present it makes the map an exact structural inverse of the matching\n\t * BlockRemovalMap during history replay.\n\t */\n\treadonly insertedBlockIds?: ReadonlySet<BlockId>;\n}\n\n/**\n * One existing subtree moves between child lists. Positions inside the moved\n * subtree keep their block IDs and offsets; sibling child indices in both\n * parents are shifted by the removal followed by the insertion.\n */\nexport interface MoveNodeMap {\n\treadonly type: 'moveNode';\n\treadonly movedNodeId: BlockId;\n\treadonly fromParentPath: readonly BlockId[];\n\treadonly fromIndex: number;\n\treadonly toParentPath: readonly BlockId[];\n\t/** Destination index after removing the source node. */\n\treadonly destinationIndex: number;\n}\n\n/** Discriminated union of all StepMap variants. */\nexport type StepMap =\n\t| IdentityMap\n\t| ShiftMap\n\t| SplitMap\n\t| MergeMap\n\t| BlockRemovalMap\n\t| ChildIndexShiftMap\n\t| MoveNodeMap;\n\n// --- Map results ---\n\n/** Result of mapping a single position. */\nexport interface MapResult {\n\treadonly pos: Position;\n\t/** True if the input position fell inside content removed by the map. */\n\treadonly deleted: boolean;\n}\n\n/** A range expressed in `Position` space. */\nexport interface PositionRange {\n\treadonly from: Position;\n\treadonly to: Position;\n}\n\n// --- Singletons / factories ---\n\n/** The shared identity StepMap; reuse instead of allocating per step. */\nexport const IDENTITY_MAP: IdentityMap = Object.freeze({ type: 'identity' });\n\n/**\n * Runtime-immutable ReadonlySet facade.\n *\n * `Object.freeze(new Set())` only freezes the wrapper object; its internal\n * slots remain mutable through `add`, `delete`, and `clear`. Keeping the real\n * Set in an ECMAScript private field and exposing only ReadonlySet operations\n * makes structural StepMap snapshots immutable at runtime as well as by type.\n */\nclass ImmutableReadonlySet<T> implements ReadonlySet<T> {\n\treadonly #values: Set<T>;\n\n\tconstructor(values: Iterable<T>) {\n\t\tthis.#values = new Set(values);\n\t\tObject.freeze(this);\n\t}\n\n\tget size(): number {\n\t\treturn this.#values.size;\n\t}\n\n\thas(value: T): boolean {\n\t\treturn this.#values.has(value);\n\t}\n\n\tentries(): SetIterator<[T, T]> {\n\t\treturn this.#values.entries();\n\t}\n\n\tkeys(): SetIterator<T> {\n\t\treturn this.#values.keys();\n\t}\n\n\tvalues(): SetIterator<T> {\n\t\treturn this.#values.values();\n\t}\n\n\t[Symbol.iterator](): SetIterator<T> {\n\t\treturn this.#values[Symbol.iterator]();\n\t}\n\n\tforEach(callback: (value: T, value2: T, set: ReadonlySet<T>) => void, thisArg?: unknown): void {\n\t\tfor (const value of this.#values) callback.call(thisArg, value, value, this);\n\t}\n\n\tunion<U>(other: ReadonlySetLike<U>): Set<T | U> {\n\t\treturn new Set<T | U>([...this.#values, ...setLikeValues(other)]);\n\t}\n\n\tintersection<U>(other: ReadonlySetLike<U>): Set<T & U> {\n\t\tconst otherValues = setLikeValues(other);\n\t\tconst intersection = new Set<T & U>();\n\t\tfor (const value of this.#values) {\n\t\t\tif (hasSetValue(otherValues, value)) intersection.add(value as T & U);\n\t\t}\n\t\treturn intersection;\n\t}\n\n\tdifference<U>(other: ReadonlySetLike<U>): Set<T> {\n\t\tconst otherValues = setLikeValues(other);\n\t\treturn new Set([...this.#values].filter((value) => !hasSetValue(otherValues, value)));\n\t}\n\n\tsymmetricDifference<U>(other: ReadonlySetLike<U>): Set<T | U> {\n\t\tconst otherValues = setLikeValues(other);\n\t\tconst difference = new Set<T | U>();\n\t\tfor (const value of this.#values) {\n\t\t\tif (!hasSetValue(otherValues, value)) difference.add(value);\n\t\t}\n\t\tfor (const value of otherValues) {\n\t\t\tif (!hasSetValue(this.#values, value)) difference.add(value);\n\t\t}\n\t\treturn difference;\n\t}\n\n\tisSubsetOf(other: ReadonlySetLike<unknown>): boolean {\n\t\tconst otherValues = setLikeValues(other);\n\t\tfor (const value of this.#values) {\n\t\t\tif (!otherValues.has(value)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tisSupersetOf(other: ReadonlySetLike<unknown>): boolean {\n\t\tfor (const value of setLikeValues(other)) {\n\t\t\tif (!hasSetValue(this.#values, value)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tisDisjointFrom(other: ReadonlySetLike<unknown>): boolean {\n\t\tfor (const value of setLikeValues(other)) {\n\t\t\tif (hasSetValue(this.#values, value)) return false;\n\t\t}\n\t\treturn true;\n\t}\n}\n\nfunction setLikeValues<T>(values: ReadonlySetLike<T>): Set<T> {\n\tconst copy = new Set<T>();\n\tconst iterator = values.keys();\n\tfor (let next = iterator.next(); !next.done; next = iterator.next()) copy.add(next.value);\n\treturn copy;\n}\n\nfunction hasSetValue(values: ReadonlySetLike<unknown>, value: unknown): boolean {\n\treturn values.has(value);\n}\n\n/** Creates a detached, deeply immutable snapshot of a StepMap payload. */\nexport function snapshotStepMap(stepMap: StepMap): StepMap {\n\tswitch (stepMap.type) {\n\t\tcase 'identity':\n\t\t\treturn IDENTITY_MAP;\n\t\tcase 'blockRemoval':\n\t\t\treturn Object.freeze({\n\t\t\t\t...stepMap,\n\t\t\t\tremovedBlockIds: new ImmutableReadonlySet(stepMap.removedBlockIds),\n\t\t\t\tparentPath: Object.freeze([...stepMap.parentPath]),\n\t\t\t});\n\t\tcase 'childIndexShift':\n\t\t\treturn Object.freeze({\n\t\t\t\t...stepMap,\n\t\t\t\tparentPath: Object.freeze([...stepMap.parentPath]),\n\t\t\t\t...(stepMap.insertedBlockIds\n\t\t\t\t\t? { insertedBlockIds: new ImmutableReadonlySet(stepMap.insertedBlockIds) }\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\tcase 'moveNode':\n\t\t\treturn Object.freeze({\n\t\t\t\t...stepMap,\n\t\t\t\tfromParentPath: Object.freeze([...stepMap.fromParentPath]),\n\t\t\t\ttoParentPath: Object.freeze([...stepMap.toParentPath]),\n\t\t\t});\n\t\tdefault:\n\t\t\treturn Object.freeze({ ...stepMap });\n\t}\n}\n\n/**\n * Walks a block subtree and returns the set of its own ID plus every\n * descendant block ID. Used to build {@link BlockRemovalMap.removedBlockIds}.\n */\nexport function collectRemovedBlockIds(node: BlockNode): Set<BlockId> {\n\tconst ids = new Set<BlockId>();\n\tconst walk = (n: BlockNode): void => {\n\t\tids.add(n.id);\n\t\tfor (const child of n.children) {\n\t\t\tif (isBlockNode(child)) walk(child);\n\t\t}\n\t};\n\twalk(node);\n\treturn ids;\n}\n\n// --- Single-StepMap application ---\n\n/**\n * Maps a single position through one {@link StepMap}.\n *\n * @param pos input position\n * @param map the StepMap describing the change\n * @param assoc which side of a boundary to stick to (default `-1`)\n * @returns mapped position plus a `deleted` flag indicating whether `pos`\n * fell inside content that the step removed\n */\nexport function mapPositionThroughStep(pos: Position, map: StepMap, assoc: Assoc = -1): MapResult {\n\tswitch (map.type) {\n\t\tcase 'identity':\n\t\t\treturn { pos, deleted: false };\n\t\tcase 'shift':\n\t\t\treturn mapPositionThroughShift(pos, map, assoc);\n\t\tcase 'split':\n\t\t\treturn mapPositionThroughSplit(pos, map, assoc);\n\t\tcase 'merge':\n\t\t\treturn mapPositionThroughMerge(pos, map);\n\t\tcase 'blockRemoval':\n\t\t\treturn mapPositionThroughBlockRemoval(pos, map);\n\t\tcase 'childIndexShift':\n\t\t\t// Child-index shifts do not touch position space ({blockId, offset}):\n\t\t\t// a new sibling block has no prior positions to map, and existing\n\t\t\t// siblings keep their internal offsets even if their parent-relative\n\t\t\t// index changed. Consumed only by {@link mapChildIndex}.\n\t\t\treturn { pos, deleted: false };\n\t\tcase 'moveNode':\n\t\t\t// A move preserves block identity and in-block offsets. Structural\n\t\t\t// child-index consumers handle the parent-list shifts separately.\n\t\t\treturn { pos, deleted: false };\n\t}\n}\n\nfunction mapPositionThroughShift(pos: Position, map: ShiftMap, assoc: Assoc): MapResult {\n\tif (pos.blockId !== map.blockId) return { pos, deleted: false };\n\n\tconst delta: number = map.newLen - (map.to - map.from);\n\tconst off: number = pos.offset;\n\n\t// Strictly before the affected range\n\tif (off < map.from) return { pos, deleted: false };\n\n\t// At the start boundary\n\tif (off === map.from) {\n\t\t// Pure insertion (from === to): assoc decides whether we stick before\n\t\t// or after the inserted run.\n\t\tif (map.from === map.to) {\n\t\t\tconst newOff: number = assoc === 1 ? map.from + map.newLen : map.from;\n\t\t\treturn newOff === off\n\t\t\t\t? { pos, deleted: false }\n\t\t\t\t: { pos: shiftedPos(pos, newOff), deleted: false };\n\t\t}\n\t\t// Deletion starts at this point — position stays at `from` regardless\n\t\t// of assoc; nothing was inserted to skip past.\n\t\treturn { pos, deleted: false };\n\t}\n\n\t// Strictly inside [from, to): position fell into removed content\n\tif (off < map.to) {\n\t\tconst newOff: number = assoc === 1 ? map.from + map.newLen : map.from;\n\t\treturn { pos: shiftedPos(pos, newOff), deleted: true };\n\t}\n\n\t// At or past the end boundary: shift by delta\n\tconst newOff: number = off + delta;\n\treturn newOff === off\n\t\t? { pos, deleted: false }\n\t\t: { pos: shiftedPos(pos, newOff), deleted: false };\n}\n\nfunction mapPositionThroughSplit(pos: Position, map: SplitMap, assoc: Assoc): MapResult {\n\tif (pos.blockId !== map.blockId) return { pos, deleted: false };\n\n\tif (pos.offset < map.offset) return { pos, deleted: false };\n\n\tif (pos.offset > map.offset) {\n\t\treturn {\n\t\t\tpos: createPosition(map.newBlockId, pos.offset - map.offset),\n\t\t\tdeleted: false,\n\t\t};\n\t}\n\n\t// At the split boundary: assoc decides which side keeps the cursor.\n\tif (assoc === 1) {\n\t\treturn { pos: createPosition(map.newBlockId, 0), deleted: false };\n\t}\n\treturn { pos, deleted: false };\n}\n\nfunction mapPositionThroughMerge(pos: Position, map: MergeMap): MapResult {\n\tif (pos.blockId !== map.sourceBlockId) return { pos, deleted: false };\n\treturn {\n\t\tpos: createPosition(map.targetBlockId, pos.offset + map.targetLengthBefore),\n\t\tdeleted: false,\n\t};\n}\n\nfunction mapPositionThroughBlockRemoval(pos: Position, map: BlockRemovalMap): MapResult {\n\tif (map.removedBlockIds.has(pos.blockId)) {\n\t\treturn { pos, deleted: true };\n\t}\n\treturn { pos, deleted: false };\n}\n\n/** Allocates a new Position with the given offset, preserving an optional `path`. */\nfunction shiftedPos(original: Position, newOffset: number): Position {\n\treturn createPosition(original.blockId, newOffset, original.path);\n}\n\n// --- Mapping ---\n\n/**\n * Composes a sequence of {@link StepMap}s into a single mapper. A `Mapping`\n * is immutable; `appendMap` returns a new instance.\n *\n * Construction always normalizes by dropping identity maps — they're a\n * common case and would otherwise inflate every transaction's mapping\n * pipeline with no-ops.\n */\nexport class Mapping {\n\t/** Shared empty Mapping. */\n\tstatic readonly empty: Mapping = new Mapping([]);\n\n\treadonly maps: readonly StepMap[];\n\n\tprivate constructor(maps: readonly StepMap[]) {\n\t\tthis.maps = Object.freeze(maps.map(snapshotStepMap));\n\t\tObject.freeze(this);\n\t}\n\n\t/** Creates a Mapping from a list of StepMaps, dropping identity maps. */\n\tstatic from(maps: readonly StepMap[]): Mapping {\n\t\tconst filtered: StepMap[] = [];\n\t\tfor (const m of maps) {\n\t\t\tif (m.type !== 'identity') filtered.push(m);\n\t\t}\n\t\tif (filtered.length === 0) return Mapping.empty;\n\t\treturn new Mapping(filtered);\n\t}\n\n\t/** Returns a new Mapping with `map` appended. */\n\tappendMap(map: StepMap): Mapping {\n\t\tif (map.type === 'identity') return this;\n\t\treturn new Mapping([...this.maps, map]);\n\t}\n\n\t/** Concatenates two mappings into a new one. */\n\tappendMapping(other: Mapping): Mapping {\n\t\tif (other.maps.length === 0) return this;\n\t\tif (this.maps.length === 0) return other;\n\t\treturn new Mapping([...this.maps, ...other.maps]);\n\t}\n\n\t/** True if the mapping contains no position-changing maps. */\n\tget isEmpty(): boolean {\n\t\treturn this.maps.length === 0;\n\t}\n\n\t/**\n\t * Folds a position through every contained StepMap in order.\n\t * Returns the mapped position; the `deleted` flag is **not** preserved\n\t * (use {@link mapResult} when you need it).\n\t */\n\tmap(pos: Position, assoc: Assoc = -1): Position {\n\t\treturn this.mapResult(pos, assoc).pos;\n\t}\n\n\t/**\n\t * Like {@link map}, but returns whether the position is deleted in the final\n\t * frame. Content deletion remains sticky across every later map. Structural\n\t * deletion can be recovered by an `insertNode` map carrying the same block\n\t * ID; a later removal can mark that identity deleted again.\n\t */\n\tmapResult(pos: Position, assoc: Assoc = -1): MapResult {\n\t\tlet current: Position = pos;\n\t\tlet contentDeleted = false;\n\t\tlet structurallyDeleted = false;\n\t\tfor (const m of this.maps) {\n\t\t\tconst result: MapResult = mapPositionThroughStep(current, m, assoc);\n\t\t\tcurrent = result.pos;\n\t\t\tif (result.deleted) {\n\t\t\t\tif (m.type === 'blockRemoval') {\n\t\t\t\t\tstructurallyDeleted = true;\n\t\t\t\t} else {\n\t\t\t\t\tcontentDeleted = true;\n\t\t\t\t}\n\t\t\t} else if (m.type === 'childIndexShift' && m.insertedBlockIds?.has(current.blockId)) {\n\t\t\t\tstructurallyDeleted = false;\n\t\t\t}\n\t\t}\n\t\treturn { pos: current, deleted: contentDeleted || structurallyDeleted };\n\t}\n\n\t/**\n\t * Maps a range. By convention, `from` is mapped with `assoc = -1`\n\t * (inclusive-start) and `to` with `assoc = +1` (exclusive-end). The\n\t * caller may override either bias.\n\t *\n\t * Returns `null` when both endpoints land in deleted content **and** the\n\t * mapped range would collapse to length zero or negative — i.e. the\n\t * range no longer covers any live content.\n\t *\n\t * The returned `from`/`to` may live in different blocks (e.g. after a\n\t * `split` map). Callers that require an in-block range (decorations,\n\t * inline selections) must detect and split accordingly.\n\t */\n\tmapRange(range: PositionRange, assocFrom: Assoc = -1, assocTo: Assoc = 1): PositionRange | null {\n\t\tconst from: MapResult = this.mapResult(range.from, assocFrom);\n\t\tconst to: MapResult = this.mapResult(range.to, assocTo);\n\n\t\tif (from.deleted && to.deleted) {\n\t\t\tif (from.pos.blockId === to.pos.blockId && from.pos.offset >= to.pos.offset) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn { from: from.pos, to: to.pos };\n\t}\n}\n\n// --- In-block range helpers (used by per-step Step→Step mapping) ---\n\n/**\n * Maps an `(blockId, [from, to))` range through `mapping`, asserting the\n * result lives in a single block.\n *\n * Returns `null` when the range no longer addresses live content in a single\n * block:\n *\n * - the host block was removed;\n * - the range was fully deleted (both endpoints flagged deleted and collapse);\n * - the endpoints migrated to different blocks (range fragmented, e.g. a\n * `split` map placed `from` and `to` on opposite sides of the cut).\n *\n * Default biases are **conservative for step rebasing**: `assocFrom = +1`,\n * `assocTo = -1`. An intervening insertion at either boundary therefore\n * does NOT expand the rebased range to cover the new content — the user's\n * original edit only addressed the original content, and the agent's\n * intervening insertion should be preserved across an undo/redo. This is\n * the opposite of {@link Mapping.mapRange}'s default biases, which model\n * selections (inclusive-start, exclusive-end) where boundary insertions\n * naturally extend the selection.\n */\nexport function mapInBlockRange(\n\tblockId: BlockId,\n\tfrom: number,\n\tto: number,\n\tmapping: Mapping,\n\tassocFrom: Assoc = 1,\n\tassocTo: Assoc = -1,\n): MappedInBlockRange | null {\n\tif (mapping.isEmpty) return { blockId, from, to };\n\n\tconst fromPos: Position = createPosition(blockId, from);\n\tconst toPos: Position = createPosition(blockId, to);\n\tconst fromResult: MapResult = mapping.mapResult(fromPos, assocFrom);\n\tconst toResult: MapResult = mapping.mapResult(toPos, assocTo);\n\n\t// If both endpoints fell inside removed/replaced content, the range no\n\t// longer addresses live document territory — abandon. A partial overlap\n\t// (one endpoint deleted, the other shifted) still survives clamped.\n\tif (fromResult.deleted && toResult.deleted) return null;\n\n\t// Range must remain within a single block. A split could have moved one\n\t// endpoint to the new block; that's a fragmentation we cannot represent\n\t// as a single in-block step.\n\tif (fromResult.pos.blockId !== toResult.pos.blockId) return null;\n\n\t// Defensive: a range whose endpoints inverted (from > to) is invalid.\n\t// An empty range with from === to is still valid (e.g. a pure-insertion\n\t// `shift` whose offset survived).\n\tif (fromResult.pos.offset > toResult.pos.offset) return null;\n\n\treturn {\n\t\tblockId: fromResult.pos.blockId,\n\t\tfrom: fromResult.pos.offset,\n\t\tto: toResult.pos.offset,\n\t};\n}\n\n/**\n * Maps an `(blockId, offset)` point through `mapping`, returning the\n * equivalent in-block position or `null` when the host block was removed.\n *\n * Convenience wrapper around {@link mapInBlockRange} for steps that carry a\n * single offset (`insertText`, `insertInlineNode`, `splitBlock`).\n */\nexport function mapOffsetInBlock(\n\tblockId: BlockId,\n\toffset: number,\n\tmapping: Mapping,\n\tassoc: Assoc = -1,\n): MappedInBlockRange | null {\n\tif (mapping.isEmpty) return { blockId, from: offset, to: offset };\n\n\tconst pos: Position = createPosition(blockId, offset);\n\tconst result: MapResult = mapping.mapResult(pos, assoc);\n\tif (result.deleted) return null;\n\treturn { blockId: result.pos.blockId, from: result.pos.offset, to: result.pos.offset };\n}\n\n// --- Child-index mapping (used by structural step rebasing) ---\n\n/**\n * Rebases a child-index `(parentPath, index)` through `mapping`. The\n * `index` is interpreted as the position of an **existing** child block:\n * if an intervening edit removed exactly that child, the result is\n * `null`. For an **insertion slot** (the target index of a future\n * `insertNode`), use {@link mapInsertionIndex} — slots stay valid even\n * when the block previously at that index is removed.\n *\n * Child-indices live in a coordinate space orthogonal to positions\n * (`{blockId, offset}`): they describe a slot in a parent's child list,\n * not a place inside text. Three {@link StepMap} categories carry\n * child-index-affecting information:\n *\n * - {@link ChildIndexShiftMap} (produced by `insertNode`): shifts\n * sibling indices `≥ fromIndex` by `delta` (always `+1` today).\n * - {@link BlockRemovalMap} (produced by `removeNode`): removes the child\n * at `index` (the input index becomes invalid → `null`), and shifts\n * sibling indices `> index` down by `1`.\n * - {@link MoveNodeMap} (produced by `moveNode`): combines the source removal\n * and destination insertion while preserving the moved subtree's identity.\n *\n * Maps whose `parentPath` differs from the input pass through; all\n * non-structural categories (`shift`, `split`, `merge`, `identity`) are\n * no-ops here.\n */\nexport function mapChildIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n): number | null {\n\treturn foldChildIndex(parentPath, index, mapping, 'existing');\n}\n\n/**\n * Rebases an **insertion slot** `(parentPath, index)` through `mapping`.\n * An insertion slot lives in `[0, children.length]` (inclusive of the\n * end) and represents \"where to insert\", not an existing block. Slots\n * remain valid across intervening edits — even when the block previously\n * at that index is removed — so this function never returns `null`.\n *\n * Difference from {@link mapChildIndex}: for a `BlockRemovalMap` with\n * matching parent and `index === map.index`, this function keeps the\n * slot (returning `map.index`, which is the same numeric position in the\n * post-removal frame); {@link mapChildIndex} would return `null`.\n * {@link ChildIndexShiftMap} handling is identical.\n */\nexport function mapInsertionIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n): number {\n\t// `foldChildIndex` with `'insertion'` provably never returns `null` —\n\t// the only path that would (BlockRemovalMap, matching parent, matching\n\t// index) is short-circuited inside `mapChildIndexThroughStep`. The\n\t// overload signature carries that invariant into the type system.\n\treturn foldChildIndex(parentPath, index, mapping, 'insertion');\n}\n\ntype ChildIndexKind = 'existing' | 'insertion';\n\nfunction foldChildIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n\tkind: 'existing',\n): number | null;\nfunction foldChildIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n\tkind: 'insertion',\n): number;\nfunction foldChildIndex(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmapping: Mapping,\n\tkind: ChildIndexKind,\n): number | null {\n\tif (mapping.isEmpty) return index;\n\n\tlet current: number = index;\n\tfor (const m of mapping.maps) {\n\t\tconst next: number | null = mapChildIndexThroughStep(parentPath, current, m, kind);\n\t\tif (next === null) return null;\n\t\tcurrent = next;\n\t}\n\treturn current;\n}\n\nfunction mapChildIndexThroughStep(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmap: StepMap,\n\tkind: ChildIndexKind,\n): number | null {\n\tswitch (map.type) {\n\t\tcase 'identity':\n\t\tcase 'shift':\n\t\tcase 'split':\n\t\tcase 'merge':\n\t\t\treturn index;\n\t\tcase 'blockRemoval':\n\t\t\tif (!sameParentPath(parentPath, map.parentPath)) return index;\n\t\t\tif (index === map.index) {\n\t\t\t\t// Existing-child semantics: that child is gone → invalid.\n\t\t\t\t// Insertion-slot semantics: the slot survives; nothing was\n\t\t\t\t// inserted/removed *to the left* of `index`, so the slot\n\t\t\t\t// number is unchanged in the post-removal frame.\n\t\t\t\treturn kind === 'existing' ? null : index;\n\t\t\t}\n\t\t\tif (index > map.index) return index - 1;\n\t\t\treturn index;\n\t\tcase 'childIndexShift':\n\t\t\tif (!sameParentPath(parentPath, map.parentPath)) return index;\n\t\t\tif (index >= map.fromIndex) return index + map.delta;\n\t\t\treturn index;\n\t\tcase 'moveNode':\n\t\t\treturn mapChildIndexThroughMove(parentPath, index, map, kind);\n\t}\n}\n\nfunction mapChildIndexThroughMove(\n\tparentPath: readonly BlockId[],\n\tindex: number,\n\tmap: MoveNodeMap,\n\tkind: ChildIndexKind,\n): number | null {\n\tconst sameParent: boolean = sameParentPath(map.fromParentPath, map.toParentPath);\n\tif (sameParent && map.fromIndex === map.destinationIndex) return index;\n\tif (\n\t\tkind === 'existing' &&\n\t\tsameParent &&\n\t\tsameParentPath(parentPath, map.fromParentPath) &&\n\t\tindex === map.fromIndex\n\t) {\n\t\treturn map.destinationIndex;\n\t}\n\n\tlet current: number = index;\n\tif (sameParentPath(parentPath, map.fromParentPath)) {\n\t\tif (current === map.fromIndex) {\n\t\t\tif (kind === 'existing') return null;\n\t\t} else if (current > map.fromIndex) {\n\t\t\tcurrent--;\n\t\t}\n\t}\n\n\tif (sameParentPath(parentPath, map.toParentPath) && current >= map.destinationIndex) {\n\t\tcurrent++;\n\t}\n\treturn current;\n}\n\nfunction sameParentPath(a: readonly BlockId[], b: readonly BlockId[]): boolean {\n\tif (a === b) return true;\n\tif (a.length !== b.length) return false;\n\tfor (let i = 0; i < a.length; i++) {\n\t\tif (a[i] !== b[i]) return false;\n\t}\n\treturn true;\n}\n\n// --- StepMap inversion (used by history's frame-walk cancellation) ---\n\n/**\n * Returns the {@link StepMap} that undoes `map` in position space — i.e.\n * composing `map` with `invertStepMap(map)` is content-preserving (though\n * the composed position-mapping is *not* a true identity in our framework:\n * positions interior to a delete-then-reinsert round-trip clamp to the\n * deletion start during the deletion half and don't return on the insert\n * half).\n *\n * Used by history to detect mutually-inverse stepmaps in the rebase chain\n * and cancel them, sidestepping the round-trip clamping for cases where\n * the rebase is a no-op in content terms.\n *\n * Structural maps include enough metadata to recover their exact inverse\n * where possible. Synthetic ChildIndexShiftMaps without inserted subtree IDs\n * remain position-only and therefore invert to {@link IDENTITY_MAP}.\n */\nexport function invertStepMap(map: StepMap): StepMap {\n\tswitch (map.type) {\n\t\tcase 'identity':\n\t\t\treturn IDENTITY_MAP;\n\t\tcase 'shift':\n\t\t\treturn {\n\t\t\t\ttype: 'shift',\n\t\t\t\tblockId: map.blockId,\n\t\t\t\tfrom: map.from,\n\t\t\t\tto: map.from + map.newLen,\n\t\t\t\tnewLen: map.to - map.from,\n\t\t\t};\n\t\tcase 'split':\n\t\t\treturn {\n\t\t\t\ttype: 'merge',\n\t\t\t\ttargetBlockId: map.blockId,\n\t\t\t\tsourceBlockId: map.newBlockId,\n\t\t\t\ttargetLengthBefore: map.offset,\n\t\t\t};\n\t\tcase 'merge':\n\t\t\treturn {\n\t\t\t\ttype: 'split',\n\t\t\t\tblockId: map.targetBlockId,\n\t\t\t\toffset: map.targetLengthBefore,\n\t\t\t\tnewBlockId: map.sourceBlockId,\n\t\t\t};\n\t\tcase 'blockRemoval':\n\t\t\treturn {\n\t\t\t\ttype: 'childIndexShift',\n\t\t\t\tparentPath: map.parentPath,\n\t\t\t\tfromIndex: map.index,\n\t\t\t\tdelta: 1,\n\t\t\t\tinsertedBlockIds: map.removedBlockIds,\n\t\t\t};\n\t\tcase 'childIndexShift':\n\t\t\tif (map.delta === 1 && map.insertedBlockIds) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'blockRemoval',\n\t\t\t\t\tremovedBlockIds: map.insertedBlockIds,\n\t\t\t\t\tparentPath: map.parentPath,\n\t\t\t\t\tindex: map.fromIndex,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn IDENTITY_MAP;\n\t\tcase 'moveNode':\n\t\t\treturn {\n\t\t\t\ttype: 'moveNode',\n\t\t\t\tmovedNodeId: map.movedNodeId,\n\t\t\t\tfromParentPath: map.toParentPath,\n\t\t\t\tfromIndex: map.destinationIndex,\n\t\t\t\ttoParentPath: map.fromParentPath,\n\t\t\t\tdestinationIndex: map.fromIndex,\n\t\t\t};\n\t}\n}\n\n/**\n * Structural equality for {@link StepMap}s. Used by history to recognize\n * cancelling pairs in the rebase chain ({@link invertStepMap}(a) ≡ b).\n */\nexport function stepMapsEqual(a: StepMap, b: StepMap): boolean {\n\tif (a.type !== b.type) return false;\n\tswitch (a.type) {\n\t\tcase 'identity':\n\t\t\treturn true;\n\t\tcase 'shift': {\n\t\t\tconst bs = b as ShiftMap;\n\t\t\treturn (\n\t\t\t\ta.blockId === bs.blockId && a.from === bs.from && a.to === bs.to && a.newLen === bs.newLen\n\t\t\t);\n\t\t}\n\t\tcase 'split': {\n\t\t\tconst bs = b as SplitMap;\n\t\t\treturn a.blockId === bs.blockId && a.offset === bs.offset && a.newBlockId === bs.newBlockId;\n\t\t}\n\t\tcase 'merge': {\n\t\t\tconst bm = b as MergeMap;\n\t\t\treturn (\n\t\t\t\ta.targetBlockId === bm.targetBlockId &&\n\t\t\t\ta.sourceBlockId === bm.sourceBlockId &&\n\t\t\t\ta.targetLengthBefore === bm.targetLengthBefore\n\t\t\t);\n\t\t}\n\t\tcase 'blockRemoval': {\n\t\t\tconst br = b as BlockRemovalMap;\n\t\t\tif (a.index !== br.index) return false;\n\t\t\tif (!sameParentPath(a.parentPath, br.parentPath)) return false;\n\t\t\tif (a.removedBlockIds.size !== br.removedBlockIds.size) return false;\n\t\t\tfor (const id of a.removedBlockIds) {\n\t\t\t\tif (!br.removedBlockIds.has(id)) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tcase 'childIndexShift': {\n\t\t\tconst cs = b as ChildIndexShiftMap;\n\t\t\treturn (\n\t\t\t\ta.fromIndex === cs.fromIndex &&\n\t\t\t\ta.delta === cs.delta &&\n\t\t\t\tsameParentPath(a.parentPath, cs.parentPath) &&\n\t\t\t\toptionalIdSetsEqual(a.insertedBlockIds, cs.insertedBlockIds)\n\t\t\t);\n\t\t}\n\t\tcase 'moveNode': {\n\t\t\tif (b.type !== 'moveNode') return false;\n\t\t\treturn (\n\t\t\t\ta.movedNodeId === b.movedNodeId &&\n\t\t\t\ta.fromIndex === b.fromIndex &&\n\t\t\t\ta.destinationIndex === b.destinationIndex &&\n\t\t\t\tsameParentPath(a.fromParentPath, b.fromParentPath) &&\n\t\t\t\tsameParentPath(a.toParentPath, b.toParentPath)\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction optionalIdSetsEqual(\n\ta: ReadonlySet<BlockId> | undefined,\n\tb: ReadonlySet<BlockId> | undefined,\n): boolean {\n\tif (a === b) return true;\n\tif (!a || !b || a.size !== b.size) return false;\n\tfor (const id of a) {\n\t\tif (!b.has(id)) return false;\n\t}\n\treturn true;\n}\n","/**\n * Thin decoration-specific adapters over the generic {@link StepMap}\n * primitive. Position-shift arithmetic lives in `state/Mapping.ts`; this\n * module only contains the decoration-shape concerns:\n *\n * - splitting an {@link InlineDecoration} into two when a `splitBlock`\n * crosses its range,\n * - dropping a {@link NodeDecoration} when its block disappears\n * (`removeNode`) or is absorbed by a merge,\n * - applying widget `side` as the mapping `assoc`.\n *\n * The legacy entry point `mapDecorationThroughStep(deco, step)` is\n * preserved as a thin shim over `mapDecorationThroughStepMap` so existing\n * tests keep working; new consumers should reach for `Transaction.mapping`\n * directly via `DecorationSet.map(tr)`.\n */\n\nimport type { Document } from '../model/Document.js';\nimport { createPosition } from '../model/Selection.js';\nimport type { MergeMap, ShiftMap, SplitMap, StepMap } from '../state/Mapping.js';\nimport { mapPositionThroughStep } from '../state/Mapping.js';\nimport { getStepMap } from '../state/StepHandlers.js';\nimport type { Step } from '../state/Transaction.js';\nimport type {\n\tDecoration,\n\tInlineDecoration,\n\tNodeDecoration,\n\tWidgetDecoration,\n} from './Decoration.js';\n\nconst EMPTY_DOC: Document = { children: [] };\n\n/**\n * Maps a decoration through a single {@link StepMap}. Returns:\n * - the (possibly identical) decoration,\n * - an array of two decorations when a `splitBlock` cuts an inline range,\n * - or `null` when the decoration was deleted.\n */\nexport function mapDecorationThroughStepMap(\n\tdeco: Decoration,\n\tstepMap: StepMap,\n): Decoration | readonly Decoration[] | null {\n\tswitch (deco.type) {\n\t\tcase 'inline':\n\t\t\treturn mapInline(deco, stepMap);\n\t\tcase 'widget':\n\t\t\treturn mapWidget(deco, stepMap);\n\t\tcase 'node':\n\t\t\treturn mapNode(deco, stepMap);\n\t}\n}\n\n/**\n * Legacy entry point — kept for backward compatibility with callers and\n * tests that hold a {@link Step} rather than a {@link StepMap}. Internally\n * converts step → StepMap (cheap, no doc state needed for any of the\n * shape categories used here) and delegates to\n * {@link mapDecorationThroughStepMap}.\n */\nexport function mapDecorationThroughStep(\n\tdeco: Decoration,\n\tstep: Step,\n): Decoration | readonly Decoration[] | null {\n\treturn mapDecorationThroughStepMap(deco, getStepMap(EMPTY_DOC, step));\n}\n\n// --- Inline ---\n\nfunction mapInline(\n\tdeco: InlineDecoration,\n\tstepMap: StepMap,\n): InlineDecoration | readonly InlineDecoration[] | null {\n\tswitch (stepMap.type) {\n\t\tcase 'identity':\n\t\t\treturn deco;\n\t\tcase 'shift':\n\t\t\treturn mapInlineShift(deco, stepMap);\n\t\tcase 'split':\n\t\t\treturn mapInlineSplit(deco, stepMap);\n\t\tcase 'merge':\n\t\t\treturn mapInlineMerge(deco, stepMap);\n\t\tcase 'blockRemoval':\n\t\t\treturn stepMap.removedBlockIds.has(deco.blockId) ? null : deco;\n\t\tcase 'childIndexShift':\n\t\tcase 'moveNode':\n\t\t\t// Sibling-index shifts don't move text positions.\n\t\t\treturn deco;\n\t}\n}\n\nfunction mapInlineShift(deco: InlineDecoration, map: ShiftMap): InlineDecoration | null {\n\tif (deco.blockId !== map.blockId) return deco;\n\n\tconst fromPos = mapPositionThroughStep(createPosition(deco.blockId, deco.from), map, -1).pos;\n\tconst toPos = mapPositionThroughStep(createPosition(deco.blockId, deco.to), map, 1).pos;\n\n\tif (fromPos.offset >= toPos.offset) return null;\n\tif (fromPos.offset === deco.from && toPos.offset === deco.to) return deco;\n\treturn { ...deco, from: fromPos.offset, to: toPos.offset };\n}\n\nfunction mapInlineSplit(\n\tdeco: InlineDecoration,\n\tmap: SplitMap,\n): InlineDecoration | readonly InlineDecoration[] {\n\tif (deco.blockId !== map.blockId) return deco;\n\n\tif (deco.to <= map.offset) return deco;\n\n\tif (deco.from >= map.offset) {\n\t\treturn {\n\t\t\t...deco,\n\t\t\tblockId: map.newBlockId,\n\t\t\tfrom: deco.from - map.offset,\n\t\t\tto: deco.to - map.offset,\n\t\t};\n\t}\n\n\t// Spans the split — return both halves\n\tconst left: InlineDecoration = { ...deco, to: map.offset };\n\tconst right: InlineDecoration = {\n\t\t...deco,\n\t\tblockId: map.newBlockId,\n\t\tfrom: 0,\n\t\tto: deco.to - map.offset,\n\t};\n\treturn [left, right];\n}\n\nfunction mapInlineMerge(deco: InlineDecoration, map: MergeMap): InlineDecoration {\n\tif (deco.blockId !== map.sourceBlockId) return deco;\n\treturn {\n\t\t...deco,\n\t\tblockId: map.targetBlockId,\n\t\tfrom: deco.from + map.targetLengthBefore,\n\t\tto: deco.to + map.targetLengthBefore,\n\t};\n}\n\n// --- Widget ---\n\nfunction mapWidget(deco: WidgetDecoration, stepMap: StepMap): WidgetDecoration | null {\n\tswitch (stepMap.type) {\n\t\tcase 'identity':\n\t\t\treturn deco;\n\t\tcase 'shift':\n\t\t\treturn mapWidgetShift(deco, stepMap);\n\t\tcase 'split':\n\t\t\treturn mapWidgetSplit(deco, stepMap);\n\t\tcase 'merge':\n\t\t\treturn mapWidgetMerge(deco, stepMap);\n\t\tcase 'blockRemoval':\n\t\t\treturn stepMap.removedBlockIds.has(deco.blockId) ? null : deco;\n\t\tcase 'childIndexShift':\n\t\tcase 'moveNode':\n\t\t\treturn deco;\n\t}\n}\n\nfunction mapWidgetShift(deco: WidgetDecoration, map: ShiftMap): WidgetDecoration | null {\n\tif (deco.blockId !== map.blockId) return deco;\n\n\tconst result = mapPositionThroughStep(createPosition(deco.blockId, deco.offset), map, deco.side);\n\t// A widget that lands strictly inside removed content is deleted.\n\tif (result.deleted) return null;\n\tif (result.pos.offset === deco.offset) return deco;\n\treturn { ...deco, offset: result.pos.offset };\n}\n\nfunction mapWidgetSplit(deco: WidgetDecoration, map: SplitMap): WidgetDecoration {\n\tif (deco.blockId !== map.blockId) return deco;\n\tconst result = mapPositionThroughStep(createPosition(deco.blockId, deco.offset), map, deco.side);\n\tif (result.pos.blockId === deco.blockId && result.pos.offset === deco.offset) return deco;\n\treturn { ...deco, blockId: result.pos.blockId, offset: result.pos.offset };\n}\n\nfunction mapWidgetMerge(deco: WidgetDecoration, map: MergeMap): WidgetDecoration {\n\tif (deco.blockId !== map.sourceBlockId) return deco;\n\treturn {\n\t\t...deco,\n\t\tblockId: map.targetBlockId,\n\t\toffset: deco.offset + map.targetLengthBefore,\n\t};\n}\n\n// --- Node ---\n\nfunction mapNode(deco: NodeDecoration, stepMap: StepMap): NodeDecoration | null {\n\tswitch (stepMap.type) {\n\t\tcase 'identity':\n\t\tcase 'shift':\n\t\tcase 'split':\n\t\t\t// Node decorations are bound to a block; in-block content edits\n\t\t\t// and splits don't affect them. Splits keep the decoration on the\n\t\t\t// original block (the new block has no decoration of its own).\n\t\t\treturn deco;\n\t\tcase 'merge':\n\t\t\t// Source block disappears as a separate block → its decoration is dropped.\n\t\t\treturn deco.blockId === stepMap.sourceBlockId ? null : deco;\n\t\tcase 'blockRemoval':\n\t\t\treturn stepMap.removedBlockIds.has(deco.blockId) ? null : deco;\n\t\tcase 'childIndexShift':\n\t\tcase 'moveNode':\n\t\t\treturn deco;\n\t}\n}\n","/**\n * Decoration types and DecorationSet for transient, view-only annotations.\n * Decorations are NOT part of the document model and do NOT affect undo/redo.\n */\n\nimport type { PluginCallbackRegistration } from '../model/PluginCallbackExecutor.js';\nimport type { BlockId } from '../model/TypeBrands.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport { mapDecorationThroughStepMap } from './PositionMapping.js';\n\n// --- Decoration Attrs ---\n\nexport interface DecorationAttrs {\n\treadonly class?: string;\n\treadonly style?: string;\n\treadonly nodeName?: string;\n\treadonly [key: string]: string | undefined;\n}\n\n// --- Decoration Types ---\n\nconst WIDGET_CALLBACK_OWNER: unique symbol = Symbol('notectl.widget-callback-owner');\n\nexport interface InlineDecoration {\n\treadonly type: 'inline';\n\treadonly blockId: BlockId;\n\treadonly from: number;\n\treadonly to: number;\n\treadonly attrs: DecorationAttrs;\n}\n\nexport interface NodeDecoration {\n\treadonly type: 'node';\n\treadonly blockId: BlockId;\n\treadonly attrs: DecorationAttrs;\n}\n\nexport interface WidgetDecoration {\n\treadonly type: 'widget';\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n\treadonly toDOM: () => HTMLElement;\n\treadonly side: -1 | 1;\n\treadonly key?: string;\n\t/** Plugin ownership attached by PluginLifecycle before the decoration reaches the view. */\n\treadonly [WIDGET_CALLBACK_OWNER]?: PluginCallbackRegistration;\n}\n\nexport type Decoration = InlineDecoration | NodeDecoration | WidgetDecoration;\n\n/** Returns lifecycle-owned attribution for a widget renderer, when available. */\nexport function getWidgetCallbackOwner(\n\tdecoration: WidgetDecoration,\n): PluginCallbackRegistration | undefined {\n\treturn decoration[WIDGET_CALLBACK_OWNER];\n}\n\n// --- Factory Functions ---\n\n/** Creates an inline decoration for a text range within a block. */\nexport function inline(\n\tblockId: BlockId,\n\tfrom: number,\n\tto: number,\n\tattrs: DecorationAttrs,\n): InlineDecoration {\n\treturn { type: 'inline', blockId, from, to, attrs };\n}\n\n/** Creates a node decoration that applies to a whole block element. */\nexport function node(blockId: BlockId, attrs: DecorationAttrs): NodeDecoration {\n\treturn { type: 'node', blockId, attrs };\n}\n\n/** Creates a widget decoration that inserts a DOM element at a position. */\nexport function widget(\n\tblockId: BlockId,\n\toffset: number,\n\ttoDOM: () => HTMLElement,\n\toptions?: { readonly side?: -1 | 1; readonly key?: string },\n): WidgetDecoration {\n\treturn {\n\t\ttype: 'widget',\n\t\tblockId,\n\t\toffset,\n\t\ttoDOM,\n\t\tside: options?.side ?? -1,\n\t\tkey: options?.key,\n\t};\n}\n\n// --- DecorationSet ---\n\n/**\n * Immutable set of decorations indexed by block ID.\n * Provides efficient lookup and merging of decoration collections.\n */\nexport class DecorationSet {\n\tstatic readonly empty: DecorationSet = new DecorationSet(new Map());\n\n\tprivate constructor(private readonly byBlock: ReadonlyMap<BlockId, readonly Decoration[]>) {}\n\n\t/** Creates a DecorationSet from a flat array of decorations. */\n\tstatic create(decorations: readonly Decoration[]): DecorationSet {\n\t\tif (decorations.length === 0) return DecorationSet.empty;\n\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const deco of decorations) {\n\t\t\tconst existing = map.get(deco.blockId);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(deco);\n\t\t\t} else {\n\t\t\t\tmap.set(deco.blockId, [deco]);\n\t\t\t}\n\t\t}\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Returns all decorations for a given block. */\n\tfind(blockId: BlockId): readonly Decoration[] {\n\t\treturn this.byBlock.get(blockId) ?? [];\n\t}\n\n\t/** Returns only inline decorations for a given block. */\n\tfindInline(blockId: BlockId): readonly InlineDecoration[] {\n\t\tconst decos = this.byBlock.get(blockId);\n\t\tif (!decos) return [];\n\t\treturn decos.filter((d): d is InlineDecoration => d.type === 'inline');\n\t}\n\n\t/** Returns only node decorations for a given block. */\n\tfindNode(blockId: BlockId): readonly NodeDecoration[] {\n\t\tconst decos = this.byBlock.get(blockId);\n\t\tif (!decos) return [];\n\t\treturn decos.filter((d): d is NodeDecoration => d.type === 'node');\n\t}\n\n\t/** Returns only widget decorations for a given block. */\n\tfindWidget(blockId: BlockId): readonly WidgetDecoration[] {\n\t\tconst decos = this.byBlock.get(blockId);\n\t\tif (!decos) return [];\n\t\treturn decos.filter((d): d is WidgetDecoration => d.type === 'widget');\n\t}\n\n\t/** Returns a new DecorationSet with the given decorations added. */\n\tadd(decorations: readonly Decoration[]): DecorationSet {\n\t\tif (decorations.length === 0) return this;\n\t\tif (this.isEmpty) return DecorationSet.create(decorations);\n\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tmap.set(bid, [...decos]);\n\t\t}\n\t\tfor (const deco of decorations) {\n\t\t\tconst existing = map.get(deco.blockId);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(deco);\n\t\t\t} else {\n\t\t\t\tmap.set(deco.blockId, [deco]);\n\t\t\t}\n\t\t}\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Returns a new DecorationSet with decorations matching the predicate removed. */\n\tremove(predicate: (d: Decoration) => boolean): DecorationSet {\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tlet changed = false;\n\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tconst filtered = decos.filter((d) => !predicate(d));\n\t\t\tif (filtered.length !== decos.length) changed = true;\n\t\t\tif (filtered.length > 0) {\n\t\t\t\tmap.set(bid, filtered);\n\t\t\t}\n\t\t}\n\n\t\tif (!changed) return this;\n\t\tif (map.size === 0) return DecorationSet.empty;\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Returns a new DecorationSet merging this set with another. */\n\tmerge(other: DecorationSet): DecorationSet {\n\t\tif (other.isEmpty) return this;\n\t\tif (this.isEmpty) return other;\n\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tmap.set(bid, [...decos]);\n\t\t}\n\t\tfor (const [bid, decos] of other.byBlock) {\n\t\t\tconst existing = map.get(bid);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(...decos);\n\t\t\t} else {\n\t\t\t\tmap.set(bid, [...decos]);\n\t\t\t}\n\t\t}\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Attaches plugin attribution to widget callbacks without mutating plugin-owned objects. */\n\twithWidgetOwner(pluginId: string): DecorationSet {\n\t\tlet changed = false;\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const [bid, decorations] of this.byBlock) {\n\t\t\tconst attributed = decorations.map((decoration): Decoration => {\n\t\t\t\tif (decoration.type !== 'widget') return decoration;\n\t\t\t\tchanged = true;\n\t\t\t\treturn {\n\t\t\t\t\t...decoration,\n\t\t\t\t\t[WIDGET_CALLBACK_OWNER]: { pluginId, name: 'widget' },\n\t\t\t\t};\n\t\t\t});\n\t\t\tmap.set(bid, attributed);\n\t\t}\n\t\treturn changed ? new DecorationSet(map) : this;\n\t}\n\n\t/** Checks equality — reference first, then structural comparison. */\n\tequals(other: DecorationSet): boolean {\n\t\tif (this === other) return true;\n\t\tif (this.byBlock.size !== other.byBlock.size) return false;\n\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tconst otherDecos = other.byBlock.get(bid);\n\t\t\tif (!otherDecos) return false;\n\t\t\tif (!decorationArraysEqual(decos, otherDecos)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** True if the set contains no decorations. */\n\tget isEmpty(): boolean {\n\t\treturn this.byBlock.size === 0;\n\t}\n\n\t/**\n\t * Maps decorations through document changes described by a transaction.\n\t * Decorations that become invalid (e.g. fully deleted range) are removed.\n\t * Decorations that span a split point are split into two.\n\t *\n\t * Iterates over `tr.mapping.maps` (the position-space {@link StepMap}s)\n\t * rather than `tr.steps`. This means selection-only or other identity\n\t * transactions short-circuit (`tr.mapping.isEmpty`) without rebuilding\n\t * the set, and the decoration-specific shape concerns (split-into-two,\n\t * drop-on-block-removal) are the only logic that lives here.\n\t */\n\tmap(tr: Transaction): DecorationSet {\n\t\tif (this.isEmpty || tr.mapping.isEmpty) return this;\n\n\t\tlet mapped: Decoration[] = [];\n\t\tfor (const decos of this.byBlock.values()) {\n\t\t\tfor (const d of decos) {\n\t\t\t\tmapped.push(d);\n\t\t\t}\n\t\t}\n\n\t\tfor (const stepMap of tr.mapping.maps) {\n\t\t\tconst next: Decoration[] = [];\n\t\t\tfor (const deco of mapped) {\n\t\t\t\tconst result = mapDecorationThroughStepMap(deco, stepMap);\n\t\t\t\tif (result === null) continue;\n\t\t\t\tif (Array.isArray(result)) {\n\t\t\t\t\tfor (const r of result) {\n\t\t\t\t\t\tnext.push(r);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnext.push(result as Decoration);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmapped = next;\n\t\t}\n\n\t\tif (mapped.length === 0) return DecorationSet.empty;\n\t\treturn DecorationSet.create(mapped);\n\t}\n}\n\n// --- Helpers ---\n\n/** Compares two decoration arrays for structural equality. */\nexport function decorationArraysEqual(a: readonly Decoration[], b: readonly Decoration[]): boolean {\n\tif (a === b) return true;\n\tif (a.length !== b.length) return false;\n\n\tfor (let i = 0; i < a.length; i++) {\n\t\tconst ai = a[i];\n\t\tconst bi = b[i];\n\t\tif (!ai || !bi || !decorationsEqual(ai, bi)) return false;\n\t}\n\treturn true;\n}\n\n/** Compares two individual decorations for structural equality. */\nfunction decorationsEqual(a: Decoration, b: Decoration): boolean {\n\tif (a.type !== b.type) return false;\n\tif (a.blockId !== b.blockId) return false;\n\n\tswitch (a.type) {\n\t\tcase 'inline': {\n\t\t\tconst bi = b as InlineDecoration;\n\t\t\treturn a.from === bi.from && a.to === bi.to && attrsEqual(a.attrs, bi.attrs);\n\t\t}\n\t\tcase 'node': {\n\t\t\tconst bn = b as NodeDecoration;\n\t\t\treturn attrsEqual(a.attrs, bn.attrs);\n\t\t}\n\t\tcase 'widget': {\n\t\t\tconst bw = b as WidgetDecoration;\n\t\t\tconst sameIdentity: boolean =\n\t\t\t\ta.key !== undefined || bw.key !== undefined ? a.key === bw.key : a.toDOM === bw.toDOM;\n\t\t\treturn a.offset === bw.offset && a.side === bw.side && a.key === bw.key && sameIdentity;\n\t\t}\n\t}\n}\n\n/** Compares two DecorationAttrs objects. */\nfunction attrsEqual(a: DecorationAttrs, b: DecorationAttrs): boolean {\n\tif (a === b) return true;\n\tconst aKeys = Object.keys(a);\n\tconst bKeys = Object.keys(b);\n\tif (aKeys.length !== bKeys.length) return false;\n\tfor (const key of aKeys) {\n\t\tif (a[key] !== b[key]) return false;\n\t}\n\treturn true;\n}\n"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,OAAO,EAE/B,OAAO,CACR"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{R as r}from"./Document-
|
|
2
|
-
//# sourceMappingURL=DirectionDetection-
|
|
1
|
+
import{R as r}from"./Document-ssR6hBzG.mjs";var t=/[\p{Script=Hebrew}\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Mandaic}\p{Script=Nko}\p{Script=Samaritan}\p{Script=Adlam}\p{Script=Hanifi_Rohingya}\p{Script=Mende_Kikakui}\p{Script=Yezidi}\p{Script=Old_South_Arabian}\p{Script=Old_North_Arabian}\p{Script=Avestan}\p{Script=Imperial_Aramaic}\p{Script=Phoenician}\p{Script=Lydian}\u200F\u061C]/u,i=/[\p{Script=Latin}\p{Script=Greek}\p{Script=Cyrillic}\p{Script=Armenian}\p{Script=Devanagari}\p{Script=Bengali}\p{Script=Gurmukhi}\p{Script=Gujarati}\p{Script=Oriya}\p{Script=Tamil}\p{Script=Telugu}\p{Script=Kannada}\p{Script=Malayalam}\p{Script=Sinhala}\p{Script=Thai}\p{Script=Lao}\p{Script=Tibetan}\p{Script=Myanmar}\p{Script=Georgian}\p{Script=Hangul}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}\p{Script=Ethiopic}\p{Script=Cherokee}\p{Script=Khmer}\u200E]/u;function p(r){const p=r.search(t),a=r.search(i);return-1===p&&-1===a?null:-1===p?"ltr":-1===a||p<a?"rtl":"ltr"}function a(r){const t=r.attrs?.dir;return"ltr"===t||"rtl"===t?t:"auto"}function c(t,i,p){const a=function(t,i){if(0===i.length)return t.doc.children;const p=i[i.length-1];if(!p)return[];const a=t.getBlock(p);return a?a.children.filter(r):[]}(t,i);for(let r=p-1;r>=0;r--){const t=a[r]?.attrs?.dir;if("ltr"===t||"rtl"===t)return t}for(let r=p;r<a.length;r++){const t=a[r]?.attrs?.dir;if("ltr"===t||"rtl"===t)return t}}export{c as n,a as r,p as t};
|
|
2
|
+
//# sourceMappingURL=DirectionDetection-a-1iksmh.mjs.map
|
package/dist/chunks/{DirectionDetection-ZrkMhyaL.mjs.map → DirectionDetection-a-1iksmh.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectionDetection-
|
|
1
|
+
{"version":3,"file":"DirectionDetection-a-1iksmh.mjs","names":[],"sources":["../../src/plugins/text-direction/DirectionDetection.ts"],"sourcesContent":["/**\n * Direction detection utilities for the TextDirectionPlugin.\n * Detects text direction based on the first strong directional character\n * and finds sibling block direction for inheritance.\n */\n\nimport { type BlockNode, isBlockNode } from '../../model/Document.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { TextDirection } from './TextDirectionPlugin.js';\n\n// --- RTL Detection ---\n\n/**\n * Regex matching strong RTL characters using Unicode Script property escapes.\n * Auto-maintained by the Unicode standard — no manual code-point ranges needed.\n * Covers all RTL scripts: Hebrew, Arabic, Syriac, Thaana, N'Ko, Samaritan,\n * Mandaic, Adlam, Hanifi Rohingya, Mende Kikakui, Yezidi, and historic scripts.\n * Includes U+200F (RLM) and U+061C (ALM) as strong directional markers.\n */\nconst RTL_CHAR_RE: RegExp =\n\t/[\\p{Script=Hebrew}\\p{Script=Arabic}\\p{Script=Syriac}\\p{Script=Thaana}\\p{Script=Mandaic}\\p{Script=Nko}\\p{Script=Samaritan}\\p{Script=Adlam}\\p{Script=Hanifi_Rohingya}\\p{Script=Mende_Kikakui}\\p{Script=Yezidi}\\p{Script=Old_South_Arabian}\\p{Script=Old_North_Arabian}\\p{Script=Avestan}\\p{Script=Imperial_Aramaic}\\p{Script=Phoenician}\\p{Script=Lydian}\\u200F\\u061C]/u;\n\n/**\n * Regex matching strong LTR characters using Unicode Script property escapes.\n * Covers all major LTR scripts: Latin, Greek, Cyrillic, Armenian, Indic scripts,\n * Southeast Asian scripts, East Asian scripts, Georgian, Ethiopic, and more.\n * Includes U+200E (LRM) as a strong directional marker.\n */\nconst LTR_CHAR_RE: RegExp =\n\t/[\\p{Script=Latin}\\p{Script=Greek}\\p{Script=Cyrillic}\\p{Script=Armenian}\\p{Script=Devanagari}\\p{Script=Bengali}\\p{Script=Gurmukhi}\\p{Script=Gujarati}\\p{Script=Oriya}\\p{Script=Tamil}\\p{Script=Telugu}\\p{Script=Kannada}\\p{Script=Malayalam}\\p{Script=Sinhala}\\p{Script=Thai}\\p{Script=Lao}\\p{Script=Tibetan}\\p{Script=Myanmar}\\p{Script=Georgian}\\p{Script=Hangul}\\p{Script=Hiragana}\\p{Script=Katakana}\\p{Script=Han}\\p{Script=Ethiopic}\\p{Script=Cherokee}\\p{Script=Khmer}\\u200E]/u;\n\n/**\n * Detects the dominant text direction based on the first strong directional character.\n * Returns `null` if no strong character is found (all neutral/numeric/whitespace).\n */\nexport function detectTextDirection(text: string): TextDirection | null {\n\tconst rtlIdx: number = text.search(RTL_CHAR_RE);\n\tconst ltrIdx: number = text.search(LTR_CHAR_RE);\n\n\tif (rtlIdx === -1 && ltrIdx === -1) return null;\n\tif (rtlIdx === -1) return 'ltr';\n\tif (ltrIdx === -1) return 'rtl';\n\treturn rtlIdx < ltrIdx ? 'rtl' : 'ltr';\n}\n\n// --- Block Direction Accessor ---\n\n/** Returns the current `dir` attribute of a block, defaulting to `'auto'`. */\nexport function getBlockDir(block: BlockNode): TextDirection {\n\tconst dir: unknown = block.attrs?.dir;\n\tif (dir === 'ltr' || dir === 'rtl') return dir;\n\treturn 'auto';\n}\n\n// --- Sibling Direction Lookup ---\n\n/**\n * Finds the `dir` attribute of the nearest sibling with an explicit direction\n * (not `'auto'`) before the insert position, walking backwards.\n */\nexport function findSiblingDirection(\n\tstate: EditorState,\n\tparentPath: readonly BlockId[],\n\tindex: number,\n): TextDirection | undefined {\n\tconst siblings: readonly BlockNode[] = getSiblings(state, parentPath);\n\n\t// Walk backward first (preceding siblings take priority)\n\tfor (let i: number = index - 1; i >= 0; i--) {\n\t\tconst dir: unknown = siblings[i]?.attrs?.dir;\n\t\tif (dir === 'ltr' || dir === 'rtl') return dir;\n\t}\n\n\t// Walk forward when no backward sibling has explicit direction\n\tfor (let i: number = index; i < siblings.length; i++) {\n\t\tconst dir: unknown = siblings[i]?.attrs?.dir;\n\t\tif (dir === 'ltr' || dir === 'rtl') return dir;\n\t}\n\n\treturn undefined;\n}\n\n/** Returns the sibling list for the given parent path. */\nfunction getSiblings(state: EditorState, parentPath: readonly BlockId[]): readonly BlockNode[] {\n\tif (parentPath.length === 0) {\n\t\treturn state.doc.children;\n\t}\n\n\tconst parentId: BlockId | undefined = parentPath[parentPath.length - 1];\n\tif (!parentId) return [];\n\tconst parent: BlockNode | undefined = state.getBlock(parentId);\n\tif (!parent) return [];\n\n\treturn parent.children.filter(isBlockNode);\n}\n"],"mappings":"4CAoBA,IAAM,EACL,wWAQK,EACL,udAMD,SAAgB,EAAoB,GACnC,MAAM,EAAiB,EAAK,OAAO,GAC7B,EAAiB,EAAK,OAAO,GAEnC,OAAe,IAAX,IAA4B,IAAX,EAAsB,MAC5B,IAAX,EAAsB,OACX,IAAX,GACG,EAAS,EADU,MACO,KAClC,CAKA,SAAgB,EAAY,GAC3B,MAAM,EAAe,EAAM,OAAO,IAClC,MAAY,QAAR,GAAyB,QAAR,EAAsB,EACpC,MACR,CAQA,SAAgB,EACf,EACA,EACA,GAEA,MAAM,EAkBP,SAAqB,EAAoB,GACxC,GAA0B,IAAtB,EAAW,OACd,OAAO,EAAM,IAAI,SAGlB,MAAM,EAAgC,EAAW,EAAW,OAAS,GACrE,IAAK,EAAU,MAAO,GACtB,MAAM,EAAgC,EAAM,SAAS,GACrD,OAAK,EAEE,EAAO,SAAS,OAAO,GAFV,EAGrB,CA7BwC,CAAY,EAAO,GAG1D,IAAK,IAAI,EAAY,EAAQ,EAAG,GAAK,EAAG,IAAK,CAC5C,MAAM,EAAe,EAAS,IAAI,OAAO,IACzC,GAAY,QAAR,GAAyB,QAAR,EAAe,OAAO,CAC5C,CAGA,IAAK,IAAI,EAAY,EAAO,EAAI,EAAS,OAAQ,IAAK,CACrD,MAAM,EAAe,EAAS,IAAI,OAAO,IACzC,GAAY,QAAR,GAAyB,QAAR,EAAe,OAAO,CAC5C,CAGD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=Document-
|
|
1
|
+
import{c as t}from"./HTMLUtils-DTpsjZyK.mjs";function e(t,e=[]){return{kind:"text",text:t,marks:e}}function n(t){return{kind:"inline",node:t}}function r(t,e,n){const r=[];return s(t,e,n,{onText(t,e){r.push({kind:"text",text:t,marks:e})},onInline(t){r.push({kind:"inline",node:t})}}),r}function s(t,e,n,r){for(const{child:s,from:o,to:c}of rt(u(t)))if(!(c<=e||o>=n))if(i(s))r.onInline?.(s);else{const t=Math.max(0,e-o),i=Math.min(s.text.length,n-o),c=s.text.slice(t,i);c.length>0&&r.onText(c,s.marks)}}function o(t){return"object"==typeof t&&null!==t&&"text"===t.type&&"string"==typeof t.text}function i(t){return"object"==typeof t&&null!==t&&"inline"===t.type&&"string"==typeof t.inlineType}function c(t){return"object"==typeof t&&null!==t&&"string"==typeof t.id&&"string"==typeof t.type&&"text"!==t.type&&"inline"!==t.type&&Array.isArray(t.children)}function f(t){return t.children.every(t=>o(t)||i(t))}function a(t){return t.children.filter(t=>o(t))}function u(t){return t.children.filter(t=>o(t)||i(t))}function l(t){return t.children.filter(t=>c(t))}function h(){return`block-${crypto.randomUUID()}`}function d(t){return{children:t?[...t]:[y("paragraph")]}}function y(e,n,r,s,o){const i=t(o);return{id:r??h(),...i?{htmlId:i}:{},type:e,...s?{attrs:H(s)}:{},children:n?[...n]:[k("")]}}function k(t,e){return{type:"text",text:t,marks:S(e??[])}}function m(t,e,n){return{type:"inline",inlineType:t,attrs:e?{...e}:{},marks:S(n??[])}}function p(t){return y("paragraph",[k("")],t)}var b=/* @__PURE__ */new WeakSet,j=/* @__PURE__ */new WeakSet,g=/* @__PURE__ */new WeakSet,O=/* @__PURE__ */new WeakSet,x=/* @__PURE__ */new WeakSet,z=/* @__PURE__ */new WeakSet,A=/* @__PURE__ */new WeakSet,F=/* @__PURE__ */new WeakSet;function v(t){return{...t,children:t.children.map(w)}}function w(t){const e=t.attrs?H(t.attrs):void 0;return{...t,...e?{attrs:e}:{},children:t.children.map(D)}}function S(t){return t.map(W)}function W(t){return{...t,...t.attrs?{attrs:{...t.attrs}}:{}}}function T(t){return{...t,attrs:{...t.attrs},marks:S(t.marks)}}function I(t){return"text"===t.kind?{...t,marks:S(t.marks)}:{...t,node:T(t.node)}}function M(t){return t.map(I)}function U(t){if(b.has(t))return t;for(const e of t.children)L(e);return Object.isFrozen(t.children)||Object.freeze(t.children),Object.isFrozen(t)||Object.freeze(t),b.add(t),t}function D(t){if(o(t)){const e=Array.isArray(t.marks)?S(t.marks):void 0;return{...t,...e?{marks:e}:{}}}return i(t)?T(t):w(t)}function H(t){const e={};for(const[n,r]of Object.entries(t))e[n]=Array.isArray(r)?[...r]:r;return e}function L(t){if(!j.has(t)){t.attrs&&q(t.attrs);for(const e of t.children)o(e)||i(e)?J(e):L(e);Object.isFrozen(t.children)||Object.freeze(t.children),Object.isFrozen(t)||Object.freeze(t),j.add(t)}}function q(t){if(!g.has(t)){for(const e of Object.values(t))Array.isArray(e)&&!Object.isFrozen(e)&&Object.freeze(e);Object.isFrozen(t)||Object.freeze(t),g.add(t)}}function B(t){O.has(t)||(t.attrs&&!Object.isFrozen(t.attrs)&&Object.freeze(t.attrs),Object.isFrozen(t)||Object.freeze(t),O.add(t))}function C(t){if(!x.has(t)){for(const e of t)B(e);Object.isFrozen(t)||Object.freeze(t),x.add(t)}}function E(t){z.has(t)||(Object.isFrozen(t.attrs)||Object.freeze(t.attrs),C(t.marks),Object.isFrozen(t)||Object.freeze(t),z.add(t))}function G(t){if(!F.has(t)){for(const e of t)"text"===e.kind?C(e.marks):E(e.node),Object.isFrozen(e)||Object.freeze(e);Object.isFrozen(t)||Object.freeze(t),F.add(t)}}function J(t){i(t)?E(t):A.has(t)||(C(t.marks),Object.isFrozen(t)||Object.freeze(t),A.add(t))}function K(t){const e=u(t);let n="";for(const r of e)o(r)&&(n+=r.text);return n}function N(t){let e=0;for(const{to:n}of rt(u(t)))e=n;return e}function P(t,e){const n=u(t);for(const{child:r,from:s,to:o}of rt(n))if(i(r)){if(e===s)return[]}else{if(e>=s&&e<o)return r.marks;if(e===s&&0===r.text.length)return r.marks}for(let r=n.length-1;r>=0;r--){const t=n[r];if(t&&o(t))return t.marks}return[]}function R(t,e,n){const r=P(t,e);if(0===r.length)return r;const s=function(t,e){for(const{child:n,from:r,to:s}of rt(u(t)))if(i(n)){if(e===r)return[]}else if(e>=r&&e<s)return n.marks;return[]}(t,e);return r.filter(t=>n(t.type)||s.some(e=>V(e,t)))}function V(t,e){if(t.type!==e.type)return!1;const n=t.attrs,r=e.attrs;if(!n&&!r)return!0;if(!n||!r)return!1;const s=Object.keys(n),o=Object.keys(r);return s.length===o.length&&s.every(t=>n[t]===r[t])}function $(t,e){return t===e||void 0!==t&&void 0!==e&&null!==t&&null!==e&&!(!Array.isArray(t)&&!Array.isArray(e))&&!(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)&&t.every((t,n)=>t===e[n])}function _(t,e){if(t===e)return!0;if(!t||!e)return!1;const n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(n=>$(t[n],e[n]))}function Q(t,e){return t.length===e.length&&t.every(t=>e.some(e=>V(t,e)))}function X(t,e){return t.some(t=>t.type===e)}function Y(t,e){return X(t,e.type)?t:[...t,e]}function Z(t,e){return t.filter(t=>t.type!==e)}function tt(t){if(0===t.length)return[k("")];if(t.every(t=>o(t)))return function(t){if(0===t.length)return[k("")];const e=[];for(const n of t){const t=e[e.length-1];t&&Q(t.marks,n.marks)?e[e.length-1]=k(t.text+n.text,t.marks):(n.text.length>0||0===e.length)&&e.push(n)}return 0===e.length?[k("")]:e}(t);const e=[];for(const r of t){if(i(r)){e.push(r);continue}const t=e[e.length-1];t&&o(t)&&Q(t.marks,r.marks)?e[e.length-1]=k(t.text+r.text,t.marks):(r.text.length>0||0===e.length)&&e.push(r)}const n=e.filter((t,n)=>{if(i(t))return!0;if(t.text.length>0)return!0;if(1===e.length)return!0;const r=e[n-1],s=e[n+1];return!(r&&i(r)||s&&i(s))});return 0===n.length?[k("")]:n.some(t=>o(t))?n:[k(""),...n]}function et(t){return"inline"===t.kind?t.node:k(t.text,t.marks)}function nt(t){return tt(t.map(et))}function*rt(t){let e=0;for(const n of t){const t=i(n)?1:n.text.length;yield{child:n,from:e,to:e+t},e+=t}}function st(t,e){let n=0;for(const{child:r,from:s,to:o}of rt(u(t)))if(i(r)){if(s>=e)return n}else{if(o>=e)return n+(e-s);n+=r.text.length}return n}function ot(t,e){const n=u(t);for(const{child:r,from:s}of rt(n)){if(i(r)){if(e===s)return{kind:"inline",node:r};continue}const t=e-s;if(t>=0&&t<r.text.length)return{kind:"text",char:r.text[t]??"",marks:r.marks}}return null}export{P as A,f as B,E as C,l as D,h as E,a as F,Z as G,Q as H,X as I,rt as J,nt as K,n as L,ot as M,R as N,r as O,u as P,c as R,U as S,C as T,V as U,o as V,tt as W,k as _,H as a,L as b,v as c,S as d,et as f,m as g,p as h,st as i,K as j,N as k,T as l,d as m,$ as n,w as o,y as p,e as q,_ as r,M as s,Y as t,W as u,s as v,B as w,G as x,q as y,i as z};
|
|
2
|
+
//# sourceMappingURL=Document-ssR6hBzG.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Document-D_2cIBJG.mjs","names":[],"sources":["../../src/model/Document.ts"],"sourcesContent":["/**\n * Core document model types for the Notectl editor.\n * All types are deeply readonly — mutations create new instances.\n */\n\nimport { normalizeHTMLId } from './HTMLUtils.js';\nimport type { BlockId, InlineTypeName, MarkTypeName, NodeTypeName } from './TypeBrands.js';\n\n// --- Mark Types ---\n\nexport interface Mark {\n\treadonly type: MarkTypeName;\n\treadonly attrs?: Readonly<Record<string, string | number | boolean>>;\n}\n\nexport interface BoldMark extends Mark {\n\treadonly type: MarkTypeName & 'bold';\n}\n\nexport interface ItalicMark extends Mark {\n\treadonly type: MarkTypeName & 'italic';\n}\n\nexport interface UnderlineMark extends Mark {\n\treadonly type: MarkTypeName & 'underline';\n}\n\n// --- Node Types ---\n\n/** JSON-compatible primitive stored in a block attribute. */\nexport type BlockAttrPrimitive = string | number | boolean | null;\n\n/** Scalar member permitted inside a structured block-attribute array. */\nexport type BlockAttrArrayValue = BlockAttrPrimitive;\n\n/**\n * Immutable JSON-compatible block attribute value.\n *\n * Marks and inline nodes intentionally retain their scalar-only attributes.\n * Block nodes may additionally own structured state (for example a table's\n * logical column-width vector) without encoding it in delimiter strings.\n */\nexport type BlockAttrValue = Exclude<BlockAttrPrimitive, null> | readonly BlockAttrArrayValue[];\n\nexport interface BlockAttrs {\n\treadonly [key: string]: BlockAttrValue;\n}\n\nexport interface TextNode {\n\treadonly type: 'text';\n\treadonly text: string;\n\treadonly marks: readonly Mark[];\n}\n\n/** Atomic inline element (width 1 in offset space). */\nexport interface InlineNode {\n\treadonly type: 'inline';\n\treadonly inlineType: InlineTypeName;\n\treadonly attrs: Readonly<Record<string, string | number | boolean>>;\n\t/**\n\t * Marks applied to this atomic node (e.g. a `link` on an inline image). Inline\n\t * nodes carry marks just like text nodes do, so a linked inline image survives\n\t * import, export, and rendering without the link being dropped.\n\t */\n\treadonly marks: readonly Mark[];\n}\n\n/** A child of a BlockNode: text, inline element, or nested block. */\nexport type ChildNode = TextNode | InlineNode | BlockNode;\n\nexport interface BlockNode {\n\t/** Internal editor identity, serialized to HTML as `data-block-id`. */\n\treadonly id: BlockId;\n\t/** Optional document-local HTML target, serialized to the block element's `id` attribute. */\n\treadonly htmlId?: string;\n\treadonly type: NodeTypeName;\n\treadonly attrs?: BlockAttrs;\n\treadonly children: readonly ChildNode[];\n}\n\nexport interface Document {\n\treadonly children: readonly BlockNode[];\n}\n\n// --- Text Segment (for mark-preserving undo) ---\n\nexport interface TextSegment {\n\treadonly text: string;\n\treadonly marks: readonly Mark[];\n}\n\n/** A content segment: either text (with marks) or an inline node. */\nexport type ContentSegment =\n\t| { readonly kind: 'text'; readonly text: string; readonly marks: readonly Mark[] }\n\t| { readonly kind: 'inline'; readonly node: InlineNode };\n\n/** Creates a text {@link ContentSegment}. */\nexport function textSegment(text: string, marks: readonly Mark[] = []): ContentSegment {\n\treturn { kind: 'text', text, marks };\n}\n\n/** Creates an inline {@link ContentSegment} wrapping an {@link InlineNode}. */\nexport function inlineSegment(node: InlineNode): ContentSegment {\n\treturn { kind: 'inline', node };\n}\n\n/** Returns content segments (text and inline) for a block range. */\nexport function getBlockContentSegmentsInRange(\n\tblock: BlockNode,\n\tfrom: number,\n\tto: number,\n): readonly ContentSegment[] {\n\tconst segments: ContentSegment[] = [];\n\tforEachInlineChildInRange(block, from, to, {\n\t\tonText(text: string, marks: readonly Mark[]): void {\n\t\t\tsegments.push({ kind: 'text', text, marks });\n\t\t},\n\t\tonInline(node: InlineNode): void {\n\t\t\tsegments.push({ kind: 'inline', node });\n\t\t},\n\t});\n\treturn segments;\n}\n\n/** Visitor callbacks invoked by {@link forEachInlineChildInRange} for each in-range child. */\nexport interface BlockRangeVisitor {\n\t/** Called with the clipped text and its marks for each text node overlapping the range. */\n\treadonly onText: (text: string, marks: readonly Mark[]) => void;\n\t/** Called for each inline node falling within the range. */\n\treadonly onInline?: (node: InlineNode) => void;\n}\n\n/**\n * Walks the inline children of `block` overlapping `[from, to)` and invokes the\n * matching visitor callback for each. Text nodes are clipped to the range before\n * `onText` fires; empty slices are skipped. This is the single read-only walker\n * for range-based inline serialization (segments, HTML, clipboard).\n */\nexport function forEachInlineChildInRange(\n\tblock: BlockNode,\n\tfrom: number,\n\tto: number,\n\tvisitor: BlockRangeVisitor,\n): void {\n\tfor (const { child, from: childFrom, to: childEnd } of walkInlineContent(\n\t\tgetInlineChildren(block),\n\t)) {\n\t\tif (childEnd <= from || childFrom >= to) continue;\n\n\t\tif (isInlineNode(child)) {\n\t\t\tvisitor.onInline?.(child);\n\t\t} else {\n\t\t\tconst sliceFrom: number = Math.max(0, from - childFrom);\n\t\t\tconst sliceTo: number = Math.min(child.text.length, to - childFrom);\n\t\t\tconst text: string = child.text.slice(sliceFrom, sliceTo);\n\t\t\tif (text.length > 0) {\n\t\t\t\tvisitor.onText(text, child.marks);\n\t\t\t}\n\t\t}\n\t}\n}\n\n// --- Type Guards ---\n\n/** Checks whether a value is a {@link TextNode}. */\nexport function isTextNode(node: unknown): node is TextNode {\n\treturn (\n\t\ttypeof node === 'object' &&\n\t\tnode !== null &&\n\t\t(node as TextNode).type === 'text' &&\n\t\ttypeof (node as TextNode).text === 'string'\n\t);\n}\n\n/** Checks whether a value is an {@link InlineNode}. */\nexport function isInlineNode(node: unknown): node is InlineNode {\n\treturn (\n\t\ttypeof node === 'object' &&\n\t\tnode !== null &&\n\t\t(node as InlineNode).type === 'inline' &&\n\t\ttypeof (node as InlineNode).inlineType === 'string'\n\t);\n}\n\n/** Checks whether a value is a {@link BlockNode}. */\nexport function isBlockNode(node: unknown): node is BlockNode {\n\treturn (\n\t\ttypeof node === 'object' &&\n\t\tnode !== null &&\n\t\ttypeof (node as BlockNode).id === 'string' &&\n\t\ttypeof (node as BlockNode).type === 'string' &&\n\t\t(node as BlockNode).type !== ('text' as string) &&\n\t\t(node as BlockNode).type !== ('inline' as string) &&\n\t\tArray.isArray((node as BlockNode).children)\n\t);\n}\n\n// --- Child Node Helpers ---\n\n/** Returns true if a block has only inline content (TextNodes and InlineNodes). */\nexport function isLeafBlock(node: BlockNode): boolean {\n\treturn node.children.every((c) => isTextNode(c) || isInlineNode(c));\n}\n\n/** Returns only the TextNode children of a block. */\nexport function getTextChildren(node: BlockNode): readonly TextNode[] {\n\treturn node.children.filter((c): c is TextNode => isTextNode(c));\n}\n\n/** Returns the inline content children (TextNode | InlineNode) of a block. */\nexport function getInlineChildren(node: BlockNode): readonly (TextNode | InlineNode)[] {\n\treturn node.children.filter((c): c is TextNode | InlineNode => isTextNode(c) || isInlineNode(c));\n}\n\n/** Returns only the BlockNode children of a block. */\nexport function getBlockChildren(node: BlockNode): readonly BlockNode[] {\n\treturn node.children.filter((c): c is BlockNode => isBlockNode(c));\n}\n\n// --- Factory Functions ---\n\n/** Generates a unique block ID using crypto.randomUUID(). */\nexport function generateBlockId(): BlockId {\n\treturn `block-${crypto.randomUUID()}` as BlockId;\n}\n\n/** Creates a new empty {@link Document} with a single empty paragraph. */\nexport function createDocument(children?: readonly BlockNode[]): Document {\n\treturn {\n\t\tchildren: children ? [...children] : [createBlockNode('paragraph' as NodeTypeName)],\n\t};\n}\n\n/** Creates a new {@link BlockNode}. */\nexport function createBlockNode(\n\ttype: NodeTypeName,\n\tchildren?: readonly ChildNode[],\n\tid?: BlockId,\n\tattrs?: BlockAttrs,\n\thtmlId?: string,\n): BlockNode {\n\tconst normalizedHTMLId: string | undefined = normalizeHTMLId(htmlId);\n\treturn {\n\t\tid: id ?? generateBlockId(),\n\t\t...(normalizedHTMLId ? { htmlId: normalizedHTMLId } : {}),\n\t\ttype,\n\t\t...(attrs ? { attrs: cloneBlockAttrs(attrs) } : {}),\n\t\tchildren: children ? [...children] : [createTextNode('')],\n\t};\n}\n\n/** Creates a new {@link TextNode}. */\nexport function createTextNode(text: string, marks?: readonly Mark[]): TextNode {\n\treturn {\n\t\ttype: 'text',\n\t\ttext,\n\t\tmarks: cloneMarks(marks ?? []),\n\t};\n}\n\n/** Creates a new {@link InlineNode}. */\nexport function createInlineNode(\n\tinlineType: InlineTypeName,\n\tattrs?: Readonly<Record<string, string | number | boolean>>,\n\tmarks?: readonly Mark[],\n): InlineNode {\n\treturn {\n\t\ttype: 'inline',\n\t\tinlineType,\n\t\tattrs: attrs ? { ...attrs } : {},\n\t\tmarks: cloneMarks(marks ?? []),\n\t};\n}\n\n/** Creates an empty paragraph block node with the given ID. */\nexport function createEmptyParagraph(id?: BlockId): BlockNode {\n\treturn createBlockNode('paragraph' as NodeTypeName, [createTextNode('')], id);\n}\n\n// --- Snapshot Ownership -------------------------------------------------\n\n// `Object.isFrozen` is shallow and therefore cannot prove our deep-immutability\n// invariant for external values. These private brands are added only after a\n// complete traversal, allowing persistent state to skip verified shared\n// subtrees without trusting caller-applied shallow freezes.\nconst VERIFIED_DOCUMENTS = new WeakSet<Document>();\nconst VERIFIED_BLOCKS = new WeakSet<BlockNode>();\nconst VERIFIED_BLOCK_ATTRS = new WeakSet<BlockAttrs>();\nconst VERIFIED_MARKS = new WeakSet<Mark>();\nconst VERIFIED_MARK_LISTS = new WeakSet<readonly Mark[]>();\nconst VERIFIED_INLINE_NODES = new WeakSet<InlineNode>();\nconst VERIFIED_TEXT_NODES = new WeakSet<TextNode>();\nconst VERIFIED_SEGMENT_LISTS = new WeakSet<readonly ContentSegment[]>();\n\n/**\n * Creates a fully detached document snapshot.\n *\n * Public JSON boundaries use this instead of exposing the structurally shared\n * objects owned by an {@link EditorState}. Besides child arrays, attribute\n * records, structured block attributes, marks, and mark attributes are copied.\n */\nexport function cloneDocument(doc: Document): Document {\n\treturn { ...doc, children: doc.children.map(cloneBlockNode) };\n}\n\n/** Creates a fully detached block snapshot, preserving its stable block ID. */\nexport function cloneBlockNode(block: BlockNode): BlockNode {\n\tconst attrs: BlockAttrs | undefined = block.attrs ? cloneBlockAttrs(block.attrs) : undefined;\n\treturn {\n\t\t...block,\n\t\t...(attrs ? { attrs } : {}),\n\t\tchildren: block.children.map(cloneChildNode),\n\t};\n}\n\n/** Creates a detached mark set, including each mark's attribute record. */\nexport function cloneMarks(marks: readonly Mark[]): Mark[] {\n\treturn marks.map(cloneMark);\n}\n\n/** Creates a detached mark, including its attribute record. */\nexport function cloneMark(mark: Mark): Mark {\n\treturn {\n\t\t...mark,\n\t\t...(mark.attrs ? { attrs: { ...mark.attrs } } : {}),\n\t};\n}\n\n/** Creates a detached inline node, including attrs, marks, and mark attrs. */\nexport function cloneInlineNode(node: InlineNode): InlineNode {\n\treturn {\n\t\t...node,\n\t\tattrs: { ...node.attrs },\n\t\tmarks: cloneMarks(node.marks),\n\t};\n}\n\n/** Creates a detached content-segment payload for transaction/history ownership. */\nexport function cloneContentSegment(segment: ContentSegment): ContentSegment {\n\treturn segment.kind === 'text'\n\t\t? { ...segment, marks: cloneMarks(segment.marks) }\n\t\t: { ...segment, node: cloneInlineNode(segment.node) };\n}\n\n/** Creates a detached list of content-segment payloads. */\nexport function cloneContentSegments(segments: readonly ContentSegment[]): ContentSegment[] {\n\treturn segments.map(cloneContentSegment);\n}\n\n/**\n * Freezes a document and every mutable collection reachable from it.\n *\n * Already-frozen nodes are skipped. This keeps transaction application\n * proportional to the changed branch because unchanged subtrees are\n * structurally shared between states.\n */\nexport function freezeDocument(doc: Document): Document {\n\tif (VERIFIED_DOCUMENTS.has(doc)) return doc;\n\tfor (const block of doc.children) freezeBlockNode(block);\n\tif (!Object.isFrozen(doc.children)) Object.freeze(doc.children);\n\tif (!Object.isFrozen(doc)) Object.freeze(doc);\n\tVERIFIED_DOCUMENTS.add(doc);\n\treturn doc;\n}\n\nfunction cloneChildNode(child: ChildNode): ChildNode {\n\tif (isTextNode(child)) {\n\t\tconst marks: readonly Mark[] | undefined = Array.isArray(child.marks)\n\t\t\t? cloneMarks(child.marks)\n\t\t\t: undefined;\n\t\treturn {\n\t\t\t...child,\n\t\t\t...(marks ? { marks } : {}),\n\t\t};\n\t}\n\tif (isInlineNode(child)) {\n\t\treturn cloneInlineNode(child);\n\t}\n\treturn cloneBlockNode(child);\n}\n\n/** Creates a detached block-attribute record, including structured array values. */\nexport function cloneBlockAttrs(attrs: BlockAttrs): BlockAttrs {\n\tconst copy: Record<string, BlockAttrValue> = {};\n\tfor (const [key, value] of Object.entries(attrs)) {\n\t\tcopy[key] = Array.isArray(value) ? [...value] : value;\n\t}\n\treturn copy;\n}\n\n/** Deep-freezes one detached block snapshot in place. */\nexport function freezeBlockNode(block: BlockNode): void {\n\tif (VERIFIED_BLOCKS.has(block)) return;\n\tif (block.attrs) freezeBlockAttrs(block.attrs);\n\tfor (const child of block.children) {\n\t\tif (isTextNode(child) || isInlineNode(child)) {\n\t\t\tfreezeInlineChild(child);\n\t\t} else {\n\t\t\tfreezeBlockNode(child);\n\t\t}\n\t}\n\tif (!Object.isFrozen(block.children)) Object.freeze(block.children);\n\tif (!Object.isFrozen(block)) Object.freeze(block);\n\tVERIFIED_BLOCKS.add(block);\n}\n\n/** Deep-freezes a block-attribute record in place. */\nexport function freezeBlockAttrs(attrs: BlockAttrs): void {\n\tif (VERIFIED_BLOCK_ATTRS.has(attrs)) return;\n\tfor (const value of Object.values(attrs)) {\n\t\tif (Array.isArray(value) && !Object.isFrozen(value)) Object.freeze(value);\n\t}\n\tif (!Object.isFrozen(attrs)) Object.freeze(attrs);\n\tVERIFIED_BLOCK_ATTRS.add(attrs);\n}\n\n/** Deep-freezes a mark and its attrs in place. */\nexport function freezeMark(mark: Mark): void {\n\tif (VERIFIED_MARKS.has(mark)) return;\n\tif (mark.attrs && !Object.isFrozen(mark.attrs)) Object.freeze(mark.attrs);\n\tif (!Object.isFrozen(mark)) Object.freeze(mark);\n\tVERIFIED_MARKS.add(mark);\n}\n\n/** Deep-freezes a mark list in place. */\nexport function freezeMarks(marks: readonly Mark[]): void {\n\tif (VERIFIED_MARK_LISTS.has(marks)) return;\n\tfor (const mark of marks) freezeMark(mark);\n\tif (!Object.isFrozen(marks)) Object.freeze(marks);\n\tVERIFIED_MARK_LISTS.add(marks);\n}\n\n/** Deep-freezes an inline node and all of its payload records in place. */\nexport function freezeInlineNode(node: InlineNode): void {\n\tif (VERIFIED_INLINE_NODES.has(node)) return;\n\tif (!Object.isFrozen(node.attrs)) Object.freeze(node.attrs);\n\tfreezeMarks(node.marks);\n\tif (!Object.isFrozen(node)) Object.freeze(node);\n\tVERIFIED_INLINE_NODES.add(node);\n}\n\n/** Deep-freezes transaction/history content-segment payloads in place. */\nexport function freezeContentSegments(segments: readonly ContentSegment[]): void {\n\tif (VERIFIED_SEGMENT_LISTS.has(segments)) return;\n\tfor (const segment of segments) {\n\t\tif (segment.kind === 'text') freezeMarks(segment.marks);\n\t\telse freezeInlineNode(segment.node);\n\t\tif (!Object.isFrozen(segment)) Object.freeze(segment);\n\t}\n\tif (!Object.isFrozen(segments)) Object.freeze(segments);\n\tVERIFIED_SEGMENT_LISTS.add(segments);\n}\n\nfunction freezeInlineChild(child: TextNode | InlineNode): void {\n\tif (isInlineNode(child)) {\n\t\tfreezeInlineNode(child);\n\t\treturn;\n\t}\n\tif (VERIFIED_TEXT_NODES.has(child)) return;\n\tfreezeMarks(child.marks);\n\tif (!Object.isFrozen(child)) Object.freeze(child);\n\tVERIFIED_TEXT_NODES.add(child);\n}\n\n// --- Utility Functions ---\n\n/** Extracts plain text from a block (InlineNodes are skipped). */\nexport function getBlockText(block: BlockNode): string {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\tlet text = '';\n\tfor (const child of inlineChildren) {\n\t\tif (isTextNode(child)) {\n\t\t\ttext += child.text;\n\t\t}\n\t}\n\treturn text;\n}\n\n/** Returns the length of a block's inline content (InlineNodes count as 1). */\nexport function getBlockLength(block: BlockNode): number {\n\tlet len = 0;\n\tfor (const { to } of walkInlineContent(getInlineChildren(block))) {\n\t\tlen = to;\n\t}\n\treturn len;\n}\n\n/** Returns the marks active at the given offset (empty for InlineNode offsets). */\nexport function getBlockMarksAtOffset(block: BlockNode, offset: number): readonly Mark[] {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\n\tfor (const { child, from, to } of walkInlineContent(inlineChildren)) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (offset === from) return [];\n\t\t\tcontinue;\n\t\t}\n\t\tif (offset >= from && offset < to) {\n\t\t\treturn child.marks;\n\t\t}\n\t\t// Empty text node (from === to): match exactly at its position.\n\t\tif (offset === from && child.text.length === 0) {\n\t\t\treturn child.marks;\n\t\t}\n\t}\n\n\t// Fall back to last text child's marks\n\tfor (let i: number = inlineChildren.length - 1; i >= 0; i--) {\n\t\tconst child: TextNode | InlineNode | undefined = inlineChildren[i];\n\t\tif (child && isTextNode(child)) {\n\t\t\treturn child.marks;\n\t\t}\n\t}\n\treturn [];\n}\n\n/** Returns the marks of the text content immediately to the right of `offset`. */\nfunction getMarksAfterOffset(block: BlockNode, offset: number): readonly Mark[] {\n\tfor (const { child, from, to } of walkInlineContent(getInlineChildren(block))) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (offset === from) return [];\n\t\t\tcontinue;\n\t\t}\n\t\tif (offset >= from && offset < to) return child.marks;\n\t}\n\treturn [];\n}\n\n/**\n * Returns the marks that text typed at a collapsed cursor should carry.\n *\n * Marks are derived from the content around `offset` (via\n * {@link getBlockMarksAtOffset}). A mark whose spec is non-inclusive\n * (`isMarkInclusive` returns `false`) is only kept when it also covers the\n * content to the right of the cursor, so it never bleeds past its right\n * boundary onto newly typed text. Inclusive marks (the default) are unaffected.\n */\nexport function getCursorMarks(\n\tblock: BlockNode,\n\toffset: number,\n\tisMarkInclusive: (type: MarkTypeName) => boolean,\n): readonly Mark[] {\n\tconst marks: readonly Mark[] = getBlockMarksAtOffset(block, offset);\n\tif (marks.length === 0) return marks;\n\n\tconst after: readonly Mark[] = getMarksAfterOffset(block, offset);\n\treturn marks.filter(\n\t\t(mark) => isMarkInclusive(mark.type) || after.some((a) => marksEqual(a, mark)),\n\t);\n}\n\n/** Checks whether two marks are equal by type and attrs. */\nexport function marksEqual(a: Mark, b: Mark): boolean {\n\tif (a.type !== b.type) return false;\n\tconst aAttrs = a.attrs;\n\tconst bAttrs = b.attrs;\n\tif (!aAttrs && !bAttrs) return true;\n\tif (!aAttrs || !bAttrs) return false;\n\tconst aKeys = Object.keys(aAttrs);\n\tconst bKeys = Object.keys(bAttrs);\n\tif (aKeys.length !== bKeys.length) return false;\n\treturn aKeys.every((key) => aAttrs[key] === bAttrs[key]);\n}\n\n/** Deep equality for immutable, JSON-compatible block attribute values. */\nexport function blockAttrValuesEqual(\n\ta: BlockAttrValue | undefined,\n\tb: BlockAttrValue | undefined,\n): boolean {\n\tif (a === b) return true;\n\tif (a === undefined || b === undefined || a === null || b === null) return false;\n\tif (Array.isArray(a) || Array.isArray(b)) {\n\t\tif (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;\n\t\treturn a.every((value, index) => value === b[index]);\n\t}\n\treturn false;\n}\n\n/** Deep equality for block attribute records. */\nexport function blockAttrsEqual(a: BlockAttrs | undefined, b: BlockAttrs | undefined): boolean {\n\tif (a === b) return true;\n\tif (!a || !b) return false;\n\tconst aKeys: readonly string[] = Object.keys(a);\n\tconst bKeys: readonly string[] = Object.keys(b);\n\tif (aKeys.length !== bKeys.length) return false;\n\treturn aKeys.every((key) => blockAttrValuesEqual(a[key], b[key]));\n}\n\n/** Checks whether two mark arrays contain the same marks (order-independent). */\nexport function markSetsEqual(a: readonly Mark[], b: readonly Mark[]): boolean {\n\tif (a.length !== b.length) return false;\n\treturn a.every((markA) => b.some((markB) => marksEqual(markA, markB)));\n}\n\n/** Returns true if the mark set contains a mark of the given type. */\nexport function hasMark(marks: readonly Mark[], markType: MarkTypeName): boolean {\n\treturn marks.some((m) => m.type === markType);\n}\n\n/** Adds a mark to a mark set (no duplicates). */\nexport function addMarkToSet(marks: readonly Mark[], mark: Mark): readonly Mark[] {\n\tif (hasMark(marks, mark.type)) return marks;\n\treturn [...marks, mark];\n}\n\n/** Removes a mark type from a mark set. */\nexport function removeMarkFromSet(marks: readonly Mark[], markType: MarkTypeName): readonly Mark[] {\n\treturn marks.filter((m) => m.type !== markType);\n}\n\n/**\n * Normalizes text nodes within a block: merges adjacent nodes with identical marks,\n * removes empty text nodes (keeping at least one).\n */\nexport function normalizeTextNodes(nodes: readonly TextNode[]): readonly TextNode[] {\n\tif (nodes.length === 0) return [createTextNode('')];\n\n\tconst result: TextNode[] = [];\n\tfor (const node of nodes) {\n\t\tconst prev: TextNode | undefined = result[result.length - 1];\n\t\tif (prev && markSetsEqual(prev.marks, node.marks)) {\n\t\t\tresult[result.length - 1] = createTextNode(prev.text + node.text, prev.marks);\n\t\t} else if (node.text.length > 0 || result.length === 0) {\n\t\t\tresult.push(node);\n\t\t}\n\t}\n\n\treturn result.length === 0 ? [createTextNode('')] : result;\n}\n\n/**\n * Normalizes mixed inline content: merges adjacent TextNodes with same marks,\n * removes empty TextNodes adjacent to InlineNodes, preserves InlineNodes as-is.\n * Guarantees at least one TextNode exists if all text is empty.\n */\nexport function normalizeInlineContent(\n\tnodes: readonly (TextNode | InlineNode)[],\n): readonly (TextNode | InlineNode)[] {\n\tif (nodes.length === 0) return [createTextNode('')];\n\n\t// Fast path: no InlineNodes, delegate to normalizeTextNodes\n\tif (nodes.every((n): n is TextNode => isTextNode(n))) {\n\t\treturn normalizeTextNodes(nodes);\n\t}\n\n\tconst result: (TextNode | InlineNode)[] = [];\n\n\tfor (const node of nodes) {\n\t\tif (isInlineNode(node)) {\n\t\t\tresult.push(node);\n\t\t\tcontinue;\n\t\t}\n\t\t// TextNode: try to merge with previous TextNode\n\t\tconst prev: TextNode | InlineNode | undefined = result[result.length - 1];\n\t\tif (prev && isTextNode(prev) && markSetsEqual(prev.marks, node.marks)) {\n\t\t\tresult[result.length - 1] = createTextNode(prev.text + node.text, prev.marks);\n\t\t} else if (node.text.length > 0 || result.length === 0) {\n\t\t\tresult.push(node);\n\t\t}\n\t}\n\n\t// Remove empty TextNodes that are adjacent to InlineNodes\n\tconst cleaned: (TextNode | InlineNode)[] = result.filter((node, i) => {\n\t\tif (isInlineNode(node)) return true;\n\t\tif (node.text.length > 0) return true;\n\t\t// Keep if it's the only node\n\t\tif (result.length === 1) return true;\n\t\t// Remove empty TextNode if adjacent to InlineNode\n\t\tconst prev: TextNode | InlineNode | undefined = result[i - 1];\n\t\tconst next: TextNode | InlineNode | undefined = result[i + 1];\n\t\tif ((prev && isInlineNode(prev)) || (next && isInlineNode(next))) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\n\t// Ensure at least one TextNode exists\n\tif (cleaned.length === 0) return [createTextNode('')];\n\tif (!cleaned.some((n) => isTextNode(n))) {\n\t\treturn [createTextNode(''), ...cleaned];\n\t}\n\n\treturn cleaned;\n}\n\n/** Materializes a single {@link ContentSegment} into its inline child node. */\nexport function contentSegmentToInlineNode(segment: ContentSegment): TextNode | InlineNode {\n\treturn segment.kind === 'inline' ? segment.node : createTextNode(segment.text, segment.marks);\n}\n\n/**\n * Materializes content segments (text + inline) into normalized inline children.\n * Inverse of {@link getBlockContentSegmentsInRange}: used when turning a range of\n * segments back into a block's children (paste insertion, slice extraction).\n */\nexport function segmentsToInlineChildren(\n\tsegments: readonly ContentSegment[],\n): readonly (TextNode | InlineNode)[] {\n\treturn normalizeInlineContent(segments.map(contentSegmentToInlineNode));\n}\n\n/** Yields each inline child with its offset range. InlineNodes have width 1. */\nexport function* walkInlineContent(children: readonly (TextNode | InlineNode)[]): Generator<{\n\treadonly child: TextNode | InlineNode;\n\treadonly from: number;\n\treadonly to: number;\n}> {\n\tlet pos = 0;\n\tfor (const child of children) {\n\t\tconst width: number = isInlineNode(child) ? 1 : child.text.length;\n\t\tyield { child, from: pos, to: pos + width };\n\t\tpos += width;\n\t}\n}\n\n/**\n * Converts a block-space offset to a text-space offset.\n *\n * Block-space counts InlineNodes as width 1, but `getBlockText()` skips them.\n * This function maps a block offset to the equivalent position in the\n * text-only string returned by `getBlockText()`.\n */\nexport function blockOffsetToTextOffset(block: BlockNode, blockOffset: number): number {\n\tlet textPos = 0;\n\n\tfor (const { child, from, to } of walkInlineContent(getInlineChildren(block))) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (from >= blockOffset) return textPos;\n\t\t} else {\n\t\t\tif (to >= blockOffset) return textPos + (blockOffset - from);\n\t\t\ttextPos += child.text.length;\n\t\t}\n\t}\n\n\treturn textPos;\n}\n\n/** Returns the content at a specific offset: text char, inline node, or null. */\nexport function getContentAtOffset(\n\tblock: BlockNode,\n\toffset: number,\n):\n\t| { readonly kind: 'text'; readonly char: string; readonly marks: readonly Mark[] }\n\t| { readonly kind: 'inline'; readonly node: InlineNode }\n\t| null {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\n\tfor (const { child, from } of walkInlineContent(inlineChildren)) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (offset === from) return { kind: 'inline', node: child };\n\t\t\tcontinue;\n\t\t}\n\t\tconst localOffset: number = offset - from;\n\t\tif (localOffset >= 0 && localOffset < child.text.length) {\n\t\t\treturn {\n\t\t\t\tkind: 'text',\n\t\t\t\tchar: child.text[localOffset] ?? '',\n\t\t\t\tmarks: child.marks,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn null;\n}\n"],"mappings":"6CAiGA,SAAgB,EAAY,EAAc,EAAyB,IAClE,MAAO,CAAE,KAAM,OAAQ,OAAM,QAC9B,CAGA,SAAgB,EAAc,GAC7B,MAAO,CAAE,KAAM,SAAU,OAC1B,CAGA,SAAgB,EACf,EACA,EACA,GAEA,MAAM,EAA6B,GASnC,OARA,EAA0B,EAAO,EAAM,EAAI,CAC1C,MAAA,CAAO,EAAc,GACpB,EAAS,KAAK,CAAE,KAAM,OAAQ,OAAM,SACrC,EACA,QAAA,CAAS,GACR,EAAS,KAAK,CAAE,KAAM,SAAU,QACjC,IAEM,CACR,CAgBA,SAAgB,EACf,EACA,EACA,EACA,GAEA,IAAK,MAAM,MAAE,EAAO,KAAM,EAAW,GAAI,KAAc,GACtD,EAAkB,IAElB,KAAI,GAAY,GAAQ,GAAa,GAErC,GAAI,EAAa,GAChB,EAAQ,WAAW,OACb,CACN,MAAM,EAAoB,KAAK,IAAI,EAAG,EAAO,GACvC,EAAkB,KAAK,IAAI,EAAM,KAAK,OAAQ,EAAK,GACnD,EAAe,EAAM,KAAK,MAAM,EAAW,GAC7C,EAAK,OAAS,GACjB,EAAQ,OAAO,EAAM,EAAM,MAE7B,CAEF,CAKA,SAAgB,EAAW,GAC1B,MACiB,iBAAT,GACE,OAAT,GAC4B,SAA3B,EAAkB,MACgB,iBAA3B,EAAkB,I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AAa,MAO3D,OAAuB,IAAnB,EAAQ,OAAqB,CAAC,EAAe,KAC5C,EAAQ,KAAM,GAAM,EAAW,IAI7B,EAHC,CAAC,EAAe,OAAQ,EAIjC,CAGA,SAAgB,GAA2B,GAC1C,MAAwB,WAAjB,EAAQ,KAAoB,EAAQ,KAAO,EAAe,EAAQ,KAAM,EAAQ,MACxF,CAOA,SAAgB,GACf,GAEA,OAAO,GAAuB,EAAS,IAAI,IAC5C,CAGA,SAAiB,GAAkB,GAKlC,IAAI,EAAM,EACV,IAAK,MAAM,KAAS,EAAU,CAC7B,MAAM,EAAgB,EAAa,GAAS,EAAI,EAAM,KAAK,YACrD,CAAE,QAAO,KAAM,EAAK,GAAI,EAAM,GACpC,GAAO,CACR,CACD,CASA,SAAgB,GAAwB,EAAkB,GACzD,IAAI,EAAU,EAEd,IAAK,MAAM,MAAE,EAAA,KAAO,EAAA,GAAM,KAAQ,GAAkB,EAAkB,IACrE,GAAI,EAAa,IACZ,GAAA,GAAQ,EAAa,OAAO,MAC1B,CACN,GAAI,GAAM,EAAa,OAAO,GAAW,EAAc,GACvD,GAAW,EAAM,KAAK,MACvB,CAGD,OAAO,CACR,CAGA,SAAgB,GACf,EACA,GAKA,MAAM,EAAqD,EAAkB,GAE7E,IAAK,MAAM,MAAE,EAAA,KAAO,KAAU,GAAkB,GAAiB,CAChE,GAAI,EAAa,GAAQ,CACxB,GAAI,IAAW,EAAM,MAAO,CAAE,KAAM,SAAU,KAAM,GACpD,QACD,CACA,MAAM,EAAsB,EAAS,EACrC,GAAI,GAAe,GAAK,EAAc,EAAM,KAAK,OAChD,MAAO,CACN,KAAM,OACN,KAAM,EAAM,KAAK,IAAgB,GACjC,MAAO,EAAM,MAGhB,CAEA,OAAO,IACR"}
|
|
1
|
+
{"version":3,"file":"Document-ssR6hBzG.mjs","names":[],"sources":["../../src/model/Document.ts"],"sourcesContent":["/**\n * Core document model types for the Notectl editor.\n * All types are deeply readonly — mutations create new instances.\n */\n\nimport { normalizeHTMLId } from './HTMLUtils.js';\nimport type { BlockId, InlineTypeName, MarkTypeName, NodeTypeName } from './TypeBrands.js';\n\n// --- Mark Types ---\n\nexport interface Mark {\n\treadonly type: MarkTypeName;\n\treadonly attrs?: Readonly<Record<string, string | number | boolean>>;\n}\n\nexport interface BoldMark extends Mark {\n\treadonly type: MarkTypeName & 'bold';\n}\n\nexport interface ItalicMark extends Mark {\n\treadonly type: MarkTypeName & 'italic';\n}\n\nexport interface UnderlineMark extends Mark {\n\treadonly type: MarkTypeName & 'underline';\n}\n\n// --- Node Types ---\n\n/** JSON-compatible primitive stored in a block attribute. */\nexport type BlockAttrPrimitive = string | number | boolean | null;\n\n/** Scalar member permitted inside a structured block-attribute array. */\nexport type BlockAttrArrayValue = BlockAttrPrimitive;\n\n/**\n * Immutable JSON-compatible block attribute value.\n *\n * Marks and inline nodes intentionally retain their scalar-only attributes.\n * Block nodes may additionally own structured state (for example a table's\n * logical column-width vector) without encoding it in delimiter strings.\n */\nexport type BlockAttrValue = Exclude<BlockAttrPrimitive, null> | readonly BlockAttrArrayValue[];\n\nexport interface BlockAttrs {\n\treadonly [key: string]: BlockAttrValue;\n}\n\nexport interface TextNode {\n\treadonly type: 'text';\n\treadonly text: string;\n\treadonly marks: readonly Mark[];\n}\n\n/** Atomic inline element (width 1 in offset space). */\nexport interface InlineNode {\n\treadonly type: 'inline';\n\treadonly inlineType: InlineTypeName;\n\treadonly attrs: Readonly<Record<string, string | number | boolean>>;\n\t/**\n\t * Marks applied to this atomic node (e.g. a `link` on an inline image). Inline\n\t * nodes carry marks just like text nodes do, so a linked inline image survives\n\t * import, export, and rendering without the link being dropped.\n\t */\n\treadonly marks: readonly Mark[];\n}\n\n/** A child of a BlockNode: text, inline element, or nested block. */\nexport type ChildNode = TextNode | InlineNode | BlockNode;\n\nexport interface BlockNode {\n\t/** Internal editor identity, serialized to HTML as `data-block-id`. */\n\treadonly id: BlockId;\n\t/** Optional document-local HTML target, serialized to the block element's `id` attribute. */\n\treadonly htmlId?: string;\n\treadonly type: NodeTypeName;\n\treadonly attrs?: BlockAttrs;\n\treadonly children: readonly ChildNode[];\n}\n\nexport interface Document {\n\treadonly children: readonly BlockNode[];\n}\n\n// --- Text Segment (for mark-preserving undo) ---\n\nexport interface TextSegment {\n\treadonly text: string;\n\treadonly marks: readonly Mark[];\n}\n\n/** A content segment: either text (with marks) or an inline node. */\nexport type ContentSegment =\n\t| { readonly kind: 'text'; readonly text: string; readonly marks: readonly Mark[] }\n\t| { readonly kind: 'inline'; readonly node: InlineNode };\n\n/** Creates a text {@link ContentSegment}. */\nexport function textSegment(text: string, marks: readonly Mark[] = []): ContentSegment {\n\treturn { kind: 'text', text, marks };\n}\n\n/** Creates an inline {@link ContentSegment} wrapping an {@link InlineNode}. */\nexport function inlineSegment(node: InlineNode): ContentSegment {\n\treturn { kind: 'inline', node };\n}\n\n/** Returns content segments (text and inline) for a block range. */\nexport function getBlockContentSegmentsInRange(\n\tblock: BlockNode,\n\tfrom: number,\n\tto: number,\n): readonly ContentSegment[] {\n\tconst segments: ContentSegment[] = [];\n\tforEachInlineChildInRange(block, from, to, {\n\t\tonText(text: string, marks: readonly Mark[]): void {\n\t\t\tsegments.push({ kind: 'text', text, marks });\n\t\t},\n\t\tonInline(node: InlineNode): void {\n\t\t\tsegments.push({ kind: 'inline', node });\n\t\t},\n\t});\n\treturn segments;\n}\n\n/** Visitor callbacks invoked by {@link forEachInlineChildInRange} for each in-range child. */\nexport interface BlockRangeVisitor {\n\t/** Called with the clipped text and its marks for each text node overlapping the range. */\n\treadonly onText: (text: string, marks: readonly Mark[]) => void;\n\t/** Called for each inline node falling within the range. */\n\treadonly onInline?: (node: InlineNode) => void;\n}\n\n/**\n * Walks the inline children of `block` overlapping `[from, to)` and invokes the\n * matching visitor callback for each. Text nodes are clipped to the range before\n * `onText` fires; empty slices are skipped. This is the single read-only walker\n * for range-based inline serialization (segments, HTML, clipboard).\n */\nexport function forEachInlineChildInRange(\n\tblock: BlockNode,\n\tfrom: number,\n\tto: number,\n\tvisitor: BlockRangeVisitor,\n): void {\n\tfor (const { child, from: childFrom, to: childEnd } of walkInlineContent(\n\t\tgetInlineChildren(block),\n\t)) {\n\t\tif (childEnd <= from || childFrom >= to) continue;\n\n\t\tif (isInlineNode(child)) {\n\t\t\tvisitor.onInline?.(child);\n\t\t} else {\n\t\t\tconst sliceFrom: number = Math.max(0, from - childFrom);\n\t\t\tconst sliceTo: number = Math.min(child.text.length, to - childFrom);\n\t\t\tconst text: string = child.text.slice(sliceFrom, sliceTo);\n\t\t\tif (text.length > 0) {\n\t\t\t\tvisitor.onText(text, child.marks);\n\t\t\t}\n\t\t}\n\t}\n}\n\n// --- Type Guards ---\n\n/** Checks whether a value is a {@link TextNode}. */\nexport function isTextNode(node: unknown): node is TextNode {\n\treturn (\n\t\ttypeof node === 'object' &&\n\t\tnode !== null &&\n\t\t(node as TextNode).type === 'text' &&\n\t\ttypeof (node as TextNode).text === 'string'\n\t);\n}\n\n/** Checks whether a value is an {@link InlineNode}. */\nexport function isInlineNode(node: unknown): node is InlineNode {\n\treturn (\n\t\ttypeof node === 'object' &&\n\t\tnode !== null &&\n\t\t(node as InlineNode).type === 'inline' &&\n\t\ttypeof (node as InlineNode).inlineType === 'string'\n\t);\n}\n\n/** Checks whether a value is a {@link BlockNode}. */\nexport function isBlockNode(node: unknown): node is BlockNode {\n\treturn (\n\t\ttypeof node === 'object' &&\n\t\tnode !== null &&\n\t\ttypeof (node as BlockNode).id === 'string' &&\n\t\ttypeof (node as BlockNode).type === 'string' &&\n\t\t(node as BlockNode).type !== ('text' as string) &&\n\t\t(node as BlockNode).type !== ('inline' as string) &&\n\t\tArray.isArray((node as BlockNode).children)\n\t);\n}\n\n// --- Child Node Helpers ---\n\n/** Returns true if a block has only inline content (TextNodes and InlineNodes). */\nexport function isLeafBlock(node: BlockNode): boolean {\n\treturn node.children.every((c) => isTextNode(c) || isInlineNode(c));\n}\n\n/** Returns only the TextNode children of a block. */\nexport function getTextChildren(node: BlockNode): readonly TextNode[] {\n\treturn node.children.filter((c): c is TextNode => isTextNode(c));\n}\n\n/** Returns the inline content children (TextNode | InlineNode) of a block. */\nexport function getInlineChildren(node: BlockNode): readonly (TextNode | InlineNode)[] {\n\treturn node.children.filter((c): c is TextNode | InlineNode => isTextNode(c) || isInlineNode(c));\n}\n\n/** Returns only the BlockNode children of a block. */\nexport function getBlockChildren(node: BlockNode): readonly BlockNode[] {\n\treturn node.children.filter((c): c is BlockNode => isBlockNode(c));\n}\n\n// --- Factory Functions ---\n\n/** Generates a unique block ID using crypto.randomUUID(). */\nexport function generateBlockId(): BlockId {\n\treturn `block-${crypto.randomUUID()}` as BlockId;\n}\n\n/** Creates a new empty {@link Document} with a single empty paragraph. */\nexport function createDocument(children?: readonly BlockNode[]): Document {\n\treturn {\n\t\tchildren: children ? [...children] : [createBlockNode('paragraph' as NodeTypeName)],\n\t};\n}\n\n/** Creates a new {@link BlockNode}. */\nexport function createBlockNode(\n\ttype: NodeTypeName,\n\tchildren?: readonly ChildNode[],\n\tid?: BlockId,\n\tattrs?: BlockAttrs,\n\thtmlId?: string,\n): BlockNode {\n\tconst normalizedHTMLId: string | undefined = normalizeHTMLId(htmlId);\n\treturn {\n\t\tid: id ?? generateBlockId(),\n\t\t...(normalizedHTMLId ? { htmlId: normalizedHTMLId } : {}),\n\t\ttype,\n\t\t...(attrs ? { attrs: cloneBlockAttrs(attrs) } : {}),\n\t\tchildren: children ? [...children] : [createTextNode('')],\n\t};\n}\n\n/** Creates a new {@link TextNode}. */\nexport function createTextNode(text: string, marks?: readonly Mark[]): TextNode {\n\treturn {\n\t\ttype: 'text',\n\t\ttext,\n\t\tmarks: cloneMarks(marks ?? []),\n\t};\n}\n\n/** Creates a new {@link InlineNode}. */\nexport function createInlineNode(\n\tinlineType: InlineTypeName,\n\tattrs?: Readonly<Record<string, string | number | boolean>>,\n\tmarks?: readonly Mark[],\n): InlineNode {\n\treturn {\n\t\ttype: 'inline',\n\t\tinlineType,\n\t\tattrs: attrs ? { ...attrs } : {},\n\t\tmarks: cloneMarks(marks ?? []),\n\t};\n}\n\n/** Creates an empty paragraph block node with the given ID. */\nexport function createEmptyParagraph(id?: BlockId): BlockNode {\n\treturn createBlockNode('paragraph' as NodeTypeName, [createTextNode('')], id);\n}\n\n// --- Snapshot Ownership -------------------------------------------------\n\n// `Object.isFrozen` is shallow and therefore cannot prove our deep-immutability\n// invariant for external values. These private brands are added only after a\n// complete traversal, allowing persistent state to skip verified shared\n// subtrees without trusting caller-applied shallow freezes.\nconst VERIFIED_DOCUMENTS = new WeakSet<Document>();\nconst VERIFIED_BLOCKS = new WeakSet<BlockNode>();\nconst VERIFIED_BLOCK_ATTRS = new WeakSet<BlockAttrs>();\nconst VERIFIED_MARKS = new WeakSet<Mark>();\nconst VERIFIED_MARK_LISTS = new WeakSet<readonly Mark[]>();\nconst VERIFIED_INLINE_NODES = new WeakSet<InlineNode>();\nconst VERIFIED_TEXT_NODES = new WeakSet<TextNode>();\nconst VERIFIED_SEGMENT_LISTS = new WeakSet<readonly ContentSegment[]>();\n\n/**\n * Creates a fully detached document snapshot.\n *\n * Public JSON boundaries use this instead of exposing the structurally shared\n * objects owned by an {@link EditorState}. Besides child arrays, attribute\n * records, structured block attributes, marks, and mark attributes are copied.\n */\nexport function cloneDocument(doc: Document): Document {\n\treturn { ...doc, children: doc.children.map(cloneBlockNode) };\n}\n\n/** Creates a fully detached block snapshot, preserving its stable block ID. */\nexport function cloneBlockNode(block: BlockNode): BlockNode {\n\tconst attrs: BlockAttrs | undefined = block.attrs ? cloneBlockAttrs(block.attrs) : undefined;\n\treturn {\n\t\t...block,\n\t\t...(attrs ? { attrs } : {}),\n\t\tchildren: block.children.map(cloneChildNode),\n\t};\n}\n\n/** Creates a detached mark set, including each mark's attribute record. */\nexport function cloneMarks(marks: readonly Mark[]): Mark[] {\n\treturn marks.map(cloneMark);\n}\n\n/** Creates a detached mark, including its attribute record. */\nexport function cloneMark(mark: Mark): Mark {\n\treturn {\n\t\t...mark,\n\t\t...(mark.attrs ? { attrs: { ...mark.attrs } } : {}),\n\t};\n}\n\n/** Creates a detached inline node, including attrs, marks, and mark attrs. */\nexport function cloneInlineNode(node: InlineNode): InlineNode {\n\treturn {\n\t\t...node,\n\t\tattrs: { ...node.attrs },\n\t\tmarks: cloneMarks(node.marks),\n\t};\n}\n\n/** Creates a detached content-segment payload for transaction/history ownership. */\nexport function cloneContentSegment(segment: ContentSegment): ContentSegment {\n\treturn segment.kind === 'text'\n\t\t? { ...segment, marks: cloneMarks(segment.marks) }\n\t\t: { ...segment, node: cloneInlineNode(segment.node) };\n}\n\n/** Creates a detached list of content-segment payloads. */\nexport function cloneContentSegments(segments: readonly ContentSegment[]): ContentSegment[] {\n\treturn segments.map(cloneContentSegment);\n}\n\n/**\n * Freezes a document and every mutable collection reachable from it.\n *\n * Already-frozen nodes are skipped. This keeps transaction application\n * proportional to the changed branch because unchanged subtrees are\n * structurally shared between states.\n */\nexport function freezeDocument(doc: Document): Document {\n\tif (VERIFIED_DOCUMENTS.has(doc)) return doc;\n\tfor (const block of doc.children) freezeBlockNode(block);\n\tif (!Object.isFrozen(doc.children)) Object.freeze(doc.children);\n\tif (!Object.isFrozen(doc)) Object.freeze(doc);\n\tVERIFIED_DOCUMENTS.add(doc);\n\treturn doc;\n}\n\nfunction cloneChildNode(child: ChildNode): ChildNode {\n\tif (isTextNode(child)) {\n\t\tconst marks: readonly Mark[] | undefined = Array.isArray(child.marks)\n\t\t\t? cloneMarks(child.marks)\n\t\t\t: undefined;\n\t\treturn {\n\t\t\t...child,\n\t\t\t...(marks ? { marks } : {}),\n\t\t};\n\t}\n\tif (isInlineNode(child)) {\n\t\treturn cloneInlineNode(child);\n\t}\n\treturn cloneBlockNode(child);\n}\n\n/** Creates a detached block-attribute record, including structured array values. */\nexport function cloneBlockAttrs(attrs: BlockAttrs): BlockAttrs {\n\tconst copy: Record<string, BlockAttrValue> = {};\n\tfor (const [key, value] of Object.entries(attrs)) {\n\t\tcopy[key] = Array.isArray(value) ? [...value] : value;\n\t}\n\treturn copy;\n}\n\n/** Deep-freezes one detached block snapshot in place. */\nexport function freezeBlockNode(block: BlockNode): void {\n\tif (VERIFIED_BLOCKS.has(block)) return;\n\tif (block.attrs) freezeBlockAttrs(block.attrs);\n\tfor (const child of block.children) {\n\t\tif (isTextNode(child) || isInlineNode(child)) {\n\t\t\tfreezeInlineChild(child);\n\t\t} else {\n\t\t\tfreezeBlockNode(child);\n\t\t}\n\t}\n\tif (!Object.isFrozen(block.children)) Object.freeze(block.children);\n\tif (!Object.isFrozen(block)) Object.freeze(block);\n\tVERIFIED_BLOCKS.add(block);\n}\n\n/** Deep-freezes a block-attribute record in place. */\nexport function freezeBlockAttrs(attrs: BlockAttrs): void {\n\tif (VERIFIED_BLOCK_ATTRS.has(attrs)) return;\n\tfor (const value of Object.values(attrs)) {\n\t\tif (Array.isArray(value) && !Object.isFrozen(value)) Object.freeze(value);\n\t}\n\tif (!Object.isFrozen(attrs)) Object.freeze(attrs);\n\tVERIFIED_BLOCK_ATTRS.add(attrs);\n}\n\n/** Deep-freezes a mark and its attrs in place. */\nexport function freezeMark(mark: Mark): void {\n\tif (VERIFIED_MARKS.has(mark)) return;\n\tif (mark.attrs && !Object.isFrozen(mark.attrs)) Object.freeze(mark.attrs);\n\tif (!Object.isFrozen(mark)) Object.freeze(mark);\n\tVERIFIED_MARKS.add(mark);\n}\n\n/** Deep-freezes a mark list in place. */\nexport function freezeMarks(marks: readonly Mark[]): void {\n\tif (VERIFIED_MARK_LISTS.has(marks)) return;\n\tfor (const mark of marks) freezeMark(mark);\n\tif (!Object.isFrozen(marks)) Object.freeze(marks);\n\tVERIFIED_MARK_LISTS.add(marks);\n}\n\n/** Deep-freezes an inline node and all of its payload records in place. */\nexport function freezeInlineNode(node: InlineNode): void {\n\tif (VERIFIED_INLINE_NODES.has(node)) return;\n\tif (!Object.isFrozen(node.attrs)) Object.freeze(node.attrs);\n\tfreezeMarks(node.marks);\n\tif (!Object.isFrozen(node)) Object.freeze(node);\n\tVERIFIED_INLINE_NODES.add(node);\n}\n\n/** Deep-freezes transaction/history content-segment payloads in place. */\nexport function freezeContentSegments(segments: readonly ContentSegment[]): void {\n\tif (VERIFIED_SEGMENT_LISTS.has(segments)) return;\n\tfor (const segment of segments) {\n\t\tif (segment.kind === 'text') freezeMarks(segment.marks);\n\t\telse freezeInlineNode(segment.node);\n\t\tif (!Object.isFrozen(segment)) Object.freeze(segment);\n\t}\n\tif (!Object.isFrozen(segments)) Object.freeze(segments);\n\tVERIFIED_SEGMENT_LISTS.add(segments);\n}\n\nfunction freezeInlineChild(child: TextNode | InlineNode): void {\n\tif (isInlineNode(child)) {\n\t\tfreezeInlineNode(child);\n\t\treturn;\n\t}\n\tif (VERIFIED_TEXT_NODES.has(child)) return;\n\tfreezeMarks(child.marks);\n\tif (!Object.isFrozen(child)) Object.freeze(child);\n\tVERIFIED_TEXT_NODES.add(child);\n}\n\n// --- Utility Functions ---\n\n/** Extracts plain text from a block (InlineNodes are skipped). */\nexport function getBlockText(block: BlockNode): string {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\tlet text = '';\n\tfor (const child of inlineChildren) {\n\t\tif (isTextNode(child)) {\n\t\t\ttext += child.text;\n\t\t}\n\t}\n\treturn text;\n}\n\n/** Returns the length of a block's inline content (InlineNodes count as 1). */\nexport function getBlockLength(block: BlockNode): number {\n\tlet len = 0;\n\tfor (const { to } of walkInlineContent(getInlineChildren(block))) {\n\t\tlen = to;\n\t}\n\treturn len;\n}\n\n/** Returns the marks active at the given offset (empty for InlineNode offsets). */\nexport function getBlockMarksAtOffset(block: BlockNode, offset: number): readonly Mark[] {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\n\tfor (const { child, from, to } of walkInlineContent(inlineChildren)) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (offset === from) return [];\n\t\t\tcontinue;\n\t\t}\n\t\tif (offset >= from && offset < to) {\n\t\t\treturn child.marks;\n\t\t}\n\t\t// Empty text node (from === to): match exactly at its position.\n\t\tif (offset === from && child.text.length === 0) {\n\t\t\treturn child.marks;\n\t\t}\n\t}\n\n\t// Fall back to last text child's marks\n\tfor (let i: number = inlineChildren.length - 1; i >= 0; i--) {\n\t\tconst child: TextNode | InlineNode | undefined = inlineChildren[i];\n\t\tif (child && isTextNode(child)) {\n\t\t\treturn child.marks;\n\t\t}\n\t}\n\treturn [];\n}\n\n/** Returns the marks of the text content immediately to the right of `offset`. */\nfunction getMarksAfterOffset(block: BlockNode, offset: number): readonly Mark[] {\n\tfor (const { child, from, to } of walkInlineContent(getInlineChildren(block))) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (offset === from) return [];\n\t\t\tcontinue;\n\t\t}\n\t\tif (offset >= from && offset < to) return child.marks;\n\t}\n\treturn [];\n}\n\n/**\n * Returns the marks that text typed at a collapsed cursor should carry.\n *\n * Marks are derived from the content around `offset` (via\n * {@link getBlockMarksAtOffset}). A mark whose spec is non-inclusive\n * (`isMarkInclusive` returns `false`) is only kept when it also covers the\n * content to the right of the cursor, so it never bleeds past its right\n * boundary onto newly typed text. Inclusive marks (the default) are unaffected.\n */\nexport function getCursorMarks(\n\tblock: BlockNode,\n\toffset: number,\n\tisMarkInclusive: (type: MarkTypeName) => boolean,\n): readonly Mark[] {\n\tconst marks: readonly Mark[] = getBlockMarksAtOffset(block, offset);\n\tif (marks.length === 0) return marks;\n\n\tconst after: readonly Mark[] = getMarksAfterOffset(block, offset);\n\treturn marks.filter(\n\t\t(mark) => isMarkInclusive(mark.type) || after.some((a) => marksEqual(a, mark)),\n\t);\n}\n\n/** Checks whether two marks are equal by type and attrs. */\nexport function marksEqual(a: Mark, b: Mark): boolean {\n\tif (a.type !== b.type) return false;\n\tconst aAttrs = a.attrs;\n\tconst bAttrs = b.attrs;\n\tif (!aAttrs && !bAttrs) return true;\n\tif (!aAttrs || !bAttrs) return false;\n\tconst aKeys = Object.keys(aAttrs);\n\tconst bKeys = Object.keys(bAttrs);\n\tif (aKeys.length !== bKeys.length) return false;\n\treturn aKeys.every((key) => aAttrs[key] === bAttrs[key]);\n}\n\n/** Deep equality for immutable, JSON-compatible block attribute values. */\nexport function blockAttrValuesEqual(\n\ta: BlockAttrValue | undefined,\n\tb: BlockAttrValue | undefined,\n): boolean {\n\tif (a === b) return true;\n\tif (a === undefined || b === undefined || a === null || b === null) return false;\n\tif (Array.isArray(a) || Array.isArray(b)) {\n\t\tif (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;\n\t\treturn a.every((value, index) => value === b[index]);\n\t}\n\treturn false;\n}\n\n/** Deep equality for block attribute records. */\nexport function blockAttrsEqual(a: BlockAttrs | undefined, b: BlockAttrs | undefined): boolean {\n\tif (a === b) return true;\n\tif (!a || !b) return false;\n\tconst aKeys: readonly string[] = Object.keys(a);\n\tconst bKeys: readonly string[] = Object.keys(b);\n\tif (aKeys.length !== bKeys.length) return false;\n\treturn aKeys.every((key) => blockAttrValuesEqual(a[key], b[key]));\n}\n\n/** Checks whether two mark arrays contain the same marks (order-independent). */\nexport function markSetsEqual(a: readonly Mark[], b: readonly Mark[]): boolean {\n\tif (a.length !== b.length) return false;\n\treturn a.every((markA) => b.some((markB) => marksEqual(markA, markB)));\n}\n\n/** Returns true if the mark set contains a mark of the given type. */\nexport function hasMark(marks: readonly Mark[], markType: MarkTypeName): boolean {\n\treturn marks.some((m) => m.type === markType);\n}\n\n/** Adds a mark to a mark set (no duplicates). */\nexport function addMarkToSet(marks: readonly Mark[], mark: Mark): readonly Mark[] {\n\tif (hasMark(marks, mark.type)) return marks;\n\treturn [...marks, mark];\n}\n\n/** Removes a mark type from a mark set. */\nexport function removeMarkFromSet(marks: readonly Mark[], markType: MarkTypeName): readonly Mark[] {\n\treturn marks.filter((m) => m.type !== markType);\n}\n\n/**\n * Normalizes text nodes within a block: merges adjacent nodes with identical marks,\n * removes empty text nodes (keeping at least one).\n */\nexport function normalizeTextNodes(nodes: readonly TextNode[]): readonly TextNode[] {\n\tif (nodes.length === 0) return [createTextNode('')];\n\n\tconst result: TextNode[] = [];\n\tfor (const node of nodes) {\n\t\tconst prev: TextNode | undefined = result[result.length - 1];\n\t\tif (prev && markSetsEqual(prev.marks, node.marks)) {\n\t\t\tresult[result.length - 1] = createTextNode(prev.text + node.text, prev.marks);\n\t\t} else if (node.text.length > 0 || result.length === 0) {\n\t\t\tresult.push(node);\n\t\t}\n\t}\n\n\treturn result.length === 0 ? [createTextNode('')] : result;\n}\n\n/**\n * Normalizes mixed inline content: merges adjacent TextNodes with same marks,\n * removes empty TextNodes adjacent to InlineNodes, preserves InlineNodes as-is.\n * Guarantees at least one TextNode exists if all text is empty.\n */\nexport function normalizeInlineContent(\n\tnodes: readonly (TextNode | InlineNode)[],\n): readonly (TextNode | InlineNode)[] {\n\tif (nodes.length === 0) return [createTextNode('')];\n\n\t// Fast path: no InlineNodes, delegate to normalizeTextNodes\n\tif (nodes.every((n): n is TextNode => isTextNode(n))) {\n\t\treturn normalizeTextNodes(nodes);\n\t}\n\n\tconst result: (TextNode | InlineNode)[] = [];\n\n\tfor (const node of nodes) {\n\t\tif (isInlineNode(node)) {\n\t\t\tresult.push(node);\n\t\t\tcontinue;\n\t\t}\n\t\t// TextNode: try to merge with previous TextNode\n\t\tconst prev: TextNode | InlineNode | undefined = result[result.length - 1];\n\t\tif (prev && isTextNode(prev) && markSetsEqual(prev.marks, node.marks)) {\n\t\t\tresult[result.length - 1] = createTextNode(prev.text + node.text, prev.marks);\n\t\t} else if (node.text.length > 0 || result.length === 0) {\n\t\t\tresult.push(node);\n\t\t}\n\t}\n\n\t// Remove empty TextNodes that are adjacent to InlineNodes\n\tconst cleaned: (TextNode | InlineNode)[] = result.filter((node, i) => {\n\t\tif (isInlineNode(node)) return true;\n\t\tif (node.text.length > 0) return true;\n\t\t// Keep if it's the only node\n\t\tif (result.length === 1) return true;\n\t\t// Remove empty TextNode if adjacent to InlineNode\n\t\tconst prev: TextNode | InlineNode | undefined = result[i - 1];\n\t\tconst next: TextNode | InlineNode | undefined = result[i + 1];\n\t\tif ((prev && isInlineNode(prev)) || (next && isInlineNode(next))) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\n\t// Ensure at least one TextNode exists\n\tif (cleaned.length === 0) return [createTextNode('')];\n\tif (!cleaned.some((n) => isTextNode(n))) {\n\t\treturn [createTextNode(''), ...cleaned];\n\t}\n\n\treturn cleaned;\n}\n\n/** Materializes a single {@link ContentSegment} into its inline child node. */\nexport function contentSegmentToInlineNode(segment: ContentSegment): TextNode | InlineNode {\n\treturn segment.kind === 'inline' ? segment.node : createTextNode(segment.text, segment.marks);\n}\n\n/**\n * Materializes content segments (text + inline) into normalized inline children.\n * Inverse of {@link getBlockContentSegmentsInRange}: used when turning a range of\n * segments back into a block's children (paste insertion, slice extraction).\n */\nexport function segmentsToInlineChildren(\n\tsegments: readonly ContentSegment[],\n): readonly (TextNode | InlineNode)[] {\n\treturn normalizeInlineContent(segments.map(contentSegmentToInlineNode));\n}\n\n/** Yields each inline child with its offset range. InlineNodes have width 1. */\nexport function* walkInlineContent(children: readonly (TextNode | InlineNode)[]): Generator<{\n\treadonly child: TextNode | InlineNode;\n\treadonly from: number;\n\treadonly to: number;\n}> {\n\tlet pos = 0;\n\tfor (const child of children) {\n\t\tconst width: number = isInlineNode(child) ? 1 : child.text.length;\n\t\tyield { child, from: pos, to: pos + width };\n\t\tpos += width;\n\t}\n}\n\n/**\n * Converts a block-space offset to a text-space offset.\n *\n * Block-space counts InlineNodes as width 1, but `getBlockText()` skips them.\n * This function maps a block offset to the equivalent position in the\n * text-only string returned by `getBlockText()`.\n */\nexport function blockOffsetToTextOffset(block: BlockNode, blockOffset: number): number {\n\tlet textPos = 0;\n\n\tfor (const { child, from, to } of walkInlineContent(getInlineChildren(block))) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (from >= blockOffset) return textPos;\n\t\t} else {\n\t\t\tif (to >= blockOffset) return textPos + (blockOffset - from);\n\t\t\ttextPos += child.text.length;\n\t\t}\n\t}\n\n\treturn textPos;\n}\n\n/** Returns the content at a specific offset: text char, inline node, or null. */\nexport function getContentAtOffset(\n\tblock: BlockNode,\n\toffset: number,\n):\n\t| { readonly kind: 'text'; readonly char: string; readonly marks: readonly Mark[] }\n\t| { readonly kind: 'inline'; readonly node: InlineNode }\n\t| null {\n\tconst inlineChildren: readonly (TextNode | InlineNode)[] = getInlineChildren(block);\n\n\tfor (const { child, from } of walkInlineContent(inlineChildren)) {\n\t\tif (isInlineNode(child)) {\n\t\t\tif (offset === from) return { kind: 'inline', node: child };\n\t\t\tcontinue;\n\t\t}\n\t\tconst localOffset: number = offset - from;\n\t\tif (localOffset >= 0 && localOffset < child.text.length) {\n\t\t\treturn {\n\t\t\t\tkind: 'text',\n\t\t\t\tchar: child.text[localOffset] ?? '',\n\t\t\t\tmarks: child.marks,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn null;\n}\n"],"mappings":"6CAiGA,SAAgB,EAAY,EAAc,EAAyB,IAClE,MAAO,CAAE,KAAM,OAAQ,OAAM,QAC9B,CAGA,SAAgB,EAAc,GAC7B,MAAO,CAAE,KAAM,SAAU,OAC1B,CAGA,SAAgB,EACf,EACA,EACA,GAEA,MAAM,EAA6B,GASnC,OARA,EAA0B,EAAO,EAAM,EAAI,CAC1C,MAAA,CAAO,EAAc,GACpB,EAAS,KAAK,CAAE,KAAM,OAAQ,OAAM,SACrC,EACA,QAAA,CAAS,GACR,EAAS,KAAK,CAAE,KAAM,SAAU,QACjC,IAEM,CACR,CAgBA,SAAgB,EACf,EACA,EACA,EACA,GAEA,IAAK,MAAM,MAAE,EAAO,KAAM,EAAW,GAAI,KAAc,GACtD,EAAkB,IAElB,KAAI,GAAY,GAAQ,GAAa,GAErC,GAAI,EAAa,GAChB,EAAQ,WAAW,OACb,CACN,MAAM,EAAoB,KAAK,IAAI,EAAG,EAAO,GACvC,EAAkB,KAAK,IAAI,EAAM,KAAK,OAAQ,EAAK,G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