@dou-ui/code 0.0.0-stage → 0.1.0-alpha.1

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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -2
  3. package/dist/_virtual/_rolldown/runtime.js +12 -0
  4. package/dist/assets/default-BZBMZKf_.js.map +1 -0
  5. package/dist/code-diff.js +6 -0
  6. package/dist/code-diff.js.map +1 -0
  7. package/dist/code-diff.vue_vue_type_script_setup_true_lang.js +792 -0
  8. package/dist/code-diff.vue_vue_type_script_setup_true_lang.js.map +1 -0
  9. package/dist/code-editor.js +6 -0
  10. package/dist/code-editor.js.map +1 -0
  11. package/dist/code-editor.vue_vue_type_script_setup_true_lang.js +5078 -0
  12. package/dist/code-editor.vue_vue_type_script_setup_true_lang.js.map +1 -0
  13. package/dist/code-input.js +6 -0
  14. package/dist/code-input.js.map +1 -0
  15. package/dist/code-input.vue_vue_type_script_setup_true_lang.js +237 -0
  16. package/dist/code-input.vue_vue_type_script_setup_true_lang.js.map +1 -0
  17. package/dist/code-keys.js +42 -0
  18. package/dist/code-keys.js.map +1 -0
  19. package/dist/code-keys.vue_vue_type_script_setup_true_lang.js +244 -0
  20. package/dist/code-keys.vue_vue_type_script_setup_true_lang.js.map +1 -0
  21. package/dist/code-keys2.js +6 -0
  22. package/dist/code-keys2.js.map +1 -0
  23. package/dist/collaboration/index.js +255 -0
  24. package/dist/collaboration/index.js.map +1 -0
  25. package/dist/completion/match.js +55 -0
  26. package/dist/completion/match.js.map +1 -0
  27. package/dist/completion/snippet.js +71 -0
  28. package/dist/completion/snippet.js.map +1 -0
  29. package/dist/core/brackets.js +55 -0
  30. package/dist/core/brackets.js.map +1 -0
  31. package/dist/core/changes.js +185 -0
  32. package/dist/core/changes.js.map +1 -0
  33. package/dist/core/chars.js +130 -0
  34. package/dist/core/chars.js.map +1 -0
  35. package/dist/core/commands.js +910 -0
  36. package/dist/core/commands.js.map +1 -0
  37. package/dist/core/diff.js +215 -0
  38. package/dist/core/diff.js.map +1 -0
  39. package/dist/core/folding.js +87 -0
  40. package/dist/core/folding.js.map +1 -0
  41. package/dist/core/history.js +74 -0
  42. package/dist/core/history.js.map +1 -0
  43. package/dist/core/keymap.js +326 -0
  44. package/dist/core/keymap.js.map +1 -0
  45. package/dist/core/search.js +91 -0
  46. package/dist/core/search.js.map +1 -0
  47. package/dist/core/selection.js +88 -0
  48. package/dist/core/selection.js.map +1 -0
  49. package/dist/core/text.js +320 -0
  50. package/dist/core/text.js.map +1 -0
  51. package/dist/core/transaction.js +98 -0
  52. package/dist/core/transaction.js.map +1 -0
  53. package/dist/extension.js +16 -0
  54. package/dist/extension.js.map +1 -0
  55. package/dist/index.js +38 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/language/highlighter.js +336 -0
  58. package/dist/language/highlighter.js.map +1 -0
  59. package/dist/language/language.js +138 -0
  60. package/dist/language/language.js.map +1 -0
  61. package/dist/language/stream.js +112 -0
  62. package/dist/language/stream.js.map +1 -0
  63. package/dist/language/to-html.js +36 -0
  64. package/dist/language/to-html.js.map +1 -0
  65. package/dist/language/worker-client.js +198 -0
  66. package/dist/language/worker-client.js.map +1 -0
  67. package/dist/language/worker-protocol.js +48 -0
  68. package/dist/language/worker-protocol.js.map +1 -0
  69. package/dist/languages/css.js +128 -0
  70. package/dist/languages/css.js.map +1 -0
  71. package/dist/languages/html.js +175 -0
  72. package/dist/languages/html.js.map +1 -0
  73. package/dist/languages/javascript.js +300 -0
  74. package/dist/languages/javascript.js.map +1 -0
  75. package/dist/languages/json.js +45 -0
  76. package/dist/languages/json.js.map +1 -0
  77. package/dist/languages/markdown.js +82 -0
  78. package/dist/languages/markdown.js.map +1 -0
  79. package/dist/languages/python.js +88 -0
  80. package/dist/languages/python.js.map +1 -0
  81. package/dist/languages/shell.js +153 -0
  82. package/dist/languages/shell.js.map +1 -0
  83. package/dist/languages/sql.js +91 -0
  84. package/dist/languages/sql.js.map +1 -0
  85. package/dist/languages/yaml.js +85 -0
  86. package/dist/languages/yaml.js.map +1 -0
  87. package/dist/locale.js +158 -0
  88. package/dist/locale.js.map +1 -0
  89. package/dist/lsp/index.js +715 -0
  90. package/dist/lsp/index.js.map +1 -0
  91. package/dist/lsp/markup.js +139 -0
  92. package/dist/lsp/markup.js.map +1 -0
  93. package/dist/render-part.js +14 -0
  94. package/dist/render-part.js.map +1 -0
  95. package/dist/shiki/index.js +140 -0
  96. package/dist/shiki/index.js.map +1 -0
  97. package/dist/style.css +1 -0
  98. package/dist/style.d.ts +1 -0
  99. package/dist/style.js +4 -0
  100. package/dist/types/code-diff.vue.d.ts +45 -0
  101. package/dist/types/code-editor.vue.d.ts +43 -0
  102. package/dist/types/code-input.vue.d.ts +32 -0
  103. package/dist/types/code-keys.d.ts +9 -0
  104. package/dist/types/code-keys.vue.d.ts +8 -0
  105. package/dist/types/collaboration/index.d.ts +36 -0
  106. package/dist/types/completion/match.d.ts +13 -0
  107. package/dist/types/completion/snippet.d.ts +17 -0
  108. package/dist/types/core/brackets.d.ts +15 -0
  109. package/dist/types/core/changes.d.ts +52 -0
  110. package/dist/types/core/chars.d.ts +24 -0
  111. package/dist/types/core/commands.d.ts +199 -0
  112. package/dist/types/core/diff.d.ts +52 -0
  113. package/dist/types/core/folding.d.ts +23 -0
  114. package/dist/types/core/history.d.ts +24 -0
  115. package/dist/types/core/keymap.d.ts +29 -0
  116. package/dist/types/core/search.d.ts +37 -0
  117. package/dist/types/core/selection.d.ts +28 -0
  118. package/dist/types/core/text.d.ts +79 -0
  119. package/dist/types/core/transaction.d.ts +65 -0
  120. package/dist/types/extension.d.ts +321 -0
  121. package/dist/types/index.d.ts +159 -0
  122. package/dist/types/language/highlighter.d.ts +99 -0
  123. package/dist/types/language/language.d.ts +100 -0
  124. package/dist/types/language/stream.d.ts +56 -0
  125. package/dist/types/language/to-html.d.ts +17 -0
  126. package/dist/types/language/worker-client.d.ts +52 -0
  127. package/dist/types/language/worker-protocol.d.ts +50 -0
  128. package/dist/types/languages/css.d.ts +17 -0
  129. package/dist/types/languages/html.d.ts +34 -0
  130. package/dist/types/languages/javascript.d.ts +29 -0
  131. package/dist/types/languages/json.d.ts +7 -0
  132. package/dist/types/languages/markdown.d.ts +17 -0
  133. package/dist/types/languages/python.d.ts +9 -0
  134. package/dist/types/languages/shell.d.ts +11 -0
  135. package/dist/types/languages/sql.d.ts +9 -0
  136. package/dist/types/languages/yaml.d.ts +14 -0
  137. package/dist/types/locale.d.ts +79 -0
  138. package/dist/types/lsp/index.d.ts +119 -0
  139. package/dist/types/lsp/markup.d.ts +14 -0
  140. package/dist/types/render-part.d.ts +14 -0
  141. package/dist/types/shiki/index.d.ts +63 -0
  142. package/dist/types/types.d.ts +267 -0
  143. package/dist/types/view/input.d.ts +12 -0
  144. package/dist/types/view/layout.d.ts +55 -0
  145. package/dist/types/view/measure.d.ts +22 -0
  146. package/dist/types/view/viewport.d.ts +16 -0
  147. package/dist/types/view/viewport.test.d.ts +1 -0
  148. package/dist/types/worker/default.d.ts +1 -0
  149. package/dist/types/worker/index.d.ts +34 -0
  150. package/dist/view/input.js +27 -0
  151. package/dist/view/input.js.map +1 -0
  152. package/dist/view/layout.js +194 -0
  153. package/dist/view/layout.js.map +1 -0
  154. package/dist/view/measure.js +104 -0
  155. package/dist/view/measure.js.map +1 -0
  156. package/dist/view/viewport.js +31 -0
  157. package/dist/view/viewport.js.map +1 -0
  158. package/dist/worker/default.js +20 -0
  159. package/dist/worker/default.js.map +1 -0
  160. package/dist/worker/index.js +139 -0
  161. package/dist/worker/index.js.map +1 -0
  162. package/package.json +88 -4
