@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,194 @@
1
+ import { clusterStarts, isAscii } from "../core/chars.js";
2
+ import { splitLines } from "../core/text.js";
3
+ // src/view/layout.ts
4
+ var UNWRAPPED = Object.freeze({
5
+ breaks: Object.freeze([]),
6
+ indent: 0
7
+ });
8
+ var isSpace = (ch) => ch === " " || ch === " ";
9
+ /** Punctuation a row may end after, so long code breaks between its parts rather than inside a name. */
10
+ var AFTER = "([{,;";
11
+ /** Surrogate pairs, combining marks and joiners: characters made of several code units. */
12
+ var COMPLEX = /[\p{M}\u200d\ud800-\udfff]/u;
13
+ /** Scripts written without spaces, which may break between any two characters. */
14
+ var WIDE = /[⺀-꓏가-힣豈-﫿︰-﹏＀-⦆]/;
15
+ /**
16
+ * Cuts a line into rows no wider than `width`. Rows break after spaces and
17
+ * opening brackets, commas and semicolons, before a `.`, or between
18
+ * characters of scripts written without spaces; a word longer than
19
+ * a row is cut where it overflows. Rows after the first line up with the
20
+ * line's indentation, unless that leaves too little room.
21
+ */
22
+ function wrapLine(text, width, measure) {
23
+ if (!text) return UNWRAPPED;
24
+ const ascii = isAscii(text);
25
+ if (!text.includes(" ") && text.length * measure.cell * (ascii ? 1 : 2) <= width) return UNWRAPPED;
26
+ const stop = measure.cell * measure.tabSize;
27
+ let lead = 0;
28
+ let indent = 0;
29
+ for (; lead < text.length && isSpace(text[lead]); lead++) indent = text[lead] === " " ? (Math.floor(indent / stop + 1e-6) + 1) * stop : indent + measure.cell;
30
+ if (indent > width / 2) indent = 0;
31
+ const single = ascii || !COMPLEX.test(text);
32
+ const starts = single ? null : clusterStarts(text);
33
+ const count = single ? text.length : starts.length - 1;
34
+ const breaks = [];
35
+ let x = 0;
36
+ let rowStart = 0;
37
+ let rowX = 0;
38
+ let limit = width;
39
+ /** Where the current row may end at the latest, and the x there. */
40
+ let chance = -1;
41
+ let chanceX = 0;
42
+ for (let i = 0; i < count; i++) {
43
+ const from = single ? i : starts[i];
44
+ const to = single ? i + 1 : starts[i + 1];
45
+ const ch = single ? text[i] : text.slice(from, to);
46
+ const w = ch === " " ? (Math.floor(x / stop + 1e-6) + 1) * stop - x : ascii ? measure.cell : measure.width(ch);
47
+ const wide = !ascii && WIDE.test(ch);
48
+ if ((wide || ch === ".") && from > rowStart) {
49
+ chance = from;
50
+ chanceX = x;
51
+ }
52
+ while (x + w - rowX > limit && from > rowStart) {
53
+ const at = chance > rowStart ? chance : from;
54
+ const atX = chance > rowStart ? chanceX : x;
55
+ breaks.push(at);
56
+ rowStart = at;
57
+ rowX = atX;
58
+ limit = width - indent;
59
+ chance = -1;
60
+ }
61
+ x += w;
62
+ if (isSpace(ch) || wide || AFTER.includes(ch)) {
63
+ chance = to;
64
+ chanceX = x;
65
+ }
66
+ }
67
+ return breaks.length ? {
68
+ breaks,
69
+ indent
70
+ } : UNWRAPPED;
71
+ }
72
+ /** The row of a line that column `col` is drawn on. A column right at a break starts the next row. */
73
+ function rowOfCol(wrapped, col) {
74
+ const { breaks } = wrapped;
75
+ let row = 0;
76
+ while (row < breaks.length && breaks[row] <= col) row++;
77
+ return row;
78
+ }
79
+ /**
80
+ * Where each line sits, counted in rows: a wrapped line takes several and a
81
+ * folded line none. When every line is one row, nothing is stored and the
82
+ * answers are plain arithmetic.
83
+ */
84
+ var LineLayout = class {
85
+ lines;
86
+ /** Rows before each line, as a Fenwick tree over the rows of each line. */
87
+ tree = null;
88
+ rows = null;
89
+ total;
90
+ constructor(lines, wrapRows, hidden) {
91
+ this.lines = lines;
92
+ if (!wrapRows && !hidden.length) {
93
+ this.total = lines;
94
+ return;
95
+ }
96
+ const rows = new Int32Array(lines);
97
+ if (wrapRows) for (let i = 0; i < lines; i++) rows[i] = wrapRows[i] ?? 1;
98
+ else rows.fill(1);
99
+ for (const [from, to] of hidden) for (let n = Math.max(1, from); n <= Math.min(lines, to); n++) rows[n - 1] = 0;
100
+ const tree = new Int32Array(lines + 1);
101
+ let total = 0;
102
+ for (let i = 1; i <= lines; i++) {
103
+ tree[i] += rows[i - 1];
104
+ total += rows[i - 1];
105
+ const parent = i + (i & -i);
106
+ if (parent <= lines) tree[parent] += tree[i];
107
+ }
108
+ this.rows = rows;
109
+ this.tree = tree;
110
+ this.total = Math.max(1, total);
111
+ }
112
+ /** Whether every line is one row. */
113
+ get uniform() {
114
+ return !this.tree;
115
+ }
116
+ /** How many rows line `n` takes; `0` when it is hidden. */
117
+ rowsOf(n) {
118
+ return this.rows ? this.rows[n - 1] ?? 0 : 1;
119
+ }
120
+ /** The row line `n` starts on, from 0. */
121
+ rowOf(n) {
122
+ if (!this.tree) return n - 1;
123
+ let sum = 0;
124
+ for (let i = Math.min(n - 1, this.lines); i > 0; i -= i & -i) sum += this.tree[i];
125
+ return sum;
126
+ }
127
+ /** The line drawn on row `row`, and which of its rows that is; clamped to the text. */
128
+ lineAtRow(row) {
129
+ row = Math.max(0, Math.min(Math.floor(row), this.total - 1));
130
+ if (!this.tree) return {
131
+ n: Math.min(this.lines, row + 1),
132
+ sub: 0
133
+ };
134
+ let pos = 0;
135
+ let rest = row;
136
+ let step = 1;
137
+ while (step * 2 <= this.lines) step *= 2;
138
+ for (; step; step >>= 1) {
139
+ const next = pos + step;
140
+ if (next <= this.lines && this.tree[next] <= rest) {
141
+ pos = next;
142
+ rest -= this.tree[next];
143
+ }
144
+ }
145
+ return {
146
+ n: Math.min(this.lines, pos + 1),
147
+ sub: rest
148
+ };
149
+ }
150
+ /** Whether line `n` is drawn. */
151
+ shown(n) {
152
+ return !this.rows || this.rows[n - 1] > 0;
153
+ }
154
+ };
155
+ /**
156
+ * Moves per-line values (rows of each line) along with an edit, working
157
+ * out `valueOf` again only for the lines it touched. Returns `false` when
158
+ * starting over is cheaper or the values no longer fit the text.
159
+ */
160
+ function updateRows(rows, before, after, changes, valueOf) {
161
+ if (rows.length !== before.lines) return false;
162
+ const groups = [];
163
+ for (const change of changes.changes) {
164
+ const first = before.lineAt(change.from).number;
165
+ const last = before.lineAt(change.to).number;
166
+ const added = splitLines(change.insert).length - 1 - (last - first);
167
+ const group = groups[groups.length - 1];
168
+ if (group && first <= group.last) {
169
+ group.last = Math.max(group.last, last);
170
+ group.added += added;
171
+ } else groups.push({
172
+ first,
173
+ last,
174
+ added
175
+ });
176
+ }
177
+ let shift = 0;
178
+ const placed = groups.map((group) => {
179
+ const from = group.first + shift;
180
+ shift += group.added;
181
+ return from;
182
+ });
183
+ for (let i = groups.length - 1; i >= 0; i--) {
184
+ const { first, last, added } = groups[i];
185
+ const count = last - first + 1 + added;
186
+ if (count > 5e3) return false;
187
+ const texts = after.lineTexts(placed[i], placed[i] + count - 1);
188
+ rows.splice(first - 1, last - first + 1, ...texts.map(valueOf));
189
+ }
190
+ return rows.length === after.lines;
191
+ }
192
+ export { LineLayout, UNWRAPPED, rowOfCol, updateRows, wrapLine };
193
+
194
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","names":[],"sources":["../../src/view/layout.ts"],"sourcesContent":["import type { ChangeSet } from '../core/changes'\nimport { clusterStarts, isAscii } from '../core/chars'\nimport { type CodeText, splitLines } from '../core/text'\nimport type { Measure } from './measure'\n\n/** How a line is cut into rows: where each row after the first starts, and how far those rows are indented. */\nexport interface WrappedLine {\n readonly breaks: readonly number[]\n readonly indent: number\n}\n\nexport const UNWRAPPED: WrappedLine = Object.freeze({ breaks: Object.freeze([]), indent: 0 })\n\nconst isSpace = (ch: string) => ch === ' ' || ch === '\\t'\n/** Punctuation a row may end after, so long code breaks between its parts rather than inside a name. */\nconst AFTER = '([{,;'\n/** Surrogate pairs, combining marks and joiners: characters made of several code units. */\nconst COMPLEX = /[\\p{M}\\u200d\\ud800-\\udfff]/u\n/** Scripts written without spaces, which may break between any two characters. */\nconst WIDE = /[⺀-꓏가-힣豈-﫿︰-﹏＀-⦆]/\n\n/**\n * Cuts a line into rows no wider than `width`. Rows break after spaces and\n * opening brackets, commas and semicolons, before a `.`, or between\n * characters of scripts written without spaces; a word longer than\n * a row is cut where it overflows. Rows after the first line up with the\n * line's indentation, unless that leaves too little room.\n */\nexport function wrapLine(text: string, width: number, measure: Measure): WrappedLine {\n if (!text) return UNWRAPPED\n const ascii = isAscii(text)\n // Wide characters take about two cells; a line that fits even so needs no closer look.\n if (!text.includes('\\t') && text.length * measure.cell * (ascii ? 1 : 2) <= width)\n return UNWRAPPED\n const stop = measure.cell * measure.tabSize\n let lead = 0\n let indent = 0\n for (; lead < text.length && isSpace(text[lead]!); lead++)\n indent =\n text[lead] === '\\t' ? (Math.floor(indent / stop + 1e-6) + 1) * stop : indent + measure.cell\n if (indent > width / 2) indent = 0\n\n // Each UTF-16 unit is a character of its own unless the line has pairs or marks; finding clusters is slow.\n const single = ascii || !COMPLEX.test(text)\n const starts = single ? null : clusterStarts(text)\n const count = single ? text.length : starts!.length - 1\n const breaks: number[] = []\n let x = 0\n let rowStart = 0\n let rowX = 0\n let limit = width\n /** Where the current row may end at the latest, and the x there. */\n let chance = -1\n let chanceX = 0\n for (let i = 0; i < count; i++) {\n const from = single ? i : starts![i]!\n const to = single ? i + 1 : starts![i + 1]!\n const ch = single ? text[i]! : text.slice(from, to)\n const w =\n ch === '\\t'\n ? (Math.floor(x / stop + 1e-6) + 1) * stop - x\n : ascii\n ? measure.cell\n : measure.width(ch)\n const wide = !ascii && WIDE.test(ch)\n // A wide character or a `.` (a member access) may start a row, so the row can end before it.\n if ((wide || ch === '.') && from > rowStart) {\n chance = from\n chanceX = x\n }\n while (x + w - rowX > limit && from > rowStart) {\n const at = chance > rowStart ? chance : from\n const atX = chance > rowStart ? chanceX : x\n breaks.push(at)\n rowStart = at\n rowX = atX\n limit = width - indent\n chance = -1\n }\n x += w\n if (isSpace(ch) || wide || AFTER.includes(ch)) {\n chance = to\n chanceX = x\n }\n }\n return breaks.length ? { breaks, indent } : UNWRAPPED\n}\n\n/** The row of a line that column `col` is drawn on. A column right at a break starts the next row. */\nexport function rowOfCol(wrapped: WrappedLine, col: number): number {\n const { breaks } = wrapped\n let row = 0\n while (row < breaks.length && breaks[row]! <= col) row++\n return row\n}\n\n/**\n * Where each line sits, counted in rows: a wrapped line takes several and a\n * folded line none. When every line is one row, nothing is stored and the\n * answers are plain arithmetic.\n */\nexport class LineLayout {\n /** Rows before each line, as a Fenwick tree over the rows of each line. */\n private tree: Int32Array | null = null\n private rows: Int32Array | null = null\n readonly total: number\n\n constructor(\n readonly lines: number,\n /** Rows of each line (index `n - 1`), or `null` when none wraps. */\n wrapRows: ArrayLike<number> | null,\n /** Hidden lines, as sorted inclusive ranges. */\n hidden: ReadonlyArray<readonly [number, number]>,\n ) {\n if (!wrapRows && !hidden.length) {\n this.total = lines\n return\n }\n const rows = new Int32Array(lines)\n if (wrapRows) for (let i = 0; i < lines; i++) rows[i] = wrapRows[i] ?? 1\n else rows.fill(1)\n for (const [from, to] of hidden)\n for (let n = Math.max(1, from); n <= Math.min(lines, to); n++) rows[n - 1] = 0\n // Build the tree in O(n): each node adds itself to its parent.\n const tree = new Int32Array(lines + 1)\n let total = 0\n for (let i = 1; i <= lines; i++) {\n tree[i]! += rows[i - 1]!\n total += rows[i - 1]!\n const parent = i + (i & -i)\n if (parent <= lines) tree[parent]! += tree[i]!\n }\n this.rows = rows\n this.tree = tree\n this.total = Math.max(1, total)\n }\n\n /** Whether every line is one row. */\n get uniform() {\n return !this.tree\n }\n\n /** How many rows line `n` takes; `0` when it is hidden. */\n rowsOf(n: number): number {\n return this.rows ? (this.rows[n - 1] ?? 0) : 1\n }\n\n /** The row line `n` starts on, from 0. */\n rowOf(n: number): number {\n if (!this.tree) return n - 1\n let sum = 0\n for (let i = Math.min(n - 1, this.lines); i > 0; i -= i & -i) sum += this.tree[i]!\n return sum\n }\n\n /** The line drawn on row `row`, and which of its rows that is; clamped to the text. */\n lineAtRow(row: number): { n: number; sub: number } {\n row = Math.max(0, Math.min(Math.floor(row), this.total - 1))\n if (!this.tree) return { n: Math.min(this.lines, row + 1), sub: 0 }\n // The last line whose start is at or before `row`, skipping lines that take no rows.\n let pos = 0\n let rest = row\n let step = 1\n while (step * 2 <= this.lines) step *= 2\n for (; step; step >>= 1) {\n const next = pos + step\n if (next <= this.lines && this.tree[next]! <= rest) {\n pos = next\n rest -= this.tree[next]!\n }\n }\n // `pos` lines fit entirely before `row`; the row is in line `pos + 1`.\n return { n: Math.min(this.lines, pos + 1), sub: rest }\n }\n\n /** Whether line `n` is drawn. */\n shown(n: number): boolean {\n return !this.rows || this.rows[n - 1]! > 0\n }\n}\n\n/**\n * Moves per-line values (rows of each line) along with an edit, working\n * out `valueOf` again only for the lines it touched. Returns `false` when\n * starting over is cheaper or the values no longer fit the text.\n */\nexport function updateRows(\n rows: number[],\n before: CodeText,\n after: CodeText,\n changes: ChangeSet,\n valueOf: (text: string) => number,\n): boolean {\n if (rows.length !== before.lines) return false\n // Changes on the same lines (several cursors on one line) are one group of old lines.\n const groups: Array<{ first: number; last: number; added: number }> = []\n for (const change of changes.changes) {\n const first = before.lineAt(change.from).number\n const last = before.lineAt(change.to).number\n const added = splitLines(change.insert).length - 1 - (last - first)\n const group = groups[groups.length - 1]\n if (group && first <= group.last) {\n group.last = Math.max(group.last, last)\n group.added += added\n } else groups.push({ first, last, added })\n }\n let shift = 0\n const placed = groups.map((group) => {\n const from = group.first + shift\n shift += group.added\n return from\n })\n // From the last group back, so the line numbers of earlier ones still hold.\n for (let i = groups.length - 1; i >= 0; i--) {\n const { first, last, added } = groups[i]!\n const count = last - first + 1 + added\n if (count > 5000) return false\n const texts = after.lineTexts(placed[i]!, placed[i]! + count - 1)\n rows.splice(first - 1, last - first + 1, ...texts.map(valueOf))\n }\n return rows.length === after.lines\n}\n"],"mappings":";;;AAWA,IAAa,YAAyB,OAAO,OAAO;CAAE,QAAQ,OAAO,OAAO,CAAC,CAAC;CAAG,QAAQ;AAAE,CAAC;AAE5F,IAAM,WAAW,OAAe,OAAO,OAAO,OAAO;;AAErD,IAAM,QAAQ;;AAEd,IAAM,UAAU;;AAEhB,IAAM,OAAO;;;;;;;;AASb,SAAgB,SAAS,MAAc,OAAe,SAA+B;CACnF,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,QAAQ,QAAQ,IAAI;CAE1B,IAAI,CAAC,KAAK,SAAS,GAAI,KAAK,KAAK,SAAS,QAAQ,QAAQ,QAAQ,IAAI,MAAM,OAC1E,OAAO;CACT,MAAM,OAAO,QAAQ,OAAO,QAAQ;CACpC,IAAI,OAAO;CACX,IAAI,S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AAO,OAAO,KAAK;GAAE;GAAO;GAAM;EAAM,CAAC;CAC3C;CACA,IAAI,QAAQ;CACZ,MAAM,SAAS,OAAO,KAAK,UAAU;EACnC,MAAM,OAAO,MAAM,QAAQ;EAC3B,SAAS,MAAM;EACf,OAAO;CACT,CAAC;CAED,KAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;EAC3C,MAAM,EAAE,OAAO,MAAM,UAAU,OAAO;EACtC,MAAM,QAAQ,OAAO,QAAQ,IAAI;EACjC,IAAI,QAAQ,KAAM,OAAO;EACzB,MAAM,QAAQ,MAAM,UAAU,OAAO,IAAK,OAAO,KAAM,QAAQ,CAAC;EAChE,KAAK,OAAO,QAAQ,GAAG,OAAO,QAAQ,GAAG,GAAG,MAAM,IAAI,OAAO,CAAC;CAChE;CACA,OAAO,KAAK,WAAW,MAAM;AAC/B"}
@@ -0,0 +1,104 @@
1
+ import { clusterStarts, isAscii } from "../core/chars.js";
2
+ // src/view/measure.ts
3
+ /**
4
+ * Text metrics without reading layout per line: every plain ASCII
5
+ * character is one monospace cell, and anything else (CJK, emoji, accents)
6
+ * is measured once in the page's own font and remembered. Tabs reach to
7
+ * the next tab stop.
8
+ */
9
+ /** A length read from computed styles, in px. */
10
+ function px(value, fallback) {
11
+ const n = Number.parseFloat(value);
12
+ return Number.isFinite(n) ? Math.max(0, n) : fallback;
13
+ }
14
+ var Measure = class {
15
+ probe;
16
+ /** Width of one monospace cell. */
17
+ cell = 8;
18
+ lineHeight = 20;
19
+ /** Space above the first line and below the last (`--dou-code-editor-padding-y`). */
20
+ padY = 8;
21
+ /** Space before and after each line (`--dou-code-editor-padding-x`). */
22
+ padX = 12;
23
+ tabSize = 2;
24
+ widths = /* @__PURE__ */ new Map();
25
+ constructor(probe) {
26
+ this.probe = probe;
27
+ }
28
+ /** Reads the cell width and line height again, e.g. after the font changed. */
29
+ refresh(tabSize) {
30
+ this.tabSize = tabSize;
31
+ this.widths.clear();
32
+ const el = this.probe();
33
+ if (!el) return;
34
+ el.textContent = "x".repeat(64);
35
+ const rect = el.getBoundingClientRect();
36
+ if (rect.width > 0) this.cell = rect.width / 64;
37
+ if (rect.height > 0) this.lineHeight = Math.round(rect.height);
38
+ el.textContent = "";
39
+ el.style.padding = "var(--dou-code-editor-padding-y, 8px) var(--dou-code-editor-padding-x, 12px)";
40
+ const style = getComputedStyle(el);
41
+ this.padY = px(style.paddingTop, 8);
42
+ this.padX = px(style.paddingLeft, 12);
43
+ el.style.padding = "";
44
+ }
45
+ /** Width of one character as drawn. */
46
+ width(cluster) {
47
+ const code = cluster.charCodeAt(0);
48
+ if (cluster.length === 1 && code >= 32 && code < 127) return this.cell;
49
+ let width = this.widths.get(cluster);
50
+ if (width !== void 0) return width;
51
+ const el = this.probe();
52
+ if (el) {
53
+ el.textContent = cluster;
54
+ width = el.getBoundingClientRect().width;
55
+ el.textContent = "";
56
+ }
57
+ if (!width) width = /[ᄀ-ᅟ⺀-꓏가-힣豈-﫿︰-﹏＀-⦆¢-₩]|[\ud83c-\ud83e]/.test(cluster) ? this.cell * 2 : this.cell;
58
+ if (el?.isConnected) this.widths.set(cluster, width);
59
+ return width;
60
+ }
61
+ tab(x) {
62
+ const stop = this.cell * this.tabSize;
63
+ return (Math.floor(x / stop + 1e-6) + 1) * stop;
64
+ }
65
+ /** The x of column `col` in `text`, from the line's start. */
66
+ x(text, col) {
67
+ col = Math.min(col, text.length);
68
+ if (isAscii(text)) {
69
+ if (!text.includes(" ")) return col * this.cell;
70
+ let x = 0;
71
+ for (let i = 0; i < col; i++) x = text.charCodeAt(i) === 9 ? this.tab(x) : x + this.cell;
72
+ return x;
73
+ }
74
+ let x = 0;
75
+ const starts = clusterStarts(text);
76
+ for (let i = 0; i < starts.length - 1 && starts[i] < col; i++) {
77
+ const cluster = text.slice(starts[i], starts[i + 1]);
78
+ x = cluster === " " ? this.tab(x) : x + this.width(cluster);
79
+ }
80
+ return x;
81
+ }
82
+ /** The column nearest to `x` in `text`, on a character boundary. */
83
+ col(text, x) {
84
+ if (x <= 0) return 0;
85
+ if (isAscii(text) && !text.includes(" ")) return Math.min(text.length, Math.round(x / this.cell));
86
+ let left = 0;
87
+ const ascii = isAscii(text);
88
+ const starts = ascii ? null : clusterStarts(text);
89
+ const count = ascii ? text.length : starts.length - 1;
90
+ for (let i = 0; i < count; i++) {
91
+ const from = ascii ? i : starts[i];
92
+ const to = ascii ? i + 1 : starts[i + 1];
93
+ const cluster = text.slice(from, to);
94
+ const right = cluster === " " ? this.tab(left) : left + this.width(cluster);
95
+ if (x < (left + right) / 2) return from;
96
+ if (x < right) return to;
97
+ left = right;
98
+ }
99
+ return text.length;
100
+ }
101
+ };
102
+ export { Measure };
103
+
104
+ //# sourceMappingURL=measure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measure.js","names":[],"sources":["../../src/view/measure.ts"],"sourcesContent":["import { clusterStarts, isAscii } from '../core/chars'\n\n/**\n * Text metrics without reading layout per line: every plain ASCII\n * character is one monospace cell, and anything else (CJK, emoji, accents)\n * is measured once in the page's own font and remembered. Tabs reach to\n * the next tab stop.\n */\n/** A length read from computed styles, in px. */\nfunction px(value: string, fallback: number) {\n const n = Number.parseFloat(value)\n return Number.isFinite(n) ? Math.max(0, n) : fallback\n}\n\nexport class Measure {\n /** Width of one monospace cell. */\n cell = 8\n lineHeight = 20\n /** Space above the first line and below the last (`--dou-code-editor-padding-y`). */\n padY = 8\n /** Space before and after each line (`--dou-code-editor-padding-x`). */\n padX = 12\n tabSize = 2\n private widths = new Map<string, number>()\n\n constructor(private readonly probe: () => HTMLElement | null | undefined) {}\n\n /** Reads the cell width and line height again, e.g. after the font changed. */\n refresh(tabSize: number) {\n this.tabSize = tabSize\n this.widths.clear()\n const el = this.probe()\n if (!el) return\n el.textContent = 'x'.repeat(64)\n const rect = el.getBoundingClientRect()\n if (rect.width > 0) this.cell = rect.width / 64\n if (rect.height > 0) this.lineHeight = Math.round(rect.height)\n el.textContent = ''\n // Through a padding, so a calc() in the variable comes out in pixels.\n el.style.padding =\n 'var(--dou-code-editor-padding-y, 8px) var(--dou-code-editor-padding-x, 12px)'\n const style = getComputedStyle(el)\n this.padY = px(style.paddingTop, 8)\n this.padX = px(style.paddingLeft, 12)\n el.style.padding = ''\n }\n\n /** Width of one character as drawn. */\n width(cluster: string): number {\n const code = cluster.charCodeAt(0)\n if (cluster.length === 1 && code >= 0x20 && code < 0x7f) return this.cell\n let width = this.widths.get(cluster)\n if (width !== undefined) return width\n const el = this.probe()\n if (el) {\n el.textContent = cluster\n width = el.getBoundingClientRect().width\n el.textContent = ''\n }\n // No layout (tests, a hidden editor): wide scripts take two cells.\n if (!width)\n width = /[ᄀ-ᅟ⺀-꓏가-힣豈-﫿︰-﹏＀-⦆¢-₩]|[\\ud83c-\\ud83e]/.test(cluster)\n ? this.cell * 2\n : this.cell\n // Only keep it once the page has fonts, so a fallback guess isn't kept forever.\n if (el?.isConnected) this.widths.set(cluster, width)\n return width\n }\n\n private tab(x: number) {\n const stop = this.cell * this.tabSize\n return (Math.floor(x / stop + 1e-6) + 1) * stop\n }\n\n /** The x of column `col` in `text`, from the line's start. */\n x(text: string, col: number): number {\n col = Math.min(col, text.length)\n if (isAscii(text)) {\n if (!text.includes('\\t')) return col * this.cell\n let x = 0\n for (let i = 0; i < col; i++) x = text.charCodeAt(i) === 9 ? this.tab(x) : x + this.cell\n return x\n }\n let x = 0\n const starts = clusterStarts(text)\n for (let i = 0; i < starts.length - 1 && starts[i]! < col; i++) {\n const cluster = text.slice(starts[i], starts[i + 1])\n x = cluster === '\\t' ? this.tab(x) : x + this.width(cluster)\n }\n return x\n }\n\n /** The column nearest to `x` in `text`, on a character boundary. */\n col(text: string, x: number): number {\n if (x <= 0) return 0\n if (isAscii(text) && !text.includes('\\t'))\n return Math.min(text.length, Math.round(x / this.cell))\n let left = 0\n const ascii = isAscii(text)\n const starts = ascii ? null : clusterStarts(text)\n const count = ascii ? text.length : starts!.length - 1\n for (let i = 0; i < count; i++) {\n const from = ascii ? i : starts![i]!\n const to = ascii ? i + 1 : starts![i + 1]!\n const cluster = text.slice(from, to)\n const right = cluster === '\\t' ? this.tab(left) : left + this.width(cluster)\n if (x < (left + right) / 2) return from\n if (x < right) return to\n left = right\n }\n return text.length\n }\n}\n"],"mappings":";;;;;;;;;AASA,SAAS,GAAG,OAAe,UAAkB;CAC3C,MAAM,IAAI,OAAO,WAAW,KAAK;CACjC,OAAO,OAAO,SAAS,CAAC,IAAI,KAAK,IAAI,GAAG,CAAC,IAAI;AAC/C;AAEA,IAAa,UAAb,MAAqB;CAWU;;CAT7B,OAAO;CACP,aAAa;;CAEb,OAAO;;CAEP,OAAO;CACP,UAAU;CACV,yBAAiB,IAAI,IAAoB;CAEzC,YAAY,OAA8D;EAA7C,KAAA,QAAA;CAA8C;;CAG3E,QAAQ,SAAiB;EACvB,KAAK,UAAU;EACf,KAAK,OAAO,MAAM;EAClB,MAAM,KAAK,KAAK,MAAM;EACtB,IAAI,CAAC,IAAI;EACT,GAAG,cAAc,IAAI,OAAO,EAAE;EAC9B,MAAM,OAAO,GAAG,sBAAsB;EACtC,IAAI,KAAK,QAAQ,GAAG,KAAK,OAAO,KAAK,QAAQ;EAC7C,IAAI,KAAK,SAAS,GAAG,KAAK,aAAa,KAAK,MAAM,KAAK,MAAM;EAC7D,GAAG,cAAc;EAEjB,GAAG,MAAM,UACP;EACF,MAAM,QAAQ,iBAAiB,EAAE;EACjC,KAAK,OAAO,GAAG,MAAM,YAAY,CAAC;EAClC,KAAK,OAAO,GAAG,MAAM,aAAa,EAAE;EACpC,GAAG,MAAM,UAAU;CACrB;;CAGA,MAAM,SAAyB;EAC7B,MAAM,OAAO,QAAQ,WAAW,CAAC;EACjC,IAAI,QAAQ,WAAW,KAAK,QAAQ,MAAQ,OAAO,KAAM,OAAO,KAAK;EACrE,IAAI,QAAQ,KAAK,OAAO,IAAI,OAAO;EACnC,IAAI,UAAU,KAAA,GAAW,OAAO;EAChC,MAAM,KAAK,KAAK,MAAM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O,cAAc,IAAI;EAChD,MAAM,QAAQ,QAAQ,KAAK,SAAS,OAAQ,SAAS;EACrD,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC9B,MAAM,OAAO,QAAQ,IAAI,OAAQ;GACjC,MAAM,KAAK,QAAQ,IAAI,IAAI,OAAQ,IAAI;GACvC,MAAM,UAAU,KAAK,MAAM,MAAM,EAAE;GACnC,MAAM,QAAQ,YAAY,MAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,MAAM,OAAO;GAC3E,IAAI,KAAK,OAAO,SAAS,GAAG,OAAO;GACnC,IAAI,IAAI,OAAO,OAAO;GACtB,OAAO;EACT;EACA,OAAO,KAAK;CACd;AACF"}
@@ -0,0 +1,31 @@
1
+ // src/view/viewport.ts
2
+ /**
3
+ * The part of the window in view, above a phone's keyboard and inside a
4
+ * pinch zoom, in the coordinates `getBoundingClientRect` gives.
5
+ *
6
+ * Browsers disagree on what those coordinates are relative to: the layout
7
+ * viewport (so the visual viewport sits `offsetTop` into them), or the
8
+ * visual viewport itself (iOS Safari, where adding `offsetTop` counts the
9
+ * scroll twice). The page's own box tells which: the visual viewport's place
10
+ * in the page, plus where the page starts in those coordinates.
11
+ */
12
+ function visibleViewport() {
13
+ const root = document.documentElement;
14
+ const vv = window.visualViewport;
15
+ if (!vv) return {
16
+ left: 0,
17
+ top: 0,
18
+ width: root.clientWidth,
19
+ height: root.clientHeight
20
+ };
21
+ const page = root.getBoundingClientRect();
22
+ return {
23
+ left: vv.pageLeft + page.left,
24
+ top: vv.pageTop + page.top,
25
+ width: vv.width,
26
+ height: vv.height
27
+ };
28
+ }
29
+ export { visibleViewport };
30
+
31
+ //# sourceMappingURL=viewport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport.js","names":[],"sources":["../../src/view/viewport.ts"],"sourcesContent":["/**\n * The part of the window in view, above a phone's keyboard and inside a\n * pinch zoom, in the coordinates `getBoundingClientRect` gives.\n *\n * Browsers disagree on what those coordinates are relative to: the layout\n * viewport (so the visual viewport sits `offsetTop` into them), or the\n * visual viewport itself (iOS Safari, where adding `offsetTop` counts the\n * scroll twice). The page's own box tells which: the visual viewport's place\n * in the page, plus where the page starts in those coordinates.\n */\nexport function visibleViewport(): { left: number; top: number; width: number; height: number } {\n const root = document.documentElement\n const vv = window.visualViewport\n if (!vv) return { left: 0, top: 0, width: root.clientWidth, height: root.clientHeight }\n const page = root.getBoundingClientRect()\n return {\n left: vv.pageLeft + page.left,\n top: vv.pageTop + page.top,\n width: vv.width,\n height: vv.height,\n }\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,kBAAgF;CAC9F,MAAM,OAAO,SAAS;CACtB,MAAM,KAAK,OAAO;CAClB,IAAI,CAAC,IAAI,OAAO;EAAE,MAAM;EAAG,KAAK;EAAG,OAAO,KAAK;EAAa,QAAQ,KAAK;CAAa;CACtF,MAAM,OAAO,KAAK,sBAAsB;CACxC,OAAO;EACL,MAAM,GAAG,WAAW,KAAK;EACzB,KAAK,GAAG,UAAU,KAAK;EACvB,OAAO,GAAG;EACV,QAAQ,GAAG;CACb;AACF"}