@bigbinary/neeto-editor-frontend 2.0.10 → 2.1.0-beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/.ready +1 -1
  2. package/dist/Editor.js +7 -6
  3. package/dist/Editor.js.map +1 -1
  4. package/dist/EditorContent.js +4 -3
  5. package/dist/EditorContent.js.map +1 -1
  6. package/dist/FormikEditor.js +7 -6
  7. package/dist/FormikEditor.js.map +1 -1
  8. package/dist/Menu.js +5 -4
  9. package/dist/Menu.js.map +1 -1
  10. package/dist/{chunk-DxmX0drN.js → chunk-7ioLE0kx.js} +2 -2
  11. package/dist/{chunk-DxmX0drN.js.map → chunk-7ioLE0kx.js.map} +1 -1
  12. package/dist/{chunk-MLCxAQf7.js → chunk-BNyLNMnb.js} +3 -3
  13. package/dist/{chunk-MLCxAQf7.js.map → chunk-BNyLNMnb.js.map} +1 -1
  14. package/dist/{cjs/chunk-Crp27WMe.cjs.js → chunk-BpMZjml2.js} +147 -3234
  15. package/dist/chunk-BpMZjml2.js.map +1 -0
  16. package/dist/{chunk-C_P2M3zF.js → chunk-Br5h7rjn.js} +7 -3
  17. package/dist/chunk-Br5h7rjn.js.map +1 -0
  18. package/dist/{chunk-Di3ipdfT.js → chunk-CRUXOawK.js} +3 -2
  19. package/dist/{chunk-Di3ipdfT.js.map → chunk-CRUXOawK.js.map} +1 -1
  20. package/dist/chunk-DN9pYQV5.js +3210 -0
  21. package/dist/chunk-DN9pYQV5.js.map +1 -0
  22. package/dist/{chunk-DbtYYDYF.js → chunk-DYRpf9PJ.js} +3 -3
  23. package/dist/{chunk-DbtYYDYF.js.map → chunk-DYRpf9PJ.js.map} +1 -1
  24. package/dist/{chunk-CTLN7kYv.js → chunk-DfH1lF5p.js} +3 -17
  25. package/dist/chunk-DfH1lF5p.js.map +1 -0
  26. package/dist/{chunk-Byc0nnPW.js → chunk-YhV82e9I.js} +8 -4
  27. package/dist/chunk-YhV82e9I.js.map +1 -0
  28. package/dist/{chunk-BAjN56q8.js → chunk-lEnpEBRB.js} +5 -4
  29. package/dist/{chunk-BAjN56q8.js.map → chunk-lEnpEBRB.js.map} +1 -1
  30. package/dist/{chunk-CrQm8ki8.js → chunk-sn8HEeT6.js} +4 -3
  31. package/dist/{chunk-CrQm8ki8.js.map → chunk-sn8HEeT6.js.map} +1 -1
  32. package/dist/cjs/Editor.cjs.js +8 -7
  33. package/dist/cjs/Editor.cjs.js.map +1 -1
  34. package/dist/cjs/EditorContent.cjs.js +4 -3
  35. package/dist/cjs/EditorContent.cjs.js.map +1 -1
  36. package/dist/cjs/FormikEditor.cjs.js +7 -6
  37. package/dist/cjs/FormikEditor.cjs.js.map +1 -1
  38. package/dist/cjs/Menu.cjs.js +5 -4
  39. package/dist/cjs/Menu.cjs.js.map +1 -1
  40. package/dist/cjs/{chunk-CwtiYxqr.cjs.js → chunk-78VpxO0R.cjs.js} +4 -3
  41. package/dist/cjs/{chunk-CwtiYxqr.cjs.js.map → chunk-78VpxO0R.cjs.js.map} +1 -1
  42. package/dist/{chunk-DgZGzqPs.js → cjs/chunk-BPJBeVDI.cjs.js} +166 -3206
  43. package/dist/cjs/chunk-BPJBeVDI.cjs.js.map +1 -0
  44. package/dist/cjs/{chunk-Ty2BpOZ5.cjs.js → chunk-CBswWnmM.cjs.js} +10 -6
  45. package/dist/cjs/chunk-CBswWnmM.cjs.js.map +1 -0
  46. package/dist/cjs/{chunk-Bsk_FDUA.cjs.js → chunk-CQLQEN5P.cjs.js} +5 -22
  47. package/dist/cjs/chunk-CQLQEN5P.cjs.js.map +1 -0
  48. package/dist/cjs/{chunk-CohcWDmm.cjs.js → chunk-CwY6UgZq.cjs.js} +78 -77
  49. package/dist/cjs/{chunk-CohcWDmm.cjs.js.map → chunk-CwY6UgZq.cjs.js.map} +1 -1
  50. package/dist/cjs/chunk-DRnP2LQe.cjs.js +3231 -0
  51. package/dist/cjs/chunk-DRnP2LQe.cjs.js.map +1 -0
  52. package/dist/cjs/{chunk-D9InNR1-.cjs.js → chunk-QnVNXaqt.cjs.js} +11 -7
  53. package/dist/cjs/chunk-QnVNXaqt.cjs.js.map +1 -0
  54. package/dist/cjs/{chunk-D53HfRZd.cjs.js → chunk-V1V-Gqfy.cjs.js} +3 -3
  55. package/dist/cjs/{chunk-D53HfRZd.cjs.js.map → chunk-V1V-Gqfy.cjs.js.map} +1 -1
  56. package/dist/cjs/{chunk-CkdAygKd.cjs.js → chunk-bfmPXyQJ.cjs.js} +3 -3
  57. package/dist/cjs/{chunk-CkdAygKd.cjs.js.map → chunk-bfmPXyQJ.cjs.js.map} +1 -1
  58. package/dist/cjs/{chunk-BwE6pvh2.cjs.js → chunk-bxP1kilM.cjs.js} +2 -2
  59. package/dist/cjs/{chunk-BwE6pvh2.cjs.js.map → chunk-bxP1kilM.cjs.js.map} +1 -1
  60. package/dist/cjs/{chunk-BAEoAF1o.cjs.js → chunk-j4T5BDua.cjs.js} +23 -22
  61. package/dist/cjs/{chunk-BAEoAF1o.cjs.js.map → chunk-j4T5BDua.cjs.js.map} +1 -1
  62. package/dist/cjs/index.cjs.js +9 -8
  63. package/dist/cjs/index.cjs.js.map +1 -1
  64. package/dist/cjs/utils.cjs.js +7 -6
  65. package/dist/cjs/utils.cjs.js.map +1 -1
  66. package/dist/cjs/v2/Editor.cjs.js +7 -6
  67. package/dist/cjs/v2/Editor.cjs.js.map +1 -1
  68. package/dist/cjs/v2/EditorContent.cjs.js +4 -3
  69. package/dist/cjs/v2/EditorContent.cjs.js.map +1 -1
  70. package/dist/cjs/v2/FormikEditor.cjs.js +6 -5
  71. package/dist/cjs/v2/FormikEditor.cjs.js.map +1 -1
  72. package/dist/cjs/v2/Menu.cjs.js +4 -3
  73. package/dist/cjs/v2/Menu.cjs.js.map +1 -1
  74. package/dist/cjs/v2/index.cjs.js +8 -7
  75. package/dist/cjs/v2/index.cjs.js.map +1 -1
  76. package/dist/cjs/v2/utils.cjs.js +7 -6
  77. package/dist/cjs/v2/utils.cjs.js.map +1 -1
  78. package/dist/editor-stats.html +2 -2
  79. package/dist/index.js +9 -8
  80. package/dist/index.js.map +1 -1
  81. package/dist/utils.js +7 -6
  82. package/dist/utils.js.map +1 -1
  83. package/dist/v2/Editor.js +6 -5
  84. package/dist/v2/Editor.js.map +1 -1
  85. package/dist/v2/EditorContent.js +4 -3
  86. package/dist/v2/EditorContent.js.map +1 -1
  87. package/dist/v2/FormikEditor.js +6 -5
  88. package/dist/v2/FormikEditor.js.map +1 -1
  89. package/dist/v2/Menu.js +4 -3
  90. package/dist/v2/Menu.js.map +1 -1
  91. package/dist/v2/index.js +8 -7
  92. package/dist/v2/index.js.map +1 -1
  93. package/dist/v2/utils.js +7 -6
  94. package/dist/v2/utils.js.map +1 -1
  95. package/package.json +7 -5
  96. package/dist/chunk-Byc0nnPW.js.map +0 -1
  97. package/dist/chunk-CTLN7kYv.js.map +0 -1
  98. package/dist/chunk-C_P2M3zF.js.map +0 -1
  99. package/dist/chunk-DgZGzqPs.js.map +0 -1
  100. package/dist/cjs/chunk-Bsk_FDUA.cjs.js.map +0 -1
  101. package/dist/cjs/chunk-Crp27WMe.cjs.js.map +0 -1
  102. package/dist/cjs/chunk-D9InNR1-.cjs.js.map +0 -1
  103. package/dist/cjs/chunk-Ty2BpOZ5.cjs.js.map +0 -1
@@ -1,3 +1,7 @@
1
+ 'use strict';
2
+
3
+ var ramda = require('ramda');
4
+
1
5
  // ::- Persistent data structure representing an ordered mapping from
2
6
  // strings to values, with some convenient update methods.
3
7
  function OrderedMap(content) {
@@ -846,7 +850,7 @@ function checkJoin(main, sub) {
846
850
  if (!sub.type.compatibleContent(main.type))
847
851
  throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name);
848
852
  }
