@damiro/stylo 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/dist/InPlaceView-Ba7JCZ2Y.js +2346 -0
  4. package/dist/InPlaceView-Ba7JCZ2Y.js.map +1 -0
  5. package/dist/Preview-Dxb9zPVv.js +93 -0
  6. package/dist/Preview-Dxb9zPVv.js.map +1 -0
  7. package/dist/SplitView.d.ts +23 -0
  8. package/dist/SplitView.d.ts.map +1 -0
  9. package/dist/Stylo.d.ts +15 -0
  10. package/dist/Stylo.d.ts.map +1 -0
  11. package/dist/callout-oLE630ZP.js +37 -0
  12. package/dist/callout-oLE630ZP.js.map +1 -0
  13. package/dist/callout.d.ts +18 -0
  14. package/dist/callout.d.ts.map +1 -0
  15. package/dist/config-DTBxVhtH.js +101 -0
  16. package/dist/config-DTBxVhtH.js.map +1 -0
  17. package/dist/editor/SourceView.d.ts +17 -0
  18. package/dist/editor/SourceView.d.ts.map +1 -0
  19. package/dist/editor/extensions.d.ts +20 -0
  20. package/dist/editor/extensions.d.ts.map +1 -0
  21. package/dist/editor/highlight.d.ts +19 -0
  22. package/dist/editor/highlight.d.ts.map +1 -0
  23. package/dist/editor/save.d.ts +12 -0
  24. package/dist/editor/save.d.ts.map +1 -0
  25. package/dist/editor/theme.d.ts +3 -0
  26. package/dist/editor/theme.d.ts.map +1 -0
  27. package/dist/editor/useCodeMirror.d.ts +26 -0
  28. package/dist/editor/useCodeMirror.d.ts.map +1 -0
  29. package/dist/frontmatter.d.ts +21 -0
  30. package/dist/frontmatter.d.ts.map +1 -0
  31. package/dist/index.d.ts +4 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/inplace/InPlaceView.d.ts +30 -0
  34. package/dist/inplace/InPlaceView.d.ts.map +1 -0
  35. package/dist/inplace/autoformat.d.ts +23 -0
  36. package/dist/inplace/autoformat.d.ts.map +1 -0
  37. package/dist/inplace/config.d.ts +57 -0
  38. package/dist/inplace/config.d.ts.map +1 -0
  39. package/dist/inplace/context-menu-actions.d.ts +53 -0
  40. package/dist/inplace/context-menu-actions.d.ts.map +1 -0
  41. package/dist/inplace/context-menu.d.ts +50 -0
  42. package/dist/inplace/context-menu.d.ts.map +1 -0
  43. package/dist/inplace/decorate.d.ts +17 -0
  44. package/dist/inplace/decorate.d.ts.map +1 -0
  45. package/dist/inplace/edit-boundaries.d.ts +59 -0
  46. package/dist/inplace/edit-boundaries.d.ts.map +1 -0
  47. package/dist/inplace/edit-insert-assoc.d.ts +17 -0
  48. package/dist/inplace/edit-insert-assoc.d.ts.map +1 -0
  49. package/dist/inplace/edit-line-prefix.d.ts +23 -0
  50. package/dist/inplace/edit-line-prefix.d.ts.map +1 -0
  51. package/dist/inplace/extension.d.ts +21 -0
  52. package/dist/inplace/extension.d.ts.map +1 -0
  53. package/dist/inplace/frontmatter.d.ts +13 -0
  54. package/dist/inplace/frontmatter.d.ts.map +1 -0
  55. package/dist/inplace/inline-md.d.ts +13 -0
  56. package/dist/inplace/inline-md.d.ts.map +1 -0
  57. package/dist/inplace/lazyInPlace.d.ts +7 -0
  58. package/dist/inplace/lazyInPlace.d.ts.map +1 -0
  59. package/dist/inplace/link-click.d.ts +24 -0
  60. package/dist/inplace/link-click.d.ts.map +1 -0
  61. package/dist/inplace/link-hover.d.ts +11 -0
  62. package/dist/inplace/link-hover.d.ts.map +1 -0
  63. package/dist/inplace/list-guides.d.ts +16 -0
  64. package/dist/inplace/list-guides.d.ts.map +1 -0
  65. package/dist/inplace/long-press.d.ts +39 -0
  66. package/dist/inplace/long-press.d.ts.map +1 -0
  67. package/dist/inplace/math.d.ts +16 -0
  68. package/dist/inplace/math.d.ts.map +1 -0
  69. package/dist/inplace/menu-plugin.d.ts +30 -0
  70. package/dist/inplace/menu-plugin.d.ts.map +1 -0
  71. package/dist/inplace/nodes.d.ts +24 -0
  72. package/dist/inplace/nodes.d.ts.map +1 -0
  73. package/dist/inplace/plugin.d.ts +21 -0
  74. package/dist/inplace/plugin.d.ts.map +1 -0
  75. package/dist/inplace/reveal.d.ts +8 -0
  76. package/dist/inplace/reveal.d.ts.map +1 -0
  77. package/dist/inplace/scan.d.ts +11 -0
  78. package/dist/inplace/scan.d.ts.map +1 -0
  79. package/dist/inplace/selection-bar.d.ts +38 -0
  80. package/dist/inplace/selection-bar.d.ts.map +1 -0
  81. package/dist/inplace/table-cell-dom.d.ts +30 -0
  82. package/dist/inplace/table-cell-dom.d.ts.map +1 -0
  83. package/dist/inplace/table-enter.d.ts +22 -0
  84. package/dist/inplace/table-enter.d.ts.map +1 -0
  85. package/dist/inplace/table-gizmos.d.ts +55 -0
  86. package/dist/inplace/table-gizmos.d.ts.map +1 -0
  87. package/dist/inplace/table-structure.d.ts +23 -0
  88. package/dist/inplace/table-structure.d.ts.map +1 -0
  89. package/dist/inplace/table-widget.d.ts +81 -0
  90. package/dist/inplace/table-widget.d.ts.map +1 -0
  91. package/dist/inplace/tables.d.ts +8 -0
  92. package/dist/inplace/tables.d.ts.map +1 -0
  93. package/dist/inplace/theme.d.ts +14 -0
  94. package/dist/inplace/theme.d.ts.map +1 -0
  95. package/dist/inplace/widgets.d.ts +25 -0
  96. package/dist/inplace/widgets.d.ts.map +1 -0
  97. package/dist/inplace/wikilinks.d.ts +10 -0
  98. package/dist/inplace/wikilinks.d.ts.map +1 -0
  99. package/dist/katex-BfiLlqfN.js +21979 -0
  100. package/dist/katex-BfiLlqfN.js.map +1 -0
  101. package/dist/katex.css +3 -0
  102. package/dist/markdown-N3lRmU2n.js +8524 -0
  103. package/dist/markdown-N3lRmU2n.js.map +1 -0
  104. package/dist/render/Preview.d.ts +10 -0
  105. package/dist/render/Preview.d.ts.map +1 -0
  106. package/dist/render/lazyPreview.d.ts +8 -0
  107. package/dist/render/lazyPreview.d.ts.map +1 -0
  108. package/dist/render/remark-callout.d.ts +10 -0
  109. package/dist/render/remark-callout.d.ts.map +1 -0
  110. package/dist/render/remark-wikilink.d.ts +8 -0
  111. package/dist/render/remark-wikilink.d.ts.map +1 -0
  112. package/dist/styles.css +2 -0
  113. package/dist/stylo.js +293 -0
  114. package/dist/stylo.js.map +1 -0
  115. package/dist/toolbar/Toolbar.d.ts +28 -0
  116. package/dist/toolbar/Toolbar.d.ts.map +1 -0
  117. package/dist/toolbar/block.d.ts +56 -0
  118. package/dist/toolbar/block.d.ts.map +1 -0
  119. package/dist/toolbar/cell-inline.d.ts +16 -0
  120. package/dist/toolbar/cell-inline.d.ts.map +1 -0
  121. package/dist/toolbar/commands.d.ts +25 -0
  122. package/dist/toolbar/commands.d.ts.map +1 -0
  123. package/dist/toolbar/config.d.ts +21 -0
  124. package/dist/toolbar/config.d.ts.map +1 -0
  125. package/dist/toolbar/fence.d.ts +28 -0
  126. package/dist/toolbar/fence.d.ts.map +1 -0
  127. package/dist/toolbar/floating-watchdog.d.ts +18 -0
  128. package/dist/toolbar/floating-watchdog.d.ts.map +1 -0
  129. package/dist/toolbar/icon-paths.d.ts +10 -0
  130. package/dist/toolbar/icon-paths.d.ts.map +1 -0
  131. package/dist/toolbar/icons.d.ts +10 -0
  132. package/dist/toolbar/icons.d.ts.map +1 -0
  133. package/dist/toolbar/inline-ops.d.ts +101 -0
  134. package/dist/toolbar/inline-ops.d.ts.map +1 -0
  135. package/dist/toolbar/inline.d.ts +38 -0
  136. package/dist/toolbar/inline.d.ts.map +1 -0
  137. package/dist/toolbar/keyboard-inset.d.ts +10 -0
  138. package/dist/toolbar/keyboard-inset.d.ts.map +1 -0
  139. package/dist/toolbar/keymap.d.ts +8 -0
  140. package/dist/toolbar/keymap.d.ts.map +1 -0
  141. package/dist/toolbar/labels.d.ts +16 -0
  142. package/dist/toolbar/labels.d.ts.map +1 -0
  143. package/dist/toolbar/table-grid.d.ts +23 -0
  144. package/dist/toolbar/table-grid.d.ts.map +1 -0
  145. package/dist/toolbar/table.d.ts +35 -0
  146. package/dist/toolbar/table.d.ts.map +1 -0
  147. package/dist/toolbar-settings/SortableRow.d.ts +15 -0
  148. package/dist/toolbar-settings/SortableRow.d.ts.map +1 -0
  149. package/dist/toolbar-settings/StyloToolbarSettings.d.ts +29 -0
  150. package/dist/toolbar-settings/StyloToolbarSettings.d.ts.map +1 -0
  151. package/dist/toolbar-settings/index.d.ts +3 -0
  152. package/dist/toolbar-settings/index.d.ts.map +1 -0
  153. package/dist/toolbar-settings/items.d.ts +24 -0
  154. package/dist/toolbar-settings/items.d.ts.map +1 -0
  155. package/dist/toolbar-settings.js +269 -0
  156. package/dist/toolbar-settings.js.map +1 -0
  157. package/dist/types.d.ts +264 -0
  158. package/dist/types.d.ts.map +1 -0
  159. package/dist/useCodeMirror-YnIFkvKn.js +1361 -0
  160. package/dist/useCodeMirror-YnIFkvKn.js.map +1 -0
  161. package/dist/wikilink-BFpTehto.js +42 -0
  162. package/dist/wikilink-BFpTehto.js.map +1 -0
  163. package/dist/wikilink.d.ts +11 -0
  164. package/dist/wikilink.d.ts.map +1 -0
  165. package/package.json +122 -0