@@ -0,0 +1,320 @@
1
+ import { markRaw } from "vue";
2
+ // src/core/text.ts
3
+ /**
4
+ * The document text: an immutable, balanced tree of lines.
5
+ *
6
+ * Leaves hold up to `LEAF_MAX` lines, branches up to `BRANCH_MAX` children,
7
+ * and every node knows its length and line count, so finding a line by
8
+ * number or by offset walks one path from the root: O(log n). An edit copies
9
+ * only that path and shares everything else with the old text, so keeping
10
+ * old versions around (undo, a `v-model:doc` snapshot) costs next to
11
+ * nothing.
12
+ *
13
+ * Offsets count UTF-16 code units, like the browser and language servers.
14
+ * Lines are numbered from 1 and are joined by one `\n`; a `\r\n` or a lone
15
+ * `\r` in the input becomes `\n`.
16
+ */
17
+ var LEAF_MAX = 64;
18
+ var LEAF_MIN = 16;
19
+ var BRANCH_MAX = 32;
20
+ var BRANCH_MIN = 8;
21
+ /** New leaves and branches start half full, so the next edits rarely split them. */
22
+ var LEAF_FILL = 32;
23
+ var BRANCH_FILL = 16;
24
+ var Leaf = class {
25
+ text;
26
+ length;
27
+ /** The longest line, in code units. */
28
+ widest;
29
+ constructor(text) {
30
+ this.text = text;
31
+ let length = text.length - 1;
32
+ let widest = 0;
33
+ for (const line of text) {
34
+ length += line.length;
35
+ if (line.length > widest) widest = line.length;
36
+ }
37
+ this.length = length;
38
+ this.widest = widest;
39
+ }
40
+ get lines() {
41
+ return this.text.length;
42
+ }
43
+ };
44
+ var Branch = class {
45
+ children;
46
+ length;
47
+ lines;
48
+ widest;
49
+ constructor(children) {
50
+ this.children = children;
51
+ let length = children.length - 1;
52
+ let lines = 0;
53
+ let widest = 0;
54
+ for (const child of children) {
55
+ length += child.length;
56
+ lines += child.lines;
57
+ if (child.widest > widest) widest = child.widest;
58
+ }
59
+ this.length = length;
60
+ this.lines = lines;
61
+ this.widest = widest;
62
+ }
63
+ };
64
+ var isSmall = (node) => node instanceof Leaf ? node.text.length < LEAF_MIN : node.children.length < BRANCH_MIN;
65
+ /** Cuts a list into nodes of about `fill` items each; never one smaller than half of it. */
66
+ function chunk(items, fill, max, make) {
67
+ if (items.length <= max) return [make(items)];
68
+ const count = Math.ceil(items.length / fill);
69
+ const size = Math.ceil(items.length / count);
70
+ const out = [];
71
+ for (let i = 0; i < items.length; i += size) out.push(make(items.slice(i, i + size)));
72
+ return out;
73
+ }
74
+ var leaves = (lines) => chunk(lines, LEAF_FILL, LEAF_MAX, (part) => new Leaf(part));
75
+ var branches = (nodes) => chunk(nodes, BRANCH_FILL, BRANCH_MAX, (part) => new Branch(part));
76
+ /** Stacks nodes of one height into a single root. */
77
+ function root(nodes) {
78
+ while (nodes.length > 1) nodes = branches(nodes);
79
+ let node = nodes[0] ?? new Leaf([""]);
80
+ while (node instanceof Branch && node.children.length === 1) node = node.children[0];
81
+ return node;
82
+ }
83
+ /** Joins two neighbours of the same height and cuts the result again if it grew too big. */
84
+ function merge(a, b) {
85
+ if (a instanceof Leaf && b instanceof Leaf) return leaves([...a.text, ...b.text]);
86
+ return branches([...a.children, ...b.children]);
87
+ }
88
+ /** Merges every small node into a neighbour, so the tree stays shallow after deletes. */
89
+ function settle(nodes) {
90
+ if (nodes.length < 2 || !nodes.some(isSmall)) return nodes;
91
+ const out = [];
92
+ for (const node of nodes) {
93
+ const last = out[out.length - 1];
94
+ if (last && (isSmall(last) || isSmall(node))) out.splice(-1, 1, ...merge(last, node));
95
+ else out.push(node);
96
+ }
97
+ return out;
98
+ }
99
+ /**
100
+ * Replaces `count` lines from line index `at` (from 0) with `insert`, and
101
+ * returns the nodes that take this one's place, all of its height.
102
+ */
103
+ function splice(node, at, count, insert) {
104
+ if (node instanceof Leaf) {
105
+ const text = node.text.slice(0, at).concat(insert, node.text.slice(at + count));
106
+ return text.length ? leaves(text) : [];
107
+ }
108
+ const children = [];
109
+ let start = 0;
110
+ let pending = insert;
111
+ const last = node.children.length - 1;
112
+ node.children.forEach((child, i) => {
113
+ const end = start + child.lines;
114
+ const holds = at < end || i === last && at === end;
115
+ const overlaps = count > 0 && at < end && at + count > start;
116
+ if (pending && holds && at >= start || overlaps) {
117
+ const from = Math.max(at - start, 0);
118
+ const to = Math.min(at + count - start, child.lines);
119
+ children.push(...splice(child, from, Math.max(to - from, 0), pending ?? []));
120
+ pending = null;
121
+ } else children.push(child);
122
+ start = end;
123
+ });
124
+ const settled = settle(children);
125
+ if (!settled.length) return [];
126
+ return branches(settled);
127
+ }
128
+ /**
129
+ * Each node's text, kept once asked for. Nodes never change and an edit
130
+ * makes new ones only along one path, so joining the whole text again
131
+ * after an edit only joins that path: the engine strings together the
132
+ * kept parts without copying them.
133
+ */
134
+ var joined = /* @__PURE__ */ new WeakMap();
135
+ function joinNode(node) {
136
+ let text = joined.get(node);
137
+ if (text !== void 0) return text;
138
+ if (node instanceof Leaf) text = node.text.join("\n");
139
+ else {
140
+ text = joinNode(node.children[0]);
141
+ for (let i = 1; i < node.children.length; i++) text += "\n" + joinNode(node.children[i]);
142
+ }
143
+ joined.set(node, text);
144
+ return text;
145
+ }
146
+ /** Collects the text of lines `from`–`to` (indices from 0, `to` exclusive). */
147
+ function collect(node, from, to, out) {
148
+ if (node instanceof Leaf) {
149
+ for (let i = from; i < to; i++) out.push(node.text[i]);
150
+ return;
151
+ }
152
+ let start = 0;
153
+ for (const child of node.children) {
154
+ const end = start + child.lines;
155
+ if (end > from && start < to) collect(child, Math.max(from - start, 0), Math.min(to - start, child.lines), out);
156
+ if (end >= to) return;
157
+ start = end;
158
+ }
159
+ }
160
+ /** Splits text into lines, reading `\r\n` and a lone `\r` as line breaks too. */
161
+ function splitLines(text) {
162
+ return text.split(/\r\n?|\n/);
163
+ }
164
+ /** Where a text keeps its tree; a symbol rather than a private field, so a `ref` around a text keeps its type. */
165
+ var NODE = Symbol("node");
166
+ var CodeText = class CodeText {
167
+ /** @internal */
168
+ [NODE];
169
+ constructor(node) {
170
+ this[NODE] = node;
171
+ markRaw(this);
172
+ }
173
+ /** The text of a string. */
174
+ static of(text) {
175
+ const parts = leaves(typeof text === "string" ? splitLines(text) : text.length ? text : [""]);
176
+ if (typeof text === "string" && !text.includes("\r")) {
177
+ let at = 0;
178
+ for (const leaf of parts) {
179
+ joined.set(leaf, text.slice(at, at + leaf.length));
180
+ at += leaf.length + 1;
181
+ }
182
+ }
183
+ return new CodeText(root(parts));
184
+ }
185
+ /** An empty text: one empty line. */
186
+ static empty = CodeText.of("");
187
+ /** Length in UTF-16 code units, counting one per line break. */
188
+ get length() {
189
+ return this[NODE].length;
190
+ }
191
+ /** The number of lines, at least 1. */
192
+ get lines() {
193
+ return this[NODE].lines;
194
+ }
195
+ /** The length of the longest line, in code units. */
196
+ get widest() {
197
+ return this[NODE].widest;
198
+ }
199
+ /** Line `n`, counting from 1. */
200
+ line(n) {
201
+ if (n < 1 || n > this.lines) throw new RangeError(`[@dou-ui/code] line ${n} is outside 1–${this.lines}`);
202
+ let node = this[NODE];
203
+ let index = n - 1;
204
+ let from = 0;
205
+ while (node instanceof Branch) for (const child of node.children) {
206
+ if (index < child.lines) {
207
+ node = child;
208
+ break;
209
+ }
210
+ index -= child.lines;
211
+ from += child.length + 1;
212
+ }
213
+ for (let i = 0; i < index; i++) from += node.text[i].length + 1;
214
+ const text = node.text[index];
215
+ return {
216
+ number: n,
217
+ from,
218
+ to: from + text.length,
219
+ text
220
+ };
221
+ }
222
+ /** The text of line `n` (from 1); quicker than `line(n).text`, which also finds where it starts. */
223
+ lineText(n) {
224
+ if (n < 1 || n > this.lines) throw new RangeError(`[@dou-ui/code] line ${n} is outside 1–${this.lines}`);
225
+ let node = this[NODE];
226
+ let index = n - 1;
227
+ while (node instanceof Branch) for (const child of node.children) {
228
+ if (index < child.lines) {
229
+ node = child;
230
+ break;
231
+ }
232
+ index -= child.lines;
233
+ }
234
+ return node.text[index];
235
+ }
236
+ /** The line that holds offset `pos`; a line break belongs to the line before it. */
237
+ lineAt(pos) {
238
+ if (pos < 0 || pos > this.length) throw new RangeError(`[@dou-ui/code] offset ${pos} is outside 0–${this.length}`);
239
+ let node = this[NODE];
240
+ let from = 0;
241
+ let number = 1;
242
+ while (node instanceof Branch) for (const child of node.children) {
243
+ const end = from + child.length;
244
+ if (pos <= end) {
245
+ node = child;
246
+ break;
247
+ }
248
+ from = end + 1;
249
+ number += child.lines;
250
+ }
251
+ for (const text of node.text) {
252
+ const end = from + text.length;
253
+ if (pos <= end) return {
254
+ number,
255
+ from,
256
+ to: end,
257
+ text
258
+ };
259
+ from = end + 1;
260
+ number++;
261
+ }
262
+ throw new RangeError(`[@dou-ui/code] offset ${pos} not found`);
263
+ }
264
+ /** The text of lines `from`–`to`, both counted from 1 and included. */
265
+ lineTexts(from, to = from) {
266
+ const out = [];
267
+ from = Math.max(from, 1);
268
+ to = Math.min(to, this.lines);
269
+ if (from <= to) collect(this[NODE], from - 1, to, out);
270
+ return out;
271
+ }
272
+ /** The text between two offsets. */
273
+ slice(from = 0, to = this.length) {
274
+ from = Math.max(0, from);
275
+ to = Math.min(this.length, to);
276
+ if (from >= to) return "";
277
+ const start = this.lineAt(from);
278
+ if (to <= start.to) return start.text.slice(from - start.from, to - start.from);
279
+ const end = this.lineAt(to);
280
+ const lines = this.lineTexts(start.number, end.number);
281
+ lines[0] = lines[0].slice(from - start.from);
282
+ lines[lines.length - 1] = lines[lines.length - 1].slice(0, to - end.from);
283
+ return lines.join("\n");
284
+ }
285
+ /** A new text with `from`–`to` replaced by `insert`; this one stays as it is. */
286
+ replace(from, to, insert) {
287
+ if (from < 0 || to > this.length || from > to) throw new RangeError(`[@dou-ui/code] range ${from}–${to} is outside 0–${this.length}`);
288
+ const lines = typeof insert === "string" ? splitLines(insert) : insert;
289
+ if (from === to && lines.length === 1 && !lines[0]) return this;
290
+ const start = this.lineAt(from);
291
+ const end = to <= start.to ? start : this.lineAt(to);
292
+ const head = start.text.slice(0, from - start.from);
293
+ const tail = end.text.slice(to - end.from);
294
+ const next = lines.slice();
295
+ next[0] = head + next[0];
296
+ next[next.length - 1] += tail;
297
+ const nodes = splice(this[NODE], start.number - 1, end.number - start.number + 1, next);
298
+ return new CodeText(root(nodes));
299
+ }
300
+ /** Every line, from 1 to the end. */
301
+ toLines() {
302
+ return this.lineTexts(1, this.lines);
303
+ }
304
+ /** The whole text, with `\n` between lines. */
305
+ toString() {
306
+ return joinNode(this[NODE]);
307
+ }
308
+ /** Whether two texts hold the same characters. */
309
+ eq(other) {
310
+ if (other === this) return true;
311
+ if (other.length !== this.length || other.lines !== this.lines) return false;
312
+ const a = this.toLines();
313
+ const b = other.toLines();
314
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
315
+ return true;
316
+ }
317
+ };
318
+ export { CodeText, splitLines };
319
+
320
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","names":[],"sources":["../../src/core/text.ts"],"sourcesContent":["/**\n * The document text: an immutable, balanced tree of lines.\n *\n * Leaves hold up to `LEAF_MAX` lines, branches up to `BRANCH_MAX` children,\n * and every node knows its length and line count, so finding a line by\n * number or by offset walks one path from the root: O(log n). An edit copies\n * only that path and shares everything else with the old text, so keeping\n * old versions around (undo, a `v-model:doc` snapshot) costs next to\n * nothing.\n *\n * Offsets count UTF-16 code units, like the browser and language servers.\n * Lines are numbered from 1 and are joined by one `\\n`; a `\\r\\n` or a lone\n * `\\r` in the input becomes `\\n`.\n */\n\nimport { markRaw } from 'vue'\n\nconst LEAF_MAX = 64\nconst LEAF_MIN = 16\nconst BRANCH_MAX = 32\nconst BRANCH_MIN = 8\n/** New leaves and branches start half full, so the next edits rarely split them. */\nconst LEAF_FILL = LEAF_MAX >> 1\nconst BRANCH_FILL = BRANCH_MAX >> 1\n\n/** One line of the text. */\nexport interface CodeLine {\n /** The line number, from 1. */\n readonly number: number\n /** Offset of the line's first character. */\n readonly from: number\n /** Offset just after the line's last character, before its line break. */\n readonly to: number\n /** The line's text, without the line break. */\n readonly text: string\n}\n\ntype Node = Leaf | Branch\n\nclass Leaf {\n readonly length: number\n /** The longest line, in code units. */\n readonly widest: number\n constructor(readonly text: readonly string[]) {\n let length = text.length - 1\n let widest = 0\n for (const line of text) {\n length += line.length\n if (line.length > widest) widest = line.length\n }\n this.length = length\n this.widest = widest\n }\n get lines() {\n return this.text.length\n }\n}\n\nclass Branch {\n readonly length: number\n readonly lines: number\n readonly widest: number\n constructor(readonly children: readonly Node[]) {\n let length = children.length - 1\n let lines = 0\n let widest = 0\n for (const child of children) {\n length += child.length\n lines += child.lines\n if (child.widest > widest) widest = child.widest\n }\n this.length = length\n this.lines = lines\n this.widest = widest\n }\n}\n\nconst isSmall = (node: Node) =>\n node instanceof Leaf ? node.text.length < LEAF_MIN : node.children.length < BRANCH_MIN\n\n/** Cuts a list into nodes of about `fill` items each; never one smaller than half of it. */\nfunction chunk<T, N>(items: readonly T[], fill: number, max: number, make: (part: T[]) => N): N[] {\n if (items.length <= max) return [make(items as T[])]\n const count = Math.ceil(items.length / fill)\n const size = Math.ceil(items.length / count)\n const out: N[] = []\n for (let i = 0; i < items.length; i += size) out.push(make(items.slice(i, i + size)))\n return out\n}\n\nconst leaves = (lines: readonly string[]) =>\n chunk(lines, LEAF_FILL, LEAF_MAX, (part) => new Leaf(part))\n\nconst branches = (nodes: readonly Node[]) =>\n chunk(nodes, BRANCH_FILL, BRANCH_MAX, (part) => new Branch(part))\n\n/** Stacks nodes of one height into a single root. */\nfunction root(nodes: Node[]): Node {\n while (nodes.length > 1) nodes = branches(nodes)\n let node = nodes[0] ?? new Leaf([''])\n while (node instanceof Branch && node.children.length === 1) node = node.children[0]!\n return node\n}\n\n/** Joins two neighbours of the same height and cuts the result again if it grew too big. */\nfunction merge(a: Node, b: Node): Node[] {\n if (a instanceof Leaf && b instanceof Leaf) return leaves([...a.text, ...b.text])\n return branches([...(a as Branch).children, ...(b as Branch).children])\n}\n\n/** Merges every small node into a neighbour, so the tree stays shallow after deletes. */\nfunction settle(nodes: Node[]): Node[] {\n if (nodes.length < 2 || !nodes.some(isSmall)) return nodes\n const out: Node[] = []\n for (const node of nodes) {\n const last = out[out.length - 1]\n if (last && (isSmall(last) || isSmall(node))) out.splice(-1, 1, ...merge(last, node))\n else out.push(node)\n }\n return out\n}\n\n/**\n * Replaces `count` lines from line index `at` (from 0) with `insert`, and\n * returns the nodes that take this one's place, all of its height.\n */\nfunction splice(node: Node, at: number, count: number, insert: readonly string[]): Node[] {\n if (node instanceof Leaf) {\n const text = node.text.slice(0, at).concat(insert, node.text.slice(at + count))\n return text.length ? leaves(text) : []\n }\n const children: Node[] = []\n let start = 0\n let pending: readonly string[] | null = insert\n const last = node.children.length - 1\n node.children.forEach((child, i) => {\n const end = start + child.lines\n // Lines go into the child that holds `at`, or the last one when `at` is the end.\n const holds = at < end || (i === last && at === end)\n const overlaps = count > 0 && at < end && at + count > start\n if ((pending && holds && at >= start) || overlaps) {\n const from = Math.max(at - start, 0)\n const to = Math.min(at + count - start, child.lines)\n children.push(...splice(child, from, Math.max(to - from, 0), pending ?? []))\n pending = null\n } else {\n children.push(child)\n }\n start = end\n })\n const settled = settle(children)\n if (!settled.length) return []\n return branches(settled)\n}\n\n/**\n * Each node's text, kept once asked for. Nodes never change and an edit\n * makes new ones only along one path, so joining the whole text again\n * after an edit only joins that path: the engine strings together the\n * kept parts without copying them.\n */\nconst joined = new WeakMap<Node, string>()\nfunction joinNode(node: Node): string {\n let text = joined.get(node)\n if (text !== undefined) return text\n if (node instanceof Leaf) text = node.text.join('\\n')\n else {\n text = joinNode(node.children[0]!)\n for (let i = 1; i < node.children.length; i++) text += '\\n' + joinNode(node.children[i]!)\n }\n joined.set(node, text)\n return text\n}\n\n/** Collects the text of lines `from`–`to` (indices from 0, `to` exclusive). */\nfunction collect(node: Node, from: number, to: number, out: string[]) {\n if (node instanceof Leaf) {\n for (let i = from; i < to; i++) out.push(node.text[i]!)\n return\n }\n let start = 0\n for (const child of node.children) {\n const end = start + child.lines\n if (end > from && start < to)\n collect(child, Math.max(from - start, 0), Math.min(to - start, child.lines), out)\n if (end >= to) return\n start = end\n }\n}\n\n/** Splits text into lines, reading `\\r\\n` and a lone `\\r` as line breaks too. */\nexport function splitLines(text: string): string[] {\n return text.split(/\\r\\n?|\\n/)\n}\n\n/** Where a text keeps its tree; a symbol rather than a private field, so a `ref` around a text keeps its type. */\nconst NODE = Symbol('node')\n\nexport class CodeText {\n /** @internal */\n readonly [NODE]: Node\n\n private constructor(node: Node) {\n this[NODE] = node\n // Immutable: a ref around it needs no deep proxy, and comparing by identity keeps working.\n markRaw(this)\n }\n\n /** The text of a string. */\n static of(text: string | readonly string[]): CodeText {\n const lines = typeof text === 'string' ? splitLines(text) : text.length ? text : ['']\n const parts = leaves(lines)\n // Each leaf's text is a slice of the source, which costs nothing to keep and saves joining it later.\n if (typeof text === 'string' && !text.includes('\\r')) {\n let at = 0\n for (const leaf of parts) {\n joined.set(leaf, text.slice(at, at + leaf.length))\n at += leaf.length + 1\n }\n }\n return new CodeText(root(parts))\n }\n\n /** An empty text: one empty line. */\n static readonly empty: CodeText = CodeText.of('')\n\n /** Length in UTF-16 code units, counting one per line break. */\n get length(): number {\n return this[NODE].length\n }\n\n /** The number of lines, at least 1. */\n get lines(): number {\n return this[NODE].lines\n }\n\n /** The length of the longest line, in code units. */\n get widest(): number {\n return this[NODE].widest\n }\n\n /** Line `n`, counting from 1. */\n line(n: number): CodeLine {\n if (n < 1 || n > this.lines)\n throw new RangeError(`[@dou-ui/code] line ${n} is outside 1–${this.lines}`)\n let node = this[NODE]\n let index = n - 1\n let from = 0\n while (node instanceof Branch) {\n for (const child of node.children) {\n if (index < child.lines) {\n node = child\n break\n }\n index -= child.lines\n from += child.length + 1\n }\n }\n for (let i = 0; i < index; i++) from += node.text[i]!.length + 1\n const text = node.text[index]!\n return { number: n, from, to: from + text.length, text }\n }\n\n /** The text of line `n` (from 1); quicker than `line(n).text`, which also finds where it starts. */\n lineText(n: number): string {\n if (n < 1 || n > this.lines)\n throw new RangeError(`[@dou-ui/code] line ${n} is outside 1–${this.lines}`)\n let node = this[NODE]\n let index = n - 1\n while (node instanceof Branch) {\n for (const child of node.children) {\n if (index < child.lines) {\n node = child\n break\n }\n index -= child.lines\n }\n }\n return node.text[index]!\n }\n\n /** The line that holds offset `pos`; a line break belongs to the line before it. */\n lineAt(pos: number): CodeLine {\n if (pos < 0 || pos > this.length)\n throw new RangeError(`[@dou-ui/code] offset ${pos} is outside 0–${this.length}`)\n let node = this[NODE]\n let from = 0\n let number = 1\n while (node instanceof Branch) {\n for (const child of node.children) {\n const end = from + child.length\n if (pos <= end) {\n node = child\n break\n }\n from = end + 1\n number += child.lines\n }\n }\n for (const text of node.text) {\n const end = from + text.length\n if (pos <= end) return { number, from, to: end, text }\n from = end + 1\n number++\n }\n // unreachable: `pos` is inside the leaf\n throw new RangeError(`[@dou-ui/code] offset ${pos} not found`)\n }\n\n /** The text of lines `from`–`to`, both counted from 1 and included. */\n lineTexts(from: number, to: number = from): string[] {\n const out: string[] = []\n from = Math.max(from, 1)\n to = Math.min(to, this.lines)\n if (from <= to) collect(this[NODE], from - 1, to, out)\n return out\n }\n\n /** The text between two offsets. */\n slice(from = 0, to = this.length): string {\n from = Math.max(0, from)\n to = Math.min(this.length, to)\n if (from >= to) return ''\n const start = this.lineAt(from)\n if (to <= start.to) return start.text.slice(from - start.from, to - start.from)\n const end = this.lineAt(to)\n const lines = this.lineTexts(start.number, end.number)\n lines[0] = lines[0]!.slice(from - start.from)\n lines[lines.length - 1] = lines[lines.length - 1]!.slice(0, to - end.from)\n return lines.join('\\n')\n }\n\n /** A new text with `from`–`to` replaced by `insert`; this one stays as it is. */\n replace(from: number, to: number, insert: string | readonly string[]): CodeText {\n if (from < 0 || to > this.length || from > to)\n throw new RangeError(`[@dou-ui/code] range ${from}–${to} is outside 0–${this.length}`)\n const lines = typeof insert === 'string' ? splitLines(insert) : insert\n if (from === to && lines.length === 1 && !lines[0]) return this\n const start = this.lineAt(from)\n const end = to <= start.to ? start : this.lineAt(to)\n const head = start.text.slice(0, from - start.from)\n const tail = end.text.slice(to - end.from)\n const next = lines.slice()\n next[0] = head + next[0]\n next[next.length - 1] += tail\n const nodes = splice(this[NODE], start.number - 1, end.number - start.number + 1, next)\n return new CodeText(root(nodes))\n }\n\n /** Every line, from 1 to the end. */\n toLines(): string[] {\n return this.lineTexts(1, this.lines)\n }\n\n /** The whole text, with `\\n` between lines. */\n toString(): string {\n return joinNode(this[NODE])\n }\n\n /** Whether two texts hold the same characters. */\n eq(other: CodeText): boolean {\n if (other === this) return true\n if (other.length !== this.length || other.lines !== this.lines) return false\n const a = this.toLines()\n const b = other.toLines()\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false\n return true\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,aAAa;AACnB,IAAM,aAAa;;AAEnB,IAAM,YAAY;AAClB,IAAM,cAAc;AAgBpB,IAAM,OAAN,MAAW;CAIY;CAHrB;;CAEA;CACA,YAAY,MAAkC;EAAzB,KAAA,OAAA;EACnB,IAAI,SAAS,KAAK,SAAS;EAC3B,IAAI,SAAS;EACb,KAAK,MAAM,QAAQ,MAAM;GACvB,UAAU,KAAK;GACf,IAAI,KAAK,SAAS,QAAQ,SAAS,KAAK;EAC1C;EACA,KAAK,SAAS;EACd,KAAK,SAAS;CAChB;CACA,IAAI,QAAQ;EACV,OAAO,KAAK,KAAK;CACnB;AACF;AAEA,IAAM,SAAN,MAAa;CAIU;CAHrB;CACA;CACA;CACA,YAAY,UAAoC;EAA3B,KAAA,WAAA;EACnB,IAAI,SAAS,SAAS,SAAS;EAC/B,IAAI,QAAQ;EACZ,IAAI,SAAS;EACb,KAAK,MAAM,SAAS,UAAU;GAC5B,UAAU,MAAM;GAChB,SAAS,MAAM;GACf,IAAI,MAAM,SAAS,QAAQ,SAAS,MAAM;EAC5C;EACA,KAAK,SAAS;EACd,KAAK,QAAQ;EACb,KAAK,SAAS;CAChB;AACF;AAEA,IAAM,WAAW,SACf,gBAAgB,OAAO,KAAK,KAAK,SAAS,WAAW,KAAK,SAAS,SAAS;;AAG9E,SAAS,MAAY,OAAqB,MAAc,KAAa,MAA6B;CAChG,IAAI,MAAM,UAAU,KAAK,OAAO,CAAC,KAAK,KAAY,CAAC;CACnD,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,IAAI;CAC3C,MAAM,OAAO,KAAK,KAAK,MAAM,SAAS,KAAK;CAC3C,MAAM,MAAW,CAAC;CAClB,KAAK,IAAI,IA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AM,KAAK,QAAQ,KAAK,OAAO,EAAE;EACnD,MAAM,OAAO,MAAM,KAAK,MAAM,GAAG,OAAO,MAAM,IAAI;EAClD,MAAM,OAAO,IAAI,KAAK,MAAM,KAAK,IAAI,IAAI;EACzC,MAAM,OAAO,MAAM,MAAM;EACzB,KAAK,KAAK,OAAO,KAAK;EACtB,KAAK,KAAK,SAAS,MAAM;EACzB,MAAM,QAAQ,OAAO,KAAK,OAAO,MAAM,SAAS,GAAG,IAAI,SAAS,MAAM,SAAS,GAAG,IAAI;EACtF,OAAO,IAAI,SAAS,KAAK,KAAK,CAAC;CACjC;;CAGA,UAAoB;EAClB,OAAO,KAAK,UAAU,GAAG,KAAK,KAAK;CACrC;;CAGA,WAAmB;EACjB,OAAO,SAAS,KAAK,KAAK;CAC5B;;CAGA,GAAG,OAA0B;EAC3B,IAAI,UAAU,MAAM,OAAO;EAC3B,IAAI,MAAM,WAAW,KAAK,UAAU,MAAM,UAAU,KAAK,OAAO,OAAO;EACvE,MAAM,IAAI,KAAK,QAAQ;EACvB,MAAM,IAAI,MAAM,QAAQ;EACxB,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK,IAAI,EAAE,OAAO,EAAE,IAAI,OAAO;EAC7D,OAAO;CACT;AACF"}
@@ -0,0 +1,98 @@
1
+ import { ChangeSet } from "./changes.js";
2
+ import { mapSelection, normalizeSelection, rangeFrom, rangeTo, sameSelection, selectionOf } from "./selection.js";
3
+ // src/core/transaction.ts
4
+ /**
5
+ * One step from a state to the next. Every position given to it is in the
6
+ * text as it was when the transaction started, also after earlier calls in
7
+ * the same transaction; changes may not overlap.
8
+ *
9
+ * Without `select()`, the selection moves along with the changes.
10
+ */
11
+ var CodeTransaction = class {
12
+ start;
13
+ specs = [];
14
+ nextSelection = null;
15
+ meta = {};
16
+ constructor(start) {
17
+ this.start = start;
18
+ }
19
+ get doc() {
20
+ return this.start.doc;
21
+ }
22
+ get selection() {
23
+ return this.start.selection;
24
+ }
25
+ /** Replaces `from`–`to` with `insert`. */
26
+ replace(from, to, insert) {
27
+ this.specs.push({
28
+ from,
29
+ to,
30
+ insert
31
+ });
32
+ return this;
33
+ }
34
+ insert(pos, text) {
35
+ return this.replace(pos, pos, text);
36
+ }
37
+ delete(from, to) {
38
+ return this.replace(from, to, "");
39
+ }
40
+ /** Sets the selection after the step, in the text after the step. */
41
+ select(selection, head) {
42
+ this.nextSelection = typeof selection === "number" ? selectionOf(selection, head) : selection;
43
+ return this;
44
+ }
45
+ /**
46
+ * Replaces every selected range with `text` (or what `text` returns for
47
+ * it) and leaves a cursor after each insertion.
48
+ */
49
+ replaceSelection(text) {
50
+ const ranges = this.start.selection.ranges;
51
+ let shift = 0;
52
+ const cursors = [];
53
+ ranges.forEach((range, i) => {
54
+ const insert = typeof text === "string" ? text : text(range, i);
55
+ const from = rangeFrom(range);
56
+ const to = rangeTo(range);
57
+ this.replace(from, to, insert);
58
+ const pos = from + shift + insert.replace(/\r\n?/g, "\n").length;
59
+ cursors.push({
60
+ anchor: pos,
61
+ head: pos
62
+ });
63
+ shift += insert.replace(/\r\n?/g, "\n").length - (to - from);
64
+ });
65
+ return this.select({
66
+ ranges: cursors,
67
+ main: this.start.selection.main
68
+ });
69
+ }
70
+ setMeta(meta) {
71
+ Object.assign(this.meta, meta);
72
+ return this;
73
+ }
74
+ /** Whether the transaction changes the text. */
75
+ get docChanged() {
76
+ return this.specs.length > 0;
77
+ }
78
+ /** The changes, the new state, and the selection before. */
79
+ resolve() {
80
+ const changes = ChangeSet.of(this.specs, this.start.doc.length);
81
+ const doc = changes.empty ? this.start.doc : changes.apply(this.start.doc);
82
+ const selection = normalizeSelection(this.nextSelection ?? mapSelection(this.start.selection, changes), doc.length);
83
+ const changed = !changes.empty || !sameSelection(selection, this.start.selection);
84
+ return {
85
+ changes,
86
+ state: {
87
+ doc,
88
+ selection
89
+ },
90
+ before: this.start,
91
+ meta: this.meta,
92
+ changed
93
+ };
94
+ }
95
+ };
96
+ export { CodeTransaction };
97
+
98
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","names":[],"sources":["../../src/core/transaction.ts"],"sourcesContent":["import { ChangeSet, type CodeChangeSpec } from './changes'\nimport {\n type CodeRange,\n type CodeSelection,\n mapSelection,\n normalizeSelection,\n rangeFrom,\n rangeTo,\n sameSelection,\n selectionOf,\n} from './selection'\nimport type { CodeText } from './text'\n\n/** Where a transaction came from. Undo groups typing and deleting by it. */\nexport type CodeAction =\n | 'input'\n | 'delete'\n | 'paste'\n | 'cut'\n | 'drop'\n | 'indent'\n | 'select'\n | 'undo'\n | 'redo'\n | 'external'\n /** Someone else's change, from editing together. */\n | 'remote'\n | (string & {})\n\nexport interface CodeTransactionMeta {\n /**\n * What made the change, e.g. `'input'` for typing, `'external'` for a new\n * `v-model` value, `'remote'` for someone else's.\n */\n action?: CodeAction\n /** `false` keeps the change out of undo. */\n history?: boolean\n /** Scroll the main cursor into view afterwards; on by default for edits. */\n scroll?: boolean\n [key: string]: unknown\n}\n\n/** The editor's content: the text and what is selected in it. */\nexport interface CodeState {\n readonly doc: CodeText\n readonly selection: CodeSelection\n}\n\n/**\n * One step from a state to the next. Every position given to it is in the\n * text as it was when the transaction started, also after earlier calls in\n * the same transaction; changes may not overlap.\n *\n * Without `select()`, the selection moves along with the changes.\n */\nexport class CodeTransaction {\n private specs: CodeChangeSpec[] = []\n private nextSelection: CodeSelection | null = null\n readonly meta: CodeTransactionMeta = {}\n\n constructor(readonly start: CodeState) {}\n\n get doc(): CodeText {\n return this.start.doc\n }\n\n get selection(): CodeSelection {\n return this.start.selection\n }\n\n /** Replaces `from`–`to` with `insert`. */\n replace(from: number, to: number, insert: string): this {\n this.specs.push({ from, to, insert })\n return this\n }\n\n insert(pos: number, text: string): this {\n return this.replace(pos, pos, text)\n }\n\n delete(from: number, to: number): this {\n return this.replace(from, to, '')\n }\n\n /** Sets the selection after the step, in the text after the step. */\n select(selection: CodeSelection | number, head?: number): this {\n this.nextSelection = typeof selection === 'number' ? selectionOf(selection, head) : selection\n return this\n }\n\n /**\n * Replaces every selected range with `text` (or what `text` returns for\n * it) and leaves a cursor after each insertion.\n */\n replaceSelection(text: string | ((range: CodeRange, index: number) => string)): this {\n const ranges = this.start.selection.ranges\n let shift = 0\n const cursors: CodeRange[] = []\n ranges.forEach((range, i) => {\n const insert = typeof text === 'string' ? text : text(range, i)\n const from = rangeFrom(range)\n const to = rangeTo(range)\n this.replace(from, to, insert)\n const pos = from + shift + insert.replace(/\\r\\n?/g, '\\n').length\n cursors.push({ anchor: pos, head: pos })\n shift += insert.replace(/\\r\\n?/g, '\\n').length - (to - from)\n })\n return this.select({ ranges: cursors, main: this.start.selection.main })\n }\n\n setMeta(meta: CodeTransactionMeta): this {\n Object.assign(this.meta, meta)\n return this\n }\n\n /** Whether the transaction changes the text. */\n get docChanged(): boolean {\n return this.specs.length > 0\n }\n\n /** The changes, the new state, and the selection before. */\n resolve(): CodeTransactionResult {\n const changes = ChangeSet.of(this.specs, this.start.doc.length)\n const doc = changes.empty ? this.start.doc : changes.apply(this.start.doc)\n const selection = normalizeSelection(\n this.nextSelection ?? mapSelection(this.start.selection, changes),\n doc.length,\n )\n const changed = !changes.empty || !sameSelection(selection, this.start.selection)\n return { changes, state: { doc, selection }, before: this.start, meta: this.meta, changed }\n }\n}\n\n/** What a transaction did, as handed to `change` listeners. */\nexport interface CodeTransactionResult {\n readonly changes: ChangeSet\n readonly state: CodeState\n readonly before: CodeState\n readonly meta: CodeTransactionMeta\n /** Whether the text or the selection changed; when neither did, nothing was applied. */\n readonly changed: boolean\n}\n"],"mappings":";;;;;;;;;;AAuDA,IAAa,kBAAb,MAA6B;CAKN;CAJrB,QAAkC,CAAC;CACnC,gBAA8C;CAC9C,OAAqC,CAAC;CAEtC,YAAY,OAA2B;EAAlB,KAAA,QAAA;CAAmB;CAExC,IAAI,MAAgB;EAClB,OAAO,KAAK,MAAM;CACpB;CAEA,IAAI,YAA2B;EAC7B,O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AAM,QAAQ,MAAM,KAAK,MAAM,GAAG;EACzE,MAAM,YAAY,mBAChB,KAAK,iBAAiB,aAAa,KAAK,MAAM,WAAW,OAAO,GAChE,IAAI,MACN;EACA,MAAM,UAAU,CAAC,QAAQ,SAAS,CAAC,cAAc,WAAW,KAAK,MAAM,SAAS;EAChF,OAAO;GAAE;GAAS,OAAO;IAAE;IAAK;GAAU;GAAG,QAAQ,KAAK;GAAO,MAAM,KAAK;GAAM;EAAQ;CAC5F;AACF"}
@@ -0,0 +1,16 @@
1
+ import { inject } from "vue";
2
+ // src/extension.ts
3
+ /** Types an extension; returns it as it is. */
4
+ function defineCodeExtension(extension) {
5
+ return extension;
6
+ }
7
+ var CODE_EDITOR_KEY = Symbol("DouCodeEditor");
8
+ /** The editor a panel or gutter component is drawn in. */
9
+ function useCodeEditor() {
10
+ const context = inject(CODE_EDITOR_KEY, null);
11
+ if (!context) throw new Error("[@dou-ui/code] useCodeEditor() must be called inside <DouCodeEditor>");
12
+ return context;
13
+ }
14
+ export { CODE_EDITOR_KEY, defineCodeExtension, useCodeEditor };
15
+
16
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","names":[],"sources":["../src/extension.ts"],"sourcesContent":["import type { CodeMessages } from './locale'\nimport { type Component, type InjectionKey, type VNodeChild, inject } from 'vue'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeSelection } from './core/selection'\nimport type { CodeText } from './core/text'\nimport type { CodeState, CodeTransaction, CodeTransactionResult } from './core/transaction'\nimport type { CodeEditorExpose } from './types'\n\n/** How bad a diagnostic is, worst first. */\nexport type CodeDiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint'\n\n/** A fix offered with a diagnostic. */\nexport interface CodeDiagnosticAction {\n label: string\n /** Makes the fix, usually with `context.transact`. */\n run: (context: CodeExtensionContext, diagnostic: CodeDiagnostic) => void\n}\n\n/**\n * A problem found in the text, from `from` to `to` (offsets in the text,\n * the same as a language service's ranges). An empty range marks the\n * character after it.\n */\nexport interface CodeDiagnostic {\n from: number\n to: number\n severity: CodeDiagnosticSeverity\n message: string\n /** Who found it, shown after the message, e.g. the name of a linter. */\n source?: string\n /** Fixes, shown under the message and with `Mod` + `.`. */\n actions?: CodeDiagnosticAction[]\n}\n\n/**\n * How a part of the text is drawn. Marks and line classes only change how\n * the text looks (colors, backgrounds, underlines, borders), never its\n * size, so the cursor still lands where the characters are; an inline\n * widget takes its own room in the line.\n */\nexport type CodeDecoration =\n /**\n * Classes on the characters from `from` to `to`. `style` sets inline\n * styles on them as well, e.g. a CSS variable holding a person's color;\n * where marks overlap, the later one's styles win.\n */\n | {\n type: 'mark'\n from: number\n to: number\n class: string\n title?: string\n style?: Readonly<Record<string, string>>\n }\n /** A class on a whole line (`line` from 1), e.g. a tinted background. */\n | { type: 'line'; line: number; class: string }\n /**\n * Something drawn inside a line, before the character at `pos`, such as\n * a color swatch or a parameter's name. It isn't text: the cursor steps\n * over it and copying leaves it out. `width` in px saves measuring it;\n * without it the widget is measured once drawn, and the width is kept by\n * `id`.\n */\n | { type: 'inline'; pos: number; render: () => VNodeChild; width?: number; id?: string }\n\n/**\n * A component drawn between lines, across the editor, e.g. a review\n * comment. The lines below move down to make room, and it moves with the\n * text as lines are added or removed above it.\n */\nexport interface CodeWidget {\n /** Tells widgets apart, unique among one extension's; its measured height is kept by it. */\n id: string\n /**\n * Where it is: below the line of text position `pos`, or below line\n * `line` (from 1); above with `position: 'above'`. Give one of them.\n */\n pos?: number\n line?: number\n /** Defaults to `below`. */\n position?: 'above' | 'below'\n render: () => VNodeChild\n /** Its height in px before it has been drawn and measured; defaults to one line. */\n height?: number\n /** What it is, read out when the cursor moves onto its line, e.g. \"戴兜的评论\". */\n label?: string\n}\n\n/** Something drawn in a column beside the line numbers, on line `line` (from 1). */\nexport interface CodeGutterMarker {\n line: number\n /** Drawn in the middle of the column. */\n icon?: Component\n /** Short text, when there is no icon. */\n text?: string\n class?: string\n /** Shown on hover and read out. */\n title?: string\n}\n\n/** A column of the gutter, left of the line numbers. */\nexport interface CodeGutter {\n name: string\n /** In px. Defaults to 16. */\n width?: number\n /** The markers on the lines in view; reactive state read here updates them. */\n markers: (context: CodeExtensionContext) => CodeGutterMarker[]\n /** A press on the column, on line `line`, e.g. to set a breakpoint. */\n onPress?: (line: number, event: PointerEvent, context: CodeExtensionContext) => void\n}\n\n/** An undo history that takes the place of the editor's own, e.g. one shared with others. */\nexport interface CodeHistoryHandler {\n /** `false` when there is nothing to undo. */\n undo: () => boolean\n redo: () => boolean\n /** Read in templates and computed values: keep them reactive. */\n canUndo: () => boolean\n canRedo: () => boolean\n /** The next change starts a new undo step, e.g. when the editor loses focus. */\n close?: () => void\n}\n\n/** A bar above or below the text, inside the editor's frame. */\nexport interface CodePanel {\n /** Tells panels apart, unique among one extension's. */\n name: string\n /** Defaults to `bottom`. */\n position?: 'top' | 'bottom'\n render: () => VNodeChild\n}\n\n/** What a completion is, shown as its icon. */\nexport type CodeCompletionKind =\n | 'keyword'\n | 'function'\n | 'method'\n | 'variable'\n | 'property'\n | 'constant'\n | 'class'\n | 'type'\n | 'module'\n | 'snippet'\n | 'text'\n\n/** One entry of the completion list. */\nexport interface CodeCompletion {\n /** Shown, and matched against what was typed. */\n label: string\n kind?: CodeCompletionKind\n /** Short, after the label, e.g. a type. */\n detail?: string\n /** Longer, below the list while this entry is picked: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n /** What goes into the text, if not the label. */\n insert?: string\n /** Inserted as a snippet instead: `${1:name}` places to fill in, Tab to the next, `$0` where it ends. */\n snippet?: string\n /** Moves the entry up (positive) or down among equally good matches. */\n boost?: number\n}\n\n/** What a completion source is asked with. */\nexport interface CodeCompletionRequest {\n /** The cursor. */\n pos: number\n /** The word right before the cursor, by the language's word characters; empty when there is none. */\n word: { from: number; to: number; text: string }\n /** Asked for from the keyboard (`Ctrl` + `Space`, `Alt` + `Esc`) rather than by typing. */\n explicit: boolean\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a hover or signature source is asked with. */\nexport interface CodePositionRequest {\n /** The position asked about: under the pointer, or the cursor. */\n pos: number\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a completion source answers: entries to put in place of `from`–cursor. */\nexport interface CodeCompletionResult {\n from: number\n options: CodeCompletion[]\n}\n\n/** Text shown on hover, or with the cursor on it from the keyboard. */\nexport interface CodeHoverResult {\n /** What it is about, `from`–`to`; defaults to the word under the pointer. */\n from?: number\n to?: number\n /** Plain text, or a render function for anything else. */\n content: string | (() => VNodeChild)\n}\n\n/** The parameters of the call the cursor is in. */\nexport interface CodeSignatureResult {\n /** The whole signature, e.g. `slice(start, end)`. */\n label: string\n /** Each parameter as `[from, to]` in `label`. */\n params: Array<[number, number]>\n /** Which parameter the cursor is at, from 0. */\n active: number\n /** Shown under the signature: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n}\n\nexport interface CodeExtension {\n name: string\n /** Higher runs first: its keys and hooks come before others. Defaults to 100. */\n priority?: number\n /** Keys tried before the built-in ones, and after the `keymap` prop. */\n keymap?: (context: CodeExtensionContext) => CodeKeymap\n /**\n * How parts of the text look, read while drawing: reactive state read\n * here updates them. Asked for the lines in view (`context.visible`),\n * which is all that needs them.\n */\n decorations?: (context: CodeExtensionContext) => CodeDecoration[]\n /** Columns beside the line numbers. */\n gutters?: CodeGutter[]\n /**\n * Components between lines. Unlike decorations, these are asked for the\n * whole text, since their heights place every line after them; keep\n * them few (comments, not one per line).\n */\n widgets?: (context: CodeExtensionContext) => CodeWidget[]\n /**\n * Lines left out of view: line numbers (from 1, not text positions), from\n * line `from` to line `to`, both left out,\n * e.g. the unchanged lines of a diff. Unlike a fold, nothing marks the\n * spot; put a widget there for that. Asked for the whole text; reactive\n * state read here updates them. Moving up and down steps over them.\n */\n hide?: (context: CodeExtensionContext) => Array<{ from: number; to: number }>\n /** Bars above or below the text; reactive state read here updates them. */\n panels?: (context: CodeExtensionContext) => CodePanel[]\n /**\n * Finds problems in the text. Run when the editor mounts and again a\n * moment after the text stops changing; an answer that arrives after\n * the text changed again is dropped, and the next run follows it.\n * Meanwhile the problems found move with the text.\n */\n lint?: (\n context: CodeExtensionContext,\n ) => CodeDiagnostic[] | null | undefined | Promise<CodeDiagnostic[] | null | undefined>\n /**\n * Offers completions while typing (after a word character or one of\n * `completionTriggers`) and on `Ctrl` + `Space` or `Alt` + `Esc`. Answers from every\n * extension are put in one list; a Promise is waited for, and dropped\n * when the text has moved on.\n */\n completion?: (\n request: CodeCompletionRequest,\n context: CodeExtensionContext,\n ) => CodeCompletionResult | null | undefined | Promise<CodeCompletionResult | null | undefined>\n /** Characters that ask for completions when typed, such as `.`. */\n completionTriggers?: string[]\n /**\n * Text about a position, shown on hover and with `Mod` + `I`. A Promise\n * is waited for; `signal` aborts when the pointer moves on.\n */\n hover?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeHoverResult | null | undefined | Promise<CodeHoverResult | null | undefined>\n /**\n * The parameters of the call around the cursor, shown while typing its\n * arguments. A Promise is waited for, and dropped when the cursor has\n * moved on.\n */\n signature?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeSignatureResult | null | undefined | Promise<CodeSignatureResult | null | undefined>\n /**\n * Sees every change before it is applied, in priority order, and may add\n * to it (positions are in the text before the change). Undo, redo, new\n * `v-model` values and other people's changes (`action: 'remote'`) don't\n * come through here.\n */\n transaction?: (tr: CodeTransaction, context: CodeExtensionContext) => void\n /**\n * Runs after every step the editor took, with the text and selection\n * already updated: typing, commands, undo and redo, new `v-model`\n * values and other people's changes. `result.meta.action` tells them\n * apart.\n */\n update?: (result: CodeTransactionResult, context: CodeExtensionContext) => void\n /**\n * Replaces the editor's undo history; the first extension that has one\n * wins. Called once per list of extensions: return the same handler\n * each time.\n */\n history?: (context: CodeExtensionContext) => CodeHistoryHandler\n /**\n * Buttons added to the toolbar shown over the selection on touch screens,\n * after cut, copy, paste and select all. Read again as the selection\n * changes.\n */\n menu?: (context: CodeExtensionContext) => CodeMenuItem[]\n /** Runs once the editor is mounted. Return a function to run when it unmounts. */\n setup?: (context: CodeExtensionContext) => void | (() => void)\n}\n\n/** A button of the touch toolbar, from an extension's `menu`. */\nexport interface CodeMenuItem {\n label: string\n run: (context: CodeExtensionContext) => void\n}\n\n/** What an extension sees of the editor: its instance, plus a little more. */\nexport interface CodeExtensionContext extends CodeEditorExpose {\n /** The text and selection now; reading them in `decorations` or `panels` follows every change. */\n readonly state: CodeState\n readonly doc: CodeText\n readonly selection: CodeSelection\n /** The lines in view: line numbers (from 1, not text positions), both ends in view. */\n readonly visible: { readonly from: number; readonly to: number }\n /** The problems found now, by all linters and the `diagnostics` prop, in text order. */\n readonly diagnostics: readonly CodeDiagnostic[]\n /** Whether the editor has focus; reading it in reactive code follows it. */\n readonly focused: boolean\n /** The editor's texts, in DouUI's locale or as given by the `messages` prop. */\n readonly messages: CodeMessages\n /** Reads a message out to screen readers. */\n announce: (message: string) => void\n /**\n * Runs the linter of the extension named `name` again now (every linter\n * without a name), for problems that arrive by themselves, such as ones a\n * server pushes.\n */\n relint: (name?: string) => void\n}\n\n/** Types an extension; returns it as it is. */\nexport function defineCodeExtension(extension: CodeExtension): CodeExtension {\n return extension\n}\n\nexport const CODE_EDITOR_KEY: InjectionKey<CodeExtensionContext> = Symbol('DouCodeEditor')\n\n/** The editor a panel or gutter component is drawn in. */\nexport function useCodeEditor(): CodeExtensionContext {\n const context = inject(CODE_EDITOR_KEY, null)\n if (!context)\n throw new Error('[@dou-ui/code] useCodeEditor() must be called inside <DouCodeEditor>')\n return context\n}\n"],"mappings":";;;AAmVA,SAAgB,oBAAoB,WAAyC;CAC3E,OAAO;AACT;AAEA,IAAa,kBAAsD,OAAO,eAAe;;AAGzF,SAAgB,gBAAsC;CACpD,MAAM,UAAU,OAAO,iBAAiB,IAAI;CAC5C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sEAAsE;CACxF,OAAO;AACT"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import { findPartner, matchBracket } from "./core/brackets.js";
2
+ import { ChangeSet } from "./core/changes.js";
3
+ import { isEmptyRange, mainRange, mapSelection, normalizeSelection, rangeFrom, rangeTo, sameSelection, selectionOf } from "./core/selection.js";
4
+ import { commands_exports } from "./core/commands.js";
5
+ import { defaultKeymap } from "./core/keymap.js";
6
+ import { CodeText, splitLines } from "./core/text.js";
7
+ import { CodeTransaction } from "./core/transaction.js";
8
+ import { matchAfter, queryRegExp, replacementFor, searchText } from "./core/search.js";
9
+ import { CodeStream } from "./language/stream.js";
10
+ import { copyPlain, defineCodeLanguage, languageFor, lineParts, samePlain, tokenTypes, tokenizeLine } from "./language/language.js";
11
+ import { CodeHighlighter } from "./language/highlighter.js";
12
+ import { codeLocales } from "./locale.js";
13
+ import { defaultCodeKeys } from "./code-keys.js";
14
+ import code_keys_default from "./code-keys2.js";
15
+ import { defineCodeExtension, useCodeEditor } from "./extension.js";
16
+ import code_editor_default from "./code-editor.js";
17
+ import { diffText } from "./core/diff.js";
18
+ import code_diff_default from "./code-diff.js";
19
+ import code_input_default from "./code-input.js";
20
+ import { createCodeHighlighter, highlightToHtml } from "./language/to-html.js";
21
+ import { createJavaScript, javascript, jsx, tsx, typescript } from "./languages/javascript.js";
22
+ import { createCss, css, scss } from "./languages/css.js";
23
+ import { json } from "./languages/json.js";
24
+ import { createHtml, html, vue } from "./languages/html.js";
25
+ import { createMarkdown, markdown } from "./languages/markdown.js";
26
+ import { python } from "./languages/python.js";
27
+ import { shell } from "./languages/shell.js";
28
+ import { sql } from "./languages/sql.js";
29
+ import { yaml } from "./languages/yaml.js";
30
+ import { withInstall } from "dou-ui";
31
+ // src/index.ts
32
+ var DouCodeEditor = withInstall(code_editor_default);
33
+ var DouCodeKeys = withInstall(code_keys_default);
34
+ var DouCodeInput = withInstall(code_input_default);
35
+ var DouCodeDiff = withInstall(code_diff_default);
36
+ export { ChangeSet, CodeHighlighter, CodeStream, CodeText, CodeTransaction, DouCodeDiff, DouCodeEditor, DouCodeEditor as default, DouCodeInput, DouCodeKeys, commands_exports as codeCommands, codeLocales, copyPlain, createCodeHighlighter, createCss, createHtml, createJavaScript, createMarkdown, css, defaultCodeKeys, defaultKeymap, defineCodeExtension, defineCodeLanguage, diffText, findPartner, highlightToHtml, html, isEmptyRange, javascript, json, jsx, languageFor, lineParts, mainRange, mapSelection, markdown, matchAfter, matchBracket, normalizeSelection, python, queryRegExp, rangeFrom, rangeTo, replacementFor, samePlain, sameSelection, scss, searchText, selectionOf, shell, splitLines, sql, tokenTypes, tokenizeLine, tsx, typescript, useCodeEditor, vue, yaml };
37
+
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["CodeEditor","CodeKeys","CodeInput","CodeDiff"],"sources":["../src/index.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport CodeEditor from './code-editor.vue'\nimport CodeDiff from './code-diff.vue'\nimport CodeInput from './code-input.vue'\nimport CodeKeys from './code-keys.vue'\n\nexport const DouCodeEditor = withInstall(CodeEditor)\nexport const DouCodeKeys = withInstall(CodeKeys)\nexport const DouCodeInput = withInstall(CodeInput)\nexport const DouCodeDiff = withInstall(CodeDiff)\nexport { diffText } from './core/diff'\nexport type { CodeDiffHunk, CodeDiffOptions, CodeDiffPart } from './core/diff'\nexport { defaultCodeKeys } from './code-keys'\nexport { defineCodeExtension, useCodeEditor } from './extension'\nexport type {\n CodeDecoration,\n CodeDiagnostic,\n CodeDiagnosticAction,\n CodeDiagnosticSeverity,\n CodeExtension,\n CodeExtensionContext,\n CodeGutter,\n CodeGutterMarker,\n CodeHistoryHandler,\n CodeCompletion,\n CodeCompletionKind,\n CodeCompletionRequest,\n CodePositionRequest,\n CodeCompletionResult,\n CodeHoverResult,\n CodeMenuItem,\n CodePanel,\n CodeSignatureResult,\n CodeWidget,\n} from './extension'\nexport default DouCodeEditor\n\nexport type {\n CodeDiffEmits,\n CodeDiffProps,\n CodeEditorEmits,\n CodeEditorExpose,\n CodeEditorProps,\n CodeInputEmits,\n CodeInputProps,\n CodeKey,\n CodeKeysProps,\n} from './types'\nexport { CodeText, splitLines } from './core/text'\nexport type { CodeLine } from './core/text'\nexport { ChangeSet } from './core/changes'\nexport type { CodeChange, CodeChangeSpec, MapAssoc } from './core/changes'\nexport {\n isEmptyRange,\n mainRange,\n mapSelection,\n normalizeSelection,\n rangeFrom,\n rangeTo,\n sameSelection,\n selectionOf,\n} from './core/selection'\nexport type { CodeRange, CodeSelection } from './core/selection'\nexport { CodeTransaction } from './core/transaction'\nexport type {\n CodeAction,\n CodeState,\n CodeTransactionMeta,\n CodeTransactionResult,\n} from './core/transaction'\nexport * as codeCommands from './core/commands'\nexport type { CodeCommand, CodeCommandTarget } from './core/commands'\nexport { defaultKeymap } from './core/keymap'\nexport { findPartner, matchBracket } from './core/brackets'\nexport type { BracketMatch } from './core/brackets'\nexport { CodeStream } from './language/stream'\nexport {\n copyPlain,\n defineCodeLanguage,\n languageFor,\n lineParts,\n samePlain,\n tokenizeLine,\n tokenTypes,\n} from './language/language'\nexport type {\n CodeLanguage,\n CodeLanguageSpec,\n CodeLineTokens,\n CodeTokenType,\n} from './language/language'\nexport { CodeHighlighter } from './language/highlighter'\nexport { createCodeHighlighter, highlightToHtml } from './language/to-html'\nexport { createJavaScript, javascript, jsx, tsx, typescript } from './languages/javascript'\nexport type { JavaScriptOptions, JavaScriptState } from './languages/javascript'\nexport { createCss, css, scss } from './languages/css'\nexport type { CssState } from './languages/css'\nexport { json } from './languages/json'\nexport type { JsonState } from './languages/json'\nexport { createHtml, html, vue } from './languages/html'\nexport type { HtmlState } from './languages/html'\nexport { createMarkdown, markdown } from './languages/markdown'\nexport type { MarkdownOptions, MarkdownState } from './languages/markdown'\nexport { python } from './languages/python'\nexport type { PythonState } from './languages/python'\nexport { shell } from './languages/shell'\nexport type { ShellState } from './languages/shell'\nexport { sql } from './languages/sql'\nexport type { SqlState } from './languages/sql'\nexport { yaml } from './languages/yaml'\nexport type { YamlState } from './languages/yaml'\nexport type { CodeKeyBinding, CodeKeymap } from './core/keymap'\nexport type { CodeAssistControl, CodeDiagnosticControl, CodeSearchControl } from './core/commands'\nexport { matchAfter, queryRegExp, replacementFor, searchText } from './core/search'\nexport type { CodeMatch, CodeSearchQuery, CodeSearchResult } from './core/search'\nexport { codeLocales } from './locale'\nexport type { CodeMessages } from './locale'\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouCodeEditor: typeof DouCodeEditor\n DouCodeKeys: typeof DouCodeKeys\n DouCodeInput: typeof DouCodeInput\n DouCodeDiff: typeof DouCodeDiff\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAa,gBAAgB,YAAYA,mBAAU;AACnD,IAAa,cAAc,YAAYC,iBAAQ;AAC/C,IAAa,eAAe,YAAYC,kBAAS;AACjD,IAAa,cAAc,YAAYC,iBAAQ"}