849
- function joinable$1($before, $after, depth) {
853
+ function joinable($before, $after, depth) {
850
854
  let node = $before.node(depth);
851
855
  checkJoin(node, $after.node(depth));
852
856
  return node;
@@ -882,8 +886,8 @@ function close(node, content) {
882
886
  return node.copy(content);
883
887
  }
884
888
  function replaceThreeWay($from, $start, $end, $to, depth) {
885
- let openStart = $from.depth > depth && joinable$1($from, $start, depth + 1);
886
- let openEnd = $to.depth > depth && joinable$1($end, $to, depth + 1);
889
+ let openStart = $from.depth > depth && joinable($from, $start, depth + 1);
890
+ let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);
887
891
  let content = [];
888
892
  addRange(null, $from, depth, content);
889
893
  if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {
@@ -904,7 +908,7 @@ function replaceTwoWay($from, $to, depth) {
904
908
  let content = [];
905
909
  addRange(null, $from, depth, content);
906
910
  if ($from.depth > depth) {
907
- let type = joinable$1($from, $to, depth + 1);
911
+ let type = joinable($from, $to, depth + 1);
908
912
  addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content);
909
913
  }
910
914
  addRange($to, null, depth, content);
@@ -2655,7 +2659,7 @@ A DOM parser represents a strategy for parsing DOM content into a
2655
2659
  ProseMirror document conforming to a given schema. Its behavior is
2656
2660
  defined by an array of [rules](https://prosemirror.net/docs/ref/#model.ParseRule).
2657
2661
  */
2658
- class DOMParser {
2662
+ let DOMParser$1 = class DOMParser {
2659
2663
  /**
2660
2664
  Create a parser that targets the given schema, using the given
2661
2665
  parsing rules.
@@ -2806,7 +2810,7 @@ class DOMParser {
2806
2810
  return schema.cached.domParser ||
2807
2811
  (schema.cached.domParser = new DOMParser(schema, DOMParser.schemaRules(schema)));
2808
2812
  }
2809
- }
2813
+ };
2810
2814
  const blockTags = {
2811
2815
  address: true, article: true, aside: true, blockquote: true, body: true, canvas: true,
2812
2816
  dd: true, div: true, dl: true, fieldset: true, figcaption: true, figure: true,
@@ -3594,3211 +3598,167 @@ function renderSpec(doc, structure, xmlNS, blockArraysIn) {
3594
3598
  return { dom, contentDOM };
3595
3599
  }
3596
3600
 
3597
- // Recovery values encode a range index and an offset. They are
3598
- // represented as numbers, because tons of them will be created when
3599
- // mapping, for example, a large number of decorations. The number's
3600
- // lower 16 bits provide the index, the remaining bits the offset.
3601
- //
3602
- // Note: We intentionally don't use bit shift operators to en- and
3603
- // decode these, since those clip to 32 bits, which we might in rare
3604
- // cases want to overflow. A 64-bit float can represent 48-bit
3605
- // integers precisely.
3606
- const lower16 = 0xffff;
3607
- const factor16 = Math.pow(2, 16);
3608
- function makeRecover(index, offset) { return index + offset * factor16; }
3609
- function recoverIndex(value) { return value & lower16; }
3610
- function recoverOffset(value) { return (value - (value & lower16)) / factor16; }
3611
- const DEL_BEFORE = 1, DEL_AFTER = 2, DEL_ACROSS = 4, DEL_SIDE = 8;
3612
- /**
3613
- An object representing a mapped position with extra
3614
- information.
3615
- */
3616
- class MapResult {
3617
- /**
3618
- @internal
3619
- */
3620
- constructor(
3621
- /**
3622
- The mapped version of the position.
3623
- */
3624
- pos,
3625
- /**
3626
- @internal
3627
- */
3628
- delInfo,
3629
- /**
3630
- @internal
3631
- */
3632
- recover) {
3633
- this.pos = pos;
3634
- this.delInfo = delInfo;
3635
- this.recover = recover;
3636
- }
3637
- /**
3638
- Tells you whether the position was deleted, that is, whether the
3639
- step removed the token on the side queried (via the `assoc`)
3640
- argument from the document.
3641
- */
3642
- get deleted() { return (this.delInfo & DEL_SIDE) > 0; }
3643
- /**
3644
- Tells you whether the token before the mapped position was deleted.
3645
- */
3646
- get deletedBefore() { return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0; }
3647
- /**
3648
- True when the token after the mapped position was deleted.
3649
- */
3650
- get deletedAfter() { return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0; }
3651
- /**
3652
- Tells whether any of the steps mapped through deletes across the
3653
- position (including both the token before and after the
3654
- position).
3655
- */
3656
- get deletedAcross() { return (this.delInfo & DEL_ACROSS) > 0; }
3657
- }
3658
- /**
3659
- A map describing the deletions and insertions made by a step, which
3660
- can be used to find the correspondence between positions in the
3661
- pre-step version of a document and the same position in the
3662
- post-step version.
3663
- */
3664
- class StepMap {
3665
- /**
3666
- Create a position map. The modifications to the document are
3667
- represented as an array of numbers, in which each group of three
3668
- represents a modified chunk as `[start, oldSize, newSize]`.
3669
- */
3670
- constructor(
3671
- /**
3672
- @internal
3673
- */
3674
- ranges,
3675
- /**
3676
- @internal
3677
- */
3678
- inverted = false) {
3679
- this.ranges = ranges;
3680
- this.inverted = inverted;
3681
- if (!ranges.length && StepMap.empty)
3682
- return StepMap.empty;
3683
- }
3684
- /**
3685
- @internal
3686
- */
3687
- recover(value) {
3688
- let diff = 0, index = recoverIndex(value);
3689
- if (!this.inverted)
3690
- for (let i = 0; i < index; i++)
3691
- diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
3692
- return this.ranges[index * 3] + diff + recoverOffset(value);
3693
- }
3694
- mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }
3695
- map(pos, assoc = 1) { return this._map(pos, assoc, true); }
3696
- /**
3697
- @internal
3698
- */
3699
- _map(pos, assoc, simple) {
3700
- let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
3701
- for (let i = 0; i < this.ranges.length; i += 3) {
3702
- let start = this.ranges[i] - (this.inverted ? diff : 0);
3703
- if (start > pos)
3704
- break;
3705
- let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;
3706
- if (pos <= end) {
3707
- let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;
3708
- let result = start + diff + (side < 0 ? 0 : newSize);
3709
- if (simple)
3710
- return result;
3711
- let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
3712
- let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
3713
- if (assoc < 0 ? pos != start : pos != end)
3714
- del |= DEL_SIDE;
3715
- return new MapResult(result, del, recover);
3716
- }
3717
- diff += newSize - oldSize;
3718
- }
3719
- return simple ? pos + diff : new MapResult(pos + diff, 0, null);
3720
- }
3721
- /**
3722
- @internal
3723
- */
3724
- touches(pos, recover) {
3725
- let diff = 0, index = recoverIndex(recover);
3726
- let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
3727
- for (let i = 0; i < this.ranges.length; i += 3) {
3728
- let start = this.ranges[i] - (this.inverted ? diff : 0);
3729
- if (start > pos)
3730
- break;
3731
- let oldSize = this.ranges[i + oldIndex], end = start + oldSize;
3732
- if (pos <= end && i == index * 3)
3733
- return true;
3734
- diff += this.ranges[i + newIndex] - oldSize;
3735
- }
3736
- return false;
3737
- }
3738
- /**
3739
- Calls the given function on each of the changed ranges included in
3740
- this map.
3741
- */
3742
- forEach(f) {
3743
- let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
3744
- for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {
3745
- let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);
3746
- let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];
3747
- f(oldStart, oldStart + oldSize, newStart, newStart + newSize);
3748
- diff += newSize - oldSize;
3749
- }
3750
- }
3751
- /**
3752
- Create an inverted version of this map. The result can be used to
3753
- map positions in the post-step document to the pre-step document.
3754
- */
3755
- invert() {
3756
- return new StepMap(this.ranges, !this.inverted);
3757
- }
3758
- /**
3759
- @internal
3760
- */
3761
- toString() {
3762
- return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
3763
- }
3764
- /**
3765
- Create a map that moves all positions by offset `n` (which may be
3766
- negative). This can be useful when applying steps meant for a
3767
- sub-document to a larger document, or vice-versa.
3768
- */
3769
- static offset(n) {
3770
- return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
3771
- }
3772
- }
3773
- /**
3774
- A StepMap that contains no changed ranges.
3775
- */
3776
- StepMap.empty = new StepMap([]);
3777
3601
  /**
3778
- A mapping represents a pipeline of zero or more [step
3779
- maps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly
3780
- handling mapping positions through a series of steps in which some
3781
- steps are inverted versions of earlier steps. (This comes up when
3782
- ‘[rebasing](https://prosemirror.net/docs/guide/#transform.rebasing)’ steps for
3783
- collaboration or history management.)
3784
- */
3785
- class Mapping {
3786
- /**
3787
- Create a new mapping with the given position maps.
3788
- */
3789
- constructor(maps,
3790
- /**
3791
- @internal
3792
- */
3793
- mirror,
3794
- /**
3795
- The starting position in the `maps` array, used when `map` or
3796
- `mapResult` is called.
3797
- */
3798
- from = 0,
3799
- /**
3800
- The end position in the `maps` array.
3801
- */
3802
- to = maps ? maps.length : 0) {
3803
- this.mirror = mirror;
3804
- this.from = from;
3805
- this.to = to;
3806
- this._maps = maps || [];
3807
- this.ownData = !(maps || mirror);
3808
- }
3809
- /**
3810
- The step maps in this mapping.
3811
- */
3812
- get maps() { return this._maps; }
3813
- /**
3814
- Create a mapping that maps only through a part of this one.
3815
- */
3816
- slice(from = 0, to = this.maps.length) {
3817
- return new Mapping(this._maps, this.mirror, from, to);
3818
- }
3819
- /**
3820
- Add a step map to the end of this mapping. If `mirrors` is
3821
- given, it should be the index of the step map that is the mirror
3822
- image of this one.
3823
- */
3824
- appendMap(map, mirrors) {
3825
- if (!this.ownData) {
3826
- this._maps = this._maps.slice();
3827
- this.mirror = this.mirror && this.mirror.slice();
3828
- this.ownData = true;
3829
- }
3830
- this.to = this._maps.push(map);
3831
- if (mirrors != null)
3832
- this.setMirror(this._maps.length - 1, mirrors);
3833
- }
3834
- /**
3835
- Add all the step maps in a given mapping to this one (preserving
3836
- mirroring information).
3837
- */
3838
- appendMapping(mapping) {
3839
- for (let i = 0, startSize = this._maps.length; i < mapping._maps.length; i++) {
3840
- let mirr = mapping.getMirror(i);
3841
- this.appendMap(mapping._maps[i], mirr != null && mirr < i ? startSize + mirr : undefined);
3842
- }
3843
- }
3844
- /**
3845
- Finds the offset of the step map that mirrors the map at the
3846
- given offset, in this mapping (as per the second argument to
3847
- `appendMap`).
3848
- */
3849
- getMirror(n) {
3850
- if (this.mirror)
3851
- for (let i = 0; i < this.mirror.length; i++)
3852
- if (this.mirror[i] == n)
3853
- return this.mirror[i + (i % 2 ? -1 : 1)];
3854
- }
3855
- /**
3856
- @internal
3857
- */
3858
- setMirror(n, m) {
3859
- if (!this.mirror)
3860
- this.mirror = [];
3861
- this.mirror.push(n, m);
3862
- }
3863
- /**
3864
- Append the inverse of the given mapping to this one.
3865
- */
3866
- appendMappingInverted(mapping) {
3867
- for (let i = mapping.maps.length - 1, totalSize = this._maps.length + mapping._maps.length; i >= 0; i--) {
3868
- let mirr = mapping.getMirror(i);
3869
- this.appendMap(mapping._maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined);
3870
- }
3871
- }
3872
- /**
3873
- Create an inverted version of this mapping.
3874
- */
3875
- invert() {
3876
- let inverse = new Mapping;
3877
- inverse.appendMappingInverted(this);
3878
- return inverse;
3879
- }
3880
- /**
3881
- Map a position through this mapping.
3882
- */
3883
- map(pos, assoc = 1) {
3884
- if (this.mirror)
3885
- return this._map(pos, assoc, true);
3886
- for (let i = this.from; i < this.to; i++)
3887
- pos = this._maps[i].map(pos, assoc);
3888
- return pos;
3889
- }
3890
- /**
3891
- Map a position through this mapping, returning a mapping
3892
- result.
3893
- */
3894
- mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }
3895
- /**
3896
- @internal
3897
- */
3898
- _map(pos, assoc, simple) {
3899
- let delInfo = 0;
3900
- for (let i = this.from; i < this.to; i++) {
3901
- let map = this._maps[i], result = map.mapResult(pos, assoc);
3902
- if (result.recover != null) {
3903
- let corr = this.getMirror(i);
3904
- if (corr != null && corr > i && corr < this.to) {
3905
- i = corr;
3906
- pos = this._maps[corr].recover(result.recover);
3907
- continue;
3908
- }
3909
- }
3910
- delInfo |= result.delInfo;
3911
- pos = result.pos;
3912
- }
3913
- return simple ? pos : new MapResult(pos, delInfo, null);
3914
- }
3915
- }
3602
+ * marked v18.0.14 - a markdown parser
3603
+ * Copyright (c) 2018-2026, MarkedJS. (MIT License)
3604
+ * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT License)
3605
+ * https://github.com/markedjs/marked
3606
+ */
3916
3607
 
3917
- const stepsByID = Object.create(null);
3918
3608
  /**
3919
- A step object represents an atomic change. It generally applies
3920
- only to the document it was created for, since the positions
3921
- stored in it will only make sense for that document.
3609
+ * DO NOT EDIT THIS FILE
3610
+ * The code in this file is generated from files in ./src/
3611
+ */
3922
3612
 
3923
- New steps are defined by creating classes that extend `Step`,
3924
- overriding the `apply`, `invert`, `map`, `getMap` and `fromJSON`
3925
- methods, and registering your class with a unique
3926
- JSON-serialization identifier using
3927
- [`Step.jsonID`](https://prosemirror.net/docs/ref/#transform.Step^jsonID).
3928
- */
3929
- class Step {
3930
- /**
3931
- Get the step map that represents the changes made by this step,
3932
- and which can be used to transform between positions in the old
3933
- and the new document.
3934
- */
3935
- getMap() { return StepMap.empty; }
3936
- /**
3937
- Try to merge this step with another one, to be applied directly
3938
- after it. Returns the merged step when possible, null if the
3939
- steps can't be merged.
3940
- */
3941
- merge(other) { return null; }
3942
- /**
3943
- Deserialize a step from its JSON representation. Will call
3944
- through to the step class' own implementation of this method.
3945
- */
3946
- static fromJSON(schema, json) {
3947
- if (!json || !json.stepType)
3948
- throw new RangeError("Invalid input for Step.fromJSON");
3949
- let type = stepsByID[json.stepType];
3950
- if (!type)
3951
- throw new RangeError(`No step type ${json.stepType} defined`);
3952
- return type.fromJSON(schema, json);
3953
- }
3954
- /**
3955
- To be able to serialize steps to JSON, each step needs a string
3956
- ID to attach to its JSON representation. Use this method to
3957
- register an ID for your step classes. Try to pick something
3958
- that's unlikely to clash with steps from other modules.
3959
- */
3960
- static jsonID(id, stepClass) {
3961
- if (id in stepsByID)
3962
- throw new RangeError("Duplicate use of step JSON ID " + id);
3963
- stepsByID[id] = stepClass;
3964
- stepClass.prototype.jsonID = id;
3965
- return stepClass;
3966
- }
3967
- }
3968
- /**
3969
- The result of [applying](https://prosemirror.net/docs/ref/#transform.Step.apply) a step. Contains either a
3970
- new document or a failure value.
3971
- */
3972
- class StepResult {
3973
- /**
3974
- @internal
3975
- */
3976
- constructor(
3977
- /**
3978
- The transformed document, if successful.
3979
- */
3980
- doc,
3981
- /**
3982
- The failure message, if unsuccessful.
3983
- */
3984
- failed) {
3985
- this.doc = doc;
3986
- this.failed = failed;
3987
- }
3988
- /**
3989
- Create a successful step result.
3990
- */
3991
- static ok(doc) { return new StepResult(doc, null); }
3992
- /**
3993
- Create a failed step result.
3994
- */
3995
- static fail(message) { return new StepResult(null, message); }
3996
- /**
3997
- Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
3998
- arguments. Create a successful result if it succeeds, and a
3999
- failed one if it throws a `ReplaceError`.
4000
- */
4001
- static fromReplace(doc, from, to, slice) {
4002
- try {
4003
- return StepResult.ok(doc.replace(from, to, slice));
4004
- }
4005
- catch (e) {
4006
- if (e instanceof ReplaceError)
4007
- return StepResult.fail(e.message);
4008
- throw e;
4009
- }
4010
- }
4011
- }
3613
+ function I(){return {async:false,breaks:false,extensions:null,gfm:true,hooks:null,pedantic:false,renderer:null,silent:false,tokenizer:null,walkTokens:null}}var y=I();function W(l){y=l;}var A={exec:()=>null};function C(l){let e=[];return t=>{let n=Math.max(0,Math.min(3,t-1)),s=e[n];return s||(s=l(n),e[n]=s),s}}function h(l,e=""){let t=typeof l=="string"?l:l.source,n={replace:(s,r)=>{let o=typeof r=="string"?r:r.source;return o=o.replace(x.caret,"$1"),t=t.replace(s,o),n},getRegex:()=>new RegExp(t,e)};return n}var _e=((l="")=>{try{return !!new RegExp("(?<=1)(?<!1)"+l)}catch{return false}})(),x={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:l=>new RegExp(`^( {0,3}${l})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:C(l=>new RegExp(`^ {0,${l}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:C(l=>new RegExp(`^ {0,${l}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:C(l=>new RegExp(`^ {0,${l}}(?:\`\`\`|~~~)`)),headingBeginRegex:C(l=>new RegExp(`^ {0,${l}}#`)),htmlBeginRegex:C(l=>new RegExp(`^ {0,${l}}(?:</?(?:${N})(?: +|$|/?>)|<(?:script|pre|style|textarea|!--))`,"i")),blockquoteBeginRegex:C(l=>new RegExp(`^ {0,${l}}>`))},$e=/^(?:[ \t]*(?:\n|$))+/,Le=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ze=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,G=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ae=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,J=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,ce=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,he=h(ce).replace(/bull/g,J).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Ee=h(ce).replace(/bull/g,J).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),V=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,Me=/^[^\n]+/,Y=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Ie=h(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Y).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ce=h(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,J).getRegex(),N="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",ee=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Be=h("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",ee).replace("tag",N).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),de=l=>h(V).replace("hr",G).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",l).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",N).getRegex(),De=de(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),qe=de(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),ve=h(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",qe).getRegex(),te={blockquote:ve,code:Le,def:Ie,fences:ze,heading:Ae,hr:G,html:Be,lheading:he,list:Ce,newline:$e,paragraph:De,table:A,text:Me},le=h("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",G).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",N).getRegex(),Ze={...te,lheading:Ee,table:le,paragraph:h(V).replace("hr",G).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",le).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",N).getRegex()},He={...te,html:h(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ee).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:A,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:h(V).replace("hr",G).replace("heading",` *#{1,6} *[^
3614
+ ]`).replace("lheading",he).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Ge=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Ne=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ke=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,Qe=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,$=/[\p{P}\p{S}]/u,B=/[\s\p{P}\p{S}]/u,Q=/[^\s\p{P}\p{S}]/u,je=h(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,B).getRegex(),Fe=/[\p{Pi}\p{Ps}"']/u,ge=/(?!~)[\p{P}\p{S}]/u,Ue=/(?!~)[\s\p{P}\p{S}]/u,Ke=/(?:[^\s\p{P}\p{S}]|~)/u,We=h(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",_e?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),fe=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Xe=h(fe,"u").replace(/punct/g,$).getRegex(),Je=h(fe,"u").replace(/punct/g,ge).getRegex(),Ve=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,Ye=h(Ve,"u").replace(/openQuote/g,Fe).replace(/punct/g,$).getRegex(),me="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",et=h(me,"gu").replace(/notPunctSpace/g,Q).replace(/punctSpace/g,B).replace(/punct/g,$).getRegex(),tt=h(me,"gu").replace(/notPunctSpace/g,Ke).replace(/punctSpace/g,Ue).replace(/punct/g,ge).getRegex(),nt="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",rt=h(nt,"gu").replace(/notPunctSpace/g,Q).replace(/punctSpace/g,B).replace(/punct/g,$).getRegex(),st=h("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Q).replace(/punctSpace/g,B).replace(/punct/g,$).getRegex(),it="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",ot=h(it,"gu").replace(/notPunctSpace/g,Q).replace(/punctSpace/g,B).replace(/punct/g,$).getRegex(),at=h(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,$).getRegex(),lt="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",ut=h(lt,"gu").replace(/notPunctSpace/g,Q).replace(/punctSpace/g,B).replace(/punct/g,$).getRegex(),pt=h(/\\(punct)/,"gu").replace(/punct/g,$).getRegex(),ct=h(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),ht=h(ee).replace("(?:-->|$)","-->").getRegex(),dt=h("^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",ht).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),xe=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,U=h(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets",xe).getRegex(),kt=h(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",U).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),gt=h(/^!?\[(label)\]\[(ref)\]/).replace("label",U).replace("ref",Y).getRegex(),ft=h(/^!?\[(ref)\](?:\[\])?/).replace("ref",Y).getRegex(),ue=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,mt=h(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets",xe).getRegex(),xt=h("reflink|nolink(?!\\()","g").replace("reflink",h(/^!?\[(label)\]\[(ref)\]/).replace("label",mt).replace("ref",ue).getRegex()).replace("nolink",h(/^!?\[(ref)\](?:\[\])?/).replace("ref",ue).getRegex()).getRegex(),pe=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,bt=/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/,Rt=h(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,bt).getRegex(),ne={_backpedal:A,anyPunctuation:pt,autolink:ct,blockSkip:We,br:ke,code:Ne,del:A,delLDelim:A,delRDelim:A,emStrongLDelim:Xe,emStrongRDelimAst:et,emStrongRDelimUnd:st,escape:Ge,link:kt,nolink:ft,punctuation:je,reflink:gt,reflinkSearch:xt,tag:dt,text:Qe,url:A},Tt={...ne,emStrongLDelim:Ye,emStrongRDelimAst:rt,emStrongRDelimUnd:ot,link:h(/^!?\[(label)\]\((.*?)\)/).replace("label",U).getRegex(),reflink:h(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",U).getRegex()},X={...ne,emStrongRDelimAst:tt,emStrongLDelim:Je,delLDelim:at,delRDelim:ut,url:h(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol",Rt).replace("protocol",pe).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:h(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace("protocol",pe).replace(/emailProtocol/g,/(?:mailto|xmpp):/).getRegex()},Ot={...X,br:h(ke).replace("{2,}","*").getRegex(),text:h(X.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},j={normal:te,gfm:Ze,pedantic:He},D={normal:ne,gfm:X,breaks:Ot,pedantic:Tt};var wt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},be=l=>wt[l];function O(l,e){if(e){if(x.escapeTest.test(l))return l.replace(x.escapeReplace,be)}else if(x.escapeTestNoEncode.test(l))return l.replace(x.escapeReplaceNoEncode,be);return l}function Re(l){return l.replace(x.numericCharacterReference,(e,t,n)=>{let s=t===void 0?Number.parseInt(n,16):Number.parseInt(t,10);return s===0||s>1114111||s>=55296&&s<=57343?"\uFFFD":String.fromCodePoint(s)})}function re(l){try{l=encodeURI(l).replace(x.percentDecode,"%");}catch{return null}return l}function se(l,e){let t=l.replace(x.findPipe,(r,o,i)=>{let u=false,a=o;for(;--a>=0&&i[a]==="\\";)u=!u;return u?"|":" |"}),n=t.split(x.splitPipe),s=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),e)if(n.length>e)n.splice(e);else for(;n.length<e;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(x.slashPipe,"|");return n}function L(l,e,t){let n=l.length;if(n===0)return "";let s=0;for(;s<n;){let r=l.charAt(n-s-1);if(r===e&&true)s++;else break}return l.slice(0,n-s)}function ie(l){let e=l.split(`
3615
+ `),t=e.length-1;for(;t>=0&&x.blankLine.test(e[t]);)t--;return e.length-t<=2?l:e.slice(0,t+1).join(`
3616
+ `)}function q(l){return l.trim().toLowerCase().toUpperCase().toLowerCase()}function Te(l,e){if(l.indexOf(e[1])===-1)return -1;let t=0;for(let n=0;n<l.length;n++)if(l[n]==="\\")n++;else if(l[n]===e[0])t++;else if(l[n]===e[1]&&(t--,t<0))return n;return t>0?-2:-1}function oe(l,e=0){let t=e,n="";for(let s of l)if(s===" "){let r=4-t%4;n+=" ".repeat(r),t+=r;}else n+=s,t++;return n}function Oe(l,e,t,n,s){let r=e.href,o=e.title||null,i=l[1].replace(s.other.outputLinkReplace,"$1"),u=l[0].charAt(0)==="!";n.state.inLink=true;let a=n.state.linkEmitted,p=n.state.inRawBlock;n.state.linkEmitted=false;let c=n.inlineTokens(i),d=n.state.linkEmitted;if(n.state.linkEmitted=a,n.state.inLink=false,!u){if(d){n.state.inRawBlock=p;return}n.state.linkEmitted=true;}return {type:u?"image":"link",raw:t,href:r,title:o,text:i,tokens:c}}function yt(l,e,t){let n=l.match(t.other.indentCodeCompensation);if(n===null)return e;let s=n[1];return e.split(`
3617
+ `).map(r=>{let o=r.match(t.other.beginningSpace);if(o===null)return r;let[i]=o;return r.slice(Math.min(i.length,s.length))}).join(`
3618
+ `)}function we(l,e,t,n){if(!e.includes("<"))return false;for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="`"){let i=n.inline.code.exec(e.slice(s));if(i){s+=i[0].length-1;continue}}if(e[s]!=="<")continue;let r=l.slice(t+s),o=n.inline.tag.exec(r)||n.inline.autolink.exec(r);if(o){if(o[0].length>e.length-s)return true;s+=o[0].length-1;}}return false}var P=class{options;rules;lexer;constructor(e){this.options=e||y;}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return {type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=this.options.pedantic?t[0]:ie(t[0]),s=n.replace(this.rules.other.codeRemoveIndent,"");return {type:"code",raw:n,codeBlockStyle:"indented",text:s}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],s=yt(n,t[3]||"",this.rules);return {type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:s}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let s=L(n,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceTabChar.test(s))&&(n=s.trim());}return {type:"heading",raw:L(t[0],`
3619
+ `),depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return {type:"hr",raw:L(t[0],`
3620
+ `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=L(t[0],`
3621
+ `).split(`
3622
+ `),s="",r="",o=[];for(;n.length>0;){let i=false,u=[],a;for(a=0;a<n.length;a++)if(this.rules.other.blockquoteStart.test(n[a]))u.push(n[a]),i=true;else if(!i)u.push(n[a]);else break;n=n.slice(a);let p=u.join(`
3623
+ `),c=p.replace(this.rules.other.blockquoteSetextReplace,`
3624
+ $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
3625
+ ${p}`:p,r=r?`${r}
3626
+ ${c}`:c;let d=this.lexer.state.top;if(this.lexer.state.top=true,this.lexer.blockTokens(c,o,true),this.lexer.state.top=d,n.length===0)break;let m=o.at(-1);if(m?.type==="code")break;if(m?.type==="blockquote"){let b=m,g=n.join(`
3627
+ `),w=b.raw+`
3628
+ `+g.replace(this.rules.other.blockquoteSetextReplace2,""),f=this.blockquote(w);o[o.length-1]=f;let M=w.substring(f.raw.length).replace(/^\n/,""),v=M?M.split(`
3629
+ `).length:0,Z=v?n.slice(0,-v):n;Z.length>0&&(s=`${s}
3630
+ ${Z.join(`
3631
+ `)}`),r=r.substring(0,r.length-b.text.length)+f.text;break}else if(m?.type==="list"){let b=m,g=b.raw+`
3632
+ `+n.join(`
3633
+ `),w=this.list(g);o[o.length-1]=w,s=s.substring(0,s.length-m.raw.length)+w.raw,r=r.substring(0,r.length-b.raw.length)+w.raw,n=g.substring(o.at(-1).raw.length).split(`
3634
+ `);continue}}return {type:"blockquote",raw:s,tokens:o,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:false,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");let o=this.rules.other.listItemRegex(n),i=false;for(;e;){let a=false,p="",c="";if(!(t=o.exec(e))||this.rules.block.hr.test(e))break;p=t[0],e=e.substring(p.length);let d=t[2].split(`
3635
+ `,1)[0],m=t[1].length,b=this.options.pedantic?oe(d,m):d.replace(this.rules.other.leadingSpaceTab,M=>oe(M,m)),g=e.split(`
3636
+ `,1)[0],w=!b.trim(),f=0;if(this.options.pedantic?(f=2,c=b.trimStart()):w?f=m+1:(f=b.search(this.rules.other.nonSpaceChar),f=f>4?1:f,c=b.slice(f),f+=m),w&&this.rules.other.blankLine.test(g)&&(p+=g+`
3637
+ `,e=e.substring(g.length+1),a=true),!a){let M=this.rules.other.nextBulletRegex(f),v=this.rules.other.hrRegex(f),Z=this.rules.other.fencesBeginRegex(f),ae=this.rules.other.headingBeginRegex(f),ye=this.rules.other.htmlBeginRegex(f),Pe=this.rules.other.blockquoteBeginRegex(f);for(;e;){let K=e.split(`
3638
+ `,1)[0],H;if(g=K,this.options.pedantic?(g=g.replace(this.rules.other.listReplaceNesting," "),H=g):H=g.replace(this.rules.other.leadingSpaceTab,Se=>Se.replace(this.rules.other.tabCharGlobal," ")),Z.test(g)||ae.test(g)||ye.test(g)||Pe.test(g)||M.test(g)||v.test(g))break;if(H.search(this.rules.other.nonSpaceChar)>=f||!g.trim())c+=`
3639
+ `+H.slice(f);else {if(w||b.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||Z.test(b)||ae.test(b)||v.test(b))break;c+=`
3640
+ `+g;}w=!g.trim(),p+=K+`
3641
+ `,e=e.substring(K.length+1),b=H.slice(f);}}r.loose||(i?r.loose=true:this.rules.other.doubleBlankLine.test(p)&&(i=true)),r.items.push({type:"list_item",raw:p,task:!!this.options.gfm&&this.rules.other.listIsTask.test(c),loose:false,text:c,tokens:[]}),r.raw+=p;}let u=r.items.at(-1);if(u)u.raw=u.raw.trimEnd(),u.text=u.text.trimEnd();else return;r.raw=r.raw.trimEnd();for(let a of r.items)if(this.lexer.state.top=false,a.tokens=this.lexer.blockTokens(a.text,[]),!r.loose){let p=a.tokens.filter(d=>d.type==="space"),c=p.length>0&&p.some(d=>this.rules.other.anyLine.test(d.raw));r.loose=c;}for(let a of r.items){let p=a.tokens[0];if(a.task&&(p?.type==="text"||p?.type==="paragraph")){a.text=a.text.replace(this.rules.other.listReplaceTask,""),p.raw=p.raw.replace(this.rules.other.listReplaceTask,""),p.text=p.text.replace(this.rules.other.listReplaceTask,"");for(let d=this.lexer.inlineQueue.length-1;d>=0;d--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[d].src)){this.lexer.inlineQueue[d].src=this.lexer.inlineQueue[d].src.replace(this.rules.other.listReplaceTask,"");break}let c=this.rules.other.listTaskCheckbox.exec(a.raw);if(c){let d={type:"checkbox",raw:c[0]+" ",checked:c[0]!=="[ ]"};a.checked=d.checked,r.loose?a.tokens[0]&&["paragraph","text"].includes(a.tokens[0].type)&&"tokens"in a.tokens[0]&&a.tokens[0].tokens?(a.tokens[0].raw=d.raw+a.tokens[0].raw,a.tokens[0].text=d.raw+a.tokens[0].text,a.tokens[0].tokens.unshift(d)):a.tokens.unshift({type:"paragraph",raw:d.raw,text:d.raw,tokens:[d]}):a.tokens.unshift(d);}}else a.task&&(a.task=false);}if(r.loose)for(let a of r.items){a.loose=true;for(let p of a.tokens)p.type==="text"&&(p.type="paragraph");}return r}}html(e){let t=this.rules.block.html.exec(e);if(t){let n=ie(t[0]);return {type:"html",block:true,raw:n,pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:n}}}def(e){let t=this.rules.block.def.exec(e);if(t){let n=q(t[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return {type:"def",tag:n,raw:L(t[0],`
3642
+ `),href:s,title:r}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=se(t[1]),s=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),r=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
3643
+ `):[],o={type:"table",raw:L(t[0],`
3644
+ `),header:[],align:[],rows:[]};if(n.length===s.length){for(let i of s)this.rules.other.tableAlignRight.test(i)?o.align.push("right"):this.rules.other.tableAlignCenter.test(i)?o.align.push("center"):this.rules.other.tableAlignLeft.test(i)?o.align.push("left"):o.align.push(null);for(let i=0;i<n.length;i++)o.header.push({text:n[i],tokens:this.lexer.inline(n[i]),header:true,align:o.align[i]});for(let i of r)o.rows.push(se(i,o.header.length).map((u,a)=>({text:u,tokens:this.lexer.inline(u),header:false,align:o.align[a]})));return o}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let n=t[1].trim();return {type:"heading",raw:L(t[0],`
3645
+ `),depth:t[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
3646
+ `?t[1].slice(0,-1):t[1];return {type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return {type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return {type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return !this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=true:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=false),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=true:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=false),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:false,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let n=t[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&we(e,t[1],n,this.rules))return;let s=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(s)){if(!this.rules.other.endAngleBracket.test(s))return;let i=L(s.slice(0,-1),"\\");if((s.length-i.length)%2===0)return}else {let i=Te(t[2],"()");if(i===-2)return;if(i>-1){let a=(t[0].indexOf("!")===0?5:4)+t[1].length+i;t[2]=t[2].substring(0,i),t[0]=t[0].substring(0,a).trim(),t[3]="";}}let r=t[2],o="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],o=i[3]);}else o=t[3]?t[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(s)?r=r.slice(1):r=r.slice(1,-1)),Oe(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:o&&o.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let s=n[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&we(e,n[1],s,this.rules))return;let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),o=t[q(r)];if(!o){let i=n[0].charAt(0);return {type:"text",raw:i,text:i}}return Oe(n,o,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&n.match(this.rules.other.unicodeAlphaNumeric))return;if(!(s[1]||s[3]||"")||!n||this.rules.inline.punctuation.exec(n)){let o=[...s[0]].length-1,i,u,a=o,p=0,c=s[0][0],d=n===c,m=c==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(m.lastIndex=0,t=t.slice(-1*e.length+o);(s=m.exec(t))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i)continue;if(u=[...i].length,s[3]||s[4]){a+=u;continue}else if(s[5]||s[6]){if(o%3&&!((o+u)%3)){p+=u;continue}if(d)break}if(a-=u,a>0)continue;u=Math.min(u,u+a+p);let b=[...s[0]][0].length,g=e.slice(0,o+s.index+b+u);if(Math.min(o,u)%2){let f=g.slice(1,-1);return {type:"em",raw:g,text:f,tokens:this.lexer.inlineTokens(f)}}let w=g.slice(2,-2);return {type:"strong",raw:g,text:w,tokens:this.lexer.inlineTokens(w)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(n),r=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return s&&r&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:t[0],text:n}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return {type:"br",raw:t[0]}}del(e,t,n=""){let s=this.rules.inline.delLDelim.exec(e);if(!s)return;if(!(s[1]||"")||!n||this.rules.inline.punctuation.exec(n)){let o=[...s[0]].length-1,i,u,a=o,p=this.rules.inline.delRDelim;for(p.lastIndex=0,t=t.slice(-1*e.length+o);(s=p.exec(t))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i||(u=[...i].length,u!==o))continue;if(s[3]||s[4]){a+=u;continue}if(a-=u,a>0)continue;u=Math.min(u,u+a);let c=[...s[0]][0].length,d=e.slice(0,o+s.index+c+u),m=d.slice(o,-o);return {type:"del",raw:d,text:m,tokens:this.lexer.inlineTokens(m)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let n,s;return t[2]==="@"?(n=t[1],s="mailto:"+n):(n=t[1],s=n),{type:"link",raw:t[0],text:n,href:s,autolink:true,tokens:[{type:"text",raw:n,text:n}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let n,s;if(t[2]==="@")n=t[0],s="mailto:"+n;else {let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(r!==t[0]);n=t[0],t[1]==="www."?s="http://"+t[0]:s=t[0];}return {type:"link",raw:t[0],text:n,href:s,autolink:true,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return {type:"text",raw:t[0],text:n?t[0]:Re(t[0]),escaped:n}}}};var R=class l{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||y,this.options.tokenizer=this.options.tokenizer||new P,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:false,inRawBlock:false,linkEmitted:false,top:true};let t={other:x,block:j.normal,inline:D.normal};this.options.pedantic?(t.block=j.pedantic,t.inline=D.pedantic):this.options.gfm&&(t.block=j.gfm,this.options.breaks?t.inline=D.breaks:t.inline=D.gfm),this.tokenizer.rules=t;}static get rules(){return {block:j,inline:D}}static lex(e,t){return new l(t).lex(e)}static lexInline(e,t){return new l(t).inlineTokens(e)}lex(e){e=e.replace(x.carriageReturn,`
3647
+ `),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let n=this.inlineQueue[t];this.inlineTokens(n.src,n.tokens);}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=false){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(x.tabCharGlobal," ").replace(x.spaceLine,""));let s=1/0;for(;e;){if(e.length<s)s=e.length;else {this.infiniteLoopError(e.charCodeAt(0));break}let r;if(this.options.extensions?.block?.some(i=>(r=i.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),true):false))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let i=t.at(-1);r.raw.length===1&&i!==void 0?i.raw+=`
3648
+ `:t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let i=t.at(-1);i?.type==="paragraph"||i?.type==="text"?(i.raw+=(i.raw.endsWith(`
3649
+ `)?"":`
3650
+ `)+r.raw,i.text+=`
3651
+ `+r.text,this.inlineQueue.at(-1).src=i.text):t.push(r);continue}if(r=this.tokenizer.fences(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.heading(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.hr(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.blockquote(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.list(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.html(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let i=t.at(-1);i?.type==="paragraph"||i?.type==="text"?(i.raw+=(i.raw.endsWith(`
3652
+ `)?"":`
3653
+ `)+r.raw,i.text+=`
3654
+ `+r.raw,this.inlineQueue.at(-1).src=i.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},t.push(r));continue}if(r=this.tokenizer.table(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.lheading(e)){e=e.substring(r.raw.length),t.push(r);continue}let o=e;if(this.options.extensions?.startBlock){let i=1/0,u=e.slice(1),a;this.options.extensions.startBlock.forEach(p=>{a=p.call({lexer:this},u),typeof a=="number"&&a>=0&&(i=Math.min(i,a));}),i<1/0&&i>=0&&(o=e.substring(0,i+1));}if(this.state.top&&(r=this.tokenizer.paragraph(o))){let i=t.at(-1);n&&i?.type==="paragraph"?(i.raw+=(i.raw.endsWith(`
3655
+ `)?"":`
3656
+ `)+r.raw,i.text+=`
3657
+ `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):t.push(r),n=o.length!==e.length,e=e.substring(r.raw.length);continue}if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let i=t.at(-1);i?.type==="text"?(i.raw+=(i.raw.endsWith(`
3658
+ `)?"":`
3659
+ `)+r.raw,i.text+=`
3660
+ `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):t.push(r);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=true,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}linkInText(e){if(!e.includes("["))return false;let t=this.tokenizer.rules.inline.link;for(let n of e.matchAll(this.tokenizer.rules.inline.blockSkip))if(t.test(n[0])&&e.charAt(n.index-1)!=="!")return true;for(let n of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)){let s=n[0],r=s.lastIndexOf("[");if(!(s.charAt(0)==="!"||!Object.hasOwn(this.tokens.links,q(s.slice(r+1,-1))))&&!(r>1&&this.linkInText(s.slice(1,r-1))))return true}return false}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let n=e;if(this.tokens.links&&e.includes("[")){let i=this.tokenizer.rules.inline.reflinkSearch,u=a=>{let p=a.lastIndexOf("[");if(!Object.hasOwn(this.tokens.links,q(a.slice(p+1,-1))))return a;if(p>1&&a.charAt(0)!=="!"){let c=a.slice(1,p-1);if(this.linkInText(c))return "["+c.replace(i,u)+"]["+"a".repeat(a.length-p-2)+"]"}return "["+"a".repeat(a.length-2)+"]"};n=n.replace(i,u);}n=n.replace(this.tokenizer.rules.inline.anyPunctuation,i=>"+".repeat(i.length)),n=n.replace(this.tokenizer.rules.inline.blockSkip,(i,u,a)=>{let p=a?a.length:0;return i.slice(0,p)+"["+"a".repeat(i.length-p-2)+"]"}),n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n;let s=false,r="",o=1/0;for(;e;){if(e.length<o)o=e.length;else {this.infiniteLoopError(e.charCodeAt(0));break}s||(r=""),s=false;let i;if(this.options.extensions?.inline?.some(a=>(i=a.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),true):false))continue;if(i=this.tokenizer.escape(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.tag(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.link(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(i.raw.length);let a=t.at(-1);i.type==="text"&&a?.type==="text"?(a.raw+=i.raw,a.text+=i.text):t.push(i);continue}if(i=this.tokenizer.emStrong(e,n,r)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.codespan(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.br(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.del(e,n,r)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.autolink(e)){e=e.substring(i.raw.length),t.push(i);continue}if(!this.state.inLink&&(i=this.tokenizer.url(e))){e=e.substring(i.raw.length),t.push(i);continue}let u=e;if(this.options.extensions?.startInline){let a=1/0,p=e.slice(1),c;this.options.extensions.startInline.forEach(d=>{c=d.call({lexer:this},p),typeof c=="number"&&c>=0&&(a=Math.min(a,c));}),a<1/0&&a>=0&&(u=e.substring(0,a+1));}if(i=this.tokenizer.inlineText(u)){e=e.substring(i.raw.length),i.raw.slice(-1)!=="_"&&(r=i.raw.slice(-1)),s=true;let a=t.at(-1);a?.type==="text"?(a.raw+=i.raw,a.text+=i.text):t.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t="Infinite loop on byte: "+e;if(this.options.silent)console.error(t);else throw new Error(t)}};var S=class{options;parser;constructor(e){this.options=e||y;}space(e){return ""}code({text:e,lang:t,escaped:n}){let s=(t||"").match(x.notSpaceStart)?.[0],r=e?e.replace(x.endingNewline,"")+`
3661
+ `:"";return s?'<pre><code class="language-'+O(s)+'">'+(n?r:O(r,true))+`</code></pre>
3662
+ `:"<pre><code>"+(n?r:O(r,true))+`</code></pre>
3663
+ `}blockquote({tokens:e}){return `<blockquote>
3664
+ ${this.parser.parse(e)}</blockquote>
3665
+ `}html({text:e}){return e}def(e){return ""}heading({tokens:e,depth:t}){return `<h${t}>${this.parser.parseInline(e)}</h${t}>
3666
+ `}hr(e){return `<hr>
3667
+ `}list(e){let t=e.ordered,n=e.start,s="";for(let i=0;i<e.items.length;i++){let u=e.items[i];s+=this.listitem(u);}let r=t?"ol":"ul",o=t&&n!==1?' start="'+n+'"':"";return "<"+r+o+`>
3668
+ `+s+"</"+r+`>
3669
+ `}listitem(e){return `<li>${this.parser.parse(e.tokens)}</li>
3670
+ `}checkbox({checked:e}){return "<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return `<p>${this.parser.parseInline(e)}</p>
3671
+ `}table(e){let t="",n="";for(let r=0;r<e.header.length;r++)n+=this.tablecell(e.header[r]);t+=this.tablerow({text:n});let s="";for(let r=0;r<e.rows.length;r++){let o=e.rows[r];n="";for(let i=0;i<o.length;i++)n+=this.tablecell(o[i]);s+=this.tablerow({text:n});}return s&&(s=`<tbody>${s}</tbody>`),`<table>
3672
+ <thead>
3673
+ `+t+`</thead>
3674
+ `+s+`</table>
3675
+ `}tablerow({text:e}){return `<tr>
3676
+ ${e}</tr>
3677
+ `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return (e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
3678
+ `}strong({tokens:e}){return `<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return `<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return `<code>${O(e,true)}</code>`}br(e){return "<br>"}del({tokens:e}){return `<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,text:n,tokens:s,autolink:r}){let o=r?O(n,true):this.parser.parseInline(s),i=re(e);if(i===null)return o;e=O(i,r);let u='<a href="'+e+'"';return t&&(u+=' title="'+O(t)+'"'),u+=">"+o+"</a>",u}image({href:e,title:t,text:n,tokens:s}){s&&(n=this.parser.parseInline(s,this.parser.textRenderer));let r=re(e);if(r===null)return O(n);e=r;let o=`<img src="${O(e)}" alt="${O(n)}"`;return t&&(o+=` title="${O(t)}"`),o+=">",o}text(e){return "tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:O(e.text)}};var z=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return ""+e}image({text:e}){return ""+e}br(){return ""}checkbox({raw:e}){return e}};var T=class l{options;renderer;textRenderer;constructor(e){this.options=e||y,this.options.renderer=this.options.renderer||new S,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new z;}static parse(e,t){return new l(t).parse(e)}static parseInline(e,t){return new l(t).parseInline(e)}parse(e){this.renderer.parser=this;let t="";for(let n=0;n<e.length;n++){let s=e[n];if(this.options.extensions?.renderers?.[s.type]){let o=s,i=this.options.extensions.renderers[o.type].call({parser:this},o);if(i!==false||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(o.type)){t+=i||"";continue}}let r=s;switch(r.type){case "space":{t+=this.renderer.space(r);break}case "hr":{t+=this.renderer.hr(r);break}case "heading":{t+=this.renderer.heading(r);break}case "code":{t+=this.renderer.code(r);break}case "table":{t+=this.renderer.table(r);break}case "blockquote":{t+=this.renderer.blockquote(r);break}case "list":{t+=this.renderer.list(r);break}case "checkbox":{t+=this.renderer.checkbox(r);break}case "html":{t+=this.renderer.html(r);break}case "def":{t+=this.renderer.def(r);break}case "paragraph":{t+=this.renderer.paragraph(r);break}case "text":{t+=this.renderer.text(r);break}default:{let o='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let n="";for(let s=0;s<e.length;s++){let r=e[s];if(this.options.extensions?.renderers?.[r.type]){let i=this.options.extensions.renderers[r.type].call({parser:this},r);if(i!==false||!["escape","html","link","image","checkbox","strong","em","codespan","br","del","text"].includes(r.type)){n+=i||"";continue}}let o=r;switch(o.type){case "escape":{n+=t.text(o);break}case "html":{n+=t.html(o);break}case "link":{n+=t.link(o);break}case "image":{n+=t.image(o);break}case "checkbox":{n+=t.checkbox(o);break}case "strong":{n+=t.strong(o);break}case "em":{n+=t.em(o);break}case "codespan":{n+=t.codespan(o);break}case "br":{n+=t.br(o);break}case "del":{n+=t.del(o);break}case "text":{n+=t.text(o);break}default:{let i='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(i),"";throw new Error(i)}}}return n}};var _=class{options;block;constructor(e){this.options=e||y;}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?R.lex:R.lexInline}provideParser(e=this.block){return e?T.parse:T.parseInline}};var F=class{defaults=I();options=this.setOptions;parse=this.parseMarkdown(true);parseInline=this.parseMarkdown(false);Parser=T;Renderer=S;TextRenderer=z;Lexer=R;Tokenizer=P;Hooks=_;constructor(...e){this.use(...e);}walkTokens(e,t){let n=[];for(let s of e)switch(n=n.concat(t.call(this,s)),s.type){case "table":{let r=s;for(let o of r.header)n=n.concat(this.walkTokens(o.tokens,t));for(let o of r.rows)for(let i of o)n=n.concat(this.walkTokens(i.tokens,t));break}case "list":{let r=s;n=n.concat(this.walkTokens(r.items,t));break}default:{let r=s;this.defaults.extensions?.childTokens?.[r.type]?this.defaults.extensions.childTokens[r.type].forEach(o=>{let i=r[o].flat(1/0);n=n.concat(this.walkTokens(i,t));}):r.tokens&&(n=n.concat(this.walkTokens(r.tokens,t)));}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let s={...n};if(s.async=this.defaults.async||s.async||false,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){let o=t.renderers[r.name];o?t.renderers[r.name]=function(...i){let u=r.renderer.apply(this,i);return u===false&&(u=o.apply(this,i)),u}:t.renderers[r.name]=r.renderer;}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let o=t[r.level];o?o.unshift(r.tokenizer):t[r.level]=[r.tokenizer],r.start&&(r.level==="block"?t.startBlock?t.startBlock.push(r.start):t.startBlock=[r.start]:r.level==="inline"&&(t.startInline?t.startInline.push(r.start):t.startInline=[r.start]));}"childTokens"in r&&r.childTokens&&(t.childTokens[r.name]=r.childTokens);}),s.extensions=t),n.renderer){let r=this.defaults.renderer||new S(this.defaults);for(let o in n.renderer){if(!(o in r))throw new Error(`renderer '${o}' does not exist`);if(["options","parser"].includes(o))continue;let i=o,u=n.renderer[i],a=r[i];r[i]=(...p)=>{let c=u.apply(r,p);return c===false&&(c=a.apply(r,p)),c||""};}s.renderer=r;}if(n.tokenizer){let r=this.defaults.tokenizer||new P(this.defaults);for(let o in n.tokenizer){if(!(o in r))throw new Error(`tokenizer '${o}' does not exist`);if(["options","rules","lexer"].includes(o))continue;let i=o,u=n.tokenizer[i],a=r[i];r[i]=(...p)=>{let c=u.apply(r,p);return c===false&&(c=a.apply(r,p)),c};}s.tokenizer=r;}if(n.hooks){let r=this.defaults.hooks||new _;for(let o in n.hooks){if(!(o in r))throw new Error(`hook '${o}' does not exist`);if(["options","block"].includes(o))continue;let i=o,u=n.hooks[i],a=r[i];_.passThroughHooks.has(o)?r[i]=p=>{if(this.defaults.async&&_.passThroughHooksRespectAsync.has(o))return (async()=>{let d=await u.call(r,p);return a.call(r,d)})();let c=u.call(r,p);return a.call(r,c)}:r[i]=(...p)=>{if(this.defaults.async)return (async()=>{let d=await u.apply(r,p);return d===false&&(d=await a.apply(r,p)),d})();let c=u.apply(r,p);return c===false&&(c=a.apply(r,p)),c};}s.hooks=r;}if(n.walkTokens){let r=this.defaults.walkTokens,o=n.walkTokens;s.walkTokens=function(i){let u=[];return u.push(o.call(this,i)),r&&(u=u.concat(r.call(this,i))),u};}this.defaults={...this.defaults,...s};}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return R.lex(e,t??this.defaults)}parser(e,t){return T.parse(e,t??this.defaults)}parseMarkdown(e){return (n,s)=>{let r={...s},o={...this.defaults,...r},i=this.onError(!!o.silent,!!o.async);if(this.defaults.async===true&&r.async===false)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(o.hooks&&(o.hooks.options=o,o.hooks.block=e),o.async)return (async()=>{let u=o.hooks?await o.hooks.preprocess(n):n,p=await(o.hooks?await o.hooks.provideLexer(e):e?R.lex:R.lexInline)(u,o),c=o.hooks?await o.hooks.processAllTokens(p):p;o.walkTokens&&await Promise.all(this.walkTokens(c,o.walkTokens));let m=await(o.hooks?await o.hooks.provideParser(e):e?T.parse:T.parseInline)(c,o);return o.hooks?await o.hooks.postprocess(m):m})().catch(i);try{o.hooks&&(n=o.hooks.preprocess(n));let a=(o.hooks?o.hooks.provideLexer(e):e?R.lex:R.lexInline)(n,o);o.hooks&&(a=o.hooks.processAllTokens(a)),o.walkTokens&&this.walkTokens(a,o.walkTokens);let c=(o.hooks?o.hooks.provideParser(e):e?T.parse:T.parseInline)(a,o);return o.hooks&&(c=o.hooks.postprocess(c)),c}catch(u){return i(u)}}}onError(e,t){return n=>{if(n.message+=`
3679
+ Please report this to https://github.com/markedjs/marked.`,e){let s="<p>An error occurred:</p><pre>"+O(n.message+"",true)+"</pre>";return t?Promise.resolve(s):s}if(t)return Promise.reject(n);throw n}}};var E=new F;function k(l,e){return E.parse(l,e)}k.options=k.setOptions=function(l){return E.setOptions(l),k.defaults=E.defaults,W(k.defaults),k};k.getDefaults=I;k.defaults=y;function Pt(...l){return E.use(...l),k.defaults=E.defaults,W(k.defaults),k}k.use=Pt;k.walkTokens=function(l,e){return E.walkTokens(l,e)};k.parseInline=E.parseInline;k.Parser=T;k.parser=T.parse;k.Renderer=S;k.TextRenderer=z;k.Lexer=R;k.lexer=R.lex;k.Tokenizer=P;k.Hooks=_;k.parse=k;k.options;k.setOptions;k.walkTokens;k.parseInline;T.parse;R.lex;
4012
3680
 
4013
- function mapFragment(fragment, f, parent) {
4014
- let mapped = [];
4015
- for (let i = 0; i < fragment.childCount; i++) {
4016
- let child = fragment.child(i);
4017
- if (child.content.size)
4018
- child = child.copy(mapFragment(child.content, f, child));
4019
- if (child.isInline)
4020
- child = f(child, parent, i);
4021
- mapped.push(child);
4022
- }
4023
- return Fragment.fromArray(mapped);
4024
- }
4025
- /**
4026
- Add a mark to all inline content between two positions.
4027
- */
4028
- class AddMarkStep extends Step {
4029
- /**
4030
- Create a mark step.
4031
- */
4032
- constructor(
4033
- /**
4034
- The start of the marked range.
4035
- */
4036
- from,
4037
- /**
4038
- The end of the marked range.
4039
- */
4040
- to,
4041
- /**
4042
- The mark to add.
4043
- */
4044
- mark) {
4045
- super();
4046
- this.from = from;
4047
- this.to = to;
4048
- this.mark = mark;
4049
- }
4050
- apply(doc) {
4051
- let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
4052
- let parent = $from.node($from.sharedDepth(this.to));
4053
- let slice = new Slice(mapFragment(oldSlice.content, (node, parent) => {
4054
- if (!node.isAtom || !parent.type.allowsMarkType(this.mark.type))
4055
- return node;
4056
- return node.mark(this.mark.addToSet(node.marks));
4057
- }, parent), oldSlice.openStart, oldSlice.openEnd);
4058
- return StepResult.fromReplace(doc, this.from, this.to, slice);
4059
- }
4060
- invert() {
4061
- return new RemoveMarkStep(this.from, this.to, this.mark);
4062
- }
4063
- map(mapping) {
4064
- let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
4065
- if (from.deleted && to.deleted || from.pos >= to.pos)
4066
- return null;
4067
- return new AddMarkStep(from.pos, to.pos, this.mark);
4068
- }
4069
- merge(other) {
4070
- if (other instanceof AddMarkStep &&
4071
- other.mark.eq(this.mark) &&
4072
- this.from <= other.to && this.to >= other.from)
4073
- return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
4074
- return null;
4075
- }
4076
- toJSON() {
4077
- return { stepType: "addMark", mark: this.mark.toJSON(),
4078
- from: this.from, to: this.to };
4079
- }
4080
- /**
4081
- @internal
4082
- */
4083
- static fromJSON(schema, json) {
4084
- if (typeof json.from != "number" || typeof json.to != "number")
4085
- throw new RangeError("Invalid input for AddMarkStep.fromJSON");
4086
- return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
4087
- }
4088
- }
4089
- Step.jsonID("addMark", AddMarkStep);
4090
- /**
4091
- Remove a mark from all inline content between two positions.
4092
- */
4093
- class RemoveMarkStep extends Step {
4094
- /**
4095
- Create a mark-removing step.
4096
- */
4097
- constructor(
4098
- /**
4099
- The start of the unmarked range.
4100
- */
4101
- from,
4102
- /**
4103
- The end of the unmarked range.
4104
- */
4105
- to,
4106
- /**
4107
- The mark to remove.
4108
- */
4109
- mark) {
4110
- super();
4111
- this.from = from;
4112
- this.to = to;
4113
- this.mark = mark;
4114
- }
4115
- apply(doc) {
4116
- let oldSlice = doc.slice(this.from, this.to);
4117
- let slice = new Slice(mapFragment(oldSlice.content, node => {
4118
- return node.mark(this.mark.removeFromSet(node.marks));
4119
- }, doc), oldSlice.openStart, oldSlice.openEnd);
4120
- return StepResult.fromReplace(doc, this.from, this.to, slice);
4121
- }
4122
- invert() {
4123
- return new AddMarkStep(this.from, this.to, this.mark);
4124
- }
4125
- map(mapping) {
4126
- let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
4127
- if (from.deleted && to.deleted || from.pos >= to.pos)
4128
- return null;
4129
- return new RemoveMarkStep(from.pos, to.pos, this.mark);
4130
- }
4131
- merge(other) {
4132
- if (other instanceof RemoveMarkStep &&
4133
- other.mark.eq(this.mark) &&
4134
- this.from <= other.to && this.to >= other.from)
4135
- return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
4136
- return null;
4137
- }
4138
- toJSON() {
4139
- return { stepType: "removeMark", mark: this.mark.toJSON(),
4140
- from: this.from, to: this.to };
4141
- }
4142
- /**
4143
- @internal
4144
- */
4145
- static fromJSON(schema, json) {
4146
- if (typeof json.from != "number" || typeof json.to != "number")
4147
- throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
4148
- return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
4149
- }
4150
- }
4151
- Step.jsonID("removeMark", RemoveMarkStep);
4152
- /**
4153
- Add a mark to a specific node.
4154
- */
4155
- class AddNodeMarkStep extends Step {
4156
- /**
4157
- Create a node mark step.
4158
- */
4159
- constructor(
4160
- /**
4161
- The position of the target node.
4162
- */
4163
- pos,
4164
- /**
4165
- The mark to add.
4166
- */
4167
- mark) {
4168
- super();
4169
- this.pos = pos;
4170
- this.mark = mark;
4171
- }
4172
- apply(doc) {
4173
- let node = doc.nodeAt(this.pos);
4174
- if (!node)
4175
- return StepResult.fail("No node at mark step's position");
4176
- let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
4177
- return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
4178
- }
4179
- invert(doc) {
4180
- let node = doc.nodeAt(this.pos);
4181
- if (node) {
4182
- let newSet = this.mark.addToSet(node.marks);
4183
- if (newSet.length == node.marks.length) {
4184
- for (let i = 0; i < node.marks.length; i++)
4185
- if (!node.marks[i].isInSet(newSet))
4186
- return new AddNodeMarkStep(this.pos, node.marks[i]);
4187
- return new AddNodeMarkStep(this.pos, this.mark);
4188
- }
4189
- }
4190
- return new RemoveNodeMarkStep(this.pos, this.mark);
4191
- }
4192
- map(mapping) {
4193
- let pos = mapping.mapResult(this.pos, 1);
4194
- return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);
4195
- }
4196
- toJSON() {
4197
- return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
4198
- }
4199
- /**
4200
- @internal
4201
- */
4202
- static fromJSON(schema, json) {
4203
- if (typeof json.pos != "number")
4204
- throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
4205
- return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
3681
+ var NON_EMPTY_TAGS = ["img", "iframe"];
3682
+ var MARGIN_HEIGHT = 8;
3683
+ var EMPTY_TAGS_TO_REMOVE = ["p", "h1", "h2", "h3", "h4", "h5", "h6", "br"];
3684
+ var DEFAULT_SEARCH_KEYS = [{
3685
+ name: "title",
3686
+ weight: 0.7
3687
+ }, {
3688
+ name: "optionName",
3689
+ weight: 0.6
3690
+ }, {
3691
+ name: "description",
3692
+ weight: 0.1
3693
+ }];
3694
+ var FUZZY_SEARCH_DEFAULT_LIMIT = 4;
3695
+ var MARKDOWN_PATTERNS = [/^#{1,6}\s/m, /^[ \t]*([-*+]|\d+[.)])\s/m, /^>\s/m, /^ {0,3}(```|~~~)/m, /^ *(?:\| *)?:?-+:? *(?:\| *:?-+:? *)+(?:\| *)?$/m, /\[[^[\]\n]+\]\([^()\s]+\)/, /\*\*\S[^\n]*?\*\*|(?<!\w)__[^\s_][^_\n]*__(?!\w)/, /`[^`\n]+`/];
3696
+
3697
+ var escapeHtml = function escapeHtml(text) {
3698
+ return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
3699
+ };
3700
+ var markdown = new F({
3701
+ gfm: true,
3702
+ breaks: true,
3703
+ renderer: {
3704
+ html: function html(_ref) {
3705
+ var text = _ref.text;
3706
+ return escapeHtml(text);
3707
+ },
3708
+ checkbox: function checkbox() {
3709
+ return "";
3710
+ },
3711
+ code: function code(_ref2) {
3712
+ var _lang$match;
3713
+ var text = _ref2.text,
3714
+ lang = _ref2.lang;
3715
+ var language = lang === null || lang === void 0 || (_lang$match = lang.match(/^\S+/)) === null || _lang$match === void 0 ? void 0 : _lang$match[0];
3716
+ var languageClass = language ? " class=\"language-".concat(escapeHtml(language), "\"") : "";
3717
+ return "<pre><code".concat(languageClass, ">").concat(escapeHtml(text), "</code></pre>");
3718
+ },
3719
+ list: function list(token) {
3720
+ var _this = this;
3721
+ if (!token.items.some(ramda.prop("task"))) return false;
3722
+ var items = token.items.map(function (item) {
3723
+ return _this.listitem(item);
3724
+ }).join("");
3725
+ return "<ul data-type=\"todoList\">".concat(items, "</ul>");
3726
+ },
3727
+ listitem: function listitem(item) {
3728
+ if (!item.task) return false;
3729
+ var body = this.parser.parse(item.tokens, !!item.loose);
3730
+ return "<li data-type=\"taskItem\" data-checked=\"".concat(item.checked, "\">").concat(body, "</li>");
4206
3731
  }
4207
- }
4208
- Step.jsonID("addNodeMark", AddNodeMarkStep);
4209
- /**
4210
- Remove a mark from a specific node.
4211
- */
4212
- class RemoveNodeMarkStep extends Step {
4213
- /**
4214
- Create a mark-removing step.
4215
- */
4216
- constructor(
4217
- /**
4218
- The position of the target node.
4219
- */
4220
- pos,
4221
- /**
4222
- The mark to remove.
4223
- */
4224
- mark) {
4225
- super();
4226
- this.pos = pos;
4227
- this.mark = mark;
4228
- }
4229
- apply(doc) {
4230
- let node = doc.nodeAt(this.pos);
4231
- if (!node)
4232
- return StepResult.fail("No node at mark step's position");
4233
- let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
4234
- return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
4235
- }
4236
- invert(doc) {
4237
- let node = doc.nodeAt(this.pos);
4238
- if (!node || !this.mark.isInSet(node.marks))
4239
- return this;
4240
- return new AddNodeMarkStep(this.pos, this.mark);
4241
- }
4242
- map(mapping) {
4243
- let pos = mapping.mapResult(this.pos, 1);
4244
- return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);
4245
- }
4246
- toJSON() {
4247
- return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
4248
- }
4249
- /**
4250
- @internal
4251
- */
4252
- static fromJSON(schema, json) {
4253
- if (typeof json.pos != "number")
4254
- throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
4255
- return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
4256
- }
4257
- }
4258
- Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
4259
-
4260
- /**
4261
- Replace a part of the document with a slice of new content.
4262
- */
4263
- class ReplaceStep extends Step {
4264
- /**
4265
- The given `slice` should fit the 'gap' between `from` and
4266
- `to`—the depths must line up, and the surrounding nodes must be
4267
- able to be joined with the open sides of the slice. When
4268
- `structure` is true, the step will fail if the content between
4269
- from and to is not just a sequence of closing and then opening
4270
- tokens (this is to guard against rebased replace steps
4271
- overwriting something they weren't supposed to).
4272
- */
4273
- constructor(
4274
- /**
4275
- The start position of the replaced range.
4276
- */
4277
- from,
4278
- /**
4279
- The end position of the replaced range.
4280
- */
4281
- to,
4282
- /**
4283
- The slice to insert.
4284
- */
4285
- slice,
4286
- /**
4287
- @internal
4288
- */
4289
- structure = false) {
4290
- super();
4291
- this.from = from;
4292
- this.to = to;
4293
- this.slice = slice;
4294
- this.structure = structure;
4295
- }
4296
- apply(doc) {
4297
- if (this.structure && contentBetween(doc, this.from, this.to))
4298
- return StepResult.fail("Structure replace would overwrite content");
4299
- return StepResult.fromReplace(doc, this.from, this.to, this.slice);
4300
- }
4301
- getMap() {
4302
- return new StepMap([this.from, this.to - this.from, this.slice.size]);
4303
- }
4304
- invert(doc) {
4305
- return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
4306
- }
4307
- map(mapping) {
4308
- let to = mapping.mapResult(this.to, -1);
4309
- let from = this.from == this.to && ReplaceStep.MAP_BIAS < 0 ? to : mapping.mapResult(this.from, 1);
4310
- if (from.deletedAcross && to.deletedAcross)
4311
- return null;
4312
- return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);
4313
- }
4314
- merge(other) {
4315
- if (!(other instanceof ReplaceStep) || other.structure || this.structure)
4316
- return null;
4317
- if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
4318
- let slice = this.slice.size + other.slice.size == 0 ? Slice.empty
4319
- : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
4320
- return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
4321
- }
4322
- else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
4323
- let slice = this.slice.size + other.slice.size == 0 ? Slice.empty
4324
- : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
4325
- return new ReplaceStep(other.from, this.to, slice, this.structure);
4326
- }
4327
- else {
4328
- return null;
4329
- }
4330
- }
4331
- toJSON() {
4332
- let json = { stepType: "replace", from: this.from, to: this.to };
4333
- if (this.slice.size)
4334
- json.slice = this.slice.toJSON();
4335
- if (this.structure)
4336
- json.structure = true;
4337
- return json;
4338
- }
4339
- /**
4340
- @internal
4341
- */
4342
- static fromJSON(schema, json) {
4343
- if (typeof json.from != "number" || typeof json.to != "number")
4344
- throw new RangeError("Invalid input for ReplaceStep.fromJSON");
4345
- return new ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
4346
- }
4347
- }
4348
- /**
4349
- By default, for backwards compatibility, an inserting step
4350
- mapped over an insertion at that same position fill move after
4351
- the inserted content. In a collaborative editing situation, that
4352
- can make redone insertions appear in unexpected places. You can
4353
- set this to -1 to make such mapping keep the step before the
4354
- insertion instead.
4355
- */
4356
- ReplaceStep.MAP_BIAS = 1;
4357
- Step.jsonID("replace", ReplaceStep);
4358
- /**
4359
- Replace a part of the document with a slice of content, but
4360
- preserve a range of the replaced content by moving it into the
4361
- slice.
4362
- */
4363
- class ReplaceAroundStep extends Step {
4364
- /**
4365
- Create a replace-around step with the given range and gap.
4366
- `insert` should be the point in the slice into which the content
4367
- of the gap should be moved. `structure` has the same meaning as
4368
- it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
4369
- */
4370
- constructor(
4371
- /**
4372
- The start position of the replaced range.
4373
- */
4374
- from,
4375
- /**
4376
- The end position of the replaced range.
4377
- */
4378
- to,
4379
- /**
4380
- The start of preserved range.
4381
- */
4382
- gapFrom,
4383
- /**
4384
- The end of preserved range.
4385
- */
4386
- gapTo,
4387
- /**
4388
- The slice to insert.
4389
- */
4390
- slice,
4391
- /**
4392
- The position in the slice where the preserved range should be
4393
- inserted.
4394
- */
4395
- insert,
4396
- /**
4397
- @internal
4398
- */
4399
- structure = false) {
4400
- super();
4401
- this.from = from;
4402
- this.to = to;
4403
- this.gapFrom = gapFrom;
4404
- this.gapTo = gapTo;
4405
- this.slice = slice;
4406
- this.insert = insert;
4407
- this.structure = structure;
4408
- }
4409
- apply(doc) {
4410
- if (this.structure && (contentBetween(doc, this.from, this.gapFrom) ||
4411
- contentBetween(doc, this.gapTo, this.to)))
4412
- return StepResult.fail("Structure gap-replace would overwrite content");
4413
- let gap = doc.slice(this.gapFrom, this.gapTo);
4414
- if (gap.openStart || gap.openEnd)
4415
- return StepResult.fail("Gap is not a flat range");
4416
- let inserted = this.slice.insertAt(this.insert, gap.content);
4417
- if (!inserted)
4418
- return StepResult.fail("Content does not fit in gap");
4419
- return StepResult.fromReplace(doc, this.from, this.to, inserted);
4420
- }
4421
- getMap() {
4422
- return new StepMap([this.from, this.gapFrom - this.from, this.insert,
4423
- this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]);
4424
- }
4425
- invert(doc) {
4426
- let gap = this.gapTo - this.gapFrom;
4427
- return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
4428
- }
4429
- map(mapping) {
4430
- let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
4431
- let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
4432
- let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
4433
- if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos)
4434
- return null;
4435
- return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
4436
- }
4437
- toJSON() {
4438
- let json = { stepType: "replaceAround", from: this.from, to: this.to,
4439
- gapFrom: this.gapFrom, gapTo: this.gapTo, insert: this.insert };
4440
- if (this.slice.size)
4441
- json.slice = this.slice.toJSON();
4442
- if (this.structure)
4443
- json.structure = true;
4444
- return json;
4445
- }
4446
- /**
4447
- @internal
4448
- */
4449
- static fromJSON(schema, json) {
4450
- if (typeof json.from != "number" || typeof json.to != "number" ||
4451
- typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
4452
- throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
4453
- return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
4454
- }
4455
- }
4456
- Step.jsonID("replaceAround", ReplaceAroundStep);
4457
- function contentBetween(doc, from, to) {
4458
- let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
4459
- while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
4460
- depth--;
4461
- dist--;
4462
- }
4463
- if (dist > 0) {
4464
- let next = $from.node(depth).maybeChild($from.indexAfter(depth));
4465
- while (dist > 0) {
4466
- if (!next || next.isLeaf)
4467
- return true;
4468
- next = next.firstChild;
4469
- dist--;
4470
- }
4471
- }
4472
- return false;
4473
- }
4474
-
4475
- function addMark(tr, from, to, mark) {
4476
- let removed = [], added = [];
4477
- let removing, adding;
4478
- tr.doc.nodesBetween(from, to, (node, pos, parent) => {
4479
- if (!node.isInline)
4480
- return;
4481
- let marks = node.marks;
4482
- if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
4483
- let start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
4484
- let newSet = mark.addToSet(marks);
4485
- for (let i = 0; i < marks.length; i++) {
4486
- if (!marks[i].isInSet(newSet)) {
4487
- if (removing && removing.to == start && removing.mark.eq(marks[i]))
4488
- removing.to = end;
4489
- else
4490
- removed.push(removing = new RemoveMarkStep(start, end, marks[i]));
4491
- }
4492
- }
4493
- if (adding && adding.to == start)
4494
- adding.to = end;
4495
- else
4496
- added.push(adding = new AddMarkStep(start, end, mark));
4497
- }
4498
- });
4499
- removed.forEach(s => tr.step(s));
4500
- added.forEach(s => tr.step(s));
4501
- }
4502
- function removeMark(tr, from, to, mark) {
4503
- let matched = [], step = 0;
4504
- tr.doc.nodesBetween(from, to, (node, pos) => {
4505
- if (!node.isInline)
4506
- return;
4507
- step++;
4508
- let toRemove = null;
4509
- if (mark instanceof MarkType) {
4510
- let set = node.marks, found;
4511
- while (found = mark.isInSet(set)) {
4512
- (toRemove || (toRemove = [])).push(found);
4513
- set = found.removeFromSet(set);
4514
- }
4515
- }
4516
- else if (mark) {
4517
- if (mark.isInSet(node.marks))
4518
- toRemove = [mark];
4519
- }
4520
- else {
4521
- toRemove = node.marks;
4522
- }
4523
- if (toRemove && toRemove.length) {
4524
- let end = Math.min(pos + node.nodeSize, to);
4525
- for (let i = 0; i < toRemove.length; i++) {
4526
- let style = toRemove[i], found;
4527
- for (let j = 0; j < matched.length; j++) {
4528
- let m = matched[j];
4529
- if (m.step == step - 1 && style.eq(matched[j].style))
4530
- found = m;
4531
- }
4532
- if (found) {
4533
- found.to = end;
4534
- found.step = step;
4535
- }
4536
- else {
4537
- matched.push({ style, from: Math.max(pos, from), to: end, step });
4538
- }
4539
- }
4540
- }
4541
- });
4542
- matched.forEach(m => tr.step(new RemoveMarkStep(m.from, m.to, m.style)));
4543
- }
4544
- function clearIncompatible(tr, pos, parentType, match = parentType.contentMatch, clearNewlines = true) {
4545
- let node = tr.doc.nodeAt(pos);
4546
- let replSteps = [], cur = pos + 1;
4547
- for (let i = 0; i < node.childCount; i++) {
4548
- let child = node.child(i), end = cur + child.nodeSize;
4549
- let allowed = match.matchType(child.type);
4550
- if (!allowed) {
4551
- replSteps.push(new ReplaceStep(cur, end, Slice.empty));
4552
- }
4553
- else {
4554
- match = allowed;
4555
- for (let j = 0; j < child.marks.length; j++)
4556
- if (!parentType.allowsMarkType(child.marks[j].type))
4557
- tr.step(new RemoveMarkStep(cur, end, child.marks[j]));
4558
- if (clearNewlines && child.isText && parentType.whitespace != "pre") {
4559
- let m, newline = /\r?\n|\r/g, slice;
4560
- while (m = newline.exec(child.text)) {
4561
- if (!slice)
4562
- slice = new Slice(Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))), 0, 0);
4563
- replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice));
4564
- }
4565
- }
4566
- }
4567
- cur = end;
4568
- }
4569
- if (!match.validEnd) {
4570
- let fill = match.fillBefore(Fragment.empty, true);
4571
- tr.replace(cur, cur, new Slice(fill, 0, 0));
4572
- }
4573
- for (let i = replSteps.length - 1; i >= 0; i--)
4574
- tr.step(replSteps[i]);
4575
- }
4576
-
4577
- function canCut(node, start, end) {
4578
- return (start == 0 || node.canReplace(start, node.childCount)) &&
4579
- (end == node.childCount || node.canReplace(0, end));
4580
- }
4581
- /**
4582
- Try to find a target depth to which the content in the given range
4583
- can be lifted. Will not go across
4584
- [isolating](https://prosemirror.net/docs/ref/#model.NodeSpec.isolating) parent nodes.
4585
- */
4586
- function liftTarget(range) {
4587
- let parent = range.parent;
4588
- let content = parent.content.cutByIndex(range.startIndex, range.endIndex);
4589
- for (let depth = range.depth, contentBefore = 0, contentAfter = 0;; --depth) {
4590
- let node = range.$from.node(depth);
4591
- let index = range.$from.index(depth) + contentBefore, endIndex = range.$to.indexAfter(depth) - contentAfter;
4592
- if (depth < range.depth && node.canReplace(index, endIndex, content))
4593
- return depth;
4594
- if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex))
4595
- break;
4596
- if (index)
4597
- contentBefore = 1;
4598
- if (endIndex < node.childCount)
4599
- contentAfter = 1;
4600
- }
4601
- return null;
4602
- }
4603
- function lift(tr, range, target) {
4604
- let { $from, $to, depth } = range;
4605
- let gapStart = $from.before(depth + 1), gapEnd = $to.after(depth + 1);
4606
- let start = gapStart, end = gapEnd;
4607
- let before = Fragment.empty, openStart = 0;
4608
- for (let d = depth, splitting = false; d > target; d--)
4609
- if (splitting || $from.index(d) > 0) {
4610
- splitting = true;
4611
- before = Fragment.from($from.node(d).copy(before));
4612
- openStart++;
4613
- }
4614
- else {
4615
- start--;
4616
- }
4617
- let after = Fragment.empty, openEnd = 0;
4618
- for (let d = depth, splitting = false; d > target; d--)
4619
- if (splitting || $to.after(d + 1) < $to.end(d)) {
4620
- splitting = true;
4621
- after = Fragment.from($to.node(d).copy(after));
4622
- openEnd++;
4623
- }
4624
- else {
4625
- end++;
4626
- }
4627
- tr.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
4628
- }
4629
- /**
4630
- Try to find a valid way to wrap the content in the given range in a
4631
- node of the given type. May introduce extra nodes around and inside
4632
- the wrapper node, if necessary. Returns null if no valid wrapping
4633
- could be found. When `innerRange` is given, that range's content is
4634
- used as the content to fit into the wrapping, instead of the
4635
- content of `range`.
4636
- */
4637
- function findWrapping(range, nodeType, attrs = null, innerRange = range) {
4638
- let around = findWrappingOutside(range, nodeType);
4639
- let inner = around && findWrappingInside(innerRange, nodeType);
4640
- if (!inner)
4641
- return null;
4642
- return around.map(withAttrs)
4643
- .concat({ type: nodeType, attrs }).concat(inner.map(withAttrs));
4644
- }
4645
- function withAttrs(type) { return { type, attrs: null }; }
4646
- function findWrappingOutside(range, type) {
4647
- let { parent, startIndex, endIndex } = range;
4648
- let around = parent.contentMatchAt(startIndex).findWrapping(type);
4649
- if (!around)
4650
- return null;
4651
- let outer = around.length ? around[0] : type;
4652
- return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null;
4653
- }
4654
- function findWrappingInside(range, type) {
4655
- let { parent, startIndex, endIndex } = range;
4656
- let inner = parent.child(startIndex);
4657
- let inside = type.contentMatch.findWrapping(inner.type);
4658
- if (!inside)
4659
- return null;
4660
- let lastType = inside.length ? inside[inside.length - 1] : type;
4661
- let innerMatch = lastType.contentMatch;
4662
- for (let i = startIndex; innerMatch && i < endIndex; i++)
4663
- innerMatch = innerMatch.matchType(parent.child(i).type);
4664
- if (!innerMatch || !innerMatch.validEnd)
4665
- return null;
4666
- return inside;
4667
- }
4668
- function wrap(tr, range, wrappers) {
4669
- let content = Fragment.empty;
4670
- for (let i = wrappers.length - 1; i >= 0; i--) {
4671
- if (content.size) {
4672
- let match = wrappers[i].type.contentMatch.matchFragment(content);
4673
- if (!match || !match.validEnd)
4674
- throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper");
4675
- }
4676
- content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
4677
- }
4678
- let start = range.start, end = range.end;
4679
- tr.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true));
4680
- }
4681
- function setBlockType(tr, from, to, type, attrs) {
4682
- if (!type.isTextblock)
4683
- throw new RangeError("Type given to setBlockType should be a textblock");
4684
- let mapFrom = tr.steps.length;
4685
- tr.doc.nodesBetween(from, to, (node, pos) => {
4686
- let attrsHere = typeof attrs == "function" ? attrs(node) : attrs;
4687
- if (node.isTextblock && !node.hasMarkup(type, attrsHere) &&
4688
- canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) {
4689
- let convertNewlines = null;
4690
- if (type.schema.linebreakReplacement) {
4691
- let pre = type.whitespace == "pre", supportLinebreak = !!type.contentMatch.matchType(type.schema.linebreakReplacement);
4692
- if (pre && !supportLinebreak)
4693
- convertNewlines = false;
4694
- else if (!pre && supportLinebreak)
4695
- convertNewlines = true;
4696
- }
4697
- // Ensure all markup that isn't allowed in the new node type is cleared
4698
- if (convertNewlines === false)
4699
- replaceLinebreaks(tr, node, pos, mapFrom);
4700
- clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type, undefined, convertNewlines === null);
4701
- let mapping = tr.mapping.slice(mapFrom);
4702
- let startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1);
4703
- tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true));
4704
- if (convertNewlines === true)
4705
- replaceNewlines(tr, node, pos, mapFrom);
4706
- return false;
4707
- }
4708
- });
4709
- }
4710
- function replaceNewlines(tr, node, pos, mapFrom) {
4711
- node.forEach((child, offset) => {
4712
- if (child.isText) {
4713
- let m, newline = /\r?\n|\r/g;
4714
- while (m = newline.exec(child.text)) {
4715
- let start = tr.mapping.slice(mapFrom).map(pos + 1 + offset + m.index);
4716
- tr.replaceWith(start, start + 1, node.type.schema.linebreakReplacement.create());
4717
- }
4718
- }
4719
- });
4720
- }
4721
- function replaceLinebreaks(tr, node, pos, mapFrom) {
4722
- node.forEach((child, offset) => {
4723
- if (child.type == child.type.schema.linebreakReplacement) {
4724
- let start = tr.mapping.slice(mapFrom).map(pos + 1 + offset);
4725
- tr.replaceWith(start, start + 1, node.type.schema.text("\n"));
4726
- }
4727
- });
4728
- }
4729
- function canChangeType(doc, pos, type) {
4730
- let $pos = doc.resolve(pos), index = $pos.index();
4731
- return $pos.parent.canReplaceWith(index, index + 1, type);
4732
- }
4733
- /**
4734
- Change the type, attributes, and/or marks of the node at `pos`.
4735
- When `type` isn't given, the existing node type is preserved,
4736
- */
4737
- function setNodeMarkup(tr, pos, type, attrs, marks) {
4738
- let node = tr.doc.nodeAt(pos);
4739
- if (!node)
4740
- throw new RangeError("No node at given position");
4741
- if (!type)
4742
- type = node.type;
4743
- let newNode = type.create(attrs, null, marks || node.marks);
4744
- if (node.isLeaf)
4745
- return tr.replaceWith(pos, pos + node.nodeSize, newNode);
4746
- if (!type.validContent(node.content))
4747
- throw new RangeError("Invalid content for node type " + type.name);
4748
- tr.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));
4749
- }
4750
- /**
4751
- Check whether splitting at the given position is allowed.
4752
- */
4753
- function canSplit(doc, pos, depth = 1, typesAfter) {
4754
- let $pos = doc.resolve(pos), base = $pos.depth - depth;
4755
- let innerType = (typesAfter && typesAfter[typesAfter.length - 1]) || $pos.parent;
4756
- if (base < 0 || $pos.parent.type.spec.isolating ||
4757
- !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) ||
4758
- !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount)))
4759
- return false;
4760
- for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) {
4761
- let node = $pos.node(d), index = $pos.index(d);
4762
- if (node.type.spec.isolating)
4763
- return false;
4764
- let rest = node.content.cutByIndex(index, node.childCount);
4765
- let overrideChild = typesAfter && typesAfter[i + 1];
4766
- if (overrideChild)
4767
- rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));
4768
- let after = (typesAfter && typesAfter[i]) || node;
4769
- if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))
4770
- return false;
4771
- }
4772
- let index = $pos.indexAfter(base);
4773
- let baseType = typesAfter && typesAfter[0];
4774
- return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type);
4775
- }
4776
- function split(tr, pos, depth = 1, typesAfter) {
4777
- let $pos = tr.doc.resolve(pos), before = Fragment.empty, after = Fragment.empty;
4778
- for (let d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) {
4779
- before = Fragment.from($pos.node(d).copy(before));
4780
- let typeAfter = typesAfter && typesAfter[i];
4781
- after = Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after));
4782
- }
4783
- tr.step(new ReplaceStep(pos, pos, new Slice(before.append(after), depth, depth), true));
4784
- }
4785
- /**
4786
- Test whether the blocks before and after a given position can be
4787
- joined.
4788
- */
4789
- function canJoin(doc, pos) {
4790
- let $pos = doc.resolve(pos), index = $pos.index();
4791
- return joinable($pos.nodeBefore, $pos.nodeAfter) &&
4792
- $pos.parent.canReplace(index, index + 1);
4793
- }
4794
- function canAppendWithSubstitutedLinebreaks(a, b) {
4795
- if (!b.content.size)
4796
- a.type.compatibleContent(b.type);
4797
- let match = a.contentMatchAt(a.childCount);
4798
- let { linebreakReplacement } = a.type.schema;
4799
- for (let i = 0; i < b.childCount; i++) {
4800
- let child = b.child(i);
4801
- let type = child.type == linebreakReplacement ? a.type.schema.nodes.text : child.type;
4802
- match = match.matchType(type);
4803
- if (!match)
4804
- return false;
4805
- if (!a.type.allowsMarks(child.marks))
4806
- return false;
4807
- }
4808
- return match.validEnd;
4809
- }
4810
- function joinable(a, b) {
4811
- return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b));
4812
- }
4813
- /**
4814
- Find an ancestor of the given position that can be joined to the
4815
- block before (or after if `dir` is positive). Returns the joinable
4816
- point, if any.
4817
- */
4818
- function joinPoint(doc, pos, dir = -1) {
4819
- let $pos = doc.resolve(pos);
4820
- for (let d = $pos.depth;; d--) {
4821
- let before, after, index = $pos.index(d);
4822
- if (d == $pos.depth) {
4823
- before = $pos.nodeBefore;
4824
- after = $pos.nodeAfter;
4825
- }
4826
- else if (dir > 0) {
4827
- before = $pos.node(d + 1);
4828
- index++;
4829
- after = $pos.node(d).maybeChild(index);
4830
- }
4831
- else {
4832
- before = $pos.node(d).maybeChild(index - 1);
4833
- after = $pos.node(d + 1);
4834
- }
4835
- if (before && !before.isTextblock && joinable(before, after) &&
4836
- $pos.node(d).canReplace(index, index + 1))
4837
- return pos;
4838
- if (d == 0)
4839
- break;
4840
- pos = dir < 0 ? $pos.before(d) : $pos.after(d);
4841
- }
4842
- }
4843
- function join(tr, pos, depth) {
4844
- let convertNewlines = null;
4845
- let { linebreakReplacement } = tr.doc.type.schema;
4846
- let $before = tr.doc.resolve(pos - depth), beforeType = $before.node().type;
4847
- if (linebreakReplacement && beforeType.inlineContent) {
4848
- let pre = beforeType.whitespace == "pre";
4849
- let supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement);
4850
- if (pre && !supportLinebreak)
4851
- convertNewlines = false;
4852
- else if (!pre && supportLinebreak)
4853
- convertNewlines = true;
4854
- }
4855
- let mapFrom = tr.steps.length;
4856
- if (convertNewlines === false) {
4857
- let $after = tr.doc.resolve(pos + depth);
4858
- replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom);
4859
- }
4860
- if (beforeType.inlineContent)
4861
- clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null);
4862
- let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos - depth);
4863
- tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), Slice.empty, true));
4864
- if (convertNewlines === true) {
4865
- let $full = tr.doc.resolve(start);
4866
- replaceNewlines(tr, $full.node(), $full.before(), tr.steps.length);
4867
- }
4868
- return tr;
4869
- }
4870
- /**
4871
- Try to find a point where a node of the given type can be inserted
4872
- near `pos`, by searching up the node hierarchy when `pos` itself
4873
- isn't a valid place but is at the start or end of a node. Return
4874
- null if no position was found.
4875
- */
4876
- function insertPoint(doc, pos, nodeType) {
4877
- let $pos = doc.resolve(pos);
4878
- if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType))
4879
- return pos;
4880
- if ($pos.parentOffset == 0)
4881
- for (let d = $pos.depth - 1; d >= 0; d--) {
4882
- let index = $pos.index(d);
4883
- if ($pos.node(d).canReplaceWith(index, index, nodeType))
4884
- return $pos.before(d + 1);
4885
- if (index > 0)
4886
- return null;
4887
- }
4888
- if ($pos.parentOffset == $pos.parent.content.size)
4889
- for (let d = $pos.depth - 1; d >= 0; d--) {
4890
- let index = $pos.indexAfter(d);
4891
- if ($pos.node(d).canReplaceWith(index, index, nodeType))
4892
- return $pos.after(d + 1);
4893
- if (index < $pos.node(d).childCount)
4894
- return null;
4895
- }
4896
- return null;
4897
- }
4898
- /**
4899
- Finds a position at or around the given position where the given
4900
- slice can be inserted. Will look at parent nodes' nearest boundary
4901
- and try there, even if the original position wasn't directly at the
4902
- start or end of that node. Returns null when no position was found.
4903
- */
4904
- function dropPoint(doc, pos, slice) {
4905
- let $pos = doc.resolve(pos);
4906
- if (!slice.content.size)
4907
- return pos;
4908
- let content = slice.content;
4909
- for (let i = 0; i < slice.openStart; i++)
4910
- content = content.firstChild.content;
4911
- for (let pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) {
4912
- for (let d = $pos.depth; d >= 0; d--) {
4913
- let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;
4914
- let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);
4915
- let parent = $pos.node(d), fits = false;
4916
- if (pass == 1) {
4917
- fits = parent.canReplace(insertPos, insertPos, content);
4918
- }
4919
- else {
4920
- let wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type);
4921
- fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]);
4922
- }
4923
- if (fits)
4924
- return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1);
4925
- }
4926
- }
4927
- return null;
4928
- }
4929
-
4930
- /**
4931
- ‘Fit’ a slice into a given position in the document, producing a
4932
- [step](https://prosemirror.net/docs/ref/#transform.Step) that inserts it. Will return null if
4933
- there's no meaningful way to insert the slice here, or inserting it
4934
- would be a no-op (an empty slice over an empty range).
4935
- */
4936
- function replaceStep(doc, from, to = from, slice = Slice.empty) {
4937
- if (from == to && !slice.size)
4938
- return null;
4939
- let $from = doc.resolve(from), $to = doc.resolve(to);
4940
- // Optimization -- avoid work if it's obvious that it's not needed.
4941
- if (fitsTrivially($from, $to, slice))
4942
- return new ReplaceStep(from, to, slice);
4943
- return new Fitter($from, $to, slice).fit();
4944
- }
4945
- function fitsTrivially($from, $to, slice) {
4946
- return !slice.openStart && !slice.openEnd && $from.start() == $to.start() &&
4947
- $from.parent.canReplace($from.index(), $to.index(), slice.content);
4948
- }
4949
- // Algorithm for 'placing' the elements of a slice into a gap:
4950
- //
4951
- // We consider the content of each node that is open to the left to be
4952
- // independently placeable. I.e. in <p("foo"), p("bar")>, when the
4953
- // paragraph on the left is open, "foo" can be placed (somewhere on
4954
- // the left side of the replacement gap) independently from p("bar").
4955
- //
4956
- // This class tracks the state of the placement progress in the
4957
- // following properties:
4958
- //
4959
- // - `frontier` holds a stack of `{type, match}` objects that
4960
- // represent the open side of the replacement. It starts at
4961
- // `$from`, then moves forward as content is placed, and is finally
4962
- // reconciled with `$to`.
4963
- //
4964
- // - `unplaced` is a slice that represents the content that hasn't
4965
- // been placed yet.
4966
- //
4967
- // - `placed` is a fragment of placed content. Its open-start value
4968
- // is implicit in `$from`, and its open-end value in `frontier`.
4969
- class Fitter {
4970
- constructor($from, $to, unplaced) {
4971
- this.$from = $from;
4972
- this.$to = $to;
4973
- this.unplaced = unplaced;
4974
- this.frontier = [];
4975
- this.placed = Fragment.empty;
4976
- for (let i = 0; i <= $from.depth; i++) {
4977
- let node = $from.node(i);
4978
- this.frontier.push({
4979
- type: node.type,
4980
- match: node.contentMatchAt($from.indexAfter(i))
4981
- });
4982
- }
4983
- for (let i = $from.depth; i > 0; i--)
4984
- this.placed = Fragment.from($from.node(i).copy(this.placed));
4985
- }
4986
- get depth() { return this.frontier.length - 1; }
4987
- fit() {
4988
- // As long as there's unplaced content, try to place some of it.
4989
- // If that fails, either increase the open score of the unplaced
4990
- // slice, or drop nodes from it, and then try again.
4991
- while (this.unplaced.size) {
4992
- let fit = this.findFittable();
4993
- if (fit)
4994
- this.placeNodes(fit);
4995
- else
4996
- this.openMore() || this.dropNode();
4997
- }
4998
- // When there's inline content directly after the frontier _and_
4999
- // directly after `this.$to`, we must generate a `ReplaceAround`
5000
- // step that pulls that content into the node after the frontier.
5001
- // That means the fitting must be done to the end of the textblock
5002
- // node after `this.$to`, not `this.$to` itself.
5003
- let moveInline = this.mustMoveInline(), placedSize = this.placed.size - this.depth - this.$from.depth;
5004
- let $from = this.$from, $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline));
5005
- if (!$to)
5006
- return null;
5007
- // If closing to `$to` succeeded, create a step
5008
- let content = this.placed, openStart = $from.depth, openEnd = $to.depth;
5009
- while (openStart && openEnd && content.childCount == 1) { // Normalize by dropping open parent nodes
5010
- content = content.firstChild.content;
5011
- openStart--;
5012
- openEnd--;
5013
- }
5014
- let slice = new Slice(content, openStart, openEnd);
5015
- if (moveInline > -1)
5016
- return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);
5017
- if (slice.size || $from.pos != this.$to.pos) // Don't generate no-op steps
5018
- return new ReplaceStep($from.pos, $to.pos, slice);
5019
- return null;
5020
- }
5021
- // Find a position on the start spine of `this.unplaced` that has
5022
- // content that can be moved somewhere on the frontier. Returns two
5023
- // depths, one for the slice and one for the frontier.
5024
- findFittable() {
5025
- let startDepth = this.unplaced.openStart;
5026
- for (let cur = this.unplaced.content, d = 0, openEnd = this.unplaced.openEnd; d < startDepth; d++) {
5027
- let node = cur.firstChild;
5028
- if (cur.childCount > 1)
5029
- openEnd = 0;
5030
- if (node.type.spec.isolating && openEnd <= d) {
5031
- startDepth = d;
5032
- break;
5033
- }
5034
- cur = node.content;
5035
- }
5036
- // Only try wrapping nodes (pass 2) after finding a place without
5037
- // wrapping failed.
5038
- for (let pass = 1; pass <= 2; pass++) {
5039
- for (let sliceDepth = pass == 1 ? startDepth : this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) {
5040
- let fragment, parent = null;
5041
- if (sliceDepth) {
5042
- parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild;
5043
- fragment = parent.content;
5044
- }
5045
- else {
5046
- fragment = this.unplaced.content;
5047
- }
5048
- let first = fragment.firstChild;
5049
- for (let frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) {
5050
- let { type, match } = this.frontier[frontierDepth], wrap, inject = null;
5051
- // In pass 1, if the next node matches, or there is no next
5052
- // node but the parents look compatible, we've found a
5053
- // place.
5054
- if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(Fragment.from(first), false))
5055
- : parent && type.compatibleContent(parent.type)))
5056
- return { sliceDepth, frontierDepth, parent, inject };
5057
- // In pass 2, look for a set of wrapping nodes that make
5058
- // `first` fit here.
5059
- else if (pass == 2 && first && (wrap = match.findWrapping(first.type)))
5060
- return { sliceDepth, frontierDepth, parent, wrap };
5061
- // Don't continue looking further up if the parent node
5062
- // would fit here.
5063
- if (parent && match.matchType(parent.type))
5064
- break;
5065
- }
5066
- }
5067
- }
5068
- }
5069
- openMore() {
5070
- let { content, openStart, openEnd } = this.unplaced;
5071
- let inner = contentAt(content, openStart);
5072
- if (!inner.childCount || inner.firstChild.isLeaf)
5073
- return false;
5074
- this.unplaced = new Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0));
5075
- return true;
5076
- }
5077
- dropNode() {
5078
- let { content, openStart, openEnd } = this.unplaced;
5079
- let inner = contentAt(content, openStart);
5080
- if (inner.childCount <= 1 && openStart > 0) {
5081
- let openAtEnd = content.size - openStart <= openStart + inner.size;
5082
- this.unplaced = new Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd);
5083
- }
5084
- else {
5085
- this.unplaced = new Slice(dropFromFragment(content, openStart, 1), openStart, openEnd);
5086
- }
5087
- }
5088
- // Move content from the unplaced slice at `sliceDepth` to the
5089
- // frontier node at `frontierDepth`. Close that frontier node when
5090
- // applicable.
5091
- placeNodes({ sliceDepth, frontierDepth, parent, inject, wrap }) {
5092
- while (this.depth > frontierDepth)
5093
- this.closeFrontierNode();
5094
- if (wrap)
5095
- for (let i = 0; i < wrap.length; i++)
5096
- this.openFrontierNode(wrap[i]);
5097
- let slice = this.unplaced, fragment = parent ? parent.content : slice.content;
5098
- let openStart = slice.openStart - sliceDepth;
5099
- let taken = 0, add = [];
5100
- let { match, type } = this.frontier[frontierDepth];
5101
- if (inject) {
5102
- for (let i = 0; i < inject.childCount; i++)
5103
- add.push(inject.child(i));
5104
- match = match.matchFragment(inject);
5105
- }
5106
- // Computes the amount of (end) open nodes at the end of the
5107
- // fragment. When 0, the parent is open, but no more. When
5108
- // negative, nothing is open.
5109
- let openEndCount = (fragment.size + sliceDepth) - (slice.content.size - slice.openEnd);
5110
- // Scan over the fragment, fitting as many child nodes as
5111
- // possible.
5112
- while (taken < fragment.childCount) {
5113
- let next = fragment.child(taken), matches = match.matchType(next.type);
5114
- if (!matches)
5115
- break;
5116
- taken++;
5117
- if (taken > 1 || openStart == 0 || next.content.size) { // Drop empty open nodes
5118
- match = matches;
5119
- add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1));
5120
- }
5121
- }
5122
- let toEnd = taken == fragment.childCount;
5123
- if (!toEnd)
5124
- openEndCount = -1;
5125
- this.placed = addToFragment(this.placed, frontierDepth, Fragment.from(add));
5126
- this.frontier[frontierDepth].match = match;
5127
- // If the parent types match, and the entire node was moved, and
5128
- // it's not open, close this frontier node right away.
5129
- if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1)
5130
- this.closeFrontierNode();
5131
- // Add new frontier nodes for any open nodes at the end.
5132
- for (let i = 0, cur = fragment; i < openEndCount; i++) {
5133
- let node = cur.lastChild;
5134
- this.frontier.push({ type: node.type, match: node.contentMatchAt(node.childCount) });
5135
- cur = node.content;
5136
- }
5137
- // Update `this.unplaced`. Drop the entire node from which we
5138
- // placed it we got to its end, otherwise just drop the placed
5139
- // nodes.
5140
- this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd)
5141
- : sliceDepth == 0 ? Slice.empty
5142
- : new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);
5143
- }
5144
- mustMoveInline() {
5145
- if (!this.$to.parent.isTextblock)
5146
- return -1;
5147
- let top = this.frontier[this.depth], level;
5148
- if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) ||
5149
- (this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth))
5150
- return -1;
5151
- let { depth } = this.$to, after = this.$to.after(depth);
5152
- while (depth > 1 && after == this.$to.end(--depth))
5153
- ++after;
5154
- return after;
5155
- }
5156
- findCloseLevel($to) {
5157
- scan: for (let i = Math.min(this.depth, $to.depth); i >= 0; i--) {
5158
- let { match, type } = this.frontier[i];
5159
- let dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1));
5160
- let fit = contentAfterFits($to, i, type, match, dropInner);
5161
- if (!fit)
5162
- continue;
5163
- for (let d = i - 1; d >= 0; d--) {
5164
- let { match, type } = this.frontier[d];
5165
- let matches = contentAfterFits($to, d, type, match, true);
5166
- if (!matches || matches.childCount)
5167
- continue scan;
5168
- }
5169
- return { depth: i, fit, move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to };
5170
- }
5171
- }
5172
- close($to) {
5173
- let close = this.findCloseLevel($to);
5174
- if (!close)
5175
- return null;
5176
- while (this.depth > close.depth)
5177
- this.closeFrontierNode();
5178
- if (close.fit.childCount)
5179
- this.placed = addToFragment(this.placed, close.depth, close.fit);
5180
- $to = close.move;
5181
- for (let d = close.depth + 1; d <= $to.depth; d++) {
5182
- let node = $to.node(d), add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d));
5183
- this.openFrontierNode(node.type, node.attrs, add);
5184
- }
5185
- return $to;
5186
- }
5187
- openFrontierNode(type, attrs = null, content) {
5188
- let top = this.frontier[this.depth];
5189
- top.match = top.match.matchType(type);
5190
- this.placed = addToFragment(this.placed, this.depth, Fragment.from(type.create(attrs, content)));
5191
- this.frontier.push({ type, match: type.contentMatch });
5192
- }
5193
- closeFrontierNode() {
5194
- let open = this.frontier.pop();
5195
- let add = open.match.fillBefore(Fragment.empty, true);
5196
- if (add.childCount)
5197
- this.placed = addToFragment(this.placed, this.frontier.length, add);
5198
- }
5199
- }
5200
- function dropFromFragment(fragment, depth, count) {
5201
- if (depth == 0)
5202
- return fragment.cutByIndex(count, fragment.childCount);
5203
- return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count)));
5204
- }
5205
- function addToFragment(fragment, depth, content) {
5206
- if (depth == 0)
5207
- return fragment.append(content);
5208
- return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content)));
5209
- }
5210
- function contentAt(fragment, depth) {
5211
- for (let i = 0; i < depth; i++)
5212
- fragment = fragment.firstChild.content;
5213
- return fragment;
5214
- }
5215
- function closeNodeStart(node, openStart, openEnd) {
5216
- if (openStart <= 0)
5217
- return node;
5218
- let frag = node.content;
5219
- if (openStart > 1)
5220
- frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0));
5221
- if (openStart > 0) {
5222
- frag = node.type.contentMatch.fillBefore(frag).append(frag);
5223
- if (openEnd <= 0)
5224
- frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(Fragment.empty, true));
5225
- }
5226
- return node.copy(frag);
5227
- }
5228
- function contentAfterFits($to, depth, type, match, open) {
5229
- let node = $to.node(depth), index = open ? $to.indexAfter(depth) : $to.index(depth);
5230
- if (index == node.childCount && !type.compatibleContent(node.type))
5231
- return null;
5232
- let fit = match.fillBefore(node.content, true, index);
5233
- return fit && !invalidMarks(type, node.content, index) ? fit : null;
5234
- }
5235
- function invalidMarks(type, fragment, start) {
5236
- for (let i = start; i < fragment.childCount; i++)
5237
- if (!type.allowsMarks(fragment.child(i).marks))
5238
- return true;
5239
- return false;
5240
- }
5241
- function definesContent(type) {
5242
- return type.spec.defining || type.spec.definingForContent;
5243
- }
5244
- function replaceRange(tr, from, to, slice) {
5245
- if (!slice.size)
5246
- return tr.deleteRange(from, to);
5247
- let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
5248
- if (fitsTrivially($from, $to, slice))
5249
- return tr.step(new ReplaceStep(from, to, slice));
5250
- let targetDepths = coveredDepths($from, $to);
5251
- // Can't replace the whole document, so remove 0 if it's present
5252
- if (targetDepths[targetDepths.length - 1] == 0)
5253
- targetDepths.pop();
5254
- // Negative numbers represent not expansion over the whole node at
5255
- // that depth, but replacing from $from.before(-D) to $to.pos.
5256
- let preferredTarget = -($from.depth + 1);
5257
- targetDepths.unshift(preferredTarget);
5258
- // This loop picks a preferred target depth, if one of the covering
5259
- // depths is not outside of a defining node, and adds negative
5260
- // depths for any depth that has $from at its start and does not
5261
- // cross a defining node.
5262
- for (let d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {
5263
- let spec = $from.node(d).type.spec;
5264
- if (spec.defining || spec.definingAsContext || spec.isolating)
5265
- break;
5266
- if (targetDepths.indexOf(d) > -1)
5267
- preferredTarget = d;
5268
- else if ($from.before(d) == pos)
5269
- targetDepths.splice(1, 0, -d);
5270
- }
5271
- // Try to fit each possible depth of the slice into each possible
5272
- // target depth, starting with the preferred depths.
5273
- let preferredTargetIndex = targetDepths.indexOf(preferredTarget);
5274
- let leftNodes = [], preferredDepth = slice.openStart;
5275
- for (let content = slice.content, i = 0;; i++) {
5276
- let node = content.firstChild;
5277
- leftNodes.push(node);
5278
- if (i == slice.openStart)
5279
- break;
5280
- content = node.content;
5281
- }
5282
- // Back up preferredDepth to cover defining textblocks directly
5283
- // above it, possibly skipping a non-defining textblock.
5284
- for (let d = preferredDepth - 1; d >= 0; d--) {
5285
- let leftNode = leftNodes[d], def = definesContent(leftNode.type);
5286
- if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1)))
5287
- preferredDepth = d;
5288
- else if (def || !leftNode.type.isTextblock)
5289
- break;
5290
- }
5291
- for (let j = slice.openStart; j >= 0; j--) {
5292
- let openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);
5293
- let insert = leftNodes[openDepth];
5294
- if (!insert)
5295
- continue;
5296
- for (let i = 0; i < targetDepths.length; i++) {
5297
- // Loop over possible expansion levels, starting with the
5298
- // preferred one
5299
- let targetDepth = targetDepths[(i + preferredTargetIndex) % targetDepths.length], expand = true;
5300
- if (targetDepth < 0) {
5301
- expand = false;
5302
- targetDepth = -targetDepth;
5303
- }
5304
- let parent = $from.node(targetDepth - 1), index = $from.index(targetDepth - 1);
5305
- if (parent.canReplaceWith(index, index, insert.type, insert.marks))
5306
- return tr.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new Slice(closeFragment(slice.content, 0, slice.openStart, openDepth), openDepth, slice.openEnd));
5307
- }
5308
- }
5309
- let startSteps = tr.steps.length;
5310
- for (let i = targetDepths.length - 1; i >= 0; i--) {
5311
- tr.replace(from, to, slice);
5312
- if (tr.steps.length > startSteps)
5313
- break;
5314
- let depth = targetDepths[i];
5315
- if (depth < 0)
5316
- continue;
5317
- from = $from.before(depth);
5318
- to = $to.after(depth);
5319
- }
5320
- }
5321
- function closeFragment(fragment, depth, oldOpen, newOpen, parent) {
5322
- if (depth < oldOpen) {
5323
- let first = fragment.firstChild;
5324
- fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first)));
5325
- }
5326
- if (depth > newOpen) {
5327
- let match = parent.contentMatchAt(0);
5328
- let start = match.fillBefore(fragment).append(fragment);
5329
- fragment = start.append(match.matchFragment(start).fillBefore(Fragment.empty, true));
5330
- }
5331
- return fragment;
5332
- }
5333
- function replaceRangeWith(tr, from, to, node) {
5334
- if (!node.isInline && from == to && tr.doc.resolve(from).parent.content.size) {
5335
- let point = insertPoint(tr.doc, from, node.type);
5336
- if (point != null)
5337
- from = to = point;
5338
- }
5339
- tr.replaceRange(from, to, new Slice(Fragment.from(node), 0, 0));
5340
- }
5341
- function deleteRange(tr, from, to) {
5342
- let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
5343
- // When the deleted range spans from the start of one textblock to
5344
- // the start of another one, move out of the start of both blocks.
5345
- if ($from.parent.isTextblock && $to.parent.isTextblock && $from.start() != $to.start() &&
5346
- $from.parentOffset == 0 && $to.parentOffset == 0) {
5347
- let shared = $from.sharedDepth(to), isolated = false;
5348
- for (let d = $from.depth; d > shared; d--)
5349
- if ($from.node(d).type.spec.isolating)
5350
- isolated = true;
5351
- for (let d = $to.depth; d > shared; d--)
5352
- if ($to.node(d).type.spec.isolating)
5353
- isolated = true;
5354
- if (!isolated) {
5355
- for (let d = $from.depth; d > 0 && from == $from.start(d); d--)
5356
- from = $from.before(d);
5357
- for (let d = $to.depth; d > 0 && to == $to.start(d); d--)
5358
- to = $to.before(d);
5359
- $from = tr.doc.resolve(from);
5360
- $to = tr.doc.resolve(to);
5361
- }
5362
- }
5363
- let covered = coveredDepths($from, $to);
5364
- for (let i = 0; i < covered.length; i++) {
5365
- let depth = covered[i], last = i == covered.length - 1;
5366
- if ((last && depth == 0) || $from.node(depth).type.contentMatch.validEnd)
5367
- return tr.delete($from.start(depth), $to.end(depth));
5368
- if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1))))
5369
- return tr.delete($from.before(depth), $to.after(depth));
5370
- }
5371
- for (let d = 1; d <= $from.depth && d <= $to.depth; d++) {
5372
- if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d &&
5373
- $from.start(d - 1) == $to.start(d - 1) && $from.node(d - 1).canReplace($from.index(d - 1), $to.index(d - 1)))
5374
- return tr.delete($from.before(d), to);
5375
- }
5376
- tr.delete(from, to);
5377
- }
5378
- // Returns an array of all depths for which $from - $to spans the
5379
- // whole content of the nodes at that depth.
5380
- function coveredDepths($from, $to) {
5381
- let result = [], minDepth = Math.min($from.depth, $to.depth);
5382
- for (let d = minDepth; d >= 0; d--) {
5383
- let start = $from.start(d);
5384
- if (start < $from.pos - ($from.depth - d) ||
5385
- $to.end(d) > $to.pos + ($to.depth - d) ||
5386
- $from.node(d).type.spec.isolating ||
5387
- $to.node(d).type.spec.isolating)
5388
- break;
5389
- if (start == $to.start(d) ||
5390
- (d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent &&
5391
- d && $to.start(d - 1) == start - 1))
5392
- result.push(d);
5393
- }
5394
- return result;
5395
- }
5396
-
5397
- /**
5398
- Update an attribute in a specific node.
5399
- */
5400
- class AttrStep extends Step {
5401
- /**
5402
- Construct an attribute step.
5403
- */
5404
- constructor(
5405
- /**
5406
- The position of the target node.
5407
- */
5408
- pos,
5409
- /**
5410
- The attribute to set.
5411
- */
5412
- attr,
5413
- // The attribute's new value.
5414
- value) {
5415
- super();
5416
- this.pos = pos;
5417
- this.attr = attr;
5418
- this.value = value;
5419
- }
5420
- apply(doc) {
5421
- let node = doc.nodeAt(this.pos);
5422
- if (!node)
5423
- return StepResult.fail("No node at attribute step's position");
5424
- let attrs = Object.create(null);
5425
- for (let name in node.attrs)
5426
- attrs[name] = node.attrs[name];
5427
- attrs[this.attr] = this.value;
5428
- let updated = node.type.create(attrs, null, node.marks);
5429
- return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
5430
- }
5431
- getMap() {
5432
- return StepMap.empty;
5433
- }
5434
- invert(doc) {
5435
- return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
5436
- }
5437
- map(mapping) {
5438
- let pos = mapping.mapResult(this.pos, 1);
5439
- return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);
5440
- }
5441
- toJSON() {
5442
- return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
5443
- }
5444
- static fromJSON(schema, json) {
5445
- if (typeof json.pos != "number" || typeof json.attr != "string")
5446
- throw new RangeError("Invalid input for AttrStep.fromJSON");
5447
- return new AttrStep(json.pos, json.attr, json.value);
5448
- }
5449
- }
5450
- Step.jsonID("attr", AttrStep);
5451
- /**
5452
- Update an attribute in the doc node.
5453
- */
5454
- class DocAttrStep extends Step {
5455
- /**
5456
- Construct an attribute step.
5457
- */
5458
- constructor(
5459
- /**
5460
- The attribute to set.
5461
- */
5462
- attr,
5463
- // The attribute's new value.
5464
- value) {
5465
- super();
5466
- this.attr = attr;
5467
- this.value = value;
5468
- }
5469
- apply(doc) {
5470
- let attrs = Object.create(null);
5471
- for (let name in doc.attrs)
5472
- attrs[name] = doc.attrs[name];
5473
- attrs[this.attr] = this.value;
5474
- let updated = doc.type.create(attrs, doc.content, doc.marks);
5475
- return StepResult.ok(updated);
5476
- }
5477
- getMap() {
5478
- return StepMap.empty;
5479
- }
5480
- invert(doc) {
5481
- return new DocAttrStep(this.attr, doc.attrs[this.attr]);
5482
- }
5483
- map(mapping) {
5484
- return this;
5485
- }
5486
- toJSON() {
5487
- return { stepType: "docAttr", attr: this.attr, value: this.value };
5488
- }
5489
- static fromJSON(schema, json) {
5490
- if (typeof json.attr != "string")
5491
- throw new RangeError("Invalid input for DocAttrStep.fromJSON");
5492
- return new DocAttrStep(json.attr, json.value);
5493
- }
5494
- }
5495
- Step.jsonID("docAttr", DocAttrStep);
5496
-
5497
- /**
5498
- @internal
5499
- */
5500
- let TransformError = class extends Error {
5501
- };
5502
- TransformError = function TransformError(message) {
5503
- let err = Error.call(this, message);
5504
- err.__proto__ = TransformError.prototype;
5505
- return err;
5506
- };
5507
- TransformError.prototype = Object.create(Error.prototype);
5508
- TransformError.prototype.constructor = TransformError;
5509
- TransformError.prototype.name = "TransformError";
5510
- /**
5511
- Abstraction to build up and track an array of
5512
- [steps](https://prosemirror.net/docs/ref/#transform.Step) representing a document transformation.
5513
-
5514
- Most transforming methods return the `Transform` object itself, so
5515
- that they can be chained.
5516
- */
5517
- class Transform {
5518
- /**
5519
- Create a transform that starts with the given document.
5520
- */
5521
- constructor(
5522
- /**
5523
- The current document (the result of applying the steps in the
5524
- transform).
5525
- */
5526
- doc) {
5527
- this.doc = doc;
5528
- /**
5529
- The steps in this transform.
5530
- */
5531
- this.steps = [];
5532
- /**
5533
- The documents before each of the steps.
5534
- */
5535
- this.docs = [];
5536
- /**
5537
- A mapping with the maps for each of the steps in this transform.
5538
- */
5539
- this.mapping = new Mapping;
5540
- }
5541
- /**
5542
- The starting document.
5543
- */
5544
- get before() { return this.docs.length ? this.docs[0] : this.doc; }
5545
- /**
5546
- Apply a new step in this transform, saving the result. Throws an
5547
- error when the step fails.
5548
- */
5549
- step(step) {
5550
- let result = this.maybeStep(step);
5551
- if (result.failed)
5552
- throw new TransformError(result.failed);
5553
- return this;
5554
- }
5555
- /**
5556
- Try to apply a step in this transformation, ignoring it if it
5557
- fails. Returns the step result.
5558
- */
5559
- maybeStep(step) {
5560
- let result = step.apply(this.doc);
5561
- if (!result.failed)
5562
- this.addStep(step, result.doc);
5563
- return result;
5564
- }
5565
- /**
5566
- True when the document has been changed (when there are any
5567
- steps).
5568
- */
5569
- get docChanged() {
5570
- return this.steps.length > 0;
5571
- }
5572
- /**
5573
- Return a single range, in post-transform document positions,
5574
- that covers all content changed by this transform. Returns null
5575
- if no replacements are made. Note that this will ignore changes
5576
- that add/remove marks without replacing the underlying content.
5577
- */
5578
- changedRange() {
5579
- let from = 1e9, to = -1e9;
5580
- for (let i = 0; i < this.mapping.maps.length; i++) {
5581
- let map = this.mapping.maps[i];
5582
- if (i) {
5583
- from = map.map(from, 1);
5584
- to = map.map(to, -1);
5585
- }
5586
- map.forEach((_f, _t, fromB, toB) => {
5587
- from = Math.min(from, fromB);
5588
- to = Math.max(to, toB);
5589
- });
5590
- }
5591
- return from == 1e9 ? null : { from, to };
5592
- }
5593
- /**
5594
- @internal
5595
- */
5596
- addStep(step, doc) {
5597
- this.docs.push(this.doc);
5598
- this.steps.push(step);
5599
- this.mapping.appendMap(step.getMap());
5600
- this.doc = doc;
5601
- }
5602
- /**
5603
- Replace the part of the document between `from` and `to` with the
5604
- given `slice`.
5605
- */
5606
- replace(from, to = from, slice = Slice.empty) {
5607
- let step = replaceStep(this.doc, from, to, slice);
5608
- if (step)
5609
- this.step(step);
5610
- return this;
5611
- }
5612
- /**
5613
- Replace the given range with the given content, which may be a
5614
- fragment, node, or array of nodes.
5615
- */
5616
- replaceWith(from, to, content) {
5617
- return this.replace(from, to, new Slice(Fragment.from(content), 0, 0));
5618
- }
5619
- /**
5620
- Delete the content between the given positions.
5621
- */
5622
- delete(from, to) {
5623
- return this.replace(from, to, Slice.empty);
5624
- }
5625
- /**
5626
- Insert the given content at the given position.
5627
- */
5628
- insert(pos, content) {
5629
- return this.replaceWith(pos, pos, content);
5630
- }
5631
- /**
5632
- Replace a range of the document with a given slice, using
5633
- `from`, `to`, and the slice's
5634
- [`openStart`](https://prosemirror.net/docs/ref/#model.Slice.openStart) property as hints, rather
5635
- than fixed start and end points. This method may grow the
5636
- replaced area or close open nodes in the slice in order to get a
5637
- fit that is more in line with WYSIWYG expectations, by dropping
5638
- fully covered parent nodes of the replaced region when they are
5639
- marked [non-defining as
5640
- context](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext), or including an
5641
- open parent node from the slice that _is_ marked as [defining
5642
- its content](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).
5643
-
5644
- This is the method, for example, to handle paste. The similar
5645
- [`replace`](https://prosemirror.net/docs/ref/#transform.Transform.replace) method is a more
5646
- primitive tool which will _not_ move the start and end of its given
5647
- range, and is useful in situations where you need more precise
5648
- control over what happens.
5649
- */
5650
- replaceRange(from, to, slice) {
5651
- replaceRange(this, from, to, slice);
5652
- return this;
5653
- }
5654
- /**
5655
- Replace the given range with a node, but use `from` and `to` as
5656
- hints, rather than precise positions. When from and to are the same
5657
- and are at the start or end of a parent node in which the given
5658
- node doesn't fit, this method may _move_ them out towards a parent
5659
- that does allow the given node to be placed. When the given range
5660
- completely covers a parent node, this method may completely replace
5661
- that parent node.
5662
- */
5663
- replaceRangeWith(from, to, node) {
5664
- replaceRangeWith(this, from, to, node);
5665
- return this;
5666
- }
5667
- /**
5668
- Delete the given range, expanding it to cover fully covered
5669
- parent nodes until a valid replace is found.
5670
- */
5671
- deleteRange(from, to) {
5672
- deleteRange(this, from, to);
5673
- return this;
5674
- }
5675
- /**
5676
- Split the content in the given range off from its parent, if there
5677
- is sibling content before or after it, and move it up the tree to
5678
- the depth specified by `target`. You'll probably want to use
5679
- [`liftTarget`](https://prosemirror.net/docs/ref/#transform.liftTarget) to compute `target`, to make
5680
- sure the lift is valid.
5681
- */
5682
- lift(range, target) {
5683
- lift(this, range, target);
5684
- return this;
5685
- }
5686
- /**
5687
- Join the blocks around the given position. If depth is 2, their
5688
- last and first siblings are also joined, and so on.
5689
- */
5690
- join(pos, depth = 1) {
5691
- join(this, pos, depth);
5692
- return this;
5693
- }
5694
- /**
5695
- Wrap the given [range](https://prosemirror.net/docs/ref/#model.NodeRange) in the given set of wrappers.
5696
- The wrappers are assumed to be valid in this position, and should
5697
- probably be computed with [`findWrapping`](https://prosemirror.net/docs/ref/#transform.findWrapping).
5698
- */
5699
- wrap(range, wrappers) {
5700
- wrap(this, range, wrappers);
5701
- return this;
5702
- }
5703
- /**
5704
- Set the type of all textblocks (partly) between `from` and `to` to
5705
- the given node type with the given attributes.
5706
- */
5707
- setBlockType(from, to = from, type, attrs = null) {
5708
- setBlockType(this, from, to, type, attrs);
5709
- return this;
5710
- }
5711
- /**
5712
- Change the type, attributes, and/or marks of the node at `pos`.
5713
- When `type` isn't given, the existing node type is preserved,
5714
- */
5715
- setNodeMarkup(pos, type, attrs = null, marks) {
5716
- setNodeMarkup(this, pos, type, attrs, marks);
5717
- return this;
5718
- }
5719
- /**
5720
- Set a single attribute on a given node to a new value.
5721
- The `pos` addresses the document content. Use `setDocAttribute`
5722
- to set attributes on the document itself.
5723
- */
5724
- setNodeAttribute(pos, attr, value) {
5725
- this.step(new AttrStep(pos, attr, value));
5726
- return this;
5727
- }
5728
- /**
5729
- Set a single attribute on the document to a new value.
5730
- */
5731
- setDocAttribute(attr, value) {
5732
- this.step(new DocAttrStep(attr, value));
5733
- return this;
5734
- }
5735
- /**
5736
- Add a mark to the node at position `pos`.
5737
- */
5738
- addNodeMark(pos, mark) {
5739
- this.step(new AddNodeMarkStep(pos, mark));
5740
- return this;
5741
- }
5742
- /**
5743
- Remove a mark (or all marks of the given type) from the node at
5744
- position `pos`.
5745
- */
5746
- removeNodeMark(pos, mark) {
5747
- let node = this.doc.nodeAt(pos);
5748
- if (!node)
5749
- throw new RangeError("No node at position " + pos);
5750
- if (mark instanceof Mark) {
5751
- if (mark.isInSet(node.marks))
5752
- this.step(new RemoveNodeMarkStep(pos, mark));
5753
- }
5754
- else {
5755
- let set = node.marks, found, steps = [];
5756
- while (found = mark.isInSet(set)) {
5757
- steps.push(new RemoveNodeMarkStep(pos, found));
5758
- set = found.removeFromSet(set);
5759
- }
5760
- for (let i = steps.length - 1; i >= 0; i--)
5761
- this.step(steps[i]);
5762
- }
5763
- return this;
5764
- }
5765
- /**
5766
- Split the node at the given position, and optionally, if `depth` is
5767
- greater than one, any number of nodes above that. By default, the
5768
- parts split off will inherit the node type of the original node.
5769
- This can be changed by passing an array of types and attributes to
5770
- use after the split (with the outermost nodes coming first).
5771
- */
5772
- split(pos, depth = 1, typesAfter) {
5773
- split(this, pos, depth, typesAfter);
5774
- return this;
5775
- }
5776
- /**
5777
- Add the given mark to the inline content between `from` and `to`.
5778
- */
5779
- addMark(from, to, mark) {
5780
- addMark(this, from, to, mark);
5781
- return this;
5782
- }
5783
- /**
5784
- Remove marks from inline nodes between `from` and `to`. When
5785
- `mark` is a single mark, remove precisely that mark. When it is
5786
- a mark type, remove all marks of that type. When it is null,
5787
- remove all marks of any type.
5788
- */
5789
- removeMark(from, to, mark) {
5790
- removeMark(this, from, to, mark);
5791
- return this;
5792
- }
5793
- /**
5794
- Removes all marks and nodes from the content of the node at
5795
- `pos` that don't match the given new parent node type. Accepts
5796
- an optional starting [content match](https://prosemirror.net/docs/ref/#model.ContentMatch) as
5797
- third argument.
5798
- */
5799
- clearIncompatible(pos, parentType, match) {
5800
- clearIncompatible(this, pos, parentType, match);
5801
- return this;
5802
- }
5803
- }
5804
-
5805
- const classesById = Object.create(null);
5806
- /**
5807
- Superclass for editor selections. Every selection type should
5808
- extend this. Should not be instantiated directly.
5809
- */
5810
- class Selection {
5811
- /**
5812
- Initialize a selection with the head and anchor and ranges. If no
5813
- ranges are given, constructs a single range across `$anchor` and
5814
- `$head`.
5815
- */
5816
- constructor(
5817
- /**
5818
- The resolved anchor of the selection (the side that stays in
5819
- place when the selection is modified).
5820
- */
5821
- $anchor,
5822
- /**
5823
- The resolved head of the selection (the side that moves when
5824
- the selection is modified).
5825
- */
5826
- $head, ranges) {
5827
- this.$anchor = $anchor;
5828
- this.$head = $head;
5829
- this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))];
5830
- }
5831
- /**
5832
- The selection's anchor, as an unresolved position.
5833
- */
5834
- get anchor() { return this.$anchor.pos; }
5835
- /**
5836
- The selection's head.
5837
- */
5838
- get head() { return this.$head.pos; }
5839
- /**
5840
- The lower bound of the selection's main range.
5841
- */
5842
- get from() { return this.$from.pos; }
5843
- /**
5844
- The upper bound of the selection's main range.
5845
- */
5846
- get to() { return this.$to.pos; }
5847
- /**
5848
- The resolved lower bound of the selection's main range.
5849
- */
5850
- get $from() {
5851
- return this.ranges[0].$from;
5852
- }
5853
- /**
5854
- The resolved upper bound of the selection's main range.
5855
- */
5856
- get $to() {
5857
- return this.ranges[0].$to;
5858
- }
5859
- /**
5860
- Indicates whether the selection contains any content.
5861
- */
5862
- get empty() {
5863
- let ranges = this.ranges;
5864
- for (let i = 0; i < ranges.length; i++)
5865
- if (ranges[i].$from.pos != ranges[i].$to.pos)
5866
- return false;
5867
- return true;
5868
- }
5869
- /**
5870
- Get the content of this selection as a slice.
5871
- */
5872
- content() {
5873
- return this.$from.doc.slice(this.from, this.to, true);
5874
- }
5875
- /**
5876
- Replace the selection with a slice or, if no slice is given,
5877
- delete the selection. Will append to the given transaction.
5878
- */
5879
- replace(tr, content = Slice.empty) {
5880
- // Put the new selection at the position after the inserted
5881
- // content. When that ended in an inline node, search backwards,
5882
- // to get the position after that node. If not, search forward.
5883
- let lastNode = content.content.lastChild, lastParent = null;
5884
- for (let i = 0; i < content.openEnd; i++) {
5885
- lastParent = lastNode;
5886
- lastNode = lastNode.lastChild;
5887
- }
5888
- let mapFrom = tr.steps.length, ranges = this.ranges;
5889
- for (let i = 0; i < ranges.length; i++) {
5890
- let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
5891
- tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
5892
- if (i == 0)
5893
- selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1);
5894
- }
5895
- }
5896
- /**
5897
- Replace the selection with the given node, appending the changes
5898
- to the given transaction.
5899
- */
5900
- replaceWith(tr, node) {
5901
- let mapFrom = tr.steps.length, ranges = this.ranges;
5902
- for (let i = 0; i < ranges.length; i++) {
5903
- let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
5904
- let from = mapping.map($from.pos), to = mapping.map($to.pos);
5905
- if (i) {
5906
- tr.deleteRange(from, to);
5907
- }
5908
- else {
5909
- tr.replaceRangeWith(from, to, node);
5910
- selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1);
5911
- }
5912
- }
5913
- }
5914
- /**
5915
- Find a valid cursor or leaf node selection starting at the given
5916
- position and searching back if `dir` is negative, and forward if
5917
- positive. When `textOnly` is true, only consider cursor
5918
- selections. Will return null when no valid selection position is
5919
- found.
5920
- */
5921
- static findFrom($pos, dir, textOnly = false) {
5922
- let inner = $pos.parent.inlineContent ? new TextSelection($pos)
5923
- : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);
5924
- if (inner)
5925
- return inner;
5926
- for (let depth = $pos.depth - 1; depth >= 0; depth--) {
5927
- let found = dir < 0
5928
- ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly)
5929
- : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly);
5930
- if (found)
5931
- return found;
5932
- }
5933
- return null;
5934
- }
5935
- /**
5936
- Find a valid cursor or leaf node selection near the given
5937
- position. Searches forward first by default, but if `bias` is
5938
- negative, it will search backwards first.
5939
- */
5940
- static near($pos, bias = 1) {
5941
- return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0));
5942
- }
5943
- /**
5944
- Find the cursor or leaf node selection closest to the start of
5945
- the given document. Will return an
5946
- [`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position
5947
- exists.
5948
- */
5949
- static atStart(doc) {
5950
- return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc);
5951
- }
5952
- /**
5953
- Find the cursor or leaf node selection closest to the end of the
5954
- given document.
5955
- */
5956
- static atEnd(doc) {
5957
- return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc);
5958
- }
5959
- /**
5960
- Deserialize the JSON representation of a selection. Must be
5961
- implemented for custom classes (as a static class method).
5962
- */
5963
- static fromJSON(doc, json) {
5964
- if (!json || !json.type)
5965
- throw new RangeError("Invalid input for Selection.fromJSON");
5966
- let cls = classesById[json.type];
5967
- if (!cls)
5968
- throw new RangeError(`No selection type ${json.type} defined`);
5969
- return cls.fromJSON(doc, json);
5970
- }
5971
- /**
5972
- To be able to deserialize selections from JSON, custom selection
5973
- classes must register themselves with an ID string, so that they
5974
- can be disambiguated. Try to pick something that's unlikely to
5975
- clash with classes from other modules.
5976
- */
5977
- static jsonID(id, selectionClass) {
5978
- if (id in classesById)
5979
- throw new RangeError("Duplicate use of selection JSON ID " + id);
5980
- classesById[id] = selectionClass;
5981
- selectionClass.prototype.jsonID = id;
5982
- return selectionClass;
5983
- }
5984
- /**
5985
- Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection,
5986
- which is a value that can be mapped without having access to a
5987
- current document, and later resolved to a real selection for a
5988
- given document again. (This is used mostly by the history to
5989
- track and restore old selections.) The default implementation of
5990
- this method just converts the selection to a text selection and
5991
- returns the bookmark for that.
5992
- */
5993
- getBookmark() {
5994
- return TextSelection.between(this.$anchor, this.$head).getBookmark();
5995
- }
5996
- }
5997
- Selection.prototype.visible = true;
5998
- /**
5999
- Represents a selected range in a document.
6000
- */
6001
- class SelectionRange {
6002
- /**
6003
- Create a range.
6004
- */
6005
- constructor(
6006
- /**
6007
- The lower bound of the range.
6008
- */
6009
- $from,
6010
- /**
6011
- The upper bound of the range.
6012
- */
6013
- $to) {
6014
- this.$from = $from;
6015
- this.$to = $to;
6016
- }
6017
- }
6018
- let warnedAboutTextSelection = false;
6019
- function checkTextSelection($pos) {
6020
- if (!warnedAboutTextSelection && !$pos.parent.inlineContent) {
6021
- warnedAboutTextSelection = true;
6022
- console["warn"]("TextSelection endpoint not pointing into a node with inline content (" + $pos.parent.type.name + ")");
6023
- }
6024
- }
6025
- /**
6026
- A text selection represents a classical editor selection, with a
6027
- head (the moving side) and anchor (immobile side), both of which
6028
- point into textblock nodes. It can be empty (a regular cursor
6029
- position).
6030
- */
6031
- class TextSelection extends Selection {
6032
- /**
6033
- Construct a text selection between the given points.
6034
- */
6035
- constructor($anchor, $head = $anchor) {
6036
- checkTextSelection($anchor);
6037
- checkTextSelection($head);
6038
- super($anchor, $head);
6039
- }
6040
- /**
6041
- Returns a resolved position if this is a cursor selection (an
6042
- empty text selection), and null otherwise.
6043
- */
6044
- get $cursor() { return this.$anchor.pos == this.$head.pos ? this.$head : null; }
6045
- map(doc, mapping) {
6046
- let $head = doc.resolve(mapping.map(this.head));
6047
- if (!$head.parent.inlineContent)
6048
- return Selection.near($head);
6049
- let $anchor = doc.resolve(mapping.map(this.anchor));
6050
- return new TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head);
6051
- }
6052
- replace(tr, content = Slice.empty) {
6053
- super.replace(tr, content);
6054
- if (content == Slice.empty) {
6055
- let marks = this.$from.marksAcross(this.$to);
6056
- if (marks)
6057
- tr.ensureMarks(marks);
6058
- }
6059
- }
6060
- eq(other) {
6061
- return other instanceof TextSelection && other.anchor == this.anchor && other.head == this.head;
6062
- }
6063
- getBookmark() {
6064
- return new TextBookmark(this.anchor, this.head);
6065
- }
6066
- toJSON() {
6067
- return { type: "text", anchor: this.anchor, head: this.head };
6068
- }
6069
- /**
6070
- @internal
6071
- */
6072
- static fromJSON(doc, json) {
6073
- if (typeof json.anchor != "number" || typeof json.head != "number")
6074
- throw new RangeError("Invalid input for TextSelection.fromJSON");
6075
- return new TextSelection(doc.resolve(json.anchor), doc.resolve(json.head));
6076
- }
6077
- /**
6078
- Create a text selection from non-resolved positions.
6079
- */
6080
- static create(doc, anchor, head = anchor) {
6081
- let $anchor = doc.resolve(anchor);
6082
- return new this($anchor, head == anchor ? $anchor : doc.resolve(head));
6083
- }
6084
- /**
6085
- Return a text selection that spans the given positions or, if
6086
- they aren't text positions, find a text selection near them.
6087
- `bias` determines whether the method searches forward (default)
6088
- or backwards (negative number) first. Will fall back to calling
6089
- [`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document
6090
- doesn't contain a valid text position.
6091
- */
6092
- static between($anchor, $head, bias) {
6093
- let dPos = $anchor.pos - $head.pos;
6094
- if (!bias || dPos)
6095
- bias = dPos >= 0 ? 1 : -1;
6096
- if (!$head.parent.inlineContent) {
6097
- let found = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true);
6098
- if (found)
6099
- $head = found.$head;
6100
- else
6101
- return Selection.near($head, bias);
6102
- }
6103
- if (!$anchor.parent.inlineContent) {
6104
- if (dPos == 0) {
6105
- $anchor = $head;
6106
- }
6107
- else {
6108
- $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor;
6109
- if (($anchor.pos < $head.pos) != (dPos < 0))
6110
- $anchor = $head;
6111
- }
6112
- }
6113
- return new TextSelection($anchor, $head);
6114
- }
6115
- }
6116
- Selection.jsonID("text", TextSelection);
6117
- class TextBookmark {
6118
- constructor(anchor, head) {
6119
- this.anchor = anchor;
6120
- this.head = head;
6121
- }
6122
- map(mapping) {
6123
- return new TextBookmark(mapping.map(this.anchor), mapping.map(this.head));
6124
- }
6125
- resolve(doc) {
6126
- return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head));
6127
- }
6128
- }
6129
- /**
6130
- A node selection is a selection that points at a single node. All
6131
- nodes marked [selectable](https://prosemirror.net/docs/ref/#model.NodeSpec.selectable) can be the
6132
- target of a node selection. In such a selection, `from` and `to`
6133
- point directly before and after the selected node, `anchor` equals
6134
- `from`, and `head` equals `to`..
6135
- */
6136
- class NodeSelection extends Selection {
6137
- /**
6138
- Create a node selection. Does not verify the validity of its
6139
- argument.
6140
- */
6141
- constructor($pos) {
6142
- let node = $pos.nodeAfter;
6143
- let $end = $pos.node(0).resolve($pos.pos + node.nodeSize);
6144
- super($pos, $end);
6145
- this.node = node;
6146
- }
6147
- map(doc, mapping) {
6148
- let { deleted, pos } = mapping.mapResult(this.anchor);
6149
- let $pos = doc.resolve(pos);
6150
- if (deleted)
6151
- return Selection.near($pos);
6152
- return new NodeSelection($pos);
6153
- }
6154
- content() {
6155
- return new Slice(Fragment.from(this.node), 0, 0);
6156
- }
6157
- eq(other) {
6158
- return other instanceof NodeSelection && other.anchor == this.anchor;
6159
- }
6160
- toJSON() {
6161
- return { type: "node", anchor: this.anchor };
6162
- }
6163
- getBookmark() { return new NodeBookmark(this.anchor); }
6164
- /**
6165
- @internal
6166
- */
6167
- static fromJSON(doc, json) {
6168
- if (typeof json.anchor != "number")
6169
- throw new RangeError("Invalid input for NodeSelection.fromJSON");
6170
- return new NodeSelection(doc.resolve(json.anchor));
6171
- }
6172
- /**
6173
- Create a node selection from non-resolved positions.
6174
- */
6175
- static create(doc, from) {
6176
- return new NodeSelection(doc.resolve(from));
6177
- }
6178
- /**
6179
- Determines whether the given node may be selected as a node
6180
- selection.
6181
- */
6182
- static isSelectable(node) {
6183
- return !node.isText && node.type.spec.selectable !== false;
6184
- }
6185
- }
6186
- NodeSelection.prototype.visible = false;
6187
- Selection.jsonID("node", NodeSelection);
6188
- class NodeBookmark {
6189
- constructor(anchor) {
6190
- this.anchor = anchor;
6191
- }
6192
- map(mapping) {
6193
- let { deleted, pos } = mapping.mapResult(this.anchor);
6194
- return deleted ? new TextBookmark(pos, pos) : new NodeBookmark(pos);
6195
- }
6196
- resolve(doc) {
6197
- let $pos = doc.resolve(this.anchor), node = $pos.nodeAfter;
6198
- if (node && NodeSelection.isSelectable(node))
6199
- return new NodeSelection($pos);
6200
- return Selection.near($pos);
6201
- }
6202
- }
6203
- /**
6204
- A selection type that represents selecting the whole document
6205
- (which can not necessarily be expressed with a text selection, when
6206
- there are for example leaf block nodes at the start or end of the
6207
- document).
6208
- */
6209
- class AllSelection extends Selection {
6210
- /**
6211
- Create an all-selection over the given document.
6212
- */
6213
- constructor(doc) {
6214
- super(doc.resolve(0), doc.resolve(doc.content.size));
6215
- }
6216
- replace(tr, content = Slice.empty) {
6217
- if (content == Slice.empty) {
6218
- tr.delete(0, tr.doc.content.size);
6219
- let sel = Selection.atStart(tr.doc);
6220
- if (!sel.eq(tr.selection))
6221
- tr.setSelection(sel);
6222
- }
6223
- else {
6224
- super.replace(tr, content);
6225
- }
6226
- }
6227
- toJSON() { return { type: "all" }; }
6228
- /**
6229
- @internal
6230
- */
6231
- static fromJSON(doc) { return new AllSelection(doc); }
6232
- map(doc) { return new AllSelection(doc); }
6233
- eq(other) { return other instanceof AllSelection; }
6234
- getBookmark() { return AllBookmark; }
6235
- }
6236
- Selection.jsonID("all", AllSelection);
6237
- const AllBookmark = {
6238
- map() { return this; },
6239
- resolve(doc) { return new AllSelection(doc); }
3732
+ }
3733
+ });
3734
+ var isMarkdown = function isMarkdown(text) {
3735
+ return MARKDOWN_PATTERNS.some(function (pattern) {
3736
+ return pattern.test(text);
3737
+ });
3738
+ };
3739
+ var markdownToHtml = markdown.parse;
3740
+ var markdownToSlice = function markdownToSlice(text, schema, context) {
3741
+ var body = new DOMParser().parseFromString(markdownToHtml(text), "text/html").body;
3742
+ return DOMParser$1.fromSchema(schema).parseSlice(body, {
3743
+ context: context
3744
+ });
6240
3745
  };
