mardora 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +113 -0
  3. package/dist/chunk-3OCUX4OO.js +7690 -0
  4. package/dist/chunk-3OCUX4OO.js.map +1 -0
  5. package/dist/chunk-3ZOCCFDL.cjs +74 -0
  6. package/dist/chunk-3ZOCCFDL.cjs.map +1 -0
  7. package/dist/chunk-7JOEPNEV.cjs +7740 -0
  8. package/dist/chunk-7JOEPNEV.cjs.map +1 -0
  9. package/dist/chunk-BIKZQZ6W.js +33 -0
  10. package/dist/chunk-BIKZQZ6W.js.map +1 -0
  11. package/dist/chunk-EQJESPP2.js +234 -0
  12. package/dist/chunk-EQJESPP2.js.map +1 -0
  13. package/dist/chunk-G4SE26YY.js +70 -0
  14. package/dist/chunk-G4SE26YY.js.map +1 -0
  15. package/dist/chunk-KNDWF2DP.cjs +35 -0
  16. package/dist/chunk-KNDWF2DP.cjs.map +1 -0
  17. package/dist/chunk-MLBEBFHB.cjs +2971 -0
  18. package/dist/chunk-MLBEBFHB.cjs.map +1 -0
  19. package/dist/chunk-P7JFCYU3.js +905 -0
  20. package/dist/chunk-P7JFCYU3.js.map +1 -0
  21. package/dist/chunk-SWFUKJDO.cjs +243 -0
  22. package/dist/chunk-SWFUKJDO.cjs.map +1 -0
  23. package/dist/chunk-WFVCG4LD.cjs +926 -0
  24. package/dist/chunk-WFVCG4LD.cjs.map +1 -0
  25. package/dist/chunk-XL6WFGJT.js +2901 -0
  26. package/dist/chunk-XL6WFGJT.js.map +1 -0
  27. package/dist/editor/index.cjs +277 -0
  28. package/dist/editor/index.cjs.map +1 -0
  29. package/dist/editor/index.d.cts +186 -0
  30. package/dist/editor/index.d.ts +186 -0
  31. package/dist/editor/index.js +4 -0
  32. package/dist/editor/index.js.map +1 -0
  33. package/dist/index.cjs +405 -0
  34. package/dist/index.cjs.map +1 -0
  35. package/dist/index.d.cts +13 -0
  36. package/dist/index.d.ts +13 -0
  37. package/dist/index.js +8 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/lib/index.cjs +12 -0
  40. package/dist/lib/index.cjs.map +1 -0
  41. package/dist/lib/index.d.cts +16 -0
  42. package/dist/lib/index.d.ts +16 -0
  43. package/dist/lib/index.js +3 -0
  44. package/dist/lib/index.js.map +1 -0
  45. package/dist/mardora-DCwjomil.d.cts +640 -0
  46. package/dist/mardora-DCwjomil.d.ts +640 -0
  47. package/dist/plugins/index.cjs +104 -0
  48. package/dist/plugins/index.cjs.map +1 -0
  49. package/dist/plugins/index.d.cts +740 -0
  50. package/dist/plugins/index.d.ts +740 -0
  51. package/dist/plugins/index.js +7 -0
  52. package/dist/plugins/index.js.map +1 -0
  53. package/dist/preview/index.cjs +38 -0
  54. package/dist/preview/index.cjs.map +1 -0
  55. package/dist/preview/index.d.cts +101 -0
  56. package/dist/preview/index.d.ts +101 -0
  57. package/dist/preview/index.js +5 -0
  58. package/dist/preview/index.js.map +1 -0
  59. package/dist/types-NBsaxl4d.d.cts +71 -0
  60. package/dist/types-Pw2SWWAR.d.ts +71 -0
  61. package/package.json +92 -0
  62. package/src/editor/attachments/extension.ts +181 -0
  63. package/src/editor/attachments/format.ts +63 -0
  64. package/src/editor/attachments/index.ts +3 -0
  65. package/src/editor/attachments/types.ts +37 -0
  66. package/src/editor/heading-fold/config.ts +25 -0
  67. package/src/editor/heading-fold/extension.ts +268 -0
  68. package/src/editor/heading-fold/extract.ts +88 -0
  69. package/src/editor/heading-fold/index.ts +5 -0
  70. package/src/editor/heading-fold/theme.ts +85 -0
  71. package/src/editor/heading-fold/types.ts +24 -0
  72. package/src/editor/i18n.ts +13 -0
  73. package/src/editor/icons/index.ts +367 -0
  74. package/src/editor/index.ts +16 -0
  75. package/src/editor/mardora.ts +257 -0
  76. package/src/editor/media-lightbox-theme.ts +146 -0
  77. package/src/editor/media-lightbox.ts +125 -0
  78. package/src/editor/plugin.ts +294 -0
  79. package/src/editor/selection-toolbar/activation.ts +123 -0
  80. package/src/editor/selection-toolbar/commands.ts +279 -0
  81. package/src/editor/selection-toolbar/extension.ts +564 -0
  82. package/src/editor/selection-toolbar/i18n.ts +164 -0
  83. package/src/editor/selection-toolbar/index.ts +7 -0
  84. package/src/editor/selection-toolbar/menu.ts +252 -0
  85. package/src/editor/selection-toolbar/position.ts +43 -0
  86. package/src/editor/selection-toolbar/theme.ts +195 -0
  87. package/src/editor/selection-toolbar/types.ts +155 -0
  88. package/src/editor/slash/default-commands.ts +190 -0
  89. package/src/editor/slash/extension.ts +319 -0
  90. package/src/editor/slash/index.ts +7 -0
  91. package/src/editor/slash/insertions.ts +26 -0
  92. package/src/editor/slash/menu.ts +123 -0
  93. package/src/editor/slash/position.ts +61 -0
  94. package/src/editor/slash/query.ts +33 -0
  95. package/src/editor/slash/theme.ts +113 -0
  96. package/src/editor/slash/types.ts +40 -0
  97. package/src/editor/table-of-contents/extension.ts +202 -0
  98. package/src/editor/table-of-contents/extract.ts +53 -0
  99. package/src/editor/table-of-contents/index.ts +7 -0
  100. package/src/editor/table-of-contents/panel.ts +83 -0
  101. package/src/editor/table-of-contents/slug.ts +50 -0
  102. package/src/editor/table-of-contents/storage.ts +35 -0
  103. package/src/editor/table-of-contents/theme.ts +153 -0
  104. package/src/editor/table-of-contents/types.ts +44 -0
  105. package/src/editor/theme.ts +72 -0
  106. package/src/editor/utils.ts +176 -0
  107. package/src/editor/view-plugin.ts +189 -0
  108. package/src/index.ts +5 -0
  109. package/src/lib/index.ts +2 -0
  110. package/src/lib/input-handler.ts +47 -0
  111. package/src/plugins/code-plugin.theme.ts +545 -0
  112. package/src/plugins/code-plugin.ts +1892 -0
  113. package/src/plugins/emoji-plugin.ts +140 -0
  114. package/src/plugins/heading-plugin.ts +194 -0
  115. package/src/plugins/hr-plugin.ts +102 -0
  116. package/src/plugins/html-plugin.ts +353 -0
  117. package/src/plugins/image-plugin.ts +806 -0
  118. package/src/plugins/index.ts +71 -0
  119. package/src/plugins/inline-plugin.ts +311 -0
  120. package/src/plugins/link-plugin.ts +509 -0
  121. package/src/plugins/list-plugin.ts +492 -0
  122. package/src/plugins/math-plugin.ts +526 -0
  123. package/src/plugins/mermaid-plugin.ts +513 -0
  124. package/src/plugins/paragraph-plugin.ts +38 -0
  125. package/src/plugins/quote-plugin.ts +733 -0
  126. package/src/plugins/table-controls-theme.ts +126 -0
  127. package/src/plugins/table-controls.ts +423 -0
  128. package/src/plugins/table-model.ts +661 -0
  129. package/src/plugins/table-plugin.ts +2111 -0
  130. package/src/preview/context.ts +45 -0
  131. package/src/preview/css-generator.ts +64 -0
  132. package/src/preview/default-renderers.ts +29 -0
  133. package/src/preview/index.ts +29 -0
  134. package/src/preview/preview.ts +41 -0
  135. package/src/preview/renderer.ts +184 -0
  136. package/src/preview/syntax-theme.ts +112 -0
  137. package/src/preview/toc.ts +23 -0
  138. package/src/preview/types.ts +89 -0