@@ -0,0 +1,1361 @@
1
+ import { n as e, t } from "./wikilink-BFpTehto.js";
2
+ import { useEffect as n, useRef as r } from "react";
3
+ import { EditorView as i, keymap as a, placeholder as o } from "@codemirror/view";
4
+ import { Annotation as s, ChangeSet as c, Compartment as l, EditorSelection as u, EditorState as d, Facet as f, Prec as p } from "@codemirror/state";
5
+ import { defaultKeymap as ee, history as m, historyKeymap as h, redo as g, undo as _ } from "@codemirror/commands";
6
+ import { markdown as v, markdownLanguage as y } from "@codemirror/lang-markdown";
7
+ import { openSearchPanel as b, search as x, searchKeymap as te } from "@codemirror/search";
8
+ import { HighlightStyle as ne, syntaxHighlighting as re, syntaxTree as ie } from "@codemirror/language";
9
+ import { tags as S } from "@lezer/highlight";
10
+ //#region src/editor/save.ts
11
+ var C = f.define({ combine: (e) => e[0] ?? null });
12
+ function ae(e) {
13
+ let t = e.state.facet(C);
14
+ return t ? (t(e.state.doc.toString()), !0) : !1;
15
+ }
16
+ //#endregion
17
+ //#region src/toolbar/block.ts
18
+ function w(e) {
19
+ let { from: t, to: n } = e.selection.main;
20
+ return [e.doc.lineAt(t).number, e.doc.lineAt(n).number];
21
+ }
22
+ function oe(e, t) {
23
+ let n = "#".repeat(t) + " ", r = e.state, [i, a] = w(r), o = [];
24
+ for (let e = i; e <= a; e++) {
25
+ let i = r.doc.line(e), a = /^(#{1,6}) +/.exec(i.text);
26
+ a && a[1].length === t ? o.push({
27
+ from: i.from,
28
+ to: i.from + a[0].length
29
+ }) : a ? o.push({
30
+ from: i.from,
31
+ to: i.from + a[0].length,
32
+ insert: n
33
+ }) : o.push({
34
+ from: i.from,
35
+ insert: n
36
+ });
37
+ }
38
+ return e.dispatch({
39
+ changes: o,
40
+ scrollIntoView: !0
41
+ }), e.focus(), !0;
42
+ }
43
+ function se(e) {
44
+ let t = e.state, [n, r] = w(t), i = [];
45
+ for (let e = n; e <= r; e++) {
46
+ let n = t.doc.line(e), r = /^#{1,6} +/.exec(n.text);
47
+ r && i.push({
48
+ from: n.from,
49
+ to: n.from + r[0].length
50
+ });
51
+ }
52
+ return i.length ? (e.dispatch({
53
+ changes: i,
54
+ scrollIntoView: !0
55
+ }), e.focus(), !0) : !1;
56
+ }
57
+ function ce(e, t) {
58
+ let n = e.state, [r, i] = w(n), a = r === i && !n.doc.line(r).text.trim(), o = !a;
59
+ for (let e = r; e <= i && o; e++) {
60
+ let r = n.doc.line(e).text;
61
+ r.trim() && !t.match.test(r) && (o = !1);
62
+ }
63
+ let s = [], c = 0;
64
+ for (let e = r; e <= i; e++) {
65
+ let r = n.doc.line(e);
66
+ if (!r.text.trim() && !a) continue;
67
+ let i = t.match.exec(r.text);
68
+ if (o) {
69
+ i && s.push({
70
+ from: r.from,
71
+ to: r.from + i[0].length
72
+ });
73
+ continue;
74
+ }
75
+ if (i) continue;
76
+ let l = typeof t.insert == "function" ? t.insert(c++) : t.insert, u = t.siblings?.exec(r.text);
77
+ if (u) s.push({
78
+ from: r.from + (u[1] ?? "").length,
79
+ to: r.from + u[0].length,
80
+ insert: l
81
+ });
82
+ else {
83
+ let e = /^\s*/.exec(r.text)[0].length;
84
+ s.push({
85
+ from: r.from + e,
86
+ insert: l
87
+ });
88
+ }
89
+ }
90
+ return s.length ? (e.dispatch({
91
+ changes: s,
92
+ scrollIntoView: !0
93
+ }), e.focus(), !0) : !1;
94
+ }
95
+ function le(e, t) {
96
+ return t.test(e.doc.lineAt(e.selection.main.head).text);
97
+ }
98
+ var ue = /^ {0,3}([-*_])[ \t]*(?:\1[ \t]*){2,}$/;
99
+ function de(e) {
100
+ let t = e.state, n = t.doc.lineAt(t.selection.main.head);
101
+ return ue.test(n.text) ? e.dispatch({
102
+ changes: {
103
+ from: n.from,
104
+ to: Math.min(n.to + 1, t.doc.length)
105
+ },
106
+ scrollIntoView: !0
107
+ }) : n.text.trim() === "" ? e.dispatch({
108
+ changes: {
109
+ from: n.from,
110
+ to: n.to,
111
+ insert: "---"
112
+ },
113
+ selection: u.cursor(n.from + 3),
114
+ scrollIntoView: !0
115
+ }) : e.dispatch({
116
+ changes: {
117
+ from: n.to,
118
+ insert: "\n\n---\n"
119
+ },
120
+ selection: u.cursor(n.to + 6),
121
+ scrollIntoView: !0
122
+ }), e.focus(), !0;
123
+ }
124
+ function fe(e) {
125
+ return ue.test(e.doc.lineAt(e.selection.main.head).text);
126
+ }
127
+ function pe(t) {
128
+ let n = t.state, r = e(n.doc);
129
+ if (r) {
130
+ let e = n.doc.lineAt(r.from), i = n.doc.lineAt(r.to);
131
+ t.dispatch({
132
+ changes: [{
133
+ from: e.from,
134
+ to: Math.min(e.to + 1, n.doc.length)
135
+ }, {
136
+ from: i.from,
137
+ to: Math.min(i.to + 1, n.doc.length)
138
+ }],
139
+ scrollIntoView: !0
140
+ });
141
+ } else {
142
+ let e = n.doc.lineAt(n.selection.main.to).number;
143
+ t.dispatch({
144
+ changes: [{
145
+ from: 0,
146
+ insert: "---\n"
147
+ }, {
148
+ from: n.doc.line(e).to,
149
+ insert: "\n---"
150
+ }],
151
+ selection: u.cursor(4),
152
+ scrollIntoView: !0
153
+ });
154
+ }
155
+ return t.focus(), !0;
156
+ }
157
+ function me(t) {
158
+ return e(t.doc) !== null;
159
+ }
160
+ //#endregion
161
+ //#region src/toolbar/inline-ops.ts
162
+ function T(e) {
163
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
164
+ }
165
+ function he(e, t, n) {
166
+ let r = t, i = t;
167
+ if (n < 0) for (; r > 0 && "*~`$".includes(e[r - 1]);) r--;
168
+ else for (; i < e.length && "*~`$".includes(e[i]);) i++;
169
+ return {
170
+ text: e.slice(r, n < 0 ? t : i),
171
+ from: r
172
+ };
173
+ }
174
+ function ge(e, t) {
175
+ let n = [];
176
+ for (let r = 0; r < e.length;) {
177
+ if (e[r] !== t) {
178
+ r++;
179
+ continue;
180
+ }
181
+ let i = 0;
182
+ for (; e[r + i] === t;) i++;
183
+ n.push({
184
+ start: r,
185
+ len: i
186
+ }), r += i;
187
+ }
188
+ return n;
189
+ }
190
+ function _e(e, t, n) {
191
+ return e < n || t < n ? !1 : n > 1 || e % 2 == 1 && t % 2 == 1;
192
+ }
193
+ function ve(e, t, n, r) {
194
+ let i = r.length, a = r[0], o = e.slice(t, n), s = 0;
195
+ for (; o[s] === a;) s++;
196
+ let c = 0;
197
+ for (; o[o.length - 1 - c] === a;) c++;
198
+ if (o.length >= 2 * i && o.startsWith(r) && o.endsWith(r) && _e(s, c, i)) return {
199
+ changes: [{
200
+ from: t,
201
+ to: t + i,
202
+ insert: ""
203
+ }, {
204
+ from: n - i,
205
+ to: n,
206
+ insert: ""
207
+ }],
208
+ from: t,
209
+ to: n - 2 * i
210
+ };
211
+ let l = he(e, t, -1), u = he(e, n, 1), d = ge(l.text, a), f = ge(u.text, a).reverse();
212
+ for (let e = 0; e < Math.min(d.length, f.length); e++) {
213
+ let r = d[e], a = f[e];
214
+ if (!_e(r.len, a.len, i)) continue;
215
+ let o = l.from + r.start + r.len, s = n + a.start;
216
+ return {
217
+ changes: [{
218
+ from: o - i,
219
+ to: o,
220
+ insert: ""
221
+ }, {
222
+ from: s,
223
+ to: s + i,
224
+ insert: ""
225
+ }],
226
+ from: t - i,
227
+ to: n - i
228
+ };
229
+ }
230
+ return {
231
+ changes: [{
232
+ from: t,
233
+ to: t,
234
+ insert: r
235
+ }, {
236
+ from: n,
237
+ to: n,
238
+ insert: r
239
+ }],
240
+ from: t + i,
241
+ to: n + i
242
+ };
243
+ }
244
+ function ye(e, t) {
245
+ let n = e;
246
+ for (let e of [...t].sort((e, t) => t.from - e.from)) n = n.slice(0, e.from) + e.insert + n.slice(e.to);
247
+ return n;
248
+ }
249
+ function E(e, t, n, r) {
250
+ let i = ve(e, t, n, r);
251
+ return {
252
+ text: ye(e, i.changes),
253
+ from: i.from,
254
+ to: i.to
255
+ };
256
+ }
257
+ function be(e, t) {
258
+ let n = D(e, t);
259
+ if (n) return {
260
+ from: n.from,
261
+ to: n.to
262
+ };
263
+ let r = k(e, t);
264
+ if (r) return {
265
+ from: r.from,
266
+ to: r.to
267
+ };
268
+ let i = null;
269
+ for (let n of [
270
+ "**",
271
+ "~~",
272
+ "*",
273
+ "`"
274
+ ]) {
275
+ let r = RegExp(T(n) + "(?!\\s)(?:[^]*?\\S)??" + T(n), "g");
276
+ for (let a; a = r.exec(e);) {
277
+ if (a[0].length <= 2 * n.length) continue;
278
+ let e = a.index + n.length, r = a.index + a[0].length - n.length;
279
+ t >= e && t <= r && (!i || r - e < i.to - i.from) && (i = {
280
+ from: e,
281
+ to: r
282
+ });
283
+ }
284
+ }
285
+ return i;
286
+ }
287
+ function D(e, t) {
288
+ let n = /\[([^\]]*)\]\([^)]*\)/g;
289
+ for (let r; r = n.exec(e);) {
290
+ let e = r.index, n = e + r[0].length;
291
+ if (t >= e && t <= n) return {
292
+ from: e,
293
+ to: n,
294
+ label: r[1] ?? ""
295
+ };
296
+ }
297
+ return null;
298
+ }
299
+ function xe(e, t) {
300
+ let n = /\[([^\]]*)\]\(([^)]*)\)/g;
301
+ for (let r; r = n.exec(e);) {
302
+ let e = r.index, n = e + r[0].length;
303
+ if (t >= e && t <= n) {
304
+ let t = r[1] ?? "", i = r[2] ?? "", a = e + 1 + t.length + 2;
305
+ return {
306
+ from: e,
307
+ to: n,
308
+ label: t,
309
+ url: i,
310
+ urlFrom: a,
311
+ urlTo: a + i.length
312
+ };
313
+ }
314
+ }
315
+ return null;
316
+ }
317
+ function Se(e, t, n) {
318
+ let r = D(e, t);
319
+ if (r) return {
320
+ text: e.slice(0, r.from) + r.label + e.slice(r.to),
321
+ from: r.from,
322
+ to: r.from + r.label.length
323
+ };
324
+ let i = e.slice(t, n) || "text", a = t + i.length + 3;
325
+ return {
326
+ text: e.slice(0, t) + `[${i}](url)` + e.slice(n),
327
+ from: a,
328
+ to: a + 3
329
+ };
330
+ }
331
+ function Ce(e, t) {
332
+ let n = /<u>([\s\S]*?)<\/u>/gi;
333
+ for (let r; r = n.exec(e);) {
334
+ let e = r.index, n = e + r[0].length;
335
+ if (t >= e && t <= n) return {
336
+ from: e,
337
+ to: n,
338
+ inner: r[1] ?? ""
339
+ };
340
+ }
341
+ return null;
342
+ }
343
+ function we(e, t, n) {
344
+ let r = Ce(e, t);
345
+ if (r) return {
346
+ text: e.slice(0, r.from) + r.inner + e.slice(r.to),
347
+ from: r.from,
348
+ to: r.from + r.inner.length
349
+ };
350
+ let i = e.slice(t, n) || "text";
351
+ return {
352
+ text: e.slice(0, t) + `<u>${i}</u>` + e.slice(n),
353
+ from: t + 3,
354
+ to: t + 3 + i.length
355
+ };
356
+ }
357
+ function O(e, n) {
358
+ for (let r of e.matchAll(t)) {
359
+ let e = r.index ?? 0, t = e + r[0].length;
360
+ if (n >= e && n <= t) return {
361
+ from: e,
362
+ to: t,
363
+ label: r[2] || r[1] || ""
364
+ };
365
+ }
366
+ return null;
367
+ }
368
+ function k(e, n) {
369
+ for (let r of e.matchAll(t)) {
370
+ let e = r.index ?? 0, t = e + r[0].length;
371
+ if (n < e || n > t) continue;
372
+ let i = r[1] ?? "", a = e + 2;
373
+ return {
374
+ from: e,
375
+ to: t,
376
+ target: i,
377
+ label: r[2] ?? "",
378
+ targetFrom: a,
379
+ targetTo: a + i.length
380
+ };
381
+ }
382
+ return null;
383
+ }
384
+ function Te(e, t, n) {
385
+ let r = O(e, t);
386
+ if (r) return {
387
+ text: e.slice(0, r.from) + r.label + e.slice(r.to),
388
+ from: r.from,
389
+ to: r.from + r.label.length
390
+ };
391
+ let i = e.slice(t, n) || "target";
392
+ return {
393
+ text: e.slice(0, t) + `[[${i}]]` + e.slice(n),
394
+ from: t + 2,
395
+ to: t + 2 + i.length
396
+ };
397
+ }
398
+ //#endregion
399
+ //#region src/inplace/table-cell-dom.ts
400
+ var Ee = (e) => [e.head, ...e.body].map((e) => [...e]), De = (e) => e.map((e) => e.map((e) => e.trim())), Oe = (e) => e.replace(/\\\|/g, "|");
401
+ function A(e, t) {
402
+ let n = e.ownerDocument.createTreeWalker(e, NodeFilter.SHOW_TEXT), r = 0;
403
+ for (let e = n.nextNode(); e; e = n.nextNode()) {
404
+ if (e === t) return r;
405
+ r += e.textContent?.length ?? 0;
406
+ }
407
+ return r;
408
+ }
409
+ function ke(e) {
410
+ let t = e.ownerDocument.getSelection(), n = t?.anchorNode;
411
+ return !n || !e.contains(n) ? 0 : n.nodeType === Node.TEXT_NODE ? A(e, n) + (t?.anchorOffset ?? 0) : (t?.anchorOffset ?? 0) > 0 ? (e.textContent ?? "").length : 0;
412
+ }
413
+ function Ae(e) {
414
+ let t = e.ownerDocument.getSelection(), n = (e.textContent ?? "").length, r = (t, r) => !t || !e.contains(t) ? n : t.nodeType === Node.TEXT_NODE ? A(e, t) + r : r > 0 ? n : 0;
415
+ if (!t || t.rangeCount === 0) return {
416
+ from: n,
417
+ to: n
418
+ };
419
+ let i = r(t.anchorNode, t.anchorOffset), a = r(t.focusNode, t.focusOffset);
420
+ return {
421
+ from: Math.min(i, a),
422
+ to: Math.max(i, a)
423
+ };
424
+ }
425
+ function je(e, t, n) {
426
+ let r = e.ownerDocument, i = null, a = 0;
427
+ if (r.caretPositionFromPoint) {
428
+ let e = r.caretPositionFromPoint(t, n);
429
+ e && ([i, a] = [e.offsetNode, e.offset]);
430
+ } else if (r.caretRangeFromPoint) {
431
+ let e = r.caretRangeFromPoint(t, n);
432
+ e && ([i, a] = [e.startContainer, e.startOffset]);
433
+ }
434
+ return !i || !e.contains(i) ? 0 : A(e, i) + (i.nodeType === Node.TEXT_NODE ? a : 0);
435
+ }
436
+ var Me = /[\p{L}\p{N}_]/u;
437
+ function Ne(e, t, n) {
438
+ let r = e.textContent ?? "", i = je(e, t, n), a = be(r, i);
439
+ if (a) return j(e, a.from, a.to), !0;
440
+ let o = i, s = i;
441
+ for (; o > 0 && Me.test(r[o - 1]);) o--;
442
+ for (; s < r.length && Me.test(r[s]);) s++;
443
+ return s <= o ? !1 : (j(e, o, s), !0);
444
+ }
445
+ function j(e, t, n = t) {
446
+ e.focus();
447
+ let r = e.ownerDocument, i = r.createRange(), a = e.firstChild;
448
+ if (a && a.nodeType === Node.TEXT_NODE) {
449
+ let e = a.textContent?.length ?? 0;
450
+ i.setStart(a, Math.min(Math.min(t, n), e)), i.setEnd(a, Math.min(Math.max(t, n), e));
451
+ } else i.selectNodeContents(e);
452
+ t === n && i.collapse(!0);
453
+ let o = r.getSelection();
454
+ o?.removeAllRanges(), o?.addRange(i);
455
+ }
456
+ //#endregion
457
+ //#region src/toolbar/cell-inline.ts
458
+ function Pe(e) {
459
+ let t = e.dom.ownerDocument.activeElement;
460
+ return !(t instanceof HTMLElement) || !e.dom.contains(t) ? null : t.matches(".cm-inplace-tcell") ? t : null;
461
+ }
462
+ function Fe(e, t) {
463
+ let { from: n, to: r } = Ae(e), i = t(e.textContent ?? "", n, r);
464
+ e.textContent = i.text, j(e, i.from, i.to), e.dispatchEvent(new Event("input", { bubbles: !0 }));
465
+ }
466
+ function M(e, t) {
467
+ let n = Pe(e);
468
+ return n ? (Fe(n, t), !0) : !1;
469
+ }
470
+ var Ie = {
471
+ b: (e, t, n) => E(e, t, n, "**"),
472
+ i: (e, t, n) => E(e, t, n, "*"),
473
+ u: we,
474
+ k: Se,
475
+ K: Te
476
+ };
477
+ function Le(e, t) {
478
+ if (!(e.metaKey || e.ctrlKey) || e.altKey) return !1;
479
+ let n = Ie[e.shiftKey ? e.key.toUpperCase() : e.key.toLowerCase()];
480
+ return n ? (e.preventDefault(), Fe(t, n), !0) : !1;
481
+ }
482
+ //#endregion
483
+ //#region src/toolbar/fence.ts
484
+ function N(e, t) {
485
+ for (let n = ie(e).resolveInner(t, 0); n; n = n.parent) {
486
+ if (n.name === "FencedCode") return {
487
+ from: n.from,
488
+ to: n.to
489
+ };
490
+ if (!n.parent) break;
491
+ }
492
+ return null;
493
+ }
494
+ function Re(e) {
495
+ let t = e.state, n = N(t, t.selection.main.head);
496
+ if (n) {
497
+ let r = t.doc.lineAt(n.from), i = t.doc.lineAt(n.to), a = [{
498
+ from: r.from,
499
+ to: Math.min(r.to + 1, t.doc.length)
500
+ }];
501
+ i.number !== r.number && a.push({
502
+ from: Math.max(i.from - 1, 0),
503
+ to: i.to
504
+ }), e.dispatch({
505
+ changes: a,
506
+ scrollIntoView: !0
507
+ });
508
+ } else {
509
+ let [n, r] = w(t);
510
+ e.dispatch({
511
+ changes: [{
512
+ from: t.doc.line(n).from,
513
+ insert: "```\n"
514
+ }, {
515
+ from: t.doc.line(r).to,
516
+ insert: "\n```"
517
+ }],
518
+ selection: { anchor: t.doc.line(n).from + 4 },
519
+ scrollIntoView: !0
520
+ });
521
+ }
522
+ return e.focus(), !0;
523
+ }
524
+ function P(e) {
525
+ return N(e, e.selection.main.head) !== null;
526
+ }
527
+ function ze(e) {
528
+ let t = N(e, e.selection.main.head);
529
+ if (!t) return null;
530
+ let n = e.doc.lineAt(t.from), r = /^(\s*(?:`{3,}|~{3,})[ \t]*)(.*?)[ \t]*$/.exec(n.text);
531
+ if (!r) return null;
532
+ let i = n.from + r[1].length;
533
+ return {
534
+ from: i,
535
+ to: i + r[2].length,
536
+ lang: r[2]
537
+ };
538
+ }
539
+ var Be = /^\s*\$\$\s*$/;
540
+ function F(e, t) {
541
+ let n = 0, r = 0;
542
+ for (let i = 1; i <= e.doc.lines; i++) if (Be.test(e.doc.line(i).text)) {
543
+ if (r++, r % 2 == 1) {
544
+ if (n = i, i > t) return null;
545
+ } else if (i >= t) return [n, i];
546
+ }
547
+ return null;
548
+ }
549
+ function Ve(e) {
550
+ let t = e.state, [n, r] = w(t), i = F(t, t.doc.lineAt(t.selection.main.head).number);
551
+ if (i) {
552
+ let n = t.doc.line(i[0]), r = t.doc.line(i[1]);
553
+ e.dispatch({
554
+ changes: [{
555
+ from: n.from,
556
+ to: Math.min(n.to + 1, t.doc.length)
557
+ }, {
558
+ from: Math.max(r.from - 1, 0),
559
+ to: r.to
560
+ }],
561
+ scrollIntoView: !0
562
+ });
563
+ } else e.dispatch({
564
+ changes: [{
565
+ from: t.doc.line(n).from,
566
+ insert: "$$\n"
567
+ }, {
568
+ from: t.doc.line(r).to,
569
+ insert: "\n$$"
570
+ }],
571
+ selection: { anchor: t.doc.line(n).from + 3 },
572
+ scrollIntoView: !0
573
+ });
574
+ return e.focus(), !0;
575
+ }
576
+ function I(e) {
577
+ return F(e, e.doc.lineAt(e.selection.main.head).number) !== null;
578
+ }
579
+ //#endregion
580
+ //#region src/toolbar/inline.ts
581
+ function L(e, t) {
582
+ let n = e.state.doc.toString();
583
+ return e.dispatch({
584
+ ...e.state.changeByRange((e) => {
585
+ let r = ve(n, e.from, e.to, t);
586
+ return {
587
+ changes: r.changes,
588
+ range: r.from === r.to ? u.cursor(r.from) : u.range(r.from, r.to)
589
+ };
590
+ }),
591
+ scrollIntoView: !0
592
+ }), e.focus(), !0;
593
+ }
594
+ function R(e, t) {
595
+ let n = e.selection.main, r = e.doc.lineAt(n.head), i = RegExp(T(t) + "(?!\\s)(?:[^]*?\\S)??" + T(t), "g");
596
+ for (let e; e = i.exec(r.text);) {
597
+ if (e[0].length <= 2 * t.length || t === "$" && (r.text[e.index - 1] === "$" || r.text[e.index + e[0].length] === "$")) continue;
598
+ let i = r.from + e.index;
599
+ if (n.from >= i && n.to <= i + e[0].length) return !0;
600
+ }
601
+ return !1;
602
+ }
603
+ function He(e) {
604
+ let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = D(n.text, t - n.from);
605
+ return r ? {
606
+ from: n.from + r.from,
607
+ to: n.from + r.to,
608
+ text: r.label
609
+ } : null;
610
+ }
611
+ function Ue(e) {
612
+ let t = He(e.state);
613
+ if (t) return e.dispatch({
614
+ changes: {
615
+ from: t.from,
616
+ to: t.to,
617
+ insert: t.text
618
+ },
619
+ selection: u.range(t.from, t.from + t.text.length),
620
+ scrollIntoView: !0
621
+ }), e.focus(), !0;
622
+ let { from: n, to: r } = e.state.selection.main, i = e.state.sliceDoc(n, r) || "text", a = n + i.length + 3;
623
+ return e.dispatch({
624
+ changes: {
625
+ from: n,
626
+ to: r,
627
+ insert: `[${i}](url)`
628
+ },
629
+ selection: u.range(a, a + 3),
630
+ scrollIntoView: !0
631
+ }), e.focus(), !0;
632
+ }
633
+ function We(e) {
634
+ return He(e) !== null;
635
+ }
636
+ function Ge(e) {
637
+ let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = O(n.text, t - n.from);
638
+ return r ? {
639
+ from: n.from + r.from,
640
+ to: n.from + r.to,
641
+ text: r.label
642
+ } : null;
643
+ }
644
+ function Ke(e) {
645
+ let t = Ge(e.state);
646
+ if (t) return e.dispatch({
647
+ changes: {
648
+ from: t.from,
649
+ to: t.to,
650
+ insert: t.text
651
+ },
652
+ selection: u.range(t.from, t.from + t.text.length),
653
+ scrollIntoView: !0
654
+ }), e.focus(), !0;
655
+ let { from: n, to: r } = e.state.selection.main, i = e.state.sliceDoc(n, r) || "target";
656
+ return e.dispatch({
657
+ changes: {
658
+ from: n,
659
+ to: r,
660
+ insert: `[[${i}]]`
661
+ },
662
+ selection: u.range(n + 2, n + 2 + i.length),
663
+ scrollIntoView: !0
664
+ }), e.focus(), !0;
665
+ }
666
+ function qe(e) {
667
+ return Ge(e) !== null;
668
+ }
669
+ function Je(e) {
670
+ let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = Ce(n.text, t - n.from);
671
+ return r ? {
672
+ from: n.from + r.from,
673
+ to: n.from + r.to,
674
+ inner: r.inner
675
+ } : null;
676
+ }
677
+ function Ye(e) {
678
+ let t = Je(e.state);
679
+ if (t) return e.dispatch({
680
+ changes: {
681
+ from: t.from,
682
+ to: t.to,
683
+ insert: t.inner
684
+ },
685
+ selection: u.range(t.from, t.from + t.inner.length),
686
+ scrollIntoView: !0
687
+ }), e.focus(), !0;
688
+ let { from: n, to: r } = e.state.selection.main, i = e.state.sliceDoc(n, r) || "text";
689
+ return e.dispatch({
690
+ changes: {
691
+ from: n,
692
+ to: r,
693
+ insert: `<u>${i}</u>`
694
+ },
695
+ selection: u.range(n + 3, n + 3 + i.length),
696
+ scrollIntoView: !0
697
+ }), e.focus(), !0;
698
+ }
699
+ function Xe(e) {
700
+ return Je(e) !== null;
701
+ }
702
+ //#endregion
703
+ //#region src/toolbar/table-grid.ts
704
+ function Ze(e) {
705
+ let t = e.trim();
706
+ return t.includes("-") && t.includes("|") && /^[\s|:-]+$/.test(t);
707
+ }
708
+ function Qe(e) {
709
+ let t = e.trim();
710
+ t.startsWith("|") && (t = t.slice(1)), t.endsWith("|") && !t.endsWith("\\|") && (t = t.slice(0, -1));
711
+ let n = [], r = "";
712
+ for (let e = 0; e < t.length; e++) t[e] === "\\" && t[e + 1] === "|" ? (r += "\\|", e++) : t[e] === "|" ? (n.push(r.trim()), r = "") : r += t[e];
713
+ return n.push(r.trim()), n;
714
+ }
715
+ function $e(e) {
716
+ let t = e.trim(), n = t.startsWith(":"), r = t.endsWith(":");
717
+ return n && r ? "center" : r ? "right" : n ? "left" : "";
718
+ }
719
+ function z(e) {
720
+ if (e.length < 2 || !Ze(e[1])) return null;
721
+ let t = Qe(e[1]).map($e), n = e.filter((e, t) => t !== 1).map(Qe), r = Math.max(t.length, ...n.map((e) => e.length)), i = n.map((e) => {
722
+ let t = e.slice(0, r);
723
+ for (; t.length < r;) t.push("");
724
+ return t;
725
+ }), a = t.slice(0, r);
726
+ for (; a.length < r;) a.push("");
727
+ return {
728
+ rows: i,
729
+ aligns: a
730
+ };
731
+ }
732
+ function et(e) {
733
+ return e.replace(/\\\|/g, "|").length;
734
+ }
735
+ function tt(e, t, n) {
736
+ let r = t - et(e);
737
+ if (r <= 0) return e;
738
+ if (n === "right") return " ".repeat(r) + e;
739
+ if (n === "center") {
740
+ let t = Math.floor(r / 2);
741
+ return " ".repeat(t) + e + " ".repeat(r - t);
742
+ }
743
+ return e + " ".repeat(r);
744
+ }
745
+ function nt(e, t) {
746
+ let n = Math.max(3, e);
747
+ return t === "left" ? ":" + "-".repeat(n - 1) : t === "right" ? "-".repeat(n - 1) + ":" : t === "center" ? ":" + "-".repeat(n - 2) + ":" : "-".repeat(n);
748
+ }
749
+ function B(e) {
750
+ let t = e.aligns.length, n = [];
751
+ for (let r = 0; r < t; r++) {
752
+ let t = 3;
753
+ for (let n of e.rows) t = Math.max(t, et(n[r] ?? ""));
754
+ n.push(t);
755
+ }
756
+ let r = (t) => "| " + t.map((t, r) => tt(t ?? "", n[r], e.aligns[r])).join(" | ") + " |", i = [r(e.rows[0] ?? [])];
757
+ i.push("| " + e.aligns.map((e, t) => nt(n[t], e)).join(" | ") + " |");
758
+ for (let t = 1; t < e.rows.length; t++) i.push(r(e.rows[t]));
759
+ return i.join("\n");
760
+ }
761
+ function rt(e) {
762
+ let t = [];
763
+ for (let n = 0; n < e.length; n++) {
764
+ if (e[n] === "\\") {
765
+ n++;
766
+ continue;
767
+ }
768
+ e[n] === "|" && t.push(n);
769
+ }
770
+ let n = [];
771
+ for (let r = 0; r < t.length - 1; r++) {
772
+ let i = t[r] + 1, a = t[r + 1], o = e.slice(i, a), s = o.length - o.trimStart().length, c = o.length - o.trimEnd().length;
773
+ n.push({
774
+ start: i,
775
+ contentStart: i + s,
776
+ contentEnd: a - c,
777
+ end: a
778
+ });
779
+ }
780
+ return n;
781
+ }
782
+ //#endregion
783
+ //#region src/toolbar/table.ts
784
+ function V(e, t) {
785
+ let n = e.lineAt(t);
786
+ if (!n.text.includes("|")) return null;
787
+ let r = n.number;
788
+ for (; r > 1;) {
789
+ let t = e.line(r - 1).text;
790
+ if (!t.includes("|") || !t.trim()) break;
791
+ r--;
792
+ }
793
+ let i = n.number;
794
+ for (; i < e.lines;) {
795
+ let t = e.line(i + 1).text;
796
+ if (!t.includes("|") || !t.trim()) break;
797
+ i++;
798
+ }
799
+ if (i - r < 1) return null;
800
+ let a = [];
801
+ for (let t = r; t <= i; t++) a.push(e.line(t).text);
802
+ return z(a) ? {
803
+ from: e.line(r).from,
804
+ to: e.line(i).to,
805
+ lines: a
806
+ } : null;
807
+ }
808
+ function it(e, t, n) {
809
+ let r = t;
810
+ for (let t = 0; t < e.length; t++) {
811
+ let i = e[t];
812
+ if (n <= r + i.length) {
813
+ let e = n - r;
814
+ if (t === 1) {
815
+ let t = 0;
816
+ for (let n = 0; n < e && n < i.length; n++) i[n] === "|" && t++;
817
+ return {
818
+ row: 0,
819
+ col: Math.max(0, t - 1),
820
+ offset: 0,
821
+ onDelimiter: !0
822
+ };
823
+ }
824
+ let a = rt(i), o = 0;
825
+ for (let t = 0; t < a.length && (o = t, !(e <= a[t].end)); t++);
826
+ let s = a[o], c = s ? Math.max(0, Math.min(e, s.contentEnd) - s.contentStart) : 0;
827
+ return {
828
+ row: t === 0 ? 0 : t - 1,
829
+ col: o,
830
+ offset: c,
831
+ onDelimiter: !1
832
+ };
833
+ }
834
+ r += i.length + 1;
835
+ }
836
+ return null;
837
+ }
838
+ function H(e, t, n) {
839
+ let r = e.split("\n"), i = n.onDelimiter ? 1 : n.row === 0 ? 0 : n.row + 1, a = t;
840
+ for (let e = 0; e < i; e++) a += r[e].length + 1;
841
+ let o = rt(r[i]), s = o[Math.min(n.col, o.length - 1)];
842
+ return s ? a + s.contentStart + Math.min(n.offset, s.contentEnd - s.contentStart) : a;
843
+ }
844
+ function at(e, t, n, r) {
845
+ let i = V(e, t);
846
+ return i ? H(i.lines.join("\n"), i.from, {
847
+ row: n,
848
+ col: r,
849
+ offset: 0,
850
+ onDelimiter: !1
851
+ }) : null;
852
+ }
853
+ function ot(e, t) {
854
+ requestAnimationFrame(() => {
855
+ let n = e.dom.querySelectorAll(".cm-inplace-table-edit");
856
+ if (n.length === 0) return;
857
+ let r = n[0], i = Infinity;
858
+ for (let a of n) {
859
+ let n = Infinity;
860
+ try {
861
+ n = Math.abs(e.posAtDOM(a) - t);
862
+ } catch {}
863
+ n < i && (i = n, r = a);
864
+ }
865
+ let a = r.querySelector("th, td");
866
+ if (!a) return;
867
+ let o = document.createRange();
868
+ o.selectNodeContents(a);
869
+ let s = a.ownerDocument.getSelection();
870
+ s?.removeAllRanges(), s?.addRange(o), a.focus();
871
+ });
872
+ }
873
+ function st(e) {
874
+ let { from: t, to: n } = e.state.selection.main, r = e.state.doc.lineAt(t), i = r.text.slice(0, t - r.from).trim() ? "\n\n" : "", a = t + i.length + 2;
875
+ return e.dispatch({
876
+ changes: {
877
+ from: t,
878
+ to: n,
879
+ insert: i + "| Column 1 | Column 2 |\n| -------- | -------- |\n| | |\n"
880
+ },
881
+ selection: u.range(a, a + 8),
882
+ scrollIntoView: !0
883
+ }), e.focus(), ot(e, a), !0;
884
+ }
885
+ function U(e) {
886
+ return V(e.doc, e.selection.main.head) !== null;
887
+ }
888
+ function W(e, t) {
889
+ let n = V(e.state.doc, e.state.selection.main.head);
890
+ if (!n) return !1;
891
+ let r = z(n.lines), i = it(n.lines, n.from, e.state.selection.main.head);
892
+ if (!r || !i) return !1;
893
+ let a = t(r, i);
894
+ if (!a) return !1;
895
+ let o = B(r);
896
+ return e.dispatch({
897
+ changes: {
898
+ from: n.from,
899
+ to: n.to,
900
+ insert: o
901
+ },
902
+ selection: u.cursor(H(o, n.from, a)),
903
+ scrollIntoView: !0
904
+ }), e.focus(), !0;
905
+ }
906
+ function ct(e, t, n) {
907
+ let r = e.aligns.length, { row: i, col: a } = t;
908
+ return a += n, a >= r ? (i++, a = 0) : a < 0 && (i--, a = r - 1), i < 0 ? null : (i >= e.rows.length && e.rows.push(Array(r).fill("")), {
909
+ row: i,
910
+ col: a,
911
+ offset: 0,
912
+ onDelimiter: !1
913
+ });
914
+ }
915
+ function lt(e, t) {
916
+ let n = t.row + 1;
917
+ return n >= e.rows.length && e.rows.push(Array(e.aligns.length).fill("")), {
918
+ row: n,
919
+ col: t.col,
920
+ offset: 0,
921
+ onDelimiter: !1
922
+ };
923
+ }
924
+ var ut = a.of([
925
+ {
926
+ key: "Tab",
927
+ run: (e) => W(e, (e, t) => ct(e, t, 1))
928
+ },
929
+ {
930
+ key: "Shift-Tab",
931
+ run: (e) => W(e, (e, t) => ct(e, t, -1))
932
+ },
933
+ {
934
+ key: "Enter",
935
+ run: (e) => W(e, lt)
936
+ }
937
+ ]), dt = d.transactionFilter.of((e) => {
938
+ if (!e.docChanged || !e.isUserEvent("input") && !e.isUserEvent("delete")) return e;
939
+ let t = e.newSelection.main.head, n = V(e.newDoc, t);
940
+ if (!n) return e;
941
+ let r = z(n.lines);
942
+ if (!r) return e;
943
+ let i = B(r);
944
+ if (i === n.lines.join("\n")) return e;
945
+ let a = it(n.lines, n.from, t), o = c.of([{
946
+ from: n.from,
947
+ to: n.to,
948
+ insert: i
949
+ }], e.newDoc.length);
950
+ return {
951
+ changes: e.changes.compose(o),
952
+ selection: a ? u.cursor(H(i, n.from, a)) : e.newSelection,
953
+ effects: e.effects,
954
+ scrollIntoView: e.scrollIntoView
955
+ };
956
+ }), G = (e) => /^\s{0,3}#{1,6}(?:\s|$)/.test(e.doc.lineAt(e.selection.main.head).text), K = (t) => {
957
+ let n = e(t.doc);
958
+ return n !== null && t.selection.main.head <= n.to;
959
+ }, q = (e) => K(e) || P(e) || I(e), ft = (e) => (t) => e !== "`" && R(t, "`") || e !== "$" && R(t, "$"), pt = (e) => e.selection.main.empty && !e.wordAt(e.selection.main.head), J = (...e) => (t) => e.some((e) => e(t)), Y = /^(\s*)(?:[-*+] \[[ xX]\] +|\d+\. +|[-*+] +)/, mt = {
960
+ match: /^ {0,3}> ?/,
961
+ insert: "> "
962
+ }, ht = {
963
+ match: /^(\s*)[-*+] +(?!\[[ xX]\])/,
964
+ insert: "- ",
965
+ siblings: Y
966
+ }, gt = {
967
+ match: /^(\s*)\d+\. +/,
968
+ insert: (e) => `${e + 1}. `,
969
+ siblings: Y
970
+ }, _t = {
971
+ match: /^(\s*)[-*+] \[[ xX]\] +/,
972
+ insert: "- [ ] ",
973
+ siblings: Y
974
+ };
975
+ function vt(e, t, n) {
976
+ return {
977
+ id: e,
978
+ title: t,
979
+ run: (e) => {
980
+ let t = n(e);
981
+ return e.focus(), t;
982
+ }
983
+ };
984
+ }
985
+ function X(e, t, n, r) {
986
+ return {
987
+ id: e,
988
+ title: t,
989
+ run: (e) => M(e, (e, t, r) => E(e, t, r, n)) || L(e, n),
990
+ isActive: (e) => R(e, n),
991
+ disabled: J(q, ft(n), pt),
992
+ keys: r
993
+ };
994
+ }
995
+ function Z(e) {
996
+ let t = RegExp(`^#{${e}} `);
997
+ return {
998
+ id: `h${e}`,
999
+ title: `Heading ${e}`,
1000
+ run: (t) => oe(t, e),
1001
+ isActive: (e) => t.test(e.doc.lineAt(e.selection.main.head).text),
1002
+ disabled: J(U, q),
1003
+ keys: [`Mod-Alt-${e}`]
1004
+ };
1005
+ }
1006
+ function Q(e, t, n, ...r) {
1007
+ return {
1008
+ id: e,
1009
+ title: t,
1010
+ run: (e) => ce(e, n),
1011
+ isActive: (e) => le(e, n.match),
1012
+ disabled: J(U, q, ...r)
1013
+ };
1014
+ }
1015
+ var yt = [
1016
+ vt("undo", "Undo", _),
1017
+ vt("redo", "Redo", g),
1018
+ {
1019
+ id: "save",
1020
+ title: "Save",
1021
+ run: (e) => {
1022
+ let t = ae(e);
1023
+ return e.focus(), t;
1024
+ },
1025
+ disabled: (e) => e.facet(C) == null
1026
+ },
1027
+ {
1028
+ id: "search",
1029
+ title: "Find / replace",
1030
+ run: (e) => b(e),
1031
+ keys: ["Mod-f"]
1032
+ },
1033
+ Z(1),
1034
+ Z(2),
1035
+ Z(3),
1036
+ {
1037
+ id: "body",
1038
+ title: "Body",
1039
+ run: (e) => (se(e) || e.focus(), !0),
1040
+ isActive: (e) => !/^#{1,6} /.test(e.doc.lineAt(e.selection.main.head).text),
1041
+ disabled: J(U, q)
1042
+ },
1043
+ X("bold", "Bold", "**", ["Mod-b"]),
1044
+ X("italic", "Italic", "*", ["Mod-i"]),
1045
+ X("strike", "Strikethrough", "~~"),
1046
+ {
1047
+ id: "underline",
1048
+ title: "Underline",
1049
+ run: (e) => M(e, we) || Ye(e),
1050
+ isActive: Xe,
1051
+ disabled: J(q, ft("u"), pt),
1052
+ keys: ["Mod-u"]
1053
+ },
1054
+ X("code", "Inline code", "`"),
1055
+ {
1056
+ id: "codeBlock",
1057
+ title: "Code block",
1058
+ run: (e) => M(e, (e, t, n) => E(e, t, n, "`")) || (U(e.state) ? L(e, "`") : Re(e)),
1059
+ isActive: (e) => U(e) ? R(e, "`") : P(e),
1060
+ disabled: J(K, I, G)
1061
+ },
1062
+ {
1063
+ id: "link",
1064
+ title: "Link",
1065
+ run: (e) => M(e, Se) || Ue(e),
1066
+ isActive: We,
1067
+ disabled: q,
1068
+ keys: ["Mod-k"]
1069
+ },
1070
+ {
1071
+ id: "wikilink",
1072
+ title: "Wikilink",
1073
+ run: (e) => M(e, Te) || Ke(e),
1074
+ isActive: qe,
1075
+ disabled: q,
1076
+ keys: ["Mod-Shift-k"]
1077
+ },
1078
+ Q("quote", "Blockquote", mt),
1079
+ Q("bulletList", "Bulleted list", ht, G),
1080
+ Q("orderedList", "Numbered list", gt, G),
1081
+ Q("task", "Task list", _t, G),
1082
+ {
1083
+ id: "hr",
1084
+ title: "Divider",
1085
+ run: de,
1086
+ isActive: fe,
1087
+ disabled: J(U, q)
1088
+ },
1089
+ {
1090
+ id: "frontmatter",
1091
+ title: "Frontmatter",
1092
+ run: pe,
1093
+ isActive: me,
1094
+ disabled: J(U, P, I, G)
1095
+ },
1096
+ {
1097
+ id: "table",
1098
+ title: "Table",
1099
+ run: st,
1100
+ isActive: U,
1101
+ disabled: J(U, K, P, I, G)
1102
+ },
1103
+ X("math", "Inline math", "$"),
1104
+ {
1105
+ id: "mathBlock",
1106
+ title: "Block math",
1107
+ run: (e) => M(e, (e, t, n) => E(e, t, n, "$")) || (U(e.state) ? L(e, "$") : Ve(e)),
1108
+ isActive: (e) => U(e) ? R(e, "$") : I(e),
1109
+ disabled: J(K, P, G)
1110
+ }
1111
+ ], bt = Object.fromEntries(yt.map((e) => [e.id, e])), xt = p.high(a.of(yt.filter((e) => e.keys && e.keys.length > 0).flatMap((e) => e.keys.map((t) => ({
1112
+ key: t,
1113
+ preventDefault: !0,
1114
+ run: ((t) => !e.disabled?.(t.state) && e.run(t))
1115
+ }))))), St = ne.define([
1116
+ {
1117
+ tag: [
1118
+ S.keyword,
1119
+ S.modifier,
1120
+ S.controlKeyword,
1121
+ S.operatorKeyword,
1122
+ S.definitionKeyword,
1123
+ S.moduleKeyword
1124
+ ],
1125
+ color: "var(--stylo-syntax-keyword)"
1126
+ },
1127
+ {
1128
+ tag: [
1129
+ S.string,
1130
+ S.special(S.string),
1131
+ S.regexp,
1132
+ S.attributeValue
1133
+ ],
1134
+ color: "var(--stylo-syntax-string)"
1135
+ },
1136
+ {
1137
+ tag: [S.escape, S.character],
1138
+ color: "var(--stylo-syntax-escape)"
1139
+ },
1140
+ {
1141
+ tag: [
1142
+ S.comment,
1143
+ S.lineComment,
1144
+ S.blockComment,
1145
+ S.docComment
1146
+ ],
1147
+ color: "var(--stylo-syntax-comment)",
1148
+ fontStyle: "italic"
1149
+ },
1150
+ {
1151
+ tag: [
1152
+ S.number,
1153
+ S.integer,
1154
+ S.float
1155
+ ],
1156
+ color: "var(--stylo-syntax-number)"
1157
+ },
1158
+ {
1159
+ tag: [
1160
+ S.bool,
1161
+ S.null,
1162
+ S.atom,
1163
+ S.constant(S.name)
1164
+ ],
1165
+ color: "var(--stylo-syntax-constant)"
1166
+ },
1167
+ {
1168
+ tag: [
1169
+ S.function(S.variableName),
1170
+ S.function(S.propertyName),
1171
+ S.macroName
1172
+ ],
1173
+ color: "var(--stylo-syntax-function)"
1174
+ },
1175
+ {
1176
+ tag: [
1177
+ S.typeName,
1178
+ S.className,
1179
+ S.namespace
1180
+ ],
1181
+ color: "var(--stylo-syntax-type)"
1182
+ },
1183
+ {
1184
+ tag: [S.propertyName, S.attributeName],
1185
+ color: "var(--stylo-syntax-property)"
1186
+ },
1187
+ {
1188
+ tag: [S.tagName],
1189
+ color: "var(--stylo-syntax-tag)"
1190
+ },
1191
+ {
1192
+ tag: [S.meta, S.annotation],
1193
+ color: "var(--stylo-syntax-comment)"
1194
+ },
1195
+ {
1196
+ tag: [S.invalid],
1197
+ color: "var(--stylo-syntax-invalid)"
1198
+ }
1199
+ ]), Ct = re(St), wt = i.theme({
1200
+ "&": {
1201
+ color: "var(--stylo-text)",
1202
+ backgroundColor: "var(--stylo-bg)",
1203
+ fontSize: "0.9375rem"
1204
+ },
1205
+ ".cm-content": {
1206
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
1207
+ padding: "0.75rem 0",
1208
+ caretColor: "var(--stylo-text)"
1209
+ },
1210
+ ".cm-line": { padding: "0 0.75rem" },
1211
+ "&.cm-focused": { outline: "none" },
1212
+ ".cm-cursor, .cm-dropCursor": { borderLeftColor: "var(--stylo-text)" },
1213
+ "&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: "color-mix(in srgb, var(--stylo-accent) 15%, transparent)" },
1214
+ ".cm-placeholder": { color: "var(--stylo-text-muted)" },
1215
+ ".cm-gutters": { display: "none" },
1216
+ ".cm-panels": {
1217
+ background: "var(--stylo-surface-floating, #fff)",
1218
+ color: "var(--stylo-text)"
1219
+ },
1220
+ ".cm-panels.cm-panels-top": { borderBottom: "1px solid var(--stylo-border)" },
1221
+ ".cm-panel.cm-search": {
1222
+ padding: "6px 8px",
1223
+ font: "inherit",
1224
+ fontSize: "0.8125rem"
1225
+ },
1226
+ ".cm-panel.cm-search label": {
1227
+ fontSize: "0.75rem",
1228
+ color: "var(--stylo-text-muted)"
1229
+ },
1230
+ ".cm-panel.cm-search .cm-textfield": {
1231
+ padding: "0.3em 0.5em",
1232
+ border: "1px solid var(--stylo-border)",
1233
+ borderRadius: "calc(var(--stylo-radius) - 3px)",
1234
+ background: "var(--stylo-bg)",
1235
+ color: "var(--stylo-text)",
1236
+ fontSize: "0.8125rem"
1237
+ },
1238
+ ".cm-panel.cm-search .cm-textfield:focus-visible": {
1239
+ outline: "2px solid var(--stylo-ring)",
1240
+ outlineOffset: "-1px"
1241
+ },
1242
+ ".cm-panel.cm-search .cm-button": {
1243
+ padding: "0.3em 0.65em",
1244
+ border: "1px solid var(--stylo-border)",
1245
+ borderRadius: "calc(var(--stylo-radius) - 3px)",
1246
+ background: "var(--stylo-bg)",
1247
+ backgroundImage: "none",
1248
+ color: "var(--stylo-text)",
1249
+ fontSize: "0.75rem",
1250
+ cursor: "pointer"
1251
+ },
1252
+ ".cm-panel.cm-search .cm-button:hover": { background: "color-mix(in srgb, var(--stylo-border) 45%, transparent)" },
1253
+ ".cm-panel.cm-search [name='close']": {
1254
+ color: "var(--stylo-text-muted)",
1255
+ fontSize: "1.1rem"
1256
+ },
1257
+ ".cm-searchMatch": {
1258
+ backgroundColor: "color-mix(in srgb, var(--stylo-ring) 35%, transparent)",
1259
+ borderRadius: "2px"
1260
+ },
1261
+ ".cm-searchMatch.cm-searchMatch-selected": {
1262
+ backgroundColor: "color-mix(in srgb, var(--stylo-ring) 70%, transparent)",
1263
+ outline: "1px solid var(--stylo-ring)"
1264
+ }
1265
+ });
1266
+ //#endregion
1267
+ //#region src/editor/extensions.ts
1268
+ function Tt(e) {
1269
+ return [
1270
+ m(),
1271
+ a.of([...ee, ...h]),
1272
+ p.high(ut),
1273
+ xt,
1274
+ dt,
1275
+ x({ top: !0 }),
1276
+ a.of(te),
1277
+ v({
1278
+ base: y,
1279
+ codeLanguages: e
1280
+ }),
1281
+ Ct,
1282
+ i.lineWrapping,
1283
+ wt
1284
+ ];
1285
+ }
1286
+ function Et(e) {
1287
+ return [
1288
+ d.readOnly.of(e.readOnly),
1289
+ i.editable.of(!e.readOnly),
1290
+ e.placeholder ? o(e.placeholder) : [],
1291
+ e.save ? C.of(e.save) : []
1292
+ ];
1293
+ }
1294
+ //#endregion
1295
+ //#region src/editor/useCodeMirror.ts
1296
+ var $ = s.define();
1297
+ function Dt({ value: e, onChange: t, readOnly: o = !1, placeholder: s, onSave: c, onViewChange: u, extensions: f, codeLanguages: ee }) {
1298
+ let m = r(null), h = r(null), g = r(t);
1299
+ g.current = t;
1300
+ let _ = r(c);
1301
+ _.current = c;
1302
+ let v = r((e) => _.current?.(e)).current, y = c != null, b = r(u);
1303
+ b.current = u;
1304
+ let x = r(new l());
1305
+ return n(() => {
1306
+ let t = m.current;
1307
+ if (!t) return;
1308
+ let n = new i({
1309
+ parent: t,
1310
+ state: d.create({
1311
+ doc: e,
1312
+ extensions: [
1313
+ Tt(ee),
1314
+ x.current.of(Et({
1315
+ readOnly: o,
1316
+ placeholder: s,
1317
+ save: y ? v : void 0
1318
+ })),
1319
+ p.high(a.of([{
1320
+ key: "Mod-s",
1321
+ run: ae
1322
+ }])),
1323
+ ...f ?? [],
1324
+ i.updateListener.of((e) => {
1325
+ e.docChanged && (e.transactions.some((e) => !!e.annotation($)) || g.current(e.state.doc.toString()));
1326
+ })
1327
+ ]
1328
+ })
1329
+ });
1330
+ return h.current = n, b.current?.(n), () => {
1331
+ b.current?.(null), n.destroy(), h.current = null;
1332
+ };
1333
+ }, []), n(() => {
1334
+ let t = h.current;
1335
+ if (!t) return;
1336
+ let n = t.state.doc.toString();
1337
+ n !== e && t.dispatch({
1338
+ changes: {
1339
+ from: 0,
1340
+ to: n.length,
1341
+ insert: e
1342
+ },
1343
+ annotations: $.of(!0)
1344
+ });
1345
+ }, [e]), n(() => {
1346
+ h.current?.dispatch({ effects: x.current.reconfigure(Et({
1347
+ readOnly: o,
1348
+ placeholder: s,
1349
+ save: y ? v : void 0
1350
+ })) });
1351
+ }, [
1352
+ o,
1353
+ s,
1354
+ y,
1355
+ v
1356
+ ]), m;
1357
+ }
1358
+ //#endregion
1359
+ export { Oe as _, B as a, k as b, Pe as c, je as d, j as f, De as g, Ae as h, z as i, Le as l, Ne as m, bt as n, ze as o, ke as p, at as r, P as s, Dt as t, Ee as u, xe as v, O as y };
1360
+
1361
+ //# sourceMappingURL=useCodeMirror-YnIFkvKn.js.map