6241
- // FIXME we'll need some awareness of text direction when scanning for selections
6242
- // Try to find a selection inside the given node. `pos` points at the
6243
- // position where the search starts. When `text` is true, only return
6244
- // text selections.
6245
- function findSelectionIn(doc, node, pos, index, dir, text = false) {
6246
- if (node.inlineContent)
6247
- return TextSelection.create(doc, pos);
6248
- for (let i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) {
6249
- let child = node.child(i);
6250
- if (!child.isAtom) {
6251
- let inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text);
6252
- if (inner)
6253
- return inner;
6254
- }
6255
- else if (!text && NodeSelection.isSelectable(child)) {
6256
- return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0));
6257
- }
6258
- pos += child.nodeSize * dir;
6259
- }
6260
- return null;
6261
- }
6262
- function selectionToInsertionEnd(tr, startLen, bias) {
6263
- let last = tr.steps.length - 1;
6264
- if (last < startLen)
6265
- return;
6266
- let step = tr.steps[last];
6267
- if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))
6268
- return;
6269
- let map = tr.mapping.maps[last], end;
6270
- map.forEach((_from, _to, _newFrom, newTo) => { if (end == null)
6271
- end = newTo; });
6272
- tr.setSelection(Selection.near(tr.doc.resolve(end), bias));
6273
- }
6274
-
6275
- const UPDATED_SEL = 1, UPDATED_MARKS = 2, UPDATED_SCROLL = 4;
6276
- /**
6277
- An editor state transaction, which can be applied to a state to
6278
- create an updated state. Use
6279
- [`EditorState.tr`](https://prosemirror.net/docs/ref/#state.EditorState.tr) to create an instance.
6280
-
6281
- Transactions track changes to the document (they are a subclass of
6282
- [`Transform`](https://prosemirror.net/docs/ref/#transform.Transform)), but also other state changes,
6283
- like selection updates and adjustments of the set of [stored
6284
- marks](https://prosemirror.net/docs/ref/#state.EditorState.storedMarks). In addition, you can store
6285
- metadata properties in a transaction, which are extra pieces of
6286
- information that client code or plugins can use to describe what a
6287
- transaction represents, so that they can update their [own
6288
- state](https://prosemirror.net/docs/ref/#state.StateField) accordingly.
6289
-
6290
- The [editor view](https://prosemirror.net/docs/ref/#view.EditorView) uses a few metadata
6291
- properties: it will attach a property `"pointer"` with the value
6292
- `true` to selection transactions directly caused by mouse or touch
6293
- input, a `"composition"` property holding an ID identifying the
6294
- composition that caused it to transactions caused by composed DOM
6295
- input, and a `"uiEvent"` property of that may be `"paste"`,
6296
- `"cut"`, or `"drop"`.
6297
- */
6298
- class Transaction extends Transform {
6299
- /**
6300
- @internal
6301
- */
6302
- constructor(state) {
6303
- super(state.doc);
6304
- // The step count for which the current selection is valid.
6305
- this.curSelectionFor = 0;
6306
- // Bitfield to track which aspects of the state were updated by
6307
- // this transaction.
6308
- this.updated = 0;
6309
- // Object used to store metadata properties for the transaction.
6310
- this.meta = Object.create(null);
6311
- this.time = Date.now();
6312
- this.curSelection = state.selection;
6313
- this.storedMarks = state.storedMarks;
6314
- }
6315
- /**
6316
- The transaction's current selection. This defaults to the editor
6317
- selection [mapped](https://prosemirror.net/docs/ref/#state.Selection.map) through the steps in the
6318
- transaction, but can be overwritten with
6319
- [`setSelection`](https://prosemirror.net/docs/ref/#state.Transaction.setSelection).
6320
- */
6321
- get selection() {
6322
- if (this.curSelectionFor < this.steps.length) {
6323
- this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor));
6324
- this.curSelectionFor = this.steps.length;
6325
- }
6326
- return this.curSelection;
6327
- }
6328
- /**
6329
- Update the transaction's current selection. Will determine the
6330
- selection that the editor gets when the transaction is applied.
6331
- */
6332
- setSelection(selection) {
6333
- if (selection.$from.doc != this.doc)
6334
- throw new RangeError("Selection passed to setSelection must point at the current document");
6335
- this.curSelection = selection;
6336
- this.curSelectionFor = this.steps.length;
6337
- this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS;
6338
- this.storedMarks = null;
6339
- return this;
6340
- }
6341
- /**
6342
- Whether the selection was explicitly updated by this transaction.
6343
- */
6344
- get selectionSet() {
6345
- return (this.updated & UPDATED_SEL) > 0;
6346
- }
6347
- /**
6348
- Set the current stored marks.
6349
- */
6350
- setStoredMarks(marks) {
6351
- this.storedMarks = marks;
6352
- this.updated |= UPDATED_MARKS;
6353
- return this;
6354
- }
6355
- /**
6356
- Make sure the current stored marks or, if that is null, the marks
6357
- at the selection, match the given set of marks. Does nothing if
6358
- this is already the case.
6359
- */
6360
- ensureMarks(marks) {
6361
- if (!Mark.sameSet(this.storedMarks || this.selection.$from.marks(), marks))
6362
- this.setStoredMarks(marks);
6363
- return this;
6364
- }
6365
- /**
6366
- Add a mark to the set of stored marks.
6367
- */
6368
- addStoredMark(mark) {
6369
- return this.ensureMarks(mark.addToSet(this.storedMarks || this.selection.$head.marks()));
6370
- }
6371
- /**
6372
- Remove a mark or mark type from the set of stored marks.
6373
- */
6374
- removeStoredMark(mark) {
6375
- return this.ensureMarks(mark.removeFromSet(this.storedMarks || this.selection.$head.marks()));
6376
- }
6377
- /**
6378
- Whether the stored marks were explicitly set for this transaction.
6379
- */
6380
- get storedMarksSet() {
6381
- return (this.updated & UPDATED_MARKS) > 0;
6382
- }
6383
- /**
6384
- @internal
6385
- */
6386
- addStep(step, doc) {
6387
- super.addStep(step, doc);
6388
- this.updated = this.updated & ~UPDATED_MARKS;
6389
- this.storedMarks = null;
6390
- }
6391
- /**
6392
- Update the timestamp for the transaction.
6393
- */
6394
- setTime(time) {
6395
- this.time = time;
6396
- return this;
6397
- }
6398
- /**
6399
- Replace the current selection with the given slice.
6400
- */
6401
- replaceSelection(slice) {
6402
- this.selection.replace(this, slice);
6403
- return this;
6404
- }
6405
- /**
6406
- Replace the selection with the given node. When `inheritMarks` is
6407
- true and the content is inline, it inherits the marks from the
6408
- place where it is inserted.
6409
- */
6410
- replaceSelectionWith(node, inheritMarks = true) {
6411
- let selection = this.selection;
6412
- if (inheritMarks)
6413
- node = node.mark(this.storedMarks || (selection.empty ? selection.$from.marks() : (selection.$from.marksAcross(selection.$to) || Mark.none)));
6414
- selection.replaceWith(this, node);
6415
- return this;
6416
- }
6417
- /**
6418
- Delete the selection.
6419
- */
6420
- deleteSelection() {
6421
- this.selection.replace(this);
6422
- return this;
6423
- }
6424
- /**
6425
- Replace the given range, or the selection if no range is given,
6426
- with a text node containing the given string.
6427
- */
6428
- insertText(text, from, to) {
6429
- let schema = this.doc.type.schema;
6430
- if (from == null) {
6431
- if (!text)
6432
- return this.deleteSelection();
6433
- return this.replaceSelectionWith(schema.text(text), true);
6434
- }
6435
- else {
6436
- if (to == null)
6437
- to = from;
6438
- if (!text)
6439
- return this.deleteRange(from, to);
6440
- let marks = this.storedMarks;
6441
- if (!marks) {
6442
- let $from = this.doc.resolve(from);
6443
- marks = to == from ? $from.marks() : $from.marksAcross(this.doc.resolve(to));
6444
- }
6445
- this.replaceRangeWith(from, to, schema.text(text, marks));
6446
- if (!this.selection.empty && this.selection.to == from + text.length)
6447
- this.setSelection(Selection.near(this.selection.$to));
6448
- return this;
6449
- }
6450
- }
6451
- /**
6452
- Store a metadata property in this transaction, keyed either by
6453
- name or by plugin.
6454
- */
6455
- setMeta(key, value) {
6456
- this.meta[typeof key == "string" ? key : key.key] = value;
6457
- return this;
6458
- }
6459
- /**
6460
- Retrieve a metadata property for a given name or plugin.
6461
- */
6462
- getMeta(key) {
6463
- return this.meta[typeof key == "string" ? key : key.key];
6464
- }
6465
- /**
6466
- Returns true if this transaction doesn't contain any metadata,
6467
- and can thus safely be extended.
6468
- */
6469
- get isGeneric() {
6470
- for (let _ in this.meta)
6471
- return false;
6472
- return true;
6473
- }
6474
- /**
6475
- Indicate that the editor should scroll the selection into view
6476
- when updated to the state produced by this transaction.
6477
- */
6478
- scrollIntoView() {
6479
- this.updated |= UPDATED_SCROLL;
6480
- return this;
6481
- }
6482
- /**
6483
- True when this transaction has had `scrollIntoView` called on it.
6484
- */
6485
- get scrolledIntoView() {
6486
- return (this.updated & UPDATED_SCROLL) > 0;
6487
- }
6488
- }
6489
-
6490
- function bind(f, self) {
6491
- return !self || !f ? f : f.bind(self);
6492
- }
6493
- class FieldDesc {
6494
- constructor(name, desc, self) {
6495
- this.name = name;
6496
- this.init = bind(desc.init, self);
6497
- this.apply = bind(desc.apply, self);
6498
- }
6499
- }
6500
- const baseFields = [
6501
- new FieldDesc("doc", {
6502
- init(config) { return config.doc || config.schema.topNodeType.createAndFill(); },
6503
- apply(tr) { return tr.doc; }
6504
- }),
6505
- new FieldDesc("selection", {
6506
- init(config, instance) { return config.selection || Selection.atStart(instance.doc); },
6507
- apply(tr) { return tr.selection; }
6508
- }),
6509
- new FieldDesc("storedMarks", {
6510
- init(config) { return config.storedMarks || null; },
6511
- apply(tr, _marks, _old, state) { return state.selection.$cursor ? tr.storedMarks : null; }
6512
- }),
6513
- new FieldDesc("scrollToSelection", {
6514
- init() { return 0; },
6515
- apply(tr, prev) { return tr.scrolledIntoView ? prev + 1 : prev; }
6516
- })
6517
- ];
6518
- // Object wrapping the part of a state object that stays the same
6519
- // across transactions. Stored in the state's `config` property.
6520
- class Configuration {
6521
- constructor(schema, plugins) {
6522
- this.schema = schema;
6523
- this.plugins = [];
6524
- this.pluginsByKey = Object.create(null);
6525
- this.fields = baseFields.slice();
6526
- if (plugins)
6527
- plugins.forEach(plugin => {
6528
- if (this.pluginsByKey[plugin.key])
6529
- throw new RangeError("Adding different instances of a keyed plugin (" + plugin.key + ")");
6530
- this.plugins.push(plugin);
6531
- this.pluginsByKey[plugin.key] = plugin;
6532
- if (plugin.spec.state)
6533
- this.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin));
6534
- });
6535
- }
6536
- }
6537
- /**
6538
- The state of a ProseMirror editor is represented by an object of
6539
- this type. A state is a persistent data structure—it isn't
6540
- updated, but rather a new state value is computed from an old one
6541
- using the [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) method.
6542
-
6543
- A state holds a number of built-in fields, and plugins can
6544
- [define](https://prosemirror.net/docs/ref/#state.PluginSpec.state) additional fields.
6545
- */
6546
- class EditorState {
6547
- /**
6548
- @internal
6549
- */
6550
- constructor(
6551
- /**
6552
- @internal
6553
- */
6554
- config) {
6555
- this.config = config;
6556
- }
6557
- /**
6558
- The schema of the state's document.
6559
- */
6560
- get schema() {
6561
- return this.config.schema;
6562
- }
6563
- /**
6564
- The plugins that are active in this state.
6565
- */
6566
- get plugins() {
6567
- return this.config.plugins;
6568
- }
6569
- /**
6570
- Apply the given transaction to produce a new state.
6571
- */
6572
- apply(tr) {
6573
- return this.applyTransaction(tr).state;
6574
- }
6575
- /**
6576
- @internal
6577
- */
6578
- filterTransaction(tr, ignore = -1) {
6579
- for (let i = 0; i < this.config.plugins.length; i++)
6580
- if (i != ignore) {
6581
- let plugin = this.config.plugins[i];
6582
- if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this))
6583
- return false;
6584
- }
6585
- return true;
6586
- }
6587
- /**
6588
- Verbose variant of [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) that
6589
- returns the precise transactions that were applied (which might
6590
- be influenced by the [transaction
6591
- hooks](https://prosemirror.net/docs/ref/#state.PluginSpec.filterTransaction) of
6592
- plugins) along with the new state.
6593
- */
6594
- applyTransaction(rootTr) {
6595
- if (!this.filterTransaction(rootTr))
6596
- return { state: this, transactions: [] };
6597
- let trs = [rootTr], newState = this.applyInner(rootTr), seen = null;
6598
- // This loop repeatedly gives plugins a chance to respond to
6599
- // transactions as new transactions are added, making sure to only
6600
- // pass the transactions the plugin did not see before.
6601
- for (;;) {
6602
- let haveNew = false;
6603
- for (let i = 0; i < this.config.plugins.length; i++) {
6604
- let plugin = this.config.plugins[i];
6605
- if (plugin.spec.appendTransaction) {
6606
- let n = seen ? seen[i].n : 0, oldState = seen ? seen[i].state : this;
6607
- let tr = n < trs.length &&
6608
- plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState);
6609
- if (tr && newState.filterTransaction(tr, i)) {
6610
- tr.setMeta("appendedTransaction", rootTr);
6611
- if (!seen) {
6612
- seen = [];
6613
- for (let j = 0; j < this.config.plugins.length; j++)
6614
- seen.push(j < i ? { state: newState, n: trs.length } : { state: this, n: 0 });
6615
- }
6616
- trs.push(tr);
6617
- newState = newState.applyInner(tr);
6618
- haveNew = true;
6619
- }
6620
- if (seen)
6621
- seen[i] = { state: newState, n: trs.length };
6622
- }
6623
- }
6624
- if (!haveNew)
6625
- return { state: newState, transactions: trs };
6626
- }
6627
- }
6628
- /**
6629
- @internal
6630
- */
6631
- applyInner(tr) {
6632
- if (!tr.before.eq(this.doc))
6633
- throw new RangeError("Applying a mismatched transaction");
6634
- let newInstance = new EditorState(this.config), fields = this.config.fields;
6635
- for (let i = 0; i < fields.length; i++) {
6636
- let field = fields[i];
6637
- newInstance[field.name] = field.apply(tr, this[field.name], this, newInstance);
6638
- }
6639
- return newInstance;
6640
- }
6641
- /**
6642
- Accessor that constructs and returns a new [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
6643
- */
6644
- get tr() { return new Transaction(this); }
6645
- /**
6646
- Create a new state.
6647
- */
6648
- static create(config) {
6649
- let $config = new Configuration(config.doc ? config.doc.type.schema : config.schema, config.plugins);
6650
- let instance = new EditorState($config);
6651
- for (let i = 0; i < $config.fields.length; i++)
6652
- instance[$config.fields[i].name] = $config.fields[i].init(config, instance);
6653
- return instance;
6654
- }
6655
- /**
6656
- Create a new state based on this one, but with an adjusted set
6657
- of active plugins. State fields that exist in both sets of
6658
- plugins are kept unchanged. Those that no longer exist are
6659
- dropped, and those that are new are initialized using their
6660
- [`init`](https://prosemirror.net/docs/ref/#state.StateField.init) method, passing in the new
6661
- configuration object..
6662
- */
6663
- reconfigure(config) {
6664
- let $config = new Configuration(this.schema, config.plugins);
6665
- let fields = $config.fields, instance = new EditorState($config);
6666
- for (let i = 0; i < fields.length; i++) {
6667
- let name = fields[i].name;
6668
- instance[name] = this.hasOwnProperty(name) ? this[name] : fields[i].init(config, instance);
6669
- }
6670
- return instance;
6671
- }
6672
- /**
6673
- Serialize this state to JSON. If you want to serialize the state
6674
- of plugins, pass an object mapping property names to use in the
6675
- resulting JSON object to plugin objects. The argument may also be
6676
- a string or number, in which case it is ignored, to support the
6677
- way `JSON.stringify` calls `toString` methods.
6678
- */
6679
- toJSON(pluginFields) {
6680
- let result = { doc: this.doc.toJSON(), selection: this.selection.toJSON() };
6681
- if (this.storedMarks)
6682
- result.storedMarks = this.storedMarks.map(m => m.toJSON());
6683
- if (pluginFields && typeof pluginFields == 'object')
6684
- for (let prop in pluginFields) {
6685
- if (prop == "doc" || prop == "selection")
6686
- throw new RangeError("The JSON fields `doc` and `selection` are reserved");
6687
- let plugin = pluginFields[prop], state = plugin.spec.state;
6688
- if (state && state.toJSON)
6689
- result[prop] = state.toJSON.call(plugin, this[plugin.key]);
6690
- }
6691
- return result;
6692
- }
6693
- /**
6694
- Deserialize a JSON representation of a state. `config` should
6695
- have at least a `schema` field, and should contain array of
6696
- plugins to initialize the state with. `pluginFields` can be used
6697
- to deserialize the state of plugins, by associating plugin
6698
- instances with the property names they use in the JSON object.
6699
- */
6700
- static fromJSON(config, json, pluginFields) {
6701
- if (!json)
6702
- throw new RangeError("Invalid input for EditorState.fromJSON");
6703
- if (!config.schema)
6704
- throw new RangeError("Required config field 'schema' missing");
6705
- let $config = new Configuration(config.schema, config.plugins);
6706
- let instance = new EditorState($config);
6707
- $config.fields.forEach(field => {
6708
- if (field.name == "doc") {
6709
- instance.doc = Node.fromJSON(config.schema, json.doc);
6710
- }
6711
- else if (field.name == "selection") {
6712
- instance.selection = Selection.fromJSON(instance.doc, json.selection);
6713
- }
6714
- else if (field.name == "storedMarks") {
6715
- if (json.storedMarks)
6716
- instance.storedMarks = json.storedMarks.map(config.schema.markFromJSON);
6717
- }
6718
- else {
6719
- if (pluginFields)
6720
- for (let prop in pluginFields) {
6721
- let plugin = pluginFields[prop], state = plugin.spec.state;
6722
- if (plugin.key == field.name && state && state.fromJSON &&
6723
- Object.prototype.hasOwnProperty.call(json, prop)) {
6724
- instance[field.name] = state.fromJSON.call(plugin, config, json[prop], instance);
6725
- return;
6726
- }
6727
- }
6728
- instance[field.name] = field.init(config, instance);
6729
- }
6730
- });
6731
- return instance;
6732
- }
6733
- }
6734
-
6735
- function bindProps(obj, self, target) {
6736
- for (let prop in obj) {
6737
- let val = obj[prop];
6738
- if (val instanceof Function)
6739
- val = val.bind(self);
6740
- else if (prop == "handleDOMEvents")
6741
- val = bindProps(val, self, {});
6742
- target[prop] = val;
6743
- }
6744
- return target;
6745
- }
6746
- /**
6747
- Plugins bundle functionality that can be added to an editor.
6748
- They are part of the [editor state](https://prosemirror.net/docs/ref/#state.EditorState) and
6749
- may influence that state and the view that contains it.
6750
- */
6751
- class Plugin {
6752
- /**
6753
- Create a plugin.
6754
- */
6755
- constructor(
6756
- /**
6757
- The plugin's [spec object](https://prosemirror.net/docs/ref/#state.PluginSpec).
6758
- */
6759
- spec) {
6760
- this.spec = spec;
6761
- /**
6762
- The [props](https://prosemirror.net/docs/ref/#view.EditorProps) exported by this plugin.
6763
- */
6764
- this.props = {};
6765
- if (spec.props)
6766
- bindProps(spec.props, this, this.props);
6767
- this.key = spec.key ? spec.key.key : createKey("plugin");
6768
- }
6769
- /**
6770
- Extract the plugin's state field from an editor state.
6771
- */
6772
- getState(state) { return state[this.key]; }
6773
- }
6774
- const keys = Object.create(null);
6775
- function createKey(name) {
6776
- if (name in keys)
6777
- return name + "$" + ++keys[name];
6778
- keys[name] = 0;
6779
- return name + "$";
6780
- }
6781
- /**
6782
- A key is used to [tag](https://prosemirror.net/docs/ref/#state.PluginSpec.key) plugins in a way
6783
- that makes it possible to find them, given an editor state.
6784
- Assigning a key does mean only one plugin of that type can be
6785
- active in a state.
6786
- */
6787
- class PluginKey {
6788
- /**
6789
- Create a plugin key.
6790
- */
6791
- constructor(name = "key") { this.key = createKey(name); }
6792
- /**
6793
- Get the active plugin with this key, if any, from an editor
6794
- state.
6795
- */
6796
- get(state) { return state.config.pluginsByKey[this.key]; }
6797
- /**
6798
- Get the plugin's state from an editor state.
6799
- */
6800
- getState(state) { return state[this.key]; }
6801
- }
6802
3746
 