@@ -0,0 +1,926 @@
1
+ 'use strict';
2
+
3
+ var language = require('@codemirror/language');
4
+ var view = require('@codemirror/view');
5
+ var state = require('@codemirror/state');
6
+
7
+ // src/editor/utils.ts
8
+ function deepMerge(a, b) {
9
+ const result = { ...a };
10
+ if (!b) {
11
+ return result;
12
+ }
13
+ for (const key in b) {
14
+ if (b[key] && typeof b[key] === "object" && !Array.isArray(b[key]) && typeof a[key] === "object") {
15
+ result[key] = deepMerge(a[key], b[key]);
16
+ } else {
17
+ result[key] = b[key];
18
+ }
19
+ }
20
+ return result;
21
+ }
22
+ var ThemeEnum = /* @__PURE__ */ ((ThemeEnum2) => {
23
+ ThemeEnum2["DARK"] = "dark";
24
+ ThemeEnum2["LIGHT"] = "light";
25
+ ThemeEnum2["AUTO"] = "auto";
26
+ return ThemeEnum2;
27
+ })(ThemeEnum || {});
28
+ function createTheme({
29
+ default: defaultTheme,
30
+ dark: darkTheme,
31
+ light: lightTheme
32
+ }) {
33
+ return (theme) => {
34
+ defaultTheme = flattenThemeStyles(defaultTheme);
35
+ darkTheme = flattenThemeStyles(darkTheme || {});
36
+ lightTheme = flattenThemeStyles(lightTheme || {});
37
+ let style = defaultTheme;
38
+ if (theme === "dark" /* DARK */) {
39
+ style = deepMerge(style, darkTheme);
40
+ }
41
+ if (theme === "light" /* LIGHT */) {
42
+ style = deepMerge(style, lightTheme);
43
+ }
44
+ return style;
45
+ };
46
+ }
47
+ function flattenThemeStyles(themeStyles, parentSelector) {
48
+ const flattened = {};
49
+ for (const [selectors, styles] of Object.entries(themeStyles)) {
50
+ for (const selector of selectors.split(",")) {
51
+ if (typeof styles === "object" && !Array.isArray(styles)) {
52
+ const fullSelector = fixSelector(parentSelector ? `${parentSelector} ${selector}` : selector);
53
+ const nestedStyles = flattenThemeStyles(styles, fullSelector);
54
+ Object.assign(flattened, nestedStyles);
55
+ } else {
56
+ if (parentSelector) {
57
+ flattened[parentSelector] = { ...flattened[parentSelector], [selector]: styles };
58
+ } else {
59
+ flattened[selector] = styles;
60
+ }
61
+ }
62
+ }
63
+ }
64
+ return flattened;
65
+ }
66
+ function fixSelector(selector) {
67
+ return selector.replace(/\s&/g, "");
68
+ }
69
+ function cursorInRange(view, from, to) {
70
+ const selection = view.state.selection.main;
71
+ return selection.from <= to && selection.to >= from;
72
+ }
73
+ function selectionOverlapsRange(view, from, to) {
74
+ for (const range of view.state.selection.ranges) {
75
+ if (range.from <= to && range.to >= from) {
76
+ return true;
77
+ }
78
+ }
79
+ return false;
80
+ }
81
+ function toggleMarkdownStyle(marker) {
82
+ return (view) => {
83
+ const { state } = view;
84
+ const { from, to, empty } = state.selection.main;
85
+ const selectedText = state.sliceDoc(from, to);
86
+ const markerLen = marker.length;
87
+ const beforeFrom = Math.max(0, from - markerLen);
88
+ const afterTo = Math.min(state.doc.length, to + markerLen);
89
+ const textBefore = state.sliceDoc(beforeFrom, from);
90
+ const textAfter = state.sliceDoc(to, afterTo);
91
+ const isWrapped = textBefore === marker && textAfter === marker;
92
+ if (isWrapped) {
93
+ view.dispatch({
94
+ changes: [
95
+ { from: beforeFrom, to: from, insert: "" },
96
+ { from: to, to: afterTo, insert: "" }
97
+ ],
98
+ selection: { anchor: beforeFrom, head: beforeFrom + selectedText.length }
99
+ });
100
+ } else if (empty) {
101
+ view.dispatch({
102
+ changes: { from, to, insert: marker + marker },
103
+ selection: { anchor: from + markerLen }
104
+ });
105
+ } else {
106
+ view.dispatch({
107
+ changes: { from, to, insert: marker + selectedText + marker },
108
+ selection: { anchor: from + markerLen, head: to + markerLen }
109
+ });
110
+ }
111
+ return true;
112
+ };
113
+ }
114
+
115
+ // src/editor/icons/index.ts
116
+ var svgNamespace = "http://www.w3.org/2000/svg";
117
+ var iconDefinitions = {
118
+ "arrow-down": [
119
+ { name: "path", attrs: { d: "M12 5v14" } },
120
+ { name: "path", attrs: { d: "m19 12-7 7-7-7" } }
121
+ ],
122
+ "arrow-down-to-line": [
123
+ { name: "path", attrs: { d: "M19 21H5" } },
124
+ { name: "path", attrs: { d: "M12 3v14" } },
125
+ { name: "path", attrs: { d: "m19 10-7 7-7-7" } }
126
+ ],
127
+ "arrow-left": [
128
+ { name: "path", attrs: { d: "M19 12H5" } },
129
+ { name: "path", attrs: { d: "m12 19-7-7 7-7" } }
130
+ ],
131
+ "arrow-left-to-line": [
132
+ { name: "path", attrs: { d: "M3 5v14" } },
133
+ { name: "path", attrs: { d: "M21 12H7" } },
134
+ { name: "path", attrs: { d: "m14 19-7-7 7-7" } }
135
+ ],
136
+ "arrow-right": [
137
+ { name: "path", attrs: { d: "M5 12h14" } },
138
+ { name: "path", attrs: { d: "m12 5 7 7-7 7" } }
139
+ ],
140
+ "arrow-right-to-line": [
141
+ { name: "path", attrs: { d: "M21 5v14" } },
142
+ { name: "path", attrs: { d: "M3 12h14" } },
143
+ { name: "path", attrs: { d: "m10 5 7 7-7 7" } }
144
+ ],
145
+ "arrow-up": [
146
+ { name: "path", attrs: { d: "M12 19V5" } },
147
+ { name: "path", attrs: { d: "m5 12 7-7 7 7" } }
148
+ ],
149
+ "arrow-up-to-line": [
150
+ { name: "path", attrs: { d: "M5 3h14" } },
151
+ { name: "path", attrs: { d: "M12 21V7" } },
152
+ { name: "path", attrs: { d: "m5 14 7-7 7 7" } }
153
+ ],
154
+ "badge-alert": [
155
+ {
156
+ name: "path",
157
+ attrs: {
158
+ d: "M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z"
159
+ }
160
+ },
161
+ { name: "line", attrs: { x1: "12", x2: "12", y1: "8", y2: "12" } },
162
+ { name: "line", attrs: { x1: "12", x2: "12.01", y1: "16", y2: "16" } }
163
+ ],
164
+ baseline: [
165
+ { name: "path", attrs: { d: "M4 20h16" } },
166
+ { name: "path", attrs: { d: "m6 16 6-12 6 12" } },
167
+ { name: "path", attrs: { d: "M8 12h8" } }
168
+ ],
169
+ bold: [
170
+ {
171
+ name: "path",
172
+ attrs: {
173
+ d: "M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"
174
+ }
175
+ }
176
+ ],
177
+ code: [
178
+ { name: "path", attrs: { d: "m16 18 6-6-6-6" } },
179
+ { name: "path", attrs: { d: "m8 6-6 6 6 6" } }
180
+ ],
181
+ "code-xml": [
182
+ { name: "path", attrs: { d: "m18 16 4-4-4-4" } },
183
+ { name: "path", attrs: { d: "m6 8-4 4 4 4" } },
184
+ { name: "path", attrs: { d: "m14.5 4-5 16" } }
185
+ ],
186
+ copy: [
187
+ { name: "rect", attrs: { width: "14", height: "14", x: "8", y: "8", rx: "2", ry: "2" } },
188
+ { name: "path", attrs: { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" } }
189
+ ],
190
+ "external-link": [
191
+ { name: "path", attrs: { d: "M15 3h6v6" } },
192
+ { name: "path", attrs: { d: "M10 14 21 3" } },
193
+ { name: "path", attrs: { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" } }
194
+ ],
195
+ file: [
196
+ {
197
+ name: "path",
198
+ attrs: {
199
+ d: "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"
200
+ }
201
+ },
202
+ { name: "path", attrs: { d: "M14 2v5a1 1 0 0 0 1 1h5" } }
203
+ ],
204
+ "heading-1": [
205
+ { name: "path", attrs: { d: "M4 12h8" } },
206
+ { name: "path", attrs: { d: "M4 18V6" } },
207
+ { name: "path", attrs: { d: "M12 18V6" } },
208
+ { name: "path", attrs: { d: "m17 12 3-2v8" } }
209
+ ],
210
+ "heading-2": [
211
+ { name: "path", attrs: { d: "M4 12h8" } },
212
+ { name: "path", attrs: { d: "M4 18V6" } },
213
+ { name: "path", attrs: { d: "M12 18V6" } },
214
+ { name: "path", attrs: { d: "M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1" } }
215
+ ],
216
+ "heading-3": [
217
+ { name: "path", attrs: { d: "M4 12h8" } },
218
+ { name: "path", attrs: { d: "M4 18V6" } },
219
+ { name: "path", attrs: { d: "M12 18V6" } },
220
+ { name: "path", attrs: { d: "M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2" } },
221
+ { name: "path", attrs: { d: "M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2" } }
222
+ ],
223
+ "heading-4": [
224
+ { name: "path", attrs: { d: "M12 18V6" } },
225
+ { name: "path", attrs: { d: "M17 10v3a1 1 0 0 0 1 1h3" } },
226
+ { name: "path", attrs: { d: "M21 10v8" } },
227
+ { name: "path", attrs: { d: "M4 12h8" } },
228
+ { name: "path", attrs: { d: "M4 18V6" } }
229
+ ],
230
+ "heading-5": [
231
+ { name: "path", attrs: { d: "M4 12h8" } },
232
+ { name: "path", attrs: { d: "M4 18V6" } },
233
+ { name: "path", attrs: { d: "M12 18V6" } },
234
+ { name: "path", attrs: { d: "M17 13v-3h4" } },
235
+ { name: "path", attrs: { d: "M17 17.7c.4.2.8.3 1.3.3 1.5 0 2.7-1.1 2.7-2.5S19.8 13 18.3 13H17" } }
236
+ ],
237
+ "heading-6": [
238
+ { name: "path", attrs: { d: "M4 12h8" } },
239
+ { name: "path", attrs: { d: "M4 18V6" } },
240
+ { name: "path", attrs: { d: "M12 18V6" } },
241
+ { name: "circle", attrs: { cx: "19", cy: "16", r: "2" } },
242
+ { name: "path", attrs: { d: "M20 10c-2 2-3 3.5-3 6" } }
243
+ ],
244
+ highlighter: [
245
+ { name: "path", attrs: { d: "m9 11-6 6v3h9l3-3" } },
246
+ { name: "path", attrs: { d: "m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4" } }
247
+ ],
248
+ image: [
249
+ { name: "rect", attrs: { width: "18", height: "18", x: "3", y: "3", rx: "2", ry: "2" } },
250
+ { name: "circle", attrs: { cx: "9", cy: "9", r: "2" } },
251
+ { name: "path", attrs: { d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" } }
252
+ ],
253
+ info: [
254
+ { name: "circle", attrs: { cx: "12", cy: "12", r: "10" } },
255
+ { name: "path", attrs: { d: "M12 16v-4" } },
256
+ { name: "path", attrs: { d: "M12 8h.01" } }
257
+ ],
258
+ italic: [
259
+ { name: "line", attrs: { x1: "19", x2: "10", y1: "4", y2: "4" } },
260
+ { name: "line", attrs: { x1: "14", x2: "5", y1: "20", y2: "20" } },
261
+ { name: "line", attrs: { x1: "15", x2: "9", y1: "4", y2: "20" } }
262
+ ],
263
+ link: [
264
+ { name: "path", attrs: { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" } },
265
+ { name: "path", attrs: { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" } }
266
+ ],
267
+ lightbulb: [
268
+ {
269
+ name: "path",
270
+ attrs: {
271
+ d: "M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"
272
+ }
273
+ },
274
+ { name: "path", attrs: { d: "M9 18h6" } },
275
+ { name: "path", attrs: { d: "M10 22h4" } }
276
+ ],
277
+ list: [
278
+ { name: "path", attrs: { d: "M3 5h.01" } },
279
+ { name: "path", attrs: { d: "M3 12h.01" } },
280
+ { name: "path", attrs: { d: "M3 19h.01" } },
281
+ { name: "path", attrs: { d: "M8 5h13" } },
282
+ { name: "path", attrs: { d: "M8 12h13" } },
283
+ { name: "path", attrs: { d: "M8 19h13" } }
284
+ ],
285
+ "list-ordered": [
286
+ { name: "path", attrs: { d: "M11 5h10" } },
287
+ { name: "path", attrs: { d: "M11 12h10" } },
288
+ { name: "path", attrs: { d: "M11 19h10" } },
289
+ { name: "path", attrs: { d: "M4 4h1v5" } },
290
+ { name: "path", attrs: { d: "M4 9h2" } },
291
+ { name: "path", attrs: { d: "M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02" } }
292
+ ],
293
+ "list-todo": [
294
+ { name: "path", attrs: { d: "M13 5h8" } },
295
+ { name: "path", attrs: { d: "M13 12h8" } },
296
+ { name: "path", attrs: { d: "M13 19h8" } },
297
+ { name: "path", attrs: { d: "m3 17 2 2 4-4" } },
298
+ { name: "rect", attrs: { x: "3", y: "4", width: "6", height: "6", rx: "1" } }
299
+ ],
300
+ "maximize-2": [
301
+ { name: "path", attrs: { d: "M15 3h6v6" } },
302
+ { name: "path", attrs: { d: "m21 3-7 7" } },
303
+ { name: "path", attrs: { d: "M9 21H3v-6" } },
304
+ { name: "path", attrs: { d: "m3 21 7-7" } }
305
+ ],
306
+ minus: [{ name: "path", attrs: { d: "M5 12h14" } }],
307
+ "music-2": [
308
+ { name: "circle", attrs: { cx: "8", cy: "18", r: "4" } },
309
+ { name: "path", attrs: { d: "M12 18V2l7 4" } }
310
+ ],
311
+ "octagon-alert": [
312
+ { name: "path", attrs: { d: "M12 16h.01" } },
313
+ { name: "path", attrs: { d: "M12 8v4" } },
314
+ {
315
+ name: "path",
316
+ attrs: {
317
+ d: "M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z"
318
+ }
319
+ }
320
+ ],
321
+ play: [
322
+ {
323
+ name: "path",
324
+ attrs: { d: "M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z" }
325
+ }
326
+ ],
327
+ "rotate-ccw": [
328
+ { name: "path", attrs: { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" } },
329
+ { name: "path", attrs: { d: "M3 3v5h5" } }
330
+ ],
331
+ strikethrough: [
332
+ { name: "path", attrs: { d: "M16 4H9a3 3 0 0 0-2.83 4" } },
333
+ { name: "path", attrs: { d: "M14 12a4 4 0 0 1 0 8H6" } },
334
+ { name: "line", attrs: { x1: "4", x2: "20", y1: "12", y2: "12" } }
335
+ ],
336
+ table: [
337
+ { name: "path", attrs: { d: "M12 3v18" } },
338
+ { name: "rect", attrs: { width: "18", height: "18", x: "3", y: "3", rx: "2" } },
339
+ { name: "path", attrs: { d: "M3 9h18" } },
340
+ { name: "path", attrs: { d: "M3 15h18" } }
341
+ ],
342
+ "table-delete": [
343
+ { name: "rect", attrs: { width: "18", height: "18", x: "3", y: "3", rx: "2" } },
344
+ { name: "path", attrs: { d: "M3 9h18" } },
345
+ { name: "path", attrs: { d: "M9 3v18" } },
346
+ { name: "path", attrs: { d: "m14 14 4 4" } },
347
+ { name: "path", attrs: { d: "m18 14-4 4" } }
348
+ ],
349
+ "table-of-contents": [
350
+ { name: "path", attrs: { d: "M16 5H3" } },
351
+ { name: "path", attrs: { d: "M16 12H3" } },
352
+ { name: "path", attrs: { d: "M16 19H3" } },
353
+ { name: "path", attrs: { d: "M21 5h.01" } },
354
+ { name: "path", attrs: { d: "M21 12h.01" } },
355
+ { name: "path", attrs: { d: "M21 19h.01" } }
356
+ ],
357
+ "text-align-start": [
358
+ { name: "path", attrs: { d: "M21 5H3" } },
359
+ { name: "path", attrs: { d: "M15 12H3" } },
360
+ { name: "path", attrs: { d: "M17 19H3" } }
361
+ ],
362
+ "text-quote": [
363
+ { name: "path", attrs: { d: "M17 5H3" } },
364
+ { name: "path", attrs: { d: "M21 12H8" } },
365
+ { name: "path", attrs: { d: "M21 19H8" } },
366
+ { name: "path", attrs: { d: "M3 12v7" } }
367
+ ],
368
+ "trash-2": [
369
+ { name: "path", attrs: { d: "M10 11v6" } },
370
+ { name: "path", attrs: { d: "M14 11v6" } },
371
+ { name: "path", attrs: { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" } },
372
+ { name: "path", attrs: { d: "M3 6h18" } },
373
+ { name: "path", attrs: { d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" } }
374
+ ],
375
+ "triangle-alert": [
376
+ { name: "path", attrs: { d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" } },
377
+ { name: "path", attrs: { d: "M12 9v4" } },
378
+ { name: "path", attrs: { d: "M12 17h.01" } }
379
+ ],
380
+ underline: [
381
+ { name: "path", attrs: { d: "M6 4v6a6 6 0 0 0 12 0V4" } },
382
+ { name: "line", attrs: { x1: "4", x2: "20", y1: "20", y2: "20" } }
383
+ ],
384
+ type: [
385
+ { name: "path", attrs: { d: "M12 4v16" } },
386
+ { name: "path", attrs: { d: "M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2" } },
387
+ { name: "path", attrs: { d: "M9 20h6" } }
388
+ ],
389
+ x: [
390
+ { name: "path", attrs: { d: "M18 6 6 18" } },
391
+ { name: "path", attrs: { d: "m6 6 12 12" } }
392
+ ]
393
+ };
394
+ function hasMardoraIcon(name) {
395
+ return name in iconDefinitions;
396
+ }
397
+ function createMardoraIcon(name) {
398
+ if (!hasMardoraIcon(name)) return null;
399
+ const svg = document.createElementNS(svgNamespace, "svg");
400
+ svg.setAttribute("xmlns", svgNamespace);
401
+ svg.setAttribute("width", "24");
402
+ svg.setAttribute("height", "24");
403
+ svg.setAttribute("viewBox", "0 0 24 24");
404
+ svg.setAttribute("fill", "none");
405
+ svg.setAttribute("stroke", "currentColor");
406
+ svg.setAttribute("stroke-width", "2");
407
+ svg.setAttribute("stroke-linecap", "round");
408
+ svg.setAttribute("stroke-linejoin", "round");
409
+ svg.setAttribute("aria-hidden", "true");
410
+ svg.setAttribute("focusable", "false");
411
+ for (const definition of iconDefinitions[name]) {
412
+ const element = document.createElementNS(svgNamespace, definition.name);
413
+ for (const [attr, value] of Object.entries(definition.attrs)) {
414
+ element.setAttribute(attr, value);
415
+ }
416
+ svg.appendChild(element);
417
+ }
418
+ return svg;
419
+ }
420
+
421
+ // src/editor/table-of-contents/slug.ts
422
+ var defaultMinWidth = 180;
423
+ var defaultMaxWidth = 360;
424
+ var defaultWidth = 240;
425
+ function clampTocWidth(width, config) {
426
+ return Math.min(Math.max(width, config.minWidth), config.maxWidth);
427
+ }
428
+ function resolveTocConfig(config = {}) {
429
+ const minWidth = Math.max(120, config.minWidth ?? defaultMinWidth);
430
+ const maxWidth = Math.max(minWidth, config.maxWidth ?? defaultMaxWidth);
431
+ const requestedMinLevel = config.minLevel ?? 2;
432
+ const requestedMaxLevel = config.maxLevel ?? 6;
433
+ const minLevel = requestedMinLevel <= requestedMaxLevel ? requestedMinLevel : requestedMaxLevel;
434
+ const maxLevel = requestedMaxLevel >= requestedMinLevel ? requestedMaxLevel : requestedMinLevel;
435
+ const resolved = {
436
+ enabled: config.enabled !== false,
437
+ minLevel,
438
+ maxLevel,
439
+ defaultExpanded: config.defaultExpanded !== false,
440
+ defaultWidth,
441
+ minWidth,
442
+ maxWidth
443
+ };
444
+ if (config.onTocChange) resolved.onTocChange = config.onTocChange;
445
+ if (config.storageKey) resolved.storageKey = config.storageKey;
446
+ resolved.defaultWidth = clampTocWidth(config.defaultWidth ?? defaultWidth, resolved);
447
+ return resolved;
448
+ }
449
+ function normalizeHeadingText(value) {
450
+ return value.trim().toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "");
451
+ }
452
+ function createTocSlugger() {
453
+ const seen = /* @__PURE__ */ new Map();
454
+ return (text) => {
455
+ const base = normalizeHeadingText(text) || "heading";
456
+ const count = (seen.get(base) ?? 0) + 1;
457
+ seen.set(base, count);
458
+ return count === 1 ? base : `${base}-${count}`;
459
+ };
460
+ }
461
+
462
+ // src/editor/table-of-contents/storage.ts
463
+ function defaultStorage() {
464
+ if (typeof window === "undefined") return null;
465
+ return window.localStorage;
466
+ }
467
+ function readTocPanelState(storageKey, storage = defaultStorage()) {
468
+ if (!storageKey || !storage) return null;
469
+ try {
470
+ const raw = storage.getItem(storageKey);
471
+ if (!raw) return null;
472
+ const parsed = JSON.parse(raw);
473
+ if (typeof parsed.expanded !== "boolean" || typeof parsed.width !== "number") return null;
474
+ return { expanded: parsed.expanded, width: parsed.width };
475
+ } catch {
476
+ return null;
477
+ }
478
+ }
479
+ function writeTocPanelState(storageKey, state, storage = defaultStorage()) {
480
+ if (!storageKey || !storage) return;
481
+ try {
482
+ storage.setItem(storageKey, JSON.stringify({ expanded: state.expanded, width: state.width }));
483
+ } catch {
484
+ }
485
+ }
486
+ var headingPattern = /^ATXHeading([1-6])$/;
487
+ var tocParseTimeout = 100;
488
+ function headingLevel(node) {
489
+ const match = headingPattern.exec(node.name);
490
+ if (!match) return null;
491
+ const level = Number(match[1]);
492
+ return level >= 2 && level <= 6 ? level : null;
493
+ }
494
+ function stripMarkdownHeadingText(text) {
495
+ return text.replace(/^#{1,6}\s*/, "").replace(/`([^`]+)`/g, "$1").replace(/\*\*([^*]+)\*\*/g, "$1").replace(/\*([^*]+)\*/g, "$1").replace(/__([^_]+)__/g, "$1").replace(/_([^_]+)_/g, "$1").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").trim();
496
+ }
497
+ function extractTocItemsFromState(state, config = {}) {
498
+ const resolved = resolveTocConfig(config);
499
+ const slug = createTocSlugger();
500
+ const items = [];
501
+ const tree = language.ensureSyntaxTree(state, state.doc.length, tocParseTimeout) ?? language.syntaxTree(state);
502
+ tree.iterate({
503
+ enter: (node) => {
504
+ const level = headingLevel(node);
505
+ if (!level || level < resolved.minLevel || level > resolved.maxLevel) return;
506
+ const text = stripMarkdownHeadingText(state.sliceDoc(node.from, node.to));
507
+ if (!text) return;
508
+ items.push({
509
+ id: slug(text),
510
+ level,
511
+ text,
512
+ from: node.from,
513
+ to: node.to,
514
+ active: false
515
+ });
516
+ }
517
+ });
518
+ return items;
519
+ }
520
+
521
+ // src/editor/table-of-contents/panel.ts
522
+ function appendIcon(parent, name) {
523
+ const icon = createMardoraIcon(name);
524
+ if (icon) parent.appendChild(icon);
525
+ }
526
+ function createExpandedToggle(callbacks) {
527
+ const toggle = document.createElement("button");
528
+ toggle.type = "button";
529
+ toggle.className = "cm-mardora-toc-toggle";
530
+ toggle.setAttribute("aria-label", "Toggle table of contents");
531
+ toggle.textContent = "\u2039";
532
+ toggle.addEventListener("click", callbacks.onToggle);
533
+ return toggle;
534
+ }
535
+ function createCollapsed(callbacks) {
536
+ const button = document.createElement("button");
537
+ button.type = "button";
538
+ button.className = "cm-mardora-toc-collapsed";
539
+ button.setAttribute("aria-label", "Open table of contents");
540
+ appendIcon(button, "table-of-contents");
541
+ button.addEventListener("click", callbacks.onToggle);
542
+ return button;
543
+ }
544
+ function createItem(item, callbacks) {
545
+ const button = document.createElement("button");
546
+ button.type = "button";
547
+ button.className = item.active ? "cm-mardora-toc-item cm-mardora-toc-item-active" : "cm-mardora-toc-item";
548
+ button.dataset.mardoraTocId = item.id;
549
+ button.dataset.mardoraTocLevel = String(item.level);
550
+ button.title = item.text;
551
+ button.textContent = item.text;
552
+ button.addEventListener("click", () => callbacks.onSelect(item));
553
+ return button;
554
+ }
555
+ function createTocPanelElement(state, callbacks) {
556
+ const root = document.createElement("aside");
557
+ root.className = "cm-mardora-toc";
558
+ root.dataset.mardoraTocExpanded = String(state.expanded);
559
+ root.style.setProperty("--mardora-toc-width", `${state.width}px`);
560
+ const resize = document.createElement("div");
561
+ resize.className = "cm-mardora-toc-resize";
562
+ resize.addEventListener("mousedown", callbacks.onResizeStart);
563
+ root.appendChild(resize);
564
+ if (!state.expanded) {
565
+ root.appendChild(createCollapsed(callbacks));
566
+ return root;
567
+ }
568
+ root.appendChild(createExpandedToggle(callbacks));
569
+ const list = document.createElement("nav");
570
+ list.className = "cm-mardora-toc-list";
571
+ if (state.items.length === 0) {
572
+ const empty = document.createElement("div");
573
+ empty.className = "cm-mardora-toc-empty";
574
+ empty.textContent = "\u6682\u65E0\u76EE\u5F55";
575
+ list.appendChild(empty);
576
+ } else {
577
+ for (const item of state.items) list.appendChild(createItem(item, callbacks));
578
+ }
579
+ root.appendChild(list);
580
+ return root;
581
+ }
582
+ var tocTheme = view.EditorView.baseTheme({
583
+ ".cm-mardora": {
584
+ position: "relative"
585
+ },
586
+ ".cm-mardora .cm-scroller": {
587
+ boxSizing: "border-box",
588
+ paddingRight: "calc(var(--mardora-toc-layout-width, 0px) + var(--mardora-toc-scrollbar-gutter, 0px))",
589
+ scrollbarGutter: "stable"
590
+ },
591
+ ".cm-mardora .cm-scroller::-webkit-scrollbar-track": {
592
+ background: "transparent"
593
+ },
594
+ ".cm-mardora-toc": {
595
+ position: "absolute",
596
+ top: "0",
597
+ right: "var(--mardora-toc-scrollbar-gutter, 0px)",
598
+ bottom: "0",
599
+ zIndex: "8",
600
+ width: "var(--mardora-toc-width, 240px)",
601
+ minWidth: "0",
602
+ borderLeft: "1px solid var(--mardora-toc-border, #ececef)",
603
+ background: "var(--mardora-toc-bg, transparent)",
604
+ color: "var(--mardora-toc-fg, #27272a)",
605
+ userSelect: "none"
606
+ },
607
+ ".cm-mardora-toc[data-mardora-toc-expanded='false']": {
608
+ width: "42px"
609
+ },
610
+ ".cm-mardora-toc-resize": {
611
+ position: "absolute",
612
+ top: "0",
613
+ bottom: "0",
614
+ left: "-4px",
615
+ zIndex: "2",
616
+ width: "8px",
617
+ cursor: "col-resize"
618
+ },
619
+ ".cm-mardora-toc-resize::after": {
620
+ position: "absolute",
621
+ top: "50%",
622
+ left: "3px",
623
+ width: "2px",
624
+ height: "64px",
625
+ borderRadius: "999px",
626
+ background: "var(--mardora-toc-handle, #d4d4d8)",
627
+ opacity: "0",
628
+ transform: "translateY(-50%)",
629
+ transition: "opacity 120ms ease",
630
+ content: "''"
631
+ },
632
+ ".cm-mardora-toc:hover .cm-mardora-toc-resize::after, .cm-mardora-toc-resizing .cm-mardora-toc-resize::after": {
633
+ opacity: "1"
634
+ },
635
+ ".cm-mardora-toc-collapsed svg": {
636
+ width: "16px",
637
+ height: "16px"
638
+ },
639
+ ".cm-mardora-toc-toggle, .cm-mardora-toc-collapsed, .cm-mardora-toc-item": {
640
+ border: "0",
641
+ background: "transparent",
642
+ color: "inherit",
643
+ cursor: "default",
644
+ font: "inherit"
645
+ },
646
+ ".cm-mardora-toc-toggle": {
647
+ position: "absolute",
648
+ top: "8px",
649
+ right: "8px",
650
+ zIndex: "1",
651
+ width: "28px",
652
+ height: "28px",
653
+ borderRadius: "6px",
654
+ color: "var(--mardora-toc-muted, #71717a)",
655
+ opacity: "0.55",
656
+ transition: "background 120ms ease, color 120ms ease, opacity 120ms ease"
657
+ },
658
+ ".cm-mardora-toc-toggle:hover": {
659
+ color: "var(--mardora-toc-active, #18181b)",
660
+ opacity: "1"
661
+ },
662
+ ".cm-mardora-toc-toggle:hover, .cm-mardora-toc-collapsed:hover, .cm-mardora-toc-item:hover": {
663
+ background: "var(--mardora-toc-hover, #f4f4f5)"
664
+ },
665
+ ".cm-mardora-toc-collapsed": {
666
+ display: "flex",
667
+ alignItems: "center",
668
+ justifyContent: "center",
669
+ width: "100%",
670
+ height: "100%",
671
+ color: "var(--mardora-toc-muted, #71717a)"
672
+ },
673
+ ".cm-mardora-toc-list": {
674
+ overflow: "auto",
675
+ height: "100%",
676
+ padding: "12px 10px 16px 18px",
677
+ scrollbarWidth: "thin"
678
+ },
679
+ ".cm-mardora-toc-list::-webkit-scrollbar": {
680
+ width: "8px"
681
+ },
682
+ ".cm-mardora-toc-list::-webkit-scrollbar-track": {
683
+ background: "transparent"
684
+ },
685
+ ".cm-mardora-toc-list::-webkit-scrollbar-thumb": {
686
+ borderRadius: "999px",
687
+ background: "var(--mardora-toc-scrollbar, #c7c7cc)"
688
+ },
689
+ ".cm-mardora-toc-item": {
690
+ display: "block",
691
+ width: "100%",
692
+ overflow: "hidden",
693
+ minHeight: "30px",
694
+ padding: "0 8px",
695
+ borderLeft: "2px solid transparent",
696
+ borderRadius: "6px",
697
+ color: "var(--mardora-toc-muted, #71717a)",
698
+ lineHeight: "30px",
699
+ textAlign: "left",
700
+ textOverflow: "ellipsis",
701
+ whiteSpace: "nowrap",
702
+ transition: "background 120ms ease, color 120ms ease"
703
+ },
704
+ ".cm-mardora-toc-item[data-mardora-toc-level='3']": { paddingLeft: "18px" },
705
+ ".cm-mardora-toc-item[data-mardora-toc-level='4']": { paddingLeft: "28px" },
706
+ ".cm-mardora-toc-item[data-mardora-toc-level='5']": { paddingLeft: "38px" },
707
+ ".cm-mardora-toc-item[data-mardora-toc-level='6']": { paddingLeft: "48px" },
708
+ ".cm-mardora-toc-item-active": {
709
+ borderLeftColor: "var(--mardora-toc-active, #18181b)",
710
+ background: "var(--mardora-toc-hover, #f4f4f5)",
711
+ color: "var(--mardora-toc-active, #18181b)",
712
+ fontWeight: "600"
713
+ },
714
+ ".cm-mardora-toc-empty": {
715
+ padding: "12px 8px",
716
+ color: "var(--mardora-toc-muted, #71717a)",
717
+ fontSize: "13px"
718
+ },
719
+ ".cm-mardora-toc-resizing": {
720
+ userSelect: "none"
721
+ },
722
+ "&dark .cm-mardora-toc": {
723
+ "--mardora-toc-bg": "#18181b",
724
+ "--mardora-toc-fg": "#f4f4f5",
725
+ "--mardora-toc-border": "#3f3f46",
726
+ "--mardora-toc-handle": "#52525b",
727
+ "--mardora-toc-hover": "#27272a",
728
+ "--mardora-toc-muted": "#a1a1aa",
729
+ "--mardora-toc-active": "#f4f4f5",
730
+ "--mardora-toc-scrollbar": "#52525b"
731
+ }
732
+ });
733
+ function sameItems(a, b) {
734
+ return JSON.stringify(a) === JSON.stringify(b);
735
+ }
736
+ var TocViewPlugin = class {
737
+ constructor(view, rawConfig) {
738
+ this.view = view;
739
+ this.config = resolveTocConfig(rawConfig);
740
+ const stored = readTocPanelState(this.config.storageKey);
741
+ this.panelState = {
742
+ expanded: stored?.expanded ?? this.config.defaultExpanded,
743
+ width: clampTocWidth(stored?.width ?? this.config.defaultWidth, this.config)
744
+ };
745
+ this.view.scrollDOM.addEventListener("scroll", this.handleScroll, { passive: true });
746
+ this.recompute();
747
+ this.scheduleRender();
748
+ this.scheduleActiveMeasure();
749
+ }
750
+ view;
751
+ panel = null;
752
+ config;
753
+ panelState;
754
+ items = [];
755
+ renderFrame = null;
756
+ measureKey = {};
757
+ update(update) {
758
+ if (update.docChanged) {
759
+ this.recompute();
760
+ return;
761
+ }
762
+ if (update.viewportChanged || update.geometryChanged) this.scheduleActiveMeasure();
763
+ }
764
+ destroy() {
765
+ this.view.scrollDOM.removeEventListener("scroll", this.handleScroll);
766
+ if (this.renderFrame !== null) {
767
+ this.view.dom.ownerDocument.defaultView?.cancelAnimationFrame(this.renderFrame);
768
+ this.renderFrame = null;
769
+ }
770
+ this.clearLayoutWidth();
771
+ this.panel?.remove();
772
+ this.panel = null;
773
+ }
774
+ handleScroll = () => {
775
+ this.scheduleActiveMeasure();
776
+ };
777
+ recompute() {
778
+ const next = extractTocItemsFromState(this.view.state, this.config);
779
+ this.items = this.withPreservedActive(next);
780
+ this.config.onTocChange?.(this.items);
781
+ this.render();
782
+ this.scheduleActiveMeasure();
783
+ }
784
+ withPreservedActive(items) {
785
+ if (items.length === 0) return [];
786
+ const previousActive = this.items.find((item) => item.active)?.id;
787
+ const fallbackActiveId = items[0]?.id;
788
+ const activeId = previousActive && items.some((item) => item.id === previousActive) ? previousActive : fallbackActiveId;
789
+ return items.map((item) => ({ ...item, active: item.id === activeId }));
790
+ }
791
+ scheduleActiveMeasure() {
792
+ if (this.items.length === 0 || !this.view.dom.isConnected) return;
793
+ this.view.requestMeasure({
794
+ key: this.measureKey,
795
+ read: (view) => {
796
+ const viewportTop = view.scrollDOM.getBoundingClientRect().top + 24;
797
+ let activeId = this.items[0]?.id ?? null;
798
+ for (const item of this.items) {
799
+ if (typeof item.from !== "number") continue;
800
+ const coords = view.coordsAtPos(item.from);
801
+ if (coords && coords.top <= viewportTop) activeId = item.id;
802
+ }
803
+ return activeId;
804
+ },
805
+ write: (activeId) => {
806
+ if (!activeId) return;
807
+ this.updateActiveItem(activeId);
808
+ }
809
+ });
810
+ }
811
+ updateActiveItem(activeId) {
812
+ const next = this.items.map((item) => ({ ...item, active: item.id === activeId }));
813
+ if (sameItems(next, this.items)) return;
814
+ this.items = next;
815
+ this.config.onTocChange?.(this.items);
816
+ this.render();
817
+ }
818
+ scheduleRender() {
819
+ const win = this.view.dom.ownerDocument.defaultView;
820
+ if (!win) {
821
+ this.render();
822
+ return;
823
+ }
824
+ if (this.renderFrame !== null) return;
825
+ this.renderFrame = win.requestAnimationFrame(() => {
826
+ this.renderFrame = null;
827
+ this.render();
828
+ });
829
+ }
830
+ render() {
831
+ if (!this.config.enabled) {
832
+ this.clearLayoutWidth();
833
+ this.panel?.remove();
834
+ this.panel = null;
835
+ return;
836
+ }
837
+ this.syncLayoutWidth();
838
+ const nextPanel = createTocPanelElement(
839
+ { expanded: this.panelState.expanded, width: this.panelState.width, items: this.items },
840
+ {
841
+ onSelect: (item) => this.selectItem(item),
842
+ onToggle: () => this.toggle(),
843
+ onResizeStart: (event) => this.startResize(event)
844
+ }
845
+ );
846
+ if (this.panel?.isConnected) {
847
+ this.panel.replaceWith(nextPanel);
848
+ } else {
849
+ this.view.dom.appendChild(nextPanel);
850
+ }
851
+ this.panel = nextPanel;
852
+ }
853
+ selectItem(item) {
854
+ if (typeof item.from !== "number") return;
855
+ this.view.dispatch({
856
+ selection: state.EditorSelection.cursor(item.from),
857
+ effects: view.EditorView.scrollIntoView(item.from, { y: "start" })
858
+ });
859
+ this.view.focus();
860
+ this.updateActiveItem(item.id);
861
+ this.scheduleActiveMeasure();
862
+ }
863
+ persistPanelState() {
864
+ writeTocPanelState(this.config.storageKey, this.panelState);
865
+ }
866
+ toggle() {
867
+ this.panelState = { ...this.panelState, expanded: !this.panelState.expanded };
868
+ this.persistPanelState();
869
+ this.render();
870
+ }
871
+ syncLayoutWidth() {
872
+ const layoutWidth = this.panelState.expanded ? this.panelState.width : 42;
873
+ this.view.dom.style.setProperty("--mardora-toc-layout-width", `${layoutWidth}px`);
874
+ this.view.dom.style.setProperty("--mardora-toc-scrollbar-gutter", "14px");
875
+ }
876
+ clearLayoutWidth() {
877
+ this.view.dom.style.removeProperty("--mardora-toc-layout-width");
878
+ this.view.dom.style.removeProperty("--mardora-toc-scrollbar-gutter");
879
+ }
880
+ startResize(event) {
881
+ event.preventDefault();
882
+ const startX = event.clientX;
883
+ const startWidth = this.panelState.width;
884
+ const doc = this.view.dom.ownerDocument;
885
+ doc.body.classList.add("cm-mardora-toc-resizing");
886
+ const move = (moveEvent) => {
887
+ const nextWidth = clampTocWidth(startWidth - (moveEvent.clientX - startX), this.config);
888
+ this.panelState = { ...this.panelState, width: nextWidth };
889
+ this.render();
890
+ };
891
+ const up = () => {
892
+ doc.body.classList.remove("cm-mardora-toc-resizing");
893
+ doc.removeEventListener("mousemove", move);
894
+ doc.removeEventListener("mouseup", up);
895
+ this.persistPanelState();
896
+ };
897
+ doc.addEventListener("mousemove", move);
898
+ doc.addEventListener("mouseup", up);
899
+ }
900
+ };
901
+ function tableOfContents(config = {}) {
902
+ return [tocTheme, state.Prec.low(view.ViewPlugin.define((view) => new TocViewPlugin(view, config)))];
903
+ }
904
+
905
+ exports.ThemeEnum = ThemeEnum;
906
+ exports.clampTocWidth = clampTocWidth;
907
+ exports.createMardoraIcon = createMardoraIcon;
908
+ exports.createTheme = createTheme;
909
+ exports.createTocPanelElement = createTocPanelElement;
910
+ exports.createTocSlugger = createTocSlugger;
911
+ exports.cursorInRange = cursorInRange;
912
+ exports.deepMerge = deepMerge;
913
+ exports.extractTocItemsFromState = extractTocItemsFromState;
914
+ exports.fixSelector = fixSelector;
915
+ exports.flattenThemeStyles = flattenThemeStyles;
916
+ exports.hasMardoraIcon = hasMardoraIcon;
917
+ exports.readTocPanelState = readTocPanelState;
918
+ exports.resolveTocConfig = resolveTocConfig;
919
+ exports.selectionOverlapsRange = selectionOverlapsRange;
920
+ exports.stripMarkdownHeadingText = stripMarkdownHeadingText;
921
+ exports.tableOfContents = tableOfContents;
922
+ exports.tocTheme = tocTheme;
923
+ exports.toggleMarkdownStyle = toggleMarkdownStyle;
924
+ exports.writeTocPanelState = writeTocPanelState;
925
+ //# sourceMappingURL=chunk-WFVCG4LD.cjs.map
926
+ //# sourceMappingURL=chunk-WFVCG4LD.cjs.map