6803
- export { AllSelection as A, DOMSerializer as D, EditorState as E, Fragment as F, Mark as M, Node as N, Plugin as P, ReplaceStep as R, Slice as S, TextSelection as T, Selection as a, NodeSelection as b, DOMParser as c, dropPoint as d, canSplit as e, findWrapping as f, canJoin as g, ReplaceAroundStep as h, NodeRange as i, joinPoint as j, Transform as k, liftTarget as l, PluginKey as m, RemoveMarkStep as n, Schema as o, SelectionRange as p, Mapping as q, replaceStep as r };
6804
- //# sourceMappingURL=chunk-DgZGzqPs.js.map
3747
+ exports.DEFAULT_SEARCH_KEYS = DEFAULT_SEARCH_KEYS;
3748
+ exports.DOMParser = DOMParser$1;
3749
+ exports.DOMSerializer = DOMSerializer;
3750
+ exports.EMPTY_TAGS_TO_REMOVE = EMPTY_TAGS_TO_REMOVE;
3751
+ exports.FUZZY_SEARCH_DEFAULT_LIMIT = FUZZY_SEARCH_DEFAULT_LIMIT;
3752
+ exports.Fragment = Fragment;
3753
+ exports.MARGIN_HEIGHT = MARGIN_HEIGHT;
3754
+ exports.Mark = Mark;
3755
+ exports.MarkType = MarkType;
3756
+ exports.NON_EMPTY_TAGS = NON_EMPTY_TAGS;
3757
+ exports.Node = Node;
3758
+ exports.NodeRange = NodeRange;
3759
+ exports.ReplaceError = ReplaceError;
3760
+ exports.Schema = Schema;
3761
+ exports.Slice = Slice;
3762
+ exports.isMarkdown = isMarkdown;
3763
+ exports.markdownToSlice = markdownToSlice;
3764
+ //# sourceMappingURL=chunk-BPJBeVDI.cjs.js.map